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:
Allen Hutchison
2025-10-24 13:04:40 -07:00
committed by GitHub
parent 63a90836fe
commit b188a51c32
15 changed files with 224 additions and 92 deletions
+28 -6
View File
@@ -24,6 +24,7 @@ import type {
} from './modifiable-tool.js';
import { ToolErrorType } from './tool-error.js';
import { MEMORY_TOOL_NAME } from './tool-names.js';
import type { MessageBus } from '../confirmation-bus/message-bus.js';
const memoryToolSchemaData: FunctionDeclaration = {
name: MEMORY_TOOL_NAME,
@@ -58,8 +59,7 @@ Do NOT use this tool:
## Parameters
- \`fact\` (string, required): The specific fact or piece of information to remember. This should be a clear, self-contained statement. For example, if the user says "My favorite color is blue", the fact would be "My favorite color is blue".
`;
- \`fact\` (string, required): The specific fact or piece of information to remember. This should be a clear, self-contained statement. For example, if the user says "My favorite color is blue", the fact would be "My favorite color is blue".`;
export const DEFAULT_CONTEXT_FILENAME = 'GEMINI.md';
export const MEMORY_SECTION_HEADER = '## Gemini Added Memories';
@@ -177,12 +177,21 @@ class MemoryToolInvocation extends BaseToolInvocation<
> {
private static readonly allowlist: Set<string> = new Set();
constructor(
params: SaveMemoryParams,
messageBus?: MessageBus,
toolName?: string,
displayName?: string,
) {
super(params, messageBus, toolName, displayName);
}
getDescription(): string {
const memoryFilePath = getGlobalMemoryFilePath();
return `in ${tildeifyPath(memoryFilePath)}`;
}
override async shouldConfirmExecute(
protected override async getConfirmationDetails(
_abortSignal: AbortSignal,
): Promise<ToolEditConfirmationDetails | false> {
const memoryFilePath = getGlobalMemoryFilePath();
@@ -291,13 +300,16 @@ export class MemoryTool
{
static readonly Name = MEMORY_TOOL_NAME;
constructor() {
constructor(messageBus?: MessageBus) {
super(
MemoryTool.Name,
'Save Memory',
memoryToolDescription,
Kind.Think,
memoryToolSchemaData.parametersJsonSchema as Record<string, unknown>,
true,
false,
messageBus,
);
}
@@ -311,8 +323,18 @@ export class MemoryTool
return null;
}
protected createInvocation(params: SaveMemoryParams) {
return new MemoryToolInvocation(params);
protected createInvocation(
params: SaveMemoryParams,
messageBus?: MessageBus,
toolName?: string,
displayName?: string,
) {
return new MemoryToolInvocation(
params,
messageBus ?? this.messageBus,
toolName ?? this.name,
displayName ?? this.displayName,
);
}
static async performAddMemoryEntry(