diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 4fb03956e9e13..46a8f4c888296 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -111,6 +111,10 @@ const OMP_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ commandPath: "/usr/local/bin/omp", commandArgs: ["acp"], }); +const DROID_LOCAL_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ + source: "local", + commandPath: "/opt/droid/bin/droid", +}); const OPENCODE_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ source: "local", commandPath: "/usr/local/bin/opencode", @@ -2082,6 +2086,17 @@ describe("AcpAdapterV2", () => { content: { question_1: "option_1", question_2: "other", question_2_other: "Markdown" }, }, }, + { + scenario: "extracts the paired form for a local droid command", + settings: DROID_LOCAL_SETTINGS, + schema: droidSchema, + questions: droidQuestions, + answers: { question_1: "option_1", question_2: "Markdown" }, + result: { + action: "accept", + content: { question_1: "option_1", question_2: "other", question_2_other: "Markdown" }, + }, + }, { scenario: "preserves selected labels and attachment paths in custom answers", schema: droidSchema, diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 35c0ec29d1148..55b313a9d3adc 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -2928,6 +2928,128 @@ describe("AcpRegistryAdapterV2", () => { }).pipe(Effect.provide(layerTest), Effect.scoped), ); + it.effect("counts per-turn usage for a local glm command", () => + Effect.gen(function* () { + const session = yield* openClaudeReplaySession( + [ + // GLM reports per-turn usage on the v1 prompt response. + ...claudeFrames.open.map((entry) => + entry.frame.method === "initialize" && entry.type === "emit_inbound" + ? { + ...entry, + frame: { + ...entry.frame, + result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] }, + }, + } + : entry, + ), + { + type: "expect_outbound", + frame: { kind: "request", method: "session/prompt", params: "" }, + }, + { + type: "emit_inbound", + frame: { + kind: "response", + method: "session/prompt", + result: { + stopReason: "end_turn", + usage: { totalTokens: 3_000, inputTokens: 2_500, outputTokens: 500 }, + }, + }, + }, + claudeFrames.closeRequest, + claudeFrames.closed, + ], + undefined, + false, + { source: "local", commandPath: "/opt/glm/bin/glm" }, + ); + yield* session.runtime.startTurn(session.turnInput(1)).pipe(Effect.forkScoped); + const events = yield* session.until((event) => event.type === "turn.terminal"); + const completed = events.findLast( + (event) => + event.type === "provider_turn.updated" && event.providerTurn.status === "completed", + ); + assert.deepEqual( + completed?.type === "provider_turn.updated" ? completed.providerTurn.turnTokenUsage : null, + { + usageScope: "main_agent", + usageStatus: "complete", + hasSubagents: false, + inputTokens: 2_500, + outputTokens: 500, + }, + ); + const terminal = events.at(-1)!; + if (terminal.type !== "turn.terminal") throw new Error("Missing terminal"); + assert.equal(terminal.status, "completed"); + }).pipe(Effect.provide(layerTest), Effect.scoped), + ); + + it.effect("surfaces Mistral's retry notice for a local vibe command", () => + Effect.gen(function* () { + const session = yield* openClaudeReplaySession( + [ + ...claudeFrames.open, + { + type: "expect_outbound", + frame: { kind: "request", method: "session/prompt", params: "" }, + }, + claudeFrames.update(CLAUDE_ROOT_SESSION, { + sessionUpdate: "user_message", + messageId: "user-1", + content: [{ type: "text", text: "test prompt" }], + }), + claudeFrames.update(CLAUDE_ROOT_SESSION, { + sessionUpdate: "state_update", + state: "running", + }), + { + type: "emit_inbound", + frame: { + kind: "notification", + method: "_session/retrying", + params: { + sessionId: CLAUDE_ROOT_SESSION, + category: "rate_limited", + detail: "Backing off for 30s", + }, + }, + }, + claudeMarker("retry noticed"), + { + type: "emit_inbound", + frame: { + kind: "response", + method: "session/prompt", + result: { stopReason: "end_turn" }, + }, + }, + claudeFrames.idle("end_turn"), + claudeFrames.closeRequest, + claudeFrames.closed, + ], + undefined, + false, + { source: "local", commandPath: "/opt/vibe/bin/vibe-acp" }, + ); + yield* session.runtime.startTurn(session.turnInput(1)); + const events = yield* session.throughMarker("retry noticed"); + const retry = events.find( + (event) => event.type === "turn_item.updated" && event.turnItem.type === "error", + ); + if (retry?.type !== "turn_item.updated" || retry.turnItem.type !== "error") + throw new Error("Missing provider retry item"); + assert.equal(retry.turnItem.title, "Provider retry"); + assert.equal(retry.turnItem.failure.class, "usage_limit"); + assert.equal(retry.turnItem.retry?.attempt, 1); + const terminal = yield* session.terminal; + assert.equal(terminal.status, "completed"); + }).pipe(Effect.provide(layerTest), Effect.scoped), + ); + it.effect("keeps stopped child tools interrupted when a late output chunk arrives", () => Effect.gen(function* () { const { update } = claudeFrames; diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index ce5a2b94531c4..8eb5dbb30b8cc 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -225,6 +225,24 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu /^claude-agent-acp(\.exe|\.cmd)?$/i.test( options.settings.commandPath.split(/[\\/]/).pop() ?? "", )); + const isDroid = + registryAgentId === "factory-droid" || + (options.settings.source === "local" && + /^(?:factory-)?droid(\.exe|\.cmd)?$/i.test( + options.settings.commandPath.split(/[\\/]/).pop() ?? "", + )); + const isGlm = + registryAgentId === "glm-acp-agent" || + (options.settings.source === "local" && + /^glm(?:-acp-agent)?(\.exe|\.cmd)?$/i.test( + options.settings.commandPath.split(/[\\/]/).pop() ?? "", + )); + const isVibe = + registryAgentId === "mistral-vibe" || + (options.settings.source === "local" && + /^(?:mistral-)?vibe(?:-acp)?(\.exe|\.cmd)?$/i.test( + options.settings.commandPath.split(/[\\/]/).pop() ?? "", + )); const runtimeOptions = isClaude ? { ...options, @@ -256,8 +274,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu customModels: readCustomModelEntries(options.settings.customModels).map((entry) => entry.slug), compactViaAdvertisedCommand: true, ...(isAntigravityCli ? { wakeOnDetachedRequest: true, replyEndsWithUsageUpdate: true } : {}), - promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause), - ...(registryAgentId === "factory-droid" + promptFailure: (cause) => + acpRegistryPromptFailure(isVibe ? "mistral-vibe" : registryAgentId, cause), + ...(isDroid ? { extractElicitationForm: extractDroidElicitationForm } : isOmp ? { extractElicitationForm: extractOmpElicitationForm } @@ -265,7 +284,7 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu ? { extractElicitationForm: extractOpenCodeElicitationForm } : {}), // glm-acp-agent is the one agent whose per-turn usage a live probe has verified. - ...(registryAgentId === "glm-acp-agent" ? { reportsPerTurnPromptUsage: true } : {}), + ...(isGlm ? { reportsPerTurnPromptUsage: true } : {}), ...(watchKimiPromptOutcome === undefined ? {} : { @@ -280,9 +299,7 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu ), ), }), - ...(registryAgentId === "mistral-vibe" - ? { registerExtensions: registerMistralVibeAcpExtensions } - : {}), + ...(isVibe ? { registerExtensions: registerMistralVibeAcpExtensions } : {}), ...(isClaude ? { followAgentWorkState: true,