aboutsummaryrefslogtreecommitdiffstats
path: root/docs/superpowers/specs/2026-11-10-assistant-design.md
blob: 9fbaf38dd0a79c2279ce9e38a9fabcff32173287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# 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: voice questions through the tablet's mic with
streamed, formatted replies (no keyboard: typing happens on the PC), 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.
- History (list, open, delete, search): easier on the PC. The tablet shows
  the daemon's current conversation, so one opened in the canvas appears
  there too.

## 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), with
    the Compress submenu's formats as ops of their own, of kind `any`;
  - `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.
- **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`, `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 <desktop> ipc call assistant catalog` at
    start, on each daemon (re)connect and on each pick, so edits on keystone's presets page apply;
  - each local model's audio support comes with the daemon's `models`
    event: desktop-assistant reports `inputs` (the router's
    `architecture.input_modalities`) per local model.
- **`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.esm.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 |
| --- | --- | --- |
| `stop`, `new` | — | the daemon commands |
| `models` | — | daemon `models`, local items with `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 `MediaRecorder`, decodes the clip with
`decodeAudioData`, resamples it to 16 kHz mono with an
`OfflineAudioContext` and encodes a 16-bit WAV in JS, 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` unless the op has `max: 1`; an
   op's `min` is checked after the pick. 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 <op> <outDir> <paths>`, 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), tools, new.
- **Tools overlay** (from the header's tools icon, so the transcript keeps
  the screen): 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). A tap closes it; while picking, a
  line above the transcript says "Choose the file on the PC", with 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 turn is finished.
- **Bottom bar:** the status line, a large mic (toggle; red from the tap
  itself, with a running timer) and a stop icon while a reply streams. A
  clip whose loudest sample is under 1500 (silence) is not sent, since the
  model would invent a question from it; the tab says "nothing heard".
- **Model panel** slides 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
  tools overlay shows a note saying why.
- qarma missing or failing: in the notice above the bottom bar.
- 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.