mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(cli): filter subagent sessions from resume history (#19698)
This commit is contained in:
@@ -445,9 +445,76 @@ describe('SessionSelector', () => {
|
||||
const sessionSelector = new SessionSelector(config);
|
||||
const sessions = await sessionSelector.listSessions();
|
||||
|
||||
// Should list the session with gemini message
|
||||
expect(sessions.length).toBe(1);
|
||||
expect(sessions[0].id).toBe(sessionIdGeminiOnly);
|
||||
});
|
||||
|
||||
it('should not list sessions marked as subagent', async () => {
|
||||
const mainSessionId = randomUUID();
|
||||
const subagentSessionId = randomUUID();
|
||||
|
||||
// Create test session files
|
||||
const chatsDir = path.join(tmpDir, 'chats');
|
||||
await fs.mkdir(chatsDir, { recursive: true });
|
||||
|
||||
// Main session - should be listed
|
||||
const mainSession = {
|
||||
sessionId: mainSessionId,
|
||||
projectHash: 'test-hash',
|
||||
startTime: '2024-01-01T10:00:00.000Z',
|
||||
lastUpdated: '2024-01-01T10:30:00.000Z',
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
content: 'Hello world',
|
||||
id: 'msg1',
|
||||
timestamp: '2024-01-01T10:00:00.000Z',
|
||||
},
|
||||
],
|
||||
kind: 'main',
|
||||
};
|
||||
|
||||
// Subagent session - should NOT be listed
|
||||
const subagentSession = {
|
||||
sessionId: subagentSessionId,
|
||||
projectHash: 'test-hash',
|
||||
startTime: '2024-01-01T11:00:00.000Z',
|
||||
lastUpdated: '2024-01-01T11:30:00.000Z',
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
content: 'Internal subagent task',
|
||||
id: 'msg1',
|
||||
timestamp: '2024-01-01T11:00:00.000Z',
|
||||
},
|
||||
],
|
||||
kind: 'subagent',
|
||||
};
|
||||
|
||||
await fs.writeFile(
|
||||
path.join(
|
||||
chatsDir,
|
||||
`${SESSION_FILE_PREFIX}2024-01-01T10-00-${mainSessionId.slice(0, 8)}.json`,
|
||||
),
|
||||
JSON.stringify(mainSession, null, 2),
|
||||
);
|
||||
|
||||
await fs.writeFile(
|
||||
path.join(
|
||||
chatsDir,
|
||||
`${SESSION_FILE_PREFIX}2024-01-01T11-00-${subagentSessionId.slice(0, 8)}.json`,
|
||||
),
|
||||
JSON.stringify(subagentSession, null, 2),
|
||||
);
|
||||
|
||||
const sessionSelector = new SessionSelector(config);
|
||||
const sessions = await sessionSelector.listSessions();
|
||||
|
||||
// Should only list the main session
|
||||
expect(sessions.length).toBe(1);
|
||||
expect(sessions[0].id).toBe(mainSessionId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractFirstUserMessage', () => {
|
||||
|
||||
@@ -276,6 +276,12 @@ export const getAllSessionFiles = async (
|
||||
return { fileName: file, sessionInfo: null };
|
||||
}
|
||||
|
||||
// Skip subagent sessions - these are implementation details of a tool call
|
||||
// and shouldn't be surfaced for resumption in the main agent history.
|
||||
if (content.kind === 'subagent') {
|
||||
return { fileName: file, sessionInfo: null };
|
||||
}
|
||||
|
||||
const firstUserMessage = extractFirstUserMessage(content.messages);
|
||||
const isCurrentSession = currentSessionId
|
||||
? file.includes(currentSessionId.slice(0, 8))
|
||||
|
||||
Reference in New Issue
Block a user