hexbus 0.1.0 → 0.2.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 (4) hide show
  1. package/README.md +133 -10
  2. package/dist/index.d.mts +1242 -38
  3. package/dist/index.mjs +990 -283
  4. package/package.json +45 -46
package/dist/index.d.mts CHANGED
@@ -1,312 +1,1516 @@
1
- import color from "picocolors";
2
-
3
1
  //#region src/types.d.ts
4
- type LogLevel = 'error' | 'warn' | 'info' | 'debug';
5
- type FlagType = 'boolean' | 'string' | 'special';
2
+ /**
3
+ * Supported logger verbosity levels.
4
+ *
5
+ * @remarks
6
+ * Levels are ordered from least verbose (`error`) to most verbose (`debug`).
7
+ * `createCliLogger` uses this ordering to decide whether a message should be
8
+ * emitted.
9
+ */
10
+ type LogLevel = "error" | "warn" | "info" | "debug";
11
+ /**
12
+ * Describes how a command-line flag should be parsed.
13
+ *
14
+ * @remarks
15
+ * `special` flags behave like booleans during parsing but usually trigger
16
+ * control flow outside command execution, such as showing help or version
17
+ * output.
18
+ */
19
+ type FlagType = "boolean" | "string" | "special";
20
+ /**
21
+ * Defines a global command-line flag accepted by a Hexbus CLI.
22
+ */
6
23
  interface CliFlag {
24
+ /**
25
+ * Flag aliases accepted on the command line.
26
+ *
27
+ * @example ['--help', '-h']
28
+ */
7
29
  names: string[];
30
+ /**
31
+ * Human-readable explanation shown in generated help output.
32
+ */
8
33
  description: string;
34
+ /**
35
+ * Parser behavior for this flag.
36
+ */
9
37
  type: FlagType;
38
+ /**
39
+ * Whether the flag consumes the following argument as its value.
40
+ */
10
41
  expectsValue: boolean;
42
+ /**
43
+ * Initial value assigned before raw arguments are parsed.
44
+ */
11
45
  defaultValue?: string | boolean;
12
46
  }
47
+ /**
48
+ * Normalized representation of raw CLI arguments.
49
+ */
13
50
  interface ParsedArgs {
51
+ /**
52
+ * Name of the matched top-level command, if the first positional argument
53
+ * matched a registered command.
54
+ */
14
55
  commandName: string | undefined;
56
+ /**
57
+ * Positional arguments remaining after the top-level command name is
58
+ * removed.
59
+ */
15
60
  commandArgs: string[];
61
+ /**
62
+ * Parsed global flags keyed by their primary long name without leading
63
+ * dashes.
64
+ *
65
+ * @example
66
+ * The `--no-telemetry` flag is stored as `no-telemetry`.
67
+ */
16
68
  parsedFlags: Record<string, string | boolean | undefined>;
17
69
  }
70
+ /**
71
+ * Defines a command that can be rendered in help output and executed with a
72
+ * fully resolved CLI context.
73
+ *
74
+ * @remarks
75
+ * Commands are intentionally data-first so product CLIs can build menus,
76
+ * telemetry labels, and nested command trees from the same object. The action
77
+ * receives the resolved context after flags, package manager detection,
78
+ * framework detection, logging, and telemetry have been initialized.
79
+ *
80
+ * @typeParam TContext - CLI context shape required by this command. Extend the
81
+ * base context when a product CLI injects additional services or configuration.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const command: CliCommand = {
86
+ * name: 'init',
87
+ * label: 'Initialize project',
88
+ * hint: 'Scaffold config files',
89
+ * description: 'Creates project configuration files.',
90
+ * async action(context) {
91
+ * context.logger.info(`Running in ${context.projectRoot}`);
92
+ * },
93
+ * };
94
+ * ```
95
+ */
18
96
  interface CliCommand<TContext extends CliContext = CliContext> {
97
+ /**
98
+ * Stable command name accepted on the command line.
99
+ */
19
100
  name: string;
101
+ /**
102
+ * Short display label for menus or selection prompts.
103
+ */
20
104
  label: string;
105
+ /**
106
+ * Compact hint for interactive command menus.
107
+ */
21
108
  hint: string;
109
+ /**
110
+ * Longer explanation used in help output.
111
+ */
22
112
  description: string;
113
+ /**
114
+ * Command implementation.
115
+ *
116
+ * @remarks
117
+ * Throw `CliError` when possible so shared error handling can render
118
+ * catalog hints and documentation links.
119
+ */
23
120
  action: (context: TContext) => Promise<void>;
121
+ /**
122
+ * Optional nested command list consumed by `parseSubcommand` and custom
123
+ * command routers.
124
+ */
24
125
  subcommands?: CliCommand<TContext>[];
126
+ /**
127
+ * Hides the command from generated help and menu UIs without preventing
128
+ * direct execution by a custom router.
129
+ */
25
130
  hidden?: boolean;
26
131
  }
132
+ /**
133
+ * Minimal package metadata loaded from a project's `package.json`.
134
+ */
27
135
  interface PackageInfo {
136
+ /**
137
+ * Package name, or `unknown` when no readable package name exists.
138
+ */
28
139
  name: string;
140
+ /**
141
+ * Package version, or `unknown` when no readable package version exists.
142
+ */
29
143
  version: string;
144
+ /**
145
+ * Additional package.json fields preserved for callers that need them.
146
+ */
30
147
  [key: string]: unknown;
31
148
  }
149
+ /**
150
+ * Result of inspecting project dependencies for a known frontend framework.
151
+ *
152
+ * @typeParam TPackage - Product-specific package identifier selected from a
153
+ * `FrameworkPackageMap`.
154
+ */
32
155
  interface FrameworkDetectionResult<TPackage extends string = string> {
156
+ /**
157
+ * Detected framework display name, or `null` when no supported framework was
158
+ * found.
159
+ */
33
160
  framework: string | null;
161
+ /**
162
+ * Version range read from `package.json` for the detected framework.
163
+ */
34
164
  frameworkVersion: string | null;
165
+ /**
166
+ * Product package identifier associated with the detected framework.
167
+ */
35
168
  pkg: TPackage | null;
169
+ /**
170
+ * Whether any React dependency was found.
171
+ */
36
172
  hasReact: boolean;
173
+ /**
174
+ * React version range read from `package.json`, if present.
175
+ */
37
176
  reactVersion: string | null;
177
+ /**
178
+ * Tailwind CSS version range read from `package.json`, if present.
179
+ */
38
180
  tailwindVersion: string | null;
39
181
  }
40
- type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
182
+ /**
183
+ * Package managers Hexbus can detect and render commands for.
184
+ */
185
+ type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
186
+ /**
187
+ * Package manager command templates resolved for the current project.
188
+ */
41
189
  interface PackageManagerResult {
190
+ /**
191
+ * Detected package manager name.
192
+ */
42
193
  name: PackageManager;
194
+ /**
195
+ * Command used to install existing dependencies.
196
+ */
43
197
  installCommand: string;
198
+ /**
199
+ * Command prefix used to add new dependencies.
200
+ */
44
201
  addCommand: string;
202
+ /**
203
+ * Command prefix used to run package scripts.
204
+ */
45
205
  runCommand: string;
206
+ /**
207
+ * Command prefix used to execute package binaries without installing them
208
+ * globally.
209
+ */
46
210
  execCommand: string;
211
+ /**
212
+ * Optional detected package manager version.
213
+ */
47
214
  version?: string | null;
48
215
  }
216
+ /**
217
+ * User-facing logger abstraction used by Hexbus commands.
218
+ *
219
+ * @remarks
220
+ * The interface mirrors the small subset of logging and prompt output that
221
+ * command authors need. It keeps command code independent from the concrete
222
+ * prompt renderer used by `createCliLogger`.
223
+ */
49
224
  interface CliLogger {
225
+ /**
226
+ * Emits a debug message when the active log level allows debug output.
227
+ */
50
228
  debug(message: string, ...args: unknown[]): void;
229
+ /**
230
+ * Emits an informational message.
231
+ */
51
232
  info(message: string, ...args: unknown[]): void;
233
+ /**
234
+ * Emits a warning message.
235
+ */
52
236
  warn(message: string, ...args: unknown[]): void;
237
+ /**
238
+ * Emits an error message.
239
+ */
53
240
  error(message: string, ...args: unknown[]): void;
241
+ /**
242
+ * Emits an unadorned message without log-level filtering.
243
+ */
54
244
  message(message: string): void;
245
+ /**
246
+ * Renders a note block with optional title.
247
+ */
55
248
  note(content: string, title?: string): void;
249
+ /**
250
+ * Renders a closing message for a completed interaction.
251
+ */
56
252
  outro(message: string): void;
253
+ /**
254
+ * Renders a successful completion message.
255
+ */
57
256
  success(message: string): void;
257
+ /**
258
+ * Renders a failure message and terminates the process.
259
+ *
260
+ * @throws Never returns because it exits the current process.
261
+ */
58
262
  failed(message: string, exitCode?: number): never;
263
+ /**
264
+ * Renders a numbered progress step.
265
+ */
59
266
  step(current: number, total: number, label: string): void;
60
267
  }
268
+ /**
269
+ * Shared process-ending error and cancellation handlers.
270
+ */
61
271
  interface ErrorHandlers {
272
+ /**
273
+ * Normalizes, displays, tracks, and exits for an unknown thrown value.
274
+ */
62
275
  handleError(error: unknown, command: string): never;
276
+ /**
277
+ * Displays a cancellation message and exits successfully.
278
+ */
63
279
  handleCancel(message?: string, context?: {
64
280
  command?: string;
65
281
  stage?: string;
66
282
  }): never;
67
283
  }
284
+ /**
285
+ * Configuration loading helpers attached to a CLI context.
286
+ */
68
287
  interface ConfigManagement {
288
+ /**
289
+ * Loads optional configuration for the current project.
290
+ *
291
+ * @typeParam TConfig - Expected user configuration shape.
292
+ * @returns The parsed config object, or `null` when no config is found.
293
+ */
69
294
  loadConfig<TConfig = unknown>(): Promise<TConfig | null>;
295
+ /**
296
+ * Loads required configuration for the current project.
297
+ *
298
+ * @typeParam TConfig - Expected user configuration shape.
299
+ * @throws `CliError` with `CONFIG_NOT_FOUND` when no config is found.
300
+ */
70
301
  requireConfig<TConfig = unknown>(): Promise<TConfig>;
302
+ /**
303
+ * Reads TypeScript-style path aliases from configuration when supported.
304
+ *
305
+ * @remarks
306
+ * The default Hexbus context currently returns `null`; product CLIs can
307
+ * override this method when they provide config-aware file resolution.
308
+ */
71
309
  getPathAliases(configPath?: string): Record<string, string> | null;
72
310
  }
311
+ /**
312
+ * File-system helpers rooted in the detected project.
313
+ */
73
314
  interface FileSystemUtils {
315
+ /**
316
+ * Reads project package metadata.
317
+ */
74
318
  getPackageInfo(): PackageInfo;
319
+ /**
320
+ * Tests whether a file-system path exists.
321
+ */
75
322
  exists(path: string): Promise<boolean>;
323
+ /**
324
+ * Reads a UTF-8 text file.
325
+ */
76
326
  read(path: string): Promise<string>;
327
+ /**
328
+ * Writes a UTF-8 text file.
329
+ */
77
330
  write(path: string, content: string): Promise<void>;
331
+ /**
332
+ * Creates a directory and any missing parents.
333
+ */
78
334
  mkdir(path: string): Promise<void>;
79
335
  }
336
+ /**
337
+ * Telemetry client used by CLI lifecycle and command code.
338
+ *
339
+ * @remarks
340
+ * The built-in implementation queues events in memory and flushes them only
341
+ * when an endpoint is configured. Commands should treat telemetry as best
342
+ * effort and never depend on it for core behavior.
343
+ */
80
344
  interface Telemetry {
345
+ /**
346
+ * Queues a named telemetry event.
347
+ */
81
348
  trackEvent(eventName: string, properties?: Record<string, unknown>): void;
349
+ /**
350
+ * Queues a standardized command invocation event.
351
+ */
82
352
  trackCommand(command: string, args?: string[], flags?: Record<string, string | number | boolean | undefined>): void;
353
+ /**
354
+ * Queues a standardized error event.
355
+ */
83
356
  trackError(error: Error, command?: string): void;
357
+ /**
358
+ * Sends queued events when possible and clears the local queue.
359
+ */
84
360
  flush(): Promise<void>;
361
+ /**
362
+ * Starts an immediate best-effort flush without requiring callers to await it.
363
+ *
364
+ * @remarks
365
+ * Entrypoints can call this before short-lived process exits. Implementations
366
+ * should not throw from this method.
367
+ */
368
+ flushBackground(): void;
369
+ /**
370
+ * Performs final telemetry cleanup before process exit.
371
+ */
85
372
  shutdown(): Promise<void>;
373
+ /**
374
+ * Indicates whether this telemetry instance is disabled.
375
+ */
86
376
  isDisabled(): boolean;
87
377
  }
378
+ /**
379
+ * Fully resolved execution context passed to command actions.
380
+ *
381
+ * @remarks
382
+ * `createCliContext` builds this object once per invocation after parsing raw
383
+ * arguments, detecting the project root, selecting framework/package-manager
384
+ * metadata, and initializing logger, config, file-system, and telemetry
385
+ * services.
386
+ *
387
+ * @typeParam TPackage - Product-specific package identifier selected during
388
+ * framework detection.
389
+ */
88
390
  interface CliContext<TPackage extends string = string> {
391
+ /**
392
+ * Logger for command output.
393
+ */
89
394
  logger: CliLogger;
90
- flags: ParsedArgs['parsedFlags'];
395
+ /**
396
+ * Parsed global flags keyed by primary flag name.
397
+ */
398
+ flags: ParsedArgs["parsedFlags"];
399
+ /**
400
+ * Matched top-level command name, if one was provided.
401
+ */
91
402
  commandName: string | undefined;
403
+ /**
404
+ * Positional arguments remaining after command parsing.
405
+ */
92
406
  commandArgs: string[];
407
+ /**
408
+ * Original working directory where context creation began.
409
+ */
93
410
  cwd: string;
411
+ /**
412
+ * Shared process-ending error handlers.
413
+ */
94
414
  error: ErrorHandlers;
415
+ /**
416
+ * Configuration loading helpers.
417
+ */
95
418
  config: ConfigManagement;
419
+ /**
420
+ * File-system helpers rooted at `projectRoot`.
421
+ */
96
422
  fs: FileSystemUtils;
423
+ /**
424
+ * Telemetry client for lifecycle and command events.
425
+ */
97
426
  telemetry: Telemetry;
427
+ /**
428
+ * Prompts the user to confirm an action.
429
+ *
430
+ * @remarks
431
+ * Returns `true` without prompting when `-y` or `--yes` was provided.
432
+ */
98
433
  confirm(message: string, initialValue?: boolean): Promise<boolean>;
434
+ /**
435
+ * Nearest ancestor directory containing `package.json`, or `cwd` when none
436
+ * was found.
437
+ */
99
438
  projectRoot: string;
439
+ /**
440
+ * Framework and package selection metadata for the detected project.
441
+ */
100
442
  framework: FrameworkDetectionResult<TPackage>;
443
+ /**
444
+ * Package manager commands for the detected project.
445
+ */
101
446
  packageManager: PackageManagerResult;
102
447
  }
103
448
  //#endregion
104
449
  //#region src/context.d.ts
450
+ /**
451
+ * Options used to build a complete CLI execution context.
452
+ *
453
+ * @typeParam TPackage - Product-specific package identifier selected by
454
+ * framework detection.
455
+ */
105
456
  interface CreateContextOptions<TPackage extends string = string> {
457
+ /**
458
+ * Raw process arguments after the executable and script path have been
459
+ * removed.
460
+ *
461
+ * @example process.argv.slice(2)
462
+ */
106
463
  rawArgs: string[];
464
+ /**
465
+ * Directory where invocation started.
466
+ *
467
+ * @default process.cwd()
468
+ */
107
469
  cwd?: string;
470
+ /**
471
+ * Top-level commands used to identify `commandName` during argument parsing.
472
+ */
108
473
  commands: CliCommand[];
474
+ /**
475
+ * Global flags parsed before command execution.
476
+ *
477
+ * @remarks
478
+ * Pass this when a product CLI needs extra global flags while keeping Hexbus'
479
+ * parser and context bootstrap.
480
+ */
481
+ globalFlags?: CliFlag[];
482
+ /**
483
+ * Application name used for config lookup, telemetry defaults, and logger
484
+ * metadata.
485
+ *
486
+ * @default "cli"
487
+ */
109
488
  appName?: string;
489
+ /**
490
+ * Config name passed to `c12` when loading project configuration.
491
+ *
492
+ * @default appName
493
+ */
110
494
  configName?: string;
495
+ /**
496
+ * Telemetry configuration for the context.
497
+ */
111
498
  telemetry?: {
499
+ /**
500
+ * Disables telemetry regardless of command-line flags or environment
501
+ * variables.
502
+ */
112
503
  disabled?: boolean;
504
+ /**
505
+ * Emits queued telemetry payloads through the logger debug channel.
506
+ */
113
507
  debug?: boolean;
508
+ /**
509
+ * HTTP endpoint that receives flushed telemetry batches.
510
+ */
114
511
  endpoint?: string;
512
+ /**
513
+ * Environment variable prefix used to read telemetry opt-out flags.
514
+ *
515
+ * @remarks
516
+ * A prefix of `MY_CLI` reads `MY_CLI_TELEMETRY_DISABLED`.
517
+ */
115
518
  envVarPrefix?: string;
519
+ /**
520
+ * Properties merged into every telemetry event created by this context.
521
+ */
116
522
  defaultProperties?: Record<string, unknown>;
117
523
  };
524
+ /**
525
+ * Product package identifiers selected for framework-specific installs.
526
+ */
118
527
  packageMap?: {
528
+ /**
529
+ * Package used when no React framework is detected.
530
+ */
119
531
  core?: TPackage;
532
+ /**
533
+ * Package used for generic React-compatible projects.
534
+ */
120
535
  react?: TPackage;
536
+ /**
537
+ * Package used for Next.js projects.
538
+ */
121
539
  next?: TPackage;
122
540
  };
541
+ /**
542
+ * Allows package-manager detection to prompt when lockfile and package.json
543
+ * detection fail.
544
+ *
545
+ * @default false
546
+ */
123
547
  interactivePackageManagerDetection?: boolean;
124
548
  }
549
+ /**
550
+ * Creates the resolved context passed to command actions.
551
+ *
552
+ * @remarks
553
+ * Context creation performs the standard CLI bootstrap sequence: parse global
554
+ * flags, create the logger, detect the project root, detect framework and
555
+ * package manager metadata, set up telemetry, and attach helpers for config
556
+ * loading, file-system access, confirmation prompts, and process-ending error
557
+ * handling.
558
+ *
559
+ * @typeParam TPackage - Product-specific package identifier returned from
560
+ * framework detection.
561
+ * @param options - Context creation options for the current invocation.
562
+ * @returns A fully initialized `CliContext`.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * const context = await createCliContext({
567
+ * rawArgs: process.argv.slice(2),
568
+ * appName: 'acme',
569
+ * commands,
570
+ * });
571
+ *
572
+ * await commands.find((command) => command.name === context.commandName)
573
+ * ?.action(context);
574
+ * ```
575
+ */
125
576
  declare function createCliContext<TPackage extends string = string>(options: CreateContextOptions<TPackage>): Promise<CliContext<TPackage>>;
577
+ /**
578
+ * Creates a deterministic context for unit tests.
579
+ *
580
+ * @remarks
581
+ * The test context disables telemetry, uses an error-only logger, avoids real
582
+ * framework or package-manager detection, and provides no-op file-system
583
+ * helpers. Pass overrides to replace only the services a test needs.
584
+ *
585
+ * @param overrides - Partial context fields to merge into the default test
586
+ * context.
587
+ * @returns A `CliContext` suitable for command and helper tests.
588
+ *
589
+ * @example
590
+ * ```ts
591
+ * const context = createTestContext({
592
+ * flags: { force: true },
593
+ * commandName: 'init',
594
+ * });
595
+ * ```
596
+ */
126
597
  declare function createTestContext(overrides?: Partial<CliContext>): CliContext;
127
598
  //#endregion
128
599
  //#region src/detection.d.ts
600
+ /**
601
+ * Product package identifiers to select after framework detection.
602
+ *
603
+ * @remarks
604
+ * Use this map when a product CLI installs different packages for core,
605
+ * React, or Next.js projects.
606
+ *
607
+ * @typeParam TPackage - Product-specific package identifier.
608
+ */
129
609
  interface FrameworkPackageMap<TPackage extends string = string> {
610
+ /**
611
+ * Package identifier used when no React framework is detected.
612
+ */
130
613
  core?: TPackage;
614
+ /**
615
+ * Package identifier used for React-compatible projects.
616
+ */
131
617
  react?: TPackage;
618
+ /**
619
+ * Package identifier used specifically for Next.js projects.
620
+ */
132
621
  next?: TPackage;
133
622
  }
623
+ /**
624
+ * Detects common frontend frameworks from project dependencies.
625
+ *
626
+ * @remarks
627
+ * Detection reads the nearest project's `package.json` and looks at
628
+ * dependencies and devDependencies. It recognizes Next.js, Remix, Vite React,
629
+ * Gatsby, generic React, Tailwind CSS, and a configured core fallback.
630
+ *
631
+ * @typeParam TPackage - Product-specific package identifier returned in
632
+ * `FrameworkDetectionResult.pkg`.
633
+ * @param projectRoot - Directory containing the package.json to inspect.
634
+ * @param logger - Optional logger for debug diagnostics.
635
+ * @param packageMap - Product packages to select for detected frameworks.
636
+ * @returns Framework metadata and the selected product package identifier.
637
+ */
134
638
  declare function detectFramework<TPackage extends string = string>(projectRoot: string, logger?: CliLogger, packageMap?: FrameworkPackageMap<TPackage>): Promise<FrameworkDetectionResult<TPackage>>;
639
+ /**
640
+ * Finds the nearest project root by walking up to a package.json.
641
+ *
642
+ * @remarks
643
+ * The search is capped at ten directory levels to avoid surprising filesystem
644
+ * traversal. When no root is found, the original current working directory is
645
+ * returned and a warning is logged.
646
+ *
647
+ * @param cwd - Directory where invocation started.
648
+ * @param logger - Optional logger for warning output.
649
+ * @returns The detected project root or `cwd` as a fallback.
650
+ */
135
651
  declare function detectProjectRoot(cwd: string, logger?: CliLogger): Promise<string>;
652
+ /**
653
+ * Detects the package manager used by a project.
654
+ *
655
+ * @remarks
656
+ * Detection prefers lockfiles, then the `packageManager` field in
657
+ * `package.json`, then an optional interactive prompt, and finally `npm`.
658
+ *
659
+ * @param projectRoot - Directory to inspect for lockfiles and package.json.
660
+ * @param logger - Optional logger for debug output.
661
+ * @param options - Detection options.
662
+ * @returns Command templates for the detected package manager.
663
+ *
664
+ * @throws When interactive prompting is enabled and the user cancels package
665
+ * manager selection.
666
+ */
136
667
  declare function detectPackageManager(projectRoot: string, logger?: CliLogger, options?: {
137
668
  interactive?: boolean;
138
669
  }): Promise<PackageManagerResult>;
670
+ /**
671
+ * Builds a dependency installation command for the detected package manager.
672
+ *
673
+ * @param pm - Package manager command templates.
674
+ * @param packages - Package names to install.
675
+ * @param options - Install command options.
676
+ * @returns A shell command string suitable for display or execution.
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * getInstallCommand(pm, ['typescript'], { dev: true });
681
+ * ```
682
+ */
139
683
  declare function getInstallCommand(pm: PackageManagerResult, packages: string[], options?: {
140
684
  dev?: boolean;
141
685
  }): string;
686
+ /**
687
+ * Builds a package-script command for the detected package manager.
688
+ *
689
+ * @param pm - Package manager command templates.
690
+ * @param script - Package script name to run.
691
+ * @returns A shell command string.
692
+ */
142
693
  declare function getRunCommand(pm: PackageManagerResult, script: string): string;
694
+ /**
695
+ * Builds a one-off binary execution command for the detected package manager.
696
+ *
697
+ * @param pm - Package manager command templates.
698
+ * @param binary - Binary name to execute.
699
+ * @param args - Optional arguments appended after the binary name.
700
+ * @returns A shell command string.
701
+ */
143
702
  declare function getExecCommand(pm: PackageManagerResult, binary: string, args?: string[]): string;
144
703
  //#endregion
145
704
  //#region src/errors.d.ts
705
+ /**
706
+ * Metadata used to render a known CLI error.
707
+ */
146
708
  interface ErrorCatalogEntry {
709
+ /**
710
+ * Stable machine-readable error code.
711
+ */
147
712
  code: string;
713
+ /**
714
+ * User-facing error message.
715
+ */
148
716
  message: string;
717
+ /**
718
+ * Optional recovery guidance displayed after the message.
719
+ */
149
720
  hint?: string;
721
+ /**
722
+ * Optional documentation URL displayed after the hint.
723
+ */
150
724
  docs?: string;
151
725
  }
726
+ /**
727
+ * Error catalog keyed by stable error code.
728
+ */
152
729
  type ErrorCatalog = Record<string, ErrorCatalogEntry>;
730
+ /**
731
+ * Built-in errors used by the Hexbus runtime.
732
+ */
153
733
  declare const DEFAULT_ERROR_CATALOG: {
734
+ readonly CANCELLED: {
735
+ readonly code: "CANCELLED";
736
+ readonly message: "Operation cancelled";
737
+ };
738
+ readonly COMMAND_NOT_FOUND: {
739
+ readonly code: "COMMAND_NOT_FOUND";
740
+ readonly hint: "Run --help to see available commands";
741
+ readonly message: "Unknown command";
742
+ };
154
743
  readonly CONFIG_NOT_FOUND: {
155
744
  readonly code: "CONFIG_NOT_FOUND";
156
- readonly message: "Configuration not found";
157
745
  readonly hint: "Run the setup command to create a configuration";
746
+ readonly message: "Configuration not found";
158
747
  };
159
748
  readonly FLAG_VALUE_REQUIRED: {
160
749
  readonly code: "FLAG_VALUE_REQUIRED";
161
750
  readonly message: "Flag requires a value";
162
751
  };
163
- readonly COMMAND_NOT_FOUND: {
164
- readonly code: "COMMAND_NOT_FOUND";
165
- readonly message: "Unknown command";
166
- readonly hint: "Run --help to see available commands";
167
- };
168
- readonly CANCELLED: {
169
- readonly code: "CANCELLED";
170
- readonly message: "Operation cancelled";
171
- };
172
752
  readonly UNKNOWN_ERROR: {
173
753
  readonly code: "UNKNOWN_ERROR";
174
754
  readonly message: "An unexpected error occurred";
175
755
  };
176
756
  };
757
+ /**
758
+ * Adds or replaces entries in the active error catalog.
759
+ *
760
+ * @remarks
761
+ * This mutates process-local catalog state. Product CLIs should call it once
762
+ * during startup before command actions create `CliError` instances.
763
+ *
764
+ * @param entries - Error entries keyed by their stable code.
765
+ *
766
+ * @example
767
+ * ```ts
768
+ * extendErrorCatalog({
769
+ * PROJECT_NOT_READY: {
770
+ * code: 'PROJECT_NOT_READY',
771
+ * message: 'Project is not ready',
772
+ * hint: 'Run init before running this command.',
773
+ * },
774
+ * });
775
+ * ```
776
+ */
177
777
  declare function extendErrorCatalog(entries: ErrorCatalog): void;
778
+ /**
779
+ * Built-in or product-defined CLI error code.
780
+ */
178
781
  type ErrorCode = keyof typeof DEFAULT_ERROR_CATALOG | string;
782
+ /**
783
+ * Error type that carries a catalog entry and optional structured context.
784
+ *
785
+ * @remarks
786
+ * `CliError` keeps command code focused on stable error codes while shared
787
+ * handlers render the configured message, hint, and documentation link.
788
+ */
179
789
  declare class CliError extends Error {
790
+ /**
791
+ * Error code requested by the caller.
792
+ */
180
793
  readonly code: ErrorCode;
794
+ /**
795
+ * Structured diagnostic details attached by the caller.
796
+ */
181
797
  readonly context?: Record<string, unknown>;
798
+ /**
799
+ * Catalog entry used to render this error.
800
+ */
182
801
  readonly entry: ErrorCatalogEntry;
802
+ /**
803
+ * Creates a catalog-backed CLI error.
804
+ *
805
+ * @param code - Built-in or product-defined error code.
806
+ * @param context - Optional diagnostic details for rendering or telemetry.
807
+ */
183
808
  constructor(code: ErrorCode, context?: Record<string, unknown>);
809
+ /**
810
+ * Renders the error message, hint, and docs link through a logger.
811
+ *
812
+ * @param logger - Logger used for user-facing output.
813
+ */
184
814
  display(logger: CliLogger): void;
815
+ /**
816
+ * Normalizes an unknown thrown value into a `CliError`.
817
+ *
818
+ * @param error - Value caught from a `try`/`catch` block.
819
+ * @param fallbackCode - Catalog code to use when `error` is not already a
820
+ * `CliError`.
821
+ * @returns `error` unchanged when it is already a `CliError`, otherwise a
822
+ * wrapped `CliError`.
823
+ */
185
824
  static from(error: unknown, fallbackCode?: ErrorCode): CliError;
186
825
  }
826
+ /**
827
+ * Narrows an unknown value to a `CliError`.
828
+ *
829
+ * @param error - Value to inspect.
830
+ * @param code - Optional code that must match the error.
831
+ * @returns `true` when the value is a `CliError` and, if provided, matches the
832
+ * requested code.
833
+ */
187
834
  declare function isCliError(error: unknown, code?: ErrorCode): error is CliError;
835
+ /**
836
+ * Creates shared process-ending error and cancellation handlers.
837
+ *
838
+ * @param logger - Logger used to render messages.
839
+ * @param telemetry - Optional telemetry sink for failed command errors.
840
+ * @returns Error handlers suitable for `CliContext.error`.
841
+ */
188
842
  declare function createErrorHandlers(logger: CliLogger, telemetry?: {
189
843
  trackError(error: Error, command?: string): void;
190
844
  }): {
191
- handleError(error: unknown, command: string): never;
192
845
  handleCancel(message?: string, context?: {
193
846
  command?: string;
194
847
  stage?: string;
195
848
  }): never;
849
+ handleError(error: unknown, command: string): never;
196
850
  };
851
+ /**
852
+ * Wraps an async function with CLI-style error rendering and process exit.
853
+ *
854
+ * @remarks
855
+ * This helper is useful near process entrypoints. Library-style code should
856
+ * usually throw `CliError` and let the caller decide when to exit.
857
+ *
858
+ * @typeParam T - Async function type to preserve.
859
+ * @param fn - Async function to run.
860
+ * @param logger - Logger used to render caught errors.
861
+ * @param context - Optional command metadata shown after an error.
862
+ * @returns A function with the same call signature as `fn`.
863
+ */
197
864
  declare function withErrorHandling<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, logger: CliLogger, context?: {
198
865
  command?: string;
199
866
  }): T;
200
867
  //#endregion
201
868
  //#region src/help.d.ts
869
+ /**
870
+ * Metadata shown in the generated CLI help menu.
871
+ */
202
872
  interface ShowHelpMenuOptions {
873
+ /**
874
+ * CLI application name shown in usage and title text.
875
+ */
203
876
  appName: string;
877
+ /**
878
+ * CLI version shown near the top of the help menu.
879
+ */
204
880
  version: string;
881
+ /**
882
+ * Optional documentation URL shown after commands and global flags.
883
+ */
205
884
  docsUrl?: string;
206
885
  }
207
- declare function showHelpMenu(context: Pick<CliContext, 'logger'>, options: ShowHelpMenuOptions, commands: CliCommand[], flags: CliFlag[]): void;
886
+ /**
887
+ * Renders a help menu for commands and global flags.
888
+ *
889
+ * @param context - Context subset providing the logger used for output.
890
+ * @param options - Application metadata for the help menu.
891
+ * @param commands - Commands to list; commands with `hidden: true` are
892
+ * omitted.
893
+ * @param flags - Global flags to list.
894
+ */
895
+ declare function showHelpMenu(context: Pick<CliContext, "logger">, options: ShowHelpMenuOptions, commands: CliCommand[], flags: CliFlag[]): void;
208
896
  //#endregion
209
897
  //#region src/intro.d.ts
898
+ /**
899
+ * Options for rendering a CLI intro banner.
900
+ */
210
901
  interface DisplayIntroOptions {
902
+ /**
903
+ * Application name used as the note title and default banner text.
904
+ */
211
905
  appName: string;
906
+ /**
907
+ * Optional application version shown in the fallback tagline.
908
+ */
212
909
  version?: string;
910
+ /**
911
+ * Optional tagline shown below the banner.
912
+ */
213
913
  tagline?: string;
914
+ /**
915
+ * Optional text passed to figlet instead of `appName`.
916
+ */
214
917
  figletText?: string;
215
918
  }
216
- declare function displayIntro(context: Pick<CliContext, 'logger'>, options: DisplayIntroOptions): Promise<void>;
919
+ /**
920
+ * Renders a figlet banner and short intro note.
921
+ *
922
+ * @remarks
923
+ * If figlet rendering fails, the plain banner text is displayed instead.
924
+ *
925
+ * @param context - Context subset providing the logger used for output.
926
+ * @param options - Intro banner metadata.
927
+ */
928
+ declare function displayIntro(context: Pick<CliContext, "logger">, options: DisplayIntroOptions): Promise<void>;
929
+ //#endregion
930
+ //#region src/color.d.ts
931
+ /**
932
+ * Formats an arbitrary value as a string, optionally wrapping it in ANSI
933
+ * escape codes.
934
+ */
935
+ type ColorFormatter = (input: unknown) => string;
936
+ /**
937
+ * Collection of ANSI style and color formatters.
938
+ *
939
+ * @remarks
940
+ * When color is disabled, every formatter returns the input converted with
941
+ * `String(input)` and does not add escape codes.
942
+ */
943
+ interface Colors {
944
+ /**
945
+ * Whether this formatter set emits ANSI escape codes.
946
+ */
947
+ isColorSupported: boolean;
948
+ /** Resets all ANSI styles. */
949
+ reset: ColorFormatter;
950
+ /** Applies bold text styling. */
951
+ bold: ColorFormatter;
952
+ /** Applies dim text styling. */
953
+ dim: ColorFormatter;
954
+ /** Applies italic text styling. */
955
+ italic: ColorFormatter;
956
+ /** Applies underline text styling. */
957
+ underline: ColorFormatter;
958
+ /** Applies inverse foreground/background styling. */
959
+ inverse: ColorFormatter;
960
+ /** Applies hidden text styling. */
961
+ hidden: ColorFormatter;
962
+ /** Applies strikethrough text styling. */
963
+ strikethrough: ColorFormatter;
964
+ /** Applies black foreground color. */
965
+ black: ColorFormatter;
966
+ /** Applies red foreground color. */
967
+ red: ColorFormatter;
968
+ /** Applies green foreground color. */
969
+ green: ColorFormatter;
970
+ /** Applies yellow foreground color. */
971
+ yellow: ColorFormatter;
972
+ /** Applies blue foreground color. */
973
+ blue: ColorFormatter;
974
+ /** Applies magenta foreground color. */
975
+ magenta: ColorFormatter;
976
+ /** Applies cyan foreground color. */
977
+ cyan: ColorFormatter;
978
+ /** Applies white foreground color. */
979
+ white: ColorFormatter;
980
+ /** Applies gray foreground color. */
981
+ gray: ColorFormatter;
982
+ /** Applies black background color. */
983
+ bgBlack: ColorFormatter;
984
+ /** Applies red background color. */
985
+ bgRed: ColorFormatter;
986
+ /** Applies green background color. */
987
+ bgGreen: ColorFormatter;
988
+ /** Applies yellow background color. */
989
+ bgYellow: ColorFormatter;
990
+ /** Applies blue background color. */
991
+ bgBlue: ColorFormatter;
992
+ /** Applies magenta background color. */
993
+ bgMagenta: ColorFormatter;
994
+ /** Applies cyan background color. */
995
+ bgCyan: ColorFormatter;
996
+ /** Applies white background color. */
997
+ bgWhite: ColorFormatter;
998
+ /** Applies bright black foreground color. */
999
+ blackBright: ColorFormatter;
1000
+ /** Applies bright red foreground color. */
1001
+ redBright: ColorFormatter;
1002
+ /** Applies bright green foreground color. */
1003
+ greenBright: ColorFormatter;
1004
+ /** Applies bright yellow foreground color. */
1005
+ yellowBright: ColorFormatter;
1006
+ /** Applies bright blue foreground color. */
1007
+ blueBright: ColorFormatter;
1008
+ /** Applies bright magenta foreground color. */
1009
+ magentaBright: ColorFormatter;
1010
+ /** Applies bright cyan foreground color. */
1011
+ cyanBright: ColorFormatter;
1012
+ /** Applies bright white foreground color. */
1013
+ whiteBright: ColorFormatter;
1014
+ /** Applies bright black background color. */
1015
+ bgBlackBright: ColorFormatter;
1016
+ /** Applies bright red background color. */
1017
+ bgRedBright: ColorFormatter;
1018
+ /** Applies bright green background color. */
1019
+ bgGreenBright: ColorFormatter;
1020
+ /** Applies bright yellow background color. */
1021
+ bgYellowBright: ColorFormatter;
1022
+ /** Applies bright blue background color. */
1023
+ bgBlueBright: ColorFormatter;
1024
+ /** Applies bright magenta background color. */
1025
+ bgMagentaBright: ColorFormatter;
1026
+ /** Applies bright cyan background color. */
1027
+ bgCyanBright: ColorFormatter;
1028
+ /** Applies bright white background color. */
1029
+ bgWhiteBright: ColorFormatter;
1030
+ }
1031
+ /**
1032
+ * Default color formatter object plus a factory for creating formatter sets
1033
+ * with explicit color support.
1034
+ */
1035
+ type Color = Colors & {
1036
+ createColors: typeof createColors;
1037
+ };
1038
+ /**
1039
+ * Creates a complete set of color and style formatters.
1040
+ *
1041
+ * @param enabled - Whether returned formatters should emit ANSI escape codes.
1042
+ * @returns A `Colors` object with either active ANSI formatters or plain string
1043
+ * pass-through formatters.
1044
+ */
1045
+ declare function createColors(enabled?: boolean): Colors;
1046
+ /**
1047
+ * Default color formatter set for the current process.
1048
+ *
1049
+ * @remarks
1050
+ * Use `color.createColors(false)` when tests need deterministic plain-text
1051
+ * output.
1052
+ */
1053
+ declare const color: Color;
217
1054
  //#endregion
218
1055
  //#region src/logger.d.ts
1056
+ /**
1057
+ * Supported log levels in ascending verbosity.
1058
+ */
219
1059
  declare const LOG_LEVELS: LogLevel[];
1060
+ /**
1061
+ * Alias for `LOG_LEVELS` kept for callers that prefer validation-oriented
1062
+ * naming.
1063
+ */
220
1064
  declare const validLogLevels: LogLevel[];
221
- declare function formatLogMessage(logLevel: LogLevel | 'success' | 'failed' | string, message: unknown, args?: unknown[]): string;
222
- declare function logMessage(logLevel: LogLevel | 'success' | 'failed' | string, message: unknown, ...args: unknown[]): void;
1065
+ /**
1066
+ * Formats a log message with a level badge and optional structured arguments.
1067
+ *
1068
+ * @param logLevel - Log level or custom badge label.
1069
+ * @param message - Primary message to render.
1070
+ * @param args - Additional values rendered as indented JSON-like bullets.
1071
+ * @returns A formatted message string.
1072
+ */
1073
+ declare function formatLogMessage(logLevel: LogLevel | "success" | "failed" | string, message: unknown, args?: unknown[]): string;
1074
+ /**
1075
+ * Emits a formatted message through the prompt logger.
1076
+ *
1077
+ * @param logLevel - Log level or custom badge label.
1078
+ * @param message - Primary message to render.
1079
+ * @param args - Additional values rendered below the message.
1080
+ */
1081
+ declare function logMessage(logLevel: LogLevel | "success" | "failed" | string, message: unknown, ...args: unknown[]): void;
1082
+ /**
1083
+ * Formats a bounded progress step indicator.
1084
+ *
1085
+ * @remarks
1086
+ * `current` is clamped between `0` and `total`, and `total` is clamped to at
1087
+ * least `0` so malformed progress values still render predictably.
1088
+ *
1089
+ * @param current - Current step number.
1090
+ * @param total - Total number of steps.
1091
+ * @param label - Step label shown after the progress bar.
1092
+ * @returns A formatted progress row.
1093
+ */
223
1094
  declare function formatStep(current: number, total: number, label: string): string;
1095
+ /**
1096
+ * Creates a `CliLogger` backed by Clack prompt output.
1097
+ *
1098
+ * @remarks
1099
+ * Messages below the configured verbosity are ignored for `debug`, `info`,
1100
+ * `warn`, and `error`. Other output helpers such as `message`, `note`,
1101
+ * `success`, `failed`, and `outro` always render because they represent
1102
+ * explicit user interaction states rather than diagnostic verbosity.
1103
+ *
1104
+ * @param level - Minimum log level to emit.
1105
+ * @returns A logger suitable for `CliContext.logger`.
1106
+ */
224
1107
  declare function createCliLogger(level?: LogLevel): CliLogger;
225
1108
  //#endregion
226
1109
  //#region src/parser.d.ts
1110
+ /**
1111
+ * Built-in flags parsed for every Hexbus CLI invocation.
1112
+ *
1113
+ * @remarks
1114
+ * Primary flag names are derived from the first long flag in each entry. For
1115
+ * example, `--no-telemetry` is exposed as `parsedFlags['no-telemetry']`.
1116
+ */
227
1117
  declare const globalFlags: CliFlag[];
228
- declare function parseCliArgs(rawArgs: string[], commands: CliCommand[]): ParsedArgs;
1118
+ /**
1119
+ * Parses raw command-line arguments into command name, command args, and
1120
+ * global and caller-provided flags.
1121
+ *
1122
+ * @remarks
1123
+ * Flags declared in `globalFlags` and `flags` are parsed. Unknown flags and
1124
+ * other positional arguments are preserved as command arguments. If the first
1125
+ * positional argument matches a registered top-level command in `commands`, it
1126
+ * is returned as `commandName` and removed from `commandArgs`.
1127
+ *
1128
+ * @param rawArgs - Arguments after the executable and script path.
1129
+ * @param commands - Top-level commands used to identify the command name.
1130
+ * @param flags - Additional global flag definitions to parse alongside
1131
+ * `globalFlags`. Caller-provided flags override built-in definitions that use
1132
+ * the same primary flag name.
1133
+ * @returns Normalized parsed output containing the matched command name,
1134
+ * remaining command arguments, and parsed flag values keyed by primary name.
1135
+ *
1136
+ * @example
1137
+ * ```ts
1138
+ * const parsed = parseCliArgs(['init', '--logger', 'debug'], commands);
1139
+ * // parsed.commandName === 'init'
1140
+ * // parsed.parsedFlags.logger === 'debug'
1141
+ * ```
1142
+ */
1143
+ declare function parseCliArgs(rawArgs: string[], commands: CliCommand[], flags?: CliFlag[]): ParsedArgs;
1144
+ /**
1145
+ * Formats a single flag for display in help output.
1146
+ *
1147
+ * @param flag - Flag definition to render.
1148
+ * @returns A help row containing names, value hint, and description.
1149
+ */
229
1150
  declare function formatFlagHelp(flag: CliFlag): string;
230
- declare function generateFlagsHelp(): string;
231
- declare function hasFlag(flags: ParsedArgs['parsedFlags'], name: string): boolean;
232
- declare function getFlagValue(flags: ParsedArgs['parsedFlags'], name: string): string | undefined;
1151
+ /**
1152
+ * Formats a provided set of flags for help output.
1153
+ *
1154
+ * @param flags - Flag definitions to render with `formatFlagHelp`, defaulting
1155
+ * to `globalFlags`.
1156
+ *
1157
+ * @returns Newline-delimited help rows for the provided flag definitions.
1158
+ */
1159
+ declare function generateFlagsHelp(flags?: CliFlag[]): string;
1160
+ /**
1161
+ * Checks whether a parsed boolean flag is enabled.
1162
+ *
1163
+ * @param flags - Parsed flag map from `parseCliArgs` or `CliContext`.
1164
+ * @param name - Primary flag name without leading dashes.
1165
+ * @returns `true` only when the flag value is exactly `true`.
1166
+ *
1167
+ * @example
1168
+ * ```ts
1169
+ * if (hasFlag(context.flags, 'force')) {
1170
+ * // overwrite existing files
1171
+ * }
1172
+ * ```
1173
+ */
1174
+ declare function hasFlag(flags: ParsedArgs["parsedFlags"], name: string): boolean;
1175
+ /**
1176
+ * Reads a string-valued flag from a parsed flag map.
1177
+ *
1178
+ * @param flags - Parsed flag map from `parseCliArgs` or `CliContext`.
1179
+ * @param name - Primary flag name without leading dashes.
1180
+ * @returns The flag value when it is a string, otherwise `undefined`.
1181
+ */
1182
+ declare function getFlagValue(flags: ParsedArgs["parsedFlags"], name: string): string | undefined;
1183
+ /**
1184
+ * Splits command arguments into an optional nested subcommand and remaining
1185
+ * args.
1186
+ *
1187
+ * @param args - Positional command arguments to inspect.
1188
+ * @param subcommands - Available subcommands for the current command.
1189
+ * @returns The matched subcommand, if any, plus arguments after the subcommand
1190
+ * name.
1191
+ *
1192
+ * @example
1193
+ * ```ts
1194
+ * const { subcommand, remainingArgs } = parseSubcommand(
1195
+ * context.commandArgs,
1196
+ * command.subcommands ?? []
1197
+ * );
1198
+ * ```
1199
+ */
233
1200
  declare function parseSubcommand(args: string[], subcommands: CliCommand[]): {
234
1201
  subcommand: CliCommand | undefined;
235
1202
  remainingArgs: string[];
236
1203
  };
237
1204
  //#endregion
238
1205
  //#region src/spinner.d.ts
1206
+ /**
1207
+ * Minimal spinner controller used for long-running CLI tasks.
1208
+ */
239
1209
  interface Spinner {
1210
+ /**
1211
+ * Starts the spinner with an optional message override.
1212
+ */
240
1213
  start(message?: string): void;
1214
+ /**
1215
+ * Stops the spinner with an optional completion message.
1216
+ */
241
1217
  stop(message?: string): void;
1218
+ /**
1219
+ * Updates the spinner message while it is running.
1220
+ */
242
1221
  message(message: string): void;
243
1222
  }
1223
+ /**
1224
+ * Creates a Clack-backed spinner.
1225
+ *
1226
+ * @param initialMessage - Message used when `start()` is called without an
1227
+ * explicit message.
1228
+ * @returns A spinner controller.
1229
+ */
244
1230
  declare function createSpinner(initialMessage?: string): Spinner;
1231
+ /**
1232
+ * Runs an async task while displaying a spinner.
1233
+ *
1234
+ * @typeParam T - Value returned by the task.
1235
+ * @param message - Message shown when the spinner starts.
1236
+ * @param task - Async work to run.
1237
+ * @param options - Optional success and error messages shown when the task
1238
+ * settles.
1239
+ * @returns The value returned by `task`.
1240
+ *
1241
+ * @throws Re-throws any error from `task` after stopping the spinner.
1242
+ */
245
1243
  declare function withSpinner<T>(message: string, task: () => Promise<T>, options?: {
246
1244
  successMessage?: string;
247
1245
  errorMessage?: string;
248
1246
  }): Promise<T>;
249
1247
  //#endregion
250
1248
  //#region src/telemetry.d.ts
1249
+ /**
1250
+ * Options for the built-in in-memory telemetry client.
1251
+ */
251
1252
  interface TelemetryOptions {
1253
+ /**
1254
+ * Disables telemetry completely.
1255
+ */
252
1256
  disabled?: boolean;
1257
+ /**
1258
+ * Logs queued telemetry payloads through the optional debug logger.
1259
+ */
253
1260
  debug?: boolean;
1261
+ /**
1262
+ * HTTP endpoint that receives telemetry batches on flush.
1263
+ */
254
1264
  endpoint?: string;
1265
+ /**
1266
+ * Application name included in every telemetry event.
1267
+ *
1268
+ * @default "cli"
1269
+ */
255
1270
  appName?: string;
1271
+ /**
1272
+ * Environment variable prefix used for opt-out detection.
1273
+ *
1274
+ * @remarks
1275
+ * A prefix of `MY_CLI` reads `MY_CLI_TELEMETRY_DISABLED`.
1276
+ *
1277
+ * @default "APP"
1278
+ */
256
1279
  envVarPrefix?: string;
1280
+ /**
1281
+ * Properties merged into every telemetry event before event-specific
1282
+ * properties.
1283
+ */
257
1284
  defaultProperties?: Record<string, unknown>;
258
- logger?: Pick<CliLogger, 'debug' | 'warn'>;
1285
+ /**
1286
+ * Logger used for debug payload output and flush warnings.
1287
+ */
1288
+ logger?: Pick<CliLogger, "debug" | "warn">;
259
1289
  }
1290
+ /**
1291
+ * Standard telemetry event names emitted by Hexbus runtime helpers.
1292
+ */
260
1293
  declare const TelemetryEventName: {
261
- readonly CLI_INVOKED: "cli_invoked";
262
- readonly CLI_ENVIRONMENT_DETECTED: "cli_environment_detected";
263
1294
  readonly CLI_COMPLETED: "cli_completed";
1295
+ readonly CLI_ENVIRONMENT_DETECTED: "cli_environment_detected";
1296
+ readonly CLI_INVOKED: "cli_invoked";
1297
+ readonly COMMAND_FAILED: "command_failed";
264
1298
  readonly COMMAND_INVOKED: "command_invoked";
265
1299
  readonly COMMAND_SUCCEEDED: "command_succeeded";
266
- readonly COMMAND_FAILED: "command_failed";
267
1300
  readonly COMMAND_UNKNOWN: "command_unknown";
268
1301
  readonly ERROR_OCCURRED: "error_occurred";
269
1302
  readonly HELP_DISPLAYED: "help_displayed";
270
- readonly VERSION_DISPLAYED: "version_displayed";
271
- readonly INTERACTIVE_MENU_OPENED: "interactive_menu_opened";
272
1303
  readonly INTERACTIVE_MENU_EXITED: "interactive_menu_exited";
1304
+ readonly INTERACTIVE_MENU_OPENED: "interactive_menu_opened";
1305
+ readonly VERSION_DISPLAYED: "version_displayed";
273
1306
  };
1307
+ /**
1308
+ * Union of standard telemetry event name string values.
1309
+ */
274
1310
  type TelemetryEventNameType = (typeof TelemetryEventName)[keyof typeof TelemetryEventName];
1311
+ /**
1312
+ * Creates a no-op telemetry client.
1313
+ *
1314
+ * @returns A telemetry implementation whose methods do nothing and whose
1315
+ * `isDisabled()` method returns `true`.
1316
+ */
275
1317
  declare function createDisabledTelemetry(): Telemetry;
1318
+ /**
1319
+ * Creates the built-in telemetry client.
1320
+ *
1321
+ * @remarks
1322
+ * Events are queued in memory. `flush()` posts the queue to `endpoint` when one
1323
+ * is configured, then clears the queue. Failed flushes are reported through
1324
+ * the optional logger and do not throw, keeping telemetry best effort.
1325
+ *
1326
+ * @param options - Telemetry behavior and event defaults.
1327
+ * @returns An enabled or disabled telemetry client depending on options and
1328
+ * environment opt-out variables.
1329
+ */
276
1330
  declare function createTelemetry(options?: TelemetryOptions): Telemetry;
277
1331
  //#endregion
278
- //#region src/version-check.d.ts
279
- type InstallSource = 'npm-global' | 'brew' | 'npx' | 'bunx' | 'pnpm-dlx' | 'yarn-dlx' | 'local' | 'unknown';
1332
+ //#region src/version-check/types.d.ts
1333
+ /**
1334
+ * Installation source inferred from the running binary path and package manager
1335
+ * environment.
1336
+ */
1337
+ type InstallSource = "npm-global" | "brew" | "npx" | "bunx" | "pnpm-dlx" | "yarn-dlx" | "local" | "unknown";
1338
+ /**
1339
+ * Result returned by an update check.
1340
+ */
280
1341
  interface UpdateCheckResult {
1342
+ /**
1343
+ * Version currently running.
1344
+ */
281
1345
  currentVersion: string;
1346
+ /**
1347
+ * Latest version fetched from the registry or cache, or `null` when lookup
1348
+ * failed.
1349
+ */
282
1350
  latestVersion: string | null;
1351
+ /**
1352
+ * Whether `latestVersion` is newer than `currentVersion`.
1353
+ *
1354
+ * @remarks
1355
+ * This is `false` when `latestVersion` is `null` due to lookup failure.
1356
+ * Callers can check `latestVersion === null` to distinguish lookup failure
1357
+ * from an up-to-date package.
1358
+ */
283
1359
  isOutdated: boolean;
1360
+ /**
1361
+ * Detected installation source for the current binary.
1362
+ */
284
1363
  source: InstallSource;
1364
+ /**
1365
+ * Update command appropriate for the detected source, when Hexbus can infer
1366
+ * one.
1367
+ */
285
1368
  updateCommand: string | null;
1369
+ /**
1370
+ * User-facing update hint, or `null` when no actionable update is available.
1371
+ */
286
1372
  hint: string | null;
287
1373
  }
1374
+ /**
1375
+ * Options for checking package registry state and update hints.
1376
+ */
288
1377
  interface UpdateCheckOptions {
1378
+ /**
1379
+ * Published package name to query.
1380
+ */
289
1381
  packageName: string;
1382
+ /**
1383
+ * Version currently running.
1384
+ */
290
1385
  currentVersion: string;
1386
+ /**
1387
+ * Homebrew formula name used for Homebrew update hints.
1388
+ *
1389
+ * @default packageName
1390
+ */
291
1391
  brewFormula?: string;
1392
+ /**
1393
+ * Registry base URL used to fetch latest package metadata.
1394
+ *
1395
+ * @default "https://registry.npmjs.org"
1396
+ */
292
1397
  registryUrl?: string;
1398
+ /**
1399
+ * Maximum registry request duration in milliseconds.
1400
+ *
1401
+ * @default 1500
1402
+ */
293
1403
  timeoutMs?: number;
1404
+ /**
1405
+ * Directory where latest-version cache files are stored.
1406
+ *
1407
+ * @default path.join(os.tmpdir(), "hexbus-version-cache")
1408
+ */
294
1409
  cacheDir?: string;
1410
+ /**
1411
+ * How long cached latest-version data stays fresh.
1412
+ *
1413
+ * @default 86400000
1414
+ */
295
1415
  cacheTtlMs?: number;
1416
+ /**
1417
+ * Binary path used for installation-source detection.
1418
+ *
1419
+ * @default process.argv[1]
1420
+ */
296
1421
  binPath?: string;
1422
+ /**
1423
+ * Optional logger used for debug output when update checks fail.
1424
+ */
1425
+ logger?: VersionInfoLogger;
1426
+ /**
1427
+ * Clock override used by tests and deterministic callers.
1428
+ *
1429
+ * @default Date.now
1430
+ */
297
1431
  now?: () => number;
298
1432
  }
299
- type VersionInfoLogger = Pick<CliLogger, 'message' | 'note'> & Partial<Pick<CliLogger, 'debug'>>;
1433
+ type VersionInfoLogger = Pick<CliLogger, "message" | "note"> & Partial<Pick<CliLogger, "debug">>;
1434
+ /**
1435
+ * Options for printing or background-checking CLI version information.
1436
+ */
300
1437
  interface VersionInfoOptions extends UpdateCheckOptions {
1438
+ /**
1439
+ * Application name shown in version output.
1440
+ */
301
1441
  appName: string;
302
- logger?: VersionInfoLogger;
303
1442
  }
1443
+ //#endregion
1444
+ //#region src/version-check/check.d.ts
1445
+ /**
1446
+ * Checks whether raw arguments request version output.
1447
+ *
1448
+ * @param rawArgs - Arguments after executable and script path.
1449
+ * @returns `true` when `-v` or `--version` is present.
1450
+ */
304
1451
  declare function isVersionRequest(rawArgs: string[]): boolean;
305
- declare function detectInstallSource(binPath?: string): InstallSource;
306
- declare function getUpdateCommand(source: InstallSource, packageName: string, brewFormula?: string): string | null;
307
- declare function checkForUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
1452
+ /**
1453
+ * Formats a user-facing update hint from an update-check result.
1454
+ *
1455
+ * @param result - Update-check result to render.
1456
+ * @returns A formatted hint when the result is outdated and has an update
1457
+ * command, otherwise `null`.
1458
+ */
308
1459
  declare function formatUpdateHint(result: UpdateCheckResult): string | null;
1460
+ /**
1461
+ * Checks whether a newer package version is available.
1462
+ *
1463
+ * @remarks
1464
+ * The function first reads the local cache. On a cache miss it refreshes the
1465
+ * cache from the configured registry. Refresh failures produce a result with
1466
+ * `latestVersion: null` rather than throwing.
1467
+ *
1468
+ * @param options - Update-check configuration.
1469
+ * @returns Update metadata and a formatted hint when an update is available.
1470
+ */
1471
+ declare function checkForUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
1472
+ //#endregion
1473
+ //#region src/version-check/display.d.ts
1474
+ /**
1475
+ * Prints CLI version information and any available update hint.
1476
+ *
1477
+ * @param options - Version display and update-check options.
1478
+ */
309
1479
  declare function printVersionInfo(options: VersionInfoOptions): Promise<void>;
1480
+ /**
1481
+ * Starts a non-blocking update check.
1482
+ *
1483
+ * @remarks
1484
+ * Cached hints are displayed synchronously when available. If the cache is
1485
+ * stale or missing, a refresh is started in the background and failures are
1486
+ * only logged at debug level.
1487
+ *
1488
+ * @param options - Version display and update-check options.
1489
+ */
310
1490
  declare function startBackgroundUpdateCheck(options: VersionInfoOptions): void;
311
1491
  //#endregion
1492
+ //#region src/version-check/install-source.d.ts
1493
+ /**
1494
+ * Infers how the current CLI binary was installed.
1495
+ *
1496
+ * @remarks
1497
+ * Detection is heuristic and based on binary path, realpath, and package
1498
+ * manager environment variables. Unknown or transient install modes return
1499
+ * `unknown` instead of throwing.
1500
+ *
1501
+ * @param binPath - Binary path to inspect.
1502
+ * @returns The inferred installation source.
1503
+ */
1504
+ declare function detectInstallSource(binPath?: string): InstallSource;
1505
+ /**
1506
+ * Builds an update command for an installation source.
1507
+ *
1508
+ * @param source - Installation source returned by `detectInstallSource`.
1509
+ * @param packageName - Package name to update.
1510
+ * @param brewFormula - Homebrew formula name when `source` is `brew`.
1511
+ * @returns A command string when the source has an actionable update path,
1512
+ * otherwise `null`.
1513
+ */
1514
+ declare function getUpdateCommand(source: InstallSource, packageName: string, brewFormula?: string): string | null;
1515
+ //#endregion
312
1516
  export { type CliCommand, type CliContext, CliError, type CliFlag, type CliLogger, type ConfigManagement, type CreateContextOptions, DEFAULT_ERROR_CATALOG, type DisplayIntroOptions, type ErrorCatalog, type ErrorCatalogEntry, type ErrorCode, type ErrorHandlers, type FileSystemUtils, type FlagType, type FrameworkDetectionResult, type FrameworkPackageMap, type InstallSource, LOG_LEVELS, type LogLevel, type PackageInfo, type PackageManager, type PackageManagerResult, type ParsedArgs, type ShowHelpMenuOptions, type Spinner, type Telemetry, TelemetryEventName, type TelemetryEventNameType, type TelemetryOptions, type UpdateCheckOptions, type UpdateCheckResult, type VersionInfoOptions, checkForUpdate, color, createCliContext, createCliLogger, createDisabledTelemetry, createErrorHandlers, createSpinner, createTelemetry, createTestContext, detectFramework, detectInstallSource, detectPackageManager, detectProjectRoot, displayIntro, extendErrorCatalog, formatFlagHelp, formatLogMessage, formatStep, formatUpdateHint, generateFlagsHelp, getExecCommand, getFlagValue, getInstallCommand, getRunCommand, getUpdateCommand, globalFlags, hasFlag, isCliError, isVersionRequest, logMessage, parseCliArgs, parseSubcommand, printVersionInfo, showHelpMenu, startBackgroundUpdateCheck, validLogLevels, withErrorHandling, withSpinner };