diff --git a/apps/desktop/src/index.css b/apps/desktop/src/index.css index 7642e3185..08556f6a1 100644 --- a/apps/desktop/src/index.css +++ b/apps/desktop/src/index.css @@ -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); diff --git a/apps/desktop/src/state/widgets.test.ts b/apps/desktop/src/state/widgets.test.ts index f72a210a5..2f4498caa 100644 --- a/apps/desktop/src/state/widgets.test.ts +++ b/apps/desktop/src/state/widgets.test.ts @@ -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 => ({ harness: "codex", @@ -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, + }); + }); +}); diff --git a/apps/desktop/src/state/widgets.ts b/apps/desktop/src/state/widgets.ts index aaba62bf7..8cd4607cd 100644 --- a/apps/desktop/src/state/widgets.ts +++ b/apps/desktop/src/state/widgets.ts @@ -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; +} + +/** + * 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, 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(); + 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(); diff --git a/apps/desktop/src/ui/NewThreadWidgets.tsx b/apps/desktop/src/ui/NewThreadWidgets.tsx index e6fdff672..7290e0b9b 100644 --- a/apps/desktop/src/ui/NewThreadWidgets.tsx +++ b/apps/desktop/src/ui/NewThreadWidgets.tsx @@ -29,11 +29,14 @@ import { heatmapWeeks, monthBounds, projectThreads, + type Streak, + streakOf, turnsPerDay, } from "../state/widgets"; import { Activity, CalendarDays, + Flame, Gauge, GitMerge, GitPullRequest, @@ -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; @@ -92,10 +98,13 @@ function Card({ )} >
-

- - {label} -

+
+

+ + {label} +

+ {aside} +
{children}
@@ -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 ( + + + + {streak.current === 0 ? "Start a streak" : `${streak.current}-day streak`} + + + ); +} + 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 ( - + } + > {rows === undefined ? ( ) : totalTurns === 0 ? ( @@ -152,7 +203,11 @@ function ActivityCard({ rows, since }: { rows?: UsageRow[]; since: string }) { ) : ( diff --git a/apps/desktop/src/ui/icons.tsx b/apps/desktop/src/ui/icons.tsx index ae83599a6..88d06a00a 100644 --- a/apps/desktop/src/ui/icons.tsx +++ b/apps/desktop/src/ui/icons.tsx @@ -58,6 +58,7 @@ import { FileDiffIcon, FilterHorizontalIcon, FilterIcon, + FireIcon, Folder01Icon, FolderAddIcon, FolderGitTwoIcon, @@ -297,6 +298,7 @@ export const FilePlus = (props: IconProps) => ; export const FileText = (props: IconProps) => ; export const Filter = (props: IconProps) => ; +export const Flame = (props: IconProps) => ; export const FlaskConical = (props: IconProps) => ( );