@milesroxas/design-hub 0.10.0 → 0.11.1

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 (131) hide show
  1. package/README.md +13 -11
  2. package/core/files.test.ts +76 -0
  3. package/core/files.ts +131 -0
  4. package/core/prototype.test.ts +124 -7
  5. package/core/prototype.ts +133 -24
  6. package/core/review/model.ts +119 -2
  7. package/core/review/policy.test.ts +79 -22
  8. package/core/review/policy.ts +36 -8
  9. package/core/review/service.test.ts +1464 -340
  10. package/core/review/service.ts +777 -191
  11. package/core/review/store.test.ts +91 -0
  12. package/core/review/store.ts +143 -33
  13. package/dist/core/files.d.ts +39 -0
  14. package/dist/core/files.js +107 -0
  15. package/dist/core/prototype.d.ts +61 -12
  16. package/dist/core/prototype.js +105 -26
  17. package/dist/core/review/model.d.ts +76 -2
  18. package/dist/core/review/model.js +76 -1
  19. package/dist/core/review/policy.d.ts +11 -4
  20. package/dist/core/review/policy.js +14 -2
  21. package/dist/core/review/service.d.ts +197 -45
  22. package/dist/core/review/service.js +702 -192
  23. package/dist/core/review/store.d.ts +84 -31
  24. package/dist/core/review/store.js +66 -33
  25. package/dist/scripts/bootstrap.d.ts +4 -34
  26. package/dist/scripts/bootstrap.js +9 -244
  27. package/dist/scripts/cli.js +6 -0
  28. package/dist/scripts/client.d.ts +45 -0
  29. package/dist/scripts/client.js +320 -0
  30. package/dist/scripts/commands.js +6 -0
  31. package/dist/scripts/comments.d.ts +8 -26
  32. package/dist/scripts/comments.js +27 -14
  33. package/dist/scripts/lib/builds.d.ts +40 -0
  34. package/dist/scripts/lib/builds.js +198 -0
  35. package/dist/scripts/lib/cli.js +3 -1
  36. package/dist/scripts/lib/deploy.d.ts +6 -90
  37. package/dist/scripts/lib/deploy.js +24 -137
  38. package/dist/scripts/lib/dns.d.ts +49 -0
  39. package/dist/scripts/lib/dns.js +141 -0
  40. package/dist/scripts/lib/fake-host.d.ts +168 -0
  41. package/dist/scripts/lib/fake-host.js +244 -0
  42. package/dist/scripts/lib/host.d.ts +87 -0
  43. package/dist/scripts/lib/host.js +362 -0
  44. package/dist/scripts/lib/linked.d.ts +51 -0
  45. package/dist/scripts/lib/linked.js +124 -0
  46. package/dist/scripts/lib/names.d.ts +35 -0
  47. package/dist/scripts/lib/names.js +77 -0
  48. package/dist/scripts/lib/review.d.ts +23 -2
  49. package/dist/scripts/lib/review.js +32 -15
  50. package/dist/scripts/lib/studio-deps.d.ts +35 -0
  51. package/dist/scripts/lib/studio-deps.js +79 -0
  52. package/dist/scripts/lib/studios.d.ts +70 -0
  53. package/dist/scripts/lib/studios.js +187 -0
  54. package/dist/scripts/lib/update.d.ts +33 -0
  55. package/dist/scripts/lib/update.js +40 -0
  56. package/dist/scripts/lib/vercel.d.ts +1 -23
  57. package/dist/scripts/lib/vercel.js +6 -81
  58. package/dist/scripts/people.d.ts +7 -11
  59. package/dist/scripts/people.js +51 -46
  60. package/dist/scripts/preflight.d.ts +8 -1
  61. package/dist/scripts/preflight.js +36 -19
  62. package/dist/scripts/project.d.ts +86 -0
  63. package/dist/scripts/project.js +141 -0
  64. package/dist/scripts/share.d.ts +105 -30
  65. package/dist/scripts/share.js +82 -154
  66. package/dist/scripts/skills.d.ts +18 -2
  67. package/dist/scripts/skills.js +22 -3
  68. package/dist/scripts/studio.d.ts +75 -0
  69. package/dist/scripts/studio.js +401 -0
  70. package/dist/scripts/upgrade.d.ts +10 -2
  71. package/dist/scripts/upgrade.js +44 -14
  72. package/dist/server/api.d.ts +22 -11
  73. package/dist/server/api.js +116 -47
  74. package/dist/server/blob.d.ts +10 -0
  75. package/dist/server/blob.js +53 -0
  76. package/dist/server/checks.js +2 -2
  77. package/dist/server/dev.js +4 -4
  78. package/dist/server/env.d.ts +2 -0
  79. package/dist/server/env.js +9 -0
  80. package/dist/server/fake-upstash.js +52 -3
  81. package/dist/server/hosts.d.ts +11 -0
  82. package/dist/server/hosts.js +31 -0
  83. package/dist/server/local.d.ts +7 -1
  84. package/dist/server/local.js +10 -1
  85. package/dist/server/mark.d.ts +41 -0
  86. package/dist/server/mark.js +111 -0
  87. package/dist/server/session.d.ts +17 -9
  88. package/dist/server/session.js +22 -45
  89. package/dist/server/upstash.js +20 -0
  90. package/dist/vercel/files.d.ts +11 -0
  91. package/dist/vercel/files.js +68 -0
  92. package/dist/vercel/index.d.ts +4 -3
  93. package/dist/vercel/index.js +12 -8
  94. package/dist/vercel/proxy.d.ts +69 -4
  95. package/dist/vercel/proxy.js +171 -107
  96. package/dist/vite/plugin.d.ts +24 -1
  97. package/dist/vite/plugin.js +46 -2
  98. package/kit/dials.tsx +2 -2
  99. package/package.json +2 -1
  100. package/shell/Guide.tsx +11 -5
  101. package/shell/Index.tsx +32 -10
  102. package/shell/Notice.tsx +1 -1
  103. package/shell/controls.ts +1 -1
  104. package/shell/hub.ts +5 -1
  105. package/shell/main.tsx +18 -3
  106. package/shell/review/Review.tsx +6 -4
  107. package/shell/review/ThreadCard.tsx +20 -7
  108. package/shell/review/client.ts +42 -14
  109. package/shell/review/view.test.ts +19 -0
  110. package/shell/review/view.ts +25 -0
  111. package/shell/shell.css +4 -0
  112. package/shell/studio/ClientHub.tsx +98 -0
  113. package/shell/studio/hub.css +48 -0
  114. package/shell/studio/index.html +14 -0
  115. package/shell/studio/main.tsx +17 -0
  116. package/skills/miles-deploy/SKILL.md +120 -65
  117. package/skills/miles-design-hub/SKILL.md +11 -9
  118. package/skills/miles-review/SKILL.md +5 -7
  119. package/skills/miles-worktrees/SKILL.md +3 -3
  120. package/templates/conductor/settings.toml +1 -1
  121. package/templates/studio/.env.example +9 -0
  122. package/templates/studio/.vercelignore +5 -0
  123. package/templates/studio/README.md +84 -0
  124. package/templates/studio/_gitignore +7 -0
  125. package/templates/studio/api/files.ts +4 -0
  126. package/templates/studio/api/review.ts +4 -0
  127. package/templates/studio/build.mjs +4 -0
  128. package/templates/studio/package.json +16 -0
  129. package/templates/studio/proxy.ts +4 -0
  130. package/templates/studio/studio.json +9 -0
  131. package/templates/studio/vercel.json +27 -0
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import { type Args } from './lib/cli.ts';
3
+ import { type StudioDeps } from './lib/studio-deps.ts';
4
+ export declare const spec: {
5
+ readonly name: 'client';
6
+ readonly summary: 'Add a client to a studio with its host and first sign-in links, archive one, or set how long its people keep access.';
7
+ readonly positionals: [{
8
+ readonly name: 'action';
9
+ readonly required: true;
10
+ readonly description: 'add <slug>: the client, its host and its first links. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.';
11
+ }, {
12
+ readonly name: 'slug';
13
+ readonly description: 'The client, kebab-case; never studio, www, api or site.';
14
+ }];
15
+ readonly flags: {
16
+ readonly studio: {
17
+ readonly type: 'string';
18
+ readonly description: 'The studio’s slug. Absent, the studio folder this runs in.';
19
+ };
20
+ readonly name: {
21
+ readonly type: 'string';
22
+ readonly description: 'For add: the client’s name.';
23
+ };
24
+ readonly host: {
25
+ readonly type: 'string';
26
+ readonly description: "For add: a codename for the host, served as <codename>.<apex> (or that full host): one label under the apex, never studio, www or api. Absent, <slug>.<apex>. With per-host DNS a client’s host is public in certificate logs from the moment it is added. To keep the client’s name out of them, add it with --host <codename>.";
27
+ };
28
+ readonly person: {
29
+ readonly type: 'string';
30
+ readonly description: 'For add: the client’s first person, by name, who gets the first sign-in link.';
31
+ };
32
+ readonly team: {
33
+ readonly type: 'string';
34
+ readonly description: 'For add: that person’s company, shown beside their name. Absent, --name.';
35
+ };
36
+ readonly access: {
37
+ readonly type: 'string';
38
+ readonly choices: readonly ["3m", "6m", "open", "studio"];
39
+ readonly description: 'For access: 3m, 6m or open; with a slug, studio hands the client back to the studio’s default. A person’s own length wins over both.';
40
+ };
41
+ };
42
+ readonly output: 'add: { ok, client, host, dns, links: { client, studio? }, notice?, next }. archive: { ok, client, host, domain: removed | absent | wildcard | kept (another client has the host) | unknown, files, dns?: { removed, left, fix? } | { record, fix } }. access: { ok, client?, access, default }';
43
+ };
44
+ export declare function run({ positionals: [action, slug], flags }: Args<typeof spec>, deps: StudioDeps): Promise<Record<string, unknown>>;
45
+ export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
@@ -0,0 +1,320 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ // A studio's clients. Each is served on its own host below the studio's
4
+ // apex, and sees only its own projects there.
5
+ //
6
+ // client add <slug> its host (DNS record and domain) and the client,
7
+ // then, once the host proves it is this studio's
8
+ // site, its first sign-in links, on that host only
9
+ // client archive <slug> every key and file it has, so the slug used again
10
+ // starts clean, then its DNS record (one this studio
11
+ // made) and its host off the site
12
+ // client access [slug] how long a new person of the client keeps access
13
+ // (the studio's default without a slug)
14
+ //
15
+ // No link exists until the host proves it: asked over HTTPS for a proof the
16
+ // store holds, it must send back the answer only this studio's gate can give,
17
+ // so a host another server answers never gets one. Nothing asks for the host
18
+ // through this machine's resolver until the zone's own nameservers serve it,
19
+ // so no resolver is left keeping "no such host" for it. A run that stops part way
20
+ // (a record to add, a certificate still coming) leaves the client waiting for
21
+ // its proof, and the same command run again with the same flags finishes it.
22
+ import { clearPrefix, clientPrefix } from '../core/files.js';
23
+ import { ACCESS, isAdded, isStudioClient, STUDIO_CLIENT_SLUG } from '../core/review/model.js';
24
+ import { REUSE_SECONDS } from '../core/review/service.js';
25
+ import { localStudio } from '../server/local.js';
26
+ import { CliError } from './lib/cli.js';
27
+ import { openReview, realDeps, recordOf } from './lib/studio-deps.js';
28
+ import { clientHost, findStudio } from './lib/studios.js';
29
+ /** S9: what a per-host or manual record makes public. */
30
+ const PUBLIC_HOST = 'With per-host DNS a client’s host is public in certificate logs from the moment it is added. To keep the client’s name out of them, add it with --host <codename>.';
31
+ export const spec = {
32
+ name: 'client',
33
+ summary: 'Add a client to a studio with its host and first sign-in links, archive one, or set how long its people keep access.',
34
+ positionals: [
35
+ {
36
+ name: 'action',
37
+ required: true,
38
+ description: 'add <slug>: the client, its host and its first links. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.',
39
+ },
40
+ { name: 'slug', description: 'The client, kebab-case; never studio, www, api or site.' },
41
+ ],
42
+ flags: {
43
+ studio: { type: 'string', description: 'The studio’s slug. Absent, the studio folder this runs in.' },
44
+ name: { type: 'string', description: 'For add: the client’s name.' },
45
+ host: {
46
+ type: 'string',
47
+ description: `For add: a codename for the host, served as <codename>.<apex> (or that full host): one label under the apex, never studio, www or api. Absent, <slug>.<apex>. ${PUBLIC_HOST}`,
48
+ },
49
+ person: {
50
+ type: 'string',
51
+ description: 'For add: the client’s first person, by name, who gets the first sign-in link.',
52
+ },
53
+ team: {
54
+ type: 'string',
55
+ description: 'For add: that person’s company, shown beside their name. Absent, --name.',
56
+ },
57
+ access: {
58
+ type: 'string',
59
+ choices: [...ACCESS, 'studio'],
60
+ description: 'For access: 3m, 6m or open; with a slug, studio hands the client back to the studio’s default. A person’s own length wins over both.',
61
+ },
62
+ },
63
+ output: 'add: { ok, client, host, dns, links: { client, studio? }, notice?, next }. archive: { ok, client, host, domain: removed | absent | wildcard | kept (another client has the host) | unknown, files, dns?: { removed, left, fix? } | { record, fix } }. access: { ok, client?, access, default }',
64
+ };
65
+ const actor = () => localStudio('cli', 'CLI');
66
+ function needSlug(action, slug) {
67
+ if (!slug)
68
+ throw new CliError(`Name the client: design-hub client ${action} <slug>.`);
69
+ if (!isStudioClient(slug))
70
+ throw new CliError(`${slug} cannot be a client.`, { problems: [STUDIO_CLIENT_SLUG] });
71
+ return slug;
72
+ }
73
+ /**
74
+ * The client an earlier run of this add left still being added (a record
75
+ * not yet marked proven, isAdded), or null when the slug and the host are
76
+ * free. Anything else the studio already has is refused early, before any
77
+ * DNS or domain change. Not the claim: addClient makes that.
78
+ */
79
+ async function free({ review, flags, studio }, slug, host) {
80
+ const existing = await recordOf(review, slug);
81
+ const waiting = existing?.host === host && existing.archivedAt === null && !isAdded(existing);
82
+ // An add that stopped inside addClient left the record without the host's entry, so the site never
83
+ // answers the host's proof, and a run again cannot finish it: only an archive frees the slug and host.
84
+ if (existing && waiting && (await review.clientOfHost(host))?.slug !== slug)
85
+ throw new CliError(`Client ${slug} was left part way through being added, before its host was set up.`, {
86
+ fix: `design-hub client archive ${slug} --studio ${studio.config.slug}, then add it again: the slug and host can be added again ${REUSE_SECONDS / 60} minutes after the archive.`,
87
+ });
88
+ if (existing && waiting) {
89
+ if (existing.name !== flags.name)
90
+ throw new CliError(`Client ${slug} is waiting for its host under another --name.`, {
91
+ name: existing.name,
92
+ fix: `Run this again with --name "${existing.name}", the name it was added with; or archive it and add it again.`,
93
+ });
94
+ return existing;
95
+ }
96
+ if (existing)
97
+ throw new CliError(`Client ${slug} exists.`, {
98
+ fix: 'Pick another slug, or archive that client first (run client archive again if one stopped part way).',
99
+ });
100
+ const wait = await review.clientWait(actor(), { slug, host });
101
+ if (wait)
102
+ throw new CliError(`${slug} or ${host} was archived moments ago and cannot be added yet.`, {
103
+ wait,
104
+ fix: `Run this again in ${wait} seconds: until then a studio site may still hold the archived client's answer for the host.`,
105
+ });
106
+ if (await review.clientOfHost(host))
107
+ throw new CliError(`${host} already serves a client.`, { fix: 'Pick another --host.' });
108
+ return null;
109
+ }
110
+ /**
111
+ * Points the host at the studio site: its DNS record and, unless the
112
+ * wildcard serves it, its domain on the project (verified). Each step is safe
113
+ * to repeat; one a person must take stops the command with what to do.
114
+ */
115
+ async function serve(host, dns, name) {
116
+ const ensured = await dns.ensure(name);
117
+ if (dns.mode !== 'wildcard') {
118
+ const domain = await host.addDomain(name);
119
+ if (!domain.verified)
120
+ throw new CliError(`Vercel asks for proof that the studio may use ${name}.`, {
121
+ records: domain.verification.map((v) => `${v.type} ${v.domain} ${v.value}`),
122
+ fix: 'Add each record at the DNS provider, then run this again with the same flags.',
123
+ });
124
+ }
125
+ return ensured;
126
+ }
127
+ /**
128
+ * Holds every request for the host back until its DNS serves it. A resolver
129
+ * asked for a name in the seconds before its record is served keeps "no such
130
+ * host" for the zone's negative-cache time, for this machine and everyone
131
+ * behind it; so the host is first asked only of its zone's own nameservers,
132
+ * which never cache, and this machine's resolver once they all serve it. One
133
+ * that already keeps a miss, from before this command or an earlier run,
134
+ * stops it with what to wait for: the proof is never skipped, and without
135
+ * that resolver it cannot be asked.
136
+ */
137
+ async function served(ctx, host, ensured, stop) {
138
+ const { state, zone, negative } = await ctx.deps.names.served(host, ctx.studio.config.apex);
139
+ const record = typeof ensured === 'object' ? { record: ensured.record } : {};
140
+ if (state === 'unreachable')
141
+ throw new CliError(`This network would not let the command ask the nameservers of ${zone ?? ctx.studio.config.apex} whether ${host} is served; no sign-in link was made.`, {
142
+ ...record,
143
+ fix: `Run this again with the same flags on a network that lets DNS through to any server. ${stop}`,
144
+ });
145
+ if (state === 'missing')
146
+ throw new CliError(`${host} is not served by its DNS yet; no sign-in link was made.`, {
147
+ ...record,
148
+ fix: typeof ensured === 'object'
149
+ ? `Add the record at the DNS provider, then run this again with the same flags. ${stop}`
150
+ : `A new record can take a minute to be served: run this again with the same flags. ${stop}`,
151
+ });
152
+ if (await ctx.deps.names.seen(host))
153
+ return;
154
+ const within = negative ? `up to ${Math.ceil(negative / 60)} minutes` : 'some minutes';
155
+ throw new CliError(`${host} is set up, and its DNS serves it, but this network does not see it yet; no sign-in link was made.`, {
156
+ ...(negative ? { wait: negative } : {}),
157
+ fix: `Nothing is left to set up. This network's resolver keeps an earlier "no such host" for ${within} (the zone's negative-cache time); run this again with the same flags once that has passed. ${stop}`,
158
+ });
159
+ }
160
+ /**
161
+ * Proves, before any link exists, that the client's host is this studio's
162
+ * site: a new proof in the store, whose answer the host must send back for
163
+ * its ask. Only the gate reading this store has it, so a host that another
164
+ * server answers fails, whatever that server sends. Answered, the client is
165
+ * marked proven (endProof), and only then is it added. A run that stops on
166
+ * the way leaves it unmarked, which the same command finishes.
167
+ */
168
+ async function prove(ctx, host, client, ensured) {
169
+ const { review } = ctx;
170
+ const scope = { client: client.slug };
171
+ const proof = await review.startProof(scope, actor());
172
+ const stop = `To drop it instead: design-hub client archive ${client.slug} --studio ${ctx.studio.config.slug}.`;
173
+ await served(ctx, client.host, ensured, stop);
174
+ if (await host.reaches(client.host, proof)) {
175
+ await review.endProof(scope, actor());
176
+ return;
177
+ }
178
+ throw new CliError(`${client.host} does not answer from the studio site yet; no sign-in link was made.`, {
179
+ ...(typeof ensured === 'object' ? { record: ensured.record } : {}),
180
+ fix: typeof ensured === 'object'
181
+ ? `Add the record at the DNS provider, then run this again with the same flags. ${stop}`
182
+ : `A new certificate can take a minute: run this again with the same flags. If ${client.host} has a DNS record of its own, another server answers it: remove that record, or archive the client and add it with another --host. ${stop}`,
183
+ });
184
+ }
185
+ async function add(ctx) {
186
+ const { studio, review, deps, flags } = ctx;
187
+ const slug = needSlug('add', ctx.slug);
188
+ if (!flags.name)
189
+ throw new CliError('--name is required: the client’s name.');
190
+ if (!flags.person)
191
+ throw new CliError('--person is required: the client’s first person, who gets the first link.');
192
+ const { config } = studio;
193
+ const name = clientHost(slug, config.apex, flags.host);
194
+ const waiting = await free(ctx, slug, name);
195
+ const host = deps.host(studio.dir, config);
196
+ const dns = await serve(host, deps.dns(studio, host), name);
197
+ // The client goes in before the host is asked anything, so the gate never keeps the host as unknown
198
+ // (server/hosts.ts) and the links open at once; nobody can sign in until the proof passes.
199
+ const client = waiting ?? (await review.addClient(actor(), { slug, host: name, name: flags.name }));
200
+ // Its files start clean too, now the slug is its own: whatever a share that raced an archive of an
201
+ // earlier client of the slug left. Again on a run that finishes one, in case the last stopped first;
202
+ // but only while the client is still not added, read again now: another run may have finished it
203
+ // while this one waited on the host, and its projects' builds are live.
204
+ const current = await recordOf(review, slug);
205
+ if (current && !isAdded(current))
206
+ await clearPrefix(deps.files(studio), clientPrefix(slug));
207
+ await prove(ctx, host, client, dns);
208
+ const at = (token) => `https://${client.host}/invite/${token}`;
209
+ try {
210
+ const first = await review.addPerson({ client: slug }, actor(), {
211
+ name: flags.person,
212
+ team: flags.team ?? flags.name,
213
+ kind: 'client',
214
+ });
215
+ const studioLink = config.owner ? await review.newStudioLink(actor(), config.owner) : null;
216
+ return {
217
+ client: { slug: client.slug, name: client.name },
218
+ host: client.host,
219
+ dns,
220
+ links: { client: at(first.token), ...(studioLink ? { studio: at(studioLink.token) } : {}) },
221
+ ...(config.dns.mode === 'wildcard' ? {} : { notice: PUBLIC_HOST }),
222
+ next: 'Send each person their own link. A link signs in one device on this host, then stops working. One that shows Not found opens within a minute: the site keeps a host’s answer that long.',
223
+ };
224
+ }
225
+ catch (error) {
226
+ throw new CliError(`Client ${slug} was added, but its first links were not: ${error.message}`, {
227
+ fix: `design-hub client archive ${slug} --studio ${config.slug}, then add it again.`,
228
+ });
229
+ }
230
+ }
231
+ /** Takes an archived client's host off the studio project; a failure says the client is gone but the domain is not. */
232
+ async function offSite(host, name, again) {
233
+ try {
234
+ return await host.removeDomain(name);
235
+ }
236
+ catch (error) {
237
+ throw new CliError(`The client is archived and ${name} serves nothing, but ${name} is still a domain of the studio project.`, {
238
+ host: name,
239
+ cause: error.message,
240
+ fix: `${again} finishes it, or remove ${name} from the studio project’s Domains settings on Vercel.`,
241
+ });
242
+ }
243
+ }
244
+ /** What archive says of the host's DNS record: what came off, and what a person must remove or check. */
245
+ function dnsReport(released) {
246
+ if ('record' in released)
247
+ return {
248
+ record: released.record,
249
+ fix: `Remove this record at the DNS provider: ${released.record}`,
250
+ };
251
+ return {
252
+ ...released,
253
+ ...(released.left.length
254
+ ? {
255
+ fix: 'The records in left were not made by this studio and are left in place: remove them at the DNS provider if nothing else uses them.',
256
+ }
257
+ : {}),
258
+ };
259
+ }
260
+ async function archive(ctx) {
261
+ const { studio, review, deps } = ctx;
262
+ const slug = needSlug('archive', ctx.slug);
263
+ const scope = { client: slug };
264
+ const again = `design-hub client archive ${slug} --studio ${studio.config.slug}`;
265
+ // Everything of the client that can be read goes first: its keys and sessions (its host then
266
+ // serves the plain 404), then its files. Its DNS record and its domain are last, so no failed call
267
+ // leaves the client readable; the record stays, archived, until they are done, so a run again
268
+ // still knows the host and each step finds what is left.
269
+ const archived = await review.archiveClient(scope, actor());
270
+ const files = await clearPrefix(deps.files(studio), clientPrefix(slug));
271
+ const record = archived?.client ?? null;
272
+ const wildcard = studio.config.dns.mode === 'wildcard';
273
+ // Another client's host, or one a live client's record names, is never taken off.
274
+ const own = !!archived?.ownHost && !wildcard;
275
+ const host = own ? deps.host(studio.dir, studio.config) : null;
276
+ const dns = host && record ? dnsReport(await deps.dns(studio, host).release(record.host)) : null;
277
+ const domain = !record
278
+ ? 'unknown'
279
+ : wildcard
280
+ ? 'wildcard'
281
+ : host
282
+ ? await offSite(host, record.host, again)
283
+ : 'kept';
284
+ await review.forgetClient(scope, actor());
285
+ return {
286
+ client: slug,
287
+ host: record?.host ?? null,
288
+ domain,
289
+ files,
290
+ ...(dns ? { dns } : {}),
291
+ };
292
+ }
293
+ async function access({ review, flags, slug }) {
294
+ if (!slug) {
295
+ if (flags.access === 'studio')
296
+ throw new CliError('--access studio needs a client: it hands one back to the studio’s default.');
297
+ const set = flags.access
298
+ ? await review.setStudioAccess(actor(), flags.access)
299
+ : await review.studioAccess(actor());
300
+ return { access: set, default: set };
301
+ }
302
+ const scope = { client: needSlug('access', slug) };
303
+ const client = flags.access
304
+ ? await review.setClientAccess(scope, actor(), flags.access === 'studio' ? null : flags.access)
305
+ : await review.clientRecord(scope, actor());
306
+ return {
307
+ client: client.slug,
308
+ access: client.access ?? 'studio',
309
+ default: await review.defaultAccess(scope, actor()),
310
+ };
311
+ }
312
+ const ACTIONS = { add, archive, access };
313
+ export async function run({ positionals: [action, slug], flags }, deps) {
314
+ const act = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
315
+ if (!act)
316
+ throw new CliError(`Unknown action ${action}.`, { fix: 'add, archive or access' });
317
+ const studio = findStudio(deps.home, flags.studio, deps.cwd);
318
+ return act({ studio, review: await openReview(deps, studio), deps, flags, slug });
319
+ }
320
+ export const main = (args) => run(args, realDeps());
@@ -6,6 +6,7 @@
6
6
  import * as bootstrap from './bootstrap.js';
7
7
  import * as calibrate from './calibrate.js';
8
8
  import * as check from './check.js';
9
+ import * as client from './client.js';
9
10
  import * as comments from './comments.js';
10
11
  import * as dev from './dev.js';
11
12
  import * as elyx from './elyx.js';
@@ -16,11 +17,13 @@ import { schema } from './lib/cli.js';
16
17
  import * as create from './new.js';
17
18
  import * as people from './people.js';
18
19
  import * as preflight from './preflight.js';
20
+ import * as project from './project.js';
19
21
  import * as releaseCheck from './release-check.js';
20
22
  import * as share from './share.js';
21
23
  import * as signin from './signin.js';
22
24
  import * as skillHint from './skill-hint.js';
23
25
  import * as skills from './skills.js';
26
+ import * as studio from './studio.js';
24
27
  import * as tracks from './tracks.js';
25
28
  import * as upgrade from './upgrade.js';
26
29
  import * as visualMatch from './visual-match.js';
@@ -43,6 +46,9 @@ export const COMMANDS = [
43
46
  signin.spec,
44
47
  share.spec,
45
48
  people.spec,
49
+ studio.spec,
50
+ client.spec,
51
+ project.spec,
46
52
  comments.spec,
47
53
  calibrate.spec,
48
54
  fixturesPull.spec,
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { type Comment } from '../core/review/model.ts';
2
+ import { type Comment, type Scope } from '../core/review/model.ts';
3
3
  import type { Review } from '../core/review/service.ts';
4
4
  import { type Args } from './lib/cli.ts';
5
+ import { type ProjectDeps } from './lib/linked.ts';
5
6
  import { type CliReview } from './lib/review.ts';
6
7
  export declare const spec: {
7
8
  readonly name: 'comments';
@@ -20,10 +21,10 @@ export declare const spec: {
20
21
  };
21
22
  readonly local: {
22
23
  readonly type: 'boolean';
23
- readonly description: 'Use the local dev store even when the deployed one is configured.';
24
+ readonly description: 'Use this machine’s dev store, even in a project linked to a studio.';
24
25
  };
25
26
  };
26
- readonly output: '{ ok, store, ... } per action';
27
+ readonly output: '{ ok, store, studio?, ... } per action; store is studio in a linked project, with studio: { studio, client, host, project }, and local otherwise';
27
28
  };
28
29
  /**
29
30
  * One feature's comments as Markdown: by README state in table order, then
@@ -33,12 +34,13 @@ export declare function renderComments(feature: string, comments: Comment[], sta
33
34
  type Context = {
34
35
  review: Review;
35
36
  store: CliReview['store'];
37
+ scope: Scope;
36
38
  all: Comment[];
37
39
  roots: Comment[];
38
40
  };
39
41
  /** Threads per prototype: open and resolved, and internal and client-facing. */
40
42
  export declare function summary({ store, roots }: Pick<Context, 'store' | 'roots'>): {
41
- store: "deployed" | "local";
43
+ store: "local" | "studio";
42
44
  prototypes: Record<string, {
43
45
  open: number;
44
46
  resolved: number;
@@ -46,26 +48,6 @@ export declare function summary({ store, roots }: Pick<Context, 'store' | 'roots
46
48
  client: number;
47
49
  }>;
48
50
  };
49
- export declare function main({ positionals: [action, id], flags }: Args<typeof spec>): Promise<{
50
- store: "deployed" | "local";
51
- prototypes: Record<string, {
52
- open: number;
53
- resolved: number;
54
- internal: number;
55
- client: number;
56
- }>;
57
- } | {
58
- store: "deployed" | "local";
59
- threads: number;
60
- written: string[];
61
- } | {
62
- store: "deployed" | "local";
63
- comment: {
64
- id: string;
65
- status: "open" | "resolved";
66
- };
67
- } | {
68
- store: "deployed" | "local";
69
- sorted: string[];
70
- }>;
51
+ export declare function run({ positionals: [action, id], flags }: Args<typeof spec>, deps: ProjectDeps): Promise<Record<string, unknown>>;
52
+ export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
71
53
  export {};
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  /// <reference types="node" />
3
- // Review comments from the deployed prototypes, brought into the repo where
3
+ // Review comments on a project's prototypes, brought into the repo where
4
4
  // Claude works from them. `pull` writes a generated file per feature; the
5
- // panel or `resolve` is where a comment is closed, never the file.
5
+ // panel or `resolve` is where a comment is closed, never the file. In a
6
+ // project linked to a studio they are that project's comments in the studio;
7
+ // otherwise, and with --local, the dev server's.
6
8
  import { mkdirSync, writeFileSync } from 'node:fs';
7
9
  import { join, relative } from 'node:path';
8
10
  import { featureTitle } from '../core/feature.js';
@@ -13,6 +15,7 @@ import { readEnv } from '../server/env.js';
13
15
  import { DOCS, ROOT } from '../server/paths.js';
14
16
  import { prototypes } from './lib/catalog.js';
15
17
  import { CliError } from './lib/cli.js';
18
+ import { realProjectDeps } from './lib/linked.js';
16
19
  import { cliActor, cliReview } from './lib/review.js';
17
20
  export const spec = {
18
21
  name: 'comments',
@@ -28,10 +31,10 @@ export const spec = {
28
31
  all: { type: 'boolean', description: 'For pull: include resolved threads.' },
29
32
  local: {
30
33
  type: 'boolean',
31
- description: 'Use the local dev store even when the deployed one is configured.',
34
+ description: 'Use this machine’s dev store, even in a project linked to a studio.',
32
35
  },
33
36
  },
34
- output: '{ ok, store, ... } per action',
37
+ output: '{ ok, store, studio?, ... } per action; store is studio in a linked project, with studio: { studio, client, host, project }, and local otherwise',
35
38
  };
36
39
  const NO_STATE = 'No state';
37
40
  const KIND_TITLE = { bug: 'Bugs', taste: 'Taste', copy: 'Copy' };
@@ -112,19 +115,19 @@ function pull({ store, all, roots }, includeResolved) {
112
115
  });
113
116
  return { store, threads: keep.size, written };
114
117
  }
115
- async function setStatus({ review, store }, id, resolved) {
118
+ async function setStatus({ review, store, scope }, id, resolved) {
116
119
  const action = resolved ? 'resolve' : 'reopen';
117
120
  if (!id)
118
121
  throw new CliError(`Name the comment: pnpm comments ${action} <id>.`, {
119
122
  fix: 'pnpm comments pull lists ids.',
120
123
  });
121
- const found = await review.locate(cliActor(), id);
124
+ const found = await review.locate(scope, cliActor(), id);
122
125
  if (!found)
123
126
  throw new CliError('No comment has that id.', { id });
124
- const comment = await review.resolve(cliActor(), { prototype: found.prototype, id, resolved });
127
+ const comment = await review.resolve(scope, cliActor(), { prototype: found.prototype, id, resolved });
125
128
  return { store, comment: { id: comment.id, status: comment.status } };
126
129
  }
127
- async function triage({ review, store, roots }) {
130
+ async function triage({ review, store, scope, roots }) {
128
131
  const triager = jevTriager(readEnv(ROOT).TYPESAFE_API_KEY ?? '', checks);
129
132
  if (!triager)
130
133
  throw new CliError('TypeSafe is off.', {
@@ -139,20 +142,22 @@ async function triage({ review, store, roots }) {
139
142
  const t = await triager({ body: c.body, prototype: c.anchor.prototype, url: c.anchor.url, states });
140
143
  if (!t)
141
144
  continue;
142
- await review.retriage(cliActor(), { prototype: c.anchor.prototype, id: c.id, triage: t, states });
145
+ await review.retriage(scope, cliActor(), {
146
+ prototype: c.anchor.prototype,
147
+ id: c.id,
148
+ triage: t,
149
+ states,
150
+ });
143
151
  sorted.push(c.id);
144
152
  }
145
153
  return { store, sorted };
146
154
  }
147
- export async function main({ positionals: [action = 'summary', id], flags }) {
148
- const { review, store } = cliReview(flags.local);
149
- const all = await review.allComments(cliActor());
150
- const ctx = { review, store, all, roots: all.filter(isRoot) };
155
+ function act(ctx, action, id, all) {
151
156
  switch (action) {
152
157
  case 'summary':
153
158
  return summary(ctx);
154
159
  case 'pull':
155
- return pull(ctx, flags.all);
160
+ return pull(ctx, all);
156
161
  case 'resolve':
157
162
  case 'reopen':
158
163
  return setStatus(ctx, id, action === 'resolve');
@@ -162,3 +167,11 @@ export async function main({ positionals: [action = 'summary', id], flags }) {
162
167
  throw new CliError(`Unknown action ${action}.`, { fix: 'summary, pull, resolve, reopen or triage' });
163
168
  }
164
169
  }
170
+ export async function run({ positionals: [action = 'summary', id], flags }, deps) {
171
+ const found = await cliReview(flags.local, deps);
172
+ const { review, store, scope } = found;
173
+ const all = await review.allComments(scope, cliActor());
174
+ const done = await act({ review, store, scope, all, roots: all.filter(isRoot) }, action, id, flags.all);
175
+ return found.studio ? { ...done, studio: found.studio } : done;
176
+ }
177
+ export const main = (args) => run(args, realProjectDeps());
@@ -0,0 +1,40 @@
1
+ import { type Files } from '../../core/files.ts';
2
+ import type { Person } from '../../core/review/model.ts';
3
+ import type { Review } from '../../core/review/service.ts';
4
+ /** How many builds of a project the store keeps: the live one and the two that were live before it. */
5
+ export declare const KEEP_BUILDS = 3;
6
+ /**
7
+ * A new build id: 16 random bytes in hex. Never a counter: 128 random bits
8
+ * mean an id never comes back for the life of the store, even for a project
9
+ * deleted and made again, so a path never comes back with other bytes.
10
+ * Inside the build-id rule (`[a-z0-9]{16,64}`, core/files.ts).
11
+ */
12
+ export declare const newBuildId: () => string;
13
+ type Scope = {
14
+ client: string;
15
+ project: string;
16
+ };
17
+ type Deps = {
18
+ review: Review;
19
+ files: Files;
20
+ actor: Person;
21
+ };
22
+ /**
23
+ * Starts a build in the studio's store, uploads every file of `dist` under
24
+ * it, then points the project at it. A failed upload or pointer write
25
+ * removes the build and leaves the pointer as it was; only a pointer write
26
+ * whose result cannot be read back leaves the files, since they may be
27
+ * live. Returns the build id and how many files went up.
28
+ */
29
+ export declare function publishBuild(deps: Deps, scope: Scope, dist: string): Promise<{
30
+ build: string;
31
+ files: number;
32
+ }>;
33
+ /**
34
+ * Deletes every build of the project that is out of the running but the two
35
+ * that were live last: partial builds of failed shares and shares overtaken
36
+ * by a newer one included, and files no started build names. Returns the
37
+ * builds whose files it removed.
38
+ */
39
+ export declare function pruneBuilds({ review, files, actor }: Deps, scope: Scope): Promise<string[]>;
40
+ export {};