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
@@ -1,369 +0,0 @@
1
- import type { RunLimits } from "run";
2
- import { ApplyQueue } from "#src/core/apply/queue.js";
3
-
4
- /** Read-only IDE operations plus the private transactional editor bridge. */
5
- export const defaultApplyOperations = [
6
- "read",
7
- "search",
8
- "diff",
9
- "editorOpen",
10
- "editorResolve",
11
- "editorApply",
12
- ] as const;
13
- export type ApplyOperation = (typeof defaultApplyOperations)[number];
14
-
15
- // Node timers use signed 32-bit delays. This is effectively unbounded for an agent turn while
16
- // preserving Run's finite sandbox deadline and explicit limits used by focused tests.
17
- const APPLY_EXECUTION_TIMEOUT_MS = 2_147_483_647;
18
-
19
- /** Return the fixed Apply capability set. Kept as a function for callers that build prompts. */
20
- export function getApplyOperations(): readonly ApplyOperation[] {
21
- return defaultApplyOperations;
22
- }
23
-
24
- /** The host records outcomes before returning them across the guest bridge. */
25
- export interface ApplyRuntimeHost {
26
- execute(
27
- operation: ApplyOperation,
28
- arguments_: unknown,
29
- signal: AbortSignal,
30
- id: string,
31
- ): Promise<unknown>;
32
- result(value: unknown, operationId?: string): Promise<void>;
33
- }
34
-
35
- /** Runs a fresh composition and drains host work on success, failure, or cancellation. */
36
- export async function executeApplySource(
37
- source: string,
38
- host: ApplyRuntimeHost,
39
- signal?: AbortSignal,
40
- limits?: RunLimits,
41
- enabledOperations: readonly ApplyOperation[] = defaultApplyOperations,
42
- ): Promise<void> {
43
- const { createRunner, getHostFunctionContext } = await import("run");
44
- const queue = new ApplyQueue();
45
- const operations = Object.fromEntries(
46
- enabledOperations.map((operation) => [
47
- operation,
48
- (arguments_: unknown) => {
49
- const context = getHostFunctionContext();
50
- return queue.submit(async () => {
51
- context.abortSignal.throwIfAborted();
52
- try {
53
- return {
54
- ok: true,
55
- value: await host.execute(
56
- operation,
57
- arguments_,
58
- context.abortSignal,
59
- context.requestId,
60
- ),
61
- id: context.requestId,
62
- };
63
- } catch (error) {
64
- return { ok: false, error: serializeApplyError(error) };
65
- }
66
- });
67
- },
68
- ]),
69
- );
70
- try {
71
- const runner = createRunner({
72
- syncHostFunctions: {
73
- __apply: {
74
- ...operations,
75
- result: (value: unknown, operationId?: string) =>
76
- queue.submit(() => host.result(value, operationId)),
77
- },
78
- },
79
- });
80
- await runner.run({
81
- source: `${guestBindings(enabledOperations)}\nawait (async () => {\n${source}\n})();\n__finishApplyScript();`,
82
- abortSignal: signal,
83
- limits: { ...limits, timeoutMs: limits?.timeoutMs ?? APPLY_EXECUTION_TIMEOUT_MS },
84
- });
85
- } finally {
86
- await queue.close();
87
- }
88
- }
89
-
90
- /** Preserves operation error fields without sending host Error instances across the bridge. */
91
- export function serializeApplyError(error: unknown): {
92
- code: string;
93
- message: string;
94
- details?: unknown;
95
- } {
96
- if (!(error instanceof Error)) return { code: "OPERATION_FAILED", message: String(error) };
97
- const runtimeCode = "code" in error && typeof error.code === "string" ? error.code : undefined;
98
- return {
99
- code:
100
- runtimeCode === "RUN_USER_SOURCE_ERROR"
101
- ? applyGuestErrorCode(error.message)
102
- : (runtimeCode ?? "OPERATION_FAILED"),
103
- message: error.message,
104
- ...("details" in error ? { details: error.details } : {}),
105
- };
106
- }
107
-
108
- function applyGuestErrorCode(message: string): string {
109
- if (/Expected exactly one (?:match|end marker)/u.test(message))
110
- return message.endsWith("found 0") ? "NOT_FOUND" : "AMBIGUOUS_MATCH";
111
- if (message === "No matches") return "NOT_FOUND";
112
- if (message === "Search match is stale") return "STALE_SELECTION";
113
- if (message === "Editor handle belongs to a committed transaction") return "STALE_EDITOR";
114
- if (message === "union() selections overlap" || message === "Expected a SelectionSet")
115
- return "INVALID_SELECTION";
116
- if (message === "SelectionSet belongs to another file") return "CROSS_FILE_SELECTION";
117
- if (message === "SelectionSet belongs to a stale snapshot") return "STALE_SELECTION";
118
- if (/^(?:Invalid line range|Line range is outside document)$/u.test(message))
119
- return "INVALID_SELECTION";
120
- return "RUN_USER_SOURCE_ERROR";
121
- }
122
- function guestBindings(enabledOperations: readonly ApplyOperation[]): string {
123
- const readOperations = enabledOperations.filter(
124
- (name) => name === "read" || name === "search" || name === "diff",
125
- );
126
- return `const { ${readOperations.join(", ")}, open, createFile, deleteFile, copyFile, moveFile, replace, remove, insertBefore, insertAfter, copy, move, flush, __finishApplyScript } = (() => {
127
-
128
- const invoke = (name, args) => {
129
- const response = __apply[name](args);
130
- if (!response.ok) throw Object.assign(new Error(response.error.message), response.error);
131
-
132
- return response.value;
133
- };
134
- let snapshots = new Map();
135
- let operations = [];
136
- const assertCurrent = (document) => {
137
- if (!snapshots.has(document.id)) throw Object.assign(new Error("Editor handle belongs to an unavailable snapshot"), {code: "STALE_EDITOR"});
138
- };
139
- const selection = (document, from, to, linewise = false) => Object.freeze({document: document.id, from, to, text: document.content.slice(from, to), ...(linewise && {linewise: true})});
140
- const selectionSet = (document, ranges, provenance) => {
141
- const set = ranges.map(({from, to, linewise}) => selection(document, from, to, linewise === true));
142
- Object.defineProperties(set, {document: {value: document.id}, generation: {value: document.generation}, provenance: {value: provenance}, text: {value: set.map((item) => item.text).join("")}});
143
- return Object.freeze(set);
144
- };
145
- const occurrences = (content, needle) => {
146
- if (typeof needle !== "string" || needle.length === 0) throw new Error("Find text must be non-empty");
147
- const found = [];
148
- for (let from = content.indexOf(needle); from >= 0; from = content.indexOf(needle, from + needle.length)) found.push(from);
149
- return found;
150
- };
151
- const selectionError = (code, message) => Object.assign(new Error(message), {code});
152
- const assertSet = (document, set) => {
153
- if (!Array.isArray(set)) throw selectionError("INVALID_SELECTION", "Expected a SelectionSet");
154
- if (set.document !== document.id) throw selectionError("CROSS_FILE_SELECTION", "SelectionSet belongs to another file");
155
- if (set.generation !== document.generation) throw selectionError("STALE_SELECTION", "SelectionSet belongs to a stale snapshot");
156
- return set;
157
- };
158
- const boundarySet = (document, value) => {
159
- if (typeof value !== "string") return assertSet(document, value);
160
- const ranges = occurrences(document.content, value).map((from) => ({from, to: from + value.length}));
161
- return selectionSet(document, ranges, {kind: "exact", query: value});
162
- };
163
- const lineRange = (document, item) => {
164
- const from = document.content.lastIndexOf("\\n", Math.max(0, item.from - 1)) + 1;
165
- const newline = document.content.indexOf("\\n", Math.max(item.from, item.to - 1));
166
- return {from, to: newline < 0 ? document.content.length : newline + 1, linewise: true};
167
- };
168
- const targetSet = (document, target) => {
169
- if (typeof target !== "string") return target;
170
- const resolved = invoke("editorResolve", {snapshot: {id: document.id, source: document.source, content: document.content}, query: target});
171
- return selectionSet(document, resolved.selections, {kind: "exact", query: target, warning: resolved.warning});
172
- };
173
- const stage = (document, target, text, edge, options = {}) => {
174
- if (edge !== undefined && text.length === 0) throw new Error("Insert text must not be empty.");
175
- if (options.separation !== undefined && options.separation !== "line" && options.separation !== "blank-line") throw new Error("Invalid separation mode.");
176
- const selected = targetSet(document, target);
177
- if (!Array.isArray(selected) || selected.document !== document.id) throw new Error("SelectionSet belongs to another file");
178
- if (selected.generation !== document.generation) throw Object.assign(new Error("SelectionSet belongs to a stale snapshot"), {code:"STALE_SELECTION"});
179
- if (selected.length === 0) { operations.push({kind: "warning", document: document.id, query: selected.provenance?.query, warning: selected.provenance?.warning}); return; }
180
- for (const range of selected) {
181
- const point = edge === "before" ? range.from : edge === "after" ? range.to : undefined;
182
- let insert = text;
183
- if (point !== undefined && range.linewise === true) {
184
- const separator = document.content.includes("\\r\\n") ? "\\r\\n" : "\\n";
185
- const before = document.content.slice(0, point);
186
- const after = document.content.slice(point);
187
- const prefix = edge === "after" && before.length > 0 && !before.endsWith("\\n") ? separator : "";
188
- const following = after.length > 0;
189
- insert = prefix + insert;
190
- if (options.separation === "blank-line") {
191
- if (before.length > 0 && !before.endsWith(separator + separator) && !insert.slice(prefix.length).startsWith(separator)) insert = separator + insert;
192
- if (following && !insert.endsWith(separator + separator) && !after.startsWith(separator)) insert += insert.endsWith(separator) ? separator : separator + separator;
193
- }
194
- if (following && !insert.endsWith("\\n")) insert += separator;
195
- }
196
- operations.push({kind: "replace", selection: point === undefined ? range : selection(document, point, point), text: insert});
197
- }
198
- };
199
- const stageTransfer = (kind, source, destination) => {
200
- for (const set of [source, destination]) {
201
- const document = snapshots.get(set?.document);
202
- if (!Array.isArray(set) || document === undefined || set.generation !== document.generation) throw Object.assign(new Error("SelectionSet belongs to a stale or unopened snapshot"), {code:"STALE_SELECTION"});
203
- }
204
- const empty = source.length === 0 ? source : destination.length === 0 ? destination : undefined;
205
- if (empty !== undefined) { operations.push({kind:"warning", document:empty.document, query:empty.provenance?.query, warning:empty.provenance?.warning}); return; }
206
- operations.push({kind, sources:[...source], destinations:[...destination], text:source.map((item) => item.text).join("")});
207
- };
208
- const stageSet = (target, text, edge, options) => {
209
- const document = snapshots.get(target?.document);
210
- if (document === undefined) throw selectionError("STALE_SELECTION", "SelectionSet belongs to a stale or unopened snapshot");
211
- stage(document, target, text, edge, options);
212
- };
213
- const refreshSnapshots = (value) => {
214
- for (const refreshed of value?.snapshots ?? []) {
215
- const document = snapshots.get(refreshed.id);
216
- if (document !== undefined && refreshed.unavailable === true) snapshots.delete(refreshed.id);
217
- else if (document !== undefined) {
218
- document.source = refreshed.source;
219
- document.content = refreshed.content;
220
- document.lines = refreshed.lines;
221
- document.generation += 1;
222
- }
223
- }
224
- };
225
- const commit = (selected) => {
226
- if (selected.length === 0) return undefined;
227
- const value = invoke("editorApply", {snapshots: [...snapshots.values()].map(({id, source, content}) => ({id, source, content})), operations: selected});
228
- refreshSnapshots(value);
229
- return value;
230
- };
231
- const flushDocument = (document) => {
232
- assertCurrent(document);
233
- const participatesInTransfer = operations.some((operation) =>
234
- (operation.kind === "text-copy" || operation.kind === "text-move") &&
235
- [...operation.sources, ...operation.destinations].some((item) => item.document === document.id));
236
- if (participatesInTransfer) return undefined;
237
- const selected = [];
238
- const remaining = [];
239
- for (const operation of operations) {
240
- const belongs =
241
- (operation.kind === "replace" && operation.selection.document === document.id) ||
242
- (operation.kind === "warning" && operation.document === document.id) ||
243
- (operation.kind === "delete" && operation.path === document.source);
244
- (belongs ? selected : remaining).push(operation);
245
- }
246
- operations = remaining;
247
- return commit(selected);
248
- };
249
- const makeDocument = (snapshot) => {
250
- const document = {id: snapshot.id, source: snapshot.source, content: snapshot.content, lines: snapshot.lines, generation: 0};
251
- snapshots.set(document.id, document);
252
- const api = {
253
- get source() { return document.source; },
254
- get content() { return document.content; },
255
- get lines() { return document.lines; },
256
- find: (text) => { assertCurrent(document); const ranges = occurrences(document.content, text).map((from) => ({from, to: from + text.length})); if (ranges.length > 0) return selectionSet(document, ranges, {kind: "exact", query: text}); const resolved = invoke("editorResolve", {snapshot: {id: document.id, source: document.source, content: document.content}, query: text}); return selectionSet(document, [], {kind: "exact", query: text, warning: resolved.warning}); },
257
- between: (start, end, options = {}) => {
258
- assertCurrent(document);
259
- if (options.inside === true && options.lines === true) throw selectionError("INVALID_SELECTION", "between() cannot combine inside and lines");
260
- const starts = boundarySet(document, start);
261
- const ends = boundarySet(document, end);
262
- const ranges = [];
263
- let cursor = 0;
264
- for (const left of starts) {
265
- if (left.from < cursor) continue;
266
- const right = ends.find((candidate) => candidate.from >= left.to);
267
- if (right === undefined) break;
268
- const range = options.lines === true
269
- ? {from: lineRange(document, left).from, to: lineRange(document, right).to, linewise: true}
270
- : {
271
- from: options.inside === true ? left.to : left.from,
272
- to: options.inside === true ? right.from : right.to,
273
- linewise: options.inside !== true && left.linewise === true && right.linewise === true,
274
- };
275
- ranges.push(range);
276
- cursor = right.to;
277
- }
278
- return selectionSet(document, ranges, {kind: "between"});
279
- },
280
- slice: (set, start, end) => {
281
- assertCurrent(document);
282
- const selected = assertSet(document, set);
283
- return selectionSet(document, selected.slice(start, end), {kind: "slice", source: selected.provenance, start, end, warning: selected.provenance?.warning});
284
- },
285
- union: (...sets) => {
286
- assertCurrent(document);
287
- const ranges = sets.flatMap((set) => [...assertSet(document, set)]).sort((left, right) => left.from - right.from || left.to - right.to);
288
- const unique = ranges.filter((range, index) => index === 0 || range.from !== ranges[index - 1].from || range.to !== ranges[index - 1].to);
289
- for (let index = 1; index < unique.length; index += 1) {
290
- if (unique[index].from < unique[index - 1].to) throw selectionError("INVALID_SELECTION", "union() selections overlap");
291
- }
292
- return selectionSet(document, unique, {kind: "union", sources: sets.map((set) => set.provenance), warning: sets.find((set) => set.provenance?.warning)?.provenance.warning});
293
- },
294
- within: (candidates, scopes) => {
295
- assertCurrent(document);
296
- const selected = assertSet(document, candidates);
297
- const containers = assertSet(document, scopes);
298
- const ranges = selected.filter((candidate) => containers.some((scope) => scope.from <= candidate.from && candidate.to <= scope.to));
299
- return selectionSet(document, ranges, {kind: "within", source: selected.provenance, scopes: containers.provenance, warning: selected.provenance?.warning ?? containers.provenance?.warning});
300
- },
301
- linesOf: (set) => {
302
- assertCurrent(document);
303
- const selected = assertSet(document, set);
304
- const ranges = selected.map((item) => lineRange(document, item)).sort((left, right) => left.from - right.from);
305
- const unique = ranges.filter((range, index) => index === 0 || range.from !== ranges[index - 1].from || range.to !== ranges[index - 1].to);
306
- return selectionSet(document, unique, {kind: "linesOf", source: selected.provenance, warning: selected.provenance?.warning});
307
- },
308
- select: (match) => {
309
- assertCurrent(document);
310
- const candidate = match?.selection ?? match;
311
- if (!candidate || typeof candidate !== "object") throw new Error("select() requires a search match");
312
- if (candidate.source && candidate.source !== document.source) throw new Error("Search match belongs to another file");
313
- const starts = [0];
314
- for (let index = 0; index < document.content.length; index += 1) if (document.content[index] === "\\n") starts.push(index + 1);
315
- const startLine = candidate.lineNumber;
316
- const endLine = candidate.endLineNumber ?? startLine;
317
- if (!Number.isInteger(startLine) || !Number.isInteger(endLine)) throw new Error("Search match has no text range");
318
- const from = starts[startLine - 1] + candidate.startColumn;
319
- const to = starts[endLine - 1] + candidate.endColumn;
320
- const selected = selection(document, from, to);
321
- if (typeof candidate.matchedText === "string" && selected.text !== candidate.matchedText) throw Object.assign(new Error("Search match is stale"), {code: "STALE_SELECTION"});
322
- return selectionSet(document, [selected]);
323
- },
324
- line: (first, last = first) => {
325
- assertCurrent(document);
326
- if (!Number.isInteger(first) || !Number.isInteger(last) || first < 1 || last < first) throw new RangeError("Invalid line range");
327
- const starts = [0];
328
- for (let index = 0; index < document.content.length; index += 1) if (document.content[index] === "\\n") starts.push(index + 1);
329
- if (last > starts.length) throw new RangeError("Line range is outside document");
330
- return selectionSet(document, [{from: starts[first - 1], to: starts[last] === undefined ? document.content.length : starts[last], linewise: true}], {kind: "line", first, last});
331
- },
332
- start: () => { assertCurrent(document); return selectionSet(document, [{from: 0, to: 0, linewise: true}], {kind: "start"}); },
333
- end: () => { assertCurrent(document); const point = document.content.length; return selectionSet(document, [{from: point, to: point, linewise: true}], {kind: "end"}); },
334
- before: (set) => { assertCurrent(document); const selected = assertSet(document, set); return selectionSet(document, selected.map((item) => ({from: item.from, to: item.from, linewise: item.linewise === true})), {kind: "before", source: selected.provenance}); },
335
- after: (set) => { assertCurrent(document); const selected = assertSet(document, set); return selectionSet(document, selected.map((item) => ({from: item.to, to: item.to, linewise: item.linewise === true})), {kind: "after", source: selected.provenance}); },
336
- replace: (target, text) => { assertCurrent(document); stage(document, target, String(text)); },
337
- remove: (target) => { assertCurrent(document); stage(document, target, ""); },
338
- insertBefore: (target, text, options) => { assertCurrent(document); stage(document, target, String(text), "before", options); },
339
- insertAfter: (target, text, options) => { assertCurrent(document); stage(document, target, String(text), "after", options); },
340
- flush: () => flushDocument(document),
341
- delete: () => { assertCurrent(document); operations.push({kind: "delete", path: document.source}); },
342
- };
343
- return Object.freeze(api);
344
- };
345
- const api = {
346
- ${readOperations.map((name) => `${name}: (args) => invoke(${JSON.stringify(name)}, args)`).join(",\n")},
347
- open: (path) => makeDocument(invoke("editorOpen", typeof path === "string" ? {path} : path)),
348
- createFile: (path, content) => operations.push({kind: "create", path, content: String(content)}),
349
- deleteFile: (path) => operations.push({kind: "delete", path}),
350
- copyFile: (path, target, options = {}) => operations.push({kind: "copy", path, target, overwrite: options.overwrite === true}),
351
- moveFile: (path, target, options = {}) => operations.push({kind: "move", path, target, overwrite: options.overwrite === true}),
352
- replace: (target, text) => stageSet(target, String(text)),
353
- remove: (target) => stageSet(target, ""),
354
- insertBefore: (target, text, options) => stageSet(target, String(text), "before", options),
355
- insertAfter: (target, text, options) => stageSet(target, String(text), "after", options),
356
- copy: (source, destination) => stageTransfer("text-copy", source, destination),
357
- move: (source, destination) => stageTransfer("text-move", source, destination),
358
- flush: () => {
359
- if (operations.length === 0) return undefined;
360
- const pending = operations;
361
- operations = [];
362
- return commit(pending);
363
- },
364
-
365
- __finishApplyScript: () => { if (operations.length > 0) return api.flush(); },
366
- };
367
- return api;
368
- })();`;
369
- }
@@ -1,251 +0,0 @@
1
- import { Type } from "typebox";
2
- import {
3
- resultError,
4
- resultErrorSchema,
5
- structuredResultSchema,
6
- withStructuredResult,
7
- type ResultError,
8
- } from "pi-agent-resource";
9
- import { readDataSchema, structuredRead } from "pi-agent-read/api/tools/read";
10
- import { searchDataSchema } from "pi-agent-search/api/search";
11
- import { mutationDataSchema } from "#src/core/structured-result.js";
12
- import { diffDataSchema, isDiffOutcome } from "#src/core/diff-tool.js";
13
- import type { ApplyResults } from "./results.js";
14
- import type { ReadPluginApi } from "pi-agent-read/api/plugin-protocol";
15
- import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
16
- import { truncateHead } from "@earendil-works/pi-coding-agent";
17
- const operationSchema = Type.Object(
18
- {
19
- id: Type.String(),
20
- kind: Type.Union([Type.Literal("read"), Type.Literal("mutation")]),
21
- fullResultBytes: Type.Optional(Type.Integer({ minimum: 0 })),
22
- fullResult: Type.Optional(Type.String()),
23
- status: Type.Union([Type.Literal("success"), Type.Literal("error"), Type.Literal("partial")]),
24
- data: Type.Optional(
25
- Type.Union([
26
- readDataSchema,
27
- searchDataSchema,
28
- mutationDataSchema,
29
- diffDataSchema,
30
- Type.Object({ source: Type.String() }, { additionalProperties: false }),
31
- ]),
32
- ),
33
- errors: Type.Array(resultErrorSchema),
34
- },
35
- { additionalProperties: false },
36
- );
37
- export const applyDataSchema = Type.Object(
38
- {
39
- operations: Type.Array(operationSchema),
40
- files: Type.Array(Type.String()),
41
- transactions: Type.Array(Type.String()),
42
- values: Type.Array(Type.Unknown()),
43
- truncated: Type.Boolean(),
44
- fullResult: Type.Optional(Type.String()),
45
- },
46
- { additionalProperties: false },
47
- );
48
- export const applyOutputSchema = structuredResultSchema(applyDataSchema);
49
- function record(value: unknown): value is Record<string, unknown> {
50
- return value !== null && typeof value === "object";
51
- }
52
-
53
- /** Project the host ledger, retaining committed receipts while omitting full source snapshots. */
54
- export async function structuredApply<D>(
55
- result: AgentToolResult<D>,
56
- results: ApplyResults,
57
- read: ReadPluginApi,
58
- transactions: readonly string[],
59
- error?: unknown,
60
- ) {
61
- const errors: ResultError[] = error === undefined ? [] : [resultError(error, "APPLY_FAILED")];
62
- const operations = [];
63
- let applied = false;
64
- for (const entry of results.operations()) {
65
- const value = record(entry.value) ? entry.value : {};
66
- let data: unknown;
67
- const failures: ResultError[] = [];
68
- if (entry.kind === "mutation") {
69
- const effect =
70
- value.effect === "applied" || value.effect === "not-applied" || value.effect === "unknown"
71
- ? value.effect
72
- : "unknown";
73
- applied ||= effect === "applied";
74
- const operationErrors = Array.isArray(value.errors) ? value.errors : [];
75
- for (const error of operationErrors)
76
- if (record(error))
77
- failures.push({
78
- code: typeof error.code === "string" ? error.code : "MUTATION_FAILED",
79
- message: typeof error.message === "string" ? error.message : "Mutation failed",
80
- ...(typeof error.source === "string" ? { source: error.source } : {}),
81
- });
82
- const perOperation = Array.isArray(value.operations) ? value.operations.filter(record) : [];
83
- if (
84
- value.ok === false &&
85
- failures.length === 0 &&
86
- (perOperation.length === 0 ||
87
- perOperation.some(
88
- (operation) => operation.status !== "applied" && operation.status !== "warning",
89
- ))
90
- )
91
- failures.push(resultError("Mutation did not complete", "MUTATION_FAILED"));
92
- if (record(value.error))
93
- failures.push(
94
- resultError(
95
- value.error.message,
96
- typeof value.error.code === "string" ? value.error.code : "MUTATION_FAILED",
97
- ),
98
- );
99
- data = {
100
- operation: typeof value.operation === "string" ? value.operation : "apply",
101
- effect,
102
- files: Array.isArray(value.files)
103
- ? value.files
104
- .filter(record)
105
- .filter((file) => typeof file.source === "string")
106
- .map((file) => ({ source: file.source, effect: "applied" }))
107
- : [],
108
- operations: perOperation.filter(record).map((operation) => ({
109
- id: `${entry.id}:${String(operation.index)}`,
110
- operation: String(operation.kind),
111
- effect: operation.effect,
112
- status:
113
- operation.status === "applied"
114
- ? "success"
115
- : operation.status === "warning"
116
- ? "warning"
117
- : operation.status === "unknown"
118
- ? "unknown"
119
- : "error",
120
- sources: Array.isArray(operation.resources) ? operation.resources : [],
121
- ...(record(operation.warning)
122
- ? { warnings: [resultError(operation.warning.message, String(operation.warning.code))] }
123
- : {}),
124
- errors: record(operation.error)
125
- ? [resultError(operation.error.message, String(operation.error.code))]
126
- : [],
127
- })),
128
- ...(typeof value.transaction === "string" ? { transaction: value.transaction } : {}),
129
- };
130
- } else if (isDiffOutcome(value)) {
131
- const diff = truncateHead(value.diff);
132
- const fullResult = diff.truncated ? await read.saveTemporary(value.diff) : undefined;
133
- data = {
134
- kind: "diff",
135
- equal: value.equal,
136
- before: { source: value.before.source, sources: value.before.sources },
137
- after: { source: value.after.source, sources: value.after.sources },
138
- stats: value.stats,
139
- diff: diff.content,
140
- truncated: diff.truncated,
141
- ...(fullResult === undefined ? {} : { fullResult }),
142
- };
143
- } else if (entry.presentation?.script !== undefined || entry.presentation?.isError) {
144
- const projected = structuredRead(entry.presentation);
145
- const outcome = projected.structuredContent;
146
- if (record(outcome)) {
147
- data = outcome.data;
148
- if (Array.isArray(outcome.errors))
149
- for (const error of outcome.errors)
150
- if (record(error)) failures.push(resultError(error.message, String(error.code)));
151
- }
152
- } else if (record(value.structured)) {
153
- data = value.structured.data;
154
- if (Array.isArray(value.structured.errors))
155
- for (const error of value.structured.errors)
156
- if (record(error)) failures.push(resultError(error.message, String(error.code)));
157
- } else if (typeof value.source === "string") {
158
- data = { source: value.source };
159
- } else if (value.ok === false) {
160
- failures.push(
161
- resultError(
162
- record(value.error) ? value.error.message : "Operation failed",
163
- "APPLY_OPERATION_FAILED",
164
- ),
165
- );
166
- } else {
167
- failures.push(resultError("Operation did not report structured data", "UNKNOWN_RESULT"));
168
- }
169
- errors.push(...failures);
170
- operations.push({
171
- id: entry.id,
172
- kind: entry.kind,
173
- ...(typeof value.fullResult === "string" ? { fullResult: value.fullResult } : {}),
174
- ...(typeof value.fullResultBytes === "number"
175
- ? { fullResultBytes: value.fullResultBytes }
176
- : {}),
177
- status:
178
- failures.length === 0
179
- ? "success"
180
- : entry.kind === "mutation" && value.effect === "applied"
181
- ? "partial"
182
- : "error",
183
- ...(data === undefined ? {} : { data }),
184
- errors: failures,
185
- });
186
- }
187
- const selected = results.select();
188
- const status =
189
- errors.length === 0
190
- ? "success"
191
- : applied || operations.some((operation) => operation.status === "success")
192
- ? "partial"
193
- : "error";
194
- const data = {
195
- operations,
196
- files: selected.files.map((file) => file.source),
197
- transactions: [...transactions],
198
- values: selected.explicit.filter((entry) => entry.kind === "value").map((entry) => entry.value),
199
- truncated: false,
200
- };
201
- if (
202
- results.mutationValues().some((value) => record(value) && value.truncated === true) ||
203
- Buffer.byteLength(JSON.stringify(data)) > 512 * 1024
204
- ) {
205
- const fullResult = await read.saveTemporary(JSON.stringify(data, null, 2));
206
- const oversized = Buffer.byteLength(JSON.stringify(data)) > 512 * 1024;
207
- const withoutReads = operations.map((operation) => {
208
- if (!oversized || operation.kind === "mutation") return operation;
209
- const { data: _detail, ...summary } = operation;
210
- return summary;
211
- });
212
- const mutationsOversized = Buffer.byteLength(JSON.stringify(withoutReads)) > 512 * 1024;
213
- const summaries = withoutReads.map((operation) => {
214
- if (!mutationsOversized || !("data" in operation)) return operation;
215
- const { data: detail, ...summary } = operation;
216
- const value = record(detail) ? detail : undefined;
217
- return {
218
- ...summary,
219
- ...(operation.kind === "mutation" && value !== undefined
220
- ? {
221
- data: {
222
- operation: value.operation,
223
- effect: value.effect,
224
- files: value.files,
225
- ...(typeof value.transaction === "string"
226
- ? { transaction: value.transaction }
227
- : {}),
228
- },
229
- }
230
- : {}),
231
- };
232
- });
233
- return withStructuredResult(result, applyDataSchema, {
234
- status,
235
- data: {
236
- operations: summaries,
237
- files: data.files,
238
- transactions: data.transactions,
239
- values: [],
240
- truncated: true,
241
- fullResult,
242
- },
243
- errors,
244
- });
245
- }
246
- return withStructuredResult(result, applyDataSchema, {
247
- status,
248
- data,
249
- errors,
250
- });
251
- }