@narumitw/pi-analytics 0.49.6 β 0.49.8
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 +76 -37
- package/dist/index.ts +1809 -0
- package/dist/index.ts.map +7 -0
- package/package.json +12 -11
- package/src/analytics.ts +0 -2
package/README.md
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
# π pi-analytics β
|
|
1
|
+
# π pi-analytics β Understand Pi Activity Without Sending Data Away
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-analytics) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
> This extension is experimental. Its metrics, storage format, and dashboard may change between releases.
|
|
7
|
-
|
|
8
|
-
`@narumitw/pi-analytics` is a local-first [Pi coding agent](https://pi.dev) extension that counts model calls, skill activations, tool activity, and observed provider errors without storing conversation or tool content.
|
|
5
|
+
Measure local model, skill, tool, and provider reliability activity without storing conversation or tool content or sending analytics elsewhere.
|
|
9
6
|
|
|
10
7
|
## β¨ Features
|
|
11
8
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
- Stores only content-free metadata in private, versioned JSON Lines files.
|
|
19
|
-
- Uses one writer file per Pi runtime, so concurrent Pi processes never share a routine writer lock.
|
|
20
|
-
- Never starts a server or sends analytics anywhere.
|
|
9
|
+
- Collects content-free metrics automatically after installation.
|
|
10
|
+
- Counts settled response cycles, logical LLM calls, skill activations, tool calls, and observed provider errors.
|
|
11
|
+
- Reports tool failures and duration, model attribution, and per-response call distributions.
|
|
12
|
+
- Separates recovered provider errors from terminal failures.
|
|
13
|
+
- Provides Today, rolling 7-day, rolling 30-day, and all-time views through `/analytics`.
|
|
14
|
+
- Stores private, versioned JSONL locally, isolates concurrent writers, and does not start an analytics server.
|
|
21
15
|
|
|
22
16
|
## π¦ Install
|
|
23
17
|
|
|
@@ -33,13 +27,17 @@ Try the published package without installing:
|
|
|
33
27
|
pi -e npm:@narumitw/pi-analytics
|
|
34
28
|
```
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
Build and try a local checkout from the repository root:
|
|
37
31
|
|
|
38
32
|
```bash
|
|
33
|
+
npm --workspace @narumitw/pi-analytics run build
|
|
39
34
|
pi -e ./packages/pi-analytics
|
|
40
35
|
```
|
|
41
36
|
|
|
42
|
-
The
|
|
37
|
+
The package declares `dist/index.ts`, so an unbuilt local checkout must run the build before Pi loads the package directory.
|
|
38
|
+
|
|
39
|
+
The extension uses Node's built-in filesystem APIs and has no native database dependency.
|
|
40
|
+
Pi extensions run with the Pi process's user permissions, so install only trusted packages.
|
|
43
41
|
|
|
44
42
|
## π Quick start
|
|
45
43
|
|
|
@@ -64,41 +62,58 @@ Provider errors 4
|
|
|
64
62
|
Recovered errors 3
|
|
65
63
|
```
|
|
66
64
|
|
|
67
|
-
Use the menu to change the
|
|
65
|
+
Use the menu to change the range or inspect Skills, Tools, Provider reliability, Response cycles, and Data & privacy.
|
|
66
|
+
The dashboard includes finalized cycles and omits active work.
|
|
68
67
|
|
|
69
68
|
## π Metric definitions
|
|
70
69
|
|
|
71
70
|
### Response cycles and LLM calls
|
|
72
71
|
|
|
73
|
-
A **response cycle** starts when Pi begins agent work and ends at `agent_settled`.
|
|
72
|
+
A **response cycle** starts when Pi begins agent work and normally ends at `agent_settled`.
|
|
73
|
+
Retries, overflow-compaction recovery, tool follow-ups, and queued continuations before settlement remain in that cycle.
|
|
74
74
|
|
|
75
|
-
An **LLM call** is one logical provider generation.
|
|
75
|
+
An **LLM call** is one logical provider generation.
|
|
76
|
+
A provider can make several HTTP attempts within it, so `429 β 429 β 200` counts as one LLM call, three observed HTTP responses, two provider errors, and one recovered generation.
|
|
76
77
|
|
|
77
78
|
### Skills
|
|
78
79
|
|
|
79
|
-
An activation is **User initiated** when an observed interactive or RPC `/skill:<name>` input
|
|
80
|
+
An activation is **User initiated** when an observed interactive or RPC `/skill:<name>` input belongs to an active or subsequently started response cycle.
|
|
81
|
+
This includes skill commands queued while Pi is streaming.
|
|
82
|
+
It is **Model initiated** when Pi's built-in `read` tool successfully loads the exact canonical `SKILL.md` path Pi discovered.
|
|
83
|
+
Each skill counts at most once per response cycle, with explicit user use taking precedence.
|
|
80
84
|
|
|
81
|
-
Pi does not expose a first-class skill-invocation event or
|
|
85
|
+
Pi does not expose a first-class skill-invocation event or post-chain acceptance event to input observers.
|
|
86
|
+
The extension does not count unsuccessful reads, provider behavior hidden from Pi, or non-standard loading such as `bash` plus `cat SKILL.md`.
|
|
82
87
|
|
|
83
88
|
### Tools
|
|
84
89
|
|
|
85
|
-
A tool call starts at Pi's `tool_execution_start` event and finishes at `tool_execution_end`.
|
|
90
|
+
A tool call starts at Pi's `tool_execution_start` event and finishes at `tool_execution_end`.
|
|
91
|
+
The extension stores the tool name, model attribution, timing, completion state, and final error flag.
|
|
92
|
+
Pi does not expose enough information to distinguish a call blocked by another extension from other tool errors, so both count as errors.
|
|
86
93
|
|
|
87
94
|
### Provider reliability
|
|
88
95
|
|
|
89
|
-
Pi exposes HTTP responses and final assistant failures, not every provider-SDK transport retry.
|
|
96
|
+
Pi exposes HTTP responses and final assistant failures, but not every provider-SDK transport retry.
|
|
97
|
+
The dashboard therefore calls these values **observed provider errors**.
|
|
98
|
+
It reports HTTP 429 and 5xx counts, conservative error categories, recovered errors, and terminal failures.
|
|
99
|
+
Raw error messages are classified in memory and discarded.
|
|
90
100
|
|
|
91
|
-
## π¬
|
|
101
|
+
## π¬ Commands
|
|
92
102
|
|
|
93
103
|
```text
|
|
94
104
|
/analytics
|
|
95
105
|
```
|
|
96
106
|
|
|
97
|
-
The command accepts no arguments.
|
|
107
|
+
The command accepts no arguments.
|
|
108
|
+
TUI mode shows the full dashboard, and RPC mode adapts the same screens to dialogs.
|
|
109
|
+
Print and JSON modes reject the command before reading analytics data.
|
|
98
110
|
|
|
99
|
-
The root menu contains Change time range, Skills, Tools, Provider reliability, Response cycles, Data & privacy, and Close.
|
|
111
|
+
The root menu contains Change time range, Skills, Tools, Provider reliability, Response cycles, Data & privacy, and Close.
|
|
112
|
+
Skills and Tools provide searchable details and model breakdowns.
|
|
113
|
+
Escape goes back from nested screens and closes the root, while Ctrl+C closes the menu.
|
|
114
|
+
Deleting data requires confirmation; Back keeps the dashboard open, Ctrl+C closes it in TUI mode, and cancellation leaves data unchanged.
|
|
100
115
|
|
|
101
|
-
##
|
|
116
|
+
## π Security and privacy
|
|
102
117
|
|
|
103
118
|
Current analytics live under:
|
|
104
119
|
|
|
@@ -110,21 +125,35 @@ Current analytics live under:
|
|
|
110
125
|
βββ <opaque-writer-id>.jsonl
|
|
111
126
|
```
|
|
112
127
|
|
|
113
|
-
The opaque IDs are storage coordination identifiers generated by the extension; they are not Pi session IDs.
|
|
128
|
+
The opaque IDs are storage coordination identifiers generated by the extension; they are not Pi session IDs.
|
|
129
|
+
On Unix, directories are restricted to mode `0700` and files to `0600`.
|
|
130
|
+
Linked storage roots, markers, and writer files are rejected.
|
|
114
131
|
|
|
115
|
-
Stored fields are limited to timestamps and durations; extension-generated record IDs; provider/model IDs and thinking level; tool and skill names; user/model skill source; counts, outcomes, and completion states; HTTP status codes; and classified provider-error categories.
|
|
132
|
+
Stored fields are limited to timestamps and durations; extension-generated record IDs; provider/model IDs and thinking level; tool and skill names; user/model skill source; counts, outcomes, and completion states; HTTP status codes; and classified provider-error categories.
|
|
133
|
+
Provider-supplied tool-call IDs are replaced with local ordinals before publication.
|
|
116
134
|
|
|
117
135
|
The extension does **not** store prompts, responses, thinking content, tool arguments or results, raw error messages, HTTP headers, cwd/project/file paths, session names or IDs, or credentials.
|
|
118
136
|
|
|
119
|
-
Each
|
|
137
|
+
Each finalized response cycle is one versioned, newline-terminated frame.
|
|
138
|
+
Frames larger than 1 MiB are dropped.
|
|
139
|
+
Local writes receive a 5-second cancellation deadline.
|
|
140
|
+
Node filesystem cancellation is best-effort, so an operating-system request that has begun may still finish.
|
|
141
|
+
The extension reports the first failed or timed-out write and a later recovery without exposing filesystem errors.
|
|
120
142
|
|
|
121
|
-
`/analytics` streams and validates the active generation, checks cancellation between files and records, and periodically yields to the event loop.
|
|
143
|
+
`/analytics` streams and validates the active generation, checks cancellation between files and records, and periodically yields to the event loop.
|
|
144
|
+
It ignores a crash-truncated final frame.
|
|
145
|
+
Completed malformed frames and unsupported format versions fail closed without replacing existing files.
|
|
122
146
|
|
|
123
147
|
### Clear analytics data
|
|
124
148
|
|
|
125
|
-
Choose **Data & privacy β Clear analytics dataβ¦** to
|
|
149
|
+
Choose **Data & privacy β Clear analytics dataβ¦** to publish a fresh active generation atomically.
|
|
150
|
+
Other Pi processes observe it before their next write.
|
|
151
|
+
A record racing with Clear can land immediately before or after the switch.
|
|
126
152
|
|
|
127
|
-
The extension then removes
|
|
153
|
+
The extension then removes obsolete generations.
|
|
154
|
+
If another process still uses an obsolete file, Clear reports incomplete physical cleanup but the logical clear remains complete.
|
|
155
|
+
Stop other Pi processes and clear again to retry cleanup.
|
|
156
|
+
File deletion does not guarantee secure erasure from the storage medium.
|
|
128
157
|
|
|
129
158
|
## π§ Legacy SQLite data
|
|
130
159
|
|
|
@@ -135,14 +164,18 @@ Versions that used Turso/SQLite stored data in:
|
|
|
135
164
|
<pi-agent-directory>/pi-analytics.db-wal
|
|
136
165
|
```
|
|
137
166
|
|
|
138
|
-
The JSONL version
|
|
167
|
+
The JSONL version does not open, import, migrate, delete, or rewrite these files.
|
|
168
|
+
New analytics start empty.
|
|
139
169
|
|
|
140
|
-
If legacy history matters, stop every old Pi process first and preserve both files together.
|
|
170
|
+
If legacy history matters, stop every old Pi process first and preserve both files together.
|
|
171
|
+
If it does not matter, stop every old Pi process before deleting both files manually.
|
|
172
|
+
Never copy or remove only the main DB while an old process may still own its WAL.
|
|
141
173
|
|
|
142
174
|
## π§ Limitations
|
|
143
175
|
|
|
144
176
|
- There are no retention settings; records remain until explicitly cleared.
|
|
145
|
-
- Analytics are best-effort derived metadata.
|
|
177
|
+
- Analytics are best-effort derived metadata.
|
|
178
|
+
A failed or interrupted local write may be omitted.
|
|
146
179
|
- Large all-time histories require scanning the active JSONL generation when the dashboard opens.
|
|
147
180
|
- Prometheus, JSON/CSV export, cloud sync, browser dashboards, token/cost reporting, and project attribution are not included.
|
|
148
181
|
- Statistics cover only events visible through Pi's public extension API.
|
|
@@ -151,6 +184,9 @@ If legacy history matters, stop every old Pi process first and preserve both fil
|
|
|
151
184
|
|
|
152
185
|
```text
|
|
153
186
|
packages/pi-analytics/
|
|
187
|
+
βββ dist/ # Generated TypeScript runtime loaded by Jiti
|
|
188
|
+
βββ scripts/
|
|
189
|
+
β βββ build-runtime.mjs # Deterministic runtime builder and boundary validator
|
|
154
190
|
βββ src/
|
|
155
191
|
β βββ index.ts # Thin Pi entrypoint
|
|
156
192
|
β βββ analytics.ts # Pi lifecycle, command, and session ownership
|
|
@@ -171,10 +207,13 @@ packages/pi-analytics/
|
|
|
171
207
|
βββ tsconfig.json
|
|
172
208
|
```
|
|
173
209
|
|
|
210
|
+
The generated runtime is built from the authoritative `src/index.ts` graph and does not import back into `src`.
|
|
211
|
+
|
|
174
212
|
## π Keywords
|
|
175
213
|
|
|
176
214
|
Pi extension, Pi coding agent, local analytics, agent skills, tool usage, model calls, provider reliability, JSON Lines, content-free metrics.
|
|
177
215
|
|
|
178
216
|
## π License
|
|
179
217
|
|
|
180
|
-
MIT.
|
|
218
|
+
MIT.
|
|
219
|
+
See [`LICENSE`](./LICENSE).
|