@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 CHANGED
@@ -1,23 +1,17 @@
1
- # πŸ“ˆ pi-analytics β€” Local Analytics for Pi
1
+ # πŸ“ˆ pi-analytics β€” Understand Pi Activity Without Sending Data Away
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-analytics)](https://www.npmjs.com/package/@narumitw/pi-analytics) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- > [!WARNING]
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
- - Starts collecting settled Pi response cycles after installation with no configuration or startup I/O.
13
- - Breaks skill activations down by explicit user invocation, model loading, provider, and model.
14
- - Counts tool calls, failures, average duration, and model attribution.
15
- - Reports logical LLM calls per response with average, median, P95, maximum, and distribution buckets.
16
- - Separates HTTP 429/5xx responses, conservative connection-error categories, recovered errors, and terminal provider failures.
17
- - Offers Today, rolling 7-day, rolling 30-day, and all-time views through one `/analytics` TUI/RPC dashboard.
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
- Try a local checkout from the repository root:
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 storage implementation uses Node's built-in filesystem APIs and has no native database dependency.
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 time range or browse Skills, Tools, Provider reliability, Response cycles, and Data & privacy. Only fully settled cycles are included; active work is omitted.
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`. Automatic retries, overflow-compaction recovery, tool follow-ups, and queued continuations before settlement stay in that cycle.
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. A provider may make several HTTP attempts inside it, so `429 β†’ 429 β†’ 200` is one LLM call, three observed HTTP responses, two provider errors, and a recovered 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 is associated with an active or subsequently started response cycle. This includes skill commands queued while Pi is streaming. It is **Model initiated** when the built-in `read` tool successfully loads the exact canonical `SKILL.md` path Pi discovered. A skill is counted at most once per response cycle, and explicit user use takes precedence.
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 a post-chain acceptance event for input observers. Non-standard loading such as `bash` plus `cat SKILL.md`, unsuccessful reads, and provider behavior invisible to Pi are not counted.
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`. The extension stores the tool name, model attribution, timing, completion state, and final error flag. It cannot reliably distinguish another extension blocking a call from every other tool error, so both appear as errors.
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. The dashboard therefore labels these values as **observed provider errors**. It reports HTTP 429 and 5xx counts; conservative DNS, timeout, connection, TLS, network, and provider categories; recovered errors; and terminal failures. Error messages are classified in memory and discarded.
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
- ## πŸ’¬ Command
101
+ ## πŸ’¬ Commands
92
102
 
93
103
  ```text
94
104
  /analytics
95
105
  ```
96
106
 
97
- The command accepts no arguments. TUI mode uses the full dashboard; RPC mode adapts the same standard screens to dialogs. Print and JSON modes reject the interactive command observably instead of writing ad hoc protocol output.
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. Skills and Tools are searchable browse views with details and model breakdowns. Escape goes Back from nested screens and closes the root. Ctrl+C closes the menu. Data deletion uses Pi TUI Kit's standalone confirmation: Back keeps the dashboard open, Ctrl+C closes it in TUI mode, and cancellation never clears data.
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
- ## πŸ” Local data and privacy
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. On Unix, directories are restricted to mode `0700` and files to `0600`. Linked storage roots, markers, and writer files are rejected.
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. Provider-supplied tool-call IDs are replaced with local ordinals before publication.
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 settled response is one versioned, newline-terminated frame. Frames larger than 1 MiB are dropped. Local writes receive a 500 ms cancellation deadline; Node filesystem cancellation is best-effort, so an operating-system request that has already begun may still finish. The extension reports the first failed or timed-out write and a later recovery without exposing filesystem errors.
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. A crash-truncated final frame is ignored; completed malformed frames and unsupported format versions fail closed without replacing existing files.
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 atomically publish a fresh active generation. Other Pi processes observe that generation before their next write. Records racing with Clear may land immediately before or after the generation switch.
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 the previous generation. If another process still has an obsolete file in use, Clear remains logically complete and reports that physical cleanup is incomplete; stop other Pi processes and clear again. Clearing files is not a secure-erasure guarantee for underlying storage media.
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 deliberately does not open, import, migrate, delete, or rewrite those files, so startup cannot re-enter the old native database path. New analytics start empty.
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. If it does not matter, stop every old Pi process before deleting both files manually. Never copy or remove only the main DB while an old process may still own its WAL.
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. A failed or interrupted local write may be omitted.
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. See [`LICENSE`](./LICENSE).
218
+ MIT.
219
+ See [`LICENSE`](./LICENSE).