@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 +1,463 @@
1
- import{assertNumberConstraints as e}from"./number-constraints.mjs";function t(e,t){return{kind:e,presence:`required`,variadic:!1,stdinMode:!1,defaultValue:void 0,description:void 0,envVar:void 0,enumValues:void 0,numberConstraints:void 0,parseFn:void 0,deprecated:void 0,...t}}var n=class t{schema;constructor(e){this.schema=e}required(){return new t({...this.schema,presence:`required`})}optional(){return new t({...this.schema,presence:`optional`})}default(e){return new t({...this.schema,presence:`defaulted`,defaultValue:e})}variadic(){return new t({...this.schema,variadic:!0})}stdin(){return new t({...this.schema,stdinMode:!0})}env(e){return new t({...this.schema,envVar:e})}describe(e){return new t({...this.schema,description:e})}deprecated(e){return new t({...this.schema,deprecated:e??!0})}int(e=!0){return new t({...this.schema,numberConstraints:{...this.schema.numberConstraints,int:e}})}min(n){let r={...this.schema.numberConstraints,min:n};return e(r),new t({...this.schema,numberConstraints:r})}max(n){let r={...this.schema.numberConstraints,max:n};return e(r),new t({...this.schema,numberConstraints:r})}finite(e=!0){return new t({...this.schema,numberConstraints:{...this.schema.numberConstraints,finite:e}})}};const r={string(){return new n(t(`string`))},number(r){return r!==void 0&&e(r),new n(t(`number`,r===void 0?{}:{numberConstraints:r}))},enum(e){return new n(t(`enum`,{enumValues:e}))},custom(e){return new n(t(`custom`,{parseFn:e}))}};export{n as ArgBuilder,r as arg,t as createArgSchema};
1
+ import { assertNumberConstraints } from "./number-constraints.mjs";
2
+ //#region src/core/schema/arg.ts
3
+ /**
4
+ * Positional argument schema builder with full type inference.
5
+ *
6
+ * Each factory (`arg.string()`, `arg.number()`, `arg.enum()`, `arg.custom()`) returns an
7
+ * immutable {@linkcode ArgBuilder} whose generic parameter tracks the value type,
8
+ * presence state, and variadic flag through the fluent chain.
9
+ *
10
+ * @module dreamcli/core/schema/arg
11
+ */
12
+ /**
13
+ * Create a raw {@link ArgSchema} object with sensible defaults.
14
+ *
15
+ * Most consumers should prefer the higher-level {@link arg} factory, which
16
+ * returns an immutable {@link ArgBuilder} with type inference and fluent
17
+ * modifiers. `createArgSchema()` exists for advanced schema composition,
18
+ * targeted tests, or custom builders that need the plain runtime descriptor.
19
+ *
20
+ * `overrides` are shallow-merged on top of the default shape, so callers are
21
+ * responsible for preserving invariants such as variadic ordering and
22
+ * compatible `parseFn` / `kind` combinations.
23
+ *
24
+ * @param kind - Discriminator for the value type this arg accepts.
25
+ * @param overrides - Partial schema fields shallow-merged onto defaults.
26
+ * @returns A fully populated {@link ArgSchema}.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const schema = createArgSchema('custom', {
31
+ * description: 'Hex color',
32
+ * parseFn: (raw) => `#${raw}`,
33
+ * });
34
+ * ```
35
+ */
36
+ function createArgSchema(kind, overrides) {
37
+ return {
38
+ kind,
39
+ presence: "required",
40
+ variadic: false,
41
+ stdinMode: false,
42
+ defaultValue: void 0,
43
+ description: void 0,
44
+ envVar: void 0,
45
+ enumValues: void 0,
46
+ numberConstraints: void 0,
47
+ parseFn: void 0,
48
+ deprecated: void 0,
49
+ ...overrides
50
+ };
51
+ }
52
+ /**
53
+ * Immutable positional argument schema builder.
54
+ *
55
+ * The type parameter `C` is a phantom that tracks the value type, presence,
56
+ * and variadic state through the fluent chain. Each modifier returns a **new**
57
+ * builder — the original is never mutated.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * // Full command with multiple args and modifiers
62
+ * import { command, arg } from '@kjanat/dreamcli';
63
+ *
64
+ * command('deploy')
65
+ * .arg('target', arg.string()
66
+ * .env('DEPLOY_TARGET')
67
+ * .describe('Deploy target'))
68
+ * .arg('port', arg.number()
69
+ * .env('PORT')
70
+ * .default(3000)
71
+ * .describe('Port number'))
72
+ * .arg('files', arg.string()
73
+ * .variadic()
74
+ * .optional()
75
+ * .describe('Extra config files'))
76
+ * .action(({ args }) => {
77
+ * args.target; // string (required, from CLI or $DEPLOY_TARGET)
78
+ * args.port; // number (defaulted, from CLI, $PORT, or 3000)
79
+ * args.files; // string[] (optional variadic)
80
+ * });
81
+ * ```
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * // Type inference
86
+ * const target = arg.string();
87
+ * type T = InferArg<typeof target>; // string
88
+ *
89
+ * const opt = arg.string().optional();
90
+ * type O = InferArg<typeof opt>; // string | undefined
91
+ *
92
+ * const files = arg.string().variadic();
93
+ * type F = InferArg<typeof files>; // string[]
94
+ * ```
95
+ */
96
+ var ArgBuilder = class ArgBuilder {
97
+ /** @internal Runtime schema descriptor. */
98
+ schema;
99
+ /**
100
+ * Create an arg builder from a pre-built schema descriptor.
101
+ *
102
+ * @param schema - Runtime descriptor for this positional argument.
103
+ */
104
+ constructor(schema) {
105
+ this.schema = schema;
106
+ }
107
+ /**
108
+ * Mark the arg as required (this is the default for positional args).
109
+ * Produces an error if no value resolves from any configured source
110
+ * (CLI → stdin → env → default).
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * arg.string().required() // explicit, same as default
115
+ *
116
+ * // In a command — omitting <target> causes a ValidationError:
117
+ * command('deploy')
118
+ * .arg('target', arg.string().required().describe('Deploy target'))
119
+ * // $ mycli deploy
120
+ * // Error: Missing required argument <target>
121
+ * ```
122
+ *
123
+ * @returns The builder (for chaining).
124
+ */
125
+ required() {
126
+ return new ArgBuilder({
127
+ ...this.schema,
128
+ presence: "required"
129
+ });
130
+ }
131
+ /**
132
+ * Mark the arg as optional. Handlers receive `undefined` when absent.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * arg.string().optional()
137
+ *
138
+ * // In a command — handler receives `undefined` when omitted:
139
+ * command('greet')
140
+ * .arg('name', arg.string().optional().describe('Who to greet'))
141
+ * .action(({ args }) => {
142
+ * args.name; // string | undefined
143
+ * });
144
+ * // $ mycli greet → args.name is undefined
145
+ * // $ mycli greet Alice → args.name is 'Alice'
146
+ * ```
147
+ *
148
+ * @returns The builder (for chaining).
149
+ */
150
+ optional() {
151
+ return new ArgBuilder({
152
+ ...this.schema,
153
+ presence: "optional"
154
+ });
155
+ }
156
+ /**
157
+ * Provide a default value. The arg becomes "always present" — handlers
158
+ * will never see `undefined`.
159
+ *
160
+ * The generic constraint `V extends C['valueType']` ensures the default
161
+ * matches the arg's declared type.
162
+ *
163
+ * Resolution order when extra sources are configured: CLI → stdin → env → **default**.
164
+ *
165
+ * @param value - Fallback used when no CLI value or env var resolves.
166
+ * @returns The builder (for chaining).
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * arg.string().default('production')
171
+ * arg.number().default(3000)
172
+ *
173
+ * // In a command — default kicks in when CLI and env are both absent:
174
+ * command('deploy')
175
+ * .arg('env', arg.string()
176
+ * .env('DEPLOY_ENV')
177
+ * .default('staging')
178
+ * .describe('Target environment'))
179
+ * .action(({ args }) => {
180
+ * args.env; // string (never undefined)
181
+ * });
182
+ * // $ mycli deploy → 'staging' (default)
183
+ * // $ DEPLOY_ENV=prod mycli deploy → 'prod' (env)
184
+ * // $ mycli deploy production → 'production' (CLI)
185
+ * ```
186
+ */
187
+ default(value) {
188
+ return new ArgBuilder({
189
+ ...this.schema,
190
+ presence: "defaulted",
191
+ defaultValue: value
192
+ });
193
+ }
194
+ /**
195
+ * Mark this arg as variadic — it consumes all remaining positional
196
+ * arguments. The inferred type becomes `T[]`.
197
+ *
198
+ * A variadic arg must be the last positional in a command.
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * arg.string().variadic()
203
+ *
204
+ * // In a command — collects all remaining positionals:
205
+ * command('build')
206
+ * .arg('entry', arg.string().describe('Main entry'))
207
+ * .arg('extras', arg.string().variadic().optional().describe('Extra files'))
208
+ * .action(({ args }) => {
209
+ * args.entry; // string
210
+ * args.extras; // string[]
211
+ * });
212
+ * // $ mycli build main.ts a.ts b.ts
213
+ * // → entry = 'main.ts', extras = ['a.ts', 'b.ts']
214
+ * ```
215
+ *
216
+ * @returns The builder (for chaining).
217
+ */
218
+ variadic() {
219
+ return new ArgBuilder({
220
+ ...this.schema,
221
+ variadic: true
222
+ });
223
+ }
224
+ /**
225
+ * Allow this arg to resolve from stdin when CLI input is missing.
226
+ *
227
+ * Resolution order becomes: CLI value -> stdin -> env -> default.
228
+ * Only one arg per command may enable stdin mode.
229
+ *
230
+ * @returns The builder (for chaining).
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * arg.string().describe('Input text').stdin()
235
+ * // $ echo "hello" | mycli transform → input = 'hello' (from stdin)
236
+ * // $ mycli transform "hello" → input = 'hello' (from CLI)
237
+ * ```
238
+ */
239
+ stdin() {
240
+ return new ArgBuilder({
241
+ ...this.schema,
242
+ stdinMode: true
243
+ });
244
+ }
245
+ /**
246
+ * Bind to an environment variable.
247
+ *
248
+ * When the arg is not provided on the CLI, the resolver checks this
249
+ * env var before falling back to the default value. The env string is
250
+ * coerced to the arg's declared kind (passthrough for strings, parsed
251
+ * for numbers, run through `parseFn` for custom args).
252
+ *
253
+ * Resolution order when extra sources are configured: **CLI → stdin → env → default**.
254
+ *
255
+ * Help output shows `[env: VAR]` next to the arg description.
256
+ *
257
+ * @param varName - Environment variable name (e.g. `'DEPLOY_TARGET'`).
258
+ * @returns The builder (for chaining).
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * command('deploy')
263
+ * .arg('target', arg.string().env('DEPLOY_TARGET').describe('Deploy target'))
264
+ * .arg('port', arg.number().env('PORT').default(3000))
265
+ * .action(({ args }) => {
266
+ * console.log(args.target); // from CLI, $DEPLOY_TARGET, or error
267
+ * console.log(args.port); // from CLI, $PORT, or 3000
268
+ * });
269
+ * ```
270
+ */
271
+ env(varName) {
272
+ return new ArgBuilder({
273
+ ...this.schema,
274
+ envVar: varName
275
+ });
276
+ }
277
+ /**
278
+ * Human-readable description shown in help output.
279
+ *
280
+ * @param description - Text displayed next to the arg in `--help`.
281
+ * @returns The builder (for chaining).
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * arg.string().describe('Deploy target')
286
+ *
287
+ * // Help output:
288
+ * // Arguments:
289
+ * // <target> Deploy target
290
+ * ```
291
+ */
292
+ describe(description) {
293
+ return new ArgBuilder({
294
+ ...this.schema,
295
+ description
296
+ });
297
+ }
298
+ /**
299
+ * Mark this arg as deprecated.
300
+ *
301
+ * When used, a warning is emitted to stderr. Help text shows
302
+ * `[deprecated]` or `[deprecated: <reason>]`.
303
+ *
304
+ * Does not change the arg's type-level config — it's metadata only.
305
+ *
306
+ * @param message - Optional migration reason/guidance.
307
+ * @returns The builder (for chaining).
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * arg.string().deprecated() // generic
312
+ * arg.string().deprecated('use --target flag instead') // with guidance
313
+ *
314
+ * // Help output:
315
+ * // Arguments:
316
+ * // <target> Deploy target [deprecated: use --target flag instead]
317
+ * ```
318
+ */
319
+ deprecated(message) {
320
+ return new ArgBuilder({
321
+ ...this.schema,
322
+ deprecated: message ?? true
323
+ });
324
+ }
325
+ /**
326
+ * Require an integer value. Composes with other numeric constraints.
327
+ *
328
+ * @param value - Whether to require an integer.
329
+ * @defaultValue `true`
330
+ * @returns The builder (for chaining).
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * arg.number().int() // rejects 3.7, accepts 3
335
+ * arg.number({ int: true }).int(false) // re-allows non-integers
336
+ * ```
337
+ */
338
+ int(value = true) {
339
+ return new ArgBuilder({
340
+ ...this.schema,
341
+ numberConstraints: {
342
+ ...this.schema.numberConstraints,
343
+ int: value
344
+ }
345
+ });
346
+ }
347
+ /**
348
+ * Set an inclusive lower bound. Composes with other numeric constraints;
349
+ * a later call overrides an earlier `min` (including one from the options
350
+ * object).
351
+ *
352
+ * @param value - Inclusive minimum.
353
+ * @returns The builder (for chaining).
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * arg.number().min(0) // rejects -1, accepts 0
358
+ * arg.number({ min: 0 }).min(5) // effective min is 5
359
+ * ```
360
+ */
361
+ min(value) {
362
+ const numberConstraints = {
363
+ ...this.schema.numberConstraints,
364
+ min: value
365
+ };
366
+ assertNumberConstraints(numberConstraints);
367
+ return new ArgBuilder({
368
+ ...this.schema,
369
+ numberConstraints
370
+ });
371
+ }
372
+ /**
373
+ * Set an inclusive upper bound. Composes with other numeric constraints;
374
+ * a later call overrides an earlier `max`.
375
+ *
376
+ * @param value - Inclusive maximum.
377
+ * @returns The builder (for chaining).
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * arg.number().max(100) // rejects 101, accepts 100
382
+ * ```
383
+ */
384
+ max(value) {
385
+ const numberConstraints = {
386
+ ...this.schema.numberConstraints,
387
+ max: value
388
+ };
389
+ assertNumberConstraints(numberConstraints);
390
+ return new ArgBuilder({
391
+ ...this.schema,
392
+ numberConstraints
393
+ });
394
+ }
395
+ /**
396
+ * Require (or, with `false`, allow) a finite value. Finiteness is enforced
397
+ * by default, so this is mainly used as `.finite(false)` to re-allow
398
+ * `Infinity` / `-Infinity`.
399
+ *
400
+ * @param allow - Whether to require a finite value.
401
+ * @defaultValue `true`
402
+ * @returns The builder (for chaining).
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * arg.number().finite(false) // accepts Infinity
407
+ * ```
408
+ */
409
+ finite(allow = true) {
410
+ return new ArgBuilder({
411
+ ...this.schema,
412
+ numberConstraints: {
413
+ ...this.schema.numberConstraints,
414
+ finite: allow
415
+ }
416
+ });
417
+ }
418
+ };
419
+ /**
420
+ * Positional argument schema factory.
421
+ *
422
+ * Entry point for defining args on a command. Use `arg.<kind>()` to create
423
+ * an {@linkcode ArgBuilder}, then chain modifiers and pass the result to
424
+ * `command().arg(name, builder)`.
425
+ *
426
+ * Four kinds are available:
427
+ * - `arg.string()` — raw string (most common)
428
+ * - `arg.number()` — parsed to number, errors on NaN
429
+ * - `arg.enum(values)` — constrained to listed literals
430
+ * - `arg.custom(fn)` — arbitrary parse function, infers return type
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * import { command, arg } from '@kjanat/dreamcli';
435
+ *
436
+ * command('deploy')
437
+ * .arg('target', arg.string().env('DEPLOY_TARGET').describe('Where to deploy'))
438
+ * .arg('port', arg.number().env('PORT').default(3000))
439
+ * .action(({ args }) => {
440
+ * console.log(`Deploying to ${args.target} on port ${args.port}`);
441
+ * });
442
+ *
443
+ * // $ mycli deploy production 8080 → target='production', port=8080
444
+ * // $ DEPLOY_TARGET=staging mycli deploy → target='staging', port=3000
445
+ * ```
446
+ */
447
+ const arg = {
448
+ string() {
449
+ return new ArgBuilder(createArgSchema("string"));
450
+ },
451
+ number(constraints) {
452
+ if (constraints !== void 0) assertNumberConstraints(constraints);
453
+ return new ArgBuilder(createArgSchema("number", constraints !== void 0 ? { numberConstraints: constraints } : {}));
454
+ },
455
+ enum(values) {
456
+ return new ArgBuilder(createArgSchema("enum", { enumValues: values }));
457
+ },
458
+ custom(parseFn) {
459
+ return new ArgBuilder(createArgSchema("custom", { parseFn }));
460
+ }
461
+ };
462
+ //#endregion
463
+ export { ArgBuilder, arg, createArgSchema };
@@ -4,7 +4,7 @@ import { PromptConfig } from "./prompt.mjs";
4
4
  import { FlagBuilder, FlagConfig, FlagSchema, InferFlags } from "./flag.mjs";
5
5
  import { ErasedMiddlewareHandler, Middleware } from "./middleware.mjs";
6
6
  import { RunOptions, RunResult } from "./run.mjs";
7
-
7
+ import { Colors } from "ansispeck";
8
8
  //#region src/core/schema/command.d.ts
9
9
  /**
10
10
  * Widen the context type when adding middleware.
@@ -21,7 +21,7 @@ type WidenContext<C extends Record<string, unknown>, Output extends Record<strin
21
21
  /**
22
22
  * Widen the context type when adding command-scoped derived context.
23
23
  *
24
- * Validation-only derive handlers return `undefined`, preserving `C`.
24
+ * Validation-only derive handlers return `undefined` (or nothing), preserving `C`.
25
25
  * Context-producing derive handlers return an object that merges into `C`
26
26
  * using the same first-call replacement rules as middleware.
27
27
  */
@@ -152,6 +152,23 @@ interface Out {
152
152
  * decorative output should be suppressed regardless of `isTTY`.
153
153
  */
154
154
  readonly isTTY: boolean;
155
+ /**
156
+ * Context-aware ANSI color palette (powered by `ansispeck`).
157
+ *
158
+ * Colors are enabled only when stdout is a TTY, JSON mode is off, and the
159
+ * environment supports color (`NO_COLOR`, `FORCE_COLOR`, `--no-color`,
160
+ * `--color`, `CI` are respected). When disabled, every formatter is an
161
+ * identity function — `out.color.red('x')` returns `'x'` — so handlers can
162
+ * style unconditionally without gating on `isTTY`/`jsonMode` themselves.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * .action(({ out }) => {
167
+ * out.log(`${out.color.green('✔')} deployed ${out.color.bold('api')}`);
168
+ * });
169
+ * ```
170
+ */
171
+ readonly color: Colors;
155
172
  /**
156
173
  * Render tabular data.
157
174
  *
@@ -313,12 +330,13 @@ type DeriveParams<F extends Record<string, FlagBuilder<FlagConfig>>, A extends R
313
330
  *
314
331
  * Derive handlers may:
315
332
  * - validate resolved input and throw {@linkcode CLIError}
316
- * - return `undefined` to continue without changing context
333
+ * - return nothing (or `undefined`) to continue without changing context
317
334
  * - return an object whose properties merge into `ctx` downstream
318
335
  *
336
+ * Handlers may be async; the resolved value follows the same rules.
319
337
  * They cannot wrap downstream execution; use {@linkcode middleware} for that.
320
338
  */
321
- type DeriveHandler<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown> = Record<string, never>, Output extends Record<string, unknown> | undefined = undefined> = (params: DeriveParams<F, A, C>) => Output | Promise<Output>;
339
+ type DeriveHandler<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown> = Record<string, never>, Output extends Record<string, unknown> | undefined = undefined> = (params: DeriveParams<F, A, C>) => Output | Promise<Output> | void | Promise<void>;
322
340
  /**
323
341
  * Type-erased derive handler stored on the command builder.
324
342
  *
@@ -580,9 +598,11 @@ declare class CommandBuilder<F extends Record<string, FlagBuilder<FlagConfig>> =
580
598
  * Derive runs after full resolution and before the action handler.
581
599
  * It receives typed `{ args, flags, ctx, out, meta }` and may either:
582
600
  *
583
- * - return `undefined` for validation-only behavior
601
+ * - return nothing (or `undefined`) for validation-only behavior
584
602
  * - return an object to merge additional properties into `ctx`
585
603
  *
604
+ * Handlers may be async — the runtime awaits them before continuing.
605
+ *
586
606
  * Unlike middleware, derive cannot wrap downstream execution and does not
587
607
  * use `next()`. Use {@linkcode middleware} for timing, logging, retries, cleanup,
588
608
  * or error-boundary patterns.
@@ -611,7 +631,7 @@ declare class CommandBuilder<F extends Record<string, FlagBuilder<FlagConfig>> =
611
631
  * @param handler - Derive function receiving typed args/flags/ctx.
612
632
  * @returns The builder (for chaining).
613
633
  */
614
- derive<Output extends Record<string, unknown> | undefined>(handler: DeriveHandler<F, A, C, Output>): CommandBuilder<F, A, WidenDerivedContext<C, Output>>;
634
+ derive<Output extends Record<string, unknown> | undefined = undefined>(handler: DeriveHandler<F, A, C, Output>): CommandBuilder<F, A, WidenDerivedContext<C, Output>>;
615
635
  /**
616
636
  * Register middleware to run before the action handler.
617
637
  *