Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Swarm routing: rank choices by measured cost per shipped change and first-review pass rate (Goals piece 3) (#2423)

0xken15841e5d03cb39
diff --git a/backend/src/superTabs/costs/read.test.ts b/backend/src/superTabs/costs/read.test.ts
index d2066048d..da391da00 100644
--- a/backend/src/superTabs/costs/read.test.ts
+++ b/backend/src/superTabs/costs/read.test.ts
@@ -25,10 +25,12 @@ describe('the cost summary', () => {
expect(summary.rows).toEqual([
{ engine: 'claude', model: 'opus', effort: 'high', kind: 'parser', attempts: 3, firstReviews: 2, firstReviewPassed: 1, firstReviewPassRate: 0.5,
shipped: 2, outcomes: { done: 2, lost: 1 }, billing: { subscription: 2, api: 1 }, medianMinutesToShip: 30,
- tokens: { input: 2.5e6, output: 0, cacheRead: 0, cacheWrite: 0 }, tokensKnown: 3, apiCost: 10, spend: 4, costKnown: 3, costPerShipped: 5, stepUps: 0 },
+ tokens: { input: 2.5e6, output: 0, cacheRead: 0, cacheWrite: 0 }, tokensKnown: 3, apiCost: 10, spend: 4, costKnown: 3, costPerShipped: 5, stepUps: 0,
+ reviewAttempts: 0, fullCostKnown: 1, fullCostPerShipped: 5 },
{ engine: 'claude', model: 'opus', effort: 'xhigh', kind: 'unspecified', attempts: 1, firstReviews: 0, firstReviewPassed: 0, firstReviewPassRate: null,
shipped: 1, outcomes: { done: 1 }, billing: { subscription: 1 }, medianMinutesToShip: 30,
- tokens: { input: 1e6, output: 0, cacheRead: 0, cacheWrite: 0 }, tokensKnown: 1, apiCost: 4, spend: 0, costKnown: 1, costPerShipped: 4, stepUps: 0 },
+ tokens: { input: 1e6, output: 0, cacheRead: 0, cacheWrite: 0 }, tokensKnown: 1, apiCost: 4, spend: 0, costKnown: 1, costPerShipped: 4, stepUps: 0,
+ reviewAttempts: 0, fullCostKnown: 1, fullCostPerShipped: 4 },
])
expect(summary.totals).toMatchObject({ attempts: 4, shipped: 3, apiCost: 14, spend: 4, costPerShipped: 14 / 3 })
})
@@ -80,3 +82,67 @@ describe('the cost summary', () => {
expect(summarizeCosts([row('a1')], []).prices).toEqual([{ model: 'claude-opus-5-5', source: 'https://platform.claude.com/docs/en/about-claude/pricing', checked: '2026-10-29' }])
})
})
+
+describe('the full cost per shipped change (routing, Goals piece 3)', () => {
+ const reviewRun = (startedAt: number) => run({ engine: 'codex', model: 'gpt-6.1-sol', effort: 'high', startedAt, endedAt: startedAt + 5 * MINUTE,
+ end: { 'gpt-6.1-sol': t(1e5, 0) } })
+ const reviewGroup = (id: string, of: string) => ({ ...group(id, []), reviewOf: of }) as Conversation
+
+ it('counts every attempt of the choice and every review of its work, so a choice that needs rework rounds costs more per shipped change', () => {
+ // Two builds that ship; g1's work took three review rounds (a first review failed twice), g2's one.
+ const rows = [
+ row('b1', { conversationId: 'g1' }), row('b2', { conversationId: 'g2' }),
+ row('r1', { conversationId: 'v1', kind: 'review', run: reviewRun(10 * MINUTE) }),
+ row('r2', { conversationId: 'v1', kind: 'review', run: reviewRun(40 * MINUTE) }),
+ row('r3', { conversationId: 'v1', kind: 'review', run: reviewRun(70 * MINUTE) }),
+ row('r4', { conversationId: 'v2', kind: 'review', run: reviewRun(10 * MINUTE) }),
+ ]
+ const summary = summarizeCosts(rows, [group('g1', [{ assignmentId: 'b1', firstReview: false }], 90 * MINUTE),
+ group('g2', [{ assignmentId: 'b2', firstReview: true }], 30 * MINUTE), reviewGroup('v1', 'g1'), reviewGroup('v2', 'g2')])
+ const build = summary.rows.find(r => r.kind === 'parser')!
+ const review = summary.rows.find(r => r.kind === 'review')!
+ const perReview = review.apiCost! / 4
+ expect(build).toMatchObject({ costPerShipped: 4, reviewAttempts: 4, fullCostKnown: 1 })
+ // Its own two attempts ($8) and the four reviews of its work, over two shipped changes.
+ expect(build.fullCostPerShipped).toBeCloseTo((8 + 4 * perReview) / 2, 10)
+ // A review's own row counts no reviews of reviews.
+ expect(review).toMatchObject({ reviewAttempts: 0 })
+ })
+
+ it('charges a review to the build attempt that ran when it started, also a failed attempt of another choice', () => {
+ // Sonnet's attempt was reviewed and lost; Opus took over and shipped. The first review is Sonnet's cost, not Opus's.
+ const rows = [
+ row('s1', { conversationId: 'g1', outcome: 'lost', run: run({ model: 'sonnet', effort: 'medium', startedAt: 0 }) }),
+ row('o1', { conversationId: 'g1', run: run({ startedAt: 30 * MINUTE }) }),
+ row('r1', { conversationId: 'v1', kind: 'review', run: reviewRun(20 * MINUTE) }),
+ row('r2', { conversationId: 'v1', kind: 'review', run: reviewRun(50 * MINUTE) }),
+ ]
+ const summary = summarizeCosts(rows, [group('g1', [], 60 * MINUTE), reviewGroup('v1', 'g1')])
+ expect(summary.rows.find(r => r.model === 'sonnet')).toMatchObject({ reviewAttempts: 1, shipped: 0, fullCostPerShipped: null })
+ expect(summary.rows.find(r => r.model === 'opus')).toMatchObject({ reviewAttempts: 1, shipped: 1 })
+ })
+
+ it('names no group, title, person or id: only choices, kinds and numbers', () => {
+ const rows = [row('b1', { conversationId: 'g-secret' }), row('r1', { conversationId: 'v-secret', kind: 'review', run: reviewRun(10 * MINUTE) })]
+ const groups = [{ ...group('g-secret', [{ assignmentId: 'b1', firstReview: true }], 30 * MINUTE), title: 'Ana private plan', leadId: 'agent-ana' },
+ { ...reviewGroup('v-secret', 'g-secret'), title: 'Review: Ana private plan' }] as Conversation[]
+ const text = JSON.stringify(summarizeCosts(rows, groups))
+ for (const leak of ['secret', 'Ana', 'plan', 'agent-ana', 'b1', 'r1', '"m"', '"h"']) expect(text).not.toContain(leak)
+ })
+
+ it('fills an unknown attempt cost with the mean of known ones on the same choice, and gives no figure when under half are known', () => {
+ const known = [row('a1', { conversationId: 'g1' }), row('a2', { conversationId: 'g2' }), row('a3', { conversationId: 'g3', run: run({ start: null }) })]
+ const half = summarizeCosts(known, [group('g1', [], 30 * MINUTE), group('g2', [], 30 * MINUTE), group('g3', [], 30 * MINUTE)])
+ // Two of three known at $4 each: the third counts $4 too; strict cost per shipped stays null, as before.
+ expect(half.rows[0]).toMatchObject({ costPerShipped: null, fullCostKnown: 2 / 3, fullCostPerShipped: 4 })
+ const few = summarizeCosts([row('b1'), row('b2', { run: run({ start: null }) }), row('b3', { run: run({ start: null }) })], [group('g1', [], 30 * MINUTE)])
+ expect(few.rows[0]).toMatchObject({ fullCostKnown: 1 / 3, fullCostPerShipped: null })
+ // Open attempts are still going: they are neither known nor unknown yet.
+ const open = summarizeCosts([row('c1'), row('c2', { outcome: null, run: run({ endedAt: undefined, end: undefined }) })], [group('g1', [], 30 * MINUTE)])
+ expect(open.rows[0]).toMatchObject({ fullCostKnown: 1, fullCostPerShipped: 4 })
+ // An open attempt that already shipped (merged mid-attempt) counts, its cost filled like an unknown one (review of #2423).
+ const shippedOpen = summarizeCosts([row('k1', { run: run({ startedAt: 0 }) }), row('o1', { outcome: null, run: run({ startedAt: 10 * MINUTE, endedAt: undefined, end: undefined }) })],
+ [group('g1', [], 20 * MINUTE)])
+ expect(shippedOpen.rows[0]).toMatchObject({ shipped: 1, fullCostKnown: 0.5, fullCostPerShipped: 8 })
+ })
+})
diff --git a/backend/src/superTabs/costs/read.ts b/backend/src/superTabs/costs/read.ts
index bcc04f42f..d0bf0d8ce 100644
--- a/backend/src/superTabs/costs/read.ts
+++ b/backend/src/superTabs/costs/read.ts
@@ -82,8 +82,23 @@ export interface CostSummaryRow {
stepUps: number
}
+/** What a choice's shipped change cost in full, for routing (Goals piece 3): every ended attempt of the choice, failed and lost
+ * ones too, and every review of its work, rework rounds included (fullCosts). Without the reviews a choice that needs three
+ * review rounds read as cheap as one that passes the first (Lead, 2026-10-31). */
+export interface FullCost {
+ /** Review attempts charged to this choice's attempts, open ones too. */
+ reviewAttempts: number
+ /** Of the ended attempts counted (its own and the reviews), the share whose cost is known; null with none ended. */
+ fullCostKnown: number | null
+ /** Their API-equivalent cost over shipped, an unknown attempt counted at the mean of known ones on its own choice; null
+ * with nothing shipped, under half the costs known, or an unknown cost on a choice with none known. */
+ fullCostPerShipped: number | null
+}
+/** Under this share of known costs the mean that fills the rest says too little. */
+export const MIN_KNOWN_SHARE = 0.5
+
export interface CostSummary {
- rows: CostSummaryRow[]
+ rows: Array<CostSummaryRow & FullCost>
/** The same per model alone (a grid model by its own name), across efforts and kinds: what a model's first-review pass
* rate and cost per shipped change are, week over week (Ken, 2026-10-29). */
models: Array<Omit<CostSummaryRow, 'effort' | 'kind'>>
@@ -148,6 +163,45 @@ function summarize(rows: CostRow[], firstReview: Map<string, boolean>, shippedAt
costPerShipped: costKnown && shipped && !endedUnknown ? apiCost / shipped : null, stepUps }
}
+/** Each review attempt by the build attempt whose work it reviewed: in the group its group reviews (reviewOf), the latest
+ * attempt started by the review's start, else that group's first, as shipping() picks the shipping attempt. A review of
+ * a group the reader cannot read is charged to nobody. */
+function reviewsByBuild(rows: CostRow[], groups: Conversation[]): Map<string, CostRow[]> {
+ const reviewed = new Map(groups.filter(g => g.reviewOf).map(g => [g.id, g.reviewOf!]))
+ const byGroup = new Map<string, CostRow[]>()
+ for (const row of rows) byGroup.set(row.conversationId, [...byGroup.get(row.conversationId) ?? [], row])
+ const charged = new Map<string, CostRow[]>()
+ for (const review of rows) {
+ const of = reviewed.get(review.conversationId)
+ const builds = of ? [...byGroup.get(of) ?? []].sort((a, b) => a.run.startedAt - b.run.startedAt) : []
+ if (!builds.length) continue
+ const build = builds.filter(b => b.run.startedAt <= review.run.startedAt).at(-1) ?? builds[0]!
+ charged.set(build.assignmentId, [...charged.get(build.assignmentId) ?? [], review])
+ }
+ return charged
+}
+
+/** [group]'s full cost (FullCost): its own ended attempts and the reviews charged to them, an unknown cost filled with the
+ * mean known cost of its own choice ([means], by [keyOf]). */
+function fullCost(group: CostRow[], shipped: number, shippedAt: Map<string, number>, reviews: Map<string, CostRow[]>, means: Map<string, number>,
+ keyOf: (row: CostRow) => string): FullCost {
+ const charged = group.flatMap(row => reviews.get(row.assignmentId) ?? [])
+ // Open attempts are still going: their cost is neither known nor unknown yet. One that already shipped (merged mid-attempt)
+ // counts, filled like an unknown cost, or its ship would come free (review of #2423).
+ const ended = [...group, ...charged].filter(row => row.outcome !== null || shippedAt.has(row.assignmentId))
+ let total = 0, known = 0, unfilled = false
+ for (const row of ended) {
+ const cost = attemptCost(row.run, row.fresh).apiCost
+ if (cost !== null) { known++; total += cost; continue }
+ const mean = means.get(keyOf(row))
+ if (mean === undefined) unfilled = true
+ else total += mean
+ }
+ const share = ended.length ? known / ended.length : null
+ return { reviewAttempts: charged.length, fullCostKnown: share,
+ fullCostPerShipped: shipped && share !== null && share >= MIN_KNOWN_SHARE && !unfilled ? total / shipped : null }
+}
+
/** The summary of these attempts; `groups` are the groups they belong to, for their ledgers' first reviews. */
export function summarizeCosts(rows: CostRow[], groups: Conversation[]): CostSummary {
const firstReview = new Map<string, boolean>()
@@ -160,7 +214,19 @@ export function summarizeCosts(rows: CostRow[], groups: Conversation[]): CostSum
return [...byKey.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, group]) => [key(group[0]!), group] as const)
}
const prices = new Set<string>(), shippedAt = shipping(rows, groups)
- const summary = grouped(keyOf).map(([[engine, model, effort, kind], group]) => ({ engine, model, effort, kind, ...summarize(group, firstReview, shippedAt, prices) }))
+ const reviews = reviewsByBuild(rows, groups), key = (row: CostRow) => JSON.stringify(keyOf(row))
+ const sums = new Map<string, { cost: number; n: number }>()
+ for (const row of rows) {
+ const cost = attemptCost(row.run, row.fresh).apiCost
+ if (cost === null) continue
+ const sum = sums.get(key(row)) ?? { cost: 0, n: 0 }
+ sums.set(key(row), { cost: sum.cost + cost, n: sum.n + 1 })
+ }
+ const means = new Map([...sums].map(([k, s]) => [k, s.cost / s.n]))
+ const summary = grouped(keyOf).map(([[engine, model, effort, kind], group]) => {
+ const summed = summarize(group, firstReview, shippedAt, prices)
+ return { engine, model, effort, kind, ...summed, ...fullCost(group, summed.shipped, shippedAt, reviews, means, key) }
+ })
const models = grouped(row => [row.run.engine, row.run.grid ?? row.run.model] as const)
.map(([[engine, model], group]) => ({ engine, model, ...summarize(group, firstReview, shippedAt, new Set()) }))
return { rows: summary, models, totals: summarize(rows, firstReview, shippedAt, new Set()),
diff --git a/cli/src/superTabs/routeCommand.spec.ts b/cli/src/superTabs/routeCommand.spec.ts
index aabbfc353..8cbece16d 100644
--- a/cli/src/superTabs/routeCommand.spec.ts
+++ b/cli/src/superTabs/routeCommand.spec.ts
@@ -1721,3 +1721,31 @@ describe('routing by facts', () => {
expect(old.next).not.toContain('roleName')
})
})
+
+/** Piece 3 through the route itself, with the makers it ships with (routePlugins.ts ROUTE_PLUGIN_MAKERS). */
+describe('routing by measured cost and results', () => {
+ const row = (model: string, effort: string, fullCostPerShipped: number) => ({ engine: 'claude', model, effort, kind: 'build', firstReviews: 10,
+ firstReviewPassed: 8, shipped: 6, costPerShipped: 1, fullCostPerShipped, fullCostKnown: 1 })
+ const built = { ...input, assessment: { ...input.assessment, kind: 'build' } }
+ const withCosts = (base: ReturnType<typeof scoped>, answer: (payload: Record<string, unknown>) => Promise<Answer>) =>
+ vi.fn(async (payload: Record<string, any>) => payload.action === 'costs' ? answer(payload) : base(payload))
+
+ it('reads the last 7 days\' results and ranks the choice that costs less per shipped change first, with its numbers', async () => {
+ const base = scoped()
+ // Sonnet ranks first today (cost 2 against Opus's 3); measured in full, Opus costs $3 per shipped change and Sonnet $9.
+ const plain = await routeTask(input, scoped(), where as never, opener(), () => 'op')
+ expect(plain).toMatchObject({ pick: { model: 'sonnet' } })
+ const s = withCosts(base, async () => ({ ok: true, value: { truncated: false, rows: [row('opus', 'high', 3), row('sonnet', 'medium', 9)] } }))
+ const result = await routeTask(built, s, where as never, opener(), () => 'op')
+ expect(s.mock.calls.filter(c => c[0].action === 'costs').map(c => c[0])).toEqual([{ action: 'costs', days: 7 }])
+ expect(result).toMatchObject({ ok: true, pick: { model: 'opus', notes: expect.arrayContaining([expect.stringMatching(/^measured results: build work, last 7 days: 8 of 10 first reviews passed, \$3\.00 per shipped change over 6/)]) } })
+ expect(labels(base)[0]).toContain('measured results: build work')
+ })
+
+ it('a failed read leaves today\'s ranking and says so', async () => {
+ const s = withCosts(scoped(), async () => ({ error: 'FORBIDDEN' }))
+ const result = await routeTask(built, s, where as never, opener(), () => 'op')
+ expect(result).toMatchObject({ ok: true, pick: { model: 'sonnet' },
+ warnings: expect.arrayContaining(['The routing plug-in "measured results" was skipped: its maker failed. The route is ranked without it.']) })
+ })
+})
diff --git a/cli/src/superTabs/routeMeasured.spec.ts b/cli/src/superTabs/routeMeasured.spec.ts
new file mode 100644
index 000000000..6cea80825
--- /dev/null
+++ b/cli/src/superTabs/routeMeasured.spec.ts
@@ -0,0 +1,210 @@
+// cli/src/superTabs/routeMeasured.spec.ts
+import { describe, expect, it } from 'vitest'
+import { choose, type Assessment, type Catalog, type Probe } from './route.js'
+import { MEASURED, MEASURED_MAKER, measuredFrom, measuredPlugin, readMeasured, type MeasuredRow } from './routeMeasured.js'
+import { ROUTE_PLUGIN_MAKERS, type PluginInput } from './routePlugins.js'
+
+/** Today's strong rows (backend superTabs/catalog.ts): at equal strength Codex's cost 2 ranks before Opus's 3. */
+const catalog: Catalog = { grid: { strength: 1, models: [{ model: 'kimi k3', strength: 2 }] }, models: [
+ { engine: 'claude', model: 'opus', effort: 'high', strength: 3, cost: 3, offered: true },
+ { engine: 'claude', model: 'opus', effort: 'xhigh', strength: 3, cost: 4, offered: true },
+ { engine: 'codex', model: 'gpt-6.1-sol', effort: 'high', strength: 3, cost: 2, offered: true },
+ { engine: 'claude', model: 'sonnet', effort: 'medium', strength: 2, cost: 2, offered: true },
+] }
+const NOW = 1_000_000_000
+const task = (patch: Partial<Assessment> = {}): Assessment => ({ difficulty: 'medium', risk: 'low', size: 'small', why: 'Parser fix.', kind: 'build',
+ needs: { tools: [], devices: [] }, ...patch })
+const probe = (patch: Partial<Probe> = {}): Probe => ({ kind: 'new', machineId: 'm1', machineName: 'mac-1', engine: 'claude', model: 'opus', effort: 'high',
+ quality: 3, cost: 3, quota: { known: true, leftPercent: null, resetsAt: null, metered: true }, activity: 'new', known: true, refusals: [], notes: [], ...patch })
+const opus = probe(), codex = probe({ machineId: 'm2', machineName: 'mac-2', engine: 'codex', model: 'gpt-6.1-sol', effort: 'high', cost: 2 })
+const row = (patch: Partial<MeasuredRow>): MeasuredRow => ({ engine: 'claude', model: 'opus', effort: 'high', kind: 'build', firstReviews: 10, firstReviewPassed: 9,
+ shipped: 10, costPerShipped: 5, fullCostPerShipped: 6, fullCostKnown: 1, ...patch })
+/** Opus passes 9 of 10 first reviews; Codex 6 of 10. Codex's own attempts are cheaper per shipped change ($3 against $5), but
+ * its failed reviews take rework rounds and their reviews: in full it costs $9 against Opus's $6. */
+const measured = [row({}), row({ engine: 'codex', model: 'gpt-6.1-sol', firstReviewPassed: 6, costPerShipped: 3, fullCostPerShipped: 9 })]
+const route = (rows: MeasuredRow[], probes: Probe[] = [opus, codex], a: Assessment = task(), truncated = false) => {
+ const choice = choose(probes, catalog, a, NOW, [], [], [], [measuredPlugin({ rows, truncated })])
+ if ('error' in choice) throw new Error('no candidate')
+ return choice
+}
+const order = (choice: ReturnType<typeof route>) => choice.shown.map(s => `${s.engine} ${s.model}`)
+const mine = (s: { notes: string[] }) => s.notes.filter(n => n.startsWith(`${MEASURED}: `))
+
+describe('routing by measured cost and results (Goals piece 3)', () => {
+ it('today, without measures, Codex ranks first by its lower catalog cost', () => {
+ expect(order(route([]))).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ })
+
+ it('the choice that costs less per shipped change in full wins, rework rounds and their reviews counted', () => {
+ // 9 of 10 against 6 of 10: their 95% ranges overlap, so cost decides; counted in full, Opus is cheaper.
+ const choice = route(measured)
+ expect(order(choice)).toEqual(['claude opus', 'codex gpt-6.1-sol'])
+ expect(choice.adjusted).toBe(true)
+ expect(mine(choice.shown[0]!)).toEqual([`${MEASURED}: build work, last 7 days: 9 of 10 first reviews passed, $6.00 per shipped change over 10 (failed attempts and every review round included); ranked as cost 2.0 instead of 3`])
+ expect(mine(choice.shown[1]!)).toEqual([`${MEASURED}: build work, last 7 days: 6 of 10 first reviews passed, $9.00 per shipped change over 10 (failed attempts and every review round included); ranked as cost 3.0 instead of 2`])
+ })
+
+ it('never ranks by the cost of its own attempts alone, which leaves the rework out', () => {
+ // Without a full cost (a backend before it) nothing is measured, even with a cheaper cost per shipped change of its own.
+ const old = measured.map(({ fullCostPerShipped: _full, ...r }) => ({ ...r, fullCostPerShipped: null }))
+ const choice = route(old)
+ expect(order(choice)).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ expect(choice.adjusted).toBeUndefined()
+ })
+
+ it('a clearly lower first-review pass rate ranks below its strength\'s other choices, whatever it costs', () => {
+ // 2 of 12 against 11 of 12: the ranges do not overlap. Codex is cheaper in full here and still goes second.
+ const choice = route([row({ firstReviews: 12, firstReviewPassed: 11, fullCostPerShipped: 9 }),
+ row({ engine: 'codex', model: 'gpt-6.1-sol', firstReviews: 12, firstReviewPassed: 2, fullCostPerShipped: 3 })])
+ expect(order(choice)).toEqual(['claude opus', 'codex gpt-6.1-sol'])
+ expect(mine(choice.shown[1]!)[0]).toContain('2 of 12 first reviews passed, clearly fewer than Claude opus high\'s 11 of 12, so it ranks after its strength\'s other choices')
+ // Still above a weaker model: the plug-in moves a candidate within its strength, never across it.
+ const sonnet = probe({ machineId: 'm3', machineName: 'mac-3', model: 'sonnet', effort: 'medium', quality: 2, cost: 2 })
+ expect(order(route([row({ firstReviews: 12, firstReviewPassed: 11 }), row({ engine: 'codex', model: 'gpt-6.1-sol', firstReviews: 12, firstReviewPassed: 2 })],
+ [opus, codex, sonnet]))).toEqual(['claude opus', 'codex gpt-6.1-sol', 'claude sonnet'])
+ })
+
+ it('below the minimum sample today\'s ranking stays, and nothing is said', () => {
+ const thin = route(measured.map(r => ({ ...r, shipped: 2 })))
+ expect(order(thin)).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ expect(thin.shown.flatMap(mine)).toEqual([])
+ // Too few first reviews keep only the pass rate out: cost still decides with enough shipped changes.
+ const fewReviews = route(measured.map(r => ({ ...r, firstReviews: 4, firstReviewPassed: Math.min(r.firstReviewPassed, 4) })))
+ expect(order(fewReviews)).toEqual(['claude opus', 'codex gpt-6.1-sol'])
+ expect(mine(fewReviews.shown[0]!)[0]).toContain('first reviews too few to compare (4)')
+ // One measured choice has nothing to compare with: its numbers are shown, its place is today's.
+ const alone = route([measured[1]!])
+ expect(order(alone)).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ expect(mine(alone.shown[0]!)[0]).toMatch(/\$9\.00 per shipped change over 10 .*; no other choice for build work has a cost to compare, so its place is unchanged$/)
+ // Nor do choices that cost nothing (own hardware), or a run whose model was never known.
+ for (const others of [[row({ fullCostPerShipped: 0 }), row({ engine: 'codex', model: 'gpt-6.1-sol', fullCostPerShipped: 0 })],
+ [row({ model: 'unknown', effort: 'unknown' }), measured[1]!]]) {
+ expect(order(route(others))).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ }
+ })
+
+ it('a clearly lower pass rate counts with too few shipped changes to compare cost, also against another engine\'s choice', () => {
+ const choice = route([row({ firstReviews: 12, firstReviewPassed: 11, shipped: 1, engine: 'opencode', model: 'big' }),
+ row({ engine: 'codex', model: 'gpt-6.1-sol', firstReviews: 12, firstReviewPassed: 2, shipped: 2 })])
+ expect(order(choice)).toEqual(['claude opus', 'codex gpt-6.1-sol'])
+ expect(mine(choice.shown[1]!)).toEqual([`${MEASURED}: build work, last 7 days: 2 of 12 first reviews passed, clearly fewer than another measured choice's 11 of 12, so it ranks after its strength's other choices, too few shipped changes with known costs to compare cost (2 shipped)`])
+ expect(mine(choice.shown[0]!)).toEqual([])
+ })
+
+ it('a reason built from other groups\' runs names nothing from them: only numbers, the task\'s kind and catalog models', () => {
+ // Runs whose model an agent was configured with as a path or a person's share name, in groups the reader may not open.
+ const leaky = [row({ firstReviews: 12, firstReviewPassed: 11, model: '/Users/ken/models/secret-plan.gguf', effort: 'default', fullCostPerShipped: 9 }),
+ row({ engine: 'codex', model: 'gpt-6.1-sol', firstReviews: 12, firstReviewPassed: 2, fullCostPerShipped: 3 })]
+ const choice = route(leaky)
+ const reasons = choice.shown.flatMap(mine).join(' ')
+ expect(reasons).toContain('clearly fewer than another measured choice\'s 11 of 12')
+ for (const leak of ['Users', 'ken', 'secret', 'gguf', '/']) expect(reasons).not.toContain(leak)
+ // A kind that is no plain word (an old record's free text) is dropped before any reason can carry it.
+ expect(measuredFrom({ ok: true, value: { rows: [row({ kind: 'Fix Ana\'s login (#2101)' })] } })).toEqual({ rows: [], truncated: false })
+ })
+
+ it('a Claude model it has no family for is matched by its own name', () => {
+ const odd = probe({ model: 'claude-experimental', effort: 'default', cost: 1, quality: 3 })
+ const choice = route([...measured, row({ model: 'claude-experimental', effort: 'default', fullCostPerShipped: 60 })], [odd, codex])
+ expect(order(choice)).toEqual(['codex gpt-6.1-sol', 'claude claude-experimental'])
+ })
+
+ it('review work, and any kind with no first reviews, ranks as today: cost alone says nothing of how it went', () => {
+ // A review attempt is credited with the reviewed work's ship, and its cost is already in that build's full cost (review of
+ // #2423: Opus high reviews read as 76 shipped changes at $0.95).
+ const reviews = measured.map(r => ({ ...r, kind: 'review', firstReviews: 0, firstReviewPassed: 0 }))
+ for (const [rows, a] of [[reviews, task({ kind: 'review' })], [measured.map(r => ({ ...r, kind: 'review' })), task({ kind: 'review' })],
+ [measured.map(r => ({ ...r, firstReviews: 0, firstReviewPassed: 0 })), task()]] as const) {
+ const choice = route([...rows], [opus, codex], a)
+ expect(order(choice)).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ expect(choice.shown.flatMap(mine)).toEqual([])
+ }
+ })
+
+ it('only choices a candidate can be set the cost scale, so a run of a model nobody offers moves nothing', () => {
+ const odd = row({ model: 'sonnet', effort: 'high', fullCostPerShipped: 300 })
+ expect(route([...measured, odd]).shown.flatMap(mine)).toEqual(route(measured).shown.flatMap(mine))
+ })
+
+ it('says how much of a choice\'s cost is estimated', () => {
+ const choice = route([{ ...measured[0]!, fullCostKnown: 0.6 }, measured[1]!])
+ expect(mine(choice.shown[0]!)[0]).toContain('$6.00 per shipped change over 10 (failed attempts and every review round included; 40% of the costs estimated)')
+ })
+
+ it('a task with no kind, or a kind nothing was measured for, ranks as today', () => {
+ for (const a of [task({ kind: undefined }), task({ kind: 'docs' })]) {
+ const choice = route(measured, [opus, codex], a)
+ expect(order(choice)).toEqual(['codex gpt-6.1-sol', 'claude opus'])
+ expect(choice.adjusted).toBeUndefined()
+ }
+ })
+
+ it('only reorders what the route allows: a refused candidate stays out, and the plug-in adds none', () => {
+ const blocked = { ...opus, refusals: ['Machine is offline or unreachable.'] }
+ const choice = choose([blocked, codex], catalog, task(), NOW, [], [], [], [measuredPlugin({ rows: measured, truncated: false })])
+ if ('error' in choice) throw new Error('no candidate')
+ expect(order(choice)).toEqual(['codex gpt-6.1-sol'])
+ expect(choice.excluded.map(e => e.reason)).toEqual(['Machine is offline or unreachable.'])
+ expect(measuredPlugin({ rows: measured, truncated: false }).candidates).toBeUndefined()
+ })
+
+ it('matches a member by its model\'s family and a grid agent by its grid model', () => {
+ const member = probe({ kind: 'member', agentId: 'a1', name: 'Jules', model: 'claude-opus-5-5[1m]', machineId: 'm4', machineName: 'mac-4' })
+ const grid = probe({ machineId: 'm5', machineName: 'grid-1', model: 'default', effort: 'default', quality: 3, cost: 1, gridModel: 'moonshotai/kimi-k3', gridName: 'g', gridLabel: 'Kimi K3', gridKind: 'api' })
+ const rows = [...measured, row({ model: 'moonshotai/kimi-k3', effort: 'default', firstReviewPassed: 5, fullCostPerShipped: 30 })]
+ const choice = route(rows, [member, codex, grid])
+ expect(order(choice)).toEqual(['claude claude-opus-5-5[1m]', 'codex gpt-6.1-sol', 'claude default'])
+ expect(mine(choice.shown[2]!)[0]).toContain('$30.00 per shipped change')
+ })
+
+ it('says when the read held only the newest attempts', () => {
+ expect(mine(route(measured, [opus, codex], task(), true).shown[0]!)[0]).toMatch(/; only the newest attempts were read$/)
+ })
+})
+
+describe('reading the measures', () => {
+ const answer = (rows: unknown[], extra: Record<string, unknown> = {}) => ({ ok: true, value: { days: 7, truncated: false, rows, ...extra } })
+
+ it('asks for the last 7 days and keeps only the fields it ranks by', async () => {
+ const asked: unknown[] = []
+ const read = await readMeasured(async payload => { asked.push(payload); return answer([{ ...row({}), tokens: { input: 1 }, outcomes: { done: 1 } }], { truncated: true }) })
+ expect(asked).toEqual([{ action: 'costs', days: 7 }])
+ expect(read).toEqual({ rows: [row({})], truncated: true })
+ })
+
+ it('a refusal, a failure, a slow read or an answer it cannot read gives no measures, so the route ranks as today', async () => {
+ expect(await readMeasured(async () => ({ error: 'FORBIDDEN' }))).toBeNull()
+ expect(await readMeasured(async () => { throw new Error('gone') })).toBeNull()
+ expect(await readMeasured(() => new Promise(() => {}), 5)).toBeNull()
+ expect(measuredFrom({ ok: true, value: { rows: 'x' } })).toBeNull()
+ // A row it cannot read is dropped; the rest count.
+ expect(measuredFrom(answer([{ engine: 'claude' }, row({}), { ...row({}), shipped: -1 }, { ...row({}), fullCostPerShipped: Number.NaN }]))).toEqual({ rows: [row({})], truncated: false })
+ // A backend before full costs sends none: read as unknown.
+ const { fullCostPerShipped: _f, fullCostKnown: _k, ...older } = row({})
+ expect(measuredFrom(answer([older]))).toEqual({ rows: [row({ fullCostPerShipped: null, fullCostKnown: null })], truncated: false })
+ expect(measuredFrom(answer([{ ...row({}), fullCostKnown: 2 }]))).toEqual({ rows: [], truncated: false })
+ })
+})
+
+describe('the maker', () => {
+ const made = (a: Assessment, request: PluginInput['request']) => MEASURED_MAKER.make({ conversationId: 'g1', assessment: a, read: {}, catalog,
+ history: Promise.resolve(null), request })
+ const costs = (rows: unknown[]) => async () => ({ ok: true, value: { truncated: false, rows } })
+
+ it('is in the route\'s list of makers', () => {
+ expect(ROUTE_PLUGIN_MAKERS).toContain(MEASURED_MAKER)
+ })
+
+ it('reads nothing for a task with no kind of work', async () => {
+ let asked = 0
+ expect(await made(task({ kind: undefined }), async () => { asked++; return {} })).toBeNull()
+ expect(asked).toBe(0)
+ })
+
+ it('makes the plug-in when the kind was measured, has nothing to say when it was not, and fails when the read fails', async () => {
+ const plugin = await made(task(), costs(measured))
+ expect(plugin?.name).toBe(MEASURED)
+ expect(await made(task({ kind: 'docs' }), costs(measured))).toBeNull()
+ await expect(made(task(), async () => ({ error: 'FORBIDDEN' }))).rejects.toThrow()
+ })
+})
diff --git a/cli/src/superTabs/routeMeasured.ts b/cli/src/superTabs/routeMeasured.ts
new file mode 100644
index 000000000..071f8fb60
--- /dev/null
+++ b/cli/src/superTabs/routeMeasured.ts
@@ -0,0 +1,163 @@
+/** Routing by what choices actually cost and how they did (Scholes's goals, piece 3, 2026-10-31): a routing plug-in (route.ts
+ * RoutePlugin) that moves a candidate within its strength by its choice's measured results for the task's kind of work, over
+ * the project's last 7 days (backend superTabs/costs/read.ts, the same read as `harness super-tab costs`, which counts only
+ * the groups the routing agent may read and refuses a Buddy).
+ *
+ * - Cost: the full cost per shipped change, every ended attempt of the choice (failed and lost ones too) and every review of
+ * its work, rework rounds included. A choice's own attempts alone made one that passes 6 of 10 first reviews look cheaper
+ * than one that passes 9 of 10, its extra review rounds left out (Lead, 2026-10-31). The measured choices of the kind are
+ * ranked by it on the catalog's cost scale, so they keep their place against unmeasured ones on average.
+ * - Results: a first-review pass rate clearly under another measured choice's (their 95% ranges apart) ranks the choice after
+ * its strength's other choices, never below a weaker strength. With 5 to 10 reviews the ranges nearly always overlap, so
+ * cost decides.
+ * - Only with enough of it: at least MIN_SHIPPED shipped changes for cost and MIN_FIRST_REVIEWS first reviews for the pass
+ * rate (the nightly reflection's own thresholds, costs/reflection.ts); otherwise today's ranking.
+ * It never adds or refuses a candidate: what may run is the route's, and only its order changes. The kind is the word the
+ * routing agent gives in its assessment (`kind`); none, or one nothing was measured for, ranks as today. */
+import { claudeAliasForModel } from '../engines/claude/runtimeProfile.js'
+import { catalogRow, type Catalog, type Probe, type RoutePlugin } from './route.js'
+import type { PluginMaker } from './routePlugins.js'
+import type { ScopedRequest } from './start.js'
+import { within } from './wire.js'
+
+export const MEASURED = 'measured results'
+export const DAYS = 7
+export const MIN_FIRST_REVIEWS = 5
+export const MIN_SHIPPED = 3
+/** How far a clearly worse pass rate moves a candidate: after its strength's other choices, before the next strength's. */
+const WORSE = -0.5
+const Z = 1.96
+/** Well under the makers' 3 s (routePlugins.ts MAKER_TIMEOUT_MS), so a slow read is said as this piece's own failure. */
+export const READ_MS = 2000
+
+/** One choice's results for one kind of work, as the costs read gives them (backend costs/read.ts CostSummaryRow, FullCost). */
+export interface MeasuredRow { engine: string; model: string; effort: string; kind: string; firstReviews: number; firstReviewPassed: number
+ shipped: number; costPerShipped: number | null; fullCostPerShipped: number | null
+ /** The share of the full cost's attempts whose cost is known; the rest were filled with their choice's mean. */
+ fullCostKnown: number | null }
+/** `truncated`: the read reached its row limit, so it holds only the newest attempts. */
+export interface Measured { rows: MeasuredRow[]; truncated: boolean }
+
+const ENGINE: Record<string, string> = { claude: 'Claude', codex: 'Codex' }
+const count = (v: unknown): v is number => Number.isInteger(v) && (v as number) >= 0
+const money = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v) && v >= 0
+const object = (v: unknown): Record<string, unknown> => v && typeof v === 'object' && !Array.isArray(v) ? v as Record<string, unknown> : {}
+
+/** The rows of a costs answer it can rank by, or null when the answer is no summary. A row it cannot read is dropped; a
+ * backend before full costs sends none, read as unknown. */
+export function measuredFrom(answer: unknown): Measured | null {
+ const reply = object(answer), value = object(reply.value)
+ if (reply.ok !== true || !Array.isArray(value.rows)) return null
+ const rows = value.rows.map(object).flatMap((r): MeasuredRow[] => {
+ const full = r.fullCostPerShipped ?? null, own = r.costPerShipped ?? null, known = r.fullCostKnown ?? null
+ if (![r.engine, r.model, r.effort, r.kind].every(s => typeof s === 'string') || !KIND.test(r.kind as string) || !count(r.firstReviews) || !count(r.firstReviewPassed)
+ || r.firstReviewPassed > r.firstReviews || !count(r.shipped) || !(full === null || money(full)) || !(own === null || money(own))
+ || !(known === null || money(known) && known <= 1)) return []
+ return [{ engine: r.engine as string, model: r.model as string, effort: r.effort as string, kind: r.kind as string, firstReviews: r.firstReviews,
+ firstReviewPassed: r.firstReviewPassed, shipped: r.shipped, costPerShipped: own, fullCostPerShipped: full, fullCostKnown: known }]
+ })
+ return { rows, truncated: value.truncated === true }
+}
+
+/** The project's measures, read through the route's own backend request: null when refused, failed, slower than [ms] or
+ * unreadable, so the route ranks as today. The route runs about 30 times an hour; the read is the costs command's, about
+ * 0.1 to 0.3 s beyond a plain request on the openharness Swarm (2026-10-31). */
+export async function readMeasured(request: ScopedRequest, ms = READ_MS): Promise<Measured | null> {
+ const answer = await within(request({ action: 'costs', days: DAYS }).catch(() => null), ms)
+ return answer ? measuredFrom(answer) : null
+}
+
+/** The 95% Wilson range of `passed` of `n` (backend costs/reflection.ts wilson): honest about small samples. */
+function wilson(passed: number, n: number): { low: number; high: number } {
+ const p = passed / n, z2 = Z * Z
+ const centre = p + z2 / (2 * n), spread = Z * Math.sqrt(p * (1 - p) / n + z2 / (4 * n * n)), scale = 1 + z2 / n
+ return { low: Math.max(0, (centre - spread) / scale), high: Math.min(1, (centre + spread) / scale) }
+}
+
+/** The name a candidate's runs are kept under: a grid model's own, a Claude family for Claude's full ids. */
+function ranAs(p: Pick<Probe, 'engine' | 'model' | 'gridModel'>): string {
+ if (p.gridModel) return p.gridModel
+ return p.engine === 'claude' ? claudeAliasForModel(p.model.replace(/\[1m\]$/i, '')) ?? p.model : p.model
+}
+const listed = (r: MeasuredRow, catalog: Catalog) => catalog.models.some(m => m.engine === r.engine && m.model === r.model && m.effort === r.effort)
+/** Kinds whose attempts have no result of their own: a review is credited with the reviewed work's ship, and its cost is
+ * already in that build's full cost, so by cost alone Opus high reviews read as 76 shipped changes at $0.95 (review of #2423). */
+const UNMEASURED_KINDS = new Set(['review'])
+/** Another choice as a reason names it: only a model of the catalog, whose names every reader of the route log already sees.
+ * A row's model is what an agent was configured with, and a grid or local model's can be a file path or a person's share
+ * name: such a row is "another measured choice" (hook review, 2026-10-31: reasons hold numbers and kinds of work only). */
+const nameOf = (r: MeasuredRow, catalog: Catalog) => listed(r, catalog) ? `${ENGINE[r.engine]} ${r.model} ${r.effort}` : 'another measured choice'
+/** A kind of work as the route takes it (route.ts parseAssessment): one lowercase word. A row of any other kind is dropped. */
+const KIND = /^[a-z][a-z0-9-]{0,39}$/
+const costed = (r: MeasuredRow) => r.shipped >= MIN_SHIPPED && r.fullCostPerShipped !== null
+const reviewed = (r: MeasuredRow) => r.firstReviews >= MIN_FIRST_REVIEWS
+
+/** The plug-in over [measured]: pure, so the route ranks every candidate with the same numbers. */
+export function measuredPlugin(measured: Measured): RoutePlugin {
+ /** Per kind: its rows, and the measured costs' scale on the catalog's: dollars per cost point, so the measured choices keep
+ * their mean place against unmeasured ones. Null when fewer than two choices have a cost to compare. */
+ const byKind = new Map<string, { rows: MeasuredRow[]; scale: number | null; results: boolean }>()
+ const scaleOf = (rows: MeasuredRow[], catalog: Catalog) => {
+ // Only the catalog's own choices set the scale: a run of a model nobody offers (an effort the catalog has no row for, a
+ // model never reported) would move every candidate without being one (review of #2423).
+ const scaled = rows.filter(r => costed(r) && listed(r, catalog))
+ const points = scaled.reduce((sum, r) => sum + catalogRow(catalog, r.engine, r.model, r.effort)!.cost, 0)
+ const dollars = scaled.reduce((sum, r) => sum + r.fullCostPerShipped!, 0)
+ // All free (own hardware): nothing to tell them apart by.
+ return scaled.length >= 2 && dollars > 0 ? dollars / points : null
+ }
+ return {
+ name: MEASURED,
+ adjust(candidate, { assessment, catalog }) {
+ const kind = assessment.kind
+ if (!kind || UNMEASURED_KINDS.has(kind)) return null
+ let ofKind = byKind.get(kind)
+ if (!ofKind) {
+ const rows = measured.rows.filter(r => r.kind === kind)
+ // A kind with no first review at all has no results to go by: cost alone ranks it as nothing else does.
+ ofKind = { rows, scale: rows.some(r => r.firstReviews > 0) ? scaleOf(rows, catalog) : null, results: rows.some(r => r.firstReviews > 0) }
+ byKind.set(kind, ofKind)
+ }
+ if (!ofKind.results) return null
+ const name = ranAs(candidate)
+ const mine = ofKind.rows.find(r => r.engine === candidate.engine && r.model === name && r.effort === candidate.effort)
+ if (!mine) return null
+ // Clearly fewer passes than the best other measured choice: the top of its range under the bottom of that one's.
+ const range = reviewed(mine) ? wilson(mine.firstReviewPassed, mine.firstReviews) : null
+ const best = range ? ofKind.rows.filter(r => r !== mine && reviewed(r))
+ .map(r => ({ r, low: wilson(r.firstReviewPassed, r.firstReviews).low })).sort((x, y) => y.low - x.low)[0] : undefined
+ const worse = !!range && !!best && range.high < best.low
+ if (!costed(mine) && !worse) return null
+ const pass = !reviewed(mine) ? `first reviews too few to compare (${mine.firstReviews})`
+ : `${mine.firstReviewPassed} of ${mine.firstReviews} first reviews passed${worse
+ ? `, clearly fewer than ${nameOf(best!.r, catalog)}'s ${best!.r.firstReviewPassed} of ${best!.r.firstReviews}, so it ranks after its strength's other choices` : ''}`
+ let cost: string, shift = 0
+ if (!costed(mine)) cost = `too few shipped changes with known costs to compare cost (${mine.shipped} shipped)`
+ else {
+ const estimated = mine.fullCostKnown !== null && mine.fullCostKnown < 1 ? `; ${Math.round((1 - mine.fullCostKnown) * 100)}% of the costs estimated` : ''
+ const full = `$${mine.fullCostPerShipped!.toFixed(2)} per shipped change over ${mine.shipped} (failed attempts and every review round included${estimated})`
+ if (ofKind.scale === null) cost = `${full}; no other choice for ${kind} work has a cost to compare, so its place is unchanged`
+ else {
+ const points = mine.fullCostPerShipped! / ofKind.scale
+ shift = points - candidate.cost
+ cost = `${full}; ranked as cost ${points.toFixed(1)} instead of ${candidate.cost}`
+ }
+ }
+ return { reason: `${kind} work, last ${DAYS} days: ${pass}, ${cost}${measured.truncated ? '; only the newest attempts were read' : ''}`,
+ ...(shift ? { cost: shift } : {}), ...(worse ? { strength: WORSE } : {}) }
+ },
+ }
+}
+
+/** The maker (routePlugins.ts): no kind of work, nothing to read; a read that fails says so through the route's warnings
+ * (the maker failed); a kind with no rows has nothing to say. */
+export const MEASURED_MAKER: PluginMaker = {
+ name: MEASURED,
+ async make({ assessment, request }) {
+ const kind = assessment.kind
+ if (!kind) return null
+ const measured = await readMeasured(request)
+ if (!measured) throw new Error('The cost results could not be read.')
+ return measured.rows.some(r => r.kind === kind) ? measuredPlugin(measured) : null
+ },
+}
diff --git a/cli/src/superTabs/routePlugins.ts b/cli/src/superTabs/routePlugins.ts
index e2280990a..dd92d6046 100644
--- a/cli/src/superTabs/routePlugins.ts
+++ b/cli/src/superTabs/routePlugins.ts
@@ -3,6 +3,7 @@
* call (piece 3's builder, 10-31). A maker does its piece's outside read and returns a pure plug-in holding what it read;
* routeTask starts every maker together with the machine probes, so a maker's read costs no time of its own. */
import { pluginSkipped, type Assessment, type Catalog, type RoutePlugin } from './route.js'
+import { MEASURED_MAKER } from './routeMeasured.js'
import type { ScopedRequest } from './start.js'
import { windowPullMaker } from './windowPull.js'
@@ -25,6 +26,8 @@ export interface PluginMaker { readonly name: string; make(input: PluginInput):
/** The makers, in the order their plug-ins run. One line per piece. */
export const ROUTE_PLUGIN_MAKERS: readonly PluginMaker[] = [
+ // Piece 3: measured cost per shipped change and first-review pass rate, per kind of work.
+ MEASURED_MAKER,
windowPullMaker(),
]
diff --git a/cli/src/superTabs/windowPull.spec.ts b/cli/src/superTabs/windowPull.spec.ts
index c21b10fe6..d34025b53 100644
--- a/cli/src/superTabs/windowPull.spec.ts
+++ b/cli/src/superTabs/windowPull.spec.ts
@@ -2,6 +2,7 @@
import { describe, expect, it } from 'vitest'
import { choose, decide, recordOf, type Assessment, type Catalog, type Commitment, type Fit, type Probe, type RoutePlugin } from './route.js'
import { makePlugins, ROUTE_PLUGIN_MAKERS, type PluginInput } from './routePlugins.js'
+import { MEASURED, measuredPlugin } from './routeMeasured.js'
import { MAX_DISCOUNT, pendingPicks, PENDING_MS, WINDOW_PULL, windowPull, windowPullAdjust, windowPullMaker, weeklyUnused } from './windowPull.js'
/** Today's rows (route.spec.ts): Opus high and Codex default both strength 3, Codex cheaper; Sonnet weaker. */
@@ -69,14 +70,17 @@ describe('the window pull ranks', () => {
// At most half, however much would go unused.
expect(windowPullAdjust(fitted(codex('zulu', SOON)), NOW, [])?.cost).toBe(-2 * MAX_DISCOUNT)
expect(windowPullAdjust(fitted(codex('zulu', SOON), { effectiveCost: 1.2 }), NOW, [])?.cost).toBe(-0.6)
- // A stand-in for piece 3's measured plug-in until it merges: a first-review record worth more than half the price.
- const measured: RoutePlugin = { name: 'Measured', adjust: c => c.machineId === 'alpha' ? { cost: -1.2, reason: 'passed first review on 9 of its last 10 builds' } : null }
- const probes = [codex('alpha', FRESH), codex('zulu', SOON)]
- expect(route(probes, [pull]).shown[0]!.machineId).toBe('zulu')
+ // Piece 3's measured plug-in: Opus high passed 9 of 10 first reviews at $3 per shipped change in full, Codex 6 of 10 at $9.
+ const row = (engine: string, model: string, effort: string, firstReviewPassed: number, fullCostPerShipped: number) => ({ engine, model, effort, kind: 'build',
+ firstReviews: 10, firstReviewPassed, shipped: 10, costPerShipped: 1, fullCostPerShipped, fullCostKnown: 1 })
+ const measured = measuredPlugin({ truncated: false, rows: [row('claude', 'opus', 'high', 9, 3), row('codex', 'default', 'default', 6, 9)] })
+ const probes = [codex('alpha', FRESH, { engine: 'claude', model: 'opus', effort: 'high', cost: 3 }), codex('zulu', SOON)]
+ expect(route(probes, [pull], [], { kind: 'build' }).shown[0]!.machineId).toBe('zulu')
for (const plugins of [[measured, pull], [pull, measured]]) {
- const choice = route(probes, plugins)
+ const choice = route(probes, plugins, [], { kind: 'build' })
expect(choice.shown.map(s => s.machineId)).toEqual(['alpha', 'zulu'])
expect(noteOf(choice.shown[1]!)).toBeDefined()
+ expect(choice.shown[0]!.notes.some(n => n.startsWith(`${MEASURED}: build work`))).toBe(true)
}
})
it('takes off only the part of the task the window would leave unused', () => {
diff --git a/cli/vitest.super-tabs.config.ts b/cli/vitest.super-tabs.config.ts
index f285597d4..4938c454c 100644
--- a/cli/vitest.super-tabs.config.ts
+++ b/cli/vitest.super-tabs.config.ts
@@ -6,7 +6,10 @@ import base from './vitest.config.js'
* the core and services, which no other gate covers, held to 100% in every file. And the Swarm's side of the core's
* process (superTabs/inCore/), which left the core's own 100% gate when the Swarm became a switch. */
const IN_CORE = ['adoption', 'agents', 'attention', 'cards', 'deliveries', 'launch', 'role', 'teamApps', 'teamPurge', 'terminal'].map(name => `src/superTabs/inCore/${name}.ts`)
-const FILES = ['src/superTabs/route.ts', 'src/superTabs/routeCommand.ts', 'src/superTabs/routePlugins.ts', 'src/superTabs/windowPull.ts', 'src/superTabs/shortCommand.ts', ...IN_CORE]
+const FILES = ['src/superTabs/route.ts', 'src/superTabs/routeCommand.ts', 'src/superTabs/routePlugins.ts', 'src/superTabs/shortCommand.ts', ...IN_CORE,
+ // The routing plug-ins (routePlugins.ts), one line each.
+ 'src/superTabs/routeMeasured.ts', 'src/superTabs/windowPull.ts',
+]
export default defineConfig({
test: {
...base.test,