mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 00:51:25 -07:00
feat(sessions): use 1-line generated session summary to describe sessions (#14467)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
} from '@google/gemini-cli-core';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { stripUnsafeCharacters } from '../ui/utils/textUtils.js';
|
||||
|
||||
/**
|
||||
* Constant for the resume "latest" identifier.
|
||||
@@ -60,6 +61,8 @@ export interface SessionInfo {
|
||||
isCurrentSession: boolean;
|
||||
/** Display index in the list */
|
||||
index: number;
|
||||
/** AI-generated summary of the session (if available) */
|
||||
summary?: string;
|
||||
/** Full concatenated content (only loaded when needed for search) */
|
||||
fullContent?: string;
|
||||
/** Processed messages with normalized roles (only loaded when needed) */
|
||||
@@ -259,10 +262,13 @@ export const getAllSessionFiles = async (
|
||||
startTime: content.startTime,
|
||||
lastUpdated: content.lastUpdated,
|
||||
messageCount: content.messages.length,
|
||||
displayName: firstUserMessage,
|
||||
displayName: content.summary
|
||||
? stripUnsafeCharacters(content.summary)
|
||||
: firstUserMessage,
|
||||
firstUserMessage,
|
||||
isCurrentSession,
|
||||
index: 0, // Will be set after sorting valid sessions
|
||||
summary: content.summary,
|
||||
fullContent,
|
||||
messages,
|
||||
};
|
||||
|
||||
@@ -290,6 +290,40 @@ describe('listSessions', () => {
|
||||
expect.stringContaining(', current)'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should display summary as title when available instead of first user message', async () => {
|
||||
// Arrange
|
||||
const now = new Date('2025-01-20T12:00:00.000Z');
|
||||
const mockSessions: SessionInfo[] = [
|
||||
{
|
||||
id: 'session-with-summary',
|
||||
file: 'session-file',
|
||||
fileName: 'session-file.json',
|
||||
startTime: now.toISOString(),
|
||||
lastUpdated: now.toISOString(),
|
||||
messageCount: 10,
|
||||
displayName: 'Add dark mode to the app', // Summary
|
||||
firstUserMessage:
|
||||
'How do I add dark mode to my React application with CSS variables?',
|
||||
isCurrentSession: false,
|
||||
index: 1,
|
||||
summary: 'Add dark mode to the app',
|
||||
},
|
||||
];
|
||||
|
||||
mockListSessions.mockResolvedValue(mockSessions);
|
||||
|
||||
// Act
|
||||
await listSessions(mockConfig);
|
||||
|
||||
// Assert: Should show the summary (displayName), not the first user message
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('1. Add dark mode to the app'),
|
||||
);
|
||||
expect(consoleLogSpy).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining('How do I add dark mode to my React application'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteSession', () => {
|
||||
|
||||
@@ -31,9 +31,9 @@ export async function listSessions(config: Config): Promise<void> {
|
||||
const current = session.isCurrentSession ? ', current' : '';
|
||||
const time = formatRelativeTime(session.lastUpdated);
|
||||
const title =
|
||||
session.firstUserMessage.length > 100
|
||||
? session.firstUserMessage.slice(0, 97) + '...'
|
||||
: session.firstUserMessage;
|
||||
session.displayName.length > 100
|
||||
? session.displayName.slice(0, 97) + '...'
|
||||
: session.displayName;
|
||||
console.log(
|
||||
` ${index + 1}. ${title} (${time}${current}) [${session.id}]`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user