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
@@ -0,0 +1,384 @@
1
+ import { Type, type Static } from "typebox";
2
+ import { resultInputSchema, structuredResultSchema } from "pi-agent-resource";
3
+
4
+ const textOperationSchema = Type.Union([
5
+ Type.Object(
6
+ {
7
+ kind: Type.Literal("range"),
8
+ startLine: Type.Integer({ minimum: 1 }),
9
+ startColumn: Type.Integer({ minimum: 0 }),
10
+ endLine: Type.Integer({ minimum: 1 }),
11
+ endColumn: Type.Integer({ minimum: 0 }),
12
+ },
13
+ {
14
+ additionalProperties: false,
15
+ description:
16
+ "Use absolute one-based lines and exclusive UTF-16 columns in one source. Require full containment in an input region.",
17
+ },
18
+ ),
19
+ Type.Object(
20
+ {
21
+ kind: Type.Literal("lines"),
22
+ first: Type.Integer({ minimum: 1 }),
23
+ last: Type.Integer({ minimum: 1 }),
24
+ },
25
+ {
26
+ additionalProperties: false,
27
+ description:
28
+ "Use inclusive absolute line numbers in one source. Include existing line endings; require full containment in an input region.",
29
+ },
30
+ ),
31
+ Type.Object(
32
+ {
33
+ kind: Type.Literal("between"),
34
+ start: Type.String({ minLength: 1 }),
35
+ end: Type.String({ minLength: 1 }),
36
+ extent: Type.Union([Type.Literal("inside"), Type.Literal("around"), Type.Literal("lines")]),
37
+ },
38
+ {
39
+ additionalProperties: false,
40
+ description:
41
+ "Pair non-empty literal opening markers with the next closing marker per region, without nesting. Resume after each pair; unmatched openings are errors. inside excludes markers, around includes them, lines explicitly expands to complete containing lines.",
42
+ },
43
+ ),
44
+ Type.Object(
45
+ {
46
+ kind: Type.Literal("sliceText"),
47
+ from: Type.Integer({ minimum: 0 }),
48
+ to: Type.Optional(Type.Integer({ minimum: 0 })),
49
+ },
50
+ {
51
+ additionalProperties: false,
52
+ description:
53
+ "Slice each region by non-negative relative UTF-16 offsets. The exclusive to defaults to its end. Equal offsets select a zero-width point.",
54
+ },
55
+ ),
56
+ Type.Object(
57
+ {
58
+ kind: Type.Literal("trim"),
59
+ side: Type.Union([Type.Literal("start"), Type.Literal("end"), Type.Literal("both")]),
60
+ },
61
+ {
62
+ additionalProperties: false,
63
+ description:
64
+ "Trim Unicode whitespace from the requested edges of each region. A whitespace-only region selects a zero-width point at its end.",
65
+ },
66
+ ),
67
+ Type.Object(
68
+ {
69
+ kind: Type.Literal("split"),
70
+ delimiter: Type.String({ minLength: 1 }),
71
+ },
72
+ {
73
+ additionalProperties: false,
74
+ description:
75
+ "Split each region by a non-empty literal delimiter, excluding delimiters and retaining empty segments as zero-width points.",
76
+ },
77
+ ),
78
+ Type.Object(
79
+ {
80
+ kind: Type.Literal("linesOf"),
81
+ },
82
+ {
83
+ additionalProperties: false,
84
+ description:
85
+ "Expand each region to complete containing lines, preserving line endings and reporting expansion. An exclusive end at next-line column zero does not include that next line.",
86
+ },
87
+ ),
88
+ Type.Object(
89
+ {
90
+ kind: Type.Literal("position"),
91
+ edge: Type.Union([Type.Literal("before"), Type.Literal("after")]),
92
+ },
93
+ {
94
+ additionalProperties: false,
95
+ description:
96
+ "Select the zero-width start or end of each region. Use a whole-file Read for file edges.",
97
+ },
98
+ ),
99
+ Type.Object(
100
+ {
101
+ kind: Type.Literal("columns"),
102
+ from: Type.Integer({ minimum: 0 }),
103
+ to: Type.Integer({ minimum: 0 }),
104
+ },
105
+ {
106
+ additionalProperties: false,
107
+ description:
108
+ "Select an exclusive UTF-16 column interval on each touched line, excluding line endings. Every interval must fit its line and original input region; no clipping.",
109
+ },
110
+ ),
111
+ ]);
112
+
113
+ function scopedOperation<const Kind extends "within" | "intersection" | "difference">(
114
+ kind: Kind,
115
+ description: string,
116
+ ) {
117
+ return Type.Object(
118
+ {
119
+ kind: Type.Literal(kind),
120
+ scopes: {
121
+ ...resultInputSchema,
122
+ description:
123
+ "Comparison scopes: verified results, data, targets, item arrays, or a readable source string. Match sets by source, not array position.",
124
+ },
125
+ },
126
+ { additionalProperties: false, description },
127
+ );
128
+ }
129
+
130
+ const geometryOperationSchema = Type.Union([
131
+ scopedOperation(
132
+ "within",
133
+ "Retain each candidate whole only when one comparison scope contains it. Never clip or join scopes for containment.",
134
+ ),
135
+ scopedOperation(
136
+ "intersection",
137
+ "Clip each candidate to the union of comparison scopes in its source. Touching text ranges do not create a point.",
138
+ ),
139
+ scopedOperation(
140
+ "difference",
141
+ "Subtract comparison scopes from each candidate, retaining separate surviving fragments. Point scopes do not cut text.",
142
+ ),
143
+ Type.Object(
144
+ {
145
+ kind: Type.Literal("merge"),
146
+ adjacent: Type.Optional(
147
+ Type.Boolean({
148
+ description:
149
+ "Also merge touching nonempty ranges. Default false; never fill a gap or extend text for a point.",
150
+ }),
151
+ ),
152
+ },
153
+ {
154
+ additionalProperties: false,
155
+ description:
156
+ "Explicitly merge overlapping ranges by source, retaining every contributing origin. Covered points are absorbed; other points remain separate.",
157
+ },
158
+ ),
159
+ ]);
160
+
161
+ const astObjectSchema = Type.Union([
162
+ Type.Literal("function"),
163
+ Type.Literal("call"),
164
+ Type.Literal("class"),
165
+ Type.Literal("if"),
166
+ Type.Literal("switch"),
167
+ Type.Literal("loop"),
168
+ Type.Literal("try"),
169
+ Type.Literal("catch"),
170
+ Type.Literal("binding"),
171
+ Type.Literal("assignment"),
172
+ Type.Literal("object"),
173
+ Type.Literal("property"),
174
+ Type.Literal("array"),
175
+ Type.Literal("return"),
176
+ Type.Literal("throw"),
177
+ ]);
178
+ const astPartSchema = Type.Union([
179
+ Type.Literal("name"),
180
+ Type.Literal("body"),
181
+ Type.Literal("parameters"),
182
+ Type.Literal("returnType"),
183
+ Type.Literal("type"),
184
+ Type.Literal("callee"),
185
+ Type.Literal("arguments"),
186
+ Type.Literal("condition"),
187
+ Type.Literal("then"),
188
+ Type.Literal("else"),
189
+ Type.Literal("initializer"),
190
+ Type.Literal("update"),
191
+ Type.Literal("iterable"),
192
+ Type.Literal("left"),
193
+ Type.Literal("right"),
194
+ Type.Literal("value"),
195
+ Type.Literal("key"),
196
+ Type.Literal("handler"),
197
+ Type.Literal("finalizer"),
198
+ Type.Literal("parameter"),
199
+ ]);
200
+ const objectFilter = Type.Optional({
201
+ ...astObjectSchema,
202
+ description:
203
+ "Filter results by construct category after navigation. The filter does not change parent/child/sibling relationships.",
204
+ });
205
+ const structuralOperationSchema = Type.Union([
206
+ Type.Object(
207
+ {
208
+ kind: Type.Literal("elementExtent"),
209
+ extent: Type.Union([Type.Literal("inside"), Type.Literal("around")]),
210
+ },
211
+ {
212
+ additionalProperties: false,
213
+ description:
214
+ "Select an exact direct JS/TS call argument or parenthesized function parameter. inside keeps the element; around includes owned comma/whitespace. Prefer the following separator; last without a trailing comma uses the preceding gap; only elements own the list interior. Adjacent boundary comments reject around. No destination syntax repair.",
215
+ },
216
+ ),
217
+ Type.Object(
218
+ {
219
+ kind: Type.Literal("object"),
220
+ object: astObjectSchema,
221
+ relation: Type.Optional(Type.Literal("enclosing")),
222
+ level: Type.Optional(
223
+ Type.Integer({
224
+ minimum: 1,
225
+ description: "Default 1 (nearest). Count only constructs of the requested category.",
226
+ }),
227
+ ),
228
+ extent: Type.Optional(Type.Literal("around")),
229
+ },
230
+ {
231
+ additionalProperties: false,
232
+ description:
233
+ "Select the requested containing construct. level=1 is nearest and includes an exact seed; higher levels count only that category. Match the entire seed, not its first character.",
234
+ },
235
+ ),
236
+ Type.Object(
237
+ { kind: Type.Literal("part"), part: astPartSchema },
238
+ {
239
+ additionalProperties: false,
240
+ description:
241
+ "Select an exact supported construct's named part, including delimiters belonging to its syntax node. A supported optional part may be absent; unsupported parts are errors with available names. Use an enclosing object first for partial input.",
242
+ },
243
+ ),
244
+ Type.Object(
245
+ {
246
+ kind: Type.Literal("navigate"),
247
+ relation: Type.Union([
248
+ Type.Literal("parent"),
249
+ Type.Literal("ancestors"),
250
+ Type.Literal("children"),
251
+ Type.Literal("descendants"),
252
+ ]),
253
+ object: objectFilter,
254
+ },
255
+ {
256
+ additionalProperties: false,
257
+ description:
258
+ "Navigate from an exact named syntax node, including constructs, part targets and the document root. Skip parser-only wrappers in results. Exclude the starting node; ancestors/descendants return results in source order. parent/children never skip recognized constructs to satisfy a filter. Use enclosing first for ranges that cut through a node.",
259
+ },
260
+ ),
261
+ Type.Object(
262
+ {
263
+ kind: Type.Literal("navigate"),
264
+ relation: Type.Literal("siblings"),
265
+ object: objectFilter,
266
+ direction: Type.Optional(
267
+ Type.Union([Type.Literal("previous"), Type.Literal("next"), Type.Literal("all")], {
268
+ description:
269
+ "Default all. previous/next select the immediate sibling before category filtering, not the next matching category.",
270
+ }),
271
+ ),
272
+ },
273
+ {
274
+ additionalProperties: false,
275
+ description:
276
+ "Select siblings of an exact supported construct under the same normalized parent. Exclude the input; return source order. A missing neighbor is valid absence.",
277
+ },
278
+ ),
279
+ ]);
280
+ /** Normalized JS/TS constructs, independent of parser-only wrapper nodes. */
281
+ export type AstObject = Static<typeof astObjectSchema>;
282
+ /** Named construct parts. Availability depends on the actual node form. */
283
+ export type AstPart = Static<typeof astPartSchema>;
284
+ /** Callable text and structural transformations; future catalog entries are not exposed here. */
285
+ export const selectSchema = Type.Object(
286
+ {
287
+ path: {
288
+ ...resultInputSchema,
289
+ description:
290
+ "Pass a compatible source result, its data or RESULT# target, a returned-item array, or a file path. Preview text and reconstructed coordinates are not source targets.",
291
+ },
292
+ operation: Type.Union([
293
+ structuralOperationSchema,
294
+ textOperationSchema,
295
+ geometryOperationSchema,
296
+ ]),
297
+ },
298
+ { additionalProperties: false },
299
+ );
300
+
301
+ /** Inputs accepted by the Select tool. */
302
+ export type SelectParameters = Static<typeof selectSchema>;
303
+ /** Supported source transformations. */
304
+ export type SelectOperation = SelectParameters["operation"];
305
+ /** AST operations require the existing syntax provider. */
306
+ export type StructuralSelectOperation = Static<typeof structuralOperationSchema>;
307
+ /** Geometry operations compare verified source-local sets. */
308
+ export type GeometrySelectOperation = Static<typeof geometryOperationSchema>;
309
+ /** Text operations work independently of a source language or parser. */
310
+ export type TextSelectOperation = Exclude<
311
+ SelectOperation,
312
+ StructuralSelectOperation | GeometrySelectOperation
313
+ >;
314
+
315
+ const rangeSchema = Type.Object(
316
+ {
317
+ startLine: Type.Integer({ minimum: 1 }),
318
+ startColumn: Type.Integer({ minimum: 0 }),
319
+ endLine: Type.Integer({ minimum: 1 }),
320
+ endColumn: Type.Integer({ minimum: 0 }),
321
+ },
322
+ { additionalProperties: false },
323
+ );
324
+
325
+ /** Source-backed selection set with bounded previews and retained input associations. */
326
+ export const selectionDataSchema = Type.Object(
327
+ {
328
+ kind: Type.Literal("selection"),
329
+ target: Type.String({
330
+ description: "Stored target for every selected range, including items beyond the preview.",
331
+ }),
332
+ complete: Type.Boolean({
333
+ description:
334
+ "Execution completeness inherited from all inputs, independent of preview limits.",
335
+ }),
336
+ totalItems: Type.Integer({ minimum: 0 }),
337
+ missingInputs: Type.Integer({ minimum: 0 }),
338
+ truncated: Type.Boolean(),
339
+ items: Type.Array(
340
+ Type.Object(
341
+ {
342
+ target: Type.String(),
343
+ source: Type.String(),
344
+ range: rangeSchema,
345
+ syntax: Type.Optional(
346
+ Type.Object(
347
+ {
348
+ object: astObjectSchema,
349
+ part: Type.Optional(astPartSchema),
350
+ },
351
+ {
352
+ additionalProperties: false,
353
+ description:
354
+ "Parser-derived normalized construct category and selected part. This describes the target; it is not edit authority.",
355
+ },
356
+ ),
357
+ ),
358
+ origins: Type.Array(
359
+ Type.Object(
360
+ {
361
+ source: Type.String(),
362
+ range: rangeSchema,
363
+ expanded: Type.Boolean(),
364
+ },
365
+ { additionalProperties: false },
366
+ ),
367
+ ),
368
+ preview: Type.String({ maxLength: 1000 }),
369
+ textTruncated: Type.Boolean(),
370
+ },
371
+ { additionalProperties: false },
372
+ ),
373
+ { maxItems: 100 },
374
+ ),
375
+ },
376
+ { additionalProperties: false },
377
+ );
378
+
379
+ /** Structured output; editable authority is stored in its targets, not these coordinates. */
380
+ export type SelectionData = Static<typeof selectionDataSchema>;
381
+ /** One individually consumable selection and the inputs that produced it. */
382
+ export type SelectionItem = SelectionData["items"][number];
383
+ /** Public structured success/error envelope for Select. */
384
+ export const selectOutputSchema = structuredResultSchema(selectionDataSchema);
@@ -0,0 +1,41 @@
1
+ import type { ResultRange, ResultSourceTarget } from "pi-agent-resource";
2
+ import type { SelectionItem } from "./select-schema.js";
3
+
4
+ /** A structural or text refusal is distinct from valid absence. */
5
+ export class SelectionError extends Error {
6
+ public constructor(
7
+ public readonly code: string,
8
+ message: string,
9
+ ) {
10
+ super(message);
11
+ }
12
+ }
13
+
14
+ /** Verified geometry and original seed associations before handles and previews are added. */
15
+ export interface SelectedRegion {
16
+ readonly target: ResultSourceTarget;
17
+ readonly range: ResultRange;
18
+ readonly text: string;
19
+ readonly origins: SelectionItem["origins"];
20
+ readonly syntax?: SelectionItem["syntax"];
21
+ }
22
+
23
+ /** Coordinates use one-based lines and exclusive UTF-16 character ends. */
24
+ export function publicRange(range: ResultRange): SelectionItem["range"] {
25
+ return {
26
+ startLine: range.start.lineNumber,
27
+ startColumn: range.start.column,
28
+ endLine: range.end.lineNumber,
29
+ endColumn: range.end.column,
30
+ };
31
+ }
32
+
33
+ /** Deduplicate output geometry without losing any original input association. */
34
+ export function retainRegion(selected: Map<string, SelectedRegion>, region: SelectedRegion): void {
35
+ const identity = JSON.stringify([region.target.source, region.range]);
36
+ const previous = selected.get(identity);
37
+ selected.set(
38
+ identity,
39
+ previous ? { ...region, origins: [...previous.origins, ...region.origins] } : region,
40
+ );
41
+ }
@@ -0,0 +1,92 @@
1
+ import { createTextDocument } from "pi-agent-text";
2
+ import type { ResultRange } from "pi-agent-resource";
3
+ import { SelectionError } from "./selection-region.js";
4
+
5
+ interface SourceLine {
6
+ readonly start: number;
7
+ readonly length: number;
8
+ readonly end: number;
9
+ }
10
+
11
+ /** Map retained text coordinates without normalizing line endings or splitting source characters. */
12
+ export class SourceText {
13
+ public readonly lines: readonly SourceLine[];
14
+ public constructor(public readonly content: string) {
15
+ let start = 0;
16
+ const document = createTextDocument("", content);
17
+ const lines = document.lines.map((line) => {
18
+ const from = start;
19
+ start += line.content.length + line.lineEnding.length;
20
+ return { start: from, length: line.content.length, end: start };
21
+ });
22
+ if (lines.length === 0 || document.lines.at(-1)?.lineEnding)
23
+ lines.push({ start, length: 0, end: start });
24
+ this.lines = lines;
25
+ }
26
+
27
+ /** Validate one exact character boundary, including CRLF and surrogate-pair integrity. */
28
+ public boundary(offset: number): void {
29
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset > this.content.length)
30
+ throw new SelectionError("INVALID_RANGE", "Text bounds are outside the retained snapshot.");
31
+ const left = this.content.charCodeAt(offset - 1);
32
+ const right = this.content.charCodeAt(offset);
33
+ if (
34
+ (left >= 0xd800 && left <= 0xdbff && right >= 0xdc00 && right <= 0xdfff) ||
35
+ (left === 13 && right === 10)
36
+ )
37
+ throw new SelectionError(
38
+ "INVALID_BOUNDARY",
39
+ "Text boundary splits a surrogate pair or CRLF separator.",
40
+ );
41
+ }
42
+
43
+ /** Resolve absolute source coordinates; columns do not include line-ending characters. */
44
+ public offset(position: ResultRange["start"]): number {
45
+ const line = this.lines[position.lineNumber - 1];
46
+ if (
47
+ !Number.isSafeInteger(position.lineNumber) ||
48
+ !line ||
49
+ !Number.isSafeInteger(position.column) ||
50
+ position.column < 0 ||
51
+ position.column > line.length
52
+ )
53
+ throw new SelectionError("INVALID_RANGE", "Source bounds are outside the retained snapshot.");
54
+ const offset = line.start + position.column;
55
+ this.boundary(offset);
56
+ return offset;
57
+ }
58
+
59
+ /** Find the physical containing line, including separator bytes, without creating a boundary. */
60
+ public lineIndex(offset: number): number {
61
+ let low = 0;
62
+ let high = this.lines.length - 1;
63
+ while (low < high) {
64
+ const middle = Math.ceil((low + high) / 2);
65
+ if ((this.lines[middle]?.start ?? 0) <= offset) low = middle;
66
+ else high = middle - 1;
67
+ }
68
+ return low;
69
+ }
70
+
71
+ /** Convert a validated offset to an exclusive source position. */
72
+ public position(offset: number): ResultRange["start"] {
73
+ this.boundary(offset);
74
+ const index = this.lineIndex(offset);
75
+ return { lineNumber: index + 1, column: offset - (this.lines[index]?.start ?? 0) };
76
+ }
77
+
78
+ /** Build canonical character ranges; line endings remain represented by next-line column zero. */
79
+ public range(from: number, to: number): ResultRange {
80
+ if (to < from) throw new SelectionError("INVALID_RANGE", "Text bounds are reversed.");
81
+ return { start: this.position(from), end: this.position(to) };
82
+ }
83
+
84
+ /** Return the complete physical lines touched by a half-open range or caret. */
85
+ public fullLines(from: number, to: number): { from: number; to: number } {
86
+ const first = this.lines[this.lineIndex(from)];
87
+ const last = this.lines[this.lineIndex(to > from ? to - 1 : from)];
88
+ if (!first || !last)
89
+ throw new SelectionError("INVALID_RANGE", "Source line bounds are unavailable.");
90
+ return { from: first.start, to: last.end };
91
+ }
92
+ }