pi-agent-ide 0.2.2 → 0.4.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 (403) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +13 -8
  3. package/dist/chunk-3SE372WC.js +3 -0
  4. package/dist/chunk-5MSNYFDE.js +1 -0
  5. package/dist/chunk-5VSE5X5R.js +2 -0
  6. package/dist/chunk-6DZA4CLO.js +4 -0
  7. package/dist/chunk-6EYWFBNG.js +0 -0
  8. package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
  9. package/dist/chunk-7JYQMAEL.js +14 -0
  10. package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
  11. package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
  12. package/dist/{chunk-XF5PVZOS.js → chunk-B5KB2I7J.js} +1 -1
  13. package/dist/chunk-DQF5QMJ2.js +1 -0
  14. package/dist/chunk-EJ5OACQM.js +1 -0
  15. package/dist/chunk-GFW5QPQV.js +2 -0
  16. package/dist/{chunk-LQYZG62K.js → chunk-GUTQ3PWL.js} +1 -1
  17. package/dist/chunk-HGPUI7F3.js +1 -0
  18. package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
  19. package/dist/chunk-ITSNK5YG.js +7 -0
  20. package/dist/chunk-J34VKQGJ.js +1 -0
  21. package/dist/chunk-KAB3AYA2.js +1 -0
  22. package/dist/{chunk-76WHES5H.js → chunk-M5L42DWE.js} +5 -5
  23. package/dist/chunk-M5MJP7Z2.js +1 -0
  24. package/dist/chunk-NMFQGKPE.js +2 -0
  25. package/dist/chunk-NTYXZ3EL.js +3 -0
  26. package/dist/{chunk-P6T3Q7LB.js → chunk-QDST6VIU.js} +1 -1
  27. package/dist/chunk-ROXXK6TW.js +0 -0
  28. package/dist/{chunk-WNMGUALD.js → chunk-TI5GMJ7Q.js} +1 -1
  29. package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
  30. package/dist/chunk-XSTHESNR.js +25 -0
  31. package/dist/{chunk-THSCUT2L.js → chunk-Y7ZMR4LT.js} +1 -1
  32. package/dist/chunk-YHADTHQM.js +1 -0
  33. package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
  34. package/dist/{chunk-ZXN3TWWW.js → chunk-ZM4L5AGN.js} +1 -1
  35. package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
  36. package/dist/entry-0.js +1 -1
  37. package/dist/entry-1.js +1 -1
  38. package/dist/entry-10.js +1 -1
  39. package/dist/entry-12.js +1 -1
  40. package/dist/entry-13.js +1 -1
  41. package/dist/entry-14.js +1 -1
  42. package/dist/entry-2.js +1 -1
  43. package/dist/entry-21.js +1 -1
  44. package/dist/entry-24.js +1 -1
  45. package/dist/entry-25.js +1 -1
  46. package/dist/entry-26.js +10 -5
  47. package/dist/entry-28.js +1 -1
  48. package/dist/entry-29.js +1 -1
  49. package/dist/entry-31.js +3 -3
  50. package/dist/entry-32.js +6 -5
  51. package/dist/entry-36.js +1 -1
  52. package/dist/entry-37.js +1 -1
  53. package/dist/entry-38.js +1 -1
  54. package/dist/entry-39.js +1 -1
  55. package/dist/entry-4.js +1 -1
  56. package/dist/entry-40.js +12 -8
  57. package/dist/entry-42.js +1 -1
  58. package/dist/entry-43.js +1 -1
  59. package/dist/entry-44.js +1 -1
  60. package/dist/entry-45.js +4 -4
  61. package/dist/entry-46.js +10 -10
  62. package/dist/entry-47.js +1 -1
  63. package/dist/entry-48.js +1 -1
  64. package/dist/entry-49.js +1 -1
  65. package/dist/entry-50.js +1 -1
  66. package/dist/entry-51.js +1 -1
  67. package/dist/entry-52.js +1 -1
  68. package/dist/entry-53.js +1 -1
  69. package/dist/entry-54.js +1 -0
  70. package/dist/entry-55.js +0 -1
  71. package/dist/entry-56.js +1 -0
  72. package/dist/entry-57.js +0 -1
  73. package/dist/entry-58.js +1 -1
  74. package/dist/entry-59.js +1 -1
  75. package/dist/entry-60.js +1 -1
  76. package/dist/entry-61.js +1 -1
  77. package/dist/entry-62.js +1 -1
  78. package/dist/entry-63.js +1 -0
  79. package/dist/entry-64.js +0 -1
  80. package/dist/entry-65.js +1 -0
  81. package/dist/entry-66.js +0 -1
  82. package/dist/entry-67.js +1 -1
  83. package/dist/entry-68.js +1 -1
  84. package/dist/entry-69.js +1 -59
  85. package/dist/entry-70.js +123 -4
  86. package/dist/entry-71.js +30 -1
  87. package/dist/entry-72.js +2 -29
  88. package/dist/entry-73.js +1 -2
  89. package/dist/entry-74.js +1 -1
  90. package/dist/entry-75.js +1 -1
  91. package/dist/entry-76.js +3 -1
  92. package/dist/entry-77.js +1 -3
  93. package/dist/entry-78.js +1 -1
  94. package/dist/entry-79.js +1 -1
  95. package/dist/pi-agent-ide.js +3 -2
  96. package/docs/configuration.md +32 -11
  97. package/docs/tools.md +17 -0
  98. package/node_modules/pi-agent-doctor/package.json +1 -1
  99. package/node_modules/pi-agent-filesystem/package.json +6 -6
  100. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  101. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  102. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  103. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  104. package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -3
  105. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  106. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  107. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  108. package/node_modules/pi-agent-ide-changes/index.ts +21 -5
  109. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  110. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  111. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  112. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  113. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +26 -8
  114. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
  115. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  116. package/node_modules/pi-agent-ide-lint/index.ts +46 -17
  117. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  118. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
  119. package/node_modules/pi-agent-ide-lsp/index.ts +126 -8
  120. package/node_modules/pi-agent-ide-lsp/package.json +9 -8
  121. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  122. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  123. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  124. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  125. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  126. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  127. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  128. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  129. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  130. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  131. package/node_modules/pi-agent-image/package.json +2 -2
  132. package/node_modules/pi-agent-invariant/package.json +1 -1
  133. package/node_modules/pi-agent-pdf/package.json +2 -2
  134. package/node_modules/pi-agent-read/package.json +6 -6
  135. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  136. package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
  137. package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
  138. package/node_modules/pi-agent-read/src/core/read-core.ts +26 -2
  139. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  140. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  141. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
  142. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  143. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  144. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  145. package/node_modules/pi-agent-resource/package.json +1 -1
  146. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  147. package/node_modules/pi-agent-resource/src/resource.ts +2 -0
  148. package/node_modules/pi-agent-search/package.json +3 -3
  149. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  150. package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
  151. package/node_modules/pi-agent-search/src/api/search.ts +55 -1
  152. package/node_modules/pi-agent-search/src/core/extension.ts +2 -23
  153. package/node_modules/pi-agent-search/src/core/search-core.ts +28 -3
  154. package/node_modules/pi-agent-search-text/index.ts +44 -4
  155. package/node_modules/pi-agent-search-text/package.json +6 -6
  156. package/node_modules/pi-agent-search-text/src/search-session.ts +65 -25
  157. package/node_modules/pi-agent-text/package.json +2 -2
  158. package/node_modules/pi-agent-text/src/text-document.ts +5 -0
  159. package/node_modules/pi-agent-text/src/text-target.ts +4 -0
  160. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  161. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  162. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  163. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  164. package/node_modules/pi-agent-text-editor/index.ts +1 -3
  165. package/node_modules/pi-agent-text-editor/package.json +34 -24
  166. package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
  167. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  168. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  169. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  170. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  171. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  172. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  173. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  174. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  175. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  176. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  177. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  178. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  179. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  180. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  181. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  182. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  183. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  184. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  185. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  186. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  187. package/node_modules/pi-agent-text-editor/src/core/extension.ts +6 -0
  188. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  189. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  190. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  191. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  192. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  193. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  194. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  195. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  196. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
  197. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
  198. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  199. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  201. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  202. package/node_modules/pi-agent-text-editor-renderer/index.ts +88 -1
  203. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  204. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  205. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
  206. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  207. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  208. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  209. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
  210. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  211. package/node_modules/pi-agent-web/package.json +7 -7
  212. package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
  213. package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
  214. package/node_modules/pi-agent-web-html/package.json +3 -3
  215. package/node_modules/pi-agent-web-image/package.json +4 -4
  216. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  217. package/node_modules/pi-agent-web-text/package.json +4 -4
  218. package/package.json +41 -38
  219. package/src/api/plugin-protocol.ts +10 -2
  220. package/src/api/tool-config.ts +73 -2
  221. package/src/code-view/diagnostic-view.ts +22 -3
  222. package/src/composite/builtin-extensions.ts +10 -15
  223. package/src/composite/extensions-config.ts +59 -0
  224. package/src/composite/feature-flags.ts +32 -0
  225. package/src/composite/module-labels.ts +59 -0
  226. package/src/composite/module-settings-store.ts +60 -0
  227. package/src/composite/module-settings.ts +162 -0
  228. package/src/composite/preferences.ts +26 -0
  229. package/src/composite/selection.ts +4 -4
  230. package/src/composite/settings-panel.ts +103 -0
  231. package/src/core/diagnostic-delivery.ts +29 -0
  232. package/src/core/diagnostic-entry.ts +51 -3
  233. package/src/core/diagnostic-store.ts +56 -5
  234. package/src/core/extension.ts +34 -33
  235. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  236. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  237. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  238. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  239. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
  247. package/src/extensions/pi-agent-read/package.json +6 -6
  248. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  249. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
  250. package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
  251. package/src/extensions/pi-agent-read/src/core/read-core.ts +26 -2
  252. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  253. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  254. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
  255. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  256. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  257. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  258. package/src/extensions/pi-agent-search/package.json +3 -3
  259. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +44 -4
  260. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  261. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +65 -25
  262. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  263. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
  264. package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
  265. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -23
  266. package/src/extensions/pi-agent-search/src/core/search-core.ts +28 -3
  267. package/src/extensions/pi-agent-text-editor/index.ts +1 -3
  268. package/src/extensions/pi-agent-text-editor/package.json +34 -24
  269. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  270. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  271. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  272. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  273. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +88 -1
  274. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  275. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  276. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
  277. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  278. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  279. package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
  280. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
  281. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  282. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  283. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  284. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  285. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  286. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  287. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  288. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  289. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  290. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  291. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  292. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  293. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  294. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  295. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  296. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  297. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  298. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  299. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  300. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  301. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +6 -0
  302. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  303. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  304. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  305. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  306. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  307. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  308. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  309. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  310. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
  311. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
  312. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  313. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  314. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  315. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  316. package/src/pi-agent-ide.ts +43 -8
  317. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  318. package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -3
  319. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  320. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  321. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  322. package/src/plugins/pi-agent-ide-changes/index.ts +21 -5
  323. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  324. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  325. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  326. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -11
  327. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  328. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +26 -8
  329. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
  330. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  331. package/src/plugins/pi-agent-ide-lint/index.ts +46 -17
  332. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  333. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
  334. package/src/plugins/pi-agent-ide-lsp/index.ts +126 -8
  335. package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
  336. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  337. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  338. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  339. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  340. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  341. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  342. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  343. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  344. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  345. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  346. package/src/plugins/pi-agent-ide-terminal/index.ts +34 -0
  347. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +238 -0
  348. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +461 -0
  349. package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
  350. package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
  351. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +529 -0
  352. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
  353. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +157 -0
  354. package/src/plugins/pi-agent-ide-terminal/src/types.ts +66 -0
  355. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +336 -0
  356. package/src/post-edit/gate.ts +15 -2
  357. package/dist/chunk-4U6KGABH.js +0 -1
  358. package/dist/chunk-6ACQQBUY.js +0 -7
  359. package/dist/chunk-GFWDXTOB.js +0 -4
  360. package/dist/chunk-JASLOB2X.js +0 -1
  361. package/dist/chunk-JJVXUL5U.js +0 -2
  362. package/dist/chunk-KCEOTU5Z.js +0 -3
  363. package/dist/chunk-KVGQG43U.js +0 -1
  364. package/dist/chunk-QJFRAMK7.js +0 -2
  365. package/dist/chunk-RAZOACDD.js +0 -2
  366. package/dist/chunk-RIGRP3FD.js +0 -1
  367. package/dist/chunk-VCCMVQXU.js +0 -1
  368. package/dist/chunk-X6MPU7UO.js +0 -3
  369. package/dist/chunk-YPHXLAQF.js +0 -1
  370. package/dist/entry-80.js +0 -1
  371. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  372. package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
  373. package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
  374. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  375. package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
  376. package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
  377. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  378. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
  379. package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
  380. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
  381. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
  382. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
  383. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
  384. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
  385. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  386. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
  387. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
  388. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  389. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  390. /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
  391. /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
  392. /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  393. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
  394. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
  395. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
  396. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  397. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  398. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  399. /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
  400. /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
  401. /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
  402. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  403. /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
@@ -0,0 +1,461 @@
1
+ import {
2
+ READ_API_VERSION,
3
+ READ_PROTOCOL,
4
+ type ReadPlugin,
5
+ } from "pi-agent-read/api/plugin-protocol";
6
+ import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
7
+ import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
8
+ import {
9
+ TEXT_EDITOR_API_VERSION,
10
+ TEXT_EDITOR_PROTOCOL,
11
+ type TextEditorPlugin,
12
+ } from "pi-agent-text-editor/api/plugin-protocol";
13
+ import type { AgentContent, ResourceResolver } from "pi-agent-resource";
14
+
15
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
16
+
17
+ import { renderTerminalScreen } from "#src/plugins/pi-agent-ide-terminal/src/screen-image.js";
18
+ import {
19
+ renderTerminalAction,
20
+ renderTerminalActionResult,
21
+ renderTerminalResult,
22
+ } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
23
+ import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
24
+ import type { TerminalSessionSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
25
+
26
+ const WRITE_PREFIX = "\u0000pi-terminal-write\u0000";
27
+ const KEYS_PREFIX = "\u0000pi-terminal-keys\u0000";
28
+
29
+ type TerminalAction = "write" | "insert" | "delete";
30
+ interface TerminalActionDetails {
31
+ readonly source: string;
32
+ readonly action: TerminalAction;
33
+ readonly input: string;
34
+ readonly snapshot: Partial<TerminalSessionSnapshot>;
35
+ readonly changedLines: readonly string[];
36
+ readonly status?: string;
37
+ readonly deleted?: boolean;
38
+ }
39
+
40
+ /** Connect shell sessions to the shared read, write, and insert resource interfaces. */
41
+ export async function registerTerminalResources(
42
+ pi: ExtensionAPI,
43
+ manager: TerminalSessionManager,
44
+ ): Promise<void> {
45
+ const pendingOutputEnd = new Map<string, number>();
46
+ const pendingScreen = new Map<string, readonly string[]>();
47
+ const readPlugin = {
48
+ protocol: READ_PROTOCOL,
49
+ apiVersion: READ_API_VERSION,
50
+ id: "terminal",
51
+ setup(api) {
52
+ api.addResolver({
53
+ resolver: createReadResolver(manager),
54
+ preserveTruncatedOutput: true,
55
+ renderResult(result, options, theme) {
56
+ const details = result.details as { source?: string };
57
+ const session = details.source === undefined ? undefined : manager.get(details.source);
58
+ const snapshot = session === undefined ? {} : manager.snapshot(session);
59
+ return renderTerminalResult(
60
+ session === undefined
61
+ ? snapshot
62
+ : { ...snapshot, output: manager.screenTail(session).join("\n") },
63
+ options.expanded,
64
+ theme,
65
+ "read terminal",
66
+ );
67
+ },
68
+ });
69
+ api.addHandler({
70
+ stage: "pre-read",
71
+ async handler(context) {
72
+ const source = context.request.path;
73
+ if (
74
+ source === undefined ||
75
+ !isShellSource(source) ||
76
+ context.request.views?.includes("image") !== true
77
+ ) {
78
+ return { kind: "continue", context };
79
+ }
80
+ const session = manager.get(source);
81
+ if (session === undefined) {
82
+ return {
83
+ kind: "return",
84
+ result: failure(source, `Unknown terminal session ${source}`),
85
+ };
86
+ }
87
+ try {
88
+ const data = await renderTerminalScreen(manager, source);
89
+ return {
90
+ kind: "return",
91
+ result: {
92
+ content: [{ type: "image", data, mimeType: "image/png" }],
93
+ details: { source: session.source, resolvedBy: "terminal" },
94
+ },
95
+ };
96
+ } catch (error) {
97
+ return {
98
+ kind: "return",
99
+ result: failure(source, error instanceof Error ? error.message : String(error)),
100
+ };
101
+ }
102
+ },
103
+ });
104
+ api.describe(
105
+ 'shell:<session> — terminal session status and bounded output. Use views: ["image"] to read the current virtual terminal screen as a PNG.',
106
+ );
107
+ api.addPromptGuideline(
108
+ "Use read with a returned shell:<session> source to inspect terminal status and output. Add the image view when cursor movement, ANSI layout, or a full-screen terminal interface matters.",
109
+ );
110
+ },
111
+ } satisfies ReadPlugin;
112
+
113
+ const editorPlugin = {
114
+ protocol: TEXT_EDITOR_PROTOCOL,
115
+ apiVersion: TEXT_EDITOR_API_VERSION,
116
+ id: "terminal",
117
+ setup(api) {
118
+ api.addResolver({ resolver: createInputResolver(manager) });
119
+ api.tool("write").addHandler({
120
+ stage: "text-pre-edit",
121
+ handler: async (state) => {
122
+ rememberOutputEnd(state.input, manager, pendingOutputEnd);
123
+ await rememberScreen(state.input, manager, pendingScreen);
124
+ return transformWriteInput(state, WRITE_PREFIX);
125
+ },
126
+ });
127
+ api.tool("insert").addHandler({
128
+ stage: "text-pre-edit",
129
+ handler: async (state) => {
130
+ await rememberScreen(state.input, manager, pendingScreen);
131
+ rememberOutputEnd(state.input, manager, pendingOutputEnd);
132
+ return transformInsertInput(state);
133
+ },
134
+ });
135
+ for (const tool of ["write", "insert", "delete"] as const) {
136
+ api.addToolRenderer({
137
+ tool,
138
+ matches: (value, phase) => isTerminalRenderValue(value, phase),
139
+ renderCall(arguments_, theme, context) {
140
+ const input = arguments_ as Record<string, unknown>;
141
+ const session = typeof input.path === "string" ? manager.get(input.path) : undefined;
142
+ const state = context.state as { snapshot?: TerminalSessionSnapshot };
143
+ if (session !== undefined) state.snapshot = manager.snapshot(session);
144
+ return renderTerminalAction(
145
+ state.snapshot ?? {},
146
+ tool,
147
+ terminalInputLabel(tool, input),
148
+ [],
149
+ theme,
150
+ );
151
+ },
152
+ renderResult(result, _options, theme) {
153
+ const details = terminalActionDetails(result.details);
154
+ return renderTerminalActionResult(details.action, details.changedLines, theme);
155
+ },
156
+ });
157
+ }
158
+ api.describe(
159
+ "For shell:<session> resources, write sends exact terminal input, insert sends named keys at end, and delete terminates and removes the session. replace is unsupported.",
160
+ );
161
+ api
162
+ .tool("write")
163
+ .describe(
164
+ "When path is shell:<session>, send content exactly as terminal input without adding Enter.",
165
+ );
166
+ api
167
+ .tool("insert")
168
+ .describe(
169
+ "When path is shell:<session>, omit anchor or use end, keep before false, and put whitespace- or comma-separated named keys and chords such as Enter, Ctrl+C, Ctrl+Left, Ctrl+Shift+Left, Up, or Backspace in text. Use Unix caret forms such as ^C and ^U for control characters.",
170
+ );
171
+ },
172
+ } satisfies TextEditorPlugin;
173
+
174
+ await Promise.all([connectReadPlugin(pi, readPlugin), connectTextEditorPlugin(pi, editorPlugin)]);
175
+
176
+ pi.on("tool_result", async (event, context) => {
177
+ if (!isRecord(event.input)) return;
178
+ const requestedSource = event.input.path;
179
+ if (
180
+ event.toolName === "replace" &&
181
+ typeof requestedSource === "string" &&
182
+ isShellSource(requestedSource)
183
+ ) {
184
+ return {
185
+ content: [
186
+ {
187
+ type: "text",
188
+ text: `replace is unsupported for ${requestedSource}; use write for text, insert for keys, or delete to terminate and remove the session.`,
189
+ },
190
+ ],
191
+ details: event.details,
192
+ isError: true,
193
+ };
194
+ }
195
+ if (
196
+ event.toolName === "delete" &&
197
+ typeof requestedSource === "string" &&
198
+ isShellSource(requestedSource)
199
+ ) {
200
+ const session = manager.get(requestedSource);
201
+ if (session === undefined) return;
202
+ const snapshot = manager.snapshot(session);
203
+ return manager.delete(requestedSource).then(
204
+ () => ({
205
+ content: [
206
+ { type: "text" as const, text: `Deleted terminal session ${requestedSource}.` },
207
+ ],
208
+ details: {
209
+ source: requestedSource,
210
+ deleted: true,
211
+ snapshot,
212
+ action: "delete" as const,
213
+ input: "session",
214
+ changedLines: [],
215
+ } satisfies TerminalActionDetails,
216
+ isError: false,
217
+ }),
218
+ (error: unknown) => ({
219
+ content: [
220
+ { type: "text" as const, text: error instanceof Error ? error.message : String(error) },
221
+ ],
222
+ details: { source: requestedSource, deleted: false },
223
+ isError: true,
224
+ }),
225
+ );
226
+ }
227
+ if (event.toolName !== "write" && event.toolName !== "insert") return;
228
+ if (event.isError) return;
229
+ const source = event.input.path;
230
+ if (typeof source !== "string" || !isShellSource(source)) return;
231
+ const session = manager.get(source);
232
+ if (session === undefined) return;
233
+ const beforeScreen = pendingScreen.get(source) ?? manager.screenRows(session);
234
+ pendingScreen.delete(source);
235
+ const previousEnd = pendingOutputEnd.get(source) ?? session.outputStart + session.output.length;
236
+ pendingOutputEnd.delete(source);
237
+ await manager.waitForOutputAfter(session, previousEnd);
238
+ const snapshot = manager.snapshot(session);
239
+ const action = event.toolName;
240
+ const input = terminalInputLabel(action, event.input);
241
+ const region = manager.screenChangeRegion(session, beforeScreen, 6);
242
+ const content: Array<
243
+ | { readonly type: "text"; readonly text: string }
244
+ | { readonly type: "image"; readonly data: string; readonly mimeType: "image/png" }
245
+ > = [{ type: "text", text: `Sent ${input} to ${session.source}.` }];
246
+ if (context.model?.input.includes("image") === true) {
247
+ content.push({
248
+ type: "image",
249
+ data: await renderTerminalScreen(manager, source, {
250
+ start: region.startRow,
251
+ count: region.lines.length,
252
+ }),
253
+ mimeType: "image/png",
254
+ });
255
+ }
256
+ return {
257
+ content,
258
+ details: {
259
+ source: session.source,
260
+ action,
261
+ status: session.status,
262
+ snapshot,
263
+ input,
264
+ changedLines: region.lines,
265
+ } satisfies TerminalActionDetails,
266
+ isError: event.isError,
267
+ };
268
+ });
269
+ }
270
+
271
+ function createReadResolver(manager: TerminalSessionManager): ResourceResolver {
272
+ return {
273
+ id: "terminal",
274
+ async tryResolve(source) {
275
+ if (!isShellSource(source)) return { kind: "not-handled" };
276
+ const session = manager.get(source);
277
+ if (session === undefined)
278
+ return { kind: "failed", error: new Error(`Unknown terminal session ${source}`) };
279
+ return {
280
+ kind: "resolved",
281
+ resource: {
282
+ source: session.source,
283
+ async read() {
284
+ const snapshot = manager.snapshot(session);
285
+ return [{ type: "text", text: formatSnapshot(snapshot) }];
286
+ },
287
+ },
288
+ };
289
+ },
290
+ };
291
+ }
292
+
293
+ function createInputResolver(manager: TerminalSessionManager): ResourceResolver {
294
+ return {
295
+ id: "terminal-input",
296
+ async tryResolve(source) {
297
+ if (!isShellSource(source)) return { kind: "not-handled" };
298
+ const session = manager.get(source);
299
+ if (session === undefined)
300
+ return { kind: "failed", error: new Error(`Unknown terminal session ${source}`) };
301
+ return {
302
+ kind: "resolved",
303
+ resource: {
304
+ source: session.source,
305
+ skipPostEdit: true,
306
+ async read() {
307
+ return [{ type: "text", text: "terminal input" }];
308
+ },
309
+ async write(content) {
310
+ const text = singleText(content);
311
+ const writeIndex = text.indexOf(WRITE_PREFIX);
312
+ const keysIndex = text.indexOf(KEYS_PREFIX);
313
+ if (writeIndex >= 0) {
314
+ manager.write(session.source, text.slice(writeIndex + WRITE_PREFIX.length));
315
+ return;
316
+ }
317
+ if (keysIndex >= 0) {
318
+ manager.sendKeys(session.source, text.slice(keysIndex + KEYS_PREFIX.length).trim());
319
+ return;
320
+ }
321
+ throw new Error(`Unsupported text operation for ${session.source}`);
322
+ },
323
+ },
324
+ };
325
+ },
326
+ };
327
+ }
328
+
329
+ function transformWriteInput<State extends { readonly input: unknown }>(
330
+ state: State,
331
+ prefix: string,
332
+ ): State {
333
+ if (!isRecord(state.input) || !isShellSourceValue(state.input.path)) return state;
334
+ return {
335
+ ...state,
336
+ input: {
337
+ ...state.input,
338
+ content: `${prefix}${typeof state.input.content === "string" ? state.input.content : ""}`,
339
+ },
340
+ };
341
+ }
342
+
343
+ function transformInsertInput<State extends { readonly input: unknown }>(state: State): State {
344
+ if (!isRecord(state.input) || !isShellSourceValue(state.input.path)) return state;
345
+ if (state.input.before === true)
346
+ throw new Error("Shell keys can only be inserted after the active input position");
347
+ return {
348
+ ...state,
349
+ input: {
350
+ ...state.input,
351
+ anchor: "end",
352
+ before: false,
353
+ text: `${KEYS_PREFIX}${typeof state.input.text === "string" ? state.input.text : ""}`,
354
+ },
355
+ };
356
+ }
357
+
358
+ function formatSnapshot(snapshot: ReturnType<TerminalSessionManager["snapshot"]>): string {
359
+ const metadata = [
360
+ `session: ${snapshot.source}`,
361
+ `status: ${snapshot.status}`,
362
+ `shell: ${snapshot.shell}`,
363
+ `cwd: ${snapshot.cwd}`,
364
+ `elapsedMs: ${snapshot.elapsedMs}`,
365
+ snapshot.exitCode === undefined ? undefined : `exitCode: ${snapshot.exitCode}`,
366
+ snapshot.signal === undefined ? undefined : `signal: ${snapshot.signal}`,
367
+ `outputRange: ${snapshot.outputStart}-${snapshot.outputEnd}`,
368
+ `truncated: ${String(snapshot.truncated)}`,
369
+ ].filter((line): line is string => line !== undefined);
370
+ return `${metadata.join("\n")}\n\n${snapshot.output}`;
371
+ }
372
+
373
+ function singleText(content: AgentContent): string {
374
+ if (content.length !== 1 || content[0].type !== "text") {
375
+ throw new Error("Terminal input must contain one text block");
376
+ }
377
+ return content[0].text;
378
+ }
379
+
380
+ function failure(source: string, message: string) {
381
+ return {
382
+ content: [{ type: "text" as const, text: message }],
383
+ details: {
384
+ source,
385
+ failure: { code: "READ_FAILED" as const, source, resolverId: "terminal", message },
386
+ },
387
+ isError: true,
388
+ };
389
+ }
390
+
391
+ function isShellSource(value: string): boolean {
392
+ return /^shell:[a-f\d]{12}$/u.test(value);
393
+ }
394
+
395
+ function isShellSourceValue(value: unknown): value is string {
396
+ return typeof value === "string" && isShellSource(value);
397
+ }
398
+
399
+ function terminalActionDetails(value: unknown): TerminalActionDetails {
400
+ if (!isRecord(value) || !isRecord(value.snapshot)) {
401
+ throw new TypeError("Invalid terminal action result");
402
+ }
403
+ const snapshot = value.snapshot;
404
+ const action = value.action;
405
+ if (action !== "write" && action !== "insert" && action !== "delete") {
406
+ throw new TypeError("Invalid terminal action");
407
+ }
408
+ return {
409
+ source: typeof value.source === "string" ? value.source : "shell:unknown",
410
+ action,
411
+ input: typeof value.input === "string" ? value.input : "",
412
+ changedLines: Array.isArray(value.changedLines)
413
+ ? value.changedLines.filter((line): line is string => typeof line === "string")
414
+ : [],
415
+ snapshot: {
416
+ ...(typeof snapshot.shell === "string" ? { shell: snapshot.shell } : {}),
417
+ ...(typeof snapshot.cwd === "string" ? { cwd: snapshot.cwd } : {}),
418
+ ...(typeof snapshot.command === "string" ? { command: snapshot.command } : {}),
419
+ ...(typeof snapshot.background === "boolean" ? { background: snapshot.background } : {}),
420
+ ...(typeof snapshot.status === "string"
421
+ ? { status: snapshot.status as TerminalSessionSnapshot["status"] }
422
+ : {}),
423
+ },
424
+ };
425
+ }
426
+
427
+ async function rememberScreen(
428
+ input: unknown,
429
+ manager: TerminalSessionManager,
430
+ pending: Map<string, readonly string[]>,
431
+ ): Promise<void> {
432
+ if (!isRecord(input) || typeof input.path !== "string" || !isShellSource(input.path)) return;
433
+ const session = manager.get(input.path);
434
+ if (session !== undefined) await session.screenReady;
435
+ if (session !== undefined) pending.set(input.path, manager.screenRows(session));
436
+ }
437
+ function rememberOutputEnd(
438
+ input: unknown,
439
+ manager: TerminalSessionManager,
440
+ pending: Map<string, number>,
441
+ ): void {
442
+ if (!isRecord(input) || typeof input.path !== "string" || !isShellSource(input.path)) return;
443
+ const session = manager.get(input.path);
444
+ if (session !== undefined) pending.set(input.path, session.outputStart + session.output.length);
445
+ }
446
+ function terminalInputLabel(tool: TerminalAction, input: Record<string, unknown>): string {
447
+ if (tool === "delete") return "session";
448
+ const value = tool === "write" ? input.content : input.text;
449
+ const label = typeof value === "string" ? value : "";
450
+ return tool === "write" ? `text ${JSON.stringify(label)}` : `keys ${label}`;
451
+ }
452
+
453
+ function isTerminalRenderValue(value: unknown, phase: "call" | "result"): boolean {
454
+ if (!isRecord(value)) return false;
455
+ if (phase === "call") return typeof value.path === "string" && isShellSource(value.path);
456
+ const details = value.details;
457
+ return isRecord(details) && typeof details.source === "string" && isShellSource(details.source);
458
+ }
459
+ function isRecord(value: unknown): value is Record<string, unknown> {
460
+ return typeof value === "object" && value !== null;
461
+ }
@@ -0,0 +1,127 @@
1
+ import type { SKRSContext2D } from "@napi-rs/canvas";
2
+ import type { IBufferCell } from "@xterm/headless";
3
+
4
+ import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
5
+
6
+ const CELL_WIDTH = 9;
7
+ const CELL_HEIGHT = 18;
8
+ const FONT_SIZE = 14;
9
+ const PADDING = 12;
10
+ const DEFAULT_FOREGROUND = "#d8dee9";
11
+ const DEFAULT_BACKGROUND = "#111418";
12
+ const ANSI_16 = [
13
+ "#000000",
14
+ "#cd0000",
15
+ "#00cd00",
16
+ "#cdcd00",
17
+ "#0000ee",
18
+ "#cd00cd",
19
+ "#00cdcd",
20
+ "#e5e5e5",
21
+ "#7f7f7f",
22
+ "#ff0000",
23
+ "#00ff00",
24
+ "#ffff00",
25
+ "#5c5cff",
26
+ "#ff00ff",
27
+ "#00ffff",
28
+ "#ffffff",
29
+ ] as const;
30
+
31
+ /** Render the current ANSI-aware virtual terminal screen to a PNG for multimodal agent reads. */
32
+ export async function renderTerminalScreen(
33
+ manager: TerminalSessionManager,
34
+ source: string,
35
+ rows?: { readonly start: number; readonly count: number },
36
+ ): Promise<string> {
37
+ const session = manager.get(source);
38
+ if (session === undefined) throw new Error(`Unknown terminal session ${source}`);
39
+ await session.screenReady;
40
+ const { createCanvas } = await import("@napi-rs/canvas");
41
+ const startRow = Math.max(0, Math.min(session.rows - 1, rows?.start ?? 0));
42
+ const rowCount = Math.max(1, Math.min(session.rows - startRow, rows?.count ?? session.rows));
43
+ const canvas = createCanvas(
44
+ session.cols * CELL_WIDTH + PADDING * 2,
45
+ rowCount * CELL_HEIGHT + PADDING * 2,
46
+ );
47
+ const context = canvas.getContext("2d");
48
+ context.fillStyle = DEFAULT_BACKGROUND;
49
+ context.fillRect(0, 0, canvas.width, canvas.height);
50
+ context.textBaseline = "top";
51
+
52
+ const buffer = session.screen.buffer.active;
53
+ const firstRow = Math.max(0, buffer.baseY);
54
+ for (let row = 0; row < rowCount; row += 1) {
55
+ const line = buffer.getLine(firstRow + startRow + row);
56
+ if (line === undefined) continue;
57
+ for (let column = 0; column < session.cols; column += 1) {
58
+ const cell = line.getCell(column);
59
+ if (cell === undefined || cell.getWidth() === 0) continue;
60
+ drawCell(context, cell, column, row);
61
+ }
62
+ }
63
+
64
+ if (
65
+ session.status === "running" &&
66
+ buffer.cursorY >= startRow &&
67
+ buffer.cursorY < startRow + rowCount
68
+ ) {
69
+ context.fillStyle = "rgba(216, 222, 233, 0.75)";
70
+ context.fillRect(
71
+ PADDING + buffer.cursorX * CELL_WIDTH,
72
+ PADDING + (buffer.cursorY - startRow) * CELL_HEIGHT + CELL_HEIGHT - 2,
73
+ CELL_WIDTH,
74
+ 2,
75
+ );
76
+ }
77
+ return canvas.toBuffer("image/png").toString("base64");
78
+ }
79
+
80
+ function drawCell(context: SKRSContext2D, cell: IBufferCell, column: number, row: number): void {
81
+ let foreground = cellColor(cell, "foreground");
82
+ let background = cellColor(cell, "background");
83
+ if (cell.isInverse()) [foreground, background] = [background, foreground];
84
+ const x = PADDING + column * CELL_WIDTH;
85
+ const y = PADDING + row * CELL_HEIGHT;
86
+ if (background !== DEFAULT_BACKGROUND) {
87
+ context.fillStyle = background;
88
+ context.fillRect(x, y, CELL_WIDTH * Math.max(1, cell.getWidth()), CELL_HEIGHT);
89
+ }
90
+ const chars = cell.getChars();
91
+ if (chars.length === 0) return;
92
+ context.font = `${cell.isBold() ? "bold " : ""}${FONT_SIZE}px monospace`;
93
+ context.fillStyle = foreground;
94
+ context.fillText(chars, x, y);
95
+ if (cell.isUnderline()) {
96
+ context.fillRect(x, y + CELL_HEIGHT - 2, CELL_WIDTH * Math.max(1, cell.getWidth()), 1);
97
+ }
98
+ }
99
+
100
+ function cellColor(cell: IBufferCell, kind: "foreground" | "background"): string {
101
+ const foreground = kind === "foreground";
102
+ const isDefault = foreground ? cell.isFgDefault() : cell.isBgDefault();
103
+ if (isDefault) return foreground ? DEFAULT_FOREGROUND : DEFAULT_BACKGROUND;
104
+ const isRgb = foreground ? cell.isFgRGB() : cell.isBgRGB();
105
+ const value = foreground ? cell.getFgColor() : cell.getBgColor();
106
+ if (isRgb) return `#${value.toString(16).padStart(6, "0")}`;
107
+ return ansiColor(value);
108
+ }
109
+
110
+ function ansiColor(index: number): string {
111
+ const basic = ANSI_16[index];
112
+ if (basic !== undefined) return basic;
113
+ if (index >= 232) {
114
+ const level = 8 + (index - 232) * 10;
115
+ return rgb(level, level, level);
116
+ }
117
+ const cube = Math.max(0, index - 16);
118
+ const red = Math.floor(cube / 36);
119
+ const green = Math.floor((cube % 36) / 6);
120
+ const blue = cube % 6;
121
+ const channel = (value: number): number => (value === 0 ? 0 : 55 + value * 40);
122
+ return rgb(channel(red), channel(green), channel(blue));
123
+ }
124
+
125
+ function rgb(red: number, green: number, blue: number): string {
126
+ return `#${[red, green, blue].map((value) => value.toString(16).padStart(2, "0")).join("")}`;
127
+ }