Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hide-empty-current-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Hide the empty current session from the sessions picker while keeping other empty sessions visible.
14 changes: 6 additions & 8 deletions apps/kimi-code/src/tui/kimi-tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
} from './utils/mcp-server-status';
import { openUrl } from './utils/open-url';
import { setProcessTitle } from './utils/proctitle';
import { sessionRowsForPicker } from './utils/session-picker-rows';
import { installTerminalFocusTracking } from './utils/terminal-focus';
import { notifyTerminalOnce } from './utils/terminal-notification';
import { createTerminalState, type TerminalState } from './utils/terminal-state';
Expand Down Expand Up @@ -1304,7 +1305,7 @@
isCompacting: this.state.appState.isCompacting,
});

switch (intent.kind) {

Check warning on line 1308 in apps/kimi-code/src/tui/kimi-tui.ts

View workflow job for this annotation

GitHub Actions / lint

typescript-eslint(switch-exhaustiveness-check)

Switch is not exhaustive. Cases not matched: "invalid"
case 'not-command':
return;
case 'blocked':
Expand Down Expand Up @@ -1866,14 +1867,11 @@
this.state.loadingSessions = true;
try {
const sessions = await this.harness.listSessions({ workDir: this.state.appState.workDir });
this.state.sessions = sessions.map((session) => ({
id: session.id,
title: session.title ?? null,
last_prompt: session.lastPrompt ?? null,
work_dir: session.workDir,
updated_at: session.updatedAt ?? session.createdAt ?? 0,
metadata: session.metadata,
}));
this.state.sessions = sessionRowsForPicker(
sessions,
this.state.appState.sessionId,
this.hasSessionContent(),
);
} catch {
/* silently ignore */
} finally {
Expand Down
20 changes: 20 additions & 0 deletions apps/kimi-code/src/tui/utils/session-picker-rows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { SessionSummary } from '@moonshot-ai/kimi-code-sdk';

import type { SessionRow } from '#/tui/components/dialogs/session-picker';

export function sessionRowsForPicker(
sessions: readonly SessionSummary[],
currentSessionId: string,
currentSessionHasContent: boolean,
): SessionRow[] {
return sessions
.filter((session) => currentSessionHasContent || session.id !== currentSessionId)
.map((session) => ({
id: session.id,
title: session.title ?? null,
last_prompt: session.lastPrompt ?? null,
work_dir: session.workDir,
updated_at: session.updatedAt ?? session.createdAt ?? 0,
metadata: session.metadata,
}));
}
64 changes: 64 additions & 0 deletions apps/kimi-code/test/tui/utils/session-picker-rows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { SessionSummary } from '@moonshot-ai/kimi-code-sdk';
import { describe, expect, it } from 'vitest';

import { sessionRowsForPicker } from '#/tui/utils/session-picker-rows';

function summary(input: {
readonly id: string;
readonly title?: string;
readonly lastPrompt?: string;
}): SessionSummary {
return {
id: input.id,
title: input.title,
lastPrompt: input.lastPrompt,
workDir: '/tmp/project',
sessionDir: `/tmp/home/sessions/${input.id}`,
createdAt: 1,
updatedAt: 2,
};
}

describe('sessionRowsForPicker', () => {
it('omits the current session when the TUI session has no content', () => {
const rows = sessionRowsForPicker(
[
summary({ id: 'ses_current', title: 'New Session' }),
summary({ id: 'ses_previous', title: 'New Session' }),
],
'ses_current',
false,
);

expect(rows.map((row) => row.id)).toEqual(['ses_previous']);
});

it('keeps the current session when the TUI session has content', () => {
const rows = sessionRowsForPicker(
[
summary({
id: 'ses_current',
title: 'Implement feature',
lastPrompt: 'Implement feature',
}),
],
'ses_current',
true,
);

expect(rows.map((row) => row.id)).toEqual(['ses_current']);
});

it('does not filter empty historical sessions', () => {
const rows = sessionRowsForPicker(
[
summary({ id: 'ses_current', title: 'New Session' }),
summary({ id: 'ses_previous_empty', title: 'New Session' }),
],
'ses_current',
false,
);

expect(rows.map((row) => row.id)).toEqual(['ses_previous_empty']);
});
});
Loading