pi-agent-ide 0.7.0 → 0.7.2

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 (323) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/chunk-6U5OU77O.js +3 -0
  3. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  4. package/dist/chunk-EURHXLN3.js +2 -0
  5. package/dist/{chunk-PYPPV2F5.js → chunk-F6IWZKOG.js} +6 -6
  6. package/dist/{chunk-GBLKIB6O.js → chunk-H445SHSJ.js} +2 -2
  7. package/dist/chunk-IG56UGSO.js +2 -0
  8. package/dist/chunk-IICJXZBU.js +6 -0
  9. package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
  10. package/dist/{chunk-YRF7OATP.js → chunk-KOVPDKSJ.js} +1 -1
  11. package/dist/chunk-MXLSGMRZ.js +3 -0
  12. package/dist/chunk-NRZO5KJT.js +9 -0
  13. package/dist/chunk-OB46OPMZ.js +1 -0
  14. package/dist/chunk-PKSQT6TC.js +1 -0
  15. package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
  16. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  17. package/dist/chunk-QUYXINGZ.js +7 -0
  18. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  19. package/dist/chunk-SBP3ABH4.js +5 -0
  20. package/dist/{chunk-FXNKMNSJ.js → chunk-SJ4UZ4GU.js} +1 -1
  21. package/dist/chunk-SNF7PDDX.js +11 -0
  22. package/dist/{chunk-AJRIASPQ.js → chunk-STBJO3Z3.js} +1 -1
  23. package/dist/{chunk-3HYXQ4YA.js → chunk-TQGE7RH6.js} +13 -13
  24. package/dist/{chunk-S5LXX32D.js → chunk-XDG7EQRN.js} +3 -3
  25. package/dist/{chunk-F5YZG77W.js → chunk-XH5WN5XA.js} +1 -1
  26. package/dist/chunk-YWQS33DF.js +1 -0
  27. package/dist/chunk-ZIWPKIBZ.js +1 -0
  28. package/dist/entry-11.js +1 -1
  29. package/dist/entry-13.js +1 -1
  30. package/dist/entry-14.js +1 -1
  31. package/dist/entry-15.js +1 -1
  32. package/dist/entry-17.js +1 -1
  33. package/dist/entry-25.js +2 -2
  34. package/dist/entry-26.js +1 -1
  35. package/dist/entry-27.js +2 -2
  36. package/dist/entry-28.js +1 -1
  37. package/dist/entry-29.js +1 -1
  38. package/dist/entry-31.js +15 -13
  39. package/dist/entry-33.js +2 -1
  40. package/dist/entry-37.js +6 -6
  41. package/dist/entry-41.js +1 -1
  42. package/dist/entry-42.js +1 -1
  43. package/dist/entry-43.js +1 -1
  44. package/dist/entry-44.js +1 -1
  45. package/dist/entry-45.js +20 -13
  46. package/dist/entry-46.js +1 -1
  47. package/dist/entry-49.js +1 -1
  48. package/dist/entry-50.js +1 -1
  49. package/dist/entry-51.js +8 -7
  50. package/dist/entry-52.js +1 -1
  51. package/dist/entry-53.js +1 -1
  52. package/dist/entry-54.js +1 -1
  53. package/dist/entry-56.js +1 -1
  54. package/dist/entry-57.js +1 -1
  55. package/dist/entry-58.js +1 -1
  56. package/dist/entry-60.js +1 -1
  57. package/dist/entry-62.js +1 -1
  58. package/dist/entry-65.js +1 -1
  59. package/dist/entry-66.js +1 -1
  60. package/dist/entry-68.js +1 -1
  61. package/dist/entry-70.js +1 -1
  62. package/dist/entry-75.js +1 -1
  63. package/dist/entry-77.js +51 -43
  64. package/dist/entry-78.js +14 -14
  65. package/dist/entry-79.js +1 -1
  66. package/dist/entry-80.js +1 -1
  67. package/dist/entry-82.js +5 -5
  68. package/dist/entry-83.js +1 -1
  69. package/dist/entry-84.js +1 -1
  70. package/dist/entry-85.js +1 -1
  71. package/dist/entry-86.js +1 -1
  72. package/dist/pi-agent-ide.js +37 -9
  73. package/docs/agent-guides/editing.md +35 -46
  74. package/docs/agent-guides/git-changes.md +10 -0
  75. package/docs/agent-guides/read-resources.md +9 -50
  76. package/docs/agent-guides/search-code.md +18 -17
  77. package/docs/agent-guides/select-code.md +62 -140
  78. package/docs/agent-guides/terminal.md +9 -1
  79. package/docs/configuration.md +1 -1
  80. package/docs/releases.md +4 -0
  81. package/docs/research/native-codemode-batch-decision.md +2 -0
  82. package/docs/structured-results.md +27 -62
  83. package/docs/tools.md +15 -11
  84. package/node_modules/pi-agent-doctor/package.json +1 -1
  85. package/node_modules/pi-agent-documentation/package.json +1 -1
  86. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  87. package/node_modules/pi-agent-filesystem/package.json +7 -7
  88. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  89. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  90. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  91. package/node_modules/pi-agent-filesystem-jq/src/jq.ts +4 -1
  92. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  93. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  94. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  95. package/node_modules/pi-agent-ide-ast/src/extension.ts +5 -4
  96. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  97. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +35 -9
  98. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  99. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +10 -8
  100. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +28 -3
  101. package/node_modules/pi-agent-ide-changes/index.ts +4 -3
  102. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  103. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
  104. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  105. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  106. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  107. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  108. package/node_modules/pi-agent-ide-lsp/index.ts +3 -3
  109. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  110. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
  111. package/node_modules/pi-agent-image/package.json +2 -2
  112. package/node_modules/pi-agent-invariant/package.json +1 -1
  113. package/node_modules/pi-agent-pdf/package.json +2 -2
  114. package/node_modules/pi-agent-read/package.json +7 -7
  115. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  116. package/node_modules/pi-agent-read/src/api/read-parameters.ts +38 -1
  117. package/node_modules/pi-agent-read/src/api/tools/read.ts +18 -1
  118. package/node_modules/pi-agent-read/src/core/extension.ts +8 -2
  119. package/node_modules/pi-agent-read/src/core/read-core.ts +54 -35
  120. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  121. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  122. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  123. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  124. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  125. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +108 -46
  126. package/node_modules/pi-agent-resource/package.json +1 -1
  127. package/node_modules/pi-agent-resource/src/index.ts +1 -0
  128. package/node_modules/pi-agent-resource/src/result-targets.ts +186 -9
  129. package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
  130. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  131. package/node_modules/pi-agent-search/package.json +5 -5
  132. package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
  133. package/node_modules/pi-agent-search/src/api/search-parameters.ts +3 -3
  134. package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
  135. package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
  136. package/node_modules/pi-agent-search-text/index.ts +1 -1
  137. package/node_modules/pi-agent-search-text/package.json +7 -7
  138. package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
  139. package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
  140. package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
  141. package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
  142. package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
  143. package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
  144. package/node_modules/pi-agent-text/package.json +2 -2
  145. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  146. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  147. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  148. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  149. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  150. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  151. package/node_modules/pi-agent-text-editor/package.json +9 -9
  152. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  153. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
  154. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  155. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  156. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  157. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  158. package/node_modules/pi-agent-text-editor/src/core/extension.ts +10 -3
  159. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  160. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
  161. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -1
  162. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  163. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +232 -144
  164. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  165. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
  166. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +7 -2
  167. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +49 -214
  168. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  169. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +152 -22
  170. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  171. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +76 -32
  172. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
  173. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  174. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
  175. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
  176. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  177. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  178. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  179. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
  180. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  181. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  182. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  183. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +54 -5
  184. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  185. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  186. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  187. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  188. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  189. package/node_modules/pi-agent-web/index.ts +4 -3
  190. package/node_modules/pi-agent-web/package.json +7 -7
  191. package/node_modules/pi-agent-web/src/resolver.ts +11 -13
  192. package/node_modules/pi-agent-web-html/package.json +2 -2
  193. package/node_modules/pi-agent-web-image/package.json +3 -3
  194. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  195. package/node_modules/pi-agent-web-text/package.json +3 -3
  196. package/package.json +35 -35
  197. package/src/composite/nested-tool-rendering.ts +64 -6
  198. package/src/composite/output-limits.ts +125 -0
  199. package/src/composite/responses-tools.ts +25 -0
  200. package/src/composite/text-results.ts +372 -0
  201. package/src/documentation/extension.ts +11 -9
  202. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  203. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  204. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  205. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  206. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  207. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
  208. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  209. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  210. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +4 -3
  211. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  212. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  213. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  214. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  215. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  216. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +11 -13
  217. package/src/extensions/pi-agent-read/package.json +7 -7
  218. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  219. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +38 -1
  220. package/src/extensions/pi-agent-read/src/api/tools/read.ts +18 -1
  221. package/src/extensions/pi-agent-read/src/core/extension.ts +8 -2
  222. package/src/extensions/pi-agent-read/src/core/read-core.ts +54 -35
  223. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  224. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  225. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  226. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  227. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  228. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +108 -46
  229. package/src/extensions/pi-agent-search/package.json +5 -5
  230. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  231. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  232. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
  233. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
  234. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
  235. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
  236. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
  237. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
  238. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
  239. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +3 -3
  240. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
  241. package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
  242. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  243. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  244. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  245. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  246. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  247. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  248. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  249. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  250. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  251. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +54 -5
  252. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  253. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  254. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  255. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
  256. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  257. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  258. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  259. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  260. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +10 -3
  261. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  262. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
  263. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -1
  264. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  265. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +232 -144
  266. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  267. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
  268. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +7 -2
  269. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +49 -214
  270. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  271. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +152 -22
  272. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  273. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +76 -32
  274. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
  275. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  276. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
  277. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
  278. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  279. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  280. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  281. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
  282. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  283. package/src/pi-agent-ide.ts +15 -1
  284. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  285. package/src/plugins/pi-agent-ide-ast/src/extension.ts +5 -4
  286. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  287. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +35 -9
  288. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  289. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +10 -8
  290. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +28 -3
  291. package/src/plugins/pi-agent-ide-changes/index.ts +4 -3
  292. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  293. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
  294. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  295. package/src/plugins/pi-agent-ide-debugger/index.ts +22 -10
  296. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
  297. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
  298. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +6 -3
  299. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  300. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  301. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  302. package/src/plugins/pi-agent-ide-lsp/index.ts +3 -3
  303. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  304. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
  305. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
  306. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  307. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
  308. package/src/plugins/pi-agent-ide-vision/index.ts +13 -4
  309. package/src/post-edit/gate.ts +13 -2
  310. package/dist/chunk-3JO7QFIL.js +0 -1
  311. package/dist/chunk-4NIFBFFR.js +0 -11
  312. package/dist/chunk-64M3SQPG.js +0 -3
  313. package/dist/chunk-7LZKOHH2.js +0 -1
  314. package/dist/chunk-EAZGN5ND.js +0 -7
  315. package/dist/chunk-FK42RSF4.js +0 -1
  316. package/dist/chunk-KBP3QUDT.js +0 -2
  317. package/dist/chunk-KR36BT5E.js +0 -1
  318. package/dist/chunk-MBUXFKIW.js +0 -3
  319. package/dist/chunk-OE7QVAI2.js +0 -5
  320. package/dist/chunk-SILJ3OL4.js +0 -9
  321. package/dist/chunk-SQKAXYIR.js +0 -2
  322. package/dist/chunk-VCGNVTXQ.js +0 -1
  323. 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,18 @@ 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";
26
27
  import {
27
28
  ResourceScheduler,
28
29
  resourceAccesses,
29
30
  connectResultTargets,
30
31
  resultError,
31
- withStructuredResult,
32
32
  type ResultTargetStore,
33
33
  type StructuredResult,
34
34
  } from "pi-agent-resource";
35
35
  import { createPostEditScope } from "./post-edit-scope.js";
36
- import { committedMutationTargets } from "./mutation-result-targets.js";
36
+ import { committedMutationTargets, unchangedCopySources } from "./mutation-result-targets.js";
37
37
  import { FileMutationResult as MutationPresentation } from "./mutation-result/file-mutation-result.js";
38
38
  import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
39
39
  import { captureScriptMutation } from "./text-mutation.js";
@@ -41,12 +41,7 @@ import {
41
41
  NATIVE_EDIT_BATCH_EVENT,
42
42
  type NativeEditBatchEvent,
43
43
  } from "#src/api/native-edit-batch-event.js";
44
- import {
45
- mutationDataSchema,
46
- mutationOutputSchema,
47
- mutationOutcome,
48
- type MutationData,
49
- } from "./structured-result.js";
44
+ import { mutationOutcome, type MutationData, type BatchMutationData } from "./structured-result.js";
50
45
 
51
46
  interface PendingBatch {
52
47
  readonly entries: TextBatchEntry[];
@@ -62,8 +57,7 @@ interface BatchSummary {
62
57
  }
63
58
 
64
59
  interface ScriptBatch {
65
- readonly reports: StructuredResult<MutationData>[];
66
- reportCursor: number;
60
+ readonly reports: StructuredResult<BatchMutationData>[];
67
61
  readonly id: string;
68
62
  readonly context: ExtensionContext;
69
63
  readonly summaries: BatchSummary[];
@@ -76,10 +70,33 @@ interface ScriptBatch {
76
70
  tail: Promise<void>;
77
71
  readonly scheduler: ResourceScheduler;
78
72
  readonly callOrder: Map<string, number>;
73
+ readonly unfinishedCalls: Map<string, string>;
79
74
  pending: PendingBatch;
80
75
  closed: boolean;
81
76
  }
82
77
 
78
+ function replaceScriptResult(
79
+ script: ScriptBatch,
80
+ previous: FileMutationResult,
81
+ updated: FileMutationResult,
82
+ ): void {
83
+ const index = script.results.indexOf(previous);
84
+ if (index >= 0) script.results[index] = updated;
85
+ for (const [slot, presentation] of script.presentations.entries()) {
86
+ const results = presentation.result.details.results;
87
+ if (!results?.includes(previous)) continue;
88
+ script.presentations[slot] = {
89
+ ...presentation,
90
+ result: {
91
+ ...presentation.result,
92
+ details: {
93
+ ...presentation.result.details,
94
+ results: results.map((result) => (result === previous ? updated : result)),
95
+ },
96
+ },
97
+ };
98
+ }
99
+ }
83
100
  function mergedFiles(files: MutationData["files"]): MutationData["files"] {
84
101
  const merged = new Map<string, MutationData["files"][number]>();
85
102
  for (const file of files) {
@@ -103,10 +120,7 @@ function receiptEffect(files: MutationData["files"]): MutationData["effect"] {
103
120
  : "not-applied";
104
121
  }
105
122
 
106
- function receiptStatus(
107
- errors: readonly unknown[],
108
- operations: NonNullable<MutationData["operations"]>,
109
- ) {
123
+ function receiptStatus(errors: readonly unknown[], operations: BatchMutationData["operations"]) {
110
124
  return errors.length === 0
111
125
  ? ("success" as const)
112
126
  : operations.some(
@@ -138,6 +152,7 @@ function isBatchable(
138
152
  input: Readonly<Record<string, unknown>>,
139
153
  ): boolean {
140
154
  if (
155
+ registration.name === "write" ||
141
156
  registration.direct?.matches(input) ||
142
157
  registration.intent === "restore" ||
143
158
  isWholeFileInvocation(registration.wholeFileOperation, input) ||
@@ -174,64 +189,6 @@ class NativeTextEditBatchCoordinator {
174
189
  private readonly pi: ExtensionAPI,
175
190
  ) {
176
191
  this.resultTargets = connectResultTargets(pi);
177
- pi.registerTool({
178
- name: "flush",
179
- exposure: "codemode",
180
- namespace: {
181
- name: "ide_edit",
182
- description: "Edit files and live IDE resources with guarded operations.",
183
- },
184
- annotations: {
185
- readOnlyHint: false,
186
- destructiveHint: true,
187
- idempotentHint: false,
188
- openWorldHint: false,
189
- },
190
- label: "Flush",
191
- description:
192
- "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.",
193
- promptSnippet: "Commit pending native editor changes and inspect their effects",
194
- parameters: Type.Object({}, { additionalProperties: false }),
195
- outputSchema: mutationOutputSchema,
196
- execute: async (id) => {
197
- const script = this.invocations.get(id);
198
- if (!script) throw new Error("Flush requires an active native Codemode script");
199
- const work = script.scheduler.run(undefined, async () => {
200
- await this.commit(script);
201
- const reports = script.reports.slice(script.reportCursor);
202
- script.reportCursor = script.reports.length;
203
- const files = mergedFiles(reports.flatMap((report) => report.data?.files ?? []));
204
- const errors = reports.flatMap((report) => report.errors);
205
- const operations = reports.flatMap((report) => report.data?.operations ?? []);
206
- const effect = receiptEffect(files);
207
- return withStructuredResult(
208
- {
209
- content: [
210
- {
211
- type: "text",
212
- text:
213
- errors.length === 0
214
- ? `Flushed ${operations.length} editor operations; ${effect}.`
215
- : `Editor flush failed; ${effect}.\n${errors.map((error) => error.message).join("\n")}`,
216
- },
217
- ],
218
- details: { results: [] },
219
- },
220
- mutationDataSchema,
221
- {
222
- status: receiptStatus(errors, operations),
223
- data: { operation: "flush", effect, files, operations },
224
- errors,
225
- },
226
- );
227
- });
228
- script.tail = work.then(
229
- () => undefined,
230
- () => undefined,
231
- );
232
- return work;
233
- },
234
- });
235
192
  pi.on("tool_call", async (event, context) => {
236
193
  if (event.toolName === "codemode" && event.parentToolCallId === undefined) {
237
194
  this.scripts.set(event.toolCallId, {
@@ -239,7 +196,6 @@ class NativeTextEditBatchCoordinator {
239
196
  context,
240
197
  summaries: [],
241
198
  reports: [],
242
- reportCursor: 0,
243
199
  presentations: [],
244
200
  results: [],
245
201
  errors: [],
@@ -249,6 +205,7 @@ class NativeTextEditBatchCoordinator {
249
205
  tail: Promise.resolve(),
250
206
  scheduler: new ResourceScheduler(),
251
207
  callOrder: new Map(),
208
+ unfinishedCalls: new Map(),
252
209
  pending: pendingBatch(),
253
210
  closed: false,
254
211
  });
@@ -257,15 +214,18 @@ class NativeTextEditBatchCoordinator {
257
214
  const script =
258
215
  event.parentToolCallId === undefined ? undefined : this.scripts.get(event.parentToolCallId);
259
216
  if (!script) return;
260
- if (event.toolName === "flush") {
261
- this.invocations.set(event.toolCallId, script);
262
- return;
263
- }
264
217
  const registration = this.core
265
218
  .getMutationTools()
266
219
  .find((tool) => tool.name === event.toolName);
267
- if (registration) this.scopedInvocations.set(event.toolCallId, script);
268
220
  const input: Record<string, unknown> = event.input;
221
+ if (registration) {
222
+ this.scopedInvocations.set(event.toolCallId, script);
223
+ const source = input[registration.source.field];
224
+ script.unfinishedCalls.set(
225
+ event.toolCallId,
226
+ typeof source === "string" && !isResultInput(source) ? source : "",
227
+ );
228
+ }
269
229
  let ownsSource = false;
270
230
  if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
271
231
  const resolverContext = {
@@ -276,7 +236,9 @@ class NativeTextEditBatchCoordinator {
276
236
  const value = input[descriptor.field];
277
237
  if (typeof value === "string" && value.length > 0) {
278
238
  if (
279
- ["replace", "write", "copy", "move", "delete", "undo"].includes(registration.name) &&
239
+ ["replace", "write", "copy", "move", "delete", "undo", "insert"].includes(
240
+ registration.name,
241
+ ) &&
280
242
  value.startsWith("RESULT#")
281
243
  ) {
282
244
  // The executor validates result handles and returns a structured rejection.
@@ -319,25 +281,51 @@ class NativeTextEditBatchCoordinator {
319
281
  return;
320
282
  });
321
283
  pi.on("tool_result", async (event) => {
284
+ this.scopedInvocations.get(event.toolCallId)?.unfinishedCalls.delete(event.toolCallId);
322
285
  this.invocations.delete(event.toolCallId);
323
286
  this.scopedInvocations.delete(event.toolCallId);
324
287
  const script = this.scripts.get(event.toolCallId);
325
288
  if (!script) return;
326
289
  script.closed = true;
290
+ const texts = event.content
291
+ .filter((block) => block.type === "text")
292
+ .map((block) => block.text);
293
+ let executionError = texts.findLast((text) => text.startsWith("Script error:\n")) ?? "";
294
+ const executionDetails = event.details;
295
+ if (
296
+ event.isError &&
297
+ executionDetails !== null &&
298
+ typeof executionDetails === "object" &&
299
+ "fullOutputPath" in executionDetails &&
300
+ typeof executionDetails.fullOutputPath === "string"
301
+ ) {
302
+ try {
303
+ const output = await readFile(executionDetails.fullOutputPath, "utf8");
304
+ // A timeout has one engine error line followed by the call summary, not a JavaScript stack.
305
+ const matches = [
306
+ ...output.matchAll(
307
+ /(?:^|\n)(Script error:\nScript (?:aborted|timed out):[^\n]*\n\n(?:Tool calls made before the failure[^\n]*|No tool calls were made\.))/gu,
308
+ ),
309
+ ];
310
+ const match = matches.at(-1);
311
+ executionError =
312
+ match !== undefined &&
313
+ !output.slice(match.index + match[0].length).includes("Script error:\n")
314
+ ? (match[1] ?? "")
315
+ : "";
316
+ } catch {
317
+ // Use the returned output when its complete artifact is unavailable.
318
+ }
319
+ }
327
320
  const interrupted =
328
321
  script.context.signal?.aborted ||
329
- (event.isError &&
330
- event.content.some(
331
- (block) =>
332
- block.type === "text" &&
333
- /^Script error:\nScript (?:aborted|timed out):/u.test(block.text),
334
- ));
322
+ (event.isError && /^Script error:\nScript (?:aborted|timed out):/u.test(executionError));
335
323
  if (interrupted) script.cancellation.abort();
336
324
  await script.tail;
337
325
  if (interrupted) {
338
326
  if (script.pending.entries.length > 0) {
339
327
  const error = resultError(
340
- "Pending editor batch cancelled; no pending edits were written.",
328
+ "The operation was interrupted before writing. No file was changed.",
341
329
  "CANCELLED",
342
330
  );
343
331
  const operations = script.pending.entries.map((entry) => ({
@@ -350,7 +338,7 @@ class NativeTextEditBatchCoordinator {
350
338
  status: "error",
351
339
  errors: [error],
352
340
  data: {
353
- operation: "flush",
341
+ operation: "batch",
354
342
  effect: "not-applied",
355
343
  operations,
356
344
  files: [...script.pending.snapshots.keys()].map((source) => ({
@@ -367,46 +355,85 @@ class NativeTextEditBatchCoordinator {
367
355
  script.pending = pendingBatch();
368
356
  }
369
357
  } else await this.commit(script);
358
+ if (interrupted) {
359
+ for (const [id, source] of script.unfinishedCalls) {
360
+ if (
361
+ script.presentations.some((presentation) => presentation.calls.includes(id)) ||
362
+ script.reports.some((report) =>
363
+ report.data?.operations.some((operation) => operation.id === id),
364
+ )
365
+ )
366
+ continue;
367
+ // Cancellation is not a result. Do not guess whether a resolver already wrote.
368
+ const message =
369
+ "The operation was interrupted. Its file effects are unknown.\nRead the affected files before retrying.";
370
+ const presentation = new MutationPresentation({
371
+ ok: false,
372
+ path: source,
373
+ fileChangedStatement: message,
374
+ errors: [{ path: source, code: "CANCELLED" }],
375
+ });
376
+ const result: AgentToolResult<FileMutationBatchResult> = {
377
+ content: [new FileMutationAgentResult(presentation).toTextContent()],
378
+ details: { results: [presentation], effect: "unknown" },
379
+ isError: true,
380
+ };
381
+ script.results.push(presentation);
382
+ script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
383
+ }
384
+ }
370
385
  try {
371
386
  await this.core.enqueueFileOperation(
372
387
  () =>
373
- script.postEdits.finish((outcome) => {
374
- const index = script.results.findLastIndex(
375
- (item) => item.data.path === outcome.after.source,
376
- );
377
- if (index < 0) return;
378
- const previous = requiredValue(script.results[index]).data;
379
- const updated = new MutationPresentation({
380
- ...previous,
381
- afterContent: outcome.after.content,
382
- afterDocument: outcome.after,
383
- formatting: outcome.postEditContributions
384
- .map((item) => item.data)
385
- .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
386
- diffStatuses: outcome.postEditContributions
387
- .map((item) => item.data)
388
- .filter(isDiffStatusContribution)
389
- .flatMap((item) => item.diffStatuses),
390
- });
391
- const previousResult = requiredValue(script.results[index]);
392
- script.results[index] = updated;
393
- for (const [slot, presentation] of script.presentations.entries()) {
394
- const results = presentation.result.details.results;
395
- if (!results?.includes(previousResult)) continue;
396
- script.presentations[slot] = {
397
- ...presentation,
398
- result: {
399
- ...presentation.result,
400
- details: {
401
- ...presentation.result.details,
402
- results: results.map((result) =>
403
- result === previousResult ? updated : result,
404
- ),
405
- },
406
- },
407
- };
408
- }
409
- }),
388
+ script.postEdits.finish(
389
+ (outcome) => {
390
+ const index = script.results.findLastIndex(
391
+ (item) => item.data.path === outcome.after.source,
392
+ );
393
+ if (index < 0) return;
394
+ const previous = requiredValue(script.results[index]).data;
395
+ const updated = new MutationPresentation({
396
+ ...previous,
397
+ afterContent: outcome.after.content,
398
+ afterDocument: outcome.after,
399
+ formatting: outcome.postEditContributions
400
+ .map((item) => item.data)
401
+ .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
402
+ diffStatuses: outcome.postEditContributions
403
+ .map((item) => item.data)
404
+ .filter(isDiffStatusContribution)
405
+ .flatMap((item) => item.diffStatuses),
406
+ });
407
+ replaceScriptResult(script, requiredValue(script.results[index]), updated);
408
+ },
409
+ (source, error) => {
410
+ const reason = error instanceof Error ? error.message : String(error);
411
+ const failure = { code: "POST_EDIT_FAILED", message: reason, source };
412
+ for (const previous of script.results.filter(
413
+ (result) => result.data.path === source,
414
+ )) {
415
+ replaceScriptResult(
416
+ script,
417
+ previous,
418
+ new MutationPresentation({
419
+ ok: false,
420
+ path: source,
421
+ errors: [{ path: source, code: failure.code, reason }],
422
+ fileChangedStatement:
423
+ "The edit was saved, but final processing failed. Final text is not confirmed. Run Read/Search before editing this resource again.",
424
+ }),
425
+ );
426
+ }
427
+ for (const [index, report] of script.reports.entries()) {
428
+ if (!report.data?.files.some((file) => file.source === source)) continue;
429
+ script.reports[index] = {
430
+ ...report,
431
+ status: report.status === "success" ? "partial" : report.status,
432
+ errors: [...report.errors, failure],
433
+ };
434
+ }
435
+ },
436
+ ),
410
437
  undefined,
411
438
  { cwd: script.context.cwd, sources: script.postEdits.sources() },
412
439
  );
@@ -471,16 +498,23 @@ class NativeTextEditBatchCoordinator {
471
498
  pi.on("session_shutdown", clear);
472
499
  }
473
500
 
474
- /** Keep every mutation in the script's shared post-edit scope, including non-batched calls. */
475
- runPostEdits<T>(id: string, work: () => T): T {
501
+ /** Share post-edit state while allowing Write to finish its own processing immediately. */
502
+ runPostEdits<T>(id: string, work: () => T, immediate: boolean): T {
476
503
  const script = this.scopedInvocations.get(id);
477
- return script ? script.postEdits.run(work) : work();
504
+ return script ? script.postEdits.run(work, immediate) : work();
478
505
  }
479
506
 
480
- /** Include non-batched mutations in the script's final post-edit presentation. */
507
+ /** Include applied, non-batched mutations in the script's final post-edit presentation. */
481
508
  recordMutation(id: string, result: AgentToolResult<FileMutationBatchResult>): void {
482
509
  const script = this.scopedInvocations.get(id);
483
- if (!script || !result.details.results?.some((item) => item.data.ok === true)) return;
510
+ if (script && !script.closed) script.unfinishedCalls.delete(id);
511
+ if (
512
+ !script ||
513
+ script.closed ||
514
+ result.details.effect === "not-applied" ||
515
+ !result.details.results?.some((item) => item.data.ok === true)
516
+ )
517
+ return;
484
518
  script.results.push(...result.details.results);
485
519
  script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
486
520
  }
@@ -608,6 +642,13 @@ class NativeTextEditBatchCoordinator {
608
642
  ? this.resultTargets.reserve(context.cwd)
609
643
  : undefined;
610
644
  if (target) script.targets.set(id, target);
645
+ const unchangedCopy =
646
+ registration.name === "copy" &&
647
+ planning.plan.mutations.every(
648
+ ({ mutation }) =>
649
+ mutation.edits.size > 0 &&
650
+ unchangedCopySources(mutation, batch.snapshots).size === mutation.edits.size,
651
+ );
611
652
  const details = {
612
653
  results: [],
613
654
  source: entry.path,
@@ -619,7 +660,12 @@ class NativeTextEditBatchCoordinator {
619
660
  content: [
620
661
  {
621
662
  type: "text",
622
- text: `Accepted ${registration.name} for ${entry.path}; not yet applied. The editor batch commits before another tool or when this script ends.`,
663
+ text:
664
+ registration.name === "copy"
665
+ ? unchangedCopy
666
+ ? "No changes: destination already has this text."
667
+ : `Copy destination: ${typeof normalized.target === "string" ? normalized.target : entry.path}`
668
+ : `Accepted ${registration.name} for ${entry.path}. Check the final Codemode result for applied changes.`,
623
669
  },
624
670
  ],
625
671
  details,
@@ -638,6 +684,7 @@ class NativeTextEditBatchCoordinator {
638
684
  mapped = committedMutationTargets(
639
685
  batch.plan.mutations.map(({ callId, mutation }) => ({ callId, edits: mutation.edits })),
640
686
  completions,
687
+ batch.snapshots,
641
688
  );
642
689
  } catch (error) {
643
690
  for (const entry of batch.entries) {
@@ -681,6 +728,17 @@ class NativeTextEditBatchCoordinator {
681
728
  script.context.signal === undefined
682
729
  ? script.cancellation.signal
683
730
  : AbortSignal.any([script.context.signal, script.cancellation.signal]);
731
+ const unchangedCopies = new Map(
732
+ batch.plan.mutations
733
+ .filter(({ mutation }) => mutation.operation === "copy")
734
+ .map(({ callId, mutation }) => {
735
+ const sources = unchangedCopySources(mutation, batch.snapshots);
736
+ return [
737
+ callId,
738
+ { sources, all: sources.size > 0 && sources.size === mutation.edits.size },
739
+ ] as const;
740
+ }),
741
+ );
684
742
  let observedSources: string[] = [];
685
743
  const record = (outcome: StructuredResult<MutationData>): boolean => {
686
744
  const calls = journal.snapshot();
@@ -688,11 +746,13 @@ class NativeTextEditBatchCoordinator {
688
746
  id: call.callId,
689
747
  operation: requiredValue(batch.entries.find((entry) => entry.callId === call.callId)).op,
690
748
  effect:
691
- call.state === "completed" || call.state === "failed-applied"
692
- ? ("applied" as const)
693
- : call.state === "failed-unknown" || call.state === "running"
694
- ? ("unknown" as const)
695
- : ("not-applied" as const),
749
+ call.state === "completed" && unchangedCopies.get(call.callId)?.all
750
+ ? ("not-applied" as const)
751
+ : call.state === "completed" || call.state === "failed-applied"
752
+ ? ("applied" as const)
753
+ : call.state === "failed-unknown" || call.state === "running"
754
+ ? ("unknown" as const)
755
+ : ("not-applied" as const),
696
756
  errors: call.failure === undefined ? [] : [resultError(call.failure.error)],
697
757
  }));
698
758
  const files = mergedFiles([
@@ -705,7 +765,10 @@ class NativeTextEditBatchCoordinator {
705
765
  return [...mutationSources(registration, entry).values()].map((source) => ({
706
766
  source,
707
767
  effect:
708
- mutation?.edits.has(source) === false ? ("not-applied" as const) : operation.effect,
768
+ mutation?.edits.has(source) === false ||
769
+ unchangedCopies.get(operation.id)?.sources.has(source) === true
770
+ ? ("not-applied" as const)
771
+ : operation.effect,
709
772
  }));
710
773
  }),
711
774
  ...observedSources.map((source) => ({ source, effect: "applied" as const })),
@@ -727,7 +790,7 @@ class NativeTextEditBatchCoordinator {
727
790
  errors,
728
791
  data: {
729
792
  ...outcome.data,
730
- operation: "flush",
793
+ operation: "batch",
731
794
  effect: receiptEffect(files),
732
795
  files,
733
796
  operations,
@@ -768,16 +831,36 @@ class NativeTextEditBatchCoordinator {
768
831
  );
769
832
  observedSources = captured.completions.map((completion) => completion.resourceSource);
770
833
  if (captured.kind === "failed") throw captured.error;
771
- script.results.push(...(captured.value.details.results ?? []));
834
+ const value =
835
+ captured.completions.length === 0 &&
836
+ journal
837
+ .snapshot()
838
+ .every((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
839
+ ? {
840
+ ...captured.value,
841
+ content: [
842
+ { type: "text" as const, text: "No changes: destination already has this text." },
843
+ ],
844
+ details: { ...captured.value.details, effect: "not-applied" as const },
845
+ }
846
+ : captured.value;
847
+ script.results.push(...(value.details.results ?? []));
772
848
  await this.settleTargets(script, batch, journal, captured.completions, signal);
773
849
  const presentation = {
774
850
  parentToolCallId: script.id,
775
851
  calls: batch.entries.map((entry) => entry.callId),
776
- result: captured.value,
852
+ unchangedCopyCalls: journal
853
+ .snapshot()
854
+ .filter((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
855
+ .map((call) => call.callId),
856
+ ...(value.details.copyResults === undefined
857
+ ? {}
858
+ : { copyResults: value.details.copyResults }),
859
+ result: value,
777
860
  } satisfies NativeEditBatchEvent;
778
861
  script.presentations.push(presentation);
779
862
  this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, presentation);
780
- return record(mutationOutcome(captured.value, "flush", captured.completions));
863
+ return record(mutationOutcome(value, "batch", captured.completions));
781
864
  } catch (error) {
782
865
  journal.markRunningUnknown(error);
783
866
  await this.settleTargets(script, batch, journal, [], signal);
@@ -788,10 +871,15 @@ class NativeTextEditBatchCoordinator {
788
871
 
789
872
  const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
790
873
 
791
- /** Run immediate mutation paths under the same deferred post-edit boundary as native batches. */
792
- export function runNativePostEditScope<T>(core: TextEditorCore, id: string, work: () => T): T {
874
+ /** Share deferred post-edit state, or finish this operation's processing before return. */
875
+ export function runNativePostEditScope<T>(
876
+ core: TextEditorCore,
877
+ id: string,
878
+ work: () => T,
879
+ immediate = false,
880
+ ): T {
793
881
  const coordinator = coordinators.get(core);
794
- return coordinator ? coordinator.runPostEdits(id, work) : work();
882
+ return coordinator ? coordinator.runPostEdits(id, work, immediate) : work();
795
883
  }
796
884
 
797
885
  /** Retain immediate child results so final formatting is visible on the parent script. */