@criogaid/pi-hashline-edit 0.5.0 → 0.6.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 (66) hide show
  1. package/README.md +66 -22
  2. package/package.json +6 -6
  3. package/src/core/apply.test.ts +66 -16
  4. package/src/core/apply.ts +36 -19
  5. package/src/core/lines.ts +3 -3
  6. package/src/core/text.test.ts +30 -1
  7. package/src/core/text.ts +8 -3
  8. package/src/index.ts +2 -0
  9. package/src/integration/forget-grep.test.ts +98 -0
  10. package/src/integration/fusion-dispatch.test.ts +343 -0
  11. package/src/integration/grep-rg.test.ts +466 -111
  12. package/src/integration/large-text.test.ts +3 -5
  13. package/src/integration/mutation-file-types.test.ts +44 -0
  14. package/src/pi/action-fusion.test.ts +158 -79
  15. package/src/pi/action-fusion.ts +105 -34
  16. package/src/pi/anchor-format.test.ts +46 -0
  17. package/src/pi/anchor-format.ts +21 -2
  18. package/src/pi/argument-validation.test.ts +136 -0
  19. package/src/pi/argument-validation.ts +103 -0
  20. package/src/pi/budgets.ts +4 -1
  21. package/src/pi/config.test.ts +1 -0
  22. package/src/pi/config.ts +4 -0
  23. package/src/pi/diagnostic-buffer.test.ts +58 -0
  24. package/src/pi/diagnostic-buffer.ts +59 -0
  25. package/src/pi/directory-sync.test.ts +1 -1
  26. package/src/pi/edit-tool.ts +56 -37
  27. package/src/pi/execute.test.ts +185 -645
  28. package/src/pi/failure-context.test.ts +4 -3
  29. package/src/pi/failure-path.test.ts +3 -3
  30. package/src/pi/file-commit.test.ts +24 -17
  31. package/src/pi/file-commit.ts +36 -9
  32. package/src/pi/file-snapshot.test.ts +24 -0
  33. package/src/pi/forget-tool.ts +268 -0
  34. package/src/pi/forget.test.ts +343 -0
  35. package/src/pi/forget.testing.ts +273 -0
  36. package/src/pi/fusion-card.test.ts +26 -0
  37. package/src/pi/fusion-card.ts +21 -6
  38. package/src/pi/grep-output.ts +82 -55
  39. package/src/pi/grep-render.ts +8 -11
  40. package/src/pi/grep-scope.ts +6 -31
  41. package/src/pi/grep-search.ts +94 -58
  42. package/src/pi/grep-tool.ts +50 -59
  43. package/src/pi/grep.test.ts +412 -208
  44. package/src/pi/mutation-result.test.ts +23 -0
  45. package/src/pi/mutation-runner.ts +8 -4
  46. package/src/pi/path.ts +16 -2
  47. package/src/pi/pi.test.ts +4 -3
  48. package/src/pi/read-tool.ts +59 -27
  49. package/src/pi/read.test.ts +361 -0
  50. package/src/pi/registration.test.ts +121 -4
  51. package/src/pi/render.test.ts +172 -15
  52. package/src/pi/render.ts +28 -5
  53. package/src/pi/replace-tool.ts +18 -27
  54. package/src/pi/replace.test.ts +8 -107
  55. package/src/pi/result-safety.test.ts +123 -149
  56. package/src/pi/rg-match-bytes.ts +95 -0
  57. package/src/pi/rg-process.test.ts +40 -59
  58. package/src/pi/rg-process.ts +8 -5
  59. package/src/pi/rg-text-view.ts +59 -9
  60. package/src/pi/text-stream.test.ts +153 -0
  61. package/src/pi/text-stream.ts +33 -13
  62. package/src/pi/tool-call.testing.ts +50 -0
  63. package/src/pi/tool-prompts.ts +15 -0
  64. package/src/pi/write-tool.ts +19 -26
  65. package/src/pi/write.test.ts +70 -61
  66. package/src/pi/e2e-scenarios.test.ts +0 -360
@@ -17,7 +17,6 @@ import { makeEditOverride } from "./edit-tool.ts";
17
17
  import { validateToolArguments } from "@earendil-works/pi-ai";
18
18
  import { callTool } from "./tool-call.testing.ts";
19
19
  import { createActionFusionExecutor } from "./action-fusion.ts";
20
- import { generateMutationDetails } from "./mutation-result.ts";
21
20
  import { DEFAULT_CONFIG } from "./config.ts";
22
21
 
23
22
  async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
@@ -44,20 +43,6 @@ const stubTheme = { fg: (_k: string, s: string) => s, bold: (s: string) => s } a
44
43
  // singleton — initialize it once for this test process (watcher off by default).
45
44
  initTheme();
46
45
 
47
- test("replace find guidance distinguishes literal escapes and regex line anchors", () => {
48
- const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG);
49
- const description: unknown = Reflect.get(
50
- tool.parameters.properties.replacements.items.properties.find,
51
- "description",
52
- );
53
- assert.ok(typeof description === "string");
54
- assert.match(description, /JavaScript regex/);
55
- assert.match(description, /not grep's ripgrep syntax/);
56
- assert.match(description, /CRLF.*LF.*\\n/);
57
- assert.match(description, /literal mode.*backslash followed by n.*two characters/);
58
- assert.match(description, /regex mode.*\^ and \$.*m flag.*per line/);
59
- });
60
-
61
46
  test("replace schema requires a non-empty replacements array", async () => {
62
47
  for (const fusion of [undefined, createActionFusionExecutor()]) {
63
48
  const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG, fusion);
@@ -524,95 +509,6 @@ test("replace: multiline replacement (changes line count) still reports a correc
524
509
  });
525
510
  });
526
511
 
527
- test("replace renderResult: renders the diff without throwing", async () => {
528
- await withDir(async (dir) => {
529
- const f = join(dir, "f.txt");
530
- await writeFile(f, "a\nb\nc\n");
531
- const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
532
- const r: any = await call(tool, { path: "f.txt", replacements: [{ find: "b", replace: "B" }] });
533
- const comp = tool.renderResult(
534
- { content: r.content, details: r.details },
535
- { isPartial: false, expanded: true },
536
- stubTheme,
537
- {
538
- args: { path: "f.txt", replacements: [{ find: "b", replace: "B" }] },
539
- isError: r.isError ?? false,
540
- state: {},
541
- invalidate: () => {},
542
- } as Parameters<typeof tool.renderResult>[3],
543
- );
544
- assert.match(comp.render(80).join("\n"), /B/, "rendered diff should contain the new content");
545
- });
546
- });
547
-
548
- test("replace renderResult: renders the error line without throwing", async () => {
549
- await withDir(async (dir) => {
550
- const f = join(dir, "f.txt");
551
- await writeFile(f, "a\n");
552
- const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
553
- let thrown: any;
554
- const r: any = await call(tool, {
555
- path: "f.txt",
556
- replacements: [{ find: "zzz", replace: "y" }],
557
- }).catch((e: any) => {
558
- thrown = e;
559
- return null;
560
- });
561
- assert.ok(thrown, "expected the call to throw");
562
- const comp = tool.renderResult(
563
- {
564
- content: [{ type: "text", text: thrown.message }],
565
- details: generateMutationDetails(
566
- "f.txt",
567
- "a\n",
568
- "a\n",
569
- { publishedRevision: "r", observedRevision: "r" },
570
- "PUBLISHED",
571
- ),
572
- },
573
- { isPartial: false, expanded: false },
574
- stubTheme,
575
- {
576
- args: { path: "f.txt", replacements: [{ find: "zzz", replace: "y" }] },
577
- isError: true,
578
- } as Parameters<typeof tool.renderResult>[3],
579
- );
580
- assert.match(comp.render(80).join("\n"), /zero matches|no matches|match/i);
581
- });
582
- });
583
-
584
- test("replace header: renderResult refreshes the call header in place — no invalidate", async () => {
585
- await withDir(async (dir) => {
586
- const f = join(dir, "f.txt");
587
- await writeFile(f, "a\nb\nc\n");
588
- const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
589
- const args = { path: "f.txt", replacements: [{ find: "b", replace: "B1\nB2" }] };
590
- const r: any = await call(tool, args);
591
- let invalidated = false;
592
- const context: any = {
593
- args,
594
- isError: false,
595
- state: {},
596
- invalidate: () => {
597
- invalidated = true;
598
- },
599
- };
600
- const header: any = tool.renderCall(args, stubTheme, context);
601
- assert.match(header.text, /1 rule\b/);
602
- assert.ok(!header.text.includes("+2"), "pre-execution header must not show counts");
603
- tool.renderResult(
604
- { content: r.content, details: r.details },
605
- { isPartial: false, expanded: true },
606
- stubTheme,
607
- context,
608
- );
609
- assert.deepEqual(context.state.diffCounts, { added: 2, removed: 1 });
610
- assert.ok(header.text.includes("+2"), "header should show added count");
611
- assert.ok(header.text.includes("-1"), "header should show removed count");
612
- assert.ok(!invalidated, "renderResult must not call invalidate");
613
- });
614
- });
615
-
616
512
  test("replace header retains the rule count when a long path wraps", () => {
617
513
  const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG);
618
514
  const args = {
@@ -662,7 +558,7 @@ test("invalid batches reject every change and never run a fused command", async
662
558
  DEFAULT_CONFIG,
663
559
  createActionFusionExecutor(async () => {
664
560
  commands++;
665
- return "done";
561
+ return { status: "succeeded", output: "done" };
666
562
  }),
667
563
  );
668
564
  const first = { find: "bar", replace: "changed" };
@@ -807,10 +703,11 @@ test("successful batches run one command against the complete result", async ()
807
703
  const tool = makeReplaceTool(
808
704
  dir,
809
705
  DEFAULT_CONFIG,
810
- createActionFusionExecutor(async () => {
706
+ createActionFusionExecutor(async (_toolCallId, input) => {
707
+ assert.equal(input.command, "check");
811
708
  commands++;
812
709
  assert.equal(await readFile(file, "utf8"), "bar baz");
813
- return "checked";
710
+ return { status: "succeeded", output: "checked" };
814
711
  }),
815
712
  );
816
713
  const result = await tool.execute(
@@ -830,6 +727,10 @@ test("successful batches run one command against the complete result", async ()
830
727
  assert.equal(commands, 1);
831
728
  assert.ok(result.details.actionFusion);
832
729
  assert.equal(result.details.actionFusion.command, "succeeded");
730
+ assert.equal(result.details.actionFusion.freshness, "unchanged");
731
+ const command = result.content[1];
732
+ assert.ok(command.type === "text");
733
+ assert.match(command.text, /checked/);
833
734
  assert.ok(result.content[0].type === "text");
834
735
  assert.match(result.content[0].text, /Updated anchors/);
835
736
  }));