@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,291 +0,0 @@
1
- import { type Application, ApplicationLifecycle, Autowired, Component } from '@celljs/core';
2
- import type { RpcConnection } from '@celljs/rpc/lib/node';
3
- import { type ExecEnvironment, ExecEnvironmentFactory, type ExecProcess } from '@celljs/ta-exec';
4
- import { TaClient, TaLocation, type TaOpenTerminalOptions, type TaTerminalInfo } from '@celljs/ta-protocol';
5
- import { TaErrors } from './ta-errors';
6
- import { TaTerminals } from './terminal-protocol';
7
- import { PipeDiscipline, type TerminalPlatform, TerminalUtil, TtyMarker } from './terminal-util';
8
-
9
- /** How long a shell waits for a connection after its own dropped. */
10
- export const TERMINAL_ORPHAN_MS = 30000;
11
- /** Output a shell keeps while no connection takes it; older output goes first. */
12
- const MAX_PENDING_CHARS = 256 * 1024;
13
- /** Output of the same moment leaves in one message. */
14
- const FLUSH_MS = 8;
15
- const DEFAULT_COLS = 80;
16
- const DEFAULT_ROWS = 24;
17
-
18
- class Terminal {
19
- owner?: RpcConnection;
20
- orphanTimer?: ReturnType<typeof setTimeout>;
21
- pending = '';
22
- /** The last output, for a page that takes the shell again after its own went (a reload). */
23
- history = '';
24
- flushTimer?: ReturnType<typeof setTimeout>;
25
- sending = false;
26
- /** The code the shell ended with, as it said, or as its process did. */
27
- exitCode?: number;
28
- /** Its process ended. */
29
- exited = false;
30
- /** The size its view asked for last; it waits for the name of the terminal when that is not known yet. */
31
- size?: { cols: number; rows: number };
32
- /** Its client knows it ended: nothing more goes. */
33
- ended = false;
34
- readonly decoder = new TextDecoder();
35
- readonly marker = new TtyMarker();
36
- readonly discipline?: PipeDiscipline;
37
-
38
- constructor(
39
- readonly info: TaTerminalInfo,
40
- readonly env: ExecEnvironment,
41
- readonly platform: TerminalPlatform,
42
- readonly process: ExecProcess,
43
- pty: boolean,
44
- owner: RpcConnection,
45
- ) {
46
- this.owner = owner;
47
- this.discipline = pty ? undefined : new PipeDiscipline();
48
- }
49
- }
50
-
51
- @Component([TaTerminals, ApplicationLifecycle])
52
- export class DefaultTaTerminals implements TaTerminals, ApplicationLifecycle<Application> {
53
- @Autowired(ExecEnvironmentFactory)
54
- protected readonly environments: ExecEnvironmentFactory;
55
-
56
- protected readonly terminals = new Map<string, Terminal>();
57
- protected readonly watched = new WeakSet<RpcConnection>();
58
- /** By machine: `''` for this one (or the exec server), else the host of `ssh://`. */
59
- protected readonly platforms = new Map<string, Promise<TerminalPlatform>>();
60
- protected nextId = 0;
61
-
62
- async open(connection: RpcConnection, options: TaOpenTerminalOptions & { cwd: string }): Promise<TaTerminalInfo> {
63
- const env = this.environments.create(options.cwd);
64
- const stat = await env.stat(env.cwd);
65
- if (!stat?.isDirectory) {
66
- throw TaErrors.invalidArgument(`${options.cwd} is not a directory.`, 'Open the terminal in a directory that exists.');
67
- }
68
- const platform = await this.detect(env, this.machine(options.cwd));
69
- const launch = TerminalUtil.launch(platform, TerminalUtil.size(options.cols, DEFAULT_COLS), TerminalUtil.size(options.rows, DEFAULT_ROWS));
70
- // `pty`: false when the shell runs on pipes, so that the view can say why some programs behave otherwise.
71
- const info: TaTerminalInfo & { pty: boolean } = { terminalId: `t${++this.nextId}`, cwd: options.cwd, shell: platform.shell, pty: launch.pty };
72
- const terminal = new Terminal(info, env, platform, env.spawn(launch.command, launch.args), launch.pty, connection);
73
- this.terminals.set(info.terminalId, terminal);
74
- this.watch(connection);
75
- const receive = (data: Uint8Array) => this.output(terminal, terminal.decoder.decode(data, { stream: true }));
76
- terminal.process.onStdout(receive);
77
- terminal.process.onStderr(receive);
78
- terminal.process.onExit(code => this.exited(terminal, code));
79
- return info;
80
- }
81
-
82
- write(connection: RpcConnection, terminalId: string, data: string): void {
83
- const terminal = this.require(connection, terminalId);
84
- if (!terminal.discipline) {
85
- terminal.process.write(data);
86
- return;
87
- }
88
- const { echo, send } = terminal.discipline.input(data);
89
- this.queue(terminal, echo);
90
- if (send) {
91
- terminal.process.write(send);
92
- }
93
- }
94
-
95
- async resize(connection: RpcConnection, terminalId: string, cols: number, rows: number): Promise<void> {
96
- const terminal = this.require(connection, terminalId);
97
- terminal.size = { cols: TerminalUtil.size(cols, DEFAULT_COLS), rows: TerminalUtil.size(rows, DEFAULT_ROWS) };
98
- await this.applySize(terminal);
99
- }
100
-
101
- /** A view sizes its shell as soon as it shows, often before the shell named its terminal: the size waits for it. */
102
- protected async applySize(terminal: Terminal): Promise<void> {
103
- if (terminal.marker.tty && terminal.size) {
104
- const command = TerminalUtil.resizeCommand(terminal.platform, terminal.marker.tty, terminal.size.cols, terminal.size.rows);
105
- await terminal.env.exec(command, { timeout: 5000 });
106
- }
107
- }
108
-
109
- close(connection: RpcConnection, terminalId: string): Promise<void> {
110
- return this.end(this.require(connection, terminalId));
111
- }
112
-
113
- list(connection: RpcConnection): TaTerminalInfo[] {
114
- const own: TaTerminalInfo[] = [];
115
- for (const terminal of this.terminals.values()) {
116
- if (!terminal.owner) {
117
- this.adopt(terminal, connection);
118
- }
119
- if (terminal.owner === connection) {
120
- own.push(terminal.info);
121
- }
122
- }
123
- return own;
124
- }
125
-
126
- onStop(): Promise<void> {
127
- return this.closeAll();
128
- }
129
-
130
- async closeAll(): Promise<void> {
131
- await Promise.all([...this.terminals.values()].map(terminal => this.end(terminal)));
132
- }
133
-
134
- /** The shell of this connection, or one nobody has: it becomes this connection's. */
135
- protected require(connection: RpcConnection, terminalId: string): Terminal {
136
- const terminal = this.terminals.get(terminalId);
137
- if (!terminal || (terminal.owner && terminal.owner !== connection)) {
138
- throw TaErrors.invalidArgument(
139
- `No terminal of this connection has the id ${terminalId}.`,
140
- 'Open one with openTerminal; listTerminals has those still open.',
141
- );
142
- }
143
- if (!terminal.owner) {
144
- this.adopt(terminal, connection);
145
- }
146
- return terminal;
147
- }
148
-
149
- /**
150
- * A connection takes a shell nobody has. What its page shows went with the page: it gets the last
151
- * output again, after a reset, so that a page that kept its screen does not show it twice.
152
- */
153
- protected adopt(terminal: Terminal, connection: RpcConnection): void {
154
- clearTimeout(terminal.orphanTimer);
155
- terminal.orphanTimer = undefined;
156
- terminal.owner = connection;
157
- terminal.pending = terminal.history ? `${TerminalUtil.RESET}${terminal.history}` : terminal.pending;
158
- this.watch(connection);
159
- this.schedule(terminal);
160
- }
161
-
162
- protected watch(connection: RpcConnection): void {
163
- if (this.watched.has(connection)) {
164
- return;
165
- }
166
- this.watched.add(connection);
167
- connection.onClose(() => {
168
- for (const terminal of this.terminals.values()) {
169
- if (terminal.owner === connection) {
170
- terminal.owner = undefined;
171
- terminal.orphanTimer = setTimeout(() => void this.end(terminal), TERMINAL_ORPHAN_MS);
172
- }
173
- }
174
- });
175
- }
176
-
177
- protected output(terminal: Terminal, text: string): void {
178
- const { text: rest, exitCode } = TerminalUtil.takeExitCode(text);
179
- terminal.exitCode ??= exitCode;
180
- const named = terminal.marker.tty !== undefined;
181
- const shown = terminal.marker.feed(rest);
182
- if (!named && terminal.marker.tty !== undefined) {
183
- void this.applySize(terminal).catch(() => undefined);
184
- }
185
- this.queue(terminal, terminal.discipline ? terminal.discipline.output(shown) : shown);
186
- }
187
-
188
- protected queue(terminal: Terminal, text: string): void {
189
- if (!text) {
190
- return;
191
- }
192
- terminal.pending += text;
193
- if (terminal.pending.length > MAX_PENDING_CHARS) {
194
- terminal.pending = TerminalUtil.tail(terminal.pending, MAX_PENDING_CHARS);
195
- }
196
- terminal.history = TerminalUtil.tail(terminal.history + text, MAX_PENDING_CHARS);
197
- this.schedule(terminal);
198
- }
199
-
200
- protected schedule(terminal: Terminal): void {
201
- const due = terminal.pending || terminal.exited;
202
- if (terminal.flushTimer === undefined && terminal.owner && !terminal.ended && due) {
203
- terminal.flushTimer = setTimeout(() => this.flush(terminal), FLUSH_MS);
204
- }
205
- }
206
-
207
- /** One message at a time: the next leaves when the client has the last. */
208
- protected flush(terminal: Terminal): void {
209
- terminal.flushTimer = undefined;
210
- const owner = terminal.owner;
211
- if (!owner || owner.closed || terminal.sending) {
212
- return;
213
- }
214
- const data = terminal.pending;
215
- const exitCode = terminal.exited ? (terminal.exitCode ?? -1) : undefined;
216
- terminal.pending = '';
217
- terminal.sending = true;
218
- owner
219
- .client<TaClient>(TaClient)
220
- .onTerminalData(terminal.info.terminalId, data, exitCode)
221
- .then(
222
- () => {
223
- if (exitCode !== undefined) {
224
- terminal.ended = true;
225
- this.terminals.delete(terminal.info.terminalId);
226
- }
227
- },
228
- () => {
229
- // Lost on the way: it goes again to whoever takes the shell.
230
- terminal.pending = data + terminal.pending;
231
- },
232
- )
233
- .finally(() => {
234
- terminal.sending = false;
235
- this.schedule(terminal);
236
- });
237
- }
238
-
239
- protected exited(terminal: Terminal, exitCode: number | null): void {
240
- const rest = terminal.decoder.decode() + terminal.marker.flush();
241
- this.queue(terminal, terminal.discipline ? terminal.discipline.output(rest) : rest);
242
- terminal.exitCode ??= exitCode ?? undefined;
243
- terminal.exited = true;
244
- clearTimeout(terminal.orphanTimer);
245
- if (terminal.owner) {
246
- this.schedule(terminal);
247
- } else {
248
- this.terminals.delete(terminal.info.terminalId);
249
- }
250
- }
251
-
252
- /** Hangs up its terminal, which ends what runs there, then the wrapper. */
253
- protected async end(terminal: Terminal): Promise<void> {
254
- clearTimeout(terminal.orphanTimer);
255
- this.terminals.delete(terminal.info.terminalId);
256
- if (terminal.marker.tty) {
257
- await terminal.env.exec(TerminalUtil.hangUpCommand(terminal.marker.tty), { timeout: 5000 }).catch(() => undefined);
258
- }
259
- terminal.process.kill();
260
- }
261
-
262
- /** The machine of a location: its shell, `script` and system are those of that machine. */
263
- protected machine(location: string): string {
264
- try {
265
- return TaLocation.parse(location)?.host ?? '';
266
- } catch {
267
- return '';
268
- }
269
- }
270
-
271
- protected detect(env: ExecEnvironment, machine: string): Promise<TerminalPlatform> {
272
- let platform = this.platforms.get(machine);
273
- if (platform) {
274
- return platform;
275
- }
276
- platform = (async () => {
277
- let output = '';
278
- const decoder = new TextDecoder();
279
- const { exitCode } = await env.exec(`${TerminalUtil.PROBE} 2>/dev/null`, {
280
- timeout: 5000,
281
- onData: data => (output += decoder.decode(data, { stream: true })),
282
- });
283
- const fallback = env.local && process.platform === 'win32' ? (process.env.ComSpec ?? 'cmd.exe') : '/bin/sh';
284
- return exitCode === 0 ? TerminalUtil.parsePlatform(output, fallback) : { system: '', script: false, shell: fallback };
285
- })();
286
- // A machine that could not answer is asked again next time.
287
- platform.catch(() => this.platforms.delete(machine));
288
- this.platforms.set(machine, platform);
289
- return platform;
290
- }
291
- }
@@ -1,109 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { PipeDiscipline, TerminalUtil, TtyMarker } from './terminal-util';
3
-
4
- describe('TerminalUtil', () => {
5
- it('reads the platform', () => {
6
- expect(TerminalUtil.parsePlatform('Darwin\n/usr/bin/script\n/bin/zsh', '/bin/sh')).toEqual({ system: 'Darwin', script: true, shell: '/bin/zsh' });
7
- expect(TerminalUtil.parsePlatform('Linux\n\n', '/bin/sh')).toEqual({ system: 'Linux', script: false, shell: '/bin/sh' });
8
- });
9
-
10
- it('runs the shell on a pseudo-terminal when script is there', () => {
11
- const mac = TerminalUtil.launch({ system: 'Darwin', script: true, shell: '/bin/zsh' }, 100, 30);
12
- expect(mac).toMatchObject({ command: '/bin/sh', pty: true });
13
- expect(mac.args[1]).toStartWith('cat | { script -q /dev/null /bin/sh -c ');
14
- expect(mac.args[1]).toContain('stty cols 100 rows 30');
15
- expect(mac.args[1]).toContain('/bin/zsh');
16
- expect(mac.args[1]).toContain('BASH_SILENCE_DEPRECATION_WARNING=1');
17
- expect(mac.args[1]).toEndWith('kill $$; }');
18
- const linux = TerminalUtil.launch({ system: 'Linux', script: true, shell: '/bin/bash' }, 80, 24);
19
- expect(linux.args[1]).toStartWith('cat | { script -qefc ');
20
- expect(linux.args[1]).toContain(' /dev/null; code=$?');
21
- expect(TerminalUtil.launch({ system: 'Linux', script: false, shell: '/bin/bash' }, 80, 24)).toEqual({ command: '/bin/bash', args: ['-i'], pty: false });
22
- });
23
-
24
- it('resizes with the stty of the system', () => {
25
- expect(TerminalUtil.resizeCommand({ system: 'Linux', script: true, shell: '' }, '/dev/pts/3', 120, 40)).toBe("stty -F '/dev/pts/3' cols 120 rows 40");
26
- expect(TerminalUtil.resizeCommand({ system: 'Darwin', script: true, shell: '' }, '/dev/ttys001', 80, 24)).toBe(
27
- "stty -f '/dev/ttys001' cols 80 rows 24",
28
- );
29
- expect(TerminalUtil.hangUpCommand('/dev/pts/3')).toBe("kill -HUP $(ps -t 'pts/3' -o pid=)");
30
- expect(TerminalUtil.size(0, 80)).toBe(1);
31
- expect(TerminalUtil.size(Number.NaN, 80)).toBe(80);
32
- expect(TerminalUtil.size(99999, 80)).toBe(1000);
33
- });
34
- });
35
-
36
- describe('TerminalUtil.takeExitCode', () => {
37
- it('takes the code the wrapper printed', () => {
38
- expect(TerminalUtil.takeExitCode('bye\x1b]1337;ta-exit=3\x07')).toEqual({ text: 'bye', exitCode: 3 });
39
- expect(TerminalUtil.takeExitCode('plain')).toEqual({ text: 'plain' });
40
- });
41
- });
42
-
43
- describe('TtyMarker', () => {
44
- it('takes the name of the terminal out of the output, in pieces too', () => {
45
- const marker = new TtyMarker();
46
- expect(marker.feed('^D\x1b]1337;ta-')).toBe('');
47
- expect(marker.feed('tty=/dev/ttys004\x07$ ')).toBe('^D$ ');
48
- expect(marker.tty).toBe('/dev/ttys004');
49
- expect(marker.feed('more')).toBe('more');
50
- });
51
-
52
- it('gives up after a while, and gives back what it held', () => {
53
- const marker = new TtyMarker();
54
- expect(marker.feed('x'.repeat(5000))).toHaveLength(5000);
55
- expect(marker.tty).toBeUndefined();
56
- const early = new TtyMarker();
57
- early.feed('bye');
58
- expect(early.flush()).toBe('bye');
59
- });
60
- });
61
-
62
- describe('PipeDiscipline', () => {
63
- it('echoes, edits the line, and sends it on Enter', () => {
64
- const discipline = new PipeDiscipline();
65
- expect(discipline.input('lsx')).toEqual({ echo: 'lsx', send: '' });
66
- expect(discipline.input('\x7f')).toEqual({ echo: '\b \b', send: '' });
67
- expect(discipline.input('\x1b[A -l\r')).toEqual({ echo: ' -l\r\n', send: 'ls -l\n' });
68
- discipline.input('oops');
69
- expect(discipline.input('\x03').echo).toBe('^C\r\n');
70
- expect(discipline.input('\r').send).toBe('\n');
71
- discipline.input('ab');
72
- expect(discipline.input('\x15').echo).toBe('\b \b\b \b');
73
- });
74
-
75
- it('turns line feeds into what a terminal shows', () => {
76
- expect(new PipeDiscipline().output('a\nb\r\n')).toBe('a\r\nb\r\n');
77
- });
78
- });
79
-
80
- describe('TerminalUtil.tail', () => {
81
- it('keeps the end, from the start of a line', () => {
82
- expect(TerminalUtil.tail('abc', 10)).toBe('abc');
83
- expect(TerminalUtil.tail('one\r\n\x1b[31mtwo\r\nthree', 12)).toBe('three');
84
- expect(TerminalUtil.tail('abcdefgh', 3)).toBe('fgh');
85
- });
86
- });
87
-
88
- describe('TerminalUtil.UTF8_LOCALE', () => {
89
- const ctype = (env: Record<string, string>) =>
90
- new TextDecoder()
91
- .decode(
92
- Bun.spawnSync(['/bin/sh', '-c', `${TerminalUtil.UTF8_LOCALE}; printf '%s|%s' "$LC_CTYPE" "$LC_ALL"`], {
93
- env: { PATH: process.env.PATH ?? '/usr/bin:/bin', ...env },
94
- }).stdout,
95
- )
96
- .split('|');
97
-
98
- it('gives a shell without a UTF-8 locale one for its characters', () => {
99
- const [lcCtype, lcAll] = ctype({ LANG: 'C' });
100
- expect(lcCtype).toMatch(/utf-?8$/i);
101
- expect(lcAll).toBe('');
102
- expect(ctype({ LC_ALL: 'POSIX' }).every(value => /utf-?8$/i.test(value))).toBe(true);
103
- });
104
-
105
- it('leaves a UTF-8 locale as it is', () => {
106
- expect(ctype({ LANG: 'zh_CN.UTF-8' })).toEqual(['', '']);
107
- expect(ctype({ LC_CTYPE: 'en_US.utf8' })).toEqual(['en_US.utf8', '']);
108
- });
109
- });
@@ -1,197 +0,0 @@
1
- import { WorkspaceUtil } from './workspace-util';
2
-
3
- /** What the environment has for a shell: its system (`uname -s`), `script` and the user's shell. */
4
- export interface TerminalPlatform {
5
- system: string;
6
- script: boolean;
7
- shell: string;
8
- }
9
-
10
- export interface TerminalLaunch {
11
- command: string;
12
- args: string[];
13
- /** Runs on a pseudo-terminal: the shell echoes and edits lines itself. */
14
- pty: boolean;
15
- }
16
-
17
- /** The shell prints the name of its terminal first, between these, so that resizing can find it. */
18
- const TTY_START = '\x1b]1337;ta-tty=';
19
- const TTY_END = '\x07';
20
- const ESC = '\x1b';
21
- const EXIT_MARK = new RegExp(`${ESC}\\]1337;ta-exit=(\\d+)\x07`);
22
- /** Sequences of keys (arrows, F-keys): they mean nothing to a line. */
23
- const KEY_SEQUENCE = new RegExp(`${ESC}(?:\\[[0-9;?]*[ -/]*[@-~]|O.|.)?`, 'g');
24
- /** The name comes first or not at all: after this much output, nobody looks for it. */
25
- const TTY_SEARCH_CHARS = 4096;
26
-
27
- /**
28
- * Shells without node-pty: `script` (BSD's or util-linux's) gives one a pseudo-terminal; without it the
29
- * shell runs on pipes, and {@link PipeDiscipline} does what the terminal would.
30
- */
31
- export namespace TerminalUtil {
32
- /** A full reset of the terminal (RIS): its screen, scrollback and modes. */
33
- export const RESET = '\x1bc';
34
-
35
- /**
36
- * At most `max` characters of the end of `text`, from the start of a line when it is cut, so that it
37
- * does not start inside a control sequence or a character.
38
- */
39
- export function tail(text: string, max: number): string {
40
- if (text.length <= max) {
41
- return text;
42
- }
43
- const cut = text.slice(-max);
44
- const line = cut.indexOf('\n');
45
- return line < 0 ? cut : cut.slice(line + 1);
46
- }
47
-
48
- /**
49
- * A shell started by ssh or by an app of the desktop often has no locale (`C`): it then reads
50
- * Chinese, typed or pasted, as bytes it cannot show (`<ffffffff>`), and programs print `?`. When
51
- * the locale is not UTF-8, the shell gets one for its characters (LC_CTYPE, and LC_ALL when set):
52
- * C.UTF-8 where the system has it, else en_US.UTF-8; its messages and formats stay as they were.
53
- */
54
- export const UTF8_LOCALE = [
55
- 'case "${LC_ALL:-${LC_CTYPE:-$LANG}}" in *[Uu][Tt][Ff]-8*|*[Uu][Tt][Ff]8*) ;; *)',
56
- "ta_utf8=$(locale -a 2>/dev/null | grep -i -x -m 1 -E 'c\\.utf-?8|en_us\\.utf-?8'); ta_utf8=${ta_utf8:-en_US.UTF-8};",
57
- '[ -n "$LC_ALL" ] && export LC_ALL="$ta_utf8"; export LC_CTYPE="$ta_utf8"; unset ta_utf8;;',
58
- 'esac',
59
- ].join(' ');
60
-
61
- /** The command that tells the platform: three lines. */
62
- export const PROBE = 'uname -s; command -v script; printf %s "$SHELL"';
63
-
64
- export function parsePlatform(output: string, fallbackShell: string): TerminalPlatform {
65
- const [system = '', script = '', shell = ''] = output.split('\n').map(line => line.trim());
66
- return { system, script: script.length > 0, shell: shell || fallbackShell };
67
- }
68
-
69
- /**
70
- * The shell, on a pseudo-terminal when `script` is there. `script` reads a pipe, not the socket
71
- * the server hands it (BSD's refuses one): `cat` sits between. When the shell ends, the wrapper
72
- * prints its code and ends itself, so that `cat` ends with it.
73
- */
74
- export function launch(platform: TerminalPlatform, cols: number, rows: number): TerminalLaunch {
75
- const quote = WorkspaceUtil.quote;
76
- const boot = [
77
- // macOS's bash 3.2 otherwise asks to switch to zsh on each start.
78
- 'export TERM=xterm-256color BASH_SILENCE_DEPRECATION_WARNING=1',
79
- UTF8_LOCALE,
80
- // Sized before it says its name: a resize that waited for the name comes after this size.
81
- `stty cols ${cols} rows ${rows} 2>/dev/null`,
82
- `printf '\\033]1337;ta-tty=%s\\007' "$(tty)"`,
83
- `exec ${quote(platform.shell)} -i`,
84
- ].join('; ');
85
- let script: string | undefined;
86
- if (platform.script && platform.system === 'Linux') {
87
- // -e: util-linux's script ends with 0 unless asked for the code of the shell.
88
- script = `script -qefc ${quote(`/bin/sh -c ${quote(boot)}`)} /dev/null`;
89
- } else if (platform.script && /^(Darwin|FreeBSD|OpenBSD|NetBSD)$/.test(platform.system)) {
90
- script = `script -q /dev/null /bin/sh -c ${quote(boot)}`;
91
- }
92
- if (script) {
93
- const wrapper = `cat | { ${script}; code=$?; printf '\\033]1337;ta-exit=%s\\007' "$code"; kill $$; }`;
94
- return { command: '/bin/sh', args: ['-c', wrapper], pty: true };
95
- }
96
- return { command: platform.shell, args: /cmd(\.exe)?$/i.test(platform.shell) ? [] : ['-i'], pty: false };
97
- }
98
-
99
- /** Ends every program of the terminal `tty`, not only the shell. */
100
- export function hangUpCommand(tty: string): string {
101
- return `kill -HUP $(ps -t ${WorkspaceUtil.quote(tty.replace(/^\/dev\//, ''))} -o pid=)`;
102
- }
103
-
104
- /** The code the wrapper of {@link launch} printed, taken out of the output. */
105
- export function takeExitCode(text: string): { text: string; exitCode?: number } {
106
- const found = EXIT_MARK.exec(text);
107
- return found ? { text: text.replace(EXIT_MARK, ''), exitCode: Number(found[1]) } : { text };
108
- }
109
-
110
- /** Sets the size of the terminal `tty`; its programs get SIGWINCH. */
111
- export function resizeCommand(platform: TerminalPlatform, tty: string, cols: number, rows: number): string {
112
- const flag = platform.system === 'Linux' ? '-F' : '-f';
113
- return `stty ${flag} ${WorkspaceUtil.quote(tty)} cols ${cols} rows ${rows}`;
114
- }
115
-
116
- /** At least one column and row, whole numbers, not absurd. */
117
- export function size(value: number, fallback: number): number {
118
- return Number.isFinite(value) ? Math.min(1000, Math.max(1, Math.floor(value))) : fallback;
119
- }
120
- }
121
-
122
- /** Takes the name of the terminal out of the first output of the shell. */
123
- export class TtyMarker {
124
- tty?: string;
125
- protected head = '';
126
- protected done = false;
127
-
128
- /** The output without the name. */
129
- feed(text: string): string {
130
- if (this.done) {
131
- return text;
132
- }
133
- this.head += text;
134
- const start = this.head.indexOf(TTY_START);
135
- const end = start < 0 ? -1 : this.head.indexOf(TTY_END, start);
136
- if (end >= 0) {
137
- this.tty = this.head.slice(start + TTY_START.length, end).trim() || undefined;
138
- return this.finish(this.head.slice(0, start) + this.head.slice(end + TTY_END.length));
139
- }
140
- if (this.head.length > TTY_SEARCH_CHARS) {
141
- return this.finish(this.head);
142
- }
143
- return '';
144
- }
145
-
146
- /** What it holds, when the shell ended before naming its terminal. */
147
- flush(): string {
148
- return this.done ? '' : this.finish(this.head);
149
- }
150
-
151
- protected finish(text: string): string {
152
- this.done = true;
153
- this.head = '';
154
- return text;
155
- }
156
- }
157
-
158
- /**
159
- * The line discipline of a terminal for a shell on pipes: it echoes what the user types, edits the
160
- * line (backspace, Ctrl+U, Ctrl+C) and sends it whole on Enter; output gets `\r\n` for `\n`.
161
- */
162
- export class PipeDiscipline {
163
- protected line = '';
164
-
165
- /** What to show, and what to send to the shell. */
166
- input(data: string): { echo: string; send: string } {
167
- let echo = '';
168
- let send = '';
169
- const text = data.replace(KEY_SEQUENCE, '');
170
- for (const char of Array.from(text)) {
171
- if (char === '\r' || char === '\n') {
172
- send += `${this.line}\n`;
173
- echo += '\r\n';
174
- this.line = '';
175
- } else if (char === '\x7f' || char === '\b') {
176
- if (this.line) {
177
- this.line = Array.from(this.line).slice(0, -1).join('');
178
- echo += '\b \b';
179
- }
180
- } else if (char === '\x03') {
181
- echo += '^C\r\n';
182
- this.line = '';
183
- } else if (char === '\x15') {
184
- echo += '\b \b'.repeat(Array.from(this.line).length);
185
- this.line = '';
186
- } else if (char === '\t' || char >= ' ') {
187
- this.line += char;
188
- echo += char;
189
- }
190
- }
191
- return { echo, send };
192
- }
193
-
194
- output(text: string): string {
195
- return text.replace(/\r?\n/g, '\r\n');
196
- }
197
- }