@@ -31,7 +31,12 @@ import {
3131 getContextIdFromMetadata ,
3232 getAgentSettingsFromMetadata ,
3333} from '../types.js' ;
34- import { loadConfig , loadEnvironment , setTargetDir } from '../config/config.js' ;
34+ import {
35+ loadConfig ,
36+ loadEnvironment ,
37+ setIsTrusted ,
38+ setTargetDir ,
39+ } from '../config/config.js' ;
3540import { loadSettings } from '../config/settings.js' ;
3641import { loadExtensions } from '../config/extension.js' ;
3742import { Task } from './task.js' ;
@@ -93,8 +98,8 @@ export class CoderAgentExecutor implements AgentExecutor {
9398 taskId : string ,
9499 ) : Promise < Config > {
95100 const workspaceRoot = setTargetDir ( agentSettings ) ;
96- const isTrusted = agentSettings . isTrusted ?? false ;
97101 loadEnvironment ( ) ; // Will override any global env with workspace envs
102+ const isTrusted = setIsTrusted ( agentSettings ) ;
98103 const settings = loadSettings ( workspaceRoot , isTrusted ) ;
99104 const extensions = loadExtensions ( workspaceRoot ) ;
100105 return loadConfig (
@@ -541,42 +546,49 @@ export class CoderAgentExecutor implements AgentExecutor {
541546
542547 if ( abortSignal . aborted ) throw new Error ( 'Execution aborted' ) ;
543548
544- const completedTools = currentTask . getAndClearCompletedTools ( ) ;
545-
546- if ( completedTools . length > 0 ) {
547- // If all completed tool calls were canceled, manually add them to history and set state to input-required, final:true
548- if ( completedTools . every ( ( tool ) => tool . status === 'cancelled' ) ) {
549- logger . info (
550- `[CoderAgentExecutor] Task ${ taskId } : All tool calls were cancelled. Updating history and ending agent turn.` ,
551- ) ;
552- currentTask . addToolResponsesToHistory ( completedTools ) ;
553- agentTurnActive = false ;
554- const stateChange : StateChange = {
555- kind : CoderAgentEvent . StateChangeEvent ,
556- } ;
557- currentTask . setTaskStateAndPublishUpdate (
558- 'input-required' ,
559- stateChange ,
560- undefined ,
561- undefined ,
562- true ,
563- ) ;
549+ if ( currentTask . hasPendingTools ) {
550+ logger . info (
551+ `[CoderAgentExecutor] Task ${ taskId } : There are still ${ currentTask . pendingToolsCount } pending tools waiting for approval. Yielding to user.` ,
552+ ) ;
553+ agentTurnActive = false ;
554+ } else {
555+ const completedTools = currentTask . getAndClearCompletedTools ( ) ;
556+
557+ if ( completedTools . length > 0 ) {
558+ // If all completed tool calls were canceled, manually add them to history and set state to input-required, final:true
559+ if ( completedTools . every ( ( tool ) => tool . status === 'cancelled' ) ) {
560+ logger . info (
561+ `[CoderAgentExecutor] Task ${ taskId } : All tool calls were cancelled. Updating history and ending agent turn.` ,
562+ ) ;
563+ currentTask . addToolResponsesToHistory ( completedTools ) ;
564+ agentTurnActive = false ;
565+ const stateChange : StateChange = {
566+ kind : CoderAgentEvent . StateChangeEvent ,
567+ } ;
568+ currentTask . setTaskStateAndPublishUpdate (
569+ 'input-required' ,
570+ stateChange ,
571+ undefined ,
572+ undefined ,
573+ true ,
574+ ) ;
575+ } else {
576+ logger . info (
577+ `[CoderAgentExecutor] Task ${ taskId } : Found ${ completedTools . length } completed tool calls. Sending results back to LLM.` ,
578+ ) ;
579+
580+ agentEvents = currentTask . sendCompletedToolsToLlm (
581+ completedTools ,
582+ abortSignal ,
583+ ) ;
584+ // Continue the loop to process the LLM response to the tool results.
585+ }
564586 } else {
565587 logger . info (
566- `[CoderAgentExecutor] Task ${ taskId } : Found ${ completedTools . length } completed tool calls. Sending results back to LLM.` ,
567- ) ;
568-
569- agentEvents = currentTask . sendCompletedToolsToLlm (
570- completedTools ,
571- abortSignal ,
588+ `[CoderAgentExecutor] Task ${ taskId } : No more tool calls to process. Ending agent turn.` ,
572589 ) ;
573- // Continue the loop to process the LLM response to the tool results.
590+ agentTurnActive = false ;
574591 }
575- } else {
576- logger . info (
577- `[CoderAgentExecutor] Task ${ taskId } : No more tool calls to process. Ending agent turn.` ,
578- ) ;
579- agentTurnActive = false ;
580592 }
581593 }
582594
0 commit comments