@alcyone-labs/arg-parser 2.14.2 → 3.0.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 (75) hide show
  1. package/README.md +20 -127
  2. package/dist/config/plugins/index.d.ts +36 -4
  3. package/dist/config/plugins/index.d.ts.map +1 -1
  4. package/dist/core/ArgParser.d.ts +124 -464
  5. package/dist/core/ArgParser.d.ts.map +1 -1
  6. package/dist/core/FlagManager.d.ts +36 -136
  7. package/dist/core/FlagManager.d.ts.map +1 -1
  8. package/dist/core/PromptManager.d.ts +42 -91
  9. package/dist/core/PromptManager.d.ts.map +1 -1
  10. package/dist/core/log-path-utils.d.ts +28 -36
  11. package/dist/core/log-path-utils.d.ts.map +1 -1
  12. package/dist/core/types.d.ts +83 -592
  13. package/dist/core/types.d.ts.map +1 -1
  14. package/dist/index.cjs +599 -9658
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +26 -15
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.min.mjs +615 -8224
  19. package/dist/index.min.mjs.map +1 -1
  20. package/dist/index.mjs +581 -8881
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/plugin/types.d.ts +121 -0
  23. package/dist/plugin/types.d.ts.map +1 -0
  24. package/dist/utils/debug-utils.d.ts +4 -26
  25. package/dist/utils/debug-utils.d.ts.map +1 -1
  26. package/package.json +12 -73
  27. package/dist/assets/.dxtignore.template +0 -37
  28. package/dist/assets/logo_1_small.jpg +0 -0
  29. package/dist/config/ConfigurationManager.d.ts +0 -82
  30. package/dist/config/ConfigurationManager.d.ts.map +0 -1
  31. package/dist/config/plugins/ConfigPlugin.d.ts +0 -60
  32. package/dist/config/plugins/ConfigPlugin.d.ts.map +0 -1
  33. package/dist/config/plugins/ConfigPluginRegistry.d.ts +0 -72
  34. package/dist/config/plugins/ConfigPluginRegistry.d.ts.map +0 -1
  35. package/dist/config/plugins/TomlConfigPlugin.d.ts +0 -30
  36. package/dist/config/plugins/TomlConfigPlugin.d.ts.map +0 -1
  37. package/dist/config/plugins/YamlConfigPlugin.d.ts +0 -29
  38. package/dist/config/plugins/YamlConfigPlugin.d.ts.map +0 -1
  39. package/dist/core/ArgParserBase.d.ts +0 -319
  40. package/dist/core/ArgParserBase.d.ts.map +0 -1
  41. package/dist/core/dxt-path-resolver.d.ts +0 -100
  42. package/dist/core/dxt-path-resolver.d.ts.map +0 -1
  43. package/dist/dxt/DxtGenerator-testUtils.d.ts +0 -22
  44. package/dist/dxt/DxtGenerator-testUtils.d.ts.map +0 -1
  45. package/dist/dxt/DxtGenerator.d.ts +0 -120
  46. package/dist/dxt/DxtGenerator.d.ts.map +0 -1
  47. package/dist/mcp/ArgParserMcp.d.ts +0 -21
  48. package/dist/mcp/ArgParserMcp.d.ts.map +0 -1
  49. package/dist/mcp/mcp-integration.d.ts +0 -86
  50. package/dist/mcp/mcp-integration.d.ts.map +0 -1
  51. package/dist/mcp/mcp-lifecycle.d.ts +0 -163
  52. package/dist/mcp/mcp-lifecycle.d.ts.map +0 -1
  53. package/dist/mcp/mcp-notifications.d.ts +0 -132
  54. package/dist/mcp/mcp-notifications.d.ts.map +0 -1
  55. package/dist/mcp/mcp-prompts.d.ts +0 -132
  56. package/dist/mcp/mcp-prompts.d.ts.map +0 -1
  57. package/dist/mcp/mcp-protocol-versions.d.ts +0 -150
  58. package/dist/mcp/mcp-protocol-versions.d.ts.map +0 -1
  59. package/dist/mcp/mcp-resources.d.ts +0 -133
  60. package/dist/mcp/mcp-resources.d.ts.map +0 -1
  61. package/dist/mcp/mcp-utils.d.ts +0 -20
  62. package/dist/mcp/mcp-utils.d.ts.map +0 -1
  63. package/dist/mcp/zod-compatibility.d.ts +0 -74
  64. package/dist/mcp/zod-compatibility.d.ts.map +0 -1
  65. package/dist/testing/fuzzy-test-cli.d.ts +0 -5
  66. package/dist/testing/fuzzy-test-cli.d.ts.map +0 -1
  67. package/dist/testing/fuzzy-tester.d.ts +0 -101
  68. package/dist/testing/fuzzy-tester.d.ts.map +0 -1
  69. package/dist/tui/index.d.ts +0 -281
  70. package/dist/tui/types.d.ts +0 -60
  71. package/dist/tui/types.d.ts.map +0 -1
  72. package/dist/tui.cjs +0 -1060
  73. package/dist/tui.cjs.map +0 -1
  74. package/dist/tui.mjs +0 -967
  75. package/dist/tui.mjs.map +0 -1
@@ -1,68 +1,16 @@
1
- import { z, type ZodTypeAny } from "zod";
2
- export type ArgParserInstance = IArgParser;
3
- /**
4
- * Interface defining the MCP server methods expected by ArgParserBase.
5
- * This allows ArgParserBase to use these methods without depending on the concrete ArgParser class.
6
- */
7
- export interface IMcpServerMethods {
8
- createMcpServer(serverInfo?: any, toolOptions?: any, logPath?: any): Promise<any>;
9
- startMcpServerWithTransport(serverInfo: any, transportType: string, transportOptions: any, toolOptions: any, logPath?: string): Promise<void>;
10
- startMcpServerWithMultipleTransports(serverInfo: any, transports: any[], toolOptions: any, logPath?: string): Promise<void>;
11
- getMcpServerConfig(): any;
12
- }
13
1
  /**
14
- * Interface representing the public API of ArgParser/ArgParserBase.
2
+ * Core types for ArgParser
3
+ *
4
+ * These types define the shape of flags, commands, and configuration
5
+ * for the argument parser.
15
6
  */
16
- export interface IArgParser<THandlerReturn = any> {
17
- getAppName(): string | undefined;
18
- getAppCommandName(): string | undefined;
19
- getSubCommandName(): string;
20
- getDescription(): string | undefined;
21
- getAutoExit(): boolean;
22
- getHandler(): ((ctx: IHandlerContext) => void) | undefined;
23
- getSubCommands(): Map<string, ISubCommand>;
24
- get logger(): any;
25
- get flags(): ProcessedFlag[];
26
- get flagNames(): string[];
27
- addFlag(flag: IFlag): this;
28
- addFlags(flags: readonly IFlag[]): this;
29
- hasFlag(name: string): boolean;
30
- getFlagDefinition(name: string): ProcessedFlag | undefined;
31
- addSubCommand(subCommandConfig: ISubCommand): this;
32
- getSubCommand(name: string): ISubCommand | undefined;
33
- parse(processArgs?: string[], options?: any): Promise<any>;
34
- setHandler(handler: (ctx: IHandlerContext<any, any>) => THandlerReturn | Promise<THandlerReturn>): this;
35
- helpText(): string;
36
- printAll(filePath?: string): void;
37
- getCommandChain(): string[];
38
- addMcpResource(config: any): this;
39
- removeMcpResource(name: string): this;
40
- getMcpResources(): any[];
41
- addMcpPrompt(config: any): this;
42
- removeMcpPrompt(name: string): this;
43
- getMcpPrompts(): any[];
44
- getMcpServerConfig?(): any;
45
- setPromptWhen?(promptWhen: PromptWhen): this;
46
- setOnCancel?(onCancel: (ctx: IHandlerContext) => void | Promise<void>): this;
47
- getPromptWhen?(): PromptWhen;
48
- }
7
+ import { z, type ZodTypeAny } from "zod";
49
8
  /**
50
9
  * Defines the behavior for flag inheritance in sub-commands.
51
10
  */
52
11
  export declare const FlagInheritance: {
53
- /**
54
- * No flags are inherited from the parent.
55
- */
56
12
  readonly NONE: "none";
57
- /**
58
- * Inherits flags only from the direct parent at the time of attachment (Snapshot behavior).
59
- * Equivalent to `true` in legacy boolean config.
60
- */
61
13
  readonly DirectParentOnly: "direct-parent-only";
62
- /**
63
- * Inherits flags from the entire parent chain, ensuring grandchildren receive root flags
64
- * even in bottom-up construction scenarios.
65
- */
66
14
  readonly AllParents: "all-parents";
67
15
  };
68
16
  export type TFlagInheritance = (typeof FlagInheritance)[keyof typeof FlagInheritance] | boolean;
@@ -76,8 +24,8 @@ export declare const zodDxtOptionsSchema: z.ZodObject<{
76
24
  string: "string";
77
25
  number: "number";
78
26
  boolean: "boolean";
79
- file: "file";
80
27
  directory: "directory";
28
+ file: "file";
81
29
  }>>;
82
30
  multiple: z.ZodOptional<z.ZodBoolean>;
83
31
  min: z.ZodOptional<z.ZodNumber>;
@@ -85,7 +33,7 @@ export declare const zodDxtOptionsSchema: z.ZodObject<{
85
33
  default: z.ZodOptional<z.ZodAny>;
86
34
  title: z.ZodOptional<z.ZodString>;
87
35
  }, z.core.$strict>;
88
- export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
36
+ export declare const zodFlagSchema: z.ZodObject<{
89
37
  name: z.ZodString;
90
38
  allowLigature: z.ZodDefault<z.ZodBoolean>;
91
39
  allowMultiple: z.ZodDefault<z.ZodBoolean>;
@@ -93,10 +41,10 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
93
41
  valueHint: z.ZodOptional<z.ZodString>;
94
42
  options: z.ZodArray<z.ZodString>;
95
43
  defaultValue: z.ZodOptional<z.ZodAny>;
96
- type: z.ZodDefault<z.ZodUnion<readonly [z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodCustom<(value: string) => any | Promise<any>, (value: string) => any | Promise<any>>, z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.ZodString]>>;
97
- mandatory: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(value?: any, parsedArgs?: any) => boolean, (value?: any, parsedArgs?: any) => boolean>]>>;
44
+ type: z.ZodDefault<z.ZodUnion<readonly [z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodCustom<unknown, unknown>, z.ZodString]>>;
45
+ mandatory: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<unknown, unknown>]>>;
98
46
  flagOnly: z.ZodDefault<z.ZodBoolean>;
99
- validate: z.ZodOptional<z.ZodCustom<(value?: any, parsedArgs?: any) => boolean | string | void | Promise<boolean | string | void>, (value?: any, parsedArgs?: any) => boolean | string | void | Promise<boolean | string | void>>>;
47
+ validate: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
100
48
  enum: z.ZodOptional<z.ZodArray<z.ZodAny>>;
101
49
  env: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
102
50
  dxtOptions: z.ZodOptional<z.ZodObject<{
@@ -106,8 +54,8 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
106
54
  string: "string";
107
55
  number: "number";
108
56
  boolean: "boolean";
109
- file: "file";
110
57
  directory: "directory";
58
+ file: "file";
111
59
  }>>;
112
60
  multiple: z.ZodOptional<z.ZodBoolean>;
113
61
  min: z.ZodOptional<z.ZodNumber>;
@@ -115,502 +63,160 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
115
63
  default: z.ZodOptional<z.ZodAny>;
116
64
  title: z.ZodOptional<z.ZodString>;
117
65
  }, z.core.$strict>>;
118
- dynamicRegister: z.ZodOptional<z.ZodCustom<DynamicRegisterFn, DynamicRegisterFn>>;
66
+ dynamicRegister: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
119
67
  setWorkingDirectory: z.ZodOptional<z.ZodBoolean>;
120
68
  positional: z.ZodOptional<z.ZodNumber>;
121
- prompt: z.ZodOptional<z.ZodCustom<(ctx: any) => any, (ctx: any) => any>>;
69
+ prompt: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
122
70
  promptSequence: z.ZodOptional<z.ZodNumber>;
123
- }, z.core.$strip>, z.ZodTransform<{
124
- [key: string]: any;
125
- }, {
126
- name: string;
127
- allowLigature: boolean;
128
- allowMultiple: boolean;
129
- options: string[];
130
- type: any;
131
- flagOnly: boolean;
132
- description?: string | string[] | undefined;
133
- valueHint?: string | undefined;
134
- defaultValue?: any;
135
- mandatory?: boolean | ((value?: any, parsedArgs?: any) => boolean) | undefined;
136
- validate?: ((value?: any, parsedArgs?: any) => boolean | string | void | Promise<boolean | string | void>) | undefined;
137
- enum?: any[] | undefined;
138
- env?: string | string[] | undefined;
139
- dxtOptions?: {
140
- sensitive?: boolean | undefined;
141
- localDefault?: string | undefined;
142
- type?: "string" | "number" | "boolean" | "file" | "directory" | undefined;
143
- multiple?: boolean | undefined;
144
- min?: number | undefined;
145
- max?: number | undefined;
146
- default?: any;
147
- title?: string | undefined;
148
- } | undefined;
149
- dynamicRegister?: DynamicRegisterFn | undefined;
150
- setWorkingDirectory?: boolean | undefined;
151
- positional?: number | undefined;
152
- prompt?: ((ctx: any) => any) | undefined;
153
- promptSequence?: number | undefined;
154
- }>>;
155
- /**
156
- * The raw input type for defining a flag, before Zod processing (aliases, defaults).
157
- */
71
+ }, z.core.$strip>;
158
72
  export type IFlagCore = z.input<typeof zodFlagSchema>;
159
- /**
160
- * The type of the `type` property in a ProcessedFlagCore object.
161
- * This represents all valid forms the `type` property can take after Zod processing.
162
- */
163
- export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | ((value: string) => Promise<any>) | ZodTypeAny | "string" | "number" | "boolean" | "array" | "object";
164
- /**
165
- * The core type of a flag after Zod processing (defaults applied, aliases resolved),
166
- * but before some properties are made more specific (like `type` constructor to actual type).
167
- * This type is output by `zodFlagSchema.parse()`.
168
- */
169
- export type ProcessedFlagCore = Omit<z.output<typeof zodFlagSchema>, "type"> & {
170
- type: TParsedArgsTypeFromFlagDef;
171
- };
172
- /**
173
- * DXT-specific configuration options for flags that will be included in DXT manifests.
174
- * These options control how the flag appears in DXT user_config and how it behaves in DXT environments.
175
- */
73
+ export type ProcessedFlagCore = z.output<typeof zodFlagSchema>;
176
74
  export interface IDxtOptions {
177
- /** Whether this field should be marked as sensitive in DXT user_config (default: true for ENV-linked flags) */
178
75
  sensitive?: boolean;
179
- /** Default value specific to DXT sandbox environment (different from regular default) */
180
76
  localDefault?: string;
181
- /** DXT input type - determines UI component in DXT clients (default: inferred from IFlag.type) */
182
77
  type?: "string" | "directory" | "file" | "boolean" | "number";
183
- /** Allow multiple values (for arrays) */
184
78
  multiple?: boolean;
185
- /** Minimum value (for number type) */
186
79
  min?: number;
187
- /** Maximum value (for number type) */
188
80
  max?: number;
189
- /** DXT-specific default value (overrides localDefault if provided) */
190
81
  default?: any;
191
- /** Custom title for the user_config field (overrides auto-generated title) */
192
82
  title?: string;
193
83
  }
194
- /**
195
- * The user-facing type for defining a flag. It includes aliases like `default` and `required`.
196
- * The `handler` property is removed as handlers are typically associated with commands/subcommands, not individual flags.
197
- */
198
84
  export type IFlag = IFlagCore & {
199
- /** @alias defaultValue */
200
85
  default?: any;
201
- /** @alias mandatory */
202
- required?: boolean | ((parsedArgs: TParsedArgs<any>) => boolean);
203
- /** Environment variables that should be set from this flag's value in DXT packages */
86
+ required?: boolean | ((parsedArgs: any) => boolean);
204
87
  env?: string | string[];
205
- /** DXT-specific configuration options for enhanced DXT manifest generation */
206
88
  dxtOptions?: IDxtOptions;
207
- /** Optional callback to dynamically register additional flags when this flag is present */
208
89
  dynamicRegister?: DynamicRegisterFn;
209
- /**
210
- * If true, this flag's value becomes the effective working directory.
211
- * When set, all file operations (including .env loading) will be relative to this path.
212
- * Last flag with this property in the command chain wins.
213
- *
214
- * @alias chdir
215
- *
216
- * @example
217
- * ```typescript
218
- * .addFlag({
219
- * name: "workspace",
220
- * description: "Workspace directory to operate in",
221
- * options: ["--workspace", "-w"],
222
- * type: "string",
223
- * setWorkingDirectory: true,
224
- * })
225
- * ```
226
- *
227
- * @example
228
- * ```typescript
229
- * // User runs: my-cli --workspace ./packages/my-app
230
- * // Effective cwd becomes: /repo/packages/my-app/
231
- * // All .env files are loaded from: /repo/packages/my-app/
232
- * ```
233
- */
234
90
  setWorkingDirectory?: boolean;
235
- /**
236
- * Captures the Nth trailing positional argument (1-indexed).
237
- *
238
- * - `positional: 1` captures the first trailing arg
239
- * - `positional: 2` captures the second trailing arg
240
- * - etc.
241
- *
242
- * Positional args are assigned AFTER all flags and subcommands are parsed.
243
- * The flag's `options` array still works as a fallback (e.g., `--id xxx`).
244
- *
245
- * @example
246
- * ```typescript
247
- * .addFlag({
248
- * name: "id",
249
- * type: "string",
250
- * mandatory: true,
251
- * options: ["--id"], // Fallback: --id xxx
252
- * positional: 1, // Primary: workflow show xxx
253
- * description: "Workflow ID to show",
254
- * })
255
- * ```
256
- */
257
91
  positional?: number;
258
92
  };
259
- /**
260
- * Context for dynamic flag registration callbacks.
261
- */
262
93
  export type DynamicRegisterContext = {
263
94
  value: any | any[];
264
95
  argsSoFar: Record<string, any>;
265
- parser: ArgParserInstance;
96
+ parser: any;
266
97
  processArgs: string[];
267
98
  forHelp?: boolean;
268
99
  registerFlags: (flags: readonly IFlag[]) => void;
269
100
  };
270
- /**
271
- * Function signature for dynamic flag loader/registrar.
272
- */
273
101
  export type DynamicRegisterFn = (ctx: DynamicRegisterContext) => Promise<readonly IFlag[] | void> | readonly IFlag[] | void;
274
- /**
275
- * A more refined type for a flag after it has been fully processed by ArgParser,
276
- * particularly its `type` property and validation/enum/mandatory functions.
277
- * This is the type that ArgParser would internally work with for parsing and type extraction.
278
- */
279
- export type ProcessedFlag = Omit<ProcessedFlagCore, "validate" | "enum" | "mandatory"> & {
280
- validate?: (value: any, parsedArgs?: TParsedArgs<ProcessedFlag[]>) => boolean | string | void | Promise<boolean | string | void>;
281
- enum?: any[];
282
- mandatory?: boolean | ((parsedArgs: TParsedArgs<ProcessedFlag[]>) => boolean);
283
- env?: string | string[];
284
- dynamicRegister?: DynamicRegisterFn;
285
- positional?: number;
286
- };
287
- /**
288
- * Resolves the TypeScript type from a flag's `type` definition.
289
- */
102
+ export type ProcessedFlag = ProcessedFlagCore;
103
+ export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | ((value: string) => Promise<any>) | ZodTypeAny | "string" | "number" | "boolean" | "array" | "object";
290
104
  export type ResolveType<T extends TParsedArgsTypeFromFlagDef> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? any[] : T extends ObjectConstructor ? Record<string, any> : T extends ZodTypeAny ? z.infer<T> : T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "array" ? any[] : T extends "object" ? Record<string, any> : T extends (value: string) => infer R ? R : any;
291
- /**
292
- * Extracts the final TypeScript type for a flag's value based on its definition,
293
- * considering `flagOnly` and `allowMultiple` properties.
294
- */
295
- export type ExtractFlagType<TFlag extends ProcessedFlag> = TFlag["flagOnly"] extends true ? TFlag["allowMultiple"] extends true ? boolean[] : boolean : TFlag["allowMultiple"] extends true ? Array<ResolveType<TFlag["type"]>> : ResolveType<TFlag["type"]>;
296
- /**
297
- * Represents the structured object of parsed arguments.
298
- * Keys are flag names, and values are their parsed and typed values.
299
- * `TFlags` should be the array of `ProcessedFlag` definitions for the specific command.
300
- */
105
+ export type ExtractFlagType<_TFlag extends ProcessedFlag> = any;
106
+ export type FlagsArray = readonly ProcessedFlag[];
301
107
  export type TParsedArgs<TFlags extends readonly ProcessedFlag[]> = {
302
108
  [K in TFlags[number]["name"]]: ExtractFlagType<Extract<TFlags[number], {
303
109
  name: K;
304
110
  }>>;
305
111
  };
306
- /**
307
- * System flags detected during parsing.
308
- * These flags are processed by ArgParser internally and made available to handlers
309
- * for inspection and debugging purposes.
310
- */
311
112
  export interface ISystemArgs {
312
- /** Whether --s-debug flag was present (enables debug output) */
313
113
  debug?: boolean;
314
- /** Whether --s-debug-print flag was present (prints config and exits) */
315
114
  debugPrint?: boolean;
316
- /** Whether --s-enable-fuzzy flag was present (enables fuzzy testing mode) */
317
115
  enableFuzzy?: boolean;
318
- /** Path provided with --s-with-env flag (loads env config from file), or true if no path */
319
116
  withEnv?: string | true;
320
- /** Whether --s-save-to-env flag was present (saves config to env file) */
321
117
  saveToEnv?: boolean;
322
- /** Output path for --s-build-dxt flag (generates DXT package), or true if no path */
323
118
  buildDxt?: string | true;
324
- /** Whether --s-mcp-serve flag was present (starts MCP server) */
325
119
  mcpServe?: boolean;
326
- /** Transport type from --s-mcp-transport flag */
327
120
  mcpTransport?: string;
328
- /** Port from --s-mcp-port flag */
329
121
  mcpPort?: number;
330
- /** Host from --s-mcp-host flag */
331
122
  mcpHost?: string;
332
- /** Path from --s-mcp-path flag */
333
123
  mcpPath?: string;
334
- /** Transports config from --s-mcp-transports flag */
335
124
  mcpTransports?: string;
336
- /** Log path from --s-mcp-log-path flag */
337
125
  mcpLogPath?: string;
338
- /** CORS config from --s-mcp-cors flag */
339
126
  mcpCors?: any;
340
- /** Auth config from --s-mcp-auth flag */
341
127
  mcpAuth?: any;
342
- /** Raw system flags that were detected but not explicitly typed */
343
128
  [key: string]: any;
344
129
  }
345
- /**
346
- * Types of interactive prompts supported by @clack/prompts integration.
347
- */
130
+ export type IHandlerContext<TCurrentCommandArgs = any, TParentCommandArgs = any> = {
131
+ args: TCurrentCommandArgs;
132
+ parentArgs?: TParentCommandArgs;
133
+ commandChain: string[];
134
+ parser: any;
135
+ parentParser?: any;
136
+ isMcp?: boolean;
137
+ isInteractive?: boolean;
138
+ getFlag?: (name: string) => any;
139
+ displayHelp: () => void;
140
+ rootPath?: string;
141
+ systemArgs?: ISystemArgs;
142
+ promptAnswers?: Record<string, any>;
143
+ logger: any;
144
+ };
145
+ export type MainHandler<TParserFlags extends FlagsArray = FlagsArray, TParentParserFlags extends FlagsArray = FlagsArray, THandlerReturn = any> = (ctx: IHandlerContext<TParsedArgs<TParserFlags>, TParsedArgs<TParentParserFlags>>) => THandlerReturn | Promise<THandlerReturn>;
146
+ export interface ISubCommand {
147
+ name: string;
148
+ description?: string;
149
+ parser: any;
150
+ handler?: (ctx: IHandlerContext) => any;
151
+ isMcp?: boolean;
152
+ mcpServerInfo?: {
153
+ name: string;
154
+ version: string;
155
+ description?: string;
156
+ };
157
+ mcpToolOptions?: any;
158
+ promptWhen?: PromptWhen;
159
+ onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
160
+ }
348
161
  export type PromptType = "text" | "password" | "confirm" | "select" | "multiselect";
349
- /**
350
- * Configuration for a single interactive prompt field.
351
- * Used to define the appearance and behavior of a prompt.
352
- *
353
- * @example
354
- * ```typescript
355
- * {
356
- * type: "select",
357
- * message: "Select environment:",
358
- * options: [
359
- * { label: "Staging", value: "staging", hint: "Safe for testing" },
360
- * { label: "Production", value: "production", hint: "Careful!" }
361
- * ],
362
- * validate: (val) => val !== "production" || confirm("Are you sure?")
363
- * }
364
- * ```
365
- */
366
162
  export interface PromptFieldConfig {
367
- /** Type of prompt to display */
368
163
  type: PromptType;
369
- /** Message shown to the user */
370
164
  message: string;
371
- /** Placeholder text (for text/password types) */
372
165
  placeholder?: string;
373
- /**
374
- * Initial/default value for the prompt.
375
- * For select: the value to pre-select
376
- * For multiselect: array of values to pre-select
377
- * For confirm: boolean initial value
378
- * Falls back to flag's defaultValue if not specified
379
- */
380
166
  initial?: any;
381
- /**
382
- * Validation function.
383
- * Return true for valid, string for error message.
384
- * Can be async.
385
- */
386
167
  validate?: (value: any, ctx: IHandlerContext) => boolean | string | Promise<boolean | string>;
387
- /**
388
- * Options for select/multiselect.
389
- * Can be simple strings or label/value objects.
390
- */
391
168
  options?: Array<string | {
392
169
  label: string;
393
170
  value: any;
394
171
  hint?: string;
395
172
  }>;
396
- /** Maximum items to show before scrolling (select/multiselect) */
397
173
  maxItems?: number;
398
- /**
399
- * If true, this prompt will be skipped and the flag will not be set.
400
- * Useful for conditional prompts based on previous answers.
401
- * @default false
402
- */
403
174
  skip?: boolean;
404
175
  }
405
- /**
406
- * When to trigger interactive prompts for a command.
407
- * - `"interactive-flag"`: Prompts shown only when `--interactive` or `-i` flag is present (default)
408
- * - `"missing"`: Prompts shown when any promptable flag is missing a value
409
- * - `"always"`: Always show prompts (overrides CLI args for promptable flags)
410
- */
411
176
  export type PromptWhen = "interactive-flag" | "missing" | "always";
412
- /**
413
- * Extended flag with interactive prompt capability.
414
- * Flags with a `prompt` property can participate in interactive mode.
415
- *
416
- * @example
417
- * ```typescript
418
- * cli.addFlag({
419
- * name: "environment",
420
- * options: ["--env", "-e"],
421
- * type: "string",
422
- * promptSequence: 1,
423
- * prompt: async (ctx) => ({
424
- * type: "select",
425
- * message: "Select environment:",
426
- * options: ["staging", "production"]
427
- * })
428
- * });
429
- * ```
430
- */
431
177
  export interface IPromptableFlag extends IFlag {
432
- /**
433
- * Prompt configuration factory.
434
- * If provided, this flag can participate in interactive mode.
435
- * Called at prompt time to get the configuration for @clack/prompts.
436
- *
437
- * The context (`ctx`) includes `promptAnswers` with previous answers,
438
- * enabling conditional prompts based on earlier selections.
439
- */
440
178
  prompt?: (ctx: IHandlerContext) => PromptFieldConfig | Promise<PromptFieldConfig>;
441
- /**
442
- * Explicit sequence order (1 = first, 2 = second, etc.)
443
- * If omitted, uses the flag's position in the parser's flag array.
444
- * Ties are broken by array order (first in array wins).
445
- */
446
179
  promptSequence?: number;
447
180
  }
448
- /**
449
- * Extended subcommand with interactive mode support.
450
- * Configure when prompts are shown and handle cancellation.
451
- *
452
- * @example
453
- * ```typescript
454
- * cli.addSubCommand({
455
- * name: "deploy",
456
- * description: "Deploy the application",
457
- * promptWhen: "interactive-flag",
458
- * parser: deployParser,
459
- * onCancel: () => console.log("Deployment cancelled")
460
- * });
461
- * ```
462
- */
463
181
  export interface IInteractiveSubCommand extends ISubCommand {
464
- /**
465
- * When to trigger interactive prompts for this command.
466
- * @default "interactive-flag"
467
- */
468
182
  promptWhen?: PromptWhen;
469
- /**
470
- * Called when user cancels (Ctrl+C) during prompts.
471
- * If not provided, exits gracefully with code 0.
472
- */
473
183
  onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
474
184
  }
475
- /**
476
- * Generic context object passed to command handlers.
477
- * @template TCurrentCommandArgs Shape of `args` for the current command, derived from its flags.
478
- * @template TParentCommandArgs Shape of `parentArgs` from the parent command, if any.
479
- */
480
- export type IHandlerContext<TCurrentCommandArgs = any, TParentCommandArgs = any> = {
481
- /** Parsed arguments specific to the current command. */
482
- args: TCurrentCommandArgs;
483
- /** Parsed arguments from the parent command, if this is a subcommand. */
484
- parentArgs?: TParentCommandArgs;
485
- /** The sequence of command names that led to this handler. */
486
- commandChain: string[];
487
- /** The `ArgParser` instance that invoked this handler (could be a subcommand's parser). */
488
- parser: ArgParserInstance;
489
- /** The parent `ArgParser` instance, if this is a subcommand handler. */
490
- parentParser?: ArgParserInstance;
491
- /** Optional: The root `ArgParser` instance of the CLI. */
492
- /** Indicates if the handler is being called from MCP mode (true) or CLI mode (false). */
493
- isMcp?: boolean;
494
- /**
495
- * Indicates if running in interactive mode (prompts were shown).
496
- * Only true when interactive prompts were triggered and completed.
497
- */
498
- isInteractive?: boolean;
499
- /**
500
- * Get a flag value with proper resolution priority (CLI flag > ENV > default).
501
- * Only available in MCP mode when isMcp is true.
502
- */
503
- getFlag?: (name: string) => any;
504
- /**
505
- * Display the help message for the current command context.
506
- */
507
- displayHelp: () => void;
508
- /**
509
- * The root path from the user's CLI command perspective.
510
- * This is the original current working directory when the CLI was invoked.
511
- *
512
- * Use this when you need to reference paths relative to where the user ran the command,
513
- * as opposed to the effective working directory (which may have been changed by
514
- * flags with `setWorkingDirectory`).
515
- *
516
- * @example
517
- * // User runs: my-cli --workspace ./packages/app --input ./data/file.txt
518
- * // From /repo/ directory
519
- *
520
- * // In handler:
521
- * console.log(ctx.rootPath); // "/repo/" (where user ran command)
522
- * console.log(process.cwd()); // "/repo/packages/app/" (effective cwd)
523
- * console.log(ctx.args.input); // "./data/file.txt" (relative to effective cwd)
524
- *
525
- * // To resolve ctx.args.input relative to user's cwd:
526
- * const userInputPath = path.resolve(ctx.rootPath, ctx.args.input);
527
- */
528
- rootPath?: string;
529
- /**
530
- * System flags that were detected during parsing.
531
- * These are flags that start with --s- and are processed internally by ArgParser.
532
- * They are made available to handlers for inspection and debugging.
533
- *
534
- * @example
535
- * // User runs: my-cli --s-debug --s-mcp-serve
536
- * // In handler:
537
- * console.log(ctx.systemArgs); // { debug: true, mcpServe: true }
538
- */
539
- systemArgs?: ISystemArgs;
540
- /**
541
- * Answers collected from interactive prompts.
542
- * Populated sequentially as prompts are answered.
543
- * Available to subsequent prompts for conditional logic.
544
- * Also available to the final handler.
545
- *
546
- * Keys are flag names, values are the user's answers.
547
- *
548
- * @example
549
- * // After prompts: environment="staging", version="1.2.3"
550
- * console.log(ctx.promptAnswers); // { environment: "staging", version: "1.2.3" }
551
- */
552
- promptAnswers?: Record<string, any>;
553
- /**
554
- * Data-safe logger instance.
555
- * In MCP mode, this logger ensures STDOUT safety by routing logs to STDERR or a file.
556
- */
557
- logger: any;
558
- };
559
- /**
560
- * Generic type for the collection of processed flags that an ArgParser instance manages.
561
- */
562
- export type FlagsArray = readonly ProcessedFlag[];
563
- /**
564
- * Converts a flag type to a JSON Schema type string.
565
- * This function handles all possible flag type formats and returns a valid JSON Schema type.
566
- *
567
- * @param flagType - The flag type from IFlag or ProcessedFlag
568
- * @returns A JSON Schema type string: "string" | "number" | "boolean" | "array" | "object"
569
- *
570
- * @example
571
- * ```typescript
572
- * getJsonSchemaTypeFromFlag(String) // returns "string"
573
- * getJsonSchemaTypeFromFlag("number") // returns "number"
574
- * getJsonSchemaTypeFromFlag((val) => parseInt(val)) // returns "string" (fallback for custom functions)
575
- * ```
576
- */
185
+ export type ArgParserInstance = any;
186
+ export interface ParseResult<T = any> {
187
+ success: boolean;
188
+ exitCode: number;
189
+ data?: T;
190
+ message?: string;
191
+ shouldExit?: boolean;
192
+ type?: "success" | "error" | "help" | "version" | "debug";
193
+ }
194
+ export interface ArgParserOptions {
195
+ autoExit?: boolean;
196
+ handleErrors?: boolean;
197
+ }
198
+ export interface ArgParserBehaviorOptions {
199
+ autoExit?: boolean;
200
+ handleErrors?: boolean;
201
+ }
577
202
  export declare function getJsonSchemaTypeFromFlag(flagType: TParsedArgsTypeFromFlagDef): "string" | "number" | "boolean" | "array" | "object";
578
- /**
579
- * Common output schema patterns for typical CLI/MCP tool responses
580
- */
581
203
  export declare const OutputSchemaPatterns: {
582
- /**
583
- * Simple success/error response pattern
584
- * @example { success: true, message: "Operation completed" }
585
- */
586
204
  readonly successError: () => z.ZodObject<{
587
205
  success: z.ZodBoolean;
588
206
  message: z.ZodOptional<z.ZodString>;
589
207
  error: z.ZodOptional<z.ZodString>;
590
208
  }, z.core.$strip>;
591
- /**
592
- * Success response with data payload
593
- * @example { success: true, data: {...}, message: "Data retrieved" }
594
- */
595
209
  readonly successWithData: (dataSchema?: z.ZodTypeAny) => z.ZodObject<{
596
210
  success: z.ZodBoolean;
597
211
  data: z.ZodAny | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
598
212
  message: z.ZodOptional<z.ZodString>;
599
213
  error: z.ZodOptional<z.ZodString>;
600
214
  }, z.core.$strip>;
601
- /**
602
- * List/array response pattern
603
- * @example { items: [...], count: 5, hasMore: false }
604
- */
605
215
  readonly list: (itemSchema?: z.ZodTypeAny) => z.ZodObject<{
606
216
  items: z.ZodArray<z.ZodAny | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
607
217
  count: z.ZodOptional<z.ZodNumber>;
608
218
  hasMore: z.ZodOptional<z.ZodBoolean>;
609
219
  }, z.core.$strip>;
610
- /**
611
- * File operation response pattern
612
- * @example { path: "/path/to/file", size: 1024, created: true }
613
- */
614
220
  readonly fileOperation: () => z.ZodObject<{
615
221
  path: z.ZodString;
616
222
  size: z.ZodOptional<z.ZodNumber>;
@@ -618,10 +224,6 @@ export declare const OutputSchemaPatterns: {
618
224
  modified: z.ZodOptional<z.ZodBoolean>;
619
225
  exists: z.ZodOptional<z.ZodBoolean>;
620
226
  }, z.core.$strip>;
621
- /**
622
- * Process execution response pattern
623
- * @example { exitCode: 0, stdout: "output", stderr: "", duration: 1500 }
624
- */
625
227
  readonly processExecution: () => z.ZodObject<{
626
228
  exitCode: z.ZodNumber;
627
229
  stdout: z.ZodOptional<z.ZodString>;
@@ -630,134 +232,23 @@ export declare const OutputSchemaPatterns: {
630
232
  command: z.ZodOptional<z.ZodString>;
631
233
  }, z.core.$strip>;
632
234
  };
633
- /**
634
- * Type for output schema pattern names with auto-completion support
635
- */
636
235
  export type OutputSchemaPatternName = keyof typeof OutputSchemaPatterns;
637
- /**
638
- * Type for output schema configuration - supports pattern names, Zod schemas, or schema definition objects
639
- */
640
236
  export type OutputSchemaConfig = OutputSchemaPatternName | z.ZodTypeAny | Record<string, z.ZodTypeAny>;
641
- /**
642
- * Creates a Zod output schema from a pattern or custom definition
643
- *
644
- * @param pattern - Either a predefined pattern name, a Zod schema, or a schema definition object
645
- * @returns A Zod schema for output validation
646
- *
647
- * @example
648
- * ```typescript
649
- * // Using a predefined pattern
650
- * const schema1 = createOutputSchema('successError');
651
- *
652
- * // Using a custom Zod schema
653
- * const schema2 = createOutputSchema(z.object({ result: z.string() }));
654
- *
655
- * // Using a schema definition object
656
- * const schema3 = createOutputSchema({
657
- * result: z.string().describe("The result"),
658
- * timestamp: z.string().describe("When the operation completed")
659
- * });
660
- * ```
661
- */
662
237
  export declare function createOutputSchema(pattern: OutputSchemaConfig): z.ZodTypeAny;
663
238
  /**
664
- * Defines a subcommand within an ArgParser setup.
665
- * @template TSubCommandFlags Flags defined specifically FOR this subcommand.
666
- * @template TParentCommandFlags Flags defined for the PARENT of this subcommand.
667
- * @template THandlerReturn The expected return type of the subcommand's handler.
668
- */
669
- export interface ISubCommand<TSubCommandFlags extends FlagsArray = FlagsArray, TParentCommandFlags extends FlagsArray = FlagsArray, THandlerReturn = any> {
670
- name: string;
671
- description?: string;
672
- /** The ArgParser instance for this subcommand, typed with its own flags. */
673
- parser: ArgParserInstance;
674
- /** Handler function for this subcommand. */
675
- handler?: (ctx: IHandlerContext<TParsedArgs<TSubCommandFlags>, TParsedArgs<TParentCommandFlags>>) => THandlerReturn | Promise<THandlerReturn>;
676
- /** Internal flag to identify MCP subcommands for proper exclusion from tool generation */
677
- isMcp?: boolean;
678
- /** MCP server information for DXT generation */
679
- mcpServerInfo?: {
680
- name: string;
681
- version: string;
682
- description?: string;
683
- };
684
- /** MCP tool generation options for DXT generation */
685
- mcpToolOptions?: any;
686
- /**
687
- * When to trigger interactive prompts for this command.
688
- * - `"interactive-flag"` (default): Prompts shown only when `--interactive` or `-i` flag is present
689
- * - `"missing"`: Prompts shown when any promptable flag is missing a value
690
- * - `"always"`: Always show prompts (overrides CLI args for promptable flags)
691
- *
692
- * @example
693
- * ```typescript
694
- * cli.addSubCommand({
695
- * name: "deploy",
696
- * description: "Deploy the application",
697
- * promptWhen: "interactive-flag",
698
- * parser: deployParser
699
- * });
700
- * ```
701
- */
702
- promptWhen?: PromptWhen;
703
- /**
704
- * Called when user cancels (Ctrl+C) during prompts.
705
- * If not provided, exits gracefully with code 0.
706
- *
707
- * @example
708
- * ```typescript
709
- * cli.addSubCommand({
710
- * name: "deploy",
711
- * parser: deployParser,
712
- * onCancel: (ctx) => console.log("Deployment cancelled by user")
713
- * });
714
- * ```
715
- */
716
- onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
717
- }
718
- /**
719
- * Result of parsing operations that replaces process.exit() calls.
720
- * Provides structured information about the parsing outcome.
721
- */
722
- export interface ParseResult<T = any> {
723
- /** Whether the parsing was successful */
724
- success: boolean;
725
- /** Exit code that would have been used with process.exit() */
726
- exitCode: number;
727
- /** The parsed data/result when successful */
728
- data?: T;
729
- /** Human-readable message about the result */
730
- message?: string;
731
- /** Whether the process should exit (for help, version, etc.) */
732
- shouldExit?: boolean;
733
- /** Type of result for better handling */
734
- type?: "success" | "error" | "help" | "version" | "debug";
735
- }
736
- /**
737
- * Configuration options for ArgParser behavior
738
- * @deprecated Use IArgParserParams for full configuration options. This interface will be removed in v3.0.
739
- */
740
- export interface ArgParserOptions {
741
- /** Whether to automatically call process.exit() based on ParseResult (default: true for backward compatibility) */
742
- autoExit?: boolean;
743
- /** Whether to handle errors by exiting or throwing (default: true for backward compatibility) */
744
- handleErrors?: boolean;
745
- }
746
- /**
747
- * Configuration options for ArgParser runtime behavior
748
- * This is a more clearly named version of ArgParserOptions
749
- */
750
- export interface ArgParserBehaviorOptions {
751
- /** Whether to automatically call process.exit() based on ParseResult (default: true for backward compatibility) */
752
- autoExit?: boolean;
753
- /** Whether to handle errors by exiting or throwing (default: true for backward compatibility) */
754
- handleErrors?: boolean;
239
+ * Result of executing prompts
240
+ */
241
+ export interface PromptResult {
242
+ /** Collected answers */
243
+ answers: Record<string, any>;
244
+ /** Individual prompt results */
245
+ results: Array<{
246
+ flagName: string;
247
+ success: boolean;
248
+ value?: any;
249
+ error?: string;
250
+ }>;
251
+ /** Whether the user cancelled */
252
+ cancelled: boolean;
755
253
  }
756
- /**
757
- * Type for the main handler of an ArgParser instance (root command or a command defined by an ArgParser).
758
- * @template TParserFlags Flags defined for this ArgParser instance.
759
- * @template TParentParserFlags Flags of the parent parser, if this parser is used as a subcommand.
760
- * @template THandlerReturn The expected return type of the handler.
761
- */
762
- export type MainHandler<TParserFlags extends FlagsArray = FlagsArray, TParentParserFlags extends FlagsArray = FlagsArray, THandlerReturn = any> = (ctx: IHandlerContext<TParsedArgs<TParserFlags>, TParsedArgs<TParentParserFlags>>) => THandlerReturn | Promise<THandlerReturn>;
763
254
  //# sourceMappingURL=types.d.ts.map