@milesroxas/design-hub 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +7 -2
  2. package/core/prototype.test.ts +83 -0
  3. package/core/prototype.ts +84 -0
  4. package/core/review/model.ts +7 -0
  5. package/core/review/policy.test.ts +4 -2
  6. package/core/review/policy.ts +4 -2
  7. package/core/review/service.test.ts +144 -4
  8. package/core/review/service.ts +70 -2
  9. package/core/review/store.ts +6 -0
  10. package/dist/core/prototype.d.ts +35 -0
  11. package/dist/core/prototype.js +84 -0
  12. package/dist/core/review/model.d.ts +2 -0
  13. package/dist/core/review/model.js +6 -0
  14. package/dist/core/review/policy.d.ts +1 -1
  15. package/dist/core/review/policy.js +1 -0
  16. package/dist/core/review/service.d.ts +23 -1
  17. package/dist/core/review/service.js +62 -3
  18. package/dist/core/review/store.d.ts +6 -0
  19. package/dist/core/review/store.js +6 -0
  20. package/dist/scripts/lib/cdp.js +6 -1
  21. package/dist/scripts/lib/export-smoke.d.ts +18 -0
  22. package/dist/scripts/lib/export-smoke.js +73 -0
  23. package/dist/scripts/new.js +5 -2
  24. package/dist/scripts/release-check.d.ts +5 -3
  25. package/dist/scripts/release-check.js +17 -4
  26. package/dist/scripts/share.d.ts +2 -2
  27. package/dist/server/api.js +8 -0
  28. package/dist/server/session.d.ts +5 -1
  29. package/dist/server/session.js +39 -21
  30. package/dist/vercel/proxy.js +44 -8
  31. package/dist/vite/boundary.d.ts +93 -0
  32. package/dist/vite/boundary.js +218 -0
  33. package/dist/vite/css-boundary.d.ts +39 -0
  34. package/dist/vite/css-boundary.js +167 -0
  35. package/dist/vite/kit.js +15 -6
  36. package/dist/vite/leaks.d.ts +37 -0
  37. package/dist/vite/leaks.js +331 -0
  38. package/dist/vite/plugin.js +2 -1
  39. package/dist/vite/registry.d.ts +15 -4
  40. package/dist/vite/registry.js +531 -27
  41. package/dist/vite/settle.d.ts +27 -0
  42. package/dist/vite/settle.js +185 -0
  43. package/package.json +4 -3
  44. package/shell/ClientViewNote.tsx +18 -0
  45. package/shell/Guide.tsx +17 -2
  46. package/shell/Index.tsx +257 -25
  47. package/shell/audience.test.ts +63 -0
  48. package/shell/audience.ts +47 -0
  49. package/shell/hub.ts +36 -0
  50. package/shell/main.tsx +39 -5
  51. package/shell/registry.ts +28 -7
  52. package/shell/registry.virtual.d.ts +12 -4
  53. package/shell/review/client.ts +16 -4
  54. package/shell/review/review.css +2 -2
  55. package/shell/shell.css +50 -3
  56. package/shell/system.css +5 -0
  57. package/skills/miles-deploy/SKILL.md +17 -0
  58. package/skills/miles-new-feature/SKILL.md +1 -1
  59. package/skills/miles-prototype/SKILL.md +14 -1
@@ -0,0 +1,84 @@
1
+ // What a prototype's slug may be, and where the files built from it live.
2
+ // One rule for the registry's scan, `design-hub new` and the gate, so a
3
+ // folder the hub lists is always a path the gate knows how to refuse.
4
+ import { SLUG } from './feature.js';
5
+ /**
6
+ * First path segments the hub owns, never a prototype: the walkthroughs,
7
+ * the review API, and the shared bundle.
8
+ */
9
+ export const RESERVED = ['guide', 'api', 'assets'];
10
+ /**
11
+ * Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
12
+ * Studio's list of every slug at `/_p/all.js`. `_p` can never be a slug: SLUG
13
+ * has no underscore.
14
+ */
15
+ export const PROTOTYPE_DIR = '_p';
16
+ export const ALL_FILE = `${PROTOTYPE_DIR}/all.js`;
17
+ export const entryFile = (slug) => `${PROTOTYPE_DIR}/${slug}/entry.js`;
18
+ /** Whether `name` can be a prototype's folder: kebab-case and not one of the hub's own paths. */
19
+ export const isPrototypeSlug = (name) => typeof name === 'string' && SLUG.test(name) && !RESERVED.includes(name);
20
+ /**
21
+ * A path's segments as a file server might read them, or null when the path
22
+ * could mean more than one file: it does not decode, still holds a `%` after
23
+ * decoding (`%255F`), holds a backslash, a `.` or `..` segment, or an empty
24
+ * segment other than the last. The gate refuses those to a Client rather than
25
+ * guess how the server resolves them. An encoded space or letter decodes and passes.
26
+ */
27
+ function segments(pathname) {
28
+ let decoded;
29
+ try {
30
+ decoded = decodeURIComponent(pathname);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ if (/[%\\]/.test(decoded))
36
+ return null;
37
+ const parts = decoded.split('/').slice(1);
38
+ if (parts.at(-1) === '')
39
+ parts.pop();
40
+ return parts.some((p) => p === '' || p === '.' || p === '..') ? null : parts;
41
+ }
42
+ /**
43
+ * The first path segments that are the hub's own, for anyone signed in: the
44
+ * reserved routes, the gate's font folder, and the files the hub serves at
45
+ * the top (shell/index.html, shell/public/favicon.svg).
46
+ */
47
+ const HUB_ROOT = [...RESERVED, '_gate', 'index.html', 'favicon.svg'];
48
+ /**
49
+ * Which prototype a request path belongs to, for the gate: the name a
50
+ * prototype path carries, or null for a hub path (`/`, or a first segment in
51
+ * HUB_ROOT). The first segment, decoded, must be one of those, `_p`, or a
52
+ * prototype slug; anything else (`_P`, `_p;x`, `_p.`, a full-width `_p`)
53
+ * belongs to `''`, refused like an internal prototype. A path under `/_p/`
54
+ * always belongs to one, so its name may be no slug at all (`all.js`), which
55
+ * no audience makes client-facing. A path that could mean more than one file
56
+ * belongs to `''` too.
57
+ */
58
+ export function prototypeOfPath(pathname) {
59
+ const parts = segments(pathname);
60
+ if (!parts)
61
+ return '';
62
+ const [first, second] = parts;
63
+ if (first === undefined || HUB_ROOT.includes(first))
64
+ return null;
65
+ if (first === PROTOTYPE_DIR)
66
+ return second ?? '';
67
+ return isPrototypeSlug(first) ? first : '';
68
+ }
69
+ /**
70
+ * Whether a built prototype's entry is there for this person, asked with a
71
+ * HEAD before it is imported. Not there: a 404 (the gate's answer for a
72
+ * prototype this person may not open, or none at all), or a 200 that is not
73
+ * JavaScript (the host's page for an entry that was never built). Any other
74
+ * answer (401, 500, 503) is an error, never "not there", so an outage never
75
+ * reads as nothing shared.
76
+ */
77
+ export async function probeEntry(path, fetcher) {
78
+ const head = await fetcher(path, { method: 'HEAD', credentials: 'same-origin' });
79
+ if (head.status === 404)
80
+ return false;
81
+ if (head.status !== 200)
82
+ throw new Error(`${path} answered ${head.status}.`);
83
+ return /javascript/.test(head.headers.get('content-type') ?? '');
84
+ }
@@ -140,6 +140,8 @@ export type PersonInput = Pick<Person, 'name' | 'team' | 'kind'> & {
140
140
  export declare function checkPersonInput(input: unknown): Checked<PersonInput>;
141
141
  /** A new thread's audience as asked: one of AUDIENCES, or null when none is given. */
142
142
  export declare function checkAudience(input: unknown): Checked<Audience | null>;
143
+ /** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
144
+ export declare function checkPrototypeAudience(input: unknown): Checked<Audience>;
143
145
  /** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
144
146
  export declare function checkViewAs(input: unknown): Checked<PersonKind | null>;
145
147
  export declare function checkBody(body: unknown): Checked<string>;
@@ -140,6 +140,12 @@ export function checkAudience(input) {
140
140
  ? { ok: true, value: input }
141
141
  : { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
142
142
  }
143
+ /** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
144
+ export function checkPrototypeAudience(input) {
145
+ return AUDIENCES.includes(input)
146
+ ? { ok: true, value: input }
147
+ : { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
148
+ }
143
149
  /** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
144
150
  export function checkViewAs(input) {
145
151
  if (input === undefined || input === null)
@@ -1,5 +1,5 @@
1
1
  import type { Audience, Comment, Person, PersonKind } from './model.ts';
2
- export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people';
2
+ export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people' | 'audience';
3
3
  /** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
4
4
  type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
5
5
  /**
@@ -23,6 +23,7 @@ export function can(actor, action, root, subject) {
23
23
  return own || studio;
24
24
  case 'triage':
25
25
  case 'people':
26
+ case 'audience':
26
27
  return studio;
27
28
  }
28
29
  }
@@ -1,4 +1,4 @@
1
- import { type Access, type Comment, type Person, type Triage } from './model.ts';
1
+ import { type Access, type Audience, type Comment, type Person, type PersonKind, type Triage } from './model.ts';
2
2
  import { type KV } from './store.ts';
3
3
  export type ErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'invalid';
4
4
  export declare class ReviewError extends Error {
@@ -98,6 +98,28 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
98
98
  triage?: unknown;
99
99
  states?: unknown;
100
100
  }): Promise<Comment>;
101
+ /**
102
+ * Marks a prototype client-facing or internal. Only client-facing is
103
+ * stored, so internal deletes the field and a prototype nobody marked is
104
+ * internal. Studio only.
105
+ */
106
+ setAudience(actor: Person | null, prototype: unknown, audience: unknown): Promise<Audience>;
107
+ /**
108
+ * Who a prototype is for, asked by the gate with no actor. Absent, or any
109
+ * value but `client`, is internal; a name that cannot be a prototype is
110
+ * internal without asking the store.
111
+ */
112
+ audienceOf(prototype: string): Promise<Audience>;
113
+ /**
114
+ * What the index is built from: the view the actor gets (Client view for
115
+ * Studio with `viewAs: 'client'`) and every client-facing slug. The
116
+ * server keeps no list of internal ones: Studio's view reads the build's
117
+ * own list, which the gate refuses to a Client.
118
+ */
119
+ visiblePrototypes(actor: Person | null, viewAs?: unknown): Promise<{
120
+ view: PersonKind;
121
+ clientFacing: string[];
122
+ }>;
101
123
  /** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
102
124
  locate(actor: Person | null, id: string): Promise<{
103
125
  prototype: string;
@@ -5,7 +5,8 @@
5
5
  // person, per comment), so two people commenting at once never collide;
6
6
  // two edits of the same comment at once keep the last.
7
7
  import { base64url, hex, sha256 } from '../bytes.js';
8
- import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkPersonInput, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
8
+ import { isPrototypeSlug } from '../prototype.js';
9
+ import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkPersonInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
9
10
  import { audienceFor, can, viewOf, visibleTo } from './policy.js';
10
11
  import { KEY } from './store.js';
11
12
  export class ReviewError extends Error {
@@ -159,11 +160,20 @@ export function createReview(kv, overrides = {}) {
159
160
  return json === null ? null : readComment(json);
160
161
  };
161
162
  const saveComment = (prototype, c) => kv.hset(KEY.comments(prototype), c.id, JSON.stringify(c));
163
+ const isClientFacing = async (prototype) => isPrototypeSlug(prototype) && (await kv.hget(KEY.audiences, prototype)) === 'client';
164
+ /**
165
+ * Whether a view reaches a prototype's comments at all. A Client's view
166
+ * reaches only a client-facing prototype: on any other, every op answers
167
+ * as if it had no comments, so no answer confirms an internal slug.
168
+ */
169
+ const reachable = async (view, prototype) => view === 'studio' || (await isClientFacing(prototype));
162
170
  /**
163
171
  * A comment and its thread's root, if `actor` may see both; else null. A
164
172
  * reply whose root is gone is not there either.
165
173
  */
166
174
  async function seen(actor, prototype, id) {
175
+ if (!(await reachable(viewOf(actor), prototype)))
176
+ return null;
167
177
  const comment = await commentAt(prototype, id);
168
178
  if (!comment)
169
179
  return null;
@@ -307,13 +317,19 @@ export function createReview(kv, overrides = {}) {
307
317
  async listComments(actor, prototype, viewAs) {
308
318
  allow(actor, 'read');
309
319
  const view = viewOf(actor, valid(checkViewAs(viewAs)));
320
+ if (!(await reachable(view, prototype)))
321
+ return [];
310
322
  return visibleTo(view, await commentsOf(prototype));
311
323
  },
312
324
  /** Every comment on every prototype the actor may see, for the CLI (which acts as Studio). */
313
325
  async allComments(actor) {
314
326
  allow(actor, 'read');
315
- const prototypes = await kv.smembers(KEY.prototypes);
316
- return visibleTo(viewOf(actor), (await Promise.all(prototypes.map(commentsOf))).flat());
327
+ const view = viewOf(actor);
328
+ const prototypes = [];
329
+ for (const p of await kv.smembers(KEY.prototypes))
330
+ if (await reachable(view, p))
331
+ prototypes.push(p);
332
+ return visibleTo(view, (await Promise.all(prototypes.map(commentsOf))).flat());
317
333
  },
318
334
  /**
319
335
  * A new thread. A Client's is client-facing whatever the input says;
@@ -323,6 +339,9 @@ export function createReview(kv, overrides = {}) {
323
339
  async add(actor, input) {
324
340
  allow(actor, 'comment');
325
341
  const [body, anchor, asked] = validAll(checkBody(input.body), checkAnchor(input.anchor), checkAudience(input.audience));
342
+ // A Client's thread on a prototype that is not client-facing: the answer an unknown id gets.
343
+ if (!(await reachable(viewOf(actor), anchor.prototype)))
344
+ throw new ReviewError('not_found', 'No such comment.');
326
345
  const id = newId();
327
346
  const triage = deps.triage
328
347
  ? await deps
@@ -407,6 +426,46 @@ export function createReview(kv, overrides = {}) {
407
426
  await saveComment(input.prototype, next);
408
427
  return next;
409
428
  },
429
+ /**
430
+ * Marks a prototype client-facing or internal. Only client-facing is
431
+ * stored, so internal deletes the field and a prototype nobody marked is
432
+ * internal. Studio only.
433
+ */
434
+ async setAudience(actor, prototype, audience) {
435
+ allow(actor, 'audience');
436
+ const [slug, value] = validAll(isPrototypeSlug(prototype)
437
+ ? { ok: true, value: prototype }
438
+ : { ok: false, problems: ['prototype: a prototype slug'] }, checkPrototypeAudience(audience));
439
+ if (value === 'client')
440
+ await kv.hset(KEY.audiences, slug, 'client');
441
+ else
442
+ await kv.hdel(KEY.audiences, slug);
443
+ return value;
444
+ },
445
+ /**
446
+ * Who a prototype is for, asked by the gate with no actor. Absent, or any
447
+ * value but `client`, is internal; a name that cannot be a prototype is
448
+ * internal without asking the store.
449
+ */
450
+ async audienceOf(prototype) {
451
+ return (await isClientFacing(prototype)) ? 'client' : 'internal';
452
+ },
453
+ /**
454
+ * What the index is built from: the view the actor gets (Client view for
455
+ * Studio with `viewAs: 'client'`) and every client-facing slug. The
456
+ * server keeps no list of internal ones: Studio's view reads the build's
457
+ * own list, which the gate refuses to a Client.
458
+ */
459
+ async visiblePrototypes(actor, viewAs) {
460
+ allow(actor, 'read');
461
+ const view = viewOf(actor, valid(checkViewAs(viewAs)));
462
+ const all = await kv.hgetall(KEY.audiences);
463
+ const clientFacing = Object.entries(all)
464
+ .filter(([slug, value]) => value === 'client' && isPrototypeSlug(slug))
465
+ .map(([slug]) => slug)
466
+ .sort();
467
+ return { view, clientFacing };
468
+ },
410
469
  /** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
411
470
  async locate(actor, id) {
412
471
  allow(actor, 'read');
@@ -21,6 +21,12 @@ export declare const KEY: {
21
21
  /** Project settings, one field each: `access` is the default access length. */
22
22
  readonly settings: "hub3:settings";
23
23
  readonly prototypes: "hub3:prototypes";
24
+ /**
25
+ * Which prototypes are client-facing: field `<slug>`, value `client`. Only
26
+ * client-facing is stored; internal is the field's absence, and any other
27
+ * value reads as internal too.
28
+ */
29
+ readonly audiences: "hub3:audiences";
24
30
  /**
25
31
  * The last thread number given on each prototype, only ever raised by HINCRBY: field
26
32
  * `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
@@ -20,6 +20,12 @@ export const KEY = {
20
20
  /** Project settings, one field each: `access` is the default access length. */
21
21
  settings: `${PREFIX}settings`,
22
22
  prototypes: `${PREFIX}prototypes`,
23
+ /**
24
+ * Which prototypes are client-facing: field `<slug>`, value `client`. Only
25
+ * client-facing is stored; internal is the field's absence, and any other
26
+ * value reads as internal too.
27
+ */
28
+ audiences: `${PREFIX}audiences`,
23
29
  /**
24
30
  * The last thread number given on each prototype, only ever raised by HINCRBY: field
25
31
  * `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
@@ -41,6 +41,9 @@ export async function launch(chrome) {
41
41
  `--user-data-dir=${profile}`,
42
42
  '--no-first-run',
43
43
  '--no-default-browser-check',
44
+ // No component updates or background fetches: an export needs neither, and their fetcher leaves a temp folder.
45
+ '--disable-component-update',
46
+ '--disable-background-networking',
44
47
  '--hide-scrollbars',
45
48
  '--mute-audio',
46
49
  '--force-color-profile=srgb',
@@ -49,7 +52,9 @@ export async function launch(chrome) {
49
52
  const exited = new Promise((resolve) => child.once('exit', () => resolve()));
50
53
  // The profile goes once Chrome has let go of it; a leftover temp folder is not worth failing an export over.
51
54
  const cleanup = async () => {
52
- if (child.exitCode === null)
55
+ // Let Chrome exit on its own first: killed, it leaves its temp folders behind.
56
+ await within(exited, CLOSE_TIMEOUT_MS);
57
+ if (child.exitCode === null && child.signalCode === null)
53
58
  child.kill('SIGKILL');
54
59
  await within(exited, CLOSE_TIMEOUT_MS);
55
60
  try {
@@ -0,0 +1,18 @@
1
+ /** `root` is the throwaway project, removed before this returns. */
2
+ export type Smoke = {
3
+ ran: true;
4
+ files: string[];
5
+ root: string;
6
+ } | {
7
+ ran: false;
8
+ reason: string;
9
+ };
10
+ /** The browser export would use, or null. */
11
+ export declare const findChrome: () => string | null;
12
+ /**
13
+ * Exports the brand template's one artboard through `cli` (the CLI entry:
14
+ * the source `scripts/cli.ts` or the built `dist/scripts/cli.js`) and
15
+ * checks a PNG came out. Not run without Chrome, saying so. Throws, with
16
+ * what the command printed, when the export fails. Leaves nothing behind.
17
+ */
18
+ export declare function exportSmoke(cli: string): Promise<Smoke>;
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+ // A real `design-hub export` of one brand prototype on a cold cache: a
3
+ // throwaway project with the package's brand template, the CLI run in a
4
+ // child process of its own (ROOT is fixed when paths.ts loads), and the
5
+ // PNG it writes checked. Export is the one command that starts the hub
6
+ // with no one watching, so a break in it shows only when someone runs it.
7
+ // `scripts/export.test.ts` runs this when Chrome is found and skips with the
8
+ // reason when it is not; `release-check` runs it and fails without Chrome.
9
+ import { execFile } from 'node:child_process';
10
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync, } from 'node:fs';
11
+ import { tmpdir } from 'node:os';
12
+ import { join } from 'node:path';
13
+ import { chromeCandidates } from '../../core/export.js';
14
+ import { TEMPLATES } from '../../server/paths.js';
15
+ const SLUG = 'smoke-post';
16
+ const TIMEOUT_MS = 180_000;
17
+ const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
18
+ /** The browser export would use, or null. */
19
+ export const findChrome = () => chromeCandidates(process.platform, process.env).find((p) => existsSync(p)) ?? null;
20
+ /** A project with one brand prototype from the package's template, and the kit file the hub imports. */
21
+ function project() {
22
+ // Real, as the CLI reads $DESIGN_HUB_ROOT, so the files it names are relative to this folder.
23
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'hub-export-')));
24
+ mkdirSync(join(root, 'kit'), { recursive: true });
25
+ writeFileSync(join(root, 'kit', 'tokens.css'), ':root { --t: 1; }\n');
26
+ const dir = join(root, 'prototypes', SLUG);
27
+ cpSync(join(TEMPLATES, 'brand'), dir, { recursive: true });
28
+ const vars = {
29
+ title: 'Smoke post',
30
+ slug: SLUG,
31
+ created: '2030-01-01',
32
+ kind: 'exploration',
33
+ feature: "''",
34
+ track: 'brand',
35
+ };
36
+ for (const name of readdirSync(dir)) {
37
+ let text = readFileSync(join(dir, name), 'utf8');
38
+ for (const [k, v] of Object.entries(vars))
39
+ text = text.replaceAll(`{{${k}}}`, v);
40
+ writeFileSync(join(dir, name), text);
41
+ }
42
+ return root;
43
+ }
44
+ const run = (cli, root) => new Promise((done) => {
45
+ execFile(process.execPath, [cli, 'export', SLUG, '--out', join(root, 'exports')], { cwd: root, env: { ...process.env, DESIGN_HUB_ROOT: root }, timeout: TIMEOUT_MS, encoding: 'utf8' }, (error, stdout, stderr) => done({ code: error ? Number(error.code ?? 1) || 1 : 0, stdout, stderr }));
46
+ });
47
+ /**
48
+ * Exports the brand template's one artboard through `cli` (the CLI entry:
49
+ * the source `scripts/cli.ts` or the built `dist/scripts/cli.js`) and
50
+ * checks a PNG came out. Not run without Chrome, saying so. Throws, with
51
+ * what the command printed, when the export fails. Leaves nothing behind.
52
+ */
53
+ export async function exportSmoke(cli) {
54
+ if (!findChrome())
55
+ return { ran: false, reason: 'No Chrome, Chromium or Edge found; set CHROME_PATH to one.' };
56
+ const root = project();
57
+ try {
58
+ const { code, stdout, stderr } = await run(cli, root);
59
+ let out = {};
60
+ try {
61
+ out = JSON.parse(stdout);
62
+ }
63
+ catch { }
64
+ const files = (out.files ?? []).map((f) => join(root, f));
65
+ const pngs = files.filter((f) => existsSync(f) && readFileSync(f).subarray(0, 4).equals(PNG));
66
+ if (code !== 0 || out.ok !== true || !pngs.length)
67
+ throw new Error(`design-hub export failed (exit ${code}):\n${stdout}\n${stderr}`.trim());
68
+ return { ran: true, files: (out.files ?? []).map(String), root };
69
+ }
70
+ finally {
71
+ rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
72
+ }
73
+ }
@@ -9,6 +9,7 @@ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, wri
9
9
  import { dirname, join, relative } from 'node:path';
10
10
  import { featureTitle, guideHref, SLUG } from '../core/feature.js';
11
11
  import { TRACKS, trackFor } from '../core/project.js';
12
+ import { isPrototypeSlug, RESERVED } from '../core/prototype.js';
12
13
  import { devPort, readEnv } from '../server/env.js';
13
14
  import { DOCS, PROTOTYPES, ROOT, TEMPLATES } from '../server/paths.js';
14
15
  import { readProject } from '../server/project.js';
@@ -120,8 +121,10 @@ export function kindFor(flags, feature, primary = (f) => primaryOf(f)?.slug) {
120
121
  function prototype(slug, { flags }) {
121
122
  if (!SLUG.test(slug))
122
123
  throw new CliError('The slug is kebab-case.', { got: slug });
123
- if (slug === 'guide')
124
- throw new CliError('guide/ is the walkthrough route; pick another slug.');
124
+ if (!isPrototypeSlug(slug))
125
+ throw new CliError(`${slug}/ is the hub's own path (${RESERVED.join(', ')}); pick another slug.`, {
126
+ got: slug,
127
+ });
125
128
  const feature = flags.feature ?? '';
126
129
  if (feature && !SLUG.test(feature))
127
130
  throw new CliError('--feature takes a kebab-case slug.', { got: feature });
@@ -9,11 +9,13 @@ export declare const spec: {
9
9
  readonly description: 'A term to refuse, case-insensitive. Repeat for more.';
10
10
  };
11
11
  };
12
- readonly output: '{ ok, terms, files, hits: { <file>: [terms] } }';
12
+ readonly output: '{ ok, terms, files, hits: { <file>: [terms] }, export: { ran, files | reason } }';
13
13
  };
14
- export declare function main({ flags }: Args<typeof spec>): {
14
+ export declare function main({ flags }: Args<typeof spec>): Promise<{
15
15
  ok: boolean;
16
16
  terms: string[];
17
17
  files: number;
18
18
  hits: Record<string, string[]>;
19
- };
19
+ export: import("./lib/export-smoke.ts").Smoke;
20
+ fix?: string | undefined;
21
+ }>;
@@ -3,19 +3,22 @@
3
3
  // The gate before a repo is published: no tracked file may contain a
4
4
  // term from the list, case-insensitive (a client's name, a person's name).
5
5
  // Tracked means `git ls-files`, so an untracked plan never trips it and a
6
- // gitignored secret never hides a hit.
6
+ // gitignored secret never hides a hit. It also runs a real cold
7
+ // `design-hub export` (scripts/lib/export-smoke.ts), which `pnpm test`
8
+ // skips on a machine without Chrome: here no Chrome is a failure.
7
9
  import { execFileSync } from 'node:child_process';
8
10
  import { readFileSync } from 'node:fs';
9
11
  import { join } from 'node:path';
10
12
  import { ROOT } from '../server/paths.js';
11
13
  import { CliError } from './lib/cli.js';
14
+ import { exportSmoke } from './lib/export-smoke.js';
12
15
  export const spec = {
13
16
  name: 'release-check',
14
17
  summary: 'Fail when any tracked file contains one of the given terms.',
15
18
  flags: { term: { type: 'list', description: 'A term to refuse, case-insensitive. Repeat for more.' } },
16
- output: '{ ok, terms, files, hits: { <file>: [terms] } }',
19
+ output: '{ ok, terms, files, hits: { <file>: [terms] }, export: { ran, files | reason } }',
17
20
  };
18
- export function main({ flags }) {
21
+ export async function main({ flags }) {
19
22
  const terms = flags.term.map((t) => t.toLowerCase()).filter(Boolean);
20
23
  if (!terms.length)
21
24
  throw new CliError('Give at least one --term.');
@@ -35,5 +38,15 @@ export function main({ flags }) {
35
38
  if (found.length)
36
39
  hits[file] = found;
37
40
  }
38
- return { ok: Object.keys(hits).length === 0, terms, files: files.length, hits };
41
+ // The entry this process runs (scripts/cli.ts or dist/scripts/cli.js) exports the same way a project does.
42
+ const exported = await exportSmoke(process.argv[1]);
43
+ const ok = Object.keys(hits).length === 0 && exported.ran;
44
+ return {
45
+ ok,
46
+ terms,
47
+ files: files.length,
48
+ hits,
49
+ export: exported,
50
+ ...(exported.ran ? {} : { fix: `Install Chrome, or set CHROME_PATH: ${exported.reason}` }),
51
+ };
39
52
  }
@@ -40,6 +40,8 @@ export declare function main({ flags }: Args<typeof spec>): Promise<{
40
40
  error: string;
41
41
  fix: string;
42
42
  } | {
43
+ ok?: undefined;
44
+ error?: undefined;
43
45
  share: {
44
46
  url: string;
45
47
  open: {
@@ -51,9 +53,7 @@ export declare function main({ flags }: Args<typeof spec>): Promise<{
51
53
  review: string;
52
54
  next: string;
53
55
  steps?: undefined;
54
- ok?: undefined;
55
56
  stage?: undefined;
56
- error?: undefined;
57
57
  fix?: undefined;
58
58
  via: "cli" | "git";
59
59
  deployment: string;
@@ -34,6 +34,9 @@ async function query(op, params, { review, actor }) {
34
34
  return {
35
35
  comments: await review.listComments(actor, prototypeOf(params.get('prototype')), params.get('viewAs') ?? undefined),
36
36
  };
37
+ case 'prototypes':
38
+ // The index's read: the view the caller gets and the client-facing slugs. viewAs is checked as comments checks it.
39
+ return await review.visiblePrototypes(actor, params.get('viewAs') ?? undefined);
37
40
  case 'people':
38
41
  return { people: (await review.listPeople(actor)).map(visible) };
39
42
  case 'access':
@@ -94,6 +97,11 @@ async function command(op, b, ctx) {
94
97
  return { comment: await review.resolve(actor, { ...at(), resolved: b.resolved === true }) };
95
98
  case 'comment.triage':
96
99
  return { comment: await review.retriage(actor, { ...at(), triage: b.triage, states: b.states }) };
100
+ case 'prototype.audience':
101
+ return {
102
+ prototype: b.prototype,
103
+ audience: await review.setAudience(actor, b.prototype, b.audience),
104
+ };
97
105
  default:
98
106
  return peopleCommand(op, b, ctx);
99
107
  }
@@ -1,3 +1,4 @@
1
+ import { type PersonKind } from '../core/review/model.ts';
1
2
  export declare const PERSON_COOKIE = "__Host-hub_person";
2
3
  /** How long the store's last yes is trusted before the gate asks again. */
3
4
  export declare const CHECK_SECONDS: number;
@@ -20,8 +21,11 @@ export declare function sessionSeconds(endsAt: string | null, at?: Date): number
20
21
  export type PersonClaim = {
21
22
  id: string;
22
23
  epoch: number;
24
+ kind: PersonKind;
23
25
  };
24
- export type SessionClaim = PersonClaim & {
26
+ /** `kind` is null for a p3 token, which never counts as fresh. */
27
+ export type SessionClaim = Omit<PersonClaim, 'kind'> & {
28
+ kind: PersonKind | null;
25
29
  checkedAt: number;
26
30
  };
27
31
  /** A token for someone the store said yes to at `at`, lasting to their access end. */