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
10 changes: 10 additions & 0 deletions packages/cli/src/config/settingsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ const SETTINGS_SCHEMA = {
{ value: 'json', label: 'JSON' },
],
},
showTimestamps: {
type: 'boolean',
label: 'Show Timestamps',
category: 'General',
requiresRestart: false,
default: false,
description:
'Show [HH:MM:SS] timestamp before each assistant response.',
showInDialog: true,
},
},
},

Expand Down
76 changes: 76 additions & 0 deletions packages/cli/src/ui/components/HistoryItemDisplay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
} from '@qwen-code/qwen-code-core';
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
import { renderWithProviders } from '../../test-utils/render.js';
import { LoadedSettings } from '../../config/settings.js';
import { ConfigContext } from '../contexts/ConfigContext.js';
import { CompactModeProvider } from '../contexts/CompactModeContext.js';

Expand Down Expand Up @@ -406,4 +407,79 @@ describe('<HistoryItemDisplay />', () => {

expect(lastFrame()).not.toContain('Continuing the reasoning');
});

describe('showTimestamps', () => {
const timestampItem: HistoryItem = {
...baseItem,
type: 'gemini',
text: 'Hello from assistant',
timestamp: new Date('2026-01-15T14:30:45').getTime(),
};

const makeTimestampSettings = () =>
new LoadedSettings(
{ path: '', settings: {}, originalSettings: {} },
{ path: '', settings: {}, originalSettings: {} },
{
path: '',
settings: { output: { showTimestamps: true } },
originalSettings: {},
},
{ path: '', settings: {}, originalSettings: {} },
true,
new Set(),
);

it('does not render timestamp when showTimestamps is disabled', () => {
const { lastFrame } = renderWithProviders(
<HistoryItemDisplay
{...baseItem}
item={timestampItem}
isPending={false}
/>,
);
expect(lastFrame()).not.toMatch(/\[\d{2}:\d{2}:\d{2}\]/);
});

it('renders [HH:MM:SS] timestamp when showTimestamps is enabled', () => {
const { lastFrame } = renderWithProviders(
<HistoryItemDisplay
{...baseItem}
item={timestampItem}
isPending={false}
/>,
{ settings: makeTimestampSettings() },
);
expect(lastFrame()).toMatch(/\[\d{2}:\d{2}:\d{2}\]/);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The test fixture hardcodes timestamp: new Date('2026-01-15T14:30:45').getTime() but the regex \[\d{2}:\d{2}:\d{2}\] only asserts format, not value. A bug rendering the wrong time (e.g., Date.now() instead of item.timestamp) would pass undetected.

Pin the assertion to the expected value:

// Using UTC timestamp for deterministic assertion:
expect(lastFrame()).toContain('[14:30:45]');
// Or derive from fixture:
const expected = new Date('2026-01-15T14:30:45').toLocaleTimeString('en-US', { hour12: false });
expect(lastFrame()).toContain(`[${expected}]`);

— qwen3.7-max via Qwen Code /review


it('renders timestamp even when isPending is true (streaming)', () => {
const { lastFrame } = renderWithProviders(
<HistoryItemDisplay
{...baseItem}
item={timestampItem}
isPending={true}
/>,
{ settings: makeTimestampSettings() },
);
expect(lastFrame()).toMatch(/\[\d{2}:\d{2}:\d{2}\]/);
});

it('does not render timestamp when timestamp field is missing', () => {
const noTimestampItem: HistoryItem = {
id: 1,
type: 'gemini',
text: 'Hello',
};
const { lastFrame } = renderWithProviders(
<HistoryItemDisplay
{...baseItem}
item={noTimestampItem}
isPending={false}
/>,
{ settings: makeTimestampSettings() },
);
expect(lastFrame()).not.toMatch(/\[\d{2}:\d{2}:\d{2}\]/);
});
});
});
33 changes: 24 additions & 9 deletions packages/cli/src/ui/components/HistoryItemDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { MemorySavedMessage } from './messages/MemorySavedMessage.js';
import { DiffStatsDisplay } from './messages/DiffStatsDisplay.js';
import { GoalStatusMessage } from './messages/GoalStatusMessage.js';
import { useCompactMode } from '../contexts/CompactModeContext.js';
import { useSettings } from '../contexts/SettingsContext.js';

interface HistoryItemDisplayProps {
item: HistoryItem;
Expand Down Expand Up @@ -137,6 +138,9 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
const marginTop = getHistoryItemMarginTop(item);

const { compactMode } = useCompactMode();
const settings = useSettings();
const showTimestamps = settings.merged.output?.showTimestamps === true;

const itemForDisplay = useMemo(() => escapeAnsiCtrlCodes(item), [item]);
const contentWidth = terminalWidth - 4;
const boxWidth = mainAreaWidth || contentWidth;
Expand All @@ -160,15 +164,26 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
<UserShellMessage text={itemForDisplay.text} />
)}
{itemForDisplay.type === 'gemini' && (
<AssistantMessage
text={itemForDisplay.text}
isPending={isPending}
availableTerminalHeight={
availableTerminalHeightGemini ?? availableTerminalHeight
}
contentWidth={contentWidth}
sourceCopyIndexOffsets={sourceCopyIndexOffsets}
/>
<>
{showTimestamps && itemForDisplay.timestamp != null && (
Comment thread
yiliang114 marked this conversation as resolved.
<Text dimColor>
[

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] toLocaleTimeString('en-US', { hour12: false }) doesn't guarantee the HH:MM:SS format across all Node.js/ICU builds. Some ICU versions produce 9:05:30 instead of 09:05:30 for single-digit hours.

The codebase already has the correct pattern at demo.ts:202:

Suggested change
[
{new Date(itemForDisplay.timestamp).toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})}

— qwen3.7-max via Qwen Code /review

{new Date(itemForDisplay.timestamp).toLocaleTimeString('en-US', {
hour12: false,
})}
]
</Text>
)}
<AssistantMessage
text={itemForDisplay.text}
isPending={isPending}
availableTerminalHeight={
availableTerminalHeightGemini ?? availableTerminalHeight
}
contentWidth={contentWidth}
sourceCopyIndexOffsets={sourceCopyIndexOffsets}
/>
</>
)}
{itemForDisplay.type === 'gemini_content' && (
<AssistantMessageContent
Expand Down
135 changes: 60 additions & 75 deletions packages/cli/src/ui/components/SessionPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Copyright 2025 Qwen Code
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from 'ink-testing-library';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { KeypressProvider } from '../contexts/KeypressContext.js';
import { renderWithProviders } from '../../test-utils/render.js';
import { SessionPreview } from './SessionPreview.js';

beforeEach(() => {
Expand Down Expand Up @@ -83,32 +82,28 @@ function fakeResumedData(
describe('SessionPreview', () => {
it('shows loading state before data arrives', () => {
const svc = mockService(new Promise(() => {})); // never resolves
const { lastFrame } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { lastFrame } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>,
);
expect(lastFrame()).toContain('Loading session preview');
});

it('renders all messages after load', async () => {
const svc = mockService(fakeResumedData());
const { lastFrame } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { lastFrame } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>,
);
await wait(100);
const frame = lastFrame() ?? '';
Expand All @@ -127,16 +122,14 @@ describe('SessionPreview', () => {
{ text: 'FINAL-ANSWER-MARKER' },
]),
);
const { lastFrame } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { lastFrame } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>,
);
await wait(100);
const frame = lastFrame() ?? '';
Expand All @@ -151,19 +144,17 @@ describe('SessionPreview', () => {

it('renders footer metadata (messageCount · time · branch)', async () => {
const svc = mockService(fakeResumedData());
const { lastFrame } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
messageCount={42}
mtime={Date.now() - 60_000}
gitBranch="feat/preview"
onExit={vi.fn()}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { lastFrame } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
messageCount={42}
mtime={Date.now() - 60_000}
gitBranch="feat/preview"
onExit={vi.fn()}
onResume={vi.fn()}
/>,
);
await wait(100);
const frame = lastFrame() ?? '';
Expand All @@ -176,16 +167,14 @@ describe('SessionPreview', () => {
// through to SessionPreview. The footer must still show a count, derived
// from the loaded ResumedSessionData using unique user/assistant UUIDs.
const svc = mockService(fakeResumedData());
const { lastFrame } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { lastFrame } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={vi.fn()}
/>,
);
await wait(100);
const frame = lastFrame() ?? '';
Expand All @@ -196,16 +185,14 @@ describe('SessionPreview', () => {
it('calls onExit when Escape is pressed', async () => {
const onExit = vi.fn();
const svc = mockService(fakeResumedData());
const { stdin } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={onExit}
onResume={vi.fn()}
/>
</KeypressProvider>,
const { stdin } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={onExit}
onResume={vi.fn()}
/>,
);
await wait(100);
stdin.write('\u001B'); // ESC
Expand All @@ -216,16 +203,14 @@ describe('SessionPreview', () => {
it('calls onResume(sessionId) when Enter is pressed', async () => {
const onResume = vi.fn();
const svc = mockService(fakeResumedData());
const { stdin } = render(
<KeypressProvider kittyProtocolEnabled={false}>
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={onResume}
/>
</KeypressProvider>,
const { stdin } = renderWithProviders(
<SessionPreview
sessionService={svc}
sessionId="s1"
sessionTitle="My session"
onExit={vi.fn()}
onResume={onResume}
/>,
);
await wait(100);
stdin.write('\r'); // Enter
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/ui/hooks/useGeminiStream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3759,10 +3759,10 @@ describe('useGeminiStream', () => {
});

expect(mockAddItem).toHaveBeenCalledWith(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The only test changes for commitItem are relaxed assertions (expect.objectContaining) to accommodate the new timestamp field. There are no positive tests verifying that commitItem actually attaches a timestamp to gemini items, leaves non-gemini items (gemini_content, info, tool_group) untouched, or preserves a pre-existing timestamp via the !timestamp guard.

Consider adding dedicated tests that drive the stream through a gemini text event and assert mockAddItem was called with an item containing a numeric timestamp, and a test that commits a non-gemini item and asserts no timestamp was added.

— qwen3.7-max via Qwen Code /review

{
expect.objectContaining({
type: 'gemini',
text: 'Initial',
},
}),
expect.any(Number),
);

Expand Down Expand Up @@ -6695,10 +6695,10 @@ describe('useGeminiStream', () => {
});

expect(mockAddItem).toHaveBeenCalledWith(
{
expect.objectContaining({
type: 'gemini',
text: 'First call content',
},
}),
expect.any(Number),
);
expect(mainAbortSignal?.aborted).toBe(true);
Expand Down
Loading
Loading