feat(ext): single callable binding, provider v2 CLI, capability handlers, stdlib aliases

Implements RFC-EXT-0001 PR-00..PR-07 first pass:
- CallSiteKey/CallBindingTable + one frontend binding pass; runtime dispatch by identity
- prepare composition root shared by check/run/inspect/Analysis; exact plugin reconciliation
- provider.json v2 --provider/--allow-provider worker CLI with fail-closed verification
- capability handler registry with real fs.read and audit
- verified stdlib public aliases replace print_override/AST scan
- docs: specs, ADR-0054/0055/0057/0058, README, CI/release gates, evidence

PR-04 extension selection/lock v4 and final frozen-binary evidence remain.
This commit is contained in:
cflmy committed 2026-11-22 00:17:36 +08:00
1 parent 9aa536c2c9
commit 1f6fd644a0
54 files changed
+8710 -828

No files matched your search

@@ -0,0 +1,195 @@
# RFC-EXT-0001 implementation evidence (P0 core + PR-03/05/06/07 first pass)
Status: **partial, honest record.** PR-00/01/02/03/05/06 are implemented and
tested on Linux x86_64 in this tree; PR-04 (extension selection/lock v4) and the
final frozen-release evidence are still in progress. This document is not a
release claim. The authoritative executed status is regenerated in
`docs/STATUS.md` and `docs/evidence/extension/<SHA>/manifest.json`.
## 1. Identity and environment
| Field | Value |
|---|---|
| Trees | `/root/work/marqdo-cli` (branch `feat/extensible-ecosystem`) and separate `/root/work/marqdo-extension-conformance` |
| Baseline | `595279fe38048b52b96d9ff1e7d57a867ec5c4c6`; green baseline in `docs/evidence/ext-baseline-595279f.md` |
| Rust | `rustc 1.100.0`, `cargo 1.100.0` |
| OS / arch | Linux x86_64 |
| Commands | logged under `.cache/ext/` (gitignored) |
No commit SHA is claimed for the implementation yet: work is uncommitted on the
feature branch, so this file cannot be a same-SHA release artifact.
## 2. Executed workspace gate (current tree)
```text
cargo fmt --all -- --check PASS (exit 0)
cargo clippy --workspace --all-targets -- -D warnings PASS (exit 0)
cargo test --workspace --locked PASS (exit 0)
66 test targets: 584 passed, 0 failed, 0 ignored
```
Targeted new suites:
```text
cargo test -p marqdo-cli --test callable_resolution 14 passed
cargo test -p marqdo-cli --test stdlib_alias_routing 5 passed
cargo test -p marqdo-cli --test provider_cli 12 passed
cargo test -p marqdo-cli --test analysis_trace 7 passed
cargo test -p marqdo-cli --test plugin_worker 4 passed
cargo test -p marqdo-cli --test print_routing 2 passed
cargo test -p marqdo-cli --test architecture_boundaries 9 passed
cargo test -p marqdo-host (includes capability_handlers 12)
```
## 3. What was implemented (source paths)
### PR-01/02 — one static binding, bound runtime dispatch
* `crates/marqdo-ir/src/call_binding.rs` — `CallSiteKey`, `BoundTarget`
(`Builtin`/`Marqdo`/`AbiPlugin`/`DynamicValue`), deterministic
`CallBindingTable`, unit tests.
* `crates/marqdo-ir/src/callable.rs` — `try_from_program` (rejects duplicate
exports instead of first-wins), `OfficialAlias` registration, dotted-prefix
conflict helpers, `function_id`.
* `crates/marqdo-frontend/src/calls.rs` — the single `bind_program_calls` pass,
RFC priority matrix, import namespace conflicts, exact plugin signature
validation; `validate_module` is a standalone-frontend wrapper.
* `crates/marqdo-frontend/src/analyze.rs` — `analyze_source_for_program` defers
call checking to the composition root; standalone `analyze_source` keeps its
single-document checks for the conformance corpora.
* `crates/marqdo-runtime/src/interpreter.rs` — dispatch by `CallSiteKey`; the
unknown-plugin fallback, `print_override` branch and dead `resolve_function`
are removed; bound ABI calls normalise positional arguments to manifest order.
* `crates/cli/src/extension_descriptors.rs` — static plugin manifest reading
(no `dlopen`/spawn), signature parsing (defaults rejected), bundle-relative
path checks, artifact sha helpers.
* `crates/cli/src/project_prepare.rs` — one `prepare()`: load → descriptors →
registry → bind once → `PreparedProgram`; diagnostics are appended once.
* `crates/cli/src/commands/{check,run,inspect}.rs` + `loader.rs` — all consume
`prepare_project`; `run` verifies artifacts before load and reconciles the
Host exports one-to-one (`ext.plugin_binding_mismatch` on any difference).
* `crates/cli/src/analysis.rs` — Analysis `calls[].state/target` are projected
from the same binding table (no second resolver).
* `crates/cli/tests/callable_resolution.rs` — CALL-01/02/03/04/05/06/07/08/09/
11/12/13/14/15/16 as black-box CLI tests (CALL-10 has unit coverage in
`commands/run.rs` for missing/extra runtime exports).
Normative docs: `spec/callable-resolution.md`, `docs/adr/0054-*`,
`spec/plugin-abi.md` §12, `spec/analysis-v2.md` calls note.
### PR-03 — resource provider v2 through the normal CLI
* `crates/cli/src/main.rs` — repeatable `--provider PATH` and
`--allow-provider NAME` on `run`/`call` only.
* `crates/cli/src/commands/sandbox.rs` — grants map to
`allow_resource_provider`; `pure`/`strict` preflight refuse the flags;
wildcards rejected.
* `crates/cli/src/provider_manifest.rs` — strict schema v2 parser/verifier,
target selection, bundle containment, sha256, reserved-kind rejection,
duplicate kind/provider checks, sibling `marqdo-provider-worker` resolution
(no `PATH` fallback; `ext.worker_unavailable`/`ext.platform_unsupported`).
* `crates/cli/src/commands/run.rs` — verify all manifests/artifacts/grants and
duplicate kinds before spawning; spawn only granted+verified providers; no
native fallback; no new `HostOp`/`resource_request` branch.
* Tests: `crates/cli/tests/provider_cli.rs` (real C sensor + real worker
helper), 12 tests; `spec/resource-provider-v2.md`, ADR-0055, README section.
Provider evidence recorded by the PR-03 implementer:
| ID | Result | Evidence summary |
|---|---|---|
| PROV-01 | PASS | exit 0, `count=5`, `eof=true`, one worker/open/close marker |
| PROV-02 | PASS | exit 1 `permission.denied`; helper never started |
| PROV-03 | PASS | exit 2 `ext.provider_grant_unmatched`; no worker |
| PROV-04 | PASS | exit 2 `ext.duplicate_provider_kind`; no worker |
| PROV-05 | PASS | one provider, two kinds, counts `[5,2]`, both closed |
| PROV-06 | PASS | `stdio/file/tcp/tls/udp/tcp-listener` rejected `ext.manifest_invalid` |
| PROV-07 | PASS | sha mismatch / symlink escape / `..` → `ext.artifact_integrity` before spawn |
| PROV-08 | PASS | `ext.no_matching_artifact` |
| PROV-09 | PASS | v1 → `ext.unsupported_provider_schema`, no migration |
| PROV-10 | PASS | pure `cli.invalid_grants`, strict `strict.unsupported_grant`, `*` rejected |
| PROV-13 | PASS | sibling helper missing → `ext.worker_unavailable`, PATH helper unused |
Platform: provider worker transport is claimed **linux/x86_64 only**; macOS and
Windows are explicitly `UNSUPPORTED`/fail-closed (`ext.platform_unsupported`),
not claimed supported. PROV-11/12/14/15 belong to host-protocol and PR-07
external closure and are not claimed by the PR-03 CLI matrix.
### PR-05 — capability handler registry
`crates/marqdo-host/src/capability.rs` now has a trusted handler directory,
`fs.read` as a real handler, decide → handler-installed → execute under budget →
audit with duration; missing handler stays `capability.unavailable`, duplicate/
reserved/empty registrations are rejected. `crates/marqdo-host/tests/
capability_handlers.rs` has 12 CAP tests (CAP-01…CAP-12); ADR-0057 and
`spec/security.md` updated. `cargo test -p marqdo-host` PASS.
### PR-06 — official stdlib public aliases
`stdlib/stdlib.json` declares `public_aliases` (`print`/`打印` →
`io.mq.md::写值`) and `aliases_digest`; `crates/cli/src/stdlib.rs` verifies the
metadata digest and expected target signature; `loader.rs` loads the target
module only when the alias name is referenced and produces `OfficialAlias`
records; `project_prepare` registers them and the binding pass targets the
ordinary `Marqdo` function. `program_uses_print`, `Program.print_override`, the
runtime print branch and the AST scanner are deleted; the placeholder builtin
still fails with `kernel.unavailable` for unbundled embedders. Tests:
`crates/cli/tests/stdlib_alias_routing.rs` (5) + existing print/format/Trace
goldens; the stdlib fixture aliases that collided with builtin namespaces
(`table`/`text`/`fs`) were renamed and the bundle digest regenerated.
`tools/pack-stdlib.py` verifies `aliases_digest` before packaging.
ADR-0058 documents the decision.
### PR-07 (first pass) — independent external repository
`/root/work/marqdo-extension-conformance` is a separate Git repository (own
history, remote `https://git.cflmy.cn/cflmy/marqdo-extension-conformance`,
pushed; commit `b729afc` at the time of this record). It contains:
* `pure-lib/` + `consumer/` with a pinned full-SHA Git dependency;
* `plugin/` — real C ABI v1 worker plugin, three exports under two prefixes;
* `kernel/` — `mocklang` provider with a language the CLI does not know;
* `provider/` — `provider.json` v2 + real C ABI sensor library;
* `tool/` — stdlib-only Python consumer of Analysis v2 / Trace v2;
* `tests/run_all.py`, `tests/verify_frozen_cli.py`, `CONTRACT.md`,
`.github/workflows/conformance.yml`.
Provisional run against the current development binary (debug build, not a
release candidate):
```text
[PASS] plugin_worker, callable_registry, foreign_kernel,
resource_provider_cli, package_pinned_git,
tool_analysis_consumer, negative_security
(all categories PASS; frozen CLI sha256 recorded in evidence/results.json)
```
This is **not** final PR-07/PR-08 evidence: the binary was not a `--release`
candidate, and `tools/ci/verify_extension_contracts.py` has not yet emitted a
`docs/evidence/extension/<SHA>/manifest.json`. The external suite will be rerun
against the frozen release binary after PR-04 lands.
## 4. Known gaps / deviations (not hidden)
1. **PR-04 not landed yet.** `marqdo.yaml.extensions` and lock v4 are still in
progress; the CLI composition root for extension selection is not wired.
2. **Provider platform claims are Linux x86_64 only**; macOS/Windows are
explicitly unsupported for the worker transport. The RFC's mac/Windows
provider lanes are not claimed.
3. **Additive provider error codes** `ext.manifest_invalid`,
`ext.duplicate_provider`, `ext.provider_grant_unmatched` were added because
the RFC's frozen code list has no precise code for malformed v2, duplicate
provider names, or an unmatched `--allow-provider`; documented in
`spec/resource-provider-v2.md` and ADR-0055.
4. **`--allow-provider` without a selected manifest** aborts with
`permission.denied` before spawning rather than silently ignoring the grant
(needed to satisfy PROV-02 with the existing spawn-on-register Host API).
5. **Analysis v2 `calls[].state/target` semantics changed for official aliases**
(print now projects as a `function` target). This is a projection of
existing fields, documented in `spec/analysis-v2.md`/ADR-0054/ADR-0058;
there is no v3 bump and the private binding table is not exposed.
6. **CALL-10's host-side mismatches** are unit-tested for missing/extra exports;
a live TOCTOU signature/digest mismatch is covered by artifact-tamper tests
plus exact reconciliation, not by swapping a manifest mid-run.
7. Full `--release` build, frozen external rerun, SHA-bound evidence manifest,
docs/STATUS/CURRENT/COMPATIBILITY/CHANGELOG finalisation remain for PR-08.
+82
View File
@@ -0,0 +1,82 @@
# RFC-EXT-0001 baseline audit — `595279f`
Status: **baseline evidence recorded before implementation.** This is not a
release claim and none of the new RFC-EXT-0001 behaviour existed at this SHA.
## 1. Identity and environment
| Field | Value |
|---|---|
| Repository | `cflmy/marqdo-cli` (private remote `https://git.cflmy.cn/cflmy/marqdo-cli`) |
| Baseline commit | `595279fe38048b52b96d9ff1e7d57a867ec5c4c6` (`master`, 2026-11-21) |
| Working branch | `feat/extensible-ecosystem` |
| Rust | `rustc 1.100.0 (0ef1bc386 2026-11-09)` |
| Cargo | `cargo 1.100.0 (3acc79c0c 2026-11-05)` |
| OS / arch | Linux `x86_64` (Ubuntu container) |
| Local homes | `RUSTUP_HOME=.rustup-home`, `CARGO_HOME=.cargo-home` |
| Command log | `.cache/ext/baseline.log` (local, gitignored) |
## 2. Executed gate (same SHA, before any RFC-EXT-0001 edit)
```text
cargo fmt --all -- --check exit 0 PASS
cargo clippy --workspace --all-targets -- -D warnings exit 0 PASS
cargo test --workspace --locked exit 0 PASS
62 test targets: 521 passed, 0 failed, 2 ignored
```
The RFC §2.2 static inventory commands were also run and their findings are
recorded in §3. A green baseline is only the starting point, not evidence for
any new feature.
## 3. Source facts at the baseline (RFC §2.1 refresh)
Each row was checked against the actual tree, not against the RFC prose. None of
the rows was `already_closed` at `595279f`.
| ID | Observed at `595279f` | Impact | RFC treatment |
|---|---|---|---|
| EXT-01 | `marqdo-frontend/src/units.rs` `SemanticMode` is `Exec`/`Knowledge` only; unknown `@xxx` is `sem.invalid_mode_marker` | third parties cannot add an execution mode (intended closure) | keep; metadata is inert Markdown |
| EXT-02 | `frontend/src/calls.rs` checks Member builtin before import; `runtime/src/interpreter.rs` checks import before builtin | check and run can bind different targets | PR-01/02 single binding |
| EXT-03 | `ir/src/callable.rs` has `CallableRegistry` but calls still use `builtins::find` and runtime fallbacks | registry was not the single truth | PR-01/02 |
| EXT-04 | interpreter tolerated undeclared `alias.name` as a plugin call when `external_callables` was empty | static-unknown symbol failed only at run time | PR-02 remove fallback |
| EXT-05 | `cli/src/commands/run.rs` synthesised `params: Vec::new()` descriptors for loaded exports | manifest/runtime signature could differ silently | PR-02 exact reconciliation |
| EXT-06 | `loader.rs` validated the program before the CLI appended static plugin descriptors, then validated again | duplicated diagnostics and ordering hazards | PR-01 single `prepare` finalize |
| EXT-07 | `host/src/host/providers.rs` has Rust/C/Worker provider registration; CLI had no `--provider` | providers were only reachable by trusted embedders | PR-03 |
| EXT-08 | `host/src/capability.rs::execute` implemented only `fs.read`; other names returned unavailable | declaring a capability did not mean executing it | PR-05 handler registry |
| EXT-09 | `host/src/host.rs::resource_request` has per-string built-in operations | adding a non-streaming operation required core edits | PR-03/05; keep core operations |
| EXT-10 | `cli/src/loader.rs::program_uses_print` injected `stdlib/io.mq.md` and set `Program.print_override`; runtime special-cased `打印/print` | migrating another stdlib function by copying this pattern would hard-code every name | PR-06 public aliases |
| EXT-11 | `foreign/src/lib.rs::KernelRegistry` supports unknown languages; old `normalize_language` only knows Python/Node | registry is the execution path, legacy helper is display-only | keep registry as the only query |
| EXT-12 | Plugin ABI v1 Native/Worker implemented; Wasm unsupported; Tool Protocol tested | do not rebuild plugin/tool platform | keep + add identity reconciliation |
| EXT-13 | `package/src/lib.rs` supports path + pinned `git` + package instances; `stdlib/` is a verified bundle | real `.mq.md` source decoupling exists | keep + external black-box test |
| EXT-14 | strict L1 permits only limited pure computation and stdout and rejects Worker/Foreign/Provider | project mode is not an OS sandbox | keep fail-closed; strict L2 is a separate RFC |
## 4. Issues reproduced while recording this baseline
They were reproduced while writing the RFC acceptance fixtures; all are fixed by
the PR series recorded later in `docs/STATUS.md` and
`docs/evidence/extension/<SHA>/manifest.json`:
1. **Duplicate resolution (EXT-02/03/04).** A fixture with an import alias that
matched a builtin dotted namespace (`import: {math: ./math.mq.md}` plus
`math.eval(...)`) had no deterministic binding rule; the frontend checked the
builtin while the runtime checked the import first.
2. **Runtime plugin guessing (EXT-04).** `solver.add(...)` without `--plugin`
reached the runtime and attempted `PluginInvoke` instead of failing during
`check` with `symbol.unknown`.
3. **Synthesised plugin signatures (EXT-05).** `run` could execute a plugin
export whose static descriptor had an empty parameter list, so an arity or
position/name mismatch was only discovered (or not) at the ABI boundary.
4. **Print magic (EXT-10).** `打印`/`print` were routed by a whole-AST
`program_uses_print` scan plus a runtime name special case; there was no
generic de-magicking path for a second official stdlib function.
5. **Provider CLI gap (EXT-07).** There was no `--provider`/`--allow-provider`;
an external `provider.json` could not be used through the shipped binary.
## 5. Not claimed by this baseline
* No `--provider`/`--allow-provider` existed; strict L2 remains unimplemented.
* No frozen-binary external repository evidence existed.
* No `docs/evidence/extension/<SHA>/manifest.json` existed.
* G3 remote security and G4 performance status is unchanged by this document;
see `docs/STATUS.md` and `docs/releasing.md`.
+32
View File
@@ -0,0 +1,32 @@
# External-extension evidence
RFC-EXT-0001 §10.2/§11.3 requires SHA-bound proof that an **unchanged** CLI
binary can use extensions from physically separate Git repositories. This
directory holds that evidence.
* `schema.json` — JSON Schema for the evidence manifest.
* `<40-hex-source-SHA>/manifest.json` — generated by
`tools/ci/verify_extension_contracts.py`; never hand-written.
Generation (from a clean fixture checkout and a release build of this repo):
```bash
cargo build --release --locked -p marqdo-cli
CLI="$(realpath target/release/marqdo)"
python3 tools/ci/verify_extension_contracts.py \
--cli "$CLI" \
--fixtures /path/to/marqdo-extension-conformance
python3 tools/ci/verify_extension_contracts.py \
--validate docs/evidence/extension/<SHA>/manifest.json
```
The generator refuses to write evidence when:
* the CLI binary hash changes between the start and end of the suite;
* the fixture repository has uncommitted changes;
* a required result is missing or `FAIL`;
* `UNSUPPORTED`/`SKIPPED` is recorded without `--allow-unverified` and a report
entry explaining the platform limitation.
A local or container run is **not** a substitute for the release gates in
`docs/releasing.md` (G3/G4), and no tag is created by this evidence.
+63
View File
@@ -0,0 +1,63 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/extension-evidence-v1.json",
"title": "Marqdo external-extension evidence manifest",
"description": "SHA-bound evidence that independent repositories can use the frozen CLI without modifying or recompiling marqdo-cli (RFC-EXT-0001 §11.3). Generated by tools/ci/verify_extension_contracts.py; never hand-edited.",
"type": "object",
"additionalProperties": false,
"required": [
"schema",
"schema_version",
"tested_sha",
"cli_binary_sha256",
"fixture_repo_sha",
"os",
"arch",
"results",
"commands",
"failures",
"unverified"
],
"properties": {
"schema": { "const": "marqdo.extension-evidence" },
"schema_version": { "const": 1 },
"tested_sha": {
"type": "string",
"pattern": "^[0-9a-f]{40}$",
"description": "Exact marqdo-cli source commit the frozen binary was built from."
},
"cli_binary_sha256": {
"type": "string",
"pattern": "^[0-9a-f]{64}$"
},
"fixture_repo_sha": {
"type": "string",
"pattern": "^[0-9a-f]{40}$"
},
"os": { "type": "string", "enum": ["linux", "macos", "windows"] },
"arch": { "type": "string" },
"results": {
"type": "object",
"additionalProperties": {
"type": "string",
"enum": ["PASS", "FAIL", "UNSUPPORTED", "SKIPPED"]
},
"required": [
"callable_registry",
"plugin_worker",
"foreign_kernel",
"resource_provider_cli",
"package_pinned_git",
"tool_analysis_consumer",
"negative_security"
]
},
"commands": {
"type": "array",
"items": { "type": "string" },
"minItems": 1
},
"failures": { "type": "array", "items": { "type": "string" } },
"unverified": { "type": "array", "items": { "type": "string" } }
}
}