padrone 1.5.0 → 1.7.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 +44 -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-DA4KzK1M.mjs} +26 -3
- package/dist/errors-DA4KzK1M.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-BtxLgrF_.mjs} +190 -43
- package/dist/help-BtxLgrF_.mjs.map +1 -0
- package/dist/{types-Ch8Mk6Qb.d.mts → index-D6-7dz0l.d.mts} +634 -745
- package/dist/index-D6-7dz0l.d.mts.map +1 -0
- package/dist/index.d.mts +869 -36
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3884 -1699
- package/dist/index.mjs.map +1 -1
- package/dist/{mcp-mLWIdUIu.mjs → mcp-6-Jw4Bpq.mjs} +13 -15
- package/dist/mcp-6-Jw4Bpq.mjs.map +1 -0
- package/dist/{serve-B0u43DK7.mjs → serve-YVTPzBCl.mjs} +12 -14
- package/dist/serve-YVTPzBCl.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 +301 -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 +146 -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 +44 -0
- package/src/extension/ink.ts +93 -0
- package/src/extension/interactive.ts +106 -0
- package/src/extension/logger.ts +262 -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 +115 -30
- package/src/{formatter.ts → output/formatter.ts} +124 -176
- package/src/{help.ts → output/help.ts} +22 -8
- package/src/output/output-indicator.ts +87 -0
- package/src/output/primitives.ts +335 -0
- package/src/output/styling.ts +221 -0
- 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 +718 -0
- package/src/types/command.ts +157 -0
- package/src/types/index.ts +60 -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
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { a as getJsonSchema, i as extractSchemaMetadata } from "./args-Cnq0nwSM.mjs";
|
|
2
|
+
import { a as readStreamAsText } from "./stream-DC4H8YTx.mjs";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/runtime.ts
|
|
16
|
+
/**
|
|
17
|
+
* Sentinel value returned by the terminal REPL session when Ctrl+C is pressed.
|
|
18
|
+
* Distinguished from empty string (user pressed enter) and null (EOF/Ctrl+D).
|
|
19
|
+
*/
|
|
20
|
+
const REPL_SIGINT = Symbol("REPL_SIGINT");
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/default-runtime.ts
|
|
23
|
+
/**
|
|
24
|
+
* Default terminal prompt implementation powered by Enquirer.
|
|
25
|
+
* Lazily imported to avoid loading Enquirer when not needed.
|
|
26
|
+
*/
|
|
27
|
+
async function defaultTerminalPrompt(config) {
|
|
28
|
+
const Enquirer = (await import("enquirer")).default;
|
|
29
|
+
const question = {
|
|
30
|
+
type: config.type,
|
|
31
|
+
name: config.name,
|
|
32
|
+
message: config.message
|
|
33
|
+
};
|
|
34
|
+
if (config.default !== void 0) question.initial = config.default;
|
|
35
|
+
if (config.choices) question.choices = config.choices.map((c) => ({
|
|
36
|
+
name: String(c.value),
|
|
37
|
+
message: c.label
|
|
38
|
+
}));
|
|
39
|
+
return (await Enquirer.prompt(question))[config.name];
|
|
40
|
+
}
|
|
41
|
+
function createTerminalReplSession(config) {
|
|
42
|
+
let history = config.history ? [...config.history] : [];
|
|
43
|
+
let currentCompleter = config.completer;
|
|
44
|
+
return {
|
|
45
|
+
set completer(fn) {
|
|
46
|
+
currentCompleter = fn;
|
|
47
|
+
},
|
|
48
|
+
async question(prompt) {
|
|
49
|
+
const { createInterface } = await import("node:readline");
|
|
50
|
+
const opts = {
|
|
51
|
+
input: process.stdin,
|
|
52
|
+
output: process.stdout,
|
|
53
|
+
terminal: true,
|
|
54
|
+
history: [...history],
|
|
55
|
+
historySize: Math.max(history.length, 1e3)
|
|
56
|
+
};
|
|
57
|
+
if (currentCompleter) opts.completer = currentCompleter;
|
|
58
|
+
const rl = createInterface(opts);
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
let resolved = false;
|
|
61
|
+
const settle = (value) => {
|
|
62
|
+
if (resolved) return;
|
|
63
|
+
resolved = true;
|
|
64
|
+
rl.close();
|
|
65
|
+
resolve(value);
|
|
66
|
+
};
|
|
67
|
+
rl.question(prompt, (answer) => {
|
|
68
|
+
if (Array.isArray(rl.history)) history = [...rl.history];
|
|
69
|
+
settle(answer);
|
|
70
|
+
});
|
|
71
|
+
rl.once("SIGINT", () => {
|
|
72
|
+
process.stdout.write("\n");
|
|
73
|
+
settle(REPL_SIGINT);
|
|
74
|
+
});
|
|
75
|
+
rl.once("close", () => {
|
|
76
|
+
process.stdout.write("\n");
|
|
77
|
+
settle(null);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
close() {}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Auto-detect interactive mode when not explicitly set.
|
|
86
|
+
* Returns 'disabled' in CI environments or non-TTY contexts, 'supported' otherwise.
|
|
87
|
+
*/
|
|
88
|
+
function detectInteractiveMode() {
|
|
89
|
+
if (typeof process === "undefined") return "disabled";
|
|
90
|
+
if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) return "disabled";
|
|
91
|
+
if (!process.stdout?.isTTY) return "disabled";
|
|
92
|
+
return "supported";
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a default stdin reader from `process.stdin`.
|
|
96
|
+
* Only created when a command actually declares a `stdin` meta field.
|
|
97
|
+
*/
|
|
98
|
+
function createDefaultStdin() {
|
|
99
|
+
return {
|
|
100
|
+
get isTTY() {
|
|
101
|
+
if (typeof process === "undefined") return true;
|
|
102
|
+
return process.stdin?.isTTY === true;
|
|
103
|
+
},
|
|
104
|
+
async text() {
|
|
105
|
+
if (typeof process === "undefined") return "";
|
|
106
|
+
return readStreamAsText(process.stdin);
|
|
107
|
+
},
|
|
108
|
+
async *lines() {
|
|
109
|
+
if (typeof process === "undefined") return;
|
|
110
|
+
const { createInterface } = await import("node:readline");
|
|
111
|
+
const rl = createInterface({ input: process.stdin });
|
|
112
|
+
try {
|
|
113
|
+
for await (const line of rl) yield line;
|
|
114
|
+
} finally {
|
|
115
|
+
rl.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Default signal listener that wires to `process.on(signal)`.
|
|
122
|
+
* Returns an unsubscribe function that removes all listeners.
|
|
123
|
+
*/
|
|
124
|
+
function defaultOnSignal(callback) {
|
|
125
|
+
if (typeof process === "undefined") return () => {};
|
|
126
|
+
const signals = [
|
|
127
|
+
"SIGINT",
|
|
128
|
+
"SIGTERM",
|
|
129
|
+
"SIGHUP"
|
|
130
|
+
];
|
|
131
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const sig of signals) {
|
|
133
|
+
const handler = () => callback(sig);
|
|
134
|
+
handlers.set(sig, handler);
|
|
135
|
+
process.on(sig, handler);
|
|
136
|
+
}
|
|
137
|
+
return () => {
|
|
138
|
+
for (const [sig, handler] of handlers) process.removeListener(sig, handler);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates the default Node.js/Bun runtime.
|
|
143
|
+
*/
|
|
144
|
+
function defaultExit(code) {
|
|
145
|
+
if (typeof process !== "undefined") process.exit(code);
|
|
146
|
+
throw new Error(`Exit with code ${code}`);
|
|
147
|
+
}
|
|
148
|
+
function getTerminalInfo() {
|
|
149
|
+
if (typeof process === "undefined") return void 0;
|
|
150
|
+
return {
|
|
151
|
+
get columns() {
|
|
152
|
+
return process.stdout?.columns;
|
|
153
|
+
},
|
|
154
|
+
get isTTY() {
|
|
155
|
+
return process.stdout?.isTTY === true;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function createDefaultRuntime() {
|
|
160
|
+
return {
|
|
161
|
+
output: (...args) => console.log(...args),
|
|
162
|
+
error: (text) => console.error(text),
|
|
163
|
+
argv: () => typeof process !== "undefined" ? process.argv.slice(2) : [],
|
|
164
|
+
env: () => typeof process !== "undefined" ? process.env : {},
|
|
165
|
+
format: "auto",
|
|
166
|
+
prompt: defaultTerminalPrompt,
|
|
167
|
+
interactive: detectInteractiveMode(),
|
|
168
|
+
onSignal: defaultOnSignal,
|
|
169
|
+
terminal: getTerminalInfo(),
|
|
170
|
+
exit: defaultExit
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the stdin abstraction: custom runtime stdin > default process.stdin.
|
|
175
|
+
* Returns `undefined` when no custom stdin is provided and process.stdin is not piped.
|
|
176
|
+
*/
|
|
177
|
+
function resolveStdin(partial) {
|
|
178
|
+
if (partial?.stdin) return partial.stdin;
|
|
179
|
+
const defaultStdin = createDefaultStdin();
|
|
180
|
+
if (defaultStdin.isTTY) return void 0;
|
|
181
|
+
return defaultStdin;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Like `resolveStdin`, but always returns a stdin source even when it's a TTY.
|
|
185
|
+
* Used for async streams which support interactive (non-piped) input.
|
|
186
|
+
*/
|
|
187
|
+
function resolveStdinAlways(partial) {
|
|
188
|
+
if (partial?.stdin) return partial.stdin;
|
|
189
|
+
return createDefaultStdin();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Merges a partial runtime with the default runtime.
|
|
193
|
+
*/
|
|
194
|
+
function resolveRuntime(partial) {
|
|
195
|
+
const defaults = createDefaultRuntime();
|
|
196
|
+
if (!partial) return defaults;
|
|
197
|
+
return {
|
|
198
|
+
output: partial.output ?? defaults.output,
|
|
199
|
+
error: partial.error ?? defaults.error,
|
|
200
|
+
argv: partial.argv ?? defaults.argv,
|
|
201
|
+
env: partial.env ?? defaults.env,
|
|
202
|
+
format: partial.format ?? defaults.format,
|
|
203
|
+
interactive: partial.interactive ?? defaults.interactive,
|
|
204
|
+
prompt: partial.prompt ?? defaults.prompt,
|
|
205
|
+
readLine: partial.readLine ?? defaults.readLine,
|
|
206
|
+
stdin: partial.stdin,
|
|
207
|
+
theme: partial.theme,
|
|
208
|
+
onSignal: partial.onSignal ?? defaults.onSignal,
|
|
209
|
+
terminal: partial.terminal ?? defaults.terminal,
|
|
210
|
+
exit: partial.exit ?? defaults.exit
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/core/commands.ts
|
|
215
|
+
var commands_exports = /* @__PURE__ */ __exportAll({
|
|
216
|
+
buildInputSchema: () => buildInputSchema,
|
|
217
|
+
buildReplCompleter: () => buildReplCompleter,
|
|
218
|
+
collectEndpoints: () => collectEndpoints,
|
|
219
|
+
commandSymbol: () => commandSymbol,
|
|
220
|
+
configKeys: () => configKeys,
|
|
221
|
+
findCommandByName: () => findCommandByName,
|
|
222
|
+
getCommand: () => getCommand,
|
|
223
|
+
getCommandRuntime: () => getCommandRuntime,
|
|
224
|
+
lazyResolver: () => lazyResolver,
|
|
225
|
+
mergeCommands: () => mergeCommands,
|
|
226
|
+
repathCommandTree: () => repathCommandTree,
|
|
227
|
+
resolveAllCommands: () => resolveAllCommands,
|
|
228
|
+
resolveCommand: () => resolveCommand,
|
|
229
|
+
serializeArgsToFlags: () => serializeArgsToFlags,
|
|
230
|
+
suggestSimilar: () => suggestSimilar
|
|
231
|
+
});
|
|
232
|
+
const lazyResolver = Symbol("lazyResolver");
|
|
233
|
+
/** Resolves a lazy command in place by calling its stored resolver. No-op if already resolved. */
|
|
234
|
+
function resolveCommand(cmd) {
|
|
235
|
+
const resolver = cmd[lazyResolver];
|
|
236
|
+
if (resolver) {
|
|
237
|
+
delete cmd[lazyResolver];
|
|
238
|
+
resolver(cmd);
|
|
239
|
+
}
|
|
240
|
+
return cmd;
|
|
241
|
+
}
|
|
242
|
+
/** Recursively resolves a command and all its descendants. */
|
|
243
|
+
function resolveAllCommands(cmd) {
|
|
244
|
+
resolveCommand(cmd);
|
|
245
|
+
if (cmd.commands) for (const sub of cmd.commands) resolveAllCommands(sub);
|
|
246
|
+
}
|
|
247
|
+
/** Extracts the underlying command from a program/builder and resolves the full command tree. */
|
|
248
|
+
function getCommand(program) {
|
|
249
|
+
const cmd = commandSymbol in program ? program[commandSymbol] : program;
|
|
250
|
+
resolveAllCommands(cmd);
|
|
251
|
+
return cmd;
|
|
252
|
+
}
|
|
253
|
+
const commandSymbol = Symbol("padrone_command");
|
|
254
|
+
/** Config keys that are merged when overriding a command. */
|
|
255
|
+
const configKeys = [
|
|
256
|
+
"title",
|
|
257
|
+
"description",
|
|
258
|
+
"version",
|
|
259
|
+
"deprecated",
|
|
260
|
+
"hidden",
|
|
261
|
+
"mutation",
|
|
262
|
+
"needsApproval"
|
|
263
|
+
];
|
|
264
|
+
/**
|
|
265
|
+
* Merges an existing command with an override.
|
|
266
|
+
* - Config fields are shallow-merged (new overrides old).
|
|
267
|
+
* - Action, arguments, meta, config schema, env schema are taken from the override if set.
|
|
268
|
+
* - Subcommands are recursively merged by name.
|
|
269
|
+
*/
|
|
270
|
+
function mergeCommands(existing, override) {
|
|
271
|
+
resolveCommand(existing);
|
|
272
|
+
resolveCommand(override);
|
|
273
|
+
const merged = { ...existing };
|
|
274
|
+
for (const key of configKeys) if (override[key] !== void 0) merged[key] = override[key];
|
|
275
|
+
if (override.action !== existing.action) merged.action = override.action;
|
|
276
|
+
if (override.argsSchema !== existing.argsSchema) merged.argsSchema = override.argsSchema;
|
|
277
|
+
if (override.meta !== existing.meta) merged.meta = override.meta;
|
|
278
|
+
if (override.isAsync !== existing.isAsync) merged.isAsync = override.isAsync || existing.isAsync;
|
|
279
|
+
if (override.runtime !== existing.runtime) merged.runtime = override.runtime;
|
|
280
|
+
if (override.interceptors !== existing.interceptors) merged.interceptors = override.interceptors;
|
|
281
|
+
if (override.aliases !== existing.aliases) merged.aliases = override.aliases;
|
|
282
|
+
if (override.commands) {
|
|
283
|
+
const baseCommands = [...existing.commands || []];
|
|
284
|
+
for (const overrideChild of override.commands) {
|
|
285
|
+
const existingIndex = baseCommands.findIndex((c) => c.name === overrideChild.name);
|
|
286
|
+
if (existingIndex >= 0) baseCommands[existingIndex] = mergeCommands(baseCommands[existingIndex], overrideChild);
|
|
287
|
+
else baseCommands.push(overrideChild);
|
|
288
|
+
}
|
|
289
|
+
merged.commands = baseCommands;
|
|
290
|
+
}
|
|
291
|
+
return merged;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Resolves the runtime for a command by walking up the parent chain.
|
|
295
|
+
* Returns a fully resolved runtime with all defaults filled in.
|
|
296
|
+
*/
|
|
297
|
+
function getCommandRuntime(cmd) {
|
|
298
|
+
let current = cmd;
|
|
299
|
+
while (current) {
|
|
300
|
+
if (current.runtime) return resolveRuntime(current.runtime);
|
|
301
|
+
current = current.parent;
|
|
302
|
+
}
|
|
303
|
+
return resolveRuntime();
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Recursively re-paths a command tree under a new parent path, updating parent references.
|
|
307
|
+
*/
|
|
308
|
+
function repathCommandTree(cmd, newName, parentPath, parent) {
|
|
309
|
+
resolveCommand(cmd);
|
|
310
|
+
const newPath = parentPath ? `${parentPath} ${newName}` : newName;
|
|
311
|
+
const remounted = {
|
|
312
|
+
...cmd,
|
|
313
|
+
name: newName,
|
|
314
|
+
path: newPath,
|
|
315
|
+
parent,
|
|
316
|
+
version: void 0
|
|
317
|
+
};
|
|
318
|
+
if (cmd.commands?.length) remounted.commands = cmd.commands.map((child) => repathCommandTree(child, child.name, newPath, remounted));
|
|
319
|
+
return remounted;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Builds a completer function for the REPL from the command tree.
|
|
323
|
+
* Completes command names, subcommand names, option names (--foo), and aliases (-f).
|
|
324
|
+
* Also includes dot-prefixed built-in REPL commands (.exit, .clear, .scope, .help, .history).
|
|
325
|
+
*/
|
|
326
|
+
function buildReplCompleter(rootCommand, builtins) {
|
|
327
|
+
resolveAllCommands(rootCommand);
|
|
328
|
+
return (line) => {
|
|
329
|
+
const parts = line.trimStart().split(/\s+/);
|
|
330
|
+
const lastPart = parts[parts.length - 1] ?? "";
|
|
331
|
+
if (lastPart.startsWith(".")) {
|
|
332
|
+
const dotCmds = [
|
|
333
|
+
".exit",
|
|
334
|
+
".clear",
|
|
335
|
+
".help",
|
|
336
|
+
".history"
|
|
337
|
+
];
|
|
338
|
+
if (rootCommand.commands?.some((c) => c.commands?.length) || builtins.inScope) dotCmds.push(".scope");
|
|
339
|
+
const hits = dotCmds.filter((c) => c.startsWith(lastPart));
|
|
340
|
+
return [hits.length ? hits : dotCmds, lastPart];
|
|
341
|
+
}
|
|
342
|
+
if (lastPart.startsWith("-")) {
|
|
343
|
+
const commandParts = parts.slice(0, -1).filter((p) => !p.startsWith("-"));
|
|
344
|
+
let targetCommand = rootCommand;
|
|
345
|
+
for (const part of commandParts) {
|
|
346
|
+
resolveCommand(targetCommand);
|
|
347
|
+
const sub = targetCommand.commands?.find((c) => c.name === part || c.aliases?.includes(part));
|
|
348
|
+
if (sub) {
|
|
349
|
+
resolveCommand(sub);
|
|
350
|
+
targetCommand = sub;
|
|
351
|
+
} else break;
|
|
352
|
+
}
|
|
353
|
+
const options = [];
|
|
354
|
+
if (targetCommand.argsSchema) try {
|
|
355
|
+
const argsMeta = targetCommand.meta?.fields;
|
|
356
|
+
const { flags, aliases } = extractSchemaMetadata(targetCommand.argsSchema, argsMeta, targetCommand.meta?.autoAlias);
|
|
357
|
+
const jsonSchema = getJsonSchema(targetCommand.argsSchema);
|
|
358
|
+
if (jsonSchema.type === "object" && jsonSchema.properties) {
|
|
359
|
+
for (const key of Object.keys(jsonSchema.properties)) options.push(`--${key}`);
|
|
360
|
+
for (const flag of Object.keys(flags)) options.push(`-${flag}`);
|
|
361
|
+
for (const alias of Object.keys(aliases)) options.push(`--${alias}`);
|
|
362
|
+
}
|
|
363
|
+
} catch {}
|
|
364
|
+
options.push("--help", "-h");
|
|
365
|
+
const hits = options.filter((o) => o.startsWith(lastPart));
|
|
366
|
+
return [hits.length ? hits : options, lastPart];
|
|
367
|
+
}
|
|
368
|
+
const commandParts = parts.filter((p) => !p.startsWith("-"));
|
|
369
|
+
let targetCommand = rootCommand;
|
|
370
|
+
for (let i = 0; i < commandParts.length - 1; i++) {
|
|
371
|
+
resolveCommand(targetCommand);
|
|
372
|
+
const sub = targetCommand.commands?.find((c) => c.name === commandParts[i] || c.aliases?.includes(commandParts[i]));
|
|
373
|
+
if (sub) {
|
|
374
|
+
resolveCommand(sub);
|
|
375
|
+
targetCommand = sub;
|
|
376
|
+
} else break;
|
|
377
|
+
}
|
|
378
|
+
const candidates = [];
|
|
379
|
+
if (targetCommand.commands) {
|
|
380
|
+
for (const cmd of targetCommand.commands) if (!cmd.hidden) {
|
|
381
|
+
candidates.push(cmd.name);
|
|
382
|
+
if (cmd.aliases) candidates.push(...cmd.aliases);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (targetCommand === rootCommand) {
|
|
386
|
+
candidates.push(".help", ".exit", ".clear", ".history");
|
|
387
|
+
if (rootCommand.commands?.some((c) => c.commands?.length) || builtins.inScope) candidates.push(".scope");
|
|
388
|
+
if (builtins.inScope) candidates.push("..");
|
|
389
|
+
}
|
|
390
|
+
const hits = candidates.filter((c) => c.startsWith(lastPart));
|
|
391
|
+
return [hits.length ? hits : candidates, lastPart];
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Computes the Levenshtein edit distance between two strings.
|
|
396
|
+
*/
|
|
397
|
+
function levenshtein(a, b) {
|
|
398
|
+
const m = a.length;
|
|
399
|
+
const n = b.length;
|
|
400
|
+
const dp = Array.from({ length: n + 1 }, (_, i) => i);
|
|
401
|
+
for (let i = 1; i <= m; i++) {
|
|
402
|
+
let prev = dp[0];
|
|
403
|
+
dp[0] = i;
|
|
404
|
+
for (let j = 1; j <= n; j++) {
|
|
405
|
+
const temp = dp[j];
|
|
406
|
+
dp[j] = a[i - 1] === b[j - 1] ? prev : 1 + Math.min(prev, dp[j], dp[j - 1]);
|
|
407
|
+
prev = temp;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return dp[n];
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Finds close matches from a list of candidates using Levenshtein distance
|
|
414
|
+
* and prefix/substring matching (for inputs longer than 3 characters).
|
|
415
|
+
* Returns up to 3 matching candidate names (raw, unformatted).
|
|
416
|
+
*/
|
|
417
|
+
function suggestSimilar(input, candidates) {
|
|
418
|
+
if (candidates.length === 0) return [];
|
|
419
|
+
const lower = input.toLowerCase();
|
|
420
|
+
const matches = [];
|
|
421
|
+
for (const candidate of candidates) {
|
|
422
|
+
const candidateLower = candidate.toLowerCase();
|
|
423
|
+
if (candidateLower === lower) continue;
|
|
424
|
+
const dist = levenshtein(lower, candidateLower);
|
|
425
|
+
const maxLen = Math.max(input.length, candidate.length);
|
|
426
|
+
const threshold = Math.min(3, Math.max(1, Math.ceil(maxLen * .4)));
|
|
427
|
+
if (dist > 0 && dist <= threshold) matches.push({
|
|
428
|
+
candidate,
|
|
429
|
+
score: dist
|
|
430
|
+
});
|
|
431
|
+
else if (lower.length >= 3) {
|
|
432
|
+
if (candidateLower.startsWith(lower) || candidateLower.includes(lower)) matches.push({
|
|
433
|
+
candidate,
|
|
434
|
+
score: threshold + 1
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
matches.sort((a, b) => a.score - b.score);
|
|
439
|
+
return matches.slice(0, 3).map((m) => m.candidate);
|
|
440
|
+
}
|
|
441
|
+
function findCommandByName(name, commands) {
|
|
442
|
+
if (!commands) return void 0;
|
|
443
|
+
const foundByName = commands.find((cmd) => cmd.name === name);
|
|
444
|
+
if (foundByName) return resolveCommand(foundByName);
|
|
445
|
+
const foundByAlias = commands.find((cmd) => cmd.aliases?.includes(name));
|
|
446
|
+
if (foundByAlias) return resolveCommand(foundByAlias);
|
|
447
|
+
for (const cmd of commands) {
|
|
448
|
+
if (name.startsWith(`${cmd.name} `)) {
|
|
449
|
+
resolveCommand(cmd);
|
|
450
|
+
if (cmd.commands) {
|
|
451
|
+
const subCommand = findCommandByName(name.slice(cmd.name.length + 1), cmd.commands);
|
|
452
|
+
if (subCommand) return subCommand;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (cmd.aliases) {
|
|
456
|
+
for (const alias of cmd.aliases) if (name.startsWith(`${alias} `)) {
|
|
457
|
+
resolveCommand(cmd);
|
|
458
|
+
if (cmd.commands) {
|
|
459
|
+
const subCommand = findCommandByName(name.slice(alias.length + 1), cmd.commands);
|
|
460
|
+
if (subCommand) return subCommand;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/** Collect all actionable commands recursively. Hidden commands are excluded. */
|
|
467
|
+
function collectEndpoints(commands, prefix) {
|
|
468
|
+
if (!commands) return [];
|
|
469
|
+
const endpoints = [];
|
|
470
|
+
for (const cmd of commands) {
|
|
471
|
+
resolveCommand(cmd);
|
|
472
|
+
if (cmd.hidden) continue;
|
|
473
|
+
const path = cmd.name ? prefix ? `${prefix}.${cmd.name}` : cmd.name : prefix;
|
|
474
|
+
if (cmd.action || cmd.argsSchema) endpoints.push({
|
|
475
|
+
name: path,
|
|
476
|
+
command: cmd
|
|
477
|
+
});
|
|
478
|
+
if (cmd.commands?.length) endpoints.push(...collectEndpoints(cmd.commands, path));
|
|
479
|
+
}
|
|
480
|
+
return endpoints;
|
|
481
|
+
}
|
|
482
|
+
/** Build the JSON Schema for a command's arguments. */
|
|
483
|
+
function buildInputSchema(cmd) {
|
|
484
|
+
if (!cmd.argsSchema) return {
|
|
485
|
+
type: "object",
|
|
486
|
+
additionalProperties: false
|
|
487
|
+
};
|
|
488
|
+
try {
|
|
489
|
+
return getJsonSchema(cmd.argsSchema);
|
|
490
|
+
} catch {
|
|
491
|
+
return {
|
|
492
|
+
type: "object",
|
|
493
|
+
additionalProperties: false
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/** Serialize a record of args into CLI flag strings. */
|
|
498
|
+
function serializeArgsToFlags(args) {
|
|
499
|
+
const parts = [];
|
|
500
|
+
for (const [key, value] of Object.entries(args)) {
|
|
501
|
+
if (value === void 0) continue;
|
|
502
|
+
if (typeof value === "boolean") parts.push(value ? `--${key}` : `--no-${key}`);
|
|
503
|
+
else if (Array.isArray(value)) for (const v of value) parts.push(`--${key}=${String(v)}`);
|
|
504
|
+
else {
|
|
505
|
+
const strVal = String(value);
|
|
506
|
+
parts.push(strVal.includes(" ") ? `--${key}="${strVal}"` : `--${key}=${strVal}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return parts;
|
|
510
|
+
}
|
|
511
|
+
//#endregion
|
|
512
|
+
export { resolveStdin as _, commands_exports as a, getCommandRuntime as c, repathCommandTree as d, resolveAllCommands as f, createTerminalReplSession as g, suggestSimilar as h, commandSymbol as i, lazyResolver as l, serializeArgsToFlags as m, buildReplCompleter as n, findCommandByName as o, resolveCommand as p, collectEndpoints as r, getCommand as s, buildInputSchema as t, mergeCommands as u, resolveStdinAlways as v, REPL_SIGINT as y };
|
|
513
|
+
|
|
514
|
+
//# sourceMappingURL=commands-B_gufyR9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands-B_gufyR9.mjs","names":[],"sources":["../src/core/runtime.ts","../src/core/default-runtime.ts","../src/core/commands.ts"],"sourcesContent":["import type { ColorConfig, ColorTheme } from '../output/colorizer.ts';\nimport type { HelpFormat } from '../output/formatter.ts';\n\n/** Process signals that Padrone can handle for graceful shutdown. */\nexport type PadroneSignal = 'SIGINT' | 'SIGTERM' | 'SIGHUP';\n\n/** Value accepted by `PadroneProgressIndicator.update()`. */\nexport type PadroneProgressUpdate = string | number | { message?: string; progress?: number; indeterminate?: boolean; time?: boolean };\n\n/**\n * A progress indicator instance (spinner, progress bar, etc).\n * Created by the runtime's `progress` factory and used to show loading state during command execution.\n */\nexport type PadroneProgressIndicator = {\n /**\n * Update the indicator.\n * - `string` — update the displayed message.\n * - `number` — set progress ratio (0–1). Values outside this range are clamped.\n * - `{ message?, progress?, indeterminate? }` — update message, progress, or both.\n *\n * Set `indeterminate: true` to force the bar into indeterminate mode (shows animation, no percentage).\n * This makes the bar visible even in `show: 'auto'` mode without providing a number.\n * Omitting `progress` (or passing a string) leaves the bar in its current state.\n * Setting `progress` when bar mode is not enabled is a no-op for the bar portion.\n *\n * Set `time: true` to start the elapsed timer on demand (useful when `time` was not set in options).\n * Set `time: false` to hide the elapsed timer.\n */\n update: (value: PadroneProgressUpdate) => void;\n /** Mark as succeeded and stop. Pass `null` to stop without rendering a final message. */\n succeed: (message?: string | null, options?: { indicator?: string }) => void;\n /** Mark as failed and stop. Pass `null` to stop without rendering a final message. */\n fail: (message?: string | null, options?: { indicator?: string }) => void;\n /** Stop without success/fail status. */\n stop: () => void;\n /** Temporarily hide the indicator so other output can be written cleanly. */\n pause: () => void;\n /** Redraw the indicator after a `pause()`. */\n resume: () => void;\n};\n\n/** Controls when a progress element (spinner or bar) is visible. */\nexport type PadroneProgressShow = 'auto' | 'always' | 'never';\n\n/** Built-in spinner presets. */\nexport type PadroneSpinnerPreset = 'dots' | 'line' | 'arc' | 'bounce';\n\n/**\n * Spinner configuration for progress indicators.\n * - A preset name (e.g., `'dots'`) to use built-in frames.\n * - `true` — default spinner with `show: 'always'` (visible even alongside a bar).\n * - An object with custom `frames`, `interval`, and/or `show`.\n * - `false` to disable the spinner (`show: 'never'`).\n *\n * Default `show` is `'auto'`: visible when the bar is not shown.\n */\nexport type PadroneSpinnerConfig = PadroneSpinnerPreset | boolean | { frames?: string[]; interval?: number; show?: PadroneProgressShow };\n\n/**\n * Options passed to the runtime's `progress` factory.\n */\n/** Common fill/empty character pairs for progress bars. */\nexport type PadroneBarChar = '█' | '░' | '▓' | '▒' | '─' | '━' | '■' | '□' | '#' | '-' | '=' | '·' | '▰' | '▱' | (string & {});\n\n/**\n * Built-in indeterminate bar animation presets.\n * - `'bounce'` — a filled segment slides back and forth (default).\n * - `'slide'` — a filled segment slides left-to-right and wraps around.\n * - `'pulse'` — the entire bar fades in and out using gradient characters (`░▒▓█▓▒░`).\n */\nexport type PadroneBarAnimation = 'bounce' | 'slide' | 'pulse';\n\n/**\n * Progress bar configuration.\n */\nexport type PadroneBarConfig = {\n /** Total width of the bar in characters. Defaults to `20`. */\n width?: number;\n /** Character used for the filled portion of the bar. Defaults to `'█'`. */\n filled?: PadroneBarChar;\n /** Character used for the empty portion of the bar. Defaults to `'░'`. */\n empty?: PadroneBarChar;\n /** Indeterminate animation style. Defaults to `'bounce'`. */\n animation?: PadroneBarAnimation;\n /**\n * When the bar is visible. Defaults to `'always'` when bar is enabled, `'auto'` when bar is not explicitly configured.\n * - `'always'` — bar is always shown (indeterminate until a number is provided).\n * - `'auto'` — bar is shown only after `update()` is called with a number.\n * - `'never'` — bar is never shown.\n */\n show?: PadroneProgressShow;\n};\n\nexport type PadroneProgressOptions = {\n spinner?: PadroneSpinnerConfig;\n /** 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). */\n bar?: boolean | PadroneBarConfig;\n /** Show elapsed time since the indicator started. Defaults to `false`. */\n time?: boolean;\n /** Show estimated time remaining based on progress rate. Requires numeric `update()` calls. Defaults to `false`. */\n eta?: boolean;\n /** Character/string shown before the success message. Defaults to `'✔'`. */\n successIndicator?: string;\n /** Character/string shown before the error message. Defaults to `'✖'`. */\n errorIndicator?: string;\n};\n\n/**\n * Controls interactive prompting capability and default behavior at the runtime level.\n * - `'supported'` — capable; caller decides.\n * - `'unsupported'` — hard veto; nothing can override.\n * - `'forced'` — capable and forces prompts by default.\n * - `'disabled'` — capable but suppresses prompts by default.\n */\nexport type InteractiveMode = 'supported' | 'unsupported' | 'forced' | 'disabled';\n\n/**\n * Configuration passed to the runtime's `prompt` function for interactive field prompting.\n * The prompt type and choices are auto-detected from the field's JSON schema.\n */\nexport type InteractivePromptConfig = {\n /** The field name being prompted. */\n name: string;\n /** Human-readable message/label for the prompt, derived from the field's description or name. */\n message: string;\n /** The prompt type, auto-detected from the JSON schema. */\n type: 'input' | 'confirm' | 'select' | 'multiselect' | 'password';\n /** Available choices for select/multiselect prompts. */\n choices?: { label: string; value: unknown }[];\n /** Default value from the schema. */\n default?: unknown;\n};\n\n/**\n * Defines the execution context for a Padrone program.\n * Abstracts all environment-dependent I/O so the CLI framework\n * can run outside of a terminal (e.g., web UIs, chat interfaces, testing).\n *\n * All fields are optional — unspecified fields fall back to the Node.js/Bun defaults.\n */\nexport type PadroneRuntime = {\n /** Write normal output (replaces console.log). Receives the raw value — runtime handles formatting. */\n output?: (...args: unknown[]) => void;\n /** Write error output (replaces console.error). */\n error?: (text: string) => void;\n /** Return the raw CLI arguments (replaces process.argv.slice(2)). */\n argv?: () => string[];\n /** Return environment variables (replaces process.env). */\n env?: () => Record<string, string | undefined>;\n /** Default help output format. */\n format?: HelpFormat | 'auto';\n /** Color theme for ANSI/console help output. A theme name or partial color config. */\n theme?: ColorTheme | ColorConfig;\n /**\n * Standard input abstraction. Provides methods to read piped data from stdin.\n * When not provided, defaults to reading from `process.stdin`.\n *\n * Used by commands that declare a `stdin` field in their arguments meta.\n * The framework reads stdin automatically during the validate phase and\n * injects the data into the specified argument field.\n */\n stdin?: {\n /** Whether stdin is a TTY (interactive terminal) vs a pipe/file. */\n isTTY?: boolean;\n /** Read all of stdin as a string. */\n text: () => Promise<string>;\n /** Async iterable of lines for streaming. */\n lines: () => AsyncIterable<string>;\n };\n /**\n * Controls interactive prompting capability and default behavior.\n * - `'supported'` — runtime can handle prompts; caller (flag/pref) decides whether to prompt. This is the default when `prompt` is provided.\n * - `'unsupported'` — runtime cannot handle prompts; hard veto that nothing can override.\n * - `'forced'` — runtime supports prompts and forces them by default (prompts even for provided values).\n * - `'disabled'` — runtime supports prompts but suppresses them by default.\n *\n * `'unsupported'` is the only immutable state. For the others, the `--interactive`/`-i` flag\n * and `cli()` preferences can override the default behavior.\n */\n interactive?: InteractiveMode;\n /**\n * Prompt the user for input. Called during `cli()` for fields marked as interactive.\n * When `interactive` is `true` and this is not provided, defaults to an Enquirer-based terminal prompt.\n */\n prompt?: (config: InteractivePromptConfig) => Promise<unknown>;\n /**\n * Read a line of input from the user. Used by `repl()` for custom runtimes\n * (web UIs, chat interfaces, testing).\n * Returns the input string, `null` on EOF (e.g. Ctrl+D, closed connection),\n * or `REPL_SIGINT` when the user presses Ctrl+C.\n *\n * When not provided, `repl()` uses a built-in Node.js readline session\n * with command history (up/down arrows) and tab completion.\n */\n readLine?: (prompt: string) => Promise<string | typeof REPL_SIGINT | null>;\n\n /**\n * Register a callback for process signals. Returns an unsubscribe function.\n * The default runtime wires this to `process.on('SIGINT' | 'SIGTERM' | 'SIGHUP')`.\n * Non-Node runtimes (web UIs, tests) can map their own cancellation semantics.\n *\n * When not provided, signal handling is disabled for this runtime.\n */\n onSignal?: (callback: (signal: PadroneSignal) => void) => () => void;\n\n /**\n * Terminal/output capabilities. Used for ANSI detection, text wrapping, and TTY checks.\n * The default runtime auto-detects from `process.stdout`. Non-terminal runtimes\n * (web UIs, tests) should provide explicit values.\n */\n terminal?: {\n /** Number of columns in the terminal. Used for text wrapping. */\n columns?: number;\n /** Whether stdout is a TTY. Affects ANSI color output and interactive features. */\n isTTY?: boolean;\n };\n\n /**\n * Force-exit the process. The default runtime wires this to `process.exit()`.\n * Non-Node runtimes can throw an error or no-op.\n */\n exit?: (code: number) => never;\n};\n\n/**\n * Internal resolved runtime where all fields are guaranteed to be present.\n * The `prompt`, `interactive`, and `readLine` fields remain optional since not all runtimes provide them.\n */\nexport type ResolvedPadroneRuntime = Required<\n Omit<PadroneRuntime, 'prompt' | 'interactive' | 'readLine' | 'stdin' | 'theme' | 'onSignal' | 'terminal' | 'exit'>\n> &\n Pick<PadroneRuntime, 'prompt' | 'interactive' | 'readLine' | 'stdin' | 'theme' | 'onSignal' | 'terminal' | 'exit'>;\n\n/**\n * Sentinel value returned by the terminal REPL session when Ctrl+C is pressed.\n * Distinguished from empty string (user pressed enter) and null (EOF/Ctrl+D).\n */\nexport const REPL_SIGINT = Symbol('REPL_SIGINT');\n\n/**\n * Internal session config for the REPL's persistent readline interface.\n */\nexport type ReplSessionConfig = {\n completer?: (line: string) => [string[], string];\n history?: string[];\n};\n","import { readStreamAsText } from '../util/stream.ts';\nimport type {\n InteractiveMode,\n InteractivePromptConfig,\n PadroneRuntime,\n PadroneSignal,\n ReplSessionConfig,\n ResolvedPadroneRuntime,\n} from './runtime.ts';\nimport { REPL_SIGINT } from './runtime.ts';\n\n/**\n * Default terminal prompt implementation powered by Enquirer.\n * Lazily imported to avoid loading Enquirer when not needed.\n */\nasync function defaultTerminalPrompt(config: InteractivePromptConfig): Promise<unknown> {\n const Enquirer = (await import('enquirer')).default;\n\n const question: Record<string, unknown> = {\n type: config.type,\n name: config.name,\n message: config.message,\n };\n\n if (config.default !== undefined) {\n question.initial = config.default;\n }\n\n if (config.choices) {\n question.choices = config.choices.map((c) => ({\n name: String(c.value),\n message: c.label,\n }));\n }\n\n const response = (await Enquirer.prompt(question as any)) as Record<string, unknown>;\n return response[config.name];\n}\n\nexport function createTerminalReplSession(config: ReplSessionConfig) {\n // History accumulates across per-call interfaces, giving us\n // up/down arrow navigation without a persistent stdin listener\n // that would conflict with Enquirer or other stdin consumers.\n let history: string[] = config.history ? [...config.history] : [];\n let currentCompleter = config.completer;\n\n return {\n /** Update the tab completer (e.g. when REPL scope changes). Takes effect on the next question. */\n set completer(fn: ((line: string) => [string[], string]) | undefined) {\n currentCompleter = fn;\n },\n async question(prompt: string): Promise<string | typeof REPL_SIGINT | null> {\n const { createInterface } = await import('node:readline');\n const opts: Record<string, unknown> = {\n input: process.stdin,\n output: process.stdout,\n terminal: true,\n history: [...history],\n historySize: Math.max(history.length, 1000),\n };\n if (currentCompleter) {\n opts.completer = currentCompleter;\n }\n const rl = createInterface(opts as any);\n\n return new Promise((resolve) => {\n let resolved = false;\n const settle = (value: string | typeof REPL_SIGINT | null) => {\n if (resolved) return;\n resolved = true;\n rl.close();\n resolve(value);\n };\n\n rl.question(prompt, (answer) => {\n // Grab updated history (includes the new entry) before closing.\n if (Array.isArray((rl as any).history)) history = [...(rl as any).history];\n settle(answer);\n });\n // Ctrl+C: cancel current line, print newline, resolve SIGINT sentinel.\n rl.once('SIGINT', () => {\n process.stdout.write('\\n');\n settle(REPL_SIGINT);\n });\n // EOF (Ctrl+D) fires close without the question callback.\n rl.once('close', () => {\n // Write newline so zsh doesn't show '%' (partial-line indicator).\n process.stdout.write('\\n');\n settle(null);\n });\n });\n },\n close() {\n // No persistent interface to clean up.\n },\n };\n}\n\n/**\n * Auto-detect interactive mode when not explicitly set.\n * Returns 'disabled' in CI environments or non-TTY contexts, 'supported' otherwise.\n */\nfunction detectInteractiveMode(): InteractiveMode {\n if (typeof process === 'undefined') return 'disabled';\n if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) return 'disabled';\n if (!process.stdout?.isTTY) return 'disabled';\n return 'supported';\n}\n\n/**\n * Creates a default stdin reader from `process.stdin`.\n * Only created when a command actually declares a `stdin` meta field.\n */\nfunction createDefaultStdin(): NonNullable<PadroneRuntime['stdin']> {\n return {\n get isTTY() {\n // process.stdin.isTTY is `true` when interactive terminal, `undefined` when piped/redirected.\n // Node.js never sets it to `false` — it's either `true` or absent.\n if (typeof process === 'undefined') return true;\n return process.stdin?.isTTY === true;\n },\n async text() {\n if (typeof process === 'undefined') return '';\n return readStreamAsText(process.stdin);\n },\n async *lines() {\n if (typeof process === 'undefined') return;\n const { createInterface } = await import('node:readline');\n const rl = createInterface({ input: process.stdin });\n try {\n for await (const line of rl) {\n yield line;\n }\n } finally {\n rl.close();\n }\n },\n };\n}\n\n/**\n * Default signal listener that wires to `process.on(signal)`.\n * Returns an unsubscribe function that removes all listeners.\n */\nfunction defaultOnSignal(callback: (signal: PadroneSignal) => void): () => void {\n if (typeof process === 'undefined') return () => {};\n const signals: PadroneSignal[] = ['SIGINT', 'SIGTERM', 'SIGHUP'];\n const handlers = new Map<PadroneSignal, () => void>();\n for (const sig of signals) {\n const handler = () => callback(sig);\n handlers.set(sig, handler);\n process.on(sig, handler);\n }\n return () => {\n for (const [sig, handler] of handlers) {\n process.removeListener(sig, handler);\n }\n };\n}\n\n/**\n * Creates the default Node.js/Bun runtime.\n */\nfunction defaultExit(code: number): never {\n if (typeof process !== 'undefined') process.exit(code);\n throw new Error(`Exit with code ${code}`);\n}\n\nfunction getTerminalInfo(): PadroneRuntime['terminal'] {\n if (typeof process === 'undefined') return undefined;\n return {\n get columns() {\n return process.stdout?.columns;\n },\n get isTTY() {\n return process.stdout?.isTTY === true;\n },\n };\n}\n\nexport function createDefaultRuntime(): ResolvedPadroneRuntime {\n return {\n output: (...args) => console.log(...args),\n error: (text) => console.error(text),\n argv: () => (typeof process !== 'undefined' ? process.argv.slice(2) : []),\n env: () => (typeof process !== 'undefined' ? (process.env as Record<string, string | undefined>) : {}),\n format: 'auto',\n prompt: defaultTerminalPrompt,\n interactive: detectInteractiveMode(),\n onSignal: defaultOnSignal,\n terminal: getTerminalInfo(),\n exit: defaultExit,\n };\n}\n\n/**\n * Returns the stdin abstraction: custom runtime stdin > default process.stdin.\n * Returns `undefined` when no custom stdin is provided and process.stdin is not piped.\n */\nexport function resolveStdin(partial?: PadroneRuntime): NonNullable<PadroneRuntime['stdin']> | undefined {\n if (partial?.stdin) return partial.stdin;\n const defaultStdin = createDefaultStdin();\n // Only use default stdin if it's actually piped (isTTY === false).\n // This avoids accidentally blocking on stdin in tests/CI.\n if (defaultStdin.isTTY) return undefined;\n return defaultStdin;\n}\n\n/**\n * Like `resolveStdin`, but always returns a stdin source even when it's a TTY.\n * Used for async streams which support interactive (non-piped) input.\n */\nexport function resolveStdinAlways(partial?: PadroneRuntime): NonNullable<PadroneRuntime['stdin']> {\n if (partial?.stdin) return partial.stdin;\n return createDefaultStdin();\n}\n\n/**\n * Merges a partial runtime with the default runtime.\n */\nexport function resolveRuntime(partial?: PadroneRuntime): ResolvedPadroneRuntime {\n const defaults = createDefaultRuntime();\n if (!partial) return defaults;\n return {\n output: partial.output ?? defaults.output,\n error: partial.error ?? defaults.error,\n argv: partial.argv ?? defaults.argv,\n env: partial.env ?? defaults.env,\n format: partial.format ?? defaults.format,\n interactive: partial.interactive ?? defaults.interactive,\n prompt: partial.prompt ?? defaults.prompt,\n readLine: partial.readLine ?? defaults.readLine,\n stdin: partial.stdin,\n theme: partial.theme,\n onSignal: partial.onSignal ?? defaults.onSignal,\n terminal: partial.terminal ?? defaults.terminal,\n exit: partial.exit ?? defaults.exit,\n };\n}\n","import type { AnyPadroneCommand } from '../types/index.ts';\nimport { extractSchemaMetadata, getJsonSchema } from './args.ts';\nimport { resolveRuntime } from './default-runtime.ts';\nimport type { ResolvedPadroneRuntime } from './runtime.ts';\n\n// ---------------------------------------------------------------------------\n// Lazy command resolution\n// ---------------------------------------------------------------------------\n\nexport const lazyResolver = Symbol('lazyResolver');\n\n/** Resolves a lazy command in place by calling its stored resolver. No-op if already resolved. */\nexport function resolveCommand(cmd: AnyPadroneCommand): AnyPadroneCommand {\n const resolver = (cmd as any)[lazyResolver];\n if (resolver) {\n delete (cmd as any)[lazyResolver];\n resolver(cmd);\n }\n return cmd;\n}\n\n/** Recursively resolves a command and all its descendants. */\nexport function resolveAllCommands(cmd: AnyPadroneCommand): void {\n resolveCommand(cmd);\n if (cmd.commands) {\n for (const sub of cmd.commands) resolveAllCommands(sub);\n }\n}\n\n/** Checks whether a value is a Padrone program/builder. */\nexport function isPadroneProgram(value: unknown): value is object {\n return !!value && typeof value === 'object' && commandSymbol in value;\n}\n\n/** Extracts the underlying command from a program/builder and resolves the full command tree. */\nexport function getCommand(program: object): AnyPadroneCommand {\n const cmd = commandSymbol in program ? ((program as any)[commandSymbol] as AnyPadroneCommand) : (program as AnyPadroneCommand);\n resolveAllCommands(cmd);\n return cmd;\n}\n\nexport const commandSymbol = Symbol('padrone_command');\n\n/** Config keys that are merged when overriding a command. */\nexport const configKeys = ['title', 'description', 'version', 'deprecated', 'hidden', 'mutation', 'needsApproval'] as const;\n\n/**\n * Merges an existing command with an override.\n * - Config fields are shallow-merged (new overrides old).\n * - Action, arguments, meta, config schema, env schema are taken from the override if set.\n * - Subcommands are recursively merged by name.\n */\nexport function mergeCommands(existing: AnyPadroneCommand, override: AnyPadroneCommand): AnyPadroneCommand {\n resolveCommand(existing);\n resolveCommand(override);\n const merged: AnyPadroneCommand = { ...existing };\n\n // Merge config fields\n for (const key of configKeys) {\n if (override[key] !== undefined) (merged as any)[key] = override[key];\n }\n\n // Override fields: take from override if explicitly set (not inherited from existing via spread)\n if (override.action !== existing.action) merged.action = override.action;\n if (override.argsSchema !== existing.argsSchema) merged.argsSchema = override.argsSchema;\n if (override.meta !== existing.meta) merged.meta = override.meta;\n if (override.isAsync !== existing.isAsync) merged.isAsync = override.isAsync || existing.isAsync;\n if (override.runtime !== existing.runtime) merged.runtime = override.runtime;\n if (override.interceptors !== existing.interceptors) merged.interceptors = override.interceptors;\n if (override.aliases !== existing.aliases) merged.aliases = override.aliases;\n // Recursively merge subcommands by name\n if (override.commands) {\n const baseCommands = [...(existing.commands || [])];\n for (const overrideChild of override.commands) {\n const existingIndex = baseCommands.findIndex((c) => c.name === overrideChild.name);\n if (existingIndex >= 0) {\n baseCommands[existingIndex] = mergeCommands(baseCommands[existingIndex]!, overrideChild);\n } else {\n baseCommands.push(overrideChild);\n }\n }\n merged.commands = baseCommands;\n }\n\n return merged;\n}\n\n/**\n * Resolves the runtime for a command by walking up the parent chain.\n * Returns a fully resolved runtime with all defaults filled in.\n */\nexport function getCommandRuntime(cmd: AnyPadroneCommand): ResolvedPadroneRuntime {\n let current: AnyPadroneCommand | undefined = cmd;\n while (current) {\n if (current.runtime) return resolveRuntime(current.runtime);\n current = current.parent;\n }\n return resolveRuntime();\n}\n\n/**\n * Recursively re-paths a command tree under a new parent path, updating parent references.\n */\nexport function repathCommandTree(\n cmd: AnyPadroneCommand,\n newName: string,\n parentPath: string,\n parent: AnyPadroneCommand,\n): AnyPadroneCommand {\n resolveCommand(cmd);\n const newPath = parentPath ? `${parentPath} ${newName}` : newName;\n const remounted: AnyPadroneCommand = {\n ...cmd,\n name: newName,\n path: newPath,\n parent,\n version: undefined,\n };\n\n if (cmd.commands?.length) {\n remounted.commands = cmd.commands.map((child) => repathCommandTree(child, child.name, newPath, remounted));\n }\n\n return remounted;\n}\n\n/**\n * Builds a completer function for the REPL from the command tree.\n * Completes command names, subcommand names, option names (--foo), and aliases (-f).\n * Also includes dot-prefixed built-in REPL commands (.exit, .clear, .scope, .help, .history).\n */\nexport function buildReplCompleter(\n rootCommand: AnyPadroneCommand,\n builtins: {\n inScope?: boolean;\n },\n): (line: string) => [string[], string] {\n resolveAllCommands(rootCommand);\n return (line: string): [string[], string] => {\n const trimmed = line.trimStart();\n const parts = trimmed.split(/\\s+/);\n const lastPart = parts[parts.length - 1] ?? '';\n\n // If we're completing a dot-command\n if (lastPart.startsWith('.')) {\n const dotCmds = ['.exit', '.clear', '.help', '.history'];\n if (rootCommand.commands?.some((c) => c.commands?.length) || builtins.inScope) dotCmds.push('.scope');\n const hits = dotCmds.filter((c) => c.startsWith(lastPart));\n return [hits.length ? hits : dotCmds, lastPart];\n }\n\n // If we're completing an option (starts with -)\n if (lastPart.startsWith('-')) {\n // Find which command we're in\n const commandParts = parts.slice(0, -1).filter((p) => !p.startsWith('-'));\n let targetCommand = rootCommand;\n for (const part of commandParts) {\n resolveCommand(targetCommand);\n const sub = targetCommand.commands?.find((c) => c.name === part || c.aliases?.includes(part));\n if (sub) {\n resolveCommand(sub);\n targetCommand = sub;\n } else break;\n }\n\n // Get options for this command\n const options: string[] = [];\n if (targetCommand.argsSchema) {\n try {\n const argsMeta = targetCommand.meta?.fields;\n const { flags, aliases } = extractSchemaMetadata(targetCommand.argsSchema, argsMeta, targetCommand.meta?.autoAlias);\n const jsonSchema = getJsonSchema(targetCommand.argsSchema) as Record<string, any>;\n if (jsonSchema.type === 'object' && jsonSchema.properties) {\n for (const key of Object.keys(jsonSchema.properties)) {\n options.push(`--${key}`);\n }\n for (const flag of Object.keys(flags)) {\n options.push(`-${flag}`);\n }\n for (const alias of Object.keys(aliases)) {\n options.push(`--${alias}`);\n }\n }\n } catch {\n // Ignore schema parsing errors\n }\n }\n // Add global flags\n options.push('--help', '-h');\n\n const hits = options.filter((o) => o.startsWith(lastPart));\n return [hits.length ? hits : options, lastPart];\n }\n\n // Completing command names\n const commandParts = parts.filter((p) => !p.startsWith('-'));\n // Walk into subcommands for all but the last token\n let targetCommand = rootCommand;\n for (let i = 0; i < commandParts.length - 1; i++) {\n resolveCommand(targetCommand);\n const sub = targetCommand.commands?.find((c) => c.name === commandParts[i] || c.aliases?.includes(commandParts[i]!));\n if (sub) {\n resolveCommand(sub);\n targetCommand = sub;\n } else break;\n }\n\n const candidates: string[] = [];\n\n // Add subcommand names and aliases\n if (targetCommand.commands) {\n for (const cmd of targetCommand.commands) {\n if (!cmd.hidden) {\n candidates.push(cmd.name);\n if (cmd.aliases) candidates.push(...cmd.aliases);\n }\n }\n }\n\n // Add dot-commands and `..` shorthand at the root level (relative to current scope)\n if (targetCommand === rootCommand) {\n candidates.push('.help', '.exit', '.clear', '.history');\n if (rootCommand.commands?.some((c) => c.commands?.length) || builtins.inScope) candidates.push('.scope');\n if (builtins.inScope) candidates.push('..');\n }\n\n const hits = candidates.filter((c) => c.startsWith(lastPart));\n return [hits.length ? hits : candidates, lastPart];\n };\n}\n\n/**\n * Computes the Levenshtein edit distance between two strings.\n */\nfunction levenshtein(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n const dp: number[] = Array.from({ length: n + 1 }, (_, i) => i);\n\n for (let i = 1; i <= m; i++) {\n let prev = dp[0]!;\n dp[0] = i;\n for (let j = 1; j <= n; j++) {\n const temp = dp[j]!;\n dp[j] = a[i - 1] === b[j - 1] ? prev : 1 + Math.min(prev, dp[j]!, dp[j - 1]!);\n prev = temp;\n }\n }\n\n return dp[n]!;\n}\n\n/**\n * Finds close matches from a list of candidates using Levenshtein distance\n * and prefix/substring matching (for inputs longer than 3 characters).\n * Returns up to 3 matching candidate names (raw, unformatted).\n */\nexport function suggestSimilar(input: string, candidates: string[]): string[] {\n if (candidates.length === 0) return [];\n\n const lower = input.toLowerCase();\n const matches: { candidate: string; score: number }[] = [];\n\n for (const candidate of candidates) {\n const candidateLower = candidate.toLowerCase();\n if (candidateLower === lower) continue;\n\n const dist = levenshtein(lower, candidateLower);\n const maxLen = Math.max(input.length, candidate.length);\n const threshold = Math.min(3, Math.max(1, Math.ceil(maxLen * 0.4)));\n\n if (dist > 0 && dist <= threshold) {\n matches.push({ candidate, score: dist });\n } else if (lower.length >= 3) {\n // Prefix or substring match for longer inputs\n if (candidateLower.startsWith(lower) || candidateLower.includes(lower)) {\n matches.push({ candidate, score: threshold + 1 });\n }\n }\n }\n\n matches.sort((a, b) => a.score - b.score);\n return matches.slice(0, 3).map((m) => m.candidate);\n}\n\nexport function findCommandByName(name: string, commands?: AnyPadroneCommand[]): AnyPadroneCommand | undefined {\n if (!commands) return undefined;\n\n const foundByName = commands.find((cmd) => cmd.name === name);\n if (foundByName) return resolveCommand(foundByName);\n\n // Check for aliases\n const foundByAlias = commands.find((cmd) => cmd.aliases?.includes(name));\n if (foundByAlias) return resolveCommand(foundByAlias);\n\n for (const cmd of commands) {\n if (name.startsWith(`${cmd.name} `)) {\n resolveCommand(cmd);\n if (cmd.commands) {\n const subCommandName = name.slice(cmd.name.length + 1);\n const subCommand = findCommandByName(subCommandName, cmd.commands);\n if (subCommand) return subCommand;\n }\n }\n // Check aliases for nested commands\n if (cmd.aliases) {\n for (const alias of cmd.aliases) {\n if (name.startsWith(`${alias} `)) {\n resolveCommand(cmd);\n if (cmd.commands) {\n const subCommandName = name.slice(alias.length + 1);\n const subCommand = findCommandByName(subCommandName, cmd.commands);\n if (subCommand) return subCommand;\n }\n }\n }\n }\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Shared utilities for MCP and serve\n// ---------------------------------------------------------------------------\n\nexport type CollectedEndpoint = { name: string; command: AnyPadroneCommand };\n\n/** Collect all actionable commands recursively. Hidden commands are excluded. */\nexport function collectEndpoints(commands: AnyPadroneCommand[] | undefined, prefix: string): CollectedEndpoint[] {\n if (!commands) return [];\n const endpoints: CollectedEndpoint[] = [];\n for (const cmd of commands) {\n resolveCommand(cmd);\n if (cmd.hidden) continue;\n const path = cmd.name ? (prefix ? `${prefix}.${cmd.name}` : cmd.name) : prefix;\n if (cmd.action || cmd.argsSchema) {\n endpoints.push({ name: path, command: cmd });\n }\n if (cmd.commands?.length) {\n endpoints.push(...collectEndpoints(cmd.commands, path));\n }\n }\n return endpoints;\n}\n\n/** Build the JSON Schema for a command's arguments. */\nexport function buildInputSchema(cmd: AnyPadroneCommand): Record<string, unknown> {\n if (!cmd.argsSchema) {\n return { type: 'object', additionalProperties: false };\n }\n try {\n return getJsonSchema(cmd.argsSchema) as Record<string, unknown>;\n } catch {\n return { type: 'object', additionalProperties: false };\n }\n}\n\n/** Serialize a record of args into CLI flag strings. */\nexport function serializeArgsToFlags(args: Record<string, unknown>): string[] {\n const parts: string[] = [];\n for (const [key, value] of Object.entries(args)) {\n if (value === undefined) continue;\n if (typeof value === 'boolean') {\n parts.push(value ? `--${key}` : `--no-${key}`);\n } else if (Array.isArray(value)) {\n for (const v of value) parts.push(`--${key}=${String(v)}`);\n } else {\n const strVal = String(value);\n parts.push(strVal.includes(' ') ? `--${key}=\"${strVal}\"` : `--${key}=${strVal}`);\n }\n }\n return parts;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6OA,MAAa,cAAc,OAAO,cAAc;;;;;;;AC9NhD,eAAe,sBAAsB,QAAmD;CACtF,MAAM,YAAY,MAAM,OAAO,aAAa;CAE5C,MAAM,WAAoC;EACxC,MAAM,OAAO;EACb,MAAM,OAAO;EACb,SAAS,OAAO;EACjB;AAED,KAAI,OAAO,YAAY,KAAA,EACrB,UAAS,UAAU,OAAO;AAG5B,KAAI,OAAO,QACT,UAAS,UAAU,OAAO,QAAQ,KAAK,OAAO;EAC5C,MAAM,OAAO,EAAE,MAAM;EACrB,SAAS,EAAE;EACZ,EAAE;AAIL,SADkB,MAAM,SAAS,OAAO,SAAgB,EACxC,OAAO;;AAGzB,SAAgB,0BAA0B,QAA2B;CAInE,IAAI,UAAoB,OAAO,UAAU,CAAC,GAAG,OAAO,QAAQ,GAAG,EAAE;CACjE,IAAI,mBAAmB,OAAO;AAE9B,QAAO;EAEL,IAAI,UAAU,IAAwD;AACp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