Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat(community): bot activity heatmap on my-bots cards
Guse6fe530887c2
diff --git a/src/web/src/components/community/bots/bot-activity-heatmap.test.ts b/src/web/src/components/community/bots/bot-activity-heatmap.test.tsnew file mode 100644index 000000000..5f8c29fc9--- /dev/null+++ b/src/web/src/components/community/bots/bot-activity-heatmap.test.ts@@ -0,0 +1,65 @@+import { describe, it, expect, vi, afterEach } from "vitest"+import React from "react"+import TestRenderer, { act } from "react-test-renderer"+import { utcDayKeyDaysAgo } from "@alook/shared"+import { BotActivityHeatmap, type BotActivityDay } from "./bot-activity-heatmap"++// The heatmap must place each sparse day at its true calendar slot (a gap of N+// days = N empty cells between them), NOT left-pad by count — Alli/Blair+// /Gus/working #666/#667. These tests pin that: cells are keyed by UTC day-key+// and filled from the sparse array by matching that key.++function render(days: BotActivityDay[]) {+ let r!: TestRenderer.ReactTestRenderer+ act(() => {+ r = TestRenderer.create(+ React.createElement(BotActivityHeatmap, { days, variant: "mobile" }),+ )+ })+ return r+}++// Every leaf cell in DOM order — the grid renders exactly 30, oldest→newest.+function cells(r: TestRenderer.ReactTestRenderer) {+ return r.root.findAll(+ (n) => typeof n.type === "string" && n.type === "span",+ )+}++afterEach(() => vi.useRealTimers())++describe("BotActivityHeatmap — calendar-axis fill", () => {+ it("always renders exactly 30 cells regardless of how sparse the data is", () => {+ expect(cells(render([])).length).toBe(30)+ expect(+ cells(render([{ day: utcDayKeyDaysAgo(new Date(), 0), handledCount: 3, sentCount: 1 }]))+ .length,+ ).toBe(30)+ })++ it("places two days 15 apart at their true slots, not adjacent", () => {+ const now = new Date()+ const older = utcDayKeyDaysAgo(now, 20) // 20 days ago+ const newer = utcDayKeyDaysAgo(now, 5) // 5 days ago+ const r = render([+ { day: older, handledCount: 4, sentCount: 0 },+ { day: newer, handledCount: 1, sentCount: 2 },+ ])+ const all = cells(r)+ // Oldest→newest over a 30-day axis (today-29 … today): index = 29 - daysAgo.+ const olderIdx = all.findIndex((c) => c.props.title?.includes("4 handled"))+ const newerIdx = all.findIndex((c) => c.props.title?.includes("1 handled"))+ expect(olderIdx).toBe(29 - 20)+ expect(newerIdx).toBe(29 - 5)+ // 15 calendar days apart → 15 index slots apart, not glued together.+ expect(newerIdx - olderIdx).toBe(15)+ })++ it("gives empty days no tooltip (bucket-0 track cells)", () => {+ const r = render([{ day: utcDayKeyDaysAgo(new Date(), 10), handledCount: 2, sentCount: 0 }])+ const withTitle = cells(r).filter((c) => c.props.title)+ // Only the single active day carries a tooltip; the other 29 are empty.+ expect(withTitle.length).toBe(1)+ expect(withTitle[0].props.title).toContain("2 handled · 0 sent")+ })+})diff --git a/src/web/src/components/community/bots/bot-activity-heatmap.tsx b/src/web/src/components/community/bots/bot-activity-heatmap.tsxnew file mode 100644index 000000000..397152b1e--- /dev/null+++ b/src/web/src/components/community/bots/bot-activity-heatmap.tsx@@ -0,0 +1,155 @@+"use client"++import { useMemo } from "react"+import { utcDayKeyDaysAgo } from "@alook/shared"++// One day's activity for a bot: post-gate messages handled + messages the bot+// sent. Both counts are non-negative integers; a day with no activity is 0/0.+// Field names match the backend rollup contract (Cecilia /Gus/working #617):+// `{ day, handledCount, sentCount }[]`, past 30 days, missing days padded 0.+// A brand-new bot returns [] (normal, not an error) — we render 30 empty cells.+export type BotActivityDay = {+ // Calendar day, "YYYY-MM-DD".+ day: string+ handledCount: number+ sentCount: number+}++// Gus asked for "past 30 days" (Gus /Gus/uiux #608). Responsive layout is set+// in the grid classes below: mobile = full-width 3×10 ribbon, desktop = a thin+// 4-row strip on the card's right. Cells flow column-by-column (grid-flow-col),+// like a GitHub contribution graph. 30 divides both row counts → flush columns.+const WINDOW_DAYS = 30++// Intensity buckets (0 = no activity, then four filled steps like GitHub).+// The fill is `--status-online` (the "alive/online" green already on this+// card's Online pill — Alli /Gus/uiux #154) at rising strength, so "active"+// and "alive" speak the same color and it reads in both themes without a+// bespoke palette. Bucket 0 is a faint track cell (also the all-zero state).+const BUCKET_CLASSES = [+ "bg-muted-foreground/15", // 0 — no activity / empty day+ "bg-status-online/30",+ "bg-status-online/55",+ "bg-status-online/80",+ "bg-status-online", // busiest+] as const++const DATE_FMT = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric" })++function bucketFor(total: number, max: number): number {+ if (total <= 0 || max <= 0) return 0+ // Map (0, max] onto buckets 1..4 by quartile of the observed max, so a quiet+ // month still shows contrast instead of collapsing to a single step (Alli+ // #628 adopted this relative scale over absolute thresholds).+ const ratio = total / max+ if (ratio > 0.75) return 4+ if (ratio > 0.5) return 3+ if (ratio > 0.25) return 2+ return 1+}++function tooltipFor(day: BotActivityDay): string {+ const d = new Date(`${day.day}T00:00:00`)+ const label = Number.isNaN(d.getTime()) ? day.day : DATE_FMT.format(d)+ return `${label} · ${day.handledCount} handled · ${day.sentCount} sent`+}++/**+ * BotActivityHeatmap — compact contribution grid for the bot card.+ *+ * Design (Gus /Gus/uiux #155, refining Alli #154): a compact, variable-size+ * grid — NOT a fixed block forced onto every card, NO Less→More legend, and+ * uniform x/y spacing (equal gap both axes). Each cell's tint encodes total+ * activity (handled + sent) for that day; the tooltip splits the two numbers+ * ("Jul 17 · 12 handled · 4 sent"). Placement is the card's job (desktop: the+ * card's empty right side; mobile: below the meta line) — this component only+ * owns the grid and stays placement-agnostic.+ *+ * Data shape is the locked frontend contract (Claudette /Gus/working #663):+ * `dailyActivity: { day, handledCount, sentCount }[]`, oldest→newest, ONLY days+ * with activity (sparse — backend does NOT pad), new bot = []. We build the full+ * 30-day UTC calendar and fill from the sparse rows by day-key, so gaps and empty+ * bots both render as bucket-0 cells and the grid is always exactly 30.+ */+// The card renders two instances — the desktop strip (on the card's right) and+// the mobile ribbon (below the meta line) live in different DOM spots, so each+// picks its layout by `variant` and hides at the other breakpoint. `className`+// lets the card apply that `hidden`/`sm:hidden` visibility wrapper.+export function BotActivityHeatmap({+ days,+ variant,+ className,+}: {+ days: BotActivityDay[]+ variant: "desktop" | "mobile"+ className?: string+}) {+ const cells = useMemo(() => {+ // The backend returns ONLY days with activity (sparse, Claudette #663) — it+ // does NOT pad. So we can't pad by count; we build the full WINDOW_DAYS+ // calendar (today back, in UTC to match the backend's utcDayKey) and fill+ // each slot from the sparse map by day-key. Missing days → bucket 0.+ const byDay = new Map(days.map((d) => [d.day, d]))+ const now = new Date()+ // Oldest→newest: slot i counts back (WINDOW_DAYS-1-i) days from today, so+ // the last cell is today and the first is 29 days ago. utcDayKeyDaysAgo is+ // the SAME shared helper the backend's read + upserts use (Claudette #669) —+ // one function, so the front-end axis and the backend `day` strings can't+ // drift apart on the UTC boundary.+ const axisKeys = Array.from({ length: WINDOW_DAYS }, (_, i) =>+ utcDayKeyDaysAgo(now, WINDOW_DAYS - 1 - i),+ )+ const max = days.reduce((m, d) => Math.max(m, d.handledCount + d.sentCount), 0)+ // Key by calendar day (stable across renders), not grid index.+ return axisKeys.map((key) => {+ const d = byDay.get(key)+ if (!d) return { key, bucket: 0, title: undefined as string | undefined }+ return {+ key,+ bucket: bucketFor(d.handledCount + d.sentCount, max),+ title: tooltipFor(d),+ }+ })+ }, [days])++ const total = useMemo(+ () => days.reduce((s, d) => s + d.handledCount + d.sentCount, 0),+ [days],+ )++ // Cells flow column-by-column (grid-flow-col), so the 30-day sequence reads+ // down each column like a GitHub graph. Always exactly 30 cells into a row+ // count that divides 30 → complete columns, flush bottom edge (#159). Uniform+ // x/y gap both variants (Gus /Gus/uiux #155). Two layouts:+ // • mobile: FULL-WIDTH horizontal ribbon (Gus #164/#165) — 3 rows × 10+ // columns; 10 1fr columns span the card, cells auto-size square to the+ // column width so the ribbon always fills the card, left/right flush.+ // • desktop: a thin fixed-size strip in the card's empty right side+ // (#155/#165) — 4 rows, auto columns, small size-2 cells, w-fit.+ const isMobile = variant === "mobile"+ return (+ <div+ role="img"+ aria-label={`Activity over the last ${WINDOW_DAYS} days: ${total} messages total`}+ className={[+ "grid grid-flow-col gap-[3px]",+ isMobile+ ? "w-full [grid-template-columns:repeat(10,minmax(0,1fr))] [grid-template-rows:repeat(3,auto)]"+ : "w-fit [grid-template-rows:repeat(4,minmax(0,1fr))]",+ className ?? "",+ ].join(" ")}+ >+ {cells.map((c) => (+ <span+ key={c.key}+ title={c.title}+ className={[+ "rounded-[2px]",+ isMobile ? "aspect-square w-full" : "size-2",+ BUCKET_CLASSES[c.bucket],+ ].join(" ")}+ />+ ))}+ </div>+ )+}diff --git a/src/web/src/components/community/bots/bot-list-card.test.ts b/src/web/src/components/community/bots/bot-list-card.test.tsindex 272bfc6d5..95bf41ad6 100644--- a/src/web/src/components/community/bots/bot-list-card.test.ts+++ b/src/web/src/components/community/bots/bot-list-card.test.ts@@ -66,6 +66,8 @@ function bot(over: Partial<BotSummary>): BotSummary {machineId: "mac1",runtime: "claude",modelName: null,+ lastRefreshContextAt: null,+ dailyActivity: [],...over,}}diff --git a/src/web/src/components/community/bots/bot-list.tsx b/src/web/src/components/community/bots/bot-list.tsxindex 50ac31ac8..8795c7bb7 100644--- a/src/web/src/components/community/bots/bot-list.tsx+++ b/src/web/src/components/community/bots/bot-list.tsx@@ -27,7 +27,8 @@ import {} from "@/components/ui/alert-dialog"import { AgentAvatar } from "@/components/avatar"import { ProviderLogo } from "@/components/provider-logo"-import { formatRelativeTime } from "@/components/community/format-time"+import { formatAwakeDuration } from "@/components/community/format-time"+import { BotActivityHeatmap } from "./bot-activity-heatmap"import { useMachines } from "@/hooks/community/use-machines"import { useBots, useDeleteBot, useResetBotSession, type BotSummary } from "@/hooks/community/use-bots"import { useCreateOrGetDm } from "@/hooks/community/mutations"@@ -266,10 +267,12 @@ export function BotList({ onBack }: { onBack?: () => void } = {}) {)}</div>{/* One meta line (Gus #573: no third row). Runtime ·- model · context-lifecycle (my-bots #516/#531):- last refresh (nap/reset — null omits it, new- bot never refreshed) + messages handled this- lifecycle (always shown, defaults 0). */}+ model · awake-duration (my-bots #516; Gus+ #672/#674 relabelled "Refreshed X ago" → the+ awake concept "Awake 17h"). null lastRefresh =+ never awoke → the segment is omitted. The old+ "Handled N msgs" counter is replaced by the+ 30-day activity heatmap (Gus #608). */}<span className="flex items-center gap-1.5 truncate text-xs text-muted-foreground"><ProviderLogo provider={bot.runtime} className="size-3.5 shrink-0" /><span className="truncate">{bot.runtime}</span>@@ -290,14 +293,28 @@ export function BotList({ onBack }: { onBack?: () => void } = {}) {{bot.lastRefreshContextAt && (<><span aria-hidden className="shrink-0">·</span>- <span className="shrink-0">Refreshed {formatRelativeTime(bot.lastRefreshContextAt)}</span>+ <span className="shrink-0">{formatAwakeDuration(bot.lastRefreshContextAt)}</span></>)}- <span aria-hidden className="shrink-0">·</span>- <span className="shrink-0">Handled {bot.handledMessageCount} msgs</span></span>+ {/* Mobile heatmap: full-width ribbon below the meta+ line (Gus /Gus/uiux #164). Desktop places its+ own instance on the card's right (below).+ Visibility is on the wrapper, not the grid+ element, to avoid a display-class conflict. */}+ <div className="mt-1.5 sm:hidden">+ <BotActivityHeatmap days={bot.dailyActivity} variant="mobile" />+ </div></div></div>+ {/* Desktop heatmap: thin strip in the card's empty+ right side, pushed toward the kebab (Gus+ /Gus/uiux #155). ml-auto eats the gap so it hugs+ the right rather than centering in a justify-between+ row. */}+ <div className="ml-auto hidden self-center sm:block">+ <BotActivityHeatmap days={bot.dailyActivity} variant="desktop" />+ </div><DropdownMenu><DropdownMenuTriggerrender={diff --git a/src/web/src/components/community/format-time.ts b/src/web/src/components/community/format-time.tsindex 99f346f46..d82365aa6 100644--- a/src/web/src/components/community/format-time.ts+++ b/src/web/src/components/community/format-time.ts@@ -50,6 +50,23 @@ export function formatRelativeTime(iso: string): string {return DATE_FMT.format(d)}+// How long the agent has been awake since it last refreshed its context (nap /+// session reset), as a magnitude — "Awake 5m" / "Awake 17h" / "Awake 3d" (Gus+// #672/#674: the awake concept reads clearer than "Refreshed X ago"). Unlike+// formatRelativeTime this has no "ago" and no date fallback — it's an elapsed+// duration, so long-awake agents still read as a running count, not a date.+export function formatAwakeDuration(iso: string): string {+ const d = new Date(iso)+ if (Number.isNaN(d.getTime())) return ""+ const mins = Math.floor((Date.now() - d.getTime()) / 60_000)+ if (mins < 1) return "Awake <1m"+ if (mins < 60) return `Awake ${mins}m`+ const hours = Math.floor(mins / 60)+ if (hours < 24) return `Awake ${hours}h`+ const days = Math.floor(hours / 24)+ return `Awake ${days}d`+}+// Get just the date key (YYYY-MM-DD) from an ISO string for groupingexport function dateKey(iso: string | undefined): string {if (!iso) return ""diff --git a/src/web/src/hooks/community/use-bots.ts b/src/web/src/hooks/community/use-bots.tsindex 3ad653d1f..f08e9b51d 100644--- a/src/web/src/hooks/community/use-bots.ts+++ b/src/web/src/hooks/community/use-bots.ts@@ -3,6 +3,7 @@import { useQuery, useMutation, useQueryClient, type UseQueryResult } from "@tanstack/react-query"import { apiFetch, readUploadError } from "@/lib/api/client"import { communityKeys } from "@/lib/query-keys"+import type { BotActivityDay } from "@/components/community/bots/bot-activity-heatmap"export type BotSummary = {id: string@@ -12,14 +13,15 @@ export type BotSummary = {machineId: stringruntime: stringmodelName: string | null- // Context lifecycle (my-bots #516/#531): when the agent last refreshed its- // context (nap OR session reset — both "refresh context"), ISO string, null- // if it never has; and how many messages it's handled in the CURRENT lifecycle- // (reset/nap zero it) — the field is post-gate "handled" count (excludes- // deleted-sender / parse-failed), so it's labeled "Handled N msgs" (Gus #582),- // NOT "received". Rendered as "Refreshed X ago · Handled N msgs".+ // Context lifecycle (my-bots #516): when the agent last refreshed its context+ // (nap OR session reset), ISO string, null if it never has. Rendered as the+ // awake-duration "Awake 17h" (Gus #672/#674 — how long the agent has been+ // awake since that refresh, not "X ago"); null (never refreshed) omits it.lastRefreshContextAt: string | null- handledMessageCount: number+ // Per-day handled/sent activity for the last 30 days (heatmap, Gus #608).+ // Sparse — only days with activity; oldest→newest; [] for a brand-new bot.+ // The heatmap builds the full 30-day calendar and fills from this by day-key.+ dailyActivity: BotActivityDay[]}export type BotsResponse = { bots: BotSummary[] }