@kjanat/dreamcli 3.0.0-rc.1 → 3.0.0-rc.11
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 +227 -1
- package/dist/core/cli/dispatch.d.mts +6 -5
- package/dist/core/cli/dispatch.mjs +205 -1
- package/dist/core/cli/help-links.d.mts +0 -1
- package/dist/core/cli/help-links.mjs +41 -1
- package/dist/core/cli/index.d.mts +81 -8
- package/dist/core/cli/index.mjs +945 -1
- package/dist/core/cli/planner.d.mts +5 -1
- package/dist/core/cli/planner.mjs +300 -1
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/plugin.mjs +41 -1
- package/dist/core/cli/propagate.d.mts +1 -1
- package/dist/core/cli/propagate.mjs +57 -1
- package/dist/core/cli/root-help.d.mts +2 -1
- package/dist/core/cli/root-help.mjs +226 -4
- package/dist/core/cli/root-surface.d.mts +12 -1
- package/dist/core/cli/root-surface.mjs +28 -1
- package/dist/core/cli/runtime-preflight.d.mts +14 -2
- package/dist/core/cli/runtime-preflight.mjs +169 -1
- package/dist/core/completion/index.d.mts +0 -1
- package/dist/core/completion/index.mjs +90 -1
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +308 -3
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +162 -2
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +358 -2
- package/dist/core/completion/shells/shared.d.mts +13 -2
- package/dist/core/completion/shells/shared.mjs +176 -1
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +251 -2
- package/dist/core/config/index.d.mts +2 -3
- package/dist/core/config/index.mjs +246 -1
- package/dist/core/config/package-json.d.mts +27 -4
- package/dist/core/config/package-json.mjs +386 -3
- package/dist/core/errors/index.d.mts +3 -3
- package/dist/core/errors/index.mjs +87 -1
- package/dist/core/execution/index.d.mts +0 -1
- package/dist/core/execution/index.mjs +201 -1
- package/dist/core/help/ansi.d.mts +11 -5
- package/dist/core/help/ansi.mjs +121 -2
- package/dist/core/help/index.d.mts +22 -3
- package/dist/core/help/index.mjs +341 -7
- package/dist/core/help/theme.d.mts +68 -0
- package/dist/core/help/theme.mjs +46 -0
- package/dist/core/json-schema/index.d.mts +15 -2
- package/dist/core/json-schema/index.mjs +536 -12
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +55 -38
- package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
- package/dist/core/output/activity.d.mts +0 -1
- package/dist/core/output/activity.mjs +452 -1
- package/dist/core/output/bind.mjs +56 -1
- package/dist/core/output/contracts.d.mts +4 -5
- package/dist/core/output/contracts.mjs +57 -1
- package/dist/core/output/display-value.mjs +32 -1
- package/dist/core/output/index.d.mts +21 -1
- package/dist/core/output/index.mjs +442 -2
- package/dist/core/output/renderers.d.mts +0 -1
- package/dist/core/output/renderers.mjs +46 -1
- package/dist/core/output/writer.mjs +12 -1
- package/dist/core/parse/index.d.mts +40 -7
- package/dist/core/parse/index.mjs +727 -1
- package/dist/core/prompt/index.d.mts +1 -1
- package/dist/core/prompt/index.mjs +348 -6
- package/dist/core/resolve/args.d.mts +1 -1
- package/dist/core/resolve/args.mjs +105 -1
- package/dist/core/resolve/coerce.d.mts +1 -1
- package/dist/core/resolve/coerce.mjs +336 -1
- package/dist/core/resolve/config.mjs +19 -1
- package/dist/core/resolve/contracts.d.mts +9 -4
- package/dist/core/resolve/errors.d.mts +0 -1
- package/dist/core/resolve/errors.mjs +140 -2
- package/dist/core/resolve/flags.d.mts +7 -2
- package/dist/core/resolve/flags.mjs +251 -1
- package/dist/core/resolve/index.d.mts +2 -2
- package/dist/core/resolve/index.mjs +85 -1
- package/dist/core/resolve/property.d.mts +4 -2
- package/dist/core/resolve/property.mjs +53 -1
- package/dist/core/schema/activity.d.mts +31 -11
- package/dist/core/schema/arg.d.mts +3 -4
- package/dist/core/schema/arg.mjs +463 -1
- package/dist/core/schema/command.d.mts +26 -6
- package/dist/core/schema/command.mjs +726 -1
- package/dist/core/schema/flag.d.mts +485 -19
- package/dist/core/schema/flag.mjs +705 -1
- package/dist/core/schema/index.d.mts +4 -2
- package/dist/core/schema/middleware.d.mts +4 -3
- package/dist/core/schema/middleware.mjs +41 -1
- package/dist/core/schema/number-constraints.mjs +60 -1
- package/dist/core/schema/prompt.d.mts +6 -3
- package/dist/core/schema/run.d.mts +20 -1
- package/dist/core/schema/string-constraints.d.mts +97 -0
- package/dist/core/schema/string-constraints.mjs +69 -0
- package/dist/core/schema/value-parsers.d.mts +78 -0
- package/dist/core/schema/value-parsers.mjs +142 -0
- package/dist/core/schema-dsl/runtime.mjs +271 -2
- package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
- package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
- package/dist/core/testkit/index.d.mts +0 -31
- package/dist/core/testkit/index.mjs +83 -1
- package/dist/index.d.mts +11 -6
- package/dist/index.mjs +22 -1
- package/dist/runtime/adapter.d.mts +38 -2
- package/dist/runtime/adapter.mjs +87 -1
- package/dist/runtime/auto.d.mts +2 -3
- package/dist/runtime/auto.mjs +45 -1
- package/dist/runtime/deno.d.mts +24 -5
- package/dist/runtime/deno.mjs +262 -2
- package/dist/runtime/detect.mjs +45 -1
- package/dist/runtime/index.d.mts +3 -4
- package/dist/runtime/node.d.mts +8 -2
- package/dist/runtime/node.mjs +220 -2
- package/dist/runtime/paths.mjs +48 -1
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +6 -1
- package/dist/strings.mjs +22 -1
- package/dist/testkit.d.mts +1 -0
- package/dist/testkit.mjs +5 -1
- package/dist/version.d.mts +7 -3
- package/dist/version.mjs +7 -1
- package/dreamcli.schema.json +36 -7
- package/package.json +45 -42
- package/dist/runtime/bun.d.mts +0 -28
- package/dist/runtime/bun.mjs +0 -1
- package/src/core/cli/dispatch.ts +0 -355
- package/src/core/cli/help-links.ts +0 -82
- package/src/core/cli/index.ts +0 -1614
- package/src/core/cli/planner.ts +0 -656
- package/src/core/cli/plugin.ts +0 -117
- package/src/core/cli/propagate.ts +0 -97
- package/src/core/cli/root-help.ts +0 -342
- package/src/core/cli/root-surface.ts +0 -87
- package/src/core/cli/runtime-preflight.ts +0 -456
- package/src/core/completion/index.ts +0 -138
- package/src/core/completion/shells/bash.ts +0 -459
- package/src/core/completion/shells/fish.ts +0 -259
- package/src/core/completion/shells/powershell.ts +0 -439
- package/src/core/completion/shells/shared.ts +0 -310
- package/src/core/completion/shells/zsh.ts +0 -381
- package/src/core/config/index.ts +0 -417
- package/src/core/config/package-json.ts +0 -560
- package/src/core/errors/index.ts +0 -193
- package/src/core/execution/index.ts +0 -265
- package/src/core/help/ansi.ts +0 -144
- package/src/core/help/index.ts +0 -563
- package/src/core/json-schema/index.ts +0 -910
- package/src/core/json-schema/meta-descriptions.generated.ts +0 -202
- package/src/core/output/activity.ts +0 -575
- package/src/core/output/bind.ts +0 -59
- package/src/core/output/contracts.ts +0 -194
- package/src/core/output/display-value.ts +0 -48
- package/src/core/output/index.ts +0 -704
- package/src/core/output/renderers.ts +0 -125
- package/src/core/output/writer.ts +0 -46
- package/src/core/parse/index.ts +0 -742
- package/src/core/prompt/index.ts +0 -623
- package/src/core/resolve/args.ts +0 -144
- package/src/core/resolve/coerce.ts +0 -500
- package/src/core/resolve/config.ts +0 -26
- package/src/core/resolve/contracts.ts +0 -135
- package/src/core/resolve/errors.ts +0 -227
- package/src/core/resolve/flags.ts +0 -269
- package/src/core/resolve/index.ts +0 -108
- package/src/core/resolve/property.ts +0 -99
- package/src/core/schema/activity.ts +0 -240
- package/src/core/schema/arg.ts +0 -841
- package/src/core/schema/command.ts +0 -1500
- package/src/core/schema/flag.ts +0 -917
- package/src/core/schema/index.ts +0 -96
- package/src/core/schema/middleware.ts +0 -171
- package/src/core/schema/number-constraints.ts +0 -153
- package/src/core/schema/prompt.ts +0 -171
- package/src/core/schema/run.ts +0 -198
- package/src/core/schema-dsl/index.ts +0 -109
- package/src/core/schema-dsl/parse.ts +0 -262
- package/src/core/schema-dsl/runtime.ts +0 -609
- package/src/core/schema-dsl/to-json-schema.ts +0 -102
- package/src/core/testkit/index.ts +0 -147
- package/src/index.ts +0 -181
- package/src/runtime/adapter.ts +0 -303
- package/src/runtime/auto.ts +0 -86
- package/src/runtime/bun.ts +0 -48
- package/src/runtime/deno.ts +0 -367
- package/src/runtime/detect.ts +0 -105
- package/src/runtime/index.ts +0 -21
- package/src/runtime/node-builtins.d.ts +0 -27
- package/src/runtime/node.ts +0 -289
- package/src/runtime/paths.ts +0 -64
- package/src/runtime/support.ts +0 -77
- package/src/runtime.ts +0 -31
- package/src/schema.ts +0 -16
- package/src/strings.ts +0 -34
- package/src/testkit.ts +0 -25
- package/src/version.ts +0 -20
|
@@ -1,2 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/core/schema-dsl/runtime.ts
|
|
2
|
+
/** Map single characters to their token kinds. */
|
|
3
|
+
const SINGLE_CHAR_TOKENS = {
|
|
4
|
+
"{": "lbrace",
|
|
5
|
+
"}": "rbrace",
|
|
6
|
+
"[": "lbracket",
|
|
7
|
+
"]": "rbracket",
|
|
8
|
+
"<": "langle",
|
|
9
|
+
">": "rangle",
|
|
10
|
+
",": "comma",
|
|
11
|
+
":": "colon",
|
|
12
|
+
";": "semicolon",
|
|
13
|
+
"?": "question",
|
|
14
|
+
"|": "pipe"
|
|
15
|
+
};
|
|
16
|
+
/** Whitespace characters to skip. */
|
|
17
|
+
function isWhitespace(c) {
|
|
18
|
+
return c === " " || c === "\n" || c === " " || c === "\r";
|
|
19
|
+
}
|
|
20
|
+
/** Identifier-valid characters (a-z, A-Z, 0-9, _, $). */
|
|
21
|
+
function isIdentChar(c) {
|
|
22
|
+
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9" || c === "_" || c === "$";
|
|
23
|
+
}
|
|
24
|
+
/** Identifier start characters (a-z, A-Z, _, $). */
|
|
25
|
+
function isIdentStart(c) {
|
|
26
|
+
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c === "$";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Tokenize a schema source string.
|
|
30
|
+
*
|
|
31
|
+
* Produces a flat array of tokens: identifiers (`string`, `number`, etc.),
|
|
32
|
+
* punctuation (`{`, `}`, `[`, `]`, `:`, `;`, `?`, `|`), and skips
|
|
33
|
+
* whitespace. Throws on unrecognized characters.
|
|
34
|
+
*/
|
|
35
|
+
function tokenize(source) {
|
|
36
|
+
const tokens = [];
|
|
37
|
+
let i = 0;
|
|
38
|
+
while (i < source.length) {
|
|
39
|
+
const c = source[i] ?? "";
|
|
40
|
+
if (isWhitespace(c)) {
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const singleKind = SINGLE_CHAR_TOKENS[c];
|
|
45
|
+
if (singleKind !== void 0) {
|
|
46
|
+
tokens.push({
|
|
47
|
+
kind: singleKind,
|
|
48
|
+
value: c
|
|
49
|
+
});
|
|
50
|
+
i++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (c === "'") {
|
|
54
|
+
let lit = "";
|
|
55
|
+
i++;
|
|
56
|
+
while (i < source.length && source[i] !== "'") {
|
|
57
|
+
lit += source[i];
|
|
58
|
+
i++;
|
|
59
|
+
}
|
|
60
|
+
if (i >= source.length) throw new SyntaxError("Unterminated string literal");
|
|
61
|
+
i++;
|
|
62
|
+
tokens.push({
|
|
63
|
+
kind: "string_literal",
|
|
64
|
+
value: lit
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (c === "@") {
|
|
69
|
+
i++;
|
|
70
|
+
let ref = "";
|
|
71
|
+
while (i < source.length) {
|
|
72
|
+
const ch = source[i] ?? "";
|
|
73
|
+
if (!isIdentChar(ch)) break;
|
|
74
|
+
ref += ch;
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
if (ref.length === 0) throw new SyntaxError(`Expected identifier after '@' at position ${String(i)}`);
|
|
78
|
+
tokens.push({
|
|
79
|
+
kind: "ref",
|
|
80
|
+
value: ref
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (isIdentStart(c)) {
|
|
85
|
+
let ident = "";
|
|
86
|
+
while (i < source.length) {
|
|
87
|
+
const ch = source[i] ?? "";
|
|
88
|
+
if (!isIdentChar(ch)) break;
|
|
89
|
+
ident += ch;
|
|
90
|
+
i++;
|
|
91
|
+
}
|
|
92
|
+
tokens.push({
|
|
93
|
+
kind: "ident",
|
|
94
|
+
value: ident
|
|
95
|
+
});
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
throw new SyntaxError(`Unexpected character '${c}' at position ${String(i)}`);
|
|
99
|
+
}
|
|
100
|
+
return tokens;
|
|
101
|
+
}
|
|
102
|
+
/** Primitive type names recognized by the parser. */
|
|
103
|
+
const PRIMITIVES = /* @__PURE__ */ new Set([
|
|
104
|
+
"string",
|
|
105
|
+
"number",
|
|
106
|
+
"integer",
|
|
107
|
+
"boolean",
|
|
108
|
+
"true",
|
|
109
|
+
"false",
|
|
110
|
+
"null",
|
|
111
|
+
"undefined",
|
|
112
|
+
"unknown",
|
|
113
|
+
"never"
|
|
114
|
+
]);
|
|
115
|
+
/** Map a primitive name to its AST node. */
|
|
116
|
+
function primitiveNode(name) {
|
|
117
|
+
switch (name) {
|
|
118
|
+
case "string": return { kind: "string" };
|
|
119
|
+
case "number": return { kind: "number" };
|
|
120
|
+
case "integer": return { kind: "integer" };
|
|
121
|
+
case "boolean": return { kind: "boolean" };
|
|
122
|
+
case "true": return { kind: "true" };
|
|
123
|
+
case "false": return { kind: "false" };
|
|
124
|
+
case "null": return { kind: "null" };
|
|
125
|
+
case "undefined": return { kind: "undefined" };
|
|
126
|
+
case "unknown": return { kind: "unknown" };
|
|
127
|
+
case "never": return { kind: "never" };
|
|
128
|
+
default: throw new SyntaxError(`Unknown type '${name}'`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse a token stream into a {@link SchemaNode} AST.
|
|
133
|
+
*
|
|
134
|
+
* Implements the grammar documented at the module level using standard
|
|
135
|
+
* recursive descent. Each grammar rule maps to one `parse*` method.
|
|
136
|
+
*/
|
|
137
|
+
var SchemaParser = class {
|
|
138
|
+
tokens;
|
|
139
|
+
pos = 0;
|
|
140
|
+
constructor(tokens) {
|
|
141
|
+
this.tokens = tokens;
|
|
142
|
+
}
|
|
143
|
+
/** Parse the full token stream, asserting all tokens are consumed. */
|
|
144
|
+
parseRoot() {
|
|
145
|
+
const result = this.parseValue();
|
|
146
|
+
if (this.pos < this.tokens.length) {
|
|
147
|
+
const leftover = this.peek();
|
|
148
|
+
throw new SyntaxError(`Unexpected token '${leftover?.value ?? "?"}' at position ${String(this.pos)}`);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
/** value = union */
|
|
153
|
+
parseValue() {
|
|
154
|
+
return this.parseUnion();
|
|
155
|
+
}
|
|
156
|
+
/** union = postfix ('|' postfix)* */
|
|
157
|
+
parseUnion() {
|
|
158
|
+
const first = this.parsePostfix();
|
|
159
|
+
if (!this.check("pipe")) return first;
|
|
160
|
+
const members = [first];
|
|
161
|
+
while (this.match("pipe")) members.push(this.parsePostfix());
|
|
162
|
+
return {
|
|
163
|
+
kind: "union",
|
|
164
|
+
members
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** postfix = primary ('[]')* */
|
|
168
|
+
parsePostfix() {
|
|
169
|
+
let node = this.parsePrimary();
|
|
170
|
+
while (this.check("lbracket") && this.checkAt(this.pos + 1, "rbracket")) {
|
|
171
|
+
this.advance();
|
|
172
|
+
this.advance();
|
|
173
|
+
node = {
|
|
174
|
+
kind: "array",
|
|
175
|
+
element: node
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return node;
|
|
179
|
+
}
|
|
180
|
+
/** primary = object | record | ref | literal | IDENT */
|
|
181
|
+
parsePrimary() {
|
|
182
|
+
if (this.check("lbrace")) return this.parseObject();
|
|
183
|
+
if (this.check("string_literal")) return {
|
|
184
|
+
kind: "literal",
|
|
185
|
+
value: this.advance().value
|
|
186
|
+
};
|
|
187
|
+
if (this.check("ref")) return {
|
|
188
|
+
kind: "ref",
|
|
189
|
+
target: this.advance().value
|
|
190
|
+
};
|
|
191
|
+
const name = this.expectIdent();
|
|
192
|
+
if (name === "Record") {
|
|
193
|
+
this.expect("langle");
|
|
194
|
+
if (this.parseValue().kind !== "string") throw new SyntaxError("Record key type must be 'string' because JSON object keys are always strings");
|
|
195
|
+
this.expect("comma");
|
|
196
|
+
const valueSchema = this.parseValue();
|
|
197
|
+
this.expect("rangle");
|
|
198
|
+
return {
|
|
199
|
+
kind: "record",
|
|
200
|
+
value: valueSchema
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (!PRIMITIVES.has(name)) throw new SyntaxError(`Unknown type '${name}' at position ${String(this.pos - 1)}`);
|
|
204
|
+
return primitiveNode(name);
|
|
205
|
+
}
|
|
206
|
+
/** object = '{' properties '}' */
|
|
207
|
+
parseObject() {
|
|
208
|
+
this.expect("lbrace");
|
|
209
|
+
const properties = {};
|
|
210
|
+
while (!this.check("rbrace")) {
|
|
211
|
+
const name = this.expectIdent();
|
|
212
|
+
if (Object.hasOwn(properties, name)) throw new SyntaxError(`Duplicate property '${name}' at position ${String(this.pos - 1)}`);
|
|
213
|
+
const optional = this.match("question");
|
|
214
|
+
this.expect("colon");
|
|
215
|
+
properties[name] = {
|
|
216
|
+
optional,
|
|
217
|
+
schema: this.parseValue()
|
|
218
|
+
};
|
|
219
|
+
this.match("semicolon");
|
|
220
|
+
}
|
|
221
|
+
this.expect("rbrace");
|
|
222
|
+
return {
|
|
223
|
+
kind: "object",
|
|
224
|
+
properties
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
peek() {
|
|
228
|
+
return this.tokens[this.pos];
|
|
229
|
+
}
|
|
230
|
+
check(kind) {
|
|
231
|
+
return this.peek()?.kind === kind;
|
|
232
|
+
}
|
|
233
|
+
checkAt(pos, kind) {
|
|
234
|
+
return this.tokens[pos]?.kind === kind;
|
|
235
|
+
}
|
|
236
|
+
advance() {
|
|
237
|
+
const token = this.tokens[this.pos];
|
|
238
|
+
if (token === void 0) throw new SyntaxError("Unexpected end of input");
|
|
239
|
+
this.pos++;
|
|
240
|
+
return token;
|
|
241
|
+
}
|
|
242
|
+
match(kind) {
|
|
243
|
+
if (this.check(kind)) {
|
|
244
|
+
this.pos++;
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
expect(kind) {
|
|
250
|
+
if (!this.check(kind)) {
|
|
251
|
+
const got = this.peek();
|
|
252
|
+
throw new SyntaxError(got ? `Expected '${kind}' but got '${got.kind}' ('${got.value}') at position ${String(this.pos)}` : `Expected '${kind}' but reached end of input`);
|
|
253
|
+
}
|
|
254
|
+
return this.advance();
|
|
255
|
+
}
|
|
256
|
+
expectIdent() {
|
|
257
|
+
return this.expect("ident").value;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Parse a schema source string into a runtime AST.
|
|
262
|
+
*
|
|
263
|
+
* @param source - Schema string (e.g. `"{ name: string; age: number }"`).
|
|
264
|
+
* @returns The root {@link SchemaNode}.
|
|
265
|
+
* @throws {@link SyntaxError} on malformed input.
|
|
266
|
+
*/
|
|
267
|
+
function parseSchema(source) {
|
|
268
|
+
return new SchemaParser(tokenize(source)).parseRoot();
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
export { parseSchema };
|
|
@@ -1 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/core/schema-dsl/to-json-schema.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert a {@link SchemaNode} AST node to a JSON Schema fragment.
|
|
4
|
+
*
|
|
5
|
+
* Mapping:
|
|
6
|
+
* - `string` → `{ type: 'string' }`
|
|
7
|
+
* - `number` → `{ type: 'number' }`
|
|
8
|
+
* - `integer` → `{ type: 'integer' }`
|
|
9
|
+
* - `boolean` → `{ type: 'boolean' }`
|
|
10
|
+
* - `true` → `{ const: true }`
|
|
11
|
+
* - `false` → `{ const: false }`
|
|
12
|
+
* - `null` → `{ type: 'null' }`
|
|
13
|
+
* - `undefined` → throws (JSON Schema has no `undefined` type)
|
|
14
|
+
* - `unknown` → `{}` (accepts any value)
|
|
15
|
+
* - `never` → `{ not: {} }` (rejects all values)
|
|
16
|
+
* - `'literal'` → `{ const: 'literal' }`
|
|
17
|
+
* - `@ref` → `{ $ref: '#/$defs/ref' }`
|
|
18
|
+
* - `T[]` → `{ type: 'array', items: convert(T) }`
|
|
19
|
+
* - `Record<K,V>` → `{ type: 'object', additionalProperties: convert(V) }`
|
|
20
|
+
* - `{...}` → `{ type: 'object', properties: ..., required: [...] }`
|
|
21
|
+
* - `A | B` → `{ enum: [...] }` if all literals, else `{ oneOf: [...] }`
|
|
22
|
+
*
|
|
23
|
+
* @param node - The AST node to convert.
|
|
24
|
+
* @returns A plain JSON Schema fragment.
|
|
25
|
+
*/
|
|
26
|
+
function nodeToJsonSchema(node) {
|
|
27
|
+
switch (node.kind) {
|
|
28
|
+
case "string": return { type: "string" };
|
|
29
|
+
case "number": return { type: "number" };
|
|
30
|
+
case "integer": return { type: "integer" };
|
|
31
|
+
case "boolean": return { type: "boolean" };
|
|
32
|
+
case "true": return { const: true };
|
|
33
|
+
case "false": return { const: false };
|
|
34
|
+
case "null": return { type: "null" };
|
|
35
|
+
case "literal": return { const: node.value };
|
|
36
|
+
case "undefined": throw new Error("Cannot convert 'undefined' type to JSON Schema; model optionality at the parent level");
|
|
37
|
+
case "unknown": return {};
|
|
38
|
+
case "never": return { not: {} };
|
|
39
|
+
case "ref": return { $ref: `#/$defs/${node.target}` };
|
|
40
|
+
case "array": return {
|
|
41
|
+
type: "array",
|
|
42
|
+
items: nodeToJsonSchema(node.element)
|
|
43
|
+
};
|
|
44
|
+
case "record": return {
|
|
45
|
+
type: "object",
|
|
46
|
+
additionalProperties: nodeToJsonSchema(node.value)
|
|
47
|
+
};
|
|
48
|
+
case "object": {
|
|
49
|
+
const properties = {};
|
|
50
|
+
const required = [];
|
|
51
|
+
for (const [key, prop] of Object.entries(node.properties)) {
|
|
52
|
+
properties[key] = nodeToJsonSchema(prop.schema);
|
|
53
|
+
if (!prop.optional) required.push(key);
|
|
54
|
+
}
|
|
55
|
+
const result = {
|
|
56
|
+
type: "object",
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
properties
|
|
59
|
+
};
|
|
60
|
+
if (required.length > 0) result.required = required;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
case "union": {
|
|
64
|
+
const literalValues = [];
|
|
65
|
+
let allLiteral = true;
|
|
66
|
+
for (const member of node.members) if (member.kind === "literal") literalValues.push(member.value);
|
|
67
|
+
else allLiteral = false;
|
|
68
|
+
if (allLiteral) return { enum: literalValues };
|
|
69
|
+
return { oneOf: node.members.map(nodeToJsonSchema) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { nodeToJsonSchema };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RunOptions, RunResult } from "../schema/run.mjs";
|
|
2
2
|
import { RunnableCommand } from "../schema/command.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/core/testkit/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Run a command builder against the given argv with injected options.
|
|
@@ -24,35 +23,5 @@ import { RunnableCommand } from "../schema/command.mjs";
|
|
|
24
23
|
* @returns Structured run result with exit code and captured output
|
|
25
24
|
*/
|
|
26
25
|
declare function runCommand(cmd: RunnableCommand, argv: readonly string[], options?: RunOptions): Promise<RunResult>;
|
|
27
|
-
/**
|
|
28
|
-
* Options for {@linkcode runCommand} — process-free command execution.
|
|
29
|
-
*
|
|
30
|
-
* Every field is optional. Inject env, config, prompt answers, and
|
|
31
|
-
* output capture without touching process state.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const result = await runCommand(cmd, ['--verbose'], {
|
|
36
|
-
* env: { LOG_LEVEL: 'debug' },
|
|
37
|
-
* config: { theme: 'dark' },
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* Structured result from {@linkcode runCommand}.
|
|
43
|
-
*
|
|
44
|
-
* Contains the exit code, captured stdout/stderr output, recorded
|
|
45
|
-
* {@linkcode ActivityEvent | activity events}, and an `error` field
|
|
46
|
-
* that is `undefined` on success and a {@linkcode CLIError} on failure.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const result = await runCommand(greetCmd, ['World']);
|
|
51
|
-
*
|
|
52
|
-
* expect(result.exitCode).toBe(0);
|
|
53
|
-
* expect(result.stdout).toContain('Hello, World!');
|
|
54
|
-
* expect(result.error).toBeUndefined();
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
26
|
//#endregion
|
|
58
27
|
export { type RunOptions, type RunResult, runCommand };
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { includesBeforeSeparator, stripBeforeSeparator } from "../parse/index.mjs";
|
|
2
|
+
import { createCaptureOutput } from "../output/index.mjs";
|
|
3
|
+
import { buildRunResult, executeCommand } from "../execution/index.mjs";
|
|
4
|
+
//#region src/core/testkit/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Test harness: command.run() with injected state, output capture.
|
|
7
|
+
*
|
|
8
|
+
* Provides {@linkcode runCommand()} — the in-process test harness wrapper over DreamCLI's
|
|
9
|
+
* shared executor.\
|
|
10
|
+
* It wires capture output and standalone command metadata,
|
|
11
|
+
* then returns a structured {@linkcode RunResult} with exitCode and captured output.
|
|
12
|
+
*
|
|
13
|
+
* This keeps command tests process-free without testkit owning the canonical pipeline:
|
|
14
|
+
*
|
|
15
|
+
* ```text
|
|
16
|
+
* parse -> resolve -> execute
|
|
17
|
+
* ```
|
|
18
|
+
* @module dreamcli/core/testkit
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Run a command builder against the given argv with injected options.
|
|
22
|
+
*
|
|
23
|
+
* This is the testkit wrapper around the shared executor:
|
|
24
|
+
* 1. Apply the CLI root-flag layer (detect/strip `--json`) so copied real argv works
|
|
25
|
+
* 2. Create or reuse capture output
|
|
26
|
+
* 3. Build standalone schema/meta defaults when CLI dispatch did not
|
|
27
|
+
* 4. Delegate parse -> resolve -> execute to the shared executor
|
|
28
|
+
* 5. Return the structured result with captured buffers
|
|
29
|
+
*
|
|
30
|
+
* Errors are normalized by the shared executor into structured {@linkcode RunResult}s
|
|
31
|
+
* with appropriate exit codes. The function never throws.
|
|
32
|
+
*
|
|
33
|
+
* @param cmd - The command builder (must have an action handler)
|
|
34
|
+
* @param argv - Raw argv strings (NOT including the command name itself). A
|
|
35
|
+
* CLI-level `--json` before the `--` separator is honored and stripped here,
|
|
36
|
+
* just like the real CLI root — so `['--json']` enables JSON mode rather than
|
|
37
|
+
* failing as an unknown flag. Equivalent to passing `{ jsonMode: true }`.
|
|
38
|
+
* @param options - Injectable runtime state
|
|
39
|
+
* @returns Structured run result with exit code and captured output
|
|
40
|
+
*/
|
|
41
|
+
async function runCommand(cmd, argv, options) {
|
|
42
|
+
const hasJsonFlag = includesBeforeSeparator(argv, "--json");
|
|
43
|
+
const jsonMode = hasJsonFlag || options?.jsonMode === true;
|
|
44
|
+
const effectiveArgv = hasJsonFlag ? stripBeforeSeparator(argv, "--json") : argv;
|
|
45
|
+
let out;
|
|
46
|
+
let captured;
|
|
47
|
+
if (options?.out !== void 0) {
|
|
48
|
+
out = options.out;
|
|
49
|
+
captured = options.captured ?? {
|
|
50
|
+
stdout: [],
|
|
51
|
+
stderr: [],
|
|
52
|
+
activity: []
|
|
53
|
+
};
|
|
54
|
+
} else {
|
|
55
|
+
const captureOptions = {
|
|
56
|
+
...options?.verbosity !== void 0 ? { verbosity: options.verbosity } : {},
|
|
57
|
+
...jsonMode ? { jsonMode } : {},
|
|
58
|
+
...options?.isTTY !== void 0 ? { isTTY: options.isTTY } : {}
|
|
59
|
+
};
|
|
60
|
+
[out, captured] = createCaptureOutput(Object.keys(captureOptions).length > 0 ? captureOptions : void 0);
|
|
61
|
+
}
|
|
62
|
+
const schema = options?.mergedSchema ?? cmd.schema;
|
|
63
|
+
const meta = options?.meta ?? {
|
|
64
|
+
name: schema.name,
|
|
65
|
+
bin: options?.help?.binName ?? schema.name,
|
|
66
|
+
version: void 0,
|
|
67
|
+
command: schema.name
|
|
68
|
+
};
|
|
69
|
+
const effectiveOptions = options !== void 0 ? {
|
|
70
|
+
...options,
|
|
71
|
+
...jsonMode ? { jsonMode } : {}
|
|
72
|
+
} : jsonMode ? { jsonMode } : void 0;
|
|
73
|
+
return buildRunResult(await executeCommand({
|
|
74
|
+
command: cmd,
|
|
75
|
+
argv: effectiveArgv,
|
|
76
|
+
out,
|
|
77
|
+
schema,
|
|
78
|
+
meta,
|
|
79
|
+
...effectiveOptions !== void 0 ? { options: effectiveOptions } : {}
|
|
80
|
+
}), captured);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { runCommand };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,10 @@ import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle
|
|
|
2
2
|
import { NumberConstraintViolation, NumberConstraints } from "./core/schema/number-constraints.mjs";
|
|
3
3
|
import { ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
4
4
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./core/schema/prompt.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { StringConstraintViolation, StringConstraints } from "./core/schema/string-constraints.mjs";
|
|
6
|
+
import { DateFlagOptions, UrlFlagOptions } from "./core/schema/value-parsers.mjs";
|
|
7
|
+
import { DuplicatePolicy, FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagNegation, FlagParseFn, FlagPresence, FlagSchema, InferFlag, InferFlags, PathChecks, PathFlagOptions, ResolvedValue, WithPresence, createSchema, flag, getFlagNegatedName } from "./core/schema/flag.mjs";
|
|
6
8
|
import { Middleware, MiddlewareHandler, MiddlewareParams, middleware } from "./core/schema/middleware.mjs";
|
|
7
|
-
import { ParseResult, Token, parse, tokenize } from "./core/parse/index.mjs";
|
|
8
9
|
import { WriteFn } from "./core/output/writer.mjs";
|
|
9
10
|
import { Verbosity } from "./core/output/contracts.mjs";
|
|
10
11
|
import { OutputOptions, createOutput } from "./core/output/index.mjs";
|
|
@@ -13,11 +14,14 @@ import { DeprecationWarning, ResolveOptions, ResolveResult } from "./core/resolv
|
|
|
13
14
|
import { resolve } from "./core/resolve/index.mjs";
|
|
14
15
|
import { BeforeParseParams, CLIPlugin, CLIPluginHooks, PluginCommandContext, ResolvedCommandParams, plugin } from "./core/cli/plugin.mjs";
|
|
15
16
|
import { CLIError, CLIErrorJSON, CLIErrorOptions, ErrorCode, ParseError, ParseErrorCode, ParseErrorOptions, ValidationError, ValidationErrorCode, ValidationErrorOptions, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
17
|
+
import { HelpTheme, HelpThemeFactory } from "./core/help/theme.mjs";
|
|
16
18
|
import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
17
19
|
import { HelpOptions, formatHelp } from "./core/help/index.mjs";
|
|
18
20
|
import { RunResult } from "./core/schema/run.mjs";
|
|
19
21
|
import { ActionHandler, ActionParams, AnyCommandBuilder, CommandArgEntry, CommandBuilder, CommandConfig, CommandExample, CommandMeta, CommandSchema, DeriveHandler, DeriveParams, InteractiveParams, InteractiveResolver, InteractiveResult, Out, command, group } from "./core/schema/command.mjs";
|
|
20
|
-
import
|
|
22
|
+
import "./core/schema/index.mjs";
|
|
23
|
+
import { ParseOptions, ParseResult, Token, parse, tokenize } from "./core/parse/index.mjs";
|
|
24
|
+
import { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, PackageRepositoryUrlOptions, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
21
25
|
import { HelpLinks } from "./core/cli/help-links.mjs";
|
|
22
26
|
import { CompletionOptions } from "./core/completion/shells/shared.mjs";
|
|
23
27
|
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
@@ -26,6 +30,7 @@ import { generatePowerShellCompletion } from "./core/completion/shells/powershel
|
|
|
26
30
|
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
27
31
|
import { SHELLS, Shell, generateCompletion } from "./core/completion/index.mjs";
|
|
28
32
|
import { ConfigAdapter, ConfigDiscoveryOptions, ConfigDiscoveryResult, ConfigFound, ConfigNotFound, FormatLoader, buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
29
|
-
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
30
|
-
import { JsonSchemaOptions, definitionMetaSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
31
|
-
|
|
33
|
+
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, DefaultCommandOptions, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
34
|
+
import { JsonSchemaOptions, definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
35
|
+
import { Colors } from "ansispeck";
|
|
36
|
+
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type Colors, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DateFlagOptions, type DefaultCommandOptions, type DeprecationWarning, type DeriveHandler, type DeriveParams, type DuplicatePolicy, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagNegation, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type HelpTheme, type HelpThemeFactory, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InferNameOption, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type ManifestDiscoveryOptions, type ManifestPresetSettings, type ManifestSettings, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type NumberConstraintViolation, type NumberConstraints, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, type PackageRepositoryUrlOptions, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseOptions, type ParseResult, type PathChecks, type PathFlagOptions, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedManifestSettings, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type StringConstraintViolation, type StringConstraints, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, type UrlFlagOptions, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCommandSchema, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, getFlagNegatedName, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CLIError, ParseError, ValidationError, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
2
|
+
import { FlagBuilder, createSchema, flag, getFlagNegatedName } from "./core/schema/flag.mjs";
|
|
3
|
+
import { ArgBuilder, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
4
|
+
import { CommandBuilder, command, group } from "./core/schema/command.mjs";
|
|
5
|
+
import { middleware } from "./core/schema/middleware.mjs";
|
|
6
|
+
import { parse, tokenize } from "./core/parse/index.mjs";
|
|
7
|
+
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
8
|
+
import { generateFishCompletion } from "./core/completion/shells/fish.mjs";
|
|
9
|
+
import { generatePowerShellCompletion } from "./core/completion/shells/powershell.mjs";
|
|
10
|
+
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
11
|
+
import { SHELLS, generateCompletion } from "./core/completion/index.mjs";
|
|
12
|
+
import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
13
|
+
import { formatHelp } from "./core/help/index.mjs";
|
|
14
|
+
import { definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
15
|
+
import { createOutput } from "./core/output/index.mjs";
|
|
16
|
+
import { createTerminalPrompter, resolvePromptConfig } from "./core/prompt/index.mjs";
|
|
17
|
+
import { resolve } from "./core/resolve/index.mjs";
|
|
18
|
+
import { discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
19
|
+
import { plugin } from "./core/cli/plugin.mjs";
|
|
20
|
+
import { buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
21
|
+
import { CLIBuilder, cli } from "./core/cli/index.mjs";
|
|
22
|
+
export { ArgBuilder, CLIBuilder, CLIError, CommandBuilder, FlagBuilder, ParseError, SHELLS, ValidationError, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCommandSchema, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, getFlagNegatedName, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WriteFn } from "../core/output/writer.mjs";
|
|
2
|
+
import "../core/output/index.mjs";
|
|
2
3
|
import { ReadFn } from "../core/prompt/index.mjs";
|
|
3
|
-
|
|
4
4
|
//#region src/runtime/adapter.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Runtime adapter interface.
|
|
@@ -62,6 +62,10 @@ interface RuntimeAdapter {
|
|
|
62
62
|
readonly isTTY: boolean;
|
|
63
63
|
/** Whether stdin is connected to a TTY (used for prompt gating). */
|
|
64
64
|
readonly stdinIsTTY: boolean;
|
|
65
|
+
/** Read current terminal dimensions for stdout, if available. */
|
|
66
|
+
readonly getTerminalSize: () => TerminalSize | undefined;
|
|
67
|
+
/** Subscribe to terminal resize events when the runtime supports them. */
|
|
68
|
+
readonly onTerminalResize: (listener: () => void) => (() => void) | undefined;
|
|
65
69
|
/**
|
|
66
70
|
* Exit the process with the given code.
|
|
67
71
|
* Must not return (divergent function).
|
|
@@ -78,6 +82,15 @@ interface RuntimeAdapter {
|
|
|
78
82
|
* Used by config file discovery to probe multiple candidate paths.
|
|
79
83
|
*/
|
|
80
84
|
readonly readFile: (path: string) => Promise<string | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Probe what exists at a filesystem path.
|
|
87
|
+
*
|
|
88
|
+
* Returns `'file'` or `'directory'` for existing paths (other kinds such
|
|
89
|
+
* as sockets report `'file'`), or `null` when nothing exists there.
|
|
90
|
+
*
|
|
91
|
+
* Used by `flag.path()` existence/type checks after resolution.
|
|
92
|
+
*/
|
|
93
|
+
readonly stat: (path: string) => Promise<'file' | 'directory' | null>;
|
|
81
94
|
/**
|
|
82
95
|
* User home directory (absolute path).
|
|
83
96
|
*
|
|
@@ -95,6 +108,13 @@ interface RuntimeAdapter {
|
|
|
95
108
|
*/
|
|
96
109
|
readonly configDir: string;
|
|
97
110
|
}
|
|
111
|
+
/** Current terminal dimensions in columns and rows. */
|
|
112
|
+
interface TerminalSize {
|
|
113
|
+
/** Terminal width in columns. */
|
|
114
|
+
readonly columns: number;
|
|
115
|
+
/** Terminal height in rows. */
|
|
116
|
+
readonly rows: number;
|
|
117
|
+
}
|
|
98
118
|
/**
|
|
99
119
|
* Options for creating a test adapter.
|
|
100
120
|
*
|
|
@@ -138,6 +158,10 @@ interface TestAdapterOptions {
|
|
|
138
158
|
readonly isTTY?: boolean;
|
|
139
159
|
/** TTY flag for stdin (defaults to `false`). */
|
|
140
160
|
readonly stdinIsTTY?: boolean;
|
|
161
|
+
/** Terminal dimensions returned by `getTerminalSize()`. */
|
|
162
|
+
readonly terminalSize?: TerminalSize;
|
|
163
|
+
/** Resize subscription hook returned by `onTerminalResize()`. */
|
|
164
|
+
readonly onTerminalResize?: (listener: () => void) => (() => void) | undefined;
|
|
141
165
|
/**
|
|
142
166
|
* Exit function (defaults to throwing {@linkcode ExitError}).
|
|
143
167
|
* The default throw-based exit allows tests to catch the exit code.
|
|
@@ -158,6 +182,18 @@ interface TestAdapterOptions {
|
|
|
158
182
|
* ```
|
|
159
183
|
*/
|
|
160
184
|
readonly readFile?: (path: string) => Promise<string | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Filesystem probe stub for `flag.path()` checks (defaults to returning
|
|
187
|
+
* `null` — nothing exists).
|
|
188
|
+
*
|
|
189
|
+
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
190
|
+
* ```ts
|
|
191
|
+
* createTestAdapter({
|
|
192
|
+
* stat: (path) => Promise.resolve(path === '/data' ? 'directory' : null),
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
readonly stat?: (path: string) => Promise<'file' | 'directory' | null>;
|
|
161
197
|
/** Home directory (defaults to `'/home/test'`). */
|
|
162
198
|
readonly homedir?: string;
|
|
163
199
|
/** Config directory (defaults to `'/home/test/.config'`). */
|
|
@@ -209,4 +245,4 @@ declare class ExitError extends Error {
|
|
|
209
245
|
*/
|
|
210
246
|
declare function createTestAdapter(options?: TestAdapterOptions): RuntimeAdapter;
|
|
211
247
|
//#endregion
|
|
212
|
-
export { ExitError, type RuntimeAdapter, type TestAdapterOptions, createTestAdapter };
|
|
248
|
+
export { ExitError, type RuntimeAdapter, type TerminalSize, type TestAdapterOptions, createTestAdapter };
|