@kjanat/dreamcli 1.0.0 → 2.0.1

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 (217) hide show
  1. package/CHANGELOG.md +63 -6
  2. package/LICENSE +1 -1
  3. package/README.md +296 -164
  4. package/dist/core/cli/dispatch.d.mts +85 -0
  5. package/dist/core/cli/dispatch.mjs +1 -0
  6. package/dist/core/cli/index.d.mts +418 -0
  7. package/dist/core/cli/index.mjs +1 -0
  8. package/dist/core/cli/planner.d.mts +143 -0
  9. package/dist/core/cli/planner.mjs +1 -0
  10. package/dist/core/cli/plugin.d.mts +94 -0
  11. package/dist/core/cli/plugin.mjs +1 -0
  12. package/dist/core/cli/propagate.d.mts +39 -0
  13. package/dist/core/cli/propagate.mjs +1 -0
  14. package/dist/core/cli/root-help.d.mts +28 -0
  15. package/dist/core/cli/root-help.mjs +7 -0
  16. package/dist/core/cli/root-surface.d.mts +42 -0
  17. package/dist/core/cli/root-surface.mjs +1 -0
  18. package/dist/core/cli/runtime-preflight.d.mts +149 -0
  19. package/dist/core/cli/runtime-preflight.mjs +1 -0
  20. package/dist/core/completion/index.d.mts +46 -0
  21. package/dist/core/completion/index.mjs +1 -0
  22. package/dist/core/completion/shells/bash.d.mts +24 -0
  23. package/dist/core/completion/shells/bash.mjs +3 -0
  24. package/dist/core/completion/shells/fish.d.mts +20 -0
  25. package/dist/core/completion/shells/fish.mjs +2 -0
  26. package/dist/core/completion/shells/powershell.d.mts +14 -0
  27. package/dist/core/completion/shells/powershell.mjs +2 -0
  28. package/dist/core/completion/shells/shared.d.mts +139 -0
  29. package/dist/core/completion/shells/shared.mjs +1 -0
  30. package/dist/core/completion/shells/zsh.d.mts +24 -0
  31. package/dist/core/completion/shells/zsh.mjs +2 -0
  32. package/dist/core/config/index.d.mts +161 -0
  33. package/dist/core/config/index.mjs +1 -0
  34. package/dist/core/config/package-json.d.mts +68 -0
  35. package/dist/core/config/package-json.mjs +1 -0
  36. package/dist/core/errors/index.d.mts +126 -0
  37. package/dist/core/errors/index.mjs +1 -0
  38. package/dist/core/execution/index.d.mts +49 -0
  39. package/dist/core/execution/index.mjs +1 -0
  40. package/dist/core/help/index.d.mts +49 -0
  41. package/dist/core/help/index.mjs +8 -0
  42. package/dist/core/json-schema/index.d.mts +109 -0
  43. package/dist/core/json-schema/index.mjs +55 -0
  44. package/dist/core/json-schema/meta-descriptions.generated.d.mts +185 -0
  45. package/dist/core/json-schema/meta-descriptions.generated.mjs +28 -0
  46. package/dist/core/output/activity.d.mts +194 -0
  47. package/dist/core/output/activity.mjs +1 -0
  48. package/dist/core/output/contracts.d.mts +88 -0
  49. package/dist/core/output/contracts.mjs +1 -0
  50. package/dist/core/output/display-value.d.mts +19 -0
  51. package/dist/core/output/display-value.mjs +1 -0
  52. package/dist/core/output/index.d.mts +280 -0
  53. package/dist/core/output/index.mjs +2 -0
  54. package/dist/core/output/renderers.d.mts +46 -0
  55. package/dist/core/output/renderers.mjs +1 -0
  56. package/dist/core/output/writer.d.mts +40 -0
  57. package/dist/core/output/writer.mjs +1 -0
  58. package/dist/core/parse/index.d.mts +79 -0
  59. package/dist/core/parse/index.mjs +1 -0
  60. package/dist/core/prompt/index.d.mts +205 -0
  61. package/dist/core/prompt/index.mjs +6 -0
  62. package/dist/core/resolve/args.d.mts +8 -0
  63. package/dist/core/resolve/args.mjs +1 -0
  64. package/dist/core/resolve/coerce.d.mts +22 -0
  65. package/dist/core/resolve/coerce.mjs +1 -0
  66. package/dist/core/resolve/config.d.mts +10 -0
  67. package/dist/core/resolve/config.mjs +1 -0
  68. package/dist/core/resolve/contracts.d.mts +112 -0
  69. package/dist/core/resolve/errors.d.mts +11 -0
  70. package/dist/core/resolve/errors.mjs +2 -0
  71. package/dist/core/resolve/flags.d.mts +10 -0
  72. package/dist/core/resolve/flags.mjs +1 -0
  73. package/dist/core/resolve/index.d.mts +42 -0
  74. package/dist/core/resolve/index.mjs +1 -0
  75. package/dist/core/resolve/property.d.mts +47 -0
  76. package/dist/core/resolve/property.mjs +1 -0
  77. package/dist/core/schema/activity.d.mts +169 -0
  78. package/dist/core/schema/arg.d.mts +559 -0
  79. package/dist/core/schema/arg.mjs +1 -0
  80. package/dist/core/schema/command.d.mts +960 -0
  81. package/dist/core/schema/command.mjs +1 -0
  82. package/dist/core/schema/flag.d.mts +491 -0
  83. package/dist/core/schema/flag.mjs +1 -0
  84. package/dist/core/schema/index.d.mts +8 -0
  85. package/dist/core/schema/middleware.d.mts +122 -0
  86. package/dist/core/schema/middleware.mjs +1 -0
  87. package/dist/core/schema/prompt.d.mts +117 -0
  88. package/dist/core/schema/run.d.mts +171 -0
  89. package/dist/core/schema-dsl/runtime.d.mts +144 -0
  90. package/dist/core/schema-dsl/runtime.mjs +2 -0
  91. package/dist/core/schema-dsl/to-json-schema.d.mts +30 -0
  92. package/dist/core/schema-dsl/to-json-schema.mjs +1 -0
  93. package/dist/core/testkit/index.d.mts +54 -0
  94. package/dist/core/testkit/index.mjs +1 -0
  95. package/dist/index.d.mts +28 -920
  96. package/dist/index.mjs +1 -10
  97. package/dist/runtime/adapter.d.mts +212 -0
  98. package/dist/{adapter-B37d9oia.mjs → runtime/adapter.mjs} +1 -1
  99. package/dist/runtime/auto.d.mts +26 -0
  100. package/dist/runtime/auto.mjs +1 -0
  101. package/dist/runtime/bun.d.mts +28 -0
  102. package/dist/runtime/bun.mjs +1 -0
  103. package/dist/runtime/deno.d.mts +76 -0
  104. package/dist/runtime/deno.mjs +2 -0
  105. package/dist/runtime/detect.d.mts +86 -0
  106. package/dist/runtime/detect.mjs +1 -0
  107. package/dist/runtime/index.d.mts +7 -0
  108. package/dist/runtime/node.d.mts +65 -0
  109. package/dist/runtime/node.mjs +2 -0
  110. package/dist/runtime/paths.d.mts +31 -0
  111. package/dist/runtime/paths.mjs +1 -0
  112. package/dist/runtime/support.d.mts +42 -0
  113. package/dist/runtime/support.mjs +1 -0
  114. package/dist/runtime.d.mts +6 -252
  115. package/dist/runtime.mjs +1 -1
  116. package/dist/testkit.d.mts +5 -24
  117. package/dist/testkit.mjs +1 -1
  118. package/dist/version.d.mts +16 -0
  119. package/dist/version.mjs +1 -0
  120. package/dreamcli.schema.json +338 -0
  121. package/examples/basic.ts +2 -2
  122. package/examples/gh/package.json +7 -11
  123. package/examples/gh/src/commands/auth.ts +2 -2
  124. package/examples/gh/src/commands/issue.ts +4 -4
  125. package/examples/gh/src/commands/pr.ts +4 -4
  126. package/examples/gh/src/docs.ts +11 -0
  127. package/examples/gh/src/lib/auth.ts +1 -1
  128. package/examples/gh/src/main.test.ts +6 -5
  129. package/examples/gh/src/main.ts +8 -6
  130. package/examples/interactive.ts +3 -3
  131. package/examples/json-mode.ts +4 -6
  132. package/examples/middleware.ts +3 -3
  133. package/examples/multi-command.ts +3 -3
  134. package/examples/spinner-progress.ts +5 -5
  135. package/examples/testing.ts +8 -6
  136. package/package.json +70 -44
  137. package/src/core/cli/dispatch.ts +4 -0
  138. package/src/core/cli/index.ts +185 -632
  139. package/src/core/cli/planner.ts +413 -0
  140. package/src/core/cli/plugin.ts +7 -1
  141. package/src/core/cli/propagate.ts +1 -1
  142. package/src/core/cli/runtime-preflight.ts +409 -0
  143. package/src/core/completion/index.ts +15 -9
  144. package/src/core/completion/shells/bash.ts +6 -3
  145. package/src/core/completion/shells/fish.ts +245 -10
  146. package/src/core/completion/shells/powershell.ts +390 -9
  147. package/src/core/completion/shells/shared.ts +4 -4
  148. package/src/core/completion/shells/zsh.ts +12 -7
  149. package/src/core/config/index.ts +7 -4
  150. package/src/core/config/package-json.ts +6 -2
  151. package/src/core/errors/index.ts +23 -8
  152. package/src/core/execution/index.ts +270 -0
  153. package/src/core/help/index.ts +13 -15
  154. package/src/core/json-schema/index.ts +193 -7
  155. package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
  156. package/src/core/output/contracts.ts +194 -0
  157. package/src/core/output/index.ts +47 -82
  158. package/src/core/output/renderers.ts +125 -0
  159. package/src/core/parse/index.ts +39 -21
  160. package/src/core/prompt/index.ts +44 -27
  161. package/src/core/resolve/args.ts +144 -0
  162. package/src/core/resolve/coerce.ts +432 -0
  163. package/src/core/resolve/config.ts +26 -0
  164. package/src/core/resolve/contracts.ts +135 -0
  165. package/src/core/resolve/errors.ts +227 -0
  166. package/src/core/resolve/flags.ts +205 -0
  167. package/src/core/resolve/index.ts +41 -1264
  168. package/src/core/resolve/property.ts +99 -0
  169. package/src/core/schema/activity.ts +3 -0
  170. package/src/core/schema/arg.ts +26 -14
  171. package/src/core/schema/command.ts +265 -38
  172. package/src/core/schema/flag.ts +120 -15
  173. package/src/core/schema/index.ts +11 -2
  174. package/src/core/schema/middleware.ts +6 -6
  175. package/src/core/schema/prompt.ts +9 -1
  176. package/src/core/schema/run.ts +25 -17
  177. package/src/core/schema-dsl/index.ts +109 -0
  178. package/src/core/schema-dsl/parse.ts +262 -0
  179. package/src/core/schema-dsl/runtime.ts +609 -0
  180. package/src/core/schema-dsl/to-json-schema.ts +102 -0
  181. package/src/core/testkit/index.ts +55 -297
  182. package/src/index.ts +10 -4
  183. package/src/runtime/adapter.ts +13 -10
  184. package/src/runtime/auto.ts +3 -3
  185. package/src/runtime/bun.ts +4 -4
  186. package/src/runtime/deno.ts +43 -29
  187. package/src/runtime/detect.ts +4 -1
  188. package/src/runtime/index.ts +1 -1
  189. package/src/runtime/node.ts +43 -21
  190. package/src/runtime/paths.ts +9 -3
  191. package/src/runtime/support.ts +20 -4
  192. package/src/runtime.ts +1 -1
  193. package/src/testkit.ts +10 -8
  194. package/dist/adapter-CCSh5juX.cjs +0 -1
  195. package/dist/adapter-DIwO-q7K.d.mts +0 -3447
  196. package/dist/adapter-DQnxxLiE.d.cts +0 -3447
  197. package/dist/auto-5cjZaF9V.mjs +0 -3
  198. package/dist/auto-B0eSgoDw.cjs +0 -3
  199. package/dist/index.cjs +0 -10
  200. package/dist/index.d.cts +0 -920
  201. package/dist/runtime.cjs +0 -1
  202. package/dist/runtime.d.cts +0 -253
  203. package/dist/testkit-CEDYPvhF.mjs +0 -14
  204. package/dist/testkit-ClIKijxC.cjs +0 -14
  205. package/dist/testkit.cjs +0 -1
  206. package/dist/testkit.d.cts +0 -25
  207. package/examples/gh/tsconfig.json +0 -37
  208. package/examples/tsconfig.json +0 -17
  209. package/src/core/cli/AGENTS.md +0 -72
  210. package/src/core/completion/AGENTS.md +0 -72
  211. package/src/core/completion/completion-test-helpers.ts +0 -48
  212. package/src/core/output/AGENTS.md +0 -69
  213. package/src/core/resolve/AGENTS.md +0 -69
  214. package/src/core/schema/AGENTS.md +0 -61
  215. package/src/core/testkit/AGENTS.md +0 -55
  216. package/src/runtime/AGENTS.md +0 -74
  217. package/src/runtime/test-helpers.ts +0 -40
package/dist/runtime.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./auto-B0eSgoDw.cjs`),t=require(`./adapter-CCSh5juX.cjs`);exports.ExitError=t.t,exports.RUNTIMES=e.n,exports.createAdapter=e.t,exports.createBunAdapter=e.a,exports.createDenoAdapter=e.i,exports.createNodeAdapter=e.o,exports.detectRuntime=e.r;
@@ -1,253 +0,0 @@
1
- import { n as RuntimeAdapter, t as ExitError } from "./adapter-DQnxxLiE.cjs";
2
-
3
- //#region src/runtime/detect.d.ts
4
- /**
5
- * Auto-detects the current JavaScript runtime environment.
6
- *
7
- * Uses `globalThis` feature detection (version globals) to identify
8
- * the runtime without importing platform-specific modules. This is
9
- * the recommended approach because each runtime defines a unique
10
- * global marker:
11
- *
12
- * - **Bun:** `globalThis.Bun.version` (string)
13
- * - **Deno:** `globalThis.Deno.version` (object with `deno` key)
14
- * - **Node:** `globalThis.process.versions.node` (string)
15
- *
16
- * Detection order matters: Bun provides a Node-compatible `process`
17
- * global, so it must be checked *before* Node to avoid misidentification.
18
- *
19
- * @module dreamcli/runtime/detect
20
- */
21
- /**
22
- * Known JavaScript runtime environments.
23
- *
24
- * - `'node'` — Node.js
25
- * - `'bun'` — Bun
26
- * - `'deno'` — Deno
27
- * - `'unknown'` — Unrecognized environment
28
- */
29
- type Runtime = 'node' | 'bun' | 'deno' | 'unknown';
30
- /**
31
- * All known runtime values as a readonly tuple.
32
- *
33
- * Useful for validation, iteration, and exhaustiveness checks.
34
- *
35
- * @example
36
- * ```ts
37
- * if (RUNTIMES.includes(value)) {
38
- * // value is a valid Runtime
39
- * }
40
- * ```
41
- */
42
- declare const RUNTIMES: readonly ['node', 'bun', 'deno', 'unknown'];
43
- /**
44
- * Minimal `globalThis` shape used for runtime detection.
45
- *
46
- * Each field is optional — only the present one identifies the runtime.
47
- * Typed as `unknown` where we only need truthiness; version fields are
48
- * typed just enough to distinguish runtimes safely.
49
- */
50
- interface GlobalForDetect {
51
- readonly Bun?: {
52
- readonly version?: string;
53
- };
54
- readonly Deno?: {
55
- readonly version?: {
56
- readonly deno?: string;
57
- };
58
- };
59
- readonly process?: {
60
- readonly versions?: {
61
- readonly node?: string;
62
- readonly bun?: string;
63
- };
64
- };
65
- }
66
- /**
67
- * Detect the current JavaScript runtime.
68
- *
69
- * Uses `globalThis` feature detection to identify the host runtime.
70
- * Detection order is significant: Bun is checked before Node because
71
- * Bun exposes a Node-compatible `process` global.
72
- *
73
- * @param globals - Override `globalThis` for testing. Production callers
74
- * should omit this parameter.
75
- * @returns The detected {@link Runtime} identifier.
76
- *
77
- * @example
78
- * ```ts
79
- * const rt = detectRuntime();
80
- * // rt === 'node' | 'bun' | 'deno' | 'unknown'
81
- * ```
82
- */
83
- declare function detectRuntime(globals?: GlobalForDetect): Runtime;
84
- //#endregion
85
- //#region src/runtime/auto.d.ts
86
- /**
87
- * Create a runtime adapter for the current environment.
88
- *
89
- * Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
90
- * Unknown runtimes fall back to the Node adapter because most JS runtimes
91
- * expose a Node-compatible `process` global.
92
- *
93
- * @param globals - Override `globalThis` for testing. Production callers
94
- * should omit this parameter.
95
- * @returns A `RuntimeAdapter` for the detected runtime.
96
- *
97
- * @example
98
- * ```ts
99
- * import { cli } from 'dreamcli';
100
- *
101
- * // Auto-detects Node/Bun/Deno and creates the right adapter
102
- * cli('mycli').run(); // uses createAdapter() internally
103
- * ```
104
- */
105
- declare function createAdapter(globals?: GlobalForDetect): RuntimeAdapter;
106
- //#endregion
107
- //#region src/runtime/node.d.ts
108
- /**
109
- * Minimal subset of the Node.js `process` object needed by the adapter.
110
- *
111
- * We avoid importing `@types/node` to keep the core runtime-agnostic
112
- * at the type level. This interface declares only what `createNodeAdapter`
113
- * actually reads from the global.
114
- */
115
- interface NodeProcess {
116
- readonly argv: readonly string[];
117
- readonly env: Readonly<Record<string, string | undefined>>;
118
- readonly versions?: {
119
- readonly node?: string;
120
- readonly bun?: string;
121
- };
122
- cwd(): string;
123
- /** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
124
- readonly platform: string;
125
- readonly stdin: {
126
- readonly isTTY?: boolean; /** Async iterable for reading all of stdin (used by readStdin). */
127
- [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
128
- };
129
- readonly stdout: {
130
- readonly isTTY?: boolean;
131
- write(data: string): unknown;
132
- };
133
- readonly stderr: {
134
- write(data: string): unknown;
135
- };
136
- exit(code: number): never;
137
- }
138
- /**
139
- * Create a runtime adapter backed by Node.js `process` globals.
140
- *
141
- * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
142
- * `process.stdout.write`/`process.stderr.write` as `WriteFn` functions.
143
- *
144
- * Also works on Bun, which provides a Node-compatible `process` global.
145
- *
146
- * @param proc - Override the process object (useful for testing the adapter itself).
147
- * @returns A `RuntimeAdapter` backed by Node.js process state.
148
- *
149
- * @example
150
- * ```ts
151
- * import { cli } from 'dreamcli';
152
- * import { createNodeAdapter } from 'dreamcli/runtime/node';
153
- *
154
- * cli('mycli')
155
- * .command(deploy)
156
- * .run({ adapter: createNodeAdapter() });
157
- * ```
158
- */
159
- declare function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter;
160
- //#endregion
161
- //#region src/runtime/bun.d.ts
162
- /**
163
- * Create a runtime adapter backed by Bun's Node-compatible `process` global.
164
- *
165
- * Bun exposes `globalThis.process` with the same shape as Node.js, so this
166
- * delegates entirely to {@link createNodeAdapter}. If Bun-specific optimizations
167
- * are needed in the future (e.g. `Bun.write` for I/O), they can be layered
168
- * here without changing the public API.
169
- *
170
- * @param proc - Override the process object (useful for testing the adapter itself).
171
- * @returns A `RuntimeAdapter` backed by Bun's process state.
172
- *
173
- * @example
174
- * ```ts
175
- * import { cli } from 'dreamcli';
176
- * import { createBunAdapter } from 'dreamcli/runtime/bun';
177
- *
178
- * cli('mycli')
179
- * .command(deploy)
180
- * .run({ adapter: createBunAdapter() });
181
- * ```
182
- */
183
- declare function createBunAdapter(proc?: NodeProcess): RuntimeAdapter;
184
- //#endregion
185
- //#region src/runtime/deno.d.ts
186
- /**
187
- * Minimal subset of the Deno namespace needed by the adapter.
188
- *
189
- * We avoid `@types/deno` to keep the core runtime-agnostic at the type level.
190
- * This interface declares only what `createDenoAdapter` actually reads.
191
- *
192
- * The `env` property is optional because it requires `--allow-env` permission.
193
- * When permission is denied, the adapter catches the error and falls back to
194
- * an empty env object.
195
- */
196
- interface DenoNamespace {
197
- readonly build: {
198
- readonly os: 'darwin' | 'linux' | 'android' | 'windows' | 'freebsd' | 'netbsd' | 'aix' | 'solaris' | 'illumos';
199
- };
200
- readonly version?: {
201
- readonly deno?: string;
202
- };
203
- /** Raw command-line args (excludes the binary/script — Deno pre-strips them). */
204
- readonly args: readonly string[];
205
- /** Environment variable access (requires `--allow-env`). */
206
- readonly env: {
207
- /** Get a single env var. Returns `undefined` if unset or permission denied. */get(key: string): string | undefined; /** Get all env vars as a plain object. Throws on permission denied. */
208
- toObject(): Record<string, string>;
209
- };
210
- /** Current working directory (may throw if `--allow-read` is denied for cwd). */
211
- cwd(): string;
212
- readonly stdout: {
213
- /** Write raw bytes to stdout synchronously. */writeSync(p: Uint8Array): number; /** Whether stdout is connected to a TTY. */
214
- isTerminal(): boolean;
215
- };
216
- readonly stderr: {
217
- /** Write raw bytes to stderr synchronously. */writeSync(p: Uint8Array): number;
218
- };
219
- readonly stdin: {
220
- /** Whether stdin is connected to a TTY. */isTerminal(): boolean; /** Readable stream for stdin bytes. */
221
- readonly readable: ReadableStream<Uint8Array>;
222
- };
223
- /** Exit the process with the given code. */
224
- exit(code: number): never;
225
- /** Read a file as UTF-8 text (requires `--allow-read`). */
226
- readTextFile(path: string): Promise<string>;
227
- }
228
- /**
229
- * Create a runtime adapter backed by the Deno namespace.
230
- *
231
- * Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
232
- * I/O into the `WriteFn`/`ReadFn` functions expected by the framework.
233
- *
234
- * Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
235
- * The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
236
- * shape matches the `RuntimeAdapter` contract (binary + script + user args).
237
- *
238
- * @param ns - Override the Deno namespace (useful for testing the adapter itself).
239
- * @returns A `RuntimeAdapter` backed by Deno's namespace APIs.
240
- *
241
- * @example
242
- * ```ts
243
- * import { cli } from 'dreamcli';
244
- * import { createDenoAdapter } from 'dreamcli/runtime';
245
- *
246
- * cli('mycli')
247
- * .command(deploy)
248
- * .run({ adapter: createDenoAdapter() });
249
- * ```
250
- */
251
- declare function createDenoAdapter(ns?: DenoNamespace): RuntimeAdapter;
252
- //#endregion
253
- export { ExitError, RUNTIMES, type Runtime, type RuntimeAdapter, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
@@ -1,14 +0,0 @@
1
- var e=class extends Error{name=`CLIError`;code;exitCode;suggest;details;constructor(e,t){super(e,t.cause===void 0?void 0:{cause:t.cause}),this.code=t.code,this.exitCode=t.exitCode??1,this.suggest=t.suggest,this.details=t.details}toJSON(){return{name:this.name,code:this.code,message:this.message,exitCode:this.exitCode,...this.suggest!==void 0&&{suggest:this.suggest},...this.details!==void 0&&{details:this.details}}}},t=class extends e{name=`ParseError`;constructor(e,t){super(e,{...t,exitCode:t.exitCode??2})}},n=class extends e{name=`ValidationError`;constructor(e,t){super(e,{...t,exitCode:t.exitCode??2})}};function r(t){return t instanceof e}function i(e){return e instanceof t}function a(e){return e instanceof n}function o(e){if(e==null)return``;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`||typeof e==`symbol`)return String(e);if(e instanceof Date)return Number.isNaN(e.getTime())?`Invalid Date`:e.toISOString();if(typeof e==`function`)return e.name.length>0?`[Function: ${e.name}]`:`[Function]`;try{return JSON.stringify(e)??`[unserializable]`}catch{return`[unserializable]`}}function s(e){return{width:e?.width??80,binName:e?.binName,isDefaultHelp:e?.isDefaultHelp??!1}}function c(e,t){return e.length>=t?e:e+` `.repeat(t-e.length)}function l(e,t,n){if(e.length+n<=t)return e;let r=t-n;if(r<=0)return e;let i=e.split(` `),a=[],o=``;for(let e of i)o.length===0?o=e:o.length+1+e.length<=r?o+=` ${e}`:(a.push(o),o=e);o.length>0&&a.push(o);let s=` `.repeat(n);return a.map((e,t)=>t===0?e:`${s}${e}`).join(`
2
- `)}function u(e){return typeof e==`string`?`[deprecated: ${e}]`:`[deprecated]`}function d(e){return e===void 0?`undefined`:e===null?`null`:o(e)}function ee(e,t){let n=[],r=t.aliases.find(e=>e.length===1);return r!==void 0&&n.push(`-${r},`),n.push(`--${e}`),t.kind!==`boolean`&&n.push(f(t)),n.join(` `)}function f(e){switch(e.kind){case`string`:return`<string>`;case`number`:return`<number>`;case`enum`:return`<${(e.enumValues??[]).join(`|`)}>`;case`array`:return`<${e.elementSchema===void 0?`value`:f(e.elementSchema).slice(1,-1)}>...`;case`boolean`:return``;case`custom`:return`<value>`}}function p(e){let t=[];return e.description!==void 0&&t.push(e.description),e.deprecated!==void 0&&t.push(u(e.deprecated)),e.envVar!==void 0&&t.push(`[env: ${e.envVar}]`),e.configPath!==void 0&&t.push(`[config: ${e.configPath}]`),e.prompt!==void 0&&t.push(`[prompt]`),e.presence===`required`?t.push(`[required]`):e.presence===`defaulted`&&e.kind!==`boolean`&&t.push(`(default: ${d(e.defaultValue)})`),t.join(` `)}function te(e){let t=Object.keys(e);if(t.length===0)return[];let n=[...t].sort((t,n)=>{let r=e[t],i=e[n];if(r===void 0||i===void 0)return 0;let a=r.aliases.some(e=>e.length===1),o=i.aliases.some(e=>e.length===1);return a&&!o?-1:!a&&o?1:t.localeCompare(n)}),r=[];for(let t of n){let n=e[t];n!==void 0&&r.push({left:ee(t,n),description:p(n)})}return r}function m(e){let{name:t,schema:n}=e,r=n.kind===`enum`&&n.enumValues!==void 0?n.enumValues.join(`|`):t,i=n.variadic?`...`:``;return n.presence===`required`?`<${r}>${i}`:`[${r}]${i}`}function ne(e){let t=[];return e.description!==void 0&&t.push(e.description),e.deprecated!==void 0&&t.push(u(e.deprecated)),e.envVar!==void 0&&t.push(`[env: ${e.envVar}]`),e.presence===`defaulted`&&t.push(`(default: ${d(e.defaultValue)})`),t.join(` `)}function h(e,t){let n=s(t),r=[];r.push(re(e,n)),e.description!==void 0&&r.push(e.description);let i=e.commands.filter(e=>!e.hidden);return i.length>0&&r.push(oe(i,n)),e.args.length>0&&r.push(ie(e.args,n)),Object.keys(e.flags).length>0&&r.push(ae(e.flags,n)),e.examples.length>0&&r.push(se(e.examples)),r}function g(e,t){return`${h(e,t).join(`
3
-
4
- `)}\n`}function re(e,t){let n=[`Usage:`],r=t.binName===void 0||t.isDefaultHelp&&t.binName===e.name?e.name:`${t.binName} ${e.name}`;n.push(r),e.commands.length>0&&n.push(`<command>`),Object.keys(e.flags).length>0&&n.push(`[flags]`);for(let t of e.args)n.push(m(t));return n.join(` `)}function ie(e,t){let n=[`Arguments:`],r=0,i=[];for(let t of e){let e=` ${m(t)}`,n=ne(t.schema);i.push({left:e,desc:n}),e.length>r&&(r=e.length)}let a=r+2;for(let{left:e,desc:r}of i)if(r.length===0)n.push(e);else{let i=c(e,a),o=l(r,t.width,a);n.push(`${i}${o}`)}return n.join(`
5
- `)}function ae(e,t){let n=[`Flags:`],r=te(e);if(r.length===0)return``;let i=0;for(let e of r){let t=` ${e.left}`;t.length>i&&(i=t.length)}let a=i+2;for(let e of r){let r=` ${e.left}`;if(e.description.length===0)n.push(r);else{let i=c(r,a),o=l(e.description,t.width,a);n.push(`${i}${o}`)}}return n.join(`
6
- `)}function oe(e,t){let n=[`Commands:`],r=0;for(let t of e)t.name.length>r&&(r=t.name.length);let i=2+r+2;for(let r of e){let e=` ${r.name}`,a=r.description??``;if(a.length===0)n.push(e);else{let r=c(e,i),o=l(a,t.width,i);n.push(`${r}${o}`)}}return n.join(`
7
- `)}function se(e){let t=[`Examples:`];for(let n of e)n.description===void 0?t.push(` $ ${n.command}`):(t.push(` ${n.description}:`),t.push(` $ ${n.command}`));return t.join(`
8
- `)}function _(e,t){e(`${t}\n`)}const ce={update(){},succeed(){},fail(){},stop(){},wrap(e){return e}},le={increment(){},update(){},done(){},fail(){}};var ue=class{stopped=!1;constructor(e,t){this.write=t,_(t,e)}update(e){}succeed(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}stop(){this.stopped||=!0}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},de=class{stopped=!1;constructor(e,t){this.write=t,e!==void 0&&_(t,e)}increment(e){}update(e){}done(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}};const v=`\x1B[?25l`,y=`\x1B[?25h`,b=`\x1B[2K`,x=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];var S=class{stopped=!1;timer;frameIndex=0;text;constructor(e,t){this.write=t,this.text=e,t(v),this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%x.length,this.render()},80)}render(){let e=x[this.frameIndex]??x[0];this.write(`\r${b}${e} ${this.text}`)}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${b}${y}`)}update(e){this.stopped||(this.text=e,this.render())}succeed(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✗ ${e}`))}stop(){this.stopped||(this.stopped=!0,this.cleanup())}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},C=class{stopped=!1;timer;current=0;total;label;pulsePos=0;pulseDir=1;constructor(e,t){this.write=t,this.total=e.total,this.label=e.label??``,t(v),this.render(),this.total===void 0&&(this.timer=setInterval(()=>{this.advancePulse(),this.render()},80))}advancePulse(){this.pulsePos+=this.pulseDir,this.pulsePos+3>20?(this.pulseDir=-1,this.pulsePos=17):this.pulsePos<0&&(this.pulseDir=1,this.pulsePos=0)}render(){let e=this.total===void 0?this.renderIndeterminate():this.renderDeterminate(this.total),t=this.label.length>0?` ${this.label}`:``;this.write(`\r${b}${e}${t}`)}renderDeterminate(e){let t=e>0?Math.max(0,Math.min(this.current/e,1)):0,n=Math.round(t*20),r=20-n,i=Math.round(t*100);return`[${`█`.repeat(n)}${`░`.repeat(r)}] ${String(i)}%`}renderIndeterminate(){let e=``;for(let t=0;t<20;t++)e+=t>=this.pulsePos&&t<this.pulsePos+3?`█`:`░`;return`[${e}]`}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${b}${y}`)}increment(e){this.stopped||(this.current+=e??1,this.render())}update(e){this.stopped||(this.current=e,this.render())}done(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✗ ${e}`))}},fe=class{stopped=!1;constructor(e,t){this.events=t,t.push({type:`spinner:start`,text:e})}update(e){this.stopped||this.events.push({type:`spinner:update`,text:e})}succeed(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:succeed`,text:e??``}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:fail`,text:e??``}))}stop(){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:stop`}))}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},pe=class{stopped=!1;constructor(e,t){this.events=t,t.push({type:`progress:start`,label:e.label??``,total:e.total})}increment(e){this.stopped||this.events.push({type:`progress:increment`,delta:e??1})}update(e){this.stopped||this.events.push({type:`progress:update`,value:e})}done(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:done`,text:e}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:fail`,text:e}))}};const w=()=>{};function T(e){return{stdout:e?.stdout??w,stderr:e?.stderr??w,isTTY:e?.isTTY??!1,verbosity:e?.verbosity??`normal`,jsonMode:e?.jsonMode??!1}}var E=class{options;jsonMode;isTTY;constructor(e){this.options=e,this.jsonMode=e.jsonMode,this.isTTY=e.isTTY}log(e){_(this.options.jsonMode?this.options.stderr:this.options.stdout,e)}info(e){this.options.verbosity!==`quiet`&&_(this.options.jsonMode?this.options.stderr:this.options.stdout,e)}warn(e){_(this.options.stderr,e)}error(e){_(this.options.stderr,e)}json(e){_(this.options.stdout,JSON.stringify(e))}table(e,t,n){let{columns:r,options:i}=ge(t,n),a=ve(this.options.jsonMode,i),o=r??he(e);if(a===`json`){this.json(_e(e,o));return}let s=xe(e,o);s.length!==0&&_(ye(this.options,a,i),s)}activeCleanup;stopActive(){this.activeCleanup!==void 0&&(this.activeCleanup(),this.activeCleanup=void 0)}spinner(e,t){let n=t?.fallback??`silent`;if(this.options.jsonMode||!this.options.isTTY&&n===`silent`)return ce;if(this.stopActive(),this.options.isTTY){let t=new S(e,this.options.stderr);return this.activeCleanup=()=>t.stop(),t}let r=new ue(e,this.options.stderr);return this.activeCleanup=()=>r.stop(),r}progress(e){let t=e.fallback??`silent`;if(this.options.jsonMode||!this.options.isTTY&&t===`silent`)return le;if(this.stopActive(),this.options.isTTY){let t=new C(e,this.options.stderr);return this.activeCleanup=()=>t.done(),t}let n=new de(e.label,this.options.stderr);return this.activeCleanup=()=>n.done(),n}},me=class extends E{constructor(e,t){super(e),this.activity=t}spinner(e,t){return new fe(e,this.activity)}progress(e){return new pe(e,this.activity)}};function he(e){let t=e[0];return t===void 0?[]:Object.keys(t).map(e=>({key:e}))}function D(e){return Array.isArray(e)}function ge(e,t){return t===void 0?D(e)?{columns:e,options:t}:{columns:void 0,options:e}:{columns:D(e)?e:void 0,options:t}}function _e(e,t){return e.map(e=>Object.fromEntries(t.map(t=>[t.key,e[t.key]])))}function ve(e,t){switch(t?.format){case`json`:return`json`;case`text`:return`text`;case`auto`:case void 0:return e?`json`:`text`}}function ye(e,t,n){return t===`text`&&n!==void 0&&`stream`in n&&n.stream!==void 0?n.stream===`stderr`?e.stderr:e.stdout:e.jsonMode?e.stderr:e.stdout}function be(e){return o(e)}function xe(e,t){if(e.length===0||t.length===0)return``;let n=t.map(e=>e.header??e.key),r=e.map(e=>t.map(t=>be(e[t.key]))),i=n.map((e,t)=>{let n=e.length;for(let e of r){let r=e[t];r!==void 0&&r.length>n&&(n=r.length)}return n});return[n.map((e,t)=>e.padEnd(i[t]??0)).join(` `),i.map(e=>`-`.repeat(e)).join(` `),...r.map(e=>e.map((e,t)=>e.padEnd(i[t]??0)).join(` `))].join(`
9
- `)}function Se(e){return new E(T(e))}function O(e){let t={stdout:[],stderr:[],activity:[]};return[new me(T({...e,stdout:e=>t.stdout.push(e),stderr:e=>t.stderr.push(e)}),t.activity),t]}function k(e){let t=[],n=!1;for(let r of e){if(n){t.push({kind:`positional`,value:r});continue}if(r===`--`){t.push({kind:`separator`}),n=!0;continue}if(r.startsWith(`--`)){let e=r.indexOf(`=`);e===-1?t.push({kind:`long-flag`,name:r.slice(2),value:void 0}):t.push({kind:`long-flag`,name:r.slice(2,e),value:r.slice(e+1)});continue}if(r.startsWith(`-`)&&r.length>1){t.push({kind:`short-flags`,chars:r.slice(1)});continue}t.push({kind:`positional`,value:r})}return t}function A(e){let t=new Map;for(let[n,r]of Object.entries(e)){t.set(n,[n,r]);for(let e of r.aliases)t.set(e,[n,r])}return t}function j(e){return e.kind!==`boolean`}function M(e,n,r){switch(r.kind){case`string`:return n;case`number`:{let r=Number(n);if(Number.isNaN(r))throw new t(`Invalid number value '${n}' for flag --${e}`,{code:`INVALID_VALUE`,details:{flag:e,value:n,expected:`number`}});return r}case`boolean`:if(n===`true`||n===`1`)return!0;if(n===`false`||n===`0`)return!1;throw new t(`Invalid boolean value '${n}' for flag --${e}. Use true/false or 1/0`,{code:`INVALID_VALUE`,details:{flag:e,value:n,expected:`boolean`}});case`enum`:{let i=r.enumValues;if(i===void 0)throw new t(`Enum flag --${e} is misconfigured: no allowed values declared`,{code:`INVALID_SCHEMA`,details:{flag:e,kind:`enum`,missing:`enumValues`}});if(!i.includes(n))throw new t(`Invalid value '${n}' for flag --${e}. Allowed: ${i.join(`, `)}`,{code:`INVALID_VALUE`,details:{flag:e,value:n,allowed:i}});return n}case`array`:return r.elementSchema?M(e,n,r.elementSchema):n;case`custom`:if(!r.parseFn)return n;try{return r.parseFn(n)}catch(r){throw r instanceof t?r:new t(`Failed to parse flag --${e}: ${r instanceof Error?r.message:String(r)}`,{code:`INVALID_VALUE`,details:{flag:e,value:n},cause:r})}}}function N(e,n,r){switch(r.kind){case`string`:return n;case`number`:{let r=Number(n);if(Number.isNaN(r))throw new t(`Invalid number value '${n}' for argument <${e}>`,{code:`INVALID_VALUE`,details:{arg:e,value:n,expected:`number`}});return r}case`enum`:{let i=r.enumValues;if(i===void 0)throw new t(`Enum argument <${e}> is misconfigured: no allowed values declared`,{code:`INVALID_SCHEMA`,details:{arg:e,kind:`enum`,missing:`enumValues`}});if(!i.includes(n))throw new t(`Invalid value '${n}' for argument <${e}>. Allowed: ${i.join(`, `)}`,{code:`INVALID_VALUE`,details:{arg:e,value:n,allowed:i}});return n}case`custom`:if(!r.parseFn)return n;try{return r.parseFn(n)}catch(r){throw r instanceof t?r:new t(`Failed to parse argument <${e}>: ${r instanceof Error?r.message:String(r)}`,{code:`INVALID_VALUE`,details:{arg:e,value:n},cause:r})}}}function P(e,t){let n=k(t),r=A(e.flags),i={},a=[],o=0;for(;o<n.length;){let e=n[o];if(e===void 0)break;if(e.kind===`separator`){o++;continue}if(e.kind===`positional`){a.push(e.value),o++;continue}if(e.kind===`long-flag`){o=Ce(e,n,o,r,i);continue}o=we(e,n,o,r,i)}return{flags:i,args:Te(e.args,a)}}function Ce(e,n,r,i,a){let o=i.get(e.name);if(!o){let n=Ee(e.name,i);throw new t(`Unknown flag --${e.name}${n?`. Did you mean --${n}?`:``}`,{code:`UNKNOWN_FLAG`,details:{flag:e.name,...n?{suggestion:n}:{}},...n?{suggest:`--${n}`}:{}})}let[s,c]=o;if(!j(c))return e.value===void 0?a[s]=!0:a[s]=M(s,e.value,c),r+1;if(e.value!==void 0)return F(a,s,c,e.value),r+1;let l=n[r+1];if(!l||l.kind!==`positional`)throw new t(`Flag --${s} requires a value`,{code:`MISSING_VALUE`,details:{flag:s,kind:c.kind}});return F(a,s,c,l.value),r+2}function we(e,n,r,i,a){let{chars:o}=e,s=r+1;for(let e=0;e<o.length;e++){let r=o.charAt(e),c=i.get(r);if(!c)throw new t(`Unknown flag -${r}`,{code:`UNKNOWN_FLAG`,details:{flag:r}});let[l,u]=c;if(!j(u)){a[l]=!0;continue}if(e<o.length-1){F(a,l,u,o.slice(e+1));break}let d=n[s];if(!d||d.kind!==`positional`)throw new t(`Flag -${r} requires a value`,{code:`MISSING_VALUE`,details:{flag:r,canonical:l,kind:u.kind}});F(a,l,u,d.value),s++}return s}function F(e,t,n,r){let i=M(t,r,n);if(n.kind===`array`){let n=e[t];Array.isArray(n)?n.push(i):e[t]=[i]}else e[t]=i}function Te(e,n){let r={},i=0;for(let t of e){if(t.schema.variadic){let e=n.slice(i);r[t.name]=e.map(e=>N(t.name,e,t.schema)),i=n.length;break}let e=n[i];e!==void 0&&(r[t.name]=N(t.name,e,t.schema),i++)}if(i<n.length){let r=n.slice(i);throw new t(`Unexpected positional argument${r.length>1?`s`:``}: ${r.join(`, `)}`,{code:`UNEXPECTED_POSITIONAL`,details:{excess:r,expected:e.length}})}return r}function Ee(e,t){let n,r=1/0,i=Math.max(2,Math.floor(e.length/2));for(let a of t.keys()){if(a.length<2)continue;let t=De(e,a);t<r&&t<=i&&(r=t,n=a)}return n}function De(e,t){if(e===t)return 0;if(e.length===0)return t.length;if(t.length===0)return e.length;let n=e.length<=t.length?e:t,r=e.length<=t.length?t:e,i=n.length,a=r.length,o=Array.from({length:i+1},(e,t)=>t);for(let e=1;e<=a;e++){let t=o[0]??0;o[0]=e;for(let a=1;a<=i;a++){let i=n.charAt(a-1)===r.charAt(e-1)?0:1,s=Math.min((o[a]??0)+1,(o[a-1]??0)+1,t+i);t=o[a]??0,o[a]=s}}return o[i]??0}const I=Symbol.for(`dreamcli.prompt.cancel`);function L(e,t){let n=0;return{promptOne(){if(n>=e.length)return t?.onExhausted===`cancel`?Promise.resolve({answered:!1}):Promise.reject(Error(`Test prompter exhausted: expected at most ${e.length} prompts, got prompt #${n+1}`));let r=e[n];return n+=1,r===I?Promise.resolve({answered:!1}):Promise.resolve({answered:!0,value:r})}}}function Oe(e,t){return{promptOne(n){switch(n.kind){case`confirm`:return R(n,e,t);case`input`:return ke(n,e,t);case`select`:return Ae(n,e,t);case`multiselect`:return je(n,e,t)}}}}async function R(e,t,n){n(`${e.message} (y/n) `);let r=await t();if(r===null)return{answered:!1};let i=r.trim().toLowerCase();return i===``||i===`y`||i===`yes`?{answered:!0,value:!0}:i===`n`||i===`no`?{answered:!0,value:!1}:(n(`Please answer y or n.
10
- `),R(e,t,n))}async function ke(e,t,n){let r=0;for(;r<10;){let i=e.placeholder===void 0?``:` (${e.placeholder})`;n(`${e.message}${i}: `);let a=await t();if(a===null)return{answered:!1};let o=a.trim();if(e.validate!==void 0){let t=e.validate(o);if(t!==!0){n(`${t}\n`),r+=1;continue}}return{answered:!0,value:o}}return n(`Too many invalid attempts.
11
- `),{answered:!1}}async function Ae(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter number: `);let i=await t();if(i===null)return{answered:!1};let a=Number(i.trim());if(Number.isNaN(a)||!Number.isInteger(a)||a<1||a>e.choices.length){n(`Please enter a number between 1 and ${e.choices.length}.\n`),r+=1;continue}let o=e.choices[a-1];if(o===void 0){r+=1;continue}return{answered:!0,value:o.value}}return n(`Too many invalid attempts.
12
- `),{answered:!1}}async function je(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter numbers separated by commas (e.g. 1,3${e.min===void 0?``:`, min: ${e.min}`}${e.max===void 0?``:`, max: ${e.max}`}): `);let i=await t();if(i===null)return{answered:!1};let a=i.trim();if(a===``){if(e.min!==void 0&&e.min>0){n(`Please select at least ${e.min}.\n`),r+=1;continue}return{answered:!0,value:[]}}let o=a.split(`,`).map(e=>e.trim()),s=[],c=!0;for(let t of o){let r=Number(t);if(Number.isNaN(r)||!Number.isInteger(r)||r<1||r>e.choices.length){n(`Invalid selection '${t}'. Use numbers between 1 and ${e.choices.length}.\n`),c=!1;break}s.push(r)}if(!c){r+=1;continue}let l=[...new Set(s)];if(e.min!==void 0&&l.length<e.min){n(`Please select at least ${e.min}.\n`),r+=1;continue}if(e.max!==void 0&&l.length>e.max){n(`Please select at most ${e.max}.\n`),r+=1;continue}return{answered:!0,value:l.map(t=>e.choices[t-1]?.value??``)}}return n(`Too many invalid attempts.
13
- `),{answered:!1}}function z(e,t){if(e.kind===`confirm`||e.kind===`input`)return e;let n=e.choices??t?.map(e=>({value:e}))??[];if(n.length===0)throw Error(`Prompt config (${e.kind}) requires choices but none were provided and no enum values are available`);let r=n;return e.kind===`select`?{kind:`select`,message:e.message,choices:r}:{kind:`multiselect`,message:e.message,choices:r,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max}}}async function B(e,t,n){let r=n?.stdinData,i=n?.env??{},a=n?.config??{},o=n?.prompter,s=[];return{flags:await Me(e.flags,t.flags,i,a,o,e.interactive,s),args:Ie(e.args,t.args,r,i,s),deprecations:s}}async function Me(e,t,r,i,a,o,s){let c={},l=[],u=new Set;for(let[n,a]of Object.entries(e)){let e=t[n];if(e!==void 0){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=e;continue}if(a.envVar!==void 0){let e=r[a.envVar];if(e!==void 0){let t=W(n,{kind:`env`,envVar:a.envVar},e,a);if(t.ok){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=t.value;continue}l.push(t.error),u.add(n);continue}}if(a.configPath!==void 0){let e=Fe(i,a.configPath);if(e!==void 0){let t=W(n,{kind:`config`,configPath:a.configPath},e,a);if(t.ok){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=t.value;continue}l.push(t.error),u.add(n)}}}let d=o===void 0?void 0:o({flags:c});for(let[t,r]of Object.entries(e)){if(t in c||u.has(t))continue;let e=d?.[t],i;if(i=e!=null&&e!==!1&&e!==0&&e!==``?e:e===!1?void 0:r.prompt,i!==void 0&&a!==void 0){let e=await Ne(t,r,i,a);if(e.ok){r.deprecated!==void 0&&s.push({kind:`flag`,name:t,message:r.deprecated}),c[t]=e.value;continue}if(e.error!==void 0){l.push(e.error);continue}}if(r.defaultValue!==void 0){c[t]=r.defaultValue;continue}if(r.kind===`array`&&r.presence!==`required`){c[t]=[];continue}if(r.presence===`required`){let e={flag:t,kind:r.kind};r.envVar!==void 0&&(e.envVar=r.envVar),r.configPath!==void 0&&(e.configPath=r.configPath),l.push(new n(`Missing required flag --${t}`,{code:`REQUIRED_FLAG`,details:e,suggest:Pe(t,r)}));continue}c[t]=void 0}return Y(l)&&X(l),c}async function Ne(e,t,n,r){let i=z(n,t.enumValues),a=await r.promptOne(i);return a.answered?W(e,{kind:`prompt`},a.value,t):{ok:!1,error:void 0}}function Pe(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}`}function V(e){switch(e.kind){case`env`:return`from env ${e.envVar}`;case`config`:return`from config ${e.configPath}`;case`prompt`:return`from prompt`}}function H(e){switch(e.kind){case`env`:return{envVar:e.envVar};case`config`:return{configPath:e.configPath};case`prompt`:return{source:`prompt`}}}function U(e,t,r,i,a,o,s,c){return{ok:!1,error:new n(`${o} ${V(t)} for flag --${e}`,{code:r,details:{flag:e,...H(t),value:a,expected:i,...c},suggest:s})}}function W(e,t,r,i){switch(i.kind){case`string`:return typeof r==`string`?{ok:!0,value:r}:t.kind===`prompt`||t.kind===`config`&&(typeof r==`number`||typeof r==`boolean`)?{ok:!0,value:String(r)}:U(e,t,`TYPE_MISMATCH`,`string`,r,`Invalid string value`,t.kind===`config`?`Set ${t.configPath} to a string in your config`:`Enter a valid string for --${e}`);case`number`:if(typeof r==`number`)return Number.isNaN(r)?U(e,t,`TYPE_MISMATCH`,`number`,r,`Invalid number value NaN`,t.kind===`env`?`Set ${t.envVar} to a valid number`:t.kind===`config`?`Set ${t.configPath} to a valid number in your config`:`Enter a valid number for --${e}`):{ok:!0,value:r};if(typeof r==`string`){let e=Number(r);if(!Number.isNaN(e))return{ok:!0,value:e}}return U(e,t,`TYPE_MISMATCH`,`number`,r,typeof r==`string`?`Invalid number value '${r}'`:`Invalid number value`,t.kind===`env`?`Set ${t.envVar} to a valid number`:t.kind===`config`?`Set ${t.configPath} to a valid number in your config`:`Enter a valid number for --${e}`);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 U(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`enum`:{let a=i.enumValues??[];return typeof r==`string`&&a.includes(r)?{ok:!0,value:r}:{ok:!1,error:new n(`Invalid value '${String(r)}' ${V(t)} for flag --${e}. Allowed: ${a.join(`, `)}`,{code:`INVALID_ENUM`,details:{flag:e,...H(t),value:r,allowed:a},suggest:t.kind===`env`?`Set ${t.envVar} to one of: ${a.join(`, `)}`:t.kind===`config`?`Set ${t.configPath} to one of: ${a.join(`, `)}`:`Select one of: ${a.join(`, `)}`})}}case`custom`:if(i.parseFn)try{return{ok:!0,value:i.parseFn(r)}}catch(i){let a=i instanceof Error?i.message:String(i);return{ok:!1,error:new n(`Failed to parse ${t.kind===`env`?`env ${t.envVar}`:t.kind===`config`?`config ${t.configPath}`:`prompt value`} for flag --${e}: ${a}`,{code:`TYPE_MISMATCH`,details:{flag:e,...H(t),value:r,expected:`custom`},suggest:t.kind===`env`?`Set ${t.envVar} to a valid value for --${e}`:t.kind===`config`?`Set ${t.configPath} to a valid value for --${e} in your config`:`Enter a valid value for --${e}`})}}return{ok:!0,value:r};case`array`:if(Array.isArray(r)){if(i.elementSchema){let n=[];for(let a of r){let r=W(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=W(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 U(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}`)}}function Fe(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}function Ie(e,t,r,i,a){let o={},s=[];for(let c of e){let{name:e,schema:l}=c,u=t[e];if(u!==void 0&&(!l.stdinMode||u!==`-`)&&!(l.variadic&&Array.isArray(u)&&u.length===0)){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=u;continue}if(l.stdinMode&&(u===void 0||u===`-`)&&r!=null){let t=q(e,{kind:`stdin`},r,l);if(t.ok){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=t.value;continue}s.push(t.error);continue}if(l.envVar!==void 0){let t=i[l.envVar];if(t!==void 0){let n=q(e,{kind:`env`,envVar:l.envVar},t,l);if(n.ok){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=n.value;continue}s.push(n.error);continue}}if(l.defaultValue!==void 0){o[e]=l.defaultValue;continue}if(l.variadic){if(l.presence===`required`){s.push(new n(`Missing required argument <${e}>`,{code:`REQUIRED_ARG`,details:{arg:e,variadic:!0},suggest:J(e,l,!0)}));continue}o[e]=[];continue}if(l.presence===`required`){s.push(new n(`Missing required argument <${e}>`,{code:`REQUIRED_ARG`,details:{arg:e},suggest:J(e,l)}));continue}o[e]=void 0}return Y(s)&&X(s),o}function G(e){return e.kind===`env`?`from env ${e.envVar}`:`from stdin`}function Le(e){return e.kind===`env`?{envVar:e.envVar}:{source:`stdin`}}function Re(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 ze(e){return e.kind===`env`?{kind:`env`,envVar:e.envVar}:{kind:`prompt`}}function Be(e){let t={presence:`optional`,defaultValue:void 0,aliases:[],envVar:void 0,configPath:void 0,description:e.description,prompt:void 0,deprecated:e.deprecated,propagate:!1,enumValues:void 0,elementSchema:void 0,parseFn:void 0};switch(e.kind){case`string`:return{...t,kind:`string`};case`number`:return{...t,kind:`number`};case`enum`:return{...t,kind:`enum`,enumValues:e.enumValues};case`custom`:{if(e.parseFn===void 0)return{...t,kind:`custom`,parseFn:void 0};let n=e.parseFn;return{...t,kind:`custom`,parseFn:e=>n(typeof e==`string`?e:String(e))}}default:return e.kind}}function Ve(e,t,n,r){switch(n.kind){case`number`:return`Invalid number value '<redacted>' ${G(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>' ${G(t)} for argument <${e}>. Allowed: ${n.join(`, `)}`}case`custom`:{let n=/: ([^:]+)$/.exec(r.message)?.[1];return n===void 0?`Invalid value '<redacted>' ${G(t)} for argument <${e}>`:`Invalid value '<redacted>' ${G(t)} for argument <${e}>: ${n}`}case`string`:return`Invalid value '<redacted>' ${G(t)} for argument <${e}>`;default:return n.kind}}function K(e,t,n,r){return{arg:e,...Le(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 He(e,t,n,r){if(n.kind===`number`||n.kind===`custom`)return Re(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 q(e,t,r,i){let a=W(e,ze(t),r,Be(i));if(a.ok)return a;let o=He(e,t,i,a.error),s=o===void 0?{code:a.error.code,details:K(e,t,i,a.error)}:{code:a.error.code,details:K(e,t,i,a.error),suggest:o};return{ok:!1,error:new n(Ve(e,t,i,a.error),s)}}function J(e,t,n){let r=[n?`Provide at least one value for <${e}>`:`Provide a value for <${e}>`];return t.stdinMode&&r.push(`pipe a value to stdin or pass '-'`),t.envVar!==void 0&&r.push(`set ${t.envVar}`),r.length===1?r[0]:r.length===2?`${r[0]} or ${r[1]}`:`${r.slice(0,-1).join(`, `)}, or ${r[r.length-1]}`}function Y(e){return e.length>0}function X(e){throw e.length===1?e[0]:new n(`Multiple validation errors:\n - ${e.map(e=>e.message).join(`
14
- - `)}`,{code:e[0].code,details:{errors:e.map(e=>e.toJSON()),count:e.length},suggest:`Fix all missing required values listed above`})}async function Z(t,n,r){let i,a;if(r?.out!==void 0)i=r.out,a=r.captured??{stdout:[],stderr:[],activity:[]};else{let e={...r?.verbosity===void 0?{}:{verbosity:r.verbosity},...r?.jsonMode===void 0?{}:{jsonMode:r.jsonMode},...r?.isTTY===void 0?{}:{isTTY:r.isTTY}};[i,a]=O(Object.keys(e).length>0?e:void 0)}let o=r?.mergedSchema??t.schema,s=r?.meta??{name:o.name,bin:r?.help?.binName??o.name,version:void 0,command:o.name};if(n.includes(`--help`)||n.includes(`-h`)){let e=g(o,r?.help);return i.log(e),$(0,a,void 0)}if(!t.handler){let n=new e(`Command '${t.schema.name}' has no action handler`,{code:`NO_ACTION`,suggest:`Add an .action() handler to the '${t.schema.name}' command`});return i.error(n.message),$(1,a,n)}try{await Ue(r?.plugins,{argv:n,command:o,meta:s,out:i});let e=P(o,n),c=r?.prompter??(r?.answers===void 0?void 0:L(r.answers)),l=await B(o,e,{...r?.stdinData===void 0?{}:{stdinData:r.stdinData},...r?.env===void 0?{}:{env:r.env},...r?.config===void 0?{}:{config:r.config},...c===void 0?{}:{prompter:c}}),u={args:l.args,flags:l.flags,deprecations:l.deprecations,command:o,meta:s,out:i};await Q(r?.plugins,`afterResolve`,u);for(let e of l.deprecations)i.warn(Ge(e));return await Q(r?.plugins,`beforeAction`,u),await We(t,l.flags,l.args,i,s),await Q(r?.plugins,`afterAction`,u),$(0,a,void 0)}catch(t){if(t instanceof e)return r?.jsonMode===!0?i.json({error:t.toJSON()}):(i.error(t.message),t.suggest!==void 0&&i.error(`Suggestion: ${t.suggest}`)),$(t.exitCode,a,t);let n=new e(`Unexpected error: ${t instanceof Error?t.message:String(t)}`,{code:`UNEXPECTED_ERROR`,cause:t});return r?.jsonMode===!0?i.json({error:n.toJSON()}):i.error(n.message),$(1,a,n)}finally{i.stopActive()}}async function Ue(e,t){if(e!==void 0)for(let n of e){let e=n.hooks.beforeParse;e!==void 0&&await e(t)}}async function Q(e,t,n){if(e!==void 0)for(let r of e){let e=r.hooks[t];e!==void 0&&await e(n)}}async function We(t,n,r,i,a){let o=t._executionSteps,s=t.handler;if(s===void 0)throw new e(`Command '${t.schema.name}' has no action handler`,{code:`NO_ACTION`,suggest:`Add an .action() handler to the '${t.schema.name}' command`});let c=async e=>{await s({flags:n,args:r,ctx:e,out:i,meta:a})};for(let t=o.length-1;t>=0;t--){let s=o[t];if(s===void 0)continue;let l=c;switch(s.kind){case`derive`:c=async t=>{let o=await s.handler({args:r,flags:n,ctx:t,out:i,meta:a});if(o===void 0){await l(t);return}if(typeof o!=`object`||!o||Array.isArray(o))throw new e(`derive() must return an object or undefined`,{code:`INVALID_BUILDER_STATE`,suggest:`Return an object to add context, or return nothing for validation-only derive handlers`});await l({...t,...o})};break;case`middleware`:c=async e=>{await s.handler({args:r,flags:n,ctx:e,out:i,meta:a,next:async t=>{await l({...e,...t})}})};break}}await c({})}function $(e,t,n){return{exitCode:e,stdout:t.stdout,stderr:t.stderr,activity:t.activity,error:n}}function Ge(e){let t=e.kind===`flag`?`flag --${e.name}`:`argument <${e.name}>`;return typeof e.message==`string`?`Warning: ${t} is deprecated: ${e.message}`:`Warning: ${t} is deprecated`}export{i as _,L as a,k as c,g as d,h as f,r as g,n as h,Oe as i,O as l,t as m,B as n,z as o,e as p,I as r,P as s,Z as t,Se as u,a as v};
@@ -1,14 +0,0 @@
1
- var e=class extends Error{name=`CLIError`;code;exitCode;suggest;details;constructor(e,t){super(e,t.cause===void 0?void 0:{cause:t.cause}),this.code=t.code,this.exitCode=t.exitCode??1,this.suggest=t.suggest,this.details=t.details}toJSON(){return{name:this.name,code:this.code,message:this.message,exitCode:this.exitCode,...this.suggest!==void 0&&{suggest:this.suggest},...this.details!==void 0&&{details:this.details}}}},t=class extends e{name=`ParseError`;constructor(e,t){super(e,{...t,exitCode:t.exitCode??2})}},n=class extends e{name=`ValidationError`;constructor(e,t){super(e,{...t,exitCode:t.exitCode??2})}};function r(t){return t instanceof e}function i(e){return e instanceof t}function a(e){return e instanceof n}function o(e){if(e==null)return``;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`||typeof e==`symbol`)return String(e);if(e instanceof Date)return Number.isNaN(e.getTime())?`Invalid Date`:e.toISOString();if(typeof e==`function`)return e.name.length>0?`[Function: ${e.name}]`:`[Function]`;try{return JSON.stringify(e)??`[unserializable]`}catch{return`[unserializable]`}}function s(e){return{width:e?.width??80,binName:e?.binName,isDefaultHelp:e?.isDefaultHelp??!1}}function c(e,t){return e.length>=t?e:e+` `.repeat(t-e.length)}function l(e,t,n){if(e.length+n<=t)return e;let r=t-n;if(r<=0)return e;let i=e.split(` `),a=[],o=``;for(let e of i)o.length===0?o=e:o.length+1+e.length<=r?o+=` ${e}`:(a.push(o),o=e);o.length>0&&a.push(o);let s=` `.repeat(n);return a.map((e,t)=>t===0?e:`${s}${e}`).join(`
2
- `)}function u(e){return typeof e==`string`?`[deprecated: ${e}]`:`[deprecated]`}function d(e){return e===void 0?`undefined`:e===null?`null`:o(e)}function ee(e,t){let n=[],r=t.aliases.find(e=>e.length===1);return r!==void 0&&n.push(`-${r},`),n.push(`--${e}`),t.kind!==`boolean`&&n.push(f(t)),n.join(` `)}function f(e){switch(e.kind){case`string`:return`<string>`;case`number`:return`<number>`;case`enum`:return`<${(e.enumValues??[]).join(`|`)}>`;case`array`:return`<${e.elementSchema===void 0?`value`:f(e.elementSchema).slice(1,-1)}>...`;case`boolean`:return``;case`custom`:return`<value>`}}function p(e){let t=[];return e.description!==void 0&&t.push(e.description),e.deprecated!==void 0&&t.push(u(e.deprecated)),e.envVar!==void 0&&t.push(`[env: ${e.envVar}]`),e.configPath!==void 0&&t.push(`[config: ${e.configPath}]`),e.prompt!==void 0&&t.push(`[prompt]`),e.presence===`required`?t.push(`[required]`):e.presence===`defaulted`&&e.kind!==`boolean`&&t.push(`(default: ${d(e.defaultValue)})`),t.join(` `)}function te(e){let t=Object.keys(e);if(t.length===0)return[];let n=[...t].sort((t,n)=>{let r=e[t],i=e[n];if(r===void 0||i===void 0)return 0;let a=r.aliases.some(e=>e.length===1),o=i.aliases.some(e=>e.length===1);return a&&!o?-1:!a&&o?1:t.localeCompare(n)}),r=[];for(let t of n){let n=e[t];n!==void 0&&r.push({left:ee(t,n),description:p(n)})}return r}function m(e){let{name:t,schema:n}=e,r=n.kind===`enum`&&n.enumValues!==void 0?n.enumValues.join(`|`):t,i=n.variadic?`...`:``;return n.presence===`required`?`<${r}>${i}`:`[${r}]${i}`}function ne(e){let t=[];return e.description!==void 0&&t.push(e.description),e.deprecated!==void 0&&t.push(u(e.deprecated)),e.envVar!==void 0&&t.push(`[env: ${e.envVar}]`),e.presence===`defaulted`&&t.push(`(default: ${d(e.defaultValue)})`),t.join(` `)}function h(e,t){let n=s(t),r=[];r.push(re(e,n)),e.description!==void 0&&r.push(e.description);let i=e.commands.filter(e=>!e.hidden);return i.length>0&&r.push(oe(i,n)),e.args.length>0&&r.push(ie(e.args,n)),Object.keys(e.flags).length>0&&r.push(ae(e.flags,n)),e.examples.length>0&&r.push(se(e.examples)),r}function g(e,t){return`${h(e,t).join(`
3
-
4
- `)}\n`}function re(e,t){let n=[`Usage:`],r=t.binName===void 0||t.isDefaultHelp&&t.binName===e.name?e.name:`${t.binName} ${e.name}`;n.push(r),e.commands.length>0&&n.push(`<command>`),Object.keys(e.flags).length>0&&n.push(`[flags]`);for(let t of e.args)n.push(m(t));return n.join(` `)}function ie(e,t){let n=[`Arguments:`],r=0,i=[];for(let t of e){let e=` ${m(t)}`,n=ne(t.schema);i.push({left:e,desc:n}),e.length>r&&(r=e.length)}let a=r+2;for(let{left:e,desc:r}of i)if(r.length===0)n.push(e);else{let i=c(e,a),o=l(r,t.width,a);n.push(`${i}${o}`)}return n.join(`
5
- `)}function ae(e,t){let n=[`Flags:`],r=te(e);if(r.length===0)return``;let i=0;for(let e of r){let t=` ${e.left}`;t.length>i&&(i=t.length)}let a=i+2;for(let e of r){let r=` ${e.left}`;if(e.description.length===0)n.push(r);else{let i=c(r,a),o=l(e.description,t.width,a);n.push(`${i}${o}`)}}return n.join(`
6
- `)}function oe(e,t){let n=[`Commands:`],r=0;for(let t of e)t.name.length>r&&(r=t.name.length);let i=2+r+2;for(let r of e){let e=` ${r.name}`,a=r.description??``;if(a.length===0)n.push(e);else{let r=c(e,i),o=l(a,t.width,i);n.push(`${r}${o}`)}}return n.join(`
7
- `)}function se(e){let t=[`Examples:`];for(let n of e)n.description===void 0?t.push(` $ ${n.command}`):(t.push(` ${n.description}:`),t.push(` $ ${n.command}`));return t.join(`
8
- `)}function _(e,t){e(`${t}\n`)}const ce={update(){},succeed(){},fail(){},stop(){},wrap(e){return e}},le={increment(){},update(){},done(){},fail(){}};var ue=class{stopped=!1;constructor(e,t){this.write=t,_(t,e)}update(e){}succeed(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}stop(){this.stopped||=!0}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},de=class{stopped=!1;constructor(e,t){this.write=t,e!==void 0&&_(t,e)}increment(e){}update(e){}done(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&_(this.write,e))}};const v=`\x1B[?25l`,y=`\x1B[?25h`,b=`\x1B[2K`,x=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];var S=class{stopped=!1;timer;frameIndex=0;text;constructor(e,t){this.write=t,this.text=e,t(v),this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%x.length,this.render()},80)}render(){let e=x[this.frameIndex]??x[0];this.write(`\r${b}${e} ${this.text}`)}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${b}${y}`)}update(e){this.stopped||(this.text=e,this.render())}succeed(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✗ ${e}`))}stop(){this.stopped||(this.stopped=!0,this.cleanup())}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},C=class{stopped=!1;timer;current=0;total;label;pulsePos=0;pulseDir=1;constructor(e,t){this.write=t,this.total=e.total,this.label=e.label??``,t(v),this.render(),this.total===void 0&&(this.timer=setInterval(()=>{this.advancePulse(),this.render()},80))}advancePulse(){this.pulsePos+=this.pulseDir,this.pulsePos+3>20?(this.pulseDir=-1,this.pulsePos=17):this.pulsePos<0&&(this.pulseDir=1,this.pulsePos=0)}render(){let e=this.total===void 0?this.renderIndeterminate():this.renderDeterminate(this.total),t=this.label.length>0?` ${this.label}`:``;this.write(`\r${b}${e}${t}`)}renderDeterminate(e){let t=e>0?Math.max(0,Math.min(this.current/e,1)):0,n=Math.round(t*20),r=20-n,i=Math.round(t*100);return`[${`█`.repeat(n)}${`░`.repeat(r)}] ${String(i)}%`}renderIndeterminate(){let e=``;for(let t=0;t<20;t++)e+=t>=this.pulsePos&&t<this.pulsePos+3?`█`:`░`;return`[${e}]`}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${b}${y}`)}increment(e){this.stopped||(this.current+=e??1,this.render())}update(e){this.stopped||(this.current=e,this.render())}done(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&_(this.write,`✗ ${e}`))}},fe=class{stopped=!1;constructor(e,t){this.events=t,t.push({type:`spinner:start`,text:e})}update(e){this.stopped||this.events.push({type:`spinner:update`,text:e})}succeed(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:succeed`,text:e??``}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:fail`,text:e??``}))}stop(){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:stop`}))}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},pe=class{stopped=!1;constructor(e,t){this.events=t,t.push({type:`progress:start`,label:e.label??``,total:e.total})}increment(e){this.stopped||this.events.push({type:`progress:increment`,delta:e??1})}update(e){this.stopped||this.events.push({type:`progress:update`,value:e})}done(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:done`,text:e}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:fail`,text:e}))}};const w=()=>{};function T(e){return{stdout:e?.stdout??w,stderr:e?.stderr??w,isTTY:e?.isTTY??!1,verbosity:e?.verbosity??`normal`,jsonMode:e?.jsonMode??!1}}var E=class{options;jsonMode;isTTY;constructor(e){this.options=e,this.jsonMode=e.jsonMode,this.isTTY=e.isTTY}log(e){_(this.options.jsonMode?this.options.stderr:this.options.stdout,e)}info(e){this.options.verbosity!==`quiet`&&_(this.options.jsonMode?this.options.stderr:this.options.stdout,e)}warn(e){_(this.options.stderr,e)}error(e){_(this.options.stderr,e)}json(e){_(this.options.stdout,JSON.stringify(e))}table(e,t,n){let{columns:r,options:i}=ge(t,n),a=ve(this.options.jsonMode,i),o=r??he(e);if(a===`json`){this.json(_e(e,o));return}let s=xe(e,o);s.length!==0&&_(ye(this.options,a,i),s)}activeCleanup;stopActive(){this.activeCleanup!==void 0&&(this.activeCleanup(),this.activeCleanup=void 0)}spinner(e,t){let n=t?.fallback??`silent`;if(this.options.jsonMode||!this.options.isTTY&&n===`silent`)return ce;if(this.stopActive(),this.options.isTTY){let t=new S(e,this.options.stderr);return this.activeCleanup=()=>t.stop(),t}let r=new ue(e,this.options.stderr);return this.activeCleanup=()=>r.stop(),r}progress(e){let t=e.fallback??`silent`;if(this.options.jsonMode||!this.options.isTTY&&t===`silent`)return le;if(this.stopActive(),this.options.isTTY){let t=new C(e,this.options.stderr);return this.activeCleanup=()=>t.done(),t}let n=new de(e.label,this.options.stderr);return this.activeCleanup=()=>n.done(),n}},me=class extends E{constructor(e,t){super(e),this.activity=t}spinner(e,t){return new fe(e,this.activity)}progress(e){return new pe(e,this.activity)}};function he(e){let t=e[0];return t===void 0?[]:Object.keys(t).map(e=>({key:e}))}function D(e){return Array.isArray(e)}function ge(e,t){return t===void 0?D(e)?{columns:e,options:t}:{columns:void 0,options:e}:{columns:D(e)?e:void 0,options:t}}function _e(e,t){return e.map(e=>Object.fromEntries(t.map(t=>[t.key,e[t.key]])))}function ve(e,t){switch(t?.format){case`json`:return`json`;case`text`:return`text`;case`auto`:case void 0:return e?`json`:`text`}}function ye(e,t,n){return t===`text`&&n!==void 0&&`stream`in n&&n.stream!==void 0?n.stream===`stderr`?e.stderr:e.stdout:e.jsonMode?e.stderr:e.stdout}function be(e){return o(e)}function xe(e,t){if(e.length===0||t.length===0)return``;let n=t.map(e=>e.header??e.key),r=e.map(e=>t.map(t=>be(e[t.key]))),i=n.map((e,t)=>{let n=e.length;for(let e of r){let r=e[t];r!==void 0&&r.length>n&&(n=r.length)}return n});return[n.map((e,t)=>e.padEnd(i[t]??0)).join(` `),i.map(e=>`-`.repeat(e)).join(` `),...r.map(e=>e.map((e,t)=>e.padEnd(i[t]??0)).join(` `))].join(`
9
- `)}function Se(e){return new E(T(e))}function O(e){let t={stdout:[],stderr:[],activity:[]};return[new me(T({...e,stdout:e=>t.stdout.push(e),stderr:e=>t.stderr.push(e)}),t.activity),t]}function k(e){let t=[],n=!1;for(let r of e){if(n){t.push({kind:`positional`,value:r});continue}if(r===`--`){t.push({kind:`separator`}),n=!0;continue}if(r.startsWith(`--`)){let e=r.indexOf(`=`);e===-1?t.push({kind:`long-flag`,name:r.slice(2),value:void 0}):t.push({kind:`long-flag`,name:r.slice(2,e),value:r.slice(e+1)});continue}if(r.startsWith(`-`)&&r.length>1){t.push({kind:`short-flags`,chars:r.slice(1)});continue}t.push({kind:`positional`,value:r})}return t}function A(e){let t=new Map;for(let[n,r]of Object.entries(e)){t.set(n,[n,r]);for(let e of r.aliases)t.set(e,[n,r])}return t}function j(e){return e.kind!==`boolean`}function M(e,n,r){switch(r.kind){case`string`:return n;case`number`:{let r=Number(n);if(Number.isNaN(r))throw new t(`Invalid number value '${n}' for flag --${e}`,{code:`INVALID_VALUE`,details:{flag:e,value:n,expected:`number`}});return r}case`boolean`:if(n===`true`||n===`1`)return!0;if(n===`false`||n===`0`)return!1;throw new t(`Invalid boolean value '${n}' for flag --${e}. Use true/false or 1/0`,{code:`INVALID_VALUE`,details:{flag:e,value:n,expected:`boolean`}});case`enum`:{let i=r.enumValues;if(i===void 0)throw new t(`Enum flag --${e} is misconfigured: no allowed values declared`,{code:`INVALID_SCHEMA`,details:{flag:e,kind:`enum`,missing:`enumValues`}});if(!i.includes(n))throw new t(`Invalid value '${n}' for flag --${e}. Allowed: ${i.join(`, `)}`,{code:`INVALID_VALUE`,details:{flag:e,value:n,allowed:i}});return n}case`array`:return r.elementSchema?M(e,n,r.elementSchema):n;case`custom`:if(!r.parseFn)return n;try{return r.parseFn(n)}catch(r){throw r instanceof t?r:new t(`Failed to parse flag --${e}: ${r instanceof Error?r.message:String(r)}`,{code:`INVALID_VALUE`,details:{flag:e,value:n},cause:r})}}}function N(e,n,r){switch(r.kind){case`string`:return n;case`number`:{let r=Number(n);if(Number.isNaN(r))throw new t(`Invalid number value '${n}' for argument <${e}>`,{code:`INVALID_VALUE`,details:{arg:e,value:n,expected:`number`}});return r}case`enum`:{let i=r.enumValues;if(i===void 0)throw new t(`Enum argument <${e}> is misconfigured: no allowed values declared`,{code:`INVALID_SCHEMA`,details:{arg:e,kind:`enum`,missing:`enumValues`}});if(!i.includes(n))throw new t(`Invalid value '${n}' for argument <${e}>. Allowed: ${i.join(`, `)}`,{code:`INVALID_VALUE`,details:{arg:e,value:n,allowed:i}});return n}case`custom`:if(!r.parseFn)return n;try{return r.parseFn(n)}catch(r){throw r instanceof t?r:new t(`Failed to parse argument <${e}>: ${r instanceof Error?r.message:String(r)}`,{code:`INVALID_VALUE`,details:{arg:e,value:n},cause:r})}}}function P(e,t){let n=k(t),r=A(e.flags),i={},a=[],o=0;for(;o<n.length;){let e=n[o];if(e===void 0)break;if(e.kind===`separator`){o++;continue}if(e.kind===`positional`){a.push(e.value),o++;continue}if(e.kind===`long-flag`){o=Ce(e,n,o,r,i);continue}o=we(e,n,o,r,i)}return{flags:i,args:Te(e.args,a)}}function Ce(e,n,r,i,a){let o=i.get(e.name);if(!o){let n=Ee(e.name,i);throw new t(`Unknown flag --${e.name}${n?`. Did you mean --${n}?`:``}`,{code:`UNKNOWN_FLAG`,details:{flag:e.name,...n?{suggestion:n}:{}},...n?{suggest:`--${n}`}:{}})}let[s,c]=o;if(!j(c))return e.value===void 0?a[s]=!0:a[s]=M(s,e.value,c),r+1;if(e.value!==void 0)return F(a,s,c,e.value),r+1;let l=n[r+1];if(!l||l.kind!==`positional`)throw new t(`Flag --${s} requires a value`,{code:`MISSING_VALUE`,details:{flag:s,kind:c.kind}});return F(a,s,c,l.value),r+2}function we(e,n,r,i,a){let{chars:o}=e,s=r+1;for(let e=0;e<o.length;e++){let r=o.charAt(e),c=i.get(r);if(!c)throw new t(`Unknown flag -${r}`,{code:`UNKNOWN_FLAG`,details:{flag:r}});let[l,u]=c;if(!j(u)){a[l]=!0;continue}if(e<o.length-1){F(a,l,u,o.slice(e+1));break}let d=n[s];if(!d||d.kind!==`positional`)throw new t(`Flag -${r} requires a value`,{code:`MISSING_VALUE`,details:{flag:r,canonical:l,kind:u.kind}});F(a,l,u,d.value),s++}return s}function F(e,t,n,r){let i=M(t,r,n);if(n.kind===`array`){let n=e[t];Array.isArray(n)?n.push(i):e[t]=[i]}else e[t]=i}function Te(e,n){let r={},i=0;for(let t of e){if(t.schema.variadic){let e=n.slice(i);r[t.name]=e.map(e=>N(t.name,e,t.schema)),i=n.length;break}let e=n[i];e!==void 0&&(r[t.name]=N(t.name,e,t.schema),i++)}if(i<n.length){let r=n.slice(i);throw new t(`Unexpected positional argument${r.length>1?`s`:``}: ${r.join(`, `)}`,{code:`UNEXPECTED_POSITIONAL`,details:{excess:r,expected:e.length}})}return r}function Ee(e,t){let n,r=1/0,i=Math.max(2,Math.floor(e.length/2));for(let a of t.keys()){if(a.length<2)continue;let t=De(e,a);t<r&&t<=i&&(r=t,n=a)}return n}function De(e,t){if(e===t)return 0;if(e.length===0)return t.length;if(t.length===0)return e.length;let n=e.length<=t.length?e:t,r=e.length<=t.length?t:e,i=n.length,a=r.length,o=Array.from({length:i+1},(e,t)=>t);for(let e=1;e<=a;e++){let t=o[0]??0;o[0]=e;for(let a=1;a<=i;a++){let i=n.charAt(a-1)===r.charAt(e-1)?0:1,s=Math.min((o[a]??0)+1,(o[a-1]??0)+1,t+i);t=o[a]??0,o[a]=s}}return o[i]??0}const I=Symbol.for(`dreamcli.prompt.cancel`);function L(e,t){let n=0;return{promptOne(){if(n>=e.length)return t?.onExhausted===`cancel`?Promise.resolve({answered:!1}):Promise.reject(Error(`Test prompter exhausted: expected at most ${e.length} prompts, got prompt #${n+1}`));let r=e[n];return n+=1,r===I?Promise.resolve({answered:!1}):Promise.resolve({answered:!0,value:r})}}}function Oe(e,t){return{promptOne(n){switch(n.kind){case`confirm`:return R(n,e,t);case`input`:return ke(n,e,t);case`select`:return Ae(n,e,t);case`multiselect`:return je(n,e,t)}}}}async function R(e,t,n){n(`${e.message} (y/n) `);let r=await t();if(r===null)return{answered:!1};let i=r.trim().toLowerCase();return i===``||i===`y`||i===`yes`?{answered:!0,value:!0}:i===`n`||i===`no`?{answered:!0,value:!1}:(n(`Please answer y or n.
10
- `),R(e,t,n))}async function ke(e,t,n){let r=0;for(;r<10;){let i=e.placeholder===void 0?``:` (${e.placeholder})`;n(`${e.message}${i}: `);let a=await t();if(a===null)return{answered:!1};let o=a.trim();if(e.validate!==void 0){let t=e.validate(o);if(t!==!0){n(`${t}\n`),r+=1;continue}}return{answered:!0,value:o}}return n(`Too many invalid attempts.
11
- `),{answered:!1}}async function Ae(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter number: `);let i=await t();if(i===null)return{answered:!1};let a=Number(i.trim());if(Number.isNaN(a)||!Number.isInteger(a)||a<1||a>e.choices.length){n(`Please enter a number between 1 and ${e.choices.length}.\n`),r+=1;continue}let o=e.choices[a-1];if(o===void 0){r+=1;continue}return{answered:!0,value:o.value}}return n(`Too many invalid attempts.
12
- `),{answered:!1}}async function je(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter numbers separated by commas (e.g. 1,3${e.min===void 0?``:`, min: ${e.min}`}${e.max===void 0?``:`, max: ${e.max}`}): `);let i=await t();if(i===null)return{answered:!1};let a=i.trim();if(a===``){if(e.min!==void 0&&e.min>0){n(`Please select at least ${e.min}.\n`),r+=1;continue}return{answered:!0,value:[]}}let o=a.split(`,`).map(e=>e.trim()),s=[],c=!0;for(let t of o){let r=Number(t);if(Number.isNaN(r)||!Number.isInteger(r)||r<1||r>e.choices.length){n(`Invalid selection '${t}'. Use numbers between 1 and ${e.choices.length}.\n`),c=!1;break}s.push(r)}if(!c){r+=1;continue}let l=[...new Set(s)];if(e.min!==void 0&&l.length<e.min){n(`Please select at least ${e.min}.\n`),r+=1;continue}if(e.max!==void 0&&l.length>e.max){n(`Please select at most ${e.max}.\n`),r+=1;continue}return{answered:!0,value:l.map(t=>e.choices[t-1]?.value??``)}}return n(`Too many invalid attempts.
13
- `),{answered:!1}}function z(e,t){if(e.kind===`confirm`||e.kind===`input`)return e;let n=e.choices??t?.map(e=>({value:e}))??[];if(n.length===0)throw Error(`Prompt config (${e.kind}) requires choices but none were provided and no enum values are available`);let r=n;return e.kind===`select`?{kind:`select`,message:e.message,choices:r}:{kind:`multiselect`,message:e.message,choices:r,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max}}}async function B(e,t,n){let r=n?.stdinData,i=n?.env??{},a=n?.config??{},o=n?.prompter,s=[];return{flags:await Me(e.flags,t.flags,i,a,o,e.interactive,s),args:Ie(e.args,t.args,r,i,s),deprecations:s}}async function Me(e,t,r,i,a,o,s){let c={},l=[],u=new Set;for(let[n,a]of Object.entries(e)){let e=t[n];if(e!==void 0){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=e;continue}if(a.envVar!==void 0){let e=r[a.envVar];if(e!==void 0){let t=W(n,{kind:`env`,envVar:a.envVar},e,a);if(t.ok){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=t.value;continue}l.push(t.error),u.add(n);continue}}if(a.configPath!==void 0){let e=Fe(i,a.configPath);if(e!==void 0){let t=W(n,{kind:`config`,configPath:a.configPath},e,a);if(t.ok){a.deprecated!==void 0&&s.push({kind:`flag`,name:n,message:a.deprecated}),c[n]=t.value;continue}l.push(t.error),u.add(n)}}}let d=o===void 0?void 0:o({flags:c});for(let[t,r]of Object.entries(e)){if(t in c||u.has(t))continue;let e=d?.[t],i;if(i=e!=null&&e!==!1&&e!==0&&e!==``?e:e===!1?void 0:r.prompt,i!==void 0&&a!==void 0){let e=await Ne(t,r,i,a);if(e.ok){r.deprecated!==void 0&&s.push({kind:`flag`,name:t,message:r.deprecated}),c[t]=e.value;continue}if(e.error!==void 0){l.push(e.error);continue}}if(r.defaultValue!==void 0){c[t]=r.defaultValue;continue}if(r.kind===`array`&&r.presence!==`required`){c[t]=[];continue}if(r.presence===`required`){let e={flag:t,kind:r.kind};r.envVar!==void 0&&(e.envVar=r.envVar),r.configPath!==void 0&&(e.configPath=r.configPath),l.push(new n(`Missing required flag --${t}`,{code:`REQUIRED_FLAG`,details:e,suggest:Pe(t,r)}));continue}c[t]=void 0}return Y(l)&&X(l),c}async function Ne(e,t,n,r){let i=z(n,t.enumValues),a=await r.promptOne(i);return a.answered?W(e,{kind:`prompt`},a.value,t):{ok:!1,error:void 0}}function Pe(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}`}function V(e){switch(e.kind){case`env`:return`from env ${e.envVar}`;case`config`:return`from config ${e.configPath}`;case`prompt`:return`from prompt`}}function H(e){switch(e.kind){case`env`:return{envVar:e.envVar};case`config`:return{configPath:e.configPath};case`prompt`:return{source:`prompt`}}}function U(e,t,r,i,a,o,s,c){return{ok:!1,error:new n(`${o} ${V(t)} for flag --${e}`,{code:r,details:{flag:e,...H(t),value:a,expected:i,...c},suggest:s})}}function W(e,t,r,i){switch(i.kind){case`string`:return typeof r==`string`?{ok:!0,value:r}:t.kind===`prompt`||t.kind===`config`&&(typeof r==`number`||typeof r==`boolean`)?{ok:!0,value:String(r)}:U(e,t,`TYPE_MISMATCH`,`string`,r,`Invalid string value`,t.kind===`config`?`Set ${t.configPath} to a string in your config`:`Enter a valid string for --${e}`);case`number`:if(typeof r==`number`)return Number.isNaN(r)?U(e,t,`TYPE_MISMATCH`,`number`,r,`Invalid number value NaN`,t.kind===`env`?`Set ${t.envVar} to a valid number`:t.kind===`config`?`Set ${t.configPath} to a valid number in your config`:`Enter a valid number for --${e}`):{ok:!0,value:r};if(typeof r==`string`){let e=Number(r);if(!Number.isNaN(e))return{ok:!0,value:e}}return U(e,t,`TYPE_MISMATCH`,`number`,r,typeof r==`string`?`Invalid number value '${r}'`:`Invalid number value`,t.kind===`env`?`Set ${t.envVar} to a valid number`:t.kind===`config`?`Set ${t.configPath} to a valid number in your config`:`Enter a valid number for --${e}`);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 U(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`enum`:{let a=i.enumValues??[];return typeof r==`string`&&a.includes(r)?{ok:!0,value:r}:{ok:!1,error:new n(`Invalid value '${String(r)}' ${V(t)} for flag --${e}. Allowed: ${a.join(`, `)}`,{code:`INVALID_ENUM`,details:{flag:e,...H(t),value:r,allowed:a},suggest:t.kind===`env`?`Set ${t.envVar} to one of: ${a.join(`, `)}`:t.kind===`config`?`Set ${t.configPath} to one of: ${a.join(`, `)}`:`Select one of: ${a.join(`, `)}`})}}case`custom`:if(i.parseFn)try{return{ok:!0,value:i.parseFn(r)}}catch(i){let a=i instanceof Error?i.message:String(i);return{ok:!1,error:new n(`Failed to parse ${t.kind===`env`?`env ${t.envVar}`:t.kind===`config`?`config ${t.configPath}`:`prompt value`} for flag --${e}: ${a}`,{code:`TYPE_MISMATCH`,details:{flag:e,...H(t),value:r,expected:`custom`},suggest:t.kind===`env`?`Set ${t.envVar} to a valid value for --${e}`:t.kind===`config`?`Set ${t.configPath} to a valid value for --${e} in your config`:`Enter a valid value for --${e}`})}}return{ok:!0,value:r};case`array`:if(Array.isArray(r)){if(i.elementSchema){let n=[];for(let a of r){let r=W(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=W(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 U(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}`)}}function Fe(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}function Ie(e,t,r,i,a){let o={},s=[];for(let c of e){let{name:e,schema:l}=c,u=t[e];if(u!==void 0&&(!l.stdinMode||u!==`-`)&&!(l.variadic&&Array.isArray(u)&&u.length===0)){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=u;continue}if(l.stdinMode&&(u===void 0||u===`-`)&&r!=null){let t=q(e,{kind:`stdin`},r,l);if(t.ok){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=t.value;continue}s.push(t.error);continue}if(l.envVar!==void 0){let t=i[l.envVar];if(t!==void 0){let n=q(e,{kind:`env`,envVar:l.envVar},t,l);if(n.ok){l.deprecated!==void 0&&a.push({kind:`arg`,name:e,message:l.deprecated}),o[e]=n.value;continue}s.push(n.error);continue}}if(l.defaultValue!==void 0){o[e]=l.defaultValue;continue}if(l.variadic){if(l.presence===`required`){s.push(new n(`Missing required argument <${e}>`,{code:`REQUIRED_ARG`,details:{arg:e,variadic:!0},suggest:J(e,l,!0)}));continue}o[e]=[];continue}if(l.presence===`required`){s.push(new n(`Missing required argument <${e}>`,{code:`REQUIRED_ARG`,details:{arg:e},suggest:J(e,l)}));continue}o[e]=void 0}return Y(s)&&X(s),o}function G(e){return e.kind===`env`?`from env ${e.envVar}`:`from stdin`}function Le(e){return e.kind===`env`?{envVar:e.envVar}:{source:`stdin`}}function Re(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 ze(e){return e.kind===`env`?{kind:`env`,envVar:e.envVar}:{kind:`prompt`}}function Be(e){let t={presence:`optional`,defaultValue:void 0,aliases:[],envVar:void 0,configPath:void 0,description:e.description,prompt:void 0,deprecated:e.deprecated,propagate:!1,enumValues:void 0,elementSchema:void 0,parseFn:void 0};switch(e.kind){case`string`:return{...t,kind:`string`};case`number`:return{...t,kind:`number`};case`enum`:return{...t,kind:`enum`,enumValues:e.enumValues};case`custom`:{if(e.parseFn===void 0)return{...t,kind:`custom`,parseFn:void 0};let n=e.parseFn;return{...t,kind:`custom`,parseFn:e=>n(typeof e==`string`?e:String(e))}}default:return e.kind}}function Ve(e,t,n,r){switch(n.kind){case`number`:return`Invalid number value '<redacted>' ${G(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>' ${G(t)} for argument <${e}>. Allowed: ${n.join(`, `)}`}case`custom`:{let n=/: ([^:]+)$/.exec(r.message)?.[1];return n===void 0?`Invalid value '<redacted>' ${G(t)} for argument <${e}>`:`Invalid value '<redacted>' ${G(t)} for argument <${e}>: ${n}`}case`string`:return`Invalid value '<redacted>' ${G(t)} for argument <${e}>`;default:return n.kind}}function K(e,t,n,r){return{arg:e,...Le(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 He(e,t,n,r){if(n.kind===`number`||n.kind===`custom`)return Re(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 q(e,t,r,i){let a=W(e,ze(t),r,Be(i));if(a.ok)return a;let o=He(e,t,i,a.error),s=o===void 0?{code:a.error.code,details:K(e,t,i,a.error)}:{code:a.error.code,details:K(e,t,i,a.error),suggest:o};return{ok:!1,error:new n(Ve(e,t,i,a.error),s)}}function J(e,t,n){let r=[n?`Provide at least one value for <${e}>`:`Provide a value for <${e}>`];return t.stdinMode&&r.push(`pipe a value to stdin or pass '-'`),t.envVar!==void 0&&r.push(`set ${t.envVar}`),r.length===1?r[0]:r.length===2?`${r[0]} or ${r[1]}`:`${r.slice(0,-1).join(`, `)}, or ${r[r.length-1]}`}function Y(e){return e.length>0}function X(e){throw e.length===1?e[0]:new n(`Multiple validation errors:\n - ${e.map(e=>e.message).join(`
14
- - `)}`,{code:e[0].code,details:{errors:e.map(e=>e.toJSON()),count:e.length},suggest:`Fix all missing required values listed above`})}async function Z(t,n,r){let i,a;if(r?.out!==void 0)i=r.out,a=r.captured??{stdout:[],stderr:[],activity:[]};else{let e={...r?.verbosity===void 0?{}:{verbosity:r.verbosity},...r?.jsonMode===void 0?{}:{jsonMode:r.jsonMode},...r?.isTTY===void 0?{}:{isTTY:r.isTTY}};[i,a]=O(Object.keys(e).length>0?e:void 0)}let o=r?.mergedSchema??t.schema,s=r?.meta??{name:o.name,bin:r?.help?.binName??o.name,version:void 0,command:o.name};if(n.includes(`--help`)||n.includes(`-h`)){let e=g(o,r?.help);return i.log(e),$(0,a,void 0)}if(!t.handler){let n=new e(`Command '${t.schema.name}' has no action handler`,{code:`NO_ACTION`,suggest:`Add an .action() handler to the '${t.schema.name}' command`});return i.error(n.message),$(1,a,n)}try{await Ue(r?.plugins,{argv:n,command:o,meta:s,out:i});let e=P(o,n),c=r?.prompter??(r?.answers===void 0?void 0:L(r.answers)),l=await B(o,e,{...r?.stdinData===void 0?{}:{stdinData:r.stdinData},...r?.env===void 0?{}:{env:r.env},...r?.config===void 0?{}:{config:r.config},...c===void 0?{}:{prompter:c}}),u={args:l.args,flags:l.flags,deprecations:l.deprecations,command:o,meta:s,out:i};await Q(r?.plugins,`afterResolve`,u);for(let e of l.deprecations)i.warn(Ge(e));return await Q(r?.plugins,`beforeAction`,u),await We(t,l.flags,l.args,i,s),await Q(r?.plugins,`afterAction`,u),$(0,a,void 0)}catch(t){if(t instanceof e)return r?.jsonMode===!0?i.json({error:t.toJSON()}):(i.error(t.message),t.suggest!==void 0&&i.error(`Suggestion: ${t.suggest}`)),$(t.exitCode,a,t);let n=new e(`Unexpected error: ${t instanceof Error?t.message:String(t)}`,{code:`UNEXPECTED_ERROR`,cause:t});return r?.jsonMode===!0?i.json({error:n.toJSON()}):i.error(n.message),$(1,a,n)}finally{i.stopActive()}}async function Ue(e,t){if(e!==void 0)for(let n of e){let e=n.hooks.beforeParse;e!==void 0&&await e(t)}}async function Q(e,t,n){if(e!==void 0)for(let r of e){let e=r.hooks[t];e!==void 0&&await e(n)}}async function We(t,n,r,i,a){let o=t._executionSteps,s=t.handler;if(s===void 0)throw new e(`Command '${t.schema.name}' has no action handler`,{code:`NO_ACTION`,suggest:`Add an .action() handler to the '${t.schema.name}' command`});let c=async e=>{await s({flags:n,args:r,ctx:e,out:i,meta:a})};for(let t=o.length-1;t>=0;t--){let s=o[t];if(s===void 0)continue;let l=c;switch(s.kind){case`derive`:c=async t=>{let o=await s.handler({args:r,flags:n,ctx:t,out:i,meta:a});if(o===void 0){await l(t);return}if(typeof o!=`object`||!o||Array.isArray(o))throw new e(`derive() must return an object or undefined`,{code:`INVALID_BUILDER_STATE`,suggest:`Return an object to add context, or return nothing for validation-only derive handlers`});await l({...t,...o})};break;case`middleware`:c=async e=>{await s.handler({args:r,flags:n,ctx:e,out:i,meta:a,next:async t=>{await l({...e,...t})}})};break}}await c({})}function $(e,t,n){return{exitCode:e,stdout:t.stdout,stderr:t.stderr,activity:t.activity,error:n}}function Ge(e){let t=e.kind===`flag`?`flag --${e.name}`:`argument <${e.name}>`;return typeof e.message==`string`?`Warning: ${t} is deprecated: ${e.message}`:`Warning: ${t} is deprecated`}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return a}});
package/dist/testkit.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./testkit-ClIKijxC.cjs`),t=require(`./adapter-CCSh5juX.cjs`);exports.PROMPT_CANCEL=e.r,exports.createCaptureOutput=e.l,exports.createTestAdapter=t.n,exports.createTestPrompter=e.a,exports.runCommand=e.t;
@@ -1,25 +0,0 @@
1
- import { C as RunOptions, St as FlagConfig, Ut as ArgBuilder, Wt as ArgConfig, X as PROMPT_CANCEL, at as createTestPrompter, i as createTestAdapter, l as CommandBuilder, nt as TestAnswer, r as TestAdapterOptions, rt as TestPrompterOptions, st as CapturedOutput, ut as createCaptureOutput, w as RunResult, xt as FlagBuilder } from "./adapter-DQnxxLiE.cjs";
2
-
3
- //#region src/core/testkit/index.d.ts
4
- /**
5
- * Run a command builder against the given argv with injected options.
6
- *
7
- * This is the core execution pipeline:
8
- * 1. Detect `--help` / `-h` → print help text, exit 0
9
- * 2. Parse argv against the command schema
10
- * 3. Resolve values (CLI → env → config → default)
11
- * 4. Create a capture output channel
12
- * 5. Run derive/middleware/action execution steps
13
- * 6. Return structured result
14
- *
15
- * All errors are caught and converted to structured `RunResult`s with
16
- * appropriate exit codes. The function never throws.
17
- *
18
- * @param cmd - The command builder (must have an action handler)
19
- * @param argv - Raw argv strings (NOT including the command name itself)
20
- * @param options - Injectable runtime state
21
- * @returns Structured run result with exit code and captured output
22
- */
23
- declare function runCommand<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown> = Record<string, never>>(cmd: CommandBuilder<F, A, C>, argv: readonly string[], options?: RunOptions): Promise<RunResult>;
24
- //#endregion
25
- export { type CapturedOutput, PROMPT_CANCEL, type RunOptions, type RunResult, type TestAdapterOptions, type TestAnswer, type TestPrompterOptions, createCaptureOutput, createTestAdapter, createTestPrompter, runCommand };
@@ -1,37 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Environment setup & latest features
4
- "lib": ["ESNext"],
5
- "target": "ESNext",
6
- "module": "Preserve",
7
- "moduleDetection": "force",
8
- "allowJs": true,
9
-
10
- // Bundler mode
11
- "moduleResolution": "bundler",
12
- "allowImportingTsExtensions": true,
13
- "verbatimModuleSyntax": true,
14
- "noEmit": true,
15
-
16
- // Best practices
17
- "strict": true,
18
- "skipLibCheck": true,
19
- "noFallthroughCasesInSwitch": true,
20
- "noUncheckedIndexedAccess": true,
21
- "noImplicitOverride": true,
22
-
23
- // Some stricter flags (disabled by default)
24
- "noUnusedLocals": true,
25
- "noUnusedParameters": true,
26
- "noPropertyAccessFromIndexSignature": false,
27
-
28
- "composite": true,
29
-
30
- "types": ["bun"],
31
- "rootDir": ".",
32
- "paths": {
33
- "$gh": ["./src/main.ts"],
34
- "$gh/*": ["./src/*"]
35
- }
36
- }
37
- }
@@ -1,17 +0,0 @@
1
- {
2
- "extends": ["../tsconfig.json"],
3
- "compilerOptions": {
4
- "composite": true,
5
- "noEmit": false,
6
- "declaration": true,
7
- "emitDeclarationOnly": true,
8
- "outDir": ".cache",
9
- "declarationDir": ".cache/declarations",
10
- "paths": {
11
- "dreamcli": ["../src/index.ts"],
12
- "dreamcli/testkit": ["../src/testkit.ts"],
13
- "dreamcli/runtime": ["../src/runtime.ts"]
14
- }
15
- },
16
- "exclude": ["**/dist", "**/node_modules", "**/.cache", "gh"]
17
- }
@@ -1,72 +0,0 @@
1
- # cli — CLIBuilder, multi-command dispatch
2
-
3
- `index.ts` (~793 lines) — partially split: `dispatch.ts` + `propagate.ts` + `root-help.ts` extracted
4
- as `@internal`.
5
-
6
- ## KEY TYPES
7
-
8
- | Symbol | Role |
9
- | ------------------ | ----------------------------------------------------------- |
10
- | `CLIBuilder` | Fluent builder: `.command()`, `.default()`, `.execute()` |
11
- | `cli(name)` | Factory function → `CLIBuilder` |
12
- | `CLISchema` | Runtime descriptor for the full CLI |
13
- | `CLIRunOptions` | Extends `RunOptions` with CLI-level settings |
14
- | `ConfigSettings` | Config file discovery settings for CLI |
15
- | `ErasedCommand` | `@internal` — type-erased command for dispatch map |
16
- | `formatRootHelp()` | `@internal` — root-level help rendering (in `root-help.ts`) |
17
-
18
- ## FILES
19
-
20
- | File | Lines | Purpose |
21
- | -------------- | ----: | --------------------------------------------------------------------------- |
22
- | `index.ts` | 793 | CLIBuilder class + cli() factory + JSON error handling |
23
- | `root-help.ts` | 133 | `@internal` — root-level help text + text helpers, structural CLISchemaLike |
24
- | `dispatch.ts` | 285 | `@internal` — command dispatch, nested resolution, levenshtein |
25
- | `propagate.ts` | 87 | `@internal` — flag propagation through command tree |
26
-
27
- ## DISPATCH FLOW
28
-
29
- ```
30
- argv → strip --json flag → match subcommand (nested) → resolve → middleware → action → output
31
- ↓ (no match)
32
- → error (unknown command / no action) → render as JSON if --json
33
- ```
34
-
35
- Nested dispatch: `group('db').command(migrate).command(seed)` → `mycli db migrate --force`
36
-
37
- ## `execute()` METHOD (~145 lines)
38
-
39
- Handles 6 concerns sequentially: `--json` extraction, `--version`, `--help`, no-commands error,
40
- command map building, 3-way dispatch result (`unknown` / `needs-subcommand` / `match`).
41
-
42
- ## `--json` MODE
43
-
44
- - Stripped from argv before command dispatch
45
- - CLI-level errors rendered as JSON when active
46
- - Propagated to `OutputChannel` via `jsonMode` option
47
- - `out.log`/`out.info` redirect to stderr in JSON mode (stdout reserved for data)
48
-
49
- ## GOTCHAS
50
-
51
- - `root-help.ts` uses structural `CLISchemaLike` instead of importing `CLISchema` — avoids circular
52
- dep through barrel
53
- - `levenshtein()` in `dispatch.ts` uses `Uint16Array` rolling buffer — different impl from `parse/`
54
- - `uniqueCommands()` deduplicates via `Set` on command name — `@internal`
55
- - `extractConfigFlag()` handles both `--config path` and `--config=path` forms
56
- - Direct imports: `schema/command.ts`, `schema/flag.ts`, `schema/arg.ts` (not through barrel)
57
- - Cross-layer imports: `runtime/adapter.ts`, `runtime/auto.ts` (not through runtime barrel)
58
-
59
- ## TEST FILES (10)
60
-
61
- | File | Tests |
62
- | ---------------------------- | --------------------------------------- |
63
- | `cli.test.ts` | Core dispatch, help, errors, version |
64
- | `cli-json.test.ts` | JSON mode output + error rendering |
65
- | `cli-tty.test.ts` | TTY detection propagation |
66
- | `cli-middleware.test.ts` | Middleware wiring through CLI |
67
- | `cli-dispatch.test.ts` | Subcommand dispatch, default commands |
68
- | `cli-nesting.test.ts` | Nested command groups, deep dispatch |
69
- | `cli-completions.test.ts` | Completion integration in CLI context |
70
- | `cli-completion-e2e.test.ts` | End-to-end completion script generation |
71
- | `cli-config.test.ts` | Config discovery integration |
72
- | `cli-propagate.test.ts` | Flag propagation through command tree |