|
| 1 | +# PROJECT KNOWLEDGE BASE |
| 2 | + |
| 3 | +**Generated:** 2026-08-16 |
| 4 | +**Commit:** b71afdd |
| 5 | +**Branch:** main |
| 6 | + |
| 7 | +## OVERVIEW |
| 8 | +Claw Code: public Rust implementation of the `claw` CLI agent harness (Claude-Code-style). Canonical code lives in `rust/`; the repo is an agent-managed exhibit (harnesses plan/execute/verify per README), not a hand-operated product. `src/` is a companion Python porting/parity workspace, not production code. |
| 9 | + |
| 10 | +## STRUCTURE |
| 11 | +``` |
| 12 | +claw-code/ |
| 13 | +├── rust/ # canonical Cargo workspace: 11 crates, `claw` binary |
| 14 | +├── src/ # Python porting workspace + reference_data/ parity snapshots |
| 15 | +├── tests/ # Python unittest validation of src/ + scripts/ (stdlib unittest) |
| 16 | +├── docs/ # g0XX gate verification maps + topic docs |
| 17 | +├── scripts/ # fmt.sh, dogfood-build.sh, roadmap/board helpers |
| 18 | +├── assets/ # README images only |
| 19 | +└── install.sh, Containerfile, docker-compose.yml |
| 20 | +``` |
| 21 | + |
| 22 | +## WHERE TO LOOK |
| 23 | +| Task | Location | Notes | |
| 24 | +|------|----------|-------| |
| 25 | +| CLI subcommands | rust/crates/rusty-claude-cli/src/main.rs | hand-rolled parser; CliAction enum ~L1162; dispatch in run() L995-1158 | |
| 26 | +| Sessions/permissions/MCP | rust/crates/runtime/src/ | 47 flat modules | |
| 27 | +| Provider clients | rust/crates/api/src/providers/ | anthropic.rs + openai_compat.rs | |
| 28 | +| Tool definitions | rust/crates/tools/src/lib.rs | 55-tool spec table L484-1348 | |
| 29 | +| Slash commands | rust/crates/commands/src/lib.rs | 120+ spec table L60-1047 | |
| 30 | +| Plugins/hooks | rust/crates/plugins/src/ | manifest = .claude-plugin/plugin.json | |
| 31 | +| Lean agent harness | rust/crates/claw-analog/src/lib.rs | lib+bin; tool loop over api+runtime | |
| 32 | +| RAG HTTP service | rust/crates/claw-rag-service/src/ | axum; SQLite + optional Qdrant | |
| 33 | +| Test mock server | rust/crates/mock-anthropic-service/ | SCENARIO_PREFIX scripted responses | |
| 34 | +| Python porting CLI | src/main.py | argparse: manifest, parity-audit, graphs | |
| 35 | +| Parity reference DB | src/reference_data/subsystems/ | 29 JSON snapshots of TS archive | |
| 36 | + |
| 37 | +## CODE MAP |
| 38 | +| Symbol | Type | Location | Refs | Role | |
| 39 | +|--------|------|----------|------|------| |
| 40 | +| Session | struct | runtime/src/session.rs:117 | 229 | session persistence/lifecycle | |
| 41 | +| ConfigLoader | struct | runtime/src/config.rs:409 | 83 | config schema/load | |
| 42 | +| PluginManager | struct | plugins/src/lib.rs | 48 | plugin install/registry | |
| 43 | +| PermissionEnforcer | struct | runtime/src/permission_enforcer.rs:27 | 35 | pre-dispatch permission gate | |
| 44 | +| ConversationRuntime | struct | runtime/src/conversation.rs:130 | 32 | conversation loop driver | |
| 45 | +| McpServerManager | struct | runtime/src/mcp_stdio.rs:488 | 30 | MCP JSON-RPC processes | |
| 46 | +| HookRunner | struct | runtime/src/hooks.rs:155 | 25 | shell hook execution | |
| 47 | +| CliAction | enum | rusty-claude-cli/src/main.rs:1162 | — | 25 subcommand variants | |
| 48 | +| mvp_tool_specs | fn | tools/src/lib.rs:484 | — | static 55-tool table | |
| 49 | +| SLASH_COMMAND_SPECS | const | commands/src/lib.rs:60 | — | 120+ slash commands | |
| 50 | + |
| 51 | +(Refs = rg count across rust/crates; rust-analyzer references timed out during mapping.) |
| 52 | + |
| 53 | +## CONVENTIONS |
| 54 | +- `unsafe_code = "forbid"` workspace-wide; every crate opts in via `[lints] workspace = true`; clippy all=warn, pedantic=allow |
| 55 | +- Edition 2021, resolver 2, publish=false; no rust-toolchain pin (CI floats stable); no rustfmt.toml/clippy.toml — stock defaults |
| 56 | +- Giant flat files by design (main.rs 19.8k, tools/lib.rs 10.9k, commands/lib.rs 7.2k): organization is positional — types → spec table → dispatch → handlers → tests at EOF |
| 57 | +- Dual output paths everywhere: `render_x` + `render_x_json`; JSON errors to **stdout**, text errors to **stderr** |
| 58 | +- Tests: inline `#[cfg(test)] mod tests` primary; integration tests spawn `CARGO_BIN_EXE_claw` subprocess against mock-anthropic-service; tempfile everywhere; env-mutating tests serialize via env_lock/test_env_lock |
| 59 | +- Comments carry issue numbers (#824, #146); gate tests named by roadmap gate (g004_conformance.rs) |
| 60 | +- Python side: stdlib only, `python -m unittest`; src/ mixes camelCase (QueryEngine.py) and snake_case filenames |
| 61 | + |
| 62 | +## ANTI-PATTERNS (THIS PROJECT) |
| 63 | +- NEVER `cargo install claw-code` — crates.io stub is deprecated and installs `claw-code-deprecated.exe`; build from source |
| 64 | +- Forbidden doc strings (CI-enforced by .github/scripts/check_doc_source_of_truth.py): old org links `github.com/Yeachan-Heo/claw-code`, `github.com/code-yeongyu/claw-code`, `discord.gg/6ztZB9jvWq`, `assets/clawd-hero.jpeg` |
| 65 | +- Deprecated config keys: `permissionMode` → `permissions.defaultMode`; `enabledPlugins` → `plugins.enabled`; env `RUSTY_CLAUDE_PERMISSION_MODE` is dead |
| 66 | +- Direct push to main is policy-blocked (`main_push_forbidden` approval scope) |
| 67 | +- Automation lanes must not merge/close remote PRs/issues (docs/anti-slop-triage.md) |
| 68 | +- `claw init` must not scaffold `dontAsk` permission mode (regression-pinned in output_format_contract.rs) |
| 69 | +- File-level `#![allow(dead_code)]` blocks (main.rs, session_control.rs) are tolerated legacy — do not extend the pattern |
| 70 | + |
| 71 | +## UNIQUE STYLES |
| 72 | +- Dogfood build: scripts/dogfood-build.sh injects GIT_SHA; `claw version` provenance must equal HEAD |
| 73 | +- Mock parity: rust/mock_parity_scenarios.json drives CLI subprocess vs MockAnthropicService |
| 74 | +- Dogfooding uses `CLAW_CONFIG_HOME=$(mktemp -d)` for config isolation |
| 75 | +- Env contracts: GIT_SHA (build), CLAW_CONFIG_HOME (config dir), OLLAMA_HOST (provider override), `*_API_KEY`/`*_BASE_URL` per provider |
| 76 | + |
| 77 | +## COMMANDS |
| 78 | +```bash |
| 79 | +scripts/fmt.sh --check # fmt check (apply: scripts/fmt.sh) |
| 80 | +cd rust && cargo clippy --workspace --all-targets -- -D warnings |
| 81 | +cd rust && cargo test --workspace |
| 82 | +cd rust && cargo build -p rusty-claude-cli # binary: rust/target/debug/claw |
| 83 | +python -m unittest discover -s tests # Python suite |
| 84 | +python .github/scripts/check_doc_source_of_truth.py && scripts/roadmap-check-ids.sh # docs/roadmap CI |
| 85 | +``` |
| 86 | + |
| 87 | +## NOTES |
| 88 | +- `claw` binary comes from crate `rusty-claude-cli` (package/bin name mismatch) |
| 89 | +- rust-ci.yml triggers only on rust/**, docs/**, listed meta file changes (path filters) |
| 90 | +- CI clippy job runs without `-D warnings` — weaker than the documented gate; known pre-existing failures recorded in docs/g002/g003 maps |
| 91 | +- `claw acp` is a status stub, not a real ACP server |
| 92 | +- rust/ has committed harness dotdirs (.clawd-agents/, .omc/, .sandbox-home/) — intentional |
0 commit comments