aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-10 12:45:52 +0100
committerDanilo M. <danix@danix.xyz>2026-11-10 12:45:52 +0100
commitc30385b92ff767f8aaff58bf0bc1e5c42ce9036c (patch)
tree724f3fca1eacf2ba2cd3d7046befd8b464e42e97
parentc8f5a1e68d3294d4e1c7be3c386f3cc538eeb7af (diff)
downloaddeck-it-c30385b92ff767f8aaff58bf0bc1e5c42ce9036c.tar.gz
deck-it-c30385b92ff767f8aaff58bf0bc1e5c42ce9036c.zip
fix(assistant): voice-only tab, tools in an overlay, silent clips dropped
The first voice question on the tablet was a 0.66 s silent clip: the mic gave no feedback until the next poll, an extra tap made a near-empty recording, and the model invented a question from the silence. The mic now turns red on the tap itself, and a clip whose loudest sample is under 1500 (room noise measured ~260, speech 15000+) is not sent. Typing happens on the PC, so the text field, send button and the ask action are gone; the bar is a large mic and a stop icon. The presets and ops move into an overlay opened from the header, so the transcript gets the screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--README.md2
-rw-r--r--deckit/modules/assistant.py8
-rw-r--r--docs/superpowers/specs/2026-11-10-assistant-design.md27
-rw-r--r--static/deck.css16
-rw-r--r--static/modules/assistant.js87
-rw-r--r--static/wav.js8
-rw-r--r--tests/test_assistant.py11
-rw-r--r--tests/test_wav.mjs4
8 files changed, 92 insertions, 71 deletions
diff --git a/README.md b/README.md
index a7b7a34..e1784ef 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ launchers included, with a Restart button to apply a save.
- The K1C tab follows a Klipper printer through Moonraker (`[k1c] url`):
state, progress with the slicer's model preview, temperatures, camera, and
a red emergency stop that fires on a press and hold.
-- The Assistant tab talks to desktop-assistant: type or tap the mic to ask,
+- The Assistant tab talks to desktop-assistant: tap the mic to ask,
pick the model, and use the canvas's Ask presets and Do ops on a file you
choose in a dialog on the PC (add a Translate preset on keystone's Ask
presets page to get one here).
diff --git a/deckit/modules/assistant.py b/deckit/modules/assistant.py
index 247caf4..f0b3947 100644
--- a/deckit/modules/assistant.py
+++ b/deckit/modules/assistant.py
@@ -203,12 +203,6 @@ def make(cfg: dict) -> Module:
out["hears"] = hears(st["models"], out["wanted"])
return out
- def ask(body):
- text = body.get("text")
- if not isinstance(text, str) or not text.strip():
- raise ModuleError("text required")
- send(with_model({"type": "ask", "text": text}))
-
def model(body):
mid = body.get("id")
with lock:
@@ -343,7 +337,7 @@ def make(cfg: dict) -> Module:
return Module(
name="assistant", title="Assistant", state=state,
- actions={"ask": ask, "stop": lambda b: send({"type": "stop"}),
+ actions={"stop": lambda b: send({"type": "stop"}),
"new": lambda b: send({"type": "new"}),
"models": lambda b: send({"type": "models"}),
"model": model, "voice": voice, "pick": pick, "cancel": cancel},
diff --git a/docs/superpowers/specs/2026-11-10-assistant-design.md b/docs/superpowers/specs/2026-11-10-assistant-design.md
index 55c82eb..9fbaf38 100644
--- a/docs/superpowers/specs/2026-11-10-assistant-design.md
+++ b/docs/superpowers/specs/2026-11-10-assistant-design.md
@@ -6,8 +6,8 @@ Date: 2026-11-10. Fills the module slot the original design deferred
## 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, model choice, and the canvas's
+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.
@@ -69,7 +69,6 @@ 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 |
| `models` | — | daemon `models`, local items with `inputs` |
| `model` | `id` | the chat's pick; must be in the last model list |
@@ -115,16 +114,20 @@ 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), 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.
+ 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.
-- **Input bar:** text field, then mic (toggle, with a running timer while
- recording), then send, which becomes stop while a reply streams.
+- **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.
@@ -140,8 +143,8 @@ re-rendered on each poll; an unclosed fence shows as plain text.
- 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.
+ 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".
diff --git a/static/deck.css b/static/deck.css
index 60a9b56..8d17a66 100644
--- a/static/deck.css
+++ b/static/deck.css
@@ -638,7 +638,14 @@ select {
.assistant .as-mrow.on { border-color: var(--udt-accent); }
.assistant .as-mrow span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assistant .as-mrow small { color: var(--udt-overlay0); }
-.assistant .as-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
+.assistant .fresh { margin-left: auto; }
+.assistant .as-strip {
+ position: absolute; top: 58px; left: 0; right: 0; z-index: 2; max-height: 75%; overflow-y: auto;
+ display: flex; flex-direction: column; gap: 10px;
+ background: var(--udt-mantle); border: 1px solid var(--udt-surface1); border-radius: 12px; padding: 10px;
+}
+.assistant .as-strip[hidden], .assistant .as-picking[hidden] { display: none; }
+.assistant .as-row { display: flex; flex-wrap: wrap; gap: 8px; }
.assistant .as-tile {
flex: none; width: 84px; min-height: 72px; display: flex; flex-direction: column; align-items: center;
justify-content: center; gap: 4px; border-radius: 12px; font: inherit; cursor: pointer;
@@ -661,11 +668,8 @@ select {
.assistant .md table { border-collapse: collapse; }
.assistant .md th, .assistant .md td { border: 1px solid var(--udt-surface1); padding: 4px 8px; }
.assistant .md a { color: var(--udt-accent); }
-.assistant .as-bar { display: flex; gap: 8px; align-items: flex-end; }
-.assistant .as-bar textarea {
- flex: 1; min-height: 48px; max-height: 30vh; resize: none; font: inherit; padding: 12px; border-radius: 12px;
- background: var(--udt-surface0); border: 1px solid var(--udt-surface1); color: var(--udt-text); field-sizing: content;
-}
+.assistant .as-bar { display: flex; gap: 12px; align-items: center; }
+.assistant .as-bar .mic { min-width: 72px; min-height: 72px; font-size: 1.9rem; border-radius: 36px; }
.assistant .mic.on { background: var(--udt-red); border-color: var(--udt-red); color: var(--udt-crust); }
.assistant .mic.on::after { content: attr(data-secs); font-family: inherit; font-size: 0.714rem; margin-left: 4px; }
.assistant .as-op.good { color: var(--udt-green); }
diff --git a/static/modules/assistant.js b/static/modules/assistant.js
index dcb6f27..0159936 100644
--- a/static/modules/assistant.js
+++ b/static/modules/assistant.js
@@ -21,12 +21,15 @@
import { offline } from "../offline.js";
import { render } from "../md.js";
-import { toWav } from "../wav.js";
+import { peak, toWav } from "../wav.js";
// Font Awesome codepoints, present in Inconsolata Nerd Font.
-const G = { send: "", stop: "", mic: "", micOff: "", plus: "",
+const G = { tools: "", stop: "", mic: "", micOff: "", plus: "",
cloud: "", close: "", copy: "", fallback: "" };
const MAX_REC = 59;
+// Below this peak a clip is silence (room noise measured ~260, speech
+// 15000+); the model would invent a question from it, so it is not sent.
+const SILENT = 1500;
const STATUS = { thinking: "thinking…", transcribing: "transcribing…" };
async function post(action, body = {}) {
@@ -109,18 +112,20 @@ function renderLog(log, st, el) {
if (el._stick) log.scrollTop = log.scrollHeight;
}
+function renderPicking(box, st, el) {
+ box.hidden = !st.picking;
+ if (!st.picking || box._key === st.picking) return;
+ box._key = st.picking;
+ box.innerHTML = `<span></span>`;
+ box.firstElementChild.textContent = `${st.picking}: choose the file on the PC`;
+ const cancel = iconBtn(G.close, "Cancel");
+ cancel.onclick = () => act(el, "cancel");
+ box.append(cancel);
+}
+
+// The presets and ops, in an overlay opened from the header, so the
+// transcript keeps the screen.
function renderStrip(strip, st, el) {
- if (st.picking) {
- const key = `picking:${st.picking}`;
- if (strip._key === key) return;
- strip._key = key;
- strip.innerHTML = `<div class="as-picking"><span></span></div>`;
- strip.querySelector("span").textContent = `${st.picking}: choose the file on the PC`;
- const cancel = iconBtn(G.close, "Cancel");
- cancel.onclick = () => act(el, "cancel");
- strip.firstElementChild.append(cancel);
- return;
- }
const cat = st.catalog;
const key = JSON.stringify([cat?.presets, cat?.ops, st.catalogError]);
if (strip._key === key) return;
@@ -142,7 +147,7 @@ function renderStrip(strip, st, el) {
b.innerHTML = `<i class="nf"></i><span></span>`;
b.querySelector("i").textContent = item.icon || G.fallback;
b.querySelector("span").textContent = item.label;
- b.onclick = () => act(el, "pick", { [kind]: item.label });
+ b.onclick = () => { strip.hidden = true; act(el, "pick", { [kind]: item.label }); };
row.append(b);
}
strip.append(row);
@@ -175,10 +180,17 @@ function renderModels(panel, st, el) {
}
}
+// The mic's look follows the recorder at once, not at the next poll: a tap
+// with no feedback invites a second one, which made a silent clip.
+function micLook(el) {
+ el.querySelector(".mic").classList.toggle("on", !!(el._rec || el._recStarting));
+}
+
async function toggleMic(el) {
if (el._rec) { el._rec.stop(); return; }
if (el._recStarting) return;
el._recStarting = true;
+ micLook(el);
let stream, rec;
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
@@ -189,6 +201,7 @@ async function toggleMic(el) {
return;
} finally {
el._recStarting = false;
+ micLook(el);
}
try {
rec = new MediaRecorder(stream);
@@ -204,9 +217,11 @@ async function toggleMic(el) {
clearTimeout(el._recCap);
const secs = (Date.now() - el._recAt) / 1000;
el._rec = null;
+ micLook(el);
if (secs < 0.5) return;
try {
const wav = await toWav(new Blob(chunks, { type: rec.mimeType }));
+ if (peak(wav) < SILENT) return note(el, "nothing heard");
const r = await fetch("/api/assistant/voice", {
method: "POST", headers: { "Content-Type": "audio/wav" }, body: wav,
});
@@ -218,6 +233,7 @@ async function toggleMic(el) {
el._rec = rec;
el._recAt = Date.now();
rec.start();
+ micLook(el);
el._recCap = setTimeout(() => rec.state === "recording" && rec.stop(), MAX_REC * 1000);
}
@@ -233,23 +249,27 @@ export default {
<div class="as-main">
<div class="as-head">
<button class="as-model"><i class="nf"></i><span></span></button>
- <span class="as-status"></span>
</div>
<div class="as-models" hidden></div>
- <div class="as-strip"></div>
+ <div class="as-strip" hidden></div>
+ <div class="as-picking" hidden></div>
<div class="as-op" hidden></div>
<div class="as-log"></div>
<div class="as-notice"></div>
- <div class="as-bar"><textarea rows="1" aria-label="Question"></textarea></div>
+ <div class="as-bar"><span class="as-status"></span></div>
</div>
</div>`;
const head = el.querySelector(".as-head");
- const fresh = iconBtn(G.plus, "New chat");
- fresh.onclick = () => act(el, "new");
- head.append(fresh);
const panel = el.querySelector(".as-models");
+ const strip = el.querySelector(".as-strip");
+ const tools = iconBtn(G.tools, "Presets and file operations", "tools");
+ tools.onclick = () => { strip.hidden = !strip.hidden; panel.hidden = true; };
+ const fresh = iconBtn(G.plus, "New chat", "fresh");
+ fresh.onclick = () => act(el, "new");
+ head.append(tools, fresh);
el.querySelector(".as-model").onclick = () => {
panel.hidden = !panel.hidden;
+ strip.hidden = true;
if (!panel.hidden) act(el, "models");
};
const log = el.querySelector(".as-log");
@@ -257,23 +277,16 @@ export default {
log.addEventListener("scroll", () => { el._stick = log.scrollHeight - log.scrollTop - log.clientHeight < 40; });
el.addEventListener("pointerdown", (e) => {
if (!e.target.closest(".as-models, .as-model")) panel.hidden = true;
+ if (!e.target.closest(".as-strip, .tools")) strip.hidden = true;
});
+ // No keyboard: the PC is at hand for typing. Voice, and Stop while a
+ // reply streams.
const bar = el.querySelector(".as-bar");
- const input = bar.querySelector("textarea");
const mic = iconBtn(G.mic, "Ask by voice", "mic");
mic.onclick = () => toggleMic(el);
- const send = iconBtn(G.send, "Send", "send");
- send.onclick = () => {
- if (el._busy) return act(el, "stop");
- const text = input.value.trim();
- if (!text) return;
- input.value = "";
- post("ask", { text }).catch((e) => { if (!input.value) input.value = text; note(el, e.message); });
- };
- input.addEventListener("keydown", (e) => {
- if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); if (!el._busy) send.onclick(); }
- });
- bar.append(mic, send);
+ const stop = iconBtn(G.stop, "Stop", "stop");
+ stop.onclick = () => act(el, "stop");
+ bar.append(mic, stop);
},
update(st, el) {
@@ -303,19 +316,17 @@ export default {
const panel = el.querySelector(".as-models");
if (!panel.hidden) renderModels(panel, st, el);
renderStrip(el.querySelector(".as-strip"), st, el);
+ renderPicking(el.querySelector(".as-picking"), st, el);
renderOp(el.querySelector(".as-op"), st.op);
renderLog(el.querySelector(".as-log"), st, el);
el.querySelector(".as-notice").textContent = el._note || st.notice || "";
- const send = el.querySelector(".send");
- send.textContent = el._busy ? G.stop : G.send;
- send.setAttribute("aria-label", el._busy ? "Stop" : "Send");
- send.title = send.getAttribute("aria-label");
+ el.querySelector(".stop").hidden = !el._busy;
const mic = el.querySelector(".mic");
const deaf = !st.hears || el._micDenied;
mic.disabled = !st.hears && !el._rec;
mic.textContent = deaf ? G.micOff : G.mic;
- mic.classList.toggle("on", !!el._rec);
+ micLook(el);
mic.title = el._micDenied ? "Microphone not allowed"
: !st.hears ? `${st.wanted || st.model} takes no audio`
: el._rec ? `Recording ${Math.floor((Date.now() - el._recAt) / 1000)}s, tap to send` : "Ask by voice";
diff --git a/static/wav.js b/static/wav.js
index ada6302..b83fae2 100644
--- a/static/wav.js
+++ b/static/wav.js
@@ -34,6 +34,14 @@ export function encodeWav(samples, rate) {
return buf;
}
+// The loudest sample of a 16-bit WAV from encodeWav, to tell silence.
+export function peak(wav) {
+ const v = new DataView(wav);
+ let p = 0;
+ for (let i = 44; i + 1 < wav.byteLength; i += 2) p = Math.max(p, Math.abs(v.getInt16(i, true)));
+ return p;
+}
+
export async function toWav(blob, rate = 16000) {
const ctx = new AudioContext();
try {
diff --git a/tests/test_assistant.py b/tests/test_assistant.py
index 7ea782b..0280e0c 100644
--- a/tests/test_assistant.py
+++ b/tests/test_assistant.py
@@ -199,19 +199,18 @@ class Client(Base):
self.assertTrue(until(lambda: {"type": "models"} in self.d.got))
self.assertEqual(self.m.state()["model"], "m1")
- def test_ask_carries_the_picked_model(self):
+ def test_voice_carries_the_picked_model(self):
self.d.push({"type": "models", "items": [{"id": "ears", "status": "loaded", "cloud": False,
"inputs": ["audio"]}]})
self.assertTrue(until(lambda: self.m.state()["models"]))
self.m.actions["model"]({"id": "ears"})
- self.m.actions["ask"]({"text": "hi"})
- self.assertTrue(until(lambda: {"type": "ask", "text": "hi", "model": "ears"} in self.d.got))
+ self.m.actions["voice"](b"RIFF\x24\x00\x00\x00WAVE" + b"\x00" * 32)
+ self.assertTrue(until(lambda: {"type": "ask", "text": "", "audio": str(a.VOICE),
+ "model": "ears"} in self.d.got))
self.assertTrue(self.m.state()["hears"])
def test_bad_input_is_refused(self):
- for bad in ({}, {"text": ""}, {"text": 3}):
- with self.assertRaises(a.ModuleError):
- self.m.actions["ask"](bad)
+ self.assertNotIn("ask", self.m.actions) # no keyboard on the tablet
with self.assertRaises(a.ModuleError):
self.m.actions["model"]({"id": "nope"})
diff --git a/tests/test_wav.mjs b/tests/test_wav.mjs
index 68f97d0..e28be9a 100644
--- a/tests/test_wav.mjs
+++ b/tests/test_wav.mjs
@@ -15,7 +15,7 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import assert from "node:assert/strict";
-import { encodeWav } from "../static/wav.js";
+import { encodeWav, peak } from "../static/wav.js";
const buf = encodeWav(new Float32Array([0, 1, -1]), 16000);
const v = new DataView(buf);
@@ -29,4 +29,6 @@ assert.equal(v.getUint32(24, true), 16000);
assert.equal(v.getUint16(34, true), 16);
assert.equal(v.getUint32(40, true), 6);
assert.deepEqual([v.getInt16(44, true), v.getInt16(46, true), v.getInt16(48, true)], [0, 32767, -32768]);
+assert.equal(peak(buf), 32768);
+assert.equal(peak(encodeWav(new Float32Array([0.001, -0.002]), 16000)), 65);
console.log("wav ok");