Skip to content

Commit 17c837c

Browse files
Radu028claudemaria-rcks
authored
fix(acp): Plan mode switches Copilot into its native plan mode (#26951)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent d1049c4 commit 17c837c

3 files changed

Lines changed: 195 additions & 150 deletions

File tree

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

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ 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}`;
25+
const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode";
2126
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
2227
const emitInterleavedAssistantToolCalls =
2328
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -74,7 +79,11 @@ const permissionOptionIds = {
7479
};
7580
const sessionId = "mock-session-1";
7681

77-
let currentModeId = antigravityProfile ? "default" : "ask";
82+
let currentModeId = antigravityProfile
83+
? "default"
84+
: copilotModesProfile
85+
? copilotModeId("agent")
86+
: "ask";
7887
let currentModelId = antigravityProfile ? "gemini-test-low" : "default";
7988
let parameterizedModelPicker = false;
8089
let currentReasoning = "medium";
@@ -263,7 +272,7 @@ function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
263272
{
264273
configId: "mode",
265274
name: "Mode",
266-
category: "mode",
275+
category: modeOptionCategory,
267276
type: "select" as const,
268277
currentValue: currentModeId,
269278
options: availableModes.map((mode) => ({
@@ -328,23 +337,29 @@ const availableModes: ReadonlyArray<AcpCompat.SessionMode> = antigravityProfile
328337
{ id: "auto_edit", name: "Auto edit" },
329338
{ id: "yolo", name: "YOLO" },
330339
]
331-
: [
332-
{
333-
id: "ask",
334-
name: "Ask",
335-
description: "Request permission before making any changes",
336-
},
337-
{
338-
id: "architect",
339-
name: "Architect",
340-
description: "Design and plan software systems without implementation",
341-
},
342-
{
343-
id: "code",
344-
name: "Code",
345-
description: "Write and modify code with full tool access",
346-
},
347-
];
340+
: copilotModesProfile
341+
? [
342+
{ id: copilotModeId("agent"), name: "Agent" },
343+
{ id: copilotModeId("plan"), name: "Plan" },
344+
{ id: copilotModeId("autopilot"), name: "Autopilot" },
345+
]
346+
: [
347+
{
348+
id: "ask",
349+
name: "Ask",
350+
description: "Request permission before making any changes",
351+
},
352+
{
353+
id: "architect",
354+
name: "Architect",
355+
description: "Design and plan software systems without implementation",
356+
},
357+
{
358+
id: "code",
359+
name: "Code",
360+
description: "Write and modify code with full tool access",
361+
},
362+
];
348363

349364
function modeState(): AcpCompat.SessionModeState {
350365
return {

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

Lines changed: 152 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,136 +1712,162 @@ describe("AcpAdapterV2", () => {
17121712
}).pipe(Effect.provide(layerTest), Effect.scoped),
17131713
);
17141714

1715-
it.live("refreshes ACP prompt instructions when the interaction mode changes", () =>
1716-
Effect.gen(function* () {
1717-
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1718-
const path = yield* Path.Path;
1719-
const selfInvocation = yield* resolveSelfInvocation();
1720-
const mockAgentPath = yield* path.fromFileUrl(
1721-
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1722-
);
1723-
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
1724-
const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
1725-
const threadId = ThreadId.make("thread-acp-instruction-transitions");
1726-
yield* (yield* McpProviderSessions.McpProviderSessions).set({
1727-
environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
1728-
threadId,
1729-
providerSessionId: "mcp-session-acp-instruction-transitions",
1730-
providerInstanceId: instanceId,
1731-
endpoint: "http://127.0.0.1:43123/mcp",
1732-
authorizationHeader: "Bearer instruction-transition-token",
1733-
browserToolsAvailable: false,
1734-
});
1735-
const adapter = yield* makeAcpAdapterV2({
1736-
instanceId,
1737-
flavor: {
1738-
driver: ACP_TEST_DRIVER,
1739-
capabilities: AcpProviderCapabilitiesV2,
1740-
makeRuntime: makeMockRuntime({
1741-
childProcessSpawner,
1742-
mockAgentPath,
1743-
protocolEvents,
1744-
}),
1745-
},
1746-
selfInvocation,
1747-
});
1748-
const policy = (interactionMode: "default" | "plan") =>
1749-
ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1750-
runtimeMode: "full-access",
1751-
interactionMode,
1752-
cwd: process.cwd(),
1715+
it.live.each([
1716+
{ modeIds: "plain", environment: {}, planModeId: "architect", buildModeId: "ask" },
1717+
{
1718+
modeIds: "Copilot URL",
1719+
environment: { T3_ACP_COPILOT_MODES: "1" },
1720+
planModeId: "https://agentclientprotocol.com/protocol/session-modes#plan",
1721+
buildModeId: "https://agentclientprotocol.com/protocol/session-modes#agent",
1722+
},
1723+
{
1724+
// Without a `mode` category, T3 derives no mode state and only the config option switches.
1725+
modeIds: "Copilot URL collaboration_mode",
1726+
environment: { T3_ACP_COPILOT_MODES: "1", T3_ACP_MODE_OPTION_CATEGORY: "collaboration_mode" },
1727+
planModeId: "https://agentclientprotocol.com/protocol/session-modes#plan",
1728+
buildModeId: "https://agentclientprotocol.com/protocol/session-modes#agent",
1729+
},
1730+
])(
1731+
"refreshes ACP prompt instructions and native mode when the interaction mode changes ($modeIds mode ids)",
1732+
({ environment, planModeId, buildModeId }) =>
1733+
Effect.gen(function* () {
1734+
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1735+
const path = yield* Path.Path;
1736+
const selfInvocation = yield* resolveSelfInvocation();
1737+
const mockAgentPath = yield* path.fromFileUrl(
1738+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1739+
);
1740+
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
1741+
const instanceId = ProviderInstanceId.make("acp-test-instruction-transitions");
1742+
const threadId = ThreadId.make("thread-acp-instruction-transitions");
1743+
yield* (yield* McpProviderSessions.McpProviderSessions).set({
1744+
environmentId: EnvironmentId.make("environment-acp-instruction-transitions"),
1745+
threadId,
1746+
providerSessionId: "mcp-session-acp-instruction-transitions",
1747+
providerInstanceId: instanceId,
1748+
endpoint: "http://127.0.0.1:43123/mcp",
1749+
authorizationHeader: "Bearer instruction-transition-token",
1750+
browserToolsAvailable: false,
17531751
});
1754-
const defaultPolicy = policy("default");
1755-
const modelSelection = { instanceId, model: "default" } as const;
1756-
const runtime = yield* adapter.openSession({
1757-
threadId,
1758-
providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
1759-
modelSelection,
1760-
runtimePolicy: defaultPolicy,
1761-
});
1762-
const providerThread = yield* runtime.ensureThread({
1763-
threadId,
1764-
modelSelection,
1765-
runtimePolicy: defaultPolicy,
1766-
});
1767-
const now = yield* DateTime.now;
1768-
const runTurn = Effect.fnUntraced(function* (
1769-
ordinal: number,
1770-
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
1771-
messageText: string,
1772-
) {
1773-
yield* runtime.startTurn(
1774-
makeTurnInput({
1775-
threadId,
1776-
providerThread,
1777-
instanceId,
1778-
runtimePolicy,
1779-
now,
1780-
ordinal,
1781-
messageText,
1782-
}),
1752+
const adapter = yield* makeAcpAdapterV2({
1753+
instanceId,
1754+
flavor: {
1755+
driver: ACP_TEST_DRIVER,
1756+
capabilities: AcpProviderCapabilitiesV2,
1757+
makeRuntime: makeMockRuntime({
1758+
childProcessSpawner,
1759+
mockAgentPath,
1760+
protocolEvents,
1761+
environment,
1762+
}),
1763+
},
1764+
selfInvocation,
1765+
});
1766+
const policy = (interactionMode: "default" | "plan") =>
1767+
ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1768+
runtimeMode: "full-access",
1769+
interactionMode,
1770+
cwd: process.cwd(),
1771+
});
1772+
const defaultPolicy = policy("default");
1773+
const modelSelection = { instanceId, model: "default" } as const;
1774+
const runtime = yield* adapter.openSession({
1775+
threadId,
1776+
providerSessionId: ProviderSessionId.make("provider-session-acp-instruction-transitions"),
1777+
modelSelection,
1778+
runtimePolicy: defaultPolicy,
1779+
});
1780+
const providerThread = yield* runtime.ensureThread({
1781+
threadId,
1782+
modelSelection,
1783+
runtimePolicy: defaultPolicy,
1784+
});
1785+
const now = yield* DateTime.now;
1786+
const runTurn = Effect.fnUntraced(function* (
1787+
ordinal: number,
1788+
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
1789+
messageText: string,
1790+
) {
1791+
yield* runtime.startTurn(
1792+
makeTurnInput({
1793+
threadId,
1794+
providerThread,
1795+
instanceId,
1796+
runtimePolicy,
1797+
now,
1798+
ordinal,
1799+
messageText,
1800+
}),
1801+
);
1802+
yield* runtime.events.pipe(
1803+
Stream.takeUntil((event) => event.type === "turn.terminal"),
1804+
Stream.runDrain,
1805+
);
1806+
const methods: Array<string> = [];
1807+
const modeSets: Array<unknown> = [];
1808+
while (true) {
1809+
const event = yield* Queue.take(protocolEvents);
1810+
if (event.direction !== "outgoing") continue;
1811+
const method = rawProtocolMethod(event);
1812+
if (method === undefined) continue;
1813+
methods.push(method);
1814+
if (
1815+
method === "session/set_config_option" &&
1816+
rawProtocolRequestParam(event, "configId") === "mode"
1817+
) {
1818+
modeSets.push(rawProtocolRequestParam(event, "value"));
1819+
}
1820+
if (method === "session/prompt") {
1821+
const promptBlocks = rawProtocolPromptTextBlocks(event);
1822+
return {
1823+
methods,
1824+
modeSets,
1825+
prompt: promptBlocks.map((block) => block.text).join("\n"),
1826+
textBlockCount: promptBlocks.length,
1827+
};
1828+
}
1829+
}
1830+
});
1831+
1832+
const command = yield* runTurn(0, defaultPolicy, "/compact");
1833+
assert.isTrue(command.prompt.startsWith("/compact"));
1834+
assert.notInclude(command.prompt, "<t3_code_instructions>");
1835+
assert.equal(command.textBlockCount, 1);
1836+
const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
1837+
assert.equal(whitespaceCommand.prompt, " /repro-skill");
1838+
assert.equal(whitespaceCommand.textBlockCount, 1);
1839+
assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
1840+
const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
1841+
assert.equal(firstDefault.textBlockCount, 2);
1842+
assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
1843+
assert.include(firstDefault.prompt, "## T3 Code browser");
1844+
assert.include(firstDefault.prompt, "T3 Code orchestration");
1845+
assert.notInclude(
1846+
firstDefault.methods,
1847+
"session/set_config_option",
1848+
"Build should preserve the agent's advertised mode default",
17831849
);
1784-
yield* runtime.events.pipe(
1785-
Stream.takeUntil((event) => event.type === "turn.terminal"),
1786-
Stream.runDrain,
1850+
assert.include(
1851+
(yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
1852+
"Second default request.",
17871853
);
1788-
const methods: Array<string> = [];
1789-
while (true) {
1790-
const event = yield* Queue.take(protocolEvents);
1791-
if (event.direction !== "outgoing") continue;
1792-
const method = rawProtocolMethod(event);
1793-
if (method === undefined) continue;
1794-
methods.push(method);
1795-
if (method === "session/prompt") {
1796-
const promptBlocks = rawProtocolPromptTextBlocks(event);
1797-
return {
1798-
methods,
1799-
prompt: promptBlocks.map((block) => block.text).join("\n"),
1800-
textBlockCount: promptBlocks.length,
1801-
};
1802-
}
1803-
}
1804-
});
18051854

1806-
const command = yield* runTurn(0, defaultPolicy, "/compact");
1807-
assert.isTrue(command.prompt.startsWith("/compact"));
1808-
assert.notInclude(command.prompt, "<t3_code_instructions>");
1809-
assert.equal(command.textBlockCount, 1);
1810-
const whitespaceCommand = yield* runTurn(1, defaultPolicy, " /repro-skill");
1811-
assert.equal(whitespaceCommand.prompt, " /repro-skill");
1812-
assert.equal(whitespaceCommand.textBlockCount, 1);
1813-
assert.notInclude(whitespaceCommand.prompt, "<t3_code_instructions>");
1814-
const firstDefault = yield* runTurn(2, defaultPolicy, "First default request.");
1815-
assert.equal(firstDefault.textBlockCount, 2);
1816-
assert.include(firstDefault.prompt, "T3 Code interaction mode: Default");
1817-
assert.include(firstDefault.prompt, "## T3 Code browser");
1818-
assert.include(firstDefault.prompt, "T3 Code orchestration");
1819-
assert.notInclude(
1820-
firstDefault.methods,
1821-
"session/set_config_option",
1822-
"Build should preserve the agent's advertised mode default",
1823-
);
1824-
assert.include(
1825-
(yield* runTurn(3, defaultPolicy, "Second default request.")).prompt,
1826-
"Second default request.",
1827-
);
1828-
1829-
const planPolicy = policy("plan");
1830-
const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
1831-
assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
1832-
assert.include(firstPlan.methods, "session/set_config_option");
1833-
assert.include(
1834-
(yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
1835-
"Continue planning.",
1836-
);
1837-
const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
1838-
assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
1839-
assert.include(
1840-
restoredBuild.methods,
1841-
"session/set_config_option",
1842-
"Build should restore the native mode that T3 temporarily replaced for Plan",
1843-
);
1844-
}).pipe(Effect.provide(layerTest), Effect.scoped),
1855+
const planPolicy = policy("plan");
1856+
const firstPlan = yield* runTurn(4, planPolicy, "Plan this change.");
1857+
assert.include(firstPlan.prompt, "T3 Code interaction mode: Plan");
1858+
assert.deepEqual(firstPlan.modeSets, [planModeId]);
1859+
assert.include(
1860+
(yield* runTurn(5, planPolicy, "Continue planning.")).prompt,
1861+
"Continue planning.",
1862+
);
1863+
const restoredBuild = yield* runTurn(6, defaultPolicy, "Implement the change.");
1864+
assert.include(restoredBuild.prompt, "T3 Code interaction mode: Default");
1865+
assert.deepEqual(
1866+
restoredBuild.modeSets,
1867+
[buildModeId],
1868+
"Build should restore the native mode that T3 temporarily replaced for Plan",
1869+
);
1870+
}).pipe(Effect.provide(layerTest), Effect.scoped),
18451871
);
18461872

18471873
it.live(

0 commit comments

Comments
 (0)