0050. The cli platform passes capabilities to main
- Status: Accepted
- Date: 2026-10-31
- Plan: M6.1, M6.3, M6.7, M10.2–M10.3
- Review: Platforms are the missing extension point; extends ADR-0005
Context
Effects need explicit, unforgeable authority without adding grammar or inflating scalar programs. The built-in platform must be movable into M10's plugin manifest.
Decision
Accept fn main() and
fn main(cli: Cli) -> result<unit, CliError>;
the parameter name is arbitrary. Capabilities are checked
Type::Cap values erased to IR unit (File later erases
to i64). They can be passed, stored and specialized normally, but
never constructed or concretely compared. Generic equality
compares units.
platform.rs is a data table of capability fields
and methods, with marked L1, L2, L3 and L4 sections. Effects lower
through lower_platform.rs and
Rvalue::Platform; pure operations remain intrinsics.
Feature bits select runtime includes. Stage A installs all five
include-guarded headers and driver entries. No platform use means
byte-identical existing IR/C.
Output is cli.stdout.print/println/write/flush,
likewise stderr. Printable interpolation keeps the direct
no-allocation path. Cli also exposes stdin, args, raw_args, env,
fs and process, implemented in their later tasks. No parser
changes.
Removal lands in three stages: A adds this surface beside global print; B uses a compiler-backed call-graph codemod; C rejects globals with E0800 and deletes the codemod. No public transition period: CP-6.1 has no global I/O.
M6.7 CLI tools belong at
bench/cli/harness/<tool>.hn for
python3 bench/cli/run.py --id <cp>, or
examples/tools/ with --harness-bin-dir.
Do not change the benchmark runner to locate them.
Alternatives considered
- Keep global print — ambient authority violates ADR-0005.
- Import cli or use cli.println — imports are not authority; separate streams support later attenuation and familiar stdout/stderr vocabulary.
- Real capability structs now — no runtime state is needed before attenuation.
Consequences
Stage A is the branch point for paths, maps and streams. M5.8
follows M6.2 and uses cli.stdin.read_all(), never a
new global read_stdin. Empty pure main remains legal and keeps
diagnostic fixtures stable. ADR-0051 defines the synthetic entry
point and unit-result rules. Parameter assignability remains an
open decision.