@celljs/ta-host 4.8.0 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/README.en.md +33 -5
  2. package/README.md +33 -5
  3. package/cell.schema.json +4 -0
  4. package/cell.yml +2 -0
  5. package/esm/node/client-tool-broker.d.ts +11 -3
  6. package/esm/node/client-tool-broker.js +23 -3
  7. package/esm/node/host-protocol.d.ts +22 -1
  8. package/esm/node/host-protocol.js +1 -0
  9. package/esm/node/index.d.ts +4 -0
  10. package/esm/node/index.js +4 -0
  11. package/esm/node/live-run.d.ts +22 -0
  12. package/esm/node/live-run.js +58 -0
  13. package/esm/node/message-page.d.ts +17 -0
  14. package/esm/node/message-page.js +71 -0
  15. package/esm/node/package-server-impl.d.ts +9 -1
  16. package/esm/node/package-server-impl.js +16 -1
  17. package/esm/node/relay-bridge.d.ts +9 -1
  18. package/esm/node/relay-bridge.js +44 -4
  19. package/esm/node/session-catalog.d.ts +69 -0
  20. package/esm/node/session-catalog.js +213 -0
  21. package/esm/node/session-info-util.d.ts +4 -1
  22. package/esm/node/session-info-util.js +8 -3
  23. package/esm/node/settings-store.d.ts +1 -4
  24. package/esm/node/settings-store.js +11 -3
  25. package/esm/node/sign-in/access-server-impl.d.ts +19 -0
  26. package/esm/node/sign-in/access-server-impl.js +82 -0
  27. package/esm/node/sign-in/access-store.d.ts +65 -0
  28. package/esm/node/sign-in/access-store.js +175 -0
  29. package/esm/node/sign-in/index.d.ts +7 -0
  30. package/esm/node/sign-in/index.js +8 -0
  31. package/esm/node/sign-in/sign-in-flow.d.ts +58 -0
  32. package/esm/node/sign-in/sign-in-flow.js +104 -0
  33. package/esm/node/sign-in/sign-in-middleware.d.ts +10 -0
  34. package/esm/node/sign-in/sign-in-middleware.js +48 -0
  35. package/esm/node/sign-in/sign-in-pages.d.ts +31 -0
  36. package/esm/node/sign-in/sign-in-pages.js +124 -0
  37. package/esm/node/sign-in/sign-in-provider.d.ts +135 -0
  38. package/esm/node/sign-in/sign-in-provider.js +225 -0
  39. package/esm/node/sign-in/ta-sign-in.d.ts +10 -0
  40. package/esm/node/sign-in/ta-sign-in.js +32 -0
  41. package/esm/node/ta-access.d.ts +7 -0
  42. package/esm/node/ta-access.js +30 -1
  43. package/esm/node/ta-server-impl.d.ts +8 -3
  44. package/esm/node/ta-server-impl.js +25 -6
  45. package/esm/node/ta-session-factory.d.ts +1 -1
  46. package/esm/node/ta-session-factory.js +14 -4
  47. package/esm/node/ta-session-registry.d.ts +2 -0
  48. package/esm/node/ta-session-registry.js +23 -3
  49. package/esm/node/ta-session.d.ts +24 -2
  50. package/esm/node/ta-session.js +83 -6
  51. package/esm/node/temporary-packages.d.ts +46 -0
  52. package/esm/node/temporary-packages.js +114 -0
  53. package/esm/node/temporary-purge.d.ts +13 -0
  54. package/esm/node/temporary-purge.js +51 -0
  55. package/esm/node/web-extension-catalog.d.ts +28 -1
  56. package/esm/node/web-extension-catalog.js +173 -5
  57. package/esm/node/web-extension-util.d.ts +5 -1
  58. package/esm/node/web-extension-util.js +36 -5
  59. package/esm/node/workspace-service.js +1 -1
  60. package/lib/node/client-tool-broker.d.ts +11 -3
  61. package/lib/node/client-tool-broker.js +23 -3
  62. package/lib/node/host-protocol.d.ts +22 -1
  63. package/lib/node/host-protocol.js +2 -1
  64. package/lib/node/index.d.ts +4 -0
  65. package/lib/node/index.js +4 -0
  66. package/lib/node/live-run.d.ts +23 -0
  67. package/lib/node/live-run.js +62 -0
  68. package/lib/node/message-page.d.ts +18 -0
  69. package/lib/node/message-page.js +74 -0
  70. package/lib/node/package-server-impl.d.ts +9 -1
  71. package/lib/node/package-server-impl.js +15 -0
  72. package/lib/node/relay-bridge.d.ts +9 -1
  73. package/lib/node/relay-bridge.js +43 -3
  74. package/lib/node/session-catalog.d.ts +70 -0
  75. package/lib/node/session-catalog.js +216 -0
  76. package/lib/node/session-info-util.d.ts +4 -1
  77. package/lib/node/session-info-util.js +7 -2
  78. package/lib/node/settings-store.d.ts +1 -4
  79. package/lib/node/settings-store.js +11 -3
  80. package/lib/node/sign-in/access-server-impl.d.ts +20 -0
  81. package/lib/node/sign-in/access-server-impl.js +85 -0
  82. package/lib/node/sign-in/access-store.d.ts +66 -0
  83. package/lib/node/sign-in/access-store.js +179 -0
  84. package/lib/node/sign-in/index.d.ts +8 -0
  85. package/lib/node/sign-in/index.js +24 -0
  86. package/lib/node/sign-in/sign-in-flow.d.ts +59 -0
  87. package/lib/node/sign-in/sign-in-flow.js +108 -0
  88. package/lib/node/sign-in/sign-in-middleware.d.ts +11 -0
  89. package/lib/node/sign-in/sign-in-middleware.js +51 -0
  90. package/lib/node/sign-in/sign-in-pages.d.ts +32 -0
  91. package/lib/node/sign-in/sign-in-pages.js +127 -0
  92. package/lib/node/sign-in/sign-in-provider.d.ts +136 -0
  93. package/lib/node/sign-in/sign-in-provider.js +232 -0
  94. package/lib/node/sign-in/ta-sign-in.d.ts +11 -0
  95. package/lib/node/sign-in/ta-sign-in.js +35 -0
  96. package/lib/node/ta-access.d.ts +7 -0
  97. package/lib/node/ta-access.js +30 -1
  98. package/lib/node/ta-server-impl.d.ts +8 -3
  99. package/lib/node/ta-server-impl.js +24 -5
  100. package/lib/node/ta-session-factory.d.ts +1 -1
  101. package/lib/node/ta-session-factory.js +14 -4
  102. package/lib/node/ta-session-registry.d.ts +2 -0
  103. package/lib/node/ta-session-registry.js +23 -3
  104. package/lib/node/ta-session.d.ts +24 -2
  105. package/lib/node/ta-session.js +83 -6
  106. package/lib/node/temporary-packages.d.ts +47 -0
  107. package/lib/node/temporary-packages.js +118 -0
  108. package/lib/node/temporary-purge.d.ts +14 -0
  109. package/lib/node/temporary-purge.js +54 -0
  110. package/lib/node/web-extension-catalog.d.ts +28 -1
  111. package/lib/node/web-extension-catalog.js +172 -4
  112. package/lib/node/web-extension-util.d.ts +5 -1
  113. package/lib/node/web-extension-util.js +36 -5
  114. package/lib/node/workspace-service.js +1 -1
  115. package/package.json +17 -12
  116. package/esm/node/auth-server-impl.js.map +0 -1
  117. package/esm/node/client-channel.js.map +0 -1
  118. package/esm/node/client-tool-broker.js.map +0 -1
  119. package/esm/node/event-log.js.map +0 -1
  120. package/esm/node/exec-environment-factory.js.map +0 -1
  121. package/esm/node/extension-data-notifier.js.map +0 -1
  122. package/esm/node/extension-data.js.map +0 -1
  123. package/esm/node/extension-providers.js.map +0 -1
  124. package/esm/node/host-protocol.js.map +0 -1
  125. package/esm/node/index.js.map +0 -1
  126. package/esm/node/module.js.map +0 -1
  127. package/esm/node/package-host-extension.js.map +0 -1
  128. package/esm/node/package-hosts.js.map +0 -1
  129. package/esm/node/package-server-impl.js.map +0 -1
  130. package/esm/node/package-switch.js.map +0 -1
  131. package/esm/node/receipt-book.js.map +0 -1
  132. package/esm/node/relay-bridge.js.map +0 -1
  133. package/esm/node/remote/index.js.map +0 -1
  134. package/esm/node/remote/pi-directories.js.map +0 -1
  135. package/esm/node/remote/port-forwards.js.map +0 -1
  136. package/esm/node/remote/remote-hosts.js.map +0 -1
  137. package/esm/node/remote/remote-protocol.js.map +0 -1
  138. package/esm/node/remote/remote-server-impl.js.map +0 -1
  139. package/esm/node/remote-ui-context.js.map +0 -1
  140. package/esm/node/session-files.js.map +0 -1
  141. package/esm/node/session-info-util.js.map +0 -1
  142. package/esm/node/session-storage/file-session-storage.js.map +0 -1
  143. package/esm/node/session-storage/index.js.map +0 -1
  144. package/esm/node/session-storage/session-storage-protocol.js.map +0 -1
  145. package/esm/node/session-storage/stored-session.js.map +0 -1
  146. package/esm/node/settings-server-impl.js.map +0 -1
  147. package/esm/node/settings-store.js.map +0 -1
  148. package/esm/node/ta-access.js.map +0 -1
  149. package/esm/node/ta-errors.js.map +0 -1
  150. package/esm/node/ta-event-util.js.map +0 -1
  151. package/esm/node/ta-server-impl.js.map +0 -1
  152. package/esm/node/ta-session-factory.js.map +0 -1
  153. package/esm/node/ta-session-registry.js.map +0 -1
  154. package/esm/node/ta-session.js.map +0 -1
  155. package/esm/node/terminal-protocol.js.map +0 -1
  156. package/esm/node/terminal-service.js.map +0 -1
  157. package/esm/node/terminal-util.js.map +0 -1
  158. package/esm/node/web-extension-catalog.js.map +0 -1
  159. package/esm/node/web-extension-util.js.map +0 -1
  160. package/esm/node/working-directory.js.map +0 -1
  161. package/esm/node/workspace-files.js.map +0 -1
  162. package/esm/node/workspace-protocol.js.map +0 -1
  163. package/esm/node/workspace-server-impl.js.map +0 -1
  164. package/esm/node/workspace-service.js.map +0 -1
  165. package/esm/node/workspace-util.js.map +0 -1
  166. package/lib/node/auth-server-impl.d.ts.map +0 -1
  167. package/lib/node/auth-server-impl.js.map +0 -1
  168. package/lib/node/auth-server-impl.spec.d.ts +0 -2
  169. package/lib/node/auth-server-impl.spec.d.ts.map +0 -1
  170. package/lib/node/auth-server-impl.spec.js +0 -47
  171. package/lib/node/auth-server-impl.spec.js.map +0 -1
  172. package/lib/node/client-channel.d.ts.map +0 -1
  173. package/lib/node/client-channel.js.map +0 -1
  174. package/lib/node/client-channel.spec.d.ts +0 -2
  175. package/lib/node/client-channel.spec.d.ts.map +0 -1
  176. package/lib/node/client-channel.spec.js +0 -106
  177. package/lib/node/client-channel.spec.js.map +0 -1
  178. package/lib/node/client-tool-broker.d.ts.map +0 -1
  179. package/lib/node/client-tool-broker.js.map +0 -1
  180. package/lib/node/client-tool-broker.spec.d.ts +0 -2
  181. package/lib/node/client-tool-broker.spec.d.ts.map +0 -1
  182. package/lib/node/client-tool-broker.spec.js +0 -49
  183. package/lib/node/client-tool-broker.spec.js.map +0 -1
  184. package/lib/node/event-log.d.ts.map +0 -1
  185. package/lib/node/event-log.js.map +0 -1
  186. package/lib/node/event-log.spec.d.ts +0 -2
  187. package/lib/node/event-log.spec.d.ts.map +0 -1
  188. package/lib/node/event-log.spec.js +0 -48
  189. package/lib/node/event-log.spec.js.map +0 -1
  190. package/lib/node/exec-environment-factory.d.ts.map +0 -1
  191. package/lib/node/exec-environment-factory.js.map +0 -1
  192. package/lib/node/extension-data-notifier.d.ts.map +0 -1
  193. package/lib/node/extension-data-notifier.js.map +0 -1
  194. package/lib/node/extension-data-notifier.spec.d.ts +0 -2
  195. package/lib/node/extension-data-notifier.spec.d.ts.map +0 -1
  196. package/lib/node/extension-data-notifier.spec.js +0 -35
  197. package/lib/node/extension-data-notifier.spec.js.map +0 -1
  198. package/lib/node/extension-data.d.ts.map +0 -1
  199. package/lib/node/extension-data.js.map +0 -1
  200. package/lib/node/extension-data.spec.d.ts +0 -2
  201. package/lib/node/extension-data.spec.d.ts.map +0 -1
  202. package/lib/node/extension-data.spec.js +0 -99
  203. package/lib/node/extension-data.spec.js.map +0 -1
  204. package/lib/node/extension-providers.d.ts.map +0 -1
  205. package/lib/node/extension-providers.js.map +0 -1
  206. package/lib/node/host-protocol.d.ts.map +0 -1
  207. package/lib/node/host-protocol.js.map +0 -1
  208. package/lib/node/index.d.ts.map +0 -1
  209. package/lib/node/index.js.map +0 -1
  210. package/lib/node/module.d.ts.map +0 -1
  211. package/lib/node/module.js.map +0 -1
  212. package/lib/node/package-host-extension.d.ts.map +0 -1
  213. package/lib/node/package-host-extension.js.map +0 -1
  214. package/lib/node/package-hosts.d.ts.map +0 -1
  215. package/lib/node/package-hosts.js.map +0 -1
  216. package/lib/node/package-hosts.spec.d.ts +0 -2
  217. package/lib/node/package-hosts.spec.d.ts.map +0 -1
  218. package/lib/node/package-hosts.spec.js +0 -53
  219. package/lib/node/package-hosts.spec.js.map +0 -1
  220. package/lib/node/package-server-impl.d.ts.map +0 -1
  221. package/lib/node/package-server-impl.js.map +0 -1
  222. package/lib/node/package-switch.d.ts.map +0 -1
  223. package/lib/node/package-switch.js.map +0 -1
  224. package/lib/node/receipt-book.d.ts.map +0 -1
  225. package/lib/node/receipt-book.js.map +0 -1
  226. package/lib/node/receipt-book.spec.d.ts +0 -2
  227. package/lib/node/receipt-book.spec.d.ts.map +0 -1
  228. package/lib/node/receipt-book.spec.js +0 -39
  229. package/lib/node/receipt-book.spec.js.map +0 -1
  230. package/lib/node/relay-bridge.d.ts.map +0 -1
  231. package/lib/node/relay-bridge.js.map +0 -1
  232. package/lib/node/remote/index.d.ts.map +0 -1
  233. package/lib/node/remote/index.js.map +0 -1
  234. package/lib/node/remote/pi-directories.d.ts.map +0 -1
  235. package/lib/node/remote/pi-directories.js.map +0 -1
  236. package/lib/node/remote/port-forwards.d.ts.map +0 -1
  237. package/lib/node/remote/port-forwards.js.map +0 -1
  238. package/lib/node/remote/remote-hosts.d.ts.map +0 -1
  239. package/lib/node/remote/remote-hosts.js.map +0 -1
  240. package/lib/node/remote/remote-protocol.d.ts.map +0 -1
  241. package/lib/node/remote/remote-protocol.js.map +0 -1
  242. package/lib/node/remote/remote-server-impl.d.ts.map +0 -1
  243. package/lib/node/remote/remote-server-impl.js.map +0 -1
  244. package/lib/node/remote/remote.spec.d.ts +0 -2
  245. package/lib/node/remote/remote.spec.d.ts.map +0 -1
  246. package/lib/node/remote/remote.spec.js +0 -130
  247. package/lib/node/remote/remote.spec.js.map +0 -1
  248. package/lib/node/remote-ui-context.d.ts.map +0 -1
  249. package/lib/node/remote-ui-context.js.map +0 -1
  250. package/lib/node/remote-ui-context.spec.d.ts +0 -2
  251. package/lib/node/remote-ui-context.spec.d.ts.map +0 -1
  252. package/lib/node/remote-ui-context.spec.js +0 -85
  253. package/lib/node/remote-ui-context.spec.js.map +0 -1
  254. package/lib/node/session-files.d.ts.map +0 -1
  255. package/lib/node/session-files.js.map +0 -1
  256. package/lib/node/session-files.spec.d.ts +0 -2
  257. package/lib/node/session-files.spec.d.ts.map +0 -1
  258. package/lib/node/session-files.spec.js +0 -51
  259. package/lib/node/session-files.spec.js.map +0 -1
  260. package/lib/node/session-info-util.d.ts.map +0 -1
  261. package/lib/node/session-info-util.js.map +0 -1
  262. package/lib/node/session-info-util.spec.d.ts +0 -2
  263. package/lib/node/session-info-util.spec.d.ts.map +0 -1
  264. package/lib/node/session-info-util.spec.js +0 -22
  265. package/lib/node/session-info-util.spec.js.map +0 -1
  266. package/lib/node/session-storage/file-session-storage.d.ts.map +0 -1
  267. package/lib/node/session-storage/file-session-storage.js.map +0 -1
  268. package/lib/node/session-storage/file-session-storage.spec.d.ts +0 -2
  269. package/lib/node/session-storage/file-session-storage.spec.d.ts.map +0 -1
  270. package/lib/node/session-storage/file-session-storage.spec.js +0 -70
  271. package/lib/node/session-storage/file-session-storage.spec.js.map +0 -1
  272. package/lib/node/session-storage/index.d.ts.map +0 -1
  273. package/lib/node/session-storage/index.js.map +0 -1
  274. package/lib/node/session-storage/session-storage-protocol.d.ts.map +0 -1
  275. package/lib/node/session-storage/session-storage-protocol.js.map +0 -1
  276. package/lib/node/session-storage/stored-session.d.ts.map +0 -1
  277. package/lib/node/session-storage/stored-session.js.map +0 -1
  278. package/lib/node/session-storage/stored-session.spec.d.ts +0 -2
  279. package/lib/node/session-storage/stored-session.spec.d.ts.map +0 -1
  280. package/lib/node/session-storage/stored-session.spec.js +0 -73
  281. package/lib/node/session-storage/stored-session.spec.js.map +0 -1
  282. package/lib/node/settings-server-impl.d.ts.map +0 -1
  283. package/lib/node/settings-server-impl.js.map +0 -1
  284. package/lib/node/settings-store.d.ts.map +0 -1
  285. package/lib/node/settings-store.js.map +0 -1
  286. package/lib/node/settings-store.spec.d.ts +0 -2
  287. package/lib/node/settings-store.spec.d.ts.map +0 -1
  288. package/lib/node/settings-store.spec.js +0 -148
  289. package/lib/node/settings-store.spec.js.map +0 -1
  290. package/lib/node/ta-access.d.ts.map +0 -1
  291. package/lib/node/ta-access.js.map +0 -1
  292. package/lib/node/ta-access.spec.d.ts +0 -2
  293. package/lib/node/ta-access.spec.d.ts.map +0 -1
  294. package/lib/node/ta-access.spec.js +0 -33
  295. package/lib/node/ta-access.spec.js.map +0 -1
  296. package/lib/node/ta-errors.d.ts.map +0 -1
  297. package/lib/node/ta-errors.js.map +0 -1
  298. package/lib/node/ta-errors.spec.d.ts +0 -2
  299. package/lib/node/ta-errors.spec.d.ts.map +0 -1
  300. package/lib/node/ta-errors.spec.js +0 -25
  301. package/lib/node/ta-errors.spec.js.map +0 -1
  302. package/lib/node/ta-event-util.d.ts.map +0 -1
  303. package/lib/node/ta-event-util.js.map +0 -1
  304. package/lib/node/ta-event-util.spec.d.ts +0 -2
  305. package/lib/node/ta-event-util.spec.d.ts.map +0 -1
  306. package/lib/node/ta-event-util.spec.js +0 -28
  307. package/lib/node/ta-event-util.spec.js.map +0 -1
  308. package/lib/node/ta-server-impl.d.ts.map +0 -1
  309. package/lib/node/ta-server-impl.js.map +0 -1
  310. package/lib/node/ta-session-factory.d.ts.map +0 -1
  311. package/lib/node/ta-session-factory.js.map +0 -1
  312. package/lib/node/ta-session-registry.d.ts.map +0 -1
  313. package/lib/node/ta-session-registry.js.map +0 -1
  314. package/lib/node/ta-session.d.ts.map +0 -1
  315. package/lib/node/ta-session.js.map +0 -1
  316. package/lib/node/terminal-protocol.d.ts.map +0 -1
  317. package/lib/node/terminal-protocol.js.map +0 -1
  318. package/lib/node/terminal-service.d.ts.map +0 -1
  319. package/lib/node/terminal-service.js.map +0 -1
  320. package/lib/node/terminal-service.spec.d.ts +0 -2
  321. package/lib/node/terminal-service.spec.d.ts.map +0 -1
  322. package/lib/node/terminal-service.spec.js +0 -110
  323. package/lib/node/terminal-service.spec.js.map +0 -1
  324. package/lib/node/terminal-util.d.ts.map +0 -1
  325. package/lib/node/terminal-util.js.map +0 -1
  326. package/lib/node/terminal-util.spec.d.ts +0 -2
  327. package/lib/node/terminal-util.spec.d.ts.map +0 -1
  328. package/lib/node/terminal-util.spec.js +0 -95
  329. package/lib/node/terminal-util.spec.js.map +0 -1
  330. package/lib/node/web-extension-catalog.d.ts.map +0 -1
  331. package/lib/node/web-extension-catalog.js.map +0 -1
  332. package/lib/node/web-extension-catalog.spec.d.ts +0 -2
  333. package/lib/node/web-extension-catalog.spec.d.ts.map +0 -1
  334. package/lib/node/web-extension-catalog.spec.js +0 -157
  335. package/lib/node/web-extension-catalog.spec.js.map +0 -1
  336. package/lib/node/web-extension-util.d.ts.map +0 -1
  337. package/lib/node/web-extension-util.js.map +0 -1
  338. package/lib/node/working-directory.d.ts.map +0 -1
  339. package/lib/node/working-directory.js.map +0 -1
  340. package/lib/node/workspace-files.d.ts.map +0 -1
  341. package/lib/node/workspace-files.js.map +0 -1
  342. package/lib/node/workspace-files.spec.d.ts +0 -2
  343. package/lib/node/workspace-files.spec.d.ts.map +0 -1
  344. package/lib/node/workspace-files.spec.js +0 -133
  345. package/lib/node/workspace-files.spec.js.map +0 -1
  346. package/lib/node/workspace-protocol.d.ts.map +0 -1
  347. package/lib/node/workspace-protocol.js.map +0 -1
  348. package/lib/node/workspace-server-impl.d.ts.map +0 -1
  349. package/lib/node/workspace-server-impl.js.map +0 -1
  350. package/lib/node/workspace-service.d.ts.map +0 -1
  351. package/lib/node/workspace-service.js.map +0 -1
  352. package/lib/node/workspace-service.spec.d.ts +0 -2
  353. package/lib/node/workspace-service.spec.d.ts.map +0 -1
  354. package/lib/node/workspace-service.spec.js +0 -113
  355. package/lib/node/workspace-service.spec.js.map +0 -1
  356. package/lib/node/workspace-util.d.ts.map +0 -1
  357. package/lib/node/workspace-util.js.map +0 -1
  358. package/lib/node/workspace-util.spec.d.ts +0 -2
  359. package/lib/node/workspace-util.spec.d.ts.map +0 -1
  360. package/lib/node/workspace-util.spec.js +0 -44
  361. package/lib/node/workspace-util.spec.js.map +0 -1
  362. package/src/node/auth-server-impl.spec.ts +0 -49
  363. package/src/node/auth-server-impl.ts +0 -258
  364. package/src/node/client-channel.spec.ts +0 -117
  365. package/src/node/client-channel.ts +0 -94
  366. package/src/node/client-tool-broker.spec.ts +0 -53
  367. package/src/node/client-tool-broker.ts +0 -106
  368. package/src/node/event-log.spec.ts +0 -52
  369. package/src/node/event-log.ts +0 -59
  370. package/src/node/exec-environment-factory.ts +0 -66
  371. package/src/node/extension-data-notifier.spec.ts +0 -34
  372. package/src/node/extension-data-notifier.ts +0 -124
  373. package/src/node/extension-data.spec.ts +0 -105
  374. package/src/node/extension-data.ts +0 -180
  375. package/src/node/extension-providers.ts +0 -49
  376. package/src/node/host-protocol.ts +0 -62
  377. package/src/node/index.ts +0 -39
  378. package/src/node/module.ts +0 -4
  379. package/src/node/package-host-extension.ts +0 -23
  380. package/src/node/package-hosts.spec.ts +0 -54
  381. package/src/node/package-hosts.ts +0 -204
  382. package/src/node/package-server-impl.ts +0 -87
  383. package/src/node/package-switch.ts +0 -80
  384. package/src/node/receipt-book.spec.ts +0 -41
  385. package/src/node/receipt-book.ts +0 -40
  386. package/src/node/relay-bridge.ts +0 -94
  387. package/src/node/remote/index.ts +0 -5
  388. package/src/node/remote/pi-directories.ts +0 -49
  389. package/src/node/remote/port-forwards.ts +0 -148
  390. package/src/node/remote/remote-hosts.ts +0 -170
  391. package/src/node/remote/remote-protocol.ts +0 -57
  392. package/src/node/remote/remote-server-impl.ts +0 -60
  393. package/src/node/remote/remote.spec.ts +0 -142
  394. package/src/node/remote-ui-context.spec.ts +0 -93
  395. package/src/node/remote-ui-context.ts +0 -197
  396. package/src/node/session-files.spec.ts +0 -52
  397. package/src/node/session-files.ts +0 -41
  398. package/src/node/session-info-util.spec.ts +0 -23
  399. package/src/node/session-info-util.ts +0 -55
  400. package/src/node/session-storage/file-session-storage.spec.ts +0 -72
  401. package/src/node/session-storage/file-session-storage.ts +0 -145
  402. package/src/node/session-storage/index.ts +0 -3
  403. package/src/node/session-storage/session-storage-protocol.ts +0 -81
  404. package/src/node/session-storage/stored-session.spec.ts +0 -80
  405. package/src/node/session-storage/stored-session.ts +0 -149
  406. package/src/node/settings-server-impl.ts +0 -42
  407. package/src/node/settings-store.spec.ts +0 -158
  408. package/src/node/settings-store.ts +0 -327
  409. package/src/node/ta-access.spec.ts +0 -36
  410. package/src/node/ta-access.ts +0 -156
  411. package/src/node/ta-errors.spec.ts +0 -25
  412. package/src/node/ta-errors.ts +0 -75
  413. package/src/node/ta-event-util.spec.ts +0 -29
  414. package/src/node/ta-event-util.ts +0 -23
  415. package/src/node/ta-server-impl.ts +0 -341
  416. package/src/node/ta-session-factory.ts +0 -216
  417. package/src/node/ta-session-registry.ts +0 -75
  418. package/src/node/ta-session.ts +0 -241
  419. package/src/node/terminal-protocol.ts +0 -18
  420. package/src/node/terminal-service.spec.ts +0 -119
  421. package/src/node/terminal-service.ts +0 -291
  422. package/src/node/terminal-util.spec.ts +0 -109
  423. package/src/node/terminal-util.ts +0 -197
  424. package/src/node/web-extension-catalog.spec.ts +0 -172
  425. package/src/node/web-extension-catalog.ts +0 -177
  426. package/src/node/web-extension-util.ts +0 -144
  427. package/src/node/working-directory.ts +0 -71
  428. package/src/node/workspace-files.spec.ts +0 -145
  429. package/src/node/workspace-files.ts +0 -256
  430. package/src/node/workspace-protocol.ts +0 -24
  431. package/src/node/workspace-server-impl.ts +0 -108
  432. package/src/node/workspace-service.spec.ts +0 -123
  433. package/src/node/workspace-service.ts +0 -235
  434. package/src/node/workspace-util.spec.ts +0 -47
  435. package/src/node/workspace-util.ts +0 -103
@@ -1,216 +0,0 @@
1
- import { resolve, sep } from 'node:path';
2
- import {
3
- AgentExtension,
4
- AgentTool,
5
- AgentToolUtil,
6
- CODING_AGENT_OPTIONS,
7
- type CodingAgentOptions,
8
- ModelRuntimeProvider,
9
- type PiSdk,
10
- PiSdkUtil,
11
- } from '@celljs/ai-coding-agent';
12
- import { Autowired, Component, Optional, Value } from '@celljs/core';
13
- import { type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
14
- import {
15
- BrandExtension,
16
- type ContextFile,
17
- ExecExtension,
18
- ExecMcpTransport,
19
- type InlineExtension,
20
- type McpServerEntry,
21
- RemoteContextFiles,
22
- SessionLock,
23
- SessionLockExtension,
24
- TaExtensionUtil,
25
- TaPackages,
26
- } from '@celljs/ta-harness';
27
- import type { TaOpenSessionOptions } from '@celljs/ta-protocol';
28
- import { ClientToolBroker } from './client-tool-broker';
29
- import { ExtensionProviders } from './extension-providers';
30
- import { TA_HOST_OPTIONS, type TaHostOptions, TaSessionFactory } from './host-protocol';
31
- import { PackageHostExtension } from './package-host-extension';
32
- import { PackageHosts } from './package-hosts';
33
- import { PiDirectories } from './remote/remote-protocol';
34
- import { ExecSessionFiles } from './session-files';
35
- import { TaErrors } from './ta-errors';
36
- import { TaSession } from './ta-session';
37
-
38
- type AgentsFilesOverride = (base: { agentsFiles: ContextFile[] }) => { agentsFiles: ContextFile[] };
39
- type ModelRuntime = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).ModelRuntime;
40
- type SessionManager = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).SessionManager;
41
- type Model = NonNullable<import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSession['model']>;
42
-
43
- /** Sets up pi for each session the way its command does, with one model runtime for all of them. */
44
- @Component(TaSessionFactory)
45
- export class DefaultTaSessionFactory implements TaSessionFactory {
46
- @Value(TA_HOST_OPTIONS)
47
- protected readonly options: TaHostOptions;
48
-
49
- @Value(CODING_AGENT_OPTIONS)
50
- protected readonly codingAgentOptions?: CodingAgentOptions;
51
-
52
- @Autowired(ModelRuntimeProvider)
53
- protected readonly modelRuntimeProvider: ModelRuntimeProvider;
54
-
55
- @Autowired(ExecEnvironmentFactory)
56
- protected readonly environments: ExecEnvironmentFactory;
57
-
58
- @Autowired(AgentExtension)
59
- @Optional()
60
- protected readonly extensions: AgentExtension[] = [];
61
-
62
- @Autowired(AgentTool)
63
- @Optional()
64
- protected readonly tools: AgentTool[] = [];
65
-
66
- @Autowired(PackageHosts)
67
- protected readonly packageHosts: PackageHosts;
68
-
69
- @Autowired(PiDirectories)
70
- protected readonly directories: PiDirectories;
71
-
72
- @Autowired(ExtensionProviders)
73
- protected readonly extensionProviders: ExtensionProviders;
74
-
75
- async create(options: TaOpenSessionOptions, requestClose: (session: TaSession) => void): Promise<TaSession> {
76
- const clientTools = new ClientToolBroker(options.clientTools);
77
- const sdk = await PiSdkUtil.load();
78
- const agentDir = this.codingAgentOptions?.agentDir ?? sdk.getAgentDir();
79
- const modelRuntime = await this.modelRuntimeProvider.provide();
80
- // `options.cwd` is a location; pi works in a directory of this machine (PiDirectories). A session
81
- // file works where its header says, as pi's `--session` does, whatever `cwd` the caller gave.
82
- const sessionManager = this.openSessionManager(sdk, { ...options, cwd: this.directories.toPi(options.cwd) });
83
- const piCwd = options.sessionFile ? sessionManager.getCwd() : this.directories.toPi(options.cwd);
84
- const lock = new SessionLock();
85
- const sessionFile = sessionManager.getSessionFile();
86
- if (sessionFile && !lock.acquire(sessionFile)) {
87
- throw TaErrors.sessionLocked(sessionFile);
88
- }
89
- try {
90
- if (options.model && !this.findModel(modelRuntime, options.model)) {
91
- // A model of a pi package, whose provider is there once the package loaded.
92
- await this.extensionProviders.ensure();
93
- }
94
- const model = options.model ? this.resolveModel(modelRuntime, options.model) : undefined;
95
- const runtime = await sdk.createAgentSessionRuntime(
96
- async ({ cwd, agentDir: dir, sessionManager: manager, sessionStartEvent }) => {
97
- const environment = this.environments.create(this.directories.fromPi(cwd));
98
- const settingsManager = sdk.SettingsManager.create(cwd, dir, { projectTrusted: this.isTrusted(sdk, cwd, dir) });
99
- const services = await sdk.createAgentSessionServices({
100
- cwd,
101
- agentDir: dir,
102
- settingsManager,
103
- modelRuntime,
104
- resourceLoaderOptions: {
105
- ...TaPackages.loaderOptions(dir),
106
- ...(await this.contextFiles(environment, dir)),
107
- extensionFactories: this.extensionFactories(sdk, environment, cwd, lock),
108
- appendSystemPrompt: options.appendSystemPrompt ? [options.appendSystemPrompt] : undefined,
109
- },
110
- });
111
- const created = await sdk.createAgentSessionFromServices({
112
- services,
113
- sessionManager: manager,
114
- sessionStartEvent,
115
- model,
116
- thinkingLevel: options.thinkingLevel,
117
- customTools: [...(this.tools ?? []).map(AgentToolUtil.toToolDefinition), ...clientTools.tools()],
118
- });
119
- return { ...created, services, diagnostics: services.diagnostics };
120
- },
121
- { cwd: piCwd, agentDir, sessionManager },
122
- );
123
- const session = new TaSession({
124
- runtime,
125
- lock,
126
- clientTools,
127
- options: this.options,
128
- requestClose,
129
- group: options.group,
130
- locate: cwd => this.directories.fromPi(cwd),
131
- });
132
- await session.start();
133
- return session;
134
- } catch (error) {
135
- lock.releaseAll();
136
- throw error;
137
- }
138
- }
139
-
140
- protected openSessionManager(sdk: PiSdk, options: TaOpenSessionOptions): SessionManager {
141
- if (!options.sessionFile) {
142
- return sdk.SessionManager.create(options.cwd);
143
- }
144
- try {
145
- return sdk.SessionManager.open(options.sessionFile);
146
- } catch (error) {
147
- throw TaErrors.invalidArgument(
148
- `Cannot open the session ${options.sessionFile}: ${(error as Error).message}`,
149
- 'Pass a session file that exists; listSessions shows the open ones.',
150
- );
151
- }
152
- }
153
-
154
- /**
155
- * For another machine, its context files (AGENTS.md...) instead of those pi finds above the directory
156
- * of this machine it works in; the user's own, in the agent directory, stay.
157
- */
158
- protected async contextFiles(environment: ExecEnvironment, agentDir: string): Promise<{ agentsFilesOverride?: AgentsFilesOverride }> {
159
- if (environment.local) {
160
- return {};
161
- }
162
- const remote = await RemoteContextFiles.load(environment).catch(() => []);
163
- const own = resolve(agentDir) + sep;
164
- return { agentsFilesOverride: ({ agentsFiles }) => ({ agentsFiles: [...agentsFiles.filter(file => resolve(file.path).startsWith(own)), ...remote] }) };
165
- }
166
-
167
- protected extensionFactories(sdk: PiSdk, environment: ExecEnvironment, piCwd: string, lock: SessionLock): InlineExtension[] {
168
- const builtIn = [
169
- new SessionLockExtension(lock),
170
- new PackageHostExtension(this.packageHosts, new ExecSessionFiles(environment, piCwd)),
171
- new BrandExtension(sdk),
172
- ...(environment.local ? [] : [new ExecExtension(environment, sdk, piCwd)]),
173
- ];
174
- return [
175
- ...this.piExtensions(sdk, environment),
176
- TaExtensionUtil.bundle(builtIn),
177
- ...(this.extensions ?? []).map(extension => ({
178
- name: extension.name ?? extension.constructor.name,
179
- factory: (pi: Parameters<AgentExtension['register']>[0]) => extension.register(pi),
180
- })),
181
- ];
182
- }
183
-
184
- /**
185
- * The built-in extensions pi's command loads (codemode, tool search, MCP), which its SDK leaves to
186
- * the host. Flagged as pi flags them: an installed extension that registers the same tool or
187
- * command replaces them. pi does not export its llama.cpp extension. MCP servers over stdio start
188
- * in the execution environment, where the session's tools run.
189
- */
190
- protected piExtensions(sdk: PiSdk, environment: ExecEnvironment): InlineExtension[] {
191
- const createTransport = environment.local ? undefined : (entry: McpServerEntry) => new ExecMcpTransport(environment, entry);
192
- return [
193
- { name: 'codemode', factory: sdk.createCodemodeExtension(), replaceable: true, builtin: true },
194
- { name: 'tool-search', factory: sdk.createToolSearchExtension(), replaceable: true, builtin: true },
195
- { name: 'mcp', factory: sdk.createMcpExtension({ createTransport }), replaceable: true, builtin: true },
196
- ];
197
- }
198
-
199
- /** Project resources load only in a project the user has trusted, or one without any. */
200
- protected isTrusted(sdk: PiSdk, cwd: string, agentDir: string): boolean {
201
- return new sdk.ProjectTrustStore(agentDir).get(cwd) ?? !sdk.hasTrustRequiringProjectResources(cwd);
202
- }
203
-
204
- protected findModel(modelRuntime: ModelRuntime, ref: string): Model | undefined {
205
- const index = ref.indexOf('/');
206
- return index > 0 ? modelRuntime.getModel(ref.slice(0, index), ref.slice(index + 1)) : undefined;
207
- }
208
-
209
- protected resolveModel(modelRuntime: ModelRuntime, ref: string): Model {
210
- const model = this.findModel(modelRuntime, ref);
211
- if (!model) {
212
- throw TaErrors.modelNotFound(ref);
213
- }
214
- return model;
215
- }
216
- }
@@ -1,75 +0,0 @@
1
- import { Autowired, Component, Value } from '@celljs/core';
2
- import type { RpcConnection } from '@celljs/rpc/lib/node';
3
- import type { TaOpenSessionOptions } from '@celljs/ta-protocol';
4
- import { ClientChannel } from './client-channel';
5
- import { TA_HOST_OPTIONS, type TaHostOptions, TaSessionFactory, TaSessionRegistry } from './host-protocol';
6
- import { TaErrors } from './ta-errors';
7
- import type { TaSession } from './ta-session';
8
-
9
- @Component(TaSessionRegistry)
10
- export class DefaultTaSessionRegistry implements TaSessionRegistry {
11
- @Value(TA_HOST_OPTIONS)
12
- protected readonly options: TaHostOptions;
13
-
14
- @Autowired(TaSessionFactory)
15
- protected readonly factory: TaSessionFactory;
16
-
17
- protected readonly sessions = new Map<string, TaSession>();
18
- protected readonly channels = new WeakMap<RpcConnection, ClientChannel>();
19
- /** Sessions being created count against the limit too. */
20
- protected opening = 0;
21
-
22
- async open(options: TaOpenSessionOptions): Promise<TaSession> {
23
- if (this.sessions.size + this.opening >= this.options.maxSessions) {
24
- throw TaErrors.tooManySessions(this.options.maxSessions);
25
- }
26
- this.opening++;
27
- try {
28
- const session = await this.factory.create(options, ended => void this.close(ended.id));
29
- this.sessions.set(session.id, session);
30
- return session;
31
- } finally {
32
- this.opening--;
33
- }
34
- }
35
-
36
- require(sessionId: string): TaSession {
37
- const session = this.sessions.get(sessionId);
38
- if (!session) {
39
- throw TaErrors.sessionNotFound(sessionId);
40
- }
41
- return session;
42
- }
43
-
44
- list(): TaSession[] {
45
- return [...this.sessions.values()];
46
- }
47
-
48
- async close(sessionId: string): Promise<void> {
49
- const session = this.sessions.get(sessionId);
50
- if (session) {
51
- this.sessions.delete(sessionId);
52
- await session.close();
53
- }
54
- }
55
-
56
- async closeAll(): Promise<void> {
57
- await Promise.all([...this.sessions.keys()].map(id => this.close(id)));
58
- }
59
-
60
- /** The one channel of a connection; it leaves every session when the connection ends. */
61
- channel(connection: RpcConnection): ClientChannel {
62
- let channel = this.channels.get(connection);
63
- if (!channel) {
64
- const created = new ClientChannel(connection, this.options.clientBacklogBytes);
65
- this.channels.set(connection, created);
66
- connection.onClose(() => {
67
- for (const session of this.list()) {
68
- session.detach(created);
69
- }
70
- });
71
- channel = created;
72
- }
73
- return channel;
74
- }
75
- }
@@ -1,241 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import type { SessionLock } from '@celljs/ta-harness';
3
- import type {
4
- RpcExtensionUIResponse,
5
- TaAttachResult,
6
- TaClientToolResult,
7
- TaEvent,
8
- TaNavigateResult,
9
- TaPromptInput,
10
- TaPromptReceipt,
11
- TaSessionInfo,
12
- } from '@celljs/ta-protocol';
13
- import type { ClientChannel } from './client-channel';
14
- import type { ClientToolBroker } from './client-tool-broker';
15
- import { EventLog } from './event-log';
16
- import type { TaHostOptions } from './host-protocol';
17
- import { ReceiptBook } from './receipt-book';
18
- import { RemoteUiContext } from './remote-ui-context';
19
- import { SessionInfoUtil } from './session-info-util';
20
- import { TaEventUtil } from './ta-event-util';
21
-
22
- type AgentSessionRuntime = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSessionRuntime;
23
- type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSession;
24
- type PromptDisposition = 'started' | 'queued' | 'handled';
25
-
26
- export interface TaSessionContext {
27
- runtime: AgentSessionRuntime;
28
- lock: SessionLock;
29
- /** The tools of the session that its clients run. */
30
- clientTools: ClientToolBroker;
31
- options: TaHostOptions;
32
- /** The session should end: it has been idle, or an extension asked. */
33
- requestClose(session: TaSession): void;
34
- /** TaOpenSessionOptions.group. */
35
- group?: string;
36
- /** The location of the directory pi works in (PiDirectories.fromPi); default: that directory. */
37
- locate?(cwd: string): string;
38
- }
39
-
40
- /**
41
- * One open session of `ta serve`: pi's runtime, its event log, and the clients attached to it. Its id
42
- * stays the same while the runtime moves between conversations.
43
- */
44
- export class TaSession {
45
- readonly id = randomUUID();
46
- readonly createdAt = Date.now();
47
- readonly ui: RemoteUiContext;
48
- readonly runtime: AgentSessionRuntime;
49
- protected readonly log: EventLog;
50
- protected readonly receipts = new ReceiptBook();
51
- protected readonly channels = new Set<ClientChannel>();
52
- protected unsubscribe?: () => void;
53
- protected idleTimer?: ReturnType<typeof setTimeout>;
54
- protected started = false;
55
-
56
- constructor(protected readonly context: TaSessionContext) {
57
- this.runtime = context.runtime;
58
- this.log = new EventLog(this.id, context.options.eventBufferBytes);
59
- this.ui = new RemoteUiContext(event => this.publish(event));
60
- context.clientTools.connect(event => this.publish(event));
61
- }
62
-
63
- get pi(): AgentSession {
64
- return this.runtime.session;
65
- }
66
-
67
- /** Where the session works, as clients name it: a path, or an `ssh://` location. */
68
- get cwd(): string {
69
- return this.context.locate ? this.context.locate(this.runtime.cwd) : this.runtime.cwd;
70
- }
71
-
72
- async start(): Promise<void> {
73
- this.runtime.setRebindSession(() => this.bind());
74
- await this.bind();
75
- this.started = true;
76
- this.watchIdle();
77
- }
78
-
79
- info(): TaSessionInfo {
80
- const { pi } = this;
81
- // Without a model pi's agent holds a placeholder that no runtime knows.
82
- const model = pi.model && pi.modelRuntime.getModel(pi.model.provider, pi.model.id);
83
- return {
84
- sessionId: this.id,
85
- piSessionId: pi.sessionId,
86
- cwd: this.cwd,
87
- sessionFile: pi.sessionFile,
88
- sessionName: pi.sessionName,
89
- firstMessage: SessionInfoUtil.firstMessage(pi.messages),
90
- model: model ? `${model.provider}/${model.id}` : undefined,
91
- isStreaming: pi.isStreaming,
92
- messageCount: pi.messages.length,
93
- attached: this.channels.size,
94
- createdAt: this.createdAt,
95
- updatedAt: SessionInfoUtil.updatedAt(pi.messages, this.createdAt),
96
- group: this.context.group,
97
- };
98
- }
99
-
100
- attach(channel: ClientChannel, afterSeq?: number): TaAttachResult {
101
- this.channels.add(channel);
102
- this.watchIdle();
103
- const { events, gap } = afterSeq === undefined ? { events: [], gap: false } : this.log.since(afterSeq);
104
- return {
105
- info: this.info(),
106
- events,
107
- pendingUi: this.ui.pendingRequests,
108
- shownUi: this.ui.shownRequests,
109
- pendingClientTools: this.context.clientTools.pendingRequests,
110
- lastSeq: this.log.lastSeq,
111
- gap,
112
- };
113
- }
114
-
115
- detach(channel: ClientChannel): void {
116
- if (this.channels.delete(channel)) {
117
- this.watchIdle();
118
- }
119
- }
120
-
121
- respondUi(response: RpcExtensionUIResponse): boolean {
122
- return this.ui.respond(response);
123
- }
124
-
125
- respondClientTool(result: TaClientToolResult): boolean {
126
- return this.context.clientTools.respond(result);
127
- }
128
-
129
- prompt(input: TaPromptInput): Promise<TaPromptReceipt> {
130
- return this.accept(
131
- input,
132
- () =>
133
- new Promise<PromptDisposition>((resolve, reject) => {
134
- this.pi
135
- .prompt(input.message, {
136
- images: input.images,
137
- streamingBehavior: input.streamingBehavior ?? 'followUp',
138
- source: 'rpc',
139
- preflightResult: resolve,
140
- })
141
- // After the preflight, failures of the run reach the clients as events.
142
- .then(() => resolve('handled'), reject);
143
- }),
144
- );
145
- }
146
-
147
- steer(input: TaPromptInput): Promise<TaPromptReceipt> {
148
- return this.accept(input, () => this.pi.steer(input.message, input.images, { source: 'rpc' }));
149
- }
150
-
151
- followUp(input: TaPromptInput): Promise<TaPromptReceipt> {
152
- return this.accept(input, () => this.pi.followUp(input.message, input.images, { source: 'rpc' }));
153
- }
154
-
155
- /** pi's runtime says nothing of a move in the tree: the clients are told to read the conversation again. */
156
- async navigateTree(targetId: string, options?: Parameters<AgentSession['navigateTree']>[1]): Promise<TaNavigateResult> {
157
- const { cancelled, editorText } = await this.pi.navigateTree(targetId, options);
158
- if (!cancelled) {
159
- this.publish({ type: 'session_replaced', info: this.info() });
160
- }
161
- return { cancelled, editorText };
162
- }
163
-
164
- async close(): Promise<void> {
165
- clearTimeout(this.idleTimer);
166
- this.ui.cancelAll();
167
- this.context.clientTools.cancelAll();
168
- this.publish({ type: 'session_closed' });
169
- this.channels.clear();
170
- this.unsubscribe?.();
171
- if (this.pi.isStreaming) {
172
- await this.pi.abort();
173
- }
174
- await this.runtime.dispose();
175
- this.context.lock.releaseAll();
176
- }
177
-
178
- protected async accept(input: TaPromptInput, run: () => Promise<PromptDisposition>): Promise<TaPromptReceipt> {
179
- const duplicate = this.receipts.take(input);
180
- if (duplicate) {
181
- return duplicate;
182
- }
183
- try {
184
- const disposition = await run();
185
- return { clientMessageId: input.clientMessageId, status: disposition === 'queued' ? 'queued' : 'accepted' };
186
- } catch (error) {
187
- this.receipts.forget(input.clientMessageId);
188
- throw error;
189
- }
190
- }
191
-
192
- /** Connects this object to the session the runtime has now: at the start and after each replacement. */
193
- protected async bind(): Promise<void> {
194
- this.unsubscribe?.();
195
- const { pi, runtime } = this;
196
- await pi.bindExtensions({
197
- uiContext: this.ui,
198
- mode: 'rpc',
199
- commandContextActions: {
200
- waitForIdle: () => pi.waitForIdle(),
201
- newSession: options => runtime.newSession(options),
202
- fork: async (entryId, options) => ({ cancelled: (await runtime.fork(entryId, options)).cancelled }),
203
- navigateTree: async (targetId, options) => ({ cancelled: (await this.navigateTree(targetId, options)).cancelled }),
204
- switchSession: (sessionPath, options) => runtime.switchSession(sessionPath, options),
205
- reload: () => pi.reload(),
206
- },
207
- shutdownHandler: () => this.context.requestClose(this),
208
- onError: error => this.publish({ type: 'extension_error', extensionPath: error.extensionPath, event: error.event, error: error.error }),
209
- });
210
- this.unsubscribe = pi.subscribe(event => {
211
- this.publish(TaEventUtil.toWire(event));
212
- if (event.type === 'agent_settled') {
213
- this.watchIdle();
214
- }
215
- });
216
- if (this.started) {
217
- this.publish({ type: 'session_replaced', info: this.info() });
218
- }
219
- }
220
-
221
- protected publish(event: TaEvent): void {
222
- const logged = this.log.append(event);
223
- for (const channel of this.channels) {
224
- channel.send(logged);
225
- }
226
- }
227
-
228
- protected isIdle(): boolean {
229
- return this.channels.size === 0 && !this.pi.isStreaming && this.ui.pendingRequests.length === 0;
230
- }
231
-
232
- /** One timer per session, armed only when nothing is attached: an idle server does no work. */
233
- protected watchIdle(): void {
234
- clearTimeout(this.idleTimer);
235
- this.idleTimer = undefined;
236
- if (this.isIdle()) {
237
- this.idleTimer = setTimeout(() => this.isIdle() && this.context.requestClose(this), this.context.options.idleTimeoutMs);
238
- this.idleTimer.unref();
239
- }
240
- }
241
- }
@@ -1,18 +0,0 @@
1
- import type { RpcConnection } from '@celljs/rpc/lib/node';
2
- import type { TaOpenTerminalOptions, TaTerminalInfo } from '@celljs/ta-protocol';
3
-
4
- export const TaTerminals = Symbol('TaTerminals');
5
-
6
- /**
7
- * The shells of the web client's terminal. Each belongs to the connection that opened it and sends it
8
- * its output (TaClient.onTerminalData). When that connection drops, the shell waits 30 s for another
9
- * to take it (listTerminals, writeTerminal or resizeTerminal) and keeps its output meanwhile; then it ends.
10
- */
11
- export interface TaTerminals {
12
- open(connection: RpcConnection, options: TaOpenTerminalOptions & { cwd: string }): Promise<TaTerminalInfo>;
13
- write(connection: RpcConnection, terminalId: string, data: string): void;
14
- resize(connection: RpcConnection, terminalId: string, cols: number, rows: number): Promise<void>;
15
- close(connection: RpcConnection, terminalId: string): Promise<void>;
16
- list(connection: RpcConnection): TaTerminalInfo[];
17
- closeAll(): Promise<void>;
18
- }
@@ -1,119 +0,0 @@
1
- import { afterEach, describe, expect, it } from 'bun:test';
2
- import { realpathSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import type { RpcConnection } from '@celljs/rpc/lib/node';
5
- import { LocalExecEnvironment } from '@celljs/ta-exec';
6
- import { DefaultTaTerminals } from './terminal-service';
7
-
8
- /** A connection that keeps what the shells sent it. */
9
- class FakeConnection {
10
- readonly id = String(Math.random());
11
- closed = false;
12
- output = '';
13
- exitCode?: number;
14
- protected readonly closeListeners: (() => void)[] = [];
15
-
16
- client() {
17
- return {
18
- onTerminalData: async (_terminalId: string, data: string, exitCode?: number) => {
19
- this.output += data;
20
- this.exitCode ??= exitCode;
21
- },
22
- };
23
- }
24
-
25
- onClose(listener: () => void) {
26
- this.closeListeners.push(listener);
27
- return { dispose: () => undefined };
28
- }
29
-
30
- close() {
31
- this.closed = true;
32
- for (const listener of this.closeListeners) {
33
- listener();
34
- }
35
- }
36
- }
37
-
38
- async function until(check: () => boolean, what: string): Promise<void> {
39
- for (let i = 0; i < 500 && !check(); i++) {
40
- await Bun.sleep(10);
41
- }
42
- if (!check()) {
43
- throw new Error(`Timed out waiting until ${what}`);
44
- }
45
- }
46
-
47
- describe('DefaultTaTerminals', () => {
48
- const cwd = realpathSync(tmpdir());
49
- const terminals = new DefaultTaTerminals();
50
- Object.assign(terminals, { environments: { create: (dir: string) => new LocalExecEnvironment(dir), defaultCwd: async () => cwd } });
51
- const as = (connection: FakeConnection) => connection as unknown as RpcConnection;
52
-
53
- afterEach(() => terminals.closeAll());
54
-
55
- it('runs a shell and sends its output to the connection that opened it', async () => {
56
- const connection = new FakeConnection();
57
- const info = await terminals.open(as(connection), { cwd, cols: 80, rows: 24 });
58
- expect(info.cwd).toBe(cwd);
59
- expect(info.terminalId).toBeString();
60
- terminals.write(as(connection), info.terminalId, 'echo ta-$((40+2))\r');
61
- await until(() => connection.output.includes('ta-42'), 'the shell answered');
62
- expect(connection.output).not.toContain('ta-tty=');
63
- expect(terminals.list(as(connection))).toEqual([info]);
64
- await terminals.resize(as(connection), info.terminalId, 100, 30);
65
- terminals.write(as(connection), info.terminalId, 'exit\r');
66
- await until(() => connection.exitCode !== undefined, 'the shell ended');
67
- expect(terminals.list(as(connection))).toEqual([]);
68
- });
69
-
70
- it('sizes the shell as its view asked, even before the shell named its terminal', async () => {
71
- const connection = new FakeConnection();
72
- const info = await terminals.open(as(connection), { cwd, cols: 80, rows: 24 });
73
- if (!info.pty) {
74
- return;
75
- }
76
- await terminals.resize(as(connection), info.terminalId, 101, 31);
77
- await Bun.sleep(300);
78
- terminals.write(as(connection), info.terminalId, 'stty size\r');
79
- await until(() => connection.output.includes('31 101'), 'the shell has the size of its view');
80
- });
81
-
82
- it('asks each machine for its own shell and system', async () => {
83
- const asked: string[] = [];
84
- const service = new DefaultTaTerminals();
85
- const detect = (service as unknown as { detect(env: { exec: unknown; local: boolean }, machine: string): Promise<{ system: string }> }).detect.bind(
86
- service,
87
- );
88
- const env = (system: string) => ({
89
- local: false,
90
- exec: async (_command: string, options: { onData(data: Uint8Array): void }) => {
91
- asked.push(system);
92
- options.onData(new TextEncoder().encode(`${system}\n/usr/bin/script\n/bin/zsh`));
93
- return { exitCode: 0 };
94
- },
95
- });
96
- expect((await detect(env('Linux'), 'box')).system).toBe('Linux');
97
- expect((await detect(env('Darwin'), '')).system).toBe('Darwin');
98
- expect((await detect(env('Darwin'), 'box')).system).toBe('Linux');
99
- expect(asked).toEqual(['Linux', 'Darwin']);
100
- });
101
-
102
- it('keeps a shell for another connection after its own dropped', async () => {
103
- const first = new FakeConnection();
104
- const info = await terminals.open(as(first), { cwd, cols: 80, rows: 24 });
105
- const stranger = new FakeConnection();
106
- expect(terminals.list(as(stranger))).toEqual([]);
107
- expect(() => terminals.write(as(stranger), info.terminalId, 'x')).toThrow('No terminal');
108
- terminals.write(as(first), info.terminalId, 'echo first-$((1+2))\r');
109
- await until(() => first.output.includes('first-3'), 'the first connection got the output');
110
- first.close();
111
- const second = new FakeConnection();
112
- expect(terminals.list(as(second))).toEqual([info]);
113
- await until(() => second.output.startsWith('\x1bc') && second.output.includes('first-3'), 'the second connection got what the shell showed before');
114
- terminals.write(as(second), info.terminalId, 'echo back-$((1+1))\r');
115
- await until(() => second.output.includes('back-2'), 'the second connection got the output');
116
- await terminals.close(as(second), info.terminalId);
117
- expect(terminals.list(as(second))).toEqual([]);
118
- });
119
- });