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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597<script lang="ts"> import { tick, untrack } from 'svelte'; import type { Session } from '../api'; import { summarize, type Step } from '../burst'; import { displayedIn, jsonField, madeIn, picturesOf, type Block, type Displayed, type Made, type Transcript, } from '../transcript.svelte'; import ImageGallery from './ImageGallery.svelte'; import Markdown from './Markdown.svelte'; import LiveFace from '../LiveFace.svelte'; import { prefs } from '../prefs.svelte'; import ToolStep from './ToolStep.svelte'; import ArtifactTab from '../ArtifactTab.svelte'; import { traceLink } from '../tracelink.svelte'; import { scrollToShow } from '../anchors';
// A turn's thinking and tool use between two messages (and its mid-turn prose // when traces collapse), read as one line of what it did. The run still going // stays open so it can be watched; collapsed, its line shows the newest step. let { block, steps, live, transcript, session, onreview, onartifact, ondisplay, }: { /** The thread's key for this stretch, which the chat finds its place by. */ block: string; steps: Block[]; live: boolean; transcript: Transcript; session: Session | undefined; onreview: (turnId: string, from: number, path?: string) => void; onartifact: (made: Made) => void; ondisplay?: (shown: Displayed) => void; } = $props();
let chosen = $state<boolean | null>(null); let element = $state<HTMLElement>(); let strip = $state<HTMLElement>(); let seenPictures = 0; let followPictures = true; let scrollPictures = false; // Thoughts show their first lines; a click shows the rest, and keeps this // stretch open when a tool call or prose follows. let whole = $state(new Set<number>()); const open = $derived( chosen ?? (!prefs.collapseTraces && (live || whole.size > 0)), ); const keyed = $derived.by(() => { let thoughts = 0; return steps.map((step) => step.kind === 'thinking' ? { step, key: `thought:${thoughts}`, thought: thoughts++ } : { step, key: step.key, thought: -1 }, ); }); const latest = $derived(steps.at(-1)); const current = $derived.by(() => { if (!latest) return 'working'; if (latest.kind === 'progress') return progressLabel(latest) || latest.name; if (latest.kind === 'tool') return latest.entry.tool?.title || latest.name; if (latest.kind === 'thinking') return 'thinking'; if (latest.kind === 'assistant') return ( latest.text .split('\n') .find((line) => line.trim()) ?.trim() || 'responding' ); return 'working'; }); const tools = $derived( steps.flatMap((step) => (step.kind === 'tool' ? [step.entry] : [])), ); const pictures = $derived(tools.flatMap(picturesOf)); const summary = $derived( summarize( steps.flatMap((step): Step[] => { if (step.kind === 'thinking') return [{ kind: 'thinking', ms: step.ms }]; if (step.kind === 'tool') return [ { kind: 'tool', name: step.name, title: step.entry.tool?.title, args: jsonField(step.entry, 'arguments') as Record<string, unknown> | undefined, trace: step.trace, failed: step.failed, }, ]; return []; }), session?.workspace ?? '', ), );
// What a call touched lives in its trace, which a page may only reference; // fetch it once the line comes into view. $effect(() => { if (!element) return; const observer = new IntersectionObserver( ([entry]) => entry.isIntersecting && transcript.expand(...tools), { rootMargin: '200px' }, ); observer.observe(element); return () => observer.disconnect(); });
// The counts open the turn's review, on the first file this stretch changed. const turnId = $derived( tools.find((entry) => entry.turn_id)?.turn_id ?? null, ); function review() { const from = turnId ? transcript.turnStart(turnId) : null; const path = steps .flatMap((step) => step.kind === 'tool' ? (step.trace?.changes ?? []) : [], ) .find((change) => change.path)?.path; if (turnId && from !== null) onreview(turnId, from, path); }
// Each artifact this stretch made or revised, at its newest version, as a // line that opens it. const made = $derived.by(() => { const newest = new Map<string, Made>(); for (const step of steps) if (step.kind === 'tool') for (const item of madeIn(step.trace)) newest.set(item.id, item); return [...newest.values()]; });
// Each block this stretch showed with `display()`, in order. const displayed = $derived( steps.flatMap((step) => step.kind === 'tool' ? displayedIn(step.entry.id, step.trace) : [], ), );
// A call picked in a trace opens this stretch and is brought into the chat's view. $effect(() => { const entry = traceLink.reveal; if (!entry || !tools.some((tool) => tool.id === entry)) return; chosen = true; traceLink.reveal = null; requestAnimationFrame(() => { const step = element?.querySelector<HTMLElement>( `[data-entry="${CSS.escape(entry)}"]`, ); const scroller = step?.closest<HTMLElement>('.scroller'); if (step && scroller) scrollToShow(scroller, step.getBoundingClientRect()); }); });
$effect(() => { const count = pictures.length; const isLive = untrack(() => live); if (!strip || !count) { seenPictures = count; scrollPictures = false; return; } const grew = count > seenPictures; const initial = seenPictures === 0; seenPictures = count; if (!grew || (initial && !isLive) || !followPictures) return; scrollPictures = true; const box = strip; tick().then(() => { if (box.isConnected && followPictures) box.scrollLeft = box.scrollWidth; }); });
function onStripScroll() { if (!strip) return; followPictures = strip.scrollWidth - strip.scrollLeft - strip.clientWidth < 24; }
function onImageLoad() { if (strip && scrollPictures && followPictures) strip.scrollLeft = strip.scrollWidth; }
function toggle(thought: number) { const next = new Set(whole); if (!next.delete(thought)) next.add(thought); whole = next; }
function progressLabel(step: { name: string; title?: string | null; preview: string; }): string { if (step.title) return step.title; return ( step.preview .split('\n') .find((line) => line.trim()) ?.trim() ?? '' ); }</script>
<div class="work" bind:this={element} data-block={block} data-tools={tools.map((tool) => tool.id).join(' ')}> <div class="head"> <button class="summary" onclick={() => (chosen = !open)} aria-expanded={open} title={live && !open ? current : summary.text} > <svg class="chevron" class:open viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" ><path d="M6 4l4 4-4 4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" /></svg > {#if live && prefs.collapseTraces}<LiveFace {session} />{/if} {#if live && !open}<span class="line">{current}</span> {:else}<span class="line">{summary.text || 'worked'}</span>{/if} {#if summary.failed}<span class="failed">{summary.failed} failed</span >{/if} </button> {#if summary.added || summary.removed} <button class="counts" onclick={review} title="show these changes in the review" ><span class="added">+{summary.added}</span> <span class="removed">−{summary.removed}</span></button > {/if} </div> {#each made as item (item.id)} <div class="artifact-row"> <button class="artifact" onclick={() => onartifact(item)} title="open {item.title}" > <svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" ><rect x="2" y="3" width="12" height="10" rx="2" fill="none" stroke="currentColor" stroke-width="1.4" /><path d="M2 6h12" stroke="currentColor" stroke-width="1.4" /></svg > <span class="verb">{item.version === 1 ? 'made' : 'updated'}</span> <span class="title">{item.title}</span> {#if item.version > 1}<span class="version">v{item.version}</span>{/if} </button> <ArtifactTab artifact={item} /> </div> {/each} {#each displayed as item (`${item.entryId}:${item.index}`)} <div class="artifact-row"> <button class="artifact" onclick={() => ondisplay?.(item)} title="open {item.title}" > <svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" ><path d="M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8z" fill="none" stroke="currentColor" stroke-width="1.4" /><circle cx="8" cy="8" r="1.8" fill="none" stroke="currentColor" stroke-width="1.4" /></svg > <span class="verb">displayed</span> <span class="title">{item.title}</span> </button> </div> {/each} {#if open} <div class="steps"> {#each keyed as { step, key, thought } (key)} {#if step.kind === 'thinking'} <button class="thought" data-entry={step.key} class:whole={whole.has(thought)} onclick={() => toggle(thought)} ><Markdown text={step.text} /></button > {:else if step.kind === 'assistant'} <div data-entry={step.key}><Markdown text={step.text} /></div> {:else if step.kind === 'tool'} <ToolStep entry={step.entry} name={step.name} done={step.done} {transcript} /> {:else if step.kind === 'progress'} <p class="running"> <span class="spinner" aria-label="running"></span><span class="name" >{step.name}</span ><span class="preview">{progressLabel(step)}</span> </p> {/if} {/each} </div> {/if} {#if pictures.length} <div class="pictures" bind:this={strip} onscroll={onStripScroll}> <ImageGallery {pictures} label="Tool image"> {#snippet children(open)} {#each pictures 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="Tool image #{index + 1}" > <img src={picture.src} alt="Tool image #{index + 1}" width={picture.width} height={picture.height} loading="lazy" onload={onImageLoad} /> </a> {/each} {/snippet} </ImageGallery> </div> {/if}</div>
<style> .pictures { display: flex; flex-wrap: nowrap; align-items: flex-start; gap: 8px; margin-top: 8px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; padding-bottom: 2px; } .pictures a { flex: none; display: block; height: 112px; line-height: 0; border-radius: 10px; overflow: hidden; border: 1px solid color-mix(in oklab, var(--muted) 18%, transparent); background: var(--well); } .pictures img { display: block; width: auto; height: 100%; max-width: 260px; object-fit: contain; } .summary { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; text-align: left; padding: 2px 6px; margin: 0 -6px; color: var(--muted); font: inherit; font-size: calc(12.5px * var(--canvas-scale)); background: none; border: 0; border-radius: 6px; cursor: pointer; transition: background-color 100ms ease, color 100ms ease; } .summary:hover { color: var(--text); background: var(--hover); } .chevron { transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1); } .chevron.open { transform: rotate(90deg); } .chevron { flex: none; } .line { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .failed { flex: none; color: var(--danger); } .head { display: flex; align-items: center; gap: 2px; min-width: 0; } .head .summary { flex: 1; width: auto; } .counts { flex: none; padding: 2px 6px; font: inherit; font-variant-numeric: tabular-nums; background: none; border: 0; border-radius: 6px; cursor: pointer; transition: background-color 120ms ease; } .counts:hover { background: var(--hover); } .added { color: var(--added); } .removed { color: var(--danger); } .steps { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; margin: 6px 0 0; padding: 8px 12px; background: var(--well); border-radius: 10px; } .artifact-row { display: flex; align-items: center; width: fit-content; max-width: 100%; margin: 4px -6px 0; } @media (hover: hover) and (pointer: fine) { .artifact-row:not(:hover):not(:focus-within) :global(.tab) { opacity: 0; } } .artifact { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 4px 8px 4px 6px; color: var(--muted); font: inherit; font-size: calc(12.5px * var(--canvas-scale)); text-align: left; background: none; border: 0; border-radius: 6px; cursor: pointer; transition: background-color 100ms ease, color 100ms ease; } .artifact:hover { color: var(--text); background: var(--hover); } .artifact svg { flex: none; color: var(--accent); } .artifact .title { min-width: 0; overflow: hidden; color: var(--accent); font-weight: 560; white-space: nowrap; text-overflow: ellipsis; } .artifact .version { flex: none; color: var(--faint); font-variant-numeric: tabular-nums; } .running { display: flex; align-items: center; gap: 8px; min-width: 0; margin: 0; padding: 3px 0; color: var(--muted); font-size: calc(12.5px * var(--canvas-scale)); } .running .name { flex: none; font-weight: 560; } .running .preview { min-width: 0; overflow: hidden; font-family: var(--mono); font-size: calc(11.5px * var(--canvas-scale)); white-space: nowrap; text-overflow: ellipsis; } .spinner { flex: none; width: 9px; height: 9px; border: 1.5px solid color-mix(in oklab, var(--accent) 25%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .thought { display: -webkit-box; margin: 2px 0 6px; padding: 0; overflow: hidden; color: var(--muted); font: inherit; font-size: calc(12.5px * var(--canvas-scale)); text-align: left; background: none; border: 0; cursor: pointer; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; } .thought.whole { display: block; }</style>