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
@@ -1,3 +1,4 @@
1
+ import { readFile } from "node:fs/promises";
1
2
  import path from "node:path";
2
3
  import { requiredValue } from "pi-agent-invariant";
3
4
  import { fileURLToPath } from "node:url";
@@ -21,19 +22,19 @@ import {
21
22
  } from "./text-edit-batch-registrar.js";
22
23
  import { buildFailedTextMutationResult, mutationSources } from "./text-mutation.js";
23
24
  import { isWholeFileInvocation } from "./file-operation-tools.js";
25
+ import { isResultInput } from "./result-transfer.js";
24
26
  import { FileMutationAgentResult } from "./mutation-result/file-mutation-agent-result.js";
25
- import { Type } from "typebox";
27
+ import { writeProblemNotices } from "./write-agent-result.js";
26
28
  import {
27
29
  ResourceScheduler,
28
30
  resourceAccesses,
29
31
  connectResultTargets,
30
32
  resultError,
31
- withStructuredResult,
32
33
  type ResultTargetStore,
33
34
  type StructuredResult,
34
35
  } from "pi-agent-resource";
35
36
  import { createPostEditScope } from "./post-edit-scope.js";
36
- import { committedMutationTargets } from "./mutation-result-targets.js";
37
+ import { committedMutationTargets, unchangedCopySources } from "./mutation-result-targets.js";
37
38
  import { FileMutationResult as MutationPresentation } from "./mutation-result/file-mutation-result.js";
38
39
  import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
39
40
  import { captureScriptMutation } from "./text-mutation.js";
@@ -41,13 +42,7 @@ import {
41
42
  NATIVE_EDIT_BATCH_EVENT,
42
43
  type NativeEditBatchEvent,
43
44
  } from "#src/api/native-edit-batch-event.js";
44
- import {
45
- flushDataSchema,
46
- flushOutputSchema,
47
- mutationOutcome,
48
- type MutationData,
49
- type FlushData,
50
- } from "./structured-result.js";
45
+ import { mutationOutcome, type MutationData, type BatchMutationData } from "./structured-result.js";
51
46
 
52
47
  interface PendingBatch {
53
48
  readonly entries: TextBatchEntry[];
@@ -63,12 +58,12 @@ interface BatchSummary {
63
58
  }
64
59
 
65
60
  interface ScriptBatch {
66
- readonly reports: StructuredResult<FlushData>[];
67
- reportCursor: number;
61
+ readonly reports: StructuredResult<BatchMutationData>[];
68
62
  readonly id: string;
69
63
  readonly context: ExtensionContext;
70
64
  readonly summaries: BatchSummary[];
71
65
  readonly results: FileMutationResult[];
66
+ readonly completedWrites: Set<FileMutationResult>;
72
67
  readonly presentations: NativeEditBatchEvent[];
73
68
  readonly errors: string[];
74
69
  readonly cancellation: AbortController;
@@ -77,10 +72,37 @@ interface ScriptBatch {
77
72
  tail: Promise<void>;
78
73
  readonly scheduler: ResourceScheduler;
79
74
  readonly callOrder: Map<string, number>;
75
+ readonly unfinishedCalls: Map<string, string>;
80
76
  pending: PendingBatch;
81
77
  closed: boolean;
82
78
  }
83
79
 
80
+ function completedWriteNotices(result: FileMutationResult): string[] {
81
+ return writeProblemNotices([result]).map((notice) => `${result.path ?? "Write"}: ${notice}`);
82
+ }
83
+ function replaceScriptResult(
84
+ script: ScriptBatch,
85
+ previous: FileMutationResult,
86
+ updated: FileMutationResult,
87
+ ): void {
88
+ const index = script.results.indexOf(previous);
89
+ if (index >= 0) script.results[index] = updated;
90
+ if (script.completedWrites.delete(previous)) script.completedWrites.add(updated);
91
+ for (const [slot, presentation] of script.presentations.entries()) {
92
+ const results = presentation.result.details.results;
93
+ if (!results?.includes(previous)) continue;
94
+ script.presentations[slot] = {
95
+ ...presentation,
96
+ result: {
97
+ ...presentation.result,
98
+ details: {
99
+ ...presentation.result.details,
100
+ results: results.map((result) => (result === previous ? updated : result)),
101
+ },
102
+ },
103
+ };
104
+ }
105
+ }
84
106
  function mergedFiles(files: MutationData["files"]): MutationData["files"] {
85
107
  const merged = new Map<string, MutationData["files"][number]>();
86
108
  for (const file of files) {
@@ -104,7 +126,7 @@ function receiptEffect(files: MutationData["files"]): MutationData["effect"] {
104
126
  : "not-applied";
105
127
  }
106
128
 
107
- function receiptStatus(errors: readonly unknown[], operations: FlushData["operations"]) {
129
+ function receiptStatus(errors: readonly unknown[], operations: BatchMutationData["operations"]) {
108
130
  return errors.length === 0
109
131
  ? ("success" as const)
110
132
  : operations.some(
@@ -136,6 +158,7 @@ function isBatchable(
136
158
  input: Readonly<Record<string, unknown>>,
137
159
  ): boolean {
138
160
  if (
161
+ registration.name === "write" ||
139
162
  registration.direct?.matches(input) ||
140
163
  registration.intent === "restore" ||
141
164
  isWholeFileInvocation(registration.wholeFileOperation, input) ||
@@ -172,73 +195,6 @@ class NativeTextEditBatchCoordinator {
172
195
  private readonly pi: ExtensionAPI,
173
196
  ) {
174
197
  this.resultTargets = connectResultTargets(pi);
175
- pi.registerTool({
176
- name: "flush",
177
- exposure: "codemode",
178
- namespace: {
179
- name: "ide_edit",
180
- description: "Edit files and live IDE resources with guarded operations.",
181
- },
182
- annotations: {
183
- readOnlyHint: false,
184
- destructiveHint: true,
185
- idempotentHint: false,
186
- openWorldHint: false,
187
- },
188
- label: "Flush",
189
- description:
190
- "Use flush to commit pending native Codemode text edits and return their observed effects. Await tools.flush({}) before depending on a completed write. A failed flush retains applied effects and does not replay edits. Call it only inside native Codemode.",
191
- promptSnippet: "Commit pending native editor changes and inspect their effects",
192
- parameters: Type.Object({}, { additionalProperties: false }),
193
- outputSchema: flushOutputSchema,
194
- execute: async (id) => {
195
- const script = this.invocations.get(id);
196
- if (!script) throw new Error("Flush requires an active native Codemode script");
197
- const work = script.scheduler.run(undefined, async () => {
198
- await this.commit(script);
199
- const reports = script.reports.slice(script.reportCursor);
200
- script.reportCursor = script.reports.length;
201
- const files = mergedFiles(reports.flatMap((report) => report.data?.files ?? []));
202
- const errors = reports.flatMap((report) => report.errors);
203
- const operations = reports.flatMap((report) => report.data?.operations ?? []);
204
- const effect = receiptEffect(files);
205
- return withStructuredResult(
206
- {
207
- content: [
208
- {
209
- type: "text",
210
- text: [
211
- errors.length === 0
212
- ? `Flushed ${operations.length} editor operations; ${effect}.`
213
- : `Editor flush failed; ${effect}.`,
214
- ...files.map(
215
- (file) =>
216
- `${file.source}: ${file.effect}${file.state ? ` (${file.state})` : ""}`,
217
- ),
218
- ...operations.map(
219
- (operation) =>
220
- `${operation.operation}: ${operation.effect}${operation.errors.length ? ` — ${operation.errors.map((error) => error.message).join("; ")}` : ""}`,
221
- ),
222
- ].join("\n"),
223
- },
224
- ],
225
- details: { results: [] },
226
- },
227
- flushDataSchema,
228
- {
229
- status: receiptStatus(errors, operations),
230
- data: { operation: "flush", effect, files, operations },
231
- errors,
232
- },
233
- );
234
- });
235
- script.tail = work.then(
236
- () => undefined,
237
- () => undefined,
238
- );
239
- return work;
240
- },
241
- });
242
198
  pi.on("tool_call", async (event, context) => {
243
199
  if (event.toolName === "codemode" && event.parentToolCallId === undefined) {
244
200
  this.scripts.set(event.toolCallId, {
@@ -246,9 +202,9 @@ class NativeTextEditBatchCoordinator {
246
202
  context,
247
203
  summaries: [],
248
204
  reports: [],
249
- reportCursor: 0,
250
205
  presentations: [],
251
206
  results: [],
207
+ completedWrites: new Set(),
252
208
  errors: [],
253
209
  cancellation: new AbortController(),
254
210
  targets: new Map(),
@@ -256,6 +212,7 @@ class NativeTextEditBatchCoordinator {
256
212
  tail: Promise.resolve(),
257
213
  scheduler: new ResourceScheduler(),
258
214
  callOrder: new Map(),
215
+ unfinishedCalls: new Map(),
259
216
  pending: pendingBatch(),
260
217
  closed: false,
261
218
  });
@@ -264,15 +221,18 @@ class NativeTextEditBatchCoordinator {
264
221
  const script =
265
222
  event.parentToolCallId === undefined ? undefined : this.scripts.get(event.parentToolCallId);
266
223
  if (!script) return;
267
- if (event.toolName === "flush") {
268
- this.invocations.set(event.toolCallId, script);
269
- return;
270
- }
271
224
  const registration = this.core
272
225
  .getMutationTools()
273
226
  .find((tool) => tool.name === event.toolName);
274
- if (registration) this.scopedInvocations.set(event.toolCallId, script);
275
227
  const input: Record<string, unknown> = event.input;
228
+ if (registration) {
229
+ this.scopedInvocations.set(event.toolCallId, script);
230
+ const source = input[registration.source.field];
231
+ script.unfinishedCalls.set(
232
+ event.toolCallId,
233
+ typeof source === "string" && !isResultInput(source) ? source : "",
234
+ );
235
+ }
276
236
  let ownsSource = false;
277
237
  if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
278
238
  const resolverContext = {
@@ -283,7 +243,9 @@ class NativeTextEditBatchCoordinator {
283
243
  const value = input[descriptor.field];
284
244
  if (typeof value === "string" && value.length > 0) {
285
245
  if (
286
- ["replace", "write", "copy", "move", "delete", "undo"].includes(registration.name) &&
246
+ ["replace", "write", "copy", "move", "delete", "undo", "insert"].includes(
247
+ registration.name,
248
+ ) &&
287
249
  value.startsWith("RESULT#")
288
250
  ) {
289
251
  // The executor validates result handles and returns a structured rejection.
@@ -326,25 +288,51 @@ class NativeTextEditBatchCoordinator {
326
288
  return;
327
289
  });
328
290
  pi.on("tool_result", async (event) => {
291
+ this.scopedInvocations.get(event.toolCallId)?.unfinishedCalls.delete(event.toolCallId);
329
292
  this.invocations.delete(event.toolCallId);
330
293
  this.scopedInvocations.delete(event.toolCallId);
331
294
  const script = this.scripts.get(event.toolCallId);
332
295
  if (!script) return;
333
296
  script.closed = true;
297
+ const texts = event.content
298
+ .filter((block) => block.type === "text")
299
+ .map((block) => block.text);
300
+ let executionError = texts.findLast((text) => text.startsWith("Script error:\n")) ?? "";
301
+ const executionDetails = event.details;
302
+ if (
303
+ event.isError &&
304
+ executionDetails !== null &&
305
+ typeof executionDetails === "object" &&
306
+ "fullOutputPath" in executionDetails &&
307
+ typeof executionDetails.fullOutputPath === "string"
308
+ ) {
309
+ try {
310
+ const output = await readFile(executionDetails.fullOutputPath, "utf8");
311
+ // A timeout has one engine error line followed by the call summary, not a JavaScript stack.
312
+ const matches = [
313
+ ...output.matchAll(
314
+ /(?:^|\n)(Script error:\nScript (?:aborted|timed out):[^\n]*\n\n(?:Tool calls made before the failure[^\n]*|No tool calls were made\.))/gu,
315
+ ),
316
+ ];
317
+ const match = matches.at(-1);
318
+ executionError =
319
+ match !== undefined &&
320
+ !output.slice(match.index + match[0].length).includes("Script error:\n")
321
+ ? (match[1] ?? "")
322
+ : "";
323
+ } catch {
324
+ // Use the returned output when its complete artifact is unavailable.
325
+ }
326
+ }
334
327
  const interrupted =
335
328
  script.context.signal?.aborted ||
336
- (event.isError &&
337
- event.content.some(
338
- (block) =>
339
- block.type === "text" &&
340
- /^Script error:\nScript (?:aborted|timed out):/u.test(block.text),
341
- ));
329
+ (event.isError && /^Script error:\nScript (?:aborted|timed out):/u.test(executionError));
342
330
  if (interrupted) script.cancellation.abort();
343
331
  await script.tail;
344
332
  if (interrupted) {
345
333
  if (script.pending.entries.length > 0) {
346
334
  const error = resultError(
347
- "Pending editor batch cancelled; no pending edits were written.",
335
+ "The operation was interrupted before writing. No file was changed.",
348
336
  "CANCELLED",
349
337
  );
350
338
  const operations = script.pending.entries.map((entry) => ({
@@ -357,7 +345,7 @@ class NativeTextEditBatchCoordinator {
357
345
  status: "error",
358
346
  errors: [error],
359
347
  data: {
360
- operation: "flush",
348
+ operation: "batch",
361
349
  effect: "not-applied",
362
350
  operations,
363
351
  files: [...script.pending.snapshots.keys()].map((source) => ({
@@ -374,46 +362,85 @@ class NativeTextEditBatchCoordinator {
374
362
  script.pending = pendingBatch();
375
363
  }
376
364
  } else await this.commit(script);
365
+ if (interrupted) {
366
+ for (const [id, source] of script.unfinishedCalls) {
367
+ if (
368
+ script.presentations.some((presentation) => presentation.calls.includes(id)) ||
369
+ script.reports.some((report) =>
370
+ report.data?.operations.some((operation) => operation.id === id),
371
+ )
372
+ )
373
+ continue;
374
+ // Cancellation is not a result. Do not guess whether a resolver already wrote.
375
+ const message =
376
+ "The operation was interrupted. Its file effects are unknown.\nRead the affected files before retrying.";
377
+ const presentation = new MutationPresentation({
378
+ ok: false,
379
+ path: source,
380
+ fileChangedStatement: message,
381
+ errors: [{ path: source, code: "CANCELLED" }],
382
+ });
383
+ const result: AgentToolResult<FileMutationBatchResult> = {
384
+ content: [new FileMutationAgentResult(presentation).toTextContent()],
385
+ details: { results: [presentation], effect: "unknown" },
386
+ isError: true,
387
+ };
388
+ script.results.push(presentation);
389
+ script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
390
+ }
391
+ }
377
392
  try {
378
393
  await this.core.enqueueFileOperation(
379
394
  () =>
380
- script.postEdits.finish((outcome) => {
381
- const index = script.results.findLastIndex(
382
- (item) => item.data.path === outcome.after.source,
383
- );
384
- if (index < 0) return;
385
- const previous = requiredValue(script.results[index]).data;
386
- const updated = new MutationPresentation({
387
- ...previous,
388
- afterContent: outcome.after.content,
389
- afterDocument: outcome.after,
390
- formatting: outcome.postEditContributions
391
- .map((item) => item.data)
392
- .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
393
- diffStatuses: outcome.postEditContributions
394
- .map((item) => item.data)
395
- .filter(isDiffStatusContribution)
396
- .flatMap((item) => item.diffStatuses),
397
- });
398
- const previousResult = requiredValue(script.results[index]);
399
- script.results[index] = updated;
400
- for (const [slot, presentation] of script.presentations.entries()) {
401
- const results = presentation.result.details.results;
402
- if (!results?.includes(previousResult)) continue;
403
- script.presentations[slot] = {
404
- ...presentation,
405
- result: {
406
- ...presentation.result,
407
- details: {
408
- ...presentation.result.details,
409
- results: results.map((result) =>
410
- result === previousResult ? updated : result,
411
- ),
412
- },
413
- },
414
- };
415
- }
416
- }),
395
+ script.postEdits.finish(
396
+ (outcome) => {
397
+ const index = script.results.findLastIndex(
398
+ (item) => item.data.path === outcome.after.source,
399
+ );
400
+ if (index < 0) return;
401
+ const previous = requiredValue(script.results[index]).data;
402
+ const updated = new MutationPresentation({
403
+ ...previous,
404
+ afterContent: outcome.after.content,
405
+ afterDocument: outcome.after,
406
+ formatting: outcome.postEditContributions
407
+ .map((item) => item.data)
408
+ .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
409
+ diffStatuses: outcome.postEditContributions
410
+ .map((item) => item.data)
411
+ .filter(isDiffStatusContribution)
412
+ .flatMap((item) => item.diffStatuses),
413
+ });
414
+ replaceScriptResult(script, requiredValue(script.results[index]), updated);
415
+ },
416
+ (source, error) => {
417
+ const reason = error instanceof Error ? error.message : String(error);
418
+ const failure = { code: "POST_EDIT_FAILED", message: reason, source };
419
+ for (const previous of script.results.filter(
420
+ (result) => result.data.path === source,
421
+ )) {
422
+ replaceScriptResult(
423
+ script,
424
+ previous,
425
+ new MutationPresentation({
426
+ ok: false,
427
+ path: source,
428
+ errors: [{ path: source, code: failure.code, reason }],
429
+ fileChangedStatement:
430
+ "The edit was saved, but final processing failed. Final text is not confirmed. Run Read/Search before editing this resource again.",
431
+ }),
432
+ );
433
+ }
434
+ for (const [index, report] of script.reports.entries()) {
435
+ if (!report.data?.files.some((file) => file.source === source)) continue;
436
+ script.reports[index] = {
437
+ ...report,
438
+ status: report.status === "success" ? "partial" : report.status,
439
+ errors: [...report.errors, failure],
440
+ };
441
+ }
442
+ },
443
+ ),
417
444
  undefined,
418
445
  { cwd: script.context.cwd, sources: script.postEdits.sources() },
419
446
  );
@@ -432,6 +459,11 @@ class NativeTextEditBatchCoordinator {
432
459
  } satisfies NativeEditBatchEvent);
433
460
  }
434
461
  this.scripts.delete(event.toolCallId);
462
+ // Write already returned its compact receipt to the script. Keep full user panels,
463
+ // but do not append their file text outside explicit script output.
464
+ const parentResults = script.results.filter(
465
+ (result) => !result.ok || !script.completedWrites.has(result),
466
+ );
435
467
  if (
436
468
  script.results.length === 0 &&
437
469
  script.summaries.length === 0 &&
@@ -444,12 +476,17 @@ class NativeTextEditBatchCoordinator {
444
476
  ? { ...block, text: block.text.replace(/^Script completed\n/u, "Script failed\n") }
445
477
  : block,
446
478
  );
447
- content.push({
448
- type: "text",
449
- text: `Editor batches: ${script.summaries.filter((batch) => batch.applied).length} committed.${failed ? "\n" + script.errors.join("\n") : ""}`,
450
- });
451
- if (script.results.length > 0)
452
- content.push(new FileMutationAgentResult(script.results).toTextContent());
479
+ if (script.summaries.length > 0 || failed)
480
+ content.push({
481
+ type: "text",
482
+ text: `Editor batches: ${script.summaries.filter((batch) => batch.applied).length} committed.${failed ? "\n" + script.errors.join("\n") : ""}`,
483
+ });
484
+ const writeNotices = script.results
485
+ .filter((result) => result.ok && script.completedWrites.has(result))
486
+ .flatMap(completedWriteNotices);
487
+ if (writeNotices.length > 0) content.push({ type: "text", text: writeNotices.join("\n") });
488
+ if (parentResults.length > 0)
489
+ content.push(new FileMutationAgentResult(parentResults).toTextContent());
453
490
  const details =
454
491
  typeof event.details === "object" && event.details !== null ? event.details : {};
455
492
  return {
@@ -478,17 +515,30 @@ class NativeTextEditBatchCoordinator {
478
515
  pi.on("session_shutdown", clear);
479
516
  }
480
517
 
481
- /** Keep every mutation in the script's shared post-edit scope, including non-batched calls. */
482
- runPostEdits<T>(id: string, work: () => T): T {
518
+ /** Share post-edit state while allowing Write to finish its own processing immediately. */
519
+ runPostEdits<T>(id: string, work: () => T, immediate: boolean): T {
483
520
  const script = this.scopedInvocations.get(id);
484
- return script ? script.postEdits.run(work) : work();
521
+ return script ? script.postEdits.run(work, immediate) : work();
485
522
  }
486
523
 
487
- /** Include non-batched mutations in the script's final post-edit presentation. */
488
- recordMutation(id: string, result: AgentToolResult<FileMutationBatchResult>): void {
524
+ /** Include applied, non-batched mutations in the script's final post-edit presentation. */
525
+ recordMutation(
526
+ id: string,
527
+ toolName: string,
528
+ result: AgentToolResult<FileMutationBatchResult>,
529
+ ): void {
489
530
  const script = this.scopedInvocations.get(id);
490
- if (!script || !result.details.results?.some((item) => item.data.ok === true)) return;
531
+ if (script && !script.closed) script.unfinishedCalls.delete(id);
532
+ if (
533
+ !script ||
534
+ script.closed ||
535
+ result.details.effect === "not-applied" ||
536
+ !result.details.results?.some((item) => item.data.ok === true)
537
+ )
538
+ return;
491
539
  script.results.push(...result.details.results);
540
+ if (toolName === "write")
541
+ for (const item of result.details.results) script.completedWrites.add(item);
492
542
  script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
493
543
  }
494
544
  execute(
@@ -615,6 +665,13 @@ class NativeTextEditBatchCoordinator {
615
665
  ? this.resultTargets.reserve(context.cwd)
616
666
  : undefined;
617
667
  if (target) script.targets.set(id, target);
668
+ const unchangedCopy =
669
+ registration.name === "copy" &&
670
+ planning.plan.mutations.every(
671
+ ({ mutation }) =>
672
+ mutation.edits.size > 0 &&
673
+ unchangedCopySources(mutation, batch.snapshots).size === mutation.edits.size,
674
+ );
618
675
  const details = {
619
676
  results: [],
620
677
  source: entry.path,
@@ -626,7 +683,12 @@ class NativeTextEditBatchCoordinator {
626
683
  content: [
627
684
  {
628
685
  type: "text",
629
- text: `Accepted ${registration.name} for ${entry.path}; not yet applied. The editor batch commits before another tool or when this script ends.`,
686
+ text:
687
+ registration.name === "copy"
688
+ ? unchangedCopy
689
+ ? "No changes: destination already has this text."
690
+ : `Copy destination: ${typeof normalized.target === "string" ? normalized.target : entry.path}`
691
+ : `Accepted ${registration.name} for ${entry.path}. Check the final Codemode result for applied changes.`,
630
692
  },
631
693
  ],
632
694
  details,
@@ -645,6 +707,7 @@ class NativeTextEditBatchCoordinator {
645
707
  mapped = committedMutationTargets(
646
708
  batch.plan.mutations.map(({ callId, mutation }) => ({ callId, edits: mutation.edits })),
647
709
  completions,
710
+ batch.snapshots,
648
711
  );
649
712
  } catch (error) {
650
713
  for (const entry of batch.entries) {
@@ -688,18 +751,45 @@ class NativeTextEditBatchCoordinator {
688
751
  script.context.signal === undefined
689
752
  ? script.cancellation.signal
690
753
  : AbortSignal.any([script.context.signal, script.cancellation.signal]);
754
+ const unchangedCopies = new Map(
755
+ batch.plan.mutations
756
+ .filter(({ mutation }) => mutation.operation === "copy")
757
+ .map(({ callId, mutation }) => {
758
+ const sources = unchangedCopySources(mutation, batch.snapshots);
759
+ return [
760
+ callId,
761
+ { sources, all: sources.size > 0 && sources.size === mutation.edits.size },
762
+ ] as const;
763
+ }),
764
+ );
691
765
  let observedSources: string[] = [];
692
- const record = (outcome: StructuredResult<MutationData>): boolean => {
766
+ const record = (
767
+ outcome: StructuredResult<MutationData>,
768
+ results: readonly FileMutationResult[] = [],
769
+ ): boolean => {
770
+ // Only explicit rollback evidence overrides the journal's call-wide effect.
771
+ const reportedFiles = new Map<string, MutationData["files"][number]>(
772
+ results.flatMap(({ data }) => [
773
+ ...(data.rollback?.restoredSources ?? []).map(
774
+ (source) => [source, { source, effect: "not-applied" as const }] as const,
775
+ ),
776
+ ...(data.rollback?.failedSources ?? []).map(
777
+ (source) => [source, { source, effect: "unknown" as const }] as const,
778
+ ),
779
+ ]),
780
+ );
693
781
  const calls = journal.snapshot();
694
782
  const operations = calls.map((call) => ({
695
783
  id: call.callId,
696
784
  operation: requiredValue(batch.entries.find((entry) => entry.callId === call.callId)).op,
697
785
  effect:
698
- call.state === "completed" || call.state === "failed-applied"
699
- ? ("applied" as const)
700
- : call.state === "failed-unknown" || call.state === "running"
701
- ? ("unknown" as const)
702
- : ("not-applied" as const),
786
+ call.state === "completed" && unchangedCopies.get(call.callId)?.all
787
+ ? ("not-applied" as const)
788
+ : call.state === "completed" || call.state === "failed-applied"
789
+ ? ("applied" as const)
790
+ : call.state === "failed-unknown" || call.state === "running"
791
+ ? ("unknown" as const)
792
+ : ("not-applied" as const),
703
793
  errors: call.failure === undefined ? [] : [resultError(call.failure.error)],
704
794
  }));
705
795
  const files = mergedFiles([
@@ -712,12 +802,17 @@ class NativeTextEditBatchCoordinator {
712
802
  return [...mutationSources(registration, entry).values()].map((source) => ({
713
803
  source,
714
804
  effect:
715
- mutation?.edits.has(source) === false ? ("not-applied" as const) : operation.effect,
805
+ mutation?.edits.has(source) === false ||
806
+ unchangedCopies.get(operation.id)?.sources.has(source) === true
807
+ ? ("not-applied" as const)
808
+ : operation.effect,
716
809
  }));
717
810
  }),
718
811
  ...observedSources.map((source) => ({ source, effect: "applied" as const })),
719
812
  ]).map((file) =>
720
- observedSources.includes(file.source) ? { ...file, effect: "applied" as const } : file,
813
+ observedSources.includes(file.source)
814
+ ? { ...file, effect: "applied" as const }
815
+ : (reportedFiles.get(file.source) ?? file),
721
816
  );
722
817
  const errors = [
723
818
  ...new Map(
@@ -734,7 +829,7 @@ class NativeTextEditBatchCoordinator {
734
829
  errors,
735
830
  data: {
736
831
  ...outcome.data,
737
- operation: "flush",
832
+ operation: "batch",
738
833
  effect: receiptEffect(files),
739
834
  files,
740
835
  operations,
@@ -775,16 +870,39 @@ class NativeTextEditBatchCoordinator {
775
870
  );
776
871
  observedSources = captured.completions.map((completion) => completion.resourceSource);
777
872
  if (captured.kind === "failed") throw captured.error;
778
- script.results.push(...(captured.value.details.results ?? []));
873
+ const value =
874
+ captured.completions.length === 0 &&
875
+ journal
876
+ .snapshot()
877
+ .every((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
878
+ ? {
879
+ ...captured.value,
880
+ content: [
881
+ { type: "text" as const, text: "No changes: destination already has this text." },
882
+ ],
883
+ details: { ...captured.value.details, effect: "not-applied" as const },
884
+ }
885
+ : captured.value;
886
+ script.results.push(...(value.details.results ?? []));
779
887
  await this.settleTargets(script, batch, journal, captured.completions, signal);
780
888
  const presentation = {
781
889
  parentToolCallId: script.id,
782
890
  calls: batch.entries.map((entry) => entry.callId),
783
- result: captured.value,
891
+ unchangedCopyCalls: journal
892
+ .snapshot()
893
+ .filter((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
894
+ .map((call) => call.callId),
895
+ ...(value.details.copyResults === undefined
896
+ ? {}
897
+ : { copyResults: value.details.copyResults }),
898
+ result: value,
784
899
  } satisfies NativeEditBatchEvent;
785
900
  script.presentations.push(presentation);
786
901
  this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, presentation);
787
- return record(mutationOutcome(captured.value, "flush", captured.completions));
902
+ return record(
903
+ mutationOutcome(value, "batch", captured.completions),
904
+ value.details.results ?? [],
905
+ );
788
906
  } catch (error) {
789
907
  journal.markRunningUnknown(error);
790
908
  await this.settleTargets(script, batch, journal, [], signal);
@@ -795,19 +913,25 @@ class NativeTextEditBatchCoordinator {
795
913
 
796
914
  const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
797
915
 
798
- /** Run immediate mutation paths under the same deferred post-edit boundary as native batches. */
799
- export function runNativePostEditScope<T>(core: TextEditorCore, id: string, work: () => T): T {
916
+ /** Share deferred post-edit state, or finish this operation's processing before return. */
917
+ export function runNativePostEditScope<T>(
918
+ core: TextEditorCore,
919
+ id: string,
920
+ work: () => T,
921
+ immediate = false,
922
+ ): T {
800
923
  const coordinator = coordinators.get(core);
801
- return coordinator ? coordinator.runPostEdits(id, work) : work();
924
+ return coordinator ? coordinator.runPostEdits(id, work, immediate) : work();
802
925
  }
803
926
 
804
- /** Retain immediate child results so final formatting is visible on the parent script. */
927
+ /** Retain immediate child results for final user panels and deferred processing failures. */
805
928
  export function recordNativeTextMutation(
806
929
  core: TextEditorCore,
807
930
  id: string,
931
+ toolName: string,
808
932
  result: AgentToolResult<FileMutationBatchResult>,
809
933
  ): void {
810
- coordinators.get(core)?.recordMutation(id, result);
934
+ coordinators.get(core)?.recordMutation(id, toolName, result);
811
935
  }
812
936
  /** Attach accumulating editor batches to native Codemode's public parent/child lifecycle. */
813
937
  export function registerNativeTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void {