@nervekit/tools 0.1.0 → 0.3.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.
- package/dist/execution/common/output-budget.d.ts +5 -0
- package/dist/execution/common/output-budget.d.ts.map +1 -1
- package/dist/execution/common/output-budget.js +26 -0
- package/dist/execution/common/output-budget.js.map +1 -1
- package/dist/execution/common/process-result.d.ts.map +1 -1
- package/dist/execution/common/process-result.js +55 -1
- package/dist/execution/common/process-result.js.map +1 -1
- package/dist/execution/filesystem/find.d.ts.map +1 -1
- package/dist/execution/filesystem/find.js +5 -2
- package/dist/execution/filesystem/find.js.map +1 -1
- package/dist/execution/filesystem/list.d.ts.map +1 -1
- package/dist/execution/filesystem/list.js +5 -2
- package/dist/execution/filesystem/list.js.map +1 -1
- package/dist/execution/filesystem/read.d.ts.map +1 -1
- package/dist/execution/filesystem/read.js +19 -2
- package/dist/execution/filesystem/read.js.map +1 -1
- package/dist/execution/filesystem/search.d.ts.map +1 -1
- package/dist/execution/filesystem/search.js +12 -2
- package/dist/execution/filesystem/search.js.map +1 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +1 -1
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/shell/bash.d.ts.map +1 -1
- package/dist/execution/shell/bash.js +12 -1
- package/dist/execution/shell/bash.js.map +1 -1
- package/dist/execution/web/web-fetch.d.ts.map +1 -1
- package/dist/execution/web/web-fetch.js +39 -0
- package/dist/execution/web/web-fetch.js.map +1 -1
- package/dist/execution/web/web-search.d.ts.map +1 -1
- package/dist/execution/web/web-search.js +9 -2
- package/dist/execution/web/web-search.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/catalog/orchestration/process.tools.d.ts +0 -68
- package/dist/catalog/orchestration/process.tools.d.ts.map +0 -1
- package/dist/catalog/orchestration/process.tools.js +0 -96
- package/dist/catalog/orchestration/process.tools.js.map +0 -1
- package/dist/catalog/orchestration/subagent.tools.d.ts +0 -16
- package/dist/catalog/orchestration/subagent.tools.d.ts.map +0 -1
- package/dist/catalog/orchestration/subagent.tools.js +0 -25
- package/dist/catalog/orchestration/subagent.tools.js.map +0 -1
- package/dist/definitions.d.ts +0 -2
- package/dist/definitions.d.ts.map +0 -1
- package/dist/definitions.js +0 -2
- package/dist/definitions.js.map +0 -1
- package/dist/execution/atomic-write.d.ts +0 -2
- package/dist/execution/atomic-write.d.ts.map +0 -1
- package/dist/execution/atomic-write.js +0 -7
- package/dist/execution/atomic-write.js.map +0 -1
- package/dist/execution/bash.d.ts +0 -3
- package/dist/execution/bash.d.ts.map +0 -1
- package/dist/execution/bash.js +0 -133
- package/dist/execution/bash.js.map +0 -1
- package/dist/execution/common.d.ts +0 -2
- package/dist/execution/common.d.ts.map +0 -1
- package/dist/execution/common.js +0 -6
- package/dist/execution/common.js.map +0 -1
- package/dist/execution/dispatch.d.ts +0 -4
- package/dist/execution/dispatch.d.ts.map +0 -1
- package/dist/execution/dispatch.js +0 -54
- package/dist/execution/dispatch.js.map +0 -1
- package/dist/execution/edit.d.ts +0 -9
- package/dist/execution/edit.d.ts.map +0 -1
- package/dist/execution/edit.js +0 -175
- package/dist/execution/edit.js.map +0 -1
- package/dist/execution/file-mutation-queue.d.ts +0 -2
- package/dist/execution/file-mutation-queue.d.ts.map +0 -1
- package/dist/execution/file-mutation-queue.js +0 -19
- package/dist/execution/file-mutation-queue.js.map +0 -1
- package/dist/execution/filesystem/legacy-edit.d.ts +0 -9
- package/dist/execution/filesystem/legacy-edit.d.ts.map +0 -1
- package/dist/execution/filesystem/legacy-edit.js +0 -122
- package/dist/execution/filesystem/legacy-edit.js.map +0 -1
- package/dist/execution/find.d.ts +0 -3
- package/dist/execution/find.d.ts.map +0 -1
- package/dist/execution/find.js +0 -90
- package/dist/execution/find.js.map +0 -1
- package/dist/execution/list.d.ts +0 -3
- package/dist/execution/list.d.ts.map +0 -1
- package/dist/execution/list.js +0 -46
- package/dist/execution/list.js.map +0 -1
- package/dist/execution/path.d.ts +0 -7
- package/dist/execution/path.d.ts.map +0 -1
- package/dist/execution/path.js +0 -69
- package/dist/execution/path.js.map +0 -1
- package/dist/execution/read.d.ts +0 -3
- package/dist/execution/read.d.ts.map +0 -1
- package/dist/execution/read.js +0 -97
- package/dist/execution/read.js.map +0 -1
- package/dist/execution/search-utils.d.ts +0 -8
- package/dist/execution/search-utils.d.ts.map +0 -1
- package/dist/execution/search-utils.js +0 -110
- package/dist/execution/search-utils.js.map +0 -1
- package/dist/execution/search.d.ts +0 -3
- package/dist/execution/search.d.ts.map +0 -1
- package/dist/execution/search.js +0 -131
- package/dist/execution/search.js.map +0 -1
- package/dist/execution/truncate.d.ts +0 -21
- package/dist/execution/truncate.d.ts.map +0 -1
- package/dist/execution/truncate.js +0 -94
- package/dist/execution/truncate.js.map +0 -1
- package/dist/execution/web-fetch.d.ts +0 -3
- package/dist/execution/web-fetch.d.ts.map +0 -1
- package/dist/execution/web-fetch.js +0 -132
- package/dist/execution/web-fetch.js.map +0 -1
- package/dist/execution/web-search.d.ts +0 -3
- package/dist/execution/web-search.d.ts.map +0 -1
- package/dist/execution/web-search.js +0 -59
- package/dist/execution/web-search.js.map +0 -1
- package/dist/execution/write.d.ts +0 -3
- package/dist/execution/write.d.ts.map +0 -1
- package/dist/execution/write.js +0 -21
- package/dist/execution/write.js.map +0 -1
package/dist/execution/bash.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { numberArg } from "./common.js";
|
|
6
|
-
import { truncateTail } from "./truncate.js";
|
|
7
|
-
export async function executeBash(args, context) {
|
|
8
|
-
if (typeof args.command !== "string" || args.command.trim().length === 0) {
|
|
9
|
-
throw new Error("Tool argument 'command' must be a non-empty string.");
|
|
10
|
-
}
|
|
11
|
-
const timeoutSeconds = typeof args.timeout === "number"
|
|
12
|
-
? Math.max(0, numberArg(args.timeout, 0))
|
|
13
|
-
: undefined;
|
|
14
|
-
const stdoutChunks = [];
|
|
15
|
-
const stderrChunks = [];
|
|
16
|
-
const combinedChunks = [];
|
|
17
|
-
return await new Promise((resolve, reject) => {
|
|
18
|
-
if (context.signal?.aborted) {
|
|
19
|
-
reject(new Error("Command aborted."));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const child = spawn(args.command, {
|
|
23
|
-
cwd: context.cwd,
|
|
24
|
-
shell: true,
|
|
25
|
-
detached: process.platform !== "win32",
|
|
26
|
-
env: process.env,
|
|
27
|
-
});
|
|
28
|
-
let settled = false;
|
|
29
|
-
let timeout;
|
|
30
|
-
const cleanup = () => {
|
|
31
|
-
if (timeout)
|
|
32
|
-
clearTimeout(timeout);
|
|
33
|
-
context.signal?.removeEventListener("abort", onAbort);
|
|
34
|
-
};
|
|
35
|
-
const kill = () => {
|
|
36
|
-
try {
|
|
37
|
-
if (process.platform !== "win32" && child.pid) {
|
|
38
|
-
process.kill(-child.pid, "SIGTERM");
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
child.kill("SIGTERM");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
child.kill("SIGTERM");
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const onAbort = () => {
|
|
49
|
-
if (settled)
|
|
50
|
-
return;
|
|
51
|
-
kill();
|
|
52
|
-
settled = true;
|
|
53
|
-
cleanup();
|
|
54
|
-
reject(new Error("Command aborted."));
|
|
55
|
-
};
|
|
56
|
-
context.signal?.addEventListener("abort", onAbort, { once: true });
|
|
57
|
-
if (timeoutSeconds !== undefined && timeoutSeconds > 0) {
|
|
58
|
-
timeout = setTimeout(() => {
|
|
59
|
-
if (settled)
|
|
60
|
-
return;
|
|
61
|
-
kill();
|
|
62
|
-
settled = true;
|
|
63
|
-
cleanup();
|
|
64
|
-
reject(new Error(`Command timed out after ${timeoutSeconds}s.`));
|
|
65
|
-
}, timeoutSeconds * 1000);
|
|
66
|
-
}
|
|
67
|
-
child.stdout?.on("data", (chunk) => {
|
|
68
|
-
stdoutChunks.push(chunk);
|
|
69
|
-
combinedChunks.push(chunk);
|
|
70
|
-
context.onUpdate?.({
|
|
71
|
-
kind: "output",
|
|
72
|
-
stream: "stdout",
|
|
73
|
-
chunk: chunk.toString("utf8"),
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
child.stderr?.on("data", (chunk) => {
|
|
77
|
-
stderrChunks.push(chunk);
|
|
78
|
-
combinedChunks.push(chunk);
|
|
79
|
-
context.onUpdate?.({
|
|
80
|
-
kind: "output",
|
|
81
|
-
stream: "stderr",
|
|
82
|
-
chunk: chunk.toString("utf8"),
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
child.on("error", (error) => {
|
|
86
|
-
if (settled)
|
|
87
|
-
return;
|
|
88
|
-
settled = true;
|
|
89
|
-
cleanup();
|
|
90
|
-
reject(error);
|
|
91
|
-
});
|
|
92
|
-
child.on("close", (code, signal) => {
|
|
93
|
-
if (settled)
|
|
94
|
-
return;
|
|
95
|
-
settled = true;
|
|
96
|
-
cleanup();
|
|
97
|
-
void buildResult(stdoutChunks, stderrChunks, combinedChunks, code, signal)
|
|
98
|
-
.then(resolve)
|
|
99
|
-
.catch(reject);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
async function buildResult(stdoutChunks, stderrChunks, combinedChunks, code, signal) {
|
|
104
|
-
const stdout = Buffer.concat(stdoutChunks).toString("utf8");
|
|
105
|
-
const stderr = Buffer.concat(stderrChunks).toString("utf8");
|
|
106
|
-
const combined = Buffer.concat(combinedChunks).toString("utf8");
|
|
107
|
-
const exitCode = code ?? (signal ? 128 : 0);
|
|
108
|
-
const output = combined.length > 0 ? combined : "(no output)";
|
|
109
|
-
const truncated = truncateTail(output);
|
|
110
|
-
let content = truncated.text;
|
|
111
|
-
let fullOutputPath;
|
|
112
|
-
if (truncated.truncated) {
|
|
113
|
-
fullOutputPath = join(tmpdir(), `nerve-bash-${Date.now()}-${Math.random().toString(16).slice(2)}.log`);
|
|
114
|
-
await writeFile(fullOutputPath, output, "utf8");
|
|
115
|
-
content = `[...output truncated; full output saved to ${fullOutputPath}]\n${content}`;
|
|
116
|
-
}
|
|
117
|
-
if (exitCode !== 0) {
|
|
118
|
-
content += `${content.endsWith("\n") ? "" : "\n"}Command exited with code ${exitCode}.`;
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
stdout,
|
|
122
|
-
stderr,
|
|
123
|
-
exitCode,
|
|
124
|
-
content,
|
|
125
|
-
contentBlocks: [{ type: "text", text: content }],
|
|
126
|
-
details: {
|
|
127
|
-
truncation: truncated.truncated ? truncated : undefined,
|
|
128
|
-
fullOutputPath,
|
|
129
|
-
signal,
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=bash.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/execution/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAA6B,EAC7B,OAA6B;IAE7B,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IA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I,EAAE,OAAO,EAAE,CAAC;QAChD,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACvD,cAAc;YACd,MAAM;SACP;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/execution/common.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGlE"}
|
package/dist/execution/common.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/execution/common.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,QAAgB;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ToolName } from "@nerve/shared";
|
|
2
|
-
import type { ToolExecutionContext, ToolExecutionResult } from "../types.js";
|
|
3
|
-
export declare function executeTool(name: ToolName, args: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
4
|
-
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/execution/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAW7E,wBAAsB,WAAW,CAC/B,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAiD9B"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { executeBash } from "./bash.js";
|
|
2
|
-
import { executeEdit } from "./edit.js";
|
|
3
|
-
import { executeFind } from "./find.js";
|
|
4
|
-
import { executeLs } from "./list.js";
|
|
5
|
-
import { executeRead } from "./read.js";
|
|
6
|
-
import { executeGrep } from "./search.js";
|
|
7
|
-
import { executeWebFetch } from "./web-fetch.js";
|
|
8
|
-
import { executeWebSearch } from "./web-search.js";
|
|
9
|
-
import { executeWrite } from "./write.js";
|
|
10
|
-
export async function executeTool(name, args, context) {
|
|
11
|
-
switch (name) {
|
|
12
|
-
case "read":
|
|
13
|
-
return executeRead(args, context);
|
|
14
|
-
case "bash":
|
|
15
|
-
return executeBash(args, context);
|
|
16
|
-
case "edit":
|
|
17
|
-
return executeEdit(args, context);
|
|
18
|
-
case "write":
|
|
19
|
-
return executeWrite(args, context);
|
|
20
|
-
case "grep":
|
|
21
|
-
return executeGrep(args, context);
|
|
22
|
-
case "find":
|
|
23
|
-
return executeFind(args, context);
|
|
24
|
-
case "ls":
|
|
25
|
-
return executeLs(args, context);
|
|
26
|
-
case "web_search":
|
|
27
|
-
return executeWebSearch(args, context);
|
|
28
|
-
case "web_fetch":
|
|
29
|
-
return executeWebFetch(args, context);
|
|
30
|
-
case "ask_user":
|
|
31
|
-
throw new Error("ask_user is executed by the orchestrator user-interaction service.");
|
|
32
|
-
case "todos_set":
|
|
33
|
-
case "todos_get":
|
|
34
|
-
throw new Error(`${name} is executed by the orchestrator task-state service.`);
|
|
35
|
-
case "process_start":
|
|
36
|
-
case "process_stop":
|
|
37
|
-
case "process_restart":
|
|
38
|
-
case "process_list":
|
|
39
|
-
case "process_logs":
|
|
40
|
-
// packages/tools executes only core local tools. Managed process tools are
|
|
41
|
-
// orchestration tools: descriptors are shared for prompting/API purposes,
|
|
42
|
-
// but execution is mediated by the orchestrator process manager.
|
|
43
|
-
throw new Error(`${name} is executed by the orchestrator process manager.`);
|
|
44
|
-
case "subagent_run":
|
|
45
|
-
// Subagents require runtime/conversation authority checks owned by orchestrator.
|
|
46
|
-
throw new Error(`${name} is executed by the orchestrator agent runtime.`);
|
|
47
|
-
case "plan_mode_enter":
|
|
48
|
-
case "plan_mode_present":
|
|
49
|
-
case "plan_mode_force_exit":
|
|
50
|
-
// Plan mode requires runtime/conversation state and user-review waiters owned by orchestrator.
|
|
51
|
-
throw new Error(`${name} is executed by the orchestrator plan service.`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=dispatch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/execution/dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAc,EACd,IAA6B,EAC7B,OAA6B;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACp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"}
|
package/dist/execution/edit.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ToolExecutionContext, ToolExecutionResult } from "../types.js";
|
|
2
|
-
type NormalizedEdit = {
|
|
3
|
-
oldText: string;
|
|
4
|
-
newText: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function executeEdit(args: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
7
|
-
export declare function normalizeEditOperations(args: Record<string, unknown>): NormalizedEdit[];
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/execution/edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAK7E,KAAK,cAAc,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAG3D,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAoD9B;AAsHD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,cAAc,EAAE,CA2BlB"}
|
package/dist/execution/edit.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { writeTextFileAtomically } from "./atomic-write.js";
|
|
3
|
-
import { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
4
|
-
import { resolveToolPath } from "./path.js";
|
|
5
|
-
export async function executeEdit(args, context) {
|
|
6
|
-
const path = resolveToolPath(context.cwd, args.path);
|
|
7
|
-
const edits = normalizeEditOperations(args);
|
|
8
|
-
return withFileMutationQueue(path, async () => {
|
|
9
|
-
const raw = await readFile(path, "utf8");
|
|
10
|
-
const bom = raw.startsWith("\uFEFF") ? "\uFEFF" : "";
|
|
11
|
-
const withoutBom = bom ? raw.slice(1) : raw;
|
|
12
|
-
const lineEnding = detectLineEnding(withoutBom);
|
|
13
|
-
const content = normalizeLineEndings(withoutBom);
|
|
14
|
-
const normalizedEdits = edits.map((edit) => ({
|
|
15
|
-
oldText: normalizeLineEndings(edit.oldText),
|
|
16
|
-
newText: normalizeLineEndings(edit.newText),
|
|
17
|
-
}));
|
|
18
|
-
const matches = normalizedEdits.map((edit, index) => findUniqueMatch(content, edit, index));
|
|
19
|
-
const ordered = [...matches].sort((a, b) => a.start - b.start);
|
|
20
|
-
for (let i = 1; i < ordered.length; i++) {
|
|
21
|
-
const previous = ordered[i - 1];
|
|
22
|
-
const current = ordered[i];
|
|
23
|
-
if (!previous || !current)
|
|
24
|
-
continue;
|
|
25
|
-
if (current.start < previous.end) {
|
|
26
|
-
throw new Error(`edits[${current.index}] overlaps edits[${previous.index}]; merge overlapping changes.`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
let updated = content;
|
|
30
|
-
for (const edit of [...ordered].reverse()) {
|
|
31
|
-
updated = `${updated.slice(0, edit.start)}${edit.newText}${updated.slice(edit.end)}`;
|
|
32
|
-
}
|
|
33
|
-
if (updated === content) {
|
|
34
|
-
throw new Error("Edit would not change the file.");
|
|
35
|
-
}
|
|
36
|
-
const restored = bom + restoreLineEndings(updated, lineEnding);
|
|
37
|
-
await writeTextFileAtomically(path, restored);
|
|
38
|
-
const contentMessage = `Edited file with ${edits.length} replacement(s).`;
|
|
39
|
-
return {
|
|
40
|
-
path,
|
|
41
|
-
content: contentMessage,
|
|
42
|
-
contentBlocks: [{ type: "text", text: contentMessage }],
|
|
43
|
-
details: {
|
|
44
|
-
diff: generateDiffString(content, updated),
|
|
45
|
-
firstChangedLine: firstChangedLine(content, updated),
|
|
46
|
-
lineEnding,
|
|
47
|
-
bom: Boolean(bom),
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function findUniqueMatch(content, edit, index) {
|
|
53
|
-
const first = content.indexOf(edit.oldText);
|
|
54
|
-
if (first >= 0) {
|
|
55
|
-
if (content.indexOf(edit.oldText, first + edit.oldText.length) >= 0) {
|
|
56
|
-
throw new Error(`edits[${index}].oldText matched more than once; provide a unique region.`);
|
|
57
|
-
}
|
|
58
|
-
return { ...edit, index, start: first, end: first + edit.oldText.length };
|
|
59
|
-
}
|
|
60
|
-
const fuzzy = fuzzyFind(content, edit.oldText);
|
|
61
|
-
if (!fuzzy)
|
|
62
|
-
throw new Error(`edits[${index}].oldText was not found.`);
|
|
63
|
-
if (fuzzy.duplicate) {
|
|
64
|
-
throw new Error(`edits[${index}].oldText matched more than once; provide a unique region.`);
|
|
65
|
-
}
|
|
66
|
-
return { ...edit, index, start: fuzzy.start, end: fuzzy.end };
|
|
67
|
-
}
|
|
68
|
-
function fuzzyFind(content, needle) {
|
|
69
|
-
const normalizedNeedle = normalizeForFuzzyMatch(needle);
|
|
70
|
-
const lines = content.split("\n");
|
|
71
|
-
const needleLineCount = needle.split("\n").length;
|
|
72
|
-
const matches = [];
|
|
73
|
-
const offsets = [];
|
|
74
|
-
let offset = 0;
|
|
75
|
-
for (const line of lines) {
|
|
76
|
-
offsets.push(offset);
|
|
77
|
-
offset += line.length + 1;
|
|
78
|
-
}
|
|
79
|
-
for (let line = 0; line < lines.length; line += 1) {
|
|
80
|
-
for (let count = Math.max(1, needleLineCount - 1); count <= needleLineCount + 1; count += 1) {
|
|
81
|
-
const chunk = lines.slice(line, line + count).join("\n");
|
|
82
|
-
if (normalizeForFuzzyMatch(chunk) !== normalizedNeedle)
|
|
83
|
-
continue;
|
|
84
|
-
const start = offsets[line] ?? 0;
|
|
85
|
-
const end = start + chunk.length;
|
|
86
|
-
matches.push({ start, end });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const first = matches[0];
|
|
90
|
-
if (!first)
|
|
91
|
-
return undefined;
|
|
92
|
-
return { ...first, duplicate: matches.length > 1 };
|
|
93
|
-
}
|
|
94
|
-
function normalizeForFuzzyMatch(input) {
|
|
95
|
-
return normalizeLineEndings(input)
|
|
96
|
-
.replace(/[“”]/g, '"')
|
|
97
|
-
.replace(/[‘’]/g, "'")
|
|
98
|
-
.replace(/[–—]/g, "-")
|
|
99
|
-
.split("\n")
|
|
100
|
-
.map((line) => line.trimEnd())
|
|
101
|
-
.join("\n")
|
|
102
|
-
.trim();
|
|
103
|
-
}
|
|
104
|
-
function detectLineEnding(input) {
|
|
105
|
-
const crlf = input.match(/\r\n/g)?.length ?? 0;
|
|
106
|
-
const lf = input.match(/(?<!\r)\n/g)?.length ?? 0;
|
|
107
|
-
return crlf > lf ? "\r\n" : "\n";
|
|
108
|
-
}
|
|
109
|
-
function normalizeLineEndings(input) {
|
|
110
|
-
return input.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
111
|
-
}
|
|
112
|
-
function restoreLineEndings(input, lineEnding) {
|
|
113
|
-
return lineEnding === "\n" ? input : input.replace(/\n/g, "\r\n");
|
|
114
|
-
}
|
|
115
|
-
function firstChangedLine(before, after) {
|
|
116
|
-
const beforeLines = before.split("\n");
|
|
117
|
-
const afterLines = after.split("\n");
|
|
118
|
-
const length = Math.max(beforeLines.length, afterLines.length);
|
|
119
|
-
for (let index = 0; index < length; index += 1) {
|
|
120
|
-
if (beforeLines[index] !== afterLines[index])
|
|
121
|
-
return index + 1;
|
|
122
|
-
}
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
function generateDiffString(before, after) {
|
|
126
|
-
const line = firstChangedLine(before, after) ?? 1;
|
|
127
|
-
const beforeLines = before.split("\n");
|
|
128
|
-
const afterLines = after.split("\n");
|
|
129
|
-
const start = Math.max(0, line - 3);
|
|
130
|
-
const end = Math.min(Math.max(beforeLines.length, afterLines.length), line + 3);
|
|
131
|
-
const output = [
|
|
132
|
-
`@@ -${start + 1},${end - start} +${start + 1},${end - start} @@`,
|
|
133
|
-
];
|
|
134
|
-
for (let index = start; index < end; index += 1) {
|
|
135
|
-
const beforeLine = beforeLines[index];
|
|
136
|
-
const afterLine = afterLines[index];
|
|
137
|
-
if (beforeLine === afterLine)
|
|
138
|
-
output.push(` ${beforeLine ?? ""}`);
|
|
139
|
-
else {
|
|
140
|
-
if (beforeLine !== undefined)
|
|
141
|
-
output.push(`-${beforeLine}`);
|
|
142
|
-
if (afterLine !== undefined)
|
|
143
|
-
output.push(`+${afterLine}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return output.join("\n");
|
|
147
|
-
}
|
|
148
|
-
export function normalizeEditOperations(args) {
|
|
149
|
-
if (Array.isArray(args.edits)) {
|
|
150
|
-
if (args.edits.length === 0) {
|
|
151
|
-
throw new Error("Tool argument 'edits' must contain at least one edit.");
|
|
152
|
-
}
|
|
153
|
-
return args.edits.map((entry, index) => {
|
|
154
|
-
if (!entry || typeof entry !== "object") {
|
|
155
|
-
throw new Error(`edits[${index}] must be an object.`);
|
|
156
|
-
}
|
|
157
|
-
const edit = entry;
|
|
158
|
-
if (typeof edit.oldText !== "string" || edit.oldText.length === 0) {
|
|
159
|
-
throw new Error(`edits[${index}].oldText must be a non-empty string.`);
|
|
160
|
-
}
|
|
161
|
-
if (typeof edit.newText !== "string") {
|
|
162
|
-
throw new Error(`edits[${index}].newText must be a string.`);
|
|
163
|
-
}
|
|
164
|
-
return { oldText: edit.oldText, newText: edit.newText };
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
if (typeof args.oldText !== "string" || args.oldText.length === 0) {
|
|
168
|
-
throw new Error("Tool argument 'oldText' must be a non-empty string.");
|
|
169
|
-
}
|
|
170
|
-
if (typeof args.newText !== "string") {
|
|
171
|
-
throw new Error("Tool argument 'newText' must be a string.");
|
|
172
|
-
}
|
|
173
|
-
return [{ oldText: args.oldText, newText: args.newText }];
|
|
174
|
-
}
|
|
175
|
-
//#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
-
export async function withFileMutationQueue(path, task) {
|
|
3
|
-
const previous = queues.get(path) ?? Promise.resolve();
|
|
4
|
-
let release;
|
|
5
|
-
const current = new Promise((resolve) => {
|
|
6
|
-
release = resolve;
|
|
7
|
-
});
|
|
8
|
-
queues.set(path, previous.then(() => current, () => current));
|
|
9
|
-
await previous.catch(() => undefined);
|
|
10
|
-
try {
|
|
11
|
-
return await task();
|
|
12
|
-
}
|
|
13
|
-
finally {
|
|
14
|
-
release();
|
|
15
|
-
if (queues.get(path) === current)
|
|
16
|
-
queues.delete(path);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=file-mutation-queue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-mutation-queue.js","sourceRoot":"","sources":["../../src/execution/file-mutation-queue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEhD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAAY,EACZ,IAAsB;IAEtB,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvD,IAAI,OAAoB,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC5C,OAAO,GAAG,OAAO,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CACR,IAAI,EACJ,QAAQ,CAAC,IAAI,CACX,GAAG,EAAE,CAAC,OAAO,EACb,GAAG,EAAE,CAAC,OAAO,CACd,CACF,CAAC;IACF,MAAM,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;YAAS,CAAC;QACT,OAAO,EAAE,CAAC;QACV,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,OAAO;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ToolExecutionContext, ToolExecutionResult } from "../../types.js";
|
|
2
|
-
type NormalizedLegacyEdit = {
|
|
3
|
-
oldText: string;
|
|
4
|
-
newText: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function executeLegacyEdit(args: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
7
|
-
export declare function normalizeLegacyEditOperations(args: Record<string, unknown>): NormalizedLegacyEdit[];
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=legacy-edit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-edit.d.ts","sourceRoot":"","sources":["../../../src/execution/filesystem/legacy-edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAahF,KAAK,oBAAoB,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAOjE,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAoD9B;AA2DD,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,oBAAoB,EAAE,CA2BxB"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { writeTextFileAtomically } from "./atomic-write.js";
|
|
3
|
-
import { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
4
|
-
import { resolveToolPath } from "./path.js";
|
|
5
|
-
import { detectLineEnding, firstChangedLine, generateDiffString, normalizeForTrimmedMatch, normalizeLineEndings, restoreLineEndings, } from "./text-editing.js";
|
|
6
|
-
export async function executeLegacyEdit(args, context) {
|
|
7
|
-
const path = resolveToolPath(context.cwd, args.path);
|
|
8
|
-
const edits = normalizeLegacyEditOperations(args);
|
|
9
|
-
return withFileMutationQueue(path, async () => {
|
|
10
|
-
const raw = await readFile(path, "utf8");
|
|
11
|
-
const bom = raw.startsWith("\uFEFF") ? "\uFEFF" : "";
|
|
12
|
-
const withoutBom = bom ? raw.slice(1) : raw;
|
|
13
|
-
const lineEnding = detectLineEnding(withoutBom);
|
|
14
|
-
const content = normalizeLineEndings(withoutBom);
|
|
15
|
-
const normalizedEdits = edits.map((edit) => ({
|
|
16
|
-
oldText: normalizeLineEndings(edit.oldText),
|
|
17
|
-
newText: normalizeLineEndings(edit.newText),
|
|
18
|
-
}));
|
|
19
|
-
const matches = normalizedEdits.map((edit, index) => findUniqueMatch(content, edit, index));
|
|
20
|
-
const ordered = [...matches].sort((a, b) => a.start - b.start);
|
|
21
|
-
for (let i = 1; i < ordered.length; i++) {
|
|
22
|
-
const previous = ordered[i - 1];
|
|
23
|
-
const current = ordered[i];
|
|
24
|
-
if (!previous || !current)
|
|
25
|
-
continue;
|
|
26
|
-
if (current.start < previous.end) {
|
|
27
|
-
throw new Error(`edits[${current.index}] overlaps edits[${previous.index}]; merge overlapping changes.`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
let updated = content;
|
|
31
|
-
for (const edit of [...ordered].reverse()) {
|
|
32
|
-
updated = `${updated.slice(0, edit.start)}${edit.newText}${updated.slice(edit.end)}`;
|
|
33
|
-
}
|
|
34
|
-
if (updated === content) {
|
|
35
|
-
throw new Error("Legacy edit would not change the file.");
|
|
36
|
-
}
|
|
37
|
-
const restored = bom + restoreLineEndings(updated, lineEnding);
|
|
38
|
-
await writeTextFileAtomically(path, restored);
|
|
39
|
-
const contentMessage = `Edited file with ${edits.length} replacement(s).`;
|
|
40
|
-
return {
|
|
41
|
-
path,
|
|
42
|
-
content: contentMessage,
|
|
43
|
-
contentBlocks: [{ type: "text", text: contentMessage }],
|
|
44
|
-
details: {
|
|
45
|
-
diff: generateDiffString(content, updated),
|
|
46
|
-
firstChangedLine: firstChangedLine(content, updated),
|
|
47
|
-
lineEnding,
|
|
48
|
-
bom: Boolean(bom),
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function findUniqueMatch(content, edit, index) {
|
|
54
|
-
const first = content.indexOf(edit.oldText);
|
|
55
|
-
if (first >= 0) {
|
|
56
|
-
if (content.indexOf(edit.oldText, first + edit.oldText.length) >= 0) {
|
|
57
|
-
throw new Error(`edits[${index}].oldText matched more than once; provide a unique region.`);
|
|
58
|
-
}
|
|
59
|
-
return { ...edit, index, start: first, end: first + edit.oldText.length };
|
|
60
|
-
}
|
|
61
|
-
const fuzzy = fuzzyFind(content, edit.oldText);
|
|
62
|
-
if (!fuzzy)
|
|
63
|
-
throw new Error(`edits[${index}].oldText was not found.`);
|
|
64
|
-
if (fuzzy.duplicate) {
|
|
65
|
-
throw new Error(`edits[${index}].oldText matched more than once; provide a unique region.`);
|
|
66
|
-
}
|
|
67
|
-
return { ...edit, index, start: fuzzy.start, end: fuzzy.end };
|
|
68
|
-
}
|
|
69
|
-
function fuzzyFind(content, needle) {
|
|
70
|
-
const normalizedNeedle = normalizeForTrimmedMatch(needle);
|
|
71
|
-
const lines = content.split("\n");
|
|
72
|
-
const needleLineCount = needle.split("\n").length;
|
|
73
|
-
const matches = [];
|
|
74
|
-
const offsets = [];
|
|
75
|
-
let offset = 0;
|
|
76
|
-
for (const line of lines) {
|
|
77
|
-
offsets.push(offset);
|
|
78
|
-
offset += line.length + 1;
|
|
79
|
-
}
|
|
80
|
-
for (let line = 0; line < lines.length; line += 1) {
|
|
81
|
-
for (let count = Math.max(1, needleLineCount - 1); count <= needleLineCount + 1; count += 1) {
|
|
82
|
-
const chunk = lines.slice(line, line + count).join("\n");
|
|
83
|
-
if (normalizeForTrimmedMatch(chunk) !== normalizedNeedle)
|
|
84
|
-
continue;
|
|
85
|
-
const start = offsets[line] ?? 0;
|
|
86
|
-
const end = start + chunk.length;
|
|
87
|
-
matches.push({ start, end });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const first = matches[0];
|
|
91
|
-
if (!first)
|
|
92
|
-
return undefined;
|
|
93
|
-
return { ...first, duplicate: matches.length > 1 };
|
|
94
|
-
}
|
|
95
|
-
export function normalizeLegacyEditOperations(args) {
|
|
96
|
-
if (Array.isArray(args.edits)) {
|
|
97
|
-
if (args.edits.length === 0) {
|
|
98
|
-
throw new Error("Tool argument 'edits' must contain at least one edit.");
|
|
99
|
-
}
|
|
100
|
-
return args.edits.map((entry, index) => {
|
|
101
|
-
if (!entry || typeof entry !== "object") {
|
|
102
|
-
throw new Error(`edits[${index}] must be an object.`);
|
|
103
|
-
}
|
|
104
|
-
const edit = entry;
|
|
105
|
-
if (typeof edit.oldText !== "string" || edit.oldText.length === 0) {
|
|
106
|
-
throw new Error(`edits[${index}].oldText must be a non-empty string.`);
|
|
107
|
-
}
|
|
108
|
-
if (typeof edit.newText !== "string") {
|
|
109
|
-
throw new Error(`edits[${index}].newText must be a string.`);
|
|
110
|
-
}
|
|
111
|
-
return { oldText: edit.oldText, newText: edit.newText };
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
if (typeof args.oldText !== "string" || args.oldText.length === 0) {
|
|
115
|
-
throw new Error("Tool argument 'oldText' must be a non-empty string.");
|
|
116
|
-
}
|
|
117
|
-
if (typeof args.newText !== "string") {
|
|
118
|
-
throw new Error("Tool argument 'newText' must be a string.");
|
|
119
|
-
}
|
|
120
|
-
return [{ oldText: args.oldText, newText: args.newText }];
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=legacy-edit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-edit.js","sourceRoot":"","sources":["../../../src/execution/filesystem/legac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