@kjanat/dreamcli 3.0.1 → 4.0.0-rc.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 (137) hide show
  1. package/CHANGELOG.md +951 -1
  2. package/README.md +7 -3
  3. package/dist/core/cli/builtins.d.mts +47 -0
  4. package/dist/core/cli/builtins.mjs +135 -0
  5. package/dist/core/cli/compiled.d.mts +29 -0
  6. package/dist/core/cli/compiled.mjs +76 -0
  7. package/dist/core/cli/dispatch.d.mts +9 -85
  8. package/dist/core/cli/help-links.d.mts +2 -14
  9. package/dist/core/cli/index.d.mts +282 -101
  10. package/dist/core/cli/index.mjs +497 -264
  11. package/dist/core/cli/planner.d.mts +13 -86
  12. package/dist/core/cli/planner.mjs +47 -30
  13. package/dist/core/cli/plugin.d.mts +1 -1
  14. package/dist/core/cli/propagate.mjs +1 -1
  15. package/dist/core/cli/reserved-flags.d.mts +1 -0
  16. package/dist/core/cli/reserved-flags.mjs +158 -0
  17. package/dist/core/cli/root-help.d.mts +1 -47
  18. package/dist/core/cli/root-help.mjs +37 -47
  19. package/dist/core/cli/root-output-flags.d.mts +1 -0
  20. package/dist/core/cli/root-output-flags.mjs +169 -0
  21. package/dist/core/cli/root-surface.d.mts +1 -68
  22. package/dist/core/cli/root-surface.mjs +2 -2
  23. package/dist/core/cli/runtime-preflight.d.mts +1 -199
  24. package/dist/core/cli/runtime-preflight.mjs +67 -17
  25. package/dist/core/completion/index.d.mts +2 -2
  26. package/dist/core/completion/shells/bash.d.mts +0 -1
  27. package/dist/core/completion/shells/bash.mjs +2 -1
  28. package/dist/core/completion/shells/fish.d.mts +0 -1
  29. package/dist/core/completion/shells/fish.mjs +2 -1
  30. package/dist/core/completion/shells/powershell.d.mts +0 -1
  31. package/dist/core/completion/shells/powershell.mjs +2 -1
  32. package/dist/core/completion/shells/shared.d.mts +3 -114
  33. package/dist/core/completion/shells/shared.mjs +9 -39
  34. package/dist/core/completion/shells/zsh.d.mts +0 -1
  35. package/dist/core/completion/shells/zsh.mjs +2 -1
  36. package/dist/core/config/index.d.mts +3 -3
  37. package/dist/core/config/index.mjs +2 -2
  38. package/dist/core/config/package-json.d.mts +2 -33
  39. package/dist/core/config/package-json.mjs +1 -34
  40. package/dist/core/errors/index.d.mts +7 -7
  41. package/dist/core/execution/index.d.mts +1 -48
  42. package/dist/core/execution/index.mjs +42 -27
  43. package/dist/core/help/ansi.d.mts +0 -11
  44. package/dist/core/help/index.d.mts +3 -35
  45. package/dist/core/help/index.mjs +29 -6
  46. package/dist/core/help/theme.d.mts +1 -21
  47. package/dist/core/json-schema/index.d.mts +279 -10
  48. package/dist/core/json-schema/index.mjs +482 -237
  49. package/dist/core/json-schema/meta-descriptions.generated.d.mts +79 -7
  50. package/dist/core/json-schema/meta-descriptions.generated.mjs +40 -6
  51. package/dist/core/output/activity.d.mts +1 -193
  52. package/dist/core/output/activity.mjs +1 -1
  53. package/dist/core/output/bind.d.mts +1 -37
  54. package/dist/core/output/contracts.d.mts +7 -13
  55. package/dist/core/output/contracts.mjs +1 -1
  56. package/dist/core/output/display-value.d.mts +1 -19
  57. package/dist/core/output/index.d.mts +5 -187
  58. package/dist/core/output/index.mjs +44 -9
  59. package/dist/core/output/renderers.d.mts +1 -45
  60. package/dist/core/output/writer.d.mts +0 -1
  61. package/dist/core/parse/index.d.mts +27 -5
  62. package/dist/core/parse/index.mjs +350 -227
  63. package/dist/core/parse/occurrences.d.mts +89 -0
  64. package/dist/core/parse/occurrences.mjs +114 -0
  65. package/dist/core/prompt/index.d.mts +3 -3
  66. package/dist/core/read-flags/index.d.mts +150 -0
  67. package/dist/core/read-flags/index.mjs +217 -0
  68. package/dist/core/resolve/args.d.mts +35 -4
  69. package/dist/core/resolve/args.mjs +132 -55
  70. package/dist/core/resolve/coerce.d.mts +66 -9
  71. package/dist/core/resolve/coerce.mjs +834 -270
  72. package/dist/core/resolve/config.d.mts +1 -10
  73. package/dist/core/resolve/contracts.d.mts +67 -44
  74. package/dist/core/resolve/errors.mjs +29 -21
  75. package/dist/core/resolve/flags.d.mts +36 -9
  76. package/dist/core/resolve/flags.mjs +129 -151
  77. package/dist/core/resolve/index.d.mts +8 -6
  78. package/dist/core/resolve/index.mjs +51 -18
  79. package/dist/core/resolve/path-checks.d.mts +47 -0
  80. package/dist/core/resolve/path-checks.mjs +102 -0
  81. package/dist/core/resolve/redaction.d.mts +12 -0
  82. package/dist/core/resolve/redaction.mjs +14 -0
  83. package/dist/core/resolve/stages.d.mts +85 -0
  84. package/dist/core/resolve/stages.mjs +170 -0
  85. package/dist/core/resolve/standard.d.mts +1 -24
  86. package/dist/core/resolve/standard.mjs +141 -43
  87. package/dist/core/schema/activity.d.mts +16 -16
  88. package/dist/core/schema/arg.d.mts +849 -71
  89. package/dist/core/schema/arg.mjs +727 -54
  90. package/dist/core/schema/brand.d.mts +17 -0
  91. package/dist/core/schema/cardinality.d.mts +301 -0
  92. package/dist/core/schema/cardinality.mjs +514 -0
  93. package/dist/core/schema/command.d.mts +181 -112
  94. package/dist/core/schema/command.mjs +305 -42
  95. package/dist/core/schema/flag.d.mts +515 -173
  96. package/dist/core/schema/flag.mjs +576 -78
  97. package/dist/core/schema/index.d.mts +11 -8
  98. package/dist/core/schema/index.mjs +10 -0
  99. package/dist/core/schema/middleware.d.mts +15 -12
  100. package/dist/core/schema/number-constraints.d.mts +5 -5
  101. package/dist/core/schema/prompt.d.mts +4 -4
  102. package/dist/core/schema/provenance.d.mts +99 -0
  103. package/dist/core/schema/provenance.mjs +28 -0
  104. package/dist/core/schema/run.d.mts +21 -60
  105. package/dist/core/schema/source.d.mts +179 -0
  106. package/dist/core/schema/source.mjs +206 -0
  107. package/dist/core/schema/standard.d.mts +12 -19
  108. package/dist/core/schema/stdin.d.mts +87 -0
  109. package/dist/core/schema/stdin.mjs +91 -0
  110. package/dist/core/schema/string-constraints.d.mts +16 -5
  111. package/dist/core/schema/string-constraints.mjs +18 -1
  112. package/dist/core/schema/value-parsers.d.mts +81 -9
  113. package/dist/core/schema/value-parsers.mjs +19 -1
  114. package/dist/core/schema/value.d.mts +242 -0
  115. package/dist/core/schema/value.mjs +573 -0
  116. package/dist/core/testkit/index.d.mts +28 -3
  117. package/dist/core/testkit/index.mjs +40 -26
  118. package/dist/index.d.mts +21 -16
  119. package/dist/index.mjs +10 -6
  120. package/dist/runtime/adapter.d.mts +3 -3
  121. package/dist/runtime/deno.d.mts +3 -3
  122. package/dist/runtime/detect.d.mts +2 -2
  123. package/dist/runtime/node.d.mts +3 -3
  124. package/dist/runtime/paths.d.mts +1 -31
  125. package/dist/runtime.d.mts +4 -4
  126. package/dist/strings.d.mts +1 -16
  127. package/dist/testkit.d.mts +2 -2
  128. package/dist/testkit.mjs +1 -1
  129. package/dist/version.d.mts +0 -13
  130. package/dist/version.mjs +2 -2
  131. package/dreamcli.schema.json +368 -78
  132. package/examples/interactive.ts +6 -5
  133. package/package.json +9 -9
  134. package/skills/cli-creation/SKILL.md +72 -16
  135. package/skills/cli-creation/references/pattern-cookbook.md +169 -11
  136. package/dist/core/resolve/property.d.mts +0 -51
  137. package/dist/core/resolve/property.mjs +0 -53
package/CHANGELOG.md CHANGED
@@ -7,6 +7,950 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Release checklist
11
+
12
+ - [ ] Set the intended version in `package.json` and `deno.json`, add the dated
13
+ changelog section, and update every comparison link.
14
+ - [ ] Update first-party DreamCLI pins in documentation and import-map
15
+ configuration; do not rewrite versions that belong to transitive lockfile
16
+ metadata.
17
+ - [ ] Run `runner run -s schema:emit version:check ci smoke`.
18
+ - [ ] Pack with `bun pm pack --quiet --ignore-scripts` and inspect the tarball's
19
+ files and version.
20
+ - [ ] Confirm generators and formatters leave no unexpected worktree changes.
21
+ - [ ] Commit and push the release preparation, then verify the target commit is
22
+ signed, `master` matches the remote, and every required check is green.
23
+ - [ ] Confirm the exact `v<version>` tag does not already exist and npm and JSR
24
+ do not already contain that version before publishing the GitHub release.
25
+
26
+ ## [4.0.0-rc.1] - 2026-08-12
27
+
28
+ ### Added
29
+
30
+ - **Handlers can see where each value came from**
31
+ ([#90](https://github.com/kjanat/dreamcli/issues/90)). `ActionParams`,
32
+ `DeriveParams`, and `MiddlewareParams` gain `sources`, keyed like `flags` and
33
+ `args`, holding the full record resolution already produced:
34
+ `{ stage: 'cli' }`, `{ stage: 'cli', via: 'stdin', trigger: 'dash' }`,
35
+ `{ stage: 'stdin', via: 'stdin', trigger: 'fallback' }`,
36
+ `{ stage: 'env', envVar }`, `{ stage: 'config', configPath }`,
37
+ `{ stage: 'prompt' }`, or `{ stage: 'default' }`. An input that resolved no
38
+ value has no record. `wasExplicit(record)` derives the explicit-versus-defaulted
39
+ question from it without dropping `.default()`, which would also drop
40
+ `defaultValue` from the definition document. `ResolveResult.provenance` carries
41
+ the same records for a direct `resolve()` caller, and `readFlags()` hands them
42
+ to a new `onSources` receiver, typed against the definitions record.
43
+ `ResolutionProvenance`, `ResolutionProvenanceRecord`, `InputSources`,
44
+ `SourcesOf`, and `wasExplicit` are exported from the package root. The existing
45
+ `ResolutionProvenance` name continues to describe one input's winning stage;
46
+ `ResolutionProvenanceRecord` names the complete `ResolveResult.provenance`
47
+ object.
48
+
49
+ - **`arg.keyValue()` takes an element builder**
50
+ ([#87](https://github.com/kjanat/dreamcli/issues/87)). Entry values used to be
51
+ strings on the positional surface while `flag.keyValue(element)` gave them a
52
+ codec. `arg.keyValue(arg.number().int().min(0))` now resolves
53
+ `mycli scale web=3` to `{ web: 3 }`, with the element's constraints, path
54
+ checks, and Standard Schema validator applied to every entry, from every
55
+ source. The element is guarded the same way flags guard theirs: `ArgConfig`
56
+ gains `elementEligible`, so a builder already described as a positional
57
+ (`.optional()`, `.env()`, `.stdin()`, `.describe()`, …) is refused in element
58
+ position at compile time. `ArgSchema` gains `elementSchema`, which serializes
59
+ into definition documents under the new `ArgElementFragmentV1` shape and the
60
+ `$defs.argElement` meta-schema definition.
61
+
62
+ - **Help names the stdin source.** An input that declares `.stdin()` renders
63
+ `[stdin]` beside the existing `[env: X]`, `[config: y]`, and `[prompt]`
64
+ annotations, on the flag table and the argument table alike. The narrower
65
+ triggers say which one applies: `[stdin: '-']` for `{ when: 'dash' }` and
66
+ `[stdin: when omitted]` for `{ when: 'missing' }`. Completion scripts are
67
+ unchanged; they carry the plain description.
68
+
69
+ - **A dedicated error code for a dash with nothing piped.**
70
+ `ValidationErrorCode` gains `MISSING_STDIN`, which replaces the borrowed
71
+ `REQUIRED_FLAG` / `REQUIRED_ARG` on the one failure that is neither: a `-`
72
+ typed beside other occurrences of a collection when the stream is empty. Those
73
+ two keep their own meaning, a required input no source filled.
74
+
75
+ - **A variadic argument reads stdin from its tail.** `.stdin()` and
76
+ `.variadic()` now compose. A `-` among the tail tokens stands for the whole
77
+ stdin source at that position, so
78
+ `printf 'x\ny\n' | mycli build a - b` collects `['a', 'x', 'y', 'b']`, and an
79
+ empty tail under a binding that covers a missing input takes the whole buffer.
80
+ `arg.keyValue().variadic().stdin()` aggregates entries across the typed tokens
81
+ and the pipe under its `.duplicateKeys()` policy. Each `-` stands for all of
82
+ the buffer, so two of them splice it twice, and the stream is still read at
83
+ most once per invocation. The preflight that decides whether to read stdin
84
+ counts an empty tail as an absent input, which is what makes
85
+ `printf 'x\ny\n' | mycli build` reach the fallback stage under `.run()`.
86
+
87
+ - **`.stdin({ trim: true })` drops the terminator a pipe appends.** Codecs that
88
+ preserve text terminators, including `string` and `path`, keep the buffer byte
89
+ for byte by default. `trim` drops one trailing `\n`, `\r\n`, or `\r` from a
90
+ single value before anything decodes or checks it, so
91
+ `echo ./dist | mycli clean` satisfies `arg.path({ mustExist: true })`. It
92
+ applies to both surfaces, to an explicit `-` and to the implicit fallback, and
93
+ to `readFlags()` and `runCommand()`. Other decoding codecs already remove one
94
+ framing terminator and are unaffected, so no value ever loses two. A collection's
95
+ terminators separate its elements, so `.split({ stdin })` still decides those.
96
+ The binding serializes as `stdin.trim` in definition documents, alongside
97
+ `when` and `consume`.
98
+
99
+ - **Stability policy and a 4.0 upgrade guide** — the
100
+ [stability page](https://dreamcli.kjanat.dev/reference/stability) now places
101
+ every export of the root, `/testkit`, `/runtime`, and `/version` entrypoints
102
+ in one of thirteen categories, each with the rules it carries into a minor
103
+ release: sealed framework values, consumer input options, transparent input
104
+ definitions, implementer ports, externally governed protocols, structural
105
+ consumer configuration, closed unions and discriminated results, open unions,
106
+ framework-produced callback payloads, closed constructible DTOs, serialized
107
+ formats, classes and functions, and internal surface.
108
+ [Upgrading From 3.x To 4.0](https://dreamcli.kjanat.dev/guide/upgrading-v4)
109
+ walks the breaking changes below with before and after code.
110
+
111
+ - **Definition types and normalization factories for flags, args, commands, and
112
+ the CLI** — `createFlagSchema()`, `createCommandSchema()`, and
113
+ `createCLISchema()` join the existing `createArgSchema()`. The flag and arg
114
+ factories take a plain definition object, or a kind plus that kind's fields;
115
+ the command and CLI factories take complete definition objects. Each returns
116
+ the normalized schema; feeding a built schema back in produces a deep-equal
117
+ schema, and a field belonging to another kind throws `INVALID_SCHEMA`.
118
+ `createCommandSchema()` normalizes nested flags, args, and subcommands, and
119
+ `createCLISchema()` normalizes commands and config settings for a description
120
+ of a program with no execution graph attached. Each level ships its definition
121
+ types: `FlagDefinition`,
122
+ `FlagDefinitionBase`, `FlagDefinitionByKind`, `FlagDefinitionOverrides`, and
123
+ the per-kind members `StringFlagDefinition`, `NumberFlagDefinition`,
124
+ `BooleanFlagDefinition`, `EnumFlagDefinition`, `ArrayFlagDefinition`,
125
+ `CustomFlagDefinition`, `CountFlagDefinition`, `KeyValueFlagDefinition`;
126
+ `ArgDefinition`, `ArgDefinitionBase`, `ArgDefinitionByKind`,
127
+ `ArgDefinitionOverrides`, `StringArgDefinition`, `NumberArgDefinition`,
128
+ `EnumArgDefinition`, `CustomArgDefinition`; `CommandDefinition` with
129
+ `CommandArgEntryDefinition`; and `CLIDefinition` with
130
+ `ConfigSettingsDefinition`. All of them are exported from the package root.
131
+
132
+ - **`.builtins()` takes `--help`, `--json`, or `--quiet` over to the commands**
133
+ ([#86](https://github.com/kjanat/dreamcli/issues/86)). A CLI whose `--json`
134
+ names the document it operates on, whose `-q` means something domain-specific,
135
+ or whose `--help` is a routable topic browser can now claim the token.
136
+ `cli('mycli').builtins({ json: 'off' })` releases every spelling that built-in
137
+ answers to. The root stops reading and stripping it from argv, root help stops
138
+ listing it under `Global options:`, the `RESERVED_FLAG` guard stops reserving
139
+ it, and a command may declare it as an ordinary flag that parses and reaches
140
+ the handler. Releasing `help` also disables command-level `--help`/`-h`, the
141
+ bare `help` token, the `--help` footer hint, the
142
+ `Run '<bin> --help' for available commands` suggestion on dispatch errors, and
143
+ the synthetic `--help` in generated completion scripts. `version` and
144
+ `completions` have no entry, since `.version()` and `.completions()` are
145
+ opt-in and a CLI declines those by omission. Every built-in defaults to
146
+ `'on'`, repeated calls merge with the last mode per built-in winning, and
147
+ `RunOptions.jsonMode` / `RunOptions.verbosity` keep working regardless, since
148
+ only argv-driven activation is disabled. The state is normalized onto
149
+ `CLISchema.builtins` by both `.builtins()` and the `builtins` field of
150
+ `createCLISchema()`, an invalid mode throws `INVALID_SCHEMA`, and
151
+ `BuiltinsConfig`, `Builtins`, `BuiltinName`, and `BuiltinMode` are exported
152
+ from the package root. `runCommand()` from `/testkit` takes the same
153
+ `builtins` option so a command owning a released flag can be tested; its
154
+ options type is now `RunCommandOptions`. The `RESERVED_FLAG` error offers
155
+ `.builtins({ <name>: 'off' })` alongside renaming, and a version discovered by
156
+ `.manifest()` filesystem walking now runs the same guard at `.run()` time
157
+ instead of silently shadowing a command's `version` flag. That startup failure
158
+ is reported the way every other `.run()` startup failure is: the message and
159
+ its suggestion go to stderr, `--json` puts the serialized error on stdout, and
160
+ the process exits with the error's exit code rather than rejecting the
161
+ `.run()` promise.
162
+
163
+ - **Definition format v1 — versioned, typed documents** — `generateSchema()`
164
+ and `generateCommandSchema()` now emit `schemaVersion: 1`, so a consumer can
165
+ tell which format it is reading before parsing the rest. Both return typed
166
+ documents instead of `Record<string, unknown>`: `DefinitionDocumentV1` for a
167
+ whole CLI, `CommandDefinitionDocumentV1` for a single command, with
168
+ `DefinitionDocument` and `CommandDefinitionDocument` aliasing the current
169
+ version. Documents are distinct from the fragments nested inside them.
170
+ `CommandDefinitionFragmentV1`, `FlagDefinitionFragmentV1`,
171
+ `ArgDefinitionFragmentV1`, `ExampleDefinitionFragmentV1`,
172
+ `PromptDefinitionFragmentV1`, `PromptChoiceFragmentV1`,
173
+ `FlagNegationFragmentV1`, `FlagStringConstraintsFragmentV1`, and
174
+ `FlagPathChecksFragmentV1` carry no `schemaVersion` and take the version of
175
+ the document they sit in. `generateInputSchema()` is standard JSON Schema and
176
+ stays outside the family, typed as `InputSchemaDocument` with
177
+ `InputSchemaBranch` and `InputSchemaProperty`. Every one of these is exported
178
+ from the package root, and the returned documents remain assignable to
179
+ `Record<string, unknown>`. `--help` in `--json` mode serializes through
180
+ `generateCommandSchema()`, so that output gains `schemaVersion: 1` as its
181
+ first key.
182
+
183
+ - **`readFlags()` evaluates a record of flag builders outside a CLI**
184
+ ([#107](https://github.com/kjanat/dreamcli/issues/107)). A build script or a
185
+ small tool that wants typed options without commands, handlers, or output
186
+ channels hands its flags straight to `readFlags()` and awaits the resolved
187
+ values, typed by `InferFlags`:
188
+
189
+ ```ts
190
+ const options = await readFlags({
191
+ watch: flag.boolean().alias('w').env('WATCH'),
192
+ minify: flag.boolean().env('MINIFY').default(true),
193
+ target: flag.enum(['node', 'browser']).env('TARGET').default('node'),
194
+ });
195
+
196
+ options.watch; // boolean
197
+ options.target; // 'node' | 'browser'
198
+ ```
199
+
200
+ Each object key is the canonical flag name, and evaluation runs through the
201
+ same command schema, parser, coercion, resolver, and validation a command
202
+ uses. Aliases, negated spellings, duplicate policy, case parity, unknown-flag
203
+ rejection, collisions between names, aliases and negated forms, the CLI,
204
+ stdin, env, config, prompt, default precedence, constraints, Standard Schema
205
+ validators, and `flag.path()` checks all behave as they do inside `.action()`.
206
+ `argv`, `env`, `stdinData`, `stat`, and `mkdir` fall back to the detected
207
+ `RuntimeAdapter`, while
208
+ `config` and `prompter` stay caller-supplied, since standalone flag reading
209
+ has no application name to discover a file from and opens no terminal session.
210
+ `ReadFlagsOptions` extends `ResolveOptions` with `argv`, `adapter`, `parse`,
211
+ `strict`, `help`, and `onDeprecation`. The adapter is built on the first fact
212
+ the caller left
213
+ out, so a call given `argv` and `env` reads nothing from the host unless a
214
+ `flag.path()` check needs the adapter's filesystem primitives. Failures throw
215
+ `ParseError` and `ValidationError` instead of exiting, a colliding record, the
216
+ definition key `__proto__`, and a record whose prototype is replaced (an
217
+ object-literal `__proto__` key, or `Object.create(base)`, whose inherited
218
+ definitions are never read) each throw `CLIError` before argv is read, and
219
+ `.deprecated()` notices reach `onDeprecation` rather than a warning stream,
220
+ since there is no output channel on this path.
221
+
222
+ A pre-separator `--help` or `-h` prints generated help for the record to the
223
+ adapter's stdout and exits with code 0, with the script named from the
224
+ adapter's argv in the usage line. The built-in yields to a definition that
225
+ claims the `help` or `h` spelling through a name, alias, negated form, or
226
+ case-parity counterpart, and `help: 'off'` removes it entirely; `json` and
227
+ `quiet` are never reserved, so a record may declare them as ordinary flags.
228
+ `strict: false` drops undeclared argv content instead of rejecting it: unknown
229
+ long flags with their inline `=value`, unknown short-group characters,
230
+ positional arguments, and the `--` separator, while value tokens of declared
231
+ flags survive under the parser's own consumption rules and misuse of a
232
+ declared flag keeps its diagnostics.
233
+
234
+ Positional arguments are not part of this API, and there is no
235
+ synchronous variant: prompts, async validators, and filesystem checks make the
236
+ result a promise. `readFlags`, `ReadFlagsOptions`, and `FlagMap` are exported
237
+ from the package root, and
238
+ [Standalone Flag Evaluation](https://dreamcli.kjanat.dev/guide/read-flags)
239
+ walks the API with the build-script case it was added for.
240
+
241
+ - **Purpose-built positional argument kinds and string constraints**
242
+ ([#87](https://github.com/kjanat/dreamcli/issues/87)). A base URL, an input
243
+ file, or a cutoff date reads naturally as a positional, and until now the only
244
+ route was `arg.custom()` re-implementing what `flag.url()` already did.
245
+ `arg.url(options?)`, `arg.path(options?)`, `arg.date(options?)`,
246
+ `arg.duration()`, and `arg.bytes()` mirror their flag counterparts: same value
247
+ types, same option objects (`UrlFlagOptions`, `PathFlagOptions`,
248
+ `DateFlagOptions`), same parsers. `arg.string()` takes a `StringConstraints`
249
+ object, and string-kind `ArgBuilder`s carry `.nonEmpty()`, `.minLength()`,
250
+ `.maxLength()`, and `.pattern()` alongside the numeric `.int()`, `.min()`,
251
+ `.max()`, and `.finite()` they already had. Both factories run the same parse
252
+ functions and the same constraint validator, so a value a flag accepts an
253
+ argument accepts, and a rejection carries the same code and the same reason,
254
+ differing in the subject: `for flag --x` versus `for argument <x>`.
255
+
256
+ String constraints are enforced on CLI parse (`INVALID_VALUE`) and on stdin,
257
+ env, config, and prompt resolution (`CONSTRAINT_VIOLATED`), both exit code
258
+ `2`; as with flags, a `.default()` value is checked where it is declared and a
259
+ violation throws `INVALID_DEFAULT`. `arg.path()`
260
+ checks run after resolution through the runtime adapter's `stat`/`mkdir`, the
261
+ same seam `flag.path()` uses, so a piped, env-sourced, config-sourced,
262
+ prompted, or defaulted path is checked like one typed on the command line. A
263
+ variadic argument validates every value it collects, path checks included.
264
+ Argument values sourced from anywhere but argv stay redacted in the message,
265
+ as in `Invalid value '<redacted>' from stdin for argument <x>` and
266
+ `Invalid number value '<redacted>' from config deploy.port for argument <x>`,
267
+ so the flag and argument messages are equivalent apart from their subjects.
268
+
269
+ `ArgSchema` and the arg definition types carry `stringConstraints`,
270
+ `pathChecks`, and `valueHint`. The first two are string-kind gated the way the
271
+ flag schema gates them. Args serialize `numberConstraints`,
272
+ `stringConstraints`, `pathChecks`, and `valueHint` into the definition
273
+ document, which previously emitted none of them, and `generateInputSchema()`
274
+ now surfaces arg string constraints as `minLength` / `maxLength` / `pattern`.
275
+ The meta-schema hoists the `numberConstraints`, `stringConstraints`, and
276
+ `pathChecks` fragments into `$defs` so the flag and arg definitions reference
277
+ one copy. All of it is additive at `schemaVersion: 1`. Help still renders a
278
+ positional by its own name rather than its `valueHint`, so
279
+ `mycli copy <src> <dst>` does not collapse into `<path> <path>`.
280
+
281
+ The flag-only surface stays flag-only, and
282
+ [the arguments guide](https://dreamcli.kjanat.dev/guide/arguments#flag-only-surface)
283
+ lists it with the reason for each entry. `boolean`, `count`, `negatable`,
284
+ `alias`, `duplicates`, `separator`, `unique`, and `propagate` are bound to
285
+ flag syntax; `array` is served by `.variadic()`. `keyValue` merges repeated
286
+ occurrences into one record, which a positional slot cannot express, and
287
+ `arg.custom()` with a Standard Schema validator is the documented route.
288
+ `.config()` and `.prompt()` are no longer among them: both surfaces now
289
+ declare the same sources, described in the unified source model entry below.
290
+
291
+ - **A unified source model — every input uses the same source order** — flags and
292
+ args now declare sources from the same set and resolve declared sources through
293
+ one ordered chain:
294
+ `CLI -> stdin -> env -> config -> prompt -> default`. `arg.config(path)` and
295
+ `arg.prompt(config)` join `arg.env()`, so a positional reads a dotted config
296
+ key and asks the user exactly as a flag does; the arg prompt table mirrors the
297
+ flag one (`PromptConfigByArgKind`, `AllowedArgPromptConfig`), and an
298
+ incompatible pairing throws `CONSTRAINT_VIOLATED` naming `<arg>`. Help
299
+ annotates a positional with `[config: PATH]` and `[prompt]` beside the
300
+ `[env: VAR]` it already showed.
301
+ `flag.string().stdin()` becomes legal on `string`, `number`, `boolean`,
302
+ `enum`, and `custom` flags, giving `echo hi | mycli send` and
303
+ `mycli send --body -` the meaning `arg.stdin()` already had. `.stdin()` takes
304
+ `{ when: 'dash' | 'missing' | 'dash-or-missing', consume: 'exclusive' |
305
+ 'broadcast' }` on both surfaces, defaulting to `dash-or-missing` and
306
+ `exclusive`. `StdinBinding`, `StdinOptions`, `StdinWhen`, and `StdinConsume`
307
+ are exported from the package root, and `StdinBindingFragmentV1` names the
308
+ serialized form.
309
+
310
+ An explicit `-` is CLI-sourced with bytes from stdin and keeps CLI precedence;
311
+ an absent input takes the stdin fallback stage, which sits ahead of env, so a
312
+ flag set in the environment still reads a pipe and the pipe wins. The `-`
313
+ sentinel now survives the parse boundary for every kind, so
314
+ `flag.number().stdin()` accepts `--port -` where it used to reject `-` as a
315
+ malformed number. `readFlags()` carries the same contract and reads stdin only
316
+ through the adapter, only when a declared `.stdin()` flag would actually
317
+ select it; `runCommand()` feeds the identical path from its `stdinData`
318
+ option. Stdin is read at most once per invocation, and only when resolution
319
+ will select it: `when: 'dash'` reads on `-` alone, `when: 'missing'` reads on
320
+ an absent input alone, and env, config, prompt, and a default never suppress
321
+ the read.
322
+
323
+ One command has one exclusive stdin consumer. Declaring a second stdin input
324
+ of any kind, flag or arg, throws `DUPLICATE_STDIN_INPUT` on both construction
325
+ paths; `{ consume: 'broadcast' }` on every stdin input opts into sharing one
326
+ buffer among them. The definition document carries the binding as
327
+ `stdin: { when, consume }` on flags and args, with a `stdin` entry in the
328
+ meta-schema `$defs`, and the arg fragment gains `configPath` and `prompt`.
329
+
330
+ - **Cardinality is its own axis, with per-source splitting.** How many values an
331
+ input carries (`one`, `many`, `entries`, `count`) is now decided separately
332
+ from what each value means, so every source fills a collection by the same
333
+ rules. `.split({ cli, env, stdin })` on `flag.array()`, `flag.keyValue()`, and
334
+ the arg builders sets each source's decoding independently: a delimiter or
335
+ `'whole'` for CLI tokens, a delimiter, `'whole'`, or `{ format: 'json' }` for
336
+ env values, and `'lines'`, `'whole'`, a delimiter, or `{ format: 'json' }` for
337
+ the stdin buffer. Defaults are whole CLI tokens (or the `.separator()`
338
+ delimiter), comma-delimited env values, and line-delimited stdin; a config
339
+ value stays a native array or object, and a config string decodes under the
340
+ env policy. JSON is never guessed. `SplitOptions`, `SplitSetting`,
341
+ `SplitPolicy`, `SplitBinding`, `SourceSplitBinding`, and `SplitFormat` are
342
+ exported from the package root, and the definition document carries `split` on
343
+ flag and arg fragments as `SourceSplitFragmentV1` / `SplitPolicyFragmentV1`.
344
+
345
+ - **Collections read stdin, and `-` splices into occurrence order.**
346
+ `flag.array()` and `flag.keyValue()` accept `.stdin()`, and a `-` occurrence
347
+ stands for the whole stdin source at the position it holds:
348
+ `--tag before --tag - --tag after` over `a\nb\n` resolves to
349
+ `['before', 'a', 'b', 'after']`. An explicit `-` and the implicit fallback
350
+ decode identically, entries splice the same way, and the duplicate-key policy
351
+ applies across the whole spliced order. Broadcast consumers each decode the
352
+ one shared buffer under their own binding, so a line-split array flag and a
353
+ JSON key-value flag can read the same pipe.
354
+
355
+ - **`.duplicateKeys()` on key-value inputs.** `'last'` (the default), `'first'`,
356
+ or `'error'` decides what a repeated key means, on every source rather than
357
+ only on repeated CLI occurrences. A repeat under `'error'` reports
358
+ `CONSTRAINT_VIOLATED` naming the key. `DuplicateKeys` is exported from the
359
+ package root and the policy is serialized as `duplicateKeys`.
360
+
361
+ - **`arg.boolean()` and `arg.keyValue()`.** A positional carries no presence
362
+ semantics, so `arg.boolean()` consumes an explicit `true`/`false` (or `1`/`0`)
363
+ token through the shared boolean codec, widening to `yes`/`no` and an empty
364
+ string only for env, config, stdin, and prompt values. `arg.keyValue()`
365
+ consumes `KEY=VALUE` tokens and resolves to `Record<string, string>`, splitting
366
+ at the first `=`; the variadic form aggregates the whole tail into one record.
367
+ `BooleanArgDefinition` and `KeyValueArgDefinition` join the definition types,
368
+ and `ArgKind` gains `'boolean'` and `'keyValue'`.
369
+
370
+ - **Element-level sugar inside collections.** Path checks and constraints belong
371
+ to the element, so `flag.array(flag.path({ mustExist: true }))` checks every
372
+ collected element and `flag.keyValue(flag.path())` checks every entry value.
373
+ `flag.keyValue()` takes an optional element builder, and `flag.path()` is now
374
+ element-eligible.
375
+
376
+ - **`.standard()` on both builders, split into element and aggregate
377
+ validation.** A validator declared on an element builder
378
+ (`flag.array(flag.string().standard(s))`) validates each item or entry value;
379
+ one declared on a builder that already aggregates
380
+ (`flag.array(flag.string()).standard(s)`, `arg.string().variadic().standard(s)`)
381
+ validates the completed array or record after every element passed. Element
382
+ issues name the element (`--tag[1]`, `--vars.KEY`). Sync and async validators
383
+ are both awaited, and every source runs the same pipeline.
384
+
385
+ - **`.unique()` and `.separator()` on args.** A variadic arg deduplicates with
386
+ the same `SameValueZero` semantics an array flag uses, and splits each
387
+ positional token on the CLI separator it declares.
388
+
389
+ ### Changed
390
+
391
+ - **Breaking: flag diagnostics redact every value resolved outside a literal
392
+ CLI value.** A
393
+ stdin, environment, config, or prompt value that failed to coerce used to be
394
+ printed and stored under `details.value` on the flag surface, while the
395
+ argument surface already redacted it. Both surfaces now report
396
+ `Invalid value '<redacted>' from env API_TOKEN for flag --token: must match
397
+ /^ghp_/` and omit `value` from `details`. Everything that identifies the
398
+ failure stays: the input name, the source, the expected type, the constraint
399
+ that failed with its bound or pattern, the allowed enum values, and a custom
400
+ parse function's own message. A Standard Schema validator's
401
+ `CONSTRAINT_VIOLATED` failure follows
402
+ the same rule: `details.value` is recorded only for a value typed on the
403
+ command line, and omitted for one a pipe, an explicit `-`, the environment, a
404
+ config file, or a prompt supplied. A literal CLI value is untouched, since it
405
+ is already on the user's screen. Every coercion failure now also carries
406
+ `source: 'env' | 'config' | 'stdin' | 'prompt'` in `details`, which is what
407
+ labels an issue `[env API_TOKEN]` in an aggregate error and what now gives the
408
+ argument surface the same label the flag surface had. The `flag.path()` and
409
+ `arg.path()` filesystem checks read the same rule, so a path a pipe, an
410
+ explicit `-`, the environment, a config file, a prompt, or a declared default
411
+ supplied reports `Path '<redacted>' for flag --key does not exist` and omits
412
+ `value` from `details`; a path typed on the command line is still quoted in
413
+ full. Every element of a collection of paths is checked and redacted
414
+ individually.
415
+
416
+ - **Breaking: a positional declared after a variadic one is a build error.** A
417
+ variadic argument consumes every remaining positional, so anything registered
418
+ behind it could never be filled and a second variadic one had nothing left to
419
+ collect. Both silently produced an argument that stayed empty. `.arg()` and
420
+ `createCommandSchema()` now throw `INVALID_BUILDER_STATE`
421
+ (`Argument <target> comes after variadic argument <files>, which consumes
422
+ every remaining positional`), with the command under `command`, the offending
423
+ argument under `arg`, and the greedy one under `variadicArg`, so a definition
424
+ tree names the nested command that declared the pair. Move the variadic
425
+ argument last.
426
+
427
+ - **Breaking: an explicit `-` with nothing piped is an error inside a
428
+ collection.** `--tag a --tag - --tag b` with an empty pipe used to resolve to
429
+ `['a', 'b']`, dropping the occurrence the user typed. It now fails with
430
+ `MISSING_STDIN` and the message
431
+ `No piped stdin for the '-' occurrence of flag --tag`. Occurrences of nothing
432
+ but `-` are unchanged: they are the whole value, so they still fall through to
433
+ env, config, prompt, and the default, exactly as an absent input does, and the
434
+ implicit `when: 'missing'` fallback that simply does not fire stays silent. A
435
+ scalar `-` falls through for the same reason. Only a collection could be
436
+ silently shortened, so only a collection errors.
437
+
438
+ - **Breaking: the arg collection modifiers require a collection.**
439
+ `createArgSchema('string', { unique: true })` and its siblings used to build,
440
+ storing a field nothing would read. They now state their requirement to the
441
+ compiler and throw `INVALID_SCHEMA` from `createArgSchema()`: `separator` and
442
+ `split` want a variadic argument or `arg.keyValue()`, `unique` a variadic
443
+ argument of a list kind, and `duplicateKeys` `arg.keyValue()`. The values a
444
+ schema already stores as its own default, `unique: false` and
445
+ `duplicateKeys: 'last'`, stay accepted on any kind, so a built `ArgSchema` fed
446
+ back through the factory round-trips. This mirrors the `array | keyValue`
447
+ restriction the flag surface already had. Drop the field, or add
448
+ `variadic: true` alongside it. The matching builder methods are new in 4.0, so
449
+ only definitions composed as data change.
450
+
451
+ - **Breaking: `.stdin()` and `.variadic()` on one argument is now legal.** The
452
+ pairing threw `INVALID_BUILDER_STATE`; the tail-splicing entry under Added
453
+ describes what it does instead. Code that relied on the throw has nothing to
454
+ catch.
455
+
456
+ - **Breaking: declared defaults are validated.** A `.default()` value is
457
+ already the typed value, so it is validated rather than decoded: the codec's
458
+ own domain, string and number constraints, element and aggregate Standard
459
+ Schema validators, the shape the cardinality requires, and the collection rules
460
+ all apply to it. Purely synchronous violations throw `INVALID_DEFAULT` where
461
+ the chain declares them, so `flag.string({ minLength: 3 }).default('ab')` and
462
+ `flag.number().default(Number.POSITIVE_INFINITY)` now fail at construction
463
+ instead of reaching a handler; a constraint added after the default
464
+ (`flag.string().default('ab').minLength(3)`) is checked too, as is a validator
465
+ (`.standard()`). On the definition path, where no compiler stands in the way,
466
+ the domain check also rejects a default of the wrong primitive type and an
467
+ `enum` default outside `enumValues`. Asynchronous
468
+ validators and `flag.path()` filesystem checks stay at resolution time, where
469
+ command resolution awaits the validator or probes the path. Code relying on a default that violates
470
+ its own declaration either fixes the default or widens the constraint
471
+ (`flag.number({ finite: false })` still accepts `Infinity`).
472
+
473
+ - **Breaking: `.separator()` sets the CLI delimiter alone.** Env and config
474
+ string values used to inherit it, so `.separator('|')` silently changed how an
475
+ env var decoded. Env values split on `','` unless `.split({ env })` says
476
+ otherwise. The stdin buffer splits on line terminators by default;
477
+ `.split({ stdin })` can select `'whole'`, `'json'`, or a delimiter instead.
478
+ Config arrays and objects remain native; config strings use the env split policy.
479
+ `.separator('|')` becomes `.split({ cli: '|', env: '|' })` where the old
480
+ coupling was intended.
481
+
482
+ - **Breaking: `FlagSchema` and `ArgSchema` carry the cardinality axis.**
483
+ `FlagSchema` gains `split`, `duplicateKeys`, and `aggregateStandard`;
484
+ `ArgSchema` gains `separator`, `split`, `duplicateKeys`, `unique`, and
485
+ `aggregateStandard`. `elementSchema` and `separator` are valid on `keyValue`
486
+ as well as `array` flags, `standard` is valid on every kind, `aggregateStandard`
487
+ only on a kind that aggregates, and `stdin` is valid on scalar and collection kinds.
488
+ Definition documents serialize the new fields additively at `schemaVersion: 1`,
489
+ which has not shipped, with `split` and `splitPolicy` entries in the
490
+ meta-schema `$defs`.
491
+
492
+ - **Breaking: `.default()` on a variadic arg takes the array.** The type
493
+ parameter followed the element type, so the only value that compiled was a
494
+ single element, which is not what a variadic arg resolves to. It now follows
495
+ `ArgDefaultValue`, the value the arg actually produces:
496
+ `arg.string().variadic().default(['a', 'b'])`, and a record for
497
+ `arg.keyValue()`. `ArgDefaultValue` is exported from the package root.
498
+
499
+ - **Breaking: `ArgSchema.stdinMode` is now `ArgSchema.stdin`** — the boolean
500
+ carried no room for the trigger and sharing modes the unified source model
501
+ needs, so it is replaced by `stdin: StdinBinding | undefined`. `.stdin()` is
502
+ unchanged for callers who pass no options and keeps its exact resolution
503
+ behavior. Code reading the schema directly reads `schema.stdin !== undefined`
504
+ where `schema.stdinMode` used to be, and a definition passed to
505
+ `createArgSchema()` or `createCommandSchema()` writes `stdin: {}` instead of
506
+ `stdinMode: true`. The definition document changes to match: the arg fragment
507
+ emits `stdin: { when, consume }` in place of `stdinMode: true`, at
508
+ `schemaVersion: 1`, which has not shipped.
509
+
510
+ - **Breaking: `DUPLICATE_STDIN_ARG` is now `DUPLICATE_STDIN_INPUT`** — the rule
511
+ covers flags as well as args, and a flag-versus-flag conflict reporting an
512
+ arg-shaped code would be a lie. The message reads `Only one input may consume
513
+ stdin exclusively; <name> already consumes stdin`, naming the input that was
514
+ declared first. `details` names the offending input under `flag` or `arg` and
515
+ the existing one under `existingFlag` or `existingArg`.
516
+
517
+ - **Breaking: stdin values reach non-string codecs without their trailing line
518
+ terminator** — the stdin source hands the whole buffer over byte for byte, so
519
+ `echo hi | mycli` still gives a `string` input `'hi\n'`. Every other codec
520
+ interprets the text, where a terminator a pipe appended is framing rather than
521
+ value, so one trailing `\n`, `\r\n`, or `\r` is dropped before decoding.
522
+ `echo true | mycli` now resolves a boolean input to `true`, `echo 1h30m` to a
523
+ duration, and `echo eu` to an enum member; all three used to fail. A number
524
+ input is unaffected, since `Number()` already ignored the terminator. Stdin
525
+ also stops borrowing the prompt widening table: it accepts exactly what an env
526
+ value accepts, so the prompt-only `y` and `n` boolean spellings are rejected.
527
+
528
+ - **Breaking: a number input rejects blank text instead of reading it as zero.**
529
+ `Number('')` and `Number(' ')` are both `0`, so `PORT= mycli serve`,
530
+ `printf '\n' | mycli serve`, and a config key holding `""` all resolved a
531
+ number input to `0` without a word. All three now fail with `TYPE_MISMATCH`
532
+ and the same `Invalid number value '<redacted>' from …` diagnostic any other
533
+ unreadable value gets, and `mycli serve --port ''` fails at the parse boundary
534
+ where it quotes the token. Whitespace around a real number is still ignored,
535
+ so `' 42 '` and `'42\n'` are unaffected. A `count` flag already guarded this;
536
+ the number codec now does too. Set the variable, or drop it and let the
537
+ default apply.
538
+
539
+ - **Breaking: `CLISchema.commands` and `CLISchema.defaultCommand` hold
540
+ `CommandSchema`** — both used to hold `ErasedCommand` wrappers carrying the
541
+ action handler and an `_execute` function. The execution graph now lives
542
+ beside the schema instead of inside it, so `app.schema.commands[0]` is the
543
+ command schema itself: read `app.schema.commands[0].name` where
544
+ `app.schema.commands[0].schema.name` used to be needed. `ErasedCommand` is
545
+ gone.
546
+
547
+ - **Breaking: `CLISchema.plugins` removed** — plugins are execution state, not
548
+ a description of the program, and `.plugin()` no longer writes to the schema.
549
+ Registration, order, and hook behavior are unchanged.
550
+
551
+ - **Breaking: `CLIBuilder` is factory-only** — its constructor is private, so
552
+ `new CLIBuilder(schema)` no longer compiles. Call `cli(name)` or
553
+ `cli({ ... })`; every builder method still returns a new builder.
554
+
555
+ - **Breaking: `CommandSchema.middleware` removed** — the executor builds the
556
+ handler chain from the builder's ordered execution steps, so registration
557
+ order, handler identity, and runtime behavior are unchanged.
558
+ `CommandDefinition` no longer accepts a `middleware` key, and
559
+ `createCommandSchema()` no longer emits one.
560
+
561
+ - **Breaking: `FlagSchema`, `ArgSchema`, and `CommandSchema` are sealed** — all
562
+ three carry a private brand, so an object literal assembled by hand no longer
563
+ type-checks where a schema is expected. Call `createFlagSchema()`,
564
+ `createArgSchema()`, or `createCommandSchema()` with a definition object to
565
+ obtain one; spreading a built schema keeps the brand, so
566
+ `{ ...schema, description }` still type-checks. `createSchema()` was renamed
567
+ to `createFlagSchema()`, which validates its fields against the kind and
568
+ normalizes a nested `elementSchema`.
569
+
570
+ - **Breaking: `createCommandSchema()` validates what the builder validates** — a
571
+ definition whose flags share a name, an alias, or a negated spelling on one
572
+ command now throws `FLAG_NAME_COLLISION`, and a flag spelled the same way as
573
+ one propagated from an ancestor command throws `PROPAGATED_FLAG_COLLISION`.
574
+ The whole tree is checked, nested subcommands included. Commands built with
575
+ `command()` already refused these at `.flag()` and `.command()`; a definition
576
+ composed as data used to build without complaint and then answer the shared
577
+ spelling with one flag only. Two flags both aliased `v` still parsed under
578
+ `--verbose` and `--version`, help listed `-v` on both, and `-v` set the
579
+ second. The arg invariants moved with them, so a definition declaring a
580
+ positional after a variadic one throws `INVALID_BUILDER_STATE`, and a second
581
+ stdin-backed input throws `DUPLICATE_STDIN_INPUT`, matching `.arg()`.
582
+ Previously, both combinations built without complaint. Two stdin-backed args
583
+ each resolved to the
584
+ whole of stdin, and a positional behind a variadic one silently never filled. Every arg error names the
585
+ command in `details`, since a definition tree reaches them at any depth and
586
+ the arg name alone does not say which command declared it. A flag or arg
587
+ named `__proto__` now throws `INVALID_SCHEMA` from both the factory and the
588
+ builder, the check `readFlags()` already applied to its definitions record.
589
+ The factory and `.arg()` used to accept the key, which sets a prototype rather
590
+ than an entry, so the flag or the value the user typed disappeared; `.flag()`
591
+ used to report `FLAG_NAME_COLLISION` against a flag the command never
592
+ declared. A flag record whose prototype is replaced throws `INVALID_SCHEMA`
593
+ too, since only its own keys are read: an object-literal `__proto__` key lands
594
+ there, and so does `Object.create(base)`, whose inherited flags the factory
595
+ silently dropped. `createCLISchema()` normalizes its commands through the same
596
+ factory and inherits every check, and `readFlags()` reports the same errors it
597
+ always did.
598
+
599
+ - **Breaking: `CLISchema` and `ConfigSettings` are sealed** — both carry a
600
+ private brand, so an object literal assembled by hand no longer type-checks
601
+ where either is expected. Call `cli()` for an executable program or
602
+ `createCLISchema()` for a description; spreading a built schema keeps the
603
+ brand, so `{ ...app.schema, name }` still type-checks. `createCLISchema()`
604
+ throws `INVALID_SCHEMA` on an empty name, which `cli('')` now does too.
605
+
606
+ - **Breaking: `createArgSchema()` validates its fields against the kind** — the
607
+ second parameter is now `ArgDefinitionOverrides<K>` rather than
608
+ `Partial<ArgSchema>`, so `enumValues` on a `string` arg (and the other
609
+ kind-scoped fields) stops compiling and throws `INVALID_SCHEMA` at runtime.
610
+ `enumValues` is required on an `enum` arg. A single definition object
611
+ (`createArgSchema({ kind: 'enum', enumValues })`) is accepted as well.
612
+
613
+ - **Breaking: `Out` gained a required `verbosity` member** — action handlers
614
+ can read `out.verbosity`, and `resolveRenderContext()` exposes the same
615
+ `verbosity` decision for custom content built before `.run()` (including
616
+ `--`-aware `--quiet`/`-q` detection). A hand-rolled `Out` object literal
617
+ stops compiling until it declares one; migrate to a real channel from the
618
+ testkit and spy on it instead:
619
+
620
+ ```ts
621
+ const [out] = createCaptureOutput();
622
+ vi.spyOn(out, 'info');
623
+ ```
624
+
625
+ Do not spread a channel (`{ ...out, info: vi.fn() }`) — its methods are
626
+ non-enumerable bound copies, so the spread result has none of them.
627
+
628
+ - **Breaking: `Out` and `RenderContext` are sealed** — both interfaces now
629
+ carry a private brand, so implementing or structurally constructing them
630
+ outside the framework no longer type-checks. They are framework-created,
631
+ non-exhaustive values: obtain instances from action parameters,
632
+ `createOutput()`, `createCaptureOutput()`, or `resolveRenderContext()`, and
633
+ expect new readonly members in minor releases. Helpers that only need a
634
+ subset can accept `Pick<Out, 'info' | 'status'>`-style capability types.
635
+
636
+ - **Breaking: internal execution fields left `RunOptions` and
637
+ `CLIRunOptions`** — `out`, `captured`, `mergedSchema`, `meta`, and `plugins`
638
+ were framework-populated fields marked `@internal` yet shipped on the public
639
+ option types. They now live on unexported internal execution options; code
640
+ passing them to `runCommand()` or `.execute()` stops compiling. Inject
641
+ writers via `createCaptureOutput()` options or `OutputOptions.stdout`/
642
+ `stderr` instead of replacing the channel wholesale.
643
+
644
+ - **Breaking: `.execute()` takes `CLIExecuteOptions`**. The new root export
645
+ carries the process-free option surface and has no `adapter` member; passing
646
+ one to `.execute()` stops compiling. `CLIRunOptions` now extends
647
+ `CLIExecuteOptions` with `adapter`, and `.run()` remains the only method that
648
+ accepts it.
649
+
650
+ - **Breaking: `CommandConfig` and the root `AnyCommandBuilder` export removed**.
651
+ `CommandConfig` described the builder's type-level accumulator shape but no
652
+ signature referenced it. `AnyCommandBuilder` is `@internal` erasure machinery
653
+ that appears only on `CommandBuilder`'s underscore members, so the package
654
+ root no longer exports the name.
655
+
656
+ - **Breaking: the canonical `$schema`/`$id` for definition documents is
657
+ self-hosted and format-versioned** —
658
+ `https://dreamcli.kjanat.dev/schemas/definition/v1.schema.json` replaces the
659
+ jsDelivr URL in `generateSchema()` output and in `definitionMetaSchema.$id`.
660
+ The `v1` segment tracks the definition format, so it stays valid for every
661
+ package release that emits `schemaVersion: 1`, and it is permanent once
662
+ published. The `@kjanat/dreamcli/schema` subpath and the jsDelivr URL keep
663
+ serving the same bytes as mirrors. Documents pinned to the old URL still
664
+ validate against a local copy but no longer match the meta-schema's `$schema`
665
+ constant.
666
+
667
+ - **Breaking: a command flag spelled like a root-owned flag now throws
668
+ `RESERVED_FLAG` at build time**
669
+ ([#84](https://github.com/kjanat/dreamcli/issues/84)). The root removes
670
+ `--json` and `--quiet`/`-q` from argv before dispatch, intercepts
671
+ `--version`/`-V` once a version is configured, and renders help for
672
+ `--help`/`-h` before a command's flags are parsed. A command declaring one of
673
+ those spellings used to build, run, and render help while its flag stayed
674
+ permanently at its default value. `.command()`, `.default()`, `.version()`,
675
+ `.manifest(data)`, and `createCLISchema()` now reject it with `CLIError` code
676
+ `RESERVED_FLAG`, checking each flag's canonical name, its aliases (hidden ones
677
+ included), and its custom negated spelling (`.negatable({ alias: 'quiet' })`)
678
+ through the whole nested subcommand tree. The error names the colliding flag
679
+ and the root flag that shadows it, and suggests renaming, or `out.status()`
680
+ for output that root `--quiet` suppresses. Near misses such as
681
+ `jsonOutput` or `quietMode` stay legal, the default `--no-<name>` spelling
682
+ never collides, and `version`/`V` stay available to a CLI that declares no
683
+ version.
684
+
685
+ - **`--completions` collision detection now covers negated spellings and the
686
+ definition path.** `.negatable({ alias: 'completions' })` and a
687
+ `createCLISchema()` definition carrying `completionsFlag` both used to build a
688
+ CLI whose command flag the planner intercepted. Both now throw `CLIError` code
689
+ `RESERVED_FLAG`, matching what `.completions({ as: 'flag' })` already rejected
690
+ on the builder.
691
+
692
+ ### Removed
693
+
694
+ - **Breaking: `.packageJson()`** — deprecated since 2.5. Use `.manifest()`,
695
+ which defaults to `files: ['package.json']` and accepts the same pre-loaded
696
+ data object.
697
+
698
+ - **Breaking: `.denoJson()`** — deprecated since 2.5. Use
699
+ `.manifest({ files: ['deno.json', 'deno.jsonc', 'jsr.json'] })`.
700
+
701
+ - **Breaking: `ManifestPresetSettings`** — the settings type of the two removed
702
+ presets. Use `ManifestSettings`, which adds `files`.
703
+
704
+ - **Breaking: `PackageJsonSettings`** — the deprecated alias for
705
+ `ResolvedManifestSettings`, the shape stored in
706
+ `CLISchema.packageJsonSettings`. The schema field itself is unchanged.
707
+
708
+ - **Breaking: `discoverPackageJson()`** — deprecated since 2.5. Use
709
+ `discoverManifest(adapter, { startDir, files: ['package.json'] })`; `files`
710
+ already defaults to `['package.json']`.
711
+
712
+ ### Fixed
713
+
714
+ - **A variadic argument could not take the prompt its flag twin takes.** The
715
+ argument prompt gate read the kind discriminator alone, so
716
+ `arg.string().variadic().prompt({ kind: 'multiselect' })` was rejected with
717
+ `Prompt kind 'multiselect' is not compatible with string argument <files>`
718
+ while `flag.array(flag.string()).prompt({ kind: 'multiselect' })` resolved,
719
+ and the scalar `input` and `select` kinds the flag surface rejects were
720
+ accepted, resolving a one-element array. The gate now reads the cardinality:
721
+ an argument that collects several values takes `multiselect`, and names itself
722
+ `variadic string argument <files>` when it reports a mismatch.
723
+ `AllowedArgPromptConfig<C>` follows the same rule, so the compiler agrees.
724
+
725
+ - **A collection given a config value of the wrong shape said less on the
726
+ argument surface.** `flag.array(...).config('p')` over `{ p: 5 }` reported
727
+ `Invalid array value from config p for flag --tags`; the positional twin
728
+ reported `Invalid value '<redacted>' from config p for argument <tags>`,
729
+ naming neither the shape nor a value it actually held. Both surfaces now word
730
+ it `Invalid array value` / `Invalid object value`, so the byte-for-byte
731
+ wording rule in [Diagnostics and redaction](https://dreamcli.kjanat.dev/guide/semantics#diagnostics-and-redaction)
732
+ holds for the collection faults too.
733
+
734
+ - **A builder could produce a schema its own factory refuses.** Each modifier
735
+ states the kinds it belongs to through a `this` constraint, which the compiler
736
+ enforces and a JavaScript caller does not see, so `flag.string().separator(',')`
737
+ built a string flag carrying a CLI delimiter and emitted a definition document
738
+ `createFlagSchema()` then rejected with `INVALID_SCHEMA`. Twelve modifiers on
739
+ the flag surface and eleven on the argument surface behaved this way. Every
740
+ builder modifier now runs the same check `createFlagSchema()` /
741
+ `createArgSchema()` run, so what a builder produces is always a definition the
742
+ framework reads back. A test calling such a modifier through `@ts-expect-error`
743
+ and expecting it to build needs `expect(...).toThrow()`.
744
+
745
+ - **The normalization factories accepted a kind they have no arm for.**
746
+ `createFlagSchema('nope')` and `createArgSchema('count')` built a schema whose
747
+ discriminator is outside `FLAG_KINDS` / `ARG_KINDS`, which every exhaustive
748
+ `switch (schema.kind)` downstream falls through. The types forbid the call,
749
+ but a JavaScript caller reached it, and the keyValue prompt gate showed such a
750
+ schema can reach a shipped diagnostic. Both factories now throw
751
+ `INVALID_SCHEMA` with `Unknown flag kind 'nope'` / `Unknown arg kind 'count'`,
752
+ listing the allowed kinds in `details.allowed`, on the two-argument path, the
753
+ definition path, and a nested `elementSchema`.
754
+
755
+ - **`flag.array()` with no element threw a raw `TypeError`.** The factory read
756
+ `.schema` off the element it was handed, so a JavaScript caller omitting it
757
+ got `Cannot read properties of undefined` instead of a framework error. It now
758
+ throws `INVALID_SCHEMA` with `flag.array() requires an element builder`.
759
+ `flag.keyValue()` and `arg.keyValue()`, whose element is optional, apply the
760
+ same check to an element that is supplied.
761
+
762
+ - **A positional cut a parse function's message at its last colon.** Off argv,
763
+ the argument surface rebuilt the reason for a failure by scanning the message
764
+ the flag surface had already written, keeping only the text after the final
765
+ `": "`. Anything a parse function put before a colon was lost, and a reason
766
+ whose own tail held a colon was dropped whole: `arg.url({ protocols: ['https'] })`
767
+ reported `Invalid value '<redacted>' from env ENDPOINT for argument <endpoint>: https`,
768
+ and `arg.date()` reported no reason at all. `arg.duration()`, `arg.bytes()`,
769
+ and every `arg.custom()` whose error text carries a colon were affected the
770
+ same way. Each surface now words its own diagnostic from the value layer's
771
+ verdict, so the reason reaches the argument surface whole.
772
+
773
+ A parse-function failure off argv is also worded the way the flag surface and
774
+ the command line already word it, so `Failed to parse env ENDPOINT for
775
+ argument <endpoint>: URL protocol 'http' is not allowed. Allowed: https`
776
+ replaces the `Invalid value '<redacted>' …` opening, which announced a
777
+ redaction in the same sentence that printed the parse function's own text.
778
+ A test asserting the old opening for a non-argv `arg.url()`, `arg.date()`,
779
+ `arg.duration()`, `arg.bytes()`, or `arg.custom()` message needs the new one.
780
+
781
+ - **A positional withheld what a type mismatch expected.** For a value no
782
+ boolean codec could read, the flag surface reported
783
+ `Invalid boolean value '<redacted>' …` and suggested
784
+ `Set VAR to true/false, 1/0, or yes/no`, while the argument surface reported
785
+ `Invalid value '<redacted>' …` and suggested only `Set VAR to a valid boolean`,
786
+ which is the question rather than the answer. A string a config object could
787
+ not fill carried no `expected` field and no suggestion at all on the argument
788
+ surface. Both now match the flag surface: the message names the type, the
789
+ details carry `expected`, and the suggestion names what the codec reads.
790
+
791
+ - **An argument kind with no compatible prompt was told to use `undefined`.**
792
+ `createArgSchema({ kind: 'keyValue', prompt: … })` reached the prompt gate,
793
+ which took the first allowed prompt kind from an empty list and reported
794
+ `Prompt kind 'input' is not compatible with keyValue argument <vars>. Use
795
+ 'undefined' instead` with `Change the prompt to { kind: 'undefined' }`. The
796
+ flag surface already had a branch for a kind that is not promptable at all;
797
+ both surfaces now share it and report
798
+ `keyValue arguments are not promptable` with `Remove the prompt config for <vars>`.
799
+
800
+ - **A key-value input told the user to write an array.** A config value of the
801
+ wrong shape for `flag.keyValue()` or `arg.keyValue()` reported
802
+ `Invalid array value from config c for flag --vars` with `expected: 'array'`
803
+ and `Set c to an array in your config`, which is not what an entries input
804
+ accepts and, for a config value that already was an array, not even a change.
805
+ The fault now carries the shape the cardinality wants: an entries input reads
806
+ `Invalid object value …` with `expected: 'object'` and
807
+ `Set c to an object in your config` on the flag surface and
808
+ `Use KEY=VALUE for <vars>` on the argument surface. A list input is unchanged.
809
+
810
+ - **Five types the stability page classified as public were exported from
811
+ nowhere.** `NodeProcess`, `DenoNamespace`, and `GlobalForDetect` are the host
812
+ objects `createNodeAdapter()`, `createDenoAdapter()`, and `detectRuntime()`
813
+ accept, and the page attributes all three to `@kjanat/dreamcli/runtime`, which
814
+ exported none of them; a caller injecting a host could not name the parameter
815
+ type. `StringArgElementConfig` and `WithoutArgElementEligibility` sat in the
816
+ same sentence as `StringElementConfig`, which the root entrypoint does export.
817
+ All five are now exported, along with the flag-side
818
+ `WithoutElementEligibility` its argument twin mirrors.
819
+
820
+ - **A definition document, its input schema, and help all dropped a default the
821
+ schema still resolved.** `generateSchema()`, `generateInputSchema()`, and
822
+ `formatHelp()` each reported a default only for `presence: 'defaulted'`, but
823
+ resolution uses any `defaultValue` a schema carries, and
824
+ `createFlagSchema({ kind: 'string', defaultValue: 'dist' })` keeps
825
+ `presence: 'optional'`. A document emitted from such a schema decoded back to
826
+ a flag with no default, so a round trip through the format changed behavior;
827
+ the input schema omitted `default`, and help omitted `(default: dist)` for a
828
+ flag that does resolve one. All three now report the default whenever the
829
+ schema carries one, on both surfaces, whatever the presence.
830
+ Builder-authored schemas are unaffected, since `.default()` sets the
831
+ defaulted presence.
832
+
833
+ Help no longer calls such an input required either. A default binding always
834
+ produces a value, so neither `REQUIRED_FLAG` nor `REQUIRED_ARG` can fire for a
835
+ schema carrying a `defaultValue`, yet `flag.string().default('dist').required()`
836
+ rendered `[required]` and hid its own default while the positional twin
837
+ rendered `(default: prod)` and still demanded a token as `<target>`. A
838
+ `defaultValue` now suppresses the `[required]` marker and the angle brackets on
839
+ both surfaces; an input without one is unchanged.
840
+
841
+ - **A duplicate key leaked its text from every non-argv source.** Under
842
+ `.duplicateKeys('error')`, `Duplicate key 'DB_PASSWORD' from env VARS for flag
843
+ --vars` quoted the key in the message, in `details.key`, and in `suggest`,
844
+ whatever source carried it. A key is half of a `KEY=VALUE` pair, so it is
845
+ value text from that source, and the same pair reported `Invalid key-value
846
+ pair '<redacted>'` when it failed to split instead. The key is now quoted only
847
+ for occurrences the user typed on the command line; stdin, env, config, and
848
+ prompt read `Duplicate key '<redacted>'`, carry no `key` in `details`, and
849
+ suggest `Set the repeated key once`. Both surfaces follow the rule.
850
+
851
+ - **A flag reported a JSON shape fault in the wrong order.** `Invalid JSON
852
+ value, expected an object from env VARS for flag --vars` put the expectation
853
+ between the fault and the source that carried it. The flag surface now words
854
+ it as the argument surface already did: `Invalid JSON value from env VARS for
855
+ flag --vars, expected an object`.
856
+
857
+ - **`ArgElementFragmentV1` was documented as public but exported from nowhere.**
858
+ `stability.md` classifies it with the other version 1 fragment types and
859
+ `schema-export.md` names it as the shape of an arg `elementSchema`, but the
860
+ type never reached `@kjanat/dreamcli`. It is exported now, alongside its
861
+ siblings.
862
+
863
+ - **A default rejected on a vowel-initial kind read `a array`.** The
864
+ construction-time `INVALID_DEFAULT` message built its subject with a fixed
865
+ article, so `createFlagSchema('array', …)` and `createFlagSchema('enum', …)`
866
+ produced `Default value for a array flag` and `Default value for a enum flag`.
867
+ Both now read `an`.
868
+
869
+ - **A duplicate key the user typed said it came from stdin.** Under
870
+ `.duplicateKeys('error')`, a repeat among CLI occurrences was worded
871
+ `Duplicate key 'A' from stdin for flag --v`, naming a source the value never
872
+ had, on a command with no pipe at all. CLI occurrences now name no source
873
+ (`Duplicate key 'A' for flag --v`), and a key a `-` occurrence spliced in
874
+ still reads `from stdin`. Each occurrence carries its own source through
875
+ aggregation, so a collection filled from both names whichever one carried the
876
+ repeat. `details` no longer claims `source: 'stdin'` for a typed token, and
877
+ the arg surface follows the same rule with `for argument <vars>`.
878
+
879
+ - **`flag.count().stdin()` threw only on the definition path.** The builder
880
+ method is blocked by its `this` constraint at compile time and
881
+ `createFlagSchema('count', { stdin: {} })` throws `INVALID_SCHEMA`, but a
882
+ JavaScript caller reaching the builder got a count flag carrying a stdin
883
+ binding no stage would ever read. The builder now throws the same error, with
884
+ the same message and code. In 3.x neither path complained: `createSchema()`
885
+ stored `stdinMode: true` on a count flag and `.stdin()` did not exist on the
886
+ count builder at all.
887
+
888
+ - **Flags named after `Object.prototype` members were rejected as duplicates** —
889
+ `.flag('constructor')`, `.flag('toString')`, `.flag('valueOf')`, and every
890
+ other `Object.prototype` member name failed with a `FLAG_NAME_COLLISION`
891
+ claiming the command already declared the flag, on commands that declared no
892
+ flags at all. `collectPropagatedFlags()` read its descendant records the same
893
+ way, so a propagated flag with one of those names would have stopped at every
894
+ intermediate subcommand, and `resolveFlags()` read an `.interactive()`
895
+ resolver's override record the same way, so the inherited method reached the
896
+ prompt gate as a config and failed the command with `CONSTRAINT_VIOLATED`.
897
+ `.flag()` refused the name first, so no 3.x CLI ever got that far. Every one of
898
+ those reads now tests own keys only, so all eleven of those names behave like
899
+ any other and `createCommandSchema()` accepts the schemas `command()` produces.
900
+ `__proto__` is the one `Object.prototype` name still rejected, with
901
+ `INVALID_SCHEMA` on both construction paths, listed under Changed above.
902
+
903
+ - **An env var named after an `Object.prototype` member always read as set** —
904
+ `.env('toString')` on a flag, or on an arg, looked the name up on the env
905
+ record without checking own keys, so an unset variable resolved to the
906
+ inherited method and failed coercion instead of falling through to config,
907
+ prompt, or default. Both lookups now test own keys.
908
+
909
+ - **`.run()` never read stdin for an arg named after an `Object.prototype`
910
+ member** — the precheck that decides whether to read stdin looked the arg name
911
+ up on the parsed positionals without checking own keys, so an arg such as
912
+ `.arg('toString', arg.string().stdin())` looked already supplied. `.run()`
913
+ skipped the read and the command failed with `Missing required argument`
914
+ however much was piped to it. The lookup now tests own keys. `.execute()` and
915
+ the testkit take `stdinData` from the caller and were never affected.
916
+
917
+ - **`out.table()` printed a native method for a column key named after an
918
+ `Object.prototype` member** — a column keyed `toString`, `constructor`, or any
919
+ other member name read the row with a bare lookup, so a row that carried no
920
+ such key rendered `[Function: toString]` in place of the empty cell every
921
+ other missing key produces. Dynamic rows typed as `Record<string, unknown>`
922
+ are the reachable case, including columns inferred from a first row that does
923
+ carry the key. Both the text renderer and the JSON projection now treat a key
924
+ that only `Object.prototype` carries as absent. A key held anywhere earlier in
925
+ the row's prototype chain still renders, so a class getter and an
926
+ `Object.create(defaults)` fallback reach the table as before.
927
+
928
+ - **A Standard Schema validator ran against a native method on a failed
929
+ resolution** — when a required flag or arg was missing, `resolve()` still ran
930
+ the Standard Schema pass before rethrowing, over a values record the failed
931
+ resolver had left empty. The pass read each declared name without checking own
932
+ keys, so a flag or arg named after an `Object.prototype` member handed its
933
+ `flag.custom()` / `arg.custom()` validator the inherited method. The user saw a
934
+ second, invented `CONSTRAINT_VIOLATED` beside the real error. The pass now
935
+ tests own keys.
936
+
937
+ - **Quiet mode leaked spinner and progress output** — activity handles now
938
+ resolve to no-ops under quiet verbosity, including interactive TTYs and
939
+ explicit static fallbacks. Consumers can route informational rows through
940
+ `out.info()` and rely on DreamCLI to suppress the complete presentation
941
+ layer without reading private output policy state.
942
+
943
+ - **`--json=true` and `--quiet=true` failed as unknown flags**
944
+ ([#85](https://github.com/kjanat/dreamcli/issues/85)). Both root flags now
945
+ take a value the way `flag.boolean()` does. `true` and `1` enable, `false`
946
+ and `0` disable, the last occurrence wins, and an invalid literal fails with
947
+ the parser's `INVALID_VALUE` error and exit code 2 instead of `Unknown flag`.
948
+ `--help`, `-h`, and `--version` still render ahead of that error, so a
949
+ mistyped value never hides the text that documents the flag. Short `-q` keeps
950
+ its presence-only form, matching short boolean flags at the command level.
951
+ `runCommand()` from `/testkit` reads the same layer, and tokens after `--`
952
+ still reach the command untouched.
953
+
10
954
  ## [3.0.1] - 2026-07-21
11
955
 
12
956
  No library code changed; this release ships agent-facing material that was
@@ -1451,7 +2395,13 @@ sections that follow. Upgrading from 2.x is covered by the new
1451
2395
  - MIT License.
1452
2396
  - Markdownlint configuration.
1453
2397
 
1454
- [Unreleased]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.17...HEAD
2398
+ [Unreleased]: https://github.com/kjanat/dreamcli/compare/v4.0.0-rc.1...HEAD
2399
+ [4.0.0-rc.1]: https://github.com/kjanat/dreamcli/compare/v3.0.1...v4.0.0-rc.1
2400
+ [3.0.1]: https://github.com/kjanat/dreamcli/compare/v3.0.0...v3.0.1
2401
+ [3.0.0]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.20...v3.0.0
2402
+ [3.0.0-rc.20]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.19...v3.0.0-rc.20
2403
+ [3.0.0-rc.19]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.18...v3.0.0-rc.19
2404
+ [3.0.0-rc.18]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.17...v3.0.0-rc.18
1455
2405
  [3.0.0-rc.17]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.16...v3.0.0-rc.17
1456
2406
  [3.0.0-rc.16]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.15...v3.0.0-rc.16
1457
2407
  [3.0.0-rc.15]: https://github.com/kjanat/dreamcli/compare/v3.0.0-rc.14...v3.0.0-rc.15