usagebench 0.0.0-stage → 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -2
  3. package/dist/anon.d.ts +11 -0
  4. package/dist/anon.js +108 -0
  5. package/dist/audit.d.ts +1 -0
  6. package/dist/audit.js +173 -0
  7. package/dist/bip39_english.d.ts +1 -0
  8. package/dist/bip39_english.js +126 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +95 -0
  11. package/dist/compare.d.ts +16 -0
  12. package/dist/compare.js +200 -0
  13. package/dist/diff.d.ts +1 -0
  14. package/dist/diff.js +86 -0
  15. package/dist/doctor.d.ts +1 -0
  16. package/dist/doctor.js +138 -0
  17. package/dist/index.d.ts +47 -0
  18. package/dist/index.js +181 -0
  19. package/dist/logs.d.ts +22 -0
  20. package/dist/logs.js +122 -0
  21. package/dist/repro.d.ts +1 -0
  22. package/dist/repro.js +154 -0
  23. package/dist/secrets.d.ts +11 -0
  24. package/dist/secrets.js +100 -0
  25. package/fixtures/claude/2.1.321_compaction-zeroed-usage.continued.expected.json +21 -0
  26. package/fixtures/claude/2.1.321_compaction-zeroed-usage.continued.jsonl +3 -0
  27. package/fixtures/claude/2.1.321_compaction-zeroed-usage.original.expected.json +21 -0
  28. package/fixtures/claude/2.1.321_compaction-zeroed-usage.original.jsonl +2 -0
  29. package/fixtures/claude/2.1.334_main.expected.json +21 -0
  30. package/fixtures/claude/2.1.334_main.jsonl +162 -0
  31. package/fixtures/claude/2.1.335_sidechain.expected.json +21 -0
  32. package/fixtures/claude/2.1.335_sidechain.jsonl +60 -0
  33. package/fixtures/claude/2.1.335_stream-abort-tool-error.expected.json +21 -0
  34. package/fixtures/claude/2.1.335_stream-abort-tool-error.jsonl +200 -0
  35. package/fixtures/claude/synthetic_duplicate-id-partial-usage.expected.json +22 -0
  36. package/fixtures/claude/synthetic_duplicate-id-partial-usage.jsonl +6 -0
  37. package/fixtures/codex/0.160.0_compacted.expected.json +38 -0
  38. package/fixtures/codex/0.160.0_compacted.jsonl +200 -0
  39. package/fixtures/codex/0.171.0-alpha.13.2_subagent-forked.expected.json +38 -0
  40. package/fixtures/codex/0.171.0-alpha.13.2_subagent-forked.jsonl +154 -0
  41. package/fixtures/codex/0.173.0-alpha.4.1_basic.expected.json +38 -0
  42. package/fixtures/codex/0.173.0-alpha.4.1_basic.jsonl +200 -0
  43. package/fixtures/codex/synthetic_total-reset.expected.json +39 -0
  44. package/fixtures/codex/synthetic_total-reset.jsonl +12 -0
  45. package/package.json +48 -4
@@ -0,0 +1,11 @@
1
+ export declare const SENSITIVE: Record<string, RegExp>;
2
+ export declare function sensitive(text: string): string[];
3
+ export interface Hit {
4
+ type: string;
5
+ index: number;
6
+ length: number;
7
+ preview: string;
8
+ placeholder: boolean;
9
+ }
10
+ export declare const mask: (s: string) => string;
11
+ export declare function findSecrets(line: string): Hit[];
@@ -0,0 +1,100 @@
1
+ // Secret detectors. SENSITIVE is the same set tools/check_leaks.py uses (make_fixture refuses on it);
2
+ // AUDIT adds the patterns `usagebench audit` looks for in raw logs. Callers only ever get a type name, a position
3
+ // and a length back; matched text never leaves this module except for in-place redaction by `audit --fix`.
4
+ import { createHash } from "node:crypto";
5
+ import { BIP39_ENGLISH } from "./bip39_english.js";
6
+ export const SENSITIVE = {
7
+ drive_path: /[A-Za-z]:\\|[A-Za-z]:\//,
8
+ unc_path: /\\\\[\w.$-]+\\/,
9
+ unix_home: /\/Users\/|\/home\/|\/root\//,
10
+ email: /[\w.+-]+@[\w-]+\.[\w.]+/,
11
+ anthropic_key: /sk-ant-[A-Za-z0-9_\-]{20,}/,
12
+ openai_key: /sk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_\-]{20,}/,
13
+ github_token: /\bgh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}/,
14
+ aws_key: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,
15
+ google_key: /AIza[0-9A-Za-z_\-]{30,}/,
16
+ slack_token: /\bxox[abposr]-[A-Za-z0-9-]{10,}/,
17
+ private_key: /-----BEGIN [A-Z ]*PRIVATE KEY-----/,
18
+ };
19
+ export function sensitive(text) {
20
+ return Object.entries(SENSITIVE).filter(([, rx]) => rx.test(text)).map(([k]) => k);
21
+ }
22
+ // Exchange API keys (Binance, Upbit, ...) have no documented distinctive format (plain 64/40-char alphanumerics),
23
+ // so they are not detected: a pattern for them would flag every hash in a log.
24
+ const AUDIT = {
25
+ anthropic_key: /sk-ant-[A-Za-z0-9_\-]{20,}/g,
26
+ openai_key: /\bsk-(?!ant-)(?:proj-|svcacct-|admin-)?[A-Za-z0-9_\-]{20,}/g,
27
+ github_token: /\bgh[pousr]_[A-Za-z0-9]{36,}|\bgithub_pat_[A-Za-z0-9_]{22,}/g,
28
+ aws_access_key_id: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
29
+ aws_secret_access_key: /(?<=aws_secret_access_key\W{1,6})[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+])/gi,
30
+ google_api_key: /\bAIza[0-9A-Za-z_\-]{35}/g,
31
+ google_oauth_token: /\bya29\.[0-9A-Za-z_\-]{20,}/g,
32
+ slack_token: /\bxox[abposr]-[A-Za-z0-9-]{10,}/g,
33
+ // PEM block; in a JSONL line its newlines are the two characters \n.
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; 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
+ };
38
+ // Values that are documentation examples or templates, not secrets.
39
+ const PLACEHOLDER = /EXAMPLE|\[REDACTED:|x{4,}|X{4,}|\*{3,}|\.{3}|your[_-]?|<|>|\$\{|\{\{|(.)\1{7,}|^(?:pass(?:word)?|secret|changeme|admin|root|test|user|pwd)$/i;
40
+ export const mask = (s) => `${s.slice(0, 4)}…(${s.length})`;
41
+ const WORDS = new Map(BIP39_ENGLISH.map((w, i) => [w, i]));
42
+ function bip39Valid(words) {
43
+ const idx = words.map((w) => WORDS.get(w));
44
+ if (idx.some((i) => i === undefined))
45
+ return false;
46
+ const bits = idx.map((i) => i.toString(2).padStart(11, "0")).join("");
47
+ const ent = (bits.length * 32) / 33, cs = bits.length - ent;
48
+ const bytes = Buffer.alloc(ent / 8);
49
+ for (let i = 0; i < bytes.length; i++)
50
+ bytes[i] = parseInt(bits.slice(i * 8, i * 8 + 8), 2);
51
+ const h = createHash("sha256").update(bytes).digest();
52
+ const hbits = [...h].map((b) => b.toString(2).padStart(8, "0")).join("").slice(0, cs);
53
+ return hbits === bits.slice(ent);
54
+ }
55
+ // 12/15/18/21/24 consecutive wordlist words (single spaces) whose checksum is valid.
56
+ function seedPhrases(line) {
57
+ const out = [];
58
+ for (const m of line.matchAll(/\b[a-z]{3,8}(?: [a-z]{3,8}){11,}\b/g)) {
59
+ const words = m[0].split(" ");
60
+ const starts = [];
61
+ let p = 0;
62
+ for (const w of words) {
63
+ starts.push(p);
64
+ p += w.length + 1;
65
+ }
66
+ let i = 0;
67
+ outer: while (i + 12 <= words.length) {
68
+ for (const n of [24, 21, 18, 15, 12]) {
69
+ if (i + n > words.length)
70
+ continue;
71
+ const win = words.slice(i, i + n);
72
+ if (bip39Valid(win)) {
73
+ const text = win.join(" ");
74
+ out.push({ type: "bip39_seed_phrase", index: m.index + starts[i], length: text.length,
75
+ preview: `${text.slice(0, 4)}…(${n} words)`, placeholder: false });
76
+ i += n;
77
+ continue outer;
78
+ }
79
+ }
80
+ i++;
81
+ }
82
+ }
83
+ return out;
84
+ }
85
+ export function findSecrets(line) {
86
+ const hits = [];
87
+ for (const [type, rx] of Object.entries(AUDIT)) {
88
+ for (const m of line.matchAll(rx)) {
89
+ // A PEM header with no real key body (code or docs that mention the format) is not a key.
90
+ const noBody = type === "private_key" && (m[0].replace(/-----[A-Z ]+-----|\\[nr]|\s/g, "").match(/[A-Za-z0-9+\/=]/g)?.length ?? 0) < 64;
91
+ hits.push({ type, index: m.index, length: m[0].length, preview: mask(m[0]), placeholder: noBody || PLACEHOLDER.test(m[0]) });
92
+ }
93
+ }
94
+ if (/[a-z]{3,8}(?: [a-z]{3,8}){11}/.test(line))
95
+ hits.push(...seedPhrases(line));
96
+ // Drop hits that sit inside a longer hit (e.g. an AWS key id inside a PEM body).
97
+ hits.sort((a, b) => a.index - b.index || b.length - a.length);
98
+ return hits.filter((h, i) => !hits.some((o, j) => j !== i && o.index <= h.index && o.index + o.length >= h.index + h.length
99
+ && (o.length > h.length || j < i)));
100
+ }
@@ -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>"}
@@ -0,0 +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
+ }