mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 22:14:52 -07:00
feat(core): Introduce message bus for tool execution confirmation (#11544)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,13 @@ import type {
|
||||
ToolLocation,
|
||||
ToolResult,
|
||||
} from './tools.js';
|
||||
import { BaseDeclarativeTool, Kind, ToolConfirmationOutcome } from './tools.js';
|
||||
import {
|
||||
BaseDeclarativeTool,
|
||||
BaseToolInvocation,
|
||||
Kind,
|
||||
ToolConfirmationOutcome,
|
||||
} from './tools.js';
|
||||
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
||||
import { ToolErrorType } from './tool-error.js';
|
||||
import { makeRelative, shortenPath } from '../utils/paths.js';
|
||||
import { isNodeError } from '../utils/errors.js';
|
||||
@@ -102,13 +108,21 @@ interface CalculatedEdit {
|
||||
isNewFile: boolean;
|
||||
}
|
||||
|
||||
class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
class EditToolInvocation
|
||||
extends BaseToolInvocation<EditToolParams, ToolResult>
|
||||
implements ToolInvocation<EditToolParams, ToolResult>
|
||||
{
|
||||
constructor(
|
||||
private readonly config: Config,
|
||||
public params: EditToolParams,
|
||||
) {}
|
||||
params: EditToolParams,
|
||||
messageBus?: MessageBus,
|
||||
toolName?: string,
|
||||
displayName?: string,
|
||||
) {
|
||||
super(params, messageBus, toolName, displayName);
|
||||
}
|
||||
|
||||
toolLocations(): ToolLocation[] {
|
||||
override toolLocations(): ToolLocation[] {
|
||||
return [{ path: this.params.file_path }];
|
||||
}
|
||||
|
||||
@@ -241,7 +255,7 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
* Handles the confirmation prompt for the Edit tool in the CLI.
|
||||
* It needs to calculate the diff to show the user.
|
||||
*/
|
||||
async shouldConfirmExecute(
|
||||
protected override async getConfirmationDetails(
|
||||
abortSignal: AbortSignal,
|
||||
): Promise<ToolCallConfirmationDetails | false> {
|
||||
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
||||
@@ -467,7 +481,10 @@ export class EditTool
|
||||
{
|
||||
static readonly Name = EDIT_TOOL_NAME;
|
||||
|
||||
constructor(private readonly config: Config) {
|
||||
constructor(
|
||||
private readonly config: Config,
|
||||
messageBus?: MessageBus,
|
||||
) {
|
||||
super(
|
||||
EditTool.Name,
|
||||
'Edit',
|
||||
@@ -510,6 +527,9 @@ Expectation for required parameters:
|
||||
required: ['file_path', 'old_string', 'new_string'],
|
||||
type: 'object',
|
||||
},
|
||||
true, // isOutputMarkdown
|
||||
false, // canUpdateOutput
|
||||
messageBus,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -540,8 +560,17 @@ Expectation for required parameters:
|
||||
|
||||
protected createInvocation(
|
||||
params: EditToolParams,
|
||||
messageBus?: MessageBus,
|
||||
toolName?: string,
|
||||
displayName?: string,
|
||||
): ToolInvocation<EditToolParams, ToolResult> {
|
||||
return new EditToolInvocation(this.config, params);
|
||||
return new EditToolInvocation(
|
||||
this.config,
|
||||
params,
|
||||
messageBus ?? this.messageBus,
|
||||
toolName ?? this.name,
|
||||
displayName ?? this.displayName,
|
||||
);
|
||||
}
|
||||
|
||||
getModifyContext(_: AbortSignal): ModifyContext<EditToolParams> {
|
||||
|
||||
Reference in New Issue
Block a user