@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.
- package/client/activity-heatmap.tsx +138 -0
- package/client/global-surface.tsx +689 -0
- package/client/panel.tsx +423 -0
- package/client/pending-skill.ts +50 -0
- package/client/pill-data-cache.test.ts +68 -0
- package/client/pill-data-cache.ts +37 -0
- package/client/pill.tsx +211 -0
- package/client/provider-filter.test.ts +95 -0
- package/client/provider-filter.ts +44 -0
- package/client/rank-color.test.ts +35 -0
- package/client/rank-color.ts +69 -0
- package/client/usage-popover.tsx +383 -0
- package/client/usage-query.tsx +54 -0
- package/client/usage-stats.tsx +18 -0
- package/client/use-app-language.ts +14 -0
- package/client/web.ts +28 -0
- package/index.client.tsx +62 -0
- package/index.server.ts +128 -0
- package/package.json +31 -0
- package/paseo-plugin.json +6 -0
- package/server/agents.test.ts +67 -0
- package/server/agents.ts +75 -0
- package/server/background-sync.test.ts +143 -0
- package/server/background-sync.ts +105 -0
- package/server/handlers-query.test.ts +91 -0
- package/server/handlers.ts +531 -0
- package/server/host-types.ts +14 -0
- package/server/ingest.test.ts +233 -0
- package/server/ingest.ts +277 -0
- package/server/mcp-servers.test.ts +70 -0
- package/server/mcp-servers.ts +212 -0
- package/server/messages.test.ts +150 -0
- package/server/migrate-data.test.ts +65 -0
- package/server/migrate-data.ts +54 -0
- package/server/resolve-model.test.ts +11 -0
- package/server/resolve-model.ts +30 -0
- package/server/skill-path.test.ts +56 -0
- package/server/skill-path.ts +85 -0
- package/server/store.test.ts +221 -0
- package/server/store.ts +909 -0
- package/server/ttl-cache.ts +34 -0
- package/shared/activity.test.ts +86 -0
- package/shared/activity.ts +185 -0
- package/shared/classify.test.ts +306 -0
- package/shared/classify.ts +378 -0
- package/shared/format.test.ts +48 -0
- package/shared/format.ts +45 -0
- package/shared/insights.test.ts +122 -0
- package/shared/insights.ts +188 -0
- package/shared/plugin-id.ts +7 -0
- package/shared/usage.test.ts +668 -0
- package/shared/usage.ts +726 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Simple in-memory TTL cache for expensive sync filesystem scans. */
|
|
2
|
+
export function createTtlCache<T>(ttlMs: number) {
|
|
3
|
+
let cached: { value: T; expiresAt: number } | null = null;
|
|
4
|
+
return {
|
|
5
|
+
get(compute: () => T): T {
|
|
6
|
+
const now = Date.now();
|
|
7
|
+
if (cached && cached.expiresAt > now) return cached.value;
|
|
8
|
+
const value = compute();
|
|
9
|
+
cached = { value, expiresAt: now + ttlMs };
|
|
10
|
+
return value;
|
|
11
|
+
},
|
|
12
|
+
clear(): void {
|
|
13
|
+
cached = null;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Keyed TTL cache. */
|
|
19
|
+
export function createKeyedTtlCache<T>(ttlMs: number) {
|
|
20
|
+
const map = new Map<string, { value: T; expiresAt: number }>();
|
|
21
|
+
return {
|
|
22
|
+
get(key: string, compute: () => T): T {
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
const hit = map.get(key);
|
|
25
|
+
if (hit && hit.expiresAt > now) return hit.value;
|
|
26
|
+
const value = compute();
|
|
27
|
+
map.set(key, { value, expiresAt: now + ttlMs });
|
|
28
|
+
return value;
|
|
29
|
+
},
|
|
30
|
+
clear(): void {
|
|
31
|
+
map.clear();
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { activityLevel, buildActivityCalendar, computeStreaks } from "./activity.ts";
|
|
4
|
+
|
|
5
|
+
const days = [
|
|
6
|
+
{ date: "2026-03-07", skills: 2, mcp: 1, agents: 2, messages: 4, total: 9 },
|
|
7
|
+
{ date: "2026-03-09", skills: 1, mcp: 4, agents: 1, messages: 3, total: 9 },
|
|
8
|
+
];
|
|
9
|
+
const today = new Date(2026, 2, 10);
|
|
10
|
+
const from = new Date(2026, 2, 7).toISOString();
|
|
11
|
+
|
|
12
|
+
describe("activity calendar", () => {
|
|
13
|
+
it("formats months with the explicit app language", () => {
|
|
14
|
+
const english = buildActivityCalendar([], "daily", from, today, "en");
|
|
15
|
+
const chinese = buildActivityCalendar([], "daily", from, today, "zh-CN");
|
|
16
|
+
assert.equal(english.months.length, 1);
|
|
17
|
+
assert.equal(english.months[0]?.label, "Mar");
|
|
18
|
+
assert.equal(chinese.months[0]?.label, "3月");
|
|
19
|
+
});
|
|
20
|
+
it("uses 12 evenly spaced month labels for a year window", () => {
|
|
21
|
+
const result = buildActivityCalendar([], "daily", undefined, new Date(2026, 8, 19), "en");
|
|
22
|
+
assert.equal(result.weeks.length, 52);
|
|
23
|
+
assert.equal(result.months.length, 12);
|
|
24
|
+
assert.equal(result.months[0]?.label, "Oct");
|
|
25
|
+
assert.equal(result.months[11]?.label, "Sep");
|
|
26
|
+
assert.equal(result.months[0]?.index, 0);
|
|
27
|
+
assert.equal(result.months[11]?.index, (11 / 12) * result.weeks.length);
|
|
28
|
+
for (let i = 0; i < 12; i++) {
|
|
29
|
+
assert.equal(result.months[i]?.index, (i / 12) * result.weeks.length);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
it("keeps the year window at a fixed 52 weeks", () => {
|
|
33
|
+
for (const day of [1, 15, 28]) {
|
|
34
|
+
for (const month of [0, 5, 8, 11]) {
|
|
35
|
+
const result = buildActivityCalendar([], "daily", undefined, new Date(2026, month, day), "en");
|
|
36
|
+
assert.equal(result.weeks.length, 52, `2026-${month + 1}-${day}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
it("carries cumulative counts across missing days including today", () => {
|
|
41
|
+
const cells = buildActivityCalendar(days, "cumulative", from, today).weeks.flat();
|
|
42
|
+
assert.equal(cells.find(c => c.key === "2026-03-08")?.total, 9);
|
|
43
|
+
assert.equal(cells.find(c => c.key === "2026-03-08")?.agents, 2);
|
|
44
|
+
assert.equal(cells.find(c => c.key === "2026-03-10")?.total, 18);
|
|
45
|
+
assert.equal(cells.find(c => c.key === "2026-03-10")?.agents, 3);
|
|
46
|
+
assert.equal(cells.find(c => c.key === "2026-03-10")?.messages, 7);
|
|
47
|
+
});
|
|
48
|
+
it("keeps daily gaps empty and aggregates Sunday-start weeks", () => {
|
|
49
|
+
assert.equal(buildActivityCalendar(days, "daily", from, today).weeks.flat().find(c => c.key === "2026-03-08")?.total, 0);
|
|
50
|
+
const weekly = buildActivityCalendar(days, "weekly", from, today).weeks[1]?.[0];
|
|
51
|
+
assert.equal(weekly?.total, 9);
|
|
52
|
+
assert.equal(weekly?.agents, 1);
|
|
53
|
+
assert.equal(weekly?.messages, 3);
|
|
54
|
+
});
|
|
55
|
+
it("includes the current week across DST and marks padding cells", () => {
|
|
56
|
+
const previous = process.env.TZ;
|
|
57
|
+
process.env.TZ = "America/New_York";
|
|
58
|
+
try {
|
|
59
|
+
const result = buildActivityCalendar([], "daily", new Date(2026, 2, 1).toISOString(), new Date(2026, 2, 15));
|
|
60
|
+
assert.equal(result.weeks.length, 3);
|
|
61
|
+
assert.equal(result.weeks[2]?.[0]?.key, "2026-03-15");
|
|
62
|
+
assert.equal(result.weeks[2]?.[1]?.future, true);
|
|
63
|
+
} finally {
|
|
64
|
+
if (previous === undefined) delete process.env.TZ; else process.env.TZ = previous;
|
|
65
|
+
}
|
|
66
|
+
assert.equal(buildActivityCalendar([], "daily", from, today).weeks[0]?.[0]?.excluded, true);
|
|
67
|
+
});
|
|
68
|
+
it("renders empty windows and bounded intensity", () => {
|
|
69
|
+
const result = buildActivityCalendar([], "daily", undefined, today);
|
|
70
|
+
assert.equal(result.weeks.length, 52);
|
|
71
|
+
assert.equal(result.max, 0);
|
|
72
|
+
assert.equal(activityLevel(0, 100), 0);
|
|
73
|
+
assert.equal(activityLevel(1, 100), 1);
|
|
74
|
+
assert.equal(activityLevel(100, 100), 4);
|
|
75
|
+
});
|
|
76
|
+
it("allows yesterday as the current streak endpoint", () => {
|
|
77
|
+
assert.deepEqual(computeStreaks(days, today), { current: 1, longest: 1 });
|
|
78
|
+
});
|
|
79
|
+
it("counts message-only and agent-only days toward streaks", () => {
|
|
80
|
+
const messageOnly = [
|
|
81
|
+
{ date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 2, total: 0 },
|
|
82
|
+
{ date: "2026-03-10", skills: 0, mcp: 0, agents: 1, messages: 0, total: 0 },
|
|
83
|
+
];
|
|
84
|
+
assert.deepEqual(computeStreaks(messageOnly, today), { current: 2, longest: 2 });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { ActivityDay } from "./usage.ts";
|
|
2
|
+
|
|
3
|
+
function pad2(value: number): string {
|
|
4
|
+
return String(value).padStart(2, "0");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function toDayKey(date: Date): string {
|
|
8
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parseDayKey(key: string): Date {
|
|
12
|
+
const [y, m, d] = key.split("-").map(Number);
|
|
13
|
+
return new Date(y!, m! - 1, d!);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function startOfLocalDay(date: Date): Date {
|
|
17
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Sunday-start week containing `date`. */
|
|
21
|
+
function startOfWeekSunday(date: Date): Date {
|
|
22
|
+
const d = startOfLocalDay(date);
|
|
23
|
+
d.setDate(d.getDate() - d.getDay());
|
|
24
|
+
return d;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function addDays(date: Date, days: number): Date {
|
|
28
|
+
const next = new Date(date);
|
|
29
|
+
next.setDate(next.getDate() + days);
|
|
30
|
+
return next;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type HeatmapMode = "daily" | "weekly" | "cumulative";
|
|
34
|
+
|
|
35
|
+
export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, from?: string, today = new Date(), locale = "en") {
|
|
36
|
+
const end = startOfLocalDay(today);
|
|
37
|
+
let first: Date;
|
|
38
|
+
let start: Date;
|
|
39
|
+
if (from) {
|
|
40
|
+
const parsed = startOfLocalDay(new Date(from));
|
|
41
|
+
first = Number.isNaN(parsed.getTime()) ? addDays(end, -363) : parsed;
|
|
42
|
+
start = startOfWeekSunday(first);
|
|
43
|
+
} else {
|
|
44
|
+
// Fixed 52-week year window (ChatGPT-style): current week + 51 prior weeks.
|
|
45
|
+
start = addDays(startOfWeekSunday(end), -7 * 51);
|
|
46
|
+
first = start;
|
|
47
|
+
}
|
|
48
|
+
const daily = new Map(days.map(day => [day.date, day]));
|
|
49
|
+
const weekly = new Map<string, ActivityDay>();
|
|
50
|
+
for (const day of days) {
|
|
51
|
+
const key = toDayKey(startOfWeekSunday(parseDayKey(day.date)));
|
|
52
|
+
const prev = weekly.get(key) ?? { date: key, skills: 0, mcp: 0, agents: 0, messages: 0, total: 0 };
|
|
53
|
+
weekly.set(key, {
|
|
54
|
+
date: key,
|
|
55
|
+
skills: prev.skills + day.skills,
|
|
56
|
+
mcp: prev.mcp + day.mcp,
|
|
57
|
+
agents: prev.agents + day.agents,
|
|
58
|
+
messages: prev.messages + day.messages,
|
|
59
|
+
total: 0,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
for (const [key, day] of weekly) {
|
|
63
|
+
weekly.set(key, {
|
|
64
|
+
...day,
|
|
65
|
+
total: day.skills + day.mcp + day.agents + day.messages,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
let skills = 0;
|
|
69
|
+
let mcp = 0;
|
|
70
|
+
let agents = 0;
|
|
71
|
+
let messages = 0;
|
|
72
|
+
// Carry history before the displayed year into the cumulative view.
|
|
73
|
+
for (const day of days) {
|
|
74
|
+
if (day.date < toDayKey(start)) {
|
|
75
|
+
skills += day.skills;
|
|
76
|
+
mcp += day.mcp;
|
|
77
|
+
agents += day.agents;
|
|
78
|
+
messages += day.messages;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const weeks = [];
|
|
82
|
+
let max = 0;
|
|
83
|
+
for (let cursor = start; cursor <= end; cursor = addDays(cursor, 7)) {
|
|
84
|
+
const week = [];
|
|
85
|
+
for (let d = 0; d < 7; d++) {
|
|
86
|
+
const date = addDays(cursor, d);
|
|
87
|
+
const key = toDayKey(date);
|
|
88
|
+
const future = date > end;
|
|
89
|
+
const excluded = date < first;
|
|
90
|
+
const raw = daily.get(key);
|
|
91
|
+
skills += raw?.skills ?? 0;
|
|
92
|
+
mcp += raw?.mcp ?? 0;
|
|
93
|
+
agents += raw?.agents ?? 0;
|
|
94
|
+
messages += raw?.messages ?? 0;
|
|
95
|
+
const value =
|
|
96
|
+
mode === "weekly"
|
|
97
|
+
? weekly.get(toDayKey(cursor))
|
|
98
|
+
: mode === "cumulative"
|
|
99
|
+
? { skills, mcp, agents, messages, total: skills + mcp + agents + messages }
|
|
100
|
+
: raw;
|
|
101
|
+
const skillsN = value?.skills ?? 0;
|
|
102
|
+
const mcpN = value?.mcp ?? 0;
|
|
103
|
+
const agentsN = value?.agents ?? 0;
|
|
104
|
+
const messagesN = value?.messages ?? 0;
|
|
105
|
+
const cell = {
|
|
106
|
+
key,
|
|
107
|
+
future,
|
|
108
|
+
excluded,
|
|
109
|
+
skills: skillsN,
|
|
110
|
+
mcp: mcpN,
|
|
111
|
+
agents: agentsN,
|
|
112
|
+
messages: messagesN,
|
|
113
|
+
total: skillsN + mcpN + agentsN + messagesN,
|
|
114
|
+
};
|
|
115
|
+
if (!future && !excluded) max = Math.max(max, cell.total);
|
|
116
|
+
week.push(cell);
|
|
117
|
+
}
|
|
118
|
+
weeks.push(week);
|
|
119
|
+
}
|
|
120
|
+
// Month axis: at most 12 labels, first/last flush to sides, evenly spaced (ChatGPT-style).
|
|
121
|
+
// Year windows use the trailing 12 months ending at `end` (e.g. Oct…Sep).
|
|
122
|
+
const startMonth = new Date(start.getFullYear(), start.getMonth(), 1);
|
|
123
|
+
const endMonth = new Date(end.getFullYear(), end.getMonth(), 1);
|
|
124
|
+
const spanMonths =
|
|
125
|
+
(endMonth.getFullYear() - startMonth.getFullYear()) * 12 +
|
|
126
|
+
(endMonth.getMonth() - startMonth.getMonth()) +
|
|
127
|
+
1;
|
|
128
|
+
const monthCount = Math.min(12, Math.max(1, spanMonths));
|
|
129
|
+
const months: Array<{ index: number; label: string }> = [];
|
|
130
|
+
for (let i = 0; i < monthCount; i++) {
|
|
131
|
+
const date =
|
|
132
|
+
monthCount === 12
|
|
133
|
+
? new Date(end.getFullYear(), end.getMonth() - (monthCount - 1 - i), 1)
|
|
134
|
+
: new Date(startMonth.getFullYear(), startMonth.getMonth() + i, 1);
|
|
135
|
+
months.push({
|
|
136
|
+
index: (i / monthCount) * weeks.length,
|
|
137
|
+
label: date.toLocaleDateString(locale, { month: "short" }),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return { weeks, months, max };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function activityLevel(total: number, max: number): number {
|
|
144
|
+
if (total <= 0 || max <= 0) return 0;
|
|
145
|
+
return Math.max(1, Math.min(4, Math.ceil(Math.sqrt(total / max) * 4)));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Day counts as active if any tracked dimension fired (tools, agents, or messages). */
|
|
149
|
+
export function isActiveDay(day: Pick<ActivityDay, "skills" | "mcp" | "agents" | "messages">): boolean {
|
|
150
|
+
return day.skills > 0 || day.mcp > 0 || day.agents > 0 || day.messages > 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Current streak ending today (or yesterday), and longest streak in the series. */
|
|
154
|
+
export function computeStreaks(
|
|
155
|
+
days: readonly ActivityDay[],
|
|
156
|
+
today = new Date(),
|
|
157
|
+
): { current: number; longest: number } {
|
|
158
|
+
const active = new Set(days.filter(isActiveDay).map((d) => d.date));
|
|
159
|
+
if (active.size === 0) return { current: 0, longest: 0 };
|
|
160
|
+
|
|
161
|
+
const end = startOfLocalDay(today);
|
|
162
|
+
let longest = 0;
|
|
163
|
+
let run = 0;
|
|
164
|
+
const sorted = [...active].sort();
|
|
165
|
+
let prev: string | null = null;
|
|
166
|
+
for (const key of sorted) {
|
|
167
|
+
if (prev && toDayKey(addDays(parseDayKey(prev), 1)) === key) run += 1;
|
|
168
|
+
else run = 1;
|
|
169
|
+
if (run > longest) longest = run;
|
|
170
|
+
prev = key;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let current = 0;
|
|
174
|
+
let cursor = end;
|
|
175
|
+
// Allow streak to still count if last active day was yesterday.
|
|
176
|
+
if (!active.has(toDayKey(cursor))) {
|
|
177
|
+
cursor = addDays(cursor, -1);
|
|
178
|
+
}
|
|
179
|
+
while (active.has(toDayKey(cursor))) {
|
|
180
|
+
current += 1;
|
|
181
|
+
cursor = addDays(cursor, -1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return { current, longest };
|
|
185
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
classifyToolCall,
|
|
5
|
+
matchSkillFile,
|
|
6
|
+
normalizeProvider,
|
|
7
|
+
} from "./classify.ts";
|
|
8
|
+
|
|
9
|
+
describe("normalizeProvider", () => {
|
|
10
|
+
it("maps provider ids", () => {
|
|
11
|
+
assert.equal(normalizeProvider("claude/opus"), "claude");
|
|
12
|
+
assert.equal(normalizeProvider("opencode"), "opencode");
|
|
13
|
+
assert.equal(normalizeProvider("codex"), "codex");
|
|
14
|
+
assert.equal(normalizeProvider("pi"), "pi");
|
|
15
|
+
assert.equal(normalizeProvider("cursor"), "cursor");
|
|
16
|
+
assert.equal(normalizeProvider("codebuddy-code"), "codebuddy");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("matchSkillFile", () => {
|
|
21
|
+
it("extracts skill name from common agent config roots", () => {
|
|
22
|
+
assert.equal(
|
|
23
|
+
matchSkillFile("/Users/me/.claude/skills/paseo/SKILL.md", undefined, "/Users/me"),
|
|
24
|
+
"paseo",
|
|
25
|
+
);
|
|
26
|
+
assert.equal(
|
|
27
|
+
matchSkillFile(
|
|
28
|
+
"/Users/me/.cursor/skills/wecomcli-message/SKILL.md",
|
|
29
|
+
undefined,
|
|
30
|
+
"/Users/me",
|
|
31
|
+
),
|
|
32
|
+
"wecomcli-message",
|
|
33
|
+
);
|
|
34
|
+
assert.equal(
|
|
35
|
+
matchSkillFile("/Users/me/.codebuddy/skills/foo/SKILL.md", undefined, "/Users/me"),
|
|
36
|
+
"foo",
|
|
37
|
+
);
|
|
38
|
+
assert.equal(
|
|
39
|
+
matchSkillFile("/Users/me/.pi/agent/skills/bar/SKILL.md", undefined, "/Users/me"),
|
|
40
|
+
"bar",
|
|
41
|
+
);
|
|
42
|
+
assert.equal(
|
|
43
|
+
matchSkillFile("/proj/.agents/skills/baz/SKILL.md", undefined, "/Users/me"),
|
|
44
|
+
"baz",
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("returns null outside roots", () => {
|
|
49
|
+
assert.equal(matchSkillFile("/tmp/other/SKILL.md", undefined, "/Users/me"), null);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("matches nested category under .agents/skills", () => {
|
|
53
|
+
assert.equal(
|
|
54
|
+
matchSkillFile(
|
|
55
|
+
"/proj/.agents/skills/info/zhihu/SKILL.md",
|
|
56
|
+
undefined,
|
|
57
|
+
"/Users/me",
|
|
58
|
+
),
|
|
59
|
+
"zhihu",
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("classifyToolCall — skill exact", () => {
|
|
65
|
+
it("Claude Skill tool", () => {
|
|
66
|
+
const r = classifyToolCall(
|
|
67
|
+
{
|
|
68
|
+
name: "Skill",
|
|
69
|
+
detail: { type: "plain_text", label: "paseo-help", icon: "sparkles" },
|
|
70
|
+
},
|
|
71
|
+
{ provider: "claude" },
|
|
72
|
+
);
|
|
73
|
+
assert.equal(r.category, "skill");
|
|
74
|
+
assert.equal(r.confidence, "exact");
|
|
75
|
+
assert.equal(r.skillName, "paseo-help");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("OpenCode skill tool", () => {
|
|
79
|
+
const r = classifyToolCall(
|
|
80
|
+
{
|
|
81
|
+
name: "skill",
|
|
82
|
+
detail: { type: "plain_text", label: "commit" },
|
|
83
|
+
},
|
|
84
|
+
{ provider: "opencode" },
|
|
85
|
+
);
|
|
86
|
+
assert.equal(r.category, "skill");
|
|
87
|
+
assert.equal(r.confidence, "exact");
|
|
88
|
+
assert.equal(r.skillName, "commit");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("classifyToolCall — skill inferred / low", () => {
|
|
93
|
+
const homeDir = "/home/u";
|
|
94
|
+
|
|
95
|
+
it("read SKILL.md → inferred", () => {
|
|
96
|
+
const r = classifyToolCall(
|
|
97
|
+
{
|
|
98
|
+
name: "Read",
|
|
99
|
+
detail: { type: "read", filePath: "/home/u/.codex/skills/review/SKILL.md" },
|
|
100
|
+
},
|
|
101
|
+
{ provider: "codex", homeDir },
|
|
102
|
+
);
|
|
103
|
+
assert.equal(r.category, "skill");
|
|
104
|
+
assert.equal(r.confidence, "inferred");
|
|
105
|
+
assert.equal(r.skillName, "review");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("Cursor read ~/.cursor/skills → inferred", () => {
|
|
109
|
+
const r = classifyToolCall(
|
|
110
|
+
{
|
|
111
|
+
name: "read",
|
|
112
|
+
detail: {
|
|
113
|
+
type: "read",
|
|
114
|
+
filePath: "/home/u/.cursor/skills/wecomcli-shared/SKILL.md",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{ provider: "cursor", homeDir },
|
|
118
|
+
);
|
|
119
|
+
assert.equal(r.category, "skill");
|
|
120
|
+
assert.equal(r.confidence, "inferred");
|
|
121
|
+
assert.equal(r.skillName, "wecomcli-shared");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("shell cat SKILL.md → low", () => {
|
|
125
|
+
const r = classifyToolCall(
|
|
126
|
+
{
|
|
127
|
+
name: "Bash",
|
|
128
|
+
detail: {
|
|
129
|
+
type: "shell",
|
|
130
|
+
command: "cat /home/u/.codex/skills/review/SKILL.md",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{ provider: "codex", homeDir },
|
|
134
|
+
);
|
|
135
|
+
assert.equal(r.category, "skill");
|
|
136
|
+
assert.equal(r.confidence, "low");
|
|
137
|
+
assert.equal(r.skillName, "review");
|
|
138
|
+
assert.equal(r.filePath, "/home/u/.codex/skills/review/SKILL.md");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("shell SKILL.md outside roots still low via parent dir", () => {
|
|
142
|
+
const r = classifyToolCall(
|
|
143
|
+
{
|
|
144
|
+
name: "Bash",
|
|
145
|
+
detail: { type: "shell", command: "rg -n foo foo-skill/SKILL.md" },
|
|
146
|
+
},
|
|
147
|
+
{ provider: "pi", homeDir },
|
|
148
|
+
);
|
|
149
|
+
assert.equal(r.category, "skill");
|
|
150
|
+
assert.equal(r.confidence, "low");
|
|
151
|
+
assert.equal(r.skillName, "foo-skill");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("classifyToolCall — MCP", () => {
|
|
156
|
+
it("Claude mcp__server__tool", () => {
|
|
157
|
+
const r = classifyToolCall(
|
|
158
|
+
{ name: "mcp__knot__tapd_search", detail: { type: "unknown", input: {}, output: {} } },
|
|
159
|
+
{ provider: "claude" },
|
|
160
|
+
);
|
|
161
|
+
assert.equal(r.category, "mcp");
|
|
162
|
+
assert.equal(r.mcpServer, "knot");
|
|
163
|
+
assert.equal(r.mcpTool, "tapd_search");
|
|
164
|
+
assert.equal(r.confidence, "exact");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("Codex server.tool with provider path", () => {
|
|
168
|
+
const r = classifyToolCall(
|
|
169
|
+
{ name: "paseo.list_agents", detail: { type: "unknown", input: {}, output: {} } },
|
|
170
|
+
{ provider: "codex/gpt-5" },
|
|
171
|
+
);
|
|
172
|
+
assert.equal(r.category, "mcp");
|
|
173
|
+
assert.equal(r.mcpServer, "paseo");
|
|
174
|
+
assert.equal(r.mcpTool, "list_agents");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("Pi server.tool", () => {
|
|
178
|
+
const r = classifyToolCall(
|
|
179
|
+
{ name: "github.create_issue", detail: { type: "unknown", input: {}, output: {} } },
|
|
180
|
+
{ provider: "pi" },
|
|
181
|
+
);
|
|
182
|
+
assert.equal(r.category, "mcp");
|
|
183
|
+
assert.equal(r.mcpServer, "github");
|
|
184
|
+
assert.equal(r.mcpTool, "create_issue");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("OpenCode configured server prefix", () => {
|
|
188
|
+
const r = classifyToolCall(
|
|
189
|
+
{ name: "knot_tapd_search", detail: { type: "unknown", input: {}, output: {} } },
|
|
190
|
+
{ provider: "opencode", mcpServers: ["knot"] },
|
|
191
|
+
);
|
|
192
|
+
assert.equal(r.category, "mcp");
|
|
193
|
+
assert.equal(r.mcpServer, "knot");
|
|
194
|
+
assert.equal(r.mcpTool, "tapd_search");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("OpenCode hyphenated server name (mobile-mcp)", () => {
|
|
198
|
+
const r = classifyToolCall(
|
|
199
|
+
{
|
|
200
|
+
name: "mobile-mcp_mobile_list_available_devices",
|
|
201
|
+
detail: { type: "unknown", input: {}, output: {} },
|
|
202
|
+
},
|
|
203
|
+
{ provider: "opencode", mcpServers: ["mobile-mcp", "paseo"] },
|
|
204
|
+
);
|
|
205
|
+
assert.equal(r.category, "mcp");
|
|
206
|
+
assert.equal(r.mcpServer, "mobile-mcp");
|
|
207
|
+
assert.equal(r.mcpTool, "mobile_list_available_devices");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("OpenCode without server list stays regular", () => {
|
|
211
|
+
const r = classifyToolCall(
|
|
212
|
+
{ name: "mobile-mcp_mobile_list_available_devices", detail: { type: "unknown", input: {}, output: {} } },
|
|
213
|
+
{ provider: "opencode" },
|
|
214
|
+
);
|
|
215
|
+
assert.equal(r.category, "regular");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("Codex does not need mcpServers list", () => {
|
|
219
|
+
const r = classifyToolCall(
|
|
220
|
+
{ name: "mobile-mcp.list_devices", detail: { type: "unknown", input: {}, output: {} } },
|
|
221
|
+
{ provider: "codex" },
|
|
222
|
+
);
|
|
223
|
+
assert.equal(r.category, "mcp");
|
|
224
|
+
assert.equal(r.mcpServer, "mobile-mcp");
|
|
225
|
+
assert.equal(r.mcpTool, "list_devices");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("ACP inferred from metadata.title", () => {
|
|
229
|
+
const r = classifyToolCall(
|
|
230
|
+
{
|
|
231
|
+
name: "execute",
|
|
232
|
+
detail: { type: "unknown", input: {}, output: {} },
|
|
233
|
+
metadata: { title: "knot.search" },
|
|
234
|
+
},
|
|
235
|
+
{ provider: "cursor" },
|
|
236
|
+
);
|
|
237
|
+
assert.equal(r.category, "mcp");
|
|
238
|
+
assert.equal(r.confidence, "inferred");
|
|
239
|
+
assert.equal(r.mcpServer, "knot");
|
|
240
|
+
assert.equal(r.mcpTool, "search");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("ACP other + underscore title matches mcpServers", () => {
|
|
244
|
+
const r = classifyToolCall(
|
|
245
|
+
{
|
|
246
|
+
name: "other",
|
|
247
|
+
detail: { type: "unknown", input: {}, output: {} },
|
|
248
|
+
metadata: { kind: "other", title: "paseo_list_agents" },
|
|
249
|
+
},
|
|
250
|
+
{ provider: "cursor", mcpServers: ["paseo"] },
|
|
251
|
+
);
|
|
252
|
+
assert.equal(r.category, "mcp");
|
|
253
|
+
assert.equal(r.mcpServer, "paseo");
|
|
254
|
+
assert.equal(r.mcpTool, "list_agents");
|
|
255
|
+
assert.equal(r.confidence, "inferred");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("ACP other with empty title stays regular", () => {
|
|
259
|
+
const r = classifyToolCall(
|
|
260
|
+
{
|
|
261
|
+
name: "other",
|
|
262
|
+
detail: { type: "unknown", input: {}, output: {} },
|
|
263
|
+
metadata: { kind: "other", title: "Other" },
|
|
264
|
+
},
|
|
265
|
+
{ provider: "cursor", mcpServers: ["paseo"] },
|
|
266
|
+
);
|
|
267
|
+
assert.equal(r.category, "regular");
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe("classifyToolCall — regular shell", () => {
|
|
272
|
+
it("plain shell is regular", () => {
|
|
273
|
+
const r = classifyToolCall(
|
|
274
|
+
{ name: "Bash", detail: { type: "shell", command: "ls -la", exitCode: 0 } },
|
|
275
|
+
{ provider: "claude" },
|
|
276
|
+
);
|
|
277
|
+
assert.equal(r.category, "regular");
|
|
278
|
+
assert.equal(r.detailType, "shell");
|
|
279
|
+
assert.equal(r.command, "ls -la");
|
|
280
|
+
assert.equal(r.confidence, null);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("Cursor ACP shell (normalized detail.type) is regular", () => {
|
|
284
|
+
const r = classifyToolCall(
|
|
285
|
+
{ name: "execute", detail: { type: "shell", command: "pwd" }, metadata: { kind: "execute" } },
|
|
286
|
+
{ provider: "cursor" },
|
|
287
|
+
);
|
|
288
|
+
assert.equal(r.category, "regular");
|
|
289
|
+
assert.equal(r.detailType, "shell");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("regular file read/edit stay regular (not skill)", () => {
|
|
293
|
+
const read = classifyToolCall(
|
|
294
|
+
{ name: "Read", detail: { type: "read", filePath: "/tmp/app.ts" } },
|
|
295
|
+
{ provider: "claude" },
|
|
296
|
+
);
|
|
297
|
+
assert.equal(read.category, "regular");
|
|
298
|
+
assert.equal(read.detailType, "read");
|
|
299
|
+
const edit = classifyToolCall(
|
|
300
|
+
{ name: "edit", detail: { type: "edit", filePath: "/tmp/app.ts" } },
|
|
301
|
+
{ provider: "cursor" },
|
|
302
|
+
);
|
|
303
|
+
assert.equal(edit.category, "regular");
|
|
304
|
+
assert.equal(edit.detailType, "edit");
|
|
305
|
+
});
|
|
306
|
+
});
|