@narumitw/pi-analytics 0.49.8 → 0.49.10
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/README.md +13 -36
- package/dist/index.ts +53 -106
- package/dist/index.ts.map +2 -2
- package/package.json +49 -50
- package/src/analytics.ts +368 -358
- package/src/collector.ts +250 -262
- package/src/errors.ts +12 -12
- package/src/menu.ts +325 -343
- package/src/skills.ts +55 -57
- package/src/storage/files.ts +352 -374
- package/src/storage/format.ts +159 -201
- package/src/storage/queries.ts +200 -204
- package/src/storage/store.ts +39 -43
- package/src/types.ts +66 -79
package/src/skills.ts
CHANGED
|
@@ -3,80 +3,78 @@ import path from "node:path";
|
|
|
3
3
|
import type { InputSource } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
|
|
5
5
|
export interface AvailableSkill {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
name: string;
|
|
7
|
+
filePath: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface PendingExplicitSkill {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
name: string;
|
|
12
|
+
observedAtMs: number;
|
|
13
|
+
source: "interactive" | "rpc";
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function explicitSkillName(text: string): string | undefined {
|
|
17
|
-
|
|
17
|
+
return text.match(/^\/skill:([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?:\s|$)/u)?.[1];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class SkillTracker {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
private pending: PendingExplicitSkill | undefined;
|
|
22
|
+
private readonly skillByPath = new Map<string, string>();
|
|
23
|
+
private readonly availableNames = new Set<string>();
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly cwd: string,
|
|
27
|
+
private readonly canonicalize: (filePath: string) => Promise<string> = realpath,
|
|
28
|
+
) {}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
observeInput(text: string, source: InputSource, now: number): void {
|
|
31
|
+
if (source === "extension") return;
|
|
32
|
+
const name = explicitSkillName(text);
|
|
33
|
+
this.pending = name ? { name, observedAtMs: now, source } : undefined;
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
consumeExplicitSkill(): PendingExplicitSkill | undefined {
|
|
37
|
+
const pending = this.pending;
|
|
38
|
+
this.pending = undefined;
|
|
39
|
+
return pending;
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
clearPending(): void {
|
|
43
|
+
this.pending = undefined;
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
hasAvailableSkill(name: string): boolean {
|
|
47
|
+
return this.availableNames.has(name);
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
}
|
|
50
|
+
async setAvailableSkills(skills: readonly AvailableSkill[]): Promise<void> {
|
|
51
|
+
this.skillByPath.clear();
|
|
52
|
+
this.availableNames.clear();
|
|
53
|
+
const seenNames = new Set<string>();
|
|
54
|
+
for (const skill of skills) {
|
|
55
|
+
if (seenNames.has(skill.name)) continue;
|
|
56
|
+
seenNames.add(skill.name);
|
|
57
|
+
this.availableNames.add(skill.name);
|
|
58
|
+
const canonical = await this.canonicalize(skill.filePath).catch(() => path.resolve(this.cwd, skill.filePath));
|
|
59
|
+
this.skillByPath.set(canonical, skill.name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
async matchSuccessfulRead(input: {
|
|
64
|
+
toolName: string;
|
|
65
|
+
input: unknown;
|
|
66
|
+
isError: boolean;
|
|
67
|
+
}): Promise<string | undefined> {
|
|
68
|
+
if (input.toolName !== "read" || input.isError || !isRecord(input.input)) return undefined;
|
|
69
|
+
const rawPath = input.input.path;
|
|
70
|
+
if (typeof rawPath !== "string" || rawPath.length === 0) return undefined;
|
|
71
|
+
const normalized = rawPath.startsWith("@") ? rawPath.slice(1) : rawPath;
|
|
72
|
+
const absolute = path.resolve(this.cwd, normalized);
|
|
73
|
+
const canonical = await this.canonicalize(absolute).catch(() => absolute);
|
|
74
|
+
return this.skillByPath.get(canonical);
|
|
75
|
+
}
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
81
|
-
|
|
79
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
82
80
|
}
|