@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,158 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
2
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, utimesSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { PiSdkUtil } from '@celljs/ai-coding-agent';
6
- import { SettingsLockUtil, TaSettingsStoreImpl, TaSettingsUtil } from './settings-store';
7
-
8
- describe('TaSettingsUtil', () => {
9
- it('reads the settings ta changes, the model from its two keys, and leaves out values pi would not take', () => {
10
- const file = {
11
- defaultProvider: 'anthropic',
12
- defaultModel: 'claude/x',
13
- compaction: { enabled: false, reserveTokens: -1 },
14
- transport: 'pigeon',
15
- theme: 'dark',
16
- };
17
- expect(TaSettingsUtil.read(file)).toEqual({ model: 'anthropic/claude/x', 'compaction.enabled': false });
18
- });
19
-
20
- it('changes keys and keeps the others; null removes a key and the objects it leaves empty', () => {
21
- const file = { theme: 'dark', compaction: { enabled: false }, defaultProvider: 'a', defaultModel: 'b' };
22
- const next = TaSettingsUtil.apply(file, { 'compaction.enabled': null, 'retry.maxRetries': 5, model: 'openai/gpt-5' });
23
- expect(next).toEqual({ theme: 'dark', retry: { maxRetries: 5 }, defaultProvider: 'openai', defaultModel: 'gpt-5' });
24
- expect(file.compaction.enabled).toBe(false);
25
- expect(TaSettingsUtil.apply(next, { model: null })).toEqual({ theme: 'dark', retry: { maxRetries: 5 } });
26
- });
27
-
28
- it('refuses keys it does not know and values that are not of the setting', () => {
29
- expect(() => TaSettingsUtil.apply({}, { theme: 'dark' })).toThrow('not a setting clients change');
30
- expect(() => TaSettingsUtil.apply({}, { transport: 'pigeon' })).toThrow('not a value of transport');
31
- expect(() => TaSettingsUtil.apply({}, { 'retry.maxRetries': 1.5 })).toThrow('not a value of retry.maxRetries');
32
- expect(() => TaSettingsUtil.apply({}, { model: 'no-provider' })).toThrow('not a value of model');
33
- expect(TaSettingsUtil.apply({ shellPath: '/bin/zsh' }, { shellPath: ' ' })).toEqual({});
34
- });
35
-
36
- it('does not overwrite a file it cannot read', () => {
37
- expect(TaSettingsUtil.parse('', 'f')).toEqual({});
38
- expect(() => TaSettingsUtil.parse('{', 'f')).toThrow('not valid JSON');
39
- expect(() => TaSettingsUtil.parse('[]', 'f')).toThrow('JSON object');
40
- });
41
- });
42
-
43
- describe('TaSettingsStoreImpl', () => {
44
- let root: string;
45
- let agentDir: string;
46
- let cwd: string;
47
- let store: TaSettingsStoreImpl;
48
- /** `.ta` under ta, pi's own name in tests. */
49
- let configDir: string;
50
- const reloaded: string[] = [];
51
-
52
- function session(dir: string) {
53
- let trusted = false;
54
- return {
55
- cwd: dir,
56
- pi: {
57
- settingsManager: {
58
- isProjectTrusted: () => trusted,
59
- setProjectTrusted: (value: boolean) => {
60
- trusted = value;
61
- },
62
- reload: async () => {
63
- reloaded.push(`${dir}:${trusted}`);
64
- },
65
- },
66
- },
67
- };
68
- }
69
-
70
- beforeEach(async () => {
71
- configDir = (await PiSdkUtil.load()).CONFIG_DIR_NAME;
72
- root = mkdtempSync(join(tmpdir(), 'ta-settings-'));
73
- agentDir = join(root, 'agent');
74
- cwd = join(root, 'project');
75
- mkdirSync(agentDir);
76
- mkdirSync(cwd);
77
- reloaded.length = 0;
78
- store = new TaSettingsStoreImpl();
79
- Object.assign(store, {
80
- codingAgentOptions: { agentDir },
81
- modelRuntimeProvider: { provide: async () => ({ getAvailable: async () => [{ provider: 'fake', id: 'fake-1', name: 'Fake One' }] }) },
82
- extensionProviders: { ensure: async () => undefined },
83
- sessions: { list: () => [session(cwd), session(join(root, 'other'))] },
84
- directories: { toPi: (location: string) => location, fromPi: (dir: string) => dir },
85
- });
86
- });
87
- afterEach(() => rmSync(root, { recursive: true, force: true }));
88
-
89
- it('writes the settings of the user next to what the file had, and has every session read them again', async () => {
90
- writeFileSync(join(agentDir, 'settings.json'), JSON.stringify({ theme: 'dark', packages: ['npm:x'] }));
91
- const snapshot = await store.update('user', { 'compaction.enabled': false, model: 'fake/fake-1' }, cwd);
92
- expect(snapshot.user).toEqual({ model: 'fake/fake-1', 'compaction.enabled': false });
93
- expect(snapshot.models).toEqual(['fake/fake-1']);
94
- expect(snapshot.modelNames).toEqual({ 'fake/fake-1': 'Fake One' });
95
- expect(JSON.parse(readFileSync(join(agentDir, 'settings.json'), 'utf8'))).toEqual({
96
- theme: 'dark',
97
- packages: ['npm:x'],
98
- compaction: { enabled: false },
99
- defaultProvider: 'fake',
100
- defaultModel: 'fake-1',
101
- });
102
- expect(reloaded).toHaveLength(2);
103
- });
104
-
105
- it('writes the settings of a project in its directory, trusts the project, and reloads only its sessions', async () => {
106
- const first = await store.get(cwd);
107
- expect(first.projectTrusted).toBe(true);
108
- expect(first.projectFile).toBe(join(cwd, configDir, 'settings.json'));
109
- const snapshot = await store.update('project', { 'retry.enabled': false }, cwd);
110
- expect(snapshot.project).toEqual({ 'retry.enabled': false });
111
- expect(snapshot.projectTrusted).toBe(true);
112
- expect(reloaded).toEqual([`${cwd}:true`]);
113
- expect(Object.values(JSON.parse(readFileSync(join(agentDir, 'trust.json'), 'utf8')))).toEqual([true]);
114
- });
115
-
116
- it('does not write the settings of a project the user has not trusted yet', async () => {
117
- mkdirSync(join(cwd, configDir, 'extensions'), { recursive: true });
118
- expect((await store.get(cwd)).projectTrusted).toBe(false);
119
- await expect(store.update('project', { 'retry.enabled': false }, cwd)).rejects.toThrow('does not trust');
120
- expect(existsSync(join(cwd, configDir, 'settings.json'))).toBe(false);
121
- });
122
-
123
- it('keeps both of two changes made at once', async () => {
124
- await Promise.all([store.update('user', { 'retry.enabled': false }, cwd), store.update('user', { 'retry.maxRetries': 7 }, cwd)]);
125
- expect((await store.get(cwd)).user).toEqual({ 'retry.enabled': false, 'retry.maxRetries': 7 });
126
- });
127
- });
128
- describe('SettingsLockUtil', () => {
129
- let dir: string;
130
- beforeEach(() => {
131
- dir = mkdtempSync(join(tmpdir(), 'ta-settings-lock-'));
132
- });
133
- afterEach(() => rmSync(dir, { recursive: true, force: true }));
134
-
135
- it('holds the lock pi takes while it works, and lets it go after, also when the work fails', async () => {
136
- const file = join(dir, 'agent/settings.json');
137
- expect(await SettingsLockUtil.run(file, async () => existsSync(`${file}.lock`))).toBe(true);
138
- expect(existsSync(`${file}.lock`)).toBe(false);
139
- await expect(SettingsLockUtil.run(file, () => Promise.reject(new Error('broken')))).rejects.toThrow('broken');
140
- expect(existsSync(`${file}.lock`)).toBe(false);
141
- });
142
-
143
- it('waits for a lock another process holds, and takes over one that is stale', async () => {
144
- const file = join(dir, 'settings.json');
145
- mkdirSync(`${file}.lock`);
146
- const order: string[] = [];
147
- const waiting = SettingsLockUtil.run(file, async () => void order.push('ta'));
148
- await new Promise(resolve => setTimeout(resolve, 60));
149
- order.push('other');
150
- rmSync(`${file}.lock`, { recursive: true });
151
- await waiting;
152
- expect(order).toEqual(['other', 'ta']);
153
- mkdirSync(`${file}.lock`);
154
- const old = (Date.now() - SettingsLockUtil.STALE_MS - 1000) / 1000;
155
- utimesSync(`${file}.lock`, old, old);
156
- expect(await SettingsLockUtil.run(file, async () => 'taken')).toBe('taken');
157
- });
158
- });
@@ -1,327 +0,0 @@
1
- import { mkdir, readFile, rename, rmdir, stat, writeFile } from 'node:fs/promises';
2
- import { dirname, join } from 'node:path';
3
- import { CODING_AGENT_OPTIONS, type CodingAgentOptions, ModelRuntimeProvider, PiSdkUtil } from '@celljs/ai-coding-agent';
4
- import { Autowired, Component, Value } from '@celljs/core';
5
- import { TA_SETTINGS, type TaSettingSpec, type TaSettingsScope, type TaSettingsSnapshot } from '@celljs/ta-protocol';
6
- import { ExtensionProviders } from './extension-providers';
7
- import { TaSessionRegistry } from './host-protocol';
8
- import { PiDirectories } from './remote/remote-protocol';
9
- import { TaErrors } from './ta-errors';
10
-
11
- export const TaSettingsStore = Symbol('TaSettingsStore');
12
-
13
- /** The settings of ta (TA_SETTINGS) in pi's `settings.json` of the user and of a project. */
14
- export interface TaSettingsStore {
15
- get(cwd: string): Promise<TaSettingsSnapshot>;
16
- update(scope: TaSettingsScope, changes: Record<string, unknown>, cwd: string): Promise<TaSettingsSnapshot>;
17
- }
18
-
19
- type Json = Record<string, unknown>;
20
-
21
- export namespace TaSettingsUtil {
22
- const MODEL = 'model';
23
-
24
- /** The settings of TA_SETTINGS that a file sets, by key. */
25
- export function read(data: Json, specs: readonly TaSettingSpec[] = TA_SETTINGS): Json {
26
- const values: Json = {};
27
- for (const spec of specs) {
28
- if (spec.key === MODEL) {
29
- if (typeof data.defaultProvider === 'string' && typeof data.defaultModel === 'string') {
30
- values[MODEL] = `${data.defaultProvider}/${data.defaultModel}`;
31
- }
32
- continue;
33
- }
34
- const value = at(data, spec.key);
35
- if (value !== undefined && check(spec, value) !== undefined) {
36
- values[spec.key] = value;
37
- }
38
- }
39
- return values;
40
- }
41
-
42
- /** The file with the changes; the other keys stay. Throws for a key or a value ta does not take. */
43
- export function apply(data: Json, changes: Json, specs: readonly TaSettingSpec[] = TA_SETTINGS): Json {
44
- const next = structuredClone(data);
45
- for (const [key, raw] of Object.entries(changes)) {
46
- const spec = specs.find(candidate => candidate.key === key);
47
- if (!spec) {
48
- throw TaErrors.invalidArgument(
49
- `${key} is not a setting clients change.`,
50
- `Use one of ${specs.map(other => other.key).join(', ')}; edit settings.json for the others.`,
51
- );
52
- }
53
- // Blank text removes the key, as a cleared field means.
54
- const removes = raw === null || raw === undefined || (typeof raw === 'string' && !raw.trim());
55
- const value = removes ? undefined : check(spec, raw);
56
- if (!removes && value === undefined) {
57
- throw TaErrors.invalidArgument(`${JSON.stringify(raw)} is not a value of ${key}.`, describe(spec));
58
- }
59
- if (key === MODEL) {
60
- const [provider, ...id] = typeof value === 'string' ? value.split('/') : [];
61
- put(next, 'defaultProvider', provider);
62
- put(next, 'defaultModel', provider ? id.join('/') : undefined);
63
- } else {
64
- put(next, key, value);
65
- }
66
- }
67
- return next;
68
- }
69
-
70
- /** The value as the setting keeps it, or undefined when it is not one. An empty string is no value. */
71
- export function check(spec: TaSettingSpec, value: unknown): unknown {
72
- switch (spec.type) {
73
- case 'boolean':
74
- return typeof value === 'boolean' ? value : undefined;
75
- case 'number':
76
- return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : undefined;
77
- case 'enum':
78
- return typeof value === 'string' && spec.values?.includes(value) ? value : undefined;
79
- case 'model':
80
- return typeof value === 'string' && /^[^/\s]+\/\S+$/.test(value.trim()) ? value.trim() : undefined;
81
- default:
82
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
83
- }
84
- }
85
-
86
- function describe(spec: TaSettingSpec): string {
87
- switch (spec.type) {
88
- case 'boolean':
89
- return 'Pass true or false, or null to remove it.';
90
- case 'number':
91
- return 'Pass a whole number of 0 or more, or null to remove it.';
92
- case 'enum':
93
- return `Pass one of ${spec.values?.join(', ')}, or null to remove it.`;
94
- case 'model':
95
- return 'Pass <provider>/<model id>, or null to remove it.';
96
- default:
97
- return 'Pass text, or null to remove it.';
98
- }
99
- }
100
-
101
- function at(data: Json, key: string): unknown {
102
- let value: unknown = data;
103
- for (const part of key.split('.')) {
104
- value = value && typeof value === 'object' && !Array.isArray(value) ? (value as Json)[part] : undefined;
105
- }
106
- return value;
107
- }
108
-
109
- /** Sets a dotted key; undefined removes it, and the objects it leaves empty. */
110
- function put(data: Json, key: string, value: unknown): void {
111
- const parts = key.split('.');
112
- const last = parts.pop() as string;
113
- const parents: Json[] = [data];
114
- let target = data;
115
- for (const part of parts) {
116
- const child = target[part];
117
- if (!child || typeof child !== 'object' || Array.isArray(child)) {
118
- if (value === undefined) {
119
- return;
120
- }
121
- target[part] = {};
122
- }
123
- target = target[part] as Json;
124
- parents.push(target);
125
- }
126
- if (value === undefined) {
127
- delete target[last];
128
- for (let index = parts.length - 1; index >= 0; index--) {
129
- if (Object.keys(parents[index + 1]).length === 0) {
130
- delete parents[index][parts[index]];
131
- }
132
- }
133
- } else {
134
- target[last] = value;
135
- }
136
- }
137
-
138
- export function parse(text: string | undefined, file: string): Json {
139
- if (!text?.trim()) {
140
- return {};
141
- }
142
- let data: unknown;
143
- try {
144
- data = JSON.parse(text);
145
- } catch (error) {
146
- throw TaErrors.invalidArgument(
147
- `${file} is not valid JSON: ${(error as Error).message}`,
148
- 'Fix the file by hand first; ta does not overwrite what it cannot read.',
149
- );
150
- }
151
- if (!data || typeof data !== 'object' || Array.isArray(data)) {
152
- throw TaErrors.invalidArgument(`${file} does not hold a JSON object.`, 'Fix the file by hand first; ta does not overwrite what it cannot read.');
153
- }
154
- return data as Json;
155
- }
156
- }
157
-
158
- /**
159
- * The lock pi takes on a settings file while it writes it (proper-lockfile: a directory `<file>.lock`, taken
160
- * over when older than 10 s), so that a write of ta serve and one of `ta` in a terminal do not lose each
161
- * other's changes: pi reads the file again under the lock and writes back only what it changed.
162
- */
163
- export namespace SettingsLockUtil {
164
- export const STALE_MS = 10_000;
165
- const RETRY_MS = 20;
166
- const ATTEMPTS = 250;
167
-
168
- export async function run<T>(file: string, work: () => Promise<T>): Promise<T> {
169
- const lock = `${file}.lock`;
170
- await mkdir(dirname(file), { recursive: true });
171
- for (let attempt = 0; ; attempt++) {
172
- try {
173
- await mkdir(lock);
174
- break;
175
- } catch (error) {
176
- if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
177
- throw error;
178
- }
179
- const since = await stat(lock).then(
180
- info => Date.now() - info.mtimeMs,
181
- () => 0,
182
- );
183
- if (since > STALE_MS) {
184
- await rmdir(lock).catch(() => undefined);
185
- } else if (attempt >= ATTEMPTS) {
186
- throw TaErrors.invalidArgument(`${file} stays locked by another process.`, `Try again; if no Ta is running, delete ${lock}.`);
187
- } else {
188
- await new Promise(resolve => setTimeout(resolve, RETRY_MS));
189
- }
190
- }
191
- }
192
- try {
193
- return await work();
194
- } finally {
195
- await rmdir(lock).catch(() => undefined);
196
- }
197
- }
198
- }
199
-
200
- /**
201
- * Reads and writes the settings of ta where pi keeps them, under pi's lock of the file (SettingsLockUtil), and has the open sessions read them again. A
202
- * file is written whole, through a temporary file, with its other keys as they were.
203
- */
204
- @Component(TaSettingsStore)
205
- export class TaSettingsStoreImpl implements TaSettingsStore {
206
- @Value(CODING_AGENT_OPTIONS)
207
- protected readonly codingAgentOptions?: CodingAgentOptions;
208
-
209
- @Autowired(ModelRuntimeProvider)
210
- protected readonly modelRuntimeProvider: ModelRuntimeProvider;
211
-
212
- @Autowired(TaSessionRegistry)
213
- protected readonly sessions: TaSessionRegistry;
214
-
215
- @Autowired(ExtensionProviders)
216
- protected readonly extensionProviders: ExtensionProviders;
217
-
218
- @Autowired(PiDirectories)
219
- protected readonly directories: PiDirectories;
220
-
221
- /** One write at a time, so that two changes of one file both stay. */
222
- protected writing: Promise<unknown> = Promise.resolve();
223
-
224
- async get(cwd: string): Promise<TaSettingsSnapshot> {
225
- const { userFile, projectFile, trusted } = await this.files(cwd);
226
- const [user, project, { models, modelNames }] = await Promise.all([this.read(userFile), this.read(projectFile), this.models()]);
227
- return {
228
- user: TaSettingsUtil.read(user),
229
- project: TaSettingsUtil.read(project),
230
- cwd,
231
- userFile,
232
- projectFile,
233
- projectTrusted: trusted !== false,
234
- models,
235
- modelNames,
236
- };
237
- }
238
-
239
- update(scope: TaSettingsScope, changes: Record<string, unknown>, cwd: string): Promise<TaSettingsSnapshot> {
240
- const next = this.writing.then(() => this.write(scope, changes, cwd));
241
- this.writing = next.catch(() => undefined);
242
- return next;
243
- }
244
-
245
- protected async write(scope: TaSettingsScope, changes: Record<string, unknown>, cwd: string): Promise<TaSettingsSnapshot> {
246
- if (!changes || typeof changes !== 'object' || Array.isArray(changes)) {
247
- throw TaErrors.invalidArgument('The changes are an object of settings.', 'Pass { key: value }, with null to remove a key.');
248
- }
249
- const { userFile, projectFile, trusted, trust } = await this.files(cwd);
250
- if (scope === 'project' && trusted === false) {
251
- throw TaErrors.invalidArgument(
252
- `ta does not trust ${cwd}, so it does not read the settings of the project.`,
253
- 'Run ta in that directory and trust the project, or change the settings of the user.',
254
- );
255
- }
256
- const file = scope === 'user' ? userFile : projectFile;
257
- await SettingsLockUtil.run(file, async () => {
258
- const data = TaSettingsUtil.apply(await this.read(file), changes);
259
- await writeFile(`${file}.tmp`, `${JSON.stringify(data, null, 2)}\n`);
260
- await rename(`${file}.tmp`, file);
261
- });
262
- // A project with nothing pi asks about: the user writing its settings is trusting it, else pi would ignore them.
263
- if (scope === 'project' && trusted === undefined) {
264
- trust();
265
- }
266
- await this.reloadSessions(scope, cwd);
267
- return this.get(cwd);
268
- }
269
-
270
- /**
271
- * `trusted`: pi's decision for the project, or false when it has resources pi asks about first;
272
- * undefined when nobody decided and there is nothing to ask about, as pi trusts it then.
273
- */
274
- protected async files(location: string): Promise<{ userFile: string; projectFile: string; trusted?: boolean; trust(): void }> {
275
- // The project of a directory of another machine is the directory here that pi works in for it.
276
- const cwd = this.directories.toPi(location);
277
- const sdk = await PiSdkUtil.load();
278
- const agentDir = this.codingAgentOptions?.agentDir ?? sdk.getAgentDir();
279
- const store = new sdk.ProjectTrustStore(agentDir);
280
- const decision = store.get(cwd);
281
- return {
282
- userFile: join(agentDir, 'settings.json'),
283
- projectFile: join(cwd, sdk.CONFIG_DIR_NAME, 'settings.json'),
284
- trusted: decision ?? (sdk.hasTrustRequiringProjectResources(cwd) ? false : undefined),
285
- trust: () => store.set(cwd, true),
286
- };
287
- }
288
-
289
- protected async read(file: string): Promise<Record<string, unknown>> {
290
- const text = await readFile(file, 'utf8').catch((error: NodeJS.ErrnoException) => {
291
- if (error.code === 'ENOENT') {
292
- return undefined;
293
- }
294
- throw error;
295
- });
296
- return TaSettingsUtil.parse(text, file);
297
- }
298
-
299
- protected async models(): Promise<{ models: string[]; modelNames: Record<string, string> }> {
300
- try {
301
- const runtime = await this.modelRuntimeProvider.provide();
302
- await this.extensionProviders.ensure();
303
- const available = await runtime.getAvailable();
304
- const modelNames: Record<string, string> = {};
305
- for (const model of available) {
306
- if (model.name && model.name !== model.id) {
307
- modelNames[`${model.provider}/${model.id}`] = model.name;
308
- }
309
- }
310
- return { models: available.map(model => `${model.provider}/${model.id}`), modelNames };
311
- } catch {
312
- return { models: [], modelNames: {} };
313
- }
314
- }
315
-
316
- protected async reloadSessions(scope: TaSettingsScope, cwd: string): Promise<void> {
317
- for (const session of this.sessions.list()) {
318
- if (scope === 'user' || session.cwd === cwd) {
319
- const manager = session.pi.settingsManager;
320
- if (scope === 'project' && !manager.isProjectTrusted()) {
321
- manager.setProjectTrusted(true);
322
- }
323
- await manager.reload().catch(() => undefined);
324
- }
325
- }
326
- }
327
- }
@@ -1,36 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import type { IncomingMessage } from 'node:http';
3
- import { TaAccessUtil } from './ta-access';
4
-
5
- const request = (url: string, headers: Record<string, string> = {}) => ({ url, headers }) as unknown as IncomingMessage;
6
-
7
- describe('TaAccessUtil', () => {
8
- it('reads the token from the header or the query', () => {
9
- expect(TaAccessUtil.tokenOf(request('/api/ws', { authorization: 'Bearer abc' }))).toBe('abc');
10
- expect(TaAccessUtil.tokenOf(request('/api/ws?token=abc'))).toBe('abc');
11
- expect(TaAccessUtil.tokenOf(request('/api/ws'))).toBeUndefined();
12
- });
13
-
14
- it('compares tokens of any length', () => {
15
- expect(TaAccessUtil.equals('abc', 'abc')).toBe(true);
16
- expect(TaAccessUtil.equals('abc', 'abd')).toBe(false);
17
- expect(TaAccessUtil.equals('abc', 'abcd')).toBe(false);
18
- });
19
-
20
- it('knows the names of this machine', () => {
21
- expect(TaAccessUtil.isLoopbackHost('127.0.0.1:3000')).toBe(true);
22
- expect(TaAccessUtil.isLoopbackHost('localhost')).toBe(true);
23
- expect(TaAccessUtil.isLoopbackHost('[::1]:3000')).toBe(true);
24
- expect(TaAccessUtil.isLoopbackHost('evil.example:3000')).toBe(false);
25
- expect(TaAccessUtil.isLoopbackHost(undefined)).toBe(false);
26
- });
27
-
28
- it('tells calls over plain HTTP from the files and the pages', () => {
29
- const call = (method: string, url: string) => ({ method, url, headers: {} }) as unknown as IncomingMessage;
30
- expect(TaAccessUtil.isHttpCall(call('POST', '/api/TaServer'))).toBe(true);
31
- expect(TaAccessUtil.isHttpCall(call('POST', '/api/TaWorkspaceServer?token=abc'))).toBe(true);
32
- expect(TaAccessUtil.isHttpCall(call('GET', '/api/files/x/a.png'))).toBe(false);
33
- expect(TaAccessUtil.isHttpCall(call('GET', '/api/ws'))).toBe(false);
34
- expect(TaAccessUtil.isHttpCall(call('POST', '/index.html'))).toBe(false);
35
- });
36
- });
@@ -1,156 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { randomBytes, timingSafeEqual } from 'node:crypto';
3
- import { chmodSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
4
- import type { IncomingMessage, Server } from 'node:http';
5
- import type { AddressInfo } from 'node:net';
6
- import { join } from 'node:path';
7
- import { type Application, ApplicationLifecycle, Autowired, Component, Value } from '@celljs/core';
8
- import { RpcContext, RpcWebSocketGuard } from '@celljs/rpc/lib/node';
9
- import { TaServeStateUtil } from '@celljs/ta-harness/lib/node/serve-state';
10
- import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
11
- import { TA_SERVE_FILE, TA_WEBSOCKET_PATH, type TaServeInfo } from '@celljs/ta-protocol';
12
- import { type Context, Middleware, ServerAware } from '@celljs/web/lib/node';
13
- import { TaSessionRegistry } from './host-protocol';
14
-
15
- const LOOPBACK_NAMES = new Set(['127.0.0.1', 'localhost', '[::1]']);
16
-
17
- /** Where the calls go (`rpc.path`); everything else is the web client, if it is installed. */
18
- const API_PATH = '/api';
19
-
20
- /** The id of {@link TaAccess}, for what needs the token, as RelayBridge does. */
21
- export const TA_ACCESS = Symbol('TaAccess');
22
-
23
- /** Runs before everything else that handles a request. */
24
- export const ACCESS_MIDDLEWARE_PRIORITY = 10000;
25
-
26
- export namespace TaAccessUtil {
27
- /** From `Authorization: Bearer`, or `?token=` for browsers, whose WebSocket API cannot set headers. */
28
- export function tokenOf(request: IncomingMessage): string | undefined {
29
- const header = request.headers.authorization;
30
- if (header?.startsWith('Bearer ')) {
31
- return header.slice('Bearer '.length);
32
- }
33
- return new URL(request.url ?? '/', 'http://localhost').searchParams.get('token') ?? undefined;
34
- }
35
-
36
- export function equals(a: string, b: string): boolean {
37
- const [left, right] = [Buffer.from(a), Buffer.from(b)];
38
- return left.length === right.length && timingSafeEqual(left, right);
39
- }
40
-
41
- /** A page that rebinds its domain to 127.0.0.1 reaches the server with its own name in `Host`. */
42
- export function isLoopbackHost(host: string | undefined): boolean {
43
- return LOOPBACK_NAMES.has((host ?? '').replace(/:\d+$/, ''));
44
- }
45
-
46
- /** The files of the web client are the same for everyone: they hold no data, so they need no token. */
47
- export function isPublic(request: IncomingMessage): boolean {
48
- const path = (request.url ?? '/').split('?')[0];
49
- return (request.method === 'GET' || request.method === 'HEAD') && path !== API_PATH && !path.startsWith(`${API_PATH}/`);
50
- }
51
-
52
- /**
53
- * A JSON-RPC call over plain HTTP (`POST /api/<service>`), which @celljs/rpc answers too: ta serve takes
54
- * calls on its WebSocket only, where a call knows its connection (attach, terminals) and gets pushes.
55
- */
56
- export function isHttpCall(request: IncomingMessage): boolean {
57
- const path = (request.url ?? '/').split('?')[0];
58
- return request.method === 'POST' && path.startsWith(`${API_PATH}/`);
59
- }
60
-
61
- /** The token goes in the fragment, which the browser does not send to the server or in `Referer`. */
62
- export function webUrl(httpUrl: string, token: string): string {
63
- return `${httpUrl}/#token=${token}`;
64
- }
65
-
66
- /** Opens a URL in the user's browser. */
67
- export function openBrowser(url: string): void {
68
- const [command, ...args] =
69
- process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['cmd', '/c', 'start', '""', url] : ['xdg-open', url];
70
- const child = spawn(command, args, { stdio: 'ignore', detached: true });
71
- child.on('error', () => console.log(`ta serve: open ${url} in a browser`));
72
- child.unref();
73
- }
74
- }
75
-
76
- /**
77
- * The token of this server: `TA_SERVE_TOKEN`, which a parent process (the desktop app) can choose, or the
78
- * one of the last start, or a random one. It lets in connections and requests, and is published in a file
79
- * only this user can read. It stays across restarts with the port (TaServeStateUtil), so that the web app
80
- * installed from this address, which remembers both, signs in again by itself.
81
- */
82
- @Component([TA_ACCESS, RpcWebSocketGuard, Middleware, ServerAware, ApplicationLifecycle])
83
- export class TaAccess implements RpcWebSocketGuard, Middleware, ServerAware, ApplicationLifecycle<Application> {
84
- readonly priority = ACCESS_MIDDLEWARE_PRIORITY;
85
- readonly token = process.env.TA_SERVE_TOKEN || TaServeStateUtil.read().token || randomBytes(32).toString('base64url');
86
-
87
- @Value('server.host')
88
- protected readonly host?: string;
89
-
90
- @Autowired(TaSessionRegistry)
91
- protected readonly sessions: TaSessionRegistry;
92
-
93
- protected readonly infoFile = join(TaBrand.agentDir(), TA_SERVE_FILE);
94
-
95
- allows(request: IncomingMessage): boolean {
96
- const token = TaAccessUtil.tokenOf(request);
97
- return token !== undefined && TaAccessUtil.equals(token, this.token) && this.acceptsHost(request);
98
- }
99
-
100
- /** Calls over a WebSocket were checked when it opened; this covers plain HTTP. */
101
- async handle(ctx: Context, next: () => Promise<void>): Promise<void> {
102
- const request = ctx.request as unknown as IncomingMessage;
103
- if (RpcContext.connection()) {
104
- await next();
105
- return;
106
- }
107
- if (this.allows(request) && TaAccessUtil.isHttpCall(request)) {
108
- ctx.response.statusCode = 404;
109
- ctx.response.end(`Call ta serve over its WebSocket, ${TA_WEBSOCKET_PATH}.`);
110
- return;
111
- }
112
- if (this.allows(request) || (TaAccessUtil.isPublic(request) && this.acceptsHost(request))) {
113
- await next();
114
- return;
115
- }
116
- ctx.response.statusCode = 401;
117
- ctx.response.end('Unauthorized');
118
- }
119
-
120
- async setServer(server: Server): Promise<void> {
121
- const publish = () => this.publish(server);
122
- if (server.listening) {
123
- publish();
124
- } else {
125
- server.once('listening', publish);
126
- }
127
- }
128
-
129
- async onStop(): Promise<void> {
130
- rmSync(this.infoFile, { force: true });
131
- await this.sessions.closeAll();
132
- }
133
-
134
- protected acceptsHost(request: IncomingMessage): boolean {
135
- return !TaAccessUtil.isLoopbackHost(this.host) || TaAccessUtil.isLoopbackHost(request.headers.host);
136
- }
137
-
138
- protected publish(server: Server): void {
139
- const { port } = server.address() as AddressInfo;
140
- const origin = `${this.host ?? '127.0.0.1'}:${port}`;
141
- const info: TaServeInfo = { url: `ws://${origin}${TA_WEBSOCKET_PATH}`, token: this.token, pid: process.pid };
142
- mkdirSync(join(this.infoFile, '..'), { recursive: true });
143
- writeFileSync(this.infoFile, JSON.stringify(info), { mode: 0o600 });
144
- // The mode above only applies to a new file.
145
- chmodSync(this.infoFile, 0o600);
146
- // A token that a parent process chose is its to keep.
147
- const kept = TaServeStateUtil.read().token;
148
- TaServeStateUtil.write({ port, token: process.env.TA_SERVE_TOKEN ? kept : this.token });
149
- console.log(`ta serve: ${info.url} (token in ${this.infoFile})`);
150
- if (process.env.TA_SERVE_OPEN_WEB) {
151
- const url = TaAccessUtil.webUrl(`http://${origin}`, this.token);
152
- console.log(`ta serve: web client at ${url}`);
153
- TaAccessUtil.openBrowser(url);
154
- }
155
- }
156
- }