crabmate 0.4.0

Rust AI agent: OpenAI-compatible chat/completions, function calling, HTTP serve, ops CLI
Documentation

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

  • Chat and tools: OpenAI-compatible chat/completions; built-in workspace files, run_command (allowlist; defaults include bash/sh—glob/$VAR/~ run via bash -c on 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 via allow_external_path_with_approval—git A..B is 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 by command_max_output_len (embedded default 512KiB); see config/tools.toml and docs/en/CONFIGURATION.md.
  • Web UI (Client): built and shipped from crabmate-client; this repo’s serve defaults to API-only; host a SPA with --with-web plus CM_WEB_STATIC_DIR (or probed Client frontend/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-path apply only after a workspace is selected.
  • Terminal: Official remote client is crabmate-tui in crabmate-client (HTTP/SSE to serve; LLM keys stay on the client). In-process repl / chat / tui are hard-deleted (D2.2—docs/design/client_shell_split.md §2.5). serve is HTTP API-only by default (optional --with-web). Streaming SSE: docs/en/SSE_PROTOCOL.md.
  • Sessions and export: by default Web serve persists under <workspace>/.crabmate/conversations.db; clear conversation_store_sqlite_path to disable. Web or CLI save-session (alias export-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, workspace plugins/*.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)

make help              # list targets
make all / all-dev     # backend-release / backend
make backend           # cargo build -p crabmate
make package           # server-only tar.gz + optional .deb → dist/ (no UI)
make clean             # clean target and dist/

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
cargo build
./target/debug/crabmate serve            # API-only by default
./target/debug/crabmate serve --with-web # host SPA (needs CM_WEB_STATIC_DIR or probed dist)
# or: API_KEY=… ./target/debug/crabmate serve

# Release
cargo build --release
./target/release/crabmate serve

# 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.

cd ../crabmate-client && make frontend
export CM_WEB_STATIC_DIR="$PWD/frontend/dist"
cd ../crabmate_agent && cargo run -- serve --with-web

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 removed desktop-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.

cd ../crabmate-client
make desktop-release    # Linux .deb (no serve sidecar)
# 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 (includes protocol, web, mcp); opt-in fastembed, project_metrics, docker_sandbox, gen-man. Examples: cargo build --features fastembed, --features project_metrics, or --all-features. In-process repl/tui features removed (D2.2; use Client crabmate-tui). See root Cargo.toml [features] and AGENTS.md.
  • fmt / clippy / test, pre-commit, SSE, E2E: docs/en/TESTING.md (includes ./scripts/check-sse-protocol.sh). CI also runs make package (server-only tar.gz + .deb smoke).

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_KEYnever 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.0 needs web_api_bearer_token or an explicit insecure switch (docs/en/CONFIGURATION.md).
  • LLM API Key: Client stores keys locally and sends client_llm.api_key. Process env API_KEY remains an optional serve / ops fallback.
  • Web API: embedded default web_api_require_bearer = falseserve may start without a shared secret; with true, require non-empty CM_WEB_API_BEARER_TOKEN (or TOML / crabmate web-bearer set). When the token is set, send Authorization: Bearer … or X-API-Key: …. Browsers must save the same value under Settings → Web API shared secret (localStorage crabmate-api-bearer-token)—not the LLM API_KEY. Cross-origin static UI: set API base; official shell Origins are allowed by default—add CM_WEB_CORS_ALLOWED_ORIGINS only for extra browser Origins. Smoke: docs/design/client_turn_smoke_runbook.md §9. Temporary local skip: unset the secret and bind 127.0.0.1, or clear it and set CM_ALLOW_INSECURE_NO_AUTH_FOR_NON_LOOPBACK=true before 0.0.0.0. Prefer web_api_require_bearer = true on 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: crabmate 0.4.0 with default feature server. Install: cargo install crabmate. Official Client pins default-features = false, features = ["protocol"] (crabmate::cm_sse_protocol, cm_types, … — not types/sse aliases). Until crates.io publish (S5), Client may still git-pin a rev.
  • Semver surface: protocol = the six cm_* contract modules. server promises the composition module names (agent / config / llm / sse / types) and explicit root pub uses (run, run_agent_turn, build_tools*, …). #[doc(hidden)] modules and paths such as agent::agent_turn are not a stable SDK. Details: docs/design/crates_io_single_package.md §2.4.