@@ -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