@@ -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 (
0 commit comments