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

224 lines
8.1 KiB
Plaintext

#compdef dais-ctl
# zsh completion for dais-ctl (tools/dais-ctl). Keep in sync with the verbs in
# that script's buildRequest() and usage block.
# Install: symlink into a dir on $fpath, e.g.
# ln -s ~/dais/tools/_dais-ctl ~/.zsh/completion/_dais-ctl
# then restart zsh (or: rm -f ~/.zcompdump*; compinit).
# Repo root from the resolved dais-ctl exe (tools/dais-ctl -> tools -> repo),
# so live reads work no matter where the symlink lives on $PATH.
_dais_ctl_repo() {
local exe=${commands[dais-ctl]:-}
[[ -z $exe && $words[1] == */* ]] && exe=$words[1]
[[ -n $exe ]] || return 1
print -r -- ${exe:A:h:h}
}
# Target slots, read live. The durable overlay (~/.local/state/dais, set via
# $DAIS_STATE_DIR) shadows config wholesale, so prefer it; fall back to
# config/dais.edn ($DAIS_CONFIG override). Each slot is annotated with its
# type and pane so the menu mirrors `dais-ctl target list`.
_dais_ctl_slots() {
local repo=$(_dais_ctl_repo)
local overlay=${DAIS_STATE_DIR:-$HOME/.local/state/dais}/targets.edn
local src=$overlay
[[ -r $src ]] || src=${DAIS_CONFIG:-$repo/config/dais.edn}
[[ -r $src ]] || return 1
local flat=$(tr -d '\n' < $src)
local -a entries=( ${(f)"$(print -r -- $flat | grep -oE '[0-9]+[[:space:]]*\{:type[^}]*\}')"} )
local -a slots=()
local e slot type pane
for e in $entries; do
slot=${e%%[^0-9]*}
type=$(print -r -- $e | grep -oE ':type[[:space:]]+:[a-z]+'); type=${type##*:}
pane=$(print -r -- $e | grep -oE ':pane[[:space:]]+"[^"]*"'); pane=${pane#*\"}; pane=${pane%\"}
slots+=( "${slot}:${type}${pane:+ $pane}" )
done
(( ${#slots} )) && _describe -t slots 'target slot' slots
}
# tmux panes for `target set <slot> <pane>` and `dictate <action> <pane>` — the
# session:window.pane shape dais-ctl expects, the pane-ID shape (immune to
# pane_index renumbering, and what airc reports), plus the two pseudo-targets.
# Specs go through compadd, not _describe: their names carry colons, which
# _describe would split off as a description. IDs have none, so they can carry
# the spec + command as their description.
_dais_ctl_panes() {
local -a special=(
'focus:deliver to the focused app via ydotool'
'current:the pane that is current right now'
)
_describe -t special 'pseudo-target' special
if (( $+commands[tmux] )); then
local -a panes=( ${(f)"$(tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index}' 2>/dev/null)"} )
(( ${#panes} )) && _wanted panes expl 'tmux pane' compadd -a panes
local -a ids=( ${(f)"$(tmux list-panes -a -F '#{pane_id}:#{session_name}:#{window_index}.#{pane_index} [#{pane_current_command}]' 2>/dev/null)"} )
(( ${#ids} )) && _describe -t paneids 'tmux pane id' ids
fi
}
# Recent trace_ids from the event log for `replay`.
_dais_ctl_traces() {
local repo=$(_dais_ctl_repo)
local dir=${DAIS_EVENTS_DIR:-$repo/events}
[[ -d $dir ]] || return 1
local -a traces=( ${(f)"$(grep -hoE '"trace_id":"[^"]+"' $dir/*.jsonl(N) 2>/dev/null | grep -oE '[0-9a-f-]{36}' | tail -50 | awk '!seen[$0]++')"} )
(( ${#traces} )) && _describe -t traces 'trace id' traces
}
_dais_ctl() {
local curcontext=$curcontext state line
typeset -A opt_args
local -a subcommands=(
'status:show daemon status'
'inject:feed a fake transcript into the router'
'send:raw text/keys straight to the target (router bypassed)'
'dictate:latch a recording aimed at one pane (airc mic button)'
'brief:deliver the voice-input briefing (pointer, or --full text)'
'vad:toggle the VAD session (F9)'
'rec:toggle the manual record latch (F10)'
'esc:send Escape to the target (F11)'
'off:force voice off'
'arm:next utterance must be a command'
'mute:warm pause: drop utterances until unmute'
'unmute:resume after a mute'
'dry-run:toggle dry-run (route & plan, do not deliver)'
'target:manage delivery target slots'
'set:change a session setting (enter-mode/strategy/language)'
'events:print the last N events'
'replay:re-run a trace by id'
'shutdown:stop the daemon'
)
_arguments -C \
'1:command:->command' \
'*::arg:->args'
case $state in
command) _describe -t commands 'dais-ctl command' subcommands ;;
args)
case ${line[1]} in
target)
local -a target_actions=(
'set:point a slot at a pane/focus/current'
'use:make a slot active'
'release:forget a slot, freeing the digit for reuse'
'next:cycle to the next slot'
'prev:cycle to the previous slot'
'next-live:next deliverable slot (skips dead targets)'
'list:list configured slots'
'panes:list all tmux panes (annotated)'
'pick:fzf-pick a pane into a slot'
)
_arguments -C \
'1:action:->taction' \
'*::targ:->targs'
case $state in
taction) _describe -t actions 'target action' target_actions ;;
targs)
case ${line[1]} in
set)
_arguments \
'1:slot:_dais_ctl_slots' \
'2:pane:_dais_ctl_panes'
;;
use) _arguments '1:slot:_dais_ctl_slots' ;;
release) _arguments '1:slot:_dais_ctl_slots' ;;
pick) _arguments '1:slot (default active):_dais_ctl_slots' ;;
esac
;;
esac
;;
set)
_arguments -C \
'1:key:->skey' \
'2:value:->sval'
case $state in
skey)
local -a keys=(
'enter-mode:dictation submit behavior'
'strategy:how an utterance is classified'
'language:transcription language'
)
_describe -t keys 'setting' keys
;;
sval)
local -a values
case ${line[1]} in
enter-mode)
values=(
'no-enter:type, never press Enter'
'enter-auto:press Enter when the utterance looks complete'
'enter-always:always press Enter'
)
;;
strategy)
values=(
'whole-match:command iff the whole utterance matches'
'prefix:commands must start with the prefix word'
'key-armed:everything is dictation unless armed'
)
;;
language)
values=(
'en:English'
'fi:Finnish'
'auto:autodetect (needs a multilingual model)'
)
;;
esac
(( ${#values} )) && _describe -t values "${line[1]}" values
;;
esac
;;
dictate)
_arguments -C \
'1:action:->daction' \
'2:pane:->dpane'
case $state in
daction)
local -a dactions=(
'start:open the mic aimed at one pane'
'stop:close the mic and TRANSCRIBE'
'discard:close the mic and throw the recording away'
'toggle:start when idle, stop when recording'
)
_describe -t actions 'dictate action' dactions
;;
dpane) _dais_ctl_panes ;;
esac
;;
brief)
_arguments '1:option:(--full)'
;;
replay)
_arguments '1:trace id:_dais_ctl_traces'
;;
events)
_message -e count 'number of events (default 20)'
;;
inject)
_message -e text 'transcript text'
;;
send)
if [[ ${line[2]} == --keys || ${words[2]} == --keys ]]; then
_message -e chords 'key chords (C-c Enter S-Tab …)'
else
_alternative \
'flags:flag:(--keys)' \
'text:text: _message -e text "raw text for the target"'
fi
;;
esac
;;
esac
}
if [[ $funcstack[1] = _dais_ctl ]]; then
_dais_ctl "$@"
else
compdef _dais_ctl dais-ctl
fi