pi-agent-ide 0.6.3 → 0.6.4

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 (355) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +8 -1
  3. package/dist/chunk-2P2OGO3G.js +2 -0
  4. package/dist/{chunk-5QQABP47.js → chunk-3BBJZSMS.js} +1 -1
  5. package/dist/chunk-5J43L2RL.js +11 -0
  6. package/dist/{chunk-ITSNK5YG.js → chunk-7AVXUV4A.js} +2 -2
  7. package/dist/chunk-BAYETTZZ.js +16 -0
  8. package/dist/{chunk-VCTK4JSN.js → chunk-BSICWXMH.js} +1 -1
  9. package/dist/chunk-BVK5A7ED.js +28 -0
  10. package/dist/{chunk-ZM4L5AGN.js → chunk-EDURPQAV.js} +3 -2
  11. package/dist/{chunk-L7JMDDSD.js → chunk-FBOW7XOV.js} +1 -1
  12. package/dist/{chunk-25CZ5ZIU.js → chunk-FUG2TEKI.js} +1 -1
  13. package/dist/chunk-FZBCKIJJ.js +1 -0
  14. package/dist/chunk-HPUAIWIH.js +25 -0
  15. package/dist/chunk-I5JLCFUX.js +1 -0
  16. package/dist/chunk-KUPHNMUK.js +2 -0
  17. package/dist/{chunk-NTYXZ3EL.js → chunk-KVHDMIZS.js} +1 -1
  18. package/dist/{chunk-QDST6VIU.js → chunk-KZC7TI5M.js} +1 -1
  19. package/dist/chunk-MIZAFRDR.js +1 -0
  20. package/dist/chunk-PJPA5EEE.js +2 -0
  21. package/dist/{chunk-GUTQ3PWL.js → chunk-PLKYHUNT.js} +1 -1
  22. package/dist/chunk-QEJGED4V.js +28 -0
  23. package/dist/chunk-SILJ3OL4.js +9 -0
  24. package/dist/{chunk-VXD6FZP5.js → chunk-TQZBVOTT.js} +3 -3
  25. package/dist/chunk-VBICI5YA.js +1 -0
  26. package/dist/chunk-VWW3RLUX.js +12 -0
  27. package/dist/{chunk-O6LE42GK.js → chunk-WJTHY6AG.js} +1 -1
  28. package/dist/chunk-YGGKGZO2.js +1 -0
  29. package/dist/chunk-ZODCBFBL.js +2 -0
  30. package/dist/chunk-ZPT5D4VP.js +2 -0
  31. package/dist/entry-0.js +1 -1
  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-16.js +1 -1
  37. package/dist/entry-17.js +1 -1
  38. package/dist/entry-25.js +2 -2
  39. package/dist/entry-26.js +1 -1
  40. package/dist/entry-27.js +1 -1
  41. package/dist/entry-28.js +1 -1
  42. package/dist/entry-29.js +1 -1
  43. package/dist/entry-30.js +1 -1
  44. package/dist/entry-31.js +11 -11
  45. package/dist/entry-33.js +1 -1
  46. package/dist/entry-37.js +2 -2
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-44.js +1 -1
  49. package/dist/entry-45.js +13 -12
  50. package/dist/entry-46.js +1 -1
  51. package/dist/entry-49.js +1 -1
  52. package/dist/entry-50.js +4 -4
  53. package/dist/entry-51.js +9 -9
  54. package/dist/entry-52.js +1 -1
  55. package/dist/entry-53.js +1 -1
  56. package/dist/entry-55.js +1 -1
  57. package/dist/entry-56.js +1 -1
  58. package/dist/entry-57.js +1 -1
  59. package/dist/entry-58.js +1 -1
  60. package/dist/entry-59.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +1 -1
  63. package/dist/entry-63.js +1 -1
  64. package/dist/entry-66.js +1 -1
  65. package/dist/entry-68.js +1 -1
  66. package/dist/entry-69.js +1 -1
  67. package/dist/entry-70.js +1 -1
  68. package/dist/entry-71.js +1 -0
  69. package/dist/entry-72.js +0 -1
  70. package/dist/entry-73.js +1 -0
  71. package/dist/entry-74.js +0 -1
  72. package/dist/entry-75.js +1 -1
  73. package/dist/entry-76.js +1 -1
  74. package/dist/entry-77.js +1 -324
  75. package/dist/entry-78.js +324 -25
  76. package/dist/entry-79.js +18 -2
  77. package/dist/entry-80.js +2 -1
  78. package/dist/entry-81.js +1 -1
  79. package/dist/entry-82.js +1 -3
  80. package/dist/entry-83.js +5 -3
  81. package/dist/entry-84.js +3 -1
  82. package/dist/entry-85.js +1 -1
  83. package/dist/entry-86.js +1 -1
  84. package/dist/entry-87.js +1 -0
  85. package/dist/pi-agent-ide.js +15 -3
  86. package/docs/agent-guides/editing.md +12 -0
  87. package/docs/agent-guides/json-reading.md +19 -3
  88. package/docs/agent-guides/read-resources.md +6 -0
  89. package/docs/agent-guides/search-code.md +5 -1
  90. package/docs/agent-guides/terminal.md +1 -1
  91. package/docs/code-review.md +99 -0
  92. package/docs/configuration.md +34 -0
  93. package/docs/development.md +15 -19
  94. package/docs/nightly.md +7 -0
  95. package/docs/releases.md +42 -0
  96. package/docs/research/native-codemode-batch-decision.md +27 -0
  97. package/docs/research/native-codemode-batching.md +65 -0
  98. package/docs/structured-results.md +59 -0
  99. package/docs/tools.md +18 -2
  100. package/node_modules/pi-agent-doctor/package.json +1 -1
  101. package/node_modules/pi-agent-documentation/package.json +1 -1
  102. package/node_modules/pi-agent-documentation/src/index.ts +1 -1
  103. package/node_modules/pi-agent-filesystem/index.ts +6 -1
  104. package/node_modules/pi-agent-filesystem/package.json +7 -6
  105. package/node_modules/pi-agent-filesystem/src/path-recovery.ts +109 -0
  106. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  107. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  108. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  109. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  110. package/node_modules/pi-agent-ide-ast/package.json +10 -10
  111. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
  112. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +6 -2
  113. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +17 -0
  114. package/node_modules/pi-agent-ide-changes/index.ts +3 -9
  115. package/node_modules/pi-agent-ide-changes/package.json +8 -7
  116. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
  117. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +125 -47
  118. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  119. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  120. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  121. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  122. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +19 -0
  123. package/node_modules/pi-agent-image/package.json +2 -2
  124. package/node_modules/pi-agent-invariant/package.json +1 -1
  125. package/node_modules/pi-agent-pdf/package.json +2 -2
  126. package/node_modules/pi-agent-read/package.json +7 -7
  127. package/node_modules/pi-agent-read/src/api/tools/read.ts +31 -2
  128. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
  129. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
  130. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +216 -0
  131. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +119 -72
  132. package/node_modules/pi-agent-resource/package.json +1 -1
  133. package/node_modules/pi-agent-resource/src/index.ts +12 -0
  134. package/node_modules/pi-agent-resource/src/resource-access.ts +55 -0
  135. package/node_modules/pi-agent-resource/src/resource-scheduler.ts +204 -0
  136. package/node_modules/pi-agent-resource/src/tool-result.ts +125 -0
  137. package/node_modules/pi-agent-search/package.json +5 -4
  138. package/node_modules/pi-agent-search/src/api/search-parameters.ts +6 -5
  139. package/node_modules/pi-agent-search/src/api/search.ts +11 -0
  140. package/node_modules/pi-agent-search/src/api/structured-result.ts +93 -0
  141. package/node_modules/pi-agent-search/src/core/extension.ts +40 -14
  142. package/node_modules/pi-agent-search/src/core/search-core.ts +136 -77
  143. package/node_modules/pi-agent-search-text/index.ts +3 -0
  144. package/node_modules/pi-agent-search-text/package.json +6 -6
  145. package/node_modules/pi-agent-search-text/src/resolvers.ts +17 -0
  146. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -8
  147. package/node_modules/pi-agent-search-text/src/search-query.ts +42 -34
  148. package/node_modules/pi-agent-search-text/src/search-recipe.ts +18 -4
  149. package/node_modules/pi-agent-search-text/src/search-renderer.ts +37 -3
  150. package/node_modules/pi-agent-search-text/src/search-session.ts +21 -13
  151. package/node_modules/pi-agent-text/package.json +2 -2
  152. package/node_modules/pi-agent-text/src/text-document.ts +15 -10
  153. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  154. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  155. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
  156. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  157. package/node_modules/pi-agent-text-editor/index.ts +4 -2
  158. package/node_modules/pi-agent-text-editor/package.json +21 -17
  159. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +0 -1
  160. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
  161. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
  162. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
  163. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +4 -0
  164. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +95 -34
  165. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +4 -0
  166. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +251 -0
  167. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +32 -12
  168. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +154 -132
  169. package/node_modules/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
  170. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +74 -18
  171. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
  172. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -0
  173. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  174. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +640 -0
  175. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
  176. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +314 -0
  177. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +143 -138
  178. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
  179. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +242 -116
  180. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +109 -47
  181. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
  182. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
  183. package/node_modules/pi-agent-text-editor-renderer/index.ts +8 -1
  184. package/node_modules/pi-agent-text-editor-renderer/package.json +7 -6
  185. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +262 -129
  186. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
  187. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
  188. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
  189. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +16 -1
  190. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  191. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  192. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  193. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  194. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +1 -0
  195. package/node_modules/pi-agent-web/index.ts +20 -0
  196. package/node_modules/pi-agent-web/package.json +8 -7
  197. package/node_modules/pi-agent-web/src/search.ts +112 -0
  198. package/node_modules/pi-agent-web-html/package.json +3 -3
  199. package/node_modules/pi-agent-web-image/package.json +4 -4
  200. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  201. package/node_modules/pi-agent-web-text/package.json +4 -4
  202. package/node_modules/pi-agent-web-text/runtime/entry-87.js +2 -0
  203. package/package.json +42 -36
  204. package/skills/capture-code-review-rule/SKILL.md +60 -0
  205. package/src/code-review/config.ts +68 -0
  206. package/src/code-review/extension.ts +105 -0
  207. package/src/code-review/fragments.ts +26 -0
  208. package/src/code-review/reviewer.ts +198 -0
  209. package/src/composite/host-version.ts +13 -0
  210. package/src/composite/nested-tool-rendering.ts +298 -0
  211. package/src/composite/tool-availability.ts +90 -0
  212. package/src/core/extension.ts +2 -0
  213. package/src/documentation/extension.ts +81 -145
  214. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +6 -1
  215. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -6
  216. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  217. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  218. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/path-recovery.ts +109 -0
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +20 -0
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -7
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +2 -0
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +2 -0
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +112 -0
  230. package/src/extensions/pi-agent-read/package.json +7 -7
  231. package/src/extensions/pi-agent-read/src/api/tools/read.ts +31 -2
  232. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
  233. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
  234. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +216 -0
  235. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +119 -72
  236. package/src/extensions/pi-agent-search/package.json +5 -4
  237. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -0
  238. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  239. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +17 -0
  240. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -8
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +42 -34
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +18 -4
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +37 -3
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +21 -13
  245. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +6 -5
  246. package/src/extensions/pi-agent-search/src/api/search.ts +11 -0
  247. package/src/extensions/pi-agent-search/src/api/structured-result.ts +93 -0
  248. package/src/extensions/pi-agent-search/src/core/extension.ts +40 -14
  249. package/src/extensions/pi-agent-search/src/core/search-core.ts +136 -77
  250. package/src/extensions/pi-agent-text-editor/index.ts +4 -2
  251. package/src/extensions/pi-agent-text-editor/package.json +21 -17
  252. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  253. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  254. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
  255. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  256. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +8 -1
  257. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +7 -6
  258. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +262 -129
  259. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +16 -1
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  265. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +0 -1
  266. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +2 -0
  267. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
  268. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
  269. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
  270. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +4 -0
  271. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +95 -34
  272. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +4 -0
  273. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +251 -0
  274. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +32 -12
  275. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +154 -132
  276. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
  277. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +74 -18
  278. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
  279. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -0
  280. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  281. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +640 -0
  282. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
  283. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +314 -0
  284. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +143 -138
  285. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
  286. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +242 -116
  287. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +109 -47
  288. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
  289. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
  290. package/src/pi-agent-ide.ts +61 -2
  291. package/src/plugins/pi-agent-ide-ast/package.json +10 -10
  292. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
  293. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +6 -2
  294. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +17 -0
  295. package/src/plugins/pi-agent-ide-changes/index.ts +3 -9
  296. package/src/plugins/pi-agent-ide-changes/package.json +8 -7
  297. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
  298. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +125 -47
  299. package/src/plugins/pi-agent-ide-debugger/index.ts +63 -17
  300. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +18 -2
  301. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +24 -4
  302. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +68 -2
  303. package/src/plugins/pi-agent-ide-debugger/src/java-runtime.ts +357 -0
  304. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +55 -3
  305. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +13 -13
  306. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  307. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  308. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  309. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  310. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +19 -0
  311. package/src/plugins/pi-agent-ide-terminal/index.ts +12 -2
  312. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +1 -1
  313. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +65 -30
  314. package/src/plugins/pi-agent-ide-terminal/src/search.ts +13 -8
  315. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +1 -0
  316. package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +100 -0
  317. package/src/plugins/pi-agent-ide-terminal/src/steering.ts +62 -0
  318. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +97 -45
  319. package/src/plugins/pi-agent-ide-terminal/src/types.ts +3 -1
  320. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +15 -6
  321. package/src/plugins/pi-agent-ide-vision/index.ts +16 -1
  322. package/dist/chunk-3E2NTWCN.js +0 -2
  323. package/dist/chunk-4LUW26BX.js +0 -10
  324. package/dist/chunk-5VSE5X5R.js +0 -2
  325. package/dist/chunk-CEX3VOJ7.js +0 -2
  326. package/dist/chunk-FA6BKC5Y.js +0 -1
  327. package/dist/chunk-FEDVTZJG.js +0 -1
  328. package/dist/chunk-HMLH43ZS.js +0 -4
  329. package/dist/chunk-KII2JQC5.js +0 -1
  330. package/dist/chunk-LVWMWWWF.js +0 -28
  331. package/dist/chunk-P7XO5CIP.js +0 -2
  332. package/dist/chunk-PZFOOHY2.js +0 -15
  333. package/dist/chunk-S3ZPXWX7.js +0 -2
  334. package/dist/chunk-T7CZIACQ.js +0 -27
  335. package/dist/chunk-YT42LKFV.js +0 -16
  336. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
  337. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +0 -1
  338. package/node_modules/pi-agent-web/runtime/entry-82.js +0 -2
  339. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +0 -2
  340. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +0 -2
  341. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +0 -2
  342. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
  343. /package/dist/{chunk-4U2GUKNJ.js → chunk-F7NVAC4Q.js} +0 -0
  344. /package/dist/{chunk-ROXXK6TW.js → chunk-PXWDDBBC.js} +0 -0
  345. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-78.js +0 -0
  346. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
  347. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-81.js +0 -0
  348. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-83.js +0 -0
  349. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  350. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  351. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  352. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  353. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  354. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  355. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "pi-agent-web-pdf",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-pdf": "0.6.3",
7
- "pi-agent-resource": "0.6.3"
6
+ "pi-agent-pdf": "0.6.4",
7
+ "pi-agent-resource": "0.6.4"
8
8
  },
9
9
  "pi": {
10
10
  "extensions": [
11
- "./runtime/entry-85.js"
11
+ "./runtime/entry-86.js"
12
12
  ]
13
13
  },
14
14
  "peerDependencies": {
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "pi-agent-web-text",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-resource": "0.6.3",
7
- "pi-agent-text": "0.6.3"
6
+ "pi-agent-resource": "0.6.4",
7
+ "pi-agent-text": "0.6.4"
8
8
  },
9
9
  "pi": {
10
10
  "extensions": [
11
- "./runtime/entry-86.js"
11
+ "./runtime/entry-87.js"
12
12
  ]
13
13
  },
14
14
  "peerDependencies": {
@@ -0,0 +1,2 @@
1
+ export * from "../../../../../../../../dist/entry-87.js";
2
+ export { default } from "../../../../../../../../dist/entry-87.js";
@@ -0,0 +1,2 @@
1
+ export * from "../../../../../../dist/entry-83.js";
2
+ export { default } from "../../../../../../dist/entry-83.js";
@@ -0,0 +1,112 @@
1
+ import type { ResourceResolver } from "pi-agent-resource";
2
+ import {
3
+ selectionData,
4
+ type SearchRequest,
5
+ type SearchResolver,
6
+ type SearchSelectionMatch,
7
+ } from "pi-agent-search/api/search";
8
+
9
+ interface WebSearchResult {
10
+ readonly source: string;
11
+ readonly matches: readonly SearchSelectionMatch[];
12
+ readonly complete: boolean;
13
+ }
14
+
15
+ /** Search the same converted HTTP(S) content as Read, without treating URLs as files. */
16
+ export function createWebSearchResolver(web: ResourceResolver): SearchResolver {
17
+ return {
18
+ id: "web",
19
+ readResources: (request) =>
20
+ request.path !== undefined && /^https?:/iu.test(request.path) ? [request.path] : [],
21
+ async tryResolve(request, context) {
22
+ const source = request.path;
23
+ if (source === undefined || !/^https?:/iu.test(source)) return { kind: "not-handled" };
24
+ if (request.include !== undefined || request.exclude !== undefined) {
25
+ return {
26
+ kind: "failed",
27
+ error: new Error("File include/exclude globs do not apply to a web page."),
28
+ };
29
+ }
30
+ const pattern = searchPattern(request);
31
+ const resolved = await web.tryResolve(source, context);
32
+ if (resolved.kind !== "resolved") return resolved;
33
+ if (resolved.resource.read === undefined)
34
+ return { kind: "failed", error: new Error(`Cannot read ${source}`) };
35
+ const content = await resolved.resource.read({ signal: context.signal });
36
+ if (content.some((block) => block.type !== "text")) {
37
+ return { kind: "failed", error: new Error(`Web search requires text content: ${source}`) };
38
+ }
39
+ const text = content.map((block) => (block.type === "text" ? block.text : "")).join("\n");
40
+ const matches: SearchSelectionMatch[] = [];
41
+ const maximum = request.limit ?? 50;
42
+ for (const [index, lineText] of text.split(/\r\n|\n|\r/u).entries()) {
43
+ context.signal?.throwIfAborted();
44
+ for (const match of lineText.matchAll(pattern)) {
45
+ if (match[0].length === 0) continue;
46
+ const startColumn = match.index;
47
+ const endColumn = startColumn + match[0].length;
48
+ if (
49
+ request.wholeWord === true &&
50
+ (/\p{L}|\p{N}|_/u.test(lineText[startColumn - 1] ?? "") ||
51
+ /\p{L}|\p{N}|_/u.test(lineText[endColumn] ?? ""))
52
+ )
53
+ continue;
54
+ if (matches.length === maximum)
55
+ return {
56
+ kind: "resolved",
57
+ payload: { source, matches, complete: false } satisfies WebSearchResult,
58
+ };
59
+ matches.push({
60
+ source,
61
+ lineNumber: index + 1,
62
+ startColumn,
63
+ endColumn,
64
+ matchedText: match[0],
65
+ lineText,
66
+ });
67
+ }
68
+ }
69
+ return {
70
+ kind: "resolved",
71
+ payload: { source, matches, complete: true } satisfies WebSearchResult,
72
+ };
73
+ },
74
+ toScriptData(payload) {
75
+ const result = payload as WebSearchResult;
76
+ return selectionData(result.matches, result.complete);
77
+ },
78
+ format(payload) {
79
+ const result = payload as WebSearchResult;
80
+ const heading =
81
+ result.matches.length === 0
82
+ ? `No matches in ${result.source}`
83
+ : `${result.matches.length}${result.complete ? "" : "+"} matches in ${result.source}${result.complete ? "" : " (limit reached)"}`;
84
+ const rows = [heading];
85
+ let bytes = Buffer.byteLength(heading);
86
+ for (const match of result.matches) {
87
+ const row = `${result.source}:${match.lineNumber}:${match.startColumn + 1} ${previewMatch(match)}`;
88
+ bytes += Buffer.byteLength(row) + 1;
89
+ if (bytes > 48 * 1024) {
90
+ rows.push("Output shortened. Narrow the query or lower the limit.");
91
+ break;
92
+ }
93
+ rows.push(row);
94
+ }
95
+ return { content: [{ type: "text", text: rows.join("\n") }], details: result };
96
+ },
97
+ };
98
+ }
99
+
100
+ function previewMatch(match: SearchSelectionMatch): string {
101
+ const from = Math.max(0, match.startColumn - 64);
102
+ const to = Math.min(match.lineText.length, match.startColumn + 192);
103
+ return `${from > 0 ? "…" : ""}${match.lineText.slice(from, to)}${to < match.lineText.length ? "…" : ""}`;
104
+ }
105
+ function searchPattern(request: SearchRequest): RegExp {
106
+ const query = request.query;
107
+ const literal = query.startsWith('"') && query.endsWith('"') ? query.slice(1, -1) : query;
108
+ const pattern = query.startsWith("regex:")
109
+ ? query.slice(6)
110
+ : literal.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
111
+ return new RegExp(pattern, request.caseSensitive === true ? "gu" : "giu");
112
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-read",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "pi-agent-documentation": "0.6.3",
28
- "pi-agent-invariant": "0.6.3",
29
- "pi-agent-resource": "0.6.3",
30
- "pi-agent-text": "0.6.3",
31
- "pi-agent-tool-call-interception": "0.6.3",
32
- "pi-agent-tool-ui": "0.6.3"
27
+ "pi-agent-documentation": "0.6.4",
28
+ "pi-agent-invariant": "0.6.4",
29
+ "pi-agent-resource": "0.6.4",
30
+ "pi-agent-text": "0.6.4",
31
+ "pi-agent-tool-call-interception": "0.6.4",
32
+ "pi-agent-tool-ui": "0.6.4"
33
33
  },
34
34
  "pi": {
35
35
  "extensions": [
@@ -7,6 +7,7 @@ import {
7
7
  type TextContent,
8
8
  } from "pi-agent-resource";
9
9
  import { Type } from "typebox";
10
+ import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
10
11
  import { Value } from "typebox/value";
11
12
 
12
13
  import type { ToolDefinition, TruncationResult } from "@earendil-works/pi-coding-agent";
@@ -50,12 +51,19 @@ export interface ReadFailure {
50
51
  readonly stage?: ReadPipelineStage;
51
52
  readonly message: string;
52
53
  readonly cause?: unknown;
54
+ /** Ranked exact paths offered as hints, never read automatically. */
55
+ readonly candidates?: readonly { readonly path: string }[];
53
56
  }
54
57
 
55
58
  export type ReadResultRenderer = NonNullable<ToolDefinition["renderResult"]>;
56
59
  export type ReadCallRenderer = NonNullable<ToolDefinition["renderCall"]>;
57
60
 
58
61
  export interface ResourceResolverRegistration {
62
+ /** Offers recovery hints after this resolver fails to resolve or read a source. */
63
+ readonly recoverFailure?: (
64
+ failure: ReadFailure,
65
+ context: ResourceResolverContext,
66
+ ) => Promise<ReadFailure["candidates"]>;
59
67
  readonly resolver: ResourceResolver;
60
68
  /** Selects a resolver-specific call header before resource resolution. */
61
69
  readonly matchesCall?: (source: string) => boolean;
@@ -187,6 +195,7 @@ export type ReadScriptData =
187
195
  readonly byteLength: number;
188
196
  readonly totalBytes: number;
189
197
  readonly bytes: readonly number[];
198
+ readonly truncated?: boolean;
190
199
  }
191
200
  | {
192
201
  readonly kind: "text";
@@ -195,6 +204,11 @@ export type ReadScriptData =
195
204
  readonly lines: readonly ReadTextLine[];
196
205
  readonly startLine: number;
197
206
  readonly endLine: number;
207
+ readonly references?: readonly {
208
+ readonly value: string;
209
+ readonly kind: string;
210
+ readonly state?: string;
211
+ }[];
198
212
  readonly totalLines: number;
199
213
  }
200
214
  | {
@@ -208,7 +222,8 @@ export type ReadScriptData =
208
222
  readonly resources: readonly ReadScriptData[];
209
223
  };
210
224
  export interface ReadToolResult {
211
- /** Present only for script execution; never reconstructed from rendered text. */
225
+ readonly structuredContent?: AgentToolResult<ReadResultDetails>["structuredContent"];
226
+ /** Canonical adapter data; never reconstructed from rendered text or stored in renderer details. */
212
227
  readonly script?: ReadScriptData;
213
228
  readonly content: (TextContent | ImageContent)[];
214
229
  readonly details: ReadResultDetails;
@@ -216,7 +231,16 @@ export interface ReadToolResult {
216
231
  }
217
232
 
218
233
  export type ReadStageOutcome =
219
- | { readonly kind: "continue"; readonly context: ReadPipelineContext }
234
+ | {
235
+ readonly kind: "continue";
236
+ readonly context: ReadPipelineContext;
237
+ /**
238
+ * Post-read handlers inspect the same base result concurrently. Return a pure
239
+ * decoration here; transforms apply in registration order, unless a handler
240
+ * returns a final result. Context changes are ignored during post-read.
241
+ */
242
+ readonly transform?: (result: ReadToolResult) => ReadToolResult;
243
+ }
220
244
  | { readonly kind: "return"; readonly result: ReadToolResult };
221
245
 
222
246
  export type ReadPreReadHandler = ReadPipelineHandler;
@@ -413,3 +437,8 @@ function isRecord(value: unknown): value is Record<string, unknown> {
413
437
  }
414
438
 
415
439
  export { readParameters } from "#src/api/read-parameters.js";
440
+ export {
441
+ readDataSchema,
442
+ readOutputSchema,
443
+ structuredRead,
444
+ } from "#src/core/tools/read/structured-result.js";
@@ -107,16 +107,15 @@ export async function readRaw(
107
107
  byteLength: count,
108
108
  totalBytes: stat.size,
109
109
  },
110
- ...(audience === "script" && {
111
- script: {
112
- kind: "bytes" as const,
113
- source,
114
- byteOffset: start,
115
- byteLength: count,
116
- totalBytes: stat.size,
117
- bytes: Array.from(bytes),
118
- },
119
- }),
110
+ script: {
111
+ kind: "bytes",
112
+ source,
113
+ byteOffset: start,
114
+ byteLength: count,
115
+ totalBytes: stat.size,
116
+ bytes: Array.from(bytes),
117
+ truncated: count < requestedLength,
118
+ },
120
119
  };
121
120
  } finally {
122
121
  await handle.close();
@@ -65,9 +65,7 @@ export function projectReadState(
65
65
  const projected = projectAgentContent(state.content);
66
66
 
67
67
  return {
68
- ...(options?.audience === "script" && {
69
- script: { kind: "native" as const, source: state.source, blocks: state.content },
70
- }),
68
+ script: { kind: "native", source: state.source, blocks: state.content },
71
69
  content: projected.content,
72
70
  details: {
73
71
  ...readDetails(state),
@@ -104,17 +102,16 @@ export function projectReadState(
104
102
  ];
105
103
 
106
104
  return {
107
- ...(options?.audience === "script" && {
108
- script: {
109
- kind: "text" as const,
110
- source: state.source,
111
- content: lines.map((line) => line.content + line.lineEnding).join(""),
112
- lines,
113
- startLine: lines[0]?.lineNumber ?? 0,
114
- endLine: lines.at(-1)?.lineNumber ?? 0,
115
- totalLines,
116
- },
117
- }),
105
+ script: {
106
+ kind: "text",
107
+ ...(state.text.references === undefined ? {} : { references: state.text.references }),
108
+ source: state.source,
109
+ content: lines.map((line) => line.content + line.lineEnding).join(""),
110
+ lines,
111
+ startLine: lines[0]?.lineNumber ?? 0,
112
+ endLine: lines.at(-1)?.lineNumber ?? 0,
113
+ totalLines,
114
+ },
118
115
  content,
119
116
  details: {
120
117
  ...readDetails(state),
@@ -140,7 +137,23 @@ function renderFinalTextLines(
140
137
 
141
138
  export function failureResult(failure: ReadFailure): ReadToolResult {
142
139
  return {
143
- content: [{ type: "text", text: `${failure.code}: ${failure.message}` }],
140
+ content: [
141
+ {
142
+ type: "text",
143
+ text: [
144
+ `${failure.code}: ${failure.message}`,
145
+ ...(failure.candidates?.length
146
+ ? [
147
+ "",
148
+ "Possible matches:",
149
+ ...failure.candidates.map((candidate) => `- ${JSON.stringify(candidate.path)}`),
150
+ "",
151
+ "Retry read with an exact candidate path.",
152
+ ]
153
+ : []),
154
+ ].join("\n"),
155
+ },
156
+ ],
144
157
  details: { failure },
145
158
  isError: true,
146
159
  };
@@ -0,0 +1,216 @@
1
+ import { Type } from "typebox";
2
+ import { structuredResultSchema, withStructuredResult } from "pi-agent-resource";
3
+ import type { ReadScriptData, ReadToolResult } from "#src/api/tools/read.js";
4
+ import type { TextLine } from "pi-agent-text";
5
+
6
+ const reference = Type.Object(
7
+ { value: Type.String(), kind: Type.String(), state: Type.Optional(Type.String()) },
8
+ { additionalProperties: false },
9
+ );
10
+ const line = Type.Object(
11
+ {
12
+ lineNumber: Type.Integer(),
13
+ content: Type.String(),
14
+ lineEnding: Type.String(),
15
+ anchors: Type.Optional(Type.Array(Type.String())),
16
+ },
17
+ { additionalProperties: false },
18
+ );
19
+ const continuation = Type.Object(
20
+ { path: Type.String(), offset: Type.Integer() },
21
+ { additionalProperties: false },
22
+ );
23
+ const common = {
24
+ source: Type.String(),
25
+ truncated: Type.Boolean(),
26
+ continuation: Type.Optional(continuation),
27
+ fullResult: Type.Optional(Type.String()),
28
+ };
29
+ const text = Type.Object(
30
+ {
31
+ ...common,
32
+ kind: Type.Literal("text"),
33
+ lines: Type.Array(line),
34
+ startLine: Type.Integer(),
35
+ endLine: Type.Integer(),
36
+ totalLines: Type.Integer(),
37
+ references: Type.Optional(Type.Array(reference)),
38
+ },
39
+ { additionalProperties: false },
40
+ );
41
+ const bytes = Type.Object(
42
+ {
43
+ ...common,
44
+ kind: Type.Literal("bytes"),
45
+ bytes: Type.Array(Type.Integer({ minimum: 0, maximum: 255 })),
46
+ byteOffset: Type.Integer(),
47
+ byteLength: Type.Integer(),
48
+ totalBytes: Type.Integer(),
49
+ },
50
+ { additionalProperties: false },
51
+ );
52
+ const block = Type.Union([
53
+ Type.Object({ type: Type.Literal("text"), text: Type.String() }, { additionalProperties: false }),
54
+ Type.Object(
55
+ { type: Type.Literal("image"), data: Type.String(), mimeType: Type.String() },
56
+ { additionalProperties: false },
57
+ ),
58
+ ]);
59
+ const native = Type.Object(
60
+ { ...common, kind: Type.Literal("native"), blocks: Type.Array(block) },
61
+ { additionalProperties: false },
62
+ );
63
+ export const readDataSchema = Type.Union([
64
+ Type.Object(
65
+ {
66
+ kind: Type.Literal("recovery"),
67
+ source: Type.String(),
68
+ candidates: Type.Array(Type.Object({ path: Type.String() }, { additionalProperties: false })),
69
+ },
70
+ { additionalProperties: false },
71
+ ),
72
+ text,
73
+ bytes,
74
+ native,
75
+ Type.Object(
76
+ {
77
+ kind: Type.Literal("resources"),
78
+ source: Type.Optional(Type.String()),
79
+ resources: Type.Array(Type.Union([text, bytes, native])),
80
+ truncated: Type.Boolean(),
81
+ fullResult: Type.Optional(Type.String()),
82
+ },
83
+ { additionalProperties: false },
84
+ ),
85
+ ]);
86
+ export const readOutputSchema = structuredResultSchema(readDataSchema);
87
+
88
+ function publicLine(value: TextLine) {
89
+ return {
90
+ lineNumber: value.lineNumber,
91
+ content: value.content,
92
+ lineEnding: value.lineEnding,
93
+ ...(value.anchors === undefined ? {} : { anchors: [...value.anchors] }),
94
+ };
95
+ }
96
+ /** Bound selected data, not source snapshots or human-facing presentation. */
97
+ function publicData(value: ReadScriptData): unknown {
98
+ if (value.kind === "resources") {
99
+ const resources = value.resources.map((resource) => publicData(resource));
100
+ return {
101
+ kind: value.kind,
102
+ ...(value.source === undefined ? {} : { source: value.source }),
103
+ resources,
104
+ truncated: resources.some(
105
+ (resource) =>
106
+ typeof resource === "object" &&
107
+ resource !== null &&
108
+ "truncated" in resource &&
109
+ resource.truncated === true,
110
+ ),
111
+ };
112
+ }
113
+ if (value.kind === "bytes") {
114
+ const bytes = value.bytes.slice(0, 32768);
115
+ const truncated = value.truncated === true || bytes.length < value.bytes.length;
116
+ return {
117
+ kind: value.kind,
118
+ source: value.source,
119
+ bytes,
120
+ byteOffset: value.byteOffset,
121
+ byteLength: bytes.length,
122
+ totalBytes: value.totalBytes,
123
+ truncated,
124
+ ...(value.byteOffset + bytes.length < value.totalBytes
125
+ ? { continuation: { path: value.source, offset: value.byteOffset + bytes.length } }
126
+ : {}),
127
+ };
128
+ }
129
+ if (value.kind === "native")
130
+ return {
131
+ kind: value.kind,
132
+ source: value.source,
133
+ truncated: false,
134
+ blocks: value.blocks.map((block) => {
135
+ 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
+ throw new TypeError("Custom content requires a structured adapter");
139
+ }),
140
+ };
141
+ const lines = [];
142
+ let size = 0;
143
+ for (const line of value.lines) {
144
+ const projected = publicLine(line);
145
+ size += Buffer.byteLength(JSON.stringify(projected));
146
+ if (lines.length >= 2000 || size > 512 * 1024) break;
147
+ lines.push(projected);
148
+ }
149
+ if (lines.length === 0 && value.lines.length > 0)
150
+ throw new RangeError(
151
+ "Selected line exceeds the structured window; use a raw byte range or a source-specific view",
152
+ );
153
+ const truncated = lines.length < value.lines.length;
154
+ const endLine = lines.at(-1)?.lineNumber ?? value.startLine - 1;
155
+ // Continue against the resolved source with absolute line numbers, not a relative selector.
156
+ return {
157
+ kind: value.kind,
158
+ source: value.source,
159
+ lines,
160
+ startLine: lines[0]?.lineNumber ?? 0,
161
+ endLine: lines.at(-1)?.lineNumber ?? 0,
162
+ totalLines: value.totalLines,
163
+ truncated,
164
+ ...(value.references === undefined ? {} : { references: value.references }),
165
+ ...(truncated || endLine < value.totalLines
166
+ ? { continuation: { path: value.source, offset: endLine + 1 } }
167
+ : {}),
168
+ };
169
+ }
170
+
171
+ /** Require resolver-owned script data. Never reconstruct it from rendered content or renderer details. */
172
+ export function structuredRead(result: ReadToolResult): ReadToolResult {
173
+ const failure = result.details.failure;
174
+ if (result.isError || failure !== undefined)
175
+ return withStructuredResult(result, readDataSchema, {
176
+ status: "error",
177
+ ...(failure?.candidates?.length && failure.source !== undefined
178
+ ? {
179
+ data: { kind: "recovery", source: failure.source, candidates: failure.candidates },
180
+ }
181
+ : {}),
182
+ errors: [
183
+ {
184
+ code: failure?.code ?? "READ_FAILED",
185
+ message: failure?.message ?? "Read failed",
186
+ ...(failure?.source === undefined ? {} : { source: failure.source }),
187
+ },
188
+ ],
189
+ });
190
+ try {
191
+ if (result.script === undefined)
192
+ throw new TypeError("Read handler must return structured script data");
193
+ const data = publicData(result.script);
194
+ return withStructuredResult(result, readDataSchema, {
195
+ status: "success",
196
+ data:
197
+ result.details.temporarySource !== undefined && typeof data === "object" && data !== null
198
+ ? { ...data, fullResult: result.details.temporarySource }
199
+ : data,
200
+ errors: [],
201
+ });
202
+ } catch (error) {
203
+ return withStructuredResult(result, readDataSchema, {
204
+ status: "error",
205
+ errors: [
206
+ {
207
+ code:
208
+ error instanceof RangeError
209
+ ? "STRUCTURED_RESULT_TOO_LARGE"
210
+ : "STRUCTURED_ADAPTER_REQUIRED",
211
+ message: error instanceof Error ? error.message : String(error),
212
+ },
213
+ ],
214
+ });
215
+ }
216
+ }