@@ -2891,6 +2891,174 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
28912891 } ) . pipe ( Effect . scoped ) ,
28922892 ) ;
28932893
2894+ it . effect ( "projects successful native todo updates into one checklist" , ( ) =>
2895+ Effect . gen ( function * ( ) {
2896+ const updates = [
2897+ [
2898+ { content : " Inspect code " , status : "completed" } ,
2899+ { content : "Implement" , status : "in_progress" } ,
2900+ { content : "Verify" , status : "pending" } ,
2901+ { content : "Abandoned" , status : "cancelled" } ,
2902+ ] ,
2903+ [ { content : "Inspect code" , status : "completed" } ] ,
2904+ [ { content : "Abandoned" , status : "cancelled" } ] ,
2905+ [ ] ,
2906+ [ { content : "Follow up" , status : "pending" } ] ,
2907+ ] ;
2908+ const tool = ( id : string ) => ( {
2909+ sessionID : SESSION ,
2910+ assistantMessageID : "msg_assistant" ,
2911+ id,
2912+ } ) ;
2913+ const call = ( id : string , todos : unknown ) : ReadonlyArray < ProviderReplayEntry > => [
2914+ event ( "session.tool.input.started" , { ...tool ( id ) , name : "todowrite" } ) ,
2915+ event ( "session.tool.called" , { ...tool ( id ) , input : { todos } , executed : false } ) ,
2916+ ] ;
2917+ const { runtime, thread } = yield * resumed ( [
2918+ out ( "session.prompt" , { sessionID : SESSION , text : "<any>" } ) ,
2919+ promptAccepted ,
2920+ ...call ( "call-denied" , [ { content : "Not saved" , status : "pending" } ] ) ,
2921+ event (
2922+ "session.tool.failed" ,
2923+ {
2924+ ...tool ( "call-denied" ) ,
2925+ error : { type : "unknown" , message : "Unable to update todos" } ,
2926+ executed : false ,
2927+ } ,
2928+ undefined ,
2929+ 2 ,
2930+ ) ,
2931+ ...call ( "call-malformed" , [ { content : "Not saved" , status : "pending" } ] ) ,
2932+ event (
2933+ "session.tool.success" ,
2934+ {
2935+ ...tool ( "call-malformed" ) ,
2936+ content : [ { type : "text" , text : "Unrecognized todo result" } ] ,
2937+ metadata : { todos : [ { content : "Unknown" , status : "new-status" } ] } ,
2938+ executed : false ,
2939+ } ,
2940+ undefined ,
2941+ 2 ,
2942+ ) ,
2943+ ...updates . flatMap ( ( todos , index ) => [
2944+ ...call ( `call-todo-${ index } ` , todos ) ,
2945+ event (
2946+ "session.tool.success" ,
2947+ {
2948+ ...tool ( `call-todo-${ index } ` ) ,
2949+ content : [ { type : "text" , text : "Todos updated" } ] ,
2950+ metadata : { todos } ,
2951+ executed : false ,
2952+ } ,
2953+ undefined ,
2954+ 2 ,
2955+ ) ,
2956+ ] ) ,
2957+ event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
2958+ ] ) ;
2959+ const events = yield * runtime . events . pipe (
2960+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
2961+ Stream . runCollect ,
2962+ Effect . forkScoped ,
2963+ ) ;
2964+ yield * runtime . startTurn ( turnInput ( thread ) ) ;
2965+ const collected = yield * Fiber . join ( events ) ;
2966+ const plans = collected . flatMap ( ( event ) =>
2967+ event . type === "plan.updated" && event . plan . kind === "todo_list" ? [ event . plan ] : [ ] ,
2968+ ) ;
2969+ assert . deepEqual (
2970+ plans . map ( ( plan ) => plan . steps . map ( ( step ) => [ step . text , step . status ] ) ) ,
2971+ [
2972+ [
2973+ [ "Inspect code" , "completed" ] ,
2974+ [ "Implement" , "running" ] ,
2975+ [ "Verify" , "pending" ] ,
2976+ ] ,
2977+ [ [ "Inspect code" , "completed" ] ] ,
2978+ [ ] ,
2979+ [ ] ,
2980+ [ [ "Follow up" , "pending" ] ] ,
2981+ ] ,
2982+ ) ;
2983+ assert . equal ( new Set ( plans . map ( ( plan ) => plan . id ) ) . size , 1 ) ;
2984+ assert . equal ( plans [ 0 ] ?. steps [ 0 ] ?. id , plans [ 1 ] ?. steps [ 0 ] ?. id ) ;
2985+ assert . deepEqual (
2986+ plans . map ( ( plan ) => plan . status ) ,
2987+ [ "active" , "completed" , "completed" , "completed" , "active" ] ,
2988+ ) ;
2989+ const items = collected . flatMap ( ( event ) =>
2990+ event . type === "turn_item.updated" ? [ event . turnItem ] : [ ] ,
2991+ ) ;
2992+ const checklists = items . filter ( ( item ) => item . type === "todo_list" ) ;
2993+ assert . equal ( new Set ( checklists . map ( ( item ) => item . id ) ) . size , 1 ) ;
2994+ assert . deepEqual (
2995+ checklists . map ( ( item ) => item . steps ) ,
2996+ plans . map ( ( plan ) => plan . steps ) ,
2997+ ) ;
2998+ assert . deepEqual (
2999+ checklists . map ( ( item ) => item . status ) ,
3000+ [ "completed" , "completed" , "completed" , "completed" , "completed" ] ,
3001+ ) ;
3002+ assert . isFalse (
3003+ items . some (
3004+ ( item ) =>
3005+ item . type === "dynamic_tool" && item . nativeItemRef ?. nativeId ?. startsWith ( "call-todo-" ) ,
3006+ ) ,
3007+ ) ;
3008+ assert . deepInclude (
3009+ items . find ( ( item ) => item . nativeItemRef ?. nativeId === "call-denied" ) ,
3010+ { type : "dynamic_tool" , status : "failed" } ,
3011+ ) ;
3012+ assert . deepInclude (
3013+ items . find ( ( item ) => item . nativeItemRef ?. nativeId === "call-malformed" ) ,
3014+ { type : "dynamic_tool" , status : "completed" } ,
3015+ ) ;
3016+ } ) . pipe ( Effect . scoped ) ,
3017+ ) ;
3018+
3019+ it . effect ( "recovers native todo updates missed during reconnect" , ( ) =>
3020+ Effect . gen ( function * ( ) {
3021+ const todos = [ { content : "Saved during disconnect" , status : "in_progress" } ] ;
3022+ const { runtime, thread } = yield * resumed ( [
3023+ out ( "session.prompt" , { sessionID : SESSION , id : PROMPT_ID , text : "<any>" } ) ,
3024+ promptAccepted ,
3025+ ...reconnected ( { } , "succeeded" , {
3026+ content : [
3027+ {
3028+ type : "tool" ,
3029+ id : "call-todo-gap" ,
3030+ name : "todowrite" ,
3031+ executed : false ,
3032+ state : {
3033+ status : "completed" ,
3034+ input : { todos } ,
3035+ content : [ { type : "text" , text : "Todos updated" } ] ,
3036+ metadata : { todos } ,
3037+ } ,
3038+ time : { created : 2 , ran : 2 , completed : 2 } ,
3039+ } ,
3040+ ] ,
3041+ } ) ,
3042+ ] ) ;
3043+ const events = yield * runtime . events . pipe (
3044+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
3045+ Stream . runCollect ,
3046+ Effect . forkScoped ,
3047+ ) ;
3048+ yield * runtime . startTurn ( turnInput ( thread ) ) ;
3049+ const collected = yield * Fiber . join ( events ) ;
3050+ const plans = collected . flatMap ( ( event ) =>
3051+ event . type === "plan.updated" && event . plan . kind === "todo_list" ? [ event . plan ] : [ ] ,
3052+ ) ;
3053+ assert . equal ( plans . length , 1 ) ;
3054+ assert . deepEqual (
3055+ plans [ 0 ] ?. steps . map ( ( step ) => [ step . text , step . status ] ) ,
3056+ [ [ "Saved during disconnect" , "running" ] ] ,
3057+ ) ;
3058+ assert . include ( turnItems ( collected ) , "todo_list:completed" ) ;
3059+ } ) . pipe ( Effect . scoped ) ,
3060+ ) ;
3061+
28943062 it . effect ( "stores a shell command that exits non-zero as failed" , ( ) =>
28953063 Effect . gen ( function * ( ) {
28963064 const tool = { sessionID : SESSION , assistantMessageID : "msg_assistant" , id : "call-exit" } ;
0 commit comments