codex-token-tracker 0.2.0 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,82 @@
2
2
 
3
3
  All notable changes to `codex-token-tracker`. This project follows [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 0.2.2 — 2026-09-02
6
+
7
+ Installs on machines that cannot download Electron.
8
+
9
+ ### Fixed
10
+
11
+ - **`npm install -g` no longer runs Electron's install script.** `electron` was an optional dependency, and
12
+ `menubar` declared it as a hard peer dependency, so every install ran Electron's `install.js` — a ~100 MB
13
+ download from GitHub. When that download failed (firewalled build servers, no proxy) npm aborted the
14
+ **entire** install instead of skipping the optional package — Node 16's npm 8 does so outright, npm 11 does
15
+ the same once the script runs — and the retry died with
16
+ `Cannot find module …/node_modules/electron/install.js`, leaving the machine unable to install the tracker
17
+ even for headless use. Neither package is a dependency any more: `menubar` is bundled into `dist/main.js`,
18
+ and the CLI downloads the Electron runtime itself on first GUI launch into
19
+ `~/.codex-tracker/electron/<version>/` — the same downloader 0.1.1 added for package managers that skip
20
+ install scripts — honouring `ELECTRON_MIRROR` and `HTTPS_PROXY`. A globally installed `electron` is still
21
+ preferred when present. Headless machines never download Electron at all, and a plain install is ~40
22
+ packages instead of ~75.
23
+
24
+ ### Changed
25
+
26
+ - The *Electron download failed* message now points at `ELECTRON_MIRROR` / `HTTPS_PROXY` and
27
+ `codex-tracker menubar` rather than `npm rebuild electron`.
28
+
29
+ ## 0.2.1 — 2026-09-01
30
+
31
+ A manual **Sync** button that recalibrates this device's numbers on the dashboard.
32
+
33
+ ### Added
34
+
35
+ - **Full sync.** The popover header gets a **⟳** button (also *Sync now* in the Account card and the tray
36
+ menu, and `codex-token-tracker sync` on the CLI). Unlike the background upload — which every 60 s pushes
37
+ only the hour buckets and sessions that changed — a full sync throws away every cache on the way:
38
+ 1. re-reads the config, so agents enabled since start-up are picked up;
39
+ 2. re-discovers every session directory and re-parses every transcript from scratch — Codex plus the
40
+ coding agents running on your Codex subscription (pi, OpenCode, Cline / Roo / Kilo, Hermes) and any
41
+ configured `extraSessionDirs` — instead of skipping files whose size and mtime are unchanged;
42
+ 3. recomputes the aggregates with the current pricing table;
43
+ 4. re-uploads **everything**, so the dashboard's totals for this device are replaced by the freshly
44
+ computed ones;
45
+ 5. pulls the other devices' rows and the live rate limits back down.
46
+
47
+ Use it when a machine's numbers look wrong, after installing a new agent, or after an update that
48
+ changes the pricing table. It is manual only — never on a timer — because it re-sends the whole history.
49
+ - A banner in the popover reports the phase while a sync runs (*Rescanning every agent's transcripts…*,
50
+ *Re-uploading this device's history…*) and then the result, e.g. `Synced codex, pi · 75 files ·
51
+ 75 sessions · 70 hours re-uploaded`. Signed out, the rescan still runs and nothing leaves the machine.
52
+ - `codex-token-tracker sync` prints the same summary and exits non-zero if the sync failed.
53
+
54
+ - **Dev builds target the dev environment.** A build now carries its channel, stamped by
55
+ `scripts/build.mjs`: only `--release` (what `prepack` runs) produces a production build, so every
56
+ published tarball is prod and every local `pnpm build` / `pnpm dev` is dev. A dev build
57
+ - defaults to the local dashboard `http://localhost:3000` instead of `https://codex.chenli.dev`, and
58
+ therefore uploads to whatever Convex deployment that dashboard advertises — the dev one;
59
+ - keeps its config, device token and upload state in `~/.codex-tracker-dev`, so a local run can
60
+ never overwrite the production token or the record of what was already pushed to production;
61
+ - defaults `checkUpdates` to `false` and refuses `codex-token-tracker update`, which would otherwise
62
+ install the published package over the checkout;
63
+ - runs as `Codex Tracker (dev)` with its own Electron userData directory and macOS LaunchAgent, so it
64
+ can run **beside** an installed copy instead of fighting it for the single-instance lock;
65
+ - shows an orange **DEV** badge in the popover header and names its dashboard and config directory in
66
+ `--version`, `status` and `paths`.
67
+
68
+ `--dashboard <url>`, `config set dashboardUrl` and `CODEX_TRACKER_HOME` still override all of it.
69
+
70
+ ### Changed
71
+
72
+ - `Uploader.pushAll()` takes a `{ full }` option that clears the pushed-buckets/pushed-sessions record
73
+ before building the payload, and waits for an in-flight incremental push instead of skipping the call.
74
+ - `SessionStore.reset()` drops the parsed-file index so a following deep refresh re-reads everything.
75
+ - Packaging scripts: `build:release` builds with the prod channel; `prepack` runs it (so `npm pack` and
76
+ `npm publish` always ship a prod build) and `postpack` restores the dev build in `dist/`.
77
+ `prepublishOnly` now only typechecks.
78
+ - `app.setName()` moved ahead of `requestSingleInstanceLock()` — the lock is keyed on the userData
79
+ directory, which is derived from the name.
80
+
5
81
  ## 0.2.0 — 2026-09-01
6
82
 
7
83
  Pricing accuracy, an honest tokens/s number, and self-update.
package/README.md CHANGED
@@ -27,9 +27,11 @@ This installs two equivalent commands on your PATH: **`codex-token-tracker`** an
27
27
  Already installed? `codex-token-tracker update` fetches the newest published version and installs it
28
28
  with whichever package manager you used (npm / pnpm / yarn / bun).
29
29
 
30
- > **npm 11+ / pnpm 10+ block Electron's install script by default.** That's fine: the first `codex-tracker` run downloads the Electron runtime itself (~100 MB, once). To do it during install instead: `npm install -g codex-token-tracker --allow-scripts=electron`.
30
+ > **Electron is downloaded on first launch, not during install.** `npm install -g` never runs Electron's install script, so the install succeeds on locked-down servers and headless machines download nothing. The first `codex-tracker` run on a desktop fetches the runtime (~100 MB, once) into `~/.codex-tracker/electron/<version>/`, honouring `ELECTRON_MIRROR` (e.g. `https://npmmirror.com/mirrors/electron/`) and `HTTPS_PROXY`. A globally installed `electron` (`npm i -g electron`) is used instead when present.
31
31
 
32
- Node.js 20+ is required. Electron is an *optional* dependency: if its binary cannot be downloaded (locked-down servers, WSL without a desktop), the package still installs and runs in agent mode.
32
+ Node.js 20+ is required. Electron is not an npm dependency: if the runtime cannot be downloaded (locked-down servers, WSL without a desktop), the package still installs and runs in agent mode.
33
+
34
+ > **Stuck on Node 16?** Install [`codex-token-tracker-nodejs16`](https://www.npmjs.com/package/codex-token-tracker-nodejs16) instead — the same app, same features, same version number, built from these same sources for Node 16.8+. Use one or the other on a machine, not both, since they install the same commands.
33
35
 
34
36
  ## Quick start
35
37
 
@@ -61,6 +63,7 @@ The tracker discovers the Convex deployment through `<dashboard>/api/config`.
61
63
  | `codex-tracker login [--dashboard <url>]` | Device-code login |
62
64
  | `codex-tracker logout` | Forget the device token (local data stays) |
63
65
  | `codex-tracker status [--json]` | Today / 7d / 30d usage, live session, rate limits, models |
66
+ | `codex-tracker sync` | Full sync: rescan every agent and re-upload this device's whole history |
64
67
  | `codex-tracker paths` | Detected Codex session directories |
65
68
  | `codex-tracker config get [key]` / `config set <key> <value>` | Settings (see below) |
66
69
  | `codex-tracker lang <en\|zh\|auto>` | Display language |
@@ -71,10 +74,35 @@ The tracker discovers the Convex deployment through `<dashboard>/api/config`.
71
74
 
72
75
  - Tray title shows today's tokens (`12.4k`) — `config set trayTitle tokens|cost|none`
73
76
  - Click: popover with Today, Live session (tokens/s, context window, rate limits), Activity heatmap, Models, Account
74
- - Right-click: Open dashboard, Sign in/out, Language, Launch at login, Refresh, Check for updates, Quit
77
+ - Right-click: Open dashboard, Sign in/out, Language, Launch at login, Refresh, **Sync now**, Check for updates, Quit
75
78
  - A banner appears at the top of the popover when a newer version is published; **Update** installs it and the app asks you to restart
76
79
  - Launch at login uses a LaunchAgent on macOS and the registry run key on Windows
77
80
 
81
+ ## Sync
82
+
83
+ The tracker uploads continuously in the background: every 60 s it sends the hour buckets and sessions
84
+ that *changed* since the last push. **Sync** does the full version instead — use it when the dashboard's
85
+ numbers for this machine look wrong, after you install a new agent, or after an update that changes the
86
+ pricing table.
87
+
88
+ Press the **⟳** button in the popover header (or *Sync now* in the Account card and the tray menu, or run
89
+ `codex-tracker sync`). It:
90
+
91
+ 1. re-reads the config, so agents enabled since the app started are picked up;
92
+ 2. re-discovers **every** session directory and re-parses **every** transcript from scratch — Codex plus
93
+ the coding agents running on your Codex subscription (pi, OpenCode, Cline / Roo / Kilo, Hermes) and any
94
+ `extraSessionDirs` you configured — instead of skipping files whose size and mtime are unchanged;
95
+ 3. recomputes all aggregates with the current pricing table;
96
+ 4. re-uploads **everything**, not just what changed, so the dashboard's totals for this device are
97
+ replaced by the freshly computed ones — this is the calibration step;
98
+ 5. pulls the other devices' rows and the live rate limits back down.
99
+
100
+ A banner reports the phase while it runs and then what it found (`Synced codex, pi · 75 files ·
101
+ 75 sessions · 70 hours re-uploaded`). Signed out, steps 1-3 still run and nothing leaves the machine.
102
+
103
+ A full sync re-sends your whole history, so it costs more bandwidth than a normal push — it is a manual
104
+ action, never on a timer.
105
+
78
106
  ## Windows and WSL2
79
107
 
80
108
  **Native Windows**: `npm i -g codex-token-tracker` in PowerShell, then `codex-tracker`. The tray app also scans every WSL distro (`\\wsl$\<distro>\home\*\.codex\sessions`) so sessions run inside WSL are counted.
@@ -199,7 +227,42 @@ CODEX_TRACKER_DEVTOOLS=1 ... # op
199
227
  pnpm --filter codex-token-tracker build:icons # regenerate tray icons
200
228
  ```
201
229
 
202
- Publishing (from the repo root): `pnpm release:menubar` — `prepublishOnly` rebuilds and typechecks first.
230
+ ### Dev builds vs published builds
231
+
232
+ A build knows which environment it belongs to, so a local test run can never write into production.
233
+ `scripts/build.mjs` stamps the channel at bundle time: **only `--release` produces a prod build**, which
234
+ is what `prepack` runs — so every tarball and every `npm publish` is prod, and every `pnpm build`,
235
+ `pnpm dev` and watch-mode rebuild is dev.
236
+
237
+ | | dev build (`pnpm build`) | published build (`npm i -g codex-token-tracker`) |
238
+ | --- | --- | --- |
239
+ | Dashboard default | `http://localhost:3000` | `https://codex.chenli.dev` |
240
+ | Convex deployment | whatever the local dashboard's `/api/config` advertises — the **dev** one | production |
241
+ | Config, device token, upload state | `~/.codex-tracker-dev` | `~/.codex-tracker` |
242
+ | `checkUpdates` default | `false` (`update` refuses to run) | `true` |
243
+ | App name / Electron userData | `Codex Tracker (dev)` | `Codex Tracker` |
244
+ | macOS LaunchAgent | `dev.codex-tracker.menubar.dev` | `dev.codex-tracker.menubar` |
245
+ | Popover | orange **DEV** badge in the header | — |
246
+
247
+ Because the two differ in app name and config directory, **a dev build and an installed one can run at
248
+ the same time**, each with its own tray icon, device token and upload state.
249
+
250
+ To test against a dev environment, start the dashboard and Convex, then run the local build:
251
+
252
+ ```bash
253
+ cd apps/dashboard && npx convex dev # terminal 1
254
+ pnpm dev # terminal 2 — http://localhost:3000
255
+ pnpm --filter codex-token-tracker build # terminal 3
256
+ node packages/menubar/bin/codex-tracker.js login # → localhost:3000, no --dashboard needed
257
+ node packages/menubar/bin/codex-tracker.js menubar
258
+ ```
259
+
260
+ Both defaults are only *defaults*: `--dashboard <url>` and `config set dashboardUrl <url>` still point
261
+ either build anywhere, and `CODEX_TRACKER_HOME` still overrides the config directory.
262
+
263
+ Publishing (from the repo root): `pnpm release:menubar` — `prepublishOnly` typechecks and `prepack`
264
+ makes the release build, so a published tarball is never accidentally a dev build. `postpack` restores
265
+ the dev build in `dist/` afterwards, so your working copy keeps pointing at localhost.
203
266
 
204
267
  ## License
205
268
 
@@ -207,6 +270,6 @@ MIT
207
270
 
208
271
  ## Troubleshooting
209
272
 
210
- - **"Electron is not installed" / tray app does not start** – the Electron binary is downloaded by an install script. If your package manager skipped or cached it incompletely, run `npm rebuild electron` (or `node "$(npm root -g)/codex-token-tracker/node_modules/electron/install.js"`). With pnpm, allow the build script (`pnpm approve-builds`). The headless `codex-tracker agent` and `codex-tracker status` work without Electron.
273
+ - **"Electron download failed" / tray app does not start** – the CLI downloads the Electron runtime on first launch from GitHub releases into `~/.codex-tracker/electron/<version>/`. Behind a firewall set `ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` (or `HTTPS_PROXY`) and run `codex-tracker menubar` again; a half-finished download can be cleared by deleting that directory. A manually installed `npm i -g electron` is also picked up. The headless `codex-tracker agent` and `codex-tracker status` work without Electron.
211
274
  - **Nothing is tracked** – run `codex-tracker paths`; Codex must have written rollouts under `~/.codex/sessions` (or set `CODEX_HOME`). Add other locations with `codex-tracker config set extraSessionDirs '["/path/to/sessions"]'`.
212
275
  - **Uploads fail with BAD_TOKEN** – the device was revoked in the dashboard; run `codex-tracker login` again.