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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/CHANGELOG.md +227 -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,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||i.kind===`input`&&i.default===void 0&&typeof l.value==`string`&&l.value.trim()===``?{ok:!1,error:void 0}:n(e,{kind:`prompt`},l.value,r)}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,15 +1,17 @@
1
1
  import { NumberConstraints } from "../schema/number-constraints.mjs";
2
2
  import { ArgSchema } from "../schema/arg.mjs";
3
+ import { StringConstraints } from "../schema/string-constraints.mjs";
3
4
  import { FlagSchema } from "../schema/flag.mjs";
4
-
5
+ import "../schema/index.mjs";
5
6
  //#region src/core/resolve/property.d.ts
6
7
  /** Flag/arg kinds that share a common coercion path. */
7
- declare const SHARED_PROPERTY_MODEL_KINDS: readonly ['string', 'number', 'enum', 'custom'];
8
+ declare const SHARED_PROPERTY_MODEL_KINDS: readonly ["string", "number", "enum", "custom"];
8
9
  /** Union of kind discriminants that participate in shared coercion. */
9
10
  type SharedPropertyKind = (typeof SHARED_PROPERTY_MODEL_KINDS)[number];
10
11
  /** Minimal coercion-relevant slice of a flag or arg schema, discriminated by kind. */
11
12
  type SharedPropertySchema = {
12
13
  readonly kind: 'string';
14
+ readonly stringConstraints: StringConstraints | undefined;
13
15
  } | {
14
16
  readonly kind: 'number';
15
17
  readonly numberConstraints: NumberConstraints | undefined;
@@ -1 +1,53 @@
1
- function e(e){switch(e.kind){case`string`:return{kind:`string`};case`number`:return{kind:`number`,numberConstraints:e.numberConstraints};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`,numberConstraints:e.numberConstraints};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,8 +1,7 @@
1
1
  import { NumberConstraints } from "./number-constraints.mjs";
2
-
3
2
  //#region src/core/schema/arg.d.ts
4
3
  /** All arg presence states as a runtime array. */
5
- declare const ARG_PRESENCES: readonly ['required', 'optional', 'defaulted'];
4
+ declare const ARG_PRESENCES: readonly ["required", "optional", "defaulted"];
6
5
  /**
7
6
  * Presence describes whether a positional arg is guaranteed to exist when the
8
7
  * action handler runs:
@@ -60,9 +59,9 @@ type ResolvedArgValue<C extends ArgConfig> = C['variadic'] extends true ? C['val
60
59
  /** Extract the resolved value type from an {@linkcode ArgBuilder}. */
61
60
  type InferArg<B> = B extends ArgBuilder<infer C extends ArgConfig> ? ResolvedArgValue<C> : never;
62
61
  /** Extract resolved value types from a record of builders. */
63
- 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]>; };
64
63
  /** All arg kind discriminators as a runtime array. */
65
- declare const ARG_KINDS: readonly ['string', 'number', 'enum', 'custom'];
64
+ declare const ARG_KINDS: readonly ["string", "number", "enum", "custom"];
66
65
  /** Discriminator for the kind of value an arg accepts. */
67
66
  type ArgKind = (typeof ARG_KINDS)[number];
68
67
  /** Custom parse function for `arg.custom()`. */