@koinzhang/paseo-plugin-activity 0.4.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +61 -2
  2. package/README.md +3 -3
  3. package/client/activity-heatmap.tsx +17 -25
  4. package/client/agent-creations.tsx +207 -0
  5. package/client/agent-directory.test.ts +191 -0
  6. package/client/agent-directory.ts +150 -0
  7. package/client/attention-pill.tsx +17 -105
  8. package/client/color-mix.test.ts +27 -0
  9. package/client/color-mix.ts +38 -0
  10. package/client/fit-text.test.ts +41 -0
  11. package/client/fit-text.ts +33 -0
  12. package/client/global-surface.tsx +104 -31
  13. package/client/hourly-activity-timeline.tsx +392 -0
  14. package/client/measured-width.ts +72 -0
  15. package/client/pill-directory.ts +20 -68
  16. package/client/range.test.ts +44 -0
  17. package/client/range.ts +14 -0
  18. package/client/rank-color.test.ts +108 -14
  19. package/client/rank-color.ts +261 -48
  20. package/client/usage-stats.tsx +116 -5
  21. package/client/use-agent-turn-end.ts +19 -2
  22. package/client/use-workspace-agent-statuses.ts +18 -42
  23. package/client/workspace/constants.ts +2 -0
  24. package/client/workspace/host-archive-sync.test.ts +46 -0
  25. package/client/workspace/host-archive-sync.ts +15 -0
  26. package/client/workspace/list-host-agents.test.ts +11 -63
  27. package/client/workspace/list-host-agents.ts +4 -58
  28. package/client/workspace/panel.tsx +99 -12
  29. package/client/workspace/rank-section.tsx +150 -11
  30. package/index.server.ts +30 -0
  31. package/package.json +3 -3
  32. package/paseo-plugin.json +1 -1
  33. package/server/background-sync.test.ts +43 -0
  34. package/server/background-sync.ts +9 -0
  35. package/server/handlers-query.test.ts +225 -0
  36. package/server/handlers.ts +117 -0
  37. package/shared/activity.test.ts +123 -6
  38. package/shared/activity.ts +103 -5
  39. package/shared/classify.test.ts +10 -0
  40. package/shared/classify.ts +10 -0
  41. package/shared/explorer-agent-display.test.ts +61 -0
  42. package/shared/explorer-agent-display.ts +21 -2
  43. package/shared/format.test.ts +28 -3
  44. package/shared/format.ts +22 -2
  45. package/shared/insights.test.ts +113 -70
  46. package/shared/insights.ts +53 -39
  47. package/shared/usage.test.ts +209 -0
  48. package/shared/usage.ts +283 -1
  49. package/client/pill-directory.test.ts +0 -92
  50. package/client/workspace/agent-live-status-sync.tsx +0 -103
  51. package/client/workspace/status-cache.test.ts +0 -62
  52. package/client/workspace/status-cache.ts +0 -23
@@ -4,6 +4,7 @@ import {
4
4
  classifyToolCall,
5
5
  matchSkillFile,
6
6
  normalizeProvider,
7
+ brandProviderId,
7
8
  } from "./classify.ts";
8
9
 
9
10
  describe("normalizeProvider", () => {
@@ -12,11 +13,20 @@ describe("normalizeProvider", () => {
12
13
  assert.equal(normalizeProvider("opencode"), "opencode");
13
14
  assert.equal(normalizeProvider("codex"), "codex");
14
15
  assert.equal(normalizeProvider("pi"), "pi");
16
+ assert.equal(normalizeProvider("omp"), "pi");
15
17
  assert.equal(normalizeProvider("cursor"), "cursor");
16
18
  assert.equal(normalizeProvider("codebuddy-code"), "codebuddy");
17
19
  });
18
20
  });
19
21
 
22
+ describe("brandProviderId", () => {
23
+ it("keeps omp distinct from pi for chart colour", () => {
24
+ assert.equal(brandProviderId("omp"), "omp");
25
+ assert.equal(brandProviderId("pi"), "pi");
26
+ assert.equal(brandProviderId("claude/opus"), "claude");
27
+ });
28
+ });
29
+
20
30
  describe("matchSkillFile", () => {
21
31
  it("extracts skill name from common agent config roots", () => {
22
32
  assert.equal(
@@ -124,6 +124,16 @@ export function normalizeProvider(provider: string): string {
124
124
  return head;
125
125
  }
126
126
 
127
+ /**
128
+ * Chart / brand colour identity. Same as `normalizeProvider`, except Oh My Pi
129
+ * (`omp`) stays distinct from Pi so the creations histogram can colour them apart.
130
+ */
131
+ export function brandProviderId(provider: string): string {
132
+ const head = (provider.split("/")[0] ?? provider).toLowerCase();
133
+ if (head === "omp") return "omp";
134
+ return normalizeProvider(provider);
135
+ }
136
+
127
137
  function expandHome(path: string, homeDir?: string): string {
128
138
  if (homeDir && path.startsWith("~/")) {
129
139
  return `${homeDir.replace(/\/+$/, "")}/${path.slice(2)}`;
@@ -0,0 +1,61 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import {
4
+ explorerAgentDisplaySettings,
5
+ migrateExplorerAgentDisplay,
6
+ } from "./explorer-agent-display.ts";
7
+
8
+ test("Explorer display settings default Skills and MCP to timeline", () => {
9
+ const values = explorerAgentDisplaySettings.schema.parse({});
10
+ assert.equal(values.rankView, "timeline");
11
+ });
12
+
13
+ test("Explorer display settings migrate v1 while preserving Agent filters", () => {
14
+ const migrated = migrateExplorerAgentDisplay(
15
+ {
16
+ sort: "name",
17
+ group: "provider",
18
+ show: ["messages"],
19
+ status: ["active", "archived"],
20
+ lifecycle: ["running"],
21
+ },
22
+ 1,
23
+ );
24
+ const values = explorerAgentDisplaySettings.schema.parse(migrated);
25
+ assert.equal(values.rankView, "timeline");
26
+ assert.equal(values.sort, "name");
27
+ assert.deepEqual(values.status, ["active", "archived"]);
28
+ });
29
+
30
+ test("Explorer display settings preserve the v2 Skills view as the shared rank view", () => {
31
+ const migrated = migrateExplorerAgentDisplay(
32
+ {
33
+ sort: "updated",
34
+ group: "none",
35
+ show: [],
36
+ status: ["active"],
37
+ lifecycle: ["idle", "running", "error", "closed"],
38
+ skillView: "timeline",
39
+ },
40
+ 2,
41
+ );
42
+ const values = explorerAgentDisplaySettings.schema.parse(migrated);
43
+ assert.equal(values.rankView, "timeline");
44
+ assert.equal("skillView" in values, false);
45
+ });
46
+
47
+ test("Explorer display settings preserve an explicit v2 ranked Skills view", () => {
48
+ const migrated = migrateExplorerAgentDisplay(
49
+ {
50
+ sort: "updated",
51
+ group: "none",
52
+ show: [],
53
+ status: ["active"],
54
+ lifecycle: ["idle", "running", "error", "closed"],
55
+ skillView: "ranked",
56
+ },
57
+ 2,
58
+ );
59
+ const values = explorerAgentDisplaySettings.schema.parse(migrated);
60
+ assert.equal(values.rankView, "ranked");
61
+ });
@@ -1,11 +1,27 @@
1
1
  import { defineSettings } from "@getpaseo/plugin";
2
2
  import { z } from "zod";
3
3
 
4
- /** Host-scoped Explorer Agents menu prefs (Sort / Group / Show / Status / Lifecycle). */
4
+ export function migrateExplorerAgentDisplay(values: unknown, fromVersion: number): unknown {
5
+ if (
6
+ fromVersion < 3 &&
7
+ values !== null &&
8
+ typeof values === "object" &&
9
+ !Array.isArray(values)
10
+ ) {
11
+ const { skillView, ...rest } = values as Record<string, unknown>;
12
+ return {
13
+ ...rest,
14
+ rankView: skillView === "ranked" ? "ranked" : "timeline",
15
+ };
16
+ }
17
+ return values;
18
+ }
19
+
20
+ /** Host-scoped Explorer display prefs (Agents menu + shared Skills/MCP view). */
5
21
  export const explorerAgentDisplaySettings = defineSettings({
6
22
  id: "explorer-agent-display",
7
23
  scope: "host",
8
- version: 1,
24
+ version: 3,
9
25
  schema: z.object({
10
26
  sort: z.enum(["created", "updated", "name", "messages", "status"]).default("updated"),
11
27
  group: z.enum(["none", "provider", "status"]).default("none"),
@@ -14,7 +30,9 @@ export const explorerAgentDisplaySettings = defineSettings({
14
30
  lifecycle: z
15
31
  .array(z.enum(["idle", "running", "error", "closed"]))
16
32
  .default(["idle", "running", "error", "closed"]),
33
+ rankView: z.enum(["ranked", "timeline"]).default("timeline"),
17
34
  }),
35
+ migrate: migrateExplorerAgentDisplay,
18
36
  });
19
37
 
20
38
  export type ExplorerAgentDisplayValues = z.infer<
@@ -27,4 +45,5 @@ export const EXPLORER_AGENT_DISPLAY_DEFAULTS: ExplorerAgentDisplayValues = {
27
45
  show: [],
28
46
  status: ["active"],
29
47
  lifecycle: ["idle", "running", "error", "closed"],
48
+ rankView: "timeline",
30
49
  };
@@ -2,9 +2,10 @@ import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
3
  import {
4
4
  formatActivityTime,
5
+ formatCount,
5
6
  formatDisplayName,
7
+ formatDuration,
6
8
  formatLocalDateTime,
7
- formatUpdatedAt,
8
9
  } from "./format.ts";
9
10
 
10
11
  const NOW = new Date(2026, 8, 18, 15, 30);
@@ -39,9 +40,33 @@ describe("formatActivityTime", () => {
39
40
  assert.equal(formatActivityTime(undefined, "en", NOW), "—");
40
41
  assert.equal(formatActivityTime("not-a-date", "en", NOW), "not-a-date");
41
42
  });
43
+ });
44
+
45
+ describe("formatDuration", () => {
46
+ it("steps through minutes, hours, days and months", () => {
47
+ assert.equal(formatDuration(0), "<1 min");
48
+ assert.equal(formatDuration(59_000), "<1 min");
49
+ assert.equal(formatDuration(59 * 60_000), "59 min");
50
+ assert.equal(formatDuration(3.25 * 3_600_000), "3.3 h");
51
+ assert.equal(formatDuration(47 * 3_600_000), "47 h");
52
+ assert.equal(formatDuration(48 * 3_600_000), "2 days");
53
+ assert.equal(formatDuration(277.7 * 3_600_000), "11.6 days");
54
+ assert.equal(formatDuration(100 * 24 * 3_600_000), "3.3 months");
55
+ });
56
+
57
+ it("rejects negative and non-finite input", () => {
58
+ assert.equal(formatDuration(-1), "—");
59
+ assert.equal(formatDuration(Number.NaN), "—");
60
+ });
61
+ });
42
62
 
43
- it("keeps formatUpdatedAt as an alias", () => {
44
- assert.equal(formatUpdatedAt, formatActivityTime);
63
+ describe("formatCount", () => {
64
+ it("keeps small counts exact and abbreviates k / M", () => {
65
+ assert.equal(formatCount(0), "0");
66
+ assert.equal(formatCount(9999), "9999");
67
+ assert.equal(formatCount(12345), "12.3k");
68
+ assert.equal(formatCount(10000), "10k");
69
+ assert.equal(formatCount(1234567), "1.2M");
45
70
  });
46
71
  });
47
72
 
package/shared/format.ts CHANGED
@@ -50,5 +50,25 @@ export function formatActivityTime(
50
50
  return date.toLocaleString(locale, options);
51
51
  }
52
52
 
53
- /** @deprecated Prefer `formatActivityTime`. */
54
- export const formatUpdatedAt = formatActivityTime;
53
+ const MINUTE_MS = 60_000;
54
+ const HOUR_MS = 60 * MINUTE_MS;
55
+ const DAY_MS = 24 * HOUR_MS;
56
+
57
+ /** Compact count for KPI tiles: 9999 → `9999`, 12345 → `12.3k`, 1234567 → `1.2M`. */
58
+ export function formatCount(value: number): string {
59
+ if (value >= 1_000_000) return `${Number((value / 1_000_000).toFixed(1))}M`;
60
+ if (value >= 10_000) return `${Number((value / 1_000).toFixed(1))}k`;
61
+ return String(value);
62
+ }
63
+
64
+ /** Compact locale-independent duration for agent lifetimes (049). */
65
+ export function formatDuration(ms: number): string {
66
+ if (!Number.isFinite(ms) || ms < 0) return "—";
67
+ if (ms < MINUTE_MS) return "<1 min";
68
+ if (ms < HOUR_MS) return `${Math.floor(ms / MINUTE_MS)} min`;
69
+ const hours = ms / HOUR_MS;
70
+ if (hours < 48) return `${Number(hours.toFixed(1))} h`;
71
+ const days = ms / DAY_MS;
72
+ if (days < 60) return `${Number(days.toFixed(1))} days`;
73
+ return `${Number((days / 30.44).toFixed(1))} months`;
74
+ }
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import { ACTIVITY_LIST_LIMIT, buildActivityInsights } from "./insights.ts";
3
+ import { ACTIVITY_LIST_LIMIT, buildActivityInsights, buildActivityKpi } from "./insights.ts";
4
4
  import type { ProviderUsageItem } from "./usage.ts";
5
5
 
6
6
  function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem, "provider" | "label">): ProviderUsageItem {
@@ -27,8 +27,7 @@ function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem,
27
27
  }
28
28
 
29
29
  describe("buildActivityInsights", () => {
30
- it("returns habit → preference → structure 8 rows", () => {
31
- // 2026-03-07 Sat, 2026-03-09 Mon — Mon has more messages → Peak weekday Mon
30
+ it("returns calendar → volume → structure 8 rows", () => {
32
31
  const days = [
33
32
  { date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
34
33
  { date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 },
@@ -42,29 +41,8 @@ describe("buildActivityInsights", () => {
42
41
  messages: 14,
43
42
  codingAgents: 3,
44
43
  chatAgents: 1,
45
- longestStreak: 6,
46
44
  },
47
- providers: [
48
- provider({
49
- provider: "codex",
50
- label: "Codex",
51
- messageCount: 10,
52
- agentCount: 3,
53
- codingAgentCount: 2,
54
- chatAgentCount: 1,
55
- models: [{ model: "gpt-5.4", count: 10 }],
56
- }),
57
- provider({
58
- provider: "claude",
59
- label: "Claude",
60
- messageCount: 4,
61
- agentCount: 2,
62
- codingAgentCount: 1,
63
- chatAgentCount: 0,
64
- models: [{ model: "opus", count: 4 }],
65
- }),
66
- ],
67
- providerFilter: "all",
45
+ workspaces: 7,
68
46
  locale: "en",
69
47
  });
70
48
 
@@ -73,70 +51,135 @@ describe("buildActivityInsights", () => {
73
51
  rows.map((r) => r.label),
74
52
  [
75
53
  "Active days",
76
- "Longest streak",
77
54
  "Busiest day",
78
- "Peak weekday",
79
- "Top provider",
80
- "Top model",
55
+ "Workspaces",
56
+ "Messages",
57
+ "Skill calls",
58
+ "MCP calls",
81
59
  "Messages per agent",
82
60
  "Coding vs chat",
83
61
  ],
84
62
  );
85
63
  assert.equal(rows[0]?.value, "2");
86
- assert.equal(rows[1]?.value, "6 days");
87
- assert.equal(rows[2]?.value, "Mar 9 · 10 messages");
88
- assert.equal(rows[3]?.value, "Mon");
89
- assert.equal(rows[4]?.value, "Codex · 71%");
90
- assert.equal(rows[5]?.value, "Gpt 5.4 · 71%");
64
+ assert.equal(rows[1]?.value, "Mar 9 · 10 messages");
65
+ assert.equal(rows[2]?.value, "7");
66
+ assert.equal(rows[3]?.value, "14");
67
+ assert.equal(rows[4]?.value, "2");
68
+ assert.equal(rows[5]?.value, "3");
91
69
  assert.equal(rows[6]?.value, "2.8");
92
70
  // 3 coding / (3+1) active → 75%
93
71
  assert.equal(rows[7]?.value, "75% coding");
94
72
  });
95
73
 
96
- it("hides Top provider when filtered; Top model stays scoped", () => {
97
- const rows = buildActivityInsights({
98
- days: [{ date: "2026-03-07", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 }],
99
- summary: {
100
- skills: 0,
101
- mcp: 0,
102
- agents: 1,
103
- messages: 10,
104
- codingAgents: 0,
105
- chatAgents: 1,
106
- longestStreak: 1,
107
- },
108
- providers: [
109
- provider({
110
- provider: "codex",
111
- label: "Codex",
112
- messageCount: 10,
113
- agentCount: 1,
114
- codingAgentCount: 0,
115
- chatAgentCount: 1,
116
- models: [{ model: "gpt-5.4", count: 10 }],
117
- }),
118
- ],
119
- providerFilter: "codex",
120
- });
121
- assert.equal(rows.length, ACTIVITY_LIST_LIMIT);
122
- assert.equal(rows.find((r) => r.label === "Top provider")?.value, "—");
123
- assert.equal(rows.find((r) => r.label === "Top model")?.value, "Gpt 5.4 · 100%");
124
- assert.equal(rows.find((r) => r.label === "Coding vs chat")?.value, "0% coding");
125
- });
126
-
127
74
  it("uses dashes for zero denominators and falls back busiest day", () => {
128
75
  const rows = buildActivityInsights({
129
76
  days: [{ date: "2026-03-08", skills: 3, mcp: 1, agents: 2, messages: 0, total: 4 }],
130
77
  summary: { skills: 3, mcp: 1, agents: 2, messages: 0, codingAgents: 0, chatAgents: 0 },
131
- providers: [],
132
- providerFilter: "all",
78
+ workspaces: 0,
133
79
  locale: "en",
134
80
  });
135
81
  assert.equal(rows.find((r) => r.label === "Busiest day")?.value, "Mar 8 · 4 calls");
136
82
  assert.equal(rows.find((r) => r.label === "Messages per agent")?.value, "0");
137
83
  assert.equal(rows.find((r) => r.label === "Coding vs chat")?.value, "—");
138
- assert.equal(rows.find((r) => r.label === "Top provider")?.value, "—");
139
- assert.equal(rows.find((r) => r.label === "Top model")?.value, "—");
140
- assert.equal(rows.find((r) => r.label === "Peak weekday")?.value, "Sun");
84
+ assert.equal(rows.find((r) => r.label === "Workspaces")?.value, "0");
85
+ });
86
+
87
+ it("groups volume counts with the app locale", () => {
88
+ const rows = buildActivityInsights({
89
+ days: [],
90
+ summary: { skills: 0, mcp: 0, agents: 1, messages: 12345 },
91
+ workspaces: 0,
92
+ locale: "en",
93
+ });
94
+ assert.equal(rows.find((r) => r.label === "Messages")?.value, "12,345");
95
+ assert.equal(rows.find((r) => r.label === "Active days")?.value, "0");
96
+ assert.equal(rows.find((r) => r.label === "Busiest day")?.value, "—");
97
+ });
98
+ });
99
+
100
+ describe("buildActivityKpi", () => {
101
+ const codex = provider({
102
+ provider: "codex",
103
+ label: "Codex",
104
+ messageCount: 10,
105
+ models: [{ model: "gpt-5.4", count: 10 }],
106
+ });
107
+ const claude = provider({
108
+ provider: "claude",
109
+ label: "Claude",
110
+ messageCount: 4,
111
+ models: [{ model: "opus", count: 4 }],
112
+ });
113
+ // 2026-03-07 Sat, 2026-03-09 Mon — Mon carries more messages → Peak weekday Mon.
114
+ const days = [
115
+ { date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
116
+ { date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 },
117
+ ];
118
+
119
+ it("leads with top / longest tiles", () => {
120
+ const rows = buildActivityKpi({
121
+ agents: 12345,
122
+ days,
123
+ locale: "en",
124
+ longestStreak: 6,
125
+ longestAgent: { durationMs: 277.7 * 3_600_000, active: false },
126
+ providers: [codex, claude],
127
+ providerFilter: "all",
128
+ });
129
+ assert.deepEqual(
130
+ rows.map((r) => r.label),
131
+ ["Agents", "Longest agent", "Top provider", "Top model", "Peak weekday", "Longest streak"],
132
+ );
133
+ assert.equal(rows[0]?.value, "12.3k");
134
+ assert.equal(rows[1]?.value, "11.6 days");
135
+ assert.equal(rows[2]?.value, "Codex");
136
+ assert.equal(rows[3]?.value, "Gpt 5.4");
137
+ assert.equal(rows[4]?.value, "Mon");
138
+ assert.equal(rows[5]?.value, "6 days");
139
+ });
140
+
141
+ it("marks the longest agent as active while it is still open (051)", () => {
142
+ const rows = buildActivityKpi({
143
+ agents: 3,
144
+ days: [{ date: "2026-03-08", skills: 3, mcp: 1, agents: 2, messages: 0, total: 4 }],
145
+ locale: "en",
146
+ longestStreak: 2,
147
+ longestAgent: { durationMs: 26 * 3_600_000, active: true },
148
+ providers: [codex],
149
+ providerFilter: "all",
150
+ });
151
+ assert.equal(rows[1]?.value, "26 h · active");
152
+ assert.equal(rows[4]?.value, "Sun");
153
+ });
154
+
155
+ it("scopes top tiles to the selected provider and tolerates missing data", () => {
156
+ const rows = buildActivityKpi({
157
+ agents: 0,
158
+ days,
159
+ locale: "en",
160
+ longestStreak: 1,
161
+ longestAgent: null,
162
+ providers: [codex],
163
+ providerFilter: "codex",
164
+ });
165
+ assert.equal(rows[1]?.value, "—");
166
+ assert.equal(rows[2]?.value, "Codex");
167
+ assert.equal(rows[3]?.value, "Gpt 5.4");
168
+ assert.equal(rows[4]?.value, "Mon");
169
+ assert.equal(rows[5]?.value, "1 day");
170
+
171
+ const empty = buildActivityKpi({
172
+ agents: 0,
173
+ days: [],
174
+ locale: "en",
175
+ longestStreak: 0,
176
+ longestAgent: null,
177
+ providers: [],
178
+ providerFilter: "all",
179
+ });
180
+ assert.equal(empty[2]?.value, "—");
181
+ assert.equal(empty[3]?.value, "—");
182
+ assert.equal(empty[4]?.value, "—");
183
+ assert.equal(empty[5]?.value, "0 days");
141
184
  });
142
185
  });
@@ -1,6 +1,6 @@
1
1
  import type { ActivityDay, ProviderUsageItem } from "./usage.ts";
2
2
  import { isActiveDay } from "./activity.ts";
3
- import { formatDisplayName } from "./format.ts";
3
+ import { formatCount, formatDisplayName, formatDuration } from "./format.ts";
4
4
 
5
5
  export type InsightRow = { label: string; value: string };
6
6
 
@@ -13,7 +13,6 @@ export type InsightSummary = {
13
13
  codingAgents?: number;
14
14
  /** Active non-coding agents (018); empty creations excluded. */
15
15
  chatAgents?: number;
16
- longestStreak?: number;
17
16
  };
18
17
 
19
18
  /** Shared cap for Activity insights and Most used skills / MCP / models. */
@@ -74,25 +73,24 @@ function formatBusiest(day: ActivityDay, locale: string): string {
74
73
  return label;
75
74
  }
76
75
 
77
- /** All view only: messages-weighted top provider. Filtered or empty → `—`. */
76
+ /** Messages-weighted top provider (050); label only — no share (052 follow-up). */
78
77
  function topProviderValue(
79
78
  providers: readonly ProviderUsageItem[],
80
79
  providerFilter: string,
81
80
  ): string {
82
- if (providerFilter !== "all") return "—";
81
+ if (providerFilter !== "all") {
82
+ return providers.find((p) => p.provider === providerFilter)?.label ?? "—";
83
+ }
83
84
  const ranked = [...providers]
84
85
  .filter((p) => p.messageCount > 0)
85
86
  .sort(
86
87
  (a, b) =>
87
88
  b.messageCount - a.messageCount || a.provider.localeCompare(b.provider),
88
89
  );
89
- const top = ranked[0];
90
- if (!top) return "—";
91
- const total = ranked.reduce((sum, p) => sum + p.messageCount, 0);
92
- const pct = total > 0 ? Math.round((top.messageCount / total) * 100) : 0;
93
- return `${top.label} · ${pct}%`;
90
+ return ranked[0]?.label ?? "—";
94
91
  }
95
92
 
93
+ /** Messages-weighted top model (050); label only — no share (052 follow-up). */
96
94
  function topModelValue(
97
95
  providers: readonly ProviderUsageItem[],
98
96
  providerFilter: string,
@@ -112,9 +110,7 @@ function topModelValue(
112
110
  );
113
111
  const top = ranked[0];
114
112
  if (!top || top[1] <= 0) return "—";
115
- const total = ranked.reduce((sum, [, count]) => sum + count, 0);
116
- const pct = total > 0 ? Math.round((top[1] / total) * 100) : 0;
117
- return `${formatDisplayName(top[0])} · ${pct}%`;
113
+ return formatDisplayName(top[0]);
118
114
  }
119
115
 
120
116
  /** Share of active agents that are coding (018); empty creations excluded. */
@@ -149,59 +145,77 @@ function peakWeekdayValue(days: readonly ActivityDay[], locale: string): string
149
145
  }
150
146
 
151
147
  /**
152
- * Fixed 8-row habit insights. Avoids KPI totals and Most used entity lists.
148
+ * Fixed 8-row insights: calendar habit → in-window volume → structure (050;
149
+ * Workspaces moved in from the KPI row in 054).
153
150
  */
154
151
  export function buildActivityInsights(input: {
155
152
  days: readonly ActivityDay[];
156
153
  summary: InsightSummary;
157
- providers: readonly ProviderUsageItem[];
158
- providerFilter: string;
154
+ /** Distinct workspaces among in-window agents (011); was KPI tile 3 before 054. */
155
+ workspaces: number;
159
156
  locale?: string;
160
- /** Max rows (default {@link ACTIVITY_LIST_LIMIT}). */
161
- limit?: number;
162
157
  }): InsightRow[] {
163
158
  const locale = input.locale ?? "en";
164
- const limit = input.limit ?? ACTIVITY_LIST_LIMIT;
165
159
  const activeDays = input.days.filter(isActiveDay).length;
166
160
  const busiest = pickBusiestDay(input.days);
167
- const longest = input.summary.longestStreak;
168
161
  const codingAgents = input.summary.codingAgents ?? 0;
169
162
  const chatAgents = input.summary.chatAgents ?? 0;
170
163
 
171
- const rows: InsightRow[] = [
164
+ return [
172
165
  { label: "Active days", value: String(activeDays) },
173
- {
174
- label: "Longest streak",
175
- value:
176
- longest != null
177
- ? `${longest} day${longest === 1 ? "" : "s"}`
178
- : "—",
179
- },
180
166
  {
181
167
  label: "Busiest day",
182
168
  value: busiest ? formatBusiest(busiest, locale) : "—",
183
169
  },
170
+ { label: "Workspaces", value: formatCount(input.workspaces) },
171
+ { label: "Messages", value: input.summary.messages.toLocaleString(locale) },
172
+ { label: "Skill calls", value: input.summary.skills.toLocaleString(locale) },
173
+ { label: "MCP calls", value: input.summary.mcp.toLocaleString(locale) },
184
174
  {
185
- label: "Peak weekday",
186
- value: peakWeekdayValue(input.days, locale),
175
+ label: "Messages per agent",
176
+ value: formatRatio(input.summary.messages, input.summary.agents),
187
177
  },
188
178
  {
189
- label: "Top provider",
190
- value: topProviderValue(input.providers, input.providerFilter),
179
+ label: "Coding vs chat",
180
+ value: codingVsChatValue(codingAgents, chatAgents),
191
181
  },
182
+ ];
183
+ }
184
+
185
+ /**
186
+ * Fixed 6-tile KPI row (050): agents, longest agent, top provider, top model,
187
+ * peak weekday (054), longest streak.
188
+ */
189
+ export function buildActivityKpi(input: {
190
+ agents: number;
191
+ /** Active days drive the peak-weekday tile (054); was an insights row before. */
192
+ days: readonly ActivityDay[];
193
+ locale?: string;
194
+ longestStreak: number;
195
+ /** Longest created→(archived | now) span from the registry (049 / 051). */
196
+ longestAgent: { durationMs: number; active: boolean } | null;
197
+ providers: readonly ProviderUsageItem[];
198
+ providerFilter: string;
199
+ }): InsightRow[] {
200
+ const streak = input.longestStreak;
201
+ const longest = input.longestAgent;
202
+ return [
203
+ { label: "Agents", value: formatCount(input.agents) },
192
204
  {
193
- label: "Top model",
194
- value: topModelValue(input.providers, input.providerFilter),
205
+ label: "Longest agent",
206
+ value: longest
207
+ ? `${formatDuration(longest.durationMs)}${longest.active ? " · active" : ""}`
208
+ : "—",
195
209
  },
196
210
  {
197
- label: "Messages per agent",
198
- value: formatRatio(input.summary.messages, input.summary.agents),
211
+ label: "Top provider",
212
+ value: topProviderValue(input.providers, input.providerFilter),
199
213
  },
200
214
  {
201
- label: "Coding vs chat",
202
- value: codingVsChatValue(codingAgents, chatAgents),
215
+ label: "Top model",
216
+ value: topModelValue(input.providers, input.providerFilter),
203
217
  },
218
+ { label: "Peak weekday", value: peakWeekdayValue(input.days, input.locale ?? "en") },
219
+ { label: "Longest streak", value: `${streak} day${streak === 1 ? "" : "s"}` },
204
220
  ];
205
-
206
- return rows.slice(0, limit);
207
221
  }