Render context compaction as standard work log entries

- Replace timeline marker treatment with normal grouped work rows
- Switch context window meter to an SVG ring and show auto-compaction
This commit is contained in:
Julius Marminge committed 2026-03-24 12:14:18 -07:00
1 parent 0cc49b27b7
commit ea69a017dd
5 files changed
+42 -67

No files matched your search

@@ -1,5 +1,3 @@
import type { CSSProperties } from "react";
import { cn } from "~/lib/utils";
import { type ContextWindowSnapshot, formatContextWindowTokens } from "~/lib/contextWindow";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -14,26 +12,13 @@ function formatPercentage(value: number | null): string | null {
return `${Math.round(value)}%`;
}
function ringStyle(usage: ContextWindowSnapshot): CSSProperties {
const percentage = Math.max(0, Math.min(100, usage.usedPercentage ?? 0));
const tone =
percentage >= 90
? "var(--color-rose-500)"
: percentage >= 75
? "var(--color-amber-500)"
: "var(--color-foreground)";
return {
backgroundImage:
usage.usedPercentage === null
? "linear-gradient(var(--color-muted), var(--color-muted))"
: `conic-gradient(${tone} ${percentage}%, color-mix(in oklab, var(--color-muted) 70%, transparent) 0)`,
};
}
export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
const { usage } = props;
const usedPercentage = formatPercentage(usage.usedPercentage);
const normalizedPercentage = Math.max(0, Math.min(100, usage.usedPercentage ?? 0));
const radius = 10;
const circumference = 2 * Math.PI * radius;
const dashOffset = circumference - (normalizedPercentage / 100) * circumference;
return (
<Tooltip>
@@ -48,18 +33,37 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
: `Context window ${formatContextWindowTokens(usage.usedTokens)} tokens used`
}
>
<span
className="relative flex h-6 w-6 items-center justify-center rounded-full p-[2px]"
style={ringStyle(usage)}
>
<span className="relative flex h-6 w-6 items-center justify-center">
<svg
viewBox="0 0 24 24"
className="-rotate-90 absolute inset-0 h-full w-full transform-gpu"
aria-hidden="true"
>
<circle
cx="12"
cy="12"
r={radius}
fill="none"
stroke="color-mix(in oklab, var(--color-muted) 70%, transparent)"
strokeWidth="2"
/>
<circle
cx="12"
cy="12"
r={radius}
fill="none"
stroke="var(--color-muted-foreground)"
strokeWidth="2"
strokeLinecap="round"
strokeDasharray={circumference}
strokeDashoffset={dashOffset}
className="transition-[stroke-dashoffset] duration-500 ease-out motion-reduce:transition-none"
/>
</svg>
<span
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-background text-[8px] font-medium",
usage.usedPercentage !== null && usage.usedPercentage >= 90
? "text-rose-500"
: usage.usedPercentage !== null && usage.usedPercentage >= 75
? "text-amber-500"
: "text-muted-foreground",
"relative flex h-[20px] w-[20px] items-center justify-center rounded-full bg-background text-[8px] font-medium",
"text-muted-foreground",
)}
>
{usage.usedPercentage !== null
@@ -95,6 +99,11 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
tokens
</div>
) : null}
{usage.compactsAutomatically ? (
<div className="text-xs text-muted-foreground">
Automatically compacts its context when needed.
</div>
) : null}
</div>
</TooltipPopup>
</Tooltip>
@@ -97,7 +97,7 @@ describe("MessagesTimeline", () => {
expect(markup).toContain("yoo what&#x27;s ");
});
it("renders context compaction markers as centered chips", async () => {
it("renders context compaction entries in the normal work log", async () => {
const { MessagesTimeline } = await import("./MessagesTimeline");
const markup = renderToStaticMarkup(
<MessagesTimeline
@@ -116,7 +116,6 @@ describe("MessagesTimeline", () => {
createdAt: "2026-03-17T19:12:28.000Z",
label: "Context compacted",
tone: "info",
display: "timeline-marker",
},
},
]}
@@ -139,5 +138,6 @@ describe("MessagesTimeline", () => {
);
expect(markup).toContain("Context compacted");
expect(markup).toContain("Work log");
});
});
@@ -147,25 +147,11 @@ export const MessagesTimeline = memo(function MessagesTimeline({
}
if (timelineEntry.kind === "work") {
if (timelineEntry.entry.display === "timeline-marker") {
nextRows.push({
kind: "work",
id: timelineEntry.id,
createdAt: timelineEntry.createdAt,
groupedEntries: [timelineEntry.entry],
});
continue;
}
const groupedEntries = [timelineEntry.entry];
let cursor = index + 1;
while (cursor < timelineEntries.length) {
const nextEntry = timelineEntries[cursor];
if (
!nextEntry ||
nextEntry.kind !== "work" ||
nextEntry.entry.display === "timeline-marker"
)
break;
if (!nextEntry || nextEntry.kind !== "work") break;
groupedEntries.push(nextEntry.entry);
cursor += 1;
}
@@ -328,21 +314,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({
(() => {
const groupId = row.id;
const groupedEntries = row.groupedEntries;
const markerEntry =
groupedEntries.length === 1 && groupedEntries[0]?.display === "timeline-marker"
? groupedEntries[0]
: null;
if (markerEntry) {
return (
<div className="my-3 flex items-center gap-3">
<span className="h-px flex-1 bg-border" />
<span className="rounded-full border border-border bg-background px-2.5 py-1 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/80">
{markerEntry.label}
</span>
<span className="h-px flex-1 bg-border" />
</div>
);
}
const isExpanded = expandedWorkGroups[groupId] ?? false;
const hasOverflow = groupedEntries.length > MAX_VISIBLE_WORK_LOG_ENTRIES;
const visibleEntries =
+1 -2
View File
@@ -992,7 +992,7 @@ describe("deriveWorkLogEntries context window handling", () => {
expect(entries[0]?.label).toBe("Ran command");
});
it("marks context compaction activities as timeline markers", () => {
it("keeps context compaction activities as normal work log entries", () => {
const entries = deriveWorkLogEntries(
[
makeActivity({
@@ -1008,7 +1008,6 @@ describe("deriveWorkLogEntries context window handling", () => {
expect(entries).toHaveLength(1);
expect(entries[0]?.label).toBe("Context compacted");
expect(entries[0]?.display).toBe("timeline-marker");
});
});
-4
View File
@@ -40,7 +40,6 @@ export interface WorkLogEntry {
command?: string;
changedFiles?: ReadonlyArray<string>;
tone: "thinking" | "tool" | "info" | "error";
display?: "timeline-marker";
toolTitle?: string;
itemType?: ToolLifecycleItemType;
requestKind?: PendingApproval["requestKind"];
@@ -523,9 +522,6 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
if (requestKind) {
entry.requestKind = requestKind;
}
if (activity.kind === "context-compaction") {
entry.display = "timeline-marker";
}
const collapseKey = deriveToolLifecycleCollapseKey(entry);
if (collapseKey) {
entry.collapseKey = collapseKey;