capable-kit 0.0.1-alpha.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/dist/ai-sdk.d.mts +40 -0
- package/dist/ai-sdk.mjs +58 -0
- package/dist/ai-sdk.mjs.map +1 -0
- package/dist/app.d.mts +2 -0
- package/dist/app.mjs +2 -0
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +447 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/cli.d.mts +45 -0
- package/dist/cli.mjs +2 -0
- package/dist/core.d.mts +3 -0
- package/dist/core.mjs +3 -0
- package/dist/eve.d.mts +28 -0
- package/dist/eve.mjs +61 -0
- package/dist/eve.mjs.map +1 -0
- package/dist/http.d.mts +2 -0
- package/dist/http.mjs +2 -0
- package/dist/index-BuXwkN8G.d.mts +42 -0
- package/dist/index-C9ZThFPN.d.mts +125 -0
- package/dist/index-DLcYNpfo.d.mts +252 -0
- package/dist/index-u9ZOETR5.d.mts +57 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +4 -0
- package/dist/mcp.d.mts +36 -0
- package/dist/mcp.mjs +140 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/projection-Cgq2u0Wt.mjs +18 -0
- package/dist/projection-Cgq2u0Wt.mjs.map +1 -0
- package/dist/server.d.mts +2 -0
- package/dist/server.mjs +82 -0
- package/dist/server.mjs.map +1 -0
- package/dist/src-CT4fbWqb.mjs +455 -0
- package/dist/src-CT4fbWqb.mjs.map +1 -0
- package/dist/src-CvWOGyGW.mjs +438 -0
- package/dist/src-CvWOGyGW.mjs.map +1 -0
- package/dist/src-DX-_J6l2.mjs +539 -0
- package/dist/src-DX-_J6l2.mjs.map +1 -0
- package/dist/src-DlSJtEhv.mjs +441 -0
- package/dist/src-DlSJtEhv.mjs.map +1 -0
- package/dist/subscription-CBnnIU42.d.mts +18 -0
- package/package.json +35 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { a as TransportError, c as getAppRuntime } from "./src-CT4fbWqb.mjs";
|
|
2
|
+
import { render } from "markdansi";
|
|
3
|
+
//#region packages/cli/src/commands.ts
|
|
4
|
+
function collectCommands(nodes, parent = []) {
|
|
5
|
+
const commands = [];
|
|
6
|
+
const groups = [];
|
|
7
|
+
for (const node of nodes) {
|
|
8
|
+
if (node.type === "group") {
|
|
9
|
+
const meta = node.meta.cli ?? {};
|
|
10
|
+
const command = [...parent, meta.name ?? node.key];
|
|
11
|
+
groups.push(groupFrom(node, command));
|
|
12
|
+
const children = collectCommands(node.children, command);
|
|
13
|
+
commands.push(...children.commands);
|
|
14
|
+
groups.push(...children.groups);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const rawMeta = node.meta.cli;
|
|
18
|
+
if (rawMeta === false) continue;
|
|
19
|
+
const meta = rawMeta ?? {};
|
|
20
|
+
commands.push({
|
|
21
|
+
command: meta.command ?? [...parent, meta.name ?? node.path.at(-1)],
|
|
22
|
+
capability: node,
|
|
23
|
+
meta
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
commands: Object.freeze(commands),
|
|
28
|
+
groups: Object.freeze(groups)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function groupFrom(node, command) {
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
command: Object.freeze(command),
|
|
34
|
+
...node.title ? { title: node.title } : {},
|
|
35
|
+
...node.description ? { description: node.description } : {}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region packages/cli/src/style.ts
|
|
40
|
+
function createCliStyle(color) {
|
|
41
|
+
const enabled = color ?? supportsColor();
|
|
42
|
+
return {
|
|
43
|
+
bold: enabled ? (text) => `\u001B[1m${text}\u001B[22m` : identity,
|
|
44
|
+
accent: enabled ? (text) => `\u001B[36m${text}\u001B[39m` : identity,
|
|
45
|
+
dim: enabled ? (text) => `\u001B[2m${text}\u001B[22m` : identity
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function supportsColor(env = process.env, isTTY = Boolean(process.stdout.isTTY)) {
|
|
49
|
+
if ("NO_COLOR" in env) return false;
|
|
50
|
+
if (env.FORCE_COLOR !== void 0) return env.FORCE_COLOR !== "0";
|
|
51
|
+
return isTTY && env.TERM !== "dumb";
|
|
52
|
+
}
|
|
53
|
+
function renderRows(rows, style) {
|
|
54
|
+
const width = Math.max(0, ...rows.map(({ label }) => label.length));
|
|
55
|
+
return rows.map(({ label, description }) => {
|
|
56
|
+
const styledLabel = style.accent(label);
|
|
57
|
+
return description ? ` ${styledLabel}${" ".repeat(width - label.length + 3)}${style.dim(description)}` : ` ${styledLabel}`;
|
|
58
|
+
}).join("\n");
|
|
59
|
+
}
|
|
60
|
+
function renderSection(title, body, style) {
|
|
61
|
+
return `${style.bold(title)}\n${body}`;
|
|
62
|
+
}
|
|
63
|
+
function identity(text) {
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region packages/cli/src/help.ts
|
|
68
|
+
function renderRootHelp(manifest, commands, invocationName, style) {
|
|
69
|
+
return renderHelp([
|
|
70
|
+
heading(manifest.name, manifest.description, style),
|
|
71
|
+
renderSection("Usage", ` ${style.accent(invocationName)} <command> [options]`, style),
|
|
72
|
+
renderSection("Commands", renderRows(commands.map((command) => ({
|
|
73
|
+
label: commandLabel(command),
|
|
74
|
+
...command.capability.title ? { description: command.capability.title } : {}
|
|
75
|
+
})), style), style),
|
|
76
|
+
globalOptions(style)
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
function renderGroupHelp(group, commands, invocationName, style) {
|
|
80
|
+
const children = commands.filter((candidate) => startsWith(candidate.command, group.command)).map((candidate) => {
|
|
81
|
+
const suffix = candidate.command.slice(group.command.length);
|
|
82
|
+
const positionals = candidate.meta.positional ?? [];
|
|
83
|
+
return {
|
|
84
|
+
label: [...suffix, ...positionals.map((name) => `<${name}>`)].join(" "),
|
|
85
|
+
...candidate.capability.title ? { description: candidate.capability.title } : {}
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
return renderHelp([
|
|
89
|
+
heading(group.title ?? group.command.at(-1), group.description, style),
|
|
90
|
+
renderSection("Usage", ` ${style.accent(`${invocationName} ${group.command.join(" ")}`)} <command> [options]`, style),
|
|
91
|
+
renderSection("Commands", renderRows(children, style), style),
|
|
92
|
+
globalOptions(style)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
function renderCommandHelp(command, invocationName, style) {
|
|
96
|
+
const positionals = command.meta.positional ?? [];
|
|
97
|
+
const properties = command.capability.input?.properties;
|
|
98
|
+
const required = new Set(command.capability.input?.required);
|
|
99
|
+
const argumentsRows = positionals.map((name) => ({
|
|
100
|
+
label: `<${name}>`,
|
|
101
|
+
description: describeField(properties?.[name], required.has(name))
|
|
102
|
+
}));
|
|
103
|
+
const optionRows = Object.entries(properties ?? {}).filter(([name]) => !positionals.includes(name)).map(([name, schema]) => ({
|
|
104
|
+
label: optionLabel(name, schema),
|
|
105
|
+
description: describeField(schema, required.has(name))
|
|
106
|
+
}));
|
|
107
|
+
const usage = [
|
|
108
|
+
invocationName,
|
|
109
|
+
...command.command,
|
|
110
|
+
...positionals.map((name) => `<${name}>`),
|
|
111
|
+
"[options]"
|
|
112
|
+
].join(" ");
|
|
113
|
+
return renderHelp([
|
|
114
|
+
heading(command.capability.title ?? command.command.join(" "), command.capability.description, style),
|
|
115
|
+
renderSection("Usage", ` ${style.accent(usage)}`, style),
|
|
116
|
+
argumentsRows.length ? renderSection("Arguments", renderRows(argumentsRows, style), style) : void 0,
|
|
117
|
+
renderSection("Options", renderRows([
|
|
118
|
+
...optionRows,
|
|
119
|
+
...command.capability.subscription ? [{
|
|
120
|
+
label: "--watch",
|
|
121
|
+
description: "Stream updates until interrupted"
|
|
122
|
+
}] : [],
|
|
123
|
+
{
|
|
124
|
+
label: "--json",
|
|
125
|
+
description: "Print canonical JSON"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
label: "-h, --help",
|
|
129
|
+
description: "Show command help"
|
|
130
|
+
}
|
|
131
|
+
], style), style)
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
function globalOptions(style) {
|
|
135
|
+
return renderSection("Options", renderRows([{
|
|
136
|
+
label: "--json",
|
|
137
|
+
description: "Print canonical JSON"
|
|
138
|
+
}, {
|
|
139
|
+
label: "-h, --help",
|
|
140
|
+
description: "Show help"
|
|
141
|
+
}], style), style);
|
|
142
|
+
}
|
|
143
|
+
function heading(title, description, style) {
|
|
144
|
+
return description ? `${style.bold(title)}\n\n${style.dim(description)}` : style.bold(title);
|
|
145
|
+
}
|
|
146
|
+
function commandLabel(command) {
|
|
147
|
+
const positionals = (command.meta.positional ?? []).map((name) => `<${name}>`);
|
|
148
|
+
return [...command.command, ...positionals].join(" ");
|
|
149
|
+
}
|
|
150
|
+
function optionLabel(name, schema) {
|
|
151
|
+
const flag = `--${kebabCase$1(name)}`;
|
|
152
|
+
if (schema.type === "boolean") return flag;
|
|
153
|
+
if (schema.type === "array" || schema.type === "object") return `${flag} <json>`;
|
|
154
|
+
return `${flag} <${String(schema.type ?? "value")}>`;
|
|
155
|
+
}
|
|
156
|
+
function describeField(schema, required) {
|
|
157
|
+
const description = typeof schema?.description === "string" ? schema.description : void 0;
|
|
158
|
+
const type = describeSchema(schema);
|
|
159
|
+
return [
|
|
160
|
+
description ? `${description} (${type})` : type,
|
|
161
|
+
required ? "required" : void 0,
|
|
162
|
+
schema?.default !== void 0 ? `default: ${String(schema.default)}` : void 0
|
|
163
|
+
].filter(Boolean).join(", ");
|
|
164
|
+
}
|
|
165
|
+
function describeSchema(schema) {
|
|
166
|
+
if (!schema) return "value";
|
|
167
|
+
const type = schema.type === "array" ? `array<${String(schema.items?.type ?? "value")}>` : schema.type === "object" ? `object { ${Object.keys(schema.properties ?? {}).join(", ")} }` : String(schema.type ?? "value");
|
|
168
|
+
const constraints = [];
|
|
169
|
+
if (Array.isArray(schema.enum)) constraints.push(`one of ${schema.enum.map(String).join(", ")}`);
|
|
170
|
+
if (typeof schema.minLength === "number") constraints.push(`minimum ${schema.minLength} characters`);
|
|
171
|
+
if (typeof schema.maxLength === "number") constraints.push(`maximum ${schema.maxLength} characters`);
|
|
172
|
+
if (typeof schema.minimum === "number") constraints.push(`minimum ${schema.minimum}`);
|
|
173
|
+
if (typeof schema.maximum === "number") constraints.push(`maximum ${schema.maximum}`);
|
|
174
|
+
if (typeof schema.format === "string") constraints.push(`format ${schema.format}`);
|
|
175
|
+
return [type, ...constraints].join(", ");
|
|
176
|
+
}
|
|
177
|
+
function startsWith(value, prefix) {
|
|
178
|
+
return prefix.every((part, index) => value[index] === part);
|
|
179
|
+
}
|
|
180
|
+
function kebabCase$1(value) {
|
|
181
|
+
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
182
|
+
}
|
|
183
|
+
function renderHelp(sections) {
|
|
184
|
+
return `${sections.filter(Boolean).join("\n\n")}\n`;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region packages/cli/src/index.ts
|
|
188
|
+
function createCli(app, cliOptions = {}) {
|
|
189
|
+
return Object.freeze({ run(argv, options = {}) {
|
|
190
|
+
return runCli({
|
|
191
|
+
app,
|
|
192
|
+
argv,
|
|
193
|
+
...cliOptions.invocationName ? { invocationName: cliOptions.invocationName } : {},
|
|
194
|
+
...cliOptions.color !== void 0 ? { color: cliOptions.color } : {},
|
|
195
|
+
...cliOptions.isTTY !== void 0 ? { isTTY: cliOptions.isTTY } : {},
|
|
196
|
+
...cliOptions.columns !== void 0 ? { columns: cliOptions.columns } : {},
|
|
197
|
+
...options.io ? { io: options.io } : {}
|
|
198
|
+
});
|
|
199
|
+
} });
|
|
200
|
+
}
|
|
201
|
+
async function runCli(options) {
|
|
202
|
+
const io = {
|
|
203
|
+
stdout: options.io?.stdout ?? ((text) => process.stdout.write(withTrailingNewline(text))),
|
|
204
|
+
stderr: options.io?.stderr ?? ((text) => process.stderr.write(withTrailingNewline(text)))
|
|
205
|
+
};
|
|
206
|
+
const invocationName = options.invocationName ?? "capable";
|
|
207
|
+
const isTTY = options.isTTY ?? Boolean(process.stdout.isTTY);
|
|
208
|
+
const color = options.color ?? supportsColor(process.env, isTTY);
|
|
209
|
+
const columns = options.columns ?? process.stdout.columns ?? 80;
|
|
210
|
+
const style = createCliStyle(color);
|
|
211
|
+
const runtime = getAppRuntime(options.app);
|
|
212
|
+
let manifest;
|
|
213
|
+
try {
|
|
214
|
+
manifest = await runtime.manifest();
|
|
215
|
+
} catch (error) {
|
|
216
|
+
io.stderr(renderRuntimeError(error));
|
|
217
|
+
return 1;
|
|
218
|
+
}
|
|
219
|
+
const catalog = collectCommands(manifest.capabilities);
|
|
220
|
+
const json = options.argv.includes("--json");
|
|
221
|
+
const watch = options.argv.includes("--watch");
|
|
222
|
+
const wantsHelp = options.argv.includes("--help") || options.argv.includes("-h");
|
|
223
|
+
const argv = options.argv.filter((argument) => ![
|
|
224
|
+
"--json",
|
|
225
|
+
"--watch",
|
|
226
|
+
"--help",
|
|
227
|
+
"-h"
|
|
228
|
+
].includes(argument));
|
|
229
|
+
if (argv.length === 0) {
|
|
230
|
+
io.stdout(renderRootHelp(manifest, catalog.commands, invocationName, style));
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
const command = matchCommand(argv, catalog.commands);
|
|
234
|
+
const group = exactGroup(argv, catalog.groups);
|
|
235
|
+
if (wantsHelp) {
|
|
236
|
+
if (command) {
|
|
237
|
+
io.stdout(renderCommandHelp(command, invocationName, style));
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
if (group) {
|
|
241
|
+
io.stdout(renderGroupHelp(group, catalog.commands, invocationName, style));
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
io.stderr(unknownCommand(argv, catalog.commands, invocationName));
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
if (!command) {
|
|
248
|
+
if (group) {
|
|
249
|
+
io.stderr(`Missing command after ${group.command.join(" ")}\nRun \`${invocationName} ${group.command.join(" ")} --help\` to list available commands.`);
|
|
250
|
+
return 2;
|
|
251
|
+
}
|
|
252
|
+
io.stderr(unknownCommand(argv, catalog.commands, invocationName));
|
|
253
|
+
return 2;
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
if (watch && !command.capability.subscription) throw new CliUsageError(`Option --watch is only available for subscribable Capabilities`);
|
|
257
|
+
const input = parseArguments(argv.slice(command.command.length), command, invocationName);
|
|
258
|
+
if (watch) return await runWatchedCommand({
|
|
259
|
+
runtime,
|
|
260
|
+
command,
|
|
261
|
+
input,
|
|
262
|
+
json,
|
|
263
|
+
io,
|
|
264
|
+
color,
|
|
265
|
+
isTTY,
|
|
266
|
+
columns
|
|
267
|
+
});
|
|
268
|
+
const result = await runtime.call({
|
|
269
|
+
id: command.capability.id,
|
|
270
|
+
input
|
|
271
|
+
});
|
|
272
|
+
io.stdout(json ? JSON.stringify(result.output, null, 2) : renderCapabilityResult(result, {
|
|
273
|
+
color,
|
|
274
|
+
isTTY,
|
|
275
|
+
columns
|
|
276
|
+
}));
|
|
277
|
+
return 0;
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error instanceof CliUsageError) {
|
|
280
|
+
io.stderr(error.message);
|
|
281
|
+
return 2;
|
|
282
|
+
}
|
|
283
|
+
if (error instanceof TransportError) {
|
|
284
|
+
io.stderr(renderRuntimeError(error));
|
|
285
|
+
return 1;
|
|
286
|
+
}
|
|
287
|
+
io.stderr(error instanceof Error ? error.message : String(error));
|
|
288
|
+
return 1;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function withTrailingNewline(value) {
|
|
292
|
+
return value.endsWith("\n") ? value : `${value}\n`;
|
|
293
|
+
}
|
|
294
|
+
async function runWatchedCommand(options) {
|
|
295
|
+
const controller = new AbortController();
|
|
296
|
+
const abort = () => controller.abort();
|
|
297
|
+
process.once("SIGINT", abort);
|
|
298
|
+
const stream = options.runtime.subscribe({
|
|
299
|
+
id: options.command.capability.id,
|
|
300
|
+
input: options.input,
|
|
301
|
+
signal: controller.signal
|
|
302
|
+
});
|
|
303
|
+
try {
|
|
304
|
+
let frame = 0;
|
|
305
|
+
let previousFrameLines = 0;
|
|
306
|
+
for await (const result of stream) {
|
|
307
|
+
if (options.json) {
|
|
308
|
+
options.io.stdout(`${JSON.stringify(result.output)}\n`);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const presentation = renderCapabilityResult(result, options);
|
|
312
|
+
options.io.stdout(formatWatchFrame(presentation, frame++, options.isTTY, previousFrameLines));
|
|
313
|
+
previousFrameLines = countFrameLines(presentation);
|
|
314
|
+
}
|
|
315
|
+
return 0;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (controller.signal.aborted || isAbortError(error)) return 0;
|
|
318
|
+
throw error;
|
|
319
|
+
} finally {
|
|
320
|
+
process.off("SIGINT", abort);
|
|
321
|
+
await stream.return?.();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function renderCapabilityResult(result, options) {
|
|
325
|
+
if (result.markdown !== void 0) return options.isTTY ? render(result.markdown, {
|
|
326
|
+
color: options.color,
|
|
327
|
+
width: options.columns
|
|
328
|
+
}) : result.markdown;
|
|
329
|
+
return typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2);
|
|
330
|
+
}
|
|
331
|
+
function formatWatchFrame(value, index, isTTY, previousFrameLines) {
|
|
332
|
+
const frame = value.endsWith("\n") ? value : `${value}\n`;
|
|
333
|
+
if (isTTY) return index === 0 ? frame : `\u001B[${previousFrameLines}A\r\u001B[0J${frame}`;
|
|
334
|
+
return index === 0 ? frame : `\n---\n\n${frame}`;
|
|
335
|
+
}
|
|
336
|
+
function countFrameLines(value) {
|
|
337
|
+
return (value.endsWith("\n") ? value : `${value}\n`).split("\n").length - 1;
|
|
338
|
+
}
|
|
339
|
+
function isAbortError(error) {
|
|
340
|
+
return error instanceof DOMException && error.name === "AbortError";
|
|
341
|
+
}
|
|
342
|
+
function parseArguments(argv, command, invocationName) {
|
|
343
|
+
const capability = command.capability;
|
|
344
|
+
const positional = command.meta.positional ?? [];
|
|
345
|
+
const commandName = `${invocationName} ${command.command.join(" ")}`;
|
|
346
|
+
const schema = capability.input;
|
|
347
|
+
const properties = schema?.properties;
|
|
348
|
+
const input = {};
|
|
349
|
+
let position = 0;
|
|
350
|
+
for (let index = 0; index < argv.length; index++) {
|
|
351
|
+
const token = argv[index];
|
|
352
|
+
if (token.startsWith("--")) {
|
|
353
|
+
const [rawName, inline] = token.slice(2).split("=", 2);
|
|
354
|
+
const name = camelCase(rawName);
|
|
355
|
+
const field = properties?.[name];
|
|
356
|
+
if (!field || positional.includes(name)) {
|
|
357
|
+
const suggestion = nearest(rawName, Object.keys(properties ?? {}).filter((candidate) => !positional.includes(candidate)).map(kebabCase));
|
|
358
|
+
throw new CliUsageError([
|
|
359
|
+
`Unknown option --${rawName}`,
|
|
360
|
+
...suggestion ? [`Did you mean \`--${suggestion}\`?`] : [],
|
|
361
|
+
`Run \`${commandName} --help\` to inspect accepted input.`
|
|
362
|
+
].join("\n"));
|
|
363
|
+
}
|
|
364
|
+
const boolean = field.type === "boolean";
|
|
365
|
+
const raw = inline ?? (boolean ? "true" : argv[++index]);
|
|
366
|
+
if (raw === void 0) throw new CliUsageError(`Option --${rawName} requires a value\nRun \`${commandName} --help\` to inspect accepted input.`);
|
|
367
|
+
input[name] = coerce(raw, field, `--${rawName}`, commandName);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const name = positional[position++];
|
|
371
|
+
if (!name) throw new CliUsageError(`Unexpected argument "${token}"\nRun \`${commandName} --help\` to inspect accepted input.`);
|
|
372
|
+
const field = properties?.[name];
|
|
373
|
+
if (!field) throw new CliUsageError(`CLI positional field "${name}" is not present in the input schema`);
|
|
374
|
+
input[name] = coerce(token, field, `<${name}>`, commandName);
|
|
375
|
+
}
|
|
376
|
+
const required = schema?.required;
|
|
377
|
+
for (const name of required ?? []) if (!(name in input)) throw new CliUsageError(`Missing ${positional.includes(name) ? `positional argument <${name}>` : `required option --${kebabCase(name)}`}\nRun \`${commandName} --help\` to inspect accepted input.`);
|
|
378
|
+
return input;
|
|
379
|
+
}
|
|
380
|
+
function coerce(value, schema, label, commandName) {
|
|
381
|
+
if (schema.type === "boolean") return value !== "false";
|
|
382
|
+
if (schema.type === "integer" || schema.type === "number") {
|
|
383
|
+
const number = Number(value);
|
|
384
|
+
if (!Number.isFinite(number)) throw new CliUsageError(`Expected a number for ${label}, received "${value}"\nRun \`${commandName} --help\` to inspect accepted input.`);
|
|
385
|
+
return number;
|
|
386
|
+
}
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
var CliUsageError = class extends Error {};
|
|
390
|
+
function renderRuntimeError(error) {
|
|
391
|
+
return error instanceof TransportError ? `${error.code}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
392
|
+
}
|
|
393
|
+
function matchCommand(argv, commands) {
|
|
394
|
+
return commands.filter((candidate) => candidate.command.every((token, index) => argv[index] === token)).sort((left, right) => right.command.length - left.command.length)[0];
|
|
395
|
+
}
|
|
396
|
+
function exactGroup(argv, groups) {
|
|
397
|
+
return groups.find((group) => group.command.length === argv.length && group.command.every((token, index) => argv[index] === token));
|
|
398
|
+
}
|
|
399
|
+
function unknownCommand(argv, commands, invocationName) {
|
|
400
|
+
const entered = argv.join(" ");
|
|
401
|
+
const suggestion = nearest(entered, commands.map((command) => command.command.join(" ")));
|
|
402
|
+
return [
|
|
403
|
+
`Unknown command: ${entered}`,
|
|
404
|
+
...suggestion ? [`Did you mean \`${suggestion}\`?`] : [],
|
|
405
|
+
`Run \`${invocationName} --help\` to list available commands.`
|
|
406
|
+
].join("\n");
|
|
407
|
+
}
|
|
408
|
+
function nearest(value, candidates) {
|
|
409
|
+
let match;
|
|
410
|
+
for (const candidate of new Set(candidates)) {
|
|
411
|
+
const distance = editDistance(value, candidate);
|
|
412
|
+
if (!match || distance < match.distance) match = {
|
|
413
|
+
candidate,
|
|
414
|
+
distance
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
if (!match) return void 0;
|
|
418
|
+
return match.distance <= Math.max(2, Math.floor(match.candidate.length / 3)) ? match.candidate : void 0;
|
|
419
|
+
}
|
|
420
|
+
function editDistance(left, right) {
|
|
421
|
+
const previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
422
|
+
for (let leftIndex = 1; leftIndex <= left.length; leftIndex++) {
|
|
423
|
+
const current = [leftIndex];
|
|
424
|
+
for (let rightIndex = 1; rightIndex <= right.length; rightIndex++) current[rightIndex] = Math.min(current[rightIndex - 1] + 1, previous[rightIndex] + 1, previous[rightIndex - 1] + (left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1));
|
|
425
|
+
previous.splice(0, previous.length, ...current);
|
|
426
|
+
}
|
|
427
|
+
return previous[right.length];
|
|
428
|
+
}
|
|
429
|
+
function camelCase(value) {
|
|
430
|
+
return value.replace(/-([a-z])/g, (_, character) => character.toUpperCase());
|
|
431
|
+
}
|
|
432
|
+
function kebabCase(value) {
|
|
433
|
+
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
export { runCli as n, createCli as t };
|
|
437
|
+
|
|
438
|
+
//# sourceMappingURL=src-CvWOGyGW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-CvWOGyGW.mjs","names":["kebabCase","renderMarkdown"],"sources":["../../cli/src/commands.ts","../../cli/src/style.ts","../../cli/src/help.ts","../../cli/src/index.ts"],"sourcesContent":["import type {\n ManifestGroup,\n ManifestNode,\n ManifestCapability,\n} from \"@capable/app\";\nimport type {\n CliGroupMeta,\n CliCapabilityMeta,\n} from \"./index.ts\";\n\nexport type CliCommand = {\n readonly command: readonly string[];\n readonly capability: ManifestCapability;\n readonly meta: Exclude<CliCapabilityMeta, false>;\n};\n\nexport type CliCommandGroup = {\n readonly command: readonly string[];\n readonly title?: string;\n readonly description?: string;\n};\n\nexport type CliCommandCatalog = {\n readonly commands: readonly CliCommand[];\n readonly groups: readonly CliCommandGroup[];\n};\n\nexport function collectCommands(\n nodes: readonly ManifestNode[],\n parent: readonly string[] = [],\n): CliCommandCatalog {\n const commands: CliCommand[] = [];\n const groups: CliCommandGroup[] = [];\n\n for (const node of nodes) {\n if (node.type === \"group\") {\n const meta = (node.meta.cli ?? {}) as CliGroupMeta;\n const command = [...parent, meta.name ?? node.key];\n groups.push(groupFrom(node, command));\n const children = collectCommands(node.children, command);\n commands.push(...children.commands);\n groups.push(...children.groups);\n continue;\n }\n\n const rawMeta = node.meta.cli as CliCapabilityMeta | undefined;\n if (rawMeta === false) continue;\n const meta = rawMeta ?? {};\n commands.push({\n command: meta.command ?? [...parent, meta.name ?? node.path.at(-1)!],\n capability: node,\n meta,\n });\n }\n\n return {\n commands: Object.freeze(commands),\n groups: Object.freeze(groups),\n };\n}\n\nfunction groupFrom(\n node: ManifestGroup,\n command: readonly string[],\n): CliCommandGroup {\n return Object.freeze({\n command: Object.freeze(command),\n ...(node.title ? { title: node.title } : {}),\n ...(node.description ? { description: node.description } : {}),\n });\n}\n","export type CliStyle = {\n readonly bold: (text: string) => string;\n readonly accent: (text: string) => string;\n readonly dim: (text: string) => string;\n};\n\nexport function createCliStyle(color?: boolean): CliStyle {\n const enabled = color ?? supportsColor();\n return {\n bold: enabled ? (text) => `\\u001B[1m${text}\\u001B[22m` : identity,\n accent: enabled ? (text) => `\\u001B[36m${text}\\u001B[39m` : identity,\n dim: enabled ? (text) => `\\u001B[2m${text}\\u001B[22m` : identity,\n };\n}\n\nexport function supportsColor(\n env: Record<string, string | undefined> = process.env,\n isTTY = Boolean(process.stdout.isTTY),\n): boolean {\n if (\"NO_COLOR\" in env) return false;\n if (env.FORCE_COLOR !== undefined) return env.FORCE_COLOR !== \"0\";\n return isTTY && env.TERM !== \"dumb\";\n}\n\nexport function renderRows(\n rows: readonly {\n readonly label: string;\n readonly description?: string;\n }[],\n style: CliStyle,\n): string {\n const width = Math.max(0, ...rows.map(({ label }) => label.length));\n return rows.map(({ label, description }) => {\n const styledLabel = style.accent(label);\n return description\n ? ` ${styledLabel}${\" \".repeat(width - label.length + 3)}${style.dim(description)}`\n : ` ${styledLabel}`;\n }).join(\"\\n\");\n}\n\nexport function renderSection(\n title: string,\n body: string,\n style: CliStyle,\n): string {\n return `${style.bold(title)}\\n${body}`;\n}\n\nfunction identity(text: string): string {\n return text;\n}\n","import type {\n ApplicationManifest,\n JsonSchema,\n} from \"@capable/app\";\nimport type {\n CliCommand,\n CliCommandGroup,\n} from \"./commands.ts\";\nimport {\n renderRows,\n renderSection,\n type CliStyle,\n} from \"./style.ts\";\n\nexport function renderRootHelp(\n manifest: Pick<ApplicationManifest, \"name\" | \"description\">,\n commands: readonly CliCommand[],\n invocationName: string,\n style: CliStyle,\n): string {\n return renderHelp([\n heading(manifest.name, manifest.description, style),\n renderSection(\n \"Usage\",\n ` ${style.accent(invocationName)} <command> [options]`,\n style,\n ),\n renderSection(\n \"Commands\",\n renderRows(commands.map((command) => ({\n label: commandLabel(command),\n ...(command.capability.title\n ? { description: command.capability.title }\n : {}),\n })), style),\n style,\n ),\n globalOptions(style),\n ]);\n}\n\nexport function renderGroupHelp(\n group: CliCommandGroup,\n commands: readonly CliCommand[],\n invocationName: string,\n style: CliStyle,\n): string {\n const children = commands\n .filter((candidate) => startsWith(candidate.command, group.command))\n .map((candidate) => {\n const suffix = candidate.command.slice(group.command.length);\n const positionals = candidate.meta.positional ?? [];\n return {\n label: [...suffix, ...positionals.map((name) => `<${name}>`)].join(\" \"),\n ...(candidate.capability.title\n ? { description: candidate.capability.title }\n : {}),\n };\n });\n return renderHelp([\n heading(\n group.title ?? group.command.at(-1)!,\n group.description,\n style,\n ),\n renderSection(\n \"Usage\",\n ` ${style.accent(`${invocationName} ${group.command.join(\" \")}`)} <command> [options]`,\n style,\n ),\n renderSection(\"Commands\", renderRows(children, style), style),\n globalOptions(style),\n ]);\n}\n\nexport function renderCommandHelp(\n command: CliCommand,\n invocationName: string,\n style: CliStyle,\n): string {\n const positionals = command.meta.positional ?? [];\n const properties = command.capability.input?.properties as\n | Record<string, JsonSchema>\n | undefined;\n const required = new Set(\n command.capability.input?.required as readonly string[] | undefined,\n );\n const argumentsRows = positionals.map((name) => ({\n label: `<${name}>`,\n description: describeField(properties?.[name], required.has(name)),\n }));\n const optionRows = Object.entries(properties ?? {})\n .filter(([name]) => !positionals.includes(name))\n .map(([name, schema]) => ({\n label: optionLabel(name, schema),\n description: describeField(schema, required.has(name)),\n }));\n const usage = [\n invocationName,\n ...command.command,\n ...positionals.map((name) => `<${name}>`),\n \"[options]\",\n ].join(\" \");\n\n return renderHelp([\n heading(\n command.capability.title ?? command.command.join(\" \"),\n command.capability.description,\n style,\n ),\n renderSection(\"Usage\", ` ${style.accent(usage)}`, style),\n argumentsRows.length\n ? renderSection(\"Arguments\", renderRows(argumentsRows, style), style)\n : undefined,\n renderSection(\"Options\", renderRows([\n ...optionRows,\n ...(command.capability.subscription\n ? [{\n label: \"--watch\",\n description: \"Stream updates until interrupted\",\n }]\n : []),\n { label: \"--json\", description: \"Print canonical JSON\" },\n { label: \"-h, --help\", description: \"Show command help\" },\n ], style), style),\n ]);\n}\n\nfunction globalOptions(style: CliStyle): string {\n return renderSection(\"Options\", renderRows([\n { label: \"--json\", description: \"Print canonical JSON\" },\n { label: \"-h, --help\", description: \"Show help\" },\n ], style), style);\n}\n\nfunction heading(\n title: string,\n description: string | undefined,\n style: CliStyle,\n): string {\n return description\n ? `${style.bold(title)}\\n\\n${style.dim(description)}`\n : style.bold(title);\n}\n\nfunction commandLabel(command: CliCommand): string {\n const positionals = (command.meta.positional ?? []).map((name) => `<${name}>`);\n return [...command.command, ...positionals].join(\" \");\n}\n\nfunction optionLabel(name: string, schema: JsonSchema): string {\n const flag = `--${kebabCase(name)}`;\n if (schema.type === \"boolean\") return flag;\n if (schema.type === \"array\" || schema.type === \"object\") {\n return `${flag} <json>`;\n }\n return `${flag} <${String(schema.type ?? \"value\")}>`;\n}\n\nfunction describeField(\n schema: JsonSchema | undefined,\n required: boolean,\n): string {\n const description = typeof schema?.description === \"string\"\n ? schema.description\n : undefined;\n const type = describeSchema(schema);\n return [\n description ? `${description} (${type})` : type,\n required ? \"required\" : undefined,\n schema?.default !== undefined ? `default: ${String(schema.default)}` : undefined,\n ].filter(Boolean).join(\", \");\n}\n\nfunction describeSchema(schema: JsonSchema | undefined): string {\n if (!schema) return \"value\";\n const type = schema.type === \"array\"\n ? `array<${String((schema.items as JsonSchema | undefined)?.type ?? \"value\")}>`\n : schema.type === \"object\"\n ? `object { ${Object.keys(\n schema.properties as Record<string, unknown> | undefined ?? {},\n ).join(\", \")} }`\n : String(schema.type ?? \"value\");\n const constraints: string[] = [];\n if (Array.isArray(schema.enum)) {\n constraints.push(`one of ${schema.enum.map(String).join(\", \")}`);\n }\n if (typeof schema.minLength === \"number\") {\n constraints.push(`minimum ${schema.minLength} characters`);\n }\n if (typeof schema.maxLength === \"number\") {\n constraints.push(`maximum ${schema.maxLength} characters`);\n }\n if (typeof schema.minimum === \"number\") {\n constraints.push(`minimum ${schema.minimum}`);\n }\n if (typeof schema.maximum === \"number\") {\n constraints.push(`maximum ${schema.maximum}`);\n }\n if (typeof schema.format === \"string\") {\n constraints.push(`format ${schema.format}`);\n }\n return [type, ...constraints].join(\", \");\n}\n\nfunction startsWith(\n value: readonly string[],\n prefix: readonly string[],\n): boolean {\n return prefix.every((part, index) => value[index] === part);\n}\n\nfunction kebabCase(value: string): string {\n return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);\n}\n\nfunction renderHelp(sections: readonly (string | undefined)[]): string {\n return `${sections.filter(Boolean).join(\"\\n\\n\")}\\n`;\n}\n","import type {\n GroupMetaRegistry,\n CapabilityMetaRegistry,\n} from \"@capable/core\";\nimport {\n getAppRuntime,\n TransportError,\n type AnyApp,\n type JsonSchema,\n type CapabilityResult,\n} from \"@capable/app\";\nimport { render as renderMarkdown } from \"markdansi\";\nimport {\n collectCommands,\n type CliCommand,\n type CliCommandGroup,\n} from \"./commands.ts\";\nimport {\n renderCommandHelp,\n renderGroupHelp,\n renderRootHelp,\n} from \"./help.ts\";\nimport {\n createCliStyle,\n supportsColor,\n} from \"./style.ts\";\n\nexport type CliCapabilityMeta =\n | false\n | {\n readonly name?: string;\n readonly command?: readonly string[];\n readonly positional?: readonly string[];\n };\n\nexport type CliGroupMeta = {\n readonly name?: string;\n};\n\ndeclare module \"@capable/core\" {\n interface CapabilityMetaRegistry {\n readonly cli?: CliCapabilityMeta;\n }\n\n interface GroupMetaRegistry {\n readonly cli?: CliGroupMeta;\n }\n}\n\nexport type CliIo = {\n readonly stdout: (text: string) => void;\n readonly stderr: (text: string) => void;\n};\n\nexport type CreateCliOptions = {\n readonly invocationName?: string;\n readonly color?: boolean;\n readonly isTTY?: boolean;\n readonly columns?: number;\n};\n\nexport function createCli(\n app: AnyApp,\n cliOptions: CreateCliOptions = {},\n): {\n run(\n argv: readonly string[],\n options?: { readonly io?: Partial<CliIo> },\n ): Promise<number>;\n} {\n return Object.freeze({\n run(argv, options = {}) {\n return runCli({\n app,\n argv,\n ...(cliOptions.invocationName\n ? { invocationName: cliOptions.invocationName }\n : {}),\n ...(cliOptions.color !== undefined ? { color: cliOptions.color } : {}),\n ...(cliOptions.isTTY !== undefined ? { isTTY: cliOptions.isTTY } : {}),\n ...(cliOptions.columns !== undefined\n ? { columns: cliOptions.columns }\n : {}),\n ...(options.io ? { io: options.io } : {}),\n });\n },\n });\n}\n\nexport async function runCli(options: {\n readonly app: AnyApp;\n readonly argv: readonly string[];\n readonly invocationName?: string;\n readonly color?: boolean;\n readonly isTTY?: boolean;\n readonly columns?: number;\n readonly io?: Partial<CliIo>;\n}): Promise<number> {\n const io: CliIo = {\n stdout: options.io?.stdout ??\n ((text) => process.stdout.write(withTrailingNewline(text))),\n stderr: options.io?.stderr ??\n ((text) => process.stderr.write(withTrailingNewline(text))),\n };\n const invocationName = options.invocationName ?? \"capable\";\n const isTTY = options.isTTY ?? Boolean(process.stdout.isTTY);\n const color = options.color ?? supportsColor(process.env, isTTY);\n const columns = options.columns ?? process.stdout.columns ?? 80;\n const style = createCliStyle(color);\n const runtime = getAppRuntime(options.app);\n let manifest;\n try {\n manifest = await runtime.manifest();\n } catch (error) {\n io.stderr(renderRuntimeError(error));\n return 1;\n }\n const catalog = collectCommands(manifest.capabilities);\n const json = options.argv.includes(\"--json\");\n const watch = options.argv.includes(\"--watch\");\n const wantsHelp = options.argv.includes(\"--help\") ||\n options.argv.includes(\"-h\");\n const argv = options.argv.filter((argument) =>\n ![\"--json\", \"--watch\", \"--help\", \"-h\"].includes(argument)\n );\n\n if (argv.length === 0) {\n io.stdout(renderRootHelp(\n manifest,\n catalog.commands,\n invocationName,\n style,\n ));\n return 0;\n }\n\n const command = matchCommand(argv, catalog.commands);\n const group = exactGroup(argv, catalog.groups);\n if (wantsHelp) {\n if (command) {\n io.stdout(renderCommandHelp(command, invocationName, style));\n return 0;\n }\n if (group) {\n io.stdout(renderGroupHelp(\n group,\n catalog.commands,\n invocationName,\n style,\n ));\n return 0;\n }\n io.stderr(unknownCommand(argv, catalog.commands, invocationName));\n return 2;\n }\n\n if (!command) {\n if (group) {\n io.stderr(\n `Missing command after ${group.command.join(\" \")}\\n` +\n `Run \\`${invocationName} ${group.command.join(\" \")} --help\\` to list available commands.`,\n );\n return 2;\n }\n io.stderr(unknownCommand(argv, catalog.commands, invocationName));\n return 2;\n }\n\n try {\n if (watch && !command.capability.subscription) {\n throw new CliUsageError(\n `Option --watch is only available for subscribable Capabilities`,\n );\n }\n const input = parseArguments(\n argv.slice(command.command.length),\n command,\n invocationName,\n );\n if (watch) {\n return await runWatchedCommand({\n runtime,\n command,\n input,\n json,\n io,\n color,\n isTTY,\n columns,\n });\n }\n const result = await runtime.call({\n id: command.capability.id,\n input,\n });\n io.stdout(\n json\n ? JSON.stringify(result.output, null, 2)\n : renderCapabilityResult(result, {\n color,\n isTTY,\n columns,\n }),\n );\n return 0;\n } catch (error) {\n if (error instanceof CliUsageError) {\n io.stderr(error.message);\n return 2;\n }\n if (error instanceof TransportError) {\n io.stderr(renderRuntimeError(error));\n return 1;\n }\n io.stderr(error instanceof Error ? error.message : String(error));\n return 1;\n }\n}\n\nfunction withTrailingNewline(value: string): string {\n return value.endsWith(\"\\n\") ? value : `${value}\\n`;\n}\n\nasync function runWatchedCommand(options: {\n readonly runtime: ReturnType<typeof getAppRuntime>;\n readonly command: CliCommand;\n readonly input: Record<string, unknown>;\n readonly json: boolean;\n readonly io: CliIo;\n readonly color: boolean;\n readonly isTTY: boolean;\n readonly columns: number;\n}): Promise<number> {\n const controller = new AbortController();\n const abort = () => controller.abort();\n process.once(\"SIGINT\", abort);\n const stream = options.runtime.subscribe({\n id: options.command.capability.id,\n input: options.input,\n signal: controller.signal,\n });\n\n try {\n let frame = 0;\n let previousFrameLines = 0;\n for await (const result of stream) {\n if (options.json) {\n options.io.stdout(`${JSON.stringify(result.output)}\\n`);\n continue;\n }\n const presentation = renderCapabilityResult(result, options);\n options.io.stdout(formatWatchFrame(\n presentation,\n frame++,\n options.isTTY,\n previousFrameLines,\n ));\n previousFrameLines = countFrameLines(presentation);\n }\n return 0;\n } catch (error) {\n if (controller.signal.aborted || isAbortError(error)) return 0;\n throw error;\n } finally {\n process.off(\"SIGINT\", abort);\n await stream.return?.();\n }\n}\n\nfunction renderCapabilityResult(\n result: CapabilityResult,\n options: {\n readonly color: boolean;\n readonly isTTY: boolean;\n readonly columns: number;\n },\n): string {\n if (result.markdown !== undefined) {\n return options.isTTY\n ? renderMarkdown(result.markdown, {\n color: options.color,\n width: options.columns,\n })\n : result.markdown;\n }\n return typeof result.output === \"string\"\n ? result.output\n : JSON.stringify(result.output, null, 2);\n}\n\nfunction formatWatchFrame(\n value: string,\n index: number,\n isTTY: boolean,\n previousFrameLines: number,\n): string {\n const frame = value.endsWith(\"\\n\") ? value : `${value}\\n`;\n if (isTTY) {\n return index === 0\n ? frame\n : `\\u001B[${previousFrameLines}A\\r\\u001B[0J${frame}`;\n }\n return index === 0 ? frame : `\\n---\\n\\n${frame}`;\n}\n\nfunction countFrameLines(value: string): number {\n const frame = value.endsWith(\"\\n\") ? value : `${value}\\n`;\n return frame.split(\"\\n\").length - 1;\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof DOMException && error.name === \"AbortError\";\n}\n\nfunction parseArguments(\n argv: readonly string[],\n command: CliCommand,\n invocationName: string,\n): Record<string, unknown> {\n const capability = command.capability;\n const positional = command.meta.positional ?? [];\n const commandName = `${invocationName} ${command.command.join(\" \")}`;\n const schema = capability.input;\n const properties = schema?.properties as\n | Record<string, JsonSchema>\n | undefined;\n const input: Record<string, unknown> = {};\n let position = 0;\n\n for (let index = 0; index < argv.length; index++) {\n const token = argv[index]!;\n if (token.startsWith(\"--\")) {\n const [rawName, inline] = token.slice(2).split(\"=\", 2);\n const name = camelCase(rawName!);\n const field = properties?.[name];\n if (!field || positional.includes(name)) {\n const suggestion = nearest(\n rawName!,\n Object.keys(properties ?? {})\n .filter((candidate) => !positional.includes(candidate))\n .map(kebabCase),\n );\n throw new CliUsageError([\n `Unknown option --${rawName}`,\n ...(suggestion ? [`Did you mean \\`--${suggestion}\\`?`] : []),\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n ].join(\"\\n\"));\n }\n const boolean = field.type === \"boolean\";\n const raw = inline ?? (boolean ? \"true\" : argv[++index]);\n if (raw === undefined) {\n throw new CliUsageError(\n `Option --${rawName} requires a value\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n input[name] = coerce(raw, field, `--${rawName}`, commandName);\n continue;\n }\n const name = positional[position++];\n if (!name) {\n throw new CliUsageError(\n `Unexpected argument \"${token}\"\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n const field = properties?.[name];\n if (!field) {\n throw new CliUsageError(\n `CLI positional field \"${name}\" is not present in the input schema`,\n );\n }\n input[name] = coerce(token, field, `<${name}>`, commandName);\n }\n\n const required = schema?.required as readonly string[] | undefined;\n for (const name of required ?? []) {\n if (!(name in input)) {\n const label = positional.includes(name)\n ? `positional argument <${name}>`\n : `required option --${kebabCase(name)}`;\n throw new CliUsageError(\n `Missing ${label}\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n }\n return input;\n}\n\nfunction coerce(\n value: string,\n schema: JsonSchema,\n label: string,\n commandName: string,\n): unknown {\n if (schema.type === \"boolean\") return value !== \"false\";\n if (schema.type === \"integer\" || schema.type === \"number\") {\n const number = Number(value);\n if (!Number.isFinite(number)) {\n throw new CliUsageError(\n `Expected a number for ${label}, received \"${value}\"\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n return number;\n }\n return value;\n}\n\nclass CliUsageError extends Error {}\n\nfunction renderRuntimeError(error: unknown): string {\n return error instanceof TransportError\n ? `${error.code}: ${error.message}`\n : error instanceof Error\n ? error.message\n : String(error);\n}\n\nfunction matchCommand(\n argv: readonly string[],\n commands: readonly CliCommand[],\n): CliCommand | undefined {\n return commands\n .filter((candidate) =>\n candidate.command.every((token, index) => argv[index] === token)\n )\n .sort((left, right) => right.command.length - left.command.length)[0];\n}\n\nfunction exactGroup(\n argv: readonly string[],\n groups: readonly CliCommandGroup[],\n): CliCommandGroup | undefined {\n return groups.find((group) =>\n group.command.length === argv.length &&\n group.command.every((token, index) => argv[index] === token)\n );\n}\n\nfunction unknownCommand(\n argv: readonly string[],\n commands: readonly CliCommand[],\n invocationName: string,\n): string {\n const entered = argv.join(\" \");\n const suggestion = nearest(\n entered,\n commands.map((command) => command.command.join(\" \")),\n );\n return [\n `Unknown command: ${entered}`,\n ...(suggestion ? [`Did you mean \\`${suggestion}\\`?`] : []),\n `Run \\`${invocationName} --help\\` to list available commands.`,\n ].join(\"\\n\");\n}\n\nfunction nearest(\n value: string,\n candidates: readonly string[],\n): string | undefined {\n let match: { readonly candidate: string; readonly distance: number } | undefined;\n for (const candidate of new Set(candidates)) {\n const distance = editDistance(value, candidate);\n if (!match || distance < match.distance) {\n match = { candidate, distance };\n }\n }\n if (!match) return undefined;\n return match.distance <= Math.max(2, Math.floor(match.candidate.length / 3))\n ? match.candidate\n : undefined;\n}\n\nfunction editDistance(left: string, right: string): number {\n const previous = Array.from(\n { length: right.length + 1 },\n (_, index) => index,\n );\n for (let leftIndex = 1; leftIndex <= left.length; leftIndex++) {\n const current = [leftIndex];\n for (let rightIndex = 1; rightIndex <= right.length; rightIndex++) {\n current[rightIndex] = Math.min(\n current[rightIndex - 1]! + 1,\n previous[rightIndex]! + 1,\n previous[rightIndex - 1]! +\n (left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1),\n );\n }\n previous.splice(0, previous.length, ...current);\n }\n return previous[right.length]!;\n}\n\nfunction camelCase(value: string): string {\n return value.replace(/-([a-z])/g, (_, character: string) =>\n character.toUpperCase()\n );\n}\n\nfunction kebabCase(value: string): string {\n return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);\n}\n"],"mappings":";;;AA2BA,SAAgB,gBACd,OACA,SAA4B,CAAC,GACV;CACnB,MAAM,WAAyB,CAAC;CAChC,MAAM,SAA4B,CAAC;CAEnC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,SAAS;GACzB,MAAM,OAAQ,KAAK,KAAK,OAAO,CAAC;GAChC,MAAM,UAAU,CAAC,GAAG,QAAQ,KAAK,QAAQ,KAAK,GAAG;GACjD,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC;GACpC,MAAM,WAAW,gBAAgB,KAAK,UAAU,OAAO;GACvD,SAAS,KAAK,GAAG,SAAS,QAAQ;GAClC,OAAO,KAAK,GAAG,SAAS,MAAM;GAC9B;EACF;EAEA,MAAM,UAAU,KAAK,KAAK;EAC1B,IAAI,YAAY,OAAO;EACvB,MAAM,OAAO,WAAW,CAAC;EACzB,SAAS,KAAK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