mirror of
https://github.com/Kynde/dais.git
synced 2026-10-20 08:32:28 +02:00
Runtime-switchable ASR language without reloading the resident model: a
new set_language ndjson message mutates the language the ear passes to
faster-whisper per utterance ("auto"/null = per-utterance autodetect).
One knob, shaped like the existing strategy/enter-mode toggles
(session-only; config wins on restart): language ∈ en | fi | auto.
Commands may carry :lang; untagged commands belong to the base language
(:asr :language). The router filters live commands by the utterance's
own reported language, so it works the same forced or autodetected — a
phrase only matters when the model is transcribing in its language.
normalize is now Unicode-aware so non-ASCII phrases (Finnish ä/ö)
survive instead of being stripped.
Surfaces: dais-ctl set language <code|auto>, dais-top [l] cycle, status
reports language/languages, and a :set-language voice control (:to lang).
Default stays small.en/en — English is unchanged and fast. Switching to
fi/auto needs a MULTILINGUAL model (small/medium); validated on real
Finnish speech (gates pass with wide margin, no retuning needed).
239 lines
8.4 KiB
JavaScript
Executable File
239 lines
8.4 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 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 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 "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 === "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();
|