@koinzhang/paseo-plugin-activity 0.6.0 → 0.8.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 +50 -1
- package/README.md +18 -11
- package/client/activity-heatmap.tsx +115 -74
- package/client/agent-creations.tsx +100 -90
- package/client/attention-pill.tsx +17 -6
- package/client/attention-popover.tsx +19 -23
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +180 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +243 -268
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +153 -103
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +94 -111
- package/client/pill.tsx +1 -1
- package/client/provider-dropdown.tsx +134 -0
- package/client/provider-filter.test.ts +17 -13
- package/client/provider-filter.ts +5 -7
- package/client/rank-color.ts +3 -3
- package/client/ranking-bars.tsx +294 -0
- package/client/sidebar-item.tsx +15 -0
- package/client/ui.tsx +351 -0
- package/client/usage-popover.tsx +72 -137
- package/client/usage-stats.tsx +29 -11
- package/client/use-agent-turn-end.ts +2 -1
- package/client/use-app-language.ts +17 -0
- package/client/web.ts +73 -18
- package/client/workspace/agent-row.tsx +28 -28
- package/client/workspace/agents-section.tsx +42 -57
- package/client/workspace/constants.ts +8 -6
- package/client/workspace/display-menu.tsx +6 -5
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +96 -104
- package/client/workspace/rank-section.tsx +40 -65
- package/client/workspace/running-indicator.tsx +1 -1
- package/client/workspace/terminals-section.tsx +24 -12
- package/index.client.tsx +53 -31
- package/index.server.ts +55 -73
- package/package.json +3 -3
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.ts +34 -4
- package/server/handlers-query.test.ts +27 -1
- package/server/handlers.ts +75 -31
- package/server/host-types.ts +6 -6
- package/server/ingest.test.ts +8 -0
- package/server/messages.test.ts +96 -1
- package/server/prompt-dedupe.ts +52 -0
- package/server/rpc-cache.test.ts +74 -0
- package/server/rpc-cache.ts +48 -0
- package/server/store.test.ts +122 -0
- package/server/store.ts +313 -19
- package/server/ttl-cache.ts +3 -0
- package/server/turn-ingest.test.ts +180 -0
- package/server/turn-ingest.ts +71 -0
- package/shared/activity.test.ts +36 -0
- package/shared/activity.ts +37 -0
- package/shared/classify.test.ts +1 -10
- package/shared/classify.ts +3 -10
- package/shared/format.ts +10 -7
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +120 -81
- package/shared/insights.ts +125 -64
- package/shared/usage.test.ts +121 -0
- package/shared/usage.ts +191 -2
package/shared/i18n.ts
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Activity UI copy (066). The host SDK does not expose the app language; the
|
|
3
|
+
* client reads the Paseo `language` setting (see `client/web.ts`) and resolves
|
|
4
|
+
* it here. Catalogs are factories so counts format with the same locale.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Languages the Paseo app offers in Settings → Language (besides `system`). */
|
|
8
|
+
export const APP_LANGUAGES = ["ar", "en", "es", "fr", "ja", "ko", "pt-BR", "ru", "zh-CN"] as const;
|
|
9
|
+
export type AppLanguage = (typeof APP_LANGUAGES)[number];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the app `language` setting to a supported tag: an explicit choice wins;
|
|
13
|
+
* `system` / unknown walks the OS preferences by exact tag, then base language.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveAppLanguage(
|
|
16
|
+
setting: string | null | undefined,
|
|
17
|
+
systemLanguages: readonly string[] = [],
|
|
18
|
+
): AppLanguage {
|
|
19
|
+
const explicit = matchLanguage(setting ?? "");
|
|
20
|
+
if (explicit && setting !== "system") return explicit;
|
|
21
|
+
for (const candidate of systemLanguages) {
|
|
22
|
+
const match = matchLanguage(candidate);
|
|
23
|
+
if (match) return match;
|
|
24
|
+
}
|
|
25
|
+
return "en";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function matchLanguage(tag: string): AppLanguage | null {
|
|
29
|
+
const lower = tag.trim().toLowerCase();
|
|
30
|
+
if (!lower || lower === "system") return null;
|
|
31
|
+
const exact = APP_LANGUAGES.find((lang) => lang.toLowerCase() === lower);
|
|
32
|
+
if (exact) return exact;
|
|
33
|
+
const base = lower.split(/[-_]/)[0];
|
|
34
|
+
if (base === "zh") return "zh-CN";
|
|
35
|
+
if (base === "pt") return "pt-BR";
|
|
36
|
+
return APP_LANGUAGES.find((lang) => lang.toLowerCase() === base) ?? null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type Formatters = { num: (value: number) => string };
|
|
40
|
+
|
|
41
|
+
function en({ num }: Formatters) {
|
|
42
|
+
const count = (value: number, one: string, many: string) =>
|
|
43
|
+
`${num(value)} ${value === 1 ? one : many}`;
|
|
44
|
+
return {
|
|
45
|
+
common: {
|
|
46
|
+
activity: "Activity",
|
|
47
|
+
skills: "Skills",
|
|
48
|
+
mcp: "MCP",
|
|
49
|
+
agents: "Agents",
|
|
50
|
+
sessions: "Sessions",
|
|
51
|
+
prompts: "Prompts",
|
|
52
|
+
loading: "Loading…",
|
|
53
|
+
retry: "Retry",
|
|
54
|
+
loadFailed: "Couldn't load activity",
|
|
55
|
+
today: "Today",
|
|
56
|
+
now: "Now",
|
|
57
|
+
noSkillOrMcp: "No skill or MCP calls yet",
|
|
58
|
+
lastUsed: (time: string) => `Last ${time}`,
|
|
59
|
+
failed: (value: number) => `${num(value)} failed`,
|
|
60
|
+
openConversation: (label: string) => `Open conversation ${label}`,
|
|
61
|
+
openSkillFile: (name: string) => `Open ${name} SKILL.md`,
|
|
62
|
+
openSkillInPanel: "Open SKILL.md in panel",
|
|
63
|
+
showSkills: "Show skills",
|
|
64
|
+
showMcp: "Show MCP",
|
|
65
|
+
agentOnly: "Activity is only available for an agent",
|
|
66
|
+
},
|
|
67
|
+
units: {
|
|
68
|
+
agents: (value: number) => count(value, "agent", "agents"),
|
|
69
|
+
sessions: (value: number) => count(value, "session", "sessions"),
|
|
70
|
+
prompts: (value: number) => count(value, "prompt", "prompts"),
|
|
71
|
+
skills: (value: number) => count(value, "skill", "skills"),
|
|
72
|
+
mcp: (value: number) => `${num(value)} MCP`,
|
|
73
|
+
calls: (value: number) => count(value, "call", "calls"),
|
|
74
|
+
days: (value: number) => count(value, "day", "days"),
|
|
75
|
+
},
|
|
76
|
+
duration: {
|
|
77
|
+
underMinute: "<1 min",
|
|
78
|
+
minutes: (value: number) => `${num(value)} min`,
|
|
79
|
+
hours: (value: number) => `${num(value)} h`,
|
|
80
|
+
days: (value: number) => `${num(value)} days`,
|
|
81
|
+
months: (value: number) => `${num(value)} months`,
|
|
82
|
+
},
|
|
83
|
+
kpi: {
|
|
84
|
+
sessions: "Sessions",
|
|
85
|
+
prompts: "Prompts",
|
|
86
|
+
topProvider: "Top provider",
|
|
87
|
+
topModel: "Top model",
|
|
88
|
+
previous7Days: "vs prev. 7d",
|
|
89
|
+
previous7DaysBare: "prev. 7d",
|
|
90
|
+
skillCalls: "Skill calls",
|
|
91
|
+
mcpCalls: "MCP calls",
|
|
92
|
+
shellCalls: "Shell calls",
|
|
93
|
+
fileReads: "File reads",
|
|
94
|
+
fileWrites: "File writes",
|
|
95
|
+
toolsExplored: "Tools explored",
|
|
96
|
+
},
|
|
97
|
+
insights: {
|
|
98
|
+
title: "Activity insights",
|
|
99
|
+
activeDays: "Active days",
|
|
100
|
+
busiestDay: "Busiest day",
|
|
101
|
+
workspaces: "Workspaces",
|
|
102
|
+
codingVsChat: "Coding vs chat",
|
|
103
|
+
longestStreak: "Longest streak",
|
|
104
|
+
peakWeekday: "Peak weekday",
|
|
105
|
+
multiTurnSessions: "Multi-turn sessions",
|
|
106
|
+
avgSessionDuration: "Avg session duration",
|
|
107
|
+
codingShare: (pct: number) => `${num(pct)}% coding`,
|
|
108
|
+
},
|
|
109
|
+
global: {
|
|
110
|
+
allProviders: "All",
|
|
111
|
+
providerLabel: "Provider",
|
|
112
|
+
selectProvider: "Select provider",
|
|
113
|
+
closeProviderMenu: "Close provider menu",
|
|
114
|
+
metrics: { sessions: "Sessions", prompts: "Prompts", skills: "Skill calls", mcp: "MCP calls" },
|
|
115
|
+
previousMetric: "Previous metric",
|
|
116
|
+
nextMetric: "Next metric",
|
|
117
|
+
providerRanking: { title: "Providers", empty: "No provider activity yet" },
|
|
118
|
+
projectRanking: { title: "Projects", empty: "No project activity yet", other: "Other" },
|
|
119
|
+
ranking: { showMore: (value: number) => `Show ${num(value)} more`, showLess: "Show less" },
|
|
120
|
+
rankTitle: { skills: "Most used skills", mcp: "Most used MCP", models: "Most used models" },
|
|
121
|
+
rankEmpty: { skills: "No skills yet", mcp: "No MCP yet", models: "No models yet" },
|
|
122
|
+
rankShow: {
|
|
123
|
+
skills: "Show most used skills",
|
|
124
|
+
mcp: "Show most used MCP",
|
|
125
|
+
models: "Show most used models",
|
|
126
|
+
},
|
|
127
|
+
emptyTitle: "No usage yet",
|
|
128
|
+
emptyHint: "Sessions, prompts, skill and MCP calls will show up here",
|
|
129
|
+
},
|
|
130
|
+
heatmap: {
|
|
131
|
+
title: "Activity Calendar",
|
|
132
|
+
highlightMonth: (month: string) => `Highlight ${month}`,
|
|
133
|
+
weekContaining: (date: string) => `Week containing ${date}`,
|
|
134
|
+
through: (date: string) => `Through ${date}`,
|
|
135
|
+
},
|
|
136
|
+
creations: {
|
|
137
|
+
title: "Daily Activity",
|
|
138
|
+
empty: (days: number) => `No activity in the last ${num(days)} days`,
|
|
139
|
+
},
|
|
140
|
+
timeline: {
|
|
141
|
+
title: "Hourly Activity",
|
|
142
|
+
empty: "No activity yet",
|
|
143
|
+
},
|
|
144
|
+
workspace: {
|
|
145
|
+
empty: "No activity in this workspace yet",
|
|
146
|
+
searchPlaceholder: "Search agents",
|
|
147
|
+
searchLabel: "Search agents by title",
|
|
148
|
+
openSearch: "Search agents",
|
|
149
|
+
closeSearch: "Close agent search",
|
|
150
|
+
displayOptions: "Agent display options",
|
|
151
|
+
closeDisplayOptions: "Close agent display options",
|
|
152
|
+
noFilters: "No filters selected",
|
|
153
|
+
noMatches: "No matching agents",
|
|
154
|
+
previousPage: "Previous agents page",
|
|
155
|
+
nextPage: "Next agents page",
|
|
156
|
+
terminals: "Terminals",
|
|
157
|
+
showOutput: (name: string) => `Show output of ${name}`,
|
|
158
|
+
hideOutput: (name: string) => `Hide output of ${name}`,
|
|
159
|
+
closeTerminal: (name: string) => `Close ${name}`,
|
|
160
|
+
noOutput: "No output",
|
|
161
|
+
showTimeline: (title: string) => `Show ${title} as a timeline`,
|
|
162
|
+
showRanked: (title: string) => `Show ${title} ranked by calls`,
|
|
163
|
+
archive: (label: string) => `Archive ${label}`,
|
|
164
|
+
unarchive: (label: string) => `Unarchive ${label}`,
|
|
165
|
+
state: {
|
|
166
|
+
running: "running",
|
|
167
|
+
subagents: (value: number) => count(value, "subagent", "subagents"),
|
|
168
|
+
permissions: (value: number) => count(value, "pending permission", "pending permissions"),
|
|
169
|
+
failed: "failed",
|
|
170
|
+
finished: "turn finished, unread",
|
|
171
|
+
},
|
|
172
|
+
menu: { sort: "Sort", group: "Group", show: "Show", status: "Status", lifecycle: "Lifecycle" },
|
|
173
|
+
options: {
|
|
174
|
+
sort: { updated: "Updated", created: "Created", name: "Name", messages: "Prompts", status: "Status" },
|
|
175
|
+
group: { none: "None", provider: "Provider", status: "Status" },
|
|
176
|
+
show: { provider: "Provider", calls: "Calls", messages: "Prompts", updated: "Updated", prompt: "Latest prompt" },
|
|
177
|
+
status: { active: "Active", archived: "Archived" },
|
|
178
|
+
lifecycle: { idle: "Idle", running: "Running", error: "Error", closed: "Closed" },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
attention: {
|
|
182
|
+
title: "Needs attention",
|
|
183
|
+
empty: "No other agents need attention",
|
|
184
|
+
agentOnly: "Attention is only available for an agent",
|
|
185
|
+
},
|
|
186
|
+
commands: {
|
|
187
|
+
agentActivity: "Agent Activity",
|
|
188
|
+
workspaceActivity: "Workspace Activity",
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export type Messages = ReturnType<typeof en>;
|
|
194
|
+
|
|
195
|
+
function zhCN({ num }: Formatters): Messages {
|
|
196
|
+
return {
|
|
197
|
+
common: {
|
|
198
|
+
activity: "Activity",
|
|
199
|
+
skills: "Skill",
|
|
200
|
+
mcp: "MCP",
|
|
201
|
+
agents: "Agent",
|
|
202
|
+
sessions: "会话",
|
|
203
|
+
prompts: "提示词",
|
|
204
|
+
loading: "加载中…",
|
|
205
|
+
retry: "重试",
|
|
206
|
+
loadFailed: "无法加载 Activity",
|
|
207
|
+
today: "今天",
|
|
208
|
+
now: "现在",
|
|
209
|
+
noSkillOrMcp: "还没有 Skill 或 MCP 调用",
|
|
210
|
+
lastUsed: (time: string) => `最近 ${time}`,
|
|
211
|
+
failed: (value: number) => `${num(value)} 次失败`,
|
|
212
|
+
openConversation: (label: string) => `打开会话 ${label}`,
|
|
213
|
+
openSkillFile: (name: string) => `打开 ${name} 的 SKILL.md`,
|
|
214
|
+
openSkillInPanel: "在面板中打开 SKILL.md",
|
|
215
|
+
showSkills: "显示 Skill",
|
|
216
|
+
showMcp: "显示 MCP",
|
|
217
|
+
agentOnly: "Activity 仅适用于 Agent",
|
|
218
|
+
},
|
|
219
|
+
units: {
|
|
220
|
+
agents: (value: number) => `${num(value)} 个 Agent`,
|
|
221
|
+
sessions: (value: number) => `${num(value)} 个会话`,
|
|
222
|
+
prompts: (value: number) => `${num(value)} 条提示词`,
|
|
223
|
+
skills: (value: number) => `${num(value)} 次 Skill`,
|
|
224
|
+
mcp: (value: number) => `${num(value)} 次 MCP`,
|
|
225
|
+
calls: (value: number) => `${num(value)} 次调用`,
|
|
226
|
+
days: (value: number) => `${num(value)} 天`,
|
|
227
|
+
},
|
|
228
|
+
duration: {
|
|
229
|
+
underMinute: "<1 分钟",
|
|
230
|
+
minutes: (value: number) => `${num(value)} 分钟`,
|
|
231
|
+
hours: (value: number) => `${num(value)} 小时`,
|
|
232
|
+
days: (value: number) => `${num(value)} 天`,
|
|
233
|
+
months: (value: number) => `${num(value)} 个月`,
|
|
234
|
+
},
|
|
235
|
+
kpi: {
|
|
236
|
+
sessions: "会话",
|
|
237
|
+
prompts: "提示词",
|
|
238
|
+
topProvider: "常用 Provider",
|
|
239
|
+
topModel: "常用模型",
|
|
240
|
+
previous7Days: "较前 7 天",
|
|
241
|
+
previous7DaysBare: "前 7 天",
|
|
242
|
+
skillCalls: "Skill 调用",
|
|
243
|
+
mcpCalls: "MCP 调用",
|
|
244
|
+
shellCalls: "Shell 调用",
|
|
245
|
+
fileReads: "文件读取",
|
|
246
|
+
fileWrites: "文件写入",
|
|
247
|
+
toolsExplored: "用过的工具",
|
|
248
|
+
},
|
|
249
|
+
insights: {
|
|
250
|
+
title: "Activity 洞察",
|
|
251
|
+
activeDays: "活跃天数",
|
|
252
|
+
busiestDay: "最忙的一天",
|
|
253
|
+
workspaces: "工作区",
|
|
254
|
+
codingVsChat: "编码 vs 对话",
|
|
255
|
+
longestStreak: "最长连续",
|
|
256
|
+
peakWeekday: "最活跃星期",
|
|
257
|
+
multiTurnSessions: "多轮会话",
|
|
258
|
+
avgSessionDuration: "平均会话时长",
|
|
259
|
+
codingShare: (pct: number) => `${num(pct)}% 编码`,
|
|
260
|
+
},
|
|
261
|
+
global: {
|
|
262
|
+
allProviders: "全部",
|
|
263
|
+
providerLabel: "Provider",
|
|
264
|
+
selectProvider: "选择 Provider",
|
|
265
|
+
closeProviderMenu: "关闭 Provider 菜单",
|
|
266
|
+
metrics: { sessions: "会话", prompts: "提示词", skills: "Skill 调用", mcp: "MCP 调用" },
|
|
267
|
+
previousMetric: "上一个指标",
|
|
268
|
+
nextMetric: "下一个指标",
|
|
269
|
+
providerRanking: { title: "Provider", empty: "还没有 Provider 活动" },
|
|
270
|
+
projectRanking: { title: "项目", empty: "还没有项目活动", other: "其他" },
|
|
271
|
+
ranking: { showMore: (value: number) => `展开剩余 ${num(value)} 项`, showLess: "收起" },
|
|
272
|
+
rankTitle: { skills: "常用 Skill", mcp: "常用 MCP", models: "常用模型" },
|
|
273
|
+
rankEmpty: { skills: "还没有 Skill", mcp: "还没有 MCP", models: "还没有模型" },
|
|
274
|
+
rankShow: { skills: "显示常用 Skill", mcp: "显示常用 MCP", models: "显示常用模型" },
|
|
275
|
+
emptyTitle: "还没有使用记录",
|
|
276
|
+
emptyHint: "会话、提示词、Skill 和 MCP 调用会显示在这里",
|
|
277
|
+
},
|
|
278
|
+
heatmap: {
|
|
279
|
+
title: "活动日历",
|
|
280
|
+
highlightMonth: (month: string) => `高亮 ${month}`,
|
|
281
|
+
weekContaining: (date: string) => `${date} 所在周`,
|
|
282
|
+
through: (date: string) => `截至 ${date}`,
|
|
283
|
+
},
|
|
284
|
+
creations: {
|
|
285
|
+
title: "每日活动",
|
|
286
|
+
empty: (days: number) => `最近 ${num(days)} 天没有活动`,
|
|
287
|
+
},
|
|
288
|
+
timeline: {
|
|
289
|
+
title: "每小时活动",
|
|
290
|
+
empty: "还没有活动",
|
|
291
|
+
},
|
|
292
|
+
workspace: {
|
|
293
|
+
empty: "此工作区还没有活动",
|
|
294
|
+
searchPlaceholder: "搜索 Agent",
|
|
295
|
+
searchLabel: "按标题搜索 Agent",
|
|
296
|
+
openSearch: "搜索 Agent",
|
|
297
|
+
closeSearch: "关闭 Agent 搜索",
|
|
298
|
+
displayOptions: "Agent 显示选项",
|
|
299
|
+
closeDisplayOptions: "关闭 Agent 显示选项",
|
|
300
|
+
noFilters: "未选择筛选条件",
|
|
301
|
+
noMatches: "没有匹配的 Agent",
|
|
302
|
+
previousPage: "上一页 Agent",
|
|
303
|
+
nextPage: "下一页 Agent",
|
|
304
|
+
terminals: "终端",
|
|
305
|
+
showOutput: (name: string) => `显示 ${name} 的输出`,
|
|
306
|
+
hideOutput: (name: string) => `隐藏 ${name} 的输出`,
|
|
307
|
+
closeTerminal: (name: string) => `关闭 ${name}`,
|
|
308
|
+
noOutput: "无输出",
|
|
309
|
+
showTimeline: (title: string) => `以时间线显示 ${title}`,
|
|
310
|
+
showRanked: (title: string) => `按调用次数排序 ${title}`,
|
|
311
|
+
archive: (label: string) => `归档 ${label}`,
|
|
312
|
+
unarchive: (label: string) => `取消归档 ${label}`,
|
|
313
|
+
state: {
|
|
314
|
+
running: "运行中",
|
|
315
|
+
subagents: (value: number) => `${num(value)} 个子 Agent`,
|
|
316
|
+
permissions: (value: number) => `${num(value)} 个待处理权限`,
|
|
317
|
+
failed: "失败",
|
|
318
|
+
finished: "本轮已完成,未读",
|
|
319
|
+
},
|
|
320
|
+
menu: { sort: "排序", group: "分组", show: "显示", status: "状态", lifecycle: "生命周期" },
|
|
321
|
+
options: {
|
|
322
|
+
sort: { updated: "更新时间", created: "创建时间", name: "名称", messages: "提示词", status: "状态" },
|
|
323
|
+
group: { none: "无", provider: "Provider", status: "状态" },
|
|
324
|
+
show: { provider: "Provider", calls: "调用", messages: "提示词", updated: "更新时间", prompt: "最新提示词" },
|
|
325
|
+
status: { active: "活跃", archived: "已归档" },
|
|
326
|
+
lifecycle: { idle: "空闲", running: "运行中", error: "错误", closed: "已关闭" },
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
attention: {
|
|
330
|
+
title: "需要关注",
|
|
331
|
+
empty: "没有其他需要关注的 Agent",
|
|
332
|
+
agentOnly: "仅在 Agent 中可用",
|
|
333
|
+
},
|
|
334
|
+
commands: {
|
|
335
|
+
agentActivity: "Agent Activity",
|
|
336
|
+
workspaceActivity: "工作区 Activity",
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const CATALOGS: Partial<Record<AppLanguage, (fmt: Formatters) => Messages>> = {
|
|
342
|
+
en,
|
|
343
|
+
"zh-CN": zhCN,
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const cache = new Map<string, Messages>();
|
|
347
|
+
|
|
348
|
+
/** Copy for `locale`; languages without a catalog fall back to English text. */
|
|
349
|
+
export function messagesFor(locale: string = "en"): Messages {
|
|
350
|
+
const cached = cache.get(locale);
|
|
351
|
+
if (cached) return cached;
|
|
352
|
+
const lang = resolveAppLanguage(locale);
|
|
353
|
+
const factory = CATALOGS[lang] ?? en;
|
|
354
|
+
let numberLocale = locale;
|
|
355
|
+
try {
|
|
356
|
+
numberLocale = Intl.getCanonicalLocales(locale)[0] ?? "en";
|
|
357
|
+
} catch {
|
|
358
|
+
numberLocale = "en";
|
|
359
|
+
}
|
|
360
|
+
const messages = factory({ num: (value) => value.toLocaleString(numberLocale) });
|
|
361
|
+
cache.set(locale, messages);
|
|
362
|
+
return messages;
|
|
363
|
+
}
|
package/shared/insights.test.ts
CHANGED
|
@@ -27,13 +27,15 @@ function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem,
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
describe("buildActivityInsights", () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// 2026-03-07 Sat, 2026-03-09 Mon — Mon carries more volume → Peak weekday Mon.
|
|
31
|
+
const days = [
|
|
32
|
+
{ date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
|
|
33
|
+
{ date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
it("returns the 8 habit / average rows (072)", () => {
|
|
35
37
|
const rows = buildActivityInsights({
|
|
36
|
-
days,
|
|
38
|
+
days: [...days, { date: "2026-03-10", skills: 0, mcp: 1, agents: 0, messages: 0, total: 1 }],
|
|
37
39
|
summary: {
|
|
38
40
|
skills: 2,
|
|
39
41
|
mcp: 3,
|
|
@@ -43,6 +45,8 @@ describe("buildActivityInsights", () => {
|
|
|
43
45
|
chatAgents: 1,
|
|
44
46
|
},
|
|
45
47
|
workspaces: 7,
|
|
48
|
+
averageSessionMs: 18 * 60_000 + 20_000,
|
|
49
|
+
multiTurn: { multiTurnSessions: 2, promptedSessions: 3 },
|
|
46
50
|
locale: "en",
|
|
47
51
|
});
|
|
48
52
|
|
|
@@ -52,48 +56,48 @@ describe("buildActivityInsights", () => {
|
|
|
52
56
|
[
|
|
53
57
|
"Active days",
|
|
54
58
|
"Busiest day",
|
|
59
|
+
"Longest streak",
|
|
60
|
+
"Peak weekday",
|
|
55
61
|
"Workspaces",
|
|
56
|
-
"Messages",
|
|
57
|
-
"Skill calls",
|
|
58
|
-
"MCP calls",
|
|
59
|
-
"Messages per agent",
|
|
60
62
|
"Coding vs chat",
|
|
63
|
+
"Multi-turn sessions",
|
|
64
|
+
"Avg session duration",
|
|
61
65
|
],
|
|
62
66
|
);
|
|
63
|
-
assert.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
assert.equal(rows[5]?.value, "3");
|
|
69
|
-
assert.equal(rows[6]?.value, "2.8");
|
|
70
|
-
// 3 coding / (3+1) active → 75%
|
|
71
|
-
assert.equal(rows[7]?.value, "75% coding");
|
|
67
|
+
assert.deepEqual(
|
|
68
|
+
rows.map((r) => r.value),
|
|
69
|
+
// 3 coding / (3+1) active → 75%; Mar 9–10 streak; 2 of 3 prompted sessions multi-turn.
|
|
70
|
+
["3", "Mar 9 · 10 prompts", "2 days", "Monday", "7", "75% coding", "67%", "18 min"],
|
|
71
|
+
);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it("uses dashes for
|
|
74
|
+
it("uses dashes for empty data and falls back busiest day", () => {
|
|
75
75
|
const rows = buildActivityInsights({
|
|
76
76
|
days: [{ date: "2026-03-08", skills: 3, mcp: 1, agents: 2, messages: 0, total: 4 }],
|
|
77
77
|
summary: { skills: 3, mcp: 1, agents: 2, messages: 0, codingAgents: 0, chatAgents: 0 },
|
|
78
78
|
workspaces: 0,
|
|
79
79
|
locale: "en",
|
|
80
80
|
});
|
|
81
|
-
|
|
82
|
-
assert.equal(
|
|
83
|
-
assert.equal(
|
|
84
|
-
assert.equal(
|
|
85
|
-
|
|
81
|
+
const value = (label: string) => rows.find((r) => r.label === label)?.value;
|
|
82
|
+
assert.equal(value("Busiest day"), "Mar 8 · 4 calls");
|
|
83
|
+
assert.equal(value("Peak weekday"), "Sunday");
|
|
84
|
+
assert.equal(value("Longest streak"), "1 day");
|
|
85
|
+
assert.equal(value("Multi-turn sessions"), "—");
|
|
86
|
+
assert.equal(value("Avg session duration"), "—");
|
|
87
|
+
assert.equal(value("Coding vs chat"), "—");
|
|
88
|
+
assert.equal(value("Workspaces"), "0");
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
const rows = buildActivityInsights({
|
|
90
|
+
const empty = buildActivityInsights({
|
|
89
91
|
days: [],
|
|
90
|
-
summary: { skills: 0, mcp: 0, agents:
|
|
92
|
+
summary: { skills: 0, mcp: 0, agents: 0, messages: 0 },
|
|
91
93
|
workspaces: 0,
|
|
94
|
+
averageSessionMs: null,
|
|
92
95
|
locale: "en",
|
|
93
96
|
});
|
|
94
|
-
assert.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
empty.map((r) => r.value),
|
|
99
|
+
["0", "—", "—", "—", "0", "—", "—", "—"],
|
|
100
|
+
);
|
|
97
101
|
});
|
|
98
102
|
});
|
|
99
103
|
|
|
@@ -101,8 +105,11 @@ describe("buildActivityKpi", () => {
|
|
|
101
105
|
const codex = provider({
|
|
102
106
|
provider: "codex",
|
|
103
107
|
label: "Codex",
|
|
104
|
-
messageCount:
|
|
105
|
-
models: [
|
|
108
|
+
messageCount: 12,
|
|
109
|
+
models: [
|
|
110
|
+
{ model: "gpt-5.4", count: 9 },
|
|
111
|
+
{ model: "gpt-5.4-mini", count: 3 },
|
|
112
|
+
],
|
|
106
113
|
});
|
|
107
114
|
const claude = provider({
|
|
108
115
|
provider: "claude",
|
|
@@ -110,76 +117,108 @@ describe("buildActivityKpi", () => {
|
|
|
110
117
|
messageCount: 4,
|
|
111
118
|
models: [{ model: "opus", count: 4 }],
|
|
112
119
|
});
|
|
113
|
-
|
|
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
|
+
it("shows sessions, prompts and shares (069 / 070 / 072)", () => {
|
|
120
121
|
const rows = buildActivityKpi({
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
sessions: 12345,
|
|
123
|
+
messages: 1605,
|
|
123
124
|
locale: "en",
|
|
124
|
-
longestStreak: 6,
|
|
125
|
-
longestAgent: { durationMs: 277.7 * 3_600_000, active: false },
|
|
126
125
|
providers: [codex, claude],
|
|
126
|
+
allProviders: [codex, claude],
|
|
127
127
|
providerFilter: "all",
|
|
128
128
|
});
|
|
129
129
|
assert.deepEqual(
|
|
130
130
|
rows.map((r) => r.label),
|
|
131
|
-
["
|
|
131
|
+
["Sessions", "Prompts", "Top provider", "Top model"],
|
|
132
132
|
);
|
|
133
|
-
assert.equal(rows[0]?.value, "12
|
|
134
|
-
assert.equal(rows[1]?.value, "
|
|
135
|
-
assert.equal(rows[2]?.value, "Codex");
|
|
136
|
-
|
|
137
|
-
assert.equal(rows[
|
|
138
|
-
assert.equal(rows
|
|
133
|
+
assert.equal(rows[0]?.value, "12,345");
|
|
134
|
+
assert.equal(rows[1]?.value, "1,605");
|
|
135
|
+
assert.equal(rows[2]?.value, "Codex · 75%");
|
|
136
|
+
// gpt-5.4 9 of 16 model messages → 56%
|
|
137
|
+
assert.equal(rows[3]?.value, "Gpt 5.4 · 56%");
|
|
138
|
+
assert.equal(rows.length, 4);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it("
|
|
141
|
+
it("scopes shares to the selected provider", () => {
|
|
142
142
|
const rows = buildActivityKpi({
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
sessions: 0,
|
|
144
|
+
messages: 4,
|
|
145
145
|
locale: "en",
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
providers: [claude],
|
|
147
|
+
allProviders: [codex, claude],
|
|
148
|
+
providerFilter: "claude",
|
|
149
|
+
});
|
|
150
|
+
assert.equal(rows[2]?.value, "Claude · 25%");
|
|
151
|
+
assert.equal(rows[3]?.value, "Opus · 100%");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("tolerates missing data", () => {
|
|
155
|
+
const empty = buildActivityKpi({
|
|
156
|
+
sessions: 0,
|
|
157
|
+
messages: 0,
|
|
158
|
+
locale: "en",
|
|
159
|
+
providers: [],
|
|
160
|
+
allProviders: [],
|
|
149
161
|
providerFilter: "all",
|
|
150
162
|
});
|
|
151
|
-
assert.equal(
|
|
152
|
-
assert.equal(
|
|
163
|
+
assert.equal(empty[0]?.value, "0");
|
|
164
|
+
assert.equal(empty[2]?.value, "—");
|
|
165
|
+
assert.equal(empty[3]?.value, "—");
|
|
153
166
|
});
|
|
154
167
|
|
|
155
|
-
it("
|
|
168
|
+
it("compares each KPI against the preceding seven days", () => {
|
|
169
|
+
const current = [
|
|
170
|
+
provider({ provider: "codex", label: "Codex", agentCount: 10, messageCount: 9, models: [{ model: "gpt-5.4", count: 9 }] }),
|
|
171
|
+
provider({ provider: "claude", label: "Claude", agentCount: 2, messageCount: 1, models: [{ model: "opus", count: 1 }] }),
|
|
172
|
+
];
|
|
173
|
+
const previous = [
|
|
174
|
+
provider({ provider: "codex", label: "Codex", agentCount: 6, messageCount: 4, models: [{ model: "gpt-5.4", count: 4 }] }),
|
|
175
|
+
provider({ provider: "claude", label: "Claude", agentCount: 4, messageCount: 6, models: [{ model: "opus", count: 6 }] }),
|
|
176
|
+
];
|
|
156
177
|
const rows = buildActivityKpi({
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
sessions: 100,
|
|
179
|
+
messages: 160,
|
|
180
|
+
providers: [codex, claude],
|
|
181
|
+
allProviders: [codex, claude],
|
|
182
|
+
providerFilter: "all",
|
|
159
183
|
locale: "en",
|
|
160
|
-
|
|
161
|
-
longestAgent: null,
|
|
162
|
-
providers: [codex],
|
|
163
|
-
providerFilter: "codex",
|
|
184
|
+
comparison: { current, previous },
|
|
164
185
|
});
|
|
165
|
-
assert.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
186
|
+
assert.deepEqual(rows.map((row) => row.comparison?.text), [
|
|
187
|
+
"↑20% vs prev. 7d",
|
|
188
|
+
"→0% vs prev. 7d",
|
|
189
|
+
"Claude prev. 7d",
|
|
190
|
+
"Opus prev. 7d",
|
|
191
|
+
]);
|
|
170
192
|
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
const filtered = buildActivityKpi({
|
|
194
|
+
sessions: 20,
|
|
195
|
+
messages: 30,
|
|
196
|
+
providers: [claude],
|
|
197
|
+
allProviders: [codex, claude],
|
|
198
|
+
providerFilter: "claude",
|
|
174
199
|
locale: "en",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
comparison: { current, previous },
|
|
201
|
+
});
|
|
202
|
+
assert.deepEqual(filtered.map((row) => row.comparison?.text), [
|
|
203
|
+
"↓50% vs prev. 7d",
|
|
204
|
+
"↓83% vs prev. 7d",
|
|
205
|
+
"Claude prev. 7d",
|
|
206
|
+
"Opus prev. 7d",
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("leaves percentage undefined when the preceding window has no baseline", () => {
|
|
211
|
+
const rows = buildActivityKpi({
|
|
212
|
+
sessions: 1,
|
|
213
|
+
messages: 1,
|
|
214
|
+
providers: [codex],
|
|
215
|
+
allProviders: [codex],
|
|
178
216
|
providerFilter: "all",
|
|
217
|
+
comparison: { current: [{ ...codex, agentCount: 1 }], previous: [] },
|
|
179
218
|
});
|
|
180
|
-
assert.equal(
|
|
181
|
-
assert.equal(
|
|
182
|
-
assert.equal(
|
|
183
|
-
assert.equal(
|
|
219
|
+
assert.equal(rows[0]?.comparison?.text, "— vs prev. 7d");
|
|
220
|
+
assert.equal(rows[1]?.comparison?.direction, "unknown");
|
|
221
|
+
assert.equal(rows[2]?.comparison?.text, "— prev. 7d");
|
|
222
|
+
assert.equal(rows[3]?.comparison?.text, "— prev. 7d");
|
|
184
223
|
});
|
|
185
224
|
});
|