pi-agent-ide 0.7.1 → 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 (307) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +3 -1
  3. package/dist/{chunk-PKKDDIWW.js → chunk-2ZMMRINH.js} +1 -1
  4. package/dist/chunk-6U5OU77O.js +3 -0
  5. package/dist/chunk-BYZSBXUK.js +2 -0
  6. package/dist/{chunk-LEEQIQ7D.js → chunk-CEX73RI5.js} +6 -6
  7. package/dist/chunk-DZWTKF2K.js +1 -0
  8. package/dist/{chunk-WMO6RNE2.js → chunk-EOKEQ3YH.js} +6 -6
  9. package/dist/{chunk-HZEY4GT4.js → chunk-H445SHSJ.js} +2 -2
  10. package/dist/{chunk-4GCWGE2C.js → chunk-HZ5BNF3A.js} +1 -1
  11. package/dist/chunk-IG56UGSO.js +2 -0
  12. package/dist/chunk-IICJXZBU.js +6 -0
  13. package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
  14. package/dist/chunk-MXLSGMRZ.js +3 -0
  15. package/dist/{chunk-76ZK5ODR.js → chunk-NHKPP2AI.js} +13 -13
  16. package/dist/chunk-OB46OPMZ.js +1 -0
  17. package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
  18. package/dist/chunk-QUYXINGZ.js +7 -0
  19. package/dist/{chunk-OMVRLWMX.js → chunk-SBP3ABH4.js} +1 -1
  20. package/dist/{chunk-YP46DVVP.js → chunk-STBJO3Z3.js} +1 -1
  21. package/dist/{chunk-2TRHFMCZ.js → chunk-TXOTNK6B.js} +1 -1
  22. package/dist/chunk-WLZIUMJL.js +1 -0
  23. package/dist/chunk-ZIWPKIBZ.js +1 -0
  24. package/dist/entry-11.js +1 -1
  25. package/dist/entry-13.js +1 -1
  26. package/dist/entry-14.js +1 -1
  27. package/dist/entry-15.js +1 -1
  28. package/dist/entry-17.js +1 -1
  29. package/dist/entry-25.js +1 -1
  30. package/dist/entry-26.js +1 -1
  31. package/dist/entry-27.js +1 -1
  32. package/dist/entry-28.js +1 -1
  33. package/dist/entry-29.js +1 -1
  34. package/dist/entry-31.js +12 -11
  35. package/dist/entry-33.js +3 -1
  36. package/dist/entry-37.js +6 -6
  37. package/dist/entry-42.js +1 -1
  38. package/dist/entry-44.js +1 -1
  39. package/dist/entry-45.js +20 -12
  40. package/dist/entry-46.js +1 -1
  41. package/dist/entry-49.js +1 -1
  42. package/dist/entry-50.js +1 -1
  43. package/dist/entry-51.js +7 -6
  44. package/dist/entry-52.js +1 -1
  45. package/dist/entry-53.js +1 -1
  46. package/dist/entry-54.js +1 -1
  47. package/dist/entry-56.js +1 -1
  48. package/dist/entry-58.js +1 -1
  49. package/dist/entry-60.js +1 -1
  50. package/dist/entry-62.js +1 -1
  51. package/dist/entry-65.js +1 -1
  52. package/dist/entry-66.js +1 -1
  53. package/dist/entry-68.js +1 -1
  54. package/dist/entry-70.js +1 -1
  55. package/dist/entry-75.js +1 -1
  56. package/dist/entry-77.js +63 -49
  57. package/dist/entry-78.js +15 -14
  58. package/dist/entry-79.js +1 -1
  59. package/dist/entry-82.js +5 -5
  60. package/dist/entry-83.js +1 -1
  61. package/dist/entry-84.js +1 -1
  62. package/dist/entry-85.js +1 -1
  63. package/dist/entry-86.js +1 -1
  64. package/dist/pi-agent-ide.js +34 -11
  65. package/docs/agent-guides/editing.md +14 -7
  66. package/docs/agent-guides/git-changes.md +10 -0
  67. package/docs/agent-guides/read-resources.md +9 -46
  68. package/docs/agent-guides/search-code.md +7 -1
  69. package/docs/agent-guides/select-code.md +1 -0
  70. package/docs/agent-guides/terminal.md +9 -1
  71. package/docs/configuration.md +22 -1
  72. package/docs/development.md +4 -0
  73. package/docs/directory-operations.md +45 -0
  74. package/docs/releases.md +12 -0
  75. package/docs/research/codemode-write-context.md +56 -0
  76. package/docs/research/native-codemode-batch-decision.md +2 -0
  77. package/docs/structured-results.md +2 -2
  78. package/docs/tools.md +10 -2
  79. package/docs/user-hooks.md +26 -0
  80. package/node_modules/pi-agent-doctor/package.json +1 -1
  81. package/node_modules/pi-agent-documentation/package.json +1 -1
  82. package/node_modules/pi-agent-filesystem/package.json +7 -7
  83. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  84. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  85. package/node_modules/pi-agent-filesystem-jq/src/jq.ts +4 -1
  86. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  87. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  88. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  89. package/node_modules/pi-agent-ide-ast/src/extension.ts +3 -3
  90. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
  91. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +0 -3
  92. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +8 -6
  93. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +13 -5
  94. package/node_modules/pi-agent-ide-changes/package.json +9 -8
  95. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
  96. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  97. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  98. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  99. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  100. package/node_modules/pi-agent-ide-lsp/index.ts +1 -1
  101. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  102. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
  103. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
  104. package/node_modules/pi-agent-image/package.json +2 -2
  105. package/node_modules/pi-agent-invariant/package.json +1 -1
  106. package/node_modules/pi-agent-pdf/package.json +2 -2
  107. package/node_modules/pi-agent-read/package.json +7 -7
  108. package/node_modules/pi-agent-read/src/api/read-parameters.ts +3 -3
  109. package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -0
  110. package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
  111. package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
  112. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  113. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  114. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  115. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  116. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +99 -44
  117. package/node_modules/pi-agent-resource/package.json +1 -1
  118. package/node_modules/pi-agent-resource/src/index.ts +1 -0
  119. package/node_modules/pi-agent-resource/src/result-targets.ts +6 -3
  120. package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
  121. package/node_modules/pi-agent-search/package.json +5 -5
  122. package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
  123. package/node_modules/pi-agent-search/src/api/search-parameters.ts +2 -2
  124. package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
  125. package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
  126. package/node_modules/pi-agent-search-text/package.json +7 -7
  127. package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
  128. package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
  129. package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
  130. package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
  131. package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
  132. package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
  133. package/node_modules/pi-agent-text/package.json +2 -2
  134. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  135. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  136. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  137. package/node_modules/pi-agent-text-editor/package.json +9 -9
  138. package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
  139. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  140. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  141. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
  142. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  143. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
  144. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  145. package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
  146. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  147. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  148. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
  149. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +30 -40
  150. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
  151. package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
  152. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
  153. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
  154. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  155. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
  156. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  157. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
  158. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
  159. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +21 -14
  160. package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
  161. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  162. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
  163. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  164. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
  165. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
  166. package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
  167. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
  168. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
  169. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  170. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  171. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
  172. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
  173. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  174. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  175. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  176. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
  177. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  178. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  179. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  180. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  181. package/node_modules/pi-agent-web/package.json +7 -7
  182. package/node_modules/pi-agent-web/src/resolver.ts +11 -13
  183. package/node_modules/pi-agent-web-html/package.json +2 -2
  184. package/node_modules/pi-agent-web-image/package.json +3 -3
  185. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  186. package/node_modules/pi-agent-web-text/package.json +3 -3
  187. package/package.json +36 -35
  188. package/src/api/hooks.ts +24 -0
  189. package/src/composite/nested-tool-rendering.ts +184 -77
  190. package/src/composite/output-limits.ts +125 -0
  191. package/src/composite/responses-tools.ts +25 -0
  192. package/src/composite/text-results.ts +158 -7
  193. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  194. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  195. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  196. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
  197. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  198. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  199. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  200. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  201. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  202. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  203. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  204. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +11 -13
  205. package/src/extensions/pi-agent-read/package.json +7 -7
  206. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +3 -3
  207. package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -0
  208. package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
  209. package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
  210. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  211. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  212. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  213. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  214. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +99 -44
  215. package/src/extensions/pi-agent-search/package.json +5 -5
  216. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  217. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
  218. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
  219. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
  220. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
  221. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
  222. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
  223. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
  224. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +2 -2
  225. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
  226. package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
  227. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  228. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  229. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  230. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  231. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  232. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  233. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
  234. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  235. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  236. package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
  237. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  238. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  239. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
  240. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  241. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
  242. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  243. package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
  244. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  245. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  246. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
  247. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +30 -40
  248. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
  249. package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
  250. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
  251. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
  252. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  253. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
  254. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  255. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
  256. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
  257. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +21 -14
  258. package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
  259. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  260. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
  261. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  262. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
  263. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
  264. package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
  265. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
  266. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
  267. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  268. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  269. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
  270. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
  271. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  272. package/src/pi-agent-ide.ts +11 -0
  273. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  274. package/src/plugins/pi-agent-ide-ast/src/extension.ts +3 -3
  275. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
  276. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +0 -3
  277. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +8 -6
  278. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +13 -5
  279. package/src/plugins/pi-agent-ide-changes/package.json +9 -8
  280. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
  281. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  282. package/src/plugins/pi-agent-ide-debugger/index.ts +20 -8
  283. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
  284. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
  285. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +3 -2
  286. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  287. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  288. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  289. package/src/plugins/pi-agent-ide-lsp/index.ts +1 -1
  290. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  291. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
  292. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
  293. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
  294. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
  295. package/src/plugins/pi-agent-ide-vision/index.ts +1 -0
  296. package/src/post-edit/gate.ts +13 -2
  297. package/dist/chunk-4XMY4H4V.js +0 -1
  298. package/dist/chunk-64M3SQPG.js +0 -3
  299. package/dist/chunk-CWD4O5PM.js +0 -3
  300. package/dist/chunk-D3WTDA6V.js +0 -2
  301. package/dist/chunk-EAZGN5ND.js +0 -7
  302. package/dist/chunk-GXEGY7GV.js +0 -1
  303. package/dist/chunk-MBUXFKIW.js +0 -3
  304. package/dist/chunk-PGIVHICI.js +0 -1
  305. package/dist/chunk-VMTR74FF.js +0 -2
  306. package/dist/chunk-WU6ZK6YD.js +0 -1
  307. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
@@ -51,7 +51,12 @@ import {
51
51
  runNativePostEditScope,
52
52
  recordNativeTextMutation,
53
53
  } from "#src/core/native-text-edit-batch.js";
54
- import { attachCommittedMutationTarget } from "./mutation-result-targets.js";
54
+ import {
55
+ attachCommittedMutationTarget,
56
+ attachWriteTarget,
57
+ describeUnavailableCopyTarget,
58
+ unchangedCopySources,
59
+ } from "./mutation-result-targets.js";
55
60
  import { wholeFileResultSource } from "./result-input.js";
56
61
  import { TEXT_SEARCH_ANCHOR_KIND } from "#src/api/plugin-protocol.js";
57
62
  import { isResultInput, prepareResultTransfer } from "./result-transfer.js";
@@ -84,6 +89,7 @@ import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception"
84
89
  import type { Static, TSchema } from "typebox";
85
90
  import { executeWholeFileTool, isWholeFileInvocation } from "#src/core/file-operation-tools.js";
86
91
  import { EDITING_GUIDELINES } from "#src/core/editing-guidelines.js";
92
+ import { writeAgentResult } from "./write-agent-result.js";
87
93
  import { mutationResultSchema, structuredMutation } from "./structured-result.js";
88
94
  import type { ResultTargetStore } from "pi-agent-resource";
89
95
 
@@ -119,8 +125,8 @@ export function createTextTool<TParameters extends TSchema>(
119
125
  description: definition.description,
120
126
  parameters: definition.parameters,
121
127
  outputSchema: mutationResultSchema(definition.name),
128
+ // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
122
129
  prepareArguments: (arguments_) =>
123
- // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
124
130
  prepareGuardedArguments(
125
131
  definition.parameters,
126
132
  arguments_,
@@ -142,170 +148,211 @@ export function createTextTool<TParameters extends TSchema>(
142
148
  }),
143
149
  async execute(toolCallId, parameters, signal, onUpdate, context) {
144
150
  let plannedEdits: ReadonlyMap<string, TextMutationEdit> | undefined;
145
- const captured = await runNativePostEditScope(core, toolCallId, () =>
146
- captureScriptMutation(core, async () => {
147
- const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
148
- let input = asMutationParameters<TParameters>(parameters);
149
- if (
150
- ["replace", "write", "delete", "undo"].includes(definition.name) &&
151
- isResultInput(input[definition.source.field])
152
- ) {
153
- try {
154
- if (resultTargets === undefined)
155
- throw new Error("Result targets are unavailable.");
156
- if (input.start !== undefined || input.end !== undefined)
157
- throw new Error("Do not combine result targets with start/end.");
158
- const selected = resultTargets.resolve(
159
- input[definition.source.field],
160
- context.cwd,
161
- );
162
- if (!selected.complete)
163
- throw new Error(
164
- "Incomplete result targets cannot establish a complete edit; repeat Search.",
151
+ const copyPlan = { snapshots: new Map<string, string>(), unchanged: false };
152
+ const captured = await runNativePostEditScope(
153
+ core,
154
+ toolCallId,
155
+ () =>
156
+ captureScriptMutation(core, async () => {
157
+ const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
158
+ let input = asMutationParameters<TParameters>(parameters);
159
+ if (
160
+ ["replace", "write", "delete", "undo", "insert"].includes(definition.name) &&
161
+ isResultInput(input[definition.source.field])
162
+ ) {
163
+ try {
164
+ if (resultTargets === undefined)
165
+ throw new Error("Result targets are unavailable.");
166
+ if (input.start !== undefined || input.end !== undefined)
167
+ throw new Error("Do not combine result targets with start/end.");
168
+ const selected = resultTargets.resolve(
169
+ input[definition.source.field],
170
+ context.cwd,
165
171
  );
166
- await resultTargets.verify(selected, signal);
167
- if (definition.name === "write" || definition.name === "undo")
168
- wholeFileResultSource(selected);
169
- if (selected.targets.length === 0)
170
- return {
171
- content: [{ type: "text", text: "Empty result target set; no changes." }],
172
- details: {
173
- results: [],
174
- effect: "not-applied",
175
- metadata: { emptyTargets: true },
176
- },
172
+ if (!selected.complete)
173
+ throw new Error(
174
+ "Incomplete result targets cannot establish a complete edit. Run Search again with a higher limit or a narrower query, then use the complete result.",
175
+ );
176
+ await resultTargets.verify(selected, signal);
177
+ if (definition.name === "write" || definition.name === "undo")
178
+ wholeFileResultSource(selected, definition.name);
179
+ if (selected.targets.length === 0)
180
+ return {
181
+ content: [{ type: "text", text: "Empty result target set; no changes." }],
182
+ details: {
183
+ results: [],
184
+ effect: "not-applied",
185
+ metadata: { emptyTargets: true },
186
+ },
187
+ };
188
+ input = {
189
+ ...input,
190
+ [definition.source.field]: resultTargets.register(
191
+ selected.targets,
192
+ context.cwd,
193
+ selected.complete,
194
+ ),
177
195
  };
178
- input = {
179
- ...input,
180
- [definition.source.field]: resultTargets.register(
181
- selected.targets,
196
+ } catch (error) {
197
+ signal?.throwIfAborted();
198
+ return failureToolResult(
199
+ "",
200
+ "RESULT_INPUT_REJECTED",
201
+ errorMessage(error),
202
+ "not-applied",
203
+ );
204
+ }
205
+ }
206
+ let executionDefinition = definition;
207
+ let verifyFileSource: (() => Promise<void>) | undefined;
208
+ if (
209
+ (definition.name === "copy" || definition.name === "move") &&
210
+ (isResultInput(input.path) || isResultInput(input.target))
211
+ ) {
212
+ try {
213
+ if (resultTargets === undefined)
214
+ throw new Error("Result targets are unavailable.");
215
+ const prepared = await prepareResultTransfer(
216
+ definition.name,
217
+ input,
218
+ resultTargets,
182
219
  context.cwd,
183
- selected.complete,
184
- ),
185
- };
186
- } catch (error) {
187
- signal?.throwIfAborted();
188
- return failureToolResult(
189
- "",
190
- "RESULT_INPUT_REJECTED",
191
- errorMessage(error),
192
- "not-applied",
193
- );
220
+ signal,
221
+ );
222
+ input = asMutationParameters<TParameters>(prepared.input);
223
+ verifyFileSource = prepared.verifyFileSource;
224
+ if (prepared.noOpTarget !== undefined)
225
+ return {
226
+ content: [
227
+ {
228
+ type: "text",
229
+ text: "No changes: zero-width selections. The result selects the unchanged destination points.",
230
+ },
231
+ ],
232
+ details: {
233
+ results: [],
234
+ effect: "not-applied",
235
+ metadata: { resultTarget: prepared.noOpTarget },
236
+ },
237
+ };
238
+ if (prepared.empty)
239
+ return {
240
+ content: [
241
+ {
242
+ type: "text",
243
+ text:
244
+ definition.name === "copy"
245
+ ? "No changes: empty selection."
246
+ : "Empty result target set; no changes.",
247
+ },
248
+ ],
249
+ details: {
250
+ results: [],
251
+ effect: "not-applied",
252
+ metadata: { emptyTargets: true },
253
+ },
254
+ };
255
+ if (prepared.mutate !== undefined)
256
+ executionDefinition = { ...definition, mutate: prepared.mutate };
257
+ } catch (error) {
258
+ signal?.throwIfAborted();
259
+ return failureToolResult(
260
+ "",
261
+ "RESULT_INPUT_REJECTED",
262
+ errorMessage(error),
263
+ "not-applied",
264
+ );
265
+ }
194
266
  }
195
- }
196
- let executionDefinition = definition;
197
- let verifyFileSource: (() => Promise<void>) | undefined;
198
- if (
199
- (definition.name === "copy" || definition.name === "move") &&
200
- (isResultInput(input.path) || isResultInput(input.target))
201
- ) {
202
- try {
203
- if (resultTargets === undefined)
204
- throw new Error("Result targets are unavailable.");
205
- const prepared = await prepareResultTransfer(
206
- definition.name,
207
- input,
208
- resultTargets,
209
- context.cwd,
210
- signal,
211
- );
212
- input = asMutationParameters<TParameters>(prepared.input);
213
- verifyFileSource = prepared.verifyFileSource;
214
- if (prepared.empty)
267
+ const directDefinition = executionDefinition;
268
+ executionDefinition = {
269
+ ...directDefinition,
270
+ mutate: async (mutationContext, arguments_) => {
271
+ const mutation = await directDefinition.mutate(mutationContext, arguments_);
272
+ plannedEdits = mutation.edits;
273
+ if (definition.name === "copy") {
274
+ for (const source of mutation.edits.keys())
275
+ copyPlan.snapshots.set(source, mutationContext.documentFor(source).content);
276
+ copyPlan.unchanged =
277
+ mutation.edits.size > 0 &&
278
+ unchangedCopySources(mutation, copyPlan.snapshots).size ===
279
+ mutation.edits.size;
280
+ }
281
+ return mutation;
282
+ },
283
+ };
284
+ const queued = executeNativeTextEditBatch(
285
+ core,
286
+ toolCallId,
287
+ definition,
288
+ input,
289
+ signal,
290
+ context,
291
+ );
292
+ if (queued !== undefined) return queued;
293
+ if (definition.direct?.matches(input) === true) {
294
+ try {
295
+ const action = await definition.direct.execute(
296
+ { cwd: context.cwd, ...(signal !== undefined && { signal }) },
297
+ input,
298
+ );
215
299
  return {
216
- content: [{ type: "text", text: "Empty result target set; no changes." }],
300
+ content: [{ type: "text", text: action.summary }],
217
301
  details: {
218
302
  results: [],
219
- effect: "not-applied",
220
- metadata: { emptyTargets: true },
303
+ metadata: { semanticAction: { ...action.data, source: action.source } },
221
304
  },
222
305
  };
223
- if (prepared.mutate !== undefined)
224
- executionDefinition = { ...definition, mutate: prepared.mutate };
225
- } catch (error) {
226
- signal?.throwIfAborted();
227
- return failureToolResult(
228
- "",
229
- "RESULT_INPUT_REJECTED",
230
- errorMessage(error),
231
- "not-applied",
232
- );
306
+ } catch (error) {
307
+ const code =
308
+ error !== null && typeof error === "object" && "code" in error
309
+ ? String(error.code)
310
+ : "DIRECT_MUTATION_FAILED";
311
+ return failureToolResult(
312
+ "transaction" in input ? String(input.transaction) : "",
313
+ code,
314
+ error instanceof Error ? error.message : String(error),
315
+ "unknown",
316
+ );
317
+ }
233
318
  }
234
- }
235
- const directDefinition = executionDefinition;
236
- executionDefinition = {
237
- ...directDefinition,
238
- mutate: async (mutationContext, arguments_) => {
239
- const mutation = await directDefinition.mutate(mutationContext, arguments_);
240
- plannedEdits = mutation.edits;
241
- return mutation;
242
- },
243
- };
244
- const queued = executeNativeTextEditBatch(
245
- core,
246
- toolCallId,
247
- definition,
248
- input,
249
- signal,
250
- context,
251
- );
252
- if (queued !== undefined) return queued;
253
- if (definition.direct?.matches(input) === true) {
254
- try {
255
- const action = await definition.direct.execute(
256
- { cwd: context.cwd, ...(signal !== undefined && { signal }) },
319
+ if (
320
+ isWholeFileInvocation(definition.wholeFileOperation, input) &&
321
+ core.getSemanticMutationHandler(definition.name, input) === undefined
322
+ ) {
323
+ return executeWholeFileTool(
324
+ core,
325
+ definition.wholeFileOperation,
257
326
  input,
258
- );
259
- return {
260
- content: [{ type: "text", text: action.summary }],
261
- details: {
262
- results: [],
263
- metadata: { semanticAction: { ...action.data, source: action.source } },
264
- },
265
- };
266
- } catch (error) {
267
- const code =
268
- error !== null && typeof error === "object" && "code" in error
269
- ? String(error.code)
270
- : "DIRECT_MUTATION_FAILED";
271
- return failureToolResult(
272
- "transaction" in input ? String(input.transaction) : "",
273
- code,
274
- error instanceof Error ? error.message : String(error),
275
- "unknown",
327
+ signal,
328
+ context,
329
+ verifyFileSource,
276
330
  );
277
331
  }
278
- }
279
- if (
280
- isWholeFileInvocation(definition.wholeFileOperation, input) &&
281
- core.getSemanticMutationHandler(definition.name, input) === undefined
282
- ) {
283
- return executeWholeFileTool(
284
- core,
285
- definition.wholeFileOperation,
286
- input,
287
- signal,
288
- context,
289
- verifyFileSource,
290
- );
291
- }
292
- const directExecute = () =>
293
- executeTextMutation(
294
- core,
295
- executionDefinition,
296
- input,
332
+ const directExecute = () =>
333
+ executeTextMutation(
334
+ core,
335
+ executionDefinition,
336
+ input,
337
+ signal,
338
+ context,
339
+ (field, state) =>
340
+ annotations.resolveArguments(toolCallId, {
341
+ [TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
342
+ }),
343
+ getLastResolvedSource(),
344
+ );
345
+ return executeTextToolWithBatch(
346
+ toolCallId,
347
+ directExecute,
297
348
  signal,
349
+ onUpdate,
298
350
  context,
299
- (field, state) =>
300
- annotations.resolveArguments(toolCallId, {
301
- [TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
302
- }),
303
- getLastResolvedSource(),
304
351
  );
305
- return executeTextToolWithBatch(toolCallId, directExecute, signal, onUpdate, context);
306
- };
307
- return execute();
308
- }),
352
+ };
353
+ return execute();
354
+ }),
355
+ definition.name === "write",
309
356
  );
310
357
  if (captured.kind === "failed") {
311
358
  const failed = failureToolResult(
@@ -313,26 +360,73 @@ export function createTextTool<TParameters extends TSchema>(
313
360
  "EXECUTION_FAILED",
314
361
  errorMessage(captured.error),
315
362
  "unknown",
363
+ undefined,
364
+ definition.name === "copy",
365
+ );
366
+ return structuredMutation(
367
+ definition.name === "write"
368
+ ? writeAgentResult(
369
+ failed,
370
+ captured.completions,
371
+ asMutationParameters<TParameters>(parameters)[definition.source.field],
372
+ )
373
+ : failed,
374
+ definition.name,
375
+ captured.completions,
376
+ toolCallId,
316
377
  );
317
- return structuredMutation(failed, definition.name, captured.completions, toolCallId);
318
378
  }
319
- recordNativeTextMutation(core, toolCallId, captured.value);
379
+ const completedValue =
380
+ copyPlan.unchanged && captured.completions.length === 0 && !captured.value.isError
381
+ ? {
382
+ ...captured.value,
383
+ content: [
384
+ { type: "text" as const, text: "No changes: destination already has this text." },
385
+ ],
386
+ details: { ...captured.value.details, effect: "not-applied" as const },
387
+ }
388
+ : captured.value;
389
+ // Live-resource actions have their own receipts, not filesystem editor batches.
390
+ if (captured.completions.every((completion) => completion.resolvedBy === "filesystem"))
391
+ recordNativeTextMutation(core, toolCallId, definition.name, completedValue);
320
392
  const value =
321
393
  resultTargets &&
322
394
  ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
323
- ? await attachCommittedMutationTarget(
324
- captured.value,
325
- captured.completions,
326
- resultTargets,
327
- toolCallId,
328
- context.cwd,
329
- signal,
330
- definition.name === "write" || definition.name === "undo",
331
- plannedEdits,
332
- definition.name === "copy" || definition.name === "move",
333
- )
334
- : captured.value;
335
- return structuredMutation(value, definition.name, captured.completions, toolCallId);
395
+ ? definition.name === "write"
396
+ ? await attachWriteTarget(
397
+ completedValue,
398
+ captured.completions,
399
+ resultTargets,
400
+ context.cwd,
401
+ signal,
402
+ )
403
+ : await attachCommittedMutationTarget(
404
+ completedValue,
405
+ captured.completions,
406
+ resultTargets,
407
+ toolCallId,
408
+ context.cwd,
409
+ signal,
410
+ definition.name === "undo",
411
+ plannedEdits,
412
+ definition.name === "copy" || definition.name === "move",
413
+ copyPlan.snapshots,
414
+ )
415
+ : completedValue;
416
+ return structuredMutation(
417
+ definition.name === "copy"
418
+ ? describeUnavailableCopyTarget(value)
419
+ : definition.name === "write"
420
+ ? writeAgentResult(
421
+ value,
422
+ captured.completions,
423
+ asMutationParameters<TParameters>(parameters)[definition.source.field],
424
+ )
425
+ : value,
426
+ definition.name,
427
+ captured.completions,
428
+ toolCallId,
429
+ );
336
430
  },
337
431
  }),
338
432
  annotations,
@@ -342,25 +436,32 @@ export function createTextTool<TParameters extends TSchema>(
342
436
  get(): string {
343
437
  return [
344
438
  definition.description,
345
- definition.intent !== "restore"
346
- ? "In native Codemode, local text edits share original snapshots and return acceptance before writing. Another tool, whole-file operation, or resource-owned selector commits the batch first; script completion also commits it. Formatting and registered resource post-edit handlers run at script end, not at flush or dependency boundaries. Earlier targets become stale if final processing changes bytes. Ordinary script errors keep accepted edits; aborts and deadlines discard pending edits."
347
- : "",
439
+ core.renderToolPromptGuideline(definition.name) ?? "",
348
440
  (
349
441
  {
350
442
  replace:
351
443
  "This result selects the resulting text; empty replacement selects the resulting position, not the removed text.",
352
- insert: "This result selects the inserted text, including supplied line separators.",
353
- write: "This result selects the whole written file, not only its changed span.",
354
- copy: "This result selects only destination text; a whole-file copy selects the whole destination. The source is unchanged.",
355
- move: "This result selects only destination text; a whole-file move selects the whole destination. Source removals never become output targets.",
356
- delete: "Deletion reports file effects but provides no reusable text selection.",
357
- undo: "This result selects whole restored text files, not only reversed spans. Deleted files provide no text selection.",
444
+ insert:
445
+ "For text edits, this result selects the inserted text, including supplied line separators. Specialized resources return their own action result.",
446
+ write:
447
+ "For file writes, this result selects the whole file and returns a compact write receipt, not file content.",
448
+ copy: "This result selects only the copied destination text; a whole-file copy selects the whole destination. Copy edits only the destination.",
449
+ move: "Use the Move result to work with the inserted destination text, including any added line separators. Valid empty arrays and paired zero-width selections succeed without writes; paired points select only the unchanged destination points. Source removals are not selected. A whole-file move selects the whole destination when a reusable text result is available.",
450
+ delete: "Delete returns no reusable text selection.",
451
+ undo: "The result selects the whole restored text file, not only the reversed span.",
358
452
  } as Record<string, string>
359
453
  )[definition.name] ?? "",
360
- ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
361
- ? "Pass this unchanged result to another source tool for dependent work. Pending edits commit before the next tool consumes them. If the result reports no verified text selection, inspect the file instead."
362
- : "",
363
- definition.source.inherited
454
+ definition.name === "replace"
455
+ ? "Pass the unchanged result to another source tool to use its selection. If it has no text selection, read the file again."
456
+ : definition.name === "write"
457
+ ? "For file writes, pass this unchanged result to another source tool for dependent work. If the result reports no verified text selection, inspect the file instead."
458
+ : definition.name === "undo"
459
+ ? "Pass the unchanged result to another source tool for dependent work. If no verified text selection is returned, read the file again."
460
+ : ["insert", "copy", "move"].includes(definition.name)
461
+ ? "Pass this unchanged result to another source tool for dependent work." +
462
+ " If the result reports no verified text selection, inspect the file instead."
463
+ : "",
464
+ definition.source.inherited && !["delete", "undo"].includes(definition.name)
364
465
  ? definition.wholeFileOperation === undefined
365
466
  ? `When ${definition.source.field} is omitted, the tool can reuse the file identified by the supplied anchor, the last read, or the preceding edit in the same batch.`
366
467
  : `When ${definition.source.field} is omitted, the tool can reuse the file identified by a supplied text anchor.`
@@ -703,6 +804,7 @@ interface MutationExecutionContext extends TextMutationContext {
703
804
 
704
805
  interface ExecutedTextMutation extends TextMutation {
705
806
  readonly resultPresentations: ReadonlyMap<string, MutationResultPresentation>;
807
+ readonly unchangedWrite?: { readonly source: string; readonly content: string };
706
808
  }
707
809
 
708
810
  function createMutationContext(
@@ -1135,7 +1237,15 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1135
1237
  );
1136
1238
  await preflightMutationAnchors(definition, state.input, mutationContext);
1137
1239
  const mutation = await definition.mutate(mutationContext, state.input);
1138
- const executedMutation = withResultPresentations(mutation, mutationContext);
1240
+ const executedMutation: ExecutedTextMutation = {
1241
+ ...withResultPresentations(mutation, mutationContext),
1242
+ ...(definition.name === "write" && {
1243
+ unchangedWrite: {
1244
+ source: mutationContext.sourceFor("path"),
1245
+ content: mutationContext.sourceDocument.content,
1246
+ },
1247
+ }),
1248
+ };
1139
1249
  return {
1140
1250
  changes: new Map(
1141
1251
  [...mutation.edits].map(([editSource, edit]) => [editSource, edit.changes]),
@@ -1209,6 +1319,21 @@ type CompletedTextResource = Extract<
1209
1319
  { readonly kind: "completed" }
1210
1320
  >;
1211
1321
 
1322
+ /** Count real Copy changes without counting retained identical destination ranges. */
1323
+ export function textMutationOperationReceipts(
1324
+ operation: string,
1325
+ edit: TextMutationEdit,
1326
+ before: string,
1327
+ ): readonly MutationOperationReceipt[] {
1328
+ const changes =
1329
+ operation === "copy"
1330
+ ? edit.changes.filter(
1331
+ (change) =>
1332
+ !change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
1333
+ ).length
1334
+ : edit.changes.length;
1335
+ return operation === "copy" && changes === 0 ? [] : [{ operation, changes }];
1336
+ }
1212
1337
  /** Builds a mutation receipt; peer ranges are supplied only for per-call batch display results. */
1213
1338
  export function buildSuccessfulTextMutationResult(
1214
1339
  resource: CompletedTextResource,
@@ -1308,7 +1433,7 @@ async function buildToolResult(
1308
1433
  source,
1309
1434
  pipeline.failure.code,
1310
1435
  pipeline.failure.message,
1311
- "not-applied",
1436
+ pipeline.failure.stage === "text-pre-edit" ? "not-applied" : "unknown",
1312
1437
  );
1313
1438
  }
1314
1439
 
@@ -1330,11 +1455,19 @@ async function buildToolResult(
1330
1455
  return recovery;
1331
1456
  }
1332
1457
 
1458
+ if (operation === "copy" && outcome.failure.code === "WRITE_FAILED") {
1459
+ return buildFailedCopyWriteResult(outcome.failure, outcome.completed);
1460
+ }
1333
1461
  const completed =
1334
1462
  outcome.completed.length === 0 ? "" : ` Completed writes: ${outcome.completed.join(", ")}.`;
1335
- const effect = outcome.completed.length === 0 ? "not-applied" : "applied";
1463
+ const effect =
1464
+ outcome.completed.length > 0
1465
+ ? "applied"
1466
+ : outcome.failure.code === "POST_WRITE_FAILED"
1467
+ ? "unknown"
1468
+ : "not-applied";
1336
1469
  const message = `${outcome.failure.message.replace(/[.!?]+$/u, "")}.${completed}`;
1337
- return failureToolResult(source, outcome.failure.code, message, effect);
1470
+ return buildFailedTextMutationResult(core, { ...outcome.failure, message }, context, effect);
1338
1471
  }
1339
1472
 
1340
1473
  const mutation = outcome.result as ExecutedTextMutation;
@@ -1352,6 +1485,28 @@ async function buildToolResult(
1352
1485
  },
1353
1486
  };
1354
1487
  }
1488
+ if (operation === "write" && outcome.resources.length === 0 && mutation.unchangedWrite) {
1489
+ const { source: unchangedSource, content } = mutation.unchangedWrite;
1490
+ return {
1491
+ content: [
1492
+ {
1493
+ type: "text",
1494
+ text: `File already matches the supplied content. Nothing was written.\nPost-edit processing was skipped.\n\n${unchangedSource}`,
1495
+ },
1496
+ ],
1497
+ details: {
1498
+ effect: "not-applied",
1499
+ results: [
1500
+ new FileMutationResult({
1501
+ ok: true,
1502
+ path: unchangedSource,
1503
+ afterContent: content,
1504
+ rawChanges: [],
1505
+ }),
1506
+ ],
1507
+ },
1508
+ };
1509
+ }
1355
1510
  const results = outcome.resources.flatMap((resource) => {
1356
1511
  const resultSource = resource.source;
1357
1512
  const edit = mutation.edits.get(resultSource);
@@ -1366,7 +1521,7 @@ async function buildToolResult(
1366
1521
  mutation.resultPresentations.get(resultSource) ?? "plain",
1367
1522
 
1368
1523
  1,
1369
- [{ operation, changes: edit.changes.length }],
1524
+ textMutationOperationReceipts(operation, edit, resource.before.content),
1370
1525
  ),
1371
1526
  ];
1372
1527
  });
@@ -1545,14 +1700,16 @@ function formatRejectedAnchorMessage(
1545
1700
  : code === "missing"
1546
1701
  ? "was not found"
1547
1702
  : code === "invalid"
1548
- ? "is invalid"
1703
+ ? "was rejected"
1549
1704
  : "could not be resolved";
1550
1705
  const guidance =
1551
1706
  failure.resolution.resolverId === "exact-text"
1552
- ? "Exact-text editing is now blocked for this file until an anchor-based edit succeeds. Find the intended location among the current anchors below, or use Read/Search for another section, and use its anchor. After that edit, exact text is available again."
1707
+ ? failure.toolName === "copy"
1708
+ ? "Use an anchor below, or get a fresh Read/Search selection and pass it to Copy."
1709
+ : "Exact-text edits are blocked for this file. Use a current anchor below for the intended edit, or get one with Read/Search. Exact text is available again after that edit succeeds."
1553
1710
  : "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
1554
1711
  const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
1555
- return `[SYSTEM] ${failure.toolName} blocked: ${failure.field} anchor "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
1712
+ return `[SYSTEM] ${failure.toolName} blocked: ${failure.field === "anchor" ? "anchor" : `${failure.field} anchor`} "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
1556
1713
  }
1557
1714
 
1558
1715
  function recoveryWindows(
@@ -1584,27 +1741,109 @@ export async function buildFailedTextMutationResult(
1584
1741
  context: ExtensionContext,
1585
1742
  effect: "applied" | "not-applied" | "unknown" = "not-applied",
1586
1743
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
1744
+ if (failure.rollback !== undefined) {
1745
+ return failureToolResult(
1746
+ failure.source,
1747
+ failure.code,
1748
+ failure.message,
1749
+ failure.rollback.failed.length === 0 && failure.rollback.originallyMissing.length === 0
1750
+ ? "not-applied"
1751
+ : "unknown",
1752
+ failure.rollback,
1753
+ );
1754
+ }
1587
1755
  return effect === "not-applied"
1588
1756
  ? ((await anchorFailureToolResult(core, failure, context)) ??
1589
- failureToolResult(failure.source, failure.code, failure.message, effect))
1590
- : failureToolResult(failure.source, failure.code, failure.message, effect);
1757
+ failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback))
1758
+ : failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback);
1591
1759
  }
1592
1760
 
1761
+ /** Report Copy rollback evidence without claiming that an unverified destination is unchanged. */
1762
+ export function buildFailedCopyWriteResult(
1763
+ failure: TextResourceEditFailure,
1764
+ unrestoredSources: readonly string[],
1765
+ ): AgentToolResult<FileMutationBatchResult> {
1766
+ const rollbackFailed =
1767
+ failure.rollback === undefined
1768
+ ? unrestoredSources.length > 0
1769
+ : failure.rollback.failed.length > 0 || failure.rollback.originallyMissing.length > 0;
1770
+ const effect = rollbackFailed ? "unknown" : "not-applied";
1771
+ const result = new FileMutationResult({
1772
+ ok: false,
1773
+ path: failure.source,
1774
+ errors: [{ path: failure.source, code: failure.code, reason: failure.message }],
1775
+ fileChangedStatement: rollbackFailed
1776
+ ? "Rollback failed. Read the listed destinations before retrying."
1777
+ : "Copy failed. Destination changes were rolled back.",
1778
+ });
1779
+ return {
1780
+ content: [new FileMutationAgentResult(result).toTextContent()],
1781
+ details: {
1782
+ results: [result],
1783
+ effect,
1784
+ metadata: { copyRollback: rollbackFailed ? "failed" : "restored" },
1785
+ },
1786
+ };
1787
+ }
1593
1788
  function failureToolResult(
1594
1789
  source: string,
1595
1790
  code: string,
1596
1791
  reason: string,
1597
1792
  effect: "not-applied" | "applied" | "unknown",
1793
+ rollback?: TextResourceEditFailure["rollback"],
1794
+ copyExecutionFailure = false,
1598
1795
  ): { content: [{ type: "text"; text: string }]; details: FileMutationBatchResult } {
1796
+ const uncertain =
1797
+ rollback !== undefined && (rollback.failed.length > 0 || rollback.originallyMissing.length > 0);
1798
+ const fileChangedStatement =
1799
+ rollback === undefined
1800
+ ? effect === "applied"
1801
+ ? "The edit was saved, but a post-write step failed. Run Read/Search before editing this resource again."
1802
+ : effect === "unknown"
1803
+ ? "The operation failed, and its effects are unknown. Read the affected resources before retrying."
1804
+ : code === "MUTATION_REJECTED"
1805
+ ? undefined
1806
+ : "No file was changed."
1807
+ : rollback.originallyMissing.length > 0
1808
+ ? "The file may now exist. Read the path before retrying."
1809
+ : uncertain
1810
+ ? `Rollback failed for ${rollback.failed.join(", ")}. Current contents are unknown. Run Read/Search before editing these resources again.`
1811
+ : "Attempted writes were rolled back.";
1599
1812
  const result = new FileMutationResult({
1600
1813
  ok: false,
1601
1814
  path: source,
1602
1815
  errors: [{ path: source, code, reason }],
1816
+ ...(fileChangedStatement === undefined
1817
+ ? {}
1818
+ : {
1819
+ fileChangedStatement:
1820
+ fileChangedStatement +
1821
+ (rollback !== undefined && rollback.restored.length > 0
1822
+ ? `\nRolled back: ${rollback.restored.join(", ")}.`
1823
+ : ""),
1824
+ }),
1825
+ ...(rollback !== undefined && {
1826
+ rollback: {
1827
+ restoredSources: rollback.restored,
1828
+ failedSources: [...new Set([...rollback.failed, ...rollback.originallyMissing])],
1829
+ },
1830
+ }),
1831
+ ...(copyExecutionFailure && {
1832
+ fileChangedStatement:
1833
+ "Copy failed. Its effects are uncertain. Read the affected destinations before retrying.",
1834
+ }),
1603
1835
  });
1604
1836
 
1605
1837
  return {
1606
1838
  content: [new FileMutationAgentResult(result).toTextContent()],
1607
- details: { results: [result], effect },
1839
+ details: {
1840
+ results: [result],
1841
+ effect: rollback === undefined ? effect : uncertain ? "unknown" : "not-applied",
1842
+ ...(rollback === undefined
1843
+ ? {}
1844
+ : { metadata: { rollback: uncertain ? "uncertain" : "restored" } }),
1845
+ ...(copyExecutionFailure && { metadata: { copyExecution: "uncertain" } }),
1846
+ },
1608
1847
  };
1609
1848
  }
1610
1849