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
29 changes: 29 additions & 0 deletions apps/desktop/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,35 @@
border-radius: 2px;
}

/* The days of the current streak: a hairline of the accent, so the run reads as one line. */
.rc-heat-streak {
box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--color-accent) 70%, transparent);
}

/* The streak's flame catches once when the card appears; a milestone run keeps a soft glow. */
.rc-streak-flame {
transform-origin: 50% 90%;
animation: rc-streak-catch 700ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.rc-streak-milestone {
box-shadow: 0 0 10px -2px color-mix(in oklab, var(--color-accent) 60%, transparent);
}

@keyframes rc-streak-catch {
0% {
transform: scale(0.4) rotate(-12deg);
opacity: 0;
}
60% {
transform: scale(1.2) rotate(6deg);
opacity: 1;
}
100% {
transform: none;
}
}

/* Small pills over text (jump to latest, toasts): the denser glass, so their label reads. */
.rc-glass-strong {
background: var(--rc-glass-bg-strong);
Expand Down
35 changes: 34 additions & 1 deletion apps/desktop/src/state/widgets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { describe, expect, test } from "bun:test";
import type { UsageRow } from "../acp/rustcode";
import type { SessionSummary } from "../acp/types";
import { heatmapWeeks, monthBounds, projectThreads, turnsPerDay } from "./widgets";
import { heatmapWeeks, monthBounds, projectThreads, streakOf, turnsPerDay } from "./widgets";

const row = (over: Partial<UsageRow> = {}): UsageRow => ({
harness: "codex",
Expand Down Expand Up @@ -133,3 +133,36 @@ test("the overview defaults closed and persists its choice", async () => {
else Reflect.deleteProperty(scope, "localStorage");
}
});

describe("the activity streak", () => {
const today = new Date("2026-06-10T12:00:00Z");
const days = (...entries: [string, number][]) => new Map(entries);

test("counts the days in a row up to today", () => {
const streak = streakOf(days(["2026-06-08", 2], ["2026-06-09", 1], ["2026-06-10", 4]), today);
expect(streak).toMatchObject({ current: 3, longest: 3, today: true });
expect([...streak.days].sort()).toEqual(["2026-06-08", "2026-06-09", "2026-06-10"]);
});

test("a quiet today keeps yesterday's run alive", () => {
expect(streakOf(days(["2026-06-08", 1], ["2026-06-09", 1]), today)).toMatchObject({
current: 2,
today: false,
});
});

test("a missed day ends the run, and the longest one is remembered", () => {
const streak = streakOf(
days(["2026-05-01", 1], ["2026-05-02", 1], ["2026-05-03", 1], ["2026-05-04", 1], ["2026-06-08", 1]),
today,
);
expect(streak).toMatchObject({ current: 0, longest: 4, today: false });
});

test("a day with no turns does not count", () => {
expect(streakOf(days(["2026-06-09", 0], ["2026-06-10", 1]), today)).toMatchObject({
current: 1,
longest: 1,
});
});
});
34 changes: 34 additions & 0 deletions apps/desktop/src/state/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ export function heatmapWeeks(
return columns;
}

/** A run of days in a row with at least one turn, as the activity card counts it. */
export interface Streak {
/** Days in a row up to today, or up to yesterday while today has nothing yet. */
current: number;
/** The longest run in the days read, the current one included. */
longest: number;
/** Whether today already counts. */
today: boolean;
/** The days of the current run, so the heatmap can mark them. */
days: ReadonlySet<string>;
}

/**
* The streak in a day-by-day report. A quiet today does not break it: the run
* still counts up to yesterday until the day is over, so the card says what
* keeps it going instead of showing zero every morning.
*/
export function streakOf(turns: ReadonlyMap<string, number>, today: Date = new Date()): Streak {
const active = (day: string) => (turns.get(day) ?? 0) > 0;
const last = today.toISOString().slice(0, 10);
const days = new Set<string>();
const ranToday = active(last);
for (let day = ranToday ? last : plusDays(last, -1); active(day); day = plusDays(day, -1)) days.add(day);
let longest = days.size;
let run = 0;
let previous = "";
for (const day of [...turns.keys()].filter(active).sort()) {
run = previous && plusDays(previous, 1) === day ? run + 1 : 1;
previous = day;
if (run > longest) longest = run;
}
return { current: days.size, longest, today: ranToday, days };
}

/** The UTC days a month starts on: this one, and the one before it. */
export function monthBounds(now: Date = new Date()): { since: string; previousSince: string } {
const year = now.getUTCFullYear();
Expand Down
67 changes: 61 additions & 6 deletions apps/desktop/src/ui/NewThreadWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ import {
heatmapWeeks,
monthBounds,
projectThreads,
type Streak,
streakOf,
turnsPerDay,
} from "../state/widgets";
import {
Activity,
CalendarDays,
Flame,
Gauge,
GitMerge,
GitPullRequest,
Expand Down Expand Up @@ -71,10 +74,13 @@ function Card({
label,
icon: Icon,
span,
aside,
children,
}: {
label: string;
icon: LucideIcon;
/** Something small at the end of the card's label row. */
aside?: ReactNode;
/** How wide the card is in the dashboard's six columns (from `lg`). */
span: string;
children: ReactNode;
Expand All @@ -92,10 +98,13 @@ function Card({
)}
>
<div className="rc-overview-body flex min-h-0 flex-1 flex-col gap-2">
<h3 className="flex shrink-0 items-center gap-1.5 text-caption font-medium text-fg-muted">
<Icon size={12} className="shrink-0" />
{label}
</h3>
<div className="flex shrink-0 items-center justify-between gap-2">
<h3 className="flex min-w-0 items-center gap-1.5 text-caption font-medium text-fg-muted">
<Icon size={12} className="shrink-0" />
{label}
</h3>
{aside}
</div>
{children}
</div>
</section>
Expand All @@ -122,17 +131,59 @@ function CardRow({ onClick, title, children }: { onClick: () => void; title: str
);
}

/** Streak lengths worth a little more warmth: a week, a month, a hundred days. */
const MILESTONES = [7, 30, 100] as const;

/**
* The streak at the end of the activity card's label: a flame and the days in a row
* with a turn. It is lit once today counts; until then it is quiet and says what keeps
* the run going. A run that reaches a milestone glows.
*/
function StreakBadge({ streak }: { streak: Streak }) {
if (streak.current === 0 && streak.longest === 0) return null;
const milestone = [...MILESTONES].reverse().find((days) => streak.current >= days);
const best = streak.longest > streak.current ? ` · best ${count(streak.longest, "day")}` : "";
const label =
streak.current === 0
? `No streak right now${best}. Run a turn today to start one.`
: streak.today
? `${count(streak.current, "day")} in a row${best}. Today counts.`
: `${count(streak.current, "day")} in a row${best}. Run a turn today to keep it.`;
return (
<Tooltip label={label}>
<span
role="img"
aria-label={label}
className={cx(
"rc-streak flex shrink-0 items-center gap-1 rounded-full px-1.5 py-px text-caption font-medium tabular",
streak.today ? "bg-accent/15 text-accent" : "bg-fill-subtle text-fg-muted",
streak.today && milestone && "rc-streak-milestone",
)}
>
<Flame size={12} className={cx("shrink-0", streak.today && "rc-streak-flame")} />
{streak.current === 0 ? "Start a streak" : `${streak.current}-day streak`}
</span>
</Tooltip>
);
}

function ActivityCard({ rows, since }: { rows?: UsageRow[]; since: string }) {
const sessions = useApp((s) => s.sessions);
const turns = useMemo(() => turnsPerDay(rows ?? []), [rows]);
const columns = useMemo(() => heatmapWeeks(turns, HEATMAP_WEEKS), [turns]);
const streak = useMemo(() => streakOf(turns), [turns]);
const totalTurns = useMemo(() => [...turns.values()].reduce((sum, n) => sum + n, 0), [turns]);
const activeThreads = useMemo(() => {
const from = Date.parse(`${since}T00:00:00Z`);
return sessions.filter((session) => (session.updatedAt ?? 0) >= from).length;
}, [sessions, since]);
return (
<Card label="Activity" icon={Activity} span="lg:col-span-3">
<Card
label="Activity"
icon={Activity}
span="lg:col-span-3"
aside={rows === undefined ? undefined : <StreakBadge streak={streak} />}
>
{rows === undefined ? (
<Skeleton className="h-[62px] w-full flex-1" />
) : totalTurns === 0 ? (
Expand All @@ -152,7 +203,11 @@ function ActivityCard({ rows, since }: { rows?: UsageRow[]; since: string }) {
<span
key={cell.day}
title={`${cell.day} · ${count(cell.turns, "turn")}`}
className={cx("rc-heat-cell h-[7px] w-full", SHADE[cell.level])}
className={cx(
"rc-heat-cell h-[7px] w-full",
SHADE[cell.level],
streak.days.has(cell.day) && "rc-heat-streak",
)}
/>
) : (
<span key={`future-${index}-${day}`} className="h-[7px] w-full" />
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
FileDiffIcon,
FilterHorizontalIcon,
FilterIcon,
FireIcon,
Folder01Icon,
FolderAddIcon,
FolderGitTwoIcon,
Expand Down Expand Up @@ -297,6 +298,7 @@ export const FilePlus = (props: IconProps) => <Rounded name="FilePlus" icon={Fil
export const FilePlus2 = (props: IconProps) => <Rounded name="FilePlus2" icon={FileAddIcon} {...props} />;
export const FileText = (props: IconProps) => <Rounded name="FileText" icon={File02Icon} {...props} />;
export const Filter = (props: IconProps) => <Rounded name="Filter" icon={FilterIcon} {...props} />;
export const Flame = (props: IconProps) => <Rounded name="Flame" icon={FireIcon} {...props} />;
export const FlaskConical = (props: IconProps) => (
<Rounded name="FlaskConical" icon={Chemistry01Icon} {...props} />
);
Expand Down
Loading