@@ -82,6 +82,7 @@ const event = (
8282 id : `evt_${ type . replaceAll ( "." , "" ) } 0000` ,
8383 created : 1 ,
8484 type,
85+ ...( type . startsWith ( "rpc." ) ? { location : { directory : WORK } } : { } ) ,
8586 data,
8687 durable : { ...durable . durable , version } ,
8788 } ,
@@ -163,6 +164,7 @@ const withInstructions = (
163164 "session.compact" ,
164165 "command.list" ,
165166 "skill.list" ,
167+ "rpc.call" ,
166168 ] . includes ( String ( entry . frame . type ) ) ,
167169 ) ;
168170 const after = entries . findIndex (
@@ -422,6 +424,17 @@ const history = {
422424 cursor : { } ,
423425} ;
424426
427+ const nativeGoal = ( status : "active" | "paused" | "complete" ) => ( {
428+ id : "goal-1" ,
429+ objective : "Write proof.txt" ,
430+ status,
431+ rounds : 2 ,
432+ maxRounds : 100 ,
433+ boot : "boot-1" ,
434+ updatedAt : 1 ,
435+ reason : "Checked proof.txt" ,
436+ } ) ;
437+
425438it . layer ( McpProviderSessions . layer ) ( "OpenCode2 adapter" , ( it ) => {
426439 it . effect ( "switches the session's model and variant before a turn that changed them" , ( ) =>
427440 Effect . gen ( function * ( ) {
@@ -5031,6 +5044,133 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
50315044 assert . lengthOf ( offers , 1 ) ;
50325045 } ) . pipe ( Effect . scoped , Effect . provide ( IdAllocator . layer ) ) ,
50335046 ) ;
5047+ it . effect ( "reads an existing OpenCode 2.2.5 goal when resuming a session" , ( ) =>
5048+ Effect . gen ( function * ( ) {
5049+ const runtime = yield * openCode2ReplayRuntime (
5050+ [
5051+ ...opening ,
5052+ out ( "session.get" , { sessionID : SESSION } ) ,
5053+ replyData ( "session.get" , sessionInfo ( ) ) ,
5054+ ...noOpenRequests ,
5055+ out ( "rpc.call" , {
5056+ rpcID : "opencode.goal" ,
5057+ method : "get" ,
5058+ "location[directory]" : WORK ,
5059+ input : { sessionID : SESSION } ,
5060+ } ) ,
5061+ reply ( "rpc.call" , { output : nativeGoal ( "paused" ) } ) ,
5062+ ] ,
5063+ { version : "2.2.5" } ,
5064+ ) ;
5065+ const thread = yield * runtime . resumeThread ( {
5066+ providerThread : providerThread ( yield * DateTime . now ) ,
5067+ threadId,
5068+ modelSelection : bigPickle ,
5069+ runtimePolicy : policy ( ) ,
5070+ } ) ;
5071+ assert . deepEqual ( thread . goal , {
5072+ objective : "Write proof.txt" ,
5073+ status : "paused" ,
5074+ checks : 2 ,
5075+ lastCheck : "Checked proof.txt" ,
5076+ } ) ;
5077+ } ) . pipe ( Effect . scoped ) ,
5078+ ) ;
5079+
5080+ it . effect . each ( [ "complete" , "paused" ] as const ) (
5081+ "keeps an OpenCode goal turn open across executions until its goal is %s" ,
5082+ ( status ) =>
5083+ Effect . gen ( function * ( ) {
5084+ const { runtime, thread } = yield * resumed ( [
5085+ out ( "command.list" , "<any>" ) ,
5086+ reply ( "command.list" , { location : { directory : WORK } , data : [ { name : "goal" } ] } ) ,
5087+ out ( "message.list" , { sessionID : SESSION , order : "desc" , limit : "1" } ) ,
5088+ reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
5089+ out ( "session.command" , { sessionID : SESSION , name : "goal" , text : "Write proof.txt" } ) ,
5090+ reply ( "session.command" , null ) ,
5091+ event ( "rpc.opencode.goal.changed" , { sessionID : SESSION , goal : nativeGoal ( "active" ) } ) ,
5092+ event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
5093+ ...( status === "complete"
5094+ ? [ event ( "session.execution.started" , { sessionID : SESSION } ) ]
5095+ : [ ] ) ,
5096+ event ( "rpc.opencode.goal.changed" , { sessionID : SESSION , goal : nativeGoal ( status ) } ) ,
5097+ ...( status === "complete"
5098+ ? [ event ( "session.execution.succeeded" , { sessionID : SESSION } ) ]
5099+ : [ ] ) ,
5100+ ] ) ;
5101+ const events = yield * runtime . events . pipe (
5102+ Stream . takeUntil ( ( e ) => e . type === "turn.terminal" ) ,
5103+ Stream . runCollect ,
5104+ Effect . forkScoped ,
5105+ ) ;
5106+ const input = turnInput ( thread ) ;
5107+ yield * runtime . startTurn ( {
5108+ ...input ,
5109+ message : { ...input . message , text : "/goal Write proof.txt" } ,
5110+ } ) ;
5111+ const collected = yield * Fiber . join ( events ) ;
5112+ const goals = collected . flatMap ( ( e ) =>
5113+ e . type === "provider_thread.updated" && e . providerThread . goal
5114+ ? [ e . providerThread . goal ]
5115+ : [ ] ,
5116+ ) ;
5117+ assert . includeDeepMembers ( goals , [
5118+ {
5119+ objective : "Write proof.txt" ,
5120+ status : "active" ,
5121+ checks : 2 ,
5122+ lastCheck : "Checked proof.txt" ,
5123+ } ,
5124+ {
5125+ objective : "Write proof.txt" ,
5126+ status,
5127+ checks : 2 ,
5128+ lastCheck : "Checked proof.txt" ,
5129+ } ,
5130+ ] ) ;
5131+ assert . deepInclude ( collected . at ( - 1 ) , { type : "turn.terminal" , status : "completed" } ) ;
5132+ } ) . pipe ( Effect . scoped ) ,
5133+ ) ;
5134+
5135+ it . effect . each ( [ "show" , "pause" , "clear" ] as const ) (
5136+ "settles OpenCode /goal %s without waiting for an execution" ,
5137+ ( control ) =>
5138+ Effect . gen ( function * ( ) {
5139+ const goal = control === "clear" ? null : nativeGoal ( "paused" ) ;
5140+ const { runtime, thread } = yield * resumed (
5141+ control === "show"
5142+ ? [ out ( "rpc.call" , "<any>" ) , reply ( "rpc.call" , { output : goal } ) ]
5143+ : [
5144+ out ( "command.list" , "<any>" ) ,
5145+ reply ( "command.list" , { location : { directory : WORK } , data : [ { name : "goal" } ] } ) ,
5146+ out ( "message.list" , { sessionID : SESSION , order : "desc" , limit : "1" } ) ,
5147+ reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
5148+ out ( "session.command" , { sessionID : SESSION , name : "goal" , text : control } ) ,
5149+ event ( "rpc.opencode.goal.changed" , { sessionID : SESSION , goal } ) ,
5150+ reply ( "session.command" , null ) ,
5151+ ] ,
5152+ ) ;
5153+ const events = yield * runtime . events . pipe (
5154+ Stream . takeUntil ( ( e ) => e . type === "turn.terminal" ) ,
5155+ Stream . runCollect ,
5156+ Effect . forkScoped ,
5157+ ) ;
5158+ const input = turnInput ( thread ) ;
5159+ yield * runtime . startTurn ( {
5160+ ...input ,
5161+ message : { ...input . message , text : control === "show" ? "/goal" : `/goal ${ control } ` } ,
5162+ } ) ;
5163+ const collected = yield * Fiber . join ( events ) ;
5164+ const updated = collected . findLast ( ( e ) => e . type === "provider_thread.updated" ) ;
5165+ assert . equal (
5166+ updated ?. type === "provider_thread.updated"
5167+ ? ( updated . providerThread . goal ?. status ?? null )
5168+ : undefined ,
5169+ goal ?. status ?? null ,
5170+ ) ;
5171+ assert . deepInclude ( collected . at ( - 1 ) , { type : "turn.terminal" , status : "completed" } ) ;
5172+ } ) . pipe ( Effect . scoped ) ,
5173+ ) ;
50345174} ) ;
50355175
50365176const providerTurnId = Effect . gen ( function * ( ) {
0 commit comments