Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
122 changes: 122 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<any>" },
},
{
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: "<any>" },
},
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;
Expand Down
29 changes: 23 additions & 6 deletions packages/provider-acp-registry/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -256,16 +274,17 @@ 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 }
: isOpenCode
? { 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
? {}
: {
Expand All @@ -280,9 +299,7 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
),
),
}),
...(registryAgentId === "mistral-vibe"
? { registerExtensions: registerMistralVibeAcpExtensions }
: {}),
...(isVibe ? { registerExtensions: registerMistralVibeAcpExtensions } : {}),
...(isClaude
? {
followAgentWorkState: true,
Expand Down
Loading