@intentic/sandbox-contract 1.394.0 → 1.395.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +20 -2
  2. package/dist/app-routes/app-pages.d.ts +97 -0
  3. package/dist/app-routes/app-pages.d.ts.map +1 -0
  4. package/dist/app-routes/app-pages.js +71 -0
  5. package/dist/app-routes/app-pages.js.map +1 -0
  6. package/dist/app-routes/index.d.ts +5 -0
  7. package/dist/app-routes/index.d.ts.map +1 -0
  8. package/dist/app-routes/index.js +5 -0
  9. package/dist/app-routes/index.js.map +1 -0
  10. package/dist/app-routes/legacy.d.ts +10 -0
  11. package/dist/app-routes/legacy.d.ts.map +1 -0
  12. package/dist/app-routes/legacy.js +92 -0
  13. package/dist/app-routes/legacy.js.map +1 -0
  14. package/dist/app-routes/paths.d.ts +38 -0
  15. package/dist/app-routes/paths.d.ts.map +1 -0
  16. package/dist/app-routes/paths.js +89 -0
  17. package/dist/app-routes/paths.js.map +1 -0
  18. package/dist/app-routes/patterns.d.ts +5 -0
  19. package/dist/app-routes/patterns.d.ts.map +1 -0
  20. package/dist/app-routes/patterns.js +94 -0
  21. package/dist/app-routes/patterns.js.map +1 -0
  22. package/dist/chores/stack.d.ts.map +1 -1
  23. package/dist/chores/stack.js +13 -2
  24. package/dist/chores/stack.js.map +1 -1
  25. package/dist/contracts/agent.contract.d.ts +115 -0
  26. package/dist/contracts/agent.contract.d.ts.map +1 -1
  27. package/dist/contracts/agents.contract.d.ts +1300 -11
  28. package/dist/contracts/agents.contract.d.ts.map +1 -1
  29. package/dist/contracts/agents.contract.js +11 -1
  30. package/dist/contracts/agents.contract.js.map +1 -1
  31. package/dist/contracts/capabilities.contract.d.ts +8 -0
  32. package/dist/contracts/capabilities.contract.d.ts.map +1 -1
  33. package/dist/contracts/endpoints.contract.d.ts +45 -0
  34. package/dist/contracts/endpoints.contract.d.ts.map +1 -1
  35. package/dist/contracts/endpoints.contract.js +9 -0
  36. package/dist/contracts/endpoints.contract.js.map +1 -1
  37. package/dist/contracts/git.contract.d.ts +5 -0
  38. package/dist/contracts/git.contract.d.ts.map +1 -1
  39. package/dist/contracts/org.contract.d.ts +8 -0
  40. package/dist/contracts/org.contract.d.ts.map +1 -1
  41. package/dist/contracts/runner.contract.d.ts +87 -0
  42. package/dist/contracts/runner.contract.d.ts.map +1 -1
  43. package/dist/contracts/seal.contract.d.ts +2760 -0
  44. package/dist/contracts/seal.contract.d.ts.map +1 -0
  45. package/dist/contracts/seal.contract.js +95 -0
  46. package/dist/contracts/seal.contract.js.map +1 -0
  47. package/dist/contracts/sessions.contract.d.ts +16 -0
  48. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  49. package/dist/contracts/settings.contract.d.ts +89 -2
  50. package/dist/contracts/settings.contract.d.ts.map +1 -1
  51. package/dist/contracts/settings.contract.js +21 -3
  52. package/dist/contracts/settings.contract.js.map +1 -1
  53. package/dist/contracts/system.contract.d.ts +419 -62
  54. package/dist/contracts/system.contract.d.ts.map +1 -1
  55. package/dist/contracts/webext.contract.d.ts +4 -0
  56. package/dist/contracts/webext.contract.d.ts.map +1 -1
  57. package/dist/contracts/workspace.contract.d.ts +6 -0
  58. package/dist/contracts/workspace.contract.d.ts.map +1 -1
  59. package/dist/contracts/workspace.contract.js +11 -1
  60. package/dist/contracts/workspace.contract.js.map +1 -1
  61. package/dist/events/agent-events.d.ts +80 -1
  62. package/dist/events/agent-events.d.ts.map +1 -1
  63. package/dist/events/agent-events.js +16 -0
  64. package/dist/events/agent-events.js.map +1 -1
  65. package/dist/events/agent-transcript.d.ts +16 -0
  66. package/dist/events/agent-transcript.d.ts.map +1 -1
  67. package/dist/events/requests.d.ts +2 -0
  68. package/dist/events/requests.d.ts.map +1 -1
  69. package/dist/events/requests.js +4 -0
  70. package/dist/events/requests.js.map +1 -1
  71. package/dist/events/system-events.d.ts +292 -62
  72. package/dist/events/system-events.d.ts.map +1 -1
  73. package/dist/events/system-events.js +3 -0
  74. package/dist/events/system-events.js.map +1 -1
  75. package/dist/events/transcript.d.ts +96 -0
  76. package/dist/events/transcript.d.ts.map +1 -1
  77. package/dist/events/transcript.js +7 -1
  78. package/dist/events/transcript.js.map +1 -1
  79. package/dist/ids/row-ids.d.ts.map +1 -1
  80. package/dist/ids/row-ids.js +7 -2
  81. package/dist/ids/row-ids.js.map +1 -1
  82. package/dist/index.d.ts +107 -34346
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +7 -3
  85. package/dist/index.js.map +1 -1
  86. package/dist/models/model-roles.d.ts +8 -0
  87. package/dist/models/model-roles.d.ts.map +1 -1
  88. package/dist/models/model-roles.js +8 -0
  89. package/dist/models/model-roles.js.map +1 -1
  90. package/dist/policy/org-locks.d.ts +1 -1
  91. package/dist/policy/org-locks.d.ts.map +1 -1
  92. package/dist/policy/org-locks.js +9 -1
  93. package/dist/policy/org-locks.js.map +1 -1
  94. package/dist/policy/request-status.d.ts.map +1 -1
  95. package/dist/policy/request-status.js +26 -10
  96. package/dist/policy/request-status.js.map +1 -1
  97. package/dist/protocol/raw/raw-json-routes.d.ts +6 -0
  98. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  99. package/dist/protocol/routes.d.ts +6 -0
  100. package/dist/protocol/routes.d.ts.map +1 -1
  101. package/dist/protocol/routes.js +64 -8
  102. package/dist/protocol/routes.js.map +1 -1
  103. package/dist/protocol/sse.d.ts.map +1 -1
  104. package/dist/protocol/sse.js +5 -1
  105. package/dist/protocol/sse.js.map +1 -1
  106. package/dist/schemas/agent-land.d.ts +78 -0
  107. package/dist/schemas/agent-land.d.ts.map +1 -0
  108. package/dist/schemas/agent-land.js +47 -0
  109. package/dist/schemas/agent-land.js.map +1 -0
  110. package/dist/schemas/agent.d.ts +4 -0
  111. package/dist/schemas/agent.d.ts.map +1 -1
  112. package/dist/schemas/agent.js +1 -0
  113. package/dist/schemas/agent.js.map +1 -1
  114. package/dist/schemas/agents-list.d.ts +130 -0
  115. package/dist/schemas/agents-list.d.ts.map +1 -1
  116. package/dist/schemas/agents.d.ts +196 -76
  117. package/dist/schemas/agents.d.ts.map +1 -1
  118. package/dist/schemas/agents.js +5 -46
  119. package/dist/schemas/agents.js.map +1 -1
  120. package/dist/schemas/capabilities.d.ts +4 -0
  121. package/dist/schemas/capabilities.d.ts.map +1 -1
  122. package/dist/schemas/commit-attribution.d.ts +41 -0
  123. package/dist/schemas/commit-attribution.d.ts.map +1 -0
  124. package/dist/schemas/commit-attribution.js +16 -0
  125. package/dist/schemas/commit-attribution.js.map +1 -0
  126. package/dist/schemas/composer-drafts.d.ts +19 -0
  127. package/dist/schemas/composer-drafts.d.ts.map +1 -1
  128. package/dist/schemas/composer-drafts.js +10 -0
  129. package/dist/schemas/composer-drafts.js.map +1 -1
  130. package/dist/schemas/environment.d.ts +12 -0
  131. package/dist/schemas/environment.d.ts.map +1 -1
  132. package/dist/schemas/environment.js +1 -0
  133. package/dist/schemas/environment.js.map +1 -1
  134. package/dist/schemas/git/git-history.d.ts +10 -0
  135. package/dist/schemas/git/git-history.d.ts.map +1 -1
  136. package/dist/schemas/git/git-history.js +8 -0
  137. package/dist/schemas/git/git-history.js.map +1 -1
  138. package/dist/schemas/gpu-settings.d.ts +15 -0
  139. package/dist/schemas/gpu-settings.d.ts.map +1 -0
  140. package/dist/schemas/gpu-settings.js +18 -0
  141. package/dist/schemas/gpu-settings.js.map +1 -0
  142. package/dist/schemas/night-hours.d.ts +31 -0
  143. package/dist/schemas/night-hours.d.ts.map +1 -0
  144. package/dist/schemas/night-hours.js +33 -0
  145. package/dist/schemas/night-hours.js.map +1 -0
  146. package/dist/schemas/organisation.d.ts +33 -0
  147. package/dist/schemas/organisation.d.ts.map +1 -1
  148. package/dist/schemas/organisation.js +9 -0
  149. package/dist/schemas/organisation.js.map +1 -1
  150. package/dist/schemas/privacy.d.ts +1 -0
  151. package/dist/schemas/privacy.d.ts.map +1 -1
  152. package/dist/schemas/privacy.js +1 -0
  153. package/dist/schemas/privacy.js.map +1 -1
  154. package/dist/schemas/providers/plan-limits.d.ts +16 -0
  155. package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
  156. package/dist/schemas/providers/plan-limits.js +3 -0
  157. package/dist/schemas/providers/plan-limits.js.map +1 -1
  158. package/dist/schemas/sandbox-mode.d.ts +20 -0
  159. package/dist/schemas/sandbox-mode.d.ts.map +1 -0
  160. package/dist/schemas/sandbox-mode.js +54 -0
  161. package/dist/schemas/sandbox-mode.js.map +1 -0
  162. package/dist/schemas/seal-proof.d.ts +20 -0
  163. package/dist/schemas/seal-proof.d.ts.map +1 -0
  164. package/dist/schemas/seal-proof.js +8 -0
  165. package/dist/schemas/seal-proof.js.map +1 -0
  166. package/dist/schemas/seal.d.ts +235 -0
  167. package/dist/schemas/seal.d.ts.map +1 -0
  168. package/dist/schemas/seal.js +97 -0
  169. package/dist/schemas/seal.js.map +1 -0
  170. package/dist/schemas/settings-experiments.d.ts.map +1 -1
  171. package/dist/schemas/settings-experiments.js +1 -1
  172. package/dist/schemas/settings-experiments.js.map +1 -1
  173. package/dist/schemas/settings-history.d.ts +2 -2
  174. package/dist/schemas/settings.d.ts +59 -15
  175. package/dist/schemas/settings.d.ts.map +1 -1
  176. package/dist/schemas/settings.js +23 -27
  177. package/dist/schemas/settings.js.map +1 -1
  178. package/dist/schemas/webext.d.ts +9 -0
  179. package/dist/schemas/webext.d.ts.map +1 -1
  180. package/dist/schemas/webext.js +2 -0
  181. package/dist/schemas/webext.js.map +1 -1
  182. package/dist/schemas/workspace/workspace-tree.d.ts +8 -0
  183. package/dist/schemas/workspace/workspace-tree.d.ts.map +1 -1
  184. package/dist/schemas/workspace/workspace-tree.js +16 -0
  185. package/dist/schemas/workspace/workspace-tree.js.map +1 -1
  186. package/dist/state/definition.d.ts +48 -8
  187. package/dist/state/definition.d.ts.map +1 -1
  188. package/dist/text/mentions.d.ts.map +1 -1
  189. package/dist/text/mentions.js +8 -1
  190. package/dist/text/mentions.js.map +1 -1
  191. package/dist/text/transcript-fold.d.ts.map +1 -1
  192. package/dist/text/transcript-fold.js +1 -0
  193. package/dist/text/transcript-fold.js.map +1 -1
  194. package/package.json +16 -5
  195. package/src/app-routes/app-pages.ts +148 -0
  196. package/src/app-routes/app-routes.test.ts +183 -0
  197. package/src/app-routes/index.ts +6 -0
  198. package/src/app-routes/legacy.ts +144 -0
  199. package/src/app-routes/paths.ts +160 -0
  200. package/src/app-routes/patterns.ts +145 -0
  201. package/src/chores/stack.ts +14 -2
  202. package/src/contracts/agents.contract.ts +15 -1
  203. package/src/contracts/endpoints.contract.ts +12 -0
  204. package/src/contracts/seal.contract.ts +117 -0
  205. package/src/contracts/settings.contract.ts +30 -6
  206. package/src/contracts/workspace.contract.ts +16 -0
  207. package/src/events/agent-events.ts +20 -0
  208. package/src/events/requests.ts +8 -0
  209. package/src/events/system-events.ts +39 -4
  210. package/src/events/transcript.ts +9 -1
  211. package/src/ids/row-ids.test.ts +31 -0
  212. package/src/ids/row-ids.ts +10 -2
  213. package/src/index.ts +65 -5
  214. package/src/models/model-roles.ts +10 -0
  215. package/src/policy/org-locks.ts +9 -1
  216. package/src/policy/request-status.ts +38 -10
  217. package/src/protocol/routes.test.ts +75 -2
  218. package/src/protocol/routes.ts +119 -11
  219. package/src/protocol/sse.ts +6 -1
  220. package/src/schemas/agent-land.ts +98 -0
  221. package/src/schemas/agent.ts +3 -0
  222. package/src/schemas/agents.ts +6 -94
  223. package/src/schemas/capabilities.ts +1 -1
  224. package/src/schemas/commit-attribution.ts +38 -0
  225. package/src/schemas/composer-drafts.ts +17 -0
  226. package/src/schemas/environment.ts +4 -0
  227. package/src/schemas/git/git-history.ts +10 -0
  228. package/src/schemas/gpu-settings.ts +31 -0
  229. package/src/schemas/night-hours.test.ts +54 -0
  230. package/src/schemas/night-hours.ts +70 -0
  231. package/src/schemas/organisation.ts +15 -0
  232. package/src/schemas/privacy.test.ts +8 -1
  233. package/src/schemas/privacy.ts +10 -1
  234. package/src/schemas/providers/plan-limits.ts +5 -0
  235. package/src/schemas/sandbox-mode.test.ts +68 -0
  236. package/src/schemas/sandbox-mode.ts +93 -0
  237. package/src/schemas/seal-proof.ts +12 -0
  238. package/src/schemas/seal.ts +175 -0
  239. package/src/schemas/settings-experiments.ts +3 -1
  240. package/src/schemas/settings.test.ts +7 -0
  241. package/src/schemas/settings.ts +60 -48
  242. package/src/schemas/webext.ts +8 -0
  243. package/src/schemas/workspace/workspace-tree.ts +23 -0
  244. package/src/state/daemon-floor.test.ts +1 -0
  245. package/src/text/mentions.ts +10 -1
  246. package/src/text/pages.test.ts +1 -0
  247. package/src/text/transcript-fold.ts +1 -0
@@ -0,0 +1,148 @@
1
+ // THE APP'S PAGES, NAMED ONCE (2026-11-04). Every address the editor answers is spelled in this file and nowhere else:
2
+ // the editor's router builds its route table from it, and every link (the editor's own, an extension's, the daemon's
3
+ // push messages, the desktop and phone apps' hand-offs) is made by a constructor below, so a page renamed or moved is
4
+ // one edit here and a type error everywhere a link no longer fits. `_tools/checks/route-literals.mjs` fails an address
5
+ // typed by hand anywhere else, reading the patterns below to know what counts as one.
6
+ //
7
+ // A page of a sandbox is shown in one of two frames (paths.ts): inside the sandbox, `/s/<sandbox>/<page>`, or in Home's,
8
+ // `/home/<sandbox>/<page>`, where the rail lists every sandbox. Its pattern is the same in both. A page of the
9
+ // account's own (its settings, its deleted sandboxes) is shown in either frame too, and names no sandbox in Home's.
10
+
11
+ /** The pages of one sandbox, by name: the pattern of each below the frame's `/s/<sandbox>` or `/home/<sandbox>`. */
12
+ export const SANDBOX_PAGES = {
13
+ /** The chat surface, expanded to the whole view; on a phone, the open conversation's own screen. */
14
+ chat: `chat`,
15
+ /** The board of every agent. */
16
+ agents: `agents`,
17
+ /** One agent: its conversation and its changes. */
18
+ agent: `agents/:id`,
19
+ /** One page an agent showed in its conversation, alone on the screen. */
20
+ agentPage: `agents/:id/pages/:page`,
21
+ /** The file tree and the open file, whose path is the rest of the address. */
22
+ workspace: `workspace/:path(.*)*`,
23
+ /** Everything live the sandbox shows (its browser windows, its apps, its desktop), the tab in front named. */
24
+ browsers: `browsers/:tab(.*)?`,
25
+ /** The machines the sandbox reaches. */
26
+ devices: `devices`,
27
+ /** The catalog of what the sandbox can connect to, one entry open. */
28
+ capabilities: `capabilities/:entry?`,
29
+ /** An extension's own view, one of its activations named. */
30
+ extension: `ext/:ext/:key?`,
31
+ /** The sandbox's own settings, one section open. */
32
+ sandboxSettings: `settings/:tab?`,
33
+ /** The terminal as a page: a phone's. */
34
+ terminal: `terminal`,
35
+ /** The rail's contents as a page: a phone's. */
36
+ menu: `menu`,
37
+ } as const;
38
+
39
+ /** The account's own pages, shown in whichever frame the reader opened them from. */
40
+ export const ACCOUNT_PAGES = {
41
+ /** The account's settings, one section open. */
42
+ account: `account/:tab?`,
43
+ /** The sandboxes the account deleted, still restorable. */
44
+ deletedSandboxes: `deleted-sandboxes`,
45
+ } as const;
46
+
47
+ export type SandboxPageName = keyof typeof SANDBOX_PAGES;
48
+ export type AccountPageName = keyof typeof ACCOUNT_PAGES;
49
+ export type PageName = SandboxPageName | AccountPageName;
50
+
51
+ export const PAGE_PATTERNS = { ...SANDBOX_PAGES, ...ACCOUNT_PAGES } as const;
52
+
53
+ export const isSandboxPage = (name: PageName): name is SandboxPageName => Object.hasOwn(SANDBOX_PAGES, name);
54
+
55
+ /** A query as a link carries it: a key left undefined or empty is not written. */
56
+ export type LinkQuery = Readonly<Record<string, string | undefined>>;
57
+
58
+ /** What a link adds after the page: its query and the anchor it scrolls to (without `#`). */
59
+ export interface LinkExtras {
60
+ readonly query?: LinkQuery | undefined;
61
+ readonly hash?: string | undefined;
62
+ }
63
+
64
+ /**
65
+ * A page and the values that pick what it shows: what a link names, before a frame says where it is drawn. Made only by
66
+ * the constructors in `page`, so its parameters are always the ones its pattern names. No query is `{}`, no anchor ``.
67
+ */
68
+ export interface PageLink<Name extends PageName = PageName> {
69
+ readonly page: Name;
70
+ readonly params: Readonly<Record<string, string | undefined>>;
71
+ readonly query: LinkQuery;
72
+ /** The anchor it scrolls to, without its `#`. */
73
+ readonly hash: string;
74
+ }
75
+
76
+ const link = <Name extends PageName>(name: Name, params: PageLink[`params`], extras: LinkExtras = {}): PageLink<Name> => ({
77
+ page: name,
78
+ params,
79
+ query: extras.query ?? {},
80
+ hash: (extras.hash ?? ``).replace(/^#/, ``),
81
+ });
82
+
83
+ /** The constructors of every link, one per page, each taking what its page's pattern needs. */
84
+ export const page = {
85
+ chat: (extras?: LinkExtras) => link(`chat`, {}, extras),
86
+ agents: (extras?: LinkExtras) => link(`agents`, {}, extras),
87
+ agent: (id: string, extras?: LinkExtras) => link(`agent`, { id }, extras),
88
+ agentPage: (id: string, pageId: string, extras?: LinkExtras) => link(`agentPage`, { id, page: pageId }, extras),
89
+ /** A file or folder by its path in the workspace, or the workspace with nothing open. */
90
+ workspace: (path?: string, extras?: LinkExtras) => link(`workspace`, { path }, extras),
91
+ browsers: (tab?: string, extras?: LinkExtras) => link(`browsers`, { tab }, extras),
92
+ devices: (extras?: LinkExtras) => link(`devices`, {}, extras),
93
+ capabilities: (entry?: string, extras?: LinkExtras) => link(`capabilities`, { entry }, extras),
94
+ extension: (ext: string, key?: string, extras?: LinkExtras) => link(`extension`, { ext, key }, extras),
95
+ sandboxSettings: (tab?: string, extras?: LinkExtras) => link(`sandboxSettings`, { tab }, extras),
96
+ terminal: (extras?: LinkExtras) => link(`terminal`, {}, extras),
97
+ menu: (extras?: LinkExtras) => link(`menu`, {}, extras),
98
+ account: (tab?: string, extras?: LinkExtras) => link(`account`, { tab }, extras),
99
+ deletedSandboxes: (extras?: LinkExtras) => link(`deletedSandboxes`, {}, extras),
100
+ } as const;
101
+
102
+ /** The same link with other extras: its query merged over, its hash replaced when one is given. */
103
+ export const withExtras = <Name extends PageName>(base: PageLink<Name>, extras: LinkExtras): PageLink<Name> =>
104
+ link(base.page, base.params, { query: { ...base.query, ...extras.query }, hash: extras.hash ?? base.hash });
105
+
106
+ /**
107
+ * The pages that are no sandbox's: the way in (sign-in, setup, an invite), the recovery and outage screens, the pages
108
+ * the desktop app hands over, and the design kit a dev build serves. Each a pattern from the root.
109
+ */
110
+ export const TOP_PAGES = {
111
+ root: ``,
112
+ login: `login`,
113
+ loginConfirm: `login/confirm`,
114
+ setup: `setup`,
115
+ startHosted: `start/hosted`,
116
+ invite: `invite/:token`,
117
+ recover: `recover`,
118
+ open: `open`,
119
+ previewPass: `preview-pass`,
120
+ platformUnavailable: `platform-unavailable`,
121
+ desktopAuth: `desktop-auth`,
122
+ desktopAuthComplete: `desktop-auth/complete`,
123
+ kit: `kit`,
124
+ kitRepair: `kit/repair`,
125
+ } as const;
126
+
127
+ export type TopPageName = keyof typeof TOP_PAGES;
128
+
129
+ /** The panels a floating window holds, each a window of its own on one sandbox. */
130
+ export const FLOATING_PANELS = [`chat`, `terminal`, `browsers`] as const;
131
+ export type FloatingPanel = (typeof FLOATING_PANELS)[number];
132
+
133
+ /**
134
+ * A desktop window on a folder of this computer (the desktop app's local face) has a shell of its own with pages of its
135
+ * own, none of them a sandbox's: the folder's files, this computer's page and vault, the folder's way to a sandbox.
136
+ */
137
+ export const LOCAL_PAGES = {
138
+ files: `workspace/:path(.*)*`,
139
+ device: `device`,
140
+ passwords: `passwords`,
141
+ repair: `repair`,
142
+ sandboxSetup: `sandbox-setup`,
143
+ newSandbox: `sandbox-new`,
144
+ process: `process/:id`,
145
+ account: `account/:tab?`,
146
+ } as const;
147
+
148
+ export type LocalPageName = keyof typeof LOCAL_PAGES;
@@ -0,0 +1,183 @@
1
+ import { fillPattern, matchPattern } from "./patterns.js";
2
+ import { page, PAGE_PATTERNS, type PageLink, withExtras } from "./app-pages.js";
3
+ import { floatingPath, homePath, insidePath, localPath, parseAppPath, parseFloatingPath, topPath } from "./paths.js";
4
+ import { legacyPathOf, legacySandbox, legacyTarget } from "./legacy.js";
5
+
6
+ /* Every address the editor answers is made here and read back here, so these pin the scheme itself: what an address
7
+ says about its frame, its sandbox and its page, and what the addresses from before frames still mean. */
8
+
9
+ const SB = `3f2a9c1b4d5e`;
10
+
11
+ describe(`the grammar of a pattern`, () => {
12
+ it(`writes and reads a plain parameter, encoding what a segment cannot hold`, () => {
13
+ expect(fillPattern(`agents/:id`, { id: `a b/c` })).toBe(`agents/a%20b%2Fc`);
14
+ expect(matchPattern(`agents/:id`, `/agents/a%20b%2Fc`)).toEqual({ id: `a b/c` });
15
+ });
16
+
17
+ it(`keeps a file's slashes as slashes and drops an empty optional tail`, () => {
18
+ expect(fillPattern(`workspace/:path(.*)*`, { path: `src/a b.ts` })).toBe(`workspace/src/a%20b.ts`);
19
+ expect(fillPattern(`workspace/:path(.*)*`, {})).toBe(`workspace`);
20
+ expect(matchPattern(`workspace/:path(.*)*`, `workspace/src/a%20b.ts`)).toEqual({ path: `src/a b.ts` });
21
+ expect(matchPattern(`workspace/:path(.*)*`, `workspace`)).toEqual({});
22
+ });
23
+
24
+ it(`refuses to write a link that leaves out what its page needs`, () => {
25
+ expect(() => fillPattern(`agents/:id`, {})).toThrow(/:id/);
26
+ });
27
+
28
+ it(`reads only the values an alternation names`, () => {
29
+ expect(matchPattern(`floating/:panel(chat|terminal)`, `floating/chat`)).toEqual({ panel: `chat` });
30
+ expect(matchPattern(`floating/:panel(chat|terminal)`, `floating/files`)).toBeUndefined();
31
+ });
32
+ });
33
+
34
+ describe(`a link's address in each frame`, () => {
35
+ it(`puts a sandbox page inside its sandbox`, () => {
36
+ expect(insidePath(SB, page.agents())).toBe(`/s/${SB}/agents`);
37
+ expect(insidePath(SB, page.agent(`c1`, { query: { view: `changes` } }))).toBe(`/s/${SB}/agents/c1?view=changes`);
38
+ expect(insidePath(SB, page.workspace(`src/main.ts`))).toBe(`/s/${SB}/workspace/src/main.ts`);
39
+ expect(insidePath(SB, page.sandboxSettings(`agent`, { query: { section: `tools` }, hash: `#voice` }))).toBe(
40
+ `/s/${SB}/settings/agent?section=tools#voice`,
41
+ );
42
+ expect(insidePath(SB)).toBe(`/s/${SB}`);
43
+ });
44
+
45
+ it(`puts the same page in Home's frame under the same relative path`, () => {
46
+ expect(homePath(SB, page.agents())).toBe(`/home/${SB}/agents`);
47
+ expect(homePath(SB)).toBe(`/home/${SB}`);
48
+ expect(homePath()).toBe(`/home`);
49
+ });
50
+
51
+ it(`draws the account's pages in either frame, naming a sandbox only inside one`, () => {
52
+ expect(homePath(SB, page.account(`appearance`))).toBe(`/home/account/appearance`);
53
+ expect(homePath(undefined, page.deletedSandboxes())).toBe(`/home/deleted-sandboxes`);
54
+ expect(insidePath(SB, page.account(`appearance`))).toBe(`/s/${SB}/account/appearance`);
55
+ });
56
+
57
+ it(`will not draw a sandbox's page in Home's frame without its sandbox`, () => {
58
+ expect(() => homePath(undefined, page.agents())).toThrow(/sandbox/);
59
+ });
60
+
61
+ it(`leaves out a query key with no value`, () => {
62
+ expect(insidePath(SB, page.agents({ query: { focus: undefined, mine: `` } }))).toBe(`/s/${SB}/agents`);
63
+ });
64
+
65
+ it(`merges extras over a link`, () => {
66
+ const merged = withExtras(page.agents({ query: { focus: `a` } }), { query: { view: `x` }, hash: `top` });
67
+ expect(insidePath(SB, merged)).toBe(`/s/${SB}/agents?focus=a&view=x#top`);
68
+ });
69
+
70
+ it(`addresses the pages that are no sandbox's, and a floating window`, () => {
71
+ expect(topPath(`login`, {}, { returnTo: `/s/${SB}/agents` })).toBe(`/login?returnTo=%2Fs%2F${SB}%2Fagents`);
72
+ expect(topPath(`invite`, { token: `t1` })).toBe(`/invite/t1`);
73
+ expect(topPath(`root`)).toBe(`/`);
74
+ expect(floatingPath(SB, `chat`)).toBe(`/s/${SB}/floating/chat`);
75
+ expect(localPath(`account`, { tab: `data` })).toBe(`/account/data`);
76
+ });
77
+ });
78
+
79
+ describe(`reading an address back`, () => {
80
+ const roundTrips: readonly PageLink[] = [
81
+ page.chat(),
82
+ page.agents(),
83
+ page.agent(`c1`),
84
+ page.agentPage(`c1`, `p9`),
85
+ page.workspace(),
86
+ page.workspace(`docs/a b.md`),
87
+ page.browsers(),
88
+ page.browsers(`app:shop/web`),
89
+ page.devices(),
90
+ page.capabilities(),
91
+ page.capabilities(`github`),
92
+ page.extension(`pipelines`),
93
+ page.extension(`e-urzad`, `office-ed`),
94
+ page.sandboxSettings(),
95
+ page.sandboxSettings(`models`),
96
+ page.terminal(),
97
+ page.menu(),
98
+ ];
99
+
100
+ it.each(roundTrips.map((link) => [link.page, link] as const))(`reads %s back from both frames`, (_name, link) => {
101
+ const params = Object.fromEntries(Object.entries(link.params).filter((entry): entry is [string, string] => entry[1] !== undefined));
102
+ expect(parseAppPath(insidePath(SB, link))).toEqual({ frame: { kind: `inside`, sandbox: SB }, page: { name: link.page, params } });
103
+ expect(parseAppPath(homePath(SB, link))).toEqual({ frame: { kind: `home`, sandbox: SB }, page: { name: link.page, params } });
104
+ });
105
+
106
+ it(`reads the frames with no page, and the account's pages in Home's frame`, () => {
107
+ expect(parseAppPath(`/s/${SB}`)).toEqual({ frame: { kind: `inside`, sandbox: SB } });
108
+ expect(parseAppPath(`/home/${SB}?x=1`)).toEqual({ frame: { kind: `home`, sandbox: SB } });
109
+ expect(parseAppPath(`/home`)).toEqual({ frame: { kind: `home` } });
110
+ expect(parseAppPath(`/home/account/data#voice`)).toEqual({ frame: { kind: `home` }, page: { name: `account`, params: { tab: `data` } } });
111
+ });
112
+
113
+ it(`reads nothing of an address that is no shell page's`, () => {
114
+ expect(parseAppPath(`/login`)).toBeUndefined();
115
+ expect(parseAppPath(`/agents`)).toBeUndefined();
116
+ expect(parseAppPath(`/s/${SB}/nowhere`)).toBeUndefined();
117
+ expect(parseAppPath(`/s/${SB}/floating/chat`)).toBeUndefined();
118
+ expect(parseFloatingPath(`/s/${SB}/floating/chat`)).toEqual({ sandbox: SB, panel: `chat` });
119
+ expect(parseFloatingPath(`/s/${SB}/floating/files`)).toBeUndefined();
120
+ });
121
+
122
+ it(`has one pattern per page, none a prefix of a frame's own segment`, () => {
123
+ for (const pattern of Object.values(PAGE_PATTERNS)) {
124
+ expect(pattern.startsWith(`/`)).toBe(false);
125
+ expect(pattern.split(`/`)[0]).not.toBe(`floating`);
126
+ }
127
+ });
128
+ });
129
+
130
+ describe(`the addresses from before frames`, () => {
131
+ it.each([
132
+ [`/agents`, `inside`, `/s/${SB}/agents`],
133
+ [`/agents/c1?view=changes`, `inside`, `/s/${SB}/agents/c1?view=changes`],
134
+ [`/agents/c1/pages/p9`, `inside`, `/s/${SB}/agents/c1/pages/p9`],
135
+ [`/needs?focus=c1`, `inside`, `/s/${SB}/agents?focus=c1`],
136
+ [`/chat`, `inside`, `/s/${SB}/chat`],
137
+ [`/workspace/src/a.ts`, `inside`, `/s/${SB}/workspace/src/a.ts`],
138
+ [`/browsers/app:shop/web`, `inside`, `/s/${SB}/browsers/app:shop/web`],
139
+ [`/desktop`, `inside`, `/s/${SB}/browsers/desktop`],
140
+ [`/preview?target=shop`, `inside`, `/s/${SB}/browsers/preview:shop`],
141
+ [`/devices`, `inside`, `/s/${SB}/devices`],
142
+ [`/sandbox/devices?machine=m1`, `inside`, `/s/${SB}/devices?machine=m1`],
143
+ [`/capabilities/github?edit=i1`, `inside`, `/s/${SB}/capabilities/github?edit=i1`],
144
+ [`/connect?provider=claude#x`, `inside`, `/s/${SB}/settings/models?provider=claude#x`],
145
+ [`/ext/e-urzad/office-ed`, `inside`, `/s/${SB}/ext/e-urzad/office-ed`],
146
+ [`/sandbox`, `inside`, `/s/${SB}/settings`],
147
+ [`/sandbox/models`, `inside`, `/s/${SB}/settings/models`],
148
+ [`/sandbox/audit`, `inside`, `/s/${SB}/settings/activity?section=audit`],
149
+ [`/sandbox/audit?section=keeping`, `inside`, `/s/${SB}/settings/retention`],
150
+ [`/sandbox/areas`, `inside`, `/s/${SB}/settings/access?section=areas`],
151
+ [`/terminal`, `inside`, `/s/${SB}/terminal`],
152
+ [`/menu`, `inside`, `/s/${SB}/menu`],
153
+ [`/settings/appearance`, `home`, `/home/account/appearance`],
154
+ [`/settings`, `home`, `/home/account`],
155
+ [`/deleted-sandboxes`, `home`, `/home/deleted-sandboxes`],
156
+ [`/sandbox/deleted`, `home`, `/home/deleted-sandboxes`],
157
+ ] as const)(`%s means its page, %s`, (old, frame, now) => {
158
+ const target = legacyTarget(old);
159
+ expect(target?.frame).toBe(frame);
160
+ if (target !== undefined) {
161
+ expect(target.frame === `inside` ? insidePath(SB, target.link) : homePath(SB, target.link)).toBe(now);
162
+ }
163
+ });
164
+
165
+ it(`takes the sandbox an old link named out of the page's query, for the reader to read`, () => {
166
+ expect(legacySandbox(`/agents/c1?sandbox=${SB}&view=changes`)).toBe(SB);
167
+ expect(legacyTarget(`/agents/c1?sandbox=${SB}&view=changes`)?.link.query).toEqual({ view: `changes` });
168
+ expect(legacySandbox(`/agents`)).toBeUndefined();
169
+ });
170
+
171
+ it(`is no address of today's scheme or a top page`, () => {
172
+ expect(legacyTarget(`/s/${SB}/agents`)).toBeUndefined();
173
+ expect(legacyTarget(`/home`)).toBeUndefined();
174
+ expect(legacyTarget(`/login`)).toBeUndefined();
175
+ });
176
+
177
+ it(`writes a link back in the old form, for an app that reads that form`, () => {
178
+ expect(legacyPathOf(page.agent(`c1`), SB)).toBe(`/agents/c1?sandbox=${SB}`);
179
+ expect(legacyPathOf(page.agentPage(`c1`, `p9`))).toBe(`/agents/c1/pages/p9`);
180
+ expect(legacyPathOf(page.agent(`c1`, { query: { view: `changes` } }), SB)).toBe(`/agents/c1?view=changes&sandbox=${SB}`);
181
+ expect(legacyPathOf(page.menu())).toBe(`/menu`);
182
+ });
183
+ });
@@ -0,0 +1,6 @@
1
+ // The app's addresses: the pages it has (app-pages.ts), where each is drawn and the address that says so (paths.ts), and
2
+ // what the addresses from before frames meant (legacy.ts). The one place an address of the editor is spelled.
3
+ export * from "./app-pages.js";
4
+ export * from "./paths.js";
5
+ export * from "./legacy.js";
6
+ export { fillPattern, matchPattern, paramNames } from "./patterns.js";
@@ -0,0 +1,144 @@
1
+ import { fillPattern, matchPattern } from "./patterns.js";
2
+ import { type LinkExtras, page, type PageLink, type PageName } from "./app-pages.js";
3
+
4
+ // THE ADDRESSES FROM BEFORE FRAMES (before 2026-11-04), read into the pages they meant. Every one of them named a page of
5
+ // "the sandbox this browser had open last", so they are still out there and still mean something: an installed Android
6
+ // app or desktop app hands them over, a daemon's push message points at one, a bookmark or an e-mail holds one. The
7
+ // editor's router sends each to its page in its sandbox (`?sandbox=<id>` when the link named one, the one last opened
8
+ // otherwise), and a native app that reads addresses is handed this form back (`legacyPathOf`), so neither has to change
9
+ // in step with the editor.
10
+
11
+ /** What an old address meant: its page, and the frame when it was an account page reached with no sandbox needed. */
12
+ export interface LegacyTarget {
13
+ readonly link: PageLink;
14
+ /** Home's frame for the account's pages, which must open with no sandbox at all; inside the sandbox otherwise. */
15
+ readonly frame: `inside` | `home`;
16
+ }
17
+
18
+ type Query = Readonly<Record<string, string>>;
19
+
20
+ interface LegacyRoute {
21
+ readonly pattern: string;
22
+ readonly to: (params: Readonly<Record<string, string>>, query: Query, hash: string) => LegacyTarget;
23
+ }
24
+
25
+ const inside = (link: PageLink): LegacyTarget => ({ link, frame: `inside` });
26
+
27
+ const extras = (query: Query, hash: string): LinkExtras => ({ query, hash });
28
+
29
+ // A redirect the old table already carried, kept with it: its words say why each old address is where it is now.
30
+ const withoutKey = (query: Query, key: string): Query => Object.fromEntries(Object.entries(query).filter(([name]) => name !== key));
31
+
32
+ // Most specific first: `sandbox/devices` before `sandbox/:tab?`.
33
+ const LEGACY_ROUTES: readonly LegacyRoute[] = [
34
+ { pattern: `chat`, to: (_p, q, h) => inside(page.chat(extras(q, h))) },
35
+ { pattern: `agents`, to: (_p, q, h) => inside(page.agents(extras(q, h))) },
36
+ // The Needs you inbox until 2026-10-12, when each of its rows went back to the board's tile that already badged it.
37
+ { pattern: `needs`, to: (_p, q, h) => inside(page.agents(extras(q, h))) },
38
+ { pattern: `agents/:id`, to: (p, q, h) => inside(page.agent(p[`id`] ?? ``, extras(q, h))) },
39
+ { pattern: `agents/:id/pages/:page`, to: (p, q, h) => inside(page.agentPage(p[`id`] ?? ``, p[`page`] ?? ``, extras(q, h))) },
40
+ { pattern: `workspace/:path(.*)*`, to: (p, q, h) => inside(page.workspace(p[`path`], extras(q, h))) },
41
+ { pattern: `browsers/:tab(.*)?`, to: (p, q, h) => inside(page.browsers(p[`tab`], extras(q, h))) },
42
+ // The sandbox's own desktop was a view of its own until it became a tab of Browsers (2026-10-08).
43
+ { pattern: `desktop`, to: (_p, q, h) => inside(page.browsers(`desktop`, extras(q, h))) },
44
+ // The live app's home until it, too, became a tab of Browsers: `?target=` names the app.
45
+ {
46
+ pattern: `preview`,
47
+ to: (_p, q, h) => {
48
+ const target = q[`target`];
49
+ return inside(page.browsers(target === undefined || target === `` ? undefined : `preview:${target}`, extras(withoutKey(q, `target`), h)));
50
+ },
51
+ },
52
+ { pattern: `devices`, to: (_p, q, h) => inside(page.devices(extras(q, h))) },
53
+ { pattern: `sandbox/devices`, to: (_p, q, h) => inside(page.devices(extras(q, h))) },
54
+ { pattern: `capabilities/:entry?`, to: (p, q, h) => inside(page.capabilities(p[`entry`], extras(q, h))) },
55
+ // The connect page's address until it became the sandbox's Models.
56
+ { pattern: `connect`, to: (_p, q, h) => inside(page.sandboxSettings(`models`, extras(q, h))) },
57
+ { pattern: `ext/:ext/:key?`, to: (p, q, h) => inside(page.extension(p[`ext`] ?? ``, p[`key`], extras(q, h))) },
58
+ { pattern: `terminal`, to: (_p, q, h) => inside(page.terminal(extras(q, h))) },
59
+ { pattern: `menu`, to: (_p, q, h) => inside(page.menu(extras(q, h))) },
60
+ // Recently deleted was a hub section, then the foot of the Devices board; it is the account's own page now.
61
+ { pattern: `sandbox/deleted`, to: () => ({ link: page.deletedSandboxes(), frame: `home` }) },
62
+ // The audit log was a hub section until 2026-10-17; its records are a part of Activity now, and how they are kept
63
+ // (its old second part, `?section=keeping`) is Retention's.
64
+ {
65
+ pattern: `sandbox/audit`,
66
+ to: (_p, q, h) =>
67
+ q[`section`] === `keeping`
68
+ ? inside(page.sandboxSettings(`retention`))
69
+ : inside(page.sandboxSettings(`activity`, { query: { ...q, section: `audit` }, hash: h })),
70
+ },
71
+ // Areas was a hub section until 2026-10-26; it is a part of Access now, beside the profiles that name it.
72
+ { pattern: `sandbox/areas`, to: (_p, q, h) => inside(page.sandboxSettings(`access`, { query: { ...q, section: `areas` }, hash: h })) },
73
+ { pattern: `sandbox/:tab?`, to: (p, q, h) => inside(page.sandboxSettings(p[`tab`], extras(q, h))) },
74
+ { pattern: `settings/:tab?`, to: (p, q, h) => ({ link: page.account(p[`tab`], extras(q, h)), frame: `home` }) },
75
+ { pattern: `deleted-sandboxes`, to: (_p, q, h) => ({ link: page.deletedSandboxes(extras(q, h)), frame: `home` }) },
76
+ ];
77
+
78
+ /** The patterns of every old address, for a router to route them to `legacyTarget`. */
79
+ export const LEGACY_PATTERNS: readonly string[] = LEGACY_ROUTES.map((route) => route.pattern);
80
+
81
+ const queryOf = (search: string): Query => Object.fromEntries(new URLSearchParams(search));
82
+
83
+ /**
84
+ * What an old address (path, query and hash, as `fullPath` spells it) meant, or undefined when it is not one. The
85
+ * `sandbox` key names the sandbox it was for and is the reader's to read, so it is left out of the page's query.
86
+ */
87
+ export const legacyTarget = (fullPath: string): LegacyTarget | undefined => {
88
+ const hashAt = fullPath.indexOf(`#`);
89
+ const beforeHash = hashAt === -1 ? fullPath : fullPath.slice(0, hashAt);
90
+ const hash = hashAt === -1 ? `` : fullPath.slice(hashAt + 1);
91
+ const queryAt = beforeHash.indexOf(`?`);
92
+ const path = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);
93
+ const query = withoutKey(queryAt === -1 ? {} : queryOf(beforeHash.slice(queryAt + 1)), `sandbox`);
94
+ for (const route of LEGACY_ROUTES) {
95
+ const params = matchPattern(route.pattern, path);
96
+ if (params !== undefined) {
97
+ return route.to(params, query, hash);
98
+ }
99
+ }
100
+ return undefined;
101
+ };
102
+
103
+ /** The sandbox an old address named (`?sandbox=<id>`), if it named one. */
104
+ export const legacySandbox = (fullPath: string): string | undefined => {
105
+ const search = fullPath.split(`#`, 1)[0]?.split(`?`)[1];
106
+ const named = search === undefined ? null : new URLSearchParams(search).get(`sandbox`);
107
+ return named === null || named === `` ? undefined : named;
108
+ };
109
+
110
+ // Each page's address before frames, for the readers that still read that form.
111
+ const OLD_PATTERNS = {
112
+ chat: `chat`,
113
+ agents: `agents`,
114
+ agent: `agents/:id`,
115
+ agentPage: `agents/:id/pages/:page`,
116
+ workspace: `workspace/:path(.*)*`,
117
+ browsers: `browsers/:tab(.*)?`,
118
+ devices: `devices`,
119
+ capabilities: `capabilities/:entry?`,
120
+ extension: `ext/:ext/:key?`,
121
+ sandboxSettings: `sandbox/:tab?`,
122
+ terminal: `terminal`,
123
+ menu: `menu`,
124
+ account: `settings/:tab?`,
125
+ deletedSandboxes: `deleted-sandboxes`,
126
+ } as const satisfies Readonly<Record<PageName, string>>;
127
+
128
+ /**
129
+ * A link in the form addresses had before frames, the sandbox named as `?sandbox=`: what the Android app's bridge reads
130
+ * (it parses `/agents/<id>` to open a conversation natively), so an installed app keeps working against this editor.
131
+ */
132
+ export const legacyPathOf = (link: PageLink, sandbox?: string): string => {
133
+ const query: Record<string, string> = {};
134
+ for (const [key, value] of Object.entries(link.query)) {
135
+ if (value !== undefined && value !== ``) {
136
+ query[key] = value;
137
+ }
138
+ }
139
+ if (sandbox !== undefined) {
140
+ query[`sandbox`] = sandbox;
141
+ }
142
+ const search = Object.keys(query).length === 0 ? `` : `?${new URLSearchParams(query).toString()}`;
143
+ return `/${fillPattern(OLD_PATTERNS[link.page], link.params)}${search}${link.hash === `` ? `` : `#${link.hash}`}`;
144
+ };
@@ -0,0 +1,160 @@
1
+ import { fillPattern, matchPattern } from "./patterns.js";
2
+ import {
3
+ type FloatingPanel,
4
+ FLOATING_PANELS,
5
+ isSandboxPage,
6
+ LOCAL_PAGES,
7
+ type LinkQuery,
8
+ type LocalPageName,
9
+ PAGE_PATTERNS,
10
+ type PageLink,
11
+ type PageName,
12
+ TOP_PAGES,
13
+ type TopPageName,
14
+ } from "./app-pages.js";
15
+
16
+ // WHERE A LINK IS DRAWN, AND ITS ADDRESS (2026-11-04). The first segment of every address in the workspace shell says
17
+ // its frame, so the address alone says what the screen shows, and Back, a reload and a shared link all agree with it:
18
+ //
19
+ // /s/<sandbox>/<page> inside the sandbox: its own rail, its sections, its status bar
20
+ // /home/<sandbox>/<page> in Home's frame: the rail of every sandbox, around this one's page
21
+ // /home/<sandbox> Home's frame around that sandbox's home conversation
22
+ // /home/<account page> the account's own pages opened from Home; `/s/<sandbox>/<account page>` from inside
23
+ //
24
+ // Until then the frame was the window's memory (a sessionStorage flag) and the sandbox the browser's (one localStorage
25
+ // key for every tab), so one address drew two screens and Back could not leave Home.
26
+
27
+ /** The address segment of each frame. */
28
+ export const SANDBOX_SEGMENT = `s`;
29
+ export const HOME_SEGMENT = `home`;
30
+
31
+ /** Inside a sandbox, or in Home's frame. */
32
+ export type FrameKind = `inside` | `home`;
33
+
34
+ /** Where a page is drawn: inside one sandbox, or in Home's frame (around one sandbox's page, or around the account's). */
35
+ export type Frame = { readonly kind: `inside`; readonly sandbox: string } | { readonly kind: `home`; readonly sandbox?: string | undefined };
36
+
37
+ const queryString = (query: LinkQuery): string => {
38
+ const entries = Object.entries(query).filter((entry): entry is [string, string] => entry[1] !== undefined && entry[1] !== ``);
39
+ return entries.length === 0 ? `` : `?${new URLSearchParams(entries).toString()}`;
40
+ };
41
+
42
+ const suffix = (link: Pick<PageLink, `query` | `hash`>): string => `${queryString(link.query)}${link.hash === `` ? `` : `#${link.hash}`}`;
43
+
44
+ const joined = (...parts: readonly string[]): string => `/${parts.filter((part) => part !== ``).join(`/`)}`;
45
+
46
+ /** A page's path below its frame, no query: `agents/1a2b`. */
47
+ export const pagePath = (link: PageLink): string => fillPattern(PAGE_PATTERNS[link.page], link.params);
48
+
49
+ /** A link's address inside a sandbox: `/s/<sandbox>/<page>`, or the sandbox's own landing with no page. */
50
+ export const insidePath = (sandbox: string, link?: PageLink): string =>
51
+ link === undefined ? joined(SANDBOX_SEGMENT, encodeURIComponent(sandbox)) : `${joined(SANDBOX_SEGMENT, encodeURIComponent(sandbox), pagePath(link))}${suffix(link)}`;
52
+
53
+ /**
54
+ * A link's address in Home's frame: a sandbox's page beside the rail of every sandbox, that sandbox's home conversation
55
+ * with no page, an account page with no sandbox needed, and Home itself with neither.
56
+ */
57
+ export const homePath = (sandbox?: string, link?: PageLink): string => {
58
+ if (link !== undefined && !isSandboxPage(link.page)) {
59
+ return `${joined(HOME_SEGMENT, pagePath(link))}${suffix(link)}`;
60
+ }
61
+ if (sandbox === undefined) {
62
+ if (link !== undefined) {
63
+ throw new Error(`Home's frame shows the page ${link.page} of a sandbox, and none was named.`);
64
+ }
65
+ return joined(HOME_SEGMENT);
66
+ }
67
+ return link === undefined
68
+ ? joined(HOME_SEGMENT, encodeURIComponent(sandbox))
69
+ : `${joined(HOME_SEGMENT, encodeURIComponent(sandbox), pagePath(link))}${suffix(link)}`;
70
+ };
71
+
72
+ /** A link's address in a frame. */
73
+ export const framePath = (frame: Frame, link?: PageLink): string =>
74
+ frame.kind === `inside` ? insidePath(frame.sandbox, link) : homePath(frame.sandbox, link);
75
+
76
+ /** A floating window's own address: one panel of one sandbox, with no shell around it. */
77
+ export const floatingPath = (sandbox: string, panel: FloatingPanel): string => joined(SANDBOX_SEGMENT, encodeURIComponent(sandbox), `floating`, panel);
78
+
79
+ /** A page that is no sandbox's, by name: `/login`, `/invite/<token>`. */
80
+ export const topPath = (name: TopPageName, params: Readonly<Record<string, string | undefined>> = {}, query: LinkQuery = {}): string =>
81
+ `${joined(fillPattern(TOP_PAGES[name], params))}${queryString(query)}`;
82
+
83
+ /** A page of a desktop window on a folder (the app's local face). */
84
+ export const localPath = (name: LocalPageName, params: Readonly<Record<string, string | undefined>> = {}, extras: { query?: LinkQuery; hash?: string } = {}): string =>
85
+ `${joined(fillPattern(LOCAL_PAGES[name], params))}${suffix({ query: extras.query ?? {}, hash: extras.hash ?? `` })}`;
86
+
87
+ /** What an address of the workspace shell names: its frame, its sandbox, and its page when it names one. */
88
+ export interface AppAddress {
89
+ readonly frame: Frame;
90
+ readonly page?: { readonly name: PageName; readonly params: Readonly<Record<string, string>> };
91
+ }
92
+
93
+ // SAFETY: PAGE_PATTERNS is a const literal whose own keys are exactly PageName; Object.keys only widens their type.
94
+ const PAGE_NAMES = Object.keys(PAGE_PATTERNS) as PageName[];
95
+
96
+ /** The page a path below a frame names (no query, no hash), if it names one. */
97
+ export const matchPage = (path: string): { readonly name: PageName; readonly params: Readonly<Record<string, string>> } | undefined => {
98
+ for (const name of PAGE_NAMES) {
99
+ const params = matchPattern(PAGE_PATTERNS[name], path);
100
+ if (params !== undefined) {
101
+ return { name, params };
102
+ }
103
+ }
104
+ return undefined;
105
+ };
106
+
107
+ const decodeSegment = (segment: string): string => {
108
+ try {
109
+ return decodeURIComponent(segment);
110
+ } catch {
111
+ return segment;
112
+ }
113
+ };
114
+
115
+ /**
116
+ * What a path of the workspace shell names (query and hash are ignored), or undefined for any other path: one of a
117
+ * top page's, a floating window's, an address from before frames (legacy.ts reads those), or none at all.
118
+ */
119
+ export const parseAppPath = (address: string): AppAddress | undefined => {
120
+ const path = address.split(/[?#]/, 1)[0] ?? ``;
121
+ const segments = path.split(`/`).filter((segment) => segment !== ``);
122
+ const [head, second, ...rest] = segments;
123
+ if (head === SANDBOX_SEGMENT && second !== undefined) {
124
+ const frame: Frame = { kind: `inside`, sandbox: decodeSegment(second) };
125
+ if (rest[0] === `floating`) {
126
+ return undefined;
127
+ }
128
+ if (rest.length === 0) {
129
+ return { frame };
130
+ }
131
+ const page = matchPage(rest.join(`/`));
132
+ return page === undefined ? undefined : { frame, page };
133
+ }
134
+ if (head === HOME_SEGMENT) {
135
+ if (second === undefined) {
136
+ return { frame: { kind: `home` } };
137
+ }
138
+ const account = matchPage([second, ...rest].join(`/`));
139
+ if (account !== undefined && !isSandboxPage(account.name)) {
140
+ return { frame: { kind: `home` }, page: account };
141
+ }
142
+ const frame: Frame = { kind: `home`, sandbox: decodeSegment(second) };
143
+ if (rest.length === 0) {
144
+ return { frame };
145
+ }
146
+ const page = matchPage(rest.join(`/`));
147
+ return page === undefined ? undefined : { frame, page };
148
+ }
149
+ return undefined;
150
+ };
151
+
152
+ /** The sandbox and panel a floating window's address names, if it is one. */
153
+ export const parseFloatingPath = (address: string): { readonly sandbox: string; readonly panel: FloatingPanel } | undefined => {
154
+ const path = address.split(/[?#]/, 1)[0] ?? ``;
155
+ const [head, sandbox, floating, panel, ...rest] = path.split(`/`).filter((segment) => segment !== ``);
156
+ const known = FLOATING_PANELS.find((candidate) => candidate === panel);
157
+ return head === SANDBOX_SEGMENT && sandbox !== undefined && floating === `floating` && known !== undefined && rest.length === 0
158
+ ? { sandbox: decodeSegment(sandbox), panel: known }
159
+ : undefined;
160
+ };