@kjanat/dreamcli 2.5.0 → 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 (202) hide show
  1. package/CHANGELOG.md +344 -1
  2. package/README.md +9 -2
  3. package/dist/core/cli/dispatch.d.mts +6 -5
  4. package/dist/core/cli/dispatch.mjs +205 -1
  5. package/dist/core/cli/help-links.d.mts +0 -1
  6. package/dist/core/cli/help-links.mjs +41 -1
  7. package/dist/core/cli/index.d.mts +185 -19
  8. package/dist/core/cli/index.mjs +945 -1
  9. package/dist/core/cli/planner.d.mts +32 -6
  10. package/dist/core/cli/planner.mjs +300 -1
  11. package/dist/core/cli/plugin.d.mts +1 -1
  12. package/dist/core/cli/plugin.mjs +41 -1
  13. package/dist/core/cli/propagate.d.mts +1 -1
  14. package/dist/core/cli/propagate.mjs +57 -1
  15. package/dist/core/cli/root-help.d.mts +18 -3
  16. package/dist/core/cli/root-help.mjs +226 -6
  17. package/dist/core/cli/root-surface.d.mts +30 -4
  18. package/dist/core/cli/root-surface.mjs +28 -1
  19. package/dist/core/cli/runtime-preflight.d.mts +30 -3
  20. package/dist/core/cli/runtime-preflight.mjs +169 -1
  21. package/dist/core/completion/index.d.mts +32 -2
  22. package/dist/core/completion/index.mjs +90 -1
  23. package/dist/core/completion/shells/bash.d.mts +0 -1
  24. package/dist/core/completion/shells/bash.mjs +308 -3
  25. package/dist/core/completion/shells/fish.d.mts +0 -1
  26. package/dist/core/completion/shells/fish.mjs +162 -2
  27. package/dist/core/completion/shells/powershell.d.mts +0 -1
  28. package/dist/core/completion/shells/powershell.mjs +358 -2
  29. package/dist/core/completion/shells/shared.d.mts +23 -2
  30. package/dist/core/completion/shells/shared.mjs +176 -1
  31. package/dist/core/completion/shells/zsh.d.mts +0 -1
  32. package/dist/core/completion/shells/zsh.mjs +251 -2
  33. package/dist/core/config/index.d.mts +2 -3
  34. package/dist/core/config/index.mjs +246 -1
  35. package/dist/core/config/package-json.d.mts +27 -4
  36. package/dist/core/config/package-json.mjs +386 -3
  37. package/dist/core/errors/index.d.mts +3 -3
  38. package/dist/core/errors/index.mjs +87 -1
  39. package/dist/core/execution/index.d.mts +0 -1
  40. package/dist/core/execution/index.mjs +201 -1
  41. package/dist/core/help/ansi.d.mts +11 -5
  42. package/dist/core/help/ansi.mjs +121 -2
  43. package/dist/core/help/index.d.mts +65 -2
  44. package/dist/core/help/index.mjs +341 -7
  45. package/dist/core/help/theme.d.mts +68 -0
  46. package/dist/core/help/theme.mjs +46 -0
  47. package/dist/core/json-schema/index.d.mts +15 -2
  48. package/dist/core/json-schema/index.mjs +536 -12
  49. package/dist/core/json-schema/meta-descriptions.generated.d.mts +22 -5
  50. package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
  51. package/dist/core/output/activity.d.mts +0 -1
  52. package/dist/core/output/activity.mjs +452 -1
  53. package/dist/core/output/bind.mjs +56 -1
  54. package/dist/core/output/contracts.d.mts +4 -5
  55. package/dist/core/output/contracts.mjs +57 -1
  56. package/dist/core/output/display-value.mjs +32 -1
  57. package/dist/core/output/index.d.mts +21 -1
  58. package/dist/core/output/index.mjs +442 -2
  59. package/dist/core/output/renderers.d.mts +0 -1
  60. package/dist/core/output/renderers.mjs +46 -1
  61. package/dist/core/output/writer.mjs +12 -1
  62. package/dist/core/parse/index.d.mts +54 -7
  63. package/dist/core/parse/index.mjs +727 -1
  64. package/dist/core/prompt/index.d.mts +12 -4
  65. package/dist/core/prompt/index.mjs +348 -6
  66. package/dist/core/resolve/args.d.mts +1 -1
  67. package/dist/core/resolve/args.mjs +105 -1
  68. package/dist/core/resolve/coerce.d.mts +1 -1
  69. package/dist/core/resolve/coerce.mjs +336 -1
  70. package/dist/core/resolve/config.mjs +19 -1
  71. package/dist/core/resolve/contracts.d.mts +9 -4
  72. package/dist/core/resolve/errors.d.mts +0 -1
  73. package/dist/core/resolve/errors.mjs +140 -2
  74. package/dist/core/resolve/flags.d.mts +7 -2
  75. package/dist/core/resolve/flags.mjs +251 -1
  76. package/dist/core/resolve/index.d.mts +2 -2
  77. package/dist/core/resolve/index.mjs +85 -1
  78. package/dist/core/resolve/property.d.mts +6 -2
  79. package/dist/core/resolve/property.mjs +53 -1
  80. package/dist/core/schema/activity.d.mts +31 -11
  81. package/dist/core/schema/arg.d.mts +92 -13
  82. package/dist/core/schema/arg.mjs +463 -1
  83. package/dist/core/schema/command.d.mts +29 -7
  84. package/dist/core/schema/command.mjs +726 -1
  85. package/dist/core/schema/flag.d.mts +577 -21
  86. package/dist/core/schema/flag.mjs +705 -1
  87. package/dist/core/schema/index.d.mts +5 -2
  88. package/dist/core/schema/middleware.d.mts +4 -3
  89. package/dist/core/schema/middleware.mjs +41 -1
  90. package/dist/core/schema/number-constraints.d.mts +96 -0
  91. package/dist/core/schema/number-constraints.mjs +60 -0
  92. package/dist/core/schema/prompt.d.mts +21 -3
  93. package/dist/core/schema/run.d.mts +24 -5
  94. package/dist/core/schema/string-constraints.d.mts +97 -0
  95. package/dist/core/schema/string-constraints.mjs +69 -0
  96. package/dist/core/schema/value-parsers.d.mts +78 -0
  97. package/dist/core/schema/value-parsers.mjs +142 -0
  98. package/dist/core/schema-dsl/runtime.mjs +271 -2
  99. package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
  100. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  101. package/dist/core/testkit/index.d.mts +9 -36
  102. package/dist/core/testkit/index.mjs +83 -1
  103. package/dist/index.d.mts +12 -6
  104. package/dist/index.mjs +22 -1
  105. package/dist/runtime/adapter.d.mts +38 -2
  106. package/dist/runtime/adapter.mjs +87 -1
  107. package/dist/runtime/auto.d.mts +2 -3
  108. package/dist/runtime/auto.mjs +45 -1
  109. package/dist/runtime/deno.d.mts +24 -5
  110. package/dist/runtime/deno.mjs +262 -2
  111. package/dist/runtime/detect.mjs +45 -1
  112. package/dist/runtime/index.d.mts +3 -4
  113. package/dist/runtime/node.d.mts +8 -2
  114. package/dist/runtime/node.mjs +220 -2
  115. package/dist/runtime/paths.mjs +48 -1
  116. package/dist/runtime.d.mts +4 -4
  117. package/dist/runtime.mjs +6 -1
  118. package/dist/strings.mjs +22 -1
  119. package/dist/testkit.d.mts +1 -0
  120. package/dist/testkit.mjs +5 -1
  121. package/dist/version.d.mts +7 -3
  122. package/dist/version.mjs +7 -1
  123. package/dreamcli.schema.json +36 -7
  124. package/examples/basic.ts +5 -1
  125. package/examples/gh/package.json +2 -7
  126. package/examples/pwsh-demo/package.json +1 -7
  127. package/examples/pwsh-demo/src/main.test.ts +1 -4
  128. package/examples/pwsh-demo/src/main.ts +14 -4
  129. package/examples/transport-launcher.ts +85 -0
  130. package/package.json +43 -49
  131. package/dist/runtime/bun.d.mts +0 -28
  132. package/dist/runtime/bun.mjs +0 -1
  133. package/dist/runtime/support.d.mts +0 -42
  134. package/dist/runtime/support.mjs +0 -1
  135. package/src/core/cli/dispatch.ts +0 -349
  136. package/src/core/cli/help-links.ts +0 -82
  137. package/src/core/cli/index.ts +0 -1413
  138. package/src/core/cli/planner.ts +0 -487
  139. package/src/core/cli/plugin.ts +0 -117
  140. package/src/core/cli/propagate.ts +0 -97
  141. package/src/core/cli/root-help.ts +0 -252
  142. package/src/core/cli/root-surface.ts +0 -74
  143. package/src/core/cli/runtime-preflight.ts +0 -438
  144. package/src/core/completion/index.ts +0 -88
  145. package/src/core/completion/shells/bash.ts +0 -459
  146. package/src/core/completion/shells/fish.ts +0 -259
  147. package/src/core/completion/shells/powershell.ts +0 -439
  148. package/src/core/completion/shells/shared.ts +0 -283
  149. package/src/core/completion/shells/zsh.ts +0 -381
  150. package/src/core/config/index.ts +0 -417
  151. package/src/core/config/package-json.ts +0 -560
  152. package/src/core/errors/index.ts +0 -193
  153. package/src/core/execution/index.ts +0 -268
  154. package/src/core/help/ansi.ts +0 -144
  155. package/src/core/help/index.ts +0 -516
  156. package/src/core/json-schema/index.ts +0 -891
  157. package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
  158. package/src/core/output/activity.ts +0 -575
  159. package/src/core/output/bind.ts +0 -59
  160. package/src/core/output/contracts.ts +0 -194
  161. package/src/core/output/display-value.ts +0 -48
  162. package/src/core/output/index.ts +0 -704
  163. package/src/core/output/renderers.ts +0 -125
  164. package/src/core/output/writer.ts +0 -46
  165. package/src/core/parse/index.ts +0 -681
  166. package/src/core/prompt/index.ts +0 -583
  167. package/src/core/resolve/args.ts +0 -144
  168. package/src/core/resolve/coerce.ts +0 -432
  169. package/src/core/resolve/config.ts +0 -26
  170. package/src/core/resolve/contracts.ts +0 -135
  171. package/src/core/resolve/errors.ts +0 -227
  172. package/src/core/resolve/flags.ts +0 -255
  173. package/src/core/resolve/index.ts +0 -108
  174. package/src/core/resolve/property.ts +0 -99
  175. package/src/core/schema/activity.ts +0 -240
  176. package/src/core/schema/arg.ts +0 -719
  177. package/src/core/schema/command.ts +0 -1498
  178. package/src/core/schema/flag.ts +0 -801
  179. package/src/core/schema/index.ts +0 -91
  180. package/src/core/schema/middleware.ts +0 -171
  181. package/src/core/schema/prompt.ts +0 -156
  182. package/src/core/schema/run.ts +0 -198
  183. package/src/core/schema-dsl/index.ts +0 -109
  184. package/src/core/schema-dsl/parse.ts +0 -262
  185. package/src/core/schema-dsl/runtime.ts +0 -609
  186. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  187. package/src/core/testkit/index.ts +0 -123
  188. package/src/index.ts +0 -179
  189. package/src/runtime/adapter.ts +0 -303
  190. package/src/runtime/auto.ts +0 -110
  191. package/src/runtime/bun.ts +0 -55
  192. package/src/runtime/deno.ts +0 -369
  193. package/src/runtime/detect.ts +0 -105
  194. package/src/runtime/index.ts +0 -21
  195. package/src/runtime/node-builtins.d.ts +0 -27
  196. package/src/runtime/node.ts +0 -300
  197. package/src/runtime/paths.ts +0 -64
  198. package/src/runtime/support.ts +0 -135
  199. package/src/runtime.ts +0 -31
  200. package/src/strings.ts +0 -34
  201. package/src/testkit.ts +0 -25
  202. package/src/version.ts +0 -20
@@ -1 +1,251 @@
1
- import{ValidationError as e}from"../errors/index.mjs";import{resolvePromptConfig as t}from"../prompt/index.mjs";import{coerceValue as n}from"./coerce.mjs";import{isNonEmpty as r,throwAggregatedErrors as i}from"./errors.mjs";import{resolveConfigPath as a}from"./config.mjs";async function o(t,o,s,c,d,f,p){let m={},h=[],g=new Set;for(let[e,r]of Object.entries(t)){let t=Object.hasOwn(o,e),i=o[e];if(t&&i!==void 0){r.deprecated!==void 0&&p.push({kind:`flag`,name:e,message:r.deprecated}),m[e]=i;continue}if(r.envVar!==void 0){let t=s[r.envVar];if(t!==void 0){let i=n(e,{kind:`env`,envVar:r.envVar},t,r);if(i.ok){r.deprecated!==void 0&&p.push({kind:`flag`,name:e,message:r.deprecated}),m[e]=i.value;continue}h.push(i.error),g.add(e);continue}}if(r.configPath!==void 0){let t=a(c,r.configPath);if(t!==void 0){let i=n(e,{kind:`config`,configPath:r.configPath},t,r);if(i.ok){r.deprecated!==void 0&&p.push({kind:`flag`,name:e,message:r.deprecated}),m[e]=i.value;continue}h.push(i.error),g.add(e)}}}let _=f===void 0?void 0:f({flags:m});for(let[n,r]of Object.entries(t)){if(Object.hasOwn(m,n)||g.has(n))continue;let t=_?.[n],i;if(i=t!=null&&t!==!1&&t!==0&&t!==``?t:t===!1?void 0:r.prompt,i!==void 0&&d!==void 0){let e=await l(n,r,i,d);if(e.ok){r.deprecated!==void 0&&p.push({kind:`flag`,name:n,message:r.deprecated}),m[n]=e.value;continue}if(e.error!==void 0){h.push(e.error);continue}}if(r.defaultValue!==void 0){m[n]=r.defaultValue;continue}if(r.kind===`array`&&r.presence!==`required`){m[n]=[];continue}if(r.presence===`required`){let t={flag:n,kind:r.kind};r.envVar!==void 0&&(t.envVar=r.envVar),r.configPath!==void 0&&(t.configPath=r.configPath),h.push(new e(`Missing required flag --${n}`,{code:`REQUIRED_FLAG`,details:t,suggest:u(n,r)}));continue}m[n]=void 0}return r(h)&&i(h),m}const s={boolean:[`confirm`],string:[`input`,`select`],number:[`input`],enum:[`select`,`input`],array:[`multiselect`],custom:[`input`,`select`,`confirm`,`multiselect`]};function c(t,n,r){let i=s[n];if(!i.includes(r))return new e(`Prompt kind '${r}' is not compatible with ${n} flag --${t}. Use '${i[0]}' instead`,{code:`CONSTRAINT_VIOLATED`,details:{flag:t,flagKind:n,promptKind:r,allowed:i},suggest:`Change the prompt to { kind: '${i[0]}' } for --${t}`})}async function l(e,r,i,a){let o=c(e,r.kind,i.kind);if(o!==void 0)return{ok:!1,error:o};let s=t(i,r.enumValues),l=await a.promptOne(s);return l.answered?n(e,{kind:`prompt`},l.value,r):{ok:!1,error:void 0}}function u(e,t){let n=[];if(n.push(`Provide --${e}${t.kind===`boolean`?``:` <value>`}`),t.envVar!==void 0&&n.push(`set ${t.envVar}`),t.configPath!==void 0&&n.push(`add ${t.configPath} to config`),n.length<=1)return n.join(``);let r=n.slice(0,-1),i=n.slice(-1).join(``);return n.length===2?`${r.join(``)} or ${i}`:`${r.join(`, `)}, or ${i}`}export{o as resolveFlags};
1
+ import { ValidationError } from "../errors/index.mjs";
2
+ import { resolvePromptConfig } from "../prompt/index.mjs";
3
+ import { coerceValue } from "./coerce.mjs";
4
+ import { isNonEmpty, throwAggregatedErrors } from "./errors.mjs";
5
+ import { resolveConfigPath } from "./config.mjs";
6
+ //#region src/core/resolve/flags.ts
7
+ /**
8
+ * Internal flag resolution helpers.
9
+ *
10
+ * @module dreamcli/core/resolve/flags
11
+ * @internal
12
+ */
13
+ /** Walk every declared flag through the resolution chain (cli -> env -> config -> prompt -> default), collecting deprecations and throwing aggregated errors. */
14
+ async function resolveFlags(flagSchemas, parsedFlags, env, config, prompter, interactive, deprecations, stat) {
15
+ const resolved = {};
16
+ const errors = [];
17
+ const hardErrorFlags = /* @__PURE__ */ new Set();
18
+ for (const [name, schema] of Object.entries(flagSchemas)) {
19
+ const hasParsedValue = Object.hasOwn(parsedFlags, name);
20
+ const parsedValue = parsedFlags[name];
21
+ if (hasParsedValue && parsedValue !== void 0) {
22
+ if (schema.deprecated !== void 0) deprecations.push({
23
+ kind: "flag",
24
+ name,
25
+ message: schema.deprecated
26
+ });
27
+ resolved[name] = parsedValue;
28
+ continue;
29
+ }
30
+ if (schema.envVar !== void 0) {
31
+ const envValue = env[schema.envVar];
32
+ if (envValue !== void 0) {
33
+ const coerced = coerceValue(name, {
34
+ kind: "env",
35
+ envVar: schema.envVar
36
+ }, envValue, schema);
37
+ if (coerced.ok) {
38
+ if (schema.deprecated !== void 0) deprecations.push({
39
+ kind: "flag",
40
+ name,
41
+ message: schema.deprecated
42
+ });
43
+ resolved[name] = coerced.value;
44
+ continue;
45
+ }
46
+ errors.push(coerced.error);
47
+ hardErrorFlags.add(name);
48
+ continue;
49
+ }
50
+ }
51
+ if (schema.configPath !== void 0) {
52
+ const configValue = resolveConfigPath(config, schema.configPath);
53
+ if (configValue !== void 0) {
54
+ const coerced = coerceValue(name, {
55
+ kind: "config",
56
+ configPath: schema.configPath
57
+ }, configValue, schema);
58
+ if (coerced.ok) {
59
+ if (schema.deprecated !== void 0) deprecations.push({
60
+ kind: "flag",
61
+ name,
62
+ message: schema.deprecated
63
+ });
64
+ resolved[name] = coerced.value;
65
+ continue;
66
+ }
67
+ errors.push(coerced.error);
68
+ hardErrorFlags.add(name);
69
+ }
70
+ }
71
+ }
72
+ const interactiveConfigs = interactive !== void 0 ? interactive({ flags: resolved }) : void 0;
73
+ for (const [name, schema] of Object.entries(flagSchemas)) {
74
+ if (Object.hasOwn(resolved, name) || hardErrorFlags.has(name)) continue;
75
+ const interactiveConfig = interactiveConfigs?.[name];
76
+ let effectivePromptConfig;
77
+ if (interactiveConfig !== void 0 && interactiveConfig !== null && interactiveConfig !== false && interactiveConfig !== 0 && interactiveConfig !== "") effectivePromptConfig = interactiveConfig;
78
+ else if (interactiveConfig === false) effectivePromptConfig = void 0;
79
+ else effectivePromptConfig = schema.prompt;
80
+ if (effectivePromptConfig !== void 0 && prompter !== void 0) {
81
+ const promptResult = await resolvePromptValueWithConfig(name, schema, effectivePromptConfig, prompter);
82
+ if (promptResult.ok) {
83
+ if (schema.deprecated !== void 0) deprecations.push({
84
+ kind: "flag",
85
+ name,
86
+ message: schema.deprecated
87
+ });
88
+ resolved[name] = promptResult.value;
89
+ continue;
90
+ }
91
+ if (promptResult.error !== void 0) {
92
+ errors.push(promptResult.error);
93
+ continue;
94
+ }
95
+ }
96
+ if (schema.defaultValue !== void 0) {
97
+ resolved[name] = schema.defaultValue;
98
+ continue;
99
+ }
100
+ if (schema.kind === "array" && schema.presence !== "required") {
101
+ resolved[name] = [];
102
+ continue;
103
+ }
104
+ if (schema.kind === "keyValue" && schema.presence !== "required") {
105
+ resolved[name] = {};
106
+ continue;
107
+ }
108
+ if (schema.presence === "required") {
109
+ const details = {
110
+ flag: name,
111
+ kind: schema.kind
112
+ };
113
+ if (schema.envVar !== void 0) details.envVar = schema.envVar;
114
+ if (schema.configPath !== void 0) details.configPath = schema.configPath;
115
+ errors.push(new ValidationError(`Missing required flag --${name}`, {
116
+ code: "REQUIRED_FLAG",
117
+ details,
118
+ suggest: buildRequiredFlagSuggest(name, schema)
119
+ }));
120
+ continue;
121
+ }
122
+ resolved[name] = void 0;
123
+ }
124
+ for (const [name, schema] of Object.entries(flagSchemas)) {
125
+ const value = resolved[name];
126
+ if (schema.kind === "array" && schema.unique && Array.isArray(value)) resolved[name] = [...new Set(value)];
127
+ if (schema.pathChecks !== void 0 && typeof value === "string" && stat !== void 0) {
128
+ const violation = await validatePathChecks(name, value, schema.pathChecks, stat);
129
+ if (violation !== void 0) errors.push(violation);
130
+ }
131
+ }
132
+ if (isNonEmpty(errors)) throwAggregatedErrors(errors);
133
+ return resolved;
134
+ }
135
+ /**
136
+ * Check a resolved path value against its declared filesystem expectations.
137
+ *
138
+ * @returns `undefined` when the path satisfies the checks, or a
139
+ * {@link ValidationError} with code `'CONSTRAINT_VIOLATED'` otherwise.
140
+ * @internal
141
+ */
142
+ async function validatePathChecks(flagName, value, checks, stat) {
143
+ const found = await stat(value);
144
+ if (found === null) return new ValidationError(`Path '${value}' for flag --${flagName} does not exist`, {
145
+ code: "CONSTRAINT_VIOLATED",
146
+ details: {
147
+ flag: flagName,
148
+ value,
149
+ constraint: "mustExist"
150
+ },
151
+ suggest: `Provide an existing path for --${flagName}`
152
+ });
153
+ if (checks.type !== void 0 && found !== checks.type) return new ValidationError(`Path '${value}' for flag --${flagName} is a ${found}, expected a ${checks.type}`, {
154
+ code: "CONSTRAINT_VIOLATED",
155
+ details: {
156
+ flag: flagName,
157
+ value,
158
+ constraint: "pathType",
159
+ expected: checks.type
160
+ },
161
+ suggest: `Provide a ${checks.type} path for --${flagName}`
162
+ });
163
+ }
164
+ /** Maps each flag kind to the prompt kinds that produce compatible values. */
165
+ const COMPATIBLE_PROMPT_KINDS = {
166
+ boolean: ["confirm"],
167
+ string: ["input", "select"],
168
+ number: ["input"],
169
+ enum: ["select", "input"],
170
+ array: ["multiselect"],
171
+ custom: [
172
+ "input",
173
+ "select",
174
+ "confirm",
175
+ "multiselect"
176
+ ],
177
+ count: [],
178
+ keyValue: []
179
+ };
180
+ /**
181
+ * Check whether a prompt kind is compatible with the flag's declared kind.
182
+ *
183
+ * @returns `undefined` when compatible, or a {@link ValidationError} with
184
+ * code `'CONSTRAINT_VIOLATED'` and an actionable `suggest` message when not.
185
+ * @internal
186
+ */
187
+ function validatePromptFlagCompatibility(flagName, flagKind, promptKind) {
188
+ const allowed = COMPATIBLE_PROMPT_KINDS[flagKind];
189
+ if (allowed.includes(promptKind)) return void 0;
190
+ const first = allowed[0];
191
+ if (first === void 0) return new ValidationError(`Prompt kind '${promptKind}' is not compatible with ${flagKind} flag --${flagName}. ${flagKind} flags are not promptable`, {
192
+ code: "CONSTRAINT_VIOLATED",
193
+ details: {
194
+ flag: flagName,
195
+ flagKind,
196
+ promptKind,
197
+ allowed
198
+ },
199
+ suggest: `Remove the prompt config for --${flagName}`
200
+ });
201
+ return new ValidationError(`Prompt kind '${promptKind}' is not compatible with ${flagKind} flag --${flagName}. Use '${first}' instead`, {
202
+ code: "CONSTRAINT_VIOLATED",
203
+ details: {
204
+ flag: flagName,
205
+ flagKind,
206
+ promptKind,
207
+ allowed
208
+ },
209
+ suggest: `Change the prompt to { kind: '${first}' } for --${flagName}`
210
+ });
211
+ }
212
+ /**
213
+ * Validate prompt/flag compatibility, run the prompt engine, and coerce the result.
214
+ *
215
+ * Returns early with a {@link ValidationError} if the prompt kind is
216
+ * incompatible with the flag kind (checked via {@link COMPATIBLE_PROMPT_KINDS}
217
+ * before the prompter is invoked).
218
+ * @internal
219
+ */
220
+ async function resolvePromptValueWithConfig(flagName, schema, promptConfig, prompter) {
221
+ const mismatch = validatePromptFlagCompatibility(flagName, schema.kind, promptConfig.kind);
222
+ if (mismatch !== void 0) return {
223
+ ok: false,
224
+ error: mismatch
225
+ };
226
+ const resolvedConfig = resolvePromptConfig(promptConfig, schema.enumValues);
227
+ const result = await prompter.promptOne(resolvedConfig);
228
+ if (!result.answered) return {
229
+ ok: false,
230
+ error: void 0
231
+ };
232
+ if (promptConfig.kind === "input" && promptConfig.default === void 0 && typeof result.value === "string" && result.value.trim() === "") return {
233
+ ok: false,
234
+ error: void 0
235
+ };
236
+ return coerceValue(flagName, { kind: "prompt" }, result.value, schema);
237
+ }
238
+ /** Build a human-readable suggestion listing all available sources for a required flag. @internal */
239
+ function buildRequiredFlagSuggest(name, schema) {
240
+ const sources = [];
241
+ const takesValue = schema.kind !== "boolean" && schema.kind !== "count";
242
+ sources.push(`Provide --${name}${takesValue ? " <value>" : ""}`);
243
+ if (schema.envVar !== void 0) sources.push(`set ${schema.envVar}`);
244
+ if (schema.configPath !== void 0) sources.push(`add ${schema.configPath} to config`);
245
+ if (sources.length <= 1) return sources.join("");
246
+ const rest = sources.slice(0, -1);
247
+ const last = sources.slice(-1).join("");
248
+ return sources.length === 2 ? `${rest.join("")} or ${last}` : `${rest.join(", ")}, or ${last}`;
249
+ }
250
+ //#endregion
251
+ export { COMPATIBLE_PROMPT_KINDS, resolveFlags };
@@ -1,7 +1,7 @@
1
- import { ParseResult } from "../parse/index.mjs";
2
1
  import { DeprecationWarning, ResolveOptions, ResolveResult } from "./contracts.mjs";
3
2
  import { CommandSchema } from "../schema/command.mjs";
4
-
3
+ import "../schema/index.mjs";
4
+ import { ParseResult } from "../parse/index.mjs";
5
5
  //#region src/core/resolve/index.d.ts
6
6
  /**
7
7
  * Resolve parsed values against a command schema.
@@ -1 +1,85 @@
1
- import{isValidationError as e}from"../errors/index.mjs";import{collectValidationErrors as t,isNonEmpty as n,throwAggregatedErrors as r}from"./errors.mjs";import{resolveArgs as i}from"./args.mjs";import{resolveFlags as a}from"./flags.mjs";async function o(o,s,c){let l=c?.stdinData,u=c?.env??{},d=c?.config??{},f=c?.prompter,p=[],m={},h={},g=[];try{m=await a(o.flags,s.flags,u,d,f,o.interactive,p)}catch(n){if(!e(n))throw n;g.push(...t(n))}try{h=i(o.args,s.args,l,u,p)}catch(n){if(!e(n))throw n;g.push(...t(n))}return n(g)&&r(g),{flags:m,args:h,deprecations:p}}export{o as resolve};
1
+ import { isValidationError } from "../errors/index.mjs";
2
+ import { collectValidationErrors, isNonEmpty, throwAggregatedErrors } from "./errors.mjs";
3
+ import { resolveArgs } from "./args.mjs";
4
+ import { resolveFlags } from "./flags.mjs";
5
+ //#region src/core/resolve/index.ts
6
+ /**
7
+ * Resolution chain: CLI -> env -> config -> prompt -> default.
8
+ *
9
+ * v0.1 implemented: **CLI parsed value -> default value**.
10
+ * v0.2 adds: **env variable resolution** and **config object resolution**
11
+ * between CLI and default.
12
+ * v0.3 adds: **prompt resolution** between config and default.
13
+ *
14
+ * The resolver takes raw {@linkcode ParseResult} (from the parser) and a
15
+ * {@linkcode CommandSchema}, applies the resolution chain, and validates
16
+ * that all required flags/args are present. On success it returns a
17
+ * {@linkcode ResolveResult} with fully resolved values; on failure it throws
18
+ * {@linkcode ValidationError}.
19
+ *
20
+ * @module dreamcli/core/resolve
21
+ */
22
+ /**
23
+ * Resolve parsed values against a command schema.
24
+ *
25
+ * Low-level API: most applications should rely on `cli().run()`, `.execute()`,
26
+ * or `runCommand()`, which already call {@linkcode resolve} at the right time.
27
+ * Reach for this function when testing precedence rules directly or building
28
+ * custom execution flows around {@linkcode CommandSchema}.
29
+ *
30
+ * Resolution order:
31
+ * 1. CLI parsed value (from {@linkcode ParseResult})
32
+ * 2. Env variable (from {@linkcode ResolveOptions.env}, if flag declares `envVar`)
33
+ * 3. Config value (from {@linkcode ResolveOptions.config}, if flag declares `configPath`)
34
+ * 4. Prompt (from {@linkcode ResolveOptions.prompter}, if flag declares `prompt`)
35
+ * 5. Default value (from schema)
36
+ *
37
+ * After resolution, validates that all required flags and args have
38
+ * a value. Collects **all** validation errors before throwing, so the
39
+ * user sees every missing field at once.
40
+ *
41
+ * @param schema - The command schema defining flags and args
42
+ * @param parsed - Raw parsed values from the parser
43
+ * @param options - External state for the resolution chain
44
+ * @returns Fully resolved flag and arg values
45
+ * @throws {@linkcode ValidationError} if any required flag or arg is missing,
46
+ * or if an env/config value fails coercion
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const parsed = parse(deploy.schema, ['production']);
51
+ * const resolved = await resolve(deploy.schema, parsed, {
52
+ * env: { DEPLOY_REGION: 'eu' },
53
+ * });
54
+ * ```
55
+ */
56
+ async function resolve(schema, parsed, options) {
57
+ const stdinData = options?.stdinData;
58
+ const env = options?.env ?? {};
59
+ const config = options?.config ?? {};
60
+ const prompter = options?.prompter;
61
+ const deprecations = [];
62
+ let flags = {};
63
+ let args = {};
64
+ const errors = [];
65
+ try {
66
+ flags = await resolveFlags(schema.flags, parsed.flags, env, config, prompter, schema.interactive, deprecations, options?.stat);
67
+ } catch (error) {
68
+ if (!isValidationError(error)) throw error;
69
+ errors.push(...collectValidationErrors(error));
70
+ }
71
+ try {
72
+ args = resolveArgs(schema.args, parsed.args, stdinData, env, deprecations);
73
+ } catch (error) {
74
+ if (!isValidationError(error)) throw error;
75
+ errors.push(...collectValidationErrors(error));
76
+ }
77
+ if (isNonEmpty(errors)) throwAggregatedErrors(errors);
78
+ return {
79
+ flags,
80
+ args,
81
+ deprecations
82
+ };
83
+ }
84
+ //#endregion
85
+ export { resolve };
@@ -1,16 +1,20 @@
1
+ import { NumberConstraints } from "../schema/number-constraints.mjs";
1
2
  import { ArgSchema } from "../schema/arg.mjs";
3
+ import { StringConstraints } from "../schema/string-constraints.mjs";
2
4
  import { FlagSchema } from "../schema/flag.mjs";
3
-
5
+ import "../schema/index.mjs";
4
6
  //#region src/core/resolve/property.d.ts
5
7
  /** Flag/arg kinds that share a common coercion path. */
6
- declare const SHARED_PROPERTY_MODEL_KINDS: readonly ['string', 'number', 'enum', 'custom'];
8
+ declare const SHARED_PROPERTY_MODEL_KINDS: readonly ["string", "number", "enum", "custom"];
7
9
  /** Union of kind discriminants that participate in shared coercion. */
8
10
  type SharedPropertyKind = (typeof SHARED_PROPERTY_MODEL_KINDS)[number];
9
11
  /** Minimal coercion-relevant slice of a flag or arg schema, discriminated by kind. */
10
12
  type SharedPropertySchema = {
11
13
  readonly kind: 'string';
14
+ readonly stringConstraints: StringConstraints | undefined;
12
15
  } | {
13
16
  readonly kind: 'number';
17
+ readonly numberConstraints: NumberConstraints | undefined;
14
18
  } | {
15
19
  readonly kind: 'enum';
16
20
  readonly enumValues: readonly string[] | undefined;
@@ -1 +1,53 @@
1
- function e(e){switch(e.kind){case`string`:return{kind:`string`};case`number`:return{kind:`number`};case`enum`:return{kind:`enum`,enumValues:e.enumValues};case`custom`:return e.parseFn===void 0?{kind:`custom`}:{kind:`custom`,parseFn:e.parseFn};case`boolean`:case`array`:return}}function t(e){switch(e.kind){case`string`:return{kind:`string`};case`number`:return{kind:`number`};case`enum`:return{kind:`enum`,enumValues:e.enumValues};case`custom`:{if(e.parseFn===void 0)return{kind:`custom`};let t=e.parseFn;return{kind:`custom`,parseFn:e=>t(typeof e==`string`?e:String(e))}}}}export{t as toSharedArgPropertySchema,e as toSharedFlagPropertySchema};
1
+ //#region src/core/resolve/property.ts
2
+ /** Extract the shared coercion slice from a flag schema, or `undefined` for boolean/array (handled separately). */
3
+ function toSharedFlagPropertySchema(schema) {
4
+ switch (schema.kind) {
5
+ case "string": return {
6
+ kind: "string",
7
+ stringConstraints: schema.stringConstraints
8
+ };
9
+ case "number": return {
10
+ kind: "number",
11
+ numberConstraints: schema.numberConstraints
12
+ };
13
+ case "enum": return {
14
+ kind: "enum",
15
+ enumValues: schema.enumValues
16
+ };
17
+ case "custom": return schema.parseFn === void 0 ? { kind: "custom" } : {
18
+ kind: "custom",
19
+ parseFn: schema.parseFn
20
+ };
21
+ case "boolean":
22
+ case "array":
23
+ case "count":
24
+ case "keyValue": return;
25
+ }
26
+ }
27
+ /** Extract the shared coercion slice from an arg schema (all arg kinds are shared). */
28
+ function toSharedArgPropertySchema(schema) {
29
+ switch (schema.kind) {
30
+ case "string": return {
31
+ kind: "string",
32
+ stringConstraints: void 0
33
+ };
34
+ case "number": return {
35
+ kind: "number",
36
+ numberConstraints: schema.numberConstraints
37
+ };
38
+ case "enum": return {
39
+ kind: "enum",
40
+ enumValues: schema.enumValues
41
+ };
42
+ case "custom": {
43
+ if (schema.parseFn === void 0) return { kind: "custom" };
44
+ const parseFn = schema.parseFn;
45
+ return {
46
+ kind: "custom",
47
+ parseFn: (raw) => parseFn(typeof raw === "string" ? raw : String(raw))
48
+ };
49
+ }
50
+ }
51
+ }
52
+ //#endregion
53
+ export { toSharedArgPropertySchema, toSharedFlagPropertySchema };
@@ -87,34 +87,54 @@ interface ProgressHandle {
87
87
  * without polluting stdout/stderr arrays.
88
88
  */
89
89
  type ActivityEvent = {
90
- /** Spinner created and started. */readonly type: 'spinner:start'; /** Initial spinner text. */
90
+ /** Spinner created and started. */
91
+ readonly type: 'spinner:start';
92
+ /** Initial spinner text. */
91
93
  readonly text: string;
92
94
  } | {
93
- /** Spinner text changed. */readonly type: 'spinner:update'; /** Updated spinner text. */
95
+ /** Spinner text changed. */
96
+ readonly type: 'spinner:update';
97
+ /** Updated spinner text. */
94
98
  readonly text: string;
95
99
  } | {
96
- /** Spinner completed successfully. */readonly type: 'spinner:succeed'; /** Success message. */
100
+ /** Spinner completed successfully. */
101
+ readonly type: 'spinner:succeed';
102
+ /** Success message. */
97
103
  readonly text: string;
98
104
  } | {
99
- /** Spinner stopped with an error. */readonly type: 'spinner:fail'; /** Failure message. */
105
+ /** Spinner stopped with an error. */
106
+ readonly type: 'spinner:fail';
107
+ /** Failure message. */
100
108
  readonly text: string;
101
109
  } | {
102
- /** Spinner stopped without a final status. */readonly type: 'spinner:stop';
110
+ /** Spinner stopped without a final status. */
111
+ readonly type: 'spinner:stop';
103
112
  } | {
104
- /** Progress bar created and started. */readonly type: 'progress:start'; /** Bar label. */
105
- readonly label: string; /** Known total, or `undefined` for indeterminate. */
113
+ /** Progress bar created and started. */
114
+ readonly type: 'progress:start';
115
+ /** Bar label. */
116
+ readonly label: string;
117
+ /** Known total, or `undefined` for indeterminate. */
106
118
  readonly total: number | undefined;
107
119
  } | {
108
- /** Progress bar advanced. */readonly type: 'progress:increment'; /** Amount advanced. */
120
+ /** Progress bar advanced. */
121
+ readonly type: 'progress:increment';
122
+ /** Amount advanced. */
109
123
  readonly delta: number;
110
124
  } | {
111
- /** Progress bar set to an absolute value. */readonly type: 'progress:update'; /** New absolute value. */
125
+ /** Progress bar set to an absolute value. */
126
+ readonly type: 'progress:update';
127
+ /** New absolute value. */
112
128
  readonly value: number;
113
129
  } | {
114
- /** Progress bar completed. */readonly type: 'progress:done'; /** Completion message, if any. */
130
+ /** Progress bar completed. */
131
+ readonly type: 'progress:done';
132
+ /** Completion message, if any. */
115
133
  readonly text: string | undefined;
116
134
  } | {
117
- /** Progress bar stopped with an error. */readonly type: 'progress:fail'; /** Failure message, if any. */
135
+ /** Progress bar stopped with an error. */
136
+ readonly type: 'progress:fail';
137
+ /** Failure message, if any. */
118
138
  readonly text: string | undefined;
119
139
  };
120
140
  /**
@@ -1,15 +1,7 @@
1
+ import { NumberConstraints } from "./number-constraints.mjs";
1
2
  //#region src/core/schema/arg.d.ts
2
- /**
3
- * Positional argument schema builder with full type inference.
4
- *
5
- * Each factory (`arg.string()`, `arg.number()`, `arg.enum()`, `arg.custom()`) returns an
6
- * immutable {@linkcode ArgBuilder} whose generic parameter tracks the value type,
7
- * presence state, and variadic flag through the fluent chain.
8
- *
9
- * @module dreamcli/core/schema/arg
10
- */
11
3
  /** All arg presence states as a runtime array. */
12
- declare const ARG_PRESENCES: readonly ['required', 'optional', 'defaulted'];
4
+ declare const ARG_PRESENCES: readonly ["required", "optional", "defaulted"];
13
5
  /**
14
6
  * Presence describes whether a positional arg is guaranteed to exist when the
15
7
  * action handler runs:
@@ -29,6 +21,8 @@ interface ArgConfig {
29
21
  readonly presence: ArgPresence;
30
22
  /** Whether this arg consumes remaining positionals. */
31
23
  readonly variadic: boolean;
24
+ /** The runtime kind discriminator, mirroring {@link ArgKind}. */
25
+ readonly argKind: ArgKind;
32
26
  }
33
27
  /**
34
28
  * Advanced type helper used by {@linkcode ArgBuilder} modifiers to replace presence.
@@ -38,6 +32,7 @@ type WithArgPresence<C extends ArgConfig, P extends ArgPresence> = {
38
32
  readonly valueType: C['valueType'];
39
33
  readonly presence: P;
40
34
  readonly variadic: C['variadic'];
35
+ readonly argKind: C['argKind'];
41
36
  };
42
37
  /**
43
38
  * Advanced type helper used by {@linkcode ArgBuilder.variadic | ArgBuilder.variadic()}.
@@ -47,6 +42,7 @@ type WithVariadic<C extends ArgConfig> = {
47
42
  readonly valueType: C['valueType'];
48
43
  readonly presence: C['presence'];
49
44
  readonly variadic: true;
45
+ readonly argKind: C['argKind'];
50
46
  };
51
47
  /**
52
48
  * Compute the final value type from config — this is what handlers receive.
@@ -63,9 +59,9 @@ type ResolvedArgValue<C extends ArgConfig> = C['variadic'] extends true ? C['val
63
59
  /** Extract the resolved value type from an {@linkcode ArgBuilder}. */
64
60
  type InferArg<B> = B extends ArgBuilder<infer C extends ArgConfig> ? ResolvedArgValue<C> : never;
65
61
  /** Extract resolved value types from a record of builders. */
66
- type InferArgs<T extends Record<string, ArgBuilder<ArgConfig>>> = { [K in keyof T]: InferArg<T[K]> };
62
+ type InferArgs<T extends Record<string, ArgBuilder<ArgConfig>>> = { [K in keyof T]: InferArg<T[K]>; };
67
63
  /** All arg kind discriminators as a runtime array. */
68
- declare const ARG_KINDS: readonly ['string', 'number', 'enum', 'custom'];
64
+ declare const ARG_KINDS: readonly ["string", "number", "enum", "custom"];
69
65
  /** Discriminator for the kind of value an arg accepts. */
70
66
  type ArgKind = (typeof ARG_KINDS)[number];
71
67
  /** Custom parse function for `arg.custom()`. */
@@ -102,6 +98,13 @@ interface ArgSchema {
102
98
  readonly envVar: string | undefined;
103
99
  /** Allowed literal values when `kind === 'enum'`. */
104
100
  readonly enumValues: readonly string[] | undefined;
101
+ /**
102
+ * Numeric constraints when `kind === 'number'` (`undefined` otherwise).
103
+ *
104
+ * Enforced at the parse and resolution boundaries. `finite` defaults to
105
+ * `true`, so `Infinity` is rejected even when no constraints object is set.
106
+ */
107
+ readonly numberConstraints: NumberConstraints | undefined;
105
108
  /** Custom parse function (only when `kind === 'custom'`). */
106
109
  readonly parseFn: ArgParseFn<unknown> | undefined;
107
110
  /**
@@ -376,6 +379,71 @@ declare class ArgBuilder<C extends ArgConfig> {
376
379
  * ```
377
380
  */
378
381
  deprecated(message?: string): ArgBuilder<C>;
382
+ /**
383
+ * Require an integer value. Composes with other numeric constraints.
384
+ *
385
+ * @param value - Whether to require an integer.
386
+ * @defaultValue `true`
387
+ * @returns The builder (for chaining).
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * arg.number().int() // rejects 3.7, accepts 3
392
+ * arg.number({ int: true }).int(false) // re-allows non-integers
393
+ * ```
394
+ */
395
+ int(this: ArgBuilder<C & {
396
+ readonly argKind: 'number';
397
+ }>, value?: boolean): ArgBuilder<C>;
398
+ /**
399
+ * Set an inclusive lower bound. Composes with other numeric constraints;
400
+ * a later call overrides an earlier `min` (including one from the options
401
+ * object).
402
+ *
403
+ * @param value - Inclusive minimum.
404
+ * @returns The builder (for chaining).
405
+ *
406
+ * @example
407
+ * ```ts
408
+ * arg.number().min(0) // rejects -1, accepts 0
409
+ * arg.number({ min: 0 }).min(5) // effective min is 5
410
+ * ```
411
+ */
412
+ min(this: ArgBuilder<C & {
413
+ readonly argKind: 'number';
414
+ }>, value: number): ArgBuilder<C>;
415
+ /**
416
+ * Set an inclusive upper bound. Composes with other numeric constraints;
417
+ * a later call overrides an earlier `max`.
418
+ *
419
+ * @param value - Inclusive maximum.
420
+ * @returns The builder (for chaining).
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * arg.number().max(100) // rejects 101, accepts 100
425
+ * ```
426
+ */
427
+ max(this: ArgBuilder<C & {
428
+ readonly argKind: 'number';
429
+ }>, value: number): ArgBuilder<C>;
430
+ /**
431
+ * Require (or, with `false`, allow) a finite value. Finiteness is enforced
432
+ * by default, so this is mainly used as `.finite(false)` to re-allow
433
+ * `Infinity` / `-Infinity`.
434
+ *
435
+ * @param allow - Whether to require a finite value.
436
+ * @defaultValue `true`
437
+ * @returns The builder (for chaining).
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * arg.number().finite(false) // accepts Infinity
442
+ * ```
443
+ */
444
+ finite(this: ArgBuilder<C & {
445
+ readonly argKind: 'number';
446
+ }>, allow?: boolean): ArgBuilder<C>;
379
447
  }
380
448
  /**
381
449
  * Arg factory functions — the public API for creating positional arguments.
@@ -439,6 +507,7 @@ interface ArgFactory {
439
507
  readonly valueType: string;
440
508
  readonly presence: 'required';
441
509
  readonly variadic: false;
510
+ readonly argKind: 'string';
442
511
  }>;
443
512
  /**
444
513
  * Number-valued positional argument. Required by default.
@@ -460,12 +529,20 @@ interface ArgFactory {
460
529
  * // $ mycli serve → 3000
461
530
  * ```
462
531
  *
532
+ * Constraints are enforced at the parse and resolution boundaries and also
533
+ * compose via chained methods (`.int()`, `.min()`, `.max()`, `.finite()`),
534
+ * which override values set here. The resolved value type stays `number`.
535
+ *
536
+ * @param constraints - Optional numeric constraints. `finite` defaults to
537
+ * `true`, so `Infinity` / `-Infinity` are rejected unless `finite: false`.
538
+ * @defaultValue `undefined` (finite-only, no bounds, non-integer allowed)
463
539
  * @returns A required number {@link ArgBuilder}.
464
540
  */
465
- number(): ArgBuilder<{
541
+ number(constraints?: NumberConstraints): ArgBuilder<{
466
542
  readonly valueType: number;
467
543
  readonly presence: 'required';
468
544
  readonly variadic: false;
545
+ readonly argKind: 'number';
469
546
  }>;
470
547
  /**
471
548
  * Enum-valued positional argument. Required by default.
@@ -494,6 +571,7 @@ interface ArgFactory {
494
571
  readonly valueType: T[number];
495
572
  readonly presence: 'required';
496
573
  readonly variadic: false;
574
+ readonly argKind: 'enum';
497
575
  }>;
498
576
  /**
499
577
  * Custom-parsed positional argument. Required by default.
@@ -524,6 +602,7 @@ interface ArgFactory {
524
602
  readonly valueType: T;
525
603
  readonly presence: 'required';
526
604
  readonly variadic: false;
605
+ readonly argKind: 'custom';
527
606
  }>;
528
607
  }
529
608
  /**