@agiflowai/style-system 0.0.12 → 0.1.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.
@@ -1,4 +1,4 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,43 +19,37 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
-
23
22
  //#endregion
24
- let __modelcontextprotocol_sdk_server_index_js = require("@modelcontextprotocol/sdk/server/index.js");
25
- __modelcontextprotocol_sdk_server_index_js = __toESM(__modelcontextprotocol_sdk_server_index_js);
26
- let __modelcontextprotocol_sdk_types_js = require("@modelcontextprotocol/sdk/types.js");
27
- __modelcontextprotocol_sdk_types_js = __toESM(__modelcontextprotocol_sdk_types_js);
23
+ let _modelcontextprotocol_sdk_server_index_js = require("@modelcontextprotocol/sdk/server/index.js");
24
+ let _modelcontextprotocol_sdk_types_js = require("@modelcontextprotocol/sdk/types.js");
28
25
  let node_path = require("node:path");
29
- node_path = __toESM(node_path);
30
- let __agiflowai_aicode_utils = require("@agiflowai/aicode-utils");
31
- __agiflowai_aicode_utils = __toESM(__agiflowai_aicode_utils);
26
+ node_path = __toESM(node_path, 1);
27
+ let _agiflowai_aicode_utils = require("@agiflowai/aicode-utils");
32
28
  let node_fs = require("node:fs");
33
- node_fs = __toESM(node_fs);
34
29
  let js_yaml = require("js-yaml");
35
- js_yaml = __toESM(js_yaml);
30
+ js_yaml = __toESM(js_yaml, 1);
36
31
  let postcss = require("postcss");
37
- postcss = __toESM(postcss);
32
+ postcss = __toESM(postcss, 1);
38
33
  let glob = require("glob");
39
- glob = __toESM(glob);
40
34
  let node_crypto = require("node:crypto");
41
- node_crypto = __toESM(node_crypto);
42
- let __storybook_csf_tools = require("@storybook/csf-tools");
43
- __storybook_csf_tools = __toESM(__storybook_csf_tools);
44
- let __tailwindcss_vite = require("@tailwindcss/vite");
45
- __tailwindcss_vite = __toESM(__tailwindcss_vite);
35
+ let _storybook_csf_tools = require("@storybook/csf-tools");
36
+ let _tailwindcss_vite = require("@tailwindcss/vite");
37
+ _tailwindcss_vite = __toESM(_tailwindcss_vite, 1);
46
38
  let vite_plugin_singlefile = require("vite-plugin-singlefile");
47
- vite_plugin_singlefile = __toESM(vite_plugin_singlefile);
48
39
  let node_os = require("node:os");
49
- node_os = __toESM(node_os);
40
+ node_os = __toESM(node_os, 1);
50
41
  let playwright = require("playwright");
51
- playwright = __toESM(playwright);
52
42
  let sharp = require("sharp");
53
- sharp = __toESM(sharp);
54
- let __modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
55
- __modelcontextprotocol_sdk_server_stdio_js = __toESM(__modelcontextprotocol_sdk_server_stdio_js);
56
-
43
+ sharp = __toESM(sharp, 1);
44
+ let _modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
57
45
  //#region src/config.ts
58
46
  /**
47
+ * App-specific design system configuration
48
+ *
49
+ * This configuration is read from each app's project.json file
50
+ * under the "style-system" key.
51
+ */
52
+ /**
59
53
  * Default tags for identifying shared/design system components
60
54
  */
61
55
  const DEFAULT_SHARED_COMPONENT_TAGS = ["style-system"];
@@ -102,7 +96,7 @@ function validateDesignSystemConfig(config, projectName) {
102
96
  */
103
97
  async function getAppDesignSystemConfig(appPath) {
104
98
  if (!appPath || typeof appPath !== "string") throw new Error("appPath is required and must be a non-empty string");
105
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
99
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
106
100
  const resolvedAppPath = node_path.default.isAbsolute(appPath) ? appPath : node_path.default.join(monorepoRoot, appPath);
107
101
  const projectJsonPath = node_path.default.join(resolvedAppPath, "project.json");
108
102
  try {
@@ -118,10 +112,10 @@ async function getAppDesignSystemConfig(appPath) {
118
112
  const projectName = project.name ? project.name : node_path.default.basename(resolvedAppPath);
119
113
  if (project["style-system"]) {
120
114
  const validatedConfig = validateDesignSystemConfig(project["style-system"], projectName);
121
- __agiflowai_aicode_utils.log.info(`[Config] Loaded and validated style-system config for ${projectName}`);
115
+ _agiflowai_aicode_utils.log.info(`[Config] Loaded and validated style-system config for ${projectName}`);
122
116
  return validatedConfig;
123
117
  }
124
- __agiflowai_aicode_utils.log.info(`[Config] No style-system config found for ${projectName}, using defaults`);
118
+ _agiflowai_aicode_utils.log.info(`[Config] No style-system config found for ${projectName}, using defaults`);
125
119
  return DEFAULT_CONFIG;
126
120
  } catch (error) {
127
121
  throw new Error(`Failed to read style-system config from ${projectJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
@@ -136,7 +130,7 @@ async function getAppDesignSystemConfig(appPath) {
136
130
  * @returns Array of tag names that identify shared components
137
131
  */
138
132
  async function getSharedComponentTags() {
139
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
133
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
140
134
  const toolkitYamlPath = node_path.default.join(monorepoRoot, "toolkit.yaml");
141
135
  try {
142
136
  const content = await node_fs.promises.readFile(toolkitYamlPath, "utf-8");
@@ -144,15 +138,15 @@ async function getSharedComponentTags() {
144
138
  if (config?.["style-system"]?.sharedComponentTags?.length) {
145
139
  const tags = config["style-system"].sharedComponentTags;
146
140
  if (Array.isArray(tags) && tags.every((tag) => typeof tag === "string")) {
147
- __agiflowai_aicode_utils.log.info(`[Config] Loaded sharedComponentTags from toolkit.yaml: ${tags.join(", ")}`);
141
+ _agiflowai_aicode_utils.log.info(`[Config] Loaded sharedComponentTags from toolkit.yaml: ${tags.join(", ")}`);
148
142
  return tags;
149
143
  }
150
- __agiflowai_aicode_utils.log.warn("[Config] sharedComponentTags in toolkit.yaml is not a valid string array, using defaults");
144
+ _agiflowai_aicode_utils.log.warn("[Config] sharedComponentTags in toolkit.yaml is not a valid string array, using defaults");
151
145
  }
152
146
  } catch (error) {
153
- if (error instanceof Error && "code" in error && error.code !== "ENOENT") __agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
147
+ if (error instanceof Error && "code" in error && error.code !== "ENOENT") _agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
154
148
  }
155
- __agiflowai_aicode_utils.log.info(`[Config] Using default sharedComponentTags: ${DEFAULT_SHARED_COMPONENT_TAGS.join(", ")}`);
149
+ _agiflowai_aicode_utils.log.info(`[Config] Using default sharedComponentTags: ${DEFAULT_SHARED_COMPONENT_TAGS.join(", ")}`);
156
150
  return DEFAULT_SHARED_COMPONENT_TAGS;
157
151
  }
158
152
  /**
@@ -164,7 +158,7 @@ async function getSharedComponentTags() {
164
158
  * @returns GetCssClassesConfig or undefined if not configured
165
159
  */
166
160
  async function getGetCssClassesConfig() {
167
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
161
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
168
162
  const toolkitYamlPath = node_path.default.join(monorepoRoot, "toolkit.yaml");
169
163
  try {
170
164
  const content = await node_fs.promises.readFile(toolkitYamlPath, "utf-8");
@@ -172,14 +166,14 @@ async function getGetCssClassesConfig() {
172
166
  if (config?.["style-system"]?.getCssClasses) {
173
167
  const getCssClassesConfig = config["style-system"].getCssClasses;
174
168
  if (getCssClassesConfig.customService !== void 0 && typeof getCssClassesConfig.customService !== "string") {
175
- __agiflowai_aicode_utils.log.warn("[Config] style-system.getCssClasses.customService must be a string, ignoring");
169
+ _agiflowai_aicode_utils.log.warn("[Config] style-system.getCssClasses.customService must be a string, ignoring");
176
170
  return;
177
171
  }
178
- __agiflowai_aicode_utils.log.info(`[Config] Loaded getCssClasses config from toolkit.yaml`);
172
+ _agiflowai_aicode_utils.log.info(`[Config] Loaded getCssClasses config from toolkit.yaml`);
179
173
  return getCssClassesConfig;
180
174
  }
181
175
  } catch (error) {
182
- if (error instanceof Error && "code" in error && error.code !== "ENOENT") __agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
176
+ if (error instanceof Error && "code" in error && error.code !== "ENOENT") _agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
183
177
  }
184
178
  }
185
179
  /**
@@ -191,7 +185,7 @@ async function getGetCssClassesConfig() {
191
185
  * @returns BundlerConfig or undefined if not configured
192
186
  */
193
187
  async function getBundlerConfig() {
194
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
188
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
195
189
  const toolkitYamlPath = node_path.default.join(monorepoRoot, "toolkit.yaml");
196
190
  try {
197
191
  const content = await node_fs.promises.readFile(toolkitYamlPath, "utf-8");
@@ -199,20 +193,38 @@ async function getBundlerConfig() {
199
193
  if (config?.["style-system"]?.bundler) {
200
194
  const bundlerConfig = config["style-system"].bundler;
201
195
  if (bundlerConfig.customService !== void 0 && typeof bundlerConfig.customService !== "string") {
202
- __agiflowai_aicode_utils.log.warn("[Config] style-system.bundler.customService must be a string, ignoring");
196
+ _agiflowai_aicode_utils.log.warn("[Config] style-system.bundler.customService must be a string, ignoring");
203
197
  return;
204
198
  }
205
- __agiflowai_aicode_utils.log.info(`[Config] Loaded bundler config from toolkit.yaml`);
199
+ _agiflowai_aicode_utils.log.info(`[Config] Loaded bundler config from toolkit.yaml`);
206
200
  return bundlerConfig;
207
201
  }
208
202
  } catch (error) {
209
- if (error instanceof Error && "code" in error && error.code !== "ENOENT") __agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
203
+ if (error instanceof Error && "code" in error && error.code !== "ENOENT") _agiflowai_aicode_utils.log.warn(`[Config] Failed to parse toolkit.yaml: ${error.message}`);
210
204
  }
211
205
  }
212
-
213
206
  //#endregion
214
207
  //#region src/services/CssClasses/BaseCSSClassesService.ts
215
208
  /**
209
+ * BaseCSSClassesService
210
+ *
211
+ * DESIGN PATTERNS:
212
+ * - Abstract base class for CSS class extraction services
213
+ * - Template method pattern for extensible extraction logic
214
+ * - Strategy pattern allowing different CSS framework implementations
215
+ *
216
+ * CODING STANDARDS:
217
+ * - Abstract classes define interface contracts for subclasses
218
+ * - Protected methods allow subclass customization
219
+ * - Use async/await for all I/O operations
220
+ * - Throw descriptive errors with context
221
+ *
222
+ * AVOID:
223
+ * - Direct instantiation of abstract class
224
+ * - Framework-specific logic in base class
225
+ * - Synchronous file operations
226
+ */
227
+ /**
216
228
  * Abstract base class for CSS class extraction services.
217
229
  *
218
230
  * Subclasses must implement the `extractClasses` method to provide
@@ -251,10 +263,27 @@ var BaseCSSClassesService = class {
251
263
  }
252
264
  }
253
265
  };
254
-
255
266
  //#endregion
256
267
  //#region src/services/CssClasses/TailwindCSSClassesService.ts
257
268
  /**
269
+ * TailwindCSSClassesService
270
+ *
271
+ * DESIGN PATTERNS:
272
+ * - Extends BaseCSSClassesService for Tailwind-specific extraction
273
+ * - Uses postcss AST parser for robust CSS variable extraction
274
+ * - Parses CSS variables from theme files to generate utility classes
275
+ *
276
+ * CODING STANDARDS:
277
+ * - Implement abstract methods from base class
278
+ * - Use async/await for file operations
279
+ * - Throw descriptive errors with context
280
+ *
281
+ * AVOID:
282
+ * - Hardcoding theme paths
283
+ * - Synchronous file operations
284
+ * - Fragile regex-based CSS parsing
285
+ */
286
+ /**
258
287
  * Tailwind CSS class extraction service.
259
288
  *
260
289
  * Extracts CSS classes from Tailwind theme files by parsing CSS variables
@@ -469,16 +498,30 @@ var TailwindCSSClassesService = class extends BaseCSSClassesService {
469
498
  return result;
470
499
  }
471
500
  };
472
-
473
501
  //#endregion
474
502
  //#region src/services/CssClasses/types.ts
475
503
  /**
476
504
  * Default configuration values
477
505
  */
478
506
  const DEFAULT_STYLE_SYSTEM_CONFIG = { cssFramework: "tailwind" };
479
-
480
507
  //#endregion
481
508
  //#region src/services/CssClasses/CSSClassesServiceFactory.ts
509
+ /**
510
+ * CSSClassesServiceFactory
511
+ *
512
+ * DESIGN PATTERNS:
513
+ * - Factory pattern for creating CSS classes service instances
514
+ * - Supports built-in frameworks and custom service loading
515
+ *
516
+ * CODING STANDARDS:
517
+ * - Use async factory method for dynamic service loading
518
+ * - Return typed results
519
+ * - Throw descriptive errors with context
520
+ *
521
+ * AVOID:
522
+ * - Synchronous file operations
523
+ * - Hardcoded framework paths
524
+ */
482
525
  /** Valid file extensions for custom service modules */
483
526
  const VALID_SERVICE_EXTENSIONS$1 = [
484
527
  ".ts",
@@ -540,20 +583,20 @@ var CSSClassesServiceFactory = class {
540
583
  async loadCustomService(config) {
541
584
  const servicePath = config.customServicePath;
542
585
  if (!servicePath) throw new Error("customServicePath is required for custom service loading");
543
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
586
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
544
587
  const resolvedPath = node_path.default.resolve(monorepoRoot, servicePath);
545
588
  const normalizedWorkspaceRoot = node_path.default.resolve(monorepoRoot);
546
589
  if (!resolvedPath.startsWith(normalizedWorkspaceRoot + node_path.default.sep)) throw new Error(`Security error: customServicePath "${servicePath}" resolves outside workspace root`);
547
590
  const ext = node_path.default.extname(resolvedPath).toLowerCase();
548
591
  if (!VALID_SERVICE_EXTENSIONS$1.includes(ext)) throw new Error(`Invalid file extension "${ext}" for customServicePath. Expected one of: ${VALID_SERVICE_EXTENSIONS$1.join(", ")}`);
549
- __agiflowai_aicode_utils.log.info(`[CSSClassesServiceFactory] Loading custom CSS service from: ${resolvedPath}`);
592
+ _agiflowai_aicode_utils.log.info(`[CSSClassesServiceFactory] Loading custom CSS service from: ${resolvedPath}`);
550
593
  try {
551
594
  const customModule = await import(resolvedPath);
552
595
  const ServiceClass = customModule.default || customModule.CSSClassesService || customModule.CustomCSSClassesService;
553
596
  if (!ServiceClass) throw new Error(`Custom service module at ${resolvedPath} must export a default class, CSSClassesService, or CustomCSSClassesService that extends BaseCSSClassesService`);
554
597
  const instance = new ServiceClass(config);
555
598
  if (!(instance instanceof BaseCSSClassesService)) throw new Error(`Custom service at ${resolvedPath} must extend BaseCSSClassesService`);
556
- __agiflowai_aicode_utils.log.info(`[CSSClassesServiceFactory] Custom CSS service loaded successfully`);
599
+ _agiflowai_aicode_utils.log.info(`[CSSClassesServiceFactory] Custom CSS service loaded successfully`);
557
600
  return instance;
558
601
  } catch (error) {
559
602
  if (error instanceof Error && error.message.includes("BaseCSSClassesService")) throw error;
@@ -561,10 +604,29 @@ var CSSClassesServiceFactory = class {
561
604
  }
562
605
  }
563
606
  };
564
-
565
607
  //#endregion
566
608
  //#region src/tools/GetCSSClassesTool.ts
567
609
  /**
610
+ * GetCSSClassesTool
611
+ *
612
+ * DESIGN PATTERNS:
613
+ * - Tool pattern with getDefinition() and execute() methods
614
+ * - Service delegation for business logic via factory pattern
615
+ * - JSON Schema validation for inputs
616
+ *
617
+ * CODING STANDARDS:
618
+ * - Implement Tool interface from ../types
619
+ * - Use TOOL_NAME constant with snake_case (e.g., 'get_css_classes')
620
+ * - Return CallToolResult with content array
621
+ * - Handle errors with isError flag
622
+ * - Delegate complex logic to services
623
+ *
624
+ * AVOID:
625
+ * - Complex business logic in execute method
626
+ * - Unhandled promise rejections
627
+ * - Missing input validation
628
+ */
629
+ /**
568
630
  * Valid CSS class category values
569
631
  */
570
632
  const VALID_CATEGORIES = [
@@ -604,7 +666,7 @@ var GetCSSClassesTool = class GetCSSClassesTool {
604
666
  * Creates a new GetCSSClassesTool instance
605
667
  * @param defaultThemePath - Default path to theme CSS file (relative to workspace root)
606
668
  */
607
- constructor(defaultThemePath = "packages/frontend/web-theme/src/agimon-theme.css") {
669
+ constructor(defaultThemePath) {
608
670
  this.serviceFactory = new CSSClassesServiceFactory();
609
671
  this.defaultThemePath = defaultThemePath;
610
672
  }
@@ -680,7 +742,7 @@ var GetCSSClassesTool = class GetCSSClassesTool {
680
742
  * @returns Absolute path to the theme file
681
743
  */
682
744
  async resolveThemePath(appPath) {
683
- const workspaceRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
745
+ const workspaceRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
684
746
  if (appPath) {
685
747
  const config = await getAppDesignSystemConfig(appPath);
686
748
  if (config.themePath) {
@@ -688,12 +750,30 @@ var GetCSSClassesTool = class GetCSSClassesTool {
688
750
  return node_path.default.resolve(resolvedAppPath, config.themePath);
689
751
  }
690
752
  }
691
- return node_path.default.resolve(workspaceRoot, this.defaultThemePath);
753
+ if (this.defaultThemePath) return node_path.default.resolve(workspaceRoot, this.defaultThemePath);
754
+ throw new Error("No theme CSS path configured. Pass --theme-path, or provide style-system.themePath in the target app project.json.");
692
755
  }
693
756
  };
694
-
695
757
  //#endregion
696
758
  //#region src/services/StoriesIndexService/StoriesIndexService.ts
759
+ /**
760
+ * StoriesIndexService
761
+ *
762
+ * DESIGN PATTERNS:
763
+ * - Service pattern for business logic encapsulation
764
+ * - Single responsibility principle
765
+ * - Caching with file content hashing
766
+ *
767
+ * CODING STANDARDS:
768
+ * - Use async/await for asynchronous operations
769
+ * - Throw descriptive errors for error cases
770
+ * - Keep methods focused and well-named
771
+ * - Document complex logic with comments
772
+ *
773
+ * AVOID:
774
+ * - Mixing concerns (keep focused on single domain)
775
+ * - Direct tool implementation (services should be tool-agnostic)
776
+ */
697
777
  var StoriesIndexService = class {
698
778
  componentIndex = /* @__PURE__ */ new Map();
699
779
  monorepoRoot;
@@ -704,7 +784,7 @@ var StoriesIndexService = class {
704
784
  * Creates a new StoriesIndexService instance
705
785
  */
706
786
  constructor() {
707
- this.monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
787
+ this.monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
708
788
  }
709
789
  /**
710
790
  * Initialize the index by scanning all .stories files.
@@ -712,7 +792,7 @@ var StoriesIndexService = class {
712
792
  */
713
793
  async initialize() {
714
794
  if (this.initialized && this.lastInitResult) return this.lastInitResult;
715
- __agiflowai_aicode_utils.log.info("[StoriesIndexService] Initializing story index...");
795
+ _agiflowai_aicode_utils.log.info("[StoriesIndexService] Initializing story index...");
716
796
  const storyFiles = await (0, glob.glob)("**/*.stories.{ts,tsx}", {
717
797
  cwd: this.monorepoRoot,
718
798
  ignore: [
@@ -723,7 +803,7 @@ var StoriesIndexService = class {
723
803
  ],
724
804
  absolute: true
725
805
  });
726
- __agiflowai_aicode_utils.log.info(`[StoriesIndexService] Found ${storyFiles.length} story files`);
806
+ _agiflowai_aicode_utils.log.info(`[StoriesIndexService] Found ${storyFiles.length} story files`);
727
807
  const failures = [];
728
808
  let successCount = 0;
729
809
  const results = await Promise.allSettled(storyFiles.map((filePath) => this.indexStoryFile(filePath)));
@@ -731,7 +811,7 @@ var StoriesIndexService = class {
731
811
  else {
732
812
  const filePath = storyFiles[index];
733
813
  const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);
734
- __agiflowai_aicode_utils.log.error(`[StoriesIndexService] Error indexing ${filePath}: ${errorMessage}`);
814
+ _agiflowai_aicode_utils.log.error(`[StoriesIndexService] Error indexing ${filePath}: ${errorMessage}`);
735
815
  failures.push({
736
816
  filePath,
737
817
  error: errorMessage
@@ -744,8 +824,8 @@ var StoriesIndexService = class {
744
824
  failureCount: failures.length,
745
825
  failures
746
826
  };
747
- if (failures.length > 0) __agiflowai_aicode_utils.log.warn(`[StoriesIndexService] Indexed ${successCount}/${storyFiles.length} files successfully. ${failures.length} files failed.`);
748
- else __agiflowai_aicode_utils.log.info(`[StoriesIndexService] Indexed ${this.componentIndex.size} components successfully`);
827
+ if (failures.length > 0) _agiflowai_aicode_utils.log.warn(`[StoriesIndexService] Indexed ${successCount}/${storyFiles.length} files successfully. ${failures.length} files failed.`);
828
+ else _agiflowai_aicode_utils.log.info(`[StoriesIndexService] Indexed ${this.componentIndex.size} components successfully`);
749
829
  return this.lastInitResult;
750
830
  }
751
831
  /**
@@ -764,13 +844,13 @@ var StoriesIndexService = class {
764
844
  async indexStoryFile(filePath) {
765
845
  const content = await node_fs.promises.readFile(filePath, "utf-8");
766
846
  const fileHash = this.hashContent(content);
767
- const csf = (0, __storybook_csf_tools.loadCsf)(content, {
847
+ const csf = (0, _storybook_csf_tools.loadCsf)(content, {
768
848
  fileName: filePath,
769
849
  makeTitle: (title) => title
770
850
  });
771
851
  await csf.parse();
772
852
  if (!csf.meta?.title) {
773
- __agiflowai_aicode_utils.log.warn(`[StoriesIndexService] No valid meta title in ${filePath}`);
853
+ _agiflowai_aicode_utils.log.warn(`[StoriesIndexService] No valid meta title in ${filePath}`);
774
854
  return;
775
855
  }
776
856
  const stories = csf.stories.map((story) => story.name).filter((name) => !!name);
@@ -883,17 +963,32 @@ var StoriesIndexService = class {
883
963
  return Array.from(tagSet).sort();
884
964
  }
885
965
  };
886
-
887
966
  //#endregion
888
967
  //#region src/services/AppComponentsService/types.ts
889
968
  /**
890
969
  * Default configuration values.
891
970
  */
892
971
  const DEFAULT_APP_COMPONENTS_CONFIG = { pageSize: 50 };
893
-
894
972
  //#endregion
895
973
  //#region src/services/AppComponentsService/AppComponentsService.ts
896
974
  /**
975
+ * AppComponentsService
976
+ *
977
+ * DESIGN PATTERNS:
978
+ * - Service pattern for business logic encapsulation
979
+ * - Single responsibility principle
980
+ *
981
+ * CODING STANDARDS:
982
+ * - Use async/await for asynchronous operations
983
+ * - Throw descriptive errors for error cases
984
+ * - Keep methods focused and well-named
985
+ * - Document complex logic with comments
986
+ *
987
+ * AVOID:
988
+ * - Mixing concerns (keep focused on single domain)
989
+ * - Direct tool implementation (services should be tool-agnostic)
990
+ */
991
+ /**
897
992
  * AppComponentsService handles listing app-specific and package components.
898
993
  *
899
994
  * Detects components by file path (within app directory) and resolves
@@ -929,7 +1024,7 @@ var AppComponentsService = class {
929
1024
  if (input.cursor !== void 0 && typeof input.cursor !== "string") throw new Error("cursor must be a string");
930
1025
  const { appPath, cursor } = input;
931
1026
  const { offset } = cursor ? this.decodeCursor(cursor) : { offset: 0 };
932
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
1027
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
933
1028
  const resolvedAppPath = node_path.default.isAbsolute(appPath) ? appPath : node_path.default.join(monorepoRoot, appPath);
934
1029
  try {
935
1030
  await node_fs.promises.access(resolvedAppPath);
@@ -943,7 +1038,7 @@ var AppComponentsService = class {
943
1038
  this.buildPackageMap(monorepoRoot),
944
1039
  storiesIndex.initialize()
945
1040
  ]);
946
- __agiflowai_aicode_utils.log.info(`[AppComponentsService] Found ${workspaceDependencies.length} workspace dependencies for ${appName}`);
1041
+ _agiflowai_aicode_utils.log.info(`[AppComponentsService] Found ${workspaceDependencies.length} workspace dependencies for ${appName}`);
947
1042
  const allComponents = storiesIndex.getAllComponents();
948
1043
  const { appComponentsArray, packageComponents, totalPackageComponents } = this.categorizeComponents(allComponents, resolvedAppPath, workspaceDependencies, packageMap);
949
1044
  const totalComponents = appComponentsArray.length + totalPackageComponents;
@@ -961,7 +1056,7 @@ var AppComponentsService = class {
961
1056
  }
962
1057
  };
963
1058
  if (hasMore) result.nextCursor = this.encodeCursor(offset + totalReturned);
964
- __agiflowai_aicode_utils.log.info(`[AppComponentsService] Page ${Math.floor(offset / this.config.pageSize) + 1}: Returned ${totalReturned} of ${totalComponents} total components (hasMore: ${hasMore})`);
1059
+ _agiflowai_aicode_utils.log.info(`[AppComponentsService] Page ${Math.floor(offset / this.config.pageSize) + 1}: Returned ${totalReturned} of ${totalComponents} total components (hasMore: ${hasMore})`);
965
1060
  return result;
966
1061
  }
967
1062
  /**
@@ -975,7 +1070,7 @@ var AppComponentsService = class {
975
1070
  try {
976
1071
  appName = JSON.parse(await node_fs.promises.readFile(projectJsonPath, "utf-8")).name || appName;
977
1072
  } catch (error) {
978
- __agiflowai_aicode_utils.log.warn(`[AppComponentsService] Could not read project.json for ${resolvedAppPath}:`, error);
1073
+ _agiflowai_aicode_utils.log.warn(`[AppComponentsService] Could not read project.json for ${resolvedAppPath}:`, error);
979
1074
  }
980
1075
  return appName;
981
1076
  }
@@ -994,7 +1089,7 @@ var AppComponentsService = class {
994
1089
  };
995
1090
  return Object.entries(allDeps).filter(([_name, version]) => typeof version === "string" && version.startsWith("workspace:")).map(([name]) => name);
996
1091
  } catch (error) {
997
- __agiflowai_aicode_utils.log.warn(`[AppComponentsService] Could not read package.json for ${resolvedAppPath}:`, error);
1092
+ _agiflowai_aicode_utils.log.warn(`[AppComponentsService] Could not read package.json for ${resolvedAppPath}:`, error);
998
1093
  return [];
999
1094
  }
1000
1095
  }
@@ -1031,7 +1126,7 @@ var AppComponentsService = class {
1031
1126
  for (const [index, result] of results.entries()) if (result.status === "fulfilled" && result.value.name) {
1032
1127
  const pkgDir = node_path.default.dirname(result.value.pkgJsonPath);
1033
1128
  packageMap.set(result.value.name, pkgDir);
1034
- } else if (result.status === "rejected") __agiflowai_aicode_utils.log.debug(`[AppComponentsService] Skipping invalid package.json at ${packageJsonFiles[index]}:`, result.reason);
1129
+ } else if (result.status === "rejected") _agiflowai_aicode_utils.log.debug(`[AppComponentsService] Skipping invalid package.json at ${packageJsonFiles[index]}:`, result.reason);
1035
1130
  return packageMap;
1036
1131
  }
1037
1132
  /**
@@ -1130,12 +1225,11 @@ var AppComponentsService = class {
1130
1225
  const decoded = Buffer.from(cursor, "base64").toString("utf-8");
1131
1226
  return { offset: JSON.parse(decoded).offset || 0 };
1132
1227
  } catch {
1133
- __agiflowai_aicode_utils.log.debug("[AppComponentsService] Invalid cursor, resetting to offset 0");
1228
+ _agiflowai_aicode_utils.log.debug("[AppComponentsService] Invalid cursor, resetting to offset 0");
1134
1229
  return { offset: 0 };
1135
1230
  }
1136
1231
  }
1137
1232
  };
1138
-
1139
1233
  //#endregion
1140
1234
  //#region src/services/BundlerService/BaseBundlerService.ts
1141
1235
  /**
@@ -1165,10 +1259,27 @@ var BaseBundlerService = class {
1165
1259
  this.config = config;
1166
1260
  }
1167
1261
  };
1168
-
1169
1262
  //#endregion
1170
1263
  //#region src/services/BundlerService/ViteReactBundlerService.ts
1171
1264
  /**
1265
+ * ViteReactBundlerService
1266
+ *
1267
+ * DESIGN PATTERNS:
1268
+ * - Concrete implementation of BaseBundlerService
1269
+ * - Singleton pattern for dev server management
1270
+ * - Programmatic Vite build for React component SSR
1271
+ *
1272
+ * CODING STANDARDS:
1273
+ * - Use async/await for asynchronous operations
1274
+ * - Throw descriptive errors for error cases
1275
+ * - Keep methods focused and well-named
1276
+ * - Document complex logic with comments
1277
+ *
1278
+ * AVOID:
1279
+ * - Mixing concerns (keep focused on Vite + React)
1280
+ * - Direct tool implementation (services should be tool-agnostic)
1281
+ */
1282
+ /**
1172
1283
  * Maximum age for story configs in milliseconds (5 minutes).
1173
1284
  * Configs older than this are cleaned up to prevent memory leaks.
1174
1285
  */
@@ -1255,13 +1366,13 @@ function createStoryEntryPlugin(getStoryConfig, generateCode) {
1255
1366
  enforce: "pre",
1256
1367
  resolveId(id) {
1257
1368
  if (id.includes("virtual:story-entry")) {
1258
- __agiflowai_aicode_utils.log.debug(`[vite-plugin-story-entry] resolveId: ${id}`);
1369
+ _agiflowai_aicode_utils.log.debug(`[vite-plugin-story-entry] resolveId: ${id}`);
1259
1370
  return `\0${id.replace(/^\//, "")}`;
1260
1371
  }
1261
1372
  },
1262
1373
  load(id) {
1263
1374
  if (id.includes("virtual:story-entry")) {
1264
- __agiflowai_aicode_utils.log.debug(`[vite-plugin-story-entry] load: ${id}`);
1375
+ _agiflowai_aicode_utils.log.debug(`[vite-plugin-story-entry] load: ${id}`);
1265
1376
  const storyId = id.match(/id=([^&]+)/)?.[1];
1266
1377
  if (storyId) {
1267
1378
  const config = getStoryConfig(storyId);
@@ -1308,7 +1419,7 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1308
1419
  */
1309
1420
  constructor(config = {}) {
1310
1421
  super(config);
1311
- this.monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
1422
+ this.monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
1312
1423
  }
1313
1424
  /**
1314
1425
  * Get the singleton instance of ViteReactBundlerService.
@@ -1385,14 +1496,14 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1385
1496
  async startDevServer(appPath) {
1386
1497
  const resolvedAppPath = node_path.default.isAbsolute(appPath) ? appPath : node_path.default.join(this.monorepoRoot, appPath);
1387
1498
  if (this.isServerRunning() && this.currentAppPath === resolvedAppPath) {
1388
- __agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Server already running for ${resolvedAppPath}`);
1499
+ _agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Server already running for ${resolvedAppPath}`);
1389
1500
  return {
1390
1501
  url: this.serverUrl,
1391
1502
  port: this.serverPort
1392
1503
  };
1393
1504
  }
1394
1505
  if (this.serverStartPromise) {
1395
- __agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Server start already in progress, waiting...");
1506
+ _agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Server start already in progress, waiting...");
1396
1507
  return this.serverStartPromise;
1397
1508
  }
1398
1509
  this.serverStartPromise = this.doStartDevServer(resolvedAppPath);
@@ -1411,12 +1522,12 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1411
1522
  const tmpDir = node_path.default.join(resolvedAppPath, ".tmp");
1412
1523
  try {
1413
1524
  await node_fs.promises.mkdir(tmpDir, { recursive: true });
1414
- const { createServer: createServer$1 } = await import("vite");
1415
- this.server = await createServer$1({
1525
+ const { createServer } = await import("vite");
1526
+ this.server = await createServer({
1416
1527
  root: tmpDir,
1417
1528
  base: "/",
1418
1529
  configFile: false,
1419
- plugins: [(0, __tailwindcss_vite.default)(), createStoryEntryPlugin((id) => this.storyConfigs.get(id), (opts) => this.generateEntryFile(opts))],
1530
+ plugins: [(0, _tailwindcss_vite.default)(), createStoryEntryPlugin((id) => this.storyConfigs.get(id), (opts) => this.generateEntryFile(opts))],
1420
1531
  resolve: { alias: { "@": node_path.default.join(resolvedAppPath, "src") } },
1421
1532
  esbuild: {
1422
1533
  jsx: "automatic",
@@ -1428,21 +1539,21 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1428
1539
  }
1429
1540
  });
1430
1541
  this.server.middlewares.use(async (req, res, next) => {
1431
- const url$1 = req.url || "/";
1432
- const match = url$1.match(/^\/preview\/([^/?]+)/);
1542
+ const url = req.url || "/";
1543
+ const match = url.match(/^\/preview\/([^/?]+)/);
1433
1544
  if (match) {
1434
1545
  const storyId = match[1];
1435
1546
  const config = this.storyConfigs.get(storyId);
1436
1547
  if (config) try {
1437
1548
  const htmlTemplate = this.generateHtmlTemplate(`@virtual:story-entry?id=${storyId}`, config.darkMode);
1438
- const transformedHtml = await this.server?.transformIndexHtml(url$1, htmlTemplate);
1549
+ const transformedHtml = await this.server?.transformIndexHtml(url, htmlTemplate);
1439
1550
  res.statusCode = 200;
1440
1551
  res.setHeader("Content-Type", "text/html");
1441
1552
  res.end(transformedHtml);
1442
1553
  return;
1443
1554
  } catch (e) {
1444
1555
  const err = e;
1445
- __agiflowai_aicode_utils.log.error(`[ViteMiddleware] Error serving preview: ${err.message}`);
1556
+ _agiflowai_aicode_utils.log.error(`[ViteMiddleware] Error serving preview: ${err.message}`);
1446
1557
  next(err);
1447
1558
  return;
1448
1559
  }
@@ -1457,7 +1568,7 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1457
1568
  this.serverUrl = url;
1458
1569
  this.serverPort = port;
1459
1570
  this.currentAppPath = resolvedAppPath;
1460
- __agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Vite dev server started at ${url}`);
1571
+ _agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Vite dev server started at ${url}`);
1461
1572
  return {
1462
1573
  url,
1463
1574
  port
@@ -1505,7 +1616,7 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1505
1616
  this.storyConfigTimestamps.set(storyId, timestamp);
1506
1617
  const url = `${this.serverUrl}/preview/${storyId}`;
1507
1618
  const htmlContent = this.generateHtmlTemplate(`@virtual:story-entry?id=${storyId}`, darkMode);
1508
- __agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Component served at: ${url}`);
1619
+ _agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Component served at: ${url}`);
1509
1620
  return {
1510
1621
  url,
1511
1622
  htmlContent
@@ -1558,11 +1669,11 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1558
1669
  */
1559
1670
  async cleanup() {
1560
1671
  if (this.server) {
1561
- __agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Closing Vite dev server...");
1672
+ _agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Closing Vite dev server...");
1562
1673
  try {
1563
1674
  await this.server.close();
1564
1675
  } catch (error) {
1565
- __agiflowai_aicode_utils.log.error(`[ViteReactBundlerService] Error closing server: ${error instanceof Error ? error.message : String(error)}`);
1676
+ _agiflowai_aicode_utils.log.error(`[ViteReactBundlerService] Error closing server: ${error instanceof Error ? error.message : String(error)}`);
1566
1677
  }
1567
1678
  this.server = null;
1568
1679
  this.serverUrl = null;
@@ -1571,7 +1682,7 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1571
1682
  this.serverStartPromise = null;
1572
1683
  this.storyConfigs.clear();
1573
1684
  this.storyConfigTimestamps.clear();
1574
- __agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Vite dev server closed");
1685
+ _agiflowai_aicode_utils.log.info("[ViteReactBundlerService] Vite dev server closed");
1575
1686
  }
1576
1687
  }
1577
1688
  /**
@@ -1587,14 +1698,14 @@ var ViteReactBundlerService = class ViteReactBundlerService extends BaseBundlerS
1587
1698
  this.storyConfigs.delete(storyId);
1588
1699
  this.storyConfigTimestamps.delete(storyId);
1589
1700
  }
1590
- if (entriesToDelete.length > 0) __agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Cleaned up ${entriesToDelete.length} stale story configs`);
1701
+ if (entriesToDelete.length > 0) _agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Cleaned up ${entriesToDelete.length} stale story configs`);
1591
1702
  if (this.storyConfigs.size > STORY_CONFIG_MAX_COUNT) {
1592
1703
  const toRemove = Array.from(this.storyConfigTimestamps.entries()).sort((a, b) => a[1] - b[1]).slice(0, this.storyConfigs.size - STORY_CONFIG_MAX_COUNT);
1593
1704
  for (const [storyId] of toRemove) {
1594
1705
  this.storyConfigs.delete(storyId);
1595
1706
  this.storyConfigTimestamps.delete(storyId);
1596
1707
  }
1597
- __agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Removed ${toRemove.length} oldest story configs to stay under limit`);
1708
+ _agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Removed ${toRemove.length} oldest story configs to stay under limit`);
1598
1709
  }
1599
1710
  }
1600
1711
  /**
@@ -1709,7 +1820,7 @@ root.render(wrappedElement);
1709
1820
  base: "./",
1710
1821
  configFile: false,
1711
1822
  plugins: [
1712
- (0, __tailwindcss_vite.default)(),
1823
+ (0, _tailwindcss_vite.default)(),
1713
1824
  (0, vite_plugin_singlefile.viteSingleFile)(),
1714
1825
  createStoryEntryPlugin((id) => buildStoryConfigs.get(id), (opts) => this.generateEntryFile(opts))
1715
1826
  ],
@@ -1729,8 +1840,8 @@ root.render(wrappedElement);
1729
1840
  }
1730
1841
  });
1731
1842
  const builtHtmlPath = node_path.default.join(outDir, htmlTemplateFileName);
1732
- __agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Component built to: ${builtHtmlPath}`);
1733
- await node_fs.promises.unlink(htmlTemplatePath).catch((err) => __agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Failed to cleanup temp file: ${err.message}`));
1843
+ _agiflowai_aicode_utils.log.info(`[ViteReactBundlerService] Component built to: ${builtHtmlPath}`);
1844
+ await node_fs.promises.unlink(htmlTemplatePath).catch((err) => _agiflowai_aicode_utils.log.debug(`[ViteReactBundlerService] Failed to cleanup temp file: ${err.message}`));
1734
1845
  return builtHtmlPath;
1735
1846
  } catch (error) {
1736
1847
  const err = /* @__PURE__ */ new Error(`Failed to build component: ${error instanceof Error ? error.message : String(error)}`);
@@ -1739,9 +1850,26 @@ root.render(wrappedElement);
1739
1850
  }
1740
1851
  }
1741
1852
  };
1742
-
1743
1853
  //#endregion
1744
1854
  //#region src/services/BundlerService/BundlerServiceFactory.ts
1855
+ /**
1856
+ * BundlerServiceFactory
1857
+ *
1858
+ * DESIGN PATTERNS:
1859
+ * - Factory pattern for creating bundler service instances
1860
+ * - Registry pattern for bundler implementations
1861
+ * - Follows StoriesIndexService factory approach
1862
+ *
1863
+ * CODING STANDARDS:
1864
+ * - Use type-safe factory functions
1865
+ * - Provide sensible defaults (ViteReactBundlerService)
1866
+ * - Allow user-provided implementations
1867
+ * - Document public APIs with JSDoc
1868
+ *
1869
+ * AVOID:
1870
+ * - Hard-coding bundler implementations
1871
+ * - Breaking changes to factory interface
1872
+ */
1745
1873
  /** Valid file extensions for custom service modules */
1746
1874
  const VALID_SERVICE_EXTENSIONS = [
1747
1875
  ".ts",
@@ -1766,22 +1894,7 @@ const VALID_SERVICE_EXTENSIONS = [
1766
1894
  function createDefaultBundlerService() {
1767
1895
  return ViteReactBundlerService.getInstance();
1768
1896
  }
1769
- /**
1770
- * Registry of available bundler service factories.
1771
- * Allows registration of custom bundler implementations by key.
1772
- *
1773
- * @example
1774
- * ```typescript
1775
- * // Register a custom bundler
1776
- * bundlerRegistry.set('webpack-react', () => new WebpackReactBundlerService());
1777
- *
1778
- * // Get a bundler by key
1779
- * const factory = bundlerRegistry.get('webpack-react');
1780
- * const bundler = factory?.() ?? createDefaultBundlerService();
1781
- * ```
1782
- */
1783
- const bundlerRegistry = /* @__PURE__ */ new Map();
1784
- bundlerRegistry.set("vite-react", createDefaultBundlerService);
1897
+ (/* @__PURE__ */ new Map()).set("vite-react", createDefaultBundlerService);
1785
1898
  /** Cached bundler service instance loaded from config */
1786
1899
  let cachedBundlerService = null;
1787
1900
  /**
@@ -1815,28 +1928,28 @@ async function getBundlerServiceFromConfig() {
1815
1928
  cachedBundlerService = createDefaultBundlerService();
1816
1929
  return cachedBundlerService;
1817
1930
  }
1818
- const monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
1931
+ const monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
1819
1932
  const customServicePath = node_path.default.resolve(monorepoRoot, config.customService);
1820
1933
  const normalizedWorkspaceRoot = node_path.default.resolve(monorepoRoot);
1821
1934
  if (!customServicePath.startsWith(normalizedWorkspaceRoot + node_path.default.sep)) {
1822
- __agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Security error: customService path "${config.customService}" resolves outside workspace root`);
1935
+ _agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Security error: customService path "${config.customService}" resolves outside workspace root`);
1823
1936
  cachedBundlerService = createDefaultBundlerService();
1824
1937
  return cachedBundlerService;
1825
1938
  }
1826
1939
  const ext = node_path.default.extname(customServicePath).toLowerCase();
1827
1940
  if (!VALID_SERVICE_EXTENSIONS.includes(ext)) {
1828
- __agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Invalid file extension "${ext}" for customService. Expected one of: ${VALID_SERVICE_EXTENSIONS.join(", ")}`);
1941
+ _agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Invalid file extension "${ext}" for customService. Expected one of: ${VALID_SERVICE_EXTENSIONS.join(", ")}`);
1829
1942
  cachedBundlerService = createDefaultBundlerService();
1830
1943
  return cachedBundlerService;
1831
1944
  }
1832
1945
  try {
1833
- __agiflowai_aicode_utils.log.info(`[BundlerServiceFactory] Loading custom bundler service from: ${customServicePath}`);
1834
- const module$1 = await import(customServicePath);
1835
- if (module$1.default) {
1836
- if (typeof module$1.default === "function" && module$1.default.prototype) if (typeof module$1.default.getInstance === "function") cachedBundlerService = module$1.default.getInstance();
1837
- else cachedBundlerService = new module$1.default();
1838
- else if (typeof module$1.default === "object") cachedBundlerService = module$1.default;
1839
- } else if (typeof module$1.getInstance === "function") cachedBundlerService = module$1.getInstance();
1946
+ _agiflowai_aicode_utils.log.info(`[BundlerServiceFactory] Loading custom bundler service from: ${customServicePath}`);
1947
+ const module = await import(customServicePath);
1948
+ if (module.default) {
1949
+ if (typeof module.default === "function" && module.default.prototype) if (typeof module.default.getInstance === "function") cachedBundlerService = module.default.getInstance();
1950
+ else cachedBundlerService = new module.default();
1951
+ else if (typeof module.default === "object") cachedBundlerService = module.default;
1952
+ } else if (typeof module.getInstance === "function") cachedBundlerService = module.getInstance();
1840
1953
  if (!cachedBundlerService) throw new Error("Custom bundler service module must export a class extending BaseBundlerService as default, an instance as default, or a getInstance() function");
1841
1954
  const missingMethods = [
1842
1955
  "getBundlerId",
@@ -1851,19 +1964,35 @@ async function getBundlerServiceFromConfig() {
1851
1964
  "cleanup"
1852
1965
  ].filter((method) => typeof cachedBundlerService[method] !== "function");
1853
1966
  if (missingMethods.length > 0) throw new Error(`Custom bundler service must implement BaseBundlerService interface. Missing methods: ${missingMethods.join(", ")}`);
1854
- __agiflowai_aicode_utils.log.info(`[BundlerServiceFactory] Custom bundler service loaded successfully`);
1967
+ _agiflowai_aicode_utils.log.info(`[BundlerServiceFactory] Custom bundler service loaded successfully`);
1855
1968
  return cachedBundlerService;
1856
1969
  } catch (error) {
1857
1970
  const message = error instanceof Error ? error.message : String(error);
1858
- __agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Failed to load custom bundler service: ${message}`);
1859
- __agiflowai_aicode_utils.log.info("[BundlerServiceFactory] Falling back to default ViteReactBundlerService");
1971
+ _agiflowai_aicode_utils.log.error(`[BundlerServiceFactory] Failed to load custom bundler service: ${message}`);
1972
+ _agiflowai_aicode_utils.log.info("[BundlerServiceFactory] Falling back to default ViteReactBundlerService");
1860
1973
  cachedBundlerService = createDefaultBundlerService();
1861
1974
  return cachedBundlerService;
1862
1975
  }
1863
1976
  }
1864
-
1865
1977
  //#endregion
1866
1978
  //#region src/utils/screenshot.ts
1979
+ /**
1980
+ * Screenshot utility using Playwright
1981
+ *
1982
+ * DESIGN PATTERNS:
1983
+ * - Utility function for browser automation
1984
+ * - Factory pattern for browser selection
1985
+ * - Options pattern for configuration
1986
+ *
1987
+ * CODING STANDARDS:
1988
+ * - Use async/await for browser operations
1989
+ * - Clean up resources (close browser) in finally block
1990
+ * - Support multiple browsers (chromium, firefox, webkit)
1991
+ *
1992
+ * AVOID:
1993
+ * - Leaving browser instances open
1994
+ * - Hardcoding viewport sizes
1995
+ */
1867
1996
  const browsers = {
1868
1997
  chromium: playwright.chromium,
1869
1998
  firefox: playwright.firefox,
@@ -1947,10 +2076,28 @@ async function takeScreenshot(options) {
1947
2076
  if (browser) await browser.close();
1948
2077
  }
1949
2078
  }
1950
-
1951
2079
  //#endregion
1952
2080
  //#region src/services/ThemeService/BaseThemeService.ts
1953
2081
  /**
2082
+ * BaseThemeService
2083
+ *
2084
+ * DESIGN PATTERNS:
2085
+ * - Abstract base class for theme listing services
2086
+ * - Template method pattern for extensible theme extraction
2087
+ * - Strategy pattern allowing different theme source implementations
2088
+ *
2089
+ * CODING STANDARDS:
2090
+ * - Abstract classes define interface contracts for subclasses
2091
+ * - Protected methods allow subclass customization
2092
+ * - Use async/await for all I/O operations
2093
+ * - Throw descriptive errors with context
2094
+ *
2095
+ * AVOID:
2096
+ * - Direct instantiation of abstract class
2097
+ * - Source-specific logic in base class
2098
+ * - Synchronous file operations
2099
+ */
2100
+ /**
1954
2101
  * Abstract base class for theme listing services.
1955
2102
  *
1956
2103
  * Subclasses must implement the `listThemes` method to provide
@@ -1989,10 +2136,27 @@ var BaseThemeService = class {
1989
2136
  }
1990
2137
  }
1991
2138
  };
1992
-
1993
2139
  //#endregion
1994
2140
  //#region src/services/ThemeService/CSSThemeService.ts
1995
2141
  /**
2142
+ * CSSThemeService
2143
+ *
2144
+ * DESIGN PATTERNS:
2145
+ * - Extends BaseThemeService for CSS-based theme extraction
2146
+ * - Uses postcss AST parser for robust CSS parsing
2147
+ * - Extracts theme names from CSS class selectors
2148
+ *
2149
+ * CODING STANDARDS:
2150
+ * - Implement abstract methods from base class
2151
+ * - Use async/await for file operations
2152
+ * - Throw descriptive errors with context
2153
+ *
2154
+ * AVOID:
2155
+ * - Hardcoding theme paths
2156
+ * - Synchronous file operations
2157
+ * - Fragile regex-based CSS parsing
2158
+ */
2159
+ /**
1996
2160
  * CSS-based theme service implementation.
1997
2161
  *
1998
2162
  * Extracts themes from CSS files by parsing class selectors that contain
@@ -2014,7 +2178,7 @@ var CSSThemeService = class extends BaseThemeService {
2014
2178
  */
2015
2179
  constructor(config) {
2016
2180
  super(config);
2017
- this.monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
2181
+ this.monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
2018
2182
  }
2019
2183
  /**
2020
2184
  * Get the source identifier for this service
@@ -2041,7 +2205,7 @@ var CSSThemeService = class extends BaseThemeService {
2041
2205
  return this.extractThemesFromCSS(cssFilePath);
2042
2206
  }));
2043
2207
  for (const [index, result] of results.entries()) if (result.status === "fulfilled") themes.push(...result.value);
2044
- else __agiflowai_aicode_utils.log.warn(`[CSSThemeService] Could not process ${cssFilePaths[index]}:`, result.reason);
2208
+ else _agiflowai_aicode_utils.log.warn(`[CSSThemeService] Could not process ${cssFilePaths[index]}:`, result.reason);
2045
2209
  const uniqueThemes = this.deduplicateThemes(themes);
2046
2210
  return {
2047
2211
  themes: uniqueThemes.sort((a, b) => a.name.localeCompare(b.name)),
@@ -2102,7 +2266,7 @@ var CSSThemeService = class extends BaseThemeService {
2102
2266
  } catch (error) {
2103
2267
  throw new Error(`Failed to parse CSS file ${cssFilePath}: ${error instanceof Error ? error.message : String(error)}`);
2104
2268
  }
2105
- __agiflowai_aicode_utils.log.info(`[CSSThemeService] Found ${themes.length} themes in ${fileName}`);
2269
+ _agiflowai_aicode_utils.log.info(`[CSSThemeService] Found ${themes.length} themes in ${fileName}`);
2106
2270
  return themes;
2107
2271
  }
2108
2272
  /**
@@ -2119,10 +2283,26 @@ var CSSThemeService = class extends BaseThemeService {
2119
2283
  });
2120
2284
  }
2121
2285
  };
2122
-
2123
2286
  //#endregion
2124
2287
  //#region src/services/ThemeService/ThemeService.ts
2125
2288
  /**
2289
+ * ThemeService
2290
+ *
2291
+ * DESIGN PATTERNS:
2292
+ * - Service pattern for business logic encapsulation
2293
+ * - App-specific theme configuration from project.json
2294
+ *
2295
+ * CODING STANDARDS:
2296
+ * - Use async/await for asynchronous operations
2297
+ * - Throw descriptive errors for error cases
2298
+ * - Keep methods focused and well-named
2299
+ * - Document complex logic with comments
2300
+ *
2301
+ * AVOID:
2302
+ * - Mixing concerns (keep focused on single domain)
2303
+ * - Direct tool implementation (services should be tool-agnostic)
2304
+ */
2305
+ /**
2126
2306
  * ThemeService handles theme configuration and CSS generation.
2127
2307
  *
2128
2308
  * Provides methods for accessing theme CSS, generating theme wrappers,
@@ -2143,10 +2323,10 @@ var ThemeService = class {
2143
2323
  * @param config - Design system configuration
2144
2324
  */
2145
2325
  constructor(config) {
2146
- this.monorepoRoot = __agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
2326
+ this.monorepoRoot = _agiflowai_aicode_utils.TemplatesManagerService.getWorkspaceRootSync();
2147
2327
  this.config = config;
2148
- __agiflowai_aicode_utils.log.info(`[ThemeService] Using theme provider: ${this.config.themeProvider}`);
2149
- __agiflowai_aicode_utils.log.info(`[ThemeService] Design system type: ${this.config.type}`);
2328
+ _agiflowai_aicode_utils.log.info(`[ThemeService] Using theme provider: ${this.config.themeProvider}`);
2329
+ _agiflowai_aicode_utils.log.info(`[ThemeService] Design system type: ${this.config.type}`);
2150
2330
  }
2151
2331
  /**
2152
2332
  * Get design system configuration
@@ -2208,7 +2388,7 @@ export default WrappedComponent;
2208
2388
  try {
2209
2389
  return await node_fs.promises.readFile(cssFile, "utf-8");
2210
2390
  } catch (error) {
2211
- __agiflowai_aicode_utils.log.warn(`[ThemeService] Could not read CSS file ${cssFile}:`, error);
2391
+ _agiflowai_aicode_utils.log.warn(`[ThemeService] Could not read CSS file ${cssFile}:`, error);
2212
2392
  return "";
2213
2393
  }
2214
2394
  }))).filter(Boolean).join("\n");
@@ -2271,7 +2451,7 @@ export default WrappedComponent;
2271
2451
  for (const [index, result] of results.entries()) if (result.status === "fulfilled") {
2272
2452
  themes.push(result.value);
2273
2453
  if (result.value.name === "lightTheme" || result.value.name === "agimonTheme") activeBrand = result.value.name;
2274
- } else __agiflowai_aicode_utils.log.warn(`[ThemeService] Failed to process theme file ${themeFiles[index]}:`, result.reason);
2454
+ } else _agiflowai_aicode_utils.log.warn(`[ThemeService] Failed to process theme file ${themeFiles[index]}:`, result.reason);
2275
2455
  return {
2276
2456
  themes: themes.sort((a, b) => a.name.localeCompare(b.name)),
2277
2457
  activeBrand
@@ -2281,7 +2461,6 @@ export default WrappedComponent;
2281
2461
  }
2282
2462
  }
2283
2463
  };
2284
-
2285
2464
  //#endregion
2286
2465
  //#region src/services/ThemeService/types.ts
2287
2466
  /**
@@ -2292,10 +2471,25 @@ const DEFAULT_THEME_SERVICE_CONFIG = {
2292
2471
  cssFiles: [],
2293
2472
  customServicePath: void 0
2294
2473
  };
2295
-
2296
2474
  //#endregion
2297
2475
  //#region src/services/ThemeService/ThemeServiceFactory.ts
2298
2476
  /**
2477
+ * ThemeServiceFactory
2478
+ *
2479
+ * DESIGN PATTERNS:
2480
+ * - Factory pattern for creating theme service instances
2481
+ * - Supports built-in CSS theme extraction and custom service loading
2482
+ *
2483
+ * CODING STANDARDS:
2484
+ * - Use async factory method for dynamic service loading
2485
+ * - Return typed results
2486
+ * - Throw descriptive errors with context
2487
+ *
2488
+ * AVOID:
2489
+ * - Synchronous file operations
2490
+ * - Hardcoded service paths
2491
+ */
2492
+ /**
2299
2493
  * Factory for creating theme service instances.
2300
2494
  *
2301
2495
  * Supports the built-in CSSThemeService and custom service implementations
@@ -2363,10 +2557,28 @@ var ThemeServiceFactory = class {
2363
2557
  }
2364
2558
  }
2365
2559
  };
2366
-
2367
2560
  //#endregion
2368
2561
  //#region src/services/ComponentRendererService/ComponentRendererService.ts
2369
2562
  /**
2563
+ * ComponentRendererService
2564
+ *
2565
+ * DESIGN PATTERNS:
2566
+ * - Service pattern for business logic encapsulation
2567
+ * - Service composition (uses BundlerService and ThemeService)
2568
+ * - Dependency injection for bundler service (allows custom implementations)
2569
+ * - HTML template generation with theme provider wrapping
2570
+ *
2571
+ * CODING STANDARDS:
2572
+ * - Use async/await for asynchronous operations
2573
+ * - Throw descriptive errors for error cases
2574
+ * - Keep methods focused and well-named
2575
+ * - Document complex logic with comments
2576
+ *
2577
+ * AVOID:
2578
+ * - Mixing concerns (keep focused on single domain)
2579
+ * - Direct tool implementation (services should be tool-agnostic)
2580
+ */
2581
+ /**
2370
2582
  * ComponentRendererService handles rendering React components to images.
2371
2583
  *
2372
2584
  * Uses BundlerService for building/serving components and ThemeService
@@ -2433,17 +2645,17 @@ var ComponentRendererService = class ComponentRendererService {
2433
2645
  async renderComponent(componentInfo, options = {}) {
2434
2646
  const { storyName = componentInfo.stories[0] || "Default", args = {}, darkMode = false, width = 1280, height = 800 } = options;
2435
2647
  try {
2436
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Rendering ${componentInfo.title} - ${storyName}`);
2648
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Rendering ${componentInfo.title} - ${storyName}`);
2437
2649
  await node_fs.promises.mkdir(this.tmpDir, { recursive: true });
2438
2650
  const designSystemConfig = this.themeService.getConfig();
2439
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Using theme provider: ${designSystemConfig.themeProvider}`);
2440
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Design system type: ${designSystemConfig.type}`);
2441
- if (!await this.themeService.validateThemeProvider()) __agiflowai_aicode_utils.log.warn(`[ComponentRendererService] Theme provider path may not exist: ${designSystemConfig.themeProvider}`);
2651
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Using theme provider: ${designSystemConfig.themeProvider}`);
2652
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Design system type: ${designSystemConfig.type}`);
2653
+ if (!await this.themeService.validateThemeProvider()) _agiflowai_aicode_utils.log.warn(`[ComponentRendererService] Theme provider path may not exist: ${designSystemConfig.themeProvider}`);
2442
2654
  const bundlerService = this.getBundlerService();
2443
2655
  let componentUrl;
2444
2656
  let htmlFilePath;
2445
2657
  if (bundlerService.isServerRunning()) {
2446
- __agiflowai_aicode_utils.log.info("[ComponentRendererService] Using dev server for fast rendering");
2658
+ _agiflowai_aicode_utils.log.info("[ComponentRendererService] Using dev server for fast rendering");
2447
2659
  try {
2448
2660
  const result = await bundlerService.serveComponent({
2449
2661
  componentPath: componentInfo.filePath,
@@ -2457,9 +2669,9 @@ var ComponentRendererService = class ComponentRendererService {
2457
2669
  });
2458
2670
  componentUrl = result.url;
2459
2671
  htmlFilePath = result.htmlFilePath;
2460
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Component served at: ${componentUrl}`);
2672
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Component served at: ${componentUrl}`);
2461
2673
  } catch (devServerError) {
2462
- __agiflowai_aicode_utils.log.warn(`[ComponentRendererService] Dev server failed, falling back to static build: ${devServerError instanceof Error ? devServerError.message : String(devServerError)}`);
2674
+ _agiflowai_aicode_utils.log.warn(`[ComponentRendererService] Dev server failed, falling back to static build: ${devServerError instanceof Error ? devServerError.message : String(devServerError)}`);
2463
2675
  const result = await bundlerService.prerenderComponent({
2464
2676
  componentPath: componentInfo.filePath,
2465
2677
  storyName,
@@ -2472,10 +2684,10 @@ var ComponentRendererService = class ComponentRendererService {
2472
2684
  });
2473
2685
  componentUrl = `file://${result.htmlFilePath}`;
2474
2686
  htmlFilePath = result.htmlFilePath;
2475
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML built to: ${htmlFilePath}`);
2687
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML built to: ${htmlFilePath}`);
2476
2688
  }
2477
2689
  } else {
2478
- __agiflowai_aicode_utils.log.info("[ComponentRendererService] No dev server running, using static build");
2690
+ _agiflowai_aicode_utils.log.info("[ComponentRendererService] No dev server running, using static build");
2479
2691
  const result = await bundlerService.prerenderComponent({
2480
2692
  componentPath: componentInfo.filePath,
2481
2693
  storyName,
@@ -2488,7 +2700,7 @@ var ComponentRendererService = class ComponentRendererService {
2488
2700
  });
2489
2701
  componentUrl = `file://${result.htmlFilePath}`;
2490
2702
  htmlFilePath = result.htmlFilePath;
2491
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML built to: ${htmlFilePath}`);
2703
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML built to: ${htmlFilePath}`);
2492
2704
  }
2493
2705
  const timestamp = Date.now();
2494
2706
  const imageName = `component-${componentInfo.title.split("/").pop()}-${timestamp}.png`;
@@ -2508,12 +2720,12 @@ var ComponentRendererService = class ComponentRendererService {
2508
2720
  thumbnailQuality: 80,
2509
2721
  base64: false
2510
2722
  });
2511
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Screenshot saved to: ${imagePath}`);
2723
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Screenshot saved to: ${imagePath}`);
2512
2724
  let html = "";
2513
2725
  if (htmlFilePath) {
2514
2726
  html = await node_fs.promises.readFile(htmlFilePath, "utf-8");
2515
- __agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML file kept at: ${htmlFilePath}`);
2516
- } else __agiflowai_aicode_utils.log.warn("[ComponentRendererService] No HTML file path available, returning empty HTML content");
2727
+ _agiflowai_aicode_utils.log.info(`[ComponentRendererService] HTML file kept at: ${htmlFilePath}`);
2728
+ } else _agiflowai_aicode_utils.log.warn("[ComponentRendererService] No HTML file path available, returning empty HTML content");
2517
2729
  return {
2518
2730
  imagePath,
2519
2731
  html,
@@ -2555,18 +2767,18 @@ var ComponentRendererService = class ComponentRendererService {
2555
2767
  }));
2556
2768
  for (const result of statResults) if (result.status === "fulfilled") componentFiles.push(result.value);
2557
2769
  const oldFiles = componentFiles.filter((f) => now - f.mtime > olderThanMs);
2558
- await Promise.all(oldFiles.map((file) => node_fs.promises.unlink(file.path).catch((err) => __agiflowai_aicode_utils.log.warn("[ComponentRendererService] Failed to delete file:", file.path, err))));
2770
+ await Promise.all(oldFiles.map((file) => node_fs.promises.unlink(file.path).catch((err) => _agiflowai_aicode_utils.log.warn("[ComponentRendererService] Failed to delete file:", file.path, err))));
2559
2771
  let deletedCount = oldFiles.length;
2560
2772
  const remainingFiles = componentFiles.filter((f) => now - f.mtime <= olderThanMs);
2561
2773
  if (remainingFiles.length > keepCount) {
2562
2774
  remainingFiles.sort((a, b) => a.mtime - b.mtime);
2563
2775
  const toDelete = remainingFiles.slice(0, remainingFiles.length - keepCount);
2564
- await Promise.all(toDelete.map((file) => node_fs.promises.unlink(file.path).catch((err) => __agiflowai_aicode_utils.log.warn("[ComponentRendererService] Failed to delete file:", file.path, err))));
2776
+ await Promise.all(toDelete.map((file) => node_fs.promises.unlink(file.path).catch((err) => _agiflowai_aicode_utils.log.warn("[ComponentRendererService] Failed to delete file:", file.path, err))));
2565
2777
  deletedCount += toDelete.length;
2566
2778
  }
2567
- if (deletedCount > 0) __agiflowai_aicode_utils.log.info(`[ComponentRendererService] Cleaned up ${deletedCount} temp files`);
2779
+ if (deletedCount > 0) _agiflowai_aicode_utils.log.info(`[ComponentRendererService] Cleaned up ${deletedCount} temp files`);
2568
2780
  } catch (error) {
2569
- __agiflowai_aicode_utils.log.error("[ComponentRendererService] Cleanup error:", error);
2781
+ _agiflowai_aicode_utils.log.error("[ComponentRendererService] Cleanup error:", error);
2570
2782
  }
2571
2783
  }
2572
2784
  /**
@@ -2580,11 +2792,10 @@ var ComponentRendererService = class ComponentRendererService {
2580
2792
  const bundlerService = this.getBundlerService();
2581
2793
  if (!bundlerService.isServerRunning()) await bundlerService.cleanup();
2582
2794
  } catch (error) {
2583
- __agiflowai_aicode_utils.log.error("[ComponentRendererService] Dispose error:", error);
2795
+ _agiflowai_aicode_utils.log.error("[ComponentRendererService] Dispose error:", error);
2584
2796
  }
2585
2797
  }
2586
2798
  };
2587
-
2588
2799
  //#endregion
2589
2800
  //#region src/services/GetUiComponentService/types.ts
2590
2801
  /**
@@ -2596,10 +2807,26 @@ const DEFAULT_GET_UI_COMPONENT_CONFIG = {
2596
2807
  defaultWidth: 1280,
2597
2808
  defaultHeight: 800
2598
2809
  };
2599
-
2600
2810
  //#endregion
2601
2811
  //#region src/services/GetUiComponentService/GetUiComponentService.ts
2602
2812
  /**
2813
+ * GetUiComponentService
2814
+ *
2815
+ * DESIGN PATTERNS:
2816
+ * - Service pattern for business logic encapsulation
2817
+ * - Single responsibility principle
2818
+ *
2819
+ * CODING STANDARDS:
2820
+ * - Use async/await for asynchronous operations
2821
+ * - Throw descriptive errors for error cases
2822
+ * - Keep methods focused and well-named
2823
+ * - Document complex logic with comments
2824
+ *
2825
+ * AVOID:
2826
+ * - Mixing concerns (keep focused on single domain)
2827
+ * - Direct tool implementation (services should be tool-agnostic)
2828
+ */
2829
+ /**
2603
2830
  * GetUiComponentService handles rendering UI component previews.
2604
2831
  *
2605
2832
  * Locates components in the stories index, renders them with app-specific
@@ -2651,7 +2878,7 @@ var GetUiComponentService = class {
2651
2878
  if (/javascript:|expression\(|url\(/i.test(input.selector)) throw new Error("selector contains potentially malicious content");
2652
2879
  }
2653
2880
  const { componentName, appPath, storyName = this.config.defaultStoryName, darkMode = this.config.defaultDarkMode } = input;
2654
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Starting for component: ${componentName}, appPath: ${appPath}, storyName: ${storyName}`);
2881
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Starting for component: ${componentName}, appPath: ${appPath}, storyName: ${storyName}`);
2655
2882
  const storiesIndex = this.storiesIndexFactory();
2656
2883
  let designSystemConfig;
2657
2884
  try {
@@ -2661,10 +2888,10 @@ var GetUiComponentService = class {
2661
2888
  }
2662
2889
  const componentInfo = storiesIndex.findComponentByName(componentName);
2663
2890
  if (!componentInfo) throw new Error(`Component "${componentName}" not found in stories index. Ensure the component has a .stories.tsx file and has been indexed.`);
2664
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Found component: ${componentInfo.title}`);
2891
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Found component: ${componentInfo.title}`);
2665
2892
  const validStoryName = this.resolveStoryName(storyName, componentInfo.stories);
2666
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Using theme provider: ${designSystemConfig.themeProvider}`);
2667
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Design system type: ${designSystemConfig.type}`);
2893
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Using theme provider: ${designSystemConfig.themeProvider}`);
2894
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Design system type: ${designSystemConfig.type}`);
2668
2895
  const renderer = this.rendererFactory(designSystemConfig, appPath);
2669
2896
  try {
2670
2897
  const renderResult = await renderer.renderComponent(componentInfo, {
@@ -2673,9 +2900,9 @@ var GetUiComponentService = class {
2673
2900
  height: this.config.defaultHeight,
2674
2901
  darkMode
2675
2902
  });
2676
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Component rendered to: ${renderResult.imagePath}`);
2903
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Component rendered to: ${renderResult.imagePath}`);
2677
2904
  const storyFileContent = await this.readStoryFile(componentInfo.filePath);
2678
- __agiflowai_aicode_utils.log.info("[GetUiComponentService] Completed successfully");
2905
+ _agiflowai_aicode_utils.log.info("[GetUiComponentService] Completed successfully");
2679
2906
  return {
2680
2907
  imagePath: renderResult.imagePath,
2681
2908
  format: "png",
@@ -2699,9 +2926,9 @@ var GetUiComponentService = class {
2699
2926
  */
2700
2927
  resolveStoryName(requestedStory, availableStories) {
2701
2928
  if (availableStories.includes(requestedStory)) return requestedStory;
2702
- __agiflowai_aicode_utils.log.warn(`[GetUiComponentService] Story "${requestedStory}" not found, available stories: ${availableStories.join(", ")}`);
2929
+ _agiflowai_aicode_utils.log.warn(`[GetUiComponentService] Story "${requestedStory}" not found, available stories: ${availableStories.join(", ")}`);
2703
2930
  const fallbackStory = availableStories[0] || "Default";
2704
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Using fallback story: ${fallbackStory}`);
2931
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Using fallback story: ${fallbackStory}`);
2705
2932
  return fallbackStory;
2706
2933
  }
2707
2934
  /**
@@ -2713,15 +2940,14 @@ var GetUiComponentService = class {
2713
2940
  async readStoryFile(filePath) {
2714
2941
  try {
2715
2942
  const content = await node_fs.promises.readFile(filePath, "utf-8");
2716
- __agiflowai_aicode_utils.log.info(`[GetUiComponentService] Story file read successfully (${content.length} chars)`);
2943
+ _agiflowai_aicode_utils.log.info(`[GetUiComponentService] Story file read successfully (${content.length} chars)`);
2717
2944
  return content;
2718
2945
  } catch (error) {
2719
- __agiflowai_aicode_utils.log.warn(`[GetUiComponentService] Warning: Could not read story file: ${error instanceof Error ? error.message : String(error)}`);
2946
+ _agiflowai_aicode_utils.log.warn(`[GetUiComponentService] Warning: Could not read story file: ${error instanceof Error ? error.message : String(error)}`);
2720
2947
  return `// Could not read file: ${filePath}\n// Error: ${error instanceof Error ? error.message : String(error)}`;
2721
2948
  }
2722
2949
  }
2723
2950
  };
2724
-
2725
2951
  //#endregion
2726
2952
  //#region src/tools/GetComponentVisualTool.ts
2727
2953
  /**
@@ -2823,7 +3049,6 @@ var GetComponentVisualTool = class GetComponentVisualTool {
2823
3049
  }
2824
3050
  }
2825
3051
  };
2826
-
2827
3052
  //#endregion
2828
3053
  //#region src/tools/ListAppComponentsTool.ts
2829
3054
  /**
@@ -2898,7 +3123,6 @@ var ListAppComponentsTool = class ListAppComponentsTool {
2898
3123
  }
2899
3124
  }
2900
3125
  };
2901
-
2902
3126
  //#endregion
2903
3127
  //#region src/tools/ListThemesTool.ts
2904
3128
  /**
@@ -2963,9 +3187,28 @@ var ListThemesTool = class ListThemesTool {
2963
3187
  }
2964
3188
  }
2965
3189
  };
2966
-
2967
3190
  //#endregion
2968
3191
  //#region src/tools/ListSharedComponentsTool.ts
3192
+ /**
3193
+ * ListSharedComponentsTool
3194
+ *
3195
+ * DESIGN PATTERNS:
3196
+ * - Tool pattern with getDefinition() and execute() methods
3197
+ * - Service delegation for business logic
3198
+ * - JSON Schema validation for inputs
3199
+ *
3200
+ * CODING STANDARDS:
3201
+ * - Implement Tool interface from ../types
3202
+ * - Use TOOL_NAME constant with snake_case (e.g., 'list_shared_components')
3203
+ * - Return CallToolResult with content array
3204
+ * - Handle errors with isError flag
3205
+ * - Delegate complex logic to services
3206
+ *
3207
+ * AVOID:
3208
+ * - Complex business logic in execute method
3209
+ * - Unhandled promise rejections
3210
+ * - Missing input validation
3211
+ */
2969
3212
  var ListSharedComponentsTool = class ListSharedComponentsTool {
2970
3213
  static TOOL_NAME = "list_shared_components";
2971
3214
  static PAGE_SIZE = 50;
@@ -3045,7 +3288,7 @@ var ListSharedComponentsTool = class ListSharedComponentsTool {
3045
3288
  }
3046
3289
  };
3047
3290
  if (hasMore) result.nextCursor = this.encodeCursor(offset + paginatedComponents.length);
3048
- __agiflowai_aicode_utils.log.info(`[ListSharedComponentsTool] Tags: [${filterTags.join(", ")}], Page ${Math.floor(offset / ListSharedComponentsTool.PAGE_SIZE) + 1}: Returned ${paginatedComponents.length} of ${totalComponents} total components (hasMore: ${hasMore})`);
3291
+ _agiflowai_aicode_utils.log.info(`[ListSharedComponentsTool] Tags: [${filterTags.join(", ")}], Page ${Math.floor(offset / ListSharedComponentsTool.PAGE_SIZE) + 1}: Returned ${paginatedComponents.length} of ${totalComponents} total components (hasMore: ${hasMore})`);
3049
3292
  return { content: [{
3050
3293
  type: "text",
3051
3294
  text: `${ListSharedComponentsTool.COMPONENT_REUSE_INSTRUCTION}\n\n${JSON.stringify(result, null, 2)}`
@@ -3061,9 +3304,28 @@ var ListSharedComponentsTool = class ListSharedComponentsTool {
3061
3304
  }
3062
3305
  }
3063
3306
  };
3064
-
3307
+ //#endregion
3308
+ //#region package.json
3309
+ var version = "0.0.13";
3310
+ //#endregion
3311
+ //#region src/metadata.ts
3312
+ const STYLE_SYSTEM_CLI_NAME = "style-system";
3313
+ const STYLE_SYSTEM_SERVER_NAME = "style-system";
3314
+ const STYLE_SYSTEM_VERSION = version;
3065
3315
  //#endregion
3066
3316
  //#region src/server/index.ts
3317
+ /**
3318
+ * MCP Server Setup
3319
+ *
3320
+ * DESIGN PATTERNS:
3321
+ * - Factory pattern for server creation
3322
+ * - Tool registration pattern
3323
+ *
3324
+ * CODING STANDARDS:
3325
+ * - Register all tools, resources, and prompts here
3326
+ * - Keep server setup modular and extensible
3327
+ * - Import tools from ../tools/ and register them in the handlers
3328
+ */
3067
3329
  const TOOL_CAPABILITIES_META_KEY = "agiflowai/capabilities";
3068
3330
  function withCapabilities(definition, capabilities) {
3069
3331
  return {
@@ -3074,10 +3336,10 @@ function withCapabilities(definition, capabilities) {
3074
3336
  }
3075
3337
  };
3076
3338
  }
3077
- function createServer(themePath = "packages/frontend/web-theme/src/agimon-theme.css") {
3078
- const server = new __modelcontextprotocol_sdk_server_index_js.Server({
3079
- name: "style-system-mcp",
3080
- version: "0.1.0"
3339
+ function createServer(themePath) {
3340
+ const server = new _modelcontextprotocol_sdk_server_index_js.Server({
3341
+ name: STYLE_SYSTEM_SERVER_NAME,
3342
+ version: STYLE_SYSTEM_VERSION
3081
3343
  }, {
3082
3344
  capabilities: { tools: {} },
3083
3345
  instructions: "Use this MCP when you work on the frontend or design. You can use this to list supported themes, get the correct tailwind classes supported by the repo, list design system components, and get visual + detailed implementation of components."
@@ -3087,7 +3349,7 @@ function createServer(themePath = "packages/frontend/web-theme/src/agimon-theme.
3087
3349
  const getComponentVisualTool = new GetComponentVisualTool();
3088
3350
  const listSharedComponentsTool = new ListSharedComponentsTool();
3089
3351
  const listAppComponentsTool = new ListAppComponentsTool();
3090
- server.setRequestHandler(__modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => {
3352
+ server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => {
3091
3353
  return { tools: [
3092
3354
  withCapabilities(listThemesTool.getDefinition(), [
3093
3355
  "themes",
@@ -3117,7 +3379,7 @@ function createServer(themePath = "packages/frontend/web-theme/src/agimon-theme.
3117
3379
  ])
3118
3380
  ] };
3119
3381
  });
3120
- server.setRequestHandler(__modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
3382
+ server.setRequestHandler(_modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
3121
3383
  const { name, arguments: args } = request.params;
3122
3384
  if (name === ListThemesTool.TOOL_NAME) return await listThemesTool.execute({});
3123
3385
  if (name === GetCSSClassesTool.TOOL_NAME) return await getCSSClassesTool.execute(args);
@@ -3134,10 +3396,25 @@ function createServer(themePath = "packages/frontend/web-theme/src/agimon-theme.
3134
3396
  });
3135
3397
  return server;
3136
3398
  }
3137
-
3138
3399
  //#endregion
3139
3400
  //#region src/transports/stdio.ts
3140
3401
  /**
3402
+ * STDIO Transport
3403
+ *
3404
+ * DESIGN PATTERNS:
3405
+ * - Transport handler pattern implementing TransportHandler interface
3406
+ * - Standard I/O based communication for CLI usage
3407
+ *
3408
+ * CODING STANDARDS:
3409
+ * - Initialize server and transport properly
3410
+ * - Handle cleanup on shutdown with stop() method
3411
+ * - Use async/await for all operations
3412
+ *
3413
+ * AVOID:
3414
+ * - Forgetting to close transport on shutdown
3415
+ * - Missing error handling for connection failures
3416
+ */
3417
+ /**
3141
3418
  * Stdio transport handler for MCP server
3142
3419
  * Used for command-line and direct integrations
3143
3420
  */
@@ -3148,9 +3425,9 @@ var StdioTransportHandler = class {
3148
3425
  this.server = server;
3149
3426
  }
3150
3427
  async start() {
3151
- this.transport = new __modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
3428
+ this.transport = new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
3152
3429
  await this.server.connect(this.transport);
3153
- __agiflowai_aicode_utils.log.info("style-system-mcp MCP server started on stdio");
3430
+ _agiflowai_aicode_utils.log.info(`${STYLE_SYSTEM_SERVER_NAME} MCP server started on stdio`);
3154
3431
  }
3155
3432
  async stop() {
3156
3433
  if (this.transport) {
@@ -3159,119 +3436,130 @@ var StdioTransportHandler = class {
3159
3436
  }
3160
3437
  }
3161
3438
  };
3162
-
3163
3439
  //#endregion
3164
- Object.defineProperty(exports, 'BaseBundlerService', {
3165
- enumerable: true,
3166
- get: function () {
3167
- return BaseBundlerService;
3168
- }
3440
+ Object.defineProperty(exports, "BaseBundlerService", {
3441
+ enumerable: true,
3442
+ get: function() {
3443
+ return BaseBundlerService;
3444
+ }
3445
+ });
3446
+ Object.defineProperty(exports, "BaseCSSClassesService", {
3447
+ enumerable: true,
3448
+ get: function() {
3449
+ return BaseCSSClassesService;
3450
+ }
3451
+ });
3452
+ Object.defineProperty(exports, "CSSClassesServiceFactory", {
3453
+ enumerable: true,
3454
+ get: function() {
3455
+ return CSSClassesServiceFactory;
3456
+ }
3169
3457
  });
3170
- Object.defineProperty(exports, 'BaseCSSClassesService', {
3171
- enumerable: true,
3172
- get: function () {
3173
- return BaseCSSClassesService;
3174
- }
3458
+ Object.defineProperty(exports, "ComponentRendererService", {
3459
+ enumerable: true,
3460
+ get: function() {
3461
+ return ComponentRendererService;
3462
+ }
3175
3463
  });
3176
- Object.defineProperty(exports, 'CSSClassesServiceFactory', {
3177
- enumerable: true,
3178
- get: function () {
3179
- return CSSClassesServiceFactory;
3180
- }
3464
+ Object.defineProperty(exports, "DEFAULT_STYLE_SYSTEM_CONFIG", {
3465
+ enumerable: true,
3466
+ get: function() {
3467
+ return DEFAULT_STYLE_SYSTEM_CONFIG;
3468
+ }
3181
3469
  });
3182
- Object.defineProperty(exports, 'ComponentRendererService', {
3183
- enumerable: true,
3184
- get: function () {
3185
- return ComponentRendererService;
3186
- }
3470
+ Object.defineProperty(exports, "GetCSSClassesTool", {
3471
+ enumerable: true,
3472
+ get: function() {
3473
+ return GetCSSClassesTool;
3474
+ }
3187
3475
  });
3188
- Object.defineProperty(exports, 'DEFAULT_STYLE_SYSTEM_CONFIG', {
3189
- enumerable: true,
3190
- get: function () {
3191
- return DEFAULT_STYLE_SYSTEM_CONFIG;
3192
- }
3476
+ Object.defineProperty(exports, "GetComponentVisualTool", {
3477
+ enumerable: true,
3478
+ get: function() {
3479
+ return GetComponentVisualTool;
3480
+ }
3193
3481
  });
3194
- Object.defineProperty(exports, 'GetCSSClassesTool', {
3195
- enumerable: true,
3196
- get: function () {
3197
- return GetCSSClassesTool;
3198
- }
3482
+ Object.defineProperty(exports, "ListAppComponentsTool", {
3483
+ enumerable: true,
3484
+ get: function() {
3485
+ return ListAppComponentsTool;
3486
+ }
3199
3487
  });
3200
- Object.defineProperty(exports, 'GetComponentVisualTool', {
3201
- enumerable: true,
3202
- get: function () {
3203
- return GetComponentVisualTool;
3204
- }
3488
+ Object.defineProperty(exports, "ListSharedComponentsTool", {
3489
+ enumerable: true,
3490
+ get: function() {
3491
+ return ListSharedComponentsTool;
3492
+ }
3205
3493
  });
3206
- Object.defineProperty(exports, 'ListAppComponentsTool', {
3207
- enumerable: true,
3208
- get: function () {
3209
- return ListAppComponentsTool;
3210
- }
3494
+ Object.defineProperty(exports, "ListThemesTool", {
3495
+ enumerable: true,
3496
+ get: function() {
3497
+ return ListThemesTool;
3498
+ }
3211
3499
  });
3212
- Object.defineProperty(exports, 'ListSharedComponentsTool', {
3213
- enumerable: true,
3214
- get: function () {
3215
- return ListSharedComponentsTool;
3216
- }
3500
+ Object.defineProperty(exports, "STYLE_SYSTEM_CLI_NAME", {
3501
+ enumerable: true,
3502
+ get: function() {
3503
+ return STYLE_SYSTEM_CLI_NAME;
3504
+ }
3217
3505
  });
3218
- Object.defineProperty(exports, 'ListThemesTool', {
3219
- enumerable: true,
3220
- get: function () {
3221
- return ListThemesTool;
3222
- }
3506
+ Object.defineProperty(exports, "STYLE_SYSTEM_VERSION", {
3507
+ enumerable: true,
3508
+ get: function() {
3509
+ return STYLE_SYSTEM_VERSION;
3510
+ }
3223
3511
  });
3224
- Object.defineProperty(exports, 'StdioTransportHandler', {
3225
- enumerable: true,
3226
- get: function () {
3227
- return StdioTransportHandler;
3228
- }
3512
+ Object.defineProperty(exports, "StdioTransportHandler", {
3513
+ enumerable: true,
3514
+ get: function() {
3515
+ return StdioTransportHandler;
3516
+ }
3229
3517
  });
3230
- Object.defineProperty(exports, 'StoriesIndexService', {
3231
- enumerable: true,
3232
- get: function () {
3233
- return StoriesIndexService;
3234
- }
3518
+ Object.defineProperty(exports, "StoriesIndexService", {
3519
+ enumerable: true,
3520
+ get: function() {
3521
+ return StoriesIndexService;
3522
+ }
3235
3523
  });
3236
- Object.defineProperty(exports, 'TailwindCSSClassesService', {
3237
- enumerable: true,
3238
- get: function () {
3239
- return TailwindCSSClassesService;
3240
- }
3524
+ Object.defineProperty(exports, "TailwindCSSClassesService", {
3525
+ enumerable: true,
3526
+ get: function() {
3527
+ return TailwindCSSClassesService;
3528
+ }
3241
3529
  });
3242
- Object.defineProperty(exports, 'ThemeService', {
3243
- enumerable: true,
3244
- get: function () {
3245
- return ThemeService;
3246
- }
3530
+ Object.defineProperty(exports, "ThemeService", {
3531
+ enumerable: true,
3532
+ get: function() {
3533
+ return ThemeService;
3534
+ }
3247
3535
  });
3248
- Object.defineProperty(exports, 'ViteReactBundlerService', {
3249
- enumerable: true,
3250
- get: function () {
3251
- return ViteReactBundlerService;
3252
- }
3536
+ Object.defineProperty(exports, "ViteReactBundlerService", {
3537
+ enumerable: true,
3538
+ get: function() {
3539
+ return ViteReactBundlerService;
3540
+ }
3253
3541
  });
3254
- Object.defineProperty(exports, '__toESM', {
3255
- enumerable: true,
3256
- get: function () {
3257
- return __toESM;
3258
- }
3542
+ Object.defineProperty(exports, "__toESM", {
3543
+ enumerable: true,
3544
+ get: function() {
3545
+ return __toESM;
3546
+ }
3259
3547
  });
3260
- Object.defineProperty(exports, 'createDefaultBundlerService', {
3261
- enumerable: true,
3262
- get: function () {
3263
- return createDefaultBundlerService;
3264
- }
3548
+ Object.defineProperty(exports, "createDefaultBundlerService", {
3549
+ enumerable: true,
3550
+ get: function() {
3551
+ return createDefaultBundlerService;
3552
+ }
3553
+ });
3554
+ Object.defineProperty(exports, "createServer", {
3555
+ enumerable: true,
3556
+ get: function() {
3557
+ return createServer;
3558
+ }
3265
3559
  });
3266
- Object.defineProperty(exports, 'createServer', {
3267
- enumerable: true,
3268
- get: function () {
3269
- return createServer;
3270
- }
3560
+ Object.defineProperty(exports, "getBundlerServiceFromConfig", {
3561
+ enumerable: true,
3562
+ get: function() {
3563
+ return getBundlerServiceFromConfig;
3564
+ }
3271
3565
  });
3272
- Object.defineProperty(exports, 'getBundlerServiceFromConfig', {
3273
- enumerable: true,
3274
- get: function () {
3275
- return getBundlerServiceFromConfig;
3276
- }
3277
- });