# Sovereign Fleet

> Task queue, kernel sandbox, gates, router and dashboard for running coding-agent CLIs (Claude Code, OpenCode, Goose, Pi, Aider, Antigravity CLI, Cursor CLI) on your own machine. Beta, 0.13.2 (Privateer, routines, scoped tokens, crash durability, Pi Pocket controls, slim PWA shell at /, notifications, MCP over HTTPS, MCP Apps).

## What it is
- FastAPI daemon (`fleet daemon`, loopback by default): task queue in `~/.fleet/spool/tasks.json` (flock, atomic writes), model roster, settings, mobile-first PWA dashboard (`/` and legacy `/classic` redirect 307 to `/static/app/`), background jobs (daily lane health check, issue intake, routine tick, signer resend, notify loop). Every `/api` route requires a scoped token (`read`, `propose`, `operate`, `admin`; `Authorization: Bearer` or HttpOnly session cookie); `/api/v1/events` streams resumable SSE updates from `<fleet root>/events/events.jsonl` (`DATA_KEYS` only).
- Backends: `local` (the package's own queue; with `backend.kind = "local"` the daemon runs queued tasks itself: oldest first, dependencies settled, up to `backend.max_concurrent` at once, recovers interrupted tasks at start, prunes worktrees; `fleet run "<prompt>"` or `fleet run --task <id>` runs tasks directly) and `grid` (a bridge to an existing grid runner, which executes everything queued).
- A run: git worktree from the project's `default_branch` on branch `fleet/<task-id>`, sandboxed agent CLI (worktree as cwd and $PWD), agent commits folded back into the worktree, then gates (their processes end with them, and the scope is judged again afterwards), then the changes committed to that branch (also on failure), then landing. A run that leaves no change does not pass.
- Execution lifecycle: rule-based failure autopsies for the KB learning loop, atomic receipts in `<spool>/receipts/<task_id>.json`, and automated cross-lane review loops (`reviews/<project>/<task_id>.md`) with auto-fix tasks for critical/high findings.
- Sandbox (`fleet.core.sandbox`): Landlock ABI >= 6 (filesystem allow-list, TCP port allow-list, scope), no_new_privs, seccomp block of AF_UNIX sockets and io_uring; with an egress proxy (`--strict-sockets`), UDP and non-TCP socket families also fail with EACCES. Fails closed; only FLEET_SANDBOX=0 disables it.
- Capabilities (`fleet.core.capability`, `fleet.core.toolgate`, `fleet.core.evidence`, `fleet.core.signer`, `fleet.core.privateer`, `fleet.core.routines`): `[capabilities.<name>]` starts a sandboxed third-party stdio MCP server per task (requested via intent keys `capabilities` and `allowed_domains`) behind a loopback HTTP tool gate (default-deny `"allow"`/`"ask"`/`"deny"` rules, `effects`, call budgets, tool-list `pin`/`manifest_sha256`, `private_tmp`, hash-chained `<root>/toolcalls/` log, `<root>/egress/` log, `memory_max`, `sweep()` at daemon start) and runs `check_evidence` in `core/engine.py` when `evidence_recipe` is set. Side-effecting `"ask"` drafts require NIP-46 `kind 4910` phone approvals verified against root-owned `[nostr] signer_anchor` (`sudo fleet signer pin`), named Privateers (`fleet privateer new|list|show|revoke`, keys kept outside sandboxes) require signed `kind 4911` commissions and emit `kind 4912` signed receipts, and persistent `cron`/interval routines (`fleet routine new|approve|pause|resume|run|delete`, `/api/fleet/routines*`) stay in `awaiting_approval` until operator approval (with diff + schedule replay) and record/report runs missed beyond `max_lateness_seconds`. Limits: only `goose` and `claude-code` attach capabilities, no remote HTTP MCP servers, no resources/prompts, UDP unfiltered in `egress = "ports"` mode.
- Gates (`fleet.core.gates`): scope against `allowed_paths`, Python syntax, the repo gate (`projects.<name>.gate` or scripts/verify.sh, verify.sh, pytest), the task gate (`pytest:<path>` / `npm:<script>`), claimed files. Sandboxed, without credentials.
- Landing (`fleet.core.landing`): per project `branch`, `merge` (rebase, re-gate, fast-forward, push) or `pull_request` (GitHub via gh, Gitea via its API; `Closes #n` for a task from an issue).
- Router (`fleet.core.router`, `fleet.core.models`): supports both named lanes (`[lanes.<name>]`) ranked by measured pass rate per category over cost, and decoupled `(harness, model)` pairs (`[models.<name>]` + `HarnessPlugin`) ranked via Thompson sampling on cost-weighted minutes per correct result (`routing.priors_file` / `bakeoff_priors.json`). Escalation with one repair pass, quota windows after provider limits, `intent.allowed_lanes` enforcement, per-task `metadata.on_limit` (`switch`/`wait`/`wait_then_switch`, capped `wait_hours`), `max_parallel`, local model residency, dead lanes from the health check left out, and strict `is_sensitive` privacy filtering. `fleet router rank|shadow`, `fleet harnesses list|test`.
- Goose Recipes & Evals (`recipes/*/recipe.yaml`, `docs/EVALS_AND_BENCHMARKS.md`): Goose 1.0.0 recipes (`fleet-ab-proposal-eval/recipe.yaml`, `fleet-self-improvement/recipe.yaml`, `fleet-bench-runner/recipe.yaml`) loaded on demand via `goose run --recipe`.
- Budgets (`fleet.core.budget`, the only place that knows the policies and their defaults): per provider `normal` (ranked by measured quality), `reserve` (after every normal lane) or `manual` (never picked automatically; a lane the task names still runs). Defaults derived from cost and own login; only the operator's deviations are stored, with a log. `GET /api/fleet/budgets`, `PUT/DELETE /api/fleet/budgets/{provider}` (dashboard, either way), `POST .../tighten` (MCP, only stricter).
- Lane health (`fleet.core.lane_health`, `fleet.core.catalog`): `fleet lanes check [--apply]`, daily at `routing.health_hour`; a tiny request per API lane with its real key, `probe_url` for local lanes, `opencode models` for opencode lanes. Retired models (HTTP 410, or gone and deprecated on models.dev) get a probed same-family successor; `routing.discover` turns new free models into `auto_*` lanes.
- Issue intake (`fleet.plugins.intake`): `[projects.<name>.intake]`; Gitea or GitHub issues become tasks; only listed `authors` with a valid ```fleet``` block run unattended; one task per issue; results go back to the issue. `fleet intake status|sync`.
- Provider keys per lane (`key_env`, `key_file`, or a `CredentialPlugin`); a key reaches only its own CLI run. The package ships no key rotation.
- Autonomy tiers: manual_gate (review and auto-fix tasks wait for approval too), safe_auto (risky words in the task text wait for approval; not a security boundary), full_swarm.
- MCP server (`python -m fleet.api.mcp_server`, stdio, **17 tools**): `fleet_dispatch_task` (with automatic `idempotency_key`), `fleet_list_tasks`, `fleet_get_task_status`, `fleet_get_task_receipt`, `fleet_approve_task`, `fleet_reject_task`, `fleet_cancel_task`, `fleet_retry_task`, `fleet_system_health`, `fleet_lane_health`, `fleet_issue_intake`, `fleet_clear_spool`, `fleet_get_budgets`, `fleet_tighten_budget` (only tightens), `fleet_get_ledger`, `fleet_show_task`, `fleet_show_approval` (read-only SEP-1865 MCP Apps cards `ui://fleet/task-card` and `ui://fleet/approval-card` deep-linking to `#/t/<task_id>`), plus file-based templates (`core/templates.py`) as MCP Prompts. Errors carry isError. Pass `--mode front_door` (`FLEET_MCP_MODE=front_door`) for front-door assistants (OpenClaw, Goose): exposes **11 tools** (`fleet_dispatch_task` plus read-only list/status/receipt/health/lane_health/issue_intake/budgets/ledger and MCP Apps show cards; `propose` tokens hold queued tasks in `awaiting_approval` and restrict `intent` keys), removing and refusing approve/reject/cancel/retry/clear/tighten/probe/sync.
- MCP over HTTPS (`POST`/`GET /api/mcp` on the daemon port, `api/mcp_http.py`): the front-door surface for clients that cannot start a local process (Pi Pocket on a phone, a client as another OS user). Bearer token only (no query token, no cookie), each tool call runs with the caller's own token against the API (no confused deputy), browser `Origin` must be the daemon's own or in `FLEET_MCP_ALLOWED_ORIGINS`, limits 256 KB body, 32 per batch, 60 requests/min per token, 4 SSE streams, 65 s per call.
- Notifications & Dashboard (`core/notify.py`, `core/nostr_notify.py`, `api/static/app/index.html`): optional title-and-link-only "needs you" notifications via ntfy, `[matrix]`, and/or one-way NIP-17 Nostr DM (off by default, NIP-44 v2 + NIP-59 gift wrap, NIP-40 7-day expiry, fixed pinned-anchor recipient, operator-supplied relays only); slim PWA at `/` (`/static/app/`, with `/classic` 307 redirect) with structured approval briefs (`core/brief.py`), schedule (`review_id`-bound), providers, ledger, plugins, Pi Pocket host controls, Your apps companion links, access tokens (`fleet token create|list|revoke`), phone signer setup + `kind 4919` test (`POST /api/fleet/signer/test`).

## Plugin interfaces (`src/fleet/plugins/base.py`)
- `HarnessPlugin.execute_task(task, worktree_dir, timeout, model, args, pass_env, env)`; subclass `CliHarness` (name, binary, state_paths, ro_state_paths, build_command) to add a sandboxed CLI.
- `CredentialPlugin` (`get_active_key`, `record_rate_limit`, optional `record_success`, `status`), loaded with `[plugins] credentials`.
- `InputPlugin`: the issue intake is one (`IssueIntakePlugin`); trackers implement `IssueTracker` (`list_open`, `comment`, `close`). Matrix output notifications and approvals live in output_matrix.py.

## Key files
- `src/fleet/api/app.py` (API, `/api/v1/events` SSE), `background.py`, `auth.py`, `scopes.py`, `cli.py`, `mcp_server.py`, `static/app/index.html`, `mcp_apps/{task,approval}-card.html`
- `src/fleet/core/engine.py`, `executor.py`, `router.py`, `gates.py`, `landing.py`, `lane_health.py`, `quirks.py`, `quota.py`, `sandbox.py`, `capability.py`, `toolgate.py`, `evidence.py`, `signer.py`, `nip46_relay.py`, `privateer.py`, `routines.py`, `nostr_identity.py`, `events.py`, `notify.py`, `nostr_notify.py`, `templates.py`, `brief.py`, `idempotency.py`, `worktree.py`, `taskstore.py`, `config.py`, `settings.py`, `budget.py`, `backends.py`, `receipts.py`, `review.py`
- `src/fleet/plugins/intake.py`, `landing.py`, `harness_base.py`
