pi-agent-ide 0.6.4 → 0.7.1

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 (431) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/chunk-2TRHFMCZ.js +11 -0
  5. package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
  6. package/dist/chunk-4XMY4H4V.js +1 -0
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
  9. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  10. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  11. package/dist/chunk-CWD4O5PM.js +3 -0
  12. package/dist/chunk-D3WTDA6V.js +2 -0
  13. package/dist/chunk-EAZGN5ND.js +7 -0
  14. package/dist/chunk-GXEGY7GV.js +1 -0
  15. package/dist/chunk-HZEY4GT4.js +2 -0
  16. package/dist/chunk-LEEQIQ7D.js +28 -0
  17. package/dist/chunk-NRZO5KJT.js +9 -0
  18. package/dist/chunk-OMVRLWMX.js +5 -0
  19. package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
  20. package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
  21. package/dist/chunk-PNU3E7IO.js +3 -0
  22. package/dist/chunk-PS2B6THP.js +3 -0
  23. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  24. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  25. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  26. package/dist/chunk-VMTR74FF.js +2 -0
  27. package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
  28. package/dist/chunk-WU6ZK6YD.js +1 -0
  29. package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
  30. package/dist/chunk-XYS4FSCC.js +12 -0
  31. package/dist/chunk-YP46DVVP.js +2 -0
  32. package/dist/entry-11.js +1 -1
  33. package/dist/entry-13.js +1 -1
  34. package/dist/entry-14.js +1 -1
  35. package/dist/entry-15.js +1 -1
  36. package/dist/entry-17.js +1 -1
  37. package/dist/entry-25.js +2 -2
  38. package/dist/entry-26.js +1 -1
  39. package/dist/entry-27.js +2 -2
  40. package/dist/entry-28.js +1 -1
  41. package/dist/entry-29.js +1 -1
  42. package/dist/entry-30.js +1 -1
  43. package/dist/entry-31.js +12 -9
  44. package/dist/entry-33.js +1 -1
  45. package/dist/entry-37.js +6 -6
  46. package/dist/entry-41.js +1 -1
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-43.js +1 -1
  49. package/dist/entry-44.js +1 -1
  50. package/dist/entry-45.js +13 -14
  51. package/dist/entry-46.js +1 -1
  52. package/dist/entry-49.js +1 -1
  53. package/dist/entry-50.js +3 -6
  54. package/dist/entry-51.js +11 -9
  55. package/dist/entry-52.js +1 -1
  56. package/dist/entry-53.js +1 -1
  57. package/dist/entry-54.js +1 -1
  58. package/dist/entry-56.js +1 -1
  59. package/dist/entry-57.js +1 -1
  60. package/dist/entry-58.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +0 -1
  63. package/dist/entry-62.js +1 -0
  64. package/dist/entry-63.js +0 -1
  65. package/dist/entry-64.js +1 -0
  66. package/dist/entry-65.js +1 -1
  67. package/dist/entry-66.js +1 -1
  68. package/dist/entry-67.js +1 -1
  69. package/dist/entry-68.js +1 -1
  70. package/dist/entry-69.js +1 -1
  71. package/dist/entry-70.js +1 -1
  72. package/dist/entry-71.js +0 -1
  73. package/dist/entry-72.js +1 -0
  74. package/dist/entry-73.js +0 -1
  75. package/dist/entry-74.js +1 -0
  76. package/dist/entry-75.js +1 -1
  77. package/dist/entry-76.js +1 -1
  78. package/dist/entry-77.js +66 -1
  79. package/dist/entry-78.js +14 -325
  80. package/dist/entry-79.js +2 -18
  81. package/dist/entry-80.js +1 -2
  82. package/dist/entry-81.js +1 -1
  83. package/dist/entry-82.js +5 -1
  84. package/dist/entry-83.js +3 -5
  85. package/dist/entry-84.js +1 -3
  86. package/dist/entry-85.js +1 -1
  87. package/dist/entry-86.js +1 -1
  88. package/dist/pi-agent-ide.js +14 -9
  89. package/docs/agent-guides/editing.md +38 -33
  90. package/docs/agent-guides/git-changes.md +1 -1
  91. package/docs/agent-guides/read-resources.md +8 -4
  92. package/docs/agent-guides/search-code.md +34 -2
  93. package/docs/agent-guides/select-code.md +115 -0
  94. package/docs/configuration.md +12 -17
  95. package/docs/development.md +2 -1
  96. package/docs/releases.md +1 -1
  97. package/docs/research/apply-native-capability-matrix.md +174 -0
  98. package/docs/research/apply-read-latency.md +2 -0
  99. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  100. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  101. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  102. package/docs/research/native-codemode-batch-decision.md +2 -0
  103. package/docs/research/native-codemode-batching.md +1 -1
  104. package/docs/structured-results.md +30 -38
  105. package/docs/tools.md +11 -11
  106. package/docs/user-hooks.md +1 -1
  107. package/node_modules/pi-agent-doctor/package.json +1 -1
  108. package/node_modules/pi-agent-documentation/package.json +1 -1
  109. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  110. package/node_modules/pi-agent-filesystem/package.json +7 -7
  111. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  112. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  113. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  114. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  115. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  116. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  117. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  119. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  120. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  121. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  122. package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
  123. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  124. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  125. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  126. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  127. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  128. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  129. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  130. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
  131. package/node_modules/pi-agent-ide-changes/index.ts +6 -21
  132. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  133. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  134. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  135. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  136. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  137. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  138. package/node_modules/pi-agent-ide-lsp/index.ts +5 -5
  139. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-invariant/package.json +1 -1
  148. package/node_modules/pi-agent-pdf/package.json +2 -2
  149. package/node_modules/pi-agent-read/package.json +7 -7
  150. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  151. package/node_modules/pi-agent-read/src/api/read-parameters.ts +40 -3
  152. package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
  153. package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
  154. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  155. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  156. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  157. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  158. package/node_modules/pi-agent-resource/package.json +1 -1
  159. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  160. package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
  161. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  162. package/node_modules/pi-agent-search/package.json +5 -5
  163. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  164. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  165. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  166. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  167. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  168. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  169. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  170. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  171. package/node_modules/pi-agent-search-text/index.ts +3 -1
  172. package/node_modules/pi-agent-search-text/package.json +7 -6
  173. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  174. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  175. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  176. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  177. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  178. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  179. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  180. package/node_modules/pi-agent-text/package.json +2 -2
  181. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  182. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  183. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  188. package/node_modules/pi-agent-text-editor/package.json +26 -31
  189. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  190. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  192. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  193. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  194. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  195. package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
  196. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  197. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  198. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  199. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  201. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  202. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  203. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  204. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  205. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  206. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  207. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  208. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  209. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  210. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  211. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  212. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  213. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  214. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  215. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  216. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  217. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  218. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  219. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  220. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  221. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  222. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  223. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  224. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  225. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  226. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  227. package/node_modules/pi-agent-web/index.ts +7 -3
  228. package/node_modules/pi-agent-web/package.json +8 -8
  229. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  230. package/node_modules/pi-agent-web/src/search.ts +111 -2
  231. package/node_modules/pi-agent-web-html/package.json +3 -3
  232. package/node_modules/pi-agent-web-image/package.json +4 -4
  233. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  234. package/node_modules/pi-agent-web-text/package.json +4 -4
  235. package/package.json +35 -36
  236. package/src/composite/module-labels.ts +1 -1
  237. package/src/composite/preferences.ts +0 -5
  238. package/src/composite/text-results.ts +221 -0
  239. package/src/documentation/extension.ts +11 -9
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  247. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +7 -3
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  256. package/src/extensions/pi-agent-read/package.json +7 -7
  257. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  258. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +40 -3
  259. package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
  260. package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
  261. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  262. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  263. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  264. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  265. package/src/extensions/pi-agent-search/package.json +5 -5
  266. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  267. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  268. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  269. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  270. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  271. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  272. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  273. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  274. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  275. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  276. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  277. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  278. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  279. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  280. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  281. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  282. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  283. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  284. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  285. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  286. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  287. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  288. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  289. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  290. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  291. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  292. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  293. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  294. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  295. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  296. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  297. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  298. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  299. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  300. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  301. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  302. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  303. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
  304. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  305. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  306. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  307. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  308. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  309. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  310. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  311. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  312. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  313. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  314. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  315. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  316. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  317. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  318. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  319. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  320. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  321. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  322. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  323. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  324. package/src/pi-agent-ide.ts +4 -7
  325. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  326. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  327. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  328. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  329. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  330. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  331. package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
  332. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  333. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  334. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  335. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  336. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  337. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  338. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  339. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
  340. package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
  341. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  342. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  343. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  344. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  345. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  346. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  347. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  348. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  349. package/src/plugins/pi-agent-ide-lsp/index.ts +5 -5
  350. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  351. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  352. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  353. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  354. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  355. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  356. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  357. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  358. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  359. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  360. package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
  361. package/dist/chunk-2P2OGO3G.js +0 -2
  362. package/dist/chunk-5J43L2RL.js +0 -11
  363. package/dist/chunk-6EYWFBNG.js +0 -0
  364. package/dist/chunk-7AVXUV4A.js +0 -7
  365. package/dist/chunk-7WCZOO5I.js +0 -1
  366. package/dist/chunk-BAYETTZZ.js +0 -16
  367. package/dist/chunk-BVK5A7ED.js +0 -28
  368. package/dist/chunk-F7NVAC4Q.js +0 -0
  369. package/dist/chunk-FZBCKIJJ.js +0 -1
  370. package/dist/chunk-I5JLCFUX.js +0 -1
  371. package/dist/chunk-KUPHNMUK.js +0 -2
  372. package/dist/chunk-MIZAFRDR.js +0 -1
  373. package/dist/chunk-PJPA5EEE.js +0 -2
  374. package/dist/chunk-PXWDDBBC.js +0 -0
  375. package/dist/chunk-SILJ3OL4.js +0 -9
  376. package/dist/chunk-TQZBVOTT.js +0 -5
  377. package/dist/chunk-VWW3RLUX.js +0 -12
  378. package/dist/chunk-YHUTTZC6.js +0 -2
  379. package/dist/chunk-ZODCBFBL.js +0 -2
  380. package/dist/entry-87.js +0 -1
  381. package/docs/agent-guides/apply.md +0 -333
  382. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  383. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  384. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  385. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  386. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  387. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  388. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  389. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  390. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  391. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  392. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  393. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  394. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  395. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  396. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  397. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  398. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  399. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  400. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  401. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  402. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  403. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  404. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  405. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  406. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  407. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  408. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  409. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  410. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  411. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  412. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  413. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  414. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  415. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  416. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  417. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  418. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  419. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  420. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  421. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  422. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  423. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  424. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  425. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  426. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  427. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  428. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  429. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  430. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  431. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
@@ -2,7 +2,6 @@ import { requiredValue } from "pi-agent-invariant";
2
2
  import path from "node:path";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import type { TextEditCompletion } from "#src/api/edit-completion.js";
5
- import { Value } from "typebox/value";
6
5
  import type {
7
6
  TextAnchorRecoveryCandidateRange,
8
7
  TextAnchorRecoveryRange,
@@ -47,7 +46,15 @@ import { readTextAnchorRecovery } from "#src/core/text-anchor-recovery.js";
47
46
  import { applyTextChanges, TextChangeDocument } from "#src/core/text-change-engine.js";
48
47
  import { resolvedTextAnchorType } from "#src/core/text-anchor-registry.js";
49
48
  import { executeTextToolWithBatch } from "#src/core/text-edit-batch-registrar.js";
50
- import { executeNativeTextEditBatch } from "#src/core/native-text-edit-batch.js";
49
+ import {
50
+ executeNativeTextEditBatch,
51
+ runNativePostEditScope,
52
+ recordNativeTextMutation,
53
+ } from "#src/core/native-text-edit-batch.js";
54
+ import { attachCommittedMutationTarget } from "./mutation-result-targets.js";
55
+ import { wholeFileResultSource } from "./result-input.js";
56
+ import { TEXT_SEARCH_ANCHOR_KIND } from "#src/api/plugin-protocol.js";
57
+ import { isResultInput, prepareResultTransfer } from "./result-transfer.js";
51
58
  import {
52
59
  contextualizeTextMutationAnchorError,
53
60
  TextMutationAnchorAggregateError,
@@ -75,16 +82,17 @@ import { renderTextAnchor, type TextAnchor } from "pi-agent-text";
75
82
  import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
76
83
  import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception";
77
84
  import type { Static, TSchema } from "typebox";
78
- import type { ScriptMutationOutcome } from "#src/core/apply/mutation-outcome.js";
79
85
  import { executeWholeFileTool, isWholeFileInvocation } from "#src/core/file-operation-tools.js";
80
86
  import { EDITING_GUIDELINES } from "#src/core/editing-guidelines.js";
81
- import { mutationOutputSchema, structuredMutation } from "./structured-result.js";
87
+ import { mutationResultSchema, structuredMutation } from "./structured-result.js";
88
+ import type { ResultTargetStore } from "pi-agent-resource";
82
89
 
83
90
  export function createTextTool<TParameters extends TSchema>(
84
91
  core: TextEditorCore,
85
92
  definition: TextMutationToolRegistration<TParameters>,
86
93
  annotations: ToolCallInterceptionRenderStore,
87
94
  getLastResolvedSource: () => string | undefined,
95
+ resultTargets?: ResultTargetStore,
88
96
  ): ToolDefinition<TParameters, FileMutationBatchResult> {
89
97
  const renderer = core.getToolRenderer(definition.name);
90
98
  const initialRenderCall = renderer?.renderCall;
@@ -110,7 +118,7 @@ export function createTextTool<TParameters extends TSchema>(
110
118
  promptGuidelines: [...EDITING_GUIDELINES, ...(definition.promptGuidelines ?? [])],
111
119
  description: definition.description,
112
120
  parameters: definition.parameters,
113
- outputSchema: mutationOutputSchema,
121
+ outputSchema: mutationResultSchema(definition.name),
114
122
  prepareArguments: (arguments_) =>
115
123
  // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
116
124
  prepareGuardedArguments(
@@ -133,73 +141,172 @@ export function createTextTool<TParameters extends TSchema>(
133
141
  ),
134
142
  }),
135
143
  async execute(toolCallId, parameters, signal, onUpdate, context) {
136
- const captured = await captureScriptMutation(core, async () => {
137
- const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
138
- const input = asMutationParameters<TParameters>(parameters);
139
- const queued = executeNativeTextEditBatch(
140
- core,
141
- toolCallId,
142
- definition,
143
- input,
144
- signal,
145
- context,
146
- );
147
- if (queued !== undefined) return queued;
148
- if (definition.direct?.matches(input) === true) {
149
- try {
150
- const action = await definition.direct.execute(
151
- { cwd: context.cwd, ...(signal !== undefined && { signal }) },
152
- input,
153
- );
154
- return {
155
- content: [{ type: "text", text: action.summary }],
156
- details: {
157
- results: [],
158
- metadata: { semanticAction: { ...action.data, source: action.source } },
159
- },
160
- };
161
- } catch (error) {
162
- const code =
163
- error !== null && typeof error === "object" && "code" in error
164
- ? String(error.code)
165
- : "DIRECT_MUTATION_FAILED";
166
- return failureToolResult(
167
- "transaction" in input ? String(input.transaction) : "",
168
- code,
169
- error instanceof Error ? error.message : String(error),
170
- "unknown",
171
- );
144
+ let plannedEdits: ReadonlyMap<string, TextMutationEdit> | undefined;
145
+ const captured = await runNativePostEditScope(core, toolCallId, () =>
146
+ captureScriptMutation(core, async () => {
147
+ const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
148
+ let input = asMutationParameters<TParameters>(parameters);
149
+ if (
150
+ ["replace", "write", "delete", "undo"].includes(definition.name) &&
151
+ isResultInput(input[definition.source.field])
152
+ ) {
153
+ try {
154
+ if (resultTargets === undefined)
155
+ throw new Error("Result targets are unavailable.");
156
+ if (input.start !== undefined || input.end !== undefined)
157
+ throw new Error("Do not combine result targets with start/end.");
158
+ const selected = resultTargets.resolve(
159
+ input[definition.source.field],
160
+ context.cwd,
161
+ );
162
+ if (!selected.complete)
163
+ throw new Error(
164
+ "Incomplete result targets cannot establish a complete edit; repeat Search.",
165
+ );
166
+ await resultTargets.verify(selected, signal);
167
+ if (definition.name === "write" || definition.name === "undo")
168
+ wholeFileResultSource(selected);
169
+ if (selected.targets.length === 0)
170
+ return {
171
+ content: [{ type: "text", text: "Empty result target set; no changes." }],
172
+ details: {
173
+ results: [],
174
+ effect: "not-applied",
175
+ metadata: { emptyTargets: true },
176
+ },
177
+ };
178
+ input = {
179
+ ...input,
180
+ [definition.source.field]: resultTargets.register(
181
+ selected.targets,
182
+ context.cwd,
183
+ selected.complete,
184
+ ),
185
+ };
186
+ } catch (error) {
187
+ signal?.throwIfAborted();
188
+ return failureToolResult(
189
+ "",
190
+ "RESULT_INPUT_REJECTED",
191
+ errorMessage(error),
192
+ "not-applied",
193
+ );
194
+ }
172
195
  }
173
- }
174
- if (
175
- isWholeFileInvocation(definition.wholeFileOperation, input) &&
176
- core.getSemanticMutationHandler(definition.name, input) === undefined
177
- ) {
178
- return executeWholeFileTool(
179
- core,
180
- definition.wholeFileOperation,
181
- input,
182
- signal,
183
- context,
184
- );
185
- }
186
- const directExecute = () =>
187
- executeTextMutation(
196
+ let executionDefinition = definition;
197
+ let verifyFileSource: (() => Promise<void>) | undefined;
198
+ if (
199
+ (definition.name === "copy" || definition.name === "move") &&
200
+ (isResultInput(input.path) || isResultInput(input.target))
201
+ ) {
202
+ try {
203
+ if (resultTargets === undefined)
204
+ throw new Error("Result targets are unavailable.");
205
+ const prepared = await prepareResultTransfer(
206
+ definition.name,
207
+ input,
208
+ resultTargets,
209
+ context.cwd,
210
+ signal,
211
+ );
212
+ input = asMutationParameters<TParameters>(prepared.input);
213
+ verifyFileSource = prepared.verifyFileSource;
214
+ if (prepared.empty)
215
+ return {
216
+ content: [{ type: "text", text: "Empty result target set; no changes." }],
217
+ details: {
218
+ results: [],
219
+ effect: "not-applied",
220
+ metadata: { emptyTargets: true },
221
+ },
222
+ };
223
+ if (prepared.mutate !== undefined)
224
+ executionDefinition = { ...definition, mutate: prepared.mutate };
225
+ } catch (error) {
226
+ signal?.throwIfAborted();
227
+ return failureToolResult(
228
+ "",
229
+ "RESULT_INPUT_REJECTED",
230
+ errorMessage(error),
231
+ "not-applied",
232
+ );
233
+ }
234
+ }
235
+ const directDefinition = executionDefinition;
236
+ executionDefinition = {
237
+ ...directDefinition,
238
+ mutate: async (mutationContext, arguments_) => {
239
+ const mutation = await directDefinition.mutate(mutationContext, arguments_);
240
+ plannedEdits = mutation.edits;
241
+ return mutation;
242
+ },
243
+ };
244
+ const queued = executeNativeTextEditBatch(
188
245
  core,
246
+ toolCallId,
189
247
  definition,
190
248
  input,
191
249
  signal,
192
250
  context,
193
- (field, state) =>
194
- annotations.resolveArguments(toolCallId, {
195
- [TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
196
- }),
197
- getLastResolvedSource(),
198
251
  );
199
- return executeTextToolWithBatch(toolCallId, directExecute, signal, onUpdate, context);
200
- };
201
- return execute();
202
- });
252
+ if (queued !== undefined) return queued;
253
+ if (definition.direct?.matches(input) === true) {
254
+ try {
255
+ const action = await definition.direct.execute(
256
+ { cwd: context.cwd, ...(signal !== undefined && { signal }) },
257
+ input,
258
+ );
259
+ return {
260
+ content: [{ type: "text", text: action.summary }],
261
+ details: {
262
+ results: [],
263
+ metadata: { semanticAction: { ...action.data, source: action.source } },
264
+ },
265
+ };
266
+ } catch (error) {
267
+ const code =
268
+ error !== null && typeof error === "object" && "code" in error
269
+ ? String(error.code)
270
+ : "DIRECT_MUTATION_FAILED";
271
+ return failureToolResult(
272
+ "transaction" in input ? String(input.transaction) : "",
273
+ code,
274
+ error instanceof Error ? error.message : String(error),
275
+ "unknown",
276
+ );
277
+ }
278
+ }
279
+ if (
280
+ isWholeFileInvocation(definition.wholeFileOperation, input) &&
281
+ core.getSemanticMutationHandler(definition.name, input) === undefined
282
+ ) {
283
+ return executeWholeFileTool(
284
+ core,
285
+ definition.wholeFileOperation,
286
+ input,
287
+ signal,
288
+ context,
289
+ verifyFileSource,
290
+ );
291
+ }
292
+ const directExecute = () =>
293
+ executeTextMutation(
294
+ core,
295
+ executionDefinition,
296
+ input,
297
+ signal,
298
+ context,
299
+ (field, state) =>
300
+ annotations.resolveArguments(toolCallId, {
301
+ [TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
302
+ }),
303
+ getLastResolvedSource(),
304
+ );
305
+ return executeTextToolWithBatch(toolCallId, directExecute, signal, onUpdate, context);
306
+ };
307
+ return execute();
308
+ }),
309
+ );
203
310
  if (captured.kind === "failed") {
204
311
  const failed = failureToolResult(
205
312
  "",
@@ -209,12 +316,23 @@ export function createTextTool<TParameters extends TSchema>(
209
316
  );
210
317
  return structuredMutation(failed, definition.name, captured.completions, toolCallId);
211
318
  }
212
- return structuredMutation(
213
- captured.value,
214
- definition.name,
215
- captured.completions,
216
- toolCallId,
217
- );
319
+ recordNativeTextMutation(core, toolCallId, captured.value);
320
+ const value =
321
+ resultTargets &&
322
+ ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
323
+ ? await attachCommittedMutationTarget(
324
+ captured.value,
325
+ captured.completions,
326
+ resultTargets,
327
+ toolCallId,
328
+ context.cwd,
329
+ signal,
330
+ definition.name === "write" || definition.name === "undo",
331
+ plannedEdits,
332
+ definition.name === "copy" || definition.name === "move",
333
+ )
334
+ : captured.value;
335
+ return structuredMutation(value, definition.name, captured.completions, toolCallId);
218
336
  },
219
337
  }),
220
338
  annotations,
@@ -225,7 +343,22 @@ export function createTextTool<TParameters extends TSchema>(
225
343
  return [
226
344
  definition.description,
227
345
  definition.intent !== "restore"
228
- ? "In native Codemode, local text edits share original snapshots and return acceptance before writing. Another tool, whole-file operation, or resource-owned selector ends the batch; script completion also commits it. Ordinary script errors keep accepted edits; aborts and deadlines discard pending edits."
346
+ ? "In native Codemode, local text edits share original snapshots and return acceptance before writing. Another tool, whole-file operation, or resource-owned selector commits the batch first; script completion also commits it. Formatting and registered resource post-edit handlers run at script end, not at flush or dependency boundaries. Earlier targets become stale if final processing changes bytes. Ordinary script errors keep accepted edits; aborts and deadlines discard pending edits."
347
+ : "",
348
+ (
349
+ {
350
+ replace:
351
+ "This result selects the resulting text; empty replacement selects the resulting position, not the removed text.",
352
+ insert: "This result selects the inserted text, including supplied line separators.",
353
+ write: "This result selects the whole written file, not only its changed span.",
354
+ copy: "This result selects only destination text; a whole-file copy selects the whole destination. The source is unchanged.",
355
+ move: "This result selects only destination text; a whole-file move selects the whole destination. Source removals never become output targets.",
356
+ delete: "Deletion reports file effects but provides no reusable text selection.",
357
+ undo: "This result selects whole restored text files, not only reversed spans. Deleted files provide no text selection.",
358
+ } as Record<string, string>
359
+ )[definition.name] ?? "",
360
+ ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
361
+ ? "Pass this unchanged result to another source tool for dependent work. Pending edits commit before the next tool consumes them. If the result reports no verified text selection, inspect the file instead."
229
362
  : "",
230
363
  definition.source.inherited
231
364
  ? definition.wholeFileOperation === undefined
@@ -318,7 +451,11 @@ async function resolveMutationSources(
318
451
  source: string,
319
452
  ): Promise<readonly TextTarget[] | undefined> => {
320
453
  try {
321
- return await core.resolveTextAnchorResources(value, allKinds, context);
454
+ return await core.resolveTextAnchorResources(
455
+ value,
456
+ value.startsWith("RESULT#") ? [...allKinds, TEXT_SEARCH_ANCHOR_KIND] : allKinds,
457
+ context,
458
+ );
322
459
  } catch (error) {
323
460
  throw contextualizeTextMutationAnchorError(error, definition.name, field, source, value);
324
461
  }
@@ -415,6 +552,7 @@ async function resolveMutationSources(
415
552
  if (
416
553
  targets !== undefined &&
417
554
  hasImplicitSourceSelection &&
555
+ definition.name !== "undo" &&
418
556
  descriptor.field === firstAnchor?.field
419
557
  ) {
420
558
  implicitTargets.set(descriptor.field, targets);
@@ -1038,140 +1176,6 @@ export async function captureScriptMutation<T>(core: TextEditorCore, action: ()
1038
1176
  unsubscribe();
1039
1177
  }
1040
1178
  }
1041
- /**
1042
- * Runs the configured mutation pipeline and returns plain script data.
1043
- * onPresentation retains rich edit annotations on the host without sending classes to the guest.
1044
- */
1045
- export async function executeScriptMutation<TParameters extends TSchema>(
1046
- core: TextEditorCore,
1047
- definition: TextMutationToolRegistration<TParameters>,
1048
- arguments_: unknown,
1049
- signal: AbortSignal | undefined,
1050
- context: ExtensionContext,
1051
- lastResolvedSource?: string,
1052
- onPresentation?: (source: string, result: FileMutationResult) => void,
1053
- ): Promise<ScriptMutationOutcome> {
1054
- const parameters = prepareGuardedArguments(
1055
- definition.parameters,
1056
- arguments_,
1057
- definition.source.inherited ? definition.source.field : undefined,
1058
- lastResolvedSource,
1059
- definition.anchors ?? [],
1060
- definition.wholeFileOperation !== undefined,
1061
- );
1062
- if (!Value.Check(definition.parameters, parameters)) {
1063
- throw Object.assign(new Error(`Invalid arguments for ${definition.name}`), {
1064
- code: "INVALID_ARGUMENTS",
1065
- details: { operation: definition.name, effect: "not-applied" },
1066
- });
1067
- }
1068
- const captured = await captureScriptMutation(core, () =>
1069
- executeTextMutationPipeline(
1070
- core,
1071
- definition,
1072
- parameters,
1073
- signal,
1074
- context,
1075
- undefined,
1076
- lastResolvedSource,
1077
- ),
1078
- );
1079
- const source =
1080
- captured.kind === "completed" ? captured.value.source : mutationSource(definition, parameters);
1081
- const observedFiles: ScriptMutationOutcome["files"] = captured.completions.map((completion) => ({
1082
- source: completion.resourceSource,
1083
- before: completion.existed ? completion.before.content : null,
1084
- after: completion.after.content,
1085
- action: definition.name === "write" ? "overwritten" : "edited",
1086
- changes: [],
1087
- formatting: { status: "not-reported" },
1088
- }));
1089
- const failed = (
1090
- code: string,
1091
- message: string,
1092
- effect: ScriptMutationOutcome["effect"],
1093
- completed: readonly string[] = [],
1094
- ): ScriptMutationOutcome => ({
1095
- operation: definition.name,
1096
- ok: false,
1097
- effect: effect === "unknown" ? "unknown" : observedFiles.length > 0 ? "applied" : effect,
1098
- completed: [...new Set([...completed, ...observedFiles.map((file) => file.source)])],
1099
- files: observedFiles,
1100
- errors: [{ source, code, message }],
1101
- });
1102
- if (captured.kind === "failed")
1103
- return failed("EXECUTION_FAILED", errorMessage(captured.error), "unknown");
1104
- const { pipeline } = captured.value;
1105
- if (pipeline.kind === "failed")
1106
- return {
1107
- ...failed(pipeline.failure.code, pipeline.failure.message, "not-applied"),
1108
- recoveries: await scriptAnchorRecoveries(pipeline.failure.cause),
1109
- };
1110
- const outcome = pipeline.state.result;
1111
- if (!isResourcesEditOutcome(outcome))
1112
- return failed("INVALID_RESULT", "Invalid mutation outcome", "unknown");
1113
- if (outcome.kind === "failed")
1114
- return {
1115
- ...failed(
1116
- outcome.failure.code,
1117
- outcome.failure.message,
1118
- outcome.completed.length > 0 ? "unknown" : "not-applied",
1119
- outcome.completed,
1120
- ),
1121
- recoveries: await scriptAnchorRecoveries(outcome.failure.cause),
1122
- };
1123
- const mutation = outcome.result as ExecutedTextMutation;
1124
- if (mutation.semanticAction !== undefined) {
1125
- return {
1126
- operation: definition.name,
1127
- ok: true,
1128
- effect: "applied",
1129
- files: [],
1130
- completed: [mutation.semanticAction.source],
1131
- metadata: {
1132
- semanticAction: {
1133
- ...mutation.semanticAction.data,
1134
- source: mutation.semanticAction.source,
1135
- },
1136
- },
1137
- errors: [],
1138
- };
1139
- }
1140
- const files = outcome.resources.flatMap((resource) => {
1141
- const edit = mutation.edits.get(resource.source);
1142
- if (edit === undefined) return [];
1143
- const presentation = withPipelineStatuses(
1144
- buildSuccessfulTextMutationResult(resource, resource.source, edit),
1145
- pipeline.state.metadata,
1146
- );
1147
- onPresentation?.(resource.after.source, presentation);
1148
- const data = presentation.data;
1149
- return [
1150
- {
1151
- source: resource.after.source,
1152
- before:
1153
- captured.completions.find(
1154
- (completion) => completion.resourceSource === resource.after.source,
1155
- )?.existed === false
1156
- ? null
1157
- : resource.before.content,
1158
- after: resource.after.content,
1159
- action: edit.action,
1160
- changes: data.rawChanges ?? [],
1161
- formatting: data.formatting ?? { status: "not-reported" as const },
1162
- },
1163
- ];
1164
- });
1165
- return {
1166
- operation: definition.name,
1167
- ok: true,
1168
- effect: files.length > 0 ? "applied" : "not-applied",
1169
- files,
1170
- completed: files.map((file) => file.source),
1171
- ...(pipeline.state.metadata !== undefined && { metadata: pipeline.state.metadata }),
1172
- errors: [],
1173
- };
1174
- }
1175
1179
  export function mutationSources(
1176
1180
  definition: TextMutationToolRegistration,
1177
1181
  parameters: Readonly<Record<string, unknown>>,
@@ -1386,24 +1390,6 @@ async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
1386
1390
  return error.resolution.recovery;
1387
1391
  }
1388
1392
 
1389
- async function scriptAnchorRecoveries(
1390
- cause: unknown,
1391
- ): Promise<NonNullable<ScriptMutationOutcome["recoveries"]>> {
1392
- if (cause instanceof TextMutationAnchorAggregateError)
1393
- return (await Promise.all(cause.failures.map(scriptAnchorRecoveries))).flat();
1394
- if (!(cause instanceof TextMutationAnchorResolutionError)) return [];
1395
- const recovery = await resolveAnchorRecovery(cause);
1396
- return [
1397
- {
1398
- path: cause.source,
1399
- field: cause.field,
1400
- anchor: cause.anchor,
1401
- status: recovery?.kind ?? "unavailable",
1402
- candidates: recovery?.kind === "candidates" ? recovery.candidates : [],
1403
- total: recovery?.kind === "candidates" ? recovery.total : 0,
1404
- },
1405
- ];
1406
- }
1407
1393
  async function anchorFailureToolResult(
1408
1394
  core: TextEditorCore,
1409
1395
  failure: TextResourceEditFailure,
@@ -1418,12 +1404,18 @@ async function anchorFailureToolResult(
1418
1404
  const results: FileMutationResult[] = [];
1419
1405
  const anchorRecoveries: NonNullable<FileMutationBatchResult["anchorRecoveries"]>[number][] = [];
1420
1406
  const messages: string[] = [];
1407
+ const exactTextFailures: string[] = [];
1421
1408
  for (const item of recovered) {
1422
1409
  if (item === undefined) {
1423
1410
  continue;
1424
1411
  }
1425
1412
  results.push(...(item.details.results ?? []));
1426
1413
  anchorRecoveries.push(...(item.details.anchorRecoveries ?? []));
1414
+ const failed = item.details.metadata?.exactTextFailures;
1415
+ if (Array.isArray(failed))
1416
+ exactTextFailures.push(
1417
+ ...failed.filter((source): source is string => typeof source === "string"),
1418
+ );
1427
1419
  for (const block of item.content) {
1428
1420
  if (block.type === "text") {
1429
1421
  messages.push(block.text);
@@ -1435,7 +1427,12 @@ async function anchorFailureToolResult(
1435
1427
  }
1436
1428
  return {
1437
1429
  content: [{ type: "text", text: messages.join("\n\n") }],
1438
- details: { results, anchorRecoveries, effect: "not-applied" },
1430
+ details: {
1431
+ results,
1432
+ anchorRecoveries,
1433
+ effect: "not-applied",
1434
+ metadata: { exactTextFailures },
1435
+ },
1439
1436
  };
1440
1437
  }
1441
1438
  if (!(failure.cause instanceof TextMutationAnchorResolutionError)) {
@@ -1444,15 +1441,10 @@ async function anchorFailureToolResult(
1444
1441
 
1445
1442
  const contextual = failure.cause;
1446
1443
  const resolution = contextual.resolution;
1447
- const recovery = await resolveAnchorRecovery(contextual);
1448
- if (recovery?.kind === "timed-out") {
1449
- return failureToolResult(
1450
- contextual.source,
1451
- failure.code,
1452
- `${failure.message}; recovery timed out`,
1453
- "not-applied",
1454
- );
1455
- }
1444
+ const recovery = await resolveAnchorRecovery(contextual).catch(() => {
1445
+ context.signal?.throwIfAborted();
1446
+ return undefined;
1447
+ });
1456
1448
 
1457
1449
  const windows =
1458
1450
  recovery?.kind === "candidates"
@@ -1463,9 +1455,7 @@ async function anchorFailureToolResult(
1463
1455
  : resolution.rejection?.contextRange === undefined
1464
1456
  ? []
1465
1457
  : [resolution.rejection.contextRange];
1466
- if (windows.length === 0) {
1467
- return undefined;
1468
- }
1458
+ if (windows.length === 0) windows.push({ offset: 1, limit: 40 });
1469
1459
 
1470
1460
  const reads = await Promise.all(
1471
1461
  windows.map((range) =>
@@ -1476,14 +1466,15 @@ async function anchorFailureToolResult(
1476
1466
  cwd: context.cwd,
1477
1467
  ...(context.signal !== undefined && { signal: context.signal }),
1478
1468
  },
1479
- ),
1469
+ )?.catch(() => {
1470
+ context.signal?.throwIfAborted();
1471
+ return undefined;
1472
+ }),
1480
1473
  ),
1481
1474
  );
1482
1475
  const recoveryTexts: string[] = [];
1483
1476
  for (const read of reads) {
1484
- if (read === undefined || read.isError === true) {
1485
- return undefined;
1486
- }
1477
+ if (read === undefined || read.isError === true) continue;
1487
1478
  recoveryTexts.push(
1488
1479
  ...read.content.filter((block) => block.type === "text").map((block) => block.text),
1489
1480
  );
@@ -1524,6 +1515,9 @@ async function anchorFailureToolResult(
1524
1515
  results: [result],
1525
1516
  effect: "not-applied",
1526
1517
  anchorRecovery: true,
1518
+ ...(resolution.resolverId === "exact-text" && {
1519
+ metadata: { exactTextFailures: [contextual.source] },
1520
+ }),
1527
1521
  ...(recovery?.kind === "candidates" && {
1528
1522
  anchorRecoveries: [
1529
1523
  {
@@ -1554,8 +1548,8 @@ function formatRejectedAnchorMessage(
1554
1548
  ? "is invalid"
1555
1549
  : "could not be resolved";
1556
1550
  const guidance =
1557
- code === "ambiguous"
1558
- ? "Use a unique text span or one of the candidate anchors below."
1551
+ failure.resolution.resolverId === "exact-text"
1552
+ ? "Exact-text editing is now blocked for this file until an anchor-based edit succeeds. Find the intended location among the current anchors below, or use Read/Search for another section, and use its anchor. After that edit, exact text is available again."
1559
1553
  : "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
1560
1554
  const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
1561
1555
  return `[SYSTEM] ${failure.toolName} blocked: ${failure.field} anchor "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
@@ -303,7 +303,7 @@ class InterceptorImpl implements ToolCallInterceptor {
303
303
  content: guardResult.content,
304
304
  details,
305
305
  },
306
- mutationDataSchema,
306
+ mutationDataSchema(event.toolName),
307
307
  {
308
308
  status: "error",
309
309
  errors: [resultError(message, "INTERCEPTED")],