@ygncode/pi-insights 1.0.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/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/assets/index.js +46 -0
- package/dist/favicon.svg +20 -0
- package/dist/index.html +14 -0
- package/index.ts +163 -0
- package/lib/analytics.ts +254 -0
- package/lib/parser.ts +185 -0
- package/lib/rage.ts +52 -0
- package/lib/types.ts +160 -0
- package/package.json +66 -0
package/lib/types.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export interface SessionEvent {
|
|
2
|
+
type: string;
|
|
3
|
+
timestamp?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
parentId?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ContentItem {
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
isError?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TokenUsage {
|
|
17
|
+
input?: number;
|
|
18
|
+
output?: number;
|
|
19
|
+
cacheRead?: number;
|
|
20
|
+
cacheWrite?: number;
|
|
21
|
+
totalTokens?: number;
|
|
22
|
+
cost?: {
|
|
23
|
+
input?: number;
|
|
24
|
+
output?: number;
|
|
25
|
+
cacheRead?: number;
|
|
26
|
+
cacheWrite?: number;
|
|
27
|
+
total?: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SessionMessage {
|
|
32
|
+
role: "user" | "assistant" | "tool";
|
|
33
|
+
content?: ContentItem[];
|
|
34
|
+
usage?: TokenUsage;
|
|
35
|
+
model?: string;
|
|
36
|
+
provider?: string;
|
|
37
|
+
api?: string;
|
|
38
|
+
thinkingLevel?: string;
|
|
39
|
+
toolCalls?: Array<{ name?: string }>;
|
|
40
|
+
toolResults?: Array<{ isError?: boolean }>;
|
|
41
|
+
stopReason?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface RageHit {
|
|
45
|
+
word: string;
|
|
46
|
+
group: string;
|
|
47
|
+
hour: number;
|
|
48
|
+
model: string;
|
|
49
|
+
msgIndex: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ParsedSession {
|
|
53
|
+
id: string;
|
|
54
|
+
cwd: string;
|
|
55
|
+
projectName: string;
|
|
56
|
+
startTime: Date;
|
|
57
|
+
endTime: Date;
|
|
58
|
+
duration: number;
|
|
59
|
+
messageCount: number;
|
|
60
|
+
userMessageCount: number;
|
|
61
|
+
assistantMessageCount: number;
|
|
62
|
+
toolCallCount: number;
|
|
63
|
+
tokenUsage: {
|
|
64
|
+
input: number;
|
|
65
|
+
output: number;
|
|
66
|
+
cacheRead: number;
|
|
67
|
+
cacheWrite: number;
|
|
68
|
+
total: number;
|
|
69
|
+
};
|
|
70
|
+
cost: {
|
|
71
|
+
input: number;
|
|
72
|
+
output: number;
|
|
73
|
+
cacheRead: number;
|
|
74
|
+
cacheWrite: number;
|
|
75
|
+
total: number;
|
|
76
|
+
};
|
|
77
|
+
models: Record<string, { count: number; tokens: number; cost: number }>;
|
|
78
|
+
providers: Record<string, number>;
|
|
79
|
+
thinkingLevels: Record<string, number>;
|
|
80
|
+
toolUsage: Record<string, number>;
|
|
81
|
+
stopReasons: Record<string, number>;
|
|
82
|
+
toolCallErrors: number;
|
|
83
|
+
hasError: boolean;
|
|
84
|
+
rageHits: RageHit[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DailyStats {
|
|
88
|
+
date: string;
|
|
89
|
+
sessions: number;
|
|
90
|
+
messages: number;
|
|
91
|
+
tokens: number;
|
|
92
|
+
cost: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ProjectStats {
|
|
96
|
+
name: string;
|
|
97
|
+
sessions: number;
|
|
98
|
+
messages: number;
|
|
99
|
+
tokens: number;
|
|
100
|
+
cost: number;
|
|
101
|
+
duration: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface ModelStats {
|
|
105
|
+
name: string;
|
|
106
|
+
count: number;
|
|
107
|
+
tokens: number;
|
|
108
|
+
cost: number;
|
|
109
|
+
avgDuration: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface RageStats {
|
|
113
|
+
total: number;
|
|
114
|
+
messagesWithSwears: number;
|
|
115
|
+
byModel: { name: string; count: number }[];
|
|
116
|
+
byHour: { hour: number; count: number }[];
|
|
117
|
+
byProject: { name: string; count: number }[];
|
|
118
|
+
topWords: { word: string; group: string; count: number }[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface Analytics {
|
|
122
|
+
totalSessions: number;
|
|
123
|
+
totalMessages: number;
|
|
124
|
+
totalTokens: number;
|
|
125
|
+
totalCost: number;
|
|
126
|
+
totalDuration: number;
|
|
127
|
+
avgSessionDuration: number;
|
|
128
|
+
avgMessagesPerSession: number;
|
|
129
|
+
dateRange: { start: string; end: string };
|
|
130
|
+
dailyStats: DailyStats[];
|
|
131
|
+
projectStats: ProjectStats[];
|
|
132
|
+
modelStats: ModelStats[];
|
|
133
|
+
topTools: { name: string; count: number }[];
|
|
134
|
+
thinkingLevelDistribution: { name: string; count: number }[];
|
|
135
|
+
stopReasonDistribution: { name: string; count: number }[];
|
|
136
|
+
hourlyDistribution: { hour: number; count: number }[];
|
|
137
|
+
modelSwitchCount: number;
|
|
138
|
+
rageStats: RageStats;
|
|
139
|
+
sessions: Array<{
|
|
140
|
+
id: string;
|
|
141
|
+
cwd: string;
|
|
142
|
+
projectName: string;
|
|
143
|
+
startTime: string;
|
|
144
|
+
endTime: string;
|
|
145
|
+
duration: number;
|
|
146
|
+
messageCount: number;
|
|
147
|
+
userMessageCount: number;
|
|
148
|
+
assistantMessageCount: number;
|
|
149
|
+
toolCallCount: number;
|
|
150
|
+
tokenUsage: ParsedSession["tokenUsage"];
|
|
151
|
+
cost: ParsedSession["cost"];
|
|
152
|
+
models: ParsedSession["models"];
|
|
153
|
+
providers: ParsedSession["providers"];
|
|
154
|
+
thinkingLevels: ParsedSession["thinkingLevels"];
|
|
155
|
+
toolUsage: ParsedSession["toolUsage"];
|
|
156
|
+
stopReasons: ParsedSession["stopReasons"];
|
|
157
|
+
toolCallErrors: number;
|
|
158
|
+
hasError: boolean;
|
|
159
|
+
}>;
|
|
160
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ygncode/pi-insights",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Beautiful analytics reports for pi coding-agent sessions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "ygncode",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ygncode/pi-insights.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ygncode/pi-insights/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/ygncode/pi-insights#readme",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"pi-package",
|
|
21
|
+
"pi-extension",
|
|
22
|
+
"pi-coding-agent",
|
|
23
|
+
"analytics",
|
|
24
|
+
"sessions"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"index.ts",
|
|
28
|
+
"lib/",
|
|
29
|
+
"dist/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"pi": {
|
|
34
|
+
"extensions": [
|
|
35
|
+
"./index.ts"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "vite build",
|
|
40
|
+
"dev": "vite",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"test:coverage": "vitest run --coverage"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"react": "^19.2.6",
|
|
47
|
+
"react-dom": "^19.2.6",
|
|
48
|
+
"recharts": "^3.8.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
55
|
+
"@testing-library/react": "^16.3.2",
|
|
56
|
+
"@types/node": "^25.8.0",
|
|
57
|
+
"@types/react": "^19.2.14",
|
|
58
|
+
"@types/react-dom": "^19.2.3",
|
|
59
|
+
"@vitejs/plugin-react": "^6.0.2",
|
|
60
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
61
|
+
"jsdom": "^29.1.1",
|
|
62
|
+
"typescript": "^6.0.3",
|
|
63
|
+
"vite": "^8.0.13",
|
|
64
|
+
"vitest": "^4.1.6"
|
|
65
|
+
}
|
|
66
|
+
}
|