Files
dais/AGENTS.md
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

75 lines
3.2 KiB
Markdown

# Working on dais
Read `ai/` first (`ai/gotchas.md` especially) — it holds the non-obvious,
hard-won facts. It is **descriptive** (facts about the system): when it
disagrees with the code, the code wins and the `ai/` file gets fixed.
Nothing in this repo is **normative** — the agreed design lives with the user
and in the commit log, not in a plan file. So when the code looks like it drifted
from a decision, that's a decision until proven otherwise: flag it and ask,
rather than silently "fixing" it to match your own reading.
## Build & test
```sh
clojure -X:test # MUST run from the repo root (deps.edn here)
cd ear && pixi run check # ear deps + recorder presence
```
Clojure tests use dry-run executors and scratch tmux server names — never the
user's tmux sessions. Keep it that way.
## Safety: the user's daemon is usually LIVE
`systemctl --user status dais` — if active, it executes for real, and the
default target is the **focused app**: a careless `tools/dais-ctl inject ...`
types into whatever window the user has focused. For manual testing, start a
private dry-run instance instead:
```sh
# Isolate the DIRS, not just the socket: with only a socket override the test
# daemon overwrites the live daemon's state.json + marker files (and its
# shutdown hook deletes them), and a targets change clobbers targets.edn.
D=/tmp/dais-test; mkdir -p $D/{runtime,events,state}
DAIS_RUNTIME_DIR=$D/runtime DAIS_EVENTS_DIR=$D/events DAIS_STATE_DIR=$D/state \
clojure -M:daemon $D/control.sock --dry-run --no-ear &
DAIS_SOCKET=$D/control.sock tools/dais-ctl inject press enter
```
Kill it by matching its own environ — `pkill -f dais.daemon` would take the
user's systemd unit with it (same cmdline), and the restart drops their
session-only settings:
```sh
for p in $(pgrep -f "dais.daemon"); do
tr '\0' ' ' < /proc/$p/environ | grep -q "$D" && kill $p
done
```
To deliver for real, add `DAIS_CONFIG=$D/dais.edn` with `:tmux ["tmux" "-L"
"dais-test"]` and a slot pointing at a pane on that scratch server. Use the
window-INDEX form (`scratch:0.0`): automatic-rename retitles a window after its
foreground command, so a name-based spec stops resolving (see gotchas).
After changing daemon/ear code: run tests, then
`systemctl --user daemon-reload && systemctl --user restart dais`.
## Invariants (do not relax)
- Subprocesses are argv vectors, never shell strings; dictation text travels
on **stdin** (`tmux load-buffer -`, `ydotool type --file -`), never argv.
- Key names are whitelisted in BOTH `dais.router` (what speech can produce)
and `dais.executor` (what may be delivered). New keys update both + tests.
- A failed command match in a command-only context (armed, prefixed) executes
nothing — it must never fall through to typing.
- The pure core (`router`, `state`, `event`, `ear/ear-message`) stays I/O-free;
socket/file/process I/O lives in `daemon`, `executor`, `ear`, `log`, `notify`.
- Events are string-keyed maps that round-trip JSON unchanged.
## Conventions
- Config is EDN (`config/dais.edn`); the `:vad` map deliberately uses
underscore string keys (it is JSON-serialized to the Python worker).
- Wire events follow `dais.event.v1` (see daemon docstring for the op set).
- Commit messages: plain, no attribution trailers.