tokelytics 0.1.0

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 ADDED
@@ -0,0 +1,69 @@
1
+ # Tokelytics agent
2
+
3
+ Reads local AI-CLI usage logs and streams them to your Tokelytics dashboard in
4
+ realtime. v1 connectors: **Claude Code** (`~/.claude/projects`) and **Codex**
5
+ (`~/.codex/sessions`). Only token counts/model/timestamps are read — never your
6
+ prompts or responses.
7
+
8
+ ## Use it
9
+
10
+ ```
11
+ npx tokelytics@latest login # opens your browser to approve — no setup, no keys
12
+ npx tokelytics@latest watch # streams usage in realtime
13
+ ```
14
+
15
+ Other commands: `sync` (one pass), `status`, `logout`.
16
+
17
+ ### How login works (and why there's no API key)
18
+
19
+ `login` starts a tiny server on `127.0.0.1`, opens the Tokelytics dashboard at
20
+ `/connect#<port>-<code>`, and waits. In the browser you sign in (or you're
21
+ already signed in) and click **Approve**; the dashboard hands your Firebase
22
+ **refresh token** back to that loopback server. The agent then mints its own ID
23
+ tokens from that refresh token as needed.
24
+
25
+ The agent ships **no secret** — only the public Firebase web config (an `apiKey`
26
+ that identifies the project, not a credential; Firestore Security Rules are what
27
+ protect your data). The printed verification code ties the approval to the exact
28
+ `login` you started, and the loopback only ever listens on localhost.
29
+
30
+ If the browser doesn't open automatically, the command prints the link — click
31
+ it. On a headless/SSH box, open the printed link in any browser on a machine
32
+ where you can sign in (it must be able to reach `127.0.0.1:<port>` on the box, so
33
+ forward the port or run `login` where a browser is available).
34
+
35
+ ## Configuration (optional)
36
+
37
+ Nothing is required — the agent targets the hosted `tokelytics` project by
38
+ default. To override (self-hosting, a staging project, or the emulator), use env
39
+ vars or `~/.tokelytics/config.json` (Windows: `C:\Users\<you>\.tokelytics\config.json`):
40
+
41
+ | Env var | Purpose |
42
+ |---|---|
43
+ | `TOKELYTICS_FIREBASE_API_KEY` / `TOKELYTICS_FIREBASE_PROJECT_ID` | Point at a different Firebase project |
44
+ | `TOKELYTICS_WEB_URL` | Dashboard URL the login flow opens (default `https://tokelytics.web.app`) |
45
+ | `TOKELYTICS_NO_BROWSER` | Don't try to auto-open a browser; just print the link |
46
+ | `TOKELYTICS_HOME` | Override the config/state dir (default `~/.tokelytics`) |
47
+
48
+ See [`config.example.json`](config.example.json) for the file form.
49
+
50
+ ## Run from the repo (before publishing to npm)
51
+
52
+ ```
53
+ npm run build -w @tokelytics/core # if not already built
54
+ npx tsc -b agent # build the agent
55
+ node agent/dist/cli.js login
56
+ node agent/dist/cli.js watch
57
+ ```
58
+
59
+ ## Point at the local emulator (development)
60
+
61
+ ```
62
+ export FIRESTORE_EMULATOR_HOST=localhost:8080
63
+ export FIREBASE_AUTH_EMULATOR_HOST=localhost:9099
64
+ node agent/dist/cli.js sync
65
+ ```
66
+
67
+ > Dev-only: a legacy in-CLI OAuth login (`login --google` / `--github`) still
68
+ > exists for when you'd rather sign in without the browser handoff. It requires
69
+ > a Google/GitHub OAuth client configured via env and is not the default.