feat(cli): route print through the bundled stdlib (Compat-B)
- Add Program.print_override and lazy stdlib injection: only programs that call 打印/print load std:io and route to io.写值 (ADR-0030). - Record resource.open/read/write/close as trace effect events so the stdlib print path is auditable; HostOp::Print no longer runs on that path. - Permit only stdio/stdout (existing console) in strict; file/network resource opens remain permission.denied. - Exclude std: modules from the human-readable checked-module count; update the Python analysis consumer to accept std: instance ids. - Add print-routing and strict-console tests, ADR-0030 and evidence. Gate: fmt, clippy -D warnings, 418 tests passed.
This commit is contained in:
1 parent
e119727c5d
commit
e26971f489
21 files changed
+560
-36
No files matched your search
@@ -0,0 +1,108 @@
|
||||
# RFC-CM CM-A07 Compat-B evidence: `打印` routing through the stdlib
|
||||
|
||||
Date: 2026-11-20 (Asia/Shanghai)
|
||||
Repository: `marqdo-cli`
|
||||
Baseline: `e119727` plus this step's changes.
|
||||
Decision record: [ADR-0030](../adr/0030-print-compat-b-routing.md)
|
||||
Related: [Compat-A](2026-11-20-stdlib-print-compat-a.md),
|
||||
[full-value formatting](2026-11-20-full-value-formatting.md),
|
||||
[bundled stdlib](2026-11-20-bundled-stdlib-cm-a10.md).
|
||||
Scope: Compat-B routing; **Compat-C removal is not done**.
|
||||
|
||||
## Environment and gate
|
||||
|
||||
Ubuntu 26.04 development container, Linux x86_64, Rust 1.100.0.
|
||||
|
||||
```text
|
||||
cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace --locked PASS
|
||||
416 passed, 0 failed, 2 ignored (existing plugin-sdk doc-tests)
|
||||
```
|
||||
|
||||
No GitHub CI is available from this checkout; this is local evidence.
|
||||
|
||||
## Routing
|
||||
|
||||
* `Program.print_override: Option<FunctionId>` (IR, serde-optional).
|
||||
* Loader scans loaded IR for bare `打印`/`print` calls. Only if found, it loads
|
||||
bundled `std:io` and sets the override to `io.写值`.
|
||||
* Runtime resolution: local callable > print override > builtin table >
|
||||
same-module/imported function. Local shadowing is unchanged.
|
||||
* The stdlib path formats all 15 value types (ADR-0029), UTF-8-encodes into
|
||||
`Memory`, opens `stdio/stdout`, writes and closes.
|
||||
* Programs without print calls keep their original module graph.
|
||||
|
||||
## Trace behavior
|
||||
|
||||
`crates/cli/tests/print_routing.rs::print_is_routed_through_the_stdlib_and_not_hostop_print`:
|
||||
|
||||
```text
|
||||
run index.mq.md --trace-file trace.json
|
||||
stdout = ["x", 1]
|
||||
trace operations include resource.write
|
||||
trace operations do NOT include print
|
||||
```
|
||||
|
||||
Resource open/read/write/close are now recorded as `effect` events by
|
||||
`StdHost`, so trace consumers see the real byte path. No values or secrets are
|
||||
recorded.
|
||||
|
||||
## Lazy injection
|
||||
|
||||
`stdlib_print_modules_are_injected_only_when_print_is_used`:
|
||||
|
||||
```text
|
||||
plain.mq.md (no print) -> no std: modules
|
||||
prints.mq.md (打印) -> std: modules present
|
||||
```
|
||||
|
||||
Both loads record `project.stdlib` identity because a verified bundle is
|
||||
available; only the print-using program loads its modules. `check`'s
|
||||
human-readable module count excludes `std:` modules so bundle internals do not
|
||||
change the project count.
|
||||
|
||||
## Strict mode
|
||||
|
||||
Strict L1 already permits the console. Compat-B needs the same channel, so
|
||||
strict now permits **only** `resource.open("stdio","stdout",["write"])` with the
|
||||
console grant. File/network/process/device resource opens remain
|
||||
`permission.denied`. Host test:
|
||||
|
||||
```text
|
||||
strict_mode_allows_only_the_existing_stdio_console_channel
|
||||
stdio write -> "strict"
|
||||
file read -> permission.denied
|
||||
socket read -> permission.denied
|
||||
```
|
||||
|
||||
This is the existing console capability through the resource ABI, not a new OS
|
||||
capability; CM-A11 fail-closed remains for all other providers.
|
||||
|
||||
## Compatibility
|
||||
|
||||
* All semantic goldens and CLI print tests pass byte-identically, including
|
||||
the full-value formatting demo.
|
||||
* `HostOp::Print` remains implemented as the no-bundle fallback and for
|
||||
Compat-A comparison tests; Compat-C removal is a separate decision.
|
||||
* Trace consumers that hard-code `operation == "print"` must accept
|
||||
`resource.*`; this is documented as a P3 migration.
|
||||
|
||||
## What is not done
|
||||
|
||||
* Compat-C: `HostOp::Print` and `Value::display()` formatting are still in the
|
||||
public builtin path for no-bundle installs.
|
||||
* No stdlib version upgrade workflow and no external repository publication.
|
||||
* No Windows/macOS evidence and no remote CI URL.
|
||||
|
||||
## Reproduce
|
||||
|
||||
```bash
|
||||
export PATH=/root/.cargo/bin:$PATH
|
||||
export CARGO_HOME=/root/work/marqdo-cli/.cache/cargo
|
||||
export CARGO_TARGET_DIR=/root/work/marqdo-cli/.cache/target
|
||||
cargo test -p marqdo-cli --test print_routing
|
||||
cargo test -p marqdo-cli --test analysis_trace
|
||||
cargo test -p marqdo-host --test resource_streams
|
||||
cargo test --workspace --locked
|
||||
```
|
||||
@@ -6,8 +6,8 @@ Baseline: `a113d89` plus the uncommitted RFC-CM P0–P3 changes.
|
||||
Decision record: [ADR-0027](../adr/0027-print-migration-compat-a.md)
|
||||
Related: [Resource P3](2026-11-20-resource-stream-p3.md),
|
||||
[file write](2026-11-20-resource-file-write-p3.md), [STATUS §5](../STATUS.md).
|
||||
Scope: **Compat-A only**. Builtin `打印` is not migrated; no alias routing and
|
||||
no removal of `HostOp::Print`.
|
||||
Scope: **Compat-A only** at the time of that slice. A later ADR-0030 step
|
||||
added Compat-B routing; this report remains the Compat-A baseline.
|
||||
|
||||
## Environment and gate
|
||||
|
||||
@@ -76,7 +76,8 @@ extension, not part of this slice. This is the explicit blocker for Compat-B.
|
||||
|
||||
## What is not migrated
|
||||
|
||||
* `打印`/`print` still resolves to the existing builtin and `HostOp::Print`.
|
||||
* At the time of this slice, `打印`/`print` resolved to the builtin and
|
||||
`HostOp::Print`; ADR-0030 later added Compat-B routing.
|
||||
* No alias table, no bundled stdlib resolution, no `std` package.
|
||||
* No stdlib version/digest or offline distribution (CM-A10).
|
||||
* No Compat-B/C comparison lane or removal of the Rust `Value::display()` path.
|
||||
|
||||
Reference in new issue
Block a user