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
128 changes: 127 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageId } from "@okcode/contracts";
import { MessageId, TurnId } from "@okcode/contracts";
import type { ReactElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { beforeAll, describe, expect, it, vi } from "vitest";
Expand Down Expand Up @@ -201,4 +201,130 @@ describe("MessagesTimeline", () => {
expect(markup).toContain("Manage hotkeys");
expect(markup).toContain("No shortcut assigned");
});

it("renders an open diff action when a turn diff summary has files", async () => {
const { MessagesTimeline } = await import("./MessagesTimeline");
const assistantMessageId = MessageId.makeUnsafe("assistant-1");
const markup = renderWithI18n(
<MessagesTimeline
threadId={"thread-1" as never}
hasMessages
isWorking={false}
activeTurnInProgress={false}
activeTurnStartedAt={null}
scrollContainer={null}
timelineEntries={[
{
id: "entry-1",
kind: "message",
createdAt: "2026-03-17T19:12:28.000Z",
message: {
id: assistantMessageId,
role: "assistant",
text: "Updated the repo.",
createdAt: "2026-03-17T19:12:28.000Z",
completedAt: "2026-03-17T19:12:30.000Z",
streaming: false,
},
},
]}
completionDividerBeforeEntryId={null}
completionSummary={null}
turnDiffSummaryByAssistantMessageId={
new Map([
[
assistantMessageId,
{
turnId: TurnId.makeUnsafe("turn-1"),
completedAt: "2026-03-17T19:12:30.000Z",
files: [{ path: "src/index.ts", additions: 1, deletions: 0 }],
},
],
])
}
nowIso="2026-03-17T19:12:30.000Z"
expandedWorkGroups={{}}
onToggleWorkGroup={() => {}}
revertTurnCountByUserMessageId={new Map()}
onRevertUserMessage={() => {}}
isRevertingCheckpoint={false}
onImageExpand={() => {}}
markdownCwd={undefined}
resolvedTheme="light"
showReasoningContent={false}
timestampFormat="locale"
workspaceRoot={undefined}
onRemoveQueuedMessage={() => {}}
shortcutGuides={EMPTY_SHORTCUT_GUIDES}
onOpenSettings={() => {}}
onOpenTurnDiff={() => {}}
/>,
);

expect(markup).toContain("Open diff");
expect(markup).toContain("Changed files (1)");
});

it("renders an open diff action when a turn diff exists but the file summary is empty", async () => {
const { MessagesTimeline } = await import("./MessagesTimeline");
const assistantMessageId = MessageId.makeUnsafe("assistant-2");
const markup = renderWithI18n(
<MessagesTimeline
threadId={"thread-1" as never}
hasMessages
isWorking={false}
activeTurnInProgress={false}
activeTurnStartedAt={null}
scrollContainer={null}
timelineEntries={[
{
id: "entry-1",
kind: "message",
createdAt: "2026-03-17T19:12:28.000Z",
message: {
id: assistantMessageId,
role: "assistant",
text: "Updated the repo.",
createdAt: "2026-03-17T19:12:28.000Z",
completedAt: "2026-03-17T19:12:30.000Z",
streaming: false,
},
},
]}
completionDividerBeforeEntryId={null}
completionSummary={null}
turnDiffSummaryByAssistantMessageId={
new Map([
[
assistantMessageId,
{
turnId: TurnId.makeUnsafe("turn-2"),
completedAt: "2026-03-17T19:12:30.000Z",
files: [],
},
],
])
}
nowIso="2026-03-17T19:12:30.000Z"
expandedWorkGroups={{}}
onToggleWorkGroup={() => {}}
revertTurnCountByUserMessageId={new Map()}
onRevertUserMessage={() => {}}
isRevertingCheckpoint={false}
onImageExpand={() => {}}
markdownCwd={undefined}
resolvedTheme="light"
showReasoningContent={false}
timestampFormat="locale"
workspaceRoot={undefined}
onRemoveQueuedMessage={() => {}}
shortcutGuides={EMPTY_SHORTCUT_GUIDES}
onOpenSettings={() => {}}
onOpenTurnDiff={() => {}}
/>,
);

expect(markup).toContain("Open diff");
expect(markup).toContain("Diff available");
});
});
69 changes: 44 additions & 25 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({
const turnSummary = turnDiffSummaryByAssistantMessageId.get(row.message.id);
if (!turnSummary) return null;
const checkpointFiles = turnSummary.files;
if (checkpointFiles.length === 0) return null;
const summaryStat = summarizeTurnDiffStats(checkpointFiles);
const changedFileCountLabel = String(checkpointFiles.length);
const allDirectoriesExpanded =
Expand All @@ -573,31 +572,46 @@ export const MessagesTimeline = memo(function MessagesTimeline({
return (
<div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5">
<div className="flex items-center justify-between gap-2">
<button
type="button"
className="group flex items-center gap-1.5 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65 hover:text-muted-foreground/90 transition-colors duration-150"
onClick={() => onToggleFileSection(turnSummary.turnId)}
>
<ChevronRightIcon
aria-hidden="true"
className={cn(
"size-3 shrink-0 transition-transform duration-150",
!isFileSectionCollapsed && "rotate-90",
{checkpointFiles.length > 0 ? (
<button
type="button"
className="group flex items-center gap-1.5 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65 transition-colors duration-150 hover:text-muted-foreground/90"
onClick={() => onToggleFileSection(turnSummary.turnId)}
>
<ChevronRightIcon
aria-hidden="true"
className={cn(
"size-3 shrink-0 transition-transform duration-150",
!isFileSectionCollapsed && "rotate-90",
)}
/>
<span>Changed files ({changedFileCountLabel})</span>
{hasNonZeroStat(summaryStat) && (
<>
<span className="mx-1">•</span>
<DiffStatLabel
additions={summaryStat.additions}
deletions={summaryStat.deletions}
/>
</>
)}
/>
<span>Changed files ({changedFileCountLabel})</span>
{hasNonZeroStat(summaryStat) && (
<>
<span className="mx-1">•</span>
<DiffStatLabel
additions={summaryStat.additions}
deletions={summaryStat.deletions}
/>
</>
)}
</button>
</button>
) : (
<div className="flex items-center gap-1.5 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65">
<EyeIcon className="size-3 shrink-0" />
<span>Diff available</span>
</div>
)}
<div className="flex items-center gap-1.5">
{!isFileSectionCollapsed && (
<Button
type="button"
size="xs"
variant="outline"
onClick={() => onOpenTurnDiff(turnSummary.turnId)}
>
Open diff
</Button>
{checkpointFiles.length > 0 && !isFileSectionCollapsed && (
<Button
type="button"
size="xs"
Expand All @@ -609,7 +623,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
)}
</div>
</div>
{!isFileSectionCollapsed && (
{checkpointFiles.length > 0 && !isFileSectionCollapsed && (
<div className="mt-1.5">
<ChangedFilesTree
key={`changed-files-tree:${turnSummary.turnId}`}
Expand All @@ -622,6 +636,11 @@ export const MessagesTimeline = memo(function MessagesTimeline({
/>
</div>
)}
{checkpointFiles.length === 0 && (
<p className="mt-1.5 text-xs text-muted-foreground/75">
Open the diff to inspect changes when the file summary is unavailable.
</p>
)}
</div>
);
})()}
Expand Down
Loading