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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715<script lang="ts"> import { onMount } from 'svelte'; import { copyText } from '../api'; import { FRAME_MS, frames } from '../moods'; import { NOTE, QUESTION, type CdQuestion } from './cd.svelte';
// The /cd question for a folder on another host, centred over the page // like the terminal's box: ↑ ↓ move the highlight between yes, the // profile lines of a session that runs there only on another profile, // and no; Enter does the highlighted one (on a profile line it picks that // profile), Esc changes nothing, or, once yes is // moving, puts the box away while the daemon goes on. At the checklist // Enter disarms everything listed and finishes the move; Esc is later. let { question, onno, onclose, }: { question: CdQuestion; /** No: move only the kernel, as /cd always did. */ onno: () => void; onclose: () => void; } = $props();
let dialog = $state<HTMLDialogElement>(); let frame = $state(0); const q = $derived(question); const listing = $derived(q.phase === 'checklist' || q.phase === 'finishing'); const animating = $derived( q.checking || q.phase === 'moving' || q.phase === 'finishing' || (q.phase === 'checklist' && !q.move && !q.failure), ); let copied = $state(''); const face = $derived.by(() => { const shown = frames( 'connecting', [...q.host].reduce((sum, char) => sum * 31 + char.charCodeAt(0), 7), ); return shown[frame % shown.length]; });
onMount(() => dialog?.showModal()); $effect(() => { if (!animating) return; const timer = setInterval(() => frame++, FRAME_MS); return () => clearInterval(timer); }); // A box put away comes back when the move settles. $effect(() => { if (!dialog) return; if (q.hidden && dialog.open) dialog.close(); else if (!q.hidden && !dialog.open) dialog.showModal(); });
function act() { if (q.phase === 'asking') { const option = q.options[q.option - 1]; if (option) q.pick(option.session, option.profile); else if (q.yes && q.canMove) void q.begin(); else onno(); } else if (q.phase === 'failed') void q.begin(); else if (q.phase === 'checklist') void (q.move ? q.finish() : q.reread()); else if (q.phase === 'moved') onclose(); }
/** Esc while the move goes on, or at the checklist (later), only hides the box. */ function dismiss() { if (q.phase === 'moving' || listing) q.hidden = true; else onclose(); }
async function copy(url: string) { await copyText(url); copied = url; setTimeout(() => copied === url && (copied = ''), 1400); }
function keydown(event: KeyboardEvent) { const key = event.key; // Enter on a footer button is that button's; anywhere else it does the highlighted line. if (q.phase === 'asking' && ['ArrowUp', 'ArrowDown', 'Tab'].includes(key)) q.step(key === 'ArrowUp' || (key === 'Tab' && event.shiftKey) ? -1 : 1); else if ( key === 'Enter' && !event.isComposing && !(event.target as HTMLElement).closest('footer, .copy') ) act(); else if (key !== 'Escape') return; else dismiss(); event.preventDefault(); event.stopPropagation(); }
const verb = $derived.by(() => { if (q.phase === 'failed' || (q.phase === 'checklist' && q.failure)) return 'retry'; if (q.phase === 'finishing') return q.bindings.length ? 'disarming…' : 'finishing…'; if (listing) return q.bindings.length ? 'disarm all and finish the move' : 'finish the move'; if (q.phase === 'moved') return 'close'; return q.option ? 'pick' : q.yes ? 'move' : 'cd'; });
// The focus stays on the highlighted line, so the keys and the ring agree. $effect(() => { if (q.phase === 'asking' && !q.hidden) dialog ?.querySelector<HTMLElement>( `[data-choice="${q.option || (q.yes ? 'yes' : 'no')}"]`, ) ?.focus(); else if (q.phase === 'checklist' && !q.hidden) dialog?.querySelector<HTMLElement>('footer .primary')?.focus(); });</script>
<dialog bind:this={dialog} aria-label="/cd" oncancel={(event) => (event.preventDefault(), dismiss())} onkeydown={keydown} onclick={(event) => event.target === dialog && q.phase !== 'moving' && q.phase !== 'finishing' && dismiss()}> <div class="box"> <header> <span class="title">/cd</span><span class="target" title={q.target} >{q.target}</span > </header> {#if listing || q.phase === 'moved'} <p class="question">{q.host} runs this session now</p> {#if listing}<p class="note"> This copy stays live until what still fires here is disarmed. Finishing disarms all of it and leaves a read-only record here. </p>{/if} {:else} <p class="question">{QUESTION}</p> <p class="note">{NOTE}</p> {/if}
{#if q.phase === 'asking'} <div class="choices" role="radiogroup" aria-label="move the agent"> <button type="button" role="radio" data-choice="yes" class="choice" class:on={q.yes} aria-checked={q.yes} aria-disabled={!q.canMove} onclick={() => q.canMove && (q.yes ? act() : ((q.touched = true), (q.yes = true), (q.option = 0)))} > <span class="mark" aria-hidden="true">{q.yes ? '›' : ''}</span> <span class="label">yes</span> {#if q.checking} <span class="aside" >checking {q.host} <span class="face">{face}</span></span > {:else if !q.canMove} <span class="aside">unavailable</span> {/if} {#if q.checking} <span class="detail"></span> {:else if q.canMove} <span class="detail">{q.facts}</span> {:else} <span class="detail reason" class:read={!!q.words} >{q.unavailable}</span > {#if q.words}<span class="detail words">{q.words}</span>{/if} {/if} </button> {#each q.picks as run (run.session_id)} <div class="pick" role="radiogroup" aria-label="profile for {run.name} on {q.host}" > <span class="who">{run.name} · {run.model}</span> <span class="detail">{run.reason}; run it there on</span> {#each run.alternatives as profile (profile)} {@const n = q.options.findIndex( (o) => o.session === run.session_id && o.profile === profile, ) + 1} {@const picked = q.profiles[run.session_id] === profile} <button type="button" role="radio" data-choice={n} class="choice option" class:on={q.option === n} class:picked aria-checked={picked} onclick={() => q.pick(run.session_id, profile)} > <span class="mark" aria-hidden="true" >{q.option === n ? '›' : ''}</span > <span class="label" ><span class="dot" aria-hidden="true" >{picked ? '●' : '○'}</span >{profile}</span > </button> {/each} </div> {/each} <button type="button" role="radio" data-choice="no" class="choice" class:on={!q.yes && !q.option} aria-checked={!q.yes && !q.option} onclick={() => !q.yes && !q.option ? act() : ((q.touched = true), (q.yes = false), (q.option = 0))} > <span class="mark" aria-hidden="true" >{q.yes || q.option ? '' : '›'}</span > <span class="label">no</span> </button> </div> {:else if q.phase === 'moving'} <div class="state" role="status"> <p> <span class="lead">moving to {q.host}</span> <span class="face">{face}</span> </p> <div class="bar" class:unknown={q.share === null}> <span style:width="{(q.share ?? 0.3) * 100}%"></span> </div> <p class="faint">{q.progress}</p> </div> {:else if listing} {#if !q.move} <div class="state" role="status"> {#if q.failure}<p class="error">{q.failure}</p>{:else}<p> <span class="lead">reading the checklist</span> <span class="face">{face}</span> </p>{/if} </div> {:else} {#if q.bindings.length} <ul class="bindings" aria-label="disarmed when the move finishes"> {#each q.bindings as binding (`${binding.kind}:${binding.id}`)} <li> <span class="kind">{binding.kind}</span> <span class="label">{binding.label}</span> {#if binding.status !== 'pending'}<span class="status {binding.status}" >{binding.status === 'disarmed' ? '✓ disarmed' : '✗ failed'}</span >{/if} {#if binding.detail}<span class="detail">{binding.detail}</span >{/if} {#if binding.old_url}<span class="url" ><span class="tag">was</span><code>{binding.old_url}</code ></span >{/if} {#if binding.new_url} {@const url = binding.new_url} <span class="url" ><span class="tag">re-point to</span><code>{url}</code ><button type="button" class="copy" onclick={() => copy(url)} >{copied === url ? 'copied' : 'copy'}</button ></span > {/if} {#if binding.error}<span class="detail reason" >{binding.error}</span >{/if} </li> {/each} </ul> {:else} <p class="faint tail"> nothing here still fires for this session; finishing marks this copy moved. </p> {/if} {#if q.phase === 'finishing'} <p class="faint tail" role="status"> disarming here <span class="face">{face}</span> </p> {:else if q.failure} <p class="error tail" role="alert">{q.failure}</p> {/if} {/if} {:else if q.phase === 'moved'} <div class="state" role="status"> <p> <span class="ok">moved</span> <span class="lead">to {q.host} · {q.target}</span> </p> <p class="faint"> open it there: <code>albedo web</code> on {q.host}{q.move?.target_home ? ` (albedo home ${q.move.target_home})` : ''} </p> {#if q.move?.lost.length}<p class="faint"> not restored: {q.move.lost.join(', ')} </p>{/if} </div> {:else} <div class="state" role="alert"> <p class="error">{q.failure}</p> <p class="faint">the session stays here, as it was.</p> {#if q.words}<p class="faint words">{q.words}</p>{/if} </div> {/if}
<footer> {#if q.phase === 'moving'} <button type="button" class="quiet" onclick={dismiss} >hide<span class="why">· the move goes on</span><kbd>esc</kbd></button > {:else if listing} <button type="button" class="quiet" onclick={dismiss} >{q.phase === 'finishing' ? 'hide' : 'later'}<kbd>esc</kbd></button > <button type="button" class="primary" disabled={q.phase === 'finishing'} onclick={act}>{verb}<kbd>↵</kbd></button > {:else} {#if q.phase !== 'moved'} <button type="button" class="quiet" onclick={dismiss} >{q.phase === 'failed' ? 'close' : 'cancel'}<kbd>esc</kbd></button > {/if} <button type="button" class="primary" onclick={act} >{verb}<kbd>↵</kbd></button > {/if} </footer> </div></dialog>
<style> dialog { width: min(480px, calc(100vw - 24px)); padding: 0; color: var(--text); background: var(--surface); border: 0; border-radius: 14px; box-shadow: var(--shadow-raised); } dialog::backdrop { background: var(--scrim); } .box { display: flex; flex-direction: column; padding: 14px 18px 16px; font-size: calc(13.5px * var(--ui-scale)); line-height: 1.45; } header { display: flex; align-items: baseline; gap: 10px; min-width: 0; margin-bottom: 10px; } .title { flex: none; font: 600 calc(12.5px * var(--ui-scale)) var(--mono); } .target { min-width: 0; overflow: hidden; color: var(--muted); font: calc(12.5px * var(--ui-scale)) var(--mono); white-space: nowrap; text-overflow: ellipsis; } p { margin: 0; } .question { font-size: calc(15px * var(--ui-scale)); font-weight: 600; text-wrap: balance; } .note, .faint { color: var(--faint); } .note { margin-top: 2px; }
.choices { display: grid; gap: 2px; margin: 14px -8px 0; } .choice { display: grid; grid-template-columns: 14px auto 1fr; column-gap: 4px; align-items: baseline; padding: 7px 8px; color: var(--muted); font: inherit; text-align: left; background: none; border: 0; border-radius: 9px; cursor: pointer; transition: background-color 120ms ease; } .choice:hover:not([aria-disabled='true']) { background: var(--hover); } .choice.on { color: var(--accent); background: color-mix(in oklab, var(--accent) 14%, transparent); } .choice[aria-disabled='true'] { cursor: default; } .choice[aria-disabled='true'] .label { color: var(--faint); } .choice:focus-visible { outline: 1px solid color-mix(in oklab, var(--accent) 45%, transparent); outline-offset: -1px; } .mark { font-weight: 700; } .label { font-weight: 600; } .aside { justify-self: start; margin-left: 10px; color: var(--muted); font-size: calc(12.5px * var(--ui-scale)); } .detail { grid-column: 2 / -1; color: var(--faint); font-size: calc(12.5px * var(--ui-scale)); } .detail:empty { display: none; } /* A reading of the daemon's words, which follow it smaller and fainter. */ .detail.read { color: var(--muted); } .words { font-family: var(--mono); font-size: calc(11.5px * var(--ui-scale)); overflow-wrap: anywhere; } p.words { margin-top: 8px; } .pick { display: grid; margin: 6px 0 4px 18px; } .pick > .who, .pick > .detail { grid-column: auto; padding: 0 8px; } .who { color: var(--muted); font-size: calc(12.5px * var(--ui-scale)); } .option { padding-block: 3px; } .option .label { font-weight: 500; } .option.picked:not(.on) .label { color: var(--text); } .dot { display: inline-block; width: 1.3em; font-size: 0.85em; } .face { color: var(--accent); font-family: var(--face); white-space: pre; }
.state { display: grid; gap: 6px; margin-top: 14px; } .lead { color: var(--muted); } .ok { color: var(--added); font-weight: 600; } .error { color: var(--danger); overflow-wrap: anywhere; } code { font: calc(12.5px * var(--ui-scale)) var(--mono); } .bar { height: 4px; overflow: hidden; background: var(--well); border-radius: 2px; } .bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width 300ms ease; } .bar.unknown span { animation: sweep 1.4s ease-in-out infinite; } @keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(340%); } } @media (prefers-reduced-motion: reduce) { .bar.unknown span { animation: none; } }
.bindings { display: grid; gap: 2px; max-height: min(46vh, 360px); margin: 14px -8px 0; padding: 0; overflow-y: auto; list-style: none; } .bindings li { display: grid; grid-template-columns: calc(64px * var(--ui-scale)) 1fr auto; column-gap: 8px; align-items: baseline; padding: 7px 8px; border-radius: 9px; } .bindings li:nth-child(odd) { background: color-mix(in oklab, var(--well) 60%, transparent); } .kind { color: var(--faint); font: calc(11.5px * var(--ui-scale)) var(--mono); } .bindings .label { min-width: 0; overflow-wrap: anywhere; } .status { font-size: calc(12px * var(--ui-scale)); white-space: nowrap; } .status.disarmed { color: var(--added); } .status.failed { color: var(--danger); } .bindings .detail, .url { grid-column: 2 / -1; } .url { display: flex; align-items: baseline; gap: 6px; min-width: 0; color: var(--faint); font-size: calc(12px * var(--ui-scale)); } .url code { min-width: 0; color: var(--muted); font-size: calc(11.5px * var(--ui-scale)); overflow-wrap: anywhere; } .tag { flex: none; min-width: calc(64px * var(--ui-scale)); } .copy { flex: none; margin-left: auto; padding: 0 2px; color: var(--accent); font: inherit; background: none; border: 0; cursor: pointer; } .bindings .reason { color: var(--danger); } .tail { margin-top: 12px; }
footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; } footer button { display: inline-flex; align-items: center; gap: 2px; padding: 6px 8px 6px 12px; color: var(--text); font: inherit; font-weight: 550; background: var(--well); border: 0; border-radius: 9px; cursor: pointer; } footer .primary { color: var(--surface); background: var(--accent); } footer .primary:disabled { cursor: default; opacity: 0.6; } .why { margin-left: 0.35em; color: var(--muted); font-weight: 400; } kbd { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 6px; padding: 0 4px; color: inherit; font: 600 calc(11px * var(--ui-scale)) var(--sans); background: color-mix(in oklab, currentColor 14%, transparent); border-radius: 5px; opacity: 0.8; }
@media (max-width: 760px) { .url { flex-wrap: wrap; row-gap: 0; } .url code { flex-basis: 100%; order: 1; } dialog { width: calc(100vw - 20px); margin: auto auto 10px; } kbd { display: none; } footer button { flex: 1; justify-content: center; padding: 10px 12px; } }</style>