@pro-vi/designer 0.3.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.
package/dist/cli.js ADDED
@@ -0,0 +1,618 @@
1
+ #!/usr/bin/env -S node --import tsx
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { spawn, spawnSync } from 'node:child_process';
5
+ import { createHash } from 'node:crypto';
6
+ import { DesignerController } from "./designer-controller.js";
7
+ import { listSessions, getSession } from "./session-store.js";
8
+ import { createBrowser } from "./browser.js";
9
+ import { writeTastingHtml, serveAndOpen } from "./tasting.js";
10
+ import { sessionDir } from "./artifact-store.js";
11
+ import { runSetup } from "./setup.js";
12
+ import { startMcpServer } from "./mcp-server.js";
13
+ import { REPO_ROOT } from "./repo-root.js";
14
+ import { runHealth } from "./ui-anchors.js";
15
+ const [, , cmd, ...rest] = process.argv;
16
+ function parseFlags(args) {
17
+ const out = { _: [] };
18
+ for (let i = 0; i < args.length; i++) {
19
+ const a = args[i];
20
+ if (!a)
21
+ continue;
22
+ if (a.startsWith('--')) {
23
+ const parts = a.slice(2).split('=');
24
+ const k = parts[0] ?? '';
25
+ const v = parts[1] ?? args[++i] ?? true;
26
+ if (k)
27
+ out[k] = v;
28
+ }
29
+ else {
30
+ out._.push(a);
31
+ }
32
+ }
33
+ return out;
34
+ }
35
+ const flags = parseFlags(rest);
36
+ const key = flags.key || 'default';
37
+ async function main() {
38
+ if (flags.help === true || flags.h === true) {
39
+ if (cmd && HELP[cmd]) {
40
+ console.log(HELP[cmd]);
41
+ }
42
+ else {
43
+ console.log(TOP_HELP);
44
+ }
45
+ return;
46
+ }
47
+ switch (cmd) {
48
+ case 'open': {
49
+ const c = new DesignerController({ key });
50
+ console.log(JSON.stringify(await c.ensureReady(), null, 2));
51
+ break;
52
+ }
53
+ case 'session': {
54
+ const c = new DesignerController({ key });
55
+ const action = flags.action || 'status';
56
+ const name = flags.name;
57
+ const fidelity = flags.fidelity;
58
+ console.log(JSON.stringify(await c.session({ action, name, fidelity }), null, 2));
59
+ break;
60
+ }
61
+ case 'prompt': {
62
+ const prompt = await readPromptArg(flags);
63
+ if (!prompt)
64
+ throw new Error('Usage: designer prompt "<text>" | - (stdin) | --prompt-file path [--key k] [--file "f.html"]');
65
+ const c = new DesignerController({ key });
66
+ const res = await c.iterate(prompt, {
67
+ file: flags.file,
68
+ timeoutMs: flags.timeoutMs ? Number(flags.timeoutMs) : undefined,
69
+ stabilityMs: flags.stabilityMs ? Number(flags.stabilityMs) : undefined
70
+ });
71
+ if (res.url)
72
+ console.log(`\nTaste here: ${res.url}\n`);
73
+ console.log(JSON.stringify(res, null, 2));
74
+ break;
75
+ }
76
+ case 'create': {
77
+ const name = flags.name || flags._[0];
78
+ if (!name)
79
+ throw new Error('Usage: designer create <name> [--fidelity wireframe|highfi] [--key k]');
80
+ const fidelity = flags.fidelity || 'wireframe';
81
+ const c = new DesignerController({ key });
82
+ console.log(JSON.stringify(await c.createSession(name, fidelity), null, 2));
83
+ break;
84
+ }
85
+ case 'resume': {
86
+ const c = new DesignerController({ key });
87
+ console.log(JSON.stringify(await c.resumeSession(), null, 2));
88
+ break;
89
+ }
90
+ case 'snapshot': {
91
+ const c = new DesignerController({ key });
92
+ await c.ensureReady();
93
+ const filename = flags.file;
94
+ if (filename)
95
+ await c.openFile(filename);
96
+ const snap = await c.snapshotDesign();
97
+ if (snap.url)
98
+ console.log(`\nTaste here: ${snap.url}\n`);
99
+ console.log(JSON.stringify({ file: filename ?? null, url: snap.url, htmlBytes: snap.html?.length || 0, screenshotPath: snap.screenshotPath }, null, 2));
100
+ break;
101
+ }
102
+ case 'status':
103
+ console.log(JSON.stringify(getSession(key) || { key, empty: true }, null, 2));
104
+ break;
105
+ case 'list':
106
+ console.log(JSON.stringify(listSessions(), null, 2));
107
+ break;
108
+ case 'projects': {
109
+ const c = new DesignerController({ key });
110
+ console.log(JSON.stringify(await c.listProjects(), null, 2));
111
+ break;
112
+ }
113
+ case 'files': {
114
+ const c = new DesignerController({ key });
115
+ const detail = await c.listFilesDetailed();
116
+ if (!detail.authoritative) {
117
+ console.error(`[designer] Folders detected (${detail.folders.join(', ')}) — files under them are invisible to the live scrape. Run 'designer handoff --key ${key}' for authoritative file listing.`);
118
+ }
119
+ console.log(JSON.stringify(detail, null, 2));
120
+ break;
121
+ }
122
+ case 'open-file': {
123
+ const filename = flags._.join(' ');
124
+ if (!filename)
125
+ throw new Error('Usage: designer open-file "<name>.html" --key k');
126
+ const c = new DesignerController({ key });
127
+ console.log(JSON.stringify(await c.openFile(filename), null, 2));
128
+ break;
129
+ }
130
+ case 'ask': {
131
+ const prompt = await readPromptArg(flags);
132
+ if (!prompt)
133
+ throw new Error('Usage: designer ask "<text>" | - (stdin) | --prompt-file path --key k');
134
+ const c = new DesignerController({ key });
135
+ const r = await c.ask(prompt, {
136
+ file: flags.file,
137
+ timeoutMs: flags.timeoutMs ? Number(flags.timeoutMs) : undefined,
138
+ stabilityMs: flags.stabilityMs ? Number(flags.stabilityMs) : undefined
139
+ });
140
+ console.log(JSON.stringify(r, null, 2));
141
+ break;
142
+ }
143
+ case 'handoff': {
144
+ const c = new DesignerController({ key });
145
+ const r = await c.handoff({ openFile: flags.file });
146
+ console.log(JSON.stringify(r, null, 2));
147
+ break;
148
+ }
149
+ case 'fetch': {
150
+ const filename = flags._.join(' ');
151
+ if (!filename)
152
+ throw new Error('Usage: designer fetch "<name>.html" --key k [--out path]');
153
+ const c = new DesignerController({ key });
154
+ const r = await c.fetchFile(filename);
155
+ if (flags.out) {
156
+ fs.writeFileSync(flags.out, r.html);
157
+ console.log(JSON.stringify({ file: r.file, htmlBytes: r.htmlBytes, written: flags.out }, null, 2));
158
+ }
159
+ else {
160
+ console.log(JSON.stringify({ file: r.file, htmlBytes: r.htmlBytes, iframeSrc: r.iframeSrc, htmlPreview: r.html.slice(0, 200) }, null, 2));
161
+ }
162
+ break;
163
+ }
164
+ case 'close': {
165
+ await createBrowser({ session: `designer-${key}` }).close();
166
+ console.log('closed');
167
+ break;
168
+ }
169
+ case 'mcp': {
170
+ const sub = flags._[0];
171
+ if (sub !== 'serve') {
172
+ console.log("Usage: designer mcp serve\n Starts the MCP stdio server. Used in 'claude mcp add --transport stdio designer -- designer mcp serve'.");
173
+ process.exit(sub ? 2 : 0);
174
+ }
175
+ await startMcpServer();
176
+ break;
177
+ }
178
+ case 'setup': {
179
+ const code = await runSetup();
180
+ process.exit(code);
181
+ }
182
+ case 'health': {
183
+ const browser = createBrowser({ session: `designer-${key}` });
184
+ const results = await runHealth(browser);
185
+ const worst = results.some((r) => r.status === 'fail') ? 'fail' : 'ok';
186
+ const icon = (s) => (s === 'ok' ? '✓' : s === 'fail' ? '✗' : '·');
187
+ for (const r of results) {
188
+ const line = `${icon(r.status)} [${r.category}] ${r.id} — ${r.description}${r.detail ? ' (' + r.detail + ')' : ''}`;
189
+ console.log(line);
190
+ }
191
+ const counts = results.reduce((acc, r) => {
192
+ acc[r.status] = (acc[r.status] || 0) + 1;
193
+ return acc;
194
+ }, {});
195
+ console.log(`\n${counts['ok'] || 0} ok, ${counts['fail'] || 0} fail, ${counts['skip'] || 0} skip`);
196
+ if (worst === 'fail')
197
+ process.exit(2);
198
+ break;
199
+ }
200
+ case 'doctor': {
201
+ const checks = await runDoctor();
202
+ const fail = checks.some((c) => c.status === 'fail');
203
+ console.log(checks.map((c) => `${statusIcon(c.status)} ${c.name}${c.detail ? ' — ' + c.detail : ''}`).join('\n'));
204
+ if (fail)
205
+ process.exit(2);
206
+ break;
207
+ }
208
+ case 'tasting': {
209
+ const base = sessionDir(key);
210
+ const handoffs = fs
211
+ .readdirSync(base)
212
+ .filter((e) => e.startsWith('handoff-'))
213
+ .map((e) => path.join(base, e))
214
+ .filter((p) => fs.statSync(p).isDirectory())
215
+ .sort();
216
+ const latest = handoffs[handoffs.length - 1];
217
+ if (!latest)
218
+ throw new Error(`No handoff bundle found for key=${key}. Run 'designer handoff --key ${key}' first.`);
219
+ const slugDirs = fs
220
+ .readdirSync(latest)
221
+ .filter((e) => e !== 'bundle.tar.gz')
222
+ .map((e) => path.join(latest, e))
223
+ .filter((p) => fs.statSync(p).isDirectory());
224
+ const slugDir = slugDirs[0];
225
+ if (!slugDir)
226
+ throw new Error('Bundle has no project subdirectory.');
227
+ const projectDir = path.join(slugDir, 'project');
228
+ if (!fs.existsSync(projectDir))
229
+ throw new Error(`Missing ${projectDir}`);
230
+ const files = [];
231
+ const stack = [''];
232
+ while (stack.length) {
233
+ const rel = stack.pop();
234
+ const abs = path.join(projectDir, rel);
235
+ for (const entry of fs.readdirSync(abs)) {
236
+ const childRel = rel ? path.join(rel, entry) : entry;
237
+ const childAbs = path.join(projectDir, childRel);
238
+ if (fs.statSync(childAbs).isDirectory()) {
239
+ stack.push(childRel);
240
+ continue;
241
+ }
242
+ if (!entry.endsWith('.html') || entry === 'tasting.html' || entry === 'index.html')
243
+ continue;
244
+ files.push(childRel);
245
+ }
246
+ }
247
+ if (files.length === 0)
248
+ throw new Error('No .html variants found in bundle project dir.');
249
+ const variants = files.map((f) => ({
250
+ name: prettyName(path.basename(f)),
251
+ file: f
252
+ }));
253
+ const tastingPath = writeTastingHtml({ projectDir, variants, title: key });
254
+ const { url, port, pid } = await serveAndOpen(projectDir, { file: 'tasting.html' });
255
+ console.log(JSON.stringify({ ok: true, tastingPath, url, port, serverPid: pid, variants }, null, 2));
256
+ break;
257
+ }
258
+ case '--help':
259
+ case '-h':
260
+ case 'help':
261
+ case undefined:
262
+ default: {
263
+ const verb = cmd === 'help' ? flags._[0] : cmd && cmd !== '--help' && cmd !== '-h' ? cmd : undefined;
264
+ if (verb && HELP[verb]) {
265
+ console.log(HELP[verb]);
266
+ }
267
+ else {
268
+ console.log(TOP_HELP);
269
+ }
270
+ if (cmd && cmd !== 'help' && cmd !== '--help' && cmd !== '-h' && cmd !== undefined && !HELP[cmd]) {
271
+ process.exit(1);
272
+ }
273
+ }
274
+ }
275
+ }
276
+ const TOP_HELP = `designer — CLI + MCP for iterating on claude.ai/design
277
+
278
+ Typical loop:
279
+ designer setup (once per machine)
280
+ designer session --action create --name "X" --key x start a project
281
+ designer prompt "design the …" --key x prints 'Taste here: <url>' ← open that
282
+ designer prompt - --key x < follow-up.txt iterate until human says yes
283
+ designer handoff --key x bundle for code implementation
284
+
285
+ Session lifecycle:
286
+ session [--action status|ensure_ready|resume|create] [--name N] [--fidelity wireframe|highfi] [--key k]
287
+ enter/inspect/transition (primary entry)
288
+ status [--key k] read stored state
289
+ list list locally-tracked sessions
290
+ close [--key k] close browser (state preserved)
291
+
292
+ Design operations (prompt + snapshot print 'Taste here: <url>' above the JSON):
293
+ prompt "<text>" | - | --prompt-file p [--key k] [--file f.html] [--timeoutMs n] [--stabilityMs n]
294
+ ask "<text>" | - | --prompt-file p [--key k] [--file f.html]
295
+ snapshot [--key k] [--file f.html]
296
+
297
+ File / project introspection:
298
+ projects all Claude projects (scrapes home)
299
+ files [--key k] files in current project
300
+ open-file "<name>.html" [--key k] switch open file
301
+ fetch "<name>.html" [--key k] [--out p] fetch served HTML to disk
302
+
303
+ Exit / promotion:
304
+ handoff [--key k] [--file "<name>.html"] download tar.gz bundle (README + chats + source)
305
+ tasting [--key k] local full-viewport switcher for the latest bundle
306
+ (fallback when Claude's URL framing hurts taste)
307
+
308
+ Setup / ops:
309
+ setup one-call first-run
310
+ doctor diagnose setup state
311
+ health probe every UI anchor we depend on
312
+
313
+ Internal:
314
+ mcp serve start MCP stdio server ('claude mcp add' uses this)
315
+
316
+ All verbs accept --key <k> for parallel isolation.
317
+ Env: DESIGNER_CDP=9222 (auto-detected after 'designer setup').
318
+
319
+ Per-verb detail: designer help <verb> or designer <verb> --help`;
320
+ const HELP = {
321
+ session: `designer session — enter, inspect, or transition a claude.ai/design session.
322
+
323
+ Flags:
324
+ --action <a> status (default, read-only) | ensure_ready | resume | create
325
+ --name <N> required when --action create
326
+ --fidelity <f> wireframe | highfi — locked at creation, default wireframe
327
+ --key <k> stable session key (e.g., feature name), defaults to 'default'
328
+
329
+ Examples:
330
+ designer session # read status of 'default'
331
+ designer session --action create --name "feat X" --fidelity highfi --key feat-x
332
+ designer session --action resume --key feat-x
333
+ designer session --key feat-x # status for feat-x`,
334
+ prompt: `designer prompt — modify the design. Waits for HTML to change and stabilize.
335
+
336
+ Input (pick one):
337
+ "<text>" literal argument (positional)
338
+ - read from stdin
339
+ --prompt-file <path> read from file
340
+
341
+ Flags:
342
+ --key <k> session to target (default: 'default')
343
+ --file <f.html> switch to this file before prompting
344
+ --timeoutMs <n> default 20 minutes
345
+ --stabilityMs <n> default 4 seconds
346
+
347
+ Output: prints 'Taste here: <url>' then JSON metadata (done, newFiles, htmlPath, screenshotPath,
348
+ htmlHash, chatReply). HTML is written to disk (read htmlPath if needed); it's not inline.
349
+
350
+ Auto-appended to every prompt: 'Keep all generated files at the project root; no subfolders.'
351
+ Override by explicitly contradicting it in your prompt text.
352
+
353
+ Examples:
354
+ designer prompt "add a Remember-me checkbox" --key feat-x
355
+ designer prompt --prompt-file ./brief.md --key feat-x
356
+ cat follow-up.txt | designer prompt - --key feat-x`,
357
+ ask: `designer ask — Q&A with the design assistant. No file changes; returns the reply.
358
+
359
+ Input (pick one):
360
+ "<text>" literal argument
361
+ - read from stdin
362
+ --prompt-file <path> read from file
363
+
364
+ Flags:
365
+ --key <k> session to target
366
+ --file <f.html> switch to this file first (gives Claude context)
367
+ --timeoutMs <n> default 5 minutes
368
+
369
+ Output: JSON with { ok, reply, elapsedMs, failureMode }.
370
+
371
+ Use for 'why did you choose X?', 'compare A and B', 'suggest 3 alternatives before I commit'.
372
+ Distinct from prompt because it watches the chat panel, not the served HTML.`,
373
+ snapshot: `designer snapshot — capture current design state without prompting.
374
+
375
+ Flags:
376
+ --key <k> session to target
377
+ --file <f.html> switch to this file first
378
+
379
+ Output: prints 'Taste here: <url>' then JSON with { file, url, htmlBytes, screenshotPath }.
380
+ Useful when you want to inspect a variant or save the current state to disk without iterating.`,
381
+ handoff: `designer handoff — trigger Export→Handoff and download the tar.gz bundle.
382
+
383
+ Flags:
384
+ --key <k> session to target
385
+ --file <name.html> switch to this file first (marks it as the primary in the bundle)
386
+
387
+ Bundle contains:
388
+ README.md handoff protocol for the implementing agent
389
+ chats/chat1.md full transcript — every prompt + reply, verbatim (the decision record)
390
+ project/* all design files (HTML, standalone HTML, JSX, CSS)
391
+
392
+ Lands under ./artifacts/{key}/handoff-{timestamp}/. Non-optional for code promotion — the
393
+ implementing agent (Claude Code downstream) reads README + chats first, then builds in real code.`,
394
+ tasting: `designer tasting — build a local full-viewport switcher over the latest handoff bundle.
395
+
396
+ Flags:
397
+ --key <k> session to target
398
+ --port <n> default auto-assigned from 8765
399
+
400
+ What it does: walks the latest handoff's project/ dir, writes tasting.html with variant tabs
401
+ (keyboard 1/N to switch) + notes field (persisted in localStorage), starts http.server, opens
402
+ the browser.
403
+
404
+ Use when Claude.ai/design's IDE chrome (chat panel, toolbar) is stealing viewport space that
405
+ the design needs for judgment. Requires a prior 'designer handoff'.`,
406
+ setup: `designer setup — one-call first-run for this machine.
407
+
408
+ Runs in order, idempotent at every step:
409
+ 1. npm install (if missing)
410
+ 2. Check agent-browser on PATH
411
+ 3. If non-debug Chrome running → ask you to Cmd+Q, poll until quit
412
+ 4. Auto-launch debug Chrome with --remote-debugging-port + dedicated --user-data-dir
413
+ 5. Poll until you sign in to Claude and reach /design
414
+ 6. Copy the designer-loop skill to ~/.claude/skills/
415
+ 7. Register the MCP server with Claude Code at user scope
416
+
417
+ Re-run any time; every step no-ops when already satisfied.`,
418
+ doctor: `designer doctor — diagnose first-run setup state without changing anything.
419
+
420
+ Checks: agent-browser on PATH, CDP reachable at DESIGNER_CDP port, a /design tab is open,
421
+ selectors.json present, designer-loop skill installed at ~/.claude/skills/, MCP registration.
422
+
423
+ Exits with code 2 if any check fails.`,
424
+ health: `designer health — probe every UI anchor this MCP depends on.
425
+
426
+ Walks the current Chrome state (home / session) and checks each selector / button / URL /
427
+ DOM pattern we rely on. Reports pass / fail / skip per anchor with actionable detail.
428
+
429
+ Exit code 2 on any fail — wire into cron or CI to catch UI regressions (e.g., claude.ai
430
+ moving the Share button) before users do.`,
431
+ 'mcp': `designer mcp serve — start the MCP stdio server.
432
+
433
+ Used by 'claude mcp add':
434
+ claude mcp add --transport stdio designer -- env DESIGNER_CDP=9222 designer mcp serve
435
+
436
+ Handled automatically by 'designer setup'.`,
437
+ files: `designer files — list filenames in the current project (scrapes the design-files panel).
438
+
439
+ Flags: --key <k>
440
+
441
+ Note: the scrape is flat-only. Files nested under folders (directions/, variants/) are
442
+ invisible to this command. The handoff bundle is always folder-aware — use that for
443
+ authoritative file listing.`,
444
+ projects: `designer projects — list all Claude design projects visible on /design home.
445
+
446
+ Output: JSON array of { name, sub (subtitle, e.g., 'Today'), url }.`,
447
+ 'open-file': `designer open-file "<name>.html" — switch the currently-open file in the project.
448
+
449
+ Flags: --key <k>
450
+
451
+ URL-encodes the filename and navigates to ?file=<name>. Useful mid-iteration.`,
452
+ fetch: `designer fetch "<name>.html" — fetch a file's served HTML.
453
+
454
+ Flags:
455
+ --key <k>
456
+ --out <path> write HTML to this path
457
+
458
+ Without --out, returns JSON with a 200-char preview. With --out, writes the full HTML and
459
+ returns { file, htmlBytes, written }.`,
460
+ close: `designer close — close the browser (state on disk is preserved).
461
+
462
+ Flags: --key <k>
463
+
464
+ Rarely needed; the debug Chrome window persists across designer calls. Primary use is
465
+ test cleanup.`,
466
+ status: `designer status — print stored state for a session.
467
+
468
+ Flags: --key <k>
469
+
470
+ Output: the full session record from ~/.designer/sessions.json — createdAt, designUrl,
471
+ name, fidelity, lastUrl, full history.`,
472
+ list: `designer list — list all locally-tracked sessions from ~/.designer/sessions.json.
473
+
474
+ No flags. Output: JSON array of session records.`
475
+ };
476
+ function statusIcon(s) {
477
+ return s === 'ok' ? '✓' : s === 'warn' ? '⚠' : '✗';
478
+ }
479
+ async function runDoctor() {
480
+ const out = [];
481
+ out.push(checkDeps());
482
+ out.push(await checkAgentBrowser());
483
+ out.push(await checkCdp());
484
+ out.push(await checkOnDesignSurface());
485
+ out.push(checkSelectors());
486
+ out.push(checkSkillInstalled());
487
+ out.push(await checkMcpRegistered());
488
+ return out;
489
+ }
490
+ function checkDeps() {
491
+ const nm = path.join(REPO_ROOT, 'node_modules');
492
+ if (!fs.existsSync(nm)) {
493
+ return { name: 'dependencies installed', status: 'fail', detail: 'node_modules missing — run `designer setup` or `npm install`' };
494
+ }
495
+ const rootLock = path.join(REPO_ROOT, 'package-lock.json');
496
+ const innerLock = path.join(nm, '.package-lock.json');
497
+ if (!fs.existsSync(rootLock) || !fs.existsSync(innerLock)) {
498
+ return { name: 'dependencies installed', status: 'ok', detail: 'node_modules present (no lockfile to compare)' };
499
+ }
500
+ const h = (p) => createHash('sha1').update(fs.readFileSync(p)).digest('hex');
501
+ if (h(rootLock) !== h(innerLock)) {
502
+ return { name: 'dependencies installed', status: 'warn', detail: 'node_modules stale (lockfile mismatch) — run `npm install`' };
503
+ }
504
+ return { name: 'dependencies installed', status: 'ok', detail: 'in sync with package-lock' };
505
+ }
506
+ async function checkAgentBrowser() {
507
+ return new Promise((resolve) => {
508
+ const c = spawn('agent-browser', ['--version'], { stdio: 'pipe' });
509
+ let v = '';
510
+ c.stdout.on('data', (d) => (v += d.toString()));
511
+ c.on('error', () => resolve({ name: 'agent-browser installed', status: 'fail', detail: 'binary not found on PATH; install from https://github.com/agent-browser/agent-browser' }));
512
+ c.on('close', () => resolve({ name: 'agent-browser installed', status: 'ok', detail: v.trim() || 'present' }));
513
+ });
514
+ }
515
+ async function checkCdp() {
516
+ const port = process.env.DESIGNER_CDP || '9222';
517
+ if (!process.env.DESIGNER_CDP) {
518
+ return { name: `CDP at port ${port}`, status: 'warn', detail: 'DESIGNER_CDP not set; defaulting to 9222. export DESIGNER_CDP=9222 to silence.' };
519
+ }
520
+ try {
521
+ const res = await fetch(`http://127.0.0.1:${port}/json/version`);
522
+ if (!res.ok)
523
+ return { name: `CDP at port ${port}`, status: 'fail', detail: `HTTP ${res.status}` };
524
+ const j = await res.json();
525
+ return { name: `CDP at port ${port}`, status: 'ok', detail: j.Browser || 'connected' };
526
+ }
527
+ catch (e) {
528
+ return {
529
+ name: `CDP at port ${port}`,
530
+ status: 'fail',
531
+ detail: `not reachable. Run: ./scripts/designer-chrome.sh (launches Chrome with --remote-debugging-port=${port} in a dedicated profile)`
532
+ };
533
+ }
534
+ }
535
+ async function checkOnDesignSurface() {
536
+ const port = process.env.DESIGNER_CDP || '9222';
537
+ try {
538
+ const res = await fetch(`http://127.0.0.1:${port}/json/list`);
539
+ if (!res.ok)
540
+ return { name: 'logged into claude.ai/design', status: 'fail', detail: `HTTP ${res.status}` };
541
+ const tabs = await res.json();
542
+ const onDesign = tabs.find((t) => t.url && /claude\.ai\/design/.test(t.url));
543
+ if (!onDesign)
544
+ return { name: 'logged into claude.ai/design', status: 'warn', detail: 'no tab on claude.ai/design — sign in and navigate there in the debug Chrome window' };
545
+ if (/login|sign in/i.test(onDesign.title || ''))
546
+ return { name: 'logged into claude.ai/design', status: 'fail', detail: 'on a login page; sign in inside the debug Chrome window' };
547
+ return { name: 'logged into claude.ai/design', status: 'ok', detail: onDesign.url };
548
+ }
549
+ catch {
550
+ return { name: 'logged into claude.ai/design', status: 'fail', detail: 'CDP not reachable; fix CDP first' };
551
+ }
552
+ }
553
+ function checkSelectors() {
554
+ try {
555
+ fs.readFileSync(path.join(REPO_ROOT, 'selectors.json'), 'utf8');
556
+ return { name: 'selectors.json present', status: 'ok' };
557
+ }
558
+ catch {
559
+ return { name: 'selectors.json present', status: 'fail', detail: 'missing — re-clone or restore from git' };
560
+ }
561
+ }
562
+ function checkSkillInstalled() {
563
+ const home = process.env.HOME || '';
564
+ const skillDir = path.join(home, '.claude', 'skills', 'designer-loop');
565
+ const skillPath = path.join(skillDir, 'SKILL.md');
566
+ if (!fs.existsSync(skillPath)) {
567
+ return { name: 'designer-loop skill installed', status: 'warn', detail: `not at ${skillPath}; agent will lack loop guidance` };
568
+ }
569
+ try {
570
+ if (fs.lstatSync(skillDir).isSymbolicLink()) {
571
+ return { name: 'designer-loop skill installed', status: 'ok', detail: `${skillDir} → ${fs.realpathSync(skillDir)}` };
572
+ }
573
+ }
574
+ catch { }
575
+ return { name: 'designer-loop skill installed', status: 'ok', detail: skillDir };
576
+ }
577
+ async function checkMcpRegistered() {
578
+ const which = spawnSync('which', ['claude'], { stdio: 'pipe' });
579
+ if (which.status !== 0) {
580
+ return { name: 'MCP registered with Claude Code', status: 'warn', detail: 'claude CLI not on PATH; install Claude Code to verify' };
581
+ }
582
+ const list = spawnSync('claude', ['mcp', 'list'], { stdio: 'pipe' });
583
+ if (list.status !== 0) {
584
+ return { name: 'MCP registered with Claude Code', status: 'fail', detail: `\`claude mcp list\` exited ${list.status}` };
585
+ }
586
+ const stdout = list.stdout?.toString() || '';
587
+ const line = stdout.split('\n').find((l) => /(\s|^)designer\b/i.test(l));
588
+ if (!line) {
589
+ return { name: 'MCP registered with Claude Code', status: 'warn', detail: 'not registered — run `designer setup` or see README' };
590
+ }
591
+ return { name: 'MCP registered with Claude Code', status: 'ok', detail: line.trim() };
592
+ }
593
+ async function readPromptArg(flags) {
594
+ if (flags['prompt-file']) {
595
+ const p = flags['prompt-file'];
596
+ return fs.readFileSync(p, 'utf8').trim();
597
+ }
598
+ const positional = flags._.join(' ').trim();
599
+ if (positional === '-') {
600
+ const chunks = [];
601
+ for await (const chunk of process.stdin)
602
+ chunks.push(chunk.toString());
603
+ return chunks.join('').trim();
604
+ }
605
+ return positional;
606
+ }
607
+ function prettyName(filename) {
608
+ return filename
609
+ .replace(/\.html$/i, '')
610
+ .replace(/^(?:v\d+-|Philemon\s*[—-]\s*|.*?\s-\s)/i, '')
611
+ .replace(/[-_]+/g, ' ')
612
+ .trim()
613
+ .replace(/\b\w/g, (c) => c.toUpperCase()) || filename;
614
+ }
615
+ main().catch((e) => {
616
+ console.error(e.message);
617
+ process.exit(1);
618
+ });