Files
marqdo-cli/docs/evidence/2026-11-30-cli-document-runtime-access.md
cflmy 7a0e8c4e42
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/pr/main Pipeline was successful
docs: pin the evidence baseline commit
The evidence consistency gate requires a commit/security SHA in every
docs/evidence Markdown file; record the Bundle-0.3.0 baseline commit so the
document-access evidence passes the same gate as the other records.
2026-11-30 15:45:07 +08:00

59 lines
3.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CLI 运行期文稿访问能力 — issue #24
Date: 2026-11-30. Branch: `codex/issue-24-document-runtime-read`.
Baseline CLI commit: `8ad2f2cffabcea1072f772b4748606eb01dd0744`
(the Bundle 0.3.0 pin merge; the candidate is the branch commit on top).
Issue: [marqdo-cli#24](https://git.cflmy.cn/cflmy/marqdo-cli/issues/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.rs` 2 例(与 `check --emit` Analysis
的 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)
```text
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):
```text
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 侧另行验证。