Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit ddd5a46

Browse files
t3dotggclaude
andauthored
fix(web): sidebar v2 polish — jump hints, working duration, in-flight fade, settled sort (pingdotgg#4274)
Co-authored-by: Claude Fable 5 <[email protected]>
1 parent 88c69ff commit ddd5a46

3 files changed

Lines changed: 302 additions & 23 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import {
2020
resolveThreadRowClassName,
2121
resolveSidebarV2Status,
2222
resolveThreadStatusPill,
23+
resolveWorkingStartedAt,
24+
formatWorkingDurationLabel,
2325
shouldNavigateAfterProjectRemoval,
2426
shouldClearThreadSelectionOnMouseDown,
2527
sortLogicalProjectsForSidebar,
28+
sortSettledThreadsForSidebarV2,
2629
sortThreadsForSidebarV2,
2730
sortProjectsForSidebar,
2831
sortScopedProjectsForSidebar,
@@ -209,8 +212,10 @@ function makeLatestTurn(overrides?: {
209212
state: "completed",
210213
assistantMessageId: null,
211214
requestedAt: "2026-03-09T10:00:00.000Z",
212-
startedAt: overrides?.startedAt ?? "2026-03-09T10:00:00.000Z",
213-
completedAt: overrides?.completedAt ?? "2026-03-09T10:05:00.000Z",
215+
startedAt:
216+
overrides?.startedAt !== undefined ? overrides.startedAt : "2026-03-09T10:00:00.000Z",
217+
completedAt:
218+
overrides?.completedAt !== undefined ? overrides.completedAt : "2026-03-09T10:05:00.000Z",
214219
};
215220
}
216221

@@ -783,6 +788,141 @@ describe("sortThreadsForSidebarV2", () => {
783788
});
784789
});
785790

791+
describe("sortSettledThreadsForSidebarV2", () => {
792+
const settled = (input: {
793+
id: string;
794+
settledAt?: string | null;
795+
latestUserMessageAt?: string | null;
796+
latestTurn?: OrchestrationLatestTurn | null;
797+
updatedAt?: string;
798+
}) => ({
799+
id: input.id,
800+
settledAt: input.settledAt ?? null,
801+
latestUserMessageAt: input.latestUserMessageAt ?? null,
802+
latestTurn: input.latestTurn ?? null,
803+
updatedAt: input.updatedAt ?? "2026-03-09T09:00:00.000Z",
804+
});
805+
806+
it("orders by settle time, most recently settled first", () => {
807+
const sorted = sortSettledThreadsForSidebarV2([
808+
settled({
809+
id: "settled-first",
810+
settledAt: "2026-03-09T10:00:00.000Z",
811+
// Created/active later than the other thread: settle time must win.
812+
latestUserMessageAt: "2026-03-09T09:59:00.000Z",
813+
}),
814+
settled({
815+
id: "settled-last",
816+
settledAt: "2026-03-09T12:00:00.000Z",
817+
latestUserMessageAt: "2026-03-09T08:00:00.000Z",
818+
}),
819+
]);
820+
821+
expect(sorted.map((thread) => thread.id)).toEqual(["settled-last", "settled-first"]);
822+
});
823+
824+
it("falls back to last activity for auto-settled threads without a settledAt stamp", () => {
825+
const sorted = sortSettledThreadsForSidebarV2([
826+
settled({ id: "auto-old", latestUserMessageAt: "2026-03-09T08:00:00.000Z" }),
827+
settled({ id: "explicit", settledAt: "2026-03-09T10:00:00.000Z" }),
828+
settled({ id: "auto-recent", latestUserMessageAt: "2026-03-09T11:00:00.000Z" }),
829+
]);
830+
831+
expect(sorted.map((thread) => thread.id)).toEqual(["auto-recent", "explicit", "auto-old"]);
832+
});
833+
834+
it("counts a turn completion as activity for auto-settled threads", () => {
835+
// The message came in before the other thread's, but its turn finished
836+
// after: completion time is the real "work ended" moment.
837+
const sorted = sortSettledThreadsForSidebarV2([
838+
settled({ id: "message-only", latestUserMessageAt: "2026-03-09T10:04:00.000Z" }),
839+
settled({
840+
id: "completed-later",
841+
latestUserMessageAt: "2026-03-09T10:00:00.000Z",
842+
latestTurn: makeLatestTurn({ completedAt: "2026-03-09T10:30:00.000Z" }),
843+
}),
844+
]);
845+
846+
expect(sorted.map((thread) => thread.id)).toEqual(["completed-later", "message-only"]);
847+
});
848+
849+
it("breaks timestamp ties by id so the order is stable", () => {
850+
const sorted = sortSettledThreadsForSidebarV2([
851+
settled({ id: "b", settledAt: "2026-03-09T10:00:00.000Z" }),
852+
settled({ id: "a", settledAt: "2026-03-09T10:00:00.000Z" }),
853+
]);
854+
855+
expect(sorted.map((thread) => thread.id)).toEqual(["a", "b"]);
856+
});
857+
});
858+
859+
describe("resolveWorkingStartedAt", () => {
860+
const session = {
861+
threadId: ThreadId.make("thread-1"),
862+
status: "running" as const,
863+
providerName: "Codex",
864+
providerInstanceId: ProviderInstanceId.make("codex"),
865+
runtimeMode: DEFAULT_RUNTIME_MODE,
866+
activeTurnId: "turn-1" as never,
867+
lastError: null,
868+
updatedAt: "2026-03-09T10:02:00.000Z",
869+
};
870+
871+
it("uses the running turn's start time", () => {
872+
expect(
873+
resolveWorkingStartedAt({
874+
latestTurn: makeLatestTurn({ completedAt: null }),
875+
session,
876+
}),
877+
).toBe("2026-03-09T10:00:00.000Z");
878+
});
879+
880+
it("uses the request time while a turn awaits adoption", () => {
881+
expect(
882+
resolveWorkingStartedAt({
883+
latestTurn: makeLatestTurn({ startedAt: null, completedAt: null }),
884+
session,
885+
}),
886+
).toBe("2026-03-09T10:00:00.000Z");
887+
});
888+
889+
it("falls back to the session transition when the latest turn already completed", () => {
890+
expect(
891+
resolveWorkingStartedAt({
892+
latestTurn: makeLatestTurn(),
893+
session,
894+
}),
895+
).toBe("2026-03-09T10:02:00.000Z");
896+
});
897+
898+
it("skips a malformed startedAt instead of returning it", () => {
899+
expect(
900+
resolveWorkingStartedAt({
901+
latestTurn: makeLatestTurn({ startedAt: "not-a-date", completedAt: null }),
902+
session,
903+
}),
904+
).toBe("2026-03-09T10:00:00.000Z");
905+
});
906+
907+
it("returns null with neither a running turn nor a session", () => {
908+
expect(resolveWorkingStartedAt({ latestTurn: null, session: null })).toBeNull();
909+
});
910+
});
911+
912+
describe("formatWorkingDurationLabel", () => {
913+
it("formats seconds, minutes, and hours", () => {
914+
expect(formatWorkingDurationLabel(0)).toBe("0s");
915+
expect(formatWorkingDurationLabel(42_000)).toBe("42s");
916+
expect(formatWorkingDurationLabel(5 * 60_000)).toBe("5m");
917+
expect(formatWorkingDurationLabel(90 * 60_000)).toBe("1h 30m");
918+
});
919+
920+
it("clamps negative and non-finite elapsed values to zero", () => {
921+
expect(formatWorkingDurationLabel(-5_000)).toBe("0s");
922+
expect(formatWorkingDurationLabel(Number.NaN)).toBe("0s");
923+
});
924+
});
925+
786926
describe("resolveThreadStatusPill", () => {
787927
const baseThread = {
788928
hasActionableProposedPlan: false,

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,18 @@ export function firstValidTimestampMs(
502502
return 0;
503503
}
504504

505+
/** String twin of firstValidTimestampMs for callers that need the ISO string
506+
(display labels, tick anchors) rather than epoch ms. */
507+
export function firstValidTimestamp(
508+
...candidates: ReadonlyArray<string | null | undefined>
509+
): string | null {
510+
for (const candidate of candidates) {
511+
if (candidate == null) continue;
512+
if (!Number.isNaN(Date.parse(candidate))) return candidate;
513+
}
514+
return null;
515+
}
516+
505517
// v2 sort: static creation order, newest thread on top. Activity NEVER
506518
// reorders the list — a row holds its position from open until settled, so
507519
// the screen only moves at lifecycle transitions. Status (including pending
@@ -516,6 +528,73 @@ export function sortThreadsForSidebarV2<
516528
);
517529
}
518530

531+
type SettledTimestampInput = Pick<
532+
SidebarThreadSummary,
533+
"settledAt" | "latestUserMessageAt" | "latestTurn" | "updatedAt"
534+
>;
535+
536+
/** The timestamp a settled row sorts and labels by: settledAt when stamped
537+
(explicit settles), otherwise last activity — the same candidates
538+
threadLastActivityAt feeds the auto-settle window (user message plus all
539+
latestTurn stamps), so a thread whose last activity was a turn completion
540+
doesn't sort by an older message time. updatedAt is the final net. */
541+
export function resolveSettledTimestamp(thread: SettledTimestampInput): string | null {
542+
const settledAt = firstValidTimestamp(thread.settledAt);
543+
if (settledAt !== null) return settledAt;
544+
let latest: string | null = null;
545+
let latestMs = Number.NEGATIVE_INFINITY;
546+
for (const candidate of [
547+
thread.latestUserMessageAt,
548+
thread.latestTurn?.requestedAt,
549+
thread.latestTurn?.startedAt,
550+
thread.latestTurn?.completedAt,
551+
]) {
552+
if (candidate == null) continue;
553+
const parsed = Date.parse(candidate);
554+
if (!Number.isNaN(parsed) && parsed > latestMs) {
555+
latest = candidate;
556+
latestMs = parsed;
557+
}
558+
}
559+
return latest ?? firstValidTimestamp(thread.updatedAt);
560+
}
561+
562+
// Settled rows are history, so they order by when the work ENDED, not when
563+
// the thread was created or last touched.
564+
export function sortSettledThreadsForSidebarV2<
565+
T extends SettledTimestampInput & { readonly id: string },
566+
>(threads: readonly T[]): T[] {
567+
const timestampMs = (thread: T) => {
568+
const timestamp = resolveSettledTimestamp(thread);
569+
return timestamp === null ? 0 : Date.parse(timestamp);
570+
};
571+
return [...threads].toSorted(
572+
(left, right) => timestampMs(right) - timestampMs(left) || left.id.localeCompare(right.id),
573+
);
574+
}
575+
576+
/** The timestamp a working thread's elapsed label counts from: the running
577+
turn's start (request time until adoption), falling back to the session's
578+
last transition when the turn projection lags behind. Malformed
579+
timestamps fall through to the next candidate, not just missing ones. */
580+
export function resolveWorkingStartedAt(
581+
thread: Pick<SidebarThreadSummary, "latestTurn" | "session">,
582+
): string | null {
583+
const turn = thread.latestTurn;
584+
if (turn && turn.completedAt === null) {
585+
return firstValidTimestamp(turn.startedAt, turn.requestedAt, thread.session?.updatedAt);
586+
}
587+
return firstValidTimestamp(thread.session?.updatedAt);
588+
}
589+
590+
export function formatWorkingDurationLabel(elapsedMs: number): string {
591+
const seconds = Number.isFinite(elapsedMs) ? Math.max(0, Math.floor(elapsedMs / 1000)) : 0;
592+
if (seconds < 60) return `${seconds}s`;
593+
const minutes = Math.floor(seconds / 60);
594+
if (minutes < 60) return `${minutes}m`;
595+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
596+
}
597+
519598
export function resolveThreadStatusPill(input: {
520599
thread: ThreadStatusInput;
521600
}): ThreadStatusPill | null {

0 commit comments

Comments
 (0)