@srobroek/pi-design 0.0.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 (59) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/LICENSE +202 -0
  3. package/README.md +438 -2
  4. package/_kit/prereqs.json +41 -0
  5. package/_kit/prereqs.ts +374 -0
  6. package/agents/a11y-auditor.md +107 -0
  7. package/agents/council-user.md +25 -0
  8. package/agents/council-ux.md +25 -0
  9. package/agents/design-critic.md +80 -0
  10. package/agents/ui-implementer.md +75 -0
  11. package/agents/ui-ux-specialist.md +133 -0
  12. package/commands/council-product.md +26 -0
  13. package/commands/design-review.md +17 -0
  14. package/extensions/design.js +438 -0
  15. package/formulas/design-surface.formula.toml +344 -0
  16. package/formulas/design-system.formula.toml +509 -0
  17. package/formulas/design-touch.formula.toml +188 -0
  18. package/formulas/mol-design-a11y.formula.toml +128 -0
  19. package/formulas/mol-design-component.formula.toml +122 -0
  20. package/formulas/mol-design-iterate.formula.toml +187 -0
  21. package/formulas/mol-design-motion.formula.toml +138 -0
  22. package/formulas/mol-design-responsive.formula.toml +135 -0
  23. package/formulas/mol-design-tokens.formula.toml +165 -0
  24. package/mcp-servers.ts +49 -0
  25. package/package.json +61 -4
  26. package/skills/accessibility-audit/SKILL.md +92 -0
  27. package/skills/accessibility-audit/references/upstream.md +78 -0
  28. package/skills/design-component-truth/SKILL.md +41 -0
  29. package/skills/design-evidence/SKILL.md +21 -0
  30. package/skills/design-guide/SKILL.md +26 -0
  31. package/skills/design-md/LICENSE +21 -0
  32. package/skills/design-md/NOTICE +31 -0
  33. package/skills/design-md/SKILL.md +79 -0
  34. package/skills/design-md/references/create-design-md.md +254 -0
  35. package/skills/design-md/references/upstream.md +60 -0
  36. package/skills/design-no-slop/SKILL.md +32 -0
  37. package/skills/design-prototype/SKILL.md +84 -0
  38. package/skills/design-prototype/references/in-app-variants.md +47 -0
  39. package/skills/design-prototype/references/upstream.md +43 -0
  40. package/skills/design-system-audit/SKILL.md +62 -0
  41. package/skills/design-system-audit/references/token-carriers.md +106 -0
  42. package/skills/design-system-audit/references/token-pipeline.md +115 -0
  43. package/skills/design-system-audit/references/upstream.md +52 -0
  44. package/skills/design-token-discipline/SKILL.md +24 -0
  45. package/skills/design-upstream-preflight/SKILL.md +60 -0
  46. package/skills/motion-design/SKILL.md +60 -0
  47. package/skills/ui-microcopy/LICENSE +212 -0
  48. package/skills/ui-microcopy/NOTICE +28 -0
  49. package/skills/ui-microcopy/SKILL.md +50 -0
  50. package/skills/ui-microcopy/references/copy-guidance.md +86 -0
  51. package/skills/ui-microcopy/references/upstream.md +11 -0
  52. package/skills/ui-review/SKILL.md +92 -0
  53. package/skills/ui-review/references/probes.md +446 -0
  54. package/skills/ui-review/references/storybook.md +217 -0
  55. package/skills/ui-review/references/tools.md +269 -0
  56. package/skills/ui-review/references/viewport-checks.md +184 -0
  57. package/skills/wireloom/LICENSE +21 -0
  58. package/skills/wireloom/NOTICE +30 -0
  59. package/skills/wireloom/SKILL.md +95 -0
@@ -0,0 +1,438 @@
1
+ // @bun
2
+ // Generated by scripts/build.ts. Do not edit.
3
+ // plugins/design/pi-src/design.ts
4
+ import { existsSync, mkdtempSync, rmSync } from "fs";
5
+ import { tmpdir } from "os";
6
+ import { join } from "path";
7
+ import { Type } from "typebox";
8
+
9
+ // plugins/design/shared/impeccable.ts
10
+ import { isAbsolute, resolve } from "path";
11
+
12
+ // lib/src/subprocess.ts
13
+ import { constants } from "os";
14
+ var EXIT_GRACE_MS = 2000;
15
+ var EXIT_POLL_MS = 100;
16
+ function goneWatch(graceMs, pollMs) {
17
+ const polls = Math.max(1, Math.ceil(graceMs / Math.max(1, pollMs)));
18
+ let since = null;
19
+ let seen = 0;
20
+ return (alive) => {
21
+ if (alive) {
22
+ since = null;
23
+ seen = 0;
24
+ return false;
25
+ }
26
+ since ??= Date.now();
27
+ seen++;
28
+ return seen > polls && Date.now() - since >= graceMs;
29
+ };
30
+ }
31
+ function processAlive(pid) {
32
+ try {
33
+ process.kill(pid, 0);
34
+ return true;
35
+ } catch (error) {
36
+ return error.code === "EPERM";
37
+ }
38
+ }
39
+ function killChild(child, group) {
40
+ if (group) {
41
+ try {
42
+ process.kill(-child.pid, "SIGKILL");
43
+ return;
44
+ } catch {}
45
+ }
46
+ try {
47
+ child.kill("SIGKILL");
48
+ } catch {}
49
+ }
50
+ function unref(timer) {
51
+ timer.unref?.();
52
+ }
53
+ function capture(stream) {
54
+ if (!(stream instanceof ReadableStream))
55
+ return { text: Promise.resolve(""), snapshot: () => "", cancel: () => {} };
56
+ const reader = stream.getReader();
57
+ const decoder = new TextDecoder;
58
+ let collected = "";
59
+ const text = (async () => {
60
+ try {
61
+ for (;; ) {
62
+ const chunk = await reader.read();
63
+ if (chunk.done)
64
+ break;
65
+ collected += decoder.decode(chunk.value, { stream: true });
66
+ }
67
+ } catch {}
68
+ collected += decoder.decode();
69
+ return collected;
70
+ })();
71
+ const cancel = () => {
72
+ try {
73
+ reader.cancel().catch(() => {
74
+ return;
75
+ });
76
+ } catch {}
77
+ };
78
+ return { text, snapshot: () => collected, cancel };
79
+ }
80
+ function supervise(child, options = {}) {
81
+ const grace = Math.max(0, options.graceMs ?? EXIT_GRACE_MS);
82
+ const pollMs = Math.max(1, options.pollMs ?? EXIT_POLL_MS);
83
+ const alive = options.alive ?? processAlive;
84
+ const group = options.group ?? false;
85
+ const { signal, timeoutMs } = options;
86
+ const out = capture(child.stdout);
87
+ const err = capture(child.stderr);
88
+ return new Promise((resolve) => {
89
+ let ended = null;
90
+ let exitSeen = false;
91
+ let settled = false;
92
+ const gone = goneWatch(grace, pollMs);
93
+ let deadline;
94
+ let graceTimer;
95
+ const settle = (run) => {
96
+ if (settled)
97
+ return;
98
+ settled = true;
99
+ clearTimeout(deadline);
100
+ clearTimeout(graceTimer);
101
+ clearInterval(poller);
102
+ signal?.removeEventListener("abort", onAbort);
103
+ resolve(run);
104
+ };
105
+ const end = (cause) => {
106
+ if (ended !== null || settled)
107
+ return;
108
+ ended = cause;
109
+ if (cause !== "lost" || group)
110
+ killChild(child, group);
111
+ out.cancel();
112
+ err.cancel();
113
+ graceTimer = setTimeout(() => settle({ kind: cause, stdout: out.snapshot(), stderr: err.snapshot() }), grace);
114
+ if (options.unref)
115
+ unref(graceTimer);
116
+ };
117
+ const onAbort = () => end("aborted");
118
+ const poller = setInterval(() => {
119
+ if (exitSeen || ended !== null || settled)
120
+ return;
121
+ if (gone(alive(child.pid)))
122
+ end("lost");
123
+ }, pollMs);
124
+ unref(poller);
125
+ if (timeoutMs !== undefined && timeoutMs > 0 && Number.isFinite(timeoutMs)) {
126
+ deadline = setTimeout(() => end("timeout"), timeoutMs);
127
+ if (options.unref)
128
+ unref(deadline);
129
+ }
130
+ signal?.addEventListener("abort", onAbort, { once: true });
131
+ if (signal?.aborted)
132
+ onAbort();
133
+ child.exited.then(() => {
134
+ exitSeen = true;
135
+ }, () => {
136
+ return;
137
+ });
138
+ Promise.all([child.exited, out.text, err.text]).then(([exitCode, stdout, stderr]) => {
139
+ if (ended !== null)
140
+ settle({ kind: ended, stdout, stderr });
141
+ else
142
+ settle({ kind: "exited", exitCode, signalCode: signalName(child.signalCode), stdout, stderr });
143
+ }, () => end("lost"));
144
+ });
145
+ }
146
+ function signalName(code) {
147
+ if (code === null || code === undefined)
148
+ return null;
149
+ if (typeof code === "string")
150
+ return code;
151
+ return Object.entries(constants.signals).find(([, n]) => n === code)?.[0] ?? String(code);
152
+ }
153
+
154
+ // plugins/design/shared/impeccable.ts
155
+ var SCAN_TOOL = "design_impeccable_scan";
156
+ var DEFAULT_TIMEOUT_SECONDS = 180;
157
+ var MAX_TIMEOUT_SECONDS = 900;
158
+ var MAX_OUTPUT_CHARS = 60000;
159
+ var SCAN_SUMMARY = "Run impeccable's deterministic design detector over files, directories or a URL; returns JSON findings.";
160
+ var SCAN_CAVEAT = "Findings are a coarse corroborating signal: HTML-engine findings can carry line 0, so confirm each one " + "on the rendered surface before citing it.";
161
+ var SCAN_INPUT = {
162
+ type: "object",
163
+ properties: {
164
+ targets: {
165
+ type: "array",
166
+ items: { type: "string" },
167
+ minItems: 1,
168
+ description: "Files, directories, or one http(s) URL to scan; relative paths resolve against the session directory"
169
+ },
170
+ noConfig: {
171
+ type: "boolean",
172
+ description: "Raw scan that ignores .impeccable/config.json ignores and inline waivers (--no-config)"
173
+ },
174
+ viewport: {
175
+ type: "string",
176
+ pattern: "^[1-9][0-9]{1,4}x[1-9][0-9]{1,4}$",
177
+ description: "URL scans only: viewport as WIDTHxHEIGHT, for example 375x812 (detector default 1280x800)"
178
+ },
179
+ timeoutSeconds: {
180
+ type: "integer",
181
+ minimum: 1,
182
+ maximum: MAX_TIMEOUT_SECONDS,
183
+ description: `Kill the scan after this long (default ${DEFAULT_TIMEOUT_SECONDS}; a first run downloads the engine)`
184
+ }
185
+ },
186
+ required: ["targets"],
187
+ additionalProperties: false
188
+ };
189
+ var URL_TARGET = /^https?:\/\//i;
190
+ var VIEWPORT = /^[1-9][0-9]{1,4}x[1-9][0-9]{1,4}$/;
191
+ function readScanParams(input) {
192
+ const value = input ?? {};
193
+ const targets = value.targets;
194
+ if (!Array.isArray(targets) || targets.length === 0)
195
+ return "targets must be a non-empty array of strings";
196
+ for (const target of targets) {
197
+ if (typeof target !== "string" || target.trim() === "")
198
+ return "every target must be a non-empty string";
199
+ if (target.startsWith("-"))
200
+ return `target ${JSON.stringify(target)} starts with "-"; pass a path such as ./${target}`;
201
+ }
202
+ if (value.noConfig !== undefined && typeof value.noConfig !== "boolean")
203
+ return "noConfig must be a boolean";
204
+ if (value.viewport !== undefined && (typeof value.viewport !== "string" || !VIEWPORT.test(value.viewport)))
205
+ return "viewport must be WIDTHxHEIGHT, for example 375x812";
206
+ const timeout = value.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
207
+ if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)
208
+ return `timeoutSeconds must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`;
209
+ const params = { targets, noConfig: value.noConfig === true, timeoutSeconds: timeout };
210
+ if (typeof value.viewport === "string")
211
+ params.viewport = value.viewport;
212
+ return params;
213
+ }
214
+ function resolveTargets(targets, cwd) {
215
+ return targets.map((target) => URL_TARGET.test(target) || isAbsolute(target) ? target : resolve(cwd, target));
216
+ }
217
+ var NPX_RUNNER = { kind: "npx", argv: ["npx", "--yes", "impeccable"] };
218
+ function chooseScanRunner(which) {
219
+ const found = which("impeccable");
220
+ return found ? { kind: "path", argv: [found] } : NPX_RUNNER;
221
+ }
222
+ function downloadQuestion(resources) {
223
+ return `Run npx --yes impeccable detect on ${resources.join(", ")}? npx may download impeccable and its engine from the network before scanning.`;
224
+ }
225
+ function scanArgv(params, targets, runner = NPX_RUNNER) {
226
+ return [
227
+ ...runner.argv,
228
+ "detect",
229
+ "--json",
230
+ ...params.noConfig ? ["--no-config"] : [],
231
+ ...params.viewport ? ["--viewport", params.viewport] : [],
232
+ ...targets
233
+ ];
234
+ }
235
+ function countFindings(json) {
236
+ if (Array.isArray(json))
237
+ return json.length;
238
+ if (json !== null && typeof json === "object") {
239
+ const record = json;
240
+ for (const key of ["findings", "results", "issues"]) {
241
+ const list = record[key];
242
+ if (Array.isArray(list))
243
+ return list.length;
244
+ }
245
+ }
246
+ return null;
247
+ }
248
+ function clip(text) {
249
+ return text.length > MAX_OUTPUT_CHARS ? `${text.slice(0, MAX_OUTPUT_CHARS)}
250
+ [output cut at ${MAX_OUTPUT_CHARS} characters; scan fewer targets]` : text;
251
+ }
252
+ function interpretScan(run, timeoutSeconds) {
253
+ const stderr = run.stderr.trim();
254
+ if (run.kind !== "exited") {
255
+ const why = run.kind === "timeout" ? `impeccable detect did not finish within ${timeoutSeconds}s and was killed` : run.kind === "aborted" ? "impeccable detect was cancelled" : "impeccable detect ended without an exit status";
256
+ return { ok: false, status: run.kind, findings: null, text: [why, stderr].filter(Boolean).join(`
257
+ `) };
258
+ }
259
+ const stdout = run.stdout.trim();
260
+ let parsed;
261
+ let json = false;
262
+ try {
263
+ parsed = JSON.parse(stdout);
264
+ json = stdout !== "";
265
+ } catch {
266
+ json = false;
267
+ }
268
+ const findings = json ? countFindings(parsed) : null;
269
+ const code = run.exitCode;
270
+ const status = code === 0 ? "clean" : code === 2 ? "findings" : code === 1 ? "unscanned" : "failed";
271
+ const head = status === "clean" ? "impeccable detect: no primary findings. A clean run is evidence, not proof; still drive the surface." : status === "findings" ? `impeccable detect: ${findings ?? "some"} finding(s). Corroborate each on the rendered surface before citing it.` : status === "unscanned" ? "impeccable detect: at least one target could not be scanned (exit 1)." : `impeccable detect failed (exit ${code}).`;
272
+ const body = json ? stdout : [stdout, stderr].filter(Boolean).join(`
273
+ `);
274
+ return {
275
+ ok: status === "clean" || status === "findings",
276
+ status,
277
+ exitCode: code,
278
+ findings,
279
+ text: body ? `${head}
280
+ ${clip(body)}` : head
281
+ };
282
+ }
283
+ var spawnScan = async (argv, { cwd, timeoutMs, signal }) => {
284
+ try {
285
+ const child = Bun.spawn(argv, {
286
+ cwd,
287
+ stdin: "ignore",
288
+ stdout: "pipe",
289
+ stderr: "pipe",
290
+ detached: true
291
+ });
292
+ return await supervise(child, { timeoutMs, signal, group: true });
293
+ } catch (error) {
294
+ return { kind: "exited", exitCode: 127, signalCode: null, stdout: "", stderr: String(error) };
295
+ }
296
+ };
297
+ async function runScan(params, cwd, signal, exec = spawnScan, runner = NPX_RUNNER) {
298
+ const argv = scanArgv(params, resolveTargets(params.targets, cwd), runner);
299
+ const run = await exec(argv, { cwd, timeoutMs: params.timeoutSeconds * 1000, signal });
300
+ return interpretScan(run, params.timeoutSeconds);
301
+ }
302
+
303
+ // plugins/design/pi-src/playwright.ts
304
+ var PLAYWRIGHT_MCP_VERSION = "0.0.86";
305
+ var PLAYWRIGHT_SERVER = "playwright";
306
+ var PLAYWRIGHT_ARGS = [
307
+ "-y",
308
+ `@playwright/mcp@${PLAYWRIGHT_MCP_VERSION}`,
309
+ "--isolated",
310
+ "--viewport-size",
311
+ "1440x900",
312
+ "--ignore-roots",
313
+ "--file-paths",
314
+ "absolute"
315
+ ];
316
+ var BROWSER_ENV = "PLAYWRIGHT_MCP_BROWSER";
317
+ var CHROME_PATHS = {
318
+ darwin: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
319
+ linux: "/opt/google/chrome/chrome"
320
+ };
321
+ function playwrightBrowser(env, platform, exists) {
322
+ const forced = env[BROWSER_ENV]?.trim();
323
+ if (forced)
324
+ return forced;
325
+ const chrome = CHROME_PATHS[platform];
326
+ return chrome === undefined || exists(chrome) ? "chrome" : "chromium";
327
+ }
328
+ var HEADLESS_ENV = "PLAYWRIGHT_MCP_HEADLESS";
329
+ function playwrightHeadless(env, platform) {
330
+ const forced = env[HEADLESS_ENV];
331
+ if (forced === "1" || forced === "true")
332
+ return true;
333
+ if (forced === "0" || forced === "false")
334
+ return false;
335
+ if (platform === "darwin")
336
+ return false;
337
+ return !env.DISPLAY && !env.WAYLAND_DISPLAY;
338
+ }
339
+ var TOOL_REVIEW = {
340
+ browser_run_code_unsafe: { kind: "hidden", why: "runs code, or a local file's code, in the server's Node process" },
341
+ browser_file_upload: { kind: "hidden", why: "hands local files to the page" },
342
+ browser_drop: { kind: "hidden", why: "drops local files onto the page" },
343
+ browser_evaluate: { kind: "page-script", why: "runs the ui-review probes inside the page" },
344
+ browser_console_messages: { kind: "writes-output", why: "may save the console log" },
345
+ browser_find: { kind: "writes-output", why: "may save the search result" },
346
+ browser_network_request: { kind: "writes-output", why: "may save one request" },
347
+ browser_network_requests: { kind: "writes-output", why: "may save the request list" },
348
+ browser_snapshot: { kind: "writes-output", why: "may save the ARIA snapshot" },
349
+ browser_take_screenshot: { kind: "writes-output", why: "saves the screenshot" }
350
+ };
351
+ var HIDDEN_TOOLS = Object.entries(TOOL_REVIEW).filter(([, review]) => review.kind === "hidden").map(([name]) => name);
352
+ function playwrightMcp(workspace, { browser, headless }) {
353
+ return {
354
+ command: "npx",
355
+ args: [...PLAYWRIGHT_ARGS, "--browser", browser, ...headless ? ["--headless"] : []],
356
+ cwd: workspace,
357
+ env: { npm_config_registry: "https://registry.npmjs.org/", [HEADLESS_ENV]: headless ? "true" : "false" },
358
+ description: `${headless ? "Headless" : "Headed"}, isolated ${browser} for rendered-UI review: ARIA snapshots, page evaluation, resize, keyboard, console, network and screenshots.`,
359
+ toolExposure: Object.fromEntries(HIDDEN_TOOLS.map((tool) => [tool, "hidden"]))
360
+ };
361
+ }
362
+ function hostBrowserMode(env, platform, exists) {
363
+ return { browser: playwrightBrowser(env, platform, exists), headless: playwrightHeadless(env, platform) };
364
+ }
365
+
366
+ // plugins/design/pi-src/design.ts
367
+ var IMPECCABLE_INSTALL = "mise use -g npm:impeccable";
368
+ var PI_SCAN_DESCRIPTION = `${SCAN_SUMMARY}
369
+ ` + "Runs the impeccable on PATH (the design package's prerequisite) without a prompt. Without it, npx may download " + "impeccable and its engine, so the tool asks first, and refuses in a session that cannot ask. " + SCAN_CAVEAT;
370
+ function scanConsent(runner, hasUI) {
371
+ if (runner.kind === "path")
372
+ return "run";
373
+ return hasUI ? "confirm" : "refuse";
374
+ }
375
+ var properties = SCAN_INPUT.properties;
376
+ var parameters = Type.Object({
377
+ targets: Type.Array(Type.String(), { minItems: 1, description: properties.targets.description }),
378
+ noConfig: Type.Optional(Type.Boolean({ description: properties.noConfig.description })),
379
+ viewport: Type.Optional(Type.String({ pattern: properties.viewport.pattern, description: properties.viewport.description })),
380
+ timeoutSeconds: Type.Optional(Type.Integer({
381
+ minimum: properties.timeoutSeconds.minimum,
382
+ maximum: properties.timeoutSeconds.maximum,
383
+ description: properties.timeoutSeconds.description
384
+ }))
385
+ }, { additionalProperties: false });
386
+ var text = (value, details) => ({ content: [{ type: "text", text: value }], details });
387
+ var newWorkspace = () => mkdtempSync(join(tmpdir(), "pi-design-playwright-"));
388
+ function registerDesign(pi, overrides = {}) {
389
+ const which = overrides.which ?? ((bin) => Bun.which(bin));
390
+ let workspace;
391
+ pi.on("session_start", () => {
392
+ if (workspace !== undefined)
393
+ return;
394
+ workspace = (overrides.makeWorkspace ?? newWorkspace)();
395
+ pi.registerMcpServer(PLAYWRIGHT_SERVER, playwrightMcp(workspace, hostBrowserMode(process.env, process.platform, existsSync)));
396
+ });
397
+ pi.on("session_shutdown", () => {
398
+ if (workspace === undefined)
399
+ return;
400
+ rmSync(workspace, { recursive: true, force: true });
401
+ workspace = undefined;
402
+ });
403
+ pi.registerTool({
404
+ name: SCAN_TOOL,
405
+ label: "Impeccable Scan",
406
+ description: PI_SCAN_DESCRIPTION,
407
+ parameters,
408
+ async execute(_id, raw, signal, _update, ctx) {
409
+ const params = readScanParams(raw);
410
+ if (typeof params === "string")
411
+ return text(`${SCAN_TOOL}: ${params}`, { ok: false });
412
+ const runner = chooseScanRunner(which);
413
+ const consent = scanConsent(runner, ctx.hasUI);
414
+ if (consent === "refuse")
415
+ return text(`${SCAN_TOOL}: impeccable is not on PATH, and running it through npx needs a confirmation this session cannot show. Install it with \`${IMPECCABLE_INSTALL}\` and start a new session.`, { ok: false, status: "refused", runner: runner.kind });
416
+ if (consent === "confirm" && !await ctx.ui.confirm("Download impeccable?", downloadQuestion(resolveTargets(params.targets, ctx.cwd))))
417
+ return text(`${SCAN_TOOL}: scan cancelled`, { ok: false, status: "cancelled", runner: runner.kind });
418
+ const result = await runScan(params, ctx.cwd, signal, overrides.exec, runner);
419
+ return text(result.text, {
420
+ ok: result.ok,
421
+ status: result.status,
422
+ exitCode: result.exitCode,
423
+ findings: result.findings,
424
+ runner: runner.kind
425
+ });
426
+ }
427
+ });
428
+ }
429
+ function design_default(pi) {
430
+ registerDesign(pi);
431
+ }
432
+ export {
433
+ IMPECCABLE_INSTALL,
434
+ PI_SCAN_DESCRIPTION,
435
+ design_default as default,
436
+ registerDesign,
437
+ scanConsent
438
+ };