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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359<script lang="ts"> import { onDestroy } from 'svelte'; import { browse, createSession, recentWorkspaces, type Directory, type RecentWorkspace } from './api'; import { boards } from './boards.svelte'; import { homePath, rank } from './format'; import ModelChoice from './ModelChoice.svelte'; import { keepFocus } from './popover'; import SearchCard from './SearchCard.svelte'; import { sessions } from './sessions.svelte';
// Starting a session: pick its folder (one used before, a typed path, or // browsed to), then the provider, model and effort, which default to the // provider's own. A dialog on the canvas, the whole screen on a phone. let { onclose }: { onclose: () => void } = $props();
let recent = $state<RecentWorkspace[]>([]); let query = $state(''); let folder = $state<string | null>(null); let listing = $state<Directory | null>(null); let profile = $state<string | null>(null); let model = $state<string | null>(null); let effort = $state<string | null>(null); let problem = $state(''); let starting = $state(false); let dialog = $state<HTMLDialogElement>(); onDestroy(keepFocus());
const shown = $derived(rank(recent, query, (entry) => homePath(entry.location)).slice(0, 8)); // A typed absolute or home path is a folder in itself. const typed = $derived(/^(~|\/|[\w.-]+@?[\w.-]*:)/.test(query.trim()) ? query.trim() : null); const choices = $derived(typed ? [typed, ...shown.map((entry) => entry.location).filter((loc) => loc !== typed)] : shown.map((entry) => entry.location));
$effect(() => { dialog?.showModal(); recentWorkspaces() .then((found) => { recent = found; if (!folder && found[0]) folder = found[0].location; }) .catch(() => {}); });
$effect(() => { if (typed) folder = typed; else if (query.trim() && shown[0]) folder = shown[0].location; });
function folderKeydown(event: KeyboardEvent) { const step = { ArrowDown: 1, ArrowUp: -1 }[event.key] ?? (event.ctrlKey ? { n: 1, p: -1 }[event.key] : undefined); if (step && choices.length) { event.preventDefault(); const index = Math.max(0, choices.indexOf(folder ?? '')); folder = choices[(index + step + choices.length) % choices.length]; } else if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); if (!folder && choices[0]) folder = choices[0]; if (folder && profile && !starting) start(); } }
async function open(location: string) { problem = ''; try { listing = await browse(location); } catch (error) { problem = String((error as Error).message ?? error); } }
async function start() { if (!folder) return; starting = true; problem = ''; try { const session = await createSession(folder, { provider_profile: profile, model, effort }); await sessions.refresh(); onclose(); boards.openSession(session); } catch (error) { problem = String((error as Error).message ?? error); } finally { starting = false; } }</script>
<dialog bind:this={dialog} onclose={onclose} onclick={(event) => event.target === dialog && onclose()} onkeydown={(event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'Enter' && folder && profile && !starting) { event.preventDefault(); start(); } }} aria-label="new session"> <form method="dialog" class="sheet" onsubmit={(event) => (event.preventDefault(), start())}> <header class="sheet-head"> <h2>new session</h2> <div class="head-actions"> <button type="button" class="quiet" onclick={onclose}>cancel</button> <button type="submit" class="go" disabled={!folder || !profile || starting}>{starting ? 'starting…' : 'start'}</button> </div> </header>
<div class="columns"> <section> <h3>folder</h3> {#if listing} <SearchCard ariaLabel="folder" head={whereHead} foot={browseFoot}> {#each listing.items.filter((item) => !item.hidden) as item (item.location)} <button type="button" class="row" onclick={() => open(item.location)}> <span class="path">{item.name}</span> {#if item.vcs}<span class="vcs">{item.vcs}</span>{/if} </button> {/each} </SearchCard> {:else} <SearchCard bind:query placeholder="a folder you've used, or a path…" ariaLabel="folder" autofocus onkeydown={folderKeydown} foot={recentFoot}> {#if typed} <button type="button" class="row" class:selected={folder === typed} onclick={() => (folder = typed!)}> <span class="path">{typed}</span> <span class="hint">typed path</span> </button> <button type="button" class="row" onclick={() => open(typed!)}> <span class="path">browse {typed}…</span> </button> {/if} {#each shown as entry (entry.location)} {@const picked = folder === entry.location} <button type="button" class="row" class:selected={picked} onclick={() => (folder = entry.location)}> <span class="path">{homePath(entry.location)}</span> <span class="hint">{entry.use_count} {entry.use_count === 1 ? 'session' : 'sessions'}</span> </button> {/each} </SearchCard> {/if} </section>
<section> <h3>model</h3> <ModelChoice bind:profile bind:model bind:effort /> </section> </div>
{#snippet whereHead()} {#if listing?.parent}<button type="button" class="quiet" onclick={() => open(listing!.parent!)} aria-label="up a folder">↑</button>{/if} <span class="where-path" title={listing?.directory}>{homePath(listing?.directory ?? '')}</span> <button type="button" class="use" onclick={() => ((folder = listing!.directory), (listing = null))}>use this folder</button> {/snippet}
{#snippet browseFoot()} <button type="button" class="quiet" onclick={() => (listing = null)}>← recent folders</button> {/snippet}
{#snippet recentFoot()} {#if folder} <span class="picked-label" title={folder}>{homePath(folder)}</span> {:else} <span class="foot-label">folder</span> {/if} <button type="button" class="quiet" onclick={() => open(folder ?? '~')}>browse…</button> {/snippet}
{#if problem}<p class="problem">{problem}</p>{/if} </form></dialog>
<style> dialog { width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); padding: 0; color: var(--text); background: var(--surface); border: 0; border-radius: 16px; box-shadow: var(--shadow-lg); } dialog::backdrop { background: var(--scrim); } .sheet { display: grid; gap: 14px; padding: 16px 18px 18px; } .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; } .head-actions { display: flex; align-items: center; gap: 8px; } .columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: stretch; } .columns > section { min-width: 0; display: flex; flex-direction: column; } h2 { margin: 0; font-size: calc(15px * var(--ui-scale)); font-weight: 620; } h3 { margin: 0 0 8px; color: var(--muted); font-size: calc(12px * var(--ui-scale)); font-weight: 560; } .where-path { flex: 1; min-width: 0; overflow: hidden; font-family: var(--mono); font-size: calc(12px * var(--ui-scale)); white-space: nowrap; text-overflow: ellipsis; } .row { position: relative; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; width: 100%; padding: 6px 10px; color: var(--text); font: inherit; font-size: calc(13px * var(--ui-scale)); text-align: left; background: none; border: 0; border-radius: 8px; cursor: pointer; } .row:hover { background: var(--hover); } .row.selected { background: color-mix(in oklab, var(--accent) 15%, transparent); } .row.selected::before { content: ''; position: absolute; top: 6px; bottom: 6px; left: 2.5px; width: 2.5px; background: var(--accent); border-radius: 2px; } .path { min-width: 0; overflow: hidden; font-family: var(--mono); font-size: calc(12px * var(--ui-scale)); white-space: nowrap; text-overflow: ellipsis; } .row.selected .path { font-weight: 600; } .hint, .vcs { flex: none; color: var(--faint); font-size: calc(11.5px * var(--ui-scale)); } .foot-label { color: var(--muted); font-size: calc(11px * var(--ui-scale)); font-weight: 560; } .picked-label { min-width: 0; overflow: hidden; color: var(--accent); font-family: var(--mono); font-size: calc(11.5px * var(--ui-scale)); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; } .quiet { padding: 3px 8px; color: var(--muted); font: inherit; font-size: calc(12px * var(--ui-scale)); background: none; border: 0; border-radius: 7px; cursor: pointer; } .quiet:hover { color: var(--text); background: var(--hover); } .use { padding: 3px 9px; color: var(--surface); font: inherit; font-size: calc(11.5px * var(--ui-scale)); font-weight: 600; white-space: nowrap; background: var(--accent); border: 0; border-radius: 7px; cursor: pointer; } .problem { margin: 0; color: var(--danger); font-size: calc(12.5px * var(--ui-scale)); } .go { height: 30px; padding: 0 15px; color: var(--surface); font: inherit; font-size: calc(13px * var(--ui-scale)); font-weight: 600; background: var(--accent); border: 0; border-radius: 9px; cursor: pointer; } .go:disabled { opacity: 0.4; cursor: default; } @media (max-width: 760px) { dialog { --selector-height: 240px; width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; } .columns { grid-template-columns: 1fr; } }</style>