gemini-cli/packages/cli/src/ui/commands/memoryCommand.ts
Sandy Tao 8573650253
Some checks failed
Testing: E2E (Chained) / Merge Queue Skipper (push) Has been cancelled
Testing: E2E (Chained) / download_repo_name (push) Has been cancelled
Testing: E2E (Chained) / Parse run context (push) Has been cancelled
Testing: E2E (Chained) / set_pending_status (push) Has been cancelled
Testing: E2E (Chained) / E2E Test (Linux) - sandbox:docker (push) Has been cancelled
Testing: E2E (Chained) / E2E Test (Linux) - sandbox:none (push) Has been cancelled
Testing: E2E (Chained) / E2E Test (macOS) (push) Has been cancelled
Testing: E2E (Chained) / Slow E2E - Win (push) Has been cancelled
Testing: E2E (Chained) / Evals (ALWAYS_PASSING) (push) Has been cancelled
Testing: E2E (Chained) / E2E (push) Has been cancelled
Testing: E2E (Chained) / set_workflow_status (push) Has been cancelled
Testing: CI / Merge Queue Skipper (push) Has been cancelled
Testing: CI / Lint (push) Has been cancelled
Testing: CI / Link Checker (push) Has been cancelled
Testing: CI / Test (Linux) - 20.x, cli (push) Has been cancelled
Testing: CI / Test (Linux) - 20.x, others (push) Has been cancelled
Testing: CI / Test (Linux) - 22.x, cli (push) Has been cancelled
Testing: CI / Test (Linux) - 22.x, others (push) Has been cancelled
Testing: CI / Test (Linux) - 24.x, cli (push) Has been cancelled
Testing: CI / Test (Linux) - 24.x, others (push) Has been cancelled
Testing: CI / Test (Mac) - 20.x, cli (push) Has been cancelled
Testing: CI / Test (Mac) - 20.x, others (push) Has been cancelled
Testing: CI / Test (Mac) - 22.x, cli (push) Has been cancelled
Testing: CI / Test (Mac) - 22.x, others (push) Has been cancelled
Testing: CI / Test (Mac) - 24.x, cli (push) Has been cancelled
Testing: CI / Test (Mac) - 24.x, others (push) Has been cancelled
Testing: CI / CodeQL (push) Has been cancelled
Testing: CI / Check Bundle Size (push) Has been cancelled
Testing: CI / Slow Test - Win - cli (push) Has been cancelled
Testing: CI / Slow Test - Win - others (push) Has been cancelled
Testing: CI / CI (push) Has been cancelled
Trigger Docs Rebuild / trigger-rebuild (push) Has been cancelled
Links / linkChecker (push) Has been cancelled
On Merge Smoke Test / smoke-test (push) Has been cancelled
feat(config): split memoryManager flag into autoMemory (#25601)
2026-04-18 00:08:02 +00:00

171 lines
4.4 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import {
addMemory,
listMemoryFiles,
refreshMemory,
showMemory,
} from '@google/gemini-cli-core';
import { MessageType } from '../types.js';
import {
CommandKind,
type OpenCustomDialogActionReturn,
type SlashCommand,
type SlashCommandActionReturn,
} from './types.js';
import { SkillInboxDialog } from '../components/SkillInboxDialog.js';
export const memoryCommand: SlashCommand = {
name: 'memory',
description: 'Commands for interacting with memory',
kind: CommandKind.BUILT_IN,
autoExecute: false,
subCommands: [
{
name: 'show',
description: 'Show the current memory contents',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context) => {
const config = context.services.agentContext?.config;
if (!config) return;
const result = showMemory(config);
context.ui.addItem(
{
type: MessageType.INFO,
text: result.content,
},
Date.now(),
);
},
},
{
name: 'add',
description: 'Add content to the memory',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: (context, args): SlashCommandActionReturn | void => {
const result = addMemory(args);
if (result.type === 'message') {
return result;
}
context.ui.addItem(
{
type: MessageType.INFO,
text: `Attempting to save to memory: "${args.trim()}"`,
},
Date.now(),
);
return result;
},
},
{
name: 'reload',
altNames: ['refresh'],
description: 'Reload the memory from the source',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context) => {
context.ui.addItem(
{
type: MessageType.INFO,
text: 'Reloading memory from source files...',
},
Date.now(),
);
try {
const config = context.services.agentContext?.config;
if (config) {
const result = await refreshMemory(config);
context.ui.addItem(
{
type: MessageType.INFO,
text: result.content,
},
Date.now(),
);
}
} catch (error) {
context.ui.addItem(
{
type: MessageType.ERROR,
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
text: `Error reloading memory: ${(error as Error).message}`,
},
Date.now(),
);
}
},
},
{
name: 'list',
description: 'Lists the paths of the GEMINI.md files in use',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context) => {
const config = context.services.agentContext?.config;
if (!config) return;
const result = listMemoryFiles(config);
context.ui.addItem(
{
type: MessageType.INFO,
text: result.content,
},
Date.now(),
);
},
},
{
name: 'inbox',
description:
'Review skills extracted from past sessions and move them to global or project skills',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: (
context,
): OpenCustomDialogActionReturn | SlashCommandActionReturn | void => {
const config = context.services.agentContext?.config;
if (!config) {
return {
type: 'message',
messageType: 'error',
content: 'Config not loaded.',
};
}
if (!config.isAutoMemoryEnabled()) {
return {
type: 'message',
messageType: 'info',
content:
'The memory inbox requires Auto Memory. Enable it with: experimental.autoMemory = true in settings.',
};
}
return {
type: 'custom_dialog',
component: React.createElement(SkillInboxDialog, {
config,
onClose: () => context.ui.removeComponent(),
onReloadSkills: async () => {
await config.reloadSkills();
context.ui.reloadCommands();
},
}),
};
},
},
],
};