@koinzhang/paseo-plugin-activity 0.5.0 → 0.7.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/README.md +15 -8
  3. package/client/activity-heatmap.tsx +126 -93
  4. package/client/agent-creations.tsx +216 -0
  5. package/client/attention-pill.tsx +16 -5
  6. package/client/attention-popover.tsx +19 -23
  7. package/client/color-mix.test.ts +27 -0
  8. package/client/color-mix.ts +38 -0
  9. package/client/design-tokens.test.ts +39 -0
  10. package/client/design-tokens.ts +168 -0
  11. package/client/fit-text.test.ts +41 -0
  12. package/client/fit-text.ts +33 -0
  13. package/client/formatted-time.tsx +4 -4
  14. package/client/global-surface.tsx +316 -275
  15. package/client/header-button.ts +136 -0
  16. package/client/hourly-activity-timeline.tsx +425 -0
  17. package/client/measured-width.ts +72 -0
  18. package/client/panel-visibility.test.ts +25 -0
  19. package/client/panel-visibility.ts +45 -0
  20. package/client/panel.tsx +83 -108
  21. package/client/provider-dropdown.tsx +131 -0
  22. package/client/provider-filter.test.ts +17 -13
  23. package/client/provider-filter.ts +5 -7
  24. package/client/range.test.ts +44 -0
  25. package/client/range.ts +14 -0
  26. package/client/rank-color.test.ts +108 -14
  27. package/client/rank-color.ts +261 -48
  28. package/client/ranking-bars.tsx +291 -0
  29. package/client/ui.tsx +339 -0
  30. package/client/usage-popover.tsx +62 -134
  31. package/client/usage-stats.tsx +137 -8
  32. package/client/use-agent-turn-end.ts +2 -1
  33. package/client/use-app-language.ts +17 -0
  34. package/client/web.ts +73 -18
  35. package/client/workspace/agent-row.tsx +18 -25
  36. package/client/workspace/agents-section.tsx +23 -20
  37. package/client/workspace/constants.ts +6 -6
  38. package/client/workspace/display-menu.tsx +5 -4
  39. package/client/workspace/filters.test.ts +1 -1
  40. package/client/workspace/filters.ts +4 -2
  41. package/client/workspace/panel.tsx +176 -104
  42. package/client/workspace/rank-section.tsx +157 -44
  43. package/client/workspace/terminals-section.tsx +13 -9
  44. package/index.client.tsx +40 -20
  45. package/index.server.ts +63 -31
  46. package/package.json +2 -2
  47. package/paseo-plugin.json +2 -1
  48. package/server/agents.ts +20 -2
  49. package/server/background-sync.test.ts +43 -0
  50. package/server/background-sync.ts +43 -4
  51. package/server/handlers-query.test.ts +252 -1
  52. package/server/handlers.ts +174 -13
  53. package/server/ingest.test.ts +8 -0
  54. package/server/messages.test.ts +96 -1
  55. package/server/prompt-dedupe.ts +52 -0
  56. package/server/rpc-cache.test.ts +74 -0
  57. package/server/rpc-cache.ts +48 -0
  58. package/server/store.test.ts +122 -0
  59. package/server/store.ts +313 -19
  60. package/server/ttl-cache.ts +3 -0
  61. package/shared/activity.test.ts +159 -6
  62. package/shared/activity.ts +140 -5
  63. package/shared/classify.test.ts +1 -0
  64. package/shared/classify.ts +4 -1
  65. package/shared/explorer-agent-display.test.ts +61 -0
  66. package/shared/explorer-agent-display.ts +21 -2
  67. package/shared/format.test.ts +28 -3
  68. package/shared/format.ts +25 -2
  69. package/shared/i18n.test.ts +34 -0
  70. package/shared/i18n.ts +363 -0
  71. package/shared/insights.test.ts +162 -80
  72. package/shared/insights.ts +136 -61
  73. package/shared/usage.test.ts +330 -0
  74. package/shared/usage.ts +471 -0
@@ -0,0 +1,216 @@
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { Animated, Easing, Pressable, Text, View } from "react-native";
3
+ import {
4
+ buildAgentCreationBuckets,
5
+ buildDailyMetricBuckets,
6
+ rankCreationProviders,
7
+ stackCreationProviders,
8
+ type CreationBucket,
9
+ type ActivityMetric,
10
+ type CreationProviderSlice,
11
+ } from "../shared/activity.ts";
12
+ import type { ActivityDay, AgentCreationDay } from "../shared/usage.ts";
13
+ import { creationBarColor } from "./color-mix.ts";
14
+ import { chartColorScheme, creationProviderColors } from "./rank-color.ts";
15
+ import { fixedWindowFrom } from "./range.ts";
16
+ import { CHART_MOTION, RADIUS, TEXT, sectionTitle, titleGap } from "./design-tokens.ts";
17
+ import { messagesFor } from "../shared/i18n.ts";
18
+ import { ChartTooltip, InlineEmpty, MetricStepper } from "./ui.tsx";
19
+
20
+ const EMPTY_BAR_HEIGHT = 2;
21
+
22
+ type ThemeColors = {
23
+ accent: string;
24
+ border: string;
25
+ foreground: string;
26
+ foregroundMuted: string;
27
+ surface0: string;
28
+ surface2: string;
29
+ };
30
+
31
+ function bucketDate(key: string): Date {
32
+ const [year, month, day] = key.split("-").map(Number);
33
+ return new Date(year!, month! - 1, day!);
34
+ }
35
+
36
+ /** Locale month + day, e.g. `Sep 6` / `9月6日`. */
37
+ function dayLabel(key: string, locale: string): string {
38
+ return bucketDate(key).toLocaleDateString(locale, { month: "short", day: "numeric" });
39
+ }
40
+
41
+ /**
42
+ * Daily bars over a fixed window (051 / 057): the last `windowDays` days
43
+ * ending today. Each day is one accent-intensity bar (057). The header switch
44
+ * (070) picks the metric; Sessions hovers show a provider breakdown card
45
+ * (nonzero that day only, 056), other metrics come from `activityDays` and
46
+ * show the day total only.
47
+ */
48
+ export function AgentCreations({ days, activityDays, windowDays, colors, compact, locale }: {
49
+ days: readonly AgentCreationDay[];
50
+ activityDays: readonly ActivityDay[];
51
+ windowDays: number;
52
+ colors: ThemeColors;
53
+ compact?: boolean;
54
+ locale: string;
55
+ }) {
56
+ const [metric, setMetric] = useState<ActivityMetric>("sessions");
57
+ const from = fixedWindowFrom(windowDays);
58
+ const buckets = useMemo(
59
+ () =>
60
+ metric === "sessions"
61
+ ? buildAgentCreationBuckets(days, { from })
62
+ : buildDailyMetricBuckets(activityDays, metric, { from }),
63
+ [days, activityDays, metric, from],
64
+ );
65
+ const providers = useMemo(() => rankCreationProviders(buckets), [buckets]);
66
+ const [hovered, setHovered] = useState<string | null>(null);
67
+ const [selected, setSelected] = useState<string | null>(null);
68
+ const [width, setWidth] = useState(0);
69
+ useEffect(() => {
70
+ setHovered(null);
71
+ setSelected(null);
72
+ // Only the window start invalidates the selection: refetching the same
73
+ // window must not close a tooltip the pointer is resting on (051).
74
+ }, [from, metric]);
75
+
76
+ const activeKey = hovered ?? selected;
77
+ const total = buckets.reduce((sum, bucket) => sum + bucket.count, 0);
78
+ const max = buckets.reduce((peak, bucket) => Math.max(peak, bucket.count), 0);
79
+ const activeIndex = buckets.findIndex((bucket) => bucket.key === activeKey);
80
+ const active = activeIndex >= 0 ? buckets[activeIndex] : undefined;
81
+ const chartHeight = compact ? 56 : 72;
82
+ const gap = compact ? 2 : 3;
83
+ const slot = buckets.length > 0 ? (width + gap) / buckets.length : 0;
84
+ const anchorX = activeIndex >= 0 ? activeIndex * slot + (slot - gap) / 2 : 0;
85
+ const scheme = chartColorScheme(colors.surface0);
86
+ const colorByProvider = creationProviderColors(
87
+ providers.map((item) => item.provider),
88
+ scheme,
89
+ );
90
+ const tooltipProviders = active
91
+ ? stackCreationProviders(providers, active.providers)
92
+ : [];
93
+ const first = buckets[0];
94
+ const m = messagesFor(locale);
95
+ const unit = (count: number) =>
96
+ metric === "sessions"
97
+ ? m.units.sessions(count)
98
+ : metric === "prompts"
99
+ ? m.units.prompts(count)
100
+ : metric === "skills"
101
+ ? m.units.skills(count)
102
+ : m.units.mcp(count);
103
+
104
+ return (
105
+ <View style={{ gap: titleGap(compact) }}>
106
+ <View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
107
+ <Text style={{ ...sectionTitle(compact), color: colors.foreground }}>
108
+ {m.creations.title}
109
+ </Text>
110
+ <MetricStepper value={metric} onChange={setMetric} colors={colors} />
111
+ </View>
112
+
113
+ {total === 0 ? (
114
+ <InlineEmpty text={m.creations.empty(windowDays)} color={colors.foregroundMuted} />
115
+ ) : (
116
+ <View style={{ gap: 6 }}>
117
+ <View style={{ position: "relative" }} onLayout={(event) => setWidth(event.nativeEvent.layout.width)}>
118
+ <View style={{ flexDirection: "row", alignItems: "flex-end", gap, height: chartHeight }}>
119
+ {buckets.map((bucket) => (
120
+ <Pressable
121
+ key={bucket.key}
122
+ accessibilityRole="button"
123
+ accessibilityLabel={`${dayLabel(bucket.key, locale)}: ${unit(bucket.count)}${providerBreakdown(bucket, providers)}`}
124
+ accessibilityState={{ selected: activeKey === bucket.key }}
125
+ onHoverIn={() => setHovered(bucket.key)}
126
+ onHoverOut={() => setHovered(null)}
127
+ onFocus={() => setHovered(bucket.key)}
128
+ onBlur={() => setHovered(null)}
129
+ onPress={() => setSelected((prev) => (prev === bucket.key ? null : bucket.key))}
130
+ style={{
131
+ flex: 1,
132
+ minWidth: 3,
133
+ height: chartHeight,
134
+ justifyContent: "flex-end",
135
+ }}
136
+ >
137
+ <DayBar
138
+ height={
139
+ bucket.count > 0 && max > 0
140
+ ? Math.max(EMPTY_BAR_HEIGHT, Math.round((bucket.count / max) * chartHeight))
141
+ : EMPTY_BAR_HEIGHT
142
+ }
143
+ color={
144
+ bucket.count === 0
145
+ ? colors.surface2
146
+ : creationBarColor(bucket.count, max, colors.surface2, colors.accent)
147
+ }
148
+ rounded={bucket.count > 0}
149
+ />
150
+ </Pressable>
151
+ ))}
152
+ </View>
153
+ {active && width > 0 ? (
154
+ <ChartTooltip
155
+ anchorX={anchorX}
156
+ anchorY={0}
157
+ containerWidth={width}
158
+ clampTop={false}
159
+ title={`${dayLabel(active.key, locale)} · ${unit(active.count)}`}
160
+ rows={tooltipProviders.map((item) => ({
161
+ label: item.label,
162
+ value: item.count.toLocaleString(locale),
163
+ color: colorByProvider.get(item.provider) ?? colors.accent,
164
+ }))}
165
+ colors={colors}
166
+ />
167
+ ) : null}
168
+ </View>
169
+ <View style={{ flexDirection: "row", justifyContent: "space-between" }}>
170
+ <Text style={{ ...TEXT.meta, color: colors.foregroundMuted }}>
171
+ {first ? dayLabel(first.key, locale) : ""}
172
+ </Text>
173
+ <Text style={{ ...TEXT.meta, color: colors.foregroundMuted }}>{m.common.today}</Text>
174
+ </View>
175
+ </View>
176
+ )}
177
+ </View>
178
+ );
179
+ }
180
+
181
+ /** Day column that grows from 0 on mount and animates between heights on change. */
182
+ function DayBar({ height, color, rounded }: { height: number; color: string; rounded: boolean }) {
183
+ const progress = useRef(new Animated.Value(0)).current;
184
+
185
+ useEffect(() => {
186
+ const animation = Animated.timing(progress, {
187
+ toValue: height,
188
+ duration: CHART_MOTION.grow,
189
+ easing: Easing.out(Easing.cubic),
190
+ useNativeDriver: false,
191
+ });
192
+ animation.start();
193
+ return () => animation.stop();
194
+ }, [height, progress]);
195
+
196
+ return (
197
+ <Animated.View
198
+ style={{
199
+ height: progress,
200
+ backgroundColor: color,
201
+ borderTopLeftRadius: rounded ? RADIUS.swatch : 0,
202
+ borderTopRightRadius: rounded ? RADIUS.swatch : 0,
203
+ }}
204
+ />
205
+ );
206
+ }
207
+
208
+ function providerBreakdown(
209
+ bucket: CreationBucket,
210
+ ranked: readonly CreationProviderSlice[],
211
+ ): string {
212
+ const stacked = stackCreationProviders(ranked, bucket.providers);
213
+ if (stacked.length === 0) return "";
214
+ // Top→bottom to match the painted stack.
215
+ return ` — ${stacked.map((slice) => `${slice.label} ${slice.count}`).join(", ")}`;
216
+ }
@@ -12,6 +12,8 @@ import {
12
12
  type AttentionAgentItem,
13
13
  } from "./attention-agents.ts";
14
14
  import { AttentionPopover } from "./attention-popover.tsx";
15
+ import { messagesFor } from "../shared/i18n.ts";
16
+ import { currentAppLanguage, watchAppLanguage } from "./use-app-language.ts";
15
17
  import {
16
18
  clearAttentionStatuses,
17
19
  getAttentionStatuses,
@@ -22,7 +24,7 @@ import { watchAgentDirectory } from "./agent-directory.ts";
22
24
  import { agentStatusInfo } from "./workspace/list-host-agents.ts";
23
25
  import type { AgentStatusInfo } from "./workspace/constants.ts";
24
26
 
25
- const TITLE = "Needs attention";
27
+ const attentionTitle = () => messagesFor(currentAppLanguage()).attention.title;
26
28
  const PILL_ID = "attention";
27
29
 
28
30
  type PillEntry = {
@@ -56,7 +58,7 @@ export function contributeAttentionPills(client: PluginClientContext): () => voi
56
58
  entry.signature = signature;
57
59
 
58
60
  if (items.length === 0) {
59
- pill.update({ visible: false, label: TITLE, disabled: false });
61
+ pill.update({ visible: false, label: attentionTitle(), disabled: false });
60
62
  return;
61
63
  }
62
64
 
@@ -64,7 +66,7 @@ export function contributeAttentionPills(client: PluginClientContext): () => voi
64
66
  pill.update({
65
67
  visible: true,
66
68
  label: String(items.length),
67
- title: TITLE,
69
+ title: attentionTitle(),
68
70
  disabled: false,
69
71
  behavior: {
70
72
  kind: "popover",
@@ -115,8 +117,8 @@ export function contributeAttentionPills(client: PluginClientContext): () => voi
115
117
  workspaceId,
116
118
  agentId,
117
119
  button: {
118
- title: TITLE,
119
- label: TITLE,
120
+ title: attentionTitle(),
121
+ label: attentionTitle(),
120
122
  visible: false,
121
123
  icon: createPillIcon(agentId),
122
124
  behavior: {
@@ -154,7 +156,16 @@ export function contributeAttentionPills(client: PluginClientContext): () => voi
154
156
  for (const [workspaceId, statuses] of workspaces) applyWorkspace(workspaceId, statuses);
155
157
  });
156
158
 
159
+ const stopLanguage = watchAppLanguage(() => {
160
+ for (const [agentId, entry] of pills) {
161
+ entry.signature = "";
162
+ const cached = getAttentionStatuses(entry.workspaceId);
163
+ if (cached) applyPill(agentId, entry, cached);
164
+ }
165
+ });
166
+
157
167
  return () => {
168
+ stopLanguage();
158
169
  stopDirectory();
159
170
  pills.forEach((entry) => entry.registration?.remove());
160
171
  pills.clear();
@@ -3,7 +3,7 @@ import {
3
3
  useAgent,
4
4
  } from "@getpaseo/plugin/client";
5
5
  import { useEffect, useMemo, type ReactNode } from "react";
6
- import { Text, View, type TextStyle, type ViewStyle } from "react-native";
6
+ import { View, type TextStyle, type ViewStyle } from "react-native";
7
7
  import {
8
8
  filterAttentionAgents,
9
9
  type AttentionAgentItem,
@@ -12,6 +12,9 @@ import { openAttentionAgent } from "./open-agent.ts";
12
12
  import { useLatestUserMessagePreview } from "./use-latest-user-message.ts";
13
13
  import { useAttentionStatuses } from "./attention-status-store.ts";
14
14
  import { AgentRow, type AgentRowStyles } from "./workspace/agent-row.tsx";
15
+ import { CONTROL, ICON_SIZE, ROW_PADDING, TEXT, pillRadius, popoverFrame } from "./design-tokens.ts";
16
+ import { useMessages } from "./use-app-language.ts";
17
+ import { InlineEmpty } from "./ui.tsx";
15
18
 
16
19
  function AttentionRow({
17
20
  item,
@@ -56,12 +59,9 @@ function AttentionRow({
56
59
 
57
60
  /** Popover body: other agents in this workspace that need attention. */
58
61
  export function AttentionPopover(props: PluginButtonContentProps) {
62
+ const m = useMessages();
59
63
  if (props.context !== "agent") {
60
- return (
61
- <Text style={{ color: props.theme.colors.foregroundMuted }}>
62
- Attention is only available for an agent
63
- </Text>
64
- );
64
+ return <InlineEmpty text={m.attention.agentOnly} color={props.theme.colors.foregroundMuted} />;
65
65
  }
66
66
  return <AttentionPopoverAgent {...props} context="agent" />;
67
67
  }
@@ -69,7 +69,8 @@ export function AttentionPopover(props: PluginButtonContentProps) {
69
69
  function AttentionPopoverAgent(
70
70
  props: PluginButtonContentProps & { context: "agent" },
71
71
  ) {
72
- const { theme, workspaceId, agentId, close } = props;
72
+ const { theme, layout, workspaceId, agentId, close } = props;
73
+ const m = useMessages();
73
74
  const statuses = useAttentionStatuses(workspaceId);
74
75
  const items = useMemo(
75
76
  () => filterAttentionAgents(statuses, agentId),
@@ -81,18 +82,17 @@ function AttentionPopoverAgent(
81
82
  flexDirection: "row",
82
83
  alignItems: "center",
83
84
  gap: 10,
84
- paddingVertical: 6,
85
+ paddingVertical: ROW_PADDING.dense,
85
86
  };
86
87
  const title: TextStyle = {
88
+ ...TEXT.rowTitle,
87
89
  color: theme.colors.foreground,
88
- fontSize: 14,
89
- fontWeight: "500",
90
90
  };
91
91
  return {
92
92
  agentListRow: row,
93
93
  agentIconWrap: {
94
- width: 18,
95
- height: 18,
94
+ width: ICON_SIZE.leading,
95
+ height: ICON_SIZE.leading,
96
96
  alignItems: "center",
97
97
  justifyContent: "center",
98
98
  } satisfies ViewStyle,
@@ -103,47 +103,43 @@ function AttentionPopoverAgent(
103
103
  listLink: title,
104
104
  listTitle: title,
105
105
  listMeta: {
106
+ ...TEXT.meta,
106
107
  color: theme.colors.foregroundMuted,
107
- fontSize: 12,
108
108
  } satisfies TextStyle,
109
109
  titleAction: { width: 0, height: 0 } satisfies ViewStyle,
110
110
  permissionBadge: {
111
111
  flexDirection: "row",
112
112
  alignItems: "center",
113
113
  gap: 3,
114
- height: 18,
114
+ height: CONTROL.pillBadgeHeight,
115
115
  paddingHorizontal: 5,
116
- borderRadius: 9,
116
+ borderRadius: pillRadius(CONTROL.pillBadgeHeight),
117
117
  borderWidth: 1,
118
118
  borderColor: theme.colors.border,
119
119
  backgroundColor: theme.colors.surface1,
120
120
  flexShrink: 0,
121
121
  } satisfies ViewStyle,
122
122
  permissionBadgeText: {
123
+ ...TEXT.pillBadge,
123
124
  color: theme.colors.statusWarning,
124
- fontSize: 11,
125
- fontWeight: "600",
126
- fontVariant: ["tabular-nums"],
127
125
  } satisfies TextStyle,
128
126
  } satisfies AgentRowStyles;
129
127
  }, [theme]);
130
128
 
131
129
  if (!statuses) {
132
130
  return (
133
- <Text style={{ color: theme.colors.foregroundMuted }}>Loading…</Text>
131
+ <InlineEmpty text={m.common.loading} color={theme.colors.foregroundMuted} />
134
132
  );
135
133
  }
136
134
 
137
135
  if (items.length === 0) {
138
136
  return (
139
- <Text style={{ color: theme.colors.foregroundMuted }}>
140
- No other agents need attention
141
- </Text>
137
+ <InlineEmpty text={m.attention.empty} color={theme.colors.foregroundMuted} />
142
138
  );
143
139
  }
144
140
 
145
141
  return (
146
- <View style={{ gap: 2, minWidth: 240 }}>
142
+ <View style={{ gap: 2, ...popoverFrame(layout.compact) }}>
147
143
  {items.map((item) => (
148
144
  <AttentionRow
149
145
  key={item.agentId}
@@ -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,39 @@
1
+ import assert from "node:assert/strict";
2
+ import { readdirSync, readFileSync } from "node:fs";
3
+ import { join, relative } from "node:path";
4
+ import { test } from "node:test";
5
+
6
+ const CLIENT_DIR = new URL(".", import.meta.url).pathname;
7
+
8
+ const RULES: ReadonlyArray<{ name: string; pattern: RegExp }> = [
9
+ { name: "fontSize literal", pattern: /fontSize:\s*[0-9]/ },
10
+ { name: "fontWeight literal", pattern: /fontWeight:\s*["'][0-9a-z]+["']/ },
11
+ { name: "border radius literal", pattern: /[bB]order\w*Radius:\s*[0-9]/ },
12
+ { name: "Icon size literal", pattern: /<Icon\b[^>]*\bsize=\{[0-9]/ },
13
+ { name: "multi-line Icon size literal", pattern: /^\s*size=\{[0-9]+\}\s*$/ },
14
+ { name: "hitSlop literal", pattern: /hitSlop=\{[0-9]/ },
15
+ ];
16
+
17
+ function tsxFiles(dir: string): string[] {
18
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
19
+ const path = join(dir, entry.name);
20
+ if (entry.isDirectory()) return tsxFiles(path);
21
+ return entry.name.endsWith(".tsx") ? [path] : [];
22
+ });
23
+ }
24
+
25
+ test("client UI uses design tokens instead of raw type / radius / icon literals (065)", () => {
26
+ const violations: string[] = [];
27
+ for (const file of tsxFiles(CLIENT_DIR)) {
28
+ readFileSync(file, "utf8")
29
+ .split("\n")
30
+ .forEach((line, index) => {
31
+ for (const rule of RULES) {
32
+ if (rule.pattern.test(line)) {
33
+ violations.push(`${relative(CLIENT_DIR, file)}:${index + 1} ${rule.name}: ${line.trim()}`);
34
+ }
35
+ }
36
+ });
37
+ }
38
+ assert.deepEqual(violations, [], "use client/design-tokens.ts (see docs/design-system.md)");
39
+ });
@@ -0,0 +1,168 @@
1
+ import { Platform, type TextStyle, type ViewStyle } from "react-native";
2
+
3
+ /**
4
+ * Activity design tokens (065). The host only supplies `theme.colors` and
5
+ * `layout.compact`; type scale, spacing, radii and sizes live here so the
6
+ * Global / Workspace / Agent scopes and the composer popovers share one
7
+ * visual language. Rules and rationale: `docs/design-system.md`.
8
+ */
9
+
10
+ export const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
11
+
12
+ export const FONT_SIZE = {
13
+ /** Icon corner counters. */
14
+ badge: 9,
15
+ /** Pill badges, dense chart ticks, terminal output. */
16
+ caption: 11,
17
+ /** Row meta, axis labels, legends, tooltips, in-chart tabs. */
18
+ label: 12,
19
+ /** Inline empty / error / loading, row counts, search input, code body. */
20
+ small: 13,
21
+ /** Row titles, insights / rank rows, filter tabs, menu items. */
22
+ body: 14,
23
+ /** Section title (regular); compact uses `body`. */
24
+ title: 15,
25
+ /** KPI value (FitText base, shrinks to fit). */
26
+ metric: 18,
27
+ /** Full-page empty state title. */
28
+ display: 19,
29
+ } as const;
30
+
31
+ export const FONT_WEIGHT = {
32
+ regular: "normal",
33
+ medium: "500",
34
+ semibold: "600",
35
+ bold: "700",
36
+ } as const satisfies Record<string, TextStyle["fontWeight"]>;
37
+
38
+ const TABULAR: TextStyle["fontVariant"] = ["tabular-nums"];
39
+
40
+ /** Text roles without color; components add `color` from `theme.colors`. */
41
+ export const TEXT = {
42
+ display: { fontSize: FONT_SIZE.display, fontWeight: FONT_WEIGHT.medium },
43
+ rowTitle: { fontSize: FONT_SIZE.body, fontWeight: FONT_WEIGHT.medium },
44
+ body: { fontSize: FONT_SIZE.body },
45
+ small: { fontSize: FONT_SIZE.small },
46
+ meta: { fontSize: FONT_SIZE.label },
47
+ caption: { fontSize: FONT_SIZE.caption },
48
+ count: { fontSize: FONT_SIZE.small, fontVariant: TABULAR },
49
+ tabularMeta: { fontSize: FONT_SIZE.label, fontVariant: TABULAR },
50
+ pillBadge: { fontSize: FONT_SIZE.caption, fontWeight: FONT_WEIGHT.semibold, fontVariant: TABULAR },
51
+ iconBadge: { fontSize: FONT_SIZE.badge, fontWeight: FONT_WEIGHT.bold, fontVariant: TABULAR, lineHeight: 11 },
52
+ back: { fontSize: FONT_SIZE.small, fontWeight: FONT_WEIGHT.medium },
53
+ code: { fontSize: FONT_SIZE.small, lineHeight: 22, fontFamily: MONO },
54
+ terminal: { fontSize: FONT_SIZE.caption, lineHeight: 15, fontFamily: MONO },
55
+ tooltip: { fontSize: FONT_SIZE.label, lineHeight: 16 },
56
+ menu: { fontSize: FONT_SIZE.body, lineHeight: 18, fontWeight: FONT_WEIGHT.regular },
57
+ } as const satisfies Record<string, TextStyle>;
58
+
59
+ /** One section-title style for every scope and popover. */
60
+ export function sectionTitle(compact = false): TextStyle {
61
+ return {
62
+ fontSize: compact ? FONT_SIZE.body : FONT_SIZE.title,
63
+ fontWeight: FONT_WEIGHT.semibold,
64
+ letterSpacing: -0.3,
65
+ };
66
+ }
67
+
68
+ export type PageKind = "surface" | "panel";
69
+
70
+ /**
71
+ * Page container rhythm. `surface` = Global sidebar page (charts, wide);
72
+ * `panel` = Workspace / Agent workspace panels.
73
+ */
74
+ export function pageLayout(kind: PageKind, compact: boolean): { padding: number; gap: number } {
75
+ return {
76
+ padding: compact ? 16 : 24,
77
+ gap: kind === "surface" ? (compact ? 24 : 32) : compact ? 20 : 28,
78
+ };
79
+ }
80
+
81
+ /** Section title → first content row. */
82
+ export function titleGap(compact = false): number {
83
+ return compact ? 10 : 12;
84
+ }
85
+
86
+ /** List row vertical padding: `dense` for operational lists and popovers. */
87
+ export const ROW_PADDING = { dense: 6, regular: 9 } as const;
88
+
89
+ export const RADIUS = {
90
+ /** Chart bars, legend swatches. */
91
+ swatch: 3,
92
+ /** Icon buttons, menu rows, terminal preview. */
93
+ control: 6,
94
+ /** Menus, tooltips. */
95
+ overlay: 8,
96
+ /** Code body. */
97
+ block: 12,
98
+ /** KPI card. */
99
+ card: 20,
100
+ } as const;
101
+
102
+ /** Fully rounded ends for a box of the given height (badges, search field, dots). */
103
+ export function pillRadius(height: number): number {
104
+ return height / 2;
105
+ }
106
+
107
+ export const ICON_SIZE = {
108
+ /** Inside a pill badge. */
109
+ badge: 12,
110
+ /** Inline glyphs: search field, menu chevron, row close. */
111
+ inline: 14,
112
+ /** Header / back / toggle icon buttons. */
113
+ action: 16,
114
+ /** Leading icon of a list row. */
115
+ leading: 18,
116
+ } as const;
117
+
118
+ export const CONTROL = {
119
+ iconButton: 24,
120
+ hitSlop: 8,
121
+ pillBadgeHeight: 18,
122
+ } as const;
123
+
124
+ export const iconButton: ViewStyle = {
125
+ width: CONTROL.iconButton,
126
+ height: CONTROL.iconButton,
127
+ alignItems: "center",
128
+ justifyContent: "center",
129
+ borderRadius: RADIUS.control,
130
+ flexShrink: 0,
131
+ };
132
+
133
+ /**
134
+ * Global chart motion (081): `grow` for bars reaching a new value, `reveal` /
135
+ * `refresh` for the heatmap's first column sweep and later metric / range
136
+ * switches. `refreshFloor` is the lowest column opacity during a refresh.
137
+ * `disclose` is the ranking Show more / Show less height transition.
138
+ * `step` / `stepOffset` slide the metric switch label in from the pressed side.
139
+ */
140
+ export const CHART_MOTION = {
141
+ grow: 400,
142
+ disclose: 250,
143
+ step: 200,
144
+ stepOffset: 12,
145
+ reveal: 700,
146
+ refresh: 450,
147
+ refreshFloor: 0.3,
148
+ columnSpan: 0.35,
149
+ } as const;
150
+
151
+ /** Composer popover content frame, shared by the Activity and Attention pills. */
152
+ export const POPOVER_WIDTH = { min: 300, max: 380 } as const;
153
+
154
+ export function popoverFrame(compact: boolean): ViewStyle {
155
+ return compact ? {} : { minWidth: POPOVER_WIDTH.min, maxWidth: POPOVER_WIDTH.max };
156
+ }
157
+
158
+ /** Floating chart tooltip container (heatmap, creations histogram). */
159
+ export function tooltipSurface(colors: { surface2: string; border: string }): ViewStyle {
160
+ return {
161
+ paddingHorizontal: 10,
162
+ paddingVertical: 6,
163
+ borderRadius: RADIUS.overlay,
164
+ backgroundColor: colors.surface2,
165
+ borderWidth: 1,
166
+ borderColor: colors.border,
167
+ };
168
+ }