This document describes how to work on LogicShell Framework in alignment with LogicShell Framework PRD.md (Version 2.0.0-draft): TDD, coverage gates, and trait-based LLM integration.
- Test-first: No feature ships without tests (Framework PRD §6).
- Requirements traceability: Prefer test names or comments that reference FR-xx / NFR-xx where practical (§6.3).
- Library-first: Public API stability and embeddability matter as much as CLI ergonomics (§3.1).
Follow Red–Green–Refactor (§6.1):
- Red: Add a failing test that specifies one behavior (one concern per test when possible).
- Green: Implement the minimum code to pass.
- Refactor: Improve structure, names, and boundaries while keeping tests green.
For cross-cutting behavior (safety modes, LLM-off paths), add tests that lock acceptance criteria from the PRD tables (§7–8), not only implementation details.
cargo fmt --check
cargo clippy -- -D warnings
cargo testIntegration tests that require a local Ollama daemon must be marked #[ignore] so default CI remains deterministic (LLM Module PRD: no GPU/inference required for cargo test).
The framework targets ≥90% line coverage on agreed scope (Framework PRD §11.3–11.4). Use cargo-tarpaulin (or the project’s documented successor) locally and in CI:
cargo tarpaulin --out Html --output-dir target/coverageScope policy (typical):
- Include: Dispatch, safety policy, config loading, LLM bridge orchestration, prompt composition, parsers.
- Exclude: Generated code, trivial
mainshims, or third-party vendored snippets—list exclusions in CI config ortarpaulin.tomlwhen introduced.
Fail the pipeline if coverage drops below the threshold on main, per §11.4.
The product PRD names the async trait LlmClient (see LogicShell LLM Module PRD.md §5.1). Colloquially this is the inference provider boundary; new backends (e.g. additional HTTP APIs) implement LlmClient, not a separate “LlmProvider” name unless the codebase standardises otherwise.
- Signature (conceptual):
complete(request: LlmRequest) -> Result<LlmResponse, LlmError>. - No environment reads: Implementations must not call
std::envor discover cwd for prompts; system context is supplied viaSystemContextSnapshotassembled upstream (FR-10, FR-11). - Wire format: MVP targets Ollama-compatible HTTP (
OllamaLlmClient); parsing and serialization must be unit-testable with fixture JSON (no network in unit tests).
- Define or extend
LlmRequest/LlmResponseonly if the abstraction truly needs it; avoid leaking vendor JSON into safety or dispatch layers. - Implement
LlmClientfor the backend (e.g.OllamaLlmClient). - Unit tests: Deserialize canned responses; reject malformed payloads with
LlmError. - Integration tests: Use mockito (or equivalent) against a loopback server to assert path, headers, and body for one or two golden requests (FR-21).
- Bridge:
LlmBridgecomposes prompts and callsLlmClient; it never executes argv without SafetyPolicyEngine (Framework PRD §11.1).
LlmClient is async because inference is I/O-bound (NFR-05). Use async_trait if needed for object safety; keep blocking work out of the runtime (Framework PRD §11.2: Tokio).
- Tests added or updated for the change.
-
cargo fmt,cargo clippy -D warnings,cargo testpass. - Coverage meets project threshold on scoped crates/modules.
- If touching LLM or safety: confirm FR-24 (graceful degradation when AI unavailable) and FR-31 (AI proposals gated by policy) remain covered.
- LogicShell Framework PRD.md — methodology, FR/NFR, CI expectations.
- LogicShell LLM Module PRD.md —
LlmClient,LlmBridge, testing split. - TESTING_STRATEGY.md — pyramid, mocks, process isolation.
- ARCHITECTURE.md — component boundaries.