ai-dispatch 5.9.0

Multi-AI CLI team orchestrator
# v5.2 — Test Isolation + Per-Agent Analytics + Agent Fork
# Three independent features, dispatched in parallel.

[defaults]
verify = true

[[task]]
agent = "codex"
prompt = """
In tests/e2e_test.rs, the test file already uses TempDir for AID_HOME isolation via the aid_cmd() helper, which is good.

However, there are potential issues with tests that share global state. Review all test files in tests/ and fix any isolation gaps:

1. Check all e2e test files (e2e_test.rs, auto_selection_e2e.rs, init_e2e.rs, template_e2e.rs) — verify EVERY test uses its own TempDir for AID_HOME via aid_cmd() or aid_cmd_in()
2. Check for any tests that rely on the real filesystem (real ~/.aid, real PATH agents) instead of mocking/isolating
3. In auto_selection_e2e.rs, the PATH manipulation looks correct — verify no test leaks state to other tests
4. Check src/ for any unit test modules (#[cfg(test)] mod tests) that use global state (OnceLock, static mut, etc.) — especially src/agent/registry.rs which uses a static REGISTRY OnceLock. If tests rely on this, they'll conflict when run in parallel.
5. For the registry OnceLock issue: if it exists, refactor so tests can inject their own registry state instead of sharing the global singleton.

The goal: `cargo test` with default parallelism should NEVER have flaky failures from shared state.

Keep changes minimal — only fix actual isolation issues, don't refactor unrelated code.
"""
worktree = "v52-test-isolation"

[[task]]
agent = "codex"
prompt = """
Add a new `aid usage --agent <name>` subcommand option that shows per-agent analytics for a specific agent or all agents.

Current state: src/usage.rs already has AgentUsageRow with tasks, tokens, cost_usd, success_rate, avg_duration_secs, retry_count, last_task_at. The existing `aid usage` shows a summary table.

What to add:

1. In src/cmd/usage.rs (or wherever the usage CLI handler is), add an optional `--agent <name>` flag that filters to show detailed stats for one agent.

2. Add a `--period <window>` flag: "today", "7d", "30d", "all" (default: "all"). Filter tasks by created_at within the time window.

3. When `--agent` is specified, show an enhanced single-agent view:
   - Total tasks / success / fail / retry counts
   - Total cost and tokens
   - Average duration
   - Cost per successful task
   - Trend: compare current period to previous period of same length (e.g. "7d" compares last 7d to 7-14d ago)
   - Top 5 most expensive tasks (id, prompt snippet, cost, duration)

4. When showing all agents with `--period`, show the existing table but filtered to the time window.

5. Add `--json` flag to output the analytics as JSON for scripting.

Modify src/usage.rs for the data collection logic and src/main.rs for CLI arg parsing. Keep the existing `render_usage` working as-is when no flags are passed.

File structure context:
- src/usage.rs: UsageSnapshot, AgentUsageRow, collect_usage(), render_usage()
- src/main.rs: CLI arg parsing with clap
- src/store.rs or src/store_workgroups.rs: Store with list_tasks(TaskFilter)
- src/types.rs: Task, TaskFilter, TaskStatus, AgentKind
"""
worktree = "v52-agent-analytics"

[[task]]
agent = "codex"
prompt = """
Add `aid agent fork <name>` subcommand that creates a local editable copy of an agent definition.

Current state:
- src/cmd/agent.rs: handles `aid agent list`, `aid agent show <name>`, `aid agent add <name>`, `aid agent remove <name>`
- src/agent/registry.rs: loads custom agents from ~/.aid/agents/*.toml, has resolve/list/exists functions
- src/cmd/store.rs: `aid store install` downloads agent TOMLs from GitHub into ~/.aid/agents/

What to implement:

1. Add `aid agent fork <name> [--as <new-name>]` subcommand in src/cmd/agent.rs
   - If <name> is a built-in agent (codex, gemini, cursor, opencode, kilo, ob1, codebuff): generate a TOML config that wraps the built-in CLI with default capability scores, save to ~/.aid/agents/<new-name>.toml
   - If <name> is a custom/store agent: copy its existing TOML to ~/.aid/agents/<new-name>.toml
   - Default <new-name> is "<name>-custom" (e.g. `aid agent fork codex` creates `codex-custom.toml`)
   - Print the path of the created file so user can edit it

2. For built-in agent forking, generate a reasonable TOML config based on the agent's known properties:
   - command: the CLI binary name (e.g. "codex" for codex)
   - prompt_mode: how the agent receives prompts (arg, flag, stdin)
   - capability scores: use the scores from src/agent/selection.rs AGENT_CAPABILITIES const
   - Include helpful comments in the generated TOML explaining each field

3. Add the "fork" subcommand to the clap CLI in src/main.rs (under the existing agent subcommand)

4. Add a simple test: fork a built-in agent, verify the TOML file is created with expected fields

Keep it simple — no network calls, just local file operations.
"""
worktree = "v52-agent-fork"