Files
dais/tools/dais-ctl
T
Tommi Kyntola 48db46eca1 dais-top: keyboard lock, passthrough, target process/cwd labels
Three improvements to the cockpit, all about typing into the right window.

Target labels: `target list` now reports what is actually running in each
tmux target — pane_current_command and pane_current_path — so the header
reads `app:claude.0 claude ~/dais` instead of a bare pane spec. One
list-panes -a call (daemon/pane-details) serves every slot and doubles as
the liveness answer, which is cheaper than the per-slot pane-exists? calls
it replaces (those stay as the tmux-down fallback). Rows are indexed under
both the window-NAME and window-INDEX spec forms, because a stored target
may use either. A :focus target can't be introspected (no kdotool here), so
it stays bare. dais-top elides the cwd middle-first and then drops it, and
the command after it, as the header runs out of columns — the ear/armed/live
block is never the part pushed off screen.

Keyboard lock: dais-top is a single-key control surface, so typing into it
by mistake flips real state. `k` ignores every key (each swallowed one is
acknowledged in the footer); Ctrl-] or F12 always leaves a lock, and while
locked any other key just shows the way out. `K` cycles an idle auto-lock
(off -> 15 -> 30 -> 60s, persisted next to the theme file) — off by default,
and it never fires while an overlay is open.

Passthrough: `p` forwards keys to the active target instead of dropping
them, so the window you typed into by accident behaves like the pane you
meant. Printable runs go as text, the rest as chords (Enter, Tab, S-Tab,
arrows, C-<letter>, M-<char>). It refuses a :focus target and falls back to
keylock, re-checking per chunk since voice can move the active slot
mid-pass: ydotool types into whatever has focus, which during passthrough is
dais-top itself — every key would re-enter its own stdin.

New `send` op carries it: raw delivery to the active target, router
bypassed, exactly one of text or keys, chords still executor-validated so an
unknown one is refused rather than typed. Honors dry-run like any other
delivery. Deliberately NOT recorded — an event line per keystroke would turn
events/*.jsonl into a keylogger transcript. Also exposed as
`dais-ctl send [--keys]`, with zsh completion.

executor: the bridge needs unbracketed paste (a single keystroke must look
like typing, not a paste per character), so tmux-type-plan takes a
bracketed? flag; dictation stays bracketed as one deliberate paste, and text
still travels on stdin either way. And a latent bug it turned up: send-keys
"S-Tab" exits 0 but delivers a PLAIN Tab — shift-tab is its own tmux key
name, BTab. That silently broke shift-tab, which is how Claude Code cycles
permission modes.

ai/ records the tmux traps (BTab, per-pane info needs list-panes -a, the
bracketing, the focus feedback loop); tools/README.md documents the keys.
2026-08-17 12:59:04 +03:00

253 lines
9.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
// dais-ctl — thin client for the dais daemon socket. Dependency-free.
//
// Usage:
// dais-ctl status
// dais-ctl inject <text...> feed a fake transcript into the router
// dais-ctl send <text...> raw text straight to the target, router
// bypassed and nothing logged (the keystroke
// bridge behind dais-top's passthrough lock)
// dais-ctl send --keys <chord…> raw key chords, e.g. C-c Enter S-Tab
// dais-ctl brief [--full] deliver the voice-input briefing to the
// target: a pointer to BRIEF.md (default)
// or its full text (--full)
// dais-ctl vad toggle the VAD session (F9)
// dais-ctl rec toggle the manual latch (F10)
// dais-ctl esc send Escape to the target (F11)
// dais-ctl off force voice off
// dais-ctl arm next utterance must be a command
// dais-ctl mute | unmute warm pause: drop utterances until unmute
// dais-ctl dry-run toggle dry-run (route & plan, don't deliver)
// dais-ctl target set <slot> <session:window.pane|focus|current>
// dais-ctl target use <slot>
// dais-ctl target release <slot> forget a slot, freeing the digit for reuse
// (refuses the last remaining slot)
// dais-ctl target next | prev cycle to the next/previous slot
// dais-ctl target next-live next deliverable slot (skips dead targets)
// dais-ctl target list
// dais-ctl target panes list all tmux panes (annotated)
// dais-ctl target pick [slot] fzf-pick a pane into a slot
// (default: the active slot)
// dais-ctl set enter-mode <no-enter|enter-auto|enter-always>
// dais-ctl set strategy <whole-match|prefix|key-armed>
// dais-ctl set language <en|fi|...|auto> transcription language
// (needs a multilingual model for non-en/auto)
// session-only; config wins on restart
// dais-ctl events [n]
// dais-ctl replay <trace_id>
// dais-ctl shutdown
//
// Socket: $DAIS_SOCKET, else $XDG_RUNTIME_DIR/dais/control.sock
const net = require("node:net");
const { spawn } = require("node:child_process");
const { randomUUID } = require("node:crypto");
const SOCKET =
process.env.DAIS_SOCKET ??
`${process.env.XDG_RUNTIME_DIR ?? "/tmp"}/dais/control.sock`;
function usage(code = 1) {
const lines = require("node:fs")
.readFileSync(__filename, "utf8")
.split("\n")
.filter((l) => l.startsWith("// "))
.map((l) => l.slice(3));
console.error(lines.join("\n"));
process.exit(code);
}
// ---------- socket helper (multiple requests per connection) ----------
function connectSock() {
return new Promise((resolve, reject) => {
const sock = net.createConnection({ path: SOCKET });
sock.setEncoding("utf8");
const pending = [];
let buf = "";
sock.on("data", (chunk) => {
buf += chunk;
let nl;
while ((nl = buf.indexOf("\n")) >= 0) {
const line = buf.slice(0, nl);
buf = buf.slice(nl + 1);
const cb = pending.shift();
if (cb && line.trim()) {
try { cb(JSON.parse(line)); } catch { cb(null); }
}
}
});
sock.on("connect", () =>
resolve({
request: (req) =>
new Promise((res) => {
pending.push(res);
sock.write(JSON.stringify(req) + "\n");
}),
end: () => sock.end(),
}));
sock.on("error", (err) => reject(err));
});
}
function finish(resp) {
console.log(JSON.stringify(resp, null, 2));
process.exit(resp && resp.ok ? 0 : 1);
}
// ---------- interactive pane picker ----------
function fzf(lines, header) {
return new Promise((resolve) => {
const p = spawn("fzf",
["--height=40%", "--reverse", "--delimiter=\t", `--header=${header}`],
{ stdio: ["pipe", "pipe", "inherit"] });
let out = "";
p.stdout.on("data", (d) => (out += d));
p.on("close", () => resolve(out.trim() || null));
p.on("error", () => {
console.error("dais-ctl: fzf not available");
resolve(null);
});
p.stdin.end(lines.join("\n") + "\n");
});
}
async function pickFlow(slotArg) {
const sock = await connectSock();
const resp = await sock.request({ op: "target", action: "panes" });
if (!resp?.ok) finish(resp ?? { ok: false, error: "no response" });
const home = process.env.HOME;
const lines = resp.panes.map((p) => {
const tags = [
p.agent ? "★ agent" : null,
p.slot != null ? `= slot ${p.slot}` : null,
].filter(Boolean).join(", ");
const raw = p.path ?? "";
const path = home && raw.startsWith(home) ? "~" + raw.slice(home.length) : raw;
return `${p.pane}\t[${p.command}]\t${path}${tags ? `\t(${tags})` : ""}`;
});
const slot = slotArg ? Number(slotArg) : resp.active_slot;
const sel = await fzf(lines, `pick pane for target slot ${slot}`);
if (!sel) process.exit(1);
const pane = sel.split("\t")[0];
finish(await sock.request({ op: "target", action: "set", slot, pane }));
}
// ---------- request builder (single-shot verbs) ----------
function buildRequest(argv) {
const [cmd, ...rest] = argv;
switch (cmd) {
case "status":
return { op: "query", query: "status" };
case "inject": {
if (rest.length === 0) usage();
return {
op: "publish",
event: {
schema: "dais.event.v1",
id: randomUUID(),
time: new Date().toISOString(),
type: "voice.transcript",
source: { module: "dais-ctl", provider: "inject" },
payload: { text: rest.join(" ") },
},
};
}
case "send": {
if (rest.length === 0) usage();
return rest[0] === "--keys"
? { op: "send", keys: rest.slice(1) }
: { op: "send", text: rest.join(" ") };
}
case "brief": {
const fs = require("node:fs");
const path = require("node:path");
const briefPath = path.resolve(__dirname, "..", "BRIEF.md");
const text =
rest[0] === "--full"
? fs.readFileSync(briefPath, "utf8")
: `Voice input notice: parts of my input arrive via speech-to-text and may ` +
`contain recognition errors or noise. Read ${briefPath} for how to cope ` +
`(verify unclear intent, match dictated identifiers against the repo, ` +
`ignore noise fragments, prefer numbered options).`;
return {
op: "publish",
event: {
schema: "dais.event.v1",
id: randomUUID(),
time: new Date().toISOString(),
type: "voice.transcript",
source: { module: "dais-ctl", provider: "brief" },
payload: { text },
},
};
}
case "vad":
return { op: "control", action: "toggle-vad" };
case "rec":
return { op: "control", action: "toggle-record" };
case "esc":
return { op: "control", action: "esc" };
case "off":
return { op: "control", action: "voice-off" };
case "arm":
return { op: "control", action: "arm" };
case "mute":
return { op: "control", action: "mute" };
case "unmute":
return { op: "control", action: "unmute" };
case "dry-run":
return { op: "control", action: "toggle-dry-run" };
case "shutdown":
return { op: "control", action: "shutdown" };
case "target": {
const [action, slot, value] = rest;
if (action === "set" && slot && value)
return { op: "target", action: "set", slot: Number(slot), pane: value };
if (action === "use" && slot)
return { op: "target", action: "use", slot: Number(slot) };
if (action === "release" && slot)
return { op: "target", action: "release", slot: Number(slot) };
if (action === "next" || action === "prev")
return { op: "target", action };
if (action === "next-live") return { op: "target", action: "next-live" };
if (action === "list") return { op: "target", action: "list" };
if (action === "panes") return { op: "target", action: "panes" };
usage();
break;
}
case "set": {
const [key, value] = rest;
if (key === "enter-mode" && value) return { op: "settings", enter_mode: value };
if (key === "strategy" && value) return { op: "settings", strategy: value };
if (key === "language" && value) return { op: "settings", language: value };
usage();
break;
}
case "events":
return { op: "events", last: rest[0] ? Number(rest[0]) : 20 };
case "replay":
if (!rest[0]) usage();
return { op: "replay", trace_id: rest[0] };
default:
usage(cmd === "--help" || cmd === "-h" ? 0 : 1);
}
}
async function main() {
const argv = process.argv.slice(2);
try {
if (argv[0] === "target" && argv[1] === "pick") {
await pickFlow(argv[2]);
return;
}
const req = buildRequest(argv);
const sock = await connectSock();
finish(await sock.request(req));
} catch (err) {
console.error(`dais-ctl: ${err.message} (socket: ${SOCKET} — daemon running?)`);
process.exit(1);
}
}
main();