Multiplayer agent harness for work.
Add claude-opus-5-5 and harden preserved-thinking replay for adaptive Anthropic models (#1536)
Regan Bella0b9706604e4
diff --git a/package-lock.json b/package-lock.jsonindex f103220c4..461690102 100644--- a/package-lock.json+++ b/package-lock.json@@ -9,7 +9,7 @@"version": "0.1.0","license": "MIT","dependencies": {- "@anthropic-ai/claude-agent-sdk": "0.3.211",+ "@anthropic-ai/claude-agent-sdk": "0.3.280","@anthropic-ai/tokenizer": "^0.0.4","@aws-crypto/sha256-js": "^5.2.0","@aws-sdk/client-ecs": "3.1096.0",@@ -99,22 +99,22 @@}},"node_modules/@anthropic-ai/claude-agent-sdk": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk/-/claude-agent-sdk-0.3.211.tgz",- "integrity": "sha512-JhbLu6o1v2g9fjqkO+LDNPWrE0bgd9UeRQQ41JBGouAgows3KyPPYgU2WU0q7M2onuwQxR5plGDpas01F+oaUA==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk/-/claude-agent-sdk-0.3.280.tgz",+ "integrity": "sha512-aIQSTKcCJcOgi125GAGQaNZUYgxbEBQwV2Ac+Utp0+gGUjIEWjTqz4B8kXr9XjkcCTYiRUMTDsXPAUfIcBDjnw==","license": "SEE LICENSE IN README.md","engines": {"node": ">=18.0.0"},"optionalDependencies": {- "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.211",- "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.211",- "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.211",- "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.211",- "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.211",- "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.211",- "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.211",- "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.211"+ "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.280",+ "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.280"},"peerDependencies": {"@anthropic-ai/sdk": ">=0.93.0",@@ -123,9 +123,9 @@}},"node_modules/@anthropic-ai/claude-agent-sdk-darwin-arm64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-arm64/-/claude-agent-sdk-darwin-arm64-0.3.211.tgz",- "integrity": "sha512-Iwhm4kfcs20LdXffZ2RGRjj+BFdUOrT/JjhGtICjlGlBPlrLkkkAiHtGzqO9K36v5B/kSIHwOw9CM836kYYPHQ==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-arm64/-/claude-agent-sdk-darwin-arm64-0.3.280.tgz",+ "integrity": "sha512-Yws14X5g5hgDtF565Tld/+dILAhH9QZpundjKMyO3dFasq9miXZlhU0NwXqwTO2xP0jDjJ54zduIiJwkcfcvGw==","cpu": ["arm64"],@@ -136,9 +136,9 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-darwin-x64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-x64/-/claude-agent-sdk-darwin-x64-0.3.211.tgz",- "integrity": "sha512-sMBW1CLe2Hq4PwwvEbz9r8LxF84UErgB45TSf+iEa8M/EjYZCsXSoTRT0vKnN4TvrAN5mWoKgi39dkUxS9ybsA==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-x64/-/claude-agent-sdk-darwin-x64-0.3.280.tgz",+ "integrity": "sha512-B1eLx/oZ5RL1c3a13nQ4cRUksWyhGcVNS5vbCHnOVu4Pz+dH0moZ+iY8VaE6FvikVAQwFEW6VDU00b6m3tYdsQ==","cpu": ["x64"],@@ -149,12 +149,15 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-linux-arm64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64/-/claude-agent-sdk-linux-arm64-0.3.211.tgz",- "integrity": "sha512-orZm8p+BzVRZ7I8c5yD43hEZ5TvBZ+UbKTZTlvID00Y8HSn3M3rNX3sW4RUvNGF2e0eNMaXKysPyEHPEj3kqpg==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64/-/claude-agent-sdk-linux-arm64-0.3.280.tgz",+ "integrity": "sha512-6s96OIvBHT2817hCFLIZ421JBpQnvrmZucpjlWsyCODKmwGsSxiEhlWqK2h5Q7lwS6F7bzeAhqjGvC7FzDl9Rw==","cpu": ["arm64"],+ "libc": [+ "glibc"+ ],"license": "SEE LICENSE IN LICENSE.md","optional": true,"os": [@@ -162,12 +165,15 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-linux-arm64-musl": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64-musl/-/claude-agent-sdk-linux-arm64-musl-0.3.211.tgz",- "integrity": "sha512-X1eg+lCwNH2VXyqLQR722dsDDtWPfUnz7OtnmPVoNMxcMexDlSLMMuvm5fNNi94kYT0pxmBdhIvudew145JuHg==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64-musl/-/claude-agent-sdk-linux-arm64-musl-0.3.280.tgz",+ "integrity": "sha512-uDh+Ggjb36l+jcVgaYxSziGHmBSSR3clqvGlQ0Bgc1v5dLF4igwqZ6ZPW/hS9dArG27fislIOetH1waEgIr+GA==","cpu": ["arm64"],+ "libc": [+ "musl"+ ],"license": "SEE LICENSE IN LICENSE.md","optional": true,"os": [@@ -175,12 +181,15 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-linux-x64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64/-/claude-agent-sdk-linux-x64-0.3.211.tgz",- "integrity": "sha512-ohDS5EGKQvKiUUMtDNPjyWUDvaeIa+DlzUVjrZ8Y4hPtoWFpvOBtOFIYChJGpllwZ4YULS4H3gywVnLGB4do6Q==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64/-/claude-agent-sdk-linux-x64-0.3.280.tgz",+ "integrity": "sha512-vpPyxYLy+zNc7LwQDWsZf0GZtTYa0PJLxzuv2vK9iV2dG+hrbRNTl35NSKKRR9rMj6RpKz0i2NLyVQ+D4mREgw==","cpu": ["x64"],+ "libc": [+ "glibc"+ ],"license": "SEE LICENSE IN LICENSE.md","optional": true,"os": [@@ -188,12 +197,15 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-linux-x64-musl": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64-musl/-/claude-agent-sdk-linux-x64-musl-0.3.211.tgz",- "integrity": "sha512-cR12YFMVGSj38074OYkkjgwhYeblgVRK3Uw7ZXw3ZTOevjQLASPajVruFuDRW07ixxTa1ZWxqI3kSsIl71RXYA==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64-musl/-/claude-agent-sdk-linux-x64-musl-0.3.280.tgz",+ "integrity": "sha512-IVbIgvi5C0sdLg/p9hpiVvAQ/ikvTKwOOEy5C1aT7w8XLqBgfpJbzzVuk06df1Q0HlILUmf63EKPmq48lbxtqA==","cpu": ["x64"],+ "libc": [+ "musl"+ ],"license": "SEE LICENSE IN LICENSE.md","optional": true,"os": [@@ -201,9 +213,9 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-win32-arm64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-arm64/-/claude-agent-sdk-win32-arm64-0.3.211.tgz",- "integrity": "sha512-AOIQRFO0YMDUCrG8W0NUWitBQQUB6fYdNW3SMcPPq3mXpYC/pCNURFyvRdrFm729xXkxDAP5OMLk9x2/IFrTmA==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-arm64/-/claude-agent-sdk-win32-arm64-0.3.280.tgz",+ "integrity": "sha512-heTflHwciJF+Hrf7v0J53QBzD+9mxN9gt2VVmEJAN0+ejbPcOcqnGGZHvyc9aZUuGh5INN0ECaiL4Fn1X2vXQQ==","cpu": ["arm64"],@@ -214,9 +226,9 @@]},"node_modules/@anthropic-ai/claude-agent-sdk-win32-x64": {- "version": "0.3.211",- "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-x64/-/claude-agent-sdk-win32-x64-0.3.211.tgz",- "integrity": "sha512-pwzNuJg2xRBsv3kSSVVhgLdGAFxd5DqPkQX5ZLrT4uBZDJ+QM4xWKZyN8ZoFLLzNl+u0/4U83Q1ZQ0NdG/9JsQ==",+ "version": "0.3.280",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-x64/-/claude-agent-sdk-win32-x64-0.3.280.tgz",+ "integrity": "sha512-N+Y1zJb19nx0oPTvzkl/E3ng9AtWGW+K4hySmSHCgYSsgIwfs1YzDj/F5eHDMrxgklTuzFp76TvL3S75z5ge+g==","cpu": ["x64"],diff --git a/package.json b/package.jsonindex 07dec9908..342a9f2dd 100644--- a/package.json+++ b/package.json@@ -64,7 +64,7 @@"*": "prettier --write --ignore-unknown"},"dependencies": {- "@anthropic-ai/claude-agent-sdk": "0.3.211",+ "@anthropic-ai/claude-agent-sdk": "0.3.280","@anthropic-ai/tokenizer": "^0.0.4","@aws-crypto/sha256-js": "^5.2.0","@aws-sdk/client-ecs": "3.1096.0",diff --git a/src/harness/pi-harness.ts b/src/harness/pi-harness.tsindex 4b3b94740..8b642ac51 100644--- a/src/harness/pi-harness.ts+++ b/src/harness/pi-harness.ts@@ -1221,9 +1221,16 @@ export async function buildModelRuntime(if (!request) {const providerModelId =model.provider === CODEX_SUBSCRIPTION_PROVIDER ? codexProviderModelId(model.id) : model.id;- const passthrough = retained(options);+ const candidate = withRequestHeaders(model, true, false);+ const passthrough = {+ ...retained(options),+ onPayload: async (payload: unknown) => {+ const transformed = options?.onPayload ? await options.onPayload(payload, model) : undefined;+ return applyThinkingBinding(transformed === undefined ? payload : transformed, candidate);+ },+ } as T;return {- model,+ model: candidate,options:providerModelId === model.id ? passthrough : wireModelId(passthrough, model, async () => providerModelId),};@@ -1317,8 +1324,7 @@ export async function probeModel(): Promise<void> {const runtime = await buildModelRuntime(keys, modelGateway);signal.throwIfAborted();- const fastHeader = fastMode && !modelGateway?.models[model.id];- const candidate = fastHeader ? withFastModeHeaders(model) : model;+ const candidate = withRequestHeaders(model, !modelGateway?.models[model.id], fastMode);const response = await runtime.streamSimple(candidate,@@ -1347,6 +1353,8 @@ export async function probeModel(}const FAST_MODE_BETA = "fast-mode-2026-02-01";+const THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";+const THINKING_BINDING = { prefix_mismatch_behavior: "drop_block" } as const;export const FAST_COST_MULTIPLIER = 2;@@ -1366,6 +1374,28 @@ export function wantsFastMode(fastMode: boolean | undefined, modelId: string | ureturn fastMode === true && modelSupportsFastMode(modelId);}+function thinkingBindingApplies(model: Pick<Model<Api>, "api" | "compat"> | undefined): boolean {+ return (+ model?.api === "anthropic-messages" &&+ (model.compat as { forceAdaptiveThinking?: unknown } | undefined)?.forceAdaptiveThinking === true+ );+}++export function applyThinkingBinding<T>(+ payload: T,+ model: (Pick<Model<Api>, "headers"> & Partial<Pick<Model<Api>, "thinkingLevelMap">>) | undefined,+): T {+ if (!payload || typeof payload !== "object") return payload;+ if (!model?.headers?.["anthropic-beta"]?.split(",").includes(THINKING_BINDING_BETA)) return payload;+ const thinking =+ (payload as { thinking?: { type?: unknown } }).thinking ??+ (model.thinkingLevelMap?.off === null ? { type: "adaptive", display: "summarized" } : undefined);+ if (thinking?.type === "adaptive" || thinking?.type === "enabled") {+ (payload as Record<string, unknown>).thinking = { ...thinking, block_binding: THINKING_BINDING };+ }+ return payload;+}+export function applyFastSpeed<T>(payload: T, fast: boolean | undefined, api?: string): T {if (fast && payload && typeof payload === "object") {if (api && api.toLowerCase().startsWith("openai")) {@@ -1444,12 +1474,13 @@ export function resolveConfiguredModelId(configured: string | undefined, defaultreturn DEFAULT_AGENT_MODEL_ID;}-export function withFastModeHeaders(model: Model<Api>): Model<Api> {+export function withRequestHeaders(model: Model<Api>, direct: boolean, fast: boolean): Model<Api> {const api = String((model as { api?: unknown }).api ?? "").toLowerCase();- if (api.startsWith("openai")) return model;+ if (api.startsWith("openai") || !direct) return model;+ const betas = [...(thinkingBindingApplies(model) ? [THINKING_BINDING_BETA] : []), ...(fast ? [FAST_MODE_BETA] : [])];+ if (!betas.length) return model;const prior = model.headers?.["anthropic-beta"];- const beta = prior ? `${prior},${FAST_MODE_BETA}` : FAST_MODE_BETA;-+ const beta = [...new Set([...(prior ? prior.split(",").map((value) => value.trim()) : []), ...betas])].join(",");return { ...model, headers: { ...model.headers, "anthropic-beta": beta } };}@@ -1741,9 +1772,8 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {const baseModel = getRequiredModel(desiredModelId, !turn.providerKeys);const turnModelGateway = turn.providerKeys ? undefined : modelGateway;const wantFast = wantsFastMode(turn.runtime?.fastMode, desiredModelId);- const wantFastHeader = wantFast && !turnModelGateway?.models[desiredModelId];const { entry, compileMs } = await createTurnSession(- wantFastHeader ? withFastModeHeaders(baseModel) : baseModel,+ withRequestHeaders(baseModel, !turnModelGateway?.models[desiredModelId], wantFast),turn.session.id,turn.systemPrompt,turn.history,@@ -2175,8 +2205,9 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {`[pi] provider refusal — retrying on fallback model ${fromId} -> ${fallbackId} session=${turn.session.id}: ${refusal}`,);const wantFast = wantsFastMode(turn.runtime?.fastMode, fallbackId);- const wantFastHeader = wantFast && !turnModelGateway?.models[fallbackId];- await entry.agentSession.setModel(wantFastHeader ? withFastModeHeaders(fallback) : fallback);+ await entry.agentSession.setModel(+ withRequestHeaders(fallback, !turnModelGateway?.models[fallbackId], wantFast),+ );entry.ref.fast = wantFast;applyTurnEffort(entry.agentSession, turn.runtime?.effortLevel ?? defaultInteractiveThinkingLevel(fallback));const state = entry.agentSession.agent.state;diff --git a/src/harness/tape-fold.ts b/src/harness/tape-fold.tsindex 1df3264b6..d1ffe210b 100644--- a/src/harness/tape-fold.ts+++ b/src/harness/tape-fold.ts@@ -212,6 +212,14 @@ function healDanglingCalls(out: unknown[], at: number): void {}}+function withoutThinking(messages: readonly unknown[]): unknown[] {+ return messages.map((m) => {+ const msg = m as { role?: unknown; content?: unknown };+ if (msg?.role !== "assistant" || !Array.isArray(msg.content)) return m;+ return { ...msg, content: msg.content.filter((b) => (b as { type?: unknown } | null)?.type !== "thinking") };+ });+}+export function foldTape(rows: readonly TapeRecord[]): unknown[] {const f: Foldable = { out: [], boundaries: [] };for (const row of rows) {@@ -234,7 +242,7 @@ export function foldTape(rows: readonly TapeRecord[]): unknown[] {row.coversEntrySeq !== undefined? [...f.boundaries].reverse().find((b) => b.entrySeq <= row.coversEntrySeq!): undefined;- const kept = cut ? f.out.slice(cut.pos) : [...f.out];+ const kept = withoutThinking(cut ? f.out.slice(cut.pos) : f.out);f.out = [{role: "user",diff --git a/src/model/pi-models.ts b/src/model/pi-models.tsindex 2366f61db..a44616ec2 100644--- a/src/model/pi-models.ts+++ b/src/model/pi-models.ts@@ -68,6 +68,7 @@ interface ModelEntry {cacheWrite?: number;contextWindow: number;maxTokens: number;+ thinkingLevelMap?: PiModel["thinkingLevelMap"];tiers?: ReadonlyArray<{inputTokensAbove: number;@@ -82,6 +83,23 @@ interface ModelEntry {const GPT_56_CLONE = { template: "gpt-5.5", contextWindow: 1_050_000, maxTokens: 128_000 } as const;export const MODEL_REGISTRY: readonly ModelEntry[] = [+ {+ id: "claude-opus-5-5",+ name: "Claude Opus 5.5",+ fastMode: true,+ webui: true,+ base: true,+ clone: {+ template: "claude-opus-4-8",+ thinkingLevelMap: { off: null },+ input: 4,+ output: 20,+ cacheRead: 0.2,+ cacheWrite: 5,+ contextWindow: 1_000_000,+ maxTokens: 128_000,+ },+ },{id: "claude-fable-5-1",name: "Claude Fable 5.1",@@ -335,7 +353,9 @@ function cloneModel(model: PiModel, id: string, name: string, overrides: Partialinput: [...model.input],cost: structuredClone(overrides.cost ?? model.cost),...(model.headers ? { headers: { ...model.headers } } : {}),- ...(model.thinkingLevelMap ? { thinkingLevelMap: { ...model.thinkingLevelMap } } : {}),+ ...(model.thinkingLevelMap || overrides.thinkingLevelMap+ ? { thinkingLevelMap: { ...model.thinkingLevelMap, ...overrides.thinkingLevelMap } }+ : {}),...(model.compat ? { compat: { ...(model.compat as Record<string, unknown>) } as PiModel["compat"] } : {}),};}@@ -383,6 +403,7 @@ export function resolveBuiltinModel(id: string): PiModel | undefined {? cloneModel(template, id, entry.name, {contextWindow: entry.clone.contextWindow,maxTokens: entry.clone.maxTokens,+ ...(entry.clone.thinkingLevelMap ? { thinkingLevelMap: entry.clone.thinkingLevelMap } : {}),cost: {input: entry.clone.input,output: entry.clone.output,diff --git a/test/model-credential-route.test.ts b/test/model-credential-route.test.tsindex e49ec9f78..d9d58a1df 100644--- a/test/model-credential-route.test.ts+++ b/test/model-credential-route.test.ts@@ -59,6 +59,7 @@ test("admin model credentials are encrypted, write-only, live, and removable", a{ provider: "openrouter", configured: false, source: "absent" },],models: [+ { id: "claude-opus-5-5", name: "Claude Opus 5.5", provider: "anthropic" },{ id: "claude-fable-5-1", name: "Claude Fable 5.1", provider: "anthropic" },{ id: "claude-fable-5", name: "Claude Fable 5", provider: "anthropic" },{ id: "claude-opus-5", name: "Claude Opus 5", provider: "anthropic" },diff --git a/test/model-registry.test.ts b/test/model-registry.test.tsindex 2dfe51ba3..b6a0ad186 100644--- a/test/model-registry.test.ts+++ b/test/model-registry.test.ts@@ -7,6 +7,9 @@ import {FAST_MODE_MODEL_IDS,resolveModel,modelSupportsFastMode,+ modelSupportedByHarness,+ defaultModelForHarness,+ safeModelMetadata,modelServiceable,serviceableModelIds,modelProviderAvailabilityFor,@@ -71,6 +74,50 @@ test("gpt-6-astra is offered with its published context, output ceiling, and ratassert.equal(validateWebTurnModelOptions({ model: "gpt-6-astra" }, null), null);});+test("Opus 5.5 inherits adaptive thinking without off, with its own rates and limits", () => {+ const model = resolveModel("claude-opus-5-5");+ assert.ok(model);+ assert.equal(model.provider, "anthropic");+ assert.equal(model.api, "anthropic-messages");+ assert.equal(model.reasoning, true);+ assert.deepEqual(model.input, ["text", "image"]);+ assert.equal(model.contextWindow, 1_000_000);+ assert.equal(model.maxTokens, 128_000);+ assert.deepEqual(model.cost, { input: 4, output: 20, cacheRead: 0.2, cacheWrite: 5, tiers: undefined });+ assert.deepEqual(model.thinkingLevelMap, { xhigh: "xhigh", max: "max", off: null });+ assert.deepEqual(model.compat, {+ forceAdaptiveThinking: true,+ supportsTemperature: false,+ supportsStrictTools: true,+ });+ assert.equal(resolveModel("claude-opus-4-8")?.thinkingLevelMap?.off, undefined);+ assert.equal(resolveModel("claude-opus-5")?.thinkingLevelMap?.off, undefined);+ model.thinkingLevelMap!.xhigh = "high";+ assert.equal(resolveModel("claude-opus-5-5")?.thinkingLevelMap?.xhigh, "xhigh");+ assert.equal(resolveModel("claude-opus-4-8")?.thinkingLevelMap?.xhigh, "xhigh");+});++test("Opus 5.5 is selectable with compatible harnesses and credentials, without changing defaults", () => {+ const id = "claude-opus-5-5";+ assert.ok(SELECTABLE_BASE_MODELS.some((model) => model.id === id));+ assert.ok(DEFAULT_WEBUI_MODEL_IDS.includes(id));+ assert.ok(FAST_MODE_MODEL_IDS.includes(id));+ assert.equal(safeModelMetadata(id)?.label, "Opus 5.5");+ for (const harness of ["pi", "claude", "opencode", "mock"]) {+ assert.equal(modelSupportedByHarness(id, harness), true);+ assert.equal(defaultModelForHarness(harness), "claude-opus-5");+ }+ assert.equal(modelSupportedByHarness(id, "codex"), false);+ assert.match(+ validateWebTurnModelOptions({ model: id }, null, { anthropic: false, openai: true, openrouter: false }) ?? "",+ /provider isn't configured/,+ );+ assert.equal(+ validateWebTurnModelOptions({ model: id }, null, { anthropic: true, openai: false, openrouter: false }),+ null,+ );+});+test("FAST_MODE_MODEL_IDS derives from the registry — the web-ui client reads this, keeps no copy", () => {assert.deepEqual([...FAST_MODE_MODEL_IDS].sort(),diff --git a/test/pi-harness-fast-mode.test.ts b/test/pi-harness-fast-mode.test.tsindex 8e4036dbb..dabbbf73a 100644--- a/test/pi-harness-fast-mode.test.ts+++ b/test/pi-harness-fast-mode.test.ts@@ -3,9 +3,10 @@ import assert from "node:assert/strict";import {applyTurnEffort,applyFastSpeed,+ applyThinkingBinding,piUsageToCallUsage,scaleCost,- withFastModeHeaders,+ withRequestHeaders,FAST_COST_MULTIPLIER,modelSupportsFastMode,wantsFastMode,@@ -18,7 +19,7 @@ import type { Api, Model, Usage } from "@earendil-works/pi-ai";import { defaultInteractiveThinkingLevel, getRequiredModel } from "../src/model/pi-models.ts";test("modelSupportsFastMode allows only the documented direct Opus ids", () => {- for (const id of ["claude-opus-5", "claude-opus-4-8"]) {+ for (const id of ["claude-opus-5-5", "claude-opus-5", "claude-opus-4-8"]) {assert.equal(modelSupportsFastMode(id), true, `${id} should support fast mode`);}for (const id of [@@ -102,6 +103,7 @@ test("auto resets a reused Anthropic session to its interactive default", () =>});const ASTRA = getRequiredModel("gpt-6-astra", false) as Model<Api>;+const OPUS_55 = getRequiredModel("claude-opus-5-5", false);const OPUS = getRequiredModel("claude-opus-5", false) as Model<Api>;const ASTRA_TOKENS = { input: 10_000, output: 2_000, cacheRead: 50_000, cacheWrite: 4_000, totalTokens: 66_000 };@@ -121,6 +123,14 @@ const pricingCases: Array<[string, Model<Api>, Partial<Usage>, number]> = [{ input: 10_000, output: 1_000, cacheRead: 40_000, cacheWrite: 16_000, cacheWrite1h: 8_000 },0.225,],+ [+ "Opus 5.5 mixed tokens and cache durations",+ OPUS_55,+ { input: 10_000, output: 1_000, cacheRead: 40_000, cacheWrite: 16_000, cacheWrite1h: 8_000 },+ 0.172,+ ],+ ["Opus 5.5 cache reads", OPUS_55, { cacheRead: 100_000 }, 0.02],+ ["Opus 5.5 1h writes", OPUS_55, { cacheWrite: 4_000, cacheWrite1h: 4_000 }, 0.032],["all 1h writes", OPUS, { cacheWrite: 4_000, cacheWrite1h: 4_000 }, 0.04],["clamped 1h writes", OPUS, { cacheWrite: 4_000, cacheWrite1h: 40_000 }, 0.04],];@@ -155,17 +165,62 @@ test("normalization ignores provider pricing, preserves tokens and never mutatesassert.deepEqual(ASTRA.cost, card);});-test("fast headers preserve rates and existing beta headers", () => {- for (const model of [ASTRA, OPUS]) {+const HAIKU = getRequiredModel("claude-haiku-4-5", false) as Model<Api>;+const BINDING_BETA = "thinking-binding-controls-2026-08-01";++test("request headers preserve rates and existing beta headers", () => {+ for (const model of [ASTRA, OPUS, OPUS_55]) {const snapshot = structuredClone(model);- assert.deepEqual(withFastModeHeaders(model).cost, snapshot.cost);+ assert.deepEqual(withRequestHeaders(model, true, true).cost, snapshot.cost);assert.deepEqual(model, snapshot);}- assert.equal(withFastModeHeaders(OPUS).headers?.["anthropic-beta"], "fast-mode-2026-02-01");assert.equal(- withFastModeHeaders({ ...OPUS, headers: { "anthropic-beta": "prior-beta" } }).headers?.["anthropic-beta"],- "prior-beta,fast-mode-2026-02-01",+ withRequestHeaders(OPUS, true, true).headers?.["anthropic-beta"],+ `${BINDING_BETA},fast-mode-2026-02-01`,);+ assert.equal(+ withRequestHeaders({ ...OPUS, headers: { "anthropic-beta": "prior-beta" } }, true, true).headers?.[+ "anthropic-beta"+ ],+ `prior-beta,${BINDING_BETA},fast-mode-2026-02-01`,+ );+});++test("direct adaptive-thinking Claude requests opt into thinking binding controls", () => {+ assert.equal(withRequestHeaders(OPUS, true, false).headers?.["anthropic-beta"], BINDING_BETA);+ assert.equal(withRequestHeaders(OPUS, false, true).headers?.["anthropic-beta"], undefined);+ assert.equal(withRequestHeaders(ASTRA, true, false).headers?.["anthropic-beta"], undefined);+ assert.equal(withRequestHeaders(HAIKU, true, false).headers?.["anthropic-beta"], undefined);+ assert.equal(withRequestHeaders(HAIKU, true, true).headers?.["anthropic-beta"], "fast-mode-2026-02-01");+});++test("applyThinkingBinding sets drop_block only on requests that carry the beta header", () => {+ const bound = withRequestHeaders(OPUS, true, true);+ const adaptive = { thinking: { type: "adaptive", display: "summarized" } } as Record<string, unknown>;+ assert.equal(applyThinkingBinding(adaptive, bound), adaptive);+ assert.deepEqual(adaptive.thinking, {+ type: "adaptive",+ display: "summarized",+ block_binding: { prefix_mismatch_behavior: "drop_block" },+ });+ const budget = { thinking: { type: "enabled", budget_tokens: 2048 } } as Record<string, unknown>;+ applyThinkingBinding(budget, bound);+ assert.deepEqual(budget.thinking, {+ type: "enabled",+ budget_tokens: 2048,+ block_binding: { prefix_mismatch_behavior: "drop_block" },+ });+ const disabled = { thinking: { type: "disabled" } } as Record<string, unknown>;+ applyThinkingBinding(disabled, bound);+ assert.deepEqual(disabled.thinking, { type: "disabled" });+ const unbound = { thinking: { type: "adaptive" } } as Record<string, unknown>;+ applyThinkingBinding(unbound, OPUS);+ applyThinkingBinding(unbound, withRequestHeaders(HAIKU, true, true));+ assert.deepEqual(unbound.thinking, { type: "adaptive" });+ const none = { messages: [] } as Record<string, unknown>;+ applyThinkingBinding(none, bound);+ assert.equal("thinking" in none, false);+ assert.doesNotThrow(() => applyThinkingBinding(undefined, bound));});test("normalization handles absent usage, missing token fields and an unknown model", () => {@@ -258,9 +313,10 @@ async function runTurn(fastMode: boolean,respond: (payload: Record<string, unknown>, index: number) => Response,gateway = false,-): Promise<{ rows: HarnessLlmRequestRecord[]; payloads: Array<Record<string, unknown>> }> {+): Promise<{ rows: HarnessLlmRequestRecord[]; payloads: Array<Record<string, unknown>>; betas: Array<string | null> }> {const rows: HarnessLlmRequestRecord[] = [];const payloads: Array<Record<string, unknown>> = [];+ const betas: Array<string | null> = [];const harness = createPiHarness({apiKey: "sk-anthropic-test",openaiApiKey: "sk-openai-test",@@ -270,7 +326,7 @@ async function runTurn(url: "https://gateway.example/v1",apiKey: "sk-gateway-test",apiKeyHeader: "x-gateway-key",- models: { "gpt-6-astra": "openai/gpt-6-astra" },+ models: { "gpt-6-astra": "openai/gpt-6-astra", "claude-sonnet-5": "anthropic/claude-sonnet-5" },},}: {}),@@ -279,6 +335,7 @@ async function runTurn(globalThis.fetch = (async (_url: string | URL | Request, init?: RequestInit) => {const payload = JSON.parse(String(init?.body ?? "{}")) as Record<string, unknown>;payloads.push(payload);+ betas.push(new Headers(init?.headers).get("anthropic-beta"));return respond(payload, payloads.length - 1);}) as typeof globalThis.fetch;let seq = 0;@@ -302,7 +359,7 @@ async function runTurn(} finally {globalThis.fetch = realFetch;}- return { rows, payloads };+ return { rows, payloads, betas };}for (const [name, gateway, fastMode, expected, echoedTier] of [@@ -335,15 +392,33 @@ for (const [name, gateway, fastMode, expected, echoedTier] of [}test("an unsupported fast-mode request records the standard price", async () => {- const { rows, payloads } = await runTurn("sonnet-fast-ineligible", "claude-sonnet-5", true, () =>+ const { rows, payloads, betas } = await runTurn("sonnet-fast-ineligible", "claude-sonnet-5", true, () =>anthropicReply("standard", ANTHROPIC_WIRE_USAGE),);assert.equal(payloads.length, 1);assert.equal("speed" in payloads[0]!, false);+ assert.equal(betas[0], BINDING_BETA);+ assert.deepEqual((payloads[0]!.thinking as { block_binding?: unknown }).block_binding, {+ prefix_mismatch_behavior: "drop_block",+ });assert.equal(rows.length, 1);assertUsd(rows[0]!.usage!.costUsd, 0.03);});+test("gateway-routed Claude requests carry neither the binding beta nor block_binding", async () => {+ const { payloads, betas } = await runTurn(+ "sonnet-gateway-unbound",+ "claude-sonnet-5",+ false,+ () => anthropicReply("routed", ANTHROPIC_WIRE_USAGE),+ true,+ );+ assert.equal(payloads.length, 1);+ assert.equal(payloads[0]?.model, "anthropic/claude-sonnet-5");+ assert.equal(betas[0]?.includes(BINDING_BETA) ?? false, false);+ assert.equal("block_binding" in (payloads[0]!.thinking as object), false);+});+test("a refusal fallback prices each step on its actual model and tier", async () => {const { rows, payloads } = await runTurn("refusal-fallback-pricing", "claude-sonnet-5", true, (_payload, index) =>index === 0diff --git a/test/pi-models.test.ts b/test/pi-models.test.tsindex 38f9f9781..3820bcf93 100644--- a/test/pi-models.test.ts+++ b/test/pi-models.test.ts@@ -104,6 +104,7 @@ test("the curated catalog contains only current model families", () => {assert.deepEqual(SELECTABLE_BASE_MODELS.map((model) => model.id),[+ "claude-opus-5-5","claude-fable-5-1","claude-fable-5","claude-opus-5",diff --git a/test/pi-opus-55.test.ts b/test/pi-opus-55.test.tsnew file mode 100644index 000000000..4cc5d5519--- /dev/null+++ b/test/pi-opus-55.test.ts@@ -0,0 +1,97 @@+import assert from "node:assert/strict";+import { test } from "node:test";+import { buildModelRuntime, probeModel } from "../src/harness/pi-harness.ts";+import { getRequiredModel } from "../src/model/pi-models.ts";++const bindingBeta = "thinking-binding-controls-2026-08-01";+const context = { messages: [{ role: "user" as const, content: "Reply OK.", timestamp: 0 }] };++test("Opus 5.5 wire requests preserve mandatory thinking, caller hooks and beta headers across Pi entry points", async (t) => {+ const originalFetch = globalThis.fetch;+ t.after(() => {+ globalThis.fetch = originalFetch;+ });+ const requests: Array<{ headers: Headers; body: Record<string, unknown> }> = [];+ globalThis.fetch = (async (_url: string | URL | Request, init?: RequestInit) => {+ requests.push({ headers: new Headers(init?.headers), body: JSON.parse(String(init?.body)) });+ const events = [+ {+ type: "message_start",+ message: {+ id: "msg_test",+ type: "message",+ role: "assistant",+ model: "claude-opus-5-5",+ content: [],+ usage: { input_tokens: 1, output_tokens: 0 },+ },+ },+ { type: "content_block_start", index: 0, content_block: { type: "text", text: "" } },+ { type: "content_block_delta", index: 0, delta: { type: "text_delta", text: "OK" } },+ { type: "content_block_stop", index: 0 },+ { type: "message_delta", delta: { stop_reason: "end_turn", stop_sequence: null }, usage: { output_tokens: 1 } },+ { type: "message_stop" },+ ];+ return new Response(events.map((event) => `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`).join(""), {+ headers: { "content-type": "text/event-stream" },+ });+ }) as typeof fetch;+ const model = { ...getRequiredModel("claude-opus-5-5", false), headers: { "anthropic-beta": "prior-beta" } };+ const runtime = await buildModelRuntime({ anthropic: "sk-offline-test-key" });+ for (const effort of [undefined, "low", "xhigh", "max"] as const) {+ const response = await runtime+ .streamSimple(model, context, {+ reasoning: effort,+ maxRetries: 0,+ onPayload: (payload) => ({ ...(payload as object), metadata: { user_id: "caller-hook" } }),+ })+ .result();+ assert.equal(response.stopReason, "stop", response.errorMessage);+ const request = requests.at(-1)!;+ assert.ok(request.headers.get("anthropic-beta")?.includes("prior-beta"));+ assert.ok(request.headers.get("anthropic-beta")?.includes(bindingBeta));+ assert.deepEqual(request.body.thinking, {+ type: "adaptive",+ display: "summarized",+ block_binding: { prefix_mismatch_behavior: "drop_block" },+ });+ assert.deepEqual(request.body.metadata, { user_id: "caller-hook" });+ if (effort) assert.deepEqual(request.body.output_config, { effort });+ }+ const streamed = await runtime.stream(model, context, { maxRetries: 0 }).result();+ assert.equal(streamed.stopReason, "stop", streamed.errorMessage);+ assert.deepEqual(requests.at(-1)!.body.thinking, {+ type: "adaptive",+ display: "summarized",+ block_binding: { prefix_mismatch_behavior: "drop_block" },+ });+ await probeModel(model, { anthropic: "sk-offline-test-key" }, AbortSignal.timeout(10_000), true);+ assert.equal(requests.at(-1)!.body.speed, "fast");+ const betas = requests.at(-1)!.headers.get("anthropic-beta")!.split(",");+ assert.equal(betas.filter((beta) => beta === bindingBeta).length, 1);+ assert.ok(betas.includes("fast-mode-2026-02-01"));+ assert.deepEqual(model.headers, { "anthropic-beta": "prior-beta" });++ const gateway = await buildModelRuntime(+ {},+ {+ url: "https://gateway.invalid",+ apiKey: "test-gateway-key",+ apiKeyHeader: "x-test-key",+ models: { [model.id]: "routed-opus" },+ },+ );+ await gateway.streamSimple(model, context, { reasoning: "low", maxRetries: 0 }).result();+ const routed = requests.at(-1)!;+ assert.equal(routed.body.model, "routed-opus");+ assert.equal(routed.headers.get("x-test-key"), "test-gateway-key");+ assert.ok(!routed.headers.get("anthropic-beta")?.includes(bindingBeta));+ assert.deepEqual(routed.body.thinking, { type: "adaptive", display: "summarized" });++ await runtime+ .streamSimple(getRequiredModel("claude-haiku-4-5", false), context, { reasoning: "low", maxRetries: 0 })+ .result();+ const haiku = requests.at(-1)!;+ assert.ok(!haiku.headers.get("anthropic-beta")?.includes(bindingBeta));+ assert.ok(haiku.headers.get("anthropic-beta")?.includes("interleaved-thinking"));+});diff --git a/test/tape-fold.test.ts b/test/tape-fold.test.tsindex 1aeb36fce..09d9a17d5 100644--- a/test/tape-fold.test.ts+++ b/test/tape-fold.test.ts@@ -249,6 +249,28 @@ test("compaction replaces the prefix up to its watermark boundary, keeps recent);});+test("compaction strips thinking from kept turns so later blocks bind to a stable prefix", () => {+ seq = 0;+ const think = (sig: string) => ({ type: "thinking", thinking: "", thinkingSignature: sig });+ const rows = [+ user("old q"),+ assistant([think("old"), { type: "text", text: "old a" }]),+ turnEnd(1),+ user("recent q"),+ assistant([think("recent"), { type: "text", text: "recent a" }]),+ turnEnd(3),+ row({ kind: "context_event", payload: { event: "compaction", text: "the old stuff" }, coversEntrySeq: 1 }),+ user("post q"),+ assistant([think("post"), { type: "text", text: "post a" }]),+ ];+ const out = foldTape(rows) as Array<{ role: string; content: Array<{ type: string; text?: string }> }>;+ assert.deepEqual(+ out.map((m) => m.content.map((b) => b.type)),+ [["text"], ["text"], ["text"], ["text"], ["thinking", "text"]],+ );+ assert.deepEqual(out[2]!.content, [{ type: "text", text: "recent a" }]);+});+test("interrupt event heals dangling tool calls with error results", () => {seq = 0;const rows = [