piroboros 0.0.0-stage → 0.2.0

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/CHANGELOG.md +43 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +39 -0
  4. package/README.md +140 -2
  5. package/agents/astrelia.md +31 -0
  6. package/agents/avaritia.md +31 -0
  7. package/agents/elaria.md +31 -0
  8. package/agents/nytheria.md +32 -0
  9. package/agents/raskreia.md +32 -0
  10. package/agents/samaela.md +40 -0
  11. package/agents/vaelia.md +35 -0
  12. package/agents/vesperia.md +45 -0
  13. package/bin/piroboros.mjs +17 -0
  14. package/dist/auth.js +105 -0
  15. package/dist/base.js +19 -0
  16. package/dist/chat/budget.js +87 -0
  17. package/dist/chat/compactloop.js +63 -0
  18. package/dist/chat/compactor.js +530 -0
  19. package/dist/chat/extension.js +36 -0
  20. package/dist/chat/hook.js +40 -0
  21. package/dist/chat/log.js +317 -0
  22. package/dist/chat/outbound.js +114 -0
  23. package/dist/chat/plan.js +64 -0
  24. package/dist/chat/prompt.js +115 -0
  25. package/dist/chat/status.js +37 -0
  26. package/dist/chat/stuck.js +83 -0
  27. package/dist/chat/tools.js +163 -0
  28. package/dist/chat/tree.js +73 -0
  29. package/dist/chat/turn.js +305 -0
  30. package/dist/chat/view.js +163 -0
  31. package/dist/conclave/agents.js +113 -0
  32. package/dist/conclave/pipeline.js +715 -0
  33. package/dist/conclave/report.js +43 -0
  34. package/dist/config.js +614 -0
  35. package/dist/durable.js +177 -0
  36. package/dist/guard.js +346 -0
  37. package/dist/lock.js +56 -0
  38. package/dist/main.js +348 -0
  39. package/dist/memory/akashic/api.js +121 -0
  40. package/dist/memory/akashic/confusables.js +41 -0
  41. package/dist/memory/akashic/scanner.js +67 -0
  42. package/dist/memory/akashic/snapshot.js +31 -0
  43. package/dist/memory/akashic/store.js +1254 -0
  44. package/dist/memory/akashic/tools.js +168 -0
  45. package/dist/memory/akashic/vault.js +984 -0
  46. package/dist/memory/host.js +124 -0
  47. package/dist/memory/mnemosia/adapters/akashic-memories.js +180 -0
  48. package/dist/memory/mnemosia/adapters/contract.js +219 -0
  49. package/dist/memory/mnemosia/agents.js +387 -0
  50. package/dist/memory/mnemosia/brief.js +890 -0
  51. package/dist/memory/mnemosia/claims.js +609 -0
  52. package/dist/memory/mnemosia/conflicts.js +769 -0
  53. package/dist/memory/mnemosia/escalation.js +257 -0
  54. package/dist/memory/mnemosia/feedback.js +108 -0
  55. package/dist/memory/mnemosia/filters.js +248 -0
  56. package/dist/memory/mnemosia/intent.js +221 -0
  57. package/dist/memory/mnemosia/open.js +34 -0
  58. package/dist/memory/mnemosia/orchestrator.js +926 -0
  59. package/dist/memory/mnemosia/plan.js +266 -0
  60. package/dist/memory/mnemosia/policy.js +426 -0
  61. package/dist/memory/mnemosia/progressive.js +550 -0
  62. package/dist/memory/mnemosia/provenance.js +458 -0
  63. package/dist/memory/mnemosia/qualifiers.js +428 -0
  64. package/dist/memory/mnemosia/rank.js +525 -0
  65. package/dist/memory/mnemosia/relations.js +156 -0
  66. package/dist/memory/mnemosia/requirements.js +138 -0
  67. package/dist/memory/mnemosia/rerank.js +253 -0
  68. package/dist/memory/mnemosia/retention.js +174 -0
  69. package/dist/memory/mnemosia/rollback.js +337 -0
  70. package/dist/memory/mnemosia/select.js +607 -0
  71. package/dist/memory/mnemosia/similarity.js +164 -0
  72. package/dist/memory/mnemosia/situation.js +251 -0
  73. package/dist/memory/mnemosia/task.js +418 -0
  74. package/dist/memory/mnemosia/temporal.js +136 -0
  75. package/dist/memory/mnemosia/tokens.js +66 -0
  76. package/dist/memory/mnemosia/tools.js +160 -0
  77. package/dist/memory/mnemosia/trace.js +306 -0
  78. package/dist/memory/mnemosia/types.js +298 -0
  79. package/dist/models.js +360 -0
  80. package/dist/paths.js +103 -0
  81. package/dist/redact.js +79 -0
  82. package/dist/runtime.js +378 -0
  83. package/dist/search-format.js +102 -0
  84. package/dist/search.js +351 -0
  85. package/dist/setup.js +366 -0
  86. package/dist/shell.js +110 -0
  87. package/dist/skills.js +311 -0
  88. package/dist/telemetry.js +84 -0
  89. package/dist/tui/app.js +1011 -0
  90. package/dist/tui/commands.js +121 -0
  91. package/dist/tui/keys.js +83 -0
  92. package/dist/tui/pane.js +387 -0
  93. package/dist/tui/panel.js +60 -0
  94. package/dist/tui/picker.js +25 -0
  95. package/dist/tui/sanitize.js +59 -0
  96. package/dist/tui/settings.js +198 -0
  97. package/dist/tui/setup.js +256 -0
  98. package/dist/tui/theme.js +26 -0
  99. package/dist/tui/thinking/parse.js +1094 -0
  100. package/dist/tui/thinking/select.js +86 -0
  101. package/dist/tui/thinking/state.js +137 -0
  102. package/dist/tui/thinking/types.js +3 -0
  103. package/dist/tui/thinking/view.js +74 -0
  104. package/dist/tui/viewport.js +208 -0
  105. package/dist/undo.js +258 -0
  106. package/dist/web.js +933 -0
  107. package/docs/conclave.md +21 -0
  108. package/docs/configuration.md +48 -0
  109. package/docs/development.md +25 -0
  110. package/docs/interface.md +33 -0
  111. package/docs/memory.md +11 -0
  112. package/docs/privacy.md +13 -0
  113. package/docs/tools.md +20 -0
  114. package/docs/web.md +38 -0
  115. package/models.json.example +34 -0
  116. package/package.json +76 -4
  117. package/settings.json.example +29 -0
  118. package/skills/conclave/SKILL.md +76 -0
package/dist/search.js ADDED
@@ -0,0 +1,351 @@
1
+ import { spawn } from "node:child_process";
2
+ import { mkdirSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { Type } from "typebox";
5
+ import { AgentDoc, ctx, defineTool } from "./durable.js";
6
+ import { checkPath } from "./guard.js";
7
+ import { redactSensitive } from "./redact.js";
8
+ import { clampContext, formatFind, formatGrep, isWildcardOnly, normalizeConstraint, truncateLine, NO_FILES_FOUND } from "./search-format.js";
9
+ export const FIND_LIMIT = 30;
10
+ export const GREP_LIMIT = 20;
11
+ export const MAX_OUTPUT_CHARS = 20_000;
12
+ const SCAN_MS = 15_000;
13
+ const RG_TIMEOUT_MS = 30_000;
14
+ const RG_MAX_EVENTS = 5_000;
15
+ const CURSOR_KEYS = 50;
16
+ /** The code names the failure; the text after it is for the model. */
17
+ export class SearchError extends Error {
18
+ code;
19
+ constructor(code, message) {
20
+ super(`${code}: ${message}`);
21
+ this.code = code;
22
+ }
23
+ }
24
+ const reasonOf = (error) => (error instanceof Error ? error.message : String(error));
25
+ const shown = (path) => path.replace(/^\.[\\/]/u, "").replaceAll("\\", "/");
26
+ /** An rg glob for a constraint: a directory prefix means everything under it. */
27
+ const rgGlob = (constraint) => (constraint.endsWith("/") ? `${constraint}**` : constraint);
28
+ /** Run rg with an argument list. `onLine` returns true to stop early. Output is read as lines of UTF-8 text. */
29
+ function runRg(program, args, cwd, onLine) {
30
+ return new Promise((resolve, reject) => {
31
+ const child = spawn(program, args, { cwd, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
32
+ let rest = "";
33
+ let stderr = "";
34
+ let stopped = false;
35
+ const timer = setTimeout(() => {
36
+ child.kill();
37
+ reject(new SearchError("search_timeout", `ripgrep did not finish within ${RG_TIMEOUT_MS / 1000} seconds; narrow the search with glob`));
38
+ }, RG_TIMEOUT_MS);
39
+ child.stdout.setEncoding("utf8");
40
+ child.stderr.setEncoding("utf8");
41
+ child.stderr.on("data", (text) => { if (stderr.length < 4_000)
42
+ stderr += text; });
43
+ child.stdout.on("data", (text) => {
44
+ if (stopped)
45
+ return;
46
+ const parts = (rest + text).split("\n");
47
+ rest = parts.pop() ?? "";
48
+ for (const line of parts) {
49
+ if (onLine(line.replace(/\r$/u, ""))) {
50
+ stopped = true;
51
+ child.kill();
52
+ return;
53
+ }
54
+ }
55
+ });
56
+ child.on("error", (error) => {
57
+ clearTimeout(timer);
58
+ reject(error.code === "ENOENT" ? new SearchError("search_rg_unavailable", "ripgrep (rg) was not found on PATH") : error);
59
+ });
60
+ child.on("close", (code) => {
61
+ clearTimeout(timer);
62
+ if (!stopped && rest !== "")
63
+ onLine(rest.replace(/\r$/u, ""));
64
+ resolve({ code, stderr });
65
+ });
66
+ });
67
+ }
68
+ /** Whether fff loads here, and whether rg starts. Used by setup and by the status of a running search. */
69
+ export async function probeSearch(options = {}) {
70
+ let fff;
71
+ try {
72
+ const module = await (options.loadFff ?? (() => import("@ff-labs/fff-node")))();
73
+ fff = module.binaryExists() ? { ok: true } : { ok: false, reason: "the native library for this platform is not installed" };
74
+ }
75
+ catch (error) {
76
+ fff = { ok: false, reason: reasonOf(error) };
77
+ }
78
+ const rg = await runRg(options.rg ?? "rg", ["--version"], process.cwd(), () => false).then((r) => r.code === 0, () => false);
79
+ return { fff, rg };
80
+ }
81
+ export function createSearch(deps) {
82
+ const rg = deps.rg ?? "rg";
83
+ let fffPromise;
84
+ let holder;
85
+ let creating = Promise.resolve();
86
+ const loadFff = () => (fffPromise ??= (deps.loadFff ?? (() => import("@ff-labs/fff-node")))());
87
+ const allowed = (path, cwd) => checkPath(path, cwd, deps.guard()).allowed;
88
+ const destroy = () => {
89
+ if (holder !== undefined && !holder.finder.isDestroyed)
90
+ holder.finder.destroy();
91
+ holder = undefined;
92
+ };
93
+ /** One index per working directory; a different directory replaces it. Creation is serialized. */
94
+ const finderFor = (cwd) => {
95
+ const next = creating.then(async () => {
96
+ if (holder !== undefined && holder.cwd === cwd && !holder.finder.isDestroyed)
97
+ return holder;
98
+ destroy();
99
+ const fff = await loadFff();
100
+ const base = { basePath: cwd, aiMode: true, enableHomeDirScanning: false, enableFsRootScanning: false };
101
+ mkdirSync(join(deps.home, "fff"), { recursive: true });
102
+ let made = fff.FileFinder.create({ ...base, frecencyDbPath: join(deps.home, "fff", "frecency.db"), historyDbPath: join(deps.home, "fff", "history.db") });
103
+ // a locked or damaged database must not turn search off
104
+ if (!made.ok)
105
+ made = fff.FileFinder.create(base);
106
+ if (!made.ok)
107
+ throw new Error(made.error);
108
+ const waited = await made.value.waitForScan(SCAN_MS);
109
+ if (!waited.ok) {
110
+ made.value.destroy();
111
+ throw new Error(waited.error);
112
+ }
113
+ return (holder = { cwd, finder: made.value, cursors: new Map() });
114
+ });
115
+ creating = next.catch(() => undefined);
116
+ return next;
117
+ };
118
+ const constraintOf = (glob, cwd) => {
119
+ try {
120
+ return glob === undefined ? undefined : normalizeConstraint(glob, cwd);
121
+ }
122
+ catch (error) {
123
+ throw new SearchError("search_glob_outside", reasonOf(error));
124
+ }
125
+ };
126
+ const FFF_DOWN = "fff unavailable: ";
127
+ /** rg missing after fff failed is one named error; an exact search without rg names rg alone. */
128
+ const unavailable = (reason, error) => error instanceof SearchError && error.code === "search_rg_unavailable" && reason.startsWith(FFF_DOWN)
129
+ ? new SearchError("search_unavailable", `fff is unavailable (${reason.slice(FFF_DOWN.length)}) and ripgrep (rg) was not found on PATH`)
130
+ : error;
131
+ /* --- find --- */
132
+ async function findFff(cwd, query, constraint, page) {
133
+ const h = await finderFor(cwd);
134
+ // fff-node 0.11.0 reads pageIndex as the offset of the first item (checked: 30 returns the 31st item on), not as a page number.
135
+ const res = h.finder.fileSearch([constraint, query].filter((part) => part !== undefined && part !== "").join(" "), { pageIndex: (page - 1) * FIND_LIMIT, pageSize: FIND_LIMIT });
136
+ if (!res.ok)
137
+ throw new Error(res.error);
138
+ const { items, scores, totalMatched } = res.value;
139
+ const formatted = formatFind(items.filter((item) => allowed(item.relativePath, cwd)), scores[0]?.total ?? 0, FIND_LIMIT, query);
140
+ const notes = [];
141
+ const seen = (page - 1) * FIND_LIMIT + items.length;
142
+ if (formatted.weak && formatted.shown > 0)
143
+ notes.push(`"${query}" gave only weak fuzzy matches; showing ${formatted.shown} of ${totalMatched}`);
144
+ else if (items.length >= FIND_LIMIT && totalMatched > seen)
145
+ notes.push(`${totalMatched - seen} more; page=${page + 1}`);
146
+ return { text: notes.length > 0 ? `${formatted.output}\n\n[${notes.join(". ")}]` : formatted.output, backend: "fff", total: totalMatched, page };
147
+ }
148
+ async function findRg(cwd, query, constraint, page, reason) {
149
+ const argv = ["--no-config", "--no-messages", "--no-require-git", "--files", "--sort", "path", "--glob", "!.git", ...(constraint === undefined ? [] : ["--glob", rgGlob(constraint)]), "--", "."];
150
+ const words = query.toLowerCase().split(/\s+/u).filter((word) => word !== "");
151
+ const hits = [];
152
+ let run;
153
+ try {
154
+ run = await runRg(rg, argv, cwd, (line) => {
155
+ const path = shown(line);
156
+ if (path !== "" && words.every((word) => path.toLowerCase().includes(word)) && allowed(path, cwd))
157
+ hits.push(path);
158
+ return false;
159
+ });
160
+ }
161
+ catch (error) {
162
+ throw unavailable(reason, error);
163
+ }
164
+ // 0 lists files, 1 lists none. Anything else is an rg failure, never "no files"; a partial listing with some unreadable paths still counts.
165
+ if (run.code !== 0 && run.code !== 1 && hits.length === 0)
166
+ throw new SearchError("search_rg_failed", run.stderr.trim().split("\n")[0] || `ripgrep exited with code ${run.code}`);
167
+ const slice = hits.slice((page - 1) * FIND_LIMIT, page * FIND_LIMIT);
168
+ if (slice.length === 0)
169
+ return { text: NO_FILES_FOUND, backend: "rg", reason, total: hits.length, page };
170
+ const more = hits.length - page * FIND_LIMIT;
171
+ return { text: more > 0 ? `${slice.join("\n")}\n\n[${more} more; page=${page + 1}]` : slice.join("\n"), backend: "rg", reason, total: hits.length, page };
172
+ }
173
+ async function find(cwd, query, glob, page) {
174
+ const constraint = constraintOf(glob, cwd);
175
+ let reason;
176
+ try {
177
+ return await findFff(cwd, query, constraint, page);
178
+ }
179
+ catch (error) {
180
+ reason = `${FFF_DOWN}${reasonOf(error)}`;
181
+ }
182
+ return findRg(cwd, query, constraint, page, reason);
183
+ }
184
+ async function grepFff(cwd, a) {
185
+ const h = await finderFor(cwd);
186
+ const key = JSON.stringify([a.pattern, a.mode, a.constraint ?? "", a.context]);
187
+ const known = h.cursors.get(key) ?? [];
188
+ if (a.page > 1 && known[a.page - 2] === undefined)
189
+ throw new SearchError("search_page_unavailable", `page ${a.page} needs page ${a.page - 1} first, with the same arguments`);
190
+ const options = { smartCase: true, maxMatchesPerFile: 200, pageSize: GREP_LIMIT, classifyDefinitions: true, timeBudgetMs: 10_000 };
191
+ const query = a.constraint === undefined ? a.pattern : `${a.constraint} ${a.pattern}`;
192
+ const first = h.finder.grep(query, { ...options, mode: a.mode, cursor: a.page > 1 ? known[a.page - 2] : null, beforeContext: a.context, afterContext: a.context });
193
+ if (!first.ok)
194
+ throw new Error(first.error);
195
+ let result = first.value;
196
+ const notes = [];
197
+ if (result.items.length === 0 && result.nextCursor === null && a.page === 1 && a.mode === "plain") {
198
+ const fuzzy = h.finder.grep(query, { ...options, mode: "fuzzy", cursor: null });
199
+ if (fuzzy.ok && fuzzy.value.items.length > 0) {
200
+ result = fuzzy.value;
201
+ notes.push("0 exact matches; these are fuzzy matches");
202
+ }
203
+ }
204
+ if (result.regexFallbackError)
205
+ notes.push(`Invalid regex: ${result.regexFallbackError}; matched as plain text`);
206
+ if (result.nextCursor !== null) {
207
+ known[a.page - 1] = result.nextCursor;
208
+ h.cursors.delete(key);
209
+ h.cursors.set(key, known);
210
+ if (h.cursors.size > CURSOR_KEYS)
211
+ h.cursors.delete(h.cursors.keys().next().value);
212
+ notes.push(`more results; page=${a.page + 1}`);
213
+ }
214
+ const items = result.items.filter((item) => allowed(item.relativePath, cwd));
215
+ const body = formatGrep(items);
216
+ return { text: notes.length > 0 ? `${body}\n\n[${notes.join(". ")}]` : body, backend: "fff", total: result.totalMatched, page: a.page };
217
+ }
218
+ async function grepRg(cwd, a, reason) {
219
+ const argv = [
220
+ "--no-config", "--no-messages", "--no-require-git", "--json", "--smart-case", "--max-count", "200", "--max-filesize", "1M", "--glob", "!.git",
221
+ ...(a.constraint === undefined ? [] : ["--glob", rgGlob(a.constraint)]),
222
+ ...(a.context > 0 ? ["-C", String(a.context)] : []),
223
+ ...(a.mode === "regex" ? [] : ["--fixed-strings"]),
224
+ "-e", a.pattern, "--", ".",
225
+ ];
226
+ const events = [];
227
+ const verdicts = new Map();
228
+ let matches = 0;
229
+ const want = a.page * GREP_LIMIT + 1;
230
+ let run;
231
+ try {
232
+ run = await runRg(rg, argv, cwd, (line) => {
233
+ let event;
234
+ try {
235
+ event = JSON.parse(line);
236
+ }
237
+ catch {
238
+ return false;
239
+ }
240
+ if (event.type !== "match" && event.type !== "context")
241
+ return false;
242
+ const path = event.data?.path?.text;
243
+ const text = event.data?.lines?.text;
244
+ if (path === undefined || text === undefined || event.data?.line_number === undefined)
245
+ return false;
246
+ const name = shown(path);
247
+ let ok = verdicts.get(name);
248
+ if (ok === undefined)
249
+ verdicts.set(name, (ok = allowed(name, cwd)));
250
+ if (!ok)
251
+ return false;
252
+ events.push({ path: name, line: event.data.line_number, text: text.replace(/\r?\n$/u, ""), match: event.type === "match" });
253
+ if (event.type === "match")
254
+ matches += 1;
255
+ return matches >= want || events.length >= RG_MAX_EVENTS;
256
+ });
257
+ }
258
+ catch (error) {
259
+ throw unavailable(reason, error);
260
+ }
261
+ if (run.code === 2 && events.length === 0 && run.stderr.trim() !== "")
262
+ throw new SearchError(/regex|parse error/iu.test(run.stderr) ? "search_invalid_pattern" : "search_rg_failed", run.stderr.trim().split("\n")[0]);
263
+ const all = events.filter((event) => event.match);
264
+ const page = all.slice((a.page - 1) * GREP_LIMIT, a.page * GREP_LIMIT);
265
+ if (page.length === 0)
266
+ return { text: "No matches found", backend: "rg", reason, total: 0, page: a.page };
267
+ const chosen = new Map();
268
+ for (const event of page)
269
+ chosen.set(event.path, [...(chosen.get(event.path) ?? []), event.line]);
270
+ const lines = [];
271
+ let current = "";
272
+ for (const event of events) {
273
+ const near = chosen.get(event.path);
274
+ if (near === undefined || !near.some((line) => Math.abs(line - event.line) <= (event.match ? 0 : a.context)))
275
+ continue;
276
+ if (event.path !== current) {
277
+ if (lines.length > 0)
278
+ lines.push("");
279
+ current = event.path;
280
+ lines.push(current);
281
+ }
282
+ lines.push(` ${event.line}${event.match ? ":" : "-"} ${truncateLine(event.text)}`);
283
+ }
284
+ const more = all.length > a.page * GREP_LIMIT;
285
+ return { text: more ? `${lines.join("\n")}\n\n[more results; page=${a.page + 1}]` : lines.join("\n"), backend: "rg", reason, total: all.length, page: a.page };
286
+ }
287
+ async function grep(cwd, args) {
288
+ const a = { pattern: args.pattern, mode: args.mode ?? "plain", constraint: constraintOf(args.glob, cwd), context: clampContext(args.context), page: args.page ?? 1 };
289
+ if (a.pattern === "")
290
+ throw new SearchError("search_empty_pattern", "the pattern is empty");
291
+ if (args.exact === true && a.mode === "fuzzy")
292
+ throw new SearchError("search_exact_fuzzy", "exact search uses ripgrep, which has no fuzzy mode; use mode plain or regex");
293
+ if (a.mode === "regex" && isWildcardOnly(a.pattern))
294
+ return { text: `Pattern '${a.pattern}' matches everything; give a concrete word or identifier.`, backend: "fff", total: 0, page: a.page };
295
+ let reason = "exact search";
296
+ if (args.exact !== true) {
297
+ try {
298
+ return await grepFff(cwd, a);
299
+ }
300
+ catch (error) {
301
+ if (error instanceof SearchError)
302
+ throw error;
303
+ reason = `${FFF_DOWN}${reasonOf(error)}`;
304
+ }
305
+ }
306
+ return grepRg(cwd, a.mode === "fuzzy" ? { ...a, mode: "plain" } : a, a.mode === "fuzzy" && args.exact !== true ? `${reason}; fuzzy needs fff, so plain matching was used` : reason);
307
+ }
308
+ /* --- tools --- */
309
+ const cwdOf = async (api) => (await api.snapshot(AgentDoc, api.conversationId, ctx))?.cwd ?? process.cwd();
310
+ const finish = (reply) => {
311
+ const redacted = redactSensitive(reply.text);
312
+ const text = redacted.length > MAX_OUTPUT_CHARS ? `${redacted.slice(0, MAX_OUTPUT_CHARS)}\n[output cut at ${MAX_OUTPUT_CHARS} characters; narrow the search]` : redacted;
313
+ return {
314
+ output: [{ type: "text", text }],
315
+ details: { backend: reply.backend, page: reply.page, ...(reply.reason === undefined ? {} : { reason: reply.reason }), ...(reply.total === undefined ? {} : { total: reply.total }) },
316
+ };
317
+ };
318
+ const page = Type.Optional(Type.Integer({ minimum: 1, description: "Page number, from 1." }));
319
+ const glob = Type.Optional(Type.String({ description: "Limits the paths: a directory (src/), a file name (main.rs) or a glob (*.ts, src/**/*.ts)." }));
320
+ const findTool = defineTool({
321
+ name: "find",
322
+ description: "Find files by fuzzy path match, most used first. Several words narrow the match. Matches the whole path, not only the file name.",
323
+ parameters: Type.Object({ query: Type.String({ description: "Words from the path." }), glob, page }),
324
+ replay: "safe",
325
+ async execute(args, api) {
326
+ return finish(await find(await cwdOf(api), args.query, args.glob, args.page ?? 1));
327
+ },
328
+ });
329
+ const grepTool = defineTool({
330
+ name: "grep",
331
+ description: "Search file contents, most used files first. A bare identifier works best. exact: true searches every file with ripgrep and reads the pattern as given.",
332
+ parameters: Type.Object({
333
+ pattern: Type.String(),
334
+ mode: Type.Optional(Type.Union([Type.Literal("plain"), Type.Literal("regex"), Type.Literal("fuzzy")], { description: "Default plain." })),
335
+ glob,
336
+ context: Type.Optional(Type.Integer({ minimum: 0, maximum: 20, description: "Lines of context around each match." })),
337
+ exact: Type.Optional(Type.Boolean({ description: "Use ripgrep. No time limit and no query syntax." })),
338
+ page,
339
+ }),
340
+ replay: "safe",
341
+ async execute(args, api) {
342
+ return finish(await grep(await cwdOf(api), args));
343
+ },
344
+ });
345
+ return {
346
+ tools: [findTool, grepTool],
347
+ close: destroy,
348
+ indexCwd: () => holder?.cwd,
349
+ status: () => probeSearch({ rg, loadFff: deps.loadFff }),
350
+ };
351
+ }