Skip to content
TypeScript

fix(acp): Plan mode switches Copilot into its native plan mode (#26951)

Radu-Stefan Popa17c837c52253
diff --git a/apps/server/scripts/acp-mock-agent.ts b/apps/server/scripts/acp-mock-agent.ts
index 667f9eb677b..ae07db783c9 100644
--- a/apps/server/scripts/acp-mock-agent.ts
+++ b/apps/server/scripts/acp-mock-agent.ts
@@ -18,6 +18,11 @@ import { beginAcpMockPrompt } from "./acpMockCancellationState.ts";
const requestLogPath = process.env.T3_ACP_REQUEST_LOG_PATH;
const antigravityProfile = process.env.T3_ACP_ANTIGRAVITY === "1";
+// GitHub Copilot CLI advertises URL-shaped session mode ids.
+const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1";
+const copilotModeId = (name: string) =>
+ `https://agentclientprotocol.com/protocol/session-modes#${name}`;
+const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode";
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
const emitInterleavedAssistantToolCalls =
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -74,7 +79,11 @@ const permissionOptionIds = {
};
const sessionId = "mock-session-1";
-let currentModeId = antigravityProfile ? "default" : "ask";
+let currentModeId = antigravityProfile
+ ? "default"
+ : copilotModesProfile
+ ? copilotModeId("agent")
+ : "ask";
let currentModelId = antigravityProfile ? "gemini-test-low" : "default";
let parameterizedModelPicker = false;
let currentReasoning = "medium";
@@ -263,7 +272,7 @@ function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
{
configId: "mode",
name: "Mode",
- category: "mode",
+ category: modeOptionCategory,
type: "select" as const,
currentValue: currentModeId,
options: availableModes.map((mode) => ({
@@ -328,23 +337,29 @@ const availableModes: ReadonlyArray<AcpCompat.SessionMode> = antigravityProfile
{ id: "auto_edit", name: "Auto edit" },
{ id: "yolo", name: "YOLO" },
]
- : [
- {
- id: "ask",
- name: "Ask",
- description: "Request permission before making any changes",
- },
- {
- id: "architect",
- name: "Architect",
- description: "Design and plan software systems without implementation",
- },
- {
- id: "code",
- name: "Code",
- description: "Write and modify code with full tool access",
- },
- ];
+ : copilotModesProfile
+ ? [
+ { id: copilotModeId("agent"), name: "Agent" },
+ { id: copilotModeId("plan"), name: "Plan" },
+ { id: copilotModeId("autopilot"), name: "Autopilot" },
+ ]
+ : [
+ {
+ id: "ask",
+ name: "Ask",
+ description: "Request permission before making any changes",
+ },
+ {
+ id: "architect",
+ name: "Architect",
+ description: "Design and plan software systems without implementation",
+ },
+ {
+ id: "code",
+ name: "Code",
+ description: "Write and modify code with full tool access",
+ },
+ ];
function modeState(): AcpCompat.SessionModeState {
return {
diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
index 73cb274501c..bb84c1a2c74 100644
--- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
@@ -1712,136 +1712,162 @@ describe("AcpAdapterV2", () => {
}).pipe(Effect.provide(layerTest), Effect.scoped),
);
- it.live("refreshes ACP prompt instructions when the interaction mode changes", () =>
- Effect.gen(function* () {
- const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
- const path = yield* Path.Path;
- const selfInvocation = yield* resolveSelfInvocation();
- const mockAgentPath = yield* path.fromFileUrl(
- new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
- );
- const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
- const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
- const threadId = ThreadId.make("thread-acp-instruction-transitions");
- yield* (yield* McpProviderSessions.McpProviderSessions).set({
- environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
- threadId,
- providerSessionId: "mcp-session-acp-instruction-transitions",
- providerInstanceId: instanceId,
- endpoint: "http://127.0.0.1:43123/mcp",
- authorizationHeader: "Bearer instruction-transition-token",
- browserToolsAvailable: false,
- });
- const adapter = yield* makeAcpAdapterV2({
- instanceId,
- flavor: {
- driver: ACP_TEST_DRIVER,
- capabilities: AcpProviderCapabilitiesV2,
- makeRuntime: makeMockRuntime({
- childProcessSpawner,
- mockAgentPath,
- protocolEvents,
- }),
- },
- selfInvocation,
- });
- const policy = (interactionMode: "default" | "plan") =>
- ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
- runtimeMode: "full-access",
- interactionMode,
- cwd: process.cwd(),
+ it.live.each([
+ { modeIds: "plain", environment: {}, planModeId: "architect", buildModeId: "ask" },
+ {
+ modeIds: "Copilot URL",
+ environment: { T3_ACP_COPILOT_MODES: "1" },
+ planModeId: "https://agentclientprotocol.com/protocol/session-modes#plan",
+ buildModeId: "https://agentclientprotocol.com/protocol/session-modes#agent",
+ },
+ {
+ // Without a `mode` category, T3 derives no mode state and only the config option switches.
+ modeIds: "Copilot URL collaboration_mode",
+ environment: { T3_ACP_COPILOT_MODES: "1", T3_ACP_MODE_OPTION_CATEGORY: "collaboration_mode" },
+ planModeId: "https://agentclientprotocol.com/protocol/session-modes#plan",
+ buildModeId: "https://agentclientprotocol.com/protocol/session-modes#agent",
+ },
+ ])(
+ "refreshes ACP prompt instructions and native mode when the interaction mode changes ($modeIds mode ids)",
+ ({ environment, planModeId, buildModeId }) =>
+ Effect.gen(function* () {
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
+ const path = yield* Path.Path;
+ const selfInvocation = yield* resolveSelfInvocation();
+ const mockAgentPath = yield* path.fromFileUrl(
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
+ );
+ const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
+ const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
+ const threadId = ThreadId.make("thread-acp-instruction-transitions");
+ yield* (yield* McpProviderSessions.McpProviderSessions).set({
+ environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
+ threadId,
+ providerSessionId: "mcp-session-acp-instruction-transitions",
+ providerInstanceId: instanceId,
+ endpoint: "http://127.0.0.1:43123/mcp",
+ authorizationHeader: "Bearer instruction-transition-token",
+ browserToolsAvailable: false,
});
- const defaultPolicy = policy("default");
- const modelSelection = { instanceId, model: "default" } as const;
- const runtime = yield* adapter.openSession({
- threadId,
- providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
- modelSelection,
- runtimePolicy: defaultPolicy,
- });
- const providerThread = yield* runtime.ensureThread({
- threadId,
- modelSelection,
- runtimePolicy: defaultPolicy,
- });
- const now = yield* DateTime.now;
- const runTurn = Effect.fnUntraced(function* (
- ordinal: number,
- runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
- messageText: string,
- ) {
- yield* runtime.startTurn(
- makeTurnInput({
- threadId,
- providerThread,
- instanceId,
- runtimePolicy,
- now,
- ordinal,
- messageText,
- }),
+ const adapter = yield* makeAcpAdapterV2({
+ instanceId,
+ flavor: {
+ driver: ACP_TEST_DRIVER,
+ capabilities: AcpProviderCapabilitiesV2,
+ makeRuntime: makeMockRuntime({
+ childProcessSpawner,
+ mockAgentPath,
+ protocolEvents,
+ environment,
+ }),
+ },
+ selfInvocation,
+ });
+ const policy = (interactionMode: "default" | "plan") =>
+ ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
+ runtimeMode: "full-access",
+ interactionMode,
+ cwd: process.cwd(),
+ });
+ const defaultPolicy = policy("default");
+ const modelSelection = { instanceId, model: "default" } as const;
+ const runtime = yield* adapter.openSession({
+ threadId,
+ providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
+ modelSelection,
+ runtimePolicy: defaultPolicy,
+ });
+ const providerThread = yield* runtime.ensureThread({
+ threadId,
+ modelSelection,
+ runtimePolicy: defaultPolicy,
+ });
+ const now = yield* DateTime.now;
+ const runTurn = Effect.fnUntraced(function* (
+ ordinal: number,
+ runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
+ messageText: string,
+ ) {
+ yield* runtime.startTurn(
+ makeTurnInput({
+ threadId,
+ providerThread,
+ instanceId,
+ runtimePolicy,
+ now,
+ ordinal,
+ messageText,
+ }),
+ );
+ yield* runtime.events.pipe(
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
+ Stream.runDrain,
+ );
+ const methods: Array<string> = [];
+ const modeSets: Array<unknown> = [];
+ while (true) {
+ const event = yield* Queue.take(protocolEvents);
+ if (event.direction !== "outgoing") continue;
+ const method = rawProtocolMethod(event);
+ if (method === undefined) continue;
+ methods.push(method);
+ if (
+ method === "session/set_config_option" &&
+ rawProtocolRequestParam(event, "configId") === "mode"
+ ) {
+ modeSets.push(rawProtocolRequestParam(event, "value"));
+ }
+ if (method === "session/prompt") {
+ const promptBlocks = rawProtocolPromptTextBlocks(event);
+ return {
+ methods,
+ modeSets,
+ prompt: promptBlocks.map((block) => block.text).join("\n"),
+ textBlockCount: promptBlocks.length,
+ };
+ }
+ }
+ });
+
+ const command = yield* runTurn(0, defaultPolicy, "/compact");
+ assert.isTrue(command.prompt.startsWith("/compact"));
+ assert.notInclude(command.prompt, "<t3_code_instructions>");
+ assert.equal(command.textBlockCount, 1);
+ const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
+ assert.equal(whitespaceCommand.prompt, " /repro-skill");
+ assert.equal(whitespaceCommand.textBlockCount, 1);
+ assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
+ const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
+ assert.equal(firstDefault.textBlockCount, 2);
+ assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
+ assert.include(firstDefault.prompt, "## T3 Code browser");
+ assert.include(firstDefault.prompt, "T3 Code orchestration");
+ assert.notInclude(
+ firstDefault.methods,
+ "session/set_config_option",
+ "Build should preserve the agent's advertised mode default",
);
- yield* runtime.events.pipe(
- Stream.takeUntil((event) => event.type === "turn.terminal"),
- Stream.runDrain,
+ assert.include(
+ (yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
+ "Second default request.",
);
- const methods: Array<string> = [];
- while (true) {
- const event = yield* Queue.take(protocolEvents);
- if (event.direction !== "outgoing") continue;
- const method = rawProtocolMethod(event);
- if (method === undefined) continue;
- methods.push(method);
- if (method === "session/prompt") {
- const promptBlocks = rawProtocolPromptTextBlocks(event);
- return {
- methods,
- prompt: promptBlocks.map((block) => block.text).join("\n"),
- textBlockCount: promptBlocks.length,
- };
- }
- }
- });
- const command = yield* runTurn(0, defaultPolicy, "/compact");
- assert.isTrue(command.prompt.startsWith("/compact"));
- assert.notInclude(command.prompt, "<t3_code_instructions>");
- assert.equal(command.textBlockCount, 1);
- const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
- assert.equal(whitespaceCommand.prompt, " /repro-skill");
- assert.equal(whitespaceCommand.textBlockCount, 1);
- assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
- const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
- assert.equal(firstDefault.textBlockCount, 2);
- assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
- assert.include(firstDefault.prompt, "## T3 Code browser");
- assert.include(firstDefault.prompt, "T3 Code orchestration");
- assert.notInclude(
- firstDefault.methods,
- "session/set_config_option",
- "Build should preserve the agent's advertised mode default",
- );
- assert.include(
- (yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
- "Second default request.",
- );
-
- const planPolicy = policy("plan");
- const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
- assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
- assert.include(firstPlan.methods, "session/set_config_option");
- assert.include(
- (yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
- "Continue planning.",
- );
- const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
- assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
- assert.include(
- restoredBuild.methods,
- "session/set_config_option",
- "Build should restore the native mode that T3 temporarily replaced for Plan",
- );
- }).pipe(Effect.provide(layerTest), Effect.scoped),
+ const planPolicy = policy("plan");
+ const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
+ assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
+ assert.deepEqual(firstPlan.modeSets, [planModeId]);
+ assert.include(
+ (yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
+ "Continue planning.",
+ );
+ const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
+ assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
+ assert.deepEqual(
+ restoredBuild.modeSets,
+ [buildModeId],
+ "Build should restore the native mode that T3 temporarily replaced for Plan",
+ );
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
);
it.live(
diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts
index 10dd5d53d3d..bc34b9fd65f 100644
--- a/packages/provider-acp/src/server/adapter.ts
+++ b/packages/provider-acp/src/server/adapter.ts
@@ -1047,6 +1047,12 @@ function completedAtForStatus(status: ProjectedToolStatus, now: DateTime.Utc): D
return status === "completed" || status === "failed" || status === "interrupted" ? now : null;
}
+// Copilot advertises URL ids such as `https://agentclientprotocol.com/protocol/session-modes#plan`.
+function isAcpPlanModeId(id: string): boolean {
+ const name = id.slice(id.lastIndexOf("#") + 1);
+ return name === "plan" || name === "architect";
+}
+
function selectPermissionOptionId(
request: EffectAcpSchema.RequestPermissionRequest,
decision: Exclude<ProviderApprovalDecision, "cancel">,
@@ -6960,8 +6966,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
})),
});
}
- const planMode = effectiveModeState?.availableModes.find(
- (mode) => mode.id === "plan" || mode.id === "architect",
+ const planMode = effectiveModeState?.availableModes.find((mode) =>
+ isAcpPlanModeId(mode.id),
);
if (planMode !== undefined && effectiveModeState?.currentModeId !== planMode.id) {
yield* runtime.setMode(planMode.id);
@@ -6970,9 +6976,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
const choices = option.options.flatMap((entry) =>
"value" in entry ? [entry.value] : entry.options.map((choice) => choice.value),
);
- const requested = choices.find(
- (choice) => choice === "plan" || choice === "architect",
- );
+ const requested = choices.find(isAcpPlanModeId);
if (requested !== undefined && option.currentValue !== requested) {
yield* runtime.setConfigOption(option.id, requested);
}