@koinzhang/paseo-plugin-activity 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,48 @@ All notable changes to `@koinzhang/paseo-plugin-activity` are documented in this
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.6.0] - 2026-09-22
9
+
10
+ Requires Paseo **>= 0.9.0-beta.2**.
11
+
12
+ ### Added
13
+
14
+ - Workspace Activity Skills and MCP can switch from call-count rankings to newest-first timelines; each call shows its agent title and time, timeline nodes use accent for active agents and gray for archived agents, active-agent rows open their conversations, and both sections share one host-scoped persisted view choice.
15
+ - `usage.recent-skill-calls` RPC returns recent exact / inferred skill calls for a workspace with agent titles.
16
+ - `usage.recent-mcp-calls` RPC returns recent MCP calls for a workspace with agent titles.
17
+ - Global Activity **Agent creations** histogram: a fixed 30-local-day window of daily bars stacked by provider, with per-provider colours and a hover / focus / click card listing every provider's count for that day plus the date.
18
+ - `usage.agent-creations` RPC: daily creation counts with per-provider slices, read from the agent registry alone (no tool-call or message joins).
19
+ - `usage.agent-lifetime` now includes still-active agents (`createdAt → now`, marked `· active` in the KPI) instead of archived agents only.
20
+ - Directory sync lists archived agents (`includeArchived`) so archive metadata (`archivedAt`) is backfilled for agents archived before or between observations; archived entries are registered but never timeline-scanned.
21
+
22
+ ### Changed
23
+
24
+ - Workspace Activity Skills / MCP default to the newest-call timeline; an explicitly saved ranked view is kept.
25
+ - Global KPI reordered to lead with Top / Longest: Agents, Longest agent, Top provider, Top model, Peak weekday, Longest streak; Insights fixed at 8 rows.
26
+ - Agent creations histogram ignores the range chips (always the last 30 local days) and no longer depends on `usage.activity-by-day`.
27
+ - `mcpServerColor` renamed to `entityColor`; the same accent-derived stable colour now covers MCP servers and providers.
28
+ - KPI values and labels shrink to fit their tile instead of wrapping onto a second line (Global / Workspace / Agent share `UsageStats`); line height is fixed so the label baselines stay aligned.
29
+ - Top provider / Top model KPI tiles show the name only (no share), matching the provider-filtered shape; shares stay available from `usage.by-provider`.
30
+ - Agent creations bars round only the top segment's top corners — stacked joints and bar bottoms are square.
31
+ - Agent creations day bars are a single soft provider-colour gradient (tiny middle shares omitted so they cannot notch the bar; remaining colours blend evenly) instead of hard stacked segments; single-provider days stay solid.
32
+ - Global KPI tile 3 and Insights row 3 swapped: `Peak weekday` moved to the KPI (penultimate tile, next to `Longest streak`) and `Workspaces` reads with the volume counts in Insights.
33
+ - Agent creations / MCP rank colours use a soft fixed chart palette (light + dark, inferred from `surface0` luminance) instead of accent-hue hashing; known Paseo providers map to stable slots.
34
+ - Agent creations stacked segments follow window-wide provider rank (largest series at the bottom on every bar), not each day's local count order.
35
+ - Agent creations header no longer shows `N agents · last 30 days` (title is `Agents` only).
36
+ - Chart palette: light / dark colour sets swapped (bright fills on light UI, deep fills on dark UI).
37
+ - Agent creations colours: branded providers keep brand accents; unbranded catalog providers and any future ACP id fall back to the soft chart palette (no theme `accent` for the window leader).
38
+ - Agent creations hover card lists only providers with creations that day (no `: 0` rows); empty days still show the date alone.
39
+ - Agent creations day bars use the same theme-accent intensity steps as the Activity heatmap; provider brand colours remain only on the hover card chips.
40
+ - Activity heatmap rows are weekdays again (row 1 Sunday … row 7 Saturday) and each column is one Sunday-start calendar week, matching GitHub / Codex contribution graphs. The window is still 52 columns × 7 rows ending with the current week; days after today in the last column stay blank.
41
+ - Heatmap `Daily / Weekly / Cumulative` tabs use the month-axis label size (12) instead of their own 13 / 15 scale.
42
+ - Global Activity adds a rolling 168-hour timeline below the Agents histogram: a diverging filled line chart with messages above the time axis and agents below it. The viewport shows 24 hours at a time and starts at the current hour; press and drag the chart to pan through the rest of the week (no scrollbar). Empty hours keep their slot, and hovering or focusing an hour reveals its local range with agents, messages, skill calls, and MCP calls; the window is independent of range chips.
43
+
44
+ ### Fixed
45
+
46
+ - Switching back to Activity no longer re-lays out the heatmap or the 168-hour timeline. A hidden page reports width 0 to `onLayout` (and a hidden app window runs no rendering updates at all, so `onLayout` never fires), which collapsed the grid to nothing until the next measurement. Both sections now ignore zero widths, remember the last real width across remounts, and re-measure synchronously from the DOM node on mount, resize, and `visibilitychange`.
47
+ - Global Activity section rhythm: the heatmap month row no longer reserves a fixed 24px band, the 168-hour timeline's inner gap matches the other chart sections, and the insights / rank-list titles share the same 10 / 12 title gap. Sections now read as one evenly spaced stack (container gap 24 / 32 unchanged; list row density untouched).
48
+ - Longest-agent metric was understated: agents archived before the plugin could observe them had no `archived_at`, so the tile only ever saw live-hook archives.
49
+
8
50
  ## [0.5.0] - 2026-09-20
9
51
 
10
52
  Requires Paseo **>= 0.9.0-beta.2**.
@@ -113,7 +155,8 @@ Last release that supports Paseo **0.8.0**. Later versions require Paseo **>= 0.
113
155
  - Command Center entries: open panels and export a markdown usage report.
114
156
  - Plugin renamed from `tool-usage` to `activity`, migrating the old data directory automatically.
115
157
 
116
- [Unreleased]: https://github.com/koinzhang/paseo-plugins/compare/activity-v0.5.0...HEAD
158
+ [Unreleased]: https://github.com/koinzhang/paseo-plugins/compare/activity-v0.6.0...HEAD
159
+ [0.6.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.6.0
117
160
  [0.5.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.5.0
118
161
  [0.4.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.4.0
119
162
  [0.3.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.3.0
package/README.md CHANGED
@@ -6,7 +6,7 @@ It still answers “how am I using Paseo” (tools, messages, models, habits). W
6
6
 
7
7
  | Scope | Role |
8
8
  |---|---|
9
- | **Global** | Cross-workspace habits: heatmap, provider filter, insights, most-used skills / MCP / models |
9
+ | **Global** | Cross-workspace habits: heatmap, rolling 168-hour activity timeline, provider filter, insights, most-used skills / MCP / models |
10
10
  | **Workspace** | Per-workspace agent fleet: ranked list + display prefs + archive; live status (permission / finished / error / running); open Terminals; shell / file / messages KPIs; times via shared `FormattedTime` |
11
11
  | **Agent** | Current session: dense tool KPIs, Skills / MCP header toggle, SKILL.md reader, composer Activity pill; **Needs attention** pill jumps to other same-workspace finished/permission/error sessions |
12
12
 
@@ -26,7 +26,7 @@ Ingests every agent's Paseo timeline into a local SQLite database. Queries read
26
26
  ## Where it shows up
27
27
 
28
28
  - **Sidebar Activity** — global view by provider (heatmap, KPIs, insights, most used)
29
- - **Explorer → Activity** — workspace agents as a management list (search / sort / group / status / lifecycle / archive), live attention (permission badge, status colors, running spinner; API-owned directory observation + explicit lifecycle/archive fields + 15s reconciliation), open Terminals (list / preview / close), plus workspace KPIs and top skills / MCP (toggle hidden when only one kind has data); usage queries get a best-effort refresh hint when agents leave running
29
+ - **Explorer → Activity** — workspace agents as a management list (search / sort / group / status / lifecycle / archive), live attention (permission badge, status colors, running spinner; API-owned directory observation + explicit lifecycle/archive fields + 15s reconciliation), open Terminals (list / preview / close), plus workspace KPIs and Skills / MCP ranked or newest-call timeline views (with agent titles and one shared persisted view choice); usage queries get a best-effort refresh hint when agents leave running
30
30
  - **Agent workspace panel** — per-agent tool detail (dense KPI including messages / Skills / MCP toggle / SKILL.md); refreshes on timeline turn terminal events
31
31
  - **Composer pills** — Activity: current agent's skill / MCP summary (hidden when empty); **Needs attention**: other same-workspace agents with finished / permission / error (hidden when none; click opens shared list)
32
32
  - **Command Center** — Activity · Workspace Activity · Agent Activity
@@ -3,6 +3,8 @@ import { Pressable, ScrollView, Text, View } from "react-native";
3
3
  import type { ActivityDay } from "../shared/usage.ts";
4
4
  import { activityLevel, buildActivityCalendar, type HeatmapMode } from "../shared/activity.ts";
5
5
  import { useAppLanguage } from "./use-app-language.ts";
6
+ import { useMeasuredWidth } from "./measured-width.ts";
7
+ import { ACTIVITY_MIX_STEPS, mixColor } from "./color-mix.ts";
6
8
  export { computeStreaks, type HeatmapMode } from "../shared/activity.ts";
7
9
 
8
10
  type ThemeColors = {
@@ -12,23 +14,9 @@ type ThemeColors = {
12
14
 
13
15
  type HoveredMonth = { year: number; month: number };
14
16
 
15
- // Derive the activity palette from the active theme.
16
- function mix(base: string, accent: string, amount: number): string {
17
- const parse = (value: string): number[] | null => {
18
- const hex = value.replace("#", "").trim();
19
- const expanded = hex.length === 3 || hex.length === 4
20
- ? hex.split("").map((c) => c + c).join("")
21
- : hex;
22
- // Use first 6 digits only — ignore trailing alpha on 8-digit hex.
23
- const rgb = expanded.slice(0, 6);
24
- if (!/^[0-9a-fA-F]{6}$/.test(rgb)) return null;
25
- return [0, 2, 4].map((i) => parseInt(rgb.slice(i, i + 2), 16));
26
- };
27
- const a = parse(base);
28
- const b = parse(accent);
29
- if (!a || !b) return base;
30
- return `rgb(${a.map((v, i) => Math.round(v + (b[i]! - v) * amount)).join(",")})`;
31
- }
17
+ // Month-axis labels and the mode tabs share one size: both are secondary labels under
18
+ // the section title, so a separate 13 / 15 scale made the tabs outrank the axis.
19
+ const LABEL_FONT_SIZE = 12;
32
20
 
33
21
  function plural(count: number, singular: string, pluralForm = `${singular}s`): string {
34
22
  return `${count.toLocaleString()} ${count === 1 ? singular : pluralForm}`;
@@ -46,7 +34,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
46
34
  modeOptions: ReadonlyArray<{ id: HeatmapMode; label: string }>;
47
35
  }) {
48
36
  const locale = useAppLanguage();
49
- const [width, setWidth] = useState(0);
37
+ const [width, widthRef, onWidthLayout] = useMeasuredWidth("global:heatmap");
50
38
  const [gridTop, setGridTop] = useState(0);
51
39
  const [scrollX, setScrollX] = useState(0);
52
40
  const [tooltipSize, setTooltipSize] = useState({ width: 220, height: 28 });
@@ -67,7 +55,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
67
55
  : 0;
68
56
  const gridWidth = weeks.length > 0 ? weeks.length * (cellSize + gap) - gap : 0;
69
57
  const needsScroll = gridWidth > width + 0.5;
70
- const palette = [colors.surface2, ...[0.22, 0.43, 0.68, 1].map(n => mix(colors.surface2, colors.accent, n))];
58
+ const palette = [colors.surface2, ...ACTIVITY_MIX_STEPS.map(n => mixColor(colors.surface2, colors.accent, n))];
71
59
  const activeKey = hovered ?? selected;
72
60
  const activeIndex = weeks.flat().findIndex(cell => cell.key === activeKey);
73
61
  const active = activeIndex >= 0 ? weeks.flat()[activeIndex] : undefined;
@@ -89,13 +77,17 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
89
77
  const modeLabel = mode === "weekly" ? "Week containing" : mode === "cumulative" ? "Through" : "";
90
78
  const monthFocus = hoveredMonth != null;
91
79
  return (
92
- <View style={{ gap: compact ? 10 : 12 }} onLayout={event => setWidth(event.nativeEvent.layout.width)}>
80
+ <View
81
+ ref={widthRef}
82
+ style={{ gap: compact ? 10 : 12 }}
83
+ onLayout={onWidthLayout}
84
+ >
93
85
  <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
94
86
  <Text style={{ color: colors.foreground, fontSize: compact ? 13 : 15, fontWeight: "500" }}>Activity</Text>
95
87
  <View style={{ flexDirection: "row", gap: compact ? 14 : 20 }}>
96
88
  {modeOptions.map(option => (
97
89
  <Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: mode === option.id }} onPress={() => onModeChange(option.id)} style={{ paddingVertical: 6 }}>
98
- <Text style={{ color: mode === option.id ? colors.foreground : colors.foregroundMuted, fontSize: compact ? 13 : 15 }}>{option.label}</Text>
90
+ <Text style={{ color: mode === option.id ? colors.foreground : colors.foregroundMuted, fontSize: LABEL_FONT_SIZE }}>{option.label}</Text>
99
91
  </Pressable>
100
92
  ))}
101
93
  </View>
@@ -108,7 +100,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
108
100
  onScroll={event => setScrollX(event.nativeEvent.contentOffset.x)}
109
101
  scrollEventThrottle={16}
110
102
  >
111
- <View style={{ width: Math.max(0, axisWidth), paddingBottom: 4 }}>
103
+ <View style={{ width: Math.max(0, axisWidth) }}>
112
104
  <View style={{ flexDirection: "row", gap }}>
113
105
  {weeks.map((week, i) => (
114
106
  <View key={i} style={{ gap }}>
@@ -123,7 +115,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
123
115
  hidden
124
116
  ? base
125
117
  : monthFocus && inMonth
126
- ? mix(base, colors.accent, 0.04)
118
+ ? mixColor(base, colors.accent, 0.04)
127
119
  : base;
128
120
  const opacity = hidden
129
121
  ? 0
@@ -149,7 +141,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
149
141
  </View>
150
142
  ))}
151
143
  </View>
152
- <View style={{ height: 24, marginTop: 10, flexDirection: "row", justifyContent: "space-between" }}>
144
+ <View style={{ marginTop: 10, flexDirection: "row", justifyContent: "space-between" }}>
153
145
  {months.map((item, i) => {
154
146
  const activeMonth =
155
147
  hoveredMonth?.year === item.year && hoveredMonth.month === item.month;
@@ -168,7 +160,7 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
168
160
  numberOfLines={1}
169
161
  style={{
170
162
  color: activeMonth ? colors.foreground : colors.foregroundMuted,
171
- fontSize: 12,
163
+ fontSize: LABEL_FONT_SIZE,
172
164
  }}
173
165
  >
174
166
  {item.label}
@@ -0,0 +1,207 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { Pressable, Text, View } from "react-native";
3
+ import {
4
+ buildAgentCreationBuckets,
5
+ rankCreationProviders,
6
+ stackCreationProviders,
7
+ type CreationBucket,
8
+ type CreationProviderSlice,
9
+ } from "../shared/activity.ts";
10
+ import type { AgentCreationDay } from "../shared/usage.ts";
11
+ import { creationBarColor } from "./color-mix.ts";
12
+ import { chartColorScheme, creationProviderColors } from "./rank-color.ts";
13
+ import { fixedWindowFrom } from "./range.ts";
14
+
15
+ type ThemeColors = {
16
+ accent: string;
17
+ border: string;
18
+ foreground: string;
19
+ foregroundMuted: string;
20
+ surface0: string;
21
+ surface2: string;
22
+ };
23
+
24
+ function bucketDate(key: string): Date {
25
+ const [year, month, day] = key.split("-").map(Number);
26
+ return new Date(year!, month! - 1, day!);
27
+ }
28
+
29
+ /** Locale month + day, e.g. `Sep 6` / `9月6日`. */
30
+ function dayLabel(key: string, locale: string): string {
31
+ return bucketDate(key).toLocaleDateString(locale, { month: "short", day: "numeric" });
32
+ }
33
+
34
+ function agentCountText(count: number): string {
35
+ return `${count} ${count === 1 ? "agent" : "agents"}`;
36
+ }
37
+
38
+ /**
39
+ * Agent creations per local day over a fixed window (051 / 057): the last
40
+ * `windowDays` days ending today, independent of the range chips. Each day is
41
+ * one accent-intensity bar (057); hovering shows a provider breakdown card
42
+ * (nonzero that day only, 056) with brand-coloured chips and the date.
43
+ */
44
+ export function AgentCreations({ days, windowDays, colors, compact, locale }: {
45
+ days: readonly AgentCreationDay[];
46
+ windowDays: number;
47
+ colors: ThemeColors;
48
+ compact?: boolean;
49
+ locale: string;
50
+ }) {
51
+ const from = fixedWindowFrom(windowDays);
52
+ const buckets = useMemo(
53
+ () => buildAgentCreationBuckets(days, { from }),
54
+ [days, from],
55
+ );
56
+ const providers = useMemo(() => rankCreationProviders(buckets), [buckets]);
57
+ const [hovered, setHovered] = useState<string | null>(null);
58
+ const [selected, setSelected] = useState<string | null>(null);
59
+ const [width, setWidth] = useState(0);
60
+ const [tooltipSize, setTooltipSize] = useState({ width: 150, height: 0 });
61
+ useEffect(() => {
62
+ setHovered(null);
63
+ setSelected(null);
64
+ // Only the window start invalidates the selection: refetching the same
65
+ // window must not close a tooltip the pointer is resting on (051).
66
+ }, [from]);
67
+
68
+ const activeKey = hovered ?? selected;
69
+ const total = buckets.reduce((sum, bucket) => sum + bucket.count, 0);
70
+ const max = buckets.reduce((peak, bucket) => Math.max(peak, bucket.count), 0);
71
+ const activeIndex = buckets.findIndex((bucket) => bucket.key === activeKey);
72
+ const active = activeIndex >= 0 ? buckets[activeIndex] : undefined;
73
+ const chartHeight = compact ? 56 : 72;
74
+ const gap = compact ? 2 : 3;
75
+ const slot = buckets.length > 0 ? (width + gap) / buckets.length : 0;
76
+ const anchorX = activeIndex >= 0 ? activeIndex * slot + (slot - gap) / 2 : 0;
77
+ const tooltipLeft = Math.max(0, Math.min(anchorX - tooltipSize.width / 2, width - tooltipSize.width));
78
+ const scheme = chartColorScheme(colors.surface0);
79
+ const colorByProvider = creationProviderColors(
80
+ providers.map((item) => item.provider),
81
+ scheme,
82
+ );
83
+ const tooltipProviders = active
84
+ ? stackCreationProviders(providers, active.providers)
85
+ : [];
86
+ const first = buckets[0];
87
+
88
+ return (
89
+ <View style={{ gap: compact ? 10 : 12 }}>
90
+ <Text style={{ color: colors.foreground, fontSize: compact ? 13 : 15, fontWeight: "500" }}>
91
+ Agents
92
+ </Text>
93
+
94
+ {total === 0 ? (
95
+ <Text style={{ color: colors.foregroundMuted, fontSize: 14 }}>
96
+ No agents created in the last {windowDays} days
97
+ </Text>
98
+ ) : (
99
+ <View style={{ gap: 6 }}>
100
+ <View style={{ position: "relative" }} onLayout={(event) => setWidth(event.nativeEvent.layout.width)}>
101
+ <View style={{ flexDirection: "row", alignItems: "flex-end", gap, height: chartHeight }}>
102
+ {buckets.map((bucket) => (
103
+ <Pressable
104
+ key={bucket.key}
105
+ accessibilityRole="button"
106
+ accessibilityLabel={`${dayLabel(bucket.key, locale)}: ${agentCountText(bucket.count)}${providerBreakdown(bucket, providers)}`}
107
+ accessibilityState={{ selected: activeKey === bucket.key }}
108
+ onHoverIn={() => setHovered(bucket.key)}
109
+ onHoverOut={() => setHovered(null)}
110
+ onFocus={() => setHovered(bucket.key)}
111
+ onBlur={() => setHovered(null)}
112
+ onPress={() => setSelected((prev) => (prev === bucket.key ? null : bucket.key))}
113
+ style={{
114
+ flex: 1,
115
+ minWidth: 3,
116
+ height: chartHeight,
117
+ justifyContent: "flex-end",
118
+ }}
119
+ >
120
+ {bucket.providers.length === 0 ? (
121
+ <View style={{ height: 2, backgroundColor: colors.surface2 }} />
122
+ ) : (
123
+ <View
124
+ style={{
125
+ height: max > 0 ? Math.max(2, Math.round((bucket.count / max) * chartHeight)) : 2,
126
+ backgroundColor: creationBarColor(
127
+ bucket.count,
128
+ max,
129
+ colors.surface2,
130
+ colors.accent,
131
+ ),
132
+ borderTopLeftRadius: 3,
133
+ borderTopRightRadius: 3,
134
+ }}
135
+ />
136
+ )}
137
+ </Pressable>
138
+ ))}
139
+ </View>
140
+ {active && width > 0 ? (
141
+ <View
142
+ pointerEvents="none"
143
+ onLayout={(event) =>
144
+ setTooltipSize({
145
+ width: event.nativeEvent.layout.width,
146
+ height: event.nativeEvent.layout.height,
147
+ })
148
+ }
149
+ style={{
150
+ position: "absolute",
151
+ left: tooltipLeft,
152
+ bottom: chartHeight + 6,
153
+ zIndex: 10,
154
+ paddingHorizontal: 12,
155
+ paddingVertical: 8,
156
+ borderRadius: 10,
157
+ backgroundColor: colors.surface2,
158
+ borderWidth: 1,
159
+ borderColor: colors.border,
160
+ gap: 4,
161
+ }}
162
+ >
163
+ {tooltipProviders.map((item) => (
164
+ <View key={item.provider} style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
165
+ <View
166
+ style={{
167
+ width: 10,
168
+ height: 10,
169
+ borderRadius: 3,
170
+ backgroundColor: colorByProvider.get(item.provider) ?? colors.accent,
171
+ }}
172
+ />
173
+ <Text style={{ color: colors.foreground, fontSize: 13 }}>
174
+ {item.label}: {item.count}
175
+ </Text>
176
+ </View>
177
+ ))}
178
+ <Text
179
+ accessibilityLiveRegion="polite"
180
+ style={{ color: colors.foregroundMuted, fontSize: 12, marginTop: 2 }}
181
+ >
182
+ {dayLabel(active.key, locale)}
183
+ </Text>
184
+ </View>
185
+ ) : null}
186
+ </View>
187
+ <View style={{ flexDirection: "row", justifyContent: "space-between" }}>
188
+ <Text style={{ color: colors.foregroundMuted, fontSize: 12 }}>
189
+ {first ? dayLabel(first.key, locale) : ""}
190
+ </Text>
191
+ <Text style={{ color: colors.foregroundMuted, fontSize: 12 }}>Today</Text>
192
+ </View>
193
+ </View>
194
+ )}
195
+ </View>
196
+ );
197
+ }
198
+
199
+ function providerBreakdown(
200
+ bucket: CreationBucket,
201
+ ranked: readonly CreationProviderSlice[],
202
+ ): string {
203
+ const stacked = stackCreationProviders(ranked, bucket.providers);
204
+ if (stacked.length === 0) return "";
205
+ // Top→bottom to match the painted stack.
206
+ return ` — ${stacked.map((slice) => `${slice.label} ${slice.count}`).join(", ")}`;
207
+ }
@@ -0,0 +1,27 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { creationBarColor, mixColor } from "./color-mix.ts";
4
+
5
+ describe("creationBarColor (057)", () => {
6
+ const surface = "#1a1a1c";
7
+ const accent = "#6d49b5";
8
+
9
+ it("returns surface for empty or zero max", () => {
10
+ assert.equal(creationBarColor(0, 10, surface, accent), surface);
11
+ assert.equal(creationBarColor(5, 0, surface, accent), surface);
12
+ });
13
+
14
+ it("uses a deeper accent mix for the window peak than a small day", () => {
15
+ const peak = creationBarColor(20, 20, surface, accent);
16
+ const low = creationBarColor(1, 20, surface, accent);
17
+ assert.equal(peak, mixColor(surface, accent, 1));
18
+ assert.notEqual(peak, low);
19
+ assert.notEqual(low, surface);
20
+ });
21
+
22
+ it("stays in the accent family (no provider brand)", () => {
23
+ const mid = creationBarColor(5, 20, surface, accent);
24
+ assert.match(mid, /^rgb\(/);
25
+ assert.ok(!mid.toLowerCase().includes("d94816"));
26
+ });
27
+ });
@@ -0,0 +1,38 @@
1
+ import { activityLevel } from "../shared/activity.ts";
2
+
3
+ /** Derive a palette colour by mixing `base` toward `accent` (hex themes only). */
4
+ export function mixColor(base: string, accent: string, amount: number): string {
5
+ const parse = (value: string): number[] | null => {
6
+ const hex = value.replace("#", "").trim();
7
+ const expanded = hex.length === 3 || hex.length === 4
8
+ ? hex.split("").map((c) => c + c).join("")
9
+ : hex;
10
+ // Use first 6 digits only — ignore trailing alpha on 8-digit hex.
11
+ const rgb = expanded.slice(0, 6);
12
+ if (!/^[0-9a-fA-F]{6}$/.test(rgb)) return null;
13
+ return [0, 2, 4].map((i) => parseInt(rgb.slice(i, i + 2), 16));
14
+ };
15
+ const a = parse(base);
16
+ const b = parse(accent);
17
+ if (!a || !b) return base;
18
+ return `rgb(${a.map((v, i) => Math.round(v + (b[i]! - v) * amount)).join(",")})`;
19
+ }
20
+
21
+ /** Intensity steps for activity visuals, indexed by `activityLevel` - 1. */
22
+ export const ACTIVITY_MIX_STEPS = [0.22, 0.43, 0.68, 1] as const;
23
+
24
+ /**
25
+ * Accent intensity fill for a creations day bar (057) — same steps as the
26
+ * Activity heatmap so Global charts share one hue family.
27
+ */
28
+ export function creationBarColor(
29
+ count: number,
30
+ max: number,
31
+ surface2: string,
32
+ accent: string,
33
+ ): string {
34
+ const level = activityLevel(count, max);
35
+ if (level <= 0) return surface2;
36
+ const amount = ACTIVITY_MIX_STEPS[level - 1] ?? 1;
37
+ return mixColor(surface2, accent, amount);
38
+ }
@@ -0,0 +1,41 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { fitFontSize } from "./fit-text.ts";
4
+
5
+ const options = { base: 18, min: 12 };
6
+ const measured = (size: number, width: number) => ({ size, width });
7
+
8
+ describe("fitFontSize (051)", () => {
9
+ it("keeps the base size when the text fits", () => {
10
+ assert.equal(fitFontSize(measured(18, 80), 100, options), 18);
11
+ assert.equal(fitFontSize(measured(18, 100), 100, options), 18);
12
+ assert.equal(fitFontSize(measured(12, 60), 120, options), 18);
13
+ });
14
+
15
+ it("scales the size down by the measured overflow", () => {
16
+ // 138px at 18px in a 120px tile → 15.5px (1% headroom).
17
+ assert.equal(fitFontSize(measured(18, 138), 120, options), 15.5);
18
+ });
19
+
20
+ it("is independent of the size the text is currently rendered at", () => {
21
+ // The same physical width measured at 15.5px resolves to the same size.
22
+ const shrunk = fitFontSize(measured(15.5, 138 * (15.5 / 18)), 120, options);
23
+ assert.equal(shrunk, 15.5);
24
+ });
25
+
26
+ it("grows back to base once the tile widens", () => {
27
+ assert.equal(fitFontSize(measured(15.5, 118.8), 160, options), 18);
28
+ });
29
+
30
+ it("clamps to min and ignores unusable measurements", () => {
31
+ assert.equal(fitFontSize(measured(18, 400), 60, options), 12);
32
+ assert.equal(fitFontSize(measured(18, 0), 120, options), 18);
33
+ assert.equal(fitFontSize(measured(0, 120), 120, options), 18);
34
+ assert.equal(fitFontSize(measured(18, 138), 0, options), 18);
35
+ });
36
+
37
+ it("derives a min floor from the base size when none is given", () => {
38
+ assert.equal(fitFontSize(measured(18, 400), 40, { base: 18 }), 12);
39
+ assert.equal(fitFontSize(measured(12, 400), 40, { base: 12 }), 8);
40
+ });
41
+ });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Single-line text sizing (051).
3
+ *
4
+ * KPI tiles are ~130px wide at 18px values ("Cursor · 61%"), so values used to
5
+ * wrap onto two lines and push the labels out of line. The text is measured
6
+ * once at a known size, and the size that fits `available` is derived from that
7
+ * measurement alone: width scales linearly with font size, so the target does
8
+ * not depend on the size currently rendered — measure, fit, converge, and grow
9
+ * back to `base` when the tile widens.
10
+ */
11
+
12
+ export type TextMeasurement = {
13
+ /** Font size the text was measured at. */
14
+ size: number;
15
+ /** Rendered width of the text at `size`. */
16
+ width: number;
17
+ };
18
+
19
+ /** Font size that fits `available`, clamped to `[min, base]`. */
20
+ export function fitFontSize(
21
+ measured: TextMeasurement,
22
+ available: number,
23
+ options: { base: number; min?: number },
24
+ ): number {
25
+ const { base } = options;
26
+ const min = options.min ?? Math.max(8, base - 6);
27
+ if (!(measured.width > 0) || !(measured.size > 0) || !(available > 0)) return base;
28
+ const exact = (measured.size * available) / measured.width;
29
+ if (exact >= base) return base;
30
+ // 1% headroom on the shrink so sub-pixel rounding cannot trip the ellipsis.
31
+ const target = Math.min(base, Math.max(min, Math.round(exact * 0.99 * 10) / 10));
32
+ return target;
33
+ }