@criogaid/pi-hashline-edit 0.7.0 → 0.9.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/README.md +76 -220
- package/README.zh-CN.md +166 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +171 -133
- package/src/core/apply.ts +34 -31
- package/src/core/case-fold.test.ts +11 -7
- package/src/core/case-fold.ts +2 -6
- package/src/core/character-set.ts +14 -0
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +25 -7
- package/src/core/ranges.test.ts +49 -9
- package/src/core/ranges.ts +15 -4
- package/src/core/regex.ts +36 -6
- package/src/core/replace-schema.ts +18 -11
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +6 -5
- package/src/core/search-analysis.test.ts +9 -0
- package/src/core/search-analysis.ts +35 -31
- package/src/core/search.ts +1 -1
- package/src/core/types.ts +6 -8
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +18 -10
- package/src/integration/fusion-dispatch.test.ts +41 -22
- package/src/integration/grep-flags.test.ts +6 -13
- package/src/integration/grep-js-completeness.test.ts +41 -31
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +4 -3
- package/src/integration/grep-regex.test.ts +13 -16
- package/src/integration/grep-rg.test.ts +132 -92
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +4 -5
- package/src/integration/model-budget-lifecycle.test.ts +26 -8
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +2 -2
- package/src/integration/npm-package.testing.ts +7 -33
- package/src/integration/publication-read-changes.test.ts +60 -28
- package/src/integration/replace-package.testing.ts +4 -1
- package/src/integration/replace-worker-boundary.test.ts +34 -24
- package/src/integration/report-replay.test.ts +3 -3
- package/src/integration/utf8-errors.test.ts +3 -3
- package/src/pi/AGENTS.md +13 -14
- package/src/pi/action-fusion.test.ts +75 -220
- package/src/pi/action-fusion.ts +37 -74
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +7 -3
- package/src/pi/argument-diagnostics.ts +35 -186
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +25 -38
- package/src/pi/argument-validation.test.ts +446 -420
- package/src/pi/argument-validation.ts +4 -5
- package/src/pi/budgets.ts +5 -7
- package/src/pi/config.test.ts +15 -5
- package/src/pi/config.ts +6 -6
- package/src/pi/diagnostic-buffer.test.ts +2 -3
- package/src/pi/diagnostic-buffer.ts +2 -2
- package/src/pi/edit-tool.ts +175 -121
- package/src/pi/execute.test.ts +170 -227
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +13 -10
- package/src/pi/failure-path.test.ts +115 -50
- package/src/pi/file-commit.test.ts +30 -46
- package/src/pi/file-commit.ts +11 -40
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +193 -37
- package/src/pi/fusion-card.ts +186 -116
- package/src/pi/grep-candidates.ts +25 -27
- package/src/pi/grep-matrix.test.ts +1 -1
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +62 -69
- package/src/pi/grep-render.ts +4 -1
- package/src/pi/grep-scope.ts +1 -1
- package/src/pi/grep-search.ts +85 -56
- package/src/pi/grep-tool.ts +17 -48
- package/src/pi/grep.test.ts +271 -170
- package/src/pi/mutation-outcome.testing.ts +2 -3
- package/src/pi/mutation-result.test.ts +26 -19
- package/src/pi/mutation-result.ts +25 -40
- package/src/pi/mutation-runner.ts +9 -17
- package/src/pi/output-budgets.test.ts +27 -18
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +7 -6
- package/src/pi/read-tool.ts +32 -80
- package/src/pi/read.test.ts +145 -92
- package/src/pi/regex-worker-contract.ts +5 -23
- package/src/pi/regex-worker.ts +4 -10
- package/src/pi/registration.test.ts +106 -67
- package/src/pi/render.test.ts +239 -109
- package/src/pi/render.ts +42 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +29 -27
- package/src/pi/replace-worker-contract.ts +3 -12
- package/src/pi/replace.test.ts +144 -226
- package/src/pi/report-cause.ts +23 -19
- package/src/pi/report-failure.testing.ts +2 -2
- package/src/pi/report-schema.ts +60 -45
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +186 -131
- package/src/pi/rg-process.test.ts +36 -10
- package/src/pi/rg-process.ts +9 -3
- package/src/pi/rg-regex.test.ts +17 -0
- package/src/pi/rg-regex.ts +28 -22
- package/src/pi/text-stream.test.ts +35 -36
- package/src/pi/text-stream.ts +14 -14
- package/src/pi/tool-call.testing.ts +17 -7
- package/src/pi/write-tool.ts +9 -11
- package/src/pi/write.test.ts +43 -75
- package/src/testing/regex-translation-corpus.ts +16 -0
- package/src/testing/rg-line-listing.fixture.mjs +1 -1
- package/src/integration/forget-grep.test.ts +0 -148
- package/src/pi/forget-tool.ts +0 -367
- package/src/pi/forget.test.ts +0 -630
- package/src/pi/forget.testing.ts +0 -201
package/src/pi/write.test.ts
CHANGED
|
@@ -6,7 +6,6 @@ import assert from "node:assert/strict";
|
|
|
6
6
|
import { test } from "node:test";
|
|
7
7
|
import { makeWriteOverride } from "./write-tool.ts";
|
|
8
8
|
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
9
|
-
import { fileRevision } from "./file-commit.ts";
|
|
10
9
|
import { callTool } from "./tool-call.testing.ts";
|
|
11
10
|
import { reportOf } from "./report.ts";
|
|
12
11
|
import { REREAD } from "./report-schema.ts";
|
|
@@ -25,26 +24,16 @@ async function withTemp<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
test("write
|
|
29
|
-
const plain = makeWriteOverride("/tmp");
|
|
30
|
-
assert.equal(Object.hasOwn(plain.parameters.properties, "then_run"), false);
|
|
31
|
-
assert.equal(Object.hasOwn(plain.parameters.properties, "expectedRevision"), false);
|
|
32
|
-
const fusion = createActionFusionExecutor();
|
|
33
|
-
const withFusion = makeWriteOverride("/tmp", fusion);
|
|
34
|
-
assert.equal(Object.hasOwn(withFusion.parameters.properties, "then_run"), true);
|
|
35
|
-
assert.equal(Object.hasOwn(withFusion.parameters.properties, "expectedRevision"), false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("write rejects unknown fields rather than ignoring a misspelled create mode", async () =>
|
|
27
|
+
test("write receives an unknown field → rejects without changing the file", async () =>
|
|
39
28
|
withTemp(async (dir) => {
|
|
40
29
|
const file = join(dir, "file.txt");
|
|
41
30
|
await writeFile(file, "original\n");
|
|
42
31
|
for (const fusion of [undefined, createActionFusionExecutor()]) {
|
|
43
32
|
const tool = makeWriteOverride(dir, fusion);
|
|
44
|
-
const args = { path: "file.txt", content: "new\n",
|
|
33
|
+
const args = { path: "file.txt", content: "new\n", mode: "overwrite", unexpected: true };
|
|
45
34
|
await assert.rejects(
|
|
46
35
|
callTool(tool, args, { ctx: context(dir) }),
|
|
47
|
-
rejectsArgument("
|
|
36
|
+
rejectsArgument("unexpected", /not allowed/),
|
|
48
37
|
);
|
|
49
38
|
assert.equal(await readFile(file, "utf8"), "original\n");
|
|
50
39
|
}
|
|
@@ -77,7 +66,7 @@ test("write omits mode → rejects before changing files or running commands", a
|
|
|
77
66
|
let commandRuns = 0;
|
|
78
67
|
const fusion = createActionFusionExecutor(async () => {
|
|
79
68
|
commandRuns++;
|
|
80
|
-
return { status: "succeeded",
|
|
69
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
|
|
81
70
|
});
|
|
82
71
|
for (const executor of [undefined, fusion]) {
|
|
83
72
|
const tool = makeWriteOverride(dir, executor);
|
|
@@ -107,16 +96,24 @@ test("write supports create-only and overwrite-only modes", async () =>
|
|
|
107
96
|
{ path: "new.txt", content: "new\n", mode: "create" },
|
|
108
97
|
options,
|
|
109
98
|
);
|
|
99
|
+
assert.equal(created.content[0].type, "text");
|
|
110
100
|
assert.doesNotMatch(created.content[0].text, /Revision:|[0-9a-f]{64}/);
|
|
111
|
-
assert.
|
|
112
|
-
assert.equal("
|
|
101
|
+
assert.deepEqual(await readFile(target), Buffer.from("new\n"));
|
|
102
|
+
assert.equal(reportOf(created, "write")?.publication, "PUBLISHED");
|
|
103
|
+
assert.equal(reportOf(created, "write")?.created, true);
|
|
113
104
|
const exists = await callTool(
|
|
114
105
|
write,
|
|
115
106
|
{ path: "new.txt", content: "bad\n", mode: "create" },
|
|
116
107
|
options,
|
|
117
108
|
);
|
|
118
109
|
assert.equal(exists.isError, true);
|
|
119
|
-
|
|
110
|
+
const conflict = reportOf(exists, "write");
|
|
111
|
+
assert.equal(conflict?.error, "TARGET_EXISTS");
|
|
112
|
+
assert.equal(conflict?.publication, "NOT_PUBLISHED");
|
|
113
|
+
const next = conflict?.next ?? "";
|
|
114
|
+
assert.match(next, /check the path/i);
|
|
115
|
+
assert.match(next, /read the existing file/i);
|
|
116
|
+
assert.match(next, /overwrite.*only if.*intended/i);
|
|
120
117
|
assert.equal(await readFile(target, "utf8"), "new\n");
|
|
121
118
|
const missing = await callTool(
|
|
122
119
|
write,
|
|
@@ -124,31 +121,11 @@ test("write supports create-only and overwrite-only modes", async () =>
|
|
|
124
121
|
options,
|
|
125
122
|
);
|
|
126
123
|
assert.equal(missing.isError, true);
|
|
127
|
-
assert.equal(reportOf(missing)?.error, "PATH_NOT_FOUND");
|
|
124
|
+
assert.equal(reportOf(missing, "write")?.error, "PATH_NOT_FOUND");
|
|
128
125
|
await callTool(write, { path: "new.txt", content: "updated\n", mode: "overwrite" }, options);
|
|
129
126
|
assert.equal(await readFile(target, "utf8"), "updated\n");
|
|
130
127
|
}));
|
|
131
128
|
|
|
132
|
-
test("write rejects obsolete expectedRevision without overwriting", async () =>
|
|
133
|
-
withTemp(async (dir) => {
|
|
134
|
-
const target = join(dir, "concurrent.txt");
|
|
135
|
-
await writeFile(target, "original\n");
|
|
136
|
-
const params = {
|
|
137
|
-
path: target,
|
|
138
|
-
content: "changed\n",
|
|
139
|
-
mode: "overwrite",
|
|
140
|
-
expectedRevision: await fileRevision(target),
|
|
141
|
-
};
|
|
142
|
-
for (const fusion of [undefined, createActionFusionExecutor()]) {
|
|
143
|
-
const write = makeWriteOverride(dir, fusion);
|
|
144
|
-
await assert.rejects(
|
|
145
|
-
callTool(write, params, { ctx: context(dir) }),
|
|
146
|
-
rejectsArgument("expectedRevision", /not allowed/),
|
|
147
|
-
);
|
|
148
|
-
assert.equal(await readFile(target, "utf8"), "original\n");
|
|
149
|
-
}
|
|
150
|
-
}));
|
|
151
|
-
|
|
152
129
|
test("write returns only a summary for empty, short, and long content", async () =>
|
|
153
130
|
withTemp(async (dir) => {
|
|
154
131
|
const contents = [
|
|
@@ -165,10 +142,13 @@ test("write returns only a summary for empty, short, and long content", async ()
|
|
|
165
142
|
undefined,
|
|
166
143
|
context(dir),
|
|
167
144
|
);
|
|
168
|
-
assert.equal(reportOf(result)?.created, true);
|
|
169
|
-
assert.equal(reportOf(result)?.path, path);
|
|
170
|
-
assert.equal(reportOf(result)?.publication, "PUBLISHED");
|
|
145
|
+
assert.equal(reportOf(result, "write")?.created, true);
|
|
146
|
+
assert.equal(reportOf(result, "write")?.path, path);
|
|
147
|
+
assert.equal(reportOf(result, "write")?.publication, "PUBLISHED");
|
|
171
148
|
assert.equal(result.content.length, 1);
|
|
149
|
+
const block = result.content[0];
|
|
150
|
+
assert.equal(block.type, "text");
|
|
151
|
+
assert.deepEqual(JSON.parse(block.text), { publication: "PUBLISHED", created: true });
|
|
172
152
|
assert.equal(await readFile(join(dir, path), "utf8"), content);
|
|
173
153
|
}
|
|
174
154
|
}));
|
|
@@ -177,7 +157,7 @@ test("write returns its summary and command output after an unchanged then_run",
|
|
|
177
157
|
withTemp(async (dir) => {
|
|
178
158
|
const fusion = createActionFusionExecutor(async () => ({
|
|
179
159
|
status: "succeeded",
|
|
180
|
-
|
|
160
|
+
result: { content: [{ type: "text", text: "checked" }] },
|
|
181
161
|
}));
|
|
182
162
|
const write = makeWriteOverride(dir, fusion) as any;
|
|
183
163
|
const result = await write.execute(
|
|
@@ -192,9 +172,11 @@ test("write returns its summary and command output after an unchanged then_run",
|
|
|
192
172
|
undefined,
|
|
193
173
|
context(dir),
|
|
194
174
|
);
|
|
195
|
-
assert.equal(reportOf(result)?.created, true);
|
|
196
|
-
assert.deepEqual(reportOf(result)?.then_run, {
|
|
197
|
-
|
|
175
|
+
assert.equal(reportOf(result, "write")?.created, true);
|
|
176
|
+
assert.deepEqual(reportOf(result, "write")?.then_run, {
|
|
177
|
+
status: "succeeded",
|
|
178
|
+
output: "checked",
|
|
179
|
+
});
|
|
198
180
|
}));
|
|
199
181
|
|
|
200
182
|
test("write reports changed freshness when then_run changes the target", async () =>
|
|
@@ -202,7 +184,7 @@ test("write reports changed freshness when then_run changes the target", async (
|
|
|
202
184
|
const target = join(dir, "changed.txt");
|
|
203
185
|
const fusion = createActionFusionExecutor(async () => {
|
|
204
186
|
await writeFile(target, "command changed\n");
|
|
205
|
-
return { status: "succeeded",
|
|
187
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
|
|
206
188
|
});
|
|
207
189
|
const write = makeWriteOverride(dir, fusion) as any;
|
|
208
190
|
const result = await callTool(
|
|
@@ -217,12 +199,14 @@ test("write reports changed freshness when then_run changes the target", async (
|
|
|
217
199
|
);
|
|
218
200
|
const text = result.content.map((block: any) => block.text).join("\n");
|
|
219
201
|
assert.doesNotMatch(text, /revision:|[0-9a-f]{64}/i);
|
|
220
|
-
assert.equal(reportOf(result)?.created, true);
|
|
221
|
-
assert.equal(reportOf(result)?.freshness, "changed");
|
|
222
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
223
|
-
assert.deepEqual(reportOf(result)?.then_run, {
|
|
224
|
-
|
|
225
|
-
|
|
202
|
+
assert.equal(reportOf(result, "write")?.created, true);
|
|
203
|
+
assert.equal(reportOf(result, "write")?.freshness, "changed");
|
|
204
|
+
assert.equal(reportOf(result, "write")?.next, REREAD);
|
|
205
|
+
assert.deepEqual(reportOf(result, "write")?.then_run, {
|
|
206
|
+
status: "succeeded",
|
|
207
|
+
output: "checked",
|
|
208
|
+
});
|
|
209
|
+
assert.doesNotMatch(text, /\b1#[0-9A-Z]+\b/);
|
|
226
210
|
const rendered = write
|
|
227
211
|
.renderResult(result, { isPartial: false }, theme, { isError: false })
|
|
228
212
|
.render(100)
|
|
@@ -237,7 +221,7 @@ test("write reports missing freshness when then_run removes the target", async (
|
|
|
237
221
|
const target = join(dir, "missing.txt");
|
|
238
222
|
const fusion = createActionFusionExecutor(async () => {
|
|
239
223
|
await rm(target);
|
|
240
|
-
return { status: "succeeded",
|
|
224
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "removed" }] } };
|
|
241
225
|
});
|
|
242
226
|
const result = await makeWriteOverride(dir, fusion).execute(
|
|
243
227
|
"missing",
|
|
@@ -251,11 +235,8 @@ test("write reports missing freshness when then_run removes the target", async (
|
|
|
251
235
|
undefined,
|
|
252
236
|
context(dir),
|
|
253
237
|
);
|
|
254
|
-
|
|
255
|
-
assert.
|
|
256
|
-
assert.equal(result.details.actionFusion.freshness, "missing");
|
|
257
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
258
|
-
assert.doesNotMatch(text, /Fresh anchors:/);
|
|
238
|
+
assert.equal(reportOf(result, "write")?.freshness, "missing");
|
|
239
|
+
assert.equal(reportOf(result, "write")?.next, REREAD);
|
|
259
240
|
}));
|
|
260
241
|
|
|
261
242
|
test("write preserves command failure and changed freshness", async () =>
|
|
@@ -272,20 +253,7 @@ test("write preserves command failure and changed freshness", async () =>
|
|
|
272
253
|
undefined,
|
|
273
254
|
context(dir),
|
|
274
255
|
);
|
|
275
|
-
|
|
276
|
-
assert.
|
|
277
|
-
assert.equal(result
|
|
278
|
-
assert.equal(result.details.actionFusion.command, "failed");
|
|
279
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
280
|
-
assert.doesNotMatch(text, /Fresh anchors:/);
|
|
281
|
-
}));
|
|
282
|
-
|
|
283
|
-
test("write rejects NUL content", async () =>
|
|
284
|
-
withTemp(async (dir) => {
|
|
285
|
-
const write = makeWriteOverride(dir);
|
|
286
|
-
await assert.rejects(
|
|
287
|
-
callTool(write, { path: "nul.txt", content: "a\0b", mode: "create" }, { ctx: context(dir) }),
|
|
288
|
-
rejectsArgument("content", /NUL/),
|
|
289
|
-
);
|
|
290
|
-
await assert.rejects(readFile(join(dir, "nul.txt")), /ENOENT/);
|
|
256
|
+
assert.equal(reportOf(result, "write")?.freshness, "changed");
|
|
257
|
+
assert.equal(reportOf(result, "write")?.then_run?.status, "failed");
|
|
258
|
+
assert.equal(reportOf(result, "write")?.next, REREAD);
|
|
291
259
|
}));
|
|
@@ -120,6 +120,22 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
120
120
|
rejectCandidates: true,
|
|
121
121
|
source: local,
|
|
122
122
|
},
|
|
123
|
+
{
|
|
124
|
+
pattern: "(?<=(a)\\1)",
|
|
125
|
+
flags: "",
|
|
126
|
+
hits: ["a", "ab"],
|
|
127
|
+
misses: ["b"],
|
|
128
|
+
rejectCandidates: true,
|
|
129
|
+
source: local,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
pattern: "(?<=\\1(a))",
|
|
133
|
+
flags: "",
|
|
134
|
+
hits: ["aa"],
|
|
135
|
+
misses: ["a", "ab"],
|
|
136
|
+
rejectCandidates: true,
|
|
137
|
+
source: local,
|
|
138
|
+
},
|
|
123
139
|
{
|
|
124
140
|
pattern: "(cat|dog)\\1",
|
|
125
141
|
flags: "",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Emit protocol
|
|
1
|
+
// Emit protocol records for real-process smoke and termination checks.
|
|
2
2
|
const chunks = JSON.parse(process.argv[2]);
|
|
3
3
|
for (const chunk of chunks) {
|
|
4
4
|
await new Promise((resolve) => process.stdout.write(Buffer.from(chunk, "base64"), resolve));
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/** Real ripgrep results consumed and forgotten through Pi's session lifecycle. */
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { writeFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { test } from "node:test";
|
|
6
|
-
import { FORGET_MIN_BYTES } from "../pi/budgets.ts";
|
|
7
|
-
import {
|
|
8
|
-
assertForgotten,
|
|
9
|
-
finish,
|
|
10
|
-
forgetCall,
|
|
11
|
-
openForgetSession,
|
|
12
|
-
SESSION_TIMEOUT_MS,
|
|
13
|
-
taggedResultId,
|
|
14
|
-
toolResponse,
|
|
15
|
-
toolResult,
|
|
16
|
-
} from "../pi/forget.testing.ts";
|
|
17
|
-
import { reportOf } from "../pi/report.ts";
|
|
18
|
-
|
|
19
|
-
for (const encoding of ["UTF-8", "invalid UTF-8"] as const) {
|
|
20
|
-
test(`real grep of ${encoding} logs then forget → matched content is absent from the next request`, {
|
|
21
|
-
timeout: SESSION_TIMEOUT_MS,
|
|
22
|
-
}, async (t) => {
|
|
23
|
-
const f = await openForgetSession(t);
|
|
24
|
-
const path = join(f.cwd, "search.log");
|
|
25
|
-
const rowPayloadChars = 128;
|
|
26
|
-
const rowCount = Math.ceil(FORGET_MIN_BYTES / rowPayloadChars);
|
|
27
|
-
const rows = Array.from(
|
|
28
|
-
{ length: rowCount },
|
|
29
|
-
(_, index) => `needle ${index} ${"x".repeat(rowPayloadChars)}`,
|
|
30
|
-
);
|
|
31
|
-
const bytes = Buffer.concat([
|
|
32
|
-
Buffer.from(rows.join("\n")),
|
|
33
|
-
encoding === "invalid UTF-8" ? Buffer.from([0xff]) : Buffer.alloc(0),
|
|
34
|
-
Buffer.from("\n"),
|
|
35
|
-
]);
|
|
36
|
-
await writeFile(path, bytes);
|
|
37
|
-
await f.prompt(
|
|
38
|
-
toolResponse({
|
|
39
|
-
type: "toolCall",
|
|
40
|
-
id: "search",
|
|
41
|
-
name: "grep",
|
|
42
|
-
arguments: { path, pattern: "needle", literal: true },
|
|
43
|
-
}),
|
|
44
|
-
(messages) => toolResponse(forgetCall(messages, "search")),
|
|
45
|
-
finish,
|
|
46
|
-
);
|
|
47
|
-
const original = toolResult(f.requests[1], "search");
|
|
48
|
-
assert.equal(original.isError, false);
|
|
49
|
-
const text = original.content
|
|
50
|
-
.filter((block) => block.type === "text")
|
|
51
|
-
.map((block) => block.text)
|
|
52
|
-
.join("\n");
|
|
53
|
-
assert.ok(text.includes(rows[0]));
|
|
54
|
-
if (encoding === "invalid UTF-8") assert.ok(text.includes("\uFFFD"));
|
|
55
|
-
const id = taggedResultId(original);
|
|
56
|
-
assert.ok(id);
|
|
57
|
-
const forgotten = toolResult(f.requests[2], "search");
|
|
58
|
-
assertForgotten(forgotten, id);
|
|
59
|
-
const receipt = forgotten.content[0];
|
|
60
|
-
assert.ok(receipt.type === "text" && !receipt.text.includes("needle"));
|
|
61
|
-
assert.ok(receipt.type === "text" && !receipt.text.includes("search.log"));
|
|
62
|
-
const displayReceipt = `grep /needle/ · ${rows.length} matches in 1 file`;
|
|
63
|
-
assert.partialDeepStrictEqual(f.rawResult("forget-call").details, {
|
|
64
|
-
forgotten: [{ id, receipt: displayReceipt }],
|
|
65
|
-
});
|
|
66
|
-
assert.deepEqual(reportOf(f.rawResult("forget-call"))?.forgotten, [id]);
|
|
67
|
-
assert.ok(f.renderForgetCard().includes(displayReceipt));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
test("real grep reaches its limit across files → forget card reports the returned counts", {
|
|
72
|
-
timeout: SESSION_TIMEOUT_MS,
|
|
73
|
-
}, async (t) => {
|
|
74
|
-
const f = await openForgetSession(t);
|
|
75
|
-
const rowPayloadChars = 256;
|
|
76
|
-
const rowsPerFile = Math.ceil(FORGET_MIN_BYTES / rowPayloadChars) + 1;
|
|
77
|
-
const limit = rowsPerFile + 1;
|
|
78
|
-
const paths = [join(f.cwd, "one.log"), join(f.cwd, "two.log")];
|
|
79
|
-
const rows = Array.from(
|
|
80
|
-
{ length: rowsPerFile },
|
|
81
|
-
(_, index) => `${index % 2 === 0 ? "needle" : "backup"} ${"x".repeat(rowPayloadChars)}`,
|
|
82
|
-
);
|
|
83
|
-
await Promise.all(paths.map((path) => writeFile(path, `${rows.join("\n")}\n`)));
|
|
84
|
-
await f.prompt(
|
|
85
|
-
toolResponse({
|
|
86
|
-
type: "toolCall",
|
|
87
|
-
id: "search",
|
|
88
|
-
name: "grep",
|
|
89
|
-
arguments: { path: paths, pattern: ["needle", "backup"], literal: true, limit },
|
|
90
|
-
}),
|
|
91
|
-
(messages) => toolResponse(forgetCall(messages, "search")),
|
|
92
|
-
finish,
|
|
93
|
-
);
|
|
94
|
-
const id = taggedResultId(toolResult(f.requests[1], "search"));
|
|
95
|
-
assert.ok(id);
|
|
96
|
-
const receipt = `grep /needle | backup/ · ${limit} matches in ${paths.length} files · limit reached`;
|
|
97
|
-
assert.partialDeepStrictEqual(f.rawResult("forget-call").details, {
|
|
98
|
-
forgotten: [{ id, receipt }],
|
|
99
|
-
});
|
|
100
|
-
assert.deepEqual(reportOf(f.rawResult("forget-call"))?.forgotten, [id]);
|
|
101
|
-
assert.ok(f.renderForgetCard().includes(receipt));
|
|
102
|
-
assertForgotten(toolResult(f.requests[2], "search"), id);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
for (const outputMode of [undefined, "content", null, "files", "count"] as const) {
|
|
106
|
-
test(`codemode grep outputMode=${String(outputMode)} → only content output can be forgotten`, {
|
|
107
|
-
timeout: SESSION_TIMEOUT_MS,
|
|
108
|
-
}, async (t) => {
|
|
109
|
-
const f = await openForgetSession(t);
|
|
110
|
-
const path = join(f.cwd, "search.log");
|
|
111
|
-
await writeFile(path, `needle ${"x".repeat(FORGET_MIN_BYTES)}\n`);
|
|
112
|
-
const args = { path, pattern: "needle", literal: true, outputMode };
|
|
113
|
-
const eligible = outputMode === undefined || outputMode === null || outputMode === "content";
|
|
114
|
-
await f.prompt(
|
|
115
|
-
toolResponse({
|
|
116
|
-
type: "toolCall",
|
|
117
|
-
id: "script-search",
|
|
118
|
-
name: "codemode",
|
|
119
|
-
arguments: {
|
|
120
|
-
code: `text(await tools.grep(${JSON.stringify(args)})); text("padding".repeat(${FORGET_MIN_BYTES}));`,
|
|
121
|
-
},
|
|
122
|
-
}),
|
|
123
|
-
(messages) => {
|
|
124
|
-
const result = toolResult(messages, "script-search");
|
|
125
|
-
assert.equal(result.isError, false);
|
|
126
|
-
const id = taggedResultId(result);
|
|
127
|
-
if (eligible) {
|
|
128
|
-
assert.ok(id, "Content-mode inspection output needs a parent tag");
|
|
129
|
-
return toolResponse(forgetCall(messages, "script-search"));
|
|
130
|
-
}
|
|
131
|
-
assert.equal(id, undefined, "Summary-only grep must not make a script forgettable");
|
|
132
|
-
return finish;
|
|
133
|
-
},
|
|
134
|
-
...(eligible ? [finish] : []),
|
|
135
|
-
);
|
|
136
|
-
const original = toolResult(f.requests[1], "script-search");
|
|
137
|
-
const text = original.content
|
|
138
|
-
.filter((block) => block.type === "text")
|
|
139
|
-
.map((block) => block.text)
|
|
140
|
-
.join("\n");
|
|
141
|
-
assert.equal([...text.matchAll(/"resultId": "r[0-9a-f]{5}"/g)].length, eligible ? 1 : 0);
|
|
142
|
-
if (eligible) {
|
|
143
|
-
const id = taggedResultId(original);
|
|
144
|
-
assert.ok(id);
|
|
145
|
-
assertForgotten(toolResult(f.requests[2], "script-search"), id);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|