usagemax 0.3.3 → 0.3.7
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 +208 -177
- package/package.json +18 -2
- package/src/cli.js +266 -59
- package/src/progress.js +73 -0
- package/src/resume.js +3 -1
- package/src/service.js +67 -5
- package/src/transport.js +76 -0
- package/src/updates.js +99 -0
package/README.md
CHANGED
|
@@ -1,200 +1,231 @@
|
|
|
1
1
|
# UsageMax CLI
|
|
2
2
|
|
|
3
|
-
Connect
|
|
3
|
+
Connect the AI usage history on a computer to one private UsageMax workspace.
|
|
4
|
+
The CLI is deliberately short-lived: it scans locally, uploads bounded
|
|
5
|
+
aggregates, and exits.
|
|
6
|
+
|
|
7
|
+
[UsageMax](https://usagemax.com) · [Account](https://usagemax.com/account) ·
|
|
8
|
+
[CLI documentation](https://usagemax.com/cli.md) ·
|
|
9
|
+
[API contract](https://usagemax.com/openapi.json) ·
|
|
10
|
+
[npm package](https://www.npmjs.com/package/usagemax) ·
|
|
11
|
+
[source repository](https://github.com/SYMBaiEX/usagemax/tree/main/packages/cli)
|
|
12
|
+
|
|
13
|
+
This package is the open-source `usagemax` command-line collector. It is not a
|
|
14
|
+
JavaScript or Python SDK and does not expose an import API. For programmatic
|
|
15
|
+
integrations, use the documented [OpenAPI contract](https://usagemax.com/openapi.json)
|
|
16
|
+
or the public [agent surfaces](https://usagemax.com/?mode=agent); the package
|
|
17
|
+
itself is intended to be invoked as a short-lived local process.
|
|
18
|
+
|
|
19
|
+
See the repository's [SDK and integration surface](../../docs/sdk-ecosystem.md)
|
|
20
|
+
for the supported client matrix. UsageMax does not advertise Python or Go
|
|
21
|
+
packages until they are separately reviewed and published.
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node.js 20 or newer
|
|
26
|
+
- Bun or npm
|
|
27
|
+
- A UsageMax account and one link code per computer or WSL distribution
|
|
4
28
|
|
|
5
29
|
## Quick start
|
|
6
30
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
31
|
+
```bash
|
|
32
|
+
# Create a one-use code at https://usagemax.com/account.
|
|
33
|
+
bunx usagemax link UMX-XXXX-XXXX-XXXX-XXXX
|
|
34
|
+
|
|
35
|
+
# npm users can run the same one-shot command with npx.
|
|
36
|
+
npx --yes usagemax link UMX-XXXX-XXXX-XXXX-XXXX
|
|
37
|
+
|
|
38
|
+
# Preview, then upload changed local usage.
|
|
39
|
+
bunx usagemax sync --dry-run --explain
|
|
40
|
+
bunx usagemax sync
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The CLI checks npm's `latest` dist-tag at most twice per day and never replaces
|
|
44
|
+
itself silently. Run `usagemax update sync` to hand a command to the current
|
|
45
|
+
release without typing `@latest`, or set `USAGEMAX_AUTO_UPDATE=1` for an
|
|
46
|
+
explicit automatic handoff. Use `--no-update-check` or set
|
|
47
|
+
`USAGEMAX_DISABLE_UPDATE_CHECK=1` in offline environments. Interactive
|
|
48
|
+
terminals show a small stderr progress line; JSON,
|
|
49
|
+
quiet, CI, and scheduled runs remain machine-readable and quiet.
|
|
50
|
+
|
|
51
|
+
Agent-friendly checks can request JSON and keep the secret out of arguments and
|
|
52
|
+
logs. This example only inspects local source coverage:
|
|
10
53
|
|
|
11
54
|
```bash
|
|
12
|
-
|
|
55
|
+
set +x
|
|
56
|
+
bunx usagemax doctor --deep --json | jq '{complete, sources: [.sources[] | {name, status}]}'
|
|
13
57
|
```
|
|
14
58
|
|
|
15
|
-
The
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
59
|
+
The JSON shape is intended for local automation; unsupported or unavailable
|
|
60
|
+
sources remain explicitly reported rather than being inferred.
|
|
61
|
+
|
|
62
|
+
The link code expires after ten minutes and is consumed once. The account-side
|
|
63
|
+
computer name is retained. Pass `--name "Work laptop"` only when the current
|
|
64
|
+
CLI should explicitly override it.
|
|
21
65
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
installation
|
|
66
|
+
Each installation gets a stable random ID and a new write-only collector key.
|
|
67
|
+
Relinking or renaming that installation rotates the key without creating a
|
|
68
|
+
second device. Do not link two installations to the same copied or
|
|
69
|
+
network-mounted log tree; cross-installation duplicate history is ambiguous.
|
|
26
70
|
|
|
27
71
|
## Commands
|
|
28
72
|
|
|
73
|
+
```text
|
|
74
|
+
usagemax Sync changed local usage
|
|
75
|
+
usagemax link <code> [options] Link and sync a computer
|
|
76
|
+
usagemax sync [options] Reconcile local usage once
|
|
77
|
+
usagemax status Show local link state
|
|
78
|
+
usagemax doctor Check discovered sources
|
|
79
|
+
usagemax report [ccusage args] Run a local ccusage report
|
|
80
|
+
usagemax token status Diagnose a key piped on stdin
|
|
81
|
+
usagemax service install Opt into periodic OS checkpoints
|
|
82
|
+
usagemax service status|run|uninstall
|
|
83
|
+
usagemax unlink [--revoke] Remove local credentials
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Useful options:
|
|
87
|
+
|
|
29
88
|
```bash
|
|
30
|
-
bunx usagemax
|
|
31
|
-
bunx usagemax sync
|
|
32
|
-
bunx usagemax sync --
|
|
33
|
-
bunx usagemax
|
|
34
|
-
bunx usagemax
|
|
35
|
-
|
|
36
|
-
bunx usagemax link UMX-… --no-sync # link without uploading yet
|
|
37
|
-
bunx usagemax status # show link and last-sync state
|
|
38
|
-
bunx usagemax doctor # metadata-only source check
|
|
39
|
-
bunx usagemax doctor --deep --json # machine-readable retained-history audit
|
|
40
|
-
bunx usagemax report # open ccusage's local daily report
|
|
41
|
-
bunx usagemax report session --breakdown
|
|
42
|
-
bunx usagemax unlink # remove the local collector key
|
|
43
|
-
bunx usagemax unlink --revoke # disable future uploads, then remove locally
|
|
89
|
+
bunx usagemax sync --full # all retained local history
|
|
90
|
+
bunx usagemax sync --archives # one-time compressed-history recovery
|
|
91
|
+
bunx usagemax sync --restart # restart an expired saved upload
|
|
92
|
+
bunx usagemax status --remote --json # remote check; secret is never printed
|
|
93
|
+
bunx usagemax doctor --deep --json # parse and audit retained history
|
|
94
|
+
bunx usagemax link UMX-… --no-sync # link without uploading yet
|
|
44
95
|
```
|
|
45
96
|
|
|
97
|
+
## Sources and coverage
|
|
98
|
+
|
|
46
99
|
UsageMax pins [ccusage v20.0.20](https://github.com/ccusage/ccusage/releases/tag/v20.0.20)
|
|
47
|
-
and supports
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
The
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
100
|
+
and supports its 16 adapters: Amp, Claude Code, Codebuff, Codex, GitHub Copilot
|
|
101
|
+
CLI, Factory Droid, Gemini CLI, Goose, Grok Build, Hermes, Kilo Code, Kimi CLI,
|
|
102
|
+
OpenClaw, OpenCode, Pi, and Qwen Code. Named Pi-format stores are discovered as
|
|
103
|
+
well.
|
|
104
|
+
|
|
105
|
+
The collector follows the supported provider environment overrides and bounded
|
|
106
|
+
home locations. It recognizes Claude Desktop sessions, `.cc-mirror`, renamed
|
|
107
|
+
Claude/Codex backup folders, and supported Windows homes from WSL. In WSL, use
|
|
108
|
+
one collector for the Windows provider homes it can read instead of linking the
|
|
109
|
+
same history again from Windows.
|
|
110
|
+
|
|
111
|
+
Full scans catalog retained history from 2024 onward. `sync --archives` safely
|
|
112
|
+
extracts supported Claude JSONL members into a private temporary directory and
|
|
113
|
+
removes them after reconciliation. Normal runs do not crawl the whole disk or
|
|
114
|
+
unpack archives.
|
|
115
|
+
|
|
116
|
+
Cursor, Windsurf, Aider, Continue, Cline, Roo Code, hosted agents, and direct
|
|
117
|
+
provider API traffic may not leave a stable local token ledger. Use UsageMax's
|
|
118
|
+
native or OTLP/HTTP JSON contract, or a provider billing export, when local
|
|
119
|
+
evidence is unavailable. Unsupported usage is never guessed.
|
|
120
|
+
|
|
121
|
+
## Safe collector diagnostics
|
|
122
|
+
|
|
123
|
+
An advanced key from **Advanced · custom telemetry collector** is a
|
|
124
|
+
`umx_` prefix followed by 64 lowercase hexadecimal characters. Pipe it through
|
|
125
|
+
stdin; never pass it as an argument or put it in a URL:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
set +x
|
|
129
|
+
printf '%s' "$USAGEMAX_COLLECTOR_TOKEN" \
|
|
130
|
+
| bunx usagemax token status \
|
|
131
|
+
--device-id "$USAGEMAX_INSTALLATION_ID" \
|
|
132
|
+
--json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The `token status` command is included in CLI `0.3.7`. If a fresh environment
|
|
136
|
+
still has an older npm tag, run `usagemax update token status` or
|
|
137
|
+
`node packages/cli/src/cli.js token status` from this repository until the new
|
|
138
|
+
package is published.
|
|
139
|
+
|
|
140
|
+
The response is read-only and contains only status, type, scopes, profile/name,
|
|
141
|
+
activation state, and a binding result of `unbound`, `bound`, `matched`, or
|
|
142
|
+
`mismatch`. It never returns the token, hash, or raw authorized UUID.
|
|
143
|
+
|
|
144
|
+
For a numeric-only result suitable for a smoke check:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
set +x
|
|
148
|
+
printf '%s' "$USAGEMAX_COLLECTOR_TOKEN" \
|
|
149
|
+
| bunx usagemax token status \
|
|
150
|
+
--device-id "$USAGEMAX_INSTALLATION_ID" --json \
|
|
151
|
+
| jq -r '[.httpStatus, (if .ingestAuthorized then 1 else 0 end)] | @tsv'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`200 1` is active and ingestion-authorized. `200 0` is recognized but blocked;
|
|
155
|
+
inspect `status` and `scopeStatus` in the unfiltered JSON. `409 0` is a device
|
|
156
|
+
binding mismatch. `401 0` means the format/key was rejected.
|
|
157
|
+
|
|
158
|
+
New advanced keys are active immediately and need no activation or propagation.
|
|
159
|
+
They bind on their first valid write. Linked CLI keys are bound during the link
|
|
160
|
+
exchange. A `401` means the key format is invalid or the key is unknown,
|
|
161
|
+
revoked, disabled, or from another deployment. A `409` means the supplied
|
|
162
|
+
installation does not match. A recognized key missing `telemetry:write` has
|
|
163
|
+
`status: scope_missing`, `scopeStatus: missing_telemetry_write`, and
|
|
164
|
+
`ingestAuthorized: false`.
|
|
165
|
+
|
|
166
|
+
For a write-path smoke check, the root README includes a `curl` request that
|
|
167
|
+
sends one `agent_state` event with all token counters and `costMicros` set to
|
|
168
|
+
zero. It is observability-only: `agent_state` does not update accounting, and
|
|
169
|
+
the probe may bind an otherwise unbound advanced key.
|
|
170
|
+
|
|
171
|
+
## Privacy and resource use
|
|
172
|
+
|
|
173
|
+
The CLI uploads aggregate token counters, provider/model names, source names,
|
|
174
|
+
dates, cost provenance, coverage state, and opaque SHA-256 session identities.
|
|
175
|
+
It never uploads prompts, completions, source code, file contents, project
|
|
176
|
+
paths, tool payloads, or provider credentials.
|
|
177
|
+
|
|
178
|
+
Every sync is one-shot. A complete unchanged inventory can skip parsing and
|
|
179
|
+
uploading; date rollover, new sources, a weekly reconciliation, `--full`, or
|
|
180
|
+
`--archives` triggers the appropriate bounded scan. Decreases and deletions are
|
|
181
|
+
protected while coverage is incomplete.
|
|
182
|
+
|
|
183
|
+
Optional scheduling invokes the same process at low priority:
|
|
131
184
|
|
|
132
185
|
```bash
|
|
133
186
|
bun install -g usagemax
|
|
134
187
|
usagemax service install # approximately every 15 minutes
|
|
135
|
-
usagemax service install --every 30 #
|
|
136
|
-
usagemax service status
|
|
137
|
-
usagemax service
|
|
138
|
-
usagemax service uninstall # stop future jobs; retain account/data
|
|
188
|
+
usagemax service install --every 30 # 5–1440 minutes
|
|
189
|
+
usagemax service status
|
|
190
|
+
usagemax service uninstall
|
|
139
191
|
```
|
|
140
192
|
|
|
141
|
-
|
|
142
|
-
Scheduler on Windows.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
are honored up to 60 seconds; longer waits stop with an instruction to retry later.
|
|
181
|
-
Only completion's `snapshot_run_incomplete` HTTP 409 is retried, because server
|
|
182
|
-
cleanup can still be pending. Authentication, validation and other conflicts fail
|
|
183
|
-
with an actionable message and retain the journal. JSON `accepted` is null for
|
|
184
|
-
uploads because lost responses/replays cannot reliably reconstruct that count;
|
|
185
|
-
`changedRows` is the local planned count, not a server accounting receipt.
|
|
186
|
-
|
|
187
|
-
Each sorted source/day is sent as ordered chunks of at most 100 rows. Each has a
|
|
188
|
-
unique partitionId, zero-based chunkIndex and shared chunkCount. The payload hash
|
|
189
|
-
covers `{source, day, complete, pricingVersion, chunkIndex, chunkCount, rows}` in
|
|
190
|
-
that order. `partitionCount` counts transmitted chunks. The server must accept
|
|
191
|
-
this protocol, receipt replays, and finish omitted-row cleanup before completing
|
|
192
|
-
an authoritative run.
|
|
193
|
-
|
|
194
|
-
An abrupt process kill can leave `collector.lock` in the config directory. The
|
|
195
|
-
next command reports the owner PID and exact path. Confirm that process has exited
|
|
196
|
-
before removing only that lock file, then rerun sync. Never remove an active lock
|
|
197
|
-
or the saved config to recover. Normal completion and handled failures release it.
|
|
198
|
-
|
|
199
|
-
See the [collector coverage audit](../../docs/collector-coverage-audit.md) for
|
|
200
|
-
the full support matrix and known boundaries.
|
|
193
|
+
The scheduler uses a user LaunchAgent on macOS, a user systemd timer on
|
|
194
|
+
Linux/WSL, and Task Scheduler on Windows. It does not install a resident
|
|
195
|
+
watcher, wake a sleeping computer, download packages per run, or replay missed
|
|
196
|
+
intervals. Failures back off for up to six hours and the collector lock prevents
|
|
197
|
+
overlapping syncs.
|
|
198
|
+
|
|
199
|
+
## Recovery and checkpoints
|
|
200
|
+
|
|
201
|
+
Uploads are idempotent and resumable. Before network I/O, the CLI saves a
|
|
202
|
+
bounded journal containing the current run, ordered operations, and next
|
|
203
|
+
checkpoint in the user-only config directory. If a process or network request
|
|
204
|
+
fails, rerun:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
usagemax sync
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
An expired run can be restarted with `sync --restart`; already accepted usage
|
|
211
|
+
remains safe. Do not delete `config.json` to retry a failed upload. See the
|
|
212
|
+
[operations runbook](https://github.com/SYMBaiEX/usagemax/blob/main/docs/operations-runbook.md)
|
|
213
|
+
for recovery guidance.
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
From the repository root:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
bun install
|
|
221
|
+
bun run --cwd packages/cli test
|
|
222
|
+
bun run --cwd packages/cli pack:check # dry-run; lifecycle scripts disabled
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`pack:check` only inspects the local archive shape. It does not publish, contact
|
|
226
|
+
the npm registry, or establish that any registry tag contains this version.
|
|
227
|
+
|
|
228
|
+
The package is MIT-licensed. See the included [LICENSE](LICENSE), the
|
|
229
|
+
repository [LICENSE](https://github.com/SYMBaiEX/usagemax/blob/main/LICENSE),
|
|
230
|
+
[security policy](https://github.com/SYMBaiEX/usagemax/blob/main/SECURITY.md),
|
|
231
|
+
and [contributing guide](https://github.com/SYMBaiEX/usagemax/blob/main/CONTRIBUTING.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usagemax",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Link local coding-agent usage to your UsageMax profile",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"usagemax",
|
|
7
|
+
"ai-usage",
|
|
8
|
+
"usage-analytics",
|
|
9
|
+
"coding-agents",
|
|
10
|
+
"agent-usage",
|
|
11
|
+
"telemetry",
|
|
12
|
+
"observability",
|
|
13
|
+
"usage",
|
|
14
|
+
"ccusage",
|
|
15
|
+
"claude-code",
|
|
16
|
+
"codex",
|
|
17
|
+
"privacy"
|
|
18
|
+
],
|
|
5
19
|
"license": "MIT",
|
|
6
20
|
"author": "UsageMax",
|
|
7
21
|
"homepage": "https://usagemax.com",
|
|
@@ -24,6 +38,8 @@
|
|
|
24
38
|
"src/installation.js",
|
|
25
39
|
"src/sources.js",
|
|
26
40
|
"src/transport.js",
|
|
41
|
+
"src/progress.js",
|
|
42
|
+
"src/updates.js",
|
|
27
43
|
"src/resume.js",
|
|
28
44
|
"src/service.js",
|
|
29
45
|
"README.md",
|
|
@@ -37,7 +53,7 @@
|
|
|
37
53
|
},
|
|
38
54
|
"scripts": {
|
|
39
55
|
"test": "node --test src/*.test.js",
|
|
40
|
-
"pack:check": "npm pack --dry-run",
|
|
56
|
+
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
41
57
|
"prepublishOnly": "npm test"
|
|
42
58
|
},
|
|
43
59
|
"dependencies": {
|