Skip to content

Commit 26166be

Browse files
committed
docs: rewrite README + purge history markers from architecture.md
README.md / README.zh-CN.md — structural pass, corrected all stale numbers --------------------------------------------------------------------------- Verified against the current tree: - 24 crates (was 17 — counted wrong) - 46 built-in tools (was 49 — looked at an outdated list) - 33 slash commands (was "(20+)") - 3800+ tests (was 3900+ — exceeded actual count) - ~129k LOC (was "110k+") - 188 spinner verbs (was 187) - Permission modes: Default / AcceptEdits / TrustProject / DontAsk / Dangerously / Plan. README previously listed bypassPermissions and auto, which do not exist in the codebase. Condensed the separately-promoted "Multi-Agent Architecture", "File History & Rewind", and "Context Compaction" sections into compact prose; kept one paragraph each instead of three full sections. Added sections that were missing: - Insider env-only toggles block (CRAB_COORDINATOR_MODE, CRAB_AUTO_DREAM) so users know the gates exist without polluting --help. - Experimental cargo features list in the Build block (auto-dream, proactive, mem-ranker). Architecture diagram updated to show 24 crates across 4 layers. architecture.md — current state only, all history narrative removed ------------------------------------------------------------------- Scrubbed every "Phase X" / "v2.3" / "pre-Phase" / "moved here" / "deleted in …" / "[P0]" / "[P1]" / "[P2]" / "[Refactored]" / "replaces placeholder …" / "promoted from Layer 2" marker. The document now describes the code as it is, not how it got here. Rewrote the §6.11 `crates/agent/` crate layout with the actual module tree. Fixed §11.3 Agent Reliability to describe the current reliability subsystem (ErrorClassifier + RecoveryStrategy + file_history + summarizer), not the deleted CircuitBreaker / GracefulDegradation / in-memory rollback. Consolidated a handful of "Intra-crate expansions" / "layout notes" / "directory structure" headers that were phrased as change-logs back into present-tense descriptions of the current layout.
1 parent 20ff934 commit 26166be

File tree

3 files changed

+306
-313
lines changed

3 files changed

+306
-313
lines changed

README.md

Lines changed: 89 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717

1818
---
1919

20-
> **Status: Active Development** -- 49 built-in tools, 33 slash commands, 6 permission modes, extended thinking, three-layer multi-agent architecture (Teams / Swarm / Coordinator Mode), file-history rewinding, structured message TUI with 187 spinner verbs, 3800+ tests across 17 crates, 110k+ LOC. Zero `todo!()` macros.
20+
> **Status: Active Development** -- 46 built-in tools · 33 slash commands · 6 permission modes · three-layer multi-agent architecture · file-history rewinding · extended thinking · TUI with 188 spinner verbs · 3800+ tests · 24 crates · ~129k LOC.
2121
2222
## What is Crab Code?
2323

2424
[Claude Code](https://docs.anthropic.com/en/docs/claude-code) pioneered the agentic coding CLI -- an AI that doesn't just suggest code, but thinks, plans, and executes autonomously in your terminal.
2525

26-
**Crab Code** brings this experience to the open-source world, independently built from the ground up in Rust:
26+
**Crab Code** brings that experience to the open-source world, independently built from the ground up in Rust:
2727

2828
- **Fully open source** -- Apache 2.0, no feature-gating, no black box
2929
- **Rust-native performance** -- instant startup, minimal memory, no Node.js overhead
3030
- **Model agnostic** -- Claude, GPT, DeepSeek, Qwen, Ollama, or any OpenAI-compatible API
31-
- **Secure** -- 6 permission modes (default, acceptEdits, dontAsk, bypassPermissions, plan, auto)
31+
- **Secure** -- 6 permission modes + tool-level allow/deny lists
3232
- **MCP compatible** -- stdio, SSE, and WebSocket transports
3333
- **Claude Code aligned** -- CLI flags, slash commands, tools, and workflows match Claude Code behavior
3434

@@ -48,7 +48,7 @@ export ANTHROPIC_API_KEY=sk-ant-...
4848
# Single-shot mode
4949
./target/release/crab "explain this codebase"
5050

51-
# Print mode (non-interactive)
51+
# Print mode (non-interactive, reads from stdin if no prompt given)
5252
./target/release/crab -p "fix the bug in main.rs"
5353

5454
# With a specific provider
@@ -57,7 +57,7 @@ export ANTHROPIC_API_KEY=sk-ant-...
5757

5858
### Claude Code Compatible Configuration
5959

60-
Crab Code supports Claude Code's `settings.json` format, including the `env` field:
60+
Crab Code reads Claude Code's `settings.json` format, including the `env` field:
6161

6262
```json
6363
// ~/.crab/settings.json
@@ -75,143 +75,136 @@ Crab Code supports Claude Code's `settings.json` format, including the `env` fie
7575
### Core Agent Loop
7676

7777
- **Streaming SSE** -- real-time token-by-token output from LLM APIs
78-
- **Tool execution cycle** -- model reasoning -> tool call -> permission check -> execute -> result -> next turn
79-
- **Extended thinking** -- budget_tokens support for deep reasoning (Anthropic thinking blocks)
78+
- **Tool execution cycle** -- model reasoning tool call permission check execute result next turn
79+
- **Extended thinking** -- `budget_tokens` support for deep reasoning (Anthropic thinking blocks)
8080
- **Retry + fallback** -- automatic retry on transient errors, model fallback on overload
81-
- **Effort levels** -- low/medium/high/max mapped to API parameters
81+
- **Effort levels** -- low / medium / high / max mapped to API parameters
82+
- **Auto-compaction** -- heuristic summarizer triggers at 80% context-window watermark; `/compact` to invoke manually
8283

83-
### Built-in Tools (49)
84+
### Built-in Tools (46)
8485

8586
| Category | Tools |
8687
|----------|-------|
87-
| File I/O | Read, Write, Edit, Glob, Grep |
88-
| Execution | Bash, PowerShell (Windows) |
89-
| Agent | AgentTool (sub-agents), TeamCreate, TeamDelete, SendMessage |
90-
| Tasks | TaskCreate, TaskGet, TaskList, TaskUpdate, TaskStop, TaskOutput |
91-
| Scheduling | CronCreate, CronDelete, CronList |
92-
| Planning | EnterPlanMode, ExitPlanMode |
93-
| Notebook | NotebookEdit, NotebookRead |
94-
| Web | WebFetch, WebSearch |
95-
| LSP | LSP (go-to-definition, references, hover, symbols) |
96-
| Worktree | EnterWorktree, ExitWorktree |
97-
| Remote | RemoteTrigger |
98-
| Other | AskUserQuestion, Skill |
99-
100-
### Permission System
101-
102-
6 modes aligned with Claude Code:
103-
104-
- **default** -- prompt for potentially dangerous operations
105-
- **acceptEdits** -- auto-approve file edits, prompt for Bash
106-
- **dontAsk** -- auto-approve everything (no prompts)
107-
- **bypassPermissions** -- skip all checks
108-
- **plan** -- read-only mode, requires plan approval before execution
109-
- **auto** -- AI classifier auto-approves low-risk operations
110-
111-
Plus tool-level filtering with `--allowedTools` / `--disallowedTools` supporting glob patterns (`Bash(git:*)`, `Edit`).
88+
| File I/O | `Read`, `Write`, `Edit`, `Glob`, `Grep`, `ImageRead` |
89+
| Execution | `Bash`, `PowerShell` (Windows) |
90+
| Sub-agents | `Agent`, `TeamCreate`, `TeamDelete`, `SendMessage` |
91+
| Tasks | `TaskCreate`, `TaskGet`, `TaskList`, `TaskUpdate`, `TaskStop`, `TaskOutput`, `TodoWrite` |
92+
| Scheduling | `CronCreate`, `CronDelete`, `CronList` |
93+
| Planning | `EnterPlanMode`, `ExitPlanMode`, `VerifyPlanExecution` |
94+
| Notebook | `NotebookEdit`, `NotebookRead` |
95+
| Web | `WebFetch`, `WebSearch`, `WebBrowser` |
96+
| LSP | `LSP` (definition, references, hover, symbols) |
97+
| Worktree | `EnterWorktree`, `ExitWorktree` |
98+
| MCP | `ListMcpResources`, `ReadMcpResource`, `McpAuth` |
99+
| Files | `SendUserFile` |
100+
| Other | `AskUserQuestion`, `Skill`, `Sleep`, `Snip`, `Brief`, `Config`, `ToolSearch`, `Monitor`, `RemoteTrigger` |
112101

113102
### Multi-Agent Architecture
114103

115-
Three conceptually distinct layers, implemented as independent modules inside `crates/agent`:
104+
Three conceptually distinct layers in `crates/agent/`:
116105

117-
- **Layer 1 — Teams** (unconditional base plumbing): `WorkerPool`, per-agent `MessageRouter` mailbox, `Team` / `TeamMember` roster, shared `TaskList` with optional `fd-lock` file-locked `claim_task` for cross-process teammates, spawner backends (in-process, tmux).
118-
- **Layer 2a — Swarm** (default topology): peer-to-peer `TeamMode::PeerToPeer`. No extra module — it is just the default usage pattern when no overlay is active.
119-
- **Layer 2b — Coordinator Mode** (gated overlay via `CRAB_COORDINATOR_MODE=1`): the coordinator's tool registry is reduced to `{Agent, SendMessage, TaskStop}`, workers spawned through it lose `{TeamCreate, TeamDelete, SendMessage}`, and the coordinator's system prompt carries an anti-pattern guardrail ("understand before delegating"). Fully unit-tested.
106+
- **Teams** base infrastructure: `WorkerPool`, per-agent mailbox router, shared `TaskList` (`fd-lock` file-locked `claim_task` for cross-process teammates), spawner backends (in-process, tmux).
107+
- **Swarm** — the default flat topology (`TeamMode::PeerToPeer`). No extra module — it's just how teammates cooperate when no overlay is active.
108+
- **Coordinator Mode** — a star-topology overlay gated on `CRAB_COORDINATOR_MODE=1`. The coordinator's tool registry is reduced to `{Agent, SendMessage, TaskStop}`; workers it spawns lose `{TeamCreate, TeamDelete, SendMessage}`; the coordinator's system prompt carries an anti-pattern guardrail.
120109

121110
### File History & Rewind
122111

123-
Every user session gets its own snapshot store at `~/.crab/file-history/{session_id}/`. Designed to mirror Claude Code's `fileHistory.ts` / `/rewind` behavior: each file edit is recorded as `{path-hash}@v{version}`, capped at 100 snapshots per session with LRU eviction. The `/rewind [path]` slash command is wired in the REPL; tool-level `track_edit` hooks on Edit/Write/Notebook are a planned follow-up.
112+
Every session snapshots file edits under `~/.crab/file-history/{session_id}/` (at most 100 per session, LRU-evicted). `/rewind [path]` restores a file to an earlier version. Tool-level `track_edit` hooks on `Edit` / `Write` / `Notebook` are a planned follow-up; the `file_history` primitive is already unit-tested.
113+
114+
### Permission System
124115

125-
### Context Compaction
116+
6 modes aligned with Claude Code behaviour:
126117

127-
`/compact` explicitly, or automatic compaction when the conversation crosses 80% of the model's context window. A heuristic summarizer (no extra LLM call) extracts decisions, code changes, unresolved issues, and topics, then replaces the conversation history with a single summary message while preserving the system prompt, session id, and cost accumulator. Emits `Event::CompactStart` and `Event::CompactEnd` for UI observability.
118+
- **default** — prompt for potentially dangerous operations
119+
- **acceptEdits** — auto-approve file edits, still prompt for Bash
120+
- **trust-project** — auto-approve in-project writes; out-of-project and dangerous ops still prompt
121+
- **dontAsk** — auto-approve everything (no prompts)
122+
- **dangerously** — auto-approve everything except `denied_tools` (use with care)
123+
- **plan** — read-only planning mode; mutations require explicit plan approval
124+
125+
Plus tool-level filtering via `--allowedTools` / `--disallowedTools` with glob patterns (`Bash(git:*)`, `mcp__*`, `Edit`).
128126

129127
### Slash Commands (33)
130128

131-
REPL intercepts `/<letter>…` input and dispatches through `SlashCommandRegistry` before anything hits the LLM, so paths like `/tmp/foo` still pass through as prompts.
129+
The REPL intercepts input matching `/<letter>…` and dispatches through `SlashCommandRegistry` before the prompt reaches the LLM, so paths like `/tmp/foo` still pass through as prompts.
132130

133131
`/help` `/clear` `/compact` `/cost` `/status` `/memory` `/init` `/model` `/config` `/permissions` `/resume` `/history` `/export` `/doctor` `/diff` `/review` `/plan` `/exit` `/fast` `/effort` `/add-dir` `/files` `/thinking` `/rewind` `/skills` `/plugin` `/mcp` `/branch` `/commit` `/theme` `/keybindings` `/copy` `/rename`
134132

135133
### LLM Providers
136134

137-
- **Anthropic** -- Messages API with SSE streaming (default: `claude-sonnet-4-6`)
138-
- **OpenAI-compatible** -- Chat Completions API (GPT, DeepSeek, Qwen, Ollama, vLLM, etc.)
139-
- **AWS Bedrock** -- SigV4 signing with inference profile discovery
140-
- **GCP Vertex AI** -- ADC authentication
135+
- **Anthropic** Messages API with SSE streaming (default `claude-sonnet-4-6`)
136+
- **OpenAI-compatible** Chat Completions API (GPT, DeepSeek, Qwen, Ollama, vLLM, )
137+
- **AWS Bedrock** SigV4 signing with inference profile discovery
138+
- **GCP Vertex AI** — Application Default Credentials
141139

142140
### MCP (Model Context Protocol)
143141

144142
- stdio, SSE, and WebSocket transports
145-
- `McpToolAdapter` bridges MCP tools to native `Tool` trait
143+
- `McpToolAdapter` bridges MCP tools to the native `Tool` trait
146144
- Configure via `~/.crab/settings.json` or `--mcp-config`
147145

148146
### Session Management
149147

150-
- Auto-save conversation history
151-
- `--continue` / `-c` resume last session
152-
- `--resume <id>` resume specific session
153-
- `--fork-session` fork on resume
148+
- Auto-save conversation history to `~/.crab/sessions/`
149+
- `--continue` / `-c` resumes the last session
150+
- `--resume <id>` resumes a specific session
151+
- `--fork-session` branches on resume instead of continuing in-place
154152
- `--name` friendly session names
155-
- Auto-compaction at 80% context window threshold (see *Context Compaction* above)
156-
- Per-session file-history snapshots for `/rewind` (see *File History & Rewind* above)
153+
- Per-session file-history snapshots for `/rewind`
157154

158155
### Hook System
159156

160157
- `PreToolUse` / `PostToolUse` / `UserPromptSubmit` triggers
161-
- Shell command execution with Allow / Deny / Modify responses
158+
- Shell command execution with `Allow` / `Deny` / `Modify` responses
162159
- Configure in `settings.json`
163160

164-
### Experimental Cargo Features (off by default)
165-
166-
- `auto-dream` — background memory-consolidation cycles. Mirrors CCB's `src/services/autoDream/`: three-gate scheduler (min hours, min sessions, lock file) and the CCB consolidation prompt template are ready; the forked-agent LLM runner is stubbed and lands in a follow-up. Env: `CRAB_AUTO_DREAM=1`, `CRAB_AUTO_DREAM_MIN_HOURS`, `CRAB_AUTO_DREAM_MIN_SESSIONS`.
167-
- `proactive` — placeholder for CCB's `feature('PROACTIVE')` mini-agent. Compiles the module skeleton only; real implementation pending.
168-
- `mem-ranker` — enable the ML-based memory ranker inside `crab-memory`.
169-
170161
### Interactive TUI
171162

172-
- ratatui + crossterm terminal UI
163+
- `ratatui` + `crossterm` terminal UI, immediate-mode rendering
173164
- Markdown rendering with syntax highlighting
174-
- Vim mode editing
165+
- Vim-mode editing
175166
- Autocomplete for slash commands and file paths
176167
- Permission dialogs
177168
- Cost tracking status bar
169+
- 188 spinner verbs mirrored from Claude Code
178170

179171
## Architecture
180172

181-
4-layer, 17-crate Rust workspace:
173+
24 Rust crates organised in 4 layers:
182174

183175
```
184-
Layer 4 (Entry) cli daemon xtask
185-
| |
186-
Layer 3 (Orch) agent session
187-
| |
188-
Layer 2 (Service) api tools mcp tui skill plugin telemetry
189-
| | | | | |
190-
Layer 1 (Found) common core config auth
176+
Layer 4 (Entry) cli daemon
177+
| |
178+
Layer 3 (Orch) agent engine session
179+
| | |
180+
Layer 2 (Service) api tools mcp tui skill plugin telemetry acp ide job remote sandbox
181+
| | | | | | |
182+
Layer 1 (Found) common core config auth fs memory process
191183
```
192184

193185
Key design decisions:
194-
- **Async runtime**: tokio (multi-threaded)
195-
- **LLM dispatch**: `enum LlmBackend` -- zero dynamic dispatch, exhaustive match
196-
- **Tool system**: `trait Tool` with JSON Schema discovery, `ToolRegistry` + `ToolExecutor`
197-
- **TUI**: ratatui + crossterm, immediate-mode rendering
198-
- **Error handling**: `thiserror` for libraries, `anyhow` for application
186+
- **Async runtime** tokio (multi-threaded)
187+
- **LLM dispatch**`enum LlmBackend`; zero dynamic dispatch, exhaustive match
188+
- **Tool system**`trait Tool` + `ToolRegistry` + `ToolExecutor`, discovered via JSON Schema
189+
- **TUI**`ratatui` + `crossterm`, immediate-mode
190+
- **Error handling**`thiserror` for libraries, `anyhow` for the application
199191

200192
> Full architecture details: [`docs/architecture.md`](docs/architecture.md)
201193
202194
## Configuration
203195

204196
```bash
205-
# Global config
197+
# Global
206198
~/.crab/settings.json # API keys, provider settings, MCP servers
207199
~/.crab/memory/ # Persistent memory files
208200
~/.crab/sessions/ # Saved conversation sessions
201+
~/.crab/file-history/ # Per-session pre-edit snapshots
209202
~/.crab/skills/ # Global skill definitions
210203

211-
# Project config
212-
your-project/CRAB.md # Project instructions (like CLAUDE.md)
213-
your-project/.crab/settings.json # Project-level overrides
214-
your-project/.crab/skills/ # Project-specific skills
204+
# Project
205+
your-project/CRAB.md # Project instructions (like CLAUDE.md)
206+
your-project/.crab/settings.json # Project-level overrides
207+
your-project/.crab/skills/ # Project-specific skills
215208
```
216209

217210
## CLI Usage
@@ -221,29 +214,34 @@ crab # Interactive TUI mode
221214
crab "your prompt" # Single-shot mode
222215
crab -p "your prompt" # Print mode (non-interactive)
223216
crab -c # Continue last session
224-
crab --provider openai # Use OpenAI-compatible provider
225-
crab --model opus # Model alias (sonnet/opus/haiku)
217+
crab --provider openai # Use an OpenAI-compatible provider
218+
crab --model opus # Model alias (sonnet / opus / haiku)
226219
crab --permission-mode plan # Plan mode
227-
crab --effort high # Set effort level
220+
crab --effort high # Set reasoning effort
228221
crab --resume <session-id> # Resume a saved session
229222
crab doctor # Run diagnostics
230223
crab auth login # Configure authentication
231224
```
232225

226+
Insider toggles (no CLI flag, env only — keeps the surface hidden from `--help`):
227+
- `CRAB_COORDINATOR_MODE=1` — enables Coordinator Mode overlay
228+
- `CRAB_AUTO_DREAM=1` — arms the `auto-dream` memory-consolidation gate (requires the `auto-dream` cargo feature)
229+
233230
## Build & Development
234231

235232
```bash
236233
cargo build --workspace # Build all
237234
cargo test --workspace # Run all tests (3800+)
238-
cargo clippy --workspace -- -D warnings # Lint
235+
cargo clippy --workspace -- -D warnings # Lint (CI treats warnings as errors)
239236
cargo fmt --all --check # Check formatting
240237
cargo run --bin crab # Run CLI
241-
242-
# Experimental features (default off)
243-
cargo build -p crab-agent --features auto-dream # Enable auto-dream module
244-
cargo build -p crab-agent --features proactive # Enable proactive stubs
245238
```
246239

240+
Experimental cargo features (all default off):
241+
- `auto-dream` on `crab-agent` — CCB-aligned memory-consolidation scheduler (runner still stubbed)
242+
- `proactive` on `crab-agent` — placeholder matching CCB's `feature('PROACTIVE')` posture
243+
- `mem-ranker` on `crab-agent` — re-exports `crab-memory/mem-ranker`
244+
247245
## Comparison
248246

249247
| | Crab Code | Claude Code | [OpenCode](https://github.com/anomalyco/opencode) | Codex CLI |
@@ -254,14 +252,14 @@ cargo build -p crab-agent --features proactive # Enable proactive stubs
254252
| Self-hosted | Yes | No | Yes | Yes |
255253
| MCP Support | stdio + SSE + WS | 6 transports | LSP | 2 transports |
256254
| TUI | ratatui | Ink (React) | Custom | ratatui |
257-
| Built-in Tools | 49 | 52 | ~10 | ~10 |
255+
| Built-in Tools | 46 | 52 | ~10 | ~10 |
258256
| Permission Modes | 6 | 6 | 2 | 3 |
259257

260258
## Contributing
261259

262-
We'd love your help! See areas where we need contributions:
260+
Areas where we'd love help:
263261

264-
- Claude Code feature alignment (remaining gaps: auto-dream forked-agent runner, tool-level file-history hooks, proactive mini-agent)
262+
- Claude Code feature alignment remaining gaps include the `auto-dream` forked-agent runner, tool-level `track_edit` hooks on Edit / Write / Notebook, and the `proactive` mini-agent
265263
- OS-level sandboxing (Landlock / Seatbelt / Windows Job Object)
266264
- End-to-end integration testing
267265
- Additional LLM provider testing

0 commit comments

Comments
 (0)