@criogaid/pi-hashline-edit 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +74 -222
  2. package/README.zh-CN.md +162 -0
  3. package/package.json +2 -1
  4. package/src/core/AGENTS.md +1 -1
  5. package/src/core/apply.test.ts +172 -134
  6. package/src/core/apply.ts +28 -30
  7. package/src/core/case-fold.test.ts +11 -7
  8. package/src/core/case-fold.ts +2 -6
  9. package/src/core/character-set.ts +14 -0
  10. package/src/core/hash.test.ts +1 -25
  11. package/src/core/hash.ts +0 -5
  12. package/src/core/lines.ts +25 -7
  13. package/src/core/ranges.test.ts +41 -9
  14. package/src/core/ranges.ts +11 -4
  15. package/src/core/regex.ts +36 -6
  16. package/src/core/replace-schema.ts +18 -11
  17. package/src/core/replace.test.ts +90 -0
  18. package/src/core/replace.ts +6 -5
  19. package/src/core/search-analysis.test.ts +9 -0
  20. package/src/core/search-analysis.ts +35 -31
  21. package/src/core/search.ts +1 -1
  22. package/src/core/types.ts +5 -7
  23. package/src/index.ts +2 -4
  24. package/src/integration/config-registration.test.ts +16 -8
  25. package/src/integration/fusion-dispatch.test.ts +41 -22
  26. package/src/integration/grep-flags.test.ts +6 -13
  27. package/src/integration/grep-js-completeness.test.ts +41 -31
  28. package/src/integration/grep-order.test.ts +78 -0
  29. package/src/integration/grep-path-matrix.test.ts +4 -3
  30. package/src/integration/grep-regex.test.ts +13 -16
  31. package/src/integration/grep-rg.test.ts +127 -87
  32. package/src/integration/grep-scan-budget.test.ts +27 -5
  33. package/src/integration/large-text.test.ts +3 -4
  34. package/src/integration/model-budget-lifecycle.test.ts +15 -6
  35. package/src/integration/mutation-file-types.test.ts +0 -1
  36. package/src/integration/mutation-file-types.testing.ts +1 -1
  37. package/src/integration/npm-package.testing.ts +6 -32
  38. package/src/integration/publication-read-changes.test.ts +58 -26
  39. package/src/integration/replace-package.testing.ts +4 -1
  40. package/src/integration/replace-worker-boundary.test.ts +34 -24
  41. package/src/integration/report-replay.test.ts +2 -2
  42. package/src/integration/utf8-errors.test.ts +2 -2
  43. package/src/pi/AGENTS.md +12 -13
  44. package/src/pi/action-fusion.test.ts +71 -216
  45. package/src/pi/action-fusion.ts +37 -74
  46. package/src/pi/anchor-format.test.ts +16 -0
  47. package/src/pi/anchor-format.ts +7 -3
  48. package/src/pi/argument-diagnostics.ts +1 -1
  49. package/src/pi/argument-error.testing.ts +7 -4
  50. package/src/pi/argument-error.ts +5 -7
  51. package/src/pi/argument-format.test.ts +5 -16
  52. package/src/pi/argument-validation.test.ts +59 -25
  53. package/src/pi/argument-validation.ts +4 -5
  54. package/src/pi/budgets.ts +5 -7
  55. package/src/pi/config.test.ts +15 -5
  56. package/src/pi/config.ts +6 -6
  57. package/src/pi/diagnostic-buffer.test.ts +2 -3
  58. package/src/pi/diagnostic-buffer.ts +2 -2
  59. package/src/pi/edit-tool.ts +9 -12
  60. package/src/pi/execute.test.ts +80 -149
  61. package/src/pi/failure-context.test.ts +61 -16
  62. package/src/pi/failure-context.ts +12 -9
  63. package/src/pi/failure-path.test.ts +115 -50
  64. package/src/pi/file-commit.test.ts +30 -46
  65. package/src/pi/file-commit.ts +11 -40
  66. package/src/pi/file-revision.ts +25 -0
  67. package/src/pi/fusion-card-interaction.test.ts +143 -0
  68. package/src/pi/fusion-card.test.ts +193 -37
  69. package/src/pi/fusion-card.ts +186 -116
  70. package/src/pi/grep-candidates.ts +25 -27
  71. package/src/pi/grep-matrix.test.ts +1 -1
  72. package/src/pi/grep-order.test.ts +323 -0
  73. package/src/pi/grep-output.testing.ts +24 -0
  74. package/src/pi/grep-output.ts +62 -69
  75. package/src/pi/grep-render.ts +4 -1
  76. package/src/pi/grep-scope.ts +1 -1
  77. package/src/pi/grep-search.ts +85 -56
  78. package/src/pi/grep-tool.ts +17 -48
  79. package/src/pi/grep.test.ts +270 -169
  80. package/src/pi/mutation-outcome.testing.ts +2 -3
  81. package/src/pi/mutation-result.test.ts +26 -19
  82. package/src/pi/mutation-result.ts +25 -40
  83. package/src/pi/mutation-runner.ts +9 -17
  84. package/src/pi/output-budgets.test.ts +25 -16
  85. package/src/pi/path.ts +3 -1
  86. package/src/pi/pi.test.ts +4 -5
  87. package/src/pi/read-tool.ts +32 -80
  88. package/src/pi/read.test.ts +145 -92
  89. package/src/pi/regex-worker-contract.ts +5 -23
  90. package/src/pi/regex-worker.ts +4 -10
  91. package/src/pi/registration.test.ts +54 -49
  92. package/src/pi/render.test.ts +196 -93
  93. package/src/pi/render.ts +32 -22
  94. package/src/pi/replace-regex.ts +3 -5
  95. package/src/pi/replace-tool.ts +27 -26
  96. package/src/pi/replace-worker-contract.ts +3 -12
  97. package/src/pi/replace.test.ts +144 -226
  98. package/src/pi/report-cause.ts +23 -19
  99. package/src/pi/report-failure.testing.ts +2 -2
  100. package/src/pi/report-schema.ts +55 -43
  101. package/src/pi/report.test.ts +138 -71
  102. package/src/pi/report.ts +40 -43
  103. package/src/pi/result-safety.test.ts +157 -117
  104. package/src/pi/rg-process.test.ts +36 -10
  105. package/src/pi/rg-process.ts +9 -3
  106. package/src/pi/rg-regex.test.ts +17 -0
  107. package/src/pi/rg-regex.ts +28 -22
  108. package/src/pi/text-stream.test.ts +35 -36
  109. package/src/pi/text-stream.ts +14 -14
  110. package/src/pi/tool-call.testing.ts +17 -7
  111. package/src/pi/write-tool.ts +9 -11
  112. package/src/pi/write.test.ts +43 -75
  113. package/src/testing/regex-translation-corpus.ts +16 -0
  114. package/src/testing/rg-line-listing.fixture.mjs +1 -1
  115. package/src/integration/forget-grep.test.ts +0 -148
  116. package/src/pi/forget-tool.ts +0 -367
  117. package/src/pi/forget.test.ts +0 -630
  118. package/src/pi/forget.testing.ts +0 -201
@@ -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 schema follows the shared actionFusion switch", () => {
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", modee: "create" };
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("modee", /not allowed/),
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", output: "checked" };
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.equal(created.details.publishedRevision, await fileRevision(target));
112
- assert.equal("revision" in created.details, false);
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
- assert.equal(reportOf(exists)?.error, "TARGET_EXISTS");
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
- output: "checked",
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, { status: "succeeded", output: "checked" });
197
- assert.equal(result.details.actionFusion.freshness, "unchanged");
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", output: "checked" };
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, { status: "succeeded", output: "checked" });
224
- assert.doesNotMatch(text, /Fresh anchors:|\b1#[0-9A-Z]+\b/);
225
- assert.equal(result.details.actionFusion.freshness, "changed");
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", output: "removed" };
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
- const text = result.content.map((block: any) => block.text).join("\n");
255
- assert.ok(result.details.actionFusion);
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
- const text = result.content.map((block: any) => block.text).join("\n");
276
- assert.ok(result.details.actionFusion);
277
- assert.equal(result.details.actionFusion.freshness, "changed");
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 bytes in separate writes so parser tests exercise chunk boundaries.
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
- }