pi-agent-ide 0.6.4 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (431) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/chunk-2TRHFMCZ.js +11 -0
  5. package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
  6. package/dist/chunk-4XMY4H4V.js +1 -0
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
  9. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  10. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  11. package/dist/chunk-CWD4O5PM.js +3 -0
  12. package/dist/chunk-D3WTDA6V.js +2 -0
  13. package/dist/chunk-EAZGN5ND.js +7 -0
  14. package/dist/chunk-GXEGY7GV.js +1 -0
  15. package/dist/chunk-HZEY4GT4.js +2 -0
  16. package/dist/chunk-LEEQIQ7D.js +28 -0
  17. package/dist/chunk-NRZO5KJT.js +9 -0
  18. package/dist/chunk-OMVRLWMX.js +5 -0
  19. package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
  20. package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
  21. package/dist/chunk-PNU3E7IO.js +3 -0
  22. package/dist/chunk-PS2B6THP.js +3 -0
  23. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  24. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  25. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  26. package/dist/chunk-VMTR74FF.js +2 -0
  27. package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
  28. package/dist/chunk-WU6ZK6YD.js +1 -0
  29. package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
  30. package/dist/chunk-XYS4FSCC.js +12 -0
  31. package/dist/chunk-YP46DVVP.js +2 -0
  32. package/dist/entry-11.js +1 -1
  33. package/dist/entry-13.js +1 -1
  34. package/dist/entry-14.js +1 -1
  35. package/dist/entry-15.js +1 -1
  36. package/dist/entry-17.js +1 -1
  37. package/dist/entry-25.js +2 -2
  38. package/dist/entry-26.js +1 -1
  39. package/dist/entry-27.js +2 -2
  40. package/dist/entry-28.js +1 -1
  41. package/dist/entry-29.js +1 -1
  42. package/dist/entry-30.js +1 -1
  43. package/dist/entry-31.js +12 -9
  44. package/dist/entry-33.js +1 -1
  45. package/dist/entry-37.js +6 -6
  46. package/dist/entry-41.js +1 -1
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-43.js +1 -1
  49. package/dist/entry-44.js +1 -1
  50. package/dist/entry-45.js +13 -14
  51. package/dist/entry-46.js +1 -1
  52. package/dist/entry-49.js +1 -1
  53. package/dist/entry-50.js +3 -6
  54. package/dist/entry-51.js +11 -9
  55. package/dist/entry-52.js +1 -1
  56. package/dist/entry-53.js +1 -1
  57. package/dist/entry-54.js +1 -1
  58. package/dist/entry-56.js +1 -1
  59. package/dist/entry-57.js +1 -1
  60. package/dist/entry-58.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +0 -1
  63. package/dist/entry-62.js +1 -0
  64. package/dist/entry-63.js +0 -1
  65. package/dist/entry-64.js +1 -0
  66. package/dist/entry-65.js +1 -1
  67. package/dist/entry-66.js +1 -1
  68. package/dist/entry-67.js +1 -1
  69. package/dist/entry-68.js +1 -1
  70. package/dist/entry-69.js +1 -1
  71. package/dist/entry-70.js +1 -1
  72. package/dist/entry-71.js +0 -1
  73. package/dist/entry-72.js +1 -0
  74. package/dist/entry-73.js +0 -1
  75. package/dist/entry-74.js +1 -0
  76. package/dist/entry-75.js +1 -1
  77. package/dist/entry-76.js +1 -1
  78. package/dist/entry-77.js +66 -1
  79. package/dist/entry-78.js +14 -325
  80. package/dist/entry-79.js +2 -18
  81. package/dist/entry-80.js +1 -2
  82. package/dist/entry-81.js +1 -1
  83. package/dist/entry-82.js +5 -1
  84. package/dist/entry-83.js +3 -5
  85. package/dist/entry-84.js +1 -3
  86. package/dist/entry-85.js +1 -1
  87. package/dist/entry-86.js +1 -1
  88. package/dist/pi-agent-ide.js +14 -9
  89. package/docs/agent-guides/editing.md +38 -33
  90. package/docs/agent-guides/git-changes.md +1 -1
  91. package/docs/agent-guides/read-resources.md +8 -4
  92. package/docs/agent-guides/search-code.md +34 -2
  93. package/docs/agent-guides/select-code.md +115 -0
  94. package/docs/configuration.md +12 -17
  95. package/docs/development.md +2 -1
  96. package/docs/releases.md +1 -1
  97. package/docs/research/apply-native-capability-matrix.md +174 -0
  98. package/docs/research/apply-read-latency.md +2 -0
  99. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  100. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  101. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  102. package/docs/research/native-codemode-batch-decision.md +2 -0
  103. package/docs/research/native-codemode-batching.md +1 -1
  104. package/docs/structured-results.md +30 -38
  105. package/docs/tools.md +11 -11
  106. package/docs/user-hooks.md +1 -1
  107. package/node_modules/pi-agent-doctor/package.json +1 -1
  108. package/node_modules/pi-agent-documentation/package.json +1 -1
  109. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  110. package/node_modules/pi-agent-filesystem/package.json +7 -7
  111. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  112. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  113. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  114. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  115. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  116. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  117. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  119. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  120. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  121. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  122. package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
  123. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  124. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  125. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  126. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  127. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  128. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  129. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  130. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
  131. package/node_modules/pi-agent-ide-changes/index.ts +6 -21
  132. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  133. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  134. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  135. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  136. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  137. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  138. package/node_modules/pi-agent-ide-lsp/index.ts +5 -5
  139. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-invariant/package.json +1 -1
  148. package/node_modules/pi-agent-pdf/package.json +2 -2
  149. package/node_modules/pi-agent-read/package.json +7 -7
  150. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  151. package/node_modules/pi-agent-read/src/api/read-parameters.ts +40 -3
  152. package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
  153. package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
  154. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  155. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  156. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  157. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  158. package/node_modules/pi-agent-resource/package.json +1 -1
  159. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  160. package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
  161. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  162. package/node_modules/pi-agent-search/package.json +5 -5
  163. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  164. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  165. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  166. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  167. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  168. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  169. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  170. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  171. package/node_modules/pi-agent-search-text/index.ts +3 -1
  172. package/node_modules/pi-agent-search-text/package.json +7 -6
  173. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  174. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  175. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  176. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  177. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  178. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  179. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  180. package/node_modules/pi-agent-text/package.json +2 -2
  181. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  182. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  183. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  188. package/node_modules/pi-agent-text-editor/package.json +26 -31
  189. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  190. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  192. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  193. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  194. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  195. package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
  196. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  197. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  198. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  199. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  201. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  202. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  203. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  204. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  205. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  206. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  207. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  208. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  209. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  210. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  211. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  212. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  213. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  214. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  215. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  216. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  217. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  218. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  219. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  220. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  221. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  222. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  223. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  224. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  225. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  226. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  227. package/node_modules/pi-agent-web/index.ts +7 -3
  228. package/node_modules/pi-agent-web/package.json +8 -8
  229. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  230. package/node_modules/pi-agent-web/src/search.ts +111 -2
  231. package/node_modules/pi-agent-web-html/package.json +3 -3
  232. package/node_modules/pi-agent-web-image/package.json +4 -4
  233. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  234. package/node_modules/pi-agent-web-text/package.json +4 -4
  235. package/package.json +35 -36
  236. package/src/composite/module-labels.ts +1 -1
  237. package/src/composite/preferences.ts +0 -5
  238. package/src/composite/text-results.ts +221 -0
  239. package/src/documentation/extension.ts +11 -9
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  247. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +7 -3
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  256. package/src/extensions/pi-agent-read/package.json +7 -7
  257. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  258. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +40 -3
  259. package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
  260. package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
  261. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  262. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  263. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  264. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  265. package/src/extensions/pi-agent-search/package.json +5 -5
  266. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  267. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  268. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  269. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  270. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  271. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  272. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  273. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  274. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  275. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  276. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  277. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  278. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  279. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  280. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  281. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  282. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  283. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  284. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  285. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  286. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  287. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  288. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  289. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  290. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  291. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  292. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  293. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  294. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  295. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  296. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  297. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  298. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  299. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  300. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  301. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  302. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  303. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
  304. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  305. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  306. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  307. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  308. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  309. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  310. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  311. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  312. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  313. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  314. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  315. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  316. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  317. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  318. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  319. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  320. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  321. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  322. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  323. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  324. package/src/pi-agent-ide.ts +4 -7
  325. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  326. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  327. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  328. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  329. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  330. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  331. package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
  332. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  333. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  334. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  335. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  336. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  337. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  338. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  339. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
  340. package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
  341. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  342. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  343. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  344. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  345. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  346. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  347. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  348. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  349. package/src/plugins/pi-agent-ide-lsp/index.ts +5 -5
  350. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  351. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  352. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  353. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  354. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  355. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  356. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  357. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  358. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  359. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  360. package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
  361. package/dist/chunk-2P2OGO3G.js +0 -2
  362. package/dist/chunk-5J43L2RL.js +0 -11
  363. package/dist/chunk-6EYWFBNG.js +0 -0
  364. package/dist/chunk-7AVXUV4A.js +0 -7
  365. package/dist/chunk-7WCZOO5I.js +0 -1
  366. package/dist/chunk-BAYETTZZ.js +0 -16
  367. package/dist/chunk-BVK5A7ED.js +0 -28
  368. package/dist/chunk-F7NVAC4Q.js +0 -0
  369. package/dist/chunk-FZBCKIJJ.js +0 -1
  370. package/dist/chunk-I5JLCFUX.js +0 -1
  371. package/dist/chunk-KUPHNMUK.js +0 -2
  372. package/dist/chunk-MIZAFRDR.js +0 -1
  373. package/dist/chunk-PJPA5EEE.js +0 -2
  374. package/dist/chunk-PXWDDBBC.js +0 -0
  375. package/dist/chunk-SILJ3OL4.js +0 -9
  376. package/dist/chunk-TQZBVOTT.js +0 -5
  377. package/dist/chunk-VWW3RLUX.js +0 -12
  378. package/dist/chunk-YHUTTZC6.js +0 -2
  379. package/dist/chunk-ZODCBFBL.js +0 -2
  380. package/dist/entry-87.js +0 -1
  381. package/docs/agent-guides/apply.md +0 -333
  382. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  383. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  384. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  385. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  386. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  387. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  388. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  389. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  390. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  391. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  392. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  393. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  394. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  395. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  396. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  397. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  398. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  399. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  400. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  401. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  402. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  403. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  404. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  405. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  406. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  407. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  408. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  409. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  410. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  411. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  412. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  413. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  414. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  415. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  416. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  417. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  418. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  419. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  420. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  421. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  422. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  423. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  424. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  425. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  426. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  427. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  428. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  429. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  430. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  431. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
@@ -30,6 +30,7 @@ const text = Type.Object(
30
30
  {
31
31
  ...common,
32
32
  kind: Type.Literal("text"),
33
+ target: Type.Optional(Type.String()),
33
34
  lines: Type.Array(line),
34
35
  startLine: Type.Integer(),
35
36
  endLine: Type.Integer(),
@@ -52,7 +53,7 @@ const bytes = Type.Object(
52
53
  const block = Type.Union([
53
54
  Type.Object({ type: Type.Literal("text"), text: Type.String() }, { additionalProperties: false }),
54
55
  Type.Object(
55
- { type: Type.Literal("image"), data: Type.String(), mimeType: Type.String() },
56
+ { type: Type.Literal("image"), mimeType: Type.String() },
56
57
  { additionalProperties: false },
57
58
  ),
58
59
  ]);
@@ -126,6 +127,7 @@ function publicData(value: ReadScriptData): unknown {
126
127
  : {}),
127
128
  };
128
129
  }
130
+ // Image bytes belong to native content, not the composable result record.
129
131
  if (value.kind === "native")
130
132
  return {
131
133
  kind: value.kind,
@@ -133,8 +135,7 @@ function publicData(value: ReadScriptData): unknown {
133
135
  truncated: false,
134
136
  blocks: value.blocks.map((block) => {
135
137
  if (block.type === "text") return { type: block.type, text: block.text };
136
- if (block.type === "image")
137
- return { type: block.type, data: block.data, mimeType: block.mimeType };
138
+ if (block.type === "image") return { type: block.type, mimeType: block.mimeType };
138
139
  throw new TypeError("Custom content requires a structured adapter");
139
140
  }),
140
141
  };
@@ -161,6 +162,7 @@ function publicData(value: ReadScriptData): unknown {
161
162
  endLine: lines.at(-1)?.lineNumber ?? 0,
162
163
  totalLines: value.totalLines,
163
164
  truncated,
165
+ ...(value.target === undefined ? {} : { target: value.target }),
164
166
  ...(value.references === undefined ? {} : { references: value.references }),
165
167
  ...(truncated || endLine < value.totalLines
166
168
  ? { continuation: { path: value.source, offset: endLine + 1 } }
@@ -56,7 +56,11 @@ import {
56
56
  } from "#src/core/tools/read/read-result.js";
57
57
  import { TempResourceStore } from "#src/core/tools/read/temp-resource-store.js";
58
58
 
59
- import { readParameters } from "#src/api/read-parameters.js";
59
+ import {
60
+ type readParameters,
61
+ describeReadParameters,
62
+ type ReadParameterText,
63
+ } from "#src/api/read-parameters.js";
60
64
  import { readRaw } from "#src/core/tools/read/raw-read.js";
61
65
  import { readOutputSchema, structuredRead } from "./read/structured-result.js";
62
66
 
@@ -126,6 +130,7 @@ export interface ReadTool {
126
130
  export function createReadTool(
127
131
  pluginPromptGuidelines?: () => readonly string[],
128
132
  presentation: "full" | "compact" | "disabled" = "compact",
133
+ parameterDescriptions?: () => ReadParameterText,
129
134
  ): ReadTool {
130
135
  const temporaryResources = new TempResourceStore();
131
136
  const resolvers: RegisteredResolver[] = [
@@ -172,7 +177,9 @@ export function createReadTool(
172
177
  ...(pluginPromptGuidelines?.() ?? []),
173
178
  ];
174
179
  },
175
- parameters: readParameters,
180
+ get parameters() {
181
+ return describeReadParameters(parameterDescriptions?.() ?? {});
182
+ },
176
183
  outputSchema: readOutputSchema,
177
184
  renderCall(arguments_, theme, context) {
178
185
  const source = typeof arguments_.path === "string" ? arguments_.path : undefined;
@@ -606,8 +613,15 @@ async function resolveTextTargets(
606
613
  { start: { lineNumber: 1, column: 0 }, end: { lineNumber: 1, column: 1 } },
607
614
  ];
608
615
  return ranges.map(async (range): Promise<ReadToolResult> => {
609
- const rangeLimit = Math.max(1, range.end.lineNumber - range.start.lineNumber);
616
+ const sourceTarget = request.path?.startsWith("RESULT#") ? request.path : undefined;
617
+ const rangeLimit = Math.max(
618
+ 1,
619
+ range.end.lineNumber -
620
+ range.start.lineNumber +
621
+ (sourceTarget !== undefined && range.end.column > 0 ? 1 : 0),
622
+ );
610
623
  let rangePipeline: ReadPipelineContext = {
624
+ sourceTarget,
611
625
  request: {
612
626
  ...request,
613
627
  path: target.source,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-resource",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "imports": {
@@ -86,3 +86,13 @@ export {
86
86
  isResourceResolutionAttempt,
87
87
  isResourceResolver,
88
88
  } from "./validation.js";
89
+
90
+ export {
91
+ connectResultTargets,
92
+ verifyResultTargets,
93
+ ResultTargetStore,
94
+ resultInputSchema,
95
+ type ResultRange,
96
+ type ResultSourceTarget,
97
+ type ResolvedResultTargets,
98
+ } from "./result-targets.js";
@@ -0,0 +1,407 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { statSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { Type } from "typebox";
7
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
8
+
9
+ /** Serializable source coordinates. Lines are one-based; columns are UTF-16 offsets. */
10
+ export interface ResultRange {
11
+ readonly start: { readonly lineNumber: number; readonly column: number };
12
+ readonly end: { readonly lineNumber: number; readonly column: number };
13
+ readonly linewise?: boolean;
14
+ }
15
+
16
+ /** Backend-owned text targets; never accepted directly from untrusted JSON. */
17
+ export interface ResultSourceTarget {
18
+ readonly source: string;
19
+ readonly expectedContent: string;
20
+ readonly ranges: readonly ResultRange[];
21
+ }
22
+
23
+ /** A resolved input keeps completeness separate from the size of its public preview. */
24
+ export interface ResolvedResultTargets {
25
+ readonly targets: readonly ResultSourceTarget[];
26
+ readonly complete: boolean;
27
+ }
28
+
29
+ /** Public source inputs are paths, unchanged text results, issued IDs or arrays of those strings. */
30
+ export const resultInputSchema = Type.Union([Type.String(), Type.Array(Type.String())]);
31
+
32
+ const prefix = "RESULT#";
33
+ const event = "pi-agent-resource:result-targets";
34
+
35
+ type ResultEntry = { readonly cwd: string } & (
36
+ | (ResolvedResultTargets & { readonly state: "ready" })
37
+ | { readonly state: "pending" }
38
+ | { readonly state: "rejected"; readonly reason: string }
39
+ );
40
+
41
+ /** Stores immutable source selections for one extension runtime, isolated by worktree. */
42
+ export class ResultTargetStore {
43
+ readonly #entries = new Map<string, ResultEntry>();
44
+ readonly #matchReferences = new Map<string, string>();
45
+ readonly #snapshots = new Map<
46
+ string,
47
+ { source: string; cwd: string; stamp: string | undefined }
48
+ >();
49
+ readonly #results = new Map<
50
+ string,
51
+ { cwd: string; digest: string; consumable: boolean; references: string[]; resources: string[] }
52
+ >();
53
+
54
+ /** Forget results when the session closes or the extensions reload. */
55
+ public clear(): void {
56
+ this.#entries.clear();
57
+ this.#matchReferences.clear();
58
+ this.#snapshots.clear();
59
+ this.#results.clear();
60
+ }
61
+
62
+ /** Register trusted resolver data, not a live Resource or agent-supplied coordinates. */
63
+ public register(targets: readonly ResultSourceTarget[], cwd: string, complete = true): string {
64
+ for (const target of targets) this.refresh(target.source, cwd);
65
+ const reference = `${prefix}${randomUUID()}`;
66
+ this.#entries.set(reference, {
67
+ state: "ready",
68
+ targets: combineTargets(targets),
69
+ complete,
70
+ cwd: path.resolve(cwd),
71
+ });
72
+ return reference;
73
+ }
74
+
75
+ /** Reserve an operation result before writing. It has no source authority until confirmed. */
76
+ public reserve(cwd: string): string {
77
+ const reference = `${prefix}${randomUUID()}`;
78
+ this.#entries.set(reference, { state: "pending", cwd: path.resolve(cwd) });
79
+ return reference;
80
+ }
81
+
82
+ /** Resolve one pending operation to an immutable committed snapshot, exactly once. */
83
+ public confirm(reference: string, targets: readonly ResultSourceTarget[], cwd: string): void {
84
+ const entry = this.#entries.get(reference);
85
+ if (entry?.state !== "pending" || entry.cwd !== path.resolve(cwd))
86
+ throw new Error("Only a pending result in this worktree can be confirmed.");
87
+ for (const target of targets) this.refresh(target.source, cwd);
88
+ this.#entries.set(reference, {
89
+ state: "ready",
90
+ cwd: entry.cwd,
91
+ targets: combineTargets(targets),
92
+ complete: true,
93
+ });
94
+ }
95
+
96
+ /** Failed or cancelled operations cannot turn their reserved handle into live text. */
97
+ public reject(reference: string, reason: string): void {
98
+ const entry = this.#entries.get(reference);
99
+ if (entry?.state !== "pending") return;
100
+ this.#entries.set(reference, { state: "rejected", cwd: entry.cwd, reason });
101
+ }
102
+
103
+ /** Traverse supported result shapes and resolve only registered source targets. */
104
+ public resolve(input: unknown, cwd: string): ResolvedResultTargets {
105
+ input = this.source(input, cwd);
106
+ const references = this.#references(input);
107
+ const targets: ResultSourceTarget[] = [];
108
+ let complete = true;
109
+ for (const reference of references) {
110
+ const entry = this.#entries.get(reference);
111
+ if (entry === undefined)
112
+ throw new Error("Result target expired or unknown; repeat Read/Search.");
113
+ if (entry.cwd !== path.resolve(cwd))
114
+ throw new Error("Result target belongs to another worktree.");
115
+ if (entry.state === "pending")
116
+ throw new Error("Result target is pending; its write has not been confirmed.");
117
+ if (entry.state === "rejected") throw new Error(entry.reason);
118
+ for (const target of entry.targets) this.refresh(target.source, cwd);
119
+ if (!this.#entries.has(reference))
120
+ throw new Error("Result target expired after its snapshot changed; repeat Read/Search.");
121
+ complete &&= entry.complete;
122
+ targets.push(...entry.targets);
123
+ }
124
+ return { targets: combineTargets(targets), complete };
125
+ }
126
+
127
+ /** Resolve individual ranges in declared handle order for one-to-one source/destination pairs. */
128
+ public resolveOrdered(input: unknown, cwd: string): ResolvedResultTargets {
129
+ const resolved = this.resolve(input, cwd);
130
+ const targets: ResultSourceTarget[] = [];
131
+ const seen = new Set<string>();
132
+ for (const reference of new Set(this.#references(this.source(input, cwd)))) {
133
+ for (const target of this.resolve(reference, cwd).targets) {
134
+ for (const range of target.ranges) {
135
+ const identity = JSON.stringify([target.source, range]);
136
+ if (seen.has(identity)) continue;
137
+ seen.add(identity);
138
+ targets.push({ ...target, ranges: [range] });
139
+ }
140
+ }
141
+ }
142
+ return { targets, complete: resolved.complete };
143
+ }
144
+
145
+ /** Reject changed source bytes before a consumer uses a retained selection. */
146
+ public async verify(result: ResolvedResultTargets, signal?: AbortSignal): Promise<void> {
147
+ try {
148
+ await verifyResultTargets(result, signal);
149
+ } catch (error) {
150
+ if (!signal?.aborted) for (const target of result.targets) this.invalidate(target.source);
151
+ throw error;
152
+ }
153
+ }
154
+
155
+ /** Register readable output without exposing the stored tool data to the agent. */
156
+ public publish(outcome: unknown, text: string, cwd: string, resources: string[] = []): string {
157
+ const id = randomUUID();
158
+ for (const source of resources) this.refresh(source, cwd);
159
+ let references: string[] = [];
160
+ try {
161
+ references = this.#references(outcome);
162
+ } catch {
163
+ /* Not every result grants a text selection. */
164
+ }
165
+ const shown = `<system-result note="Internal reference; not part of the file. Do not edit."><uuid>${id}</uuid></system-result>\n${text}`;
166
+ const consumable =
167
+ outcome !== null &&
168
+ typeof outcome === "object" &&
169
+ "status" in outcome &&
170
+ outcome.status === "success";
171
+ if (consumable && "data" in outcome) {
172
+ const data = outcome.data;
173
+ if (
174
+ data !== null &&
175
+ typeof data === "object" &&
176
+ "matches" in data &&
177
+ Array.isArray(data.matches)
178
+ ) {
179
+ const matches: unknown[] = data.matches;
180
+ for (const match of matches) {
181
+ if (
182
+ match === null ||
183
+ typeof match !== "object" ||
184
+ !("target" in match) ||
185
+ typeof match.target !== "string" ||
186
+ !this.#entries.has(match.target) ||
187
+ !("references" in match)
188
+ )
189
+ continue;
190
+ const references = match.references;
191
+ if (
192
+ references !== null &&
193
+ typeof references === "object" &&
194
+ "match" in references &&
195
+ typeof references.match === "string" &&
196
+ /^SEARCH#[A-F\d]+:\d+:match$/u.test(references.match)
197
+ )
198
+ this.#matchReferences.set(references.match, match.target);
199
+ }
200
+ }
201
+ }
202
+ this.#results.set(id, {
203
+ cwd: path.resolve(cwd),
204
+ digest: createHash("sha256").update(shown).digest("hex"),
205
+ consumable,
206
+ references,
207
+ resources,
208
+ });
209
+ return shown;
210
+ }
211
+
212
+ /** Resolve only issued result strings or IDs. Preview text never defines source authority. */
213
+ public source(input: unknown, cwd: string, allowResource: boolean | "live" = false): unknown {
214
+ if (Array.isArray(input)) return input.map((item) => this.source(item, cwd, allowResource));
215
+ if (typeof input !== "string") return input;
216
+ const matchTarget = this.#matchReferences.get(input);
217
+ if (matchTarget) return this.source(matchTarget, cwd, allowResource);
218
+ const envelope =
219
+ /^<system-result\b[^>]*><uuid>([a-f\d-]{36})<\/uuid><\/system-result>(?:\n|$)/u.exec(input);
220
+ const id = envelope?.[1] ?? (input.startsWith(prefix) ? input.slice(prefix.length) : input);
221
+ const isId = /^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/u.test(id);
222
+ if (!envelope && !isId) {
223
+ if (input.startsWith("<system-result")) throw new Error("Invalid system result reference.");
224
+ return input;
225
+ }
226
+ const result = this.#results.get(id);
227
+ // Existing backend selection handles share RESULT# syntax, but never accept an unknown UUID.
228
+ if (!result && !envelope && input.startsWith(prefix) && this.#entries.has(input)) return input;
229
+ if (!result) throw new Error("Result reference expired or unknown; repeat the source tool.");
230
+ if (result.cwd !== path.resolve(cwd)) throw new Error("Result belongs to another worktree.");
231
+ if (envelope && createHash("sha256").update(input).digest("hex") !== result.digest)
232
+ throw new Error("Result text changed; pass the original result or its UUID.");
233
+ for (const resource of result.resources) this.refresh(resource, cwd);
234
+ if (!this.#results.has(id))
235
+ throw new Error("Result reference expired; repeat the source tool.");
236
+ if (!result.consumable) throw new Error("Only successful source results can be consumed.");
237
+ for (const reference of result.references) {
238
+ if (!this.#entries.has(reference)) {
239
+ this.#results.delete(id);
240
+ throw new Error("Result reference expired; repeat the source tool.");
241
+ }
242
+ }
243
+ if (result.references.length === 1) return result.references[0];
244
+ if (result.references.length > 1) return result.references;
245
+ const resource = result.resources.length === 1 ? result.resources[0] : undefined;
246
+ if (
247
+ resource &&
248
+ (allowResource === true || (allowResource === "live" && /^(?:shell|debug):/u.test(resource)))
249
+ )
250
+ return resource;
251
+ throw new Error("This result has no reusable text selection.");
252
+ }
253
+
254
+ /** Permanently retire every ready selection of a changed file, including derived results. */
255
+ public invalidate(source: string): void {
256
+ const removed = new Set<string>();
257
+ for (const [reference, entry] of this.#entries) {
258
+ if (
259
+ entry.state === "ready" &&
260
+ entry.targets.some((target) => sourcePath(target.source, entry.cwd) === source)
261
+ ) {
262
+ this.#entries.delete(reference);
263
+ removed.add(reference);
264
+ }
265
+ }
266
+ for (const [id, result] of this.#results)
267
+ if (
268
+ result.resources.some((resource) => sourcePath(resource, result.cwd) === source) ||
269
+ result.references.some((reference) => removed.has(reference))
270
+ )
271
+ this.#results.delete(id);
272
+ }
273
+
274
+ /** Detect filesystem generations, so restoring old bytes never revives an old reference. */
275
+ public refresh(source: string, cwd: string): void {
276
+ const identity = sourcePath(source, cwd);
277
+ const key = JSON.stringify([path.resolve(cwd), identity]);
278
+ const stamp = fileStamp(source, cwd);
279
+ const previous = this.#snapshots.get(key);
280
+ if (previous && previous.stamp !== stamp) this.invalidate(identity);
281
+ this.#snapshots.set(key, { source, cwd, stamp });
282
+ }
283
+
284
+ /** Check surviving snapshots at a script boundary, including final formatting. */
285
+ public refreshAll(): void {
286
+ for (const snapshot of [...this.#snapshots.values()])
287
+ this.refresh(snapshot.source, snapshot.cwd);
288
+ }
289
+ #references(input: unknown): string[] {
290
+ if (typeof input === "string" && input.startsWith(prefix)) return [input];
291
+ if (Array.isArray(input)) return input.flatMap((child) => this.#references(child));
292
+ if (input === null || typeof input !== "object") throw new Error("Unsupported result input.");
293
+ const value = input as Record<string, unknown>;
294
+ if ("status" in value) {
295
+ if (value.status !== "success")
296
+ throw new Error("Only successful source results can be consumed.");
297
+ return this.#references(value.data);
298
+ }
299
+ if (typeof value.target === "string" && value.target.startsWith(prefix)) return [value.target];
300
+ if (value.kind === "resources" && Array.isArray(value.resources))
301
+ return this.#references(value.resources);
302
+ throw new Error(
303
+ "This result has no supported source target; do not use preview text as a source.",
304
+ );
305
+ }
306
+ }
307
+
308
+ function sourcePath(source: string, cwd: string): string {
309
+ const file = source.startsWith("raw:") ? source.slice(4) : source;
310
+ if (file.startsWith("file:")) {
311
+ try {
312
+ return fileURLToPath(file);
313
+ } catch {
314
+ /* Unresolved protocol labels have no filesystem stamp. */
315
+ }
316
+ }
317
+ return path.resolve(cwd, file);
318
+ }
319
+ function fileStamp(source: string, cwd: string): string | undefined {
320
+ try {
321
+ const stat = statSync(sourcePath(source, cwd), { bigint: true });
322
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
323
+ } catch {
324
+ return undefined;
325
+ }
326
+ }
327
+ /** Verify retained source snapshots for tools and provider refresh operations. */
328
+ export async function verifyResultTargets(
329
+ result: ResolvedResultTargets,
330
+ signal?: AbortSignal,
331
+ ): Promise<void> {
332
+ const contents = new Map<string, string>();
333
+ for (const target of result.targets) {
334
+ signal?.throwIfAborted();
335
+ let current = contents.get(target.source);
336
+ if (current === undefined) {
337
+ current = await readFile(target.source, { encoding: "utf8", signal });
338
+ contents.set(target.source, current);
339
+ }
340
+ if (current !== target.expectedContent)
341
+ throw new Error("Result target is stale; repeat Read/Search.");
342
+ }
343
+ }
344
+ function combineTargets(targets: readonly ResultSourceTarget[]): ResultSourceTarget[] {
345
+ const grouped = new Map<
346
+ string,
347
+ { source: string; expectedContent: string; ranges: ResultRange[]; seen: Set<string> }
348
+ >();
349
+ for (const target of targets) {
350
+ const previous = grouped.get(target.source);
351
+ if (previous !== undefined && previous.expectedContent !== target.expectedContent)
352
+ throw new Error("Result targets refer to different snapshots of the same source.");
353
+ const combined = previous ?? {
354
+ source: target.source,
355
+ expectedContent: target.expectedContent,
356
+ ranges: [],
357
+ seen: new Set<string>(),
358
+ };
359
+ for (const range of target.ranges) {
360
+ const key = JSON.stringify(range);
361
+ if (combined.seen.has(key)) continue;
362
+ combined.seen.add(key);
363
+ combined.ranges.push(structuredClone(range));
364
+ }
365
+ grouped.set(target.source, combined);
366
+ }
367
+ return [...grouped.values()]
368
+ .filter((target) => target.ranges.length > 0)
369
+ .map(({ seen: _seen, ...target }) => ({
370
+ ...target,
371
+ ranges: target.ranges.sort(
372
+ (left, right) =>
373
+ left.start.lineNumber - right.start.lineNumber ||
374
+ left.start.column - right.start.column ||
375
+ left.end.lineNumber - right.end.lineNumber ||
376
+ left.end.column - right.end.column,
377
+ ),
378
+ }));
379
+ }
380
+ /** Share one backend store through Pi's extension event bus, without process-global state. */
381
+ export function connectResultTargets(pi: ExtensionAPI): ResultTargetStore {
382
+ let existing: ResultTargetStore | undefined;
383
+ pi.events.emit(event, {
384
+ accept: (store: ResultTargetStore) => {
385
+ existing = store;
386
+ },
387
+ });
388
+ if (existing !== undefined) return existing;
389
+ const store = new ResultTargetStore();
390
+ const unsubscribe = pi.events.on(event, (request) => {
391
+ if (
392
+ request !== null &&
393
+ typeof request === "object" &&
394
+ "accept" in request &&
395
+ typeof request.accept === "function"
396
+ )
397
+ (request.accept as (store: ResultTargetStore) => void)(store);
398
+ });
399
+ pi.on("session_start", () => {
400
+ store.clear();
401
+ });
402
+ pi.on("session_shutdown", () => {
403
+ store.clear();
404
+ unsubscribe();
405
+ });
406
+ return store;
407
+ }
@@ -25,7 +25,7 @@ export const resultErrorSchema = Type.Object(
25
25
 
26
26
  /** Build the common result contract around one tool's data schema. */
27
27
  export function structuredResultSchema(data: TSchema) {
28
- return Type.Union([
28
+ const outcomes = Type.Union([
29
29
  Type.Object(
30
30
  {
31
31
  status: Type.Literal("success"),
@@ -43,6 +43,18 @@ export function structuredResultSchema(data: TSchema) {
43
43
  { additionalProperties: false },
44
44
  ),
45
45
  ]);
46
+ // Expose the common object fields without weakening outcome-specific validation.
47
+ return {
48
+ ...outcomes,
49
+ type: "object" as const,
50
+ properties: {
51
+ status: Type.Union([Type.Literal("success"), Type.Literal("error"), Type.Literal("partial")]),
52
+ data: Type.Optional(data),
53
+ errors: Type.Array(resultErrorSchema),
54
+ },
55
+ required: ["status", "errors"],
56
+ additionalProperties: false,
57
+ };
46
58
  }
47
59
  /** Maximum serialized public data; callers expose a smaller window or a full-result resource. */
48
60
  export const MAX_STRUCTURED_BYTES = 1024 * 1024;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-search",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -20,10 +20,10 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "pi-agent-documentation": "0.6.4",
24
- "pi-agent-resource": "0.6.4",
25
- "pi-agent-tool-call-interception": "0.6.4",
26
- "pi-agent-tool-ui": "0.6.4"
23
+ "pi-agent-documentation": "0.7.1",
24
+ "pi-agent-resource": "0.7.1",
25
+ "pi-agent-tool-call-interception": "0.7.1",
26
+ "pi-agent-tool-ui": "0.7.1"
27
27
  },
28
28
  "pi": {
29
29
  "extensions": [