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
@@ -11,6 +11,7 @@ import { getLastResolvedResource } from "#src/api/last-resolved-resource.js";
11
11
  import { isMutationAnchorValue } from "#src/api/mutation-tool.js";
12
12
  import type { FileMutationBatchResult, FileMutationResult } from "#src/api/mutation-result.js";
13
13
  import type { TextBatchEntry } from "./text-edit-batch.js";
14
+ import type { TextEditCompletion } from "#src/api/edit-completion.js";
14
15
  import type { TextEditorCore, TextResourceEditRequest } from "./text-editor-core.js";
15
16
  import { BatchExecutionJournal } from "./text-edit-batch-execution.js";
16
17
  import {
@@ -25,10 +26,16 @@ import { Type } from "typebox";
25
26
  import {
26
27
  ResourceScheduler,
27
28
  resourceAccesses,
29
+ connectResultTargets,
28
30
  resultError,
29
31
  withStructuredResult,
32
+ type ResultTargetStore,
30
33
  type StructuredResult,
31
34
  } from "pi-agent-resource";
35
+ import { createPostEditScope } from "./post-edit-scope.js";
36
+ import { committedMutationTargets } from "./mutation-result-targets.js";
37
+ import { FileMutationResult as MutationPresentation } from "./mutation-result/file-mutation-result.js";
38
+ import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
32
39
  import { captureScriptMutation } from "./text-mutation.js";
33
40
  import {
34
41
  NATIVE_EDIT_BATCH_EVENT,
@@ -61,8 +68,11 @@ interface ScriptBatch {
61
68
  readonly context: ExtensionContext;
62
69
  readonly summaries: BatchSummary[];
63
70
  readonly results: FileMutationResult[];
71
+ readonly presentations: NativeEditBatchEvent[];
64
72
  readonly errors: string[];
65
73
  readonly cancellation: AbortController;
74
+ readonly targets: Map<string, string>;
75
+ readonly postEdits: ReturnType<typeof createPostEditScope>;
66
76
  tail: Promise<void>;
67
77
  readonly scheduler: ResourceScheduler;
68
78
  readonly callOrder: Map<string, number>;
@@ -156,11 +166,14 @@ function isBatchable(
156
166
  class NativeTextEditBatchCoordinator {
157
167
  private readonly scripts = new Map<string, ScriptBatch>();
158
168
  private readonly invocations = new Map<string, ScriptBatch>();
169
+ private readonly scopedInvocations = new Map<string, ScriptBatch>();
170
+ private readonly resultTargets: ResultTargetStore;
159
171
 
160
172
  constructor(
161
173
  private readonly core: TextEditorCore,
162
174
  private readonly pi: ExtensionAPI,
163
175
  ) {
176
+ this.resultTargets = connectResultTargets(pi);
164
177
  pi.registerTool({
165
178
  name: "flush",
166
179
  exposure: "codemode",
@@ -227,9 +240,12 @@ class NativeTextEditBatchCoordinator {
227
240
  summaries: [],
228
241
  reports: [],
229
242
  reportCursor: 0,
243
+ presentations: [],
230
244
  results: [],
231
245
  errors: [],
232
246
  cancellation: new AbortController(),
247
+ targets: new Map(),
248
+ postEdits: createPostEditScope(context.cwd),
233
249
  tail: Promise.resolve(),
234
250
  scheduler: new ResourceScheduler(),
235
251
  callOrder: new Map(),
@@ -248,6 +264,7 @@ class NativeTextEditBatchCoordinator {
248
264
  const registration = this.core
249
265
  .getMutationTools()
250
266
  .find((tool) => tool.name === event.toolName);
267
+ if (registration) this.scopedInvocations.set(event.toolCallId, script);
251
268
  const input: Record<string, unknown> = event.input;
252
269
  let ownsSource = false;
253
270
  if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
@@ -258,6 +275,14 @@ class NativeTextEditBatchCoordinator {
258
275
  for (const descriptor of [registration.source, ...(registration.source.targets ?? [])]) {
259
276
  const value = input[descriptor.field];
260
277
  if (typeof value === "string" && value.length > 0) {
278
+ if (
279
+ ["replace", "write", "copy", "move", "delete", "undo"].includes(registration.name) &&
280
+ value.startsWith("RESULT#")
281
+ ) {
282
+ // The executor validates result handles and returns a structured rejection.
283
+ ownsSource = true;
284
+ continue;
285
+ }
261
286
  const result = await this.core.textTargetResolver().tryResolve(value, resolverContext);
262
287
  if (result.kind !== "not-handled") ownsSource = true;
263
288
  }
@@ -295,6 +320,7 @@ class NativeTextEditBatchCoordinator {
295
320
  });
296
321
  pi.on("tool_result", async (event) => {
297
322
  this.invocations.delete(event.toolCallId);
323
+ this.scopedInvocations.delete(event.toolCallId);
298
324
  const script = this.scripts.get(event.toolCallId);
299
325
  if (!script) return;
300
326
  script.closed = true;
@@ -334,11 +360,77 @@ class NativeTextEditBatchCoordinator {
334
360
  },
335
361
  });
336
362
  script.errors.push(error.message);
363
+ for (const entry of script.pending.entries) {
364
+ const target = script.targets.get(entry.callId);
365
+ if (target) this.resultTargets.reject(target, error.message);
366
+ }
337
367
  script.pending = pendingBatch();
338
368
  }
339
369
  } else await this.commit(script);
370
+ try {
371
+ await this.core.enqueueFileOperation(
372
+ () =>
373
+ script.postEdits.finish((outcome) => {
374
+ const index = script.results.findLastIndex(
375
+ (item) => item.data.path === outcome.after.source,
376
+ );
377
+ if (index < 0) return;
378
+ const previous = requiredValue(script.results[index]).data;
379
+ const updated = new MutationPresentation({
380
+ ...previous,
381
+ afterContent: outcome.after.content,
382
+ afterDocument: outcome.after,
383
+ formatting: outcome.postEditContributions
384
+ .map((item) => item.data)
385
+ .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
386
+ diffStatuses: outcome.postEditContributions
387
+ .map((item) => item.data)
388
+ .filter(isDiffStatusContribution)
389
+ .flatMap((item) => item.diffStatuses),
390
+ });
391
+ const previousResult = requiredValue(script.results[index]);
392
+ script.results[index] = updated;
393
+ for (const [slot, presentation] of script.presentations.entries()) {
394
+ const results = presentation.result.details.results;
395
+ if (!results?.includes(previousResult)) continue;
396
+ script.presentations[slot] = {
397
+ ...presentation,
398
+ result: {
399
+ ...presentation.result,
400
+ details: {
401
+ ...presentation.result.details,
402
+ results: results.map((result) =>
403
+ result === previousResult ? updated : result,
404
+ ),
405
+ },
406
+ },
407
+ };
408
+ }
409
+ }),
410
+ undefined,
411
+ { cwd: script.context.cwd, sources: script.postEdits.sources() },
412
+ );
413
+ } catch (error) {
414
+ script.errors.push(error instanceof Error ? error.message : String(error));
415
+ }
416
+ // Nested panels are frozen on message_end. Publish final snapshots before history is saved.
417
+ for (const presentation of script.presentations) {
418
+ const results = presentation.result.details.results ?? [];
419
+ this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, {
420
+ ...presentation,
421
+ result: {
422
+ ...presentation.result,
423
+ content: [new FileMutationAgentResult(results).toTextContent()],
424
+ },
425
+ } satisfies NativeEditBatchEvent);
426
+ }
340
427
  this.scripts.delete(event.toolCallId);
341
- if (script.summaries.length === 0 && script.errors.length === 0) return;
428
+ if (
429
+ script.results.length === 0 &&
430
+ script.summaries.length === 0 &&
431
+ script.errors.length === 0
432
+ )
433
+ return;
342
434
  const failed = script.errors.length > 0;
343
435
  const content = event.content.map((block) =>
344
436
  failed && block.type === "text"
@@ -373,11 +465,25 @@ class NativeTextEditBatchCoordinator {
373
465
  }
374
466
  this.scripts.clear();
375
467
  this.invocations.clear();
468
+ this.scopedInvocations.clear();
376
469
  };
377
470
  pi.on("agent_end", clear);
378
471
  pi.on("session_shutdown", clear);
379
472
  }
380
473
 
474
+ /** Keep every mutation in the script's shared post-edit scope, including non-batched calls. */
475
+ runPostEdits<T>(id: string, work: () => T): T {
476
+ const script = this.scopedInvocations.get(id);
477
+ return script ? script.postEdits.run(work) : work();
478
+ }
479
+
480
+ /** Include non-batched mutations in the script's final post-edit presentation. */
481
+ recordMutation(id: string, result: AgentToolResult<FileMutationBatchResult>): void {
482
+ const script = this.scopedInvocations.get(id);
483
+ if (!script || !result.details.results?.some((item) => item.data.ok === true)) return;
484
+ script.results.push(...result.details.results);
485
+ script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
486
+ }
381
487
  execute(
382
488
  id: string,
383
489
  registration: AnyTextMutationToolRegistration,
@@ -498,11 +604,16 @@ class NativeTextEditBatchCoordinator {
498
604
  mutations: [...batch.plan.mutations, ...planning.plan.mutations].sort(order),
499
605
  failures: [...batch.plan.failures, ...planning.plan.failures],
500
606
  };
607
+ const target = ["replace", "insert", "write", "copy", "move"].includes(registration.name)
608
+ ? this.resultTargets.reserve(context.cwd)
609
+ : undefined;
610
+ if (target) script.targets.set(id, target);
501
611
  const details = {
502
612
  results: [],
503
613
  source: entry.path,
504
614
  resolvedBy: preview.resources.find((resource) => resource.path === entry.path)?.resolvedBy,
505
615
  nativeEditBatch: { parentToolCallId: script.id, state: "accepted" },
616
+ ...(target ? { metadata: { resultTarget: target } } : {}),
506
617
  };
507
618
  return {
508
619
  content: [
@@ -515,6 +626,51 @@ class NativeTextEditBatchCoordinator {
515
626
  };
516
627
  }
517
628
 
629
+ private async settleTargets(
630
+ script: ScriptBatch,
631
+ batch: PendingBatch,
632
+ journal: BatchExecutionJournal,
633
+ completions: readonly TextEditCompletion[],
634
+ signal: AbortSignal,
635
+ ): Promise<void> {
636
+ let mapped: ReturnType<typeof committedMutationTargets>;
637
+ try {
638
+ mapped = committedMutationTargets(
639
+ batch.plan.mutations.map(({ callId, mutation }) => ({ callId, edits: mutation.edits })),
640
+ completions,
641
+ );
642
+ } catch (error) {
643
+ for (const entry of batch.entries) {
644
+ const target = script.targets.get(entry.callId);
645
+ if (target)
646
+ this.resultTargets.reject(target, error instanceof Error ? error.message : String(error));
647
+ }
648
+ return;
649
+ }
650
+ const calls = journal.snapshot();
651
+ for (const entry of batch.entries) {
652
+ const reference = script.targets.get(entry.callId);
653
+ if (!reference) continue;
654
+ const targets = mapped.get(entry.callId);
655
+ if (calls.find((call) => call.callId === entry.callId)?.state !== "completed" || !targets) {
656
+ this.resultTargets.reject(
657
+ reference,
658
+ "This operation did not produce confirmed filesystem targets.",
659
+ );
660
+ continue;
661
+ }
662
+ try {
663
+ await this.resultTargets.verify({ targets, complete: true }, signal);
664
+ this.resultTargets.confirm(reference, targets, script.context.cwd);
665
+ } catch (error) {
666
+ this.resultTargets.reject(
667
+ reference,
668
+ error instanceof Error ? error.message : String(error),
669
+ );
670
+ }
671
+ }
672
+ }
673
+
518
674
  private async commit(script: ScriptBatch): Promise<boolean> {
519
675
  const batch = script.pending;
520
676
  if (batch.entries.length === 0) return true;
@@ -543,9 +699,13 @@ class NativeTextEditBatchCoordinator {
543
699
  ...operations.flatMap((operation) => {
544
700
  const entry = requiredValue(batch.entries.find((entry) => entry.callId === operation.id));
545
701
  const registration = requiredValue(registrations.get(entry.op));
702
+ const mutation = batch.plan.mutations.find(
703
+ (item) => item.callId === operation.id,
704
+ )?.mutation;
546
705
  return [...mutationSources(registration, entry).values()].map((source) => ({
547
706
  source,
548
- effect: operation.effect,
707
+ effect:
708
+ mutation?.edits.has(source) === false ? ("not-applied" as const) : operation.effect,
549
709
  }));
550
710
  }),
551
711
  ...observedSources.map((source) => ({ source, effect: "applied" as const })),
@@ -587,34 +747,40 @@ class NativeTextEditBatchCoordinator {
587
747
  };
588
748
  try {
589
749
  signal.throwIfAborted();
590
- const captured = await captureScriptMutation(this.core, () =>
591
- executeRegisteredTextBatch(
592
- this.core,
593
- registrations,
594
- {
595
- edits: batch.entries,
596
- expectedContent: batch.snapshots,
597
- expectedExistence: batch.existence,
598
- },
599
- signal,
600
- undefined,
601
- script.context,
602
- journal.reporter(),
603
- () => {},
604
- batch.plan,
750
+ const captured = await script.postEdits.run(() =>
751
+ captureScriptMutation(this.core, () =>
752
+ executeRegisteredTextBatch(
753
+ this.core,
754
+ registrations,
755
+ {
756
+ edits: batch.entries,
757
+ expectedContent: batch.snapshots,
758
+ expectedExistence: batch.existence,
759
+ },
760
+ signal,
761
+ undefined,
762
+ script.context,
763
+ journal.reporter(),
764
+ () => {},
765
+ batch.plan,
766
+ ),
605
767
  ),
606
768
  );
607
769
  observedSources = captured.completions.map((completion) => completion.resourceSource);
608
770
  if (captured.kind === "failed") throw captured.error;
609
771
  script.results.push(...(captured.value.details.results ?? []));
610
- this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, {
772
+ await this.settleTargets(script, batch, journal, captured.completions, signal);
773
+ const presentation = {
611
774
  parentToolCallId: script.id,
612
775
  calls: batch.entries.map((entry) => entry.callId),
613
776
  result: captured.value,
614
- } satisfies NativeEditBatchEvent);
777
+ } satisfies NativeEditBatchEvent;
778
+ script.presentations.push(presentation);
779
+ this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, presentation);
615
780
  return record(mutationOutcome(captured.value, "flush", captured.completions));
616
781
  } catch (error) {
617
782
  journal.markRunningUnknown(error);
783
+ await this.settleTargets(script, batch, journal, [], signal);
618
784
  return record({ status: "error", errors: [resultError(error)] });
619
785
  }
620
786
  }
@@ -622,6 +788,20 @@ class NativeTextEditBatchCoordinator {
622
788
 
623
789
  const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
624
790
 
791
+ /** Run immediate mutation paths under the same deferred post-edit boundary as native batches. */
792
+ export function runNativePostEditScope<T>(core: TextEditorCore, id: string, work: () => T): T {
793
+ const coordinator = coordinators.get(core);
794
+ return coordinator ? coordinator.runPostEdits(id, work) : work();
795
+ }
796
+
797
+ /** Retain immediate child results so final formatting is visible on the parent script. */
798
+ export function recordNativeTextMutation(
799
+ core: TextEditorCore,
800
+ id: string,
801
+ result: AgentToolResult<FileMutationBatchResult>,
802
+ ): void {
803
+ coordinators.get(core)?.recordMutation(id, result);
804
+ }
625
805
  /** Attach accumulating editor batches to native Codemode's public parent/child lifecycle. */
626
806
  export function registerNativeTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void {
627
807
  coordinators.set(core, new NativeTextEditBatchCoordinator(core, pi));
@@ -0,0 +1,22 @@
1
+ import type { ResolvedResultTargets } from "pi-agent-resource";
2
+ import { TextChangeDocument } from "./text-change-engine.js";
3
+
4
+ /** Require a verified selection of one complete file before a whole-file operation. */
5
+ export function wholeFileResultSource(result: ResolvedResultTargets): string {
6
+ const target = result.targets[0];
7
+ const range = target?.ranges[0];
8
+ if (result.targets.length !== 1 || target?.ranges.length !== 1 || range === undefined)
9
+ throw new Error("This operation requires one whole-file result target.");
10
+ const document = new TextChangeDocument(target.expectedContent);
11
+ const selected = document.range(
12
+ range.start.lineNumber,
13
+ range.start.column,
14
+ range.end.lineNumber,
15
+ range.end.column,
16
+ );
17
+ if (selected.from !== 0 || selected.to !== document.length)
18
+ throw new Error(
19
+ "This operation requires one whole-file result target; partial scopes are not widened.",
20
+ );
21
+ return target.source;
22
+ }
@@ -0,0 +1,78 @@
1
+ import type { ResultTargetStore } from "pi-agent-resource";
2
+ import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
3
+ import {
4
+ TEXT_SEARCH_ANCHOR_KIND,
5
+ type TextAnchorResolverRegistration,
6
+ } from "#src/api/plugin-protocol.js";
7
+
8
+ /** Resolve registered snapshot targets through the editor's normal source and anchor guards. */
9
+ export function createResultTargetAnchors(
10
+ store: ResultTargetStore,
11
+ ): TextAnchorResolverRegistration {
12
+ return {
13
+ kind: TEXT_SEARCH_ANCHOR_KIND,
14
+ type: "auxiliary",
15
+ describeInPrompt: false,
16
+ resolver: {
17
+ id: "result-targets",
18
+ description: "Use returned RESULT# references to target exact source snapshots.",
19
+ renderFull: (value) => value,
20
+ renderCompact: () => "result targets",
21
+ async tryResolve(value, context) {
22
+ if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
23
+ try {
24
+ const target = store
25
+ .resolve(value, context.cwd)
26
+ .targets.find((target) => target.source === context.source);
27
+ if (target === undefined)
28
+ return {
29
+ kind: "rejected",
30
+ rejection: { code: "missing", reason: "Result does not select this source." },
31
+ };
32
+ if (target.expectedContent !== context.content)
33
+ return {
34
+ kind: "rejected",
35
+ rejection: { code: "stale", reason: "Result target is stale; repeat Read/Search." },
36
+ };
37
+ return {
38
+ kind: "resolved",
39
+ anchor: new TextSelectionAnchor(value, target.source, target.ranges),
40
+ };
41
+ } catch (error) {
42
+ return {
43
+ kind: "rejected",
44
+ rejection: {
45
+ code: "invalid",
46
+ reason: error instanceof Error ? error.message : String(error),
47
+ },
48
+ };
49
+ }
50
+ },
51
+ },
52
+ resources: {
53
+ id: "result-target-sources",
54
+ async tryResolve(value, context) {
55
+ if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
56
+ try {
57
+ const selected = store.resolve(value, context.cwd);
58
+ await store.verify(selected, context.signal);
59
+ return selected.targets.length === 0
60
+ ? {
61
+ kind: "rejected",
62
+ rejection: { code: "missing", reason: "Empty result target set." },
63
+ }
64
+ : { kind: "resolved", targets: selected.targets };
65
+ } catch (error) {
66
+ context.signal?.throwIfAborted();
67
+ return {
68
+ kind: "rejected",
69
+ rejection: {
70
+ code: "stale",
71
+ reason: error instanceof Error ? error.message : String(error),
72
+ },
73
+ };
74
+ }
75
+ },
76
+ },
77
+ };
78
+ }
@@ -0,0 +1,175 @@
1
+ import type { ResolvedResultTargets, ResultTargetStore } from "pi-agent-resource";
2
+ import type {
3
+ TextMutation,
4
+ TextMutationContext,
5
+ TextMutationEdit,
6
+ } from "#src/api/mutation-tool.js";
7
+ import type { TextChange } from "./text-change-engine.js";
8
+ import {
9
+ anchorSpanRange,
10
+ insertionAfterAnchor,
11
+ replaceAnchorSpan,
12
+ } from "#src/tools/text-selection.js";
13
+ import { wholeFileResultSource } from "./result-input.js";
14
+
15
+ /** Distinguish structured source authority from ordinary paths and legacy anchors. */
16
+ export function isResultInput(value: unknown): boolean {
17
+ return value !== undefined && (typeof value !== "string" || value.startsWith("RESULT#"));
18
+ }
19
+
20
+ interface TransferSpan {
21
+ readonly source: string;
22
+ readonly from: number;
23
+ readonly to: number;
24
+ }
25
+
26
+ interface PreparedTransfer {
27
+ readonly input: Readonly<Record<string, unknown>>;
28
+ readonly empty: boolean;
29
+ readonly verifyFileSource?: () => Promise<void>;
30
+ readonly mutate?: (context: TextMutationContext) => Promise<TextMutation>;
31
+ }
32
+
33
+ /** Resolve ordered pairs once; execute them inside the editor's existing guarded snapshots. */
34
+ export async function prepareResultTransfer(
35
+ operation: "copy" | "move",
36
+ parameters: Readonly<Record<string, unknown>>,
37
+ store: ResultTargetStore,
38
+ cwd: string,
39
+ signal?: AbortSignal,
40
+ ): Promise<PreparedTransfer> {
41
+ const input = { ...parameters };
42
+ const resolve = async (field: "path" | "target", start: string, end: string) => {
43
+ if (!isResultInput(input[field])) return undefined;
44
+ if (input[start] !== undefined || input[end] !== undefined)
45
+ throw new Error(`Do not combine structured ${field} with ${start}/${end}.`);
46
+ const selected = store.resolveOrdered(input[field], cwd);
47
+ if (!selected.complete)
48
+ throw new Error(
49
+ "Incomplete result targets cannot establish a complete transfer; repeat Search.",
50
+ );
51
+ await store.verify(selected, signal);
52
+ input[field] = store.register(selected.targets, cwd);
53
+ return selected;
54
+ };
55
+ const source = await resolve("path", "start", "end");
56
+ const destination = await resolve("target", "targetStart", "targetEnd");
57
+ if (source === undefined && destination === undefined) return { input, empty: false };
58
+ if (
59
+ source !== undefined &&
60
+ destination === undefined &&
61
+ input.targetStart === undefined &&
62
+ input.targetEnd === undefined
63
+ ) {
64
+ // A structured source may use the byte-preserving file operation only when it really selects a whole file.
65
+ input.path = wholeFileResultSource(store.resolve(parameters.path, cwd));
66
+ return { input, empty: false, verifyFileSource: () => store.verify(source, signal) };
67
+ }
68
+ if (
69
+ source !== undefined &&
70
+ destination !== undefined &&
71
+ source.targets.length !== destination.targets.length
72
+ )
73
+ throw new Error(
74
+ "Transfer source and destination selection counts must match; no broadcast or concatenation.",
75
+ );
76
+ const empty = source?.targets.length === 0 || destination?.targets.length === 0;
77
+ return {
78
+ input,
79
+ empty,
80
+ async mutate(context) {
81
+ const spans = (selected: ResolvedResultTargets): TransferSpan[] =>
82
+ selected.targets.map((target) => {
83
+ const document = context.documentFor(target.source);
84
+ if (document.content !== target.expectedContent)
85
+ throw new Error("Transfer result target is stale; repeat Read/Search.");
86
+ const range = target.ranges[0];
87
+ if (range === undefined) throw new Error("Transfer selection has no range.");
88
+ return {
89
+ source: target.source,
90
+ ...document.range(
91
+ range.start.lineNumber,
92
+ range.start.column,
93
+ range.end.lineNumber,
94
+ range.end.column,
95
+ ),
96
+ };
97
+ });
98
+ const sources =
99
+ source === undefined
100
+ ? [
101
+ input.start === undefined
102
+ ? { source: context.sourceFor("path"), from: 0, to: context.sourceDocument.length }
103
+ : anchorSpanRange(
104
+ context,
105
+ await context.resolveAnchors("start"),
106
+ input.end === undefined ? undefined : await context.resolveAnchors("end"),
107
+ "start",
108
+ "end",
109
+ ),
110
+ ]
111
+ : spans(source);
112
+ const destinations = destination === undefined ? undefined : spans(destination);
113
+ if (sources.length !== (destinations?.length ?? 1))
114
+ throw new Error(
115
+ "Transfer source and destination selection counts must match; no broadcast or concatenation.",
116
+ );
117
+ const edits = new Map<string, TextMutationEdit>();
118
+ const append = (span: TransferSpan, change: TextChange, producesTarget: boolean) => {
119
+ const edit = edits.get(span.source);
120
+ const changes = [...(edit?.changes ?? []), change];
121
+ const resultChanges = [
122
+ ...(edit?.resultChanges ?? []),
123
+ ...(producesTarget ? [changes.length - 1] : []),
124
+ ];
125
+ edits.set(span.source, { action: "edited", changes, resultChanges });
126
+ };
127
+ const planned: { target: TransferSpan; change: TextChange }[] = [];
128
+ for (const [index, span] of sources.entries()) {
129
+ const copied = context.documentFor(span.source).text(span);
130
+ const destinationSpan = destinations?.[index];
131
+ if (destinationSpan !== undefined) {
132
+ planned.push({
133
+ target: destinationSpan,
134
+ change: { from: destinationSpan.from, to: destinationSpan.to, insert: copied },
135
+ });
136
+ continue;
137
+ }
138
+ const starts = await context.resolveAnchors("targetStart");
139
+ if (input.targetEnd === undefined) {
140
+ const [target, change] = insertionAfterAnchor(context, starts, "targetStart", copied);
141
+ planned.push({
142
+ target: { source: target, from: change.from, to: change.to },
143
+ change,
144
+ });
145
+ } else {
146
+ const target = anchorSpanRange(
147
+ context,
148
+ starts,
149
+ await context.resolveAnchors("targetEnd"),
150
+ "targetStart",
151
+ "targetEnd",
152
+ );
153
+ planned.push({
154
+ target,
155
+ change: replaceAnchorSpan(context, target, copied),
156
+ });
157
+ }
158
+ }
159
+ if (operation === "move") {
160
+ for (const sourceSpan of sources)
161
+ for (const transfer of planned)
162
+ if (
163
+ sourceSpan.source === transfer.target.source &&
164
+ sourceSpan.from <= transfer.target.to &&
165
+ transfer.target.from <= sourceSpan.to
166
+ )
167
+ throw new Error("Move target must not overlap or touch any source range.");
168
+ for (const span of sources)
169
+ append(span, { from: span.from, to: span.to, insert: "" }, false);
170
+ }
171
+ for (const transfer of planned) append(transfer.target, transfer.change, true);
172
+ return { edits };
173
+ },
174
+ };
175
+ }