pi-agent-ide 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +74 -22
  3. package/assets/gallery/apply-editing.png +0 -0
  4. package/assets/gallery/debugging.png +0 -0
  5. package/assets/gallery/read-web.png +0 -0
  6. package/assets/gallery/search-replace.png +0 -0
  7. package/assets/gallery/terminal.png +0 -0
  8. package/assets/gallery/tool-editing.png +0 -0
  9. package/dist/chunk-25CZ5ZIU.js +3 -0
  10. package/dist/chunk-526E364R.js +3 -0
  11. package/dist/chunk-5PLV4HLG.js +1 -0
  12. package/dist/chunk-5QQABP47.js +14 -0
  13. package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
  14. package/dist/chunk-7ALCBKCW.js +26 -0
  15. package/dist/chunk-AWXVJ5AC.js +1 -0
  16. package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
  17. package/dist/chunk-ESPNEJHK.js +1 -0
  18. package/dist/chunk-G725MARR.js +16 -0
  19. package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
  20. package/dist/chunk-IQD6PON5.js +0 -0
  21. package/dist/chunk-IRECDTJG.js +27 -0
  22. package/dist/chunk-J4RTW44E.js +1 -0
  23. package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
  24. package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
  25. package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
  26. package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
  27. package/dist/chunk-NZYDMBM6.js +1 -0
  28. package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
  29. package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
  30. package/dist/chunk-P7XO5CIP.js +2 -0
  31. package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
  32. package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
  33. package/dist/chunk-U2JKHKLK.js +0 -0
  34. package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
  35. package/dist/entry-10.js +1 -1
  36. package/dist/entry-11.js +1 -1
  37. package/dist/entry-12.js +1 -1
  38. package/dist/entry-13.js +1 -1
  39. package/dist/entry-14.js +1 -1
  40. package/dist/entry-15.js +1 -0
  41. package/dist/entry-17.js +1 -1
  42. package/dist/entry-18.js +1 -1
  43. package/dist/entry-19.js +1 -1
  44. package/dist/entry-20.js +1 -1
  45. package/dist/entry-21.js +1 -2
  46. package/dist/entry-22.js +2 -1
  47. package/dist/entry-23.js +1 -1
  48. package/dist/entry-24.js +1 -1
  49. package/dist/entry-25.js +1 -1
  50. package/dist/entry-26.js +1 -12
  51. package/dist/entry-27.js +12 -1
  52. package/dist/entry-28.js +1 -1
  53. package/dist/entry-29.js +1 -1
  54. package/dist/entry-30.js +1 -1
  55. package/dist/entry-31.js +1 -4
  56. package/dist/entry-32.js +3 -8
  57. package/dist/entry-33.js +9 -1
  58. package/dist/entry-34.js +1 -1
  59. package/dist/entry-35.js +1 -1
  60. package/dist/entry-36.js +1 -1
  61. package/dist/entry-37.js +1 -1
  62. package/dist/entry-38.js +1 -1
  63. package/dist/entry-39.js +1 -1
  64. package/dist/entry-40.js +1 -18
  65. package/dist/entry-41.js +18 -1
  66. package/dist/entry-42.js +1 -1
  67. package/dist/entry-43.js +1 -1
  68. package/dist/entry-44.js +1 -1
  69. package/dist/entry-45.js +1 -7
  70. package/dist/entry-46.js +7 -11
  71. package/dist/entry-47.js +11 -1
  72. package/dist/entry-48.js +1 -1
  73. package/dist/entry-49.js +1 -1
  74. package/dist/entry-50.js +1 -1
  75. package/dist/entry-51.js +1 -1
  76. package/dist/entry-52.js +1 -1
  77. package/dist/entry-53.js +1 -1
  78. package/dist/entry-54.js +1 -1
  79. package/dist/entry-55.js +1 -0
  80. package/dist/entry-56.js +0 -1
  81. package/dist/entry-57.js +1 -0
  82. package/dist/entry-58.js +0 -1
  83. package/dist/entry-59.js +1 -1
  84. package/dist/entry-60.js +1 -1
  85. package/dist/entry-61.js +1 -1
  86. package/dist/entry-62.js +1 -1
  87. package/dist/entry-63.js +1 -1
  88. package/dist/entry-64.js +1 -0
  89. package/dist/entry-65.js +0 -1
  90. package/dist/entry-66.js +1 -0
  91. package/dist/entry-67.js +0 -1
  92. package/dist/entry-68.js +1 -1
  93. package/dist/entry-69.js +1 -1
  94. package/dist/entry-70.js +1 -123
  95. package/dist/entry-71.js +198 -25
  96. package/dist/entry-72.js +30 -2
  97. package/dist/entry-73.js +2 -1
  98. package/dist/entry-74.js +1 -1
  99. package/dist/entry-75.js +1 -1
  100. package/dist/entry-76.js +3 -3
  101. package/dist/entry-77.js +3 -1
  102. package/dist/entry-78.js +1 -1
  103. package/dist/entry-79.js +1 -1
  104. package/dist/entry-8.js +1 -1
  105. package/dist/entry-80.js +1 -0
  106. package/dist/entry-9.js +1 -1
  107. package/dist/pi-agent-ide.js +3 -3
  108. package/docs/configuration.md +1 -1
  109. package/docs/development.md +0 -6
  110. package/docs/user-hooks.md +68 -0
  111. package/node_modules/pi-agent-doctor/package.json +6 -6
  112. package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
  113. package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
  114. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
  115. package/node_modules/pi-agent-filesystem/package.json +7 -7
  116. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  117. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  118. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  119. package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  120. package/node_modules/pi-agent-ide-ast/package.json +32 -11
  121. package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  122. package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  123. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  124. package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  125. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  126. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  127. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  128. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  129. package/node_modules/pi-agent-ide-changes/index.ts +3 -1
  130. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  131. package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  132. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  133. package/node_modules/pi-agent-ide-formatter/package.json +9 -4
  134. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  135. package/node_modules/pi-agent-ide-lint/package.json +13 -8
  136. package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
  137. package/node_modules/pi-agent-ide-lsp/package.json +15 -10
  138. package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  139. package/node_modules/pi-agent-image/package.json +3 -3
  140. package/node_modules/pi-agent-invariant/package.json +2 -2
  141. package/node_modules/pi-agent-pdf/package.json +3 -3
  142. package/node_modules/pi-agent-read/package.json +11 -11
  143. package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
  144. package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
  145. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  146. package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
  147. package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
  148. package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
  149. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  150. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  151. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  152. package/node_modules/pi-agent-resource/package.json +2 -2
  153. package/node_modules/pi-agent-search/package.json +7 -7
  154. package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
  155. package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
  156. package/node_modules/pi-agent-search-text/index.ts +1 -1
  157. package/node_modules/pi-agent-search-text/package.json +9 -9
  158. package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
  159. package/node_modules/pi-agent-search-text/src/resolvers.ts +72 -39
  160. package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
  161. package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
  162. package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
  163. package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
  164. package/node_modules/pi-agent-search-text/src/search-session.ts +33 -4
  165. package/node_modules/pi-agent-text/package.json +3 -3
  166. package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
  167. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  168. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  169. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  170. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  171. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  172. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  173. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  174. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  175. package/node_modules/pi-agent-text-editor/package.json +25 -25
  176. package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
  177. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  178. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  179. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  180. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  181. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  182. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  183. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  184. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  185. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  186. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  187. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  188. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  189. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  190. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  191. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  192. package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
  193. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  194. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  195. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  196. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  197. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  198. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  199. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  200. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  201. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  202. package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
  203. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  204. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  205. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  206. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  207. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  208. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  209. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
  210. package/node_modules/pi-agent-web/package.json +7 -7
  211. package/node_modules/pi-agent-web/src/resolver.ts +128 -1
  212. package/node_modules/pi-agent-web-html/package.json +3 -3
  213. package/node_modules/pi-agent-web-image/package.json +4 -4
  214. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  215. package/node_modules/pi-agent-web-text/package.json +4 -4
  216. package/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
  217. package/package.json +59 -39
  218. package/src/api/hooks.ts +168 -0
  219. package/src/api/text-editor.ts +2 -0
  220. package/src/composite/builtin-extensions.ts +7 -0
  221. package/src/composite/module-labels.ts +8 -0
  222. package/src/composite/preferences.ts +3 -3
  223. package/src/core/reload-resource-store.ts +34 -0
  224. package/src/doctor/tip-provider.ts +1 -0
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  230. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
  231. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  232. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  233. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  234. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  235. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  236. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
  237. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
  238. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +128 -1
  239. package/src/extensions/pi-agent-read/package.json +11 -11
  240. package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
  241. package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
  242. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  243. package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
  244. package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
  245. package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
  246. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  247. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  248. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  249. package/src/extensions/pi-agent-search/package.json +7 -7
  250. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  251. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
  252. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
  253. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
  254. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +72 -39
  255. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
  256. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
  257. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
  258. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
  259. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +33 -4
  260. package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
  261. package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
  262. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
  263. package/src/extensions/pi-agent-text-editor/package.json +25 -25
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  268. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  269. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  270. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  271. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  272. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
  273. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  274. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  275. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  276. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  277. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
  278. package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
  279. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  280. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  281. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  282. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  283. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  284. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  285. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  286. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  287. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  288. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  289. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  290. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  291. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  292. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  293. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  294. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
  295. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  296. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  297. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  298. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  299. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  300. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  301. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  302. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  303. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  304. package/src/plugins/pi-agent-ide-ast/package.json +32 -11
  305. package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  306. package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  307. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  308. package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  309. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  310. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  311. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  312. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  313. package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
  314. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  315. package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  316. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  317. package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
  318. package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
  319. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
  320. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
  321. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
  322. package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
  323. package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
  324. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
  325. package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
  326. package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
  327. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  328. package/src/plugins/pi-agent-ide-lint/package.json +13 -8
  329. package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
  330. package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
  331. package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  332. package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
  333. package/src/plugins/pi-agent-ide-processes/src/registry.ts +83 -0
  334. package/src/plugins/pi-agent-ide-processes/src/ui.ts +260 -0
  335. package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
  336. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
  337. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +31 -0
  338. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
  339. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
  340. package/src/plugins/pi-agent-ide-terminal/src/search.ts +32 -2
  341. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
  342. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
  343. package/src/plugins/pi-agent-ide-terminal/src/types.ts +14 -1
  344. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
  345. package/dist/chunk-3SE372WC.js +0 -3
  346. package/dist/chunk-5MSNYFDE.js +0 -1
  347. package/dist/chunk-7JYQMAEL.js +0 -14
  348. package/dist/chunk-B5KB2I7J.js +0 -3
  349. package/dist/chunk-NMFQGKPE.js +0 -2
  350. package/dist/chunk-OVUYPHDE.js +0 -1
  351. package/dist/chunk-TPIHQYK2.js +0 -14
  352. package/dist/chunk-XSTHESNR.js +0 -25
  353. package/dist/entry-16.js +0 -1
  354. package/docs/evaluation.md +0 -14
  355. package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
  356. package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
  357. package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  358. package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  359. package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
  360. package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
  361. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  362. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  363. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  364. package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
  365. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
  366. package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
  367. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
  368. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
  369. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
  370. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
  371. package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
  372. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
  373. package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
  374. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  375. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  376. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  377. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
  378. package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
  379. package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  380. package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  381. /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
  382. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  383. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  384. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  385. /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  386. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  387. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
  388. /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
  389. /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
  390. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
  391. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
  392. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
  393. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
  394. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
  395. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  396. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
  397. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
  398. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  399. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  400. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  401. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  402. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  403. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  404. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  405. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  406. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  407. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  408. /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  409. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  410. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
@@ -0,0 +1,31 @@
1
+ import type { AgentIdeProcessProvider } from "#src/plugins/pi-agent-ide-processes/src/registry.js";
2
+ import {
3
+ renderActiveTerminal,
4
+ renderTerminalResult,
5
+ } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
6
+ import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
7
+
8
+ /** Expose active PTY sessions through the shared Agent IDE process registry. */
9
+ export function terminalProcessProvider(manager: TerminalSessionManager): AgentIdeProcessProvider {
10
+ return {
11
+ id: "terminal",
12
+ onDidChange: (listener) => manager.onDidChange(listener),
13
+ list: () =>
14
+ manager
15
+ .list()
16
+ .filter((session) => session.status === "running" || session.status === "stopping")
17
+ .map((snapshot) => {
18
+ return {
19
+ source: snapshot.source,
20
+ kind: "terminal",
21
+ title: snapshot.shell.toLocaleLowerCase(),
22
+ description: snapshot.command,
23
+ status: snapshot.status === "stopping" ? ("stopping" as const) : ("running" as const),
24
+ renderSummary: (theme) => renderActiveTerminal(snapshot, theme).split("\n"),
25
+ renderDetail: (theme) => renderTerminalResult(snapshot, true, theme),
26
+ sendInput: (data) => manager.write(snapshot.source, data),
27
+ stop: () => manager.delete(snapshot.source),
28
+ };
29
+ }),
30
+ };
31
+ }
@@ -1,10 +1,12 @@
1
1
  import path from "node:path";
2
2
  import { stripVTControlCharacters } from "node:util";
3
3
 
4
+ import { truncateLine } from "@earendil-works/pi-coding-agent";
4
5
  import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
5
- import { Text, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
6
+ import { Text, type Component } from "@earendil-works/pi-tui";
6
7
 
7
8
  import { COMPACT_READ_ROWS } from "#src/extensions/pi-agent-read/src/core/tools/read/read-renderer.js";
9
+ import { terminalOutputTail } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
8
10
  import type {
9
11
  ShellProfile,
10
12
  TerminalSessionSnapshot,
@@ -12,6 +14,7 @@ import type {
12
14
  } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
13
15
 
14
16
  type TerminalTheme = Pick<Theme, "fg">;
17
+ const TERMINAL_MAX_LINE_LENGTH = 500;
15
18
 
16
19
  /** Render a stable shell prompt for a run tool call. */
17
20
  export function renderRunCall(
@@ -54,18 +57,14 @@ export function renderTerminalAction(
54
57
  lines.push(...changedLines.map((line) => ` ${theme.fg("dim", line)}`));
55
58
  return new Text(lines.join("\n"), 0, 0);
56
59
  }
57
- /** Render a terminal result as a compact or expanded pseudo-terminal card. */
60
+ /** Render a bounded pseudo-terminal card; complete output stays available through its log file. */
58
61
  export function renderTerminalResult(
59
62
  snapshot: Partial<TerminalSessionSnapshot>,
60
- expanded: boolean,
63
+ _expanded: boolean,
61
64
  theme: TerminalTheme,
62
65
  action?: string,
63
66
  ): Component {
64
- const lines = terminalCardLines(
65
- snapshot,
66
- expanded ? Number.POSITIVE_INFINITY : COMPACT_READ_ROWS,
67
- theme,
68
- );
67
+ const lines = terminalCardLines(snapshot, COMPACT_READ_ROWS, theme);
69
68
  if (action !== undefined) lines.splice(1, 1, theme.fg("accent", action));
70
69
  return new Text(lines.join("\n"), 0, 0);
71
70
  }
@@ -79,7 +78,7 @@ export function renderRunResult(
79
78
  if (expanded) return renderTerminalResult(snapshot, true, theme);
80
79
  const window = outputWindow(snapshot.output ?? "", COMPACT_READ_ROWS);
81
80
  const lines = [
82
- ...(window.omitted > 0 ? [` ${theme.fg("muted", `… ${window.omitted} earlier lines`)}`] : []),
81
+ ...(window.omission === undefined ? [] : [` ${theme.fg("muted", window.omission)}`]),
83
82
  ...window.lines.map((line) => ` ${theme.fg("dim", line)}`),
84
83
  ];
85
84
  lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
@@ -117,55 +116,13 @@ export function terminalCardLines(
117
116
  `${theme.fg("accent", promptMarker(family))} ${snapshot.command ?? ""}`,
118
117
  ];
119
118
  const window = outputWindow(snapshot.output ?? "", outputLines);
120
- if (window.omitted > 0) lines.push(` ${theme.fg("muted", `… ${window.omitted} earlier lines`)}`);
119
+ if (window.omission !== undefined) lines.push(` ${theme.fg("muted", window.omission)}`);
121
120
  if (window.lines.length > 0)
122
121
  lines.push(...window.lines.map((line) => ` ${theme.fg("dim", line)}`));
123
122
  lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
124
123
  return lines;
125
124
  }
126
125
 
127
- /** Render bordered mini-cards modeled after the Herdr subagent activity widget. */
128
- export function renderTerminalWidgetLines(
129
- snapshots: readonly TerminalSessionSnapshot[],
130
- width: number,
131
- theme: TerminalTheme,
132
- ): string[] {
133
- if (snapshots.length === 0) return [];
134
- const accent = (text: string): string => theme.fg("accent", text);
135
- const lines = [borderTop("Terminals", `${snapshots.length} active`, width, accent)];
136
- for (const snapshot of snapshots) {
137
- const card = renderActiveTerminal(snapshot, theme).split("\n");
138
- for (const line of card) lines.push(borderLine(` ${line} `, width, accent));
139
- if (snapshot !== snapshots.at(-1)) lines.push(borderLine("", width, accent));
140
- }
141
- lines.push(borderBottom(width, accent));
142
- return lines;
143
- }
144
-
145
- function borderTop(
146
- title: string,
147
- info: string,
148
- width: number,
149
- accent: (text: string) => string,
150
- ): string {
151
- if (width <= 1) return accent("╭");
152
- const inner = width - 2;
153
- const left = `─ ${title} `;
154
- const right = ` ${info} ─`;
155
- const fill = "─".repeat(Math.max(0, inner - visibleWidth(left) - visibleWidth(right)));
156
- return accent(`╭${truncateToWidth(`${left}${fill}${right}`, inner).padEnd(inner, "─")}╮`);
157
- }
158
-
159
- function borderLine(line: string, width: number, accent: (text: string) => string): string {
160
- if (width <= 1) return accent("│");
161
- const inner = width - 2;
162
- const clipped = truncateToWidth(line, inner);
163
- return `${accent("│")}${clipped}${" ".repeat(Math.max(0, inner - visibleWidth(clipped)))}${accent("│")}`;
164
- }
165
-
166
- function borderBottom(width: number, accent: (text: string) => string): string {
167
- return accent(width <= 1 ? "╰" : `╰${"─".repeat(width - 2)}╯`);
168
- }
169
126
  export function outputTail(output: string, count: number): readonly string[] {
170
127
  return outputWindow(output, count).lines;
171
128
  }
@@ -173,15 +130,22 @@ export function outputTail(output: string, count: number): readonly string[] {
173
130
  function outputWindow(
174
131
  output: string,
175
132
  count: number,
176
- ): { readonly lines: readonly string[]; readonly omitted: number } {
177
- const lines = stripVTControlCharacters(output)
178
- .replaceAll("\r", "")
133
+ ): { readonly lines: readonly string[]; readonly omission?: string } {
134
+ const truncation = terminalOutputTail(stripVTControlCharacters(output).replaceAll("\r", ""));
135
+ const lines = truncation.content
179
136
  .split("\n")
180
- .map((line) => line.trimEnd());
137
+ .map((line) => truncateLine(line.trimEnd(), TERMINAL_MAX_LINE_LENGTH).text);
181
138
  if (lines.at(-1) === "") lines.pop();
182
139
  const limit = Number.isFinite(count) ? Math.max(0, count) : lines.length;
183
- const omitted = Math.max(0, lines.length - limit);
184
- return { lines: lines.slice(omitted), omitted };
140
+ const omittedLines = Math.max(0, lines.length - limit);
141
+ const budgetOmittedLines = Math.max(0, truncation.totalLines - truncation.outputLines);
142
+ const omitted = omittedLines + budgetOmittedLines;
143
+ return {
144
+ lines: lines.slice(omittedLines),
145
+ ...(truncation.truncated || omitted > 0
146
+ ? { omission: omitted > 0 ? `… ${omitted} earlier lines` : "… earlier output omitted" }
147
+ : {}),
148
+ };
185
149
  }
186
150
 
187
151
  function statusLine(
@@ -193,6 +157,8 @@ function statusLine(
193
157
  const tone: ThemeColor =
194
158
  status === "completed" ? "success" : status === "running" ? "accent" : "error";
195
159
  const parts = [`${icon} ${status}`, formatElapsed(snapshot.elapsedMs ?? 0)];
160
+ if (snapshot.waitReason !== undefined) parts.push(`background · ${snapshot.waitReason}`);
161
+ if (snapshot.completionReason !== undefined) parts.push(`reason ${snapshot.completionReason}`);
196
162
  if (snapshot.exitCode !== undefined) parts.push(`exit ${snapshot.exitCode}`);
197
163
  else if (snapshot.signal !== undefined) parts.push(`signal ${snapshot.signal}`);
198
164
  return color(tone, parts.join(" · "));
@@ -14,6 +14,7 @@ import type { AgentContent, ResourceResolver } from "pi-agent-resource";
14
14
 
15
15
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
16
16
 
17
+ import { formatAgentTerminalSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
17
18
  import { renderTerminalScreen } from "#src/plugins/pi-agent-ide-terminal/src/screen-image.js";
18
19
  import {
19
20
  renderTerminalAction,
@@ -85,6 +86,7 @@ export async function registerTerminalResources(
85
86
  };
86
87
  }
87
88
  try {
89
+ manager.markInspected(source);
88
90
  const data = await renderTerminalScreen(manager, source);
89
91
  return {
90
92
  kind: "return",
@@ -102,7 +104,7 @@ export async function registerTerminalResources(
102
104
  },
103
105
  });
104
106
  api.describe(
105
- 'shell:<session> — terminal session status and bounded output. Use views: ["image"] to read the current virtual terminal screen as a PNG.',
107
+ 'shell:<session> — terminal session status and a bounded output tail with a full-log path when truncated. Use views: ["image"] to read the current virtual terminal screen as a PNG.',
106
108
  );
107
109
  api.addPromptGuideline(
108
110
  "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.",
@@ -281,6 +283,7 @@ function createReadResolver(manager: TerminalSessionManager): ResourceResolver {
281
283
  resource: {
282
284
  source: session.source,
283
285
  async read() {
286
+ manager.markInspected(session.source);
284
287
  const snapshot = manager.snapshot(session);
285
288
  return [{ type: "text", text: formatSnapshot(snapshot) }];
286
289
  },
@@ -356,20 +359,8 @@ function transformInsertInput<State extends { readonly input: unknown }>(state:
356
359
  }
357
360
 
358
361
  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}`;
362
+ return formatAgentTerminalSnapshot(snapshot);
371
363
  }
372
-
373
364
  function singleText(content: AgentContent): string {
374
365
  if (content.length !== 1 || content[0].type !== "text") {
375
366
  throw new Error("Terminal input must contain one text block");
@@ -7,6 +7,7 @@ import {
7
7
  import type { SearchRequest, SearchSelectionMatch } from "pi-agent-search/api/search";
8
8
 
9
9
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
10
+ import type { Component } from "@earendil-works/pi-tui";
10
11
 
11
12
  import { renderTerminalAction } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
12
13
  import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
@@ -85,22 +86,51 @@ function terminalSearchResolver(manager: TerminalSessionManager) {
85
86
  },
86
87
  renderResult(
87
88
  result: { details: unknown },
88
- _options: unknown,
89
+ options: { readonly expanded?: boolean },
89
90
  theme: Parameters<typeof renderTerminalAction>[4],
90
91
  ) {
91
92
  const details = result.details;
92
93
  const payload = isRecord(details) ? parsePayload(details.payload) : parsePayload(undefined);
93
- return renderTerminalAction(
94
+ const content = renderTerminalAction(
94
95
  payload.snapshot,
95
96
  "search",
96
97
  JSON.stringify(payload.query),
97
98
  payload.matches.slice(-6).map((match) => `${match.lineNumber}: ${match.lineText}`),
98
99
  theme,
99
100
  );
101
+ return new TerminalSearchPanel(content, options.expanded === true, theme);
100
102
  },
101
103
  };
102
104
  }
103
105
 
106
+ const COMPACT_TERMINAL_SEARCH_ROWS = 12;
107
+
108
+ /** Keep terminal search readable without changing the complete agent-facing result. */
109
+ export class TerminalSearchPanel implements Component {
110
+ public constructor(
111
+ private readonly content: Component,
112
+ private readonly expanded: boolean,
113
+ private readonly theme: Parameters<typeof renderTerminalAction>[4],
114
+ ) {}
115
+
116
+ public render(width: number): string[] {
117
+ const rows = this.content.render(width);
118
+ if (this.expanded || rows.length <= COMPACT_TERMINAL_SEARCH_ROWS) return rows;
119
+ const shown = COMPACT_TERMINAL_SEARCH_ROWS - 1;
120
+ return [
121
+ ...rows.slice(0, shown),
122
+ this.theme.fg(
123
+ "muted",
124
+ `… ${String(rows.length - shown)} visual rows omitted · ctrl+o to expand`,
125
+ ),
126
+ ];
127
+ }
128
+
129
+ public invalidate(): void {
130
+ this.content.invalidate();
131
+ }
132
+ }
133
+
104
134
  export function findTerminalMatches(
105
135
  snapshot: TerminalSessionSnapshot,
106
136
  request: SearchRequest,
@@ -1,4 +1,7 @@
1
1
  import { spawn as spawnProcess } from "node:child_process";
2
+ import { closeSync, mkdirSync, openSync, rmSync, writeSync } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
2
5
  import { createRequire } from "node:module";
3
6
  import { randomUUID } from "node:crypto";
4
7
  import { stripVTControlCharacters } from "node:util";
@@ -10,6 +13,7 @@ import type {
10
13
  ShellProfile,
11
14
  TerminalSession,
12
15
  TerminalSessionSnapshot,
16
+ TerminalWaitOutcomeReason,
13
17
  } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
14
18
 
15
19
  const require = createRequire(import.meta.url);
@@ -26,6 +30,7 @@ export class TerminalSessionManager {
26
30
  readonly #sessions = new Map<string, TerminalSession>();
27
31
  readonly #changeListeners = new Set<SessionListener>();
28
32
  readonly #completionListeners = new Set<SessionListener>();
33
+ readonly #outputLogs = new Map<string, number>();
29
34
  #disposed = false;
30
35
 
31
36
  public constructor(createId: () => string = defaultSessionId) {
@@ -62,6 +67,12 @@ export class TerminalSessionManager {
62
67
  shellFamily: session.shell.family,
63
68
  background: session.background,
64
69
  status: session.status,
70
+ ...(session.waitReason === undefined ? {} : { waitReason: session.waitReason }),
71
+ ...(session.completionReason === undefined
72
+ ? {}
73
+ : { completionReason: session.completionReason }),
74
+ lastActivityAt: session.lastActivityAt,
75
+ idleMs: Math.max(0, now - session.lastActivityAt),
65
76
  startedAt: session.startedAt,
66
77
  ...(session.endedAt === undefined ? {} : { endedAt: session.endedAt }),
67
78
  elapsedMs: (session.endedAt ?? now) - session.startedAt,
@@ -72,6 +83,7 @@ export class TerminalSessionManager {
72
83
  outputStart: session.outputStart,
73
84
  outputEnd: session.outputStart + session.output.length,
74
85
  truncated: session.outputStart > 0,
86
+ fullOutputPath: session.fullOutputPath,
75
87
  cols: session.cols,
76
88
  rows: session.rows,
77
89
  };
@@ -90,6 +102,8 @@ export class TerminalSessionManager {
90
102
  if (!/^[a-f\d]{12}$/u.test(id) || this.#sessions.has(id)) {
91
103
  throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");
92
104
  }
105
+ const fullOutputPath = createOutputLog(id);
106
+ this.#outputLogs.set(id, openSync(fullOutputPath, "a", 0o600));
93
107
  const cols = options.cols ?? DEFAULT_COLS;
94
108
  const rows = options.rows ?? DEFAULT_ROWS;
95
109
  const screen = createScreen(cols, rows);
@@ -105,8 +119,10 @@ export class TerminalSessionManager {
105
119
  cwd: options.cwd,
106
120
  shell: options.shell,
107
121
  startedAt: Date.now(),
122
+ lastActivityAt: Date.now(),
108
123
  cols,
109
124
  rows,
125
+ fullOutputPath,
110
126
  screen,
111
127
  status: "running" as const,
112
128
  output: "",
@@ -146,6 +162,7 @@ export class TerminalSessionManager {
146
162
  error: errorMessage(error),
147
163
  };
148
164
  this.#sessions.set(id, session);
165
+ this.#closeOutputLog(id);
149
166
  resolveCompletion(session);
150
167
  queueMicrotask(() => this.#emitCompleted(session));
151
168
  return session;
@@ -161,6 +178,8 @@ export class TerminalSessionManager {
161
178
  if (signal !== 0) session.signal = signal;
162
179
  session.status =
163
180
  session.status === "stopping" ? "stopped" : exitCode === 0 ? "completed" : "failed";
181
+ if (exitCode === 124 || exitCode === 137) session.completionReason = "timeout";
182
+ this.#closeOutputLog(session.id);
164
183
  session.resolveCompletion(session);
165
184
  this.#emitChanged(session);
166
185
  this.#emitCompleted(session);
@@ -188,6 +207,55 @@ export class TerminalSessionManager {
188
207
  });
189
208
  }
190
209
 
210
+ /** Wait for foreground completion, preserving a live PTY when the wait must return early. */
211
+ public async waitForForeground(
212
+ sourceOrId: string,
213
+ options: {
214
+ readonly signal?: AbortSignal;
215
+ readonly timeoutMs: number;
216
+ readonly interactiveDelayMs?: number;
217
+ },
218
+ ): Promise<{ readonly session: TerminalSession; readonly reason?: TerminalWaitOutcomeReason }> {
219
+ const session = this.required(sourceOrId);
220
+ if (isTerminalStatus(session.status)) return { session };
221
+ const interactiveDelayMs = options.interactiveDelayMs ?? 3_000;
222
+
223
+ return await new Promise((resolve) => {
224
+ let settled = false;
225
+ let interactiveSince: number | undefined;
226
+ const finish = (reason?: TerminalWaitOutcomeReason): void => {
227
+ if (settled) return;
228
+ if (reason !== undefined && isTerminalStatus(session.status)) reason = undefined;
229
+ settled = true;
230
+ clearTimeout(timeout);
231
+ clearInterval(interactive);
232
+ options.signal?.removeEventListener("abort", onAbort);
233
+ if (reason !== undefined) {
234
+ session.background = true;
235
+ if (reason !== "aborted") session.waitReason = reason;
236
+ this.#emitChanged(session);
237
+ }
238
+ resolve({ session, ...(reason === undefined ? {} : { reason }) });
239
+ };
240
+ const onAbort = (): void => finish("aborted");
241
+ const timeout = setTimeout(() => finish("timeout"), options.timeoutMs);
242
+ const interactive = setInterval(
243
+ () => {
244
+ if (!looksInteractive(session)) {
245
+ interactiveSince = undefined;
246
+ return;
247
+ }
248
+ interactiveSince ??= Date.now();
249
+ if (Date.now() - interactiveSince >= interactiveDelayMs) finish("interactive");
250
+ },
251
+ Math.min(100, Math.max(10, interactiveDelayMs / 2)),
252
+ );
253
+ options.signal?.addEventListener("abort", onAbort, { once: true });
254
+ if (options.signal?.aborted === true) onAbort();
255
+ void session.completion.then(() => finish());
256
+ });
257
+ }
258
+
191
259
  /** Wait for PTY output triggered by input to settle before capturing the screen. */
192
260
  public async waitForOutputAfter(session: TerminalSession, previousEnd: number): Promise<void> {
193
261
  const deadline = Date.now() + 300;
@@ -269,6 +337,14 @@ export class TerminalSessionManager {
269
337
  }
270
338
  return lines.slice(-Math.max(0, count));
271
339
  }
340
+ /** Record that the agent inspected a live terminal session. */
341
+ public markInspected(sourceOrId: string): void {
342
+ const session = this.required(sourceOrId);
343
+ if (session.status !== "running") return;
344
+ session.lastActivityAt = Date.now();
345
+ this.#emitChanged(session);
346
+ }
347
+
272
348
  public write(sourceOrId: string, data: string): void {
273
349
  const session = this.requiredRunning(sourceOrId);
274
350
  session.process?.write(data);
@@ -299,6 +375,7 @@ export class TerminalSessionManager {
299
375
  if (!isTerminalStatus(session.status)) {
300
376
  session.status = finalStatus;
301
377
  session.endedAt = Date.now();
378
+ this.#closeOutputLog(session.id);
302
379
  session.resolveCompletion(session);
303
380
  this.#emitCompleted(session);
304
381
  }
@@ -313,6 +390,8 @@ export class TerminalSessionManager {
313
390
  session.completionDelivered = true;
314
391
  await this.stop(session.source);
315
392
  session.screen.dispose();
393
+ this.#closeOutputLog(session.id);
394
+ rmSync(session.fullOutputPath, { force: true });
316
395
  this.#sessions.delete(session.id);
317
396
  this.#emitChanged(session);
318
397
  }
@@ -341,7 +420,10 @@ export class TerminalSessionManager {
341
420
  .filter((session) => !isTerminalStatus(session.status))
342
421
  .map((session) => this.stop(session.source)),
343
422
  );
344
- for (const session of this.#sessions.values()) session.screen.dispose();
423
+ for (const session of this.#sessions.values()) {
424
+ session.screen.dispose();
425
+ this.#closeOutputLog(session.id);
426
+ }
345
427
  this.#changeListeners.clear();
346
428
  this.#completionListeners.clear();
347
429
  }
@@ -363,7 +445,10 @@ export class TerminalSessionManager {
363
445
  }
364
446
 
365
447
  #appendOutput(session: TerminalSession, data: string): void {
448
+ session.lastActivityAt = Date.now();
366
449
  const plain = stripVTControlCharacters(data);
450
+ const descriptor = this.#outputLogs.get(session.id);
451
+ if (descriptor !== undefined) writeSync(descriptor, plain);
367
452
  session.output += plain;
368
453
  if (session.output.length > MAX_OUTPUT_CHARS) {
369
454
  const removed = session.output.length - MAX_OUTPUT_CHARS;
@@ -379,6 +464,13 @@ export class TerminalSessionManager {
379
464
  this.#emitChanged(session);
380
465
  }
381
466
 
467
+ #closeOutputLog(id: string): void {
468
+ const descriptor = this.#outputLogs.get(id);
469
+ if (descriptor === undefined) return;
470
+ closeSync(descriptor);
471
+ this.#outputLogs.delete(id);
472
+ }
473
+
382
474
  #emitChanged(session: TerminalSession): void {
383
475
  for (const listener of this.#changeListeners) listener(session);
384
476
  }
@@ -388,6 +480,21 @@ export class TerminalSessionManager {
388
480
  }
389
481
  }
390
482
 
483
+ function looksInteractive(session: TerminalSession): boolean {
484
+ if (session.status !== "running") return false;
485
+ const buffer = session.screen.buffer.active;
486
+ const line =
487
+ buffer
488
+ .getLine(buffer.baseY + buffer.cursorY)
489
+ ?.translateToString(true)
490
+ .trimEnd() ?? "";
491
+ return (
492
+ /\[[^\]\n]{1,20}(?:\/[^\]\n]{1,20})+\]\s*[:?>]?\s*$/iu.test(line) ||
493
+ /(?:choose|select|enter|password|confirm|continue|proceed)[^\n]{0,60}[:?]\s*$/iu.test(line) ||
494
+ /^(?:❯|›)\s+\S/u.test(line)
495
+ );
496
+ }
497
+
391
498
  function createScreen(cols: number, rows: number): XtermTerminal {
392
499
  const { Terminal } = require("@xterm/headless") as {
393
500
  Terminal: new (options: {
@@ -527,3 +634,9 @@ function delay(milliseconds: number): Promise<void> {
527
634
  function errorMessage(error: unknown): string {
528
635
  return error instanceof Error ? error.message : String(error);
529
636
  }
637
+
638
+ function createOutputLog(id: string): string {
639
+ const directory = path.join(os.tmpdir(), `pi-agent-ide-terminal-${process.pid}`);
640
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
641
+ return path.join(directory, `${id}.log`);
642
+ }
@@ -5,6 +5,7 @@ import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
6
 
7
7
  import { COMPACT_READ_ROWS } from "#src/extensions/pi-agent-read/src/core/tools/read/read-renderer.js";
8
+ import { formatAgentTerminalSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
8
9
  import { renderRunCall, renderRunResult } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
9
10
 
10
11
  import { shellSyntaxGuidance } from "#src/plugins/pi-agent-ide-terminal/src/shell-profile.js";
@@ -26,6 +27,14 @@ const runParameters = Type.Object(
26
27
  description: "Return immediately while the terminal session continues. Defaults to false.",
27
28
  }),
28
29
  ),
30
+ timeoutSeconds: Type.Optional(
31
+ Type.Number({
32
+ minimum: 0.1,
33
+ maximum: 86_400,
34
+ description:
35
+ "Maximum foreground wait in seconds before returning the live session as background. Defaults to 60.",
36
+ }),
37
+ ),
29
38
  cwd: Type.Optional(
30
39
  Type.String({
31
40
  description: "Working directory. Relative paths resolve from the current workspace.",
@@ -46,18 +55,19 @@ export function registerTerminalTools(
46
55
  pi: ExtensionAPI,
47
56
  manager: TerminalSessionManager,
48
57
  profile: ShellProfile,
49
- ui: Pick<TerminalUi, "bind">,
58
+ ui: Pick<TerminalUi, "bind" | "notifyWaitTransition">,
50
59
  ): void {
60
+ const toolName = process.platform === "win32" ? "powershell" : "bash";
51
61
  pi.registerTool(
52
62
  defineTool<typeof runParameters, TerminalSessionSnapshot>({
53
- name: "run",
54
- label: `${profile.displayName} run`,
55
- promptSnippet: `Run ${profile.displayName} commands in synchronous or background terminal sessions`,
63
+ name: toolName,
64
+ label: profile.displayName,
65
+ promptSnippet: `Execute ${profile.displayName} commands in synchronous or background terminal sessions`,
56
66
  promptGuidelines: [
57
67
  `Write commands for ${profile.displayName}; commands are not translated between shell languages.`,
58
- "Use background for servers, watchers, long builds, and work that can finish while you continue. Use the returned shell: source with read, write, insert, and delete.",
68
+ `Use ${toolName} with background for servers, watchers, and long builds. Foreground waits become background after timeoutSeconds (60 by default), on a stable interactive prompt, or when the turn is aborted. After a session enters background, do not poll it continuously; continue other work or wait for its automatic completion notification. Keep a short task in foreground wait when it should finish soon and no independent work remains. A background session with no output for two minutes wakes an idle agent so it can be inspected. Sessions survive extension reloads and keep the same shell: source. Large output returns a bounded tail and a fullOutput file path. Use the returned shell: source with read, write, insert, and delete.`,
59
69
  ],
60
- description: `Use run to execute a command in the user's configured ${profile.displayName} shell (${profile.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting; completion is delivered automatically and wakes the agent. ${shellSyntaxGuidance(profile)}`,
70
+ description: `Use ${toolName} to execute a command in the user's configured ${profile.displayName} shell (${profile.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting. A foreground wait automatically returns the live session as background on timeout, a stable interactive prompt, or turn abort. Background completion is delivered automatically and wakes the agent, so background sessions do not need continuous polling. Keep short tasks in foreground wait when they should finish soon and no independent work remains. Sessions survive extension reloads and keep the same shell: source. Output uses the shared Read limits, keeps the tail, and links a complete log file when truncated. ${shellSyntaxGuidance(profile)}`,
61
71
  parameters: runParameters,
62
72
  async execute(_toolCallId, input, signal, onUpdate, context) {
63
73
  ui.bind(context);
@@ -76,8 +86,12 @@ export function registerTerminalTools(
76
86
  return terminalResult(manager.snapshot(session));
77
87
  }
78
88
  if (session.status === "failed") return terminalResult(manager.snapshot(session));
79
- const completed = await manager.wait(session.source, signal);
80
- return terminalResult(manager.snapshot(completed));
89
+ const outcome = await manager.waitForForeground(session.source, {
90
+ signal,
91
+ timeoutMs: (input.timeoutSeconds ?? 60) * 1_000,
92
+ });
93
+ if (outcome.reason === "aborted") ui.notifyWaitTransition(outcome.session);
94
+ return terminalResult(manager.snapshot(outcome.session));
81
95
  },
82
96
  renderCall(args, theme) {
83
97
  const command = typeof args.command === "string" ? args.command : "";
@@ -97,32 +111,12 @@ export function registerTerminalTools(
97
111
  }
98
112
 
99
113
  function terminalResult(snapshot: TerminalSessionSnapshot) {
100
- const excerpt = outputExcerpt(snapshot.output);
101
- const lines = [
102
- `session: ${snapshot.source}`,
103
- `status: ${snapshot.status}`,
104
- `shell: ${snapshot.shell}`,
105
- `cwd: ${snapshot.cwd}`,
106
- `elapsedMs: ${snapshot.elapsedMs}`,
107
- snapshot.exitCode === undefined ? undefined : `exitCode: ${snapshot.exitCode}`,
108
- snapshot.signal === undefined ? undefined : `signal: ${snapshot.signal}`,
109
- snapshot.error === undefined ? undefined : `error: ${snapshot.error}`,
110
- `outputRange: ${snapshot.outputStart}-${snapshot.outputEnd}`,
111
- snapshot.truncated ? "output: truncated; use read for the retained log" : undefined,
112
- excerpt.length === 0 ? "output: (empty)" : `output:\n${excerpt}`,
113
- ].filter((line): line is string => line !== undefined);
114
114
  return {
115
- content: [{ type: "text" as const, text: lines.join("\n") }],
115
+ content: [{ type: "text" as const, text: formatAgentTerminalSnapshot(snapshot) }],
116
116
  details: snapshot,
117
117
  isError: snapshot.status === "failed" || snapshot.status === "lost",
118
118
  };
119
119
  }
120
-
121
- function outputExcerpt(output: string): string {
122
- const plain = stripVTControlCharacters(output).trimEnd();
123
- return plain.length <= 8_000 ? plain : `[earlier output omitted]\n${plain.slice(-8_000)}`;
124
- }
125
-
126
120
  async function captureInitialBackgroundPreview(
127
121
  manager: TerminalSessionManager,
128
122
  session: ReturnType<TerminalSessionManager["start"]>,