@@ -380,46 +380,38 @@ export function createProcessTool(
380380 }
381381
382382 if ( ! params . sessionId ) {
383- return {
384- content : [ { type : "text" , text : "sessionId is required for this action." } ] ,
385- details : { status : "failed" } ,
386- } ;
383+ return failText ( "sessionId is required for this action." ) ;
387384 }
388385
389386 const session = getSession ( params . sessionId ) ;
390387 const finished = getFinishedSession ( params . sessionId ) ;
391388 const scopedSession = isInScope ( session ) ? session : undefined ;
392389 const scopedFinished = isInScope ( finished ) ? finished : undefined ;
393390
394- const failedResult = ( text : string ) : AgentToolResult < unknown > => ( {
395- content : [ { type : "text" , text } ] ,
396- details : { status : "failed" } ,
397- } ) ;
398-
399391 const resolveBackgroundedWritableStdin = ( ) => {
400392 if ( ! scopedSession ) {
401393 return {
402394 ok : false as const ,
403- result : failedResult ( `No active session found for ${ params . sessionId } ` ) ,
395+ result : failText ( `No active session found for ${ params . sessionId } ` ) ,
404396 } ;
405397 }
406398 if ( ! scopedSession . backgrounded ) {
407399 return {
408400 ok : false as const ,
409- result : failedResult ( `Session ${ params . sessionId } is not backgrounded.` ) ,
401+ result : failText ( `Session ${ params . sessionId } is not backgrounded.` ) ,
410402 } ;
411403 }
412404 if ( scopedSession . finalizing ) {
413405 return {
414406 ok : false as const ,
415- result : failedResult ( `Session ${ params . sessionId } is finalizing.` ) ,
407+ result : failText ( `Session ${ params . sessionId } is finalizing.` ) ,
416408 } ;
417409 }
418410 const stdin = resolveSessionStdin ( scopedSession ) ;
419411 if ( ! isWritableStdin ( stdin ) ) {
420412 return {
421413 ok : false as const ,
422- result : failedResult ( `Session ${ params . sessionId } stdin is not writable.` ) ,
414+ result : failText ( `Session ${ params . sessionId } stdin is not writable.` ) ,
423415 } ;
424416 }
425417 return { ok : true as const , session : scopedSession , stdin } ;
@@ -451,8 +443,17 @@ export function createProcessTool(
451443 }
452444 const pollWaitMs = resolvePollWaitMs ( params . timeout ) ;
453445 if ( pollWaitMs > 0 && ! scopedSession . exited ) {
446+ if ( signal ?. aborted ) {
447+ throw createAbortError ( signal . reason ) ;
448+ }
454449 const deadline = Date . now ( ) + pollWaitMs ;
455- while ( ! scopedSession . exited && Date . now ( ) < deadline ) {
450+ // Interactive children cannot progress until their pending prompt reaches the model.
451+ while (
452+ ! scopedSession . exited &&
453+ scopedSession . pendingOutput . length === 0 &&
454+ ! scopedSession . pendingOutputDropped &&
455+ Date . now ( ) < deadline
456+ ) {
456457 await sleepPollInterval ( Math . max ( 0 , Math . min ( 250 , deadline - Date . now ( ) ) ) , signal ) ;
457458 }
458459 }
@@ -501,15 +502,7 @@ export function createProcessTool(
501502 case "log" : {
502503 if ( scopedSession ) {
503504 if ( ! scopedSession . backgrounded ) {
504- return {
505- content : [
506- {
507- type : "text" ,
508- text : `Session ${ params . sessionId } is not backgrounded.` ,
509- } ,
510- ] ,
511- details : { status : "failed" } ,
512- } ;
505+ return failText ( `Session ${ params . sessionId } is not backgrounded.` ) ;
513506 }
514507 const window = resolveLogSliceWindow ( params . offset , params . limit ) ;
515508 const { slice, totalLines, totalChars } = sliceLogLines (
@@ -570,15 +563,7 @@ export function createProcessTool(
570563 } ,
571564 } ;
572565 }
573- return {
574- content : [
575- {
576- type : "text" ,
577- text : `No session found for ${ params . sessionId } ` ,
578- } ,
579- ] ,
580- details : { status : "failed" } ,
581- } ;
566+ return failText ( `No session found for ${ params . sessionId } ` ) ;
582567 }
583568
584569 case "write" : {
@@ -632,15 +617,7 @@ export function createProcessTool(
632617 }
633618 const payload = encodePaste ( params . text ?? "" , params . bracketed !== false ) ;
634619 if ( ! payload ) {
635- return {
636- content : [
637- {
638- type : "text" ,
639- text : "No paste text provided." ,
640- } ,
641- ] ,
642- details : { status : "failed" } ,
643- } ;
620+ return failText ( "No paste text provided." ) ;
644621 }
645622 await writeProcessStdin ( resolved . stdin , payload ) ;
646623 return runningSessionResult (
@@ -690,15 +667,7 @@ export function createProcessTool(
690667 details : { status : "completed" } ,
691668 } ;
692669 }
693- return {
694- content : [
695- {
696- type : "text" ,
697- text : `No finished session found for ${ params . sessionId } ` ,
698- } ,
699- ] ,
700- details : { status : "failed" } ,
701- } ;
670+ return failText ( `No finished session found for ${ params . sessionId } ` ) ;
702671 }
703672
704673 case "remove" : {
@@ -741,26 +710,14 @@ export function createProcessTool(
741710 details : { status : "completed" } ,
742711 } ;
743712 }
744- return {
745- content : [
746- {
747- type : "text" ,
748- text : `No session found for ${ params . sessionId } ` ,
749- } ,
750- ] ,
751- details : { status : "failed" } ,
752- } ;
713+ return failText ( `No session found for ${ params . sessionId } ` ) ;
753714 }
754715 }
755716
756- return {
757- content : [ { type : "text" , text : `Unknown action ${ params . action as string } ` } ] ,
758- details : { status : "failed" } ,
759- } ;
717+ return failText ( `Unknown action ${ params . action as string } ` ) ;
760718 } ,
761719 } ;
762720}
763721
764722/** Shared process-control tool instance used by the default Bash tool barrel. */
765723export const processTool = createProcessTool ( ) ;
766- /* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */
0 commit comments