apcore-cli 0.2.0 → 0.3.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.
@@ -30,30 +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 commandCache;
43
- constructor(registry: Registry, executor: Executor);
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;
48
+ constructor(registry: Registry, executor: Executor, helpTextMaxLength?: number);
49
+ /**
50
+ * Build alias->module_id map from display overlay metadata.
51
+ */
52
+ buildAliasMap(): void;
44
53
  /**
45
54
  * List all available command names from the Registry.
46
- *
47
- * TODO: Implement registry enumeration.
48
55
  */
49
56
  listCommands(): string[];
50
57
  /**
51
58
  * Get or lazily build a Commander Command for the given module.
52
- *
53
- * TODO: Implement lazy command construction with schema-based options.
54
59
  */
55
60
  getCommand(cmdName: string): Command | null;
56
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
+ }
57
113
 
58
114
  /**
59
115
  * CLI entry point — createCli / main equivalents.
@@ -89,6 +145,13 @@ interface OptionConfig {
89
145
  * @param progName Program name shown in help (default: apcore-cli)
90
146
  */
91
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>;
92
155
  /**
93
156
  * Parse argv and run the CLI. Handles top-level error catching and exit codes.
94
157
  */
@@ -96,7 +159,7 @@ declare function main(progName?: string): void;
96
159
  /**
97
160
  * Build a Commander Command for a single apcore module.
98
161
  */
99
- declare function buildModuleCommand(moduleDef: ModuleDescriptor, executor: Executor): Command;
162
+ declare function buildModuleCommand(moduleDef: ModuleDescriptor, executor: Executor, helpTextMaxLength?: number, cmdName?: string): Command;
100
163
  /**
101
164
  * Validate that a module ID conforms to the expected format.
102
165
  * Pattern: [a-z][a-z0-9_]*(.[a-z][a-z0-9_])* — max 128 chars.
@@ -112,6 +175,30 @@ declare function collectInput(stdinFlag?: string, cliKwargs?: Record<string, unk
112
175
  */
113
176
  declare function reconvertEnumValues(kwargs: Record<string, unknown>, options: OptionConfig[]): Record<string, unknown>;
114
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
+
115
202
  /**
116
203
  * ConfigResolver — 4-tier config resolution (CLI flag > env > file > default).
117
204
  *
@@ -215,12 +302,12 @@ declare function mapType(propName: string, propSchema: Record<string, unknown>):
215
302
  /**
216
303
  * Extract help text from schema property, preferring x-llm-description.
217
304
  */
218
- declare function extractHelp(propSchema: Record<string, unknown>): string | undefined;
305
+ declare function extractHelp(propSchema: Record<string, unknown>, maxLength?: number): string | undefined;
219
306
  /**
220
307
  * Convert a JSON Schema `properties` object into an array of
221
308
  * Commander option configurations.
222
309
  */
223
- declare function schemaToCliOptions(schema: Record<string, unknown>): OptionConfig[];
310
+ declare function schemaToCliOptions(schema: Record<string, unknown>, maxHelpLength?: number): OptionConfig[];
224
311
 
225
312
  /**
226
313
  * Interactive approval prompts with timeout.
@@ -418,4 +505,4 @@ declare class Sandbox {
418
505
  private sandboxedExecute;
419
506
  }
420
507
 
421
- 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 };