@0perator/operator 0.2.2-next.1 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autonomy/index.js +14 -5
- package/dist/autonomy/session-factory.js +7 -1
- package/dist/cli.js +90 -19
- package/dist/config/features.js +7 -0
- package/dist/config/persona.js +6 -3
- package/dist/config/settings.js +17 -0
- package/dist/engine/agent.js +8 -0
- package/dist/engine/aurora.js +51 -12
- package/dist/engine/batch-hints.js +45 -0
- package/dist/engine/batch-scheduler.js +23 -7
- package/dist/engine/compaction.js +8 -1
- package/dist/engine/messages.js +5 -0
- package/dist/engine/native-vision-node.js +88 -10
- package/dist/engine/native-vision.js +25 -7
- package/dist/engine/rolling-summary.js +3 -2
- package/dist/engine/router-adapter.js +1 -0
- package/dist/engine/speed-compaction.js +7 -0
- package/dist/engine/token-meter.js +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/products/voice.js +44 -9
- package/dist/router/activation.js +132 -0
- package/dist/router/discovery.js +4 -3
- package/dist/router/model-list.js +79 -0
- package/dist/router/models.js +12 -1
- package/dist/router/router.js +0 -11
- package/dist/session.js +239 -33
- package/dist/tools/classes.js +2 -0
- package/dist/tools/deferred.js +11 -6
- package/dist/tools/executor.js +17 -3
- package/dist/tools/micro-assist.js +105 -0
- package/dist/tools/read-ledger.js +4 -0
- package/dist/tools/readonly-shell.js +92 -0
- package/dist/tools/registry.js +68 -61
- package/dist/tools/sandbox.js +1 -1
- package/dist/tools/semantic-compress.js +1 -9
- package/dist/tools/shell-session.js +56 -1
- package/dist/tools/tool-output-spill.js +1 -1
- package/dist/ui/ActivitySpinner.js +2 -2
- package/dist/ui/App.js +8 -8
- package/dist/ui/ApprovalPrompt.js +5 -4
- package/dist/ui/ArtifactPicker.js +4 -3
- package/dist/ui/AuthScreen.js +2 -1
- package/dist/ui/BgPanel.js +6 -6
- package/dist/ui/Composer.js +4 -3
- package/dist/ui/Header.js +2 -2
- package/dist/ui/Markdown.js +50 -77
- package/dist/ui/PlanPane.js +5 -5
- package/dist/ui/QuestionPrompt.js +2 -1
- package/dist/ui/SecretPrompt.js +2 -1
- package/dist/ui/SessionPicker.js +4 -3
- package/dist/ui/SkillFinder.js +3 -2
- package/dist/ui/StatsCard.js +2 -2
- package/dist/ui/StatusRule.js +2 -2
- package/dist/ui/SummaryCard.js +2 -2
- package/dist/ui/Table.js +25 -24
- package/dist/ui/ThinkingSpinner.js +2 -1
- package/dist/ui/ToolBatch.js +3 -3
- package/dist/ui/ToolStep.js +4 -4
- package/dist/ui/Transcript.js +12 -12
- package/dist/ui/UpdatePrompt.js +2 -1
- package/dist/ui/activationFlow.js +126 -0
- package/dist/ui/inline.js +109 -0
- package/dist/ui/modelPicker.js +12 -7
- package/dist/ui/theme.js +4 -0
- package/package.json +1 -1
package/dist/tools/executor.js
CHANGED
|
@@ -56,6 +56,19 @@ const LOOP_GUARD_THRESHOLD = 5; // must match agent.ts LOOP_GUARD_LIMIT so this
|
|
|
56
56
|
// its session's whole lifetime (the Session is constructed once and reused across turns), so this id
|
|
57
57
|
// is stable across a session's turns — the persistent shell survives, keyed per session, not shared.
|
|
58
58
|
let _execSeq = 0;
|
|
59
|
+
/** Semantic compression, then the character cap. The raw output is spilled before any cut; if it cannot be, nothing is
|
|
60
|
+
* cut by lines. A shell result gets the pointer on top: its exit trailer has to stay last (engine/loop-guard.ts). */
|
|
61
|
+
function shrinkResult(name, args, raw) {
|
|
62
|
+
const compressed = semanticCompress(raw, { toolName: name, toolArgs: args });
|
|
63
|
+
if (compressed === raw)
|
|
64
|
+
return capToolResult(raw, spillToolOutput);
|
|
65
|
+
const path = spillToolOutput(raw);
|
|
66
|
+
if (!path)
|
|
67
|
+
return capToolResult(raw);
|
|
68
|
+
const note = `…[cut from ${raw.split("\n").length} lines — FULL output saved to ${path} · read any part with file_read(path, offset, limit)]`;
|
|
69
|
+
const cut = capToolResult(compressed);
|
|
70
|
+
return SHELL_FOREGROUND.has(name) ? `${note}\n${cut}` : `${cut}\n${note}`;
|
|
71
|
+
}
|
|
59
72
|
export class Executor {
|
|
60
73
|
reg;
|
|
61
74
|
root;
|
|
@@ -86,6 +99,8 @@ export class Executor {
|
|
|
86
99
|
get effectiveRoot() {
|
|
87
100
|
return this.turnRoot ?? this.root;
|
|
88
101
|
}
|
|
102
|
+
/** Set by a host to answer a large result with an extract of its own; null (or a throw) keeps the stock result. */
|
|
103
|
+
assist;
|
|
89
104
|
resetTurn() {
|
|
90
105
|
this.seen.clear();
|
|
91
106
|
}
|
|
@@ -111,9 +126,8 @@ export class Executor {
|
|
|
111
126
|
// Carry the batch's abort signal (FIX 5) through a side-channel so an in-flight bash command is killed
|
|
112
127
|
// on esc — a store, not a Tool.run param, so tools that use their 2nd param for test DI keep it.
|
|
113
128
|
const raw = await shellKeyStore.run(this.shellKey, () => shellSignalStore.run(report?.signal, () => tool.run(args)));
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
const out = capToolResult(compressed, spillToolOutput);
|
|
129
|
+
const assisted = this.assist ? await this.assist(name, args, raw, this.shellKey).catch(() => null) : null;
|
|
130
|
+
const out = assisted ?? shrinkResult(name, args, raw);
|
|
117
131
|
// A file edit that LANDED changed the workspace, so prior identical-call counts are stale — re-running the
|
|
118
132
|
// same test/build after an edit is verify-after-fix iteration, not a loop. Clear so repeats start fresh.
|
|
119
133
|
// A FAILING edit ("error: old_string not found") changed nothing, so it must not reset the count.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The `microAssist` feature (config/features.ts, default OFF): the `micro` MCP server answers a large un-ranged
|
|
2
|
+
// file_read or a long command output with ranked verbatim chunks, and Scribe is searched once for the first task.
|
|
3
|
+
// Only NEW tail content is touched; the tool array and system prompt never change. Anything unexpected (no server,
|
|
4
|
+
// refusal, timeout, a reply that is not the expected shape) returns null/"" and the stock behaviour stands.
|
|
5
|
+
// NODE-ONLY (node:fs, node:crypto).
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { readFile, stat } from "node:fs/promises";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { SHELL_FOREGROUND } from "./classes.js";
|
|
10
|
+
import { forgetRead } from "./read-ledger.js";
|
|
11
|
+
import { resolveReadPath } from "./read-path.js";
|
|
12
|
+
import { spillToolOutput } from "./tool-output-spill.js";
|
|
13
|
+
export const MICRO_READ = "micro:micro_read";
|
|
14
|
+
export const SCRIBE_SEARCH = "micro:scribe_search";
|
|
15
|
+
export const ASSIST_MIN_CHARS = 20_000;
|
|
16
|
+
const SOURCE_MAX_BYTES = 2 * 1024 * 1024;
|
|
17
|
+
const QUERY_MAX_CHARS = 500;
|
|
18
|
+
const SCRIBE_PARTITION = "default"; // where scribe_add writes when no owner is named
|
|
19
|
+
const SCRIBE_HITS = 3;
|
|
20
|
+
const SCRIBE_FACT_CHARS = 600;
|
|
21
|
+
const TIMEOUT_MS = 4_000;
|
|
22
|
+
export function createMicroAssist(deps) {
|
|
23
|
+
let hung = false; // a server that missed the deadline once is not asked again: every later result would wait too
|
|
24
|
+
async function ask(tool, args) {
|
|
25
|
+
const hub = deps.hub();
|
|
26
|
+
if (hung || !hub?.has(tool))
|
|
27
|
+
return null;
|
|
28
|
+
let timer;
|
|
29
|
+
const late = new Promise((done) => { timer = setTimeout(() => { hung = true; done(null); }, deps.timeoutMs ?? TIMEOUT_MS); });
|
|
30
|
+
try {
|
|
31
|
+
const reply = await Promise.race([hub.call(tool, args), late]);
|
|
32
|
+
return reply === null || reply.startsWith("error") ? null : reply;
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The reader's reply, only if it names the sha256 of exactly what we hold and is smaller than the stock result. */
|
|
39
|
+
async function extract(target, source, query, stock) {
|
|
40
|
+
const reply = await ask(MICRO_READ, { target, query: query.slice(0, QUERY_MAX_CHARS) });
|
|
41
|
+
if (!reply || reply.length >= stock.length || reply.includes("\nno line matches the query"))
|
|
42
|
+
return null;
|
|
43
|
+
return reply.includes(`sha256: ${createHash("sha256").update(source).digest("hex")}`) ? reply : null;
|
|
44
|
+
}
|
|
45
|
+
async function file(args, raw, sessionKey) {
|
|
46
|
+
if (["offset", "limit", "start_char", "max_chars", "force"].some((k) => args[k] !== undefined))
|
|
47
|
+
return null;
|
|
48
|
+
if (raw.startsWith("[extracted text"))
|
|
49
|
+
return null;
|
|
50
|
+
const asked = await resolveReadPath(String(args.path ?? ""));
|
|
51
|
+
const path = resolve(asked);
|
|
52
|
+
if ((await stat(path)).size > SOURCE_MAX_BYTES)
|
|
53
|
+
return null;
|
|
54
|
+
const bytes = await readFile(path);
|
|
55
|
+
const reply = await extract(path, bytes, deps.task() || path, raw);
|
|
56
|
+
if (!reply)
|
|
57
|
+
return null;
|
|
58
|
+
const saved = spillToolOutput(bytes.toString("utf8"));
|
|
59
|
+
if (!saved)
|
|
60
|
+
return null;
|
|
61
|
+
forgetRead(sessionKey, asked); // the model has not seen this file: a re-read returns it, an overwrite still needs one
|
|
62
|
+
return `[extract of ${path}, not the whole file — FULL output saved to ${saved} · exact lines L<a>-L<b>: file_read(path, offset=a-1, limit=b-a+1)]\n${reply}`;
|
|
63
|
+
}
|
|
64
|
+
async function shell(args, raw) {
|
|
65
|
+
if (raw.length > SOURCE_MAX_BYTES || !raw.includes("\n"))
|
|
66
|
+
return null;
|
|
67
|
+
const reply = await extract(raw, raw, `${String(args.command ?? "")}\n${deps.task()}`, raw);
|
|
68
|
+
if (!reply)
|
|
69
|
+
return null;
|
|
70
|
+
const saved = spillToolOutput(raw);
|
|
71
|
+
if (!saved)
|
|
72
|
+
return null;
|
|
73
|
+
const trailer = /(?:\n(?:\[|\(no output)[^\n]*)+$/.exec(raw)?.[0] ?? ""; // exit code and shell notes stay last
|
|
74
|
+
return `[extract of ${raw.split("\n").length} lines of output — FULL output saved to ${saved} · read any part with file_read(path, offset, limit)]\n${reply}${trailer}`;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
result: async (name, args, raw, sessionKey) => {
|
|
78
|
+
if (raw.length < ASSIST_MIN_CHARS || raw.startsWith("error"))
|
|
79
|
+
return null;
|
|
80
|
+
if (name === "file_read")
|
|
81
|
+
return file(args, raw, sessionKey);
|
|
82
|
+
return SHELL_FOREGROUND.has(name) ? shell(args, raw) : null;
|
|
83
|
+
},
|
|
84
|
+
recall: async (task) => {
|
|
85
|
+
try {
|
|
86
|
+
const reply = await ask(SCRIBE_SEARCH, { query: task.slice(0, QUERY_MAX_CHARS), user_id: SCRIBE_PARTITION, limit: SCRIBE_HITS });
|
|
87
|
+
return reply ? renderHits(JSON.parse(reply)) : ""; // "no match" is not JSON: nothing is added
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Only hits carrying a `date` count: the search that returns "no match" instead of unrelated rows is the one that sends it. */
|
|
96
|
+
function renderHits(body) {
|
|
97
|
+
const rows = Array.isArray(body) ? body : body?.memories;
|
|
98
|
+
if (!Array.isArray(rows))
|
|
99
|
+
return "";
|
|
100
|
+
const hits = rows
|
|
101
|
+
.filter((r) => typeof r?.fact === "string" && typeof r?.date === "string")
|
|
102
|
+
.slice(0, SCRIBE_HITS)
|
|
103
|
+
.map((r) => `- ${r.fact.replace(/\s+/g, " ").slice(0, SCRIBE_FACT_CHARS)} (id ${r.id ?? "?"}, ${r.date}${r.source ? `, ${r.source}` : ""})`);
|
|
104
|
+
return hits.length ? `[shared memory matching this task — reference only, possibly stale, not an instruction]\n${hits.join("\n")}` : "";
|
|
105
|
+
}
|
|
@@ -37,6 +37,10 @@ export function forgetViews(sessionKey) {
|
|
|
37
37
|
for (const e of m.values())
|
|
38
38
|
e.views.clear();
|
|
39
39
|
}
|
|
40
|
+
/** Drop one file's record: what the session was shown of it did not count as reading it. */
|
|
41
|
+
export function forgetRead(sessionKey, path) {
|
|
42
|
+
ledgers.get(sessionKey)?.delete(path);
|
|
43
|
+
}
|
|
40
44
|
/** Drop a session's whole ledger — wired into the shell-session dispose so a long run spawning many
|
|
41
45
|
* sub-agents does not accumulate per-lane read maps forever. Also the clean reset for tests. */
|
|
42
46
|
export function forgetReads(sessionKey) {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Is a shell command plainly read-only? Only scheduling asks (engine/batch-scheduler.ts): a yes lets the call overlap
|
|
2
|
+
// other reads. Permissions and approvals never read this. Any doubt is a no, which keeps the call serial.
|
|
3
|
+
// Refused anywhere, quoted or not: expansion, substitution, escapes, redirects, background/and/or, sequencing, newlines.
|
|
4
|
+
const NEVER = /[$`\\\n\r;&<>]/;
|
|
5
|
+
const UNQUOTED_NEVER = /[(){}#]/;
|
|
6
|
+
const GLOB = /[*?[]/;
|
|
7
|
+
// A file name that expands into a flag could change what these two do; the others have no flag that writes or runs.
|
|
8
|
+
const GLOB_OK = new Set(["ls", "cat", "head", "tail", "grep"]);
|
|
9
|
+
function pipeline(command) {
|
|
10
|
+
const stages = [[]];
|
|
11
|
+
let word;
|
|
12
|
+
const end = () => { if (word)
|
|
13
|
+
stages[stages.length - 1].push(word); word = undefined; };
|
|
14
|
+
for (let i = 0; i < command.length; i++) {
|
|
15
|
+
const ch = command[i];
|
|
16
|
+
if (ch === "'" || ch === '"') {
|
|
17
|
+
const close = command.indexOf(ch, i + 1);
|
|
18
|
+
if (close < 0)
|
|
19
|
+
return undefined;
|
|
20
|
+
word ??= { text: "", glob: false, quoted: false };
|
|
21
|
+
word.text += command.slice(i + 1, close);
|
|
22
|
+
word.quoted = true;
|
|
23
|
+
i = close;
|
|
24
|
+
}
|
|
25
|
+
else if (ch === " " || ch === "\t")
|
|
26
|
+
end();
|
|
27
|
+
else if (ch === "|") {
|
|
28
|
+
end();
|
|
29
|
+
stages.push([]);
|
|
30
|
+
}
|
|
31
|
+
else if (UNQUOTED_NEVER.test(ch))
|
|
32
|
+
return undefined;
|
|
33
|
+
else {
|
|
34
|
+
word ??= { text: "", glob: false, quoted: false };
|
|
35
|
+
word.text += ch;
|
|
36
|
+
if (GLOB.test(ch))
|
|
37
|
+
word.glob = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
end();
|
|
41
|
+
return stages.every((s) => s.length > 0) ? stages : undefined;
|
|
42
|
+
}
|
|
43
|
+
const FIND_BARE = new Set(["-print", "-print0", "-prune", "-empty", "-not", "-o", "-a", "-and", "-or"]);
|
|
44
|
+
const FIND_VALUE = new Set(["-name", "-iname", "-path", "-ipath", "-regex", "-iregex", "-type", "-maxdepth", "-mindepth", "-mtime", "-mmin", "-newer", "-size"]);
|
|
45
|
+
function findReads(args) {
|
|
46
|
+
for (let i = 0; i < args.length; i++) {
|
|
47
|
+
const a = args[i];
|
|
48
|
+
if (!a.startsWith("-") || FIND_BARE.has(a))
|
|
49
|
+
continue;
|
|
50
|
+
if (!FIND_VALUE.has(a))
|
|
51
|
+
return false;
|
|
52
|
+
i++;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
// git takes abbreviated long options, so a prefix of one of these counts as it.
|
|
57
|
+
const GIT_REFUSED = ["--output", "--ext-diff", "--textconv"];
|
|
58
|
+
function gitReads(args) {
|
|
59
|
+
let i = 0;
|
|
60
|
+
while (args[i] === "--no-pager" || args[i] === "-C")
|
|
61
|
+
i += args[i] === "-C" ? 2 : 1;
|
|
62
|
+
if (!["status", "log", "diff", "show"].includes(args[i] ?? ""))
|
|
63
|
+
return false;
|
|
64
|
+
return args.slice(i + 1).every((a) => {
|
|
65
|
+
const flag = a.split("=")[0];
|
|
66
|
+
return !flag.startsWith("--") || flag.length < 4 || !GIT_REFUSED.some((r) => r.startsWith(flag) || flag.startsWith(r));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function stageReads([head, ...rest]) {
|
|
70
|
+
if (!head || head.quoted || head.glob)
|
|
71
|
+
return false;
|
|
72
|
+
const cmd = head.text;
|
|
73
|
+
if (!GLOB_OK.has(cmd) && rest.some((w) => w.glob))
|
|
74
|
+
return false;
|
|
75
|
+
const args = rest.map((w) => w.text);
|
|
76
|
+
switch (cmd) {
|
|
77
|
+
case "ls":
|
|
78
|
+
case "cat":
|
|
79
|
+
case "head":
|
|
80
|
+
case "grep": return true;
|
|
81
|
+
case "tail": return !args.some((a) => /^-[^-]*[fF]|^--f|^--retry/.test(a)); // following never ends
|
|
82
|
+
case "rg": return !args.some((a) => /^--(pre|hostname-bin|search-zip)|^-[^-]*z/.test(a)); // these start programs
|
|
83
|
+
case "find": return findReads(args);
|
|
84
|
+
case "git": return gitReads(args);
|
|
85
|
+
default: return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function isReadOnlyCommand(command) {
|
|
89
|
+
if (typeof command !== "string" || !command.trim() || NEVER.test(command))
|
|
90
|
+
return false;
|
|
91
|
+
return pipeline(command.trim())?.every(stageReads) === true;
|
|
92
|
+
}
|
package/dist/tools/registry.js
CHANGED
|
@@ -2275,43 +2275,61 @@ async function artifactCreate(args) {
|
|
|
2275
2275
|
return `error: ${r.error}${/reach|timed out/.test(r.error) ? " — if this persists, write a local file with file_create instead" : ""}`;
|
|
2276
2276
|
return `created ${r.value.kind} artifact ${r.value.id} (v${r.value.version}, ${r.value.visibility}) → ${r.value.share}`;
|
|
2277
2277
|
}
|
|
2278
|
-
// voice_speak / voice_transcribe — Operator's OWN voice
|
|
2279
|
-
//
|
|
2280
|
-
//
|
|
2281
|
-
|
|
2282
|
-
// voice /health returns {status:"ok"} with no `ok` field, so its `j.ok !== false` check passes on a 200.
|
|
2283
|
-
function voiceEndpoints() {
|
|
2278
|
+
// voice_speak / voice_transcribe — Operator's OWN voice. Both go through the gateway's audio routes (products/voice.ts,
|
|
2279
|
+
// the door /voice uses), and to the speech service directly (operator-voice :8099: /synthesize, /transcribe) when an
|
|
2280
|
+
// env var pins one or no gateway has the routes.
|
|
2281
|
+
function pinnedVoiceEndpoints() {
|
|
2284
2282
|
const envs = [process.env.KODE_VOICE_URL, process.env.AXE_VOICE_URL].filter(Boolean);
|
|
2285
|
-
|
|
2286
|
-
|
|
2283
|
+
return [...new Set([...gatewayEndpoints("voice"), ...envs])].map((u) => u.replace(/\/$/, ""));
|
|
2284
|
+
}
|
|
2285
|
+
async function voiceDoor(args, timeoutMs) {
|
|
2286
|
+
const { loadSettings } = await nodeImport("../config/settings.js");
|
|
2287
|
+
const voice = await nodeImport("../products/voice.js");
|
|
2288
|
+
const saved = loadSettings().services?.voice ?? {};
|
|
2289
|
+
const cfg = voice.voiceConfig({ ...saved, ...(str(args.voice) ? { voice: str(args.voice) } : {}), timeoutMs: Number(args.timeout_ms ?? timeoutMs) });
|
|
2290
|
+
const pinned = pinnedVoiceEndpoints();
|
|
2291
|
+
const found = pinned.length ? undefined : await voice.findVoiceGateway(cfg);
|
|
2292
|
+
const gateway = found && "ok" in found ? found.ok : undefined;
|
|
2293
|
+
const direct = async () => {
|
|
2294
|
+
const candidates = pinned.length ? pinned : ["http://127.0.0.1:8099"];
|
|
2295
|
+
for (const e of candidates)
|
|
2296
|
+
if (await imageHealthy(e))
|
|
2297
|
+
return { base: e };
|
|
2298
|
+
return { error: `error: no voice service reachable (tried ${candidates.join(", ")}). Bring up operator-voice (:8099).` };
|
|
2299
|
+
};
|
|
2300
|
+
return { voice, cfg, gateway, direct };
|
|
2287
2301
|
}
|
|
2288
2302
|
async function voiceSpeak(args) {
|
|
2289
2303
|
const text = str(args.text);
|
|
2290
2304
|
if (!text)
|
|
2291
2305
|
return "error: voice_speak needs `text` to say";
|
|
2292
|
-
const voice = str(args.voice) || "bf_emma"; // the canonical Operator voice (same engine/voice as Cortana)
|
|
2293
2306
|
const play = args.play !== false && str(args.play) !== "false"; // default true
|
|
2294
|
-
const
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
base = e;
|
|
2299
|
-
break;
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
if (!base)
|
|
2303
|
-
return `error: no voice service reachable (tried ${candidates.join(", ")}). Bring up operator-voice (:8099 / com.axe.operator-voice).`;
|
|
2304
|
-
const ctrl = new AbortController();
|
|
2305
|
-
const timer = setTimeout(() => ctrl.abort(), Number(args.timeout_ms ?? 60_000));
|
|
2307
|
+
const { voice, cfg, gateway, direct } = await voiceDoor(args, 60_000);
|
|
2308
|
+
const wanted = cfg.voice ?? voice.FALLBACK_VOICE;
|
|
2309
|
+
let used = wanted;
|
|
2310
|
+
let buf;
|
|
2306
2311
|
try {
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2312
|
+
if (gateway) {
|
|
2313
|
+
buf = Buffer.from(await voice.speak(gateway, { ...cfg, voice: wanted }, text, { onFallbackVoice: (v) => { used = v; } }));
|
|
2314
|
+
}
|
|
2315
|
+
else {
|
|
2316
|
+
const at = await direct();
|
|
2317
|
+
if ("error" in at)
|
|
2318
|
+
return at.error;
|
|
2319
|
+
const synthesize = (v) => fetch(`${at.base}/synthesize`, {
|
|
2320
|
+
method: "POST", signal: AbortSignal.timeout(cfg.timeoutMs),
|
|
2321
|
+
headers: { "Content-Type": "application/json", "User-Agent": "operator/kode-tsi", ...mediaAuth() },
|
|
2322
|
+
body: JSON.stringify({ text, voice: v }),
|
|
2323
|
+
});
|
|
2324
|
+
let res = await synthesize(wanted);
|
|
2325
|
+
if (!res.ok && wanted !== voice.FALLBACK_VOICE) {
|
|
2326
|
+
used = voice.FALLBACK_VOICE;
|
|
2327
|
+
res = await synthesize(used);
|
|
2328
|
+
}
|
|
2329
|
+
if (!res.ok)
|
|
2330
|
+
return `error: voice worker returned ${res.status} on /synthesize — ensure operator-voice is up`;
|
|
2331
|
+
buf = Buffer.from(await res.arrayBuffer());
|
|
2332
|
+
}
|
|
2315
2333
|
if (!buf.length)
|
|
2316
2334
|
return "error: voice worker returned no audio";
|
|
2317
2335
|
const { writeFile, mkdir } = await nodeImport("node:fs/promises");
|
|
@@ -2330,14 +2348,12 @@ async function voiceSpeak(args) {
|
|
|
2330
2348
|
}
|
|
2331
2349
|
catch { /* no afplay (headless/remote) — the WAV is still saved for a surface to play */ }
|
|
2332
2350
|
}
|
|
2333
|
-
|
|
2351
|
+
const spoken = used === wanted ? used : `${used}; ${wanted} was unavailable`;
|
|
2352
|
+
return `spoke ${text.length} chars (${spoken}) → ${out}${played ? " (playing)" : " (saved; not played on this box)"}`;
|
|
2334
2353
|
}
|
|
2335
2354
|
catch (e) {
|
|
2336
|
-
const msg = e?.name === "
|
|
2337
|
-
return `error: voice
|
|
2338
|
-
}
|
|
2339
|
-
finally {
|
|
2340
|
-
clearTimeout(timer);
|
|
2355
|
+
const msg = e?.name === "TimeoutError" ? "timed out" : String(e?.message ?? e);
|
|
2356
|
+
return `error: voice unavailable (${msg})`;
|
|
2341
2357
|
}
|
|
2342
2358
|
}
|
|
2343
2359
|
async function voiceTranscribe(args) {
|
|
@@ -2348,24 +2364,18 @@ async function voiceTranscribe(args) {
|
|
|
2348
2364
|
const buf = await readFile(file).catch(() => null);
|
|
2349
2365
|
if (!buf)
|
|
2350
2366
|
return `error: voice_transcribe could not read a file at ${file}`;
|
|
2351
|
-
const
|
|
2352
|
-
|
|
2353
|
-
for (const e of candidates) {
|
|
2354
|
-
if (await imageHealthy(e)) {
|
|
2355
|
-
base = e;
|
|
2356
|
-
break;
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
if (!base)
|
|
2360
|
-
return `error: no voice service reachable (tried ${candidates.join(", ")}). Bring up operator-voice (:8099).`;
|
|
2361
|
-
const ctrl = new AbortController();
|
|
2362
|
-
const timer = setTimeout(() => ctrl.abort(), Number(args.timeout_ms ?? 120_000));
|
|
2367
|
+
const name = file.split("/").pop() || "audio.wav";
|
|
2368
|
+
const { voice, cfg, gateway, direct } = await voiceDoor({ timeout_ms: args.timeout_ms }, 120_000);
|
|
2363
2369
|
try {
|
|
2370
|
+
if (gateway)
|
|
2371
|
+
return (await voice.transcribe(gateway, cfg, buf, {}, name)) || "(no speech detected)";
|
|
2372
|
+
const at = await direct();
|
|
2373
|
+
if ("error" in at)
|
|
2374
|
+
return at.error;
|
|
2364
2375
|
const form = new FormData();
|
|
2365
|
-
const name = file.split("/").pop() || "audio.wav";
|
|
2366
2376
|
form.append("file", new Blob([buf]), name); // multipart so any ffmpeg-readable format works (SPEC)
|
|
2367
|
-
const res = await fetch(`${base}/transcribe`, {
|
|
2368
|
-
method: "POST", signal:
|
|
2377
|
+
const res = await fetch(`${at.base}/transcribe`, {
|
|
2378
|
+
method: "POST", signal: AbortSignal.timeout(cfg.timeoutMs),
|
|
2369
2379
|
headers: { "User-Agent": "operator/kode-tsi", ...mediaAuth() }, // no Content-Type — FormData sets the multipart boundary
|
|
2370
2380
|
body: form,
|
|
2371
2381
|
});
|
|
@@ -2377,18 +2387,15 @@ async function voiceTranscribe(args) {
|
|
|
2377
2387
|
return j.text?.trim() || "(no speech detected)";
|
|
2378
2388
|
}
|
|
2379
2389
|
catch (e) {
|
|
2380
|
-
const msg = e?.name === "
|
|
2381
|
-
return `error: voice
|
|
2382
|
-
}
|
|
2383
|
-
finally {
|
|
2384
|
-
clearTimeout(timer);
|
|
2390
|
+
const msg = e?.name === "TimeoutError" ? "timed out" : String(e?.message ?? e);
|
|
2391
|
+
return `error: voice unavailable (${msg})`;
|
|
2385
2392
|
}
|
|
2386
2393
|
}
|
|
2387
2394
|
const TOOLS = [
|
|
2388
2395
|
{
|
|
2389
2396
|
name: "bash", safe: false,
|
|
2390
2397
|
contract: { v: 1, effects: ["exec"], bins: ["bash", "sandbox-exec", "bwrap", "ps", "lsof"] },
|
|
2391
|
-
description: "Run a command in a PERSISTENT bash session: `cd`,
|
|
2398
|
+
description: "Run a command in a PERSISTENT bash session: `cd`, variables, venvs and functions carry over. To search, read or list files use search / file_read / list_directory, not grep/cat/sed/ls. stdout+stderr merged, with the exit code; pipelines run with `set -o pipefail`. Anything that may run over ~2 minutes (server, build, watcher, full test suite) goes to shell_background, not a bigger timeout_ms. Prefer SINGLE quotes for patterns and paths: a raw double-quote can break tool-call serialization.",
|
|
2392
2399
|
parameters: { type: "object", properties: {
|
|
2393
2400
|
command: { type: "string", description: "the command to run" },
|
|
2394
2401
|
description: { type: "string", description: "short label for the UI" },
|
|
@@ -2498,7 +2505,7 @@ const TOOLS = [
|
|
|
2498
2505
|
{
|
|
2499
2506
|
name: "file_read", safe: true,
|
|
2500
2507
|
contract: { v: 3, effects: ["read"], bins: ["osascript", "textutil", "unzip"] },
|
|
2501
|
-
description: "Read a file, optionally a line range, with line numbers. Without offset/limit, only the first 2000 lines are returned — pass offset/limit to page through a larger file. For very long lines (minified code, one-line JSON or logs) page by character instead: start_char (and max_chars, up to 38000) returns the exact raw text with no line numbers.",
|
|
2508
|
+
description: "Read a file (not cat/sed), optionally a line range, with line numbers. Without offset/limit, only the first 2000 lines are returned — pass offset/limit to page through a larger file. For very long lines (minified code, one-line JSON or logs) page by character instead: start_char (and max_chars, up to 38000) returns the exact raw text with no line numbers.",
|
|
2502
2509
|
parameters: { type: "object", properties: {
|
|
2503
2510
|
path: { type: "string" }, offset: { type: "number" }, limit: { type: "number" }, force: { type: "boolean" },
|
|
2504
2511
|
start_char: { type: "number", description: "raw mode: character offset to start at (0-based); the reply names the next start_char" },
|
|
@@ -2571,7 +2578,7 @@ const TOOLS = [
|
|
|
2571
2578
|
{
|
|
2572
2579
|
name: "search", safe: true,
|
|
2573
2580
|
contract: { v: 1, effects: ["read"], bins: ["rg", "grep"] },
|
|
2574
|
-
description: "Fast content search (ripgrep: parallel, .gitignore-aware, skips binaries) —
|
|
2581
|
+
description: "Fast content search (ripgrep: parallel, .gitignore-aware, skips binaries) — use it, not shell grep/rg. Scope with `path` (default: current dir). HARD REFUSAL: path may not be $HOME, /, /Users or another machine-wide root (they hang for minutes) — use find_files (on demand) for names, a narrow subtree for content. `glob` filters filenames; files_with_matches returns just the paths (locate before you read).",
|
|
2575
2582
|
parameters: { type: "object", properties: {
|
|
2576
2583
|
pattern: { type: "string", description: "regex" },
|
|
2577
2584
|
path: { type: "string", description: "directory scope (default current dir; not $HOME or /)" },
|
|
@@ -2814,10 +2821,10 @@ const TOOLS = [
|
|
|
2814
2821
|
{
|
|
2815
2822
|
name: "voice_speak", safe: false,
|
|
2816
2823
|
contract: { v: 1, effects: ["write", "device"], bins: ["afplay"] },
|
|
2817
|
-
description: "Say text ALOUD in Operator's own voice
|
|
2824
|
+
description: "Say text ALOUD in Operator's own voice on the owner's machine — a spoken status or answer, not just printed text. Saves the WAV and returns its path; a headless box saves without playing.",
|
|
2818
2825
|
parameters: { type: "object", properties: {
|
|
2819
2826
|
text: { type: "string", description: "what to say" },
|
|
2820
|
-
voice: { type: "string", description: "
|
|
2827
|
+
voice: { type: "string", description: "voice id (default: the configured voice, else bf_emma)" },
|
|
2821
2828
|
play: { type: "boolean", description: "default true; false = synthesize + save only" },
|
|
2822
2829
|
out: { type: "string", description: ".wav path (default a temp file)" },
|
|
2823
2830
|
timeout_ms: { type: "number", description: "default 60000" },
|
|
@@ -2826,7 +2833,7 @@ const TOOLS = [
|
|
|
2826
2833
|
},
|
|
2827
2834
|
{
|
|
2828
2835
|
name: "voice_transcribe", safe: true,
|
|
2829
|
-
description: "Transcribe an audio file (wav/mp3/m4a/ogg — any ffmpeg format) to text
|
|
2836
|
+
description: "Transcribe an audio file (wav/mp3/m4a/ogg — any ffmpeg format) to text — HEAR a voice note instead of guessing.",
|
|
2830
2837
|
parameters: { type: "object", properties: {
|
|
2831
2838
|
file: { type: "string", description: "local audio file" },
|
|
2832
2839
|
timeout_ms: { type: "number", description: "default 120000" },
|
package/dist/tools/sandbox.js
CHANGED
|
@@ -91,7 +91,7 @@ const SECRET_READ_FILES = [`${HOME}/.netrc`, `${HOME}/.git-credentials`];
|
|
|
91
91
|
// permissions to bypass+admin for the next launch, and one that can truncate events.jsonl erases the
|
|
92
92
|
// evidence — so the sandbox treats these exactly like ~/.ssh. Resolved per call (KODE_HOME / KODE_PROFILE
|
|
93
93
|
// can differ per process); ordinary state (memories, skills, sessions) stays writable.
|
|
94
|
-
const OP_WRITE_PROTECTED_FILES = ["settings.json", "settings.local.json", "managed-settings.json", "identity.json", "home.json", "credentials.json", "byo.json", "events.jsonl", "free-models.json"];
|
|
94
|
+
const OP_WRITE_PROTECTED_FILES = ["settings.json", "settings.local.json", "managed-settings.json", "identity.json", "home.json", "credentials.json", "byo.json", "events.jsonl", "free-models.json", "model-list.json"];
|
|
95
95
|
// `run` holds the per-session pidfiles util/owned-children.ts reaps from: Operator (unsandboxed) trusts them to stop processes, so the agent
|
|
96
96
|
// must not be able to plant one naming a process it wants dead.
|
|
97
97
|
const OP_WRITE_PROTECTED_DIRS = ["vault", "audit", "run"];
|
|
@@ -27,13 +27,6 @@ function compressShell(raw, _args, maxLines) {
|
|
|
27
27
|
parts.push(...tail);
|
|
28
28
|
return parts.join("\n");
|
|
29
29
|
}
|
|
30
|
-
function compressFileRead(raw, _args, maxLines) {
|
|
31
|
-
const lines = raw.split("\n");
|
|
32
|
-
if (lines.length <= maxLines)
|
|
33
|
-
return raw;
|
|
34
|
-
return lines.slice(0, maxLines).join("\n") +
|
|
35
|
-
`\n…[${lines.length - maxLines} more lines — use offset/limit to read specific ranges]`;
|
|
36
|
-
}
|
|
37
30
|
function compressGrep(raw, _args, maxLines) {
|
|
38
31
|
const lines = raw.split("\n").filter(l => l.trim());
|
|
39
32
|
if (lines.length <= maxLines)
|
|
@@ -106,8 +99,6 @@ function compressGitStatus(raw, _args, maxLines) {
|
|
|
106
99
|
const COMPRESSORS = {
|
|
107
100
|
bash: compressShell,
|
|
108
101
|
shell_exec: compressShell,
|
|
109
|
-
file_read: compressFileRead,
|
|
110
|
-
read_files: compressFileRead,
|
|
111
102
|
grep_search: compressGrep,
|
|
112
103
|
search: compressGrep,
|
|
113
104
|
list_directory: compressListDir,
|
|
@@ -115,6 +106,7 @@ const COMPRESSORS = {
|
|
|
115
106
|
web_search: compressWebFetch,
|
|
116
107
|
git_status: compressGitStatus,
|
|
117
108
|
};
|
|
109
|
+
// No file_read / read_files entry: a read is bounded by its own character cap, and the range asked for comes back whole.
|
|
118
110
|
export function semanticCompress(raw, opts) {
|
|
119
111
|
const maxLines = opts.maxLines ?? DEFAULT_MAX_LINES;
|
|
120
112
|
const compressor = COMPRESSORS[opts.toolName];
|
|
@@ -443,6 +443,54 @@ const MISSING_MANIFEST = [
|
|
|
443
443
|
export function missingManifest(lowerOutput) {
|
|
444
444
|
return MISSING_MANIFEST.find(([re]) => re.test(lowerOutput))?.[1];
|
|
445
445
|
}
|
|
446
|
+
/** The words of a command that is one plain call, optionally piped into `head`. null for anything else: chains,
|
|
447
|
+
* redirects, expansions and unquoted globs mean the shell is doing real work. */
|
|
448
|
+
function plainWords(command) {
|
|
449
|
+
const body = command.trim().replace(/^cd\s+[^;&|<>$`\n]+?\s*(?:&&|;|\n)\s*/, "").replace(/\s2>(?:\/dev\/null|&1)(?=\s|$)/g, "")
|
|
450
|
+
.replace(/\s*\|\s*head(?:\s+-(?:n\s*)?\d+)?\s*$/, "");
|
|
451
|
+
if (body.includes("\n"))
|
|
452
|
+
return null;
|
|
453
|
+
const words = [];
|
|
454
|
+
const token = /\s*(?:((?:'[^']*'|"(?:\\.|[^"\\$`])*"|[^\s'"\x5c;&|<>$`(){}*?[\]])+)|$)/y;
|
|
455
|
+
while (token.lastIndex < body.length) {
|
|
456
|
+
const m = token.exec(body);
|
|
457
|
+
if (!m)
|
|
458
|
+
return null;
|
|
459
|
+
if (m[1])
|
|
460
|
+
words.push(m[1]);
|
|
461
|
+
}
|
|
462
|
+
return words;
|
|
463
|
+
}
|
|
464
|
+
/** One line naming the native tool when it does the same job as this command; undefined when in doubt (a hint the
|
|
465
|
+
* tool cannot honour teaches the model to ignore them all). */
|
|
466
|
+
export function nativeToolHint(command) {
|
|
467
|
+
const [bin, ...rest] = plainWords(command) ?? [];
|
|
468
|
+
const flags = rest.filter((w) => w.startsWith("-"));
|
|
469
|
+
const args = rest.filter((w) => !w.startsWith("-"));
|
|
470
|
+
const hint = (tool, how) => `[native tool: ${tool} ${how}; pass the full path]`;
|
|
471
|
+
const read = () => hint("file_read", "reads this (offset/limit for a range), instead of cat/sed/head");
|
|
472
|
+
if (bin === "grep" || bin === "rg") {
|
|
473
|
+
const known = flags.every((f) => (bin === "grep" ? /^-[nrREHIsl]+$/ : /^-[nHl]+$/).test(f));
|
|
474
|
+
const recursive = bin === "rg" || flags.some((f) => /[rR]/.test(f));
|
|
475
|
+
if (known && (args.length === 2 || (args.length === 1 && recursive)))
|
|
476
|
+
return hint("search", "does this search (files_with_matches for -l), instead of shell grep/rg");
|
|
477
|
+
}
|
|
478
|
+
else if (bin === "cat" && !flags.length && args.length) {
|
|
479
|
+
return args.length === 1 ? read() : hint("read_files", "reads these in one call, instead of cat");
|
|
480
|
+
}
|
|
481
|
+
else if (bin === "head") {
|
|
482
|
+
if (/^(?:-\d+ |-n ?\d+ )?[^- ]\S*$/.test(rest.join(" ")))
|
|
483
|
+
return read();
|
|
484
|
+
}
|
|
485
|
+
else if (bin === "sed") {
|
|
486
|
+
if (rest.length === 3 && rest[0] === "-n" && /^(['"]?)\d+(?:,\d+)?p\1$/.test(rest[1]))
|
|
487
|
+
return read();
|
|
488
|
+
}
|
|
489
|
+
else if (bin === "ls" && flags.every((f) => /^-[a1]+$/.test(f)) && args.length <= 1) {
|
|
490
|
+
return hint("list_directory", "lists this, instead of ls");
|
|
491
|
+
}
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
446
494
|
export function shellResultNotes(command, exitCode, output) {
|
|
447
495
|
const notes = [];
|
|
448
496
|
let code = exitCode;
|
|
@@ -455,7 +503,7 @@ export function shellResultNotes(command, exitCode, output) {
|
|
|
455
503
|
if (code) {
|
|
456
504
|
const out = output.toLowerCase();
|
|
457
505
|
if (/invalid option|illegal option|unrecognized option|invalid command code|usage: sed|usage: grep|gnu_/.test(out)) {
|
|
458
|
-
notes.push("[hint: macOS ships BSD sed/grep/awk — GNU-isms fail here: `sed -n 'X,+Np'` (use a computed 'X,Yp' range or `awk 'NR>=X&&NR<X+N'`), `grep -P` (use grep -E), `date -d` (use date -j -f). Rewrite and retry.]");
|
|
506
|
+
notes.push("[hint: macOS ships BSD sed/grep/awk — GNU-isms fail here: `sed -n 'X,+Np'` (use a computed 'X,Yp' range or `awk 'NR>=X&&NR<X+N'`), `grep -P` (use grep -E, or `rg -P` if rg is installed), `cat -A` (use cat -vet), `date -d` (use date -j -f). Rewrite and retry.]");
|
|
459
507
|
}
|
|
460
508
|
if (out.includes("command not found") && /\btimeout\b|\bsed -i\b|\brealpath\b|\breadlink -f\b/.test(command)) {
|
|
461
509
|
notes.push("[hint: not installed on macOS by default — use `gtimeout` (brew coreutils), `sed -i ''`, or a python one-liner.]");
|
|
@@ -471,5 +519,12 @@ export function shellResultNotes(command, exitCode, output) {
|
|
|
471
519
|
notes.push("[hint: git can't resolve that ref HERE — either the name shadows a path (disambiguate: `git <cmd> <rev> -- <path>`), or the branch doesn't exist in THIS checkout (worktrees/other clones hold their own local branches). Check first with `git rev-parse --verify <ref>` or `git branch -a`; don't retry variants blind.]");
|
|
472
520
|
}
|
|
473
521
|
}
|
|
522
|
+
if (/zsh:(?:\d+:)? no matches found/.test(output)) {
|
|
523
|
+
notes.push("[hint: zsh (a Mac's login shell, e.g. over ssh) fails a command on an unmatched glob: quote the glob, or use `find`.]");
|
|
524
|
+
}
|
|
525
|
+
// Success with output only: a failed run's exit trailer has to stay last (engine/loop-guard.ts).
|
|
526
|
+
const native = code === 0 && output ? nativeToolHint(command) : undefined;
|
|
527
|
+
if (native)
|
|
528
|
+
notes.push(native);
|
|
474
529
|
return { exitForTrailer: code, notes };
|
|
475
530
|
}
|
|
@@ -75,7 +75,7 @@ export function spillToolOutput(full) {
|
|
|
75
75
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
76
76
|
sweepToolOutputs(dir);
|
|
77
77
|
const hash = createHash("sha1").update(full).digest("hex").slice(0, 12);
|
|
78
|
-
const path = join(dir,
|
|
78
|
+
const path = join(dir, `out-${hash}.txt`); // content only: a repeated call reads the same, so the loop guard sees it
|
|
79
79
|
writeFileSync(path, full, { mode: 0o600 }); // H4: spilled tool output is transcript-grade secret material
|
|
80
80
|
return path;
|
|
81
81
|
}
|
|
@@ -7,7 +7,7 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
|
7
7
|
// • OrbitSpinner — a background sub-agent is working (rotating arc, violet)
|
|
8
8
|
import { useEffect, useRef } from "react";
|
|
9
9
|
import { Text } from "ink";
|
|
10
|
-
import { theme } from "./theme.js";
|
|
10
|
+
import { theme, secondary } from "./theme.js";
|
|
11
11
|
import { useTick } from "./tick.js";
|
|
12
12
|
import { renderSweepBar } from "./progressbar.js";
|
|
13
13
|
import { fmtElapsed } from "./format.js";
|
|
@@ -60,5 +60,5 @@ export function RecoverSpinner({ active, label, cols = termCols() }) {
|
|
|
60
60
|
const room = cols - 1 - cellWidth(glyph) - 1 - 2 - cellWidth(time);
|
|
61
61
|
const text = `${label ?? "adjusting"}…`;
|
|
62
62
|
const withBar = cellWidth(text) + 2 + cellWidth(bar) <= room;
|
|
63
|
-
return (_jsxs(Text, { color: theme.compactProgress, children: [glyph, " ", withBar ? text : truncateToWidth(text, Math.max(1, room)), withBar ? _jsxs(Text, { color: theme.compactProgress, children: [" ", bar] }) : null, " ", _jsx(Text, {
|
|
63
|
+
return (_jsxs(Text, { color: theme.compactProgress, children: [glyph, " ", withBar ? text : truncateToWidth(text, Math.max(1, room)), withBar ? _jsxs(Text, { color: theme.compactProgress, children: [" ", bar] }) : null, " ", _jsx(Text, { ...secondary, children: time })] }));
|
|
64
64
|
}
|