@agimon-ai/style-system 0.1.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.
package/dist/cli.mjs ADDED
@@ -0,0 +1,393 @@
1
+ #!/usr/bin/env node
2
+ import { F as log, M as DEFAULT_STYLE_SYSTEM_CONFIG, N as TailwindCSSClassesService, O as resolveStyleSystemThemePath, S as getAppDesignSystemConfig, a as STYLE_SYSTEM_CLI_NAME, i as createServer, k as STYLE_SYSTEM_TYPES, o as STYLE_SYSTEM_VERSION, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler, y as getBundlerServiceFromConfig } from "./stdio-Bh4OBwmR.mjs";
3
+ import { promises } from "node:fs";
4
+ import path from "node:path";
5
+ import { registerManagedProcess } from "@agimon-ai/foundation-exec";
6
+ import "reflect-metadata";
7
+ import { Command } from "commander";
8
+ import * as chalkImport from "chalk";
9
+ //#region src/utils/print.ts
10
+ function resolveChalk(value, depth = 0) {
11
+ if (value && (typeof value === "object" || typeof value === "function") && "red" in value && typeof value.red === "function") return value;
12
+ if (depth < 3 && value && (typeof value === "object" || typeof value === "function") && "default" in value) return resolveChalk(value.default, depth + 1);
13
+ throw new Error("Unable to resolve chalk instance");
14
+ }
15
+ const chalk = resolveChalk(chalkImport);
16
+ const print = {
17
+ info: (message) => {
18
+ console.log(chalk.cyan(message));
19
+ },
20
+ success: (message) => {
21
+ console.log(chalk.green(message));
22
+ },
23
+ warning: (message) => {
24
+ console.log(chalk.yellow(message));
25
+ },
26
+ error: (message, error) => {
27
+ if (error) {
28
+ const errorMsg = error instanceof Error ? error.message : error;
29
+ console.error(chalk.red(message), errorMsg);
30
+ } else console.error(chalk.red(message));
31
+ },
32
+ debug: (message) => {
33
+ console.log(chalk.gray(message));
34
+ },
35
+ header: (message) => {
36
+ console.log(chalk.bold.cyan(message));
37
+ },
38
+ item: (message) => {
39
+ console.log(chalk.white(` - ${message}`));
40
+ },
41
+ indent: (message) => {
42
+ console.log(chalk.white(` ${message}`));
43
+ },
44
+ highlight: (message) => {
45
+ console.log(chalk.bold.green(message));
46
+ },
47
+ newline: () => {
48
+ console.log();
49
+ },
50
+ divider: () => {
51
+ console.log(chalk.gray(".".repeat(60)));
52
+ }
53
+ };
54
+ //#endregion
55
+ //#region src/commands/generate-oxlint-config.ts
56
+ /**
57
+ * Generate Oxlint Config Command
58
+ *
59
+ * DESIGN PATTERNS:
60
+ * - Command pattern with Commander for CLI argument parsing
61
+ * - Async/await pattern for asynchronous operations
62
+ * - Error handling pattern with try-catch and proper exit codes
63
+ *
64
+ * CODING STANDARDS:
65
+ * - Use async action handlers for asynchronous operations
66
+ * - Provide clear option descriptions and default values
67
+ * - Handle errors gracefully with process.exit()
68
+ * - Log progress and errors to console
69
+ * - Use Commander's .option() and .argument() for inputs
70
+ *
71
+ * AVOID:
72
+ * - Synchronous blocking operations in action handlers
73
+ * - Missing error handling (always use try-catch)
74
+ * - Hardcoded values (use options or environment variables)
75
+ * - Not exiting with appropriate exit codes on errors
76
+ */
77
+ /**
78
+ * Generate oxlint no-restricted-classes config from theme CSS design tokens
79
+ */
80
+ const generateOxlintConfigCommand = new Command("generate-oxlint-config").description("Generate oxlint no-restricted-classes config from theme CSS design tokens").option("-a, --app-path <path>", "App path to read theme path from its style-system.config.yaml").option("-t, --theme-path <path>", "Theme CSS file path relative to workspace root").option("-o, --output <path>", "Output file path (defaults to stdout)").action(async (options) => {
81
+ try {
82
+ const themePath = (options.appPath ? (await getAppDesignSystemConfig(options.appPath)).themePath : void 0) ?? options.themePath;
83
+ if (!themePath) throw new Error("No theme CSS path resolved. Pass --theme-path, or pass --app-path for an app that configures themePath.");
84
+ const resolvedThemePath = await resolveStyleSystemThemePath({
85
+ appPath: options.appPath ?? null,
86
+ themePath
87
+ });
88
+ const cssResult = await new TailwindCSSClassesService(DEFAULT_STYLE_SYSTEM_CONFIG).extractClasses("colors", resolvedThemePath);
89
+ const config = generateRestrictedClassesConfig(cssResult);
90
+ const jsonOutput = JSON.stringify(config, null, 2);
91
+ if (options.output) {
92
+ const outputPath = path.resolve(options.output);
93
+ await promises.writeFile(outputPath, `${jsonOutput}\n`, "utf-8");
94
+ print.success(`Config written to ${outputPath}`);
95
+ } else print.info(jsonOutput);
96
+ } catch (error) {
97
+ print.error("Error generating oxlint config:", error instanceof Error ? error.message : String(error));
98
+ process.exit(1);
99
+ }
100
+ });
101
+ //#endregion
102
+ //#region src/commands/get-css-classes.ts
103
+ /**
104
+ * Get CSS Classes CLI Command
105
+ */
106
+ const getCSSClassesCommand = new Command("get-css-classes").description("Extract and return all valid CSS classes from a theme CSS file").option("-c, --category <category>", "Category filter: 'colors', 'typography', 'spacing', 'effects', 'all'", "all").option("-a, --app-path <path>", "App path to read theme path from style-system.config.yaml (e.g., \"apps/agiflow-app\")").option("-t, --theme-path <path>", "Theme CSS file path relative to workspace root (required unless appPath resolves themePath from style-system.config.yaml)").action(async (options) => {
107
+ try {
108
+ const result = await createContainer({ defaultThemePath: options.themePath }).get(STYLE_SYSTEM_TYPES.GetCSSClassesTool).execute({
109
+ category: options.category,
110
+ appPath: options.appPath
111
+ });
112
+ if (result.isError) {
113
+ const firstContent = result.content[0];
114
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
115
+ throw new Error(errorText);
116
+ }
117
+ const firstContent = result.content[0];
118
+ print.info(firstContent?.type === "text" ? firstContent.text : "");
119
+ } catch (error) {
120
+ print.error("Error getting CSS classes:", error instanceof Error ? error.message : String(error));
121
+ process.exit(1);
122
+ }
123
+ });
124
+ //#endregion
125
+ //#region src/commands/get-ui-component.ts
126
+ /**
127
+ * Get UI Component CLI Command
128
+ */
129
+ const LIGHT_COLOR_SCHEME = "light";
130
+ const DARK_COLOR_SCHEME = "dark";
131
+ const REQUESTABLE_COLOR_SCHEMES = [LIGHT_COLOR_SCHEME, DARK_COLOR_SCHEME];
132
+ const getUiComponentCommand = new Command("get-ui-component").description("Get a screenshot of a UI component rendered with app-specific design system configuration. Returns screenshot path and story file content.").requiredOption("-c, --component-name <name>", "The name of the component to capture (e.g., \"Button\", \"Card\")").requiredOption("-a, --app-path <path>", "The app path (relative or absolute) to load design system config from (e.g., \"apps/agiflow-app\")").option("-s, --story-name <name>", "The story name to render (e.g., \"Playground\", \"Default\")", "Playground").option("-d, --dark-mode", "Request dark mode for automatic-theme apps").option("--color-scheme <scheme>", "Request light or dark mode for automatic-theme apps").option("--width <pixels>", "Override the configured viewport width", Number).option("--height <pixels>", "Override the configured viewport height", Number).action(async (options) => {
133
+ try {
134
+ if (options.colorScheme !== void 0 && !REQUESTABLE_COLOR_SCHEMES.includes(options.colorScheme)) throw new Error("--color-scheme must be light or dark");
135
+ const tool = createContainer().get(STYLE_SYSTEM_TYPES.GetComponentVisualTool);
136
+ const darkMode = options.colorScheme === DARK_COLOR_SCHEME ? true : options.colorScheme === LIGHT_COLOR_SCHEME ? false : options.darkMode || void 0;
137
+ const result = await tool.execute({
138
+ componentName: options.componentName,
139
+ appPath: options.appPath,
140
+ storyName: options.storyName,
141
+ darkMode,
142
+ width: options.width,
143
+ height: options.height
144
+ });
145
+ if (result.isError) {
146
+ const firstContent = result.content[0];
147
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
148
+ throw new Error(errorText);
149
+ }
150
+ const firstContent = result.content[0];
151
+ process.stdout.write(`${firstContent?.type === "text" ? firstContent.text : ""}\n`);
152
+ } catch (error) {
153
+ const errorMessage = error instanceof Error ? error.message : String(error);
154
+ log.error("Error:", errorMessage);
155
+ process.stderr.write(`${errorMessage.startsWith("Error:") ? errorMessage : `Error: ${errorMessage}`}\n`);
156
+ process.exitCode = 1;
157
+ }
158
+ });
159
+ //#endregion
160
+ //#region src/commands/list-app-components.ts
161
+ /**
162
+ * List App Components CLI Command
163
+ */
164
+ const listAppComponentsCommand = new Command("list-app-components").description("List app-specific components and package components. Reads the app's package.json to find workspace dependencies.").requiredOption("-a, --app-path <path>", "The app path (relative or absolute) to list components for (e.g., \"apps/agiflow-app\")").option("-c, --cursor <cursor>", "Pagination cursor to fetch the next page").action(async (options) => {
165
+ try {
166
+ const result = await createContainer().get(STYLE_SYSTEM_TYPES.ListAppComponentsTool).execute({
167
+ appPath: options.appPath,
168
+ cursor: options.cursor
169
+ });
170
+ if (result.isError) {
171
+ const firstContent = result.content[0];
172
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
173
+ throw new Error(errorText);
174
+ }
175
+ const firstContent = result.content[0];
176
+ print.info(firstContent?.type === "text" ? firstContent.text : "");
177
+ } catch (error) {
178
+ print.error("Error:", error instanceof Error ? error.message : String(error));
179
+ process.exit(1);
180
+ }
181
+ });
182
+ //#endregion
183
+ //#region src/commands/list-themes.ts
184
+ /**
185
+ * List Themes Command
186
+ *
187
+ * DESIGN PATTERNS:
188
+ * - Command pattern with Commander for CLI argument parsing
189
+ * - Async/await pattern for asynchronous operations
190
+ * - Error handling pattern with try-catch and proper exit codes
191
+ *
192
+ * CODING STANDARDS:
193
+ * - Use async action handlers for asynchronous operations
194
+ * - Provide clear option descriptions and default values
195
+ * - Handle errors gracefully with process.exit()
196
+ * - Log progress and errors to console
197
+ * - Use Commander's .option() and .argument() for inputs
198
+ *
199
+ * AVOID:
200
+ * - Synchronous blocking operations in action handlers
201
+ * - Missing error handling (always use try-catch)
202
+ * - Hardcoded values (use options or environment variables)
203
+ * - Not exiting with appropriate exit codes on errors
204
+ */
205
+ /**
206
+ * List all available theme configurations from CSS files
207
+ */
208
+ const listThemesCommand = new Command("list-themes").description("List all available theme configurations from CSS files configured in style-system.config.yaml").option("-a, --app-path <path>", "App path to read theme config from style-system.config.yaml (e.g., \"apps/my-app\")").action(async (options) => {
209
+ try {
210
+ const result = await createContainer().get(STYLE_SYSTEM_TYPES.ListThemesTool).execute({ appPath: options.appPath });
211
+ if (result.isError) {
212
+ const firstContent = result.content[0];
213
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
214
+ throw new Error(errorText);
215
+ }
216
+ const firstContent = result.content[0];
217
+ print.info(firstContent?.type === "text" ? firstContent.text : "");
218
+ } catch (error) {
219
+ print.error("Error listing themes:", error instanceof Error ? error.message : String(error));
220
+ process.exit(1);
221
+ }
222
+ });
223
+ //#endregion
224
+ //#region src/commands/list-shared-components.ts
225
+ /**
226
+ * List Shared Components CLI Command
227
+ */
228
+ const listSharedComponentsCommand = new Command("list-shared-components").description("List all shared UI components available in the design system").option("-c, --cursor <cursor>", "Pagination cursor to fetch the next page").action(async (options) => {
229
+ try {
230
+ const result = await createContainer().get(STYLE_SYSTEM_TYPES.ListSharedComponentsTool).execute({ cursor: options.cursor });
231
+ if (result.isError) {
232
+ const firstContent = result.content[0];
233
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
234
+ throw new Error(errorText);
235
+ }
236
+ const firstContent = result.content[0];
237
+ print.info(firstContent?.type === "text" ? firstContent.text : "");
238
+ } catch (error) {
239
+ print.error("Error listing shared components:", error instanceof Error ? error.message : String(error));
240
+ process.exit(1);
241
+ }
242
+ });
243
+ //#endregion
244
+ //#region src/commands/mcp-serve.ts
245
+ /**
246
+ * MCP Serve Command
247
+ *
248
+ * DESIGN PATTERNS:
249
+ * - Command pattern with Commander for CLI argument parsing
250
+ * - Transport abstraction pattern for flexible deployment (stdio, HTTP, SSE)
251
+ * - Factory pattern for creating transport handlers
252
+ * - Graceful shutdown pattern with signal handling
253
+ *
254
+ * CODING STANDARDS:
255
+ * - Use async/await for asynchronous operations
256
+ * - Implement proper error handling with try-catch blocks
257
+ * - Handle process signals for graceful shutdown
258
+ * - Provide clear CLI options and help messages
259
+ *
260
+ * AVOID:
261
+ * - Hardcoded configuration values (use CLI options or environment variables)
262
+ * - Missing error handling for transport startup
263
+ * - Not cleaning up resources on shutdown
264
+ */
265
+ /**
266
+ * Start MCP server with given transport handler
267
+ */
268
+ async function startServer(handler, bundlerService, devServerPort) {
269
+ await handler.start();
270
+ let releaseProcess = async () => {};
271
+ try {
272
+ releaseProcess = await registerManagedProcess({
273
+ repositoryPath: process.cwd(),
274
+ serviceName: "style-system-mcp",
275
+ serviceType: "tool",
276
+ environment: process.env["NODE_ENV"] ?? "development",
277
+ pid: process.pid,
278
+ port: devServerPort,
279
+ command: "style-system mcp-serve",
280
+ killOnRelease: true,
281
+ releasePortOnRelease: false,
282
+ metadata: devServerPort ? { devServerPort } : {}
283
+ });
284
+ } catch {}
285
+ const shutdown = async (signal) => {
286
+ console.error(`\nReceived ${signal}, shutting down gracefully...`);
287
+ try {
288
+ if (bundlerService.isServerRunning()) {
289
+ console.error("Stopping bundler dev server...");
290
+ await bundlerService.cleanup();
291
+ }
292
+ await releaseProcess();
293
+ await handler.stop();
294
+ process.exit(0);
295
+ } catch (error) {
296
+ console.error("Error during shutdown:", error);
297
+ process.exit(1);
298
+ }
299
+ };
300
+ process.on("SIGINT", () => shutdown("SIGINT"));
301
+ process.on("SIGTERM", () => shutdown("SIGTERM"));
302
+ }
303
+ /**
304
+ * MCP Serve command
305
+ *
306
+ * Note: Design system configuration is now app-specific and read from each app's project.json.
307
+ * No global theme configuration is needed at the server level.
308
+ */
309
+ const mcpServeCommand = new Command("mcp-serve").description("Start MCP server with specified transport").option("-t, --type <type>", "Transport type: stdio", "stdio").option("--theme-path <path>", "Theme CSS file path relative to workspace root for get-css-classes when app config does not define style-system.themePath").option("--dev", "Start Vite dev server for component hot reload and caching").option("--app-path <path>", "App path for dev server (e.g., apps/agiflow-app)").action(async (options) => {
310
+ try {
311
+ const transportType = options.type.toLowerCase();
312
+ let devServerPort;
313
+ const bundlerService = await getBundlerServiceFromConfig();
314
+ if (options.dev) {
315
+ if (!options.appPath) {
316
+ console.error("Error: --app-path is required when using --dev flag");
317
+ console.error(`Example: ${STYLE_SYSTEM_CLI_NAME} mcp-serve --dev --app-path apps/agiflow-app`);
318
+ process.exit(1);
319
+ }
320
+ const { url, port } = await bundlerService.startDevServer(options.appPath);
321
+ devServerPort = port;
322
+ console.error(`Dev server started at ${url} (port: ${port})`);
323
+ }
324
+ if (transportType === "stdio") {
325
+ const container = createContainer({ defaultThemePath: options.themePath });
326
+ const server = createServer(container);
327
+ await startServer(new StdioTransportHandler(server), bundlerService, devServerPort);
328
+ } else {
329
+ console.error(`Unknown transport type: ${transportType}. Use: stdio`);
330
+ process.exit(1);
331
+ }
332
+ } catch (error) {
333
+ console.error("Failed to start MCP server:", error);
334
+ process.exit(1);
335
+ }
336
+ });
337
+ //#endregion
338
+ //#region src/commands/polish-component.ts
339
+ /**
340
+ * Polish Component Command
341
+ *
342
+ * DESIGN PATTERNS:
343
+ * - Command pattern with Commander for CLI argument parsing
344
+ * - Async/await pattern for asynchronous operations
345
+ * - Error handling pattern with try-catch and proper exit codes
346
+ *
347
+ * CODING STANDARDS:
348
+ * - Use async action handlers for asynchronous operations
349
+ * - Handle errors gracefully with process.exit()
350
+ *
351
+ * AVOID:
352
+ * - Synchronous blocking operations in action handlers
353
+ * - Missing error handling (always use try-catch)
354
+ * - Hardcoded values (use options or environment variables)
355
+ */
356
+ const polishComponentCommand = new Command("polish-component").description("Polish a UI component using Antigravity with design system context").argument("<file>", "Path to the component .tsx file to polish").option("-i, --instructions <text>", "Specific polishing instructions (e.g., \"improve spacing\")").action(async (file, options) => {
357
+ try {
358
+ const result = await createContainer().get(STYLE_SYSTEM_TYPES.PolishComponentTool).execute({
359
+ filePath: file,
360
+ instructions: options.instructions
361
+ });
362
+ if (result.isError) {
363
+ const firstContent = result.content[0];
364
+ const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
365
+ throw new Error(errorText);
366
+ }
367
+ for (const content of result.content) if (content.type === "text") console.error(content.text);
368
+ } catch (error) {
369
+ console.error("Error:", error instanceof Error ? error.message : String(error));
370
+ process.exit(1);
371
+ }
372
+ });
373
+ //#endregion
374
+ //#region src/cli.ts
375
+ /**
376
+ * Main entry point
377
+ */
378
+ async function main() {
379
+ const program = new Command();
380
+ program.name(STYLE_SYSTEM_CLI_NAME).description("MCP server for design system tools").version(STYLE_SYSTEM_VERSION);
381
+ program.addCommand(generateOxlintConfigCommand);
382
+ program.addCommand(getCSSClassesCommand);
383
+ program.addCommand(getUiComponentCommand);
384
+ program.addCommand(listAppComponentsCommand);
385
+ program.addCommand(listThemesCommand);
386
+ program.addCommand(listSharedComponentsCommand);
387
+ program.addCommand(mcpServeCommand);
388
+ program.addCommand(polishComponentCommand);
389
+ await program.parseAsync(process.argv);
390
+ }
391
+ main();
392
+ //#endregion
393
+ export {};
package/dist/index.cjs ADDED
@@ -0,0 +1,84 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_stdio = require("./stdio-D8AH3sRD.cjs");
3
+ exports.BaseBundlerService = require_stdio.BaseBundlerService;
4
+ exports.BaseCSSClassesService = require_stdio.BaseCSSClassesService;
5
+ Object.defineProperty(exports, "CSSClassesServiceFactory", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return require_stdio.CSSClassesServiceFactory;
9
+ }
10
+ });
11
+ exports.ComponentRendererService = require_stdio.ComponentRendererService;
12
+ exports.DEFAULT_STYLE_SYSTEM_CONFIG = require_stdio.DEFAULT_STYLE_SYSTEM_CONFIG;
13
+ Object.defineProperty(exports, "GetCSSClassesTool", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return require_stdio.GetCSSClassesTool;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "GetComponentVisualTool", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return require_stdio.GetComponentVisualTool;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "GetUiComponentService", {
26
+ enumerable: true,
27
+ get: function() {
28
+ return require_stdio.GetUiComponentService;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "ListAppComponentsTool", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return require_stdio.ListAppComponentsTool;
35
+ }
36
+ });
37
+ Object.defineProperty(exports, "ListSharedComponentsTool", {
38
+ enumerable: true,
39
+ get: function() {
40
+ return require_stdio.ListSharedComponentsTool;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, "ListThemesTool", {
44
+ enumerable: true,
45
+ get: function() {
46
+ return require_stdio.ListThemesTool;
47
+ }
48
+ });
49
+ Object.defineProperty(exports, "PolishComponentTool", {
50
+ enumerable: true,
51
+ get: function() {
52
+ return require_stdio.PolishComponentTool;
53
+ }
54
+ });
55
+ exports.STYLE_SYSTEM_TYPES = require_stdio.STYLE_SYSTEM_TYPES;
56
+ exports.StdioTransportHandler = require_stdio.StdioTransportHandler;
57
+ Object.defineProperty(exports, "StoriesIndexService", {
58
+ enumerable: true,
59
+ get: function() {
60
+ return require_stdio.StoriesIndexService;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, "StyleSystemConfigLoader", {
64
+ enumerable: true,
65
+ get: function() {
66
+ return require_stdio.StyleSystemConfigLoader;
67
+ }
68
+ });
69
+ exports.TailwindCSSClassesService = require_stdio.TailwindCSSClassesService;
70
+ exports.ThemeService = require_stdio.ThemeService;
71
+ exports.ViteReactBundlerService = require_stdio.ViteReactBundlerService;
72
+ exports.createContainer = require_stdio.createContainer;
73
+ exports.createDefaultBundlerService = require_stdio.createDefaultBundlerService;
74
+ exports.createServer = require_stdio.createServer;
75
+ exports.createStyleSystemModule = require_stdio.createStyleSystemModule;
76
+ exports.extractCustomTokenNames = require_stdio.extractCustomTokenNames;
77
+ exports.generateRestrictedClassesConfig = require_stdio.generateRestrictedClassesConfig;
78
+ exports.getAppDesignSystemConfig = require_stdio.getAppDesignSystemConfig;
79
+ exports.getBundlerServiceFromConfig = require_stdio.getBundlerServiceFromConfig;
80
+ exports.getSharedComponentTags = require_stdio.getSharedComponentTags;
81
+ exports.hasStyleSystemProjectConfig = require_stdio.hasStyleSystemProjectConfig;
82
+ exports.resetStyleSystemConfigCache = require_stdio.resetStyleSystemConfigCache;
83
+ exports.resolveAppDesignSystemConfig = require_stdio.resolveAppDesignSystemConfig;
84
+ exports.resolveStyleSystemThemePath = require_stdio.resolveStyleSystemThemePath;