pi-agent-ide 0.6.4 → 0.7.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 (395) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/{chunk-QEJGED4V.js → chunk-3HYXQ4YA.js} +1 -1
  5. package/dist/chunk-3JO7QFIL.js +1 -0
  6. package/dist/{chunk-5J43L2RL.js → chunk-4NIFBFFR.js} +1 -1
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  9. package/dist/chunk-7LZKOHH2.js +1 -0
  10. package/dist/chunk-AJRIASPQ.js +2 -0
  11. package/dist/chunk-EAZGN5ND.js +7 -0
  12. package/dist/{chunk-GIRAEVUJ.js → chunk-F5YZG77W.js} +1 -1
  13. package/dist/chunk-FK42RSF4.js +1 -0
  14. package/dist/{chunk-WJTHY6AG.js → chunk-FXNKMNSJ.js} +1 -1
  15. package/dist/chunk-GBLKIB6O.js +2 -0
  16. package/dist/{chunk-KUPHNMUK.js → chunk-KBP3QUDT.js} +1 -1
  17. package/dist/{chunk-VBICI5YA.js → chunk-KR36BT5E.js} +1 -1
  18. package/dist/chunk-OE7QVAI2.js +5 -0
  19. package/dist/chunk-PNU3E7IO.js +3 -0
  20. package/dist/chunk-PS2B6THP.js +3 -0
  21. package/dist/{chunk-HPUAIWIH.js → chunk-PYPPV2F5.js} +1 -1
  22. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  23. package/dist/chunk-S5LXX32D.js +28 -0
  24. package/dist/chunk-SQKAXYIR.js +2 -0
  25. package/dist/chunk-VCGNVTXQ.js +1 -0
  26. package/dist/chunk-XYS4FSCC.js +12 -0
  27. package/dist/{chunk-FBOW7XOV.js → chunk-YRF7OATP.js} +1 -1
  28. package/dist/entry-11.js +1 -1
  29. package/dist/entry-13.js +1 -1
  30. package/dist/entry-14.js +1 -1
  31. package/dist/entry-15.js +1 -1
  32. package/dist/entry-17.js +1 -1
  33. package/dist/entry-25.js +1 -1
  34. package/dist/entry-26.js +1 -1
  35. package/dist/entry-28.js +1 -1
  36. package/dist/entry-29.js +1 -1
  37. package/dist/entry-30.js +1 -1
  38. package/dist/entry-31.js +13 -11
  39. package/dist/entry-33.js +1 -1
  40. package/dist/entry-37.js +6 -6
  41. package/dist/entry-42.js +1 -1
  42. package/dist/entry-44.js +1 -1
  43. package/dist/entry-45.js +13 -13
  44. package/dist/entry-46.js +1 -1
  45. package/dist/entry-49.js +1 -1
  46. package/dist/entry-50.js +3 -6
  47. package/dist/entry-51.js +11 -9
  48. package/dist/entry-52.js +1 -1
  49. package/dist/entry-53.js +1 -1
  50. package/dist/entry-54.js +1 -1
  51. package/dist/entry-56.js +1 -1
  52. package/dist/entry-58.js +1 -1
  53. package/dist/entry-60.js +1 -1
  54. package/dist/entry-61.js +0 -1
  55. package/dist/entry-62.js +1 -0
  56. package/dist/entry-63.js +0 -1
  57. package/dist/entry-64.js +1 -0
  58. package/dist/entry-65.js +1 -1
  59. package/dist/entry-66.js +1 -1
  60. package/dist/entry-67.js +1 -1
  61. package/dist/entry-68.js +1 -1
  62. package/dist/entry-69.js +1 -1
  63. package/dist/entry-70.js +1 -1
  64. package/dist/entry-71.js +0 -1
  65. package/dist/entry-72.js +1 -0
  66. package/dist/entry-73.js +0 -1
  67. package/dist/entry-74.js +1 -0
  68. package/dist/entry-75.js +1 -1
  69. package/dist/entry-76.js +1 -1
  70. package/dist/entry-77.js +67 -1
  71. package/dist/entry-78.js +14 -325
  72. package/dist/entry-79.js +2 -18
  73. package/dist/entry-80.js +1 -2
  74. package/dist/entry-81.js +1 -1
  75. package/dist/entry-82.js +5 -1
  76. package/dist/entry-83.js +3 -5
  77. package/dist/entry-84.js +1 -3
  78. package/dist/entry-85.js +1 -1
  79. package/dist/entry-86.js +1 -1
  80. package/dist/pi-agent-ide.js +5 -5
  81. package/docs/agent-guides/editing.md +20 -4
  82. package/docs/agent-guides/git-changes.md +1 -1
  83. package/docs/agent-guides/read-resources.md +9 -1
  84. package/docs/agent-guides/search-code.md +38 -1
  85. package/docs/agent-guides/select-code.md +194 -0
  86. package/docs/configuration.md +12 -17
  87. package/docs/development.md +2 -1
  88. package/docs/releases.md +1 -1
  89. package/docs/research/apply-native-capability-matrix.md +174 -0
  90. package/docs/research/apply-read-latency.md +2 -0
  91. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  92. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  93. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  94. package/docs/research/native-codemode-batch-decision.md +2 -0
  95. package/docs/research/native-codemode-batching.md +1 -1
  96. package/docs/structured-results.md +32 -5
  97. package/docs/tools.md +6 -2
  98. package/docs/user-hooks.md +1 -1
  99. package/node_modules/pi-agent-doctor/package.json +1 -1
  100. package/node_modules/pi-agent-documentation/package.json +1 -1
  101. package/node_modules/pi-agent-filesystem/package.json +7 -7
  102. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  103. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  104. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  105. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  106. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  107. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  108. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  109. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  110. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  111. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  112. package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -2
  113. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  114. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +107 -21
  115. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  116. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  117. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  118. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  119. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  120. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +251 -0
  121. package/node_modules/pi-agent-ide-changes/index.ts +2 -18
  122. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  123. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  124. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  125. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  126. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  127. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  128. package/node_modules/pi-agent-ide-lsp/index.ts +2 -2
  129. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  130. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  131. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  132. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  133. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  134. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  135. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
  136. package/node_modules/pi-agent-image/package.json +2 -2
  137. package/node_modules/pi-agent-invariant/package.json +1 -1
  138. package/node_modules/pi-agent-pdf/package.json +2 -2
  139. package/node_modules/pi-agent-read/package.json +7 -7
  140. package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
  141. package/node_modules/pi-agent-read/src/api/tools/read.ts +4 -0
  142. package/node_modules/pi-agent-read/src/core/extension.ts +11 -0
  143. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  144. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
  145. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +8 -1
  146. package/node_modules/pi-agent-resource/package.json +1 -1
  147. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  148. package/node_modules/pi-agent-resource/src/result-targets.ts +233 -0
  149. package/node_modules/pi-agent-search/package.json +5 -5
  150. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  151. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  152. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  153. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  154. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  155. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  156. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  157. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  158. package/node_modules/pi-agent-search-text/index.ts +3 -1
  159. package/node_modules/pi-agent-search-text/package.json +7 -6
  160. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  161. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  162. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  163. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  164. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  165. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  166. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  167. package/node_modules/pi-agent-text/package.json +2 -2
  168. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  169. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  170. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  171. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  172. package/node_modules/pi-agent-text-editor/package.json +26 -31
  173. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  174. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  175. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  176. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  177. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  178. package/node_modules/pi-agent-text-editor/src/core/extension.ts +12 -2
  179. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  180. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +1 -1
  181. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  182. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  183. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  184. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
  185. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  186. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  187. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  188. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +109 -11
  189. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  190. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  191. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
  192. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  195. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  196. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  197. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  198. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  199. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  200. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  201. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  202. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  203. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  204. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  205. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  206. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  207. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  208. package/node_modules/pi-agent-web/index.ts +3 -0
  209. package/node_modules/pi-agent-web/package.json +8 -8
  210. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  211. package/node_modules/pi-agent-web/src/search.ts +111 -2
  212. package/node_modules/pi-agent-web-html/package.json +3 -3
  213. package/node_modules/pi-agent-web-image/package.json +4 -4
  214. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  215. package/node_modules/pi-agent-web-text/package.json +4 -4
  216. package/package.json +35 -36
  217. package/src/composite/module-labels.ts +1 -1
  218. package/src/composite/preferences.ts +0 -5
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +3 -0
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  230. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  231. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  232. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  233. package/src/extensions/pi-agent-read/package.json +7 -7
  234. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
  235. package/src/extensions/pi-agent-read/src/api/tools/read.ts +4 -0
  236. package/src/extensions/pi-agent-read/src/core/extension.ts +11 -0
  237. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  238. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
  239. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +8 -1
  240. package/src/extensions/pi-agent-search/package.json +5 -5
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  245. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  246. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  247. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  248. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  249. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  250. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  251. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  252. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  253. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  254. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  255. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  256. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  257. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  258. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  259. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  268. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  269. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  270. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  271. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  272. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  273. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  274. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +12 -2
  275. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  276. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +1 -1
  277. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  278. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  279. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  280. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
  281. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  282. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  283. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  284. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +109 -11
  285. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  286. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  287. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
  288. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
  289. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  290. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  291. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  292. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  293. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  294. package/src/pi-agent-ide.ts +0 -6
  295. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  296. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  297. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  298. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  299. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  300. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  301. package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -2
  302. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  303. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +107 -21
  304. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  305. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  306. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  307. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  308. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  309. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +251 -0
  310. package/src/plugins/pi-agent-ide-changes/index.ts +2 -18
  311. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  312. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  313. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  314. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  315. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  316. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  317. package/src/plugins/pi-agent-ide-lsp/index.ts +2 -2
  318. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  319. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  320. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  321. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  322. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  323. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  324. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
  325. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  326. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  327. package/src/plugins/pi-agent-ide-vision/index.ts +19 -0
  328. package/dist/chunk-2P2OGO3G.js +0 -2
  329. package/dist/chunk-6EYWFBNG.js +0 -0
  330. package/dist/chunk-7AVXUV4A.js +0 -7
  331. package/dist/chunk-7WCZOO5I.js +0 -1
  332. package/dist/chunk-BAYETTZZ.js +0 -16
  333. package/dist/chunk-BVK5A7ED.js +0 -28
  334. package/dist/chunk-F7NVAC4Q.js +0 -0
  335. package/dist/chunk-FZBCKIJJ.js +0 -1
  336. package/dist/chunk-I5JLCFUX.js +0 -1
  337. package/dist/chunk-MIZAFRDR.js +0 -1
  338. package/dist/chunk-PJPA5EEE.js +0 -2
  339. package/dist/chunk-PXWDDBBC.js +0 -0
  340. package/dist/chunk-TQZBVOTT.js +0 -5
  341. package/dist/chunk-VWW3RLUX.js +0 -12
  342. package/dist/chunk-YHUTTZC6.js +0 -2
  343. package/dist/chunk-ZODCBFBL.js +0 -2
  344. package/dist/entry-87.js +0 -1
  345. package/docs/agent-guides/apply.md +0 -333
  346. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  347. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  348. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  349. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  350. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  351. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  352. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  353. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  354. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  355. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  356. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  357. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  358. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  359. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  360. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  361. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  362. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  363. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  364. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  365. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  366. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  367. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  368. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  369. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  370. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  371. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  372. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  373. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  374. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  375. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  376. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  377. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  378. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  379. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  380. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  381. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  382. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  383. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  384. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  385. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  386. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  387. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  388. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  389. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  390. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  391. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  392. /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
  393. /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
  394. /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
  395. /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
87
  import { mutationOutputSchema, 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;
@@ -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,24 @@ 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
+ "Local data.target selects this call's resulting text; empty replacement selects the resulting position, not the removed text.",
352
+ insert:
353
+ "Local data.target selects this call's inserted text, including supplied line separators.",
354
+ write: "Local data.target selects the whole written file, not only its changed span.",
355
+ copy: "Local data.target selects only the destination text; a whole-file copy selects the whole destination. The source is unchanged.",
356
+ move: "Local data.target selects only the destination text; a whole-file move selects the whole destination. Source removals never become output targets.",
357
+ delete:
358
+ "Deletion returns a change record and file state, never a live target or an empty-position target.",
359
+ undo: "Local data.target selects whole restored text files, not only reversed spans. Restored absence is reported in files[].state without a live target.",
360
+ } as Record<string, string>
361
+ )[definition.name] ?? "",
362
+ ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
363
+ ? "A pending data.target requires confirmed writing. Successful changes without a verified text mapping expose data.targetUnavailable; inspect effects separately."
229
364
  : "",
230
365
  definition.source.inherited
231
366
  ? definition.wholeFileOperation === undefined
@@ -318,7 +453,11 @@ async function resolveMutationSources(
318
453
  source: string,
319
454
  ): Promise<readonly TextTarget[] | undefined> => {
320
455
  try {
321
- return await core.resolveTextAnchorResources(value, allKinds, context);
456
+ return await core.resolveTextAnchorResources(
457
+ value,
458
+ value.startsWith("RESULT#") ? [...allKinds, TEXT_SEARCH_ANCHOR_KIND] : allKinds,
459
+ context,
460
+ );
322
461
  } catch (error) {
323
462
  throw contextualizeTextMutationAnchorError(error, definition.name, field, source, value);
324
463
  }
@@ -415,6 +554,7 @@ async function resolveMutationSources(
415
554
  if (
416
555
  targets !== undefined &&
417
556
  hasImplicitSourceSelection &&
557
+ definition.name !== "undo" &&
418
558
  descriptor.field === firstAnchor?.field
419
559
  ) {
420
560
  implicitTargets.set(descriptor.field, targets);
@@ -1038,140 +1178,6 @@ export async function captureScriptMutation<T>(core: TextEditorCore, action: ()
1038
1178
  unsubscribe();
1039
1179
  }
1040
1180
  }
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
1181
  export function mutationSources(
1176
1182
  definition: TextMutationToolRegistration,
1177
1183
  parameters: Readonly<Record<string, unknown>>,
@@ -1386,24 +1392,6 @@ async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
1386
1392
  return error.resolution.recovery;
1387
1393
  }
1388
1394
 
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
1395
  async function anchorFailureToolResult(
1408
1396
  core: TextEditorCore,
1409
1397
  failure: TextResourceEditFailure,
@@ -1,4 +1,10 @@
1
1
  import { Type } from "typebox";
2
+ import { resultInputSchema } from "pi-agent-resource";
3
+
4
+ /** Build a structured source selector without changing legacy path semantics. */
5
+ export function resultSourceProperty(description: string) {
6
+ return Type.Optional({ ...resultInputSchema, description });
7
+ }
2
8
 
3
9
  /** Build the source selector shared by text mutation schemas. */
4
10
  export function sourcePathProperty(description: string) {
@@ -26,16 +32,13 @@ export function sourceRangeProperties() {
26
32
  /** Build the destination selectors shared by copy and move schemas. */
27
33
  export function targetProperties() {
28
34
  return {
29
- target: Type.Optional(
30
- Type.String({
31
- description:
32
- "Target resource reference or file path. Required for a whole-file operation; defaults to the source for selected text.",
33
- }),
35
+ target: resultSourceProperty(
36
+ "Destination file path or source result. A structured result replaces its exact ranges (zero-width ranges insert); omit targetStart/targetEnd. Source and destination selections pair in declared order with equal counts. A string target keeps its existing anchor semantics.",
34
37
  ),
35
38
  targetStart: Type.Optional(
36
39
  Type.String({
37
40
  description:
38
- "Registered anchor or unique exact text in the destination. Required unless target already selects one destination range. Without targetEnd, inserts after the last containing line, keeping the selected text. With targetEnd, replacement starts at the first containing line. SEARCH :match also uses these line boundaries.",
41
+ "Registered anchor or unique exact text in the destination. Required for text transfers with a string target; omit for whole-file transfers or a structured target. Without targetEnd, inserts after the last containing line, keeping the selected text. With targetEnd, replacement starts at the first containing line. SEARCH :match also uses these line boundaries.",
39
42
  }),
40
43
  ),
41
44
  targetEnd: Type.Optional(
@@ -1,7 +1,7 @@
1
1
  import { Type } from "typebox";
2
2
 
3
3
  import {
4
- sourcePathProperty,
4
+ resultSourceProperty,
5
5
  sourceRangeProperties,
6
6
  targetProperties,
7
7
  } from "#src/tools/text-tool-schema-properties.js";
@@ -17,8 +17,8 @@ import type { TextMutationToolRegistration } from "#src/api/mutation-tool.js";
17
17
 
18
18
  export const copySchema = Type.Object(
19
19
  {
20
- path: sourcePathProperty(
21
- "Source file path, or a returned SEARCH# reference selecting the text to copy",
20
+ path: resultSourceProperty(
21
+ "Source file path or structured source selection; omit start/end for structured inputs. Use one whole-file result when target is a string without text selectors. Structured source/destination selections pair in declared order, with equal counts and duplicate ranges removed.",
22
22
  ),
23
23
  ...sourceRangeProperties(),
24
24
  ...targetProperties(),
@@ -26,10 +26,10 @@ export const copySchema = Type.Object(
26
26
  { additionalProperties: false },
27
27
  );
28
28
  interface CopyParameters {
29
- readonly path?: string;
29
+ readonly path?: unknown;
30
30
  readonly start?: string;
31
31
  readonly end?: string;
32
- readonly target?: string;
32
+ readonly target?: unknown;
33
33
  readonly targetStart?: string;
34
34
  readonly targetEnd?: string;
35
35
  }
@@ -1,7 +1,7 @@
1
1
  import { Type } from "typebox";
2
2
 
3
3
  import {
4
- sourcePathProperty,
4
+ resultSourceProperty,
5
5
  sourceRangeProperties,
6
6
  } from "#src/tools/text-tool-schema-properties.js";
7
7
 
@@ -17,15 +17,15 @@ import type { TextMutationToolRegistration } from "#src/api/mutation-tool.js";
17
17
 
18
18
  export const deleteSchema = Type.Object(
19
19
  {
20
- path: sourcePathProperty(
21
- "Source resource reference or file path. A returned SEARCH# reference can select deletion ranges.",
20
+ path: resultSourceProperty(
21
+ "File path or structured source selection. A structured input deletes only its exact text ranges, even if it selects a whole file; omit start/end.",
22
22
  ),
23
23
  ...sourceRangeProperties(),
24
24
  },
25
25
  { additionalProperties: false },
26
26
  );
27
27
  interface DeleteParameters {
28
- readonly path?: string;
28
+ readonly path?: unknown;
29
29
  readonly start?: string;
30
30
  readonly end?: string;
31
31
  }
@@ -34,7 +34,7 @@ export const deleteMutationTool: TextMutationToolRegistration<typeof deleteSchem
34
34
  name: "delete",
35
35
  wholeFileOperation: "delete",
36
36
  description:
37
- "Use delete to permanently delete one regular file when path is supplied without text selectors, or to remove selected text. Whole-file deletion rejects directories and symlinks.",
37
+ "Use delete to permanently delete one regular file when an ordinary string path is supplied without text selectors, or to remove selected text. Structured path removes only its text ranges and keeps the file, even for a whole-file selection. Whole-file deletion rejects directories and symlinks.",
38
38
 
39
39
  promptSnippet: "Delete regular files, or delete selected text using exact matches or anchors",
40
40
  parameters: deleteSchema,
@@ -1,7 +1,7 @@
1
1
  import { Type } from "typebox";
2
2
 
3
3
  import {
4
- sourcePathProperty,
4
+ resultSourceProperty,
5
5
  sourceRangeProperties,
6
6
  targetProperties,
7
7
  } from "#src/tools/text-tool-schema-properties.js";
@@ -19,8 +19,8 @@ import type { TextChange } from "#src/core/text-change-engine.js";
19
19
 
20
20
  export const moveSchema = Type.Object(
21
21
  {
22
- path: sourcePathProperty(
23
- "Source file path, or a returned SEARCH# reference selecting the text to move",
22
+ path: resultSourceProperty(
23
+ "Source file path or structured source selection; omit start/end for structured inputs. Use one whole-file result when target is a string without text selectors. Structured source/destination selections pair in declared order, with equal counts and duplicate ranges removed. Destinations must not overlap or touch source ranges.",
24
24
  ),
25
25
  ...sourceRangeProperties(),
26
26
  ...targetProperties(),
@@ -28,10 +28,10 @@ export const moveSchema = Type.Object(
28
28
  { additionalProperties: false },
29
29
  );
30
30
  interface MoveParameters {
31
- readonly path?: string;
31
+ readonly path?: unknown;
32
32
  readonly start?: string;
33
33
  readonly end?: string;
34
- readonly target?: string;
34
+ readonly target?: unknown;
35
35
  readonly targetStart?: string;
36
36
  readonly targetEnd?: string;
37
37
  }
@@ -101,13 +101,15 @@ export const moveMutationTool: TextMutationToolRegistration<typeof moveSchema> =
101
101
 
102
102
  if (sourceSpan.source === target) {
103
103
  return {
104
- edits: new Map([[target, { changes: [deletion, targetChange], action: "edited" }]]),
104
+ edits: new Map([
105
+ [target, { changes: [deletion, targetChange], action: "edited", resultChanges: [1] }],
106
+ ]),
105
107
  };
106
108
  }
107
109
 
108
110
  return {
109
111
  edits: new Map([
110
- [sourceSpan.source, { changes: [deletion], action: "edited" }],
112
+ [sourceSpan.source, { changes: [deletion], action: "edited", resultChanges: [] }],
111
113
  [target, { changes: [targetChange], action: "edited" }],
112
114
  ]),
113
115
  };