pi-agent-ide 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (664) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +63 -17
  3. package/dist/{chunk-2ZMMRINH.js → chunk-2K65BSXS.js} +1 -1
  4. package/dist/chunk-3G54ZL2L.js +1 -0
  5. package/dist/chunk-3ZGDMTMD.js +25 -0
  6. package/dist/{chunk-ZIWPKIBZ.js → chunk-4OYVLXWD.js} +1 -1
  7. package/dist/chunk-4W7GH3T7.js +10 -0
  8. package/dist/chunk-4XPUN4QN.js +2 -0
  9. package/dist/chunk-5KFVDYCI.js +1 -0
  10. package/dist/chunk-6EDOLYOV.js +1 -0
  11. package/dist/chunk-756K3LJY.js +1 -0
  12. package/dist/chunk-75SWXD2Z.js +9 -0
  13. package/dist/chunk-7HDK3NRQ.js +1 -0
  14. package/dist/chunk-7JV4VN73.js +1 -0
  15. package/dist/chunk-7NS3QUIE.js +9 -0
  16. package/dist/chunk-7TJ6DWW3.js +2 -0
  17. package/dist/chunk-ABFCAOU5.js +1 -0
  18. package/dist/chunk-BIG45IPN.js +2 -0
  19. package/dist/chunk-BQ67M4NC.js +3 -0
  20. package/dist/chunk-BXGMMZT3.js +1 -0
  21. package/dist/chunk-CPZJPGLG.js +1 -0
  22. package/dist/chunk-CSXHCSTH.js +9 -0
  23. package/dist/chunk-CTJV77FR.js +1 -0
  24. package/dist/chunk-DUUOCBS3.js +3 -0
  25. package/dist/chunk-E4HPRLRB.js +1 -0
  26. package/dist/chunk-EY65TFHJ.js +1 -0
  27. package/dist/{chunk-WLZIUMJL.js → chunk-GW6NZQTQ.js} +1 -1
  28. package/dist/chunk-HCN5W76B.js +1 -0
  29. package/dist/chunk-ICDI27GZ.js +1 -0
  30. package/dist/{chunk-TXOTNK6B.js → chunk-IH5NW5JX.js} +1 -1
  31. package/dist/chunk-IMGIDBCC.js +1 -0
  32. package/dist/chunk-IUSLSROY.js +1 -0
  33. package/dist/chunk-KL776TGR.js +1 -0
  34. package/dist/chunk-L2B4DTVS.js +1 -0
  35. package/dist/chunk-LEKC4GQK.js +5 -0
  36. package/dist/chunk-MKEC3U2M.js +4 -0
  37. package/dist/chunk-MOJ5RR35.js +1 -0
  38. package/dist/{chunk-H445SHSJ.js → chunk-MZXX353D.js} +1 -1
  39. package/dist/{chunk-ZTYWHL2F.js → chunk-N7LMRL64.js} +1 -1
  40. package/dist/chunk-NULNW6GK.js +1 -0
  41. package/dist/chunk-O36UC74T.js +1 -0
  42. package/dist/chunk-OFILFO6D.js +1 -0
  43. package/dist/chunk-OJX3RJ5A.js +1 -0
  44. package/dist/chunk-OLI3JPHJ.js +28 -0
  45. package/dist/{chunk-S6QRG3TQ.js → chunk-OM4LYD3S.js} +1 -1
  46. package/dist/chunk-PNP2KNGP.js +5 -0
  47. package/dist/chunk-QP2QSQ4U.js +2 -0
  48. package/dist/chunk-R2U5WXYR.js +1 -0
  49. package/dist/chunk-R5XJSEOE.js +3 -0
  50. package/dist/{chunk-7UGNGK7Y.js → chunk-RAZP42IQ.js} +1 -1
  51. package/dist/chunk-S72FVLUX.js +1 -0
  52. package/dist/chunk-SBLKPTL3.js +1 -0
  53. package/dist/chunk-SBNR4WZF.js +1 -0
  54. package/dist/chunk-SSWUUBIR.js +1 -0
  55. package/dist/chunk-T4FTT3U4.js +1 -0
  56. package/dist/chunk-TOYN4W4F.js +1 -0
  57. package/dist/chunk-TWWND6NI.js +1 -0
  58. package/dist/chunk-UBH6X3D3.js +1 -0
  59. package/dist/{chunk-QFTBY67N.js → chunk-UEVGZUII.js} +3 -3
  60. package/dist/chunk-UUJJRXHG.js +29 -0
  61. package/dist/chunk-VDP5CQHM.js +3 -0
  62. package/dist/chunk-WE42GBGU.js +4 -0
  63. package/dist/chunk-XZDOVPRC.js +1 -0
  64. package/dist/chunk-YJ6T3PEP.js +1 -0
  65. package/dist/chunk-Z3PGADVA.js +3 -0
  66. package/dist/{chunk-QDLTO5PH.js → chunk-ZAWRSA7N.js} +1 -1
  67. package/dist/entry-0.js +1 -1
  68. package/dist/entry-1.js +1 -1
  69. package/dist/entry-10.js +1 -1
  70. package/dist/entry-11.js +1 -1
  71. package/dist/entry-13.js +1 -1
  72. package/dist/entry-14.js +1 -1
  73. package/dist/entry-15.js +1 -1
  74. package/dist/entry-17.js +1 -1
  75. package/dist/entry-2.js +1 -1
  76. package/dist/entry-20.js +1 -1
  77. package/dist/entry-21.js +1 -1
  78. package/dist/entry-22.js +1 -1
  79. package/dist/entry-23.js +1 -1
  80. package/dist/entry-24.js +1 -1
  81. package/dist/entry-25.js +1 -2
  82. package/dist/entry-26.js +2 -1
  83. package/dist/entry-27.js +1 -2
  84. package/dist/entry-28.js +4 -1
  85. package/dist/entry-29.js +1 -1
  86. package/dist/entry-30.js +1 -1
  87. package/dist/entry-31.js +1 -17
  88. package/dist/entry-32.js +18 -1
  89. package/dist/entry-33.js +1 -3
  90. package/dist/entry-34.js +1 -1
  91. package/dist/entry-35.js +1 -1
  92. package/dist/entry-36.js +1 -4
  93. package/dist/entry-37.js +1 -9
  94. package/dist/entry-38.js +1 -1
  95. package/dist/entry-39.js +1 -1
  96. package/dist/entry-4.js +1 -1
  97. package/dist/entry-40.js +1 -1
  98. package/dist/entry-41.js +1 -1
  99. package/dist/entry-42.js +1 -1
  100. package/dist/entry-43.js +1 -1
  101. package/dist/entry-44.js +1 -1
  102. package/dist/entry-45.js +1 -25
  103. package/dist/entry-46.js +25 -1
  104. package/dist/entry-47.js +1 -1
  105. package/dist/entry-48.js +1 -1
  106. package/dist/entry-49.js +1 -1
  107. package/dist/entry-50.js +1 -3
  108. package/dist/entry-51.js +3 -13
  109. package/dist/entry-52.js +13 -1
  110. package/dist/entry-53.js +1 -1
  111. package/dist/entry-54.js +1 -1
  112. package/dist/entry-55.js +1 -1
  113. package/dist/entry-56.js +1 -1
  114. package/dist/entry-57.js +1 -1
  115. package/dist/entry-58.js +1 -1
  116. package/dist/entry-59.js +1 -1
  117. package/dist/entry-60.js +1 -1
  118. package/dist/entry-61.js +1 -0
  119. package/dist/entry-62.js +0 -1
  120. package/dist/entry-63.js +1 -0
  121. package/dist/entry-64.js +0 -1
  122. package/dist/entry-65.js +1 -1
  123. package/dist/entry-66.js +1 -1
  124. package/dist/entry-67.js +1 -1
  125. package/dist/entry-68.js +1 -1
  126. package/dist/entry-69.js +1 -1
  127. package/dist/entry-70.js +1 -1
  128. package/dist/entry-71.js +1 -0
  129. package/dist/entry-72.js +0 -1
  130. package/dist/entry-73.js +1 -0
  131. package/dist/entry-74.js +0 -1
  132. package/dist/entry-75.js +1 -1
  133. package/dist/entry-76.js +1 -1
  134. package/dist/entry-77.js +1 -80
  135. package/dist/entry-78.js +76 -15
  136. package/dist/entry-79.js +21 -2
  137. package/dist/entry-8.js +1 -1
  138. package/dist/entry-80.js +2 -1
  139. package/dist/entry-81.js +1 -1
  140. package/dist/entry-82.js +1 -5
  141. package/dist/entry-83.js +1 -3
  142. package/dist/entry-84.js +3 -1
  143. package/dist/entry-85.js +1 -1
  144. package/dist/entry-86.js +1 -1
  145. package/dist/entry-87.js +1 -0
  146. package/dist/pi-agent-ide.js +19 -19
  147. package/docs/agent-guides/debugger.md +2 -0
  148. package/docs/agent-guides/editing.md +1 -1
  149. package/docs/agent-guides/search-code.md +4 -1
  150. package/docs/agent-guides/ssh.md +58 -0
  151. package/docs/agent-guides/vision.md +6 -0
  152. package/docs/configuration.md +34 -0
  153. package/docs/tools.md +21 -14
  154. package/docs/user-hooks.md +5 -3
  155. package/node_modules/pi-agent-doctor/package.json +6 -2
  156. package/node_modules/pi-agent-doctor/src/evidence.ts +49 -4
  157. package/node_modules/pi-agent-doctor/src/executable.ts +46 -16
  158. package/node_modules/pi-agent-doctor/src/fixtures/executable-probe.ts +78 -0
  159. package/node_modules/pi-agent-doctor/src/fixtures/probe-executable-wait.mjs +10 -0
  160. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +6 -0
  161. package/node_modules/pi-agent-doctor/src/project-probes.ts +73 -0
  162. package/node_modules/pi-agent-doctor/src/workspace.ts +106 -0
  163. package/node_modules/pi-agent-documentation/package.json +2 -2
  164. package/node_modules/pi-agent-documentation/runtime/entry-25.js +1 -0
  165. package/node_modules/pi-agent-filesystem/package.json +8 -8
  166. package/node_modules/pi-agent-filesystem/src/resolver.ts +23 -7
  167. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  168. package/node_modules/pi-agent-filesystem-jq/index.ts +33 -6
  169. package/node_modules/pi-agent-filesystem-jq/package.json +6 -6
  170. package/node_modules/pi-agent-filesystem-jq/src/jq.ts +67 -0
  171. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  172. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  173. package/node_modules/pi-agent-filesystem-text/runtime/entry-30.js +2 -0
  174. package/node_modules/pi-agent-ide-ast/package.json +15 -15
  175. package/node_modules/pi-agent-ide-ast/runtime/entry-31.js +0 -1
  176. package/node_modules/pi-agent-ide-ast/runtime/entry-32.js +2 -0
  177. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +2 -1
  178. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +10 -3
  179. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +4 -1
  180. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +3 -3
  181. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +13 -10
  182. package/node_modules/pi-agent-ide-ast/src/extension.ts +17 -1
  183. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +32 -4
  184. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  185. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +1 -1
  186. package/node_modules/pi-agent-ide-ast/src/search-presentation.ts +4 -3
  187. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +100 -42
  188. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +3 -2
  189. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +2 -1
  190. package/node_modules/pi-agent-ide-changes/index.ts +10 -2
  191. package/node_modules/pi-agent-ide-changes/package.json +10 -10
  192. package/node_modules/pi-agent-ide-changes/runtime/entry-33.js +0 -1
  193. package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +7 -2
  194. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +18 -1
  195. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +3 -0
  196. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +59 -7
  197. package/node_modules/pi-agent-ide-changes/src/changes/git-paths.ts +49 -0
  198. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +10 -2
  199. package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +13 -14
  200. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +2 -1
  201. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +47 -11
  202. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +6 -1
  203. package/node_modules/pi-agent-ide-formatter/index.ts +14 -2
  204. package/node_modules/pi-agent-ide-formatter/package.json +4 -4
  205. package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +47 -35
  206. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +41 -11
  207. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -28
  208. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  209. package/node_modules/pi-agent-ide-lint/index.ts +35 -4
  210. package/node_modules/pi-agent-ide-lint/package.json +8 -8
  211. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +14 -10
  212. package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +47 -39
  213. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -25
  214. package/node_modules/pi-agent-ide-lsp/index.ts +107 -25
  215. package/node_modules/pi-agent-ide-lsp/package.json +10 -10
  216. package/node_modules/pi-agent-ide-lsp/runtime/entry-38.js +2 -0
  217. package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +6 -2
  218. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +5 -1
  219. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +5 -3
  220. package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +27 -11
  221. package/node_modules/pi-agent-ide-lsp/src/lsp/abort.ts +62 -0
  222. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +245 -103
  223. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +26 -45
  224. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +1 -1
  225. package/node_modules/pi-agent-ide-lsp/src/lsp/document-uri.ts +40 -0
  226. package/node_modules/pi-agent-ide-lsp/src/lsp/file-watchers.ts +8 -1
  227. package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +24 -17
  228. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +255 -56
  229. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +51 -11
  230. package/node_modules/pi-agent-ide-lsp/src/lsp/owner-transport.ts +67 -0
  231. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +149 -18
  232. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +79 -31
  233. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +15 -12
  234. package/node_modules/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +16 -0
  235. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +67 -46
  236. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +50 -19
  237. package/node_modules/pi-agent-image/package.json +3 -3
  238. package/node_modules/pi-agent-invariant/package.json +2 -2
  239. package/node_modules/pi-agent-pdf/package.json +3 -3
  240. package/node_modules/pi-agent-read/package.json +12 -12
  241. package/node_modules/pi-agent-read/runtime/entry-45.js +0 -1
  242. package/node_modules/pi-agent-read/runtime/entry-46.js +2 -0
  243. package/node_modules/pi-agent-read/src/api/tools/read.ts +4 -2
  244. package/node_modules/pi-agent-read/src/core/extension.ts +4 -1
  245. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +143 -69
  246. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +25 -1
  247. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +67 -44
  248. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +8 -3
  249. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +20 -5
  250. package/node_modules/pi-agent-resource/package.json +2 -2
  251. package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +75 -16
  252. package/node_modules/pi-agent-resource/src/index.ts +3 -0
  253. package/node_modules/pi-agent-resource/src/resource-error.ts +17 -0
  254. package/node_modules/pi-agent-resource/src/resource.ts +23 -0
  255. package/node_modules/pi-agent-resource/src/result-targets.ts +16 -2
  256. package/node_modules/pi-agent-resource/src/validation.ts +2 -1
  257. package/node_modules/pi-agent-search/package.json +9 -9
  258. package/node_modules/pi-agent-search/runtime/entry-50.js +0 -1
  259. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  260. package/node_modules/pi-agent-search/src/api/search-parameters.ts +6 -2
  261. package/node_modules/pi-agent-search/src/api/search.ts +44 -2
  262. package/node_modules/pi-agent-search/src/core/extension.ts +2 -3
  263. package/node_modules/pi-agent-search/src/core/search-core.ts +78 -8
  264. package/node_modules/pi-agent-search-text/index.ts +35 -1
  265. package/node_modules/pi-agent-search-text/package.json +14 -12
  266. package/node_modules/pi-agent-search-text/runtime/entry-52.js +1 -0
  267. package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +10 -5
  268. package/node_modules/pi-agent-search-text/src/file-search.ts +26 -3
  269. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +54 -3
  270. package/node_modules/pi-agent-search-text/src/resolvers.ts +22 -5
  271. package/node_modules/pi-agent-search-text/src/scoped-search.ts +4 -5
  272. package/node_modules/pi-agent-search-text/src/search-backend.ts +110 -12
  273. package/node_modules/pi-agent-search-text/src/search-recipe.ts +5 -1
  274. package/node_modules/pi-agent-search-text/src/search-result.ts +1 -0
  275. package/node_modules/pi-agent-search-text/src/search-session.ts +100 -24
  276. package/node_modules/pi-agent-text/package.json +3 -3
  277. package/node_modules/pi-agent-text/runtime/entry-56.js +1 -0
  278. package/node_modules/pi-agent-text/src/text-document.ts +2 -0
  279. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  280. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-57.js +2 -0
  281. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  282. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-58.js +0 -1
  283. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-59.js +2 -0
  284. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  285. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-60.js +0 -1
  286. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-61.js +2 -0
  287. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +3 -1
  288. package/node_modules/pi-agent-text-editor/package.json +26 -26
  289. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +0 -1
  290. package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +29 -2
  291. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +3 -0
  292. package/node_modules/pi-agent-text-editor/src/api/file-operations.ts +55 -0
  293. package/node_modules/pi-agent-text-editor/src/api/file-transfers.ts +41 -0
  294. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +2 -0
  295. package/node_modules/pi-agent-text-editor/src/api/native-files.ts +127 -0
  296. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +20 -1
  297. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  298. package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +94 -80
  299. package/node_modules/pi-agent-text-editor/src/core/extension.ts +14 -2
  300. package/node_modules/pi-agent-text-editor/src/core/file-operation-guards.ts +81 -0
  301. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +21 -4
  302. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +123 -27
  303. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +30 -1
  304. package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +147 -105
  305. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  306. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +91 -14
  307. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +72 -7
  308. package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +40 -20
  309. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +4 -3
  310. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +307 -32
  311. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +79 -23
  312. package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +4 -1
  313. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  314. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +117 -27
  315. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  316. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  317. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  318. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  319. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +1 -0
  320. package/node_modules/pi-agent-web/index.ts +28 -4
  321. package/node_modules/pi-agent-web/package.json +8 -8
  322. package/node_modules/pi-agent-web/src/doctor-plugin.ts +21 -6
  323. package/node_modules/pi-agent-web/src/resolver.ts +12 -2
  324. package/node_modules/pi-agent-web/src/search.ts +2 -1
  325. package/node_modules/pi-agent-web-html/package.json +3 -3
  326. package/node_modules/pi-agent-web-image/package.json +4 -4
  327. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  328. package/node_modules/pi-agent-web-text/package.json +4 -4
  329. package/node_modules/pi-agent-web-text/runtime/entry-87.js +2 -0
  330. package/package.json +35 -35
  331. package/src/api/doctor-runtime.ts +80 -0
  332. package/src/api/doctor.ts +6 -0
  333. package/src/api/hooks.ts +3 -0
  334. package/src/api/plugin-protocol.ts +11 -1
  335. package/src/api/tool-config.ts +143 -24
  336. package/src/backend/config.ts +85 -0
  337. package/src/backend/configured-process.ts +59 -0
  338. package/src/backend/dap-java-transport.ts +112 -0
  339. package/src/backend/dap-java-worker.py +218 -0
  340. package/src/backend/dap-node-transport.ts +112 -0
  341. package/src/backend/dap-powershell-worker.py +44 -0
  342. package/src/backend/dap-r-worker.py +210 -0
  343. package/src/backend/dap-tcp-transport.ts +42 -0
  344. package/src/backend/dap-tcp-worker.py +125 -0
  345. package/src/backend/dap-transport.ts +69 -0
  346. package/src/backend/dap-unix-worker.py +63 -0
  347. package/src/backend/debugger-registration.ts +62 -0
  348. package/src/backend/debugger-workspace-owner.ts +413 -0
  349. package/src/backend/doctor-inventory-worker.py +54 -0
  350. package/src/backend/doctor-probe-worker.py +140 -0
  351. package/src/backend/doctor-registration.ts +18 -0
  352. package/src/backend/doctor-workspace.ts +381 -0
  353. package/src/backend/file-operation-resolver.ts +58 -0
  354. package/src/backend/file-revision.ts +13 -0
  355. package/src/backend/file-transfer.ts +302 -0
  356. package/src/backend/file-watch-worker.py +119 -0
  357. package/src/backend/formatter-registration.ts +114 -0
  358. package/src/backend/git-registration.ts +60 -0
  359. package/src/backend/identity.ts +47 -0
  360. package/src/backend/index.ts +12 -0
  361. package/src/backend/lint-registration.ts +102 -0
  362. package/src/backend/lsp-file-watchers.ts +220 -0
  363. package/src/backend/lsp-registration.ts +83 -0
  364. package/src/backend/lsp-transport.ts +87 -0
  365. package/src/backend/lsp-workspace-owner.ts +50 -0
  366. package/src/backend/object-transfer.ts +299 -0
  367. package/src/backend/owned-command.ts +105 -0
  368. package/src/backend/owned-process-stop.ts +36 -0
  369. package/src/backend/owned-read-command.ts +20 -0
  370. package/src/backend/process-environment.ts +77 -0
  371. package/src/backend/process-metadata-worker.py +98 -0
  372. package/src/backend/process-metadata.ts +99 -0
  373. package/src/backend/recipe-evidence-worker.py +26 -0
  374. package/src/backend/recipe-evidence.ts +77 -0
  375. package/src/backend/registration.ts +124 -0
  376. package/src/backend/registry.ts +29 -0
  377. package/src/backend/resource-resolver.ts +147 -0
  378. package/src/backend/search-environment.ts +100 -0
  379. package/src/backend/ssh-channel-worker.py +306 -0
  380. package/src/backend/ssh-channel.ts +376 -0
  381. package/src/backend/ssh-transfer-worker.py +99 -0
  382. package/src/backend/ssh-transport.ts +54 -0
  383. package/src/backend/ssh-worker.py +730 -0
  384. package/src/backend/ssh.ts +610 -0
  385. package/src/backend/tool-config-access.ts +63 -0
  386. package/src/backend/tool-project.ts +71 -0
  387. package/src/backend/vision-capture-worker.py +319 -0
  388. package/src/backend/vision-capture.ts +165 -0
  389. package/src/backend/vision-registration.ts +104 -0
  390. package/src/backend/web-browser-worker.mjs +182 -0
  391. package/src/backend/web-browser.ts +128 -0
  392. package/src/backend/web-http-worker.py +62 -0
  393. package/src/backend/web-http.ts +79 -0
  394. package/src/backend/web-owner.ts +68 -0
  395. package/src/backend/web-registration.ts +14 -0
  396. package/src/code-view/diagnostic-view.ts +2 -2
  397. package/src/code-view/reference.ts +9 -0
  398. package/src/composite/builtin-extensions.ts +9 -14
  399. package/src/composite/module-labels.ts +1 -0
  400. package/src/composite/nested-tool-rendering.ts +10 -1
  401. package/src/core/diagnostic-store.ts +32 -10
  402. package/src/core/ide-core.ts +22 -2
  403. package/src/doctor/arguments.ts +19 -0
  404. package/src/doctor/config-writer.ts +72 -29
  405. package/src/doctor/discovery.ts +53 -15
  406. package/src/doctor/extension.ts +27 -10
  407. package/src/doctor/run.ts +42 -7
  408. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +8 -8
  409. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  410. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +33 -6
  411. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +6 -6
  412. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +67 -0
  413. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  414. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  415. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-30.js +2 -0
  416. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-26.js +2 -0
  417. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +23 -7
  418. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +28 -4
  419. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  420. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  421. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  422. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  423. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  424. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +2 -0
  425. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +2 -0
  426. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/doctor-plugin.ts +21 -6
  427. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +12 -2
  428. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +2 -1
  429. package/src/extensions/pi-agent-read/package.json +12 -12
  430. package/src/extensions/pi-agent-read/runtime/entry-45.js +0 -1
  431. package/src/extensions/pi-agent-read/runtime/entry-46.js +2 -0
  432. package/src/extensions/pi-agent-read/src/api/tools/read.ts +4 -2
  433. package/src/extensions/pi-agent-read/src/core/extension.ts +4 -1
  434. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +143 -69
  435. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +25 -1
  436. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +67 -44
  437. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +8 -3
  438. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +20 -5
  439. package/src/extensions/pi-agent-search/package.json +9 -9
  440. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +35 -1
  441. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +14 -12
  442. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-52.js +1 -0
  443. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-55.js +1 -0
  444. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +10 -5
  445. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +26 -3
  446. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +54 -3
  447. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +22 -5
  448. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +4 -5
  449. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +110 -12
  450. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +5 -1
  451. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +1 -0
  452. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +100 -24
  453. package/src/extensions/pi-agent-search/runtime/entry-50.js +0 -1
  454. package/src/extensions/pi-agent-search/runtime/entry-51.js +2 -0
  455. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  456. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +6 -2
  457. package/src/extensions/pi-agent-search/src/api/search.ts +44 -2
  458. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -3
  459. package/src/extensions/pi-agent-search/src/core/search-core.ts +78 -8
  460. package/src/extensions/pi-agent-text-editor/package.json +26 -26
  461. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  462. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-57.js +2 -0
  463. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  464. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-58.js +0 -1
  465. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-59.js +2 -0
  466. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  467. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-60.js +0 -1
  468. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-61.js +2 -0
  469. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +3 -1
  470. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  471. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +117 -27
  472. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  473. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  474. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +0 -1
  475. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +2 -0
  476. package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +29 -2
  477. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +3 -0
  478. package/src/extensions/pi-agent-text-editor/src/api/file-operations.ts +55 -0
  479. package/src/extensions/pi-agent-text-editor/src/api/file-transfers.ts +41 -0
  480. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +2 -0
  481. package/src/extensions/pi-agent-text-editor/src/api/native-files.ts +127 -0
  482. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +20 -1
  483. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  484. package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +94 -80
  485. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +14 -2
  486. package/src/extensions/pi-agent-text-editor/src/core/file-operation-guards.ts +81 -0
  487. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +21 -4
  488. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +123 -27
  489. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +30 -1
  490. package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +147 -105
  491. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  492. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +91 -14
  493. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +72 -7
  494. package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +40 -20
  495. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +4 -3
  496. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +307 -32
  497. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +79 -23
  498. package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +4 -1
  499. package/src/plugins/pi-agent-ide-ast/package.json +15 -15
  500. package/src/plugins/pi-agent-ide-ast/runtime/entry-31.js +0 -1
  501. package/src/plugins/pi-agent-ide-ast/runtime/entry-32.js +2 -0
  502. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +2 -1
  503. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +10 -3
  504. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +4 -1
  505. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +3 -3
  506. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +13 -10
  507. package/src/plugins/pi-agent-ide-ast/src/extension.ts +17 -1
  508. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +32 -4
  509. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
  510. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +1 -1
  511. package/src/plugins/pi-agent-ide-ast/src/search-presentation.ts +4 -3
  512. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +100 -42
  513. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +3 -2
  514. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +2 -1
  515. package/src/plugins/pi-agent-ide-changes/index.ts +10 -2
  516. package/src/plugins/pi-agent-ide-changes/package.json +10 -10
  517. package/src/plugins/pi-agent-ide-changes/runtime/entry-33.js +0 -1
  518. package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +7 -2
  519. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +18 -1
  520. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +3 -0
  521. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +59 -7
  522. package/src/plugins/pi-agent-ide-changes/src/changes/git-paths.ts +49 -0
  523. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +10 -2
  524. package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +13 -14
  525. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +2 -1
  526. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +47 -11
  527. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +6 -1
  528. package/src/plugins/pi-agent-ide-debugger/index.ts +62 -25
  529. package/src/plugins/pi-agent-ide-debugger/src/adapter-executables.ts +3 -1
  530. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +33 -0
  531. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +150 -171
  532. package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +2 -0
  533. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +152 -58
  534. package/src/plugins/pi-agent-ide-debugger/src/workspace-owner.ts +28 -0
  535. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +4 -1
  536. package/src/plugins/pi-agent-ide-formatter/index.ts +14 -2
  537. package/src/plugins/pi-agent-ide-formatter/package.json +4 -4
  538. package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +47 -35
  539. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +41 -11
  540. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -28
  541. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  542. package/src/plugins/pi-agent-ide-lint/index.ts +35 -4
  543. package/src/plugins/pi-agent-ide-lint/package.json +8 -8
  544. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +14 -10
  545. package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +47 -39
  546. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -25
  547. package/src/plugins/pi-agent-ide-lsp/index.ts +107 -25
  548. package/src/plugins/pi-agent-ide-lsp/package.json +10 -10
  549. package/src/plugins/pi-agent-ide-lsp/runtime/entry-38.js +2 -0
  550. package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +6 -2
  551. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +5 -1
  552. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +5 -3
  553. package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +27 -11
  554. package/src/plugins/pi-agent-ide-lsp/src/lsp/abort.ts +62 -0
  555. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +245 -103
  556. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +26 -45
  557. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +1 -1
  558. package/src/plugins/pi-agent-ide-lsp/src/lsp/document-uri.ts +40 -0
  559. package/src/plugins/pi-agent-ide-lsp/src/lsp/file-watchers.ts +8 -1
  560. package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +24 -17
  561. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +255 -56
  562. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +51 -11
  563. package/src/plugins/pi-agent-ide-lsp/src/lsp/owner-transport.ts +67 -0
  564. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +149 -18
  565. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +79 -31
  566. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +15 -12
  567. package/src/plugins/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +16 -0
  568. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +67 -46
  569. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +50 -19
  570. package/src/plugins/pi-agent-ide-processes/src/registry.ts +8 -1
  571. package/src/plugins/pi-agent-ide-terminal/index.ts +7 -0
  572. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +5 -1
  573. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -2
  574. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +161 -42
  575. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +7 -0
  576. package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +11 -0
  577. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +33 -8
  578. package/src/plugins/pi-agent-ide-terminal/src/types.ts +5 -0
  579. package/src/plugins/pi-agent-ide-vision/index.ts +170 -9
  580. package/src/plugins/pi-agent-ide-vision/src/doctor-plugin.ts +47 -0
  581. package/src/plugins/pi-agent-ide-vision/src/vision.ts +42 -1
  582. package/src/post-edit/gate.ts +4 -1
  583. package/src/toolchain/types.ts +2 -0
  584. package/dist/chunk-3YK4XMWB.js +0 -0
  585. package/dist/chunk-5JELU6RV.js +0 -7
  586. package/dist/chunk-6U5OU77O.js +0 -3
  587. package/dist/chunk-7LD2OQH3.js +0 -14
  588. package/dist/chunk-BYZSBXUK.js +0 -2
  589. package/dist/chunk-CEX73RI5.js +0 -28
  590. package/dist/chunk-DZWTKF2K.js +0 -1
  591. package/dist/chunk-EOKEQ3YH.js +0 -25
  592. package/dist/chunk-HZ5BNF3A.js +0 -1
  593. package/dist/chunk-IG56UGSO.js +0 -2
  594. package/dist/chunk-KVHDMIZS.js +0 -3
  595. package/dist/chunk-M5IVSCR2.js +0 -1
  596. package/dist/chunk-M5MJP7Z2.js +0 -1
  597. package/dist/chunk-MGCHOGQD.js +0 -1
  598. package/dist/chunk-N34ATN52.js +0 -1
  599. package/dist/chunk-NHKPP2AI.js +0 -28
  600. package/dist/chunk-OB46OPMZ.js +0 -1
  601. package/dist/chunk-Q6CZ6GBR.js +0 -3
  602. package/dist/chunk-QIK2E64R.js +0 -1
  603. package/dist/chunk-SBP3ABH4.js +0 -5
  604. package/dist/chunk-STBJO3Z3.js +0 -2
  605. package/dist/chunk-T6LX2RX5.js +0 -1
  606. package/dist/chunk-WZI4YC2O.js +0 -1
  607. package/node_modules/pi-agent-filesystem/runtime/entry-25.js +0 -2
  608. package/node_modules/pi-agent-ide-ast/runtime/entry-30.js +0 -1
  609. package/node_modules/pi-agent-ide-changes/runtime/entry-32.js +0 -1
  610. package/node_modules/pi-agent-image/runtime/entry-38.js +0 -1
  611. package/node_modules/pi-agent-resource/runtime/entry-46.js +0 -1
  612. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-56.js +0 -2
  613. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-57.js +0 -1
  614. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-59.js +0 -1
  615. package/node_modules/pi-agent-text-editor/runtime/entry-61.js +0 -1
  616. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +0 -1
  617. package/node_modules/pi-agent-web/runtime/entry-82.js +0 -2
  618. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-26.js +0 -2
  619. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-25.js +0 -2
  620. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +0 -2
  621. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +0 -2
  622. package/src/extensions/pi-agent-read/runtime/entry-41.js +0 -1
  623. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-51.js +0 -2
  624. package/src/extensions/pi-agent-search/runtime/entry-47.js +0 -1
  625. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-56.js +0 -2
  626. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-57.js +0 -1
  627. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-59.js +0 -1
  628. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +0 -2
  629. package/src/extensions/pi-agent-text-editor/runtime/entry-61.js +0 -1
  630. package/src/plugins/pi-agent-ide-ast/runtime/entry-30.js +0 -1
  631. package/src/plugins/pi-agent-ide-changes/runtime/entry-32.js +0 -1
  632. /package/node_modules/{pi-agent-documentation → pi-agent-doctor}/runtime/entry-24.js +0 -0
  633. /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-26.js +0 -0
  634. /package/node_modules/{pi-agent-filesystem-jq → pi-agent-filesystem-image}/runtime/entry-27.js +0 -0
  635. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-jq}/runtime/entry-28.js +0 -0
  636. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-29.js +0 -0
  637. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-34.js +0 -0
  638. /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-35.js +0 -0
  639. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-36.js +0 -0
  640. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-37.js +0 -0
  641. /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-39.js +0 -0
  642. /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-40.js +0 -0
  643. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-41.js +0 -0
  644. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-47.js +0 -0
  645. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-51.js +0 -0
  646. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-55.js +0 -0
  647. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-78.js +0 -0
  648. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
  649. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-81.js +0 -0
  650. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-83.js +0 -0
  651. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  652. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  653. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  654. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-jq → pi-agent-filesystem-image}/runtime/entry-27.js +0 -0
  655. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-jq}/runtime/entry-28.js +0 -0
  656. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-29.js +0 -0
  657. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  658. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  659. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  660. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
  661. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-34.js +0 -0
  662. /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-35.js +0 -0
  663. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-36.js +0 -0
  664. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-37.js +0 -0
@@ -0,0 +1,306 @@
1
+ """Transient framed pipe/PTY channel for remote services. Nothing is installed remotely."""
2
+ import base64
3
+ import errno
4
+ import fcntl
5
+ import json
6
+ import os
7
+ import pty
8
+ import selectors
9
+ import signal
10
+ import struct
11
+ import subprocess
12
+ import sys
13
+ import termios
14
+ import time
15
+
16
+ FRAME_LIMIT = 65536
17
+ # Match the bounded startup request; interactive control frames keep their smaller limit.
18
+ REQUEST_LIMIT = 48 * 1024 * 1024
19
+ CHUNK_SIZE = 16384
20
+ process = None
21
+ master = None
22
+
23
+
24
+ class ChannelError(Exception):
25
+ def __init__(self, code):
26
+ self.code = code
27
+
28
+
29
+ def emit(event):
30
+ sys.stdout.write(json.dumps(event, ensure_ascii=True) + "\n")
31
+ sys.stdout.flush()
32
+
33
+
34
+ def interrupted(_signum, _frame):
35
+ raise ChannelError("CANCELLED")
36
+
37
+
38
+ for signum in (signal.SIGHUP, signal.SIGTERM, signal.SIGINT):
39
+ signal.signal(signum, interrupted)
40
+
41
+
42
+ def initial_request():
43
+ data = bytearray()
44
+ while len(data) <= REQUEST_LIMIT:
45
+ byte = os.read(0, 1)
46
+ if not byte:
47
+ raise ChannelError("CANCELLED")
48
+ if byte == b"\n":
49
+ return json.loads(data)
50
+ data.extend(byte)
51
+ raise ChannelError("FRAME_LIMIT")
52
+
53
+
54
+ def resize(cols, rows):
55
+ if master is None:
56
+ raise ChannelError("PTY_REQUIRED")
57
+ if not isinstance(cols, int) or not isinstance(rows, int) or not (1 <= cols <= 1000 and 1 <= rows <= 1000):
58
+ raise ChannelError("INVALID_REQUEST")
59
+ fcntl.ioctl(master, termios.TIOCSWINSZ, struct.pack("HHHH", rows, cols, 0, 0))
60
+ if process is not None:
61
+ try:
62
+ os.killpg(process.pid, signal.SIGWINCH)
63
+ except ProcessLookupError:
64
+ pass
65
+
66
+
67
+ def controlling_terminal():
68
+ os.setsid()
69
+ fcntl.ioctl(0, termios.TIOCSCTTY, 0)
70
+
71
+
72
+ def kill_group(sig):
73
+ # A reaped leader no longer grants authority over its numeric process-group ID.
74
+ if process is not None and process.poll() is None:
75
+ try:
76
+ os.killpg(process.pid, sig)
77
+ except ProcessLookupError:
78
+ pass
79
+
80
+
81
+ def enable_subreaper():
82
+ # The kernel keeps orphaned descendants with this channel, even after setsid().
83
+ try:
84
+ import ctypes
85
+ libc = ctypes.CDLL(None, use_errno=True)
86
+ prctl = libc.prctl
87
+ except (ImportError, OSError, AttributeError):
88
+ raise ChannelError("CAPABILITY_UNAVAILABLE")
89
+ prctl.argtypes = [ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong]
90
+ prctl.restype = ctypes.c_int
91
+ if prctl(36, 1, 0, 0, 0) != 0: # PR_SET_CHILD_SUBREAPER
92
+ raise ChannelError(errno.errorcode.get(ctypes.get_errno(), "CAPABILITY_UNAVAILABLE"))
93
+ signal.signal(signal.SIGCHLD, signal.SIG_DFL)
94
+
95
+
96
+ def stop_adopted_children():
97
+ # Read only our direct kernel children, not a system-wide ancestry snapshot.
98
+ directory = "/proc/self/task/" + str(os.getpid()) + "/children"
99
+ with open(directory, encoding="utf-8") as stream:
100
+ children = [int(value) for value in stream.read().split()]
101
+ pending = False
102
+ for pid in children:
103
+ if process is not None and pid == process.pid:
104
+ continue
105
+ # A running child cannot reuse its PID before this single-threaded parent reaps it.
106
+ reaped, _status = os.waitpid(pid, os.WNOHANG)
107
+ if reaped == 0:
108
+ os.kill(pid, signal.SIGKILL)
109
+ pending = True
110
+ return pending
111
+
112
+
113
+ def finish_children():
114
+ deadline = time.monotonic() + 2
115
+ kill_group(signal.SIGKILL)
116
+ while process.poll() is None or stop_adopted_children():
117
+ if time.monotonic() >= deadline:
118
+ raise ChannelError("PROCESS_CLEANUP_FAILED")
119
+ time.sleep(0.02)
120
+
121
+ def child_identity():
122
+ # A reaped child may already have disappeared. Missing metadata never grants PID ownership.
123
+ try:
124
+ with open("/proc/sys/kernel/random/boot_id", encoding="utf-8") as stream:
125
+ boot_id = stream.read(128).strip()
126
+ with open("/proc/" + str(process.pid) + "/stat", encoding="utf-8") as stream:
127
+ raw = stream.read(65536)
128
+ ticks = raw[raw.rfind(")") + 2:].split()[19]
129
+ return boot_id + ":" + ticks if process.poll() is None else None
130
+ except (OSError, IndexError):
131
+ return None
132
+
133
+ def run():
134
+ global process, master
135
+ request = initial_request()
136
+ enable_subreaper()
137
+ dimensions = request.get("pty")
138
+ if dimensions is None:
139
+ process = subprocess.Popen(
140
+ [request["command"], *request["args"]], cwd=request["cwd"],
141
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
142
+ start_new_session=True,
143
+ )
144
+ input_fd = process.stdin.fileno()
145
+ outputs = {name: getattr(process, name).fileno() for name in ("stdout", "stderr")}
146
+ else:
147
+ master, slave = pty.openpty()
148
+ try:
149
+ resize(dimensions["cols"], dimensions["rows"])
150
+ process = subprocess.Popen(
151
+ [request["command"], *request["args"]], cwd=request["cwd"],
152
+ stdin=slave, stdout=slave, stderr=slave,
153
+ env={**os.environ, "TERM": "xterm-256color"},
154
+ preexec_fn=controlling_terminal,
155
+ )
156
+ finally:
157
+ os.close(slave)
158
+ input_fd = master
159
+ outputs = {"stdout": master}
160
+ identity = child_identity()
161
+ emit({"kind": "ready", "pid": process.pid, **({"identity": identity} if identity is not None else {})})
162
+ incoming = bytearray()
163
+ pending_input = None
164
+ stopping = None
165
+ descendant_deadline = None
166
+ input_open = True
167
+ with selectors.DefaultSelector() as selected:
168
+ os.set_blocking(0, False)
169
+ selected.register(0, selectors.EVENT_READ, "control")
170
+ for name, fd in outputs.items():
171
+ os.set_blocking(fd, False)
172
+ selected.register(fd, selectors.EVENT_READ, "pty" if fd == master else name)
173
+ os.set_blocking(input_fd, False)
174
+
175
+ def input_poll(active):
176
+ if master is not None:
177
+ if "stdout" in outputs:
178
+ selected.modify(master, selectors.EVENT_READ | (selectors.EVENT_WRITE if active else 0), "pty")
179
+ elif active:
180
+ selected.register(input_fd, selectors.EVENT_WRITE, "input")
181
+ else:
182
+ selected.unregister(input_fd)
183
+
184
+ while True:
185
+ if stopping is not None and time.monotonic() >= stopping:
186
+ kill_group(signal.SIGKILL)
187
+ stopping = None
188
+ descendants_pending = False
189
+ if process.poll() is not None:
190
+ kill_group(signal.SIGKILL)
191
+ descendants_pending = stop_adopted_children()
192
+ if descendants_pending:
193
+ if descendant_deadline is None:
194
+ descendant_deadline = time.monotonic() + 2
195
+ elif time.monotonic() >= descendant_deadline:
196
+ raise ChannelError("PROCESS_CLEANUP_FAILED")
197
+ if not outputs and process.poll() is not None and not descendants_pending:
198
+ emit({"kind": "exit", "exitCode": process.returncode})
199
+ return
200
+ for key, events in selected.select(0.1):
201
+ if key.data in ("input", "pty") and events & selectors.EVENT_WRITE and pending_input is not None:
202
+ request_id, data, offset = pending_input
203
+ try:
204
+ count = os.write(input_fd, data[offset:])
205
+ except OSError as error:
206
+ if error.errno not in (errno.EPIPE, errno.EIO):
207
+ raise
208
+ if stopping is None and process.poll() is None:
209
+ raise ChannelError("INPUT_CLOSED")
210
+ input_poll(False)
211
+ pending_input = None
212
+ continue
213
+ offset += count
214
+ if offset == len(data):
215
+ input_poll(False)
216
+ pending_input = None
217
+ emit({"kind": "ack", "id": request_id})
218
+ else:
219
+ pending_input = (request_id, data, offset)
220
+ if key.data in ("stdout", "stderr", "pty") and events & selectors.EVENT_READ:
221
+ try:
222
+ chunk = os.read(key.fd, CHUNK_SIZE)
223
+ except OSError as error:
224
+ if key.data != "pty" or error.errno != errno.EIO:
225
+ raise
226
+ chunk = b""
227
+ name = "stdout" if key.data == "pty" else key.data
228
+ if chunk:
229
+ emit({"kind": name, "bytes": base64.b64encode(chunk).decode("ascii")})
230
+ else:
231
+ selected.unregister(key.fd)
232
+ outputs.pop(name)
233
+ if key.data == "pty":
234
+ pending_input = None
235
+ input_open = False
236
+ elif key.data == "control":
237
+ chunk = os.read(0, FRAME_LIMIT)
238
+ if not chunk:
239
+ raise ChannelError("CANCELLED")
240
+ incoming.extend(chunk)
241
+ while b"\n" in incoming:
242
+ line, _, remainder = incoming.partition(b"\n")
243
+ incoming = bytearray(remainder)
244
+ if len(line) > FRAME_LIMIT:
245
+ raise ChannelError("FRAME_LIMIT")
246
+ event = json.loads(line)
247
+ if event["kind"] == "input":
248
+ if pending_input is not None or not input_open:
249
+ raise ChannelError("INVALID_REQUEST")
250
+ data = base64.b64decode(event["bytes"], validate=True)
251
+ if len(data) > CHUNK_SIZE:
252
+ raise ChannelError("FRAME_LIMIT")
253
+ if not data:
254
+ emit({"kind": "ack", "id": event["id"]})
255
+ else:
256
+ pending_input = (event["id"], data, 0)
257
+ input_poll(True)
258
+ elif event["kind"] == "resize":
259
+ resize(event["cols"], event["rows"])
260
+ emit({"kind": "ack", "id": event["id"]})
261
+ elif event["kind"] == "end":
262
+ if master is not None:
263
+ raise ChannelError("PTY_INPUT_NOT_CLOSABLE")
264
+ if pending_input is not None:
265
+ raise ChannelError("INVALID_REQUEST")
266
+ process.stdin.close()
267
+ input_open = False
268
+ elif event["kind"] == "stop":
269
+ if pending_input is not None:
270
+ input_poll(False)
271
+ pending_input = None
272
+ if master is None and not process.stdin.closed:
273
+ process.stdin.close()
274
+ input_open = False
275
+ kill_group(signal.SIGTERM)
276
+ stopping = time.monotonic() + 2
277
+ else:
278
+ raise ChannelError("INVALID_REQUEST")
279
+ if len(incoming) > FRAME_LIMIT:
280
+ raise ChannelError("FRAME_LIMIT")
281
+
282
+
283
+ try:
284
+ run()
285
+ except ChannelError as error:
286
+ emit({"kind": "error", "code": error.code, "effect": "unknown" if process is not None else "not-applied"})
287
+ except OSError as error:
288
+ emit({"kind": "error", "code": errno.errorcode.get(error.errno, "REMOTE_OPERATION_FAILED"), "effect": "unknown" if process is not None else "not-applied"})
289
+ except Exception:
290
+ emit({"kind": "error", "code": "INVALID_REQUEST", "effect": "unknown" if process is not None else "not-applied"})
291
+ finally:
292
+ if process is not None:
293
+ for signum in (signal.SIGHUP, signal.SIGTERM, signal.SIGINT):
294
+ signal.signal(signum, signal.SIG_IGN)
295
+ try:
296
+ finish_children()
297
+ except ChannelError as error:
298
+ emit({"kind": "error", "code": error.code, "effect": "unknown"})
299
+ except OSError as error:
300
+ emit({"kind": "error", "code": errno.errorcode.get(error.errno, "PROCESS_CLEANUP_FAILED"), "effect": "unknown"})
301
+ for name in ("stdin", "stdout", "stderr"):
302
+ stream = getattr(process, name)
303
+ if stream is not None and not stream.closed:
304
+ stream.close()
305
+ if master is not None:
306
+ os.close(master)
@@ -0,0 +1,376 @@
1
+ import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
2
+ import { PassThrough, type Readable } from "node:stream";
3
+ import { Type, type Static } from "typebox";
4
+ import { Value } from "typebox/value";
5
+
6
+ import { remoteLocation } from "./identity.js";
7
+ import { SshBackendError, type SshTarget, type BackendOperationContext } from "./ssh.js";
8
+ import {
9
+ sshFailureCode,
10
+ sshWorkerCommand,
11
+ systemSshArguments,
12
+ validateSshTarget,
13
+ } from "./ssh-transport.js";
14
+
15
+ const frameSchema = Type.Union([
16
+ Type.Object({
17
+ kind: Type.Literal("ready"),
18
+ pid: Type.Integer({ minimum: 1 }),
19
+ identity: Type.Optional(Type.String({ pattern: "^[a-f0-9-]+:[0-9]+$" })),
20
+ }),
21
+ Type.Object({ kind: Type.Literal("ack"), id: Type.Integer({ minimum: 1 }) }),
22
+ Type.Object({
23
+ kind: Type.Union([Type.Literal("stdout"), Type.Literal("stderr")]),
24
+ bytes: Type.String({ maxLength: 32768 }),
25
+ }),
26
+ Type.Object({ kind: Type.Literal("exit"), exitCode: Type.Integer() }),
27
+ Type.Object({
28
+ kind: Type.Literal("error"),
29
+ code: Type.String({ pattern: "^[A-Z][A-Z0-9_]*$" }),
30
+ effect: Type.Union([Type.Literal("not-applied"), Type.Literal("unknown")]),
31
+ }),
32
+ ]);
33
+ type Frame = Static<typeof frameSchema>;
34
+
35
+ /** Service startup and optional remote terminal dimensions. */
36
+ export interface SshProcessContext extends BackendOperationContext {
37
+ readonly pty?: { readonly cols: number; readonly rows: number };
38
+ }
39
+ /** Exact remote process streams. Drain both output streams while the channel is running. */
40
+ export interface SshProcessChannel {
41
+ /** Canonical remote cwd and remote process leader, never the local SSH transport PID. */
42
+ readonly source: string;
43
+ readonly pid: number;
44
+ /** Boot ID and start ticks captured from the child; absent when native metadata is unavailable. */
45
+ readonly identity?: string;
46
+ readonly stdout: Readable;
47
+ readonly stderr: Readable;
48
+ readonly completion: Promise<{ readonly exitCode: number }>;
49
+ /** Deliver bytes in order; resolves only after the remote OS accepts all bytes. */
50
+ write(bytes: Uint8Array): Promise<void>;
51
+ /** Close remote stdin after all queued writes. */
52
+ end(): Promise<void>;
53
+ /** Resize a remote PTY; pipe channels reject this operation without changing the process. */
54
+ resize(cols: number, rows: number): Promise<void>;
55
+ /** Reap the owned group and report its actual exit. Cancellation still rejects completion. */
56
+ stop(): Promise<{ readonly exitCode: number }>;
57
+ }
58
+
59
+ /** Start a transient framed channel. timeoutMs bounds startup, not the service lifetime. */
60
+ export async function startSshProcess(
61
+ target: SshTarget,
62
+ command: string,
63
+ args: readonly string[],
64
+ cwd: string,
65
+ context: SshProcessContext = {},
66
+ ): Promise<SshProcessChannel> {
67
+ validateSshTarget(target);
68
+ if (context.pty) validateDimensions(context.pty.cols, context.pty.rows);
69
+ const source = remoteLocation(target.id, cwd).source;
70
+ const timeout = context.timeoutMs ?? 30_000;
71
+ if (!Number.isFinite(timeout) || timeout <= 0)
72
+ throw new TypeError("SSH startup deadline must be positive");
73
+ context.signal?.throwIfAborted();
74
+ const bootstrap = await sshWorkerCommand(new URL("./ssh-channel-worker.py", import.meta.url));
75
+ context.signal?.throwIfAborted();
76
+ const request = JSON.stringify({
77
+ command,
78
+ args,
79
+ cwd,
80
+ ...(context.pty ? { pty: context.pty } : {}),
81
+ });
82
+ // Initial argv is separate from the small interactive control frames.
83
+ if (Buffer.byteLength(request) > 48 * 1024 * 1024)
84
+ throw new SshBackendError("FRAME_LIMIT", source, "not-applied");
85
+ const child = spawn("ssh", systemSshArguments(target, bootstrap), { stdio: "pipe" });
86
+ const channel = new ProcessChannel(child, source, context.pty !== undefined, context.signal);
87
+ const timer = setTimeout(() => channel.cancel("TIMEOUT"), timeout);
88
+ try {
89
+ await channel.sendInitial(request);
90
+ await channel.ready;
91
+ return channel;
92
+ } finally {
93
+ clearTimeout(timer);
94
+ }
95
+ }
96
+
97
+ function validateDimensions(cols: number, rows: number): void {
98
+ if (![cols, rows].every((value) => Number.isSafeInteger(value) && value > 0 && value <= 1000))
99
+ throw new TypeError("PTY dimensions must be integers between 1 and 1000");
100
+ }
101
+ class ProcessChannel implements SshProcessChannel {
102
+ readonly stdout = new PassThrough({ highWaterMark: 65536 });
103
+ readonly stderr = new PassThrough({ highWaterMark: 65536 });
104
+ readonly completion: Promise<{ readonly exitCode: number }>;
105
+ readonly ready: Promise<void>;
106
+ readonly #acks = new Map<number, { resolve(): void; reject(error: Error): void }>();
107
+ readonly #blocked = new Set<PassThrough>();
108
+ #resolveReady!: () => void;
109
+ #rejectReady!: (error: Error) => void;
110
+ #resolveCompletion!: (result: { exitCode: number }) => void;
111
+ #rejectCompletion!: (error: Error) => void;
112
+ #buffer = Buffer.alloc(0);
113
+ #diagnostics = "";
114
+ #failure: string | undefined;
115
+ #failureEffect: SshBackendError["effect"] | undefined;
116
+ #requested = false;
117
+ #started = false;
118
+ #pid = 0;
119
+ #identity: string | undefined;
120
+ #closed = false;
121
+ #ending = false;
122
+ #stopping = false;
123
+ #exitCode: number | undefined;
124
+ #transportExit: number | null | undefined;
125
+ #sequence = 0;
126
+ #queuedBytes = 0;
127
+ #queue: Promise<void> = Promise.resolve();
128
+ #stopTimer: ReturnType<typeof setTimeout> | undefined;
129
+
130
+ constructor(
131
+ readonly child: ChildProcessWithoutNullStreams,
132
+ readonly source: string,
133
+ readonly pty: boolean,
134
+ signal?: AbortSignal,
135
+ ) {
136
+ this.ready = new Promise((resolve, reject) => {
137
+ this.#resolveReady = resolve;
138
+ this.#rejectReady = reject;
139
+ });
140
+ this.completion = new Promise((resolve, reject) => {
141
+ this.#resolveCompletion = resolve;
142
+ this.#rejectCompletion = reject;
143
+ });
144
+ // Callers may consume startup and completion at different times. Preserve rejection without
145
+ // emitting an unhandled rejection before either promise is awaited.
146
+ void this.ready.catch(() => {});
147
+ void this.completion.catch(() => {});
148
+ child.stdout.on("data", (bytes: Buffer) => {
149
+ this.#buffer = Buffer.concat([this.#buffer, bytes]);
150
+ this.parse();
151
+ });
152
+ child.stderr.on("data", (bytes: Buffer) => {
153
+ if (this.#diagnostics.length < 16384) this.#diagnostics += bytes.toString();
154
+ });
155
+ child.stdin.on("error", () => {});
156
+ child.once("error", () => {
157
+ this.#failure = "DEPENDENCY_UNAVAILABLE";
158
+ });
159
+ const abort = () => this.cancel("CANCELLED");
160
+ signal?.addEventListener("abort", abort, { once: true });
161
+ child.once("close", (exitCode) => {
162
+ this.#closed = true;
163
+ this.#transportExit = exitCode;
164
+ clearTimeout(this.#stopTimer);
165
+ signal?.removeEventListener("abort", abort);
166
+ const code =
167
+ this.#failure ??
168
+ (exitCode !== 0
169
+ ? sshFailureCode(exitCode, this.#diagnostics)
170
+ : this.#exitCode === undefined
171
+ ? "TRANSPORT_FAILED"
172
+ : undefined);
173
+ this.stdout.end();
174
+ this.stderr.end();
175
+ const inputError = this.error(code ?? "INPUT_CLOSED");
176
+ for (const pending of this.#acks.values()) pending.reject(inputError);
177
+ this.#acks.clear();
178
+ if (code) {
179
+ const error = this.error(code);
180
+ this.#rejectReady(error);
181
+ this.#rejectCompletion(error);
182
+ } else if (this.#exitCode !== undefined) {
183
+ this.#resolveCompletion({ exitCode: this.#exitCode });
184
+ }
185
+ });
186
+ for (const stream of [this.stdout, this.stderr]) {
187
+ const resume = (): void => {
188
+ this.#blocked.delete(stream);
189
+ this.parse();
190
+ if (this.#blocked.size === 0) child.stdout.resume();
191
+ };
192
+ stream.on("drain", resume);
193
+ stream.on("close", resume);
194
+ }
195
+ if (signal?.aborted) abort();
196
+ }
197
+
198
+ get pid(): number {
199
+ return this.#pid;
200
+ }
201
+ get identity(): string | undefined {
202
+ return this.#identity;
203
+ }
204
+ async sendInitial(request: string): Promise<void> {
205
+ this.#requested = true;
206
+ await this.sendLine(request);
207
+ }
208
+
209
+ async write(bytes: Uint8Array): Promise<void> {
210
+ if (this.#closed || this.#ending || this.#stopping) throw this.error("INPUT_CLOSED");
211
+ if (this.#queuedBytes + bytes.length > 1024 * 1024) throw this.error("INPUT_LIMIT");
212
+ const data = Buffer.from(bytes);
213
+ this.#queuedBytes += data.length;
214
+ const result = this.#queue.then(async () => {
215
+ for (let offset = 0; offset < data.length; offset += 16384) {
216
+ if (this.#stopping || this.#closed) throw this.error("INPUT_CLOSED");
217
+ await this.sendAcknowledged({
218
+ kind: "input",
219
+ bytes: data.subarray(offset, offset + 16384).toString("base64"),
220
+ });
221
+ }
222
+ });
223
+ this.#queue = result.catch(() => {});
224
+ try {
225
+ await result;
226
+ } finally {
227
+ this.#queuedBytes -= data.length;
228
+ }
229
+ }
230
+
231
+ async end(): Promise<void> {
232
+ if (this.pty) throw new SshBackendError("PTY_INPUT_NOT_CLOSABLE", this.source, "not-applied");
233
+ this.#ending = true;
234
+ await this.#queue;
235
+ await this.send({ kind: "end" });
236
+ }
237
+
238
+ async resize(cols: number, rows: number): Promise<void> {
239
+ if (!this.pty) throw new SshBackendError("PTY_REQUIRED", this.source, "not-applied");
240
+ validateDimensions(cols, rows);
241
+ await this.sendAcknowledged({ kind: "resize", cols, rows });
242
+ }
243
+ stop(): Promise<{ readonly exitCode: number }> {
244
+ if (!this.#closed && !this.#stopping) {
245
+ this.#stopping = true;
246
+ void this.send({ kind: "stop" }).catch(() => {});
247
+ // A disconnected transport or undrained output must not keep the local SSH child alive.
248
+ this.#stopTimer = setTimeout(() => {
249
+ this.#failure ??= "TRANSPORT_FAILED";
250
+ this.child.kill("SIGKILL");
251
+ }, 5000);
252
+ this.child.stdout.resume();
253
+ this.stdout.resume();
254
+ this.stderr.resume();
255
+ }
256
+ return this.completion.catch((error: unknown) => {
257
+ // Only a clean SSH close and an actual native exit frame prove cancellation cleanup.
258
+ if (
259
+ this.#failure === "CANCELLED" &&
260
+ this.#transportExit === 0 &&
261
+ this.#exitCode !== undefined
262
+ ) {
263
+ return { exitCode: this.#exitCode };
264
+ }
265
+ throw error;
266
+ });
267
+ }
268
+
269
+ cancel(code: string): void {
270
+ if (this.#closed) return;
271
+ this.#failure ??= code;
272
+ void this.stop().catch(() => {});
273
+ }
274
+
275
+ private error(code: string): SshBackendError {
276
+ const knownPreflightFailure = [
277
+ "HOST_KEY_FAILED",
278
+ "AUTH_FAILED",
279
+ "DEPENDENCY_UNAVAILABLE",
280
+ ].includes(code);
281
+ const effect =
282
+ this.#failureEffect ??
283
+ (!this.#requested || knownPreflightFailure ? "not-applied" : "unknown");
284
+ return new SshBackendError(code, this.source, effect);
285
+ }
286
+
287
+ private async sendAcknowledged(event: Readonly<Record<string, unknown>>): Promise<void> {
288
+ const id = ++this.#sequence;
289
+ const accepted = new Promise<void>((resolve, reject) => {
290
+ this.#acks.set(id, { resolve, reject });
291
+ });
292
+ void accepted.catch(() => {});
293
+ try {
294
+ await this.send({ ...event, id });
295
+ await accepted;
296
+ } finally {
297
+ this.#acks.delete(id);
298
+ }
299
+ }
300
+ private async send(event: Readonly<Record<string, unknown>>): Promise<void> {
301
+ await this.sendLine(JSON.stringify(event));
302
+ }
303
+ private sendLine(line: string): Promise<void> {
304
+ if (this.#closed) return Promise.reject(this.error("INPUT_CLOSED"));
305
+ return new Promise((resolve, reject) => {
306
+ this.child.stdin.write(`${line}\n`, (error) => {
307
+ if (error) reject(this.error("INPUT_CLOSED"));
308
+ else resolve();
309
+ });
310
+ });
311
+ }
312
+
313
+ private parse(): void {
314
+ while (this.#blocked.size === 0) {
315
+ const end = this.#buffer.indexOf(10);
316
+ if (end < 0) {
317
+ if (this.#buffer.length > 65536) this.cancel("FRAME_LIMIT");
318
+ return;
319
+ }
320
+ if (end > 65536) {
321
+ this.cancel("FRAME_LIMIT");
322
+ return;
323
+ }
324
+ const line = this.#buffer.subarray(0, end);
325
+ this.#buffer = this.#buffer.subarray(end + 1);
326
+ let frame: unknown;
327
+ try {
328
+ frame = JSON.parse(line.toString("utf8"));
329
+ } catch {
330
+ this.cancel("INVALID_RESPONSE");
331
+ return;
332
+ }
333
+ if (!Value.Check(frameSchema, frame)) {
334
+ this.cancel("INVALID_RESPONSE");
335
+ return;
336
+ }
337
+ this.receive(frame);
338
+ }
339
+ this.child.stdout.pause();
340
+ }
341
+
342
+ private receive(frame: Frame): void {
343
+ if (frame.kind === "ready") {
344
+ if (this.#started) {
345
+ this.cancel("INVALID_RESPONSE");
346
+ return;
347
+ }
348
+ this.#started = true;
349
+ this.#pid = frame.pid;
350
+ this.#identity = frame.identity;
351
+ this.#resolveReady();
352
+ } else if (frame.kind === "ack") {
353
+ const pending = this.#acks.get(frame.id);
354
+ if (!pending) {
355
+ this.cancel("INVALID_RESPONSE");
356
+ return;
357
+ }
358
+ this.#acks.delete(frame.id);
359
+ pending.resolve();
360
+ } else if (frame.kind === "exit") {
361
+ this.#exitCode = frame.exitCode;
362
+ } else if (frame.kind === "error") {
363
+ this.#failure = frame.code;
364
+ this.#failureEffect = frame.effect;
365
+ } else {
366
+ const bytes = Buffer.from(frame.bytes, "base64");
367
+ if (bytes.toString("base64") !== frame.bytes) {
368
+ this.cancel("INVALID_RESPONSE");
369
+ return;
370
+ }
371
+ const stream = frame.kind === "stdout" ? this.stdout : this.stderr;
372
+ // A closed consumer cannot drain. Discard its output, but still require the exit frame.
373
+ if (!stream.destroyed && !stream.write(bytes)) this.#blocked.add(stream);
374
+ }
375
+ }
376
+ }