@criogaid/pi-hashline-edit 0.3.0 → 0.4.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 (69) hide show
  1. package/README.md +59 -50
  2. package/package.json +8 -3
  3. package/src/core/apply.test.ts +366 -310
  4. package/src/core/apply.ts +269 -202
  5. package/src/core/hash.test.ts +61 -23
  6. package/src/core/hash.ts +45 -16
  7. package/src/core/lines.test.ts +46 -27
  8. package/src/core/lines.ts +36 -28
  9. package/src/core/ranges.test.ts +73 -19
  10. package/src/core/ranges.ts +15 -15
  11. package/src/core/text.test.ts +3 -3
  12. package/src/core/text.ts +28 -9
  13. package/src/core/types.ts +54 -36
  14. package/src/index.ts +22 -16
  15. package/src/integration/grep-rg.test.ts +834 -219
  16. package/src/integration/large-text.test.ts +62 -0
  17. package/src/integration/replace-package.test.ts +37 -0
  18. package/src/pi/action-fusion.test.ts +535 -206
  19. package/src/pi/action-fusion.ts +469 -244
  20. package/src/pi/anchor-format.test.ts +30 -19
  21. package/src/pi/anchor-format.ts +27 -14
  22. package/src/pi/budgets.ts +20 -0
  23. package/src/pi/config.test.ts +60 -30
  24. package/src/pi/config.ts +45 -32
  25. package/src/pi/directory-sync.test.ts +55 -0
  26. package/src/pi/e2e-scenarios.test.ts +359 -0
  27. package/src/pi/edit-tool.ts +426 -262
  28. package/src/pi/error-text.ts +21 -0
  29. package/src/pi/execute.test.ts +1594 -694
  30. package/src/pi/failure-context.test.ts +105 -83
  31. package/src/pi/failure-context.ts +83 -71
  32. package/src/pi/failure-path.test.ts +171 -64
  33. package/src/pi/file-commit.test.ts +446 -233
  34. package/src/pi/file-commit.ts +347 -203
  35. package/src/pi/fusion-card.test.ts +118 -83
  36. package/src/pi/fusion-card.ts +120 -85
  37. package/src/pi/grep-output.ts +208 -0
  38. package/src/pi/grep-render.ts +58 -0
  39. package/src/pi/grep-scope.ts +152 -0
  40. package/src/pi/grep-search.ts +217 -0
  41. package/src/pi/grep-tool.ts +191 -766
  42. package/src/pi/grep.test.ts +562 -150
  43. package/src/pi/mutation-result.test.ts +37 -0
  44. package/src/pi/mutation-result.ts +107 -59
  45. package/src/pi/mutation-runner.ts +168 -0
  46. package/src/pi/path.ts +20 -12
  47. package/src/pi/pi.test.ts +95 -52
  48. package/src/pi/read-tool.ts +219 -130
  49. package/src/pi/registration.test.ts +274 -113
  50. package/src/pi/render.test.ts +218 -83
  51. package/src/pi/render.ts +152 -95
  52. package/src/pi/replace-apply.ts +109 -0
  53. package/src/pi/replace-tool.ts +280 -240
  54. package/src/pi/replace-worker.mjs +4 -0
  55. package/src/pi/replace-worker.ts +10 -0
  56. package/src/pi/replace.test.ts +773 -389
  57. package/src/pi/result-safety.test.ts +779 -342
  58. package/src/pi/rg-line-filter.test.ts +64 -36
  59. package/src/pi/rg-line-filter.ts +40 -124
  60. package/src/pi/rg-line-ranges.test.ts +57 -31
  61. package/src/pi/rg-line-ranges.ts +44 -82
  62. package/src/pi/rg-text-view.ts +106 -36
  63. package/src/pi/schema.ts +27 -0
  64. package/src/pi/state.ts +7 -7
  65. package/src/pi/text-stream.test.ts +118 -0
  66. package/src/pi/text-stream.ts +136 -0
  67. package/src/pi/tool-call.testing.ts +37 -0
  68. package/src/pi/write-tool.ts +115 -52
  69. package/src/pi/write.test.ts +248 -96
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Overrides the built-in read/edit: read outputs "lineNo#hash│content";
5
5
  * edit accepts structured hashline ops (edits[] with LINE#HASH anchors), and
6
- * legacy oldText/newText is rejected explicitly (no silent degradation). grep
6
+ * legacy oldText/newText is rejected by the schema. grep
7
7
  * is overridden the same way so results carry usable anchors. A separate
8
8
  * `replace` tool adds location-blind bulk + regex replacement (replaceAll and
9
9
  * full JS regex with capture groups) for renames/pattern transforms that
@@ -12,7 +12,8 @@
12
12
  * @module pi-hashline-edit
13
13
  */
14
14
 
15
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15
+ import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
16
+ import type { TSchema } from "typebox";
16
17
  import { loadConfig } from "./pi/config.ts";
17
18
  import { getState } from "./pi/state.ts";
18
19
  import { makeEditOverride } from "./pi/edit-tool.ts";
@@ -25,21 +26,26 @@ import { registerFusionCards } from "./pi/fusion-card.ts";
25
26
  import { withMutationStatus } from "./pi/render.ts";
26
27
 
27
28
  export default function (pi: ExtensionAPI) {
28
- const cwd = process.cwd();
29
+ const cwd = process.cwd();
29
30
 
30
- const state = getState();
31
- state.config = loadConfig(cwd);
31
+ const state = getState();
32
+ state.config = loadConfig(cwd);
32
33
 
33
- // `enabled: false` leaves the extension fully inert — pi's built-in
34
- // read/edit/grep/replace/write stay in place, as if this package were not installed.
35
- if (state.config.enabled) {
36
- const reportProgress = registerFusionCards(pi);
37
- const fusion = state.config.actionFusion ? createActionFusionExecutor(undefined, reportProgress) : undefined;
38
- for (const tool of [makeWriteOverride(cwd, fusion), makeEditOverride(cwd, fusion), makeReplaceTool(cwd, fusion)]) {
39
- pi.registerTool(fusion ? withMutationStatus(tool) : tool);
40
- }
34
+ // `enabled: false` leaves the extension fully inert — pi's built-in
35
+ // read/edit/grep/replace/write stay in place, as if this package were not installed.
36
+ if (state.config.enabled) {
37
+ const reportProgress = registerFusionCards(pi);
38
+ const fusion = state.config.actionFusion
39
+ ? createActionFusionExecutor(undefined, reportProgress)
40
+ : undefined;
41
+ const registerMutation = <TParams extends TSchema, TDetails>(
42
+ tool: ToolDefinition<TParams, TDetails>,
43
+ ) => pi.registerTool(fusion ? withMutationStatus(tool) : tool);
44
+ registerMutation(makeWriteOverride(cwd, fusion));
45
+ registerMutation(makeEditOverride(cwd, fusion));
46
+ registerMutation(makeReplaceTool(cwd, fusion));
41
47
 
42
- pi.registerTool(makeReadOverride(cwd));
43
- pi.registerTool(makeGrepOverride(cwd));
44
- }
48
+ pi.registerTool(makeReadOverride(cwd));
49
+ pi.registerTool(makeGrepOverride(cwd));
50
+ }
45
51
  }