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:
1 parent
1a978c7a42
commit
1377af1601
28 files changed
+879
-23
No files matched your search
+11
-2
@@ -123,6 +123,12 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
|
||||
(`format.显示` → UTF-8 encode → `Memory` → `resource.write(stdout)`) matches
|
||||
builtin `打印` for the covered value set; builtin remains default and no
|
||||
alias is routed.
|
||||
- Bundled standard library (CM-A10, ADR-0028): `stdlib/` ships
|
||||
`format`/`text`/`io`; explicit `std:` imports resolve only inside the bundle;
|
||||
a SHA-256 digest over `*.mq.md` is verified before loading; Analysis records
|
||||
`project.stdlib`; a frozen-binary test asserts the CLI hash is unchanged after
|
||||
running a `std:io` project and that tampering is rejected. `打印` is still
|
||||
the builtin default.
|
||||
- Resource streams (RFC-CM CM-A06, ADR-0025): opaque host-issued `Resource`
|
||||
handles with `resource.open/read/write/close`; bytes move only through
|
||||
`Memory`; stdout write is capability/output-budget checked and project-file
|
||||
@@ -166,8 +172,8 @@ behavior. This table records only what is in this tree now.
|
||||
|---|---|---|
|
||||
| P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged |
|
||||
| P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) |
|
||||
| P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: a separate stdlib repository/package and the frozen-CLI closure lane. C01–C06/C11/C12 now each have `.mq.md` evidence, including JSON floats and a JSON formatter. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict refuses all opens. Fixture 66 + CLI/host tests. CM-A07 is **Compat-A only**: `examples/stdlib` provides an explicitly imported `.mq.md` `format/utf8/io` chain whose output matches builtin `打印` for Unit/None/Bool/Int/Float/Text/List/Map/Table; builtin `打印` remains default, no alias routing, and Formula/Code/FunctionRef/PluginHandle formatting is still unobservable. Still missing: Compat-B/C, directories, network, generic provider registry. |
|
||||
| P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: publication as a separate external stdlib repository. The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). C01–C06/C11/C12 each have `.mq.md` evidence, including JSON floats and a JSON formatter. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict refuses all opens. Fixture 66 + CLI/host tests. CM-A07 is **Compat-A only**: the bundled `stdlib/` provides an explicitly imported `.mq.md` `format/utf8/io` chain (`std:` imports) whose output matches builtin `打印` for Unit/None/Bool/Int/Float/Text/List/Map/Table; builtin `打印` remains default, no alias routing, and Formula/Code/FunctionRef/PluginHandle formatting is still unobservable. Still missing: Compat-B/C, directories, network, generic provider registry. |
|
||||
| P4 Table logical/physical migration | **NOT IMPLEMENTED** | `Value::Table` remains `Vec<Vec<Value>>`; no stdlib table algorithms |
|
||||
| P5 third-party Provider / TCP / HTTP | **NOT IMPLEMENTED** | `fs.write`, `net.request`, `process`, `clock`, `random` remain unavailable broker services (see §4) |
|
||||
| P6 performance / native backends | **NOT IMPLEMENTED** | no bytecode/JIT/GPU/QPU work |
|
||||
@@ -193,6 +199,9 @@ user-written allocator is explicitly **not** claimed.
|
||||
- [`evidence/2026-11-20-stdlib-print-compat-a.md`](evidence/2026-11-20-stdlib-print-compat-a.md)
|
||||
— CM-A07 Compat-A `.mq.md` print prototype, side-by-side output comparison,
|
||||
covered/uncovered value types and the Compat-B blocker.
|
||||
- [`evidence/2026-11-20-bundled-stdlib-cm-a10.md`](evidence/2026-11-20-bundled-stdlib-cm-a10.md)
|
||||
— CM-A10 bundled stdlib, `std:` imports, digest verification, Analysis
|
||||
identity and frozen-binary closure test.
|
||||
- [`evidence/RELEASE_CANDIDATE_0.1.0_8af7262.md`](evidence/RELEASE_CANDIDATE_0.1.0_8af7262.md)
|
||||
— G0..G12 matrix and RC decision.
|
||||
- [`security-gate.md`](security-gate.md) — mechanism, attack matrix and strict
|
||||
|
||||
@@ -40,13 +40,13 @@ claim CM-A07 complete.
|
||||
|
||||
### 2. Compat-A implementation
|
||||
|
||||
Add a normal `.mq.md` module package under `examples/stdlib/`:
|
||||
Add a normal `.mq.md` module package (later moved to the bundled `stdlib/` tree by ADR-0028):
|
||||
|
||||
```text
|
||||
examples/stdlib/format.mq.md # 显示 / 列表显示 / 映射显示 / 表格显示 / 转义文本
|
||||
examples/stdlib/text.mq.md # utf8编码 (Memory bytes)
|
||||
examples/stdlib/io.mq.md # 写文本 / 写值 (resource.open stdout + write/close)
|
||||
examples/stdlib/demo.mq.md # side-by-side comparison with 打印
|
||||
stdlib/format.mq.md # 显示 / 列表显示 / 映射显示 / 表格显示 / 转义文本
|
||||
stdlib/text.mq.md # utf8编码 (Memory bytes)
|
||||
stdlib/io.mq.md # 写文本 / 写值 (resource.open stdout + write/close)
|
||||
stdlib/demo.mq.md # side-by-side comparison with 打印
|
||||
```
|
||||
|
||||
`io.写值(值)` = `format.显示(值) + "\n"` → `text.utf8编码` → `Memory` →
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
# ADR-0028: Bundled standard library, `std:` imports and digest verification (CM-A10)
|
||||
|
||||
Status: **Accepted**
|
||||
Date: 2026-11-20
|
||||
Relates to: `docs/MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md`
|
||||
(CM-A10, CM-A07, P2/P3), ADR-0027
|
||||
Specs: `spec/analysis-v2.md`, `spec/references.md`
|
||||
Evidence: `docs/evidence/2026-11-20-bundled-stdlib-cm-a10.md`
|
||||
|
||||
## Context
|
||||
|
||||
CM-A07 Compat-A put a real `.mq.md` print chain under `examples/stdlib/`, but it
|
||||
was reachable only by relative path from a demo in the same directory. A
|
||||
standard library that ordinary projects can use offline needs:
|
||||
|
||||
* a fixed bundle shipped with the CLI;
|
||||
* an explicit import spelling that cannot be shadowed by a project file;
|
||||
* a content identity so a different bundle with the same version cannot
|
||||
masquerade;
|
||||
* no network, Git or package installation required at run time.
|
||||
|
||||
The RFC requires the official distribution to carry a tested stdlib version
|
||||
offline, while allowing independent releases. This ADR freezes the **bundled
|
||||
first slice**; it does not create the external `cflmy/marqdo-stdlib`
|
||||
repository or a public publishing workflow.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. Bundle location
|
||||
|
||||
The official bundle is the `stdlib/` tree shipped next to the CLI (or vendored
|
||||
at the repository root during development). Discovery order:
|
||||
|
||||
1. `MARQDO_STDLIB_DIR` — explicit override; if set and invalid, loading fails
|
||||
hard (no silent fallback);
|
||||
2. `<executable-dir>/stdlib` if it exists;
|
||||
3. the development tree `<repo>/stdlib` for source builds.
|
||||
|
||||
If no bundle is found, a project that uses `std:` fails with a clear error; a
|
||||
project that does not use `std:` is unaffected. No network, Git or package
|
||||
manager is consulted for a bundled stdlib.
|
||||
|
||||
### 2. Explicit `std:` imports only
|
||||
|
||||
Front-matter imports may name a stdlib module as:
|
||||
|
||||
```yaml
|
||||
import:
|
||||
io: "std:io"
|
||||
fmt: "std:format"
|
||||
parser: "std:data/json"
|
||||
```
|
||||
|
||||
The target after `std:` is a **package-relative** path inside the bundle.
|
||||
`..`, absolute paths and `std:` targets that escape the bundle are rejected;
|
||||
`.mq.md` is appended when the target has no extension. `std:` is resolved
|
||||
before relative/alias imports and never searches the project or dependencies.
|
||||
There is no implicit `std` namespace, no global name, and no auto-import.
|
||||
|
||||
Module ids use a stable package instance:
|
||||
|
||||
```text
|
||||
std:marqdo-stdlib@<version>#<sha256-hex>
|
||||
```
|
||||
|
||||
so the same logical module from a different bundle is a different instance.
|
||||
|
||||
### 3. Content digest
|
||||
|
||||
`stdlib/stdlib.json` carries the name, version and digest. The digest is:
|
||||
|
||||
```text
|
||||
sha256( for each sorted *.mq.md relative path:
|
||||
path_utf8, NUL, file_bytes, NUL )
|
||||
```
|
||||
|
||||
It excludes `stdlib.json`, README files and non-`.mq.md` files. The loader
|
||||
recomputes it before loading any stdlib module and fails closed on mismatch or
|
||||
a missing manifest. A bundle is therefore identified by **name + version +
|
||||
exact markdown bytes**, not by a path or a version string alone.
|
||||
|
||||
### 4. Visibility and analysis
|
||||
|
||||
Analysis v2 records the verified bundle identity under `project.stdlib`:
|
||||
|
||||
```json
|
||||
{"version":"0.1.0","digest":"sha256:<hex>",
|
||||
"instance_id":"std:marqdo-stdlib@0.1.0#<hex>"}
|
||||
```
|
||||
|
||||
It is `null` when no bundle was available. A project that imports `std:` always
|
||||
has a non-null identity. Trace/diagnostics keep the real stdlib source spans;
|
||||
the bundle is normal Markdown, not a special-cased module type.
|
||||
|
||||
### 5. Frozen-CLI closure lane
|
||||
|
||||
The first closure test builds the CLI once, hashes the executable, runs a
|
||||
project importing `std:io`, then re-hashes the executable and asserts equality.
|
||||
It also asserts:
|
||||
|
||||
* the project uses only `.mq.md` and standard imports, no `foreign`/`plugin`
|
||||
calls;
|
||||
* a tampered bundle fails the digest check before any module executes;
|
||||
* Analysis records the verified digest.
|
||||
|
||||
This is a local gate, not a replacement for a remote CI lane.
|
||||
|
||||
### 6. Versioning
|
||||
|
||||
The bundle version is `0.1.0` for this slice. A CLI may load a bundle whose
|
||||
version is declared compatible by this ADR; the RFC's full SemVer/digest
|
||||
contract and independent release workflow remain CM-A10 follow-up. A future
|
||||
core feature that the bundle requires must be reflected in both the bundle
|
||||
version and the CLI's compatibility table before release.
|
||||
|
||||
## Non-goals
|
||||
|
||||
* Creating/publishing the external `cflmy/marqdo-stdlib` repository or a
|
||||
package registry entry.
|
||||
* Automatic download/update, Git fetching, or manifest-driven stdlib
|
||||
installation.
|
||||
* A second plugin/provider system or a second module search path.
|
||||
* Compat-B/C name routing of `打印` (ADR-0027) — the bundle does not change
|
||||
builtin resolution.
|
||||
* Windows/macOS packaging layout; only the source-tree/executable-adjacent
|
||||
layout is exercised locally.
|
||||
|
||||
## Consequences
|
||||
|
||||
* Any project can `import: {io: "std:io"}` and use the print prototype
|
||||
offline; `打印` remains the default builtin.
|
||||
* A changed stdlib file without a digest update is rejected before execution.
|
||||
* The bundle is still an in-repo vendored package. Independent repository
|
||||
release and CI signing are explicitly tracked as remaining CM-A10 work.
|
||||
* Analysis artifacts and a frozen binary can be tied to the exact stdlib
|
||||
digest, which is the prerequisite for Compat-B and reproducible releases.
|
||||
|
||||
## Verification
|
||||
|
||||
`docs/evidence/2026-11-20-bundled-stdlib-cm-a10.md` records the `std:` import
|
||||
test, digest-tamper rejection, Analysis identity assertion, no-foreign policy
|
||||
scan and frozen binary hash equality.
|
||||
@@ -6,7 +6,7 @@ normative RFC text stays at its reviewable path under `docs/`.
|
||||
| Document | Status | Implemented part |
|
||||
|---|---|---|
|
||||
| [RFC-CM-0001: compute machine, addressable memory and system boundary](../MARQDO_COMPUTE_MACHINE_RFC_0001.md) | Draft / design input | R1 (P1): `Memory` value, `memory.new/size/grow`, byte read/write, Memory-index assignment, budgets, wire/host rejection. Implemented per [ADR-0022](../adr/0022-addressable-memory-and-place-assignment.md); see [STATUS §5](../STATUS.md). |
|
||||
| [RFC-CM-0002: minimal core, stdlib self-hosting and system capability migration](../MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md) | Draft / design input | P0/P1, a **partial P2**, and a **partial P3** first slice (ADR-0025/0026: stdout write, granted project-file read and buffered project-file write via `resource.*`; strict refuses all opens; ADR-0027 Compat-A `.mq.md` print prototype, builtin still default). P2: fixtures 48–50 (`.mq.md` bump allocator, u32 codec, linked list/traversal, failed-allocation atomicity), CM-A04 structure primitives for List/Map/Text/Table (ADR-0023, fixtures 51–54), and a `.mq.md` first-fit free-list allocator with block splitting, address-adjacent coalescing and `Result` maps (ADR-0024, fixture 55), plus a `Memory`-backed binary tree with recursive insert/in-order traversal (fixture 56), a `.mq.md` CSV row splitter (fixture 57), an open-addressing hash table with linear probing (fixture 58), a `.mq.md` UTF-8 encoder and validating decoder (`utf8.truncated`/`invalid_continuation`/`invalid_scalar`) (fixtures 59–60), a `Memory`-backed graph adjacency list (fixture 61), a recursive JSON parser/formatter for arrays, objects, strings with escapes, ints/floats/booleans/null and error Results (fixture 62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (fixture 63), big-endian 16/32/64-bit plus LEB128 integer codecs (fixture 64), a `.mq.md` table sort rebuilding the table without mutating the input (fixture 65), a table join built from `table.row/columns/cell` (fixture 67), and a quoted/escaped CSV row parser (fixture 68), table group (fixture 69) and an Int matrix multiply (fixture 70). No separate stdlib repo, network/generic providers, P4 Table migration, P5 providers or P6 performance work. |
|
||||
| [RFC-CM-0002: minimal core, stdlib self-hosting and system capability migration](../MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md) | Draft / design input | P0/P1, a **partial P2**, and a **partial P3** first slice (ADR-0025/0026: stdout write, granted project-file read and buffered project-file write via `resource.*`; strict refuses all opens; ADR-0027 Compat-A `.mq.md` print prototype, builtin still default). P2: fixtures 48–50 (`.mq.md` bump allocator, u32 codec, linked list/traversal, failed-allocation atomicity), CM-A04 structure primitives for List/Map/Text/Table (ADR-0023, fixtures 51–54), and a `.mq.md` first-fit free-list allocator with block splitting, address-adjacent coalescing and `Result` maps (ADR-0024, fixture 55), plus a `Memory`-backed binary tree with recursive insert/in-order traversal (fixture 56), a `.mq.md` CSV row splitter (fixture 57), an open-addressing hash table with linear probing (fixture 58), a `.mq.md` UTF-8 encoder and validating decoder (`utf8.truncated`/`invalid_continuation`/`invalid_scalar`) (fixtures 59–60), a `Memory`-backed graph adjacency list (fixture 61), a recursive JSON parser/formatter for arrays, objects, strings with escapes, ints/floats/booleans/null and error Results (fixture 62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (fixture 63), big-endian 16/32/64-bit plus LEB128 integer codecs (fixture 64), a `.mq.md` table sort rebuilding the table without mutating the input (fixture 65), a table join built from `table.row/columns/cell` (fixture 67), and a quoted/escaped CSV row parser (fixture 68), table group (fixture 69) and an Int matrix multiply (fixture 70). No separate external stdlib repo, network/generic providers, P4 Table migration, P5 providers or P6 performance work. |
|
||||
|
||||
The RFCs are architecture constraints, not evidence that a feature exists. The
|
||||
implementation status lives in `docs/STATUS.md`; frozen behavior is in
|
||||
@@ -24,7 +24,8 @@ implementation status lives in `docs/STATUS.md`; frozen behavior is in
|
||||
| CM-A06 minimal Resource/Stream ABI | [0025](../adr/0025-minimal-resource-stream-abi.md) | Accepted (first slice) |
|
||||
| CM-A06 buffered project-file write | [0026](../adr/0026-buffered-project-file-write-streams.md) | Accepted |
|
||||
| CM-A07 print migration staging / Compat-A | [0027](../adr/0027-print-migration-compat-a.md) | Accepted (Compat-A only) |
|
||||
| CM-A07 Compat-B/C, stdlib packaging, Table storage, generic providers, strict resources | — | Not decided; do not implement by implication |
|
||||
| CM-A10 bundled stdlib / `std:` imports / digest | [0028](../adr/0028-bundled-stdlib-and-std-imports.md) | Accepted (first slice) |
|
||||
| CM-A07 Compat-B/C, Table storage, generic providers, strict resources | — | Not decided; do not implement by implication |
|
||||
|
||||
## What a future phase must not do
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
# RFC-CM CM-A10 evidence: bundled stdlib, `std:` imports and digest
|
||||
|
||||
Date: 2026-11-20 (Asia/Shanghai)
|
||||
Repository: `marqdo-cli`
|
||||
Baseline: `92bfbf2` plus this step's changes.
|
||||
Decision record: [ADR-0028](../adr/0028-bundled-stdlib-and-std-imports.md)
|
||||
Related: [Compat-A](2026-11-20-stdlib-print-compat-a.md), [STATUS §5](../STATUS.md).
|
||||
Scope: bundled first slice; **no external repository publication**.
|
||||
|
||||
## 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
|
||||
415 passed, 0 failed, 2 ignored (existing plugin-sdk doc-tests)
|
||||
```
|
||||
|
||||
No GitHub CI is available from this checkout; this is local evidence.
|
||||
|
||||
## Bundle
|
||||
|
||||
`stdlib/` is the official offline bundle:
|
||||
|
||||
```text
|
||||
stdlib/
|
||||
stdlib.json # name, version 0.1.0, sha256 digest
|
||||
README.md
|
||||
format.mq.md # 显示 / 列表显示 / 映射显示 / 表格显示 / 转义文本
|
||||
text.mq.md # utf8编码 into Memory
|
||||
io.mq.md # 写文本 / 写值 via resource.write(stdout)
|
||||
demo.mq.md # builtin 打印 comparison
|
||||
tests/io.mq.md # std:io self-test
|
||||
```
|
||||
|
||||
Digest scheme: SHA-256 over sorted `*.mq.md` relative paths, NUL, file bytes,
|
||||
NUL. `stdlib.json` and non-`.mq.md` files are excluded. The loader recomputes
|
||||
the digest before loading any stdlib module and fails closed on mismatch or a
|
||||
missing manifest.
|
||||
|
||||
`std:<relative>` is an explicit front-matter import target; it resolves only
|
||||
inside the bundle, rejects `..`/absolute paths, appends `.mq.md` when absent,
|
||||
and uses package instance
|
||||
`std:marqdo-stdlib@0.1.0#<sha256-hex>`.
|
||||
|
||||
## Tests
|
||||
|
||||
`crates/cli/tests/stdlib_bundle.rs` (6):
|
||||
|
||||
```text
|
||||
std_import_resolves_the_verified_bundle
|
||||
index.mq.md imports std:io; io.写值(["bundle",1,2.5])
|
||||
-> ["bundle", 1, 2.5]
|
||||
|
||||
analysis_records_the_verified_stdlib_digest
|
||||
check --emit contains project.stdlib.version/digest/instance_id
|
||||
matching stdlib.json
|
||||
|
||||
tampered_bundle_is_rejected_before_module_loading
|
||||
copy bundle, modify io.mq.md
|
||||
-> non-zero, "stdlib digest mismatch"
|
||||
|
||||
missing_bundle_manifest_is_a_hard_error
|
||||
empty MARQDO_STDLIB_DIR -> non-zero stdlib error
|
||||
|
||||
bundle_uses_no_foreign_or_plugin_calls
|
||||
scans all stdlib *.mq.md for foreign./plugin. -> none
|
||||
|
||||
frozen_binary_hash_is_unchanged_after_stdlib_execution
|
||||
sha256(marqdo binary) before == after running the std:io project
|
||||
```
|
||||
|
||||
CLI unit tests in `crates/cli/src/stdlib.rs` (2): dev bundle resolves and
|
||||
verifies; a copied/tampered bundle is rejected.
|
||||
|
||||
Existing `mqmd_stdlib_print_output_matches_builtin_print` still passes with the
|
||||
demo moved to `stdlib/demo.mq.md`.
|
||||
|
||||
## Analysis identity
|
||||
|
||||
Analysis v2 project object now carries:
|
||||
|
||||
```json
|
||||
{"stdlib":{"version":"0.1.0",
|
||||
"digest":"sha256:<64 hex>",
|
||||
"instance_id":"std:marqdo-stdlib@0.1.0#<64 hex>"}}
|
||||
```
|
||||
|
||||
It is `null` when no bundle is available. The digest is verified before load,
|
||||
so an Analysis artifact cannot name mismatched stdlib bytes.
|
||||
|
||||
## What is not done
|
||||
|
||||
* No separate `cflmy/marqdo-stdlib` repository, release tag, package registry
|
||||
or CI-signed digest. The bundle is vendored in this repository and copied
|
||||
next to the executable in a release layout by later packaging work.
|
||||
* No CM-A07 Compat-B/C routing; `打印` is still the builtin default.
|
||||
* No Windows/macOS bundle layout evidence and no remote CI URL.
|
||||
* No independent stdlib upgrade workflow; changing a module requires updating
|
||||
`stdlib.json.digest`, and an incompatible core requirement is not yet
|
||||
enforced by a version table.
|
||||
|
||||
## 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 stdlib_bundle
|
||||
cargo run -q -p marqdo-cli -- run examples/stdlib-bundle.mq.md
|
||||
cargo test --workspace --locked
|
||||
```
|
||||
@@ -24,7 +24,7 @@ No GitHub CI is available from this checkout; this is local evidence.
|
||||
|
||||
## Prototype
|
||||
|
||||
Ordinary `.mq.md` modules under `examples/stdlib/`:
|
||||
Ordinary `.mq.md` modules (now the bundled `stdlib/` tree, ADR-0028):
|
||||
|
||||
| File | Responsibility |
|
||||
|---|---|
|
||||
@@ -50,7 +50,7 @@ The module is loaded only through an explicit Markdown import alias.
|
||||
## Output comparison
|
||||
|
||||
```text
|
||||
$ marqdo run examples/stdlib/demo.mq.md
|
||||
$ marqdo run stdlib/demo.mq.md
|
||||
["文本", 2, 1.5, [3, true], {a: 1, b: "x"}, None]
|
||||
["文本", 2, 1.5, [3, true], {a: 1, b: "x"}, None]
|
||||
Table[名称 | 分数]{甲 | 87; 乙 | 92}
|
||||
@@ -88,7 +88,7 @@ extension, not part of this slice. This is the explicit blocker for Compat-B.
|
||||
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 run -q -p marqdo-cli -- run examples/stdlib/demo.mq.md
|
||||
cargo run -q -p marqdo-cli -- run stdlib/demo.mq.md
|
||||
cargo test -p marqdo-cli --test examples_r6
|
||||
cargo test --workspace --locked
|
||||
```
|
||||
Reference in new issue
Block a user