@milesroxas/design-hub 0.13.0 → 0.15.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 (101) hide show
  1. package/README.md +38 -33
  2. package/core/catalog.test.ts +28 -1
  3. package/core/catalog.ts +21 -4
  4. package/core/prototype.test.ts +12 -1
  5. package/core/prototype.ts +21 -2
  6. package/core/review/model.ts +71 -6
  7. package/core/review/service.test.ts +536 -1
  8. package/core/review/service.ts +452 -25
  9. package/core/review/store.ts +45 -4
  10. package/dist/core/catalog.d.ts +8 -1
  11. package/dist/core/catalog.js +12 -3
  12. package/dist/core/prototype.d.ts +20 -2
  13. package/dist/core/prototype.js +17 -2
  14. package/dist/core/review/model.d.ts +42 -3
  15. package/dist/core/review/model.js +52 -3
  16. package/dist/core/review/service.d.ts +81 -7
  17. package/dist/core/review/service.js +407 -23
  18. package/dist/core/review/store.d.ts +29 -2
  19. package/dist/core/review/store.js +4 -0
  20. package/dist/scripts/client.d.ts +1 -1
  21. package/dist/scripts/client.js +1 -1
  22. package/dist/scripts/lib/catalog.d.ts +1 -1
  23. package/dist/scripts/lib/catalog.js +3 -3
  24. package/dist/scripts/lib/dns.d.ts +16 -2
  25. package/dist/scripts/lib/dns.js +66 -3
  26. package/dist/scripts/lib/fake-host.d.ts +16 -1
  27. package/dist/scripts/lib/fake-host.js +36 -1
  28. package/dist/scripts/lib/host.d.ts +2 -0
  29. package/dist/scripts/lib/resend.d.ts +36 -0
  30. package/dist/scripts/lib/resend.js +66 -0
  31. package/dist/scripts/lib/studio-deps.d.ts +7 -0
  32. package/dist/scripts/lib/studio-deps.js +6 -1
  33. package/dist/scripts/lib/studios.d.ts +2 -2
  34. package/dist/scripts/lib/studios.js +5 -5
  35. package/dist/scripts/lib/vercel-host.js +6 -0
  36. package/dist/scripts/new.d.ts +8 -3
  37. package/dist/scripts/new.js +15 -4
  38. package/dist/scripts/people.d.ts +16 -4
  39. package/dist/scripts/people.js +67 -17
  40. package/dist/scripts/preflight.js +1 -1
  41. package/dist/scripts/share.js +3 -3
  42. package/dist/scripts/studio.d.ts +19 -3
  43. package/dist/scripts/studio.js +327 -6
  44. package/dist/server/api.d.ts +25 -2
  45. package/dist/server/api.js +77 -17
  46. package/dist/server/dev-studio.d.ts +36 -0
  47. package/dist/server/dev-studio.js +181 -0
  48. package/dist/server/dev.d.ts +16 -1
  49. package/dist/server/dev.js +23 -3
  50. package/dist/server/gate.d.ts +26 -3
  51. package/dist/server/gate.js +323 -52
  52. package/dist/server/mailer.d.ts +60 -0
  53. package/dist/server/mailer.js +104 -0
  54. package/dist/server/mailers/fake.d.ts +8 -0
  55. package/dist/server/mailers/fake.js +16 -0
  56. package/dist/server/mailers/resend.d.ts +21 -0
  57. package/dist/server/mailers/resend.js +49 -0
  58. package/dist/server/session.js +4 -1
  59. package/dist/vercel/proxy.js +10 -3
  60. package/dist/vite/plugin.js +6 -1
  61. package/kit/ViewTools.tsx +9 -0
  62. package/kit/prefs.ts +3 -4
  63. package/kit/ui/Menu.tsx +29 -18
  64. package/kit/ui/layer.ts +41 -0
  65. package/package.json +1 -1
  66. package/shell/Command.tsx +142 -0
  67. package/shell/Index.tsx +902 -400
  68. package/shell/Milestone.tsx +302 -0
  69. package/shell/Sidebar.tsx +236 -0
  70. package/shell/index.css +224 -0
  71. package/shell/milestones.test.ts +157 -0
  72. package/shell/milestones.ts +144 -0
  73. package/shell/registry.ts +4 -3
  74. package/shell/review/Bar.tsx +1 -0
  75. package/shell/review/Card.tsx +17 -7
  76. package/shell/review/People.tsx +908 -134
  77. package/shell/review/Review.tsx +2 -2
  78. package/shell/review/anchor.ts +6 -1
  79. package/shell/review/client.ts +41 -7
  80. package/shell/review/menu-place.test.ts +41 -0
  81. package/shell/review/place.test.ts +26 -1
  82. package/shell/review/place.ts +17 -0
  83. package/shell/review/review.css +97 -11
  84. package/shell/review/view.test.ts +115 -1
  85. package/shell/review/view.ts +92 -2
  86. package/shell/shell.css +8 -175
  87. package/shell/sidebar.css +86 -0
  88. package/shell/studio/ClientHub.tsx +21 -10
  89. package/shell/studio/StudioHub.tsx +121 -45
  90. package/shell/studio/hub.css +118 -27
  91. package/shell/studio/page.tsx +28 -17
  92. package/shell/system.css +12 -0
  93. package/skills/miles-deploy/SKILL.md +25 -4
  94. package/skills/miles-new-feature/SKILL.md +2 -1
  95. package/skills/miles-prototype/SKILL.md +1 -1
  96. package/templates/app/README.md +1 -1
  97. package/templates/brand/README.md +1 -1
  98. package/templates/site/README.md +1 -1
  99. package/templates/space/README.md +1 -1
  100. package/templates/studio/.env.example +6 -0
  101. package/templates/studio/package.json +1 -1
package/README.md CHANGED
@@ -16,55 +16,60 @@ How a project becomes an app: `design-hub dev` runs Vite with the package's `she
16
16
 
17
17
  ## The index
18
18
 
19
- `/` lists every prototype from its README frontmatter (`shell/Index.tsx`, `shell/shell.css`). The page answers one question for a reviewer: which prototype is the feature, and what else was tried around it.
19
+ `/` lists the project's milestones (`shell/Index.tsx`, `shell/milestones.ts`, `shell/index.css`). It answers one question for a reviewer: what is each milestone's current answer, and what around it is live right now.
20
+
21
+ The README's fields keep their names; the hub shows them under the names people use:
22
+
23
+ | In the README | In the hub |
24
+ | --- | --- |
25
+ | `feature` | A **Milestone**: the unit of work, one question |
26
+ | `kind: sprint` | Its **Main**: the current answer, one per milestone |
27
+ | `docs/sprints/<feature>/guide.md` | Its **Guide** |
28
+ | `kind: alternate`, `kind: exploration` | An **Exploration** |
29
+
30
+ ### Sidebar
31
+
32
+ A sidebar docks to the left edge (248px, `--bg-secondary_subtle`, a hairline right border). Top to bottom: under a base, **All projects** back to the client's hub; **Search**, a button that opens the command menu; then two views. **Milestones** (`#/`) nests each milestone as a jump to its row, clearing any filter. **Tools** (`#/tools`) lists `kind: tool` prototypes; it shows only once the project has a tool. **Recent** lists the last five prototypes opened from this index, per browser. Who is signed in sits at the foot. Under 1024px the sidebar becomes a bar across the top, with no jumps and no Recent.
33
+
34
+ ### Search
35
+
36
+ The command menu (`shell/Command.tsx`): Command or Control with K, or `/`, from anywhere. It finds milestones, prototypes and tools by title, summary and slug, and holds Client view as an action. Enter opens a prototype and shows a milestone's home. With no query it lists Recent and the actions. It opens and closes with no motion.
20
37
 
21
38
  ### Which kind
22
39
 
23
40
  Walk this for every new prototype; the first match wins.
24
41
 
25
- 1. The feature's main prototype, the one its walkthrough opens → `sprint`. Exactly one per feature, so a reviewer never has to guess which build is current. `design-hub new --sprint` refuses a second while the first is not archived.
42
+ 1. The feature's main prototype, the one its walkthrough opens → `sprint`. Exactly one per feature, so a reviewer never has to guess which build is current. `design-hub new --sprint` refuses a second while the first is open (not archived, not presented).
26
43
  2. Another full take on that same flow, built to compare against the primary → `alternate` (`--alternate`). Refused until the primary exists, because an alternate is only legible next to what it replaces.
27
- 3. Anything else: a side question about one part (a menu's motion, a loading state) → `exploration`, the default.
44
+ 3. A small app that makes assets for several features (chart skeletons, an icon set) → `tool` (`--tool`). It needs no feature, starts `in-progress`, and lists under Tools, never under a milestone.
45
+ 4. Anything else: a side question about one part (a menu's motion, a loading state) → `exploration`, the default.
28
46
 
29
- ### Layout
30
-
31
- Groups, in order: one per feature, then `Without a feature` (explorations with an empty `feature:`), then `Archived` (`status: archived`, any kind, plain rows).
47
+ Statuses: `exploring` (open), `decided`, `ready` (a sprint handed to engineering; shown as Ready for dev), `in-progress` (a tool being built), `presented` (a take the client saw and did not pick; add `presented: <date>`, which dates it in place of `created`), `archived`.
32
48
 
33
- A feature group, top to bottom:
49
+ ### Layout
34
50
 
35
- 1. **Heading.** The feature's name. `Walkthrough →` ends the line when `docs/sprints/<feature>/guide.md` exists.
36
- 2. **Primary.** The one `sprint` row, its title 16px against 14px for every other row. Size alone marks it; no badge, no new shape.
37
- 3. **Alternates.** Under an `Alternates` caption (12px, 500, quaternary text), indented 20px and joined to the primary by a 1px rail in `--border-secondary` on the primary's text edge. The rail makes them children of that one row; a heading of their own would make them peers of the feature. A stray second `sprint` renders here too.
38
- 4. **Explorations.** A toggle (`Explorations`, the count, a chevron), collapsed by default because explorations are working material, not the feature. The open state persists per group in `localStorage` (`index-explorations-open`). Typing in the filter opens every fold, so a match is never hidden. Open, the explorations are cards on a grid (`minmax(208px, 1fr)`, 8px gap). Every exploration lives here, never in the row list.
51
+ Milestones, by last update or by name (Display), then **No milestone** (prototypes with an empty `feature:`). A milestone whose every prototype is archived leaves the index; search still finds its prototypes.
39
52
 
40
- Within any list: exploring above decided, then newest first.
53
+ - **A milestone row** carries its title, its Main's status and the date of its newest prototype. Click, Enter or Space opens the milestone's home; on hover or focus the date gives way to `Open →`, in the same cell.
54
+ - **Quick links** hang under it on a 1px rail, and each opens what it names: its Main (marked `Main`), its Guide, then under an `Explorations` label, indented on a second rail, the explorations still in motion. A link spells out a status only when it waits on someone: `review` and `ready`.
55
+ - **Folding.** The chevron in the gutter folds a milestone's quick links; it has its own hover surface, so the row never reads as a heading that folds. Until someone folds it, a `decided` milestone starts folded and an open one does not. Folds persist per browser (`index-folds`); Display has Fold all.
56
+ - **Filter** narrows by track and status, each offered only when the milestones have two or more; a filter in use shows as a chip that removes it.
57
+ - **Keys.** J and K, or the arrows, walk the rows; Left and Right fold and unfold the milestone in focus.
58
+ - No counts anywhere, and quick links carry no icons.
41
59
 
42
- Rhythm: inside a group, each block's text sits 20px under the text above it (primary under heading, each caption under the last summary), and a caption sits 8px over what it labels, so it reads as the start of what follows. Groups sit 40px apart, double the inner step, so a group reads as one unit.
60
+ Status is a 6px mark before the word: a ring for exploring, a solid dot for decided, the brand colour only for what waits on someone. `review` reads `Ready to present` to Studio and `In review` to a Client.
43
61
 
44
- Surfaces:
62
+ ### A milestone's home
45
63
 
46
- - **Rows** draw no dividers. The hover surface is the only drawn shape and bleeds 12px into the gutter, so every text edge on the page lines up. One page grid reaches every row through subgrid, so the context, status and date columns align across groups without fixed widths; the alternates' indent reaches the first column only.
47
- - **Cards** take `--radius-lg` and 12px padding, so card text keeps the page's text edge. The title line ends in an arrow (quaternary), because the whole card opens the prototype. The summary drops to caption size (12px/18px, tertiary) so three cards scan as three titles. Context, status and date sit pinned to the bottom so the meta lines up across a row of cards. The edge is an inset ring (`oklch(0 0 0 / 0.08)`) plus two soft layers in light, and a white 9% ring alone in dark, where the tokens drop every shadow. The ring is inset because the fold clips its content while it animates and would cut an outer one. Focus stacks the focus ring on the edge, since both are box-shadows and the edge alone would erase it.
48
- - **Status** is a 6px dot before the word: ink for exploring, success for decided, quinary for archived. The word stays, so colour is never the only signal.
49
- - **Foot.** The count alone, in body type over a hairline (the Ledger Foot Rule).
50
- - **Lede.** 18px/28px Geist at 400, secondary text. `--font-voice` resolves to Geist inside the hub's `.sys` scope (`shell/system.css`), so the index never borrows the project's faces.
64
+ Over the index, at `#/m/<feature>` (`shell/Milestone.tsx`), so it has a link and Back closes it. One bar: previous and next milestone (K and J), Full page, Close. A reading column: the title, the Main's summary, the question (the first paragraph under the Main README's `## Question`), then Main, Explorations, Presented and, for Studio, Archived. Beside it, Status, Track and Updated; under 600px they move under the text. The foot holds Guide and the one primary, `Open Main`; Enter opens it. Escape or a press on the backdrop closes, and focus returns to the milestone's row.
51
65
 
52
66
  ### Audience
53
67
 
54
- Every prototype is Internal until Studio marks it Client-facing; a Client's index lists only the client-facing ones, and the gate refuses an internal prototype's page and files to a Client. Studio, outside Client view, sees each prototype's audience in a fifth column beside its row (under a card), never inside the link: `Internal` on the internal comments' amber (`--sys-internal`), `Client-facing` in quaternary text, then a switch (`role="switch"`, a 28px track, its hit area grown to 40px). A switch shows at once and is undone, with a toast, when the save fails. **Client view** in the head shows the index as a client gets it, with the comment layer's note at the bottom and **Leave**; in it no switch and no audience word shows. A Client with nothing shared sees `Nothing shared yet`.
68
+ Every prototype is Internal until Studio marks it Client-facing; a Client's index lists only the client-facing ones, and the gate refuses an internal prototype's page and files to a Client. Studio, outside Client view, sees each prototype's audience at the end of its row in the milestone's home, never inside the link: `Internal` on the internal comments' amber (`--sys-internal`), then a switch (`role="switch"`, a 28px track, its hit area grown to 40px). A prototype with no milestone, and a tool, has no home: its switch ends its row on the index. A switch shows at once, waits while its save is out, and is undone with a toast if the save fails. **Client view** in the toolbar shows the index, and every comment, as a client gets them.
55
69
 
56
70
  ### Motion
57
71
 
58
- Nothing animates on a keyboard action.
59
-
60
- - **Arrival**, one shot: the head fades over 200ms, then each heading, caption, row and open card rises 4px and fades over 220ms, 30ms apart (stagger capped at eight), then the foot. Keyframes fill backwards only, so a settled row's opacity stays free to transition.
61
- - **Departure**, pointer only: a clicked row or card holds while the rest of the page fades over 150ms on the Layer Exit curve, filling the wait while the browser fetches the prototype. A modified click or Enter opens instantly; a back-forward restore clears the fade.
62
- - **Fold:** opens over 220ms (grid row `0fr` to `1fr`, plus the fade) and closes over 150ms, both `--ease-out`; the chevron turns 180°. A keyboard toggle is instant.
63
- - **Hover:** a row takes the Hover Rule fill. A card stays white and lifts instead (ring and shadow deepen; in dark, the ring brightens and the surface steps up to `--bg-primary_hover`), and its arrow moves 2px right and darkens to secondary. Both lift the summary to secondary. **Press:** `scale(0.97)`.
64
- - **Reduced motion** keeps the fades and drops the rise, the press, the fold's growth, the chevron's turn and the arrow's nudge.
65
- - Up and Down arrows walk the rows and the cards of open folds.
66
-
67
- A speculation rule in `shell/index.html` prefetches a prototype's page when its row is hovered, so the document is in cache by the click (Chromium; other browsers ignore the rule). Prerendering was rejected: it would play a prototype's entrance motion before anyone saw it.
72
+ Nothing animates on a keyboard action. The home fades and scales from 0.97 when opened by pointer, and lands at once by keyboard; the command menu never animates. Hover fills use the Hover Rule. Reduced motion drops the scale and the chevron's turn.
68
73
 
69
74
  ## The walkthrough
70
75
 
@@ -76,7 +81,7 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
76
81
 
77
82
  A client's address is `<client>.<apex>` (or a codename under the apex, `client add --host`), and a project is `/<project>/` below it. `design-hub project link` writes `.design-hub/studio.json` in the project (studio, its id, client, project; committed). `design-hub share` builds the project with base `/<project>/`, uploads `dist/` under `c/<client>/<project>/<build>/` in the file store with a new random build id, checks every file is there, and only then points the project's record at that build, so a half-finished upload is never served; the live build and the two before it are kept. Every path on every client's host sits behind the gate, enforced on the server by the gate (`server/gate.ts`, free of any host: it answers each request with a decision), run as Vercel Routing Middleware by its adapter (`createStudioProxy` in `vercel/proxy.ts`, which the studio's `vercel.json` names as `proxy.entrypoint`). The host names the client, from one store lookup kept a minute per instance; a host no client has is the plain 404 before anything else is read. The files function and the review function run the gate's checks again themselves, in the order host, session, project, so neither trusts anything the gate set. A client-side gate was rejected because the bundle and the state behind it would still download.
78
83
 
79
- Studio people have a host of their own, `studio.<apex>`, which `studio create` (or `studio deploy`, for an older studio) adds and proves as it proves a client's. Only Studio people sign in there; a Client, a cookie of a client's host, or none gets that host's sign-in page, word for word a client host's. Its page is the studio hub (`shell/studio/StudioHub.tsx`, built apart from the client hub under `_studio/`, so no client's host serves it): every client with its projects, an **Open** that hands the person off to the client's host (a one-time record in the client's keys, claimed once there within 60 seconds, which sets that host's own Studio cookie), and a **People** panel per client and one for the studio's own people, the review panel's People controls. Its review API answers `me`, `clients` and the people ops, each naming the client it is for with `client`, which the service checks as the handoff does (known, added, not archived) and answers as an unknown client otherwise; without `client` an op is the studio's own people. No client's host reads a `client` parameter.
84
+ Studio people have a host of their own, `studio.<apex>`, which `studio create` (or `studio deploy`, for an older studio) adds and proves as it proves a client's. Only Studio people sign in there; a Client, a cookie of a client's host, or none gets that host's sign-in page, word for word a client host's. Its page is the studio hub (`shell/studio/StudioHub.tsx`, built apart from the client hub under `_studio/`, so no client's host serves it): the index's sidebar (`shell/Sidebar.tsx`: Search over clients and projects, **Clients** with each client nested as a jump, **Studio people**), then every client with its projects, an **Open** that hands the person off to the client's host (a one-time record in the client's keys, claimed once there within 60 seconds, which sets that host's own Studio cookie), and a **People** panel per client, the review panel's People controls. **Studio people** (`#/people`) is a view of its own that shows the studio's own people in those controls at once. A client's hub wears the same sidebar, with Search over its projects. Its review API answers `me`, `clients` and the people ops, each naming the client it is for with `client`, which the service checks as the handoff does (known, added, not archived) and answers as an unknown client otherwise; without `client` an op is the studio's own people. No client's host reads a `client` parameter.
80
85
 
81
86
  Every person is named, and signs in with a one-time link that Studio makes in the review panel's People tab, on the studio hub, with `design-hub people` in a linked project, the studio folder or with `--studio`, or, for a client's first person, with `design-hub client add`. A Client's link is on their client's host, and signs in there only. A Studio person's is on `studio.<apex>` once it answers (on the linked client's host before then), and signs in on any host of the studio; the owner's first comes from the run that proves the studio host, and a new one from `people link <owner id> --studio <studio>`.
82
87
 
@@ -87,7 +92,7 @@ Every person is named, and signs in with a one-time link that Studio makes in th
87
92
  - **The session** is one cookie, `__Host-hub_person`: `HttpOnly`, `Secure`, `SameSite=Lax`, host-only. Its token is `p5.<id>.<epoch>.<kind>.<client>.<expires>.<checkedAt>.<sig>`, signed with HMAC-SHA256 over all of those and over two things it never carries: the review store's URL, so two studios that share a `GATE_SECRET` never accept each other's cookies, and when the client was added, so a slug archived and added again accepts no token from before. A token verifies only on its own client's host, a Studio person's too. Any other version never verifies. It lasts to the access end, at most 400 days, the longest a browser keeps one. For `CHECK_SECONDS` (5 minutes) after `checkedAt` any request passes on the signature. After that the next request, of any kind, asks the store: a current person passes with a fresh cookie whose expiry follows their current access end; a revoked, signed-out-everywhere or ended person gets 401 and the cookie cleared. The request's own headers never decide whether the store is asked, since the client chooses them. A store that fails answers 503 with `Retry-After`, and leaves the cookie, so an outage signs nobody out; the review panel reads `Retry-After` as try again. The API function answers the same way in JSON. The sign-in POST also refuses a store failure with 503, and a link is checked before it is used up, so a failure never burns one. The hub reads any 401, the gate's plain text or the API's JSON, as signed out.
88
93
  - **The link page** sends `Referrer-Policy: same-origin`, so Continue's POST carries a real `Origin` (with `no-referrer` a browser sends `Origin: null`, trusted only beside `Sec-Fetch-Site`, which older Safari does not send). Every other gate response sends `no-referrer`.
89
94
  - **Internal prototypes.** Everything built from `prototypes/<slug>/` (its README, code, CSS, fixtures, lazy chunks and images) lands under `/_p/<slug>/`, its entry at `/_p/<slug>/entry.js`, and Studio's list of every slug at `/_p/all.js`; the shared bundle in `/assets/` names no prototype's folder (`vite/registry.ts`, `vite/boundary.ts`, `vite/settle.ts`; the build fails if a file breaks that). The exception is the walkthroughs: their compiled text and every feature's name sit in `/assets/` and reach every signed-in person, so a walkthrough must not name or describe internal work until that is built. A built file is owned by where its content comes from, never by who reads it, and each source is recorded as the file is written (`vite/settle.ts`): a stylesheet's CSS modules, an asset's original files, a worker's output; a file with no record and no fixed name fails the build. Nothing a prototype owns is inlined by the size limit, and nothing under `prototypes/` is ever the hub's: a file directly there, or in a folder without a README, is refused (shared code belongs in `kit/`). Any import or `new URL` (`?inline` included) into a prototype its importer does not own is refused in dev and in a build. Every stylesheet is read for reaches inside Vite's postcss run (`vite/css-boundary.ts`), each reference followed as a path and through Vite's own resolvers (aliases and package paths included); Sass, Less and Stylus are refused in prototypes and the project's `kit/`, since their imports resolve inside the preprocessor; and every worker bundle refuses a module under `prototypes/` and resolves `@kit/*`. After the bundle is settled the build reads what it wrote (`vite/leaks.ts`): a file outside `/_p/<slug>/` that holds a whole file of `prototypes/<slug>/` (its bytes, a base64 or SVG data URI of it anywhere in the file, or, for a file the build read, its whole text as a string in a script; 40 bytes or more) fails the build, unless the reader's owner has a source with the same content. It is a backstop for whole-file inlining: no part of a file (a line, a rule) is looked for. Vite is pinned to 8.3 (`~8.3.5`) because the boundary leans on its internals; `vite/build.test.ts` is what to run on a Vite upgrade. A file a prototype owns lives in its folder; the hub's and the kit's live in `/assets/` and are never copied into a prototype's folder; the same bytes from several owners become one copy per owner, each named from its owner's source. A file that reads what another prototype owns, or a hub or kit file that reads what a prototype owns, fails the build, naming both. A prototype that reaches into another (an import, a CSS `@import` or `url()`, a `new URL`) or starts a web worker fails the build. A Client asking for a prototype's page (`/<project>/<slug>/`) or anything under `/<project>/_p/<slug>/` gets 404 unless that prototype is client-facing, asked of the store on every such request; `/<project>/_p/all.js` is always 404 to a Client, and an internal prototype and one that does not exist answer byte for byte the same. Below a project, any first segment that is not the hub's own (`assets`, `api`, `guide`, `_gate`, `index.html`, `favicon.svg`), `_p` or a prototype slug gets the same 404. A path that could mean more than one file (a `.` or `..` segment, a backslash, a control character, an empty segment, a `%` left after decoding, or one that does not decode) goes nowhere for anyone, Studio included. Another client's project, and a project with no build, are the same 404, its review API too. A Client's comments on a prototype that is not client-facing answer as if it had none. Studio passes on the cookie's kind with no audience read. The client's hub at `/` and a project's `/assets/*`, `/guide/*` and review API pass on the session alone. `invite`, `api`, `_gate`, `_p`, `assets`, `guide`, `index.html` and `favicon.svg` are never a prototype's slug (`RESERVED` in `core/prototype.ts`).
90
- - **Signed out**, a page gets the sign-in page (401). It has no form: it says to open the link the studio sent, that each link signs in one device and then stops working, and to ask the studio for a new one for another device. Anything else gets a plain-text 401, an anonymous `POST` included.
95
+ - **Signed out**, a page gets the sign-in page (401). It has no form: it says to open the link the studio sent, that each link works once, on one device, and to ask the studio for a new one. Anything else gets a plain-text 401, an anonymous `POST` included.
91
96
 
92
97
  The studio site reads its env from the Vercel project, never committed: `GATE_SECRET`, at least 32 random characters that sign the session cookie, and the database's and file store's credentials, which `studio create` sets and copies into the studio folder's `.env` (`templates/studio/.env.example` names them). With the secret or the database missing, every host answers 503 "This site is not set up yet.", which names no command, studio or client, so a misconfigured site never serves anything open. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The signed-out page names no client. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page, `?page=used` a used one and `?page=stopped` the studio host's page for an Open that cannot start. On the studio host the used page's way in says the clients, not the prototypes.
93
98
 
@@ -97,4 +102,4 @@ Every signed-in person can comment as themselves. The People tab lists each pers
97
102
 
98
103
  The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `<project>/api/review` (`server/api.ts`, reached on a studio site through its one-line `api/review.ts`, scoped by the host's client and the project the path names): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is, which client a person may act in) live once, in `core/review/`, behind a small storage port: the studio's database (`server/stores/`: Upstash Redis over REST, or Postgres in one table of key, field and value), or a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person in one fixed scope. Every key is built by one function from a scope, under the prefix `hub4:`: the studio's (`studio:people`, `clients`, `hosts`, …), a client's (`c:<client>:people`, `:links`, `:projects`, …) and a project's (`c:<client>:p:<project>:comments:<prototype>`, …), so no op reaches another client's records.
99
104
 
100
- `design-hub dev` serves the prototypes open, with the review panel on the local store. The gate and the studio's functions are covered by `pnpm test` (`vercel/gate.test.ts`, against an in-memory Upstash and file store, and again in `vercel/gate.postgres.test.ts` on an embedded Postgres).
105
+ `design-hub dev` serves the prototypes open, with the review panel on the local store. It also serves the studio site's own pages, so they can be seen and used before a studio exists (`server/dev-studio.ts`): the studio hub at `/_studio/` and each client's hub at `/_clients/<client>/`, on a store of their own, `.design-hub/studio.json`, filled on first use with sample clients, projects and people (delete the file for a fresh set). The page that asks (its Referer) says which site an API request is; Open goes to the client's dev hub, and every project opens this project's index. The gate and the studio's functions are covered by `pnpm test` (`vercel/gate.test.ts`, against an in-memory Upstash and file store, and again in `vercel/gate.postgres.test.ts` on an embedded Postgres).
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { test } from 'node:test';
3
- import { byIndexOrder, isLive, placeLabel, readMeta } from './catalog.ts';
3
+ import { byIndexOrder, isLive, isOpen, placeLabel, readMeta } from './catalog.ts';
4
4
  import { frontmatter } from './frontmatter.ts';
5
5
 
6
6
  const readme = (fm: string, body = '') => `---\n${fm}\n---\n\n# X\n${body}`;
@@ -28,6 +28,13 @@ test('readMeta fills defaults and keeps only the known kinds', () => {
28
28
  );
29
29
  });
30
30
 
31
+ test('readMeta reads the question: the first paragraph under its heading, on one line', () => {
32
+ const q = (body: string) => readMeta('x', readme('kind: sprint', body)).question;
33
+ assert.equal(q('\n## Question\n\nDoes the row hold\nup?\n\nMore.\n\n## Flows\n'), 'Does the row hold up?');
34
+ assert.equal(q('\n## Problem\n\nA list.\n'), '');
35
+ assert.equal(q('\n## Question\n\n## Flows\n\nNone.\n'), '');
36
+ });
37
+
31
38
  test('open questions sort above answered ones, newest first, then by title', () => {
32
39
  const m = (slug: string, status: string, created: string) =>
33
40
  readMeta(slug, readme(`title: ${slug}\nstatus: ${status}\ncreated: ${created}`));
@@ -43,6 +50,26 @@ test('open questions sort above answered ones, newest first, then by title', ()
43
50
  assert.equal(isLive({ status: 'archived' }), false);
44
51
  });
45
52
 
53
+ test('a tool is a kind of its own, and a tool being built sorts with open questions', () => {
54
+ assert.equal(readMeta('x', readme('kind: tool')).kind, 'tool');
55
+ const m = (slug: string, status: string) =>
56
+ readMeta(slug, readme(`title: ${slug}\nstatus: ${status}\ncreated: 2026-01-01`));
57
+ assert.deepEqual(
58
+ [m('b', 'decided'), m('a', 'in-progress')].sort(byIndexOrder).map((x) => x.slug),
59
+ ['a', 'b'],
60
+ );
61
+ });
62
+
63
+ test('a presented take keeps the day the client saw it, and is no longer open work', () => {
64
+ const m = readMeta('x', readme('status: presented\npresented: 2026-11-24'));
65
+ assert.equal(m.presented, '2026-11-24');
66
+ assert.equal(readMeta('x', readme('status: exploring')).presented, '');
67
+ assert.equal(isLive(m), true);
68
+ assert.equal(isOpen(m), false);
69
+ assert.equal(isOpen({ status: 'archived' }), false);
70
+ assert.equal(isOpen({ status: 'decided' }), true);
71
+ });
72
+
46
73
  test('the track is read when known, and names the shell a prototype stands in', () => {
47
74
  assert.equal(readMeta('x', readme('track: website')).track, 'website');
48
75
  assert.equal(readMeta('x', readme('track: app')).track, '');
package/core/catalog.ts CHANGED
@@ -6,7 +6,9 @@ import { frontmatter } from './frontmatter.ts';
6
6
  import { TRACKS, type Track } from './project.ts';
7
7
  import { parseStates, type State } from './states.ts';
8
8
 
9
- export type Kind = 'sprint' | 'alternate' | 'exploration';
9
+ /** A tool makes assets for several features, so it answers no one feature's question and lists apart. */
10
+ export type Kind = 'sprint' | 'alternate' | 'exploration' | 'tool';
11
+ const KINDS: readonly string[] = ['sprint', 'alternate', 'exploration', 'tool'];
10
12
 
11
13
  export type Meta = {
12
14
  slug: string;
@@ -19,10 +21,20 @@ export type Meta = {
19
21
  kind: Kind;
20
22
  feature: string;
21
23
  created: string;
24
+ /** The day the client saw it, for `status: presented` (a take shown and not picked); empty otherwise. */
25
+ presented: string;
26
+ /** The one question it answers: the first paragraph under `## Question`; empty without one. */
27
+ question: string;
22
28
  /** null when the README has no States section. */
23
29
  states: State[] | null;
24
30
  };
25
31
 
32
+ /** The first paragraph under `## Question`, on one line. */
33
+ const questionOf = (readme: string) =>
34
+ (readme.match(/^## Question[ \t]*\n+([^\n#|][^\n]*(?:\n[^\n#|][^\n]*)*)/m)?.[1] ?? '')
35
+ .replace(/\s+/g, ' ')
36
+ .trim();
37
+
26
38
  export function readMeta(slug: string, readme: string): Meta {
27
39
  const { data } = frontmatter(readme);
28
40
  return {
@@ -32,17 +44,22 @@ export function readMeta(slug: string, readme: string): Meta {
32
44
  context: data.context || 'space',
33
45
  track: TRACKS.includes(data.track as Track) ? (data.track as Track) : '',
34
46
  status: data.status || 'exploring',
35
- kind: data.kind === 'sprint' || data.kind === 'alternate' ? data.kind : 'exploration',
47
+ kind: KINDS.includes(data.kind ?? '') ? (data.kind as Kind) : 'exploration',
36
48
  feature: data.feature || '',
37
49
  created: data.created || '',
50
+ presented: data.presented || '',
51
+ question: questionOf(readme),
38
52
  states: parseStates(readme),
39
53
  };
40
54
  }
41
55
 
42
56
  export const isLive = (m: Pick<Meta, 'status'>) => m.status !== 'archived';
43
57
 
44
- // Open questions sit above answered ones; within a status, newest first.
45
- const rank = (status: string) => (status === 'exploring' ? 0 : 1);
58
+ /** Still the feature's own work: neither archived nor a take the client saw and did not pick. */
59
+ export const isOpen = (m: Pick<Meta, 'status'>) => isLive(m) && m.status !== 'presented';
60
+
61
+ // Open work (a question being explored, a tool being built) sits above answered work; within a status, newest first.
62
+ const rank = (status: string) => (status === 'exploring' || status === 'in-progress' ? 0 : 1);
46
63
  export const byIndexOrder = (a: Meta, b: Meta) =>
47
64
  rank(a.status) - rank(b.status) || b.created.localeCompare(a.created) || a.title.localeCompare(b.title);
48
65
 
@@ -33,7 +33,8 @@ test('a prototype or project slug is kebab-case and never a first segment the ga
33
33
  });
34
34
 
35
35
  test('a client slug is kebab-case and never the studio’s own host names', () => {
36
- assert.deepEqual([...RESERVED_CLIENTS], ['studio', 'www', 'api']);
36
+ // `mail` too: the default sender's subdomain (email.md, E11).
37
+ assert.deepEqual([...RESERVED_CLIENTS], ['studio', 'www', 'api', 'mail']);
37
38
  for (const reserved of RESERVED_CLIENTS) assert.equal(isClientSlug(reserved), false, reserved);
38
39
  assert.equal(isClientSlug('acme'), true);
39
40
  // A prototype's reserved names are no concern of a host's.
@@ -143,6 +144,11 @@ test('a studio path goes to the link, the gate’s assets, the client’s hub, a
143
144
  for (const path of ['/api/review', '/api/files'])
144
145
  assert.deepEqual(route(path), { kind: 'api', project: null }, path);
145
146
  assert.deepEqual(route('/rebrand/api/review'), { kind: 'api', project: 'rebrand' });
147
+ // Email sign-in's two paths, exactly; anything near them is the hub's, as before.
148
+ assert.deepEqual(route('/_gate/code'), { kind: 'code', step: 'ask' });
149
+ assert.deepEqual(route('/_gate/code/use'), { kind: 'code', step: 'use' });
150
+ for (const path of ['/_gate/code/', '/_gate/code/use/', '/_gate/code/other'])
151
+ assert.deepEqual(route(path), { kind: 'hub' }, path);
146
152
  assert.deepEqual(route('/rebrand/'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
147
153
  assert.deepEqual(route('/rebrand'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
148
154
  assert.deepEqual(route('/rebrand/assets/index-x.js'), {
@@ -229,8 +235,11 @@ test('on the studio’s own host only its hub, its bundle, its API, a link, the
229
235
  ['/api/review', 'api'],
230
236
  ['/_gate/handoff', 'handoff'],
231
237
  [`/_gate/proof/${token}`, 'proof'],
238
+ ['/_gate/code', 'code'],
239
+ ['/_gate/code/use', 'code'],
232
240
  ];
233
241
  for (const [path, kind] of cases) assert.equal(studioRouteOf(path).kind, kind, path);
242
+ assert.deepEqual(studioRouteOf('/_gate/code/use'), { kind: 'code', step: 'use' });
234
243
  for (const path of [
235
244
  STUDIO_PAGE,
236
245
  '/index.html',
@@ -244,6 +253,8 @@ test('on the studio’s own host only its hub, its bundle, its API, a link, the
244
253
  '/_studio/%2e%2e/x',
245
254
  '/_gate/proof/x',
246
255
  `/_gate/handoff/${token}`,
256
+ '/_gate/code/',
257
+ '/_gate/code/other',
247
258
  ])
248
259
  assert.equal(studioRouteOf(path).kind, 'none', path);
249
260
  // A client host never reaches the studio hub's files.
package/core/prototype.ts CHANGED
@@ -19,8 +19,8 @@ export const RESERVED = [
19
19
  'favicon.svg',
20
20
  ] as const;
21
21
 
22
- /** Never a client's slug: the studio's own host, and the names a host is often given. */
23
- export const RESERVED_CLIENTS = ['studio', 'www', 'api'] as const;
22
+ /** Never a client's slug: the studio's own host, the names a host is often given, and `mail`, the default sender's subdomain (email.md, E11). */
23
+ export const RESERVED_CLIENTS = ['studio', 'www', 'api', 'mail'] as const;
24
24
 
25
25
  /**
26
26
  * Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
@@ -117,6 +117,17 @@ const HANDOFF_PATH = /^\/_gate\/handoff\/([\w-]{20,100})$/;
117
117
  export const handoffPath = (token: string) => `/_gate/handoff/${token}`;
118
118
  /** Where the studio hub asks for a handoff, on the studio's own host: a POST of the client and the project. */
119
119
  export const HANDOFF_START = '/_gate/handoff';
120
+ /**
121
+ * Email sign-in, on a client's host and on the studio's (email.md): a POST of
122
+ * an address asks for a code, a POST of the code uses it. The gate answers
123
+ * them only when the studio has a mailer; otherwise each is what any other
124
+ * path there is.
125
+ */
126
+ export const CODE_ASK = '/_gate/code';
127
+ export const CODE_USE = '/_gate/code/use';
128
+ type CodeStep = 'ask' | 'use';
129
+ const codeStep = (pathname: string): CodeStep | null =>
130
+ pathname === CODE_ASK ? 'ask' : pathname === CODE_USE ? 'use' : null;
120
131
  /**
121
132
  * The studio site's functions, at a client host's root: the review API, and
122
133
  * the files function the gate rewrites a project's files to. The gate passes
@@ -131,6 +142,7 @@ const FUNCTIONS: readonly string[] = ['review', 'files'];
131
142
  * - `link`: `/invite/<token>`, at the host root only.
132
143
  * - `handoff`: `/_gate/handoff/<token>`, a handoff's claim, at the host root only.
133
144
  * - `asset`: the gate's font and the favicon, served before sign-in.
145
+ * - `code`: `/_gate/code` and `/_gate/code/use`, email sign-in, when the studio has a mailer.
134
146
  * - `hub`: the client's hub page and its own files (`/`, `/index.html`, `/assets/…`, `/_gate/…`).
135
147
  * - `api`: a function at the root (`project` null), or a project's review API, `/<project>/api/review`.
136
148
  * - `file`: a file of a project's build, as its segments ([] for the project's own page), and
@@ -141,6 +153,7 @@ export type Where =
141
153
  | { kind: 'link'; token: string }
142
154
  | { kind: 'handoff'; token: string }
143
155
  | { kind: 'asset' }
156
+ | { kind: 'code'; step: CodeStep }
144
157
  | { kind: 'hub' }
145
158
  | { kind: 'api'; project: string | null }
146
159
  | { kind: 'file'; project: string; file: string[]; prototype: string | null };
@@ -168,6 +181,8 @@ function where(pathname: string): Where {
168
181
  const handoff = pathname.match(HANDOFF_PATH);
169
182
  if (handoff) return { kind: 'handoff', token: handoff[1] };
170
183
  if (GATE_ASSETS.includes(pathname)) return { kind: 'asset' };
184
+ const step = codeStep(pathname);
185
+ if (step) return { kind: 'code', step };
171
186
  const parts = segments(pathname);
172
187
  if (!parts) return { kind: 'none' };
173
188
  const [first, ...rest] = parts;
@@ -199,6 +214,7 @@ export const STUDIO_PAGE = '/studio.html';
199
214
  * - `file`: the studio hub's bundle, below `/_studio/`.
200
215
  * - `api`: `/api/review`, where the studio hub reads every client.
201
216
  * - `handoff`: `/_gate/handoff`, where the studio hub asks to open a client.
217
+ * - `code`: `/_gate/code` and `/_gate/code/use`, a Studio person's email sign-in.
202
218
  * - `proof`: `/_gate/proof/<ask>`, the host proof `studio create` and
203
219
  * `studio deploy` ask the studio's own host for, as `client add` asks a client's.
204
220
  */
@@ -210,6 +226,7 @@ export type StudioWhere =
210
226
  | { kind: 'file' }
211
227
  | { kind: 'api' }
212
228
  | { kind: 'handoff' }
229
+ | { kind: 'code'; step: CodeStep }
213
230
  | { kind: 'proof'; ask: string };
214
231
 
215
232
  /** The one place a request's path on the studio's own host is read. It fails closed, as routeOf does. */
@@ -220,6 +237,8 @@ export function studioRouteOf(pathname: string): StudioWhere {
220
237
  if (pathname === '/') return { kind: 'page' };
221
238
  if (pathname === '/api/review') return { kind: 'api' };
222
239
  if (pathname === HANDOFF_START) return { kind: 'handoff' };
240
+ const step = codeStep(pathname);
241
+ if (step) return { kind: 'code', step };
223
242
  const proof = pathname.match(PROOF_PATH);
224
243
  if (proof) return { kind: 'proof', ask: proof[1] };
225
244
  const parts = segments(pathname);
@@ -89,7 +89,12 @@ export type Person = {
89
89
  * client. Never stored in the profile: it is where the person's records live.
90
90
  */
91
91
  client: string | null;
92
- /** Always null until email sign-in exists. */
92
+ /**
93
+ * The address they sign in with by code (lower case, trimmed), or null for
94
+ * links only. Within one client's people, or the studio's own, one live
95
+ * person holds an address (`emails` in store.ts). A profile stored before
96
+ * email existed reads as null.
97
+ */
93
98
  email: string | null;
94
99
  /** When their access ends (ISO time), or null for open-ended. Their sessions end with it. */
95
100
  accessEndsAt: string | null;
@@ -151,6 +156,17 @@ export type Project = { slug: string; client: string; name: string; build: strin
151
156
  /** A one-time sign-in link, stored under the hash of its token and deleted when used. */
152
157
  export type Link = { person: string; expiresAt: string };
153
158
 
159
+ /**
160
+ * A person's one live sign-in code (`codes` in store.ts): an HMAC of the code
161
+ * under a key the service is given, never the code or a bare digest, since
162
+ * 8 digits can be tried in full. A new code replaces it; a right answer
163
+ * removes it.
164
+ */
165
+ export type Code = { hash: string; expiresAt: string; sentAt: string };
166
+
167
+ /** The code rules (E6): 8 digits, 10 minutes, 5 wrong tries, one a minute and 5 an hour per person. */
168
+ export const CODE = { digits: 8, minutes: 10, tries: 5, gapSeconds: 60, perHour: 5 } as const;
169
+
154
170
  /**
155
171
  * A handoff: a Studio person, signed in on the studio's host, opening one
156
172
  * client's hub (or one of its projects) on that client's host. Stored with
@@ -239,7 +255,8 @@ const PROFILE_RULES: [string, (v: unknown) => boolean][] = [
239
255
  ['name', isText],
240
256
  ['team', isText],
241
257
  ['kind', (v) => PERSON_KINDS.includes(v as PersonKind)],
242
- ['email', isTextOrNull],
258
+ // Absent on a profile stored before email existed: it reads as null (no migration).
259
+ ['email', (v) => v === undefined || isTextOrNull(v)],
243
260
  ['accessEndsAt', isTextOrNull],
244
261
  ['createdAt', isText],
245
262
  ];
@@ -273,6 +290,12 @@ export const isRoot = (c: Comment) => c.thread === c.id;
273
290
 
274
291
  export type Checked<T> = { ok: true; value: T } | { ok: false; problems: string[] };
275
292
 
293
+ /** What a refusal says when it names fields only: the panel then shows the fields' problems. */
294
+ export const NOT_VALID = 'Some fields are not valid.';
295
+ /** What a refusal says when an address is the one thing wrong, so a person reads a sentence, not a field. */
296
+ export const NOT_AN_EMAIL =
297
+ 'That is not an email address. Use one such as name@example.com, or leave it empty.';
298
+
276
299
  const text = (v: unknown, path: string, max: number, problems: string[]): string => {
277
300
  if (typeof v !== 'string' || !v.trim()) {
278
301
  problems.push(`${path}: required`);
@@ -293,13 +316,39 @@ export function checkAccess(input: unknown): Checked<Access> {
293
316
  return isAccess(input) ? { ok: true, value: input } : { ok: false, problems: [ACCESS_PROBLEM] };
294
317
  }
295
318
 
296
- /** `team` absent: the service fills it, the studio's name for Studio and the client's for a Client. */
297
- export type PersonInput = Pick<Person, 'name' | 'kind'> & { team?: string; access: Access | null };
319
+ /**
320
+ * What an address may be: the form a browser's email field takes (WHATWG),
321
+ * lower case, 254 characters at most. Nothing in it can split a mail header
322
+ * or name a second recipient: no space, comma, semicolon, angle bracket or quote.
323
+ */
324
+ const EMAIL =
325
+ /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
326
+ const EMAIL_MAX = 254;
327
+ export const EMAIL_PROBLEM = 'email: an address such as name@example.com, or empty for links only';
328
+
329
+ /** An address as stored: trimmed and lower case, or null when it is not one. */
330
+ export function emailOf(input: unknown): string | null {
331
+ if (typeof input !== 'string') return null;
332
+ const address = input.trim().toLowerCase();
333
+ return address.length <= EMAIL_MAX && EMAIL.test(address) ? address : null;
334
+ }
335
+
336
+ /** An address as Studio sets it: null, or empty, is links only; anything else must be an address. */
337
+ export function checkEmail(input: unknown): Checked<string | null> {
338
+ if (input === null || (typeof input === 'string' && input.trim() === '')) return { ok: true, value: null };
339
+ const address = emailOf(input);
340
+ return address ? { ok: true, value: address } : { ok: false, problems: [EMAIL_PROBLEM] };
341
+ }
342
+
343
+ /** `team` absent: the service fills it, the studio's name for Studio and the client's for a Client. `email` absent is links only. */
344
+ export type PersonInput = Pick<Person, 'name' | 'kind' | 'email'> & { team?: string; access: Access | null };
298
345
 
299
346
  export function checkPersonInput(input: unknown): Checked<PersonInput> {
300
347
  const i = (input ?? {}) as Record<string, unknown>;
301
348
  const problems: string[] = [];
302
349
  const name = text(i.name, 'name', LIMITS.name, problems);
350
+ const email = checkEmail(i.email ?? null);
351
+ if (!email.ok) problems.push(...email.problems);
303
352
  const team = i.team === undefined ? undefined : text(i.team, 'team', LIMITS.team, problems);
304
353
  // Most people added are on the client's side; Studio is the deliberate choice.
305
354
  const kind = i.kind ?? 'client';
@@ -315,6 +364,7 @@ export function checkPersonInput(input: unknown): Checked<PersonInput> {
315
364
  name,
316
365
  ...(team === undefined ? {} : { team }),
317
366
  kind: kind as PersonKind,
367
+ email: email.ok ? email.value : null,
318
368
  access: access as Access | null,
319
369
  },
320
370
  };
@@ -430,14 +480,29 @@ const isSlug = (v: unknown) => typeof v === 'string' && SLUG.test(v);
430
480
  const isObject = (v: unknown): v is Record<string, unknown> =>
431
481
  !!v && typeof v === 'object' && !Array.isArray(v);
432
482
 
483
+ const PATH_BASE = 'https://path.invalid';
484
+ /**
485
+ * A path on the page's own site. Starting with `/` is not enough: a browser
486
+ * reads `//host`, `/\host` and `/<tab>/host` as another site, so the path is
487
+ * resolved the way a browser would and must stay on the same origin.
488
+ */
489
+ export function isSitePath(v: unknown): v is string {
490
+ if (typeof v !== 'string' || !v.startsWith('/')) return false;
491
+ try {
492
+ return new URL(v, PATH_BASE).origin === PATH_BASE;
493
+ } catch {
494
+ return false;
495
+ }
496
+ }
497
+
433
498
  /** One rule per field: the field, whether a value passes, and what the field must be. */
434
499
  const ANCHOR_RULES: [keyof Anchor, (v: unknown) => boolean, string][] = [
435
500
  ['prototype', isSlug, 'a prototype slug'],
436
501
  ['feature', (v) => v === '' || isSlug(v), 'a feature slug or empty'],
437
502
  [
438
503
  'url',
439
- (v) => typeof v === 'string' && v.startsWith('/') && v.length <= LIMITS.url,
440
- `a path starting with /, ${LIMITS.url} characters at most`,
504
+ (v) => isSitePath(v) && v.length <= LIMITS.url,
505
+ `a path on this site starting with /, ${LIMITS.url} characters at most`,
441
506
  ],
442
507
  [
443
508
  'dials',