@runa-cmd/core 0.1.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.
- package/LICENSE +21 -0
- package/README.md +351 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +413 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.d.ts +20 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +46 -0
- package/dist/command.js.map +1 -0
- package/dist/config/loader.d.ts +9 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +34 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/merge.d.ts +18 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +31 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/search.d.ts +18 -0
- package/dist/config/search.d.ts.map +1 -0
- package/dist/config/search.js +40 -0
- package/dist/config/search.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect.d.ts +16 -0
- package/dist/introspect.d.ts.map +1 -0
- package/dist/introspect.js +128 -0
- package/dist/introspect.js.map +1 -0
- package/dist/lifecycle.d.ts +27 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +62 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/middleware.d.ts +16 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +15 -0
- package/dist/middleware.js.map +1 -0
- package/dist/parse/parseargs-bridge.d.ts +22 -0
- package/dist/parse/parseargs-bridge.d.ts.map +1 -0
- package/dist/parse/parseargs-bridge.js +54 -0
- package/dist/parse/parseargs-bridge.js.map +1 -0
- package/dist/parse/resolve.d.ts +48 -0
- package/dist/parse/resolve.d.ts.map +1 -0
- package/dist/parse/resolve.js +240 -0
- package/dist/parse/resolve.js.map +1 -0
- package/dist/parse/schema-walker.d.ts +21 -0
- package/dist/parse/schema-walker.d.ts.map +1 -0
- package/dist/parse/schema-walker.js +121 -0
- package/dist/parse/schema-walker.js.map +1 -0
- package/dist/parse/variadic.d.ts +22 -0
- package/dist/parse/variadic.d.ts.map +1 -0
- package/dist/parse/variadic.js +71 -0
- package/dist/parse/variadic.js.map +1 -0
- package/dist/plugin.d.ts +53 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +194 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +225 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/dist/zod.d.ts +8 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +8 -0
- package/dist/zod.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Config file discovery
|
|
3
|
+
*
|
|
4
|
+
* Searches up search paths for config files matching {name}.config.{ext}.
|
|
5
|
+
* First match wins. Returns null if no config found.
|
|
6
|
+
*/
|
|
7
|
+
import { access } from 'node:fs/promises';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
/**
|
|
11
|
+
* Search for a config file in the given paths.
|
|
12
|
+
*
|
|
13
|
+
* For each search path, for each loader, checks if
|
|
14
|
+
* `{path}/{name}.config{ext}` exists.
|
|
15
|
+
*
|
|
16
|
+
* Search paths are checked in order; first match wins.
|
|
17
|
+
* '~' is resolved to os.homedir().
|
|
18
|
+
*
|
|
19
|
+
* Returns null if no config file is found (not an error).
|
|
20
|
+
*/
|
|
21
|
+
export async function searchConfig(name, loaders, searchPaths) {
|
|
22
|
+
for (const rawPath of searchPaths) {
|
|
23
|
+
// Resolve ~ to home directory
|
|
24
|
+
const searchPath = rawPath === '~' ? homedir() : rawPath;
|
|
25
|
+
for (const loader of loaders) {
|
|
26
|
+
for (const ext of loader.extensions) {
|
|
27
|
+
const filePath = join(searchPath, `${name}.config${ext}`);
|
|
28
|
+
try {
|
|
29
|
+
await access(filePath);
|
|
30
|
+
return { filePath, loader };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// File does not exist, continue searching
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/config/search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAUjC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,IAAY,EACZ,OAAuB,EACvB,WAAqB;IAErB,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE,CAAC;QACnC,8BAA8B;QAC9B,MAAM,UAAU,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAEzD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,UAAU,GAAG,EAAE,CAAC,CAAC;gBAC1D,IAAI,CAAC;oBACJ,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;oBACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;gBAC7B,CAAC;gBAAC,MAAM,CAAC;oBACR,0CAA0C;gBAC3C,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Error class hierarchy
|
|
3
|
+
*
|
|
4
|
+
* RunaError (base) → ValidationError | CommandNotFoundError | CommandError
|
|
5
|
+
* POSIX-aligned exit codes: 2 (usage), 127 (not found), 1 (general).
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from 'zod';
|
|
8
|
+
type ZodIssue = z.core.$ZodIssue;
|
|
9
|
+
export declare class RunaError extends Error {
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly exitCode: number;
|
|
12
|
+
constructor(message: string, options: {
|
|
13
|
+
code: string;
|
|
14
|
+
exitCode?: number;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export declare class ValidationError extends RunaError {
|
|
18
|
+
readonly issues: ZodIssue[];
|
|
19
|
+
constructor(issues: ZodIssue[]);
|
|
20
|
+
}
|
|
21
|
+
export declare class CommandNotFoundError extends RunaError {
|
|
22
|
+
readonly suggestion?: string;
|
|
23
|
+
constructor(commandName: string, suggestion?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class CommandError extends RunaError {
|
|
26
|
+
constructor(message: string, options?: {
|
|
27
|
+
code?: string;
|
|
28
|
+
exitCode?: number;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,KAAK,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;AASjC,qBAAa,SAAU,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;CAUzE;AAID,qBAAa,eAAgB,SAAQ,SAAS;IAC7C,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;gBAEhB,MAAM,EAAE,QAAQ,EAAE;CAgB9B;AAID,qBAAa,oBAAqB,SAAQ,SAAS;IAClD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAapD;AAID,qBAAa,YAAa,SAAQ,SAAS;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;CAW3E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// V8-specific: captureStackTrace is not in the standard Error type
|
|
2
|
+
const captureStackTrace =
|
|
3
|
+
// biome-ignore lint/complexity/noBannedTypes: V8's captureStackTrace expects Function for the constructor argument
|
|
4
|
+
Error.captureStackTrace;
|
|
5
|
+
// ─── RunaError ──────────────────────────────────────────────
|
|
6
|
+
export class RunaError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
exitCode;
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'RunaError';
|
|
12
|
+
this.code = options.code;
|
|
13
|
+
this.exitCode = options.exitCode ?? 1;
|
|
14
|
+
if (captureStackTrace) {
|
|
15
|
+
captureStackTrace(this, this.constructor);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// ─── ValidationError ────────────────────────────────────────
|
|
20
|
+
export class ValidationError extends RunaError {
|
|
21
|
+
issues;
|
|
22
|
+
constructor(issues) {
|
|
23
|
+
const message = issues
|
|
24
|
+
.map((issue) => {
|
|
25
|
+
const path = issue.path.length > 0 ? `${issue.path.join('.')}: ` : '';
|
|
26
|
+
return `${path}${issue.message}`;
|
|
27
|
+
})
|
|
28
|
+
.join('\n');
|
|
29
|
+
super(message, { code: 'VALIDATION_ERROR', exitCode: 2 });
|
|
30
|
+
this.name = 'ValidationError';
|
|
31
|
+
this.issues = issues;
|
|
32
|
+
if (captureStackTrace) {
|
|
33
|
+
captureStackTrace(this, this.constructor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// ─── CommandNotFoundError ───────────────────────────────────
|
|
38
|
+
export class CommandNotFoundError extends RunaError {
|
|
39
|
+
suggestion;
|
|
40
|
+
constructor(commandName, suggestion) {
|
|
41
|
+
const message = suggestion
|
|
42
|
+
? `Command not found: '${commandName}'. Did you mean '${suggestion}'?`
|
|
43
|
+
: `Command not found: '${commandName}'.`;
|
|
44
|
+
super(message, { code: 'COMMAND_NOT_FOUND', exitCode: 127 });
|
|
45
|
+
this.name = 'CommandNotFoundError';
|
|
46
|
+
this.suggestion = suggestion;
|
|
47
|
+
if (captureStackTrace) {
|
|
48
|
+
captureStackTrace(this, this.constructor);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// ─── CommandError ───────────────────────────────────────────
|
|
53
|
+
export class CommandError extends RunaError {
|
|
54
|
+
constructor(message, options) {
|
|
55
|
+
super(message, {
|
|
56
|
+
code: options?.code ?? 'COMMAND_ERROR',
|
|
57
|
+
exitCode: options?.exitCode ?? 1,
|
|
58
|
+
});
|
|
59
|
+
this.name = 'CommandError';
|
|
60
|
+
if (captureStackTrace) {
|
|
61
|
+
captureStackTrace(this, this.constructor);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map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re-exports the complete public surface of @runa-cmd/core.
|
|
5
|
+
* Internal modules (schema-walker, parseargs-bridge, resolve, variadic) are NOT exported.
|
|
6
|
+
*/
|
|
7
|
+
export { defineCLI, runCLI } from './cli.js';
|
|
8
|
+
export { defineCommand } from './command.js';
|
|
9
|
+
export { jsonLoader } from './config/loader.js';
|
|
10
|
+
export { CommandError, CommandNotFoundError, RunaError, ValidationError, } from './errors.js';
|
|
11
|
+
export { getSchema } from './introspect.js';
|
|
12
|
+
export { defineMiddleware } from './middleware.js';
|
|
13
|
+
export { definePlugin } from './plugin.js';
|
|
14
|
+
export type { ArgSchema, CLI, CLIConfig, CLIConfigOptions, CLIMeta, CLISchema, Command, CommandConfig, CommandMeta, CommandSchema, CommandTree, ConfigLoader, HookContext, HookHandler, HookName, InferArgs, InferOptions, Middleware, MiddlewareContext, MiddlewareFn, OptionMeta, OptionSchema, ParamMetadata, ParamType, PluginAPI, PluginCapabilities, PluginConfig, PluginMeta, RunContext, RunReturn, } from './types.js';
|
|
15
|
+
export { HOOK_NAMES, PARAM_TYPES } from './types.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACN,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACT,eAAe,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,YAAY,EACX,SAAS,EACT,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,OAAO,EAEP,SAAS,EAET,OAAO,EAEP,aAAa,EAEb,WAAW,EACX,aAAa,EACb,WAAW,EAEX,YAAY,EACZ,WAAW,EACX,WAAW,EAEX,QAAQ,EAER,SAAS,EACT,YAAY,EAEZ,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,YAAY,EAEZ,aAAa,EACb,SAAS,EACT,SAAS,EACT,kBAAkB,EAElB,YAAY,EACZ,UAAU,EAEV,UAAU,EACV,SAAS,GACT,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Public API
|
|
3
|
+
*
|
|
4
|
+
* This barrel re-exports the complete public surface of @runa-cmd/core.
|
|
5
|
+
* Internal modules (schema-walker, parseargs-bridge, resolve, variadic) are NOT exported.
|
|
6
|
+
*/
|
|
7
|
+
export { defineCLI, runCLI } from './cli.js';
|
|
8
|
+
// ─── Builder functions ──────────────────────────────────────
|
|
9
|
+
export { defineCommand } from './command.js';
|
|
10
|
+
// ─── Config utilities ───────────────────────────────────────
|
|
11
|
+
export { jsonLoader } from './config/loader.js';
|
|
12
|
+
// ─── Error classes ──────────────────────────────────────────
|
|
13
|
+
export { CommandError, CommandNotFoundError, RunaError, ValidationError, } from './errors.js';
|
|
14
|
+
// ─── Introspection ──────────────────────────────────────────
|
|
15
|
+
export { getSchema } from './introspect.js';
|
|
16
|
+
export { defineMiddleware } from './middleware.js';
|
|
17
|
+
export { definePlugin } from './plugin.js';
|
|
18
|
+
// ─── Runtime constants ──────────────────────────────────────
|
|
19
|
+
export { HOOK_NAMES, PARAM_TYPES } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,+DAA+D;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,+DAA+D;AAC/D,OAAO,EACN,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACT,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,+DAA+D;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+C3C,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Schema introspection
|
|
3
|
+
*
|
|
4
|
+
* getSchema() walks the command tree and extracts structured metadata
|
|
5
|
+
* (CLISchema) for use by plugins (help, MCP, completions).
|
|
6
|
+
*/
|
|
7
|
+
import type { ZodType } from 'zod';
|
|
8
|
+
import type { CLIConfig, CLISchema, OptionMeta } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Extract the full CLI schema for introspection.
|
|
11
|
+
*
|
|
12
|
+
* Used by plugins (help, MCP, completions) to discover commands,
|
|
13
|
+
* args, options, and metadata without executing anything.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSchema(config: CLIConfig, extraGlobalOptions?: Record<string, ZodType>, extraGlobalMeta?: Record<string, OptionMeta>): CLISchema;
|
|
16
|
+
//# sourceMappingURL=introspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EAEX,SAAS,EACT,SAAS,EAIT,UAAU,EAEV,MAAM,YAAY,CAAC;AA6FpB;;;;;GAKG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,SAAS,EACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAC1C,SAAS,CAwCX"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { walkSchema } from './parse/schema-walker.js';
|
|
2
|
+
// ─── Helpers ────────────────────────────────────────────────
|
|
3
|
+
function isCommand(value) {
|
|
4
|
+
return '_type' in value && value._type === 'runa:command';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Walk a command and extract its schema information.
|
|
8
|
+
*/
|
|
9
|
+
function walkCommand(name, command, parentPath) {
|
|
10
|
+
const fullPath = [...parentPath, name];
|
|
11
|
+
// Extract arg schemas
|
|
12
|
+
const argSchemas = [];
|
|
13
|
+
if (command.args) {
|
|
14
|
+
const metadata = walkSchema(command.args);
|
|
15
|
+
for (const meta of metadata) {
|
|
16
|
+
argSchemas.push({
|
|
17
|
+
name: meta.name,
|
|
18
|
+
description: meta.description,
|
|
19
|
+
type: meta.zodType,
|
|
20
|
+
required: !meta.isOptional,
|
|
21
|
+
defaultValue: meta.defaultValue,
|
|
22
|
+
isVariadic: meta.isArray,
|
|
23
|
+
enumValues: meta.enumValues,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Extract option schemas
|
|
28
|
+
const optionSchemas = [];
|
|
29
|
+
if (command.options) {
|
|
30
|
+
const metadata = walkSchema(command.options);
|
|
31
|
+
const optMeta = (command.meta.options ?? {});
|
|
32
|
+
for (const meta of metadata) {
|
|
33
|
+
const om = optMeta[meta.name];
|
|
34
|
+
optionSchemas.push({
|
|
35
|
+
name: meta.name,
|
|
36
|
+
description: meta.description,
|
|
37
|
+
type: meta.zodType,
|
|
38
|
+
required: !meta.isOptional,
|
|
39
|
+
defaultValue: meta.defaultValue,
|
|
40
|
+
alias: om?.alias,
|
|
41
|
+
env: om?.env,
|
|
42
|
+
group: om?.group,
|
|
43
|
+
deprecated: om?.deprecated,
|
|
44
|
+
hint: om?.hint,
|
|
45
|
+
enumValues: meta.enumValues,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
description: command.meta.description,
|
|
52
|
+
fullPath,
|
|
53
|
+
args: argSchemas,
|
|
54
|
+
options: optionSchemas,
|
|
55
|
+
hasOutput: !!command.output,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Recursively walk a command tree and extract schemas for all commands.
|
|
60
|
+
*/
|
|
61
|
+
function walkTree(tree, parentPath) {
|
|
62
|
+
const schemas = [];
|
|
63
|
+
for (const [name, entry] of Object.entries(tree)) {
|
|
64
|
+
if (isCommand(entry)) {
|
|
65
|
+
schemas.push(walkCommand(name, entry, parentPath));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// It's a subtree — recurse and collect as subcommands
|
|
69
|
+
const subcommands = walkTree(entry, [...parentPath, name]);
|
|
70
|
+
schemas.push({
|
|
71
|
+
name,
|
|
72
|
+
description: '',
|
|
73
|
+
fullPath: [...parentPath, name],
|
|
74
|
+
args: [],
|
|
75
|
+
options: [],
|
|
76
|
+
hasOutput: false,
|
|
77
|
+
subcommands,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return schemas;
|
|
82
|
+
}
|
|
83
|
+
// ─── Public API ─────────────────────────────────────────────
|
|
84
|
+
/**
|
|
85
|
+
* Extract the full CLI schema for introspection.
|
|
86
|
+
*
|
|
87
|
+
* Used by plugins (help, MCP, completions) to discover commands,
|
|
88
|
+
* args, options, and metadata without executing anything.
|
|
89
|
+
*/
|
|
90
|
+
export function getSchema(config, extraGlobalOptions, extraGlobalMeta) {
|
|
91
|
+
// Walk the command tree
|
|
92
|
+
const commands = walkTree(config.commands, []);
|
|
93
|
+
// Extract global option schemas
|
|
94
|
+
const globalOptionSchemas = [];
|
|
95
|
+
const allGlobalOptions = {
|
|
96
|
+
...(config.globalOptions ?? {}),
|
|
97
|
+
...(extraGlobalOptions ?? {}),
|
|
98
|
+
};
|
|
99
|
+
const allGlobalMeta = {
|
|
100
|
+
...(config.globalMeta?.options ?? {}),
|
|
101
|
+
...(extraGlobalMeta ?? {}),
|
|
102
|
+
};
|
|
103
|
+
if (Object.keys(allGlobalOptions).length > 0) {
|
|
104
|
+
const metadata = walkSchema(allGlobalOptions);
|
|
105
|
+
for (const meta of metadata) {
|
|
106
|
+
const om = allGlobalMeta[meta.name];
|
|
107
|
+
globalOptionSchemas.push({
|
|
108
|
+
name: meta.name,
|
|
109
|
+
description: meta.description,
|
|
110
|
+
type: meta.zodType,
|
|
111
|
+
required: !meta.isOptional,
|
|
112
|
+
defaultValue: meta.defaultValue,
|
|
113
|
+
alias: om?.alias,
|
|
114
|
+
env: om?.env,
|
|
115
|
+
group: om?.group,
|
|
116
|
+
deprecated: om?.deprecated,
|
|
117
|
+
hint: om?.hint,
|
|
118
|
+
enumValues: meta.enumValues,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
meta: config.meta,
|
|
124
|
+
commands,
|
|
125
|
+
globalOptions: globalOptionSchemas,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=introspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspect.js","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAYtD,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AK;gBAChB,GAAG,EAAE,EAAE,EAAE,GAAG;gBACZ,KAAK,EAAE,EAAE,EAAE,KAAK;gBAChB,UAAU,EAAE,EAAE,EAAE,UAAU;gBAC1B,IAAI,EAAE,EAAE,EAAE,IAAI;gBACd,UAAU,EAAE,IAAI,CAAC,UAAU;aAC3B,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ;QACR,aAAa,EAAE,mBAAmB;KAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Lifecycle hook registry + execution engine
|
|
3
|
+
*
|
|
4
|
+
* Manages the 7-hook pipeline:
|
|
5
|
+
* beforeParse → onGlobalFlags → afterParse → beforeRun → afterRun → onError → cleanup
|
|
6
|
+
*
|
|
7
|
+
* Hooks are sequential arrays. Cleanup ALWAYS runs.
|
|
8
|
+
*/
|
|
9
|
+
import type { HookContext, HookHandler, HookName } from './types.js';
|
|
10
|
+
export interface EmitResult {
|
|
11
|
+
/** True if an onGlobalFlags handler called shortCircuit() */
|
|
12
|
+
shortCircuited: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface HookRegistry {
|
|
15
|
+
/** Register a handler for a lifecycle hook */
|
|
16
|
+
register(name: HookName, handler: HookHandler): void;
|
|
17
|
+
/** Emit a hook, running all handlers in registration order */
|
|
18
|
+
emit(name: HookName, context: HookContext): Promise<EmitResult>;
|
|
19
|
+
/** Get all handlers for a hook (for testing/introspection) */
|
|
20
|
+
getHandlers(name: HookName): HookHandler[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new hook registry.
|
|
24
|
+
* Handlers are stored per hook name and execute in registration order.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createHookRegistry(): HookRegistry;
|
|
27
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIrE,MAAM,WAAW,UAAU;IAC1B,6DAA6D;IAC7D,cAAc,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACrD,8DAA8D;IAC9D,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChE,8DAA8D;IAC9D,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,EAAE,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CA+DjD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new hook registry.
|
|
3
|
+
* Handlers are stored per hook name and execute in registration order.
|
|
4
|
+
*/
|
|
5
|
+
export function createHookRegistry() {
|
|
6
|
+
const handlers = new Map();
|
|
7
|
+
return {
|
|
8
|
+
register(name, handler) {
|
|
9
|
+
if (!handlers.has(name)) {
|
|
10
|
+
handlers.set(name, []);
|
|
11
|
+
}
|
|
12
|
+
const list = handlers.get(name);
|
|
13
|
+
if (list) {
|
|
14
|
+
list.push(handler);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async emit(name, context) {
|
|
18
|
+
const hookHandlers = handlers.get(name) ?? [];
|
|
19
|
+
let shortCircuited = false;
|
|
20
|
+
if (name === 'onGlobalFlags') {
|
|
21
|
+
// onGlobalFlags supports short-circuit via context.shortCircuit()
|
|
22
|
+
let didShortCircuit = false;
|
|
23
|
+
const ctxWithShortCircuit = {
|
|
24
|
+
...context,
|
|
25
|
+
shortCircuit: () => {
|
|
26
|
+
didShortCircuit = true;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
for (const handler of hookHandlers) {
|
|
30
|
+
await handler(ctxWithShortCircuit);
|
|
31
|
+
if (didShortCircuit) {
|
|
32
|
+
shortCircuited = true;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { shortCircuited };
|
|
37
|
+
}
|
|
38
|
+
if (name === 'cleanup') {
|
|
39
|
+
// Cleanup handlers: each wrapped in try/catch, ALL must run
|
|
40
|
+
for (const handler of hookHandlers) {
|
|
41
|
+
try {
|
|
42
|
+
await handler(context);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Cleanup errors are swallowed to ensure all handlers run.
|
|
46
|
+
// Plugin cleanup errors are reported separately.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { shortCircuited: false };
|
|
50
|
+
}
|
|
51
|
+
// Standard hooks: run sequentially, propagate errors
|
|
52
|
+
for (const handler of hookHandlers) {
|
|
53
|
+
await handler(context);
|
|
54
|
+
}
|
|
55
|
+
return { shortCircuited: false };
|
|
56
|
+
},
|
|
57
|
+
getHandlers(name) {
|
|
58
|
+
return handlers.get(name) ?? [];
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IACjC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEpD,OAAO;QACN,QAAQ,CAAC,IAAc,EAAE,OAAoB;YAC5C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE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AO,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YAED,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC;QAED,WAAW,CAAC,IAAc;YACzB,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — defineMiddleware()
|
|
3
|
+
*
|
|
4
|
+
* Simple wrapper that brands a MiddlewareFn into a Middleware object.
|
|
5
|
+
* Middleware follows the Koa/Hono onion model with next().
|
|
6
|
+
*/
|
|
7
|
+
import type { Middleware, MiddlewareFn } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create a branded Middleware from a handler function.
|
|
10
|
+
*
|
|
11
|
+
* Middleware handlers are async functions receiving { next, globalOptions }.
|
|
12
|
+
* Call `await next()` to execute the next middleware or command.
|
|
13
|
+
* Code before next() runs before the command; code after runs after.
|
|
14
|
+
*/
|
|
15
|
+
export declare function defineMiddleware(handler: MiddlewareFn): Middleware;
|
|
16
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI3D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAKlE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// ─── Public API ─────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Create a branded Middleware from a handler function.
|
|
4
|
+
*
|
|
5
|
+
* Middleware handlers are async functions receiving { next, globalOptions }.
|
|
6
|
+
* Call `await next()` to execute the next middleware or command.
|
|
7
|
+
* Code before next() runs before the command; code after runs after.
|
|
8
|
+
*/
|
|
9
|
+
export function defineMiddleware(handler) {
|
|
10
|
+
return {
|
|
11
|
+
_type: 'runa:middleware',
|
|
12
|
+
handler,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAQA,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAqB;IACrD,OAAO;QACN,KAAK,EAAE,iBAA0B;QACjC,OAAO;KACP,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — util.parseArgs bridge
|
|
3
|
+
*
|
|
4
|
+
* Converts schema walker metadata + option meta into a valid
|
|
5
|
+
* util.parseArgs configuration object.
|
|
6
|
+
*/
|
|
7
|
+
import type { ParseArgsConfig } from 'node:util';
|
|
8
|
+
import type { OptionMeta, ParamMetadata } from '../types.js';
|
|
9
|
+
export interface ParseArgsBridgeConfig {
|
|
10
|
+
parseArgsConfig: ParseArgsConfig;
|
|
11
|
+
/** Maps long alias names → canonical option name */
|
|
12
|
+
longAliasMap: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build a util.parseArgs configuration from schema walker output.
|
|
16
|
+
*
|
|
17
|
+
* @param metadata - Parameter metadata from schema walker (for options only)
|
|
18
|
+
* @param optionMeta - OptionMeta from meta.options (aliases, env, etc.)
|
|
19
|
+
* @param hasArgs - Whether the command has positional args
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildParseArgsConfig(metadata: ParamMetadata[], optionMeta?: Record<string, OptionMeta>, hasArgs?: boolean): ParseArgsBridgeConfig;
|
|
22
|
+
//# sourceMappingURL=parseargs-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseargs-bridge.d.ts","sourceRoot":"","sources":["../../src/parse/parseargs-bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,WAAW,qBAAqB;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAID;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,aAAa,EAAE,EACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACvC,OAAO,CAAC,EAAE,OAAO,GACf,qBAAqB,CAsDvB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// ─── Public API ─────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Build a util.parseArgs configuration from schema walker output.
|
|
4
|
+
*
|
|
5
|
+
* @param metadata - Parameter metadata from schema walker (for options only)
|
|
6
|
+
* @param optionMeta - OptionMeta from meta.options (aliases, env, etc.)
|
|
7
|
+
* @param hasArgs - Whether the command has positional args
|
|
8
|
+
*/
|
|
9
|
+
export function buildParseArgsConfig(metadata, optionMeta, hasArgs) {
|
|
10
|
+
const options = {};
|
|
11
|
+
const longAliasMap = {};
|
|
12
|
+
for (const param of metadata) {
|
|
13
|
+
// Map Zod type → parseArgs type
|
|
14
|
+
// boolean → 'boolean' (enables --no-* negation)
|
|
15
|
+
// everything else → 'string' (Zod handles coercion later)
|
|
16
|
+
const parseArgsType = param.zodType === 'boolean' ? 'boolean' : 'string';
|
|
17
|
+
const optConfig = {
|
|
18
|
+
type: parseArgsType,
|
|
19
|
+
};
|
|
20
|
+
// Extract aliases from meta
|
|
21
|
+
const meta = optionMeta?.[param.name];
|
|
22
|
+
if (meta?.alias) {
|
|
23
|
+
for (const alias of meta.alias) {
|
|
24
|
+
if (alias.startsWith('--')) {
|
|
25
|
+
// Long alias: register as a separate option pointing to the same name
|
|
26
|
+
const longName = alias.slice(2);
|
|
27
|
+
longAliasMap[longName] = param.name;
|
|
28
|
+
// Register the long alias in parseArgs too
|
|
29
|
+
options[longName] = { type: parseArgsType };
|
|
30
|
+
}
|
|
31
|
+
else if (alias.startsWith('-') && alias.length === 2) {
|
|
32
|
+
// Short alias: single char after '-'
|
|
33
|
+
optConfig.short = alias[1];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Set boolean defaults so parseArgs returns them correctly
|
|
38
|
+
// For booleans with defaults, pass the default to parseArgs
|
|
39
|
+
if (parseArgsType === 'boolean' && param.defaultValue !== undefined) {
|
|
40
|
+
optConfig.default = param.defaultValue;
|
|
41
|
+
}
|
|
42
|
+
options[param.name] = optConfig;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
parseArgsConfig: {
|
|
46
|
+
options,
|
|
47
|
+
allowPositionals: hasArgs ?? false,
|
|
48
|
+
strict: false, // Let Zod handle unknown option errors
|
|
49
|
+
allowNegative: true, // Enable --no-* boolean negation
|
|
50
|
+
},
|
|
51
|
+
longAliasMap,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=parseargs-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseargs-bridge.js","sourceRoot":"","sources":["../../src/parse/parseargs-bridge.ts"],"names":[],"mappings":"AAiBA,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CACnC,QAAyB,EACzB,UAAuC,EACvC,OAAiB;IAEjB,MAAM,OAAO,GAA4C,EAAE,CAAC;IAC5D,MAAM,YAAY,GAA2B,EAAE,CAAC;IAEhD,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9B,gCAAgC;QAChC,gDAAgD;QAChD,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EAAE,KAAK,EAAE,uCAAuC;YACtD,aAAa,EAAE,IAAI,EAAE,iCAAiC;SACtD;QACD,YAAY;KACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @runa-cmd/core — Value resolution pipeline
|
|
3
|
+
*
|
|
4
|
+
* Merge priority: CLI args > env vars > config file > Zod defaults.
|
|
5
|
+
* Maps positionals to args by insertion order.
|
|
6
|
+
* Pre-coerces number strings before Zod .parse().
|
|
7
|
+
*/
|
|
8
|
+
import { type ZodType } from 'zod';
|
|
9
|
+
import type { OptionMeta } from '../types.js';
|
|
10
|
+
export interface ParseArgsResult {
|
|
11
|
+
values: Record<string, unknown>;
|
|
12
|
+
positionals: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface ResolveInput {
|
|
15
|
+
/** Raw output from util.parseArgs */
|
|
16
|
+
parseArgsResult: ParseArgsResult;
|
|
17
|
+
/** Long alias map from parseargs-bridge */
|
|
18
|
+
longAliasMap?: Record<string, string>;
|
|
19
|
+
/** Command schemas */
|
|
20
|
+
schemas: {
|
|
21
|
+
args?: Record<string, ZodType>;
|
|
22
|
+
options?: Record<string, ZodType>;
|
|
23
|
+
};
|
|
24
|
+
/** Option metadata (for env var mapping) */
|
|
25
|
+
meta?: {
|
|
26
|
+
options?: Record<string, OptionMeta>;
|
|
27
|
+
};
|
|
28
|
+
/** Config file values */
|
|
29
|
+
configValues?: Record<string, unknown>;
|
|
30
|
+
/** Environment variables (defaults to process.env, injectable for testing) */
|
|
31
|
+
env?: Record<string, string | undefined>;
|
|
32
|
+
}
|
|
33
|
+
export interface ResolveOutput {
|
|
34
|
+
parsedArgs: Record<string, unknown>;
|
|
35
|
+
parsedOptions: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve values from all sources and validate through Zod.
|
|
39
|
+
*
|
|
40
|
+
* Pipeline:
|
|
41
|
+
* 1. Map positionals to args by insertion order
|
|
42
|
+
* 2. Merge option values (CLI > env > config)
|
|
43
|
+
* 3. Pre-coerce number strings
|
|
44
|
+
* 4. Validate through Zod schemas
|
|
45
|
+
* 5. Return typed results or throw ValidationError
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveValues(input: ResolveInput): ResolveOutput;
|
|
48
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/parse/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAY,KAAK,OAAO,EAAK,MAAM,KAAK,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AAM7D,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,qCAAqC;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,sBAAsB;IACtB,OAAO,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,CAAC;IACF,4CAA4C;IAC5C,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KAAE,CAAC;IAChD,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IA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