feat(web,coder): arena pane — compare 2-6 AI competitors on same prompt

Arena is a new pane kind for competitive AI evaluation. A Battle runs
the same prompt against 2-6 Contestants across two concurrent lanes:
local lane (llama-swap models, serial) and cloud lane (parallel).

Added to all three registries: @boocode/contracts WsFrameSchema,
server InferenceFrame, and web WsFrame.

Backend (apps/coder):
- arena-runner: battle scheduler, lane classifier, benchmark, results
  writer, resume, user winner override
- arena-analyzer: two-stage digest→judge analysis on DEFAULT_MODEL
- arena-decisions: status transitions and resume logic (unit-tested)
- arena-analyzer-helpers: pure helper functions (unit-tested)
- arena-model-call: model call utility for analysis
- arena routes: create/get/list/stop/analyze/cross-examine/winner/diff
- schema: battles, contestants, cross_examinations tables (idempotent)
- remove old /api/arena* routes and tasks.arena_id column

Frontend (apps/web):
- ArenaLauncherDialog: battle type, prompt, contestant selection
- ArenaPane: live roster, streaming output, analysis, cross-exam
- DiffView: unified diff with line-by-line color for coding contests
- Winner override per-row dropdown (Trophy icon)
- battle_updated WS handler for live winner/analysis updates
- arena pane kind in Workspace, ChatTabBar, useSidebar

Cross-app:
- ArenaState and ArenaContestantShape/WsFrame types (contracts)
- battle_* frames in WsFrameSchema, InferenceFrame, and web WsFrame
- manifest.json written per battle results folder
- /Arena added to .gitignore
This commit is contained in:
2026-06-06 23:25:29 +00:00
parent 84a024a5a4
commit 3474be4865
34 changed files with 4581 additions and 146 deletions

View File

@@ -27,6 +27,9 @@ import type {
WorkspaceState,
FlowRunRow,
FlowStepRow,
BattleShape,
ContestantShape,
CrossExaminationShape,
} from './types';
// v2.6 Phase 1-UX §9b: chat-scoped agent-session rows. Returned by
@@ -518,6 +521,63 @@ export const api = {
request<AgentsResponse>(`/api/projects/${projectId}/agents`),
},
// Arena battle API — proxied to boocoder at /api/coder/battles/*.
battles: {
create: (body: {
project_id: string;
battle_type: 'coding' | 'qa';
prompt: string;
contestants: Array<{ identity: string; model: string }>;
}) =>
request<{ battle_id: string }>('/api/coder/battles', {
method: 'POST',
body: JSON.stringify(body),
}),
list: (projectId: string) =>
request<{ battles: BattleShape[] }>(
`/api/coder/battles?project_id=${encodeURIComponent(projectId)}`,
),
get: (battleId: string) =>
request<{
battle: BattleShape;
contestants: ContestantShape[];
cross_examinations: CrossExaminationShape[];
}>(`/api/coder/battles/${encodeURIComponent(battleId)}`),
stop: (battleId: string) =>
request<{ cancelled: boolean }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/stop`,
{ method: 'POST' },
),
analyze: (battleId: string) =>
request<{ triggered: boolean }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/analyze`,
{ method: 'POST' },
),
crossExamine: (battleId: string, body: { identity: string; model: string }) =>
request<{ cross_exam_id: string }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/cross-examine`,
{ method: 'POST', body: JSON.stringify(body) },
),
getAnalysis: (battleId: string) =>
request<{ text: string }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/analysis`,
),
generatePrompt: (description: string) =>
request<{ prompt: string }>('/api/coder/battles/generate-prompt', {
method: 'POST',
body: JSON.stringify({ description }),
}),
setWinner: (battleId: string, body: { winner_contestant_id: string | null }) =>
request<{ ok: boolean }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/winner`,
{ method: 'PATCH', body: JSON.stringify(body) },
),
getDiff: (battleId: string, contestantId: string) =>
request<{ diff: string }>(
`/api/coder/battles/${encodeURIComponent(battleId)}/contestants/${encodeURIComponent(contestantId)}/diff`,
),
},
skills: {
list: () => request<{ skills: Skill[] }>('/api/skills'),
},

View File

@@ -391,7 +391,8 @@ export type WorkspacePaneKind =
| 'settings'
| 'markdown_artifact'
| 'html_artifact'
| 'orchestrator';
| 'orchestrator'
| 'arena';
// Mixed tabs: a pane can hold tabs of different kinds (a BooChat tab next to a
// BooCode tab next to a Terminal tab). Each tab carries its own kind; the active
@@ -424,6 +425,10 @@ export interface OrchestratorState {
band: 'small' | 'medium' | 'large';
}
// Arena pane state — single-sourced in @boocode/contracts; edit the package, not here.
import type { ArenaState, BattleShape, ContestantShape, CrossExaminationShape, BattleType, BattleStatus, ContestantStatus, ContestantLane } from '@boocode/contracts/arena';
export type { ArenaState, BattleShape, ContestantShape, CrossExaminationShape, BattleType, BattleStatus, ContestantStatus, ContestantLane };
// Orchestrator run API types (returned by GET /api/coder/runs/:id).
export interface FlowRunRow {
id: string;
@@ -475,6 +480,8 @@ export interface WorkspacePane {
html_artifact_state?: HtmlArtifactState;
// orchestrator pane: populated only when kind === 'orchestrator'.
orchestrator_state?: OrchestratorState;
// arena pane: populated only when kind === 'arena'.
arena_state?: ArenaState;
}
// Reopen LIFO stack entry. Shape unchanged from the prior module-level stack;
@@ -592,4 +599,31 @@ export type WsFrame =
status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'cancelled';
run_status?: 'running' | 'completed' | 'failed' | 'cancelled';
report?: string;
}
// arena frames: battle lifecycle + per-contestant streaming
| {
type: 'battle_started';
battle_id: string;
battle_type: 'coding' | 'qa';
prompt: string;
contestants: Array<{ id: string; identity: string; model: string; lane: 'local' | 'cloud' }>;
}
| {
type: 'contestant_updated';
battle_id: string;
contestant_id: string;
status?: 'queued' | 'running' | 'done' | 'error';
duration_ms?: number;
tokens_per_sec?: number;
battle_status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
delta?: string;
error?: string;
}
| {
type: 'battle_updated';
battle_id: string;
status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
winner_contestant_id?: string | null;
analysis_ready?: boolean;
cross_exam_id?: string;
};