@@ -20,6 +20,7 @@ import {
2020 ThreadId ,
2121 type OrchestrationV2ProviderThread ,
2222 type OrchestrationV2ProviderTurn ,
23+ type ProviderOptionSelection ,
2324} from "@t3tools/contracts" ;
2425import { OpenCodeSettings } from "../settings.ts" ;
2526import * as Effect from "effect/Effect" ;
@@ -151,15 +152,22 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
151152 nativeSessionId : string ,
152153 client : object ,
153154 host : Partial < ProviderHost . ProviderHost [ "Service" ] > = { } ,
155+ turnSettings : {
156+ readonly options ?: ReadonlyArray < ProviderOptionSelection > ;
157+ readonly interactionMode ?: ProviderAdapter . ProviderAdapterV2RuntimePolicy [ "interactionMode" ] ;
158+ } = { } ,
154159) {
155160 const instanceId = ProviderInstanceId . make ( `opencode-${ suffix } ` ) ;
156161 const threadId = ThreadId . make ( `thread-opencode-${ suffix } ` ) ;
157162 const modelSelection = {
158163 instanceId,
159164 model : "anthropic/claude-sonnet" ,
160- options : [ ] ,
165+ options : turnSettings . options ?? [ ] ,
161166 } ;
162- const policy = runtimePolicy ( "full-access" , { cwd : "/workspace" } ) ;
167+ const policy = runtimePolicy ( "full-access" , {
168+ cwd : "/workspace" ,
169+ interactionMode : turnSettings . interactionMode ?? "default" ,
170+ } ) ;
163171 const adapter = yield * makeOpenCodeAdapterV2 ( {
164172 instanceId,
165173 settings : OPEN_CODE_TEST_SETTINGS ,
@@ -200,7 +208,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
200208 providerInstanceId : modelSelection . instanceId ,
201209 modelSelection,
202210 runtimeMode : "full-access" ,
203- interactionMode : "default" ,
211+ interactionMode : policy . interactionMode ,
204212 branch : null ,
205213 worktreePath : null ,
206214 activeProviderThreadId : providerThread . id ,
@@ -1588,6 +1596,62 @@ describe("OpenCodeAdapterV2", () => {
15881596 ) ,
15891597 ) ;
15901598
1599+ it . effect ( "steers with the turn's agent, reasoning variant and system instructions" , ( ) =>
1600+ Effect . gen ( function * ( ) {
1601+ const nativeEvents = asyncEventStream ( ) ;
1602+ const promptInputs : Array < { agent ?: string ; variant ?: string ; system ?: string } > = [ ] ;
1603+ const harness = yield * makeOpenCodeRuntimeHarness (
1604+ "steer-agent" ,
1605+ "root" ,
1606+ {
1607+ event : { subscribe : async ( ) => ( { stream : nativeEvents . stream } ) } ,
1608+ session : {
1609+ create : async ( ) => ( { data : { id : "root" , time : { created : 1 , updated : 1 } } } ) ,
1610+ get : async ( ) => ( { data : { id : "root" , time : { created : 1 , updated : 1 } } } ) ,
1611+ messages : async ( ) => ( { data : [ ] } ) ,
1612+ promptAsync : async ( input : { agent ?: string ; variant ?: string ; system ?: string } ) => {
1613+ promptInputs . push ( input ) ;
1614+ return { data : true } ;
1615+ } ,
1616+ abort : async ( ) => ( { data : true } ) ,
1617+ children : async ( ) => ( { data : [ ] } ) ,
1618+ } ,
1619+ } ,
1620+ { } ,
1621+ { options : [ { id : "variant" , value : "high" } ] , interactionMode : "plan" } ,
1622+ ) ;
1623+ yield * harness . startTurn ( ) ;
1624+ const snapshot = yield * harness . runtime . readThreadSnapshot ( {
1625+ providerThread : harness . providerThread ,
1626+ } ) ;
1627+ yield * harness . runtime . steerTurn ( {
1628+ threadId : harness . threadId ,
1629+ runId : harness . runId ,
1630+ providerThread : harness . providerThread ,
1631+ providerTurnId : snapshot . providerTurns . at ( - 1 ) ! . id ,
1632+ message : {
1633+ messageId : MessageId . make ( "message-opencode-steer-agent" ) ,
1634+ text : "also cover the README" ,
1635+ attachments : [ ] ,
1636+ createdBy : "user" ,
1637+ creationSource : "web" ,
1638+ } ,
1639+ } ) ;
1640+
1641+ const [ start , steer ] = promptInputs ;
1642+ assert . equal ( start ?. agent , "plan" ) ;
1643+ assert . equal ( start ?. variant , "high" ) ;
1644+ assert . include ( start ?. system ?? "" , "OpenCode" ) ;
1645+ assert . deepEqual (
1646+ { agent : steer ?. agent , variant : steer ?. variant , system : steer ?. system } ,
1647+ { agent : start ?. agent , variant : start ?. variant , system : start ?. system } ,
1648+ ) ;
1649+ } ) . pipe (
1650+ Effect . provide ( Layer . merge ( IdAllocator . layer , McpProviderSessions . layer ) ) ,
1651+ Effect . scoped ,
1652+ ) ,
1653+ ) ;
1654+
15911655 it . effect ( "keeps a newly admitted prompt alive across stale idle and delayed busy evidence" , ( ) =>
15921656 Effect . gen ( function * ( ) {
15931657 const nativeEvents = asyncEventStream ( ) ;
0 commit comments