@aaa-sentinel/ai-usage 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +120 -2
- package/dist/cli.js +1378 -0
- package/dist/hook.js +67 -0
- package/package.json +42 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AAA Sentinel
|
|
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
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @aaa-sentinel/ai-usage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reports the usage of an **individual Cursor, Claude Code, GitHub Copilot or Codex seat** to
|
|
4
|
+
AAA Sentinel, so a personal subscription shows which models it is spent on instead of only a
|
|
5
|
+
plan percentage. The prompt, the code and the conversation stay on the laptop.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 20 or newer.
|
|
10
|
+
- An individual AI connection in AAA Sentinel (Cursor, Anthropic, Copilot or OpenAI) and the
|
|
11
|
+
enrollment token it issues. The token is shown once; rotating it invalidates the previous one.
|
|
12
|
+
- For Copilot only: the [GitHub CLI](https://cli.github.com), already signed in (`gh auth login`)
|
|
13
|
+
to the account that holds the Copilot plan.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @aaa-sentinel/ai-usage
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Save the token to a file only you can read, then pass it on **standard input**:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
sentinel-usage login < token.txt
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```powershell
|
|
28
|
+
Get-Content -Raw -Encoding utf8 token.txt | sentinel-usage login
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Delete the file when `login` finishes. The token is never accepted as an argument — it would stay
|
|
32
|
+
in the shell history — and it is never read from the keyboard, so it is not echoed.
|
|
33
|
+
|
|
34
|
+
`login` registers a startup task: at sign-in and every hour while a session is open (Task
|
|
35
|
+
Scheduler on Windows, `launchd` on macOS, a `systemd` user timer on Linux). That task runs
|
|
36
|
+
`sentinel-usage report`. You do not start anything when you sit down to work.
|
|
37
|
+
|
|
38
|
+
## Commands
|
|
39
|
+
|
|
40
|
+
| Command | What it does |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `sentinel-usage login` | Stores the token read from standard input, installs the Cursor hook and registers the startup task. If any step fails, nothing is left installed |
|
|
43
|
+
| `sentinel-usage report` | Uploads the usage that is new since the last accepted day. Run by the startup task; safe to run by hand |
|
|
44
|
+
| `sentinel-usage status` | Says whether the agent and the startup task are installed, which tool this connection reports, and the last accepted day. It does not print the token |
|
|
45
|
+
| `sentinel-usage logout` | Removes the startup task, the Cursor hook and the token from this machine |
|
|
46
|
+
|
|
47
|
+
| Exit code | Meaning |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `0` | Done, including "there is no new usage to upload" |
|
|
50
|
+
| `2` | Wrong usage: unknown command, malformed token, or a base URL that is not `https` |
|
|
51
|
+
| `3` | The startup task could not be registered or removed |
|
|
52
|
+
| `4` | The server did not accept a day, or no longer recognizes the token |
|
|
53
|
+
| `5` | Copilot: `gh` is missing or lacks permission to read the usage |
|
|
54
|
+
|
|
55
|
+
Messages are printed in Spanish.
|
|
56
|
+
|
|
57
|
+
## What actually leaves your machine
|
|
58
|
+
|
|
59
|
+
One request per day of usage, with **the day, the model and the counters** — input, output,
|
|
60
|
+
cache-read and cache-write tokens, and the number of turns — plus a random identifier generated
|
|
61
|
+
on this machine that only tells two laptops apart.
|
|
62
|
+
|
|
63
|
+
Not the prompt, not the code, not the conversation, not your email and not the path of a
|
|
64
|
+
transcript. The CLI reads only the tool its connection is for: a connection enrolled for Cursor
|
|
65
|
+
never opens a Claude Code transcript, and `gh` is not called unless the connection is Copilot.
|
|
66
|
+
|
|
67
|
+
The figures are not converted to money and are not added to billed or estimated spend.
|
|
68
|
+
|
|
69
|
+
## What is read, per tool
|
|
70
|
+
|
|
71
|
+
- **Cursor.** A hook in `~/.cursor/hooks.json` writes one small file per turn to a local spool.
|
|
72
|
+
If the hook carries token counters they are reported per model; the stored input excludes
|
|
73
|
+
cache. If the counters are missing, the turn is counted and no token number is invented.
|
|
74
|
+
- **Claude Code.** The usage counters of the local session files. A cost figure that sometimes
|
|
75
|
+
comes with the session is not uploaded. A turn here is one call to the model, so a reply that
|
|
76
|
+
uses tools counts several.
|
|
77
|
+
- **GitHub Copilot.** Premium requests by model for the personal account, read through `gh`.
|
|
78
|
+
GitHub does not report tokens. This is account usage, not device usage, so two laptops do not
|
|
79
|
+
double it. The GitHub token is not read in order to send it. If `gh` answers 401 or 403, an
|
|
80
|
+
empty row is not written.
|
|
81
|
+
- **Codex.** Session counters, only when Codex is signed in with the ChatGPT subscription. If its
|
|
82
|
+
auth file shows an API key, nothing is attributed to the individual account: that spend belongs
|
|
83
|
+
to the organization connection.
|
|
84
|
+
|
|
85
|
+
Usage from before `login` is never uploaded: it predates the enrollment and the server would
|
|
86
|
+
reject it.
|
|
87
|
+
|
|
88
|
+
## Environment variables
|
|
89
|
+
|
|
90
|
+
None is required.
|
|
91
|
+
|
|
92
|
+
| Variable | Meaning |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `SENTINEL_USAGE_BASE_URL` | Defaults to `https://api.aaa-sentinel.com`. Must be `https` — the token is never sent over plain HTTP |
|
|
95
|
+
| `SENTINEL_USAGE_HOME` | Where the token, the state and the spool live. Defaults to `~/.config/aaa-sentinel` |
|
|
96
|
+
| `SENTINEL_USAGE_CURSOR_HOOKS` | Path of Cursor's hooks file. Defaults to `~/.cursor/hooks.json` |
|
|
97
|
+
| `SENTINEL_USAGE_CLAUDE_DIR` | Claude Code projects folder. Defaults to `projects` under `CLAUDE_CONFIG_DIR` or `~/.claude` |
|
|
98
|
+
| `SENTINEL_USAGE_CODEX_HOME` | Codex folder. Defaults to `CODEX_HOME` or `~/.codex` |
|
|
99
|
+
|
|
100
|
+
The token is stored in `usage.json` inside `SENTINEL_USAGE_HOME`, readable only by your user.
|
|
101
|
+
|
|
102
|
+
## Troubleshooting
|
|
103
|
+
|
|
104
|
+
**`sentinel-usage` is not found after installing.** Open a new terminal: the global `npm` folder
|
|
105
|
+
is added to `PATH` when the shell starts.
|
|
106
|
+
|
|
107
|
+
**`report` exits with 4 and says the server does not recognize the token.** The token was rotated
|
|
108
|
+
or the connection was removed. Enroll again in the portal and repeat `login` with the new token.
|
|
109
|
+
|
|
110
|
+
**`report` says the usage does not belong to this connection.** The token was enrolled for a
|
|
111
|
+
different tool than the one in use on this machine. Nothing is uploaded; enroll the token from
|
|
112
|
+
the connection that matches the tool.
|
|
113
|
+
|
|
114
|
+
**The connection shows a silent agent in the portal.** The token exists and this renewal period
|
|
115
|
+
has no usage yet. That is not a zero — use the tool and wait for the next hourly run, or run
|
|
116
|
+
`sentinel-usage report` by hand.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT — see [LICENSE](LICENSE). The licence covers this client only; access to the API is governed by
|
|
121
|
+
the terms of service at <https://app.aaa-sentinel.com>.
|