diff --git a/packages/core/src/test-utils/mock-tool.ts b/packages/core/src/test-utils/mock-tool.ts index 97f41a4fb0..ad28aa11ad 100644 --- a/packages/core/src/test-utils/mock-tool.ts +++ b/packages/core/src/test-utils/mock-tool.ts @@ -19,7 +19,7 @@ import { } from '../tools/tools.js'; import { createMockMessageBus } from './mock-message-bus.js'; import type { MessageBus } from '../confirmation-bus/message-bus.js'; -import type { ShellExecutionConfig } from 'src/services/shellExecutionService.js'; +import type { ShellExecutionConfig } from '../services/shellExecutionService.js'; interface MockToolOptions { name: string; diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 5918c994af..ae4b592f39 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -26,7 +26,6 @@ import { ToolErrorType } from './tool-error.js'; import { makeRelative, shortenPath } from '../utils/paths.js'; import { isNodeError } from '../utils/errors.js'; import type { Config } from '../config/config.js'; -import { type ApprovalMode } from '../policy/types.js'; import { CoreToolCallStatus } from '../scheduler/types.js'; import { DEFAULT_DIFF_OPTIONS, getDiffStat } from './diffOptions.js'; @@ -449,7 +448,16 @@ class EditToolInvocation toolName?: string, displayName?: string, ) { - super(params, messageBus, toolName, displayName); + super( + params, + messageBus, + toolName, + displayName, + undefined, + undefined, + true, + () => this.config.getApprovalMode(), + ); } override toolLocations(): ToolLocation[] { @@ -699,14 +707,6 @@ class EditToolInvocation ); } - protected override get respectsAutoEdit(): boolean { - return true; - } - - protected override getApprovalMode(): ApprovalMode { - return this.config.getApprovalMode(); - } - /** * Handles the confirmation prompt for the Edit tool in the CLI. * It needs to calculate the diff to show the user. diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index e224c31285..1d61108c53 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -99,6 +99,8 @@ export abstract class BaseToolInvocation< readonly _toolDisplayName?: string, readonly _serverName?: string, readonly _toolAnnotations?: Record, + readonly respectsAutoEdit: boolean = false, + readonly getApprovalMode: () => ApprovalMode = () => ApprovalMode.DEFAULT, ) {} abstract getDescription(): string; @@ -141,23 +143,6 @@ export abstract class BaseToolInvocation< return this.getConfirmationDetails(abortSignal); } - /** - * Whether this tool respects the AUTO_EDIT approval mode. - * Subclasses should override this and return true if they want to skip - * confirmation when the session is in AUTO_EDIT mode. - */ - protected get respectsAutoEdit(): boolean { - return false; - } - - /** - * Returns the current approval mode from the tool configuration. - * Subclasses should override this and return the actual approval mode. - */ - protected getApprovalMode(): ApprovalMode { - return ApprovalMode.DEFAULT; - } - /** * Returns tool-specific options for policy updates. * Subclasses can override this to provide additional options like diff --git a/packages/core/src/tools/web-fetch.ts b/packages/core/src/tools/web-fetch.ts index f69d51b2f7..57f4f8ab97 100644 --- a/packages/core/src/tools/web-fetch.ts +++ b/packages/core/src/tools/web-fetch.ts @@ -17,7 +17,6 @@ import type { MessageBus } from '../confirmation-bus/message-bus.js'; import { ToolErrorType } from './tool-error.js'; import { getErrorMessage } from '../utils/errors.js'; import type { Config } from '../config/config.js'; -import { type ApprovalMode } from '../policy/types.js'; import { getResponseText } from '../utils/partUtils.js'; import { fetchWithTimeout, isPrivateIp } from '../utils/fetch.js'; import { truncateString } from '../utils/textUtils.js'; @@ -181,7 +180,16 @@ class WebFetchToolInvocation extends BaseToolInvocation< _toolName?: string, _toolDisplayName?: string, ) { - super(params, messageBus, _toolName, _toolDisplayName); + super( + params, + messageBus, + _toolName, + _toolDisplayName, + undefined, + undefined, + true, + () => this.config.getApprovalMode(), + ); } private async executeFallback(signal: AbortSignal): Promise { @@ -291,14 +299,6 @@ ${textContent} return `Processing URLs and instructions from prompt: "${displayPrompt}"`; } - protected override get respectsAutoEdit(): boolean { - return true; - } - - protected override getApprovalMode(): ApprovalMode { - return this.config.getApprovalMode(); - } - protected override async getConfirmationDetails( _abortSignal: AbortSignal, ): Promise { diff --git a/packages/core/src/tools/write-file.ts b/packages/core/src/tools/write-file.ts index 85f46089ce..dc69c96f5e 100644 --- a/packages/core/src/tools/write-file.ts +++ b/packages/core/src/tools/write-file.ts @@ -11,7 +11,6 @@ import os from 'node:os'; import * as Diff from 'diff'; import { WRITE_FILE_TOOL_NAME, WRITE_FILE_DISPLAY_NAME } from './tool-names.js'; import type { Config } from '../config/config.js'; -import { type ApprovalMode } from '../policy/types.js'; import { BaseDeclarativeTool, @@ -153,7 +152,16 @@ class WriteFileToolInvocation extends BaseToolInvocation< toolName?: string, displayName?: string, ) { - super(params, messageBus, toolName, displayName); + super( + params, + messageBus, + toolName, + displayName, + undefined, + undefined, + true, + () => this.config.getApprovalMode(), + ); this.resolvedPath = path.resolve( this.config.getTargetDir(), this.params.file_path, @@ -172,14 +180,6 @@ class WriteFileToolInvocation extends BaseToolInvocation< return `Writing to ${shortenPath(relativePath)}`; } - protected override get respectsAutoEdit(): boolean { - return true; - } - - protected override getApprovalMode(): ApprovalMode { - return this.config.getApprovalMode(); - } - protected override async getConfirmationDetails( _abortSignal: AbortSignal, ): Promise {