@agimon-ai/doompi-style-system 0.0.1-alpha.100

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/apiContracts.cjs +118 -0
  4. package/dist/apiContracts.cjs.map +1 -0
  5. package/dist/apiContracts.d.mts +52 -0
  6. package/dist/apiContracts.d.mts.map +1 -0
  7. package/dist/apiContracts.mjs +113 -0
  8. package/dist/apiContracts.mjs.map +1 -0
  9. package/dist/cli.cjs +242 -0
  10. package/dist/cli.cjs.map +1 -0
  11. package/dist/cli.d.mts +4 -0
  12. package/dist/cli.d.mts.map +1 -0
  13. package/dist/cli.mjs +239 -0
  14. package/dist/cli.mjs.map +1 -0
  15. package/dist/designCheck-7P9r9ijq.mjs +475 -0
  16. package/dist/designCheck-7P9r9ijq.mjs.map +1 -0
  17. package/dist/designCheck-zx4PsRvE.cjs +495 -0
  18. package/dist/designCheck-zx4PsRvE.cjs.map +1 -0
  19. package/dist/extensions/pi.cjs +94 -0
  20. package/dist/extensions/pi.cjs.map +1 -0
  21. package/dist/extensions/pi.d.mts +5 -0
  22. package/dist/extensions/pi.d.mts.map +1 -0
  23. package/dist/extensions/pi.mjs +87 -0
  24. package/dist/extensions/pi.mjs.map +1 -0
  25. package/dist/extensions/server.cjs +136 -0
  26. package/dist/extensions/server.cjs.map +1 -0
  27. package/dist/extensions/server.d.mts +5 -0
  28. package/dist/extensions/server.d.mts.map +1 -0
  29. package/dist/extensions/server.mjs +131 -0
  30. package/dist/extensions/server.mjs.map +1 -0
  31. package/dist/extensions/web.mjs +942 -0
  32. package/dist/extensions/web.mjs.map +1 -0
  33. package/dist/index.cjs +8 -0
  34. package/dist/index.d.mts +171 -0
  35. package/dist/index.d.mts.map +1 -0
  36. package/dist/index.mjs +3 -0
  37. package/dist/rolldown-runtime-VH7oDXx4.cjs +28 -0
  38. package/dist/storyPreview-D-hGhlig.cjs +371 -0
  39. package/dist/storyPreview-D-hGhlig.cjs.map +1 -0
  40. package/dist/storyPreview-Dhejqhos.mjs +357 -0
  41. package/dist/storyPreview-Dhejqhos.mjs.map +1 -0
  42. package/package.json +132 -0
  43. package/skills/design-workflow/SKILL.md +84 -0
@@ -0,0 +1,357 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { promises } from "node:fs";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import { ComponentRendererService, StoriesIndexService, createDefaultBundlerService, getAppDesignSystemConfig } from "@agimon-ai/style-system";
6
+ //#region src/services/storyPreview/index.ts
7
+ const STORY_FILE_PATTERN = /\.stories\.(?:js|jsx|ts|tsx)$/u;
8
+ const STORY_EXPORT_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
9
+ const PNG_SIGNATURE = Buffer.from([
10
+ 137,
11
+ 80,
12
+ 78,
13
+ 71,
14
+ 13,
15
+ 10,
16
+ 26,
17
+ 10
18
+ ]);
19
+ const MAX_IMAGE_BYTES = 2097152;
20
+ const MAX_IMAGE_DIMENSION = 1600;
21
+ const NON_STORY_EXPORTS = /* @__PURE__ */ new Set([
22
+ "afterAll",
23
+ "afterEach",
24
+ "argTypes",
25
+ "beforeAll",
26
+ "beforeEach",
27
+ "component",
28
+ "decorators",
29
+ "excludeStories",
30
+ "globals",
31
+ "includeStories",
32
+ "loaders",
33
+ "meta",
34
+ "parameters",
35
+ "render",
36
+ "tags"
37
+ ]);
38
+ function isContained(root, candidate) {
39
+ const relative = path.relative(root, candidate);
40
+ return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
41
+ }
42
+ function stripComments(source) {
43
+ let output = "";
44
+ let quote;
45
+ let escaped = false;
46
+ for (let index = 0; index < source.length; index += 1) {
47
+ const character = source[index];
48
+ const next = source[index + 1];
49
+ if (quote !== void 0) {
50
+ output += character === "\n" ? "\n" : " ";
51
+ if (escaped) escaped = false;
52
+ else if (character === "\\") escaped = true;
53
+ else if (character === quote) quote = void 0;
54
+ continue;
55
+ }
56
+ if (character === "\"" || character === "'" || character === "`") {
57
+ quote = character;
58
+ output += " ";
59
+ } else if (character === "/" && next === "/") {
60
+ output += " ";
61
+ index += 2;
62
+ while (index < source.length && source[index] !== "\n") {
63
+ output += " ";
64
+ index += 1;
65
+ }
66
+ if (index < source.length) output += "\n";
67
+ } else if (character === "/" && next === "*") {
68
+ output += " ";
69
+ index += 2;
70
+ while (index < source.length && !(source[index - 1] === "*" && source[index] === "/")) {
71
+ output += source[index] === "\n" ? "\n" : " ";
72
+ index += 1;
73
+ }
74
+ } else output += character;
75
+ }
76
+ return output;
77
+ }
78
+ function storyLabel(source, clean, exportName) {
79
+ const escapedExport = exportName.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
80
+ const declaration = new RegExp(`\\bexport\\s+(?:const|let|var)\\s+${escapedExport}\\b[^=]*=\\s*\\{`, "u");
81
+ const match = clean.match(declaration);
82
+ if (match === null || match.index === void 0) return void 0;
83
+ const opening = clean.indexOf("{", match.index);
84
+ let depth = 0;
85
+ for (let index = opening; index < clean.length; index += 1) if (clean[index] === "{") depth += 1;
86
+ else if (clean[index] === "}") {
87
+ depth -= 1;
88
+ if (depth === 0) {
89
+ const label = source.slice(opening, index).match(/\bname\s*:\s*(['"])(.*?)\1/u)?.[2]?.trim();
90
+ return label === "" ? void 0 : label;
91
+ }
92
+ }
93
+ }
94
+ /** Extracts named CSF candidates without evaluating workspace source. */
95
+ function extractStoryExports(source) {
96
+ const names = [];
97
+ const seen = /* @__PURE__ */ new Set();
98
+ const add = (name) => {
99
+ if (name === "default" || NON_STORY_EXPORTS.has(name) || seen.has(name)) return;
100
+ seen.add(name);
101
+ names.push(name);
102
+ };
103
+ const clean = stripComments(source);
104
+ for (const match of clean.matchAll(/\bexport\s+(?:async\s+)?(?:const|let|var|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gu)) add(match[1]);
105
+ for (const match of clean.matchAll(/\bexport\s*\{([^}]*)\}/gu)) for (const item of match[1].split(",")) {
106
+ const name = (item.trim().split(/\s+as\s+/u).at(-1) ?? "").trim();
107
+ if (/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(name)) add(name);
108
+ }
109
+ return names.map((exportName) => {
110
+ const label = storyLabel(source, clean, exportName);
111
+ return label === void 0 ? { exportName } : {
112
+ exportName,
113
+ label
114
+ };
115
+ });
116
+ }
117
+ async function exists(filePath) {
118
+ try {
119
+ await promises.stat(filePath);
120
+ return true;
121
+ } catch {
122
+ return false;
123
+ }
124
+ }
125
+ function relativeWorkspacePath(root, candidate) {
126
+ const relative = path.relative(root, candidate).split(path.sep).join("/");
127
+ return relative === "" ? "." : relative;
128
+ }
129
+ const defaultDependencies = {
130
+ loadConfig: getAppDesignSystemConfig,
131
+ createBundler(_config) {
132
+ return createDefaultBundlerService();
133
+ },
134
+ createRenderer(config, appPath) {
135
+ return new ComponentRendererService(config, appPath);
136
+ },
137
+ rendererTemporaryRoot: () => path.join(os.tmpdir(), "style-system"),
138
+ createHandle: randomUUID
139
+ };
140
+ function pngCrc(data) {
141
+ let crc = 4294967295;
142
+ for (const byte of data) {
143
+ crc ^= byte;
144
+ for (let bit = 0; bit < 8; bit += 1) crc = crc >>> 1 ^ (crc & 1 ? 3988292384 : 0);
145
+ }
146
+ return (crc ^ 4294967295) >>> 0;
147
+ }
148
+ function pngDimensions(image) {
149
+ if (image.length < PNG_SIGNATURE.length || !image.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) throw new Error("Style-system returned an invalid PNG image");
150
+ let offset = PNG_SIGNATURE.length;
151
+ let width = 0;
152
+ let height = 0;
153
+ let chunks = 0;
154
+ let hasImageData = false;
155
+ let hasEnd = false;
156
+ while (offset < image.length) {
157
+ if (image.length - offset < 12) throw new Error("Style-system returned an invalid PNG image");
158
+ const length = image.readUInt32BE(offset);
159
+ const end = offset + 12 + length;
160
+ if (end > image.length) throw new Error("Style-system returned an invalid PNG image");
161
+ const type = image.toString("ascii", offset + 4, offset + 8);
162
+ if (!/^[A-Za-z]{4}$/u.test(type)) throw new Error("Style-system returned an invalid PNG image");
163
+ if (image.readUInt32BE(end - 4) !== pngCrc(image.subarray(offset + 4, end - 4))) throw new Error("Style-system returned an invalid PNG image");
164
+ if (chunks === 0) {
165
+ if (type !== "IHDR" || length !== 13) throw new Error("Style-system returned an invalid PNG image");
166
+ width = image.readUInt32BE(offset + 8);
167
+ height = image.readUInt32BE(offset + 12);
168
+ } else if (type === "IHDR") throw new Error("Style-system returned an invalid PNG image");
169
+ if (type === "IDAT") hasImageData = true;
170
+ if (type === "IEND") {
171
+ if (length !== 0 || end !== image.length) throw new Error("Style-system returned an invalid PNG image");
172
+ hasEnd = true;
173
+ }
174
+ chunks += 1;
175
+ offset = end;
176
+ }
177
+ if (!hasImageData || !hasEnd) throw new Error("Style-system returned an invalid PNG image");
178
+ if (width === 0 || height === 0 || width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION) throw new Error("Style-system returned PNG dimensions outside the supported range");
179
+ return {
180
+ width,
181
+ height
182
+ };
183
+ }
184
+ /** Owns disposable static story-preview artifacts for one trusted workspace. */
185
+ var StoryPreviewService = class {
186
+ root;
187
+ dependencies;
188
+ artifacts = /* @__PURE__ */ new Map();
189
+ constructor(workspaceRoot, dependencies = {}) {
190
+ this.root = path.resolve(workspaceRoot);
191
+ this.dependencies = {
192
+ ...defaultDependencies,
193
+ ...dependencies
194
+ };
195
+ }
196
+ async metadata(input) {
197
+ const root = await promises.realpath(this.root);
198
+ const storyPath = await this.resolveContainedPath(root, input.storyPath, "storyPath");
199
+ if (!STORY_FILE_PATTERN.test(storyPath)) throw new Error("storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file");
200
+ const project = await this.resolveProject(root, storyPath, input.appPath);
201
+ const source = await promises.readFile(storyPath, "utf8");
202
+ return {
203
+ storyPath: relativeWorkspacePath(root, storyPath),
204
+ appPath: relativeWorkspacePath(root, project.path),
205
+ projectResolution: project.resolution,
206
+ exports: extractStoryExports(source)
207
+ };
208
+ }
209
+ async resolveProject(root, storyPath, requestedPath) {
210
+ if (requestedPath !== void 0 && requestedPath.trim() !== "") return {
211
+ path: await this.resolveContainedPath(root, requestedPath, "appPath"),
212
+ resolution: "explicit"
213
+ };
214
+ let directory = path.dirname(storyPath);
215
+ let packagePath;
216
+ while (isContained(root, directory)) {
217
+ if (await exists(path.join(directory, "style-system.config.yaml"))) return {
218
+ path: directory,
219
+ resolution: "config"
220
+ };
221
+ if (packagePath === void 0 && await exists(path.join(directory, "package.json"))) packagePath = directory;
222
+ if (directory === root) break;
223
+ directory = path.dirname(directory);
224
+ }
225
+ return packagePath === void 0 ? {
226
+ path: root,
227
+ resolution: "workspace"
228
+ } : {
229
+ path: packagePath,
230
+ resolution: "package"
231
+ };
232
+ }
233
+ async exactStory(root, storyPath, storyExport) {
234
+ if (!extractStoryExports(await promises.readFile(storyPath, "utf8")).some((entry) => entry.exportName === storyExport)) throw new Error(`Story export "${storyExport}" was not found in ${relativeWorkspacePath(root, storyPath)}.`);
235
+ const index = new StoriesIndexService({
236
+ workspaceRoot: root,
237
+ storyFiles: [storyPath],
238
+ searchRoots: []
239
+ });
240
+ await index.initialize();
241
+ const component = index.getAllComponents().find((entry) => path.resolve(entry.filePath) === storyPath);
242
+ if (component === void 0) throw new Error("The requested story file could not be indexed.");
243
+ return component;
244
+ }
245
+ async build(input) {
246
+ if (!STORY_EXPORT_PATTERN.test(input.storyExport)) throw new Error("storyExport must be an exact JavaScript named export");
247
+ const root = await promises.realpath(this.root);
248
+ const appPath = await this.resolveContainedPath(root, input.appPath, "appPath");
249
+ const storyPath = await this.resolveContainedPath(root, input.storyPath, "storyPath");
250
+ if (!STORY_FILE_PATTERN.test(storyPath)) throw new Error("storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file");
251
+ await this.exactStory(root, storyPath, input.storyExport);
252
+ const [source, config] = await Promise.all([promises.readFile(storyPath, "utf8"), this.dependencies.loadConfig(appPath)]);
253
+ const bundler = this.dependencies.createBundler(config);
254
+ let artifactDirectory;
255
+ try {
256
+ const rendered = await bundler.prerenderComponent({
257
+ componentPath: storyPath,
258
+ storyName: input.storyExport,
259
+ args: input.args,
260
+ darkMode: input.darkMode,
261
+ appPath,
262
+ themePath: config.themeProvider,
263
+ cssFiles: config.cssFiles,
264
+ rootComponent: config.rootComponent,
265
+ unistylesConfig: config.unistylesConfig
266
+ });
267
+ const htmlPath = await promises.realpath(rendered.htmlFilePath);
268
+ const candidateDirectory = path.dirname(htmlPath);
269
+ const temporaryRoot = path.join(appPath, ".tmp");
270
+ if (candidateDirectory === temporaryRoot || !isContained(temporaryRoot, candidateDirectory)) throw new Error("Style-system returned a preview artifact outside the project temporary directory");
271
+ artifactDirectory = candidateDirectory;
272
+ const handle = this.dependencies.createHandle();
273
+ const html = await promises.readFile(htmlPath, "utf8");
274
+ this.artifacts.set(handle, { directory: artifactDirectory });
275
+ return {
276
+ handle,
277
+ html,
278
+ storyPath: relativeWorkspacePath(root, storyPath),
279
+ storyExport: input.storyExport,
280
+ sourceSha256: createHash("sha256").update(source).digest("hex")
281
+ };
282
+ } catch (reason) {
283
+ if (artifactDirectory !== void 0) await promises.rm(artifactDirectory, {
284
+ recursive: true,
285
+ force: true
286
+ });
287
+ throw reason;
288
+ }
289
+ }
290
+ /** Renders a fresh source-backed PNG. This does not preserve transient iframe interaction state. */
291
+ async exportImage(input) {
292
+ if (!STORY_EXPORT_PATTERN.test(input.storyExport)) throw new Error("storyExport must be an exact JavaScript named export");
293
+ const root = await promises.realpath(this.root);
294
+ const appPath = await this.resolveContainedPath(root, input.appPath, "appPath");
295
+ const storyPath = await this.resolveContainedPath(root, input.storyPath, "storyPath");
296
+ if (!STORY_FILE_PATTERN.test(storyPath)) throw new Error("storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file");
297
+ const [source, config] = await Promise.all([promises.readFile(storyPath, "utf8"), this.dependencies.loadConfig(appPath)]);
298
+ const renderer = this.dependencies.createRenderer(config, appPath);
299
+ let ownedImagePath;
300
+ try {
301
+ const component = await this.exactStory(root, storyPath, input.storyExport);
302
+ const rendered = await renderer.renderComponent(component, {
303
+ storyName: input.storyExport,
304
+ darkMode: input.darkMode
305
+ });
306
+ const [renderedImagePath, imageRoot] = await Promise.all([promises.realpath(rendered.imagePath), promises.realpath(this.dependencies.rendererTemporaryRoot())]);
307
+ if (renderedImagePath === imageRoot || !isContained(imageRoot, renderedImagePath)) throw new Error("Style-system returned an image artifact outside its temporary directory");
308
+ const imageStat = await promises.stat(renderedImagePath);
309
+ if (!imageStat.isFile()) throw new Error("Style-system returned a non-regular PNG image");
310
+ ownedImagePath = renderedImagePath;
311
+ if (imageStat.size > MAX_IMAGE_BYTES) throw new Error("Style-system returned an oversized PNG image");
312
+ const image = await promises.readFile(renderedImagePath);
313
+ if (image.length !== imageStat.size) throw new Error("Style-system PNG changed while it was being read");
314
+ const { width, height } = pngDimensions(image);
315
+ return {
316
+ data: image.toString("base64"),
317
+ mimeType: "image/png",
318
+ captureId: this.dependencies.createHandle(),
319
+ width,
320
+ height,
321
+ storyPath: relativeWorkspacePath(root, storyPath),
322
+ storyExport: input.storyExport,
323
+ sourceSha256: createHash("sha256").update(source).digest("hex")
324
+ };
325
+ } finally {
326
+ try {
327
+ if (ownedImagePath !== void 0) await promises.rm(ownedImagePath, { force: true });
328
+ } finally {
329
+ await renderer.dispose();
330
+ }
331
+ }
332
+ }
333
+ async dispose(handle) {
334
+ const artifact = this.artifacts.get(handle);
335
+ if (artifact === void 0) return false;
336
+ this.artifacts.delete(handle);
337
+ await promises.rm(artifact.directory, {
338
+ recursive: true,
339
+ force: true
340
+ });
341
+ return true;
342
+ }
343
+ async disposeAll() {
344
+ await Promise.all([...this.artifacts.keys()].map((handle) => this.dispose(handle)));
345
+ }
346
+ async resolveContainedPath(root, inputPath, field) {
347
+ if (inputPath.trim() === "") throw new Error(`${field} is required`);
348
+ const candidate = path.isAbsolute(inputPath) ? inputPath : path.resolve(root, inputPath);
349
+ const canonical = await promises.realpath(candidate);
350
+ if (!isContained(root, canonical)) throw new Error(`${field} must remain inside the workspace root`);
351
+ return canonical;
352
+ }
353
+ };
354
+ //#endregion
355
+ export { extractStoryExports as n, StoryPreviewService as t };
356
+
357
+ //# sourceMappingURL=storyPreview-Dhejqhos.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyPreview-Dhejqhos.mjs","names":["fs"],"sources":["../src/services/storyPreview/index.ts"],"sourcesContent":["import { createHash, randomUUID } from 'node:crypto';\nimport { promises as fs } from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport {\n ComponentRendererService,\n createDefaultBundlerService,\n getAppDesignSystemConfig,\n StoriesIndexService,\n type BaseBundlerService,\n type DesignSystemConfig,\n} from '@agimon-ai/style-system';\n\nimport type { StoryPreviewExport, StoryPreviewMetadataRequest, StoryPreviewMetadataView } from '../../types/previewApi';\nimport type {\n StoryPreviewBuildInput,\n StoryPreviewBuildResult,\n StoryPreviewImageResult,\n StoryPreviewServiceDependencies,\n} from './type';\n\nconst STORY_FILE_PATTERN = /\\.stories\\.(?:js|jsx|ts|tsx)$/u;\nconst STORY_EXPORT_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\nconst PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\nconst MAX_IMAGE_BYTES = 2 * 1024 * 1024;\nconst MAX_IMAGE_DIMENSION = 1600;\nconst NON_STORY_EXPORTS = new Set([\n 'afterAll',\n 'afterEach',\n 'argTypes',\n 'beforeAll',\n 'beforeEach',\n 'component',\n 'decorators',\n 'excludeStories',\n 'globals',\n 'includeStories',\n 'loaders',\n 'meta',\n 'parameters',\n 'render',\n 'tags',\n]);\n\ninterface OwnedArtifact {\n directory: string;\n}\n\nfunction isContained(root: string, candidate: string): boolean {\n const relative = path.relative(root, candidate);\n return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));\n}\n\nfunction stripComments(source: string): string {\n let output = '';\n let quote: \"'\" | '\"' | '`' | undefined;\n let escaped = false;\n for (let index = 0; index < source.length; index += 1) {\n const character = source[index];\n const next = source[index + 1];\n if (quote !== undefined) {\n output += character === '\\n' ? '\\n' : ' ';\n if (escaped) escaped = false;\n else if (character === '\\\\') escaped = true;\n else if (character === quote) quote = undefined;\n continue;\n }\n if (character === '\"' || character === \"'\" || character === '`') {\n quote = character;\n output += ' ';\n } else if (character === '/' && next === '/') {\n output += ' ';\n index += 2;\n while (index < source.length && source[index] !== '\\n') {\n output += ' ';\n index += 1;\n }\n if (index < source.length) output += '\\n';\n } else if (character === '/' && next === '*') {\n output += ' ';\n index += 2;\n while (index < source.length && !(source[index - 1] === '*' && source[index] === '/')) {\n output += source[index] === '\\n' ? '\\n' : ' ';\n index += 1;\n }\n } else output += character;\n }\n return output;\n}\n\nfunction storyLabel(source: string, clean: string, exportName: string): string | undefined {\n const escapedExport = exportName.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n const declaration = new RegExp(`\\\\bexport\\\\s+(?:const|let|var)\\\\s+${escapedExport}\\\\b[^=]*=\\\\s*\\\\{`, 'u');\n const match = clean.match(declaration);\n if (match === null || match.index === undefined) return undefined;\n const opening = clean.indexOf('{', match.index);\n let depth = 0;\n for (let index = opening; index < clean.length; index += 1) {\n if (clean[index] === '{') depth += 1;\n else if (clean[index] === '}') {\n depth -= 1;\n if (depth === 0) {\n const label = source\n .slice(opening, index)\n .match(/\\bname\\s*:\\s*(['\"])(.*?)\\1/u)?.[2]\n ?.trim();\n return label === '' ? undefined : label;\n }\n }\n }\n return undefined;\n}\n\n/** Extracts named CSF candidates without evaluating workspace source. */\nexport function extractStoryExports(source: string): readonly StoryPreviewExport[] {\n const names: string[] = [];\n const seen = new Set<string>();\n const add = (name: string): void => {\n if (name === 'default' || NON_STORY_EXPORTS.has(name) || seen.has(name)) return;\n seen.add(name);\n names.push(name);\n };\n const clean = stripComments(source);\n const declarations = /\\bexport\\s+(?:async\\s+)?(?:const|let|var|function|class)\\s+([A-Za-z_$][A-Za-z0-9_$]*)/gu;\n for (const match of clean.matchAll(declarations)) add(match[1]!);\n const lists = /\\bexport\\s*\\{([^}]*)\\}/gu;\n for (const match of clean.matchAll(lists)) {\n for (const item of match[1]!.split(',')) {\n const parts = item.trim().split(/\\s+as\\s+/u);\n const name = (parts.at(-1) ?? '').trim();\n if (/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(name)) add(name);\n }\n }\n return names.map((exportName) => {\n const label = storyLabel(source, clean, exportName);\n return label === undefined ? { exportName } : { exportName, label };\n });\n}\n\nasync function exists(filePath: string): Promise<boolean> {\n try {\n await fs.stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction relativeWorkspacePath(root: string, candidate: string): string {\n const relative = path.relative(root, candidate).split(path.sep).join('/');\n return relative === '' ? '.' : relative;\n}\n\nconst defaultDependencies: StoryPreviewServiceDependencies = {\n loadConfig: getAppDesignSystemConfig,\n createBundler(_config: DesignSystemConfig): BaseBundlerService {\n return createDefaultBundlerService();\n },\n createRenderer(config, appPath) {\n return new ComponentRendererService(config, appPath);\n },\n rendererTemporaryRoot: () => path.join(os.tmpdir(), 'style-system'),\n createHandle: randomUUID,\n};\n\nfunction pngCrc(data: Buffer): number {\n let crc = 0xffffffff;\n for (const byte of data) {\n crc ^= byte;\n for (let bit = 0; bit < 8; bit += 1) crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\nfunction pngDimensions(image: Buffer): { width: number; height: number } {\n if (image.length < PNG_SIGNATURE.length || !image.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) {\n throw new Error('Style-system returned an invalid PNG image');\n }\n let offset = PNG_SIGNATURE.length;\n let width = 0;\n let height = 0;\n let chunks = 0;\n let hasImageData = false;\n let hasEnd = false;\n while (offset < image.length) {\n if (image.length - offset < 12) throw new Error('Style-system returned an invalid PNG image');\n const length = image.readUInt32BE(offset);\n const end = offset + 12 + length;\n if (end > image.length) throw new Error('Style-system returned an invalid PNG image');\n const type = image.toString('ascii', offset + 4, offset + 8);\n if (!/^[A-Za-z]{4}$/u.test(type)) throw new Error('Style-system returned an invalid PNG image');\n if (image.readUInt32BE(end - 4) !== pngCrc(image.subarray(offset + 4, end - 4))) {\n throw new Error('Style-system returned an invalid PNG image');\n }\n if (chunks === 0) {\n if (type !== 'IHDR' || length !== 13) throw new Error('Style-system returned an invalid PNG image');\n width = image.readUInt32BE(offset + 8);\n height = image.readUInt32BE(offset + 12);\n } else if (type === 'IHDR') throw new Error('Style-system returned an invalid PNG image');\n if (type === 'IDAT') hasImageData = true;\n if (type === 'IEND') {\n if (length !== 0 || end !== image.length) throw new Error('Style-system returned an invalid PNG image');\n hasEnd = true;\n }\n chunks += 1;\n offset = end;\n }\n if (!hasImageData || !hasEnd) throw new Error('Style-system returned an invalid PNG image');\n if (width === 0 || height === 0 || width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION) {\n throw new Error('Style-system returned PNG dimensions outside the supported range');\n }\n return { width, height };\n}\n\n/** Owns disposable static story-preview artifacts for one trusted workspace. */\nexport class StoryPreviewService {\n private readonly root: string;\n private readonly dependencies: StoryPreviewServiceDependencies;\n private readonly artifacts = new Map<string, OwnedArtifact>();\n\n constructor(workspaceRoot: string, dependencies: Partial<StoryPreviewServiceDependencies> = {}) {\n this.root = path.resolve(workspaceRoot);\n this.dependencies = { ...defaultDependencies, ...dependencies };\n }\n\n async metadata(input: StoryPreviewMetadataRequest): Promise<StoryPreviewMetadataView> {\n const root = await fs.realpath(this.root);\n const storyPath = await this.resolveContainedPath(root, input.storyPath, 'storyPath');\n if (!STORY_FILE_PATTERN.test(storyPath))\n throw new Error('storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file');\n const project = await this.resolveProject(root, storyPath, input.appPath);\n const source = await fs.readFile(storyPath, 'utf8');\n return {\n storyPath: relativeWorkspacePath(root, storyPath),\n appPath: relativeWorkspacePath(root, project.path),\n projectResolution: project.resolution,\n exports: extractStoryExports(source),\n };\n }\n\n private async resolveProject(\n root: string,\n storyPath: string,\n requestedPath: string | undefined,\n ): Promise<{ path: string; resolution: StoryPreviewMetadataView['projectResolution'] }> {\n if (requestedPath !== undefined && requestedPath.trim() !== '') {\n return { path: await this.resolveContainedPath(root, requestedPath, 'appPath'), resolution: 'explicit' };\n }\n let directory = path.dirname(storyPath);\n let packagePath: string | undefined;\n while (isContained(root, directory)) {\n if (await exists(path.join(directory, 'style-system.config.yaml'))) {\n return { path: directory, resolution: 'config' };\n }\n if (packagePath === undefined && (await exists(path.join(directory, 'package.json')))) packagePath = directory;\n if (directory === root) break;\n directory = path.dirname(directory);\n }\n return packagePath === undefined\n ? { path: root, resolution: 'workspace' }\n : { path: packagePath, resolution: 'package' };\n }\n\n private async exactStory(root: string, storyPath: string, storyExport: string) {\n const source = await fs.readFile(storyPath, 'utf8');\n if (!extractStoryExports(source).some((entry) => entry.exportName === storyExport)) {\n throw new Error(`Story export \"${storyExport}\" was not found in ${relativeWorkspacePath(root, storyPath)}.`);\n }\n const index = new StoriesIndexService({ workspaceRoot: root, storyFiles: [storyPath], searchRoots: [] });\n await index.initialize();\n const component = index.getAllComponents().find((entry) => path.resolve(entry.filePath) === storyPath);\n if (component === undefined) throw new Error('The requested story file could not be indexed.');\n return component;\n }\n\n async build(input: StoryPreviewBuildInput): Promise<StoryPreviewBuildResult> {\n if (!STORY_EXPORT_PATTERN.test(input.storyExport)) {\n throw new Error('storyExport must be an exact JavaScript named export');\n }\n\n const root = await fs.realpath(this.root);\n const appPath = await this.resolveContainedPath(root, input.appPath, 'appPath');\n const storyPath = await this.resolveContainedPath(root, input.storyPath, 'storyPath');\n if (!STORY_FILE_PATTERN.test(storyPath))\n throw new Error('storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file');\n await this.exactStory(root, storyPath, input.storyExport);\n\n const [source, config] = await Promise.all([fs.readFile(storyPath, 'utf8'), this.dependencies.loadConfig(appPath)]);\n const bundler = this.dependencies.createBundler(config);\n let artifactDirectory: string | undefined;\n try {\n const rendered = await bundler.prerenderComponent({\n componentPath: storyPath,\n storyName: input.storyExport,\n args: input.args,\n darkMode: input.darkMode,\n appPath,\n themePath: config.themeProvider,\n cssFiles: config.cssFiles,\n rootComponent: config.rootComponent,\n unistylesConfig: config.unistylesConfig,\n });\n\n const htmlPath = await fs.realpath(rendered.htmlFilePath);\n const candidateDirectory = path.dirname(htmlPath);\n const temporaryRoot = path.join(appPath, '.tmp');\n if (candidateDirectory === temporaryRoot || !isContained(temporaryRoot, candidateDirectory)) {\n throw new Error('Style-system returned a preview artifact outside the project temporary directory');\n }\n artifactDirectory = candidateDirectory;\n\n const handle = this.dependencies.createHandle();\n const html = await fs.readFile(htmlPath, 'utf8');\n this.artifacts.set(handle, { directory: artifactDirectory });\n return {\n handle,\n html,\n storyPath: relativeWorkspacePath(root, storyPath),\n storyExport: input.storyExport,\n sourceSha256: createHash('sha256').update(source).digest('hex'),\n };\n } catch (reason) {\n if (artifactDirectory !== undefined) await fs.rm(artifactDirectory, { recursive: true, force: true });\n throw reason;\n }\n }\n\n /** Renders a fresh source-backed PNG. This does not preserve transient iframe interaction state. */\n async exportImage(input: StoryPreviewBuildInput): Promise<StoryPreviewImageResult> {\n if (!STORY_EXPORT_PATTERN.test(input.storyExport)) {\n throw new Error('storyExport must be an exact JavaScript named export');\n }\n const root = await fs.realpath(this.root);\n const appPath = await this.resolveContainedPath(root, input.appPath, 'appPath');\n const storyPath = await this.resolveContainedPath(root, input.storyPath, 'storyPath');\n if (!STORY_FILE_PATTERN.test(storyPath))\n throw new Error('storyPath must name a .stories.js, .stories.jsx, .stories.ts, or .stories.tsx file');\n\n const [source, config] = await Promise.all([fs.readFile(storyPath, 'utf8'), this.dependencies.loadConfig(appPath)]);\n const renderer = this.dependencies.createRenderer(config, appPath);\n let ownedImagePath: string | undefined;\n try {\n const component = await this.exactStory(root, storyPath, input.storyExport);\n const rendered = await renderer.renderComponent(component, {\n storyName: input.storyExport,\n darkMode: input.darkMode,\n });\n const [renderedImagePath, imageRoot] = await Promise.all([\n fs.realpath(rendered.imagePath),\n fs.realpath(this.dependencies.rendererTemporaryRoot()),\n ]);\n if (renderedImagePath === imageRoot || !isContained(imageRoot, renderedImagePath)) {\n throw new Error('Style-system returned an image artifact outside its temporary directory');\n }\n const imageStat = await fs.stat(renderedImagePath);\n if (!imageStat.isFile()) throw new Error('Style-system returned a non-regular PNG image');\n ownedImagePath = renderedImagePath;\n if (imageStat.size > MAX_IMAGE_BYTES) throw new Error('Style-system returned an oversized PNG image');\n const image = await fs.readFile(renderedImagePath);\n if (image.length !== imageStat.size) throw new Error('Style-system PNG changed while it was being read');\n const { width, height } = pngDimensions(image);\n return {\n data: image.toString('base64'),\n mimeType: 'image/png',\n captureId: this.dependencies.createHandle(),\n width,\n height,\n storyPath: relativeWorkspacePath(root, storyPath),\n storyExport: input.storyExport,\n sourceSha256: createHash('sha256').update(source).digest('hex'),\n };\n } finally {\n try {\n if (ownedImagePath !== undefined) await fs.rm(ownedImagePath, { force: true });\n } finally {\n await renderer.dispose();\n }\n }\n }\n\n async dispose(handle: string): Promise<boolean> {\n const artifact = this.artifacts.get(handle);\n if (artifact === undefined) return false;\n this.artifacts.delete(handle);\n await fs.rm(artifact.directory, { recursive: true, force: true });\n return true;\n }\n\n async disposeAll(): Promise<void> {\n await Promise.all([...this.artifacts.keys()].map((handle) => this.dispose(handle)));\n }\n\n private async resolveContainedPath(root: string, inputPath: string, field: string): Promise<string> {\n if (inputPath.trim() === '') throw new Error(`${field} is required`);\n const candidate = path.isAbsolute(inputPath) ? inputPath : path.resolve(root, inputPath);\n const canonical = await fs.realpath(candidate);\n if (!isContained(root, canonical)) throw new Error(`${field} must remain inside the workspace root`);\n return canonical;\n }\n}\n\nexport type {\n StoryPreviewBuildInput,\n StoryP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,UAAU,OAAO,MAAM;EAC5B,MAAMA,SAAG,GAAG,SAAS,WAAW;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EAChE,OAAO;CACT;CAEA,MAAM,aAA4B;EAChC,MAAM,QAAQ,IAAI,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC,CAAC,CAAC,KAAK,WAAW,KAAK,QAAQ,MAAM,CAAC,CAAC;CACpF;CAEA,MAAc,qBAAqB,MAAc,WAAmB,OAAgC;EAClG,IAAI,UAAU,KAAK,MAAM,IAAI,MAAM,IAAI,MAAM,GAAG,MAAM,aAAa;EACnE,MAAM,YAAY,KAAK,WAAW,SAAS,IAAI,YAAY,KAAK,QAAQ,MAAM,SAAS;EACvF,MAAM,YAAY,MAAMA,SAAG,SAAS,SAAS;EAC7C,IAAI,CAAC,YAAY,MAAM,SAAS,GAAG,MAAM,IAAI,MAAM,GAAG,MAAM,uCAAuC;EACnG,OAAO;CACT;AACF"}
package/package.json ADDED
@@ -0,0 +1,132 @@
1
+ {
2
+ "name": "@agimon-ai/doompi-style-system",
3
+ "version": "0.0.1-alpha.100",
4
+ "description": "Optional DoomPi story preview integration for the style-system package.",
5
+ "keywords": [
6
+ "ai",
7
+ "coding-agent",
8
+ "developer-tools",
9
+ "doompi",
10
+ "pi-package",
11
+ "storybook",
12
+ "style-system",
13
+ "ui-preview"
14
+ ],
15
+ "homepage": "https://agimon.ai",
16
+ "bugs": {
17
+ "url": "https://github.com/AgiFlow/doompi/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Vuong Ngo",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/AgiFlow/doompi.git",
24
+ "directory": "layers/design/doompi-style-system"
25
+ },
26
+ "bin": {
27
+ "doompi-style-system": "./dist/cli.mjs"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "skills",
32
+ "README.md"
33
+ ],
34
+ "type": "module",
35
+ "main": "./dist/index.cjs",
36
+ "module": "./dist/index.mjs",
37
+ "types": "./dist/index.d.mts",
38
+ "jsnext:main": "./dist/index.mjs",
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.mts",
42
+ "import": "./dist/index.mjs",
43
+ "require": "./dist/index.cjs"
44
+ },
45
+ "./cli": {
46
+ "types": "./dist/cli.d.mts",
47
+ "import": "./dist/cli.mjs",
48
+ "require": "./dist/cli.cjs"
49
+ },
50
+ "./extensions/pi": {
51
+ "types": "./dist/extensions/pi.d.mts",
52
+ "import": "./dist/extensions/pi.mjs",
53
+ "require": "./dist/extensions/pi.cjs"
54
+ },
55
+ "./extensions/server": {
56
+ "types": "./dist/extensions/server.d.mts",
57
+ "import": "./dist/extensions/server.mjs",
58
+ "require": "./dist/extensions/server.cjs"
59
+ },
60
+ "./extensions/web": {
61
+ "import": "./dist/extensions/web.mjs"
62
+ },
63
+ "./skills/design-workflow/SKILL.md": "./skills/design-workflow/SKILL.md",
64
+ "./package.json": "./package.json"
65
+ },
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "dependencies": {
70
+ "@agimon-ai/doompi-core": "0.0.1-alpha.99",
71
+ "@agimon-ai/doompi-web-components": "0.0.1-alpha.57",
72
+ "@agimon-ai/doompi-web-security": "0.0.1-alpha.52",
73
+ "@agimon-ai/style-system": "0.1.13",
74
+ "hono": "4.13.8",
75
+ "typebox": "1.3.34"
76
+ },
77
+ "devDependencies": {
78
+ "@agimon-ai/doompi-build": "0.0.1-alpha.21",
79
+ "@earendil-works/pi-coding-agent": "0.99.1",
80
+ "@types/node": "26.6.2",
81
+ "@types/react": "19.3.0",
82
+ "@types/react-dom": "19.3.0",
83
+ "@vitest/coverage-v8": "5.0.1",
84
+ "react": "19.3.0",
85
+ "react-dom": "19.3.0",
86
+ "tsdown": "0.23.0",
87
+ "typescript": "7.0.2",
88
+ "vitest": "5.0.1"
89
+ },
90
+ "peerDependencies": {
91
+ "@earendil-works/pi-coding-agent": "0.99.1"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "@earendil-works/pi-coding-agent": {
95
+ "optional": true
96
+ }
97
+ },
98
+ "engines": {
99
+ "node": ">=22.19.0"
100
+ },
101
+ "doompiServer": {
102
+ "entry": "./generated/server.ts",
103
+ "dist": "./dist/extensions/server.mjs",
104
+ "scopes": [
105
+ "session"
106
+ ],
107
+ "contracts": {
108
+ "entry": "./src/exports/apiContracts.ts",
109
+ "dist": "./dist/apiContracts.mjs"
110
+ }
111
+ },
112
+ "doompiWeb": {
113
+ "pluginId": "style-system",
114
+ "channels": [],
115
+ "client": "./dist/extensions/web.mjs",
116
+ "scopes": [
117
+ "session"
118
+ ]
119
+ },
120
+ "pi": {
121
+ "extensions": [
122
+ "./dist/extensions/pi.mjs"
123
+ ]
124
+ },
125
+ "scripts": {
126
+ "build": "tsdown",
127
+ "test": "vitest --run",
128
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.web.json",
129
+ "lint": "oxlint . && oxfmt . --check",
130
+ "fixcode": "oxlint . --fix && oxfmt ."
131
+ }
132
+ }
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: design-workflow
3
+ description: Use the DoomPi design workflow for source-backed interactive story design, component discovery, token guidance, validation, and an approved implementation specification.
4
+ ---
5
+
6
+ # Source-backed design workflow
7
+
8
+ Use this workflow when a feature needs an interactive UI target before production integration. The story is a target-state artifact, not a throwaway HTML mockup. Keep the target deterministic and source-backed so it can be reviewed and later connected to real APIs, hooks, stores, and routes.
9
+
10
+ ## Keep context lean
11
+
12
+ Do not paste an entire component catalog, token list, or design-system manual into the conversation. Discover only what the current surface needs:
13
+
14
+ ```bash
15
+ doompi-design list-shared-components
16
+ doompi-design list-app-components --app-path <project>
17
+ doompi-design get-css-classes --app-path <project> --category all
18
+ doompi-design list-themes --app-path <project>
19
+ ```
20
+
21
+ If `doompi-design` is unavailable, use the published `@agimon-ai/style-system` CLI with the same commands. The workflow is portable and does not require Pi, DoomPi, Author, or MCP.
22
+
23
+ Use repository source as the authority for principles and managed tokens. In this repository, begin with:
24
+
25
+ - `packages/core/doompi-web-components/README.md`
26
+ - `packages/core/doompi-web-components/styles/tokens.css`
27
+ - the applicable project `style-system.config.yaml`
28
+ - applicable Vibe-Lint rule descriptions
29
+
30
+ The catalog is story-backed and may not include every exported component. Unknown components are unresolved, not proof that no component exists.
31
+
32
+ ## Design
33
+
34
+ 1. Identify the project, user journey, states, interactions, permissions, and responsive constraints.
35
+ 2. Inspect and reuse an existing shared or application component before creating one.
36
+ 3. Define deterministic fixtures for loading, empty, error, populated, and interaction states.
37
+ 4. Build a Storybook story for a presentational View. Keep API hooks, stores, router calls, SDK calls, and side effects in a Container outside the story.
38
+ 5. Use the configured semantic tokens and primitives. Do not invent raw palette values or arbitrary scale values to make a screenshot look right.
39
+ 6. Build the interactive preview explicitly and inspect the actual interaction states. Generated HTML is a disposable artifact.
40
+ 7. Edit the underlying story or component source, never generated preview HTML.
41
+
42
+ Rendering and component capture execute trusted workspace source. Do not run a file-polishing or mutating design command during review unless the user explicitly asks for that edit.
43
+
44
+ ## Check
45
+
46
+ Run the explicit bounded check for the target after the story and relevant styles change:
47
+
48
+ ```bash
49
+ doompi-design check --target <target-manifest.json>
50
+ ```
51
+
52
+ The check is static and bounded. It reports separately:
53
+
54
+ - confirmed policy violations, such as raw theme colors or arbitrary scale values;
55
+ - recognized static classes and managed tokens;
56
+ - unresolved dynamic expressions, custom selectors, missing imports, or unsupported configuration;
57
+ - checked inputs, coverage limits, tool versions, and fingerprints.
58
+
59
+ A Tailwind class being recognized does not make it compliant. A missing generated class does not by itself make a class invalid because marker classes and ordinary custom CSS may be valid. Dynamic expressions and incomplete CSS context must not be reported as clean.
60
+
61
+ Resolve all required findings. A successful build, typecheck, or image render is not a design-compliance result.
62
+
63
+ ## Approval and specification
64
+
65
+ After checks pass, inspect the preview and ask the user to explicitly approve the exact target snapshot, including story/export, fixtures, rendering options, and evidence revision. Do not infer approval from agent prose or a model-written field.
66
+
67
+ Only after explicit target approval, inspect the current implementation and write a repository Markdown bridge specification. Reuse the repository's existing Plan review and acceptance conventions when available. The spec should map each approved target component, state, action, and route to:
68
+
69
+ - current API, hook, store, and route source references;
70
+ - reused, adapted, or new components;
71
+ - data and permission contracts;
72
+ - loading, empty, error, and responsive behavior;
73
+ - mock-to-production integration work;
74
+ - executable acceptance checks, sequence, non-goals, and unresolved decisions.
75
+
76
+ Store the target and evidence with the project, for example:
77
+
78
+ ```text
79
+ docs/specs/<feature>/target.md
80
+ docs/specs/<feature>/design-check.json
81
+ docs/specs/<feature>/spec.md
82
+ ```
83
+
84
+ The target approval does not authorize implementation. Request separate implementation approval.