@agiflowai/aicode-utils 1.0.15 → 1.0.17

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/index.d.mts CHANGED
@@ -47,82 +47,332 @@ interface NxProjectJson {
47
47
  //#region src/types/index.d.ts
48
48
 
49
49
  /**
50
- * Toolkit configuration from toolkit.yaml
50
+ * Configuration for the scaffold-mcp mcp-serve command.
51
+ * Keys map 1-to-1 with CLI flags (camelCase).
52
+ */
53
+ interface McpServeConfig {
54
+ /** Transport type. Default: stdio. */
55
+ type?: 'stdio' | 'http' | 'sse';
56
+ /** Port for http/sse transport. Default: 3000. */
57
+ port?: number;
58
+ /** Host to bind for http/sse transport. Default: localhost. */
59
+ host?: string;
60
+ /** Enable admin tools such as generate-boilerplate. Default: false. */
61
+ adminEnable?: boolean;
62
+ /** Render prompts with skill front matter for Claude Code. Default: false. */
63
+ promptAsSkill?: boolean;
64
+ /** Fallback LLM tool used when scaffold-mcp needs AI assistance. */
65
+ fallbackTool?: string;
66
+ /** Config passed to the fallback LLM tool. */
67
+ fallbackToolConfig?: Record<string, unknown>;
68
+ /** Extra CLI args merged into the mcp-serve command (key → --key value). */
69
+ args?: Record<string, string | boolean | number>;
70
+ }
71
+ /**
72
+ * Configuration for a single hook method invocation.
73
+ * Keys use kebab-case matching the adapter/CLI convention.
74
+ */
75
+ interface HookMethodConfig {
76
+ /** LLM tool to invoke for this hook method (e.g. claude-code, gemini-cli). */
77
+ 'llm-tool'?: string;
78
+ /** Config object forwarded to the LLM tool (e.g. { model: 'gemini-2.0-flash' }). */
79
+ 'tool-config'?: Record<string, unknown>;
80
+ /** Fallback LLM tool used when the primary tool is unavailable. */
81
+ 'fallback-tool'?: string;
82
+ /** Config object forwarded to the fallback LLM tool. */
83
+ 'fallback-tool-config'?: Record<string, unknown>;
84
+ /** Extra CLI args appended to the generated hook command (key → --key value). */
85
+ args?: Record<string, string | boolean | number>;
86
+ }
87
+ /**
88
+ * Per-method configuration for a specific agent.
89
+ */
90
+ interface HookAgentConfig {
91
+ /** Config applied when the agent invokes the PreToolUse hook. */
92
+ preToolUse?: HookMethodConfig;
93
+ /** Config applied when the agent invokes the PostToolUse hook. */
94
+ postToolUse?: HookMethodConfig;
95
+ /** Config applied when the agent invokes the Stop hook. */
96
+ stop?: HookMethodConfig;
97
+ /** Config applied when the agent invokes the UserPromptSubmit hook. */
98
+ userPromptSubmit?: HookMethodConfig;
99
+ /** Config applied when the agent invokes the TaskCompleted hook. */
100
+ taskCompleted?: HookMethodConfig;
101
+ }
102
+ /**
103
+ * Hook configuration keyed by agent name.
104
+ */
105
+ interface HookConfig {
106
+ /** Hook config for Claude Code agent. */
107
+ 'claude-code'?: HookAgentConfig;
108
+ /** Hook config for Gemini CLI agent. */
109
+ 'gemini-cli'?: HookAgentConfig;
110
+ }
111
+ /**
112
+ * Top-level scaffold-mcp configuration block.
113
+ */
114
+ interface ScaffoldMcpConfig {
115
+ /** Defaults for the `scaffold-mcp mcp-serve` command. */
116
+ 'mcp-serve'?: McpServeConfig;
117
+ /** Hook method defaults keyed by agent name. */
118
+ hook?: HookConfig;
119
+ }
120
+ /**
121
+ * Configuration for the architect-mcp mcp-serve command.
122
+ * Keys map 1-to-1 with CLI flags (camelCase).
123
+ */
124
+ interface ArchitectMcpServeConfig {
125
+ /** Transport type. Default: stdio. */
126
+ type?: 'stdio' | 'http' | 'sse';
127
+ /** Port for http/sse transport. Default: 3000. */
128
+ port?: number;
129
+ /** Host to bind for http/sse transport. Default: localhost. */
130
+ host?: string;
131
+ /** Enable admin tools such as add-design-pattern and add-rule. Default: false. */
132
+ adminEnable?: boolean;
133
+ /** Fallback LLM tool used for both design-pattern and review operations. */
134
+ fallbackTool?: string;
135
+ /** Config passed to the fallback LLM tool. */
136
+ fallbackToolConfig?: Record<string, unknown>;
137
+ /** LLM tool used specifically for get-file-design-pattern analysis. */
138
+ designPatternTool?: string;
139
+ /** Config passed to the design-pattern LLM tool. */
140
+ designPatternToolConfig?: Record<string, unknown>;
141
+ /** LLM tool used specifically for review-code-change analysis. */
142
+ reviewTool?: string;
143
+ /** Config passed to the review LLM tool. */
144
+ reviewToolConfig?: Record<string, unknown>;
145
+ /** Extra CLI args merged into the mcp-serve command (key → --key value). */
146
+ args?: Record<string, string | boolean | number>;
147
+ }
148
+ /**
149
+ * Configuration for a single architect-mcp hook method invocation.
150
+ * Keys use kebab-case matching the adapter/CLI convention.
151
+ */
152
+ interface ArchitectHookMethodConfig {
153
+ /** LLM tool to invoke for this hook method. */
154
+ 'llm-tool'?: string;
155
+ /** Config object forwarded to the LLM tool. */
156
+ 'tool-config'?: Record<string, unknown>;
157
+ /** Extra CLI args appended to the generated hook command (key → --key value). */
158
+ args?: Record<string, string | boolean | number>;
159
+ }
160
+ /**
161
+ * Per-method configuration for a specific agent (architect-mcp).
162
+ * Only preToolUse and postToolUse are supported.
163
+ */
164
+ interface ArchitectHookAgentConfig {
165
+ /** Config applied when the agent invokes the PreToolUse hook. */
166
+ preToolUse?: ArchitectHookMethodConfig;
167
+ /** Config applied when the agent invokes the PostToolUse hook. */
168
+ postToolUse?: ArchitectHookMethodConfig;
169
+ }
170
+ /**
171
+ * Hook configuration keyed by agent name (architect-mcp).
172
+ */
173
+ interface ArchitectHookConfig {
174
+ /** Hook config for Claude Code agent. */
175
+ 'claude-code'?: ArchitectHookAgentConfig;
176
+ /** Hook config for Gemini CLI agent. */
177
+ 'gemini-cli'?: ArchitectHookAgentConfig;
178
+ }
179
+ /**
180
+ * Top-level architect-mcp configuration block.
181
+ */
182
+ interface ArchitectMcpConfig {
183
+ /** Defaults for the `architect-mcp mcp-serve` command. */
184
+ 'mcp-serve'?: ArchitectMcpServeConfig;
185
+ /** Hook method defaults keyed by agent name. */
186
+ hook?: ArchitectHookConfig;
187
+ }
188
+ /**
189
+ * Toolkit configuration from .toolkit/settings.yaml (or legacy toolkit.yaml)
51
190
  */
52
191
  interface ToolkitConfig {
192
+ /** Config schema version (e.g. '1.0'). */
53
193
  version?: string;
194
+ /** Path to the scaffold templates directory, relative to workspace root. */
54
195
  templatesPath?: string;
196
+ /** Project structure type: monolith (single app) or monorepo (multiple packages). */
55
197
  projectType?: 'monolith' | 'monorepo';
198
+ /** Active template name (monolith only — monorepo reads from project.json). */
56
199
  sourceTemplate?: string;
200
+ /** scaffold-mcp server and hook configuration. */
201
+ 'scaffold-mcp'?: ScaffoldMcpConfig;
202
+ /** architect-mcp server and hook configuration. */
203
+ 'architect-mcp'?: ArchitectMcpConfig;
57
204
  }
58
205
  /**
59
206
  * Project configuration from project.json
60
207
  */
61
208
  interface ProjectConfig {
209
+ /** Package/project name as declared in project.json. */
62
210
  name: string;
211
+ /** Root directory of the project, relative to workspace root. */
63
212
  root: string;
213
+ /** Template this project was scaffolded from. */
64
214
  sourceTemplate?: string;
215
+ /** Project type as declared in project.json (e.g. 'application' or 'library'). */
65
216
  projectType?: string;
66
217
  }
67
218
  /**
68
219
  * Scaffold template include configuration
69
220
  */
70
221
  interface ParsedInclude {
222
+ /** Absolute path of the source template file. */
71
223
  sourcePath: string;
224
+ /** Absolute path of the destination file in the target directory. */
72
225
  targetPath: string;
226
+ /** Conditions that must be satisfied for this include to be applied. */
73
227
  conditions?: Record<string, string>;
74
228
  }
75
229
  /**
76
230
  * Result of a scaffold operation
77
231
  */
78
232
  interface ScaffoldResult {
233
+ /** Whether the scaffold operation completed without errors. */
79
234
  success: boolean;
235
+ /** Human-readable summary of the operation outcome. */
80
236
  message: string;
237
+ /** Non-fatal warnings collected during the operation. */
81
238
  warnings?: string[];
239
+ /** Paths of files that were newly created. */
82
240
  createdFiles?: string[];
241
+ /** Paths of files that already existed and were not overwritten. */
83
242
  existingFiles?: string[];
84
243
  }
244
+ /**
245
+ * Minimal stat result returned by IFileSystemService.stat.
246
+ */
247
+ interface FileStat {
248
+ /**
249
+ * @returns True when the path is a directory.
250
+ */
251
+ isDirectory(): boolean;
252
+ /**
253
+ * @returns True when the path is a regular file.
254
+ */
255
+ isFile(): boolean;
256
+ }
85
257
  /**
86
258
  * Abstract interface for file system operations
87
259
  */
88
260
  interface IFileSystemService {
261
+ /**
262
+ * Check whether a path exists on disk.
263
+ * @param path - Absolute path to check.
264
+ * @returns True when the path exists.
265
+ */
89
266
  pathExists(path: string): Promise<boolean>;
267
+ /**
268
+ * Read a file as text.
269
+ * @param path - Absolute path of the file.
270
+ * @param encoding - Character encoding (default: utf-8).
271
+ * @returns File contents as a string.
272
+ */
90
273
  readFile(path: string, encoding?: BufferEncoding): Promise<string>;
91
- readJson(path: string): Promise<any>;
274
+ /**
275
+ * Read and parse a JSON file. Returns unknown — callers must narrow the type.
276
+ * @param path - Absolute path of the JSON file.
277
+ * @returns Parsed value with type unknown.
278
+ */
279
+ readJson(path: string): Promise<unknown>;
280
+ /**
281
+ * Write text content to a file.
282
+ * @param path - Absolute path of the target file.
283
+ * @param content - Text to write.
284
+ * @param encoding - Character encoding (default: utf-8).
285
+ * @returns Promise that resolves when the file is written.
286
+ */
92
287
  writeFile(path: string, content: string, encoding?: BufferEncoding): Promise<void>;
288
+ /**
289
+ * Create a directory and all parent directories.
290
+ * @param path - Absolute path of the directory to create.
291
+ * @returns Promise that resolves when the directory exists.
292
+ */
93
293
  ensureDir(path: string): Promise<void>;
294
+ /**
295
+ * Copy a file or directory from src to dest.
296
+ * @param src - Absolute source path.
297
+ * @param dest - Absolute destination path.
298
+ * @returns Promise that resolves when the copy is complete.
299
+ */
94
300
  copy(src: string, dest: string): Promise<void>;
301
+ /**
302
+ * List the entries of a directory.
303
+ * @param path - Absolute path of the directory.
304
+ * @returns Array of entry names (not full paths).
305
+ */
95
306
  readdir(path: string): Promise<string[]>;
96
- stat(path: string): Promise<{
97
- isDirectory(): boolean;
98
- isFile(): boolean;
99
- }>;
307
+ /**
308
+ * Return stat info for a path.
309
+ * @param path - Absolute path to stat.
310
+ * @returns FileStat with isDirectory and isFile helpers.
311
+ */
312
+ stat(path: string): Promise<FileStat>;
100
313
  }
101
314
  /**
102
315
  * Abstract interface for variable replacement in templates
103
316
  */
104
317
  interface IVariableReplacementService {
105
- processFilesForVariableReplacement(dirPath: string, variables: Record<string, any>): Promise<void>;
106
- replaceVariablesInFile(filePath: string, variables: Record<string, any>): Promise<void>;
318
+ /**
319
+ * Walk dirPath and apply variable substitution to every non-binary file.
320
+ * @param dirPath - Directory to process recursively.
321
+ * @param variables - Key/value pairs used for substitution.
322
+ * @returns Promise that resolves when all files have been processed.
323
+ */
324
+ processFilesForVariableReplacement(dirPath: string, variables: Record<string, unknown>): Promise<void>;
325
+ /**
326
+ * Apply variable substitution to a single file.
327
+ * @param filePath - File to process.
328
+ * @param variables - Key/value pairs used for substitution.
329
+ * @returns Promise that resolves when the file has been processed.
330
+ */
331
+ replaceVariablesInFile(filePath: string, variables: Record<string, unknown>): Promise<void>;
332
+ /**
333
+ * Checks if a file should be treated as a binary (non-text) file.
334
+ * @param filePath - Path to check.
335
+ * @returns True if the file is binary.
336
+ */
107
337
  isBinaryFile(filePath: string): boolean;
108
338
  }
109
339
  /**
110
- * Context object passed to generator functions
340
+ * Context object passed to generator functions.
341
+ * Bundles all dependencies needed to produce scaffold output.
111
342
  */
112
343
  interface GeneratorContext {
113
- variables: Record<string, any>;
114
- config: any;
344
+ /** Template variables resolved for the current scaffold operation. */
345
+ variables: Record<string, unknown>;
346
+ /** Raw scaffold configuration loaded from scaffold.yaml. */
347
+ config: unknown;
348
+ /** Absolute path of the directory where output files will be written. */
115
349
  targetPath: string;
350
+ /** Absolute path of the source template directory. */
116
351
  templatePath: string;
352
+ /** File-system abstraction used for all I/O inside generators. */
117
353
  fileSystem: IFileSystemService;
118
- scaffoldConfigLoader: any;
354
+ /** Loader for scaffold config files — typed as unknown to avoid circular deps. */
355
+ scaffoldConfigLoader: unknown;
356
+ /** Variable-replacement service injected to avoid circular imports. */
119
357
  variableReplacer: IVariableReplacementService;
120
- ScaffoldProcessingService: any;
358
+ /** ScaffoldProcessingService constructor — passed to avoid circular imports. */
359
+ ScaffoldProcessingService: new (...args: unknown[]) => unknown;
360
+ /**
361
+ * Return the workspace root path.
362
+ * @returns Absolute path of the workspace root.
363
+ */
121
364
  getRootPath: () => string;
365
+ /**
366
+ * Return the absolute path of a project relative to the workspace root.
367
+ * @param projectPath - Project path relative to the workspace root.
368
+ * @returns Absolute path of the project.
369
+ */
122
370
  getProjectPath: (projectPath: string) => string;
123
371
  }
124
372
  /**
125
- * Type definition for generator functions
373
+ * Type definition for generator functions.
374
+ * @param context - The generator context bundling all scaffold dependencies.
375
+ * @returns A promise resolving to the scaffold result.
126
376
  */
127
377
  type GeneratorFunction = (context: GeneratorContext) => Promise<ScaffoldResult>;
128
378
  //#endregion
@@ -254,16 +504,31 @@ declare class ScaffoldProcessingService {
254
504
  declare class TemplatesManagerService {
255
505
  private static SCAFFOLD_CONFIG_FILE;
256
506
  private static TEMPLATES_FOLDER;
507
+ private static TOOLKIT_FOLDER;
508
+ private static SETTINGS_FILE;
509
+ private static SETTINGS_LOCAL_FILE;
257
510
  private static TOOLKIT_CONFIG_FILE;
511
+ /**
512
+ * Recursively merge two plain objects. Primitive and array values in `local`
513
+ * replace those in `base`; plain-object values are merged recursively.
514
+ */
515
+ private static deepMerge;
516
+ /**
517
+ * Deep-merge two ToolkitConfig objects. Plain-object values are merged
518
+ * recursively; primitives and arrays in `local` replace those in `base`.
519
+ * This allows settings.local.yaml to override a single leaf key (e.g.
520
+ * scaffold-mcp.mcp-serve.fallbackTool) without wiping sibling keys.
521
+ */
522
+ private static mergeToolkitConfigs;
258
523
  /**
259
524
  * Find the templates directory by searching upwards from the starting path.
260
525
  *
261
526
  * Algorithm:
262
527
  * 1. Start from the provided path (default: current working directory)
263
528
  * 2. Search upwards to find the workspace root (where .git exists or filesystem root)
264
- * 3. Check if toolkit.yaml exists at workspace root
265
- * - If yes, read templatesPath from toolkit.yaml
266
- * - If no, default to 'templates' folder in workspace root
529
+ * 3. Read toolkit config (checks .toolkit/settings.yaml, then toolkit.yaml)
530
+ * - If config has templatesPath, use it
531
+ * - If no config, default to 'templates' folder in workspace root
267
532
  * 4. Verify the templates directory exists
268
533
  *
269
534
  * @param startPath - The path to start searching from (defaults to process.cwd())
@@ -302,21 +567,32 @@ declare class TemplatesManagerService {
302
567
  */
303
568
  static getTemplatesFolderName(): string;
304
569
  /**
305
- * Read toolkit.yaml configuration from workspace root
570
+ * Read toolkit configuration from workspace root.
571
+ *
572
+ * Priority order:
573
+ * 1. .toolkit/settings.yaml (new location)
574
+ * 2. Shallow-merge .toolkit/settings.local.yaml over settings.yaml if present
575
+ * 3. Fallback to root toolkit.yaml (deprecated, backward-compat)
306
576
  *
307
577
  * @param startPath - The path to start searching from (defaults to process.cwd())
308
578
  * @returns The toolkit configuration object or null if not found
309
579
  */
310
580
  static readToolkitConfig(startPath?: string): Promise<ToolkitConfig | null>;
311
581
  /**
312
- * Read toolkit.yaml configuration from workspace root (sync)
582
+ * Read toolkit configuration from workspace root (sync).
583
+ *
584
+ * Priority order:
585
+ * 1. .toolkit/settings.yaml (new location)
586
+ * 2. Shallow-merge .toolkit/settings.local.yaml over settings.yaml if present
587
+ * 3. Fallback to root toolkit.yaml (deprecated, backward-compat)
313
588
  *
314
589
  * @param startPath - The path to start searching from (defaults to process.cwd())
315
590
  * @returns The toolkit configuration object or null if not found
316
591
  */
317
592
  static readToolkitConfigSync(startPath?: string): ToolkitConfig | null;
318
593
  /**
319
- * Write toolkit.yaml configuration to workspace root
594
+ * Write toolkit configuration to .toolkit/settings.yaml.
595
+ * Creates the .toolkit directory if it does not exist.
320
596
  *
321
597
  * @param config - The toolkit configuration to write
322
598
  * @param startPath - The path to start searching from (defaults to process.cwd())
@@ -680,4 +956,4 @@ interface ProjectTypeDetectionResult {
680
956
  */
681
957
  declare function detectProjectType(workspaceRoot: string): Promise<ProjectTypeDetectionResult>;
682
958
  //#endregion
683
- export { ConfigSource, GeneratorContext, GeneratorFunction, type GitHubDirectoryEntry, IFileSystemService, IVariableReplacementService, NxProjectJson, type ParsedGitHubUrl, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, cloneRepository, cloneSubdirectory, copy, detectProjectType, ensureDir, fetchGitHubDirectoryContents, findWorkspaceRoot, generateStableId, gitInit, icons, log, logger, messages, mkdir, mkdirSync, move, parseGitHubUrl, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, sections, stat, statSync, writeFile, writeFileSync };
959
+ export { ArchitectHookAgentConfig, ArchitectHookConfig, ArchitectHookMethodConfig, ArchitectMcpConfig, ArchitectMcpServeConfig, ConfigSource, FileStat, GeneratorContext, GeneratorFunction, type GitHubDirectoryEntry, HookAgentConfig, HookConfig, HookMethodConfig, IFileSystemService, IVariableReplacementService, McpServeConfig, type NxProjectJson, type ParsedGitHubUrl, ParsedInclude, ProjectConfig, ProjectConfigResolver, type ProjectConfigResult, ProjectFinderService, ProjectType, ScaffoldMcpConfig, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, cloneRepository, cloneSubdirectory, copy, detectProjectType, ensureDir, fetchGitHubDirectoryContents, findWorkspaceRoot, generateStableId, gitInit, icons, log, logger, messages, mkdir, mkdirSync, move, parseGitHubUrl, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, sections, stat, statSync, writeFile, writeFileSync };