dev_sandbox/.pi/agent/extensions/insights/README.md
2026-06-18 14:52:14 -04:00

37 lines
1.2 KiB
Markdown

# /insights
A pi extension that analyzes your recent pi session history and generates an
interactive HTML usage report — like Claude Code's `/insights`.
## Usage
```
/insights # analyze the last 30 days
/insights 7 # analyze the last 7 days
```
The report opens in your browser and is saved to:
```
~/.pi/agent/usage-data/report.html
```
## How it works
1. `analyze.py` walks `~/.pi/agent/sessions/*/*.jsonl` and computes deterministic
stats (sessions, prompts, tool calls, tokens, cost, per-project breakdown,
activity by hour/weekday/day, longest/costliest sessions). No LLM, no tokens.
2. The command feeds those stats to the model, which writes a qualitative
narrative (summary, highlights, friction patterns, suggestions) by calling the
`write_insights_report` tool.
3. `render.py` combines the stats + narrative into a self-contained HTML report
and opens it.
Intermediate files (`stats.json`, `narrative.json`) are also written to
`~/.pi/agent/usage-data/` for inspection.
## Files
- `index.ts` — extension entry point (command + tool)
- `analyze.py` — deterministic session analytics → JSON
- `render.py` — stats + narrative JSON → HTML report