@koinzhang/paseo-plugin-activity 0.1.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/client/activity-heatmap.tsx +138 -0
  2. package/client/global-surface.tsx +689 -0
  3. package/client/panel.tsx +423 -0
  4. package/client/pending-skill.ts +50 -0
  5. package/client/pill-data-cache.test.ts +68 -0
  6. package/client/pill-data-cache.ts +37 -0
  7. package/client/pill.tsx +211 -0
  8. package/client/provider-filter.test.ts +95 -0
  9. package/client/provider-filter.ts +44 -0
  10. package/client/rank-color.test.ts +35 -0
  11. package/client/rank-color.ts +69 -0
  12. package/client/usage-popover.tsx +383 -0
  13. package/client/usage-query.tsx +54 -0
  14. package/client/usage-stats.tsx +18 -0
  15. package/client/use-app-language.ts +14 -0
  16. package/client/web.ts +28 -0
  17. package/index.client.tsx +62 -0
  18. package/index.server.ts +128 -0
  19. package/package.json +31 -0
  20. package/paseo-plugin.json +6 -0
  21. package/server/agents.test.ts +67 -0
  22. package/server/agents.ts +75 -0
  23. package/server/background-sync.test.ts +143 -0
  24. package/server/background-sync.ts +105 -0
  25. package/server/handlers-query.test.ts +91 -0
  26. package/server/handlers.ts +531 -0
  27. package/server/host-types.ts +14 -0
  28. package/server/ingest.test.ts +233 -0
  29. package/server/ingest.ts +277 -0
  30. package/server/mcp-servers.test.ts +70 -0
  31. package/server/mcp-servers.ts +212 -0
  32. package/server/messages.test.ts +150 -0
  33. package/server/migrate-data.test.ts +65 -0
  34. package/server/migrate-data.ts +54 -0
  35. package/server/resolve-model.test.ts +11 -0
  36. package/server/resolve-model.ts +30 -0
  37. package/server/skill-path.test.ts +56 -0
  38. package/server/skill-path.ts +85 -0
  39. package/server/store.test.ts +221 -0
  40. package/server/store.ts +909 -0
  41. package/server/ttl-cache.ts +34 -0
  42. package/shared/activity.test.ts +86 -0
  43. package/shared/activity.ts +185 -0
  44. package/shared/classify.test.ts +306 -0
  45. package/shared/classify.ts +378 -0
  46. package/shared/format.test.ts +48 -0
  47. package/shared/format.ts +45 -0
  48. package/shared/insights.test.ts +122 -0
  49. package/shared/insights.ts +188 -0
  50. package/shared/plugin-id.ts +7 -0
  51. package/shared/usage.test.ts +668 -0
  52. package/shared/usage.ts +726 -0
@@ -0,0 +1,188 @@
1
+ import type { ActivityDay, ProviderUsageItem } from "./usage.ts";
2
+ import { isActiveDay } from "./activity.ts";
3
+ import { formatDisplayName } from "./format.ts";
4
+
5
+ export type InsightRow = { label: string; value: string };
6
+
7
+ export type InsightSummary = {
8
+ skills: number;
9
+ mcp: number;
10
+ agents: number;
11
+ messages: number;
12
+ shell?: number;
13
+ fileReads?: number;
14
+ fileWrites?: number;
15
+ longestStreak?: number;
16
+ };
17
+
18
+ /** Shared cap for Activity insights and Most used skills / MCP / models. */
19
+ export const ACTIVITY_LIST_LIMIT = 8;
20
+
21
+ function formatRatio(numerator: number, denominator: number): string {
22
+ if (denominator <= 0) return "—";
23
+ const value = numerator / denominator;
24
+ if (Number.isInteger(value)) return String(value);
25
+ return value.toFixed(1).replace(/\.0$/, "");
26
+ }
27
+
28
+ function formatDayLabel(dateKey: string, locale: string): string {
29
+ const [y, m, d] = dateKey.split("-").map(Number);
30
+ if (!y || !m || !d) return dateKey;
31
+ return new Date(y, m - 1, d).toLocaleDateString(locale, { month: "short", day: "numeric" });
32
+ }
33
+
34
+ function parseLocalDate(dateKey: string): Date | null {
35
+ const [y, m, d] = dateKey.split("-").map(Number);
36
+ if (!y || !m || !d) return null;
37
+ return new Date(y, m - 1, d);
38
+ }
39
+
40
+ function activityVolume(day: ActivityDay): number {
41
+ return day.messages + day.agents + day.skills + day.mcp;
42
+ }
43
+
44
+ function pickBusiestDay(days: readonly ActivityDay[]): ActivityDay | null {
45
+ let best: ActivityDay | null = null;
46
+ let bestMessages = -1;
47
+ for (const day of days) {
48
+ if (day.messages > bestMessages) {
49
+ best = day;
50
+ bestMessages = day.messages;
51
+ }
52
+ }
53
+ if (best && best.messages > 0) return best;
54
+
55
+ let bestVolume = -1;
56
+ best = null;
57
+ for (const day of days) {
58
+ const volume = activityVolume(day);
59
+ if (volume > bestVolume) {
60
+ best = day;
61
+ bestVolume = volume;
62
+ }
63
+ }
64
+ return bestVolume > 0 ? best : null;
65
+ }
66
+
67
+ function formatBusiest(day: ActivityDay, locale: string): string {
68
+ const label = formatDayLabel(day.date, locale);
69
+ if (day.messages > 0) return `${label} · ${day.messages} messages`;
70
+ const calls = day.skills + day.mcp;
71
+ if (calls > 0) return `${label} · ${calls} calls`;
72
+ if (day.agents > 0) return `${label} · ${day.agents} agents`;
73
+ return label;
74
+ }
75
+
76
+ function topModelValue(
77
+ providers: readonly ProviderUsageItem[],
78
+ providerFilter: string,
79
+ ): string {
80
+ const map = new Map<string, number>();
81
+ const source =
82
+ providerFilter === "all"
83
+ ? providers
84
+ : providers.filter((p) => p.provider === providerFilter);
85
+ for (const item of source) {
86
+ for (const model of item.models) {
87
+ map.set(model.model, (map.get(model.model) ?? 0) + model.count);
88
+ }
89
+ }
90
+ const ranked = [...map.entries()].sort(
91
+ (a, b) => b[1] - a[1] || a[0].localeCompare(b[0]),
92
+ );
93
+ const top = ranked[0];
94
+ if (!top || top[1] <= 0) return "—";
95
+ const total = ranked.reduce((sum, [, count]) => sum + count, 0);
96
+ const pct = total > 0 ? Math.round((top[1] / total) * 100) : 0;
97
+ return `${formatDisplayName(top[0])} · ${pct}%`;
98
+ }
99
+
100
+ /** coding = shell + file ops; share of coding among coding+messages. */
101
+ function codingVsChatValue(shell: number, fileOps: number, messages: number): string {
102
+ const coding = shell + fileOps;
103
+ const total = coding + messages;
104
+ if (total <= 0) return "—";
105
+ const pct = Math.round((coding / total) * 100);
106
+ return `${pct}% coding`;
107
+ }
108
+
109
+ /** Weekday with the highest activity volume among active days. */
110
+ function peakWeekdayValue(days: readonly ActivityDay[], locale: string): string {
111
+ const volumes = [0, 0, 0, 0, 0, 0, 0];
112
+ for (const day of days) {
113
+ if (!isActiveDay(day)) continue;
114
+ const date = parseLocalDate(day.date);
115
+ if (!date) continue;
116
+ volumes[date.getDay()] += activityVolume(day);
117
+ }
118
+ let bestDow = -1;
119
+ let bestVol = 0;
120
+ for (let dow = 0; dow < 7; dow++) {
121
+ if (volumes[dow]! > bestVol) {
122
+ bestVol = volumes[dow]!;
123
+ bestDow = dow;
124
+ }
125
+ }
126
+ if (bestDow < 0 || bestVol <= 0) return "—";
127
+ // 2026-03-08 was a Sunday — use a known Sunday + offset for locale short name.
128
+ const probe = new Date(2026, 2, 8 + bestDow);
129
+ return probe.toLocaleDateString(locale, { weekday: "short" });
130
+ }
131
+
132
+ /**
133
+ * Fixed 8-row habit insights. Avoids KPI totals and Most used entity lists.
134
+ */
135
+ export function buildActivityInsights(input: {
136
+ days: readonly ActivityDay[];
137
+ summary: InsightSummary;
138
+ providers: readonly ProviderUsageItem[];
139
+ providerFilter: string;
140
+ locale?: string;
141
+ /** Max rows (default {@link ACTIVITY_LIST_LIMIT}). */
142
+ limit?: number;
143
+ }): InsightRow[] {
144
+ const locale = input.locale ?? "en";
145
+ const limit = input.limit ?? ACTIVITY_LIST_LIMIT;
146
+ const activeDays = input.days.filter(isActiveDay).length;
147
+ const busiest = pickBusiestDay(input.days);
148
+ const shell = input.summary.shell ?? 0;
149
+ const fileOps = (input.summary.fileReads ?? 0) + (input.summary.fileWrites ?? 0);
150
+ const longest = input.summary.longestStreak;
151
+
152
+ const rows: InsightRow[] = [
153
+ { label: "Active days", value: String(activeDays) },
154
+ {
155
+ label: "Longest streak",
156
+ value:
157
+ longest != null
158
+ ? `${longest} day${longest === 1 ? "" : "s"}`
159
+ : "—",
160
+ },
161
+ {
162
+ label: "Busiest day",
163
+ value: busiest ? formatBusiest(busiest, locale) : "—",
164
+ },
165
+ {
166
+ label: "Top model",
167
+ value: topModelValue(input.providers, input.providerFilter),
168
+ },
169
+ {
170
+ label: "Messages per agent",
171
+ value: formatRatio(input.summary.messages, input.summary.agents),
172
+ },
173
+ {
174
+ label: "Tools per message",
175
+ value: formatRatio(input.summary.skills + input.summary.mcp, input.summary.messages),
176
+ },
177
+ {
178
+ label: "Coding vs chat",
179
+ value: codingVsChatValue(shell, fileOps, input.summary.messages),
180
+ },
181
+ {
182
+ label: "Peak weekday",
183
+ value: peakWeekdayValue(input.days, locale),
184
+ },
185
+ ];
186
+
187
+ return rows.slice(0, limit);
188
+ }
@@ -0,0 +1,7 @@
1
+ /** Runtime plugin id (paseo-plugin.json / install / data dir). */
2
+ export const PLUGIN_ID = "activity";
3
+
4
+ /** Pre–Phase-2 id; kept for one-shot data-dir migration. */
5
+ export const LEGACY_PLUGIN_ID = "tool-usage";
6
+
7
+ export const LOG_PREFIX = `[${PLUGIN_ID}]`;