@@ -1039,178 +1039,199 @@ it.effect("fails the run when its ownership check cannot be read before calling
10391039 } ) ,
10401040) ;
10411041
1042- it . effect (
1043- "dispatches only attachment-free compact commands through the native compaction path" ,
1044- ( ) =>
1045- Effect . gen ( function * ( ) {
1046- const runExecution = yield * RunExecutionService . RunExecutionServiceV2 ;
1047- const calls : Array < string > = [ ] ;
1048- const attachment = ChatFileAttachment . make ( {
1049- type : "file" ,
1050- id : ChatAttachmentId . make ( "compact-file-12345678-1234-1234-1234-123456789abc" ) ,
1051- name : "notes.txt" ,
1052- mimeType : "text/plain" ,
1053- sizeBytes : 1 ,
1054- } ) ;
1055- const cases = [
1056- { text : " /compact " , attachments : [ ] , expected : "compact" } ,
1057- {
1058- text : "/workspace/src/main.ts is the file to update." ,
1059- attachments : [ ] ,
1060- expected : "prompt" ,
1061- } ,
1062- {
1063- text : "/compact keep the tests" ,
1064- attachments : [ ] ,
1065- expected : "command" ,
1066- driver : ProviderDriverKind . make ( "pi" ) ,
1067- } ,
1068- {
1069- text : "/compact keep the tests" ,
1070- attachments : [ attachment ] ,
1071- expected : "command" ,
1072- driver : ProviderDriverKind . make ( "pi" ) ,
1073- } ,
1074- {
1075- text : "Continue the work" ,
1076- attachments : [ ] ,
1077- expected : "prompt" ,
1078- driver : ProviderDriverKind . make ( "pi" ) ,
1079- } ,
1080- {
1081- text : "/review" ,
1082- attachments : [ attachment ] ,
1083- expected : "prompt" ,
1084- driver : ProviderDriverKind . make ( "opencode" ) ,
1085- } ,
1086- {
1087- text : "/README.md is the file to update." ,
1088- attachments : [ ] ,
1089- expected : "prompt" ,
1090- driver : ProviderDriverKind . make ( "opencode" ) ,
1091- } ,
1092- { text : "/compact" , attachments : [ attachment ] , expected : "prompt" } ,
1093- { text : "/goal finish the work" , attachments : [ ] , expected : "goal" } ,
1094- { text : " /goal finish the work " , attachments : [ ] , expected : "goal" } ,
1095- {
1096- text : "/goal finish the work" ,
1097- attachments : [ ] ,
1098- expected : "goal" ,
1099- driver : ProviderDriverKind . make ( "claudeAgent" ) ,
1100- } ,
1101- ...[ "/goal" , "/goal edit" , "/goal clear" , "/goal pause" , "/goal resume" ] . map ( ( text ) => ( {
1102- text,
1103- attachments : [ ] ,
1104- expected : "control" ,
1105- } ) ) ,
1106- { text : "/goal finish the work" , attachments : [ attachment ] , expected : "prompt" } ,
1107- { text : "Continue the work" , attachments : [ ] , expected : "prompt" } ,
1108- ]
1109- . map ( ( testCase ) => ( { driver, ...testCase } ) )
1110- . flatMap ( ( testCase ) =>
1111- (
1112- [
1113- { createdBy : "user" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1114- { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1115- { createdBy : "agent" , senderThreadId : undefined } ,
1116- ] as const
1117- ) . map ( ( origin ) => ( { ...testCase , ...origin } ) ) ,
1118- ) ;
1119- for ( const [ index , testCase ] of cases . entries ( ) ) {
1120- const prompts : Array < ProviderAdapter . ProviderAdapterV2TurnInput > = [ ] ;
1121- const threadId = ThreadId . make ( `thread:compact-routing:${ index } ` ) ;
1122- const attemptId = RunAttemptId . make ( `attempt:compact-routing:${ index } ` ) ;
1123- yield * runExecution . startRootRun ( {
1124- commandId : CommandId . make ( `command:compact-routing:${ index } ` ) ,
1125- appThread : rootAppThread ( threadId ) ,
1126- providerSessionId : ProviderSessionId . make ( `session:compact-routing:${ index } ` ) ,
1127- session : {
1128- driver : testCase . driver ,
1129- events : Stream . never ,
1130- startTurn : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1131- Effect . sync ( ( ) => {
1132- prompts . push ( input ) ;
1133- calls . push ( "prompt" ) ;
1134- } ) ,
1135- compactThread : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1136- Effect . sync ( ( ) => {
1137- assert . equal ( input . message . text , testCase . text ) ;
1138- calls . push ( "compact" ) ;
1139- } ) ,
1140- } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
1141- run : {
1142- id : RunId . make ( `run:compact-routing:${ index } ` ) ,
1143- threadId,
1144- ordinal : 1 ,
1145- providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
1146- } as OrchestrationV2Run ,
1147- rootNode : {
1148- id : NodeId . make ( `node:compact-routing:${ index } ` ) ,
1149- } as OrchestrationV2ExecutionNode ,
1150- checkpointScope : {
1151- id : CheckpointScopeId . make ( `checkpoint:compact-routing:${ index } ` ) ,
1152- } as OrchestrationV2CheckpointScope ,
1153- providerThread : {
1154- id : ProviderThreadId . make ( `provider-thread:compact-routing:${ index } ` ) ,
1155- driver : testCase . driver ,
1156- } as OrchestrationV2ProviderThread ,
1157- attempt : { id : attemptId , providerTurnId : null } as OrchestrationV2RunAttempt ,
1158- attemptId,
1159- providerTurnOrdinal : 1 ,
1160- message : {
1161- messageId : MessageId . make ( `message:compact-routing:${ index } ` ) ,
1162- text : testCase . text ,
1163- attachments : testCase . attachments ,
1164- createdBy : testCase . createdBy ,
1165- creationSource : "web" ,
1166- ...( testCase . senderThreadId === undefined
1167- ? { }
1168- : { senderThreadId : testCase . senderThreadId } ) ,
1042+ it . effect ( "preserves native compaction and goal command routing when labeling agent messages" , ( ) =>
1043+ Effect . gen ( function * ( ) {
1044+ const runExecution = yield * RunExecutionService . RunExecutionServiceV2 ;
1045+ const calls : Array < string > = [ ] ;
1046+ const attachment = ChatFileAttachment . make ( {
1047+ type : "file" ,
1048+ id : ChatAttachmentId . make ( "compact-file-12345678-1234-1234-1234-123456789abc" ) ,
1049+ name : "notes.txt" ,
1050+ mimeType : "text/plain" ,
1051+ sizeBytes : 1 ,
1052+ } ) ;
1053+ const cases = [
1054+ { text : " /compact " , attachments : [ ] , expected : "compact" } ,
1055+ {
1056+ text : "/workspace/src/main.ts is the file to update." ,
1057+ attachments : [ ] ,
1058+ expected : "prompt" ,
1059+ } ,
1060+ {
1061+ text : "/compact keep the tests" ,
1062+ attachments : [ ] ,
1063+ expected : "command" ,
1064+ driver : ProviderDriverKind . make ( "pi" ) ,
1065+ } ,
1066+ {
1067+ text : "/compact keep the tests" ,
1068+ attachments : [ attachment ] ,
1069+ expected : "command" ,
1070+ driver : ProviderDriverKind . make ( "pi" ) ,
1071+ } ,
1072+ {
1073+ text : "Continue the work" ,
1074+ attachments : [ ] ,
1075+ expected : "prompt" ,
1076+ driver : ProviderDriverKind . make ( "pi" ) ,
1077+ } ,
1078+ {
1079+ text : "/review" ,
1080+ attachments : [ attachment ] ,
1081+ expected : "prompt" ,
1082+ driver : ProviderDriverKind . make ( "opencode" ) ,
1083+ } ,
1084+ {
1085+ text : "/README.md is the file to update." ,
1086+ attachments : [ ] ,
1087+ expected : "prompt" ,
1088+ driver : ProviderDriverKind . make ( "opencode" ) ,
1089+ } ,
1090+ { text : "/compact" , attachments : [ attachment ] , expected : "prompt" } ,
1091+ { text : "/goal finish the work" , attachments : [ ] , expected : "goal" } ,
1092+ { text : " /goal finish the work " , attachments : [ ] , expected : "goal" } ,
1093+ {
1094+ text : "/goal finish the work" ,
1095+ attachments : [ ] ,
1096+ expected : "goal" ,
1097+ driver : ProviderDriverKind . make ( "claudeAgent" ) ,
1098+ } ,
1099+ {
1100+ text : "/goal finish the work" ,
1101+ attachments : [ ] ,
1102+ expected : "goal" ,
1103+ driver : ProviderDriverKind . make ( "opencode" ) ,
1104+ nativeGoals : true ,
1105+ } ,
1106+ {
1107+ text : "/goal clear" ,
1108+ attachments : [ ] ,
1109+ expected : "control" ,
1110+ driver : ProviderDriverKind . make ( "opencode" ) ,
1111+ nativeGoals : true ,
1112+ } ,
1113+ {
1114+ text : "/goal finish the work" ,
1115+ attachments : [ ] ,
1116+ expected : "prompt" ,
1117+ driver : ProviderDriverKind . make ( "opencode" ) ,
1118+ nativeGoals : false ,
1119+ } ,
1120+ ...[ "/goal" , "/goal edit" , "/goal clear" , "/goal pause" , "/goal resume" ] . map ( ( text ) => ( {
1121+ text,
1122+ attachments : [ ] ,
1123+ expected : "control" ,
1124+ } ) ) ,
1125+ { text : "/goal finish the work" , attachments : [ attachment ] , expected : "prompt" } ,
1126+ { text : "Continue the work" , attachments : [ ] , expected : "prompt" } ,
1127+ ]
1128+ . map ( ( testCase ) => ( { driver, ...testCase } ) )
1129+ . flatMap ( ( testCase ) =>
1130+ (
1131+ [
1132+ { createdBy : "user" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1133+ { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1134+ { createdBy : "agent" , senderThreadId : undefined } ,
1135+ ] as const
1136+ ) . map ( ( origin ) => ( { ...testCase , ...origin } ) ) ,
1137+ ) ;
1138+ for ( const [ index , testCase ] of cases . entries ( ) ) {
1139+ const prompts : Array < ProviderAdapter . ProviderAdapterV2TurnInput > = [ ] ;
1140+ const threadId = ThreadId . make ( `thread:compact-routing:${ index } ` ) ;
1141+ const attemptId = RunAttemptId . make ( `attempt:compact-routing:${ index } ` ) ;
1142+ yield * runExecution . startRootRun ( {
1143+ commandId : CommandId . make ( `command:compact-routing:${ index } ` ) ,
1144+ appThread : rootAppThread ( threadId ) ,
1145+ providerSessionId : ProviderSessionId . make ( `session:compact-routing:${ index } ` ) ,
1146+ session : {
1147+ driver : testCase . driver ,
1148+ providerSession : {
1149+ capabilities : { turns : { supportsNativeGoals : testCase . nativeGoals } } ,
11691150 } ,
1170- modelSelection : { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.4" } ,
1171- runtimePolicy : {
1172- runtimeMode : "full-access" ,
1173- interactionMode : "default" ,
1174- cwd : process . cwd ( ) ,
1175- approvalPolicy : "never" ,
1176- sandboxPolicy : {
1177- type : "readOnly" ,
1178- access : { type : "fullAccess" } ,
1179- networkAccess : false ,
1180- } ,
1151+ events : Stream . never ,
1152+ startTurn : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1153+ Effect . sync ( ( ) => {
1154+ prompts . push ( input ) ;
1155+ calls . push ( "prompt" ) ;
1156+ } ) ,
1157+ compactThread : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1158+ Effect . sync ( ( ) => {
1159+ assert . equal ( input . message . text , testCase . text ) ;
1160+ calls . push ( "compact" ) ;
1161+ } ) ,
1162+ } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
1163+ run : {
1164+ id : RunId . make ( `run:compact-routing:${ index } ` ) ,
1165+ threadId,
1166+ ordinal : 1 ,
1167+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
1168+ } as OrchestrationV2Run ,
1169+ rootNode : {
1170+ id : NodeId . make ( `node:compact-routing:${ index } ` ) ,
1171+ } as OrchestrationV2ExecutionNode ,
1172+ checkpointScope : {
1173+ id : CheckpointScopeId . make ( `checkpoint:compact-routing:${ index } ` ) ,
1174+ } as OrchestrationV2CheckpointScope ,
1175+ providerThread : {
1176+ id : ProviderThreadId . make ( `provider-thread:compact-routing:${ index } ` ) ,
1177+ driver : testCase . driver ,
1178+ } as OrchestrationV2ProviderThread ,
1179+ attempt : { id : attemptId , providerTurnId : null } as OrchestrationV2RunAttempt ,
1180+ attemptId,
1181+ providerTurnOrdinal : 1 ,
1182+ message : {
1183+ messageId : MessageId . make ( `message:compact-routing:${ index } ` ) ,
1184+ text : testCase . text ,
1185+ attachments : testCase . attachments ,
1186+ createdBy : testCase . createdBy ,
1187+ creationSource : "web" ,
1188+ ...( testCase . senderThreadId === undefined
1189+ ? { }
1190+ : { senderThreadId : testCase . senderThreadId } ) ,
1191+ } ,
1192+ modelSelection : { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.4" } ,
1193+ runtimePolicy : {
1194+ runtimeMode : "full-access" ,
1195+ interactionMode : "default" ,
1196+ cwd : process . cwd ( ) ,
1197+ approvalPolicy : "never" ,
1198+ sandboxPolicy : {
1199+ type : "readOnly" ,
1200+ access : { type : "fullAccess" } ,
1201+ networkAccess : false ,
11811202 } ,
1182- } ) ;
1183- const prompt = prompts [ 0 ] ;
1184- if ( prompt !== undefined ) {
1185- if (
1186- testCase . expected !== "control" &&
1187- testCase . createdBy === "agent" &&
1188- testCase . senderThreadId !== undefined
1189- ) {
1190- assert . include ( prompt . message . text , 'thread "thread:sender"' ) ;
1191- assert . include ( prompt . message . text , "not a message from the human user" ) ;
1192- if ( testCase . expected === "goal" ) {
1193- const goal = parseGoalCommand ( prompt . message ) ;
1194- assert . equal ( goal ?. type , "set" ) ;
1195- if ( goal ?. type === "set" )
1196- assert . isTrue ( goal . objective . endsWith ( "\n\nfinish the work" ) ) ;
1197- } else if ( testCase . expected === "command" ) {
1198- assert . isTrue ( prompt . message . text . startsWith ( "/compact [Message from" ) ) ;
1199- assert . isTrue ( prompt . message . text . endsWith ( "\n\nkeep the tests" ) ) ;
1200- } else {
1201- assert . isTrue ( prompt . message . text . endsWith ( `\n\n${ testCase . text } ` ) ) ;
1202- }
1203+ } ,
1204+ } ) ;
1205+ const prompt = prompts [ 0 ] ;
1206+ if ( prompt !== undefined ) {
1207+ if (
1208+ testCase . expected !== "control" &&
1209+ testCase . createdBy === "agent" &&
1210+ testCase . senderThreadId !== undefined
1211+ ) {
1212+ assert . include ( prompt . message . text , 'thread "thread:sender"' ) ;
1213+ assert . include ( prompt . message . text , "not a message from the human user" ) ;
1214+ if ( testCase . expected === "goal" ) {
1215+ const goal = parseGoalCommand ( prompt . message ) ;
1216+ assert . equal ( goal ?. type , "set" ) ;
1217+ if ( goal ?. type === "set" ) assert . isTrue ( goal . objective . endsWith ( "\n\nfinish the work" ) ) ;
1218+ } else if ( testCase . expected === "command" ) {
1219+ assert . isTrue ( prompt . message . text . startsWith ( "/compact [Message from" ) ) ;
1220+ assert . isTrue ( prompt . message . text . endsWith ( "\n\nkeep the tests" ) ) ;
12031221 } else {
1204- assert . equal ( prompt . message . text , testCase . text ) ;
1222+ assert . isTrue ( prompt . message . text . endsWith ( `\n\n ${ testCase . text } ` ) ) ;
12051223 }
1206- assert . deepEqual ( prompt . message . attachments , testCase . attachments ) ;
1224+ } else {
1225+ assert . equal ( prompt . message . text , testCase . text ) ;
12071226 }
1227+ assert . deepEqual ( prompt . message . attachments , testCase . attachments ) ;
12081228 }
1209- assert . deepEqual (
1210- calls ,
1211- cases . map ( ( testCase ) => ( testCase . expected === "compact" ? "compact" : "prompt" ) ) ,
1212- ) ;
1213- } ) . pipe ( Effect . provide ( layerRunExecutionTest ) ) ,
1229+ }
1230+ assert . deepEqual (
1231+ calls ,
1232+ cases . map ( ( testCase ) => ( testCase . expected === "compact" ? "compact" : "prompt" ) ) ,
1233+ ) ;
1234+ } ) . pipe ( Effect . provide ( layerRunExecutionTest ) ) ,
12141235) ;
12151236
12161237it . effect ( "starts the provider when checkpoint baseline capture fails" , ( ) =>
0 commit comments