pi-agent-ide 0.2.1 → 0.3.0

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 (490) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +12 -8
  3. package/dist/{chunk-XNXQYPVT.js → chunk-4LUW26BX.js} +1 -1
  4. package/dist/chunk-5MSNYFDE.js +1 -0
  5. package/dist/chunk-5VSE5X5R.js +2 -0
  6. package/dist/chunk-6EYWFBNG.js +0 -0
  7. package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
  8. package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
  9. package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
  10. package/dist/{chunk-SMSIT3CE.js → chunk-B5KB2I7J.js} +1 -1
  11. package/dist/chunk-BHSO2MDK.js +6 -0
  12. package/dist/chunk-BMOJTJJJ.js +3 -0
  13. package/dist/{chunk-EEH4WYI7.js → chunk-CEKXBS55.js} +1 -1
  14. package/dist/chunk-CW53ZTU3.js +2 -0
  15. package/dist/chunk-EWNWKDMP.js +4 -0
  16. package/dist/{chunk-VSP2QQPQ.js → chunk-GIRAEVUJ.js} +1 -1
  17. package/dist/{chunk-MTTKFJV6.js → chunk-GUTQ3PWL.js} +1 -1
  18. package/dist/chunk-HGPUI7F3.js +1 -0
  19. package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
  20. package/dist/chunk-ITSNK5YG.js +7 -0
  21. package/dist/chunk-KAB3AYA2.js +1 -0
  22. package/dist/{chunk-266RH77Z.js → chunk-LRYE2WCN.js} +1 -1
  23. package/dist/chunk-M5L42DWE.js +7 -0
  24. package/dist/chunk-M5MJP7Z2.js +1 -0
  25. package/dist/chunk-NMFQGKPE.js +2 -0
  26. package/dist/chunk-NTYXZ3EL.js +3 -0
  27. package/dist/{chunk-PETQCA7G.js → chunk-QDST6VIU.js} +1 -1
  28. package/dist/chunk-QIJMV2P2.js +2 -0
  29. package/dist/chunk-RHV5STR3.js +3 -0
  30. package/dist/chunk-ROXXK6TW.js +0 -0
  31. package/dist/chunk-S3ZPXWX7.js +2 -0
  32. package/dist/chunk-SSHZEWWV.js +1 -0
  33. package/dist/chunk-TPIHQYK2.js +14 -0
  34. package/dist/chunk-VZJIZXSH.js +14 -0
  35. package/dist/chunk-YHADTHQM.js +1 -0
  36. package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
  37. package/dist/{chunk-SJYDLHEF.js → chunk-ZM4L5AGN.js} +1 -1
  38. package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
  39. package/dist/entry-0.js +1 -1
  40. package/dist/entry-1.js +1 -1
  41. package/dist/entry-10.js +1 -1
  42. package/dist/entry-11.js +1 -1
  43. package/dist/entry-12.js +1 -1
  44. package/dist/entry-13.js +1 -1
  45. package/dist/entry-14.js +1 -1
  46. package/dist/entry-2.js +1 -1
  47. package/dist/entry-21.js +2 -1
  48. package/dist/entry-22.js +1 -1
  49. package/dist/entry-23.js +1 -1
  50. package/dist/entry-24.js +1 -1
  51. package/dist/entry-25.js +1 -1
  52. package/dist/entry-26.js +12 -1
  53. package/dist/entry-28.js +1 -1
  54. package/dist/entry-29.js +1 -1
  55. package/dist/entry-30.js +1 -1
  56. package/dist/entry-31.js +4 -1
  57. package/dist/entry-32.js +9 -1
  58. package/dist/entry-33.js +1 -1
  59. package/dist/entry-35.js +1 -1
  60. package/dist/entry-36.js +1 -1
  61. package/dist/entry-37.js +1 -1
  62. package/dist/entry-38.js +1 -1
  63. package/dist/entry-39.js +1 -1
  64. package/dist/entry-4.js +1 -1
  65. package/dist/entry-40.js +18 -1
  66. package/dist/entry-41.js +1 -1
  67. package/dist/entry-42.js +1 -1
  68. package/dist/entry-43.js +1 -1
  69. package/dist/entry-44.js +1 -1
  70. package/dist/entry-45.js +7 -1
  71. package/dist/entry-46.js +11 -1
  72. package/dist/entry-47.js +1 -1
  73. package/dist/entry-48.js +1 -1
  74. package/dist/entry-49.js +1 -1
  75. package/dist/entry-50.js +1 -1
  76. package/dist/entry-51.js +1 -1
  77. package/dist/entry-52.js +1 -1
  78. package/dist/entry-53.js +1 -1
  79. package/dist/entry-54.js +1 -0
  80. package/dist/entry-55.js +0 -1
  81. package/dist/entry-56.js +1 -0
  82. package/dist/entry-57.js +0 -1
  83. package/dist/entry-58.js +1 -1
  84. package/dist/entry-59.js +1 -1
  85. package/dist/entry-60.js +1 -1
  86. package/dist/entry-61.js +1 -1
  87. package/dist/entry-62.js +1 -1
  88. package/dist/entry-63.js +1 -0
  89. package/dist/entry-64.js +0 -1
  90. package/dist/entry-65.js +1 -0
  91. package/dist/entry-66.js +0 -1
  92. package/dist/entry-67.js +1 -1
  93. package/dist/entry-68.js +1 -1
  94. package/dist/entry-69.js +1 -1
  95. package/dist/entry-70.js +123 -1
  96. package/dist/entry-71.js +30 -1
  97. package/dist/entry-72.js +2 -1
  98. package/dist/entry-73.js +1 -1
  99. package/dist/entry-74.js +1 -1
  100. package/dist/entry-75.js +1 -1
  101. package/dist/entry-76.js +3 -1
  102. package/dist/entry-77.js +1 -1
  103. package/dist/entry-78.js +1 -1
  104. package/dist/entry-79.js +1 -1
  105. package/dist/pi-agent-ide.js +3 -13
  106. package/docs/configuration.md +57 -11
  107. package/docs/extensions.md +4 -2
  108. package/docs/tools.md +7 -1
  109. package/node_modules/pi-agent-doctor/package.json +1 -1
  110. package/node_modules/pi-agent-filesystem/index.ts +2 -2
  111. package/node_modules/pi-agent-filesystem/package.json +6 -6
  112. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  113. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  114. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  115. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  116. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +89 -19
  117. package/node_modules/pi-agent-ide-ast/src/extension.ts +11 -15
  118. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
  119. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  120. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
  121. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  122. package/node_modules/pi-agent-ide-changes/index.ts +22 -10
  123. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  124. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  125. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +5 -9
  126. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
  127. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  128. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +36 -13
  129. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
  130. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  131. package/node_modules/pi-agent-ide-lint/index.ts +49 -17
  132. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  133. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
  134. package/node_modules/pi-agent-ide-lsp/index.ts +127 -20
  135. package/node_modules/pi-agent-ide-lsp/package.json +9 -8
  136. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  137. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +25 -7
  138. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
  139. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-image/src/image-converter.ts +1 -1
  148. package/node_modules/pi-agent-invariant/package.json +1 -1
  149. package/node_modules/pi-agent-pdf/package.json +2 -2
  150. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +1 -1
  151. package/node_modules/pi-agent-read/package.json +6 -6
  152. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  153. package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
  154. package/node_modules/pi-agent-read/src/api/rendering.ts +3 -0
  155. package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
  156. package/node_modules/pi-agent-read/src/core/read-core.ts +32 -28
  157. package/node_modules/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
  158. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  159. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  160. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +87 -19
  161. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  162. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  163. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +87 -53
  164. package/node_modules/pi-agent-resource/package.json +1 -1
  165. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +1 -8
  166. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  167. package/node_modules/pi-agent-search/package.json +3 -3
  168. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  169. package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
  170. package/node_modules/pi-agent-search/src/api/search.ts +55 -1
  171. package/node_modules/pi-agent-search/src/core/extension.ts +8 -27
  172. package/node_modules/pi-agent-search/src/core/search-core.ts +38 -3
  173. package/node_modules/pi-agent-search-text/index.ts +82 -33
  174. package/node_modules/pi-agent-search-text/package.json +6 -6
  175. package/node_modules/pi-agent-search-text/src/file-search.ts +9 -1
  176. package/node_modules/pi-agent-search-text/src/resolvers.ts +1 -1
  177. package/node_modules/pi-agent-search-text/src/search-recipe.ts +2 -0
  178. package/node_modules/pi-agent-search-text/src/search-session.ts +112 -24
  179. package/node_modules/pi-agent-text/package.json +2 -2
  180. package/node_modules/pi-agent-text/src/text-converter.ts +1 -1
  181. package/node_modules/pi-agent-text/src/text-document.ts +5 -0
  182. package/node_modules/pi-agent-text/src/text-target.ts +4 -0
  183. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +2 -6
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  188. package/node_modules/pi-agent-text-editor/index.ts +1 -3
  189. package/node_modules/pi-agent-text-editor/package.json +34 -24
  190. package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
  191. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  192. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  193. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  194. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  195. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -0
  196. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  197. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +74 -1
  198. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  199. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  200. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  201. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  202. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  203. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  204. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  205. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  206. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  207. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  208. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  209. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  210. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +4 -12
  211. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  212. package/node_modules/pi-agent-text-editor/src/core/extension.ts +13 -9
  213. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  214. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  215. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  216. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +28 -2
  217. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
  218. package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
  219. package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
  220. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  221. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +5 -2
  222. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  223. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +40 -0
  224. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
  225. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
  226. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
  227. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
  228. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
  229. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
  230. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
  231. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
  232. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
  233. package/node_modules/pi-agent-text-editor-renderer/index.ts +93 -2
  234. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  235. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +7 -0
  236. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
  237. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
  238. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
  239. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
  240. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
  241. package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
  242. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
  243. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
  244. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  245. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  246. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  247. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
  248. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  249. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  250. package/node_modules/pi-agent-web/index.ts +1 -6
  251. package/node_modules/pi-agent-web/package.json +7 -7
  252. package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
  253. package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
  254. package/node_modules/pi-agent-web-html/package.json +3 -3
  255. package/node_modules/pi-agent-web-html/src/html-converter.ts +1 -1
  256. package/node_modules/pi-agent-web-image/package.json +4 -4
  257. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  258. package/node_modules/pi-agent-web-text/package.json +4 -4
  259. package/package.json +38 -38
  260. package/src/api/plugin-protocol.ts +12 -2
  261. package/src/api/text-editor.ts +7 -0
  262. package/src/api/tool-config.ts +77 -2
  263. package/src/code-view/diagnostic-view.ts +22 -3
  264. package/src/composite/builtin-extensions.ts +138 -67
  265. package/src/composite/extensions-config.ts +59 -0
  266. package/src/composite/feature-flags.ts +32 -0
  267. package/src/composite/module-labels.ts +55 -0
  268. package/src/composite/module-settings-store.ts +44 -0
  269. package/src/composite/module-settings.ts +132 -0
  270. package/src/composite/selection.ts +4 -4
  271. package/src/composite/settings-panel.ts +71 -0
  272. package/src/core/diagnostic-delivery.ts +29 -0
  273. package/src/core/diagnostic-entry.ts +142 -0
  274. package/src/core/diagnostic-store.ts +96 -23
  275. package/src/core/extension.ts +45 -22
  276. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +2 -2
  277. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  278. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  279. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  280. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  281. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +1 -6
  282. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  283. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  284. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
  285. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +1 -1
  286. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  287. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  288. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  289. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
  290. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
  291. package/src/extensions/pi-agent-read/package.json +6 -6
  292. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  293. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
  294. package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -0
  295. package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
  296. package/src/extensions/pi-agent-read/src/core/read-core.ts +32 -28
  297. package/src/extensions/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
  298. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  299. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  300. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +87 -19
  301. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  302. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  303. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +87 -53
  304. package/src/extensions/pi-agent-search/package.json +3 -3
  305. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +82 -33
  306. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  307. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +9 -1
  308. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +1 -1
  309. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +2 -0
  310. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +112 -24
  311. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  312. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
  313. package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
  314. package/src/extensions/pi-agent-search/src/core/extension.ts +8 -27
  315. package/src/extensions/pi-agent-search/src/core/search-core.ts +38 -3
  316. package/src/extensions/pi-agent-text-editor/index.ts +1 -3
  317. package/src/extensions/pi-agent-text-editor/package.json +34 -24
  318. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  319. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  320. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +2 -6
  321. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  322. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  323. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +93 -2
  324. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  325. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +7 -0
  326. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
  327. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
  328. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
  329. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
  330. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
  331. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
  332. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
  333. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
  334. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  335. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  336. package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
  337. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
  338. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  339. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  340. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  341. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  342. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -0
  343. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  344. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +74 -1
  345. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  346. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  347. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  348. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  349. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  350. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  351. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  352. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  353. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  354. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  355. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  356. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  357. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +4 -12
  358. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  359. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +13 -9
  360. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  361. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  362. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  363. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +28 -2
  364. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
  365. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
  366. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
  367. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  368. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +5 -2
  369. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  370. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +40 -0
  371. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
  372. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
  373. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
  374. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
  375. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
  376. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
  377. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
  378. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
  379. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
  380. package/src/pi-agent-ide.ts +45 -0
  381. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  382. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +89 -19
  383. package/src/plugins/pi-agent-ide-ast/src/extension.ts +11 -15
  384. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
  385. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  386. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
  387. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  388. package/src/plugins/pi-agent-ide-changes/index.ts +22 -10
  389. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  390. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  391. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +5 -9
  392. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
  393. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -26
  394. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  395. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +36 -13
  396. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
  397. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  398. package/src/plugins/pi-agent-ide-lint/index.ts +49 -17
  399. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  400. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
  401. package/src/plugins/pi-agent-ide-lsp/index.ts +127 -20
  402. package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
  403. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  404. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +25 -7
  405. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
  406. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  407. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  408. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  409. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  410. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  411. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  412. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  413. package/src/post-edit/gate.ts +57 -15
  414. package/src/toolchain/types.ts +2 -0
  415. package/dist/chunk-2SKAED2I.js +0 -2
  416. package/dist/chunk-2XYXV5HS.js +0 -4
  417. package/dist/chunk-2ZMYT6ZC.js +0 -1
  418. package/dist/chunk-34ZQTTU2.js +0 -2
  419. package/dist/chunk-4SQQKEVD.js +0 -16
  420. package/dist/chunk-5BWUVAR4.js +0 -1
  421. package/dist/chunk-6DN7NO7L.js +0 -1
  422. package/dist/chunk-6SMFVLTY.js +0 -1
  423. package/dist/chunk-6XQQBKPE.js +0 -58
  424. package/dist/chunk-BYWAG6X3.js +0 -6
  425. package/dist/chunk-EW2KVKCN.js +0 -2
  426. package/dist/chunk-F6SESI3P.js +0 -4
  427. package/dist/chunk-GTK5AREE.js +0 -2
  428. package/dist/chunk-HOBTFFQR.js +0 -1
  429. package/dist/chunk-IMVCVPMP.js +0 -3
  430. package/dist/chunk-IOCABSRL.js +0 -1
  431. package/dist/chunk-JASLOB2X.js +0 -1
  432. package/dist/chunk-KH5KPBCR.js +0 -10
  433. package/dist/chunk-KNMWCDDK.js +0 -7
  434. package/dist/chunk-KYVOMBO5.js +0 -1
  435. package/dist/chunk-L4FA6OD4.js +0 -1
  436. package/dist/chunk-LFV6G5Z3.js +0 -1
  437. package/dist/chunk-LGN7EJYR.js +0 -13
  438. package/dist/chunk-MB6VVVAF.js +0 -2
  439. package/dist/chunk-MTQSGWZJ.js +0 -1
  440. package/dist/chunk-NI2NK4JU.js +0 -1
  441. package/dist/chunk-NXHPO7ER.js +0 -6
  442. package/dist/chunk-OFHVDY4Q.js +0 -2
  443. package/dist/chunk-OIL6BB2S.js +0 -33
  444. package/dist/chunk-ONWUJXUR.js +0 -1
  445. package/dist/chunk-PODWLGNO.js +0 -6
  446. package/dist/chunk-QZANC2IG.js +0 -1
  447. package/dist/chunk-SSZB66C3.js +0 -3
  448. package/dist/chunk-TG6H6EOI.js +0 -1
  449. package/dist/chunk-UTTW55S2.js +0 -1
  450. package/dist/chunk-VEJGSURY.js +0 -8
  451. package/dist/chunk-W3XYKJ5H.js +0 -1
  452. package/dist/chunk-XGUAL3CA.js +0 -1
  453. package/dist/chunk-YPHXLAQF.js +0 -1
  454. package/dist/chunk-ZIHEF6K3.js +0 -3
  455. package/dist/entry-80.js +0 -1
  456. package/node_modules/pi-agent-read/src/core/tools/read/views.ts +0 -29
  457. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  458. package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
  459. package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
  460. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  461. package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
  462. package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
  463. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  464. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
  465. package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
  466. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
  467. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
  468. package/src/extensions/pi-agent-read/src/core/tools/read/views.ts +0 -29
  469. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
  470. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
  471. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
  472. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  473. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
  474. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
  475. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  476. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  477. /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
  478. /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
  479. /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  480. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
  481. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
  482. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
  483. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  484. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  485. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  486. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  487. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  488. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  489. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  490. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
@@ -1,5 +1,8 @@
1
1
  import { requiredValue } from "pi-agent-invariant";
2
2
  import path from "node:path";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ import type { TextEditCompletion } from "#src/api/edit-completion.js";
5
+ import { Value } from "typebox/value";
3
6
  import type {
4
7
  TextAnchorRecoveryCandidateRange,
5
8
  TextAnchorRecoveryRange,
@@ -19,6 +22,7 @@ import {
19
22
  type FileMutationBatchResult,
20
23
  FileMutationResult,
21
24
  type MutationResultPresentation,
25
+ type MutationOperationReceipt,
22
26
  } from "#src/api/mutation-result.js";
23
27
  import {
24
28
  isMutationAnchorValue,
@@ -28,7 +32,11 @@ import {
28
32
  type TextMutationEdit,
29
33
  type TextMutationToolRegistration,
30
34
  } from "#src/api/mutation-tool.js";
31
- import { isTextMutationResultContributionData } from "#src/api/post-edit.js";
35
+ import {
36
+ isFormattingContribution,
37
+ isDiffStatusContribution,
38
+ isTextMutationResultContributionData,
39
+ } from "#src/api/post-edit.js";
32
40
  import {
33
41
  formatStaleAnchorMessage,
34
42
  type StaleAnchorMessageDetails,
@@ -49,7 +57,6 @@ import {
49
57
  type ToolCallInterceptionRenderStore,
50
58
  withToolCallInterceptionRendering,
51
59
  } from "#src/core/tool-call-interceptor/rendering.js";
52
- import { appendSchemaFieldOrder } from "#src/core/tool-description.js";
53
60
 
54
61
  import type { TextEditExecutionOutcome } from "#src/api/edit-pipeline.js";
55
62
  import type {
@@ -67,6 +74,7 @@ import { renderTextAnchor, type TextAnchor } from "pi-agent-text";
67
74
  import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
68
75
  import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception";
69
76
  import type { Static, TSchema } from "typebox";
77
+ import type { ScriptMutationOutcome } from "#src/core/apply/mutation-outcome.js";
70
78
 
71
79
  export function createTextTool<TParameters extends TSchema>(
72
80
  core: TextEditorCore,
@@ -83,7 +91,9 @@ export function createTextTool<TParameters extends TSchema>(
83
91
  label: definition.name,
84
92
 
85
93
  promptSnippet: definition.promptSnippet,
86
- description: appendSchemaFieldOrder(definition.description, definition.parameters),
94
+ promptGuidelines:
95
+ definition.promptGuidelines === undefined ? undefined : [...definition.promptGuidelines],
96
+ description: definition.description,
87
97
  parameters: definition.parameters,
88
98
  prepareArguments: (arguments_) =>
89
99
  // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
@@ -116,15 +126,18 @@ export function createTextTool<TParameters extends TSchema>(
116
126
  }),
117
127
  annotations,
118
128
  );
119
- Object.defineProperty(tool, "promptGuidelines", {
129
+ Object.defineProperty(tool, "description", {
120
130
  enumerable: true,
121
- get(): string[] | undefined {
122
- const pluginGuideline = pluginPromptGuideline();
123
- const guidelines = [
124
- ...(pluginGuideline === undefined ? [] : [pluginGuideline]),
125
- ...(definition.promptGuidelines ?? []),
126
- ];
127
- return guidelines.length === 0 ? undefined : guidelines;
131
+ get(): string {
132
+ return [
133
+ definition.description,
134
+ definition.source.inherited
135
+ ? `When ${definition.source.field} is omitted, the tool can reuse the file identified by the supplied anchor, the last read, or the preceding edit in the same batch.`
136
+ : "",
137
+ pluginPromptGuideline() ?? "",
138
+ ]
139
+ .filter(Boolean)
140
+ .join("\n");
128
141
  },
129
142
  });
130
143
  return tool;
@@ -195,6 +208,7 @@ async function resolveMutationSources(
195
208
  const expandedByAnchor = new Map<string, readonly TextTarget[]>();
196
209
  const expandedBySourceField = new Map<string, readonly TextTarget[]>();
197
210
  const expandedFromExplicitSource = new Set<string>();
211
+ const sourceSelections = new Map<string, readonly TextTarget[]>();
198
212
  const explicitlyScopedSourceFields = new Set<string>();
199
213
  const allKinds = [
200
214
  ...new Set((definition.anchors ?? []).flatMap((descriptor) => descriptor.kinds)),
@@ -239,6 +253,7 @@ async function resolveMutationSources(
239
253
  const expanded = await resolveTargets(explicit, descriptor.field, explicit);
240
254
  if (expanded !== undefined) {
241
255
  expandedFromExplicitSource.add(descriptor.field);
256
+ sourceSelections.set(descriptor.field, expanded);
242
257
  expandedBySourceField.set(
243
258
  descriptor.field,
244
259
  mergeTargets(expandedBySourceField.get(descriptor.field) ?? [], expanded),
@@ -288,14 +303,20 @@ async function resolveMutationSources(
288
303
  const anchors = new Map<string, readonly string[]>();
289
304
  const implicitTargets = new Map<string, readonly TextTarget[]>();
290
305
  for (const descriptor of definition.anchors ?? []) {
291
- const targets = expandedBySourceField.get(descriptor.sourceField);
306
+ const targets = sourceSelections.get(descriptor.sourceField);
307
+ const firstAnchor = definition.anchors?.find(
308
+ (anchor) => anchor.sourceField === descriptor.sourceField,
309
+ );
292
310
 
293
311
  const hasExplicitAnchor = isMutationAnchorValue(descriptor, input[descriptor.field]);
294
312
  const hasImplicitSourceSelection = expandedFromExplicitSource.has(descriptor.sourceField);
295
313
  if (!hasExplicitAnchor && !hasImplicitSourceSelection) continue;
314
+ // A sibling endpoint can identify the file, but must not contribute its
315
+ // selected ranges to this endpoint. Only a typed source supplies a selection.
296
316
  if (
297
317
  targets !== undefined &&
298
- (hasImplicitSourceSelection || !expandedByAnchor.has(descriptor.field))
318
+ hasImplicitSourceSelection &&
319
+ descriptor.field === firstAnchor?.field
299
320
  ) {
300
321
  implicitTargets.set(descriptor.field, targets);
301
322
  }
@@ -355,9 +376,16 @@ function mergeTargets(left: readonly TextTarget[], right: readonly TextTarget[])
355
376
  merged.set(target.source, target);
356
377
  continue;
357
378
  }
379
+ if (
380
+ previous.expectedContent !== undefined &&
381
+ target.expectedContent !== undefined &&
382
+ previous.expectedContent !== target.expectedContent
383
+ )
384
+ throw new Error("Selections refer to different source revisions. Read the source again.");
358
385
  const ranges = [...(previous.ranges ?? []), ...(target.ranges ?? [])];
359
386
  merged.set(target.source, {
360
387
  source: target.source,
388
+ expectedContent: target.expectedContent ?? previous.expectedContent,
361
389
  ...(ranges.length > 0 && { ranges: deduplicateRanges(ranges) }),
362
390
  });
363
391
  }
@@ -698,6 +726,37 @@ export async function executeTextMutation<TParameters extends TSchema>(
698
726
  publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
699
727
  lastResolvedSource?: string,
700
728
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
729
+ const execution = await executeTextMutationPipeline(
730
+ core,
731
+ definition,
732
+ parameters,
733
+ signal,
734
+ context,
735
+ publishAnchorRenderState,
736
+ lastResolvedSource,
737
+ );
738
+ const result = await buildToolResult(
739
+ core,
740
+ execution.pipeline,
741
+ execution.source,
742
+ context,
743
+ definition.name,
744
+ );
745
+ return execution.pipeline.kind === "completed" && execution.pipeline.state.metadata !== undefined
746
+ ? { ...result, details: { ...result.details, metadata: execution.pipeline.state.metadata } }
747
+ : result;
748
+ }
749
+
750
+ /** Runs configured mutation semantics without creating model-facing presentation. */
751
+ export async function executeTextMutationPipeline<TParameters extends TSchema>(
752
+ core: TextEditorCore,
753
+ definition: TextMutationToolRegistration<TParameters>,
754
+ parameters: Static<TParameters>,
755
+ signal: AbortSignal | undefined,
756
+ context: ExtensionContext,
757
+ publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
758
+ lastResolvedSource?: string,
759
+ ): Promise<{ readonly pipeline: TextEditExecutionOutcome; readonly source: string }> {
701
760
  const source = mutationSource(definition, parameters);
702
761
  const pipeline = await core.executeEdit(
703
762
  definition.name,
@@ -708,6 +767,46 @@ export async function executeTextMutation<TParameters extends TSchema>(
708
767
  },
709
768
  async (state) => {
710
769
  try {
770
+ if (state.editPlan !== undefined) {
771
+ const plan = state.editPlan;
772
+ if (
773
+ plan.files.length === 0 ||
774
+ new Set(plan.files.map((file) => file.source)).size !== plan.files.length
775
+ )
776
+ throw new Error("Semantic edit plan must contain distinct source files.");
777
+ const outcome = await core.editTexts(
778
+ plan.files.map((file) => ({ source: file.source, read: true })),
779
+ {
780
+ cwd: state.cwd,
781
+ intent: definition.intent ?? "edit",
782
+ ...(state.signal !== undefined && { signal: state.signal }),
783
+ },
784
+ (texts) => {
785
+ for (const file of plan.files) {
786
+ if (texts.get(file.source) !== file.expectedContent)
787
+ throw new Error(
788
+ "A semantic edit source changed. Resolve the symbol again before retrying.",
789
+ );
790
+ }
791
+ const edits = new Map(
792
+ plan.files.map((file) => [
793
+ file.source,
794
+ { changes: file.changes, action: "edited" as const },
795
+ ]),
796
+ );
797
+ return Promise.resolve({
798
+ changes: new Map(plan.files.map((file) => [file.source, file.changes])),
799
+ result: {
800
+ edits,
801
+ resultPresentations: new Map(
802
+ plan.files.map((file) => [file.source, "plain" as const]),
803
+ ),
804
+ },
805
+ });
806
+ },
807
+ );
808
+ return await completeTextMutation(outcome, requiredValue(plan.files[0]).source);
809
+ }
711
810
  const sources = await resolveMutationSources(
712
811
  core,
713
812
  definition,
@@ -727,6 +826,15 @@ export async function executeTextMutation<TParameters extends TSchema>(
727
826
  ...(state.signal !== undefined && { signal: state.signal }),
728
827
  },
729
828
  async (texts, resolveAnchor) => {
829
+ for (const target of sources.targets) {
830
+ if (
831
+ target.expectedContent !== undefined &&
832
+ texts.get(target.source) !== target.expectedContent
833
+ )
834
+ throw new Error(
835
+ "The selected source changed before editing. Resolve the symbol again.",
836
+ );
837
+ }
730
838
  const mutationContext = createMutationContext(
731
839
  definition,
732
840
  state.input,
@@ -759,9 +867,142 @@ export async function executeTextMutation<TParameters extends TSchema>(
759
867
  },
760
868
  );
761
869
 
762
- return buildToolResult(core, pipeline, source, context);
870
+ return { pipeline, source };
763
871
  }
764
872
 
873
+ const scriptMutationScope = new AsyncLocalStorage<TextEditCompletion[]>();
874
+
875
+ async function captureScriptMutation<T>(core: TextEditorCore, action: () => Promise<T>) {
876
+ const completions: TextEditCompletion[] = [];
877
+ const unsubscribe = core.onDidEdit((completion) => {
878
+ if (scriptMutationScope.getStore() === completions) completions.push(completion);
879
+ });
880
+ try {
881
+ const value = await scriptMutationScope.run(completions, action);
882
+ return { kind: "completed" as const, value, completions };
883
+ } catch (error) {
884
+ return { kind: "failed" as const, error, completions };
885
+ } finally {
886
+ unsubscribe();
887
+ }
888
+ }
889
+ /**
890
+ * Runs the configured mutation pipeline and returns plain script data.
891
+ * onPresentation retains rich edit annotations on the host without sending classes to the guest.
892
+ */
893
+ export async function executeScriptMutation<TParameters extends TSchema>(
894
+ core: TextEditorCore,
895
+ definition: TextMutationToolRegistration<TParameters>,
896
+ arguments_: unknown,
897
+ signal: AbortSignal | undefined,
898
+ context: ExtensionContext,
899
+ lastResolvedSource?: string,
900
+ onPresentation?: (source: string, result: FileMutationResult) => void,
901
+ ): Promise<ScriptMutationOutcome> {
902
+ const parameters = prepareGuardedArguments(
903
+ definition.parameters,
904
+ arguments_,
905
+ definition.source.inherited ? definition.source.field : undefined,
906
+ lastResolvedSource,
907
+ definition.anchors ?? [],
908
+ );
909
+ if (!Value.Check(definition.parameters, parameters)) {
910
+ throw Object.assign(new Error(`Invalid arguments for ${definition.name}`), {
911
+ code: "INVALID_ARGUMENTS",
912
+ details: { operation: definition.name, effect: "not-applied" },
913
+ });
914
+ }
915
+ const captured = await captureScriptMutation(core, () =>
916
+ executeTextMutationPipeline(
917
+ core,
918
+ definition,
919
+ parameters,
920
+ signal,
921
+ context,
922
+ undefined,
923
+ lastResolvedSource,
924
+ ),
925
+ );
926
+ const source =
927
+ captured.kind === "completed" ? captured.value.source : mutationSource(definition, parameters);
928
+ const observedFiles: ScriptMutationOutcome["files"] = captured.completions.map((completion) => ({
929
+ source: completion.resourceSource,
930
+ before: completion.existed ? completion.before.content : null,
931
+ after: completion.after.content,
932
+ action: definition.name === "write" ? "overwritten" : "edited",
933
+ changes: [],
934
+ formatting: { status: "not-reported" },
935
+ }));
936
+ const failed = (
937
+ code: string,
938
+ message: string,
939
+ effect: ScriptMutationOutcome["effect"],
940
+ completed: readonly string[] = [],
941
+ ): ScriptMutationOutcome => ({
942
+ operation: definition.name,
943
+ ok: false,
944
+ effect: effect === "unknown" ? "unknown" : observedFiles.length > 0 ? "applied" : effect,
945
+ completed: [...new Set([...completed, ...observedFiles.map((file) => file.source)])],
946
+ files: observedFiles,
947
+ errors: [{ source, code, message }],
948
+ });
949
+ if (captured.kind === "failed")
950
+ return failed("EXECUTION_FAILED", errorMessage(captured.error), "unknown");
951
+ const { pipeline } = captured.value;
952
+ if (pipeline.kind === "failed")
953
+ return {
954
+ ...failed(pipeline.failure.code, pipeline.failure.message, "not-applied"),
955
+ recoveries: await scriptAnchorRecoveries(pipeline.failure.cause),
956
+ };
957
+ const outcome = pipeline.state.result;
958
+ if (!isResourcesEditOutcome(outcome))
959
+ return failed("INVALID_RESULT", "Invalid mutation outcome", "unknown");
960
+ if (outcome.kind === "failed")
961
+ return {
962
+ ...failed(
963
+ outcome.failure.code,
964
+ outcome.failure.message,
965
+ outcome.completed.length > 0 ? "unknown" : "not-applied",
966
+ outcome.completed,
967
+ ),
968
+ recoveries: await scriptAnchorRecoveries(outcome.failure.cause),
969
+ };
970
+ const mutation = outcome.result as ExecutedTextMutation;
971
+ const files = outcome.resources.flatMap((resource) => {
972
+ const edit = mutation.edits.get(resource.source);
973
+ if (edit === undefined) return [];
974
+ const presentation = withPipelineStatuses(
975
+ buildSuccessfulTextMutationResult(resource, resource.source, edit),
976
+ pipeline.state.metadata,
977
+ );
978
+ onPresentation?.(resource.after.source, presentation);
979
+ const data = presentation.data;
980
+ return [
981
+ {
982
+ source: resource.after.source,
983
+ before:
984
+ captured.completions.find(
985
+ (completion) => completion.resourceSource === resource.after.source,
986
+ )?.existed === false
987
+ ? null
988
+ : resource.before.content,
989
+ after: resource.after.content,
990
+ action: edit.action,
991
+ changes: data.rawChanges ?? [],
992
+ formatting: data.formatting ?? { status: "not-reported" as const },
993
+ },
994
+ ];
995
+ });
996
+ return {
997
+ operation: definition.name,
998
+ ok: true,
999
+ effect: files.length > 0 ? "applied" : "not-applied",
1000
+ files,
1001
+ completed: files.map((file) => file.source),
1002
+ ...(pipeline.state.metadata !== undefined && { metadata: pipeline.state.metadata }),
1003
+ errors: [],
1004
+ };
1005
+ }
765
1006
  export function mutationSources(
766
1007
  definition: TextMutationToolRegistration,
767
1008
  parameters: Readonly<Record<string, unknown>>,
@@ -795,6 +1036,7 @@ type CompletedTextResource = Extract<
795
1036
  { readonly kind: "completed" }
796
1037
  >;
797
1038
 
1039
+ /** Builds a mutation receipt; peer ranges are supplied only for per-call batch display results. */
798
1040
  export function buildSuccessfulTextMutationResult(
799
1041
  resource: CompletedTextResource,
800
1042
  resultSource: string,
@@ -802,10 +1044,17 @@ export function buildSuccessfulTextMutationResult(
802
1044
  diffAfterContent = resource.after.content,
803
1045
  resultPresentation: MutationResultPresentation = "plain",
804
1046
  editCount = 1,
1047
+ operations: readonly MutationOperationReceipt[] = [],
1048
+
1049
+ diffPeerRanges?: readonly {
1050
+ readonly from: number;
1051
+ readonly to: number;
1052
+ readonly insert: string;
1053
+ }[],
805
1054
  ): FileMutationResult {
806
1055
  const before = resource.before.content;
807
1056
  const finalAfter = resource.after.content;
808
- const applied = applyTextChanges(before, edit.changes);
1057
+ const applied = applyTextChanges(before, edit.changes, before.length === 0);
809
1058
  const unified = createUnifiedDiff(resultSource, before, diffAfterContent);
810
1059
  const mutationResultData = resource.postEditContributions
811
1060
  .map((contribution) => contribution.data)
@@ -822,6 +1071,17 @@ export function buildSuccessfulTextMutationResult(
822
1071
 
823
1072
  return new FileMutationResult({
824
1073
  ...mutationResultData,
1074
+
1075
+ ...(diffPeerRanges === undefined ? {} : { diffPeerRanges }),
1076
+
1077
+ operations,
1078
+ diffStatuses: resource.postEditContributions
1079
+ .map((item) => item.data)
1080
+ .filter(isDiffStatusContribution)
1081
+ .flatMap((item) => item.diffStatuses),
1082
+ formatting: resource.postEditContributions
1083
+ .map((item) => item.data)
1084
+ .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
825
1085
  ok: true,
826
1086
  path: resultSource,
827
1087
  diffs: [unified.diff],
@@ -868,6 +1128,7 @@ async function buildToolResult(
868
1128
  pipeline: TextEditExecutionOutcome,
869
1129
  source: string,
870
1130
  context: ExtensionContext,
1131
+ operation: string,
871
1132
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
872
1133
  if (pipeline.kind === "failed") {
873
1134
  return failureToolResult(
@@ -916,16 +1177,50 @@ async function buildToolResult(
916
1177
  edit,
917
1178
  undefined,
918
1179
  mutation.resultPresentations.get(resultSource) ?? "plain",
1180
+
1181
+ 1,
1182
+ [{ operation, changes: edit.changes.length }],
919
1183
  ),
920
1184
  ];
921
1185
  });
922
1186
 
1187
+ const presented = results.map((result) => withPipelineStatuses(result, pipeline.state.metadata));
923
1188
  return {
924
- content: [new FileMutationAgentResult(results).toTextContent()],
925
- details: { results },
1189
+ content: [new FileMutationAgentResult(presented).toTextContent()],
1190
+ details: { results: presented },
926
1191
  };
927
1192
  }
928
1193
 
1194
+ function withPipelineStatuses(result: FileMutationResult, metadata: unknown): FileMutationResult {
1195
+ if (!isDiffStatusContribution(metadata)) return result;
1196
+ return new FileMutationResult({
1197
+ ...result.data,
1198
+ diffStatuses: [...(result.data.diffStatuses ?? []), ...metadata.diffStatuses],
1199
+ });
1200
+ }
1201
+ async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
1202
+ if (error.resolution.recovery === undefined) await error.resolution.refreshRecovery();
1203
+ return error.resolution.recovery;
1204
+ }
1205
+
1206
+ async function scriptAnchorRecoveries(
1207
+ cause: unknown,
1208
+ ): Promise<NonNullable<ScriptMutationOutcome["recoveries"]>> {
1209
+ if (cause instanceof TextMutationAnchorAggregateError)
1210
+ return (await Promise.all(cause.failures.map(scriptAnchorRecoveries))).flat();
1211
+ if (!(cause instanceof TextMutationAnchorResolutionError)) return [];
1212
+ const recovery = await resolveAnchorRecovery(cause);
1213
+ return [
1214
+ {
1215
+ path: cause.source,
1216
+ field: cause.field,
1217
+ anchor: cause.anchor,
1218
+ status: recovery?.kind ?? "unavailable",
1219
+ candidates: recovery?.kind === "candidates" ? recovery.candidates : [],
1220
+ total: recovery?.kind === "candidates" ? recovery.total : 0,
1221
+ },
1222
+ ];
1223
+ }
929
1224
  async function anchorFailureToolResult(
930
1225
  core: TextEditorCore,
931
1226
  failure: TextResourceEditFailure,
@@ -966,10 +1261,7 @@ async function anchorFailureToolResult(
966
1261
 
967
1262
  const contextual = failure.cause;
968
1263
  const resolution = contextual.resolution;
969
- if (resolution.recovery === undefined) {
970
- await resolution.refreshRecovery();
971
- }
972
- const recovery = resolution.recovery;
1264
+ const recovery = await resolveAnchorRecovery(contextual);
973
1265
  if (recovery?.kind === "timed-out") {
974
1266
  return failureToolResult(
975
1267
  contextual.source,
@@ -50,6 +50,7 @@ export function singleAnchorSpan(
50
50
  context: TextMutationContext,
51
51
  anchors: ReadonlyMap<string, TextAnchor>,
52
52
  field: string,
53
+ wholeLines = false,
53
54
  ): TextAnchorSpan {
54
55
  if (anchors.size !== 1) {
55
56
  throw new Error(`Anchor ${field} must resolve in one resource.`);
@@ -63,7 +64,9 @@ export function singleAnchorSpan(
63
64
  const selectedRange = requiredValue(anchor.ranges[0]);
64
65
  const document = context.documentFor(source);
65
66
  const exactRange = selectionRange(context, source, selectedRange);
66
- const endLine = linewiseSelectionEndLine(selectedRange);
67
+ const endLine = wholeLines
68
+ ? containingEndLine(selectedRange)
69
+ : linewiseSelectionEndLine(selectedRange);
67
70
  if (endLine !== undefined) {
68
71
  const range = document.lineRange(selectedRange.start.lineNumber, endLine);
69
72
  return {
@@ -89,7 +92,7 @@ export function singleAnchorSpan(
89
92
  };
90
93
  }
91
94
 
92
- /** Builds a natural range from the left edge of start through the right edge of end. */
95
+ /** A single anchor keeps its own extent; two ordered anchors select inclusive whole lines. */
93
96
  export function anchorSpanRange(
94
97
  context: TextMutationContext,
95
98
  starts: ReadonlyMap<string, TextAnchor>,
@@ -102,15 +105,18 @@ export function anchorSpanRange(
102
105
  if (start.source !== end.source) {
103
106
  throw new Error(`Anchors ${startField} and ${endField} must resolve in one resource.`);
104
107
  }
105
- if (start.from > end.to) {
108
+ if (start.from > end.from) {
106
109
  throw new Error(`Anchor ${startField} must not come after ${endField}.`);
107
110
  }
111
+ if (ends === undefined) return start;
112
+ const first = singleAnchorSpan(context, starts, startField, true);
113
+ const last = singleAnchorSpan(context, ends, endField, true);
108
114
  return {
109
- source: start.source,
110
- from: start.from,
111
- to: end.to,
112
- selection: start.selection || end.selection,
113
- preservesTrailingLineBreak: end.preservesTrailingLineBreak,
115
+ source: first.source,
116
+ from: first.from,
117
+ to: last.to,
118
+ selection: false,
119
+ preservesTrailingLineBreak: true,
114
120
  };
115
121
  }
116
122
 
@@ -120,12 +126,13 @@ export function targetText(context: TextMutationContext, source: string, text: s
120
126
  return text.replace(/\r\n|\r|\n/gu, separator);
121
127
  }
122
128
 
123
- /** Creates a replacement while preserving a line endpoint's trailing separator. */
129
+ /** Empty text deletes the selection; nonempty text preserves a line endpoint's separator. */
124
130
  export function replaceAnchorSpan(
125
131
  context: TextMutationContext,
126
132
  span: TextAnchorSpan,
127
133
  text: string,
128
134
  ): { readonly from: number; readonly to: number; readonly insert: string } {
135
+ if (text === "") return deleteAnchorSpan(context, span);
129
136
  const document = context.documentFor(span.source);
130
137
  let insert = targetText(context, span.source, text);
131
138
  const selected = document.text(span);
@@ -159,18 +166,15 @@ export function deleteAnchorSpan(
159
166
  return { from: span.from, to: span.to, insert: "" };
160
167
  }
161
168
 
162
- /** Creates an insertion after a selection span or after a line anchor. */
169
+ /** Inserts after the last containing line of one resolved anchor. */
163
170
  export function insertionAfterAnchor(
164
171
  context: TextMutationContext,
165
172
  anchors: ReadonlyMap<string, TextAnchor>,
166
173
  field: string,
167
174
  insert: string,
168
175
  ): readonly [string, { readonly from: number; readonly to: number; readonly insert: string }] {
169
- const span = singleAnchorSpan(context, anchors, field);
176
+ const span = singleAnchorSpan(context, anchors, field, true);
170
177
  const normalizedInsert = targetText(context, span.source, insert);
171
- if (span.selection) {
172
- return [span.source, { from: span.to, to: span.to, insert: normalizedInsert }];
173
- }
174
178
 
175
179
  const lineNumber = span.linewiseEndLine ?? lineAnchor(anchors, field).lineNumber;
176
180
  return [
@@ -179,18 +183,15 @@ export function insertionAfterAnchor(
179
183
  ];
180
184
  }
181
185
 
182
- /** Creates an insertion before a selection span or before a line anchor. */
186
+ /** Inserts before the first containing line of one resolved anchor. */
183
187
  export function insertionBeforeAnchor(
184
188
  context: TextMutationContext,
185
189
  anchors: ReadonlyMap<string, TextAnchor>,
186
190
  field: string,
187
191
  insert: string,
188
192
  ): readonly [string, { readonly from: number; readonly to: number; readonly insert: string }] {
189
- const span = singleAnchorSpan(context, anchors, field);
193
+ const span = singleAnchorSpan(context, anchors, field, true);
190
194
  const normalizedInsert = targetText(context, span.source, insert);
191
- if (span.selection) {
192
- return [span.source, { from: span.from, to: span.from, insert: normalizedInsert }];
193
- }
194
195
 
195
196
  const lineNumber = span.linewiseStartLine ?? lineAnchor(anchors, field).lineNumber;
196
197
  return [
@@ -233,15 +234,16 @@ export function selectionChanges(
233
234
  (insert.length === 0 ? coalesceAdjacentLinewiseRanges(anchor.ranges) : anchor.ranges).map(
234
235
  (range) => {
235
236
  const span = selectionRange(context, source, range);
236
- const lineSpan = {
237
- source,
238
- ...span,
239
- selection: false,
240
- preservesTrailingLineBreak: range.linewise === true && insert.length > 0,
241
- };
242
- return insert.length === 0 && range.linewise === true
243
- ? deleteAnchorSpan(context, lineSpan)
244
- : replaceAnchorSpan(context, lineSpan, insert);
237
+ return replaceAnchorSpan(
238
+ context,
239
+ {
240
+ source,
241
+ ...span,
242
+ selection: range.linewise !== true,
243
+ preservesTrailingLineBreak: range.linewise === true,
244
+ },
245
+ insert,
246
+ );
245
247
  },
246
248
  ),
247
249
  ]),
@@ -261,23 +263,19 @@ export function insertionChanges(
261
263
  return new Map(
262
264
  [...selections].map(([source, anchor]) => [
263
265
  source,
264
- anchor.ranges.map((range) => {
266
+ [
267
+ ...new Set(
268
+ anchor.ranges.map((range) => {
269
+ selectionRange(context, source, range);
270
+ return before ? range.start.lineNumber : containingEndLine(range);
271
+ }),
272
+ ),
273
+ ].map((line) => {
265
274
  const document = context.documentFor(source);
266
275
  const normalizedInsert = targetText(context, source, insert);
267
- const linewiseEnd = linewiseSelectionEndLine(range);
268
- if (linewiseEnd !== undefined) {
269
- return before
270
- ? document.insertBeforeLine(range.start.lineNumber, normalizedInsert)
271
- : document.insertAfterLine(linewiseEnd, normalizedInsert);
272
- }
273
- const position = before ? range.start : range.end;
274
- const at = document.range(
275
- position.lineNumber,
276
- position.column,
277
- position.lineNumber,
278
- position.column,
279
- );
280
- return { ...at, insert: normalizedInsert };
276
+ return before
277
+ ? document.insertBeforeLine(line, normalizedInsert)
278
+ : document.insertAfterLine(line, normalizedInsert);
281
279
  }),
282
280
  ]),
283
281
  );
@@ -314,6 +312,10 @@ function linewiseSelectionEndLine(range: TextSelectionRange): number | undefined
314
312
  if (range.linewise !== true) {
315
313
  return undefined;
316
314
  }
315
+ return containingEndLine(range);
316
+ }
317
+
318
+ function containingEndLine(range: TextSelectionRange): number {
317
319
  return range.end.column === 0 && range.end.lineNumber > range.start.lineNumber
318
320
  ? range.end.lineNumber - 1
319
321
  : range.end.lineNumber;