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
7 changes: 4 additions & 3 deletions packages/cli/src/ui/hooks/useGeminiStream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ describe('useGeminiStream', () => {
queuedPrompt,
);
const queuedPromptAddItemIndex = mockAddItem.mock.calls.findIndex(
([item]) => item.type === MessageType.USER && item.text === queuedPrompt,
([item]) =>
item.type === MessageType.NOTIFICATION && item.text === queuedPrompt,
);
expect(queuedPromptAddItemIndex).toBeGreaterThanOrEqual(0);
expect(recordMidTurnUserMessage.mock.invocationCallOrder[0]).toBeLessThan(
Expand All @@ -636,7 +637,7 @@ describe('useGeminiStream', () => {
mockSendMessageStream.mock.invocationCallOrder[0],
);
expect(mockAddItem).toHaveBeenCalledWith(
{ type: MessageType.USER, text: queuedPrompt },
{ type: MessageType.NOTIFICATION, text: queuedPrompt },
expect.any(Number),
);
expect(mockSendMessageStream).toHaveBeenCalledWith(
Expand Down Expand Up @@ -731,7 +732,7 @@ describe('useGeminiStream', () => {
});

expect(mockAddItem).toHaveBeenCalledWith(
{ type: MessageType.USER, text: queuedPrompt },
{ type: MessageType.NOTIFICATION, text: queuedPrompt },
expect.any(Number),
);
expect(mockSendMessageStream).toHaveBeenCalledWith(
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/ui/hooks/useGeminiStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2347,8 +2347,7 @@ export const useGeminiStream = (
config
.getChatRecordingService()

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] Minor UX concern: mid-turn messages now render as <InfoMessage> (dimmed/grey) instead of <UserMessage> (prominent > prefix). Users might not recognize their own mid-turn text in the transcript. Consider whether a distinguishing visual treatment is warranted (e.g., a dimmed variant of UserMessage).

Not blocking — the correctness fix is more important than the visual regression.

?.recordMidTurnUserMessage(midTurnUserMessage, msg);
// Record in UI history so the transcript stays complete.
addItem({ type: MessageType.USER, text: msg }, Date.now());
addItem({ type: MessageType.NOTIFICATION, text: msg }, Date.now());
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ export enum MessageType {
ARENA_SESSION_COMPLETE = 'arena_session_complete',
INSIGHT_PROGRESS = 'insight_progress',
BTW = 'btw',
NOTIFICATION = 'notification',
DIFF_STATS = 'diff_stats',
GOAL_STATUS = 'goal_status',
}
Expand Down
39 changes: 39 additions & 0 deletions packages/cli/src/ui/utils/historyMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,45 @@ describe('computeApiTruncationIndex', () => {
});
});

describe('mid-turn user messages (notification type)', () => {
it('skips notification items so btw merged into functionResponse does not cause mismatch', () => {
// Mid-turn messages are type 'notification' in UI (not counted by
// isRealUserTurn) and merged into tool_result in API (skipped by
// isUserTextContent). Both sides agree → correct truncation index.
const ui: HistoryItem[] = [
userItem(1, 'first prompt'),
geminiItem(2),
{
type: 'notification',
id: 3,
text: 'btw side question',
} as HistoryItem,
userItem(5, 'next prompt'),
geminiItem(6),
];
const btwMergedIntoToolResult: Content = {
role: 'user',
parts: [
{
functionResponse: { name: 'tool', response: { result: 'ok' } },
} as unknown as Part,
{ text: 'btw side question' } as Part,
],
};
const api: Content[] = [
userContent('first prompt'),
modelContent('response with tool call'),
btwMergedIntoToolResult,
modelContent('response after btw'),
userContent('next prompt'),
modelContent('response 5'),
];
// notification is not counted → uiUserTurnCount=1 before 'next prompt'
// API has 2 user text entries (idx 0 and 4) → finds idx 4 correctly
expect(computeApiTruncationIndex(ui, 5, api)).toBe(4);
});
});

describe('with slash-command items in UI history', () => {
it('ignores slash-command items when counting user turns', () => {
const ui: HistoryItem[] = [
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/ui/utils/resumeHistoryUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ describe('resumeHistoryUtils', () => {
20,
);

expect(items).toContainEqual({ id: 21, type: 'user', text: 'save logs' });
expect(items).toContainEqual({
id: 21,
type: 'notification',
text: 'save logs',
});
});

it('marks tool results as error, captures thought text, and falls back when tool is missing', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/ui/utils/resumeHistoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function convertToHistoryItems(
payload?.displayText ||
extractTextFromParts(record.message?.parts as Part[]);
if (text) {
items.push({ type: 'user', text });
items.push({ type: 'notification', text });
}
break;
}
Expand Down
Loading