文档

可复现性 - LeanCTX

可复现性

如何使代理运行可复现:稳定输入、显式策略、会话持久化和验证门控。

必须保持稳定的内容

可复现性始于稳定的输入 - 工具图的确定性取决于环境的确定性。

  • 相同的项目根目录 + 允许的路径
  • 相同的配置和内存策略
  • 相同的代码 + 依赖(lockfiles)

策略即契约

内存和验证设置定义什么被持久化以及哪些检查必须通过。

# ~/.lean-ctx/config.toml
[memory]
policy = "balanced"

[verification]
enabled = true

提示:将策略变更纳入版本控制并审查。

会话产物

会话记录发生的事情:工具调用、内存写入、关系和输出。

# Start a server with a fixed project root
lean-ctx serve --host 127.0.0.1 --port 8080 --project-root /path/to/repo
# Example tool calls that leave an audit trail
ctx_session("load", { id: "..." })
ctx_knowledge("remember", { category: "...", key: "...", value: "..." })

CI 门控

将 clippy/测试 + 验证检查视为不可协商的质量门控。

# CI gates / local checks
cd rust
cargo fmt -- --check
cargo clippy --all-features -- -D warnings

# SSOT drift gate (manifest must be up-to-date)
cargo run -q --bin gen_mcp_manifest
git diff --exit-code ../website/generated/mcp-tools.json

# Core tests (deterministic + bounded)
cargo test --all-features -- --test-threads=1

# Lightweight regression checks (stable thresholds)
cargo test -q --test savings_verification

# Proof artifact (machine-readable attestation, no secrets)
cargo run -q --bin lean-ctx -- proof --summary --no-write

Cookbook:端到端示例

针对运行中的服务器执行真实集成(无模拟数据)。

cd cookbook
npm ci
npm run memory-playground
npm run graph-explorer