usagebench 0.2.0 → 0.2.3
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 +20 -5
- package/dist/anon.js +3 -2
- package/dist/audit.js +110 -64
- package/dist/cli.js +22 -4
- package/dist/compare.d.ts +2 -2
- package/dist/compare.js +19 -8
- package/dist/diff.js +9 -3
- package/dist/doctor.js +33 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17 -7
- package/dist/logs.js +20 -3
- package/dist/repro.js +6 -1
- package/dist/secrets.js +2 -2
- package/fixtures/claude/2.1.321_compaction-zeroed-usage.continued.expected.json +21 -0
- package/fixtures/claude/2.1.321_compaction-zeroed-usage.continued.jsonl +3 -0
- package/fixtures/claude/2.1.321_compaction-zeroed-usage.original.expected.json +21 -0
- package/fixtures/claude/2.1.321_compaction-zeroed-usage.original.jsonl +2 -0
- package/fixtures/claude/2.1.334_main.expected.json +21 -21
- package/fixtures/claude/2.1.334_main.jsonl +162 -162
- package/fixtures/claude/2.1.335_sidechain.expected.json +21 -21
- package/fixtures/claude/2.1.335_sidechain.jsonl +60 -60
- package/fixtures/claude/2.1.335_stream-abort-tool-error.expected.json +21 -21
- package/fixtures/claude/2.1.335_stream-abort-tool-error.jsonl +200 -200
- package/fixtures/claude/synthetic_duplicate-id-partial-usage.expected.json +22 -22
- package/fixtures/codex/0.160.0_compacted.expected.json +38 -38
- package/fixtures/codex/0.160.0_compacted.jsonl +200 -200
- package/fixtures/codex/0.171.0-alpha.13.2_subagent-forked.expected.json +38 -38
- package/fixtures/codex/0.171.0-alpha.13.2_subagent-forked.jsonl +154 -154
- package/fixtures/codex/0.173.0-alpha.4.1_basic.expected.json +38 -38
- package/fixtures/codex/0.173.0-alpha.4.1_basic.jsonl +200 -200
- package/fixtures/codex/synthetic_total-reset.expected.json +39 -39
- package/package.json +16 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,10 @@ const AGENT_NAMES = {
|
|
|
5
5
|
claude: "claude", claude_code: "claude", codex: "codex", agy: "agy", gemini_antigravity: "agy",
|
|
6
6
|
};
|
|
7
7
|
const NORMALIZED = { claude: "claude_code", codex: "codex", agy: "gemini_antigravity" };
|
|
8
|
+
// A Claude usage row whose four top-level counters are all 0 bills nothing: a real response always has input or
|
|
9
|
+
// cache tokens. Such rows are copies (anthropics/claude-code#95555); dedup ignores them so they cannot replace
|
|
10
|
+
// the original row of the same message.
|
|
11
|
+
export const zeroedTop = (t) => !t.input && !t.output && !t.cache_write && !t.cache_read;
|
|
8
12
|
export function agentName(name) {
|
|
9
13
|
const a = AGENT_NAMES[name];
|
|
10
14
|
if (!a)
|
|
@@ -55,15 +59,20 @@ export function parse(agentIn, jsonlText, opts = {}) {
|
|
|
55
59
|
const u = m ? obj(m.usage) : null;
|
|
56
60
|
if (!m || !u)
|
|
57
61
|
continue;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const tokens = {
|
|
63
|
+
input: num(u.input_tokens), output: num(u.output_tokens), cache_write: num(u.cache_creation_input_tokens),
|
|
64
|
+
cache_read: num(u.cache_read_input_tokens), reasoning: num(obj(u.output_tokens_details)?.thinking_tokens),
|
|
65
|
+
};
|
|
66
|
+
const nonzero = (v) => Object.values(obj(v) ?? {}).some((x) => typeof x === "number" && x > 0);
|
|
67
|
+
const rec = {
|
|
68
|
+
...base(line, "assistant", tokens),
|
|
63
69
|
agent_version: str(o.version), session_id: str(o.sessionId), message_id: str(m.id),
|
|
64
70
|
parent_id: str(o.parentUuid), is_sidechain: o.isSidechain === true, timestamp: str(o.timestamp),
|
|
65
71
|
model: str(m.model),
|
|
66
|
-
}
|
|
72
|
+
};
|
|
73
|
+
if (zeroedTop(tokens) && (nonzero(u.cache_creation) || nonzero(Array.isArray(u.iterations) ? u.iterations[0] : null)))
|
|
74
|
+
rec.zeroed_copy = true;
|
|
75
|
+
out.push(rec);
|
|
67
76
|
}
|
|
68
77
|
else if (agent === "codex") {
|
|
69
78
|
const p = obj(o.payload) ?? {};
|
|
@@ -151,7 +160,8 @@ export function usage(agentIn, records, opts = {}) {
|
|
|
151
160
|
return sum(records);
|
|
152
161
|
const last = new Map();
|
|
153
162
|
for (const r of records)
|
|
154
|
-
|
|
163
|
+
if (!zeroedTop(r.tokens))
|
|
164
|
+
last.set(JSON.stringify([r.session_id, r.message_id]), r);
|
|
155
165
|
return sum([...last.values()]);
|
|
156
166
|
}
|
|
157
167
|
// agy: PLANNER_RESPONSE tokens are per call; other records with token fields (CHECKPOINT) are summaries.
|
package/dist/logs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Defaults (same on Windows, macOS and Linux, under the user's home):
|
|
3
3
|
// Claude Code: ~/.claude/projects and ~/.config/claude/projects; CLAUDE_CONFIG_DIR (comma-separated) overrides.
|
|
4
4
|
// Codex: ~/.codex/sessions (and archived_sessions); CODEX_HOME overrides ~/.codex.
|
|
5
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { join, relative } from "node:path";
|
|
8
8
|
import { parse } from "./index.js";
|
|
@@ -24,12 +24,18 @@ export function logRoots(agent, env = process.env) {
|
|
|
24
24
|
return dirs.filter((d) => existsSync(d));
|
|
25
25
|
}
|
|
26
26
|
// Every *.jsonl under the roots; unreadable directories and files are skipped silently.
|
|
27
|
+
// Symlinked directories and files are followed; a directory reached twice (symlink cycle) is walked once.
|
|
27
28
|
export function logFiles(agent, env = process.env) {
|
|
28
29
|
const out = [];
|
|
30
|
+
const seen = new Set();
|
|
29
31
|
for (const root of logRoots(agent, env)) {
|
|
30
32
|
const walk = (d) => {
|
|
31
33
|
let ents;
|
|
32
34
|
try {
|
|
35
|
+
const real = realpathSync(d);
|
|
36
|
+
if (seen.has(real))
|
|
37
|
+
return;
|
|
38
|
+
seen.add(real);
|
|
33
39
|
ents = readdirSync(d, { withFileTypes: true });
|
|
34
40
|
}
|
|
35
41
|
catch {
|
|
@@ -37,9 +43,20 @@ export function logFiles(agent, env = process.env) {
|
|
|
37
43
|
}
|
|
38
44
|
for (const e of ents) {
|
|
39
45
|
const p = join(d, e.name);
|
|
40
|
-
|
|
46
|
+
let isDir = e.isDirectory(), isFile = e.isFile();
|
|
47
|
+
if (e.isSymbolicLink()) {
|
|
48
|
+
try {
|
|
49
|
+
const s = statSync(p);
|
|
50
|
+
isDir = s.isDirectory();
|
|
51
|
+
isFile = s.isFile();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
continue;
|
|
55
|
+
} // dangling link
|
|
56
|
+
}
|
|
57
|
+
if (isDir)
|
|
41
58
|
walk(p);
|
|
42
|
-
else if (
|
|
59
|
+
else if (isFile && e.name.endsWith(".jsonl")) {
|
|
43
60
|
try {
|
|
44
61
|
const s = statSync(p);
|
|
45
62
|
out.push({ root, path: p, rel: relative(root, p).replaceAll("\\", "/"), size: s.size, mtimeMs: s.mtimeMs });
|
package/dist/repro.js
CHANGED
|
@@ -45,7 +45,12 @@ function trim(agent, lines, objs, maxBytes) {
|
|
|
45
45
|
export function repro(args) {
|
|
46
46
|
const opt = (k) => (args.includes(k) ? args[args.indexOf(k) + 1] : undefined);
|
|
47
47
|
const want = opt("--agent"), sid = opt("--session"), tracker = opt("--tracker");
|
|
48
|
-
const
|
|
48
|
+
const maxKb = Number(opt("--max-kb") ?? 50);
|
|
49
|
+
if (!Number.isFinite(maxKb) || maxKb <= 0) {
|
|
50
|
+
console.error("--max-kb must be a number > 0");
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
const maxBytes = maxKb * 1024;
|
|
49
54
|
if (want && !LOG_AGENTS.includes(want)) {
|
|
50
55
|
console.error("--agent must be claude or codex");
|
|
51
56
|
return 2;
|
package/dist/secrets.js
CHANGED
|
@@ -32,8 +32,8 @@ const AUDIT = {
|
|
|
32
32
|
slack_token: /\bxox[abposr]-[A-Za-z0-9-]{10,}/g,
|
|
33
33
|
// PEM block; in a JSONL line its newlines are the two characters \n.
|
|
34
34
|
private_key: /-----BEGIN [A-Z ]*PRIVATE KEY-----(?:[A-Za-z0-9+\/=: \t-]|\\[nr])*?(?:-----END [A-Z ]*PRIVATE KEY-----|(?=\\[^nr]|[^A-Za-z0-9+\/=: \t\\-]|$))/g,
|
|
35
|
-
// scheme://user:password@host — the match is the password only.
|
|
36
|
-
db_url_password: /(?<=\b(?:postgres(?:ql)?|mysql|mariadb|mongodb(?:\+srv)?|rediss?|amqps?|mssql|sqlserver):\/\/[^\s:\/@"'\\]*:)[^\s@\/"'\\]+(?=@)/gi,
|
|
35
|
+
// scheme://user:password@host — the match is the password only; JSON escapes (\" \\) inside it belong to it.
|
|
36
|
+
db_url_password: /(?<=\b(?:postgres(?:ql)?|mysql|mariadb|mongodb(?:\+srv)?|rediss?|amqps?|mssql|sqlserver):\/\/[^\s:\/@"'\\]*:)(?:[^\s@\/"'\\]|\\.)+(?=@)/gi,
|
|
37
37
|
};
|
|
38
38
|
// Values that are documentation examples or templates, not secrets.
|
|
39
39
|
const PLACEHOLDER = /EXAMPLE|\[REDACTED:|x{4,}|X{4,}|\*{3,}|\.{3}|your[_-]?|<|>|\$\{|\{\{|(.)\1{7,}|^(?:pass(?:word)?|secret|changeme|admin|root|test|user|pwd)$/i;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"agent": "claude",
|
|
3
|
+
"usage_lines": 2,
|
|
4
|
+
"unique_messages": 0,
|
|
5
|
+
"rule": "claude_last_per_message_id",
|
|
6
|
+
"is_sidechain": false,
|
|
7
|
+
"naive": {
|
|
8
|
+
"input": 0,
|
|
9
|
+
"output": 0,
|
|
10
|
+
"cache_write": 0,
|
|
11
|
+
"cache_read": 0,
|
|
12
|
+
"reasoning": 1590
|
|
13
|
+
},
|
|
14
|
+
"dedup": {
|
|
15
|
+
"input": 0,
|
|
16
|
+
"output": 0,
|
|
17
|
+
"cache_write": 0,
|
|
18
|
+
"cache_read": 0,
|
|
19
|
+
"reasoning": 0
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"parentUuid": null, "logicalParentUuid": "id_fake000011", "isSidechain": false, "type": "system", "subtype": "compact_boundary", "content": "<redacted>", "level": "info", "compactMetadata": {"trigger": "<redacted>", "preTokens": 248906, "postTokens": 26744, "cumulativeDroppedTokens": 957500, "durationMs": 10, "precomputed": true, "preCompactDiscoveredTools": ["<redacted>", "<redacted>", "<redacted>", "<redacted>"], "preservedSegment": {"headUuid": "id_fake000008", "anchorUuid": "id_fake000012", "tailUuid": "id_fake000011"}, "preservedMessages": {"anchorUuid": "id_fake000012", "uuids": ["id_fake000008", "id_fake000010", "id_fake000013", "id_fake000014", "id_fake000015", "id_fake000016", "id_fake000011"], "allUuids": ["id_fake000008", "id_fake000010", "id_fake000017", "id_fake000018", "id_fake000019", "id_fake000013", "id_fake000014", "id_fake000015", "id_fake000016", "id_fake000011"]}, "runningTurnSends": {"uuids": [], "openerUuid": "id_fake000015", "summarisedOnly": ["id_fake000015"]}}, "uuid": "id_fake000020", "timestamp": "2026-01-01T07:32:56.801Z", "userType": "external", "entrypoint": "<redacted>", "cwd": "<redacted>", "sessionId": "id_fake000021", "version": "2.1.321", "gitBranch": "<redacted>"}
|
|
2
|
+
{"parentUuid": "id_fake000012", "isSidechain": false, "message": {"model": "claude-sonnet-5-5", "id": "msg_fake000002", "type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "", "signature": "<redacted>"}], "container": null, "stop_reason": "end_turn", "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 0, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "output_tokens": 0, "output_tokens_details": {"thinking_tokens": 795}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 7765, "ephemeral_5m_input_tokens": 0}, "inference_geo": "global", "iterations": [{"input_tokens": 2, "output_tokens": 1637, "cache_read_input_tokens": 239131, "cache_creation_input_tokens": 7765, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 7765}, "type": "message"}], "speed": "standard", "fallback_credit": null}, "input_fake000003": [], "diagnostics": null, "context_fake000004": null}, "thinkingDurationMs": 12031, "thinkingDisplay": "<redacted>", "serverClassifierRequest": "id_fake000005", "apiBlockIndex": 0, "requestId": "req_fake000006", "requestRef": "id_fake000007", "requestedModel": "claude-sonnet-5-5", "promptCacheRequested": "<redacted>", "type": "assistant", "uuid": "id_fake000008", "timestamp": "2026-01-01T00:00:00.000Z", "advisorModel": "claude-opus-5-5", "effort": "medium", "perTurnEffort": "<redacted>", "userType": "external", "entrypoint": "<redacted>", "cwd": "<redacted>", "sessionId": "id_fake000021", "version": "2.1.321", "gitBranch": "<redacted>"}
|
|
3
|
+
{"parentUuid": "id_fake000008", "isSidechain": false, "message": {"model": "claude-sonnet-5-5", "id": "msg_fake000002", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "<redacted>"}], "container": null, "stop_reason": "end_turn", "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 0, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "output_tokens": 0, "output_tokens_details": {"thinking_tokens": 795}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 7765, "ephemeral_5m_input_tokens": 0}, "inference_geo": "global", "iterations": [{"input_tokens": 2, "output_tokens": 1637, "cache_read_input_tokens": 239131, "cache_creation_input_tokens": 7765, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 7765}, "type": "message"}], "speed": "standard", "fallback_credit": null}, "input_fake000003": [], "diagnostics": null, "context_fake000004": null}, "serverClassifierRequest": "id_fake000005", "apiBlockIndex": 1, "requestId": "req_fake000006", "requestRef": "id_fake000007", "requestedModel": "claude-sonnet-5-5", "promptCacheRequested": "<redacted>", "type": "assistant", "uuid": "id_fake000010", "timestamp": "2026-01-01T00:00:00.012Z", "advisorModel": "claude-opus-5-5", "effort": "medium", "perTurnEffort": "<redacted>", "userType": "external", "entrypoint": "<redacted>", "cwd": "<redacted>", "sessionId": "id_fake000021", "version": "2.1.321", "gitBranch": "<redacted>"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"agent": "claude",
|
|
3
|
+
"usage_lines": 2,
|
|
4
|
+
"unique_messages": 1,
|
|
5
|
+
"rule": "claude_last_per_message_id",
|
|
6
|
+
"is_sidechain": false,
|
|
7
|
+
"naive": {
|
|
8
|
+
"input": 4,
|
|
9
|
+
"output": 3274,
|
|
10
|
+
"cache_write": 15530,
|
|
11
|
+
"cache_read": 478262,
|
|
12
|
+
"reasoning": 1590
|
|
13
|
+
},
|
|
14
|
+
"dedup": {
|
|
15
|
+
"input": 2,
|
|
16
|
+
"output": 1637,
|
|
17
|
+
"cache_write": 7765,
|
|
18
|
+
"cache_read": 239131,
|
|
19
|
+
"reasoning": 795
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"parentUuid": "id_fake000001", "isSidechain": false, "message": {"model": "claude-sonnet-5-5", "id": "msg_fake000002", "type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "", "signature": "<redacted>"}], "container": null, "stop_reason": "end_turn", "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 7765, "cache_read_input_tokens": 239131, "output_tokens": 1637, "output_tokens_details": {"thinking_tokens": 795}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 7765, "ephemeral_5m_input_tokens": 0}, "inference_geo": "global", "iterations": [{"input_tokens": 2, "output_tokens": 1637, "cache_read_input_tokens": 239131, "cache_creation_input_tokens": 7765, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 7765}, "type": "message"}], "speed": "standard", "fallback_credit": null}, "input_fake000003": [], "diagnostics": null, "context_fake000004": null}, "thinkingDurationMs": 12031, "thinkingDisplay": "<redacted>", "serverClassifierRequest": "id_fake000005", "apiBlockIndex": 0, "requestId": "req_fake000006", "requestRef": "id_fake000007", "requestedModel": "claude-sonnet-5-5", "promptCacheRequested": "<redacted>", "type": "assistant", "uuid": "id_fake000008", "timestamp": "2026-01-01T00:00:00.000Z", "advisorModel": "claude-opus-5-5", "effort": "medium", "perTurnEffort": "<redacted>", "userType": "external", "entrypoint": "<redacted>", "cwd": "<redacted>", "sessionId": "id_fake000009", "version": "2.1.321", "gitBranch": "<redacted>", "slug": "<redacted>"}
|
|
2
|
+
{"parentUuid": "id_fake000008", "isSidechain": false, "message": {"model": "claude-sonnet-5-5", "id": "msg_fake000002", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "<redacted>"}], "container": null, "stop_reason": "end_turn", "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 7765, "cache_read_input_tokens": 239131, "output_tokens": 1637, "output_tokens_details": {"thinking_tokens": 795}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 7765, "ephemeral_5m_input_tokens": 0}, "inference_geo": "global", "iterations": [{"input_tokens": 2, "output_tokens": 1637, "cache_read_input_tokens": 239131, "cache_creation_input_tokens": 7765, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 7765}, "type": "message"}], "speed": "standard", "fallback_credit": null}, "input_fake000003": [], "diagnostics": null, "context_fake000004": null}, "serverClassifierRequest": "id_fake000005", "apiBlockIndex": 1, "requestId": "req_fake000006", "requestRef": "id_fake000007", "requestedModel": "claude-sonnet-5-5", "promptCacheRequested": "<redacted>", "type": "assistant", "uuid": "id_fake000010", "timestamp": "2026-01-01T00:00:00.012Z", "advisorModel": "claude-opus-5-5", "effort": "medium", "perTurnEffort": "<redacted>", "userType": "external", "entrypoint": "<redacted>", "cwd": "<redacted>", "sessionId": "id_fake000009", "version": "2.1.321", "gitBranch": "<redacted>", "slug": "<redacted>"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"agent": "claude",
|
|
3
|
-
"usage_lines": 13,
|
|
4
|
-
"unique_messages": 7,
|
|
5
|
-
"rule": "claude_last_per_message_id",
|
|
6
|
-
"is_sidechain": false,
|
|
7
|
-
"naive": {
|
|
8
|
-
"input": 26,
|
|
9
|
-
"output": 7650,
|
|
10
|
-
"cache_write": 369996,
|
|
11
|
-
"cache_read": 1308765,
|
|
12
|
-
"reasoning": 830
|
|
13
|
-
},
|
|
14
|
-
"dedup": {
|
|
15
|
-
"input": 14,
|
|
16
|
-
"output": 4039,
|
|
17
|
-
"cache_write": 186687,
|
|
18
|
-
"cache_read": 730509,
|
|
19
|
-
"reasoning": 415
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"agent": "claude",
|
|
3
|
+
"usage_lines": 13,
|
|
4
|
+
"unique_messages": 7,
|
|
5
|
+
"rule": "claude_last_per_message_id",
|
|
6
|
+
"is_sidechain": false,
|
|
7
|
+
"naive": {
|
|
8
|
+
"input": 26,
|
|
9
|
+
"output": 7650,
|
|
10
|
+
"cache_write": 369996,
|
|
11
|
+
"cache_read": 1308765,
|
|
12
|
+
"reasoning": 830
|
|
13
|
+
},
|
|
14
|
+
"dedup": {
|
|
15
|
+
"input": 14,
|
|
16
|
+
"output": 4039,
|
|
17
|
+
"cache_write": 186687,
|
|
18
|
+
"cache_read": 730509,
|
|
19
|
+
"reasoning": 415
|
|
20
|
+
}
|
|
21
|
+
}
|