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.
3.0 KiB
3.0 KiB
CLI 运行期文稿访问能力 — issue #24
Date: 2026-11-30. Branch: codex/issue-24-document-runtime-read.
Issue: marqdo-cli#24
(AI-U1 for marqdo-ext-ai).
交付
marqdo-host-contract:新增只读DocumentModule/DocumentUnit快照类型与 两个默认不可用的 Host 方法(document_outline、document_read); 引擎仍只依赖中立 Host contract。crates/cli/src/document_snapshot.rs:从prepare的同一加载快照构建模块目录 (canonical module/unit id、path/parent/level/mode/anchors、完整 section span、 heading span、source digest、exact source);只包含本次 run/call 已加载的模块 (入口 + 显式导入闭包),不再读盘/解析。- 运行时 builtin:
document.outline(module?, parent?, limit?)与document.read(module, unit, expected_digest?, max_bytes?);返回结构化 result map(ok/失败 code),预期状态不崩溃。 - 原生宿主
StdHost从快照做精确 byte slice;不执行文稿、不加载模块、不联网。 - 规范:
spec/document-access.md、spec/evaluation.md§8; ADR-0074;spec/document-structure.md/README/developers/STATUS 链接。 - 测试:
crates/cli/tests/document_access.rs2 例(与check --emitAnalysis 的 module/unit/digest/span 逐字节一致;跨模块 anchor 读取;stale/unknown/not_loaded/ too_large;同名标题 anchor 区分);docs_consistency单一契约检查; architecture boundary 的 builtin 评审表更新。
本地验证(Linux x86_64 / glibc 2.43;Bundle 0.3.0)
cargo fmt --all -- --check PASS
cargo clippy --workspace --all-targets -- -D warnings PASS
MARQDO_TEST_STDLIB_BUNDLE=<0.3.0> cargo test --workspace --locked 641 passed, 0 failed, 2 ignored
cargo test -p marqdo-cli --test document_access 2 passed
cargo test -p marqdo-cli --test docs_consistency 10 passed
check_dependency_boundaries / check_engine_boundary / check_plugin_sdk PASS
independent_build PASS
手工探针(真实 CLI):
document.outline() → {ok:true, count:4, source_digest:<same as Analysis>}
document.read(module, unit-id) → 精确 section 原文
document.read(module, "说明") → anchor 命中同一 unit
stale digest → {ok:false, code:"document.stale_source"}
unknown unit → {ok:false, code:"document.unknown_unit"}
已知限制 / 未验证
- 快照预算:≤128 模块、≤16 MiB 源码;outline limit 默认 1024/最大 4096;
read 默认 256 KiB/最大 1 MiB;超限返回
document.too_large,不静默裁剪。 check/inspect不执行,因此不暴露该能力;strict 子进程重新按同一 prepare 构建快照,不依赖父进程内存。- Windows/macOS 原生 lane、strict VM 仍 UNVERIFIED(平台 runner 限制)。
- AI 扩展移除预写全文/词法兜底等消费切换在 ext-ai 侧另行验证。