pi-agent-ide 0.7.0 → 0.7.2

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 (323) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/chunk-6U5OU77O.js +3 -0
  3. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  4. package/dist/chunk-EURHXLN3.js +2 -0
  5. package/dist/{chunk-PYPPV2F5.js → chunk-F6IWZKOG.js} +6 -6
  6. package/dist/{chunk-GBLKIB6O.js → chunk-H445SHSJ.js} +2 -2
  7. package/dist/chunk-IG56UGSO.js +2 -0
  8. package/dist/chunk-IICJXZBU.js +6 -0
  9. package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
  10. package/dist/{chunk-YRF7OATP.js → chunk-KOVPDKSJ.js} +1 -1
  11. package/dist/chunk-MXLSGMRZ.js +3 -0
  12. package/dist/chunk-NRZO5KJT.js +9 -0
  13. package/dist/chunk-OB46OPMZ.js +1 -0
  14. package/dist/chunk-PKSQT6TC.js +1 -0
  15. package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
  16. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  17. package/dist/chunk-QUYXINGZ.js +7 -0
  18. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  19. package/dist/chunk-SBP3ABH4.js +5 -0
  20. package/dist/{chunk-FXNKMNSJ.js → chunk-SJ4UZ4GU.js} +1 -1
  21. package/dist/chunk-SNF7PDDX.js +11 -0
  22. package/dist/{chunk-AJRIASPQ.js → chunk-STBJO3Z3.js} +1 -1
  23. package/dist/{chunk-3HYXQ4YA.js → chunk-TQGE7RH6.js} +13 -13
  24. package/dist/{chunk-S5LXX32D.js → chunk-XDG7EQRN.js} +3 -3
  25. package/dist/{chunk-F5YZG77W.js → chunk-XH5WN5XA.js} +1 -1
  26. package/dist/chunk-YWQS33DF.js +1 -0
  27. package/dist/chunk-ZIWPKIBZ.js +1 -0
  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 +2 -2
  34. package/dist/entry-26.js +1 -1
  35. package/dist/entry-27.js +2 -2
  36. package/dist/entry-28.js +1 -1
  37. package/dist/entry-29.js +1 -1
  38. package/dist/entry-31.js +15 -13
  39. package/dist/entry-33.js +2 -1
  40. package/dist/entry-37.js +6 -6
  41. package/dist/entry-41.js +1 -1
  42. package/dist/entry-42.js +1 -1
  43. package/dist/entry-43.js +1 -1
  44. package/dist/entry-44.js +1 -1
  45. package/dist/entry-45.js +20 -13
  46. package/dist/entry-46.js +1 -1
  47. package/dist/entry-49.js +1 -1
  48. package/dist/entry-50.js +1 -1
  49. package/dist/entry-51.js +8 -7
  50. package/dist/entry-52.js +1 -1
  51. package/dist/entry-53.js +1 -1
  52. package/dist/entry-54.js +1 -1
  53. package/dist/entry-56.js +1 -1
  54. package/dist/entry-57.js +1 -1
  55. package/dist/entry-58.js +1 -1
  56. package/dist/entry-60.js +1 -1
  57. package/dist/entry-62.js +1 -1
  58. package/dist/entry-65.js +1 -1
  59. package/dist/entry-66.js +1 -1
  60. package/dist/entry-68.js +1 -1
  61. package/dist/entry-70.js +1 -1
  62. package/dist/entry-75.js +1 -1
  63. package/dist/entry-77.js +51 -43
  64. package/dist/entry-78.js +14 -14
  65. package/dist/entry-79.js +1 -1
  66. package/dist/entry-80.js +1 -1
  67. package/dist/entry-82.js +5 -5
  68. package/dist/entry-83.js +1 -1
  69. package/dist/entry-84.js +1 -1
  70. package/dist/entry-85.js +1 -1
  71. package/dist/entry-86.js +1 -1
  72. package/dist/pi-agent-ide.js +37 -9
  73. package/docs/agent-guides/editing.md +35 -46
  74. package/docs/agent-guides/git-changes.md +10 -0
  75. package/docs/agent-guides/read-resources.md +9 -50
  76. package/docs/agent-guides/search-code.md +18 -17
  77. package/docs/agent-guides/select-code.md +62 -140
  78. package/docs/agent-guides/terminal.md +9 -1
  79. package/docs/configuration.md +1 -1
  80. package/docs/releases.md +4 -0
  81. package/docs/research/native-codemode-batch-decision.md +2 -0
  82. package/docs/structured-results.md +27 -62
  83. package/docs/tools.md +15 -11
  84. package/node_modules/pi-agent-doctor/package.json +1 -1
  85. package/node_modules/pi-agent-documentation/package.json +1 -1
  86. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  87. package/node_modules/pi-agent-filesystem/package.json +7 -7
  88. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  89. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  90. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  91. package/node_modules/pi-agent-filesystem-jq/src/jq.ts +4 -1
  92. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  93. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  94. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  95. package/node_modules/pi-agent-ide-ast/src/extension.ts +5 -4
  96. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  97. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +35 -9
  98. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  99. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +10 -8
  100. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +28 -3
  101. package/node_modules/pi-agent-ide-changes/index.ts +4 -3
  102. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  103. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
  104. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  105. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  106. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  107. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  108. package/node_modules/pi-agent-ide-lsp/index.ts +3 -3
  109. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  110. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
  111. package/node_modules/pi-agent-image/package.json +2 -2
  112. package/node_modules/pi-agent-invariant/package.json +1 -1
  113. package/node_modules/pi-agent-pdf/package.json +2 -2
  114. package/node_modules/pi-agent-read/package.json +7 -7
  115. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  116. package/node_modules/pi-agent-read/src/api/read-parameters.ts +38 -1
  117. package/node_modules/pi-agent-read/src/api/tools/read.ts +18 -1
  118. package/node_modules/pi-agent-read/src/core/extension.ts +8 -2
  119. package/node_modules/pi-agent-read/src/core/read-core.ts +54 -35
  120. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  121. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  122. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  123. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  124. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  125. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +108 -46
  126. package/node_modules/pi-agent-resource/package.json +1 -1
  127. package/node_modules/pi-agent-resource/src/index.ts +1 -0
  128. package/node_modules/pi-agent-resource/src/result-targets.ts +186 -9
  129. package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
  130. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  131. package/node_modules/pi-agent-search/package.json +5 -5
  132. package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
  133. package/node_modules/pi-agent-search/src/api/search-parameters.ts +3 -3
  134. package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
  135. package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
  136. package/node_modules/pi-agent-search-text/index.ts +1 -1
  137. package/node_modules/pi-agent-search-text/package.json +7 -7
  138. package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
  139. package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
  140. package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
  141. package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
  142. package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
  143. package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
  144. package/node_modules/pi-agent-text/package.json +2 -2
  145. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  146. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  147. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  148. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  149. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  150. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  151. package/node_modules/pi-agent-text-editor/package.json +9 -9
  152. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  153. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
  154. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  155. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  156. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  157. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  158. package/node_modules/pi-agent-text-editor/src/core/extension.ts +10 -3
  159. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  160. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
  161. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -1
  162. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  163. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +232 -144
  164. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  165. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
  166. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +7 -2
  167. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +49 -214
  168. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  169. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +152 -22
  170. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  171. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +76 -32
  172. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
  173. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  174. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
  175. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
  176. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  177. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  178. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  179. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
  180. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  181. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  182. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  183. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +54 -5
  184. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  185. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  186. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  187. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  188. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  189. package/node_modules/pi-agent-web/index.ts +4 -3
  190. package/node_modules/pi-agent-web/package.json +7 -7
  191. package/node_modules/pi-agent-web/src/resolver.ts +11 -13
  192. package/node_modules/pi-agent-web-html/package.json +2 -2
  193. package/node_modules/pi-agent-web-image/package.json +3 -3
  194. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  195. package/node_modules/pi-agent-web-text/package.json +3 -3
  196. package/package.json +35 -35
  197. package/src/composite/nested-tool-rendering.ts +64 -6
  198. package/src/composite/output-limits.ts +125 -0
  199. package/src/composite/responses-tools.ts +25 -0
  200. package/src/composite/text-results.ts +372 -0
  201. package/src/documentation/extension.ts +11 -9
  202. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  203. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  204. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  205. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  206. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  207. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
  208. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  209. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  210. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +4 -3
  211. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  212. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  213. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  214. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  215. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  216. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +11 -13
  217. package/src/extensions/pi-agent-read/package.json +7 -7
  218. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  219. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +38 -1
  220. package/src/extensions/pi-agent-read/src/api/tools/read.ts +18 -1
  221. package/src/extensions/pi-agent-read/src/core/extension.ts +8 -2
  222. package/src/extensions/pi-agent-read/src/core/read-core.ts +54 -35
  223. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
  224. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
  225. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
  226. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
  227. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  228. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +108 -46
  229. package/src/extensions/pi-agent-search/package.json +5 -5
  230. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  231. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  232. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
  233. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
  234. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
  235. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
  236. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
  237. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
  238. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
  239. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +3 -3
  240. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
  241. package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
  242. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  243. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  244. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  245. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  246. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  247. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  248. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  249. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  250. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
  251. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +54 -5
  252. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
  253. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  254. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
  255. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
  256. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
  257. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
  258. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
  259. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
  260. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +10 -3
  261. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  262. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
  263. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -1
  264. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
  265. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +232 -144
  266. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
  267. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
  268. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +7 -2
  269. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +49 -214
  270. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
  271. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +152 -22
  272. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  273. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +76 -32
  274. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
  275. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  276. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
  277. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
  278. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
  279. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
  280. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  281. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
  282. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
  283. package/src/pi-agent-ide.ts +15 -1
  284. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  285. package/src/plugins/pi-agent-ide-ast/src/extension.ts +5 -4
  286. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  287. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +35 -9
  288. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  289. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +10 -8
  290. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +28 -3
  291. package/src/plugins/pi-agent-ide-changes/index.ts +4 -3
  292. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  293. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
  294. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
  295. package/src/plugins/pi-agent-ide-debugger/index.ts +22 -10
  296. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
  297. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
  298. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +6 -3
  299. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  300. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  301. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  302. package/src/plugins/pi-agent-ide-lsp/index.ts +3 -3
  303. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  304. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
  305. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
  306. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  307. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
  308. package/src/plugins/pi-agent-ide-vision/index.ts +13 -4
  309. package/src/post-edit/gate.ts +13 -2
  310. package/dist/chunk-3JO7QFIL.js +0 -1
  311. package/dist/chunk-4NIFBFFR.js +0 -11
  312. package/dist/chunk-64M3SQPG.js +0 -3
  313. package/dist/chunk-7LZKOHH2.js +0 -1
  314. package/dist/chunk-EAZGN5ND.js +0 -7
  315. package/dist/chunk-FK42RSF4.js +0 -1
  316. package/dist/chunk-KBP3QUDT.js +0 -2
  317. package/dist/chunk-KR36BT5E.js +0 -1
  318. package/dist/chunk-MBUXFKIW.js +0 -3
  319. package/dist/chunk-OE7QVAI2.js +0 -5
  320. package/dist/chunk-SILJ3OL4.js +0 -9
  321. package/dist/chunk-SQKAXYIR.js +0 -2
  322. package/dist/chunk-VCGNVTXQ.js +0 -1
  323. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
@@ -43,20 +43,21 @@ import {
43
43
  type ResourceResolverRegistration,
44
44
  type TextTargetResolverRegistration,
45
45
  } from "#src/api/tools/read.js";
46
- import {
47
- limitReadOutput,
48
- READ_OUTPUT_MAX_BYTES,
49
- READ_OUTPUT_MAX_LINES,
50
- } from "#src/core/tools/read/output-truncation.js";
46
+ import { explainReadWindow, limitReadOutput } from "#src/core/tools/read/output-truncation.js";
51
47
  import { createReadResultRenderer, renderReadCall } from "#src/core/tools/read/read-renderer.js";
52
48
  import {
53
49
  createReadState,
54
50
  failureResult,
55
51
  projectReadState,
52
+ withReadCancellation,
56
53
  } from "#src/core/tools/read/read-result.js";
57
- import { TempResourceStore } from "#src/core/tools/read/temp-resource-store.js";
54
+ import { TempResourceStore } from "pi-agent-resource";
58
55
 
59
- import { readParameters } from "#src/api/read-parameters.js";
56
+ import {
57
+ type readParameters,
58
+ describeReadParameters,
59
+ type ReadParameterText,
60
+ } from "#src/api/read-parameters.js";
60
61
  import { readRaw } from "#src/core/tools/read/raw-read.js";
61
62
  import { readOutputSchema, structuredRead } from "./read/structured-result.js";
62
63
 
@@ -112,6 +113,8 @@ export interface ReadToolContributions {
112
113
  export interface ReadTool {
113
114
  /** Shares the read runtime's temporary resource store with composed operations. */
114
115
  saveTemporary(text: string): Promise<string>;
116
+ /** Sets the saver used before agent-facing text is truncated. */
117
+ setOutputSaver(saver: (text: string) => Promise<string>): void;
115
118
  readonly tool: ToolDefinition<typeof readParameters, ReadResultDetails>;
116
119
  execute(
117
120
  request: ReadPipelineContext["request"],
@@ -126,8 +129,10 @@ export interface ReadTool {
126
129
  export function createReadTool(
127
130
  pluginPromptGuidelines?: () => readonly string[],
128
131
  presentation: "full" | "compact" | "disabled" = "compact",
132
+ parameterDescriptions?: () => ReadParameterText,
129
133
  ): ReadTool {
130
134
  const temporaryResources = new TempResourceStore();
135
+ let outputSaver: ((text: string) => Promise<string>) | undefined;
131
136
  const resolvers: RegisteredResolver[] = [
132
137
  {
133
138
  resolver: temporaryResources.resolver,
@@ -149,6 +154,9 @@ export function createReadTool(
149
154
 
150
155
  return {
151
156
  saveTemporary: (text) => temporaryResources.save(text),
157
+ setOutputSaver(saver) {
158
+ outputSaver = saver;
159
+ },
152
160
  tool: {
153
161
  name: toolId,
154
162
  exposure: "direct",
@@ -163,16 +171,16 @@ export function createReadTool(
163
171
  label: toolId,
164
172
 
165
173
  promptSnippet: "Read supported sources as text or bytes, with optional views",
166
- get description(): string {
167
- return `Use read to inspect supported resources. path selects the source; offset and limit select a bounded window; views request source-specific presentations. Text output is limited to ${READ_OUTPUT_MAX_LINES} lines or ${READ_OUTPUT_MAX_BYTES / 1024}KB; follow a returned continuation offset or temp: reference when present.`;
168
- },
174
+ description: "Use read to inspect files and other supported resources.",
169
175
  get promptGuidelines(): string[] {
170
176
  return [
171
177
  "Use read to inspect supported sources and search to locate workspace content.",
172
178
  ...(pluginPromptGuidelines?.() ?? []),
173
179
  ];
174
180
  },
175
- parameters: readParameters,
181
+ get parameters() {
182
+ return describeReadParameters(parameterDescriptions?.() ?? {});
183
+ },
176
184
  outputSchema: readOutputSchema,
177
185
  renderCall(arguments_, theme, context) {
178
186
  const source = typeof arguments_.path === "string" ? arguments_.path : undefined;
@@ -219,8 +227,10 @@ export function createReadTool(
219
227
  fragments,
220
228
  targetResolvers,
221
229
  resourceGuards,
230
+ "agent",
231
+ outputSaver,
222
232
  );
223
- return structuredRead(result);
233
+ return structuredRead(withReadCancellation(result, parameters.path, signal));
224
234
  } catch (error) {
225
235
  if (signal?.aborted) throw error;
226
236
  return structuredRead(
@@ -233,8 +243,8 @@ export function createReadTool(
233
243
  }
234
244
  },
235
245
  },
236
- execute(request, context, audience = "agent"): Promise<ReadToolResult> {
237
- return executeRead(
246
+ async execute(request, context, audience = "agent"): Promise<ReadToolResult> {
247
+ const result = await executeRead(
238
248
  request,
239
249
  context,
240
250
  resolvers,
@@ -245,7 +255,9 @@ export function createReadTool(
245
255
  targetResolvers,
246
256
  resourceGuards,
247
257
  audience,
258
+ outputSaver,
248
259
  );
260
+ return withReadCancellation(result, request.path, context.signal);
249
261
  },
250
262
  registerContributions(pluginId, contributions): void {
251
263
  const incomingResourceGuards = [...(contributions.resourceGuards ?? [])];
@@ -363,12 +375,16 @@ async function executeRead(
363
375
  }[],
364
376
  resourceGuards: readonly RegisteredResourceGuard[],
365
377
  audience: "agent" | "script" = "agent",
378
+ outputSaver?: (text: string) => Promise<string>,
366
379
  ): Promise<ReadToolResult> {
367
380
  if (request.path?.startsWith("raw:"))
368
381
  return readRaw(request, resolverContext, audience, resourceGuards);
369
382
  resolverContext = { ...resolverContext, audience };
370
383
  const limitOutput: typeof limitReadOutput =
371
- audience === "script" ? async (result) => result : limitReadOutput;
384
+ audience === "script"
385
+ ? async (result) => result
386
+ : (result, request, fallback, options) =>
387
+ limitReadOutput(result, request, outputSaver ?? fallback, options);
372
388
  const resolverSnapshot = [...resolvers].sort(
373
389
  (left, right) => left.priority - right.priority || left.order - right.order,
374
390
  );
@@ -390,7 +406,18 @@ async function executeRead(
390
406
  ];
391
407
  const requestedViews = new Set(rawRequestedViews.map(viewName));
392
408
  const knownViews = new Set([...viewSnapshot.map(({ registration }) => registration.view)]);
393
- const ignoredViews = rawRequestedViews.filter((view) => !knownViews.has(viewName(view)));
409
+ const explicitViews = [...new Set(request.views ?? [])];
410
+ const nativeViews = new Set(
411
+ viewSnapshot
412
+ .filter(({ registration }) => registration.contentKind === "any")
413
+ .map(({ registration }) => registration.view),
414
+ );
415
+ const viewWarnings: ReadViewWarnings = {
416
+ ignored: explicitViews.filter((view) => !knownViews.has(viewName(view))),
417
+ textOnly: explicitViews.filter(
418
+ (view) => knownViews.has(viewName(view)) && !nativeViews.has(viewName(view)),
419
+ ),
420
+ };
394
421
  if (request.path !== undefined && targetSnapshot.length > 0) {
395
422
  const targeted = await resolveTextTargets(
396
423
  request,
@@ -400,9 +427,10 @@ async function executeRead(
400
427
  handlerSnapshot,
401
428
  viewSnapshot,
402
429
  requestedViews,
403
- ignoredViews,
430
+ viewWarnings,
404
431
  audience,
405
432
  resourceGuards,
433
+ outputSaver,
406
434
  );
407
435
  if (targeted !== undefined) return targeted;
408
436
  }
@@ -412,7 +440,7 @@ async function executeRead(
412
440
  const preRead = await runPreReadHandlers(pipeline, handlerSnapshot);
413
441
 
414
442
  if (preRead.kind === "return") {
415
- return withIgnoredViews(await limitOutput(preRead.result, pipeline.request), ignoredViews);
443
+ return withViewWarnings(await limitOutput(preRead.result, pipeline.request), viewWarnings);
416
444
  }
417
445
 
418
446
  pipeline = preRead.context;
@@ -482,23 +510,23 @@ async function executeRead(
482
510
  }
483
511
 
484
512
  if (pipeline.state?.textMode === "final") {
485
- return withIgnoredViews(
513
+ return withViewWarnings(
486
514
  await limitOutput(
487
515
  projectReadState(pipeline.state, pipeline.request, { originLine: origin, audience }),
488
516
  pipeline.request,
489
517
  undefined,
490
518
  { originLine: origin },
491
519
  ),
492
- ignoredViews,
520
+ viewWarnings,
493
521
  );
494
522
  }
495
523
 
496
524
  const processed = await runReadHandlers(pipeline, handlerSnapshot);
497
525
 
498
526
  if (processed.kind === "return") {
499
- return withIgnoredViews(
527
+ return withViewWarnings(
500
528
  await limitOutput(processed.result, pipeline.request, undefined, { originLine: origin }),
501
- ignoredViews,
529
+ viewWarnings,
502
530
  );
503
531
  }
504
532
 
@@ -516,9 +544,9 @@ async function executeRead(
516
544
  pipeline.request.limit === undefined && pipeline.state?.preserveTruncatedOutput === true
517
545
  ? (text: string): Promise<string> => temporaryResources.save(text)
518
546
  : undefined;
519
- return withIgnoredViews(
547
+ return withViewWarnings(
520
548
  await limitOutput(result, pipeline.request, saveFullOutput, { originLine: origin }),
521
- ignoredViews,
549
+ viewWarnings,
522
550
  );
523
551
  }
524
552
 
@@ -552,12 +580,16 @@ async function resolveTextTargets(
552
580
  handlers: readonly RegisteredHandler[],
553
581
  views: readonly RegisteredView[],
554
582
  requestedViews: ReadonlySet<string>,
555
- ignoredViews: readonly string[],
583
+ viewWarnings: ReadViewWarnings,
556
584
  audience: "agent" | "script",
557
585
  resourceGuards: readonly RegisteredResourceGuard[],
586
+ outputSaver?: (text: string) => Promise<string>,
558
587
  ): Promise<ReadToolResult | undefined> {
559
588
  const limitOutput: typeof limitReadOutput =
560
- audience === "script" ? async (result) => result : limitReadOutput;
589
+ audience === "script"
590
+ ? async (result) => result
591
+ : (result, request, fallback, options) =>
592
+ limitReadOutput(result, request, outputSaver ?? fallback, options);
561
593
  for (const { resolver } of targetResolvers) {
562
594
  let rawAttempt: unknown;
563
595
  try {
@@ -627,7 +659,7 @@ async function resolveTextTargets(
627
659
  const preRead = await runPreReadHandlers(rangePipeline, handlers);
628
660
  if (preRead.kind === "return") {
629
661
  if (preRead.result.isError === true)
630
- return withIgnoredViews(preRead.result, ignoredViews);
662
+ return withViewWarnings(preRead.result, viewWarnings);
631
663
  return preRead.result;
632
664
  }
633
665
  rangePipeline = preRead.context;
@@ -639,12 +671,12 @@ async function resolveTextTargets(
639
671
  request.path ?? target.source,
640
672
  );
641
673
  if (resolved.kind === "return") {
642
- return withIgnoredViews(resolved.result, ignoredViews);
674
+ return withViewWarnings(resolved.result, viewWarnings);
643
675
  }
644
676
  const processed = await runReadHandlers(resolved.context, handlers);
645
677
  if (processed.kind === "return") {
646
678
  if (processed.result.isError === true)
647
- return withIgnoredViews(processed.result, ignoredViews);
679
+ return withViewWarnings(processed.result, viewWarnings);
648
680
  return processed.result;
649
681
  }
650
682
  const presented = await runTextPresenters(processed.context, views, requestedViews);
@@ -653,18 +685,26 @@ async function resolveTextTargets(
653
685
  originLine: range.start.lineNumber,
654
686
  });
655
687
  const postRead = await runPostReadHandlers({ ...presented, result: projected }, handlers);
656
- if (projected.isError === true) return withIgnoredViews(projected, ignoredViews);
688
+ if (projected.isError === true) return withViewWarnings(projected, viewWarnings);
657
689
  const result =
658
690
  postRead.kind === "return" ? postRead.result : requiredValue(postRead.context.result);
659
- if (result.isError === true) return withIgnoredViews(result, ignoredViews);
660
- return result;
691
+ if (result.isError === true) return withViewWarnings(result, viewWarnings);
692
+ return audience === "script"
693
+ ? result
694
+ : explainReadWindow(
695
+ result,
696
+ { ...presented.request, limit: request.limit },
697
+ {
698
+ originLine: range.start.lineNumber,
699
+ },
700
+ );
661
701
  });
662
702
  });
663
703
  const completed = await Promise.allSettled(pending);
664
704
  for (const outcome of completed) {
665
705
  if (outcome.status === "rejected") throw outcome.reason;
666
706
  const result = outcome.value;
667
- if (result.isError === true) return withIgnoredViews(result, ignoredViews);
707
+ if (result.isError === true) return withViewWarnings(result, viewWarnings);
668
708
  for (const block of result.content) {
669
709
  if (block.type === "text") chunks.push(block.text);
670
710
  }
@@ -686,9 +726,9 @@ async function resolveTextTargets(
686
726
  ? { source: request.path, resources }
687
727
  : (firstDetails ?? { source: request.path }),
688
728
  } satisfies ReadToolResult;
689
- return withIgnoredViews(
729
+ return withViewWarnings(
690
730
  await limitOutput(aggregate, { path: request.path, views: request.views }),
691
- ignoredViews,
731
+ viewWarnings,
692
732
  );
693
733
  }
694
734
  return undefined;
@@ -726,7 +766,7 @@ async function resolveAnchoredOrigin(
726
766
  code: "UNSUPPORTED_RANGE",
727
767
  source: state.source,
728
768
  resolverId: state.resolvedBy,
729
- message: "Anchored reads require textual content",
769
+ message: "Anchored reads require textual content. Read this source without an anchor.",
730
770
  });
731
771
  }
732
772
 
@@ -1103,21 +1143,43 @@ function viewName(view: string): string {
1103
1143
  return separator < 0 ? view : view.slice(0, separator);
1104
1144
  }
1105
1145
 
1106
- /** Prepends a note listing unknown view names so the agent can correct the request. */
1107
- function withIgnoredViews(result: ReadToolResult, ignoredViews: readonly string[]): ReadToolResult {
1108
- if (ignoredViews.length === 0) {
1109
- return result;
1110
- }
1146
+ interface ReadViewWarnings {
1147
+ readonly ignored: readonly string[];
1148
+ readonly textOnly: readonly string[];
1149
+ }
1111
1150
 
1112
- const note = `note: ignored unknown views: ${ignoredViews.join(", ")}`;
1113
- const block = result.content[0];
1151
+ /** Reports unused views without changing source data or discarding native content. */
1152
+ function withViewWarnings(result: ReadToolResult, requested: ReadViewWarnings): ReadToolResult {
1153
+ const messages: string[] = [];
1154
+ if (requested.ignored.length > 0) {
1155
+ messages.push(
1156
+ requested.ignored.length === 1
1157
+ ? `Unknown view ignored: ${requested.ignored[0]}. Remove it or choose a supported view from the views parameter.`
1158
+ : `Unknown views ignored: ${requested.ignored.join(", ")}. Remove these entries or choose supported views from the views parameter.`,
1159
+ );
1160
+ }
1161
+ if (result.isError !== true && result.content.some((block) => block.type !== "text")) {
1162
+ for (const view of requested.textOnly) {
1163
+ messages.push(
1164
+ `View not applied: ${view} requires text. Read a text source to use ${viewName(view)}.`,
1165
+ );
1166
+ }
1167
+ }
1168
+ if (messages.length === 0 || result.details.viewWarnings !== undefined) return result;
1169
+ const note = messages.join("\n");
1170
+ const first = result.content[0];
1114
1171
  const content =
1115
- block?.type === "text" ? [{ ...block, text: `${note}\n${block.text}` }] : [...result.content];
1116
-
1172
+ result.content.length === 1 && first?.type === "text"
1173
+ ? [{ ...first, text: `${note}\n${first.text}` }]
1174
+ : [{ type: "text" as const, text: note }, ...result.content];
1117
1175
  return {
1118
1176
  ...result,
1119
1177
  content,
1120
- details: { ...result.details, ignoredViews },
1178
+ details: {
1179
+ ...result.details,
1180
+ ...(requested.ignored.length === 0 ? {} : { ignoredViews: requested.ignored }),
1181
+ viewWarnings: messages,
1182
+ },
1121
1183
  };
1122
1184
  }
1123
1185
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-resource",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "imports": {
@@ -1,5 +1,6 @@
1
1
  export { ResourceScheduler, resourceScheduler, type ResourceAccess } from "./resource-scheduler.js";
2
2
  export { resourceAccesses } from "./resource-access.js";
3
+ export { TempResourceStore, type TempResourceStoreOptions } from "./temp-resource-store.js";
3
4
  export {
4
5
  assertJsonData,
5
6
  MAX_STRUCTURED_BYTES,
@@ -1,6 +1,8 @@
1
- import { randomUUID } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { statSync } from "node:fs";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
4
6
  import { Type } from "typebox";
5
7
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
8
 
@@ -24,12 +26,8 @@ export interface ResolvedResultTargets {
24
26
  readonly complete: boolean;
25
27
  }
26
28
 
27
- /** Tool inputs allow returned result objects and JS-selected arrays. The store validates authority. */
28
- export const resultInputSchema = Type.Union([
29
- Type.String(),
30
- Type.Object({}, { additionalProperties: true }),
31
- Type.Array(Type.Unknown()),
32
- ]);
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())]);
33
31
 
34
32
  const prefix = "RESULT#";
35
33
  const event = "pi-agent-resource:result-targets";
@@ -43,14 +41,27 @@ type ResultEntry = { readonly cwd: string } & (
43
41
  /** Stores immutable source selections for one extension runtime, isolated by worktree. */
44
42
  export class ResultTargetStore {
45
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
+ >();
46
53
 
47
54
  /** Forget results when the session closes or the extensions reload. */
48
55
  public clear(): void {
49
56
  this.#entries.clear();
57
+ this.#matchReferences.clear();
58
+ this.#snapshots.clear();
59
+ this.#results.clear();
50
60
  }
51
61
 
52
62
  /** Register trusted resolver data, not a live Resource or agent-supplied coordinates. */
53
63
  public register(targets: readonly ResultSourceTarget[], cwd: string, complete = true): string {
64
+ for (const target of targets) this.refresh(target.source, cwd);
54
65
  const reference = `${prefix}${randomUUID()}`;
55
66
  this.#entries.set(reference, {
56
67
  state: "ready",
@@ -73,6 +84,7 @@ export class ResultTargetStore {
73
84
  const entry = this.#entries.get(reference);
74
85
  if (entry?.state !== "pending" || entry.cwd !== path.resolve(cwd))
75
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);
76
88
  this.#entries.set(reference, {
77
89
  state: "ready",
78
90
  cwd: entry.cwd,
@@ -90,6 +102,7 @@ export class ResultTargetStore {
90
102
 
91
103
  /** Traverse supported result shapes and resolve only registered source targets. */
92
104
  public resolve(input: unknown, cwd: string): ResolvedResultTargets {
105
+ input = this.source(input, cwd);
93
106
  const references = this.#references(input);
94
107
  const targets: ResultSourceTarget[] = [];
95
108
  let complete = true;
@@ -102,6 +115,9 @@ export class ResultTargetStore {
102
115
  if (entry.state === "pending")
103
116
  throw new Error("Result target is pending; its write has not been confirmed.");
104
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.");
105
121
  complete &&= entry.complete;
106
122
  targets.push(...entry.targets);
107
123
  }
@@ -113,7 +129,7 @@ export class ResultTargetStore {
113
129
  const resolved = this.resolve(input, cwd);
114
130
  const targets: ResultSourceTarget[] = [];
115
131
  const seen = new Set<string>();
116
- for (const reference of new Set(this.#references(input))) {
132
+ for (const reference of new Set(this.#references(this.source(input, cwd)))) {
117
133
  for (const target of this.resolve(reference, cwd).targets) {
118
134
  for (const range of target.ranges) {
119
135
  const identity = JSON.stringify([target.source, range]);
@@ -128,9 +144,151 @@ export class ResultTargetStore {
128
144
 
129
145
  /** Reject changed source bytes before a consumer uses a retained selection. */
130
146
  public async verify(result: ResolvedResultTargets, signal?: AbortSignal): Promise<void> {
131
- await verifyResultTargets(result, signal);
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)
230
+ throw new Error(
231
+ "Result reference expired or unknown. Run Read/Search again and use the new result.",
232
+ );
233
+ if (result.cwd !== path.resolve(cwd)) throw new Error("Result belongs to another worktree.");
234
+ if (envelope && createHash("sha256").update(input).digest("hex") !== result.digest)
235
+ throw new Error("Result text changed; pass the original result or its UUID.");
236
+ for (const resource of result.resources) this.refresh(resource, cwd);
237
+ if (!this.#results.has(id))
238
+ throw new Error("Result reference expired. Run Read/Search again and use the new result.");
239
+ if (!result.consumable) throw new Error("Only successful source results can be consumed.");
240
+ for (const reference of result.references) {
241
+ if (!this.#entries.has(reference)) {
242
+ this.#results.delete(id);
243
+ throw new Error("Result reference expired. Run Read/Search again and use the new result.");
244
+ }
245
+ }
246
+ if (result.references.length === 1) return result.references[0];
247
+ if (result.references.length > 1) return result.references;
248
+ const resource = result.resources.length === 1 ? result.resources[0] : undefined;
249
+ if (
250
+ resource &&
251
+ (allowResource === true || (allowResource === "live" && /^(?:shell|debug):/u.test(resource)))
252
+ )
253
+ return resource;
254
+ throw new Error("This result has no reusable text selection.");
255
+ }
256
+
257
+ /** Permanently retire every ready selection of a changed file, including derived results. */
258
+ public invalidate(source: string): void {
259
+ const removed = new Set<string>();
260
+ for (const [reference, entry] of this.#entries) {
261
+ if (
262
+ entry.state === "ready" &&
263
+ entry.targets.some((target) => sourcePath(target.source, entry.cwd) === source)
264
+ ) {
265
+ this.#entries.delete(reference);
266
+ removed.add(reference);
267
+ }
268
+ }
269
+ for (const [id, result] of this.#results)
270
+ if (
271
+ result.resources.some((resource) => sourcePath(resource, result.cwd) === source) ||
272
+ result.references.some((reference) => removed.has(reference))
273
+ )
274
+ this.#results.delete(id);
132
275
  }
133
276
 
277
+ /** Detect filesystem generations, so restoring old bytes never revives an old reference. */
278
+ public refresh(source: string, cwd: string): void {
279
+ const identity = sourcePath(source, cwd);
280
+ const key = JSON.stringify([path.resolve(cwd), identity]);
281
+ const stamp = fileStamp(source, cwd);
282
+ const previous = this.#snapshots.get(key);
283
+ if (previous && previous.stamp !== stamp) this.invalidate(identity);
284
+ this.#snapshots.set(key, { source, cwd, stamp });
285
+ }
286
+
287
+ /** Check surviving snapshots at a script boundary, including final formatting. */
288
+ public refreshAll(): void {
289
+ for (const snapshot of [...this.#snapshots.values()])
290
+ this.refresh(snapshot.source, snapshot.cwd);
291
+ }
134
292
  #references(input: unknown): string[] {
135
293
  if (typeof input === "string" && input.startsWith(prefix)) return [input];
136
294
  if (Array.isArray(input)) return input.flatMap((child) => this.#references(child));
@@ -150,6 +308,25 @@ export class ResultTargetStore {
150
308
  }
151
309
  }
152
310
 
311
+ function sourcePath(source: string, cwd: string): string {
312
+ const file = source.startsWith("raw:") ? source.slice(4) : source;
313
+ if (file.startsWith("file:")) {
314
+ try {
315
+ return fileURLToPath(file);
316
+ } catch {
317
+ /* Unresolved protocol labels have no filesystem stamp. */
318
+ }
319
+ }
320
+ return path.resolve(cwd, file);
321
+ }
322
+ function fileStamp(source: string, cwd: string): string | undefined {
323
+ try {
324
+ const stat = statSync(sourcePath(source, cwd), { bigint: true });
325
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
326
+ } catch {
327
+ return undefined;
328
+ }
329
+ }
153
330
  /** Verify retained source snapshots for tools and provider refresh operations. */
154
331
  export async function verifyResultTargets(
155
332
  result: ResolvedResultTargets,