pi-agent-ide 0.7.2 → 0.7.3

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 (157) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +3 -1
  3. package/dist/{chunk-KOVPDKSJ.js → chunk-2ZMMRINH.js} +1 -1
  4. package/dist/{chunk-EURHXLN3.js → chunk-BYZSBXUK.js} +1 -1
  5. package/dist/{chunk-XDG7EQRN.js → chunk-CEX73RI5.js} +1 -1
  6. package/dist/{chunk-YWQS33DF.js → chunk-DZWTKF2K.js} +1 -1
  7. package/dist/{chunk-F6IWZKOG.js → chunk-EOKEQ3YH.js} +1 -1
  8. package/dist/{chunk-SJ4UZ4GU.js → chunk-HZ5BNF3A.js} +1 -1
  9. package/dist/{chunk-TQGE7RH6.js → chunk-NHKPP2AI.js} +2 -2
  10. package/dist/{chunk-SNF7PDDX.js → chunk-TXOTNK6B.js} +1 -1
  11. package/dist/chunk-WLZIUMJL.js +1 -0
  12. package/dist/entry-11.js +1 -1
  13. package/dist/entry-17.js +1 -1
  14. package/dist/entry-25.js +1 -1
  15. package/dist/entry-31.js +12 -12
  16. package/dist/entry-33.js +3 -2
  17. package/dist/entry-37.js +6 -6
  18. package/dist/entry-51.js +1 -1
  19. package/dist/entry-56.js +1 -1
  20. package/dist/entry-58.js +1 -1
  21. package/dist/entry-60.js +1 -1
  22. package/dist/entry-62.js +1 -1
  23. package/dist/entry-65.js +1 -1
  24. package/dist/entry-68.js +1 -1
  25. package/dist/entry-70.js +1 -1
  26. package/dist/entry-75.js +1 -1
  27. package/dist/entry-77.js +56 -51
  28. package/dist/entry-78.js +8 -7
  29. package/dist/entry-79.js +1 -1
  30. package/dist/pi-agent-ide.js +20 -20
  31. package/docs/agent-guides/editing.md +9 -2
  32. package/docs/configuration.md +21 -0
  33. package/docs/development.md +4 -0
  34. package/docs/directory-operations.md +45 -0
  35. package/docs/releases.md +8 -0
  36. package/docs/research/codemode-write-context.md +56 -0
  37. package/docs/user-hooks.md +26 -0
  38. package/node_modules/pi-agent-doctor/package.json +1 -1
  39. package/node_modules/pi-agent-documentation/package.json +1 -1
  40. package/node_modules/pi-agent-filesystem/package.json +7 -7
  41. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  42. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  43. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  44. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  45. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  46. package/node_modules/pi-agent-ide-ast/src/extension.ts +3 -1
  47. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +7 -2
  48. package/node_modules/pi-agent-ide-changes/package.json +9 -8
  49. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +16 -0
  50. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  51. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  52. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  53. package/node_modules/pi-agent-ide-lsp/index.ts +1 -1
  54. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  55. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
  56. package/node_modules/pi-agent-image/package.json +2 -2
  57. package/node_modules/pi-agent-invariant/package.json +1 -1
  58. package/node_modules/pi-agent-pdf/package.json +2 -2
  59. package/node_modules/pi-agent-read/package.json +7 -7
  60. package/node_modules/pi-agent-resource/package.json +1 -1
  61. package/node_modules/pi-agent-search/package.json +5 -5
  62. package/node_modules/pi-agent-search-text/package.json +7 -7
  63. package/node_modules/pi-agent-text/package.json +2 -2
  64. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  65. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  66. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  67. package/node_modules/pi-agent-text-editor/package.json +9 -9
  68. package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
  69. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  70. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
  71. package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
  72. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
  73. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +30 -40
  74. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
  75. package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
  76. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -6
  77. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +7 -1
  78. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +55 -12
  79. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +39 -9
  80. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +7 -1
  81. package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
  82. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +3 -0
  83. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +51 -1
  84. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +53 -8
  85. package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
  86. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -2
  87. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +6 -4
  88. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  89. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
  90. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  91. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +33 -18
  92. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  93. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  94. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  95. package/node_modules/pi-agent-web/package.json +7 -7
  96. package/node_modules/pi-agent-web-html/package.json +2 -2
  97. package/node_modules/pi-agent-web-image/package.json +3 -3
  98. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  99. package/node_modules/pi-agent-web-text/package.json +3 -3
  100. package/package.json +36 -35
  101. package/src/api/hooks.ts +24 -0
  102. package/src/composite/nested-tool-rendering.ts +120 -71
  103. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  104. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  105. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  106. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  107. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  108. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  109. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  110. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  111. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  112. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  113. package/src/extensions/pi-agent-read/package.json +7 -7
  114. package/src/extensions/pi-agent-search/package.json +5 -5
  115. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  116. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  117. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  118. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  119. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  120. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  121. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +33 -18
  122. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  123. package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
  124. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  125. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
  126. package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
  127. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
  128. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +30 -40
  129. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
  130. package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
  131. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -6
  132. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +7 -1
  133. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +55 -12
  134. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +39 -9
  135. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +7 -1
  136. package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
  137. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +3 -0
  138. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +51 -1
  139. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +53 -8
  140. package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
  141. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -2
  142. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +6 -4
  143. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  144. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
  145. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  146. package/src/plugins/pi-agent-ide-ast/src/extension.ts +3 -1
  147. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +7 -2
  148. package/src/plugins/pi-agent-ide-changes/package.json +9 -8
  149. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +16 -0
  150. package/src/plugins/pi-agent-ide-debugger/index.ts +3 -1
  151. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  152. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  153. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  154. package/src/plugins/pi-agent-ide-lsp/index.ts +1 -1
  155. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  156. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
  157. package/dist/chunk-PKSQT6TC.js +0 -1
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "pi-agent-web-text",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-resource": "0.7.2",
7
- "pi-agent-text": "0.7.2"
6
+ "pi-agent-resource": "0.7.3",
7
+ "pi-agent-text": "0.7.3"
8
8
  },
9
9
  "pi": {
10
10
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-read",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "pi-agent-documentation": "0.7.2",
28
- "pi-agent-invariant": "0.7.2",
29
- "pi-agent-resource": "0.7.2",
30
- "pi-agent-text": "0.7.2",
31
- "pi-agent-tool-call-interception": "0.7.2",
32
- "pi-agent-tool-ui": "0.7.2"
27
+ "pi-agent-documentation": "0.7.3",
28
+ "pi-agent-invariant": "0.7.3",
29
+ "pi-agent-resource": "0.7.3",
30
+ "pi-agent-text": "0.7.3",
31
+ "pi-agent-tool-call-interception": "0.7.3",
32
+ "pi-agent-tool-ui": "0.7.3"
33
33
  },
34
34
  "pi": {
35
35
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-search",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -20,10 +20,10 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "pi-agent-documentation": "0.7.2",
24
- "pi-agent-resource": "0.7.2",
25
- "pi-agent-tool-call-interception": "0.7.2",
26
- "pi-agent-tool-ui": "0.7.2"
23
+ "pi-agent-documentation": "0.7.3",
24
+ "pi-agent-resource": "0.7.3",
25
+ "pi-agent-tool-call-interception": "0.7.3",
26
+ "pi-agent-tool-ui": "0.7.3"
27
27
  },
28
28
  "pi": {
29
29
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-search-text",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "pi-agent-doctor": "0.7.2",
28
- "pi-agent-invariant": "0.7.2",
29
- "pi-agent-search": "0.7.2",
30
- "pi-agent-text": "0.7.2",
31
- "pi-agent-text-editor": "0.7.2",
32
- "pi-agent-tool-ui": "0.7.2"
27
+ "pi-agent-doctor": "0.7.3",
28
+ "pi-agent-invariant": "0.7.3",
29
+ "pi-agent-search": "0.7.3",
30
+ "pi-agent-text": "0.7.3",
31
+ "pi-agent-text-editor": "0.7.3",
32
+ "pi-agent-tool-ui": "0.7.3"
33
33
  },
34
34
  "pi": {
35
35
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -79,14 +79,14 @@
79
79
  "fs-extra": "^11.4.0",
80
80
  "oxfmt": "0.64.0",
81
81
  "partial-json": "^0.1.7",
82
- "pi-agent-documentation": "0.7.2",
83
- "pi-agent-invariant": "0.7.2",
84
- "pi-agent-read": "0.7.2",
85
- "pi-agent-resource": "0.7.2",
86
- "pi-agent-search": "0.7.2",
87
- "pi-agent-text": "0.7.2",
88
- "pi-agent-tool-call-interception": "0.7.2",
89
- "pi-agent-tool-ui": "0.7.2",
82
+ "pi-agent-documentation": "0.7.3",
83
+ "pi-agent-invariant": "0.7.3",
84
+ "pi-agent-read": "0.7.3",
85
+ "pi-agent-resource": "0.7.3",
86
+ "pi-agent-search": "0.7.3",
87
+ "pi-agent-text": "0.7.3",
88
+ "pi-agent-tool-call-interception": "0.7.3",
89
+ "pi-agent-tool-ui": "0.7.3",
90
90
  "typebox-guard": "npm:typebox@^1.1.38"
91
91
  },
92
92
  "pi": {
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "pi-agent-text-anchor-constant",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
7
7
  },
8
8
  "dependencies": {
9
- "pi-agent-text": "0.7.2",
10
- "pi-agent-text-editor": "0.7.2"
9
+ "pi-agent-text": "0.7.3",
10
+ "pi-agent-text-editor": "0.7.3"
11
11
  },
12
12
  "pi": {
13
13
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-text-anchor-exact",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "fast-fuzzy": "1.12.0",
16
- "pi-agent-text": "0.7.2",
17
- "pi-agent-text-editor": "0.7.2"
16
+ "pi-agent-text": "0.7.3",
17
+ "pi-agent-text-editor": "0.7.3"
18
18
  },
19
19
  "pi": {
20
20
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-text-anchor-line-hash",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -12,10 +12,10 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "pi-agent-invariant": "0.7.2",
16
- "pi-agent-read": "0.7.2",
17
- "pi-agent-text": "0.7.2",
18
- "pi-agent-text-editor": "0.7.2"
15
+ "pi-agent-invariant": "0.7.3",
16
+ "pi-agent-read": "0.7.3",
17
+ "pi-agent-text": "0.7.3",
18
+ "pi-agent-text-editor": "0.7.3"
19
19
  },
20
20
  "pi": {
21
21
  "extensions": [
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-renderer",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
7
7
  },
8
8
  "dependencies": {
9
9
  "diff": "^9.0.0",
10
- "pi-agent-invariant": "0.7.2",
11
- "pi-agent-text-editor": "0.7.2",
12
- "pi-agent-tool-call-interception": "0.7.2",
13
- "pi-agent-tool-ui": "0.7.2",
10
+ "pi-agent-invariant": "0.7.3",
11
+ "pi-agent-text-editor": "0.7.3",
12
+ "pi-agent-tool-call-interception": "0.7.3",
13
+ "pi-agent-tool-ui": "0.7.3",
14
14
  "vscode-diff": "3.0.1"
15
15
  },
16
16
  "pi": {
@@ -293,17 +293,22 @@ function createRenderer(
293
293
  0,
294
294
  );
295
295
  }
296
- const wholeFileSucceeded = wholeFileOperationSucceeded(result.details);
297
- if (wholeFileSucceeded !== undefined) {
296
+ const wholeFileEffect = wholeFileOperationEffect(result.details);
297
+ if (wholeFileEffect !== undefined) {
298
+ const applied = wholeFileEffect === "applied";
299
+ const unknown = wholeFileEffect === "unknown";
300
+ const affected = registration.name === "delete" ? "the source" : "source and destination";
298
301
  return new Text(
299
302
  theme.fg(
300
- wholeFileSucceeded ? "success" : "error",
301
- wholeFileSucceeded
302
- ? registration.name === "copy" &&
303
- typeof result.details.metadata?.targetUnavailable === "string"
304
- ? "✓ Applied · no verified text selection; read destination before further edits"
305
- : "✓ Applied"
306
- : "✗ Not applied",
303
+ unknown ? "warning" : applied ? "success" : "error",
304
+ unknown
305
+ ? `Effects unknown · ${registration.name} failed; read ${affected} before retrying`
306
+ : applied
307
+ ? registration.name === "copy" &&
308
+ typeof result.details.metadata?.targetUnavailable === "string"
309
+ ? "✓ Applied · no verified text selection; read destination before further edits"
310
+ : "✓ Applied"
311
+ : "✗ Not applied",
307
312
  ),
308
313
  0,
309
314
  0,
@@ -892,15 +897,20 @@ function semanticRange(start: string, end: string): string {
892
897
  : `${start}–${end}`;
893
898
  }
894
899
 
895
- function wholeFileOperationSucceeded(details: unknown): boolean | undefined {
900
+ function wholeFileOperationEffect(
901
+ details: unknown,
902
+ ): "applied" | "not-applied" | "unknown" | undefined {
896
903
  if (details === null || typeof details !== "object" || !("metadata" in details)) return undefined;
897
904
  const metadata = details.metadata;
898
905
  if (metadata === null || typeof metadata !== "object" || !("semanticAction" in metadata))
899
906
  return undefined;
900
907
  const action = metadata.semanticAction;
901
908
  if (action === null || typeof action !== "object" || !("kind" in action)) return undefined;
902
- return action.kind === "file-operation" && "ok" in action && typeof action.ok === "boolean"
903
- ? action.ok
909
+ if (action.kind !== "file-operation" || !("effect" in action)) return undefined;
910
+ return action.effect === "applied" ||
911
+ action.effect === "not-applied" ||
912
+ action.effect === "unknown"
913
+ ? action.effect
904
914
  : undefined;
905
915
  }
906
916
 
@@ -908,12 +918,17 @@ function userFacingFailure(
908
918
  agentOutput: string,
909
919
  details: FileMutationBatchResult | undefined,
910
920
  ): string {
911
- const rollback = details?.results?.find((result) => result.data.rollback !== undefined)?.data
912
- .rollback;
913
- if (rollback !== undefined) {
914
- return rollback.failedSources.length === 0
915
- ? "Rolled back · write failed"
916
- : "State unknown · rollback failed";
921
+ const rollbacks =
922
+ details?.results?.flatMap((result) => (result.data.rollback ? [result.data.rollback] : [])) ??
923
+ [];
924
+ if (rollbacks.length > 0) {
925
+ const failed = [...new Set(rollbacks.flatMap((rollback) => rollback.failedSources))];
926
+ const restored = [...new Set(rollbacks.flatMap((rollback) => rollback.restoredSources))];
927
+ return [
928
+ failed.length === 0 ? "Rolled back · write failed" : "State unknown · rollback failed",
929
+ ...(failed.length > 0 ? [`Unknown: ${failed.join(", ")}`] : []),
930
+ ...(restored.length > 0 ? [`Rolled back: ${restored.join(", ")}`] : []),
931
+ ].join("\n");
917
932
  }
918
933
  if (details?.effect === "unknown") return "Effects unknown · edit failed";
919
934
  if (details?.effect === "applied") return "Saved · post-write step failed";
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-stale-anchor",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-invariant": "0.7.2",
7
- "pi-agent-read": "0.7.2",
8
- "pi-agent-text-editor": "0.7.2"
6
+ "pi-agent-invariant": "0.7.3",
7
+ "pi-agent-read": "0.7.3",
8
+ "pi-agent-text-editor": "0.7.3"
9
9
  },
10
10
  "pi": {
11
11
  "extensions": [
@@ -0,0 +1,24 @@
1
+ /** A whole object removed from this path by Delete or directory/symlink Move, never a text selection. */
2
+ export interface BeforeDeleteEvent {
3
+ /** Absolute path supplied by the caller. */
4
+ readonly path: string;
5
+ /** Absolute identity with parent symlinks resolved, but not the final symlink. */
6
+ readonly resolvedPath: string;
7
+ readonly cwd: string;
8
+ readonly kind: "file" | "directory" | "symlink";
9
+ readonly recursive: boolean;
10
+ readonly signal?: AbortSignal;
11
+ }
12
+
13
+ /** A fail-closed policy. Throwing or denying prevents removal. */
14
+ export interface DeleteGuardRegistration {
15
+ readonly id: string;
16
+ readonly guard: (
17
+ event: BeforeDeleteEvent,
18
+ ) =>
19
+ | { readonly decision: "allow" }
20
+ | { readonly decision: "deny"; readonly reason: string }
21
+ | Promise<
22
+ { readonly decision: "allow" } | { readonly decision: "deny"; readonly reason: string }
23
+ >;
24
+ }
@@ -1,3 +1,4 @@
1
+ export type { BeforeDeleteEvent, DeleteGuardRegistration } from "./delete-guard.js";
1
2
  import type { TextEditIntent } from "#src/api/edit-completion.js";
2
3
  import type { AppliedTextChange } from "#src/core/text-change-engine.js";
3
4
  export type { AppliedTextChange } from "#src/core/text-change-engine.js";
@@ -15,6 +15,7 @@ import type {
15
15
  } from "#src/api/anchor-inspection.js";
16
16
  import type { TextEditCompletionListener } from "#src/api/edit-completion.js";
17
17
  import type { TextEditorToolPluginApi } from "#src/api/edit-pipeline.js";
18
+ import type { DeleteGuardRegistration } from "#src/api/delete-guard.js";
18
19
  import type { TextMutationGuardRegistration } from "#src/api/mutation-guard.js";
19
20
  import type {
20
21
  TextMutationPreviewOutcome,
@@ -28,7 +29,7 @@ import type { TextEditorToolRendererRegistration } from "#src/api/tool-renderer.
28
29
 
29
30
  export const TEXT_EDITOR_PROTOCOL = "pi-agent-text-editor";
30
31
 
31
- export const TEXT_EDITOR_API_VERSION = 23;
32
+ export const TEXT_EDITOR_API_VERSION = 24;
32
33
 
33
34
  export const TEXT_POSITION_ANCHOR_KIND = "pi-agent-text-editor/position";
34
35
 
@@ -88,6 +89,8 @@ export interface TextEditorPluginApi {
88
89
  addTextPresenter(registration: TextPresenterRegistration): void;
89
90
  addMutationTool(registration: TextMutationToolRegistration): void;
90
91
  addMutationGuard(registration: TextMutationGuardRegistration): void;
92
+ /** Add a fail-closed policy for whole-object filesystem deletion, not text removal. */
93
+ addDeleteGuard(registration: DeleteGuardRegistration): void;
91
94
  addToolRenderer(registration: TextEditorToolRendererRegistration): void;
92
95
  onMutationTool(listener: TextMutationToolListener): () => void;
93
96
  onDidEdit(listener: TextEditCompletionListener): () => void;
@@ -0,0 +1,284 @@
1
+ import { execFile } from "node:child_process";
2
+ import { lstat, readFile, realpath } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { loadTemporaryDirectories } from "./temporary-directories.js";
6
+ import { requiredValue } from "pi-agent-invariant";
7
+ import type { BeforeDeleteEvent } from "#src/api/delete-guard.js";
8
+
9
+ const exec = promisify(execFile);
10
+
11
+ /** Host-only deletion dependencies; these are not agent parameters. */
12
+ export interface DeletePolicyContext {
13
+ readonly beforeDelete?: (event: BeforeDeleteEvent) => Promise<void>;
14
+ readonly confirm?: (event: BeforeDeleteEvent, reason: string) => Promise<boolean>;
15
+ }
16
+
17
+ interface Project {
18
+ readonly root?: string;
19
+ readonly controls: readonly string[];
20
+ readonly gitAvailable: boolean;
21
+ }
22
+
23
+ /** A host approval that must be checked again immediately before removal. */
24
+ export interface DeletionGuard {
25
+ readonly event: BeforeDeleteEvent;
26
+ readonly verify: () => Promise<void>;
27
+ }
28
+
29
+ /** Check policy and hooks, obtain any required approval, then verify the same object again. */
30
+ export async function prepareDeletion(
31
+ source: string,
32
+ cwd: string,
33
+ context: DeletePolicyContext,
34
+ signal?: AbortSignal,
35
+ ): Promise<BeforeDeleteEvent> {
36
+ const guard = await prepareDeletionGuard(source, cwd, context, signal, true);
37
+ await guard.verify();
38
+ return guard.event;
39
+ }
40
+
41
+ /** Keep approval checks for multi-object removals; only Delete opts into temporary cleanup. */
42
+ export async function prepareDeletionGuard(
43
+ source: string,
44
+ cwd: string,
45
+ context: DeletePolicyContext,
46
+ signal?: AbortSignal,
47
+ allowTemporary = false,
48
+ ): Promise<DeletionGuard> {
49
+ const before = await inspectDeletion(source, cwd, signal, allowTemporary);
50
+ await context.beforeDelete?.(before.event);
51
+ signal?.throwIfAborted();
52
+ if (before.reason !== undefined) {
53
+ if (context.confirm === undefined)
54
+ fail(
55
+ "DELETE_CONFIRMATION_REQUIRED",
56
+ `Deletion blocked: no user dialog is available. ${before.reason}`,
57
+ );
58
+ if (!(await context.confirm(before.event, before.reason)))
59
+ fail("DELETE_NOT_APPROVED", "Deletion was not approved by the user.");
60
+ }
61
+ signal?.throwIfAborted();
62
+ return {
63
+ event: before.event,
64
+ verify: async () => {
65
+ signal?.throwIfAborted();
66
+ let after;
67
+ try {
68
+ after = await inspectDeletion(source, cwd, signal, allowTemporary);
69
+ } catch (error) {
70
+ signal?.throwIfAborted();
71
+ fail(
72
+ "DELETE_TARGET_CHANGED",
73
+ `Deletion target cannot be verified again: ${error instanceof Error ? error.message : String(error)}`,
74
+ );
75
+ }
76
+ if (before.snapshot !== after.snapshot)
77
+ fail(
78
+ "DELETE_TARGET_CHANGED",
79
+ "Deletion target or its safety classification changed. Nothing was removed; make a new request.",
80
+ );
81
+ signal?.throwIfAborted();
82
+ },
83
+ };
84
+ }
85
+
86
+ async function inspectDeletion(
87
+ source: string,
88
+ cwd: string,
89
+ signal: AbortSignal | undefined,
90
+ allowTemporary: boolean,
91
+ ) {
92
+ signal?.throwIfAborted();
93
+ // Resolve ancestors without dereferencing the link that will be unlinked.
94
+ const resolvedPath = path.join(await realpath(path.dirname(source)), path.basename(source));
95
+ const stat = await lstat(resolvedPath);
96
+ const kind = stat.isSymbolicLink()
97
+ ? "symlink"
98
+ : stat.isDirectory()
99
+ ? "directory"
100
+ : stat.isFile()
101
+ ? "file"
102
+ : undefined;
103
+ if (kind === undefined)
104
+ fail("INVALID_FILE_TYPE", "Delete supports regular files, directories, and symlinks.");
105
+ const project = await findProject(cwd, signal);
106
+ const boundary = project.root ?? (await realpath(cwd));
107
+ assertUnprotected(resolvedPath, boundary, project.controls);
108
+
109
+ const temporaryRoots =
110
+ allowTemporary && kind !== "file" ? await loadTemporaryDirectories(boundary) : [];
111
+ const temporary =
112
+ !temporaryRoots.some((root) => path.relative(root, resolvedPath) === "") &&
113
+ temporaryRoots.some((root) => contains(root, resolvedPath));
114
+ let reason: string | undefined;
115
+ let tracked: string[] = [];
116
+ if (kind !== "file") {
117
+ if (!project.gitAvailable || project.root === undefined) {
118
+ // Broken Git metadata must not bypass the tracking check inside the current project.
119
+ if (!temporary || (project.root !== undefined && contains(project.root, resolvedPath)))
120
+ reason = "No Git worktree or reliable Git check is available.";
121
+ } else if (!contains(project.root, resolvedPath)) {
122
+ if (!temporary) reason = "Target is outside the current Git worktree.";
123
+ } else {
124
+ try {
125
+ const entries = (
126
+ await git(project.root, ["ls-files", "--cached", "--full-name", "-z"], signal)
127
+ )
128
+ .split("\0")
129
+ .filter(Boolean);
130
+ tracked = entries
131
+ .filter((entry) =>
132
+ contains(resolvedPath, path.resolve(requiredValue(project.root), entry)),
133
+ )
134
+ .sort();
135
+ if (tracked.length > 0)
136
+ reason = "Target is tracked by Git or contains tracked or staged entries.";
137
+ } catch {
138
+ signal?.throwIfAborted();
139
+ reason = "Git tracking check failed.";
140
+ }
141
+ }
142
+ }
143
+ const event: BeforeDeleteEvent = {
144
+ path: source,
145
+ resolvedPath,
146
+ cwd,
147
+ kind,
148
+ recursive: kind === "directory",
149
+ ...(signal === undefined ? {} : { signal }),
150
+ };
151
+ return {
152
+ event,
153
+ reason,
154
+ snapshot: JSON.stringify({
155
+ resolvedPath,
156
+ kind,
157
+ dev: stat.dev,
158
+ ino: stat.ino,
159
+ birthtime: stat.birthtimeMs,
160
+ ctime: stat.ctimeMs,
161
+ mtime: stat.mtimeMs,
162
+ size: stat.size,
163
+ boundary,
164
+ controls: project.controls,
165
+ temporaryRoots,
166
+ reason,
167
+ tracked,
168
+ }),
169
+ };
170
+ }
171
+
172
+ /** Protect recursive transfer destinations, including paths that do not exist yet. */
173
+ export async function assertUnprotectedTransferPath(
174
+ resolvedPath: string,
175
+ cwd: string,
176
+ signal?: AbortSignal,
177
+ ): Promise<void> {
178
+ const project = await findProject(cwd, signal);
179
+ assertUnprotected(resolvedPath, project.root ?? (await realpath(cwd)), project.controls);
180
+ }
181
+
182
+ function assertUnprotected(resolvedPath: string, boundary: string, controls: readonly string[]) {
183
+ if (
184
+ contains(resolvedPath, boundary) ||
185
+ resolvedPath === path.parse(resolvedPath).root ||
186
+ controls.some((control) => contains(control, resolvedPath) || contains(resolvedPath, control))
187
+ )
188
+ fail(
189
+ "DELETE_PROTECTED_TARGET",
190
+ `Cannot remove or overwrite protected project, ancestor, filesystem root, or Git control path: ${resolvedPath}`,
191
+ );
192
+ }
193
+ async function findProject(cwd: string, signal?: AbortSignal): Promise<Project> {
194
+ try {
195
+ const output = (
196
+ await git(
197
+ cwd,
198
+ [
199
+ "rev-parse",
200
+ "--path-format=absolute",
201
+ "--show-toplevel",
202
+ "--absolute-git-dir",
203
+ "--git-common-dir",
204
+ ],
205
+ signal,
206
+ )
207
+ )
208
+ .trimEnd()
209
+ .split("\n");
210
+ if (output.length !== 3) throw new Error("Unexpected Git worktree paths");
211
+ const [root, gitDir, commonDir] = await Promise.all(output.map((entry) => realpath(entry)));
212
+ return {
213
+ root,
214
+ controls: [
215
+ path.join(requiredValue(root), ".git"),
216
+ requiredValue(gitDir),
217
+ requiredValue(commonDir),
218
+ ].sort(),
219
+ gitAvailable: true,
220
+ };
221
+ } catch {
222
+ signal?.throwIfAborted();
223
+ // Preserve root/control protection even when Git is unavailable or its metadata is broken.
224
+ let directory = await realpath(cwd);
225
+ for (;;) {
226
+ const marker = path.join(directory, ".git");
227
+ const stat = await lstat(marker).catch((error: NodeJS.ErrnoException) => {
228
+ if (error.code === "ENOENT") return undefined;
229
+ throw error;
230
+ });
231
+ if (stat !== undefined) {
232
+ const controls = [marker];
233
+ if (stat.isDirectory() || stat.isSymbolicLink()) controls.push(await realpath(marker));
234
+ else if (stat.isFile()) {
235
+ const content = await readFile(marker, "utf8");
236
+ const reference = /^gitdir: (.+)\r?\n?$/u.exec(content)?.[1];
237
+ if (reference === undefined)
238
+ fail("DELETE_GIT_PROTECTION_FAILED", "Cannot identify current Git control data.");
239
+ const gitDir = await realpath(path.resolve(directory, reference));
240
+ controls.push(gitDir);
241
+ const common = await readFile(path.join(gitDir, "commondir"), "utf8").catch(
242
+ (error: NodeJS.ErrnoException) => {
243
+ if (error.code === "ENOENT") return undefined;
244
+ throw error;
245
+ },
246
+ );
247
+ if (common !== undefined)
248
+ controls.push(await realpath(path.resolve(gitDir, common.trimEnd())));
249
+ } else fail("DELETE_GIT_PROTECTION_FAILED", "Cannot identify current Git control data.");
250
+ return { root: directory, controls: controls.sort(), gitAvailable: false };
251
+ }
252
+ const parent = path.dirname(directory);
253
+ if (parent === directory) return { controls: [], gitAvailable: false };
254
+ directory = parent;
255
+ }
256
+ }
257
+ }
258
+
259
+ async function git(cwd: string, args: string[], signal?: AbortSignal): Promise<string> {
260
+ const env = Object.fromEntries(
261
+ Object.entries(process.env).filter(([key]) => !key.startsWith("GIT_")),
262
+ );
263
+ const { stdout } = await exec("git", ["-C", cwd, ...args], {
264
+ env: { ...env, GIT_OPTIONAL_LOCKS: "0" },
265
+ signal,
266
+ timeout: 5000,
267
+ maxBuffer: 16 * 1024 * 1024,
268
+ });
269
+ return stdout;
270
+ }
271
+
272
+ function contains(parent: string, child: string): boolean {
273
+ const relative = path.relative(parent, child);
274
+ return (
275
+ relative === "" ||
276
+ // This checks containment; it does not construct a parent-relative path.
277
+ // eslint-disable-next-line repo/no-parent-paths
278
+ (!path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path.sep}`))
279
+ );
280
+ }
281
+
282
+ function fail(code: string, message: string): never {
283
+ throw Object.assign(new Error(message), { code });
284
+ }