@kjanat/dreamcli 0.0.0 → 2.0.0

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 (205) hide show
  1. package/CHANGELOG.md +706 -0
  2. package/LICENSE +22 -0
  3. package/README.md +502 -0
  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 -0
  96. package/dist/index.mjs +1 -0
  97. package/dist/runtime/adapter.d.mts +212 -0
  98. package/dist/runtime/adapter.mjs +1 -0
  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 +7 -0
  115. package/dist/runtime.mjs +1 -0
  116. package/dist/testkit.d.mts +6 -0
  117. package/dist/testkit.mjs +1 -0
  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 +33 -0
  122. package/examples/gh/package.json +44 -0
  123. package/examples/gh/src/commands/auth.ts +66 -0
  124. package/examples/gh/src/commands/issue.ts +120 -0
  125. package/examples/gh/src/commands/pr.ts +125 -0
  126. package/examples/gh/src/data/issues.yaml +5 -0
  127. package/examples/gh/src/data/issues.yaml.d.ts +17 -0
  128. package/examples/gh/src/data/pull-requests.yaml +7 -0
  129. package/examples/gh/src/data/pull-requests.yaml.d.ts +18 -0
  130. package/examples/gh/src/docs.ts +11 -0
  131. package/examples/gh/src/lib/auth.ts +37 -0
  132. package/examples/gh/src/lib/utils.ts +17 -0
  133. package/examples/gh/src/main.test.ts +307 -0
  134. package/examples/gh/src/main.ts +40 -0
  135. package/examples/interactive.ts +66 -0
  136. package/examples/json-mode.ts +91 -0
  137. package/examples/middleware.ts +71 -0
  138. package/examples/multi-command.ts +66 -0
  139. package/examples/spinner-progress.ts +49 -0
  140. package/examples/testing.ts +147 -0
  141. package/package.json +149 -2
  142. package/src/core/cli/dispatch.ts +286 -0
  143. package/src/core/cli/index.ts +978 -0
  144. package/src/core/cli/planner.ts +413 -0
  145. package/src/core/cli/plugin.ts +117 -0
  146. package/src/core/cli/propagate.ts +97 -0
  147. package/src/core/cli/root-help.ts +269 -0
  148. package/src/core/cli/root-surface.ts +74 -0
  149. package/src/core/cli/runtime-preflight.ts +409 -0
  150. package/src/core/completion/index.ts +88 -0
  151. package/src/core/completion/shells/bash.ts +459 -0
  152. package/src/core/completion/shells/fish.ts +259 -0
  153. package/src/core/completion/shells/powershell.ts +405 -0
  154. package/src/core/completion/shells/shared.ts +283 -0
  155. package/src/core/completion/shells/zsh.ts +381 -0
  156. package/src/core/config/index.ts +407 -0
  157. package/src/core/config/package-json.ts +220 -0
  158. package/src/core/errors/index.ts +193 -0
  159. package/src/core/execution/index.ts +270 -0
  160. package/src/core/help/index.ts +557 -0
  161. package/src/core/json-schema/index.ts +891 -0
  162. package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
  163. package/src/core/output/activity.ts +568 -0
  164. package/src/core/output/contracts.ts +194 -0
  165. package/src/core/output/display-value.ts +48 -0
  166. package/src/core/output/index.ts +669 -0
  167. package/src/core/output/renderers.ts +125 -0
  168. package/src/core/output/writer.ts +46 -0
  169. package/src/core/parse/index.ts +661 -0
  170. package/src/core/prompt/index.ts +583 -0
  171. package/src/core/resolve/args.ts +144 -0
  172. package/src/core/resolve/coerce.ts +432 -0
  173. package/src/core/resolve/config.ts +26 -0
  174. package/src/core/resolve/contracts.ts +135 -0
  175. package/src/core/resolve/errors.ts +227 -0
  176. package/src/core/resolve/flags.ts +205 -0
  177. package/src/core/resolve/index.ts +108 -0
  178. package/src/core/resolve/property.ts +99 -0
  179. package/src/core/schema/activity.ts +240 -0
  180. package/src/core/schema/arg.ts +719 -0
  181. package/src/core/schema/command.ts +1490 -0
  182. package/src/core/schema/flag.ts +756 -0
  183. package/src/core/schema/index.ts +91 -0
  184. package/src/core/schema/middleware.ts +171 -0
  185. package/src/core/schema/prompt.ts +156 -0
  186. package/src/core/schema/run.ts +195 -0
  187. package/src/core/schema-dsl/index.ts +109 -0
  188. package/src/core/schema-dsl/parse.ts +262 -0
  189. package/src/core/schema-dsl/runtime.ts +609 -0
  190. package/src/core/schema-dsl/to-json-schema.ts +102 -0
  191. package/src/core/testkit/index.ts +123 -0
  192. package/src/index.ts +170 -0
  193. package/src/runtime/adapter.ts +303 -0
  194. package/src/runtime/auto.ts +110 -0
  195. package/src/runtime/bun.ts +55 -0
  196. package/src/runtime/deno.ts +369 -0
  197. package/src/runtime/detect.ts +105 -0
  198. package/src/runtime/index.ts +21 -0
  199. package/src/runtime/node-builtins.d.ts +23 -0
  200. package/src/runtime/node.ts +300 -0
  201. package/src/runtime/paths.ts +62 -0
  202. package/src/runtime/support.ts +135 -0
  203. package/src/runtime.ts +31 -0
  204. package/src/testkit.ts +25 -0
  205. package/src/version.ts +20 -0
@@ -0,0 +1 @@
1
+ import{CLIError as e}from"../errors/index.mjs";function t(t,n,r){if(n.stdinMode&&n.variadic)throw new e(`Argument <${t}> cannot be both variadic and stdin-backed`,{code:`INVALID_BUILDER_STATE`,details:{arg:t,stdinMode:!0,variadic:!0},suggest:`Remove .stdin() or .variadic() from this argument`});if(!n.stdinMode)return;let i=r.find(e=>e.schema.stdinMode);if(i!==void 0)throw new e(`Only one stdin argument is allowed; <${i.name}> is already stdin-backed`,{code:`DUPLICATE_STDIN_ARG`,details:{arg:t,existingArg:i.name},suggest:`Keep .stdin() on a single argument per command`})}function n(e,t){return t===`alias`&&e.length===1?`-${e}`:`--${e}`}function r(e){if(e.kind===`canonical`)return`canonical flag ${n(e.name,e.kind)}`;let t=e.name.length===1?`short alias`:`long alias`;return`${e.hidden?`hidden `:``}${t} ${n(e.name,e.kind)}`}function i(e,t){return[{owner:e,name:e,kind:`canonical`,hidden:!1},...t.aliases.map(t=>({owner:e,name:t.name,kind:`alias`,hidden:t.hidden}))]}function a(t,i,a,o){let s=o?.inherited??!1,c=`flag ${n(a.owner,`canonical`)}`,l=`Command '${t}' ${c}`;throw new e(s?`${l} propagates ${r(a)}, which collides with ${r(i)} on flag ${n(i.owner,`canonical`)}`:`Command '${t}' flag ${n(i.owner,`canonical`)} ${r(i)} collides with ${r(a)} on ${c}`,{code:s?`PROPAGATED_FLAG_COLLISION`:`FLAG_NAME_COLLISION`,details:{command:t,flag:i.owner,surface:i.name,surfaceKind:i.kind,hidden:i.hidden,existingFlag:a.owner,existingSurface:a.name,existingSurfaceKind:a.kind,existingHidden:a.hidden,inherited:s}})}function o(e,t){let n=new Map;for(let[r,o]of Object.entries(t))for(let t of i(r,o)){let r=n.get(t.name);r!==void 0&&a(e,t,r),n.set(t.name,t)}}function s(e,t,n){let r=new Map;for(let[e,n]of Object.entries(t))for(let t of i(e,n))r.set(t.name,t);for(let[t,o]of Object.entries(n))for(let n of i(t,o)){let t=r.get(n.name);t!==void 0&&a(e,n,t,{inherited:!0})}}function c(e,t){let n={...e};for(let e of Object.keys(t))delete n[e];for(let[e,r]of Object.entries(t))r.propagate&&(n[e]=r);return n}function l(e,t={}){o(e.name,e.flags);let n={...t};for(let t of Object.keys(e.flags))delete n[t];s(e.name,n,e.flags);let r=c(t,e.flags);for(let t of e.commands)l(t,r)}function u(e){return e}var d=class n{schema;handler;_subcommands;_executionSteps;constructor(e,t,n,r){this.schema=e,this.handler=t,this._subcommands=n??[],this._executionSteps=r??[]}interactive(e){let t=e;return new n({...this.schema,interactive:t},this.handler,this._subcommands,this._executionSteps)}derive(e){let t=e;return new n({...this.schema,hasAction:!1},void 0,this._subcommands,[...this._executionSteps,{kind:`derive`,handler:t}])}middleware(e){return new n({...this.schema,middleware:[...this.schema.middleware,e._handler],hasAction:!1},void 0,this._subcommands,[...this._executionSteps,{kind:`middleware`,handler:e._handler}])}description(e){return new n({...this.schema,description:e},this.handler,this._subcommands,this._executionSteps)}alias(e){return new n({...this.schema,aliases:[...this.schema.aliases,e]},this.handler,this._subcommands,this._executionSteps)}hidden(){return new n({...this.schema,hidden:!0},this.handler,this._subcommands,this._executionSteps)}example(e,t){let r=t===void 0?{command:e}:{command:e,description:t};return new n({...this.schema,examples:[...this.schema.examples,r]},this.handler,this._subcommands,this._executionSteps)}flag(t,r){if(t in this.schema.flags)throw new e(`Command '${this.schema.name}' already defines flag --${t}`,{code:`FLAG_NAME_COLLISION`,details:{command:this.schema.name,flag:t,surface:t,surfaceKind:`canonical`}});let i={...this.schema.flags,[t]:r.schema},a={...this.schema,flags:i,hasAction:!1};return l(a),new n(a,void 0,this._subcommands,this._executionSteps)}arg(e,r){t(e,r.schema,this.schema.args);let i={name:e,schema:r.schema},a=[...this.schema.args,i];return new n({...this.schema,args:a,hasAction:!1},void 0,this._subcommands,this._executionSteps)}command(e){let t={...this.schema,commands:[...this.schema.commands,e.schema]};return l(t),new n(t,this.handler,[...this._subcommands,u(e)],this._executionSteps)}action(e){return new n({...this.schema,hasAction:!0},e,this._subcommands,this._executionSteps)}};function f(e){return new d({name:e,description:void 0,aliases:[],hidden:!1,examples:[],flags:{},args:[],hasAction:!1,interactive:void 0,middleware:[],commands:[]})}function p(e){return f(e)}export{d as CommandBuilder,f as command,p as group};
@@ -0,0 +1,491 @@
1
+ import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PROMPT_KINDS, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./prompt.mjs";
2
+
3
+ //#region src/core/schema/flag.d.ts
4
+ /** All flag presence states as a runtime array. */
5
+ declare const FLAG_PRESENCES: readonly ['optional', 'required', 'defaulted'];
6
+ /**
7
+ * Presence describes whether a flag value is guaranteed to exist when the
8
+ * action handler runs:
9
+ *
10
+ * - `'optional'` — not required; unresolved value follows the kind-specific
11
+ * optional fallback (`undefined` for most flags, `[]` for arrays)
12
+ * - `'required'` — must be supplied; error if missing
13
+ * - `'defaulted'` — always present (falls back to default value)
14
+ */
15
+ type FlagPresence = (typeof FLAG_PRESENCES)[number];
16
+ /**
17
+ * Fallback behavior when an optional flag resolves no value from any source.
18
+ *
19
+ * Most optional flags resolve to `undefined`; array flags instead resolve to
20
+ * an empty array `[]`.
21
+ */
22
+ type OptionalFallback = 'undefined' | 'empty-array';
23
+ /**
24
+ * Compile-time state carried through the builder chain.
25
+ *
26
+ * Adding new tracked properties only requires extending this interface — no
27
+ * builder signature changes.
28
+ */
29
+ interface FlagConfig {
30
+ /** The resolved value type (e.g. `string`, `number`, `'us' | 'eu'`). */
31
+ readonly valueType: unknown;
32
+ /** Whether the flag is optional, required, or has a default. */
33
+ readonly presence: FlagPresence;
34
+ /** What an unresolved optional flag becomes at the action boundary. */
35
+ readonly optionalFallback: OptionalFallback;
36
+ }
37
+ /**
38
+ * Advanced type helper used by {@linkcode FlagBuilder} modifiers to replace presence.
39
+ * Most consumers rely on inference and never reference this directly.
40
+ */
41
+ type WithPresence<C extends FlagConfig, P extends FlagPresence> = {
42
+ readonly valueType: C['valueType'];
43
+ readonly presence: P;
44
+ readonly optionalFallback: C['optionalFallback'];
45
+ };
46
+ /**
47
+ * Compute the final value type from config — this is what handlers receive.
48
+ *
49
+ * Advanced type helper: this powers {@link InferFlag} and action-handler
50
+ * inference. Most apps do not need to mention it explicitly.
51
+ *
52
+ * - `'optional'` + `'undefined'` fallback → `T | undefined`
53
+ * - `'optional'` + `'empty-array'` fallback → `T`
54
+ * - `'required'` → `T`
55
+ * - `'defaulted'` → `T`
56
+ */
57
+ type ResolvedValue<C extends FlagConfig> = C['presence'] extends 'optional' ? C['optionalFallback'] extends 'empty-array' ? C['valueType'] : C['valueType'] | undefined : C['valueType'];
58
+ /** Extract the resolved value type from a {@linkcode FlagBuilder}. */
59
+ type InferFlag<B> = B extends FlagBuilder<infer C extends FlagConfig> ? ResolvedValue<C> : never;
60
+ /** Extract resolved value types from a record of builders. */
61
+ type InferFlags<T extends Record<string, FlagBuilder<FlagConfig>>> = { [K in keyof T]: InferFlag<T[K]> };
62
+ /** All flag kind discriminators as a runtime array. */
63
+ declare const FLAG_KINDS: readonly ['string', 'number', 'boolean', 'enum', 'array', 'custom'];
64
+ /** Discriminator for the kind of value a flag accepts. */
65
+ type FlagKind = (typeof FLAG_KINDS)[number];
66
+ /**
67
+ * Custom parse function for `flag.custom()`.
68
+ *
69
+ * Receives `string` from CLI argv and env vars, or any JSON-representable
70
+ * value from config files. Narrow inside the function as needed.
71
+ */
72
+ type FlagParseFn<T> = (raw: unknown) => T;
73
+ /** Runtime descriptor for a flag alias. */
74
+ interface FlagAlias {
75
+ /** Alias name without `-` / `--` prefix. */
76
+ readonly name: string;
77
+ /** Whether the alias is parser-only and hidden from user-facing surfaces. */
78
+ readonly hidden: boolean;
79
+ }
80
+ /**
81
+ * The runtime descriptor stored inside every {@linkcode FlagBuilder}. Consumers (parser,
82
+ * help generator, resolution chain) read this to understand the flag's shape
83
+ * without touching generics.
84
+ */
85
+ interface FlagSchema {
86
+ /** What kind of value this flag accepts. */
87
+ readonly kind: FlagKind;
88
+ /** Current presence state. */
89
+ readonly presence: FlagPresence;
90
+ /** Runtime default value (if any). */
91
+ readonly defaultValue: unknown;
92
+ /** Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`). */
93
+ readonly aliases: readonly FlagAlias[];
94
+ /** Environment variable name for v0.2+ resolution. */
95
+ readonly envVar: string | undefined;
96
+ /** Dotted config path for v0.2+ resolution (e.g. `'deploy.region'`). */
97
+ readonly configPath: string | undefined;
98
+ /** Human-readable description for help text. */
99
+ readonly description: string | undefined;
100
+ /** Allowed literal values when `kind === 'enum'`. */
101
+ readonly enumValues: readonly string[] | undefined;
102
+ /** Element schema when `kind === 'array'`. */
103
+ readonly elementSchema: FlagSchema | undefined;
104
+ /** Interactive prompt configuration for v0.3+ resolution. */
105
+ readonly prompt: PromptConfig | undefined;
106
+ /** Custom parse function (only when `kind === 'custom'`). */
107
+ readonly parseFn: FlagParseFn<unknown> | undefined;
108
+ /**
109
+ * Deprecation marker.
110
+ *
111
+ * - `undefined` — not deprecated (default)
112
+ * - `true` — deprecated with no migration message
113
+ * - `string` — deprecated with a reason/migration message
114
+ *
115
+ * When a deprecated flag is used, a warning is emitted to stderr.
116
+ * Help text shows `[deprecated]` or `[deprecated: <reason>]`.
117
+ */
118
+ readonly deprecated: string | true | undefined;
119
+ /**
120
+ * Whether this flag propagates to subcommands in nested command trees.
121
+ *
122
+ * When `true`, the flag is automatically available to all descendant
123
+ * commands. A child command that defines a flag with the same name
124
+ * shadows the propagated parent flag.
125
+ *
126
+ * @defaultValue `false`
127
+ */
128
+ readonly propagate: boolean;
129
+ }
130
+ /**
131
+ * Low-level overrides accepted by {@link createSchema}.
132
+ *
133
+ * `aliases` accepts both legacy string input and structured {@link FlagAlias}
134
+ * objects so tests and internal fixtures can be migrated incrementally.
135
+ */
136
+ type FlagSchemaOverrides = Omit<Partial<FlagSchema>, 'aliases'> & {
137
+ readonly aliases?: readonly (string | FlagAlias)[];
138
+ };
139
+ /**
140
+ * Normalise an alias input into a full {@link FlagAlias} object.
141
+ *
142
+ * @param alias - Raw alias name or structured alias object.
143
+ * @returns Normalised alias record.
144
+ */
145
+ declare function normalizeFlagAlias(alias: string | FlagAlias): FlagAlias;
146
+ /**
147
+ * Normalise alias input into immutable alias records.
148
+ *
149
+ * @param aliases - Alias input values.
150
+ * @returns Normalised alias objects.
151
+ */
152
+ declare function normalizeFlagAliases(aliases: readonly (string | FlagAlias)[]): readonly FlagAlias[];
153
+ /**
154
+ * List alias names for a flag schema.
155
+ *
156
+ * @param schema - Flag schema whose aliases should be listed.
157
+ * @param options - Visibility and length filtering.
158
+ * @returns Alias names in registration order.
159
+ */
160
+ declare function getFlagAliasNames(schema: FlagSchema, options?: {
161
+ readonly includeHidden?: boolean;
162
+ readonly kind?: 'all' | 'short' | 'long';
163
+ }): readonly string[];
164
+ /**
165
+ * Create a raw {@link FlagSchema} object with sensible defaults.
166
+ *
167
+ * Most consumers should prefer the higher-level {@link flag} factory,
168
+ * which returns an immutable {@link FlagBuilder} with type inference and
169
+ * safe modifier chaining. `createSchema()` is the low-level escape hatch
170
+ * for advanced schema composition, tests, or custom factories that need to
171
+ * work directly with the runtime descriptor.
172
+ *
173
+ * `overrides` are shallow-merged on top of the default shape, so callers are
174
+ * responsible for keeping the resulting schema internally consistent.
175
+ *
176
+ * @param kind - Discriminator for the value type this flag accepts.
177
+ * @param overrides - Partial {@link FlagSchema} fields merged onto defaults.
178
+ * @returns A fully populated {@link FlagSchema}.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const schema = createSchema('enum', {
183
+ * enumValues: ['us', 'eu', 'ap'],
184
+ * description: 'Deployment region',
185
+ * });
186
+ * ```
187
+ */
188
+ declare function createSchema(kind: FlagKind, overrides?: FlagSchemaOverrides): FlagSchema;
189
+ /**
190
+ * Immutable flag schema builder.
191
+ *
192
+ * The type parameter `C` is a phantom that tracks the value type and presence
193
+ * through the fluent chain. Each modifier returns a **new** builder — the
194
+ * original is never mutated.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const port = flag.number().default(8080);
199
+ * type Port = InferFlag<typeof port>; // number
200
+ *
201
+ * const region = flag.enum(['us', 'eu', 'ap']);
202
+ * type Region = InferFlag<typeof region>; // 'us' | 'eu' | 'ap' | undefined
203
+ * ```
204
+ */
205
+ declare class FlagBuilder<C extends FlagConfig> {
206
+ /** @internal Runtime schema descriptor. */
207
+ readonly schema: FlagSchema;
208
+ /**
209
+ * @internal Type brand — exists only in the type system (`declare`
210
+ * produces no runtime property). Used by {@linkcode InferFlag} / {@linkcode InferFlags}.
211
+ */
212
+ readonly _config: C;
213
+ /**
214
+ * Create a flag builder from a pre-built schema descriptor.
215
+ *
216
+ * @param schema - Runtime descriptor seeding this builder's state.
217
+ */
218
+ constructor(schema: FlagSchema);
219
+ /**
220
+ * Provide a default value. The flag becomes "always present" — handlers
221
+ * will never see `undefined`.
222
+ *
223
+ * The generic constraint `V extends C['valueType']` ensures the default
224
+ * matches the flag's declared type.
225
+ *
226
+ * @param value - Fallback value used when no source provides one.
227
+ * @returns The builder (for chaining).
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * flag.number().default(8080).describe('Port to listen on')
232
+ *
233
+ * // $ mycli serve → port = 8080
234
+ * // $ mycli serve --port 443 → port = 443
235
+ * ```
236
+ */
237
+ default<V extends C['valueType']>(value: V): FlagBuilder<WithPresence<C, 'defaulted'>>;
238
+ /**
239
+ * Mark the flag as required. If not resolved from any source the framework
240
+ * will emit a `ValidationError` before the action handler runs.
241
+ *
242
+ * @returns The builder (for chaining).
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * flag.string().required().describe('Deploy target')
247
+ *
248
+ * // $ mycli deploy
249
+ * // # → Error: Missing required flag --target
250
+ * // $ mycli deploy --target staging
251
+ * // # → target = 'staging'
252
+ * ```
253
+ */
254
+ required(): FlagBuilder<WithPresence<C, 'required'>>;
255
+ /**
256
+ * Add a short or long alias (e.g. `'f'` for `--force`, `'verbose'` as an
257
+ * alternative long name).
258
+ *
259
+ * @param name - Single-char short alias or alternative long name.
260
+ * @param options - Optional alias metadata. Hidden aliases remain parseable
261
+ * but are omitted from help, completions, and suggestions.
262
+ * @returns The builder (for chaining).
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * flag.boolean().alias('v').describe('Enable verbose output')
267
+ *
268
+ * // $ mycli build -v → verbose = true
269
+ * // $ mycli build --verbose → verbose = true
270
+ * ```
271
+ */
272
+ alias(name: string, options?: {
273
+ hidden?: boolean;
274
+ }): FlagBuilder<C>;
275
+ /**
276
+ * Bind to an environment variable (resolved in v0.2+).
277
+ *
278
+ * @param varName - Environment variable name (e.g. `'PORT'`).
279
+ * @returns The builder (for chaining).
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * flag.string().env('API_KEY').describe('Service API key')
284
+ *
285
+ * // $ API_KEY=sk-123 mycli request → apiKey = 'sk-123'
286
+ * // $ mycli request --api-key sk-456 → apiKey = 'sk-456' (CLI wins)
287
+ * ```
288
+ */
289
+ env(varName: string): FlagBuilder<C>;
290
+ /**
291
+ * Bind to a dotted config path (resolved in v0.2+).
292
+ *
293
+ * @param path - Dotted config key (e.g. `'deploy.region'`).
294
+ * @returns The builder (for chaining).
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * flag.string().config('deploy.region').default('us-east-1')
299
+ * // Config file: { "deploy": { "region": "eu-west-1" } }
300
+ * // $ mycli deploy
301
+ * // # → region = 'eu-west-1' (from config)
302
+ * // $ mycli deploy --region ap-south-1
303
+ * // # → CLI flag wins
304
+ * ```
305
+ */
306
+ config(path: string): FlagBuilder<C>;
307
+ /**
308
+ * Human-readable description shown in help output.
309
+ *
310
+ * @param description - Text displayed next to the flag in `--help`.
311
+ * @returns The builder (for chaining).
312
+ */
313
+ describe(description: string): FlagBuilder<C>;
314
+ /**
315
+ * Attach interactive prompt configuration for v0.3+ resolution.
316
+ *
317
+ * When a flag value is not resolved from CLI, env, or config, the
318
+ * prompt engine uses this config to interactively ask the user.
319
+ * In non-interactive contexts (CI, piped stdin) prompts are skipped
320
+ * and resolution falls through to default or required validation.
321
+ *
322
+ * @param config - {@link PromptConfig} describing the interactive prompt.
323
+ * @returns The builder (for chaining).
324
+ *
325
+ * @example
326
+ * ```ts
327
+ * flag.string().prompt({ kind: 'input', message: 'Enter value:' })
328
+ *
329
+ * // $ mycli init → prompts "Enter value:" interactively
330
+ * // $ mycli init --name foo → skips prompt, uses CLI value
331
+ * ```
332
+ */
333
+ prompt(config: PromptConfig): FlagBuilder<C>;
334
+ /**
335
+ * Mark this flag as deprecated.
336
+ *
337
+ * When used, a warning is emitted to stderr. Help text shows
338
+ * `[deprecated]` or `[deprecated: <reason>]`.
339
+ *
340
+ * Does not change the flag's type-level config — it's metadata only.
341
+ *
342
+ * @param message - Optional migration reason/guidance.
343
+ * @returns The builder (for chaining).
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * flag.string().deprecated('Use --target instead')
348
+ *
349
+ * // $ mycli deploy --dest staging
350
+ * // ⚠ --dest is deprecated: Use --target instead
351
+ * ```
352
+ */
353
+ deprecated(message?: string): FlagBuilder<C>;
354
+ /**
355
+ * Mark this flag as propagated to subcommands.
356
+ *
357
+ * Propagated flags are automatically available to all descendant
358
+ * commands in a nested command tree. A child command that defines
359
+ * a flag with the same name shadows the propagated parent flag.
360
+ *
361
+ * Does not change the flag's type-level config — it's metadata only.
362
+ *
363
+ * @returns The builder (for chaining).
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * flag.boolean().alias('v').propagate().describe('Enable verbose output')
368
+ *
369
+ * // $ mycli --verbose deploy staging
370
+ * // # → verbose = true in deploy handler
371
+ * // $ mycli deploy --verbose staging
372
+ * // # → same, inherited from parent
373
+ * ```
374
+ */
375
+ propagate(): FlagBuilder<C>;
376
+ }
377
+ /**
378
+ * Factory that creates {@link FlagBuilder} instances seeded with the correct
379
+ * {@link FlagKind} and initial type-level config.
380
+ */
381
+ interface FlagFactory {
382
+ /**
383
+ * String-valued flag.
384
+ *
385
+ * @returns A {@link FlagBuilder} for `string` values.
386
+ */
387
+ string(): FlagBuilder<{
388
+ readonly valueType: string;
389
+ readonly presence: 'optional';
390
+ readonly optionalFallback: 'undefined';
391
+ }>;
392
+ /**
393
+ * Number-valued flag.
394
+ *
395
+ * @returns A {@link FlagBuilder} for `number` values.
396
+ */
397
+ number(): FlagBuilder<{
398
+ readonly valueType: number;
399
+ readonly presence: 'optional';
400
+ readonly optionalFallback: 'undefined';
401
+ }>;
402
+ /**
403
+ * Boolean flag. Implicitly defaults to `false` — the only flag kind where
404
+ * the absence of a value is still meaningful (not `undefined`).
405
+ *
406
+ * @returns A {@link FlagBuilder} for `boolean` values (defaulted to `false`).
407
+ */
408
+ boolean(): FlagBuilder<{
409
+ readonly valueType: boolean;
410
+ readonly presence: 'defaulted';
411
+ readonly optionalFallback: 'undefined';
412
+ }>;
413
+ /**
414
+ * Enum flag with literal type inference.
415
+ *
416
+ * Requires a **non-empty** readonly tuple so that `T[number]` produces a
417
+ * union of string literals rather than just `string`.
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * flag.enum(['us', 'eu', 'ap'])
422
+ * // inferred type: 'us' | 'eu' | 'ap'
423
+ * ```
424
+ *
425
+ * @param values - Non-empty tuple of allowed string literals.
426
+ * @returns A {@link FlagBuilder} whose value type is the union of `values`.
427
+ */
428
+ enum<const T extends readonly [string, ...string[]]>(values: T): FlagBuilder<{
429
+ readonly valueType: T[number];
430
+ readonly presence: 'optional';
431
+ readonly optionalFallback: 'undefined';
432
+ }>;
433
+ /**
434
+ * Array flag — collects multiple values of the same element type.
435
+ *
436
+ * @example
437
+ * ```ts
438
+ * flag.array(flag.string())
439
+ * // inferred type: string[]
440
+ * ```
441
+ *
442
+ * @param element - {@link FlagBuilder} describing the element type.
443
+ * @returns A {@link FlagBuilder} for arrays of the element type.
444
+ */
445
+ array<E extends FlagConfig>(element: FlagBuilder<E>): FlagBuilder<{
446
+ readonly valueType: E['valueType'][];
447
+ readonly presence: 'optional';
448
+ readonly optionalFallback: 'empty-array';
449
+ }>;
450
+ /**
451
+ * Custom-parsed flag. The parse function receives the raw value and must
452
+ * return a value of type `T`. The return type is inferred from `parseFn`.
453
+ *
454
+ * The input is `string` from CLI argv and env vars, or any JSON value
455
+ * from config files. Narrow inside the function as needed:
456
+ *
457
+ * ```ts
458
+ * flag.custom((raw: unknown): string[] => {
459
+ * if (Array.isArray(raw)) return raw.map(String);
460
+ * if (typeof raw === 'string') return raw.split(',');
461
+ * throw new Error(`Expected string or array, got ${typeof raw}`);
462
+ * })
463
+ * ```
464
+ *
465
+ * Throw an `Error` (or `ParseError`) to signal invalid input — it will
466
+ * be wrapped with context and re-thrown as a `ParseError`.
467
+ *
468
+ * @see `coerceConfigValue` `'custom'` case in `core/resolve/index.ts`
469
+ *
470
+ * @example
471
+ * ```ts
472
+ * flag.custom((raw) => new URL(String(raw)))
473
+ * // inferred type: URL | undefined
474
+ * ```
475
+ *
476
+ * @param parseFn - Converts the raw input into a value of type `T`.
477
+ * @returns A {@link FlagBuilder} whose value type is inferred from `parseFn`.
478
+ */
479
+ custom<T>(parseFn: FlagParseFn<T>): FlagBuilder<{
480
+ readonly valueType: T;
481
+ readonly presence: 'optional';
482
+ readonly optionalFallback: 'undefined';
483
+ }>;
484
+ }
485
+ /**
486
+ * Flag schema factory. Call `flag.<kind>()` to create an immutable
487
+ * {@link FlagBuilder} with full type inference and safe modifier chaining.
488
+ */
489
+ declare const flag: FlagFactory;
490
+ //#endregion
491
+ export { type ConfirmPromptConfig, FLAG_KINDS, FLAG_PRESENCES, type FlagAlias, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FlagSchemaOverrides, type InferFlag, type InferFlags, type InputPromptConfig, type MultiselectPromptConfig, type OptionalFallback, PROMPT_KINDS, type PromptConfig, type PromptConfigBase, type PromptKind, type PromptResult, type ResolvedValue, type SelectChoice, type SelectPromptConfig, type WithPresence, createSchema, flag, getFlagAliasNames, normalizeFlagAlias, normalizeFlagAliases };
@@ -0,0 +1 @@
1
+ function e(e){return typeof e==`string`?{name:e,hidden:!1}:{name:e.name,hidden:e.hidden}}function t(t){return t.map(e)}function n(e,t){let n=t?.includeHidden??!1,r=t?.kind??`all`;return e.aliases.filter(e=>n||!e.hidden).filter(e=>r===`short`?e.name.length===1:r===`long`?e.name.length>1:!0).map(e=>e.name)}function r(e,n){let r=n?.aliases===void 0?[]:t(n.aliases),{aliases:i,...a}=n??{};return{kind:e,presence:`optional`,defaultValue:void 0,envVar:void 0,configPath:void 0,description:void 0,enumValues:void 0,elementSchema:void 0,prompt:void 0,parseFn:void 0,deprecated:void 0,propagate:!1,...a,aliases:r}}var i=class e{schema;constructor(e){this.schema=e}default(t){return new e({...this.schema,presence:`defaulted`,defaultValue:t})}required(){return new e({...this.schema,presence:`required`})}alias(t,n){return new e({...this.schema,aliases:[...this.schema.aliases,{name:t,hidden:n?.hidden??!1}]})}env(t){return new e({...this.schema,envVar:t})}config(t){return new e({...this.schema,configPath:t})}describe(t){return new e({...this.schema,description:t})}prompt(t){return new e({...this.schema,prompt:t})}deprecated(t){return new e({...this.schema,deprecated:t??!0})}propagate(){return new e({...this.schema,propagate:!0})}};const a={string(){return new i(r(`string`))},number(){return new i(r(`number`))},boolean(){return new i(r(`boolean`,{presence:`defaulted`,defaultValue:!1}))},enum(e){return new i(r(`enum`,{enumValues:e}))},array(e){return new i(r(`array`,{elementSchema:e.schema}))},custom(e){return new i(r(`custom`,{parseFn:e}))}};export{i as FlagBuilder,r as createSchema,a as flag,n as getFlagAliasNames};
@@ -0,0 +1,8 @@
1
+ import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle, SpinnerOptions, TableColumn, TableFormat, TableOptions, TableStream } from "./activity.mjs";
2
+ import { ARG_KINDS, ARG_PRESENCES, ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./arg.mjs";
3
+ import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PROMPT_KINDS, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./prompt.mjs";
4
+ import { FLAG_KINDS, FLAG_PRESENCES, FlagAlias, FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagParseFn, FlagPresence, FlagSchema, FlagSchemaOverrides, InferFlag, InferFlags, ResolvedValue, WithPresence, createSchema, flag } from "./flag.mjs";
5
+ import { ErasedMiddlewareHandler, Middleware, MiddlewareHandler, MiddlewareParams, middleware } from "./middleware.mjs";
6
+ import { RunOptions, RunResult } from "./run.mjs";
7
+ import { ActionHandler, ActionParams, AnyCommandBuilder, CommandArgEntry, CommandBuilder, CommandConfig, CommandExample, CommandMeta, CommandSchema, DeriveHandler, DeriveParams, ErasedCommand, ErasedDeriveHandler, ErasedInteractiveResolver, InteractiveParams, InteractiveResolver, InteractiveResult, Out, command, group } from "./command.mjs";
8
+ export { ARG_KINDS, ARG_PRESENCES, type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type ConfirmPromptConfig, type DeriveHandler, type DeriveParams, type ErasedCommand, type ErasedDeriveHandler, type ErasedInteractiveResolver, type ErasedMiddlewareHandler, FLAG_KINDS, FLAG_PRESENCES, type Fallback, type FlagAlias, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FlagSchemaOverrides, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type Out, PROMPT_KINDS, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptKind, type PromptResult, type ResolvedArgValue, type ResolvedValue, type RunOptions, type RunResult, type SelectChoice, type SelectPromptConfig, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type WithArgPresence, type WithPresence, type WithVariadic, arg, command, createArgSchema, createSchema, flag, group, middleware };
@@ -0,0 +1,122 @@
1
+ import { CommandMeta, Out } from "./command.mjs";
2
+
3
+ //#region src/core/schema/middleware.d.ts
4
+ /**
5
+ * Parameters received by a middleware function at runtime.
6
+ *
7
+ * Middleware receives erased args/flags (since it's defined independently
8
+ * of commands) plus the accumulated context from prior middleware and a
9
+ * `next` function to continue the chain.
10
+ */
11
+ interface MiddlewareParams {
12
+ /** Fully resolved positional arguments (type-erased). */
13
+ readonly args: Readonly<Record<string, unknown>>;
14
+ /** Fully resolved flags (type-erased). */
15
+ readonly flags: Readonly<Record<string, unknown>>;
16
+ /** Context accumulated from previous middleware in the chain. */
17
+ readonly ctx: Readonly<Record<string, unknown>>;
18
+ /** Output channel. */
19
+ readonly out: Out;
20
+ /** CLI program metadata (name, bin, version, command). */
21
+ readonly meta: CommandMeta;
22
+ /**
23
+ * Continue to the next middleware or action handler.
24
+ *
25
+ * Call with context additions that merge into `ctx` for downstream.
26
+ * Returns when the entire downstream chain completes — enabling
27
+ * wrap-around patterns (timing, try/catch, cleanup).
28
+ */
29
+ readonly next: (additions: Record<string, unknown>) => Promise<void>;
30
+ }
31
+ /**
32
+ * Type-erased middleware handler stored on `CommandSchema`.
33
+ *
34
+ * At runtime, all middleware handlers have this signature. The phantom
35
+ * `Output` type on {@linkcode Middleware} is erased.
36
+ *
37
+ * @internal
38
+ */
39
+ type ErasedMiddlewareHandler = (params: MiddlewareParams) => void | Promise<void>;
40
+ /**
41
+ * Middleware handler function with typed `next()` parameter.
42
+ *
43
+ * The `Output` generic constrains what properties must be passed to
44
+ * {@linkcode MiddlewareParams.next | next()}, ensuring type-safe context additions at the call site.
45
+ */
46
+ type MiddlewareHandler<Output extends Record<string, unknown>> = (params: {
47
+ readonly args: Readonly<Record<string, unknown>>;
48
+ readonly flags: Readonly<Record<string, unknown>>;
49
+ readonly ctx: Readonly<Record<string, unknown>>;
50
+ readonly out: Out;
51
+ readonly meta: CommandMeta; /** Pass context additions downstream. Must include all `Output` properties. */
52
+ readonly next: (additions: Output) => Promise<void>;
53
+ }) => void | Promise<void>;
54
+ /**
55
+ * Internal runtime representation of middleware.
56
+ * @internal
57
+ */
58
+ interface MiddlewareImpl {
59
+ readonly _handler: ErasedMiddlewareHandler;
60
+ }
61
+ /**
62
+ * Middleware with phantom output type.
63
+ *
64
+ * The `Output` parameter tracks what this middleware adds to context at
65
+ * compile time. The `_output` brand is phantom — it exists only in the
66
+ * type system for inference, not at runtime.
67
+ *
68
+ * Created via the {@linkcode middleware} factory. Attached to commands via
69
+ * `CommandBuilder.middleware()`.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * interface User { id: string; name: string }
74
+ *
75
+ * const auth = middleware<{ user: User }>(async ({ next }) => {
76
+ * const user = await getUser();
77
+ * if (!user) throw new CLIError('Not authenticated', { code: 'AUTH_REQUIRED' });
78
+ * return next({ user });
79
+ * });
80
+ * ```
81
+ */
82
+ type Middleware<Output extends Record<string, unknown>> = MiddlewareImpl & {
83
+ /** @internal Phantom type brand — compile-time only. */readonly _output: Output;
84
+ };
85
+ /**
86
+ * Create a middleware definition.
87
+ *
88
+ * Middleware runs before the action handler and can add typed context,
89
+ * short-circuit execution, or wrap downstream processing.
90
+ *
91
+ * @param handler - Function receiving `{ args, flags, ctx, out, meta, next }`.
92
+ * Call `next(additions)` to continue the chain with added context.
93
+ * Omitting the `next()` call short-circuits (e.g., for auth guards).
94
+ * @returns {@linkcode Middleware} to attach via `CommandBuilder.middleware()`.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * // Auth guard — adds user to context or throws
99
+ * const auth = middleware(async ({ next }) => {
100
+ * const user = await getUser();
101
+ * if (!user) throw new CLIError('Not authenticated', { code: 'AUTH_REQUIRED' });
102
+ * return next({ user });
103
+ * });
104
+ *
105
+ * // Timing wrapper — measures downstream execution
106
+ * const timing = middleware(async ({ out, next }) => {
107
+ * const start = Date.now();
108
+ * await next({});
109
+ * out.info(`Done in ${Date.now() - start}ms`);
110
+ * });
111
+ *
112
+ * command('deploy')
113
+ * .middleware(timing)
114
+ * .middleware(auth)
115
+ * .action(({ ctx }) => {
116
+ * console.log(ctx.user.name); // typed!
117
+ * });
118
+ * ```
119
+ */
120
+ declare function middleware<Output extends Record<string, unknown>>(handler: MiddlewareHandler<Output>): Middleware<Output>;
121
+ //#endregion
122
+ export { type ErasedMiddlewareHandler, type Middleware, type MiddlewareHandler, type MiddlewareImpl, type MiddlewareParams, middleware };
@@ -0,0 +1 @@
1
+ function e(e){return{_handler:e}}export{e as middleware};