11import { assert , it } from "@effect/vitest" ;
22import {
3- parseGoalCommand ,
43 CheckpointScopeId ,
54 ChatAttachmentId ,
65 ChatFileAttachment ,
@@ -1043,7 +1042,7 @@ it.effect("fails the run when its ownership check cannot be read before calling
10431042 } ) ,
10441043) ;
10451044
1046- it . effect ( "preserves native compaction and goal command routing when labeling agent messages" , ( ) =>
1045+ it . effect ( "routes compaction and goal commands and marks cross-thread agent messages" , ( ) =>
10471046 Effect . gen ( function * ( ) {
10481047 const runExecution = yield * RunExecutionService . RunExecutionServiceV2 ;
10491048 const calls : Array < string > = [ ] ;
@@ -1054,113 +1053,67 @@ it.effect("preserves native compaction and goal command routing when labeling ag
10541053 mimeType : "text/plain" ,
10551054 sizeBytes : 1 ,
10561055 } ) ;
1057- const cases = [
1058- { text : " /compact " , attachments : [ ] , expected : "compact" } ,
1056+ const origin =
1057+ '[Message from another thread\'s agent (thread "thread:sender").' +
1058+ " This is agent-authored coordination, not a message from the human user.]" ;
1059+ const agent = { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } as const ;
1060+ const cases : ReadonlyArray < {
1061+ readonly text : string ;
1062+ readonly expected : string ;
1063+ readonly attachments ?: ReadonlyArray < ChatFileAttachment > ;
1064+ readonly createdBy ?: "user" | "agent" ;
1065+ readonly senderThreadId ?: ThreadId ;
1066+ readonly driver ?: ProviderDriverKind ;
1067+ readonly nativeGoals ?: boolean ;
1068+ } > = [
1069+ { text : " /compact " , expected : "compact" } ,
1070+ { text : "/compact" , attachments : [ attachment ] , expected : "/compact" } ,
1071+ { text : "Continue the work" , expected : "Continue the work" } ,
1072+ { createdBy : "agent" , text : "Continue the work" , expected : "Continue the work" } ,
1073+ { ...agent , text : "Continue the work" , expected : `${ origin } \n\nContinue the work` } ,
10591074 {
1060- text : "/workspace/src/main.ts is the file to update." ,
1061- attachments : [ ] ,
1062- expected : "prompt" ,
1063- } ,
1064- {
1065- text : "/compact keep the tests" ,
1066- attachments : [ ] ,
1067- expected : "command" ,
1075+ ...agent ,
10681076 driver : ProviderDriverKind . make ( "pi" ) ,
1069- } ,
1070- {
10711077 text : "/compact keep the tests" ,
1072- attachments : [ attachment ] ,
1073- expected : "command" ,
1074- driver : ProviderDriverKind . make ( "pi" ) ,
1075- } ,
1076- {
1077- text : "Continue the work" ,
1078- attachments : [ ] ,
1079- expected : "prompt" ,
1080- driver : ProviderDriverKind . make ( "pi" ) ,
1081- } ,
1082- {
1083- text : "/review" ,
1084- attachments : [ attachment ] ,
1085- expected : "prompt" ,
1086- driver : ProviderDriverKind . make ( "opencode" ) ,
1078+ expected : `/compact ${ origin } \n\nkeep the tests` ,
10871079 } ,
1080+ { ...agent , text : "/goal finish" , expected : `/goal ${ origin } \n\nfinish` } ,
10881081 {
1089- text : "/README.md is the file to update." ,
1090- attachments : [ ] ,
1091- expected : "prompt" ,
1092- driver : ProviderDriverKind . make ( "opencode" ) ,
1093- } ,
1094- { text : "/compact" , attachments : [ attachment ] , expected : "prompt" } ,
1095- { text : "/goal finish the work" , attachments : [ ] , expected : "goal" } ,
1096- { text : " /goal finish the work " , attachments : [ ] , expected : "goal" } ,
1097- {
1098- text : "/goal finish the work" ,
1099- attachments : [ ] ,
1100- expected : "goal" ,
1101- driver : ProviderDriverKind . make ( "claudeAgent" ) ,
1102- } ,
1103- {
1104- text : "/goal finish the work" ,
1105- attachments : [ ] ,
1106- expected : "goal" ,
1107- driver : ProviderDriverKind . make ( "opencode" ) ,
1108- nativeGoals : true ,
1109- } ,
1110- {
1111- text : "/goal clear" ,
1112- attachments : [ ] ,
1113- expected : "control" ,
1114- driver : ProviderDriverKind . make ( "opencode" ) ,
1082+ ...agent ,
1083+ driver : ProviderDriverKind . make ( "antigravity" ) ,
11151084 nativeGoals : true ,
1085+ text : "/goal finish" ,
1086+ expected : `/goal ${ origin } \n\nfinish` ,
11161087 } ,
11171088 {
1118- text : "/goal finish the work" ,
1119- attachments : [ ] ,
1120- expected : "prompt" ,
1089+ ...agent ,
11211090 driver : ProviderDriverKind . make ( "opencode" ) ,
11221091 nativeGoals : false ,
1092+ text : "/goal finish" ,
1093+ expected : `${ origin } \n\n/goal finish` ,
11231094 } ,
1124- ...[ "/goal" , "/goal edit" , "/goal clear" , "/goal pause" , "/goal resume" ] . map ( ( text ) => ( {
1125- text,
1126- attachments : [ ] ,
1127- expected : "control" ,
1128- } ) ) ,
1129- { text : "/goal finish the work" , attachments : [ attachment ] , expected : "prompt" } ,
1130- { text : "Continue the work" , attachments : [ ] , expected : "prompt" } ,
1131- ]
1132- . map ( ( testCase ) => ( { driver, ...testCase } ) )
1133- . flatMap ( ( testCase ) =>
1134- (
1135- [
1136- { createdBy : "user" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1137- { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1138- { createdBy : "agent" , senderThreadId : undefined } ,
1139- ] as const
1140- ) . map ( ( origin ) => ( { ...testCase , ...origin } ) ) ,
1141- ) ;
1095+ { ...agent , text : "/goal clear" , expected : "/goal clear" } ,
1096+ ] ;
11421097 for ( const [ index , testCase ] of cases . entries ( ) ) {
1143- const prompts : Array < ProviderAdapter . ProviderAdapterV2TurnInput > = [ ] ;
11441098 const threadId = ThreadId . make ( `thread:compact-routing:${ index } ` ) ;
11451099 const attemptId = RunAttemptId . make ( `attempt:compact-routing:${ index } ` ) ;
1100+ const caseDriver = testCase . driver ?? driver ;
11461101 yield * runExecution . startRootRun ( {
11471102 commandId : CommandId . make ( `command:compact-routing:${ index } ` ) ,
11481103 appThread : rootAppThread ( threadId ) ,
11491104 providerSessionId : ProviderSessionId . make ( `session:compact-routing:${ index } ` ) ,
11501105 session : {
1151- driver : testCase . driver ,
1106+ driver : caseDriver ,
11521107 providerSession : {
11531108 capabilities : { turns : { supportsNativeGoals : testCase . nativeGoals } } ,
11541109 } ,
11551110 events : Stream . never ,
11561111 startTurn : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
11571112 Effect . sync ( ( ) => {
1158- prompts . push ( input ) ;
1159- calls . push ( "prompt" ) ;
1113+ calls . push ( input . message . text ) ;
11601114 } ) ,
1161- compactThread : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1115+ compactThread : ( ) =>
11621116 Effect . sync ( ( ) => {
1163- assert . equal ( input . message . text , testCase . text ) ;
11641117 calls . push ( "compact" ) ;
11651118 } ) ,
11661119 } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
@@ -1178,16 +1131,16 @@ it.effect("preserves native compaction and goal command routing when labeling ag
11781131 } as OrchestrationV2CheckpointScope ,
11791132 providerThread : {
11801133 id : ProviderThreadId . make ( `provider-thread:compact-routing:${ index } ` ) ,
1181- driver : testCase . driver ,
1134+ driver : caseDriver ,
11821135 } as OrchestrationV2ProviderThread ,
11831136 attempt : { id : attemptId , providerTurnId : null } as OrchestrationV2RunAttempt ,
11841137 attemptId,
11851138 providerTurnOrdinal : 1 ,
11861139 message : {
11871140 messageId : MessageId . make ( `message:compact-routing:${ index } ` ) ,
11881141 text : testCase . text ,
1189- attachments : testCase . attachments ,
1190- createdBy : testCase . createdBy ,
1142+ attachments : testCase . attachments ?? [ ] ,
1143+ createdBy : testCase . createdBy ?? "user" ,
11911144 creationSource : "web" ,
11921145 ...( testCase . senderThreadId === undefined
11931146 ? { }
@@ -1206,34 +1159,10 @@ it.effect("preserves native compaction and goal command routing when labeling ag
12061159 } ,
12071160 } ,
12081161 } ) ;
1209- const prompt = prompts [ 0 ] ;
1210- if ( prompt !== undefined ) {
1211- if (
1212- testCase . expected !== "control" &&
1213- testCase . createdBy === "agent" &&
1214- testCase . senderThreadId !== undefined
1215- ) {
1216- assert . include ( prompt . message . text , 'thread "thread:sender"' ) ;
1217- assert . include ( prompt . message . text , "not a message from the human user" ) ;
1218- if ( testCase . expected === "goal" ) {
1219- const goal = parseGoalCommand ( prompt . message ) ;
1220- assert . equal ( goal ?. type , "set" ) ;
1221- if ( goal ?. type === "set" ) assert . isTrue ( goal . objective . endsWith ( "\n\nfinish the work" ) ) ;
1222- } else if ( testCase . expected === "command" ) {
1223- assert . isTrue ( prompt . message . text . startsWith ( "/compact [Message from" ) ) ;
1224- assert . isTrue ( prompt . message . text . endsWith ( "\n\nkeep the tests" ) ) ;
1225- } else {
1226- assert . isTrue ( prompt . message . text . endsWith ( `\n\n${ testCase . text } ` ) ) ;
1227- }
1228- } else {
1229- assert . equal ( prompt . message . text , testCase . text ) ;
1230- }
1231- assert . deepEqual ( prompt . message . attachments , testCase . attachments ) ;
1232- }
12331162 }
12341163 assert . deepEqual (
12351164 calls ,
1236- cases . map ( ( testCase ) => ( testCase . expected === "compact" ? "compact" : "prompt" ) ) ,
1165+ cases . map ( ( testCase ) => testCase . expected ) ,
12371166 ) ;
12381167 } ) . pipe ( Effect . provide ( layerRunExecutionTest ) ) ,
12391168) ;
0 commit comments