pi-agent-ide 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +12 -8
  3. package/dist/chunk-5MSNYFDE.js +1 -0
  4. package/dist/chunk-5VSE5X5R.js +2 -0
  5. package/dist/chunk-6EYWFBNG.js +0 -0
  6. package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
  7. package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
  8. package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
  9. package/dist/{chunk-XF5PVZOS.js → chunk-B5KB2I7J.js} +1 -1
  10. package/dist/{chunk-WNMGUALD.js → chunk-CEKXBS55.js} +1 -1
  11. package/dist/chunk-CW53ZTU3.js +2 -0
  12. package/dist/chunk-EWNWKDMP.js +4 -0
  13. package/dist/{chunk-LQYZG62K.js → chunk-GUTQ3PWL.js} +1 -1
  14. package/dist/chunk-HGPUI7F3.js +1 -0
  15. package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
  16. package/dist/chunk-ITSNK5YG.js +7 -0
  17. package/dist/chunk-KAB3AYA2.js +1 -0
  18. package/dist/{chunk-THSCUT2L.js → chunk-LRYE2WCN.js} +1 -1
  19. package/dist/{chunk-76WHES5H.js → chunk-M5L42DWE.js} +5 -5
  20. package/dist/chunk-M5MJP7Z2.js +1 -0
  21. package/dist/chunk-NMFQGKPE.js +2 -0
  22. package/dist/chunk-NTYXZ3EL.js +3 -0
  23. package/dist/{chunk-P6T3Q7LB.js → chunk-QDST6VIU.js} +1 -1
  24. package/dist/chunk-RHV5STR3.js +3 -0
  25. package/dist/chunk-ROXXK6TW.js +0 -0
  26. package/dist/chunk-SSHZEWWV.js +1 -0
  27. package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
  28. package/dist/chunk-VZJIZXSH.js +14 -0
  29. package/dist/chunk-YHADTHQM.js +1 -0
  30. package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
  31. package/dist/{chunk-ZXN3TWWW.js → chunk-ZM4L5AGN.js} +1 -1
  32. package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
  33. package/dist/entry-0.js +1 -1
  34. package/dist/entry-1.js +1 -1
  35. package/dist/entry-10.js +1 -1
  36. package/dist/entry-12.js +1 -1
  37. package/dist/entry-13.js +1 -1
  38. package/dist/entry-14.js +1 -1
  39. package/dist/entry-2.js +1 -1
  40. package/dist/entry-21.js +1 -1
  41. package/dist/entry-24.js +1 -1
  42. package/dist/entry-25.js +1 -1
  43. package/dist/entry-26.js +10 -5
  44. package/dist/entry-28.js +1 -1
  45. package/dist/entry-29.js +1 -1
  46. package/dist/entry-31.js +3 -3
  47. package/dist/entry-32.js +6 -5
  48. package/dist/entry-36.js +1 -1
  49. package/dist/entry-37.js +1 -1
  50. package/dist/entry-38.js +1 -1
  51. package/dist/entry-39.js +1 -1
  52. package/dist/entry-4.js +1 -1
  53. package/dist/entry-40.js +12 -8
  54. package/dist/entry-42.js +1 -1
  55. package/dist/entry-43.js +1 -1
  56. package/dist/entry-44.js +1 -1
  57. package/dist/entry-45.js +4 -4
  58. package/dist/entry-46.js +10 -10
  59. package/dist/entry-47.js +1 -1
  60. package/dist/entry-48.js +1 -1
  61. package/dist/entry-49.js +1 -1
  62. package/dist/entry-50.js +1 -1
  63. package/dist/entry-51.js +1 -1
  64. package/dist/entry-52.js +1 -1
  65. package/dist/entry-53.js +1 -1
  66. package/dist/entry-54.js +1 -0
  67. package/dist/entry-55.js +0 -1
  68. package/dist/entry-56.js +1 -0
  69. package/dist/entry-57.js +0 -1
  70. package/dist/entry-58.js +1 -1
  71. package/dist/entry-59.js +1 -1
  72. package/dist/entry-60.js +1 -1
  73. package/dist/entry-61.js +1 -1
  74. package/dist/entry-62.js +1 -1
  75. package/dist/entry-63.js +1 -0
  76. package/dist/entry-64.js +0 -1
  77. package/dist/entry-65.js +1 -0
  78. package/dist/entry-66.js +0 -1
  79. package/dist/entry-67.js +1 -1
  80. package/dist/entry-68.js +1 -1
  81. package/dist/entry-69.js +1 -59
  82. package/dist/entry-70.js +123 -4
  83. package/dist/entry-71.js +30 -1
  84. package/dist/entry-72.js +2 -29
  85. package/dist/entry-73.js +1 -2
  86. package/dist/entry-74.js +1 -1
  87. package/dist/entry-75.js +1 -1
  88. package/dist/entry-76.js +3 -1
  89. package/dist/entry-77.js +1 -3
  90. package/dist/entry-78.js +1 -1
  91. package/dist/entry-79.js +1 -1
  92. package/dist/pi-agent-ide.js +3 -2
  93. package/docs/configuration.md +32 -11
  94. package/docs/tools.md +6 -0
  95. package/node_modules/pi-agent-doctor/package.json +1 -1
  96. package/node_modules/pi-agent-filesystem/package.json +6 -6
  97. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  98. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  99. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  100. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  101. package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -3
  102. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  103. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  104. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  105. package/node_modules/pi-agent-ide-changes/index.ts +21 -5
  106. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  107. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  108. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  109. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  110. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +26 -8
  111. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
  112. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  113. package/node_modules/pi-agent-ide-lint/index.ts +46 -17
  114. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  115. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
  116. package/node_modules/pi-agent-ide-lsp/index.ts +126 -8
  117. package/node_modules/pi-agent-ide-lsp/package.json +9 -8
  118. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  119. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  120. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  121. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  122. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  123. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  124. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  125. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  126. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  127. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  128. package/node_modules/pi-agent-image/package.json +2 -2
  129. package/node_modules/pi-agent-invariant/package.json +1 -1
  130. package/node_modules/pi-agent-pdf/package.json +2 -2
  131. package/node_modules/pi-agent-read/package.json +6 -6
  132. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  133. package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
  134. package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
  135. package/node_modules/pi-agent-read/src/core/read-core.ts +26 -2
  136. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  137. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  138. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +61 -14
  139. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  140. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  141. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  142. package/node_modules/pi-agent-resource/package.json +1 -1
  143. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  144. package/node_modules/pi-agent-search/package.json +3 -3
  145. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  146. package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
  147. package/node_modules/pi-agent-search/src/api/search.ts +55 -1
  148. package/node_modules/pi-agent-search/src/core/extension.ts +2 -23
  149. package/node_modules/pi-agent-search/src/core/search-core.ts +28 -3
  150. package/node_modules/pi-agent-search-text/index.ts +44 -4
  151. package/node_modules/pi-agent-search-text/package.json +6 -6
  152. package/node_modules/pi-agent-search-text/src/search-session.ts +65 -25
  153. package/node_modules/pi-agent-text/package.json +2 -2
  154. package/node_modules/pi-agent-text/src/text-document.ts +5 -0
  155. package/node_modules/pi-agent-text/src/text-target.ts +4 -0
  156. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  157. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  158. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  159. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  160. package/node_modules/pi-agent-text-editor/index.ts +1 -3
  161. package/node_modules/pi-agent-text-editor/package.json +34 -24
  162. package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
  163. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  164. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  165. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  166. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  167. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  168. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  169. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  170. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  171. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  172. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  173. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  174. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  175. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  176. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  177. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  178. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  179. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  180. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  181. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  182. package/node_modules/pi-agent-text-editor/src/core/extension.ts +6 -0
  183. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  184. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  185. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  186. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  187. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  188. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  189. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  190. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  191. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +173 -49
  192. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  195. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  196. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  197. package/node_modules/pi-agent-text-editor-renderer/index.ts +88 -1
  198. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  199. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  200. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -10
  201. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  202. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  203. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  204. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
  205. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  206. package/node_modules/pi-agent-web/package.json +7 -7
  207. package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
  208. package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
  209. package/node_modules/pi-agent-web-html/package.json +3 -3
  210. package/node_modules/pi-agent-web-image/package.json +4 -4
  211. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  212. package/node_modules/pi-agent-web-text/package.json +4 -4
  213. package/package.json +38 -38
  214. package/src/api/plugin-protocol.ts +10 -2
  215. package/src/api/tool-config.ts +73 -2
  216. package/src/code-view/diagnostic-view.ts +22 -3
  217. package/src/composite/builtin-extensions.ts +4 -15
  218. package/src/composite/extensions-config.ts +41 -0
  219. package/src/composite/feature-flags.ts +32 -0
  220. package/src/composite/module-labels.ts +55 -0
  221. package/src/composite/module-settings-store.ts +44 -0
  222. package/src/composite/module-settings.ts +132 -0
  223. package/src/composite/selection.ts +4 -4
  224. package/src/composite/settings-panel.ts +71 -0
  225. package/src/core/diagnostic-delivery.ts +29 -0
  226. package/src/core/diagnostic-entry.ts +51 -3
  227. package/src/core/diagnostic-store.ts +56 -5
  228. package/src/core/extension.ts +34 -33
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  230. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  231. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  232. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  233. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  234. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  235. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
  236. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  237. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  238. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  239. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
  241. package/src/extensions/pi-agent-read/package.json +6 -6
  242. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  243. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
  244. package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
  245. package/src/extensions/pi-agent-read/src/core/read-core.ts +26 -2
  246. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  247. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  248. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +61 -14
  249. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  250. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  251. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  252. package/src/extensions/pi-agent-search/package.json +3 -3
  253. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +44 -4
  254. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  255. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +65 -25
  256. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  257. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
  258. package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
  259. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -23
  260. package/src/extensions/pi-agent-search/src/core/search-core.ts +28 -3
  261. package/src/extensions/pi-agent-text-editor/index.ts +1 -3
  262. package/src/extensions/pi-agent-text-editor/package.json +34 -24
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +88 -1
  268. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  269. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  270. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -10
  271. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  272. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  273. package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
  274. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
  275. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  276. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  277. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  278. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  279. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  280. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  281. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  282. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  283. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  284. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  285. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  286. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  287. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  288. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  289. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  290. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  291. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  292. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  293. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  294. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +6 -0
  295. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  296. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  297. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  298. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  299. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  300. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  301. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  302. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  303. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +173 -49
  304. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
  305. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  306. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  307. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  308. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  309. package/src/pi-agent-ide.ts +42 -8
  310. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  311. package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -3
  312. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  313. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  314. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  315. package/src/plugins/pi-agent-ide-changes/index.ts +21 -5
  316. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  317. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  318. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  319. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -11
  320. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  321. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +26 -8
  322. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
  323. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  324. package/src/plugins/pi-agent-ide-lint/index.ts +46 -17
  325. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  326. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
  327. package/src/plugins/pi-agent-ide-lsp/index.ts +126 -8
  328. package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
  329. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  330. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  331. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  332. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  333. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  334. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  335. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  336. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  337. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  338. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  339. package/src/post-edit/gate.ts +15 -2
  340. package/dist/chunk-4U6KGABH.js +0 -1
  341. package/dist/chunk-6ACQQBUY.js +0 -7
  342. package/dist/chunk-GFWDXTOB.js +0 -4
  343. package/dist/chunk-JASLOB2X.js +0 -1
  344. package/dist/chunk-JJVXUL5U.js +0 -2
  345. package/dist/chunk-KCEOTU5Z.js +0 -3
  346. package/dist/chunk-KVGQG43U.js +0 -1
  347. package/dist/chunk-QJFRAMK7.js +0 -2
  348. package/dist/chunk-RAZOACDD.js +0 -2
  349. package/dist/chunk-RIGRP3FD.js +0 -1
  350. package/dist/chunk-X6MPU7UO.js +0 -3
  351. package/dist/chunk-YPHXLAQF.js +0 -1
  352. package/dist/entry-80.js +0 -1
  353. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  354. package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
  355. package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
  356. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  357. package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
  358. package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
  359. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  360. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
  361. package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
  362. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
  363. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
  364. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
  365. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
  366. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
  367. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  368. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
  369. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
  370. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  371. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  372. /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
  373. /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
  374. /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  375. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
  376. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
  377. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
  378. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  379. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  380. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  381. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  382. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  383. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  384. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  385. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
@@ -39,6 +39,57 @@ interface ReadCallArguments {
39
39
  readonly views?: unknown;
40
40
  }
41
41
 
42
+ interface ReadWindowPresentation {
43
+ readonly pathSuffix: string;
44
+ readonly qualifiers: readonly { readonly text: string }[];
45
+ readonly details: readonly { readonly label: string; readonly value: string }[];
46
+ }
47
+
48
+ function readWindowPresentation(
49
+ path: string,
50
+ rawOffset: unknown,
51
+ rawLimit: unknown,
52
+ ): ReadWindowPresentation {
53
+ const offset = typeof rawOffset === "number" ? rawOffset : undefined;
54
+ const limit = typeof rawLimit === "number" ? rawLimit : undefined;
55
+ if (offset === undefined && limit === undefined) {
56
+ return { pathSuffix: "", qualifiers: [], details: [] };
57
+ }
58
+
59
+ const relative = path === "inherited source" || path.includes("#");
60
+ if (relative) {
61
+ const start = offset ?? 1;
62
+ const range = limit === undefined ? String(start) : `${start}-${start + limit - 1}`;
63
+ return {
64
+ pathSuffix: "",
65
+ qualifiers: [{ text: `relative lines ${range}` }],
66
+ details: [{ label: "relative lines", value: range }],
67
+ };
68
+ }
69
+
70
+ if (offset !== undefined && offset < 0) {
71
+ return {
72
+ pathSuffix: "",
73
+ qualifiers: [
74
+ { text: `tail ${Math.abs(offset)}` },
75
+ ...(limit === undefined ? [] : [{ text: `limit ${limit}` }]),
76
+ ],
77
+ details: [
78
+ { label: "tail", value: String(Math.abs(offset)) },
79
+ ...(limit === undefined ? [] : [{ label: "limit", value: String(limit) }]),
80
+ ],
81
+ };
82
+ }
83
+
84
+ const start = Math.max(1, offset ?? 1);
85
+ const range = limit === undefined ? String(start) : `${start}-${start + limit - 1}`;
86
+ return {
87
+ pathSuffix: `:${range}`,
88
+ qualifiers: [],
89
+ details: [{ label: "lines", value: range }],
90
+ };
91
+ }
92
+
42
93
  /** Renders the requested read source and non-default options in the shared tool-card header. */
43
94
  export function renderReadCall(
44
95
  arguments_: ReadCallArguments,
@@ -54,26 +105,17 @@ export function renderReadCall(
54
105
  );
55
106
  }
56
107
  const path = typeof arguments_.path === "string" ? arguments_.path : "inherited source";
57
- const offset = typeof arguments_.offset === "number" ? arguments_.offset : undefined;
58
- const limit = typeof arguments_.limit === "number" ? arguments_.limit : undefined;
108
+ const window = readWindowPresentation(path, arguments_.offset, arguments_.limit);
59
109
  const views = Array.isArray(arguments_.views)
60
110
  ? arguments_.views.filter((view): view is string => typeof view === "string")
61
111
  : [];
62
112
  const qualifiers = [
63
- ...(offset === undefined
64
- ? []
65
- : [
66
- {
67
- text: offset < 0 ? `tail ${String(Math.abs(offset))}` : `offset ${String(offset)}`,
68
- },
69
- ]),
70
- ...(limit === undefined ? [] : [{ text: `limit ${String(limit)}` }]),
113
+ ...window.qualifiers,
71
114
  ...(views.length === 0 ? [] : [{ text: `views ${views.join(",")}` }]),
72
115
  ];
73
116
  const details = [
74
117
  ...(typeof arguments_.path === "string" ? [{ label: "path", value: arguments_.path }] : []),
75
- ...(offset === undefined ? [] : [{ label: "offset", value: String(offset) }]),
76
- ...(limit === undefined ? [] : [{ label: "limit", value: String(limit) }]),
118
+ ...window.details,
77
119
  ...(views.length === 0 ? [] : [{ label: "views", value: views.join(",") }]),
78
120
  ];
79
121
  return toolCallHeader(
@@ -81,7 +123,7 @@ export function renderReadCall(
81
123
  {
82
124
  tool: "read",
83
125
  primary: {
84
- text: path,
126
+ text: `${path}${window.pathSuffix}`,
85
127
  color: typeof arguments_.path === "string" ? "accent" : "muted",
86
128
  underline: typeof arguments_.path === "string",
87
129
  truncate: "start",
@@ -122,6 +164,9 @@ export function createReadResultRenderer(options: ReadResultRendererOptions): Re
122
164
  return new Text(theme.fg(color, text), 0, 0);
123
165
  }
124
166
 
167
+ const check = readDetails(result.details).diagnosticCheck;
168
+ if (check?.complete && check.count === 0) return new Container();
169
+
125
170
  if (!hasTextContent(result)) {
126
171
  return context.lastComponent instanceof Container ? context.lastComponent : new Container();
127
172
  }
@@ -180,7 +225,9 @@ export class ReadResultPanel implements Component {
180
225
 
181
226
  const innerWidth = width - 2;
182
227
  const contentWidth = Math.max(1, innerWidth - 2);
183
- const renderedRows = renderContentRows(this.state, contentWidth);
228
+ const renderedRows = renderContentRows(this.state, contentWidth).flatMap((row) =>
229
+ wrapTextWithAnsi(row, contentWidth),
230
+ );
184
231
  const rows = compactRows(renderedRows, this.state.expanded, this.state.theme);
185
232
  const lines = [renderTopBorder(this.state, innerWidth, this.state.theme)];
186
233
 
@@ -42,6 +42,7 @@ export function createReadState(
42
42
  }
43
43
 
44
44
  export interface ReadProjectionOptions {
45
+ readonly audience?: "agent" | "script";
45
46
  /** Absolute 1-based line where an anchored read's window starts. */
46
47
  readonly originLine?: number;
47
48
  }
@@ -64,6 +65,9 @@ export function projectReadState(
64
65
  const projected = projectAgentContent(state.content);
65
66
 
66
67
  return {
68
+ ...(options?.audience === "script" && {
69
+ script: { kind: "native" as const, source: state.source, blocks: state.content },
70
+ }),
67
71
  content: projected.content,
68
72
  details: {
69
73
  ...readDetails(state),
@@ -100,6 +104,17 @@ export function projectReadState(
100
104
  ];
101
105
 
102
106
  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
+ }),
103
118
  content,
104
119
  details: {
105
120
  ...readDetails(state),
@@ -1,73 +1,68 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { mkdir, mkdtemp, readFile, rm, unlink, writeFile } from "node:fs/promises";
2
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
 
6
6
  import type { AgentContent, ResourceResolutionAttempt, ResourceResolver } from "pi-agent-resource";
7
7
 
8
- export const TEMP_RESOURCE_TTL_MS = 5 * 60_000;
9
-
10
- interface TemporaryResource {
11
- activeReads: number;
12
- lastUsedAt: number;
13
- readonly filePath: string;
14
- }
15
-
16
8
  export interface TempResourceStoreOptions {
9
+ /** Parent folder for this store's private temporary directory. */
17
10
  readonly parentDirectory?: string;
18
- readonly ttlMs?: number;
19
11
  }
20
12
 
13
+ /** Keeps temporary text resources isolated and readable until the owning runtime disposes it. */
21
14
  export class TempResourceStore {
22
15
  readonly resolver: ResourceResolver;
23
- readonly #entries = new Map<string, TemporaryResource>();
16
+ readonly #entries = new Map<string, string>();
17
+ readonly #pendingSaves = new Set<Promise<string>>();
24
18
  readonly #parentDirectory: string;
25
- readonly #ttlMs: number;
26
19
  #directoryReady: Promise<string> | undefined;
27
- #disposed = false;
28
- #timer: ReturnType<typeof setTimeout> | undefined;
20
+ #disposal: Promise<void> | undefined;
29
21
 
30
22
  constructor(options: TempResourceStoreOptions = {}) {
31
23
  this.#parentDirectory = options.parentDirectory ?? tmpdir();
32
- this.#ttlMs = options.ttlMs ?? TEMP_RESOURCE_TTL_MS;
33
-
34
- if (!Number.isFinite(this.#ttlMs) || this.#ttlMs <= 0) {
35
- throw new TypeError("Temporary resource TTL must be a positive finite number");
36
- }
37
-
38
24
  this.resolver = {
39
25
  id: "temp",
40
26
  tryResolve: (source) => Promise.resolve(this.#resolve(source)),
41
27
  };
42
28
  }
43
29
 
30
+ /** Saves text and returns a reference owned by this store. Rejects after disposal starts. */
44
31
  async save(text: string): Promise<string> {
45
- if (this.#disposed) {
32
+ if (this.#disposal !== undefined) {
46
33
  throw new Error("Temporary resource store is closed");
47
34
  }
48
35
 
36
+ const saving = this.#save(text);
37
+ this.#pendingSaves.add(saving);
38
+ try {
39
+ return await saving;
40
+ } finally {
41
+ this.#pendingSaves.delete(saving);
42
+ }
43
+ }
44
+
45
+ /** Closes the store, waits for pending saves, and removes its private directory. */
46
+ dispose(): Promise<void> {
47
+ this.#disposal ??= this.#dispose();
48
+ return this.#disposal;
49
+ }
50
+
51
+ async #save(text: string): Promise<string> {
49
52
  const directory = await this.#getDirectory();
50
53
  const id = randomUUID();
51
54
  const source = `temp:${id}`;
52
55
  const filePath = path.join(directory, `${id}.txt`);
53
56
  await writeFile(filePath, text, { encoding: "utf8", flag: "wx" });
54
- this.#entries.set(source, { activeReads: 0, filePath, lastUsedAt: Date.now() });
55
- this.#scheduleCleanup();
57
+ this.#entries.set(source, filePath);
56
58
  return source;
57
59
  }
58
60
 
59
- async dispose(): Promise<void> {
60
- if (this.#disposed) {
61
- return;
62
- }
63
-
64
- this.#disposed = true;
65
- this.#clearTimer();
61
+ async #dispose(): Promise<void> {
62
+ await Promise.allSettled(this.#pendingSaves);
66
63
  this.#entries.clear();
67
- const directoryReady = this.#directoryReady;
68
-
69
- if (directoryReady !== undefined) {
70
- await rm(await directoryReady, { recursive: true, force: true });
64
+ if (this.#directoryReady !== undefined) {
65
+ await rm(await this.#directoryReady, { recursive: true, force: true });
71
66
  }
72
67
  }
73
68
 
@@ -76,22 +71,10 @@ export class TempResourceStore {
76
71
  return { kind: "not-handled" };
77
72
  }
78
73
 
79
- const entry = this.#entries.get(source);
80
-
81
- if (entry === undefined) {
82
- return {
83
- kind: "failed",
84
- error: new Error(`Temporary resource ${source} expired or does not exist`),
85
- };
86
- }
87
-
88
- if (entry.activeReads === 0 && entry.lastUsedAt + this.#ttlMs <= Date.now()) {
89
- this.#entries.delete(source);
90
- void unlink(entry.filePath).catch(() => {});
91
- this.#scheduleCleanup();
74
+ if (this.#disposal !== undefined || !this.#entries.has(source)) {
92
75
  return {
93
76
  kind: "failed",
94
- error: new Error(`Temporary resource ${source} expired or does not exist`),
77
+ error: new Error(`Temporary resource ${source} does not exist in this runtime`),
95
78
  };
96
79
  }
97
80
 
@@ -105,22 +88,11 @@ export class TempResourceStore {
105
88
  }
106
89
 
107
90
  async #read(source: string): Promise<AgentContent> {
108
- const entry = this.#entries.get(source);
109
-
110
- if (entry === undefined) {
111
- throw new Error(`Temporary resource ${source} expired or does not exist`);
112
- }
113
-
114
- entry.activeReads += 1;
115
- this.#scheduleCleanup();
116
-
117
- try {
118
- return [{ type: "text" as const, text: await readFile(entry.filePath, "utf8") }];
119
- } finally {
120
- entry.activeReads -= 1;
121
- entry.lastUsedAt = Date.now();
122
- this.#scheduleCleanup();
91
+ const filePath = this.#entries.get(source);
92
+ if (this.#disposal !== undefined || filePath === undefined) {
93
+ throw new Error(`Temporary resource ${source} does not exist in this runtime`);
123
94
  }
95
+ return [{ type: "text", text: await readFile(filePath, "utf8") }];
124
96
  }
125
97
 
126
98
  async #getDirectory(): Promise<string> {
@@ -130,67 +102,4 @@ export class TempResourceStore {
130
102
  })();
131
103
  return this.#directoryReady;
132
104
  }
133
-
134
- #scheduleCleanup(): void {
135
- this.#clearTimer();
136
-
137
- if (this.#disposed) {
138
- return;
139
- }
140
-
141
- const now = Date.now();
142
- let nextDeadline: number | undefined;
143
-
144
- for (const entry of this.#entries.values()) {
145
- if (entry.activeReads > 0) {
146
- continue;
147
- }
148
-
149
- const deadline = entry.lastUsedAt + this.#ttlMs;
150
- nextDeadline = nextDeadline === undefined ? deadline : Math.min(nextDeadline, deadline);
151
- }
152
-
153
- if (nextDeadline === undefined) {
154
- return;
155
- }
156
-
157
- this.#timer = setTimeout(
158
- () => {
159
- this.#timer = undefined;
160
- void this.#removeExpired().catch(() => {
161
- this.#scheduleCleanup();
162
- });
163
- },
164
- Math.max(0, nextDeadline - now),
165
- );
166
- this.#timer.unref();
167
- }
168
-
169
- async #removeExpired(): Promise<void> {
170
- const now = Date.now();
171
- const expired = [...this.#entries].filter(
172
- ([, entry]) => entry.activeReads === 0 && entry.lastUsedAt + this.#ttlMs <= now,
173
- );
174
-
175
- await Promise.all(
176
- expired.map(async ([source, entry]) => {
177
- await unlink(entry.filePath).catch((error: unknown) => {
178
- if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
179
- throw error;
180
- }
181
- });
182
- this.#entries.delete(source);
183
- }),
184
- );
185
- this.#scheduleCleanup();
186
- }
187
-
188
- #clearTimer(): void {
189
- if (this.#timer === undefined) {
190
- return;
191
- }
192
-
193
- clearTimeout(this.#timer);
194
- this.#timer = undefined;
195
- }
196
105
  }
@@ -17,7 +17,6 @@ import {
17
17
  type TextTargetResolutionAttempt,
18
18
  } from "pi-agent-text";
19
19
  import { withBlockedToolResult } from "pi-agent-tool-call-interception";
20
- import { Type } from "typebox";
21
20
 
22
21
  import {
23
22
  isFragmentResolverRegistration,
@@ -53,32 +52,8 @@ import {
53
52
  } from "#src/core/tools/read/read-result.js";
54
53
  import { TempResourceStore } from "#src/core/tools/read/temp-resource-store.js";
55
54
 
56
- const readParameters = Type.Object({
57
- path: Type.Optional(
58
- Type.String({
59
- description:
60
- "What to read: a file or directory path, URL, returned temp: or SEARCH# reference, or one of the source forms listed in the description. Supply a path; an empty call cannot select a source.",
61
- }),
62
- ),
63
- offset: Type.Optional(
64
- Type.Number({
65
- description:
66
- "First line to return, numbered from 1. Omit or use 0 to start at line 1; -1 starts at the last line, -10 at the tenth line from the end. For path#anchor or a SEARCH selection, count from its containing line instead: 0 or 1 starts there, 2 starts one line later, -1 one line earlier.",
67
- }),
68
- ),
69
- limit: Type.Optional(
70
- Type.Number({
71
- description:
72
- "Maximum lines to read from the selected starting position, subject to the output budget. Omit for the default bounded read.",
73
- }),
74
- ),
75
- views: Type.Optional(
76
- Type.Array(Type.String(), {
77
- description:
78
- 'Optional additions to the returned text. Use the views listed in the tool description. Combine views when needed, for example ["anchors", "ast"] for source text with editable line references and scope boundaries. Omit for the source\'s default presentation.',
79
- }),
80
- ),
81
- });
55
+ import { readParameters } from "#src/api/read-parameters.js";
56
+ import { readRaw } from "#src/core/tools/read/raw-read.js";
82
57
 
83
58
  const fallbackReadRenderer = createReadResultRenderer({ kind: "source" });
84
59
 
@@ -121,10 +96,13 @@ export interface ReadToolContributions {
121
96
  }
122
97
 
123
98
  export interface ReadTool {
99
+ /** Shares the read runtime's temporary resource store with composed operations. */
100
+ saveTemporary(text: string): Promise<string>;
124
101
  readonly tool: ToolDefinition<typeof readParameters, ReadResultDetails>;
125
102
  execute(
126
103
  request: ReadPipelineContext["request"],
127
104
  context: ResourceResolverContext,
105
+ audience?: "agent" | "script",
128
106
  ): Promise<ReadToolResult>;
129
107
  registerContributions(pluginId: string, contributions: ReadToolContributions): void;
130
108
  dispose(): Promise<void>;
@@ -155,15 +133,17 @@ export function createReadTool(
155
133
  const toolId = "read";
156
134
 
157
135
  return {
136
+ saveTemporary: (text) => temporaryResources.save(text),
158
137
  tool: {
159
138
  name: toolId,
160
139
  label: toolId,
161
140
 
162
141
  promptSnippet:
163
- "Read files, URLs, temporary resources, search selections, and protocol sources, with optional views projected onto text content",
142
+ "Read files, original bytes with raw:, URLs, temporary resources, search selections, and protocol sources, with optional views projected onto text content",
164
143
  get description(): string {
165
144
  return [
166
- `Use read to inspect files, directories, URLs and supported sources without changing them. path selects the source; offset/limit select a text window; views add annotations. Text limit: ${READ_OUTPUT_MAX_LINES} lines or ${READ_OUTPUT_MAX_BYTES / 1024}KB. Continuation: returned offset, or returned temp: reference as path.`,
145
+ `Use read to inspect files, directories, URLs and supported sources without changing them. path selects the source; offset/limit select a text window; views add annotations. Text limit: ${READ_OUTPUT_MAX_LINES} lines or ${READ_OUTPUT_MAX_BYTES / 1024}KB. Continuation: returned offset, or returned temp: reference as path. Temporary references remain available until their owning runtime is disposed.`,
146
+ "Use raw:<local-file> to inspect original bytes without decoding or conversion, including PDFs and images. In raw: mode offset is a zero-based byte position (negative from EOF), limit is a non-negative byte count, and 0 reads no bytes. Output uses hexadecimal offsets, hex bytes and printable ASCII; dots stand for nonprintable bytes. Follow the returned byte offset to continue. Raw sources do not accept views or text anchors.",
167
147
  pluginDescription?.() ?? "",
168
148
  ]
169
149
  .filter(Boolean)
@@ -172,6 +152,7 @@ export function createReadTool(
172
152
  get promptGuidelines(): string[] {
173
153
  return [
174
154
  "Use read to examine supported sources instead of cat, sed, head or tail. Use search to locate workspace text and paths instead of grep, rg or find.",
155
+ "Use read with raw:<local-file> instead of xxd, od or hexdump to inspect original bytes. In raw: mode offset/limit count bytes, not lines; omit text views.",
175
156
  ...(pluginPromptGuidelines?.() ?? []),
176
157
  ];
177
158
  },
@@ -202,7 +183,7 @@ export function createReadTool(
202
183
  );
203
184
  },
204
185
  },
205
- execute(request, context): Promise<ReadToolResult> {
186
+ execute(request, context, audience = "agent"): Promise<ReadToolResult> {
206
187
  return executeRead(
207
188
  request,
208
189
  context,
@@ -212,6 +193,7 @@ export function createReadTool(
212
193
  temporaryResources,
213
194
  fragments,
214
195
  targetResolvers,
196
+ audience,
215
197
  );
216
198
  },
217
199
  registerContributions(pluginId, contributions): void {
@@ -309,7 +291,12 @@ async function executeRead(
309
291
  readonly priority: number;
310
292
  readonly order: number;
311
293
  }[],
294
+ audience: "agent" | "script" = "agent",
312
295
  ): Promise<ReadToolResult> {
296
+ if (request.path?.startsWith("raw:")) return readRaw(request, resolverContext, audience);
297
+ resolverContext = { ...resolverContext, audience };
298
+ const limitOutput: typeof limitReadOutput =
299
+ audience === "script" ? async (result) => result : limitReadOutput;
313
300
  const resolverSnapshot = [...resolvers].sort(
314
301
  (left, right) => left.priority - right.priority || left.order - right.order,
315
302
  );
@@ -325,7 +312,10 @@ async function executeRead(
325
312
  const targetSnapshot = [...targetResolvers].sort(
326
313
  (left, right) => left.priority - right.priority || left.order - right.order,
327
314
  );
328
- const requestedViews = new Set(request.views ?? []);
315
+ const requestedViews = new Set([
316
+ ...(request.views ?? []),
317
+ ...(audience === "script" ? viewSnapshot.map(({ registration }) => registration.view) : []),
318
+ ]);
329
319
  const knownViews = new Set([...viewSnapshot.map(({ registration }) => registration.view)]);
330
320
  const ignoredViews = [...requestedViews].filter((view) => !knownViews.has(view));
331
321
  if (request.path !== undefined && targetSnapshot.length > 0) {
@@ -338,19 +328,17 @@ async function executeRead(
338
328
  viewSnapshot,
339
329
  requestedViews,
340
330
  ignoredViews,
331
+ audience,
341
332
  );
342
333
  if (targeted !== undefined) return targeted;
343
334
  }
344
- let pipeline: ReadPipelineContext = { request: { ...request }, resolverContext };
335
+ let pipeline: ReadPipelineContext = { request: { ...request }, resolverContext, audience };
345
336
 
346
337
  if (!pipeline.request.path?.startsWith("temp:")) {
347
338
  const preRead = await runPreReadHandlers(pipeline, handlerSnapshot);
348
339
 
349
340
  if (preRead.kind === "return") {
350
- return withIgnoredViews(
351
- await limitReadOutput(preRead.result, pipeline.request),
352
- ignoredViews,
353
- );
341
+ return withIgnoredViews(await limitOutput(preRead.result, pipeline.request), ignoredViews);
354
342
  }
355
343
 
356
344
  pipeline = preRead.context;
@@ -392,7 +380,7 @@ async function executeRead(
392
380
  }
393
381
  }
394
382
  if (resolved.kind === "return") {
395
- return limitReadOutput(resolved.result, pipeline.request);
383
+ return limitOutput(resolved.result, pipeline.request);
396
384
  }
397
385
 
398
386
  pipeline = resolved.context;
@@ -411,8 +399,8 @@ async function executeRead(
411
399
 
412
400
  if (pipeline.state?.textMode === "final") {
413
401
  return withIgnoredViews(
414
- await limitReadOutput(
415
- projectReadState(pipeline.state, pipeline.request, { originLine: origin }),
402
+ await limitOutput(
403
+ projectReadState(pipeline.state, pipeline.request, { originLine: origin, audience }),
416
404
  pipeline.request,
417
405
  undefined,
418
406
  { originLine: origin },
@@ -425,7 +413,7 @@ async function executeRead(
425
413
 
426
414
  if (processed.kind === "return") {
427
415
  return withIgnoredViews(
428
- await limitReadOutput(processed.result, pipeline.request, undefined, { originLine: origin }),
416
+ await limitOutput(processed.result, pipeline.request, undefined, { originLine: origin }),
429
417
  ignoredViews,
430
418
  );
431
419
  }
@@ -433,6 +421,7 @@ async function executeRead(
433
421
  pipeline = processed.context;
434
422
  pipeline = await runTextPresenters(pipeline, viewSnapshot, requestedViews);
435
423
  const projected = projectReadState(requiredValue(pipeline.state), pipeline.request, {
424
+ audience,
436
425
  originLine: origin,
437
426
  });
438
427
  pipeline = { ...pipeline, result: projected };
@@ -444,7 +433,7 @@ async function executeRead(
444
433
  ? (text: string): Promise<string> => temporaryResources.save(text)
445
434
  : undefined;
446
435
  return withIgnoredViews(
447
- await limitReadOutput(result, pipeline.request, saveFullOutput, { originLine: origin }),
436
+ await limitOutput(result, pipeline.request, saveFullOutput, { originLine: origin }),
448
437
  ignoredViews,
449
438
  );
450
439
  }
@@ -480,7 +469,10 @@ async function resolveTextTargets(
480
469
  views: readonly RegisteredView[],
481
470
  requestedViews: ReadonlySet<string>,
482
471
  ignoredViews: readonly string[],
472
+ audience: "agent" | "script",
483
473
  ): Promise<ReadToolResult | undefined> {
474
+ const limitOutput: typeof limitReadOutput =
475
+ audience === "script" ? async (result) => result : limitReadOutput;
484
476
  for (const { resolver } of targetResolvers) {
485
477
  let rawAttempt: unknown;
486
478
  try {
@@ -522,6 +514,7 @@ async function resolveTextTargets(
522
514
  message: "Text target resolver returned no targets",
523
515
  });
524
516
  const chunks: string[] = [];
517
+ const resources: ReadToolResult[] = [];
525
518
  let firstDetails: ReadResultDetails | undefined;
526
519
  for (const target of attempt.targets) {
527
520
  const ranges = target.ranges ?? [
@@ -536,6 +529,7 @@ async function resolveTextTargets(
536
529
  limit: request.limit ?? rangeLimit,
537
530
  },
538
531
  resolverContext,
532
+ audience,
539
533
  };
540
534
  if (!target.source.startsWith("temp:")) {
541
535
  const preRead = await runPreReadHandlers(rangePipeline, handlers);
@@ -545,6 +539,7 @@ async function resolveTextTargets(
545
539
  for (const block of preRead.result.content) {
546
540
  if (block.type === "text") chunks.push(block.text);
547
541
  }
542
+ resources.push(preRead.result);
548
543
  firstDetails ??= preRead.result.details;
549
544
  continue;
550
545
  }
@@ -561,11 +556,13 @@ async function resolveTextTargets(
561
556
  for (const block of processed.result.content) {
562
557
  if (block.type === "text") chunks.push(block.text);
563
558
  }
559
+ resources.push(processed.result);
564
560
  firstDetails ??= processed.result.details;
565
561
  continue;
566
562
  }
567
563
  const presented = await runTextPresenters(processed.context, views, requestedViews);
568
564
  const projected = projectReadState(requiredValue(presented.state), presented.request, {
565
+ audience,
569
566
  originLine: range.start.lineNumber,
570
567
  });
571
568
  const postRead = await runPostReadHandlers({ ...presented, result: projected }, handlers);
@@ -576,15 +573,36 @@ async function resolveTextTargets(
576
573
  for (const block of result.content) {
577
574
  if (block.type === "text") chunks.push(block.text);
578
575
  }
576
+ resources.push(result);
579
577
  firstDetails ??= result.details;
580
578
  }
581
579
  }
582
580
  const aggregate = {
581
+ ...(audience === "script" && {
582
+ script:
583
+ resources.length === 1 && resources[0]?.script !== undefined
584
+ ? resources[0].script
585
+ : {
586
+ kind: "resources" as const,
587
+ source: request.path,
588
+ resources: resources.map(
589
+ (result) =>
590
+ result.script ?? {
591
+ kind: "native" as const,
592
+ source: result.details.source ?? request.path ?? "",
593
+ blocks: result.content,
594
+ },
595
+ ),
596
+ },
597
+ }),
583
598
  content: [{ type: "text", text: chunks.join("\n") }],
584
- details: firstDetails ?? { source: request.path },
599
+ details:
600
+ audience === "script"
601
+ ? { source: request.path, resources }
602
+ : (firstDetails ?? { source: request.path }),
585
603
  } satisfies ReadToolResult;
586
604
  return withIgnoredViews(
587
- await limitReadOutput(aggregate, { path: request.path, views: request.views }),
605
+ await limitOutput(aggregate, { path: request.path, views: request.views }),
588
606
  ignoredViews,
589
607
  );
590
608
  }
@@ -908,6 +926,8 @@ async function runTextPresenters(
908
926
  const document = state.text;
909
927
  const presentationContext: TextPresentationContext = {
910
928
  purpose: "read",
929
+ audience: context.resolverContext.audience,
930
+ requestedViews: context.request.views,
911
931
  source: state.source,
912
932
  cwd: context.resolverContext.cwd,
913
933
  resolvedBy: state.resolvedBy,
@@ -1003,7 +1023,15 @@ function mergePresentedLine(base: TextLine, current: TextLine, contribution: Tex
1003
1023
  );
1004
1024
  const metadata = mergeLineMetadata(base.metadata, current.metadata, contribution.metadata);
1005
1025
 
1006
- if (presentation === current.presentation && metadata === current.metadata) {
1026
+ const anchors =
1027
+ contribution.anchors === undefined
1028
+ ? current.anchors
1029
+ : [...new Set([...(current.anchors ?? []), ...contribution.anchors])];
1030
+ if (
1031
+ presentation === current.presentation &&
1032
+ metadata === current.metadata &&
1033
+ anchors === current.anchors
1034
+ ) {
1007
1035
  return current;
1008
1036
  }
1009
1037
 
@@ -1011,6 +1039,7 @@ function mergePresentedLine(base: TextLine, current: TextLine, contribution: Tex
1011
1039
  ...current,
1012
1040
  ...(presentation !== undefined && { presentation }),
1013
1041
  ...(metadata !== undefined && { metadata }),
1042
+ ...(anchors !== undefined && { anchors }),
1014
1043
  };
1015
1044
  }
1016
1045