feat: implement permission denial tracking for tool calls

This commit is contained in:
Mingholy
2025-11-05 22:09:27 +08:00
parent 49b1018337
commit 95cf53f3bc
3 changed files with 56 additions and 7 deletions

View File

@@ -696,7 +696,7 @@ export class CoreToolScheduler {
response: createErrorResponse(
reqInfo,
new Error(permissionErrorMessage),
ToolErrorType.TOOL_NOT_REGISTERED,
ToolErrorType.EXECUTION_DENIED,
),
durationMs: 0,
};
@@ -811,6 +811,32 @@ export class CoreToolScheduler {
);
this.setStatusInternal(reqInfo.callId, 'scheduled');
} else {
/**
* In non-interactive mode where no user will respond to approval prompts,
* and not running as IDE companion or Zed integration, automatically deny approval.
* This is intended to create an explicit denial of the tool call,
* rather than silently waiting for approval and hanging forever.
*/
const shouldAutoDeny =
!this.config.isInteractive() &&
!this.config.getIdeMode() &&
!this.config.getExperimentalZedIntegration();
if (shouldAutoDeny) {
// Treat as execution denied error, similar to excluded tools
const errorMessage = `Qwen Code requires permission to use "${reqInfo.name}", but that permission was declined.`;
this.setStatusInternal(
reqInfo.callId,
'error',
createErrorResponse(
reqInfo,
new Error(errorMessage),
ToolErrorType.EXECUTION_DENIED,
),
);
continue;
}
// Allow IDE to resolve confirmation
if (
confirmationDetails.type === 'edit' &&

View File

@@ -14,6 +14,8 @@ export enum ToolErrorType {
UNHANDLED_EXCEPTION = 'unhandled_exception',
TOOL_NOT_REGISTERED = 'tool_not_registered',
EXECUTION_FAILED = 'execution_failed',
// Try to execute a tool that is excluded due to the approval mode
EXECUTION_DENIED = 'execution_denied',
// File System Errors
FILE_NOT_FOUND = 'file_not_found',