@@ -169,7 +169,7 @@ function applyAliases(body, plan) {
169169 * are preserved untouched. Pass a plan from {@link planToolAliases} to reuse a
170170 * mapping, for example the full-aliasing retry.
171171 */
172- export function transformRequestBody ( body , plan ) {
172+ export function transformRequestBody ( body , plan , options = { } ) {
173173 const next = { ...body } ;
174174 const notes = [ ] ;
175175 const chosen = plan ?? planToolAliases ( next [ "tools" ] ) ;
@@ -183,17 +183,29 @@ export function transformRequestBody(body, plan) {
183183 next [ "tool_choice" ] = "auto" ;
184184 notes . push ( "tool_choice=auto" ) ;
185185 }
186- const effort = next [ "reasoning_effort" ] ;
187- if ( typeof effort === "string" ) {
188- const reasoning = isRecord ( next [ "reasoning" ] ) ? next [ "reasoning" ] : { } ;
189- next [ "reasoning" ] = { ...reasoning , effort : reasoning [ "effort" ] ?? effort } ;
190- delete next [ "reasoning_effort" ] ;
191- notes . push ( "reasoning_effort->reasoning.effort" ) ;
186+ const reasoning = isRecord ( next [ "reasoning" ] ) ? next [ "reasoning" ] : undefined ;
187+ const legacyEffort = next [ "reasoning_effort" ] ;
188+ const effort = typeof reasoning ?. [ "effort" ] === "string"
189+ ? reasoning [ "effort" ]
190+ : typeof legacyEffort === "string"
191+ ? legacyEffort
192+ : undefined ;
193+ if ( effort !== undefined && ( legacyEffort !== undefined || effort === "none" || effort === "off" ) ) {
194+ // Meta accepts only minimal..max on the reasoning effort; OpenClaw's
195+ // thinking-off level arrives as "none" and would otherwise be a 400.
196+ const normalized = effort === "none" || effort === "off" ? "minimal" : effort ;
197+ next [ "reasoning" ] = { ...( reasoning ?? { } ) , effort : normalized } ;
198+ if ( legacyEffort !== undefined )
199+ delete next [ "reasoning_effort" ] ;
200+ notes . push ( normalized !== effort
201+ ? `reasoning.effort ${ effort } ->${ normalized } `
202+ : "reasoning_effort->reasoning.effort" ) ;
192203 }
193204 const maxOutput = next [ "max_output_tokens" ] ;
194- if ( typeof maxOutput === "number" && maxOutput < 16 ) {
195- next [ "max_output_tokens" ] = 16 ;
196- notes . push ( "max_output_tokens>=16" ) ;
205+ const floor = options . minOutputTokens ?? 16 ;
206+ if ( typeof maxOutput === "number" && maxOutput < floor ) {
207+ next [ "max_output_tokens" ] = floor ;
208+ notes . push ( `max_output_tokens>=${ String ( floor ) } ` ) ;
197209 }
198210 const include = Array . isArray ( next [ "include" ] ) ? next [ "include" ] : [ ] ;
199211 if ( ! include . includes ( "reasoning.encrypted_content" ) ) {
@@ -413,6 +425,7 @@ export async function startMuseCodeAdapter(options = {}) {
413425 const passthrough = options . passthrough === true ;
414426 const log = options . log ?? ( ( ) => { } ) ;
415427 const candidates = options . ports ?? DEFAULT_PORTS ;
428+ const minOutputTokens = options . minOutputTokens ?? 16 ;
416429 let lastError ;
417430 let server ;
418431 let port = 0 ;
@@ -431,6 +444,9 @@ export async function startMuseCodeAdapter(options = {}) {
431444 throw new Error ( `muse-code adapter could not bind a loopback port: ${ String ( lastError ) } ` ) ;
432445 }
433446 const running = server ;
447+ // The adapter is a background service: it must not keep a one-shot CLI
448+ // process alive after the host has finished its work.
449+ running . unref ( ) ;
434450 running . on ( "request" , ( request , response ) => {
435451 void handle ( request , response ) . catch ( ( error ) => {
436452 log ( `muse-code adapter error: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
@@ -460,7 +476,7 @@ export async function startMuseCodeAdapter(options = {}) {
460476 const parsed = JSON . parse ( raw . toString ( "utf8" ) ) ;
461477 if ( isRecord ( parsed ) ) {
462478 parsedBody = parsed ;
463- const adapted = transformRequestBody ( parsed ) ;
479+ const adapted = transformRequestBody ( parsed , undefined , { minOutputTokens } ) ;
464480 body = Buffer . from ( JSON . stringify ( adapted . body ) , "utf8" ) ;
465481 reverse = adapted . plan . reverse ;
466482 notes . push ( ...adapted . notes ) ;
@@ -484,7 +500,7 @@ export async function startMuseCodeAdapter(options = {}) {
484500 if ( probe . includes ( "client_attestation_denied" ) ) {
485501 const allPlan = planToolAliases ( parsedBody [ "tools" ] , { all : true } ) ;
486502 if ( allPlan . aliases . size > reverse . size ) {
487- const retry = transformRequestBody ( parsedBody , allPlan ) ;
503+ const retry = transformRequestBody ( parsedBody , allPlan , { minOutputTokens } ) ;
488504 reverse = allPlan . reverse ;
489505 notes . push ( `gate refused; retried with all ${ String ( allPlan . aliases . size ) } tools aliased` ) ;
490506 upstreamResponse = await send ( Buffer . from ( JSON . stringify ( retry . body ) , "utf8" ) ) ;
0 commit comments