Something went wrong. Try again.
small gleam coding and (not yet) persistent agent daemon with a detachable cli forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671<script lang="ts" module> /** * Where each window's chat was read when it unmounted (a board switch * remounts the whole board): the block at the top of the thread and how * far through it the reader was, as `reading` holds it. A chat left at its end keeps no place. */ const places = new Map<string, { block: string; share: number }>();
type Piece = { kind: 'text' | 'quote' | 'code'; text: string }; /** Messages split by their text: the chat draws every bubble again for each token of a reply. */ const pieced = new Map<string, Piece[]>();
/** * A message as you wrote it, with the quotes and fenced code a sent note * carries (notes.ts `compose`) set apart from the words around them. */ function pieces(text: string): Piece[] { const known = pieced.get(text); if (known) return known; const found: { kind: 'text' | 'quote' | 'code'; lines: string[] }[] = []; let fenced = false; for (const line of text.split('\n')) { if (line.startsWith('```')) { fenced = !fenced; if (fenced) found.push({ kind: 'code', lines: [] }); continue; } const kind = fenced ? 'code' : /^> ?/.test(line) ? 'quote' : 'text'; const body = kind === 'quote' ? line.replace(/^> ?/, '') : line; const last = found.at(-1); if (last?.kind === kind) last.lines.push(body); else found.push({ kind, lines: [body] }); } const split = found .map(({ kind, lines }) => ({ kind, text: kind === 'code' ? lines.join('\n') : lines.join('\n').replace(/^\n+|\s+$/g, ''), })) .filter((piece) => piece.text); if (pieced.size >= 1000) pieced.clear(); pieced.set(text, split); return split; }
/** A system note longer than a line folds behind its first sentence. */ const folds = (text: string) => text.length > 160 || text.includes('\n');
function firstSentence(text: string): string { const line = text.split('\n', 1)[0]; return line.match(/^.*?[.!?](?=\s|$)/)?.[0] ?? line; }</script>
<script lang="ts"> import { onMount, tick, untrack, type Snippet } from 'svelte'; import { busy, clock } from '../live.svelte'; import { boards } from '../boards.svelte'; import { popped } from '../board.svelte'; import { ApiError, browse, copyText, getShellCommand, interruptSession, moveWorkspace, readMove, sideQuestionsSupported, submitShellCommand, uuidv7, type HistoryEntry, type LoginTerms, type Session, } from '../api'; import { terms } from '../terms.svelte'; import type { Usage } from '../context'; import { watchFamily } from '../agents'; import { sessions } from '../sessions.svelte'; import { agentBubbleRole } from './mailRole'; import { compose, drafts, finishNotes } from '../notes'; import { draftOf } from './drafts'; import { filenameParts, formatSize, type Attached, type AttachedFile, } from './attachments'; import { fullStamp, stamp } from '../format'; import LiveFace from '../LiveFace.svelte'; import { prefs } from '../prefs.svelte'; import { face, formatElapsed } from '../moods'; import { Transcript, type Displayed, type Made } from '../transcript.svelte'; import Composer from './Composer.svelte'; import QueuePanel from './QueuePanel.svelte'; import ImageGallery from './ImageGallery.svelte'; import Markdown from './Markdown.svelte'; import Receipt from './Receipt.svelte'; import WorkSteps from './WorkSteps.svelte'; import ShellCommand from './ShellCommand.svelte'; import { pendingShell, resolveShell } from './shellAttempts'; import type { Scope } from '../changeset'; import AgentsButton from '../AgentsButton.svelte'; import ArtifactsButton from '../ArtifactsButton.svelte'; import SkillsButton from '../SkillsButton.svelte'; import JobsButton from '../JobsButton.svelte'; import { headline } from '../jobs.svelte'; import MenuButton from '../MenuButton.svelte'; import ContextChip from './ContextChip.svelte'; import ModelPicker from './ModelPicker.svelte'; import { btwCommand, catalogue, cdCommand, invoke, type Command, } from '../commands'; import { SideQuestions } from '../side-questions.svelte'; import { layout } from '../layout.svelte'; import SideQuestion from './SideQuestion.svelte'; import { cdTarget, splitHost } from '../folderQuery'; import { CdQuestion } from './cd.svelte'; import { lazy } from '../lazy'; // Panels a chat opens on request, loaded the first time. const artifactView = lazy(() => import('../views/ArtifactView.svelte')); const displayView = lazy(() => import('../views/DisplayView.svelte')); const diffClient = lazy(() => import('../views/DiffClient.svelte')); const terminalView = lazy(() => import('../views/TerminalView.svelte')); const shellCommandView = lazy( () => import('../views/ShellCommandView.svelte'), ); const agentsView = lazy(() => import('../views/AgentsView.svelte')); const extensionsView = lazy(() => import('../views/ExtensionsView.svelte')); const cdDialog = lazy(() => import('./CdDialog.svelte')); const termsDialog = lazy(() => import('../TermsDialog.svelte')); import type { Panel } from './panel';
// On the canvas a chat is a window, whose reviews, artifacts and notes open // beside it. `inline` is the phone's single chat: a review opens inside the // chat, under the line that asked for it, an artifact above the composer, // and there are no notes. `full` is the full-screen chat (FocusChat), inline // too: the model, artifacts, jobs and a terminal sit in the composer, and // reviews, artifacts and terminals go to `onopen`, beside the chat. let { sessionId, session, windowId, inline = false, full = false, handle, chips, onusage, onopen, onback, }: { sessionId: string; session: Session | undefined; windowId: string; inline?: boolean; full?: boolean; handle?: Snippet; /** The window's chips, to sit under the composer instead of in its title bar. */ chips?: Snippet; onusage?: (usage: Usage | null, entries: HistoryEntry[]) => void; onopen?: (panel: Panel) => void; /** The phone's way back to its session list, from the chat's header. */ onback?: () => void; } = $props();
let extensionsBack = $state<HTMLButtonElement>(); let extensionsOpen = $state(false); $effect(() => { if (extensionsOpen) extensionsBack?.focus({ preventScroll: true }); }); let agentsBack = $state<HTMLButtonElement>(); let agentsOpen = $state(false); $effect(() => { if (agentsOpen) agentsBack?.focus({ preventScroll: true }); }); let sessionMenu = $state(false); function openExtensions() { history.pushState({ ...history.state, sheet: 'extensions' }, ''); extensionsOpen = true; sessionMenu = false; } function closeExtensions() { if (history.state?.sheet === 'extensions') history.back(); else extensionsOpen = false; } function openAgentsTree() { history.pushState({ ...history.state, sheet: 'agents' }, ''); agentsOpen = true; sessionMenu = false; } function closeAgents() { if (history.state?.sheet === 'agents') history.back(); else agentsOpen = false; } function openAgent(agent: Session, replaceSheet = false) { sessions.adopt(agent); agentsOpen = false; if (full) { layout.focusSession(agent.id); return; } if (replaceSheet) { history.replaceState({ session: agent.id }, ''); layout.session = agent.id; } else { layout.open(agent.id); } }
/** The phone's diff client, open as a sheet over the chat. */ let shown = $state<{ at: string; turnId: string; from: number; scope: Scope; jump?: { path: string; at: number }; } | null>(null); /** A job's output opened inside the phone's chat, where there is no canvas to put a window on. */ let terminal = $state<{ job: string; command: string; kind?: 'command' | 'cell'; } | null>(null); /** Human command output opened in the phone's dock; its process outlives the view. */ let commandPanel = $state<string | null>(null); function openShellCommand(commandId: string) { if (!inline) boards.board?.openShellCommand(sessionId, commandId, windowId); else if (onopen) onopen({ kind: 'command', commandId }); else { terminal = null; artifact = null; displayed = null; commandPanel = commandId; } } /** An artifact opened inside the phone's chat. */ let artifact = $state<Made | null>(null); /** A `display()` block opened inside the phone's chat. */ let displayed = $state<Displayed | null>(null);
function openArtifact(made: Made) { if (onopen) onopen({ kind: 'artifact', ...made }); else if (inline) { commandPanel = null; displayed = null; artifact = made; } else boards.board?.openArtifact(made.id, sessionId, made.version, windowId); }
function openDisplay(item: Displayed) { if (onopen) onopen({ kind: 'display', ...item }); else if (inline) { commandPanel = null; terminal = null; artifact = null; displayed = item; } else boards.board?.openDisplay( sessionId, item.entryId, item.index, item.title, item.detail, windowId, ); }
/** * Opens the diff client on the turn's changes: beside the window, or over the * phone's chat, with `path` in view when a line of work asked about one file. */ function review(at: string, turnId: string, from: number, path?: string) { if (!inline) return boards.board?.openReview(sessionId, turnId, from, windowId, path); const jump = path ? { path, at: Date.now() } : undefined; if (onopen) return onopen({ kind: 'review', turnId, from, scope: 'turn', jump }); if (!shown) history.pushState({ ...history.state, sheet: 'changes' }, ''); shown = { at, turnId, from, scope: 'turn', jump }; }
// The sheet is a page of its own to the browser: its back closes it, and // so does the close button, by going back. function closeSheet() { if (history.state?.sheet === 'changes') history.back(); else shown = null; } $effect(() => { if (!inline) return; const back = () => { if (history.state?.sheet !== 'changes') shown = null; if (history.state?.sheet !== 'extensions') extensionsOpen = false; if (history.state?.sheet !== 'agents') agentsOpen = false; }; addEventListener('popstate', back); return () => removeEventListener('popstate', back); });
// svelte-ignore state_referenced_locally const sideQuestions = new SideQuestions(sessionId); // svelte-ignore state_referenced_locally const transcript = new Transcript( sessionId, () => prefs.collapseTraces, sideQuestions, ); // The stream's phase is fresher than the session list's; the list answers until the stream does. const view = $derived( session && transcript.phase ? { ...session, status: { ...session.status!, phase: transcript.phase } } : session, ); const running = $derived(busy(view)); // Between the session going idle and its last text committing, the footer // keeps its place so the sign-off can take it without the thread jumping. const answering = $derived(transcript.live.some((item) => item.text.trim())); $effect(() => { transcript.running = running; });
const rootId = $derived(session?.root_id ?? sessionId); const needsFamily = $derived( !!session && transcript.blocks.some( (block) => block.kind === 'user' && block.mail?.senderId && !block.mail.answer && block.mail.senderId !== session.parent_id, ), ); let family = $state.raw<Session[]>([]); $effect(() => { family = []; if (!needsFamily) return; return watchFamily(rootId, (found) => { if (found) family = found; }); }); const knownSessions = $derived.by(() => { if (!family.length) return sessions.byId; const merged = new Map(sessions.byId); for (const member of family) merged.set(member.id, member); return merged; }); // Untracked: what the callback reads must not rerun this, or two chats of // one session (a window and the full-screen chat) overwrite each other forever. $effect(() => { const usage = transcript.usage; const entries = transcript.entries; untrack(() => onusage?.(usage, entries)); }); let copied = $state<string | null>(null); /** The failure row opened to all its error said. */ let unfolded = $state<string | null>(null);
async function copy(key: string, text: string) { await copyText(text); copied = key; setTimeout(() => copied === key && (copied = null), 1400); } // The turn whose reply the pointer is over, by the key of its sign-off row, // which shows its actions (trace, copy) for the whole reply and not just // while the row itself is under the pointer. Found in the page when the // pointer moves: a reply's sign-off is the next one after it, before the // next message you sent. let hot = $state<string | null>(null);
function hover(event: PointerEvent) { let row = (event.target as Element).closest('.assistant, [data-end]'); while ( row && !row.hasAttribute('data-end') && !row.classList.contains('user') ) row = row.nextElementSibling; hot = row?.getAttribute('data-end') ?? null; } const last = $derived( transcript.groups.findLast( (group) => group.kind !== 'user' || group.state === 'seen', ), ); const activity = $derived( session?.activity?.lines .findLast((line) => line.text.trim()) ?.text.trim() ?? '', ); const compaction = $derived( view?.status?.phase === 'compacting' ? (transcript.compaction ?? view.status.compaction ?? null) : null, ); const compactionElapsed = $derived.by(() => { clock.tick; const started = compaction ? Date.parse(compaction.started_at) : NaN; return Number.isFinite(started) ? formatElapsed(Math.max(0, Date.now() - started)) : ''; }); const compactionLabel = $derived.by(() => { if (!compaction) return ''; const stages = { preparing: 'preparing history', summarizing: 'summarizing chunks', merging: 'combining summaries', notes: 'rewriting notes', }; const hasBatchCount = compaction.total !== null && (compaction.stage === 'summarizing' || compaction.total > 1); let count = ''; if (hasBatchCount) count = ` ${compaction.completed}/${compaction.total} completed`; else if (compaction.completed > 0) count = ` ${compaction.completed} completed`; const active = (compaction.active ?? 0) > 0 ? ` · ${compaction.active} active` : ''; const strategy = compaction.strategy ? ` · ${compaction.strategy}` : ''; return `compacting${strategy} · ${stages[compaction.stage]}${count}${active}${compactionElapsed ? ` · ${compactionElapsed}` : ''}`; }); $effect(() => { if (compaction) return clock.use(); });
let scroller = $state<HTMLElement>(); let thread = $state<HTMLElement>(); let top = $state<HTMLElement>(); let pinned = $state(true); let dockHeight = $state(0); // The end of the chat as it was when the reader scrolled up from it, so a // new message or more of a reply below can be told from older ones loading // above. const end = $derived( `${transcript.groups.at(-1)?.key ?? ''}:${transcript.live.reduce((length, item) => length + item.text.length, 0)}`, ); let leftAt = $state<string | null>(null); const unseen = $derived(!pinned && leftAt !== null && end !== leftAt); let settled = $state(false); let older = false;
// What the agent makes while the chat is open opens as it arrives: beside // the chat on the canvas, inside it on a phone. let opened = 0; $effect(() => { const made = transcript.made; for (const item of made.slice(opened)) { if (inline) openArtifact(item); else boards.board?.artifactMade(item.id, sessionId, item.version, windowId); } opened = made.length; });
let openedDisplays = 0; $effect(() => { const shown = transcript.displayed; for (const item of shown.slice(openedDisplays)) { if (inline) openDisplay(item); else boards.board?.displayShown( sessionId, item.entryId, item.index, item.title, item.detail, windowId, ); } openedDisplays = shown.length; });
// Full screen: a turn that changed files puts its changes on the desk as // it ends. The turn the chat opened on is only remembered. let ended: string | null = null; $effect(() => { if (!full || !settled) return; const end = transcript.groups.findLast((group) => group.kind === 'end'); if (!end || end.kind !== 'end' || end.key === ended) return; const first = ended === null; ended = end.key; if (!first && end.changed.files && end.turnId) untrack(() => review(end.key, end.turnId!, end.from)); });
onMount(() => { transcript .load() .then(restore) .finally(() => (settled = true)); transcript.attach(); return () => { keep(); transcript.detach(); }; });
function keep() { // Unmounted before it got back to its place, it keeps the one it had. if (!settled) return; places.delete(windowId); if (pinned || !reading) return; places.set(windowId, { block: `[data-block="${CSS.escape(reading.block.getAttribute('data-block')!)}"]`, share: reading.share, }); if (places.size > 64) places.delete(places.keys().next().value!); }
/** Back to where the chat was read before it unmounted, reading earlier pages until that block is in; else its end. */ async function restore() { const place = places.get(windowId); if (!place) return toBottom(); let block: Element | null = null; for (let pages = 0; ; pages++) { await tick(); block = thread?.querySelector(place.block) ?? null; if (block || !transcript.more || pages >= 20) break; await transcript.loadOlder(); } if (!block || !scroller) return toBottom(); holdAt(block, place.share); pinned = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 40; if (!pinned) { mark(); leftAt = end; } }
// The stream says when history grows. Polling is the fallback while it is // down, quick while the session works. $effect(() => { const every = transcript.streaming ? 20_000 : running || transcript.pending.length ? 1200 : 5000; let timer: ReturnType<typeof setTimeout>; const tickOnce = async () => { if (!document.hidden && !transcript.loading) await transcript.poll().catch(() => {}); timer = setTimeout(tickOnce, every); }; timer = setTimeout(tickOnce, every); return () => clearTimeout(timer); });
// Earlier pages load one at a time when the reader nears the top, keeping // their place. Watching starts once the first page sits at the bottom. $effect(() => { if (!top || !scroller || !settled) return; const observer = new IntersectionObserver( async ([entry]) => { if (!entry.isIntersecting || !transcript.more || older || !scroller) return; older = true; const before = scroller.scrollHeight; try { await transcript.loadOlder(); await tick(); scroller.scrollTop += scroller.scrollHeight - before; } finally { older = false; } }, { root: scroller, rootMargin: '200px 0px 0px 0px' }, ); observer.observe(top); return () => observer.disconnect(); });
// Stay at the bottom as messages arrive, unless the reader scrolled up. $effect(() => { transcript.groups; activity; transcript.live; if (pinned) toBottom(); });
// A reflow resizes the thread and its text rewraps: a chat at its end stays // there, and one read further up stays as far through the block at its top // as it was (holding that block's top still, as scroll anchoring does, moves // everything after it as the block rewraps). The block is the top one of the // transcript's own (`data-block`), so `places` can find it again. let reading: { block: Element; share: number } | null = null;
function mark() { const blocks = thread?.children; if (!scroller || !blocks?.length) return; const edge = scroller.getBoundingClientRect().top; let low = 0; let high = blocks.length - 1; while (low < high) { const middle = (low + high + 1) >> 1; if (blocks[middle].getBoundingClientRect().top <= edge) low = middle; else high = middle - 1; } let block: Element | null = blocks[low]; while (block && !block.hasAttribute('data-block')) block = block.nextElementSibling; const rect = block?.getBoundingClientRect(); reading = block && rect?.height ? { block, share: (edge - rect.top) / rect.height } : null; }
/** Scrolls the thread so its top edge is `share` of the way through `block`. */ function holdAt(block: Element, share: number) { if (!scroller) return; const rect = block.getBoundingClientRect(); scrollTo( scroller.scrollTop + (rect.top + share * rect.height - scroller.getBoundingClientRect().top) / zoom(), ); }
// The thread is watched as well as the view: maths, diagrams and images // draw after their message is in, and a chat at its end must follow them // rather than let scroll anchoring leave it short of the end. $effect(() => { if (!scroller || !thread) return; const view = scroller; const observer = new ResizeObserver(() => { if (pinned) return scrollTo(view.scrollHeight); if (reading?.block.isConnected) holdAt(reading.block, reading.share); }); observer.observe(view); observer.observe(thread); return () => observer.disconnect(); });
/** * Screen pixels over the thread's own: the chat's zoom, a window's, a * canvas's. Read off the whole thread, whose rounded height is off by far * less than the scroller's would be over a long jump. */ function zoom() { return thread ? thread.getBoundingClientRect().height / thread.offsetHeight || 1 : 1; }
async function toBottom() { await tick(); if (scroller) scrollTo(scroller.scrollHeight); }
/** * Scrolls the thread for the reader: the scroll event that lands where this * put it neither unpins nor moves where they are reading. A wheel that moves * it on in the same frame still counts as theirs. */ function scrollTo(top: number) { if (!scroller) return; scroller.scrollTop = top; autoScrollTop = scroller.scrollTop; }
// On a phone the composer floats over the thread, which scrolls on under it; // a draft growing taller must not bury the end of a chat that was there. $effect(() => { if (!inline) return; dockHeight; if (pinned) toBottom(); });
let autoScrollTop: number | null = null;
function scrolled() { if (!scroller) return; const automatic = scroller.scrollTop === autoScrollTop; autoScrollTop = null; if (automatic) return; const was = pinned; pinned = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 40; if (!pinned) mark(); if (was && !pinned) leftAt = end; else if (pinned) leftAt = null; }
/** Back to the end at once. */ function latest() { if (scroller) scroller.scrollTop = scroller.scrollHeight; }
// Notes tied to this chat or any window of its session go with the next // message, after what was typed, unless they are kept alone. const going = $derived( !inline && boards.board ? drafts(boards.board, sessionId).filter((note) => !note.data.alone) : [], );
/** Moves the draft into a note beside the window, for writing at length. */ function popout(text: string) { const board = boards.board; const frame = scroller?.closest('.window-slot')?.getBoundingClientRect(); const spot = frame && board?.besideWindow(windowId, frame.bottom - 240); board?.addNote( spot ? { x: spot.x, y: spot.y } : { x: 0, y: 0 }, { kind: 'window', window: windowId }, text, spot?.canvas, ); }
/** Stops the turn; messages queued behind it were cancelled, so they come back to the composer. */ async function stop() { const id = sessionId; // An edit ends first, so the message it held comes back through the cancel path. transcript.cancelEdit(); const cancelled = await interruptSession(id); const sends = transcript.take(cancelled); if (sends.length) draftOf(id).restore(sends); }
// The first message on a profile whose sign-in breaks its provider's terms // waits behind the warning: send goes on and records it seen for every // client, edit puts the message back in the composer. type Held = { terms: LoginTerms; text: string; images: Attached[]; files: AttachedFile[]; }; let held = $state<Held | null>(null); $effect(() => { void sessionId; void terms.refresh(); });
function send(text: string, images: Attached[], files: AttachedFile[]) { if (transcript.editing) return void transcript.saveEdit(text, images, files); const owed = terms.owed(session?.provider_profile); if (owed) held = { terms: owed, text, images, files }; else deliver(text, images, files); }
function sendHeld() { if (!held) return; const { terms: seen, text, images, files } = held; held = null; deliver(text, images, files); void terms.dismiss(seen.id); }
function editHeld() { if (!held) return; const { text, images, files } = held; held = null; draftOf(sessionId).restore([{ text, images, files }]); }
function deliver(text: string, images: Attached[], files: AttachedFile[]) { pinned = true; const board = boards.board; if (!board || !going.length) return void transcript.send(text, images, files); transcript.send(compose(board, going, text), images, files); finishNotes(board, going); }
/** Up arrow in an empty composer: edits the newest message still waiting. */ function editLatest() { const id = transcript.latestOwn(); if (id) void transcript.beginEdit(id); }
// Slash commands: skills and command inputs join the transcript like a // message; reads and changes answer here, above the composer, until dismissed. let commands = $state<Command[]>([]); let answer = $state<{ name: string; text: string; failed: boolean } | null>( null, ); let refreshCommands = $state<() => void>(() => {}); const offered = $derived([...commands, cdCommand, btwCommand]); $effect(() => { const id = sessionId; const controller = new AbortController(); let pending = false; commands = []; // Refresh on opening autocomplete, not on every keystroke or a polling timer. // A slow initial fetch and the first slash share one request. const refresh = () => { if (pending || controller.signal.aborted) return; pending = true; catalogue(id, controller.signal) .then((found) => { if (controller.signal.aborted) return; commands = found; if (answer?.name === 'commands') answer = null; }) .catch((error) => { if (!controller.signal.aborted) answer = { name: 'commands', text: String((error as Error).message ?? error), failed: true, }; }) .finally(() => (pending = false)); }; refreshCommands = refresh; refresh(); return () => controller.abort(); });
async function shell(commandText: string): Promise<boolean> { let attempt: ReturnType<typeof pendingShell>; try { attempt = pendingShell(sessionId, commandText); } catch (error) { answer = { name: '!', text: `couldn't save retry identity: ${(error as Error).message ?? error}`, failed: true, }; return false; } try { let result; try { result = await getShellCommand(sessionId, attempt.id); } catch (error) { if (!(error instanceof ApiError && error.status === 404)) throw error; result = await submitShellCommand( sessionId, attempt.id, attempt.command, ); } pinned = true; transcript.trackShell(result); try { resolveShell(attempt); } catch (error) { answer = { name: '!', text: `command was recorded, but its retry marker could not be cleared: ${(error as Error).message ?? error}`, failed: true, }; } return true; } catch (error) { answer = { name: '!', text: String((error as Error).message ?? error), failed: true, }; return false; } }
async function command(chosen: Command, rest: string) { answer = null; if (chosen === btwCommand) return btw(rest); if (chosen === cdCommand) return cd(rest); try { const outcome = await invoke(sessionId, chosen, rest, uuidv7()); if (outcome) answer = { name: chosen.slash_name, text: chosen.delivery === 'mutation' ? 'done' : describe(outcome.result), failed: false, }; else pinned = true; if (chosen.delivery === 'mutation') sessions.refresh(); } catch (error) { answer = { name: chosen.slash_name, text: String((error as Error).message ?? error), failed: true, }; } }
// /btw as the client runs it: the question goes to the side-question // resource and its card, never to the transcript or pending inputs. async function btw(rest: string) { if (!(await sideQuestionsSupported())) { answer = { name: '/btw', text: 'this daemon is too old for side questions; update it and try again', failed: true, }; return; } if (!rest) { if (!sideQuestions.reopen()) answer = { name: '/btw', text: 'no side question yet; ask one with /btw followed by your question', failed: false, }; return; } try { await sideQuestions.ask(rest); } catch (error) { answer = { name: '/btw', text: String((error as Error).message ?? error), failed: true, }; } }
/** Opens the session a side question continued in, the way any session opens here. */ async function openContinued(id: string) { const draft = draftOf(id); draft.focusRequested = true; sessions.refresh(); if (full) layout.focusSession(id); else if (layout.phone) layout.open(id); else boards.board?.openSession(id, windowId); await tick(); if (draft.focus) { draft.focusRequested = false; draft.focus(); } }
// /cd as the terminal runs it: a folder here moves the session at once; one // on another host asks whether the whole agent moves to that host's daemon. let question = $state<CdQuestion | null>(null);
async function cd(typed: string) { if (!session) return; if (session.move_pending) return reviewChecklist(); if (!typed) { answer = { name: '/cd', text: 'type a folder: /cd path, or /cd host:/path', failed: false, }; return; } const target = cdTarget(session.workspace, typed); if (splitHost(target)[0]) { question?.close(); question = new CdQuestion(sessionId, target); return; } await moveTo(target); }
/** Moves the session to another folder on this daemon, its kernel where that folder is; a ~ folder is named by the daemon first. */ async function moveTo(target: string) { try { const [host, path] = splitHost(target); await moveWorkspace( sessionId, host || path.startsWith('/') ? target : (await browse(target)).directory, ); sessions.refresh(); } catch (error) { answer = { name: '/cd', text: String((error as Error).message ?? error), failed: true, }; } }
/** Opens the checklist of the move waiting on it again, after a later. */ function reviewChecklist() { const pending = session?.move_pending; if ( question && (question.phase === 'checklist' || question.phase === 'finishing') ) question.hidden = false; else if (pending) { question?.close(); question = new CdQuestion(sessionId, pending.host, pending.transfer_id); } } const pendingHost = $derived( session?.moved ? '' : question?.phase === 'checklist' || question?.phase === 'finishing' ? question.host : (session?.move_pending?.host ?? ''), );
function closeQuestion() { question?.close(); question = null; }
/** No: the kernel alone goes to the folder's host, as /cd always did. */ function answerNo() { const target = question!.target; closeQuestion(); void moveTo(target); }
onMount(() => () => question?.close());
// The list learns the session moved, or waits on its checklist, as soon as the move does. $effect(() => { if (question?.phase === 'moved' || question?.phase === 'checklist') sessions.refresh(); });
// A moved session's daemon home there, read from its move once. let movedHome = $state<string | null>(null); $effect(() => { const transfer = session?.moved?.transfer_id; movedHome = null; if (!transfer) return; const controller = new AbortController(); readMove(transfer, controller.signal) .then((move) => (movedHome = move.target_home)) .catch(() => {}); return () => controller.abort(); });
/** A command's answer as text: its message when it has one, else the JSON. */ function describe(result: unknown): string { if (typeof result === 'string') return result; const record = result as Record<string, unknown> | null; for (const key of ['text', 'message', 'summary']) if (typeof record?.[key] === 'string') return record[key] as string; return JSON.stringify(result, null, 2); }</script>
{#if agentsOpen} <div class="extensions-page agents-page"> <header class="bar"> <button class="back" bind:this={agentsBack} onclick={closeAgents} aria-label="back to chat" > <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" ><path d="M10 3 5 8l5 5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg > </button> <h1>agents</h1> </header> {#await agentsView() then AgentsView}<AgentsView sessionId={rootId} onopen={(agent) => openAgent(agent, true)} />{/await} </div>{/if}
{#if extensionsOpen} <div class="extensions-page"> <header> <button bind:this={extensionsBack} onclick={closeExtensions} aria-label="back to chat" > <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><path d="m10 3-5 5 5 5" fill="none" stroke="currentColor" stroke-width="1.5" /></svg >back </button> <h1>extensions</h1> </header> {#await extensionsView() then ExtensionsView}<ExtensionsView {sessionId} />{/await} </div>{/if}
<div class="chat" inert={extensionsOpen || agentsOpen} class:inline class:full style:--dock={inline ? `${dockHeight}px` : undefined}> <div class="file-drop" aria-hidden="true"> <span>drop files here</span><small >{session?.location?.host ? 'images join your next message; files need a local workspace' : 'images and files join your next message'}</small > </div> {#if inline && !full} <header class="bar"> {#if onback} <button class="back" aria-label="back to sessions" onclick={onback}> <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" ><path d="M10 3 5 8l5 5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg > </button> {/if} <h1>{session?.name || 'untitled session'}</h1> <MenuButton label="session menu" bind:open={sessionMenu}> {#snippet icon()}<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" ><circle cx="3" cy="8" r="1" fill="currentColor" /><circle cx="8" cy="8" r="1" fill="currentColor" /><circle cx="13" cy="8" r="1" fill="currentColor" /></svg >{/snippet} {#if session?.parent_id} <li><button onclick={openAgentsTree}>agent tree</button></li> {/if} <li><button onclick={openExtensions}>extensions</button></li> <li> <button onclick={() => { sessionMenu = false; copyText(sessionId); }}>copy session id</button > </li> </MenuButton> <span class="top-tools"> <AgentsButton {sessionId} {rootId} busy={running} onopen={(agent) => openAgent(agent)} ontree={openAgentsTree} /> <ArtifactsButton {sessionId} busy={running} onopen={(found) => openArtifact({ id: found.id, version: found.version, title: found.title, })} /> <SkillsButton {sessionId} busy={running} /> <JobsButton {sessionId} onopen={(job) => { commandPanel = null; displayed = null; terminal = { job, command: '' }; }} /> </span> </header> {/if} <div class="scroller nowheel" bind:this={scroller} onscroll={scrolled}> {#if !settled && !transcript.error} <!-- Shaped like the end of a typical chat, as measured at phone width: a work line, your message, more work, then the reply's last lines and its sign-off, sitting at the bottom where the chat will open. --> <div class="skeleton" aria-label="loading the chat" role="status"> <span class="bar work"></span> <span class="bubble-shape"></span> <span class="bar work"></span> {#each [92, 100, 84, 96, 70, 88, 100, 60] as width, index (index)}<span class="bar line" style:width="{width}%" ></span>{/each} <span class="bar end"></span> </div> {/if} <div class="thread" class:waiting={!settled} bind:this={thread} onpointerover={hover} onpointerleave={() => (hot = null)} role="presentation" > <div bind:this={top}></div> {#if transcript.loading} <span></span> {:else if transcript.error} <p class="quiet error"> (。•︿•。) couldn't read the transcript: {transcript.error} </p> {:else if transcript.groups.length === 0} <p class="quiet">(˶ᵔ ᵕ ᵔ˶) nothing here yet. say hi below</p> {:else if transcript.more} <p class="quiet">earlier messages load as you scroll up</p> {/if}
{#each transcript.groups as group (group.key)} {#if group.kind === 'user'} {@const unseen = group.state === 'sending' || group.state === 'sent'} {@const agentRole = agentBubbleRole(group, sessionId, knownSessions)} {@const senderLabel = (group.from?.trim() || null) ?? (agentRole ? 'agent' : null)} <div class="user" class:incoming={agentRole !== null} class:subagent={agentRole === 'subagent'} class:other-agent={agentRole === 'agent'} class:failed={group.state === 'failed'} data-entry={group.key} data-block={group.key} > {#if senderLabel || group.gap} <span class="plate" title={agentRole ? `${agentRole} · ${senderLabel}` : undefined} >{#if agentRole === 'subagent'}<svg class="subagent" viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" ><path d="M3.5 8h3m0 0c2 0 1-4 3.5-4H12.5M6.5 8c2 0 1 4 3.5 4h2.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" /><circle cx="3" cy="8" r="1.4" fill="currentColor" /><circle cx="13" cy="4" r="1.4" fill="currentColor" /><circle cx="13" cy="12" r="1.4" fill="currentColor" /></svg >{/if}<span class:you={!senderLabel} class:subagent={agentRole === 'subagent'} class:other-agent={agentRole === 'agent'} >{senderLabel ?? 'you'}</span >{#if group.gap}<span class="meta">{' · '}{group.gap}</span >{/if}</span > {/if} {#if group.images.length} <div class="pictures" class:unseen> <ImageGallery pictures={group.images} label="Image"> {#snippet children(open)} {#each group.images as picture, index (index)} <a href={picture.src} onclick={(event) => open(event, index)} onkeydown={(event) => { if (event.key === 'Enter') event.stopPropagation(); }} target="_blank" rel="noopener noreferrer" title="Image #{index + 1}" > <img src={picture.src} alt="Image #{index + 1}" width={picture.width} height={picture.height} loading="lazy" /> </a> {/each} {/snippet} </ImageGallery> </div> {/if} {#if group.files.length} <ul class="attached-files" class:unseen aria-label="attached files" > {#each group.files as file, index (index)} {@const name = filenameParts(file.name)} <li title={file.name}> <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><path d="M9 2H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V6L9 2Zm0 0v4h4" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round" /></svg > <span class="attachment-name" ><span>{name.stem}</span><span>{name.extension}</span ></span > <span class="attachment-size">{formatSize(file.size)}</span> </li> {/each} </ul> {/if} {#if group.text.trim()} <div class="bubble" class:unseen> {#each pieces(group.text) as piece, index (index)}{#if piece.kind === 'quote'}<blockquote > {piece.text} </blockquote>{:else if piece.kind === 'code'}<pre>{piece.text}</pre>{:else}<p > {piece.text} </p>{/if}{/each} </div> {/if} {#if group.at || group.skill || (transcript.receipt === group.key && group.state !== 'failed')} <span class="user-foot"> {#if group.skill}<span class="skill" title="loaded the {group.skill} skill" >skill · {group.skill}</span >{/if} {#if group.at} <time class="stamp" datetime={new Date(group.at).toISOString()} title={fullStamp(group.at)}>{stamp(group.at)}</time > {/if} {#if transcript.receipt === group.key && group.state !== 'failed'} <Receipt state={group.state} /> {/if} </span> {/if} {#if group.state === 'failed'} <span class="problem"> not sent: {group.error} <button onclick={() => transcript.retry(group.key.slice('pending:'.length))} >retry</button > <button onclick={() => transcript.discard(group.key.slice('pending:'.length))} >discard</button > </span> {/if} </div> {:else if group.kind === 'assistant'} <div class="assistant" data-entry={group.key} data-block={group.key}> {#if group.plate}<span class="plate agent">albedo</span>{/if} <Markdown text={group.text} /> </div> {:else if group.kind === 'shell'} <ShellCommand {sessionId} command={group.command} onopen={() => openShellCommand(group.command.id)} openLabel={inline ? 'Open command output' : 'Open command on canvas'} /> {:else if group.kind === 'work'} <WorkSteps block={group.key} steps={group.steps} live={running && (group === last || group.steps.some( (step) => step.kind === 'progress' || step.key.startsWith('live:') || (step.kind === 'tool' && !step.done), ))} {transcript} session={view} onreview={(turnId, from, path) => review(group.key, turnId, from, path)} onartifact={openArtifact} ondisplay={openDisplay} /> {:else if group.kind === 'end'} {@const metaText = [ group.elapsedMs >= 1000 ? formatElapsed(group.elapsedMs) : '', group.tools ? `${group.tools} ${group.tools === 1 ? 'tool' : 'tools'}` : '', ] .filter(Boolean) .join(' · ')} {@const hasReview = !!(group.changed.files && group.turnId)} <p class="end" class:hot={hot === group.key} data-end={group.key} data-block={group.key} > <span class="face kaomoji" title={group.mood} >{face(group.mood, group.seed)}</span > {#if metaText} <span class="meta">{metaText}</span> {/if} {#if hasReview} <button class="review" title="review this turn's changes" aria-expanded={inline ? shown?.at === group.key : undefined} onclick={() => review(group.key, group.turnId!, group.from)} > review {group.changed.files} {group.changed.files === 1 ? 'file' : 'files'} {#if group.changed.added || group.changed.removed}<span class="added">+{group.changed.added}</span > <span class="removed">−{group.changed.removed}</span>{/if} </button> {/if} {#if group.seed} <time class="stamp" datetime={new Date(group.seed).toISOString()} title={fullStamp(group.seed)} >{metaText && !hasReview ? `· ${stamp(group.seed)}` : stamp(group.seed)}</time > {/if} {#if group.turnId && group.tools && !inline} <button class="act" title="trace this turn and its agents on a timeline" aria-label="trace" onclick={() => boards.board?.openTrace(sessionId, group.from, windowId)} > <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><path d="M2 4h6M5 8h8M3 12h5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" /></svg > </button> {/if} {#if group.text} <button class="act" title={copied === group.key ? 'copied' : 'copy this reply'} aria-label={copied === group.key ? 'copied' : 'copy'} onclick={() => copy(group.key, group.text)} > {#if copied === group.key} <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><path d="M3.5 8.5l3 3 6-7" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" /></svg > {:else} <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><rect x="5.5" y="5.5" width="8" height="8" rx="2" fill="none" stroke="currentColor" stroke-width="1.5" /><path d="M10.5 3.5v-.2a1.8 1.8 0 0 0-1.8-1.8H3.8A1.8 1.8 0 0 0 2 3.3v4.9a1.8 1.8 0 0 0 1.8 1.8h.2" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" /></svg > {/if} </button> {/if} </p> {:else if group.kind === 'note'} {@const text = group.text.trim()} {#if folds(text)} <details class="note" data-block={group.key}> <summary>{firstSentence(text)}</summary> <p>{text}</p> </details> {:else} <p class="note" data-block={group.key}>{text}</p> {/if} {:else if group.kind === 'failure'} {@const open = unfolded === group.key} <button class="failure" class:open data-block={group.key} aria-expanded={open} title={open ? undefined : group.detail} onclick={() => (unfolded = open ? null : group.key)} > <span class="kaomoji">(。•︿•。)</span> <span class="why" >this turn failed: {group.text}{#if open && group.detail !== group.text}<code >{group.detail}</code >{/if}</span > </button> {:else if group.kind === 'compaction'} <p class="note" data-block={group.key}> {'(>_<)'} earlier context was compacted here </p> {/if} {/each}
{#if (running || answering) && (compaction || !(prefs.collapseTraces && last?.kind === 'work'))} <p class="live" class:settling={!running} class:compacting={!!compactionLabel} > <LiveFace session={view} label={!compactionLabel} />{#if compactionLabel}<span class="activity">{compactionLabel}</span >{:else if !transcript.streaming && activity}<span class="activity" >{activity}</span >{/if} </p> {/if} </div> </div>
<div class="dock" bind:offsetHeight={dockHeight}> {#if settled && !pinned} <button class="latest" onclick={latest}> <svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" ><path d="M8 3v10M3.5 8.5 8 13l4.5-4.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg > {unseen ? 'see new messages' : 'back to latest'} </button> {/if} {@render handle?.()} {#if answer} <section class="answer" class:failed={answer.failed} aria-live="polite"> <header> <span>{answer.name}</span><button aria-label="dismiss" onclick={() => (answer = null)}>×</button > </header> <pre class="nowheel holds-wheel">{answer.text}</pre> </section> {/if} {#if inline} {#if artifact} <section class="inline-artifact" aria-label="artifact"> <header> <span title={artifact.title}>{artifact.title}</span> <button onclick={() => (artifact = null)} aria-label="close the artifact">close</button > </header> {#key artifact.id} {#await artifactView() then ArtifactView}<ArtifactView artifactId={artifact.id} {sessionId} latest={artifact.version} inline />{/await} {/key} </section> {/if} {#if displayed} <section class="inline-terminal" aria-label="display"> <header> <span title={displayed.title}>{displayed.title}</span> <button onclick={() => (displayed = null)} aria-label="close the display">close</button > </header> {#key `${displayed.entryId}:${displayed.index}`} {#await displayView() then DisplayView}<DisplayView {sessionId} entryId={displayed.entryId} index={displayed.index} title={displayed.title} description={displayed.description} detail={displayed.detail} toolbar />{/await} {/key} </section> {/if} {#if commandPanel} <section class="inline-terminal" aria-label="Shell command"> <header> <span>shell command output</span><button onclick={() => (commandPanel = null)} aria-label="Close command output">close</button > </header> {#key commandPanel}{#await shellCommandView() then ShellCommandView}<ShellCommandView {sessionId} commandId={commandPanel} />{/await}{/key} </section> {/if} {#if terminal} <section class="inline-terminal" aria-label="terminal"> <header> <span title={terminal.command} >{terminal.command ? headline(terminal.command, terminal.kind) : 'terminal'}</span > <button onclick={() => (terminal = null)} aria-label="close the terminal">close</button > </header> {#key terminal.job} {#await terminalView() then TerminalView}<TerminalView {sessionId} jobId={terminal.job} onjob={(found) => terminal && ((terminal.command = found.command), (terminal.kind = found.kind))} />{/await} {/key} </section> {/if} {/if} {#if session?.moved} {@const moved = session.moved} <section class="moved" aria-label="moved session"> <p> <span class="arrow" aria-hidden="true">↗</span> moved to {moved.host} · <span class="where">{moved.workspace}</span> </p> <p class="faint"> open it there: <code>albedo web</code> on {moved.host}{movedHome ? ` (albedo home ${movedHome})` : ''} </p> </section> {:else if pendingHost && (!question || question.hidden)} <section class="moving" role="status"> <span >moving to {pendingHost} · checklist pending <span class="faint">· this copy stays live here</span></span > <button onclick={reviewChecklist}>review</button> </section> {:else if question?.hidden} <section class="moving" role="status"> <span>moving to {question.host} · {question.progress}</span> <button onclick={() => question && (question.hidden = false)} >show</button > </section> {/if} <SideQuestion questions={sideQuestions} onopen={openContinued} /> <QueuePanel {sessionId} {transcript} /> <Composer remote={!!session?.location?.host} tools={full ? tools : inline ? runLine : chips} draft={draftOf(sessionId)} onsend={send} editing={!!transcript.editing} onedit={editLatest} oncanceledit={() => transcript.cancelEdit()} busy={running} commands={offered} locked={session?.moved ? `this session moved to ${session.moved.host}; new messages go to it there` : ''} oncommands={refreshCommands} oncommand={command} onshell={shell} compact={inline} onpopout={inline || popped ? undefined : popout} onstop={stop} attached={going.length} placeholder={going.length ? 'add a message, or just send the notes…' : undefined} /> </div> {#if inline && shown} {@const open = shown} <section class="review-sheet" aria-label="changes"> <header> <span>changes</span> <button onclick={closeSheet} aria-label="close the changes" >close</button > </header> {#await diffClient() then DiffClient} <DiffClient {sessionId} workspace={session?.workspace ?? ''} turn={{ turnId: open.turnId, from: open.from }} scope={open.scope} onscope={(scope) => (shown = { ...open, scope })} jump={open.jump} keyOf={(path, change) => `${windowId}#${path}#${change}`} /> {/await} </section> {/if}</div>
{#if question} {#await cdDialog() then CdDialog}<CdDialog {question} onclose={closeQuestion} onno={answerNo} />{/await}{/if}
{#if held} {#await termsDialog() then TermsDialog}<TermsDialog terms={held.terms} title="first message" back="edit" proceed="send" once onback={editHeld} onproceed={sendHeld} />{/await}{/if}
{#snippet runLine()} {#if session} <ContextChip {session} usage={transcript.usage} entries={transcript.entries} /> <ModelPicker {session} /> {/if}{/snippet}
{#snippet tools()} <ArtifactsButton {sessionId} busy={running} up onopen={(found) => openArtifact({ id: found.id, version: found.version, title: found.title, })} /> <JobsButton {sessionId} up onopen={(job) => onopen?.({ kind: 'job', job })} /> <button type="button" class="shell" aria-label="open a terminal" title="open a terminal{session ? ` in ${session.workspace}` : ''}" onclick={() => onopen?.({ kind: 'terminal' })} > <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" ><path d="M3 4.5l3.5 3.5L3 11.5M8 12h5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg > </button> {@render runLine()}{/snippet}
<style> .extensions-page { position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--surface); } .extensions-page header { display: flex; align-items: center; gap: 16px; padding: 12px; } .extensions-page h1 { margin: 0; font-size: 16px; font-weight: 550; } .extensions-page header button { display: inline-flex; align-items: center; gap: 4px; padding: 8px; border: 0; border-radius: 7px; background: var(--well); color: var(--text); font: inherit; cursor: pointer; } .agents-page { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); } .agents-page .bar button.back { display: grid; place-items: center; padding: 0; background: none; color: var(--muted); border-radius: 10px; }
/* The chat reads a size up from the rest of the canvas; everything in it, text and the spacing around it, scales together. */ .chat { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; zoom: 1.15; } .file-drop { position: absolute; z-index: 30; inset: 8px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px; padding: 18px; color: var(--accent); text-align: center; background: color-mix(in oklab, var(--surface) 94%, transparent); border: 2px dashed var(--accent); border-radius: 16px; opacity: 0; visibility: hidden; pointer-events: none; } .file-drop span { font-size: calc(17px * var(--canvas-scale)); } .file-drop small { color: var(--muted); font-size: calc(12px * var(--canvas-scale)); } .chat:global(.file-dragging) .file-drop { opacity: 1; visibility: visible; } /* On a phone the chat is the whole screen: no scaling, the reading size set outright, and the room at the sides given back to the text. */ .chat.inline { position: relative; zoom: 1; } /* The thread ends clear of the floating composer and handle. */ .inline .thread { gap: 12px; padding: 14px 16px calc(var(--dock, 0px) + 16px); font-size: calc(16px * var(--canvas-scale)); line-height: 1.55; } /* Nothing floats over the top of the full-screen chat; the thread starts near it. */ .full .thread { padding-top: 28px; } .full.inline .latest { bottom: calc(100% + 10px); } /* As the menu icons beside it (MenuButton's .icon). */ .shell { display: inline-flex; flex: none; align-items: center; height: 26px; padding: 0 7px; color: var(--muted); background: var(--well); border: 0; border-radius: 8px; cursor: pointer; transition: background-color 120ms ease, color 120ms ease; } .shell:hover { color: var(--text); background: var(--field); } /* The phone's chat says which session it is and leads back to the list. */ .bar { position: relative; z-index: 10; display: flex; flex: none; align-items: center; gap: 6px; height: 46px; padding: 0 10px 0 4px; box-shadow: 0 1px 0 color-mix(in oklab, var(--text) 7%, transparent); } .bar h1 { flex: 1; min-width: 0; margin: 0 0 0 6px; overflow: hidden; font-size: calc(15px * var(--ui-scale)); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; } .back + h1 { margin-left: 0; } .back { display: grid; flex: none; place-items: center; width: 36px; height: 36px; padding: 0; color: var(--muted); background: none; border: 0; border-radius: 10px; cursor: pointer; } .back:active { background: var(--hover); } .top-tools { display: flex; flex: none; align-items: center; gap: 5px; } .inline .dock { position: absolute; right: 0; bottom: 0; left: 0; padding: 0 10px calc(8px * (1 - var(--keyboard, 0))); } /* A band of the chat's ground under the handle and the composer, so the thread fades out behind them instead of showing between them. */ .inline:not(.full) .dock { background: linear-gradient(transparent, var(--surface) 16px); } /* Floats over the end of the thread while it is scrolled up, in the composer's tone; on a phone, above the drawer's handle. */ .latest { position: absolute; bottom: calc(100% + 8px); left: 50%; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 6px 13px 6px 10px; color: var(--text); font: inherit; font-size: calc(12.5px * var(--canvas-scale)); white-space: nowrap; background: var(--field); border: 0; border-radius: 999px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); cursor: pointer; transform: translateX(-50%); } .latest:hover { background: color-mix(in oklab, var(--field), var(--text) 6%); } .latest svg { color: var(--accent); } /* Until the first page is in and scrolled to its end, the thread stays unseen and the skeleton holds its place, so it never shows its top and then jumps. */ .thread.waiting { visibility: hidden; } /* A row off screen skips layout and paint: a long session holds tens of thousands of elements, which every page read and every delta would lay out again. `auto` keeps a row's last drawn height once it has been seen. */ .thread > :global([data-block]) { content-visibility: auto; contain-intrinsic-size: auto 80px; } .skeleton { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 12px; max-width: 720px; margin: 0 auto; padding: 18px 20px 24px; overflow: hidden; pointer-events: none; } .inline .skeleton { padding: 12px 16px calc(var(--dock, 0px) + 32px); } .skeleton > * { flex: none; border-radius: 8px; background: var(--well); animation: pulse 1.6s ease-in-out infinite; } .skeleton .work { width: 58%; height: 14px; margin: 4px 0; } .skeleton .bubble-shape { align-self: flex-end; width: 64%; height: 72px; border-radius: 16px 16px 2px 16px; background: var(--bubble); } .skeleton .line { height: 14px; margin: 0; } .skeleton .line + .line { margin-top: -2px; } .skeleton .end { width: 30%; height: 12px; } @keyframes pulse { 50% { opacity: 0.55; } } @media (prefers-reduced-motion: reduce) { .skeleton > * { animation: none; } } .scroller { position: relative; isolation: isolate; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; } .thread { display: flex; flex-direction: column; gap: 14px; max-width: 720px; margin: 0 auto; padding: 18px 20px 24px; font-size: calc(14px * var(--canvas-scale)); line-height: 1.6; } .quiet { margin: 0; color: var(--muted); font-size: calc(12px * var(--canvas-scale)); text-align: center; } .error { color: var(--danger); } .user { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; margin-top: 6px; } .plate { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: calc(12px * var(--canvas-scale)); font-weight: 560; } .plate svg { flex: none; } .plate .meta { font-weight: 400; } .user-foot { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: calc(11.5px * var(--canvas-scale)); } .user-foot .skill { color: var(--muted); white-space: nowrap; } .stamp { color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; } .you { color: var(--you); } .plate .subagent { color: var(--subagent); } .plate .other-agent { color: var(--peer); } .user.incoming { align-items: flex-start; } .user.incoming .attached-files, .user.incoming .pictures { justify-content: flex-start; } .user.incoming .bubble { border-radius: 16px 16px 16px 2px; } .user.subagent { --bubble-accent: var(--subagent); } .user.subagent .bubble { background: var(--bubble-subagent); border: 1px solid color-mix(in oklab, var(--subagent) 34%, transparent); } .user.other-agent { --bubble-accent: var(--peer); } .user.other-agent .bubble { background: var(--bubble-agent); border: 1px dashed color-mix(in oklab, var(--peer) 34%, transparent); } .agent { display: block; margin-bottom: 2px; color: var(--agent); } .end { display: flex; align-items: baseline; gap: 8px; margin: -4px 0 4px; color: var(--muted); font-size: calc(12px * var(--canvas-scale)); } .end .face { color: var(--agent); font-size: calc(13px * var(--canvas-scale)); } .review { padding: 1px 8px; color: var(--text); font: inherit; background: var(--well); border: 0; border-radius: 6px; cursor: pointer; transition: background-color 120ms ease; } .review:hover { background: var(--selected); } .review .added { color: var(--added); } .review .removed { color: var(--danger); } .act { display: grid; place-items: center; align-self: center; width: 22px; height: 20px; padding: 0; color: var(--muted); background: none; border: 0; border-radius: 5px; cursor: pointer; opacity: 0; transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease; } .end.hot .act, .end:hover .act, .end:focus-within .act, .act:focus-visible { opacity: 1; } .act:hover { color: var(--text); background: var(--hover); } /* No pointer to hover with: the actions stay, quietly. */ @media (hover: none) { .act { opacity: 0.6; } } /* The phone's diff client covers the whole chat, its header and composer too. */ .review-sheet { position: absolute; inset: 0; z-index: 11; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); background: var(--surface); } .review-sheet header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 10px 16px; color: var(--muted); font-size: calc(13px * var(--canvas-scale)); } .review-sheet header span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .review-sheet header button { padding: 6px 12px; color: var(--text); font: inherit; background: var(--well); border: 0; border-radius: 8px; cursor: pointer; } .inline-terminal, .inline-artifact { display: flex; flex-direction: column; height: min(45vh, 360px); margin: 0 0 8px; overflow: hidden; background: var(--well); border-radius: 12px; } /* An artifact takes the height of its page, up to most of the screen. */ .inline-artifact { height: auto; max-height: 70vh; } .inline-terminal header, .inline-artifact header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 12px; color: var(--muted); font-size: calc(12px * var(--canvas-scale)); background: var(--title-bar); } .inline-terminal header span, .inline-artifact header span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .inline-terminal header span { font-family: var(--mono); } .inline-terminal header button, .inline-artifact header button { padding: 2px 8px; color: var(--muted); font: inherit; background: none; border: 0; border-radius: 6px; cursor: pointer; } .inline-terminal header button:hover, .inline-artifact header button:hover { color: var(--text); background: var(--hover); } .bubble { max-width: 85%; padding: 8px 13px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bubble); border-radius: 16px 16px 2px 16px; } .bubble > * { margin: 0; } .bubble > * + * { margin-top: 8px; } .bubble blockquote { padding-left: 10px; color: var(--muted); border-left: 2px solid color-mix(in oklab, var(--bubble-accent, var(--accent)) 45%, transparent); } .bubble pre { overflow-x: auto; font-family: var(--mono); font-size: 0.86em; white-space: pre; } .bubble.unseen, .pictures.unseen, .attached-files.unseen { opacity: 0.6; } .attached-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 85%; margin: 0; padding: 0; list-style: none; } .attached-files li { display: flex; align-items: center; gap: 7px; min-width: 0; max-width: 100%; padding: 7px 10px; background: var(--surface); border: 1px solid color-mix(in oklab, var(--muted) 15%, transparent); border-radius: 9px; } .attached-files svg { flex: none; color: var(--accent); } .attachment-name { display: flex; min-width: 0; font-size: calc(12px * var(--canvas-scale)); } .attachment-name > :first-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .attachment-name > :last-child { flex: none; } .attachment-size { flex: none; color: var(--muted); font-size: calc(10.5px * var(--canvas-scale)); font-variant-numeric: tabular-nums; } .pictures { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 85%; } .pictures a { display: block; line-height: 0; } .pictures img { width: auto; max-width: 220px; height: auto; max-height: 160px; object-fit: cover; border-radius: 12px; } .failed .bubble { box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--danger) 50%, transparent); } .problem { color: var(--danger); font-size: calc(11.5px * var(--canvas-scale)); } .problem button { padding: 0 2px; color: var(--text); font: inherit; text-decoration: underline; background: none; border: 0; cursor: pointer; } .note { margin: 0; color: var(--muted); font-size: calc(12px * var(--canvas-scale)); white-space: pre-wrap; overflow-wrap: anywhere; } details.note { white-space: normal; } details.note summary { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; } details.note p { max-height: 40vh; margin: 4px 0 0; overflow: auto; color: var(--faint); white-space: pre-wrap; } .failure { display: flex; gap: 8px; align-items: baseline; min-width: 0; margin: -4px 0 4px; padding: 0; color: var(--muted); font: inherit; font-size: calc(12px * var(--canvas-scale)); text-align: left; background: none; border: 0; cursor: pointer; } .failure .kaomoji { flex: none; color: var(--danger); } .failure .why { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .failure.open .why { white-space: pre-wrap; overflow-wrap: anywhere; } .failure code { display: block; margin-top: 4px; color: var(--faint); font-family: var(--mono); font-size: calc(11px * var(--canvas-scale)); } .live { display: flex; gap: 8px; min-width: 0; margin: 0; font-size: calc(12.5px * var(--canvas-scale)); } .live.settling { visibility: hidden; } .live.compacting { flex-wrap: wrap; } .live.compacting .activity { flex: 1 1 100%; overflow: visible; overflow-wrap: anywhere; white-space: normal; } .activity { min-width: 0; overflow: hidden; color: var(--muted); font-family: var(--mono); font-size: calc(11.5px * var(--canvas-scale)); white-space: nowrap; text-overflow: ellipsis; } .moved, .moving { margin-bottom: 8px; padding: 8px 12px; font-size: calc(12.5px * var(--canvas-scale)); background: var(--well); border-radius: 12px; } .moved p { margin: 0; overflow-wrap: anywhere; } .moved .arrow { color: var(--accent); } .moved .where, .moved code { font-family: var(--mono); font-size: calc(12px * var(--canvas-scale)); } .moved .faint { margin-top: 2px; color: var(--faint); } .moving { display: flex; align-items: baseline; gap: 10px; color: var(--muted); } .moving > span { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .moving .faint { color: var(--faint); } .moving button { padding: 0; color: var(--accent); font: inherit; background: none; border: 0; cursor: pointer; } .answer { margin-bottom: 8px; padding: 8px 12px 10px; background: var(--well); border-radius: 12px; } .answer header { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-family: var(--mono); font-size: calc(12px * var(--canvas-scale)); } .answer header button { padding: 0 4px; color: var(--faint); font-size: calc(16px * var(--canvas-scale)); background: none; border: 0; cursor: pointer; } .answer pre { max-height: 220px; margin: 6px 0 0; overflow: auto; overscroll-behavior: contain; font-family: var(--mono); font-size: calc(12px * var(--canvas-scale)); white-space: pre-wrap; overflow-wrap: anywhere; } .answer.failed pre { color: var(--danger); } .dock { position: relative; display: flex; flex-direction: column; flex: none; width: 100%; max-width: 720px; margin: 0 auto; padding: 0 14px 14px; }</style>