@kjanat/dreamcli 2.5.0 → 3.0.0-rc.2

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 (160) hide show
  1. package/CHANGELOG.md +153 -1
  2. package/README.md +9 -2
  3. package/dist/core/cli/dispatch.mjs +214 -1
  4. package/dist/core/cli/help-links.mjs +41 -1
  5. package/dist/core/cli/index.d.mts +109 -16
  6. package/dist/core/cli/index.mjs +901 -1
  7. package/dist/core/cli/planner.d.mts +27 -5
  8. package/dist/core/cli/planner.mjs +300 -1
  9. package/dist/core/cli/plugin.mjs +41 -1
  10. package/dist/core/cli/propagate.mjs +57 -1
  11. package/dist/core/cli/root-help.d.mts +16 -2
  12. package/dist/core/cli/root-help.mjs +208 -6
  13. package/dist/core/cli/root-surface.d.mts +18 -3
  14. package/dist/core/cli/root-surface.mjs +27 -1
  15. package/dist/core/cli/runtime-preflight.d.mts +16 -1
  16. package/dist/core/cli/runtime-preflight.mjs +168 -1
  17. package/dist/core/completion/index.d.mts +32 -1
  18. package/dist/core/completion/index.mjs +90 -1
  19. package/dist/core/completion/shells/bash.mjs +304 -3
  20. package/dist/core/completion/shells/fish.mjs +159 -2
  21. package/dist/core/completion/shells/powershell.mjs +353 -2
  22. package/dist/core/completion/shells/shared.d.mts +10 -0
  23. package/dist/core/completion/shells/shared.mjs +154 -1
  24. package/dist/core/completion/shells/zsh.mjs +244 -2
  25. package/dist/core/config/index.mjs +246 -1
  26. package/dist/core/config/package-json.mjs +385 -3
  27. package/dist/core/errors/index.mjs +87 -1
  28. package/dist/core/execution/index.mjs +189 -1
  29. package/dist/core/help/ansi.mjs +122 -2
  30. package/dist/core/help/index.d.mts +45 -1
  31. package/dist/core/help/index.mjs +329 -7
  32. package/dist/core/json-schema/index.mjs +487 -9
  33. package/dist/core/json-schema/meta-descriptions.generated.d.mts +38 -38
  34. package/dist/core/json-schema/meta-descriptions.generated.mjs +93 -28
  35. package/dist/core/output/activity.mjs +452 -1
  36. package/dist/core/output/bind.mjs +56 -1
  37. package/dist/core/output/contracts.mjs +57 -1
  38. package/dist/core/output/display-value.mjs +32 -1
  39. package/dist/core/output/index.d.mts +21 -0
  40. package/dist/core/output/index.mjs +442 -2
  41. package/dist/core/output/renderers.mjs +46 -1
  42. package/dist/core/output/writer.mjs +12 -1
  43. package/dist/core/parse/index.d.mts +15 -1
  44. package/dist/core/parse/index.mjs +555 -1
  45. package/dist/core/prompt/index.d.mts +11 -4
  46. package/dist/core/prompt/index.mjs +348 -6
  47. package/dist/core/resolve/args.mjs +105 -1
  48. package/dist/core/resolve/coerce.mjs +279 -1
  49. package/dist/core/resolve/config.mjs +19 -1
  50. package/dist/core/resolve/errors.mjs +140 -2
  51. package/dist/core/resolve/flags.mjs +196 -1
  52. package/dist/core/resolve/index.mjs +85 -1
  53. package/dist/core/resolve/property.d.mts +2 -1
  54. package/dist/core/resolve/property.mjs +45 -1
  55. package/dist/core/schema/arg.d.mts +90 -10
  56. package/dist/core/schema/arg.mjs +463 -1
  57. package/dist/core/schema/command.d.mts +21 -1
  58. package/dist/core/schema/command.mjs +712 -1
  59. package/dist/core/schema/flag.d.mts +92 -2
  60. package/dist/core/schema/flag.mjs +453 -1
  61. package/dist/core/schema/index.d.mts +2 -1
  62. package/dist/core/schema/middleware.mjs +41 -1
  63. package/dist/core/schema/number-constraints.d.mts +96 -0
  64. package/dist/core/schema/number-constraints.mjs +60 -0
  65. package/dist/core/schema/prompt.d.mts +15 -0
  66. package/dist/core/schema/run.d.mts +4 -4
  67. package/dist/core/schema-dsl/runtime.mjs +271 -2
  68. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  69. package/dist/core/testkit/index.d.mts +9 -5
  70. package/dist/core/testkit/index.mjs +83 -1
  71. package/dist/index.d.mts +3 -1
  72. package/dist/index.mjs +22 -1
  73. package/dist/runtime/adapter.mjs +82 -1
  74. package/dist/runtime/auto.mjs +46 -1
  75. package/dist/runtime/bun.mjs +28 -1
  76. package/dist/runtime/deno.mjs +217 -2
  77. package/dist/runtime/detect.mjs +45 -1
  78. package/dist/runtime/node.mjs +169 -2
  79. package/dist/runtime/paths.mjs +48 -1
  80. package/dist/runtime.mjs +7 -1
  81. package/dist/strings.mjs +22 -1
  82. package/dist/testkit.mjs +5 -1
  83. package/dist/version.mjs +7 -1
  84. package/examples/basic.ts +5 -1
  85. package/examples/gh/package.json +2 -7
  86. package/examples/pwsh-demo/package.json +1 -7
  87. package/examples/pwsh-demo/src/main.test.ts +1 -4
  88. package/examples/pwsh-demo/src/main.ts +14 -4
  89. package/examples/transport-launcher.ts +85 -0
  90. package/package.json +23 -41
  91. package/dist/runtime/support.d.mts +0 -42
  92. package/dist/runtime/support.mjs +0 -1
  93. package/src/core/cli/dispatch.ts +0 -349
  94. package/src/core/cli/help-links.ts +0 -82
  95. package/src/core/cli/index.ts +0 -1413
  96. package/src/core/cli/planner.ts +0 -487
  97. package/src/core/cli/plugin.ts +0 -117
  98. package/src/core/cli/propagate.ts +0 -97
  99. package/src/core/cli/root-help.ts +0 -252
  100. package/src/core/cli/root-surface.ts +0 -74
  101. package/src/core/cli/runtime-preflight.ts +0 -438
  102. package/src/core/completion/index.ts +0 -88
  103. package/src/core/completion/shells/bash.ts +0 -459
  104. package/src/core/completion/shells/fish.ts +0 -259
  105. package/src/core/completion/shells/powershell.ts +0 -439
  106. package/src/core/completion/shells/shared.ts +0 -283
  107. package/src/core/completion/shells/zsh.ts +0 -381
  108. package/src/core/config/index.ts +0 -417
  109. package/src/core/config/package-json.ts +0 -560
  110. package/src/core/errors/index.ts +0 -193
  111. package/src/core/execution/index.ts +0 -268
  112. package/src/core/help/ansi.ts +0 -144
  113. package/src/core/help/index.ts +0 -516
  114. package/src/core/json-schema/index.ts +0 -891
  115. package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
  116. package/src/core/output/activity.ts +0 -575
  117. package/src/core/output/bind.ts +0 -59
  118. package/src/core/output/contracts.ts +0 -194
  119. package/src/core/output/display-value.ts +0 -48
  120. package/src/core/output/index.ts +0 -704
  121. package/src/core/output/renderers.ts +0 -125
  122. package/src/core/output/writer.ts +0 -46
  123. package/src/core/parse/index.ts +0 -681
  124. package/src/core/prompt/index.ts +0 -583
  125. package/src/core/resolve/args.ts +0 -144
  126. package/src/core/resolve/coerce.ts +0 -432
  127. package/src/core/resolve/config.ts +0 -26
  128. package/src/core/resolve/contracts.ts +0 -135
  129. package/src/core/resolve/errors.ts +0 -227
  130. package/src/core/resolve/flags.ts +0 -255
  131. package/src/core/resolve/index.ts +0 -108
  132. package/src/core/resolve/property.ts +0 -99
  133. package/src/core/schema/activity.ts +0 -240
  134. package/src/core/schema/arg.ts +0 -719
  135. package/src/core/schema/command.ts +0 -1498
  136. package/src/core/schema/flag.ts +0 -801
  137. package/src/core/schema/index.ts +0 -91
  138. package/src/core/schema/middleware.ts +0 -171
  139. package/src/core/schema/prompt.ts +0 -156
  140. package/src/core/schema/run.ts +0 -198
  141. package/src/core/schema-dsl/index.ts +0 -109
  142. package/src/core/schema-dsl/parse.ts +0 -262
  143. package/src/core/schema-dsl/runtime.ts +0 -609
  144. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  145. package/src/core/testkit/index.ts +0 -123
  146. package/src/index.ts +0 -179
  147. package/src/runtime/adapter.ts +0 -303
  148. package/src/runtime/auto.ts +0 -110
  149. package/src/runtime/bun.ts +0 -55
  150. package/src/runtime/deno.ts +0 -369
  151. package/src/runtime/detect.ts +0 -105
  152. package/src/runtime/index.ts +0 -21
  153. package/src/runtime/node-builtins.d.ts +0 -27
  154. package/src/runtime/node.ts +0 -300
  155. package/src/runtime/paths.ts +0 -64
  156. package/src/runtime/support.ts +0 -135
  157. package/src/runtime.ts +0 -31
  158. package/src/strings.ts +0 -34
  159. package/src/testkit.ts +0 -25
  160. package/src/version.ts +0 -20
@@ -1 +1,279 @@
1
- import{ValidationError as e}from"../errors/index.mjs";import{toSharedArgPropertySchema as t,toSharedFlagPropertySchema as n}from"./property.mjs";function r(e){switch(e.kind){case`env`:return`from env ${e.envVar}`;case`config`:return`from config ${e.configPath}`;case`prompt`:return`from prompt`}}function i(e){switch(e.kind){case`env`:return{envVar:e.envVar};case`config`:return{configPath:e.configPath};case`prompt`:return{source:`prompt`}}}function a(t,n,a,o,s,c,l,u){return{ok:!1,error:new e(`${c} ${r(n)} for flag --${t}`,{code:a,details:{flag:t,...i(n),value:s,expected:o,...u},suggest:l})}}function o(e,t,r,i){let c=n(i);if(c!==void 0)return s(e,t,r,c);switch(i.kind){case`boolean`:if(typeof r==`boolean`)return{ok:!0,value:r};if(typeof r==`string`){let e=r.toLowerCase();if(e===`true`||e===`1`||e===`yes`||t.kind===`prompt`&&e===`y`)return{ok:!0,value:!0};if(e===`false`||e===`0`||e===`no`||e===``||t.kind===`prompt`&&e===`n`)return{ok:!0,value:!1}}return a(e,t,`TYPE_MISMATCH`,`boolean`,r,typeof r==`string`?`Invalid boolean value '${r}'`:`Invalid boolean value`,t.kind===`env`?`Set ${t.envVar} to true/false, 1/0, or yes/no`:t.kind===`config`?`Set ${t.configPath} to true or false in your config`:`Answer yes or no for --${e}`);case`array`:if(Array.isArray(r)){if(i.elementSchema){let n=[];for(let a of r){let r=o(e,t,a,i.elementSchema);if(!r.ok)return r;n.push(r.value)}return{ok:!0,value:n}}return{ok:!0,value:r}}if(typeof r==`string`){if(r===``)return{ok:!0,value:[]};let n=r.split(`,`);if(i.elementSchema){let r=[];for(let a of n){let n=o(e,t,t.kind===`prompt`?a.trim():a,i.elementSchema);if(!n.ok)return n;r.push(n.value)}return{ok:!0,value:r}}return{ok:!0,value:t.kind===`prompt`?n.map(e=>e.trim()):n}}return a(e,t,`TYPE_MISMATCH`,`array`,r,`Invalid array value`,t.kind===`env`?`Set ${t.envVar} to comma-separated values`:t.kind===`config`?`Set ${t.configPath} to an array in your config`:`Provide valid values for --${e}`)}throw Error(`Unreachable flag coercion kind: ${i.kind}`)}function s(t,n,o,s){switch(s.kind){case`string`:return typeof o==`string`?{ok:!0,value:o}:n.kind===`prompt`||n.kind===`config`&&(typeof o==`number`||typeof o==`boolean`)?{ok:!0,value:String(o)}:a(t,n,`TYPE_MISMATCH`,`string`,o,`Invalid string value`,n.kind===`config`?`Set ${n.configPath} to a string in your config`:`Enter a valid string for --${t}`);case`number`:if(typeof o==`number`)return Number.isNaN(o)?a(t,n,`TYPE_MISMATCH`,`number`,o,`Invalid number value NaN`,n.kind===`env`?`Set ${n.envVar} to a valid number`:n.kind===`config`?`Set ${n.configPath} to a valid number in your config`:`Enter a valid number for --${t}`):{ok:!0,value:o};if(typeof o==`string`){let e=Number(o);if(!Number.isNaN(e))return{ok:!0,value:e}}return a(t,n,`TYPE_MISMATCH`,`number`,o,typeof o==`string`?`Invalid number value '${o}'`:`Invalid number value`,n.kind===`env`?`Set ${n.envVar} to a valid number`:n.kind===`config`?`Set ${n.configPath} to a valid number in your config`:`Enter a valid number for --${t}`);case`enum`:{let a=s.enumValues??[];return typeof o==`string`&&a.includes(o)?{ok:!0,value:o}:{ok:!1,error:new e(`Invalid value '${String(o)}' ${r(n)} for flag --${t}. Allowed: ${a.join(`, `)}`,{code:`INVALID_ENUM`,details:{flag:t,...i(n),value:o,allowed:a},suggest:n.kind===`env`?`Set ${n.envVar} to one of: ${a.join(`, `)}`:n.kind===`config`?`Set ${n.configPath} to one of: ${a.join(`, `)}`:`Select one of: ${a.join(`, `)}`})}}case`custom`:if(s.parseFn===void 0)return{ok:!0,value:o};try{return{ok:!0,value:s.parseFn(o)}}catch(r){let a=r instanceof Error?r.message:String(r);return{ok:!1,error:new e(`Failed to parse ${n.kind===`env`?`env ${n.envVar}`:n.kind===`config`?`config ${n.configPath}`:`prompt value`} for flag --${t}: ${a}`,{code:`TYPE_MISMATCH`,details:{flag:t,...i(n),value:o,expected:`custom`},suggest:n.kind===`env`?`Set ${n.envVar} to a valid value for --${t}`:n.kind===`config`?`Set ${n.configPath} to a valid value for --${t} in your config`:`Enter a valid value for --${t}`})}}}}function c(e){return e.kind===`env`?`from env ${e.envVar}`:`from stdin`}function l(e){return e.kind===`env`?{envVar:e.envVar}:{source:`stdin`}}function u(e,t,n){return t.kind===`env`?n===`number`?`Set ${t.envVar} to a valid number`:`Set ${t.envVar} to a valid value for <${e}>`:n===`number`?`Pipe a valid number to stdin for <${e}>`:`Pipe a valid value to stdin for <${e}>`}function d(e){return e.kind===`env`?{kind:`env`,envVar:e.envVar}:{kind:`prompt`}}function f(e,t,n,r){switch(n.kind){case`number`:return`Invalid number value '<redacted>' ${c(t)} for argument <${e}>`;case`enum`:{let n=Array.isArray(r.details?.allowed)?r.details.allowed.filter(e=>typeof e==`string`):[];return`Invalid value '<redacted>' ${c(t)} for argument <${e}>. Allowed: ${n.join(`, `)}`}case`custom`:{let n=/: ([^:]+)$/.exec(r.message)?.[1];return n===void 0?`Invalid value '<redacted>' ${c(t)} for argument <${e}>`:`Invalid value '<redacted>' ${c(t)} for argument <${e}>: ${n}`}case`string`:return`Invalid value '<redacted>' ${c(t)} for argument <${e}>`;default:return n.kind}}function p(e,t,n,r){return{arg:e,...l(t),...n.kind===`number`||n.kind===`custom`?{expected:n.kind}:{},...n.kind===`enum`&&Array.isArray(r.details?.allowed)?{allowed:r.details.allowed.filter(e=>typeof e==`string`)}:{}}}function m(e,t,n,r){if(n.kind===`number`||n.kind===`custom`)return u(e,t,n.kind);if(n.kind===`enum`){let e=(Array.isArray(r.details?.allowed)?r.details.allowed.filter(e=>typeof e==`string`):[]).join(`, `);return t.kind===`env`?`Set ${t.envVar} to one of: ${e}`:`Provide one of: ${e}`}}function h(n,r,i,a){let o=s(n,d(r),i,t(a));if(o.ok)return o;let c=m(n,r,a,o.error),l=c===void 0?{code:o.error.code,details:p(n,r,a,o.error)}:{code:o.error.code,details:p(n,r,a,o.error),suggest:c};return{ok:!1,error:new e(f(n,r,a,o.error),l)}}export{h as coerceArgStringValue,o as coerceValue};
1
+ import { describeNumberConstraintViolation, validateNumberConstraints } from "../schema/number-constraints.mjs";
2
+ import { ValidationError } from "../errors/index.mjs";
3
+ import { toSharedArgPropertySchema, toSharedFlagPropertySchema } from "./property.mjs";
4
+ //#region src/core/resolve/coerce.ts
5
+ function sourceLabel(source) {
6
+ switch (source.kind) {
7
+ case "env": return `from env ${source.envVar}`;
8
+ case "config": return `from config ${source.configPath}`;
9
+ case "prompt": return "from prompt";
10
+ }
11
+ }
12
+ function sourceDetails(source) {
13
+ switch (source.kind) {
14
+ case "env": return { envVar: source.envVar };
15
+ case "config": return { configPath: source.configPath };
16
+ case "prompt": return { source: "prompt" };
17
+ }
18
+ }
19
+ function coercionError(flagName, source, code, expected, raw, messageSuffix, suggest, extraDetails) {
20
+ return {
21
+ ok: false,
22
+ error: new ValidationError(`${messageSuffix} ${sourceLabel(source)} for flag --${flagName}`, {
23
+ code,
24
+ details: {
25
+ flag: flagName,
26
+ ...sourceDetails(source),
27
+ value: raw,
28
+ expected,
29
+ ...extraDetails
30
+ },
31
+ suggest
32
+ })
33
+ };
34
+ }
35
+ /**
36
+ * Apply numeric constraints to an already-parsed number. Shares the single
37
+ * {@link validateNumberConstraints} check used by the parse path, so the two
38
+ * boundaries cannot drift. On violation, returns a `CONSTRAINT_VIOLATED`
39
+ * failure; the human-readable reason is also surfaced in `details.constraint`
40
+ * (the violation kind) and the message suffix.
41
+ */
42
+ function finalizeNumber(flagName, source, raw, value, constraints) {
43
+ const violation = validateNumberConstraints(value, constraints);
44
+ if (violation === void 0) return {
45
+ ok: true,
46
+ value
47
+ };
48
+ const reason = describeNumberConstraintViolation(violation);
49
+ return {
50
+ ok: false,
51
+ error: new ValidationError(`Invalid number value '${String(raw)}' ${sourceLabel(source)} for flag --${flagName}: ${reason}`, {
52
+ code: "CONSTRAINT_VIOLATED",
53
+ details: {
54
+ flag: flagName,
55
+ ...sourceDetails(source),
56
+ value: raw,
57
+ expected: "number",
58
+ constraint: violation.kind,
59
+ ..."bound" in violation ? { bound: violation.bound } : {}
60
+ },
61
+ suggest: source.kind === "env" ? `Set ${source.envVar} to a valid number` : source.kind === "config" ? `Set ${source.configPath} to a valid number in your config` : `Enter a valid number for --${flagName}`
62
+ })
63
+ };
64
+ }
65
+ /** Coerce a raw value from env/config/prompt into the type declared by a flag schema. */
66
+ function coerceValue(flagName, source, raw, schema) {
67
+ const sharedSchema = toSharedFlagPropertySchema(schema);
68
+ if (sharedSchema !== void 0) return coerceSharedPropertyValue(flagName, source, raw, sharedSchema);
69
+ switch (schema.kind) {
70
+ case "boolean":
71
+ if (typeof raw === "boolean") return {
72
+ ok: true,
73
+ value: raw
74
+ };
75
+ if (typeof raw === "string") {
76
+ const lower = raw.toLowerCase();
77
+ if (lower === "true" || lower === "1" || lower === "yes" || source.kind === "prompt" && lower === "y") return {
78
+ ok: true,
79
+ value: true
80
+ };
81
+ if (lower === "false" || lower === "0" || lower === "no" || lower === "" || source.kind === "prompt" && lower === "n") return {
82
+ ok: true,
83
+ value: false
84
+ };
85
+ }
86
+ return coercionError(flagName, source, "TYPE_MISMATCH", "boolean", raw, typeof raw === "string" ? `Invalid boolean value '${raw}'` : "Invalid boolean value", source.kind === "env" ? `Set ${source.envVar} to true/false, 1/0, or yes/no` : source.kind === "config" ? `Set ${source.configPath} to true or false in your config` : `Answer yes or no for --${flagName}`);
87
+ case "array":
88
+ if (Array.isArray(raw)) {
89
+ if (schema.elementSchema) {
90
+ const coerced = [];
91
+ for (const element of raw) {
92
+ const result = coerceValue(flagName, source, element, schema.elementSchema);
93
+ if (!result.ok) return result;
94
+ coerced.push(result.value);
95
+ }
96
+ return {
97
+ ok: true,
98
+ value: coerced
99
+ };
100
+ }
101
+ return {
102
+ ok: true,
103
+ value: raw
104
+ };
105
+ }
106
+ if (typeof raw === "string") {
107
+ if (raw === "") return {
108
+ ok: true,
109
+ value: []
110
+ };
111
+ const parts = raw.split(",");
112
+ if (schema.elementSchema) {
113
+ const coerced = [];
114
+ for (const part of parts) {
115
+ const result = coerceValue(flagName, source, source.kind === "prompt" ? part.trim() : part, schema.elementSchema);
116
+ if (!result.ok) return result;
117
+ coerced.push(result.value);
118
+ }
119
+ return {
120
+ ok: true,
121
+ value: coerced
122
+ };
123
+ }
124
+ return {
125
+ ok: true,
126
+ value: source.kind === "prompt" ? parts.map((part) => part.trim()) : parts
127
+ };
128
+ }
129
+ return coercionError(flagName, source, "TYPE_MISMATCH", "array", raw, "Invalid array value", source.kind === "env" ? `Set ${source.envVar} to comma-separated values` : source.kind === "config" ? `Set ${source.configPath} to an array in your config` : `Provide valid values for --${flagName}`);
130
+ }
131
+ throw new Error(`Unreachable flag coercion kind: ${schema.kind}`);
132
+ }
133
+ function coerceSharedPropertyValue(flagName, source, raw, schema) {
134
+ switch (schema.kind) {
135
+ case "string":
136
+ if (typeof raw === "string") return {
137
+ ok: true,
138
+ value: raw
139
+ };
140
+ if (source.kind === "prompt") return {
141
+ ok: true,
142
+ value: String(raw)
143
+ };
144
+ if (source.kind === "config" && (typeof raw === "number" || typeof raw === "boolean")) return {
145
+ ok: true,
146
+ value: String(raw)
147
+ };
148
+ return coercionError(flagName, source, "TYPE_MISMATCH", "string", raw, "Invalid string value", source.kind === "config" ? `Set ${source.configPath} to a string in your config` : `Enter a valid string for --${flagName}`);
149
+ case "number":
150
+ if (typeof raw === "number") {
151
+ if (Number.isNaN(raw)) return coercionError(flagName, source, "TYPE_MISMATCH", "number", raw, "Invalid number value NaN", source.kind === "env" ? `Set ${source.envVar} to a valid number` : source.kind === "config" ? `Set ${source.configPath} to a valid number in your config` : `Enter a valid number for --${flagName}`);
152
+ return finalizeNumber(flagName, source, raw, raw, schema.numberConstraints);
153
+ }
154
+ if (typeof raw === "string") {
155
+ const value = Number(raw);
156
+ if (!Number.isNaN(value)) return finalizeNumber(flagName, source, raw, value, schema.numberConstraints);
157
+ }
158
+ return coercionError(flagName, source, "TYPE_MISMATCH", "number", raw, typeof raw === "string" ? `Invalid number value '${raw}'` : "Invalid number value", source.kind === "env" ? `Set ${source.envVar} to a valid number` : source.kind === "config" ? `Set ${source.configPath} to a valid number in your config` : `Enter a valid number for --${flagName}`);
159
+ case "enum": {
160
+ const allowed = schema.enumValues ?? [];
161
+ if (typeof raw === "string" && allowed.includes(raw)) return {
162
+ ok: true,
163
+ value: raw
164
+ };
165
+ return {
166
+ ok: false,
167
+ error: new ValidationError(`Invalid value '${String(raw)}' ${sourceLabel(source)} for flag --${flagName}. Allowed: ${allowed.join(", ")}`, {
168
+ code: "INVALID_ENUM",
169
+ details: {
170
+ flag: flagName,
171
+ ...sourceDetails(source),
172
+ value: raw,
173
+ allowed
174
+ },
175
+ suggest: source.kind === "env" ? `Set ${source.envVar} to one of: ${allowed.join(", ")}` : source.kind === "config" ? `Set ${source.configPath} to one of: ${allowed.join(", ")}` : `Select one of: ${allowed.join(", ")}`
176
+ })
177
+ };
178
+ }
179
+ case "custom":
180
+ if (schema.parseFn === void 0) return {
181
+ ok: true,
182
+ value: raw
183
+ };
184
+ try {
185
+ return {
186
+ ok: true,
187
+ value: schema.parseFn(raw)
188
+ };
189
+ } catch (error) {
190
+ const message = error instanceof Error ? error.message : String(error);
191
+ return {
192
+ ok: false,
193
+ error: new ValidationError(`Failed to parse ${source.kind === "env" ? `env ${source.envVar}` : source.kind === "config" ? `config ${source.configPath}` : "prompt value"} for flag --${flagName}: ${message}`, {
194
+ code: "TYPE_MISMATCH",
195
+ details: {
196
+ flag: flagName,
197
+ ...sourceDetails(source),
198
+ value: raw,
199
+ expected: "custom"
200
+ },
201
+ suggest: source.kind === "env" ? `Set ${source.envVar} to a valid value for --${flagName}` : source.kind === "config" ? `Set ${source.configPath} to a valid value for --${flagName} in your config` : `Enter a valid value for --${flagName}`
202
+ })
203
+ };
204
+ }
205
+ }
206
+ }
207
+ function argSourceLabel(source) {
208
+ return source.kind === "env" ? `from env ${source.envVar}` : "from stdin";
209
+ }
210
+ function argSourceDetails(source) {
211
+ return source.kind === "env" ? { envVar: source.envVar } : { source: "stdin" };
212
+ }
213
+ function buildArgCoercionSuggest(argName, source, expected) {
214
+ if (source.kind === "env") return expected === "number" ? `Set ${source.envVar} to a valid number` : `Set ${source.envVar} to a valid value for <${argName}>`;
215
+ return expected === "number" ? `Pipe a valid number to stdin for <${argName}>` : `Pipe a valid value to stdin for <${argName}>`;
216
+ }
217
+ function argSourceToCoerceSource(source) {
218
+ return source.kind === "env" ? {
219
+ kind: "env",
220
+ envVar: source.envVar
221
+ } : { kind: "prompt" };
222
+ }
223
+ function redactArgCoercionMessage(argName, source, schema, error) {
224
+ switch (schema.kind) {
225
+ case "number": {
226
+ const base = `Invalid number value '<redacted>' ${argSourceLabel(source)} for argument <${argName}>`;
227
+ if (error.code !== "CONSTRAINT_VIOLATED") return base;
228
+ const suffix = /: ([^:]+)$/.exec(error.message)?.[1];
229
+ return suffix !== void 0 ? `${base}: ${suffix}` : base;
230
+ }
231
+ case "enum": {
232
+ const allowed = Array.isArray(error.details?.allowed) ? error.details.allowed.filter((value) => typeof value === "string") : [];
233
+ return `Invalid value '<redacted>' ${argSourceLabel(source)} for argument <${argName}>. Allowed: ${allowed.join(", ")}`;
234
+ }
235
+ case "custom": {
236
+ const suffix = /: ([^:]+)$/.exec(error.message)?.[1];
237
+ return suffix !== void 0 ? `Invalid value '<redacted>' ${argSourceLabel(source)} for argument <${argName}>: ${suffix}` : `Invalid value '<redacted>' ${argSourceLabel(source)} for argument <${argName}>`;
238
+ }
239
+ case "string": return `Invalid value '<redacted>' ${argSourceLabel(source)} for argument <${argName}>`;
240
+ default: return schema.kind;
241
+ }
242
+ }
243
+ function redactArgCoercionDetails(argName, source, schema, error) {
244
+ return {
245
+ arg: argName,
246
+ ...argSourceDetails(source),
247
+ ...schema.kind === "number" || schema.kind === "custom" ? { expected: schema.kind } : {},
248
+ ...schema.kind === "number" && typeof error.details?.constraint === "string" ? { constraint: error.details.constraint } : {},
249
+ ...schema.kind === "number" && typeof error.details?.bound === "number" ? { bound: error.details.bound } : {},
250
+ ...schema.kind === "enum" && Array.isArray(error.details?.allowed) ? { allowed: error.details.allowed.filter((value) => typeof value === "string") } : {}
251
+ };
252
+ }
253
+ function redactArgCoercionSuggest(argName, source, schema, error) {
254
+ if (schema.kind === "number" || schema.kind === "custom") return buildArgCoercionSuggest(argName, source, schema.kind);
255
+ if (schema.kind === "enum") {
256
+ const allowedList = (Array.isArray(error.details?.allowed) ? error.details.allowed.filter((value) => typeof value === "string") : []).join(", ");
257
+ return source.kind === "env" ? `Set ${source.envVar} to one of: ${allowedList}` : `Provide one of: ${allowedList}`;
258
+ }
259
+ }
260
+ /** Coerce a string value from stdin/env into the type declared by an arg schema, redacting raw values in error diagnostics. */
261
+ function coerceArgStringValue(argName, source, raw, schema) {
262
+ const coerced = coerceSharedPropertyValue(argName, argSourceToCoerceSource(source), raw, toSharedArgPropertySchema(schema));
263
+ if (coerced.ok) return coerced;
264
+ const suggest = redactArgCoercionSuggest(argName, source, schema, coerced.error);
265
+ const options = suggest === void 0 ? {
266
+ code: coerced.error.code,
267
+ details: redactArgCoercionDetails(argName, source, schema, coerced.error)
268
+ } : {
269
+ code: coerced.error.code,
270
+ details: redactArgCoercionDetails(argName, source, schema, coerced.error),
271
+ suggest
272
+ };
273
+ return {
274
+ ok: false,
275
+ error: new ValidationError(redactArgCoercionMessage(argName, source, schema, coerced.error), options)
276
+ };
277
+ }
278
+ //#endregion
279
+ export { coerceArgStringValue, coerceValue };
@@ -1 +1,19 @@
1
- function e(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r||!Object.hasOwn(r,e))return;r=r[e]}return r}export{e as resolveConfigPath};
1
+ //#region src/core/resolve/config.ts
2
+ /**
3
+ * Internal resolver config helpers.
4
+ *
5
+ * @module dreamcli/core/resolve/config
6
+ * @internal
7
+ */
8
+ function resolveConfigPath(config, path) {
9
+ const segments = path.split(".");
10
+ let current = config;
11
+ for (const segment of segments) {
12
+ if (current === null || current === void 0 || typeof current !== "object") return;
13
+ if (!Object.hasOwn(current, segment)) return;
14
+ current = current[segment];
15
+ }
16
+ return current;
17
+ }
18
+ //#endregion
19
+ export { resolveConfigPath };
@@ -1,2 +1,140 @@
1
- import{ValidationError as e}from"../errors/index.mjs";function t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function n(e,t){let n=Reflect.get(e,t);return typeof n==`string`?n:void 0}function r(e,t){return Object.hasOwn(e,t)}function i(e){let t=n(e,`source`);if(t===`stdin`)return{kind:`stdin`,label:`stdin`};if(t===`prompt`)return{kind:`prompt`,label:`prompt`};if(r(e,`value`)){let t=n(e,`envVar`);if(t!==void 0)return{kind:`env`,label:`env ${t}`};let r=n(e,`configPath`);if(r!==void 0)return{kind:`config`,label:`config ${r}`}}}function a(e){let r=e.details;if(!t(r))return{code:e.code,inputKind:`input`,label:`input`,message:e.message};let a=n(r,`flag`);if(a!==void 0){let t=i(r);return{code:e.code,inputKind:`flag`,name:a,label:`flag --${a}`,message:e.message,...t===void 0?{}:{sourceKind:t.kind,sourceLabel:t.label}}}let o=n(r,`arg`);if(o!==void 0){let t=i(r);return{code:e.code,inputKind:`arg`,name:o,label:`argument <${o}>`,message:e.message,...t===void 0?{}:{sourceKind:t.kind,sourceLabel:t.label}}}return{code:e.code,inputKind:`input`,label:`input`,message:e.message}}function o(e){let t=e.filter(e=>e.inputKind===`flag`).length,n=e.filter(e=>e.inputKind===`arg`).length,r=e.length-t-n,i=[];return t>0&&i.push(`${t} flag${t===1?``:`s`}`),n>0&&i.push(`${n} arg${n===1?``:`s`}`),r>0&&i.push(`${r} input${r===1?``:`s`}`),i.length===0?`Multiple validation errors (${e.length})`:`Multiple validation errors (${i.join(`, `)})`}function s(e){let t=e.sourceLabel===void 0?``:` [${e.sourceLabel}]`;return`${e.label}${t}: ${e.message}`}function c(e){return e.length>0}function l(e){return!(typeof e!=`object`||!e||!(`code`in e)||!(`message`in e)||!(`exitCode`in e)||typeof e.code!=`string`||typeof e.message!=`string`||typeof e.exitCode!=`number`||`suggest`in e&&e.suggest!==void 0&&typeof e.suggest!=`string`||`details`in e&&e.details!==void 0&&(e.details===null||typeof e.details!=`object`))}function u(t){let n=t.details?.errors;if(!Array.isArray(n))return[t];let r=[];for(let i of n){if(!l(i))return[t];r.push(new e(i.message,{code:i.code,exitCode:i.exitCode,...i.suggest===void 0?{}:{suggest:i.suggest},...i.details===void 0?{}:{details:i.details}}))}return r}function d(t){if(t.length===1)throw t[0];let n=t.map(a),r=n.map(s);throw new e(`${o(n)}:\n - ${r.join(`
2
- - `)}`,{code:t[0].code,details:{errors:t.map(e=>e.toJSON()),count:t.length,issues:n},suggest:`Fix the listed validation errors and retry`})}export{u as collectValidationErrors,c as isNonEmpty,d as throwAggregatedErrors};
1
+ import { ValidationError } from "../errors/index.mjs";
2
+ //#region src/core/resolve/errors.ts
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function readStringProperty(record, key) {
7
+ const value = Reflect.get(record, key);
8
+ return typeof value === "string" ? value : void 0;
9
+ }
10
+ function hasValueProperty(record, key) {
11
+ return Object.hasOwn(record, key);
12
+ }
13
+ function describeIssueSource(details) {
14
+ const explicitSource = readStringProperty(details, "source");
15
+ if (explicitSource === "stdin") return {
16
+ kind: "stdin",
17
+ label: "stdin"
18
+ };
19
+ if (explicitSource === "prompt") return {
20
+ kind: "prompt",
21
+ label: "prompt"
22
+ };
23
+ if (hasValueProperty(details, "value")) {
24
+ const envVar = readStringProperty(details, "envVar");
25
+ if (envVar !== void 0) return {
26
+ kind: "env",
27
+ label: `env ${envVar}`
28
+ };
29
+ const configPath = readStringProperty(details, "configPath");
30
+ if (configPath !== void 0) return {
31
+ kind: "config",
32
+ label: `config ${configPath}`
33
+ };
34
+ }
35
+ }
36
+ function summarizeValidationError(error) {
37
+ const details = error.details;
38
+ if (!isRecord(details)) return {
39
+ code: error.code,
40
+ inputKind: "input",
41
+ label: "input",
42
+ message: error.message
43
+ };
44
+ const flag = readStringProperty(details, "flag");
45
+ if (flag !== void 0) {
46
+ const source = describeIssueSource(details);
47
+ return {
48
+ code: error.code,
49
+ inputKind: "flag",
50
+ name: flag,
51
+ label: `flag --${flag}`,
52
+ message: error.message,
53
+ ...source !== void 0 ? {
54
+ sourceKind: source.kind,
55
+ sourceLabel: source.label
56
+ } : {}
57
+ };
58
+ }
59
+ const arg = readStringProperty(details, "arg");
60
+ if (arg !== void 0) {
61
+ const source = describeIssueSource(details);
62
+ return {
63
+ code: error.code,
64
+ inputKind: "arg",
65
+ name: arg,
66
+ label: `argument <${arg}>`,
67
+ message: error.message,
68
+ ...source !== void 0 ? {
69
+ sourceKind: source.kind,
70
+ sourceLabel: source.label
71
+ } : {}
72
+ };
73
+ }
74
+ return {
75
+ code: error.code,
76
+ inputKind: "input",
77
+ label: "input",
78
+ message: error.message
79
+ };
80
+ }
81
+ function formatAggregateHeadline(issues) {
82
+ const flagCount = issues.filter((issue) => issue.inputKind === "flag").length;
83
+ const argCount = issues.filter((issue) => issue.inputKind === "arg").length;
84
+ const otherCount = issues.length - flagCount - argCount;
85
+ const counts = [];
86
+ if (flagCount > 0) counts.push(`${flagCount} flag${flagCount === 1 ? "" : "s"}`);
87
+ if (argCount > 0) counts.push(`${argCount} arg${argCount === 1 ? "" : "s"}`);
88
+ if (otherCount > 0) counts.push(`${otherCount} input${otherCount === 1 ? "" : "s"}`);
89
+ return counts.length === 0 ? `Multiple validation errors (${issues.length})` : `Multiple validation errors (${counts.join(", ")})`;
90
+ }
91
+ function formatAggregateLine(issue) {
92
+ const source = issue.sourceLabel !== void 0 ? ` [${issue.sourceLabel}]` : "";
93
+ return `${issue.label}${source}: ${issue.message}`;
94
+ }
95
+ /** Type-narrowing guard that asserts a readonly array has at least one element. */
96
+ function isNonEmpty(arr) {
97
+ return arr.length > 0;
98
+ }
99
+ function isValidationErrorJson(value) {
100
+ if (value === null || typeof value !== "object") return false;
101
+ if (!("code" in value) || !("message" in value) || !("exitCode" in value)) return false;
102
+ if (typeof value.code !== "string" || typeof value.message !== "string") return false;
103
+ if (typeof value.exitCode !== "number") return false;
104
+ if ("suggest" in value && value.suggest !== void 0 && typeof value.suggest !== "string") return false;
105
+ if ("details" in value && value.details !== void 0 && (value.details === null || typeof value.details !== "object")) return false;
106
+ return true;
107
+ }
108
+ /** Flatten an aggregate validation error's nested `details.errors` into individual errors, or return the original as a singleton. */
109
+ function collectValidationErrors(error) {
110
+ const nestedErrors = error.details?.errors;
111
+ if (!Array.isArray(nestedErrors)) return [error];
112
+ const flattened = [];
113
+ for (const entry of nestedErrors) {
114
+ if (!isValidationErrorJson(entry)) return [error];
115
+ flattened.push(new ValidationError(entry.message, {
116
+ code: entry.code,
117
+ exitCode: entry.exitCode,
118
+ ...entry.suggest !== void 0 ? { suggest: entry.suggest } : {},
119
+ ...entry.details !== void 0 ? { details: entry.details } : {}
120
+ }));
121
+ }
122
+ return flattened;
123
+ }
124
+ /** Throw a single error if one, or an aggregate with per-issue summaries if many. */
125
+ function throwAggregatedErrors(errors) {
126
+ if (errors.length === 1) throw errors[0];
127
+ const issues = errors.map(summarizeValidationError);
128
+ const lines = issues.map(formatAggregateLine);
129
+ throw new ValidationError(`${formatAggregateHeadline(issues)}:\n - ${lines.join("\n - ")}`, {
130
+ code: errors[0].code,
131
+ details: {
132
+ errors: errors.map((error) => error.toJSON()),
133
+ count: errors.length,
134
+ issues
135
+ },
136
+ suggest: "Fix the listed validation errors and retry"
137
+ });
138
+ }
139
+ //#endregion
140
+ export { collectValidationErrors, isNonEmpty, throwAggregatedErrors };
@@ -1 +1,196 @@
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) {
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.presence === "required") {
105
+ const details = {
106
+ flag: name,
107
+ kind: schema.kind
108
+ };
109
+ if (schema.envVar !== void 0) details.envVar = schema.envVar;
110
+ if (schema.configPath !== void 0) details.configPath = schema.configPath;
111
+ errors.push(new ValidationError(`Missing required flag --${name}`, {
112
+ code: "REQUIRED_FLAG",
113
+ details,
114
+ suggest: buildRequiredFlagSuggest(name, schema)
115
+ }));
116
+ continue;
117
+ }
118
+ resolved[name] = void 0;
119
+ }
120
+ if (isNonEmpty(errors)) throwAggregatedErrors(errors);
121
+ return resolved;
122
+ }
123
+ /** Maps each flag kind to the prompt kinds that produce compatible values. */
124
+ const COMPATIBLE_PROMPT_KINDS = {
125
+ boolean: ["confirm"],
126
+ string: ["input", "select"],
127
+ number: ["input"],
128
+ enum: ["select", "input"],
129
+ array: ["multiselect"],
130
+ custom: [
131
+ "input",
132
+ "select",
133
+ "confirm",
134
+ "multiselect"
135
+ ]
136
+ };
137
+ /**
138
+ * Check whether a prompt kind is compatible with the flag's declared kind.
139
+ *
140
+ * @returns `undefined` when compatible, or a {@link ValidationError} with
141
+ * code `'CONSTRAINT_VIOLATED'` and an actionable `suggest` message when not.
142
+ * @internal
143
+ */
144
+ function validatePromptFlagCompatibility(flagName, flagKind, promptKind) {
145
+ const allowed = COMPATIBLE_PROMPT_KINDS[flagKind];
146
+ if (allowed.includes(promptKind)) return void 0;
147
+ return new ValidationError(`Prompt kind '${promptKind}' is not compatible with ${flagKind} flag --${flagName}. Use '${allowed[0]}' instead`, {
148
+ code: "CONSTRAINT_VIOLATED",
149
+ details: {
150
+ flag: flagName,
151
+ flagKind,
152
+ promptKind,
153
+ allowed
154
+ },
155
+ suggest: `Change the prompt to { kind: '${allowed[0]}' } for --${flagName}`
156
+ });
157
+ }
158
+ /**
159
+ * Validate prompt/flag compatibility, run the prompt engine, and coerce the result.
160
+ *
161
+ * Returns early with a {@link ValidationError} if the prompt kind is
162
+ * incompatible with the flag kind (checked via {@link COMPATIBLE_PROMPT_KINDS}
163
+ * before the prompter is invoked).
164
+ * @internal
165
+ */
166
+ async function resolvePromptValueWithConfig(flagName, schema, promptConfig, prompter) {
167
+ const mismatch = validatePromptFlagCompatibility(flagName, schema.kind, promptConfig.kind);
168
+ if (mismatch !== void 0) return {
169
+ ok: false,
170
+ error: mismatch
171
+ };
172
+ const resolvedConfig = resolvePromptConfig(promptConfig, schema.enumValues);
173
+ const result = await prompter.promptOne(resolvedConfig);
174
+ if (!result.answered) return {
175
+ ok: false,
176
+ error: void 0
177
+ };
178
+ if (promptConfig.kind === "input" && promptConfig.default === void 0 && typeof result.value === "string" && result.value.trim() === "") return {
179
+ ok: false,
180
+ error: void 0
181
+ };
182
+ return coerceValue(flagName, { kind: "prompt" }, result.value, schema);
183
+ }
184
+ /** Build a human-readable suggestion listing all available sources for a required flag. @internal */
185
+ function buildRequiredFlagSuggest(name, schema) {
186
+ const sources = [];
187
+ sources.push(`Provide --${name}${schema.kind !== "boolean" ? " <value>" : ""}`);
188
+ if (schema.envVar !== void 0) sources.push(`set ${schema.envVar}`);
189
+ if (schema.configPath !== void 0) sources.push(`add ${schema.configPath} to config`);
190
+ if (sources.length <= 1) return sources.join("");
191
+ const rest = sources.slice(0, -1);
192
+ const last = sources.slice(-1).join("");
193
+ return sources.length === 2 ? `${rest.join("")} or ${last}` : `${rest.join(", ")}, or ${last}`;
194
+ }
195
+ //#endregion
196
+ export { resolveFlags };