Skip to content

Commit 41c5ff6

Browse files
feat(web-evals): remember last Roo model selection + add evals skill (#10470)
* feat(web-evals): remember last Roo model selection * fix(web-evals): reset model selections on provider switch and fix lint warning - Add useEffect to reset model selections when switching between providers This prevents OpenRouter model IDs from persisting when switching to Roo, which was causing Roo's stored selection to be overwritten with wrong IDs - Remove unused 'executionMethod' from onSubmit dependency array to fix react-hooks/exhaustive-deps warning * fix(web-evals): add missing executionMethod to test cases * fix(web-evals): harden localStorage + keep provider selections
1 parent 2d22804 commit 41c5ff6

6 files changed

Lines changed: 514 additions & 5 deletions

File tree

.roo/skills/evals-context/SKILL.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
---
2+
name: evals-context
3+
description: Provides context about the Roo Code evals system structure in this monorepo. Use when tasks mention "evals", "evaluation", "eval runs", "eval exercises", or working with the evals infrastructure. Helps distinguish between the evals execution system (packages/evals, apps/web-evals) and the public website evals display page (apps/web-roo-code/src/app/evals).
4+
---
5+
6+
# Evals Codebase Context
7+
8+
## When to Use This Skill
9+
10+
Use this skill when the task involves:
11+
12+
- Modifying or debugging the evals execution infrastructure
13+
- Adding new eval exercises or languages
14+
- Working with the evals web interface (apps/web-evals)
15+
- Modifying the public evals display page on roocode.com
16+
- Understanding where evals code lives in this monorepo
17+
18+
## When NOT to Use This Skill
19+
20+
Do NOT use this skill when:
21+
22+
- Working on unrelated parts of the codebase (extension, webview-ui, etc.)
23+
- The task is purely about the VS Code extension's core functionality
24+
- Working on the main website pages that don't involve evals
25+
26+
## Key Disambiguation: Two "Evals" Locations
27+
28+
This monorepo has **two distinct evals-related locations** that can cause confusion:
29+
30+
| Component | Path | Purpose |
31+
| --------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- |
32+
| **Evals Execution System** | `packages/evals/` | Core eval infrastructure: CLI, DB schema, Docker configs |
33+
| **Evals Management UI** | `apps/web-evals/` | Next.js app for creating/monitoring eval runs (localhost:3446) |
34+
| **Website Evals Page** | `apps/web-roo-code/src/app/evals/` | Public roocode.com page displaying eval results |
35+
| **External Exercises Repo** | [Roo-Code-Evals](https://github.com/RooCodeInc/Roo-Code-Evals) | Actual coding exercises (NOT in this monorepo) |
36+
37+
## Directory Structure Reference
38+
39+
### `packages/evals/` - Core Evals Package
40+
41+
```
42+
packages/evals/
43+
├── ARCHITECTURE.md # Detailed architecture documentation
44+
├── ADDING-EVALS.md # Guide for adding new exercises/languages
45+
├── README.md # Setup and running instructions
46+
├── docker-compose.yml # Container orchestration
47+
├── Dockerfile.runner # Runner container definition
48+
├── Dockerfile.web # Web app container
49+
├── drizzle.config.ts # Database ORM config
50+
├── src/
51+
│ ├── index.ts # Package exports
52+
│ ├── cli/ # CLI commands for running evals
53+
│ │ ├── runEvals.ts # Orchestrates complete eval runs
54+
│ │ ├── runTask.ts # Executes individual tasks in containers
55+
│ │ ├── runUnitTest.ts # Validates task completion via tests
56+
│ │ └── redis.ts # Redis pub/sub integration
57+
│ ├── db/
58+
│ │ ├── schema.ts # Database schema (runs, tasks)
59+
│ │ ├── queries/ # Database query functions
60+
│ │ └── migrations/ # SQL migrations
61+
│ └── exercises/
62+
│ └── index.ts # Exercise loading utilities
63+
└── scripts/
64+
└── setup.sh # Local macOS setup script
65+
```
66+
67+
### `apps/web-evals/` - Evals Management Web App
68+
69+
```
70+
apps/web-evals/
71+
├── src/
72+
│ ├── app/
73+
│ │ ├── page.tsx # Home page (runs list)
74+
│ │ ├── runs/
75+
│ │ │ ├── new/ # Create new eval run
76+
│ │ │ └── [id]/ # View specific run status
77+
│ │ └── api/runs/ # SSE streaming endpoint
78+
│ ├── actions/ # Server actions
79+
│ │ ├── runs.ts # Run CRUD operations
80+
│ │ ├── tasks.ts # Task queries
81+
│ │ ├── exercises.ts # Exercise listing
82+
│ │ └── heartbeat.ts # Controller health checks
83+
│ ├── hooks/ # React hooks (SSE, models, etc.)
84+
│ └── lib/ # Utilities and schemas
85+
```
86+
87+
### `apps/web-roo-code/src/app/evals/` - Public Website Evals Page
88+
89+
```
90+
apps/web-roo-code/src/app/evals/
91+
├── page.tsx # Fetches and displays public eval results
92+
├── evals.tsx # Main evals display component
93+
├── plot.tsx # Visualization component
94+
└── types.ts # EvalRun type (extends packages/evals types)
95+
```
96+
97+
This page **displays** eval results on the public roocode.com website. It imports types from `@roo-code/evals` but does NOT run evals.
98+
99+
## Architecture Overview
100+
101+
The evals system is a distributed evaluation platform that runs AI coding tasks in isolated VS Code environments:
102+
103+
```
104+
┌─────────────────────────────────────────────────────────────┐
105+
│ Web App (apps/web-evals) ──────────────────────────────── │
106+
│ │ │
107+
│ ▼ │
108+
│ PostgreSQL ◄────► Controller Container │
109+
│ │ │ │
110+
│ ▼ ▼ │
111+
│ Redis ◄───► Runner Containers (1-25 parallel) │
112+
└─────────────────────────────────────────────────────────────┘
113+
```
114+
115+
**Key components:**
116+
117+
- **Controller**: Orchestrates eval runs, spawns runners, manages task queue (p-queue)
118+
- **Runner**: Isolated Docker container with VS Code + Roo Code extension + language runtimes
119+
- **Redis**: Pub/sub for real-time events (NOT task queuing)
120+
- **PostgreSQL**: Stores runs, tasks, metrics
121+
122+
## Common Tasks Quick Reference
123+
124+
### Adding a New Eval Exercise
125+
126+
1. Add exercise to [Roo-Code-Evals](https://github.com/RooCodeInc/Roo-Code-Evals) repo (external)
127+
2. See [`packages/evals/ADDING-EVALS.md`](packages/evals/ADDING-EVALS.md) for structure
128+
129+
### Modifying Eval CLI Behavior
130+
131+
Edit files in [`packages/evals/src/cli/`](packages/evals/src/cli/):
132+
133+
- [`runEvals.ts`](packages/evals/src/cli/runEvals.ts) - Run orchestration
134+
- [`runTask.ts`](packages/evals/src/cli/runTask.ts) - Task execution
135+
- [`runUnitTest.ts`](packages/evals/src/cli/runUnitTest.ts) - Test validation
136+
137+
### Modifying the Evals Web Interface
138+
139+
Edit files in [`apps/web-evals/src/`](apps/web-evals/src/):
140+
141+
- [`app/runs/new/new-run.tsx`](apps/web-evals/src/app/runs/new/new-run.tsx) - New run form
142+
- [`actions/runs.ts`](apps/web-evals/src/actions/runs.ts) - Run server actions
143+
144+
### Modifying the Public Evals Display Page
145+
146+
Edit files in [`apps/web-roo-code/src/app/evals/`](apps/web-roo-code/src/app/evals/):
147+
148+
- [`evals.tsx`](apps/web-roo-code/src/app/evals/evals.tsx) - Display component
149+
- [`plot.tsx`](apps/web-roo-code/src/app/evals/plot.tsx) - Charts
150+
151+
### Database Schema Changes
152+
153+
1. Edit [`packages/evals/src/db/schema.ts`](packages/evals/src/db/schema.ts)
154+
2. Generate migration: `cd packages/evals && pnpm drizzle-kit generate`
155+
3. Apply migration: `pnpm drizzle-kit migrate`
156+
157+
## Running Evals Locally
158+
159+
```bash
160+
# From repo root
161+
pnpm evals
162+
163+
# Opens web UI at http://localhost:3446
164+
```
165+
166+
**Ports (defaults):**
167+
168+
- PostgreSQL: 5433
169+
- Redis: 6380
170+
- Web: 3446
171+
172+
## Testing
173+
174+
```bash
175+
# packages/evals tests
176+
cd packages/evals && npx vitest run
177+
178+
# apps/web-evals tests
179+
cd apps/web-evals && npx vitest run
180+
```
181+
182+
## Key Types/Exports from `@roo-code/evals`
183+
184+
The package exports are defined in [`packages/evals/src/index.ts`](packages/evals/src/index.ts):
185+
186+
- Database queries: `getRuns`, `getTasks`, `getTaskMetrics`, etc.
187+
- Schema types: `Run`, `Task`, `TaskMetrics`
188+
- Used by both `apps/web-evals` and `apps/web-roo-code`

apps/web-evals/src/app/runs/new/new-run.tsx

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useCallback, useEffect, useMemo, useState } from "react"
3+
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
44
import { useRouter } from "next/navigation"
55
import { z } from "zod"
66
import { useQuery } from "@tanstack/react-query"
@@ -48,6 +48,9 @@ import {
4848
} from "@/lib/schemas"
4949
import { cn } from "@/lib/utils"
5050

51+
import { loadRooLastModelSelection, saveRooLastModelSelection } from "@/lib/roo-last-model-selection"
52+
import { normalizeCreateRunForSubmit } from "@/lib/normalize-create-run"
53+
5154
import { useOpenRouterModels } from "@/hooks/use-open-router-models"
5255
import { useRooCodeCloudModels } from "@/hooks/use-roo-code-cloud-models"
5356

@@ -103,6 +106,8 @@ type ConfigSelection = {
103106

104107
export function NewRun() {
105108
const router = useRouter()
109+
const modelSelectionsByProviderRef = useRef<Record<string, ModelSelection[]>>({})
110+
const modelValueByProviderRef = useRef<Record<string, string>>({})
106111

107112
const [provider, setModelSource] = useState<"roo" | "openrouter" | "other">("other")
108113
const [executionMethod, setExecutionMethod] = useState<ExecutionMethod>("vscode")
@@ -147,14 +152,43 @@ export function NewRun() {
147152
})
148153

149154
const {
155+
register,
150156
setValue,
151157
clearErrors,
152158
watch,
159+
getValues,
153160
formState: { isSubmitting },
154161
} = form
155162

156163
const [suite, settings] = watch(["suite", "settings", "concurrency"])
157164

165+
const selectedModelIds = useMemo(
166+
() => modelSelections.map((s) => s.model).filter((m) => m.length > 0),
167+
[modelSelections],
168+
)
169+
170+
const applyModelIds = useCallback(
171+
(modelIds: string[]) => {
172+
const unique = Array.from(new Set(modelIds.map((m) => m.trim()).filter((m) => m.length > 0)))
173+
174+
if (unique.length === 0) {
175+
setModelSelections([{ id: crypto.randomUUID(), model: "", popoverOpen: false }])
176+
setValue("model", "")
177+
return
178+
}
179+
180+
setModelSelections(unique.map((model) => ({ id: crypto.randomUUID(), model, popoverOpen: false })))
181+
setValue("model", unique[0] ?? "")
182+
},
183+
[setValue],
184+
)
185+
186+
// Ensure the `exercises` field is registered so RHF always includes it in submit values.
187+
useEffect(() => {
188+
register("exercises")
189+
}, [register])
190+
191+
// Load settings from localStorage on mount
158192
useEffect(() => {
159193
const savedConcurrency = localStorage.getItem("evals-concurrency")
160194

@@ -215,6 +249,51 @@ export function NewRun() {
215249
}
216250
}, [setValue])
217251

252+
// Track previous provider to detect switches
253+
const [prevProvider, setPrevProvider] = useState(provider)
254+
255+
// Preserve selections per provider; avoids cross-contamination while keeping UX stable.
256+
useEffect(() => {
257+
if (provider === prevProvider) return
258+
259+
modelSelectionsByProviderRef.current[prevProvider] = modelSelections
260+
modelValueByProviderRef.current[prevProvider] = getValues("model")
261+
262+
const nextModelSelections =
263+
modelSelectionsByProviderRef.current[provider] ??
264+
([{ id: crypto.randomUUID(), model: "", popoverOpen: false }] satisfies ModelSelection[])
265+
266+
setModelSelections(nextModelSelections)
267+
268+
const nextModelValue =
269+
modelValueByProviderRef.current[provider] ??
270+
nextModelSelections.find((s) => s.model.trim().length > 0)?.model ??
271+
(provider === "other" && importedSettings && configSelections[0]?.configName
272+
? (getModelId(importedSettings.apiConfigs[configSelections[0].configName] ?? {}) ?? "")
273+
: "")
274+
275+
setValue("model", nextModelValue)
276+
setPrevProvider(provider)
277+
}, [provider, prevProvider, modelSelections, setValue, getValues, importedSettings, configSelections])
278+
279+
// When switching to Roo provider, restore last-used selection if current selection is empty
280+
useEffect(() => {
281+
if (provider !== "roo") return
282+
if (selectedModelIds.length > 0) return
283+
284+
const last = loadRooLastModelSelection()
285+
if (last.length > 0) {
286+
applyModelIds(last)
287+
}
288+
}, [applyModelIds, provider, selectedModelIds.length])
289+
290+
// Persist last-used Roo provider model selection
291+
useEffect(() => {
292+
if (provider !== "roo") return
293+
saveRooLastModelSelection(selectedModelIds)
294+
}, [provider, selectedModelIds])
295+
296+
// Extract unique languages from exercises
218297
const languages = useMemo(() => {
219298
if (!exercises.data) {
220299
return []
@@ -337,7 +416,10 @@ export function NewRun() {
337416
const onSubmit = useCallback(
338417
async (values: CreateRun) => {
339418
try {
340-
if (provider === "roo" && !values.jobToken?.trim()) {
419+
const baseValues = normalizeCreateRunForSubmit(values, selectedExercises, suite)
420+
421+
// Validate jobToken for Roo Code Cloud provider
422+
if (provider === "roo" && !baseValues.jobToken?.trim()) {
341423
toast.error("Roo Code Cloud Token is required")
342424
return
343425
}
@@ -374,8 +456,7 @@ export function NewRun() {
374456
await new Promise((resolve) => setTimeout(resolve, 20_000))
375457
}
376458

377-
const runValues = { ...values }
378-
runValues.executionMethod = executionMethod
459+
const runValues = { ...baseValues }
379460

380461
if (provider === "openrouter") {
381462
runValues.model = selection.model
@@ -424,8 +505,9 @@ export function NewRun() {
424505
}
425506
},
426507
[
508+
suite,
509+
selectedExercises,
427510
provider,
428-
executionMethod,
429511
modelSelections,
430512
configSelections,
431513
importedSettings,

0 commit comments

Comments
 (0)