@zyro-sec/gui-plugins 0.0.0-stage → 1.0.3

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 (1085) hide show
  1. package/AGENTS.md +116 -0
  2. package/README.md +874 -3
  3. package/bunfig.toml +3 -0
  4. package/happydom.ts +77 -0
  5. package/package.json +63 -4
  6. package/src/browser/activation-delay.ts +134 -0
  7. package/src/browser/address-machine.ts +468 -0
  8. package/src/browser/address.ts +111 -0
  9. package/src/browser/agent-rendering.ts +61 -0
  10. package/src/browser/analysis.ts +260 -0
  11. package/src/browser/artifact-link.ts +69 -0
  12. package/src/browser/artifact-links.ts +55 -0
  13. package/src/browser/artifact-preview.ts +61 -0
  14. package/src/browser/assets/viewport-device-chevron.svg +5 -0
  15. package/src/browser/assets/viewport-rotate.svg +7 -0
  16. package/src/browser/bar.css +562 -0
  17. package/src/browser/capture.ts +158 -0
  18. package/src/browser/cdp.ts +97 -0
  19. package/src/browser/child-targets.ts +30 -0
  20. package/src/browser/choices.tsx +42 -0
  21. package/src/browser/chromium.ts +3018 -0
  22. package/src/browser/comment.css +38 -0
  23. package/src/browser/comment.ts +98 -0
  24. package/src/browser/connection.ts +122 -0
  25. package/src/browser/default-browser.ts +59 -0
  26. package/src/browser/diagnostics-machine.ts +522 -0
  27. package/src/browser/diagnostics.ts +317 -0
  28. package/src/browser/dialog-machine.ts +268 -0
  29. package/src/browser/disk/contained-file.ts +43 -0
  30. package/src/browser/disk/handle-path.fixture.ts +99 -0
  31. package/src/browser/disk/handle-path.ts +122 -0
  32. package/src/browser/disk/index.ts +5 -0
  33. package/src/browser/disk/preview-scope.ts +90 -0
  34. package/src/browser/electron-address.fixture.ts +143 -0
  35. package/src/browser/electron-app-badge.fixture.ts +97 -0
  36. package/src/browser/electron-crash.fixture.ts +216 -0
  37. package/src/browser/electron-dialogs.fixture.ts +114 -0
  38. package/src/browser/electron-history.fixture.ts +61 -0
  39. package/src/browser/electron-icon.fixture.ts +145 -0
  40. package/src/browser/electron-import-choice.fixture.ts +58 -0
  41. package/src/browser/electron-links.fixture.ts +549 -0
  42. package/src/browser/electron-main.ts +85 -0
  43. package/src/browser/electron-media.fixture.ts +66 -0
  44. package/src/browser/electron-open.fixture.ts +351 -0
  45. package/src/browser/electron-page.fixture.ts +253 -0
  46. package/src/browser/electron-restore.fixture.ts +135 -0
  47. package/src/browser/electron-run.ts +184 -0
  48. package/src/browser/electron-sign-in-copy.fixture.ts +365 -0
  49. package/src/browser/electron-webauthn.fixture.ts +229 -0
  50. package/src/browser/electron-workers.fixture.ts +54 -0
  51. package/src/browser/errors.ts +175 -0
  52. package/src/browser/failure-view.tsx +92 -0
  53. package/src/browser/failure.ts +174 -0
  54. package/src/browser/field-value.ts +60 -0
  55. package/src/browser/file-choosers.ts +42 -0
  56. package/src/browser/file-verification.ts +18 -0
  57. package/src/browser/files.ts +134 -0
  58. package/src/browser/find-bar.tsx +80 -0
  59. package/src/browser/find-machine.ts +43 -0
  60. package/src/browser/history/earlier.ts +23 -0
  61. package/src/browser/history/index.ts +5 -0
  62. package/src/browser/history/ipc.ts +44 -0
  63. package/src/browser/history/match.ts +196 -0
  64. package/src/browser/history/page.ts +86 -0
  65. package/src/browser/history/search.ts +209 -0
  66. package/src/browser/history/store.ts +272 -0
  67. package/src/browser/history/suggest.ts +51 -0
  68. package/src/browser/history/visits.ts +59 -0
  69. package/src/browser/host-display.ts +32 -0
  70. package/src/browser/i18n/am.ts +42 -0
  71. package/src/browser/i18n/ar.ts +46 -0
  72. package/src/browser/i18n/az.ts +42 -0
  73. package/src/browser/i18n/bg.ts +42 -0
  74. package/src/browser/i18n/bn.ts +42 -0
  75. package/src/browser/i18n/br.ts +44 -0
  76. package/src/browser/i18n/bs.ts +43 -0
  77. package/src/browser/i18n/ca.ts +44 -0
  78. package/src/browser/i18n/cs.ts +44 -0
  79. package/src/browser/i18n/da.ts +42 -0
  80. package/src/browser/i18n/de.ts +43 -0
  81. package/src/browser/i18n/dv.ts +43 -0
  82. package/src/browser/i18n/dz.ts +42 -0
  83. package/src/browser/i18n/el.ts +44 -0
  84. package/src/browser/i18n/en.ts +455 -0
  85. package/src/browser/i18n/es.ts +44 -0
  86. package/src/browser/i18n/et.ts +42 -0
  87. package/src/browser/i18n/fa.ts +42 -0
  88. package/src/browser/i18n/fi.ts +42 -0
  89. package/src/browser/i18n/fo.ts +42 -0
  90. package/src/browser/i18n/fr.ts +45 -0
  91. package/src/browser/i18n/he.ts +43 -0
  92. package/src/browser/i18n/hi.ts +42 -0
  93. package/src/browser/i18n/hr.ts +43 -0
  94. package/src/browser/i18n/hu.ts +43 -0
  95. package/src/browser/i18n/hy.ts +42 -0
  96. package/src/browser/i18n/id.ts +42 -0
  97. package/src/browser/i18n/is.ts +42 -0
  98. package/src/browser/i18n/it.ts +44 -0
  99. package/src/browser/i18n/ja.ts +42 -0
  100. package/src/browser/i18n/ka.ts +42 -0
  101. package/src/browser/i18n/km.ts +42 -0
  102. package/src/browser/i18n/ko.ts +42 -0
  103. package/src/browser/i18n/lo.ts +42 -0
  104. package/src/browser/i18n/lt.ts +44 -0
  105. package/src/browser/i18n/lv.ts +43 -0
  106. package/src/browser/i18n/mk.ts +42 -0
  107. package/src/browser/i18n/mn.ts +42 -0
  108. package/src/browser/i18n/ms.ts +42 -0
  109. package/src/browser/i18n/my.ts +43 -0
  110. package/src/browser/i18n/ne.ts +42 -0
  111. package/src/browser/i18n/nl.ts +42 -0
  112. package/src/browser/i18n/no.ts +42 -0
  113. package/src/browser/i18n/pa.ts +42 -0
  114. package/src/browser/i18n/pl.ts +44 -0
  115. package/src/browser/i18n/ro.ts +43 -0
  116. package/src/browser/i18n/ru.ts +44 -0
  117. package/src/browser/i18n/si.ts +42 -0
  118. package/src/browser/i18n/sk.ts +44 -0
  119. package/src/browser/i18n/sl.ts +44 -0
  120. package/src/browser/i18n/sq.ts +43 -0
  121. package/src/browser/i18n/sr.ts +43 -0
  122. package/src/browser/i18n/sv.ts +42 -0
  123. package/src/browser/i18n/tg.ts +42 -0
  124. package/src/browser/i18n/th.ts +42 -0
  125. package/src/browser/i18n/tk.ts +42 -0
  126. package/src/browser/i18n/tr.ts +42 -0
  127. package/src/browser/i18n/uk.ts +44 -0
  128. package/src/browser/i18n/ur.ts +42 -0
  129. package/src/browser/i18n/uz.ts +42 -0
  130. package/src/browser/i18n/vi.ts +42 -0
  131. package/src/browser/i18n/zh.ts +42 -0
  132. package/src/browser/i18n/zht.ts +42 -0
  133. package/src/browser/icon-image.ts +110 -0
  134. package/src/browser/icon-samples.ts +110 -0
  135. package/src/browser/icon.ts +72 -0
  136. package/src/browser/import-prompt.tsx +265 -0
  137. package/src/browser/index.ts +97 -0
  138. package/src/browser/ipc.ts +304 -0
  139. package/src/browser/jobs-machine.ts +181 -0
  140. package/src/browser/jobs.ts +373 -0
  141. package/src/browser/keys.ts +109 -0
  142. package/src/browser/lighthouse.ts +103 -0
  143. package/src/browser/link.ts +19 -0
  144. package/src/browser/machine.ts +1522 -0
  145. package/src/browser/main-machine.ts +99 -0
  146. package/src/browser/main.ts +394 -0
  147. package/src/browser/media-gate.ts +131 -0
  148. package/src/browser/mobile-emulation.ts +121 -0
  149. package/src/browser/model-machine.ts +93 -0
  150. package/src/browser/model.ts +1173 -0
  151. package/src/browser/native-page-menu.ts +189 -0
  152. package/src/browser/navigation-deadline.ts +20 -0
  153. package/src/browser/navigation-turn.ts +118 -0
  154. package/src/browser/network.ts +140 -0
  155. package/src/browser/notice-actions.ts +52 -0
  156. package/src/browser/overlay-machine.ts +330 -0
  157. package/src/browser/page-find.ts +71 -0
  158. package/src/browser/page-icon.tsx +27 -0
  159. package/src/browser/page-log.ts +276 -0
  160. package/src/browser/page-machine.ts +329 -0
  161. package/src/browser/page-menu.ts +158 -0
  162. package/src/browser/page-prompts.ts +753 -0
  163. package/src/browser/pane-machine.ts +664 -0
  164. package/src/browser/pane.ts +1335 -0
  165. package/src/browser/panel.fixture.tsx +2046 -0
  166. package/src/browser/panel.stories.tsx +147 -0
  167. package/src/browser/panel.tsx +2029 -0
  168. package/src/browser/passkey-groups.ts +34 -0
  169. package/src/browser/picker-machine.ts +214 -0
  170. package/src/browser/plugin-tabs.ts +26 -0
  171. package/src/browser/policy.ts +439 -0
  172. package/src/browser/preview.ts +40 -0
  173. package/src/browser/profile/chromium.ts +198 -0
  174. package/src/browser/profile/compatibility.ts +177 -0
  175. package/src/browser/profile/cookie.ts +215 -0
  176. package/src/browser/profile/database.ts +116 -0
  177. package/src/browser/profile/electron-import.fixture.ts +43 -0
  178. package/src/browser/profile/electron-link.fixture.ts +137 -0
  179. package/src/browser/profile/extension-api/action.ts +276 -0
  180. package/src/browser/profile/extension-api/api.ts +112 -0
  181. package/src/browser/profile/extension-api/app-badge.js +19 -0
  182. package/src/browser/profile/extension-api/context-menus.ts +327 -0
  183. package/src/browser/profile/extension-api/cookies.ts +192 -0
  184. package/src/browser/profile/extension-api/event-page.ts +73 -0
  185. package/src/browser/profile/extension-api/frame-styles.js +46 -0
  186. package/src/browser/profile/extension-api/host.ts +291 -0
  187. package/src/browser/profile/extension-api/index.ts +119 -0
  188. package/src/browser/profile/extension-api/label.ts +4 -0
  189. package/src/browser/profile/extension-api/manifest.ts +76 -0
  190. package/src/browser/profile/extension-api/match-pattern.ts +98 -0
  191. package/src/browser/profile/extension-api/notifications.ts +100 -0
  192. package/src/browser/profile/extension-api/permissions.ts +51 -0
  193. package/src/browser/profile/extension-api/popup.ts +200 -0
  194. package/src/browser/profile/extension-api/preload.js +203 -0
  195. package/src/browser/profile/extension-api/resource.ts +36 -0
  196. package/src/browser/profile/extension-api/storage-sync.ts +167 -0
  197. package/src/browser/profile/extension-api/stubs.ts +152 -0
  198. package/src/browser/profile/extension-api/styles.ts +230 -0
  199. package/src/browser/profile/extension-api/tab-activity.ts +23 -0
  200. package/src/browser/profile/extension-api/tabs.ts +545 -0
  201. package/src/browser/profile/extension-api/web-navigation.ts +172 -0
  202. package/src/browser/profile/extension-api/worker-events.ts +114 -0
  203. package/src/browser/profile/extensions.ts +491 -0
  204. package/src/browser/profile/filter-startup.fixture.ts +111 -0
  205. package/src/browser/profile/filter-startup.ts +178 -0
  206. package/src/browser/profile/firefox.ts +119 -0
  207. package/src/browser/profile/history.ts +146 -0
  208. package/src/browser/profile/import.ts +37 -0
  209. package/src/browser/profile/index.ts +694 -0
  210. package/src/browser/profile/install.ts +131 -0
  211. package/src/browser/profile/integrity.ts +56 -0
  212. package/src/browser/profile/ipc.ts +306 -0
  213. package/src/browser/profile/link-machine.ts +183 -0
  214. package/src/browser/profile/link.ts +335 -0
  215. package/src/browser/profile/made-up-firefox.fixture.ts +67 -0
  216. package/src/browser/profile/previews.ts +70 -0
  217. package/src/browser/profile/probe.ts +43 -0
  218. package/src/browser/profile/range.ts +14 -0
  219. package/src/browser/profile/review.ts +38 -0
  220. package/src/browser/profile/safari.ts +77 -0
  221. package/src/browser/profile/serve.ts +117 -0
  222. package/src/browser/profile/sites.ts +74 -0
  223. package/src/browser/profile/sources.ts +682 -0
  224. package/src/browser/profiling-machine.ts +554 -0
  225. package/src/browser/profiling.ts +404 -0
  226. package/src/browser/prompt-gate.ts +41 -0
  227. package/src/browser/prompt-keys.ts +120 -0
  228. package/src/browser/prompt-machine.ts +242 -0
  229. package/src/browser/prompts.tsx +594 -0
  230. package/src/browser/refs.ts +65 -0
  231. package/src/browser/refusal-bar.tsx +163 -0
  232. package/src/browser/refusal-notice.ts +60 -0
  233. package/src/browser/remote-address.ts +1 -0
  234. package/src/browser/remote-preview.ts +56 -0
  235. package/src/browser/renderer.tsx +683 -0
  236. package/src/browser/restore.ts +77 -0
  237. package/src/browser/saved-tabs.ts +135 -0
  238. package/src/browser/scheme.ts +1 -0
  239. package/src/browser/session-guard.ts +94 -0
  240. package/src/browser/settings-view.ts +49 -0
  241. package/src/browser/settings.fixture.tsx +306 -0
  242. package/src/browser/settings.tsx +1036 -0
  243. package/src/browser/site-auth.ts +58 -0
  244. package/src/browser/site-chooser.fixture.tsx +222 -0
  245. package/src/browser/site-chooser.tsx +778 -0
  246. package/src/browser/site-keys.ts +35 -0
  247. package/src/browser/site-machine.ts +134 -0
  248. package/src/browser/site-permissions.ts +239 -0
  249. package/src/browser/site-search.ts +26 -0
  250. package/src/browser/snapshot.ts +440 -0
  251. package/src/browser/system-media.ts +80 -0
  252. package/src/browser/tab-openers.ts +65 -0
  253. package/src/browser/tabs.css +20 -0
  254. package/src/browser/viewport-controls-machine.ts +134 -0
  255. package/src/browser/viewport-controls.tsx +170 -0
  256. package/src/browser/viewport-handles.tsx +119 -0
  257. package/src/browser/viewport-layout.ts +24 -0
  258. package/src/browser/viewport-native.ts +99 -0
  259. package/src/browser/viewport-preset-menu.tsx +69 -0
  260. package/src/browser/viewport-presets.ts +28 -0
  261. package/src/browser/viewport-toolbar-machine.ts +94 -0
  262. package/src/browser/webauthn-gate.ts +222 -0
  263. package/src/browser/window-open.ts +143 -0
  264. package/src/browser/wire.ts +20 -0
  265. package/src/browser/workspace-file.ts +126 -0
  266. package/src/browser/workspace-pages.ts +156 -0
  267. package/src/btw/i18n/en.ts +12 -0
  268. package/src/btw/index.ts +31 -0
  269. package/src/btw/machine.ts +341 -0
  270. package/src/btw/model.ts +222 -0
  271. package/src/btw/panel.tsx +229 -0
  272. package/src/btw/renderer.tsx +125 -0
  273. package/src/context/catalog-machine.ts +153 -0
  274. package/src/context/catalog.ts +123 -0
  275. package/src/context/export.ts +57 -0
  276. package/src/context/format.ts +32 -0
  277. package/src/context/i18n/am.ts +31 -0
  278. package/src/context/i18n/ar.ts +31 -0
  279. package/src/context/i18n/az.ts +31 -0
  280. package/src/context/i18n/bg.ts +31 -0
  281. package/src/context/i18n/bn.ts +31 -0
  282. package/src/context/i18n/br.ts +31 -0
  283. package/src/context/i18n/bs.ts +31 -0
  284. package/src/context/i18n/ca.ts +31 -0
  285. package/src/context/i18n/cs.ts +31 -0
  286. package/src/context/i18n/da.ts +31 -0
  287. package/src/context/i18n/de.ts +31 -0
  288. package/src/context/i18n/dv.ts +31 -0
  289. package/src/context/i18n/dz.ts +31 -0
  290. package/src/context/i18n/el.ts +31 -0
  291. package/src/context/i18n/en.ts +31 -0
  292. package/src/context/i18n/es.ts +31 -0
  293. package/src/context/i18n/et.ts +31 -0
  294. package/src/context/i18n/fa.ts +31 -0
  295. package/src/context/i18n/fi.ts +31 -0
  296. package/src/context/i18n/fo.ts +31 -0
  297. package/src/context/i18n/fr.ts +31 -0
  298. package/src/context/i18n/he.ts +31 -0
  299. package/src/context/i18n/hi.ts +31 -0
  300. package/src/context/i18n/hr.ts +31 -0
  301. package/src/context/i18n/hu.ts +31 -0
  302. package/src/context/i18n/hy.ts +31 -0
  303. package/src/context/i18n/id.ts +31 -0
  304. package/src/context/i18n/is.ts +31 -0
  305. package/src/context/i18n/it.ts +31 -0
  306. package/src/context/i18n/ja.ts +31 -0
  307. package/src/context/i18n/ka.ts +31 -0
  308. package/src/context/i18n/km.ts +31 -0
  309. package/src/context/i18n/ko.ts +31 -0
  310. package/src/context/i18n/lo.ts +31 -0
  311. package/src/context/i18n/lt.ts +31 -0
  312. package/src/context/i18n/lv.ts +31 -0
  313. package/src/context/i18n/mk.ts +31 -0
  314. package/src/context/i18n/mn.ts +31 -0
  315. package/src/context/i18n/ms.ts +31 -0
  316. package/src/context/i18n/my.ts +31 -0
  317. package/src/context/i18n/ne.ts +31 -0
  318. package/src/context/i18n/nl.ts +31 -0
  319. package/src/context/i18n/no.ts +31 -0
  320. package/src/context/i18n/pa.ts +31 -0
  321. package/src/context/i18n/pl.ts +31 -0
  322. package/src/context/i18n/ro.ts +31 -0
  323. package/src/context/i18n/ru.ts +31 -0
  324. package/src/context/i18n/si.ts +31 -0
  325. package/src/context/i18n/sk.ts +31 -0
  326. package/src/context/i18n/sl.ts +31 -0
  327. package/src/context/i18n/sq.ts +31 -0
  328. package/src/context/i18n/sr.ts +31 -0
  329. package/src/context/i18n/sv.ts +31 -0
  330. package/src/context/i18n/tg.ts +31 -0
  331. package/src/context/i18n/th.ts +31 -0
  332. package/src/context/i18n/tk.ts +31 -0
  333. package/src/context/i18n/tr.ts +31 -0
  334. package/src/context/i18n/uk.ts +31 -0
  335. package/src/context/i18n/ur.ts +31 -0
  336. package/src/context/i18n/uz.ts +31 -0
  337. package/src/context/i18n/vi.ts +31 -0
  338. package/src/context/i18n/zh.ts +31 -0
  339. package/src/context/i18n/zht.ts +31 -0
  340. package/src/context/index.ts +71 -0
  341. package/src/context/indicator.tsx +199 -0
  342. package/src/context/machine.ts +271 -0
  343. package/src/context/renderer.tsx +72 -0
  344. package/src/context/tab.tsx +439 -0
  345. package/src/debug/bar.tsx +409 -0
  346. package/src/debug/contract.ts +45 -0
  347. package/src/debug/focus-machine.ts +84 -0
  348. package/src/debug/heap-machine.ts +229 -0
  349. package/src/debug/i18n/am.ts +50 -0
  350. package/src/debug/i18n/ar.ts +50 -0
  351. package/src/debug/i18n/az.ts +50 -0
  352. package/src/debug/i18n/bg.ts +53 -0
  353. package/src/debug/i18n/bn.ts +50 -0
  354. package/src/debug/i18n/br.ts +51 -0
  355. package/src/debug/i18n/bs.ts +52 -0
  356. package/src/debug/i18n/ca.ts +53 -0
  357. package/src/debug/i18n/cs.ts +52 -0
  358. package/src/debug/i18n/da.ts +51 -0
  359. package/src/debug/i18n/de.ts +50 -0
  360. package/src/debug/i18n/dv.ts +51 -0
  361. package/src/debug/i18n/dz.ts +52 -0
  362. package/src/debug/i18n/el.ts +54 -0
  363. package/src/debug/i18n/en.ts +50 -0
  364. package/src/debug/i18n/es.ts +52 -0
  365. package/src/debug/i18n/et.ts +50 -0
  366. package/src/debug/i18n/fa.ts +50 -0
  367. package/src/debug/i18n/fi.ts +50 -0
  368. package/src/debug/i18n/fo.ts +50 -0
  369. package/src/debug/i18n/fr.ts +52 -0
  370. package/src/debug/i18n/he.ts +50 -0
  371. package/src/debug/i18n/hi.ts +50 -0
  372. package/src/debug/i18n/hr.ts +52 -0
  373. package/src/debug/i18n/hu.ts +52 -0
  374. package/src/debug/i18n/hy.ts +52 -0
  375. package/src/debug/i18n/id.ts +51 -0
  376. package/src/debug/i18n/is.ts +50 -0
  377. package/src/debug/i18n/it.ts +52 -0
  378. package/src/debug/i18n/ja.ts +50 -0
  379. package/src/debug/i18n/ka.ts +50 -0
  380. package/src/debug/i18n/km.ts +50 -0
  381. package/src/debug/i18n/ko.ts +50 -0
  382. package/src/debug/i18n/lo.ts +50 -0
  383. package/src/debug/i18n/lt.ts +51 -0
  384. package/src/debug/i18n/lv.ts +50 -0
  385. package/src/debug/i18n/mk.ts +53 -0
  386. package/src/debug/i18n/mn.ts +52 -0
  387. package/src/debug/i18n/ms.ts +51 -0
  388. package/src/debug/i18n/my.ts +53 -0
  389. package/src/debug/i18n/ne.ts +50 -0
  390. package/src/debug/i18n/nl.ts +50 -0
  391. package/src/debug/i18n/no.ts +50 -0
  392. package/src/debug/i18n/pa.ts +50 -0
  393. package/src/debug/i18n/pl.ts +51 -0
  394. package/src/debug/i18n/ro.ts +52 -0
  395. package/src/debug/i18n/ru.ts +51 -0
  396. package/src/debug/i18n/si.ts +50 -0
  397. package/src/debug/i18n/sk.ts +52 -0
  398. package/src/debug/i18n/sl.ts +50 -0
  399. package/src/debug/i18n/sq.ts +52 -0
  400. package/src/debug/i18n/sr.ts +52 -0
  401. package/src/debug/i18n/sv.ts +51 -0
  402. package/src/debug/i18n/tg.ts +51 -0
  403. package/src/debug/i18n/th.ts +50 -0
  404. package/src/debug/i18n/tk.ts +51 -0
  405. package/src/debug/i18n/tr.ts +50 -0
  406. package/src/debug/i18n/uk.ts +50 -0
  407. package/src/debug/i18n/ur.ts +50 -0
  408. package/src/debug/i18n/uz.ts +51 -0
  409. package/src/debug/i18n/vi.ts +51 -0
  410. package/src/debug/i18n/zh.ts +49 -0
  411. package/src/debug/i18n/zht.ts +50 -0
  412. package/src/debug/index.ts +79 -0
  413. package/src/debug/main.ts +417 -0
  414. package/src/debug/memory-infra.ts +159 -0
  415. package/src/debug/memory-log.ts +65 -0
  416. package/src/debug/memory-machine.ts +151 -0
  417. package/src/debug/memory-record.ts +36 -0
  418. package/src/debug/motion-machine.ts +229 -0
  419. package/src/debug/motion.tsx +697 -0
  420. package/src/debug/options.ts +15 -0
  421. package/src/debug/renderer.tsx +185 -0
  422. package/src/debug/server-heap.ts +63 -0
  423. package/src/debug/signal.ts +13 -0
  424. package/src/details/config-action-machine.ts +107 -0
  425. package/src/details/config-file.ts +43 -0
  426. package/src/details/details.css +555 -0
  427. package/src/details/flyout-machine.ts +252 -0
  428. package/src/details/flyout-motion.ts +26 -0
  429. package/src/details/i18n/am.ts +68 -0
  430. package/src/details/i18n/ar.ts +71 -0
  431. package/src/details/i18n/az.ts +71 -0
  432. package/src/details/i18n/bg.ts +73 -0
  433. package/src/details/i18n/bn.ts +71 -0
  434. package/src/details/i18n/br.ts +71 -0
  435. package/src/details/i18n/bs.ts +72 -0
  436. package/src/details/i18n/ca.ts +72 -0
  437. package/src/details/i18n/cs.ts +71 -0
  438. package/src/details/i18n/da.ts +71 -0
  439. package/src/details/i18n/de.ts +73 -0
  440. package/src/details/i18n/dv.ts +73 -0
  441. package/src/details/i18n/dz.ts +72 -0
  442. package/src/details/i18n/el.ts +73 -0
  443. package/src/details/i18n/en.ts +71 -0
  444. package/src/details/i18n/es.ts +72 -0
  445. package/src/details/i18n/et.ts +72 -0
  446. package/src/details/i18n/fa.ts +71 -0
  447. package/src/details/i18n/fi.ts +71 -0
  448. package/src/details/i18n/fo.ts +72 -0
  449. package/src/details/i18n/fr.ts +73 -0
  450. package/src/details/i18n/he.ts +71 -0
  451. package/src/details/i18n/hi.ts +71 -0
  452. package/src/details/i18n/hr.ts +72 -0
  453. package/src/details/i18n/hu.ts +72 -0
  454. package/src/details/i18n/hy.ts +72 -0
  455. package/src/details/i18n/id.ts +71 -0
  456. package/src/details/i18n/is.ts +71 -0
  457. package/src/details/i18n/it.ts +73 -0
  458. package/src/details/i18n/ja.ts +71 -0
  459. package/src/details/i18n/ka.ts +72 -0
  460. package/src/details/i18n/km.ts +72 -0
  461. package/src/details/i18n/ko.ts +71 -0
  462. package/src/details/i18n/lo.ts +72 -0
  463. package/src/details/i18n/lt.ts +72 -0
  464. package/src/details/i18n/lv.ts +72 -0
  465. package/src/details/i18n/mk.ts +73 -0
  466. package/src/details/i18n/mn.ts +71 -0
  467. package/src/details/i18n/ms.ts +71 -0
  468. package/src/details/i18n/my.ts +72 -0
  469. package/src/details/i18n/ne.ts +71 -0
  470. package/src/details/i18n/nl.ts +71 -0
  471. package/src/details/i18n/no.ts +71 -0
  472. package/src/details/i18n/pa.ts +71 -0
  473. package/src/details/i18n/pl.ts +72 -0
  474. package/src/details/i18n/ro.ts +72 -0
  475. package/src/details/i18n/ru.ts +72 -0
  476. package/src/details/i18n/si.ts +71 -0
  477. package/src/details/i18n/sk.ts +71 -0
  478. package/src/details/i18n/sl.ts +73 -0
  479. package/src/details/i18n/sq.ts +71 -0
  480. package/src/details/i18n/sr.ts +72 -0
  481. package/src/details/i18n/sv.ts +72 -0
  482. package/src/details/i18n/tg.ts +71 -0
  483. package/src/details/i18n/th.ts +72 -0
  484. package/src/details/i18n/tk.ts +72 -0
  485. package/src/details/i18n/tr.ts +71 -0
  486. package/src/details/i18n/uk.ts +71 -0
  487. package/src/details/i18n/ur.ts +71 -0
  488. package/src/details/i18n/uz.ts +72 -0
  489. package/src/details/i18n/vi.ts +71 -0
  490. package/src/details/i18n/zh.ts +69 -0
  491. package/src/details/i18n/zht.ts +70 -0
  492. package/src/details/index.ts +71 -0
  493. package/src/details/location-menu.tsx +82 -0
  494. package/src/details/location-workspace.tsx +39 -0
  495. package/src/details/mcp-machine.ts +278 -0
  496. package/src/details/panel.tsx +27 -0
  497. package/src/details/paths.ts +17 -0
  498. package/src/details/popover-machine.ts +97 -0
  499. package/src/details/popover.tsx +179 -0
  500. package/src/details/renderer.tsx +99 -0
  501. package/src/details/server-panel.tsx +1632 -0
  502. package/src/details/service-load-machine.ts +246 -0
  503. package/src/details/workspace-menu.tsx +490 -0
  504. package/src/details/workspace-move-machine.ts +643 -0
  505. package/src/file/apps.ts +25 -0
  506. package/src/file/arrival-guard-machine.ts +59 -0
  507. package/src/file/artifact-toolbar.tsx +161 -0
  508. package/src/file/artifact-view-machine.ts +396 -0
  509. package/src/file/artifact-view.css +336 -0
  510. package/src/file/artifact-view.tsx +1031 -0
  511. package/src/file/artifact.ts +225 -0
  512. package/src/file/browser.stories.tsx +57 -0
  513. package/src/file/browser.tsx +502 -0
  514. package/src/file/context.ts +67 -0
  515. package/src/file/contract.ts +10 -0
  516. package/src/file/drag.ts +35 -0
  517. package/src/file/find.tsx +376 -0
  518. package/src/file/i18n/am.ts +56 -0
  519. package/src/file/i18n/ar.ts +64 -0
  520. package/src/file/i18n/az.ts +56 -0
  521. package/src/file/i18n/bg.ts +56 -0
  522. package/src/file/i18n/bn.ts +56 -0
  523. package/src/file/i18n/br.ts +58 -0
  524. package/src/file/i18n/bs.ts +58 -0
  525. package/src/file/i18n/ca.ts +58 -0
  526. package/src/file/i18n/cs.ts +60 -0
  527. package/src/file/i18n/da.ts +56 -0
  528. package/src/file/i18n/de.ts +56 -0
  529. package/src/file/i18n/dv.ts +56 -0
  530. package/src/file/i18n/dz.ts +56 -0
  531. package/src/file/i18n/el.ts +56 -0
  532. package/src/file/i18n/en.ts +63 -0
  533. package/src/file/i18n/es.ts +58 -0
  534. package/src/file/i18n/et.ts +56 -0
  535. package/src/file/i18n/fa.ts +56 -0
  536. package/src/file/i18n/fi.ts +56 -0
  537. package/src/file/i18n/fo.ts +56 -0
  538. package/src/file/i18n/fr.ts +58 -0
  539. package/src/file/i18n/he.ts +58 -0
  540. package/src/file/i18n/hi.ts +56 -0
  541. package/src/file/i18n/hr.ts +58 -0
  542. package/src/file/i18n/hu.ts +56 -0
  543. package/src/file/i18n/hy.ts +56 -0
  544. package/src/file/i18n/id.ts +56 -0
  545. package/src/file/i18n/is.ts +56 -0
  546. package/src/file/i18n/it.ts +58 -0
  547. package/src/file/i18n/ja.ts +56 -0
  548. package/src/file/i18n/ka.ts +56 -0
  549. package/src/file/i18n/km.ts +56 -0
  550. package/src/file/i18n/ko.ts +56 -0
  551. package/src/file/i18n/lo.ts +56 -0
  552. package/src/file/i18n/lt.ts +60 -0
  553. package/src/file/i18n/lv.ts +58 -0
  554. package/src/file/i18n/mk.ts +56 -0
  555. package/src/file/i18n/mn.ts +56 -0
  556. package/src/file/i18n/ms.ts +56 -0
  557. package/src/file/i18n/my.ts +56 -0
  558. package/src/file/i18n/ne.ts +56 -0
  559. package/src/file/i18n/nl.ts +56 -0
  560. package/src/file/i18n/no.ts +56 -0
  561. package/src/file/i18n/pa.ts +56 -0
  562. package/src/file/i18n/pl.ts +60 -0
  563. package/src/file/i18n/ro.ts +58 -0
  564. package/src/file/i18n/ru.ts +60 -0
  565. package/src/file/i18n/si.ts +56 -0
  566. package/src/file/i18n/sk.ts +60 -0
  567. package/src/file/i18n/sl.ts +60 -0
  568. package/src/file/i18n/sq.ts +56 -0
  569. package/src/file/i18n/sr.ts +58 -0
  570. package/src/file/i18n/sv.ts +56 -0
  571. package/src/file/i18n/tg.ts +56 -0
  572. package/src/file/i18n/th.ts +56 -0
  573. package/src/file/i18n/tk.ts +56 -0
  574. package/src/file/i18n/tr.ts +56 -0
  575. package/src/file/i18n/uk.ts +60 -0
  576. package/src/file/i18n/ur.ts +57 -0
  577. package/src/file/i18n/uz.ts +56 -0
  578. package/src/file/i18n/vi.ts +56 -0
  579. package/src/file/i18n/zh.ts +56 -0
  580. package/src/file/i18n/zht.ts +56 -0
  581. package/src/file/index.ts +76 -0
  582. package/src/file/label.tsx +22 -0
  583. package/src/file/link-exists-machine.ts +137 -0
  584. package/src/file/link-open-machine.ts +249 -0
  585. package/src/file/list.tsx +224 -0
  586. package/src/file/mobile.css +35 -0
  587. package/src/file/mobile.tsx +116 -0
  588. package/src/file/open-in-app-machine.ts +185 -0
  589. package/src/file/open-in-app.tsx +395 -0
  590. package/src/file/path.ts +43 -0
  591. package/src/file/picker-machine.ts +190 -0
  592. package/src/file/pierre-tree-machine.ts +679 -0
  593. package/src/file/pierre-tree.tsx +503 -0
  594. package/src/file/renderer.tsx +1030 -0
  595. package/src/file/resolve-link.ts +152 -0
  596. package/src/file/scroll-machine.ts +272 -0
  597. package/src/file/search-machine.ts +202 -0
  598. package/src/file/styles.ts +5 -0
  599. package/src/file/tabs.css +15 -0
  600. package/src/file/tree-focus.css +6 -0
  601. package/src/file/tree-model.ts +239 -0
  602. package/src/file/view.tsx +572 -0
  603. package/src/goal/goal.css +43 -0
  604. package/src/goal/i18n/en.ts +12 -0
  605. package/src/goal/icons/active.svg +13 -0
  606. package/src/goal/icons/complete.svg +4 -0
  607. package/src/goal/icons/paused.svg +4 -0
  608. package/src/goal/index.ts +9 -0
  609. package/src/goal/machine.ts +364 -0
  610. package/src/goal/renderer.tsx +287 -0
  611. package/src/icon-name.typecheck.ts +9 -0
  612. package/src/main.ts +35 -0
  613. package/src/microsoft-office/document.tsx +436 -0
  614. package/src/microsoft-office/document.worker.ts +360 -0
  615. package/src/microsoft-office/fonts-cjk.ts +3 -0
  616. package/src/microsoft-office/fonts.ts +75 -0
  617. package/src/microsoft-office/i18n/en.ts +22 -0
  618. package/src/microsoft-office/index.ts +7 -0
  619. package/src/microsoft-office/links.ts +22 -0
  620. package/src/microsoft-office/office-worker.ts +124 -0
  621. package/src/microsoft-office/pages-machine.ts +356 -0
  622. package/src/microsoft-office/pages.tsx +387 -0
  623. package/src/microsoft-office/paper.ts +2 -0
  624. package/src/microsoft-office/presentation.tsx +303 -0
  625. package/src/microsoft-office/presentation.worker.ts +373 -0
  626. package/src/microsoft-office/renderer.tsx +57 -0
  627. package/src/microsoft-office/sheet-activate.ts +35 -0
  628. package/src/microsoft-office/sheet-cells.ts +188 -0
  629. package/src/microsoft-office/sheet-frame-machine.ts +286 -0
  630. package/src/microsoft-office/sheet-frame.ts +158 -0
  631. package/src/microsoft-office/sheet-paint.ts +357 -0
  632. package/src/microsoft-office/sheet-pick-machine.ts +138 -0
  633. package/src/microsoft-office/sheet-pointer-machine.ts +169 -0
  634. package/src/microsoft-office/sheet-protocol.ts +88 -0
  635. package/src/microsoft-office/slide-fonts-machine.ts +290 -0
  636. package/src/microsoft-office/slide-fonts.ts +157 -0
  637. package/src/microsoft-office/slide-paint-machine.ts +322 -0
  638. package/src/microsoft-office/slide-protocol.ts +50 -0
  639. package/src/microsoft-office/slide-text.ts +334 -0
  640. package/src/microsoft-office/spreadsheet.tsx +1165 -0
  641. package/src/microsoft-office/spreadsheet.worker.ts +259 -0
  642. package/src/microsoft-office/word-images.ts +105 -0
  643. package/src/microsoft-office/word-layout-machine.ts +219 -0
  644. package/src/microsoft-office/word-paint-machine.ts +174 -0
  645. package/src/microsoft-office/word-protocol.ts +78 -0
  646. package/src/microsoft-office/word-text.ts +260 -0
  647. package/src/microsoft-office/worker-machine.ts +111 -0
  648. package/src/microsoft-office/worker-rpc-machine.ts +336 -0
  649. package/src/microsoft-office/worker-rpc.fixture.ts +90 -0
  650. package/src/microsoft-office/worker-rpc.ts +292 -0
  651. package/src/pairing/contract.ts +24 -0
  652. package/src/pairing/copy-machine.ts +107 -0
  653. package/src/pairing/dialog.stories.tsx +69 -0
  654. package/src/pairing/dispatch.ts +42 -0
  655. package/src/pairing/i18n/en.ts +28 -0
  656. package/src/pairing/icons/pair.svg +4 -0
  657. package/src/pairing/index.ts +5 -0
  658. package/src/pairing/machine.ts +869 -0
  659. package/src/pairing/main-machine.ts +239 -0
  660. package/src/pairing/main.ts +130 -0
  661. package/src/pairing/page.stories.tsx +108 -0
  662. package/src/pairing/page.tsx +486 -0
  663. package/src/pairing/remote.ts +7 -0
  664. package/src/pairing/renderer.tsx +66 -0
  665. package/src/renderer.ts +55 -0
  666. package/src/review/contract.ts +31 -0
  667. package/src/review/detail-machine.ts +250 -0
  668. package/src/review/folder-machine.ts +404 -0
  669. package/src/review/i18n/am.ts +23 -0
  670. package/src/review/i18n/ar.ts +35 -0
  671. package/src/review/i18n/az.ts +23 -0
  672. package/src/review/i18n/bg.ts +23 -0
  673. package/src/review/i18n/bn.ts +23 -0
  674. package/src/review/i18n/br.ts +27 -0
  675. package/src/review/i18n/bs.ts +26 -0
  676. package/src/review/i18n/ca.ts +27 -0
  677. package/src/review/i18n/cs.ts +29 -0
  678. package/src/review/i18n/da.ts +23 -0
  679. package/src/review/i18n/de.ts +23 -0
  680. package/src/review/i18n/dv.ts +24 -0
  681. package/src/review/i18n/dz.ts +24 -0
  682. package/src/review/i18n/el.ts +23 -0
  683. package/src/review/i18n/en.ts +28 -0
  684. package/src/review/i18n/es.ts +27 -0
  685. package/src/review/i18n/et.ts +23 -0
  686. package/src/review/i18n/fa.ts +23 -0
  687. package/src/review/i18n/fi.ts +23 -0
  688. package/src/review/i18n/fo.ts +23 -0
  689. package/src/review/i18n/fr.ts +27 -0
  690. package/src/review/i18n/he.ts +26 -0
  691. package/src/review/i18n/hi.ts +23 -0
  692. package/src/review/i18n/hr.ts +26 -0
  693. package/src/review/i18n/hu.ts +23 -0
  694. package/src/review/i18n/hy.ts +23 -0
  695. package/src/review/i18n/id.ts +24 -0
  696. package/src/review/i18n/is.ts +23 -0
  697. package/src/review/i18n/it.ts +27 -0
  698. package/src/review/i18n/ja.ts +23 -0
  699. package/src/review/i18n/ka.ts +23 -0
  700. package/src/review/i18n/km.ts +23 -0
  701. package/src/review/i18n/ko.ts +23 -0
  702. package/src/review/i18n/lo.ts +23 -0
  703. package/src/review/i18n/lt.ts +29 -0
  704. package/src/review/i18n/lv.ts +26 -0
  705. package/src/review/i18n/mk.ts +23 -0
  706. package/src/review/i18n/mn.ts +23 -0
  707. package/src/review/i18n/ms.ts +24 -0
  708. package/src/review/i18n/my.ts +24 -0
  709. package/src/review/i18n/ne.ts +23 -0
  710. package/src/review/i18n/nl.ts +23 -0
  711. package/src/review/i18n/no.ts +23 -0
  712. package/src/review/i18n/pa.ts +23 -0
  713. package/src/review/i18n/pl.ts +29 -0
  714. package/src/review/i18n/ro.ts +26 -0
  715. package/src/review/i18n/ru.ts +29 -0
  716. package/src/review/i18n/si.ts +23 -0
  717. package/src/review/i18n/sk.ts +29 -0
  718. package/src/review/i18n/sl.ts +29 -0
  719. package/src/review/i18n/sq.ts +24 -0
  720. package/src/review/i18n/sr.ts +27 -0
  721. package/src/review/i18n/sv.ts +23 -0
  722. package/src/review/i18n/tg.ts +23 -0
  723. package/src/review/i18n/th.ts +23 -0
  724. package/src/review/i18n/tk.ts +23 -0
  725. package/src/review/i18n/tr.ts +23 -0
  726. package/src/review/i18n/uk.ts +30 -0
  727. package/src/review/i18n/ur.ts +23 -0
  728. package/src/review/i18n/uz.ts +23 -0
  729. package/src/review/i18n/vi.ts +24 -0
  730. package/src/review/i18n/zh.ts +23 -0
  731. package/src/review/i18n/zht.ts +23 -0
  732. package/src/review/index.ts +138 -0
  733. package/src/review/init-git-machine.ts +152 -0
  734. package/src/review/kinds.ts +191 -0
  735. package/src/review/machine.ts +274 -0
  736. package/src/review/mobile.tsx +91 -0
  737. package/src/review/model.ts +1123 -0
  738. package/src/review/panel.stories.tsx +50 -0
  739. package/src/review/panel.tsx +516 -0
  740. package/src/review/parts.tsx +141 -0
  741. package/src/review/render-machine.ts +74 -0
  742. package/src/review/renderer.tsx +403 -0
  743. package/src/review/screen-machine.ts +199 -0
  744. package/src/review/scroll-machine.ts +265 -0
  745. package/src/review/settings.tsx +28 -0
  746. package/src/schemes.ts +9 -0
  747. package/src/sources/i18n/en.ts +3 -0
  748. package/src/sources/index.ts +4 -0
  749. package/src/sources/panel.tsx +36 -0
  750. package/src/sources/renderer.tsx +95 -0
  751. package/src/ssh/add-machine.ts +63 -0
  752. package/src/ssh/askpass.ts +94 -0
  753. package/src/ssh/bootstrap.ts +160 -0
  754. package/src/ssh/command.ts +243 -0
  755. package/src/ssh/contract.ts +89 -0
  756. package/src/ssh/controller.ts +345 -0
  757. package/src/ssh/cover.tsx +66 -0
  758. package/src/ssh/dialog-machine.ts +249 -0
  759. package/src/ssh/dialog.stories.tsx +348 -0
  760. package/src/ssh/dialog.tsx +236 -0
  761. package/src/ssh/i18n/am.ts +37 -0
  762. package/src/ssh/i18n/ar.ts +38 -0
  763. package/src/ssh/i18n/az.ts +43 -0
  764. package/src/ssh/i18n/bg.ts +42 -0
  765. package/src/ssh/i18n/bn.ts +41 -0
  766. package/src/ssh/i18n/br.ts +43 -0
  767. package/src/ssh/i18n/bs.ts +43 -0
  768. package/src/ssh/i18n/ca.ts +43 -0
  769. package/src/ssh/i18n/cs.ts +43 -0
  770. package/src/ssh/i18n/da.ts +43 -0
  771. package/src/ssh/i18n/de.ts +44 -0
  772. package/src/ssh/i18n/dv.ts +43 -0
  773. package/src/ssh/i18n/dz.ts +43 -0
  774. package/src/ssh/i18n/el.ts +45 -0
  775. package/src/ssh/i18n/en.ts +40 -0
  776. package/src/ssh/i18n/es.ts +43 -0
  777. package/src/ssh/i18n/et.ts +41 -0
  778. package/src/ssh/i18n/fa.ts +39 -0
  779. package/src/ssh/i18n/fi.ts +40 -0
  780. package/src/ssh/i18n/fo.ts +41 -0
  781. package/src/ssh/i18n/fr.ts +43 -0
  782. package/src/ssh/i18n/he.ts +37 -0
  783. package/src/ssh/i18n/hi.ts +40 -0
  784. package/src/ssh/i18n/hr.ts +43 -0
  785. package/src/ssh/i18n/hu.ts +43 -0
  786. package/src/ssh/i18n/hy.ts +41 -0
  787. package/src/ssh/i18n/id.ts +42 -0
  788. package/src/ssh/i18n/is.ts +40 -0
  789. package/src/ssh/i18n/it.ts +43 -0
  790. package/src/ssh/i18n/ja.ts +43 -0
  791. package/src/ssh/i18n/ka.ts +43 -0
  792. package/src/ssh/i18n/km.ts +41 -0
  793. package/src/ssh/i18n/ko.ts +40 -0
  794. package/src/ssh/i18n/lo.ts +39 -0
  795. package/src/ssh/i18n/lt.ts +41 -0
  796. package/src/ssh/i18n/lv.ts +42 -0
  797. package/src/ssh/i18n/mk.ts +43 -0
  798. package/src/ssh/i18n/mn.ts +41 -0
  799. package/src/ssh/i18n/ms.ts +40 -0
  800. package/src/ssh/i18n/my.ts +41 -0
  801. package/src/ssh/i18n/ne.ts +39 -0
  802. package/src/ssh/i18n/nl.ts +43 -0
  803. package/src/ssh/i18n/no.ts +42 -0
  804. package/src/ssh/i18n/pa.ts +40 -0
  805. package/src/ssh/i18n/pl.ts +42 -0
  806. package/src/ssh/i18n/ro.ts +44 -0
  807. package/src/ssh/i18n/ru.ts +42 -0
  808. package/src/ssh/i18n/si.ts +41 -0
  809. package/src/ssh/i18n/sk.ts +42 -0
  810. package/src/ssh/i18n/sl.ts +41 -0
  811. package/src/ssh/i18n/sq.ts +43 -0
  812. package/src/ssh/i18n/sr.ts +41 -0
  813. package/src/ssh/i18n/sv.ts +43 -0
  814. package/src/ssh/i18n/tg.ts +43 -0
  815. package/src/ssh/i18n/th.ts +38 -0
  816. package/src/ssh/i18n/tk.ts +41 -0
  817. package/src/ssh/i18n/tr.ts +42 -0
  818. package/src/ssh/i18n/uk.ts +40 -0
  819. package/src/ssh/i18n/ur.ts +40 -0
  820. package/src/ssh/i18n/uz.ts +43 -0
  821. package/src/ssh/i18n/vi.ts +42 -0
  822. package/src/ssh/i18n/zh.ts +36 -0
  823. package/src/ssh/i18n/zht.ts +36 -0
  824. package/src/ssh/index.ts +71 -0
  825. package/src/ssh/main-machine.ts +532 -0
  826. package/src/ssh/main.ts +75 -0
  827. package/src/ssh/name.ts +28 -0
  828. package/src/ssh/remote-cli.ts +137 -0
  829. package/src/ssh/renderer.tsx +254 -0
  830. package/src/ssh/row.tsx +97 -0
  831. package/src/ssh/ssh.css +35 -0
  832. package/src/ssh/state.ts +217 -0
  833. package/src/ssh/window-machine.ts +533 -0
  834. package/src/terminal/connection-machine.ts +285 -0
  835. package/src/terminal/connection.ts +112 -0
  836. package/src/terminal/dispatch.ts +44 -0
  837. package/src/terminal/focus-machine.ts +112 -0
  838. package/src/terminal/focus.ts +23 -0
  839. package/src/terminal/hover-label.ts +20 -0
  840. package/src/terminal/i18n/am.ts +28 -0
  841. package/src/terminal/i18n/ar.ts +28 -0
  842. package/src/terminal/i18n/az.ts +29 -0
  843. package/src/terminal/i18n/bg.ts +29 -0
  844. package/src/terminal/i18n/bn.ts +28 -0
  845. package/src/terminal/i18n/br.ts +29 -0
  846. package/src/terminal/i18n/bs.ts +29 -0
  847. package/src/terminal/i18n/ca.ts +28 -0
  848. package/src/terminal/i18n/cs.ts +28 -0
  849. package/src/terminal/i18n/da.ts +28 -0
  850. package/src/terminal/i18n/de.ts +29 -0
  851. package/src/terminal/i18n/dv.ts +28 -0
  852. package/src/terminal/i18n/dz.ts +28 -0
  853. package/src/terminal/i18n/el.ts +30 -0
  854. package/src/terminal/i18n/en.ts +30 -0
  855. package/src/terminal/i18n/es.ts +28 -0
  856. package/src/terminal/i18n/et.ts +28 -0
  857. package/src/terminal/i18n/fa.ts +28 -0
  858. package/src/terminal/i18n/fi.ts +29 -0
  859. package/src/terminal/i18n/fo.ts +28 -0
  860. package/src/terminal/i18n/fr.ts +29 -0
  861. package/src/terminal/i18n/he.ts +28 -0
  862. package/src/terminal/i18n/hi.ts +28 -0
  863. package/src/terminal/i18n/hr.ts +28 -0
  864. package/src/terminal/i18n/hu.ts +28 -0
  865. package/src/terminal/i18n/hy.ts +29 -0
  866. package/src/terminal/i18n/id.ts +28 -0
  867. package/src/terminal/i18n/is.ts +28 -0
  868. package/src/terminal/i18n/it.ts +28 -0
  869. package/src/terminal/i18n/ja.ts +29 -0
  870. package/src/terminal/i18n/ka.ts +29 -0
  871. package/src/terminal/i18n/km.ts +28 -0
  872. package/src/terminal/i18n/ko.ts +28 -0
  873. package/src/terminal/i18n/lo.ts +28 -0
  874. package/src/terminal/i18n/lt.ts +29 -0
  875. package/src/terminal/i18n/lv.ts +28 -0
  876. package/src/terminal/i18n/mk.ts +29 -0
  877. package/src/terminal/i18n/mn.ts +30 -0
  878. package/src/terminal/i18n/ms.ts +28 -0
  879. package/src/terminal/i18n/my.ts +29 -0
  880. package/src/terminal/i18n/ne.ts +28 -0
  881. package/src/terminal/i18n/nl.ts +28 -0
  882. package/src/terminal/i18n/no.ts +28 -0
  883. package/src/terminal/i18n/pa.ts +28 -0
  884. package/src/terminal/i18n/pl.ts +28 -0
  885. package/src/terminal/i18n/ro.ts +28 -0
  886. package/src/terminal/i18n/ru.ts +28 -0
  887. package/src/terminal/i18n/si.ts +28 -0
  888. package/src/terminal/i18n/sk.ts +28 -0
  889. package/src/terminal/i18n/sl.ts +28 -0
  890. package/src/terminal/i18n/sq.ts +29 -0
  891. package/src/terminal/i18n/sr.ts +28 -0
  892. package/src/terminal/i18n/sv.ts +28 -0
  893. package/src/terminal/i18n/tg.ts +29 -0
  894. package/src/terminal/i18n/th.ts +28 -0
  895. package/src/terminal/i18n/tk.ts +29 -0
  896. package/src/terminal/i18n/tr.ts +29 -0
  897. package/src/terminal/i18n/uk.ts +28 -0
  898. package/src/terminal/i18n/ur.ts +28 -0
  899. package/src/terminal/i18n/uz.ts +29 -0
  900. package/src/terminal/i18n/vi.ts +28 -0
  901. package/src/terminal/i18n/zh.ts +28 -0
  902. package/src/terminal/i18n/zht.ts +28 -0
  903. package/src/terminal/index.ts +74 -0
  904. package/src/terminal/inline-rename.ts +93 -0
  905. package/src/terminal/label.tsx +71 -0
  906. package/src/terminal/machine.ts +767 -0
  907. package/src/terminal/model.ts +661 -0
  908. package/src/terminal/pane-machine.ts +260 -0
  909. package/src/terminal/panel.tsx +280 -0
  910. package/src/terminal/props.ts +16 -0
  911. package/src/terminal/quote-machine.ts +381 -0
  912. package/src/terminal/quote.css +7 -0
  913. package/src/terminal/quote.tsx +218 -0
  914. package/src/terminal/rename-machine.ts +98 -0
  915. package/src/terminal/renderer.tsx +298 -0
  916. package/src/terminal/runtime-adapters.ts +34 -0
  917. package/src/terminal/surface-machine.ts +186 -0
  918. package/src/terminal/tab.tsx +112 -0
  919. package/src/terminal/terminal-key-event.ts +58 -0
  920. package/src/terminal/terminal.fixture.tsx +71 -0
  921. package/src/terminal/terminal.tsx +652 -0
  922. package/src/terminal/title.ts +41 -0
  923. package/src/terminal/writer.ts +87 -0
  924. package/src/updater/action.ts +37 -0
  925. package/src/updater/actions.tsx +110 -0
  926. package/src/updater/i18n/am.ts +40 -0
  927. package/src/updater/i18n/ar.ts +40 -0
  928. package/src/updater/i18n/az.ts +41 -0
  929. package/src/updater/i18n/bg.ts +40 -0
  930. package/src/updater/i18n/bn.ts +41 -0
  931. package/src/updater/i18n/br.ts +40 -0
  932. package/src/updater/i18n/bs.ts +41 -0
  933. package/src/updater/i18n/ca.ts +41 -0
  934. package/src/updater/i18n/cs.ts +41 -0
  935. package/src/updater/i18n/da.ts +40 -0
  936. package/src/updater/i18n/de.ts +41 -0
  937. package/src/updater/i18n/dv.ts +41 -0
  938. package/src/updater/i18n/dz.ts +42 -0
  939. package/src/updater/i18n/el.ts +42 -0
  940. package/src/updater/i18n/en.ts +42 -0
  941. package/src/updater/i18n/es.ts +40 -0
  942. package/src/updater/i18n/et.ts +40 -0
  943. package/src/updater/i18n/fa.ts +40 -0
  944. package/src/updater/i18n/fi.ts +41 -0
  945. package/src/updater/i18n/fo.ts +40 -0
  946. package/src/updater/i18n/fr.ts +41 -0
  947. package/src/updater/i18n/he.ts +40 -0
  948. package/src/updater/i18n/hi.ts +40 -0
  949. package/src/updater/i18n/hr.ts +41 -0
  950. package/src/updater/i18n/hu.ts +40 -0
  951. package/src/updater/i18n/hy.ts +41 -0
  952. package/src/updater/i18n/id.ts +41 -0
  953. package/src/updater/i18n/is.ts +40 -0
  954. package/src/updater/i18n/it.ts +40 -0
  955. package/src/updater/i18n/ja.ts +41 -0
  956. package/src/updater/i18n/ka.ts +40 -0
  957. package/src/updater/i18n/km.ts +40 -0
  958. package/src/updater/i18n/ko.ts +40 -0
  959. package/src/updater/i18n/lo.ts +40 -0
  960. package/src/updater/i18n/lt.ts +41 -0
  961. package/src/updater/i18n/lv.ts +40 -0
  962. package/src/updater/i18n/mk.ts +41 -0
  963. package/src/updater/i18n/mn.ts +40 -0
  964. package/src/updater/i18n/ms.ts +41 -0
  965. package/src/updater/i18n/my.ts +40 -0
  966. package/src/updater/i18n/ne.ts +40 -0
  967. package/src/updater/i18n/nl.ts +41 -0
  968. package/src/updater/i18n/no.ts +40 -0
  969. package/src/updater/i18n/pa.ts +40 -0
  970. package/src/updater/i18n/pl.ts +41 -0
  971. package/src/updater/i18n/ro.ts +41 -0
  972. package/src/updater/i18n/ru.ts +40 -0
  973. package/src/updater/i18n/si.ts +40 -0
  974. package/src/updater/i18n/sk.ts +41 -0
  975. package/src/updater/i18n/sl.ts +40 -0
  976. package/src/updater/i18n/sq.ts +40 -0
  977. package/src/updater/i18n/sr.ts +41 -0
  978. package/src/updater/i18n/sv.ts +40 -0
  979. package/src/updater/i18n/tg.ts +41 -0
  980. package/src/updater/i18n/th.ts +40 -0
  981. package/src/updater/i18n/tk.ts +40 -0
  982. package/src/updater/i18n/tr.ts +40 -0
  983. package/src/updater/i18n/uk.ts +40 -0
  984. package/src/updater/i18n/ur.ts +40 -0
  985. package/src/updater/i18n/uz.ts +41 -0
  986. package/src/updater/i18n/vi.ts +41 -0
  987. package/src/updater/i18n/zh.ts +40 -0
  988. package/src/updater/i18n/zht.ts +40 -0
  989. package/src/updater/index.ts +94 -0
  990. package/src/updater/log.ts +41 -0
  991. package/src/updater/machine.ts +919 -0
  992. package/src/updater/main.ts +138 -0
  993. package/src/updater/platform.ts +160 -0
  994. package/src/updater/renderer.tsx +203 -0
  995. package/src/updater/section.tsx +65 -0
  996. package/src/updater/web-driver.ts +200 -0
  997. package/src/updater/web-machine.ts +222 -0
  998. package/src/updater/web.tsx +103 -0
  999. package/src/updater/whats-new-machine.ts +97 -0
  1000. package/src/updater/whats-new.stories.tsx +38 -0
  1001. package/src/updater/whats-new.tsx +304 -0
  1002. package/src/updater/window-machine.ts +73 -0
  1003. package/src/wsl/add-machine.ts +56 -0
  1004. package/src/wsl/contract.ts +104 -0
  1005. package/src/wsl/dialog-machine.ts +322 -0
  1006. package/src/wsl/dialog.css +372 -0
  1007. package/src/wsl/dialog.tsx +492 -0
  1008. package/src/wsl/i18n/am.ts +53 -0
  1009. package/src/wsl/i18n/ar.ts +55 -0
  1010. package/src/wsl/i18n/az.ts +57 -0
  1011. package/src/wsl/i18n/bg.ts +58 -0
  1012. package/src/wsl/i18n/bn.ts +56 -0
  1013. package/src/wsl/i18n/br.ts +58 -0
  1014. package/src/wsl/i18n/bs.ts +58 -0
  1015. package/src/wsl/i18n/ca.ts +58 -0
  1016. package/src/wsl/i18n/cs.ts +57 -0
  1017. package/src/wsl/i18n/da.ts +57 -0
  1018. package/src/wsl/i18n/de.ts +59 -0
  1019. package/src/wsl/i18n/dv.ts +58 -0
  1020. package/src/wsl/i18n/dz.ts +59 -0
  1021. package/src/wsl/i18n/el.ts +57 -0
  1022. package/src/wsl/i18n/en.ts +55 -0
  1023. package/src/wsl/i18n/es.ts +58 -0
  1024. package/src/wsl/i18n/et.ts +55 -0
  1025. package/src/wsl/i18n/fa.ts +56 -0
  1026. package/src/wsl/i18n/fi.ts +57 -0
  1027. package/src/wsl/i18n/fo.ts +56 -0
  1028. package/src/wsl/i18n/fr.ts +57 -0
  1029. package/src/wsl/i18n/he.ts +54 -0
  1030. package/src/wsl/i18n/hi.ts +57 -0
  1031. package/src/wsl/i18n/hr.ts +58 -0
  1032. package/src/wsl/i18n/hu.ts +58 -0
  1033. package/src/wsl/i18n/hy.ts +57 -0
  1034. package/src/wsl/i18n/id.ts +56 -0
  1035. package/src/wsl/i18n/is.ts +55 -0
  1036. package/src/wsl/i18n/it.ts +57 -0
  1037. package/src/wsl/i18n/ja.ts +57 -0
  1038. package/src/wsl/i18n/ka.ts +56 -0
  1039. package/src/wsl/i18n/km.ts +57 -0
  1040. package/src/wsl/i18n/ko.ts +56 -0
  1041. package/src/wsl/i18n/lo.ts +54 -0
  1042. package/src/wsl/i18n/lt.ts +57 -0
  1043. package/src/wsl/i18n/lv.ts +57 -0
  1044. package/src/wsl/i18n/mk.ts +57 -0
  1045. package/src/wsl/i18n/mn.ts +58 -0
  1046. package/src/wsl/i18n/ms.ts +57 -0
  1047. package/src/wsl/i18n/my.ts +57 -0
  1048. package/src/wsl/i18n/ne.ts +57 -0
  1049. package/src/wsl/i18n/nl.ts +57 -0
  1050. package/src/wsl/i18n/no.ts +57 -0
  1051. package/src/wsl/i18n/pa.ts +57 -0
  1052. package/src/wsl/i18n/pl.ts +58 -0
  1053. package/src/wsl/i18n/ro.ts +56 -0
  1054. package/src/wsl/i18n/ru.ts +57 -0
  1055. package/src/wsl/i18n/si.ts +56 -0
  1056. package/src/wsl/i18n/sk.ts +57 -0
  1057. package/src/wsl/i18n/sl.ts +57 -0
  1058. package/src/wsl/i18n/sq.ts +56 -0
  1059. package/src/wsl/i18n/sr.ts +57 -0
  1060. package/src/wsl/i18n/sv.ts +58 -0
  1061. package/src/wsl/i18n/tg.ts +57 -0
  1062. package/src/wsl/i18n/th.ts +57 -0
  1063. package/src/wsl/i18n/tk.ts +56 -0
  1064. package/src/wsl/i18n/tr.ts +57 -0
  1065. package/src/wsl/i18n/uk.ts +57 -0
  1066. package/src/wsl/i18n/ur.ts +57 -0
  1067. package/src/wsl/i18n/uz.ts +57 -0
  1068. package/src/wsl/i18n/vi.ts +56 -0
  1069. package/src/wsl/i18n/zh.ts +53 -0
  1070. package/src/wsl/i18n/zht.ts +53 -0
  1071. package/src/wsl/index.ts +72 -0
  1072. package/src/wsl/local.ts +41 -0
  1073. package/src/wsl/machine.ts +652 -0
  1074. package/src/wsl/main.ts +95 -0
  1075. package/src/wsl/model.ts +369 -0
  1076. package/src/wsl/probe-machine.ts +143 -0
  1077. package/src/wsl/probes.ts +107 -0
  1078. package/src/wsl/remote-cli.ts +49 -0
  1079. package/src/wsl/renderer.tsx +164 -0
  1080. package/src/wsl/row-view.ts +25 -0
  1081. package/src/wsl/row.tsx +76 -0
  1082. package/src/wsl/runtime.ts +441 -0
  1083. package/src/wsl/servers.ts +330 -0
  1084. package/src/wsl/sidecar.ts +186 -0
  1085. package/tsconfig.json +21 -0
@@ -0,0 +1,1522 @@
1
+ import type { Browser } from "@zyro-sec/plugin-browser/rpc"
2
+
3
+ /** How long a registration waits for main's answer, above main's own 15 s attach timeout. */
4
+ export const REGISTER_TIMEOUT_MS = 20_000
5
+
6
+ export const RETRY_BASE_MS = 1_000
7
+
8
+ export const RETRY_MAX_MS = 30_000
9
+
10
+ /**
11
+ * How many registrations may fail in a row while a pane with nothing to show yet still counts as on its way. Past
12
+ * that the retries go on, and the pane says the browser could not open.
13
+ */
14
+ export const PENDING_RETRIES = 4
15
+
16
+ /** The pane's main-process Ipc: running in a generation, starting or restarting, or gone. */
17
+ export type Ipc =
18
+ | { readonly status: "active"; readonly generation: number }
19
+ | { readonly status: "pending" }
20
+ | { readonly status: "inactive" }
21
+
22
+ /**
23
+ * One session's native binding. `attempt` names the current binding (`registering`, `ready`) or retry timer
24
+ * (`backoff`), so results of a superseded one are ignored. `attempts` counts registrations that failed in a row, which
25
+ * sets the backoff.
26
+ * - `idle`: nothing asked for the pane yet, e.g. the server is still creating the session.
27
+ * - `registering`: a binding waits for main to take it.
28
+ * - `ready`: main took the binding.
29
+ * - `backoff`: main closed or refused the binding; a timer registers again.
30
+ * - `suspended`: the tabs stay without a binding. `idle`: the server evicted it, and a user or agent wakes it. `ipc`:
31
+ * the pane's Ipc is gone, and it registers again once the Ipc is back.
32
+ * - `blocked`: another window took the session (`replaced`), until the person comes to it here again or no desktop
33
+ * holds it, or the server lacks it (`missing`).
34
+ */
35
+ export type Phase =
36
+ | { readonly status: "idle" }
37
+ | { readonly status: "registering"; readonly attempt: number; readonly attempts: number }
38
+ | { readonly status: "ready"; readonly attempt: number }
39
+ | { readonly status: "backoff"; readonly attempt: number; readonly attempts: number }
40
+ | { readonly status: "suspended"; readonly reason: "idle" | "ipc" | "unlisted" }
41
+ | { readonly status: "blocked"; readonly reason: "replaced" | "missing" | "unsupported" }
42
+
43
+ /** A tab a page or link opened, and the tab it stands after in the strip, as the desktop reports it once. */
44
+ export type Placed = { readonly tabID: Browser.TabID; readonly after: Browser.TabID }
45
+
46
+ /** How the session's side-panel strip follows the desktop's tab inventory. */
47
+ export type Strip = {
48
+ /** The session's location is known, so the strip can be written. */
49
+ readonly located: boolean
50
+ /** Tab IDs of the last inventory the strip received, to tell new tabs from ones the user just closed. */
51
+ readonly mirrored: readonly Browser.TabID[]
52
+ /** A native inventory arrived while the strip could not be written; the next sync prunes with it. */
53
+ readonly prune: boolean
54
+ /** A tab main asked to select while the strip could not be written. */
55
+ readonly focus: Browser.TabID | undefined
56
+ /**
57
+ * Saved tabs the person closed in the strip before an inventory named them. The first native inventory that has one
58
+ * closes it on the desktop, and the strip does not take it back.
59
+ */
60
+ readonly dismissed: readonly string[]
61
+ /**
62
+ * Tabs whose close the person asked the desktop for, each by its command's request, until the desktop answers or
63
+ * an inventory leaves the tab out. The strip dropped each at once, and does not take it back meanwhile.
64
+ */
65
+ readonly closing: readonly { readonly tabID: Browser.TabID; readonly request: number }[]
66
+ /**
67
+ * The saved tab the person selected in the strip before an inventory named it, not the one the strip mounted with.
68
+ * The first native inventory that has it, with another tab in front, brings it to the front on the desktop too.
69
+ */
70
+ readonly selected: string | undefined
71
+ }
72
+
73
+ /**
74
+ * The address field focus a user's new blank tab asks for.
75
+ * - `opening`: the tab is requested; `known` are the tabs before it, and `settled` is true once the command answered.
76
+ * - `ready`: the new blank tab; its pane focuses the address field once it shows it.
77
+ */
78
+ export type AddressFocus =
79
+ | { readonly status: "none" }
80
+ | {
81
+ readonly status: "opening"
82
+ readonly request: number
83
+ readonly known: readonly Browser.TabID[]
84
+ readonly settled: boolean
85
+ }
86
+ | { readonly status: "ready"; readonly tabID: Browser.TabID }
87
+
88
+ /**
89
+ * Something that did not work: the raw `code`, such as `browser.address.web`, and the command the person attempted,
90
+ * which is undefined when main reported the error by itself. `id` tells one failure from the next with the same code.
91
+ */
92
+ export type Failure = {
93
+ readonly id: number
94
+ readonly code: string
95
+ readonly action: Browser.Action | undefined
96
+ }
97
+
98
+ export type Attachment = {
99
+ readonly serverID: string
100
+ readonly phase: Phase
101
+ /** The desktop's tab inventory, kept while suspended or retrying so a new binding restores it. */
102
+ readonly browser: Browser.State | null
103
+ /** Host embed per tab page of the current binding. */
104
+ readonly embeds: Readonly<Record<string, string | undefined>>
105
+ /**
106
+ * The last failed command or the last error main reported, until the person's next command, their dismissal or a
107
+ * newer one. A healthy inventory keeps it: the person may not have read it yet.
108
+ */
109
+ readonly failure: Failure | undefined
110
+ readonly strip: Strip
111
+ readonly addressFocus: AddressFocus
112
+ /**
113
+ * `dismissed`: the person closed the pane during a run in which it had shown the agent's page (`shown`), so nothing
114
+ * opens it again until the run ends, their next queued prompt starts, or they open it themselves.
115
+ */
116
+ readonly side: "unobserved" | "open" | "closed" | "dismissed"
117
+ /**
118
+ * The pane has shown the agent's page in this run: a show request opened or took the pane, or the agent worked in
119
+ * the tab the open pane showed. Closing a pane that showed none of that says nothing about the agent's pages.
120
+ */
121
+ readonly shown: boolean
122
+ /**
123
+ * What an agent's activity asked of the pane, kept while it cannot be decided: the strip cannot be written yet, or
124
+ * the inventory that carries the tab has not arrived. It holds only what was asked. Once both are there, the driver
125
+ * asks again with what is true then (`present-held`), so it is decided as a request that arrives at that moment is.
126
+ * A newer request replaces it, and it is dropped, not applied, when the person acts first, the run ends, the tab
127
+ * closes, the session leaves the screen, its binding is superseded, or `HELD_REQUEST_TTL_MS` passes.
128
+ */
129
+ readonly held?: Held
130
+ readonly unseen: readonly Browser.TabID[]
131
+ /**
132
+ * Tabs a link opened whose first page has no name of its own yet, as the desktop reports them. The strip sizes a tab
133
+ * by its label, so each keeps its new-tab label until its page names itself, and is relabelled once.
134
+ */
135
+ readonly unnamed: readonly Browser.TabID[]
136
+ /** The person's prompts that wait in the session's inbox, by inbox ID, with how each will be delivered. */
137
+ readonly prompts: Readonly<Record<string, "steer" | "queue">>
138
+ /**
139
+ * The tab an agent's show request selected: in a closed pane, over another tab, or in a session nobody was looking
140
+ * at. Its page stays hidden and its pane takes no input until the delay ends, which runs (`timing`) from the moment
141
+ * the pane shows the tab to the person, so a press already on its way cannot land in it.
142
+ */
143
+ readonly reveal?: { readonly tabID: Browser.TabID; readonly token: number; readonly timing: boolean }
144
+ }
145
+
146
+ /** How long a kept show request may wait for the state it needs before it is dropped. */
147
+ export const HELD_REQUEST_TTL_MS = 5_000
148
+
149
+ /** A kept show request: the binding it came through, the tab, and what it asked. `token` names its expiry timer. */
150
+ export type Held = {
151
+ readonly attempt: number
152
+ readonly tabID: Browser.TabID
153
+ readonly reveal: "none" | "tab"
154
+ readonly token: number
155
+ }
156
+
157
+ /**
158
+ * Every attachment of this window, which belongs to its shell session tab rather than the route. `issued` is the last
159
+ * attempt or request id handed out. A Location whose browser RPC is not available blocks only its session.
160
+ */
161
+ export type State =
162
+ | {
163
+ readonly status: "open"
164
+ readonly ipc: Ipc
165
+ readonly issued: number
166
+ readonly sessions: Readonly<Record<string, Attachment | undefined>>
167
+ }
168
+ | { readonly status: "disposed" }
169
+
170
+ export type Event =
171
+ /** The person's prompt entered the session's inbox. Steers, compactions and synthetic items are not reported. */
172
+ | { readonly type: "prompt.enqueued"; readonly sessionKey: string; readonly id: string; readonly delivery: "steer" | "queue" }
173
+ | { readonly type: "inbox.delivery.changed"; readonly sessionKey: string; readonly id: string; readonly delivery: "steer" | "queue" }
174
+ | { readonly type: "inbox.delivered" | "inbox.cancelled"; readonly sessionKey: string; readonly id: string }
175
+ | { readonly type: "pane.file"; readonly sessionKey: string; readonly attempt: number; readonly path: string; readonly enabled: boolean; readonly onScreen: boolean; readonly room: boolean; readonly opened: boolean }
176
+ | { readonly type: "side.changed"; readonly sessionKey: string; readonly open: boolean; readonly running: boolean }
177
+ | { readonly type: "execution.ended"; readonly sessionKey: string }
178
+ | { readonly type: "activity.seen"; readonly sessionKey: string; readonly tabID: Browser.TabID }
179
+ /** The pane now shows the revealed tab to the person: it is the tab on screen, in a window that is not hidden. */
180
+ | { readonly type: "reveal.drawn"; readonly sessionKey: string; readonly token: number }
181
+ | { readonly type: "reveal.elapsed"; readonly sessionKey: string; readonly token: number }
182
+ /** A kept show request waited `HELD_REQUEST_TTL_MS`. */
183
+ | { readonly type: "held.expired"; readonly sessionKey: string; readonly token: number }
184
+ /** The person no longer sees the session: another one is routed, or the window is hidden or minimized. */
185
+ | { readonly type: "screen.left"; readonly sessionKey: string }
186
+ | {
187
+ readonly type: "pane.activity"
188
+ /**
189
+ * `none`: the tab is only marked. `tab`: the tab is selected, in a closed pane or in an open one that shows
190
+ * another tab (a preview, or a tab the agent opened or focused to show it).
191
+ */
192
+ readonly reveal: "none" | "tab"
193
+ readonly room: boolean
194
+ readonly sessionKey: string
195
+ readonly attempt: number
196
+ readonly tabID: Browser.TabID
197
+ readonly enabled: boolean
198
+ readonly onScreen: boolean
199
+ readonly opened: boolean
200
+ readonly visible: boolean
201
+ }
202
+ | { readonly type: "disposed" }
203
+ | { readonly type: "ipc.changed"; readonly ipc: Ipc }
204
+ | { readonly type: "session.capability.changed"; readonly sessionKey: string }
205
+ | { readonly type: "session.presence"; readonly sessionKey: string; readonly listed: boolean }
206
+ | { readonly type: "session.rebind"; readonly sessionKey: string }
207
+ | {
208
+ readonly type: "session.attached"
209
+ readonly sessionKey: string
210
+ readonly serverID: string
211
+ readonly located: boolean
212
+ }
213
+ | { readonly type: "session.removed"; readonly sessionKeys: readonly string[] }
214
+ | { readonly type: "session.routed"; readonly sessionKey: string | undefined }
215
+ | { readonly type: "session.located"; readonly sessionKey: string; readonly located: boolean }
216
+ /**
217
+ * A user or agent edge asks for the pane: focus, a key, the route, or a Session execution. `takes`: the person came
218
+ * to the session in this window (its route, a prompt, opening its browser), so one another window took comes back
219
+ * here. Focus, a press, a key and an agent's edges do not take: they would fail the other window's commands.
220
+ */
221
+ | { readonly type: "session.wake"; readonly sessionKey: string; readonly takes: boolean }
222
+ /** No desktop holds the session's browser any more: the window that took it let it go. */
223
+ | { readonly type: "session.released"; readonly sessionKey: string }
224
+ /** The person asks to open the browser again, from a pane that said it could not (`sessionUnavailable`). */
225
+ | { readonly type: "session.retry"; readonly sessionKey: string }
226
+ /** The server finished creating the session. */
227
+ | { readonly type: "session.created"; readonly sessionKey: string }
228
+ | {
229
+ readonly type: "session.command"
230
+ readonly sessionKey: string
231
+ readonly action: Browser.Action
232
+ /** The user opened a blank tab, whose pane then focuses the address field. */
233
+ readonly focusAddress: boolean
234
+ }
235
+ | { readonly type: "command.settled"; readonly sessionKey: string; readonly request: number }
236
+ | {
237
+ readonly type: "command.failed"
238
+ readonly sessionKey: string
239
+ /** The binding the command went through; undefined when none could take it. */
240
+ readonly attempt: number | undefined
241
+ readonly request: number
242
+ /** The command that failed, which a notice names and can offer again. */
243
+ readonly action: Browser.Action
244
+ readonly error: string
245
+ /** The pane's Ipc could not answer. */
246
+ readonly unavailable: boolean
247
+ }
248
+ /** The person closed the failure's notice, or its time ran out. */
249
+ | { readonly type: "failure.dismissed"; readonly sessionKey: string; readonly id: number }
250
+ | { readonly type: "address.focused"; readonly sessionKey: string; readonly tabID: Browser.TabID }
251
+ /** The person closed or selected, in the strip, a tab the strip stored and no inventory has named yet. */
252
+ | { readonly type: "strip.tab.closed" | "strip.tab.selected"; readonly sessionKey: string; readonly tabID: string }
253
+ /** The person came to the session: the browser tabs its strip stores now, which may have lost some meanwhile. */
254
+ | { readonly type: "strip.read"; readonly sessionKey: string; readonly stored: readonly string[] }
255
+ | { readonly type: "register.accepted"; readonly sessionKey: string; readonly attempt: number }
256
+ | {
257
+ readonly type: "register.failed"
258
+ readonly sessionKey: string
259
+ readonly attempt: number
260
+ /** The pane's Ipc could not answer. */
261
+ readonly unavailable: boolean
262
+ /** Main closed the binding it took; its closed-state event decides why. */
263
+ readonly closed: boolean
264
+ }
265
+ | { readonly type: "register.timed-out"; readonly sessionKey: string; readonly attempt: number }
266
+ | { readonly type: "retry.due"; readonly sessionKey: string; readonly attempt: number }
267
+ | {
268
+ readonly type: "pane.state"
269
+ readonly sessionKey: string
270
+ readonly attempt: number
271
+ readonly state: Browser.State | null
272
+ readonly error: string | undefined
273
+ /** Tabs a link opened whose pages have no name of their own yet (`Attachment.unnamed`). */
274
+ readonly unnamed?: readonly Browser.TabID[]
275
+ /** The tab this inventory lists for the first time because a page or link opened it, and the tab it stands after. */
276
+ readonly placed?: Placed
277
+ /**
278
+ * The browser tabs the session's strip stores now, when the layout can be read. The strip holds what the host
279
+ * keeps, which can drop a session's tabs without the browser: it gets back every tab this inventory still has.
280
+ */
281
+ readonly stored?: readonly string[]
282
+ }
283
+ | {
284
+ readonly type: "pane.embed"
285
+ readonly sessionKey: string
286
+ readonly attempt: number
287
+ readonly tabID: Browser.TabID
288
+ readonly embed: string
289
+ }
290
+ | {
291
+ readonly type: "pane.focus"
292
+ readonly sessionKey: string
293
+ readonly attempt: number
294
+ readonly tabID: Browser.TabID
295
+ }
296
+
297
+ export type MachineEffect =
298
+ | { readonly type: "present-file"; readonly sessionKey: string; readonly path: string; readonly select: boolean }
299
+ /** Starts the time after which `held.expired` drops the kept show request. */
300
+ | { readonly type: "expire-held"; readonly sessionKey: string; readonly token: number; readonly delayMs: number }
301
+ /**
302
+ * The state a kept show request waited for is there: the driver sends it again as `pane.activity`, with what is true
303
+ * now for the screen, the pane and the person's setting.
304
+ */
305
+ | {
306
+ readonly type: "present-held"
307
+ readonly sessionKey: string
308
+ readonly attempt: number
309
+ readonly tabID: Browser.TabID
310
+ readonly reveal: "none" | "tab"
311
+ }
312
+ /** Starts the delay after which `reveal.elapsed` shows the revealed page. */
313
+ | { readonly type: "expire-reveal"; readonly sessionKey: string; readonly token: number }
314
+ | {
315
+ readonly type: "open-registration"
316
+ readonly sessionKey: string
317
+ readonly attempt: number
318
+ readonly restore: Browser.State | undefined
319
+ }
320
+ | { readonly type: "close-registration"; readonly sessionKey: string; readonly attempt: number }
321
+ | {
322
+ readonly type: "schedule-register-timeout"
323
+ readonly sessionKey: string
324
+ readonly attempt: number
325
+ readonly delayMs: number
326
+ }
327
+ | { readonly type: "cancel-register-timeout"; readonly sessionKey: string }
328
+ | { readonly type: "schedule-retry"; readonly sessionKey: string; readonly attempt: number; readonly delayMs: number }
329
+ | { readonly type: "cancel-retry"; readonly sessionKey: string }
330
+ | {
331
+ readonly type: "send-command"
332
+ readonly sessionKey: string
333
+ readonly attempt: number
334
+ readonly request: number
335
+ readonly action: Browser.Action
336
+ }
337
+ | {
338
+ readonly type: "reject-command"
339
+ readonly sessionKey: string
340
+ readonly request: number
341
+ readonly action: Browser.Action
342
+ readonly error: string
343
+ readonly unavailable: boolean
344
+ }
345
+ /**
346
+ * Applies an inventory to the strip: closes stored tabs `keep` lacks (only a native inventory prunes, so the desktop
347
+ * decides which tabs exist), then adds `open`: the tabs new since the last mirrored inventory, and the ones the
348
+ * strip lost. Each goes to the end, in order, except the ones `placed` names: a tab a page or link opened stands
349
+ * after the tab it came from, and a lost tab after the tab before it in the inventory.
350
+ */
351
+ | {
352
+ readonly type: "sync-strip"
353
+ readonly sessionKey: string
354
+ readonly keep: readonly Browser.TabID[] | undefined
355
+ readonly open: readonly Browser.TabID[]
356
+ readonly placed?: readonly Placed[]
357
+ }
358
+ | { readonly type: "focus-strip-tab"; readonly sessionKey: string; readonly tabID: Browser.TabID }
359
+ /** Records the session's loaded pages in the browser history, and its tabs for the strip of the next launch. */
360
+ | { readonly type: "record-history"; readonly sessionKey: string }
361
+ /** The session is no longer attached: drop its per-session resources. */
362
+ | { readonly type: "detach"; readonly sessionKey: string }
363
+ | { readonly type: "forget-tabs"; readonly sessionKey: string }
364
+
365
+ export type Transition = { readonly state: State; readonly effects: readonly MachineEffect[] }
366
+
367
+ /** The fields of a session ref the selectors read. */
368
+ export type Target = {
369
+ readonly key: string
370
+ readonly pending: boolean
371
+ readonly server: { readonly id: string; readonly compatible: boolean }
372
+ }
373
+
374
+ type Open = Extract<State, { status: "open" }>
375
+
376
+ type Bound = Extract<Phase, { status: "registering" | "ready" }>
377
+
378
+ type SessionEvent = Exclude<
379
+ Event,
380
+ { type: "disposed" | "ipc.changed" | "session.attached" | "session.removed" | "session.routed" }
381
+ >
382
+
383
+ // No attachment shares an object with another, not even an empty one: the model reconciles the state into its store,
384
+ // which writes into existing objects in place, so a shared object would carry one session's change into the others.
385
+ const noFocus = (): AddressFocus => ({ status: "none" })
386
+
387
+ const noStrip = (): Strip => ({
388
+ located: false,
389
+ mirrored: [],
390
+ closing: [],
391
+ prune: false,
392
+ focus: undefined,
393
+ dismissed: [],
394
+ selected: undefined,
395
+ })
396
+
397
+ export function createInitialState(ipc: Ipc): State {
398
+ return { status: "open", ipc, issued: 0, sessions: {} }
399
+ }
400
+
401
+ export function transition(state: State, event: Event): Transition {
402
+ if (state.status === "disposed") return { state, effects: [] }
403
+
404
+ if (event.type === "disposed") return dispose(state)
405
+
406
+ if (event.type === "ipc.changed") return ipcChanged(state, event.ipc)
407
+
408
+ if (event.type === "session.attached") return attached(state, event)
409
+
410
+ if (event.type === "session.removed") return removed(state, event.sessionKeys)
411
+
412
+ if (event.type === "session.routed") return routed(state, event.sessionKey)
413
+ const attachment = state.sessions[event.sessionKey]
414
+
415
+ if (!attachment) return { state, effects: [] }
416
+
417
+ return session(state, event.sessionKey, attachment, event)
418
+ }
419
+
420
+ export function sessionSupported(state: State, key: string) {
421
+ const phase = attachmentOf(state, key)?.phase
422
+
423
+ return state.status === "open" && !(phase?.status === "blocked" && phase.reason === "unsupported")
424
+ }
425
+
426
+ function attachmentOf(state: State, sessionKey: string) {
427
+ return state.status === "open" ? state.sessions[sessionKey] : undefined
428
+ }
429
+
430
+ /** The desktop answered with an inventory, or took the binding. */
431
+ export function sessionAttached(state: State, sessionKey: string) {
432
+ const attachment = attachmentOf(state, sessionKey)
433
+
434
+ return !!attachment && (attachment.phase.status === "ready" || attachment.browser !== null)
435
+ }
436
+
437
+ /** Another window took the session's browser. */
438
+ export function sessionReplaced(state: State, sessionKey: string) {
439
+ const phase = attachmentOf(state, sessionKey)?.phase
440
+
441
+ return phase?.status === "blocked" && phase.reason === "replaced"
442
+ }
443
+
444
+ /**
445
+ * The session's browser can be opened from this window: the desktop answered for it, or another window took it and
446
+ * opening it here takes it back.
447
+ */
448
+ export function sessionOpenable(state: State, sessionKey: string) {
449
+ return sessionAttached(state, sessionKey) || sessionReplaced(state, sessionKey)
450
+ }
451
+
452
+ /**
453
+ * The desktop has not answered with its first inventory yet, and is on its way to: the routed session is about to
454
+ * attach, it registered and waits, it waits for the pane's Ipc to start, or it registers again after no more than
455
+ * `PENDING_RETRIES` failures in a row.
456
+ */
457
+ export function sessionPending(state: State, target: Target) {
458
+ if (state.status === "disposed") return false
459
+ const attachment = state.sessions[target.key]
460
+
461
+ if (!attachment) return target.server.compatible && !target.pending
462
+
463
+ if (attachment.browser || attachment.failure) return false
464
+ const phase = attachment.phase
465
+
466
+ return (
467
+ phase.status === "ready" ||
468
+ ((phase.status === "registering" || phase.status === "backoff") && phase.attempts <= PENDING_RETRIES) ||
469
+ (phase.status === "suspended" && phase.reason === "ipc" && state.ipc.status === "pending")
470
+ )
471
+ }
472
+
473
+ /**
474
+ * The session's browser could not open, and no inventory says what it had: its server has no browser, or registering
475
+ * failed more than `PENDING_RETRIES` times in a row, while the retries go on. The pane says so in place of the page
476
+ * and offers to try again (`session.retry`), never a loader with no end.
477
+ */
478
+ export function sessionUnavailable(state: State, sessionKey: string) {
479
+ const attachment = attachmentOf(state, sessionKey)
480
+
481
+ if (!attachment || attachment.browser) return false
482
+ const phase = attachment.phase
483
+
484
+ return (
485
+ (phase.status === "blocked" && phase.reason === "unsupported") ||
486
+ ((phase.status === "registering" || phase.status === "backoff") && phase.attempts > PENDING_RETRIES)
487
+ )
488
+ }
489
+
490
+ /**
491
+ * Tab IDs to list in the side panel: the desktop's inventory, limited to tabs stored in the strip. Until the first
492
+ * inventory arrives, the stored tabs, whatever the session's binding does meanwhile, so the strip keeps its tabs and
493
+ * its selection; that inventory then prunes the ones it lacks. A session another window took, or one the server lacks,
494
+ * lists none.
495
+ */
496
+ export function sessionTabs(state: State, target: Target, open: readonly string[]) {
497
+ if (state.status === "disposed") return []
498
+ const attachment = state.sessions[target.key]
499
+
500
+ // Not attached, as on a server whose version does not work with this app: only a session about to attach lists.
501
+ if (!attachment) return sessionPending(state, target) ? open : []
502
+
503
+ if (attachment.browser) return attachment.browser.tabs.flatMap((tab) => (open.includes(tab.id) ? [tab.id] : []))
504
+ const phase = attachment.phase
505
+
506
+ return phase.status === "blocked" && phase.reason !== "unsupported" ? [] : open
507
+ }
508
+
509
+ export function sessionBrowser(state: State, sessionKey: string) {
510
+ return attachmentOf(state, sessionKey)?.browser ?? null
511
+ }
512
+
513
+ export function sessionTab(state: State, sessionKey: string, tabID: string) {
514
+ return sessionBrowser(state, sessionKey)?.tabs.find((tab) => tab.id === tabID)
515
+ }
516
+
517
+ /** Whether the tab keeps its new-tab label: a link opened it and its page has no name of its own yet. */
518
+ export function tabUnnamed(state: State, sessionKey: string, tabID: string) {
519
+ return attachmentOf(state, sessionKey)?.unnamed.some((id) => id === tabID) ?? false
520
+ }
521
+
522
+ export function unseenActivity(state: State, sessionKey: string, tabID: string) {
523
+ return attachmentOf(state, sessionKey)?.unseen.some(id => id === tabID) ?? false
524
+ }
525
+
526
+ export function revealGuard(state: State, sessionKey: string, tabID: string) {
527
+ const reveal = attachmentOf(state, sessionKey)?.reveal
528
+
529
+ return reveal?.tabID === tabID ? reveal.token : undefined
530
+ }
531
+
532
+ /**
533
+ * Whether the session's attachment has its answer for now: the desktop took it, or it cannot attach until something
534
+ * else happens (the pane does not run, another desktop owns the session, the server has no browser, a retry timer
535
+ * runs). False while a registration, or the pane's Ipc that is still starting, can attach it without anyone acting.
536
+ * A prompt waits on this, so its first step lists the browser tools.
537
+ */
538
+ export function sessionSettled(state: State, sessionKey: string) {
539
+ const phase = attachmentOf(state, sessionKey)?.phase
540
+
541
+ if (!phase || state.status !== "open") return true
542
+
543
+ if (phase.status === "idle" || phase.status === "registering") return false
544
+
545
+ if (phase.status !== "suspended") return true
546
+
547
+ return phase.reason === "unlisted" || (phase.reason === "ipc" && state.ipc.status !== "pending")
548
+ }
549
+
550
+ /**
551
+ * Whether a prompt to the session waits for its attachment: only while one is in flight and can still succeed, on a
552
+ * session whose server could answer it (`reachable`, see `attachable`). In every other state the prompt goes at once.
553
+ */
554
+ export function sessionAttaching(state: State, sessionKey: string, reachable: boolean) {
555
+ return reachable && !sessionSettled(state, sessionKey)
556
+ }
557
+
558
+ export function sessionSuspended(state: State, sessionKey: string) {
559
+ return attachmentOf(state, sessionKey)?.phase.status === "suspended"
560
+ }
561
+
562
+ export function sessionError(state: State, sessionKey: string) {
563
+ return attachmentOf(state, sessionKey)?.failure?.code
564
+ }
565
+
566
+ export function sessionFailure(state: State, sessionKey: string) {
567
+ return attachmentOf(state, sessionKey)?.failure
568
+ }
569
+
570
+ export function sessionEmbed(state: State, sessionKey: string, tabID: string) {
571
+ return attachmentOf(state, sessionKey)?.embeds[tabID]
572
+ }
573
+
574
+ /** The current binding's attempt; a new one, e.g. after a suspension, has no pages for restored tabs yet. */
575
+ export function sessionRegistration(state: State, sessionKey: string) {
576
+ const phase = attachmentOf(state, sessionKey)?.phase
577
+
578
+ // Registration effects install the IPC handle *after* publishing the registering state. Only acceptance
579
+ // can wake the visible tab's loader: reading the Map while registering can consume the attempt too early.
580
+ return phase?.status === "ready" ? phase.attempt : undefined
581
+ }
582
+
583
+ /** The blank tab the user just opened, whose pane focuses the address field once it shows it. */
584
+ export function addressFocusTab(state: State, sessionKey: string) {
585
+ const focus = attachmentOf(state, sessionKey)?.addressFocus
586
+
587
+ return focus?.status === "ready" ? focus.tabID : undefined
588
+ }
589
+
590
+ function dispose(state: Open): Transition {
591
+ return {
592
+ state: { status: "disposed" },
593
+ effects: [
594
+ ...listed(state.sessions).flatMap(([key, attachment]) => [...stop(key, attachment.phase), detach(key)]),
595
+ ],
596
+ }
597
+ }
598
+
599
+ // The pane's Ipc goes away while its main plugin reloads or is not active, taking every binding with it. Each
600
+ // attachment keeps its tabs and registers again once the Ipc is back, without a retry timer.
601
+ function ipcChanged(state: Open, ipc: Ipc): Transition {
602
+ const previous = state.ipc
603
+
604
+ if (
605
+ previous.status === ipc.status &&
606
+ (previous.status !== "active" || ipc.status !== "active" || previous.generation === ipc.generation)
607
+ )
608
+ return { state, effects: [] }
609
+ const restarted = previous.status === "active"
610
+
611
+ return listed(state.sessions).reduce<Transition & { state: Open }>(
612
+ (result, [key, attachment]) => {
613
+ const phase = attachment.phase
614
+ const bound = phase.status === "registering" || phase.status === "ready" || phase.status === "backoff"
615
+ const lost = phase.status === "suspended" && phase.reason === "ipc"
616
+
617
+ if (ipc.status !== "active") {
618
+ if (!bound) return result
619
+
620
+ return put(result.state, key, suspend(attachment, "ipc"), [...result.effects, ...stop(key, phase)])
621
+ }
622
+
623
+ if (!lost && !(restarted && bound)) return result
624
+ const attempt = result.state.issued + 1
625
+
626
+ return put(
627
+ result.state,
628
+ key,
629
+ { ...attachment, phase: { status: "registering", attempt, attempts: 0 }, embeds: {}, failure: undefined },
630
+ [...result.effects, ...stop(key, phase), ...register(key, attempt, attachment.browser)],
631
+ attempt,
632
+ )
633
+ },
634
+ { state: { ...state, ipc }, effects: [] },
635
+ )
636
+ }
637
+
638
+ function attached(state: Open, event: Extract<Event, { type: "session.attached" }>): Transition {
639
+ if (state.sessions[event.sessionKey]) return { state, effects: [] }
640
+
641
+ return put(state, event.sessionKey, {
642
+ serverID: event.serverID,
643
+ phase: { status: "idle" },
644
+ browser: null,
645
+ embeds: {},
646
+ failure: undefined,
647
+ strip: { ...noStrip(), located: event.located },
648
+ addressFocus: noFocus(),
649
+ side: "unobserved",
650
+ shown: false,
651
+ unseen: [],
652
+ unnamed: [],
653
+ prompts: {},
654
+ })
655
+ }
656
+
657
+ function removed(state: Open, sessionKeys: readonly string[]): Transition {
658
+ const gone = listed(state.sessions).filter((entry) => sessionKeys.includes(entry[0]))
659
+
660
+ if (gone.length === 0) return { state, effects: [] }
661
+
662
+ return {
663
+ state: {
664
+ ...state,
665
+ sessions: Object.fromEntries(listed(state.sessions).filter((entry) => !sessionKeys.includes(entry[0]))),
666
+ },
667
+ effects: gone.flatMap(([key, attachment]) => [...stop(key, attachment.phase), {type:"forget-tabs" as const,sessionKey:key}, detach(key)]),
668
+ }
669
+ }
670
+
671
+ // A blank tab the user opened in one session must not take the address focus when another session shows a blank tab.
672
+ function routed(state: Open, sessionKey: string | undefined): Transition {
673
+ const reset = listed(state.sessions).filter(
674
+ ([key, attachment]) => key !== sessionKey && attachment.addressFocus.status !== "none",
675
+ )
676
+
677
+ if (reset.length === 0) return { state, effects: [] }
678
+
679
+ return {
680
+ state: {
681
+ ...state,
682
+ sessions: {
683
+ ...state.sessions,
684
+ ...Object.fromEntries(reset.map(([key, attachment]) => [key, { ...attachment, addressFocus: noFocus() }])),
685
+ },
686
+ },
687
+ effects: [],
688
+ }
689
+ }
690
+
691
+ function session(state: Open, key: string, attachment: Attachment, event: SessionEvent): Transition {
692
+ const phase = attachment.phase
693
+
694
+ switch (event.type) {
695
+ case "prompt.enqueued":
696
+ return put(state, key, { ...attachment, prompts: { ...attachment.prompts, [event.id]: event.delivery } })
697
+ case "inbox.delivery.changed": {
698
+ if (!(event.id in attachment.prompts) || attachment.prompts[event.id] === event.delivery) return { state, effects: [] }
699
+
700
+ return put(state, key, { ...attachment, prompts: { ...attachment.prompts, [event.id]: event.delivery } })
701
+ }
702
+
703
+ case "inbox.delivered":
704
+ case "inbox.cancelled": {
705
+ if (!(event.id in attachment.prompts)) return { state, effects: [] }
706
+ // Only the person's next queued prompt starts over. A steer belongs to the run whose pane they closed.
707
+ const next = event.type === "inbox.delivered" && attachment.prompts[event.id] === "queue" && attachment.side === "dismissed"
708
+
709
+ return put(state, key, {
710
+ ...attachment,
711
+ side: next ? "closed" : attachment.side,
712
+ // Their queued prompt is the next run, which has shown nothing yet.
713
+ shown: event.type === "inbox.delivered" && attachment.prompts[event.id] === "queue" ? false : attachment.shown,
714
+ prompts: Object.fromEntries(Object.entries(attachment.prompts).filter(([id]) => id !== event.id)),
715
+ })
716
+ }
717
+
718
+ case "side.changed": {
719
+ // Closing a pane that showed nothing of the agent's in this run, such as one the person opened to look at
720
+ // something else, is not an answer to the agent: its next show request still opens the pane.
721
+ const dismissed = event.running && (attachment.side === "dismissed" || (attachment.side === "open" && attachment.shown))
722
+ const side = event.open ? "open" : dismissed ? "dismissed" : "closed"
723
+
724
+ if (side === attachment.side) return { state, effects: [] }
725
+
726
+ // The person closed the pane: a show request kept from before that does not open it again.
727
+ const held = attachment.side === "open" && !event.open ? undefined : attachment.held
728
+
729
+ return put(state, key, { ...attachment, side, held, reveal: event.open ? attachment.reveal : undefined })
730
+ }
731
+
732
+ case "execution.ended":
733
+ // A show request kept from the run that ended, or was stopped, does not land after it.
734
+ if (attachment.side !== "dismissed" && !attachment.shown) return unhold(state, key, attachment)
735
+
736
+ return put(state, key, { ...attachment, held: undefined, side: attachment.side === "dismissed" ? "closed" : attachment.side, shown: false })
737
+ case "held.expired":
738
+ return attachment.held?.token === event.token ? unhold(state, key, attachment) : { state, effects: [] }
739
+ case "screen.left":
740
+ return unhold(state, key, attachment)
741
+ case "reveal.drawn": {
742
+ const reveal = attachment.reveal
743
+
744
+ if (!reveal || reveal.token !== event.token || reveal.timing) return { state, effects: [] }
745
+
746
+ return put(state, key, { ...attachment, reveal: { ...reveal, timing: true } }, [
747
+ { type: "expire-reveal", sessionKey: key, token: reveal.token },
748
+ ])
749
+ }
750
+
751
+ case "reveal.elapsed":
752
+ return attachment.reveal?.token === event.token ? put(state, key, { ...attachment, reveal: undefined }) : { state, effects: [] }
753
+ case "activity.seen":
754
+ return attachment.unseen.includes(event.tabID)
755
+ ? put(state, key, { ...attachment, unseen: attachment.unseen.filter(id => id !== event.tabID) })
756
+ : { state, effects: [] }
757
+ case "pane.file": {
758
+ // Only the routed session has a file panel, which holds its own write until the session's location is known.
759
+ if (!current(phase, event.attempt) || !event.onScreen) return { state, effects: [] }
760
+ // A file preview is a show request: it takes the pane even when another tab is selected there.
761
+ const select = event.room && event.enabled && attachment.side !== "dismissed"
762
+ const effects: MachineEffect[] = [{ type: "present-file", sessionKey: key, path: event.path, select }]
763
+
764
+ return select && !attachment.shown ? put(state, key, { ...attachment, shown: true }, effects) : { state, effects }
765
+ }
766
+
767
+ case "pane.activity":
768
+ return current(phase, event.attempt) ? present(state, key, attachment, event) : { state, effects: [] }
769
+
770
+ case "session.capability.changed":
771
+ if (phase.status !== "blocked" || phase.reason !== "unsupported") return {state,effects:[]}
772
+
773
+ return wake(state,key,suspend(attachment,"idle"),false,false)
774
+ case "session.presence":
775
+ if (event.listed) return phase.status === "suspended" && phase.reason === "unlisted" ? wake(state,key,suspend(attachment,"idle"),false,false) : {state,effects:[]}
776
+
777
+ if (phase.status === "suspended" && phase.reason === "unlisted") return {state,effects:[]}
778
+
779
+ return put(state,key,suspend(attachment,"unlisted"),stop(key,phase))
780
+ case "session.rebind": {
781
+ if (phase.status === "suspended" && phase.reason === "unlisted") return {state,effects:[]}
782
+ const next = wake(state,key,suspend(attachment,"idle"),false,false)
783
+
784
+ return {...next,effects:[...stop(key,phase),...next.effects]}
785
+ }
786
+
787
+ case "session.retry": {
788
+ // A registration is already under way: it only counts the failures in a row from the start again.
789
+ if (phase.status === "registering")
790
+ return phase.attempts === 0 ? { state, effects: [] } : put(state, key, { ...attachment, phase: { ...phase, attempts: 0 } })
791
+
792
+ if (phase.status !== "backoff" && !(phase.status === "blocked" && phase.reason === "unsupported"))
793
+ return { state, effects: [] }
794
+ // Registers now, in place of a retry timer.
795
+ const next = wake(state, key, suspend(attachment, "idle"), false, false)
796
+
797
+ return { ...next, effects: [...stop(key, phase), ...next.effects] }
798
+ }
799
+
800
+ case "session.located":
801
+ return located(state, key, attachment, event.located)
802
+ case "session.wake":
803
+ return wake(state, key, attachment, false, event.takes)
804
+ case "session.released":
805
+ // Only a session another window took: a pane the server suspended stays so until something asks for it.
806
+ return phase.status === "blocked" && phase.reason === "replaced" ? wake(state, key, attachment, false, true) : { state, effects: [] }
807
+ case "session.created":
808
+ return wake(state, key, attachment, true, false)
809
+ case "session.command": {
810
+ const reveal = attachment.reveal
811
+
812
+ // Selecting the revealed tab in the strip answers with tabs.focus for it, which is the reveal itself, not the
813
+ // person.
814
+ if (reveal && event.action.type === "tabs.focus" && event.action.tabID === reveal.tabID)
815
+ return command(state, key, attachment, event)
816
+
817
+ // The person's own command ends the guard, so their navigation or tab switch is never held back, and a show
818
+ // request kept from before it does not take the pane from what they just chose.
819
+ if (!reveal && !attachment.held) return command(state, key, attachment, event)
820
+
821
+ return command(state, key, { ...attachment, reveal: undefined, held: undefined }, event)
822
+ }
823
+
824
+ case "command.settled": {
825
+ const focus = attachment.addressFocus
826
+ const answered = closeAnswered(attachment, event.request)
827
+
828
+ if (focus.status !== "opening" || focus.request !== event.request)
829
+ return answered === attachment ? { state, effects: [] } : put(state, key, answered)
830
+
831
+ return put(state, key, { ...answered, addressFocus: { ...focus, settled: true } })
832
+ }
833
+
834
+ case "command.failed":
835
+ return commandFailed(state, key, closeAnswered(attachment, event.request), event)
836
+ case "failure.dismissed":
837
+ return attachment.failure?.id === event.id ? put(state, key, { ...attachment, failure: undefined }) : { state, effects: [] }
838
+ case "address.focused": {
839
+ if (attachment.addressFocus.status !== "ready" || attachment.addressFocus.tabID !== event.tabID)
840
+ return { state, effects: [] }
841
+
842
+ return put(state, key, { ...attachment, addressFocus: noFocus() })
843
+ }
844
+
845
+ case "strip.read": {
846
+ const strip = attachment.strip
847
+
848
+ if (!strip.located || !attachment.browser) return { state, effects: [] }
849
+ const ids = attachment.browser.tabs.map((tab) => tab.id)
850
+
851
+ return { state, effects: sync(key, ids, strip.mirrored, false, undefined, lost(strip, ids, event.stored)) }
852
+ }
853
+
854
+ case "strip.tab.closed": {
855
+ const strip = attachment.strip
856
+
857
+ // With an inventory the tab is known, and its close is a command, or gone, and there is nothing to close.
858
+ if (attachment.browser || strip.dismissed.includes(event.tabID)) return { state, effects: [] }
859
+
860
+ return put(state, key, {
861
+ ...attachment,
862
+ strip: {
863
+ ...strip,
864
+ dismissed: [...strip.dismissed, event.tabID],
865
+ selected: strip.selected === event.tabID ? undefined : strip.selected,
866
+ },
867
+ })
868
+ }
869
+
870
+ case "strip.tab.selected": {
871
+ if (attachment.browser || attachment.strip.selected === event.tabID) return { state, effects: [] }
872
+
873
+ return put(state, key, { ...attachment, strip: { ...attachment.strip, selected: event.tabID } })
874
+ }
875
+
876
+ case "register.accepted": {
877
+ if (phase.status !== "registering" || phase.attempt !== event.attempt) return { state, effects: [] }
878
+
879
+ return put(state, key, { ...attachment, phase: { status: "ready", attempt: phase.attempt } }, [
880
+ { type: "cancel-register-timeout", sessionKey: key },
881
+ ])
882
+ }
883
+
884
+ case "register.failed": {
885
+ if (phase.status !== "registering" || phase.attempt !== event.attempt) return { state, effects: [] }
886
+
887
+ if (event.unavailable) return put(state, key, suspend(attachment, "ipc"), stop(key, phase))
888
+
889
+ // Main closed a binding it took; its closed-state event decides, and the register timeout bounds the wait.
890
+ if (event.closed) return { state, effects: [] }
891
+
892
+ return backoff(state, key, attachment, phase)
893
+ }
894
+
895
+ case "register.timed-out": {
896
+ if (phase.status !== "registering" || phase.attempt !== event.attempt) return { state, effects: [] }
897
+
898
+ return backoff(state, key, attachment, phase)
899
+ }
900
+
901
+ case "retry.due": {
902
+ if (phase.status !== "backoff" || phase.attempt !== event.attempt) return { state, effects: [] }
903
+
904
+ if (state.ipc.status !== "active") return put(state, key, suspend(attachment, "ipc"))
905
+ const attempt = state.issued + 1
906
+
907
+ return put(
908
+ state,
909
+ key,
910
+ {
911
+ ...attachment,
912
+ phase: { status: "registering", attempt, attempts: phase.attempts },
913
+ embeds: {},
914
+ failure: undefined,
915
+ },
916
+ register(key, attempt, attachment.browser),
917
+ attempt,
918
+ )
919
+ }
920
+
921
+ case "pane.state":
922
+ return paneState(state, key, attachment, event)
923
+ case "pane.embed": {
924
+ if (!current(phase, event.attempt) || attachment.embeds[event.tabID] === event.embed)
925
+ return { state, effects: [] }
926
+
927
+ return put(state, key, { ...attachment, embeds: { ...attachment.embeds, [event.tabID]: event.embed } })
928
+ }
929
+
930
+ case "pane.focus": {
931
+ if (!current(phase, event.attempt)) return { state, effects: [] }
932
+
933
+ // Focus requests write to the owning session's strip even while another shell tab is routed, so the side panel
934
+ // and browser tab are already selected when the user returns to it.
935
+ if (attachment.strip.located)
936
+ return { state, effects: [{ type: "focus-strip-tab", sessionKey: key, tabID: event.tabID }] }
937
+
938
+ return put(state, key, { ...attachment, strip: { ...attachment.strip, focus: event.tabID } })
939
+ }
940
+ }
941
+ }
942
+
943
+ // The strip must be writable and the inventory must carry the tab before a show request can be decided.
944
+ function presentable(attachment: Attachment, tabID: Browser.TabID) {
945
+ return attachment.strip.located && !!attachment.browser?.tabs.some((tab) => tab.id === tabID)
946
+ }
947
+
948
+ // Decides what an agent's activity does to the pane, from what the event says is true now. A request that arrives
949
+ // before the strip or its tab's inventory is kept as asked, with a bound, and nothing is dropped for arriving first.
950
+ function present(
951
+ state: Open,
952
+ key: string,
953
+ attachment: Attachment,
954
+ event: Extract<Event, { type: "pane.activity" }>,
955
+ ): Transition {
956
+ if (!presentable(attachment, event.tabID)) {
957
+ const token = state.issued + 1
958
+ const held = { attempt: event.attempt, tabID: event.tabID, reveal: event.reveal, token }
959
+
960
+ return put(state, key, { ...attachment, held }, [{ type: "expire-held", sessionKey: key, token, delayMs: HELD_REQUEST_TTL_MS }], token)
961
+ }
962
+
963
+ // A newer request replaces a kept one.
964
+ const settled = attachment.held ? { ...attachment, held: undefined } : attachment
965
+ const unchanged = settled === attachment ? { state, effects: [] } : put(state, key, settled)
966
+
967
+ // Off screen only a preview acts: its tab is selected in the session's strip, so it shows when the person returns.
968
+ if (!event.onScreen && event.reveal !== "tab") return unchanged
969
+
970
+ // The agent worked in the tab the person is looking at. The strip's selected tab is not on show while its pane is
971
+ // closed.
972
+ if (event.onScreen && event.opened && event.visible) return settled.shown ? unchanged : put(state, key, { ...settled, shown: true })
973
+ const marked = settled.unseen.includes(event.tabID) ? settled.unseen : [...settled.unseen, event.tabID]
974
+
975
+ const select =
976
+ event.enabled &&
977
+ settled.side !== "dismissed" &&
978
+ (!event.onScreen || (event.room && event.reveal === "tab"))
979
+
980
+ if (!select) return marked === settled.unseen ? unchanged : put(state, key, { ...settled, unseen: marked })
981
+ const focus: MachineEffect = { type: "focus-strip-tab", sessionKey: key, tabID: event.tabID }
982
+ const token = state.issued + 1
983
+ const reveal = { token, tabID: event.tabID, timing: false }
984
+
985
+ // Nobody is looking: the tab waits selected, with its mark. Its guard waits too, since the person may be back before
986
+ // the selection lands. The delay starts only when the pane shows them the tab, so it costs nothing until then.
987
+ if (!event.onScreen) return put(state, key, { ...settled, unseen: marked, reveal }, [focus], token)
988
+
989
+ return put(state, key, { ...settled, shown: true, reveal }, [focus], token)
990
+ }
991
+
992
+ // Drops a kept show request without applying it.
993
+ function unhold(state: Open, key: string, attachment: Attachment): Transition {
994
+ return attachment.held ? put(state, key, { ...attachment, held: undefined }) : { state, effects: [] }
995
+ }
996
+
997
+ // The state a kept request waited for may be there now. It is not decided here from what was true when it arrived:
998
+ // the driver sends it again with what is true now. One that came through a binding since superseded is dropped.
999
+ function settle(result: { readonly state: Open; readonly effects: readonly MachineEffect[] }, key: string): Transition {
1000
+ const attachment = result.state.sessions[key]
1001
+ const held = attachment?.held
1002
+
1003
+ if (!attachment || !held) return result
1004
+
1005
+ if (!current(attachment.phase, held.attempt)) {
1006
+ const dropped = unhold(result.state, key, attachment)
1007
+
1008
+ return { state: dropped.state, effects: result.effects }
1009
+ }
1010
+
1011
+ if (!presentable(attachment, held.tabID)) return result
1012
+ const landed = unhold(result.state, key, attachment)
1013
+
1014
+ return {
1015
+ state: landed.state,
1016
+ effects: [
1017
+ ...result.effects,
1018
+ { type: "present-held", sessionKey: key, attempt: held.attempt, tabID: held.tabID, reveal: held.reveal },
1019
+ ],
1020
+ }
1021
+ }
1022
+
1023
+ // Writes held while the session's location was unknown land once the server reports it. A held focus lands only for
1024
+ // a tab the desktop still has.
1025
+ function located(state: Open, key: string, attachment: Attachment, value: boolean): Transition {
1026
+ const strip = attachment.strip
1027
+
1028
+ if (strip.located === value) return { state, effects: [] }
1029
+
1030
+ if (!value) return put(state, key, { ...attachment, strip: { ...strip, located: false } })
1031
+ const ids = attachment.browser?.tabs.map((tab) => tab.id)
1032
+ const focus = strip.focus
1033
+
1034
+ return settle(
1035
+ put(
1036
+ state,
1037
+ key,
1038
+ { ...attachment, strip: { ...strip, located: true, mirrored: ids ?? [], prune: false, focus: undefined } },
1039
+ [
1040
+ ...(ids ? sync(key, ids, strip.mirrored, strip.prune) : []),
1041
+ ...(focus && ids?.includes(focus) ? [{ type: "focus-strip-tab" as const, sessionKey: key, tabID: focus }] : []),
1042
+ ],
1043
+ ),
1044
+ key,
1045
+ )
1046
+ }
1047
+
1048
+ // Passive edges wake an idle or suspended pane without bypassing transport backoff or duplicating a binding. Only the
1049
+ // server creating the session lifts `missing`. Only a wake that `takes` lifts `replaced`: the other window may be
1050
+ // long closed, and a block nothing lifts leaves the session without a browser for as long as the app runs.
1051
+ function wake(state: Open, key: string, attachment: Attachment, created: boolean, takes: boolean): Transition {
1052
+ const phase = attachment.phase
1053
+
1054
+ if (phase.status === "suspended" && phase.reason === "unlisted") return {state,effects:[]}
1055
+
1056
+ if (phase.status === "registering" || phase.status === "ready" || phase.status === "backoff")
1057
+ return { state, effects: [] }
1058
+
1059
+ if (phase.status === "blocked" && !(phase.reason === "replaced" ? takes : created)) return { state, effects: [] }
1060
+
1061
+ if (state.ipc.status !== "active") {
1062
+ if (phase.status === "suspended" && phase.reason === "ipc") return { state, effects: [] }
1063
+
1064
+ return put(state, key, suspend(attachment, "ipc"))
1065
+ }
1066
+
1067
+ const attempt = state.issued + 1
1068
+ const restore = phase.status === "blocked" ? null : attachment.browser
1069
+
1070
+ return put(
1071
+ state,
1072
+ key,
1073
+ { ...attachment, phase: { status: "registering", attempt, attempts: 0 }, embeds: {}, failure: undefined },
1074
+ register(key, attempt, restore),
1075
+ attempt,
1076
+ )
1077
+ }
1078
+
1079
+ // A command wakes its attachment once and is never replayed. Backoff and blocked bindings answer at once without
1080
+ // registering, so repeated commands cannot bypass the retry timer.
1081
+ function command(
1082
+ state: Open,
1083
+ key: string,
1084
+ attachment: Attachment,
1085
+ event: Extract<Event, { type: "session.command" }>,
1086
+ ): Transition {
1087
+ const phase = attachment.phase
1088
+ const request = state.issued + 1
1089
+
1090
+ const focus: AddressFocus = event.focusAddress
1091
+ ? { status: "opening", request, known: attachment.browser?.tabs.map((tab) => tab.id) ?? [], settled: false }
1092
+ : attachment.addressFocus
1093
+
1094
+ // The strip dropped a tab the person closes there at once. Until the desktop answers, no inventory puts it back.
1095
+ const strip =
1096
+ event.action.type === "tabs.close"
1097
+ ? { ...attachment.strip, closing: [...attachment.strip.closing, { tabID: event.action.tabID, request }] }
1098
+ : attachment.strip
1099
+
1100
+ if (phase.status === "registering" || phase.status === "ready")
1101
+ return put(
1102
+ state,
1103
+ key,
1104
+ { ...attachment, failure: undefined, addressFocus: focus, strip },
1105
+ [{ type: "send-command", sessionKey: key, attempt: phase.attempt, request, action: event.action }],
1106
+ request,
1107
+ )
1108
+
1109
+ // No binding takes the command now. A close is kept, as for a saved tab, and reaches the desktop with its next
1110
+ // inventory, so the tab the person closed does not come back.
1111
+ const kept =
1112
+ event.action.type === "tabs.close" && !attachment.strip.dismissed.includes(event.action.tabID)
1113
+ ? { ...attachment.strip, dismissed: [...attachment.strip.dismissed, event.action.tabID] }
1114
+ : attachment.strip
1115
+
1116
+ if (phase.status === "backoff" || phase.status === "blocked" || (phase.status === "suspended" && phase.reason === "unlisted")) {
1117
+ const error =
1118
+ phase.status === "blocked" && phase.reason === "replaced" ? "browser.pane.replaced" : "browser.pane.unavailable"
1119
+
1120
+ return put(
1121
+ state,
1122
+ key,
1123
+ { ...attachment, failure: undefined, addressFocus: noFocus(), strip: kept },
1124
+ [{ type: "reject-command", sessionKey: key, request, action: event.action, error, unavailable: false }],
1125
+ request,
1126
+ )
1127
+ }
1128
+
1129
+ // An unreachable pane is suspended, not a failed request.
1130
+ if (state.ipc.status !== "active")
1131
+ return put(
1132
+ state,
1133
+ key,
1134
+ { ...suspend(attachment, "ipc"), addressFocus: noFocus(), strip: kept },
1135
+ [{ type: "reject-command", sessionKey: key, request, action: event.action, error: "browser.pane.unavailable", unavailable: true }],
1136
+ request,
1137
+ )
1138
+ const attempt = request + 1
1139
+
1140
+ return put(
1141
+ state,
1142
+ key,
1143
+ {
1144
+ ...attachment,
1145
+ phase: { status: "registering", attempt, attempts: 0 },
1146
+ embeds: {},
1147
+ failure: undefined,
1148
+ addressFocus: focus,
1149
+ strip,
1150
+ },
1151
+ [
1152
+ ...register(key, attempt, attachment.browser),
1153
+ { type: "send-command", sessionKey: key, attempt, request, action: event.action },
1154
+ ],
1155
+ attempt,
1156
+ )
1157
+ }
1158
+
1159
+ function commandFailed(
1160
+ state: Open,
1161
+ key: string,
1162
+ attachment: Attachment,
1163
+ event: Extract<Event, { type: "command.failed" }>,
1164
+ ): Transition {
1165
+ // A tab that never opened has no address field to focus.
1166
+ const focus =
1167
+ attachment.addressFocus.status === "opening" && attachment.addressFocus.request === event.request
1168
+ ? noFocus()
1169
+ : attachment.addressFocus
1170
+
1171
+ if (event.unavailable) {
1172
+ const phase = event.attempt === undefined ? undefined : current(attachment.phase, event.attempt)
1173
+
1174
+ if (phase) return put(state, key, suspend(attachment, "ipc"), stop(key, phase))
1175
+
1176
+ if (focus === attachment.addressFocus && attachment === state.sessions[key]) return { state, effects: [] }
1177
+
1178
+ return put(state, key, { ...attachment, addressFocus: focus })
1179
+ }
1180
+
1181
+ const replaced = attachment.phase.status === "blocked" && attachment.phase.reason === "replaced"
1182
+
1183
+ return put(state, key, {
1184
+ ...attachment,
1185
+ failure: { id: event.request, code: replaced ? "browser.pane.replaced" : event.error, action: event.action },
1186
+ addressFocus: focus,
1187
+ })
1188
+ }
1189
+
1190
+ function paneState(
1191
+ state: Open,
1192
+ key: string,
1193
+ attachment: Attachment,
1194
+ event: Extract<Event, { type: "pane.state" }>,
1195
+ ): Transition {
1196
+ const phase = current(attachment.phase, event.attempt)
1197
+
1198
+ if (!phase) return { state, effects: [] }
1199
+
1200
+ // RPC registration belongs to a Location. A cold project says nothing about the other projects on its server.
1201
+ if (event.error === "browser.pane.unsupported") {
1202
+ return put(state,key,{...attachment,phase:{status:"blocked",reason:"unsupported"},embeds:{}},stop(key,phase))
1203
+ }
1204
+
1205
+ if (event.error === "browser.pane.replaced" || event.error === "browser.pane.missing") {
1206
+ const replaced = event.error === "browser.pane.replaced"
1207
+
1208
+ return put(
1209
+ state,
1210
+ key,
1211
+ {
1212
+ ...attachment,
1213
+ phase: { status: "blocked", reason: replaced ? "replaced" : "missing" },
1214
+ browser: null,
1215
+ embeds: {},
1216
+ failure: replaced ? { id: state.issued + 1, code: "browser.pane.replaced", action: undefined } : undefined,
1217
+ strip: { ...noStrip(), located: attachment.strip.located },
1218
+ addressFocus: noFocus(),
1219
+ },
1220
+ stop(key, phase),
1221
+ replaced ? state.issued + 1 : undefined,
1222
+ )
1223
+ }
1224
+
1225
+ // Main closed the binding, or never took it. Keep the tabs and register again with backoff.
1226
+ if (event.error === "browser.pane.registration.closed")
1227
+ return backoff(state, key, event.state ? { ...attachment, browser: event.state } : attachment, phase)
1228
+
1229
+ // Idle eviction has no retry timer: a user or Session execution wakes it on demand.
1230
+ if (event.error === "browser.pane.suspended") {
1231
+ const browser = event.state ?? attachment.browser
1232
+ const mirrored = event.state ? mirror(key, attachment.strip, browser, false, undefined, event.stored) : undefined
1233
+
1234
+ return put(state, key, { ...suspend(attachment, "idle", browser), strip: mirrored?.strip ?? attachment.strip }, [
1235
+ ...stop(key, phase),
1236
+ ...(mirrored?.effects ?? []),
1237
+ ])
1238
+ }
1239
+
1240
+ // What the person did to saved tabs before this inventory named them reaches the desktop now, as their commands:
1241
+ // a tab they closed closes there and is not mirrored back, and the one they selected comes to the front.
1242
+ const strip = attachment.strip
1243
+ const dismissed = event.state?.tabs.flatMap((tab) => (strip.dismissed.includes(tab.id) ? [tab.id] : [])) ?? []
1244
+ const selected = event.state?.tabs.find((tab) => tab.id === strip.selected)?.id
1245
+
1246
+ const early: Browser.Action[] = [
1247
+ ...dismissed.map((tabID) => ({ type: "tabs.close" as const, tabID })),
1248
+ ...(selected && selected !== event.state?.focusedTabID ? [{ type: "tabs.focus" as const, tabID: selected }] : []),
1249
+ ]
1250
+
1251
+ // An inventory that repeats the error it reported last is the same failure, not a new one to read again.
1252
+ const repeated = attachment.failure?.action === undefined && attachment.failure?.code === event.error
1253
+
1254
+ const failure =
1255
+ event.error === undefined || repeated
1256
+ ? moved(attachment, event.state) ? undefined : attachment.failure
1257
+ : { id: state.issued + 1, code: event.error, action: undefined }
1258
+
1259
+ // A tab the desktop had and has no more closed: a show request kept for it has nothing to show.
1260
+ const closed =
1261
+ !!attachment.held &&
1262
+ !!attachment.browser?.tabs.some((tab) => tab.id === attachment.held?.tabID) &&
1263
+ !event.state?.tabs.some((tab) => tab.id === attachment.held?.tabID)
1264
+
1265
+ const issued = failure === attachment.failure ? state.issued : state.issued + 1
1266
+
1267
+ const mirrored = mirror(
1268
+ key,
1269
+ {
1270
+ ...strip,
1271
+ mirrored: [...strip.mirrored, ...dismissed],
1272
+ // The closes sent below, each under the request it goes out with.
1273
+ closing: [...strip.closing, ...dismissed.map((tabID, index) => ({ tabID, request: issued + index + 1 }))],
1274
+ dismissed: [],
1275
+ selected: undefined,
1276
+ },
1277
+ event.state,
1278
+ true,
1279
+ event.placed,
1280
+ event.stored,
1281
+ )
1282
+
1283
+ // The strip gets the inventory's tabs first, so a kept request selects a tab the strip already has.
1284
+ return settle(
1285
+ put(
1286
+ state,
1287
+ key,
1288
+ {
1289
+ ...attachment,
1290
+ held: closed ? undefined : attachment.held,
1291
+ phase: { status: "ready", attempt: phase.attempt },
1292
+ browser: event.state,
1293
+ unseen: attachment.unseen.filter(id => event.state?.tabs.some(tab => tab.id === id)),
1294
+ unnamed: sameIDs(attachment.unnamed, event.unnamed ?? []) ? attachment.unnamed : (event.unnamed ?? []),
1295
+ failure,
1296
+ strip: mirrored.strip,
1297
+ addressFocus: follow(attachment.addressFocus, event.state),
1298
+ },
1299
+ [
1300
+ ...(phase.status === "registering" ? [{ type: "cancel-register-timeout" as const, sessionKey: key }] : []),
1301
+ // The saved tabs follow the inventory before the strip does, so a tab the strip drops for it is forgotten by
1302
+ // then, not offered as one the person closed.
1303
+ ...(event.state ? [{ type: "record-history" as const, sessionKey: key }] : []),
1304
+ ...mirrored.effects,
1305
+ ...early.map((action, index) => ({
1306
+ type: "send-command" as const,
1307
+ sessionKey: key,
1308
+ attempt: phase.attempt,
1309
+ request: issued + index + 1,
1310
+ action,
1311
+ })),
1312
+ ],
1313
+ issued + early.length,
1314
+ ),
1315
+ key,
1316
+ )
1317
+ }
1318
+
1319
+ // A failed command names a tab's page. Once that tab shows another document, or is gone, the failure is about a page
1320
+ // the person no longer sees.
1321
+ function moved(attachment: Attachment, browser: Browser.State | null) {
1322
+ const action = attachment.failure?.action
1323
+
1324
+ if (!action || !("tabID" in action)) return false
1325
+ const generation = (state: Browser.State | null) => state?.tabs.find((tab) => tab.id === action.tabID)?.generation
1326
+
1327
+ return generation(attachment.browser) !== generation(browser)
1328
+ }
1329
+
1330
+ function backoff(state: Open, key: string, attachment: Attachment, phase: Bound): Transition {
1331
+ const prior = phase.status === "registering" ? phase.attempts : 0
1332
+ const attempt = state.issued + 1
1333
+
1334
+ return put(
1335
+ state,
1336
+ key,
1337
+ {
1338
+ ...attachment,
1339
+ phase: { status: "backoff", attempt, attempts: prior + 1 },
1340
+ embeds: {},
1341
+ failure: undefined,
1342
+ addressFocus: noFocus(),
1343
+ },
1344
+ [
1345
+ ...stop(key, phase),
1346
+ {
1347
+ type: "schedule-retry",
1348
+ sessionKey: key,
1349
+ attempt,
1350
+ delayMs: Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** prior),
1351
+ },
1352
+ ],
1353
+ attempt,
1354
+ )
1355
+ }
1356
+
1357
+ // Mirrors an inventory into the strip: the tabs new since the last mirrored inventory are added, and the ones the
1358
+ // strip lost (`lost`), but not a tab the person just closed there, before the desktop confirms. Only a native
1359
+ // inventory prunes; suspended and restoring states keep the tabs they will restore. While the strip cannot be written,
1360
+ // the prune waits for the location.
1361
+ function mirror(
1362
+ key: string,
1363
+ strip: Strip,
1364
+ browser: Browser.State | null,
1365
+ native: boolean,
1366
+ placed?: Placed,
1367
+ stored?: readonly string[],
1368
+ ) {
1369
+ if (!browser) return { strip: { ...noStrip(), located: strip.located }, effects: [] }
1370
+ const ids = browser.tabs.map((tab) => tab.id)
1371
+
1372
+ if (!strip.located)
1373
+ return {
1374
+ strip: {
1375
+ ...strip,
1376
+ prune: strip.prune || native,
1377
+ focus: strip.focus && ids.includes(strip.focus) ? strip.focus : undefined,
1378
+ },
1379
+ effects: [],
1380
+ }
1381
+
1382
+ // A tab the inventory leaves out is closed: the desktop answered.
1383
+ const closing = strip.closing.every((item) => ids.includes(item.tabID))
1384
+ ? strip.closing
1385
+ : strip.closing.filter((item) => ids.includes(item.tabID))
1386
+
1387
+ return {
1388
+ strip: { ...strip, mirrored: ids, closing },
1389
+ effects: sync(key, ids, strip.mirrored, native, placed, lost({ ...strip, closing }, ids, stored)),
1390
+ }
1391
+ }
1392
+
1393
+ /**
1394
+ * The strip shows the desktop's inventory. Tabs the inventory had already and the strip no longer stores were dropped
1395
+ * by the host without the browser, as when it forgets the strips of sessions not used for long, or a session returns
1396
+ * in another directory: nobody closed them, so the strip gets them back. Only a tab the person closes there stays out.
1397
+ */
1398
+ function lost(strip: Strip, ids: readonly Browser.TabID[], stored: readonly string[] | undefined) {
1399
+ if (!stored) return []
1400
+
1401
+ return ids.filter(
1402
+ (id) => strip.mirrored.includes(id) && !stored.includes(id) && !strip.closing.some((item) => item.tabID === id),
1403
+ )
1404
+ }
1405
+
1406
+ function sync(
1407
+ key: string,
1408
+ ids: readonly Browser.TabID[],
1409
+ mirrored: readonly Browser.TabID[],
1410
+ prune: boolean,
1411
+ placed?: Placed,
1412
+ back: readonly Browser.TabID[] = [],
1413
+ ): MachineEffect[] {
1414
+ const open = ids.filter((id) => !mirrored.includes(id) || back.includes(id))
1415
+
1416
+ if (!prune && open.length === 0) return []
1417
+ const effect = { type: "sync-strip" as const, sessionKey: key, keep: prune ? ids : undefined, open }
1418
+
1419
+ const places = [
1420
+ // Only a tab this inventory adds is placed: one the strip has already stays where the person sees it.
1421
+ ...(placed && open.includes(placed.tabID) && !back.includes(placed.tabID) ? [placed] : []),
1422
+ // A tab the strip gets back stands where the desktop lists it, after the tab before it.
1423
+ ...back.flatMap((tabID) => {
1424
+ const after = ids[ids.indexOf(tabID) - 1]
1425
+
1426
+ return after ? [{ tabID, after }] : []
1427
+ }),
1428
+ ]
1429
+
1430
+ return [places.length > 0 ? { ...effect, placed: places } : effect]
1431
+ }
1432
+
1433
+ // The new tab a user's tabs.open added: blank, it takes the address focus; anything else ends the request. A ready tab
1434
+ // keeps it until it navigates or closes.
1435
+ function follow(focus: AddressFocus, browser: Browser.State | null): AddressFocus {
1436
+ if (focus.status === "none") return focus
1437
+ const tabs = browser?.tabs ?? []
1438
+
1439
+ if (focus.status === "ready") {
1440
+ const tab = tabs.find((item) => item.id === focus.tabID)
1441
+
1442
+ return tab && blank(tab) ? focus : noFocus()
1443
+ }
1444
+
1445
+ const added = tabs.filter((tab) => !focus.known.includes(tab.id))
1446
+
1447
+ if (added.length === 0) return focus.settled ? noFocus() : focus
1448
+ const opened = added.find(blank)
1449
+
1450
+ return opened ? { status: "ready", tabID: opened.id } : noFocus()
1451
+ }
1452
+
1453
+ function blank(tab: Browser.Tab) {
1454
+ return !tab.url || tab.url === "about:blank"
1455
+ }
1456
+
1457
+ function suspend(attachment: Attachment, reason: Extract<Phase,{status:"suspended"}>["reason"], browser = attachment.browser): Attachment {
1458
+ return {
1459
+ ...attachment,
1460
+ phase: { status: "suspended", reason },
1461
+ browser,
1462
+ embeds: {},
1463
+ failure: undefined,
1464
+ addressFocus: noFocus(),
1465
+ }
1466
+ }
1467
+
1468
+ function current(phase: Phase, attempt: number) {
1469
+ return (phase.status === "registering" || phase.status === "ready") && phase.attempt === attempt ? phase : undefined
1470
+ }
1471
+
1472
+ function register(key: string, attempt: number, browser: Browser.State | null): MachineEffect[] {
1473
+ return [
1474
+ { type: "open-registration", sessionKey: key, attempt, restore: browser ?? undefined },
1475
+ { type: "schedule-register-timeout", sessionKey: key, attempt, delayMs: REGISTER_TIMEOUT_MS },
1476
+ ]
1477
+ }
1478
+
1479
+ function stop(key: string, phase: Phase): MachineEffect[] {
1480
+ if (phase.status === "registering")
1481
+ return [
1482
+ { type: "cancel-register-timeout", sessionKey: key },
1483
+ { type: "close-registration", sessionKey: key, attempt: phase.attempt },
1484
+ ]
1485
+
1486
+ if (phase.status === "ready") return [{ type: "close-registration", sessionKey: key, attempt: phase.attempt }]
1487
+
1488
+ if (phase.status === "backoff") return [{ type: "cancel-retry", sessionKey: key }]
1489
+
1490
+ return []
1491
+ }
1492
+
1493
+ function detach(key: string): MachineEffect {
1494
+ return { type: "detach", sessionKey: key }
1495
+ }
1496
+
1497
+ function put(
1498
+ state: Open,
1499
+ key: string,
1500
+ attachment: Attachment,
1501
+ effects: readonly MachineEffect[] = [],
1502
+ issued = state.issued,
1503
+ ) {
1504
+ return { state: { ...state, issued, sessions: { ...state.sessions, [key]: attachment } }, effects }
1505
+ }
1506
+
1507
+ function listed(sessions: Open["sessions"]) {
1508
+ return Object.entries(sessions).filter((entry): entry is [string, Attachment] => entry[1] !== undefined)
1509
+ }
1510
+
1511
+ function sameIDs(before: readonly Browser.TabID[], after: readonly Browser.TabID[]) {
1512
+ return before.length === after.length && before.every((id, index) => id === after[index])
1513
+ }
1514
+
1515
+ // The desktop answered the close under `request`: the tab is gone, or stays, as a page that asks to be left may.
1516
+ function closeAnswered(attachment: Attachment, request: number): Attachment {
1517
+ const strip = attachment.strip
1518
+
1519
+ if (!strip.closing.some((item) => item.request === request)) return attachment
1520
+
1521
+ return { ...attachment, strip: { ...strip, closing: strip.closing.filter((item) => item.request !== request) } }
1522
+ }