@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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import type { PluginHookAgent, PluginHookContext } from "@getpaseo/plugin/server";
|
|
7
|
+
import type { AgentTimelineItem } from "./host-types.ts";
|
|
8
|
+
import { createUsageStore } from "./store.ts";
|
|
9
|
+
import { TURN_TAIL_LIMIT, ingestTurnAfter, refetchTimelineTail } from "./turn-ingest.ts";
|
|
10
|
+
|
|
11
|
+
const agent: PluginHookAgent = {
|
|
12
|
+
id: "agent-1",
|
|
13
|
+
workspaceId: "ws-1",
|
|
14
|
+
parentAgentId: null,
|
|
15
|
+
provider: "claude",
|
|
16
|
+
cwd: "/repo",
|
|
17
|
+
title: "turn ingest agent",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type RefetchOptions = {
|
|
21
|
+
projection?: string;
|
|
22
|
+
direction?: string;
|
|
23
|
+
limit?: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function fakePaseo(
|
|
27
|
+
entries: Array<{ item: AgentTimelineItem }>,
|
|
28
|
+
options: { error?: string; model?: string | null } = {},
|
|
29
|
+
) {
|
|
30
|
+
const requests: RefetchOptions[] = [];
|
|
31
|
+
const refetch = async (input: RefetchOptions) => {
|
|
32
|
+
requests.push(input);
|
|
33
|
+
return { entries, error: options.error ?? null };
|
|
34
|
+
};
|
|
35
|
+
const snapshot = options.model ? { model: options.model } : null;
|
|
36
|
+
const paseo = {
|
|
37
|
+
agents: {
|
|
38
|
+
ref: () => ({
|
|
39
|
+
current: () => snapshot,
|
|
40
|
+
refresh: async () => snapshot,
|
|
41
|
+
timeline: { refetch },
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
} as unknown as PluginHookContext["paseo"];
|
|
45
|
+
return { paseo, requests };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function withStore(run: (store: ReturnType<typeof createUsageStore>) => Promise<void>) {
|
|
49
|
+
return async () => {
|
|
50
|
+
const dir = mkdtempSync(join(tmpdir(), "activity-turn-ingest-"));
|
|
51
|
+
const store = createUsageStore({ dir, driver: "jsonl" });
|
|
52
|
+
try {
|
|
53
|
+
await run(store);
|
|
54
|
+
} finally {
|
|
55
|
+
store.close();
|
|
56
|
+
rmSync(dir, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const toolCall = (callId: string, name: string, detail: AgentTimelineItem | undefined): AgentTimelineItem => ({
|
|
62
|
+
type: "tool_call",
|
|
63
|
+
callId,
|
|
64
|
+
name,
|
|
65
|
+
detail: detail as never,
|
|
66
|
+
status: "completed",
|
|
67
|
+
error: null,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("refetchTimelineTail reads canonical recent history", async () => {
|
|
71
|
+
const items: AgentTimelineItem[] = [{ type: "user_message", text: "hi" }];
|
|
72
|
+
const { paseo, requests } = fakePaseo(items.map((item) => ({ item })));
|
|
73
|
+
|
|
74
|
+
const timeline = await refetchTimelineTail(paseo, agent.id);
|
|
75
|
+
|
|
76
|
+
assert.deepEqual(requests, [
|
|
77
|
+
{ projection: "canonical", direction: "tail", limit: TURN_TAIL_LIMIT },
|
|
78
|
+
]);
|
|
79
|
+
assert.deepEqual(timeline, items);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("refetchTimelineTail surfaces daemon errors", async () => {
|
|
83
|
+
const { paseo } = fakePaseo([], { error: "timeline unavailable" });
|
|
84
|
+
|
|
85
|
+
await assert.rejects(() => refetchTimelineTail(paseo, agent.id), /timeline unavailable/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test(
|
|
89
|
+
"ingestTurnAfter records tool calls from the refetched tail",
|
|
90
|
+
withStore(async (store) => {
|
|
91
|
+
const { paseo } = fakePaseo(
|
|
92
|
+
[
|
|
93
|
+
{ item: { type: "user_message", messageId: "m-1", text: "hi" } },
|
|
94
|
+
{
|
|
95
|
+
item: {
|
|
96
|
+
type: "tool_call",
|
|
97
|
+
callId: "call-1",
|
|
98
|
+
name: "Skill",
|
|
99
|
+
detail: { type: "plain_text", label: "paseo-plugin" },
|
|
100
|
+
status: "completed",
|
|
101
|
+
error: null,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
item: {
|
|
106
|
+
type: "tool_call",
|
|
107
|
+
callId: "call-2",
|
|
108
|
+
name: "Bash",
|
|
109
|
+
detail: { type: "shell", command: "git status", exitCode: 0 },
|
|
110
|
+
status: "completed",
|
|
111
|
+
error: null,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
{ model: "claude-sonnet-4" },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const rows = await ingestTurnAfter(store, paseo, agent, { homeDir: "/home/tester" });
|
|
119
|
+
|
|
120
|
+
assert.equal(rows, 2);
|
|
121
|
+
const stored = store.select({ agentId: agent.id });
|
|
122
|
+
assert.deepEqual(stored.map((row) => row.callId).sort(), ["call-1", "call-2"]);
|
|
123
|
+
assert.equal(store.getAgent(agent.id)?.title, "turn ingest agent");
|
|
124
|
+
assert.equal(store.selectUserMessages({ agentId: agent.id })[0]?.model, "claude-sonnet-4");
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
test(
|
|
129
|
+
"ingestTurnAfter keeps terminal calls and their stored classification",
|
|
130
|
+
withStore(async (store) => {
|
|
131
|
+
const first = fakePaseo([
|
|
132
|
+
{
|
|
133
|
+
item: {
|
|
134
|
+
type: "tool_call",
|
|
135
|
+
callId: "call-1",
|
|
136
|
+
name: "Skill",
|
|
137
|
+
detail: { type: "plain_text", label: "paseo-plugin" },
|
|
138
|
+
status: "completed",
|
|
139
|
+
error: null,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
await ingestTurnAfter(store, first.paseo, agent, { homeDir: "/home/tester" });
|
|
144
|
+
const before = store.getRow(agent.id, "call-1");
|
|
145
|
+
assert.equal(before?.category, "skill");
|
|
146
|
+
|
|
147
|
+
// A later snapshot carries the same terminal call with a different detail.
|
|
148
|
+
const second = fakePaseo([
|
|
149
|
+
{
|
|
150
|
+
item: {
|
|
151
|
+
type: "tool_call",
|
|
152
|
+
callId: "call-1",
|
|
153
|
+
name: "Bash",
|
|
154
|
+
detail: { type: "shell", command: "git status", exitCode: 0 },
|
|
155
|
+
status: "completed",
|
|
156
|
+
error: null,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
]);
|
|
160
|
+
const rows = await ingestTurnAfter(store, second.paseo, agent, { homeDir: "/home/tester" });
|
|
161
|
+
|
|
162
|
+
assert.equal(rows, 0);
|
|
163
|
+
assert.deepEqual(store.getRow(agent.id, "call-1"), before);
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
test(
|
|
168
|
+
"ingestTurnAfter preserves the registry creation time across turns",
|
|
169
|
+
withStore(async (store) => {
|
|
170
|
+
const { paseo } = fakePaseo([], {});
|
|
171
|
+
await ingestTurnAfter(store, paseo, agent);
|
|
172
|
+
const createdAt = store.getAgent(agent.id)?.createdAt;
|
|
173
|
+
assert.ok(createdAt);
|
|
174
|
+
|
|
175
|
+
await ingestTurnAfter(store, paseo, { ...agent, title: "renamed" });
|
|
176
|
+
|
|
177
|
+
assert.equal(store.getAgent(agent.id)?.createdAt, createdAt);
|
|
178
|
+
assert.equal(store.getAgent(agent.id)?.title, "renamed");
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import type { PluginHookAgent, PluginHookContext } from "@getpaseo/plugin/server";
|
|
3
|
+
import { agentRowFromHook } from "./agents.ts";
|
|
4
|
+
import type { AgentTimelineItem } from "./host-types.ts";
|
|
5
|
+
import { ingestTimeline, ingestUserMessages } from "./ingest.ts";
|
|
6
|
+
import { resolveAgentModel } from "./resolve-model.ts";
|
|
7
|
+
import type { UsageStore } from "./store.ts";
|
|
8
|
+
|
|
9
|
+
/** Recent history is enough for immediacy; the background scan owns the full timeline. */
|
|
10
|
+
export const TURN_TAIL_LIMIT = 500;
|
|
11
|
+
|
|
12
|
+
type PaseoApi = PluginHookContext["paseo"];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Paseo 0.13+ sends an empty `timeline` in `agent.turn.after`, so read the recent
|
|
16
|
+
* history back through the SDK instead of trusting the hook payload.
|
|
17
|
+
*/
|
|
18
|
+
export async function refetchTimelineTail(
|
|
19
|
+
paseo: PaseoApi,
|
|
20
|
+
agentId: string,
|
|
21
|
+
limit: number = TURN_TAIL_LIMIT,
|
|
22
|
+
): Promise<AgentTimelineItem[]> {
|
|
23
|
+
const page = await paseo.agents.ref(agentId).timeline.refetch({
|
|
24
|
+
projection: "canonical",
|
|
25
|
+
direction: "tail",
|
|
26
|
+
limit,
|
|
27
|
+
});
|
|
28
|
+
if (page.error) throw new Error(page.error);
|
|
29
|
+
return page.entries.map(({ item }) => item);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IngestTurnAfterOptions {
|
|
33
|
+
homeDir?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Ingest one finished turn from a freshly read timeline tail.
|
|
38
|
+
*
|
|
39
|
+
* Returns the number of tool-call rows upserted. Calls already stored in a
|
|
40
|
+
* terminal status cannot change from a snapshot, so they are skipped.
|
|
41
|
+
*/
|
|
42
|
+
export async function ingestTurnAfter(
|
|
43
|
+
store: UsageStore,
|
|
44
|
+
paseo: PaseoApi,
|
|
45
|
+
agent: PluginHookAgent,
|
|
46
|
+
options: IngestTurnAfterOptions = {},
|
|
47
|
+
): Promise<number> {
|
|
48
|
+
const existing = store.getAgent(agent.id);
|
|
49
|
+
store.upsertAgents([
|
|
50
|
+
agentRowFromHook(agent, {
|
|
51
|
+
createdAt: existing?.createdAt,
|
|
52
|
+
archivedAt: existing?.archivedAt,
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const model = await resolveAgentModel(paseo, agent.id);
|
|
57
|
+
const timeline = await refetchTimelineTail(paseo, agent.id);
|
|
58
|
+
store.upsertUserMessages(ingestUserMessages(timeline, agent, { model }));
|
|
59
|
+
store.pruneReplayDuplicateMessages(agent.id);
|
|
60
|
+
|
|
61
|
+
const settled = store.terminalCallIds(agent.id);
|
|
62
|
+
const pending = timeline.filter(
|
|
63
|
+
(item) => item.type !== "tool_call" || !settled.has(item.callId),
|
|
64
|
+
);
|
|
65
|
+
const rows = ingestTimeline(pending, agent, null, {
|
|
66
|
+
homeDir: options.homeDir ?? homedir(),
|
|
67
|
+
});
|
|
68
|
+
if (rows.length === 0) return 0;
|
|
69
|
+
store.upsertMany(rows);
|
|
70
|
+
return rows.length;
|
|
71
|
+
}
|
package/shared/activity.test.ts
CHANGED
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
activityLevel,
|
|
5
5
|
buildActivityCalendar,
|
|
6
6
|
buildAgentCreationBuckets,
|
|
7
|
+
buildDailyMetricBuckets,
|
|
7
8
|
computeStreaks,
|
|
9
|
+
metricValue,
|
|
10
|
+
stepMetric,
|
|
8
11
|
rankCreationProviders,
|
|
9
12
|
stackCreationProviders,
|
|
10
13
|
} from "./activity.ts";
|
|
@@ -211,3 +214,36 @@ describe("agent creation buckets (051)", () => {
|
|
|
211
214
|
);
|
|
212
215
|
});
|
|
213
216
|
});
|
|
217
|
+
|
|
218
|
+
describe("activity metrics (070)", () => {
|
|
219
|
+
it("reads each metric and cycles in both directions", () => {
|
|
220
|
+
const value = { agents: 1, messages: 2, skills: 3, mcp: 4 };
|
|
221
|
+
assert.deepEqual(
|
|
222
|
+
(["sessions", "prompts", "skills", "mcp"] as const).map((metric) => metricValue(value, metric)),
|
|
223
|
+
[1, 2, 3, 4],
|
|
224
|
+
);
|
|
225
|
+
assert.equal(stepMetric("sessions", 1), "prompts");
|
|
226
|
+
assert.equal(stepMetric("mcp", 1), "sessions");
|
|
227
|
+
assert.equal(stepMetric("sessions", -1), "mcp");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("buckets daily activity by metric over the fixed window", () => {
|
|
231
|
+
const today = new Date(2026, 2, 9);
|
|
232
|
+
const buckets = buildDailyMetricBuckets(
|
|
233
|
+
[
|
|
234
|
+
{ date: "2026-03-06", skills: 9, mcp: 0, agents: 9, messages: 9, total: 27 },
|
|
235
|
+
{ date: "2026-03-08", skills: 2, mcp: 1, agents: 1, messages: 5, total: 9 },
|
|
236
|
+
],
|
|
237
|
+
"prompts",
|
|
238
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
239
|
+
);
|
|
240
|
+
assert.deepEqual(
|
|
241
|
+
buckets.map((bucket) => [bucket.key, bucket.count, bucket.providers.length]),
|
|
242
|
+
[
|
|
243
|
+
["2026-03-07", 0, 0],
|
|
244
|
+
["2026-03-08", 5, 0],
|
|
245
|
+
["2026-03-09", 0, 0],
|
|
246
|
+
],
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
});
|
package/shared/activity.ts
CHANGED
|
@@ -32,6 +32,26 @@ function addDays(date: Date, days: number): Date {
|
|
|
32
32
|
|
|
33
33
|
export type HeatmapMode = "daily" | "weekly" | "cumulative";
|
|
34
34
|
|
|
35
|
+
/** Chart metric switch (070); `sessions` = agent creations, `prompts` = user messages. */
|
|
36
|
+
export type ActivityMetric = "sessions" | "prompts" | "skills" | "mcp";
|
|
37
|
+
|
|
38
|
+
export const ACTIVITY_METRICS: readonly ActivityMetric[] = ["sessions", "prompts", "skills", "mcp"];
|
|
39
|
+
|
|
40
|
+
export function metricValue(
|
|
41
|
+
value: { agents: number; messages: number; skills: number; mcp: number },
|
|
42
|
+
metric: ActivityMetric,
|
|
43
|
+
): number {
|
|
44
|
+
if (metric === "sessions") return value.agents;
|
|
45
|
+
if (metric === "prompts") return value.messages;
|
|
46
|
+
return metric === "skills" ? value.skills : value.mcp;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Next / previous metric in `ACTIVITY_METRICS`, wrapping around. */
|
|
50
|
+
export function stepMetric(metric: ActivityMetric, delta: number): ActivityMetric {
|
|
51
|
+
const count = ACTIVITY_METRICS.length;
|
|
52
|
+
return ACTIVITY_METRICS[(ACTIVITY_METRICS.indexOf(metric) + delta + count * 2) % count] ?? "sessions";
|
|
53
|
+
}
|
|
54
|
+
|
|
35
55
|
export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, _from?: string, today = new Date(), locale = "en") {
|
|
36
56
|
const end = startOfLocalDay(today);
|
|
37
57
|
// 52 natural weeks (Sunday-start) ending with the week containing today (058):
|
|
@@ -236,6 +256,23 @@ export function buildAgentCreationBuckets(
|
|
|
236
256
|
return buckets;
|
|
237
257
|
}
|
|
238
258
|
|
|
259
|
+
/**
|
|
260
|
+
* One bucket per local day over the same window as `buildAgentCreationBuckets`,
|
|
261
|
+
* valued by `metric` from `usage.activity-by-day` (070). No provider slices:
|
|
262
|
+
* only session creations carry a per-provider breakdown.
|
|
263
|
+
*/
|
|
264
|
+
export function buildDailyMetricBuckets(
|
|
265
|
+
days: readonly ActivityDay[],
|
|
266
|
+
metric: ActivityMetric,
|
|
267
|
+
options: { from: string; today?: Date },
|
|
268
|
+
): CreationBucket[] {
|
|
269
|
+
const byDay = new Map(days.map((day) => [day.date, metricValue(day, metric)]));
|
|
270
|
+
return buildAgentCreationBuckets([], options).map((bucket) => ({
|
|
271
|
+
...bucket,
|
|
272
|
+
count: byDay.get(bucket.key) ?? 0,
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
|
|
239
276
|
/**
|
|
240
277
|
* Providers across the whole window, ranked by total creations (051). Drives
|
|
241
278
|
* the stable stack order and colour assignment; tooltip rows use
|
package/shared/classify.test.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
classifyToolCall,
|
|
5
5
|
matchSkillFile,
|
|
6
6
|
normalizeProvider,
|
|
7
|
-
brandProviderId,
|
|
8
7
|
} from "./classify.ts";
|
|
9
8
|
|
|
10
9
|
describe("normalizeProvider", () => {
|
|
@@ -13,20 +12,12 @@ describe("normalizeProvider", () => {
|
|
|
13
12
|
assert.equal(normalizeProvider("opencode"), "opencode");
|
|
14
13
|
assert.equal(normalizeProvider("codex"), "codex");
|
|
15
14
|
assert.equal(normalizeProvider("pi"), "pi");
|
|
16
|
-
assert.equal(normalizeProvider("omp"), "
|
|
15
|
+
assert.equal(normalizeProvider("omp"), "omp");
|
|
17
16
|
assert.equal(normalizeProvider("cursor"), "cursor");
|
|
18
17
|
assert.equal(normalizeProvider("codebuddy-code"), "codebuddy");
|
|
19
18
|
});
|
|
20
19
|
});
|
|
21
20
|
|
|
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
|
-
|
|
30
21
|
describe("matchSkillFile", () => {
|
|
31
22
|
it("extracts skill name from common agent config roots", () => {
|
|
32
23
|
assert.equal(
|
package/shared/classify.ts
CHANGED
|
@@ -118,21 +118,14 @@ export function normalizeProvider(provider: string): string {
|
|
|
118
118
|
if (head === "claude" || head.startsWith("claude")) return "claude";
|
|
119
119
|
if (head === "opencode") return "opencode";
|
|
120
120
|
if (head === "codex") return "codex";
|
|
121
|
-
if (head === "pi"
|
|
121
|
+
if (head === "pi") return "pi";
|
|
122
|
+
// Oh My Pi is its own Paseo provider (manifest id `omp`), not a Pi alias (071).
|
|
123
|
+
if (head === "omp") return "omp";
|
|
122
124
|
if (head === "cursor") return "cursor";
|
|
123
125
|
if (head === "codebuddy" || head === "codebuddy-code") return "codebuddy";
|
|
124
126
|
return head;
|
|
125
127
|
}
|
|
126
128
|
|
|
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
129
|
|
|
137
130
|
function expandHome(path: string, homeDir?: string): string {
|
|
138
131
|
if (homeDir && path.startsWith("~/")) {
|
package/shared/format.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { messagesFor } from "./i18n.ts";
|
|
2
|
+
|
|
1
3
|
/** Format stored ISO timestamps for UI / export in the local timezone + locale. */
|
|
2
4
|
export function formatLocalDateTime(
|
|
3
5
|
iso: string | null | undefined,
|
|
@@ -61,14 +63,15 @@ export function formatCount(value: number): string {
|
|
|
61
63
|
return String(value);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
/** Compact
|
|
65
|
-
export function formatDuration(ms: number): string {
|
|
66
|
+
/** Compact duration for agent lifetimes (049); units follow the app language (066). */
|
|
67
|
+
export function formatDuration(ms: number, locale = "en"): string {
|
|
66
68
|
if (!Number.isFinite(ms) || ms < 0) return "—";
|
|
67
|
-
|
|
68
|
-
if (ms <
|
|
69
|
+
const m = messagesFor(locale).duration;
|
|
70
|
+
if (ms < MINUTE_MS) return m.underMinute;
|
|
71
|
+
if (ms < HOUR_MS) return m.minutes(Math.floor(ms / MINUTE_MS));
|
|
69
72
|
const hours = ms / HOUR_MS;
|
|
70
|
-
if (hours < 48) return
|
|
73
|
+
if (hours < 48) return m.hours(Number(hours.toFixed(1)));
|
|
71
74
|
const days = ms / DAY_MS;
|
|
72
|
-
if (days < 60) return
|
|
73
|
-
return
|
|
75
|
+
if (days < 60) return m.days(Number(days.toFixed(1)));
|
|
76
|
+
return m.months(Number((days / 30.44).toFixed(1)));
|
|
74
77
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { formatDuration } from "./format.ts";
|
|
4
|
+
import { messagesFor, resolveAppLanguage } from "./i18n.ts";
|
|
5
|
+
|
|
6
|
+
test("resolveAppLanguage honors an explicit Paseo setting", () => {
|
|
7
|
+
assert.equal(resolveAppLanguage("zh-CN", ["en-US"]), "zh-CN");
|
|
8
|
+
assert.equal(resolveAppLanguage("ja", ["zh-CN"]), "ja");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("resolveAppLanguage maps system to the OS preference", () => {
|
|
12
|
+
assert.equal(resolveAppLanguage("system", ["zh-TW", "en"]), "zh-CN");
|
|
13
|
+
assert.equal(resolveAppLanguage("system", ["pt-PT"]), "pt-BR");
|
|
14
|
+
assert.equal(resolveAppLanguage("system", ["de-DE", "ko-KR"]), "ko");
|
|
15
|
+
assert.equal(resolveAppLanguage("system", ["de-DE"]), "en");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("resolveAppLanguage treats missing or unknown settings like system", () => {
|
|
19
|
+
assert.equal(resolveAppLanguage(undefined, []), "en");
|
|
20
|
+
assert.equal(resolveAppLanguage("klingon", ["zh-CN"]), "zh-CN");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("messagesFor returns zh-CN copy and falls back to English", () => {
|
|
24
|
+
assert.equal(messagesFor("zh-CN").common.retry, "重试");
|
|
25
|
+
assert.equal(messagesFor("zh-CN").common.lastUsed("3 分钟前"), "最近 3 分钟前");
|
|
26
|
+
assert.equal(messagesFor("fr").common.retry, messagesFor("en").common.retry);
|
|
27
|
+
assert.equal(messagesFor("en").workspace.state.subagents(1), "1 subagent");
|
|
28
|
+
assert.equal(messagesFor("en").workspace.state.subagents(2), "2 subagents");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("formatDuration uses the locale's units", () => {
|
|
32
|
+
assert.equal(formatDuration(5 * 60_000, "en"), "5 min");
|
|
33
|
+
assert.equal(formatDuration(5 * 60_000, "zh-CN"), "5 分钟");
|
|
34
|
+
});
|