Files
Tommi Kyntola 1ea27f1eec Dictate op: one recording aimed at one pane
Driving, with the airc viewer on the car screen: an agent's input box is
visible and what you want to give it is a PROMPT, a sentence, not a keypress.
airc's buttons cover keypresses well and the Android app has IME dictation, but
the car browser has no dictation at all — so today a prompt means the laptop
keyboard. dais already transcribes locally and pastes into a tmux pane; what
was missing is a way to say "record now, and deliver it to the pane I am
looking at" without touching the laptop.

    {"op":"dictate","action":"toggle","pane":"%19"}

start | stop | discard | toggle, the last resolved against the CURRENT mode so
a client that missed a poll — or a latch someone started at the desk — cannot
be inverted by a stale button. stop TRANSCRIBES and discard throws the
recording away, which is the existing latch-vs-voice-off rule and what makes a
remote ✕ useful: a misheard prompt can be dropped instead of typed. Omit the
pane and it is F10 over the socket.

The pane is an ephemeral override (:dictate-target), never a slot. transition!
persists on any :targets/:active-slot change, so writing a slot would churn
targets.edn and the digits addressed by voice; a reserved slot is worse, since
load-targets honors the overlay only while (get targets active-slot) is truthy
and a dangling active-slot silently discards every persisted target on the next
start. save-targets! writes only :targets/:active-slot, so nothing a car-side
tap aims at can survive a restart — asserted by a test rather than by new code.

Two orderings are load-bearing, and both are the opposite of the obvious one:

- The override is set in the same transition as the mode change and AFTER it.
  Every mic OPEN drops a pending override (drop-override), which is exactly
  what keeps a forgotten one from stealing a later utterance — so setting the
  aim first would erase it.
- It is consumed after dispatch, not before, and only when the plan actually
  DELIVERED. :armed is cleared before dispatch for the opposite reason; copying
  that placement here would deliver to the slot instead. An utterance the
  confidence gate refused ("say again?") keeps its aim, or the repeat lands in
  the wrong pane.

No TTL. The plan sketched one; the rule set turned out not to need a clock,
because a mic open, a voice-off and any explicit target op all drop the aim,
and the only utterance that can reach a pending override is the one it was set
for. Dropping the TTL also removes the failure mode where an aim expires
mid-sentence.

state gains the precedence split the feature needs: active-target is where an
UTTERANCE goes (override, else slot) and is the single point everything the
router produces reads through; slot-target is the active slot ignoring any
override, and the desk-side router-bypassing paths now use it — the keystroke
bridge behind dais-top's passthrough lock and F11/esc are keys typed by
someone sitting at the machine, aimed at the slot they can see, and must not
follow a recording someone made from the car.

The ear's transcribe-vs-discard decision moves from a hardcoded via string to
ear/transcribing-stops, so the next caller that latches has one obvious place
to register — miss it and recordings vanish silently, which is a bad way to
find out.

The dictation run is now keyed on the delivery LABEL rather than the slot: an
override, a re-pointed slot and two slots naming one pane all have to answer
"same cursor?" correctly, and only the label does.

parse-target-value accepts a bare pane id ("%23"). tmux takes one anywhere a
target-pane goes, it is how airc reports panes, and it is the one spec form
immune to the pane_index renumbering trap — so `dais-ctl target set 3 %19`
starts working as a side effect.

Reporting: dictate_target rides along in state.json, the status query, the
state_changed broadcast and the target-list reply (a UI that missed an event
self-heals on the poll it already runs), and dais-top shows the override on the
target line so the cockpit never claims the slot while speech goes elsewhere.
tools/dais-ctl gains `dictate` with completion, which makes the whole feature
hand-testable without airc.

Also drops the last references to FABLE_PLAN.md, GOAL.md and CODEX_PLAN.md,
deleted in 9353d85: the README reading order, one code comment, and AGENTS.md's
claim that a missing file is normative.
2026-08-17 16:46:42 +03:00

15 KiB
Raw Permalink Blame History

dais tools

Thin clients for the daemon's control socket ($XDG_RUNTIME_DIR/dais/control.sock, override with $DAIS_SOCKET).

The daemon runs as a systemd --user unit (tools/dais.service, symlinked into ~/.config/systemd/user/ and enabled): systemctl --user start dais, logs via journalctl --user -u dais. Running clojure -M:daemon directly is the foreground/dev path (add --dry-run to plan without executing, --no-ear to skip the audio worker) — stop the unit first so they don't share a socket.

Tool Purpose
dais-ctl Full verb set (node). Status, inject, send, dictate, targets, events, replay.
dais-top Live TUI cockpit: mode, mic level meter, heard-list, counters, targets.
dais-vad Toggle the VAD session. Bind to F9.
dais-rec Toggle the manual record latch. Bind to F10.
dais-esc Send Escape to the active target immediately. Bind to F11.

The three dais-* toggles are plain sh + socat with no PATH/zsh assumptions, so they work as KDE global shortcuts as-is. State lives in the daemon — the scripts are stateless one-liners.

Examples

Pipeline smoke test without a microphone (inject feeds a fake transcript into the router; with --dry-run nothing reaches tmux/ydotool):

tools/dais-ctl status
tools/dais-ctl inject press enter            # whole-utterance command
tools/dais-ctl inject choose option two      # grammar: fillers + ordinals
tools/dais-ctl inject please review PR 123   # dictation -> type-text, no submit
tools/dais-ctl inject voice off              # voice control of the daemon itself

send is the other end of that: no router, no log, straight to the active target. It exists for dais-top's passthrough lock (below), and is handy for scripting a pane:

tools/dais-ctl send "npm test"               # raw text, verbatim
tools/dais-ctl send --keys Enter             # chords: C-c, S-Tab, M-Right, …

Brief a fresh agent session about voice input (delivers a pointer to BRIEF.md into the target — the agent reads the file itself; --full pastes the whole text for targets without file access). Then say "press enter":

tools/dais-ctl brief

Real dictation via the latch (speak between the two rec calls):

tools/dais-ctl rec      # or press F10
# ... speak ...
tools/dais-ctl rec      # stop -> transcribe -> route -> deliver
tools/dais-ctl events 3 # see what happened

dictate is the same latch aimed at one pane, for a remote UI with no keyboard — a mic button in airc's browser control bar taps this with the pane it is currently viewing (%19), so you can speak a prompt into it from the car:

tools/dais-ctl dictate start %19   # open the mic, aimed at that pane only
tools/dais-ctl dictate stop        # close it and TRANSCRIBE (like a second `rec`)
tools/dais-ctl dictate discard     # close it and throw the recording away (the ✕)
tools/dais-ctl dictate toggle %19  # what the button sends: start when idle, stop when hot

The pane is an ephemeral, single-use override, not a slot: it never touches targets.edn, it aims utterances only (keys from the bridge and esc still go to the active slot you can see on screen), and it is dropped the moment anything else opens the mic, says "voice off", or switches slots. dais-top shows it as a 🎙 %19 badge next to the target while it is live. Delivery is type-only by design — read the transcript in the pane, then press Enter yourself (airc has a button for that).

Targets (slot 1/2/... are defined in config/dais.edn and adjustable live):

tools/dais-ctl target list
tools/dais-ctl target set 2 app:claude.0 # a tmux pane (window NAMES work too)
tools/dais-ctl target set 1 focus        # the focused app (ydotool)
tools/dais-ctl target set 3 current      # grab the active tmux pane
tools/dais-ctl target use 2              # switch; or say "target two"
tools/dais-ctl target release 3          # forget slot 3, freeing the digit
tools/dais-ctl target next               # cycle to the next slot (= "next target")
tools/dais-ctl target prev               # cycle to the previous slot
tools/dais-ctl target next-live          # next deliverable slot (skips dead targets)
tools/dais-ctl target panes              # all panes, agents ★, slots annotated
tools/dais-ctl target pick [slot]        # fzf-pick a pane (default: active slot)

In dais-top, t opens the same picker as an overlay (↑/↓, Enter, then the slot digit). Picked targets are durable: the daemon persists them to ~/.local/state/dais/targets.edn and they override the config/dais.edn defaults on restart — delete that file to return to config defaults.

release is the complement: persistence means a slot you picked stays picked even after its pane dies (which is what you want — dais-driven panes come and go), so release is how you say you are done with one and hand the digit back to the picker. In dais-top press x, then the slot digit. It takes a digit rather than acting on the picker's highlighted row because the usual reason to release a slot is that its pane is gone — and a gone pane has no row in the picker. Releasing the active slot moves the active pointer to the next surviving slot; releasing the last remaining slot is refused (there would be nothing to deliver to).

Debugging a miss:

tools/dais-ctl events 20                 # recent events across the log
tools/dais-ctl replay <trace_id>         # full chain for one utterance
jq . "$XDG_RUNTIME_DIR/dais/state.json"  # mode/target/last utterance

One-shot command arming (the next utterance must be a command; a miss does nothing instead of being typed):

tools/dais-ctl arm
tools/dais-ctl off                       # force voice off
tools/dais-ctl shutdown                  # stop the daemon (cleans up socket/markers)

dais-top

tools/dais-top

Full-screen status cockpit: mode badge (pulsing while recording), a live mirrored waveform of the mic (green where the VAD heard speech, cyan ambient, flat gray baseline when quiet) with a Silero speech-probability meter (VAD mode only — the latch records to a file, so it shows a pulse animation instead), the active target labelled with what is actually running in it (app:claude.0 claude ~/dais, cwd middle-elided when the header is tight — a focus target can't be introspected, so it stays bare; a live dictate override gets a 🎙 %19 badge in front of it, because speech and keys can be aimed at two different panes at once and the surface must not hide one), target slots with the active one highlighted, the last utterances with their outcome — dictation quoted (“…” → typed), interpreted commands marked » … → Enter in yellow, drops ✗ dropped: … — and today's counters (listened time, utterances, words, drops, mean ASR latency) seeded from the event log. A confidence-gated refusal (see :confidence-min-logprob in config/dais.edn) flashes uncertain — say again? with the heard text in the footer — repeating is cheaper than undoing garbage.

Control keys: v VAD toggle · r record latch · Esc send Escape · 1–5 switch target · Tab next live target (skips dead ones) · t target picker (tmux panes plus a ⌖ focus row, so a slot can always be pointed back at the focused app) · x release a slot, then 1–5 (frees the digit; any other key cancels) · a arm · m mute (warm pause) · d dry-run toggle · e cycle enter-mode · s cycle router strategy · w toggle airc, the Tesla terminal viewer (~/airc; an AIRC badge shows while broadcasting — it is a public tunnel; DAIS_AIRC overrides the tool path, absent tool hides it all) · k keylock · p passthrough · K idle auto-lock · ? help · q quit.

Keyboard lock — dais-top is a single-key control surface, so typing into it by mistake flips real state. Two locks make that harmless: k keylock ignores every key (the footer acknowledges each swallowed one), p passthrough forwards them to the active target instead, so the window you accidentally typed into behaves like the pane you meant. Ctrl-] or F12 leaves either lock; while locked, any other key just shows the way out. Passthrough sends printable runs as text and translates the rest into chords (Enter, Tab, Shift-Tab, arrows, C-<letter>, M-<char>, …) over the send op above — no router, no event log, deliberately not a keylogger. It refuses a focus target and falls back to keylock: ydotool would type into whichever window has focus, which is dais-top itself. K cycles an idle auto-lock (off → 15 → 30 → 60 s, persisted next to the theme in ~/.local/state/dais/) for leaving dais-top up on a second screen; it is off by default and never fires while an overlay is open.

The footer lists only the frequent keys; press ? for the full key + voice-command reference — it also lists the unobtrusive cycle keys (> next / < prev target) and your config commands, pulled live from the daemon so the list never drifts from config/dais.edn. The e/s toggles (also dais-ctl set enter-mode|strategy|language ...) are session-only — a daemon restart returns to the config defaults; calibration knobs (VAD tuning, idle timeout, confidence floor) stay config-file only on purpose. Language switching has no dais-top key on purpose: it only makes sense after swapping config to a multilingual model, so it stays a deliberate dais-ctl set language act.

Entirely optional: when no dais-top is connected the daemon broadcasts nothing and the ear skips level computation entirely (the daemon toggles the meter via set_levels on subscriber transitions) — zero overhead.

Voice commands

Daemon controls — {:control kw} commands, recognized in every router strategy (unprefixed/unarmed escape hatches). These are built-in default commands; bind your own phrases to the same actions in config (see Configuring commands):

Say Effect
"voice off" / "dais off" stop listening (in-flight latch recording is discarded)
"mute" / "unmute" warm pause: mic stays on but every utterance is dropped until "unmute"
"toggle dry run" flip dry-run: utterances still route and show in dais-top, but nothing reaches the target
"next target" cycle target slot
"target two" (one–five, ordinals, digits) switch slot

Built-in whole-utterance commands:

Say Effect
"scratch that" C-u — clear the input line
"cancel" / "stop" Escape
"yes" / "no" type yes/no + Enter

Key presses: trigger verb (press/hit/push/choose/select/pick/answer) + keys; fillers (the/a/and/then/option/number/key/button) ignored; max 5 keys. Keys: enter, return, escape, esc, up, down, left, right, tab, backspace, one–nine / first–ninth / digits, control|ctrl + a c d k u w.

"press enter"                      -> Enter
"choose option two"                -> 2
"select the third option"          -> 3
"press down and enter"             -> Down Enter
"press control a then control k"   -> C-a C-k (clear the line)

Every non-filler word must map to a key, or the utterance is dictation — "select the right abstraction for this" types as text. Everything that isn't a command is dictation: typed as one line, never submitted (:no-enter; with :enter-auto a trailing spoken "enter" submits).

A pause splits one spoken paragraph into several utterances, so a dictation that continues the previous one is typed with a leading space — otherwise the pastes would butt together ("right now.What happens"). The run ends when anything else moves the cursor (submit, a keypress command, a macro, a raw send, esc), when you switch target slots, on voice off/mute, or after :dictation-continue-gap-s seconds of not dictating (60 by default; nil disables just the timeout).

Configuring commands

Add your own under config/dais.edn :router :commands — a phrase maps to:

:commands
{"clear"        {:keys ["C-u"]}                      ; press a key / chord
 "say hi"       {:text "hello" :submit true}         ; type text, then Enter
 "new terminal" {:keys ["C-M-t"]                     ; ctrl-alt-t (focus target)
                 :description "open a terminal"}      ; shown in dais-top ?
 "shush"        {:control :mute}}                     ; a daemon control (alias)

A {:control kw} entry runs a daemon control instead of delivering to the target — :voice-off, :next-target, :mute, :unmute, :toggle-dry-run. The built-in phrases above are just default :control commands, so this is how you add your own aliases (e.g. "shush" → mute). Control commands are escape hatches: they work in every strategy, unprefixed and unarmed.

Keypress chords are tmux-style: modifier prefixes C- ctrl, M- alt, S- shift, s- super, then a base key — letters, digits, Enter Escape Tab Space BSpace, arrows, Home End PgUp PgDn, F1–F12. The same chord renders to a tmux send-keys token and to ydotool keycodes, so a command works on either target (super and WM globals like C-M-t only do anything on a :focus target). Config commands are trusted, so they may use the full chord vocabulary; the narrow voice keypress grammar above is unchanged — speech can never synthesize a M-/C-M- chord.

:description is a one-liner listed under configured in the dais-top ? help overlay (without it, the overlay shows the synthesized effect).

A :macro runs an ordered list of steps against the active target — each step is {:text … :submit …}, {:keys […]}, or {:delay ms} (a pause). Top-level :delay paces between steps; a {:delay ms} step is an explicit wait. Steps run synchronously and stop at the first failure.

"setup leanheat"
{:description "cd into leanheat-app, new window, launch claude"
 :macro [{:text "cd ~/code/lh/leanheat-app" :submit true}
         {:text "tn app" :submit true}
         {:text "aclaude" :submit true}]
 :delay 120}                       ; ms between steps

"new terminal"
{:description "open a terminal, then maximize (focus target)"
 :macro [{:keys ["C-M-t"]}
         {:delay 400}              ; wait for the window
         {:keys ["C-M-Right"]}]}

A macro fires like any command — say its phrase, or dais-ctl inject "<phrase>". It runs entirely against whichever target is active, so point the right slot first (tmux pane for typing, focus for window-manager chords).

Statusline integration

$XDG_RUNTIME_DIR/dais/ holds state.json plus marker files meant for [ -f ... ] checks in a tmux powerline / Claude statusline segment:

[ -f "$XDG_RUNTIME_DIR/dais/mic-recording" ] && echo "🎤"
[ -f "$XDG_RUNTIME_DIR/dais/speech-detected" ] && echo "🗣"
[ -f "$XDG_RUNTIME_DIR/dais/muted" ]          && echo "🔇"
[ -f "$XDG_RUNTIME_DIR/dais/dry-run" ]         && echo "DRY"

zsh completion

tools/_dais-ctl completes every verb, the target/set sub-actions, and the enter-mode/strategy/language value sets. Slots (target use|set|pick), tmux panes (target set), and replay trace ids are read live — slots from the durable overlay ($DAIS_STATE_DIR, default ~/.local/state/dais/targets.edn) falling back to config/dais.edn, traces from the event log. Symlink it onto your $fpath and restart zsh:

ln -s "$PWD/tools/_dais-ctl" ~/.zsh/completion/_dais-ctl   # a dir on your $fpath

Keep it in sync with buildRequest() in dais-ctl when verbs change.