Languages / 语言: English (this page) · 中文
CrabMate
CrabMate is a Rust-based AI agent that speaks OpenAI-compatible chat/completions to backends such as DeepSeek, MiniMax, Zhipu GLM, Moonshot Kimi, and local Ollama.
It ships HTTP serve (API-only by default) plus ops CLIs. Official Web UI, Desktop/Android, and remote terminal (crabmate-tui) live in crabmate-client (local checkouts default to sibling ../crabmate-client; Playwright forwarding honors CRABMATE_CLIENT_DIR). In-process repl / chat / tui command entries are removed (use Client crabmate-tui; see ADR).
Path A (repo split): this repository maintains Server (serve, contracts, ops CLI). Official clients are in crabmate-client (ADR).
Contents
- Overview
- Common subcommands
- Build, run, and packaging
- Documentation index
- Backend models
- Environment variables
- Deployment and security
- Project structure
Overview
- Chat and tools: OpenAI-compatible
chat/completions; built-in workspace files,run_command(allowlist; defaults includebash/sh—glob/$VAR/~run viabash -con the joined script; Web re-approves standalone&&/|even if bash is allowlisted; approval shows that script; argv outside the workspace or path-traversal-shaped..defaults to approval viaallow_external_path_with_approval—gitA..Bis not treated as traversal), HTTP, web search (default worbrow local browser, no API key; optional Brave/Tavily), workspace code search (keyword + optional semantic/embeddings). Full list: docs/en/TOOLS.md. Subprocess tool output is truncated bycommand_max_output_len(embedded default 512KiB); seeconfig/tools.tomland docs/en/CONFIGURATION.md. - Web UI (Client): built and shipped from
crabmate-client; this repo’sservedefaults to API-only; host a SPA with--with-webplusCM_WEB_STATIC_DIR(or probed Clientfrontend/dist). Sessions, workspace picker / project pool, editor mode, PR views, terminal-style chat stream, Ask/Plan/Act, and settings—see Client README and docs/en/CLI.md. Tools and@relative-pathapply only after a workspace is selected. - Terminal: Official remote client is
crabmate-tuiincrabmate-client(HTTP/SSE toserve; LLM keys stay on the client). In-processrepl/chat/tuiare hard-deleted (D2.2—docs/design/client_shell_split.md§2.5).serveis HTTP API-only by default (optional--with-web). Streaming SSE: docs/en/SSE_PROTOCOL.md. - Sessions and export: by default Web
servepersists under<workspace>/.crabmate/conversations.db; clearconversation_store_sqlite_pathto disable. Web or CLIsave-session(aliasexport-session) → JSON/Markdown; shape in docs/en/CLI.md. - Advanced (skip by default): staged-plan timeline, clarification UI,
thinking_trace, long-term memory, living docs, MCP, workspaceplugins/*.json: docs/en/CONFIGURATION.md, docs/en/TOOLS.md.
Common subcommands
With no subcommand, clap requires an explicit command (e.g. serve). Prefer serve + Client crabmate-tui. Common globals: --config, --workspace, --no-tools, --llm-context-tokens, --log (see crabmate --help).
| Subcommand | Summary |
|---|---|
serve |
HTTP API (API-only by default; no SPA). Host UI with --with-web and CM_WEB_STATIC_DIR (or probed Client/frontend/dist / install path). Default port 8080, bind 127.0.0.1. |
doctor |
One-page local diagnostics (no API_KEY). |
config |
Load config and self-check (e.g. --dry-run). |
models / probe |
Probe GET …/models on api_base; bearer usually needs env API_KEY. |
save-session |
Export session file to <workspace>/.crabmate/exports/ (alias export-session). |
bench |
Batch evaluation (JSONL): benchmark/README.md, docs/基准测试规划.md. |
mcp |
mcp list / mcp list --probe; mcp serve exposes built-in tools over stdio (no transport auth). |
plugin |
init / list / validate: workspace plugins/*.json (dyn__ prefix). |
workflow |
compile / validate / run: workspace YAML/Markdown workflows (no API_KEY); docs/工作流编写教程.md. |
tool-replay |
Export or replay tool fixtures (no API_KEY; trusted workspace only). |
Full flags, HTTP routes, man crabmate: docs/en/CLI.md.
Build, run, and packaging
Prerequisites: Rust 1.85+ (edition 2024). Official UI is in the Client repo (Trunk / wasm32). More: AGENTS.md.
Makefile (recommended)
UI: cd ../crabmate-client && make frontend (clone crabmate-client as a sibling first). make package / package-tar / package-deb are server-only (API-only by default; use --with-web + CM_WEB_STATIC_DIR to host SPA). Desktop / Android: crabmate-client.
Backend
# Debug
# or: API_KEY=… ./target/debug/crabmate serve
# Release
# Optional: Ubuntu 24.04 toolchain image (dev + `make package`; glibc 2.39; not a runtime)
# docker build -t crabmate-dev . # add --network=host only if DNS fails
# docker run --rm -it -v "$PWD":/workspace -w /workspace crabmate-dev
# make package-docker # → dist/*.tar.gz and dist/*.deb on the host
serve Web API auth (CM_WEB_API_BEARER_TOKEN, etc.): Deployment and security. Cloud API_KEY: Environment variables (or Client Web Settings / client_llm on requests).
Web frontend
Official UI source: frontend/ in crabmate-client (path A Phase 4.2). Local default: sibling ../crabmate-client.
&&
&&
API-only (default): serve. UI pointers: docs/frontend/.
Official Client (Desktop / Android)
Canonical repo:
crabmate-client(path A; ADR; local sibling../crabmate-client).
This repo removeddesktop-tauri//mobile-tauri//crates/crabmate-connect(Phase 4.1).
The shell does not spawn serve: start crabmate serve, then enter URL + Web API Bearer on the Client connect page.
# or make apk / cargo tauri dev — see Client README
Compat matrix: docs/design/client_compat_matrix.md.
Install and release artifacts
| Method | Command / notes |
|---|---|
| Install to PATH | cargo install crabmate (crates.io 0.4.0, default feature server). From a clone: cargo install --path .. Does not ship man; install man/crabmate.1 manually if needed. |
| Tarball / .deb | make package (or ./scripts/package-release.sh --skip-frontend) → dist/ (binary, config/, man, systemd/, etc/crabmate/; no UI by default). Tar only: make package-tar; deb only: make package-deb (needs cargo-deb). Optional --frontend-dist is script-only. |
| Debian (.deb) | make package-deb / cargo deb (UI not required); under dist/ or target/debian/. Installs crabmate.service (127.0.0.1:8080, API-only by default; add --with-web + CM_WEB_STATIC_DIR for UI). Desktop shell .deb: Client repo. Details: docs/en/CLI.md. |
| Desktop / APK | Only the Client repo (crabmate-client). |
| Regenerate man | cargo run --features gen-man --bin crabmate-gen-man. |
Maintainer QA
- Cargo features: default
server(includesprotocol,web,mcp); opt-infastembed,project_metrics,docker_sandbox,gen-man. Examples:cargo build --features fastembed,--features project_metrics, or--all-features. In-processrepl/tuifeatures removed (D2.2; use Clientcrabmate-tui). See rootCargo.toml[features]andAGENTS.md. - fmt / clippy / test, pre-commit, SSE, E2E: docs/en/TESTING.md (includes
./scripts/check-sse-protocol.sh). CI also runsmake package(server-only tar.gz +.debsmoke).
Documentation index
| Document | Contents | 中文 |
|---|---|---|
| CHANGELOG.md | Release notes (Keep a Changelog) | — |
| docs/en/DEVELOPMENT.md | Architecture overview, main modules, data flow | zh |
| docs/en/CONFIGURATION.md | Env vars, CM_*, Web/TOML |
zh |
| docs/en/TOOLS.md | Built-in tools and examples | zh |
| docs/工作流编写教程.md | Workflow YAML/steps (Chinese) | — |
| docs/en/SSE_PROTOCOL.md | /chat/stream control JSON |
zh |
| docs/en/CLI.md | Subcommands, HTTP routes, packaging | zh |
| docs/en/CLI_CONTRACT.md | chat exit codes, --output json |
zh |
| docs/en/DEBUG.md | Logging, doctor, GET /web-ui, … |
zh |
| docs/个人VPS部署指南.md | Personal VPS: loopback serve + TLS + Bearer (Chinese) |
— |
| docs/en/TESTING.md | Tests, pre-commit, audits | zh |
| docs/design/client_shell_split.md | Official Client split (path A) | — |
| docs/design/frontend_migrate_plan.md | Phase 4.2 UI migrate plan | — |
| docs/design/client_compat_matrix.md | Server ↔ protocol ↔ Client compat | — |
| docs/基准测试规划.md | bench roadmap |
— |
| docs/BENCHMARK_RESULTS.md | Recorded bench scores (no secrets) | — |
| benchmark/README.md | HumanEval convert/run/smoke | — |
More: backlog, roadmap, frontend drafts—under docs/ (docs/中英文文档对照.md).
Maintenance: keep user-visible docs in sync; conventions in docs/en/DEVELOPMENT.md.
Backend models
POST {api_base}/chat/completions (OpenAI-compatible). Under [agent] set api_base, model, max_tokens (embedded default 4096), llm_http_auth_mode; with bearer, use env API_KEY—never commit real keys.
| Scenario | Notes |
|---|---|
| DeepSeek | api_base: https://api.deepseek.com/v1; model e.g. deepseek-chat / deepseek-reasoner. Platform · API |
| MiniMax | api_base: https://api.minimaxi.com/v1; model e.g. MiniMax-M2.7. CONFIGURATION · Vendor OpenAI-compatible API |
| Zhipu GLM | api_base: https://open.bigmodel.cn/api/paas/v4; model e.g. glm-5. CONFIGURATION · GLM-5 |
| Moonshot Kimi | api_base: https://api.moonshot.cn/v1; model e.g. kimi-k2.5. CONFIGURATION · Kimi Chat API |
| Local Ollama | llm_http_auth_mode = "none"; api_base e.g. http://127.0.0.1:11434/v1; API_KEY optional. |
Local checks: crabmate doctor (no API_KEY), probe / models. Vendor knobs: docs/en/CONFIGURATION.md. Vendor behavior is defined by provider docs.
Environment variables
| Variable | Role |
|---|---|
API_KEY |
Cloud bearer (llm_http_auth_mode=bearer); optional process fallback for serve / models / probe. Official Client dialogue sends client_llm.api_key (keychain on the client). |
CM_API_BASE / CM_MODEL |
Override gateway and model from config. |
CM_WEB_API_BEARER_TOKEN |
Protects Web APIs (with web_api_require_bearer); docs/en/CONFIGURATION.md. |
CM_WEB_CORS_ALLOWED_ORIGINS |
Extra Origin allowlist (comma-separated); unset already allows official shell Origins (tauri://localhost, http://tauri.localhost). Explicit empty disables CORS. Static browser UI: add its Origin; see Settings API base (localStorage crabmate-api-base-url). |
CM_WEB_STATIC_DIR |
Override static root when serve --with-web (Client frontend/dist / install path; SPA off by default). |
CM_DESKTOP_SUGGESTED_URL |
Optional connect-page suggested serve URL (default http://127.0.0.1:8080/). |
CM_DESKTOP_SERVE_URL |
Required when skipping connect page (with CM_DESKTOP_SKIP_CONNECT / CM_E2E_FIXTURES). |
Other CM_* (skills, staged planning, etc.): docs/en/CONFIGURATION.md.
Deployment and security
- Listen: default
127.0.0.1;0.0.0.0needsweb_api_bearer_tokenor an explicit insecure switch (docs/en/CONFIGURATION.md). - LLM API Key: Client stores keys locally and sends
client_llm.api_key. Process envAPI_KEYremains an optionalserve/ ops fallback. - Web API: embedded default
web_api_require_bearer = false—servemay start without a shared secret; withtrue, require non-emptyCM_WEB_API_BEARER_TOKEN(or TOML /crabmate web-bearer set). When the token is set, sendAuthorization: Bearer …orX-API-Key: …. Browsers must save the same value under Settings → Web API shared secret (localStoragecrabmate-api-bearer-token)—not the LLMAPI_KEY. Cross-origin static UI: set API base; official shell Origins are allowed by default—addCM_WEB_CORS_ALLOWED_ORIGINSonly for extra browser Origins. Smoke:docs/design/client_turn_smoke_runbook.md§9. Temporary local skip: unset the secret and bind127.0.0.1, or clear it and setCM_ALLOW_INSECURE_NO_AUTH_FOR_NON_LOOPBACK=truebefore0.0.0.0. Preferweb_api_require_bearer = trueon exposed networks. Details: docs/en/CONFIGURATION.md. - Other: Web Settings → Save all persists via
/user-data; workspace must stay under allowed roots. Debug /GET /web-ui: docs/en/DEBUG.md. - Personal VPS (TLS reverse proxy): docs/个人VPS部署指南.md (Chinese;
127.0.0.1+ Bearer + Caddy/Nginx).
Project structure
Architecture overview: docs/en/DEVELOPMENT.md. GET /status for full runtime status; Web shell uses GET /status?view=shell. More: docs/en/DEBUG.md.
- Single crate:
crabmate0.4.0with default featureserver. Install:cargo install crabmate. Official Client pinsdefault-features = false, features = ["protocol"](crabmate::cm_sse_protocol,cm_types, … — nottypes/ssealiases). Until crates.io publish (S5), Client may still git-pin arev. - Semver surface:
protocol= the sixcm_*contract modules.serverpromises the composition module names (agent/config/llm/sse/types) and explicit rootpub uses (run,run_agent_turn,build_tools*, …).#[doc(hidden)]modules and paths such asagent::agent_turnare not a stable SDK. Details: docs/design/crates_io_single_package.md §2.4.