2025-07-07 16:45:44 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-11-07 09:07:25 -08:00
|
|
|
import {
|
2026-01-12 16:46:42 -05:00
|
|
|
addMemory,
|
|
|
|
|
listMemoryFiles,
|
|
|
|
|
refreshMemory,
|
|
|
|
|
showMemory,
|
2025-11-07 09:07:25 -08:00
|
|
|
} from '@google/gemini-cli-core';
|
2025-07-07 16:45:44 -04:00
|
|
|
import { MessageType } from '../types.js';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { SlashCommand, SlashCommandActionReturn } from './types.js';
|
|
|
|
|
import { CommandKind } from './types.js';
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
export const memoryCommand: SlashCommand = {
|
|
|
|
|
name: 'memory',
|
2025-10-17 13:20:15 -07:00
|
|
|
description: 'Commands for interacting with memory',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: false,
|
2025-07-07 16:45:44 -04:00
|
|
|
subCommands: [
|
|
|
|
|
{
|
|
|
|
|
name: 'show',
|
2025-10-17 13:20:15 -07:00
|
|
|
description: 'Show the current memory contents',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: true,
|
2025-07-07 16:45:44 -04:00
|
|
|
action: async (context) => {
|
2026-01-12 16:46:42 -05:00
|
|
|
const config = context.services.config;
|
|
|
|
|
if (!config) return;
|
|
|
|
|
const result = showMemory(config);
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.INFO,
|
2026-01-12 16:46:42 -05:00
|
|
|
text: result.content,
|
2025-07-07 16:45:44 -04:00
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'add',
|
2025-10-17 13:20:15 -07:00
|
|
|
description: 'Add content to the memory',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: false,
|
2025-07-07 16:45:44 -04:00
|
|
|
action: (context, args): SlashCommandActionReturn | void => {
|
2026-01-12 16:46:42 -05:00
|
|
|
const result = addMemory(args);
|
|
|
|
|
|
|
|
|
|
if (result.type === 'message') {
|
|
|
|
|
return result;
|
2025-07-07 16:45:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.INFO,
|
|
|
|
|
text: `Attempting to save to memory: "${args.trim()}"`,
|
|
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
|
2026-01-12 16:46:42 -05:00
|
|
|
return result;
|
2025-07-07 16:45:44 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-03-07 14:56:11 -08:00
|
|
|
name: 'reload',
|
|
|
|
|
altNames: ['refresh'],
|
|
|
|
|
description: 'Reload the memory from the source',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: true,
|
2025-07-07 16:45:44 -04:00
|
|
|
action: async (context) => {
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.INFO,
|
2026-03-07 14:56:11 -08:00
|
|
|
text: 'Reloading memory from source files...',
|
2025-07-07 16:45:44 -04:00
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try {
|
2025-12-16 21:28:18 -08:00
|
|
|
const config = context.services.config;
|
2025-07-23 14:48:35 -07:00
|
|
|
if (config) {
|
2026-01-12 16:46:42 -05:00
|
|
|
const result = await refreshMemory(config);
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.INFO,
|
2026-01-12 16:46:42 -05:00
|
|
|
text: result.content,
|
2025-07-07 16:45:44 -04:00
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.ERROR,
|
2026-02-10 00:10:15 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
2026-03-07 14:56:11 -08:00
|
|
|
text: `Error reloading memory: ${(error as Error).message}`,
|
2025-07-07 16:45:44 -04:00
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-10-02 17:46:54 -04:00
|
|
|
{
|
|
|
|
|
name: 'list',
|
2025-10-17 13:20:15 -07:00
|
|
|
description: 'Lists the paths of the GEMINI.md files in use',
|
2025-10-02 17:46:54 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: true,
|
2025-10-02 17:46:54 -04:00
|
|
|
action: async (context) => {
|
2026-01-12 16:46:42 -05:00
|
|
|
const config = context.services.config;
|
|
|
|
|
if (!config) return;
|
|
|
|
|
const result = listMemoryFiles(config);
|
2025-10-02 17:46:54 -04:00
|
|
|
|
|
|
|
|
context.ui.addItem(
|
|
|
|
|
{
|
|
|
|
|
type: MessageType.INFO,
|
2026-01-12 16:46:42 -05:00
|
|
|
text: result.content,
|
2025-10-02 17:46:54 -04:00
|
|
|
},
|
|
|
|
|
Date.now(),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-07 16:45:44 -04:00
|
|
|
],
|
|
|
|
|
};
|