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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407<script lang="ts"> import { tick } from 'svelte'; import { boards } from './lib/boards.svelte'; import { sendAllNotes } from './lib/notes'; import BoardView from './lib/tiles/BoardView.svelte'; import { focusToward, nearest, type Direction } from './lib/tiles/focus'; import Marks from './lib/tiles/Marks.svelte'; import { marks, moveToward, sideOf, type Mark } from './lib/tiles/moves'; import { frameOf, paneTrail } from './lib/tiles/tree'; import { ago, place, rank, sessionPlace } from './lib/format'; import { altSwitchesTabs, boardJumpKey, command, option, redo, shortcut, typing, } from './lib/keys'; import Palette, { itemLabel, type Item } from './lib/Palette.svelte'; import { prefs } from './lib/prefs.svelte'; import { busy } from './lib/live.svelte'; import About from './lib/About.svelte'; import { layout } from './lib/layout.svelte'; import Phone from './lib/Phone.svelte'; import Rail from './lib/Rail.svelte'; import { sessions } from './lib/sessions.svelte'; import { mcp } from './lib/settings/mcp.svelte'; import { settingsNav } from './lib/settingsNav.svelte'; import { slotOf, type Board } from './lib/board.svelte'; import Tabs from './lib/Tabs.svelte'; import { lazy } from './lib/lazy'; // Opened only on request, so loaded then: zen mode, the usage pane, the // phone's settings and usage sheets, the new session dialog. const focusChat = lazy(() => import('./lib/FocusChat.svelte')); const settingsDialog = lazy(() => import('./lib/SettingsDialog.svelte')); const usageMenu = lazy(() => import('./lib/UsageMenu.svelte')); const usageSheet = lazy(() => import('./lib/UsageSheet.svelte')); const newSession = lazy(() => import('./lib/NewSession.svelte')); import { deleteArtifact, listArtifacts, type Artifact } from './lib/api'; import { artifacts } from './lib/artifacts.svelte'; import * as popouts from './lib/popouts.svelte';
const RAIL_KEY = 'albedo.rail'; let railOpen = $state(localStorage.getItem(RAIL_KEY) !== 'closed'); let paletteOpen = $state(false); /** What the palette opens with typed: `>` from ⌘⇧P, for commands only. */ let paletteStart = $state(''); let settingsOpen = $state(false); function openSettings(section?: string) { if (section) settingsNav.request = section; if (layout.phone) settingsOpen = true; else boards.openSettings(); } /** The top bar's usage menu, open while its pane is; the phone has no top bar, so it has the sheet. */ let usageOpen = $state(false); let usageSheetOpen = $state(false); /** * Usage details: the whole picture in a window of its own, which tiles, docks * and pops out like any other, or the sheet filling the bottom of a phone. */ function openUsage() { usageOpen = false; if (layout.phone) usageSheetOpen = true; else boards.board?.openUsage(); } /** The pane under the (?): the about card, or the keys. */ let help = $state<'about' | 'keys' | null>(null); let newOpen = $state(false); let search = $state<HTMLInputElement>(); /** The gallery of every artifact, in the palette: to open one, or to delete one. */ let gallery = $state<'open' | 'delete' | null>(null); let shelf = $state<Artifact[]>([]); /** The letters of ⌥/ while picking a window by them; `arming` waits for the arrow after ⌥P. */ let picks = $state.raw<Mark[] | null>(null); let arming = $state(false); let note = $state<string | null>(null); let noteTimer: ReturnType<typeof setTimeout> | undefined; const hint = $derived( picks ? boards.board?.presel ? 'a letter: move that window into the preselection · esc' : 'a letter: swap it with this one · ⇧ letter: join it as a tab · esc' : arming ? 'an arrow: preselect that side of this pane · esc' : note, );
// The palette finds artifacts too, so the list is read whenever it opens. $effect(() => { if (paletteOpen || gallery) listArtifacts().then( (found) => (shelf = found), () => {}, ); });
$effect(() => localStorage.setItem(RAIL_KEY, railOpen ? 'open' : 'closed'));
// The MCP store stays fresh even with Settings closed, so the gear button // can show the servers that need a sign-in; a reload mid-sign-in resumes. $effect(() => { const stop = mcp.watch(); mcp.resume(); return stop; });
// With the sessions hidden, the pointer at the canvas's edge on their side // brings them out floating over it, at once. How near counts as the edge // grows with how fast the pointer is heading there, so a flick toward the // edge opens it early and a slow drift along the canvas only right at it. // It is watched from the canvas rather than a strip along the edge, so the // edge still pans and clicks like the rest of the canvas. Out, the card // stays while the pointer is on it or near it (the top bar above it // included, for an overshoot toward the first rows), while its filter has // focus, and goes soon after the pointer is clearly elsewhere or leaves // the page. const PEEK_EDGE = 20; const PEEK_FLICK_EDGE = 50; /** px of edge gained per px/ms of speed toward it */ const PEEK_PER_SPEED = 15; const PEEK_NEAR = 48; const PEEK_LINGER_MS = 100; let peek = $state(false); let peekEl = $state<HTMLElement>(); /** The pointer's last distance from that edge, and its speed toward it, smoothed. */ const heading = { x: 0, t: 0, speed: 0 }; let peekTimer: ReturnType<typeof setTimeout> | undefined; let pointerNear = false; $effect(() => { if (railOpen) peek = false; });
function edge(event: PointerEvent) { if (railOpen || peek) return; const canvas = (event.currentTarget as HTMLElement).getBoundingClientRect(); const x = prefs.sidebarRight ? canvas.right - event.clientX : event.clientX - canvas.left; const dt = event.timeStamp - heading.t; const toward = dt > 0 && dt < 100 ? Math.max(0, (heading.x - x) / dt) : 0; heading.speed = heading.speed * 0.5 + toward * 0.5; heading.x = x; heading.t = event.timeStamp; const reach = Math.min( PEEK_FLICK_EDGE, PEEK_EDGE + heading.speed * PEEK_PER_SPEED, ); if (x <= reach && !event.buttons) peek = true; }
function near(event: PointerEvent) { if (!peek || !peekEl) { pointerNear = false; return; } const card = peekEl.getBoundingClientRect(); const beside = prefs.sidebarRight ? event.clientX >= card.left - PEEK_NEAR : event.clientX <= card.right + PEEK_NEAR; pointerNear = beside && event.clientY <= card.bottom + PEEK_NEAR; if (pointerNear) clearTimeout(peekTimer); else unpeek(); }
function unpeek() { clearTimeout(peekTimer); peekTimer = setTimeout(() => { // Typing in its filter keeps it out. if (!peekEl?.contains(document.activeElement)) peek = false; }, PEEK_LINGER_MS); }
sessions.start(); popouts.start();
function focusFilter() { if (!railOpen) peek = true; tick().then(() => search?.focus()); }
function openTerminal(cwd?: string, sessionId?: string) { const id = boards.board?.selected; const selected = id ? boards.board?.windows[id] : undefined; const session = selected?.type === 'session' ? sessions.byId.get(selected.data.sessionId) : undefined; const targetCwd = cwd ?? session?.workspace ?? undefined; const targetSessionId = sessionId ?? session?.id ?? undefined; boards.board?.openPty({ cwd: targetCwd, sessionId: targetSessionId, parent: selected?.id, }); }
const ARROWS: Record<Direction, string> = { left: '←', right: '→', up: '↑', down: '↓', }; const TOWARD: Record<string, Direction | undefined> = { ArrowLeft: 'left', ArrowRight: 'right', ArrowUp: 'up', ArrowDown: 'down', };
/** `canvas`: only offered on a board with a canvas, which it works on. */ const commands: (Omit<Item, 'kind' | 'key'> & { canvas?: boolean })[] = [ { category: 'session', label: 'new', hint: 'S', run: () => (newOpen = true), }, { category: 'terminal', label: 'new', hint: 'T', run: () => openTerminal(), }, { category: 'board', label: 'new', hint: 'B', run: () => boards.create() }, { category: 'board', label: 'rename', hint: 'F2', run: () => (boards.renaming = boards.active), }, { category: 'board', label: 'next', hint: '⇧]', run: () => boards.step(1) }, { category: 'board', label: 'previous', hint: '⇧[', run: () => boards.step(-1), }, { category: 'board', label: 'close tab', hint: '⇧W', run: () => boards.active && boards.close(boards.active), }, { category: 'board', label: 'delete', run: () => boards.active && boards.delete(boards.active), }, { category: 'note', label: 'new', hint: 'N', run: () => boards.board?.noteAt(), }, { category: 'note', label: 'send all', detail: 'each chat gets its own as one message', run: () => boards.board && sendAllNotes(boards.board), }, { category: 'help', label: 'keyboard shortcuts', hint: '?', run: () => (help = 'keys'), }, { category: 'help', label: 'about albedo', run: () => (help = 'about') }, { category: 'canvas', label: 'fit all windows', hint: '⇧1', canvas: true, run: () => boards.board?.fit(), }, { category: 'canvas', label: 'zoom to 100%', hint: '⇧0', canvas: true, run: () => boards.board?.zoomTo(1), }, { category: 'window', label: 'zoom in', hint: option('+'), run: () => zoomSelectedWindow(1), }, { category: 'window', label: 'zoom out', hint: option('−'), run: () => zoomSelectedWindow(-1), }, { category: 'window', label: 'zoom to 100%', hint: option('0'), run: () => zoomSelectedWindow(0), }, ...(Object.entries(ARROWS) as [Direction, string][]).flatMap( ([toward, arrow]) => [ { category: 'pane', label: `move ${toward}`, hint: option(`⇧${arrow}`), detail: 'past its neighbour, into tabs or a split, out at an edge', run: () => moveSelected(toward), }, { category: 'window', label: `swap ${toward}`, hint: option(`⌃${arrow}`), detail: 'with the window that way', run: () => swapWindow(toward), }, ], ), { category: 'window', label: 'pick by letter', hint: option('/'), detail: 'a letter swaps it with this one, ⇧ letter joins it as a tab', run: () => startPick(), }, { category: 'layout', label: 'preselect where the next window goes', hint: option('P'), detail: 'then an arrow: that side of this pane', run: () => arm(), }, { category: 'layout', label: 'clear the preselection', hint: 'Esc', run: () => boards.board && (boards.board.presel = null), }, { category: 'pane', label: 'focus', hint: option('F'), detail: 'it fills the board for now; the rest waits behind it', run: () => toggleExpanded(), }, { category: 'pane', label: 'unfocus', hint: 'Esc', detail: 'back to the whole board', run: () => boards.board?.collapse(), }, { category: 'layout', label: 'make section', hint: option('G'), detail: `of what is ${command}-clicked: title bars, section headers, a canvas`, run: () => makeSection(), }, { category: 'layout', label: 'undo', hint: shortcut('Z'), run: () => boards.board?.undo(), }, { category: 'layout', label: 'redo', hint: redo, run: () => boards.board?.redo(), }, { category: 'window', label: 'next', run: () => boards.board?.step(1) }, { category: 'window', label: 'previous', run: () => boards.board?.step(-1), }, { category: 'layout', label: 'canvas', detail: 'windows anywhere on a plane', run: () => boards.board?.setRoot('canvas'), }, { category: 'layout', label: 'tiles', detail: 'windows side by side, filling the board', run: () => boards.board?.setRoot('split'), }, { category: 'layout', label: 'tabs', detail: 'one window at a time', run: () => boards.board?.setRoot('tabs'), }, { category: 'canvas', label: 'new beside this window', run: () => canvasBeside(), }, { category: 'canvas', label: 'new on this canvas', detail: 'panned and zoomed on its own; windows drag in and out', canvas: true, run: () => boards.board?.addCanvasOn(), }, { category: 'pane', label: 'close', hint: 'W', detail: 'the selected window, section or canvas, with everything in it', run: () => closeSelected(), }, { category: 'pane', label: 'move to a new board', detail: 'what is picked, else the selected pane, with everything in it', run: () => toNewBoard(), }, { category: 'pane', label: 'pop out', detail: 'the selected window, section or canvas, into a browser window of its own; closing that puts it back', run: () => popOutSelected(), }, { category: 'canvas', label: 'toggle overview map', hint: 'M', canvas: true, run: () => boards.board?.toggleMap(), }, { category: 'session', label: 'toggle sidebar', hint: '[', run: () => (railOpen = !railOpen), }, { category: 'session', label: 'filter', hint: '/', run: () => focusFilter(), }, { category: 'session', label: 'extensions', run: openExtensions }, { category: 'session', label: 'refresh', hint: 'R', run: () => sessions.refresh(), }, { category: 'settings', label: 'open', hint: shortcut(','), run: () => openSettings(), }, { category: 'settings', label: 'MCP servers', detail: mcp.attention.length ? `${mcp.attention.length} need sign-in` : 'add, edit and sign in', run: () => openSettings('mcp'), }, { category: 'usage', label: 'open', detail: 'what the provider calls used, and what is left of each limit', run: openUsage, }, { category: 'theme', label: 'follow the system', run: () => (prefs.theme = 'system'), }, { category: 'theme', label: 'light', run: () => (prefs.theme = 'light') }, { category: 'theme', label: 'dark', run: () => (prefs.theme = 'dark') }, { category: 'artifact', label: 'open…', hint: 'A', run: () => (gallery = 'open'), }, { category: 'artifact', label: 'delete…', run: () => (gallery = 'delete') }, ];
/** Opens an artifact beside the chat it came from, when that chat is on the board. */ function openArtifact(artifact: Artifact) { const chat = `session:${artifact.session_id}`; const parent = boards.board?.windows[chat] ? chat : undefined; boards.board?.openArtifact( artifact.id, artifact.session_id, artifact.version, parent, ); }
async function removeArtifact(artifact: Artifact) { await deleteArtifact(artifact.id); artifacts.forget(artifact.id); boards.board?.remove(`artifact:${artifact.id}`, { undoable: false }); shelf = shelf.filter((item) => item.id !== artifact.id); }
function artifactItems(query: string, deleting = false): Item[] { return rank( shelf, query, (artifact) => [ artifact.title, artifact.session_name ?? '', `artifact: ${artifact.title}`, ], true, ).map<Item>((artifact) => ({ key: `artifact:${artifact.id}`, kind: 'artifact', category: 'artifact', label: deleting ? `delete “${artifact.title}”` : artifact.title, detail: [ artifact.versions > 1 ? `v${artifact.version}` : '', artifact.session_deleted ? 'from a deleted session' : artifact.session_name || place(artifact.workspace), ago(new Date(artifact.updated_at).toISOString()), ] .filter(Boolean) .join(' · '), run: () => (deleting ? removeArtifact(artifact) : openArtifact(artifact)), })); }
function searchEverything(query: string): Item[] { const found = rank( sessions.list.filter((session) => !session.preferences.archived), query, (session) => [ session.name, place(session.workspace), `session: ${session.name}`, ], true, ) .slice(0, 60) .map<Item>((session) => ({ key: session.id, kind: 'session', category: 'session', label: session.name || 'untitled session', detail: `${sessionPlace(session)} · ${busy(session) ? 'working' : ago(session.activity_at)}`, run: () => boards.openSession(session), })); const jump = boards.tabs.map((entry, index) => ({ key: `board:${entry.id}`, category: 'board', label: `show ${entry.name}`, hint: index < 9 ? boardJumpKey(String(index + 1)) : undefined, run: () => boards.show(entry.id), })); const reopen = boards.closed.map((entry) => ({ key: `board:${entry.id}`, category: 'board', label: `open ${entry.name}`, run: () => boards.show(entry.id), })); const offered = boards.board?.canvas ? commands : commands.filter((command) => !command.canvas); const actions = rank( [...offered, ...jump, ...reopen], query, itemLabel, true, ).map<Item>((command) => ({ key: `command:${itemLabel(command)}`, kind: 'command', ...command, })); return query ? [...found, ...artifactItems(query).slice(0, 20), ...actions] : [...found, ...actions]; }
function openExtensions() { const board = boards.board; const parent = board?.selected; const session = parent && board?.sessionOf(parent); if (session) board?.openExtensions(session, parent); else say('select a session first'); }
/** The palette's search: everything, or after `>` only commands, after `@` only sessions, as in VS Code's quick open. */ function searchPalette(query: string): Item[] { const [mark, rest] = [query[0], query.slice(1).trimStart()]; if (mark === '>') return searchEverything(rest).filter((item) => item.kind === 'command'); if (mark === '@') return searchEverything(rest).filter((item) => item.kind === 'session'); return searchEverything(query); }
/** The pane a key acts on: the selected one, else the pane under the pointer, else the board's only window. */ function targetPane(): string | null { const board = boards.board; if (!board) return null; if (board.selected) return board.selected; const hovered = document.querySelector<HTMLElement>('.window-slot:hover')?.dataset.id ?? document.querySelector<HTMLElement>('.section-head[data-pane]:hover') ?.dataset.pane ?? document.querySelector<HTMLElement>('.canvas-tile.nested:hover')?.dataset .tile; if (hovered) return hovered; return board.list.length === 1 ? board.list[0].id : null; }
function targetWindowId(): string | null { const id = targetPane(); return id && boards.board?.windows[id] ? id : null; }
function zoomSelectedWindow(by: 1 | -1 | 0) { const id = targetWindowId(); if (!id) return say('select a window first'); if (by === 0) boards.board?.zoomWindow(id, 1); else boards.board?.stepWindowZoom(id, by); }
/** Moves the focus to the window that way on screen, bringing it into view on its canvas. */ function focusWindow(direction: 'left' | 'right' | 'up' | 'down') { const board = boards.board; const id = board && focusToward(board, direction); if (id) board.reveal(id); }
function say(text: string) { clearTimeout(noteTimer); note = text; noteTimer = setTimeout(() => (note = null), 1800); }
/** Makes one layout change; the board refuses one that would leave a window too small to use. */ function arrange(change: (board: Board) => unknown, nothing: string) { const board = boards.board; if (!board) return; const before = board.root; if (change(board)) return say('no room: a window would get too small'); if (board.root === before) say(nothing); }
function moveSelected(toward: Direction) { const board = boards.board; const id = targetPane(); if (!board || !id) return; const window = !!board.windows[id]; if (window && board.placeOf(id) === 'canvas') return say( `alone on a canvas: drag it, or ${option('⌃')} an arrow to swap`, ); if (!window && paneTrail(board.root, id)?.at(-2)?.kind === 'canvas') return say('on a canvas: drag it by its header'); arrange((board) => { const move = moveToward(board.root, id, sideOf[toward]); return ( move && board.move(id, move.target, move.where, { index: move.index }) ); }, 'already at the edge'); }
/** Trades places with the window that way on screen; notes are not in the layout to trade. */ function swapWindow(toward: Direction) { const board = boards.board; const window = board?.selected; if (!board || !window) return; if (!board.windows[window]) return say('only windows swap'); const other = nearest(board, toward, { skip: (id) => board.windows[id]?.type === 'note', beyond: true, }); if (!other) return say('no window that way'); arrange((board) => board.swap(window, other), 'no window that way'); }
function startPick() { const board = boards.board; arming = false; picks = board && !picks ? marks(board) : null; }
function arm() { picks = null; const id = targetPane(); if (id && boards.board) { boards.board.select(id); arming = true; } else arming = false; }
/** What a picked letter does: moves the picked window into the preselection, or swaps it with the selected one, or (with ⇧) joins the selected one to it as a tab. */ function pick(letter: string, join: boolean) { const board = boards.board; const picked = picks?.find((mark) => mark.letter === letter)?.window; const window = board?.selected; picks = null; if (!board || !picked) return; const presel = board.presel; if (presel) { board.presel = null; const target = frameOf(board.root, presel.pane); if (target && picked !== presel.pane) arrange( (board) => board.move(picked, target.id, presel.side), 'it is already there', ); return; } if (!window || picked === window) return say('that is this window'); if (!join && !board.windows[window]) return say('only windows swap'); if (!join) return arrange((board) => board.swap(window, picked), 'nothing to swap'); const target = frameOf(board.root, picked); if (!target || target === frameOf(board.root, window)) return say('already together'); arrange( (board) => board.move(window, target.id, 'tab'), 'already together', ); }
/** A canvas's key: on the canvas it works on, or a word that there is none. */ function onCanvas(run: (board: Board) => void) { const board = boards.board; if (board?.canvas) run(board); else say('no canvas on this board'); }
/** Fills the board with the selected pane, or puts back whatever fills it. */ function toggleExpanded() { const board = boards.board; const id = board?.expanded ?? targetPane(); if (!board || !id) return say('select a pane first'); if (!board.expandable(id)) return say('nothing else to fill the board over'); board.toggleExpanded(id); }
function makeSection() { const problem = boards.board?.makeSection(); if (problem) say(problem); }
/** The layout keys: ⌥⇧ and ⌥⌃ with an arrow, ⌥/ and its letters, ⌥P and its arrow, ⌥G, ⌥F, Esc. True when the key was theirs. */ function layoutKey(event: KeyboardEvent): boolean { const toward = TOWARD[event.key]; if (event.key === 'Escape') { if (picks) picks = null; else if (arming) arming = false; else if (boards.board?.picked.size) boards.board.unpick(); else if (boards.board?.presel) ((boards.board.presel = null), say('preselection cleared')); else if (boards.board?.expanded) boards.board.collapse(); else return false; return true; } if ( picks && /^Key[A-Z]$/.test(event.code) && !event.altKey && !event.metaKey && !event.ctrlKey ) { pick(event.code.slice(3).toLowerCase(), event.shiftKey); return true; } if (arming && toward) { const board = boards.board; arming = false; if (board?.selected) board.presel = { pane: board.selected, side: sideOf[toward] }; return true; } if (!event.altKey || event.metaKey) return false; if (event.code === 'Slash') startPick(); else if (event.code === 'KeyP') arm(); else if (event.code === 'KeyG' && !event.shiftKey && !event.ctrlKey) makeSection(); else if (event.code === 'KeyF' && !event.shiftKey && !event.ctrlKey) toggleExpanded(); else if (toward && event.shiftKey && !event.ctrlKey) moveSelected(toward); else if (toward && event.ctrlKey && !event.shiftKey) swapWindow(toward); else return false; return true; }
/** ⌘Z or Ctrl+Z undoes a layout change; ⇧⌘Z, Ctrl+⇧Z or Ctrl+Y redoes it. */ function undoKey(event: KeyboardEvent): boolean { if (!(event.metaKey || event.ctrlKey) || event.altKey) return false; if (event.code === 'KeyZ') event.shiftKey ? boards.board?.redo() : boards.board?.undo(); else if (event.code === 'KeyY' && event.ctrlKey) boards.board?.redo(); else return false; return true; }
/** Splits a new, empty canvas beside the selected pane, or beside the tabs it sits in. */ function canvasBeside() { const board = boards.board; const id = targetPane(); const frame = board && id ? frameOf(board.root, id) : null; if (board && frame) board.addCanvas(frame.id, 'right'); }
function popOutSelected() { const id = targetPane(); if (id) popouts.popOut(id); else say('select a pane first'); }
/** Moves what is picked, else the selected pane, onto a board of its own. */ function toNewBoard() { const board = boards.board; if (!board) return; const picked = [...board.picked]; const ids = picked.length ? picked : [targetPane()].filter((id): id is string => !!id); if (!ids.length) return say('select a pane first'); board.unpick(); if (!boards.popToBoard(ids)) say('that is the whole board already'); }
function closeSelected() { const board = boards.board; const selected = targetPane(); if (board && selected) board.remove(selected); }
function focusSelectedWindow(): boolean { const id = targetWindowId(); if (!id) return false; const node = slotOf(id); const field = node?.querySelector<HTMLElement>( '.editor, textarea, input[type="search"], input[type="text"]', ); if (!field) return false; field.focus(); return true; }
// Alt+1–9 (Ctrl+1–9 on Firefox for Linux, which keeps Alt for its own tabs) shows that board, // even from a text field, where Alt would type a digit or a US Mac's ¡™£¢∞§¶•ª. A field keeps // other layouts' Alt characters (⌥8 is { and ⌥2 is “ on a German Mac); Ctrl types none, so it // always jumps. A terminal keeps the keys for its shell. function boardKey(event: KeyboardEvent) { if (event.metaKey || event.ctrlKey) { const k = event.key.toLowerCase(); if ( !event.shiftKey && !event.altKey && (k === 'k' || event.code === 'KeyK') ) { event.preventDefault(); event.stopPropagation(); settingsOpen = false; newOpen = false; help = null; paletteStart = ''; paletteOpen = !paletteOpen; return; } if ( event.shiftKey && !event.altKey && (k === 'p' || event.code === 'KeyP') ) { event.preventDefault(); event.stopPropagation(); settingsOpen = false; newOpen = false; help = null; paletteStart = '>'; paletteOpen = !paletteOpen; return; } if (!event.shiftKey && !event.altKey && event.key === ',') { event.preventDefault(); event.stopPropagation(); newOpen = false; paletteOpen = false; openSettings(); return; } } const held = altSwitchesTabs ? event.ctrlKey && !event.altKey : event.altKey && !event.ctrlKey; if ( !held || event.metaKey || event.shiftKey || !/^(Digit|Numpad)[1-9]$/.test(event.code) ) return; if ((event.target as Element | null)?.closest('.pty-view')) return; if (event.altKey && typing(event) && !/^[1-9¡™£¢∞§¶•ª]$/.test(event.key)) return; event.preventDefault(); event.stopPropagation(); const tab = boards.tabs[Number(event.code.at(-1)) - 1]; if (tab) boards.show(tab.id); }
function keydown(event: KeyboardEvent) { if (settingsOpen) return; if (paletteOpen || gallery || newOpen || layout.focus || typing(event)) return; if (layoutKey(event) || undoKey(event)) return event.preventDefault(); if (event.metaKey || event.ctrlKey) return; if (event.altKey) { const toward = TOWARD[event.key]; if (toward) focusWindow(toward); else if ( event.code === 'Equal' || event.code === 'NumpadAdd' || event.key === '+' || event.key === '=' ) zoomSelectedWindow(1); else if ( event.code === 'Minus' || event.code === 'NumpadSubtract' || event.key === '-' || event.key === '_' ) zoomSelectedWindow(-1); else if ( event.code === 'Digit0' || event.code === 'Numpad0' || event.key === '0' ) zoomSelectedWindow(0); else return; return event.preventDefault(); } if (event.key === '[') railOpen = !railOpen; else if (event.key === '{') boards.step(-1); else if (event.key === '}') boards.step(1); else if (event.key === 'F2') boards.renaming = boards.active; else if (event.key === '!' && event.code === 'Digit1') onCanvas((board) => board.fit()); else if (event.key === ')' && event.code === 'Digit0') onCanvas((board) => board.zoomTo(1)); else if (event.key === 's' || event.key === 'c' || event.key === 'N') newOpen = true; else if (event.key === 't' || event.key === 'T') openTerminal(); else if (event.key === 'b') boards.create(); else if (event.key === 'w') closeSelected(); else if (event.key === 'W') boards.active && boards.close(boards.active); else if (event.key === 'a') gallery = 'open'; else if (event.key === 'r') sessions.refresh(); else if (event.key === '?') help = help === 'keys' ? null : 'keys'; else if (event.key === 'm') onCanvas((board) => board.toggleMap()); else if (event.key === 'n') boards.board?.noteAt(); else if (event.key === '+' || event.key === '=') onCanvas((board) => board.stepZoom(1)); else if (event.key === '-' || event.key === '_') onCanvas((board) => board.stepZoom(-1)); else if (event.key === '/') focusFilter(); else if ( event.key === 'Enter' && (event.target === document.body || (event.target as Element | null)?.closest('.svelte-flow')) ) { if (!focusSelectedWindow()) return; } else return; event.preventDefault(); }
const linkLabel = { connecting: 'connecting', online: 'connected', offline: 'daemon unreachable', unauthorized: 'signed out: open the link albedo web printed', };</script>
<svelte:window onkeydowncapture={boardKey} onkeydown={keydown} onpointerdowncapture={() => ((picks = null), (arming = false))} onpointermove={near} onmouseout={(event) => peek && !event.relatedTarget && ((pointerNear = false), unpeek())}/>
{#if layout.phone} <Phone onsettings={openSettings} onusage={() => (usageSheetOpen = true)} onnew={() => (newOpen = true)} usageOpen={usageSheetOpen} />{:else} <div class="shell" class:rail-closed={!railOpen} class:right={prefs.sidebarRight} > <header class="topbar"> <div class="start"> <button class="icon rail-toggle" aria-label={railOpen ? 'Hide sessions' : 'Show sessions'} title="{railOpen ? 'Hide' : 'Show'} sessions ([)" onclick={() => (railOpen = !railOpen)} > <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" ><rect x="2" y="3" width="12" height="10" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.3" /><path d="M6.25 3v10" stroke="currentColor" stroke-width="1.3" /></svg > <kbd>[</kbd> </button> <span class="brand" ><span class="spark" aria-hidden="true">✦</span> <span class="brand-ink">albedo</span></span > </div> <Tabs /> {#if sessions.link !== 'online'} <span class="link" role="status">{linkLabel[sessions.link]}</span> {/if} <div class="end"> <button class="icon" data-usage-toggle aria-label="usage and limits" aria-expanded={usageOpen} aria-haspopup="dialog" title="Usage and limits" onclick={() => (usageOpen = !usageOpen)} > <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" ><path d="M3 13V8.5M8 13V3.5M13 13V6" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" /></svg > </button> <button class="command" onclick={() => (paletteOpen = true)}> <span>search</span> <kbd>{shortcut('K')}</kbd> </button> <button class="icon about" data-about-toggle aria-label="about albedo" aria-expanded={help === 'about'} title="about albedo" onclick={() => (help = help === 'about' ? null : 'about')} > <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" ><circle cx="8" cy="8" r="6" fill="none" stroke="currentColor" stroke-width="1.3" /><path d="M6.4 6.3a1.7 1.7 0 0 1 3.3.5c0 1.1-1.7 1.4-1.7 2.5" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" /><circle cx="8" cy="11.4" r="0.8" fill="currentColor" /></svg > </button> <button class="icon" class:on={!!boards.board?.windows.settings} data-settings-toggle aria-label={mcp.attention.length ? `Settings · ${mcp.attention.length} MCP server${mcp.attention.length === 1 ? '' : 's'} need you to sign in` : 'Settings'} aria-pressed={boards.board?.selected === 'settings'} title={mcp.attention.length ? `Settings · ${mcp.attention.length} MCP server${mcp.attention.length === 1 ? '' : 's'} need you to sign in` : `Settings (${shortcut(',')})`} onclick={() => openSettings()} > <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" ><path d="M6.6 3.2L6.9 1.5A6.6 6.6 0 0 1 9.1 1.5L9.4 3.2A5 5 0 0 1 10.4 3.6L11.8 2.6A6.6 6.6 0 0 1 13.4 4.2L12.4 5.6A5 5 0 0 1 12.8 6.6L14.5 6.9A6.6 6.6 0 0 1 14.5 9.1L12.8 9.4A5 5 0 0 1 12.4 10.4L13.4 11.8A6.6 6.6 0 0 1 11.8 13.4L10.4 12.4A5 5 0 0 1 9.4 12.8L9.1 14.5A6.6 6.6 0 0 1 6.9 14.5L6.6 12.8A5 5 0 0 1 5.6 12.4L4.2 13.4A6.6 6.6 0 0 1 2.6 11.8L3.6 10.4A5 5 0 0 1 3.2 9.4L1.5 9.1A6.6 6.6 0 0 1 1.5 6.9L3.2 6.6A5 5 0 0 1 3.6 5.6L2.6 4.2A6.6 6.6 0 0 1 4.2 2.6L5.6 3.6A5 5 0 0 1 6.6 3.2Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round" /><circle cx="8" cy="8" r="2" fill="none" stroke="currentColor" stroke-width="1.3" /></svg > {#if mcp.attention.length} <span class="attention" aria-hidden="true"></span> {/if} </button> </div> </header>
{#if railOpen}<Rail bind:search onnew={() => (newOpen = true)} />{/if}
<main onpointermovecapture={edge}> {#if peek} <div class="peek" bind:this={peekEl} onfocusout={(event) => !pointerNear && !peekEl?.contains(event.relatedTarget as Node) && unpeek()} > <Rail bind:search onnew={() => (newOpen = true)} /> </div> {/if} {#if boards.board} {#key boards.board} <BoardView board={boards.board} onpalette={() => (paletteOpen = true)} onnew={() => (newOpen = true)} /> <Marks board={boards.board} picks={picks ?? []} {hint} /> {/key} {/if} </main> {#if usageOpen} {#await usageMenu() then UsageMenu}<UsageMenu onclose={() => (usageOpen = false)} onwindow={openUsage} />{/await} {/if} </div>{/if}
{#if layout.focus && !layout.phone} {#key layout.focus}{#await focusChat() then FocusChat}<FocusChat sessionId={layout.focus} />{/await}{/key}{/if}
{#if settingsOpen} {#await settingsDialog() then SettingsDialog}<SettingsDialog onclose={() => (settingsOpen = false)} />{/await}{/if}
{#if usageSheetOpen} {#await usageSheet() then UsageSheet}<UsageSheet onclose={() => (usageSheetOpen = false)} />{/await}{/if}
{#if newOpen} {#await newSession() then NewSession}<NewSession onclose={() => (newOpen = false)} />{/await}{/if}
{#if help} <About bind:view={() => help ?? 'about', (view) => (help = view)} onclose={() => (help = null)} />{/if}
{#if paletteOpen} <Palette placeholder="open a session or run a command… (> commands, @ sessions)" search={searchPalette} start={paletteStart} onclose={() => ((paletteOpen = false), (paletteStart = ''))} />{/if}
{#if gallery} {#key gallery} <Palette placeholder={gallery === 'open' ? 'open an artifact…' : 'delete an artifact, for good…'} search={(query) => artifactItems(query, gallery === 'delete')} onclose={() => (gallery = null)} /> {/key}{/if}
<style> .shell { display: grid; grid-template-rows: 44px 1fr; grid-template-columns: 264px 1fr; height: 100%; } .shell.rail-closed { grid-template-columns: 1fr; } .topbar { display: grid; grid-column: 1 / -1; grid-template-columns: 264px 1fr auto auto; grid-template-areas: 'start tabs link end'; align-items: stretch; background: var(--rail); } .rail-closed .topbar { grid-template-columns: auto 1fr auto auto; } .topbar > :global(.tabs) { grid-area: tabs; } .link { grid-area: link; } .end { grid-area: end; } /* Mirrored: the sessions on the right, with their toggle and the brand above them, and search and settings on the left. */ .shell.right { grid-template-columns: 1fr 264px; } .shell.right.rail-closed { grid-template-columns: 1fr; } .shell.right > :global(aside) { grid-area: 2 / 2; } .shell.right > main { grid-area: 2 / 1; } .right .topbar { grid-template-columns: auto 1fr auto 264px; grid-template-areas: 'end tabs link start'; } .right.rail-closed .topbar { grid-template-columns: auto 1fr auto auto; } .right .start { flex-direction: row-reverse; padding: 0 10px 0 14px; } .right .end { padding: 0 6px 0 8px; } .right .rail-toggle svg { transform: scaleX(-1); } /* One control with its key, on the same surface as search. */ .icon.rail-toggle { display: flex; align-items: center; gap: 6px; width: auto; padding: 0 5px 0 7px; background: var(--field); } /* A step of ink on the button, so the key reads as its own little surface. */ .command kbd, .rail-toggle kbd { background: color-mix(in oklab, var(--text) 12%, transparent); } .start { display: flex; grid-area: start; align-items: center; gap: 8px; padding: 0 14px 0 10px; } .brand { font-size: calc(14px * var(--ui-scale)); font-weight: 650; letter-spacing: -0.02em; white-space: nowrap; } .spark { color: var(--brand-from); font-size: calc(12px * var(--ui-scale)); } .icon, .command { align-self: center; color: var(--muted); font: inherit; background: none; border: 0; border-radius: 8px; cursor: pointer; transition: color 120ms ease, background-color 120ms ease; } .icon { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; position: relative; } .attention { position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 999px; background: var(--danger); } .about { width: 24px; height: 24px; color: var(--faint); } .end { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 6px; } .icon.on { color: var(--text); background: var(--selected); } .command { display: flex; align-items: center; gap: 12px; height: 30px; padding: 0 5px 0 12px; font-size: calc(13px * var(--ui-scale)); background: var(--field); } .icon:hover, .command:hover { color: var(--text); background: var(--hover); } .command:hover, .icon.rail-toggle:hover { background: var(--selected); } .link { align-self: center; color: var(--danger); font-size: calc(12px * var(--ui-scale)); } main { position: relative; min-width: 0; min-height: 0; overflow: hidden; } /* The hidden sessions, out over the canvas while the pointer is at its edge. */ .peek { position: absolute; top: 8px; bottom: 8px; left: 8px; z-index: var(--z-peek); display: flex; width: 264px; overflow: hidden; border-radius: 14px; box-shadow: var(--shadow-lg); } .peek > :global(aside) { flex: 1; } .right .peek { right: 8px; left: auto; }</style>