Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859<script lang="ts"> import { untrack, type Snippet } from 'svelte'; import { ApiError, extensionChoices, selectExtensions, reloadSession, type CatalogCandidate, type ExtensionChoices, } from '../api';
// Without a session this is the global page (settings): one column of // defaults for new sessions, no overrides and no reload. // `below` is extra controls under the search row; settings puts its session picker there. let { sessionId, onbusy, below, }: { sessionId?: string; onbusy?: (busy: boolean) => void; below?: Snippet } = $props(); const scoped = $derived(sessionId !== undefined); const memoryOrder = [ 'rolling', 'coding-lcm', 'persistent-agent', 'snapcompact', 'notes', ]; const shelves = [ { id: 'memory' }, { id: 'reach' }, { id: 'channels' }, { id: 'providers' }, { id: 'builtins' }, ]; let data = $state<ExtensionChoices | null>(null); let loading = $state(true); let saving = $state(false); let error = $state(''); let notice = $state(''); let query = $state(''); let folded = $state(new Set(['providers', 'builtins'])); let detail = $state<string | null>(null); let scroller = $state<HTMLDivElement>(); let pinned = $state<string | null>(null); let pinnedLift = $state(0); const pinnedShelf = $derived(shelves.find((shelf) => shelf.id === pinned)); function trackShelf() { if (!scroller) return; const bounds = scroller.getBoundingClientRect(); const scale = bounds.height / scroller.clientHeight || 1; const headings = [ ...scroller.querySelectorAll<HTMLElement>('[data-shelf]'), ]; const current = headings .filter((heading) => { const rect = heading.getBoundingClientRect(); return rect.top <= bounds.top + rect.height; }) .at(-1); pinned = current?.dataset.shelf ?? null; pinnedLift = current ? Math.max(0, (current.getBoundingClientRect().top - bounds.top) / scale) : 0; } $effect(() => { query; folded; data; queueMicrotask(trackShelf); }); type Change = { name: string; scope: 'global' | 'session'; choices: Record<string, boolean | null>; question: string; }; let pending = $state<Change | null>(null); const items = $derived(data?.candidates ?? []); const own = $derived( items.filter((item) => item.session_override !== null).length, ); const selected = $derived(items.find((item) => item.id === detail)); const strategies = $derived(items.filter(strategy)); const busy = $derived(loading || saving); $effect(() => { onbusy?.(saving); }); /** A daemon that sends no extension metadata (older than the global inventory's) leaves rows on builtins. */ const shelfOf = (item: CatalogCandidate) => item.extension?.shelf ?? 'builtins'; const globalOn = (item: CatalogCandidate) => item.global_preference !== false; function strategy(item: CatalogCandidate) { return !!item.extension?.plugins.includes('compaction'); } const matches = (item: CatalogCandidate) => `${item.id} ${item.extension?.summary ?? ''} ${item.description}` .toLowerCase() .includes(query.trim().toLowerCase()); const count = (rows: CatalogCandidate[]) => { const on = rows.filter(globalOn).length; return on === rows.length ? 'all on' : `${on} on`; }; const ownCount = (rows: CatalogCandidate[]) => { const n = rows.filter((item) => item.session_override !== null).length; return n ? `${n} own` : 'this session follows'; };
let reads = 0; async function refresh() { const read = ++reads; loading = true; pending = null; try { const next = await extensionChoices(sessionId); if (read === reads) data = next; } catch (cause) { if (read === reads) error = `couldn't read extensions: ${(cause as Error).message}`; } finally { if (read === reads) loading = false; } } // Reads on mount and again whenever the session changes, so the search and // folds stay as they are while the choices are replaced. $effect(() => { sessionId; untrack(() => { data = null; detail = null; error = ''; notice = ''; void refresh(); }); });
function ask( item: CatalogCandidate, scope: 'global' | 'session', value: boolean | null, ) { error = ''; notice = ''; detail = item.id; const memory = strategy(item); const choices = { [item.id]: value }; const where = scope === 'global' ? 'for all sessions' : 'for this session'; const active = strategies.find( (candidate) => candidate.id !== item.id && (scope === 'global' ? globalOn(candidate) : candidate.effective_enabled), ); let question = value === null ? `follow all sessions for ${item.id} again?` : `${value ? 'enable' : 'disable'} ${item.id} ${where}?`; if (memory && value) { question = `switch memory to ${item.id} ${where}?`; if (active?.id === 'coding-lcm') question += " coding-lcm's summaries stay readable through the lcm tools."; } if (!value && value !== null && shelfOf(item) === 'builtins') question += ' this also turns off extensions that need it.'; question += scope === 'session' ? ' this reloads the session.' : ' reload open sessions to apply it.'; pending = { name: item.id, scope, choices, question }; }
function followMemory() { pending = { name: 'memory', scope: 'session', choices: Object.fromEntries(strategies.map((item) => [item.id, null])), question: 'follow the all-sessions memory choice again? this reloads the session.', }; error = ''; notice = ''; }
async function save() { if (!pending || !data || busy) return; const change = pending; saving = true; error = ''; notice = `saving ${change.name}…`; let saved = false; try { await selectExtensions( sessionId, change.scope, change.choices, change.scope === 'global' ? data.globalETag : data.sessionETag, ); saved = true; pending = null; if (change.scope === 'global') notice = 'saved for all sessions. reload open sessions to apply it.'; else if (sessionId !== undefined) { notice = 'choice saved · reloading this session…'; const result = (await reloadSession(sessionId)).session; notice = result?.state === 'applied' ? `choice saved · session reloaded${result.restart_required ? ' · kernel restart required' : ''}` : `choice saved · reload ${result?.state ?? 'returned no session outcome'}`; if (result?.failure) error = result.failure.detail; if (result?.warnings.length) notice += ` · ${result.warnings.map((warning) => warning.detail).join(' · ')}`; } } catch (cause) { if (cause instanceof ApiError && cause.status === 412) { pending = null; notice = ''; error = 'the configuration changed. review the refreshed choices before saving.'; } else { notice = ''; error = `${saved ? 'choice saved; reload failed' : 'could not save'}: ${(cause as Error).message}`; } } finally { await refresh(); saving = false; } }</script>
{#snippet heading( shelf: (typeof shelves)[number], all: CatalogCandidate[], open: boolean,)} <div class="shelf grid"> <button class="shelf-toggle" aria-expanded={open} onclick={() => { const next = new Set(folded); if (next.has(shelf.id)) next.delete(shelf.id); else next.add(shelf.id); folded = next; }} > <svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" class:open ><path d="m6 3 5 5-5 5" fill="none" stroke="currentColor" stroke-width="1.5" /></svg > <strong>{shelf.id}</strong><span class="count">{all.length}</span> </button> <span class="column">all sessions</span>{#if scoped}<span class="column" >this session</span >{/if} </div>{/snippet}
<div class="extensions nowheel holds-wheel" class:global={!scoped} aria-busy={busy}> <div class="toolbar"> <input type="search" aria-label="search extensions" placeholder="search extensions" bind:value={query} /> {#if scoped && own}<span class="own-count" >{own} own {own === 1 ? 'choice' : 'choices'} here</span >{/if} <button disabled={busy} onclick={() => { error = ''; notice = ''; void refresh(); }}>refresh</button > </div> {#if below}<div class="below">{@render below()}</div>{/if} <div class="feedback" aria-live="polite"> {#if error}<p class="error">(。•︿•。) {error}</p>{/if} {#if notice}<p>{notice}</p>{/if} {#if pending} <div class="confirm"> <p>{pending.question}</p> <button class="primary" disabled={busy} onclick={save} >{saving ? 'saving…' : 'confirm'}</button ><button disabled={busy} onclick={() => (pending = null)}>cancel</button > </div> {/if} </div> <div class="scroll" bind:this={scroller} onscroll={trackShelf}> <div class="pinned"> {#if pinnedShelf} {@render heading( pinnedShelf, items.filter((item) => shelfOf(item) === pinnedShelf.id), !!query.trim() || !folded.has(pinnedShelf.id), )} {/if} </div> {#if loading && !data}<p class="empty" role="status"> (・ω・) reading extensions… </p> {:else if data && !items.some(matches)}<p class="empty"> (・_・) no extensions match this search </p>{/if} {#each shelves as shelf (shelf.id)} {@const all = items .filter((item) => shelfOf(item) === shelf.id) .sort((a, b) => shelf.id === 'memory' ? memoryOrder.indexOf(a.id) - memoryOrder.indexOf(b.id) : 0, )} {@const rows = all.filter(matches)} {@const open = !!query.trim() || !folded.has(shelf.id)} {#if rows.length} <section aria-label={shelf.id}> <div data-shelf={shelf.id} style:visibility={pinned === shelf.id ? 'hidden' : undefined} style:margin-bottom={pinned === shelf.id ? `${-pinnedLift}px` : undefined} inert={pinned === shelf.id} > {@render heading(shelf, all, open)} </div> {#if !open} <div class="fold-summary grid"> <span></span><span>{count(all)}</span>{#if scoped}<span >{ownCount(all)}</span >{/if} </div> {:else} {#if shelf.id === 'builtins'}<p class="warning"> turning a builtin off also turns off what needs it. </p>{/if} {#if shelf.id === 'memory'}<div class="memory-follow"> <span>one memory strategy, with notes as a layer</span >{#if scoped}<button disabled={busy || !strategies.some( (item) => item.session_override !== null, )} onclick={followMemory}>follow all sessions</button >{/if} </div>{/if} {#each rows as item (item.id)} {@const memory = strategy(item)} <div class="row grid" class:own={item.session_override !== null}> <button class="identity" aria-expanded={detail === item.id} onclick={() => (detail = detail === item.id ? null : item.id)} ><strong>{item.id === 'notes' ? '+ notes' : item.id}</strong ><span>{item.extension?.summary ?? item.description}</span ></button > <div class="control"> <span class="phone-label">all sessions</span> {#if memory}<input type="radio" name="memory-global-{sessionId ?? 'all'}" aria-label="{item.id} for all sessions" checked={globalOn(item)} disabled={busy} onclick={(event) => { event.preventDefault(); ask(item, 'global', true); }} /> {:else}<button class="switch" class:on={globalOn(item)} role="switch" aria-checked={globalOn(item)} aria-label="{item.id} for all sessions" disabled={busy} onclick={() => ask(item, 'global', !globalOn(item))} ><span></span></button >{/if} </div> {#if scoped}<div class="control"> <span class="phone-label">this session</span> {#if memory}<input type="radio" name="memory-session-{sessionId}" aria-label="{item.id} for this session" checked={item.session_override === true} disabled={busy} onclick={(event) => { event.preventDefault(); ask(item, 'session', true); }} /> {:else}<div class="segments" role="group" aria-label="{item.id} for this session" > {#each [{ label: 'follow', value: null }, { label: 'on', value: true }, { label: 'off', value: false }] as choice (choice.label)} <button aria-label="{choice.label} {item.id} for this session" aria-pressed={item.session_override === choice.value} disabled={busy} onclick={() => ask(item, 'session', choice.value)} >{choice.label}</button > {/each} </div> <select class="phone-select" aria-label="{item.id} for this session" value={item.session_override === null ? 'follow' : item.session_override ? 'on' : 'off'} disabled={busy} onchange={(event) => { const value = event.currentTarget.value; event.currentTarget.value = item.session_override === null ? 'follow' : item.session_override ? 'on' : 'off'; ask( item, 'session', value === 'follow' ? null : value === 'on', ); }} ><option value="follow">follow</option><option value="on">on</option ><option value="off">off</option></select >{/if} </div>{/if} </div> {#if selected?.id === item.id}<div class="detail"> <p>{selected.description}</p> <dl> <dt>all sessions</dt> <dd>{globalOn(selected) ? 'on' : 'off'}</dd> {#if scoped}<dt>this session</dt> <dd> {selected.session_override === null ? 'follows all sessions' : selected.session_override ? "on, this session's own choice" : "off, this session's own choice"} </dd>{/if} <dt>needs</dt> <dd>{selected.dependencies.join(', ') || 'nothing'}</dd> <dt>provides</dt> <dd> {[ ...(selected.extension?.tools ?? []), ...(selected.extension?.python_modules ?? []), ].join(', ') || 'no tools or python modules'} </dd> </dl> {#if selected.quarantined}<p class="error"> quarantined: {selected.diagnostic?.detail ?? 'unavailable'} </p>{/if} </div>{/if} {/each} {/if} </section> {/if} {/each} </div> <footer> {items.length} extensions · {items.filter( scoped ? (item) => item.effective_enabled : globalOn, ).length} on{scoped ? ' here' : ''} </footer></div>
<style> .extensions { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; overflow: clip; font-size: 13px; container-type: inline-size; } button, input, select { font: inherit; color: var(--text); } button { border: 0; background: var(--well); border-radius: 7px; padding: 6px 10px; cursor: pointer; } button:hover { background: var(--hover); } button:disabled, input:disabled, select:disabled { opacity: 0.5; cursor: default; } button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px 18px; } input[type='search'] { flex: 1; min-width: 130px; width: 100%; border: 0; border-radius: 8px; background: var(--well); padding: 9px 12px; } input::placeholder { color: var(--muted); } .own-count { color: var(--accent); background: color-mix(in oklab, var(--surface), var(--accent) 9%); border-radius: 7px; padding: 5px 8px; font-size: 11px; } .below { padding: 0 18px 12px; } .feedback { padding: 0 18px; flex: none; } .feedback p { margin: 0 0 10px; } .error { color: var(--danger); } .confirm { padding: 12px; margin-bottom: 10px; background: var(--well); border-radius: 10px; } .confirm button + button { margin-left: 6px; } .primary { background: var(--accent); color: var(--bg); } .scroll { overflow: auto; flex: 1; min-height: 0; padding: 0 18px 20px; } section { display: contents; } .grid { display: grid; grid-template-columns: minmax(0, 1fr) 100px 130px; gap: 10px; align-items: center; } .global .grid { grid-template-columns: minmax(0, 1fr) 100px; } .pinned { position: sticky; top: 0; height: 0; z-index: 2; } .shelf { background: var(--surface); padding: 18px 8px 10px; } .shelf-toggle { display: flex; min-width: 0; align-items: center; gap: 7px; text-align: left; padding: 0; background: none; } .shelf-toggle svg { flex: none; } svg.open { transform: rotate(90deg); } .count, .column { color: var(--muted); font-size: 11px; font-weight: 400; } .column { text-align: center; } .row { padding: 9px 8px; border-radius: 8px; } .row:hover { background: var(--hover); } .row.own { background: color-mix(in oklab, var(--surface), var(--accent) 9%); } .identity { display: flex; flex-direction: column; gap: 3px; background: none; padding: 0; min-width: 0; text-align: left; } .identity strong { font-weight: 550; } .identity span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; } .control { display: flex; align-items: center; justify-content: center; gap: 6px; } .switch { width: 30px; height: 18px; padding: 3px; background: var(--field); border-radius: 10px; } .switch span { display: block; height: 12px; width: 12px; border-radius: 50%; background: var(--muted); } .switch.on { background: var(--accent); } .switch.on span { transform: translateX(12px); background: var(--surface); } input[type='radio'] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; cursor: pointer; } select { border: 0; border-radius: 6px; background: var(--well); padding: 5px 7px; max-width: 100%; } .segments { display: flex; padding: 2px; border-radius: 7px; background: var(--well); } .segments button { padding: 4px 6px; border-radius: 5px; background: none; color: var(--muted); font-size: 11px; } .segments button[aria-pressed='true'] { color: var(--text); background: var(--surface); } .segments button[aria-pressed='true']:not(:first-child) { color: var(--accent); } .phone-select { display: none; } .fold-summary { padding: 8px; color: var(--muted); font-size: 12px; } .fold-summary span:not(:first-child) { text-align: center; } .memory-follow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 8px 8px; font-size: 11px; color: var(--muted); } .warning { margin: 0 8px 10px; color: var(--muted); font-size: 12px; } .detail { background: var(--well); border-radius: 8px; padding: 12px; margin: 5px 0 10px; overflow-wrap: anywhere; } .detail p { margin: 0 0 10px; line-height: 1.5; } dl { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; margin: 0; font-size: 12px; } dt { color: var(--muted); } dd { margin: 0; } footer { padding: 10px 18px; color: var(--muted); font-size: 11px; background: var(--well); } .empty { color: var(--muted); padding: 16px 0; } .phone-label { display: none; } @container (max-width: 540px) { .toolbar { padding: 12px; gap: 8px; } .scroll { padding: 0 12px 16px; } .shelf { display: block; padding: 12px 0; } .column, .segments { display: none; } .phone-select { display: block; }
.row { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px; margin-bottom: 6px; background: var(--well); } .identity { flex-basis: 100%; } .identity span { white-space: normal; line-height: 1.4; } .control { flex-basis: 100%; justify-content: space-between; gap: 8px; } .control input[type='radio'] { margin-left: auto; } .phone-label { display: inline; color: var(--muted); font-size: 11px; } .fold-summary { display: flex; flex-wrap: wrap; padding: 0; } .fold-summary span:first-child { flex-basis: 100%; } .memory-follow { margin: 0 0 10px; } .memory-follow > span { display: none; } }</style>