@kolisachint/hoocode-agent 0.4.91 → 0.4.93
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/CHANGELOG.md +39 -0
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-frontmatter.d.ts.map +1 -1
- package/dist/core/agent-frontmatter.js +3 -0
- package/dist/core/agent-frontmatter.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -4
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/docedit.d.ts +2 -0
- package/dist/core/tools/docedit.d.ts.map +1 -1
- package/dist/core/tools/docedit.js +35 -7
- package/dist/core/tools/docedit.js.map +1 -1
- package/dist/core/tools/docgrep.d.ts +28 -0
- package/dist/core/tools/docgrep.d.ts.map +1 -0
- package/dist/core/tools/docgrep.js +106 -0
- package/dist/core/tools/docgrep.js.map +1 -0
- package/dist/core/tools/docpeek.d.ts +25 -0
- package/dist/core/tools/docpeek.d.ts.map +1 -0
- package/dist/core/tools/docpeek.js +112 -0
- package/dist/core/tools/docpeek.js.map +1 -0
- package/dist/core/tools/docread.d.ts.map +1 -1
- package/dist/core/tools/docread.js +4 -15
- package/dist/core/tools/docread.js.map +1 -1
- package/dist/core/tools/docscan.d.ts +29 -0
- package/dist/core/tools/docscan.d.ts.map +1 -0
- package/dist/core/tools/docscan.js +110 -0
- package/dist/core/tools/docscan.js.map +1 -0
- package/dist/core/tools/docwrite.d.ts.map +1 -1
- package/dist/core/tools/docwrite.js +18 -8
- package/dist/core/tools/docwrite.js.map +1 -1
- package/dist/core/tools/filetools-shared.d.ts +108 -3
- package/dist/core/tools/filetools-shared.d.ts.map +1 -1
- package/dist/core/tools/filetools-shared.js +165 -5
- package/dist/core/tools/filetools-shared.js.map +1 -1
- package/dist/core/tools/index.d.ts +10 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +27 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -3
- package/dist/main.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
|
@@ -108,6 +108,68 @@ export const patchOpsSchema = Type.Array(patchOpSchema, {
|
|
|
108
108
|
export function toPatch(ops) {
|
|
109
109
|
return { patch: ops };
|
|
110
110
|
}
|
|
111
|
+
/** Find a node by id anywhere in a (recursive) structure tree. */
|
|
112
|
+
export function findNodeById(nodes, id) {
|
|
113
|
+
for (const node of nodes) {
|
|
114
|
+
if (node.id === id)
|
|
115
|
+
return node;
|
|
116
|
+
if (node.children) {
|
|
117
|
+
const hit = findNodeById(node.children, id);
|
|
118
|
+
if (hit)
|
|
119
|
+
return hit;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extract the target node id from a patch op pointer. Returns undefined for ops
|
|
126
|
+
* that reference a node by anchor (`add`) rather than a `/structure/<id>/...`
|
|
127
|
+
* path. Pointer shapes: `/structure/<id>`, `/structure/<id>/text`,
|
|
128
|
+
* `/structure/<id>/attrs/<name>`.
|
|
129
|
+
*/
|
|
130
|
+
export function patchOpNodeId(op) {
|
|
131
|
+
if (op.op === "add")
|
|
132
|
+
return op.after ?? op.before;
|
|
133
|
+
const parts = op.path.split("/");
|
|
134
|
+
// ["", "structure", "<id>", ...]
|
|
135
|
+
return parts[1] === "structure" ? parts[2] : undefined;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Validate that every node id referenced by `ops` still exists in `structure`.
|
|
139
|
+
* Returns the ids that are missing (empty array means the patch is applicable to
|
|
140
|
+
* this extract). Used to detect when a patch was authored against a stale
|
|
141
|
+
* extract — e.g. after an external tool rewrote the document.
|
|
142
|
+
*/
|
|
143
|
+
export function findMissingPatchIds(ops, structure) {
|
|
144
|
+
const missing = [];
|
|
145
|
+
for (const op of ops) {
|
|
146
|
+
const id = patchOpNodeId(op);
|
|
147
|
+
if (id && !findNodeById(structure, id))
|
|
148
|
+
missing.push(id);
|
|
149
|
+
}
|
|
150
|
+
return missing;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Render id-addressed node lines (`#id <tag attrs> :: "text"`), the compact
|
|
154
|
+
* view the model reads and patches against. Shared by DocRead's envelope render
|
|
155
|
+
* and DocPeek's hydrated-block render so both speak the exact same dialect.
|
|
156
|
+
*/
|
|
157
|
+
export function renderDocNodeLines(nodes) {
|
|
158
|
+
const lines = [];
|
|
159
|
+
const walk = (ns, depth) => {
|
|
160
|
+
for (const node of ns) {
|
|
161
|
+
const indent = " ".repeat(depth);
|
|
162
|
+
const idPart = node.id ? `#${node.id} ` : "";
|
|
163
|
+
const attrs = node.attrs?.length ? ` ${node.attrs.map((a) => `${a.name}="${a.value}"`).join(" ")}` : "";
|
|
164
|
+
const text = node.text !== undefined ? ` :: ${JSON.stringify(node.text)}` : "";
|
|
165
|
+
lines.push(`${indent}${idPart}<${node.tag}${attrs}>${text}`);
|
|
166
|
+
if (node.children?.length)
|
|
167
|
+
walk(node.children, depth + 1);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
walk(nodes, 0);
|
|
171
|
+
return lines;
|
|
172
|
+
}
|
|
111
173
|
// ============================================================================
|
|
112
174
|
// Binary runner + working directory
|
|
113
175
|
// ============================================================================
|
|
@@ -218,18 +280,58 @@ export function invalidateExtractRecord(absolutePath) {
|
|
|
218
280
|
records.delete(absolutePath);
|
|
219
281
|
}
|
|
220
282
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
283
|
+
* Thrown when a patch references node ids that are absent from the current
|
|
284
|
+
* extract — typically because the document was rewritten out-of-band (e.g. by a
|
|
285
|
+
* script) after the ids were read, or the patch was authored against an older
|
|
286
|
+
* extract. Carries the freshly re-extracted envelope so the caller can surface
|
|
287
|
+
* current ids to the agent without forcing a separate DocRead.
|
|
224
288
|
*/
|
|
225
|
-
export
|
|
289
|
+
export class StalePatchError extends Error {
|
|
290
|
+
envelope;
|
|
291
|
+
missingIds;
|
|
292
|
+
constructor(envelope, missingIds) {
|
|
293
|
+
super(`patch references ${missingIds.length} node id${missingIds.length === 1 ? "" : "s"} that no longer exist ` +
|
|
294
|
+
`in ${basename(envelope.source.path)} (${missingIds.slice(0, 5).join(", ")}` +
|
|
295
|
+
`${missingIds.length > 5 ? ", …" : ""}). The document was re-extracted; re-issue the patch against the ids below.`);
|
|
296
|
+
this.name = "StalePatchError";
|
|
297
|
+
this.envelope = envelope;
|
|
298
|
+
this.missingIds = missingIds;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Return a valid cached extract for `absolutePath`, re-extracting automatically
|
|
303
|
+
* when the cache is missing or stale (e.g. the source changed on disk since the
|
|
304
|
+
* last extract). This keeps DocEdit/DocWrite usable after an out-of-band write
|
|
305
|
+
* without forcing the agent to call DocRead again.
|
|
306
|
+
*/
|
|
307
|
+
export async function ensureExtractRecord(absolutePath, cwd, signal, options) {
|
|
308
|
+
const existing = getExtractRecord(absolutePath);
|
|
309
|
+
if (existing)
|
|
310
|
+
return existing;
|
|
311
|
+
invalidateExtractRecord(absolutePath);
|
|
312
|
+
await extractDocument(absolutePath, cwd, signal, { timeoutSecs: options?.timeoutSecs });
|
|
226
313
|
const record = getExtractRecord(absolutePath);
|
|
227
314
|
if (!record) {
|
|
228
|
-
throw new Error(`
|
|
315
|
+
throw new Error(`failed to extract ${basename(absolutePath)} — the document tools could not read it`);
|
|
229
316
|
}
|
|
317
|
+
return record;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Apply `patch` to a document, writing the reconstructed bytes to `outPath`.
|
|
321
|
+
* Auto-extracts when the cache is missing or stale (so an out-of-band rewrite no
|
|
322
|
+
* longer forces a manual DocRead), then validates that the patch's node ids
|
|
323
|
+
* still exist in the current extract. A mismatch throws {@link StalePatchError}
|
|
324
|
+
* carrying the fresh envelope so the caller can show current ids.
|
|
325
|
+
*/
|
|
326
|
+
export async function reconstructDocument(absolutePath, patch, outPath, cwd, signal, options) {
|
|
327
|
+
const record = await ensureExtractRecord(absolutePath, cwd, signal, options);
|
|
230
328
|
if (!record.envelope.writable) {
|
|
231
329
|
throw new Error(`${basename(absolutePath)} is read-only (fidelity ${record.envelope.fidelity}); it cannot be edited`);
|
|
232
330
|
}
|
|
331
|
+
const missingIds = findMissingPatchIds(patch.patch, record.envelope.structure);
|
|
332
|
+
if (missingIds.length > 0) {
|
|
333
|
+
throw new StalePatchError(record.envelope, missingIds);
|
|
334
|
+
}
|
|
233
335
|
const binaryPath = await resolveBinary();
|
|
234
336
|
const patchPath = join(getWorkDir(), pathKey(absolutePath), "patch.json");
|
|
235
337
|
writeFileSync(patchPath, JSON.stringify(patch), "utf8");
|
|
@@ -240,4 +342,62 @@ export async function reconstructDocument(absolutePath, patch, outPath, cwd, sig
|
|
|
240
342
|
rmSync(patchPath, { force: true });
|
|
241
343
|
}
|
|
242
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Run a stdout-oriented filetools subcommand (scan/grep/read) and parse its
|
|
347
|
+
* single pretty-JSON object. These do not write files or populate the extract
|
|
348
|
+
* cache, so they are safe to interleave with a pending DocEdit/DocWrite.
|
|
349
|
+
*/
|
|
350
|
+
async function runFiletoolsJson(subcommand, args, cwd, signal, timeoutSecs) {
|
|
351
|
+
const binaryPath = await resolveBinary();
|
|
352
|
+
if (signal?.aborted)
|
|
353
|
+
throw new Error("Operation aborted");
|
|
354
|
+
const spawnTimeoutMs = (timeoutSecs + 5) * 1000;
|
|
355
|
+
const result = await execCommand(binaryPath, [subcommand, ...args], cwd, { signal, timeout: spawnTimeoutMs });
|
|
356
|
+
if (signal?.aborted)
|
|
357
|
+
throw new Error("Operation aborted");
|
|
358
|
+
if (result.killed)
|
|
359
|
+
throw new Error(`filetools ${subcommand} timed out after ${timeoutSecs}s`);
|
|
360
|
+
if (result.code !== 0) {
|
|
361
|
+
const stderr = result.stderr.trim();
|
|
362
|
+
throw new Error(stderr || `filetools ${subcommand} exited with code ${result.code}`);
|
|
363
|
+
}
|
|
364
|
+
const stdout = result.stdout.trim();
|
|
365
|
+
if (!stdout)
|
|
366
|
+
throw new Error(`filetools ${subcommand} produced no output`);
|
|
367
|
+
try {
|
|
368
|
+
return JSON.parse(stdout);
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
throw new Error(`filetools ${subcommand} produced malformed JSON output`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/** Scan a document into a paginated manifest of block previews (no hydration). */
|
|
375
|
+
export async function scanDocument(absolutePath, cwd, signal, options) {
|
|
376
|
+
const args = ["--input", absolutePath];
|
|
377
|
+
if (options?.offset !== undefined)
|
|
378
|
+
args.push("--offset", String(options.offset));
|
|
379
|
+
if (options?.limit !== undefined)
|
|
380
|
+
args.push("--limit", String(options.limit));
|
|
381
|
+
return runFiletoolsJson("scan", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);
|
|
382
|
+
}
|
|
383
|
+
/** Locate blocks containing `pattern` (literal substring) without hydrating the doc. */
|
|
384
|
+
export async function grepDocument(absolutePath, pattern, cwd, signal, options) {
|
|
385
|
+
const args = ["--input", absolutePath, "--pattern", pattern];
|
|
386
|
+
if (options?.ignoreCase)
|
|
387
|
+
args.push("--ignore-case");
|
|
388
|
+
if (options?.limit !== undefined)
|
|
389
|
+
args.push("--limit", String(options.limit));
|
|
390
|
+
return runFiletoolsJson("grep", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);
|
|
391
|
+
}
|
|
392
|
+
/** Hydrate specific blocks by id (or a paginated slice when no ids are given). */
|
|
393
|
+
export async function readDocumentBlocks(absolutePath, cwd, signal, options) {
|
|
394
|
+
const args = ["--input", absolutePath];
|
|
395
|
+
for (const id of options?.ids ?? [])
|
|
396
|
+
args.push("--id", id);
|
|
397
|
+
if (options?.offset !== undefined)
|
|
398
|
+
args.push("--offset", String(options.offset));
|
|
399
|
+
if (options?.limit !== undefined)
|
|
400
|
+
args.push("--limit", String(options.limit));
|
|
401
|
+
return runFiletoolsJson("read", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);
|
|
402
|
+
}
|
|
243
403
|
//# sourceMappingURL=filetools-shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filetools-shared.js","sourceRoot":"","sources":["../../../src/core/tools/filetools-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,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AAM,IAAI,KAAK,CACd,6BAA6B,QAAQ,CAAC,YAAY,CAAC,qDAAmD,CACtG,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACd,GAAG,QAAQ,CAAC,YAAY,CAAC,2BAA2B,MAAM,CAAC,QAAQ,CAAC,QAAQ,wBAAwB,CACpG,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;IAC1E,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,IAAI,CAAC;QACJ,MAAM,YAAY,CACjB,UAAU,EACV,aAAa,EACb,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,EACvG,GAAG,EACH,MAAM,EACN,OAAO,EAAE,WAAW,IAAI,8BAA8B,CACtD,CAAC;IACH,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,CAAC;AAAA,CACD","sourcesContent":["/**\n * Shared plumbing for the `DocRead` / `DocEdit` / `DocWrite` tools.\n *\n * All three shell out to the `filetools` binary (extract / reconstruct\n * subcommands, resolved/downloaded via {@link ensureTool}) to losslessly\n * project structured/binary documents (XML, drawio, OOXML, PDF) into editable,\n * id-addressed JSON and reconstruct them after id-based patches.\n *\n * Unlike webtools, the filetools CLI is file-oriented, not stdout-oriented:\n * `extract` writes the envelope JSON to `--out` and the sidecar id-map next to\n * it, emitting only a human status line on stderr. This module therefore:\n * - owns a per-process working directory where envelopes + sidecars live,\n * - runs extract/reconstruct and reads the resulting files back,\n * - keeps a small cache mapping a source file to its extracted envelope +\n * sidecar, so a DocRead can be followed by a DocEdit/DocWrite (the stateful\n * extract -> patch -> reconstruct flow), and\n * - exposes the locked JSON wire types mirroring the Rust `model.rs`/`patch.rs`.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { basename, join } from \"node:path\";\nimport { type Static, Type } from \"typebox\";\nimport { APP_NAME } from \"../../config.js\";\nimport { ensureTool } from \"../../utils/tools-manager.js\";\nimport { execCommand } from \"../exec.js\";\n\n/** Default timeout (seconds) for a single filetools invocation. */\nexport const FILETOOLS_DEFAULT_TIMEOUT_SECS = 30;\n\n/**\n * Soft token ceiling for a single DocRead render. The filetools binary has no\n * pagination, so a dense file (e.g. a large spreadsheet) can project into a\n * huge id-addressed dump that floods the model context and burns tokens. We\n * cannot make the extract itself smaller without the binary's help, so DocRead\n * truncates the rendered view to roughly this budget and tells the model how to\n * narrow it (readonly projection, a smaller/targeted file, or direct edits).\n */\nexport const DOCREAD_MAX_RENDER_TOKENS = 10000;\n\n/** Rough token estimate (chars/4), matching the agent's compaction heuristic. */\nexport function estimateTextTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\n/**\n * Truncate rendered envelope lines to roughly `maxTokens`, keeping whole lines.\n * Returns the kept text plus how many lines were dropped (0 when nothing was\n * truncated).\n */\nexport function truncateRenderToTokenBudget(\n\tlines: string[],\n\tmaxTokens: number = DOCREAD_MAX_RENDER_TOKENS,\n): { text: string; droppedLines: number } {\n\tconst full = lines.join(\"\\n\");\n\tif (estimateTextTokens(full) <= maxTokens) {\n\t\treturn { text: full, droppedLines: 0 };\n\t}\n\tconst budgetChars = maxTokens * 4;\n\tconst kept: string[] = [];\n\tlet used = 0;\n\tfor (const line of lines) {\n\t\tconst next = used + line.length + 1; // + newline\n\t\tif (next > budgetChars && kept.length > 0) break;\n\t\tkept.push(line);\n\t\tused = next;\n\t}\n\treturn { text: kept.join(\"\\n\"), droppedLines: lines.length - kept.length };\n}\n\n// ============================================================================\n// Wire types (locked against `filetools` model.rs / patch.rs)\n// ============================================================================\n\n/** How faithfully a handler can reconstruct a file after edits. */\nexport type Fidelity = \"lossless\" | \"in_place_text\" | \"read_only\";\n\nexport interface DocSource {\n\tpath: string;\n\t/** Logical format, e.g. \"xml\", \"drawio\". */\n\ttype: string;\n\t/** `sha256:<hex>` of the original bytes. */\n\thash: string;\n}\n\nexport interface DocAttr {\n\tname: string;\n\tvalue: string;\n}\n\nexport interface DocNode {\n\tid: string;\n\ttag: string;\n\tattrs?: DocAttr[];\n\ttext?: string;\n\tchildren?: DocNode[];\n}\n\n/** The extract output handed to the model. Mirrors the Rust `Envelope`. */\nexport interface Envelope {\n\tversion: string;\n\tsource: DocSource;\n\tfidelity: Fidelity;\n\twritable: boolean;\n\tidmap_ref?: string;\n\tstructure: DocNode[];\n}\n\n/** A new element for an `add` op (text-only content, v1). */\nexport interface NewElement {\n\ttag: string;\n\tattrs?: DocAttr[];\n\ttext?: string;\n}\n\n/**\n * One patch operation. RFC-6902 vocabulary, id-based pointers\n * (`/structure/<id>/text`, `/structure/<id>/attrs/<name>`), per the filetools\n * patch format.\n */\nexport type PatchOp =\n\t| { op: \"test\"; path: string; hash: string }\n\t| { op: \"replace\"; path: string; value: string }\n\t| { op: \"add\"; after?: string; before?: string; value: NewElement }\n\t| { op: \"remove\"; path: string };\n\nexport interface Patch {\n\tpatch: PatchOp[];\n}\n\n// ----------------------------------------------------------------------------\n// TypeBox schema for the model-facing patch input (shared by DocEdit/DocWrite)\n// ----------------------------------------------------------------------------\n\nconst attrSchema = Type.Object({\n\tname: Type.String(),\n\tvalue: Type.String(),\n});\n\nconst newElementSchema = Type.Object({\n\ttag: Type.String({ description: 'Element tag name, e.g. \"w:p\" or \"mxCell\".' }),\n\tattrs: Type.Optional(Type.Array(attrSchema, { description: \"Attributes in document order.\" })),\n\ttext: Type.Optional(Type.String({ description: \"Inline text content (text-only elements, v1).\" })),\n});\n\nconst patchOpSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"test\"),\n\t\t\tpath: Type.String({ description: \"Pointer `/structure/<id>` (or /text, /attrs/<name>) to guard.\" }),\n\t\t\thash: Type.String({ description: \"Expected content hash of the target node.\" }),\n\t\t},\n\t\t{ description: \"Optimistic guard: assert the target node's content hash before mutating.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"replace\"),\n\t\t\tpath: Type.String({\n\t\t\t\tdescription: \"`/structure/<id>/text` for element text, or `/structure/<id>/attrs/<name>` for an attribute.\",\n\t\t\t}),\n\t\t\tvalue: Type.String({ description: \"New text or attribute value.\" }),\n\t\t},\n\t\t{ description: \"Replace an element's text or an attribute value.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"add\"),\n\t\t\tafter: Type.Optional(Type.String({ description: \"Anchor node id to insert AFTER.\" })),\n\t\t\tbefore: Type.Optional(Type.String({ description: \"Anchor node id to insert BEFORE.\" })),\n\t\t\tvalue: newElementSchema,\n\t\t},\n\t\t{ description: \"Insert a new element next to an anchor. Provide exactly one of `after`/`before`.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"remove\"),\n\t\t\tpath: Type.String({ description: \"Pointer `/structure/<id>` of the element to delete.\" }),\n\t\t},\n\t\t{ description: \"Delete an element and all its bytes.\" },\n\t),\n]);\n\n/**\n * The model-facing patch parameter: an array of id-based RFC-6902 ops, matching\n * the filetools patch wire format. Shared by DocEdit and DocWrite.\n */\nexport const patchOpsSchema = Type.Array(patchOpSchema, {\n\tdescription:\n\t\t\"Ordered id-based patch ops (test/replace/add/remove) targeting node ids from a prior DocRead. Applied atomically.\",\n});\n\nexport type PatchOpsInput = Static<typeof patchOpsSchema>;\n\n/** Wrap the model-facing ops array into the binary's `{ patch: [...] }` envelope. */\nexport function toPatch(ops: PatchOpsInput): Patch {\n\treturn { patch: ops as PatchOp[] };\n}\n\n// ============================================================================\n// Binary runner + working directory\n// ============================================================================\n\nconst BINARY_MISSING_MESSAGE =\n\t\"filetools binary unavailable and could not be downloaded — the document tools require the `filetools` CLI on PATH or a published release for this platform\";\n\n/** Lazily-created per-process working directory for envelopes + sidecars. */\nlet workDir: string | undefined;\nfunction getWorkDir(): string {\n\tif (workDir) return workDir;\n\tconst base = join(tmpdir(), `${APP_NAME}-filetools`);\n\tmkdirSync(base, { recursive: true });\n\tworkDir = mkdtempSync(join(base, \"doc-\"));\n\treturn workDir;\n}\n\n/** Short, filesystem-safe key for a source path (used to name its subdir). */\nfunction pathKey(absolutePath: string): string {\n\treturn createHash(\"sha256\").update(absolutePath).digest(\"hex\").slice(0, 16);\n}\n\nasync function resolveBinary(): Promise<string> {\n\tconst binaryPath = await ensureTool(\"filetools\", true);\n\tif (!binaryPath) throw new Error(BINARY_MISSING_MESSAGE);\n\treturn binaryPath;\n}\n\nasync function runFiletools(\n\tbinaryPath: string,\n\tsubcommand: \"extract\" | \"reconstruct\",\n\targs: string[],\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\ttimeoutSecs: number,\n): Promise<string> {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tconst spawnTimeoutMs = (timeoutSecs + 5) * 1000;\n\tconst result = await execCommand(binaryPath, [subcommand, ...args], cwd, { signal, timeout: spawnTimeoutMs });\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tif (result.killed) throw new Error(`filetools ${subcommand} timed out after ${timeoutSecs}s`);\n\tif (result.code !== 0) {\n\t\tconst stderr = result.stderr.trim();\n\t\tthrow new Error(stderr || `filetools ${subcommand} exited with code ${result.code}`);\n\t}\n\t// Status goes to stderr; callers read the produced files, not stdout.\n\treturn result.stderr.trim();\n}\n\n// ============================================================================\n// Extraction cache (source file -> extracted envelope + sidecar)\n// ============================================================================\n\nexport interface ExtractRecord {\n\t/** Absolute path of the source document. */\n\tsource: string;\n\t/** Path to the envelope JSON in the working directory. */\n\tenvelopePath: string;\n\t/** Parsed envelope (also returned to the model on DocRead). */\n\tenvelope: Envelope;\n\t/** The source's stat signature at extract time, to detect drift cheaply. */\n\tsignature: string;\n}\n\nconst records = new Map<string, ExtractRecord>();\n\nfunction statSignature(absolutePath: string): string {\n\ttry {\n\t\tconst st = statSync(absolutePath);\n\t\treturn `${st.mtimeMs}:${st.size}`;\n\t} catch {\n\t\treturn \"absent\";\n\t}\n}\n\n/**\n * Extract `absolutePath` to an envelope (+ sidecar) in the working directory,\n * cache the result keyed by the source path, and return the parsed envelope.\n *\n * `readonly` strips ids for a smaller, analysis-only projection that cannot be\n * reconstructed (DocRead's default-off mode).\n */\nexport async function extractDocument(\n\tabsolutePath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { readonly?: boolean; timeoutSecs?: number },\n): Promise<Envelope> {\n\tconst binaryPath = await resolveBinary();\n\tconst dir = join(getWorkDir(), pathKey(absolutePath));\n\tmkdirSync(dir, { recursive: true });\n\tconst envelopePath = join(dir, \"envelope.json\");\n\n\tconst args = [\"--input\", absolutePath, \"--out\", envelopePath];\n\tif (options?.readonly) args.push(\"--readonly\");\n\tawait runFiletools(binaryPath, \"extract\", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);\n\n\tconst envelope = readEnvelope(envelopePath);\n\tif (!options?.readonly) {\n\t\trecords.set(absolutePath, {\n\t\t\tsource: absolutePath,\n\t\t\tenvelopePath,\n\t\t\tenvelope,\n\t\t\tsignature: statSignature(absolutePath),\n\t\t});\n\t}\n\treturn envelope;\n}\n\nfunction readEnvelope(envelopePath: string): Envelope {\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(envelopePath, \"utf8\");\n\t} catch {\n\t\tthrow new Error(\"filetools extract produced no envelope\");\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as Envelope;\n\t} catch {\n\t\tthrow new Error(\"filetools extract produced a malformed envelope\");\n\t}\n}\n\n/** Look up a cached extraction for `absolutePath`, if one is still valid. */\nexport function getExtractRecord(absolutePath: string): ExtractRecord | undefined {\n\tconst record = records.get(absolutePath);\n\tif (!record) return undefined;\n\t// Drop a stale record if the source changed since extract; reconstruct would\n\t// fail the binary's hash-drift guard anyway, but a clearer error is better.\n\tif (record.signature !== statSignature(absolutePath)) {\n\t\trecords.delete(absolutePath);\n\t\treturn undefined;\n\t}\n\treturn record;\n}\n\n/** Drop any cached extraction for `absolutePath`. */\nexport function invalidateExtractRecord(absolutePath: string): void {\n\trecords.delete(absolutePath);\n}\n\n/**\n * Apply `patch` to a previously-extracted document, writing the reconstructed\n * bytes to `outPath`. Requires a prior {@link extractDocument} (the stateful\n * flow): the cached envelope + sidecar carry the id-map reconstruct needs.\n */\nexport async function reconstructDocument(\n\tabsolutePath: string,\n\tpatch: Patch,\n\toutPath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { timeoutSecs?: number },\n): Promise<void> {\n\tconst record = getExtractRecord(absolutePath);\n\tif (!record) {\n\t\tthrow new Error(\n\t\t\t`no extracted envelope for ${basename(absolutePath)} — run DocRead on it first, then DocEdit/DocWrite`,\n\t\t);\n\t}\n\tif (!record.envelope.writable) {\n\t\tthrow new Error(\n\t\t\t`${basename(absolutePath)} is read-only (fidelity ${record.envelope.fidelity}); it cannot be edited`,\n\t\t);\n\t}\n\n\tconst binaryPath = await resolveBinary();\n\tconst patchPath = join(getWorkDir(), pathKey(absolutePath), \"patch.json\");\n\twriteFileSync(patchPath, JSON.stringify(patch), \"utf8\");\n\ttry {\n\t\tawait runFiletools(\n\t\t\tbinaryPath,\n\t\t\t\"reconstruct\",\n\t\t\t[\"--envelope\", record.envelopePath, \"--patch\", patchPath, \"--out\", outPath, \"--original\", absolutePath],\n\t\t\tcwd,\n\t\t\tsignal,\n\t\t\toptions?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS,\n\t\t);\n\t} finally {\n\t\trmSync(patchPath, { force: true });\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"filetools-shared.js","sourceRoot":"","sources":["../../../src/core/tools/filetools-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE/C,iFAAiF;AACjF,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAU;IACxD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAAA,CAClC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAC1C,KAAe,EACf,SAAS,GAAW,yBAAyB,EACJ;IACzC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;QAC3C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IACxC,CAAC;IAC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AS,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,OAAO,EAAE,UAAU;QAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACpD,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,OAAO,gBAAgB,CAAW,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,IAAI,8BAA8B,CAAC,CAAC;AAAA,CACrH;AAED,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,YAAoB,EACpB,GAAW,EACX,MAA+B,EAC/B,OAAmF,EAC/D;IACpB,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACvC,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,GAAG,IAAI,EAAE;QAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3D,IAAI,OAAO,EAAE,MAAM,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,OAAO,gBAAgB,CAAW,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,IAAI,8BAA8B,CAAC,CAAC;AAAA,CACrH","sourcesContent":["/**\n * Shared plumbing for the `DocRead` / `DocEdit` / `DocWrite` tools.\n *\n * All three shell out to the `filetools` binary (extract / reconstruct\n * subcommands, resolved/downloaded via {@link ensureTool}) to losslessly\n * project structured/binary documents (XML, drawio, OOXML, PDF) into editable,\n * id-addressed JSON and reconstruct them after id-based patches.\n *\n * Unlike webtools, the filetools CLI is file-oriented, not stdout-oriented:\n * `extract` writes the envelope JSON to `--out` and the sidecar id-map next to\n * it, emitting only a human status line on stderr. This module therefore:\n * - owns a per-process working directory where envelopes + sidecars live,\n * - runs extract/reconstruct and reads the resulting files back,\n * - keeps a small cache mapping a source file to its extracted envelope +\n * sidecar, so a DocRead can be followed by a DocEdit/DocWrite (the stateful\n * extract -> patch -> reconstruct flow), and\n * - exposes the locked JSON wire types mirroring the Rust `model.rs`/`patch.rs`.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { basename, join } from \"node:path\";\nimport { type Static, Type } from \"typebox\";\nimport { APP_NAME } from \"../../config.js\";\nimport { ensureTool } from \"../../utils/tools-manager.js\";\nimport { execCommand } from \"../exec.js\";\n\n/** Default timeout (seconds) for a single filetools invocation. */\nexport const FILETOOLS_DEFAULT_TIMEOUT_SECS = 30;\n\n/**\n * Soft token ceiling for a single DocRead render. The filetools binary has no\n * pagination, so a dense file (e.g. a large spreadsheet) can project into a\n * huge id-addressed dump that floods the model context and burns tokens. We\n * cannot make the extract itself smaller without the binary's help, so DocRead\n * truncates the rendered view to roughly this budget and tells the model how to\n * narrow it (readonly projection, a smaller/targeted file, or direct edits).\n */\nexport const DOCREAD_MAX_RENDER_TOKENS = 10000;\n\n/** Rough token estimate (chars/4), matching the agent's compaction heuristic. */\nexport function estimateTextTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\n/**\n * Truncate rendered envelope lines to roughly `maxTokens`, keeping whole lines.\n * Returns the kept text plus how many lines were dropped (0 when nothing was\n * truncated).\n */\nexport function truncateRenderToTokenBudget(\n\tlines: string[],\n\tmaxTokens: number = DOCREAD_MAX_RENDER_TOKENS,\n): { text: string; droppedLines: number } {\n\tconst full = lines.join(\"\\n\");\n\tif (estimateTextTokens(full) <= maxTokens) {\n\t\treturn { text: full, droppedLines: 0 };\n\t}\n\tconst budgetChars = maxTokens * 4;\n\tconst kept: string[] = [];\n\tlet used = 0;\n\tfor (const line of lines) {\n\t\tconst next = used + line.length + 1; // + newline\n\t\tif (next > budgetChars && kept.length > 0) break;\n\t\tkept.push(line);\n\t\tused = next;\n\t}\n\treturn { text: kept.join(\"\\n\"), droppedLines: lines.length - kept.length };\n}\n\n// ============================================================================\n// Wire types (locked against `filetools` model.rs / patch.rs)\n// ============================================================================\n\n/** How faithfully a handler can reconstruct a file after edits. */\nexport type Fidelity = \"lossless\" | \"in_place_text\" | \"read_only\";\n\nexport interface DocSource {\n\tpath: string;\n\t/** Logical format, e.g. \"xml\", \"drawio\". */\n\ttype: string;\n\t/** `sha256:<hex>` of the original bytes. */\n\thash: string;\n}\n\nexport interface DocAttr {\n\tname: string;\n\tvalue: string;\n}\n\nexport interface DocNode {\n\tid: string;\n\ttag: string;\n\tattrs?: DocAttr[];\n\ttext?: string;\n\tchildren?: DocNode[];\n}\n\n/** The extract output handed to the model. Mirrors the Rust `Envelope`. */\nexport interface Envelope {\n\tversion: string;\n\tsource: DocSource;\n\tfidelity: Fidelity;\n\twritable: boolean;\n\tidmap_ref?: string;\n\tstructure: DocNode[];\n}\n\n/** A new element for an `add` op (text-only content, v1). */\nexport interface NewElement {\n\ttag: string;\n\tattrs?: DocAttr[];\n\ttext?: string;\n}\n\n/**\n * One patch operation. RFC-6902 vocabulary, id-based pointers\n * (`/structure/<id>/text`, `/structure/<id>/attrs/<name>`), per the filetools\n * patch format.\n */\nexport type PatchOp =\n\t| { op: \"test\"; path: string; hash: string }\n\t| { op: \"replace\"; path: string; value: string }\n\t| { op: \"add\"; after?: string; before?: string; value: NewElement }\n\t| { op: \"remove\"; path: string };\n\nexport interface Patch {\n\tpatch: PatchOp[];\n}\n\n// ----------------------------------------------------------------------------\n// TypeBox schema for the model-facing patch input (shared by DocEdit/DocWrite)\n// ----------------------------------------------------------------------------\n\nconst attrSchema = Type.Object({\n\tname: Type.String(),\n\tvalue: Type.String(),\n});\n\nconst newElementSchema = Type.Object({\n\ttag: Type.String({ description: 'Element tag name, e.g. \"w:p\" or \"mxCell\".' }),\n\tattrs: Type.Optional(Type.Array(attrSchema, { description: \"Attributes in document order.\" })),\n\ttext: Type.Optional(Type.String({ description: \"Inline text content (text-only elements, v1).\" })),\n});\n\nconst patchOpSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"test\"),\n\t\t\tpath: Type.String({ description: \"Pointer `/structure/<id>` (or /text, /attrs/<name>) to guard.\" }),\n\t\t\thash: Type.String({ description: \"Expected content hash of the target node.\" }),\n\t\t},\n\t\t{ description: \"Optimistic guard: assert the target node's content hash before mutating.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"replace\"),\n\t\t\tpath: Type.String({\n\t\t\t\tdescription: \"`/structure/<id>/text` for element text, or `/structure/<id>/attrs/<name>` for an attribute.\",\n\t\t\t}),\n\t\t\tvalue: Type.String({ description: \"New text or attribute value.\" }),\n\t\t},\n\t\t{ description: \"Replace an element's text or an attribute value.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"add\"),\n\t\t\tafter: Type.Optional(Type.String({ description: \"Anchor node id to insert AFTER.\" })),\n\t\t\tbefore: Type.Optional(Type.String({ description: \"Anchor node id to insert BEFORE.\" })),\n\t\t\tvalue: newElementSchema,\n\t\t},\n\t\t{ description: \"Insert a new element next to an anchor. Provide exactly one of `after`/`before`.\" },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"remove\"),\n\t\t\tpath: Type.String({ description: \"Pointer `/structure/<id>` of the element to delete.\" }),\n\t\t},\n\t\t{ description: \"Delete an element and all its bytes.\" },\n\t),\n]);\n\n/**\n * The model-facing patch parameter: an array of id-based RFC-6902 ops, matching\n * the filetools patch wire format. Shared by DocEdit and DocWrite.\n */\nexport const patchOpsSchema = Type.Array(patchOpSchema, {\n\tdescription:\n\t\t\"Ordered id-based patch ops (test/replace/add/remove) targeting node ids from a prior DocRead. Applied atomically.\",\n});\n\nexport type PatchOpsInput = Static<typeof patchOpsSchema>;\n\n/** Wrap the model-facing ops array into the binary's `{ patch: [...] }` envelope. */\nexport function toPatch(ops: PatchOpsInput): Patch {\n\treturn { patch: ops as PatchOp[] };\n}\n\n/** Find a node by id anywhere in a (recursive) structure tree. */\nexport function findNodeById(nodes: DocNode[], id: string): DocNode | undefined {\n\tfor (const node of nodes) {\n\t\tif (node.id === id) return node;\n\t\tif (node.children) {\n\t\t\tconst hit = findNodeById(node.children, id);\n\t\t\tif (hit) return hit;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Extract the target node id from a patch op pointer. Returns undefined for ops\n * that reference a node by anchor (`add`) rather than a `/structure/<id>/...`\n * path. Pointer shapes: `/structure/<id>`, `/structure/<id>/text`,\n * `/structure/<id>/attrs/<name>`.\n */\nexport function patchOpNodeId(op: PatchOp): string | undefined {\n\tif (op.op === \"add\") return op.after ?? op.before;\n\tconst parts = op.path.split(\"/\");\n\t// [\"\", \"structure\", \"<id>\", ...]\n\treturn parts[1] === \"structure\" ? parts[2] : undefined;\n}\n\n/**\n * Validate that every node id referenced by `ops` still exists in `structure`.\n * Returns the ids that are missing (empty array means the patch is applicable to\n * this extract). Used to detect when a patch was authored against a stale\n * extract — e.g. after an external tool rewrote the document.\n */\nexport function findMissingPatchIds(ops: PatchOp[], structure: DocNode[]): string[] {\n\tconst missing: string[] = [];\n\tfor (const op of ops) {\n\t\tconst id = patchOpNodeId(op);\n\t\tif (id && !findNodeById(structure, id)) missing.push(id);\n\t}\n\treturn missing;\n}\n\n/**\n * Render id-addressed node lines (`#id <tag attrs> :: \"text\"`), the compact\n * view the model reads and patches against. Shared by DocRead's envelope render\n * and DocPeek's hydrated-block render so both speak the exact same dialect.\n */\nexport function renderDocNodeLines(nodes: DocNode[]): string[] {\n\tconst lines: string[] = [];\n\tconst walk = (ns: DocNode[], depth: number): void => {\n\t\tfor (const node of ns) {\n\t\t\tconst indent = \" \".repeat(depth);\n\t\t\tconst idPart = node.id ? `#${node.id} ` : \"\";\n\t\t\tconst attrs = node.attrs?.length ? ` ${node.attrs.map((a) => `${a.name}=\"${a.value}\"`).join(\" \")}` : \"\";\n\t\t\tconst text = node.text !== undefined ? ` :: ${JSON.stringify(node.text)}` : \"\";\n\t\t\tlines.push(`${indent}${idPart}<${node.tag}${attrs}>${text}`);\n\t\t\tif (node.children?.length) walk(node.children, depth + 1);\n\t\t}\n\t};\n\twalk(nodes, 0);\n\treturn lines;\n}\n\n// ============================================================================\n// Binary runner + working directory\n// ============================================================================\n\nconst BINARY_MISSING_MESSAGE =\n\t\"filetools binary unavailable and could not be downloaded — the document tools require the `filetools` CLI on PATH or a published release for this platform\";\n\n/** Lazily-created per-process working directory for envelopes + sidecars. */\nlet workDir: string | undefined;\nfunction getWorkDir(): string {\n\tif (workDir) return workDir;\n\tconst base = join(tmpdir(), `${APP_NAME}-filetools`);\n\tmkdirSync(base, { recursive: true });\n\tworkDir = mkdtempSync(join(base, \"doc-\"));\n\treturn workDir;\n}\n\n/** Short, filesystem-safe key for a source path (used to name its subdir). */\nfunction pathKey(absolutePath: string): string {\n\treturn createHash(\"sha256\").update(absolutePath).digest(\"hex\").slice(0, 16);\n}\n\nasync function resolveBinary(): Promise<string> {\n\tconst binaryPath = await ensureTool(\"filetools\", true);\n\tif (!binaryPath) throw new Error(BINARY_MISSING_MESSAGE);\n\treturn binaryPath;\n}\n\nasync function runFiletools(\n\tbinaryPath: string,\n\tsubcommand: \"extract\" | \"reconstruct\",\n\targs: string[],\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\ttimeoutSecs: number,\n): Promise<string> {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tconst spawnTimeoutMs = (timeoutSecs + 5) * 1000;\n\tconst result = await execCommand(binaryPath, [subcommand, ...args], cwd, { signal, timeout: spawnTimeoutMs });\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tif (result.killed) throw new Error(`filetools ${subcommand} timed out after ${timeoutSecs}s`);\n\tif (result.code !== 0) {\n\t\tconst stderr = result.stderr.trim();\n\t\tthrow new Error(stderr || `filetools ${subcommand} exited with code ${result.code}`);\n\t}\n\t// Status goes to stderr; callers read the produced files, not stdout.\n\treturn result.stderr.trim();\n}\n\n// ============================================================================\n// Extraction cache (source file -> extracted envelope + sidecar)\n// ============================================================================\n\nexport interface ExtractRecord {\n\t/** Absolute path of the source document. */\n\tsource: string;\n\t/** Path to the envelope JSON in the working directory. */\n\tenvelopePath: string;\n\t/** Parsed envelope (also returned to the model on DocRead). */\n\tenvelope: Envelope;\n\t/** The source's stat signature at extract time, to detect drift cheaply. */\n\tsignature: string;\n}\n\nconst records = new Map<string, ExtractRecord>();\n\nfunction statSignature(absolutePath: string): string {\n\ttry {\n\t\tconst st = statSync(absolutePath);\n\t\treturn `${st.mtimeMs}:${st.size}`;\n\t} catch {\n\t\treturn \"absent\";\n\t}\n}\n\n/**\n * Extract `absolutePath` to an envelope (+ sidecar) in the working directory,\n * cache the result keyed by the source path, and return the parsed envelope.\n *\n * `readonly` strips ids for a smaller, analysis-only projection that cannot be\n * reconstructed (DocRead's default-off mode).\n */\nexport async function extractDocument(\n\tabsolutePath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { readonly?: boolean; timeoutSecs?: number },\n): Promise<Envelope> {\n\tconst binaryPath = await resolveBinary();\n\tconst dir = join(getWorkDir(), pathKey(absolutePath));\n\tmkdirSync(dir, { recursive: true });\n\tconst envelopePath = join(dir, \"envelope.json\");\n\n\tconst args = [\"--input\", absolutePath, \"--out\", envelopePath];\n\tif (options?.readonly) args.push(\"--readonly\");\n\tawait runFiletools(binaryPath, \"extract\", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);\n\n\tconst envelope = readEnvelope(envelopePath);\n\tif (!options?.readonly) {\n\t\trecords.set(absolutePath, {\n\t\t\tsource: absolutePath,\n\t\t\tenvelopePath,\n\t\t\tenvelope,\n\t\t\tsignature: statSignature(absolutePath),\n\t\t});\n\t}\n\treturn envelope;\n}\n\nfunction readEnvelope(envelopePath: string): Envelope {\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(envelopePath, \"utf8\");\n\t} catch {\n\t\tthrow new Error(\"filetools extract produced no envelope\");\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as Envelope;\n\t} catch {\n\t\tthrow new Error(\"filetools extract produced a malformed envelope\");\n\t}\n}\n\n/** Look up a cached extraction for `absolutePath`, if one is still valid. */\nexport function getExtractRecord(absolutePath: string): ExtractRecord | undefined {\n\tconst record = records.get(absolutePath);\n\tif (!record) return undefined;\n\t// Drop a stale record if the source changed since extract; reconstruct would\n\t// fail the binary's hash-drift guard anyway, but a clearer error is better.\n\tif (record.signature !== statSignature(absolutePath)) {\n\t\trecords.delete(absolutePath);\n\t\treturn undefined;\n\t}\n\treturn record;\n}\n\n/** Drop any cached extraction for `absolutePath`. */\nexport function invalidateExtractRecord(absolutePath: string): void {\n\trecords.delete(absolutePath);\n}\n\n/**\n * Thrown when a patch references node ids that are absent from the current\n * extract — typically because the document was rewritten out-of-band (e.g. by a\n * script) after the ids were read, or the patch was authored against an older\n * extract. Carries the freshly re-extracted envelope so the caller can surface\n * current ids to the agent without forcing a separate DocRead.\n */\nexport class StalePatchError extends Error {\n\treadonly envelope: Envelope;\n\treadonly missingIds: string[];\n\tconstructor(envelope: Envelope, missingIds: string[]) {\n\t\tsuper(\n\t\t\t`patch references ${missingIds.length} node id${missingIds.length === 1 ? \"\" : \"s\"} that no longer exist ` +\n\t\t\t\t`in ${basename(envelope.source.path)} (${missingIds.slice(0, 5).join(\", \")}` +\n\t\t\t\t`${missingIds.length > 5 ? \", …\" : \"\"}). The document was re-extracted; re-issue the patch against the ids below.`,\n\t\t);\n\t\tthis.name = \"StalePatchError\";\n\t\tthis.envelope = envelope;\n\t\tthis.missingIds = missingIds;\n\t}\n}\n\n/**\n * Return a valid cached extract for `absolutePath`, re-extracting automatically\n * when the cache is missing or stale (e.g. the source changed on disk since the\n * last extract). This keeps DocEdit/DocWrite usable after an out-of-band write\n * without forcing the agent to call DocRead again.\n */\nexport async function ensureExtractRecord(\n\tabsolutePath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { timeoutSecs?: number },\n): Promise<ExtractRecord> {\n\tconst existing = getExtractRecord(absolutePath);\n\tif (existing) return existing;\n\tinvalidateExtractRecord(absolutePath);\n\tawait extractDocument(absolutePath, cwd, signal, { timeoutSecs: options?.timeoutSecs });\n\tconst record = getExtractRecord(absolutePath);\n\tif (!record) {\n\t\tthrow new Error(`failed to extract ${basename(absolutePath)} — the document tools could not read it`);\n\t}\n\treturn record;\n}\n\n/**\n * Apply `patch` to a document, writing the reconstructed bytes to `outPath`.\n * Auto-extracts when the cache is missing or stale (so an out-of-band rewrite no\n * longer forces a manual DocRead), then validates that the patch's node ids\n * still exist in the current extract. A mismatch throws {@link StalePatchError}\n * carrying the fresh envelope so the caller can show current ids.\n */\nexport async function reconstructDocument(\n\tabsolutePath: string,\n\tpatch: Patch,\n\toutPath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { timeoutSecs?: number },\n): Promise<void> {\n\tconst record = await ensureExtractRecord(absolutePath, cwd, signal, options);\n\tif (!record.envelope.writable) {\n\t\tthrow new Error(\n\t\t\t`${basename(absolutePath)} is read-only (fidelity ${record.envelope.fidelity}); it cannot be edited`,\n\t\t);\n\t}\n\tconst missingIds = findMissingPatchIds(patch.patch, record.envelope.structure);\n\tif (missingIds.length > 0) {\n\t\tthrow new StalePatchError(record.envelope, missingIds);\n\t}\n\n\tconst binaryPath = await resolveBinary();\n\tconst patchPath = join(getWorkDir(), pathKey(absolutePath), \"patch.json\");\n\twriteFileSync(patchPath, JSON.stringify(patch), \"utf8\");\n\ttry {\n\t\tawait runFiletools(\n\t\t\tbinaryPath,\n\t\t\t\"reconstruct\",\n\t\t\t[\"--envelope\", record.envelopePath, \"--patch\", patchPath, \"--out\", outPath, \"--original\", absolutePath],\n\t\t\tcwd,\n\t\t\tsignal,\n\t\t\toptions?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS,\n\t\t);\n\t} finally {\n\t\trmSync(patchPath, { force: true });\n\t}\n}\n\n// ============================================================================\n// Discovery commands (scan / grep / read) — the token-sensitive loop\n// ============================================================================\n//\n// Unlike extract/reconstruct (which write files and the caller reads back),\n// scan/grep/read print a single pretty-JSON object to stdout and never touch\n// the extract cache: they are read-only projections used to navigate a document\n// cheaply before (optionally) editing it. The shapes below are locked against\n// the filetools `ScanView` / `GrepView` / `ReadView` serializers.\n\n/** One block in a `scan` manifest: structure + a short preview, no full content. */\nexport interface BlockManifest {\n\tid: string;\n\tblock_type: string;\n\tpreview: string;\n\tcontent_hash: string;\n\tparent_id?: string | null;\n\ttoken_estimate: number;\n\tsection_name: string;\n\tsection_number: number;\n}\n\n/** `filetools scan` output: a paginated manifest of block previews. */\nexport interface ScanView {\n\tfile_type: string;\n\tblock_count: number;\n\ttotal_tokens: number;\n\toffset: number;\n\treturned: number;\n\ttotal: number;\n\tblocks: BlockManifest[];\n}\n\n/** One `grep` hit: the block id, the matching line number, and a snippet. */\nexport interface GrepMatch {\n\tblock_id: string;\n\tline: number;\n\tsnippet: string;\n\twritable: boolean;\n}\n\n/** `filetools grep` output: literal-substring matches across blocks. */\nexport interface GrepView {\n\tpattern: string;\n\treturned: number;\n\tmatches: GrepMatch[];\n}\n\n/** `filetools read` output: hydrated nodes for the requested blocks. */\nexport interface ReadView {\n\toffset: number;\n\treturned: number;\n\ttotal: number;\n\tnodes: DocNode[];\n}\n\n/**\n * Run a stdout-oriented filetools subcommand (scan/grep/read) and parse its\n * single pretty-JSON object. These do not write files or populate the extract\n * cache, so they are safe to interleave with a pending DocEdit/DocWrite.\n */\nasync function runFiletoolsJson<T>(\n\tsubcommand: \"scan\" | \"grep\" | \"read\",\n\targs: string[],\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\ttimeoutSecs: number,\n): Promise<T> {\n\tconst binaryPath = await resolveBinary();\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tconst spawnTimeoutMs = (timeoutSecs + 5) * 1000;\n\tconst result = await execCommand(binaryPath, [subcommand, ...args], cwd, { signal, timeout: spawnTimeoutMs });\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\tif (result.killed) throw new Error(`filetools ${subcommand} timed out after ${timeoutSecs}s`);\n\tif (result.code !== 0) {\n\t\tconst stderr = result.stderr.trim();\n\t\tthrow new Error(stderr || `filetools ${subcommand} exited with code ${result.code}`);\n\t}\n\tconst stdout = result.stdout.trim();\n\tif (!stdout) throw new Error(`filetools ${subcommand} produced no output`);\n\ttry {\n\t\treturn JSON.parse(stdout) as T;\n\t} catch {\n\t\tthrow new Error(`filetools ${subcommand} produced malformed JSON output`);\n\t}\n}\n\n/** Scan a document into a paginated manifest of block previews (no hydration). */\nexport async function scanDocument(\n\tabsolutePath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { offset?: number; limit?: number; timeoutSecs?: number },\n): Promise<ScanView> {\n\tconst args = [\"--input\", absolutePath];\n\tif (options?.offset !== undefined) args.push(\"--offset\", String(options.offset));\n\tif (options?.limit !== undefined) args.push(\"--limit\", String(options.limit));\n\treturn runFiletoolsJson<ScanView>(\"scan\", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);\n}\n\n/** Locate blocks containing `pattern` (literal substring) without hydrating the doc. */\nexport async function grepDocument(\n\tabsolutePath: string,\n\tpattern: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { ignoreCase?: boolean; limit?: number; timeoutSecs?: number },\n): Promise<GrepView> {\n\tconst args = [\"--input\", absolutePath, \"--pattern\", pattern];\n\tif (options?.ignoreCase) args.push(\"--ignore-case\");\n\tif (options?.limit !== undefined) args.push(\"--limit\", String(options.limit));\n\treturn runFiletoolsJson<GrepView>(\"grep\", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);\n}\n\n/** Hydrate specific blocks by id (or a paginated slice when no ids are given). */\nexport async function readDocumentBlocks(\n\tabsolutePath: string,\n\tcwd: string,\n\tsignal: AbortSignal | undefined,\n\toptions?: { ids?: string[]; offset?: number; limit?: number; timeoutSecs?: number },\n): Promise<ReadView> {\n\tconst args = [\"--input\", absolutePath];\n\tfor (const id of options?.ids ?? []) args.push(\"--id\", id);\n\tif (options?.offset !== undefined) args.push(\"--offset\", String(options.offset));\n\tif (options?.limit !== undefined) args.push(\"--limit\", String(options.limit));\n\treturn runFiletoolsJson<ReadView>(\"read\", args, cwd, signal, options?.timeoutSecs ?? FILETOOLS_DEFAULT_TIMEOUT_SECS);\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashTool, createBashToolDefinition, createLocalBashOperations, } from "./bash.js";
|
|
2
2
|
export { createDocEditTool, createDocEditToolDefinition, type DocEditToolDetails, type DocEditToolInput, type DocEditToolOptions, } from "./docedit.js";
|
|
3
|
+
export { createDocGrepTool, createDocGrepToolDefinition, type DocGrepToolDetails, type DocGrepToolInput, type DocGrepToolOptions, } from "./docgrep.js";
|
|
4
|
+
export { createDocPeekTool, createDocPeekToolDefinition, type DocPeekToolDetails, type DocPeekToolInput, type DocPeekToolOptions, } from "./docpeek.js";
|
|
3
5
|
export { createDocReadTool, createDocReadToolDefinition, type DocReadToolDetails, type DocReadToolInput, type DocReadToolOptions, } from "./docread.js";
|
|
6
|
+
export { createDocScanTool, createDocScanToolDefinition, type DocScanToolDetails, type DocScanToolInput, type DocScanToolOptions, } from "./docscan.js";
|
|
4
7
|
export { createDocWriteTool, createDocWriteToolDefinition, type DocWriteToolDetails, type DocWriteToolInput, type DocWriteToolOptions, } from "./docwrite.js";
|
|
5
8
|
export { createEditTool, createEditToolDefinition, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, } from "./edit.js";
|
|
6
9
|
export { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
@@ -20,7 +23,10 @@ import type { AgentTool } from "@kolisachint/hoocode-agent-core";
|
|
|
20
23
|
import type { ToolDefinition } from "../extensions/types.js";
|
|
21
24
|
import { type BashToolOptions } from "./bash.js";
|
|
22
25
|
import { type DocEditToolOptions } from "./docedit.js";
|
|
26
|
+
import { type DocGrepToolOptions } from "./docgrep.js";
|
|
27
|
+
import { type DocPeekToolOptions } from "./docpeek.js";
|
|
23
28
|
import { type DocReadToolOptions } from "./docread.js";
|
|
29
|
+
import { type DocScanToolOptions } from "./docscan.js";
|
|
24
30
|
import { type DocWriteToolOptions } from "./docwrite.js";
|
|
25
31
|
import { type EditToolOptions } from "./edit.js";
|
|
26
32
|
import { type FindToolOptions } from "./find.js";
|
|
@@ -33,7 +39,7 @@ import { type WebSearchToolOptions } from "./websearch.js";
|
|
|
33
39
|
import { type WriteToolOptions } from "./write.js";
|
|
34
40
|
export type Tool = AgentTool<any>;
|
|
35
41
|
export type ToolDef = ToolDefinition<any, any>;
|
|
36
|
-
export type ToolName = "read" | "bash" | "edit" | "write" | "grep" | "find" | "glob" | "ls" | "webfetch" | "websearch" | "DocRead" | "DocEdit" | "DocWrite";
|
|
42
|
+
export type ToolName = "read" | "bash" | "edit" | "write" | "grep" | "find" | "glob" | "ls" | "webfetch" | "websearch" | "DocRead" | "DocEdit" | "DocWrite" | "DocScan" | "DocGrep" | "DocPeek";
|
|
37
43
|
export declare const allToolNames: Set<ToolName>;
|
|
38
44
|
export interface ToolsOptions {
|
|
39
45
|
read?: ReadToolOptions;
|
|
@@ -49,6 +55,9 @@ export interface ToolsOptions {
|
|
|
49
55
|
DocRead?: DocReadToolOptions;
|
|
50
56
|
DocEdit?: DocEditToolOptions;
|
|
51
57
|
DocWrite?: DocWriteToolOptions;
|
|
58
|
+
DocScan?: DocScanToolOptions;
|
|
59
|
+
DocGrep?: DocGrepToolOptions;
|
|
60
|
+
DocPeek?: DocPeekToolOptions;
|
|
52
61
|
}
|
|
53
62
|
export declare function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef;
|
|
54
63
|
export declare function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,cAAc,EACd,wBAAwB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EACl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AgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,EAAE,CAW7E;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,EAAE,CAQ/E;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAgB1F","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.js\";\nexport {\n\tcreateDocEditTool,\n\tcreateDocEditToolDefinition,\n\ttype DocEditToolDetails,\n\ttype DocEditToolInput,\n\ttype DocEditToolOptions,\n} from \"./docedit.js\";\nexport {\n\tcreateDocReadTool,\n\tcreateDocReadToolDefinition,\n\ttype DocReadToolDetails,\n\ttype DocReadToolInput,\n\ttype DocReadToolOptions,\n} from \"./docread.js\";\nexport {\n\tcreateDocWriteTool,\n\tcreateDocWriteToolDefinition,\n\ttype DocWriteToolDetails,\n\ttype DocWriteToolInput,\n\ttype DocWriteToolOptions,\n} from \"./docwrite.js\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.js\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.js\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.js\";\nexport {\n\tcreateGlobTool,\n\tcreateGlobToolDefinition,\n\ttype GlobOperations,\n\ttype GlobToolDetails,\n\ttype GlobToolInput,\n\ttype GlobToolOptions,\n} from \"./glob.js\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.js\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.js\";\nexport { expandPath, resolveReadPath, resolveToCwd } from \"./path-utils.js\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.js\";\n// Off-by-default tools (enabled per session via flags/settings).\nexport {\n\tbuildTaskMainPrompt,\n\tcreateTaskOutputToolDefinition,\n\tcreateTaskToolDefinition,\n\ttype TaskOutputDetails,\n\ttype TaskToolDetails,\n} from \"./subagent.js\";\nexport { createTodoWriteToolDefinition, type TodoWriteDetails } from \"./todo.js\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.js\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchToolDetails,\n\ttype WebFetchToolInput,\n\ttype WebFetchToolOptions,\n} from \"./webfetch.js\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchToolDetails,\n\ttype WebSearchToolInput,\n\ttype WebSearchToolOptions,\n} from \"./websearch.js\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.js\";\n\nimport type { AgentTool } from \"@kolisachint/hoocode-agent-core\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.js\";\nimport { createDocEditTool, createDocEditToolDefinition, type DocEditToolOptions } from \"./docedit.js\";\nimport { createDocReadTool, createDocReadToolDefinition, type DocReadToolOptions } from \"./docread.js\";\nimport { createDocWriteTool, createDocWriteToolDefinition, type DocWriteToolOptions } from \"./docwrite.js\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.js\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.js\";\nimport { createGlobTool, createGlobToolDefinition, type GlobToolOptions } from \"./glob.js\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.js\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.js\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.js\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./webfetch.js\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./websearch.js\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.js\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"glob\"\n\t| \"ls\"\n\t| \"webfetch\"\n\t| \"websearch\"\n\t| \"DocRead\"\n\t| \"DocEdit\"\n\t| \"DocWrite\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"glob\",\n\t\"ls\",\n\t\"webfetch\",\n\t\"websearch\",\n\t\"DocRead\",\n\t\"DocEdit\",\n\t\"DocWrite\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tglob?: GlobToolOptions;\n\tls?: LsToolOptions;\n\twebfetch?: WebFetchToolOptions;\n\twebsearch?: WebSearchToolOptions;\n\tDocRead?: DocReadToolOptions;\n\tDocEdit?: DocEditToolOptions;\n\tDocWrite?: DocWriteToolOptions;\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"glob\":\n\t\t\treturn createGlobToolDefinition(cwd, options?.glob);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"webfetch\":\n\t\t\treturn createWebFetchToolDefinition(cwd, options?.webfetch);\n\t\tcase \"websearch\":\n\t\t\treturn createWebSearchToolDefinition(cwd, options?.websearch);\n\t\tcase \"DocRead\":\n\t\t\treturn createDocReadToolDefinition(cwd, options?.DocRead);\n\t\tcase \"DocEdit\":\n\t\t\treturn createDocEditToolDefinition(cwd, options?.DocEdit);\n\t\tcase \"DocWrite\":\n\t\t\treturn createDocWriteToolDefinition(cwd, options?.DocWrite);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"glob\":\n\t\t\treturn createGlobTool(cwd, options?.glob);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"webfetch\":\n\t\t\treturn createWebFetchTool(cwd, options?.webfetch);\n\t\tcase \"websearch\":\n\t\t\treturn createWebSearchTool(cwd, options?.websearch);\n\t\tcase \"DocRead\":\n\t\t\treturn createDocReadTool(cwd, options?.DocRead);\n\t\tcase \"DocEdit\":\n\t\t\treturn createDocEditTool(cwd, options?.DocEdit);\n\t\tcase \"DocWrite\":\n\t\t\treturn createDocWriteTool(cwd, options?.DocWrite);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateGlobToolDefinition(cwd, options?.glob),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateGlobToolDefinition(cwd, options?.glob),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tglob: createGlobToolDefinition(cwd, options?.glob),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\twebfetch: createWebFetchToolDefinition(cwd, options?.webfetch),\n\t\twebsearch: createWebSearchToolDefinition(cwd, options?.websearch),\n\t\tDocRead: createDocReadToolDefinition(cwd, options?.DocRead),\n\t\tDocEdit: createDocEditToolDefinition(cwd, options?.DocEdit),\n\t\tDocWrite: createDocWriteToolDefinition(cwd, options?.DocWrite),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateGlobTool(cwd, options?.glob),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateGlobTool(cwd, options?.glob),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tglob: createGlobTool(cwd, options?.glob),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\twebfetch: createWebFetchTool(cwd, options?.webfetch),\n\t\twebsearch: createWebSearchTool(cwd, options?.websearch),\n\t\tDocRead: createDocReadTool(cwd, options?.DocRead),\n\t\tDocEdit: createDocEditTool(cwd, options?.DocEdit),\n\t\tDocWrite: createDocWriteTool(cwd, options?.DocWrite),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,iBAAiB,EACjB,2BAA2B,EAC3B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB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AE,mBAAmB,CAAC;IAC/B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAqCrG;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAqCxF;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,EAAE,CAW1F;AAED,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,EAAE,CAQ5F;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAmBvG;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,EAAE,CAW7E;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,EAAE,CAQ/E;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAmB1F","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.js\";\nexport {\n\tcreateDocEditTool,\n\tcreateDocEditToolDefinition,\n\ttype DocEditToolDetails,\n\ttype DocEditToolInput,\n\ttype DocEditToolOptions,\n} from \"./docedit.js\";\nexport {\n\tcreateDocGrepTool,\n\tcreateDocGrepToolDefinition,\n\ttype DocGrepToolDetails,\n\ttype DocGrepToolInput,\n\ttype DocGrepToolOptions,\n} from \"./docgrep.js\";\nexport {\n\tcreateDocPeekTool,\n\tcreateDocPeekToolDefinition,\n\ttype DocPeekToolDetails,\n\ttype DocPeekToolInput,\n\ttype DocPeekToolOptions,\n} from \"./docpeek.js\";\nexport {\n\tcreateDocReadTool,\n\tcreateDocReadToolDefinition,\n\ttype DocReadToolDetails,\n\ttype DocReadToolInput,\n\ttype DocReadToolOptions,\n} from \"./docread.js\";\nexport {\n\tcreateDocScanTool,\n\tcreateDocScanToolDefinition,\n\ttype DocScanToolDetails,\n\ttype DocScanToolInput,\n\ttype DocScanToolOptions,\n} from \"./docscan.js\";\nexport {\n\tcreateDocWriteTool,\n\tcreateDocWriteToolDefinition,\n\ttype DocWriteToolDetails,\n\ttype DocWriteToolInput,\n\ttype DocWriteToolOptions,\n} from \"./docwrite.js\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.js\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.js\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.js\";\nexport {\n\tcreateGlobTool,\n\tcreateGlobToolDefinition,\n\ttype GlobOperations,\n\ttype GlobToolDetails,\n\ttype GlobToolInput,\n\ttype GlobToolOptions,\n} from \"./glob.js\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.js\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.js\";\nexport { expandPath, resolveReadPath, resolveToCwd } from \"./path-utils.js\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.js\";\n// Off-by-default tools (enabled per session via flags/settings).\nexport {\n\tbuildTaskMainPrompt,\n\tcreateTaskOutputToolDefinition,\n\tcreateTaskToolDefinition,\n\ttype TaskOutputDetails,\n\ttype TaskToolDetails,\n} from \"./subagent.js\";\nexport { createTodoWriteToolDefinition, type TodoWriteDetails } from \"./todo.js\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.js\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchToolDetails,\n\ttype WebFetchToolInput,\n\ttype WebFetchToolOptions,\n} from \"./webfetch.js\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchToolDetails,\n\ttype WebSearchToolInput,\n\ttype WebSearchToolOptions,\n} from \"./websearch.js\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.js\";\n\nimport type { AgentTool } from \"@kolisachint/hoocode-agent-core\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.js\";\nimport { createDocEditTool, createDocEditToolDefinition, type DocEditToolOptions } from \"./docedit.js\";\nimport { createDocGrepTool, createDocGrepToolDefinition, type DocGrepToolOptions } from \"./docgrep.js\";\nimport { createDocPeekTool, createDocPeekToolDefinition, type DocPeekToolOptions } from \"./docpeek.js\";\nimport { createDocReadTool, createDocReadToolDefinition, type DocReadToolOptions } from \"./docread.js\";\nimport { createDocScanTool, createDocScanToolDefinition, type DocScanToolOptions } from \"./docscan.js\";\nimport { createDocWriteTool, createDocWriteToolDefinition, type DocWriteToolOptions } from \"./docwrite.js\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.js\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.js\";\nimport { createGlobTool, createGlobToolDefinition, type GlobToolOptions } from \"./glob.js\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.js\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.js\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.js\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./webfetch.js\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./websearch.js\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.js\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"glob\"\n\t| \"ls\"\n\t| \"webfetch\"\n\t| \"websearch\"\n\t| \"DocRead\"\n\t| \"DocEdit\"\n\t| \"DocWrite\"\n\t| \"DocScan\"\n\t| \"DocGrep\"\n\t| \"DocPeek\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"glob\",\n\t\"ls\",\n\t\"webfetch\",\n\t\"websearch\",\n\t\"DocRead\",\n\t\"DocEdit\",\n\t\"DocWrite\",\n\t\"DocScan\",\n\t\"DocGrep\",\n\t\"DocPeek\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tglob?: GlobToolOptions;\n\tls?: LsToolOptions;\n\twebfetch?: WebFetchToolOptions;\n\twebsearch?: WebSearchToolOptions;\n\tDocRead?: DocReadToolOptions;\n\tDocEdit?: DocEditToolOptions;\n\tDocWrite?: DocWriteToolOptions;\n\tDocScan?: DocScanToolOptions;\n\tDocGrep?: DocGrepToolOptions;\n\tDocPeek?: DocPeekToolOptions;\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"glob\":\n\t\t\treturn createGlobToolDefinition(cwd, options?.glob);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"webfetch\":\n\t\t\treturn createWebFetchToolDefinition(cwd, options?.webfetch);\n\t\tcase \"websearch\":\n\t\t\treturn createWebSearchToolDefinition(cwd, options?.websearch);\n\t\tcase \"DocRead\":\n\t\t\treturn createDocReadToolDefinition(cwd, options?.DocRead);\n\t\tcase \"DocEdit\":\n\t\t\treturn createDocEditToolDefinition(cwd, options?.DocEdit);\n\t\tcase \"DocWrite\":\n\t\t\treturn createDocWriteToolDefinition(cwd, options?.DocWrite);\n\t\tcase \"DocScan\":\n\t\t\treturn createDocScanToolDefinition(cwd, options?.DocScan);\n\t\tcase \"DocGrep\":\n\t\t\treturn createDocGrepToolDefinition(cwd, options?.DocGrep);\n\t\tcase \"DocPeek\":\n\t\t\treturn createDocPeekToolDefinition(cwd, options?.DocPeek);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"glob\":\n\t\t\treturn createGlobTool(cwd, options?.glob);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"webfetch\":\n\t\t\treturn createWebFetchTool(cwd, options?.webfetch);\n\t\tcase \"websearch\":\n\t\t\treturn createWebSearchTool(cwd, options?.websearch);\n\t\tcase \"DocRead\":\n\t\t\treturn createDocReadTool(cwd, options?.DocRead);\n\t\tcase \"DocEdit\":\n\t\t\treturn createDocEditTool(cwd, options?.DocEdit);\n\t\tcase \"DocWrite\":\n\t\t\treturn createDocWriteTool(cwd, options?.DocWrite);\n\t\tcase \"DocScan\":\n\t\t\treturn createDocScanTool(cwd, options?.DocScan);\n\t\tcase \"DocGrep\":\n\t\t\treturn createDocGrepTool(cwd, options?.DocGrep);\n\t\tcase \"DocPeek\":\n\t\t\treturn createDocPeekTool(cwd, options?.DocPeek);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateGlobToolDefinition(cwd, options?.glob),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateGlobToolDefinition(cwd, options?.glob),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tglob: createGlobToolDefinition(cwd, options?.glob),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\twebfetch: createWebFetchToolDefinition(cwd, options?.webfetch),\n\t\twebsearch: createWebSearchToolDefinition(cwd, options?.websearch),\n\t\tDocRead: createDocReadToolDefinition(cwd, options?.DocRead),\n\t\tDocEdit: createDocEditToolDefinition(cwd, options?.DocEdit),\n\t\tDocWrite: createDocWriteToolDefinition(cwd, options?.DocWrite),\n\t\tDocScan: createDocScanToolDefinition(cwd, options?.DocScan),\n\t\tDocGrep: createDocGrepToolDefinition(cwd, options?.DocGrep),\n\t\tDocPeek: createDocPeekToolDefinition(cwd, options?.DocPeek),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateGlobTool(cwd, options?.glob),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateGlobTool(cwd, options?.glob),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tglob: createGlobTool(cwd, options?.glob),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\twebfetch: createWebFetchTool(cwd, options?.webfetch),\n\t\twebsearch: createWebSearchTool(cwd, options?.websearch),\n\t\tDocRead: createDocReadTool(cwd, options?.DocRead),\n\t\tDocEdit: createDocEditTool(cwd, options?.DocEdit),\n\t\tDocWrite: createDocWriteTool(cwd, options?.DocWrite),\n\t\tDocScan: createDocScanTool(cwd, options?.DocScan),\n\t\tDocGrep: createDocGrepTool(cwd, options?.DocGrep),\n\t\tDocPeek: createDocPeekTool(cwd, options?.DocPeek),\n\t};\n}\n"]}
|
package/dist/core/tools/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { createBashTool, createBashToolDefinition, createLocalBashOperations, } from "./bash.js";
|
|
2
2
|
export { createDocEditTool, createDocEditToolDefinition, } from "./docedit.js";
|
|
3
|
+
export { createDocGrepTool, createDocGrepToolDefinition, } from "./docgrep.js";
|
|
4
|
+
export { createDocPeekTool, createDocPeekToolDefinition, } from "./docpeek.js";
|
|
3
5
|
export { createDocReadTool, createDocReadToolDefinition, } from "./docread.js";
|
|
6
|
+
export { createDocScanTool, createDocScanToolDefinition, } from "./docscan.js";
|
|
4
7
|
export { createDocWriteTool, createDocWriteToolDefinition, } from "./docwrite.js";
|
|
5
8
|
export { createEditTool, createEditToolDefinition, } from "./edit.js";
|
|
6
9
|
export { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
@@ -19,7 +22,10 @@ export { createWebSearchTool, createWebSearchToolDefinition, } from "./websearch
|
|
|
19
22
|
export { createWriteTool, createWriteToolDefinition, } from "./write.js";
|
|
20
23
|
import { createBashTool, createBashToolDefinition } from "./bash.js";
|
|
21
24
|
import { createDocEditTool, createDocEditToolDefinition } from "./docedit.js";
|
|
25
|
+
import { createDocGrepTool, createDocGrepToolDefinition } from "./docgrep.js";
|
|
26
|
+
import { createDocPeekTool, createDocPeekToolDefinition } from "./docpeek.js";
|
|
22
27
|
import { createDocReadTool, createDocReadToolDefinition } from "./docread.js";
|
|
28
|
+
import { createDocScanTool, createDocScanToolDefinition } from "./docscan.js";
|
|
23
29
|
import { createDocWriteTool, createDocWriteToolDefinition } from "./docwrite.js";
|
|
24
30
|
import { createEditTool, createEditToolDefinition } from "./edit.js";
|
|
25
31
|
import { createFindTool, createFindToolDefinition } from "./find.js";
|
|
@@ -44,6 +50,9 @@ export const allToolNames = new Set([
|
|
|
44
50
|
"DocRead",
|
|
45
51
|
"DocEdit",
|
|
46
52
|
"DocWrite",
|
|
53
|
+
"DocScan",
|
|
54
|
+
"DocGrep",
|
|
55
|
+
"DocPeek",
|
|
47
56
|
]);
|
|
48
57
|
export function createToolDefinition(toolName, cwd, options) {
|
|
49
58
|
switch (toolName) {
|
|
@@ -73,6 +82,12 @@ export function createToolDefinition(toolName, cwd, options) {
|
|
|
73
82
|
return createDocEditToolDefinition(cwd, options?.DocEdit);
|
|
74
83
|
case "DocWrite":
|
|
75
84
|
return createDocWriteToolDefinition(cwd, options?.DocWrite);
|
|
85
|
+
case "DocScan":
|
|
86
|
+
return createDocScanToolDefinition(cwd, options?.DocScan);
|
|
87
|
+
case "DocGrep":
|
|
88
|
+
return createDocGrepToolDefinition(cwd, options?.DocGrep);
|
|
89
|
+
case "DocPeek":
|
|
90
|
+
return createDocPeekToolDefinition(cwd, options?.DocPeek);
|
|
76
91
|
default:
|
|
77
92
|
throw new Error(`Unknown tool name: ${toolName}`);
|
|
78
93
|
}
|
|
@@ -105,6 +120,12 @@ export function createTool(toolName, cwd, options) {
|
|
|
105
120
|
return createDocEditTool(cwd, options?.DocEdit);
|
|
106
121
|
case "DocWrite":
|
|
107
122
|
return createDocWriteTool(cwd, options?.DocWrite);
|
|
123
|
+
case "DocScan":
|
|
124
|
+
return createDocScanTool(cwd, options?.DocScan);
|
|
125
|
+
case "DocGrep":
|
|
126
|
+
return createDocGrepTool(cwd, options?.DocGrep);
|
|
127
|
+
case "DocPeek":
|
|
128
|
+
return createDocPeekTool(cwd, options?.DocPeek);
|
|
108
129
|
default:
|
|
109
130
|
throw new Error(`Unknown tool name: ${toolName}`);
|
|
110
131
|
}
|
|
@@ -145,6 +166,9 @@ export function createAllToolDefinitions(cwd, options) {
|
|
|
145
166
|
DocRead: createDocReadToolDefinition(cwd, options?.DocRead),
|
|
146
167
|
DocEdit: createDocEditToolDefinition(cwd, options?.DocEdit),
|
|
147
168
|
DocWrite: createDocWriteToolDefinition(cwd, options?.DocWrite),
|
|
169
|
+
DocScan: createDocScanToolDefinition(cwd, options?.DocScan),
|
|
170
|
+
DocGrep: createDocGrepToolDefinition(cwd, options?.DocGrep),
|
|
171
|
+
DocPeek: createDocPeekToolDefinition(cwd, options?.DocPeek),
|
|
148
172
|
};
|
|
149
173
|
}
|
|
150
174
|
export function createCodingTools(cwd, options) {
|
|
@@ -183,6 +207,9 @@ export function createAllTools(cwd, options) {
|
|
|
183
207
|
DocRead: createDocReadTool(cwd, options?.DocRead),
|
|
184
208
|
DocEdit: createDocEditTool(cwd, options?.DocEdit),
|
|
185
209
|
DocWrite: createDocWriteTool(cwd, options?.DocWrite),
|
|
210
|
+
DocScan: createDocScanTool(cwd, options?.DocScan),
|
|
211
|
+
DocGrep: createDocGrepTool(cwd, options?.DocGrep),
|
|
212
|
+
DocPeek: createDocPeekTool(cwd, options?.DocPeek),
|
|
186
213
|
};
|
|
187
214
|
}
|
|
188
215
|
//# sourceMappingURL=index.js.map
|