feat(stdlib): ship a verified bundled stdlib with std: imports

- Move the Compat-A print prototype into stdlib/ as the official offline
  bundle with stdlib.json (version 0.1.0 + sha256 content digest).
- Add std:<relative> import resolution in the loader with bundle path
  confinement, extension inference and fail-closed digest verification.
- Record the verified version/digest/instance_id in Analysis v2
  project.stdlib; stdlib modules get a std:name@version#digest instance id.
- Add CLI tests: std:io execution, digest-tamper rejection, missing manifest,
  Analysis identity, no foreign/plugin calls, and frozen binary hash equality.
- Update ADR-0028, specs, status, changelog and evidence.

Gate: fmt, clippy -D warnings, 415 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 21:43:14 +08:00
1 parent 1a978c7a42
commit 1377af1601
28 files changed
+879 -23

No files matched your search

+11 -1
View File
@@ -31,7 +31,12 @@ Analysis v1. v1 was never released; it is kept as history and is not written.
"project": {
"root_id": "root:quantum@0.1.0",
"identity_kind": "manifest",
"lock_digest": "sha256:<64 hex>"
"lock_digest": "sha256:<64 hex>",
"stdlib": {
"version": "0.1.0",
"digest": "sha256:<64 hex>",
"instance_id": "std:marqdo-stdlib@0.1.0#<64 hex>"
}
},
"modules": [],
"diagnostics": []
@@ -48,6 +53,11 @@ Analysis v1. v1 was never released; it is kept as history and is not written.
`project.lock_digest` is the SHA-256 of the exact `marqdo.lock` bytes prefixed
with `sha256:`, or `""` when there is no lock. It is not a logical identity.
`project.stdlib` records the verified bundled standard library identity used by
this load: declared version, content digest and package instance id. It is
`null` when no bundle was available. A digest mismatch is a hard load error, so
an Analysis artifact can only name a bundle whose bytes matched the manifest.
`AnalysisDigest` is the lowercase hex SHA-256 of the exact UTF-8 bytes written
by `check --emit` (pretty JSON). This is what Trace v2 binds to
`source.analysis_digest`; an independent consumer can verify it by hashing the
+1 -1
View File
@@ -278,7 +278,7 @@ host boundary. Names are stable; adding one requires a spec update.
| `fs.read/write` | see `spec/security.md` | capability-gated |
The legacy `打印/print` builtin remains the default and still uses the host
output path. `examples/stdlib/` contains an explicitly imported `.mq.md`
output path. `stdlib/` (the bundled standard library, `std:` imports) contains an explicitly imported `.mq.md`
`format/utf8/io` prototype (ADR-0027 Compat-A) whose output is comparison-tested
against `打印` for Unit/None/Bool/Int/Float/Text/List/Map/Table; it does **not**
replace the builtin, and Formula/Code/FunctionRef/PluginHandle formatting is not
+2 -1
View File
@@ -146,11 +146,12 @@ Parsing rules (`crates/marqdo-markdown/src/frontmatter.rs::imports`):
### 3.1 Target forms
`Loader::resolve_import` recognizes exactly two forms:
`Loader::resolve_import` recognizes exactly three forms:
| Target | Resolution |
|---|---|
| `@dependency` | Look up the alias after `@` in `marqdo.yaml` `dependencies`. The dependency must declare a **path** source. Resolve `project_root / path`; if it is a directory, append `index.mq.md`; canonicalize. A git-only dependency cannot be resolved in this build (`dependency.path` is `None` → unresolved). |
| `std:<relative>` | Resolve inside the verified bundled standard library (ADR-0028). The target must stay inside the bundle; `..`/absolute paths are rejected; `.mq.md` is appended when absent. The bundle's declared digest is verified before any module loads. No network/package manager is consulted. |
| any other string (intended: `./file.mq.md`) | Join the string to the **importing file's directory**, then canonicalize. There is no extension inference, no search path and no fallback to a package directory. |
The resulting file is loaded as a module. If it canonicalizes outside the