# Cmder interface redesign

This spec implements the six improvements approved on 2026-11-05. Breaking changes are intentional; publishing is outside this task.

## Execution and errors

- Command and root callbacks have type `(Context) -> Unit raise`. Their original business errors propagate through dispatch and run without conversion to CliError or text.
- `cli` supports root options, positionals, examples, callback and subcommands. Only the selected callback runs.
- `parse` has explicit argv, no I/O or execution, and always checks declared integer inputs in selected scopes after structural parsing. Help/version retain parser precedence.
- `get_int` returns None only for absence and raises InvalidInteger/IntegerOutOfRange otherwise; no legacy length cap or separate checked getter remains. Required getters raise CliError.
- Optional labelled arguments use direct values: `default=3`, `run=fn(ctx) { ... }`, `app.run(argv=[...])`.

## Definitions and scopes

- Option definitions are helper-constructed, immutable and carry a typed kind: string default String?, integer default Int32?, or Boolean flag. Short names are Char?. Defaults normalize effective required to false; Boolean flags are optional, initially false.
- Command collections are copied into ReadOnlyArray. CliApp owns a single root CommandDef and version. External collection mutation cannot alter the application.
- `cli` validates the entire definition tree during construction and raises InvalidDefinition for invalid names, duplicate names/short spellings, invalid positional ordering, or descendant conflicts with inherited global names/shorts. Sibling local names may repeat.
- Names consist of ASCII letters/digits/underscores/hyphens, without leading or trailing hyphens. Short spellings are ASCII letters/digits/underscores. Descriptions remain unrestricted text and are encoded for each shell's quoting and completion grammar.
- Required positionals cannot coexist with subcommands, because argparse makes those descendants unreachable; reject the combination in every scope. Optional positionals can coexist, but positional consumption prevents later selection of a subcommand.
- Only `global=true` options are shared with descendants and accepted before/after a subcommand. Other options and positionals remain local to the declaring command.
- A selected invocation exposes only its selected command's locals and inherited globals. Ancestor local values do not leak or get reinterpreted. Each global has one canonical definition; descendants cannot redefine it.
- Defaults apply only when that argument has no explicit value. The same definitions drive parsing, help, schema and completion. Schema defaults use their JSON types and include global metadata and root positionals/examples.

## Invocation and host overrides

- Invocation exposes a read-only command path and Context; all Context storage is private and returned value collections are copies/read-only.
- Invocation binds the selected command snapshot. `call.dispatch()` executes that callback without resolving against another application, reparsing or implicit I/O. Repeated calls execute again.
- Dispatch of a root without callback raises MissingCommand; selected groups/leaves without callbacks raise the appropriate MissingSubcommand/MissingHandler error.
- `with_overrides` accepts typed text/integer/flag/positional values, checks visible names, kinds and positional cardinality, then returns a fresh invocation atomically. Failed overrides preserve the original result.
- Changed values have Override provenance; unchanged sources remain intact. Original raw argv spellings survive normal parsing. No stale provenance can be created by direct mutation.
- Context no longer carries the unused subcommand tree. Selected path belongs to Invocation.

## Acceptance evidence

Tests cover original business error propagation through run/dispatch, roots and nested callbacks, integer absence/format/overflow/padding, global scope and argument placement, local isolation, definition rejection, alias safety, bound repeated dispatch, valid/invalid atomic overrides and provenance, root schema/help/completion, and process exit/output behavior on native/JS/wasm-gc.

English/Chinese README and executable examples demonstrate the new interfaces and contain a migration guide. Generated interfaces are regenerated by MoonBit. Independent Standards and Spec review must have no unresolved actionable findings before commit.
