apcore-cli 0.2.1 → 0.3.1

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.
@@ -30,31 +30,86 @@ interface ModuleDescriptor {
30
30
  annotations?: Record<string, unknown>;
31
31
  metadata?: Record<string, unknown>;
32
32
  }
33
+ /** Built-in command names that cannot be overridden by modules. */
34
+ declare const BUILTIN_COMMANDS: string[];
33
35
  /**
34
36
  * Dynamically loads apcore modules as Commander subcommands from Registry.
35
- *
36
- * TODO: Implement lazy loading — commands should only be fully built when
37
- * actually invoked, not at registration time.
38
37
  */
39
38
  declare class LazyModuleGroup {
40
- private readonly registry;
39
+ protected readonly registry: Registry;
41
40
  readonly executor: Executor;
42
- private readonly helpTextMaxLength;
43
- private commandCache;
41
+ protected readonly helpTextMaxLength: number;
42
+ protected commandCache: Map<string, Command>;
43
+ /** alias -> canonical module_id (populated lazily) */
44
+ protected aliasMap: Map<string, string>;
45
+ /** module_id -> descriptor cache (populated during alias map build) */
46
+ protected descriptorCache: Map<string, ModuleDescriptor>;
47
+ protected aliasMapBuilt: boolean;
44
48
  constructor(registry: Registry, executor: Executor, helpTextMaxLength?: number);
49
+ /**
50
+ * Build alias->module_id map from display overlay metadata.
51
+ */
52
+ buildAliasMap(): void;
45
53
  /**
46
54
  * List all available command names from the Registry.
47
- *
48
- * TODO: Implement registry enumeration.
49
55
  */
50
56
  listCommands(): string[];
51
57
  /**
52
58
  * Get or lazily build a Commander Command for the given module.
53
- *
54
- * TODO: Implement lazy command construction with schema-based options.
55
59
  */
56
60
  getCommand(cmdName: string): Command | null;
57
61
  }
62
+ /**
63
+ * Command group for a single namespace — lazily builds subcommands.
64
+ */
65
+ declare class LazyGroup {
66
+ private readonly members;
67
+ private readonly _executor;
68
+ private readonly _helpTextMaxLength;
69
+ private readonly _cmdCache;
70
+ readonly command: Command;
71
+ constructor(members: Map<string, [string, ModuleDescriptor]>, executor: Executor, name: string, helpTextMaxLength?: number);
72
+ listCommands(): string[];
73
+ getCommand(cmdName: string): Command | null;
74
+ }
75
+ /**
76
+ * Extended LazyModuleGroup that organises modules into named groups.
77
+ *
78
+ * Modules with dotted IDs (e.g., "math.add") are automatically grouped
79
+ * by their namespace prefix. The display overlay can override grouping
80
+ * via metadata.display.cli.group.
81
+ */
82
+ declare class GroupedModuleGroup extends LazyModuleGroup {
83
+ /** groupName -> { cmdName -> [moduleId, descriptor] } */
84
+ private groupMap;
85
+ /** cmdName -> [moduleId, descriptor] for top-level (ungrouped) modules */
86
+ private topLevelModules;
87
+ /** Cached LazyGroup instances */
88
+ private groupCache;
89
+ private groupMapBuilt;
90
+ /**
91
+ * Determine (groupName | null, commandName) for a module from its display overlay.
92
+ */
93
+ static resolveGroup(moduleId: string, descriptor: ModuleDescriptor): [string | null, string];
94
+ /**
95
+ * Build the group map from registry modules.
96
+ */
97
+ buildGroupMap(): void;
98
+ /**
99
+ * List all available command names: builtins + group names + top-level module names.
100
+ */
101
+ listCommands(): string[];
102
+ /**
103
+ * Get a command by name: check builtins -> group cache -> group map -> top-level modules.
104
+ */
105
+ getCommand(cmdName: string): Command | null;
106
+ /** Expose groupMap for testing. */
107
+ getGroupMap(): Map<string, Map<string, [string, ModuleDescriptor]>>;
108
+ /** Expose topLevelModules for testing. */
109
+ getTopLevelModules(): Map<string, [string, ModuleDescriptor]>;
110
+ /** Expose groupMapBuilt for testing. */
111
+ isGroupMapBuilt(): boolean;
112
+ }
58
113
 
59
114
  /**
60
115
  * CLI entry point — createCli / main equivalents.
@@ -90,6 +145,13 @@ interface OptionConfig {
90
145
  * @param progName Program name shown in help (default: apcore-cli)
91
146
  */
92
147
  declare function createCli(extensionsDir?: string, progName?: string): Command;
148
+ /**
149
+ * Optionally apply apcore-toolkit features (DisplayResolver, RegistryWriter).
150
+ *
151
+ * Uses dynamic import so the dependency remains optional — if apcore-toolkit
152
+ * is not installed, a warning is printed and the CLI continues without it.
153
+ */
154
+ declare function applyToolkitIntegration(commandsDir?: string, bindingPath?: string): Promise<void>;
93
155
  /**
94
156
  * Parse argv and run the CLI. Handles top-level error catching and exit codes.
95
157
  */
@@ -97,7 +159,7 @@ declare function main(progName?: string): void;
97
159
  /**
98
160
  * Build a Commander Command for a single apcore module.
99
161
  */
100
- declare function buildModuleCommand(moduleDef: ModuleDescriptor, executor: Executor, helpTextMaxLength?: number): Command;
162
+ declare function buildModuleCommand(moduleDef: ModuleDescriptor, executor: Executor, helpTextMaxLength?: number, cmdName?: string): Command;
101
163
  /**
102
164
  * Validate that a module ID conforms to the expected format.
103
165
  * Pattern: [a-z][a-z0-9_]*(.[a-z][a-z0-9_])* — max 128 chars.
@@ -113,6 +175,30 @@ declare function collectInput(stdinFlag?: string, cliKwargs?: Record<string, unk
113
175
  */
114
176
  declare function reconvertEnumValues(kwargs: Record<string, unknown>, options: OptionConfig[]): Record<string, unknown>;
115
177
 
178
+ /**
179
+ * Display overlay helpers — shared resolution logic for CLI surfaces.
180
+ */
181
+
182
+ /**
183
+ * Extract resolved display overlay from a ModuleDescriptor's metadata.
184
+ */
185
+ declare function getDisplay(descriptor: ModuleDescriptor): Record<string, unknown>;
186
+ /**
187
+ * Return [displayName, description, tags] resolved from the display overlay.
188
+ *
189
+ * Falls back to scanner-provided values when no overlay is present.
190
+ */
191
+ declare function getCliDisplayFields(descriptor: ModuleDescriptor): [string, string, string[]];
192
+
193
+ /**
194
+ * Init command — scaffold new apcore modules (Phase 1).
195
+ */
196
+
197
+ /**
198
+ * Register the init command group on the CLI program.
199
+ */
200
+ declare function registerInitCommand(cli: Command): void;
201
+
116
202
  /**
117
203
  * ConfigResolver — 4-tier config resolution (CLI flag > env > file > default).
118
204
  *
@@ -419,4 +505,4 @@ declare class Sandbox {
419
505
  private sandboxedExecute;
420
506
  }
421
507
 
422
- export { ApprovalDeniedError, ApprovalTimeoutError, AuditLogger, AuthProvider, AuthenticationError, ConfigDecryptionError, ConfigEncryptor, ConfigResolver, DEFAULTS, EXIT_CODES, type Executor, type ExitCode, LazyModuleGroup, type ModuleDescriptor, ModuleExecutionError, ModuleNotFoundError, type OptionConfig, type Registry, Sandbox, SchemaValidationError, buildModuleCommand, checkApproval, collectInput, createCli, debug, error, exitCodeForError, extractHelp, formatExecResult, formatModuleDetail, formatModuleList, getAuditLogger, getLogLevel, info, main, mapType, reconvertEnumValues, registerDiscoveryCommands, registerShellCommands, resolveFormat, resolveRefs, schemaToCliOptions, setAuditLogger, setLogLevel, truncate, validateModuleId, warn };
508
+ export { ApprovalDeniedError, ApprovalTimeoutError, AuditLogger, AuthProvider, AuthenticationError, BUILTIN_COMMANDS, ConfigDecryptionError, ConfigEncryptor, ConfigResolver, DEFAULTS, EXIT_CODES, type Executor, type ExitCode, GroupedModuleGroup, LazyGroup, LazyModuleGroup, type ModuleDescriptor, ModuleExecutionError, ModuleNotFoundError, type OptionConfig, type Registry, Sandbox, SchemaValidationError, applyToolkitIntegration, buildModuleCommand, checkApproval, collectInput, createCli, debug, error, exitCodeForError, extractHelp, formatExecResult, formatModuleDetail, formatModuleList, getAuditLogger, getCliDisplayFields, getDisplay, getLogLevel, info, main, mapType, reconvertEnumValues, registerDiscoveryCommands, registerInitCommand, registerShellCommands, resolveFormat, resolveRefs, schemaToCliOptions, setAuditLogger, setLogLevel, truncate, validateModuleId, warn };