@@ -21,6 +21,7 @@ import {
2121} from "./agent-tools.before-tool-call.js" ;
2222import type { AgentMessage , AgentToolResult , AgentToolUpdateCallback } from "./runtime/index.js" ;
2323import type { ToolDefinition } from "./sessions/index.js" ;
24+ import { appendBoundedTextTail , SESSION_TOOL_STDERR_TAIL_BYTES } from "./sessions/tools/limits.js" ;
2425import { asToolParamsRecord , jsonResult , ToolInputError } from "./tools/common.js" ;
2526import type { AnyAgentTool } from "./tools/common.js" ;
2627
@@ -2093,6 +2094,10 @@ async function runCodeModeBridgeRequest(
20932094 throw new ToolInputError ( "Unsupported tool_search_code bridge method." ) ;
20942095}
20952096
2097+ function appendToolSearchCodeStderrTail ( current : string , chunk : string ) : string {
2098+ return appendBoundedTextTail ( current , chunk , SESSION_TOOL_STDERR_TAIL_BYTES ) ;
2099+ }
2100+
20962101function runCodeModeChild ( params : {
20972102 code : string ;
20982103 config : ToolSearchConfig ;
@@ -2108,7 +2113,7 @@ function runCodeModeChild(params: {
21082113 env : { } ,
21092114 stdio : [ "ignore" , "pipe" , "pipe" , "ipc" ] ,
21102115 } ) ;
2111- const stderr : string [ ] = [ ] ;
2116+ let stderrTail = "" ;
21122117 let settled = false ;
21132118 let timedOut = false ;
21142119 let exitRejectionTimer : ReturnType < typeof setTimeout > | undefined ;
@@ -2147,7 +2152,7 @@ function runCodeModeChild(params: {
21472152
21482153 child . stderr ?. setEncoding ( "utf8" ) ;
21492154 child . stderr ?. on ( "data" , ( chunk : string ) => {
2150- stderr . push ( chunk ) ;
2155+ stderrTail = appendToolSearchCodeStderrTail ( stderrTail , chunk ) ;
21512156 } ) ;
21522157
21532158 child . on ( "error" , ( error ) => {
@@ -2158,7 +2163,7 @@ function runCodeModeChild(params: {
21582163 return ;
21592164 }
21602165 const rejectOnExit = ( ) => {
2161- const suffix = stderr . join ( "" ) . trim ( ) ;
2166+ const suffix = stderrTail . trim ( ) ;
21622167 const detail = suffix ? `: ${ suffix . slice ( 0 , 500 ) } ` : "" ;
21632168 settle ( ( ) =>
21642169 reject (
@@ -2351,5 +2356,6 @@ export const testing = {
23512356 } ,
23522357 applyToolSearchCatalog,
23532358 addClientToolsToToolSearchCatalog,
2359+ appendToolSearchCodeStderrTail,
23542360} ;
23552361export { testing as __testing } ;
0 commit comments