Skip to content

Commit 846f553

Browse files
Radu028claude
andcommitted
fix(acp): Plan mode switches Copilot into its native plan mode
GitHub Copilot CLI advertises URL-shaped ACP session mode ids such as https://agentclientprotocol.com/protocol/session-modes#plan. The ACP adapter only matched the literal ids "plan" and "architect", so the Plan toggle left Copilot in agent mode. Match a plan mode by its id or by the fragment after the last "#". Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6d450a4 commit 846f553

3 files changed

Lines changed: 186 additions & 149 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import { beginAcpMockPrompt } from "./acpMockCancellationState.ts";
1818

1919
const requestLogPath = process.env.T3_ACP_REQUEST_LOG_PATH;
2020
const antigravityProfile = process.env.T3_ACP_ANTIGRAVITY === "1";
21+
// GitHub Copilot CLI advertises URL-shaped session mode ids.
22+
const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1";
23+
const copilotModeId = (name: string) =>
24+
`https://agentclientprotocol.com/protocol/session-modes#${name}`;
2125
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
2226
const emitInterleavedAssistantToolCalls =
2327
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -72,7 +76,11 @@ const permissionOptionIds = {
7276
};
7377
const sessionId = "mock-session-1";
7478

75-
let currentModeId = antigravityProfile ? "default" : "ask";
79+
let currentModeId = antigravityProfile
80+
? "default"
81+
: copilotModesProfile
82+
? copilotModeId("agent")
83+
: "ask";
7684
let currentModelId = antigravityProfile ? "gemini-test-low" : "default";
7785
let parameterizedModelPicker = false;
7886
let currentReasoning = "medium";
@@ -326,23 +334,29 @@ const availableModes: ReadonlyArray<AcpCompat.SessionMode> = antigravityProfile
326334
{ id: "auto_edit", name: "Auto edit" },
327335
{ id: "yolo", name: "YOLO" },
328336
]
329-
: [
330-
{
331-
id: "ask",
332-
name: "Ask",
333-
description: "Request permission before making any changes",
334-
},
335-
{
336-
id: "architect",
337-
name: "Architect",
338-
description: "Design and plan software systems without implementation",
339-
},
340-
{
341-
id: "code",
342-
name: "Code",
343-
description: "Write and modify code with full tool access",
344-
},
345-
];
337+
: copilotModesProfile
338+
? [
339+
{ id: copilotModeId("agent"), name: "Agent" },
340+
{ id: copilotModeId("plan"), name: "Plan" },
341+
{ id: copilotModeId("autopilot"), name: "Autopilot" },
342+
]
343+
: [
344+
{
345+
id: "ask",
346+
name: "Ask",
347+
description: "Request permission before making any changes",
348+
},
349+
{
350+
id: "architect",
351+
name: "Architect",
352+
description: "Design and plan software systems without implementation",
353+
},
354+
{
355+
id: "code",
356+
name: "Code",
357+
description: "Write and modify code with full tool access",
358+
},
359+
];
346360

347361
function modeState(): AcpCompat.SessionModeState {
348362
return {

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 145 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -902,136 +902,155 @@ describe("AcpAdapterV2", () => {
902902
}).pipe(Effect.provide(layerTest), Effect.scoped),
903903
);
904904

905-
it.live("refreshes ACP prompt instructions when the interaction mode changes", () =>
906-
Effect.gen(function* () {
907-
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
908-
const path = yield* Path.Path;
909-
const selfInvocation = yield* resolveSelfInvocation();
910-
const mockAgentPath = yield* path.fromFileUrl(
911-
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
912-
);
913-
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
914-
const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
915-
const threadId = ThreadId.make("thread-acp-instruction-transitions");
916-
yield* (yield* McpProviderSessions.McpProviderSessions).set({
917-
environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
918-
threadId,
919-
providerSessionId: "mcp-session-acp-instruction-transitions",
920-
providerInstanceId: instanceId,
921-
endpoint: "http://127.0.0.1:43123/mcp",
922-
authorizationHeader: "Bearer instruction-transition-token",
923-
browserToolsAvailable: false,
924-
});
925-
const adapter = yield* makeAcpAdapterV2({
926-
instanceId,
927-
flavor: {
928-
driver: ACP_TEST_DRIVER,
929-
capabilities: AcpProviderCapabilitiesV2,
930-
makeRuntime: makeMockRuntime({
931-
childProcessSpawner,
932-
mockAgentPath,
933-
protocolEvents,
934-
}),
935-
},
936-
selfInvocation,
937-
});
938-
const policy = (interactionMode: "default" | "plan") =>
939-
ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
940-
runtimeMode: "full-access",
941-
interactionMode,
942-
cwd: process.cwd(),
905+
it.live.each([
906+
{ modeIds: "plain", environment: {}, planModeId: "architect", buildModeId: "ask" },
907+
{
908+
modeIds: "Copilot URL",
909+
environment: { T3_ACP_COPILOT_MODES: "1" },
910+
planModeId: "https://agentclientprotocol.com/protocol/session-modes#plan",
911+
buildModeId: "https://agentclientprotocol.com/protocol/session-modes#agent",
912+
},
913+
])(
914+
"refreshes ACP prompt instructions and native mode when the interaction mode changes ($modeIds mode ids)",
915+
({ environment, planModeId, buildModeId }) =>
916+
Effect.gen(function* () {
917+
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
918+
const path = yield* Path.Path;
919+
const selfInvocation = yield* resolveSelfInvocation();
920+
const mockAgentPath = yield* path.fromFileUrl(
921+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
922+
);
923+
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
924+
const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
925+
const threadId = ThreadId.make("thread-acp-instruction-transitions");
926+
yield* (yield* McpProviderSessions.McpProviderSessions).set({
927+
environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
928+
threadId,
929+
providerSessionId: "mcp-session-acp-instruction-transitions",
930+
providerInstanceId: instanceId,
931+
endpoint: "http://127.0.0.1:43123/mcp",
932+
authorizationHeader: "Bearer instruction-transition-token",
933+
browserToolsAvailable: false,
943934
});
944-
const defaultPolicy = policy("default");
945-
const modelSelection = { instanceId, model: "default" } as const;
946-
const runtime = yield* adapter.openSession({
947-
threadId,
948-
providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
949-
modelSelection,
950-
runtimePolicy: defaultPolicy,
951-
});
952-
const providerThread = yield* runtime.ensureThread({
953-
threadId,
954-
modelSelection,
955-
runtimePolicy: defaultPolicy,
956-
});
957-
const now = yield* DateTime.now;
958-
const runTurn = Effect.fnUntraced(function* (
959-
ordinal: number,
960-
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
961-
messageText: string,
962-
) {
963-
yield* runtime.startTurn(
964-
makeTurnInput({
965-
threadId,
966-
providerThread,
967-
instanceId,
968-
runtimePolicy,
969-
now,
970-
ordinal,
971-
messageText,
972-
}),
935+
const adapter = yield* makeAcpAdapterV2({
936+
instanceId,
937+
flavor: {
938+
driver: ACP_TEST_DRIVER,
939+
capabilities: AcpProviderCapabilitiesV2,
940+
makeRuntime: makeMockRuntime({
941+
childProcessSpawner,
942+
mockAgentPath,
943+
protocolEvents,
944+
environment,
945+
}),
946+
},
947+
selfInvocation,
948+
});
949+
const policy = (interactionMode: "default" | "plan") =>
950+
ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
951+
runtimeMode: "full-access",
952+
interactionMode,
953+
cwd: process.cwd(),
954+
});
955+
const defaultPolicy = policy("default");
956+
const modelSelection = { instanceId, model: "default" } as const;
957+
const runtime = yield* adapter.openSession({
958+
threadId,
959+
providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
960+
modelSelection,
961+
runtimePolicy: defaultPolicy,
962+
});
963+
const providerThread = yield* runtime.ensureThread({
964+
threadId,
965+
modelSelection,
966+
runtimePolicy: defaultPolicy,
967+
});
968+
const now = yield* DateTime.now;
969+
const runTurn = Effect.fnUntraced(function* (
970+
ordinal: number,
971+
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
972+
messageText: string,
973+
) {
974+
yield* runtime.startTurn(
975+
makeTurnInput({
976+
threadId,
977+
providerThread,
978+
instanceId,
979+
runtimePolicy,
980+
now,
981+
ordinal,
982+
messageText,
983+
}),
984+
);
985+
yield* runtime.events.pipe(
986+
Stream.takeUntil((event) => event.type === "turn.terminal"),
987+
Stream.runDrain,
988+
);
989+
const methods: Array<string> = [];
990+
const modeSets: Array<unknown> = [];
991+
while (true) {
992+
const event = yield* Queue.take(protocolEvents);
993+
if (event.direction !== "outgoing") continue;
994+
const method = rawProtocolMethod(event);
995+
if (method === undefined) continue;
996+
methods.push(method);
997+
if (
998+
method === "session/set_config_option" &&
999+
rawProtocolRequestParam(event, "configId") === "mode"
1000+
) {
1001+
modeSets.push(rawProtocolRequestParam(event, "value"));
1002+
}
1003+
if (method === "session/prompt") {
1004+
const promptBlocks = rawProtocolPromptTextBlocks(event);
1005+
return {
1006+
methods,
1007+
modeSets,
1008+
prompt: promptBlocks.map((block) => block.text).join("\n"),
1009+
textBlockCount: promptBlocks.length,
1010+
};
1011+
}
1012+
}
1013+
});
1014+
1015+
const command = yield* runTurn(0, defaultPolicy, "/compact");
1016+
assert.isTrue(command.prompt.startsWith("/compact"));
1017+
assert.notInclude(command.prompt, "<t3_code_instructions>");
1018+
assert.equal(command.textBlockCount, 1);
1019+
const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
1020+
assert.equal(whitespaceCommand.prompt, " /repro-skill");
1021+
assert.equal(whitespaceCommand.textBlockCount, 1);
1022+
assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
1023+
const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
1024+
assert.equal(firstDefault.textBlockCount, 2);
1025+
assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
1026+
assert.include(firstDefault.prompt, "## T3 Code browser");
1027+
assert.include(firstDefault.prompt, "T3 Code orchestration");
1028+
assert.notInclude(
1029+
firstDefault.methods,
1030+
"session/set_config_option",
1031+
"Build should preserve the agent's advertised mode default",
9731032
);
974-
yield* runtime.events.pipe(
975-
Stream.takeUntil((event) => event.type === "turn.terminal"),
976-
Stream.runDrain,
1033+
assert.include(
1034+
(yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
1035+
"Second default request.",
9771036
);
978-
const methods: Array<string> = [];
979-
while (true) {
980-
const event = yield* Queue.take(protocolEvents);
981-
if (event.direction !== "outgoing") continue;
982-
const method = rawProtocolMethod(event);
983-
if (method === undefined) continue;
984-
methods.push(method);
985-
if (method === "session/prompt") {
986-
const promptBlocks = rawProtocolPromptTextBlocks(event);
987-
return {
988-
methods,
989-
prompt: promptBlocks.map((block) => block.text).join("\n"),
990-
textBlockCount: promptBlocks.length,
991-
};
992-
}
993-
}
994-
});
9951037

996-
const command = yield* runTurn(0, defaultPolicy, "/compact");
997-
assert.isTrue(command.prompt.startsWith("/compact"));
998-
assert.notInclude(command.prompt, "<t3_code_instructions>");
999-
assert.equal(command.textBlockCount, 1);
1000-
const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
1001-
assert.equal(whitespaceCommand.prompt, " /repro-skill");
1002-
assert.equal(whitespaceCommand.textBlockCount, 1);
1003-
assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
1004-
const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
1005-
assert.equal(firstDefault.textBlockCount, 2);
1006-
assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
1007-
assert.include(firstDefault.prompt, "## T3 Code browser");
1008-
assert.include(firstDefault.prompt, "T3 Code orchestration");
1009-
assert.notInclude(
1010-
firstDefault.methods,
1011-
"session/set_config_option",
1012-
"Build should preserve the agent's advertised mode default",
1013-
);
1014-
assert.include(
1015-
(yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
1016-
"Second default request.",
1017-
);
1018-
1019-
const planPolicy = policy("plan");
1020-
const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
1021-
assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
1022-
assert.include(firstPlan.methods, "session/set_config_option");
1023-
assert.include(
1024-
(yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
1025-
"Continue planning.",
1026-
);
1027-
const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
1028-
assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
1029-
assert.include(
1030-
restoredBuild.methods,
1031-
"session/set_config_option",
1032-
"Build should restore the native mode that T3 temporarily replaced for Plan",
1033-
);
1034-
}).pipe(Effect.provide(layerTest), Effect.scoped),
1038+
const planPolicy = policy("plan");
1039+
const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
1040+
assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
1041+
assert.deepEqual(firstPlan.modeSets, [planModeId]);
1042+
assert.include(
1043+
(yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
1044+
"Continue planning.",
1045+
);
1046+
const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
1047+
assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
1048+
assert.deepEqual(
1049+
restoredBuild.modeSets,
1050+
[buildModeId],
1051+
"Build should restore the native mode that T3 temporarily replaced for Plan",
1052+
);
1053+
}).pipe(Effect.provide(layerTest), Effect.scoped),
10351054
);
10361055

10371056
it.live(

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,12 @@ function completedAtForStatus(status: ProjectedToolStatus, now: DateTime.Utc): D
976976
return status === "completed" || status === "failed" || status === "interrupted" ? now : null;
977977
}
978978

979+
// Copilot advertises URL ids such as `https://agentclientprotocol.com/protocol/session-modes#plan`.
980+
function isAcpPlanModeId(id: string): boolean {
981+
const name = id.slice(id.lastIndexOf("#") + 1);
982+
return name === "plan" || name === "architect";
983+
}
984+
979985
function selectPermissionOptionId(
980986
request: EffectAcpSchema.RequestPermissionRequest,
981987
decision: Exclude<ProviderApprovalDecision, "cancel">,
@@ -6827,8 +6833,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
68276833
})),
68286834
});
68296835
}
6830-
const planMode = effectiveModeState?.availableModes.find(
6831-
(mode) => mode.id === "plan" || mode.id === "architect",
6836+
const planMode = effectiveModeState?.availableModes.find((mode) =>
6837+
isAcpPlanModeId(mode.id),
68326838
);
68336839
if (planMode !== undefined && effectiveModeState?.currentModeId !== planMode.id) {
68346840
yield* runtime.setMode(planMode.id);
@@ -6837,9 +6843,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
68376843
const choices = option.options.flatMap((entry) =>
68386844
"value" in entry ? [entry.value] : entry.options.map((choice) => choice.value),
68396845
);
6840-
const requested = choices.find(
6841-
(choice) => choice === "plan" || choice === "architect",
6842-
);
6846+
const requested = choices.find(isAcpPlanModeId);
68436847
if (requested !== undefined && option.currentValue !== requested) {
68446848
yield* runtime.setConfigOption(option.id, requested);
68456849
}

0 commit comments

Comments
 (0)