@utilarium/cardigantime 0.0.24-dev.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.
Files changed (89) hide show
  1. package/LICENSE +65 -0
  2. package/README.md +398 -0
  3. package/dist/cardigantime.cjs +2169 -0
  4. package/dist/cardigantime.cjs.map +1 -0
  5. package/dist/cardigantime.d.ts +92 -0
  6. package/dist/cardigantime.js +198 -0
  7. package/dist/cardigantime.js.map +1 -0
  8. package/dist/config/executable-security.d.ts +32 -0
  9. package/dist/config/format-detector.d.ts +59 -0
  10. package/dist/configure.d.ts +55 -0
  11. package/dist/configure.js +125 -0
  12. package/dist/configure.js.map +1 -0
  13. package/dist/constants.d.ts +25 -0
  14. package/dist/constants.js +38 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/discovery/discoverer.d.ts +62 -0
  17. package/dist/discovery/hierarchical-modes.d.ts +64 -0
  18. package/dist/discovery/index.d.ts +15 -0
  19. package/dist/discovery/patterns.d.ts +77 -0
  20. package/dist/discovery/root-detection.d.ts +100 -0
  21. package/dist/discovery/traversal-security.d.ts +106 -0
  22. package/dist/env/errors.d.ts +18 -0
  23. package/dist/env/index.d.ts +7 -0
  24. package/dist/env/naming.d.ts +38 -0
  25. package/dist/env/parser.d.ts +61 -0
  26. package/dist/env/reader.d.ts +45 -0
  27. package/dist/env/resolver.d.ts +25 -0
  28. package/dist/env/schema-utils.d.ts +33 -0
  29. package/dist/env/types.d.ts +43 -0
  30. package/dist/error/ArgumentError.d.ts +31 -0
  31. package/dist/error/ArgumentError.js +48 -0
  32. package/dist/error/ArgumentError.js.map +1 -0
  33. package/dist/error/ConfigParseError.d.ts +26 -0
  34. package/dist/error/ConfigurationError.d.ts +21 -0
  35. package/dist/error/ConfigurationError.js +46 -0
  36. package/dist/error/ConfigurationError.js.map +1 -0
  37. package/dist/error/FileSystemError.d.ts +30 -0
  38. package/dist/error/FileSystemError.js +58 -0
  39. package/dist/error/FileSystemError.js.map +1 -0
  40. package/dist/error/index.d.ts +4 -0
  41. package/dist/mcp/discovery.d.ts +105 -0
  42. package/dist/mcp/errors.d.ts +75 -0
  43. package/dist/mcp/index.d.ts +22 -0
  44. package/dist/mcp/integration.d.ts +184 -0
  45. package/dist/mcp/parser.d.ts +141 -0
  46. package/dist/mcp/resolver.d.ts +165 -0
  47. package/dist/mcp/tools/check-config-types.d.ts +208 -0
  48. package/dist/mcp/tools/check-config.d.ts +85 -0
  49. package/dist/mcp/tools/index.d.ts +12 -0
  50. package/dist/mcp/types.d.ts +210 -0
  51. package/dist/parsers/index.d.ts +25 -0
  52. package/dist/parsers/javascript-parser.d.ts +12 -0
  53. package/dist/parsers/json-parser.d.ts +6 -0
  54. package/dist/parsers/typescript-parser.d.ts +15 -0
  55. package/dist/parsers/yaml-parser.d.ts +6 -0
  56. package/dist/read.d.ts +56 -0
  57. package/dist/read.js +653 -0
  58. package/dist/read.js.map +1 -0
  59. package/dist/security/audit-logger.d.ts +135 -0
  60. package/dist/security/cli-validator.d.ts +73 -0
  61. package/dist/security/config-validator.d.ts +95 -0
  62. package/dist/security/defaults.d.ts +17 -0
  63. package/dist/security/index.d.ts +14 -0
  64. package/dist/security/numeric-guard.d.ts +111 -0
  65. package/dist/security/path-guard.d.ts +53 -0
  66. package/dist/security/profiles.d.ts +127 -0
  67. package/dist/security/security-validator.d.ts +109 -0
  68. package/dist/security/string-guard.d.ts +92 -0
  69. package/dist/security/types.d.ts +126 -0
  70. package/dist/security/zod-secure-enum.d.ts +20 -0
  71. package/dist/security/zod-secure-number.d.ts +39 -0
  72. package/dist/security/zod-secure-path.d.ts +24 -0
  73. package/dist/security/zod-secure-string.d.ts +38 -0
  74. package/dist/types.d.ts +584 -0
  75. package/dist/types.js +56 -0
  76. package/dist/types.js.map +1 -0
  77. package/dist/util/hierarchical.d.ts +136 -0
  78. package/dist/util/hierarchical.js +436 -0
  79. package/dist/util/hierarchical.js.map +1 -0
  80. package/dist/util/schema-defaults.d.ts +80 -0
  81. package/dist/util/schema-defaults.js +118 -0
  82. package/dist/util/schema-defaults.js.map +1 -0
  83. package/dist/util/storage.d.ts +31 -0
  84. package/dist/util/storage.js +154 -0
  85. package/dist/util/storage.js.map +1 -0
  86. package/dist/validate.d.ts +113 -0
  87. package/dist/validate.js +260 -0
  88. package/dist/validate.js.map +1 -0
  89. package/package.json +84 -0
@@ -0,0 +1,584 @@
1
+ import { Command } from 'commander';
2
+ import { ZodObject, z } from 'zod';
3
+ import { SecurityValidationConfig } from './security/types';
4
+ export type { MCPConfigSource, FileConfigSource, ConfigSource, ResolvedConfig, MCPInvocationContext, } from './mcp/types';
5
+ /**
6
+ * Available features that can be enabled in Cardigantime.
7
+ * Currently supports:
8
+ * - 'config': Configuration file reading and validation
9
+ * - 'hierarchical': Hierarchical configuration discovery and layering
10
+ */
11
+ export type Feature = 'config' | 'hierarchical';
12
+ /**
13
+ * Supported configuration file formats.
14
+ *
15
+ * - 'yaml': YAML format (.yaml, .yml)
16
+ * - 'json': JSON format (.json)
17
+ * - 'javascript': JavaScript module (.js, .mjs, .cjs)
18
+ * - 'typescript': TypeScript module (.ts, .mts, .cts)
19
+ */
20
+ export declare enum ConfigFormat {
21
+ YAML = "yaml",
22
+ JSON = "json",
23
+ JavaScript = "javascript",
24
+ TypeScript = "typescript"
25
+ }
26
+ /**
27
+ * Interface for format-specific configuration parsers.
28
+ * Each parser is responsible for loading and parsing configuration from a specific format.
29
+ *
30
+ * @template T - The type of the parsed configuration object
31
+ */
32
+ export interface ConfigParser<T = unknown> {
33
+ /** The format this parser handles */
34
+ format: ConfigFormat;
35
+ /** File extensions this parser supports (e.g., ['.yaml', '.yml']) */
36
+ extensions: string[];
37
+ /**
38
+ * Parses configuration content from a file.
39
+ *
40
+ * @param content - The raw file content as a string
41
+ * @param filePath - The absolute path to the configuration file
42
+ * @returns Promise resolving to the parsed configuration object
43
+ * @throws {Error} When parsing fails or content is invalid
44
+ */
45
+ parse(content: string, filePath: string): Promise<T>;
46
+ }
47
+ /**
48
+ * Metadata about where a configuration value came from.
49
+ * Used for tracking configuration sources and debugging.
50
+ *
51
+ * @deprecated Use FileConfigSource from ./mcp/types instead.
52
+ * This type is kept for backward compatibility and will be removed in a future version.
53
+ */
54
+ export interface LegacyConfigSource {
55
+ /** The format of the configuration file */
56
+ format: ConfigFormat;
57
+ /** Absolute path to the configuration file */
58
+ filePath: string;
59
+ /** The parsed configuration content */
60
+ content: unknown;
61
+ /** Timestamp when the configuration was loaded */
62
+ loadedAt: Date;
63
+ }
64
+ /**
65
+ * Defines how array fields should be merged in hierarchical configurations.
66
+ *
67
+ * - 'override': Higher precedence arrays completely replace lower precedence arrays (default)
68
+ * - 'append': Higher precedence array elements are appended to lower precedence arrays
69
+ * - 'prepend': Higher precedence array elements are prepended to lower precedence arrays
70
+ */
71
+ export type ArrayOverlapMode = 'override' | 'append' | 'prepend';
72
+ /**
73
+ * Configuration for how fields should be merged in hierarchical configurations.
74
+ * Maps field names (using dot notation) to their overlap behavior.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const fieldOverlaps: FieldOverlapOptions = {
79
+ * 'features': 'append', // features arrays will be combined by appending
80
+ * 'api.endpoints': 'prepend', // nested endpoint arrays will be combined by prepending
81
+ * 'excludePatterns': 'override' // excludePatterns arrays will replace each other (default behavior)
82
+ * };
83
+ * ```
84
+ */
85
+ export interface FieldOverlapOptions {
86
+ [fieldPath: string]: ArrayOverlapMode;
87
+ }
88
+ /**
89
+ * Configuration for resolving relative paths in configuration values.
90
+ * Paths specified in these fields will be resolved relative to the configuration file's directory.
91
+ */
92
+ export interface PathResolutionOptions {
93
+ /** Array of field names (using dot notation) that contain paths to be resolved */
94
+ pathFields?: string[];
95
+ /** Array of field names whose array elements should all be resolved as paths */
96
+ resolvePathArray?: string[];
97
+ }
98
+ /**
99
+ * Default configuration options for Cardigantime.
100
+ * These define the basic behavior of configuration loading.
101
+ */
102
+ export interface DefaultOptions {
103
+ /** Directory path where configuration files are located */
104
+ configDirectory: string;
105
+ /** Name of the configuration file (e.g., 'config.yaml', 'app.yml') */
106
+ configFile: string;
107
+ /** Whether the configuration directory must exist. If true, throws error if directory doesn't exist */
108
+ isRequired: boolean;
109
+ /** File encoding for reading configuration files (e.g., 'utf8', 'ascii') */
110
+ encoding: string;
111
+ /** Configuration for resolving relative paths in configuration values */
112
+ pathResolution?: PathResolutionOptions;
113
+ /**
114
+ * Configuration for how array fields should be merged in hierarchical mode.
115
+ * Only applies when the 'hierarchical' feature is enabled.
116
+ * If not specified, all arrays use 'override' behavior (default).
117
+ */
118
+ fieldOverlaps?: FieldOverlapOptions;
119
+ /**
120
+ * Security validation configuration (optional, uses development profile by default).
121
+ * Enable security features to validate CLI arguments and config file values.
122
+ */
123
+ security?: Partial<SecurityValidationConfig>;
124
+ /**
125
+ * Optional source metadata for tracking where configuration came from.
126
+ * Populated automatically when configuration is loaded.
127
+ *
128
+ * @deprecated Use the new ConfigSource union type from ./mcp/types instead.
129
+ */
130
+ source?: LegacyConfigSource;
131
+ /**
132
+ * Allow executable configuration files (JavaScript/TypeScript).
133
+ *
134
+ * **SECURITY WARNING**: Executable configs run with full Node.js permissions
135
+ * in the same process as your application. Only enable this if you trust
136
+ * the configuration files being loaded.
137
+ *
138
+ * When disabled (default), JavaScript and TypeScript config files will be
139
+ * ignored with a warning message.
140
+ *
141
+ * @default false
142
+ */
143
+ allowExecutableConfig?: boolean;
144
+ }
145
+ /**
146
+ * Complete options object passed to Cardigantime functions.
147
+ * Combines defaults, features, schema shape, and logger.
148
+ *
149
+ * @template T - The Zod schema shape type for configuration validation
150
+ */
151
+ export interface Options<T extends z.ZodRawShape> {
152
+ /** Default configuration options */
153
+ defaults: DefaultOptions;
154
+ /** Array of enabled features */
155
+ features: Feature[];
156
+ /** Zod schema shape for validating user configuration */
157
+ configShape: T;
158
+ /** Logger instance for debugging and error reporting */
159
+ logger: Logger;
160
+ }
161
+ /**
162
+ * Logger interface for Cardigantime's internal logging.
163
+ * Compatible with popular logging libraries like Winston, Bunyan, etc.
164
+ */
165
+ export interface Logger {
166
+ /** Debug-level logging for detailed troubleshooting information */
167
+ debug: (message: string, ...args: any[]) => void;
168
+ /** Info-level logging for general information */
169
+ info: (message: string, ...args: any[]) => void;
170
+ /** Warning-level logging for non-critical issues */
171
+ warn: (message: string, ...args: any[]) => void;
172
+ /** Error-level logging for critical problems */
173
+ error: (message: string, ...args: any[]) => void;
174
+ /** Verbose-level logging for extensive detail */
175
+ verbose: (message: string, ...args: any[]) => void;
176
+ /** Silly-level logging for maximum detail */
177
+ silly: (message: string, ...args: any[]) => void;
178
+ }
179
+ /**
180
+ * Main Cardigantime interface providing configuration management functionality.
181
+ *
182
+ * @template T - The Zod schema shape type for configuration validation
183
+ */
184
+ export interface Cardigantime<T extends z.ZodRawShape> {
185
+ /**
186
+ * Adds Cardigantime's CLI options to a Commander.js command.
187
+ * This includes options like --config-directory for runtime config path overrides.
188
+ */
189
+ configure: (command: Command) => Promise<Command>;
190
+ /** Sets a custom logger for debugging and error reporting */
191
+ setLogger: (logger: Logger) => void;
192
+ /**
193
+ * Reads configuration from files and merges with CLI arguments.
194
+ * Returns a fully typed configuration object.
195
+ */
196
+ read: (args: Args) => Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>>;
197
+ /**
198
+ * Validates the merged configuration against the Zod schema.
199
+ * Throws ConfigurationError if validation fails.
200
+ */
201
+ validate: (config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>) => Promise<void>;
202
+ /**
203
+ * Generates a configuration file with default values in the specified directory.
204
+ * Creates the directory if it doesn't exist and writes a config file with all default values populated.
205
+ */
206
+ generateConfig: (configDirectory?: string) => Promise<void>;
207
+ /**
208
+ * Checks and displays the resolved configuration with detailed source tracking.
209
+ * Shows which file and hierarchical level contributed each configuration value in a git blame-like format.
210
+ */
211
+ checkConfig: (args: Args) => Promise<void>;
212
+ }
213
+ /**
214
+ * Parsed command-line arguments object, typically from Commander.js opts().
215
+ * Keys correspond to CLI option names with values from user input.
216
+ */
217
+ export interface Args {
218
+ [key: string]: any;
219
+ }
220
+ /**
221
+ * Base Zod schema for core Cardigantime configuration.
222
+ * Contains the minimum required configuration fields.
223
+ */
224
+ export declare const ConfigSchema: ZodObject<{
225
+ configDirectory: z.ZodString;
226
+ discoveredConfigDirs: z.ZodArray<z.ZodString>;
227
+ resolvedConfigDirs: z.ZodArray<z.ZodString>;
228
+ }, z.core.$strip>;
229
+ /**
230
+ * Base configuration type derived from the core schema.
231
+ */
232
+ export type Config = z.infer<typeof ConfigSchema>;
233
+ /**
234
+ * Defines a configuration file naming pattern.
235
+ * Used to discover configuration files in various standard locations.
236
+ *
237
+ * Patterns support placeholders:
238
+ * - `{app}` - The application name (e.g., 'protokoll', 'myapp')
239
+ * - `{ext}` - The file extension (e.g., 'yaml', 'json', 'ts')
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // Pattern: "{app}.config.{ext}" with app="myapp" and ext="yaml"
244
+ * // Results in: "myapp.config.yaml"
245
+ *
246
+ * const pattern: ConfigNamingPattern = {
247
+ * pattern: '{app}.config.{ext}',
248
+ * priority: 1,
249
+ * hidden: false
250
+ * };
251
+ * ```
252
+ */
253
+ export interface ConfigNamingPattern {
254
+ /**
255
+ * Pattern template with `{app}` and `{ext}` placeholders.
256
+ *
257
+ * Examples:
258
+ * - `"{app}.config.{ext}"` → `"protokoll.config.yaml"`
259
+ * - `".{app}/config.{ext}"` → `".protokoll/config.yaml"`
260
+ * - `".{app}rc.{ext}"` → `".protokollrc.json"`
261
+ * - `".{app}rc"` → `".protokollrc"` (no extension)
262
+ */
263
+ pattern: string;
264
+ /**
265
+ * Search priority (lower number = checked first).
266
+ * When multiple config files exist, lower priority patterns take precedence.
267
+ */
268
+ priority: number;
269
+ /**
270
+ * Whether this pattern results in a hidden file or directory.
271
+ * Hidden patterns start with a dot (e.g., `.myapp/`, `.myapprc`).
272
+ */
273
+ hidden: boolean;
274
+ }
275
+ /**
276
+ * Options for configuring how configuration files are discovered.
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const options: ConfigDiscoveryOptions = {
281
+ * appName: 'myapp',
282
+ * extensions: ['yaml', 'yml', 'json'],
283
+ * searchHidden: true,
284
+ * // Use custom patterns instead of defaults
285
+ * patterns: [
286
+ * { pattern: '{app}.config.{ext}', priority: 1, hidden: false }
287
+ * ]
288
+ * };
289
+ * ```
290
+ */
291
+ export interface ConfigDiscoveryOptions {
292
+ /**
293
+ * The application name used in pattern expansion.
294
+ * This value replaces `{app}` placeholders in naming patterns.
295
+ */
296
+ appName: string;
297
+ /**
298
+ * Custom naming patterns to use for discovery.
299
+ * If not provided, uses the standard patterns defined in STANDARD_PATTERNS.
300
+ */
301
+ patterns?: ConfigNamingPattern[];
302
+ /**
303
+ * File extensions to search for.
304
+ * These replace the `{ext}` placeholder in patterns.
305
+ * If not provided, defaults to supported format extensions.
306
+ *
307
+ * @example ['yaml', 'yml', 'json', 'js', 'ts']
308
+ */
309
+ extensions?: string[];
310
+ /**
311
+ * Whether to search for hidden files and directories.
312
+ * When false, patterns with `hidden: true` are skipped.
313
+ *
314
+ * @default true
315
+ */
316
+ searchHidden?: boolean;
317
+ /**
318
+ * Whether to check for multiple config files and emit a warning.
319
+ * When enabled, discovery continues after finding the first match
320
+ * to detect and warn about additional config files that would be ignored.
321
+ *
322
+ * @default true
323
+ */
324
+ warnOnMultipleConfigs?: boolean;
325
+ }
326
+ /**
327
+ * Result of discovering a configuration file.
328
+ * Contains the file path and the pattern that matched.
329
+ */
330
+ export interface DiscoveredConfig {
331
+ /**
332
+ * The resolved file path to the configuration file.
333
+ * Can be a file path (e.g., 'app.config.yaml') or include
334
+ * a directory (e.g., '.app/config.yaml').
335
+ */
336
+ path: string;
337
+ /**
338
+ * The absolute path to the configuration file.
339
+ */
340
+ absolutePath: string;
341
+ /**
342
+ * The pattern that matched this configuration file.
343
+ */
344
+ pattern: ConfigNamingPattern;
345
+ }
346
+ /**
347
+ * Warning information when multiple config files are found.
348
+ * This helps users identify and remove unused config files.
349
+ */
350
+ export interface MultipleConfigWarning {
351
+ /**
352
+ * The configuration that will be used (highest priority).
353
+ */
354
+ used: DiscoveredConfig;
355
+ /**
356
+ * Configurations that were found but will be ignored.
357
+ */
358
+ ignored: DiscoveredConfig[];
359
+ }
360
+ /**
361
+ * Full result of configuration discovery, including warnings.
362
+ */
363
+ export interface DiscoveryResult {
364
+ /**
365
+ * The discovered configuration file, or null if none found.
366
+ */
367
+ config: DiscoveredConfig | null;
368
+ /**
369
+ * Warning about multiple config files, if any were found.
370
+ */
371
+ multipleConfigWarning?: MultipleConfigWarning;
372
+ }
373
+ /**
374
+ * Controls how hierarchical configuration lookup behaves.
375
+ *
376
+ * - `'enabled'` - Walk up the directory tree and merge configs (default behavior).
377
+ * Configurations from parent directories are merged with child configurations,
378
+ * with child values taking precedence.
379
+ *
380
+ * - `'disabled'` - Use only the config found in the starting directory.
381
+ * No parent directory traversal occurs. Useful for isolated projects or
382
+ * MCP configurations that should be self-contained.
383
+ *
384
+ * - `'root-only'` - Walk up to find the first config, but don't merge with others.
385
+ * This mode finds the "closest" config file without merging parent configs.
386
+ * Useful when you want automatic config discovery but not inheritance.
387
+ *
388
+ * - `'explicit'` - Only merge configs that are explicitly referenced.
389
+ * The base config can specify which parent configs to extend via an
390
+ * `extends` field. No automatic directory traversal.
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * // In a child config that wants to be isolated:
395
+ * // protokoll.config.yaml
396
+ * hierarchical:
397
+ * mode: disabled
398
+ *
399
+ * // This config will NOT inherit from parent directories
400
+ * ```
401
+ */
402
+ export type HierarchicalMode = 'enabled' | 'disabled' | 'root-only' | 'explicit';
403
+ /**
404
+ * Files or directories that indicate a project root.
405
+ * When encountered during directory traversal, hierarchical lookup stops.
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * const markers: RootMarker[] = [
410
+ * { type: 'file', name: 'package.json' },
411
+ * { type: 'directory', name: '.git' },
412
+ * { type: 'file', name: 'pnpm-workspace.yaml' },
413
+ * ];
414
+ * ```
415
+ */
416
+ export interface RootMarker {
417
+ /** Type of the marker */
418
+ type: 'file' | 'directory';
419
+ /** Name of the file or directory that indicates a root */
420
+ name: string;
421
+ }
422
+ /**
423
+ * Default root markers used when none are specified.
424
+ * These indicate common project root boundaries.
425
+ */
426
+ export declare const DEFAULT_ROOT_MARKERS: RootMarker[];
427
+ /**
428
+ * Configuration options for hierarchical config behavior.
429
+ * Can be set in the configuration file or programmatically.
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * // Configuration file (protokoll.config.yaml):
434
+ * hierarchical:
435
+ * mode: enabled
436
+ * maxDepth: 5
437
+ * stopAt:
438
+ * - node_modules
439
+ * - vendor
440
+ * rootMarkers:
441
+ * - type: file
442
+ * name: package.json
443
+ * ```
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * // Programmatic configuration:
448
+ * const options: HierarchicalOptions = {
449
+ * mode: 'disabled', // No parent config merging
450
+ * };
451
+ *
452
+ * // For MCP servers:
453
+ * const mcpOptions: HierarchicalOptions = {
454
+ * mode: 'root-only',
455
+ * rootMarkers: [{ type: 'file', name: 'mcp.json' }],
456
+ * };
457
+ * ```
458
+ */
459
+ export interface HierarchicalOptions {
460
+ /**
461
+ * The hierarchical lookup mode.
462
+ * Controls whether and how parent directories are searched.
463
+ *
464
+ * @default 'enabled'
465
+ */
466
+ mode?: HierarchicalMode;
467
+ /**
468
+ * Maximum number of parent directories to traverse.
469
+ * Prevents unbounded traversal in deep directory structures.
470
+ *
471
+ * @default 10
472
+ */
473
+ maxDepth?: number;
474
+ /**
475
+ * Directory names where traversal should stop.
476
+ * When a directory with one of these names is encountered as a parent,
477
+ * traversal stops even if no config was found.
478
+ *
479
+ * @example ['node_modules', 'vendor', '.cache']
480
+ */
481
+ stopAt?: string[];
482
+ /**
483
+ * Files or directories that indicate a project root.
484
+ * When a directory contains one of these markers, it's treated as a root
485
+ * and traversal stops after processing that directory.
486
+ *
487
+ * If not specified, uses DEFAULT_ROOT_MARKERS.
488
+ * Set to empty array to disable root marker detection.
489
+ */
490
+ rootMarkers?: RootMarker[];
491
+ /**
492
+ * Whether to stop at the first root marker found.
493
+ * When true, traversal stops immediately when a root marker is found.
494
+ * When false, the directory with the root marker is included but no further.
495
+ *
496
+ * @default true
497
+ */
498
+ stopAtRoot?: boolean;
499
+ }
500
+ /**
501
+ * Defines security boundaries for directory traversal.
502
+ * Used to prevent configuration lookup from accessing sensitive directories.
503
+ *
504
+ * @example
505
+ * ```typescript
506
+ * const boundaries: TraversalBoundary = {
507
+ * forbidden: ['/etc', '/usr', '/var'],
508
+ * boundaries: [process.env.HOME ?? '/home'],
509
+ * maxAbsoluteDepth: 20,
510
+ * maxRelativeDepth: 10,
511
+ * };
512
+ * ```
513
+ */
514
+ export interface TraversalBoundary {
515
+ /**
516
+ * Directories that are never allowed to be accessed.
517
+ * Traversal is blocked if the path is at or within these directories.
518
+ * Paths can include environment variable placeholders like `$HOME`.
519
+ *
520
+ * @example ['/etc', '/usr', '/var', '/sys', '/proc', '$HOME/.ssh']
521
+ */
522
+ forbidden: string[];
523
+ /**
524
+ * Soft boundary directories - traversal stops at these unless explicitly allowed.
525
+ * These represent natural project boundaries.
526
+ * Paths can include environment variable placeholders like `$HOME`.
527
+ *
528
+ * @example ['$HOME', '/tmp', '/private/tmp']
529
+ */
530
+ boundaries: string[];
531
+ /**
532
+ * Maximum absolute depth from the filesystem root.
533
+ * Prevents extremely deep traversal regardless of starting point.
534
+ * Depth is counted as the number of path segments from root.
535
+ *
536
+ * @example 20 means paths like /a/b/c/.../t (20 levels deep) are allowed
537
+ * @default 20
538
+ */
539
+ maxAbsoluteDepth: number;
540
+ /**
541
+ * Maximum relative depth from the starting directory.
542
+ * Limits how far up the directory tree traversal can go.
543
+ *
544
+ * @example 10 means traversal can go up 10 directories from the start
545
+ * @default 10
546
+ */
547
+ maxRelativeDepth: number;
548
+ }
549
+ /**
550
+ * Result of a traversal boundary check.
551
+ */
552
+ export interface TraversalCheckResult {
553
+ /** Whether the path is allowed */
554
+ allowed: boolean;
555
+ /** Reason for blocking (if not allowed) */
556
+ reason?: string;
557
+ /** The boundary that was violated (if any) */
558
+ violatedBoundary?: string;
559
+ }
560
+ /**
561
+ * Options for configuring traversal security behavior.
562
+ */
563
+ export interface TraversalSecurityOptions {
564
+ /**
565
+ * Custom traversal boundaries to use instead of defaults.
566
+ */
567
+ boundaries?: Partial<TraversalBoundary>;
568
+ /**
569
+ * Allow traversal beyond safe boundaries.
570
+ *
571
+ * **SECURITY WARNING**: Setting this to true bypasses security checks
572
+ * and allows traversal into sensitive directories. Only use this in
573
+ * trusted scenarios where you control all configuration files.
574
+ *
575
+ * @default false
576
+ */
577
+ allowUnsafeTraversal?: boolean;
578
+ /**
579
+ * Whether to log warnings when boundaries are overridden.
580
+ *
581
+ * @default true
582
+ */
583
+ warnOnOverride?: boolean;
584
+ }
package/dist/types.js ADDED
@@ -0,0 +1,56 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Supported configuration file formats.
5
+ *
6
+ * - 'yaml': YAML format (.yaml, .yml)
7
+ * - 'json': JSON format (.json)
8
+ * - 'javascript': JavaScript module (.js, .mjs, .cjs)
9
+ * - 'typescript': TypeScript module (.ts, .mts, .cts)
10
+ */ var ConfigFormat = /*#__PURE__*/ function(ConfigFormat) {
11
+ ConfigFormat["YAML"] = "yaml";
12
+ ConfigFormat["JSON"] = "json";
13
+ ConfigFormat["JavaScript"] = "javascript";
14
+ ConfigFormat["TypeScript"] = "typescript";
15
+ return ConfigFormat;
16
+ }({});
17
+ /**
18
+ * Base Zod schema for core Cardigantime configuration.
19
+ * Contains the minimum required configuration fields.
20
+ */ const ConfigSchema = z.object({
21
+ /** The resolved configuration directory path */ configDirectory: z.string(),
22
+ /** Array of all directory paths that were discovered during hierarchical search */ discoveredConfigDirs: z.array(z.string()),
23
+ /** Array of directory paths that actually contained valid configuration files */ resolvedConfigDirs: z.array(z.string())
24
+ });
25
+ /**
26
+ * Default root markers used when none are specified.
27
+ * These indicate common project root boundaries.
28
+ */ const DEFAULT_ROOT_MARKERS = [
29
+ {
30
+ type: 'file',
31
+ name: 'package.json'
32
+ },
33
+ {
34
+ type: 'directory',
35
+ name: '.git'
36
+ },
37
+ {
38
+ type: 'file',
39
+ name: 'pnpm-workspace.yaml'
40
+ },
41
+ {
42
+ type: 'file',
43
+ name: 'lerna.json'
44
+ },
45
+ {
46
+ type: 'file',
47
+ name: 'nx.json'
48
+ },
49
+ {
50
+ type: 'file',
51
+ name: 'rush.json'
52
+ }
53
+ ];
54
+
55
+ export { ConfigFormat, ConfigSchema, DEFAULT_ROOT_MARKERS };
56
+ //# sourceMappingURL=types.js.map