@chances-ai/engine 28.0.0 → 30.0.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/agents/index.js +1 -1
- package/dist/ai/adapters/ai-sdk-stream.js +15 -0
- package/dist/ai/adapters/ai-sdk-stream.js.map +1 -1
- package/dist/ai/adapters/ai-sdk.js +1 -1
- package/dist/ai/adapters/ai-sdk.js.map +1 -1
- package/dist/ai/setup.d.ts +1 -1
- package/dist/ai/setup.js +1 -1
- package/dist/ai/types.d.ts +13 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/core/engine.d.ts +17 -3
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +49 -3
- package/dist/core/engine.js.map +1 -1
- package/dist/core/task-tool.d.ts +1 -1
- package/dist/core/task-tool.js +1 -1
- package/dist/core/workspace-query.d.ts +1 -1
- package/dist/core/workspace-query.js +1 -1
- package/dist/hashline/apply.d.ts +9 -0
- package/dist/hashline/apply.d.ts.map +1 -0
- package/dist/hashline/apply.js +523 -0
- package/dist/hashline/apply.js.map +1 -0
- package/dist/hashline/block.d.ts +25 -0
- package/dist/hashline/block.d.ts.map +1 -0
- package/dist/hashline/block.js +71 -0
- package/dist/hashline/block.js.map +1 -0
- package/dist/hashline/format.d.ts +106 -0
- package/dist/hashline/format.d.ts.map +1 -0
- package/dist/hashline/format.js +191 -0
- package/dist/hashline/format.js.map +1 -0
- package/dist/hashline/fs.d.ts +87 -0
- package/dist/hashline/fs.d.ts.map +1 -0
- package/dist/hashline/fs.js +123 -0
- package/dist/hashline/fs.js.map +1 -0
- package/dist/hashline/index.d.ts +27 -0
- package/dist/hashline/index.d.ts.map +1 -0
- package/dist/hashline/index.js +27 -0
- package/dist/hashline/index.js.map +1 -0
- package/dist/hashline/input.d.ts +101 -0
- package/dist/hashline/input.d.ts.map +1 -0
- package/dist/hashline/input.js +378 -0
- package/dist/hashline/input.js.map +1 -0
- package/dist/hashline/messages.d.ts +87 -0
- package/dist/hashline/messages.d.ts.map +1 -0
- package/dist/hashline/messages.js +94 -0
- package/dist/hashline/messages.js.map +1 -0
- package/dist/hashline/mismatch.d.ts +45 -0
- package/dist/hashline/mismatch.d.ts.map +1 -0
- package/dist/hashline/mismatch.js +118 -0
- package/dist/hashline/mismatch.js.map +1 -0
- package/dist/hashline/normalize.d.ts +22 -0
- package/dist/hashline/normalize.d.ts.map +1 -0
- package/dist/hashline/normalize.js +31 -0
- package/dist/hashline/normalize.js.map +1 -0
- package/dist/hashline/parser.d.ts +24 -0
- package/dist/hashline/parser.d.ts.map +1 -0
- package/dist/hashline/parser.js +295 -0
- package/dist/hashline/parser.js.map +1 -0
- package/dist/hashline/patcher.d.ts +111 -0
- package/dist/hashline/patcher.d.ts.map +1 -0
- package/dist/hashline/patcher.js +332 -0
- package/dist/hashline/patcher.js.map +1 -0
- package/dist/hashline/recovery.d.ts +41 -0
- package/dist/hashline/recovery.d.ts.map +1 -0
- package/dist/hashline/recovery.js +175 -0
- package/dist/hashline/recovery.js.map +1 -0
- package/dist/hashline/snapshots.d.ts +62 -0
- package/dist/hashline/snapshots.d.ts.map +1 -0
- package/dist/hashline/snapshots.js +127 -0
- package/dist/hashline/snapshots.js.map +1 -0
- package/dist/hashline/tokenizer.d.ts +66 -0
- package/dist/hashline/tokenizer.d.ts.map +1 -0
- package/dist/hashline/tokenizer.js +408 -0
- package/dist/hashline/tokenizer.js.map +1 -0
- package/dist/hashline/types.d.ts +117 -0
- package/dist/hashline/types.d.ts.map +1 -0
- package/dist/hashline/types.js +13 -0
- package/dist/hashline/types.js.map +1 -0
- package/dist/local-vault/index.d.ts +1 -1
- package/dist/local-vault/index.js +1 -1
- package/dist/lsp/index.d.ts +1 -1
- package/dist/lsp/index.js +1 -1
- package/dist/lsp/types.d.ts +2 -2
- package/dist/mcp/host.d.ts +3 -3
- package/dist/mcp/load-mcp-host.d.ts +4 -4
- package/dist/mcp/load-mcp-host.js +4 -4
- package/dist/mcp/oauth/provider.d.ts.map +1 -1
- package/dist/mcp/oauth/provider.js +10 -1
- package/dist/mcp/oauth/provider.js.map +1 -1
- package/dist/plugin-api/index.d.ts +10 -2
- package/dist/plugin-api/index.d.ts.map +1 -1
- package/dist/plugin-api/index.js +15 -0
- package/dist/plugin-api/index.js.map +1 -1
- package/dist/tools/approval.d.ts +1 -1
- package/dist/tools/approval.js +1 -1
- package/dist/tools/builtins/_hashline-fs.d.ts +16 -0
- package/dist/tools/builtins/_hashline-fs.d.ts.map +1 -0
- package/dist/tools/builtins/_hashline-fs.js +62 -0
- package/dist/tools/builtins/_hashline-fs.js.map +1 -0
- package/dist/tools/builtins/_image.d.ts +26 -0
- package/dist/tools/builtins/_image.d.ts.map +1 -0
- package/dist/tools/builtins/_image.js +76 -0
- package/dist/tools/builtins/_image.js.map +1 -0
- package/dist/tools/builtins/_login-shell.d.ts +17 -0
- package/dist/tools/builtins/_login-shell.d.ts.map +1 -0
- package/dist/tools/builtins/_login-shell.js +66 -0
- package/dist/tools/builtins/_login-shell.js.map +1 -0
- package/dist/tools/builtins/_notebook.d.ts +15 -0
- package/dist/tools/builtins/_notebook.d.ts.map +1 -0
- package/dist/tools/builtins/_notebook.js +81 -0
- package/dist/tools/builtins/_notebook.js.map +1 -0
- package/dist/tools/builtins/_pdf.d.ts +19 -0
- package/dist/tools/builtins/_pdf.d.ts.map +1 -0
- package/dist/tools/builtins/_pdf.js +42 -0
- package/dist/tools/builtins/_pdf.js.map +1 -0
- package/dist/tools/builtins/_shared.d.ts +11 -0
- package/dist/tools/builtins/_shared.d.ts.map +1 -1
- package/dist/tools/builtins/_shared.js +40 -1
- package/dist/tools/builtins/_shared.js.map +1 -1
- package/dist/tools/builtins/ast-edit.d.ts +18 -0
- package/dist/tools/builtins/ast-edit.d.ts.map +1 -0
- package/dist/tools/builtins/ast-edit.js +109 -0
- package/dist/tools/builtins/ast-edit.js.map +1 -0
- package/dist/tools/builtins/ast-grep.d.ts +6 -0
- package/dist/tools/builtins/ast-grep.d.ts.map +1 -0
- package/dist/tools/builtins/ast-grep.js +67 -0
- package/dist/tools/builtins/ast-grep.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +13 -2
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +112 -31
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/lsp.js +1 -1
- package/dist/tools/builtins/pty.d.ts +1 -1
- package/dist/tools/builtins/read.d.ts.map +1 -1
- package/dist/tools/builtins/read.js +187 -11
- package/dist/tools/builtins/read.js.map +1 -1
- package/dist/tools/builtins.d.ts.map +1 -1
- package/dist/tools/builtins.js +4 -0
- package/dist/tools/builtins.js.map +1 -1
- package/dist/tools/file-lock.d.ts +8 -0
- package/dist/tools/file-lock.d.ts.map +1 -1
- package/dist/tools/file-lock.js +22 -0
- package/dist/tools/file-lock.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.ts +27 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Tool } from "../types.js";
|
|
2
|
+
/** Turn an `AST_UNAVAILABLE`/native error into model-facing guidance. */
|
|
3
|
+
declare function astErr(err: unknown, tool: string): string;
|
|
4
|
+
export declare const astGrepTool: Tool;
|
|
5
|
+
export { astErr };
|
|
6
|
+
//# sourceMappingURL=ast-grep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-grep.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/ast-grep.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AASpD,yEAAyE;AACzE,iBAAS,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,eAAO,MAAM,WAAW,EAAE,IAiDzB,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { native } from "@chances-ai/native";
|
|
2
|
+
import { containReadPath, optNum, optStr, preview, str } from "./_shared.js";
|
|
3
|
+
/** Collapse a (possibly multi-line) match to a single trimmed preview line. */
|
|
4
|
+
function oneLine(text, max = 100) {
|
|
5
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
6
|
+
return flat.length > max ? `${flat.slice(0, max)}…` : flat;
|
|
7
|
+
}
|
|
8
|
+
/** Turn an `AST_UNAVAILABLE`/native error into model-facing guidance. */
|
|
9
|
+
function astErr(err, tool) {
|
|
10
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
11
|
+
if (/AST|unavailable|not a function/i.test(msg)) {
|
|
12
|
+
return `${tool} is unavailable in this build (the native tree-sitter module is absent). Use grep for a text search instead.`;
|
|
13
|
+
}
|
|
14
|
+
return `${tool} failed: ${msg}`;
|
|
15
|
+
}
|
|
16
|
+
export const astGrepTool = {
|
|
17
|
+
name: "ast_grep",
|
|
18
|
+
category: "file-read",
|
|
19
|
+
description: "Structural code search with an ast-grep pattern (e.g. `console.log($A)`, `function $F($$$) { $$$ }`). " +
|
|
20
|
+
"Matches by SYNTAX, not text — robust to formatting, whitespace, and line breaks. Returns `path:line:col` " +
|
|
21
|
+
"hits. Prefer over `grep` when you want to match a code shape rather than a string. `path` may be a file or " +
|
|
22
|
+
"directory (default: workspace root); `lang` is inferred from extension; `glob` filters a directory walk.",
|
|
23
|
+
parameters: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
pattern: { type: "string" },
|
|
27
|
+
path: { type: "string", description: "File or directory to search (default: workspace root)." },
|
|
28
|
+
lang: { type: "string", description: "Language alias (e.g. ts, rust); inferred from extension if omitted." },
|
|
29
|
+
glob: { type: "string", description: "Glob filter for relative paths in a directory search." },
|
|
30
|
+
limit: { type: "number", description: "Max matches to return (default 100)." },
|
|
31
|
+
},
|
|
32
|
+
required: ["pattern"],
|
|
33
|
+
},
|
|
34
|
+
summarize: (args) => {
|
|
35
|
+
const where = optStr(args, "path");
|
|
36
|
+
return `ast-grep ${preview(str(args, "pattern"))}${where ? ` in ${where}` : ""}`;
|
|
37
|
+
},
|
|
38
|
+
async execute(args, ctx) {
|
|
39
|
+
const pattern = str(args, "pattern");
|
|
40
|
+
const path = containReadPath(ctx, optStr(args, "path") ?? ".");
|
|
41
|
+
try {
|
|
42
|
+
const res = await native.astGrep({
|
|
43
|
+
pattern,
|
|
44
|
+
path,
|
|
45
|
+
lang: optStr(args, "lang"),
|
|
46
|
+
glob: optStr(args, "glob"),
|
|
47
|
+
limit: optNum(args, "limit"),
|
|
48
|
+
});
|
|
49
|
+
if (res.matches.length === 0) {
|
|
50
|
+
return { ok: true, output: `No matches for ${JSON.stringify(pattern)} (searched ${res.filesSearched} file(s)).` };
|
|
51
|
+
}
|
|
52
|
+
const lines = res.matches.map((m) => `${m.path}:${m.startLine}:${m.startColumn} ${oneLine(m.text)}`);
|
|
53
|
+
const more = res.limitReached
|
|
54
|
+
? `\n… ${res.totalMatches} total matches; showing ${res.matches.length}. Raise limit or narrow the pattern.`
|
|
55
|
+
: "";
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
output: `${res.totalMatches} match(es) across ${res.filesSearched} file(s):\n${lines.join("\n")}${more}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
return { ok: false, output: astErr(err, "ast_grep") };
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
export { astErr };
|
|
67
|
+
//# sourceMappingURL=ast-grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-grep.js","sourceRoot":"","sources":["../../../src/tools/builtins/ast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E,CAAC;YACpH,CAAC;YACD,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtG,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY;gBAC3B,CAAC,CAAC,OAAO,GAAG,CAAC,YAAY,2BAA2B,GAAG,CAAC,OAAO,CAAC,MAAM,sCAAsC;gBAC5G,CAAC,CAAC,EAAE,CAAC;YACP,OAAO;gBACL,EAAE,EAAE,IAAI;gBACR,MAAM,EAAE,GAAG,GAAG,CAAC,YAAY,qBAAqB,GAAG,CAAC,aAAa,cAAc,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE;aACzG,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;CACF,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAoHpD,eAAO,MAAM,QAAQ,EAAE,IA+EtB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { native } from "@chances-ai/native";
|
|
2
2
|
import { isBashCommandReadOnly } from "../bash-readonly.js";
|
|
3
|
-
import { cleanOutput, optNum, persistFullOutput, str } from "./_shared.js";
|
|
3
|
+
import { cleanOutput, optNum, persistFullOutput, pruneToolResultsRing, str } from "./_shared.js";
|
|
4
|
+
import { ensureLoginShellPath } from "./_login-shell.js";
|
|
4
5
|
/**
|
|
5
6
|
* `bash` runs a shell command in a real PTY when the native addon is
|
|
6
7
|
* loaded — programs see `isatty(stdout) === true`, signals propagate to
|
|
@@ -83,9 +84,16 @@ function formatBody(cleaned, workspaceRoot, runtimeDropped, callId) {
|
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
const persistedPath = persistFullOutput(workspaceRoot, cleaned, "bash", "output.txt", callId);
|
|
87
|
+
// (7.9 [5.10], goose) Give the model EXACT read-back commands, not a vague
|
|
88
|
+
// "output truncated" — it can page the persisted file deterministically.
|
|
89
|
+
const readBack = persistedPath
|
|
90
|
+
? ` Read more with \`sed -n '1,400p' ${persistedPath}\`, \`tail -n 200 ${persistedPath}\`, or \`grep -n PATTERN ${persistedPath}\`.`
|
|
91
|
+
: "";
|
|
86
92
|
const banner = persistedPath
|
|
87
|
-
? `[output truncated: showing first ${headStr} KB of ${totalStr} KB; full output saved to ${persistedPath}${runtimeNote}]`
|
|
93
|
+
? `[output truncated: showing first ${headStr} KB of ${totalStr} KB; full output saved to ${persistedPath}${runtimeNote}.${readBack}]`
|
|
88
94
|
: `[output truncated: showing first ${headStr} KB of ${totalStr} KB; persistence failed, remainder dropped${runtimeNote}]`;
|
|
95
|
+
if (persistedPath)
|
|
96
|
+
pruneToolResultsRing(workspaceRoot);
|
|
89
97
|
return {
|
|
90
98
|
body: `${banner}\n${head}`,
|
|
91
99
|
persistedPath,
|
|
@@ -122,6 +130,9 @@ export const bashTool = {
|
|
|
122
130
|
async execute(args, ctx) {
|
|
123
131
|
const command = str(args, "command");
|
|
124
132
|
const timeoutMs = clampTimeoutMs(optNum(args, "timeout"));
|
|
133
|
+
// (7.9 [5.9]) Ensure the child inherits the user's real PATH even when the
|
|
134
|
+
// process was GUI-launched (Electron desktop). One-shot, best-effort.
|
|
135
|
+
ensureLoginShellPath();
|
|
125
136
|
const result = await native.ptyRun({
|
|
126
137
|
command,
|
|
127
138
|
cwd: ctx.cwd,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;;;GAgBG;AAEH;;8CAE8C;AAC9C,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;uDACuD;AACvD,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEnC;;;uBAGuB;AAEvB,SAAS,cAAc,CAAC,UAA8B;IACpD,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,kBAAkB,CAAC;IACxD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI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E,+DAA+D;QAC/D,8CAA8C;QAC9C,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC;QAC5D,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,MAAM,CAAC,oBAAoB,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;aAC5E,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,aAAa,EAAE,CAAC;QACrD,CAAC;QACD,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM,CAAC,QAAQ,IAAI,SAAS,GAAG,EAAE,IAAI,CAAC;SAC/D,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,MAAM,CAAC,MAAc,EAAE,IAAY;IAC1C,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,IAAI,EAAE,CAAC;AAC3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/edit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/edit.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,aAAa,CAAC;AAyDjE,eAAO,MAAM,QAAQ,EAAE,IA+DtB,CAAC"}
|
|
@@ -1,45 +1,126 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { AppError, ErrorCode } from "@chances-ai/runtime";
|
|
3
|
+
import { InMemorySnapshotStore, MismatchError, Patch, Patcher, } from "../../hashline/index.js";
|
|
4
4
|
import { linesDiff } from "../diff.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { withSortedFileLocks } from "../file-lock.js";
|
|
6
|
+
import { EngineToolFs, makeBlockResolver } from "./_hashline-fs.js";
|
|
7
|
+
import { hashlineSnapshotKey, str } from "./_shared.js";
|
|
8
|
+
/**
|
|
9
|
+
* The model-facing hashline edit contract (7.9 [5.1], R1-S8/S9). Carried on the
|
|
10
|
+
* tool `description` so it reaches the provider. Distilled from oh-my-pi's
|
|
11
|
+
* battle-tested `prompt.md`.
|
|
12
|
+
*/
|
|
13
|
+
const EDIT_TOOL_PROMPT = `Edit existing files with a hashline patch. (To CREATE a file, use the write tool.)
|
|
14
|
+
|
|
15
|
+
A patch is one or more file sections. Each section starts with a header copied verbatim from your latest read/search output:
|
|
16
|
+
¶path#TAG
|
|
17
|
+
TAG is the 4-hex snapshot tag; it binds the edit to that exact file version and is REQUIRED.
|
|
18
|
+
|
|
19
|
+
Ops (line numbers are from read's LINE:TEXT, refer to the ORIGINAL file, and stay valid for the whole patch — they do NOT shift as hunks apply):
|
|
20
|
+
replace N..M: replace original lines N..M with the +body rows below (single line: replace N..N: or replace N:).
|
|
21
|
+
replace block N: replace the whole syntactic block that BEGINS on line N (tree-sitter; point N at the opening line, not a closing brace).
|
|
22
|
+
delete N..M delete original lines N..M. No body. (single: delete N)
|
|
23
|
+
delete block N delete the whole syntactic block beginning on line N. No body.
|
|
24
|
+
insert before N: insert the +body rows immediately before line N.
|
|
25
|
+
insert after N: insert the +body rows immediately after line N.
|
|
26
|
+
insert head: insert at the very start of the file.
|
|
27
|
+
insert tail: insert at the very end of the file.
|
|
28
|
+
|
|
29
|
+
Body rows appear only under a ':' header and are ALWAYS '+TEXT' (a new literal line, verbatim; '+' alone is a blank line). There is NO '-old' row and no bare/context row — the range does the deleting; the body is only the final new content. To insert a line starting with '+' or '-', prefix it: '++x' / '+-x'.
|
|
30
|
+
|
|
31
|
+
Rules:
|
|
32
|
+
- Keep ranges TIGHT: cover only lines whose content actually changes. To change lines 2 and 5 while keeping 3-4, issue two hunks (replace 2..2: and replace 5..5:).
|
|
33
|
+
- Multiple files / multiple hunks: just stack more sections / ops (this replaces any separate multi-edit tool). For a global rename across files, prefer the ast_edit tool.
|
|
34
|
+
- RE-GROUND AFTER EVERY EDIT: each applied edit mints a fresh #TAG and renumbers the file, so the tag and line numbers you just used are dead. Anchor the next edit on the ¶path#TAG and lines from THIS edit's response (or re-read). On a stale-tag rejection or any unexpected result, STOP and re-read — never stack more line-numbered edits onto output you have not re-grounded.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
¶src/util.ts#1A2B
|
|
38
|
+
replace 2..2:
|
|
39
|
+
+ const greeting = "Hi";
|
|
40
|
+
delete 5`;
|
|
41
|
+
/** Extract a human-readable message from an unknown thrown value. */
|
|
42
|
+
function errMsg(err) {
|
|
43
|
+
return err instanceof Error ? err.message : String(err);
|
|
44
|
+
}
|
|
45
|
+
/** Best-effort structured-diff preview for one section (permission overlay). */
|
|
46
|
+
function previewSection(section, ctx) {
|
|
47
|
+
try {
|
|
48
|
+
const abs = hashlineSnapshotKey(ctx, section.path);
|
|
49
|
+
if (!existsSync(abs))
|
|
50
|
+
return `edit ${section.path}: (file not found)`;
|
|
51
|
+
const before = readFileSync(abs, "utf8").replace(/\r\n?/g, "\n");
|
|
52
|
+
const after = section.applyPartialTo(before, makeBlockResolver()).text;
|
|
53
|
+
return `edit ${section.path}\n${linesDiff(before, after)}`;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
const hunks = section.diff.split("\n").filter((l) => /^\s*(replace|delete|insert)\b/.test(l)).length;
|
|
57
|
+
return `edit ${section.path}: ${hunks} hunk(s)`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
7
60
|
export const editTool = {
|
|
8
61
|
name: "edit",
|
|
9
|
-
description: "Replace an exact, unique substring in a workspace file.",
|
|
10
62
|
category: "file-write",
|
|
63
|
+
description: EDIT_TOOL_PROMPT,
|
|
11
64
|
parameters: {
|
|
12
65
|
type: "object",
|
|
13
|
-
properties: {
|
|
14
|
-
required: ["
|
|
66
|
+
properties: { patch: { type: "string", description: "A hashline patch (see the tool description)." } },
|
|
67
|
+
required: ["patch"],
|
|
15
68
|
},
|
|
16
|
-
summarize: (args) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
69
|
+
summarize: (args, ctx) => {
|
|
70
|
+
try {
|
|
71
|
+
const patch = Patch.parse(str(args, "patch"), { cwd: ctx.cwd });
|
|
72
|
+
if (patch.sections.length === 0)
|
|
73
|
+
return "edit (no sections)";
|
|
74
|
+
return patch.sections.map((s) => previewSection(s, ctx)).join("\n");
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return `edit (unparseable patch: ${errMsg(err)})`;
|
|
22
78
|
}
|
|
23
|
-
return `edit ${path}\n${linesDiff(find, replace)}`;
|
|
24
79
|
},
|
|
25
80
|
async execute(args, ctx) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
let patch;
|
|
82
|
+
try {
|
|
83
|
+
patch = Patch.parse(str(args, "patch"), { cwd: ctx.cwd });
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return { ok: false, output: errMsg(err) };
|
|
87
|
+
}
|
|
88
|
+
if (patch.sections.length === 0) {
|
|
89
|
+
return { ok: false, output: "No hashline sections found. Each section starts with `¶path#TAG` from your latest read." };
|
|
90
|
+
}
|
|
91
|
+
const snapshots = ctx.snapshots ?? new InMemorySnapshotStore();
|
|
92
|
+
const fs = new EngineToolFs(ctx);
|
|
93
|
+
const patcher = new Patcher({ fs, snapshots, blockResolver: makeBlockResolver() });
|
|
94
|
+
const lockPaths = patch.sections.map((s) => hashlineSnapshotKey(ctx, s.path));
|
|
95
|
+
// (R1-M1) Hold every affected file's mutation lock across the WHOLE
|
|
96
|
+
// prepare(all)+commit(all) span — hash check, apply, restore, and write all
|
|
97
|
+
// run inside the lock so a concurrent writer (another subagent, task 08)
|
|
98
|
+
// can't slip between preflight and write. Sorted acquisition = deadlock-free.
|
|
99
|
+
return withSortedFileLocks(lockPaths, async () => {
|
|
100
|
+
try {
|
|
101
|
+
const result = await patcher.apply(patch);
|
|
102
|
+
const blocks = result.sections.map((s) => {
|
|
103
|
+
const firstChange = s.firstChangedLine !== undefined ? ` (first change at line ${s.firstChangedLine})` : "";
|
|
104
|
+
const warns = s.warnings.length > 0 ? `\n${s.warnings.map((w) => `⚠ ${w}`).join("\n")}` : "";
|
|
105
|
+
return `${s.header}${firstChange}${warns}`;
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
output: `Edited ${result.sections.length} file(s). The tags below are fresh — anchor any follow-up edit on them ` +
|
|
110
|
+
`(the tags and line numbers you just used are now dead):\n${blocks.join("\n")}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
// Security violations (realpath jail escape / protected path) are hard
|
|
115
|
+
// failures — let them propagate so the write path can never be coaxed
|
|
116
|
+
// into a soft "couldn't apply" that the model might retry around.
|
|
117
|
+
if (err instanceof AppError && err.code === ErrorCode.Permission)
|
|
118
|
+
throw err;
|
|
119
|
+
// Stale-tag / unrecoverable mismatch → re-read (carries the file preview).
|
|
120
|
+
if (err instanceof MismatchError)
|
|
121
|
+
return { ok: false, output: err.displayMessage };
|
|
122
|
+
return { ok: false, output: errMsg(err) };
|
|
123
|
+
}
|
|
43
124
|
});
|
|
44
125
|
},
|
|
45
126
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/builtins/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/builtins/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,KAAK,EAEL,OAAO,GACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExD;;;;GAIG;AACH,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;WA2Bd,CAAC;AAEZ,qEAAqE;AACrE,SAAS,MAAM,CAAC,GAAY;IAC1B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,gFAAgF;AAChF,SAAS,cAAc,CAAC,OAAqB,EAAE,GAAgB;IAC7D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACnD,IAA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E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC;gBACnF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* (4.2) `lsp` built-in tool — read-only LSP queries.
|
|
3
3
|
*
|
|
4
4
|
* One tool, nine ops, claude-code-shape. The actual host
|
|
5
|
-
* (`@chances-ai/lsp`) is wired in at boot via `ToolContext.lsp`;
|
|
5
|
+
* (`@chances-ai/engine/lsp`) is wired in at boot via `ToolContext.lsp`;
|
|
6
6
|
* when absent, the tool fails fast so the model sees the install hint.
|
|
7
7
|
*
|
|
8
8
|
* Category is `integration` (codex Round-1 MUST-FIX #4) — NOT `search`.
|
|
@@ -56,7 +56,7 @@ export interface CreatePtyToolDeps {
|
|
|
56
56
|
worktreeCwd?: string;
|
|
57
57
|
/** Handle factory injected from outside — the engine wires this to
|
|
58
58
|
* `native.createPtySession.bind(native)`. Threaded through the deps
|
|
59
|
-
* object rather than imported so `@chances-ai/tools` stays free of a
|
|
59
|
+
* object rather than imported so `@chances-ai/engine/tools` stays free of a
|
|
60
60
|
* `@chances-ai/native` runtime import. */
|
|
61
61
|
createHandle: PtyHandleFactory;
|
|
62
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/read.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AA2EpD,eAAO,MAAM,QAAQ,EAAE,IA+HtB,CAAC"}
|
|
@@ -1,18 +1,194 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { native } from "@chances-ai/native";
|
|
3
|
+
import { formatHashlineHeader, formatNumberedLine, normalizeToLF, stripBom } from "../../hashline/index.js";
|
|
4
|
+
import { readImageAsParts, sniffImageMime } from "./_image.js";
|
|
5
|
+
import { renderNotebook } from "./_notebook.js";
|
|
6
|
+
import { readPdfAsText, sniffPdf } from "./_pdf.js";
|
|
7
|
+
import { containReadPath, hashlineSnapshotKey, optNum, str } from "./_shared.js";
|
|
8
|
+
/** Hard ceiling on file size we will read into memory at all. */
|
|
9
|
+
const MAX_READ_BYTES = 50 * 1024 * 1024;
|
|
10
|
+
/** First-window byte sample used for binary/UTF-8 sniffing. */
|
|
11
|
+
const SNIFF_BYTES = 8192;
|
|
12
|
+
/** Default token budget for a single read's rendered body (override per env). */
|
|
13
|
+
const DEFAULT_MAX_TOKENS = 25_000;
|
|
14
|
+
/** Token cap from the environment, clamped to a sane floor. (7.9 R1-OQ2) */
|
|
15
|
+
function readMaxTokens() {
|
|
16
|
+
const raw = Number.parseInt(process.env.CHANCES_READ_MAX_TOKENS ?? "", 10);
|
|
17
|
+
return Number.isFinite(raw) && raw >= 1000 ? raw : DEFAULT_MAX_TOKENS;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read-dedup stub (7.9 [5.4]): a bounded ring of `key|offset|limit → mtimeMs`.
|
|
21
|
+
* A repeated read of the same window whose file mtime is unchanged returns an
|
|
22
|
+
* "unchanged" note (plus the live `¶path#TAG` so a follow-up edit still anchors)
|
|
23
|
+
* instead of re-spending tokens on the body.
|
|
24
|
+
*
|
|
25
|
+
* **Per-session, not per-process (7.9 §3.3 fix):** the ring is keyed by the
|
|
26
|
+
* session's `SnapshotStore` identity via a `WeakMap`, so a long-running `serve`
|
|
27
|
+
* process can never return "unchanged since your last read" to a client session
|
|
28
|
+
* that never read the file (cross-session leakage in the original global map).
|
|
29
|
+
* It is GC-collected with the session. A shared fallback map covers direct tool
|
|
30
|
+
* calls / tests that wire no store (single-process, no isolation concern).
|
|
31
|
+
*/
|
|
32
|
+
const READ_DEDUP_CAP = 256;
|
|
33
|
+
const READ_DEDUP_BY_SESSION = new WeakMap();
|
|
34
|
+
const READ_DEDUP_FALLBACK = new Map();
|
|
35
|
+
function dedupStoreFor(ctx) {
|
|
36
|
+
const owner = ctx.snapshots;
|
|
37
|
+
if (!owner)
|
|
38
|
+
return READ_DEDUP_FALLBACK;
|
|
39
|
+
let store = READ_DEDUP_BY_SESSION.get(owner);
|
|
40
|
+
if (!store) {
|
|
41
|
+
store = new Map();
|
|
42
|
+
READ_DEDUP_BY_SESSION.set(owner, store);
|
|
43
|
+
}
|
|
44
|
+
return store;
|
|
45
|
+
}
|
|
46
|
+
function dedupRemember(store, key, mtimeMs) {
|
|
47
|
+
store.delete(key);
|
|
48
|
+
store.set(key, mtimeMs);
|
|
49
|
+
while (store.size > READ_DEDUP_CAP) {
|
|
50
|
+
const oldest = store.keys().next().value;
|
|
51
|
+
if (oldest === undefined)
|
|
52
|
+
break;
|
|
53
|
+
store.delete(oldest);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** True when `buf` looks binary: a NUL byte, or invalid UTF-8 in the sniff window. */
|
|
57
|
+
function looksBinary(buf) {
|
|
58
|
+
const window = buf.subarray(0, SNIFF_BYTES);
|
|
59
|
+
if (window.includes(0))
|
|
60
|
+
return true;
|
|
61
|
+
try {
|
|
62
|
+
new TextDecoder("utf-8", { fatal: true }).decode(window);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Estimate tokens with a 4×-byte fast-reject before the (more expensive) real
|
|
70
|
+
* count (claude-code shape): if a 4-bytes-per-token lower bound is already under
|
|
71
|
+
* the cap, skip the native count entirely. */
|
|
72
|
+
function withinTokenCap(text, cap) {
|
|
73
|
+
if (Buffer.byteLength(text, "utf8") / 4 <= cap)
|
|
74
|
+
return true;
|
|
75
|
+
return native.countTokensExact(text).tokens <= cap;
|
|
76
|
+
}
|
|
3
77
|
export const readTool = {
|
|
4
78
|
name: "read",
|
|
5
|
-
description: "Read a UTF-8 text file from the workspace.",
|
|
6
79
|
category: "file-read",
|
|
7
|
-
|
|
8
|
-
|
|
80
|
+
description: "Read a UTF-8 text file from the workspace. Output is `¶path#TAG` (the hashline " +
|
|
81
|
+
"snapshot tag) followed by `LINE:TEXT` numbered lines (1-indexed). Copy the " +
|
|
82
|
+
"`¶path#TAG` header and the bare LINE numbers into the `edit` tool — the tag binds " +
|
|
83
|
+
"your edit to this exact file version. Use `offset` (1-indexed start line) and " +
|
|
84
|
+
"`limit` (line count) to page large files; oversized output is capped and asks you " +
|
|
85
|
+
"to page. Images are returned as vision input; PDFs and Jupyter notebooks (.ipynb) " +
|
|
86
|
+
"are rendered as read-only text (no editable tag). Binary, device, and over-large " +
|
|
87
|
+
"files are refused.",
|
|
88
|
+
parameters: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
path: { type: "string" },
|
|
92
|
+
offset: { type: "number", description: "1-indexed first line to show (default 1)." },
|
|
93
|
+
limit: { type: "number", description: "Maximum number of lines to show." },
|
|
94
|
+
},
|
|
95
|
+
required: ["path"],
|
|
96
|
+
},
|
|
97
|
+
summarize: (args) => {
|
|
98
|
+
const offset = optNum(args, "offset");
|
|
99
|
+
const limit = optNum(args, "limit");
|
|
100
|
+
const window = offset !== undefined || limit !== undefined ? ` (lines ${offset ?? 1}..${limit ? (offset ?? 1) + limit - 1 : "end"})` : "";
|
|
101
|
+
return `read ${str(args, "path")}${window}`;
|
|
102
|
+
},
|
|
9
103
|
async execute(args, ctx) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
104
|
+
const rel = str(args, "path");
|
|
105
|
+
const abs = containReadPath(ctx, rel);
|
|
106
|
+
if (!existsSync(abs))
|
|
107
|
+
return { ok: false, output: `No such file: ${rel}` };
|
|
108
|
+
const stat = statSync(abs);
|
|
109
|
+
if (!stat.isFile()) {
|
|
110
|
+
return { ok: false, output: `Not a regular file (device/socket/fifo/directory): ${rel}` };
|
|
111
|
+
}
|
|
112
|
+
if (stat.size > MAX_READ_BYTES) {
|
|
113
|
+
return { ok: false, output: `File too large to read (${stat.size} bytes > ${MAX_READ_BYTES}). Use grep/glob to locate, or a bash tail/sed window.` };
|
|
114
|
+
}
|
|
115
|
+
const buf = readFileSync(abs);
|
|
116
|
+
// (7.9 [5.5]) Image files → vision content parts (before the binary reject,
|
|
117
|
+
// which would otherwise refuse them). The model sees the pixels via the
|
|
118
|
+
// engine's vision-gated injection; clients render them from the tool:result.
|
|
119
|
+
const imageMime = sniffImageMime(buf);
|
|
120
|
+
if (imageMime) {
|
|
121
|
+
return readImageAsParts(buf, rel, imageMime);
|
|
122
|
+
}
|
|
123
|
+
// (7.9 [5.5]) PDFs are binary → extract text before the binary reject.
|
|
124
|
+
if (sniffPdf(buf)) {
|
|
125
|
+
return readPdfAsText(buf, rel);
|
|
126
|
+
}
|
|
127
|
+
// (7.9 [5.5]) Jupyter notebooks are JSON text, but the raw escaped source +
|
|
128
|
+
// base64 output blobs are unreadable — render a compact cell view instead.
|
|
129
|
+
if (rel.toLowerCase().endsWith(".ipynb")) {
|
|
130
|
+
return renderNotebook(buf.toString("utf8"), rel);
|
|
131
|
+
}
|
|
132
|
+
if (looksBinary(buf)) {
|
|
133
|
+
return { ok: false, output: `Binary file, not shown (${stat.size} bytes): ${rel}` };
|
|
134
|
+
}
|
|
135
|
+
// Canonical full text the tag binds to + the snapshot key both read and edit agree on.
|
|
136
|
+
const raw = buf.toString("utf8");
|
|
137
|
+
const { text: noBom } = stripBom(raw);
|
|
138
|
+
const fullText = normalizeToLF(noBom);
|
|
139
|
+
const key = hashlineSnapshotKey(ctx, rel);
|
|
140
|
+
const tag = ctx.snapshots?.record(key, fullText);
|
|
141
|
+
const header = tag ? formatHashlineHeader(rel, tag) : `¶${rel}`;
|
|
142
|
+
const offset = Math.max(1, Math.trunc(optNum(args, "offset") ?? 1));
|
|
143
|
+
const limitArg = optNum(args, "limit");
|
|
144
|
+
const limit = limitArg !== undefined ? Math.max(0, Math.trunc(limitArg)) : undefined;
|
|
145
|
+
// read-dedup: same window + unchanged mtime → skip the body, keep the tag.
|
|
146
|
+
const dedup = dedupStoreFor(ctx);
|
|
147
|
+
const dedupKey = `${key}|${offset}|${limit ?? "all"}`;
|
|
148
|
+
if (dedup.get(dedupKey) === stat.mtimeMs) {
|
|
149
|
+
return {
|
|
150
|
+
ok: true,
|
|
151
|
+
output: `${header}\n(unchanged since your last read of this window — file not modified. Use the tag above to edit, or read a different window.)`,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const lines = fullText.split("\n");
|
|
155
|
+
const total = lines.length;
|
|
156
|
+
const start = Math.min(offset, total + 1);
|
|
157
|
+
const end = limit !== undefined ? Math.min(start - 1 + limit, total) : total;
|
|
158
|
+
const windowLines = lines.slice(start - 1, end);
|
|
159
|
+
let body = windowLines.map((line, i) => formatNumberedLine(start + i, line)).join("\n");
|
|
160
|
+
const cap = readMaxTokens();
|
|
161
|
+
let capped = false;
|
|
162
|
+
// Number of lines actually shown — drives the continue-offset. (R2-SHOULD:
|
|
163
|
+
// counting non-blank lines undercounts windows with blank lines.)
|
|
164
|
+
let shownCount = windowLines.length;
|
|
165
|
+
if (!withinTokenCap(body, cap)) {
|
|
166
|
+
// Binary-search the largest line prefix that fits the token cap.
|
|
167
|
+
let lo = 0;
|
|
168
|
+
let hi = windowLines.length;
|
|
169
|
+
while (lo < hi) {
|
|
170
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
171
|
+
const candidate = windowLines.slice(0, mid).map((line, i) => formatNumberedLine(start + i, line)).join("\n");
|
|
172
|
+
if (withinTokenCap(candidate, cap))
|
|
173
|
+
lo = mid;
|
|
174
|
+
else
|
|
175
|
+
hi = mid - 1;
|
|
176
|
+
}
|
|
177
|
+
body = windowLines.slice(0, lo).map((line, i) => formatNumberedLine(start + i, line)).join("\n");
|
|
178
|
+
shownCount = lo;
|
|
179
|
+
capped = true;
|
|
180
|
+
}
|
|
181
|
+
dedupRemember(dedup, dedupKey, stat.mtimeMs);
|
|
182
|
+
const shownEnd = capped ? start - 1 + shownCount : end;
|
|
183
|
+
const footerParts = [];
|
|
184
|
+
if (start > 1 || shownEnd < total) {
|
|
185
|
+
footerParts.push(`(showing lines ${start}..${shownEnd} of ${total})`);
|
|
186
|
+
}
|
|
187
|
+
if (capped) {
|
|
188
|
+
footerParts.push(`output capped at ~${cap} tokens — continue with offset:${shownEnd + 1}`);
|
|
189
|
+
}
|
|
190
|
+
const footer = footerParts.length > 0 ? `\n${footerParts.join(" ")}` : "";
|
|
191
|
+
return { ok: true, output: `${header}\n${body}${footer}` };
|
|
16
192
|
},
|
|
17
193
|
};
|
|
18
194
|
//# sourceMappingURL=read.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/tools/builtins/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/tools/builtins/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAE5G,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACh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{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../src/tools/builtins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../src/tools/builtins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAcvC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,IAAI,EAa9B,CAAC"}
|
package/dist/tools/builtins.js
CHANGED
|
@@ -8,6 +8,8 @@ import { diffTool } from "./builtins/diff.js";
|
|
|
8
8
|
import { webFetchTool } from "./builtins/web-fetch.js";
|
|
9
9
|
import { lspTool } from "./builtins/lsp.js";
|
|
10
10
|
import { askUserQuestionTool } from "./builtins/ask-user-question.js";
|
|
11
|
+
import { astGrepTool } from "./builtins/ast-grep.js";
|
|
12
|
+
import { astEditTool } from "./builtins/ast-edit.js";
|
|
11
13
|
/**
|
|
12
14
|
* Registry of first-party tools the engine ships with. New tools live in their
|
|
13
15
|
* own module under `./builtins/<name>.ts`; this file is a pure barrel so the
|
|
@@ -25,5 +27,7 @@ export const builtinTools = [
|
|
|
25
27
|
webFetchTool,
|
|
26
28
|
lspTool,
|
|
27
29
|
askUserQuestionTool,
|
|
30
|
+
astGrepTool,
|
|
31
|
+
astEditTool,
|
|
28
32
|
];
|
|
29
33
|
//# sourceMappingURL=builtins.js.map
|