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
@@ -9,12 +9,25 @@ export function summarizeStatuses(
9
9
  ) {
10
10
  const formatted = new Set<string>();
11
11
  const formatters = new Set<string>();
12
+ const alreadyFormatted = new Set<string>();
13
+ const unchangedFormatters = new Set<string>();
12
14
  const remaining = new Map<string, { status: MutationDiffStatus; paths: Set<string> }>();
13
15
  for (const resource of resources)
14
16
  for (const status of resource.diffStatuses ?? []) {
15
- if (status.formatter !== undefined && status.tone === "success") {
16
- formatted.add(resource.path);
17
- formatters.add(status.formatter);
17
+ if (
18
+ status.formatter !== undefined &&
19
+ status.tone === "success" &&
20
+ (status.formattingStatus === undefined ||
21
+ status.formattingStatus === "changed" ||
22
+ status.formattingStatus === "unchanged")
23
+ ) {
24
+ if (status.formattingStatus === "unchanged") {
25
+ alreadyFormatted.add(resource.path);
26
+ unchangedFormatters.add(status.formatter);
27
+ } else {
28
+ formatted.add(resource.path);
29
+ formatters.add(status.formatter);
30
+ }
18
31
  continue;
19
32
  }
20
33
  const key = JSON.stringify([status.text, status.tone]);
@@ -28,6 +41,8 @@ export function summarizeStatuses(
28
41
  return {
29
42
  formatted: [...formatted],
30
43
  formatters: [...formatters],
44
+ alreadyFormatted: [...alreadyFormatted],
45
+ unchangedFormatters: [...unchangedFormatters],
31
46
  statuses: [...remaining.values()].map(({ status, paths }) => ({ status, paths: [...paths] })),
32
47
  };
33
48
  }
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-stale-anchor",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-invariant": "0.7.0",
7
- "pi-agent-read": "0.7.0",
8
- "pi-agent-text-editor": "0.7.0"
6
+ "pi-agent-invariant": "0.7.2",
7
+ "pi-agent-read": "0.7.2",
8
+ "pi-agent-text-editor": "0.7.2"
9
9
  },
10
10
  "pi": {
11
11
  "extensions": [
@@ -3,8 +3,8 @@ import type { TextDocument } from "pi-agent-text";
3
3
  export type TextEditIntent = "edit" | "restore" | "mixed";
4
4
 
5
5
  export interface TextEditCompletion {
6
- /** Deferred writes remain observable; final updates reconcile formatting without another edit. */
7
- readonly postProcessing?: "deferred" | "final" | "complete";
6
+ /** Saved bytes remain observable even when post-edit work is deferred or interrupted. */
7
+ readonly postProcessing?: "deferred" | "final" | "complete" | "interrupted";
8
8
  readonly source: string;
9
9
  readonly resourceSource: string;
10
10
  readonly resolvedBy: string;
@@ -27,7 +27,8 @@ export {
27
27
  export { type ChangedRange, computeChangedRanges } from "#src/core/mutation-result/diff.js";
28
28
  export {
29
29
  mutationDataSchema,
30
- mutationOutputSchema,
30
+ mutationResultSchema,
31
+ type BatchMutationData,
31
32
  structuredMutation,
32
33
  type MutationData,
33
34
  } from "#src/core/structured-result.js";
@@ -5,6 +5,10 @@ import type { FileMutationBatchResult } from "./mutation-result.js";
5
5
  export interface NativeEditBatchEvent {
6
6
  readonly parentToolCallId: string;
7
7
  readonly calls: readonly string[];
8
+ /** Successful Copy calls that retained identical destination text without a write. */
9
+ readonly unchangedCopyCalls?: readonly string[];
10
+ /** Per-call Copy receipts keep destination authority and rollback evidence. */
11
+ readonly copyResults?: ReadonlyMap<string, AgentToolResult<FileMutationBatchResult>>;
8
12
  readonly result: AgentToolResult<FileMutationBatchResult>;
9
13
  }
10
14
 
@@ -14,7 +14,7 @@ export function formatStaleAnchorMessage(
14
14
  ): string {
15
15
  const context = details.context === undefined ? "" : `\n\n${details.context}`;
16
16
  return (
17
- `[SYSTEM] ${details.toolName} blocked: ${details.field} anchor "${details.anchor}" is stale. ` +
17
+ `[SYSTEM] ${details.toolName} blocked: ${details.field === "anchor" ? "anchor" : `${details.field} anchor`} "${details.anchor}" is stale. ` +
18
18
  `If the required line is represented by one of the context lines below, use that anchor. Otherwise, reread only the relevant section of "${details.path}" and regenerate the anchor. (${reason})${context}`
19
19
  );
20
20
  }
@@ -33,10 +33,42 @@ export const diffDataSchema = Type.Object(
33
33
  );
34
34
  export const diffOutputSchema = structuredResultSchema(diffDataSchema);
35
35
 
36
- const source = Type.Union([Type.String({ minLength: 1 }), readParameters]);
36
+ const comparisonReadParameters = {
37
+ ...readParameters,
38
+ properties: {
39
+ ...readParameters.properties,
40
+ path: {
41
+ ...readParameters.properties.path,
42
+ description:
43
+ "Text-readable source accepted by Read, such as a file path, URL, temp: reference, SEARCH# or RESULT# reference, or registered resource. Supply a path.",
44
+ },
45
+ offset: {
46
+ ...readParameters.properties.offset,
47
+ description:
48
+ "First text line to compare, numbered from 1. Omit or use 0 to start at line 1; negative offsets count from the end. For path#anchor, SEARCH# or RESULT# selections, count from the containing line: omitted, 0 or 1 starts there, 2 starts one line later, -1 one line earlier.",
49
+ },
50
+ limit: {
51
+ ...readParameters.properties.limit,
52
+ description:
53
+ "Maximum text lines to compare from the selected starting position. Omit to compare all resolved text in the selected range. Read's display limits do not shorten the comparison inputs.",
54
+ },
55
+ },
56
+ };
57
+ const source = Type.Union([Type.String({ minLength: 1 }), comparisonReadParameters]);
37
58
  /** Each side accepts a source string or the same request object as read. */
38
59
  export const diffParameters = Type.Object(
39
- { before: source, after: source },
60
+ {
61
+ before: {
62
+ ...source,
63
+ description:
64
+ "Source for the removed (-) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
65
+ },
66
+ after: {
67
+ ...source,
68
+ description:
69
+ "Source for the added (+) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
70
+ },
71
+ },
40
72
  { additionalProperties: false },
41
73
  );
42
74
  export type DiffRequest = Static<typeof diffParameters>;
@@ -107,13 +139,21 @@ export function comparisonText(data: ReadScriptData, requested: string): Compari
107
139
  };
108
140
  }
109
141
  if (data.kind === "bytes")
110
- throw Object.assign(new Error(`Byte sources are not text: ${data.source}`), {
111
- code: "UNSUPPORTED_CONTENT",
112
- });
142
+ throw Object.assign(
143
+ new Error(
144
+ `Byte sources are not text: ${data.source}\nIf this is a text file, use its path without raw:.`,
145
+ ),
146
+ {
147
+ code: "UNSUPPORTED_CONTENT",
148
+ },
149
+ );
113
150
  if (data.blocks.length === 0 || data.blocks.some((block) => block.type !== "text"))
114
- throw Object.assign(new Error(`Source is not text: ${data.source}`), {
115
- code: "UNSUPPORTED_CONTENT",
116
- });
151
+ throw Object.assign(
152
+ new Error(`Source is not text: ${data.source}\nUse a source that Read resolves to text.`),
153
+ {
154
+ code: "UNSUPPORTED_CONTENT",
155
+ },
156
+ );
117
157
  return {
118
158
  source: data.source,
119
159
  sources: [data.source],
@@ -166,8 +206,7 @@ export function registerDiff(
166
206
  parameters: diffParameters,
167
207
  outputSchema: diffOutputSchema,
168
208
  promptSnippet: "Compare two text-readable sources",
169
- description:
170
- "Use diff to compare two sources. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference.",
209
+ description: "Use diff to compare two text-readable sources without changing them.",
171
210
  renderCall(_args, theme) {
172
211
  return new Text(theme.fg("toolTitle", theme.bold("Diff")), 0, 0);
173
212
  },
@@ -195,7 +234,10 @@ export function registerDiff(
195
234
  const full = diffText(comparison);
196
235
  const bounded = truncateHead(full);
197
236
  const temporarySource = bounded.truncated ? await read.saveTemporary(full) : undefined;
198
- const footer = temporarySource === undefined ? "" : `\nFull diff: ${temporarySource}`;
237
+ const footer =
238
+ temporarySource === undefined
239
+ ? ""
240
+ : `\nDiff output is truncated; the comparison used the complete resolved inputs.\nUse read with path "${temporarySource}" for the full diff.`;
199
241
  return withStructuredResult(
200
242
  {
201
243
  content: [
@@ -205,7 +247,7 @@ export function registerDiff(
205
247
  temporarySource === undefined
206
248
  ? full
207
249
  : truncateHead(full, {
208
- maxLines: DEFAULT_MAX_LINES - 2,
250
+ maxLines: DEFAULT_MAX_LINES - footer.split("\n").length,
209
251
  maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
210
252
  }).content + footer,
211
253
  },
@@ -4,5 +4,5 @@ export const EDITING_GUIDELINES = [
4
4
  "Use an available anchor when it selects exactly the intended text; otherwise use minimal unique exact text. Keep the edit limited to the intended content.",
5
5
  "When search broadens to separate words, treat its results as location hints. Refine the query before using those matches for replacement.",
6
6
  "Use standalone mutation tools in one assistant-response batch when each change is known in advance and does not depend on another change. This is the default for several independent edits in one file or across files. Every call is evaluated against the original file snapshots. Combine overlapping changes into one mutation. Use native Codemode for computed or dependent tool composition; it keeps the same tool contracts and does not add grouped rollback. Check each batch result and retry only unapplied changes.",
7
- "Inside native Codemode, submit independent local text-edit calls on disjoint resource sets concurrently; await calls on overlapping sets in order. Check each result's status. Await tools.flush({}) when later script work needs a committed receipt. Check the parent result for automatic batch commits before retrying an accepted call. Read docs:editing for batch boundaries and dependent work.",
7
+ "Inside Codemode, run independent edits on different resources concurrently; run edits on the same resource in order. Check the final Codemode result and retry only unapplied changes. Read docs:editing when you need a write report inside the script.",
8
8
  ] as const;
@@ -63,6 +63,9 @@ export default async function registerTextEditorCore(
63
63
  );
64
64
  });
65
65
  setTextEditBatchRenderArgumentSink(core, interceptionRendering.resolveArguments);
66
+ core.onDidEdit((completion) => {
67
+ resultTargets.refresh(completion.resourceSource, completion.cwd);
68
+ });
66
69
  await core.registerPlugin({
67
70
  protocol: TEXT_EDITOR_PROTOCOL,
68
71
  apiVersion: TEXT_EDITOR_API_VERSION,
@@ -90,9 +93,13 @@ export default async function registerTextEditorCore(
90
93
  api.addTargetResolver({ resolver: core.textTargetResolver() });
91
94
  api.addFragmentResolver(createReadFragmentResolver(core));
92
95
 
93
- api.describe(
94
- "path#anchor — source around a returned line or scope anchor, e.g. notes.txt#12#A4F0. SEARCH# references go directly in path, without a file prefix. offset/limit select context relative to each location; output keeps original line numbers.",
95
- );
96
+ api.describe({
97
+ path: "path#anchor — source around a returned line or scope anchor, e.g. notes.txt#12#A4F0. SEARCH# and RESULT# references go directly in path, without a file prefix. Returned Read/Search/Select/mutation targets select their verified source ranges.",
98
+ offset:
99
+ "For path#anchor, SEARCH# or RESULT# selections, count from each containing line: omitted, 0 or 1 starts there; 2 starts one line later; -1 starts one line earlier. Output keeps original line numbers.",
100
+ limit:
101
+ "For source selections, limit caps each selected context window separately. Without limit, each selection supplies its natural line count, with at least one line.",
102
+ });
96
103
  },
97
104
  });
98
105
  setTextAnchorRecoveryReader(core, (request, context) => {
@@ -19,11 +19,6 @@ export const transferFileParameters = Type.Object(
19
19
  {
20
20
  path: filePath,
21
21
  target: filePath,
22
- overwrite: Type.Optional(
23
- Type.Boolean({
24
- description: "Allow replacing an existing regular target file. Defaults to false.",
25
- }),
26
- ),
27
22
  },
28
23
  { additionalProperties: false },
29
24
  );
@@ -76,7 +71,7 @@ export async function executeFileOperation(
76
71
  throw Object.assign(new Error("Invalid file operation arguments"), {
77
72
  code: "INVALID_ARGUMENTS",
78
73
  });
79
- const args = input as { path: string; target?: string; overwrite?: boolean };
74
+ const args = input as { path: string; target?: string };
80
75
  source = path.resolve(cwd, args.path);
81
76
  target = args.target === undefined ? undefined : path.resolve(cwd, args.target);
82
77
  signal?.throwIfAborted();
@@ -95,19 +90,14 @@ export async function executeFileOperation(
95
90
  throw Object.assign(new Error("Source and target are the same file"), {
96
91
  code: "SAME_FILE",
97
92
  });
98
- if (args.overwrite !== true)
99
- throw Object.assign(new Error("Target exists; use overwrite: true to replace it"), {
100
- code: "EEXIST",
101
- });
102
93
  }
103
94
  }
104
95
  signal?.throwIfAborted();
105
96
  started = true;
106
97
  if (operation === "delete") await unlink(source);
107
98
  else if (target !== undefined) {
108
- if (operation === "copy")
109
- await fs.copy(source, target, { overwrite: args.overwrite === true, errorOnExist: true });
110
- else await fs.move(source, target, { overwrite: args.overwrite === true });
99
+ if (operation === "copy") await fs.copy(source, target, { overwrite: true });
100
+ else await fs.move(source, target, { overwrite: true });
111
101
  }
112
102
  return {
113
103
  kind: "file-operation",
@@ -287,6 +287,27 @@ export class FileMutationAgentResult {
287
287
 
288
288
  // ── Success formatting ────────────────────────────────────────────────
289
289
 
290
+ private formatFormatting(formatting: FileMutationResult["data"]["formatting"]): string {
291
+ const by = formatting?.formatter === undefined ? "" : ` (${formatting.formatter})`;
292
+ switch (formatting?.status) {
293
+ case "changed": {
294
+ return `Formatted${by}.`;
295
+ }
296
+ case "unchanged": {
297
+ return `Already formatted${by}.`;
298
+ }
299
+ case "unavailable": {
300
+ return "No formatter is available for this file.";
301
+ }
302
+ case "failed": {
303
+ return `Formatting failed${by}. Read the saved file before retrying.`;
304
+ }
305
+ default: {
306
+ return `Formatting: ${formatting?.status ?? "not-reported"}${by}.`;
307
+ }
308
+ }
309
+ }
310
+
290
311
  private formatSuccess(fmr: FileMutationResult): string {
291
312
  const operations = fmr.data.operations ?? [];
292
313
  const verbs: Record<string, string> = {
@@ -295,7 +316,6 @@ export class FileMutationAgentResult {
295
316
  delete: "Deleted selected text",
296
317
  copy: "Copied selected text",
297
318
  move: "Moved selected text",
298
- write: "Wrote file content",
299
319
  undo: "Restored file content",
300
320
  stage: "Staged selected changes",
301
321
  unstage: "Unstaged selected changes",
@@ -304,15 +324,24 @@ export class FileMutationAgentResult {
304
324
  operations.length === 0
305
325
  ? "Changes applied."
306
326
  : operations
307
- .map(
308
- ({ operation, changes }) =>
309
- `${verbs[operation] ?? `Applied ${operation}`}: ${changes} text change(s) in this file.`,
327
+ .map(({ operation, changes }) =>
328
+ operation === "write"
329
+ ? "Saved file."
330
+ : `${verbs[operation] ?? `Applied ${operation}`}: ${changes} text change(s) in this file.`,
310
331
  )
311
332
  .join("\n"),
312
- `Formatting: ${fmr.data.formatting?.status ?? "not-reported"}${fmr.data.formatting?.formatter === undefined ? "" : ` (${fmr.data.formatting.formatter})`}.`,
333
+ this.formatFormatting(fmr.data.formatting),
313
334
  ];
314
335
 
315
- for (const status of fmr.data.diffStatuses ?? []) blocks.push(status.text);
336
+ for (const status of fmr.data.diffStatuses ?? []) {
337
+ if (
338
+ status.formattingStatus !== undefined &&
339
+ status.formattingStatus === fmr.data.formatting?.status &&
340
+ status.formatter === fmr.data.formatting.formatter
341
+ )
342
+ continue;
343
+ blocks.push(status.text);
344
+ }
316
345
  for (const diff of fmr.diffs) {
317
346
  const path = /^--- (.+)$/m.exec(diff)?.[1] ?? fmr.path ?? "<unknown file>";
318
347
  blocks.push(renderFinalStateFragment(fmr, path).join("\n"));
@@ -29,6 +29,8 @@ export interface MutationFormatting {
29
29
  export interface MutationDiffStatus {
30
30
  /** Formatter identity allows multi-file summaries without parsing display text. */
31
31
  readonly formatter?: string;
32
+ /** Observed formatter state for this label, kept distinct from file edit counts. */
33
+ readonly formattingStatus?: MutationFormatting["status"];
32
34
  readonly text: string;
33
35
  readonly tone?: "muted" | "success" | "warning" | "error";
34
36
  }
@@ -236,6 +238,8 @@ export interface FileMutationData {
236
238
 
237
239
  staleDiagnostic?: StaleAnchorDiagnostic | undefined;
238
240
  fileChangedStatement?: string | undefined;
241
+ /** Failed rollback resources; an empty list means all attempted writes were restored. */
242
+ rollback?: { readonly failedSources: readonly string[] } | undefined;
239
243
 
240
244
  // ── Transient engine fields ──
241
245
  snapshot?: MutationSnapshot | undefined;
@@ -325,7 +329,21 @@ export class FileMutationResult {
325
329
  readonly data: FileMutationData;
326
330
 
327
331
  public constructor(data?: FileMutationData) {
328
- this.data = data ?? {};
332
+ const formatting = data?.formatting;
333
+ this.data =
334
+ formatting === undefined || data?.diffStatuses === undefined
335
+ ? (data ?? {})
336
+ : {
337
+ ...data,
338
+ diffStatuses: data.diffStatuses.map((status) =>
339
+ status.formattingStatus !== undefined ||
340
+ formatting.formatter === undefined ||
341
+ status.formatter !== formatting.formatter ||
342
+ (status.tone !== "success" && status.tone !== "error")
343
+ ? status
344
+ : { ...status, formattingStatus: formatting.status },
345
+ ),
346
+ };
329
347
  }
330
348
 
331
349
  // ── Getters ──
@@ -1,10 +1,12 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
1
3
  import type { ResultRange, ResultSourceTarget } from "pi-agent-resource";
2
4
  import type { ResultTargetStore } from "pi-agent-resource";
3
5
  import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
4
6
  import type { FileMutationBatchResult } from "#src/api/mutation-result.js";
5
7
  import { createTextDocument } from "pi-agent-text";
6
8
  import type { TextEditCompletion } from "#src/api/edit-completion.js";
7
- import type { TextMutationEdit } from "#src/api/mutation-tool.js";
9
+ import type { TextMutation, TextMutationEdit } from "#src/api/mutation-tool.js";
8
10
  import { applyTextChanges } from "./text-change-engine.js";
9
11
  import { attachFileMutationTargets } from "./file-result-targets.js";
10
12
 
@@ -14,10 +16,36 @@ export interface OwnedMutationChanges {
14
16
  readonly edits: ReadonlyMap<string, TextMutationEdit>;
15
17
  }
16
18
 
17
- /** Map each call to its actual inserted text, including shifts from all batch peers. */
19
+ /** Find Copy destinations with identical text and no secondary resource action. */
20
+ export function unchangedCopySources(
21
+ mutation: TextMutation,
22
+ snapshots: ReadonlyMap<string, string>,
23
+ ): ReadonlySet<string> {
24
+ if (mutation.afterWrite !== undefined || mutation.semanticAction !== undefined) return new Set();
25
+ return new Set(
26
+ [...mutation.edits]
27
+ .filter(([source, edit]) => {
28
+ const before = snapshots.get(source);
29
+ return (
30
+ before !== undefined &&
31
+ edit.changes.length > 0 &&
32
+ edit.changes.every(
33
+ (change) =>
34
+ change.allowUnchanged && before.slice(change.from, change.to) === change.insert,
35
+ )
36
+ );
37
+ })
38
+ .map(([source]) => source),
39
+ );
40
+ }
41
+ /** Map final resource snapshots and unchanged Copy ranges; verify before publishing. */
18
42
  export function committedMutationTargets(
19
43
  mutations: readonly OwnedMutationChanges[],
20
- completions: readonly TextEditCompletion[],
44
+ completions: readonly Pick<
45
+ TextEditCompletion,
46
+ "source" | "resourceSource" | "resolvedBy" | "before" | "after" | "existed"
47
+ >[],
48
+ unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
21
49
  ): ReadonlyMap<string, readonly ResultSourceTarget[]> {
22
50
  const targets = new Map<string, ResultSourceTarget[]>();
23
51
  const sources = new Set(mutations.flatMap((mutation) => [...mutation.edits.keys()]));
@@ -25,7 +53,7 @@ export function committedMutationTargets(
25
53
  const completion = completions.findLast(
26
54
  (item) => item.source === source || item.resourceSource === source,
27
55
  );
28
- if (!completion || completion.resolvedBy !== "filesystem") continue;
56
+ if (completion && completion.resolvedBy !== "filesystem") continue;
29
57
  const changes = mutations
30
58
  .flatMap((mutation) =>
31
59
  (mutation.edits.get(source)?.changes ?? []).map((change, index) => ({
@@ -35,12 +63,22 @@ export function committedMutationTargets(
35
63
  })),
36
64
  )
37
65
  .sort((left, right) => left.from - right.from);
38
- const before = completion.before.content;
39
- const after = completion.after.content;
40
- if (applyTextChanges(before, changes, !completion.existed).content !== after)
66
+ const before = completion?.before.content ?? unchangedSnapshots.get(source);
67
+ if (before === undefined) continue;
68
+ if (
69
+ !completion &&
70
+ changes.some(
71
+ (change) =>
72
+ !change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
73
+ )
74
+ )
75
+ continue;
76
+ const after = completion?.after.content ?? before;
77
+ const resourceSource = completion?.resourceSource ?? source;
78
+ if (applyTextChanges(before, changes, completion?.existed === false).content !== after)
41
79
  throw new Error("Mutation targets cannot be mapped to the actual written snapshot.");
42
80
  const starts = [0];
43
- for (const line of createTextDocument(completion.resourceSource, after).lines)
81
+ for (const line of createTextDocument(resourceSource, after).lines)
44
82
  if (line.lineEnding.length > 0)
45
83
  starts.push((starts.at(-1) ?? 0) + line.content.length + line.lineEnding.length);
46
84
  const position = (offset: number): ResultRange["start"] => {
@@ -71,7 +109,7 @@ export function committedMutationTargets(
71
109
  for (const [callId, selected] of ranges) {
72
110
  const own = targets.get(callId) ?? [];
73
111
  own.push({
74
- source: completion.resourceSource,
112
+ source: resourceSource,
75
113
  expectedContent: after,
76
114
  ranges: selected,
77
115
  });
@@ -81,6 +119,81 @@ export function committedMutationTargets(
81
119
  return targets;
82
120
  }
83
121
 
122
+ /** Explain missing Copy authority without changing its write outcome. */
123
+ export function describeUnavailableCopyTarget(
124
+ result: AgentToolResult<FileMutationBatchResult>,
125
+ ): AgentToolResult<FileMutationBatchResult> {
126
+ const notice = "No verified text selection. Read the destination before further edits.";
127
+ if (
128
+ result.isError ||
129
+ typeof result.details.metadata?.targetUnavailable !== "string" ||
130
+ result.content.some((block) => block.type === "text" && block.text === notice)
131
+ )
132
+ return result;
133
+ return {
134
+ ...result,
135
+ content: [
136
+ ...result.content,
137
+ {
138
+ type: "text",
139
+ text: notice,
140
+ },
141
+ ],
142
+ };
143
+ }
144
+
145
+ /** Publish filesystem Write snapshots, never grant file authority to live resources. */
146
+ export async function attachWriteTarget(
147
+ result: AgentToolResult<FileMutationBatchResult>,
148
+ completions: readonly TextEditCompletion[],
149
+ store: ResultTargetStore,
150
+ cwd: string,
151
+ signal?: AbortSignal,
152
+ ): Promise<AgentToolResult<FileMutationBatchResult>> {
153
+ if (result.isError) return result;
154
+ const file = result.details.results?.[0]?.data;
155
+ if (file?.path === undefined || file.afterContent === undefined) return result;
156
+ if (completions.some((completion) => completion.resolvedBy !== "filesystem")) return result;
157
+ try {
158
+ const content = file.afterContent;
159
+ const lines = content.split(/\r\n|\r|\n/u);
160
+ const targets: ResultSourceTarget[] = [
161
+ {
162
+ source: path.resolve(
163
+ cwd,
164
+ file.path.startsWith("file://") ? fileURLToPath(file.path) : file.path,
165
+ ),
166
+ expectedContent: content,
167
+ ranges: [
168
+ {
169
+ start: { lineNumber: 1, column: 0 },
170
+ end: { lineNumber: lines.length, column: lines.at(-1)?.length ?? 0 },
171
+ },
172
+ ],
173
+ },
174
+ ];
175
+ await store.verify({ targets, complete: true }, signal);
176
+ return {
177
+ ...result,
178
+ details: {
179
+ ...result.details,
180
+ metadata: { ...result.details.metadata, resultTarget: store.register(targets, cwd) },
181
+ },
182
+ };
183
+ } catch (error) {
184
+ signal?.throwIfAborted();
185
+ return {
186
+ ...result,
187
+ details: {
188
+ ...result.details,
189
+ metadata: {
190
+ ...result.details.metadata,
191
+ targetUnavailable: error instanceof Error ? error.message : String(error),
192
+ },
193
+ },
194
+ };
195
+ }
196
+ }
84
197
  /** Publish immediate results only when their committed range mapping is verified. */
85
198
  export async function attachCommittedMutationTarget(
86
199
  result: AgentToolResult<FileMutationBatchResult>,
@@ -92,8 +205,14 @@ export async function attachCommittedMutationTarget(
92
205
  wholeFile = false,
93
206
  plannedEdits?: ReadonlyMap<string, TextMutationEdit>,
94
207
  destinationOnly = false,
208
+ unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
95
209
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
96
- if (result.isError || typeof result.details.metadata?.resultTarget === "string") return result;
210
+ if (
211
+ result.isError ||
212
+ typeof result.details.metadata?.resultTarget === "string" ||
213
+ completions.some((completion) => completion.resolvedBy !== "filesystem")
214
+ )
215
+ return result;
97
216
  result = await attachFileMutationTargets(result, store, cwd, signal);
98
217
  if (
99
218
  typeof result.details.metadata?.resultTarget === "string" ||
@@ -135,9 +254,11 @@ export async function attachCommittedMutationTarget(
135
254
  },
136
255
  );
137
256
  }
257
+ for (const [source, edit] of plannedEdits ?? [])
258
+ if (!edits.has(source) && unchangedSnapshots.has(source)) edits.set(source, edit);
138
259
  if (edits.size === 0 && result.details.metadata?.emptyTargets !== true) return result;
139
260
  try {
140
- const mapped = committedMutationTargets([{ callId, edits }], completions);
261
+ const mapped = committedMutationTargets([{ callId, edits }], completions, unchangedSnapshots);
141
262
  const targets = mapped.get(callId) ?? [];
142
263
  const outputCount = [...edits.values()].filter(
143
264
  (edit) => edit.resultChanges?.length !== 0,