@kjanat/dreamcli 3.0.0-rc.1 → 3.0.0-rc.10

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.
Files changed (194) hide show
  1. package/CHANGELOG.md +217 -1
  2. package/dist/core/cli/dispatch.d.mts +6 -5
  3. package/dist/core/cli/dispatch.mjs +205 -1
  4. package/dist/core/cli/help-links.d.mts +0 -1
  5. package/dist/core/cli/help-links.mjs +41 -1
  6. package/dist/core/cli/index.d.mts +81 -8
  7. package/dist/core/cli/index.mjs +945 -1
  8. package/dist/core/cli/planner.d.mts +5 -1
  9. package/dist/core/cli/planner.mjs +300 -1
  10. package/dist/core/cli/plugin.d.mts +1 -1
  11. package/dist/core/cli/plugin.mjs +41 -1
  12. package/dist/core/cli/propagate.d.mts +1 -1
  13. package/dist/core/cli/propagate.mjs +57 -1
  14. package/dist/core/cli/root-help.d.mts +2 -1
  15. package/dist/core/cli/root-help.mjs +226 -4
  16. package/dist/core/cli/root-surface.d.mts +12 -1
  17. package/dist/core/cli/root-surface.mjs +28 -1
  18. package/dist/core/cli/runtime-preflight.d.mts +14 -2
  19. package/dist/core/cli/runtime-preflight.mjs +169 -1
  20. package/dist/core/completion/index.d.mts +0 -1
  21. package/dist/core/completion/index.mjs +90 -1
  22. package/dist/core/completion/shells/bash.d.mts +0 -1
  23. package/dist/core/completion/shells/bash.mjs +308 -3
  24. package/dist/core/completion/shells/fish.d.mts +0 -1
  25. package/dist/core/completion/shells/fish.mjs +162 -2
  26. package/dist/core/completion/shells/powershell.d.mts +0 -1
  27. package/dist/core/completion/shells/powershell.mjs +358 -2
  28. package/dist/core/completion/shells/shared.d.mts +13 -2
  29. package/dist/core/completion/shells/shared.mjs +176 -1
  30. package/dist/core/completion/shells/zsh.d.mts +0 -1
  31. package/dist/core/completion/shells/zsh.mjs +251 -2
  32. package/dist/core/config/index.d.mts +2 -3
  33. package/dist/core/config/index.mjs +246 -1
  34. package/dist/core/config/package-json.d.mts +27 -4
  35. package/dist/core/config/package-json.mjs +386 -3
  36. package/dist/core/errors/index.d.mts +3 -3
  37. package/dist/core/errors/index.mjs +87 -1
  38. package/dist/core/execution/index.d.mts +0 -1
  39. package/dist/core/execution/index.mjs +201 -1
  40. package/dist/core/help/ansi.d.mts +11 -5
  41. package/dist/core/help/ansi.mjs +121 -2
  42. package/dist/core/help/index.d.mts +22 -3
  43. package/dist/core/help/index.mjs +341 -7
  44. package/dist/core/help/theme.d.mts +68 -0
  45. package/dist/core/help/theme.mjs +46 -0
  46. package/dist/core/json-schema/index.d.mts +15 -2
  47. package/dist/core/json-schema/index.mjs +536 -12
  48. package/dist/core/json-schema/meta-descriptions.generated.d.mts +55 -38
  49. package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
  50. package/dist/core/output/activity.d.mts +0 -1
  51. package/dist/core/output/activity.mjs +452 -1
  52. package/dist/core/output/bind.mjs +56 -1
  53. package/dist/core/output/contracts.d.mts +4 -5
  54. package/dist/core/output/contracts.mjs +57 -1
  55. package/dist/core/output/display-value.mjs +32 -1
  56. package/dist/core/output/index.d.mts +21 -1
  57. package/dist/core/output/index.mjs +442 -2
  58. package/dist/core/output/renderers.d.mts +0 -1
  59. package/dist/core/output/renderers.mjs +46 -1
  60. package/dist/core/output/writer.mjs +12 -1
  61. package/dist/core/parse/index.d.mts +40 -7
  62. package/dist/core/parse/index.mjs +727 -1
  63. package/dist/core/prompt/index.d.mts +1 -1
  64. package/dist/core/prompt/index.mjs +348 -6
  65. package/dist/core/resolve/args.d.mts +1 -1
  66. package/dist/core/resolve/args.mjs +105 -1
  67. package/dist/core/resolve/coerce.d.mts +1 -1
  68. package/dist/core/resolve/coerce.mjs +336 -1
  69. package/dist/core/resolve/config.mjs +19 -1
  70. package/dist/core/resolve/contracts.d.mts +9 -4
  71. package/dist/core/resolve/errors.d.mts +0 -1
  72. package/dist/core/resolve/errors.mjs +140 -2
  73. package/dist/core/resolve/flags.d.mts +7 -2
  74. package/dist/core/resolve/flags.mjs +251 -1
  75. package/dist/core/resolve/index.d.mts +2 -2
  76. package/dist/core/resolve/index.mjs +85 -1
  77. package/dist/core/resolve/property.d.mts +4 -2
  78. package/dist/core/resolve/property.mjs +53 -1
  79. package/dist/core/schema/activity.d.mts +31 -11
  80. package/dist/core/schema/arg.d.mts +3 -4
  81. package/dist/core/schema/arg.mjs +463 -1
  82. package/dist/core/schema/command.d.mts +26 -6
  83. package/dist/core/schema/command.mjs +726 -1
  84. package/dist/core/schema/flag.d.mts +485 -19
  85. package/dist/core/schema/flag.mjs +705 -1
  86. package/dist/core/schema/index.d.mts +4 -2
  87. package/dist/core/schema/middleware.d.mts +4 -3
  88. package/dist/core/schema/middleware.mjs +41 -1
  89. package/dist/core/schema/number-constraints.mjs +60 -1
  90. package/dist/core/schema/prompt.d.mts +6 -3
  91. package/dist/core/schema/run.d.mts +20 -1
  92. package/dist/core/schema/string-constraints.d.mts +97 -0
  93. package/dist/core/schema/string-constraints.mjs +69 -0
  94. package/dist/core/schema/value-parsers.d.mts +78 -0
  95. package/dist/core/schema/value-parsers.mjs +142 -0
  96. package/dist/core/schema-dsl/runtime.mjs +271 -2
  97. package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
  98. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  99. package/dist/core/testkit/index.d.mts +0 -31
  100. package/dist/core/testkit/index.mjs +83 -1
  101. package/dist/index.d.mts +11 -6
  102. package/dist/index.mjs +22 -1
  103. package/dist/runtime/adapter.d.mts +38 -2
  104. package/dist/runtime/adapter.mjs +87 -1
  105. package/dist/runtime/auto.d.mts +2 -3
  106. package/dist/runtime/auto.mjs +45 -1
  107. package/dist/runtime/deno.d.mts +24 -5
  108. package/dist/runtime/deno.mjs +262 -2
  109. package/dist/runtime/detect.mjs +45 -1
  110. package/dist/runtime/index.d.mts +3 -4
  111. package/dist/runtime/node.d.mts +8 -2
  112. package/dist/runtime/node.mjs +220 -2
  113. package/dist/runtime/paths.mjs +48 -1
  114. package/dist/runtime.d.mts +4 -4
  115. package/dist/runtime.mjs +6 -1
  116. package/dist/strings.mjs +22 -1
  117. package/dist/testkit.d.mts +1 -0
  118. package/dist/testkit.mjs +5 -1
  119. package/dist/version.d.mts +7 -3
  120. package/dist/version.mjs +7 -1
  121. package/dreamcli.schema.json +36 -7
  122. package/package.json +45 -42
  123. package/dist/runtime/bun.d.mts +0 -28
  124. package/dist/runtime/bun.mjs +0 -1
  125. package/src/core/cli/dispatch.ts +0 -355
  126. package/src/core/cli/help-links.ts +0 -82
  127. package/src/core/cli/index.ts +0 -1614
  128. package/src/core/cli/planner.ts +0 -656
  129. package/src/core/cli/plugin.ts +0 -117
  130. package/src/core/cli/propagate.ts +0 -97
  131. package/src/core/cli/root-help.ts +0 -342
  132. package/src/core/cli/root-surface.ts +0 -87
  133. package/src/core/cli/runtime-preflight.ts +0 -456
  134. package/src/core/completion/index.ts +0 -138
  135. package/src/core/completion/shells/bash.ts +0 -459
  136. package/src/core/completion/shells/fish.ts +0 -259
  137. package/src/core/completion/shells/powershell.ts +0 -439
  138. package/src/core/completion/shells/shared.ts +0 -310
  139. package/src/core/completion/shells/zsh.ts +0 -381
  140. package/src/core/config/index.ts +0 -417
  141. package/src/core/config/package-json.ts +0 -560
  142. package/src/core/errors/index.ts +0 -193
  143. package/src/core/execution/index.ts +0 -265
  144. package/src/core/help/ansi.ts +0 -144
  145. package/src/core/help/index.ts +0 -563
  146. package/src/core/json-schema/index.ts +0 -910
  147. package/src/core/json-schema/meta-descriptions.generated.ts +0 -202
  148. package/src/core/output/activity.ts +0 -575
  149. package/src/core/output/bind.ts +0 -59
  150. package/src/core/output/contracts.ts +0 -194
  151. package/src/core/output/display-value.ts +0 -48
  152. package/src/core/output/index.ts +0 -704
  153. package/src/core/output/renderers.ts +0 -125
  154. package/src/core/output/writer.ts +0 -46
  155. package/src/core/parse/index.ts +0 -742
  156. package/src/core/prompt/index.ts +0 -623
  157. package/src/core/resolve/args.ts +0 -144
  158. package/src/core/resolve/coerce.ts +0 -500
  159. package/src/core/resolve/config.ts +0 -26
  160. package/src/core/resolve/contracts.ts +0 -135
  161. package/src/core/resolve/errors.ts +0 -227
  162. package/src/core/resolve/flags.ts +0 -269
  163. package/src/core/resolve/index.ts +0 -108
  164. package/src/core/resolve/property.ts +0 -99
  165. package/src/core/schema/activity.ts +0 -240
  166. package/src/core/schema/arg.ts +0 -841
  167. package/src/core/schema/command.ts +0 -1500
  168. package/src/core/schema/flag.ts +0 -917
  169. package/src/core/schema/index.ts +0 -96
  170. package/src/core/schema/middleware.ts +0 -171
  171. package/src/core/schema/number-constraints.ts +0 -153
  172. package/src/core/schema/prompt.ts +0 -171
  173. package/src/core/schema/run.ts +0 -198
  174. package/src/core/schema-dsl/index.ts +0 -109
  175. package/src/core/schema-dsl/parse.ts +0 -262
  176. package/src/core/schema-dsl/runtime.ts +0 -609
  177. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  178. package/src/core/testkit/index.ts +0 -147
  179. package/src/index.ts +0 -181
  180. package/src/runtime/adapter.ts +0 -303
  181. package/src/runtime/auto.ts +0 -86
  182. package/src/runtime/bun.ts +0 -48
  183. package/src/runtime/deno.ts +0 -367
  184. package/src/runtime/detect.ts +0 -105
  185. package/src/runtime/index.ts +0 -21
  186. package/src/runtime/node-builtins.d.ts +0 -27
  187. package/src/runtime/node.ts +0 -289
  188. package/src/runtime/paths.ts +0 -64
  189. package/src/runtime/support.ts +0 -77
  190. package/src/runtime.ts +0 -31
  191. package/src/schema.ts +0 -16
  192. package/src/strings.ts +0 -34
  193. package/src/testkit.ts +0 -25
  194. package/src/version.ts +0 -20
@@ -1,2 +1,271 @@
1
- const e={"{":`lbrace`,"}":`rbrace`,"[":`lbracket`,"]":`rbracket`,"<":`langle`,">":`rangle`,",":`comma`,":":`colon`,";":`semicolon`,"?":`question`,"|":`pipe`};function t(e){return e===` `||e===`
2
- `||e===` `||e===`\r`}function n(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`_`||e===`$`}function r(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`_`||e===`$`}function i(i){let a=[],o=0;for(;o<i.length;){let s=i[o]??``;if(t(s)){o++;continue}let c=e[s];if(c!==void 0){a.push({kind:c,value:s}),o++;continue}if(s===`'`){let e=``;for(o++;o<i.length&&i[o]!==`'`;)e+=i[o],o++;if(o>=i.length)throw SyntaxError(`Unterminated string literal`);o++,a.push({kind:`string_literal`,value:e});continue}if(s===`@`){o++;let e=``;for(;o<i.length;){let t=i[o]??``;if(!n(t))break;e+=t,o++}if(e.length===0)throw SyntaxError(`Expected identifier after '@' at position ${String(o)}`);a.push({kind:`ref`,value:e});continue}if(r(s)){let e=``;for(;o<i.length;){let t=i[o]??``;if(!n(t))break;e+=t,o++}a.push({kind:`ident`,value:e});continue}throw SyntaxError(`Unexpected character '${s}' at position ${String(o)}`)}return a}const a=new Set([`string`,`number`,`integer`,`boolean`,`true`,`false`,`null`,`undefined`,`unknown`,`never`]);function o(e){switch(e){case`string`:return{kind:`string`};case`number`:return{kind:`number`};case`integer`:return{kind:`integer`};case`boolean`:return{kind:`boolean`};case`true`:return{kind:`true`};case`false`:return{kind:`false`};case`null`:return{kind:`null`};case`undefined`:return{kind:`undefined`};case`unknown`:return{kind:`unknown`};case`never`:return{kind:`never`};default:throw SyntaxError(`Unknown type '${e}'`)}}var s=class{tokens;pos=0;constructor(e){this.tokens=e}parseRoot(){let e=this.parseValue();if(this.pos<this.tokens.length){let e=this.peek();throw SyntaxError(`Unexpected token '${e?.value??`?`}' at position ${String(this.pos)}`)}return e}parseValue(){return this.parseUnion()}parseUnion(){let e=this.parsePostfix();if(!this.check(`pipe`))return e;let t=[e];for(;this.match(`pipe`);)t.push(this.parsePostfix());return{kind:`union`,members:t}}parsePostfix(){let e=this.parsePrimary();for(;this.check(`lbracket`)&&this.checkAt(this.pos+1,`rbracket`);)this.advance(),this.advance(),e={kind:`array`,element:e};return e}parsePrimary(){if(this.check(`lbrace`))return this.parseObject();if(this.check(`string_literal`))return{kind:`literal`,value:this.advance().value};if(this.check(`ref`))return{kind:`ref`,target:this.advance().value};let e=this.expectIdent();if(e===`Record`){if(this.expect(`langle`),this.parseValue().kind!==`string`)throw SyntaxError(`Record key type must be 'string' because JSON object keys are always strings`);this.expect(`comma`);let e=this.parseValue();return this.expect(`rangle`),{kind:`record`,value:e}}if(!a.has(e))throw SyntaxError(`Unknown type '${e}' at position ${String(this.pos-1)}`);return o(e)}parseObject(){this.expect(`lbrace`);let e={};for(;!this.check(`rbrace`);){let t=this.expectIdent();if(Object.hasOwn(e,t))throw SyntaxError(`Duplicate property '${t}' at position ${String(this.pos-1)}`);let n=this.match(`question`);this.expect(`colon`),e[t]={optional:n,schema:this.parseValue()},this.match(`semicolon`)}return this.expect(`rbrace`),{kind:`object`,properties:e}}peek(){return this.tokens[this.pos]}check(e){return this.peek()?.kind===e}checkAt(e,t){return this.tokens[e]?.kind===t}advance(){let e=this.tokens[this.pos];if(e===void 0)throw SyntaxError(`Unexpected end of input`);return this.pos++,e}match(e){return this.check(e)?(this.pos++,!0):!1}expect(e){if(!this.check(e)){let t=this.peek();throw SyntaxError(t?`Expected '${e}' but got '${t.kind}' ('${t.value}') at position ${String(this.pos)}`:`Expected '${e}' but reached end of input`)}return this.advance()}expectIdent(){return this.expect(`ident`).value}};function c(e){return new s(i(e)).parseRoot()}export{c as parseSchema};
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,5 +1,4 @@
1
1
  import { SchemaNode } from "./runtime.mjs";
2
-
3
2
  //#region src/core/schema-dsl/to-json-schema.d.ts
4
3
  /**
5
4
  * Convert a {@link SchemaNode} AST node to a JSON Schema fragment.
@@ -1 +1,74 @@
1
- function e(t){switch(t.kind){case`string`:return{type:`string`};case`number`:return{type:`number`};case`integer`:return{type:`integer`};case`boolean`:return{type:`boolean`};case`true`:return{const:!0};case`false`:return{const:!1};case`null`:return{type:`null`};case`literal`:return{const:t.value};case`undefined`:throw Error(`Cannot convert 'undefined' type to JSON Schema; model optionality at the parent level`);case`unknown`:return{};case`never`:return{not:{}};case`ref`:return{$ref:`#/$defs/${t.target}`};case`array`:return{type:`array`,items:e(t.element)};case`record`:return{type:`object`,additionalProperties:e(t.value)};case`object`:{let n={},r=[];for(let[i,a]of Object.entries(t.properties))n[i]=e(a.schema),a.optional||r.push(i);let i={type:`object`,additionalProperties:!1,properties:n};return r.length>0&&(i.required=r),i}case`union`:{let n=[],r=!0;for(let e of t.members)e.kind===`literal`?n.push(e.value):r=!1;return r?{enum:n}:{oneOf:t.members.map(e)}}}}export{e as nodeToJsonSchema};
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{createCaptureOutput as e}from"../output/index.mjs";import{includesBeforeSeparator as t,stripBeforeSeparator as n}from"../parse/index.mjs";import{buildRunResult as r,executeCommand as i}from"../execution/index.mjs";async function a(a,o,s){let c=t(o,`--json`),l=c||s?.jsonMode===!0,u=c?n(o,`--json`):o,d,f;if(s?.out!==void 0)d=s.out,f=s.captured??{stdout:[],stderr:[],activity:[]};else{let t={...s?.verbosity===void 0?{}:{verbosity:s.verbosity},...l?{jsonMode:l}:{},...s?.isTTY===void 0?{}:{isTTY:s.isTTY}};[d,f]=e(Object.keys(t).length>0?t:void 0)}let p=s?.mergedSchema??a.schema,m=s?.meta??{name:p.name,bin:s?.help?.binName??p.name,version:void 0,command:p.name},h=s===void 0?l?{jsonMode:l}:void 0:{...s,...l?{jsonMode:l}:{}};return r(await i({command:a,argv:u,out:d,schema:p,meta:m,...h===void 0?{}:{options:h}}),f)}export{a as runCommand};
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 { FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagParseFn, FlagPresence, FlagSchema, InferFlag, InferFlags, ResolvedValue, WithPresence, createSchema, flag } from "./core/schema/flag.mjs";
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 { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
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
- 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 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 DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, 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, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, 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 TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, 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, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
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{FlagBuilder as e,createSchema as t,flag as n}from"./core/schema/flag.mjs";import{generateBashCompletion as r}from"./core/completion/shells/bash.mjs";import{generateFishCompletion as i}from"./core/completion/shells/fish.mjs";import{generatePowerShellCompletion as a}from"./core/completion/shells/powershell.mjs";import{CLIError as o,ParseError as s,ValidationError as c,isCLIError as l,isParseError as u,isValidationError as d}from"./core/errors/index.mjs";import{generateZshCompletion as f}from"./core/completion/shells/zsh.mjs";import{SHELLS as p,generateCompletion as m}from"./core/completion/index.mjs";import{osc8 as h,visibleWidth as g}from"./core/help/ansi.mjs";import{formatHelp as _}from"./core/help/index.mjs";import{createOutput as v}from"./core/output/index.mjs";import{ArgBuilder as y,arg as b,createArgSchema as x}from"./core/schema/arg.mjs";import{CommandBuilder as S,command as C,group as w}from"./core/schema/command.mjs";import{middleware as T}from"./core/schema/middleware.mjs";import{parse as E,tokenize as D}from"./core/parse/index.mjs";import{createTerminalPrompter as O,resolvePromptConfig as k}from"./core/prompt/index.mjs";import{resolve as A}from"./core/resolve/index.mjs";import{discoverManifest as j,discoverPackageJson as M,inferCliName as N,packageRepositoryUrl as P}from"./core/config/package-json.mjs";import{plugin as F}from"./core/cli/plugin.mjs";import{buildConfigSearchPaths as I,configFormat as L,discoverConfig as R}from"./core/config/index.mjs";import{CLIBuilder as z,cli as B}from"./core/cli/index.mjs";import{definitionMetaSchema as V,generateInputSchema as H,generateSchema as U}from"./core/json-schema/index.mjs";export{y as ArgBuilder,z as CLIBuilder,o as CLIError,S as CommandBuilder,e as FlagBuilder,s as ParseError,p as SHELLS,c as ValidationError,b as arg,I as buildConfigSearchPaths,B as cli,C as command,L as configFormat,x as createArgSchema,v as createOutput,t as createSchema,O as createTerminalPrompter,V as definitionMetaSchema,R as discoverConfig,j as discoverManifest,M as discoverPackageJson,n as flag,_ as formatHelp,r as generateBashCompletion,m as generateCompletion,i as generateFishCompletion,H as generateInputSchema,a as generatePowerShellCompletion,U as generateSchema,f as generateZshCompletion,w as group,N as inferCliName,l as isCLIError,u as isParseError,d as isValidationError,T as middleware,h as osc8,P as packageRepositoryUrl,E as parse,F as plugin,A as resolve,k as resolvePromptConfig,D as tokenize,g as visibleWidth};
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 };