@traice/codex-collector 0.1.0 → 0.1.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/README.md +49 -11
- package/cli.mjs +8 -11
- package/collector.mjs +242 -203
- package/install.mjs +154 -132
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,26 +12,50 @@ collector data goes to `/api/v1/internal-usage`, not `/api/v1/events`.
|
|
|
12
12
|
- Codex OTel `response.completed` token events from `127.0.0.1:4318/v1/logs`
|
|
13
13
|
- local install identity: employee email/name, team name, device principal
|
|
14
14
|
- Codex context metadata: repo/cwd, model, thread id, sandbox/approval mode
|
|
15
|
-
- optional monthly seat/subscription commitment, e.g. `--seat-monthly-usd
|
|
15
|
+
- optional monthly seat/subscription commitment, e.g. `--seat-monthly-usd 100`
|
|
16
16
|
|
|
17
17
|
Prompts are not sent. Codex OTel is configured with `log_user_prompt = false`.
|
|
18
18
|
|
|
19
|
+
For an overview of OTel, the collector data path, and how Codex differs from the planned Claude Code collector, see
|
|
20
|
+
[Coding-agent collectors](../../docs/collectors.md).
|
|
21
|
+
|
|
19
22
|
## Install On This Device
|
|
20
23
|
|
|
21
24
|
Published install shape:
|
|
22
25
|
|
|
23
26
|
```sh
|
|
24
|
-
|
|
27
|
+
printf "trAIce API key: "
|
|
28
|
+
stty -echo
|
|
29
|
+
IFS= read -r TRAICE_API_KEY
|
|
30
|
+
stty echo
|
|
31
|
+
printf "\n"
|
|
25
32
|
export TRAICE_API_KEY
|
|
26
33
|
npx @traice/codex-collector@latest install \
|
|
27
|
-
--server-url https://
|
|
34
|
+
--server-url https://www.runtraice.com \
|
|
28
35
|
--employee-email you@company.com \
|
|
29
36
|
--employee-name "Your Name" \
|
|
30
37
|
--team-name Engineering \
|
|
31
|
-
--seat-monthly-usd
|
|
38
|
+
--seat-monthly-usd 100 \
|
|
39
|
+
--backfill-hours all \
|
|
40
|
+
--patch-codex-config
|
|
32
41
|
unset TRAICE_API_KEY
|
|
33
42
|
```
|
|
34
43
|
|
|
44
|
+
PowerShell on Windows:
|
|
45
|
+
|
|
46
|
+
```powershell
|
|
47
|
+
$secureKey = Read-Host "trAIce API key" -AsSecureString
|
|
48
|
+
$plainKey = [Net.NetworkCredential]::new("", $secureKey).Password
|
|
49
|
+
$plainKey | npx @traice/codex-collector@latest install --api-key-stdin `
|
|
50
|
+
--server-url 'https://www.runtraice.com' `
|
|
51
|
+
--employee-email 'you@company.com' `
|
|
52
|
+
--team-name 'Engineering' `
|
|
53
|
+
--seat-monthly-usd 100 `
|
|
54
|
+
--backfill-hours all `
|
|
55
|
+
--patch-codex-config
|
|
56
|
+
Remove-Variable plainKey, secureKey
|
|
57
|
+
```
|
|
58
|
+
|
|
35
59
|
Local repo development can still run:
|
|
36
60
|
|
|
37
61
|
```sh
|
|
@@ -39,7 +63,7 @@ node tools/internal-spend-codex/install.mjs \
|
|
|
39
63
|
--employee-email you@company.com \
|
|
40
64
|
--employee-name "Your Name" \
|
|
41
65
|
--team-name Engineering \
|
|
42
|
-
--seat-monthly-usd
|
|
66
|
+
--seat-monthly-usd 100
|
|
43
67
|
```
|
|
44
68
|
|
|
45
69
|
The installer:
|
|
@@ -47,7 +71,9 @@ The installer:
|
|
|
47
71
|
- creates or reuses the `internal-spend-poc` workspace in local dev
|
|
48
72
|
- enables the workspace `internalSpendEnabled` flag
|
|
49
73
|
- creates a real API key for `/api/v1/internal-usage`
|
|
50
|
-
- writes private collector config to
|
|
74
|
+
- writes private collector config, including the API key, to
|
|
75
|
+
`~/.traice/internal-spend-codex/install.json` (user-only mode on macOS/Linux;
|
|
76
|
+
the user-profile ACL on Windows)
|
|
51
77
|
- appends an idempotent trAIce `[otel]` block to user-level
|
|
52
78
|
`~/.codex/config.toml`
|
|
53
79
|
|
|
@@ -67,13 +93,18 @@ Local repo development can use `node tools/internal-spend-codex/collector.mjs`.
|
|
|
67
93
|
macOS LaunchAgent:
|
|
68
94
|
|
|
69
95
|
```sh
|
|
70
|
-
|
|
96
|
+
printf "trAIce API key: "
|
|
97
|
+
stty -echo
|
|
98
|
+
IFS= read -r TRAICE_API_KEY
|
|
99
|
+
stty echo
|
|
100
|
+
printf "\n"
|
|
71
101
|
export TRAICE_API_KEY
|
|
72
102
|
npx @traice/codex-collector@latest install \
|
|
73
|
-
--server-url https://
|
|
103
|
+
--server-url https://www.runtraice.com \
|
|
74
104
|
--employee-email you@company.com \
|
|
75
105
|
--team-name Engineering \
|
|
76
|
-
--seat-monthly-usd
|
|
106
|
+
--seat-monthly-usd 100 \
|
|
107
|
+
--backfill-hours all \
|
|
77
108
|
--launch-agent
|
|
78
109
|
unset TRAICE_API_KEY
|
|
79
110
|
```
|
|
@@ -113,7 +144,9 @@ contract and fill employee/team fields directly or via identity mapping.
|
|
|
113
144
|
|
|
114
145
|
The API key can be provided with `TRAICE_API_KEY`, `--api-key-stdin`, or
|
|
115
146
|
`--api-key`. Prefer `TRAICE_API_KEY` or `--api-key-stdin` for user installs so
|
|
116
|
-
keys do not end up in shell history.
|
|
147
|
+
keys do not end up in shell history. A later `install` reuses the saved key, and
|
|
148
|
+
`collect` always reads it from the private config, so neither command prompts
|
|
149
|
+
again unless the config was removed.
|
|
117
150
|
|
|
118
151
|
Private config and collector state default to `~/.traice/internal-spend-codex`.
|
|
119
152
|
Use `--out /path/to/private-dir` only when an org installer manages that
|
|
@@ -134,12 +167,17 @@ New or restarted Codex agents use native OTel export through the installed
|
|
|
134
167
|
`[otel]` config. Already-open agents are covered by session JSONL token-count
|
|
135
168
|
tailing where those files are available.
|
|
136
169
|
|
|
170
|
+
By default the first session scan imports all available Codex history. To limit
|
|
171
|
+
history, pass `--backfill-hours N` to `install` or `collect`; use
|
|
172
|
+
`--backfill-hours all` explicitly for a full import. Collector state is scoped
|
|
173
|
+
to the configured trAIce destination and source event IDs dedupe later restarts.
|
|
174
|
+
|
|
137
175
|
## One-Shot Backfill
|
|
138
176
|
|
|
139
177
|
Run a single session-file scan without opening the OTel listener:
|
|
140
178
|
|
|
141
179
|
```sh
|
|
142
|
-
npx @traice/codex-collector@latest collect --once
|
|
180
|
+
npx @traice/codex-collector@latest collect --once --backfill-hours 6
|
|
143
181
|
```
|
|
144
182
|
|
|
145
183
|
The collector keeps local dedupe state in:
|
package/cli.mjs
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawnSync } from
|
|
3
|
-
import { dirname, resolve } from
|
|
4
|
-
import { fileURLToPath } from
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const dir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const [command =
|
|
8
|
-
const script =
|
|
9
|
-
?
|
|
10
|
-
: command === 'collect' || command === 'collector'
|
|
11
|
-
? 'collector.mjs'
|
|
12
|
-
: null;
|
|
7
|
+
const [command = "collect", ...args] = process.argv.slice(2);
|
|
8
|
+
const script =
|
|
9
|
+
command === "install" ? "install.mjs" : command === "collect" || command === "collector" ? "collector.mjs" : null;
|
|
13
10
|
|
|
14
11
|
if (!script) {
|
|
15
|
-
console.error(
|
|
12
|
+
console.error("Usage: traice-codex-collector <install|collect> [options]");
|
|
16
13
|
process.exit(2);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
const result = spawnSync(process.execPath, [resolve(dir, script), ...args], {
|
|
20
|
-
stdio:
|
|
17
|
+
stdio: "inherit",
|
|
21
18
|
});
|
|
22
19
|
|
|
23
20
|
if (result.signal) {
|