Metadata-Version: 2.4
Name: dobby-subagent-mcp
Version: 0.2.0
Summary: Local stdio MCP server that delegates scoped tasks to Codex or Gemini (Antigravity) worker subagents
Keywords: mcp,codex,gemini,antigravity,subagent,claude,automation,developer-tools
Author: Avery Levitt
Author-email: Avery Levitt <avery23@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: mcp[cli]>=2.0.0,<3
Requires-Dist: pydantic>=2.12.5
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/Averyy/dobby-subagent-mcp
Project-URL: Repository, https://github.com/Averyy/dobby-subagent-mcp
Project-URL: Issues, https://github.com/Averyy/dobby-subagent-mcp/issues
Description-Content-Type: text/markdown

# Dobby Subagent MCP

A local stdio MCP server that lets Claude, or any MCP client, hand one scoped task at a time to a worker CLI and get a structured result back. Planning, research and review stay read-only, builds stay inside the repository, multi-lens reviews are verified from the reviewers' own session records, and every run leaves inspectable logs.

| Provider | Worker | Platforms |
| --- | --- | --- |
| `codex` | OpenAI models through `codex exec` | macOS, Linux |
| `gemini` | Google models through the Antigravity CLI (`agy`) | macOS |

## Tools

| Tool | What it does |
| --- | --- |
| `plan` | Break down a task and propose a scoped plan. |
| `research` | Investigate code, docs and context, and report findings with evidence. |
| `brainstorm` | Evaluate an idea, scope an MVP, and recommend whether to build it. |
| `build` | Implement a change, run focused verification, and report diffs. |
| `validate` | Run the repository's existing build, test or lint commands and report results. |
| `review` | Review code with one lens directly, or fan out to one subagent per lens. |
| `reverse_engineer` | Investigate binaries, with Ghidra when it is configured. |
| `list_models` | List each provider's models and reasoning efforts, read live from its CLI. |
| `start_run` | Start any worker tool in the background and return a `task_id`. |
| `wait_run` | Block until a background run, or the first of several, finishes. |
| `get_run` | Return a run's status, or its final result, without blocking. |
| `list_runs` | List a repository's recent runs, to recover task ids. |
| `cancel_run` | Stop a background run this server started. |

## Requirements

- Python 3.12+ and `uv`.
- A git worktree for the target repository.
- The CLI of each provider you use; the other is not needed:
  - **Codex:** `codex-cli` 0.169.0 or newer (live-tested on 0.174.0), signed in with file-based credentials (`cli_auth_credentials_store = "file"`, the default) or `CODEX_API_KEY`. Codex keys keyring credentials by the `CODEX_HOME` path, which Dobby's private per-run home does not share, so credentials kept in the keyring or in memory (`"keyring"`, `"auto"` or `"ephemeral"`, set by your `config.toml`, `/etc/codex/config.toml`, `/etc/codex/requirements.toml` or a managed profile) fail before launch with that explanation.
  - **Gemini:** macOS and `agy` 1.5.23 or newer, signed in.

Dobby checks the CLI's version before every run, from the run's private scratch directory, never the repository. For Codex it then runs `codex login status` and `codex mcp list --json` the same way; see [Codex workers](#codex-workers).

### Codex project trust

Codex 0.169 and later load project-local configuration and MCP servers only for trusted projects, including in the sandboxed `codex exec` runs Dobby starts. To enable them, run `codex exec --trust` in the target repository from your normal Codex environment before using Dobby; trust saved inside a Dobby run is discarded with its runtime, and an explicitly untrusted project needs its saved setting changed first. When Codex reports disabled project configuration, Dobby adds a warning to the response, even on success. It never grants trust itself. See the [Codex change](https://github.com/openai/codex/pull/60041).

### Optional MCP integrations

- [fetchaller-mcp](https://github.com/Averyy/fetchaller-mcp) lets `research` and `brainstorm` search and fetch the web. It is also left on for `plan`, `build` and `reverse_engineer`.
- [ghidra-mcp](https://github.com/bethington/ghidra-mcp) gives `reverse_engineer` Ghidra.

Dobby finds them in the provider's MCP config: `$CODEX_HOME/config.toml` and the repository's `.codex/config.toml` for Codex, `~/.gemini/config/mcp_config.json` for Gemini. A missing integration is not an error; the prompt tells the worker not to call it. Anything that widens a sandbox, such as the Ghidra helper directory, comes only from your own config, never the repository's, which a worker can write.

## Install

`dobby-subagent-mcp` is not published to PyPI yet. Install it from a checkout:

```bash
uv tool install .
```

Register it with your MCP client under the key `dobby`:

```json
{
  "mcpServers": {
    "dobby": { "command": "dobby-subagent-mcp" }
  }
}
```

To run from the checkout instead, use `"command": "uv"` with `"args": ["--project", "/ABSOLUTE/PATH/TO/dobby-subagent-mcp", "run", "dobby-subagent-mcp"]`. Remove any registration of the server's pre-0.2.0 name first: that server does not honour Dobby's recursion guard.

### Recommended Claude Code setup

Add this to your `CLAUDE.md` so Claude delegates correctly:

```markdown
## Delegating Work to Dobby (dobby MCP)

Offload grunt work — build/test, code review, research, planning, implementation, brainstorming, reverse engineering — to the `dobby` MCP tools instead of doing it inline. Saves tokens and context.

- Give focused prompts with a concrete outcome. One task per call — if you have multiple things to ask, make multiple Dobby calls (in parallel when independent) instead of bundling them into one vague prompt.
- Call `mcp__dobby__*` directly. Never wrap them in a general-purpose Agent/Task subagent.
- Pass the absolute path of the current repository as `repo_root` on every Dobby call except `list_models`, including `get_run`, `wait_run`, `list_runs` and `cancel_run`.
- Name `provider` and `model` on every worker call; call `mcp__dobby__list_models` for current options.
- Don't lower `timeout_seconds` below the default. Err too long — a short timeout kills the run; a long one costs nothing because Dobby returns as soon as it's ready.
- For `review`, omit `agents` or pass one lens for a direct single-agent review. Pass two or more of `generalist`, `security`, `performance`, `architecture`, `correctness`, `ux`, and `regression` for fan-out; use `timeout_seconds=1200` for multi-agent review.
- For long work, start it with `mcp__dobby__start_run`, wait for its `task_id`, then either block on `mcp__dobby__wait_run` or poll `mcp__dobby__get_run` (on Claude Code, `/loop` or `ScheduleWakeup` can schedule the polls). Never race a `start_run` and its lookup.
- A Dobby run takes no further input once started; to change scope, start a new run. To stop one, call `mcp__dobby__cancel_run`.
```

### Environment variables

| Variable | Effect |
| --- | --- |
| `CODEX_BINARY`, `AGY_BINARY` | Worker CLI to run. Otherwise the one on `PATH`, then `/opt/homebrew/bin/codex` or `~/.local/bin/agy`. |
| `CODEX_HOME` | The Codex home runs are seeded from (default `~/.codex`). |
| `CLAUDE_CONFIG_DIR` | Where helper files a Codex config references are mirrored from (default `~/.claude`). |
| `CODEX_API_KEY` | Codex credentials without an `auth.json`. |
| `XDG_CACHE_HOME` | Linux: the private runtime base is `$XDG_CACHE_HOME/dobby` (default `~/.cache/dobby`). |
| `RUST_LOG` | Codex log filter. When unset, Dobby uses codex exec's default plus an SSE trace target. |
| `DOBBY_ACTIVE` | Set to `1` in every worker. Dobby refuses to run where it is set, so it never calls itself. |
| `DOBBY_RUN_ID` | Set in every worker to its task id. |

## Calling the tools

Every tool except `list_models` requires `repo_root`, the absolute path of the target git worktree's top level. A directory inside the worktree is rejected: git reports changes from the top level, so a subdirectory root would miss them. Dobby never infers it from MCP metadata or its own working directory, which is often Dobby's own checkout. `list_models` accepts `repo_root` and ignores it.

Worker tools and `start_run` take:

| Param | |
| --- | --- |
| `prompt` | Required. One task with a concrete outcome. |
| `provider`, `model` | Required. See [Choosing a worker](#choosing-a-worker). |
| `reasoning_effort` | Optional, default `medium`. |
| `files` | Files to start from; the worker widens scope only when they are not enough. |
| `important_context` | High-priority background, delivered verbatim. |
| `timeout_seconds` | Run budget. See [Defaults](#defaults). |
| `extra_roots` | Extra directories, absolute or inside the repository: readable by read-only tools, writable by mutating ones. |
| `agents` | `review` only. See [Review](#review). |
| `danger` | `build` and `reverse_engineer` with `provider="codex"` only. |

An unknown argument name is rejected, so a misspelled `files` cannot silently turn into a whole-repository run. Input errors keep their detail as MCP tool errors.

### Choosing a worker

`provider` and `model` are required and have no default. `provider` is `codex` or `gemini`. `reasoning_effort` is optional and defaults to `medium` for every tool; it must be a level the model supports.

Dobby carries no model list. Options are read live, cached for 10 minutes, and returned by `list_models`:

| | `codex` | `gemini` |
| --- | --- | --- |
| Source | `codex debug models` | `agy models` |
| `model` | catalog slug | family, such as `gemini-4-neon` (the effort suffix is `reasoning_effort`) |
| Not offered | hidden entries | non-Gemini models and orchestrators |
| Suggested | the model in your Codex config, else the catalog's first | the model in your `agy` settings, else the first listed |

A missing or invalid choice fails before any worker starts, and the error lists the valid options. The server instructions list the options as of startup; a catalog not loaded within 10 seconds is named as still loading.

### Defaults

Any explicit `timeout_seconds` must be at least 300s.

| Tool | Timeout | Sandbox |
| --- | --- | --- |
| `plan` | 600s | read-only |
| `research` | 1200s | read-only |
| `brainstorm` | 600s | read-only |
| `review` | 600s direct, 1200s multi-agent | read-only |
| `validate` | 600s | workspace-write |
| `build` | 1200s | workspace-write |
| `reverse_engineer` | 1800s | workspace-write |

A workspace-write run can write the repository and its extra roots, but not their git metadata, `.dobby/`, or the agent configuration in `.codex/`, `.agents/`, `.claude/`, `.gemini/` and `.mcp.json`, so a `build` asked to edit those cannot. Nor can it write git's hooks directory, template directory or a config file git reads, when `core.hooksPath` (on any branch), `init.templateDir` or an `include.path` puts one inside a writable root, nor the `.git` file and hooks directory of another worktree nested inside one, such as `.worktrees/feat`: husky's `.husky/_` is the common case, so a build whose `npm install` runs husky's `prepare` script gets a denied write there. Only a Codex run with `danger=true` can.

`danger=true` runs `build` or `reverse_engineer` with Codex's `danger-full-access`, without a sandbox. Every other tool, including `start_run` with another tool, rejects it, and `provider="gemini"` rejects it everywhere.

### Review

`review` agents: `generalist` (default), `security`, `performance`, `architecture`, `correctness`, `ux`, `regression`. Zero or one effective agent runs directly. Pass two or more for fan-out to one subagent per lens, normally with `timeout_seconds=1200`. Fan-out runs a parent plus one child per lens, so pick only lenses that help. A lens that delivers nothing usable adds a `next_steps` entry saying how to re-run it alone, which takes the direct path. `agents` on any other tool is rejected.

### Background runs

`start_run` takes a worker tool's params plus required `tool`, starts it in the server process, and returns an `AsyncRunHandle` (`task_id`, `tool`, `state`, `summary`, `repo_root`, `artifact_paths`, `provider`, `model`, `reasoning_effort`). An omitted `timeout_seconds` is that tool's default, except that multi-agent review automatically uses 1200 seconds. Independent `start_run` calls may run in parallel, but wait for each one's response before looking up its `task_id`.

`wait_run(repo_root, task_id | task_ids, timeout_seconds)` blocks until a background run finishes: pass `task_id` for one run, `task_ids` for whichever of several finishes first, or neither for every run live for the repository when called. Passing both, or an empty `task_ids`, is rejected. It returns the `get_run` shape plus `pending_task_ids`, the runs still unfinished; re-call `wait_run(task_ids=pending_task_ids)` until that is empty. On timeout `state` is `running`. Runs are shielded from the waiter, so a cancelled or timed-out wait loses nothing, and a run not live in this server, for example after a restart, is answered from its artifacts at once.

`timeout_seconds` is default 540s / 9 min, clamped to `[1, 100_000]`. Keep it below your client's own `tools/call` timeout. Claude Code's `MCP_TOOL_TIMEOUT` defaults to 100,000,000 ms, about 28 hours, which is why the wait is capped at 100_000s. Codex CLI's default is [300 seconds](https://github.com/openai/codex/blob/rust-v0.171.0/codex-rs/codex-mcp/src/rmcp_client.rs#L125), below Dobby's default wait, so raise it first (`tool_timeout_sec = 100000` under `[mcp_servers.dobby]` in `~/.codex/config.toml`) or pass a shorter wait. Other clients vary. A client that gives up on a call never stops the run.

`get_run(repo_root, task_id)` returns a `RunLookupResponse` without blocking: `state`, `summary`, `provider`, `tool`, `status`, `result_state`, `stop_reason`, `artifact_paths`, `warnings`, and the final `result` once finished. `list_runs(repo_root, limit=10)` lists the newest runs in `.dobby/runs/` with the same summary fields.

`cancel_run(repo_root, task_id)` stops a background run this server started: it kills the worker's process group, writes a final `stop_reason: cancelled` result, removes the run's private runtime, and returns the `get_run` shape, waiting at most about 5 seconds for the run to unwind. An unknown or finished run is left alone, with a warning.

Run states:

- `running`: the run is live in this server.
- `finished`: a final result is available.
- `unknown`: the run directory exists without a readable final result. With `result_state: placeholder`, the server that ran it died without cleaning up; the next server start marks it final.
- `not_found`: no such run, or an invalid `task_id`.

A synchronous worker call can still hit the client's `tools/call` ceiling, so prefer `start_run` with `wait_run` or `get_run` for long work. Live tracking is in-process: a server restart loses running work, but finished results stay readable from `.dobby/runs/`.

## Results

Worker tools return a `ToolResponse`: `task_id`, `tool`, `status` (`success` or `error`), `summary`, `completeness` (`full`, `partial` or `blocked`), `important_facts`, `next_steps`, `files_changed` (this run only), `file_diffs`, `artifact_paths`, `sandbox_violations`, `repo_root`, `exit_code`, `duration_ms`, `warnings`, `raw_output_available`, `provider`, `model`, `reasoning_effort`, `result_state`, `stop_reason`, plus `review_details` for `review` and `reverse_engineer_details` for `reverse_engineer`. `sandbox_violations` lists sandbox and permission problems the run hit, such as a declined command or a patch Codex could not apply, whatever its stop reason. A denial the worker hit does not by itself fail the run; the checks under `sandbox_violation` below do.

A run Dobby stops on a timeout or stall before the worker answers still returns what its progress events show: the tail of the worker's narration and its last completed tool calls in `important_facts`, marked as reconstructed in `warnings`.

### Stop reasons

The first three are ACP's `StopReason` values; the rest are Dobby's.

- `end_turn`: the worker delivered a result and nothing failed.
- `refusal`: the worker set `refused: true`; `completeness` is `blocked`.
- `cancelled`: Dobby stopped the run, and the summary says why: the MCP request was cancelled or the client disconnected, `cancel_run`, the server stopped (`Dobby server stopped (SIGTERM)`, or `(stdin closed)`), or a later server start found the run orphaned. Also used when `agy` itself ends with `CANCELED` or `INTERRUPTED`, and by the placeholder result written at start.
- `timeout`: the run used up `timeout_seconds`, which also bounds the CLI check and the pre-run repository snapshot.
- `stall`: Codex only. No stdout or stderr for 180 s (effort `minimal`, `low` or `medium`) or 300 s (any other effort), so Dobby killed the worker.
- `sandbox_violation`: a mutating run without `danger=true` changed a [protected file](#safety), a mutating run moved or removed `HEAD` (a commit, reset or deleted branch), a read-only run reported changing files that Dobby also saw change, or `agy` ended its turn with no answer after denying a permission. Always paired with a `sandbox_violations` entry.
- `error`: anything else that failed: a preflight check (platform, private runtime, a Codex sign-in or MCP listing that failed, a missing or too-old CLI), a non-zero exit, missing or invalid structured output, failed review evidence, a post-run check that ran out of time, or a private runtime that could not be deleted.

`stop_reason` does not decide `status` alone: a review that timed out with usable findings, or a multi-agent review whose parent failed after reviewers delivered verified findings, returns `status: success` and `completeness: partial` beside a `timeout` or `error` stop reason.

### Review details

`review_details` reports the requested and effective lenses, `orchestration_protocol` (`multi_agent_v2`, `agy_subagents`, or null for a direct review), `execution_evidence` (`direct_parent`, `codex_session_rollouts` or `agy_transcripts`), the per-lens `execution_manifest`, `manifest_validated`, `coverage_complete`, and completed, partial, blocked and failed lens counts.

For a multi-agent review Dobby builds the manifest itself from session records it verifies after the run; the parent reports none. The parent only starts reviewers, and the findings, next steps, warnings and per-lens summaries are rebuilt from each child's own verified result, never from the parent's synthesis.

- `manifest_validated: true` means no lens's evidence failed an integrity check. It does not mean every reviewer finished; `coverage_complete: true` does. A direct review has `coverage_complete: null`.
- A lens that never delivered, or whose result failed its assignment attestation, is lost coverage: it is `failed`, and the other lenses' verified findings still return as a partial success.
- A lens whose evidence contradicts what Dobby asked for (started twice, the wrong role or arguments, a collaborating child, a parent message or follow-up task sent to it after its spawn, file changes) fails integrity: it contributes no text at all, its summary is a neutral placeholder, and the run reports `manifest_validated: false` with `status: error`, though `important_facts` may still hold the other lenses' verified findings.
- Evidence that cannot be trusted as a whole (an unexpected or nested session, an unselected subagent, a parent message to no selected lens or to all of them at once, unreadable records) discards every finding.
- A `blocked` child is not usable coverage.

Each reviewer gets its scope from Dobby, not the parent: Dobby writes a per-run agent definition with that lens's canonical assignment inlined into the private runtime. A child whose task message carries a different assignment must review the one Dobby gave it and report the conflict in `warnings`. Each child also attests the assignment's SHA-256 at the start of its summary. The digest is only a consistency check: the parent knows it too, so on its own it would prove a child saw the assignment's identity, not that it reviewed that scope. Scope substitution is bound rather than made impossible: enforcement is an instruction the reviewer model follows, so a child persuaded by a crafted task payload while still echoing the expected digest would pass every mechanical check.

### Reverse-engineering details

`reverse_engineer_details.ghidra` reports whether Ghidra was configured, a `mode` (`not_configured`, `prelaunch_failure`, `no_activity`, `startup_only`, `direct_mcp` or `helper_fallback`), a summary, and the observed `mcp_calls` and `helper_calls`, read from the run's progress events.

### File diffs

Mutating tools return one `file_diffs` entry per changed file inside the repository:

```jsonc
{
  "path": "/abs/repo/src/foo.py",
  "oldText": "...",      // null for new files
  "newText": "...",      // null for deleted files
  "truncated": false     // true for files over 2 MB or binary; both texts are then null
}
```

Names follow ACP's camelCase `diff` shape on the wire, in `result.json` and in `events.jsonl`. Diffs come from before-and-after snapshots, with one 60-second budget for every `git show` in a run; files past it get no diff and are named in `warnings`. A worker may also supply `file_diffs` for changes the snapshot cannot reconstruct. Read-only tools always return `file_diffs: []`.

## Streaming progress

Every run writes ACP-shaped events to `events.jsonl`. When the `tools/call` request carries a `progressToken`, Dobby also sends each event as an MCP `notifications/progress`: `progress` counts events, `message` is a short label, and the event itself is in `_meta.acpEvent`. Events use ACP `session/update` shapes: `agent_message_chunk`, `tool_call` and `tool_call_update` (with `kind` one of `read`, `edit`, `delete`, `move`, `search`, `execute`, `think`, `fetch`, `other`, and `rawInput` where known), and `plan`.

Live delivery never slows the worker and is best-effort: a client more than 1024 events behind misses the newest notifications, and one that stops responding is abandoned once the run's timeout is spent. `events.jsonl` always records every event. A line that is not JSON or nests too deeply is skipped, as is a line still unfinished after 1 MiB, up to its newline; `stdout.log` keeps every byte.

For a background run, events go only to a `wait_run` caller currently waiting on it, tagged with `_meta.taskId` and `_meta.perTaskCount`. Earlier events are not replayed; read `events.jsonl`.

## Files on disk

Each run writes `<repo_root>/.dobby/runs/<task-id>/`: `request.json`, `prompt.txt`, `stdout.log`, `stderr.log`, `last_message.txt`, `result.json`, `output-schema.json` and `events.jsonl`. `result.json` is replaced atomically: it holds a placeholder from the start until the final result. Treat `.dobby/` as unredacted local logs. Mutating tools add `.dobby/` to `.gitignore`, and refuse a `.gitignore` that is a symlink, has several hard links, is not a regular file or is larger than 4 MiB; they never read it past that size. Invalid task ids and symlinked artifact paths fail closed.

A mutating worker can write its run directory, so Dobby treats every artifact it reads back as untrusted. It reads one only as a regular file: never through a symlink, never a FIFO or a device, and never past a size cap far above what real runs write (`stdout.log`, `stderr.log` and `events.jsonl` 256 MiB, of which only the end is read past the cap; `result.json` 256 MiB; `last_message.txt` and `request.json` 16 MiB). Anything else reads as unreadable, with a warning naming the file. Dobby creates each log fresh and replaces every other artifact by renaming a new file over it, so it never opens what a worker left at that path. If the run directory itself was replaced, for example by a symlink, Dobby neither reads the run's logs and result from the replacement nor writes anything into it, and the run fails with `status: error` saying so. A mutating run cannot write `.dobby/` at all, so it cannot edit another run's artifacts, such as the `result.json` that `get_run` returns, unless it is a Codex run with `danger=true`. `output-schema.json` is only the run's record: each CLI reads a private copy in the run's runtime.

Each run also gets a private runtime outside the repository and outside system temp, mode `0700`:

```text
~/Library/Caches/dobby/<task-id>/     Linux: ${XDG_CACHE_HOME:-~/.cache}/dobby/<task-id>/
  .lock           locked by the run for its whole life
  owner.json      task id, run directory, server pid, worker pid and process group, start time
  output-schema.json  the output schema the CLI reads, mode 0600
  scratch/        the worker's TMPDIR and per-run caches, writable
  codex-home/     Codex: copied auth.json, rewritten config.toml, sessions, per-run review agents
  claude-config/  Codex: helper files the Codex config references
  home/           Gemini: private HOME with a link to your keychain folder
  workspace/      Gemini: agy's empty working directory
  settings.json   Gemini: the run's permission rules
```

A runtime is always created fresh, never adopted, and removed when the run ends, without following the keychain link. If it cannot be removed, the run fails with `status: error` naming the path, because it holds copied credentials; a scratch tree that cannot be removed is only a warning. The base must be owned by you and not be a symlink.

## Stopping and recovery

Every stop Dobby controls leaves a final `stop_reason: cancelled` result saying why: an MCP cancellation or client disconnect, `cancel_run`, or the server stopping.

SIGTERM, SIGINT, SIGHUP and stdin EOF stop the server cleanly. It kills every worker's process group, gives runs about 1.5 seconds to unwind, writes the results they did not, removes their private runtimes, and exits; a watchdog finishes the job after about 3 seconds if that stalls. A placeholder `result.json` therefore means a server died without cleaning up, for example on SIGKILL.

On startup Dobby sweeps the runtime base in the background. A runtime whose lock is free belongs to a dead server: its worker group is killed only when a live member's command line names that run's runtime or run directory, the runtime is removed, and a placeholder result becomes a final `cancelled` result saying it was interrupted, but only in a directory shaped like the run's own `<repo>/.dobby/runs/<task-id>`, whatever `owner.json` claims. Runtimes locked by a live server are skipped. One without a lock file is never deleted, only reported once it is more than two minutes old. One with a lock but no `owner.json` may be a claim still in progress, so it is skipped without touching its lock until it is two minutes old, then removed as an orphan.

## Safety

These apply to both providers.

- **No recursion.** Workers get `DOBBY_ACTIVE=1`, and Dobby refuses to run inside one.
- **MCP allowlist.** MCP servers run outside the worker's sandbox, so each role keeps only the servers it uses: `fetchaller` for `plan`, `research`, `brainstorm` and `build`; `fetchaller` and `ghidra` for `reverse_engineer`; none for `validate` and `review`. Every other configured server is turned off, and so is anything recognisable as Dobby, even under an allowed name.
- **No commits.** Commits are forbidden. A mutating run that moves or removes `HEAD` returns `status: error` with `stop_reason: sandbox_violation`.
- **Protected files.** Some files make git, Codex, Claude Code or Gemini CLI run code outside any sandbox the next time you use them: `.codex`, `.agents`, `.claude`, `.gemini` and `.mcp.json`, and the `.git` entry itself, in the repository and every writable root, plus `hooks`, `config`, `config.worktree` and `info/` in each one's git directory and common git directory. So are git's hooks directory and every other one that a `core.hooksPath` in any config file names (an include for another branch can bring it into effect), every template directory `init.templateDir` or `GIT_TEMPLATE_DIR` names (`git clone` runs its hooks at once), and every config file git reads or an `include.path` or `includeIf.<condition>.path` names (whether its condition holds now or not, and including one set through `GIT_CONFIG_COUNT` or `GIT_CONFIG_PARAMETERS`), wherever your repository, global or system config puts them inside a writable root; the `.git` entry of every other worktree of the repository inside one, with its hooks directories, a relative `core.hooksPath` resolved against that worktree; and, for any protected path that is or lies below a symlink, where it leads inside a writable root. For Codex, the writable roots include your own `[sandbox_workspace_write]` `writable_roots`, and git's hooks, template and config paths under `/tmp`, which Codex's `:workspace` makes writable, count too. Before and after every run Dobby fingerprints them by metadata alone (type, permissions, owner, inode, and for files size, mtime and ctime), listing directories only through descriptors that follow no link, and never reading a file. A change fails a mutating run without `danger=true` with `stop_reason: sandbox_violation` naming the paths. A `danger=true` run only warns, and so does a read-only run, whose sandbox lets the worker write none of them, so the change is almost surely yours. Who made the change cannot be told, so during a mutating run your own changes count too: Claude Code saving an approval to `.claude/settings.local.json`, or `git push -u`, `gh pr checkout` or `git config` writing `.git/config`. An extra root of `$HOME`, or for Codex a `writable_roots` entry of `$HOME` in your own config, makes `~/.claude`, which Claude Code writes in normal use, a protected path. Never compared: `.claude/worktrees`, `.claude/agent-memory`, `.claude/scheduled_tasks.lock`, `.DS_Store` and git's `info/refs`, which change in normal use. Each tree is compared up to 10,000 entries; past that the run warns. Only the hook itself is protected, not what it runs: a hook that is a symlink to a file in the repository, or that runs repository code (husky's `npx lint-staged` reading `lint-staged.config.js`, a hook calling `./scripts/check.sh`), runs a worker's edit to that file at your next commit.
- **Read-only attribution.** A read-only worker's sandbox blocks its writes, so a change Dobby observes during the run is someone else's, such as you editing in another terminal: it is a warning. It is a sandbox violation only when the worker also reports changing that file.
- **Process groups.** Every worker runs in its own session. Stopping one sends SIGTERM to its process group, so a git child can release `index.lock`, then SIGKILL after a grace period; a group Dobby has killed, or whose worker it has reaped, is never signalled again. After the worker exits, a descendant still holding its output pipes gets a brief grace before the group is killed, so the run reports the real exit code instead of waiting out its timeout. A descendant that left the group (for example with `setsid`) is abandoned after a short drain, with a warning.
- **Dobby's own git.** Snapshots, `HEAD` lookups and diffs run `git --no-optional-locks -c core.fsmonitor=false -c core.hooksPath=/dev/null`, and `git show` runs with `--no-textconv`, so configuration a worker planted cannot run code outside the sandbox, and an interrupted snapshot never leaves `index.lock` behind. `git status` reads no `.gitattributes` from the worktree (git 2.40 or newer), so a worker cannot make it run a clean filter, and it never runs git inside a submodule, whose `.git` file a worker could redirect. An edit inside a submodule is reported as the submodule's path, found from file metadata, without a per-file diff. The snapshot helper is a separate Python process started in isolated mode outside the repository, so a module a worker wrote there (a `json.py`, say) is never imported. To find where your own git runs hooks and which config files it reads, Dobby runs `git rev-parse` and `git config --list` without the `core.hooksPath` override; neither runs a hook. It lists the repository's other worktrees with `git worktree list --porcelain -z`, which needs git 2.36 or newer; with an older git every run fails before launch.
- **Log failures.** If a worker's output cannot be written to its log, for example on a full disk, Dobby keeps reading and mapping it so the worker is never blocked, and says so in `warnings`.
- **Config files.** Dobby reads each config it parses (your Codex `config.toml`, the repository's `.codex/config.toml`, `agy`'s MCP config and settings) only as a regular file of at most 1 MiB, so a FIFO or a huge file there cannot freeze or exhaust the server. A symlink to one of your own configs is followed, as a dotfiles setup needs; a symlink at the repository's `.codex` or `.codex/config.toml` never is, because a worker could plant one.
- **Snapshots.** Change detection hashes only regular files. A FIFO, socket or device in the repository is fingerprinted by its type and metadata without being opened, so a FIFO a worker left where a tracked file was cannot hang later snapshots.

## Codex workers

- **Private home.** Each run gets its own `CODEX_HOME` (`<runtime>/codex-home`), seeded from your `auth.json` and `config.toml` with paths rewritten, plus helper files the config references under `CODEX_HOME` or `CLAUDE_CONFIG_DIR`; the home itself and its `sessions/` are never copied. Saved project trust carries over. The server needs read access to those files. Codex runs in the repository with `approval_policy="never"`, `--json`, and the `apps` and `plugins` connectors off.
- **Unreadable config.** If your `config.toml` or the repository's `.codex/config.toml` exists but Dobby cannot read it safely (a symlink in the repository, a FIFO, over 1 MiB) or parse it as UTF-8 TOML, the run fails before launch with `status: error` naming the file: Codex could start MCP servers from it that Dobby could not turn off. A repository whose `.codex` is a symlink to shared config therefore cannot run Codex workers until it is a real directory.
- **Sign-in check.** Before launch, `codex login status` runs against the private home, so credentials Dobby could not copy fail the run with an explanation instead of at the first model request. It is skipped with `CODEX_API_KEY`, and for a model provider that does not use Codex's sign-in: a built-in other than `openai`, or a custom provider without `requires_openai_auth = true`.
- **MCP servers.** Dobby turns servers off with a single `-c mcp_servers={...}` table that repeats each server's own `command` or `url`, so a name with a dot or a space works, and so does a server defined only in an untrusted repository's `.codex/config.toml`. It finds them in your `config.toml`, the repository's `.codex/config.toml`, and `codex mcp list --json`, which it runs before launch against the private home and which also sees `/etc/codex/config.toml`, a managed profile and a cloud-managed config. If that listing fails or prints something Dobby cannot read, the run fails before launch. The listing never starts a server, but for an enabled HTTP server Codex holds no credentials for, it fetches the server's OAuth metadata. Dobby passes the listing its own overrides, so that reaches only servers the role keeps and servers no file Dobby reads defines.
- **Sandbox.** Read-only tools run in `-s read-only`, which reads anywhere and writes nowhere, so they get no `--add-dir`. Mutating tools without `danger=true` run in a per-run permission profile, `dobby_<task id>`, that extends Codex's `:workspace` and keeps `.dobby`, `.claude`, `.gemini`, `.mcp.json`, `.codex`, `.git`, `.agents` and `.aws` read-only (on macOS in any letter case) in the repository and every writable root, for shell commands and `apply_patch` alike, along with other worktrees' `.git` entries and git's hooks directories, template directories and config files where a writable root, or the `/tmp` that `:workspace` makes writable, holds them (see [Protected files](#safety)). Codex also keeps read-only where any of these leads through a symlink. A run whose hooks or template directory is a whole writable root (`core.hooksPath = .`), or whose hooks, template or config path holds `*`, `?`, `[` or `]`, which a profile reads as a pattern, is refused before launch. Each extra root and the scratch directory are added with `--add-dir`. Your own `[sandbox_workspace_write]` grants carry over: `writable_roots` become extra `--add-dir` roots, `network_access` turns on the profile's network, and `exclude_slash_tmp` makes `/tmp` read-only. The repository's config never adds a grant, and neither does `/etc/codex/config.toml`. An administrator's `allowed_permission_profiles` requirement that does not allow the profile makes Codex fall back to another one, without those read-only entries. `validate` is workspace-write because validation writes caches and build output; its prompt forbids source edits.
- **Environment.** The worker keeps your environment, since Codex needs its credentials and its `shell_environment_policy` filters them from shell commands. `TMPDIR`, `UV_CACHE_DIR` and `XDG_CACHE_HOME` point into scratch.
- **Stalls.** Dobby sets `RUST_LOG` so Codex keeps writing its SSE trace to stderr during long reasoning, and kills a run that is silent past the [stall threshold](#stop-reasons).
- **Progress.** Events are mapped from codex-cli 0.171's `exec --json` shapes in `src/dobby_subagent_mcp/backends/codex/events.py`. Sandbox denials are read from the same stream: a declined command, a denial in a failed command's output, and a patch that failed to apply, named by its paths (the stream does not say why a patch failed). A patch Codex's own path check rejects, and a shell command it reports as sandbox-denied the moment it starts, leave no item in the stream, so they are not listed.
- **Multi-agent review.** The parent runs at `low` effort with `multi_agent_v2` enabled and spawns one task per selected custom reviewer with the exact custom role, a canonical assignment bound to the requested repo, task, files and context, and `fork_turns="none"`. Reviewers run at `reasoning_effort`, and spawned threads are capped at the number of selected lenses. Dobby pins the rest of the `[features.multi_agent_v2]` settings, so a table in your or the project's config cannot change them: the parent's collaboration tools are exactly `spawn_agent`, `list_agents`, `wait_agent` and `interrupt_agent`, called directly rather than from a code cell, with no `send_message`, no `followup_task` and no model override on spawn. codex-cli 0.174 can pick multi-agent v3 for a model from its catalog; Dobby does not verify v3 yet, so such a review fails and says to choose a model whose catalog entry uses v2. Codex persists the `message` tool argument as opaque provider ciphertext (a Fernet token in codex-cli 0.171), so Dobby requires every other spawn field to remain exact, provisionally accepts a single message value with the Fernet token structure, and binds it to a SHA-256 assignment identity attested by the independently correlated child terminal result. From the private session rollouts, which it forces Codex to keep and reads before deleting the runtime, Dobby verifies root v2 mode; each child's task, thread, role and v2 mode, correlated through its start record (an `item_completed` `SubAgentActivity` item, or the legacy `sub_agent_activity` event) and its spawn output; no child collaboration calls; no parent collaboration calls beyond spawning, listing, waiting for and interrupting reviewers, so a parent `send_message` or `followup_task` fails the lens it names (or the whole review, when it names no selected lens); one strict read-only terminal JSON result; and the identical completed payload the parent observed. `execution_evidence` is then `codex_session_rollouts`. If the parent times out after children delivered, their findings are salvaged from the rollouts.
- **Ghidra.** `reverse_engineer` mounts as writable roots the helper repository your own Codex `ghidra` server config names in `$CODEX_HOME/config.toml` (its `helper_dir`, or the directory of `bridge_mcp_ghidra.py`) and any live Ghidra socket directory. The repository's `.codex/config.toml` never adds a writable root, trusted project or not. When a mounted root holds `bridge_mcp_ghidra.py`, the prompt offers it as a fallback for missing dynamic Ghidra tools. A live socket also turns on the permission profile's network access, because connecting to a Unix socket is a network operation to Codex's sandbox and Codex has no narrower grant that works without its managed proxy.

## Gemini workers

- **Private runtime.** Each run gets its own `HOME`, so `agy` sees only configuration Dobby wrote for the run. Your keychain folder is linked in so `agy` stays signed in. Only the role's allowed MCP servers are copied from `~/.gemini/config/mcp_config.json`, and each one that starts a process gets your real `HOME` in its `env` unless you set one, so it finds its own configuration.
- **Sandbox.** `agy`'s terminal sandbox plus per-run permission rules; no auto-approval flag is ever passed. The repository is never `agy`'s working directory or an `--add-dir`, because `agy` starts MCP servers a workspace declares outside the sandbox even when the folder is untrusted, so repository instruction files are not loaded automatically and the prompt tells the worker to read them. Read-only tools cannot write the repository, and shell commands have no network.
- **Temp and git.** Reads and writes in the system temp directories (the resolved `tempfile.gettempdir()`, `/private/tmp` and `/tmp`) are denied unless one holds a granted root. Mutating runs cannot write the git directory, common git directory or `.git` entry of the repository, or of any writable root that is a git worktree, nor `.git` in any other writable root, where a planted `.git/config` would run in your next git command there, nor `.dobby/` in the repository or any writable root, so they cannot touch run artifacts. Nor can they write `.codex/`, `.agents/`, `.claude/`, `.gemini/` or `.mcp.json` there, whether or not they exist yet: a later Codex run would start MCP servers from a planted `.codex/config.toml`, and Claude Code or Gemini CLI would run a planted hook or MCP server, all outside any sandbox. The same goes for other worktrees' `.git` entries and git's hooks directories, template directories and config files inside a writable root, and, since `agy` resolves symlinks before it matches a rule, for where any protected path leads through a symlink inside one. `agy`'s file tools match permission rules case-sensitively while macOS volumes usually are not, so Gemini denies each protected path in every spelling below a writable root: each letter in either case, plus every other character APFS treats as ASCII text (`ſ` for `s`, the Kelvin sign for `k`, `ß` and `ẞ` for `ss`, the ligatures `ﬀ`, `ﬁ`, `ﬂ`, `ﬃ`, `ﬄ`, `ﬅ` and `ﬆ`, and the Greek question mark and varia for `;` and a backtick), in every mix. That is 488 rules per root, plus 72 for husky's `.husky/_`. A run that would need more than 4096 such rules is refused before launch: that allows at most eight writable roots side by side, a root nested inside another multiplies its rules by every spelling of the path between them, and every letter of a protected path deep inside a root doubles its rules, so a nested worktree at `.worktrees/feat` (147,456 spellings of `.worktrees/feat/.git`) or a hooks path such as `tools/release-hooks` refuses every Gemini mutating run in that repository. So is a run that would have to respell another non-ASCII character, or whose hooks directory is a whole writable root. `agy` reads a private copy of the output schema, never the one in the repository.
- **Environment.** Variables whose names look like credentials (containing `KEY`, `SECRET`, `TOKEN`, `PASSWORD`, `PASSWD`, `CREDENTIAL` or `COOKIE`, starting `AWS_`, `AZURE_`, `GCP_` or `GOOGLE_APPLICATION_CREDENTIALS`, plus `SSH_AUTH_SOCK` and `GPG_AGENT_INFO`) are not passed to `agy`, and neither is `VIRTUAL_ENV`. `TMPDIR` and the uv, npm, Go, cargo and XDG caches are per run in scratch and start empty.
- **Toolchains.** Builds may read your real uv Python installs, rustup toolchains and `~/.cargo/bin`, but never write a real cache. With no network, builds rely on an environment that is already synced (an installed `.venv`, `node_modules`, vendored crates). Only uv and git have been verified.
- **Limits.** `agy`'s web search needs no permission, even in read-only runs. Ghidra on this backend is untested. `danger` is not supported.
- **Denials.** `agy` can report success with an empty answer after denying a permission; Dobby returns that as `stop_reason: sandbox_violation`.
- **No stall detection.** `agy` is silent while a tool runs, so a Gemini run is bounded by its `timeout_seconds` alone.
- **Multi-lens review.** One `agy` subagent per lens, each defined in the private runtime with its assignment inlined and limited to reading files, running sandboxed commands and messaging the parent. Findings come only from each subagent's own transcript; there is no parent-observed copy to compare. `review_details` reports `orchestration_protocol: "agy_subagents"` and `execution_evidence: "agy_transcripts"`. The parent and the reviewers share one `reasoning_effort`, because `agy` takes one effort per session. Every `invoke_subagent` call and every announced subagent must name a selected lens, or every finding is discarded. A call may pass `Prompt`, `Role` and `TypeName`, plus a `Model` equal to the run's model (optionally with its effort suffix) or an empty `Workspace`; anything else, or starting a lens twice, fails that lens's integrity check. So does a parent `send_message` to a started lens's conversation; a parent message to any other recipient, including the `@children` broadcast, discards every finding. When Dobby stops a run at its timeout, a subagent directory whose identity never reached the stream is only a warning if its transcript shows no message and no forbidden tool, and there are no more such directories than lenses that never reported one.

## Development

```bash
uv sync
uv run pytest
uvx ruff check src tests scripts
uv run mcp dev src/dobby_subagent_mcp/server.py:app
uv run python -m dobby_subagent_mcp
```

The default suite covers the `0.164.0`+ multi-agent v2 child-session shape with synthetic rollouts and a sanitized real codex-cli 0.171.0 review capture (`tests/fixtures/codex-0.171-v2-review`), and the `codex exec --json` event shapes with a fixture built from codex-cli 0.171's `exec_events.rs`. The live suites last passed against `codex-cli 0.174.0` and `agy 1.5.24` (2026-12-04).

Tests marked `live` run against a real worker CLI and skip when it is missing. CI's `live-codex-flags` lane runs those not marked `live_auth` against the latest published `@openai/codex` with `DOBBY_REQUIRE_LIVE=1`, which turns their skips into failures, so upstream flag drift is caught. Tests marked `live_auth` need a signed-in CLI and run only locally:

```bash
DOBBY_RUN_LIVE_V2=1 uv run pytest -m live tests/test_live_codex_v2.py tests/test_live_codex_build.py
DOBBY_RUN_LIVE_GEMINI=1 uv run pytest -m live tests/test_live_gemini.py
```

Mutation testing is described in `AGENTS.md`.

Release tags must exactly match `project.version`; for version `0.2.0`, tag `v0.2.0`. The publish workflow checks this before testing and building. A release is ready only after the full suite, both authenticated live suites, `uv build`, and an MCP initialize check of the installed wheel over stdio, which must advertise Dobby's version, all pass. The source distribution includes `AGENTS.md`, `CHANGELOG.md`, `scripts/` and `tests/`.
