padrone 1.5.0 → 1.6.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/CHANGELOG.md +36 -0
- package/README.md +15 -11
- package/dist/{args-D5PNDyNu.mjs → args-Cnq0nwSM.mjs} +91 -41
- package/dist/args-Cnq0nwSM.mjs.map +1 -0
- package/dist/codegen/index.mjs +4 -4
- package/dist/codegen/index.mjs.map +1 -1
- package/dist/commands-B_gufyR9.mjs +514 -0
- package/dist/commands-B_gufyR9.mjs.map +1 -0
- package/dist/{completion.mjs → completion-BEuflbDO.mjs} +12 -82
- package/dist/completion-BEuflbDO.mjs.map +1 -0
- package/dist/docs/index.d.mts +4 -4
- package/dist/docs/index.d.mts.map +1 -1
- package/dist/docs/index.mjs +10 -12
- package/dist/docs/index.mjs.map +1 -1
- package/dist/{errors-BiVrBgi6.mjs → errors-CL63UOzt.mjs} +26 -3
- package/dist/errors-CL63UOzt.mjs.map +1 -0
- package/dist/{formatter-DtHzbP22.d.mts → formatter-DrvhDMrq.d.mts} +3 -3
- package/dist/formatter-DrvhDMrq.d.mts.map +1 -0
- package/dist/{help-bbmu9-qd.mjs → help-B5Kk83of.mjs} +151 -37
- package/dist/help-B5Kk83of.mjs.map +1 -0
- package/dist/{types-Ch8Mk6Qb.d.mts → index-BaU3X6dY.d.mts} +621 -750
- package/dist/index-BaU3X6dY.d.mts.map +1 -0
- package/dist/index.d.mts +735 -37
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3409 -1563
- package/dist/index.mjs.map +1 -1
- package/dist/{mcp-mLWIdUIu.mjs → mcp-BM-d0nZi.mjs} +13 -15
- package/dist/mcp-BM-d0nZi.mjs.map +1 -0
- package/dist/{serve-B0u43DK7.mjs → serve-Bk0JUlCj.mjs} +12 -14
- package/dist/serve-Bk0JUlCj.mjs.map +1 -0
- package/dist/{stream-BcC146Ud.mjs → stream-DC4H8YTx.mjs} +24 -3
- package/dist/stream-DC4H8YTx.mjs.map +1 -0
- package/dist/test.d.mts +5 -8
- package/dist/test.d.mts.map +1 -1
- package/dist/test.mjs +2 -13
- package/dist/test.mjs.map +1 -1
- package/dist/{update-check-CFX1FV3v.mjs → update-check-CZ2VqjnV.mjs} +16 -17
- package/dist/update-check-CZ2VqjnV.mjs.map +1 -0
- package/dist/zod.d.mts +2 -2
- package/dist/zod.d.mts.map +1 -1
- package/dist/zod.mjs +2 -2
- package/dist/zod.mjs.map +1 -1
- package/package.json +15 -12
- package/src/cli/completions.ts +14 -11
- package/src/cli/docs.ts +13 -10
- package/src/cli/doctor.ts +22 -18
- package/src/cli/index.ts +28 -82
- package/src/cli/init.ts +10 -7
- package/src/cli/link.ts +20 -16
- package/src/cli/wrap.ts +14 -11
- package/src/codegen/schema-to-code.ts +2 -2
- package/src/{args.ts → core/args.ts} +32 -225
- package/src/core/commands.ts +373 -0
- package/src/core/create.ts +268 -0
- package/src/core/default-runtime.ts +239 -0
- package/src/{errors.ts → core/errors.ts} +22 -0
- package/src/core/exec.ts +259 -0
- package/src/core/interceptors.ts +302 -0
- package/src/{parse.ts → core/parse.ts} +36 -89
- package/src/core/program-methods.ts +301 -0
- package/src/core/results.ts +229 -0
- package/src/core/runtime.ts +246 -0
- package/src/core/validate.ts +247 -0
- package/src/docs/index.ts +12 -13
- package/src/extension/auto-output.ts +95 -0
- package/src/extension/color.ts +38 -0
- package/src/extension/completion.ts +49 -0
- package/src/extension/config.ts +262 -0
- package/src/extension/env.ts +101 -0
- package/src/extension/help.ts +192 -0
- package/src/extension/index.ts +43 -0
- package/src/extension/ink.ts +93 -0
- package/src/extension/interactive.ts +106 -0
- package/src/extension/logger.ts +214 -0
- package/src/extension/man.ts +51 -0
- package/src/extension/mcp.ts +52 -0
- package/src/extension/progress-renderer.ts +338 -0
- package/src/extension/progress.ts +299 -0
- package/src/extension/repl.ts +94 -0
- package/src/extension/serve.ts +48 -0
- package/src/extension/signal.ts +87 -0
- package/src/extension/stdin.ts +62 -0
- package/src/extension/suggestions.ts +114 -0
- package/src/extension/timing.ts +81 -0
- package/src/extension/tracing.ts +175 -0
- package/src/extension/update-check.ts +77 -0
- package/src/extension/utils.ts +51 -0
- package/src/extension/version.ts +63 -0
- package/src/{completion.ts → feature/completion.ts} +12 -12
- package/src/{interactive.ts → feature/interactive.ts} +4 -4
- package/src/{mcp.ts → feature/mcp.ts} +12 -15
- package/src/{repl-loop.ts → feature/repl-loop.ts} +10 -13
- package/src/{serve.ts → feature/serve.ts} +11 -15
- package/src/feature/test.ts +262 -0
- package/src/{update-check.ts → feature/update-check.ts} +16 -16
- package/src/{wrap.ts → feature/wrap.ts} +10 -8
- package/src/index.ts +111 -30
- package/src/{formatter.ts → output/formatter.ts} +131 -31
- package/src/{help.ts → output/help.ts} +22 -8
- package/src/{zod.d.ts → schema/zod.d.ts} +1 -1
- package/src/schema/zod.ts +50 -0
- package/src/test.ts +2 -276
- package/src/types/args-meta.ts +151 -0
- package/src/types/builder.ts +697 -0
- package/src/types/command.ts +157 -0
- package/src/types/index.ts +59 -0
- package/src/types/interceptor.ts +296 -0
- package/src/types/preferences.ts +83 -0
- package/src/types/result.ts +71 -0
- package/src/types/schema.ts +19 -0
- package/src/util/dotenv.ts +244 -0
- package/src/{shell-utils.ts → util/shell-utils.ts} +26 -9
- package/src/{stream.ts → util/stream.ts} +27 -1
- package/src/{type-helpers.ts → util/type-helpers.ts} +23 -16
- package/src/{type-utils.ts → util/type-utils.ts} +71 -33
- package/src/util/utils.ts +51 -0
- package/src/zod.ts +1 -50
- package/dist/args-D5PNDyNu.mjs.map +0 -1
- package/dist/chunk-CjcI7cDX.mjs +0 -15
- package/dist/command-utils-B1D-HqCd.mjs +0 -1117
- package/dist/command-utils-B1D-HqCd.mjs.map +0 -1
- package/dist/completion.d.mts +0 -64
- package/dist/completion.d.mts.map +0 -1
- package/dist/completion.mjs.map +0 -1
- package/dist/errors-BiVrBgi6.mjs.map +0 -1
- package/dist/formatter-DtHzbP22.d.mts.map +0 -1
- package/dist/help-bbmu9-qd.mjs.map +0 -1
- package/dist/mcp-mLWIdUIu.mjs.map +0 -1
- package/dist/serve-B0u43DK7.mjs.map +0 -1
- package/dist/stream-BcC146Ud.mjs.map +0 -1
- package/dist/types-Ch8Mk6Qb.d.mts.map +0 -1
- package/dist/update-check-CFX1FV3v.mjs.map +0 -1
- package/src/command-utils.ts +0 -882
- package/src/create.ts +0 -1829
- package/src/runtime.ts +0 -497
- package/src/types.ts +0 -1291
- package/src/utils.ts +0 -140
- /package/src/{colorizer.ts → output/colorizer.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as ColorConfig, n as HelpFormat, o as ColorTheme, t as HelpDetail } from "./formatter-
|
|
1
|
+
import { a as ColorConfig, n as HelpFormat, o as ColorTheme, t as HelpDetail } from "./formatter-DrvhDMrq.mjs";
|
|
2
2
|
import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
import { Tool } from "ai";
|
|
4
4
|
|
|
5
|
-
//#region src/args.d.ts
|
|
5
|
+
//#region src/types/args-meta.d.ts
|
|
6
6
|
type Letter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
|
|
7
7
|
/** A single letter character, valid as a short CLI flag (e.g. `'v'`, `'n'`, `'V'`). */
|
|
8
8
|
type SingleChar = Letter | Uppercase<Letter>;
|
|
@@ -119,37 +119,36 @@ interface PadroneArgsSchemaMeta<TObj = Record<string, any>> {
|
|
|
119
119
|
optionalInteractive?: true | readonly (keyof TObj & string)[];
|
|
120
120
|
}
|
|
121
121
|
//#endregion
|
|
122
|
-
//#region src/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
type PadroneMcpPreferences = {
|
|
132
|
-
/** Server name. Defaults to the program name. */name?: string; /** Server version. Defaults to the program version. */
|
|
133
|
-
version?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Transport mode.
|
|
136
|
-
* - `'http'` — Start a Streamable HTTP server (default). Responds with `application/json` or `text/event-stream` based on the client's `Accept` header. Use `port` and `host` to configure.
|
|
137
|
-
* - `'stdio'` — Communicate over stdin/stdout with newline-delimited JSON.
|
|
138
|
-
*/
|
|
139
|
-
transport?: 'http' | 'stdio'; /** HTTP port. Defaults to `3000`. Only used with `transport: 'http'`. */
|
|
140
|
-
port?: number; /** HTTP host. Defaults to `'127.0.0.1'`. Only used with `transport: 'http'`. */
|
|
141
|
-
host?: string; /** Base path for the MCP endpoint. Defaults to `'/mcp'`. Only used with `transport: 'http'`. */
|
|
142
|
-
basePath?: string; /** CORS allowed origin. Defaults to `'*'`. Set to a specific origin or `false` to disable CORS headers. Only used with HTTP transports. */
|
|
143
|
-
cors?: string | false;
|
|
122
|
+
//#region src/core/runtime.d.ts
|
|
123
|
+
/** Process signals that Padrone can handle for graceful shutdown. */
|
|
124
|
+
type PadroneSignal = 'SIGINT' | 'SIGTERM' | 'SIGHUP';
|
|
125
|
+
/** Value accepted by `PadroneProgressIndicator.update()`. */
|
|
126
|
+
type PadroneProgressUpdate = string | number | {
|
|
127
|
+
message?: string;
|
|
128
|
+
progress?: number;
|
|
129
|
+
indeterminate?: boolean;
|
|
130
|
+
time?: boolean;
|
|
144
131
|
};
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/runtime.d.ts
|
|
147
132
|
/**
|
|
148
133
|
* A progress indicator instance (spinner, progress bar, etc).
|
|
149
134
|
* Created by the runtime's `progress` factory and used to show loading state during command execution.
|
|
150
135
|
*/
|
|
151
136
|
type PadroneProgressIndicator = {
|
|
152
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Update the indicator.
|
|
139
|
+
* - `string` — update the displayed message.
|
|
140
|
+
* - `number` — set progress ratio (0–1). Values outside this range are clamped.
|
|
141
|
+
* - `{ message?, progress?, indeterminate? }` — update message, progress, or both.
|
|
142
|
+
*
|
|
143
|
+
* Set `indeterminate: true` to force the bar into indeterminate mode (shows animation, no percentage).
|
|
144
|
+
* This makes the bar visible even in `show: 'auto'` mode without providing a number.
|
|
145
|
+
* Omitting `progress` (or passing a string) leaves the bar in its current state.
|
|
146
|
+
* Setting `progress` when bar mode is not enabled is a no-op for the bar portion.
|
|
147
|
+
*
|
|
148
|
+
* Set `time: true` to start the elapsed timer on demand (useful when `time` was not set in options).
|
|
149
|
+
* Set `time: false` to hide the elapsed timer.
|
|
150
|
+
*/
|
|
151
|
+
update: (value: PadroneProgressUpdate) => void; /** Mark as succeeded and stop. Pass `null` to stop without rendering a final message. */
|
|
153
152
|
succeed: (message?: string | null, options?: {
|
|
154
153
|
indicator?: string;
|
|
155
154
|
}) => void; /** Mark as failed and stop. Pass `null` to stop without rendering a final message. */
|
|
@@ -160,23 +159,57 @@ type PadroneProgressIndicator = {
|
|
|
160
159
|
pause: () => void; /** Redraw the indicator after a `pause()`. */
|
|
161
160
|
resume: () => void;
|
|
162
161
|
};
|
|
162
|
+
/** Controls when a progress element (spinner or bar) is visible. */
|
|
163
|
+
type PadroneProgressShow = 'auto' | 'always' | 'never';
|
|
163
164
|
/** Built-in spinner presets. */
|
|
164
165
|
type PadroneSpinnerPreset = 'dots' | 'line' | 'arc' | 'bounce';
|
|
165
166
|
/**
|
|
166
167
|
* Spinner configuration for progress indicators.
|
|
167
168
|
* - A preset name (e.g., `'dots'`) to use built-in frames.
|
|
168
|
-
* -
|
|
169
|
-
* -
|
|
169
|
+
* - `true` — default spinner with `show: 'always'` (visible even alongside a bar).
|
|
170
|
+
* - An object with custom `frames`, `interval`, and/or `show`.
|
|
171
|
+
* - `false` to disable the spinner (`show: 'never'`).
|
|
172
|
+
*
|
|
173
|
+
* Default `show` is `'auto'`: visible when the bar is not shown.
|
|
170
174
|
*/
|
|
171
|
-
type PadroneSpinnerConfig = PadroneSpinnerPreset | {
|
|
175
|
+
type PadroneSpinnerConfig = PadroneSpinnerPreset | boolean | {
|
|
172
176
|
frames?: string[];
|
|
173
177
|
interval?: number;
|
|
174
|
-
|
|
178
|
+
show?: PadroneProgressShow;
|
|
179
|
+
};
|
|
175
180
|
/**
|
|
176
181
|
* Options passed to the runtime's `progress` factory.
|
|
177
182
|
*/
|
|
183
|
+
/** Common fill/empty character pairs for progress bars. */
|
|
184
|
+
type PadroneBarChar = '█' | '░' | '▓' | '▒' | '─' | '━' | '■' | '□' | '#' | '-' | '=' | '·' | '▰' | '▱' | (string & {});
|
|
185
|
+
/**
|
|
186
|
+
* Built-in indeterminate bar animation presets.
|
|
187
|
+
* - `'bounce'` — a filled segment slides back and forth (default).
|
|
188
|
+
* - `'slide'` — a filled segment slides left-to-right and wraps around.
|
|
189
|
+
* - `'pulse'` — the entire bar fades in and out using gradient characters (`░▒▓█▓▒░`).
|
|
190
|
+
*/
|
|
191
|
+
type PadroneBarAnimation = 'bounce' | 'slide' | 'pulse';
|
|
192
|
+
/**
|
|
193
|
+
* Progress bar configuration.
|
|
194
|
+
*/
|
|
195
|
+
type PadroneBarConfig = {
|
|
196
|
+
/** Total width of the bar in characters. Defaults to `20`. */width?: number; /** Character used for the filled portion of the bar. Defaults to `'█'`. */
|
|
197
|
+
filled?: PadroneBarChar; /** Character used for the empty portion of the bar. Defaults to `'░'`. */
|
|
198
|
+
empty?: PadroneBarChar; /** Indeterminate animation style. Defaults to `'bounce'`. */
|
|
199
|
+
animation?: PadroneBarAnimation;
|
|
200
|
+
/**
|
|
201
|
+
* When the bar is visible. Defaults to `'always'` when bar is enabled, `'auto'` when bar is not explicitly configured.
|
|
202
|
+
* - `'always'` — bar is always shown (indeterminate until a number is provided).
|
|
203
|
+
* - `'auto'` — bar is shown only after `update()` is called with a number.
|
|
204
|
+
* - `'never'` — bar is never shown.
|
|
205
|
+
*/
|
|
206
|
+
show?: PadroneProgressShow;
|
|
207
|
+
};
|
|
178
208
|
type PadroneProgressOptions = {
|
|
179
|
-
spinner?: PadroneSpinnerConfig; /**
|
|
209
|
+
spinner?: PadroneSpinnerConfig; /** Enable a progress bar. `true` for defaults (`show: 'always'`), or a `PadroneBarConfig` object. `false` to disable entirely. When omitted, bar defaults to `show: 'auto'` (appears when a number is provided). */
|
|
210
|
+
bar?: boolean | PadroneBarConfig; /** Show elapsed time since the indicator started. Defaults to `false`. */
|
|
211
|
+
time?: boolean; /** Show estimated time remaining based on progress rate. Requires numeric `update()` calls. Defaults to `false`. */
|
|
212
|
+
eta?: boolean; /** Character/string shown before the success message. Defaults to `'✔'`. */
|
|
180
213
|
successIndicator?: string; /** Character/string shown before the error message. Defaults to `'✖'`. */
|
|
181
214
|
errorIndicator?: string;
|
|
182
215
|
};
|
|
@@ -215,9 +248,7 @@ type PadroneRuntime = {
|
|
|
215
248
|
argv?: () => string[]; /** Return environment variables (replaces process.env). */
|
|
216
249
|
env?: () => Record<string, string | undefined>; /** Default help output format. */
|
|
217
250
|
format?: HelpFormat | 'auto'; /** Color theme for ANSI/console help output. A theme name or partial color config. */
|
|
218
|
-
theme?: ColorTheme | ColorConfig;
|
|
219
|
-
loadConfigFile?: (path: string) => Record<string, unknown> | undefined; /** Find the first existing file from a list of candidate names. */
|
|
220
|
-
findFile?: (names: string[]) => string | undefined;
|
|
251
|
+
theme?: ColorTheme | ColorConfig;
|
|
221
252
|
/**
|
|
222
253
|
* Standard input abstraction. Provides methods to read piped data from stdin.
|
|
223
254
|
* When not provided, defaults to reading from `process.stdin`.
|
|
@@ -247,12 +278,6 @@ type PadroneRuntime = {
|
|
|
247
278
|
* When `interactive` is `true` and this is not provided, defaults to an Enquirer-based terminal prompt.
|
|
248
279
|
*/
|
|
249
280
|
prompt?: (config: InteractivePromptConfig) => Promise<unknown>;
|
|
250
|
-
/**
|
|
251
|
-
* Create a progress indicator (spinner, progress bar, etc).
|
|
252
|
-
* Used by commands that set `progress` in their config, or manually via `ctx.progress()` in actions.
|
|
253
|
-
* When not provided, auto-progress is silently skipped and `ctx.progress()` returns a no-op indicator.
|
|
254
|
-
*/
|
|
255
|
-
progress?: (message: string, options?: PadroneProgressOptions) => PadroneProgressIndicator;
|
|
256
281
|
/**
|
|
257
282
|
* Read a line of input from the user. Used by `repl()` for custom runtimes
|
|
258
283
|
* (web UIs, chat interfaces, testing).
|
|
@@ -263,24 +288,57 @@ type PadroneRuntime = {
|
|
|
263
288
|
* with command history (up/down arrows) and tab completion.
|
|
264
289
|
*/
|
|
265
290
|
readLine?: (prompt: string) => Promise<string | typeof REPL_SIGINT | null>;
|
|
291
|
+
/**
|
|
292
|
+
* Register a callback for process signals. Returns an unsubscribe function.
|
|
293
|
+
* The default runtime wires this to `process.on('SIGINT' | 'SIGTERM' | 'SIGHUP')`.
|
|
294
|
+
* Non-Node runtimes (web UIs, tests) can map their own cancellation semantics.
|
|
295
|
+
*
|
|
296
|
+
* When not provided, signal handling is disabled for this runtime.
|
|
297
|
+
*/
|
|
298
|
+
onSignal?: (callback: (signal: PadroneSignal) => void) => () => void;
|
|
299
|
+
/**
|
|
300
|
+
* Terminal/output capabilities. Used for ANSI detection, text wrapping, and TTY checks.
|
|
301
|
+
* The default runtime auto-detects from `process.stdout`. Non-terminal runtimes
|
|
302
|
+
* (web UIs, tests) should provide explicit values.
|
|
303
|
+
*/
|
|
304
|
+
terminal?: {
|
|
305
|
+
/** Number of columns in the terminal. Used for text wrapping. */columns?: number; /** Whether stdout is a TTY. Affects ANSI color output and interactive features. */
|
|
306
|
+
isTTY?: boolean;
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Force-exit the process. The default runtime wires this to `process.exit()`.
|
|
310
|
+
* Non-Node runtimes can throw an error or no-op.
|
|
311
|
+
*/
|
|
312
|
+
exit?: (code: number) => never;
|
|
266
313
|
};
|
|
267
314
|
/**
|
|
268
315
|
* Internal resolved runtime where all fields are guaranteed to be present.
|
|
269
316
|
* The `prompt`, `interactive`, and `readLine` fields remain optional since not all runtimes provide them.
|
|
270
317
|
*/
|
|
271
|
-
type ResolvedPadroneRuntime = Required<Omit<PadroneRuntime, 'prompt' | 'interactive' | 'readLine' | 'stdin' | '
|
|
272
|
-
/**
|
|
273
|
-
* Creates a persistent Node.js readline session for the REPL.
|
|
274
|
-
* Enables up/down arrow history navigation and tab completion.
|
|
275
|
-
* Used internally by `repl()` when no custom `readLine` is provided.
|
|
276
|
-
*/
|
|
318
|
+
type ResolvedPadroneRuntime = Required<Omit<PadroneRuntime, 'prompt' | 'interactive' | 'readLine' | 'stdin' | 'theme' | 'onSignal' | 'terminal' | 'exit'>> & Pick<PadroneRuntime, 'prompt' | 'interactive' | 'readLine' | 'stdin' | 'theme' | 'onSignal' | 'terminal' | 'exit'>;
|
|
277
319
|
/**
|
|
278
320
|
* Sentinel value returned by the terminal REPL session when Ctrl+C is pressed.
|
|
279
321
|
* Distinguished from empty string (user pressed enter) and null (EOF/Ctrl+D).
|
|
280
322
|
*/
|
|
281
323
|
declare const REPL_SIGINT: unique symbol;
|
|
282
324
|
//#endregion
|
|
283
|
-
//#region src/
|
|
325
|
+
//#region src/feature/mcp.d.ts
|
|
326
|
+
type PadroneMcpPreferences = {
|
|
327
|
+
/** Server name. Defaults to the program name. */name?: string; /** Server version. Defaults to the program version. */
|
|
328
|
+
version?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Transport mode.
|
|
331
|
+
* - `'http'` — Start a Streamable HTTP server (default). Responds with `application/json` or `text/event-stream` based on the client's `Accept` header. Use `port` and `host` to configure.
|
|
332
|
+
* - `'stdio'` — Communicate over stdin/stdout with newline-delimited JSON.
|
|
333
|
+
*/
|
|
334
|
+
transport?: 'http' | 'stdio'; /** HTTP port. Defaults to `3000`. Only used with `transport: 'http'`. */
|
|
335
|
+
port?: number; /** HTTP host. Defaults to `'127.0.0.1'`. Only used with `transport: 'http'`. */
|
|
336
|
+
host?: string; /** Base path for the MCP endpoint. Defaults to `'/mcp'`. Only used with `transport: 'http'`. */
|
|
337
|
+
basePath?: string; /** CORS allowed origin. Defaults to `'*'`. Set to a specific origin or `false` to disable CORS headers. Only used with HTTP transports. */
|
|
338
|
+
cors?: string | false;
|
|
339
|
+
};
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/feature/serve.d.ts
|
|
284
342
|
type PadroneServePreferences = {
|
|
285
343
|
/** Port to listen on. Default: 3000 */port?: number; /** Host to bind to. Default: '127.0.0.1' */
|
|
286
344
|
host?: string; /** Base path prefix for all routes. Default: '/' */
|
|
@@ -296,7 +354,94 @@ type PadroneServePreferences = {
|
|
|
296
354
|
onError?: (error: unknown, req: Request) => Response;
|
|
297
355
|
};
|
|
298
356
|
//#endregion
|
|
299
|
-
//#region src/
|
|
357
|
+
//#region src/feature/wrap.d.ts
|
|
358
|
+
/**
|
|
359
|
+
* Configuration for wrapping an external CLI tool.
|
|
360
|
+
*/
|
|
361
|
+
type WrapConfig<TCommandArgs extends PadroneSchema = PadroneSchema, TWrapArgs extends PadroneSchema = TCommandArgs> = {
|
|
362
|
+
/**
|
|
363
|
+
* The command to execute (e.g., 'git', 'docker', 'npm').
|
|
364
|
+
*/
|
|
365
|
+
command: string;
|
|
366
|
+
/**
|
|
367
|
+
* Optional fixed arguments that always precede the arguments (e.g., ['commit'] for 'git commit').
|
|
368
|
+
*/
|
|
369
|
+
args?: string[];
|
|
370
|
+
/**
|
|
371
|
+
* Positional argument configuration for the external command.
|
|
372
|
+
* If not provided, defaults to the wrapping command's positional configuration.
|
|
373
|
+
*/
|
|
374
|
+
positional?: string[];
|
|
375
|
+
/**
|
|
376
|
+
* Whether to inherit stdio streams (stdin, stdout, stderr) from the parent process.
|
|
377
|
+
* Default: true
|
|
378
|
+
*/
|
|
379
|
+
inheritStdio?: boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Optional schema that transforms command arguments to external CLI arguments.
|
|
382
|
+
* The schema's input type should match the command arguments, and its output type defines
|
|
383
|
+
* the arguments expected by the external command.
|
|
384
|
+
* If not provided, command arguments are passed through as-is.
|
|
385
|
+
*/
|
|
386
|
+
schema?: TWrapArgs | ((commandArguments: TCommandArgs) => TWrapArgs);
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Result from executing a wrapped CLI tool.
|
|
390
|
+
*/
|
|
391
|
+
type WrapResult = {
|
|
392
|
+
/**
|
|
393
|
+
* The exit code of the process.
|
|
394
|
+
*/
|
|
395
|
+
exitCode: number;
|
|
396
|
+
/**
|
|
397
|
+
* Standard output from the process (only if inheritStdio is false).
|
|
398
|
+
*/
|
|
399
|
+
stdout?: string;
|
|
400
|
+
/**
|
|
401
|
+
* Standard error from the process (only if inheritStdio is false).
|
|
402
|
+
*/
|
|
403
|
+
stderr?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Whether the process exited successfully (exit code 0).
|
|
406
|
+
*/
|
|
407
|
+
success: boolean;
|
|
408
|
+
};
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/output/help.d.ts
|
|
411
|
+
type HelpPreferences = {
|
|
412
|
+
format?: HelpFormat | 'auto';
|
|
413
|
+
detail?: HelpDetail;
|
|
414
|
+
theme?: ColorTheme | ColorConfig; /** Show all global commands and flags in full detail */
|
|
415
|
+
all?: boolean; /** Terminal width for text wrapping. Defaults to terminal columns or 80. */
|
|
416
|
+
width?: number; /** Terminal capabilities for auto-detection of ANSI and width. */
|
|
417
|
+
terminal?: {
|
|
418
|
+
columns?: number;
|
|
419
|
+
isTTY?: boolean;
|
|
420
|
+
}; /** Environment variables for auto-detection (e.g., NO_COLOR, CI). */
|
|
421
|
+
env?: Record<string, string | undefined>;
|
|
422
|
+
};
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/types/schema.d.ts
|
|
425
|
+
/**
|
|
426
|
+
* A schema that supports both validation (StandardSchemaV1) and JSON schema generation (StandardJSONSchemaV1).
|
|
427
|
+
* This is the type required for command arguments in Padrone.
|
|
428
|
+
*/
|
|
429
|
+
type PadroneSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
|
|
430
|
+
/**
|
|
431
|
+
* A schema branded as async. When passed to `.arguments()`, `.configFile()`, or `.env()`,
|
|
432
|
+
* the command is automatically marked as async, causing `parse()` and `cli()` to return Promises.
|
|
433
|
+
*
|
|
434
|
+
* Use the `asyncSchema()` helper to brand an existing schema:
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { asyncSchema } from 'padrone';
|
|
437
|
+
* const schema = asyncSchema(z.object({ name: z.string() }).check(async (v) => { ... }));
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
type AsyncPadroneSchema<Input = unknown, Output = Input> = PadroneSchema<Input, Output> & {
|
|
441
|
+
'~async': true;
|
|
442
|
+
};
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/util/type-utils.d.ts
|
|
300
445
|
type SafeString = string & {};
|
|
301
446
|
type IsUnknown<T> = unknown extends T ? true : false;
|
|
302
447
|
type IsAny<T> = any extends T ? true : false;
|
|
@@ -371,17 +516,61 @@ type GetCommandPathsAndAliases<TCommand extends AnyPadroneCommand> = TCommand['~
|
|
|
371
516
|
/**
|
|
372
517
|
* Find a direct child command in a tuple by name.
|
|
373
518
|
* Unlike PickCommandByName, this does NOT flatten — it only checks direct children by their `name` field.
|
|
519
|
+
* Uses indexed access (O(1) depth) instead of recursive tuple walking.
|
|
374
520
|
*/
|
|
375
|
-
type FindDirectChild<TCommands extends AnyPadroneCommand[], TName extends string> = TCommands
|
|
521
|
+
type FindDirectChild<TCommands extends AnyPadroneCommand[], TName extends string> = Extract<TCommands[number], {
|
|
522
|
+
'~types': {
|
|
523
|
+
name: TName;
|
|
524
|
+
};
|
|
525
|
+
}>;
|
|
376
526
|
/**
|
|
377
527
|
* Replace a command in a tuple by name, or append if not found.
|
|
378
528
|
* Used by `.command()` override semantics: re-registering a name replaces that entry.
|
|
529
|
+
* Uses mapped type (O(1) depth) instead of recursive tuple walking.
|
|
379
530
|
*/
|
|
380
531
|
type ReplaceOrAppendCommand<TCommands extends [...AnyPadroneCommand[]], TName extends string, TNew extends AnyPadroneCommand> = HasDirectChild<TCommands, TName> extends true ? ReplaceInTuple<TCommands, TName, TNew> : [...TCommands, TNew];
|
|
381
|
-
type HasDirectChild<TCommands extends AnyPadroneCommand[], TName extends string> =
|
|
382
|
-
type ReplaceInTuple<TCommands extends AnyPadroneCommand[], TName extends string, TNew extends AnyPadroneCommand> =
|
|
532
|
+
type HasDirectChild<TCommands extends AnyPadroneCommand[], TName extends string> = TName extends TCommands[number]['~types']['name'] ? true : false;
|
|
533
|
+
type ReplaceInTuple<TCommands extends AnyPadroneCommand[], TName extends string, TNew extends AnyPadroneCommand> = { [K in keyof TCommands]: TCommands[K] extends AnyPadroneCommand ? TCommands[K]['~types']['name'] extends TName ? TNew : TCommands[K] : TCommands[K] };
|
|
534
|
+
/**
|
|
535
|
+
* Utility type for extensions that add a command to a builder/program.
|
|
536
|
+
* Replaces the boilerplate `With*<T>` pattern used across all extension files.
|
|
537
|
+
*/
|
|
538
|
+
type WithCommand<T, TName extends string, TCmd extends AnyPadroneCommand> = T extends {
|
|
539
|
+
'~types': {
|
|
540
|
+
programName: infer PN extends string;
|
|
541
|
+
name: infer N extends string;
|
|
542
|
+
parentName: infer PaN extends string;
|
|
543
|
+
argsSchema: infer A extends PadroneSchema;
|
|
544
|
+
result: infer R;
|
|
545
|
+
commands: infer C extends [...AnyPadroneCommand[]];
|
|
546
|
+
async: infer AS extends boolean;
|
|
547
|
+
context: infer CTX;
|
|
548
|
+
contextProvided: infer CTXP;
|
|
549
|
+
};
|
|
550
|
+
} ? T extends {
|
|
551
|
+
run: any;
|
|
552
|
+
} ? PadroneProgram<PN, N, PaN, A, R, ReplaceOrAppendCommand<C, TName, TCmd>, any, AS, CTX, CTXP> : PadroneBuilder<PN, N, PaN, A, R, ReplaceOrAppendCommand<C, TName, TCmd>, any, AS, CTX, CTXP> : T;
|
|
553
|
+
/**
|
|
554
|
+
* Utility type for extensions that register a context-providing interceptor.
|
|
555
|
+
* Extends `TContextProvided` with `TProvides` while preserving all other builder/program type params.
|
|
556
|
+
*/
|
|
557
|
+
type WithInterceptor<T, TProvides> = T extends {
|
|
558
|
+
'~types': {
|
|
559
|
+
programName: infer PN extends string;
|
|
560
|
+
name: infer N extends string;
|
|
561
|
+
parentName: infer PaN extends string;
|
|
562
|
+
argsSchema: infer A extends PadroneSchema;
|
|
563
|
+
result: infer R;
|
|
564
|
+
commands: infer C extends [...AnyPadroneCommand[]];
|
|
565
|
+
async: infer AS extends boolean;
|
|
566
|
+
context: infer CTX;
|
|
567
|
+
contextProvided: infer CTXP;
|
|
568
|
+
};
|
|
569
|
+
} ? T extends {
|
|
570
|
+
run: any;
|
|
571
|
+
} ? PadroneProgram<PN, N, PaN, A, R, C, any, AS, CTX, CTXP & TProvides> : PadroneBuilder<PN, N, PaN, A, R, C, any, AS, CTX, CTXP & TProvides> : T;
|
|
383
572
|
type PickCommandByName<TCommands extends AnyPadroneCommand[], TName extends string | AnyPadroneCommand> = TName extends AnyPadroneCommand ? TName : FlattenCommands<TCommands> extends infer Cmd extends AnyPadroneCommand ? Cmd extends AnyPadroneCommand ? TName extends GetCommandPathsAndAliases<Cmd> ? Cmd : never : never : never;
|
|
384
|
-
type FlattenCommands<TCommands extends AnyPadroneCommand[]> = TCommands extends [] ? never :
|
|
573
|
+
type FlattenCommands<TCommands extends AnyPadroneCommand[]> = TCommands extends [] ? never : number extends TCommands['length'] ? IsAny<TCommands[number]> extends true ? never : TCommands[number] : TCommands[number] extends infer Cmd extends AnyPadroneCommand ? Cmd | FlattenCommands<Cmd['~types']['commands']> : never;
|
|
385
574
|
/**
|
|
386
575
|
* Get all command paths including alias paths for all commands.
|
|
387
576
|
*/
|
|
@@ -411,159 +600,273 @@ type CommandIsUnknownable<TCommand> = IsGeneric<TCommand> extends true ? true :
|
|
|
411
600
|
* Used by `mount()` to update all nested command paths when a program is mounted as a subcommand.
|
|
412
601
|
*/
|
|
413
602
|
type RepathCommands<TCommands extends [...AnyPadroneCommand[]], TNewParentPath extends string> = TCommands extends [infer First extends AnyPadroneCommand, ...infer Rest extends AnyPadroneCommand[]] ? [RepathCommand<First, TNewParentPath>, ...RepathCommands<Rest, TNewParentPath>] : [];
|
|
414
|
-
type RepathCommand<TCommand extends AnyPadroneCommand, TNewParentName extends string> = PadroneCommand<TCommand['~types']['name'], TNewParentName, TCommand['~types']['argsSchema'], TCommand['~types']['result'], RepathCommands<TCommand['~types']['commands'], FullCommandName<TCommand['~types']['name'], TNewParentName>>, TCommand['~types']['aliases'], TCommand['~types']['
|
|
603
|
+
type RepathCommand<TCommand extends AnyPadroneCommand, TNewParentName extends string> = PadroneCommand<TCommand['~types']['name'], TNewParentName, TCommand['~types']['argsSchema'], TCommand['~types']['result'], RepathCommands<TCommand['~types']['commands'], FullCommandName<TCommand['~types']['name'], TNewParentName>>, TCommand['~types']['aliases'], TCommand['~types']['async'], TCommand['~types']['context'], TCommand['~types']['contextProvided']>;
|
|
415
604
|
type PickCommandByPossibleCommands<TCommands extends AnyPadroneCommand[], TCommand extends PossibleCommands<TCommands, true, true> | SafeString> = CommandIsUnknownable<TCommand> extends true ? FlattenCommands<TCommands> : TCommand extends AnyPadroneCommand ? TCommand : TCommand extends string ? TCommand extends GetCommandPathsOrAliases<TCommands> ? PickCommandByName<TCommands, TCommand> : SplitLastSpace<TCommand> extends [infer Prefix extends string, infer Rest] ? IsNever<Rest> extends true ? PickCommandByName<TCommands, Prefix> : PickCommandByPossibleCommands<TCommands, Prefix> : never : never;
|
|
416
605
|
//#endregion
|
|
417
|
-
//#region src/
|
|
606
|
+
//#region src/types/interceptor.d.ts
|
|
607
|
+
/** Base context shared across all interceptor phases within a single execution. */
|
|
608
|
+
type InterceptorBaseContext<TContext = unknown> = {
|
|
609
|
+
/** The resolved command for this execution. In the parse phase, this is the root program. */command: AnyPadroneCommand; /** The raw CLI input string (undefined when invoked without input). */
|
|
610
|
+
input: string | undefined; /** Cancellation signal that fires when the process receives a termination signal. */
|
|
611
|
+
signal: AbortSignal; /** User-defined context object, resolved through the command's parent chain. */
|
|
612
|
+
context: TContext; /** The resolved runtime for this execution. Interceptors can override this before calling `next()`. */
|
|
613
|
+
runtime: ResolvedPadroneRuntime; /** The program instance. Available for extensions that need program-level methods. */
|
|
614
|
+
program: AnyPadroneProgram; /** The invocation method that triggered this execution (e.g. 'cli', 'eval', 'run'). */
|
|
615
|
+
caller: PadroneActionContext['caller'];
|
|
616
|
+
};
|
|
617
|
+
/** Context for the parse phase. */
|
|
618
|
+
type InterceptorParseContext<TContext = unknown> = InterceptorBaseContext<TContext>;
|
|
619
|
+
/** Result returned by the parse phase's `next()`. */
|
|
620
|
+
type InterceptorParseResult = {
|
|
621
|
+
command: AnyPadroneCommand;
|
|
622
|
+
rawArgs: Record<string, unknown>;
|
|
623
|
+
positionalArgs: string[];
|
|
624
|
+
};
|
|
625
|
+
/** Context for the validate phase. */
|
|
626
|
+
type InterceptorValidateContext<TContext = unknown> = InterceptorBaseContext<TContext> & {
|
|
627
|
+
/** Raw named arguments extracted by the parser. Mutable — modify before `next()` to inject/override values. */rawArgs: Record<string, unknown>; /** Positional argument strings extracted by the parser. */
|
|
628
|
+
positionalArgs: string[]; /** Interactive mode override (set by the interactive extension when `--interactive` / `-i` flag is used). */
|
|
629
|
+
interactive?: boolean; /** Interactive mode preference from eval/cli options. Available for the interactive extension. */
|
|
630
|
+
evalInteractive?: boolean;
|
|
631
|
+
};
|
|
632
|
+
/** Result returned by the validate phase's `next()`. */
|
|
633
|
+
type InterceptorValidateResult<TArgs = unknown> = {
|
|
634
|
+
args: TArgs;
|
|
635
|
+
argsResult: StandardSchemaV1.Result<TArgs>;
|
|
636
|
+
};
|
|
637
|
+
/** Context for the execute phase. Includes validate context fields (rawArgs, positionalArgs). */
|
|
638
|
+
type InterceptorExecuteContext<TArgs = unknown, TContext = unknown> = InterceptorValidateContext<TContext> & {
|
|
639
|
+
/** Validated arguments that will be passed to the action. Mutable — modify before `next()` to override. */args: TArgs;
|
|
640
|
+
};
|
|
641
|
+
/** Result returned by the execute phase's `next()`. */
|
|
642
|
+
type InterceptorExecuteResult<TResult = unknown> = {
|
|
643
|
+
result: TResult;
|
|
644
|
+
};
|
|
645
|
+
/** Context for the start phase. Runs before parsing, wraps the entire pipeline. */
|
|
646
|
+
type InterceptorStartContext<TContext = unknown> = InterceptorBaseContext<TContext>;
|
|
647
|
+
/** Context for the error phase. Called when the pipeline throws. Includes pipeline state accumulated before the error. */
|
|
648
|
+
type InterceptorErrorContext<TContext = unknown> = InterceptorBaseContext<TContext> & {
|
|
649
|
+
/** The error that was thrown. */error: unknown; /** Raw named arguments (available if parse completed). */
|
|
650
|
+
rawArgs?: Record<string, unknown>; /** Positional argument strings (available if parse completed). */
|
|
651
|
+
positionalArgs?: string[]; /** Validated arguments (available if validate completed). */
|
|
652
|
+
args?: unknown;
|
|
653
|
+
};
|
|
654
|
+
/** Result returned by the error phase's `next()`. */
|
|
655
|
+
type InterceptorErrorResult<TResult = unknown> = {
|
|
656
|
+
/** The error (possibly transformed). Set to `undefined` to suppress the error. */error?: unknown; /** A replacement result when suppressing the error. */
|
|
657
|
+
result?: TResult;
|
|
658
|
+
};
|
|
659
|
+
/** Context for the shutdown phase. Always runs after the pipeline (success or failure). Includes pipeline state accumulated before completion. */
|
|
660
|
+
type InterceptorShutdownContext<TResult = unknown, TContext = unknown> = InterceptorBaseContext<TContext> & {
|
|
661
|
+
/** The error, if the pipeline failed (after error phase processing). */error?: unknown; /** The pipeline result, if it succeeded. */
|
|
662
|
+
result?: TResult; /** Raw named arguments (available if parse completed). */
|
|
663
|
+
rawArgs?: Record<string, unknown>; /** Positional argument strings (available if parse completed). */
|
|
664
|
+
positionalArgs?: string[]; /** Validated arguments (available if validate completed). */
|
|
665
|
+
args?: unknown;
|
|
666
|
+
};
|
|
667
|
+
/** Overrides passable to `next()`. Provides autocomplete for common fields; accepts any phase-specific fields. */
|
|
668
|
+
type InterceptorNextOverrides = Partial<InterceptorBaseContext> & Record<string, unknown>;
|
|
418
669
|
/**
|
|
419
|
-
*
|
|
670
|
+
* A phase handler function for the interceptor middleware chain.
|
|
671
|
+
*
|
|
672
|
+
* - `TCtx` — the context object available to the handler.
|
|
673
|
+
* - `TNextResult` — the typed result returned by `next()`, giving the handler type-safe access to downstream output.
|
|
674
|
+
* - `TReturn` — the type the handler itself returns. Defaults to `TNextResult` but can be wider,
|
|
675
|
+
* allowing interceptors to transform or replace the result (e.g., error-recovery interceptors returning a different type).
|
|
420
676
|
*/
|
|
421
|
-
type
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
packageName?: string;
|
|
677
|
+
type InterceptorPhaseHandler<TCtx, TNextResult, TReturn = TNextResult> = (ctx: TCtx, next: (overrides?: InterceptorNextOverrides) => TNextResult | Promise<TNextResult>) => TReturn | Promise<TReturn>;
|
|
678
|
+
/** Static metadata for an interceptor. Always available at registration time without calling the factory. */
|
|
679
|
+
type InterceptorMeta = {
|
|
680
|
+
/** Display name for this interceptor. Used for identification in logs and debugging. */name: string;
|
|
426
681
|
/**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
682
|
+
* Optional unique identifier for deduplication. When multiple interceptors share the same `id`,
|
|
683
|
+
* only the last one registered is kept. Useful for allowing downstream code to override
|
|
684
|
+
* an interceptor without accumulating duplicates.
|
|
430
685
|
*/
|
|
431
|
-
|
|
686
|
+
id?: string;
|
|
432
687
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
688
|
+
* Ordering hint. Lower values run as outer layers (earlier before `next()`, later after).
|
|
689
|
+
* Interceptors with the same order preserve registration order. Defaults to `0`.
|
|
435
690
|
*/
|
|
436
|
-
|
|
691
|
+
order?: number;
|
|
437
692
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
693
|
+
* When `true`, the interceptor is skipped during execution. Combined with `id`-based deduplication,
|
|
694
|
+
* this lets downstream code disable an interceptor by re-registering it with `disabled: true`.
|
|
440
695
|
*/
|
|
441
|
-
|
|
696
|
+
disabled?: boolean;
|
|
442
697
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
* Defaults to `'<PROGRAM_NAME>_NO_UPDATE_CHECK'` (uppercased, hyphens to underscores).
|
|
698
|
+
* When `false`, the interceptor applies only to the command it was registered on
|
|
699
|
+
* and is not inherited by subcommands. Defaults to `true`.
|
|
446
700
|
*/
|
|
447
|
-
|
|
701
|
+
inherit?: boolean;
|
|
448
702
|
};
|
|
449
|
-
//#endregion
|
|
450
|
-
//#region src/wrap.d.ts
|
|
451
703
|
/**
|
|
452
|
-
*
|
|
704
|
+
* Phase handler definitions returned by an interceptor factory.
|
|
705
|
+
* The factory's closure provides typed, scoped cross-phase state.
|
|
706
|
+
*
|
|
707
|
+
* Type parameters:
|
|
708
|
+
* - `TArgs` — the validated arguments type (output of the args schema).
|
|
709
|
+
* - `TResult` — the command's return type.
|
|
453
710
|
*/
|
|
454
|
-
type
|
|
455
|
-
/**
|
|
456
|
-
* The command to execute (e.g., 'git', 'docker', 'npm').
|
|
457
|
-
*/
|
|
458
|
-
command: string;
|
|
711
|
+
type InterceptorPhases<TArgs = unknown, TResult = unknown, TContext = unknown> = {
|
|
459
712
|
/**
|
|
460
|
-
*
|
|
461
|
-
|
|
462
|
-
args?: string[];
|
|
463
|
-
/**
|
|
464
|
-
* Positional argument configuration for the external command.
|
|
465
|
-
* If not provided, defaults to the wrapping command's positional configuration.
|
|
713
|
+
* Runs before the pipeline (parse → validate → execute). `next()` proceeds to the pipeline.
|
|
714
|
+
* Root interceptors only. Use for startup tasks like telemetry, update checks, or global config loading.
|
|
466
715
|
*/
|
|
467
|
-
|
|
716
|
+
start?: InterceptorPhaseHandler<InterceptorStartContext<TContext>, unknown>; /** Intercepts command routing and raw argument extraction. */
|
|
717
|
+
parse?: InterceptorPhaseHandler<InterceptorParseContext<TContext>, InterceptorParseResult>; /** Intercepts argument preprocessing and schema validation. Interactive prompting is handled by the interactive extension. */
|
|
718
|
+
validate?: InterceptorPhaseHandler<InterceptorValidateContext<TContext>, InterceptorValidateResult<TArgs>, InterceptorValidateResult>; /** Intercepts handler execution. */
|
|
719
|
+
execute?: InterceptorPhaseHandler<InterceptorExecuteContext<TArgs, TContext>, InterceptorExecuteResult<TResult>, InterceptorExecuteResult>;
|
|
468
720
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
721
|
+
* Called when the pipeline throws an error. `next()` passes to the next error handler
|
|
722
|
+
* (innermost returns `{ error }` unchanged). Return `{ result }` without `error` to suppress.
|
|
471
723
|
*/
|
|
472
|
-
|
|
724
|
+
error?: InterceptorPhaseHandler<InterceptorErrorContext<TContext>, InterceptorErrorResult<TResult>, InterceptorErrorResult>;
|
|
473
725
|
/**
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
* the arguments expected by the external command.
|
|
477
|
-
* If not provided, command arguments are passed through as-is.
|
|
726
|
+
* Always runs after the pipeline completes (success or failure). `next()` calls the next shutdown handler.
|
|
727
|
+
* Use for cleanup: closing connections, flushing logs, etc.
|
|
478
728
|
*/
|
|
479
|
-
|
|
729
|
+
shutdown?: InterceptorPhaseHandler<InterceptorShutdownContext<TResult, TContext>, void>;
|
|
480
730
|
};
|
|
481
731
|
/**
|
|
482
|
-
*
|
|
732
|
+
* Factory function that creates phase handlers for an interceptor.
|
|
733
|
+
* Called once per command execution — the closure provides typed, scoped cross-phase state across phases.
|
|
483
734
|
*/
|
|
484
|
-
type
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
*/
|
|
496
|
-
stderr?: string;
|
|
735
|
+
type InterceptorFactory<TArgs = unknown, TResult = unknown, TContext = unknown> = () => InterceptorPhases<TArgs, TResult, TContext>;
|
|
736
|
+
/**
|
|
737
|
+
* A self-contained interceptor value: a factory function with static metadata as own properties.
|
|
738
|
+
* Created via `defineInterceptor(meta, factory)`. This is the distributable form — a single
|
|
739
|
+
* importable value that packages can export.
|
|
740
|
+
*
|
|
741
|
+
* Also accepted directly by `.intercept()` as the single-argument form.
|
|
742
|
+
* Call `.provides<T>()` to brand it as a context-providing interceptor.
|
|
743
|
+
*/
|
|
744
|
+
type PadroneInterceptorFn<TArgs = unknown, TResult = unknown, TContext = unknown> = InterceptorFactory<TArgs, TResult, TContext> & InterceptorMeta & {
|
|
745
|
+
/** Brand this interceptor as providing additional context of type `TProvides`. No-op at runtime; purely a type-level cast. */provides: <TProvides>() => PadroneContextInterceptor<TProvides, TArgs, TResult, TContext>;
|
|
497
746
|
/**
|
|
498
|
-
*
|
|
747
|
+
* Brand this interceptor as requiring context of type `TRequires` to be available.
|
|
748
|
+
* `.intercept()` will produce a compile error if the required context is not satisfied.
|
|
749
|
+
* Use optional properties for soft requirements: `.requires<{ db: DB; logger?: Logger }>()`.
|
|
750
|
+
* No-op at runtime; purely a type-level cast.
|
|
499
751
|
*/
|
|
500
|
-
|
|
752
|
+
requires: <TRequires>() => PadroneInterceptorFn<TArgs, TResult, TContext> & InterceptorRequiresBrand<TRequires>;
|
|
753
|
+
};
|
|
754
|
+
/**
|
|
755
|
+
* A Padrone interceptor in its single-value distributable form.
|
|
756
|
+
* Alias for `PadroneInterceptorFn` — this is the primary public type.
|
|
757
|
+
*
|
|
758
|
+
* Create with `defineInterceptor(meta, factory)` or pass `(meta, factory)` directly to `.intercept()`.
|
|
759
|
+
*/
|
|
760
|
+
type PadroneInterceptor<TArgs = unknown, TResult = unknown, TContext = unknown> = PadroneInterceptorFn<TArgs, TResult, TContext>;
|
|
761
|
+
/**
|
|
762
|
+
* A context-providing interceptor. Carries a phantom `'~context'` brand declaring what it adds
|
|
763
|
+
* to the command context. When registered via `.intercept()`, the builder's context type is
|
|
764
|
+
* intersected with `TProvides`.
|
|
765
|
+
*
|
|
766
|
+
* Created by calling `.provides<T>()` on a `PadroneInterceptorFn`.
|
|
767
|
+
* Chain `.requires<T>()` to also declare context dependencies.
|
|
768
|
+
*/
|
|
769
|
+
type PadroneContextInterceptor<TProvides = unknown, TArgs = unknown, TResult = unknown, TContext = unknown> = Omit<PadroneInterceptorFn<TArgs, TResult, TContext>, 'requires'> & InterceptorFactory<TArgs, TResult, TContext> & {
|
|
770
|
+
/** Phantom brand — declares the context type this interceptor provides. */'~context': TProvides; /** Like `.requires()` on `PadroneInterceptorFn` but preserves the `'~context'` brand. */
|
|
771
|
+
requires: <TRequires>() => PadroneContextInterceptor<TProvides, TArgs, TResult, TContext> & InterceptorRequiresBrand<TRequires>;
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* Phantom brand for context requirements. Uses a contravariant function type so that
|
|
775
|
+
* `.intercept()` overloads can check `TAvailableContext extends TRequires` via assignability.
|
|
776
|
+
*/
|
|
777
|
+
type InterceptorRequiresBrand<TRequires> = {
|
|
778
|
+
'~contextRequires': (ctx: TRequires) => void;
|
|
779
|
+
};
|
|
780
|
+
/** Extracts the provided context type from a context-providing interceptor, or `unknown` if not branded. */
|
|
781
|
+
type ExtractInterceptorContext<T> = T extends {
|
|
782
|
+
'~context': infer C;
|
|
783
|
+
} ? C : unknown;
|
|
784
|
+
/** Extracts the required context type from an interceptor, or `unknown` if no requirements. */
|
|
785
|
+
type ExtractInterceptorRequires<T> = T extends {
|
|
786
|
+
'~contextRequires': (ctx: infer R) => void;
|
|
787
|
+
} ? R : unknown;
|
|
788
|
+
/**
|
|
789
|
+
* Checks whether an interceptor's context requirements are satisfied by the available context.
|
|
790
|
+
* Returns `true` if the interceptor has no requirements or if the available context extends the requirements.
|
|
791
|
+
*/
|
|
792
|
+
type InterceptorRequiresCheck<TInterceptor, TAvailableContext> = TInterceptor extends {
|
|
793
|
+
'~contextRequires': (ctx: infer TReq) => void;
|
|
794
|
+
} ? TAvailableContext extends TReq ? true : false : true;
|
|
795
|
+
/** Error brand returned by `.intercept()` when the interceptor's required context is not satisfied. */
|
|
796
|
+
type InterceptorRequiresError = {
|
|
797
|
+
readonly '~error': 'Required context not satisfied. Ensure required interceptors are registered before this one.';
|
|
798
|
+
};
|
|
799
|
+
/**
|
|
800
|
+
* Builder returned by `defineInterceptor(meta)` (single-arg form).
|
|
801
|
+
* Call `.requires<T>()` to declare (and type) the context dependency, then `.factory()` to provide the phase handlers.
|
|
802
|
+
*/
|
|
803
|
+
type InterceptorDefBuilder<TContext = unknown, TBrand = unknown> = {
|
|
804
|
+
/** Declare the context type this interceptor requires. Sets `TContext` for phase handler typing. */requires: <TRequires>() => InterceptorDefBuilder<TRequires, InterceptorRequiresBrand<TRequires>>; /** Provide the interceptor factory. Phase handlers receive the typed `TContext` from `.requires()`. */
|
|
805
|
+
factory: <TArgs = unknown, TResult = unknown>(factory: InterceptorFactory<TArgs, TResult, TContext>) => PadroneInterceptorFn<TArgs, TResult, TContext> & TBrand;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Internal stored form on command objects. Separates static metadata from the factory
|
|
809
|
+
* so that deduplication and sorting can happen without calling the factory.
|
|
810
|
+
*/
|
|
811
|
+
type RegisteredInterceptor = {
|
|
812
|
+
meta: InterceptorMeta;
|
|
813
|
+
factory: InterceptorFactory<any, any, any>;
|
|
501
814
|
};
|
|
502
815
|
//#endregion
|
|
503
|
-
//#region src/types.d.ts
|
|
816
|
+
//#region src/types/command.d.ts
|
|
504
817
|
type UnknownRecord = Record<string, unknown>;
|
|
505
|
-
type
|
|
506
|
-
|
|
818
|
+
type DefaultArgs$1 = UnknownRecord | void;
|
|
819
|
+
/**
|
|
820
|
+
* Read-only metadata about a Padrone program.
|
|
821
|
+
* Returned by `program.info` to expose program-level properties without leaking internal command internals.
|
|
822
|
+
*/
|
|
823
|
+
type PadroneProgramMeta<TName extends string = string> = {
|
|
824
|
+
/** The program name (CLI binary name). */name: TName; /** Display title shown in help output. */
|
|
825
|
+
title?: string; /** Program description. */
|
|
826
|
+
description?: string; /** Program version string. */
|
|
827
|
+
version?: string; /** Usage examples shown in help output. */
|
|
828
|
+
examples?: string[]; /** Whether the program is deprecated. */
|
|
829
|
+
deprecated?: boolean | string; /** Names of registered subcommands. */
|
|
830
|
+
commands: string[];
|
|
831
|
+
};
|
|
507
832
|
/**
|
|
508
833
|
* Context object passed as the second argument to command action handlers.
|
|
509
834
|
* Contains the resolved runtime, the executing command, and the program instance.
|
|
510
835
|
*/
|
|
511
|
-
type PadroneActionContext = {
|
|
836
|
+
type PadroneActionContext<TContext = unknown> = {
|
|
512
837
|
/** The resolved runtime for this command (I/O, env, config, etc.). */runtime: ResolvedPadroneRuntime; /** The command being executed. */
|
|
513
838
|
command: AnyPadroneCommand; /** The root program instance. */
|
|
514
839
|
program: AnyPadroneProgram;
|
|
515
840
|
/**
|
|
516
|
-
*
|
|
517
|
-
* Use
|
|
841
|
+
* Cancellation signal that fires when the process receives SIGINT, SIGTERM, or SIGHUP.
|
|
842
|
+
* Use with `fetch()`, child processes, or any API that accepts `AbortSignal`.
|
|
843
|
+
* Check `signal.aborted` to test if cancellation was requested.
|
|
844
|
+
* The `signal.reason` is a `PadroneSignal` string ('SIGINT', 'SIGTERM', or 'SIGHUP').
|
|
518
845
|
*/
|
|
519
|
-
|
|
846
|
+
signal: AbortSignal; /** User-defined context object. Set via `.context()` on the builder and provided at `cli()`/`eval()` time. */
|
|
847
|
+
context: TContext; /** Which API entry point triggered this execution. */
|
|
848
|
+
caller: 'cli' | 'eval' | 'run' | 'repl' | 'serve' | 'mcp' | 'tool';
|
|
520
849
|
};
|
|
521
850
|
/**
|
|
522
|
-
*
|
|
523
|
-
* This is the type required for command arguments in Padrone.
|
|
524
|
-
*/
|
|
525
|
-
type PadroneSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
|
|
526
|
-
/**
|
|
527
|
-
* A schema branded as async. When passed to `.arguments()`, `.configFile()`, or `.env()`,
|
|
528
|
-
* the command is automatically marked as async, causing `parse()` and `cli()` to return Promises.
|
|
529
|
-
*
|
|
530
|
-
* Use the `asyncSchema()` helper to brand an existing schema:
|
|
531
|
-
* ```ts
|
|
532
|
-
* import { asyncSchema } from 'padrone';
|
|
533
|
-
* const schema = asyncSchema(z.object({ name: z.string() }).check(async (v) => { ... }));
|
|
534
|
-
* ```
|
|
535
|
-
*/
|
|
536
|
-
type AsyncPadroneSchema<Input = unknown, Output = Input> = PadroneSchema<Input, Output> & {
|
|
537
|
-
'~async': true;
|
|
538
|
-
};
|
|
539
|
-
/**
|
|
540
|
-
* Helper type to set aliases on a command type.
|
|
541
|
-
* Uses intersection to override just the aliases while preserving all other type information.
|
|
851
|
+
* Configuration for a command.
|
|
542
852
|
*/
|
|
543
|
-
type
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
853
|
+
type PadroneCommandConfig = {
|
|
854
|
+
/** A short title for the command, displayed in help. */title?: string; /** A longer description of what the command does. */
|
|
855
|
+
description?: string; /** The version of the command. */
|
|
856
|
+
version?: string; /** Whether the command is deprecated, or a message explaining the deprecation. */
|
|
857
|
+
deprecated?: boolean | string; /** Whether the command should be hidden from help output. */
|
|
858
|
+
hidden?: boolean; /** Group name for organizing this command under a labeled section in help output. */
|
|
859
|
+
group?: string; /** Usage examples shown in help output. Each entry is a command-line invocation string. */
|
|
860
|
+
examples?: string[];
|
|
861
|
+
/**
|
|
862
|
+
* Whether this command performs a mutation (create, update, delete).
|
|
863
|
+
* - In `serve()`: mutation commands accept POST only; non-mutation commands accept GET and POST.
|
|
864
|
+
* - In `mcp()`: sets `annotations.destructiveHint` on the tool definition.
|
|
865
|
+
* - In `tool()`: defaults `needsApproval` to `true` when not explicitly set.
|
|
866
|
+
*/
|
|
867
|
+
mutation?: boolean;
|
|
548
868
|
};
|
|
549
|
-
|
|
550
|
-
* Resolves aliases for a command override: if new aliases are provided (non-empty), use them;
|
|
551
|
-
* otherwise, preserve the existing command's aliases.
|
|
552
|
-
*/
|
|
553
|
-
type ResolvedAliases<TCommands extends [...AnyPadroneCommand[]], TNameNested extends string, TAliases extends string[]> = TAliases extends [] ? FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? E['~types']['aliases'] : [] : TAliases;
|
|
554
|
-
/**
|
|
555
|
-
* Resolves the initial builder type for a `.command()` call.
|
|
556
|
-
* If TNameNested already exists in TCommands, the builder starts pre-populated with that command's types.
|
|
557
|
-
* Otherwise, a fresh builder with default types is used.
|
|
558
|
-
*/
|
|
559
|
-
type InitialCommandBuilder<TProgramName extends string, TNameNested extends string, TParentPath extends string, TParentArgs extends PadroneSchema, TCommands extends [...AnyPadroneCommand[]]> = [FindDirectChild<TCommands, TNameNested>] extends [never] ? PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, PadroneSchema<void>, PadroneSchema<void>, false> : FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? PadroneBuilder<TProgramName, TNameNested, TParentPath, E['~types']['argsSchema'], E['~types']['result'], E['~types']['commands'], TParentArgs, E['~types']['configSchema'], E['~types']['envSchema'], E['~types']['async']> : PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, PadroneSchema<void>, PadroneSchema<void>, false>;
|
|
560
|
-
type AnyPadroneBuilder = InitialCommandBuilder<string, string, string, any, [...AnyPadroneCommand[]]>;
|
|
561
|
-
/**
|
|
562
|
-
* Like InitialCommandBuilder but uses `any` for args/config/env in the fresh case.
|
|
563
|
-
* Used as the default for TBuilder when no builderFn is provided.
|
|
564
|
-
*/
|
|
565
|
-
type DefaultCommandBuilder<TProgramName extends string, TNameNested extends string, TParentPath extends string, TParentArgs extends PadroneSchema, TCommands extends [...AnyPadroneCommand[]]> = [FindDirectChild<TCommands, TNameNested>] extends [never] ? PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, any, any, false> : FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? PadroneBuilder<TProgramName, TNameNested, TParentPath, E['~types']['argsSchema'], E['~types']['result'], E['~types']['commands'], TParentArgs, E['~types']['configSchema'], E['~types']['envSchema'], E['~types']['async']> : PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, any, any, false>;
|
|
566
|
-
type PadroneCommand<TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TAliases extends string[] = string[], TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TAsync extends boolean = false> = {
|
|
869
|
+
type PadroneCommand<TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs$1>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TAliases extends string[] = string[], TAsync extends boolean = false, TContext = unknown, TContextProvided = unknown> = {
|
|
567
870
|
name: TName;
|
|
568
871
|
path: FullCommandName<TName, TParentName>;
|
|
569
872
|
title?: string;
|
|
@@ -574,29 +877,15 @@ type PadroneCommand<TName extends string = string, TParentName extends string =
|
|
|
574
877
|
hidden?: boolean; /** Group name for organizing this command under a labeled section in help output. */
|
|
575
878
|
group?: string; /** Whether this command performs a mutation (create, update, delete). Affects HTTP method in serve (POST-only) and MCP tool annotations (destructiveHint). */
|
|
576
879
|
mutation?: boolean;
|
|
577
|
-
needsApproval?: boolean | ((args: TArgs) => Promise<boolean> | boolean);
|
|
578
|
-
autoOutput?: boolean; /** Usage examples shown in help output. Each entry is a command-line invocation string. */
|
|
880
|
+
needsApproval?: boolean | ((args: TArgs) => Promise<boolean> | boolean); /** Usage examples shown in help output. Each entry is a command-line invocation string. */
|
|
579
881
|
examples?: string[];
|
|
580
|
-
/**
|
|
581
|
-
* Auto-start a progress indicator when the command's execute phase begins.
|
|
582
|
-
* - `true` — generic message based on command name.
|
|
583
|
-
* - `string` — custom message for all states.
|
|
584
|
-
* - `PadroneProgressConfig` — separate messages for progress, success, and error states.
|
|
585
|
-
*
|
|
586
|
-
* The indicator is automatically stopped on success (`.succeed()`) or failure (`.fail()`).
|
|
587
|
-
* Requires a `progress` factory on the runtime — silently skipped if not available.
|
|
588
|
-
*/
|
|
589
|
-
progress?: boolean | string | PadroneProgressPrefs;
|
|
590
882
|
argsSchema?: TArgs;
|
|
591
|
-
configSchema?: TConfig;
|
|
592
|
-
envSchema?: TEnv;
|
|
593
883
|
meta?: GetArgsMeta<TArgs>;
|
|
594
|
-
action?: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext) => TRes; /**
|
|
595
|
-
configFiles?: string[]; /** Runtime flag indicating this command uses async validation. Set by `.async()` or `asyncSchema()`. */
|
|
884
|
+
action?: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext<TContext & TContextProvided>) => TRes; /** Runtime flag indicating this command uses async validation. Set by `.async()` or `asyncSchema()`. */
|
|
596
885
|
isAsync?: boolean; /** Runtime configuration for I/O abstraction. */
|
|
597
|
-
runtime?: PadroneRuntime; /**
|
|
598
|
-
|
|
599
|
-
|
|
886
|
+
runtime?: PadroneRuntime; /** Transform function that maps parent context to this command's context. Set by `.context(transform)`. */
|
|
887
|
+
contextTransform?: (ctx: unknown) => unknown; /** Interceptors registered on this command. Collected from the parent chain at execution time. */
|
|
888
|
+
interceptors?: RegisteredInterceptor[];
|
|
600
889
|
parent?: AnyPadroneCommand;
|
|
601
890
|
commands?: TCommands; /** @deprecated Internal use only */
|
|
602
891
|
'~types': {
|
|
@@ -609,9 +898,9 @@ type PadroneCommand<TName extends string = string, TParentName extends string =
|
|
|
609
898
|
argsOutput: StandardSchemaV1.InferOutput<TArgs>;
|
|
610
899
|
result: TRes;
|
|
611
900
|
commands: TCommands;
|
|
612
|
-
configSchema: TConfig;
|
|
613
|
-
envSchema: TEnv;
|
|
614
901
|
async: TAsync;
|
|
902
|
+
context: TContext;
|
|
903
|
+
contextProvided: TContextProvided;
|
|
615
904
|
};
|
|
616
905
|
};
|
|
617
906
|
type AnyPadroneCommand = PadroneCommand<string, any, any, any, [...AnyPadroneCommand[]], string[], any, any, any>;
|
|
@@ -624,438 +913,9 @@ type CommandTypesBase = {
|
|
|
624
913
|
command: AnyPadroneCommand;
|
|
625
914
|
};
|
|
626
915
|
};
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* A progress message value: a plain string, `null` to suppress, or an object with a message and custom indicator icon.
|
|
632
|
-
*/
|
|
633
|
-
type PadroneProgressMessage = string | null | {
|
|
634
|
-
message?: string | null;
|
|
635
|
-
indicator?: string;
|
|
636
|
-
};
|
|
637
|
-
/**
|
|
638
|
-
* Progress indicator configuration with per-state messages and optional dynamic callbacks.
|
|
639
|
-
*
|
|
640
|
-
* The `success` and `error` fields accept either a static value or a callback function:
|
|
641
|
-
* - `string` — static message.
|
|
642
|
-
* - `null` — suppress the message entirely.
|
|
643
|
-
* - `{ message, indicator }` — custom message with a per-call indicator icon override.
|
|
644
|
-
* - `(result) => PadroneProgressMessage` / `(error) => PadroneProgressMessage` — dynamic from the actual result/error.
|
|
645
|
-
*/
|
|
646
|
-
type PadroneProgressPrefs<TRes = unknown> = {
|
|
647
|
-
/** Message shown during async validation. Defaults to `''` (spinner only). */validation?: string; /** Message shown while the command's action is running. */
|
|
648
|
-
progress?: string; /** Message shown when the command succeeds. `null` to suppress. Defaults to the `progress` message. */
|
|
649
|
-
success?: PadroneProgressMessage | ((result: TRes) => PadroneProgressMessage); /** Message shown when the command fails. `null` to suppress. Defaults to the error message. */
|
|
650
|
-
error?: PadroneProgressMessage | ((error: unknown) => PadroneProgressMessage); /** Spinner configuration: a preset name, custom frames/interval, or `false` to disable. */
|
|
651
|
-
spinner?: PadroneSpinnerConfig;
|
|
652
|
-
};
|
|
653
|
-
type PadroneCommandConfig = {
|
|
654
|
-
/** A short title for the command, displayed in help. */title?: string; /** A longer description of what the command does. */
|
|
655
|
-
description?: string; /** The version of the command. */
|
|
656
|
-
version?: string; /** Whether the command is deprecated, or a message explaining the deprecation. */
|
|
657
|
-
deprecated?: boolean | string; /** Whether the command should be hidden from help output. */
|
|
658
|
-
hidden?: boolean; /** Group name for organizing this command under a labeled section in help output. */
|
|
659
|
-
group?: string;
|
|
660
|
-
/**
|
|
661
|
-
* Automatically write this command's return value to output in CLI/eval/REPL mode.
|
|
662
|
-
* Overrides the `autoOutput` setting in eval/cli preferences for this command.
|
|
663
|
-
* See `PadroneEvalPreferences.autoOutput` for serialization details.
|
|
664
|
-
*/
|
|
665
|
-
autoOutput?: boolean; /** Usage examples shown in help output. Each entry is a command-line invocation string. */
|
|
666
|
-
examples?: string[];
|
|
667
|
-
/**
|
|
668
|
-
* Whether this command performs a mutation (create, update, delete).
|
|
669
|
-
* - In `serve()`: mutation commands accept POST only; non-mutation commands accept GET and POST.
|
|
670
|
-
* - In `mcp()`: sets `annotations.destructiveHint` on the tool definition.
|
|
671
|
-
* - In `tool()`: defaults `needsApproval` to `true` when not explicitly set.
|
|
672
|
-
*/
|
|
673
|
-
mutation?: boolean;
|
|
674
|
-
};
|
|
675
|
-
/**
|
|
676
|
-
* Conditional type that returns either PadroneBuilder or PadroneProgram based on TReturn.
|
|
677
|
-
* Used to avoid repetition in PadroneBuilderMethods return types.
|
|
678
|
-
*/
|
|
679
|
-
type BuilderOrProgram<TReturn extends 'builder' | 'program', TProgramName extends string, TName extends string, TParentName extends string, TArgs extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentArgs extends PadroneSchema, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>, TAsync extends boolean> = TReturn extends 'builder' ? PadroneBuilder<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync> : PadroneProgram<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
680
|
-
/**
|
|
681
|
-
* Base builder methods shared between PadroneBuilder and PadroneProgram.
|
|
682
|
-
* These methods are used for defining command structure (arguments, config, env, action, subcommands).
|
|
683
|
-
*/
|
|
684
|
-
type PadroneBuilderMethods<TProgramName extends string, TName extends string, TParentName extends string, TArgs extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentArgs extends PadroneSchema, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>, TAsync extends boolean, /** The return type for builder methods - either PadroneBuilder or PadroneProgram */TReturn extends 'builder' | 'program'> = {
|
|
685
|
-
/**
|
|
686
|
-
* Enables automatic update checking against a package registry.
|
|
687
|
-
* When enabled, the program checks for a newer version in the background
|
|
688
|
-
* and displays a notification after command output if an update is available.
|
|
689
|
-
*
|
|
690
|
-
* - Non-blocking: check runs in background, never delays command execution.
|
|
691
|
-
* - Non-intrusive: shows a one-line notice after command output, not before.
|
|
692
|
-
* - Respects CI: disabled when `CI=true` or non-TTY.
|
|
693
|
-
* - Respects user preference: `--no-update-check` flag or env var.
|
|
694
|
-
* - Caches last check timestamp to avoid hitting the registry on every invocation.
|
|
695
|
-
*
|
|
696
|
-
* @example
|
|
697
|
-
* ```ts
|
|
698
|
-
* createPadrone('myapp')
|
|
699
|
-
* .version('1.2.3')
|
|
700
|
-
* .updateCheck({
|
|
701
|
-
* registry: 'npm', // or custom URL
|
|
702
|
-
* interval: '1d', // check at most once per day
|
|
703
|
-
* cache: '~/.myapp-update' // where to store last check
|
|
704
|
-
* })
|
|
705
|
-
* ```
|
|
706
|
-
*/
|
|
707
|
-
updateCheck: (config?: UpdateCheckConfig) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
708
|
-
/**
|
|
709
|
-
* Registers a plugin that intercepts command execution phases (parse, validate, execute).
|
|
710
|
-
* Plugins are applied in order: first registered = outermost wrapper (runs first before `next()`).
|
|
711
|
-
* Use `plugin.order` for explicit ordering (lower = outermost).
|
|
712
|
-
*
|
|
713
|
-
* On the program, parse/validate/execute plugins all apply.
|
|
714
|
-
* On subcommands, only validate and execute plugins apply (parse is handled by the root program).
|
|
715
|
-
*/
|
|
716
|
-
use: (plugin: PadronePlugin<StandardSchemaV1.InferOutput<TArgs>, TRes>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
717
|
-
configure: (config: PadroneCommandConfig) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
718
|
-
/**
|
|
719
|
-
* Configures the runtime adapter for I/O abstraction.
|
|
720
|
-
* Allows the CLI framework to work outside of a terminal (e.g., web UIs, chat interfaces, testing).
|
|
721
|
-
* Unspecified fields fall back to the Node.js/Bun defaults.
|
|
722
|
-
*
|
|
723
|
-
* @example
|
|
724
|
-
* ```ts
|
|
725
|
-
* .runtime({
|
|
726
|
-
* output: (text) => panel.append(text),
|
|
727
|
-
* error: (text) => panel.appendError(text),
|
|
728
|
-
* format: 'html',
|
|
729
|
-
* })
|
|
730
|
-
* ```
|
|
731
|
-
*/
|
|
732
|
-
runtime: (runtime: PadroneRuntime) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
733
|
-
/**
|
|
734
|
-
* Explicitly marks this command as using async validation.
|
|
735
|
-
* When a command is async, `parse()` and `cli()` return Promises.
|
|
736
|
-
*
|
|
737
|
-
* This is an alternative to using `asyncSchema()` on individual schemas.
|
|
738
|
-
* Use this when your schema has async refinements but you don't want to
|
|
739
|
-
* (or can't) brand the schema itself.
|
|
740
|
-
*
|
|
741
|
-
* @example
|
|
742
|
-
* ```ts
|
|
743
|
-
* .arguments(z.object({ name: z.string() }).check(async (v) => { ... }))
|
|
744
|
-
* .async()
|
|
745
|
-
* .action((args) => { ... })
|
|
746
|
-
* ```
|
|
747
|
-
*/
|
|
748
|
-
async: () => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, true>;
|
|
749
|
-
/**
|
|
750
|
-
* Defines the arguments schema for the command, including positional arguments.
|
|
751
|
-
* Can accept either a schema directly or a function that takes parent args schema as a base and returns a schema.
|
|
752
|
-
* Use the `positional` array in meta to specify which arguments are positional args.
|
|
753
|
-
* Use '...name' prefix for variadic (rest) arguments, matching JS/TS rest syntax.
|
|
754
|
-
*
|
|
755
|
-
* @example
|
|
756
|
-
* ```ts
|
|
757
|
-
* // Direct schema
|
|
758
|
-
* .arguments(z.object({
|
|
759
|
-
* source: z.string(),
|
|
760
|
-
* files: z.string().array(),
|
|
761
|
-
* dest: z.string(),
|
|
762
|
-
* recursive: z.boolean().default(false),
|
|
763
|
-
* }), {
|
|
764
|
-
* positional: ['source', '...files', 'dest'],
|
|
765
|
-
* })
|
|
766
|
-
* ```
|
|
767
|
-
*
|
|
768
|
-
* @example
|
|
769
|
-
* ```ts
|
|
770
|
-
* // Function-based schema extending parent arguments
|
|
771
|
-
* .arguments((parentArgs) => {
|
|
772
|
-
* return z.object({
|
|
773
|
-
* ...parentArgs.shape,
|
|
774
|
-
* verbose: z.boolean().default(false),
|
|
775
|
-
* });
|
|
776
|
-
* })
|
|
777
|
-
* ```
|
|
778
|
-
*/
|
|
779
|
-
arguments: <TNewArgs extends PadroneSchema = PadroneSchema<void>, TMeta extends GetArgsMeta<TNewArgs> = GetArgsMeta<TNewArgs>>(schema?: TNewArgs | ((parentSchema: TParentArgs) => TNewArgs), meta?: TMeta) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TNewArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, OrAsyncMeta<OrAsync<TAsync, TNewArgs>, TMeta>>;
|
|
780
|
-
/**
|
|
781
|
-
* Configures config file path(s) and schema for parsing config files.
|
|
782
|
-
* @example
|
|
783
|
-
* ```ts
|
|
784
|
-
* .configFile('config.json', z.object({ port: z.number() }))
|
|
785
|
-
* ```
|
|
786
|
-
*/
|
|
787
|
-
configFile: <TNewConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = TArgs>(file: string | string[] | undefined, schema?: TNewConfig | ((argsSchema: TArgs) => TNewConfig)) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TNewConfig, TEnv, OrAsync<TAsync, TNewConfig>>;
|
|
788
|
-
/**
|
|
789
|
-
* Configures environment variable schema for parsing env vars into arguments.
|
|
790
|
-
* The schema should transform environment variables (typically SCREAMING_SNAKE_CASE)
|
|
791
|
-
* into the argument names used by the command.
|
|
792
|
-
* @example
|
|
793
|
-
* ```ts
|
|
794
|
-
* .env(z.object({ MY_APP_PORT: z.coerce.number() }).transform(e => ({ port: e.MY_APP_PORT })))
|
|
795
|
-
* ```
|
|
796
|
-
*/
|
|
797
|
-
env: <TNewEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = TArgs>(schema: TNewEnv | ((argsSchema: TArgs) => TNewEnv)) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TNewEnv, OrAsync<TAsync, TNewEnv>>;
|
|
798
|
-
/**
|
|
799
|
-
* Configures an auto-managed progress indicator for this command.
|
|
800
|
-
* The indicator starts before validation and is automatically stopped on success or failure.
|
|
801
|
-
*
|
|
802
|
-
* - `true` — generic message based on command name.
|
|
803
|
-
* - `string` — custom message for all states.
|
|
804
|
-
* - `PadroneProgressConfig` — full control: per-state messages, dynamic callbacks, spinner config.
|
|
805
|
-
*
|
|
806
|
-
* Requires a `progress` factory on the runtime — silently skipped if not available.
|
|
807
|
-
*
|
|
808
|
-
* @example
|
|
809
|
-
* ```ts
|
|
810
|
-
* .progress('Deploying...')
|
|
811
|
-
* .progress({
|
|
812
|
-
* progress: 'Deploying...',
|
|
813
|
-
* success: (result) => `Deployed ${result.version}`,
|
|
814
|
-
* error: (err) => `Deploy failed: ${err.message}`,
|
|
815
|
-
* spinner: 'line',
|
|
816
|
-
* })
|
|
817
|
-
* ```
|
|
818
|
-
*/
|
|
819
|
-
progress: (config?: boolean | string | PadroneProgressPrefs<Awaited<TRes>>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
820
|
-
/**
|
|
821
|
-
* Defines the handler function to be executed when the command is run.
|
|
822
|
-
* When overriding an existing command, the previous handler is passed as the third `base` parameter.
|
|
823
|
-
*/
|
|
824
|
-
action: <TNewRes>(handler?: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext, base: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext) => TRes) => TNewRes) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TNewRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
825
|
-
/**
|
|
826
|
-
* Wraps an external CLI tool with optional schema transformation.
|
|
827
|
-
* The config can include a schema that transforms command arguments to external CLI arguments.
|
|
828
|
-
*
|
|
829
|
-
* @experimental This API is experimental and may change in future releases.
|
|
830
|
-
*
|
|
831
|
-
* @example
|
|
832
|
-
* ```ts
|
|
833
|
-
* // No transformation - pass arguments as-is
|
|
834
|
-
* .arguments(z.object({
|
|
835
|
-
* message: z.string(),
|
|
836
|
-
* }))
|
|
837
|
-
* .wrap({
|
|
838
|
-
* command: 'echo',
|
|
839
|
-
* })
|
|
840
|
-
* ```
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* ```ts
|
|
844
|
-
* // With transformation schema
|
|
845
|
-
* .arguments(z.object({
|
|
846
|
-
* message: z.string(),
|
|
847
|
-
* all: z.boolean().optional(),
|
|
848
|
-
* }), {
|
|
849
|
-
* positional: ['message'],
|
|
850
|
-
* })
|
|
851
|
-
* .wrap({
|
|
852
|
-
* command: 'git',
|
|
853
|
-
* args: ['commit'],
|
|
854
|
-
* positional: ['m'],
|
|
855
|
-
* schema: z.object({
|
|
856
|
-
* message: z.string(),
|
|
857
|
-
* all: z.boolean().optional(),
|
|
858
|
-
* }).transform(args => ({
|
|
859
|
-
* m: args.message,
|
|
860
|
-
* a: args.all,
|
|
861
|
-
* })),
|
|
862
|
-
* })
|
|
863
|
-
* ```
|
|
864
|
-
*
|
|
865
|
-
* @example
|
|
866
|
-
* ```ts
|
|
867
|
-
* // Using function-based schema for type inference
|
|
868
|
-
* .arguments(z.object({
|
|
869
|
-
* image: z.string(),
|
|
870
|
-
* detach: z.boolean().optional(),
|
|
871
|
-
* }))
|
|
872
|
-
* .wrap({
|
|
873
|
-
* command: 'docker',
|
|
874
|
-
* args: ['run'],
|
|
875
|
-
* positional: ['image'],
|
|
876
|
-
* schema: (schema) => schema.transform(args => ({
|
|
877
|
-
* d: args.detach,
|
|
878
|
-
* image: args.image,
|
|
879
|
-
* })),
|
|
880
|
-
* })
|
|
881
|
-
* ```
|
|
882
|
-
*/
|
|
883
|
-
wrap: <TWrapArgs extends PadroneSchema = TArgs>(config: WrapConfig<TArgs, TWrapArgs>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, Promise<WrapResult>, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
884
|
-
/**
|
|
885
|
-
* Creates or extends a nested command within the current command.
|
|
886
|
-
* If a command with the same name already exists, it is extended:
|
|
887
|
-
* - Configuration is merged (new values override old).
|
|
888
|
-
* - The builder callback receives a builder pre-populated with the existing command's state.
|
|
889
|
-
* - `.action()` receives the previous handler as the third `base` parameter.
|
|
890
|
-
* - `.arguments()` callback receives the existing schema as its parameter.
|
|
891
|
-
* - Subcommands are recursively merged by name.
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* ```ts
|
|
895
|
-
* // Fresh command
|
|
896
|
-
* .command('list', (c) => c.action(() => 'list'))
|
|
897
|
-
*
|
|
898
|
-
* // Override — extend an existing command
|
|
899
|
-
* .command('list', (c) => c.action((args, ctx, base) => {
|
|
900
|
-
* const original = base(args, ctx);
|
|
901
|
-
* return `modified: ${original}`;
|
|
902
|
-
* }))
|
|
903
|
-
*
|
|
904
|
-
* // Name with aliases
|
|
905
|
-
* .command(['list', 'ls', 'l'], (c) => c.action(() => 'list'))
|
|
906
|
-
* ```
|
|
907
|
-
*/
|
|
908
|
-
command: <TNameNested extends string, TAliases extends string[] = [], TBuilder extends CommandTypesBase = DefaultCommandBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, TArgs, TCommands>>(name: TNameNested | readonly [TNameNested, ...TAliases], builderFn?: (builder: InitialCommandBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, TArgs, TCommands>) => TBuilder) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands extends [] ? [WithAliases<TBuilder['~types']['command'], TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<TBuilder['~types']['command'], TAliases>] : ReplaceOrAppendCommand<TCommands, TNameNested, WithAliases<TBuilder['~types']['command'], ResolvedAliases<TCommands, TNameNested, TAliases>>>, TParentArgs, TConfig, TEnv, TAsync>;
|
|
909
|
-
/**
|
|
910
|
-
* Mounts an existing Padrone program as a subcommand.
|
|
911
|
-
* The program's root-level properties (name, path, parent) are replaced to fit the mount point.
|
|
912
|
-
* All subcommands are recursively re-pathed. Root-level `version` is dropped.
|
|
913
|
-
*
|
|
914
|
-
* @example
|
|
915
|
-
* ```ts
|
|
916
|
-
* const admin = createPadrone('admin')
|
|
917
|
-
* .command('users', (c) => c.action(() => 'users'))
|
|
918
|
-
* .command('roles', (c) => c.action(() => 'roles'));
|
|
919
|
-
*
|
|
920
|
-
* const app = createPadrone('app')
|
|
921
|
-
* .mount('admin', admin)
|
|
922
|
-
* // Now: app admin users, app admin roles
|
|
923
|
-
*
|
|
924
|
-
* // With aliases
|
|
925
|
-
* const app2 = createPadrone('app')
|
|
926
|
-
* .mount(['admin', 'adm'], admin)
|
|
927
|
-
* ```
|
|
928
|
-
*/
|
|
929
|
-
mount: <TNameNested extends string, TAliases extends string[] = [], TProgram extends CommandTypesBase = CommandTypesBase>(name: TNameNested | readonly [TNameNested, ...TAliases], program: TProgram) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands extends [] ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['configSchema'], TProgram['~types']['command']['~types']['envSchema'], TProgram['~types']['command']['~types']['async']>, TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['configSchema'], TProgram['~types']['command']['~types']['envSchema'], TProgram['~types']['command']['~types']['async']>, TAliases>] : ReplaceOrAppendCommand<TCommands, TNameNested, WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['configSchema'], TProgram['~types']['command']['~types']['envSchema'], TProgram['~types']['command']['~types']['async']>, ResolvedAliases<TCommands, TNameNested, TAliases>>>, TParentArgs, TConfig, TEnv, TAsync>; /** @deprecated Internal use only */
|
|
930
|
-
'~types': {
|
|
931
|
-
programName: TProgramName;
|
|
932
|
-
name: TName;
|
|
933
|
-
parentName: TParentName;
|
|
934
|
-
path: FullCommandName<TName, TParentName>;
|
|
935
|
-
aliases: [];
|
|
936
|
-
argsSchema: TArgs;
|
|
937
|
-
result: TRes;
|
|
938
|
-
commands: TCommands;
|
|
939
|
-
async: TAsync;
|
|
940
|
-
command: PadroneCommand<TName, TParentName, TArgs, TRes, TCommands, [], TConfig, TEnv, TAsync>;
|
|
941
|
-
};
|
|
942
|
-
};
|
|
943
|
-
type PadroneBuilder<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentArgs extends PadroneSchema = PadroneSchema<void>, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TAsync extends boolean = false> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync, 'builder'>;
|
|
944
|
-
type PadroneProgram<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentArgs extends PadroneSchema = PadroneSchema<void>, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>, TAsync extends boolean = false> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync, 'program'> & {
|
|
945
|
-
/**
|
|
946
|
-
* Runs a command programmatically by name with provided arguments (including positional args).
|
|
947
|
-
*/
|
|
948
|
-
run: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(name: TCommand | SafeString, args: NoInfer<GetArguments<'in', PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>>) => PadroneCommandResult<PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>;
|
|
949
|
-
/**
|
|
950
|
-
* Evaluates a command string: parses, validates, and executes.
|
|
951
|
-
* On validation errors, returns a result with issues instead of throwing.
|
|
952
|
-
* This is the method used by `repl()` internally, and the right choice for
|
|
953
|
-
* programmatic invocation, testing, chat interfaces, or any context where
|
|
954
|
-
* you have a command string and want a result — not a process exit.
|
|
955
|
-
*
|
|
956
|
-
* @example
|
|
957
|
-
* ```ts
|
|
958
|
-
* const result = await program.eval('greet --name Alice');
|
|
959
|
-
* if (result.argsResult?.issues) { /* handle validation errors *\/ }
|
|
960
|
-
* ```
|
|
961
|
-
*/
|
|
962
|
-
eval: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(input: TCommand | SafeString, prefs?: PadroneEvalPreferences) => MaybePromiseCommandResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>, PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']>;
|
|
963
|
-
/**
|
|
964
|
-
* Runs the program as a CLI entry point, parsing `process.argv`.
|
|
965
|
-
* On validation errors, throws and prints help.
|
|
966
|
-
* For programmatic invocation with a command string, use `eval()` instead.
|
|
967
|
-
*/
|
|
968
|
-
cli: (prefs?: PadroneCliPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>) => MaybePromiseCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>, TAsync>;
|
|
969
|
-
/**
|
|
970
|
-
* Parses CLI input (or the provided input string) into command and arguments without executing anything.
|
|
971
|
-
*/
|
|
972
|
-
parse: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, false>>(input?: TCommand | SafeString) => MaybePromise<PadroneParseResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>, PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']>;
|
|
973
|
-
/**
|
|
974
|
-
* Converts command and arguments back into a CLI string.
|
|
975
|
-
*/
|
|
976
|
-
stringify: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command?: TCommand | SafeString, args?: GetArguments<'out', PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>) => string;
|
|
977
|
-
/**
|
|
978
|
-
* Finds a command by name, returning `undefined` if not found.
|
|
979
|
-
*/
|
|
980
|
-
find: <const TFind extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command: TFind | SafeString) => PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TFind> | undefined;
|
|
981
|
-
/**
|
|
982
|
-
* Generates a type-safe API for invoking commands programmatically.
|
|
983
|
-
*/
|
|
984
|
-
api: () => PadroneAPI<PadroneCommand<'', '', TArgs, TRes, TCommands>>;
|
|
985
|
-
/**
|
|
986
|
-
* Starts a REPL (Read-Eval-Print Loop) for running commands interactively.
|
|
987
|
-
* Returns an AsyncIterable that yields a `PadroneCommandResult` for each successfully executed command.
|
|
988
|
-
* Errors are printed via `runtime.error()` and the loop continues.
|
|
989
|
-
* The loop ends when the user sends EOF (Ctrl+D), types `.exit`/`.quit`,
|
|
990
|
-
* or presses Ctrl+C twice within 2 seconds.
|
|
991
|
-
*
|
|
992
|
-
* @example
|
|
993
|
-
* ```ts
|
|
994
|
-
* for await (const result of program.repl()) {
|
|
995
|
-
* console.log(result.command.name, result.result);
|
|
996
|
-
* }
|
|
997
|
-
* ```
|
|
998
|
-
*
|
|
999
|
-
* TODO: REPL future enhancements:
|
|
1000
|
-
* - History persistence: save/load history across sessions (currently in-memory only)
|
|
1001
|
-
* - Middleware/hooks: onBeforeCommand, onAfterCommand, error interceptors (design alongside general middleware system)
|
|
1002
|
-
*/
|
|
1003
|
-
repl: (options?: PadroneReplPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>) => AsyncIterable<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>> & {
|
|
1004
|
-
drain: () => Promise<PadroneDrainResult<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>[]>>;
|
|
1005
|
-
};
|
|
1006
|
-
/**
|
|
1007
|
-
* Returns a tool definition that can be passed to AI SDK.
|
|
1008
|
-
*/
|
|
1009
|
-
tool: () => Tool<{
|
|
1010
|
-
command: string;
|
|
1011
|
-
}>;
|
|
1012
|
-
/**
|
|
1013
|
-
* Returns the help information for the program or a specific command.
|
|
1014
|
-
*/
|
|
1015
|
-
help: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command?: TCommand, prefs?: HelpPreferences) => string;
|
|
1016
|
-
/**
|
|
1017
|
-
* Generates and returns a shell completion script.
|
|
1018
|
-
* If shell is not specified, automatically detects the current shell and provides instructions.
|
|
1019
|
-
* @param shell - The shell type (bash, zsh, fish, powershell). If not provided, auto-detects.
|
|
1020
|
-
* @returns The shell completion script as a string.
|
|
1021
|
-
* @example
|
|
1022
|
-
* ```ts
|
|
1023
|
-
* // Get bash completion script
|
|
1024
|
-
* const bashScript = program.completion('bash');
|
|
1025
|
-
*
|
|
1026
|
-
* // Auto-detect shell and get completion script with instructions
|
|
1027
|
-
* const script = program.completion();
|
|
1028
|
-
* ```
|
|
1029
|
-
*/
|
|
1030
|
-
completion: (shell?: 'bash' | 'zsh' | 'fish' | 'powershell') => Promise<string>;
|
|
1031
|
-
/**
|
|
1032
|
-
* Starts a Model Context Protocol (MCP) server that exposes commands as tools for AI assistants.
|
|
1033
|
-
* Communicates over stdio using JSON-RPC with Content-Length framing.
|
|
1034
|
-
* Returns a Promise that resolves when the connection closes.
|
|
1035
|
-
*
|
|
1036
|
-
* @experimental This API is experimental and may change in future releases.
|
|
1037
|
-
*
|
|
1038
|
-
* @example
|
|
1039
|
-
* ```ts
|
|
1040
|
-
* await program.mcp();
|
|
1041
|
-
* ```
|
|
1042
|
-
*/
|
|
1043
|
-
mcp: (prefs?: PadroneMcpPreferences) => Promise<void>;
|
|
1044
|
-
/**
|
|
1045
|
-
* Starts a REST HTTP server that exposes commands as endpoints.
|
|
1046
|
-
* Each command becomes a route: `users list` → `GET/POST /users/list`.
|
|
1047
|
-
* Commands with `mutation: true` only accept POST.
|
|
1048
|
-
*
|
|
1049
|
-
* @experimental This API is experimental and may change in future releases.
|
|
1050
|
-
*
|
|
1051
|
-
* @example
|
|
1052
|
-
* ```ts
|
|
1053
|
-
* await program.serve({ port: 3000 });
|
|
1054
|
-
* ```
|
|
1055
|
-
*/
|
|
1056
|
-
serve: (prefs?: PadroneServePreferences) => Promise<void>;
|
|
1057
|
-
};
|
|
1058
|
-
type AnyPadroneProgram = PadroneProgram<string, string, string, any, any, [...AnyPadroneCommand[]]>;
|
|
916
|
+
type GetArgsMeta<TArgs extends PadroneSchema> = PadroneArgsSchemaMeta<NonNullable<StandardSchemaV1.InferInput<TArgs>>>;
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region src/types/preferences.d.ts
|
|
1059
919
|
/**
|
|
1060
920
|
* Options for `repl()` to customize the REPL session.
|
|
1061
921
|
*/
|
|
@@ -1097,12 +957,6 @@ type PadroneReplPreferences<TScope extends string = string> = {
|
|
|
1097
957
|
* Users can change scope at runtime with `.scope <subcommand>` and `.scope ..`/`..`.
|
|
1098
958
|
*/
|
|
1099
959
|
scope?: TScope;
|
|
1100
|
-
/**
|
|
1101
|
-
* Automatically write each command's return value to output.
|
|
1102
|
-
* See `PadroneEvalPreferences.autoOutput` for details on how values are serialized.
|
|
1103
|
-
* Defaults to `true`.
|
|
1104
|
-
*/
|
|
1105
|
-
autoOutput?: boolean;
|
|
1106
960
|
};
|
|
1107
961
|
/**
|
|
1108
962
|
* Options that can be passed to `eval()` to control execution behavior.
|
|
@@ -1117,32 +971,29 @@ type PadroneEvalPreferences = {
|
|
|
1117
971
|
* - `false`: suppress all interactive prompts.
|
|
1118
972
|
*/
|
|
1119
973
|
interactive?: boolean;
|
|
1120
|
-
/**
|
|
1121
|
-
* Automatically write the command's return value to output.
|
|
1122
|
-
*
|
|
1123
|
-
* - Values are passed directly to the runtime's `output` function (no stringification).
|
|
1124
|
-
* - Promises are awaited before output.
|
|
1125
|
-
* - Iterators and async iterators are consumed, outputting each yielded value as it arrives.
|
|
1126
|
-
* - `undefined` and `null` results produce no output.
|
|
1127
|
-
*
|
|
1128
|
-
* Defaults to `true`. Set to `false` to disable.
|
|
1129
|
-
*/
|
|
1130
|
-
autoOutput?: boolean;
|
|
1131
974
|
/**
|
|
1132
975
|
* Override the runtime for this execution.
|
|
1133
976
|
* Partial — only the provided fields replace the command's resolved runtime.
|
|
1134
977
|
* Useful for capturing output, injecting test doubles, or running in non-terminal contexts (e.g. AI tool calls).
|
|
1135
978
|
*/
|
|
1136
979
|
runtime?: PadroneRuntime;
|
|
980
|
+
/**
|
|
981
|
+
* User-defined context object passed to command action handlers via `ctx.context`.
|
|
982
|
+
* The context flows through the command tree and can be transformed by subcommands via `.context(transform)`.
|
|
983
|
+
*/
|
|
984
|
+
context?: unknown; /** @internal Which API entry point triggered this execution. */
|
|
985
|
+
caller?: PadroneActionContext['caller'];
|
|
1137
986
|
};
|
|
1138
987
|
/**
|
|
1139
988
|
* Options that can be passed to `cli()` to control execution behavior.
|
|
1140
989
|
*/
|
|
1141
|
-
type PadroneCliPreferences
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
990
|
+
type PadroneCliPreferences = PadroneEvalPreferences;
|
|
991
|
+
//#endregion
|
|
992
|
+
//#region src/types/result.d.ts
|
|
993
|
+
type EmptyRecord = Record<string, never>;
|
|
994
|
+
type NormalizeArguments<TArgs> = IsGeneric<TArgs> extends true ? void | EmptyRecord : TArgs;
|
|
995
|
+
type GetArguments<TDir extends 'in' | 'out', TCommand extends AnyPadroneCommand> = TDir extends 'in' ? NormalizeArguments<TCommand['~types']['argsInput']> : NormalizeArguments<TCommand['~types']['argsOutput']>;
|
|
996
|
+
type GetResults<TCommand extends AnyPadroneCommand> = ReturnType<NonNullable<TCommand['action']>>;
|
|
1146
997
|
/**
|
|
1147
998
|
* Result of `drain()` — a discriminated union that never throws.
|
|
1148
999
|
* On success, `value` holds the fully resolved/collected result; on failure, `error` holds the error.
|
|
@@ -1163,14 +1014,18 @@ type PadroneDrainResult<TResult> = {
|
|
|
1163
1014
|
*/
|
|
1164
1015
|
type PadroneCommandResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand> = (PadroneParseResult<TCommand> & {
|
|
1165
1016
|
result: GetResults<TCommand>;
|
|
1166
|
-
error?: never; /**
|
|
1017
|
+
error?: never; /** The signal that caused cancellation, if any. */
|
|
1018
|
+
signal?: PadroneSignal; /** Suggested exit code (e.g. 130 for SIGINT). Present when a signal caused termination. */
|
|
1019
|
+
exitCode?: number; /** Flattens the result: awaits Promises, collects iterables, catches errors. Never throws. */
|
|
1167
1020
|
drain: () => Promise<PadroneDrainResult<GetResults<TCommand>>>;
|
|
1168
1021
|
}) | {
|
|
1169
1022
|
command?: TCommand;
|
|
1170
1023
|
args?: GetArguments<'out', TCommand>;
|
|
1171
1024
|
argsResult?: StandardSchemaV1.Result<GetArguments<'out', TCommand>>;
|
|
1172
1025
|
error: unknown;
|
|
1173
|
-
result?: never; /**
|
|
1026
|
+
result?: never; /** The signal that caused cancellation, if any. */
|
|
1027
|
+
signal?: PadroneSignal; /** Suggested exit code (e.g. 130 for SIGINT). Present when a signal caused termination. */
|
|
1028
|
+
exitCode?: number; /** Returns `{ error }` since there is no result to drain. */
|
|
1174
1029
|
drain: () => Promise<PadroneDrainResult<GetResults<TCommand>>>;
|
|
1175
1030
|
};
|
|
1176
1031
|
/**
|
|
@@ -1187,121 +1042,137 @@ type PadroneParseResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand>
|
|
|
1187
1042
|
};
|
|
1188
1043
|
type PadroneAPI<TCommand extends AnyPadroneCommand> = PadroneAPICommand<TCommand> & { [K in TCommand['~types']['commands'][number] as K['name']]: PadroneAPI<K> };
|
|
1189
1044
|
type PadroneAPICommand<TCommand extends AnyPadroneCommand> = (args: GetArguments<'in', TCommand>) => GetResults<TCommand>;
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
type
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
/** The raw CLI input string (undefined when invoked without input). */input: string | undefined;
|
|
1202
|
-
};
|
|
1203
|
-
/** Result returned by the parse phase's `next()`. */
|
|
1204
|
-
type PluginParseResult = {
|
|
1205
|
-
command: AnyPadroneCommand;
|
|
1206
|
-
rawArgs: Record<string, unknown>;
|
|
1207
|
-
positionalArgs: string[];
|
|
1208
|
-
};
|
|
1209
|
-
/** Context for the validate phase. */
|
|
1210
|
-
type PluginValidateContext = PluginBaseContext & {
|
|
1211
|
-
/** Raw named arguments extracted by the parser. Mutable — modify before `next()` to inject/override values. */rawArgs: Record<string, unknown>; /** Positional argument strings extracted by the parser. */
|
|
1212
|
-
positionalArgs: string[];
|
|
1213
|
-
};
|
|
1214
|
-
/** Result returned by the validate phase's `next()`. */
|
|
1215
|
-
type PluginValidateResult<TArgs = unknown> = {
|
|
1216
|
-
args: TArgs;
|
|
1217
|
-
argsResult: StandardSchemaV1.Result<TArgs>;
|
|
1218
|
-
};
|
|
1219
|
-
/** Context for the execute phase. */
|
|
1220
|
-
type PluginExecuteContext<TArgs = unknown> = PluginBaseContext & {
|
|
1221
|
-
/** Validated arguments that will be passed to the action. Mutable — modify before `next()` to override. */args: TArgs;
|
|
1222
|
-
};
|
|
1223
|
-
/** Result returned by the execute phase's `next()`. */
|
|
1224
|
-
type PluginExecuteResult<TResult = unknown> = {
|
|
1225
|
-
result: TResult;
|
|
1226
|
-
};
|
|
1227
|
-
/** Context for the start phase. Runs before parsing, wraps the entire pipeline. */
|
|
1228
|
-
type PluginStartContext = PluginBaseContext & {
|
|
1229
|
-
/** The raw CLI input string (undefined when invoked without input). */input: string | undefined;
|
|
1230
|
-
};
|
|
1231
|
-
/** Context for the error phase. Called when the pipeline throws. */
|
|
1232
|
-
type PluginErrorContext = PluginBaseContext & {
|
|
1233
|
-
/** The error that was thrown. */error: unknown;
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/types/builder.d.ts
|
|
1047
|
+
/**
|
|
1048
|
+
* Helper type to set aliases on a command type.
|
|
1049
|
+
* Uses intersection to override just the aliases while preserving all other type information.
|
|
1050
|
+
*/
|
|
1051
|
+
type WithAliases<TCommand extends AnyPadroneCommand, TAliases extends string[]> = Omit<TCommand, 'aliases' | '~types'> & {
|
|
1052
|
+
aliases?: TAliases;
|
|
1053
|
+
'~types': Omit<TCommand['~types'], 'aliases'> & {
|
|
1054
|
+
aliases: TAliases;
|
|
1055
|
+
};
|
|
1234
1056
|
};
|
|
1235
|
-
/**
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1057
|
+
/**
|
|
1058
|
+
* Resolves aliases for a command override: if new aliases are provided (non-empty), use them;
|
|
1059
|
+
* otherwise, preserve the existing command's aliases.
|
|
1060
|
+
*/
|
|
1061
|
+
type ResolvedAliases<TCommands extends [...AnyPadroneCommand[]], TNameNested extends string, TAliases extends string[]> = TAliases extends [] ? FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? E['~types']['aliases'] : [] : TAliases;
|
|
1062
|
+
/**
|
|
1063
|
+
* When TContext is `unknown` (no `.context()` called), context param is optional.
|
|
1064
|
+
* Otherwise it is required.
|
|
1065
|
+
*/
|
|
1066
|
+
type ContextParam<TContext> = unknown extends TContext ? {
|
|
1067
|
+
context?: TContext;
|
|
1068
|
+
} : {
|
|
1069
|
+
context: TContext;
|
|
1239
1070
|
};
|
|
1240
|
-
/**
|
|
1241
|
-
type
|
|
1242
|
-
|
|
1243
|
-
result?: TResult;
|
|
1071
|
+
/** Options for the `mount()` method. */
|
|
1072
|
+
type MountOptions<TContext, TNewContext> = {
|
|
1073
|
+
context: (ctx: TContext) => TNewContext;
|
|
1244
1074
|
};
|
|
1245
1075
|
/**
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
* - `TNextResult` — the typed result returned by `next()`, giving the handler type-safe access to downstream output.
|
|
1250
|
-
* - `TReturn` — the type the handler itself returns. Defaults to `TNextResult` but can be wider,
|
|
1251
|
-
* allowing plugins to transform or replace the result (e.g., error-recovery plugins returning a different type).
|
|
1076
|
+
* Resolves the initial builder type for a `.command()` call.
|
|
1077
|
+
* If TNameNested already exists in TCommands, the builder starts pre-populated with that command's types.
|
|
1078
|
+
* Otherwise, a fresh builder with default types is used.
|
|
1252
1079
|
*/
|
|
1253
|
-
type
|
|
1080
|
+
type InitialCommandBuilder<TProgramName extends string, TNameNested extends string, TParentPath extends string, TParentArgs extends PadroneSchema, TCommands extends [...AnyPadroneCommand[]], TParentContext> = [FindDirectChild<TCommands, TNameNested>] extends [never] ? PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, false, TParentContext> : FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? PadroneBuilder<TProgramName, TNameNested, TParentPath, E['~types']['argsSchema'], E['~types']['result'], E['~types']['commands'], TParentArgs, E['~types']['async'], E['~types']['context'], E['~types']['contextProvided']> : PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, false, TParentContext>;
|
|
1081
|
+
type AnyPadroneBuilder = InitialCommandBuilder<string, string, string, any, [...AnyPadroneCommand[]], any>;
|
|
1254
1082
|
/**
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1257
|
-
*
|
|
1258
|
-
* Type parameters:
|
|
1259
|
-
* - `TArgs` — the validated arguments type (output of the args schema). Provides typed `ctx.args` in the execute phase
|
|
1260
|
-
* and typed `args` in the validate result from `next()`.
|
|
1261
|
-
* - `TResult` — the command's return type. Provides typed `result` in execute/error/shutdown phases.
|
|
1262
|
-
*
|
|
1263
|
-
* When registered inline on a builder, these are inferred from the command's types automatically.
|
|
1264
|
-
* For reusable plugins that work with any command, use `PadronePlugin<any, any>`.
|
|
1265
|
-
*
|
|
1266
|
-
* Each phase handler receives a context and a `next()` function (onion/middleware pattern):
|
|
1267
|
-
* - Call `next()` to proceed to the next plugin or the core operation.
|
|
1268
|
-
* - Return without calling `next()` to short-circuit.
|
|
1269
|
-
* - Wrap `next()` in try/catch for error handling.
|
|
1270
|
-
* - Modify context fields before `next()` to alter inputs.
|
|
1271
|
-
* - Transform the return value of `next()` to alter outputs.
|
|
1083
|
+
* Like InitialCommandBuilder but uses `any` for args in the fresh case.
|
|
1084
|
+
* Used as the default for TBuilder when no builderFn is provided.
|
|
1272
1085
|
*/
|
|
1273
|
-
type
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
*
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1086
|
+
type DefaultCommandBuilder<TProgramName extends string, TNameNested extends string, TParentPath extends string, TParentArgs extends PadroneSchema, TCommands extends [...AnyPadroneCommand[]], TParentContext> = [FindDirectChild<TCommands, TNameNested>] extends [never] ? PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, false, TParentContext> : FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand ? PadroneBuilder<TProgramName, TNameNested, TParentPath, E['~types']['argsSchema'], E['~types']['result'], E['~types']['commands'], TParentArgs, E['~types']['async'], E['~types']['context'], E['~types']['contextProvided']> : PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, false, TParentContext>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Conditional type that returns either PadroneBuilder or PadroneProgram based on TReturn.
|
|
1089
|
+
* Used to avoid repetition in PadroneBuilderMethods return types.
|
|
1090
|
+
*/
|
|
1091
|
+
type BuilderOrProgram<TReturn extends 'builder' | 'program', TProgramName extends string, TName extends string, TParentName extends string, TArgs extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentArgs extends PadroneSchema, TAsync extends boolean, TContext, TContextProvided = unknown> = TReturn extends 'builder' ? PadroneBuilder<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided> : PadroneProgram<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Base builder methods shared between PadroneBuilder and PadroneProgram.
|
|
1094
|
+
* These methods are used for defining command structure (arguments, action, subcommands).
|
|
1095
|
+
*/
|
|
1096
|
+
type PadroneBuilderMethods<TProgramName extends string, TName extends string, TParentName extends string, TArgs extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentArgs extends PadroneSchema, TAsync extends boolean, TContext, TContextProvided, /** The return type for builder methods - either PadroneBuilder or PadroneProgram */TReturn extends 'builder' | 'program'> = {
|
|
1097
|
+
/** Apply a build-time extension that transforms this builder/program. @category Builder */extend: <TResult extends CommandTypesBase>(extension: PadroneExtension<BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>, TResult>) => TResult; /** Register a runtime interceptor for lifecycle phases (parse, validate, execute, etc.). @category Builder */
|
|
1098
|
+
intercept: {
|
|
1099
|
+
/** Context-providing interceptor — extends context type. Rejects if required context is not satisfied. */<TInterceptor extends PadroneContextInterceptor<any, StandardSchemaV1.InferOutput<TArgs>, TRes, any>>(interceptor: TInterceptor): InterceptorRequiresCheck<TInterceptor, TContext & TContextProvided> extends true ? BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided & ExtractInterceptorContext<TInterceptor>> : InterceptorRequiresError; /** Plain interceptor — no context change. Rejects if required context is not satisfied. */
|
|
1100
|
+
<TInterceptor extends PadroneInterceptorFn<StandardSchemaV1.InferOutput<TArgs>, TRes, any>>(interceptor: TInterceptor): InterceptorRequiresCheck<TInterceptor, TContext & TContextProvided> extends true ? BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided> : InterceptorRequiresError; /** Register an interceptor with static metadata and a factory function. Context is strongly typed. */
|
|
1101
|
+
(meta: InterceptorMeta, factory: InterceptorFactory<StandardSchemaV1.InferOutput<TArgs>, TRes, TContext & TContextProvided>): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
1102
|
+
}; /** Set command metadata like title, description, version, hidden, deprecated, etc. @category Builder */
|
|
1103
|
+
configure: (config: PadroneCommandConfig) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>; /** Override the runtime adapter (process, IO, environment). @category Builder */
|
|
1104
|
+
runtime: (runtime: PadroneRuntime) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>; /** Mark this command as async, forcing all return types to be `Promise`-wrapped. @category Builder */
|
|
1105
|
+
async: () => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, true, TContext, TContextProvided>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Declare or transform the user-defined context type for this command.
|
|
1108
|
+
*
|
|
1109
|
+
* - Without a callback: narrows the context type (type-only, no runtime transform).
|
|
1110
|
+
* - With a callback: transforms the parent/current context into a new type. Chainable — multiple calls compose.
|
|
1111
|
+
*
|
|
1112
|
+
* Interceptor-provided context (`TContextProvided`) is preserved across `.context()` calls.
|
|
1113
|
+
* @category Builder
|
|
1114
|
+
*/
|
|
1115
|
+
context: {
|
|
1116
|
+
<TNewContext>(): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TNewContext, TContextProvided>;
|
|
1117
|
+
<TNewContext>(transform: (ctx: TContext) => TNewContext): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TNewContext, TContextProvided>;
|
|
1118
|
+
}; /** Define the argument/option schema for this command. Accepts a Standard Schema or a function that extends the parent schema. @category Builder */
|
|
1119
|
+
arguments: <TNewArgs extends PadroneSchema = PadroneSchema<void>, TMeta extends GetArgsMeta<TNewArgs> = GetArgsMeta<TNewArgs>>(schema?: TNewArgs | ((parentSchema: TParentArgs) => TNewArgs), meta?: TMeta) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TNewArgs, TRes, TCommands, TParentArgs, OrAsyncMeta<OrAsync<TAsync, TNewArgs>, TMeta>, TContext, TContextProvided>; /** Set the handler function that runs when this command is executed. @category Builder */
|
|
1120
|
+
action: <TNewRes>(handler?: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext<TContext & TContextProvided>, base: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext<TContext & TContextProvided>) => TRes) => TNewRes) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TNewRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>; /** Wrap an external CLI tool, delegating execution to a shell command. @category Builder */
|
|
1121
|
+
wrap: <TWrapArgs extends PadroneSchema = TArgs>(config: WrapConfig<TArgs, TWrapArgs>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, Promise<WrapResult>, TCommands, TParentArgs, TAsync, TContext, TContextProvided>; /** Add or override a subcommand. Pass a builder function to define its schema, action, and nested commands. @category Builder */
|
|
1122
|
+
command: <TNameNested extends string, TAliases extends string[] = [], TBuilder extends CommandTypesBase = DefaultCommandBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, TArgs, TCommands, TContext & TContextProvided>>(name: TNameNested | readonly [TNameNested, ...TAliases], builderFn?: (builder: InitialCommandBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, TArgs, TCommands, TContext & TContextProvided>) => TBuilder) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands extends [] ? [WithAliases<TBuilder['~types']['command'], TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<TBuilder['~types']['command'], TAliases>] : ReplaceOrAppendCommand<TCommands, TNameNested, WithAliases<TBuilder['~types']['command'], ResolvedAliases<TCommands, TNameNested, TAliases>>>, TParentArgs, TAsync, TContext, TContextProvided>; /** Mount an existing program as a subcommand, optionally transforming the context. @category Builder */
|
|
1123
|
+
mount: {
|
|
1124
|
+
<TNameNested extends string, TAliases extends string[] = [], TProgram extends CommandTypesBase = CommandTypesBase>(name: TNameNested | readonly [TNameNested, ...TAliases], program: TProgram): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands extends [] ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TContext & TContextProvided>, TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TContext & TContextProvided>, TAliases>] : ReplaceOrAppendCommand<TCommands, TNameNested, WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TContext & TContextProvided>, ResolvedAliases<TCommands, TNameNested, TAliases>>>, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
1125
|
+
<TNameNested extends string, TAliases extends string[] = [], TProgram extends CommandTypesBase = CommandTypesBase, TNewContext = unknown>(name: TNameNested | readonly [TNameNested, ...TAliases], program: TProgram, options: MountOptions<TContext & TContextProvided, TNewContext>): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands extends [] ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TNewContext>, TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TNewContext>, TAliases>] : ReplaceOrAppendCommand<TCommands, TNameNested, WithAliases<PadroneCommand<TNameNested, FullCommandName<TName, TParentName>, TProgram['~types']['command']['~types']['argsSchema'], TProgram['~types']['command']['~types']['result'], RepathCommands<TProgram['~types']['command']['~types']['commands'], FullCommandName<TNameNested, FullCommandName<TName, TParentName>>>, [], TProgram['~types']['command']['~types']['async'], TNewContext>, ResolvedAliases<TCommands, TNameNested, TAliases>>>, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
1126
|
+
}; /** @deprecated Internal use only */
|
|
1127
|
+
'~types': {
|
|
1128
|
+
programName: TProgramName;
|
|
1129
|
+
name: TName;
|
|
1130
|
+
parentName: TParentName;
|
|
1131
|
+
path: FullCommandName<TName, TParentName>;
|
|
1132
|
+
aliases: [];
|
|
1133
|
+
argsSchema: TArgs;
|
|
1134
|
+
result: TRes;
|
|
1135
|
+
commands: TCommands;
|
|
1136
|
+
async: TAsync;
|
|
1137
|
+
context: TContext;
|
|
1138
|
+
contextProvided: TContextProvided;
|
|
1139
|
+
command: PadroneCommand<TName, TParentName, TArgs, TRes, TCommands, [], TAsync, TContext, TContextProvided>;
|
|
1140
|
+
};
|
|
1304
1141
|
};
|
|
1142
|
+
type PadroneBuilder<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentArgs extends PadroneSchema = PadroneSchema<void>, TAsync extends boolean = false, TContext = unknown, TContextProvided = unknown> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided, 'builder'>;
|
|
1143
|
+
type PadroneProgram<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentArgs extends PadroneSchema = PadroneSchema<void>, TAsync extends boolean = false, TContext = unknown, TContextProvided = unknown> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided, 'program'> & {
|
|
1144
|
+
/** Execute a command by name with pre-validated args (skips parsing and validation). @category Execution */run: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(name: TCommand | SafeString, args: NoInfer<GetArguments<'in', PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>>, prefs?: ContextParam<TContext>) => PadroneCommandResult<PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>; /** Parse and execute a string input through the full interceptor pipeline. @category Execution */
|
|
1145
|
+
eval: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(input: TCommand | SafeString, prefs?: PadroneEvalPreferences & ContextParam<TContext>) => MaybePromiseCommandResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>, PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']>; /** Parse and execute from `process.argv` through the full interceptor pipeline. @category Execution */
|
|
1146
|
+
cli: (prefs?: PadroneCliPreferences & ContextParam<TContext>) => MaybePromiseCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>, TAsync>; /** Parse and validate input without executing the action. @category Execution */
|
|
1147
|
+
parse: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, false>>(input?: TCommand | SafeString) => MaybePromise<PadroneParseResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>, PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']>; /** Serialize args back into a CLI string. @category Utility */
|
|
1148
|
+
stringify: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command?: TCommand | SafeString, args?: GetArguments<'out', PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>) => string; /** Look up a command definition by name. @category Utility */
|
|
1149
|
+
find: <const TFind extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command: TFind | SafeString) => PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TFind> | undefined; /** Get a structured API representation of all commands. @category Utility */
|
|
1150
|
+
api: () => PadroneAPI<PadroneCommand<'', '', TArgs, TRes, TCommands>>; /** Start an interactive REPL session. @category Execution */
|
|
1151
|
+
repl: (options?: PadroneReplPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>) => AsyncIterable<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>> & {
|
|
1152
|
+
drain: () => Promise<PadroneDrainResult<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>[]>>;
|
|
1153
|
+
}; /** Export as an AI SDK tool. @category Utility */
|
|
1154
|
+
tool: () => Tool<{
|
|
1155
|
+
command: string;
|
|
1156
|
+
}>; /** Generate help text for a command. @category Utility */
|
|
1157
|
+
help: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(command?: TCommand, prefs?: HelpPreferences) => string; /** Generate shell completion script. @category Utility */
|
|
1158
|
+
completion: (shell?: 'bash' | 'zsh' | 'fish' | 'powershell') => Promise<string>; /** Start a Model Context Protocol server. @category Server */
|
|
1159
|
+
mcp: (prefs?: PadroneMcpPreferences) => Promise<void>; /** Start a REST HTTP server with OpenAPI docs. @category Server */
|
|
1160
|
+
serve: (prefs?: PadroneServePreferences) => Promise<void>; /** Read-only metadata about the program (name, version, description, commands, etc.). @category Utility */
|
|
1161
|
+
info: PadroneProgramMeta<TProgramName>;
|
|
1162
|
+
};
|
|
1163
|
+
type AnyPadroneProgram = PadroneProgram<string, string, string, any, any, [...AnyPadroneCommand[]]>;
|
|
1164
|
+
/**
|
|
1165
|
+
* A build-time extension that transforms a builder/program.
|
|
1166
|
+
* Extensions can add commands, arguments, interceptors, configure settings, etc.
|
|
1167
|
+
*
|
|
1168
|
+
* Use with `.extend(extension)`:
|
|
1169
|
+
* ```ts
|
|
1170
|
+
* const withAuth = (b) => b.arguments(authSchema).command('login', ...)
|
|
1171
|
+
* program.extend(withAuth)
|
|
1172
|
+
* ```
|
|
1173
|
+
*/
|
|
1174
|
+
type PadroneExtension<TIn extends CommandTypesBase = CommandTypesBase, TOut extends CommandTypesBase = TIn> = (builder: TIn) => TOut;
|
|
1175
|
+
type DefaultArgs = Record<string, unknown> | void;
|
|
1305
1176
|
//#endregion
|
|
1306
|
-
export {
|
|
1307
|
-
//# sourceMappingURL=
|
|
1177
|
+
export { PadroneProgressOptions as $, InterceptorStartContext as A, WithInterceptor as B, InterceptorExecuteResult as C, InterceptorParseResult as D, InterceptorParseContext as E, PadroneInterceptorFn as F, PadroneServePreferences as G, PadroneSchema as H, Drained as I, InteractivePromptConfig as J, PadroneMcpPreferences as K, PickCommandByName as L, InterceptorValidateResult as M, PadroneContextInterceptor as N, InterceptorPhases as O, PadroneInterceptor as P, PadroneProgressIndicator as Q, PossibleCommands as R, InterceptorExecuteContext as S, InterceptorMeta as T, WrapConfig as U, AsyncPadroneSchema as V, WrapResult as W, PadroneBarChar as X, PadroneBarAnimation as Y, PadroneBarConfig as Z, ExtractInterceptorRequires as _, PadroneProgram as a, PadroneSpinnerPreset as at, InterceptorErrorContext as b, PadroneParseResult as c, CommandTypesBase as d, PadroneProgressShow as et, GetArgsMeta as f, ExtractInterceptorContext as g, PadroneProgramMeta as h, PadroneExtension as i, PadroneSpinnerConfig as it, InterceptorValidateContext as j, InterceptorShutdownContext as k, PadroneReplPreferences as l, PadroneCommand as m, AnyPadroneProgram as n, PadroneRuntime as nt, PadroneCommandResult as o, REPL_SIGINT as ot, PadroneActionContext as p, InteractiveMode as q, PadroneBuilder as r, PadroneSignal as rt, PadroneDrainResult as s, AnyPadroneBuilder as t, PadroneProgressUpdate as tt, AnyPadroneCommand as u, InterceptorBaseContext as v, InterceptorFactory as w, InterceptorErrorResult as x, InterceptorDefBuilder as y, WithCommand as z };
|
|
1178
|
+
//# sourceMappingURL=index-BaU3X6dY.d.mts.map
|