@visulima/cerebro 3.0.2 → 3.0.4

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 (34) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/MIGRATION-GUIDE.md +732 -0
  3. package/dist/commands/completion-command.d.ts +3 -3
  4. package/dist/commands/completion-command.js +1 -1
  5. package/dist/commands/help-command.d.ts +1 -1
  6. package/dist/commands/help-command.js +1 -1
  7. package/dist/commands/readme-command.d.ts +3 -3
  8. package/dist/commands/readme-command.js +17 -17
  9. package/dist/commands/version-command.d.ts +1 -1
  10. package/dist/index.d.ts +403 -433
  11. package/dist/index.js +1 -1
  12. package/dist/logger/create-pail-logger.d.ts +533 -555
  13. package/dist/packem_chunks/has-new-version.js +1 -1
  14. package/dist/packem_shared/Cerebro-CHB2i5uf.js +4 -0
  15. package/dist/packem_shared/{VisulimaError-C90oeIMu.js → VisulimaError-BheWBD7j.js} +2 -2
  16. package/dist/packem_shared/{cerebro-error-BjBcYVRO.js → cerebro-error-DnA3fjrR.js} +1 -1
  17. package/dist/packem_shared/command.d-B_G9vIYJ.d.ts +633 -0
  18. package/dist/packem_shared/{index-DvVGK4kr.js → index-BAKCiGjO.js} +10 -10
  19. package/dist/packem_shared/index.d-CnnVYgSZ.d.ts +117 -0
  20. package/dist/packem_shared/renderError-DjesnVYT-pHitCa3e.js +25 -0
  21. package/dist/packem_shared/split-by-case-DpyL5bdy.js +1 -0
  22. package/dist/plugins/error-handler-plugin.d.ts +18 -7
  23. package/dist/plugins/error-handler-plugin.js +1 -1
  24. package/dist/plugins/runtime-version-check-plugin.d.ts +5 -5
  25. package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +11 -10
  26. package/dist/util/general/compile-cache.d.ts +37 -37
  27. package/dist/util/general/heap-tuning.d.ts +11 -11
  28. package/dist/util/general/heap-tuning.js +1 -1
  29. package/package.json +4 -3
  30. package/dist/packem_shared/Cerebro-Czc4t-75.js +0 -4
  31. package/dist/packem_shared/command.d-DbhtfXF4.d.ts +0 -639
  32. package/dist/packem_shared/index.d-BL4NtVR3.d.ts +0 -127
  33. package/dist/packem_shared/renderError-B3ePOoBG-BmZlyMcr.js +0 -25
  34. package/dist/packem_shared/split-by-case-Dbpgd7rf.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,520 +1,490 @@
1
- import { a as CerebroFs, b as CommandSection, O as OptionDefinition, C as Command, P as Plugin, c as PluginManager, d as CliRunOptions, R as RunCommandOptions, T as Toolbox, e as CommandExecute, f as Cli$1, L as LazyCommandModule } from "./packem_shared/command.d-DbhtfXF4.js";
2
- export type { A as ArgumentDefinition, g as CerebroProcess, E as EnvDefinition, h as OutputType, i as PluginContext, V as VERBOSITY_LEVEL } from "./packem_shared/command.d-DbhtfXF4.js";
3
- export { V as VisulimaError } from "./packem_shared/index.d-BL4NtVR3.js";
1
+ import { a as CerebroFs, b as CommandSection, O as OptionDefinition, C as Command, P as Plugin, c as PluginManager, d as CliRunOptions, R as RunCommandOptions, T as Toolbox, e as CommandExecute, f as Cli$1, L as LazyCommandModule } from "./packem_shared/command.d-B_G9vIYJ.js";
2
+ export type { A as ArgumentDefinition, g as CerebroProcess, E as EnvDefinition, h as OutputType, i as PluginContext, V as VERBOSITY_LEVEL } from "./packem_shared/command.d-B_G9vIYJ.js";
3
+ export { V as VisulimaError } from "./packem_shared/index.d-CnnVYgSZ.js";
4
4
  import '@visulima/tabular';
5
5
  type CliOptions<T extends Console = Console> = {
6
6
  argv?: ReadonlyArray<string>;
7
7
  cwd?: string;
8
8
  /**
9
- * Process environment variables exposed to commands via `toolbox.process.env`.
10
- * Defaults to the runtime's process environment. Override to provide a
11
- * captured snapshot in tests so commands don't read mutating host state.
12
- */
9
+ * Process environment variables exposed to commands via `toolbox.process.env`.
10
+ * Defaults to the runtime's process environment. Override to provide a
11
+ * captured snapshot in tests so commands don't read mutating host state.
12
+ */
13
13
  env?: Record<string, string | undefined>;
14
14
  /**
15
- * Function called when a command invokes `toolbox.process.exit(code)`.
16
- * Defaults to the runtime-agnostic exit helper that terminates the process.
17
- * Override with a `vi.fn()` in tests to capture exit codes without killing
18
- * the test runner.
19
- */
15
+ * Function called when a command invokes `toolbox.process.exit(code)`.
16
+ * Defaults to the runtime-agnostic exit helper that terminates the process.
17
+ * Override with a `vi.fn()` in tests to capture exit codes without killing
18
+ * the test runner.
19
+ */
20
20
  exit?: (code?: number) => void;
21
21
  /**
22
- * Filesystem adapter exposed via `toolbox.fs`. Defaults to `node:fs/promises`.
23
- * Override with an in-memory or sandboxed adapter for tests and embedded
24
- * runtimes (MCP, JustBash).
25
- */
22
+ * Filesystem adapter exposed via `toolbox.fs`. Defaults to `node:fs/promises`.
23
+ * Override with an in-memory or sandboxed adapter for tests and embedded
24
+ * runtimes (MCP, JustBash).
25
+ */
26
26
  fs?: CerebroFs;
27
27
  logger?: T;
28
28
  /**
29
- * Maximum number of argv tokens accepted before {@link Cli} rejects the
30
- * invocation. Defaults to a generous cap (`DEFAULT_MAX_ARGS`) that never
31
- * trips real-world glob expansions; set to `Number.POSITIVE_INFINITY` to
32
- * disable the guard entirely.
33
- */
29
+ * Maximum number of argv tokens accepted before {@link Cli} rejects the
30
+ * invocation. Defaults to a generous cap (`DEFAULT_MAX_ARGS`) that never
31
+ * trips real-world glob expansions; set to `Number.POSITIVE_INFINITY` to
32
+ * disable the guard entirely.
33
+ */
34
34
  maxArguments?: number;
35
35
  packageName?: string;
36
36
  packageVersion?: string;
37
37
  /**
38
- * Buffered stdin content exposed via `toolbox.process.stdin`. Empty string
39
- * by default. Useful for tests and sandboxed runtimes where wiring real
40
- * stdin is impractical.
41
- */
38
+ * Buffered stdin content exposed via `toolbox.process.stdin`. Empty string
39
+ * by default. Useful for tests and sandboxed runtimes where wiring real
40
+ * stdin is impractical.
41
+ */
42
42
  stdin?: string;
43
43
  /**
44
- * When enabled, unknown long options (`--typo`) that appear before any `--`
45
- * passthrough separator cause the run to fail with an `UnknownOptionError`
46
- * (with did-you-mean suggestions) instead of being silently routed to
47
- * `toolbox.rawUnknown`. Tokens after `--` are always preserved as
48
- * passthrough. Off by default to preserve existing behavior.
49
- */
44
+ * When enabled, unknown long options (`--typo`) that appear before any `--`
45
+ * passthrough separator cause the run to fail with an `UnknownOptionError`
46
+ * (with did-you-mean suggestions) instead of being silently routed to
47
+ * `toolbox.rawUnknown`. Tokens after `--` are always preserved as
48
+ * passthrough. Off by default to preserve existing behavior.
49
+ */
50
50
  strictOptions?: boolean;
51
51
  };
52
52
  declare class Cli<T extends Console = Console> implements Cli$1<T> {
53
53
  #private;
54
54
  /**
55
- * Create a new CLI instance.
56
- * @param cliName
57
- * @param options The options for the CLI.
58
- * @param options.argv The command line arguments.
59
- * @param options.cwd The current working directory.
60
- * @param options.logger The logger to use.
61
- * @param options.packageName
62
- * @param options.packageVersion
63
- */
55
+ * Create a new CLI instance.
56
+ * @param cliName
57
+ * @param options The options for the CLI.
58
+ * @param options.argv The command line arguments.
59
+ * @param options.cwd The current working directory.
60
+ * @param options.logger The logger to use.
61
+ * @param options.packageName
62
+ * @param options.packageVersion
63
+ */
64
64
  constructor(cliName: string, options?: CliOptions<T>);
65
65
  /**
66
- * Sets the command section configuration for help display.
67
- *
68
- * This affects how the CLI name and version are displayed in help output.
69
- * @param commandSection The command section configuration
70
- * @returns The CLI instance for method chaining
71
- * @example
72
- * ```typescript
73
- * cli.setCommandSection({
74
- * header: 'My App v2.0.0',
75
- * footer: 'For more info, visit https://example.com'
76
- * });
77
- * ```
78
- */
66
+ * Sets the command section configuration for help display.
67
+ *
68
+ * This affects how the CLI name and version are displayed in help output.
69
+ * @param commandSection The command section configuration
70
+ * @returns The CLI instance for method chaining
71
+ * @example
72
+ * ```typescript
73
+ * cli.setCommandSection({
74
+ * header: 'My App v2.0.0',
75
+ * footer: 'For more info, visit https://example.com'
76
+ * });
77
+ * ```
78
+ */
79
79
  setCommandSection(commandSection: CommandSection): this;
80
80
  /**
81
- * Gets the current command section configuration.
82
- * @returns The command section configuration
83
- */
81
+ * Gets the current command section configuration.
82
+ * @returns The command section configuration
83
+ */
84
84
  getCommandSection(): CommandSection;
85
85
  /**
86
- * Sets the default command to run when no command is specified.
87
- *
88
- * By default, this is set to 'help'. The command must already be registered
89
- * with the CLI instance.
90
- * @param commandName The command name to use as the default
91
- * @returns The CLI instance for method chaining
92
- * @example
93
- * ```typescript
94
- * cli.setDefaultCommand('start');
95
- * ```
96
- */
86
+ * Sets the default command to run when no command is specified.
87
+ *
88
+ * By default, this is set to 'help'. The command must already be registered
89
+ * with the CLI instance.
90
+ * @param commandName The command name to use as the default
91
+ * @returns The CLI instance for method chaining
92
+ * @example
93
+ * ```typescript
94
+ * cli.setDefaultCommand('start');
95
+ * ```
96
+ */
97
97
  setDefaultCommand(commandName: string): this;
98
98
  /**
99
- * Gets the current default command.
100
- * @returns The name of the default command
101
- */
99
+ * Gets the current default command.
100
+ * @returns The name of the default command
101
+ */
102
102
  get defaultCommand(): string;
103
103
  /**
104
- * Adds a command to the CLI.
105
- *
106
- * Commands define the available operations that users can execute.
107
- * Each command can have options, arguments, aliases, and custom execution logic.
108
- * @template OD - The option definition type for the command
109
- * @param command The command configuration object
110
- * @returns The CLI instance for method chaining
111
- * @throws {CerebroError} If the command name already exists or validation fails
112
- * @example
113
- * ```typescript
114
- * cli.addCommand({
115
- * name: 'build',
116
- * description: 'Build the project',
117
- * options: [
118
- * {
119
- * name: 'output',
120
- * alias: 'o',
121
- * type: String,
122
- * description: 'Output directory'
123
- * }
124
- * ],
125
- * execute: ({ options }) => {
126
- * console.log(`Building to ${options.output || 'dist'}`);
127
- * }
128
- * });
129
- * ```
130
- */
104
+ * Adds a command to the CLI.
105
+ *
106
+ * Commands define the available operations that users can execute.
107
+ * Each command can have options, arguments, aliases, and custom execution logic.
108
+ * @template OD - The option definition type for the command
109
+ * @param command The command configuration object
110
+ * @returns The CLI instance for method chaining
111
+ * @throws {CerebroError} If the command name already exists or validation fails
112
+ * @example
113
+ * ```typescript
114
+ * cli.addCommand({
115
+ * name: 'build',
116
+ * description: 'Build the project',
117
+ * options: [
118
+ * {
119
+ * name: 'output',
120
+ * alias: 'o',
121
+ * type: String,
122
+ * description: 'Output directory'
123
+ * }
124
+ * ],
125
+ * execute: ({ options }) => {
126
+ * console.log(`Building to ${options.output || 'dist'}`);
127
+ * }
128
+ * });
129
+ * ```
130
+ */
131
131
  addCommand<OD extends OptionDefinition<unknown> = OptionDefinition<unknown>>(command: Command<OD, T>): this;
132
132
  /**
133
- * Adds a global option available to all commands.
134
- *
135
- * Global options are parsed alongside command-specific options and displayed
136
- * in the help output under the "Global Options" section.
137
- * @param option The option definition
138
- * @returns The CLI instance for method chaining
139
- * @example
140
- * ```typescript
141
- * cli.addGlobalOption({
142
- * name: 'cwd',
143
- * type: String,
144
- * description: 'Override working directory',
145
- * });
146
- * ```
147
- */
133
+ * Adds a global option available to all commands.
134
+ *
135
+ * Global options are parsed alongside command-specific options and displayed
136
+ * in the help output under the "Global Options" section.
137
+ * @param option The option definition
138
+ * @returns The CLI instance for method chaining
139
+ * @example
140
+ * ```typescript
141
+ * cli.addGlobalOption({
142
+ * name: 'cwd',
143
+ * type: String,
144
+ * description: 'Override working directory',
145
+ * });
146
+ * ```
147
+ */
148
148
  addGlobalOption<V = unknown>(option: OptionDefinition<V>): this;
149
149
  /**
150
- * Gets all global options (built-in + custom).
151
- * @returns Array of all global option definitions
152
- */
150
+ * Gets all global options (built-in + custom).
151
+ * @returns Array of all global option definitions
152
+ */
153
153
  getGlobalOptions(): OptionDefinition<unknown>[];
154
154
  /**
155
- * Adds a plugin to extend the CLI functionality.
156
- *
157
- * Plugins can hook into various lifecycle events and modify the toolbox
158
- * to provide additional functionality to commands.
159
- * @param plugin The plugin to register
160
- * @returns The CLI instance for method chaining
161
- * @example
162
- * ```typescript
163
- * cli.addPlugin({
164
- * name: 'logger',
165
- * execute: (toolbox) => {
166
- * toolbox.logger = createCustomLogger();
167
- * }
168
- * });
169
- * ```
170
- */
155
+ * Adds a plugin to extend the CLI functionality.
156
+ *
157
+ * Plugins can hook into various lifecycle events and modify the toolbox
158
+ * to provide additional functionality to commands.
159
+ * @param plugin The plugin to register
160
+ * @returns The CLI instance for method chaining
161
+ * @example
162
+ * ```typescript
163
+ * cli.addPlugin({
164
+ * name: 'logger',
165
+ * execute: (toolbox) => {
166
+ * toolbox.logger = createCustomLogger();
167
+ * }
168
+ * });
169
+ * ```
170
+ */
171
171
  addPlugin(plugin: Plugin<T>): this;
172
172
  /**
173
- * Gets the plugin manager instance for advanced plugin management.
174
- * @returns The plugin manager instance
175
- */
173
+ * Gets the plugin manager instance for advanced plugin management.
174
+ * @returns The plugin manager instance
175
+ */
176
176
  getPluginManager(): PluginManager<T>;
177
177
  /**
178
- * Gets the CLI application name.
179
- */
178
+ * Gets the CLI application name.
179
+ */
180
180
  getCliName(): string;
181
181
  /**
182
- * Gets the package version if configured.
183
- * @returns The package version or undefined
184
- */
182
+ * Gets the package version if configured.
183
+ * @returns The package version or undefined
184
+ */
185
185
  getPackageVersion(): string | undefined;
186
186
  /**
187
- * Gets the package name if configured.
188
- * @returns The package name or undefined
189
- */
187
+ * Gets the package name if configured.
188
+ * @returns The package name or undefined
189
+ */
190
190
  getPackageName(): string | undefined;
191
191
  /**
192
- * Gets all registered commands.
193
- * @returns A map of command names to command definitions
194
- */
192
+ * Gets all registered commands.
193
+ * @returns A map of command names to command definitions
194
+ */
195
195
  getCommands(): Map<string, Command<OptionDefinition<unknown>, T>>;
196
196
  /**
197
- * Gets the current working directory.
198
- * @returns The current working directory path
199
- */
197
+ * Gets the current working directory.
198
+ * @returns The current working directory path
199
+ */
200
200
  getCwd(): string;
201
201
  /**
202
- * Disposes the CLI instance and cleans up resources.
203
- *
204
- * This method removes event listeners and performs cleanup to prevent memory leaks.
205
- * Call this method when the CLI instance is no longer needed, especially in long-running
206
- * processes or when creating multiple CLI instances.
207
- * @example
208
- * ```typescript
209
- * const cli = new Cerebro('my-app');
210
- * // ... use the cli
211
- * cli.dispose(); // Clean up when done
212
- * ```
213
- */
202
+ * Disposes the CLI instance and cleans up resources.
203
+ *
204
+ * This method removes event listeners and performs cleanup to prevent memory leaks.
205
+ * Call this method when the CLI instance is no longer needed, especially in long-running
206
+ * processes or when creating multiple CLI instances.
207
+ * @example
208
+ * ```typescript
209
+ * const cli = new Cerebro('my-app');
210
+ * // ... use the cli
211
+ * cli.dispose(); // Clean up when done
212
+ * ```
213
+ */
214
214
  dispose(): void;
215
215
  /**
216
- * Runs the CLI application.
217
- *
218
- * This method parses command line arguments, executes the appropriate command,
219
- * and handles the complete CLI lifecycle including plugin initialization,
220
- * error handling, process termination, and automatic cleanup.
221
- * @param extraOptions Additional options to pass to commands
222
- * @param extraOptions.shouldExitProcess Whether to exit the process after execution (default: true)
223
- * @param extraOptions.autoDispose Whether to automatically cleanup/dispose resources after execution (default: true)
224
- * @returns A promise that resolves when execution completes
225
- * @throws {CommandNotFoundError} If the specified command doesn't exist
226
- * @throws {Error} If command arguments are invalid or conflicting options are provided
227
- * @example
228
- * ```typescript
229
- * // Run with default behavior (exits process and auto-disposes)
230
- * await cli.run();
231
- *
232
- * // Run without exiting (for testing)
233
- * await cli.run({ shouldExitProcess: false });
234
- *
235
- * // Run without auto-disposing (for reuse)
236
- * await cli.run({ autoDispose: false });
237
- * ```
238
- */
216
+ * Runs the CLI application.
217
+ *
218
+ * This method parses command line arguments, executes the appropriate command,
219
+ * and handles the complete CLI lifecycle including plugin initialization,
220
+ * error handling, process termination, and automatic cleanup.
221
+ * @param extraOptions Additional options to pass to commands
222
+ * @param extraOptions.shouldExitProcess Whether to exit the process after execution (default: true)
223
+ * @param extraOptions.autoDispose Whether to automatically cleanup/dispose resources after execution (default: true)
224
+ * @returns A promise that resolves when execution completes
225
+ * @throws {CommandNotFoundError} If the specified command doesn't exist
226
+ * @throws {Error} If command arguments are invalid or conflicting options are provided
227
+ * @example
228
+ * ```typescript
229
+ * // Run with default behavior (exits process and auto-disposes)
230
+ * await cli.run();
231
+ *
232
+ * // Run without exiting (for testing)
233
+ * await cli.run({ shouldExitProcess: false });
234
+ *
235
+ * // Run without auto-disposing (for reuse)
236
+ * await cli.run({ autoDispose: false });
237
+ * ```
238
+ */
239
239
  run(extraOptions?: CliRunOptions): Promise<void>;
240
240
  /**
241
- * Runs a command programmatically from within another command.
242
- *
243
- * This method allows commands to call other commands during execution,
244
- * enabling composition of commands and reusable command logic.
245
- * @param commandName The name of the command to execute
246
- * @param options Optional options including argv and other command options
247
- * @returns A promise that resolves with the command's result
248
- * @throws {CommandNotFoundError} If the specified command doesn't exist
249
- * @throws {CerebroError} If command validation fails
250
- * @example
251
- * ```typescript
252
- * cli.addCommand({
253
- * name: 'deploy',
254
- * execute: async ({ runtime, logger }) => {
255
- * logger.info('Building...');
256
- * await runtime.runCommand('build', { argv: ['--production'] });
257
- *
258
- * logger.info('Testing...');
259
- * await runtime.runCommand('test', { argv: ['--coverage'] });
260
- * }
261
- * });
262
- * ```
263
- */
241
+ * Runs a command programmatically from within another command.
242
+ *
243
+ * This method allows commands to call other commands during execution,
244
+ * enabling composition of commands and reusable command logic.
245
+ * @param commandName The name of the command to execute
246
+ * @param options Optional options including argv and other command options
247
+ * @returns A promise that resolves with the command's result
248
+ * @throws {CommandNotFoundError} If the specified command doesn't exist
249
+ * @throws {CerebroError} If command validation fails
250
+ * @example
251
+ * ```typescript
252
+ * cli.addCommand({
253
+ * name: 'deploy',
254
+ * execute: async ({ runtime, logger }) => {
255
+ * logger.info('Building...');
256
+ * await runtime.runCommand('build', { argv: ['--production'] });
257
+ *
258
+ * logger.info('Testing...');
259
+ * await runtime.runCommand('test', { argv: ['--coverage'] });
260
+ * }
261
+ * });
262
+ * ```
263
+ */
264
264
  runCommand(commandName: string, options?: RunCommandOptions): Promise<unknown>;
265
265
  /**
266
- * Creates a shallow copy of the CLI with optional `CliOptions` overrides.
267
- *
268
- * The clone shares the underlying command definitions (the same `Command`
269
- * objects are reused), but has its own commands map, global-options list,
270
- * default-command setting, command-section configuration, and a freshly
271
- * initialized plugin manager. Mutating one CLI's commands after cloning
272
- * does not affect the other.
273
- *
274
- * Primarily useful in tests to run the same CLI definition with different
275
- * argv / stdout / exit / fs overrides without rebuilding the command tree.
276
- * @param overrides Optional `CliOptions` to merge over the clone's existing options
277
- * @returns A new `Cli` instance with the same commands and merged options
278
- * @example
279
- * ```typescript
280
- * const cli = new Cerebro("acme");
281
- * cli.addCommand({ name: "build", execute: ({ console }) => console.log("building") });
282
- *
283
- * // In tests: clone with mocked exit + captured stdout
284
- * const exitSpy = vi.fn();
285
- * const isolated = cli.clone({ argv: ["build"], exit: exitSpy });
286
- * await isolated.run({ shouldExitProcess: false });
287
- * ```
288
- */
266
+ * Creates a shallow copy of the CLI with optional `CliOptions` overrides.
267
+ *
268
+ * The clone shares the underlying command definitions (the same `Command`
269
+ * objects are reused), but has its own commands map, global-options list,
270
+ * default-command setting, command-section configuration, and a freshly
271
+ * initialized plugin manager. Mutating one CLI's commands after cloning
272
+ * does not affect the other.
273
+ *
274
+ * Primarily useful in tests to run the same CLI definition with different
275
+ * argv / stdout / exit / fs overrides without rebuilding the command tree.
276
+ * @param overrides Optional `CliOptions` to merge over the clone's existing options
277
+ * @returns A new `Cli` instance with the same commands and merged options
278
+ * @example
279
+ * ```typescript
280
+ * const cli = new Cerebro("acme");
281
+ * cli.addCommand({ name: "build", execute: ({ console }) => console.log("building") });
282
+ *
283
+ * // In tests: clone with mocked exit + captured stdout
284
+ * const exitSpy = vi.fn();
285
+ * const isolated = cli.clone({ argv: ["build"], exit: exitSpy });
286
+ * await isolated.run({ shouldExitProcess: false });
287
+ * ```
288
+ */
289
289
  clone(overrides?: CliOptions<T>): Cli<T>;
290
290
  /**
291
- * Returns the resolved `execute` function for a registered command.
292
- *
293
- * For lazy-loaded commands (defined via `loader`), the loader is awaited
294
- * and its module's default export is returned. The result is cached on the
295
- * command for subsequent calls. Supports space-separated nested command
296
- * paths (e.g. `"git remote add"`).
297
- *
298
- * Primarily useful in tests to invoke a command's handler directly with a
299
- * synthesized toolbox, without going through argv parsing or the full
300
- * `run()` lifecycle.
301
- * @param commandName The command name or space-separated nested path
302
- * @returns A promise resolving to the command's handler function
303
- * @throws {CommandNotFoundError} If no command matches the given name
304
- * @throws {CerebroError} If the command has neither `execute` nor `loader`
305
- * @example
306
- * ```typescript
307
- * const cli = new Cerebro("acme");
308
- * cli.addCommand({
309
- * name: "deploy",
310
- * execute: ({ console, options }) => console.log("deploying to", options.env),
311
- * });
312
- *
313
- * // In tests: call the action directly with a mocked toolbox
314
- * const action = await cli.getAction("deploy");
315
- * await action({ console: fakeConsole, options: { env: "staging" } } as never);
316
- * ```
317
- */
291
+ * Returns the resolved `execute` function for a registered command.
292
+ *
293
+ * For lazy-loaded commands (defined via `loader`), the loader is awaited
294
+ * and its module's default export is returned. The result is cached on the
295
+ * command for subsequent calls. Supports space-separated nested command
296
+ * paths (e.g. `"git remote add"`).
297
+ *
298
+ * Primarily useful in tests to invoke a command's handler directly with a
299
+ * synthesized toolbox, without going through argv parsing or the full
300
+ * `run()` lifecycle.
301
+ * @param commandName The command name or space-separated nested path
302
+ * @returns A promise resolving to the command's handler function
303
+ * @throws {CommandNotFoundError} If no command matches the given name
304
+ * @throws {CerebroError} If the command has neither `execute` nor `loader`
305
+ * @example
306
+ * ```typescript
307
+ * const cli = new Cerebro("acme");
308
+ * cli.addCommand({
309
+ * name: "deploy",
310
+ * execute: ({ console, options }) => console.log("deploying to", options.env),
311
+ * });
312
+ *
313
+ * // In tests: call the action directly with a mocked toolbox
314
+ * const action = await cli.getAction("deploy");
315
+ * await action({ console: fakeConsole, options: { env: "staging" } } as never);
316
+ * ```
317
+ */
318
318
  getAction(commandName: string): Promise<CommandExecute<Toolbox<T>>>;
319
319
  }
320
320
  /**
321
- * Output with this verbosity won't write anything at all.
322
- */
321
+ * Output with this verbosity won't write anything at all.
322
+ */
323
323
  declare const VERBOSITY_QUIET = 16;
324
324
  /**
325
- * Output with this verbosity will write default content.
326
- */
325
+ * Output with this verbosity will write default content.
326
+ */
327
327
  declare const VERBOSITY_NORMAL = 32;
328
328
  /**
329
- * Output with this verbosity will be more detailed.
330
- */
329
+ * Output with this verbosity will be more detailed.
330
+ */
331
331
  declare const VERBOSITY_VERBOSE = 64;
332
332
  /**
333
- * Output with this verbosity will reveal internals.
334
- */
333
+ * Output with this verbosity will reveal internals.
334
+ */
335
335
  declare const VERBOSITY_DEBUG = 128;
336
336
  /**
337
- * Helper types for creating type-safe commands with autocomplete support.
338
- * These types help you define your options and environment variables with full TypeScript autocomplete.
339
- * Use these types to create type-safe Toolbox interfaces for your commands.
340
- * @example
341
- * ```typescript
342
- * import { CreateOptions, CreateEnv, type Toolbox } from '@visulima/cerebro';
343
- *
344
- * // Define options with their original names (they'll be converted to camelCase)
345
- * type BuildOptions = CreateOptions<{
346
- * "output-dir": string | undefined;
347
- * "verbose": boolean | undefined;
348
- * "port": number | undefined;
349
- * }>;
350
- * // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
351
- *
352
- * // Define environment variables (UPPER_SNAKE_CASE -> camelCase)
353
- * type BuildEnv = CreateEnv<{
354
- * "API_KEY": string | undefined;
355
- * "DEBUG": boolean | undefined;
356
- * }>;
357
- * // Result: { apiKey: string | undefined, debug: boolean | undefined }
358
- *
359
- * // Use in your command
360
- * cli.addCommand({
361
- * name: "build",
362
- * options: [
363
- * { name: "output-dir", type: String },
364
- * { name: "verbose", type: Boolean },
365
- * { name: "port", type: Number }
366
- * ],
367
- * env: [
368
- * { name: "API_KEY", type: String },
369
- * { name: "DEBUG", type: Boolean }
370
- * ],
371
- * execute: ({ options, env }: Toolbox<Console, BuildOptions, BuildEnv>) => {
372
- * // Full autocomplete on options.outputDir, options.verbose, env.apiKey, etc.
373
- * console.log(options.outputDir, options.verbose, env.apiKey);
374
- * }
375
- * });
376
- * ```
377
- */
337
+ * Helper types for creating type-safe commands with autocomplete support.
338
+ * These types help you define your options and environment variables with full TypeScript autocomplete.
339
+ * Use these types to create type-safe Toolbox interfaces for your commands.
340
+ * @example
341
+ * ```typescript
342
+ * import { CreateOptions, CreateEnv, type Toolbox } from '@visulima/cerebro';
343
+ *
344
+ * // Define options with their original names (they'll be converted to camelCase)
345
+ * type BuildOptions = CreateOptions<{
346
+ * "output-dir": string | undefined;
347
+ * "verbose": boolean | undefined;
348
+ * "port": number | undefined;
349
+ * }>;
350
+ * // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
351
+ *
352
+ * // Define environment variables (UPPER_SNAKE_CASE -> camelCase)
353
+ * type BuildEnv = CreateEnv<{
354
+ * "API_KEY": string | undefined;
355
+ * "DEBUG": boolean | undefined;
356
+ * }>;
357
+ * // Result: { apiKey: string | undefined, debug: boolean | undefined }
358
+ *
359
+ * // Use in your command
360
+ * cli.addCommand({
361
+ * name: "build",
362
+ * options: [
363
+ * { name: "output-dir", type: String },
364
+ * { name: "verbose", type: Boolean },
365
+ * { name: "port", type: Number }
366
+ * ],
367
+ * env: [
368
+ * { name: "API_KEY", type: String },
369
+ * { name: "DEBUG", type: Boolean }
370
+ * ],
371
+ * execute: ({ options, env }: Toolbox<Console, BuildOptions, BuildEnv>) => {
372
+ * // Full autocomplete on options.outputDir, options.verbose, env.apiKey, etc.
373
+ * console.log(options.outputDir, options.verbose, env.apiKey);
374
+ * }
375
+ * });
376
+ * ```
377
+ */
378
378
  /**
379
- * Converts option names to camelCase for the options object.
380
- * Options like "output-dir" become "outputDir" in the toolbox.
381
- * @example
382
- * ```typescript
383
- * // Option name: "output-dir" -> options.outputDir
384
- * // Option name: "api_key" -> options.apiKey
385
- * // Option name: "verbose" -> options.verbose
386
- * ```
387
- */
379
+ * Converts option names to camelCase for the options object.
380
+ * Options like "output-dir" become "outputDir" in the toolbox.
381
+ * @example
382
+ * ```typescript
383
+ * // Option name: "output-dir" -> options.outputDir
384
+ * // Option name: "api_key" -> options.apiKey
385
+ * // Option name: "verbose" -> options.verbose
386
+ * ```
387
+ */
388
388
  type OptionNameToCamelCase<T extends string> = T extends `${infer Start}-${infer Rest}` ? `${Lowercase<Start>}${Capitalize<OptionNameToCamelCase<Rest>>}` : T extends `${infer Start}_${infer Rest}` ? `${Lowercase<Start>}${Capitalize<OptionNameToCamelCase<Rest>>}` : Lowercase<T>;
389
389
  /**
390
- * Helper type to create a type-safe options object from option definitions.
391
- * @example
392
- * ```typescript
393
- * type MyOptions = CreateOptions<{
394
- * "output-dir": string | undefined;
395
- * "verbose": boolean | undefined;
396
- * "port": number | undefined;
397
- * }>;
398
- * // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
399
- * ```
400
- */
401
- type CreateOptions<T extends Record<string, unknown>> = { [K in keyof T as OptionNameToCamelCase<K & string>]: T[K] };
390
+ * Helper type to create a type-safe options object from option definitions.
391
+ * @example
392
+ * ```typescript
393
+ * type MyOptions = CreateOptions<{
394
+ * "output-dir": string | undefined;
395
+ * "verbose": boolean | undefined;
396
+ * "port": number | undefined;
397
+ * }>;
398
+ * // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
399
+ * ```
400
+ */
401
+ type CreateOptions<T extends Record<string, unknown>> = { [K in keyof T as OptionNameToCamelCase<K & string>]: T[K]; };
402
402
  /**
403
- * Helper type to create a type-safe environment variables object from env definitions.
404
- * Environment variable names are converted from UPPER_SNAKE_CASE to camelCase.
405
- * @example
406
- * ```typescript
407
- * type MyEnv = CreateEnv<{
408
- * "API_KEY": string | undefined;
409
- * "DEBUG": boolean | undefined;
410
- * }>;
411
- * // Result: { apiKey: string | undefined, debug: boolean | undefined }
412
- * ```
413
- */
414
- type CreateEnv<T extends Record<string, unknown>> = { [K in keyof T as OptionNameToCamelCase<K & string>]: T[K] };
403
+ * Helper type to create a type-safe environment variables object from env definitions.
404
+ * Environment variable names are converted from UPPER_SNAKE_CASE to camelCase.
405
+ * @example
406
+ * ```typescript
407
+ * type MyEnv = CreateEnv<{
408
+ * "API_KEY": string | undefined;
409
+ * "DEBUG": boolean | undefined;
410
+ * }>;
411
+ * // Result: { apiKey: string | undefined, debug: boolean | undefined }
412
+ * ```
413
+ */
414
+ type CreateEnv<T extends Record<string, unknown>> = { [K in keyof T as OptionNameToCamelCase<K & string>]: T[K]; };
415
415
  /**
416
- * Builds a `loader` for commands whose handler lives as a named export in a
417
- * shared handler module (the typical pattern when one file holds multiple
418
- * subcommands' execute functions).
419
- * @example
420
- * ```ts
421
- * // commands/cache/handler.ts
422
- * export const cacheListExecute: CommandExecute<Toolbox> = async (toolbox) => { ... };
423
- * export const cacheCleanExecute: CommandExecute<Toolbox> = async (toolbox) => { ... };
424
- *
425
- * // commands/cache/index.ts
426
- * cli.addCommand({
427
- * name: "list",
428
- * loader: lazyNamed(() => import("./handler"), "cacheListExecute"),
429
- * });
430
- * ```
431
- */
416
+ * Builds a `loader` for commands whose handler lives as a named export in a
417
+ * shared handler module (the typical pattern when one file holds multiple
418
+ * subcommands' execute functions).
419
+ * @example
420
+ * ```ts
421
+ * // commands/cache/handler.ts
422
+ * export const cacheListExecute: CommandExecute<Toolbox> = async (toolbox) => { ... };
423
+ * export const cacheCleanExecute: CommandExecute<Toolbox> = async (toolbox) => { ... };
424
+ *
425
+ * // commands/cache/index.ts
426
+ * cli.addCommand({
427
+ * name: "list",
428
+ * loader: lazyNamed(() => import("./handler"), "cacheListExecute"),
429
+ * });
430
+ * ```
431
+ */
432
432
  declare const lazyNamed: <M extends Record<string, unknown>, K extends keyof M, TContext>(load: () => Promise<M>, key: K) => () => Promise<LazyCommandModule<TContext>>;
433
433
  declare global {
434
434
  namespace Cerebro {
435
435
  /**
436
- * Extend this interface to add custom properties to the Toolbox.
437
- * This allows plugins and extensions to add type-safe properties to the toolbox.
438
- * @example
439
- * ```typescript
440
- * declare global {
441
- * namespace Cerebro {
442
- * interface ExtensionOverrides {
443
- * // Add custom properties with full type safety
444
- * fs: {
445
- * readFile: (path: string) => Promise<string>;
446
- * writeFile: (path: string, content: string) => Promise<void>;
447
- * };
448
- * http: {
449
- * get: <T>(url: string) => Promise<T>;
450
- * post: <T>(url: string, data: unknown) => Promise<T>;
451
- * };
452
- * myCustomUtil: () => void;
453
- * }
454
- * }
455
- * }
456
- *
457
- * // Now in your commands, you get full autocomplete:
458
- * cli.addCommand({
459
- * name: "example",
460
- * execute: ({ fs, http, myCustomUtil }) => {
461
- * // ✅ Full autocomplete and type safety!
462
- * const content = await fs.readFile("file.txt");
463
- * const data = await http.get<MyType>("https://api.example.com");
464
- * myCustomUtil();
465
- * }
466
- * });
467
- * ```
468
- */
436
+ * Extend this interface to add custom properties to the Toolbox.
437
+ * This allows plugins and extensions to add type-safe properties to the toolbox.
438
+ * @example
439
+ * ```typescript
440
+ * declare global {
441
+ * namespace Cerebro {
442
+ * interface ExtensionOverrides {
443
+ * // Add custom properties with full type safety
444
+ * fs: {
445
+ * readFile: (path: string) => Promise<string>;
446
+ * writeFile: (path: string, content: string) => Promise<void>;
447
+ * };
448
+ * http: {
449
+ * get: <T>(url: string) => Promise<T>;
450
+ * post: <T>(url: string, data: unknown) => Promise<T>;
451
+ * };
452
+ * myCustomUtil: () => void;
453
+ * }
454
+ * }
455
+ * }
456
+ *
457
+ * // Now in your commands, you get full autocomplete:
458
+ * cli.addCommand({
459
+ * name: "example",
460
+ * execute: ({ fs, http, myCustomUtil }) => {
461
+ * // ✅ Full autocomplete and type safety!
462
+ * const content = await fs.readFile("file.txt");
463
+ * const data = await http.get<MyType>("https://api.example.com");
464
+ * myCustomUtil();
465
+ * }
466
+ * });
467
+ * ```
468
+ */
469
469
  export interface ExtensionOverrides {}
470
470
  }
471
471
  }
472
472
  /**
473
- * Main entry point for the Cerebro CLI framework.
474
- *
475
- * This module provides a lightweight, extensible CLI framework for building command-line applications.
476
- * It supports plugins, subcommands, argument parsing, help generation, and more.
477
- * @example
478
- * ```typescript
479
- * import { createCerebro } from '@visulima/cerebro';
480
- *
481
- * const cli = createCerebro('my-app', {
482
- * packageName: 'my-app',
483
- * packageVersion: '1.0.0'
484
- * });
485
- *
486
- * cli.addCommand({
487
- * name: 'greet',
488
- * description: 'Greet someone',
489
- * argument: {
490
- * name: 'name',
491
- * description: 'Name to greet',
492
- * type: String
493
- * },
494
- * execute: ({ argument }) => {
495
- * console.log(`Hello, ${argument[0]}!`);
496
- * }
497
- * });
498
- *
499
- * cli.run();
500
- * ```
501
- */
502
- /**
503
- * Creates a new Cerebro CLI instance.
504
- *
505
- * This is the main factory function for creating CLI applications with Cerebro.
506
- * The returned CLI instance can be configured with commands, plugins, and options.
507
- * @template T - The console type (defaults to Console)
508
- * @param name The name of the CLI application
509
- * @param options Configuration options for the CLI
510
- * @returns A configured Cerebro CLI instance
511
- * @example
512
- * ```typescript
513
- * const cli = createCerebro('my-app', {
514
- * packageName: 'my-app',
515
- * packageVersion: '1.0.0'
516
- * });
517
- * ```
518
- */
473
+ * Creates a new Cerebro CLI instance.
474
+ *
475
+ * This is the main factory function for creating CLI applications with Cerebro.
476
+ * The returned CLI instance can be configured with commands, plugins, and options.
477
+ * @template T - The console type (defaults to Console)
478
+ * @param name The name of the CLI application
479
+ * @param options Configuration options for the CLI
480
+ * @returns A configured Cerebro CLI instance
481
+ * @example
482
+ * ```typescript
483
+ * const cli = createCerebro('my-app', {
484
+ * packageName: 'my-app',
485
+ * packageVersion: '1.0.0'
486
+ * });
487
+ * ```
488
+ */
519
489
  declare const createCerebro: <T extends Console = Console>(name: string, options?: CliOptions<T>) => InstanceType<typeof Cli<T>>;
520
490
  export { Cli as Cerebro, type CerebroFs, type Cli$1 as Cli, type CliOptions, type CliRunOptions, type Command, type CommandExecute, type CreateEnv, type CreateOptions, type LazyCommandModule, type OptionDefinition, type OptionNameToCamelCase, type Plugin, type RunCommandOptions, type Toolbox, VERBOSITY_DEBUG, VERBOSITY_NORMAL, VERBOSITY_QUIET, VERBOSITY_VERBOSE, createCerebro, lazyNamed };