@@ -11,6 +11,7 @@ import { RPC_METHODS } from '@hapi/protocol/rpcMethods';
1111import { createOpencodeBackend } from './utils/opencodeBackend' ;
1212import { OpencodePermissionHandler } from './utils/permissionHandler' ;
1313import { PLAN_MODE_INSTRUCTION , TITLE_INSTRUCTION } from './utils/systemPrompt' ;
14+ import { resolveThoughtLevelEffort } from './thoughtLevelEffort' ;
1415
1516type OpencodeRemoteLauncherOptions = {
1617 onReasoningEffortRollback ?: ( effort : string | null ) => void ;
@@ -123,6 +124,18 @@ class OpencodeRemoteLauncher extends RemoteLauncherBase {
123124 } ;
124125 } ) ;
125126
127+ session . client . rpcHandlerManager . registerHandler ( RPC_METHODS . ListOpencodeReasoningEffortOptions , async ( ) => {
128+ const effortOption = backend . getThoughtLevelConfigOption ?.( acpSessionId ) ;
129+ if ( ! effortOption ) {
130+ return { success : false , error : 'OpenCode reasoning effort options are not available' } ;
131+ }
132+ return {
133+ success : true ,
134+ options : effortOption . options ,
135+ currentValue : effortOption . currentValue ?? null
136+ } ;
137+ } ) ;
138+
126139 this . permissionHandler = new OpencodePermissionHandler (
127140 session . client ,
128141 backend ,
@@ -206,29 +219,43 @@ class OpencodeRemoteLauncher extends RemoteLauncherBase {
206219 if ( ! backend . setConfigOption || ! thoughtLevelOption || this . setEffortSupported === false ) {
207220 this . rollbackReasoningEffort ( batch , this . currentBackendEffort ) ;
208221 } else {
209- logger . debug ( `[opencode-remote] Switching effort inline: ${ this . currentBackendEffort ?? '(default)' } -> ${ requestedEffort } ` ) ;
210- try {
211- await backend . setConfigOption ( acpSessionId , thoughtLevelOption . id , requestedEffort ) ;
212- this . currentBackendEffort = requestedEffort ;
213- this . setEffortSupported = true ;
214- } catch ( error ) {
215- const message = error instanceof Error ? error . message : String ( error ) ;
216- const methodNotFound = / m e t h o d n o t f o u n d / i. test ( message ) ;
217- if ( methodNotFound && this . setEffortSupported === undefined ) {
218- this . setEffortSupported = false ;
219- logger . warn ( '[opencode-remote] OpenCode build does not support session/set_config_option; inline effort switching disabled for this session' ) ;
220- session . sendSessionEvent ( {
221- type : 'message' ,
222- message : 'This OpenCode build does not support inline reasoning effort switching.'
223- } ) ;
224- } else {
225- logger . warn ( '[opencode-remote] Inline effort switch failed' , error ) ;
226- session . sendSessionEvent ( {
227- type : 'message' ,
228- message : `Failed to switch reasoning effort to ${ requestedEffort } . Continuing with ${ this . currentBackendEffort ?? '(default)' } .`
229- } ) ;
222+ const resolvedEffort = resolveThoughtLevelEffort (
223+ requestedEffort ,
224+ thoughtLevelOption ,
225+ this . currentBackendEffort ?? this . defaultBackendEffort
226+ ) ;
227+ if ( ! resolvedEffort || resolvedEffort === this . currentBackendEffort ) {
228+ if ( requestedEffort !== resolvedEffort ) {
229+ logger . warn (
230+ `[opencode-remote] Unsupported reasoning effort "${ requestedEffort } "; continuing with ${ resolvedEffort ?? this . currentBackendEffort ?? '(default)' } `
231+ ) ;
232+ this . rollbackReasoningEffort ( batch , resolvedEffort ?? this . currentBackendEffort ) ;
233+ }
234+ } else {
235+ logger . debug ( `[opencode-remote] Switching effort inline: ${ this . currentBackendEffort ?? '(default)' } -> ${ resolvedEffort } ` ) ;
236+ try {
237+ await backend . setConfigOption ( acpSessionId , thoughtLevelOption . id , resolvedEffort ) ;
238+ this . currentBackendEffort = resolvedEffort ;
239+ this . setEffortSupported = true ;
240+ } catch ( error ) {
241+ const message = error instanceof Error ? error . message : String ( error ) ;
242+ const methodNotFound = / m e t h o d n o t f o u n d / i. test ( message ) ;
243+ if ( methodNotFound && this . setEffortSupported === undefined ) {
244+ this . setEffortSupported = false ;
245+ logger . warn ( '[opencode-remote] OpenCode build does not support session/set_config_option; inline effort switching disabled for this session' ) ;
246+ session . sendSessionEvent ( {
247+ type : 'message' ,
248+ message : 'This OpenCode build does not support inline reasoning effort switching.'
249+ } ) ;
250+ } else {
251+ logger . warn ( '[opencode-remote] Inline effort switch failed' , error ) ;
252+ session . sendSessionEvent ( {
253+ type : 'message' ,
254+ message : `Failed to switch reasoning effort to ${ resolvedEffort } . Continuing with ${ this . currentBackendEffort ?? '(default)' } .`
255+ } ) ;
256+ }
257+ this . rollbackReasoningEffort ( batch , this . currentBackendEffort ) ;
230258 }
231- this . rollbackReasoningEffort ( batch , this . currentBackendEffort ) ;
232259 }
233260 }
234261 }
0 commit comments