pi-agent-ide 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (448) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +146 -68
  3. package/assets/social-preview.png +0 -0
  4. package/assets/summary/debugging.png +0 -0
  5. package/assets/summary/editing.png +0 -0
  6. package/assets/summary/read.png +0 -0
  7. package/assets/summary/search-and-replace.png +0 -0
  8. package/assets/summary/search.png +0 -0
  9. package/assets/summary/settings.png +0 -0
  10. package/assets/summary/terminal.png +0 -0
  11. package/assets/summary/thumbs/debugging.png +0 -0
  12. package/assets/summary/thumbs/editing.png +0 -0
  13. package/assets/summary/thumbs/read.png +0 -0
  14. package/assets/summary/thumbs/search-and-replace.png +0 -0
  15. package/assets/summary/thumbs/search.png +0 -0
  16. package/assets/summary/thumbs/settings.png +0 -0
  17. package/assets/summary/thumbs/terminal.png +0 -0
  18. package/assets/summary/thumbs/user_terminal.png +0 -0
  19. package/assets/summary/user_terminal.png +0 -0
  20. package/dist/chunk-3E2NTWCN.js +2 -0
  21. package/dist/chunk-7WCZOO5I.js +1 -0
  22. package/dist/chunk-CEX3VOJ7.js +2 -0
  23. package/dist/chunk-FA6BKC5Y.js +1 -0
  24. package/dist/{chunk-2527OQ4Y.js → chunk-HMLH43ZS.js} +1 -1
  25. package/dist/chunk-LVWMWWWF.js +28 -0
  26. package/dist/chunk-MPT3R4BL.js +0 -0
  27. package/dist/chunk-PZFOOHY2.js +15 -0
  28. package/dist/{chunk-HKMBQLEK.js → chunk-QDLTO5PH.js} +1 -1
  29. package/dist/{chunk-Z3VC3S2T.js → chunk-QIK2E64R.js} +1 -1
  30. package/dist/{chunk-OYWIZII6.js → chunk-S6QRG3TQ.js} +1 -1
  31. package/dist/chunk-T7CZIACQ.js +27 -0
  32. package/dist/chunk-T7I2VX3J.js +1 -0
  33. package/dist/chunk-VCTK4JSN.js +3 -0
  34. package/dist/chunk-VXD6FZP5.js +5 -0
  35. package/dist/chunk-W7CASEO3.js +1 -0
  36. package/dist/chunk-YT42LKFV.js +16 -0
  37. package/dist/entry-1.js +1 -1
  38. package/dist/entry-10.js +1 -1
  39. package/dist/entry-11.js +1 -1
  40. package/dist/entry-12.js +1 -1
  41. package/dist/entry-13.js +1 -1
  42. package/dist/entry-14.js +1 -1
  43. package/dist/entry-15.js +1 -1
  44. package/dist/entry-16.js +1 -1
  45. package/dist/entry-17.js +1 -0
  46. package/dist/entry-19.js +1 -1
  47. package/dist/entry-2.js +1 -1
  48. package/dist/entry-20.js +1 -1
  49. package/dist/entry-21.js +1 -1
  50. package/dist/entry-22.js +1 -1
  51. package/dist/entry-23.js +1 -2
  52. package/dist/entry-24.js +1 -1
  53. package/dist/entry-25.js +2 -1
  54. package/dist/entry-26.js +1 -1
  55. package/dist/entry-27.js +2 -1
  56. package/dist/entry-28.js +1 -12
  57. package/dist/entry-29.js +1 -1
  58. package/dist/entry-30.js +1 -1
  59. package/dist/entry-31.js +13 -1
  60. package/dist/entry-32.js +1 -1
  61. package/dist/entry-33.js +1 -4
  62. package/dist/entry-34.js +1 -9
  63. package/dist/entry-35.js +1 -1
  64. package/dist/entry-36.js +4 -1
  65. package/dist/entry-37.js +9 -1
  66. package/dist/entry-38.js +1 -1
  67. package/dist/entry-39.js +1 -1
  68. package/dist/entry-40.js +1 -1
  69. package/dist/entry-41.js +1 -1
  70. package/dist/entry-42.js +1 -18
  71. package/dist/entry-43.js +1 -1
  72. package/dist/entry-44.js +1 -1
  73. package/dist/entry-45.js +17 -1
  74. package/dist/entry-46.js +1 -1
  75. package/dist/entry-47.js +1 -7
  76. package/dist/entry-48.js +1 -11
  77. package/dist/entry-49.js +1 -1
  78. package/dist/entry-50.js +6 -1
  79. package/dist/entry-51.js +10 -1
  80. package/dist/entry-52.js +1 -1
  81. package/dist/entry-53.js +1 -1
  82. package/dist/entry-54.js +1 -1
  83. package/dist/entry-55.js +1 -1
  84. package/dist/entry-56.js +1 -1
  85. package/dist/entry-57.js +1 -0
  86. package/dist/entry-58.js +1 -1
  87. package/dist/entry-59.js +1 -0
  88. package/dist/entry-60.js +1 -1
  89. package/dist/entry-61.js +1 -1
  90. package/dist/entry-62.js +0 -1
  91. package/dist/entry-63.js +1 -1
  92. package/dist/entry-64.js +0 -1
  93. package/dist/entry-65.js +1 -1
  94. package/dist/entry-66.js +1 -0
  95. package/dist/entry-67.js +1 -1
  96. package/dist/entry-68.js +1 -0
  97. package/dist/entry-69.js +1 -1
  98. package/dist/entry-70.js +1 -1
  99. package/dist/entry-71.js +0 -1
  100. package/dist/entry-72.js +1 -259
  101. package/dist/entry-73.js +0 -30
  102. package/dist/entry-74.js +1 -2
  103. package/dist/entry-75.js +1 -1
  104. package/dist/entry-76.js +1 -1
  105. package/dist/entry-77.js +315 -3
  106. package/dist/entry-78.js +30 -3
  107. package/dist/entry-79.js +2 -1
  108. package/dist/entry-80.js +1 -1
  109. package/dist/entry-81.js +1 -1
  110. package/dist/entry-82.js +3 -0
  111. package/dist/entry-83.js +3 -0
  112. package/dist/entry-84.js +1 -0
  113. package/dist/entry-85.js +1 -0
  114. package/dist/entry-86.js +1 -0
  115. package/dist/entry-9.js +1 -1
  116. package/dist/pi-agent-ide.js +3 -3
  117. package/docs/agent-guides/apply.md +333 -0
  118. package/docs/agent-guides/debugger.md +5 -0
  119. package/docs/agent-guides/diagnostics.md +5 -0
  120. package/docs/agent-guides/editing.md +44 -0
  121. package/docs/agent-guides/git-changes.md +5 -0
  122. package/docs/agent-guides/json-reading.md +41 -0
  123. package/docs/agent-guides/read-resources.md +44 -0
  124. package/docs/agent-guides/search-code.md +29 -0
  125. package/docs/agent-guides/terminal.md +7 -0
  126. package/docs/agent-guides/vision.md +5 -0
  127. package/docs/configuration.md +6 -14
  128. package/docs/research/apply-read-latency.md +219 -0
  129. package/node_modules/pi-agent-doctor/package.json +6 -6
  130. package/node_modules/pi-agent-doctor/runtime/entry-23.js +1 -0
  131. package/node_modules/pi-agent-documentation/package.json +15 -0
  132. package/node_modules/pi-agent-documentation/runtime/entry-24.js +1 -0
  133. package/node_modules/pi-agent-documentation/src/index.ts +69 -0
  134. package/node_modules/pi-agent-filesystem/index.ts +0 -4
  135. package/node_modules/pi-agent-filesystem/package.json +7 -7
  136. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  137. package/node_modules/pi-agent-filesystem-jq/index.ts +134 -0
  138. package/node_modules/pi-agent-filesystem-jq/package.json +23 -0
  139. package/node_modules/pi-agent-filesystem-jq/runtime/entry-27.js +2 -0
  140. package/node_modules/pi-agent-filesystem-jq/src/jq.ts +107 -0
  141. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  142. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  143. package/node_modules/pi-agent-filesystem-text/runtime/entry-29.js +2 -0
  144. package/node_modules/pi-agent-ide-ast/package.json +12 -11
  145. package/node_modules/pi-agent-ide-ast/runtime/entry-30.js +1 -0
  146. package/node_modules/pi-agent-ide-ast/src/search-presentation.ts +117 -0
  147. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +20 -2
  148. package/node_modules/pi-agent-ide-changes/index.ts +8 -0
  149. package/node_modules/pi-agent-ide-changes/package.json +9 -8
  150. package/node_modules/pi-agent-ide-changes/runtime/entry-32.js +1 -0
  151. package/node_modules/pi-agent-ide-formatter/package.json +4 -4
  152. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +1 -1
  153. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  154. package/node_modules/pi-agent-ide-languages/runtime/entry-35.js +2 -0
  155. package/node_modules/pi-agent-ide-lint/index.ts +1 -1
  156. package/node_modules/pi-agent-ide-lint/package.json +8 -8
  157. package/node_modules/pi-agent-ide-lint/runtime/entry-36.js +2 -0
  158. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +17 -1
  159. package/node_modules/pi-agent-ide-lsp/index.ts +0 -3
  160. package/node_modules/pi-agent-ide-lsp/package.json +10 -10
  161. package/node_modules/pi-agent-ide-lsp/runtime/entry-37.js +2 -0
  162. package/node_modules/pi-agent-image/package.json +3 -3
  163. package/node_modules/pi-agent-invariant/package.json +2 -2
  164. package/node_modules/pi-agent-pdf/package.json +3 -3
  165. package/node_modules/pi-agent-read/package.json +12 -11
  166. package/node_modules/pi-agent-read/runtime/entry-42.js +0 -1
  167. package/node_modules/pi-agent-read/runtime/entry-45.js +2 -0
  168. package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
  169. package/node_modules/pi-agent-read/src/core/extension.ts +16 -2
  170. package/node_modules/pi-agent-read/src/core/read-core.ts +4 -5
  171. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +62 -8
  172. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +19 -12
  173. package/node_modules/pi-agent-resource/package.json +2 -2
  174. package/node_modules/pi-agent-search/package.json +8 -7
  175. package/node_modules/pi-agent-search/runtime/entry-47.js +0 -1
  176. package/node_modules/pi-agent-search/runtime/entry-48.js +1 -0
  177. package/node_modules/pi-agent-search/runtime/entry-50.js +2 -0
  178. package/node_modules/pi-agent-search/src/core/extension.ts +29 -10
  179. package/node_modules/pi-agent-search-text/package.json +17 -9
  180. package/node_modules/pi-agent-search-text/runtime/entry-53.js +1 -0
  181. package/node_modules/pi-agent-search-text/src/persisted-result.ts +9 -7
  182. package/node_modules/pi-agent-search-text/src/search-renderer.ts +10 -4
  183. package/node_modules/pi-agent-search-text/src/search-result.ts +8 -1
  184. package/node_modules/pi-agent-text/package.json +3 -3
  185. package/node_modules/pi-agent-text/runtime/entry-55.js +1 -0
  186. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  187. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-56.js +2 -0
  188. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  189. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-58.js +2 -0
  190. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  191. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-60.js +2 -0
  192. package/node_modules/pi-agent-text-editor/index.ts +15 -0
  193. package/node_modules/pi-agent-text-editor/package.json +26 -25
  194. package/node_modules/pi-agent-text-editor/runtime/entry-72.js +0 -1
  195. package/node_modules/pi-agent-text-editor/runtime/entry-73.js +1 -0
  196. package/node_modules/pi-agent-text-editor/runtime/entry-74.js +1 -0
  197. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +24 -18
  198. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +4 -2
  199. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +5 -44
  200. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +13 -5
  201. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +124 -26
  202. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +2 -6
  203. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +186 -1
  204. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +1 -1
  205. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +2 -2
  206. package/node_modules/pi-agent-text-editor/src/core/extension.ts +0 -11
  207. package/node_modules/pi-agent-text-editor/src/core/text-editor-config.ts +1 -1
  208. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +0 -2
  209. package/node_modules/pi-agent-text-editor-renderer/index.ts +17 -4
  210. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  211. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +23 -11
  212. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +21 -16
  213. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  214. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  215. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  216. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  217. package/node_modules/pi-agent-tool-ui/runtime/entry-81.js +1 -0
  218. package/node_modules/pi-agent-web/package.json +7 -7
  219. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  220. package/node_modules/pi-agent-web-html/package.json +3 -3
  221. package/node_modules/pi-agent-web-html/runtime/entry-83.js +2 -0
  222. package/node_modules/pi-agent-web-image/package.json +4 -4
  223. package/node_modules/pi-agent-web-image/runtime/entry-84.js +2 -0
  224. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  225. package/node_modules/pi-agent-web-pdf/runtime/entry-85.js +2 -0
  226. package/node_modules/pi-agent-web-text/package.json +4 -4
  227. package/node_modules/pi-agent-web-text/runtime/entry-86.js +2 -0
  228. package/package.json +108 -44
  229. package/src/api/documentation.ts +2 -0
  230. package/src/api/plugin-protocol.ts +10 -4
  231. package/src/composite/builtin-extensions.ts +7 -0
  232. package/src/composite/extensions-config.ts +6 -0
  233. package/src/composite/module-labels.ts +5 -0
  234. package/src/composite/module-settings-store.ts +3 -0
  235. package/src/composite/module-settings.ts +39 -5
  236. package/src/composite/preferences.ts +37 -0
  237. package/src/composite/presentation.ts +14 -0
  238. package/src/composite/presets.ts +57 -0
  239. package/src/documentation/extension.ts +295 -0
  240. package/src/documentation/registry.ts +98 -0
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +0 -4
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +134 -0
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +23 -0
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/runtime/entry-27.js +2 -0
  247. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +107 -0
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/runtime/entry-28.js +2 -0
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-29.js +2 -0
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-25.js +2 -0
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  256. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  257. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-84.js +2 -0
  258. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  259. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-85.js +2 -0
  260. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  261. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-86.js +2 -0
  262. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  263. package/src/extensions/pi-agent-read/package.json +12 -11
  264. package/src/extensions/pi-agent-read/runtime/entry-42.js +0 -1
  265. package/src/extensions/pi-agent-read/runtime/entry-43.js +1 -0
  266. package/src/extensions/pi-agent-read/runtime/entry-45.js +2 -0
  267. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
  268. package/src/extensions/pi-agent-read/src/core/extension.ts +16 -2
  269. package/src/extensions/pi-agent-read/src/core/read-core.ts +4 -5
  270. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +62 -8
  271. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +19 -12
  272. package/src/extensions/pi-agent-search/package.json +8 -7
  273. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +17 -9
  274. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-53.js +1 -0
  275. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +9 -7
  276. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +10 -4
  277. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +8 -1
  278. package/src/extensions/pi-agent-search/runtime/entry-47.js +0 -1
  279. package/src/extensions/pi-agent-search/runtime/entry-48.js +1 -0
  280. package/src/extensions/pi-agent-search/runtime/entry-49.js +1 -0
  281. package/src/extensions/pi-agent-search/runtime/entry-50.js +2 -0
  282. package/src/extensions/pi-agent-search/src/core/extension.ts +29 -10
  283. package/src/extensions/pi-agent-text-editor/index.ts +15 -0
  284. package/src/extensions/pi-agent-text-editor/package.json +26 -25
  285. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  286. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-56.js +2 -0
  287. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  288. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-57.js +1 -0
  289. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-58.js +2 -0
  290. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  291. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-59.js +1 -0
  292. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-60.js +2 -0
  293. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +17 -4
  294. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  295. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  296. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +23 -11
  297. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +21 -16
  298. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  299. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-79.js +2 -0
  300. package/src/extensions/pi-agent-text-editor/runtime/entry-72.js +0 -1
  301. package/src/extensions/pi-agent-text-editor/runtime/entry-73.js +1 -0
  302. package/src/extensions/pi-agent-text-editor/runtime/entry-74.js +1 -0
  303. package/src/extensions/pi-agent-text-editor/runtime/entry-75.js +1 -0
  304. package/src/extensions/pi-agent-text-editor/runtime/entry-76.js +1 -0
  305. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +2 -0
  306. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +24 -18
  307. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +4 -2
  308. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +5 -44
  309. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +13 -5
  310. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +124 -26
  311. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +2 -6
  312. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +186 -1
  313. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +1 -1
  314. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +2 -2
  315. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +0 -11
  316. package/src/extensions/pi-agent-text-editor/src/core/text-editor-config.ts +1 -1
  317. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +0 -2
  318. package/src/pi-agent-ide.ts +7 -10
  319. package/src/plugins/pi-agent-ide-ast/package.json +12 -11
  320. package/src/plugins/pi-agent-ide-ast/runtime/entry-30.js +1 -0
  321. package/src/plugins/pi-agent-ide-ast/src/search-presentation.ts +117 -0
  322. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +20 -2
  323. package/src/plugins/pi-agent-ide-changes/index.ts +8 -0
  324. package/src/plugins/pi-agent-ide-changes/package.json +9 -8
  325. package/src/plugins/pi-agent-ide-changes/runtime/entry-32.js +1 -0
  326. package/src/plugins/pi-agent-ide-debugger/index.ts +44 -14
  327. package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +10 -1
  328. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +39 -0
  329. package/src/plugins/pi-agent-ide-debugger/src/ui.ts +42 -5
  330. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +9 -4
  331. package/src/plugins/pi-agent-ide-formatter/package.json +4 -4
  332. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +1 -1
  333. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  334. package/src/plugins/pi-agent-ide-languages/runtime/entry-35.js +2 -0
  335. package/src/plugins/pi-agent-ide-lint/index.ts +1 -1
  336. package/src/plugins/pi-agent-ide-lint/package.json +8 -8
  337. package/src/plugins/pi-agent-ide-lint/runtime/entry-36.js +2 -0
  338. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +17 -1
  339. package/src/plugins/pi-agent-ide-lsp/index.ts +0 -3
  340. package/src/plugins/pi-agent-ide-lsp/package.json +10 -10
  341. package/src/plugins/pi-agent-ide-lsp/runtime/entry-37.js +2 -0
  342. package/src/plugins/pi-agent-ide-terminal/index.ts +27 -2
  343. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +27 -2
  344. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +88 -12
  345. package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +6 -2
  346. package/src/plugins/pi-agent-ide-terminal/src/search.ts +0 -3
  347. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +7 -4
  348. package/src/plugins/pi-agent-ide-vision/index.ts +10 -7
  349. package/src/plugins/pi-agent-ide-vision/src/vision.ts +17 -3
  350. package/assets/gallery/apply-editing.png +0 -0
  351. package/assets/gallery/debugging.png +0 -0
  352. package/assets/gallery/read-web.png +0 -0
  353. package/assets/gallery/search-replace.png +0 -0
  354. package/assets/gallery/terminal.png +0 -0
  355. package/assets/gallery/tool-editing.png +0 -0
  356. package/dist/chunk-22CLOM2D.js +0 -1
  357. package/dist/chunk-3XJ3KDPZ.js +0 -16
  358. package/dist/chunk-526E364R.js +0 -3
  359. package/dist/chunk-DDKHZZDO.js +0 -5
  360. package/dist/chunk-EJ5OACQM.js +0 -1
  361. package/dist/chunk-HSM6R7IB.js +0 -27
  362. package/dist/chunk-PCZH7GOX.js +0 -26
  363. package/dist/chunk-SQ7ZTGOP.js +0 -2
  364. package/dist/entry-18.js +0 -1
  365. package/node_modules/pi-agent-doctor/runtime/entry-18.js +0 -1
  366. package/node_modules/pi-agent-filesystem/runtime/entry-23.js +0 -2
  367. package/node_modules/pi-agent-filesystem-image/runtime/entry-24.js +0 -2
  368. package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +0 -1
  369. package/node_modules/pi-agent-ide-changes/runtime/entry-29.js +0 -1
  370. package/node_modules/pi-agent-ide-changes/runtime/entry-30.js +0 -2
  371. package/node_modules/pi-agent-ide-languages/runtime/entry-32.js +0 -2
  372. package/node_modules/pi-agent-image/runtime/entry-35.js +0 -1
  373. package/node_modules/pi-agent-invariant/runtime/entry-36.js +0 -1
  374. package/node_modules/pi-agent-pdf/runtime/entry-37.js +0 -1
  375. package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
  376. package/node_modules/pi-agent-search-text/runtime/entry-48.js +0 -2
  377. package/node_modules/pi-agent-text/runtime/entry-50.js +0 -1
  378. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-53.js +0 -2
  379. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-55.js +0 -2
  380. package/node_modules/pi-agent-text-editor/runtime/entry-56.js +0 -1
  381. package/node_modules/pi-agent-text-editor/runtime/entry-58.js +0 -1
  382. package/node_modules/pi-agent-text-editor/runtime/entry-60.js +0 -1
  383. package/node_modules/pi-agent-text-editor-renderer/runtime/entry-73.js +0 -2
  384. package/node_modules/pi-agent-text-editor-renderer/src/config.ts +0 -73
  385. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-74.js +0 -2
  386. package/node_modules/pi-agent-web-pdf/runtime/entry-80.js +0 -2
  387. package/node_modules/pi-agent-web-text/runtime/entry-81.js +0 -2
  388. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-24.js +0 -2
  389. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/runtime/entry-25.js +0 -2
  390. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-23.js +0 -2
  391. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-78.js +0 -2
  392. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-79.js +0 -2
  393. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-80.js +0 -2
  394. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-81.js +0 -2
  395. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-77.js +0 -2
  396. package/src/extensions/pi-agent-read/runtime/entry-38.js +0 -1
  397. package/src/extensions/pi-agent-read/runtime/entry-39.js +0 -1
  398. package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
  399. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +0 -2
  400. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-49.js +0 -1
  401. package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
  402. package/src/extensions/pi-agent-search/runtime/entry-46.js +0 -1
  403. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-53.js +0 -2
  404. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-55.js +0 -2
  405. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-73.js +0 -2
  406. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/config.ts +0 -73
  407. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-74.js +0 -2
  408. package/src/extensions/pi-agent-text-editor/runtime/entry-56.js +0 -1
  409. package/src/extensions/pi-agent-text-editor/runtime/entry-57.js +0 -1
  410. package/src/extensions/pi-agent-text-editor/runtime/entry-58.js +0 -1
  411. package/src/extensions/pi-agent-text-editor/runtime/entry-59.js +0 -1
  412. package/src/extensions/pi-agent-text-editor/runtime/entry-60.js +0 -1
  413. package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +0 -1
  414. package/src/plugins/pi-agent-ide-ast/runtime/entry-28.js +0 -2
  415. package/src/plugins/pi-agent-ide-changes/runtime/entry-29.js +0 -1
  416. package/src/plugins/pi-agent-ide-changes/runtime/entry-30.js +0 -2
  417. package/src/plugins/pi-agent-ide-languages/runtime/entry-32.js +0 -2
  418. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem}/runtime/entry-25.js +0 -0
  419. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-image}/runtime/entry-26.js +0 -0
  420. /package/node_modules/{pi-agent-ide-ast → pi-agent-filesystem-pdf}/runtime/entry-28.js +0 -0
  421. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-ast}/runtime/entry-31.js +0 -0
  422. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-changes}/runtime/entry-33.js +0 -0
  423. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-formatter}/runtime/entry-34.js +0 -0
  424. /package/node_modules/{pi-agent-read → pi-agent-image}/runtime/entry-38.js +0 -0
  425. /package/node_modules/{pi-agent-read → pi-agent-invariant}/runtime/entry-39.js +0 -0
  426. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-40.js +0 -0
  427. /package/node_modules/{pi-agent-resource → pi-agent-read}/runtime/entry-43.js +0 -0
  428. /package/node_modules/{pi-agent-search → pi-agent-read}/runtime/entry-44.js +0 -0
  429. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-46.js +0 -0
  430. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-49.js +0 -0
  431. /package/node_modules/{pi-agent-text-anchor-constant → pi-agent-search-text}/runtime/entry-51.js +0 -0
  432. /package/node_modules/{pi-agent-text-anchor-exact → pi-agent-search-text}/runtime/entry-52.js +0 -0
  433. /package/node_modules/{pi-agent-text-anchor-line-hash → pi-agent-search-text}/runtime/entry-54.js +0 -0
  434. /package/node_modules/{pi-agent-text-editor → pi-agent-text-anchor-exact}/runtime/entry-57.js +0 -0
  435. /package/node_modules/{pi-agent-text-editor → pi-agent-text-anchor-line-hash}/runtime/entry-59.js +0 -0
  436. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-text-editor}/runtime/entry-75.js +0 -0
  437. /package/node_modules/{pi-agent-tool-ui → pi-agent-text-editor}/runtime/entry-76.js +0 -0
  438. /package/node_modules/{pi-agent-web → pi-agent-text-editor}/runtime/entry-77.js +0 -0
  439. /package/node_modules/{pi-agent-web-html → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  440. /package/node_modules/{pi-agent-web-image → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  441. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-image}/runtime/entry-26.js +0 -0
  442. /package/src/extensions/{pi-agent-search → pi-agent-read}/runtime/entry-44.js +0 -0
  443. /package/src/extensions/{pi-agent-text-editor/plugins/pi-agent-text-anchor-constant → pi-agent-search/plugins/pi-agent-search-text}/runtime/entry-51.js +0 -0
  444. /package/src/extensions/{pi-agent-text-editor/plugins/pi-agent-text-anchor-exact → pi-agent-search/plugins/pi-agent-search-text}/runtime/entry-52.js +0 -0
  445. /package/src/extensions/{pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash → pi-agent-search/plugins/pi-agent-search-text}/runtime/entry-54.js +0 -0
  446. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-ast}/runtime/entry-31.js +0 -0
  447. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-changes}/runtime/entry-33.js +0 -0
  448. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-formatter}/runtime/entry-34.js +0 -0
@@ -0,0 +1,28 @@
1
+ import{a as se,b as ae,c as le}from"./chunk-ESPNEJHK.js";import{a as oe}from"./chunk-M5IVSCR2.js";import{e as Y,f as K}from"./chunk-T7I2VX3J.js";import{a as te}from"./chunk-L7JMDDSD.js";import{a as Q,b as ee}from"./chunk-O6LE42GK.js";import{b as E}from"./chunk-VCTK4JSN.js";import"./chunk-YHUTTZC6.js";import{a as Z}from"./chunk-6CZO43OH.js";import{a as z,b as J}from"./chunk-OBNING2A.js";import"./chunk-S3ZPXWX7.js";import{a as ie}from"./chunk-ZTYWHL2F.js";import{a as ne,b as re}from"./chunk-7UGNGK7Y.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import Be from"node:path";import{stripVTControlCharacters as qe}from"node:util";import{truncateLine as Ve}from"@earendil-works/pi-coding-agent";import{Text as S}from"@earendil-works/pi-tui";import{DEFAULT_MAX_BYTES as ue,DEFAULT_MAX_LINES as ce,formatSize as He,truncateTail as Ge}from"@earendil-works/pi-coding-agent";function D(t){return Ge(t,{maxBytes:ue-4096,maxLines:ce-32})}l(D,"terminalOutputTail");function $(t){let e=D(t.output),n=[`session: ${t.source}`,`status: ${t.status}`,`shell: ${t.shell}`,`cwd: ${t.cwd}`,`elapsedMs: ${t.elapsedMs}`,t.exitCode===void 0?void 0:`exitCode: ${t.exitCode}`,t.signal===void 0?void 0:`signal: ${t.signal}`,t.error===void 0?void 0:`error: ${t.error}`,t.waitReason===void 0?void 0:`reason: ${t.waitReason}`,t.completionReason===void 0?void 0:`completionReason: ${t.completionReason}`,t.waitReason===void 0?void 0:`next: Read ${t.source} to inspect it, then use write or insert to send input.`,`outputRange: ${t.outputStart}-${t.outputEnd}`,t.truncated?"retainedOutput: earlier data omitted from memory":void 0,e.truncated?`fullOutput: ${t.fullOutputPath}`:void 0].filter(o=>o!==void 0),r=e.content.trimEnd();if(!e.truncated)return`${n.join(`
2
+ `)}
3
+ output:${r.length===0?" (empty)":`
4
+ ${r}`}`;let i=e.truncatedBy==="lines"?`${ce} line output budget`:`${He(ue)} output budget`,s=`[Earlier output omitted: showing the last ${e.outputLines} of ${e.totalLines} lines (${i}). Full output: ${t.fullOutputPath}]`;return`${n.join(`
5
+ `)}
6
+ output:
7
+ ${s}${r.length===0?"":`
8
+ ${r}`}`}l($,"formatAgentTerminalSnapshot");var Xe=500;function de(t,e,n,r,i){let s=e?"background":"wait",o=`${i.fg("toolTitle",r.displayName.toLocaleLowerCase())} ${i.fg("muted",`\xB7 ${k(n)} \xB7 ${s}`)}`;return new S(`${o}
9
+ ${i.fg("accent",N(r.family))} ${t}`,0,0)}l(de,"renderRunCall");function me(t,e,n){let r=e.map(i=>` ${n.fg("dim",i)}`);return r.push(n.fg("success",t==="delete"?"\u2713 stopped":"\u2713 sent")),new S(r.join(`
10
+ `),0,0)}l(me,"renderTerminalActionResult");function C(t,e,n,r,i){let s=[ze(t,i),i.fg("accent",`${e} ${n}`)];return r.length>0&&s.push(...r.map(o=>` ${i.fg("dim",o)}`)),new S(s.join(`
11
+ `),0,0)}l(C,"renderTerminalAction");function x(t,e,n,r){let i=ge(t,E,n);return r!==void 0&&i.splice(1,1,n.fg("accent",r)),new S(i.join(`
12
+ `),0,0)}l(x,"renderTerminalResult");function pe(t,e,n){if(e===!0?e="full":e===!1&&(e="compact"),e==="disabled"){if(!(t.status!==void 0&&!["running","completed"].includes(t.status)||t.exitCode!==void 0&&t.exitCode!==0||t.error!==void 0))return new S(P(t,(u,c)=>n.fg(u,c)),0,0);let o=A(t.output??"",E),a=[...o.omission===void 0?[]:[` ${n.fg("muted",o.omission)}`],...o.lines.map(u=>` ${n.fg("dim",u)}`),...t.error===void 0?[]:[` ${n.fg("error",t.error)}`],P(t,(u,c)=>n.fg(u,c))];return new S(a.join(`
13
+ `),0,0)}if(e==="full"){let s=ge(t,Number.POSITIVE_INFINITY,n).slice(2);return new S(s.join(`
14
+ `),0,0)}let r=A(t.output??"",E),i=[...r.omission===void 0?[]:[` ${n.fg("muted",r.omission)}`],...r.lines.map(s=>` ${n.fg("dim",s)}`)];return i.push(P(t,(s,o)=>n.fg(s,o))),new S(i.join(`
15
+ `),0,0)}l(pe,"renderRunResult");function fe(t,e){let n=l((o,a)=>e?.fg(o,a)??a,"color"),i=[`${n("accent",t.shell.toLocaleLowerCase())} ${n("muted",`\xB7 ${k(t.cwd)} \xB7 ${t.background?"background":"wait"}`)}`,`${n("accent",N(t.shellFamily))} ${O(t.command,84)}`],s=Ye(t.output,2);return s.length>0&&i.push(...s.map(o=>` ${n("dim",O(o,90))}`)),i.push(P(t,n)),i.join(`
16
+ `)}l(fe,"renderActiveTerminal");function ge(t,e,n){let r=(t.shell??"terminal").toLocaleLowerCase(),i=t.background===!0?"background":"wait",s=t.cwd===void 0?"workspace":k(t.cwd),o=t.shellFamily??"posix",a=[`${n.fg("accent",r)} ${n.fg("muted",`\xB7 ${s} \xB7 ${i}`)}`,`${n.fg("accent",N(o))} ${t.command??""}`],u=A(t.output??"",e);return u.omission!==void 0&&a.push(` ${n.fg("muted",u.omission)}`),u.lines.length>0&&a.push(...u.lines.map(c=>` ${n.fg("dim",c)}`)),a.push(P(t,(c,d)=>n.fg(c,d))),a}l(ge,"terminalCardLines");function Ye(t,e){return A(t,e).lines}l(Ye,"outputTail");function A(t,e){let n=D(qe(t).replaceAll("\r","")),r=n.content.split(`
17
+ `).map(u=>Ve(u.trimEnd(),Xe).text);r.at(-1)===""&&r.pop();let i=Number.isFinite(e)?Math.max(0,e):r.length,s=Math.max(0,r.length-i),o=Math.max(0,n.totalLines-n.outputLines),a=s+o;return{lines:r.slice(s),...n.truncated||a>0?{omission:a>0?`\u2026 ${a} earlier lines`:"\u2026 earlier output omitted"}:{}}}l(A,"outputWindow");function P(t,e){let n=t.status??"running",r=Ke(n),i=n==="completed"?"success":n==="running"?"accent":"error",s=[`${r} ${n}`,Je(t.elapsedMs??0)];return t.waitReason!==void 0&&s.push(`background \xB7 ${t.waitReason}`),t.completionReason!==void 0&&s.push(`reason ${t.completionReason}`),t.exitCode!==void 0?s.push(`exit ${t.exitCode}`):t.signal!==void 0&&s.push(`signal ${t.signal}`),e(i,s.join(" \xB7 "))}l(P,"statusLine");function Ke(t){return t==="completed"?"\u2713":t==="running"?"\u25CF":t==="stopping"?"\u25CC":"\u2717"}l(Ke,"statusIcon");function N(t){return t==="powershell"?"PS>":t==="cmd"?">":"$"}l(N,"promptMarker");function ze(t,e){let n=(t.shell??"terminal").toLocaleLowerCase(),r=t.cwd===void 0?"workspace":k(t.cwd),i=t.background===!0?"background":"wait",s=O(t.command??"process",48);return`${e.fg("toolTitle",n)} ${e.fg("muted",`\xB7 ${r} \xB7 ${i} \xB7 ${s}`)}`}l(ze,"terminalIdentity");function k(t){let e=process.env.HOME;return e!==void 0&&(t===e||t.startsWith(`${e}${Be.sep}`))?`~${t.slice(e.length)}`:t}l(k,"shortCwd");function O(t,e){let n=t.replaceAll(/\s+/gu," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}l(O,"oneLine");function Je(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}l(Je,"formatElapsed");function he(t){return{id:"terminal",onDidChange:l(e=>t.onDidChange(e),"onDidChange"),list:l(()=>t.list().filter(e=>e.status==="running"||e.status==="stopping").map(e=>({source:e.source,kind:"terminal",title:e.shell.toLocaleLowerCase(),description:e.command,status:e.status==="stopping"?"stopping":"running",...e.pid===void 0?{}:{pid:e.pid,owned:!0},renderSummary:l(n=>fe(e,n).split(`
18
+ `),"renderSummary"),renderDetail:l(n=>x(e,!0,n),"renderDetail"),sendInput:l(n=>t.write(e.source,n),"sendInput"),stop:l(()=>t.delete(e.source),"stop")})),"list")}}l(he,"terminalProcessProvider");import{setTimeout as nt}from"node:timers/promises";var Ze="#d8dee9",W="#111418",Qe=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"];async function F(t,e,n,r=1){let i=t.get(e);if(i===void 0)throw new Error(`Unknown terminal session ${e}`);await i.screenReady;let{createCanvas:s}=await import("@napi-rs/canvas"),o=Math.max(0,Math.min(i.rows-1,n?.start??0)),a=Math.max(1,Math.min(i.rows-o,n?.count??i.rows)),u=i.cols*9+24,c=a*18+24,d=s(Math.max(1,Math.round(u*r)),Math.max(1,Math.round(c*r))),m=d.getContext("2d");m.scale(r,r),m.fillStyle=W,m.fillRect(0,0,d.width,d.height),m.textBaseline="top";let p=i.screen.buffer.active,f=Math.max(0,p.baseY);for(let g=0;g<a;g+=1){let b=p.getLine(f+o+g);if(b!==void 0)for(let w=0;w<i.cols;w+=1){let v=b.getCell(w);v===void 0||v.getWidth()===0||et(m,v,w,g)}}return i.status==="running"&&p.cursorY>=o&&p.cursorY<o+a&&(m.fillStyle="rgba(216, 222, 233, 0.75)",m.fillRect(12+p.cursorX*9,12+(p.cursorY-o)*18+18-2,9,2)),d.toBuffer("image/png").toString("base64")}l(F,"renderTerminalScreen");function et(t,e,n,r){let i=ye(e,"foreground"),s=ye(e,"background");e.isInverse()&&([i,s]=[s,i]);let o=12+n*9,a=12+r*18;s!==W&&(t.fillStyle=s,t.fillRect(o,a,9*Math.max(1,e.getWidth()),18));let u=e.getChars();u.length!==0&&(t.font=`${e.isBold()?"bold ":""}14px monospace`,t.fillStyle=i,t.fillText(u,o,a),e.isUnderline()&&t.fillRect(o,a+18-2,9*Math.max(1,e.getWidth()),1))}l(et,"drawCell");function ye(t,e){let n=e==="foreground";if(n?t.isFgDefault():t.isBgDefault())return n?Ze:W;let i=n?t.isFgRGB():t.isBgRGB(),s=n?t.getFgColor():t.getBgColor();return i?`#${s.toString(16).padStart(6,"0")}`:tt(s)}l(ye,"cellColor");function tt(t){let e=Qe[t];if(e!==void 0)return e;if(t>=232){let a=8+(t-232)*10;return we(a,a,a)}let n=Math.max(0,t-16),r=Math.floor(n/36),i=Math.floor(n%36/6),s=n%6,o=l(a=>a===0?0:55+a*40,"channel");return we(o(r),o(i),o(s))}l(tt,"ansiColor");function we(t,e,n){return`#${[t,e,n].map(r=>r.toString(16).padStart(2,"0")).join("")}`}l(we,"rgb");var j="\0pi-terminal-write\0",H="\0pi-terminal-keys\0";function rt(t){let e=t?.find(u=>u==="image"||u==="sequence"||u.startsWith("image:")||u.startsWith("sequence:"));if(e===void 0)return;let n=e.indexOf(":"),r=n<0?e:e.slice(0,n),i=new Map;if(n>=0)for(let u of e.slice(n+1).split(",")){let[c,d,m]=u.split("=");if(c===void 0||d===void 0||m!==void 0||d.length===0)throw new Error(`Invalid terminal ${r} view parameter: ${u}`);if(c!=="duration"&&c!=="interval"&&c!=="scale")throw new Error(`Unsupported terminal ${r} view parameter: ${c}`);let p=Number(d);if(!Number.isFinite(p))throw new Error(`Terminal ${c} must be a number`);i.set(c,p)}let s=i.get("duration")??2,o=i.get("interval")??.5,a=i.get("scale")??1;if(!(a>0&&a<=1))throw new Error("Terminal image scale must be greater than 0 and at most 1");if(r==="sequence"){if(!(s>0&&s<=10))throw new Error("Terminal sequence duration must be greater than 0 and at most 10 seconds");if(!(o>0))throw new Error("Terminal sequence interval must be greater than 0 seconds");if(Math.floor(s/o)+1>20)throw new Error("Terminal sequence capture is limited to 20 frames")}return{mode:r,duration:s,interval:o,scale:a}}l(rt,"parseTerminalVisualView");async function xe(t,e){let n=new Map,r=new Map,i={protocol:z,apiVersion:J,id:"terminal",setup(o){o.addResolver({resolver:it(e),preserveTruncatedOutput:!0,renderResult(a,u,c){let d=a.details,m=d.source===void 0?void 0:e.get(d.source),p=m===void 0?{}:e.snapshot(m);return x(m===void 0?p:{...p,output:e.screenTail(m).join(`
19
+ `)},u.expanded,c,"read terminal")}}),o.addHandler({stage:"pre-read",async handler(a){let u=a.request.path;if(u===void 0||!y(u))return{kind:"continue",context:a};let c;try{c=rt(a.request.views)}catch(m){return{kind:"return",result:U(u,m instanceof Error?m.message:String(m))}}if(c===void 0)return{kind:"continue",context:a};let d=e.get(u);if(d===void 0)return{kind:"return",result:U(u,`Unknown terminal session ${u}`)};try{e.markInspected(u);let m=c.mode==="image"?1:Math.floor(c.duration/c.interval)+1,p=[];for(let f=0;f<m;f+=1){a.resolverContext.signal?.throwIfAborted(),f>0&&await nt(c.interval*1e3,void 0,{signal:a.resolverContext.signal});let g=await F(e,u,void 0,c.scale);p.push({type:"image",data:g,mimeType:"image/png"})}return{kind:"return",result:{content:p,details:{source:d.source,resolvedBy:"terminal",frames:m,mode:c.mode}}}}catch(m){return{kind:"return",result:U(u,m instanceof Error?m.message:String(m))}}}}),o.describe("shell:<session> \u2014 terminal status and a bounded output tail with a full-log path when truncated. image and parameterized sequence views return the virtual terminal screen as ordered PNG frames.")}},s={protocol:Q,apiVersion:ee,id:"terminal",setup(o){o.addResolver({resolver:ot(e)}),o.tool("write").addHandler({stage:"text-pre-edit",handler:l(async a=>(Se(a.input,e,n),await Te(a.input,e,r),st(a,j)),"handler")}),o.tool("insert").addHandler({stage:"text-pre-edit",handler:l(async a=>(await Te(a.input,e,r),Se(a.input,e,n),at(a)),"handler")});for(let a of["write","insert","delete"])o.addToolRenderer({tool:a,matches:l((u,c)=>dt(u,c),"matches"),renderCall(u,c,d){let m=u,p=typeof m.path=="string"?e.get(m.path):void 0,f=d.state;return p!==void 0&&(f.snapshot=e.snapshot(p)),C(f.snapshot??{},a,be(a,m),[],c)},renderResult(u,c,d){let m=ct(u.details);return me(m.action,m.changedLines,d)}});o.describe("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."),o.tool("write").describe("When path is shell:<session>, send content exactly as terminal input without adding Enter."),o.tool("insert").describe("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.")}};await Promise.all([Z(t,i),te(t,s)]),t.on("tool_result",async(o,a)=>{if(!T(o.input))return;let u=o.input.path;if(o.toolName==="replace"&&typeof u=="string"&&y(u))return{content:[{type:"text",text:`replace is unsupported for ${u}; use write for text, insert for keys, or delete to terminate and remove the session.`}],details:o.details,isError:!0};if(o.toolName==="delete"&&typeof u=="string"&&y(u)){let X=e.get(u);if(X===void 0)return;let je=e.snapshot(X);return e.delete(u).then(()=>({content:[{type:"text",text:`Deleted terminal session ${u}.`}],details:{source:u,deleted:!0,snapshot:je,action:"delete",input:"session",changedLines:[]},isError:!1}),_=>({content:[{type:"text",text:_ instanceof Error?_.message:String(_)}],details:{source:u,deleted:!1},isError:!0}))}if(o.toolName!=="write"&&o.toolName!=="insert"||o.isError)return;let c=o.input.path;if(typeof c!="string"||!y(c))return;let d=e.get(c);if(d===void 0)return;let m=r.get(c)??e.screenRows(d);r.delete(c);let p=n.get(c)??d.outputStart+d.output.length;n.delete(c),await e.waitForOutputAfter(d,p);let f=e.snapshot(d),g=o.toolName,b=be(g,o.input),w=e.screenChangeRegion(d,m,6),v=[{type:"text",text:`Sent ${b} to ${d.source}.`}];return a.model?.input.includes("image")===!0&&v.push({type:"image",data:await F(e,c,{start:w.startRow,count:w.lines.length}),mimeType:"image/png"}),{content:v,details:{source:d.source,action:g,status:d.status,snapshot:f,input:b,changedLines:w.lines},isError:o.isError}})}l(xe,"registerTerminalResources");function it(t){return{id:"terminal",async tryResolve(e){if(!y(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,async read(){t.markInspected(n.source);let r=t.snapshot(n);return[{type:"text",text:lt(r)}]}}}}}}l(it,"createReadResolver");function ot(t){return{id:"terminal-input",async tryResolve(e){if(!y(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,skipPostEdit:!0,async read(){return[{type:"text",text:"terminal input"}]},async write(r){let i=ut(r),s=i.indexOf(j),o=i.indexOf(H);if(s>=0){t.write(n.source,i.slice(s+j.length));return}if(o>=0){t.sendKeys(n.source,i.slice(o+H.length).trim());return}throw new Error(`Unsupported text operation for ${n.source}`)}}}}}}l(ot,"createInputResolver");function st(t,e){return!T(t.input)||!Re(t.input.path)?t:{...t,input:{...t.input,content:`${e}${typeof t.input.content=="string"?t.input.content:""}`}}}l(st,"transformWriteInput");function at(t){if(!T(t.input)||!Re(t.input.path))return t;if(t.input.before===!0)throw new Error("Shell keys can only be inserted after the active input position");return{...t,input:{...t.input,anchor:"end",before:!1,text:`${H}${typeof t.input.text=="string"?t.input.text:""}`}}}l(at,"transformInsertInput");function lt(t){return $(t)}l(lt,"formatSnapshot");function ut(t){if(t.length!==1||t[0].type!=="text")throw new Error("Terminal input must contain one text block");return t[0].text}l(ut,"singleText");function U(t,e){return{content:[{type:"text",text:e}],details:{source:t,failure:{code:"READ_FAILED",source:t,resolverId:"terminal",message:e}},isError:!0}}l(U,"failure");function y(t){return/^shell:[a-f\d]{12}$/u.test(t)}l(y,"isShellSource");function Re(t){return typeof t=="string"&&y(t)}l(Re,"isShellSourceValue");function ct(t){if(!T(t)||!T(t.snapshot))throw new TypeError("Invalid terminal action result");let e=t.snapshot,n=t.action;if(n!=="write"&&n!=="insert"&&n!=="delete")throw new TypeError("Invalid terminal action");return{source:typeof t.source=="string"?t.source:"shell:unknown",action:n,input:typeof t.input=="string"?t.input:"",changedLines:Array.isArray(t.changedLines)?t.changedLines.filter(r=>typeof r=="string"):[],snapshot:{...typeof e.shell=="string"?{shell:e.shell}:{},...typeof e.cwd=="string"?{cwd:e.cwd}:{},...typeof e.command=="string"?{command:e.command}:{},...typeof e.background=="boolean"?{background:e.background}:{},...typeof e.status=="string"?{status:e.status}:{}}}}l(ct,"terminalActionDetails");async function Te(t,e,n){if(!T(t)||typeof t.path!="string"||!y(t.path))return;let r=e.get(t.path);r!==void 0&&await r.screenReady,r!==void 0&&n.set(t.path,e.screenRows(r))}l(Te,"rememberScreen");function Se(t,e,n){if(!T(t)||typeof t.path!="string"||!y(t.path))return;let r=e.get(t.path);r!==void 0&&n.set(t.path,r.outputStart+r.output.length)}l(Se,"rememberOutputEnd");function be(t,e){if(t==="delete")return"session";let n=t==="write"?e.content:e.text,r=typeof n=="string"?n:"";return t==="write"?`text ${JSON.stringify(r)}`:`keys ${r}`}l(be,"terminalInputLabel");function dt(t,e){if(!T(t))return!1;if(e==="call")return typeof t.path=="string"&&y(t.path);let n=t.details;return T(n)&&typeof n.source=="string"&&y(n.source)}l(dt,"isTerminalRenderValue");function T(t){return typeof t=="object"&&t!==null}l(T,"isRecord");async function Ee(t,e){await ie(t,{protocol:ne,apiVersion:re,id:"terminal",setup(r){r.addResolver({resolver:mt(e),priority:100}),r.describe("path shell:<session> searches the retained text output of that terminal, including rows outside its current screen.")}})}l(Ee,"registerTerminalSearch");function mt(t){return{id:"terminal",async tryResolve(e){if(e.path===void 0||!e.path.startsWith("shell:"))return{kind:"not-handled"};let n=t.get(e.path);if(n===void 0)return{kind:"failed",error:new Error(`Unknown terminal session ${e.path}`)};let r=t.snapshot(n),i=pt(r,e);return{kind:"resolved",payload:{snapshot:r,query:e.query,matches:i}}},format(e){let n=G(e),r=n.matches.map(i=>`${n.snapshot.source}:${i.lineNumber}: ${i.lineText}`);return{content:[{type:"text",text:r.length===0?`No matches in ${n.snapshot.source}`:`${r.join(`
20
+ `)}
21
+
22
+ ${r.length} match${r.length===1?"":"es"} in ${n.snapshot.source}`}],details:{source:n.snapshot.source,payload:n}}},renderResult(e,n,r){let i=e.details,s=q(i)?G(i.payload):G(void 0),o=C(s.snapshot,"search",JSON.stringify(s.query),s.matches.slice(-6).map(a=>`${a.lineNumber}: ${a.lineText}`),r);return new B(o,n.expanded===!0,r)}}}l(mt,"terminalSearchResolver");var ve=12,B=class{constructor(e,n,r){this.content=e;this.expanded=n;this.theme=r}static{l(this,"TerminalSearchPanel")}render(e){let n=this.content.render(e);if(this.expanded||n.length<=ve)return n;let r=ve-1;return[...n.slice(0,r),this.theme.fg("muted",`\u2026 ${String(n.length-r)} visual rows omitted \xB7 ctrl+o to expand`)]}invalidate(){this.content.invalidate()}};function pt(t,e){let n=e.caseSensitive===!0?e.query:e.query.toLocaleLowerCase();if(n.length===0)return[];let r=[],i=e.limit??100;for(let[s,o]of t.output.replaceAll("\r","").split(`
23
+ `).entries()){let a=e.caseSensitive===!0?o:o.toLocaleLowerCase(),u=0;for(;r.length<i;){let c=a.indexOf(n,u);if(c<0)break;let d=c+n.length;(e.wholeWord!==!0||ft(a,c,d))&&r.push({source:t.source,lineNumber:s+1,startColumn:c,endColumn:d,matchedText:o.slice(c,d),lineText:o}),u=Math.max(d,c+1)}if(r.length>=i)break}return r}l(pt,"findTerminalMatches");function ft(t,e,n){return!/[\p{L}\p{N}_]/u.test(t[e-1]??"")&&!/[\p{L}\p{N}_]/u.test(t[n]??"")}l(ft,"isWordBoundary");function G(t){if(!gt(t))throw new TypeError("Invalid terminal search result");return t}l(G,"parsePayload");function gt(t){return q(t)&&typeof t.query=="string"&&Array.isArray(t.matches)&&q(t.snapshot)&&typeof t.snapshot.source=="string"}l(gt,"isTerminalSearchPayload");function q(t){return typeof t=="object"&&t!==null}l(q,"isRecord");import{spawn as ht}from"node:child_process";import{closeSync as yt,mkdirSync as wt,openSync as Tt,rmSync as St,writeSync as bt}from"node:fs";import xt from"node:os";import Pe from"node:path";import{createRequire as Rt}from"node:module";import{randomUUID as vt}from"node:crypto";import{stripVTControlCharacters as Et}from"node:util";var Ce=Rt(new URL("../src/plugins/pi-agent-ide-terminal/src/session-manager.ts",import.meta.url).href),$e=1e6,Pt=100,$t=30,At=2e3,L=class{static{l(this,"TerminalSessionManager")}#a;#e=new Map;#t=new Set;#r=new Set;#i=new Map;#o=!1;constructor(e=Lt){this.#a=e}onDidChange(e){return this.#t.add(e),()=>this.#t.delete(e)}onDidComplete(e){return this.#r.add(e),()=>this.#r.delete(e)}list(){return[...this.#e.values()].sort((e,n)=>n.startedAt-e.startedAt).map(e=>this.snapshot(e))}get(e){return this.#e.get(It(e))}snapshot(e,n=Date.now()){return{id:e.id,source:e.source,command:e.command,cwd:e.cwd,shell:e.shell.displayName,shellFamily:e.shell.family,...e.process===void 0?{}:{pid:e.process.pid},background:e.background,status:e.status,...e.waitReason===void 0?{}:{waitReason:e.waitReason},...e.completionReason===void 0?{}:{completionReason:e.completionReason},lastActivityAt:e.lastActivityAt,idleMs:Math.max(0,n-e.lastActivityAt),startedAt:e.startedAt,...e.endedAt===void 0?{}:{endedAt:e.endedAt},elapsedMs:(e.endedAt??n)-e.startedAt,...e.exitCode===void 0?{}:{exitCode:e.exitCode},...e.signal===void 0?{}:{signal:e.signal},...e.error===void 0?{}:{error:e.error},output:e.output,outputStart:e.outputStart,outputEnd:e.outputStart+e.output.length,truncated:e.outputStart>0,fullOutputPath:e.fullOutputPath,cols:e.cols,rows:e.rows}}start(e){if(this.#o)throw new Error("Terminal session manager is closed");let n=this.#a();if(!/^[a-f\d]{12}$/u.test(n)||this.#e.has(n))throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");let r=Wt(n);this.#i.set(n,Tt(r,"a",384));let i=e.cols??Pt,s=e.rows??$t,o=kt(i,s),a=l(p=>{},"resolveCompletion"),u=new Promise(p=>{a=p}),c={id:n,source:`shell:${n}`,command:e.command,background:e.background,cwd:e.cwd,shell:e.shell,startedAt:Date.now(),lastActivityAt:Date.now(),cols:i,rows:s,fullOutputPath:r,screen:o,status:"running",output:"",outputStart:0,screenReady:Promise.resolve(),completion:u,resolveCompletion:a,completionDelivered:!1},d;try{let p=Ce("node-pty"),f={name:"xterm-256color",cols:i,rows:s,cwd:e.cwd,env:_t(Mt())};d=p.spawn(e.shell.executable,[...e.shell.commandArgs(e.command)],f)}catch(p){let f={...c,status:"failed",endedAt:Date.now(),error:Nt(p)};return this.#e.set(n,f),this.#s(n),a(f),queueMicrotask(()=>this.#l(f)),f}let m={...c,process:d};return this.#e.set(n,m),d.onData(p=>this.#u(m,p)),d.onExit(({exitCode:p,signal:f})=>{R(m.status)||(m.endedAt=Date.now(),m.exitCode=p,f!==0&&(m.signal=f),m.status=m.status==="stopping"?"stopped":p===0?"completed":"failed",(p===124||p===137)&&(m.completionReason="timeout"),this.#s(m.id),m.resolveCompletion(m),this.#n(m),this.#l(m))}),this.#n(m),m}async wait(e,n){let r=this.required(e);return R(r.status)?r:n?.aborted===!0?(await this.stop(r.source,"cancelled"),r):await new Promise((i,s)=>{let o=l(()=>{this.stop(r.source,"cancelled").then(i,s)},"onAbort");n?.addEventListener("abort",o,{once:!0}),r.completion.then(a=>{n?.removeEventListener("abort",o),i(a)},s)})}async waitForForeground(e,n){let r=this.required(e);if(R(r.status))return{session:r};let i=n.interactiveDelayMs??3e3;return await new Promise(s=>{let o=!1,a,u=l(p=>{o||(p!==void 0&&R(r.status)&&(p=void 0),o=!0,clearTimeout(d),clearInterval(m),n.signal?.removeEventListener("abort",c),p!==void 0&&(r.background=!0,p!=="aborted"&&(r.waitReason=p),this.#n(r)),s({session:r,...p===void 0?{}:{reason:p}}))},"finish"),c=l(()=>u("aborted"),"onAbort"),d=setTimeout(()=>u("timeout"),n.timeoutMs),m=setInterval(()=>{if(!Ct(r)){a=void 0;return}a??=Date.now(),Date.now()-a>=i&&u("interactive")},Math.min(100,Math.max(10,i/2)));n.signal?.addEventListener("abort",c,{once:!0}),n.signal?.aborted===!0&&c(),r.completion.then(()=>u())})}async waitForOutputAfter(e,n){let r=Date.now()+300,i=n,s;for(;Date.now()<r;){let o=e.outputStart+e.output.length;if(o!==i)i=o,s=Date.now(),await e.screenReady;else if(s!==void 0&&Date.now()-s>=40)return;await V(10)}await e.screenReady}screenRows(e){let n=e.screen.buffer.active;return Array.from({length:e.rows},(r,i)=>(n.getLine(n.baseY+i)?.translateToString(!0)??"").trimEnd())}screenChangeRegion(e,n,r=6){let i=this.screenRows(e),s=Math.max(1,Math.min(e.rows,r)),o=Math.max(0,e.screen.buffer.active.cursorY-Math.floor(s/2)),a=-1;for(let d=0;d<=e.rows-s;d+=1){let m=0;for(let p=d;p<d+s;p+=1){let f=n[p]??"",g=i[p]??"",b=g.length>0&&!n.includes(g),w=f.length>0&&g.length===0;f!==g&&(b||w)&&(m+=1)}m>a&&(a=m,o=d)}let u=e.screen.buffer.active;return{lines:i.slice(o,o+s).map((d,m)=>{if(o+m!==u.cursorY)return d;let f=d.padEnd(u.cursorX," ");return`${f.slice(0,u.cursorX)}\u258C${f.slice(u.cursorX)}`}),startRow:o}}screenChangeWindow(e,n,r=6){return this.screenChangeRegion(e,n,r).lines}screenTail(e,n=e.rows){let r=e.screen.buffer.active,i=Math.max(0,r.baseY),s=[];for(let o=0;o<e.rows;o+=1){let a=r.getLine(i+o)?.translateToString(!0).trimEnd();a!==void 0&&a.length>0&&s.push(a)}return s.slice(-Math.max(0,n))}markInspected(e){let n=this.required(e);n.status==="running"&&(n.lastActivityAt=Date.now(),this.#n(n))}write(e,n){this.requiredRunning(e).process?.write(n)}sendKeys(e,n){this.requiredRunning(e).process?.write(Dt(n))}async stop(e,n="stopped"){let r=this.required(e);return R(r.status)||(r.status="stopping",this.#n(r),await Ae(r,!1),await Promise.race([r.completion.then(()=>!0),V(At).then(()=>!1)])||(await Ae(r,!0),await Promise.race([r.completion,V(1e3)])),R(r.status)||(r.status=n,r.endedAt=Date.now(),this.#s(r.id),r.resolveCompletion(r),this.#l(r)),n==="cancelled"&&(r.status="cancelled"),this.#n(r)),r}async delete(e){let n=this.required(e);n.completionDelivered=!0,await this.stop(n.source),n.screen.dispose(),this.#s(n.id),St(n.fullOutputPath,{force:!0}),this.#e.delete(n.id),this.#n(n)}async screenLines(e){let n=this.required(e);await n.screenReady;let r=n.screen.buffer.active,i=[],s=Math.max(0,r.baseY);for(let o=s;o<s+n.rows;o+=1)i.push(r.getLine(o)?.translateToString(!0)??"");return i}cursor(e){let n=this.required(e);return{x:n.screen.buffer.active.cursorX,y:n.screen.buffer.active.cursorY}}async dispose(){if(!this.#o){this.#o=!0,await Promise.all([...this.#e.values()].filter(e=>!R(e.status)).map(e=>this.stop(e.source)));for(let e of this.#e.values())e.screen.dispose(),this.#s(e.id);this.#t.clear(),this.#r.clear()}}required(e){let n=this.get(e);if(n===void 0)throw new Error(`Unknown terminal session ${e}`);return n}requiredRunning(e){let n=this.required(e);if(n.status!=="running")throw new Error(`Terminal session ${n.source} is ${n.status}; input is unavailable`);return n}#u(e,n){e.lastActivityAt=Date.now();let r=Et(n),i=this.#i.get(e.id);if(i!==void 0&&bt(i,r),e.output+=r,e.output.length>$e){let s=e.output.length-$e;e.output=e.output.slice(s),e.outputStart+=s}e.screenReady=e.screenReady.then(()=>new Promise(s=>{e.screen.write(n,s)})),this.#n(e)}#s(e){let n=this.#i.get(e);n!==void 0&&(yt(n),this.#i.delete(e))}#n(e){for(let n of this.#t)n(e)}#l(e){for(let n of this.#r)n(e)}};function Ct(t){if(t.status!=="running")return!1;let e=t.screen.buffer.active,n=e.getLine(e.baseY+e.cursorY)?.translateToString(!0).trimEnd()??"";return/\[[^\]\n]{1,20}(?:\/[^\]\n]{1,20})+\]\s*[:?>]?\s*$/iu.test(n)||/(?:choose|select|enter|password|confirm|continue|proceed)[^\n]{0,60}[:?]\s*$/iu.test(n)||/^(?:❯|›)\s+\S/u.test(n)}l(Ct,"looksInteractive");function kt(t,e){let{Terminal:n}=Ce("@xterm/headless");return new n({cols:t,rows:e,scrollback:2e3,allowProposedApi:!0})}l(kt,"createScreen");function Lt(){return vt().replaceAll("-","").slice(0,12)}l(Lt,"defaultSessionId");function It(t){return t.startsWith("shell:")?t.slice(6):t}l(It,"normalizeSessionId");function R(t){return t!=="running"&&t!=="stopping"}l(R,"isTerminalStatus");function Mt(){return process.env}l(Mt,"processEnvironment");function _t(t){return{...Object.fromEntries(Object.entries(t).filter(e=>e[1]!==void 0)),PAGER:"cat",GIT_PAGER:"cat",SYSTEMD_PAGER:"cat",GH_PAGER:"cat"}}l(_t,"cleanEnvironment");function Dt(t){return t.split(/[\s,]+/u).filter(Boolean).map(Ot).join("")}l(Dt,"encodeTerminalKeys");function Ot(t){if(/^\^[?@A-Z[\\\]^_]$/iu.test(t)){let d=t.slice(1).toUpperCase();return d==="?"?"\x7F":String.fromCharCode(d.charCodeAt(0)&31)}let e=t.toLowerCase().split("+"),n=e.pop()??"",r=new Set(e);if([...r].some(d=>!["ctrl","control","alt","meta","shift"].includes(d)))throw new Error(`Unsupported terminal key ${t}`);let i=r.has("ctrl")||r.has("control"),s=r.has("alt")||r.has("meta"),o=r.has("shift");if(i&&n.length===1&&/[a-z@[\\\]^_?]/u.test(n)){let d=n.toUpperCase(),m=d==="?"?"\x7F":String.fromCharCode(d.charCodeAt(0)&31);return s?`\x1B${m}`:m}let a={enter:"\r",tab:" ",escape:"\x1B",esc:"\x1B",backspace:"\x7F",home:"\x1B[H",end:"\x1B[F",delete:"\x1B[3~"};if(!i&&!s&&!o&&a[n]!==void 0)return a[n];if(s&&!i&&!o&&a[n]!==void 0)return`\x1B${a[n]}`;let c={up:"A",down:"B",right:"C",left:"D",home:"H",end:"F"}[n];if(c!==void 0)return!i&&!s&&!o?`\x1B[${c}`:`\x1B[1;${1+(o?1:0)+(s?2:0)+(i?4:0)}${c}`;if(s&&!i&&n.length===1)return`\x1B${o?n.toUpperCase():n}`;throw new Error(`Unsupported terminal key ${t}`)}l(Ot,"encodeTerminalKey");async function Ae(t,e){let n=t.process;if(n!==void 0){if(globalThis.process.platform!=="win32")try{globalThis.process.kill(-n.pid,e?"SIGKILL":"SIGTERM");return}catch{try{n.kill(e?"SIGKILL":"SIGTERM")}catch{}return}await new Promise(r=>{let i=ht("taskkill.exe",["/PID",String(n.pid),"/T",...e?["/F"]:[]],{windowsHide:!0,stdio:"ignore"});i.once("error",()=>r()),i.once("exit",()=>r())})}}l(Ae,"terminateProcessTree");function V(t){return new Promise(e=>setTimeout(e,t))}l(V,"delay");function Nt(t){return t instanceof Error?t.message:String(t)}l(Nt,"errorMessage");function Wt(t){let e=Pe.join(xt.tmpdir(),`pi-agent-ide-terminal-${process.pid}`);return wt(e,{recursive:!0,mode:448}),Pe.join(e,`${t}.log`)}l(Wt,"createOutputLog");import Ft from"node:os";import ke from"node:path";function Le(t=process.platform,e=process.env){if(t==="win32"){let i=e.SHELL?.trim()||"powershell.exe",s=ke.win32.basename(i).toLowerCase();return s==="cmd"||s==="cmd.exe"?{executable:i,displayName:"Command Prompt",family:"cmd",commandArgs:l(o=>["/d","/s","/c",o],"commandArgs")}:{executable:i,displayName:s.startsWith("pwsh")?"PowerShell":"Windows PowerShell",family:"powershell",commandArgs:l(o=>["-NoLogo","-NoProfile","-Command",o],"commandArgs")}}let n=e.SHELL?.trim()||Ft.userInfo().shell||(t==="darwin"?"/bin/zsh":"/bin/bash"),r=ke.basename(n);return{executable:n,displayName:r==="zsh"?"zsh":r==="bash"?"Bash":r,family:"posix",commandArgs:l(i=>["-c",i],"commandArgs")}}l(Le,"resolveShellProfile");function Ie(t){switch(t.family){case"powershell":return"Write PowerShell syntax. Use PowerShell cmdlets, `$env:NAME` for environment variables, and `;` or pipelines to compose commands.";case"cmd":return"Write Command Prompt syntax. Use `%NAME%` for environment variables and `&&` to chain successful commands.";case"posix":return`Write ${t.displayName} syntax. Use POSIX-style paths, \`$NAME\` for environment variables, and \`&&\` or pipelines to compose commands.`}}l(Ie,"shellSyntaxGuidance");import Me from"node:path";import{stripVTControlCharacters as Ut}from"node:util";import{defineTool as jt}from"@earendil-works/pi-coding-agent";import{Type as h}from"typebox";import{Text as Ht}from"@earendil-works/pi-tui";var Gt=h.Object({command:h.String({minLength:1,description:"Command written in the syntax of the configured system shell"}),background:h.Optional(h.Boolean({description:"Return immediately while the terminal session continues. Defaults to false."})),timeoutSeconds:h.Optional(h.Number({minimum:.1,maximum:86400,description:"Maximum foreground wait in seconds before returning the live session as background. Defaults to 60."})),cwd:h.Optional(h.String({description:"Working directory. Relative paths resolve from the current workspace."})),cols:h.Optional(h.Integer({minimum:20,maximum:300,description:"Virtual terminal width in cells"})),rows:h.Optional(h.Integer({minimum:5,maximum:120,description:"Virtual terminal height in cells"}))},{additionalProperties:!1});function _e(t,e,n,r,i="compact"){let s=process.platform==="win32"?"powershell":"bash";t.registerTool(jt({name:s,label:n.displayName,promptSnippet:`Execute ${n.displayName} commands in synchronous or background terminal sessions`,promptGuidelines:[`Do not use ${s} commands or scripts to edit files. Use Apply or the standalone editing tools instead. Commands that inherently generate files, such as formatters and code generators, are allowed.`],description:`Use ${s} to execute a command in the user's configured ${n.displayName} shell (${n.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. Silent background sessions are treated as potentially stale after two minutes and wake an idle agent for inspection. 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. ${Ie(n)}`,parameters:Gt,async execute(o,a,u,c,d){r.bind(d);let m=a.cwd===void 0?d.cwd:Me.resolve(d.cwd,a.cwd),p=e.start({command:a.command,background:a.background??!1,cwd:m,shell:n,...a.cols===void 0?{}:{cols:a.cols},...a.rows===void 0?{}:{rows:a.rows}});if(a.background===!0&&p.status!=="failed")return await Bt(e,p,c),p.status!=="running"&&(p.completionDelivered=!0),I(e.snapshot(p));if(p.status==="failed")return I(e.snapshot(p));let f=await e.waitForForeground(p.source,{signal:u,timeoutMs:(a.timeoutSeconds??60)*1e3});return f.reason==="aborted"&&r.notifyWaitTransition(f.session),I(e.snapshot(f.session))},renderCall(o,a,u){if((u.expanded?"full":i)==="disabled")return new Ht(a.fg("toolTitle",s),0,0);let d=typeof o.command=="string"?o.command:"",m=typeof o.cwd=="string"?Me.resolve(process.cwd(),o.cwd):process.cwd();return de(d,o.background===!0,m,n,a)},renderResult(o,a,u){return pe(o.details,a.expanded?"full":i,u)}}))}l(_e,"registerTerminalTools");function I(t){return{content:[{type:"text",text:$(t)}],details:t,isError:t.status==="failed"||t.status==="lost"}}l(I,"terminalResult");async function Bt(t,e,n){await new Promise(r=>{let i=!1,s,o=l(()=>{},"unsubscribe"),a=l(()=>{i||(i=!0,clearTimeout(s),o(),r())},"finish"),u=l(()=>{let c=t.snapshot(e);n?.(I(c)),(Ut(c.output).replaceAll("\r","").split(`
24
+ `).filter(m=>m.length>0).length>=E||c.status!=="running")&&a()},"publish");o=t.onDidChange(c=>{c.id===e.id&&u()}),s=setTimeout(a,2e3),u()})}l(Bt,"captureInitialBackgroundPreview");import{Box as De,Container as Oe}from"@earendil-works/pi-tui";var qt=120,Vt=12e4,M=class{constructor(e,n,r=Vt){this.pi=e;this.manager=n;this.staleIntervalMs=r;e.registerMessageRenderer("terminal-stale",(i,{expanded:s},o)=>{let a=Ne(i.details)?i.details:void 0,u=new Oe;a!==void 0&&u.addChild(x(a,s,o,"stale \xB7 inspect session"));let c=new De(1,1,d=>o.bg("toolPendingBg",d));return c.addChild(u),c}),e.registerMessageRenderer("terminal-completion",(i,{expanded:s},o)=>{let a=new Oe;for(let c of Xt(i.details))a.addChild(x(c,s,o));let u=new De(1,1,c=>o.bg("toolSuccessBg",c));return u.addChild(a),u}),this.#u=[n.onDidChange(i=>this.#s(i)),n.onDidComplete(i=>{this.#l(i.id),i.background&&this.#c(i)})]}static{l(this,"TerminalUi")}#a=new Map;#e;#t=new Map;#r=new Set;#i;#o=!1;#u;bind(e){this.#i=e}onAgentSettled(e){this.#i=e;for(let n of[...this.#r]){this.#r.delete(n);let r=this.manager.get(n);r!==void 0&&this.#s(r,!0)}}notifyWaitTransition(e){let n=this.manager.snapshot(e);this.pi.sendMessage({customType:"terminal-wait-transition",display:!1,content:`Terminal wait ended; ${n.source} is still running in background. Read it to inspect output, then use write or insert to send input.`,details:n},{triggerTurn:!0,deliverAs:"steer"})}dispose(){this.#o=!0,this.#e!==void 0&&clearTimeout(this.#e),this.#e=void 0,this.#a.clear();for(let e of this.#t.values())clearTimeout(e);this.#t.clear(),this.#r.clear(),this.#i=void 0;for(let e of this.#u)e()}#s(e,n=!1){if(this.#l(e.id),this.#o||!e.background||e.status!=="running")return;let r=this.manager.snapshot(e),i=Math.max(0,this.staleIntervalMs-r.idleMs);if(n&&i===0){this.#n(e);return}this.#t.set(e.id,setTimeout(()=>this.#n(e),i))}#n(e){if(this.#t.delete(e.id),this.#o||e.status!=="running"||!e.background)return;if(this.#i?.isIdle()!==!0){this.#r.add(e.id);return}let n=this.manager.snapshot(e);this.pi.sendMessage({customType:"terminal-stale",display:!0,content:Kt(n),details:n},{triggerTurn:!0,deliverAs:"followUp"}),this.#t.set(e.id,setTimeout(()=>this.#n(e),this.staleIntervalMs))}#l(e){let n=this.#t.get(e);n!==void 0&&clearTimeout(n),this.#t.delete(e),this.#r.delete(e)}#c(e){this.#o||e.completionDelivered||(this.#a.set(e.id,e),this.#e===void 0&&(this.#e=setTimeout(()=>{this.#e=void 0;let n=[...this.#a.values()].filter(i=>!i.completionDelivered);if(this.#a.clear(),this.#o||n.length===0)return;for(let i of n)i.completionDelivered=!0;let r=n.map(i=>this.manager.snapshot(i));this.pi.sendMessage({customType:"terminal-completion",display:!0,content:Yt(r),details:{sessions:r}},{triggerTurn:!0,deliverAs:"steer"})},qt)))}};function Xt(t){return!Fe(t)||!Array.isArray(t.sessions)?[]:t.sessions.filter(Ne)}l(Xt,"completionSnapshots");function Ne(t){return Fe(t)&&typeof t.id=="string"&&typeof t.source=="string"&&typeof t.command=="string"&&typeof t.cwd=="string"&&typeof t.shell=="string"&&typeof t.background=="boolean"&&typeof t.status=="string"&&typeof t.startedAt=="number"&&typeof t.elapsedMs=="number"&&typeof t.output=="string"}l(Ne,"isTerminalSessionSnapshot");function Yt(t){return`${t.length===1?"Background terminal completed:":"Background terminals completed:"}
25
+ ${t.map(n=>{let r=n.exitCode===void 0?"":`, exit ${n.exitCode}`,i=n.completionReason===void 0?"":`, reason ${n.completionReason}`,s=n.output.trimEnd().slice(-2e3);return`- ${n.source}: ${n.status}${r}${i}, ${We(n.elapsedMs)}
26
+ ${s||"(no output)"}`}).join(`
27
+ `)}`}l(Yt,"formatCompletionMessage");function Kt(t){let e=t.output.trimEnd().slice(-2e3);return`Background terminal ${t.source} has produced no output for ${We(t.idleMs)}. Inspect it with read. If it is healthy, keep waiting; otherwise send input or stop it.
28
+ ${e||"(no output)"}`}l(Kt,"formatStaleMessage");function We(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}l(We,"formatElapsed");function Fe(t){return typeof t=="object"&&t!==null}l(Fe,"isRecord");function Ue(t){return t==="full"||t==="disabled"?t:"compact"}l(Ue,"toolPresentation");async function zt(t,e){K(t,[await Y({id:"terminal",description:"Foreground and background commands, shell resources, and processes",triggers:[{tool:"bash"},...["read","write","insert","delete"].map(o=>({tool:o,resourcePrefixes:["shell:","process:"]}))]})]);let n=ae("terminal")??new L,r=Le(),i=new M(t,n),s=oe(t).add(he(n));await Promise.all([xe(t,n),Ee(t,n)]),_e(t,n,r,i,Ue(e?.preferences["ui.terminal"])),t.on("session_start",(o,a)=>i.bind(a)),t.on("agent_settled",(o,a)=>i.onAgentSettled(a)),t.on("session_shutdown",async o=>{if(i.dispose(),s(),o.reason!=="quit"){se("terminal",n);return}le("terminal",n),await n.dispose()})}l(zt,"registerTerminal");export{zt as default};
File without changes
@@ -0,0 +1,15 @@
1
+ import{a as p}from"./chunk-4LUW26BX.js";import"./chunk-GIRAEVUJ.js";import"./chunk-MPT3R4BL.js";import{a as E,b as I,c as k,d as P}from"./chunk-T7I2VX3J.js";import"./chunk-YHUTTZC6.js";import{a as R}from"./chunk-6CZO43OH.js";import{a as T,b as _}from"./chunk-OBNING2A.js";import{a}from"./chunk-EI7MMDWY.js";var G=/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/,h=class{static{a(this,"AgentDocumentationRegistry")}#e=new Map;register(n){let o=new Set(this.#e.keys());for(let s of n)b(s,o),o.add(s.id);for(let s of n)this.#e.set(s.id,x(s))}list(){return[...this.#e.values()].sort((n,o)=>n.id.localeCompare(o.id))}get(n){return this.#e.get(n)}matching(n,o){let s=M(o);return s?.startsWith("docs:")===!0?[]:this.list().filter(u=>u.triggers.some(i=>{if(i.tool!==n)return!1;let g=i.resourcePrefixes===void 0||s!==void 0&&i.resourcePrefixes.some(r=>s.startsWith(r)),t=i.viewPrefixes===void 0||S(o).some(r=>i.viewPrefixes?.some(d=>r.startsWith(d)));return g&&t}))}};function b(e,n){if(!G.test(e.id))throw new Error(`Invalid documentation ID: ${e.id}`);if(e.description.trim().length===0)throw new Error(`Documentation ${e.id} has no description`);if(e.markdown.trim().length===0)throw new Error(`Documentation ${e.id} has no Markdown content`);if(e.triggers.length===0||e.triggers.some(o=>o.tool.trim().length===0||o.resourcePrefixes?.some(s=>s.length===0)===!0||o.viewPrefixes?.some(s=>s.length===0)===!0))throw new Error(`Documentation ${e.id} has no valid triggers`);if(n.has(e.id))throw new Error(`Documentation ${e.id} is already registered`)}a(b,"validateDocument");function x(e){return Object.freeze({...e,triggers:Object.freeze(e.triggers.map(n=>Object.freeze({...n,...n.resourcePrefixes===void 0?{}:{resourcePrefixes:Object.freeze([...n.resourcePrefixes])},...n.viewPrefixes===void 0?{}:{viewPrefixes:Object.freeze([...n.viewPrefixes])}})))})}a(x,"freezeDocument");function S(e){if(typeof e!="object"||e===null)return[];let n=e.views;return Array.isArray(n)?n.filter(o=>typeof o=="string"):[]}a(S,"readViews");function M(e){if(typeof e!="object"||e===null)return;let n=e.path;return typeof n=="string"?n:void 0}a(M,"readPath");async function $(e){let n=new h,o=new Set,s=new Map,u=[],i={name:"agent-documentation-first-use",blockExecution:!0,toolNames:u,intercept(t){if(process.env.PI_AGENT_IDE_TEST_SKIP_GUIDE_GATE==="1"||t.toolCall.id.includes("-preflight-"))return;let r=N(n,o,t.toolCall.name,t.partialArgs??t.args);if(r.length!==0)return s.set(t.toolCall.id,r),C(e,r),U(r)}};p(e,i);let g=e.events.on(P,t=>{if(!q(t))throw new Error("Invalid agent documentation registration");n.register(t.documents),u.splice(0,u.length,...new Set(n.list().flatMap(r=>r.triggers.map(d=>d.tool)))),p(e,i)});e.on("session_shutdown",g),await R(e,{protocol:T,apiVersion:_,id:"agent-documentation",setup(t){t.addResolver({resolver:{id:"agent-documentation",tryResolve(r){if(!r.startsWith("docs:"))return Promise.resolve({kind:"not-handled"});let d=r.slice(5),m=d.length===0?void 0:n.get(d),f=d.length===0?z(n.list()):m?.markdown;return f===void 0?Promise.resolve({kind:"failed",error:new Error(`Unknown documentation ID: ${d}`)}):Promise.resolve({kind:"resolved",resource:{source:r,read:a(()=>Promise.resolve([{type:"text",text:f}]),"read")}})}}}),t.describe(()=>n.list().length===0?void 0:"docs: and docs:<id> \u2014 list or read packaged agent guidance."),t.addPromptGuideline(()=>V(n.list()))}}),e.on("session_start",(t,r)=>{y(r.sessionManager.getBranch(),n,o)}),e.on("tool_call",(t,r)=>{if(process.env.PI_AGENT_IDE_TEST_SKIP_GUIDE_GATE==="1"||t.toolCallId.includes("-preflight-"))return;y(r.sessionManager.getBranch(),n,o);let d=N(n,o,t.toolName,t.input);if(d.length!==0)return s.set(t.toolCallId,d),C(e,d),{block:!0,reason:w(d)}}),e.on("tool_result",(t,r)=>{if(t.toolCallId.includes("-preflight-"))return;let d=s.get(t.toolCallId);if(d!==void 0)return s.delete(t.toolCallId),{content:[{type:"text",text:w(d)}],details:A(d),isError:!0};y(r.sessionManager.getBranch(),n,o,t.toolCallId);let m=W(t.input);if(m!==void 0){let l=m.slice(5),O=n.list(),D=l.length===0||n.get(l)!==void 0;return l.length>0&&D&&o.add(l),{content:t.content,details:{...c(t.details)?t.details:{},documentation:D?l.length===0?{kind:"list",ids:O.map(v=>v.id)}:{kind:"document",id:l}:{kind:"error",code:"UNKNOWN_DOCUMENTATION",id:l}},isError:t.isError}}if(process.env.PI_AGENT_IDE_TEST_SKIP_GUIDE_GATE==="1")return;let f=n.matching(t.toolName,t.input).filter(l=>!o.has(l.id));if(f.length!==0){for(let l of f)o.add(l.id);return{content:[...t.content,...f.map(l=>({type:"text",text:`
2
+
3
+ ---
4
+
5
+ # Guide: ${l.id}
6
+
7
+ ${l.markdown.trim()}`}))],details:{...c(t.details)?t.details:{},documentation:{kind:"attachment",ids:f.map(l=>l.id)}},isError:t.isError}}}),e.events.emit(k,{protocol:E,apiVersion:I})}a($,"registerProgressiveDocumentation");function N(e,n,o,s){let u=e.matching(o,s).filter(i=>!n.has(i.id));for(let i of u)n.add(i.id);return u}a(N,"claimMatchingGuides");function j(e){return["[SYSTEM] Read the attached guide before using this tool. Repeat the tool call after reading it.",...e.map(n=>`
8
+
9
+ ---
10
+
11
+ # Guide: ${n.id}
12
+
13
+ ${n.markdown.trim()}`)].join("")}a(j,"renderGuideGate");function w(e){return`Guide sent to agent: ${e.map(n=>n.id).join(", ")}. Repeat the tool call.`}a(w,"guideNotice");function C(e,n){e.sendMessage({customType:"agent-documentation-first-use",content:j(n),display:!1,details:A(n)})}a(C,"sendGuideToAgent");function A(e){return{documentation:{kind:"gate",ids:e.map(n=>n.id)}}}a(A,"documentationGateDetails");function U(e){return{annotation:{kind:"blocked",reason:"Read the first-use guide, then retry."},message:{customType:"agent-documentation-first-use",content:w(e),display:!1,details:A(e)}}}a(U,"guideGateResult");function z(e){return e.length===0?"No agent documentation is currently available.":["# Available agent documentation","",...e.map(n=>`- \`${n.id}\` \u2014 ${n.description}`)].join(`
14
+ `)}a(z,"renderListing");function V(e){if(e.length!==0)return["Read docs:<id> for detailed packaged guidance when needed. Available documents:",...e.map(n=>` - ${n.id} \u2014 ${n.description}`)].join(`
15
+ `)}a(V,"renderPromptGuideline");function y(e,n,o,s){for(let u of e){if(!c(u)||u.type!=="message"||!c(u.message))continue;let i=u.message;if(i.toolCallId===s||typeof i.toolCallId=="string"&&i.toolCallId.includes("-preflight-")||i.role!=="toolResult"||typeof i.toolName!="string")continue;if(c(i.details)&&c(i.details.documentation)){let t=i.details.documentation,r=t.ids;if(Array.isArray(r)){for(let d of r)typeof d=="string"&&n.get(d)!==void 0&&o.add(d);continue}if(t.kind==="document"&&typeof t.id=="string"&&n.get(t.id)!==void 0){o.add(t.id);continue}}let g=i.input??K(i.details);for(let t of n.matching(i.toolName,g))o.add(t.id)}}a(y,"restoreClaims");function W(e){if(!(!c(e)||typeof e.path!="string"||!e.path.startsWith("docs:")))return e.path}a(W,"documentationSource");function K(e){if(!(!c(e)||typeof e.source!="string"))return{path:e.source}}a(K,"sourceInput");function q(e){return c(e)&&Array.isArray(e.documents)}a(q,"isRegistrationRequest");function c(e){return typeof e=="object"&&e!==null}a(c,"isRecord");export{$ as default};
@@ -1 +1 @@
1
- import{c as u,d as a,e as c}from"./chunk-Z3VC3S2T.js";import{a as t}from"./chunk-EI7MMDWY.js";function f(o,r){let s=t(()=>{let e,i={plugin:r,accept(g){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=g}};return o.events.emit(a,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(u,e=>{if(!c(e))throw new Error("Invalid pi-agent-ide core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-ide core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(f,"connectIdePlugin");export{f as a};
1
+ import{c as u,d as a,e as c}from"./chunk-QIK2E64R.js";import{a as t}from"./chunk-EI7MMDWY.js";function f(o,r){let s=t(()=>{let e,i={plugin:r,accept(g){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=g}};return o.events.emit(a,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(u,e=>{if(!c(e))throw new Error("Invalid pi-agent-ide core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-ide core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(f,"connectIdePlugin");export{f as a};
@@ -1 +1 @@
1
- import{a as o}from"./chunk-EI7MMDWY.js";var t="pi-agent-ide",r=4,s="pi-agent-ide/core/ready",a="pi-agent-ide/plugin/register";function d(e){return n(e)&&e.protocol===t&&e.apiVersion===4}o(d,"isIdeCoreReady");function i(e){return n(e)&&e.protocol===t&&e.apiVersion===4&&typeof e.id=="string"&&e.id.length>0&&typeof e.setup=="function"}o(i,"isIdePlugin");function c(e){return n(e)&&i(e.plugin)&&typeof e.accept=="function"}o(c,"isIdePluginRegistrationRequest");function n(e){return typeof e=="object"&&e!==null}o(n,"isRecord");export{t as a,r as b,s as c,a as d,d as e,i as f,c as g};
1
+ import{a as o}from"./chunk-EI7MMDWY.js";var t="pi-agent-ide",r=4,s="pi-agent-ide/core/ready",a="pi-agent-ide/plugin/register";function d(e){return n(e)&&e.protocol===t&&e.apiVersion===4}o(d,"isIdeCoreReady");function i(e){return n(e)&&e.protocol===t&&e.apiVersion===4&&typeof e.id=="string"&&e.id.length>0&&typeof e.setup=="function"}o(i,"isIdePlugin");function c(e){return n(e)&&i(e.plugin)&&typeof e.accept=="function"}o(c,"isIdePluginRegistrationRequest");function n(e){return typeof e=="object"&&e!==null}o(n,"isUnknownRecord");export{t as a,r as b,s as c,a as d,d as e,i as f,c as g};
@@ -1 +1 @@
1
- import{a as w}from"./chunk-M5IVSCR2.js";import{a as S,b as M}from"./chunk-EJ5OACQM.js";import{a as n}from"./chunk-EI7MMDWY.js";import{Container as _,Key as x,matchesKey as P,SelectList as k,Text as v,truncateToWidth as T,visibleWidth as A}from"@earendil-works/pi-tui";var I=class{constructor(e,o,s){this.registry=e;this.activityMode=o;e.onDidChange(()=>this.#s()),s.registerCommand("agent-ide-processes",{description:"Show active terminal and debugger processes created by Agent IDE",handler:n(async(d,c)=>{if(this.bind(c),c.mode!=="tui"){c.ui.notify("The Agent IDE process overlay requires the TUI.","info");return}await this.#r(c)},"handler")})}static{n(this,"AgentIdeProcessesUi")}#t;#i=!1;#e;bind(e){this.#i||(this.#t=e,this.#s())}dispose(){this.#i=!0,this.#e!==void 0&&clearInterval(this.#e),this.#e=void 0,this.#t?.ui.setWidget("agent-ide-processes",void 0),this.#t?.ui.setStatus("agent-ide-processes",void 0),this.#t=void 0}#n(){return this.registry.list()}#s(){let e=this.#t;if(this.#i||e===void 0||!e.hasUI)return;let o=this.#n();if(this.activityMode==="off"||o.length===0){e.ui.setWidget("agent-ide-processes",void 0),e.ui.setStatus("agent-ide-processes",void 0),this.#e!==void 0&&clearInterval(this.#e),this.#e=void 0;return}if(this.activityMode==="compact"){e.ui.setWidget("agent-ide-processes",void 0),e.ui.setStatus("agent-ide-processes",`Agent IDE processes: ${o.length}`);return}e.ui.setStatus("agent-ide-processes",void 0),e.ui.setWidget("agent-ide-processes",(s,d)=>({invalidate(){},render:n(c=>q(o,c,d),"render")}),{placement:"belowEditor"}),this.#e??=setInterval(()=>this.#s(),1e3)}async#r(e){for(;;){if(this.#n().length===0){e.ui.notify("No active Agent IDE processes.","info");return}let o=n(()=>{},"disposeRefresh"),s,d;try{d=await e.ui.custom((g,a,O,E)=>{let h=this.#n(),l="list",f,$=n(r=>{let u=h.map(t=>({value:t.source,label:`${t.status} ${t.kind} ${t.title}`,description:t.description})),p=new k(u,Math.min(u.length,12),{selectedPrefix:n(t=>a.fg("accent",t),"selectedPrefix"),selectedText:n(t=>a.fg("accent",t),"selectedText"),description:n(t=>a.fg("muted",t),"description"),scrollInfo:n(t=>a.fg("dim",t),"scrollInfo"),noMatch:n(t=>a.fg("warning",t),"noMatch")}),y=u.findIndex(t=>t.value===r);return y>=0&&p.setSelectedIndex(y),p.onSelect=t=>{f=h.find(W=>W.source===t.value),l="detail",g.requestRender()},p.onCancel=()=>E(null),p},"createList"),m=$(),C=n(()=>{let r=f?.source??m.getSelectedItem()?.value;h=this.#n(),f=l==="list"?void 0:h.find(u=>u.source===r),m=$(r),g.requestRender()},"refresh");return o=this.registry.onDidChange(C),s=setInterval(C,1e3),{invalidate:n(()=>m.invalidate(),"invalidate"),render(r){let u=new _;l==="list"?(u.addChild(m),u.addChild(new v(a.fg("dim",h.length===0?"esc close":"enter view \xB7 d stop \xB7 esc close"),1,0))):f===void 0?(u.addChild(new v(a.fg("warning","Process is no longer active."),1,0)),u.addChild(new v(a.fg("dim","esc back"),1,0))):(u.addChild(f.renderDetail(a)),u.addChild(new v(a.fg(l==="confirm"?"warning":"dim",l==="confirm"?"Stop this process? y confirm \xB7 n/esc cancel":l==="input"?"input mode \xB7 type to send \xB7 esc stop input":f.sendInput===void 0?"esc back \xB7 d stop":"i input \xB7 esc back \xB7 d stop"),1,0)));let p=n(t=>a.fg("accent",t),"accent"),y=Math.max(1,r-2);return[D("Agent IDE Processes",`${h.length} active`,r,p),...u.render(y).map(t=>b(t,r,p)),R(r,p)]},handleInput(r){l==="list"?r==="d"?(f=h.find(u=>u.source===m.getSelectedItem()?.value),f!==void 0&&(l="confirm")):m.handleInput(r):l==="detail"?P(r,x.escape)?l="list":r==="d"&&f!==void 0?l="confirm":r==="i"&&f?.sendInput!==void 0&&(l="input"):l==="input"?P(r,x.escape)?l="detail":f?.sendInput?.(r):r==="y"&&f!==void 0?E({source:f.source}):(r==="n"||P(r,x.escape))&&(l="detail"),g.requestRender()}}},{overlay:!0,overlayOptions:{width:"75%",maxHeight:"80%",minWidth:52}})}finally{o(),s!==void 0&&clearInterval(s)}if(d===null)return;let c=this.#n().find(g=>g.source===d.source);c!==void 0&&await c.stop()}}};function q(i,e,o){if(i.length===0)return[];let s=n(c=>o.fg("accent",c),"accent"),d=[D("Agent IDE Processes",`${i.length} active`,e,s)];for(let[c,g]of i.entries()){for(let a of g.renderSummary(o))d.push(b(` ${a} `,e,s));c<i.length-1&&d.push(b("",e,s))}return d.push(R(e,s)),d}n(q,"renderProcessWidget");function D(i,e,o,s){if(o<=1)return s("\u256D");let d=o-2,c=`\u2500 ${i} `,g=` ${e} \u2500`,a="\u2500".repeat(Math.max(0,d-A(c)-A(g)));return s(`\u256D${T(`${c}${a}${g}`,d).padEnd(d,"\u2500")}\u256E`)}n(D,"borderTop");function b(i,e,o){if(e<=1)return o("\u2502");let s=e-2,d=T(i,s);return`${o("\u2502")}${d}${" ".repeat(Math.max(0,s-A(d)))}${o("\u2502")}`}n(b,"borderLine");function R(i,e){return e(i<=1?"\u2570":`\u2570${"\u2500".repeat(i-2)}\u256F`)}n(R,"borderBottom");async function L(i){let e=w(i),o=await M(S()),s=new I(e,K(o.preferences?.["processes.activity"]),i);i.on("session_start",(d,c)=>s.bind(c)),i.on("session_shutdown",()=>s.dispose())}n(L,"registerAgentIdeProcesses");function K(i){return i==="compact"||i==="off"?i:"detailed"}n(K,"activityMode");export{L as default};
1
+ import{a as w}from"./chunk-M5IVSCR2.js";import{c as S,d as M}from"./chunk-W7CASEO3.js";import{a as n}from"./chunk-EI7MMDWY.js";import{Container as _,Key as x,matchesKey as P,SelectList as k,Text as v,truncateToWidth as T,visibleWidth as A}from"@earendil-works/pi-tui";var I=class{constructor(e,o,s){this.registry=e;this.activityMode=o;e.onDidChange(()=>this.#s()),s.registerCommand("agent-ide-processes",{description:"Show active terminal and debugger processes created by Agent IDE",handler:n(async(d,c)=>{if(this.bind(c),c.mode!=="tui"){c.ui.notify("The Agent IDE process overlay requires the TUI.","info");return}await this.#r(c)},"handler")})}static{n(this,"AgentIdeProcessesUi")}#t;#i=!1;#e;bind(e){this.#i||(this.#t=e,this.#s())}dispose(){this.#i=!0,this.#e!==void 0&&clearInterval(this.#e),this.#e=void 0,this.#t?.ui.setWidget("agent-ide-processes",void 0),this.#t?.ui.setStatus("agent-ide-processes",void 0),this.#t=void 0}#n(){return this.registry.list()}#s(){let e=this.#t;if(this.#i||e===void 0||!e.hasUI)return;let o=this.#n();if(this.activityMode==="off"||o.length===0){e.ui.setWidget("agent-ide-processes",void 0),e.ui.setStatus("agent-ide-processes",void 0),this.#e!==void 0&&clearInterval(this.#e),this.#e=void 0;return}if(this.activityMode==="compact"){e.ui.setWidget("agent-ide-processes",void 0),e.ui.setStatus("agent-ide-processes",`Agent IDE processes: ${o.length}`);return}e.ui.setStatus("agent-ide-processes",void 0),e.ui.setWidget("agent-ide-processes",(s,d)=>({invalidate(){},render:n(c=>q(o,c,d),"render")}),{placement:"belowEditor"}),this.#e??=setInterval(()=>this.#s(),1e3)}async#r(e){for(;;){if(this.#n().length===0){e.ui.notify("No active Agent IDE processes.","info");return}let o=n(()=>{},"disposeRefresh"),s,d;try{d=await e.ui.custom((g,a,O,E)=>{let h=this.#n(),l="list",f,$=n(r=>{let u=h.map(t=>({value:t.source,label:`${t.status} ${t.kind} ${t.title}`,description:t.description})),p=new k(u,Math.min(u.length,12),{selectedPrefix:n(t=>a.fg("accent",t),"selectedPrefix"),selectedText:n(t=>a.fg("accent",t),"selectedText"),description:n(t=>a.fg("muted",t),"description"),scrollInfo:n(t=>a.fg("dim",t),"scrollInfo"),noMatch:n(t=>a.fg("warning",t),"noMatch")}),y=u.findIndex(t=>t.value===r);return y>=0&&p.setSelectedIndex(y),p.onSelect=t=>{f=h.find(W=>W.source===t.value),l="detail",g.requestRender()},p.onCancel=()=>E(null),p},"createList"),m=$(),C=n(()=>{let r=f?.source??m.getSelectedItem()?.value;h=this.#n(),f=l==="list"?void 0:h.find(u=>u.source===r),m=$(r),g.requestRender()},"refresh");return o=this.registry.onDidChange(C),s=setInterval(C,1e3),{invalidate:n(()=>m.invalidate(),"invalidate"),render(r){let u=new _;l==="list"?(u.addChild(m),u.addChild(new v(a.fg("dim",h.length===0?"esc close":"enter view \xB7 d stop \xB7 esc close"),1,0))):f===void 0?(u.addChild(new v(a.fg("warning","Process is no longer active."),1,0)),u.addChild(new v(a.fg("dim","esc back"),1,0))):(u.addChild(f.renderDetail(a)),u.addChild(new v(a.fg(l==="confirm"?"warning":"dim",l==="confirm"?"Stop this process? y confirm \xB7 n/esc cancel":l==="input"?"input mode \xB7 type to send \xB7 esc stop input":f.sendInput===void 0?"esc back \xB7 d stop":"i input \xB7 esc back \xB7 d stop"),1,0)));let p=n(t=>a.fg("accent",t),"accent"),y=Math.max(1,r-2);return[D("Agent IDE Processes",`${h.length} active`,r,p),...u.render(y).map(t=>b(t,r,p)),R(r,p)]},handleInput(r){l==="list"?r==="d"?(f=h.find(u=>u.source===m.getSelectedItem()?.value),f!==void 0&&(l="confirm")):m.handleInput(r):l==="detail"?P(r,x.escape)?l="list":r==="d"&&f!==void 0?l="confirm":r==="i"&&f?.sendInput!==void 0&&(l="input"):l==="input"?P(r,x.escape)?l="detail":f?.sendInput?.(r):r==="y"&&f!==void 0?E({source:f.source}):(r==="n"||P(r,x.escape))&&(l="detail"),g.requestRender()}}},{overlay:!0,overlayOptions:{width:"75%",maxHeight:"80%",minWidth:52}})}finally{o(),s!==void 0&&clearInterval(s)}if(d===null)return;let c=this.#n().find(g=>g.source===d.source);c!==void 0&&await c.stop()}}};function q(i,e,o){if(i.length===0)return[];let s=n(c=>o.fg("accent",c),"accent"),d=[D("Agent IDE Processes",`${i.length} active`,e,s)];for(let[c,g]of i.entries()){for(let a of g.renderSummary(o))d.push(b(` ${a} `,e,s));c<i.length-1&&d.push(b("",e,s))}return d.push(R(e,s)),d}n(q,"renderProcessWidget");function D(i,e,o,s){if(o<=1)return s("\u256D");let d=o-2,c=`\u2500 ${i} `,g=` ${e} \u2500`,a="\u2500".repeat(Math.max(0,d-A(c)-A(g)));return s(`\u256D${T(`${c}${a}${g}`,d).padEnd(d,"\u2500")}\u256E`)}n(D,"borderTop");function b(i,e,o){if(e<=1)return o("\u2502");let s=e-2,d=T(i,s);return`${o("\u2502")}${d}${" ".repeat(Math.max(0,s-A(d)))}${o("\u2502")}`}n(b,"borderLine");function R(i,e){return e(i<=1?"\u2570":`\u2570${"\u2500".repeat(i-2)}\u256F`)}n(R,"borderBottom");async function L(i){let e=w(i),o=await M(S()),s=new I(e,K(o.preferences?.["processes.activity"]),i);i.on("session_start",(d,c)=>s.bind(c)),i.on("session_shutdown",()=>s.dispose())}n(L,"registerAgentIdeProcesses");function K(i){return i==="compact"||i==="off"?i:"detailed"}n(K,"activityMode");export{L as default};
@@ -0,0 +1,27 @@
1
+ import{a as le,b as ce,c as pe}from"./chunk-ESPNEJHK.js";import{a as ue}from"./chunk-M5IVSCR2.js";import{e as Q,f as ee}from"./chunk-T7I2VX3J.js";import{a as te}from"./chunk-MGCHOGQD.js";import{a as Y,b as Z}from"./chunk-T6LX2RX5.js";import{a as de}from"./chunk-L7JMDDSD.js";import{a as ie,b as se}from"./chunk-O6LE42GK.js";import{a as I}from"./chunk-K5G4FDXD.js";import{c as oe}from"./chunk-YHUTTZC6.js";import{a as ae}from"./chunk-6CZO43OH.js";import{a as re,b as ne}from"./chunk-OBNING2A.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import{d as S,e as y}from"./chunk-N34ATN52.js";import{a as i}from"./chunk-EI7MMDWY.js";import x from"node:path";import{access as dt}from"node:fs/promises";import{StringEnum as ut}from"@earendil-works/pi-ai";import{defineTool as lt}from"@earendil-works/pi-coding-agent";import{Type as D}from"typebox";import{access as j}from"node:fs/promises";async function $(r,e=process.env,t=process.platform){if(e.PI_PYTHON_PATH!==void 0)return{command:e.PI_PYTHON_PATH,args:[]};let n=t==="win32"?[{command:"python",args:[]},{command:"python3",args:[]},{command:"py",args:["-3"]}]:[{command:"python3",args:[]},{command:"python",args:[]}];for(let o of n)if(await S(o.command,r,e))return o;return n[0]}i($,"resolvePythonDebuggerCommand");var ge=[{language:"c",backend:"lldb-dap",status:"verified"},{language:"cpp",backend:"lldb-dap",status:"verified"},{language:"csharp",backend:"netcoredbg",status:"verified"},{language:"dart",backend:"dart debug_adapter",status:"verified"},{language:"elixir",backend:"elixir-ls",status:"verified"},{language:"go",backend:"dlv dap",status:"verified"},{language:"java",backend:"kotlin-debug-adapter",status:"verified"},{language:"javascript",backend:"vscode-js-debug",status:"verified"},{language:"julia",backend:"DebugAdapter.jl",status:"verified"},{language:"kotlin",backend:"kotlin-debug-adapter",status:"verified"},{language:"lua",backend:"local-lua-debugger-vscode",status:"verified"},{language:"php",backend:"vscode-php-debug",status:"verified"},{language:"powershell",backend:"PowerShellEditorServices",status:"verified"},{language:"python",backend:"debugpy",status:"verified"},{language:"r",backend:"vscDebugger",status:"verified"},{language:"ruby",backend:"rdbg",status:"verified"},{language:"rust",backend:"lldb-dap",status:"verified"},{language:"shell",backend:"bash-debug-adapter",status:"verified"},{language:"swift",backend:"lldb-dap",status:"verified"},{language:"typescript",backend:"vscode-js-debug",status:"verified"},{language:"zig",backend:"lldb-dap",status:"verified"}],J=[{id:"dart-debug-adapter",name:"Dart debug adapter",kind:"debugger",languages:["dart"],executables:["dart"],dependencies:["Dart SDK 3.13.3"],documentation:"https://github.com/dart-lang/sdk/tree/main/third_party/pkg/dap",debugger:{runtimeExecutables:["dart"],adapterExecutables:["dart"],platforms:["linux","win32"],install:"Install Dart SDK 3.13.3 from the official Dart archive."}},{id:"debugpy",name:"debugpy",kind:"debugger",languages:["python"],executables:["python3"],dependencies:["debugpy"],documentation:"https://github.com/microsoft/debugpy",debugger:{runtimeExecutables:["python3"],adapterExecutables:["python3"],platforms:["linux","win32"],install:"Install Python 3 and debugpy for that interpreter."}},{id:"delve",name:"Delve",kind:"debugger",languages:["go"],executables:["dlv"],dependencies:["github.com/go-delve/delve/cmd/dlv@v1.25.2"],documentation:"https://github.com/go-delve/delve/tree/master/Documentation/api/dap",debugger:{runtimeExecutables:["go"],adapterExecutables:["dlv"],platforms:["linux","win32"],install:"Install Go and Delve. Native Windows support requires amd64."}},{id:"elixir-ls-debug-adapter",name:"ElixirLS debug adapter",kind:"debugger",languages:["elixir"],executables:["elixir","mix"],dependencies:["Elixir","Erlang/OTP","ElixirLS 0.31.1"],documentation:"https://github.com/elixir-lsp/elixir-ls",debugger:{runtimeExecutables:["elixir","mix"],adapterExecutables:["debug_adapter.sh","debug_adapter.bat"],platforms:["linux","win32"],install:"Install compatible Erlang/OTP and Elixir releases plus ElixirLS 0.31.1. Use debug_adapter.bat on Windows."}},{id:"vsc-debugger",name:"vscDebugger",kind:"debugger",languages:["r"],executables:["R"],dependencies:["R 4.5.3","R6 2.6.1","jsonlite 2.0.0","vscDebugger 0.5.9"],documentation:"https://manuelhentschel.github.io/vscDebugger/",debugger:{runtimeExecutables:["R"],adapterExecutables:["R"],platforms:["linux","win32"],install:"Install R 4.5.3 and vscDebugger 0.5.9 for that R installation."}},{id:"julia-debug-adapter",name:"DebugAdapter.jl",kind:"debugger",languages:["julia"],executables:["julia"],dependencies:["Julia 1.13.0","DebugAdapter.jl 3.2.1"],documentation:"https://github.com/julia-vscode/DebugAdapter.jl",debugger:{runtimeExecutables:["julia"],adapterExecutables:["julia"],platforms:["linux"],install:"Install Julia 1.13.0 and add DebugAdapter.jl 3.2.1 to /opt/pi-debug-adapters/julia."}},{id:"kotlin-debug-adapter",name:"Kotlin Debug Adapter",kind:"debugger",languages:["java","kotlin"],executables:["kotlin-debug-adapter"],dependencies:["fwcd/kotlin-debug-adapter 0.4.4","Temurin JDK 21.0.8+9","Kotlin compiler 2.2.20 for Kotlin builds"],documentation:"https://github.com/fwcd/kotlin-debug-adapter",debugger:{runtimeExecutables:["java"],adapterExecutables:["kotlin-debug-adapter"],platforms:["linux"],install:"Install Temurin JDK 21.0.8+9 and fwcd/kotlin-debug-adapter 0.4.4. Compile the target with debug information before launching it."}},{id:"netcoredbg",name:"NetCoreDbg",kind:"debugger",languages:["csharp"],executables:["netcoredbg"],dependencies:["Samsung/netcoredbg 3.2.0-1092",".NET SDK 8"],documentation:"https://github.com/Samsung/netcoredbg",debugger:{runtimeExecutables:["dotnet"],adapterExecutables:["netcoredbg"],platforms:["linux","win32"],install:"Install .NET SDK 8 and NetCoreDbg 3.2.0-1092. On Windows, ensure the selected dotnet SDK is on PATH."}},{id:"lldb-dap",name:"lldb-dap",kind:"debugger",languages:["c","cpp","rust"],executables:["lldb-dap-18","lldb-dap"],dependencies:["lldb-18"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:[],adapterExecutables:["lldb-dap-18","lldb-dap"],platforms:["linux"],install:"Install LLDB 18 and compile the target with debug information."}},{id:"lldb-dap-swift",name:"lldb-dap for Swift",kind:"debugger",languages:["swift"],executables:["lldb-dap"],dependencies:["Swift 6.3.3 toolchain"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:["swiftc"],adapterExecutables:["lldb-dap"],platforms:["linux"],install:"Install the official Swift 6.3.3 Linux toolchain, which includes swiftc and lldb-dap."}},{id:"lldb-dap-zig",name:"lldb-dap for Zig",kind:"debugger",languages:["zig"],executables:["lldb-dap-18","lldb-dap"],dependencies:["Zig 0.15.2","lldb-18"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:["zig"],adapterExecutables:["lldb-dap-18","lldb-dap"],platforms:["linux","win32"],install:"Install Zig 0.15.2 and LLDB 18, then compile the target in Debug mode with the LLVM backend (-fllvm) so LLDB can inspect locals."}},{id:"local-lua-debugger",name:"Local Lua Debugger",kind:"debugger",languages:["lua"],executables:["lua","node"],dependencies:["local-lua-debugger-vscode 0.3.3"],documentation:"https://github.com/tomblind/local-lua-debugger-vscode",debugger:{runtimeExecutables:["lua","node"],adapterExecutables:["debugAdapter.js"],platforms:["linux","win32"],install:"Install Lua 5.3, Node 24, and local-lua-debugger-vscode 0.3.3."}},{id:"powershell-editor-services-debug",name:"PowerShell Editor Services",kind:"debugger",languages:["powershell"],executables:["pwsh"],dependencies:["PowerShellEditorServices 4.7.0"],documentation:"https://github.com/PowerShell/PowerShellEditorServices",debugger:{runtimeExecutables:["pwsh"],adapterExecutables:["Start-EditorServices.ps1"],platforms:["linux","win32"],install:"Install PowerShell 7.4.13 and PowerShellEditorServices 4.7.0."}},{id:"rdbg",name:"rdbg",kind:"debugger",languages:["ruby"],executables:["rdbg"],dependencies:["debug gem 1.11.0 or newer"],documentation:"https://github.com/ruby/debug",debugger:{runtimeExecutables:["ruby"],adapterExecutables:["rdbg","rdbg.bat"],platforms:["linux","win32"],install:"Install Ruby and debug gem 1.11.0 or newer."}},{id:"vscode-bash-debug",name:"Bash Debug",kind:"debugger",languages:["shell"],executables:["bash","node"],dependencies:["Bash Debug 0.3.9"],documentation:"https://github.com/rogalmic/vscode-bash-debug",debugger:{runtimeExecutables:["bash","node"],adapterExecutables:["bashDebug.js"],platforms:["linux"],install:"Install Bash, Node 24, and Bash Debug 0.3.9."}},{id:"vscode-php-debug",name:"PHP Debug",kind:"debugger",languages:["php"],executables:["php","node"],dependencies:["PHP Debug 1.40.1","Xdebug"],documentation:"https://github.com/xdebug/vscode-php-debug",debugger:{runtimeExecutables:["php","node"],adapterExecutables:["phpDebug.js"],platforms:["linux","win32"],install:"Install PHP with Xdebug, Node 24, and PHP Debug 1.40.1."}},{id:"vscode-js-debug",name:"vscode-js-debug",kind:"debugger",languages:["javascript","typescript"],executables:["node"],dependencies:["@vscode/js-debug"],documentation:"https://github.com/microsoft/vscode-js-debug",debugger:{runtimeExecutables:["node"],adapterExecutables:["dapDebugServer.js"],platforms:["linux","win32"],install:"Install Node 24 and js-debug-dap v1.117.0 from the official release archive."}}];function H(r){return J.find(e=>e.languages.includes(r))}i(H,"debuggerRecipeForLanguage");var be="/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js",fe="/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh",me={protocol:Y,apiVersion:1,id:"debugger",setup(r){for(let e of J)r.addToolRecipe(e);r.addSetupCheck({id:"effective-config",inspect:He}),r.addCheck({id:"adapters",title:"Debug adapters",run:Fe})}};async function He(r,e=process.platform){let t=new Map([...r.detectedLanguageIds].map(H).filter(a=>a!==void 0).map(a=>[a.id,a])),n=[...r.detectedLanguageIds].flatMap(a=>{let s=H(a);return s===void 0?[]:[{kind:"debugger",languageId:a,toolId:s.id}]}),o=[];for(let a of ge)a.status==="planned"&&r.detectedLanguageIds.has(a.language)&&o.push({id:`debugger-${a.language}-not-verified`,message:`${a.backend} is selected for ${a.language}, but its Linux debugger integration is not verified yet`});for(let a of t.values()){let s=a.debugger;if(s===void 0)continue;let d=e==="linux"||e==="darwin"||e==="win32"?e:void 0;if(d===void 0||!s.platforms.includes(d)){o.push({id:`debugger-${a.id}-platform`,category:"unsupported-platform",message:`${a.name} does not support the ${e} debugger recipe`});continue}let u=a.id==="debugpy"?await $(r.cwd,r.env,e):void 0,c=await Oe(u===void 0?s.runtimeExecutables:[u.command],r.cwd,r.env);if(c!==void 0){o.push({id:`debugger-${a.id}-runtime`,category:"missing-runtime",message:`Runtime ${c} is unavailable. ${s.install}`});continue}if(!await Ne(a.id,r.cwd,r.env,e)){o.push({id:`debugger-${a.id}-adapter`,category:"missing-adapter",message:`${a.name} is not installed. ${s.install}`});continue}await Ue(a.id,r.cwd,r.env,e)||o.push({id:`debugger-${a.id}-startup`,category:"adapter-startup",message:`${a.name} is installed but cannot start. ${s.install}`})}return{selections:n,actions:o}}i(He,"inspectDebuggerSetup");async function Fe(r){let e=[...new Map([...r.detectedLanguageIds].map(H).filter(t=>t!==void 0).map(t=>[t.id,t])).values()];return e.length===0?[{status:"skip",message:"No supported executable language was detected"}]:Promise.all(e.map(async t=>{let n=await he(t.id,r.cwd,r.env);return{status:n.ok?"pass":"fail",message:`${t.name}: ${n.ok?"available":"unavailable"}`,detail:n.detail}}))}i(Fe,"checkDebuggerAdapters");async function Oe(r,e,t){for(let n of r)if(!await S(n,e,t))return n}i(Oe,"firstMissingExecutable");async function Ne(r,e,t,n=process.platform){if(r==="elixir-ls-debug-adapter")try{return await j(t.PI_ELIXIR_LS_DEBUG_PATH??fe),!0}catch{return!1}if(r==="vsc-debugger")return(await y(t.PI_R_PATH??"R",["--vanilla","--quiet","-e","quit(status=if (requireNamespace('vscDebugger', quietly=TRUE)) 0 else 1)"],e,t)).ok;if(r==="vscode-js-debug")try{return await j(t.PI_JS_DEBUG_PATH??be),!0}catch{return!1}if(r.startsWith("lldb-dap"))return await S(t.PI_LLDB_DAP_PATH??(n==="win32"?"lldb-dap":"lldb-dap-18"),e,t)||await S("lldb-dap",e,t);if(r==="delve")return S(t.PI_DELVE_PATH??"dlv",e,t);if(r==="kotlin-debug-adapter")return S(t.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter",e,t);if(r==="julia-debug-adapter")try{return await j(`${t.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia"}/Project.toml`),!0}catch{return!1}if(r==="dart-debug-adapter")return S(t.PI_DART_PATH??"dart",e,t);let o=await $(e,t,n);return(await y(o.command,[...o.args,"-c","import importlib.util; raise SystemExit(importlib.util.find_spec('debugpy') is None)"],e,t)).ok}i(Ne,"adapterInstalled");async function Ue(r,e,t,n=process.platform){return(await he(r,e,t,n)).ok}i(Ue,"adapterAvailable");async function he(r,e,t,n=process.platform){if(r==="elixir-ls-debug-adapter")return L(t.PI_ELIXIR_LS_DEBUG_PATH??fe,e,t);if(r==="vsc-debugger")return y(t.PI_R_PATH??"R",["--vanilla","--quiet","-e","library(vscDebugger); cat(as.character(packageVersion('vscDebugger')))"],e,t);if(r==="dart-debug-adapter")return y(t.PI_DART_PATH??"dart",["--version"],e,t);if(r==="debugpy"){let a=await $(e,t,n);return y(a.command,[...a.args,"-c","import debugpy; print(debugpy.__version__)"],e,t)}if(r==="delve")return y(t.PI_DELVE_PATH??"dlv",["version"],e,t);if(r==="julia-debug-adapter"){let a=t.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia";return y(t.PI_JULIA_PATH??"julia",[`--project=${a}`,"--startup-file=no","-e","using DebugAdapter"],e,t)}if(r==="kotlin-debug-adapter"){let a=await y(t.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter",["--help"],e,t);return a.ok?y("java",["-version"],e,t):a}if(r==="netcoredbg"){let a=await y(t.PI_NETCOREDBG_PATH??"netcoredbg",["--version"],e,t);return a.ok?y("dotnet",["--version"],e,t):a}if(r.startsWith("lldb-dap")){let a=t.PI_LLDB_DAP_PATH??(n==="win32"?"lldb-dap":await S("lldb-dap-18",e,t)?"lldb-dap-18":"lldb-dap");return y(a,["--version"],e,t)}if(r==="rdbg")return y(t.PI_RUBY_DEBUG_PATH??"rdbg",["--version"],e,t);if(r==="vscode-php-debug"){let a=await y(t.PI_PHP_PATH??"php",["-r","exit(extension_loaded('xdebug') ? 0 : 1);"],e,t);return a.ok?L(t.PI_PHP_DEBUG_PATH??"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js",e,t):a}if(r==="local-lua-debugger"){let a=await y(t.PI_LUA_PATH??"lua",["-v"],e,t);return a.ok?L(t.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js",e,t):a}if(r==="vscode-bash-debug"){let a=await y(t.PI_BASH_PATH??"bash",["--version"],e,t);return a.ok?L(t.PI_BASH_DEBUG_PATH??"/opt/pi-debug-adapters/bash-debug/extension/out/bashDebug.js",e,t):a}if(r==="powershell-editor-services-debug"){let a=await y(t.PI_PWSH_PATH??"pwsh",["--version"],e,t),s=t.PI_POWERSHELL_EDITOR_SERVICES_PATH??"/opt/pi-debug-adapters/powershell-editor-services";return a.ok?L(`${s}/PowerShellEditorServices/Start-EditorServices.ps1`,e,t):a}let o=t.PI_JS_DEBUG_PATH??be;try{await j(o)}catch{return{ok:!1,detail:`${o} does not exist`}}return y(process.execPath,["-e","const fs=require('node:fs'); fs.accessSync(process.argv[1]); console.log(process.version)",o],e,t)}i(he,"probeAdapter");async function L(r,e,t){try{await j(r)}catch{return{ok:!1,detail:`${r} does not exist`}}return y(process.execPath,["-e","const fs=require('node:fs'); fs.accessSync(process.argv[1])",r],e,t)}i(L,"probeAdapterFile");import Me from"node:path";import{fileURLToPath as Ge}from"node:url";function ve(r){return{id:"debug-breakpoints",present(e,t){let n=r.get(t.source),o=r.sourceFile(t.source)??ye(t.source,t.cwd)??ye(e.source,t.cwd);if(o===void 0)return e;let a=r.breakpointsForFile(o,n?.source);if(a.length===0)return e;let s=Je(a);return{...e,lines:e.lines.map(d=>{let u=s.get(d.lineNumber);return u===void 0?d:{...d,presentation:{...d.presentation,suffix:`${d.presentation?.suffix??""}${We(u)}`,compactSuffix:`${d.presentation?.compactSuffix??""}${Ve(u)}`}}})}}}}i(ve,"createBreakpointPresenter");function Je(r){let e=new Map;for(let t of r){let n=e.get(t.line)??[];n.push(t),e.set(t.line,n)}return e}i(Je,"groupByLine");function ye(r,e){if(r.startsWith("file://"))return Ge(r);if(!/^[a-z][a-z\d+.-]*:/iu.test(r))return Me.resolve(e,r)}i(ye,"filesystemSource");function We(r){return r.map(e=>` ${e.verified?"\u25CF":"\u25CB"} breakpoint ${e.source} (${e.verified?"verified":"pending"})`).join("")}i(We,"renderAgentBreakpoints");function Ve(r){let t=r.filter(o=>o.verified).length===r.length?"\u25CF":"\u25CB",n=r.length===1?"breakpoint":`${r.length} breakpoints`;return` ${t} ${n}`}i(Ve,"renderUserBreakpoints");import F from"node:path";import{Text as W}from"@earendil-works/pi-tui";function V(r,e,t,n){return new W(`${n.fg("toolTitle",r)} ${n.fg("muted",`\xB7 ${Ee(e,t)}`)}
2
+ ${n.fg("accent","\u25C6 configure debugger")}`,0,0)}i(V,"renderDebugCall");function we(r,e,t){return new W(`${Pe(r,t)}
3
+ ${t.fg("accent",Ke(e))}`,0,0)}i(we,"renderDebugActionCall");function q(r,e,t,n){let o=ze(r,e,t);return n!==void 0&&o.unshift(`${t.fg("accent",n.expression)} ${t.fg("muted","=")} ${t.fg("toolOutput",n.result)}${n.type===void 0?"":t.fg("dim",` ${n.type}`)}`),new W(o.join(`
4
+ `),0,0)}i(q,"renderDebugResult");function De(r,e){let t=[Pe(r,e),Se(r.status,e)];return r.stop?.frame!==void 0&&t.push(` ${e.fg("warning","\u25CF")} ${r.stop.frame.name} ${e.fg("muted",`\xB7 ${ke(r.stop)}`)}`),t}i(De,"renderActiveDebugger");function ze(r,e,t){let n=[];if(r.status==="stopped"&&r.stop!==void 0){n.push(t.fg("warning",`\u25CF stopped \xB7 ${r.stop.reason}`),t.fg("text",`${r.stop.frame?.name??"unknown frame"} ${t.fg("muted",`\xB7 ${ke(r.stop)}`)}`));for(let a of r.stop.sourceLines){let s=a.current?t.fg("warning",">"):t.fg("dim","\u2502"),d=a.current?"text":"dim";n.push(`${s} ${String(a.lineNumber).padStart(4)} ${t.fg(d,a.content)}`)}let o=e?r.stop.variables:r.stop.variables.slice(0,6);if(o.length>0){n.push(t.fg("muted","Locals"));for(let a of o)n.push(` ${t.fg("accent",a.name.padEnd(16))} ${t.fg("toolOutput",a.value)}${a.type===void 0?"":t.fg("dim",` ${a.type}`)}`);o.length<r.stop.variables.length&&n.push(t.fg("muted",` \u2026 ${r.stop.variables.length-o.length} more`))}return n}if(n.push(Se(r.status,t)),r.breakpoints.length>0){let o=r.breakpoints.filter(a=>a.verified).length;n.push(t.fg("muted",`${r.breakpoints.length} breakpoint${r.breakpoints.length===1?"":"s"} \xB7 ${o} verified`))}return n}i(ze,"debugResultLines");function Pe(r,e){return`${e.fg("toolTitle",r.options.adapter)} ${e.fg("muted",`\xB7 ${Ee(r.options.program,r.options.cwd)}`)}`}i(Pe,"debugIdentity");function Ke(r){let e=r.trim().toLowerCase();return e==="start"?"\u25B6 start debugging":e==="continue"?"\u25B6 continue":e==="step over"?"\u21B7 step over":e==="step into"?"\u2193 step into":e==="step out"?"\u2191 step out":e.startsWith("evaluate ")?`\u25C6 ${r.trim().slice(9)}`:e.startsWith("breakpoint ")?`\u25CF add ${e}`:e.startsWith("delete-breakpoint ")?`\u25CB remove breakpoint \xB7 ${e.slice(18)}`:e==="breakpoint"?"\u25CF add breakpoint":e==="delete-breakpoint"?"\u25CB remove breakpoint":e==="delete-session"?"\u25A0 stop debugging":e}i(Ke,"actionLabel");function Se(r,e){return r==="configured"?e.fg("muted","\u25C7 ready"):r==="running"?e.fg("accent","\u25CF running"):r==="stopped"?e.fg("warning","\u25CF stopped"):e.fg("success","\u25A0 stopped debugging")}i(Se,"statusLine");function ke(r){let e=r.frame?.source?.path??r.frame?.source?.name??"unknown";return`${F.basename(e)}:${r.frame?.line??"?"}`}i(ke,"shortFrame");function Ee(r,e){let t=F.relative(e,r),n=".".repeat(2),o=t===n||t.startsWith(`${n}${F.sep}`);return t.length>0&&!o?t:F.basename(r)}i(Ee,"shortPath");function z(r){let e=_e(r);if(e===void 0)return;let t=e.snapshot;return typeof t=="object"&&t!==null?t:void 0}i(z,"debuggerSnapshotFromResult");function xe(r){let e=_e(r);if(e===void 0)return;let t=e.evaluation;if(!(typeof t!="object"||t===null||!("expression"in t)||typeof t.expression!="string"||!("result"in t)||typeof t.result!="string"||!("variablesReference"in t)||typeof t.variablesReference!="number"))return{expression:t.expression,result:t.result,variablesReference:t.variablesReference,..."type"in t&&typeof t.type=="string"?{type:t.type}:{}}}i(xe,"debuggerEvaluationFromResult");function _e(r){if(typeof r!="object"||r===null)return;let e=r.metadata;if(typeof e!="object"||e===null)return;let t=e.semanticAction;return typeof t=="object"&&t!==null?t:void 0}i(_e,"semanticActionFromResult");function Re(r){return{id:"debugger",onDidChange:i(e=>r.onDidChange(e),"onDidChange"),list:i(()=>r.list().map(e=>r.snapshot(e)).filter(e=>e.status==="configured"||e.status==="running"||e.status==="stopped").map(e=>({source:e.source,kind:"debugger",title:e.options.adapter,description:e.options.program,status:e.status==="configured"?"configured":e.status==="stopped"?"paused":"running",renderSummary:i(t=>De(e,t),"renderSummary"),renderDetail:i(t=>q(e,!0,t),"renderDetail"),stop:i(()=>r.delete(e.source),"stop")})),"list")}}i(Re,"debuggerProcessProvider");import C from"cross-spawn";import{randomBytes as Ae}from"node:crypto";import{rmSync as Ze}from"node:fs";import{mkdtemp as Qe,readFile as Be,rm as et}from"node:fs/promises";import Le from"node:net";import{tmpdir as tt}from"node:os";import v from"node:path";import Xe from"cross-spawn";import Ye from"node:net";var k=class r{static{i(this,"DapClient")}#a;#u;#l;#o=new Map;#b=[];#i=new Set;#f=new Set;#r=Buffer.alloc(0);#p=1;#s;#g;#n;constructor(e,t,n){this.#a=e,this.#u=t,this.#l=n,e.on("data",o=>this.#t(o)),e.once("error",o=>this.#c(o)),e.once("close",()=>this.#c(new Error("Debug adapter connection closed"))),n!==void 0&&(n.stderr.on("data",o=>{process.env.PI_DEBUG_DAP_TRACE==="1"&&process.stderr.write(o)}),n.once("error",o=>this.#c(o)),n.once("exit",(o,a)=>{this.#c(new Error(`Debug adapter exited${o===null?"":` with code ${o}`}${a===null?"":` (${a})`}`))}))}static start(e,t,n){let a=Xe(e,[...t],{cwd:n,env:process.env,stdio:["pipe","pipe","pipe"]});return new r(a.stdout,a.stdin,a)}static fromSocket(e,t=1){let n=new r(e,e);return n.#p=t,n}static connect(e,t="127.0.0.1"){return new Promise((n,o)=>{let a=Ye.createConnection({port:e,host:t}),s=i(d=>o(d),"fail");a.once("error",s),a.once("connect",()=>{a.off("error",s),n(new r(a,a))})})}onReverseRequest(e){this.#g=e}onEvent(e){return this.#f.add(e),()=>this.#f.delete(e)}request(e,t,n={}){if(this.#s!==void 0)return Promise.reject(this.#s);if(n.signal?.aborted===!0)return Promise.reject(n.signal.reason instanceof Error?n.signal.reason:new Error("Debug operation aborted"));["continue","next","stepIn","stepOut"].includes(e)&&(this.#n=void 0);let o=this.#p++,a={seq:o,type:"request",command:e,...t===void 0?{}:{arguments:t}},s=new Promise((d,u)=>{let c,l=i(()=>{c!==void 0&&clearTimeout(c),n.signal?.removeEventListener("abort",p)},"cleanup"),p=i(()=>{this.#o.delete(o),l(),u(n.signal?.reason instanceof Error?n.signal.reason:new Error("Debug operation aborted"))},"abort");n.timeoutMs!==void 0&&(c=setTimeout(()=>{this.#o.delete(o),l(),u(new Error(`Timed out waiting for debug response ${e}`))},n.timeoutMs)),this.#o.set(o,{resolve:i(f=>d(f),"resolve"),reject:u,cleanup:l}),n.signal?.addEventListener("abort",p,{once:!0})});return this.#d(a),s}waitForEvent(e,t=3e4){return this.waitForAnyEvent([e],t)}waitForAnyEvent(e,t=3e4,n){let o=new Set(e),a=this.#b.findIndex(s=>o.has(s.event));return a>=0?Promise.resolve(this.#b.splice(a,1)[0]):this.#s!==void 0?Promise.reject(this.#s):new Promise((s,d)=>{let u={events:o,resolve:i(l=>{clearTimeout(u.timer),this.#i.delete(u),s(l)},"resolve"),reject:i(l=>{clearTimeout(u.timer),this.#i.delete(u),d(l)},"reject"),timer:setTimeout(()=>{this.#i.delete(u),d(new Error(`Timed out waiting for debug event ${e.join(" or ")}`))},t)};this.#i.add(u);let c=i(()=>u.reject(n?.reason instanceof Error?n.reason:new Error("Debug operation aborted")),"abort");n?.aborted===!0?c():n?.addEventListener("abort",c,{once:!0})})}close(){this.#a.destroy(),this.#u.destroy(),this.#l!==void 0&&!this.#l.killed&&this.#l.kill(),this.#c(new Error("Debug adapter closed"))}#d(e){let t=Buffer.from(JSON.stringify(e),"utf8");this.#u.write(Buffer.concat([Buffer.from(`Content-Length: ${t.length}\r
5
+ \r
6
+ `),t]))}#t(e){for(this.#r=Buffer.concat([this.#r,e]);;){let t=this.#r.indexOf(`\r
7
+ \r
8
+ `);if(t<0)return;let n=this.#r.subarray(0,t).toString("ascii"),o=/^Content-Length:\s*(\d+)$/imu.exec(n);if(o===null){this.#c(new Error("Debug adapter sent a frame without Content-Length"));return}let a=Number(o[1]),s=t+4;if(this.#r.length<s+a)return;let d=this.#r.subarray(s,s+a).toString("utf8");this.#r=this.#r.subarray(s+a);try{this.#m(JSON.parse(d))}catch(u){this.#c(u instanceof Error?u:new Error(String(u)));return}}}#m(e){if(e.type==="event")if(e.event==="stopped"){let t=JSON.stringify(e.body??null);if(t===this.#n)return;this.#n=t}else e.event==="continued"&&(this.#n=void 0);if(e.type==="response"){let t=this.#o.get(e.request_seq);if(t===void 0)return;this.#o.delete(e.request_seq),t.cleanup(),e.success?t.resolve(e.body):t.reject(new Error(`${e.command}: ${e.message??"failed"}`));return}if(e.type==="event"){for(let n of this.#f)n(e);let t=[...this.#i].find(n=>n.events.has(e.event));t===void 0?this.#b.push(e):t.resolve(e);return}this.#e(e)}async#e(e){try{if(this.#g===void 0)throw new Error(`Client does not support reverse request ${e.command}`);let t=await this.#g(e);this.#d({seq:this.#p++,type:"response",request_seq:e.seq,success:!0,command:e.command,...t===void 0?{}:{body:t}})}catch(t){this.#d({seq:this.#p++,type:"response",request_seq:e.seq,success:!1,command:e.command,message:t instanceof Error?t.message:String(t)})}}#c(e){if(this.#s===void 0){this.#s=e;for(let t of this.#o.values())t.cleanup(),t.reject(e);this.#o.clear();for(let t of this.#i)t.reject(e);this.#i.clear()}}};var N=class{static{i(this,"DebugSessionManager")}#a=new Map;#u=new Set;create(e){let t=Ae(6).toString("hex"),n={id:t,source:`debug:${t}`,options:{...e,sourceFile:e.sourceFile??e.program},breakpoints:new Map,status:"configured",stopGeneration:0};return this.#a.set(t,n),this.#e(n),n}get(e){let t=/^debug:([a-f\d]{12})(?:\/|$)/u.exec(e);return t===null?void 0:this.#a.get(t[1])}list(){return[...this.#a.values()]}snapshot(e){return{id:e.id,source:e.source,options:e.options,status:e.status,breakpoints:[...e.breakpoints.values()].map(t=>({...t})),...e.stop===void 0?{}:{stop:e.stop}}}onDidChange(e){return this.#u.add(e),()=>this.#u.delete(e)}breakpointsForFile(e,t){return this.list().filter(n=>t===void 0||n.source===t).flatMap(n=>[...n.breakpoints.values()]).filter(n=>I(n.file,e))}sourceFile(e){let t=this.get(e);return t!==void 0&&e===`${t.source}/source`?t.options.sourceFile:void 0}sourceResource(e){return`${e.source}/source`}readSource(e){let t=this.sourceFile(e);return t===void 0?Promise.reject(new Error(`Unknown debug source ${e}`)):Be(t,"utf8")}async addBreakpoint(e,t,n){let o=this.get(e),a=this.sourceFile(e);if(o===void 0||a===void 0)throw new Error(`Unknown debug source ${e}`);if(o.status==="terminated")throw new Error("Cannot add a breakpoint to a terminated session");let s=Ae(5).toString("hex"),d={id:s,source:`${o.source}/breakpoint/${s}`,file:a,line:t,verified:!1};return o.breakpoints.set(s,d),o.client!==void 0&&await this.#d(o,o.client,a,n),this.#e(o),d}breakpoint(e){let t=this.get(e);return t===void 0?void 0:[...t.breakpoints.values()].find(n=>n.source===e)}async start(e,t){return this.#l(e,t,2)}async#l(e,t,n){if(e.status!=="configured")throw new Error(`Session is already ${e.status}`);e.options.adapter==="powershell"&&(e.adapterTemporaryDirectory=await Qe(v.join(tt(),"pi-powershell-debug-")));let o=await st(e.options,e.adapterTemporaryDirectory),a=e.options.adapter==="node"?await this.#s(e):e.options.adapter==="delve"?await this.#b(e):e.options.adapter==="ruby"?await this.#o(e):e.options.adapter==="julia"?await this.#i(e):e.options.adapter==="r"?await this.#f(e):k.start(o.command,o.args,e.options.cwd);e.client=a,e.controlClient=a,e.clients=[a],e.options.adapter==="node"&&(e.targetReady=new Promise(s=>{e.resolveTargetReady=s})),e.status="running",this.#e(e);try{e.options.adapter!=="r"&&await Te(a,o.adapterID,t);let s=a.waitForAnyEvent(["initialized"],3e4,t),d=a.request(o.request,o.launch,{signal:t});await s,await this.#n(e,a,t);let u=a.request("configurationDone",void 0,{signal:t});if(e.options.adapter==="java"||e.options.adapter==="kotlin"?u.catch(()=>{}):await u,await d,e.options.adapter==="r"&&(e.rStarted=!0),e.targetReady!==void 0&&await e.targetReady,await this.#t(e,t),this.snapshot(e).status==="terminated"&&n>0&&(e.options.adapter==="dart"||e.options.adapter==="kotlin")&&e.breakpoints.size>0){for(let c of e.clients??[a])c.close();e.adapterProcess?.kill(),await X(e),e.client=void 0,e.controlClient=void 0,e.clients=void 0,e.adapterProcess=void 0,e.status="configured";for(let c of e.breakpoints.values())c.verified=!1;return this.#e(e),await this.#l(e,t,n-1)}return e}catch(s){for(let d of e.clients??[a])d.close();throw e.adapterProcess?.kill(),await X(e),e.client=void 0,e.controlClient=void 0,e.clients=void 0,e.adapterProcess=void 0,e.targetReady=void 0,e.resolveTargetReady=void 0,e.status="configured",this.#e(e),s}}async command(e,t,n){if(e.status!=="stopped"||e.stop===void 0)throw new Error(`Cannot ${t} while session is ${e.status}`);let o=E(e),a=e.stop.threadId;return await o.request(t,{threadId:a},{signal:n}),e.stop=void 0,e.status="running",this.#e(e),await this.#t(e,n),e}async evaluate(e,t,n){if(e.status!=="stopped"||e.stop?.frame===void 0)throw new Error(`Cannot evaluate while session is ${e.status}`);let o=t.trim();if(o.length===0)throw new Error("Debug evaluation requires an expression");let a=await E(e).request("evaluate",{expression:o,frameId:e.stop.frame.id,context:"repl"},{signal:n});if(typeof a.result!="string")throw new Error("Debug adapter returned no evaluation result");return{expression:o,result:a.result,variablesReference:a.variablesReference??0,...a.type===void 0?{}:{type:a.type}}}async delete(e,t){let n=this.get(e);if(n===void 0)throw new Error(`Unknown debug session ${e}`);let o=/\/breakpoint\/([a-f\d]{10})$/u.exec(e);if(o!==null){let a=n.breakpoints.get(o[1]);if(a===void 0)throw new Error(`Unknown debug breakpoint ${e}`);n.breakpoints.delete(a.id),n.client!==void 0&&n.status!=="terminated"&&await this.#d(n,n.client,a.file,t),this.#e(n);return}if(e!==n.source)throw new Error(`Cannot delete debug resource ${e}`);if(n.client!==void 0){(n.controlClient??n.client).request("disconnect",{terminateDebuggee:!0},{signal:t,timeoutMs:500}).catch(()=>{});for(let a of n.clients??[n.client])a.close()}await Ce(n.adapterProcess),await X(n),n.status="terminated",this.#e(n),this.#a.delete(n.id)}dispose(){for(let e of this.#a.values()){for(let t of e.clients??(e.client===void 0?[]:[e.client]))t.close();Ce(e.adapterProcess),e.adapterTemporaryDirectory!==void 0&&Ze(e.adapterTemporaryDirectory,{recursive:!0,force:!0})}this.#a.clear()}async#o(e){let t=await O(),n=process.env.PI_RUBY_DEBUG_PATH??"rdbg";return e.adapterProcess=C(n,["--open","--host","127.0.0.1","--port",String(t),"--no-rc","--",e.options.program,...e.options.args],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),K(e.adapterProcess,`rdbg:${String(t)}`),await Ie(e.adapterProcess,"Debugger can attach via TCP/IP","rdbg"),k.connect(t)}async#b(e){let t=await O(),n=process.env.PI_DELVE_PATH??"dlv";return e.adapterProcess=C(n,["dap",`--listen=127.0.0.1:${String(t)}`,"--log=false"],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),e.adapterProcess.stderr?.on("data",()=>{}),await Ie(e.adapterProcess,"DAP server listening","Delve"),k.connect(t)}async#i(e){let t=await O(),n=process.env.PI_JULIA_PATH??"julia",o=process.env.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia",a='using Sockets, DebugAdapter; server = listen(ip"127.0.0.1", parse(Int, ARGS[1])); conn = accept(server); run(DebugAdapter.DebugSession(conn)); close(server)';return e.adapterProcess=C(n,["--startup-file=no","--history-file=no",`--project=${o}`,"-e",a,String(t)],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),K(e.adapterProcess,`DebugAdapter.jl:${String(t)}`),await new Promise(s=>setTimeout(s,25)),$e(t,"DebugAdapter.jl")}async#f(e){let t=Le.createServer();await new Promise((d,u)=>{t.once("error",u),t.listen(0,"127.0.0.1",()=>d())});let n=t.address();if(n===null||typeof n=="string")throw t.close(),new Error("Could not start the vscDebugger DAP listener");let o=new Promise((d,u)=>{t.once("connection",c=>{t.close();let l=k.fromSocket(c,2);l.onEvent(p=>this.#r(e,p)),d(l)}),t.once("error",u)}),a=process.env.PI_R_PATH??"R";e.rPromptInputs=[],e.rAtBrowserPrompt=!1,e.rStarted=!1,e.adapterProcess=C(a,["--vanilla","--quiet"],{cwd:e.options.cwd,env:process.env,stdio:["pipe","pipe","pipe"]}),K(e.adapterProcess,`vscDebugger:${String(n.port)}`),this.#p(e);let s=at({seq:1,type:"request",command:"initialize",arguments:{clientID:"pi-agent-ide",adapterID:"R-Debugger",pathFormat:"path",linesStartAt1:!0,columnsStartAt1:!0,supportsVariableType:!0,supportsVariablePaging:!0,supportsWriteToStdinEvent:!0,supportsStdoutReading:!0,rStrings:{packageName:"vscDebugger",prompt:"__PI_R_PROMPT__",continue:"__PI_R_CONTINUE__",attachName:"tools:vscDebugger"},useDapSocket:!0,dapHost:"127.0.0.1",dapPort:n.port}});return e.adapterProcess.stdin?.write(`library(vscDebugger); vscDebugger:::.vsc.handleDap(${JSON.stringify(s)})
9
+ `),ot(o,e.adapterProcess,t)}#r(e,t){if(process.env.PI_DEBUG_DAP_TRACE==="1"&&process.stderr.write(`[vscDebugger:event] ${JSON.stringify(t)}
10
+ `),t.event!=="custom")return;let n=R(t.body),o=typeof n.reason=="string"?n.reason:"",a=typeof n.text=="string"?n.text:"";if(!(o!=="writeToStdin"||a.length===0)){if(n.when==="browserPrompt"&&e.rAtBrowserPrompt===!0){e.rAtBrowserPrompt=!1,e.adapterProcess?.stdin?.write(`${a}
11
+ `);return}e.rPromptInputs?.push(a)}}#p(e){let t="";e.adapterProcess?.stdout?.on("data",n=>{for(t+=n.toString("utf8");;){let o=/Browse\[\d+\]> /u.exec(t),a=/(?:^|\r?\n)__PI_R_PROMPT__(?:\r?\n|$)/u.exec(t),s=o?.index??Number.POSITIVE_INFINITY,d=a?.index??Number.POSITIVE_INFINITY;if(!Number.isFinite(s)&&!Number.isFinite(d)){t=t.slice(-128);return}if(s<d){t=t.slice(s+(o?.[0].length??0));let u=e.rPromptInputs?.shift();u===void 0?(e.rAtBrowserPrompt=!0,setTimeout(()=>{e.rAtBrowserPrompt===!0&&(e.rAtBrowserPrompt=!1,e.adapterProcess?.stdin?.write(`vscDebugger::.vsc.listenForDAP(timeout=-1)
12
+ `))},100)):e.adapterProcess?.stdin?.write(`${u}
13
+ `)}else t=t.slice(d+(a?.[0].length??0)),e.adapterProcess?.stdin?.write(`vscDebugger::.vsc.listenForDAP(timeout=-1)
14
+ `),e.rStarted===!0&&e.client?.request("custom",{reason:"showingPrompt",which:"topLevel"}).catch(()=>{})}})}async#s(e){let t=await O(),n=process.env.PI_JS_DEBUG_PATH??"/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js";e.adapterProcess=C(process.execPath,[n,String(t),"127.0.0.1"],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),e.adapterProcess.stderr?.on("data",()=>{}),await it(e.adapterProcess);let o=await $e(t);return o.onReverseRequest(this.#g(e,t)),o}#g(e,t){return async n=>{if(n.command!=="startDebugging")throw new Error(`Client does not support reverse request ${n.command}`);let o=R(n.arguments),a=R(o.configuration),s=await k.connect(t);e.clients?.push(s),s.onReverseRequest(this.#g(e,t)),await Te(s,"pwa-node");let d=s.waitForEvent("initialized"),u=s.request(typeof o.request=="string"?o.request:"launch",{...a,sourceMaps:!0,pauseForSourceMap:!0,outFiles:[v.join(v.dirname(e.options.program),"**","*.js")]});return await d,e.client=s,await this.#n(e,s),await s.request("configurationDone"),await u,e.resolveTargetReady?.(),{}}}async#n(e,t,n){let o=new Set([...e.breakpoints.values()].map(a=>a.file));for(let a of o)await this.#d(e,t,a,n)}async#d(e,t,n,o){let a=[...e.breakpoints.values()].filter(d=>d.file===n),s=await t.request("setBreakpoints",{source:{path:n,name:v.basename(n)},breakpoints:a.map(({line:d})=>({line:d})),sourceModified:!1},{signal:o});for(let[d,u]of a.entries())u.verified=s.breakpoints?.[d]?.verified===!0}async#t(e,t){let n=await E(e).waitForAnyEvent(["stopped","terminated","exited","loadedSource","breakpoint","custom"],3e4,t),o=R(n.body);if(n.event==="custom"&&e.options.adapter==="r"){await this.#t(e,t);return}if(n.event==="loadedSource"){let a=R(o.source),s=typeof a.path=="string"?v.resolve(a.path):void 0,d=s===void 0?void 0:[...e.breakpoints.values()].find(u=>I(u.file,s))?.file;d!==void 0&&await this.#d(e,E(e),d,t),await this.#t(e,t);return}if(n.event==="breakpoint"){let a=R(o.breakpoint),s=R(a.source);for(let d of e.breakpoints.values())a.verified===!0&&typeof a.line=="number"&&a.line===d.line&&typeof s.path=="string"&&I(s.path,d.file)&&(d.verified=!0);await this.#t(e,t);return}if(o.reason==="exit"){e.status="terminated",e.stop=void 0,this.#e(e);return}if(e.options.adapter==="node"&&o.reason==="entry"){await this.#n(e,E(e),t);let a=typeof o.threadId=="number"?o.threadId:1;await E(e).request("continue",{threadId:a},{signal:t}),await this.#t(e,t);return}if((e.options.adapter==="dart"||e.options.adapter==="kotlin")&&o.reason==="entry"){let a=E(e);if(await this.#n(e,a,t),e.options.adapter==="kotlin"){let d=Date.now()+5e3;for(;[...e.breakpoints.values()].some(u=>!u.verified)&&Date.now()<d;)await new Promise(u=>setTimeout(u,50)),await this.#n(e,a,t)}let s=typeof o.threadId=="number"?o.threadId:1;await a.request("continue",{threadId:s},{signal:t}),await this.#t(e,t);return}if(n.event!=="stopped"){e.status="terminated",e.stop=void 0,this.#e(e);return}if(await this.#m(e,n,e.options.adapter!=="shell"),e.options.adapter==="r"&&e.stop?.frame?.source?.path===void 0){e.stopGeneration--,e.stop=void 0,e.status="running",await this.#t(e,t);return}if(e.options.adapter==="shell"&&e.stop?.frame!==void 0&&![...e.breakpoints.values()].some(a=>I(a.file,e.stop?.frame?.source?.path??"")&&a.line===e.stop?.frame?.line)){let a=e.stop.threadId;e.stopGeneration--,e.stop=void 0,e.status="running",await E(e).request("continue",{threadId:a},{signal:t}),await this.#t(e,t);return}e.options.adapter==="shell"&&this.#e(e)}async#m(e,t,n=!0){let o=E(e),a=R(t.body),s=(await o.request("threads")).threads?.[0]?.id,d=typeof a.threadId=="number"?a.threadId:s;if(d===void 0)throw new Error("Debugger stopped without a thread");let u=(await nt(o,d,e.options.adapter==="dart")).stackFrames?.[0];if(u?.source?.path!==void 0)for(let l of e.breakpoints.values())I(l.file,u.source.path)&&l.line===u.line&&(l.verified=!0);let c=[];if(u!==void 0){let l=(await o.request("scopes",{frameId:u.id})).scopes??[],p=e.options.adapter==="r"?l:l.filter(f=>[f.name.toLowerCase(),f.presentationHint?.toLowerCase()].some(g=>g?.includes("local")===!0||g==="variables"));for(let f of p){let g=await o.request("variables",{variablesReference:f.variablesReference,start:0,count:100});c.push(...g.variables??[])}}e.stopGeneration++,e.stop={generation:e.stopGeneration,reason:typeof a.reason=="string"?a.reason:"stopped",threadId:d,...u===void 0?{}:{frame:u},variables:c,sourceLines:u===void 0?[]:await rt(u)},e.status="stopped",n&&this.#e(e)}#e(e){let t=this.snapshot(e);for(let n of this.#u)n(t)}};async function rt(r){let e=r.source?.path;if(e===void 0)return[];try{let t=(await Be(e,"utf8")).split(/\r?\n/u),n=Math.max(1,r.line-2),o=Math.min(t.length,r.line+2);return t.slice(n-1,o).map((a,s)=>({lineNumber:n+s,content:a,current:n+s===r.line}))}catch{return[]}}i(rt,"sourceWindow");async function nt(r,e,t){let n=Date.now()+1e3,o;do{try{let a=await r.request("stackTrace",{threadId:e});if(!t||(a.stackFrames?.length??0)>0)return a;o=new Error("Debugger stack is not ready")}catch(a){if(o=a,!t)throw a}await new Promise(a=>setTimeout(a,25))}while(Date.now()<n);throw o instanceof Error?o:new Error("Could not read debugger stack")}i(nt,"requestStackTrace");function U(r){let e=[`Session: ${r.source}`,`Adapter: ${r.options.adapter}`,`Program: ${v.relative(r.options.cwd,r.options.program)||r.options.program}`,`Status: ${r.status}`];if(r.breakpoints.size>0){e.push("","Breakpoints:");for(let t of r.breakpoints.values())e.push(`- ${t.source} ${v.relative(r.options.cwd,t.file)}:${t.line} (${t.verified?"verified":"pending"})`)}if(r.stop!==void 0){let{stop:t}=r;if(e.push("",`Stop: ${t.generation} (${t.reason})`,`Thread: ${t.threadId}`),t.frame!==void 0&&e.push(`Frame: ${t.frame.name} at ${t.frame.source?.path??t.frame.source?.name??"unknown"}:${t.frame.line}`),t.variables.length>0){e.push("","Locals:");for(let n of t.variables)e.push(`- ${n.name}: ${n.value}${n.type===void 0?"":` (${n.type})`}`)}}return e.join(`
15
+ `)}i(U,"renderDebugSession");function E(r){if(r.client===void 0)throw new Error("Debug adapter is not running");return r.client}i(E,"requiredClient");function R(r){return typeof r=="object"&&r!==null?r:{}}i(R,"asRecord");function at(r){let e=JSON.stringify(r);return`Content-Length: ${Buffer.byteLength(e,"utf8")}\r
16
+ \r
17
+ ${e}`}i(at,"dapFrame");function Te(r,e,t){return r.request("initialize",{clientID:"pi-agent-ide",adapterID:e,pathFormat:"path",linesStartAt1:!0,columnsStartAt1:!0,supportsVariableType:!0,supportsVariablePaging:!0,supportsRunInTerminalRequest:!1,supportsStartDebuggingRequest:!0},{signal:t})}i(Te,"initializeClient");function O(){return new Promise((r,e)=>{let t=Le.createServer();t.once("error",e),t.listen(0,"127.0.0.1",()=>{let n=t.address();if(n===null||typeof n=="string"){t.close(),e(new Error("Could not allocate a debug adapter port"));return}t.close(o=>o===void 0?r(n.port):e(o))})})}i(O,"availablePort");function K(r,e){if(process.env.PI_DEBUG_DAP_TRACE==="1"){process.stderr.write(`[${e}] pid=${String(r.pid)}
18
+ `),r.once("exit",(t,n)=>process.stderr.write(`[${e}] exit code=${String(t)} signal=${String(n)}
19
+ `));for(let t of[r.stdout,r.stderr])t?.on("data",n=>process.stderr.write(`[${e}] ${n.toString("utf8")}`))}}i(K,"traceAdapterProcess");function ot(r,e,t){return new Promise((n,o)=>{let a=setTimeout(()=>d(new Error("Timed out starting vscDebugger")),5e3),s=i(()=>{clearTimeout(a),e.off("error",d),e.off("exit",u)},"cleanup"),d=i(c=>{s(),t.close(),e.killed||e.kill(),o(c)},"fail"),u=i(c=>d(new Error(`vscDebugger exited with code ${String(c)} before connecting`)),"onExit");e.once("error",d),e.once("exit",u),r.then(c=>{s(),n(c)},d)})}i(ot,"waitForRAdapterConnection");function Ie(r,e,t){return new Promise((n,o)=>{let a=[r.stdout,r.stderr].filter(c=>c!==null),s=setTimeout(()=>o(new Error(`Timed out starting ${t} server`)),process.platform==="win32"?15e3:5e3),d=i(()=>{clearTimeout(s);for(let c of a)c.off("data",u)},"cleanup"),u=i(c=>{c.toString("utf8").includes(e)&&(d(),n())},"onData");for(let c of a)c.on("data",u);r.once("error",c=>{d(),o(c)}),r.once("exit",c=>{d(),o(new Error(`${t} server exited with code ${String(c)}`))})})}i(Ie,"waitForAdapterReady");function it(r){return new Promise((e,t)=>{let n=r.stdout;if(n===null){t(new Error("js-debug server stdout is unavailable"));return}let o=setTimeout(()=>t(new Error("Timed out starting js-debug server")),5e3),a=i(s=>{s.toString("utf8").includes("Debug server listening")&&(clearTimeout(o),n.off("data",a),e())},"onData");n.on("data",a),r.once("error",t),r.once("exit",s=>t(new Error(`js-debug server exited with code ${s}`)))})}i(it,"waitForJsDebugReady");async function $e(r,e="js-debug"){let t;for(let n=0;n<100;n++)try{return await k.connect(r)}catch(o){t=o,await new Promise(a=>setTimeout(a,25))}throw t instanceof Error?t:new Error(`Could not connect to ${e}`)}i($e,"connectWithRetry");async function X(r){r.adapterTemporaryDirectory!==void 0&&(await et(r.adapterTemporaryDirectory,{recursive:!0,force:!0,maxRetries:process.platform==="win32"?10:0,retryDelay:100}),r.adapterTemporaryDirectory=void 0)}i(X,"removeAdapterTemporaryDirectory");async function Ce(r){if(!(r===void 0||r.exitCode!==null||r.signalCode!==null)){if(process.platform!=="win32"||r.pid===void 0){r.kill();return}await new Promise(e=>{let t=C("taskkill.exe",["/pid",String(r.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0});t.once("error",()=>{r.kill(),e()}),t.once("exit",()=>e())})}}i(Ce,"terminateOwnedAdapterProcess");async function st(r,e){let t={name:"Pi Agent IDE debug session",request:"launch",program:r.program,cwd:r.cwd,args:[...r.args]};if(r.adapter==="dart")return{command:process.env.PI_DART_PATH??"dart",args:["debug_adapter"],adapterID:"dart",request:"launch",launch:{...t,type:"dart",debugSdkLibraries:!1,debugExternalPackageLibraries:!1,stopOnEntry:!0,vmAdditionalArgs:["--pause-isolates-on-start"]}};if(r.adapter==="debugpy"){let n=await $(r.cwd);return{command:n.command,args:[...n.args,"-m","debugpy.adapter"],adapterID:"debugpy",request:"launch",launch:{...t,type:"python",console:"internalConsole",justMyCode:!1}}}if(r.adapter==="java"||r.adapter==="kotlin"){if(r.mainClass===void 0)throw new Error("Java and Kotlin debug sessions require mainClass");return{command:process.env.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter",args:[],adapterID:r.adapter,request:"launch",launch:{...t,type:"kotlin",mainClass:r.mainClass,projectRoot:r.cwd,stopOnEntry:!0}}}if(r.adapter==="netcoredbg")return{command:process.env.PI_NETCOREDBG_PATH??"netcoredbg",args:["--interpreter=vscode"],adapterID:"coreclr",request:"launch",launch:{...t,type:"coreclr",console:"internalConsole"}};if(r.adapter==="elixir")return{command:process.env.PI_ELIXIR_LS_DEBUG_PATH??(process.platform==="win32"?"debug_adapter.bat":"/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh"),args:[],adapterID:"mix_task",request:"launch",launch:{name:t.name,request:"launch",type:"mix_task",task:"run",taskArgs:[r.program,...r.args],projectDir:r.cwd,startApps:!0,exitAfterTaskReturns:!0}};if(r.adapter==="julia")return{command:process.env.PI_JULIA_PATH??"julia",args:[],adapterID:"julia",request:"launch",launch:{...t,type:"julia",stopOnEntry:!1}};if(r.adapter==="lldb-dap")return{command:v.extname(r.sourceFile).toLowerCase()===".swift"?process.env.PI_SWIFT_LLDB_DAP_PATH??process.env.PI_LLDB_DAP_PATH??"lldb-dap":process.env.PI_LLDB_DAP_PATH??(process.platform==="win32"?"lldb-dap":"lldb-dap-18"),args:[],adapterID:"lldb-dap",request:"launch",launch:{...t,type:"lldb-dap"}};if(r.adapter==="delve")return{command:process.env.PI_DELVE_PATH??"dlv",args:[],adapterID:"go",request:"launch",launch:{...t,type:"go",mode:"debug"}};if(r.adapter==="r")return{command:process.env.PI_R_PATH??"R",args:[],adapterID:"R-Debugger",request:"launch",launch:{name:t.name,request:"launch",type:"R-Debugger",debugMode:"file",file:r.program,workingDirectory:r.cwd,commandLineArgs:[...r.args],allowGlobalDebugging:!1,loadPackages:[],supportsStdoutReading:!0,supportsWriteToStdinEvent:!0,overwriteHelp:!1}};if(r.adapter==="ruby")return{command:process.env.PI_RUBY_DEBUG_PATH??"rdbg",args:[],adapterID:"rdbg",request:"launch",launch:{...t,type:"rdbg"}};if(r.adapter==="php")return{command:process.execPath,args:[process.env.PI_PHP_DEBUG_PATH??"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js"],adapterID:"php",request:"launch",launch:{...t,type:"php",runtimeExecutable:process.env.PI_PHP_PATH??"php",runtimeArgs:["-dxdebug.start_with_request=yes"],console:"internalConsole",port:0,env:{XDEBUG_MODE:"debug,develop",XDEBUG_CONFIG:"client_port=${port}"}}};if(r.adapter==="lua")return{command:process.execPath,args:[process.env.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js"],adapterID:"lua-local",request:"launch",launch:{...t,type:"lua-local",program:{lua:process.env.PI_LUA_PATH??"lua",file:r.program},extensionPath:v.dirname(v.dirname(process.env.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js")),workspacePath:r.cwd}};if(r.adapter==="shell"){let n=process.env.PI_BASH_DEBUG_ROOT??"/opt/pi-debug-adapters/bash-debug/extension";return{command:process.execPath,args:[process.env.PI_BASH_DEBUG_PATH??v.join(n,"out/bashDebug.js")],adapterID:"bashdb",request:"launch",launch:{...t,type:"bashdb",pathBash:process.env.PI_BASH_PATH??"/usr/bin/bash",pathBashdb:v.join(n,"bashdb_dir/bashdb"),pathBashdbLib:v.join(n,"bashdb_dir"),pathCat:"/usr/bin/cat",pathMkfifo:"/usr/bin/mkfifo",pathPkill:"/usr/bin/pkill",terminalKind:"debugConsole",argsString:"",env:{},showDebugOutput:!1,trace:!1}}}if(r.adapter==="powershell"){let n=process.env.PI_POWERSHELL_EDITOR_SERVICES_PATH??"/opt/pi-debug-adapters/powershell-editor-services";if(e===void 0)throw new Error("PowerShell debugger temporary directory was not created");return{command:process.env.PI_PWSH_PATH??"pwsh",args:["-NoLogo","-NoProfile","-Command",`& '${v.join(n,"PowerShellEditorServices/Start-EditorServices.ps1").replaceAll("'","''")}' -LogPath '${v.join(e,"logs").replaceAll("'","''")}' -LogLevel Warning -SessionDetailsPath '${v.join(e,"session.json").replaceAll("'","''")}' -FeatureFlags @() -AdditionalModules @() -HostName 'Pi Agent IDE' -HostProfileId 'pi-agent-ide' -HostVersion '1.0.0' -BundledModulesPath '${n.replaceAll("'","''")}' -Stdio -DebugServiceOnly`],adapterID:"PowerShell",request:"launch",launch:{...t,script:r.program,createTemporaryIntegratedConsole:!1,executeMode:"Call"}}}return{command:process.execPath,args:[],adapterID:"pwa-node",request:"launch",launch:{...t,type:"pwa-node",console:"internalConsole",autoAttachChildProcesses:!1,stopOnEntry:!0,sourceMaps:!0,pauseForSourceMap:!0,outFiles:[v.join(v.dirname(r.program),"**","*.js")]}}}i(st,"adapterRecipe");var ct=D.Object({adapter:ut(["dart","debugpy","delve","java","elixir","julia","kotlin","lldb-dap","lua","netcoredbg","node","php","powershell","r","ruby","shell"],{description:"Select an installed DAP adapter for Dart, Python, Go, Java, Elixir, Julia, Kotlin, C, C++, Rust, Swift, Zig, Lua, C#, JavaScript, TypeScript, PHP, PowerShell, R, Ruby, or shell scripts."}),program:D.String({minLength:1,description:"Source file or executable to launch. Relative paths resolve from cwd."}),source:D.Optional(D.String({description:"Source file used for anchored breakpoints. Defaults to program."})),args:D.Optional(D.Array(D.String(),{description:"Arguments passed to the debugged program."})),mainClass:D.Optional(D.String({minLength:1,description:"Fully qualified JVM main class. Required by Java and Kotlin adapters."})),cwd:D.Optional(D.String({description:"Working directory. Relative paths resolve from the workspace."}))},{additionalProperties:!1});async function pt(r){ee(r,[await Q({id:"debugger",description:"Debugger sessions, breakpoints, stepping, and cleanup",triggers:[{tool:"debug"},...["read","insert","delete"].map(l=>({tool:l,resourcePrefixes:["debug:"]}))]})]);let e=ce("debugger"),t=e!==void 0&&typeof e.evaluate=="function"?e:new N,n=new Map,o=je(t,"debugger-source"),a=je(t,"debugger-input"),s=ue(r).add(Re(t)),d=ve(t),u={protocol:re,apiVersion:ne,id:"debugger",setup(l){l.addResolver({resolver:o,matchesCall:i(p=>t.sourceFile(p)!==void 0,"matchesCall"),renderCall(p,f,g){let m=T(p)?p:{},b=typeof m.path=="string"?m.path:"",w=t.get(b),h=t.sourceFile(b);if(w===void 0||h===void 0)throw new Error("Debugger source header lost its session");let P=x.relative(w.options.cwd,h),_=Array.isArray(m.views)?m.views.filter(G=>typeof G=="string"):[],A=typeof m.offset=="number"?m.offset:1,B=typeof m.limit=="number"?m.limit:void 0,M=B===void 0?String(A):`${A}-${A+B-1}`;return oe(g.lastComponent,{tool:"debug file",primary:{text:`${P}:${M}`,color:"accent",underline:!0},qualifiers:_.length===0?[]:[{text:`views ${_.join(",")}`}],details:[{label:"source",value:b},{label:"file",value:h},..._.length===0?[]:[{label:"views",value:_.join(",")}]],expanded:g.expanded},f)}}),l.addView({view:"breakpoints",presenter:d}),l.describe('views: ["breakpoints"] \u2014 current debugger breakpoints beside source lines. Normal files include every current session; debug sources are session-scoped. debug:<session> \u2014 debugger state.')}},c={protocol:ie,apiVersion:se,id:"debugger",setup(l){l.addResolver({resolver:a}),l.tool("insert").addSemanticHandler({matches:i(p=>gt(p,t),"matches"),execute:i(async(p,f)=>{let g=f,m=qe(t,g.path);if(t.sourceFile(g.path)!==void 0){if(g.text!=="breakpoint"||g.anchor===void 0)throw new Error('A debug source accepts text "breakpoint" with one anchor');let w=await p.resolveAnchor("anchor"),h=await t.addBreakpoint(g.path,w.lineNumber,p.signal);return{source:h.source,summary:`Breakpoint ${h.source} created at ${x.relative(m.options.cwd,h.file)}:${h.line}.`,data:{kind:"debug-breakpoint",session:m.source,file:h.file,line:h.line,verified:h.verified,snapshot:t.snapshot(m)}}}if(g.path!==m.source||g.anchor!==void 0)throw new Error("Debug commands target the session resource without an anchor");let b=await ft(t,m,g.text,p.signal);return{source:m.source,summary:b===void 0?U(m):`${b.expression} = ${b.result}${b.type===void 0?"":` (${b.type})`}`,data:ht(t,m,g.text,b)}},"execute")}),l.tool("delete").addSemanticHandler({matches:i(p=>bt(p,t),"matches"),execute:i(async(p,f)=>{let g=f.path,m=qe(t,g),b=t.snapshot(m);n.set(g,b);let w=g.includes("/breakpoint/");await t.delete(g,p.signal);let h=w?t.snapshot(m):{...b,status:"terminated"};return{source:g,summary:`Deleted ${g}.`,data:{kind:w?"debug-breakpoint":"debug-session",deleted:!0,snapshot:h}}},"execute")}),l.describe('For debug:<session> resources, insert performs debugger actions without changing source text. On a debug source, insert "breakpoint" at an anchor. On the session, insert start, continue, step over, step into, step out, or evaluate <expression>. Delete removes a breakpoint or terminates the session.');for(let p of["insert","delete"])l.addToolRenderer({tool:p,matches(f,g){return g==="call"?T(f)&&typeof f.path=="string"&&(t.get(f.path)!==void 0||n.has(f.path)):z(T(f)&&"details"in f?f.details:f)!==void 0},renderCall(f,g,m){let b=f,w=b.path===void 0?void 0:t.get(b.path),h=b.path===void 0?void 0:n.get(b.path),P=m.state;w!==void 0?P.snapshot=t.snapshot(w):h!==void 0&&(P.snapshot=h);let _=P.snapshot;if(_===void 0)throw new Error("Debugger renderer lost its session");let A=b.path===void 0?void 0:t.breakpoint(b.path)??_.breakpoints.find(G=>G.source===b.path),B=b.path===void 0?void 0:t.sourceFile(b.path),M=p==="delete"?A===void 0?"delete-session":`delete-breakpoint ${x.basename(A.file)}:${A.line}`:b.text==="breakpoint"&&B!==void 0?`breakpoint ${x.basename(B)}:${vt(b)}`:b.text??"debug action";return we(_,M,g)},renderResult(f,g,m){let b=z(f.details);if(b===void 0)throw new Error("Debugger result is missing its session");let w=xe(f.details);return q(b,g.expanded,m,w)}})}};await Promise.all([te(r,me),ae(r,u)]),await de(r,c),r.registerTool(lt({name:"debug",label:"Debug session",promptSnippet:"Create a local DAP debug session before setting anchored breakpoints",description:"Use debug to create a configured local debugger session. This does not launch the program yet. The returned debug: resource survives extension reloads.",parameters:ct,async execute(l,p,f,g,m){let b=x.resolve(m.cwd,p.cwd??"."),w=x.resolve(b,p.program);try{await dt(w);let h=t.create({adapter:p.adapter,program:w,sourceFile:x.resolve(b,p.source??p.program),args:p.args??[],cwd:b,...p.mainClass===void 0?{}:{mainClass:p.mainClass}}),P=mt(t,h);return{content:[{type:"text",text:`${U(h)}
20
+ Source: ${P.sourceResource}
21
+ Breakpoints: ${P.breakpointsResource}
22
+
23
+ Next: read ${P.sourceResource} with views ["anchors"], then insert a breakpoint at an anchor.`}],details:P}}catch(h){return{content:[{type:"text",text:h instanceof Error?h.message:String(h)}],details:{adapter:p.adapter,program:w,cwd:b,status:"failed"},isError:!0}}},renderCall(l,p){let f=x.resolve(process.cwd(),typeof l.cwd=="string"?l.cwd:"."),g=x.resolve(f,typeof l.program=="string"?l.program:"program");return V(typeof l.adapter=="string"?l.adapter:"debugger",g,f,p)},renderResult(l,p,f){let g=T(l.details)?l.details.snapshot:void 0;if(typeof g=="object"&&g!==null)return q(g,p.expanded,f);let m=l.details;return V(m.adapter,m.program,m.cwd,f)}})),r.on("session_shutdown",l=>{if(s(),l.reason!=="quit"){le("debugger",t);return}pe("debugger",t),t.dispose()})}i(pt,"registerDebugger");function je(r,e){return{id:e,tryResolve(t){let n=r.get(t);return n===void 0?Promise.resolve({kind:"not-handled"}):Promise.resolve({kind:"resolved",resource:{source:t,async read(){let o=r.sourceFile(t);if(o!==void 0)return[wt(o,await r.readSource(t))];if(t===`${n.source}/breakpoints`)return[{type:"text",text:yt(n)}];let a=r.breakpoint(t);if(t!==n.source&&a===void 0)throw new Error(`Unknown debug resource ${t}`);return[{type:"text",text:a===void 0?U(n):`Breakpoint: ${a.source}
24
+ File: ${a.file}
25
+ Line: ${a.line}
26
+ Status: ${a.verified?"verified":"pending"}`}]}}})}}}i(je,"createDebugResourceResolver");function gt(r,e){if(!T(r)||typeof r.path!="string"||typeof r.text!="string")return!1;let t=e.get(r.path);return t!==void 0&&(r.path===t.source||e.sourceFile(r.path)!==void 0)}i(gt,"matchesDebugInsert");function bt(r,e){if(!T(r)||typeof r.path!="string")return!1;let t=e.get(r.path);return t!==void 0&&(r.path===t.source||r.path.startsWith(`${t.source}/breakpoint/`))}i(bt,"matchesDebugDelete");async function ft(r,e,t,n){let o=t.trim(),a=/^evaluate\s+(.+)$/isu.exec(o);if(a!==null)return await r.evaluate(e,a[1],n);switch(o.toLowerCase()){case"start":{await r.start(e,n);return}case"continue":{await r.command(e,"continue",n);return}case"step over":{await r.command(e,"next",n);return}case"step into":{await r.command(e,"stepIn",n);return}case"step out":{await r.command(e,"stepOut",n);return}default:throw new Error(`Unknown debug command ${JSON.stringify(t)}`)}}i(ft,"executeSessionCommand");function mt(r,e){return{source:e.source,sourceResource:r.sourceResource(e),breakpointsResource:`${e.source}/breakpoints`,adapter:e.options.adapter,program:e.options.program,cwd:e.options.cwd,status:e.status,breakpoints:[...e.breakpoints.values()].map(({source:t,file:n,line:o,verified:a})=>({source:t,file:n,line:o,verified:a})),...e.stop===void 0?{}:{stop:e.stop},snapshot:r.snapshot(e)}}i(mt,"debugDetails");function ht(r,e,t,n){return{kind:"debug-command",command:t,status:e.status,breakpoints:[...e.breakpoints.values()].map(({source:o,file:a,line:s,verified:d})=>({source:o,file:a,line:s,verified:d})),...e.stop===void 0?{}:{stop:e.stop},...n===void 0?{}:{evaluation:n},snapshot:r.snapshot(e)}}i(ht,"debugActionData");function yt(r){return r.breakpoints.size===0?`No breakpoints in ${r.source}.`:[...r.breakpoints.values()].map(e=>`${e.verified?"\u25CF":"\u25CB"} ${e.file}:${e.line} \xB7 ${e.source}`).join(`
27
+ `)}i(yt,"renderBreakpointList");function qe(r,e){let t=r.get(e);if(t===void 0)throw new Error(`Unknown debug session ${e}`);return t}i(qe,"requiredSession");function vt(r){let e=T(r)&&typeof r.anchor=="string"?r.anchor:void 0;return/^(\d+)#/u.exec(e??"")?.[1]??e??"selected line"}i(vt,"breakpointLine");function T(r){return typeof r=="object"&&r!==null}i(T,"isRecord");function wt(r,e){return{type:"text",text:e,sourceLines:Object.fromEntries(e.split(/\r?\n/u).map((t,n)=>[String(n+1),{source:r,lineNumber:n+1,content:t}]))}}i(wt,"debugSourceContent");export{pt as default};
@@ -0,0 +1 @@
1
+ import{a as t}from"./chunk-EI7MMDWY.js";import{readFile as i}from"node:fs/promises";import a from"node:path";var s="pi-agent-ide-documentation",p=1,c=`${s}/core/ready`,d=`${s}/document/register`;async function l(n){return{...n,markdown:await i(a.join(await g(),"docs","agent-guides",`${n.id}.md`),"utf8")}}t(l,"loadPackagedAgentGuide");async function g(){let n=import.meta.dirname;for(;;){let o=a.join(n,"package.json");try{if(JSON.parse(await i(o,"utf8")).name==="pi-agent-ide")return n}catch{}let e=a.dirname(n);if(e===n)throw new Error("Cannot locate the pi-agent-ide package root");n=e}}t(g,"findHostPackageRoot");function y(n,o){let e=t(()=>n.events.emit(d,{documents:o}),"announce"),r=n.events.on(c,()=>{e(),r()});n.on("session_shutdown",r),e()}t(y,"connectAgentDocumentation");export{s as a,p as b,c,d,l as e,y as f};
@@ -0,0 +1,3 @@
1
+ import{c as j}from"./chunk-YHUTTZC6.js";import{i as T,o as m,t as L,u as C}from"./chunk-5VSE5X5R.js";import{a as y}from"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function Te(e,n){let{lines:t,truncation:r,...i}=e,o=t?.map(a=>{let l=[a.lineNumber,L(a.content,n),a.lineEnding];return(a.presentation!==void 0||a.metadata!==void 0)&&l.push(a.presentation),a.metadata!==void 0&&l.push(a.metadata),l}),{content:s,...u}=r??{};return{...i,...o===void 0?{}:{storedLines:o},...r===void 0?{}:{truncation:u,truncatedText:L(s??"",n)}}}d(Te,"compactReadDetails");function H(e,n){let t=e;if(t.storedLines===void 0&&t.truncatedText===void 0)return e;let{storedLines:r,truncatedText:i,truncation:o,...s}=t;return{...s,...r===void 0?{}:{lines:r.map(([u,a,l,c,p])=>({lineNumber:u,content:C(a,n),lineEnding:l,...c==null?{}:{presentation:c},...p==null?{}:{metadata:p}}))},...o===void 0?{}:{truncation:{...o,content:C(i??"",n)}}}}d(H,"restoreReadDetails");import f from"node:path";import{homedir as G}from"node:os";import{createReadToolDefinition as X,getReadmePath as J}from"@earendil-works/pi-coding-agent";import{Text as Z}from"@earendil-works/pi-tui";var v=X(process.cwd()),K=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]);function $(e,n=process.cwd()){if(typeof e!="object"||e===null)return;let t=e,r=t.path;if(typeof r!="string"||r.length===0||r.includes("#")||!f.isAbsolute(r)&&/^[a-z][a-z\d+.-]*:/iu.test(r)||t.views!==void 0&&(!Array.isArray(t.views)||t.views.length>0)||t.offset!==void 0&&(typeof t.offset!="number"||!Number.isInteger(t.offset)||t.offset<1)||t.limit!==void 0&&(typeof t.limit!="number"||!Number.isInteger(t.limit)||t.limit<1))return;let i=r.startsWith("~/")?f.join(G(),r.slice(2)):r,o=f.resolve(n,i),s=f.basename(o),u=f.relative(f.dirname(J()),o),a=!f.isAbsolute(u)&&(u==="README.md"||u.startsWith(`docs${f.sep}`)||u.startsWith(`examples${f.sep}`));if(!(s!=="SKILL.md"&&!K.has(s)&&!a))return{path:r,...t.offset===void 0?{}:{offset:t.offset},...t.limit===void 0?{}:{limit:t.limit}}}d($,"nativeReadArguments");function A(e,n){return{...e,args:n,lastComponent:e.lastComponent instanceof Z?e.lastComponent:void 0}}d(A,"nativeReadContext");import{getLanguageFromPath as k,getMarkdownTheme as Y,highlightCode as E,keyHint as Q}from"@earendil-works/pi-coding-agent";import{Container as w,Markdown as _,Text as ee,truncateToWidth as S,visibleWidth as R,wrapTextWithAnsi as q}from"@earendil-works/pi-tui";var g=12;function ne(e,n,t){let r=typeof n=="number"?n:void 0,i=typeof t=="number"?t:void 0;if(r===void 0&&i===void 0)return{pathSuffix:"",qualifiers:[],details:[]};if(e==="inherited source"||e.includes("#")){let a=r??1,l=i===void 0?String(a):`${a}-${a+i-1}`;return{pathSuffix:"",qualifiers:[{text:`relative lines ${l}`}],details:[{label:"relative lines",value:l}]}}if(r!==void 0&&r<0)return{pathSuffix:"",qualifiers:[{text:`tail ${Math.abs(r)}`},...i===void 0?[]:[{text:`limit ${i}`}]],details:[{label:"tail",value:String(Math.abs(r))},...i===void 0?[]:[{label:"limit",value:String(i)}]]};let s=Math.max(1,r??1),u=i===void 0?String(s):`${s}-${s+i-1}`;return{pathSuffix:`:${u}`,qualifiers:[],details:[{label:"lines",value:u}]}}d(ne,"readWindowPresentation");function We(e,n,t){let r=$(e,t.cwd);if(r!==void 0)return y(v.renderCall)(r,n,A(t,r));if(typeof e.path=="string"&&e.path.startsWith("shell:"))return new w;let i=typeof e.path=="string"?e.path:"inherited source",o=ne(i,e.offset,e.limit),s=Array.isArray(e.views)?e.views.filter(l=>typeof l=="string"):[],u=[...o.qualifiers,...s.length===0?[]:[{text:`views ${s.join(",")}`}]],a=[...typeof e.path=="string"?[{label:"path",value:e.path}]:[],...o.details,...s.length===0?[]:[{label:"views",value:s.join(",")}]];return j(t.lastComponent,{tool:"read",primary:{text:`${i}${o.pathSuffix}`,color:typeof e.path=="string"?"accent":"muted",underline:typeof e.path=="string",truncate:"start"},qualifiers:u,details:a,expanded:t.expanded},n)}d(We,"renderReadCall");function je(e){let n=new WeakMap;return(t,r,i,o)=>{let s=e.nativeResources?$(o.args,o.cwd):void 0;if(s!==void 0&&!r.isPartial)return y(v.renderResult)({...t,details:{truncation:D(t.details).truncation}},r,i,A(o,s));if(r.isPartial||o.isError){let p=P(t),B=o.isError?"error":"dim";return new ee(i.fg(B,p),0,0)}let u=D(t.details).diagnosticCheck;if(u?.complete&&u.count===0)return new w;if(!me(t))return o.lastComponent instanceof w?o.lastComponent:new w;let a=n.get(t);a===void 0&&(a=H(D(t.details),P(t)),n.set(t,a));let c=(o.lastComponent instanceof b?o.lastComponent:void 0)??new b({result:t,details:a,options:e,expanded:r.expanded,theme:i});return c.update({result:t,details:a,options:e,expanded:r.expanded,theme:i}),c}}d(je,"createReadResultRenderer");var b=class{constructor(n){this.state=n}static{d(this,"ReadResultPanel")}cached;update(n){this.state.result===n.result&&this.state.details===n.details&&this.state.options===n.options&&this.state.expanded===n.expanded&&this.state.theme===n.theme||(this.state=n,this.invalidate())}render(n){if(this.cached?.width===n)return this.cached.lines;if(n<8){let c=[S(V(this.state,n),Math.max(1,n))];return this.cached={width:n,lines:c},c}let t=n-2,r=Math.max(1,t-2),i=oe(this.state,r),o=se(i.state,r).flatMap(c=>q(c,r)),s=ue(o,this.state.expanded,this.state.theme,i.hasHiddenRows),u=[le(this.state,t,this.state.theme)];for(let c of s)for(let p of q(c,r))u.push(I(p,t,this.state.theme));let a=fe(this.state.details,this.state.theme);a!==void 0&&u.push(I(a,t,this.state.theme)),u.push(this.state.theme.fg("borderMuted",`\u2570${"\u2500".repeat(t)}\u256F`));let l=u.map(c=>S(c,n));return this.cached={width:n,lines:l},l}invalidate(){this.cached=void 0}},te=100,re=g,ie=4;function oe(e,n){if(e.expanded)return{state:e,hasHiddenRows:!1};let t=N(e.details);if(t!==void 0&&t.length>te)return{state:{...e,details:{...e.details,lines:t.slice(0,re)}},hasHiddenRows:!0};if(t!==void 0)return{state:e,hasHiddenRows:!1};let r=Math.max(g,n*g*ie),i=e.result.content.map(s=>s.type!=="text"||s.text.length<=r?s:{...s,text:s.text.slice(0,r)}),o=i.some((s,u)=>{let a=e.result.content[u];return s.type==="text"&&a?.type==="text"&&s.text.length<a.text.length});return o?{state:{...e,result:{...e.result,content:i}},hasHiddenRows:o}:{state:e,hasHiddenRows:!1}}d(oe,"compactRenderInput");function se(e,n){let t=N(e.details),r=pe(e.result,t,e.details,!e.expanded);if(e.options.kind==="markdown"||Re(e.details,t,e.options.kind)){let a=new _(r,0,0,Y());return M(a.render(n),e.theme)}if(e.options.kind==="code-view"){let a=t===void 0?h(r).map(l=>O(l,e.theme,!1)):z(t)?ae(t,!e.expanded,e.theme):de(t,e.theme);return M(a,e.theme)}let i=t!==void 0&&z(t),o=t===void 0||i?h(r).map(x):t.map(({content:a})=>x(a)),s=W(e.details,t),u=s===void 0?o.map(a=>e.theme.fg("toolOutput",a)):i?U(t,s,!e.expanded,e.theme):E(o.join(`
2
+ `),s);return M(u,e.theme)}d(se,"renderContentRows");function U(e,n,t,r){return e.flatMap(i=>{let o=x(i.content),s=E(o,n)[0]??r.fg("toolOutput",o),u=!1,a=m({source:"",content:i.content,lines:[i]},{compact:t});return h(a).map(l=>{if(!u&&o.length>0){let c=l.indexOf(o);if(c>=0)return u=!0,`${r.fg("toolOutput",l.slice(0,c))}${s}${r.fg("toolOutput",l.slice(c+o.length))}`}return r.fg("toolOutput",l)})})}d(U,"renderHighlightedPresentedLines");function ae(e,n,t){return e.flatMap(r=>{let i=T(r);if(i===void 0){let s=m({source:"",content:r.content,lines:[r]},{compact:n});return h(s).map(u=>O(u,t,!1))}let o=k(i.source);if(o===void 0){let s=m({source:"",content:r.content,lines:[r]},{compact:n});return h(s).map(u=>t.fg("toolOutput",u))}return U([r],o,n,t)})}d(ae,"renderPresentedCodeViewLines");function de(e,n){return e.map(t=>{let r=T(t);if(r===void 0)return O(t.content,n);let i=k(r.source),o=x(F(t.content));return i===void 0?n.fg("toolOutput",o):E(o,i)[0]??n.fg("toolOutput",o)})}d(de,"renderCodeViewLines");function F(e){return e.replace(/(?:[ \t]{2,}<!--[ \t]+scope-(?:begin|end)-[^\s>]+[ \t]+-->)+[ \t]*$/u,"")}d(F,"stripScopeMarkers");function O(e,n,t=!0){let r=x(t?F(e):e);return/^#{2,3}\s/u.test(r)?n.fg("mdHeading",n.bold(r.replace(/^#{2,3}\s+/u,""))):/^(?:Lines|Reason|Recovery):/u.test(r)?n.fg("dim",r):/^[\p{L}][^:]*:$/u.test(r)?n.fg("accent",n.bold(r)):/^\s*[-*]\s/u.test(r)?n.fg("mdListBullet",r):n.fg("toolOutput",r)}d(O,"renderCodeViewLabel");function ue(e,n,t,r=!1){if(n||e.length<=g&&!r)return e;let i=e.slice(0,g-1),o=e.length-i.length,s=r?"more rows":`${String(o)} more ${o===1?"row":"rows"}`;return[...i,`${t.fg("dim",`\u2026 ${s} \xB7 `)}${Q("app.tools.expand","to expand")}`]}d(ue,"compactRows");function le(e,n,t){let r=d(s=>t.fg("borderMuted",s),"frame"),i=S(` ${V(e,Math.max(1,n-1))} `,Math.max(0,n-1),""),o="\u2500".repeat(Math.max(0,n-R(i)-1));return`${r("\u256D\u2500")}${i}${r(`${o}\u256E`)}`}d(le,"renderTopBorder");function V(e,n){let t=e.options.label??he(W(e.details,N(e.details))),r=e.details.source??"read result",i=ce(e.details),o=e.theme.fg("accent",e.theme.bold(t)),s=i===void 0?"":e.theme.fg("dim",` \xB7 ${i}`),u=Math.max(1,n-R(o)-R(s)-2),a=xe(r,u);return`${o} ${e.theme.fg("muted",a)}${s}`}d(V,"readTitle");function ce(e){if(!(e.startLine===void 0||e.endLine===void 0||e.totalLines===void 0||e.totalLines<=0))return`${String(e.startLine)}\u2013${String(e.endLine)} / ${String(e.totalLines)}`}d(ce,"sourceRange");function fe(e,n){let t=e.truncation;if(t?.firstLineExceedsLimit===!0)return n.fg("warning","First source line is larger than the saved read limit");if(t?.truncated===!0)return n.fg("warning",`Saved result contains ${String(t.outputLines)} of ${String(t.totalLines)} rendered rows`)}d(fe,"readStatus");function I(e,n,t){let r=Math.max(0,n-2),i=S(e,r),o=` ${i}${" ".repeat(Math.max(0,r-R(i)))} `,s=t.fg("borderMuted","\u2502");return`${s}${o}${s}`}d(I,"framed");function pe(e,n,t,r){if(n!==void 0)return m({source:t.source??"",content:"",lines:n},{compact:r});let i=P(e);return t.truncation===void 0&&!(t.totalLines!==void 0&&t.endLine!==void 0&&t.endLine<t.totalLines)?i:i.replace(/\n\n\[(?:Showing lines|Output truncated|\d+ more lines in source)[\s\S]*\]$/u,"")}d(pe,"cleanText");function z(e){return e.some(n=>n.presentation!==void 0)}d(z,"hasPresentation");function h(e){let n=e.split(/\r\n|\r|\n/u);return n.at(-1)===""&&/(?:\r\n|\r|\n)$/u.test(e)&&n.pop(),n}d(h,"splitTextRows");function P(e){return e.content.flatMap(n=>n.type==="text"?[n.text]:[]).join(`
3
+ `)}d(P,"textBlocks");function N(e){return e.lines}d(N,"readLines");function D(e){return typeof e=="object"&&e!==null?e:{}}d(D,"readDetails");function me(e){return e.content.some(n=>n.type==="text")}d(me,"hasTextContent");function W(e,n){let r=n?.map(T).find(i=>i!==void 0)?.source??e.source;return r===void 0?void 0:k(ge(r))}d(W,"languageFor");function Re(e,n,t){return t==="source"&&W(e,n)==="markdown"}d(Re,"isMarkdownSource");function ge(e){try{let n=new URL(e);return n.protocol==="file:"?n.pathname:`${n.pathname}${n.search}`}catch{return e.replace(/#[^/\\]*$/u,"").replace(/^[A-Za-z][A-Za-z\d+.-]*:(?=[/\\])/u,"")}}d(ge,"normalizeSourcePath");function x(e){let n="";for(let t of e.replaceAll(" "," ".repeat(4))){let r=y(t.codePointAt(0));n+=r<32||r===127?"\uFFFD":t}return n}d(x,"normalizeText");function he(e){return e===void 0?"TEXT":{javascript:"JS",json:"JSON",markdown:"MD",python:"PY",rust:"RS",typescript:"TS"}[e]??e.slice(0,4).toUpperCase()}d(he,"languageLabel");function M(e,n){return e.length===0?[n.fg("dim","Empty content")]:[...e]}d(M,"nonEmptyRows");function xe(e,n){return R(e)<=n?e:n<=1?"\u2026":`\u2026${e.slice(-(n-1))}`}d(xe,"truncateFromStart");export{Te as a,g as b,We as c,je as d};
@@ -0,0 +1,5 @@
1
+ import{a as _}from"./chunk-M5IVSCR2.js";import{e as $,f as q}from"./chunk-T7I2VX3J.js";import{a as T}from"./chunk-6CZO43OH.js";import{a as O,b as U}from"./chunk-OBNING2A.js";import{a as W}from"./chunk-ZTYWHL2F.js";import{a as k,b as L}from"./chunk-7UGNGK7Y.js";import{a as c}from"./chunk-EI7MMDWY.js";import{execFile as ne}from"node:child_process";import te from"node:os";import{promisify as re}from"node:util";import{createCanvas as z,loadImage as oe}from"@napi-rs/canvas";var p=re(ne),I=20*1024*1024,F={durationSeconds:2,intervalSeconds:.5,scale:.5},H=new Set;function j(e){let n=R({mode:"sequence",durationSeconds:Number(e.durationSeconds??2),intervalSeconds:Number(e.intervalSeconds??.5),scale:Number(e.scale??.5)});F={durationSeconds:n.durationSeconds,intervalSeconds:n.intervalSeconds,scale:n.scale},H=new Set((e.allowedExecutables??"").split(",").map(r=>r.trim().toLowerCase()).filter(Boolean))}c(j,"configureVision");function y(){return F}c(y,"getVisionDefaults");function G(e){let n=e.includes("\\")?e.slice(e.lastIndexOf("\\")+1):e,r=n.trim().split(/\s+/u)[0]??"",t=r.slice(r.lastIndexOf("/")+1);return H.has((e.includes("\\")?n:t).toLowerCase())}c(G,"isExecutableAllowed");function J(e,n){let r=e?.filter(i=>/^(?:image|sequence)(?::|$)/u.test(i))??[];if(r.length===0)return;if(r.length>1)throw new Error("Use only one image or sequence view");let t=r[0],s=t.indexOf(":"),a=t.slice(0,s<0?void 0:s),o={};if(s>=0&&ie(t.slice(s+1),o),a==="image"&&(o.duration!==void 0||o.interval!==void 0))throw new Error("duration and interval are supported only by the sequence view");return R({mode:a,durationSeconds:o.duration??n.durationSeconds,intervalSeconds:o.interval??n.intervalSeconds,scale:o.scale??n.scale,...o.region===void 0?{}:{region:o.region}})}c(J,"parseVisionView");function ie(e,n){if(e.length===0)throw new Error("View parameters cannot be empty");let r=e.split(",");for(let t=0;t<r.length;t+=1){let s=r[t],a=s.indexOf("=");if(a<=0)throw new Error(`Invalid view parameter ${s}`);let o=s.slice(0,a),i=s.slice(a+1);if(o==="region"){let l=[i,r[t+1],r[t+2],r[t+3]].map(Number);if(l.some(m=>!Number.isFinite(m)))throw new Error("region requires x,y,width,height values");n.region={x:l[0],y:l[1],width:l[2],height:l[3]},t+=3;continue}if(o!=="duration"&&o!=="interval"&&o!=="scale")throw new Error(`Unknown view parameter ${o}`);let d=Number(i);if(!Number.isFinite(d))throw new Error(`View parameter ${o} must be a number`);if(n[o]!==void 0)throw new Error(`Duplicate view parameter ${o}`);n[o]=d}}c(ie,"parseViewParameters");function X(e){if(!e.startsWith("display:"))return;if(e==="display:")return 0;let n=/^display:#(\d+)$/u.exec(e);if(n===null)throw new Error("Display sources use display: or display:#N with a zero-based index");let r=Number(n[1]);if(!Number.isSafeInteger(r))throw new Error("Display sources use display: or display:#N with a zero-based index");return r}c(X,"parseDisplaySource");async function E(e){let n=new Map(e.list().flatMap(s=>s.pid===void 0?[]:[[s.pid,s]]));if(process.platform!=="linux"&&process.platform!=="darwin")return[...n].map(([s,a])=>({pid:s,command:a.description,owned:!0,source:a.source,host:"local"}));let{stdout:r}=await p("ps",["-eo","pid=,ppid=,lstart=,args="],{maxBuffer:4*1024*1024}),t=r.split(`
2
+ `).flatMap(s=>{let a=/^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\d+\s+\d+:\d+:\d+\s+\d+)\s+(.*)$/u.exec(s);if(a===null)return[];let o=Number(a[1]),i=n.get(o);return[{pid:o,parentPid:Number(a[2]),started:a[3],command:a[4]??"",owned:i!==void 0,host:"local",...i===void 0?{}:{source:i.source}}]});return x()?[...t,...await se()]:t}c(E,"listProcesses");async function se(){try{let{stdout:e}=await p("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-Command","Get-Process | Select-Object Id,ProcessName,Path,StartTime | ConvertTo-Json -Compress"],{maxBuffer:4194304}),n=JSON.parse(e);return(Array.isArray(n)?n:[n]).flatMap(t=>{if(typeof t!="object"||t===null||!("Id"in t)||typeof t.Id!="number")return[];let s="ProcessName"in t&&typeof t.ProcessName=="string"?t.ProcessName:"Windows process",a="Path"in t&&typeof t.Path=="string"?t.Path:void 0,o="StartTime"in t&&typeof t.StartTime=="string"?t.StartTime:void 0;return[{pid:t.Id,command:a??s,owned:!1,host:"windows",...o===void 0?{}:{started:o}}]})}catch{return[]}}c(se,"listWindowsProcesses");async function A(e,n){if(!Number.isSafeInteger(e)||e<=0)throw new Error("Process PID must be a positive integer");let r=(await E(n)).find(t=>t.pid===e);if(r===void 0)throw new Error(`Process ${e} is not running`);return r}c(A,"readProcess");function R(e){let n=e.scale??1;if(!(n>0&&n<=1))throw new Error("Image scale must be greater than 0 and at most 1");let r=e.durationSeconds??0,t=e.intervalSeconds??1;if(e.mode==="sequence"){if(!(r>0&&r<=10))throw new Error("Sequence duration must be greater than 0 and at most 10 seconds");if(!(t>0))throw new Error("Sequence interval must be greater than 0 seconds");if(Math.floor(r/t)+1>20)throw new Error("Sequence capture is limited to 20 frames")}if(e.region!==void 0){let{x:s,y:a,width:o,height:i}=e.region;if(s<0||a<0||o<=0||i<=0||s+o>1||a+i>1)throw new Error("Image region x,y,width,height must fit within normalized bounds 0..1")}if(e.cellIndex!==void 0&&e.cellSize===void 0)throw new Error("Image offset requires limit to set the square grid cell size");if(e.cellSize!==void 0&&(!Number.isSafeInteger(e.cellSize)||e.cellSize<=0))throw new Error("Image limit must be a positive integer pixel size");if(e.cellIndex!==void 0&&(!Number.isSafeInteger(e.cellIndex)||e.cellIndex<0))throw new Error("Image offset must be a zero-based cell index");return e}c(R,"validateVisionOptions");async function b(e,n,r){let t=R(n),s=t.mode==="image"?1:Math.floor(t.durationSeconds/t.intervalSeconds)+1,a=[],o=0;for(let i=0;i<s;i+=1){r?.throwIfAborted(),i>0&&await me(t.intervalSeconds*1e3,r);let d=await e();if(o+=d.byteLength,o>I)throw new Error("Captured images exceed the 20MB aggregate limit");for(let l of await ae(d,t))a.push({type:"image",data:Buffer.from(l).toString("base64"),mimeType:"image/png"})}return a}c(b,"captureImages");async function ae(e,n){let r=await oe(e),t=n.region??{x:0,y:0,width:1,height:1},s=Math.round(t.x*r.width),a=Math.round(t.y*r.height),o=Math.max(1,Math.round(t.width*r.width)),i=Math.max(1,Math.round(t.height*r.height)),d=n.scale??1,l=Math.max(1,Math.round(o*d)),m=Math.max(1,Math.round(i*d)),w=z(l,m);if(w.getContext("2d").drawImage(r,s,a,o,i,0,0,l,m),n.cellSize===void 0)return[await w.encode("png")];let u=Math.ceil(l/n.cellSize),f=Math.ceil(m/n.cellSize),h=n.cellIndex??0;if(h>=u*f)throw new Error(`Image cell offset ${h} exceeds the ${u}x${f} grid`);let Z=h%u,ee=Math.floor(h/u),C=Z*n.cellSize,M=ee*n.cellSize,P=Math.min(n.cellSize,l-C),S=Math.min(n.cellSize,m-M),V=z(P,S);return V.getContext("2d").drawImage(w,C,M,P,S,0,0,P,S),[await V.encode("png")]}c(ae,"selectImage");function ce(e,n){return e&&n==="windows"}c(ce,"usesWindowsHostWindowCapture");function Y(){return{async captureWindow(e,n,r){if(r?.throwIfAborted(),ce(x(),n))return de(e,r);if(process.platform!=="linux"&&process.platform!=="darwin")throw new Error(`Window capture is unsupported on ${process.platform}`);let{Window:t}=await import("node-screenshots"),s;try{s=t.all()}catch(i){throw new Error(`Desktop window enumeration is unavailable: ${B(i)}`,{cause:i})}let a=s.find(i=>{try{return i.pid()===e}catch{return!1}});if(a===void 0)throw new Error(`No capturable desktop window belongs to PID ${e}`);let o=await a.captureImage();return r?.throwIfAborted(),new Uint8Array(await o.toPng())},async captureDisplay(e,n){if(n?.throwIfAborted(),x())return ue(e,n);if(process.platform!=="linux"&&process.platform!=="darwin"&&process.platform!=="win32")throw new Error(`Display capture is unsupported on ${process.platform}`);let{Monitor:r}=await import("node-screenshots"),t;try{t=r.all()}catch(o){throw new Error(`Desktop display enumeration is unavailable: ${B(o)}`,{cause:o})}let s=t[e];if(s===void 0)throw new Error(`Display index ${e} is unavailable; found ${t.length} display(s)`);let a=await s.captureImage();return n?.throwIfAborted(),new Uint8Array(await a.toPng())},async captureUrl(e,n){if(e.protocol!=="http:"&&e.protocol!=="https:")throw new Error("Web screenshots require an HTTP(S) URL");let{chromium:r}=await import("playwright-core"),t=await le(),s=await r.launch({executablePath:t,headless:!0,chromiumSandbox:!1,timeout:3e4}),a=c(()=>{s.close()},"abort");n?.addEventListener("abort",a,{once:!0});try{let o=await s.newPage({viewport:{width:1280,height:720}});return await o.goto(e.href,{waitUntil:"domcontentloaded",timeout:3e4}),await o.waitForLoadState("networkidle",{timeout:1500}).catch(()=>{}),n?.throwIfAborted(),new Uint8Array(await o.screenshot({type:"png",fullPage:!0}))}finally{n?.removeEventListener("abort",a),await s.close().catch(()=>{})}}}}c(Y,"createCaptureBackend");async function de(e,n){let r=new URL("windows-window-capture.ps1",new URL("../src/plugins/pi-agent-ide-vision/src/vision.ts",import.meta.url).href);n?.throwIfAborted();let{stdout:t}=await p("wslpath",["-w",r.pathname],{signal:n}),{stdout:s}=await p("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",t.trim(),"-ProcessId",String(e)],{encoding:"buffer",maxBuffer:I,signal:n});return new Uint8Array(s)}c(de,"captureWslWindow");async function ue(e,n){let r=new URL("windows-display-capture.ps1",new URL("../src/plugins/pi-agent-ide-vision/src/vision.ts",import.meta.url).href);n?.throwIfAborted();let{stdout:t}=await p("wslpath",["-w",r.pathname],{signal:n}),{stdout:s}=await p("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",t.trim(),"-DisplayIndex",String(e)],{encoding:"buffer",maxBuffer:I,signal:n});return new Uint8Array(s)}c(ue,"captureWslDisplay");function x(){return process.platform==="linux"&&(process.env.WSL_DISTRO_NAME!==void 0||te.release().toLowerCase().includes("microsoft"))}c(x,"isWsl");async function le(){let e=process.env.PI_AGENT_IDE_BROWSER_PATH;if(e!==void 0)return e;let{stdout:n}=await p("bash",["-lc","command -v google-chrome-stable || command -v google-chrome || command -v chromium || command -v chromium-browser"]),r=n.trim();if(r.length===0)throw new Error("No Chrome or Chromium executable was found; set PI_AGENT_IDE_BROWSER_PATH");return r}c(le,"resolveBrowser");function me(e,n){return new Promise((r,t)=>{let s=setTimeout(r,e),a=c(()=>{clearTimeout(s),t(n?.reason??new Error("Capture aborted"))},"abort");n?.addEventListener("abort",a,{once:!0}),s.unref()})}c(me,"delay");function B(e){return e instanceof Error?e.message:String(e)}c(B,"errorMessage");async function fe(e,n){q(e,[await $({id:"vision",description:"Window, display, image, and sequence capture",triggers:[{tool:"read",resourcePrefixes:["window:","display:"]}]})]);let r=n?.preferences??{};j({durationSeconds:r["vision.sequenceDurationSeconds"],intervalSeconds:r["vision.sequenceIntervalSeconds"],scale:r["vision.imageScale"],allowedExecutables:r["vision.allowedExecutables"]});let t=_(e),s=Y();await Promise.all([T(e,{protocol:O,apiVersion:U,id:"vision",setup(a){for(let i of["image","sequence"])a.addView({view:i,presenter:{id:`vision-${i}`,present:c(d=>d,"present")}});a.addHandler({stage:"pre-read",async handler(i){let d=i.request.path;if(d===void 0)return{kind:"continue",context:i};let l=X(d);if(l!==void 0){if(e.getFlag("pi-agent-ide-vision-displays")!==!0)return g(d,"Display capture is disabled. Enable --pi-agent-ide-vision-displays to allow it.");try{let u=await b(()=>s.captureDisplay(l,i.resolverContext.signal),D(i.request),i.resolverContext.signal);return v(d,u)}catch(u){return g(d,N(u))}}let m=K(d,"process:");if(m!==void 0){let u=await A(m,t);return v(d,[{type:"text",text:Q(u)}])}let w=K(d,"window:");if(w!==void 0){let u=await A(w,t);if(!u.owned&&!G(u.command)&&e.getFlag("pi-agent-ide-vision-arbitrary-windows")!==!0)return g(d,`Window capture for PID ${w} is denied because the process is neither Agent IDE-owned nor allowlisted by executable name. Enable --pi-agent-ide-vision-arbitrary-windows to allow it.`);try{let f=await b(()=>s.captureWindow(w,u.host,i.resolverContext.signal),D(i.request),i.resolverContext.signal);return v(d,f)}catch(f){return g(d,N(f))}}if(/^https?:\/\//iu.test(d)&&we(i.request)){let u=new URL(d);try{let f=await b(()=>s.captureUrl(u,i.resolverContext.signal),D(i.request),i.resolverContext.signal);return v(u.href,f)}catch(f){return g(u.href,N(f))}}return{kind:"continue",context:i}}});let o=y();a.describe(`Process metadata: process:PID. Visual capture: window:PID and display: or display:#N. HTTP(S) sources accept image and sequence screenshots. Use named view parameters such as sequence:duration=2,interval=0.5,scale=0.5 and image:scale=0.5,region=0.25,0.25,0.5,0.5. Duration is limited to 10 seconds and sequences to 20 frames. Defaults: duration=${o.durationSeconds}, interval=${o.intervalSeconds}, scale=${o.scale}. Region uses normalized x,y,width,height and runs before scaling. For captures, limit is a square grid cell size in output pixels and offset is one zero-based row-major cell index; limit without offset selects cell 0, while offset without limit is invalid. Omit both for the bounded transformed image.`)}}),W(e,{protocol:k,apiVersion:L,id:"vision-processes",setup(a){a.addResolver({priority:-100,resolver:{id:"processes",async tryResolve(o){let i=/^process:(.*)$/isu.exec(o.query);if(i===null)return{kind:"not-handled"};let d=(i[1]??"").trim().toLowerCase();return{kind:"resolved",payload:(await E(t)).filter(m=>d.length===0||String(m.pid)===d||m.command.toLowerCase().includes(d)).slice(0,Math.min(o.limit??50,100))}},format(o){let i=o;return{content:[{type:"text",text:i.length===0?"No matching processes.":i.map(Q).join(`
3
+
4
+ `)}],details:{count:i.length,processes:i}}}}}),a.describe("process:<query> finds running processes by PID or command for process:PID metadata reads and guarded window:PID capture.")}})])}c(fe,"registerVision");function K(e,n){if(!e.startsWith(n))return;let r=e.slice(n.length);if(!/^\d+$/u.test(r))throw new Error(`${n} sources require a numeric PID`);return Number(r)}c(K,"prefixedPid");function D(e){return{...J(e.views,y())??{mode:"image",...y()},...e.limit===void 0?{}:{cellSize:e.limit},...e.offset===void 0?{}:{cellIndex:e.offset}}}c(D,"options");function we(e){return e.views?.some(n=>/^(?:image|sequence)(?::|$)/u.test(n))===!0}c(we,"requestsScreenshot");function v(e,n){return{kind:"return",result:{content:n,details:{source:e,resolvedBy:"vision"}}}}c(v,"returned");function g(e,n){return{kind:"return",result:{content:[{type:"text",text:n}],details:{source:e,resolvedBy:"vision",failure:{code:"READ_FAILED",source:e,resolverId:"vision",message:n}},isError:!0}}}c(g,"failed");function N(e){return e instanceof Error?e.message:String(e)}c(N,"errorMessage");function Q(e){return[`PID: ${e.pid}`,`Command: ${e.command}`,`Owned by Agent IDE: ${e.owned?"yes":"no"}`,...e.parentPid===void 0?[]:[`Parent PID: ${e.parentPid}`],...e.started===void 0?[]:[`Started: ${e.started}`],...e.source===void 0?[]:[`Agent IDE source: ${e.source}`]].join(`
5
+ `)}c(Q,"formatProcess");export{fe as default};
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-EI7MMDWY.js";var A=[{value:"full",label:"Full IDE",description:"Load every built-in Agent IDE extension unless it is explicitly disabled."},{value:"text-editor",label:"Text Editor",description:"Load text read, search, editing, anchors, and AST only."}],b=new Set(["ide.core","ide.tips","read.core","read.filesystem","read.filesystem.text","search.core","search.text","editor.core","editor.renderer","editor.anchor.constant","editor.anchor.line-hash","editor.anchor.exact","editor.stale-anchor","ide.ast"]);function I(e,r){return r==="full"?[]:e.map(n=>n.id).filter(n=>!b.has(n))}o(I,"disabledByPreset");function g(e,r){if(e!==void 0){if(e==="full"||e==="text-editor")return e;throw new Error(`preset in ${r} must be one of: full, text-editor`)}}o(g,"readAgentIdePreset");import{readFile as y}from"node:fs/promises";import P from"node:os";import i from"node:path";function D(e=process.env,r=P.homedir(),n=process.cwd()){let t=e.PI_CODING_AGENT_DIR?.trim(),s=t===void 0||t.length===0?i.join(r,".pi","agent"):i.resolve(t);return{globalPath:i.join(s,"pi-agent-ide","extensions.json"),projectPath:i.resolve(n,".pi","pi-agent-ide","extensions.json")}}o(D,"resolvePiAgentIdeExtensionsConfigPaths");async function N(e){let r=await l(e.globalPath),n=await l(e.projectPath);return{disabled:[...new Set([...r.disabled,...n.disabled])],enabled:[...new Set([...r.enabled,...n.enabled])],...r.flags===void 0&&n.flags===void 0?{}:{flags:{...c(r),...c(n)}},...r.preferences===void 0&&n.preferences===void 0?{}:{preferences:{...r.preferences,...n.preferences}},preset:n.preset??r.preset??"full",noAnimations:n.noAnimations??r.noAnimations??!1,noPostProcessing:n.noPostProcessing??r.noPostProcessing??!1}}o(N,"readPiAgentIdeExtensionsConfig");function c(e){return{...e.noAnimations===void 0?{}:{"pi-agent-ide-no-animations":e.noAnimations},...e.noPostProcessing===void 0?{}:{"pi-agent-ide-no-post-processing":e.noPostProcessing},...e.flags}}o(c,"configuredFeatureFlags");async function k(e){return l(e)}o(k,"readExtensionSettingsScope");async function l(e){let r;try{r=await y(e,"utf8")}catch(t){if(w(t))return{disabled:[],enabled:[]};throw new Error(`Cannot read Pi Agent IDE extension config at ${e}: ${p(t)}`,{cause:t})}let n;try{n=JSON.parse(r)}catch(t){throw new Error(`Invalid JSON in Pi Agent IDE extension config at ${e}: ${p(t)}`,{cause:t})}if(!d(n))throw new Error(`Pi Agent IDE extension config at ${e} must be a JSON object`);return{disabled:u(n,"disabled",e),enabled:u(n,"enabled",e),...n.flags===void 0?{}:{flags:E(n.flags,e)},...n.preferences===void 0?{}:{preferences:m(n.preferences,e)},...n.preset===void 0?{}:{preset:g(n.preset,e)},...n.noAnimations===void 0?{}:{noAnimations:f(n,"noAnimations",e)},...n.noPostProcessing===void 0?{}:{noPostProcessing:f(n,"noPostProcessing",e)}}}o(l,"readConfigExtensionIds");function m(e,r){if(!d(e))throw new Error(`preferences in ${r} must be an object`);let n={};for(let[t,s]of Object.entries(e)){if(typeof s!="string"||s.length===0)throw new Error(`Preference ${t} in ${r} must be a non-empty string`);n[t]=s}return n}o(m,"readPreferences");function E(e,r){if(!d(e))throw new Error(`flags in ${r} must be an object`);let n={};for(let[t,s]of Object.entries(e)){if(typeof s!="boolean")throw new Error(`Flag ${t} in ${r} must be a boolean`);n[t]=s}return n}o(E,"readFlags");function f(e,r,n){let t=e[r];if(typeof t!="boolean")throw new Error(`${r} in ${n} must be a boolean`);return t}o(f,"readBoolean");function u(e,r,n){let t=e[r];if(t===void 0)return[];if(!Array.isArray(t))throw new Error(`${r} in ${n} must be an array of non-empty strings`);let s=t.filter(a=>typeof a=="string");if(s.length!==t.length||s.some(a=>a.length===0))throw new Error(`${r} in ${n} must be an array of non-empty strings`);if(new Set(s).size!==s.length)throw new Error(`${r} in ${n} must not contain duplicate IDs`);return s}o(u,"readIdField");function w(e){return d(e)&&e.code==="ENOENT"}o(w,"isMissingFile");function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(d,"isRecord");function p(e){return e instanceof Error?e.message:String(e)}o(p,"errorMessage");export{A as a,I as b,D as c,N as d,c as e,k as f};
@@ -0,0 +1,16 @@
1
+ import{a as b,d as A}from"./chunk-ITSNK5YG.js";import{a as N}from"./chunk-FA6BKC5Y.js";import{b as F,d as $}from"./chunk-VCTK4JSN.js";import{f as M}from"./chunk-YHUTTZC6.js";import{a as u}from"./chunk-EI7MMDWY.js";import L from"node:path";import{truncateHead as _,DEFAULT_MAX_BYTES as te,DEFAULT_MAX_LINES as re}from"@earendil-works/pi-coding-agent";import{Text as S}from"@earendil-works/pi-tui";import{Type as O}from"typebox";import{Value as ne}from"typebox/value";var I=O.Union([O.String({minLength:1}),N]),v=O.Object({before:I,after:I},{additionalProperties:!1});async function oe(e,i,c){if(!ne.Check(v,i))throw Object.assign(new Error("Use before and after source strings or read request objects"),{code:"INVALID_ARGUMENTS"});let n=i,r=u(async s=>{let t=typeof s=="string"?{path:s}:s,p=await e.read(t,c,"script");if(p.isError||p.details.failure)throw Object.assign(new Error(p.details.failure?.message??"Comparison read failed"),{code:p.details.failure?.code??"READ_FAILED",details:p.details.failure});if(p.script===void 0)throw Object.assign(new Error("Source has no comparable text data"),{code:"UNSUPPORTED_CONTENT"});return B(p.script,t.path??"source")},"resolve"),o=await r(n.before),a=await r(n.after),l=b(o.source,o.content,a.content,a.source);return{kind:"diff",ok:!0,equal:o.content===a.content,before:o,after:a,...l}}u(oe,"executeDiff");function B(e,i){if(e.kind==="text")return{source:e.source,sources:[e.source],content:e.content};if(e.kind==="resources"){let c=e.resources.map(n=>B(n,i));return{source:e.source??i,sources:c.flatMap(n=>n.sources),content:c.map(n=>n.content).join(`
2
+ `)}}if(e.kind==="bytes")throw Object.assign(new Error(`Byte sources are not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});if(e.blocks.length===0||e.blocks.some(c=>c.type!=="text"))throw Object.assign(new Error(`Source is not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});return{source:e.source,sources:[e.source],content:e.blocks.flatMap(c=>c.type==="text"?[c.text]:[]).join(`
3
+ `)}}u(B,"comparisonText");function R(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="diff"&&"ok"in e&&e.ok===!0}u(R,"isDiffOutcome");function T(e,i=process.cwd()){let c=u(r=>L.isAbsolute(r)?L.relative(i,r)||".":r,"displaySource"),n=`Diff: ${c(e.before.source)} \u2192 ${c(e.after.source)}`;return{results:[new A({ok:!0,path:n,beforeContentMap:{[n]:e.before.content},afterContent:e.after.content,diffs:[e.diff]})]}}u(T,"diffPresentation");function k(e){return e.equal?`No differences: ${e.before.source} \u2192 ${e.after.source}`:e.diff}u(k,"diffText");function Pe(e){return{content:[{type:"text",text:k(e)}],details:{}}}u(Pe,"diffReadResult");function Ee(e,i,c){e.registerTool({name:"diff",label:"Diff",parameters:v,promptSnippet:"Compare two text-readable sources",description:"Use diff to compare two sources. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference. The same diff function is available inside Apply.",renderCall(n,r){return new S(r.fg("toolTitle",r.bold("Diff")),0,0)},renderResult(n,r,o,a){let l=n.details;if(l?.comparison?.equal)return new S(k(l.comparison),0,0);let s=i.getToolRenderer("diff")?.renderResult;return s?s(n,r,o,a):new S(n.content.filter(t=>t.type==="text").map(t=>t.text).join(`
4
+ `),0,0)},async execute(n,r,o,a,l){let s=c();if(s===void 0)throw new Error("Diff requires the read extension");let t=await oe(s,r,{cwd:l.cwd,signal:o}),p=k(t),y=_(p).truncated?await s.saveTemporary(p):void 0,f=y===void 0?"":`
5
+ Full diff: ${y}`;return{content:[{type:"text",text:y===void 0?p:_(p,{maxLines:re-2,maxBytes:te-Buffer.byteLength(f)}).content+f}],details:{...T(t,l.cwd),comparison:t,temporarySource:y}}}})}u(Ee,"registerDiff");import{parser as q}from"@lezer/javascript";import{TreeFragment as U}from"@lezer/common";var ie=new Set(["read","search","diff","open","createFile","deleteFile","copyFile","moveFile","flush","result"]);function V(e,i=q.parse(e)){let c=[];i.iterate({enter(r){if(r.name==="AssignmentExpression"){let t=r.node.firstChild;t?.name==="VariableName"&&c.push({name:e.slice(t.from,t.to),from:0,to:e.length})}if(r.name!=="VariableDefinition")return;let o=r.node.parent;for(;o?.parent&&!["VariableDeclaration","ParamList","Block","Script"].includes(o.name);)o=o.parent;let a=o?.name==="VariableDeclaration"&&o.firstChild?.name==="var",l=new Set(["Script","FunctionDeclaration","FunctionExpression","ArrowFunction",...a?[]:["Block"]]),s=r.node.parent;for(s?.name==="FunctionDeclaration"&&(s=s.parent);s?.parent&&!l.has(s.name);)s=s.parent;c.push({name:e.slice(r.from,r.to),from:s?.from??0,to:s?.to??e.length})}});let n=[];return i.iterate({enter(r){if(r.name!=="CallExpression")return;let o=r.node.firstChild;if(o?.name!=="VariableName")return;let a=e.slice(o.from,o.to);if(!ie.has(a)||c.some(t=>t.name===a&&t.from<=r.from&&t.to>=r.to))return;let l=r.node.getChild("ArgList")?.getChild("ObjectExpression"),s=Object.create(null);if(!l){let t=r.node.getChild("ArgList"),p=t?e.slice(t.from+1,t.to).replace(/\)$/,""):"";p&&(s.arguments={text:p.length>160?p.slice(0,120)+"\u2026":p,literal:!1})}for(let t of l?.getChildren("Property")??[]){let p=t.firstChild,y=(p?e.slice(p.from,p.to):"").replace(/^["']|["']$/g,"");if(!/^[a-zA-Z_$][\w$]*$/.test(y)){for(let ee of["path","query","target","before","after"])delete s[ee];let w=e.slice(t.from,t.to);s[`argument@${t.from}`]={text:w.length>160?w.slice(0,160)+"\u2026":w,literal:!1};continue}let f=t.lastChild;if(!f||f.type.isError||f.name===":")continue;let m=e.slice(f.from,f.to),d=m.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t"),h=/^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(m);s[y]={text:d.length>160&&!h?`${d.slice(0,100)}\u2026${d.slice(-40)} (${m.length} source chars)`:d,literal:["String","Number","BooleanLiteral","Null"].includes(f.name)&&f.lastChild?.type.isError!==!0}}return n.push({name:a,from:r.from,to:r.to,path:s.path,query:s.query,target:s.target,before:s.before,after:s.after,arguments:s}),!1}}),n}u(V,"parseApplyCalls");function se(e,i=V(e),c,n=r=>r){let r=0,o=[],a=u(l=>n(l.split(`
6
+ `).map(s=>s.length>200?s.slice(0,200)+"\u2026":s).join(`
7
+ `)),"codePreview");for(let l of i)o.push(a(e.slice(r,l.from))),o.push(c?.(l)??`${l.name}(${l.path?l.path.literal?l.path.text:`\u2039${l.path.text}\u203A`:"\u2026"})`),r=l.to;return o.push(a(e.slice(r))),o.join("")}u(se,"compactApplySource");function J(e,i){let c="",n="",r=[];return o=>{if(o===c)return n;let a=0;for(;a<c.length&&a<o.length&&c[a]===o[a];)a++;r=U.applyChanges(r,[{fromA:a,toA:c.length,fromB:a,toB:o.length}]);let l=q.parse(o,r);return r=U.addTree(l),n=se(o,V(o,l),e,i),c=o,n}}u(J,"createApplySourceProjection");import{lstat as G,unlink as ae}from"node:fs/promises";import Y from"node:path";import z from"fs-extra";import{Type as x}from"typebox";import{Value as le}from"typebox/value";var j=x.String({minLength:1,description:"Local regular file path, relative to cwd or absolute."}),ce=x.Object({path:j},{additionalProperties:!1}),pe=x.Object({path:j,target:j,overwrite:x.Optional(x.Boolean({description:"Allow replacing an existing regular target file. Defaults to false."}))},{additionalProperties:!1});function P(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="file-operation"}u(P,"isFileOperationResult");function E(e){return[`${e.operation}: ${e.effect}`,e.path,e.target===void 0?void 0:`Target: ${e.target}`,e.error===void 0?void 0:`${e.error.code}: ${e.error.message}`].filter(i=>i!==void 0).join(`
8
+ `)}u(E,"formatFileOperation");async function Ue(e,i,c,n){let r=!1,o,a;try{let l=e==="delete"?ce:pe;if(!le.Check(l,i))throw Object.assign(new Error("Invalid file operation arguments"),{code:"INVALID_ARGUMENTS"});let s=i;o=Y.resolve(c,s.path),a=s.target===void 0?void 0:Y.resolve(c,s.target),n?.throwIfAborted();let t=await fe(o);if(a!==void 0){let p=await ue(a);if(p!==void 0){if(!p.isFile()||p.isSymbolicLink())throw Object.assign(new Error("Target must be a regular file"),{code:"INVALID_FILE_TYPE"});if(o===a||t.ino===p.ino&&t.dev===p.dev)throw Object.assign(new Error("Source and target are the same file"),{code:"SAME_FILE"});if(s.overwrite!==!0)throw Object.assign(new Error("Target exists; use overwrite: true to replace it"),{code:"EEXIST"})}}return n?.throwIfAborted(),r=!0,e==="delete"?await ae(o):a!==void 0&&(e==="copy"?await z.copy(o,a,{overwrite:s.overwrite===!0,errorOnExist:!0}):await z.move(o,a,{overwrite:s.overwrite===!0})),{kind:"file-operation",operation:e,ok:!0,effect:"applied",path:o,...a===void 0?{}:{target:a}}}catch(l){return{kind:"file-operation",operation:e,ok:!1,effect:r?"unknown":"not-applied",...o===void 0?{}:{path:o},...a===void 0?{}:{target:a},error:{code:l!==null&&typeof l=="object"&&"code"in l?String(l.code):"FILE_OPERATION_FAILED",message:l instanceof Error?l.message:String(l)}}}}u(Ue,"executeFileOperation");async function fe(e){let i=await G(e);if(!i.isFile()||i.isSymbolicLink())throw Object.assign(new Error("Source must be a regular file"),{code:"INVALID_FILE_TYPE"});return i}u(fe,"regularFile");async function ue(e){try{return await G(e)}catch(i){if(i!==null&&typeof i=="object"&&"code"in i&&i.code==="ENOENT")return;throw i}}u(ue,"optionalStat");import{Text as Z}from"@earendil-works/pi-tui";function K(e){let i=e.select(),c=e.mutationValues().filter(de);return i.files.map(n=>{let r=c.flatMap(l=>l.files.filter(s=>s.source===n.source).map(s=>({outcome:l,changed:s}))),o=e.mutationPresentation(n.source)?.data,a=o?.afterContent===n.after?o:void 0;return new A({ok:!0,path:n.source,files:[{path:n.source,action:n.before===null?"created":"edited"}],snapshot:{content:n.before??""},beforeContentMap:{[n.source]:n.before},afterContent:n.after??"",afterDocument:a?.afterDocument,resultPresentation:a?.resultPresentation,scopeMarkers:a?.scopeMarkers,hints:a?.hints,warnings:a?.warnings,diffStatuses:a?.diffStatuses,diffs:[b(n.source,n.before??"",n.after??"").diff],operations:r.map(({outcome:l,changed:s})=>({operation:l.operation==="remove"?"delete":l.operation,changes:s.changes.length})),formatting:a?.formatting??r.at(-1)?.changed.formatting})})}u(K,"finalApplyMutations");function de(e){return e!==null&&typeof e=="object"&&"operation"in e&&"files"in e&&Array.isArray(e.files)&&"effect"in e}u(de,"isMutation");import{highlightCode as Q}from"@earendil-works/pi-coding-agent";import{wrapTextWithAnsi as W,visibleWidth as X,truncateToWidth as me}from"@earendil-works/pi-tui";function nt(e,i,c,n=process.cwd()){let r=e.select(),o=[...r.automatic,...r.explicit.filter(t=>t.kind==="operation")].filter(t=>R(t.value)&&!t.value.equal),a=o.flatMap(t=>R(t.value)?[T(t.value,n)]:[]),l=new Set(o.flatMap(t=>t.presentation?.content??[]));if(r.files.length===0){let t=[...r.automatic.map(p=>p.presentation),...r.explicit.map(p=>p.kind==="operation"?p.presentation:void 0)].filter(p=>p!==void 0);return{comparisons:a,cwd:n,blocks:[...i.content.filter(p=>!l.has(p)).flatMap(p=>p.type==="text"?[{text:H(p.text),read:t.find(g=>g.content.includes(p))}]:[])]}}let s=i.mutations??K(e);return{...s.length>0?{mutations:{results:s}}:{},comparisons:a,cwd:n,blocks:[...r.explicit.flatMap(t=>t.kind==="operation"&&R(t.value)&&!t.value.equal?[]:P(t.value)?[{text:E(t.value)}]:t.kind==="operation"?t.presentation?.content.flatMap(p=>p.type==="text"?[{text:p.text,read:t.presentation}]:[])??[]:[{text:H(typeof t.value=="string"?t.value:t.value===void 0?"undefined":JSON.stringify(t.value,null,2))}]),...r.automatic.flatMap(({value:t,presentation:p})=>{if(P(t))return[{text:E(t)}];if(t!==null&&typeof t=="object"&&"kind"in t&&t.kind==="index-operation")return p?.content.flatMap(g=>g.type==="text"?[{text:g.text}]:[])??[];if(t===null||typeof t!="object"||!("errors"in t)||!Array.isArray(t.errors))return[];if("operations"in t&&Array.isArray(t.operations)){let g=t.operations.filter(f=>f!==null&&typeof f=="object"&&"status"in f&&f.status==="applied").length;if(g===t.operations.length)return[];let y=t.operations.filter(f=>f!==null&&typeof f=="object"&&"status"in f&&f.status!=="applied").map(f=>({text:we(f)}));return[{text:`Apply partially applied: ${g} of ${t.operations.length} operations completed.`},...y]}return t.errors.flatMap(g=>g!==null&&typeof g=="object"&&"message"in g&&typeof g.message=="string"?[{text:g.message}]:[])}),...c===void 0?[]:[{text:c instanceof Error?c.message:JSON.stringify(c)}]]}}u(nt,"createApplyDisplay");function D(e,i,c,n,r,o,a=!1){let l=Math.max(1,c);if(l<5)return e.split(`
9
+ `).flatMap(d=>W(d,l));let s=l-4,t=u(d=>i.fg("borderMuted",d),"border"),g=me(` ${n==="call"?"Apply \xB7 JavaScript":"Result"} `,l-4,""),y=[t(`${n==="call"?"\u256D":"\u251C"}\u2500`)+i.fg(a?"error":"accent",g)+t(`${"\u2500".repeat(Math.max(0,l-X(g)-3))}${n==="call"?"\u256E":"\u2524"}`)],f=`${t("\u2502")}${" ".repeat(l-2)}${t("\u2502")}`;for(let d of e.split(`
10
+ `)){let h=o==="diff"?i.fg(d.startsWith("+")?"toolDiffAdded":d.startsWith("-")?"toolDiffRemoved":"toolDiffContext",d):o?Q(d,o).join(`
11
+ `):i.fg("toolOutput",d);for(let w of W(h,s))y.push(`${t("\u2502")} ${w}${" ".repeat(Math.max(0,s-X(w)))} ${t("\u2502")}`)}n==="call"&&y.push(f),r&&y.push(t(`\u2570${"\u2500".repeat(l-2)}\u256F`));let m=i.getBgAnsi("toolPendingBg");return y.map(d=>m+M(d,m)+"\x1B[0m")}u(D,"applyFrameRows");function ge(e,i="compact"){return(c,n,r)=>{if(!r.expanded&&i==="disabled")return new Z(n.fg("toolTitle","apply"),0,0);let o=r.state,a=o.projectSource??=J(e?s=>e(s,n):void 0,e?s=>Q(s,"javascript").join(`
12
+ `):void 0),l=c!==null&&typeof c=="object"&&"source"in c&&typeof c.source=="string"?c.source:"";return{invalidate(){},render(s){return D(r.expanded||i==="full"?o.displaySource??l:i==="disabled"?"":ye(a(o.displaySource??l)),n,s,"call",!o.applyResultReady,r.expanded||i==="full"||!e?"javascript":void 0)}}}}u(ge,"createApplyCallRenderer");function ye(e,i=F){let c=e.split(`
13
+ `);if(c.length<=i)return e;let n=Math.max(2,i-1),r=Math.ceil(n/2),o=Math.floor(n/2),a=c.length-r-o;return[...c.slice(0,r),`\u2026 ${a} lines omitted \u2026`,...c.slice(-o)].join(`
14
+ `)}u(ye,"compactApplyPreview");var ot=ge();function he(e){return(i,c,n,r)=>{r.state.applyResultReady=!0;let o=i.details;r.state.displaySource=o?.displaySource;let a=o?.display,l=a?.blocks??[{text:r.isError?"Apply failed":"Apply finished"}],s=$({kind:"source"}),t=l.map(f=>s(f.read??{content:[{type:"text",text:f.text}],details:xe(f.text)},c,n,{...r,isError:!1,lastComponent:void 0})),p=a?.mutations,g=(a?.comparisons??[]).flatMap(f=>[e?.(f,n,c.expanded,a?.cwd??process.cwd())??new Z((f.results??[]).flatMap(d=>d.data.diffs??[]).join(`
15
+ `),0,0)]),y=p===void 0?void 0:e?.(p,n,c.expanded,a?.cwd??process.cwd());return{invalidate(){y?.invalidate();for(let f of g)f.invalidate()},render(f){let m=[];for(let d of t){let h=d.render(Math.max(1,f-4));h.length!==0&&(m.length>0&&m.push(""),m.push(...h))}for(let d of g)m.length>0&&m.push(""),m.push(...d.render(Math.max(1,f-4)));if(y!==void 0){let d=y.render(Math.max(1,f-4));m.length>0&&d.length>0&&m.push(""),m.push(...d),d.length===0&&m.push(...(p?.results??[]).map(h=>h.path??"Changed file"))}else p!==void 0&&m.push(...(p.results??[]).map(d=>d.path??"Changed file"));return m.length===0&&l.length>0&&l.every(d=>d.read?.details.diagnosticCheck?.complete&&d.read.details.diagnosticCheck.count===0)?D("",n,f,"result",!0).slice(-1):D(m.length===0?"No output":m.join(`
16
+ `),n,f,"result",!0,void 0,r.isError)}}}}u(he,"createApplyResultRenderer");function we(e){if(e===null||typeof e!="object")return String(e);let i="index"in e?Number(e.index)+1:"?",c="kind"in e?String(e.kind):"operation",n="status"in e?String(e.status):"unknown",r="error"in e&&e.error!==null&&typeof e.error=="object"?`: ${"code"in e.error?String(e.error.code):"ERROR"}: ${"message"in e.error?String(e.error.message):"Operation failed"}`:"";return`Operation ${i} (${c}): ${n}${r}`}u(we,"formatDisplayOutcome");function H(e){if(/^(?:Undo transaction:|Undo available)/u.test(e.trim()))return"";try{let i=JSON.parse(e);return JSON.stringify(C(i),null,2)}catch{return e.replace(/APPLY#[0-9A-F]{12}/gu,"Apply transaction")}}u(H,"redactApplyReceipts");function C(e){return Array.isArray(e)?e.map(C):e===null||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([i])=>i!=="transaction").map(([i,c])=>[i,C(c)]))}u(C,"redactTransactionKeys");function xe(e){try{let i=JSON.parse(e);return i!==null&&typeof i=="object"?{source:"result.json"}:{}}catch{return{}}}u(xe,"jsonDetails");var it=he();export{oe as a,Pe as b,Ee as c,Ue as d,K as e,nt as f,ge as g,ot as h,he as i,it as j};
package/dist/entry-1.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-HKMBQLEK.js";import"./chunk-Z3VC3S2T.js";import"./chunk-EI7MMDWY.js";export{a as connectIdePlugin};
1
+ import{a}from"./chunk-QDLTO5PH.js";import"./chunk-QIK2E64R.js";import"./chunk-EI7MMDWY.js";export{a as connectIdePlugin};
package/dist/entry-10.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-IQD6PON5.js";import"./chunk-FEDVTZJG.js";import{a as l}from"./chunk-L7JMDDSD.js";import{a as s,b as c}from"./chunk-O6LE42GK.js";import"./chunk-U2JKHKLK.js";import"./chunk-22CLOM2D.js";import"./chunk-NNCZYO4Q.js";import"./chunk-526E364R.js";import"./chunk-YHUTTZC6.js";import{a as g}from"./chunk-6CZO43OH.js";import{a as f,b as y}from"./chunk-OBNING2A.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function x(n,e){return u(e),g(n,{protocol:f,apiVersion:y,id:`hook/before-read/${e.id}`,setup(t){t.addResourceGuard({id:e.id,async guard(o){let r=await e.run(o);return r.decision==="allow"?{kind:"accepted"}:{kind:"rejected",reason:r.reason}}})}})}d(x,"connectBeforeReadHook");function A(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/before-edit/${e.id}`,setup(t){t.addMutationGuard({id:e.id,async guard(o,r){let a=await e.run({cwd:r.cwd,intent:r.intent??"edit",resources:o.resources.map(i=>({resourceSource:i.source,existed:i.existed,before:i.before,after:i.after,changes:i.changes})),...r.signal!==void 0&&{signal:r.signal}});return a.decision==="allow"?{kind:"accepted"}:{kind:"rejected",rejection:{code:"MUTATION_REJECTED",reason:a.reason,message:`Edit blocked by hook ${e.id}: ${a.reason}`,effect:"not-applied"}}}})}})}d(A,"connectBeforeEditHook");function m(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/after-edit/${e.id}`,setup(t){t.onDidEdit(async o=>{if(o.postProcessing!=="deferred")try{return await e.run(o)}catch(r){return{feedback:`After-edit hook ${e.id} failed after the edit was saved: ${r instanceof Error?r.message:String(r)}`,tone:"error"}}})}})}d(m,"connectAfterEditHook");function u(n){if(n.id.trim().length===0||typeof n.run!="function")throw new TypeError("A file hook needs a non-empty id and run function")}d(u,"assertHook");export{m as connectAfterEditHook,A as connectBeforeEditHook,x as connectBeforeReadHook};
1
+ import{a as o}from"./chunk-MGCHOGQD.js";import"./chunk-T6LX2RX5.js";import"./chunk-EI7MMDWY.js";export{o as connectDoctorPlugin};
package/dist/entry-11.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-K5G4FDXD.js";import"./chunk-EI7MMDWY.js";export{a as sameFilePath};
1
+ import"./chunk-IQD6PON5.js";import"./chunk-FEDVTZJG.js";import{a as l}from"./chunk-L7JMDDSD.js";import{a as s,b as c}from"./chunk-O6LE42GK.js";import"./chunk-U2JKHKLK.js";import"./chunk-FA6BKC5Y.js";import"./chunk-NNCZYO4Q.js";import"./chunk-VCTK4JSN.js";import"./chunk-YHUTTZC6.js";import{a as g}from"./chunk-6CZO43OH.js";import{a as f,b as y}from"./chunk-OBNING2A.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function x(n,e){return u(e),g(n,{protocol:f,apiVersion:y,id:`hook/before-read/${e.id}`,setup(t){t.addResourceGuard({id:e.id,async guard(o){let r=await e.run(o);return r.decision==="allow"?{kind:"accepted"}:{kind:"rejected",reason:r.reason}}})}})}d(x,"connectBeforeReadHook");function A(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/before-edit/${e.id}`,setup(t){t.addMutationGuard({id:e.id,async guard(o,r){let a=await e.run({cwd:r.cwd,intent:r.intent??"edit",resources:o.resources.map(i=>({resourceSource:i.source,existed:i.existed,before:i.before,after:i.after,changes:i.changes})),...r.signal!==void 0&&{signal:r.signal}});return a.decision==="allow"?{kind:"accepted"}:{kind:"rejected",rejection:{code:"MUTATION_REJECTED",reason:a.reason,message:`Edit blocked by hook ${e.id}: ${a.reason}`,effect:"not-applied"}}}})}})}d(A,"connectBeforeEditHook");function m(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/after-edit/${e.id}`,setup(t){t.onDidEdit(async o=>{if(o.postProcessing!=="deferred")try{return await e.run(o)}catch(r){return{feedback:`After-edit hook ${e.id} failed after the edit was saved: ${r instanceof Error?r.message:String(r)}`,tone:"error"}}})}})}d(m,"connectAfterEditHook");function u(n){if(n.id.trim().length===0||typeof n.run!="function")throw new TypeError("A file hook needs a non-empty id and run function")}d(u,"assertHook");export{m as connectAfterEditHook,A as connectBeforeEditHook,x as connectBeforeReadHook};