From bf959aa60e2aba3d520c6cfb758731e5a2b89976 Mon Sep 17 00:00:00 2001 From: Akiiwa <115624916+akiiwa-games@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:15:28 +0800 Subject: [PATCH] agentcompass 0.1.2: sync AgentCompass v0.3.8 scoring (floors, origin, frontier headroom, curves, work-kind inference) (#749) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Syncs Mode A's scoring with AgentCompass v0.3.8 (akiiwa-games/AgentCompass, accounts.json and scripts/allocator.py): ability floors routine 2.3 / hard 3.1, `ability_score_origin` (graded from max(floor, origin)), `critical_headroom_by_difficulty` {frontier: 0.1}, the tool_execution route floor {hard: 2.7}, the 13 effort curves and `effort_ability`/`effort_burn`, and 54bb51e's work-kind inference (COMPUTER_USE_PHRASES, CODE_FILE_RE guard, "translation of", the code-file/debug skip). `extractRequestFacts().hasComputerUse` uses the same phrases and guard, so continuity's GUI `capability_outgrown` no longer fires on bare "gui", "desktop app", "keyboard", "桌面", "键盘". Version 0.1.2. Reviewed at head 4ff38ce1d (previous review at 4de283991; the 4ff38ce diff drops the four screenshot phrases and adds tests 8.9 to 8.12). Checked against upstream v0.3.8 (e30836e7) by script: all 13 curves in 8.12's table and `effort_ability`/`effort_burn` equal accounts.json; COMPUTER_USE_PHRASES equals allocator.py:1088 exactly. Run at 4ff38ce1d on mote (macOS, Bun 1.4.2, Node 22.22.0): `bun test` 40 pass 0 fail; `node --test test/router.test.mjs` 40 pass; `bun scripts/check.mjs agentcompass` exit 0. PR CI (test, on-npm) green. Broken by hand at 4ff38ce1d, one at a time, each red: - origin = floor -> 8.9 - CODE_FILE_RE guard off in inferKindFromObjective -> 8.10 - bare "keyboard"/"mouse" in COMPUTER_USE_PHRASES -> 8.10, 8.11 - "translation of" -> "translation" -> 8.10 - namesCode out of the translation skip -> 8.10 - hasComputerUse without the guard, or on GUI_WORDS -> 8.10, 8.11 - "take a screenshot" or "截屏操作" put back -> 8.10 - opus xhigh ability, carbon medium burn, effort_ability.xhigh, effort_burn.max changed -> 8.12 - criticalHeadroom ignoring the table -> 8.7; abilityFloor ignoring the route -> 8.8 Not tried: real routing traffic through a live magpie gateway. --- packages/agentcompass/package.json | 2 +- packages/agentcompass/src/allocator.js | 51 ++++- packages/agentcompass/src/catalog.js | 76 ++++--- packages/agentcompass/src/profiler-core.js | 43 ++-- packages/agentcompass/test/router.test.mjs | 236 ++++++++++++++++++++- 5 files changed, 354 insertions(+), 54 deletions(-) diff --git a/packages/agentcompass/package.json b/packages/agentcompass/package.json index 344e3c3..c7308c1 100644 --- a/packages/agentcompass/package.json +++ b/packages/agentcompass/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/gateway-agentcompass", - "version": "0.1.1", + "version": "0.1.2", "description": "Intent, multi-dimensional capability, Model DNA, subscription quota opportunity-cost, and session-affinity routing plugin for Magpie, powered by AgentCompass.", "type": "module", "main": "./src/index.js", diff --git a/packages/agentcompass/src/allocator.js b/packages/agentcompass/src/allocator.js index 4dba9b7..71ec3a8 100644 --- a/packages/agentcompass/src/allocator.js +++ b/packages/agentcompass/src/allocator.js @@ -184,13 +184,40 @@ export function fitScore(kind, model, catalog = {}, options = {}) { return Math.max(band.floor, round4(band.start - band.step * (place - 1))); } +/** + * The minimum ability a route's work needs at a difficulty (`allocator.py:ability_floor`). + */ +export function abilityFloor(policy = DEFAULT_SCORING_POLICY, route = null, difficulty = "hard") { + const own = route?.ability_floor || {}; + return difficulty in own ? Number(own[difficulty]) : Number(policy.ability_floor?.[difficulty] ?? 3.0); +} + +/** + * Extra ability critical work needs above the difficulty's floor (`allocator.py:critical_headroom`). + */ +export function criticalHeadroom(policy = DEFAULT_SCORING_POLICY, difficulty = "hard") { + const own = policy?.critical_headroom_by_difficulty || {}; + return difficulty in own ? Number(own[difficulty]) : Number(policy?.critical_headroom ?? 0.3); +} + /** * Continuous task ability demand (`allocator.py:task_demand`). */ -export function taskDemand(profile, difficulty, critical, divergence, policy = DEFAULT_SCORING_POLICY, highPrecision = false) { +export function taskDemand( + profile, + difficulty, + critical, + divergence, + policy = DEFAULT_SCORING_POLICY, + highPrecision = false, + floorOverride = null, +) { const cfg = policy.demand || DEFAULT_SCORING_POLICY.demand; - const floor = Number(policy.ability_floor?.[difficulty] ?? 3.3); - const headroom = critical ? Number(policy.critical_headroom ?? 0.3) : 0.0; + const floor = + floorOverride === null || floorOverride === undefined + ? Number(policy.ability_floor?.[difficulty] ?? 3.3) + : Number(floorOverride); + const headroom = critical ? criticalHeadroom(policy, difficulty) : 0.0; const precision = highPrecision && !critical ? Number(cfg.precision_headroom ?? 0.15) : 0.0; const span = Number(policy.profile?.saturation_span ?? 0.3); @@ -389,15 +416,15 @@ export function evaluateCandidate(candidate, taskCtx, catalog = {}) { `context window ${info.context_window || 128000} outgrown by ${taskCtx.min_context_tokens} tokens` ); } + const routes = catalog.routes || CANONICAL_ROUTES; + const route = routes[taskCtx.kind] || {}; const ability = effortAbility(policy, curves, info, effort); const highAbility = effortAbility(policy, curves, info, "high"); const demand = taskCtx.demand; const target = demand.required_ability; - const floor = policy.ability_floor[taskCtx.difficulty] ?? 3.0; - const gate = floor + (taskCtx.critical ? policy.critical_headroom : 0.0); - - const routes = catalog.routes || CANONICAL_ROUTES; - const route = routes[taskCtx.kind] || {}; + const floor = demand.floor ?? abilityFloor(policy, route, taskCtx.difficulty); + const headroom = taskCtx.critical ? criticalHeadroom(policy, taskCtx.difficulty) : 0.0; + const gate = floor + headroom; if ( route.restrict_models && taskCtx.specialist_available && @@ -508,7 +535,8 @@ export function evaluateCandidate(candidate, taskCtx, catalog = {}) { span = Number(policy.profile?.saturation_span ?? 0.3); } - let abilityScore = clamp((credited - (taskCtx.high_precision ? gate : floor)) / span, 0, 1); + const origin = Math.max(floor, Number(policy.ability_score_origin?.[taskCtx.difficulty] ?? floor)); + let abilityScore = clamp((credited - origin - (taskCtx.high_precision ? gate - floor : 0.0)) / span, 0, 1); const qualityBonus = taskCtx.high_precision ? round4(Number(policy.high_precision_effort_weight ?? 0.14) * effortGain) : 0.0; @@ -683,7 +711,9 @@ export function rankCandidates(profileInput, options = {}) { (!critical || mechanicalRunbook) ); - const demand = taskDemand(profile, difficulty, critical, div, policy, highPrecision); + const routeObj = routes[kind] || {}; + const floor = abilityFloor(policy, routeObj, difficulty); + const demand = taskDemand(profile, difficulty, critical, div, policy, highPrecision, floor); const requirements = profileRequirements(profile, policy); const sWeights = subjectiveWeights(profile, kind); @@ -720,7 +750,6 @@ export function rankCandidates(profileInput, options = {}) { if (rawM) candidateCanonicals.add(canonicalModel(rawM, aliases)); } const dotAvailable = candidateCanonicals.has("dot"); - const routeObj = routes[kind] || {}; const specialistAvailable = Boolean( routeObj.restrict_models && (routeObj.preferred || []).some((m) => candidateCanonicals.has(canonicalModel(m, aliases))) diff --git a/packages/agentcompass/src/catalog.js b/packages/agentcompass/src/catalog.js index fe1d33f..6c52560 100644 --- a/packages/agentcompass/src/catalog.js +++ b/packages/agentcompass/src/catalog.js @@ -267,6 +267,7 @@ export const CANONICAL_ROUTES = { "gpt-6-astra", "grok-4.7", ], + ability_floor: { hard: 2.7 }, restrict_models: false, }, text_in_text_out: { @@ -1260,45 +1261,57 @@ export const MODEL_ALIASES = { }; export const EFFORT_CURVES = { + "deepseek-v4.1-flash-free": { + ability: { high: 0, max: 0.2 }, + burn: { high: 0.7, max: 0.91 }, + }, "claude-opus-5-5": { - ability: { low: -1.2, medium: -0.3, high: 0.0, xhigh: 0.2, max: 0.4 }, - burn: { low: 0.21, medium: 0.52, high: 0.7, xhigh: 1.33, max: 2.3 }, + ability: { low: -0.84, medium: -0.2, high: 0, xhigh: 0.25, max: 0.35 }, + burn: { low: 0.2, medium: 0.5, high: 0.7, xhigh: 1.22, max: 2.03 }, }, "claude-sonnet-5-5": { - ability: { low: -1.1, medium: -0.6, high: 0.0, xhigh: 0.5, max: 0.9 }, - burn: { low: 0.28, medium: 0.38, high: 0.7, xhigh: 1.6, max: 4.34 }, - }, - "claude-haiku-5-5": { - ability: { low: -0.15, medium: 0.0, high: 0.1 }, - burn: { low: 0.35, medium: 0.5, high: 0.7 }, + ability: { low: -0.79, medium: -0.54, high: 0, xhigh: 0.4, max: 0.64 }, + burn: { low: 0.22, medium: 0.33, high: 0.7, xhigh: 1.75, max: 4.28 }, }, "gpt-6-astra": { - ability: { low: -0.5, medium: -0.1, high: 0.0, xhigh: 0.1, max: 0.2 }, - burn: { low: 0.33, medium: 0.62, high: 0.7, xhigh: 0.93, max: 1.32 }, + ability: { low: -0.59, medium: -0.15, high: 0, xhigh: 0, max: 0.1 }, + burn: { low: 0.31, medium: 0.59, high: 0.7, xhigh: 0.79, max: 1.35 }, }, "gpt-6.1-sol": { - ability: { low: -0.8, medium: -0.2, high: 0.0, xhigh: 0.1, max: 0.2 }, - burn: { low: 0.28, medium: 0.46, high: 0.7, xhigh: 0.85, max: 1.58 }, - }, - "gpt-6-luna": { - ability: { low: -0.15, medium: 0.0, high: 0.1 }, - burn: { low: 0.35, medium: 0.5, high: 0.7 }, + ability: { low: -0.74, medium: -0.2, high: 0, xhigh: 0.1, max: 0.25 }, + burn: { low: 0.19, medium: 0.43, high: 0.7, xhigh: 0.9, max: 1.51 }, }, "grok-4.7": { - ability: { low: -0.4, high: 0.0, xhigh: 0.0 }, - burn: { low: 0.32, high: 0.7, xhigh: 0.96 }, + ability: { low: -0.2, high: 0, xhigh: 0 }, + burn: { low: 0.33, high: 0.7, xhigh: 0.88 }, }, "gemini-3.8-flash-high": { - ability: { medium: -0.1, high: 0.0 }, - burn: { medium: 0.53, high: 0.7 }, + ability: { low: -0.4, medium: -0.05, high: 0 }, + burn: { medium: 0.56, high: 0.7 }, }, "gemini-4-argon-high": { - ability: { low: -0.3, medium: -0.1, high: 0.0 }, + ability: { low: -0.3, medium: -0.1, high: 0 }, burn: { low: 0.63, medium: 0.7, high: 0.7 }, }, + "claude-haiku-5-5": { + ability: { low: -0.54, medium: -0.25, high: 0, xhigh: 0.25, max: 0.3 }, + burn: { low: 0.17, medium: 0.39, high: 0.7, xhigh: 1.09, max: 1.79 }, + }, + "gpt-6.1-terra": { + ability: { low: -0.64, medium: -0.2, high: 0, xhigh: 0.15, max: 0.45 }, + burn: { low: 0.19, medium: 0.46, high: 0.7, xhigh: 1.08, max: 2.58 }, + }, + "gpt-6-luna": { + ability: { low: -0.54, medium: -0.15, high: 0, xhigh: 0.1, max: 0.35 }, + burn: { low: 0.1, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.5 }, + }, "claude-fable-5-1": { - ability: { low: -0.7, medium: -0.3, high: 0.0, xhigh: 0.2, max: 0.4 }, - burn: { low: 0.2, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.3 }, + ability: { low: -0.4, medium: -0.2, high: 0, xhigh: 0.15, max: 0.15 }, + burn: { low: 0.41, medium: 0.52, high: 0.7, xhigh: 1.01, max: 1.21 }, + }, + "gemini-4-carbon": { + ability: { low: -0.3, medium: -0.1, high: 0 }, + burn: { low: 0.65, medium: 0.59, high: 0.7 }, }, }; @@ -1379,6 +1392,12 @@ export const DEFAULT_SCORING_POLICY = { frontier: 3.5, }, ability_floor: { + routine: 2.3, + hard: 3.1, + coupled: 3.6, + frontier: 4.2, + }, + ability_score_origin: { routine: 3.0, hard: 3.3, coupled: 3.6, @@ -1387,12 +1406,15 @@ export const DEFAULT_SCORING_POLICY = { ability_span: 0.6, effort_unlock_difficulties: ["coupled", "frontier"], critical_headroom: 0.3, + critical_headroom_by_difficulty: { + frontier: 0.1, + }, effort_ability: { - low: -0.7, - medium: -0.3, + low: -0.54, + medium: -0.2, high: 0.0, - xhigh: 0.2, - max: 0.4, + xhigh: 0.15, + max: 0.3, }, effort_burn: { low: 0.2, diff --git a/packages/agentcompass/src/profiler-core.js b/packages/agentcompass/src/profiler-core.js index d01c6a6..46350fe 100644 --- a/packages/agentcompass/src/profiler-core.js +++ b/packages/agentcompass/src/profiler-core.js @@ -78,26 +78,37 @@ export const READONLY_REVIEW_PHRASES = [ ]; export const GUI_WORDS = [ - "click the", - "click save", - "take a screenshot", - "capture a screenshot", + "click", + "screenshot", " gui", "desktop app", "mouse", - "keyboard", + "点击", + "截图", + "桌面", + "鼠标", +]; + +export const COMPUTER_USE_PHRASES = [ + "click the", + "click save", + "use the mouse", + "with the mouse", + "mouse and keyboard", + "keyboard and mouse", "operate the browser", "operate the desktop", "点击", - "截取屏幕", - "截屏操作", - "桌面", - "鼠标", - "键盘", + "用鼠标", + "键鼠", + "鼠标键盘", "操作浏览器", "操作桌面", ]; +export const CODE_FILE_RE = + /[\w-]\.(?:py|pyw|ts|tsx|js|jsx|mjs|cjs|go|rs|java|kt|cs|cpp|cc|c|h|hpp|rb|php|swift|lua|sh|ps1)(?!\w)(?!\.\w)/i; + const OBJECTIVE_LOCAL_RUNTIME_RE = /\b(?:ssh|ssh-agent|vps|localhost|127\.0\.0\.1|pytest|unittest|sqlite|daemon|worktree|adb|emulator|intranet|webhook|credentials?)\b/i; @@ -243,7 +254,7 @@ export function extractRequestFacts(body, ctx = {}) { const effectivePrevUser = turnState.previousUserText || ""; const hasVisual = Boolean(turnState.hasAnyVisual); const lowerObj = ` ${String(effectiveObjective || "").toLowerCase()} `; - const hasComputerUse = GUI_WORDS.some((w) => lowerObj.includes(w)); + const hasComputerUse = !CODE_FILE_RE.test(lowerObj) && COMPUTER_USE_PHRASES.some((w) => lowerObj.includes(w)); const totalChars = sysChars + (turnState.totalChars || 0); const hasExplicitEstimatedTokens = Number.isFinite(body?.estimated_input_tokens) || @@ -290,7 +301,8 @@ export function extractRequestFacts(body, ctx = {}) { export function inferKindFromObjective(objective) { const capped = capProfileText(objective); const text = ` ${capped.toLowerCase()} `; - if (GUI_WORDS.some((w) => text.includes(w))) { + const namesCode = CODE_FILE_RE.test(text); + if (!namesCode && COMPUTER_USE_PHRASES.some((w) => text.includes(w))) { return "computer_use"; } if ( @@ -381,7 +393,7 @@ export function inferKindFromObjective(objective) { "text_in_text_out", [ "translate", - "translation", + "translation of", "draft a document", "draft documentation", "rewrite the text", @@ -526,7 +538,12 @@ export function inferKindFromObjective(objective) { ], ]; + const debugKeywords = rules.find(([k]) => k === "debug_review")?.[1] || []; + const debugging = debugKeywords.some((word) => text.includes(word)); for (const [kind, keywords] of rules) { + if (kind === "text_in_text_out" && (namesCode || debugging)) { + continue; + } if (keywords.some((w) => text.includes(w))) { return kind; } diff --git a/packages/agentcompass/test/router.test.mjs b/packages/agentcompass/test/router.test.mjs index c83e152..48e0b38 100644 --- a/packages/agentcompass/test/router.test.mjs +++ b/packages/agentcompass/test/router.test.mjs @@ -6,7 +6,7 @@ import test from "node:test"; import { fileURLToPath } from "node:url"; import { namedRoute, rankCandidates, selectBestRoute } from "../src/allocator.js"; -import { DEFAULT_SCORING_POLICY } from "../src/catalog.js"; +import { DEFAULT_SCORING_POLICY, EFFORT_CURVES } from "../src/catalog.js"; import { CACHE_COLD_MS, CHATGPT_CODEX_COLD_MS, @@ -47,7 +47,7 @@ import { onResponse as mwOnResponse, strategies, } from "../src/middleware.js"; -import { capProfileText, extractRequestFacts, inferTaskProfile, profileTask } from "../src/profiler-core.js"; +import { capProfileText, extractRequestFacts, inferKindFromObjective, inferTaskProfile, profileTask } from "../src/profiler-core.js"; import { SCORER_SYSTEM_PROMPT, clearProfileCache, parseJevScorerAnswer, scoreTaskLive } from "../src/scorer-live.js"; const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); @@ -1546,8 +1546,240 @@ test("8.6 Strict AgentCompass Main-Repo Parity (`allocator.py` + `reference-acco ); assert.equal(unlimitedDec.targetModel, "gpt-6.1-sol"); assert.equal(unlimitedDec.components.free_usage, 0.18); + + // Verify v0.3.7 + 54bb51e calibration parity: + assert.deepEqual(DEFAULT_SCORING_POLICY.ability_floor, { + routine: 2.3, + hard: 3.1, + coupled: 3.6, + frontier: 4.2, + }); + assert.deepEqual(DEFAULT_SCORING_POLICY.ability_score_origin, { + routine: 3.0, + hard: 3.3, + coupled: 3.6, + frontier: 4.2, + }); + assert.deepEqual(DEFAULT_SCORING_POLICY.critical_headroom_by_difficulty, { + frontier: 0.1, + }); + + // D (54bb51e): computer_use action phrases, CODE_FILE_RE, and translation-of narrowing + for (const prompt of [ + "Fix the keyboard shortcuts in editor.py.", + "Fix mouse event handler in app.ts", + "Fix translation.py.", + "Debug translation pipeline", + "修复翻译模块的 bug", + ]) { + assert.equal(inferKindFromObjective(prompt), "debug_review", `Expected debug_review for: ${prompt}`); + } + assert.equal(inferKindFromObjective("用鼠标点击设置里的保存"), "computer_use"); + + // A3 (54bb51e): origin = max(floor, ability_score_origin[d]) so raising floor above origin does not hand out free ability score + const raisedFloorRanked = rankCandidates( + { + work_kind: "debug_review", + reasoning_depth: 2, + code_complexity: 2, + context_scale: 1, + divergence: 1, + hallucination_risk: 2, + error_cost: 3, // critical -> uses origin-based gradient + needs_visual: false, + needs_gui: false, + local_only: true, + interaction_style: "engineering", + }, + { + candidateModels: ["claude-opus-5-5", "gpt-6.1-sol"], + catalog: { + policy: { + ...DEFAULT_SCORING_POLICY, + ability_floor: { ...DEFAULT_SCORING_POLICY.ability_floor, hard: 3.6 }, + critical_headroom: 0.0, + }, + }, + } + ); + const solHigh = raisedFloorRanked.ranking.find((c) => c.canonicalModel === "gpt-6.1-sol" && c.effort === "high"); + assert.ok(solHigh, "gpt-6.1-sol:high (ability 3.6) clears floor=3.6 when critical_headroom=0"); + assert.equal(solHigh.components.ability, 0, "Model right at raised floor (3.6 > origin 3.3) must not get free ability score"); + + // gpt-6-luna's effort curve is AgentCompass v0.3.7-v0.3.9 `effort_curves["gpt-6-luna"]` + assert.deepEqual(EFFORT_CURVES["gpt-6-luna"], { + ability: { low: -0.54, medium: -0.15, high: 0, xhigh: 0.1, max: 0.35 }, + burn: { low: 0.1, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.5 }, + }); }); +const GATE_PROFILE = { + code_complexity: 2, + context_scale: 1, + divergence: 1, + hallucination_risk: 2, + needs_visual: false, + needs_gui: false, + local_only: true, + interaction_style: "engineering", +}; + +test("8.7 Critical frontier gate is 4.3 (frontier floor 4.2 + `critical_headroom_by_difficulty.frontier` 0.1): Astra Max is admitted, Astra High is not", () => { + const ranked = rankCandidates( + { ...GATE_PROFILE, work_kind: "general_implementation", reasoning_depth: 4, code_complexity: 3, error_cost: 3 }, + { candidateModels: [{ model: "gpt-6-astra", efforts: ["high", "max"] }] }, + ); + assert.equal(ranked.task.difficulty, "frontier"); + assert.equal(ranked.task.critical, true); + const byEffort = Object.fromEntries(ranked.allCandidates.map((c) => [c.effort, c])); + assert.equal(byEffort.max.eligible, true, `Astra Max (4.3) clears the 4.3 gate: ${byEffort.max.excluded.join("; ")}`); + assert.equal(byEffort.high.eligible, false, "Astra High (4.2) is below the 4.3 gate"); + assert.match(byEffort.high.excluded.join("; "), /ability 4\.20 below the frontier floor 4\.30/); +}); + +test("8.8 tool_execution/hard uses its route floor 2.7, not the policy's hard floor 3.1", () => { + // gpt-6-luna:medium is 3.2 - 0.15 = 3.05: above the route's 2.7, below the policy's 3.1 + const rank = (workKind) => + rankCandidates( + { ...GATE_PROFILE, work_kind: workKind, reasoning_depth: 2, error_cost: 2 }, + { candidateModels: [{ model: "gpt-6-luna", efforts: ["medium"] }] }, + ); + const tool = rank("tool_execution"); + assert.equal(tool.task.kind, "tool_execution"); + assert.equal(tool.task.difficulty, "hard"); + const toolLuna = tool.allCandidates[0]; + assert.equal(toolLuna.eligible, true, `luna:medium (3.05) clears the 2.7 route floor: ${toolLuna.excluded.join("; ")}`); + + const impl = rank("general_implementation"); + assert.equal(impl.task.kind, "general_implementation"); + assert.equal(impl.task.difficulty, "hard"); + assert.match(impl.allCandidates[0].excluded.join("; "), /ability 3\.05 below the hard floor 3\.10/); +}); + +test("8.9 `ability_score_origin` above the floor decides the pick (hard: origin 3.3, floor 3.1)", () => { + // Critical hard task (error_cost 3): abilityScore = (credited - origin - (gate - floor)) / span, gate 3.4, span 0.6. + const ranked = rankCandidates( + { ...GATE_PROFILE, work_kind: "general_implementation", reasoning_depth: 2, error_cost: 3 }, + { candidateModels: [{ model: "claude-sonnet-5-5", efforts: ["xhigh"] }, { model: "gpt-6-astra", efforts: ["medium"] }] }, + ); + assert.equal(ranked.task.difficulty, "hard"); + assert.equal(ranked.task.minimum_sufficient, false); + const sonnet = ranked.allCandidates.find((c) => c.canonicalModel === "claude-sonnet-5-5"); + assert.equal(sonnet.components.ability_value, 4.3); + // Measured against origin 3.3; with origin = floor 3.1 the score is 0.333 higher and Sonnet xhigh overtakes Astra medium + assert.equal(`${ranked.selected.canonicalModel}:${ranked.selected.effort}`, "gpt-6-astra:medium"); +}); + +test("8.10 Work-kind and GUI-fact guards from AgentCompass 54bb51e (v0.3.8)", () => { + // CODE_FILE_RE guard: an action phrase about a code file is not computer use + assert.equal(inferKindFromObjective("Click the Save button handler in settings.tsx is broken"), "general_implementation"); + // Bare "keyboard" / "mouse" are not computer-use phrases + assert.equal(inferKindFromObjective("Add keyboard shortcuts to the settings dialog"), "general_implementation"); + assert.equal(inferKindFromObjective("Add mouse wheel zoom to the chart"), "general_implementation"); + // "translation of", not "translation" + assert.equal(inferKindFromObjective("Add a translation layer between the API and the DB"), "general_implementation"); + assert.equal(inferKindFromObjective("Write a translation of the README into Japanese"), "text_in_text_out"); + // A named code file skips text_in_text_out even with no debug word + assert.equal(inferKindFromObjective("Translate the error strings in i18n.ts"), "general_implementation"); + assert.equal(inferKindFromObjective("Translate the release notes into Japanese"), "text_in_text_out"); + // Phrases v0.3.8 does not have are not computer use on their own + for (const prompt of ["Take a screenshot of the report", "Capture a screenshot for the docs", "截取屏幕上的报表", "截屏操作说明"]) { + assert.notEqual(inferKindFromObjective(prompt), "computer_use", prompt); + } + + // hasComputerUse: COMPUTER_USE_PHRASES with the code-file guard, not the older GUI_WORDS + const facts = (text) => extractRequestFacts({ messages: [{ role: "user", content: text }] }, { protocol: "chat" }); + assert.equal(facts("Click the Save button in the desktop app and confirm the dialog closes").hasComputerUse, true); + assert.equal(facts("Click the Save button handler in settings.tsx is broken").hasComputerUse, false); + for (const text of ["Add keyboard shortcuts to the desktop app", "Open the gui and check the desktop app", "修改桌面版的键盘快捷键"]) { + assert.equal(facts(text).hasComputerUse, false, text); + } +}); + +test("8.11 Continuity: only a computer-use turn outgrows a model without GUI (`capability_outgrown` / `gui_capability_required`)", async () => { + const t0 = 1_700_000_000_000; + const nextTurn = async (text) => { + const store = new SessionContinuityStore(); + store.set("sess-gui", { model: "grok-4.7", effort: "medium", tokens: 4000, cached: true, healthy: true, turn: 1 }, t0); + const ctx = { + protocol: "chat", + session_id: "sess-gui", + state: {}, + options: { continuityStore: store, now: t0 + 30_000, prefer_local_heuristic: true }, + }; + await hookOnRequest({ model: "agentcompass/auto", session_id: "sess-gui", messages: [{ role: "user", content: text }] }, ctx); + return ctx.state.route; + }; + const gui = await nextTurn("Click the Save button in the desktop app and confirm the dialog closes"); + assert.equal(gui.continuation.held, false); + assert.equal(gui.continuation.why, "capability_outgrown"); + assert.equal(gui.continuation.reasonDetail, "gui_capability_required"); + assert.notEqual(gui.canonicalModel, "grok-4.7"); + // Before 0.1.2 the broader GUI words (" gui", "desktop app", "keyboard", "桌面", "键盘") also moved the session; now they hold it + for (const text of [ + "Add keyboard shortcuts to the desktop app", + "Open the gui and check the desktop app", + "修改桌面版的键盘快捷键", + "Click the Save button handler in settings.tsx is broken", + ]) { + const held = await nextTurn(text); + assert.notEqual(held.continuation.why, "capability_outgrown", text); + assert.equal(held.canonicalModel, "grok-4.7", text); + } +}); + +// AgentCompass v0.3.8 skills/agent-compass/references/accounts.json: `effort_curves` for the 13 models the plugin carries +const V038_EFFORT_CURVES = { + "deepseek-v4.1-flash-free": { ability: { high: 0, max: 0.2 }, burn: { high: 0.7, max: 0.91 } }, + "claude-opus-5-5": { + ability: { low: -0.84, medium: -0.2, high: 0, xhigh: 0.25, max: 0.35 }, + burn: { low: 0.2, medium: 0.5, high: 0.7, xhigh: 1.22, max: 2.03 }, + }, + "claude-sonnet-5-5": { + ability: { low: -0.79, medium: -0.54, high: 0, xhigh: 0.4, max: 0.64 }, + burn: { low: 0.22, medium: 0.33, high: 0.7, xhigh: 1.75, max: 4.28 }, + }, + "gpt-6-astra": { + ability: { low: -0.59, medium: -0.15, high: 0, xhigh: 0, max: 0.1 }, + burn: { low: 0.31, medium: 0.59, high: 0.7, xhigh: 0.79, max: 1.35 }, + }, + "gpt-6.1-sol": { + ability: { low: -0.74, medium: -0.2, high: 0, xhigh: 0.1, max: 0.25 }, + burn: { low: 0.19, medium: 0.43, high: 0.7, xhigh: 0.9, max: 1.51 }, + }, + "grok-4.7": { ability: { low: -0.2, high: 0, xhigh: 0 }, burn: { low: 0.33, high: 0.7, xhigh: 0.88 } }, + "gemini-3.8-flash-high": { ability: { low: -0.4, medium: -0.05, high: 0 }, burn: { medium: 0.56, high: 0.7 } }, + "gemini-4-argon-high": { ability: { low: -0.3, medium: -0.1, high: 0 }, burn: { low: 0.63, medium: 0.7, high: 0.7 } }, + "claude-haiku-5-5": { + ability: { low: -0.54, medium: -0.25, high: 0, xhigh: 0.25, max: 0.3 }, + burn: { low: 0.17, medium: 0.39, high: 0.7, xhigh: 1.09, max: 1.79 }, + }, + "gpt-6.1-terra": { + ability: { low: -0.64, medium: -0.2, high: 0, xhigh: 0.15, max: 0.45 }, + burn: { low: 0.19, medium: 0.46, high: 0.7, xhigh: 1.08, max: 2.58 }, + }, + "gpt-6-luna": { + ability: { low: -0.54, medium: -0.15, high: 0, xhigh: 0.1, max: 0.35 }, + burn: { low: 0.1, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.5 }, + }, + "claude-fable-5-1": { + ability: { low: -0.4, medium: -0.2, high: 0, xhigh: 0.15, max: 0.15 }, + burn: { low: 0.41, medium: 0.52, high: 0.7, xhigh: 1.01, max: 1.21 }, + }, + "gemini-4-carbon": { ability: { low: -0.3, medium: -0.1, high: 0 }, burn: { low: 0.65, medium: 0.59, high: 0.7 } }, +}; + +test("8.12 All 13 effort curves and `effort_ability` / `effort_burn` equal AgentCompass v0.3.8", () => { + assert.deepEqual(Object.keys(EFFORT_CURVES).sort(), Object.keys(V038_EFFORT_CURVES).sort()); + for (const [model, curve] of Object.entries(V038_EFFORT_CURVES)) { + assert.deepEqual(EFFORT_CURVES[model].ability, curve.ability, `${model} ability`); + assert.deepEqual(EFFORT_CURVES[model].burn, curve.burn, `${model} burn`); + } + // scoring.effort_ability / scoring.effort_burn + assert.deepEqual(DEFAULT_SCORING_POLICY.effort_ability, { low: -0.54, medium: -0.2, high: 0, xhigh: 0.15, max: 0.3 }); + assert.deepEqual(DEFAULT_SCORING_POLICY.effort_burn, { low: 0.2, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.3 }); +}); + test("9.1 PR #670 Review Guard: Default triggers ONLY claim `agentcompass` / `agentcompass/*` and never hijack `auto` or `group/intent`", async () => { for (const nonOwnedModel of ["auto", "intent", "group/intent", "default", "claude-sonnet-4-6"]) { const req = {