@0perator/operator 0.1.285 → 0.1.321

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.
Files changed (118) hide show
  1. package/README.md +24 -2
  2. package/dist/acp/agent.js +2 -1
  3. package/dist/acp/config-options.js +3 -1
  4. package/dist/acp/tool-map.js +2 -1
  5. package/dist/auth/commands.js +69 -13
  6. package/dist/autonomy/agent-cli.js +308 -0
  7. package/dist/autonomy/cloud-agent.js +439 -0
  8. package/dist/autonomy/cron-lifecycle.js +78 -0
  9. package/dist/autonomy/cron-lock.js +121 -0
  10. package/dist/autonomy/cron.js +217 -44
  11. package/dist/autonomy/delegate.js +34 -5
  12. package/dist/autonomy/incidents.js +135 -0
  13. package/dist/autonomy/index.js +22 -0
  14. package/dist/autonomy/profile.js +1 -1
  15. package/dist/autonomy/session-factory.js +25 -16
  16. package/dist/background/index.js +40 -0
  17. package/dist/browser/cdp.js +1 -1
  18. package/dist/bus/inbox.js +20 -0
  19. package/dist/classifier/config.js +47 -0
  20. package/dist/classifier/modes.js +41 -0
  21. package/dist/classifier/types.js +1 -0
  22. package/dist/cli.js +645 -93
  23. package/dist/config/features.js +69 -0
  24. package/dist/config/persona.js +143 -107
  25. package/dist/config/scaffold.js +15 -0
  26. package/dist/config/settings.js +107 -12
  27. package/dist/consolidation/sleep.js +73 -11
  28. package/dist/engine/agent.js +279 -20
  29. package/dist/engine/anthropic-chat.js +343 -0
  30. package/dist/engine/aurora.js +109 -16
  31. package/dist/engine/batch-scheduler.js +41 -9
  32. package/dist/engine/classifier.js +85 -0
  33. package/dist/engine/compaction.js +25 -6
  34. package/dist/engine/fast-start.js +25 -0
  35. package/dist/engine/loop-guard.js +448 -0
  36. package/dist/engine/net-error.js +24 -0
  37. package/dist/engine/repetition-guard.js +180 -0
  38. package/dist/engine/router-adapter.js +1 -0
  39. package/dist/engine/selfheal.js +8 -0
  40. package/dist/engine/toolcalls.js +51 -1
  41. package/dist/engine/verify-gate.js +2 -0
  42. package/dist/flywheel/processor.js +78 -31
  43. package/dist/flywheel/srft.js +13 -0
  44. package/dist/hooks/index.js +196 -0
  45. package/dist/idle/activity.js +20 -0
  46. package/dist/idle/index.js +5 -0
  47. package/dist/idle/monitor.js +71 -0
  48. package/dist/idle/policy.js +66 -0
  49. package/dist/idle/proc.js +22 -0
  50. package/dist/idle/reaper.js +69 -0
  51. package/dist/idle/session-record.js +59 -0
  52. package/dist/index.js +1 -1
  53. package/dist/mcp/config.js +93 -15
  54. package/dist/mcp/index.js +9 -2
  55. package/dist/memory/index.js +0 -0
  56. package/dist/memory/providers.js +210 -0
  57. package/dist/memory/session-catalog.js +422 -0
  58. package/dist/memory/session-providers.js +121 -0
  59. package/dist/memory/session-sources.js +335 -0
  60. package/dist/memory/skylark.js +131 -0
  61. package/dist/models/bench.js +103 -0
  62. package/dist/models/registry.js +144 -0
  63. package/dist/models/switch.js +69 -0
  64. package/dist/observability/blackbox.js +37 -0
  65. package/dist/permissions/index.js +22 -7
  66. package/dist/permissions/policy.js +31 -6
  67. package/dist/permissions/tier.js +1 -1
  68. package/dist/remote/host.js +20 -2
  69. package/dist/remote/safe-commands.js +38 -0
  70. package/dist/router/discovery.js +127 -0
  71. package/dist/router/models.js +107 -16
  72. package/dist/router/portal.js +100 -0
  73. package/dist/router/router.js +1 -1
  74. package/dist/services/preflight.js +108 -8
  75. package/dist/services/store-sync.js +111 -0
  76. package/dist/session-teardown.js +10 -1
  77. package/dist/session.js +338 -46
  78. package/dist/skills/catalogue.js +1 -1
  79. package/dist/tools/chauffeur-native.js +155 -0
  80. package/dist/tools/chauffeur.js +26 -3
  81. package/dist/tools/download.js +229 -0
  82. package/dist/tools/executor.js +19 -9
  83. package/dist/tools/find-files.js +483 -0
  84. package/dist/tools/git-pr.js +94 -0
  85. package/dist/tools/incident-tools.js +82 -0
  86. package/dist/tools/memory.js +12 -2
  87. package/dist/tools/monitoring-tools.js +312 -0
  88. package/dist/tools/paths.js +154 -0
  89. package/dist/tools/registry.js +582 -95
  90. package/dist/tools/semantic-compress.js +124 -0
  91. package/dist/tools/shell-context.js +1 -0
  92. package/dist/tools/shell-jobs.js +163 -0
  93. package/dist/tools/shell-session.js +174 -6
  94. package/dist/tools/tool-output-spill.js +1 -1
  95. package/dist/tools/wave-tools.js +609 -0
  96. package/dist/tools/wave2-tools.js +411 -0
  97. package/dist/ui/App.js +15 -4
  98. package/dist/ui/BgPanel.js +30 -6
  99. package/dist/ui/Composer.js +15 -2
  100. package/dist/ui/QuestionPrompt.js +32 -12
  101. package/dist/ui/SessionPicker.js +86 -0
  102. package/dist/ui/StatusRule.js +5 -5
  103. package/dist/ui/ToolStep.js +17 -1
  104. package/dist/ui/Transcript.js +17 -1
  105. package/dist/ui/index.js +1 -1
  106. package/dist/ui/liveTools.js +21 -3
  107. package/dist/ui/slashCommands.js +2 -0
  108. package/dist/util/mentions.js +1 -1
  109. package/dist/util/screenshots.js +74 -8
  110. package/dist/util/slash.js +2 -2
  111. package/dist/vault/store.js +1 -1
  112. package/mcp/README.md +88 -0
  113. package/mcp/ocr-macos.swift +45 -0
  114. package/mcp/powertools-media.mjs +464 -0
  115. package/mcp/powertools-toolbox.mjs +1114 -0
  116. package/mcp/powertools.md +210 -0
  117. package/mcp/powertools.mjs +861 -0
  118. package/package.json +9 -2
@@ -0,0 +1,609 @@
1
+ import { pexecFile } from "./exec.js";
2
+ import { operatorPath } from "../config/home.js";
3
+ const nodeImport = (m) => import(/* @vite-ignore */ m);
4
+ // Home-relative paths resolve LAZILY (per call) so $KODE_HOME / $KODE_PROFILE changes after
5
+ // import are honored — see the operator-home-paths convention.
6
+ const validateFile = () => operatorPath("validate-commands.json");
7
+ const missionsDir = () => operatorPath("missions");
8
+ const boardFile = () => operatorPath("boards.json");
9
+ const routinesFile = () => operatorPath("routines.json");
10
+ async function fsp() { return await nodeImport("node:fs/promises"); }
11
+ async function pathMod() { return await nodeImport("node:path"); }
12
+ async function readJson(p) {
13
+ try {
14
+ const { readFile } = await fsp();
15
+ return JSON.parse(await readFile(p, "utf8"));
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ async function writeJson(p, data) {
22
+ const { mkdir, writeFile } = await fsp();
23
+ const { dirname } = await pathMod();
24
+ await mkdir(dirname(p), { recursive: true, mode: 0o700 });
25
+ await writeFile(p, JSON.stringify(data, null, 2), { encoding: "utf8", mode: 0o600 });
26
+ }
27
+ // ─── filesystem walking (pure code — OS-agnostic, no subprocess) ────────────
28
+ const WALK_SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", "target"]);
29
+ const WALK_MAX_ENTRIES = 50_000;
30
+ /** Iterative directory walk. Calls onFile for each regular file; returning false stops the walk.
31
+ * Exported: wave2-tools' security_scan reuses this walker instead of shelling out to find. */
32
+ export async function walkFiles(root, onFile) {
33
+ const { readdir } = await fsp();
34
+ const { join } = await pathMod();
35
+ const stack = [root];
36
+ let visited = 0;
37
+ while (stack.length) {
38
+ const dir = stack.pop();
39
+ let entries;
40
+ try {
41
+ entries = await readdir(dir, { withFileTypes: true });
42
+ }
43
+ catch {
44
+ continue;
45
+ }
46
+ for (const e of entries) {
47
+ if (++visited > WALK_MAX_ENTRIES)
48
+ return;
49
+ if (e.isSymbolicLink())
50
+ continue;
51
+ const p = join(dir, e.name);
52
+ if (e.isDirectory()) {
53
+ if (!WALK_SKIP_DIRS.has(e.name))
54
+ stack.push(p);
55
+ }
56
+ else if (e.isFile()) {
57
+ if ((await onFile(p, e.name)) === false)
58
+ return;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ /** '*.ts' / 'package.json' style name pattern → anchored RegExp ('*' and '?' wildcards). */
64
+ function nameMatcher(pattern) {
65
+ const esc = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
66
+ return new RegExp(`^${esc}$`);
67
+ }
68
+ // ─── glob ───────────────────────────────────────────────────────────────────
69
+ const GLOB_MAX_RESULTS = 500;
70
+ async function globRun(args) {
71
+ const pattern = args.pattern;
72
+ if (!pattern)
73
+ return "error: pattern required";
74
+ const { resolve } = await pathMod();
75
+ const root = resolve(args.path || ".");
76
+ let matcher;
77
+ try {
78
+ matcher = nameMatcher(pattern);
79
+ }
80
+ catch {
81
+ return "error: invalid pattern";
82
+ }
83
+ const matches = [];
84
+ await walkFiles(root, (p, name) => {
85
+ if (matcher.test(name)) {
86
+ matches.push(p);
87
+ if (matches.length >= GLOB_MAX_RESULTS)
88
+ return false;
89
+ }
90
+ });
91
+ if (!matches.length)
92
+ return "no matches";
93
+ const capped = matches.length >= GLOB_MAX_RESULTS ? `\n…capped at ${GLOB_MAX_RESULTS} results` : "";
94
+ return matches.join("\n") + capped;
95
+ }
96
+ // ─── file_create ────────────────────────────────────────────────────────────
97
+ async function fileCreateRun(args) {
98
+ const p = args.path;
99
+ if (!p)
100
+ return "error: path required";
101
+ const { mkdir, writeFile, access } = await fsp();
102
+ const { dirname } = await pathMod();
103
+ try {
104
+ await access(p);
105
+ return `error: file already exists: ${p}`;
106
+ }
107
+ catch { /* does not exist — good */ }
108
+ try {
109
+ await mkdir(dirname(p), { recursive: true });
110
+ await writeFile(p, args.content ?? "", "utf8");
111
+ return `created ${p}`;
112
+ }
113
+ catch (e) {
114
+ return `error: ${e.message}`;
115
+ }
116
+ }
117
+ // ─── file_delete ────────────────────────────────────────────────────────────
118
+ async function fileDeleteRun(args) {
119
+ const p = args.path;
120
+ if (!p)
121
+ return "error: path required";
122
+ const { unlink } = await fsp();
123
+ try {
124
+ await unlink(p);
125
+ return `deleted ${p}`;
126
+ }
127
+ catch (e) {
128
+ return e.code === "ENOENT" ? `error: not found: ${p}` : `error: ${e.message}`;
129
+ }
130
+ }
131
+ // ─── pkg_install / pkg_remove ───────────────────────────────────────────────
132
+ async function detectPkgManager(cwd) {
133
+ const { access } = await fsp();
134
+ const { join } = await pathMod();
135
+ const has = async (f) => { try {
136
+ await access(join(cwd, f));
137
+ return true;
138
+ }
139
+ catch {
140
+ return false;
141
+ } };
142
+ if (await has("pnpm-lock.yaml"))
143
+ return "pnpm";
144
+ if (await has("yarn.lock"))
145
+ return "yarn";
146
+ if (await has("package-lock.json"))
147
+ return "npm";
148
+ if (await has("Cargo.toml"))
149
+ return "cargo";
150
+ if (await has("Pipfile"))
151
+ return "pip";
152
+ if (await has("requirements.txt"))
153
+ return "pip";
154
+ return "npm";
155
+ }
156
+ // argv forms — package names are ARGUMENTS, never joined into a shell string.
157
+ const INSTALL_ARGV = {
158
+ npm: ["npm", "install"], yarn: ["yarn", "add"], pnpm: ["pnpm", "add"],
159
+ cargo: ["cargo", "add"], pip: ["pip", "install"],
160
+ };
161
+ const REMOVE_ARGV = {
162
+ npm: ["npm", "uninstall"], yarn: ["yarn", "remove"], pnpm: ["pnpm", "remove"],
163
+ cargo: ["cargo", "remove"], pip: ["pip", "uninstall", "-y"],
164
+ };
165
+ async function pkgRun(table, fallback, args, timeout) {
166
+ const pkgs = args.packages;
167
+ if (!pkgs?.length)
168
+ return "error: packages required (string[])";
169
+ const cwd = args.cwd || process.cwd();
170
+ const mgr = args.manager || await detectPkgManager(cwd);
171
+ const [bin, ...verb] = table[mgr] || fallback;
172
+ try {
173
+ const { stdout } = await pexecFile(bin, [...verb, ...pkgs], { cwd, timeout });
174
+ return stdout;
175
+ }
176
+ catch (e) {
177
+ return `error: ${e.stderr || e.message}`;
178
+ }
179
+ }
180
+ const pkgInstallRun = (args) => pkgRun(INSTALL_ARGV, ["npm", "install"], args, 120000);
181
+ const pkgRemoveRun = (args) => pkgRun(REMOVE_ARGV, ["npm", "uninstall"], args, 60000);
182
+ // ─── validate / validate_register ───────────────────────────────────────────
183
+ async function validateRegisterRun(args) {
184
+ const cmd = args.command;
185
+ if (!cmd)
186
+ return "error: command required";
187
+ const cwd = process.cwd();
188
+ const data = (await readJson(validateFile())) || {};
189
+ data[cwd] = cmd;
190
+ await writeJson(validateFile(), data);
191
+ return `registered validation command for ${cwd}: ${cmd}`;
192
+ }
193
+ // `validate` is safe:true (no approval), so it runs ONLY the command registered via the
194
+ // APPROVAL-GATED validate_register — never a command supplied in the call. A compound shell
195
+ // line ("npm test && tsc") is the point of registration, so the stored command legitimately
196
+ // runs through the shell; the gate is that storing it required approval.
197
+ async function validateRun() {
198
+ const data = (await readJson(validateFile())) || {};
199
+ const cmd = data[process.cwd()];
200
+ if (!cmd)
201
+ return "error: no validation command registered — use validate_register first";
202
+ const { exec } = await nodeImport("node:child_process");
203
+ const { promisify } = await nodeImport("node:util");
204
+ try {
205
+ const { stdout } = await promisify(exec)(cmd, { timeout: 120000, cwd: process.cwd() });
206
+ return `PASS\n${stdout}`;
207
+ }
208
+ catch (e) {
209
+ return `FAIL\n${e.stdout || ""}${e.stderr || ""}\nexit ${e.code ?? e.status ?? 1}`;
210
+ }
211
+ }
212
+ // ─── mission_set / mission_status / mission_accomplished ────────────────────
213
+ async function activeMissionFile() {
214
+ const { join } = await pathMod();
215
+ return join(missionsDir(), "active.json");
216
+ }
217
+ async function missionSetRun(args) {
218
+ const goal = args.goal;
219
+ if (!goal)
220
+ return "error: goal required";
221
+ const id = `m-${Date.now().toString(36)}`;
222
+ const mission = { id, goal, success_criteria: args.success_criteria || [], started: new Date().toISOString() };
223
+ await writeJson(await activeMissionFile(), mission);
224
+ return `mission ${id} set: ${goal}`;
225
+ }
226
+ async function missionStatusRun() {
227
+ const m = await readJson(await activeMissionFile());
228
+ if (!m)
229
+ return "no active mission";
230
+ return `mission ${m.id}: ${m.goal}\nstarted: ${m.started}\ncriteria: ${(m.success_criteria || []).join(", ") || "none"}`;
231
+ }
232
+ async function missionAccomplishedRun(args) {
233
+ const summary = args.summary;
234
+ if (!summary)
235
+ return "error: summary required";
236
+ const active = await activeMissionFile();
237
+ const m = await readJson(active);
238
+ if (!m)
239
+ return "error: no active mission";
240
+ const { unlink } = await fsp();
241
+ const { join } = await pathMod();
242
+ m.completed = new Date().toISOString();
243
+ m.summary = summary;
244
+ await writeJson(join(missionsDir(), "archive", `${m.id}.json`), m);
245
+ try {
246
+ await unlink(active);
247
+ }
248
+ catch { /* already gone */ }
249
+ return `mission ${m.id} archived: ${summary}`;
250
+ }
251
+ // ─── lsp_diag ───────────────────────────────────────────────────────────────
252
+ async function lspDiagRun(args) {
253
+ const p = args.path;
254
+ if (!p)
255
+ return "error: path required";
256
+ const { resolve } = await pathMod();
257
+ const file = resolve(p);
258
+ const ext = file.split(".").pop()?.toLowerCase();
259
+ let bin;
260
+ let argv;
261
+ if (ext === "ts" || ext === "tsx") {
262
+ bin = "npx";
263
+ argv = ["tsc", "--noEmit", "--pretty", file];
264
+ }
265
+ else if (ext === "py") {
266
+ bin = "python3";
267
+ argv = ["-m", "py_compile", file];
268
+ }
269
+ else if (ext === "js" || ext === "mjs" || ext === "cjs") {
270
+ bin = "node";
271
+ argv = ["--check", file];
272
+ }
273
+ else
274
+ return `no linter configured for .${ext}`;
275
+ try {
276
+ const { stdout } = await pexecFile(bin, argv, { timeout: 30000 });
277
+ return stdout.trim() || "clean — no diagnostics";
278
+ }
279
+ catch (e) {
280
+ return `${e.stdout || ""}${e.stderr || ""}`.trim() || e.message;
281
+ }
282
+ }
283
+ // ─── board_* (kanban) ───────────────────────────────────────────────────────
284
+ async function boardCreateRun(args) {
285
+ const name = args.name;
286
+ if (!name)
287
+ return "error: name required";
288
+ const data = (await readJson(boardFile())) || { boards: {} };
289
+ if (data.boards[name])
290
+ return `error: board '${name}' already exists`;
291
+ data.boards[name] = { items: [], nextId: 1 };
292
+ await writeJson(boardFile(), data);
293
+ return `board '${name}' created`;
294
+ }
295
+ async function boardListRun(args) {
296
+ const data = (await readJson(boardFile())) || { boards: {} };
297
+ const boardName = args.board;
298
+ if (boardName) {
299
+ const b = data.boards[boardName];
300
+ if (!b)
301
+ return `error: board '${boardName}' not found`;
302
+ if (!b.items.length)
303
+ return `board '${boardName}': empty`;
304
+ return `board '${boardName}':\n` + b.items.map((i) => ` [${i.id}] ${i.status.toUpperCase().padEnd(5)} ${i.title}`).join("\n");
305
+ }
306
+ const names = Object.keys(data.boards);
307
+ if (!names.length)
308
+ return "no boards";
309
+ return names.map(n => {
310
+ const b = data.boards[n];
311
+ const counts = { todo: 0, doing: 0, done: 0 };
312
+ for (const i of b.items)
313
+ counts[i.status]++;
314
+ return `${n}: ${counts.todo} todo / ${counts.doing} doing / ${counts.done} done`;
315
+ }).join("\n");
316
+ }
317
+ async function boardAddRun(args) {
318
+ const board = args.board;
319
+ const title = args.title;
320
+ if (!board || !title)
321
+ return "error: board and title required";
322
+ const data = (await readJson(boardFile())) || { boards: {} };
323
+ const b = data.boards[board];
324
+ if (!b)
325
+ return `error: board '${board}' not found`;
326
+ const status = args.status || "todo";
327
+ const id = b.nextId++;
328
+ b.items.push({ id, title, status, created: new Date().toISOString() });
329
+ await writeJson(boardFile(), data);
330
+ return `added [${id}] '${title}' to ${board} (${status})`;
331
+ }
332
+ async function boardUpdateRun(args) {
333
+ const board = args.board;
334
+ const id = args.id;
335
+ if (!board || id == null)
336
+ return "error: board and id required";
337
+ const data = (await readJson(boardFile())) || { boards: {} };
338
+ const b = data.boards[board];
339
+ if (!b)
340
+ return `error: board '${board}' not found`;
341
+ const item = b.items.find((i) => i.id === id);
342
+ if (!item)
343
+ return `error: item ${id} not found`;
344
+ if (args.status)
345
+ item.status = args.status;
346
+ if (args.title)
347
+ item.title = args.title;
348
+ await writeJson(boardFile(), data);
349
+ return `updated [${id}]: ${item.status} — ${item.title}`;
350
+ }
351
+ // ─── routine_* (cron) ───────────────────────────────────────────────────────
352
+ async function routineCreateRun(args) {
353
+ const name = args.name;
354
+ const command = args.command;
355
+ const schedule = args.schedule;
356
+ if (!name || !command || !schedule)
357
+ return "error: name, command, and schedule required";
358
+ const data = (await readJson(routinesFile())) || { routines: {} };
359
+ data.routines[name] = { command, schedule, created: new Date().toISOString(), enabled: true };
360
+ await writeJson(routinesFile(), data);
361
+ return `routine '${name}' created: ${schedule} → ${command}`;
362
+ }
363
+ async function routineListRun() {
364
+ const data = (await readJson(routinesFile())) || { routines: {} };
365
+ const entries = Object.entries(data.routines);
366
+ if (!entries.length)
367
+ return "no routines";
368
+ return entries.map(([name, r]) => `${r.enabled ? "ON " : "OFF"} ${name}: ${r.schedule} → ${r.command}`).join("\n");
369
+ }
370
+ async function routineDeleteRun(args) {
371
+ const name = args.name;
372
+ if (!name)
373
+ return "error: name required";
374
+ const data = (await readJson(routinesFile())) || { routines: {} };
375
+ if (!data.routines[name])
376
+ return `error: routine '${name}' not found`;
377
+ delete data.routines[name];
378
+ await writeJson(routinesFile(), data);
379
+ return `routine '${name}' deleted`;
380
+ }
381
+ // ─── code_search (text scan for now; embedding RAG in Wave 3) ───────────────
382
+ const SEARCH_MAX_FILES = 50;
383
+ const SEARCH_MAX_FILE_BYTES = 1_000_000;
384
+ const SEARCH_HITS_PER_FILE = 5;
385
+ async function codeSearchRun(args) {
386
+ const query = args.query;
387
+ if (!query)
388
+ return "error: query required";
389
+ const { resolve } = await pathMod();
390
+ const { readFile, stat } = await fsp();
391
+ const root = resolve(args.path || ".");
392
+ const exts = (args.extensions || "ts,js,py,rs,go,tsx,jsx")
393
+ .split(",").map(e => `.${e.trim().replace(/^\./, "")}`);
394
+ // Regex when the query compiles as one, literal text otherwise — never a subprocess.
395
+ let test;
396
+ try {
397
+ const re = new RegExp(query);
398
+ test = l => re.test(l);
399
+ }
400
+ catch {
401
+ test = l => l.includes(query);
402
+ }
403
+ const fileHits = [];
404
+ await walkFiles(root, async (p, name) => {
405
+ if (!exts.some(x => name.endsWith(x)))
406
+ return;
407
+ try {
408
+ if ((await stat(p)).size > SEARCH_MAX_FILE_BYTES)
409
+ return;
410
+ const lines = (await readFile(p, "utf8")).split("\n");
411
+ const hits = [];
412
+ for (let i = 0; i < lines.length && hits.length < SEARCH_HITS_PER_FILE; i++) {
413
+ if (test(lines[i]))
414
+ hits.push(`${i + 1}:${lines[i].trimEnd()}`);
415
+ }
416
+ if (hits.length) {
417
+ fileHits.push({ file: p, hits });
418
+ if (fileHits.length >= SEARCH_MAX_FILES)
419
+ return false;
420
+ }
421
+ }
422
+ catch { /* unreadable file — skip */ }
423
+ });
424
+ if (!fileHits.length)
425
+ return "no matches";
426
+ const results = [`${fileHits.length} files match:`];
427
+ for (const { file, hits } of fileHits.slice(0, 20)) {
428
+ results.push(`\n${file}:`);
429
+ results.push(hits.join("\n"));
430
+ }
431
+ if (fileHits.length > 20)
432
+ results.push(`\n…and ${fileHits.length - 20} more files`);
433
+ return results.join("\n");
434
+ }
435
+ // ─── export all tools ───────────────────────────────────────────────────────
436
+ export const WAVE_TOOLS = [
437
+ {
438
+ name: "glob", safe: true,
439
+ description: "Find files matching a name pattern ('*' and '?' wildcards). Skips node_modules/.git/dist. Returns newline-separated paths.",
440
+ parameters: { type: "object", properties: {
441
+ pattern: { type: "string", description: "filename pattern (e.g. '*.ts', 'package.json')" },
442
+ path: { type: "string", description: "directory to search in (default: '.')" },
443
+ }, required: ["pattern"] },
444
+ run: globRun,
445
+ },
446
+ {
447
+ name: "file_create", safe: false,
448
+ description: "Create a new file. Errors if file already exists (use file_write to overwrite). Creates parent dirs.",
449
+ parameters: { type: "object", properties: {
450
+ path: { type: "string" },
451
+ content: { type: "string", description: "file content (default: empty)" },
452
+ }, required: ["path"] },
453
+ run: fileCreateRun,
454
+ },
455
+ {
456
+ name: "file_delete", safe: false,
457
+ description: "Delete a single file.",
458
+ parameters: { type: "object", properties: {
459
+ path: { type: "string" },
460
+ }, required: ["path"] },
461
+ run: fileDeleteRun,
462
+ },
463
+ {
464
+ name: "pkg_install", safe: false,
465
+ description: "Install packages. Auto-detects package manager from lockfile (npm/yarn/pnpm/cargo/pip).",
466
+ parameters: { type: "object", properties: {
467
+ packages: { type: "array", items: { type: "string" }, description: "package names to install" },
468
+ manager: { type: "string", description: "force a package manager (npm|yarn|pnpm|cargo|pip)" },
469
+ cwd: { type: "string" },
470
+ }, required: ["packages"] },
471
+ run: pkgInstallRun,
472
+ },
473
+ {
474
+ name: "pkg_remove", safe: false,
475
+ description: "Remove/uninstall packages. Auto-detects package manager.",
476
+ parameters: { type: "object", properties: {
477
+ packages: { type: "array", items: { type: "string" } },
478
+ manager: { type: "string" },
479
+ cwd: { type: "string" },
480
+ }, required: ["packages"] },
481
+ run: pkgRemoveRun,
482
+ },
483
+ {
484
+ name: "validate", safe: true,
485
+ description: "Run the project's registered validation command (see validate_register) and return PASS/FAIL + output. Registering or changing the command requires approval; this tool never runs an ad-hoc command.",
486
+ parameters: { type: "object", properties: {} },
487
+ run: validateRun,
488
+ },
489
+ {
490
+ name: "validate_register", safe: false,
491
+ description: "Register a recurring validation command for the current project directory.",
492
+ parameters: { type: "object", properties: {
493
+ command: { type: "string", description: "the validation command (e.g. 'npm test', 'cargo check')" },
494
+ }, required: ["command"] },
495
+ run: validateRegisterRun,
496
+ },
497
+ {
498
+ name: "mission_set", safe: false,
499
+ description: "Set the active mission goal. Archives any prior active mission.",
500
+ parameters: { type: "object", properties: {
501
+ goal: { type: "string", description: "the mission objective" },
502
+ success_criteria: { type: "array", items: { type: "string" }, description: "measurable success criteria" },
503
+ }, required: ["goal"] },
504
+ run: missionSetRun,
505
+ },
506
+ {
507
+ name: "mission_status", safe: true,
508
+ description: "Show the current active mission and its criteria.",
509
+ parameters: { type: "object", properties: {} },
510
+ run: missionStatusRun,
511
+ },
512
+ {
513
+ name: "mission_accomplished", safe: false,
514
+ description: "Mark the active mission as complete and archive it.",
515
+ parameters: { type: "object", properties: {
516
+ summary: { type: "string", description: "completion summary" },
517
+ }, required: ["summary"] },
518
+ run: missionAccomplishedRun,
519
+ },
520
+ {
521
+ name: "lsp_diag", safe: true,
522
+ description: "Get linter/compiler diagnostics for a file. Supports .ts/.tsx (tsc), .py (py_compile), .js/.mjs/.cjs (node --check).",
523
+ parameters: { type: "object", properties: {
524
+ path: { type: "string", description: "file to check" },
525
+ }, required: ["path"] },
526
+ run: lspDiagRun,
527
+ },
528
+ {
529
+ name: "board_create", safe: false,
530
+ description: "Create a new kanban board.",
531
+ parameters: { type: "object", properties: {
532
+ name: { type: "string" },
533
+ }, required: ["name"] },
534
+ run: boardCreateRun,
535
+ },
536
+ {
537
+ name: "board_list", safe: true,
538
+ description: "List all boards (or items in a specific board).",
539
+ parameters: { type: "object", properties: {
540
+ board: { type: "string", description: "board name (omit to list all boards)" },
541
+ } },
542
+ run: boardListRun,
543
+ },
544
+ {
545
+ name: "board_add", safe: false,
546
+ description: "Add an item to a kanban board.",
547
+ parameters: { type: "object", properties: {
548
+ board: { type: "string" },
549
+ title: { type: "string" },
550
+ status: { type: "string", description: "todo|doing|done (default: todo)" },
551
+ }, required: ["board", "title"] },
552
+ run: boardAddRun,
553
+ },
554
+ {
555
+ name: "board_update", safe: false,
556
+ description: "Update a kanban board item's status or title.",
557
+ parameters: { type: "object", properties: {
558
+ board: { type: "string" },
559
+ id: { type: "number" },
560
+ status: { type: "string" },
561
+ title: { type: "string" },
562
+ }, required: ["board", "id"] },
563
+ run: boardUpdateRun,
564
+ },
565
+ {
566
+ name: "routine_create", safe: false,
567
+ description: "Create a named routine with a cron schedule.",
568
+ parameters: { type: "object", properties: {
569
+ name: { type: "string" },
570
+ command: { type: "string", description: "command to execute" },
571
+ schedule: { type: "string", description: "cron expression (e.g. '*/5 * * * *')" },
572
+ }, required: ["name", "command", "schedule"] },
573
+ run: routineCreateRun,
574
+ },
575
+ {
576
+ name: "routine_list", safe: true,
577
+ description: "List all registered routines.",
578
+ parameters: { type: "object", properties: {} },
579
+ run: routineListRun,
580
+ },
581
+ {
582
+ name: "routine_delete", safe: false,
583
+ description: "Delete a named routine.",
584
+ parameters: { type: "object", properties: {
585
+ name: { type: "string" },
586
+ }, required: ["name"] },
587
+ run: routineDeleteRun,
588
+ },
589
+ {
590
+ name: "code_search", safe: true,
591
+ description: "Search the codebase for a query (regex, falling back to literal text) across common file types. Skips node_modules/.git/dist. Returns matching files with line hits.",
592
+ parameters: { type: "object", properties: {
593
+ query: { type: "string", description: "search term (regex or literal)" },
594
+ path: { type: "string", description: "directory to search (default: '.')" },
595
+ extensions: { type: "string", description: "comma-separated extensions (default: ts,js,py,rs,go,tsx,jsx)" },
596
+ }, required: ["query"] },
597
+ run: codeSearchRun,
598
+ },
599
+ {
600
+ name: "codebase_search", safe: true,
601
+ description: "Alias of code_search — search the codebase for a query string. (Embedding-based RAG planned for Wave 3.)",
602
+ parameters: { type: "object", properties: {
603
+ query: { type: "string" },
604
+ path: { type: "string" },
605
+ extensions: { type: "string" },
606
+ }, required: ["query"] },
607
+ run: codeSearchRun,
608
+ },
609
+ ];