tokely 0.5.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean P.D. Meijer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # tokely
2
+
3
+ `tokely` is a Node.js CLI that scans local Claude Code, Codex, Cursor, Gemini CLI, Open Code, and Pi Coding Agent usage data and generates a contribution-style heatmap for the rolling past year.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js `>=22`
8
+
9
+ ## Run with npm
10
+
11
+ Use it without installing:
12
+
13
+ ```bash
14
+ npx tokely
15
+ ```
16
+
17
+ Install it globally:
18
+
19
+ ```bash
20
+ npm install -g tokely
21
+ tokely
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ tokely [--all] [--claude] [--codex] [--cursor] [--gemini] [--opencode] [--pi] [--dark] [--format png|svg|json] [--output ./heatmap-last-year.png]
28
+ ```
29
+
30
+ By default, the CLI:
31
+
32
+ - scans all supported providers
33
+ - writes `./heatmap-last-year.png`
34
+ - infers the date window as the rolling last year ending today
35
+
36
+ ## Options
37
+
38
+ - `--claude`: include only Claude Code data
39
+ - `--codex`: include only Codex data
40
+ - `--cursor`: include only Cursor data
41
+ - `--gemini`: include only Gemini CLI data
42
+ - `--opencode`: include only Open Code data
43
+ - `--pi`: include only Pi Coding Agent data
44
+ - `--all`: merge all providers into one combined graph
45
+ - `--dark`: render the image with the dark theme
46
+ - `-f, --format <png|svg|json>`: choose the output format
47
+ - `-o, --output <path>`: write output to a custom path
48
+ - `-h, --help`: print the help text
49
+
50
+ ## Examples
51
+
52
+ Generate the default PNG:
53
+
54
+ ```bash
55
+ npx tokely
56
+ ```
57
+
58
+ Write an SVG:
59
+
60
+ ```bash
61
+ npx tokely --format svg --output ./out/heatmap.svg
62
+ ```
63
+
64
+ Write JSON for custom rendering:
65
+
66
+ ```bash
67
+ npx tokely --format json --output ./out/heatmap.json
68
+ ```
69
+
70
+ Render only Codex usage:
71
+
72
+ ```bash
73
+ npx tokely --codex
74
+ ```
75
+
76
+ Render only Cursor usage:
77
+
78
+ ```bash
79
+ npx tokely --cursor
80
+ ```
81
+
82
+ Render only Gemini CLI usage:
83
+
84
+ ```bash
85
+ npx tokely --gemini
86
+ ```
87
+
88
+ Render only Pi Coding Agent usage:
89
+
90
+ ```bash
91
+ npx tokely --pi
92
+ ```
93
+
94
+ Render one merged graph across all providers:
95
+
96
+ ```bash
97
+ npx tokely --all
98
+ ```
99
+
100
+ When provider flags are present, `tokely` only loads those providers and only prints availability for those providers.
101
+
102
+ Render a dark-theme SVG:
103
+
104
+ ```bash
105
+ npx tokely --dark --format svg --output ./out/heatmap-dark.svg
106
+ ```
107
+
108
+ ## Output behavior
109
+
110
+ - If `--format` is omitted, the format is inferred from the `--output` extension when possible.
111
+ - If `--output` is omitted, the default filename becomes `heatmap-last-year.<ext>`, `heatmap-last-year_<providers>.<ext>` for explicit provider flags, or `heatmap-last-year_all.<ext>` for `--all`.
112
+ - Supported extensions are `.png`, `.svg`, and `.json`.
113
+ - If neither `--format` nor a recognized output extension is provided, PNG is used.
114
+
115
+ ## Data locations
116
+
117
+ - Claude Code: `$CLAUDE_CONFIG_DIR/*/projects` or `~/.config/claude/projects`, `~/.claude/projects`
118
+ - Older Claude Code layouts: falls back to `$CLAUDE_CONFIG_DIR/stats-cache.json`, `~/.config/claude/stats-cache.json`, or `~/.claude/stats-cache.json` for days not present in project logs
119
+ - Earliest Claude Code activity fallback: uses `$CLAUDE_CONFIG_DIR/history.jsonl`, `~/.config/claude/history.jsonl`, or `~/.claude/history.jsonl` to mark activity-only days when token totals are unavailable
120
+ - Codex: `$CODEX_HOME/sessions` or `~/.codex/sessions`
121
+ - Cursor: reads `cursorAuth/accessToken` and `cursorAuth/refreshToken` from `$CURSOR_STATE_DB_PATH`, `$CURSOR_CONFIG_DIR/User/globalStorage/state.vscdb`, `~/Library/Application Support/Cursor/User/globalStorage/state.vscdb` (macOS), `%APPDATA%/Cursor/User/globalStorage/state.vscdb` (Windows), or `~/.config/Cursor/User/globalStorage/state.vscdb` (Linux), then loads usage from Cursor's CSV export endpoint
122
+ - Gemini CLI: `$GEMINI_CONFIG_DIR/tmp/**/chats/session-*.json` or `~/.gemini/tmp/**/chats/session-*.json`
123
+ - Open Code: prefers `$OPENCODE_DATA_DIR/opencode.db` or `~/.local/share/opencode/opencode.db`, and falls back to `$OPENCODE_DATA_DIR/storage/message` or `~/.local/share/opencode/storage/message`
124
+ - Pi Coding Agent: `$PI_CODING_AGENT_DIR/sessions` or `~/.pi/agent/sessions`
125
+
126
+ When Claude Code falls back to `stats-cache.json`, the daily input/output/cache split is reconstructed from Claude's cached model totals because the older layout does not keep per-request usage logs.
127
+ When Claude Code falls back to `history.jsonl`, those days are rendered as activity-only cells and do not affect the token totals shown in the header.
128
+
129
+ ## Exit behavior
130
+
131
+ - If no provider flags are passed, `tokely` renders every provider with available data.
132
+ - If `--all` is passed, `tokely` loads all providers and renders one combined graph with merged totals, streaks, and model rankings.
133
+ - Pi Coding Agent usage is derived from assistant messages in Pi session logs, grouped by the model that handled each turn.
134
+ - If provider flags are passed and a requested provider has no data, the command exits with an error.
135
+ - If no provider has data, the command exits with an error.
136
+
137
+ ## Environment variables
138
+
139
+ - `TOKELY_FILE_PROCESS_CONCURRENCY`: positive integer file-processing limit for Claude Code and Codex JSONL files. Default: `16`.
140
+ - `TOKELY_MAX_JSONL_RECORD_BYTES`: byte cap for Claude Code and Codex JSONL records, OpenCode JSON documents, and OpenCode SQLite `message.data` payloads. Default: `67108864` (`64 MB`).
141
+
142
+ ## JSONL record handling
143
+
144
+ - Claude Code and Codex JSONL files are streamed through the same bounded record splitter; `tokely` does not materialize whole files in memory.
145
+ - Oversized Claude Code JSONL records fail the file with a clear error that names the file, line number, byte cap, and `TOKELY_MAX_JSONL_RECORD_BYTES`.
146
+ - OpenCode prefers the current SQLite store (`opencode.db`) and falls back to the legacy file-backed message layout.
147
+ - OpenCode legacy JSON message files are read through a bounded JSON document reader before `JSON.parse`.
148
+ - OpenCode SQLite `message.data` payloads use the same byte cap before `JSON.parse`.
149
+ - Oversized OpenCode JSON documents and SQLite message payloads fail clearly with the source path or row label, byte cap, and `TOKELY_MAX_JSONL_RECORD_BYTES`.
150
+ - Only Codex `turn_context` and `event_msg` `token_count` records are parsed for usage aggregation.
151
+ - Oversized irrelevant Codex records are skipped and reported in a warning summary.
152
+ - Oversized relevant Codex records fail the file with a clear error that names the file, line number, byte cap, and `TOKELY_MAX_JSONL_RECORD_BYTES`.
153
+ - Pi Coding Agent session logs are streamed and only assistant messages are parsed for usage aggregation.
154
+
155
+ ## License
156
+
157
+ MIT