feat: expose the loaded document snapshot to runtime programs
ci/woodpecker/push/main Pipeline failed
ci/woodpecker/pr/main Pipeline was canceled

Implement marqdo-cli#24 (AI-U1): ordinary .mq.md programs can read the
document snapshot that `prepare` already loaded, without a parser, host paths
or a second knowledge body.

- marqdo-host-contract gains the neutral read-only DocumentModule/DocumentUnit
  projection (canonical ids, path/parent/level/mode/anchors, exact section and
  heading spans, source digest, exact source) and two default-unavailable Host
  methods.
- The composition root builds the snapshot from the same load as Analysis
  (entry + explicit import closure only; no extra reads) and attaches it to the
  native host. StdHost only slices the immutable source; it never executes
  project code, loads modules, parses Markdown or touches the network.
- New builtins: document.outline(module?, parent?, limit?) and
  document.read(module, unit, expected_digest?, max_bytes?). Expected states
  (not loaded, unknown unit, stale source, over budget, invalid span) are
  structured result maps with stable document.* codes, so ordinary control flow
  can branch instead of crashing.
- Specification: spec/document-access.md, spec/evaluation.md §8, ADR-0074,
  README/developers/STATUS links and a docs-consistency gate for the single
  current contract.
- Tests: document_access.rs checks byte-exact agreement with check --emit
  Analysis (module/unit ids, digests, spans, cross-module anchor read) and all
  failure codes; the ADR-0064 builtin review table records the two additions.

Binary budgets are explicit (snapshot 128 modules/16 MiB; outline 1024/4096;
read 256 KiB/1 MiB) and over-budget requests report document.too_large rather
than truncating.
This commit is contained in:
cflmy committed 2026-11-30 15:42:30 +08:00
1 parent 8ad2f2cffa
commit d7dbce68b6
20 files changed
+1121 -6

No files matched your search

+5 -2
View File
@@ -43,9 +43,12 @@ Foreign wire v1, Provider manifest v2, lock v4 and markdown profile
6. [document-structure.md](../../spec/document-structure.md) — heading modes,
units/anchors/spans, `index.mq.md` entry meaning and the link≠import≠call
separation (single author/tool overview).
7. [compatibility.md](compatibility.md) — version axes, platform matrix and the
7. [document-access.md](../../spec/document-access.md) — runtime
`document.outline`/`document.read` over the prepared snapshot: exact units,
spans, source digests and structured failure codes (ADR-0074).
8. [compatibility.md](compatibility.md) — version axes, platform matrix and the
prerelease policy.
8. [release-limits.md](release-limits.md) — the honest beta limitations (this
9. [release-limits.md](release-limits.md) — the honest beta limitations (this
file ships in the archive as `KNOWN_LIMITATIONS.md`).
The full worked handbook is