Skip to content

Replay your coding agent sessions as a map and a timeline

feat(viewer): add axisTickLabels to date ticks on a new UTC day

21lakshh480165e71645
diff --git a/viewer/src/core/sessionLayout.test.ts b/viewer/src/core/sessionLayout.test.ts
index eee0ea6..e10b34a 100644
--- a/viewer/src/core/sessionLayout.test.ts
+++ b/viewer/src/core/sessionLayout.test.ts
@@ -18,7 +18,7 @@ import {
type NodeRef,
} from './sessionMapModel';
import { deriveScopeDoc, sessionTasks, stampTasks, withoutSrcSeq } from './sessionScope';
-import { optionalLanesHeight } from './timelineDraw';
+import { axisTickLabels, optionalLanesHeight } from './timelineDraw';
import {
SIDEBAR_COLLAPSED_KEY,
adjacentSubagent,
@@ -1436,3 +1436,48 @@ describe('sessionErrors for failed hooks', () => {
expect(post?.worstRunLabel).toBe('PostToolUse:Bash hook error');
});
});
+
+describe('axisTickLabels', () => {
+ const start = '2026-10-21T07:04:00Z';
+ const H = 3_600_000;
+
+ it('is plain HH:MM within the start day', () => {
+ expect(axisTickLabels(start, [0, H, 3 * H])).toEqual([
+ '07:04',
+ '08:04',
+ '10:04',
+ ]);
+ });
+
+ it('dates only the first tick on each new UTC day', () => {
+ // A 26.9h session: the axis used to read 07:04 08:04 02:22 07:46 09:58.
+ expect(
+ axisTickLabels(start, [0, H, 19.3 * H, 24.7 * H, 26.9 * H])
+ ).toEqual(['07:04', '08:04', 'Oct 22 02:22', '07:46', '09:58']);
+ });
+
+ it('dates every tick that starts another day, across many days', () => {
+ expect(axisTickLabels(start, [0, 30 * H, 60 * H, 250 * H])).toEqual([
+ '07:04',
+ 'Oct 22 13:04',
+ 'Oct 23 19:04',
+ 'Oct 31 17:04',
+ ]);
+ });
+
+ it('flips at midnight, not after 24h', () => {
+ const late = '2026-10-21T23:50:00Z';
+ expect(axisTickLabels(late, [0, 9 * 60_000, 11 * 60_000])).toEqual([
+ '23:50',
+ '23:59',
+ 'Oct 22 00:01',
+ ]);
+ });
+
+ it('falls back to bare clocks for an unparseable start', () => {
+ expect(axisTickLabels('not a date', [0, 30 * H])).toEqual([
+ '--:--',
+ '--:--',
+ ]);
+ });
+});
diff --git a/viewer/src/core/timelineDraw.ts b/viewer/src/core/timelineDraw.ts
index 2bab69c..6d20e7a 100644
--- a/viewer/src/core/timelineDraw.ts
+++ b/viewer/src/core/timelineDraw.ts
@@ -473,6 +473,30 @@ export function drawPlayhead(g: DrawEnv, p: number) {
ctx.stroke();
}
+/**
+ * "HH:MM" labels for axis ticks at `ts` ms into the session. A tick that lands
+ * on a later UTC day than the tick before it also gets the date
+ * ("Oct 22 02:23"), so a session that runs past midnight doesn't read as going
+ * back in time.
+ */
+export function axisTickLabels(startedAt: string, ts: number[]): string[] {
+ const base = Date.parse(startedAt);
+ let prevDay = Math.floor(base / 86_400_000);
+ return ts.map((t) => {
+ const clock = clockAt(startedAt, t).slice(0, 5);
+ if (Number.isNaN(base)) return clock;
+ const day = Math.floor((base + t) / 86_400_000);
+ if (day === prevDay) return clock;
+ prevDay = day;
+ const date = new Date(base + t).toLocaleDateString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ timeZone: 'UTC',
+ });
+ return `${date} ${clock}`;
+ });
+}
+
/** Five clock ticks along the bottom. */
export function drawAxis(
g: DrawEnv,