The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 08:15 UTC
fix(acp): Plan mode switches Copilot into its native plan mode (#26951)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Radu-Stefan Popa committed
Nov 1, 2026 at 04:35 UTC
17c837c52253b5cb60c1868ee92b923dcb4d9279
3 files changed
+195
-150
apps/server/scripts/acp-mock-agent.ts
+34
-19
@@ -18,6 +18,11 @@ import { beginAcpMockPrompt } from "./acpMockCancellationState.ts";
18
19
const requestLogPath = process.env.T3_ACP_REQUEST_LOG_PATH;
20
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";
26
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
27
const emitInterleavedAssistantToolCalls =
28
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -74,7 +79,11 @@ const permissionOptionIds = {
79
};
80
const sessionId = "mock-session-1";
81
77
-let currentModeId = antigravityProfile ? "default" : "ask";
82
+let currentModeId = antigravityProfile
83
+ ? "default"
84
+ : copilotModesProfile
85
+ ? copilotModeId("agent")
86
+ : "ask";
87
let currentModelId = antigravityProfile ? "gemini-test-low" : "default";
88
let parameterizedModelPicker = false;
89
let currentReasoning = "medium";
@@ -263,7 +272,7 @@ function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
272
{
273
configId: "mode",
274
name: "Mode",
266
- category: "mode",
275
+ category: modeOptionCategory,
276
type: "select" as const,
277
currentValue: currentModeId,
278
options: availableModes.map((mode) => ({
@@ -328,23 +337,29 @@ const availableModes: ReadonlyArray<AcpCompat.SessionMode> = antigravityProfile
337
{ id: "auto_edit", name: "Auto edit" },
338
{ id: "yolo", name: "YOLO" },
339
]
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
+ ];
363
364
function modeState(): AcpCompat.SessionModeState {
365
return {
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+152
-126
@@ -1712,136 +1712,162 @@ describe("AcpAdapterV2", () => {
1712
}).pipe(Effect.provide(layerTest), Effect.scoped),
1713
);
1714
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,
1751
});
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",
1849
);
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.",
1853
);
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
- });
1854
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),
1871
);
1872
1873
it.live(
packages/provider-acp/src/server/adapter.ts
+9
-5
@@ -1047,6 +1047,12 @@ function completedAtForStatus(status: ProjectedToolStatus, now: DateTime.Utc): D
1047
return status === "completed" || status === "failed" || status === "interrupted" ? now : null;
1048
}
1049
1050
+// Copilot advertises URL ids such as `https://agentclientprotocol.com/protocol/session-modes#plan`.
1051
+function isAcpPlanModeId(id: string): boolean {
1052
+ const name = id.slice(id.lastIndexOf("#") + 1);
1053
+ return name === "plan" || name === "architect";
1054
+}
1055
+
1056
function selectPermissionOptionId(
1057
request: EffectAcpSchema.RequestPermissionRequest,
1058
decision: Exclude<ProviderApprovalDecision, "cancel">,
@@ -6960,8 +6966,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6966
})),
6967
});
6968
}
6963
- const planMode = effectiveModeState?.availableModes.find(
6964
- (mode) => mode.id === "plan" || mode.id === "architect",
6969
+ const planMode = effectiveModeState?.availableModes.find((mode) =>
6970
+ isAcpPlanModeId(mode.id),
6971
);
6972
if (planMode !== undefined && effectiveModeState?.currentModeId !== planMode.id) {
6973
yield* runtime.setMode(planMode.id);
@@ -6970,9 +6976,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6976
const choices = option.options.flatMap((entry) =>
6977
"value" in entry ? [entry.value] : entry.options.map((choice) => choice.value),
6978
);
6973
- const requested = choices.find(
6974
- (choice) => choice === "plan" || choice === "architect",
6975
- );
6979
+ const requested = choices.find(isAcpPlanModeId);
6980
if (requested !== undefined && option.currentValue !== requested) {
6981
yield* runtime.setConfigOption(option.id, requested);
6982
}