@celljs/ta-host 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +211 -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 +118 -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 +214 -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 +121 -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,108 +0,0 @@
1
- import { Autowired } from '@celljs/core';
2
- import { Rpc } from '@celljs/rpc';
3
- import { RpcContext } from '@celljs/rpc/lib/node';
4
- import { ExecEnvironmentFactory } from '@celljs/ta-exec';
5
- import {
6
- TA_UPLOAD_PART_BYTES,
7
- type TaCommandOutput,
8
- type TaDirEntry,
9
- type TaFileContent,
10
- type TaOpenTerminalOptions,
11
- type TaRunCommandOptions,
12
- type TaTerminalInfo,
13
- TaTerminalServer,
14
- type TaUploadOptions,
15
- TaWorkspaceServer,
16
- } from '@celljs/ta-protocol';
17
- import { TaErrors } from './ta-errors';
18
- import { TaTerminals } from './terminal-protocol';
19
- import { TaWorkspace, WorkspaceFiles } from './workspace-protocol';
20
-
21
- /** The files and programs of a directory, for the web client; `cwd` defaults to the server's directory. */
22
- @Rpc(TaWorkspaceServer)
23
- export class TaWorkspaceServerImpl implements TaWorkspaceServer {
24
- @Autowired(ExecEnvironmentFactory)
25
- protected readonly environments: ExecEnvironmentFactory;
26
-
27
- @Autowired(TaWorkspace)
28
- protected readonly workspace: TaWorkspace;
29
-
30
- @Autowired(WorkspaceFiles)
31
- protected readonly files: WorkspaceFiles;
32
-
33
- listDirectory(path: string, cwd?: string): Promise<TaDirEntry[]> {
34
- return TaErrors.guard(async () => this.workspace.listDirectory(await this.cwd(cwd), path));
35
- }
36
-
37
- readFile(path: string, cwd?: string): Promise<TaFileContent> {
38
- return TaErrors.guard(async () => this.workspace.readFile(await this.cwd(cwd), path));
39
- }
40
-
41
- writeFile(path: string, text: string, cwd?: string): Promise<void> {
42
- return TaErrors.guard(async () => this.workspace.writeFile(await this.cwd(cwd), path, text));
43
- }
44
-
45
- uploadFile(path: string, data: string, options: TaUploadOptions = {}): Promise<void> {
46
- return TaErrors.guard(async () => {
47
- if (typeof data !== 'string') {
48
- throw TaErrors.invalidArgument('No bytes to write.', 'Pass the bytes of the file in base64.');
49
- }
50
- const bytes = Buffer.from(data, 'base64');
51
- if (bytes.length > TA_UPLOAD_PART_BYTES) {
52
- throw TaErrors.invalidArgument(
53
- 'The part is too large.',
54
- `Send the file in parts of at most ${TA_UPLOAD_PART_BYTES} bytes, each after the first with append.`,
55
- );
56
- }
57
- await this.workspace.uploadFile(await this.cwd(options.cwd), path, bytes, options.append === true);
58
- });
59
- }
60
-
61
- fileUrl(path: string, cwd?: string): Promise<string> {
62
- return TaErrors.guard(async () => this.files.url(await this.cwd(cwd), path));
63
- }
64
-
65
- findFiles(query: string, cwd?: string, limit?: number): Promise<string[]> {
66
- return TaErrors.guard(async () => this.workspace.findFiles(await this.cwd(cwd), query, limit));
67
- }
68
-
69
- runCommand(command: string, args: string[], options: TaRunCommandOptions = {}): Promise<TaCommandOutput> {
70
- return TaErrors.guard(async () => this.workspace.runCommand(await this.cwd(options.cwd), command, args, options));
71
- }
72
-
73
- protected async cwd(cwd?: string): Promise<string> {
74
- return cwd || (await this.environments.defaultCwd());
75
- }
76
- }
77
-
78
- /** The shells of the connection that calls. */
79
- @Rpc(TaTerminalServer)
80
- export class TaTerminalServerImpl implements TaTerminalServer {
81
- @Autowired(ExecEnvironmentFactory)
82
- protected readonly environments: ExecEnvironmentFactory;
83
-
84
- @Autowired(TaTerminals)
85
- protected readonly terminals: TaTerminals;
86
-
87
- openTerminal(options: TaOpenTerminalOptions): Promise<TaTerminalInfo> {
88
- return TaErrors.guard(async () =>
89
- this.terminals.open(RpcContext.requireConnection(), { ...options, cwd: options.cwd || (await this.environments.defaultCwd()) }),
90
- );
91
- }
92
-
93
- writeTerminal(terminalId: string, data: string): Promise<void> {
94
- return TaErrors.guard(() => this.terminals.write(RpcContext.requireConnection(), terminalId, data));
95
- }
96
-
97
- resizeTerminal(terminalId: string, cols: number, rows: number): Promise<void> {
98
- return TaErrors.guard(() => this.terminals.resize(RpcContext.requireConnection(), terminalId, cols, rows));
99
- }
100
-
101
- closeTerminal(terminalId: string): Promise<void> {
102
- return TaErrors.guard(() => this.terminals.close(RpcContext.requireConnection(), terminalId));
103
- }
104
-
105
- listTerminals(): Promise<TaTerminalInfo[]> {
106
- return TaErrors.guard(() => this.terminals.list(RpcContext.requireConnection()));
107
- }
108
- }
@@ -1,123 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
2
- import { execSync } from 'node:child_process';
3
- import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { LocalExecEnvironment } from '@celljs/ta-exec';
7
- import { DefaultTaWorkspace } from './workspace-service';
8
-
9
- function write(file: string, content: string | Uint8Array) {
10
- mkdirSync(join(file, '..'), { recursive: true });
11
- writeFileSync(file, content);
12
- }
13
-
14
- function workspace(): DefaultTaWorkspace {
15
- const created = new DefaultTaWorkspace();
16
- Object.assign(created, { environments: { create: (cwd: string) => new LocalExecEnvironment(cwd), defaultCwd: async () => process.cwd() } });
17
- return created;
18
- }
19
-
20
- describe('DefaultTaWorkspace', () => {
21
- let root: string;
22
- let repo: string;
23
- const git = (command: string) => execSync(`git -c user.email=t@t -c user.name=t ${command}`, { cwd: repo, stdio: 'pipe' });
24
-
25
- beforeAll(() => {
26
- root = realpathSync(mkdtempSync(join(tmpdir(), 'ta-workspace-')));
27
- repo = join(root, 'repo');
28
- write(join(repo, '.gitignore'), 'ignored/\n');
29
- write(join(repo, 'src/app.ts'), 'export const needle = 1;\n');
30
- write(join(repo, 'src/view10.ts'), 'view\n');
31
- write(join(repo, 'src/view2.ts'), 'view\n');
32
- write(join(repo, 'README.md'), '# Needle\n');
33
- write(join(repo, 'ignored/needle.ts'), 'needle\n');
34
- write(join(repo, 'logo.png'), new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0, 0, 0]));
35
- git('init -q -b main');
36
- git('add -A');
37
- git('commit -qm init');
38
- write(join(repo, 'src/app.ts'), 'export const needle = 2;\n');
39
- write(join(repo, 'src/new.ts'), 'new\n');
40
- write(join(repo, 'README.md'), '# Needle!\n');
41
- git('add README.md');
42
- write(join(root, 'secret.txt'), 'secret');
43
- });
44
-
45
- afterAll(() => rmSync(root, { recursive: true, force: true }));
46
-
47
- it('lists a directory without .git, directories first', async () => {
48
- const entries = await workspace().listDirectory(repo, '');
49
- expect(entries.map(entry => entry.name)).toEqual(['ignored', 'src', '.gitignore', 'logo.png', 'README.md']);
50
- expect(entries.find(entry => entry.name === 'README.md')).toMatchObject({ path: 'README.md', kind: 'file', size: 10 });
51
- expect((await workspace().listDirectory(repo, 'src')).map(entry => entry.path)).toEqual(['src/app.ts', 'src/new.ts', 'src/view2.ts', 'src/view10.ts']);
52
- });
53
-
54
- it('does not leave the directory', async () => {
55
- await expect(workspace().listDirectory(repo, '..')).rejects.toThrow('outside');
56
- await expect(workspace().readFile(repo, '../secret.txt')).rejects.toThrow('outside');
57
- await expect(workspace().readFile(repo, '/etc/hosts')).rejects.toThrow('outside');
58
- });
59
-
60
- it('reads text, and only says so of binary files', async () => {
61
- expect(await workspace().readFile(repo, 'src/app.ts')).toEqual({
62
- path: 'src/app.ts',
63
- size: 25,
64
- binary: false,
65
- truncated: false,
66
- text: 'export const needle = 2;\n',
67
- });
68
- expect(await workspace().readFile(repo, 'logo.png')).toEqual({ path: 'logo.png', size: 7, binary: true, truncated: false });
69
- await expect(workspace().readFile(repo, 'src')).rejects.toThrow('not a file');
70
- });
71
-
72
- it('writes a file of an existing directory', async () => {
73
- await workspace().writeFile(root, 'written.txt', 'written\n');
74
- expect((await workspace().readFile(root, 'written.txt')).text).toBe('written\n');
75
- await expect(workspace().writeFile(repo, 'missing/a.txt', 'a')).rejects.toThrow('cannot be written');
76
- await expect(workspace().writeFile(repo, 'src', 'a')).rejects.toThrow('cannot be written');
77
- await expect(workspace().writeFile(repo, '../secret.txt', 'a')).rejects.toThrow('outside');
78
- });
79
-
80
- it('uploads bytes in parts, making the folders on the way', async () => {
81
- await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([0, 1, 2]), false);
82
- await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([3]), true);
83
- expect([...readFileSync(join(root, 'up/load/a.bin'))]).toEqual([0, 1, 2, 3]);
84
- await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([9]), false);
85
- expect([...readFileSync(join(root, 'up/load/a.bin'))]).toEqual([9]);
86
- await expect(workspace().uploadFile(root, 'up', new Uint8Array([1]), false)).rejects.toThrow('is a directory');
87
- await expect(workspace().uploadFile(root, '../out.bin', new Uint8Array([1]), false)).rejects.toThrow('outside');
88
- });
89
-
90
- it('reads the start of a large file', async () => {
91
- write(join(root, 'big/large.txt'), 'x'.repeat(1024 * 1024 + 10));
92
- const content = await workspace().readFile(join(root, 'big'), 'large.txt');
93
- expect(content).toMatchObject({ truncated: true, size: 1024 * 1024 + 10 });
94
- expect(content.text).toHaveLength(1024 * 1024);
95
- });
96
-
97
- it('finds files by name, without the ignored ones', async () => {
98
- expect(await workspace().findFiles(repo, 'app')).toEqual(['src/app.ts']);
99
- const all = await workspace().findFiles(repo, '', 100);
100
- expect(all).toContain('src/new.ts');
101
- expect(all).not.toContain('ignored/needle.ts');
102
- });
103
-
104
- it('runs a program without a shell, and keeps to its limits', async () => {
105
- const status = await workspace().runCommand(repo, 'git', ['status', '--porcelain']);
106
- expect(status).toMatchObject({ exitCode: 0, truncated: false, timedOut: false });
107
- expect(status.stdout).toContain(' M src/app.ts');
108
- const quoted = await workspace().runCommand(repo, 'printf', ['%s|', '$HOME', 'a b', "it's"]);
109
- expect(quoted.stdout).toBe("$HOME|a b|it's|");
110
- expect((await workspace().runCommand(repo, 'cat', [], { input: 'fed' })).stdout).toBe('fed');
111
- expect((await workspace().runCommand(repo, 'cat', [])).stdout).toBe('');
112
- const failed = await workspace().runCommand(repo, 'git', ['show', 'nope']);
113
- expect(failed.exitCode).not.toBe(0);
114
- expect(failed.stderr).toContain('nope');
115
- expect(await workspace().runCommand(repo, 'head', ['-c', '100', '/dev/zero'], { maxBytes: 10 })).toMatchObject({
116
- truncated: true,
117
- stdout: '\0'.repeat(10),
118
- });
119
- expect(await workspace().runCommand(repo, 'sleep', ['5'], { timeoutMs: 100 })).toMatchObject({ timedOut: true, exitCode: null });
120
- expect((await workspace().runCommand(repo, 'no-such-program-of-ta', [])).exitCode).not.toBe(0);
121
- await expect(workspace().runCommand(repo, '', [])).rejects.toThrow('No program');
122
- });
123
- });
@@ -1,235 +0,0 @@
1
- import { dirname } from 'node:path';
2
- import { Autowired, Component } from '@celljs/core';
3
- import { type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
4
- import type { TaCommandOutput, TaDirEntry, TaFileContent, TaRunCommandOptions } from '@celljs/ta-protocol';
5
- import { TaErrors } from './ta-errors';
6
- import { TaWorkspace } from './workspace-protocol';
7
- import { MAX_FILE_BYTES, WorkspaceUtil } from './workspace-util';
8
-
9
- /** The start of an output, up to `maxBytes`. */
10
- class OutputBuffer {
11
- protected readonly chunks: Uint8Array[] = [];
12
- protected size = 0;
13
- truncated = false;
14
-
15
- constructor(protected readonly maxBytes: number) {}
16
-
17
- add(data: Uint8Array): void {
18
- if (this.size + data.length > this.maxBytes) {
19
- this.truncated = true;
20
- data = data.subarray(0, this.maxBytes - this.size);
21
- }
22
- if (data.length) {
23
- this.chunks.push(data);
24
- this.size += data.length;
25
- }
26
- }
27
-
28
- text(): string {
29
- const decoder = new TextDecoder();
30
- return this.chunks.map(chunk => decoder.decode(chunk, { stream: true })).join('') + decoder.decode();
31
- }
32
- }
33
-
34
- /** What a command printed, cut at `maxBytes`. */
35
- interface Output {
36
- exitCode: number | null;
37
- text: string;
38
- bytes: Uint8Array;
39
- }
40
-
41
- const MAX_LIST_BYTES = 16 * 1024 * 1024;
42
- const MAX_RUN_BYTES = 8 * 1024 * 1024;
43
- const DEFAULT_RUN_TIMEOUT_MS = 30000;
44
- const MAX_RUN_TIMEOUT_MS = 120000;
45
- const COMMAND_TIMEOUT_MS = 30000;
46
- const DEFAULT_FIND_LIMIT = 50;
47
- /** Directories that `find` skips when there is neither git nor ripgrep to read .gitignore. */
48
- const SKIPPED_DIRECTORIES = ['.git', 'node_modules'];
49
-
50
- /** Runs each method with the files and programs of the environment of `cwd`. */
51
- @Component(TaWorkspace)
52
- export class DefaultTaWorkspace implements TaWorkspace {
53
- @Autowired(ExecEnvironmentFactory)
54
- protected readonly environments: ExecEnvironmentFactory;
55
-
56
- /** Whether ripgrep is there; the same for all directories of one environment. */
57
- protected ripgrep?: Promise<boolean>;
58
-
59
- async listDirectory(cwd: string, path: string): Promise<TaDirEntry[]> {
60
- const env = this.environments.create(cwd);
61
- const target = WorkspaceUtil.inside(env.cwd, path);
62
- const stat = await env.stat(target.absolute);
63
- if (!stat?.isDirectory) {
64
- throw TaErrors.invalidArgument(`${path} is not a directory.`, 'Pass the path of a directory inside the workspace.');
65
- }
66
- const entries = (await env.readdir(target.absolute)).filter(entry => entry.name !== '.git');
67
- const listed = await Promise.all(
68
- entries.map(async (entry): Promise<TaDirEntry> => {
69
- const entryPath = WorkspaceUtil.join(target.relative, entry.name);
70
- if (entry.isDirectory) {
71
- return { name: entry.name, path: entryPath, kind: 'directory' };
72
- }
73
- // A link to a directory reads as a file here; stat follows it.
74
- const info = await env.stat(WorkspaceUtil.join(target.absolute, entry.name)).catch(() => undefined);
75
- return info?.isDirectory
76
- ? { name: entry.name, path: entryPath, kind: 'directory' }
77
- : { name: entry.name, path: entryPath, kind: 'file', size: info?.size };
78
- }),
79
- );
80
- return WorkspaceUtil.sortEntries(listed);
81
- }
82
-
83
- async readFile(cwd: string, path: string): Promise<TaFileContent> {
84
- const env = this.environments.create(cwd);
85
- const target = WorkspaceUtil.inside(env.cwd, path);
86
- const stat = await env.stat(target.absolute);
87
- if (!stat || stat.isDirectory) {
88
- throw TaErrors.invalidArgument(`${path} is not a file.`, 'Pass the path of a file inside the workspace.');
89
- }
90
- const truncated = stat.size > MAX_FILE_BYTES;
91
- // A large file: only its start crosses, not the whole of it.
92
- const bytes = truncated
93
- ? (await this.run(env, `head -c ${MAX_FILE_BYTES} -- ${WorkspaceUtil.quote(target.absolute)}`, MAX_FILE_BYTES)).bytes
94
- : await env.readFile(target.absolute);
95
- const content: TaFileContent = { path: target.relative, size: stat.size, binary: WorkspaceUtil.isBinary(bytes), truncated };
96
- if (!content.binary) {
97
- content.text = new TextDecoder().decode(bytes);
98
- }
99
- return content;
100
- }
101
-
102
- async writeFile(cwd: string, path: string, text: string): Promise<void> {
103
- const env = this.environments.create(cwd);
104
- const target = WorkspaceUtil.inside(env.cwd, path);
105
- const [stat, parent] = await Promise.all([env.stat(target.absolute), env.stat(dirname(target.absolute))]);
106
- if (stat?.isDirectory || !parent?.isDirectory) {
107
- throw TaErrors.invalidArgument(
108
- `${path} cannot be written: it is a directory, or its directory is missing.`,
109
- 'Pass the path of a file inside an existing directory of the workspace.',
110
- );
111
- }
112
- await env.writeFile(target.absolute, text);
113
- }
114
-
115
- async uploadFile(cwd: string, path: string, data: Uint8Array, append: boolean): Promise<void> {
116
- const env = this.environments.create(cwd);
117
- const target = WorkspaceUtil.inside(env.cwd, path);
118
- if (!target.relative || (await env.stat(target.absolute))?.isDirectory) {
119
- throw TaErrors.invalidArgument(`${path || '.'} is a directory.`, 'Pass the path of a file inside the workspace.');
120
- }
121
- if (!append) {
122
- await env.mkdir(dirname(target.absolute));
123
- }
124
- await env.writeFile(target.absolute, data, { append });
125
- }
126
-
127
- async findFiles(cwd: string, query: string, limit = DEFAULT_FIND_LIMIT): Promise<string[]> {
128
- const env = this.environments.create(cwd);
129
- return WorkspaceUtil.fuzzyFind(await this.listFiles(env), query, Math.max(1, limit));
130
- }
131
-
132
- /**
133
- * Without a shell: the program gets its arguments as they are. `/bin/sh` only closes the standard
134
- * input (or feeds it `input`) and then becomes the program, so that a timeout kills the program.
135
- */
136
- async runCommand(cwd: string, command: string, args: string[], options: TaRunCommandOptions = {}): Promise<TaCommandOutput> {
137
- if (!command) {
138
- throw TaErrors.invalidArgument('No program to run.', 'Pass the name or the path of a program, as git or rg.');
139
- }
140
- const env = this.environments.create(cwd);
141
- const timeout = WorkspaceUtil.clamp(options.timeoutMs, DEFAULT_RUN_TIMEOUT_MS, MAX_RUN_TIMEOUT_MS);
142
- const maxBytes = WorkspaceUtil.clamp(options.maxBytes, MAX_FILE_BYTES, MAX_RUN_BYTES);
143
- const posix = !(env.local && process.platform === 'win32');
144
- const input = options.input !== undefined;
145
- const child = posix
146
- ? env.spawn('/bin/sh', ['-c', input ? 'printf %s "$TA_RUN_INPUT" | exec "$0" "$@"' : 'exec "$0" "$@" </dev/null', command, ...args], {
147
- env: input ? { ...process.env, TA_RUN_INPUT: options.input } : undefined,
148
- })
149
- : env.spawn(command, args);
150
- const stdout = new OutputBuffer(maxBytes);
151
- const stderr = new OutputBuffer(maxBytes);
152
- child.onStdout(data => stdout.add(data));
153
- child.onStderr(data => stderr.add(data));
154
- if (options.input !== undefined && !posix) {
155
- child.write(options.input);
156
- }
157
- let timedOut = false;
158
- const exitCode = await new Promise<number | null>(done => {
159
- const timer = setTimeout(() => {
160
- timedOut = true;
161
- child.kill();
162
- }, timeout);
163
- child.onExit(code => {
164
- clearTimeout(timer);
165
- done(code);
166
- });
167
- });
168
- return {
169
- stdout: stdout.text(),
170
- stderr: stderr.text(),
171
- exitCode: timedOut ? null : exitCode,
172
- truncated: stdout.truncated || stderr.truncated,
173
- timedOut,
174
- };
175
- }
176
-
177
- /** The files of the directory: git's, ripgrep's, or all but SKIPPED_DIRECTORIES. */
178
- protected async listFiles(env: ExecEnvironment): Promise<string[]> {
179
- let command: string;
180
- if (await this.inRepository(env)) {
181
- command = 'git -c core.quotepath=off ls-files -co --exclude-standard';
182
- } else if (await this.hasRipgrep(env)) {
183
- command = 'rg --files --color never';
184
- } else {
185
- const skip = SKIPPED_DIRECTORIES.map(dir => `-name ${dir} -prune`).join(' -o ');
186
- command = `find . \\( ${skip} \\) -o -type f -print`;
187
- }
188
- const { text } = await this.run(env, command, MAX_LIST_BYTES);
189
- return text
190
- .split('\n')
191
- .map(line => line.replace(/^\.\//, ''))
192
- .filter(Boolean);
193
- }
194
-
195
- protected async inRepository(env: ExecEnvironment): Promise<boolean> {
196
- return (await this.run(env, 'git rev-parse --is-inside-work-tree', 4096)).text.trim() === 'true';
197
- }
198
-
199
- protected hasRipgrep(env: ExecEnvironment): Promise<boolean> {
200
- this.ripgrep ??= this.run(env, 'command -v rg', 4096).then(
201
- result => result.exitCode === 0,
202
- () => false,
203
- );
204
- return this.ripgrep;
205
- }
206
-
207
- /** Only what it prints on stdout; stops the command once it printed `maxBytes`: what came is enough. */
208
- protected async run(env: ExecEnvironment, command: string, maxBytes: number): Promise<Output> {
209
- const chunks: Uint8Array[] = [];
210
- let size = 0;
211
- const abort = new AbortController();
212
- const { exitCode } = await env.exec(`${command} 2>/dev/null`, {
213
- timeout: COMMAND_TIMEOUT_MS,
214
- signal: abort.signal,
215
- onData: data => {
216
- if (size >= maxBytes) {
217
- return;
218
- }
219
- const piece = data.subarray(0, maxBytes - size);
220
- chunks.push(piece);
221
- size += piece.length;
222
- if (size >= maxBytes) {
223
- abort.abort();
224
- }
225
- },
226
- });
227
- const bytes = new Uint8Array(size);
228
- let offset = 0;
229
- for (const chunk of chunks) {
230
- bytes.set(chunk, offset);
231
- offset += chunk.length;
232
- }
233
- return { exitCode, bytes, text: new TextDecoder().decode(bytes) };
234
- }
235
- }
@@ -1,47 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { WorkspaceUtil } from './workspace-util';
3
-
4
- describe('WorkspaceUtil', () => {
5
- it('keeps paths inside the directory', () => {
6
- expect(WorkspaceUtil.inside('/w', 'src/a.ts')).toEqual({ absolute: '/w/src/a.ts', relative: 'src/a.ts' });
7
- expect(WorkspaceUtil.inside('/w', '')).toEqual({ absolute: '/w', relative: '' });
8
- expect(WorkspaceUtil.inside('/w', 'a/../b')).toEqual({ absolute: '/w/b', relative: 'b' });
9
- expect(WorkspaceUtil.inside('/w', '..foo').relative).toBe('..foo');
10
- expect(() => WorkspaceUtil.inside('/w', '../x')).toThrow('outside');
11
- expect(() => WorkspaceUtil.inside('/w', '/etc/passwd')).toThrow('outside');
12
- expect(() => WorkspaceUtil.inside('/w', 'a/../../x')).toThrow('outside');
13
- });
14
-
15
- it('sorts directories first, then names as people do', () => {
16
- const sorted = WorkspaceUtil.sortEntries([
17
- { name: 'file10', path: 'file10', kind: 'file' },
18
- { name: 'src', path: 'src', kind: 'directory' },
19
- { name: 'File2', path: 'File2', kind: 'file' },
20
- { name: 'a', path: 'a', kind: 'directory' },
21
- ]);
22
- expect(sorted.map(entry => entry.name)).toEqual(['a', 'src', 'File2', 'file10']);
23
- });
24
-
25
- it('tells binary from text', () => {
26
- expect(WorkspaceUtil.isBinary(new TextEncoder().encode('hello'))).toBe(false);
27
- expect(WorkspaceUtil.isBinary(new Uint8Array([0x89, 0x50, 0x00, 0x47]))).toBe(true);
28
- });
29
-
30
- it('finds files loosely, the name before the directories', () => {
31
- const paths = ['src/browser/app-view.tsx', 'src/node/view.ts', 'docs/overview.md', 'README.md'];
32
- expect(WorkspaceUtil.fuzzyFind(paths, 'view', 10)).toEqual(['src/node/view.ts', 'src/browser/app-view.tsx', 'docs/overview.md']);
33
- expect(WorkspaceUtil.fuzzyFind(paths, 'apvw', 10)).toEqual(['src/browser/app-view.tsx']);
34
- expect(WorkspaceUtil.fuzzyFind(paths, 'zzz', 10)).toEqual([]);
35
- expect(WorkspaceUtil.fuzzyFind(paths, '', 2)).toHaveLength(2);
36
- });
37
-
38
- it('keeps limits within bounds', () => {
39
- expect(WorkspaceUtil.clamp(undefined, 30, 120)).toBe(30);
40
- expect(WorkspaceUtil.clamp(500, 30, 120)).toBe(120);
41
- expect(WorkspaceUtil.clamp(-1, 30, 120)).toBe(1);
42
- });
43
-
44
- it('quotes for the shell', () => {
45
- expect(WorkspaceUtil.quote("it's")).toBe("'it'\\''s'");
46
- });
47
- });
@@ -1,103 +0,0 @@
1
- import { isAbsolute, posix, relative, resolve, sep } from 'node:path';
2
- import type { TaDirEntry } from '@celljs/ta-protocol';
3
- import { TaErrors } from './ta-errors';
4
-
5
- /** The largest file readFile returns whole. */
6
- export const MAX_FILE_BYTES = 1024 * 1024;
7
- const BINARY_PROBE_BYTES = 8000;
8
-
9
- /** The pure parts of the workspace methods of ta serve: paths, sorting and matching names. */
10
- export namespace WorkspaceUtil {
11
- /** `path` inside `cwd`, absolute, and relative with `/`; throws when it leaves `cwd`. */
12
- export function inside(cwd: string, path: string): { absolute: string; relative: string } {
13
- const absolute = resolve(cwd, path || '.');
14
- const rel = relative(cwd, absolute);
15
- if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
16
- throw TaErrors.invalidArgument(`The path ${path} is outside of ${cwd}.`, 'Pass a path inside the directory of the workspace.');
17
- }
18
- return { absolute, relative: rel.split(sep).join('/') };
19
- }
20
-
21
- /** Joins a relative path of a directory with a name, with `/`. */
22
- export function join(dir: string, name: string): string {
23
- return dir && dir !== '.' ? posix.join(dir, name) : name;
24
- }
25
-
26
- /** Directories first, then by name as people sort (`file2` before `file10`). */
27
- export function sortEntries(entries: TaDirEntry[]): TaDirEntry[] {
28
- return [...entries].sort((a, b) => (a.kind === b.kind ? compareNames(a.name, b.name) : a.kind === 'directory' ? -1 : 1));
29
- }
30
-
31
- export function compareNames(a: string, b: string): number {
32
- return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }) || (a < b ? -1 : a > b ? 1 : 0);
33
- }
34
-
35
- /** A NUL in the first bytes: not text. */
36
- export function isBinary(bytes: Uint8Array): boolean {
37
- const end = Math.min(bytes.length, BINARY_PROBE_BYTES);
38
- for (let i = 0; i < end; i++) {
39
- if (bytes[i] === 0) {
40
- return true;
41
- }
42
- }
43
- return false;
44
- }
45
-
46
- /**
47
- * How well `path` matches `query` loosely: its characters in order, best when they start words of
48
- * the file name; undefined when it does not match. Higher is better.
49
- */
50
- export function fuzzyScore(path: string, query: string): number | undefined {
51
- const q = query.replace(/\s+/g, '').toLowerCase();
52
- if (!q) {
53
- return 0;
54
- }
55
- const lower = path.toLowerCase();
56
- const nameStart = lower.lastIndexOf('/') + 1;
57
- let score = 0;
58
- let from = 0;
59
- let previous = -2;
60
- for (const char of q) {
61
- const index = lower.indexOf(char, from);
62
- if (index < 0) {
63
- return undefined;
64
- }
65
- const boundary = index === 0 || '/._- '.includes(lower[index - 1]) || (path[index] !== lower[index] && path[index - 1] === lower[index - 1]);
66
- score += 1 + (index === previous + 1 ? 3 : 0) + (boundary ? 2 : 0) + (index >= nameStart ? 2 : 0);
67
- previous = index;
68
- from = index + 1;
69
- }
70
- const name = lower.slice(nameStart);
71
- if (name.startsWith(q)) {
72
- score += 10;
73
- } else if (name.includes(q)) {
74
- score += 5;
75
- }
76
- return score - path.length / 100;
77
- }
78
-
79
- /** The paths that match, best first. */
80
- export function fuzzyFind(paths: string[], query: string, limit: number): string[] {
81
- const scored: { path: string; score: number }[] = [];
82
- for (const path of paths) {
83
- const score = fuzzyScore(path, query);
84
- if (score !== undefined) {
85
- scored.push({ path, score });
86
- }
87
- }
88
- return scored
89
- .sort((a, b) => b.score - a.score || compareNames(a.path, b.path))
90
- .slice(0, limit)
91
- .map(({ path }) => path);
92
- }
93
-
94
- /** A limit a caller asked for, within what the server allows. */
95
- export function clamp(value: number | undefined, fallback: number, max: number): number {
96
- return value === undefined || !Number.isFinite(value) ? fallback : Math.min(max, Math.max(1, Math.floor(value)));
97
- }
98
-
99
- /** One argument for `/bin/sh`. */
100
- export function quote(value: string): string {
101
- return `'${value.replace(/'/g, `'\\''`)}'`;
102
- }
103
- }