From 7af2b72fe13da51e3507f65a089787895225cbcb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 10 Nov 2026 11:49:47 +0100 Subject: docs: design for the assistant on the tablet Co-Authored-By: Claude Opus 5.5 --- .../specs/2026-11-10-assistant-design.md | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 docs/superpowers/specs/2026-11-10-assistant-design.md diff --git a/docs/superpowers/specs/2026-11-10-assistant-design.md b/docs/superpowers/specs/2026-11-10-assistant-design.md new file mode 100644 index 0000000..8f9cf24 --- /dev/null +++ b/docs/superpowers/specs/2026-11-10-assistant-design.md @@ -0,0 +1,168 @@ +# Assistant on the tablet: design + +Date: 2026-11-10. Fills the module slot the original design deferred +(`2026-11-09-deck-it-design.md`, "Assistant control"). + +## Goal + +An **Assistant** tab on the tablet that is a full client of +desktop-assistant: typed chat with streamed, formatted replies, voice +questions through the tablet's mic, history, model choice, and the canvas's +Ask presets and Do ops applied to a file picked on the PC. The UI is built +for a finger: icon buttons, no text buttons. + +## Out of scope + +- Copying a code block to the PC's clipboard (it copies to the tablet's). +- Server-sent events; the tab polls. +- Any change to the canvas beyond the catalog and the preset prompt below. +- Deleting or searching history from the tablet. + +## Parts + +### quickshell + +- **`assistant catalog` IPC call** (an `IpcHandler` function returning a + string). One JSON object: + - `presets`: the list in use, `Presets.list(Prefs.presets)`; + - `ops`: Ops.js's list (label, icon, op, kinds, min, max, format) and the + compress formats; + - `kinds`: kind → file extensions, from Files.js; + - `fileops`: the absolute path of `assistant/fileops`; + - `outDir`, `mdPrompt`: what the canvas uses for Do ops and To .md; + - `preferred`: `Prefs.assistantModel`, "" for none; + - `routerRoot`: the router's root URL (AssistantModule's `routerRoot`). +- **Preset prompts are sent as written.** `Presets.prompt` today appends + "Answer in the language of the document."; that sentence moves into the + default prompts' own text and `prompt()` returns `p.prompt` unchanged, so + a Translate preset can name its target language. Presets already saved on + the Ask presets page lose the sentence unless it is added back by hand. + +### deck-it + +- **`deckit/modules/assistant.py`**, one daemon client: + - a reader thread on `$XDG_RUNTIME_DIR/desktop-assistant.sock` (JSON + lines) folds `hello`, `state`, `user`, `think`, `token`, `tool`, `done`, + `error`, `ctx`, `models`, `conversations`, `conversation` into one in-memory state; `state()` returns it; + - reconnects every 5s while the daemon is down, as the OBS module does; + - reads the catalog with `qs -p ipc call assistant catalog` at + start and on each pick, so edits on keystone's presets page apply; + - reads `/models` (urllib) when the model list is refreshed, + for each local model's `architecture.input_modalities`. +- **`static/modules/assistant.js`**: the tab (`tab: "Assistant"`, + wrapper class `.assistant`), polling every 0.5s; the state is in memory, + so a poll costs the PC nothing. +- **`static/vendor/marked/marked.min.js`**: Markdown rendering (MIT). +- **Server: upload hook.** POST bodies are capped at 4 KB of JSON. A + module may declare `uploads={"voice": 2_000_000}`: for that action the + server accepts `Content-Type: audio/wav` up to the limit and passes the + raw bytes. Nothing assistant-specific in the server. +- **Server: `/fonts/nerd.ttf`.** The Nerd Font found by + `fc-match "Inconsolata Nerd Font"`, served with a long cache lifetime, so + presets, ops and the tab's own buttons use the canvas's glyphs. + +## Actions + +The client sends text, ids and labels; never a path or a command. + +| Action | Body | Does | +| --- | --- | --- | +| `ask` | `text` | daemon `ask`, with `model` when one is wanted | +| `stop`, `new` | — | the daemon commands | +| `list`, `open` | `id` (open) | history; answers land in state | +| `models` | — | daemon `models` plus the router's inputs | +| `model` | `id` | the chat's pick; must be in the last model list | +| `voice` | raw WAV (upload) | writes `$XDG_RUNTIME_DIR/deck-it/voice.wav`, then `ask` with `text: ""`, `audio` and `model` | +| `pick` | `preset` or `op` label | qarma on the PC, then the preset or op | +| `cancel` | — | kills an open qarma | + +### Model choice + +As the canvas: the wanted model is the chat's stored pick +(`hello.chat_model`, `conversation.model`), else `preferred`, else none (the +daemon uses what is loaded). It goes out as `model` on each ask. Moving a +chat that has turns to a cloud model shows once that its history goes to +that provider. + +### Voice + +The tablet records with `getUserMedia` and an AudioWorklet, downsamples to +16 kHz mono and encodes a 16-bit WAV in JS (stdlib only, ~40 lines), up to +59 s. A recording under 0.5 s is dropped. The mic is greyed out when the +model that will hear it takes no audio: the chat's pick if it is local, +else the loaded local model (a cloud chat's voice is still transcribed +locally). Unknown inputs count as yes; the daemon's error covers the rest. + +### Pick + +1. The label must be in the current catalog, else 400. +2. `qarma --file-selection` opens on the PC with a `--file-filter` built + from the action's kinds, and `--multiple` for an op with `min >= 2` or a + `many` preset. It runs on a thread; state is `picking` until it returns. + One picker at a time; a second `pick` is refused. +3. Cancel or a closed dialog: back to idle. +4. A preset sends `ask` with `files` and the preset's prompt; the reply + streams into the transcript. +5. An op runs `fileops `, or the daemon's `write` + with `mdPrompt` for To .md. Its `{ok, out}` or `{ok: false, error}` stays + in state as the last op's result. + +## UI + +Built for touch: every control is an icon button at least 48 px square with +an `aria-label` and a `title`; no text buttons. Icons are the Nerd Font +glyphs the canvas uses. + +- **Header:** model button (the model's name, the one text label, since it + is the value being chosen; a cloud glyph for cloud models), history, new. +- **Action strip:** Ask presets, then Do ops, as icon tiles with the + preset's own glyph and a short caption under it (presets are user-made, + so the glyph alone cannot tell them apart). While picking, the strip is + replaced by "Choose the file on the PC" and a cancel icon. +- **Transcript:** questions and replies, Markdown rendered by `marked`; + a status line for thinking and running tools. A code block gets a copy + icon once its fence closes. +- **Input bar:** text field, then mic (toggle, with a running timer while + recording), then send, which becomes stop while a reply streams. +- **Panels** (history, models) slide over the transcript and close on a + tap outside. + +### Markdown safety + +Raw HTML in model output is escaped. Links are kept only for `http(s)` and +`mailto`. Images become a plain link and are never fetched: a quoted search +result could otherwise make the tablet load a remote URL. A reply is +re-rendered on each poll; an unclosed fence shows as plain text. + +## Errors + +- Daemon down: `offline.js`'s card, "Assistant not running", the socket + error in its tooltip; retries every 5s. +- quickshell or the IPC call failing: chat and voice keep working; the + action strip is hidden with a note saying why. +- qarma missing or failing: in the strip's status line. +- Daemon `error` with `turn`: ends the reply in the transcript; without + it: shown above the input. +- fileops with no output: "fileops gave no answer". +- Mic permission refused: a note, and the mic greyed out. + +## Security + +- File paths come only from qarma on the PC; the tablet cannot name a file. +- The upload is `audio/wav` only, capped at 2 MB, written to a fixed path + in the 0700 run directory; the daemon checks the WAV and its length. +- The token cookie and trust checks apply to every action and the upload. + +## Testing + +- Python `unittest`: + - a fake daemon on a temporary socket: event folding (`hello` with a + pending reply, `token`, `done`, `stopped`), and the commands sent + (`ask` with model, files, audio); + - pick with qarma and fileops stubbed through `PATH`; + - catalog parsing; the audio rule (which model is checked); + - the upload hook: size, content type, auth. +- JS: `node --check`; one `node` test for the WAV encoder (header fields, + sample count). +- quickshell: `qs ipc call assistant catalog | python3 -m json.tool`. +- Manual: the tablet's mic, qarma on the PC, a Translate preset end to end. -- cgit v1.2.3