Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

tests last commit release

ai-arena

Run the same Drupal task through several AI candidates at once, each in its own git worktree with its own DDEV project and database, verify each candidate mechanically, let a project-manager session judge the results blind, and promote the winner to a feature/ branch. You talk to one AI harness on your host; it drives everything.

Part of the DDEV AI Workspace. This is a host package (a skill for your host AI harness plus scripts), not a DDEV add-on. The candidates and the project manager run in the AI containers that the workspace installs.

Created by Robert Menetray · Sponsored by DruScan

Why

A single agent gives you one shape. Three candidates on different harnesses and models give you three shapes plus mechanical evidence (PHPStan, PHPCS, PHPUnit, site bootstrap) per candidate, so the judge decides on gates and a rubric instead of prose. With cheap or local models as candidates the token cost is near zero; you trade minutes and disk for quality. A wins log (~/.ddev/ai-arena/wins.tsv) tells you over time which model and harness earns trust for which kind of task.

The layout

One directory per project, the coordinator, holds everything:

projects/<project>/
├── .ddev/              coordinator DDEV project: the AI workspace, no Drupal (layer 2)
├── ai-arena.env        optional per-project settings
├── arena/<slug>/       one folder per arena: manifest, brief, PM sessions, collected candidates
├── backups/            database dumps (optional; the newest "-latest" file is used)
├── main/               the main environment: .ddev/ + <repo>/ (the git clone)
├── worktree/           real branch environments, created with worktree-add
└── worktree-tmp/       arena candidates, disposable (layer 3)

Three layers, one listener:

  • Layer 1, the host harness (Claude Code or OpenCode on your machine, opened in the coordinator) is your only point of contact. It brings the other layers up, runs the ai-arena verbs, relays questions, and reports.
  • Layer 2, the coordinator's AI container. The project-manager session runs there: it reads main/<repo>, writes the brief, answers candidates, sees every candidate live under worktree-tmp/, and judges blind from the collected copies. It has no Drupal and needs none.
  • Layer 3, the candidates. Each is a copy of main/ with a worktree on tmp/<slug>-<label>, its own DDEV project and database. The candidate runs detached in its own AI container, reads the brief, implements, verifies on its own site, and writes a report.

Containers never talk to each other. The host executes commands in them and reads files: arena/<slug>/manifest.json is the single source of truth, and every session is resumable by id, so a question travels up as a report and an answer travels down as a resumed session. Candidates run detached: closing the host session does not stop them. Several arenas can run at once; the main environment never sees any of it.

host: ai-arena ─┬─ up ─────────────▶ coordinator containers (layer 2)
                ├─ plan/pm/judge ──▶ PM session in the coordinator's AI container
                ├─ spawn ──────────▶ worktree-tmp/<base>-tmp-<slug>-a  (worktree-add --tmp)
                ├─ run/resume ─────▶ candidate a AI container (layer 3, detached)
                ├─ wait ───────────▶ arena-run.exit / arena-report.md
                ├─ gate/collect ───▶ arena/<slug>/candidates/<label>/
                └─ promote/clean ──▶ feature/<slug> (+ worktree/ env), worktree-tmp/ removed

Requirements

Linux only. The scripts are developed and tested on Linux and rely on GNU tools and bash 4.4 or newer: readlink -f, flock, iconv, empty-array expansion, hardlinks for the snapshot copy. macOS ships bash 3.2 and BSD userland and is not supported; it may work with Homebrew bash and coreutils but nobody has tested it. Also needed: ddev 1.24.10+, docker, git, jq.

Install

Once on the host:

git clone https://github.com/trebormc/ddev-ai-arena.git
cd ddev-ai-arena && ./install.sh     # copies the skill to ~/.claude/skills and ~/.config/opencode/skills, links ai-arena, worktree-add, worktree-remove and host-skills-sync into ~/.local/bin

Once per project, create the coordinator. Two DDEV rules shape the order:

  • ddev config refuses a new project in a directory that contains an already registered project in a subdirectory, and checks this only while the config does not exist yet.
  • Since DDEV 1.25.4, ddev start in an unregistered project nested inside a registered one asks whether to use the nested project, and ddev start -y silently uses the outer one instead.

So unlist the environments that live under the project directory, create the coordinator, unlist it again (ddev config registers it), register the environments back, and only then start the coordinator:

cd projects/<project>
ddev stop --unlist <base>                      # and any worktree/<env> project that is registered
ddev config --project-type=generic --project-name=<base>-arena
ddev stop --unlist <base>-arena                # keep the coordinator unregistered until main is back
(cd main && ddev start)                        # re-registers the main environment at the same path
ddev add-on get trebormc/ddev-ai-workspace     # AI containers, Playwright, agents pack; no Drupal needed
ddev start                                     # registers the coordinator; its config already exists
ai-arena doctor

worktree-add registers every new environment with ddev config --project-name before starting it, so later environments under worktree/ and worktree-tmp/ never hit the nested-project prompt.

The coordinator's name must differ from the main environment's DDEV name (the base for candidate names); ai-arena doctor fails when they collide. Move your main environment to main/ (or leave it under worktree/<base>/: it is recognised because its repository's .git is a directory).

Usage

Open your host harness in the coordinator and say: "run an arena for: add a handling fee to the order total, three candidates". Or by hand. By default an arena runs in phases, and each phase compares and merges before the next one starts:

ai-arena up
ai-arena init "Add a handling fee" --candidates claude,opencode
ai-arena spawn add-a-handling-fee       # worktree + DDEV + DB per candidate: planners have a running site
ai-arena draft add-a-handling-fee       # phase 1: each candidate writes its own plan
ai-arena wait add-a-handling-fee --all
ai-arena merge add-a-handling-fee       # PM picks one plan blind, improves it with the others
ai-arena run add-a-handling-fee         # phase 2: all implement that brief, in the same sessions
ai-arena wait add-a-handling-fee --all  # deadline for the slow ones; reviews start as each one finishes
ai-arena gate add-a-handling-fee && ai-arena collect add-a-handling-fee
ai-arena judge add-a-handling-fee       # blind, gates first, reads the reviews; writes grafts.md
ai-arena promote add-a-handling-fee b --env
ai-arena graft add-a-handling-fee       # phase 3: ports the grafts into worktree/, then gates
ai-arena review --arena add-a-handling-fee   # double review inside worktree/, with the site
ai-arena graft add-a-handling-fee --message "fix ..."   # Act-on items, then review --arena again
ai-arena reveal add-a-handling-fee
ai-arena compare add-a-handling-fee     # time, steps, tokens and cost per round, tests, gates
ai-arena clean add-a-handling-fee

The result stays uncommitted in the worktree/ environment for you to review. reveal names the label whose plan was the base.

Four rules keep it fast without losing what the comparison brings:

  • Deadline. The first candidate to finish a phase DONE sets it: every other one gets AI_ARENA_DEADLINE_FACTOR (2) times that time, counted from its own start, and wait stops it after that. A stopped candidate is marked cut and cannot win, but its work so far is still collected: the judge reads it for anything worth porting into the winner. In the planning phase, a cut plan can improve the merged brief but never be its base.
  • Self-review first. A candidate reviews its own diff with code-review, fixes what it confirms and lists it under SELF-REVIEW in its report; a DONE report without it fails the report gate. The cheapest fixes happen before anyone else reads the code.
  • Double review with the site running. As soon as a candidate finishes its implementation, two reviews start inside its own environment, with its site and database: self, a fresh session of its own harness and model, and x1..., the other candidates' harnesses. They run tests, drush and the brief's live verification to confirm findings, while the slower candidates still work. judge waits for them, reads them beside each diff (candidates/<label>/review-self.md, review-x1.md), confirms or refutes each finding, and lists the confirmed ones on the winner in grafts.md as fixes.
  • The same double review on the final code. review --arena <slug> runs it inside the worktree/ environment, against the brief, with a lead synthesis and an agreement map. After a fix it checks the previous Act-on list and reviews what changed since, not the whole diff again; status says whether the final code changed since its last review. Reviewers never change code, config or modules; probe content carries the prefix arena-review- and is deleted, and a file left in the tree is reported.

Planned by the PM

--plan-by pm (or AI_ARENA_PLAN_BY=pm) is the flow before phases: one PM session investigates and writes the brief, and every candidate starts fresh on it. Approaches mode uses it unless --plan-by says otherwise. Deadline and candidate reviews work the same; there is no grafts.md and no graft step.

ai-arena init "Add a handling fee" --plan-by pm
ai-arena plan add-a-handling-fee        # PM writes arena/<slug>/brief.md
ai-arena spawn add-a-handling-fee && ai-arena run add-a-handling-fee
ai-arena wait add-a-handling-fee --all
ai-arena gate add-a-handling-fee && ai-arena collect add-a-handling-fee
ai-arena judge add-a-handling-fee
ai-arena promote add-a-handling-fee b --env
Verb What it does
doctor Checks git, jq, ddev, docker, the layout, the coordinator's AI containers, the DB snapshot
up Starts the coordinator's containers
init "<task>" [--candidates ...] [--pm harness[:model]] Creates arena/<slug>/manifest.json
plan <slug> --plan-by pm only: PM session runs code-review PLAN mode over main/<repo> and writes the brief
draft <slug> [label...] Phase 1: each candidate investigates and writes arena-plan.md, changing nothing
merge <slug> Ends phase 1: collects the plans under arena/<slug>/plans/; the PM picks one blind, improves it and writes the brief
spawn <slug> [label...] worktree-add --tmp per candidate: worktree, DDEV project, DB, composer, provisioning
run <slug> [label...] Starts candidates detached on the brief
wait <slug> [--all] [--timeout S] [--interval S] Blocks until a state change, with no timeout unless --timeout S or AI_ARENA_WAIT_TIMEOUT (poll every --interval seconds, default 15); prints JSON. Enforces the phase deadline and starts the reviews of each finished implementation inside its own environment
stop <slug> <label...> Kills a running candidate's harness (TERM, then KILL) and settles its state from the report it wrote; use it for a dead provider or a run that never exits
status <slug> [--json] Candidate states, gates, branches
resume <slug> <label> "<msg>" Continues a candidate's session (answers, new instructions)
pm <slug> "<msg>" Talks to the PM session; prints its parsed verdict
gate <slug> [label...] Site bootstrap, config (unexported config changes fail unless the brief says Config changes: allowed), PHPStan, PHPCS, PHPUnit on changed custom modules, inside each candidate
collect <slug> Diffs, reports, gates into arena/<slug>/candidates/ (no model info)
compare <slug> [--json] Time, steps, tokens and cost per round and in total, tests and failed gates, by label; flags candidates whose production code is identical. Each run and resume is one round, kept under arena/<slug>/rounds/
judge <slug> Waits for the candidate reviews, then the PM judges blind: gates, rubric, conformance, then quality; writes grafts.md in phased arenas
promote <slug> <label> [--branch] [--env] [--allow-undeclared] Refuses files the winner's report does not declare, then records the candidate's working tree as one commit on its tmp/ branch (candidates never commit), then creates feature/<slug> from it; --env also creates its environment under worktree/
graft <slug> [--message "..."] Ports arena/<slug>/grafts.md into the promote --env environment with the winner's harness, then gates it. Blocks; commits nothing. --message continues that session
reveal <slug> Label → harness/model/agents with cost and duration, appends to the wins log
clean <slug> [--keep label] [--purge] Deletes candidates under worktree-tmp/ and their tmp/* branches (the winner's too, once the promoted branch contains it); refuses when the judge picked a winner that was not promoted yet
list Arenas in this project
review (--arena <slug> | --branch <b> | --env <dir> | --patch <file>) [--reviewers a,b] [--intent "..."] Multi-model review of one diff: independent reviewers on different harnesses/models, then a lead synthesis (act on / consider / noted / dismissed). An environment is reviewed inside its own containers, with its site, when they run; a branch or a patch from the coordinator. --arena reviews the arena's final code with a fresh session of its author's harness plus the other candidates' harnesses and, after a fix, checks the previous Act-on list

Comparing approaches instead of models

Sometimes the open question is not which model but which design: field plugin or preprocess hook, queue or synchronous, custom module or configuration. Approaches mode runs the same task with the same model and one prescribed approach per label:

# you dictate the approaches (one --approach per label, in order a, b, ...)
ai-arena init "Add a handling fee" --candidates opencode,opencode \
  --approach "Field plugin on the order entity; fee computed in a presave hook" \
  --approach "Order processor plugin (commerce_order) adding an adjustment; no new fields"
# or let the PM propose them during plan and confirm before spawning
ai-arena init "Add a handling fee" --candidates opencode,opencode --approaches

The contract, rubric and live verification stay common and approach-neutral; each candidate also receives arena-approach.md and must follow it (or report BLOCKED). The judge compares the approaches as implemented and names the one to adopt; reveal and the wins log record the approach of each label. One candidate per approach is one sample: for a weighty decision, run two labels per approach.

Evaluating a change to the agents pack

A candidate is harness[:model][@agents]. The @agents part pins the agents repository that candidate syncs (a branch or tag of the default repo, or a full url#ref), so two candidates with the same model and task differ only in the agents, rules and skills they load:

ai-arena init "Add a handling fee" --candidates claude:sonnet@main,claude:sonnet@feature/new-rule

The branch must be pushed (the containers clone it). Same gates, same blind judge, and reveal shows which agents version each label ran, with its cost and duration, so the wins log becomes an evaluation record for the pack itself. AI_ARENA_AGENTS_REPO sets the default repository the short form refers to.

Multi-model review

The cheapest use of the coordinator: review one diff with several models and let a lead synthesize. No candidate environments, no database; reviewers read the diff and the code from the coordinator's mount.

ai-arena review --branch feature/add-a-handling-fee --reviewers claude,opencode
ai-arena review --env worktree/atlas-feature-x --intent "cache the listing per role"

Reviews land in arena/reviews/<id>/ (diff.patch, one rN.md per reviewer, verdict.md). Reviewers are blind to each other; the lead does not know which model wrote which review. Default panel: AI_ARENA_REVIEWERS in the config.

Ordinary environments

The same scripts manage normal branch environments:

worktree-add feature/DREP-123           # worktree/<base>-feature-DREP-123 from main/, DB, provisioning
worktree-add --db latest feature/x      # import the newest backups/ dump instead of the baseline snapshot
worktree-remove feature/DREP-123        # containers, worktree, directory, branch

worktree-add copies main/ (minus the repo and arena data), strips name: and pinned ports, creates the worktree (existing, remote-tracking, or new branch), copies untracked local config (settings.local.php, dev services files), starts DDEV, runs composer install, provisions the database (baseline snapshot of main/, newest backups/ dump sanitised, or an export of main/), and runs drush cr, updb, cim, cim.

Protocol with the agents

The AI containers follow the arena-protocol skill from drupal-ai-agents: brief format, candidate report (STATUS first line), PM verdict trailer (VERDICT, TO, WINNER, MESSAGE), and judging rules. The prompts in skills/ai-arena/prompts/ carry the minimum inline so a run degrades gracefully if that skill is missing. From the coordinator's Playwright, a candidate's site is reachable at http://ddev-<env_name>-web.

Guardrails

  • Only worktree-tmp/ environments and tmp/* branches are ever deleted; main/ is never edited or removed, and its database is never touched.
  • The judge works from collected copies with no model information; live candidate directories are for answering questions only.
  • No pushes, and the only commit the tool ever makes is promote recording the winner's working tree on its tmp/ branch (candidates never commit); feature/<slug> is a local branch you review, squash or amend, and push yourself.
  • Candidates are told: no Beads, no git writes, only the brief's paths.

Configuration

~/.ddev/ai-arena/config.env (all projects, written by install.sh) and <project>/ai-arena.env (this project): candidate panel, PM harness and model, cap, review timeout (AI_ARENA_TIMEOUT), wait timeout (AI_ARENA_WAIT_TIMEOUT, 0 = wait forever, the default), database mode, base ref, extra local files, AI_ARENA_MAIN_ENV, who plans (AI_ARENA_PLAN_BY, candidates by default), the phase deadline (AI_ARENA_DEADLINE_FACTOR, 2; 0 disables it), the candidate reviews (AI_ARENA_CANDIDATE_REVIEWS, 1), the harnesses that implement in a fresh session reading their own plan instead of resuming the planning one (AI_ARENA_RUN_FRESH, opencode), how many times per phase a candidate that exits cleanly without a report is continued in its session (AI_ARENA_AUTO_CONTINUE, 1; 0 fails it at once) and the review panel (AI_ARENA_REVIEWERS). Candidate models are applied through each environment's .ddev/.env.agents (the cascade ddev-agents-sync already honours) plus the harness's --model flag.

Skills from a private repository

install.sh installs the ai-arena skill on the host. If you keep your own agents repository (public or private), the host agent can use its skills too, which is the place for anything that needs the whole workspace rather than one project. List the repositories in ~/.ddev/ai-arena/config.env:

# Local directories (linked live) or git URLs (url#ref, cloned under ~/.ddev/ai-arena/host-repos/).
AI_ARENA_HOST_SKILL_REPOS=~/repos/my-private-agents,git@github.com:me/more-agents.git

Then run host-skills-sync (install.sh also runs it). Each .claude/skills/<name>/ is linked into ~/.claude/skills/ and ~/.config/opencode/skills/; later repositories win, an existing directory that is not a link is left alone, and skills that disappear are unlinked. This is optional and independent of AGENTS_REPOS, which ddev-agents-sync uses for the containers.

Part of DDEV AI Workspace

Repository Description Relationship
ddev-ai-workspace Meta add-on that installs the full AI development stack with one command. Installed in the coordinator and in every environment
ddev-claude-code Claude Code CLI container. Runs candidates and the project manager
ddev-opencode OpenCode AI CLI container. Runs candidates and the project manager
ddev-ralph Autonomous AI task orchestrator: one task after another through an AI container. Sibling: sequential loop instead of parallel candidates
ddev-agents-sync Syncs agent repos and resolves model tokens per project. Per-candidate model overrides go through its .env.agents cascade
ddev-beads Beads git-backed task tracker. Candidates skip it; the main environment keeps the task
ddev-playwright-mcp Headless Playwright browser. Candidates verify on their own browser; the coordinator can open their sites
ddev-ai-ssh SSH access to the web container. Each environment gets its own keys
drupal-ai-agents 11 agents, 15 rules, 38 skills for Drupal development. Provides the arena-protocol skill

Disclaimer

This project is an independent initiative by Robert Menetray, sponsored by DruScan. It is not affiliated with Anthropic, OpenCode, Beads, Playwright, Microsoft, or DDEV. AI-generated code may contain errors. Always review the winning branch before merging.

License

Apache-2.0. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

Sponsor
SponsoredKunjungi sekarang
Promo