claude-rpc 1.7.3 → 1.8.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/README.md +5 -4
- package/SECURITY.md +20 -0
- package/package.json +1 -1
- package/src/cli.js +3 -1
- package/src/commands.js +1 -0
- package/src/config-edit.js +59 -0
- package/src/pricing.js +87 -43
- package/src/scanner.js +8 -4
- package/src/server/assets/dashboard.html +1 -0
- package/src/server/assets/settings.client.js +422 -0
- package/src/server/assets/settings.css +145 -0
- package/src/server/assets/settings.html +176 -0
- package/src/server/index.js +67 -16
- package/src/server/page.js +17 -3
- package/src/server/routes.js +16 -0
- package/src/server/settings.js +234 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ brew install rar-file/claude-rpc/claude-rpc && claude-rpc setup
|
|
|
70
70
|
.\claude-rpc.exe setup
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
`setup` copies the exe to a fixed per-user location (so the download can go afterwards) and adds that folder to your user PATH, so `claude-rpc <command>` works in any new terminal. Prefer a GUI? The release's `claude-rpc-<version>-x64-setup.exe` (installer, auto-updates) and `claude-rpc-<version>-x64-portable.exe` (no install) are the desktop
|
|
73
|
+
`setup` copies the exe to a fixed per-user location (so the download can go afterwards) and adds that folder to your user PATH, so `claude-rpc <command>` works in any new terminal. Prefer a GUI? The release's `claude-rpc-<version>-x64-setup.exe` (installer, auto-updates) and `claude-rpc-<version>-x64-portable.exe` (no install) are the desktop app: it runs the same `setup` for you on first launch, then gives you the settings page in a window and daemon controls in the tray.
|
|
74
74
|
|
|
75
75
|
That's the whole pitch.
|
|
76
76
|
|
|
@@ -120,12 +120,12 @@ A rotation frame can show your **subscription usage** — `Usage · 34% weekly`
|
|
|
120
120
|
|
|
121
121
|
### on your machine
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
Local surfaces, all served from your own machine:
|
|
124
124
|
|
|
125
125
|
<table>
|
|
126
126
|
<tr>
|
|
127
127
|
<td align="center" width="50%"><b>web dashboard</b><br/><sub><code>claude-rpc serve</code> · port 47474</sub><br/><br/><img src="docs/dashboard.png" alt="Web dashboard with range selector, activity chart, heatmap, cost panel, languages stack, and leaderboards" /></td>
|
|
128
|
-
<td align="center" width="50%"><b>settings
|
|
128
|
+
<td align="center" width="50%"><b>settings</b><br/><sub><code>claude-rpc settings</code> · same port</sub><br/><br/><img src="docs/settings.png" alt="Settings page with daemon status and controls, and a card editor with a live preview per status" /></td>
|
|
129
129
|
</tr>
|
|
130
130
|
</table>
|
|
131
131
|
|
|
@@ -326,6 +326,7 @@ It's a thin bootstrapper — on the first session it just runs `npx claude-rpc@l
|
|
|
326
326
|
| `insights` | 3–5 auto-generated lines about your history |
|
|
327
327
|
| `wrapped` | Your animated year in review; `--publish` puts it on `claude-rpc.com/wrapped/<handle>` |
|
|
328
328
|
| `serve` | The local web dashboard (port 47474) |
|
|
329
|
+
| `settings` | Edit the card, daemon and per-project privacy in the browser |
|
|
329
330
|
| `export` | The aggregate as JSON, or daily rows as CSV (`--csv` `--out`) |
|
|
330
331
|
| **Share** | |
|
|
331
332
|
| `share [week\|month\|year\|all]` | Saves the poster PNG and copies a caption with your numbers and a link (`--no-png`, `--no-copy`, `--png <file>`) |
|
|
@@ -444,7 +445,7 @@ npm test # 550+ tests, a few seconds
|
|
|
444
445
|
npm run lint # eslint over src + test + vscode-extension
|
|
445
446
|
npm run start # run daemon in foreground
|
|
446
447
|
npm run serve # web dashboard against your real data
|
|
447
|
-
npm run dashboard #
|
|
448
|
+
npm run dashboard # desktop app shell (dev mode; shows the settings page)
|
|
448
449
|
npm run build:exe # SEA single-file binary for the current OS
|
|
449
450
|
```
|
|
450
451
|
|
package/SECURITY.md
CHANGED
|
@@ -415,6 +415,26 @@ No subprocess passes untrusted or remote input to a shell — arguments are
|
|
|
415
415
|
static or escaped. The historical `shell: true` paths (`verifyHookPipe`, and the
|
|
416
416
|
gist `gh` wrapper on Windows) use only trusted args.
|
|
417
417
|
|
|
418
|
+
## 4a. Local dashboard server — only while `serve`, `wrapped` or `settings` runs
|
|
419
|
+
|
|
420
|
+
**Source:** `src/server/index.js`, `src/server/settings.js`. The daemon serves
|
|
421
|
+
no HTTP. `claude-rpc serve` / `wrapped` / `settings` (and the desktop app, which
|
|
422
|
+
runs `serve` for its window) start a server bound to **127.0.0.1 only**, port
|
|
423
|
+
47474 (`CLAUDE_RPC_PORT`).
|
|
424
|
+
|
|
425
|
+
- **Host allowlist:** requests whose `Host` isn't `localhost` / `127.0.0.1` /
|
|
426
|
+
`::1` get 403, which closes DNS rebinding.
|
|
427
|
+
- **Read routes** return your own stats and config to the page.
|
|
428
|
+
- **Write routes** (`POST /api/settings`, `/api/daemon`, `/api/workspaces`)
|
|
429
|
+
save `config.json`, start/stop the daemon, and set per-project visibility.
|
|
430
|
+
Because any site open in your browser can send requests to localhost, they
|
|
431
|
+
are accepted only when the `Origin` header is this exact host and port and
|
|
432
|
+
the body is `application/json` (which a cross-site form cannot send without a
|
|
433
|
+
CORS preflight the server never answers). A save is validated and written
|
|
434
|
+
atomically; it can only change the claude-rpc config file.
|
|
435
|
+
- The desktop app's window gets no extra access: no preload script, no IPC,
|
|
436
|
+
`sandbox` on, `nodeIntegration` off. It is the same page a browser tab gets.
|
|
437
|
+
|
|
418
438
|
## 5. What it stores locally
|
|
419
439
|
|
|
420
440
|
Three per-user locations (paths are defined in `src/paths.js`):
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -2482,7 +2482,7 @@ process.on('unhandledRejection', (e) => {
|
|
|
2482
2482
|
// Fast-exit commands touch none of the core graph (they import their own
|
|
2483
2483
|
// module, if any); daemon control needs only ensure-daemon. Everything else
|
|
2484
2484
|
// loads the core once up front, so its bindings are set for every handler.
|
|
2485
|
-
const FAST_PATHS = new Set(['--version', '-V', '-v', '--help', '-h', 'help', '__complete', 'hook', 'mcp', 'daemon', 'serve', 'wrapped', 'scan-worker', 'tail', 'logs', 'log', 'pause', 'resume', 'unpause']);
|
|
2485
|
+
const FAST_PATHS = new Set(['--version', '-V', '-v', '--help', '-h', 'help', '__complete', 'hook', 'mcp', 'daemon', 'serve', 'wrapped', 'settings', 'scan-worker', 'tail', 'logs', 'log', 'pause', 'resume', 'unpause']);
|
|
2486
2486
|
// `<command> --help` → that command's page (before it runs at all).
|
|
2487
2487
|
if (cmd && (args.includes('--help') || args.includes('-h')) && !['hook', 'scan-worker', '__complete'].includes(cmd)) {
|
|
2488
2488
|
const { findCommand } = await import('./commands.js');
|
|
@@ -2646,6 +2646,8 @@ process.on('unhandledRejection', (e) => {
|
|
|
2646
2646
|
case 'wrapped':
|
|
2647
2647
|
if (args.includes('--publish')) { await doWrappedPublish(args); break; }
|
|
2648
2648
|
process.env.CLAUDE_RPC_OPEN_PATH = '/wrapped'; await import('./server/index.js'); break;
|
|
2649
|
+
case 'settings':
|
|
2650
|
+
process.env.CLAUDE_RPC_OPEN_PATH = '/settings'; await import('./server/index.js'); break;
|
|
2649
2651
|
case 'pause': await doPause(args); break;
|
|
2650
2652
|
case 'resume':
|
|
2651
2653
|
case 'unpause': await doResume(); break;
|
package/src/commands.js
CHANGED
|
@@ -63,6 +63,7 @@ export const COMMANDS = [
|
|
|
63
63
|
{ name: 'wrapped', group: 'stats', summary: 'Your animated year in review',
|
|
64
64
|
flags: [['--publish', 'Put it on claude-rpc.com/wrapped/<handle>'], ['--year', 'Which year', 'any'], ['--yes', 'Skip the confirm']] },
|
|
65
65
|
{ name: 'serve', group: 'stats', summary: 'Open the live web dashboard' },
|
|
66
|
+
{ name: 'settings', group: 'start', summary: 'Edit your card, daemon and privacy in the browser' },
|
|
66
67
|
{ name: 'export', group: 'stats', summary: 'Everything as JSON, or daily rows as CSV',
|
|
67
68
|
flags: [['--csv', 'Daily rows as CSV'], ['--out', 'Write to a file', 'file']] },
|
|
68
69
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Config save helper for the settings page (src/server/settings.js). Pure —
|
|
2
|
+
// no fs — so test/config-edit.test.js can exercise it directly.
|
|
3
|
+
//
|
|
4
|
+
// The user's config.json holds OVERRIDES only. loadConfig deep-merges it over
|
|
5
|
+
// DEFAULT_CONFIG, and arrays REPLACE on that merge. The settings page therefore
|
|
6
|
+
// displays the merged view, but a save must write back only what the user
|
|
7
|
+
// changed. Writing the whole view would freeze every default into the file.
|
|
8
|
+
// Writing an untouched empty field would do worse: `presence.buttons: []`
|
|
9
|
+
// deletes the default button, because an array in the file replaces the default.
|
|
10
|
+
|
|
11
|
+
function isPlainObject(v) {
|
|
12
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function deepEqual(a, b) {
|
|
16
|
+
if (a === b) return true;
|
|
17
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
18
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
19
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
20
|
+
}
|
|
21
|
+
if (!isPlainObject(a) || !isPlainObject(b)) return false;
|
|
22
|
+
const ka = Object.keys(a);
|
|
23
|
+
if (ka.length !== Object.keys(b).length) return false;
|
|
24
|
+
return ka.every((k) => Object.prototype.hasOwnProperty.call(b, k) && deepEqual(a[k], b[k]));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Returns a copy of `raw` (the user's config.json as it is on disk now) with
|
|
28
|
+
// only the edits applied. `base` is what the page showed before the user
|
|
29
|
+
// touched anything, and `edited` is the same view after their edits. A key
|
|
30
|
+
// whose value is the same in both is left exactly as it is in `raw`: it isn't
|
|
31
|
+
// added, rewritten or removed. That also keeps keys another tool wrote while
|
|
32
|
+
// the page was open. A changed key is written. A changed array is written
|
|
33
|
+
// whole, which matches the merge rule. A key the page removed (a cleared
|
|
34
|
+
// field) is deleted, so the daemon falls back to its default.
|
|
35
|
+
export function applyEdits(raw, base, edited) {
|
|
36
|
+
const out = isPlainObject(raw) ? structuredClone(raw) : {};
|
|
37
|
+
patch(out, isPlainObject(base) ? base : {}, isPlainObject(edited) ? edited : {});
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function patch(target, base, edited) {
|
|
42
|
+
for (const k of new Set([...Object.keys(base), ...Object.keys(edited)])) {
|
|
43
|
+
// Never let a crafted key reach Object.prototype through the save path.
|
|
44
|
+
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
|
45
|
+
const a = base[k];
|
|
46
|
+
const b = edited[k];
|
|
47
|
+
if (deepEqual(a, b)) continue;
|
|
48
|
+
if (b === undefined) { delete target[k]; continue; }
|
|
49
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
50
|
+
const had = Object.prototype.hasOwnProperty.call(target, k);
|
|
51
|
+
if (!isPlainObject(target[k])) target[k] = {};
|
|
52
|
+
patch(target[k], a, b);
|
|
53
|
+
// Removing a key the file never had shouldn't leave an empty `{}` behind.
|
|
54
|
+
if (!had && Object.keys(target[k]).length === 0) delete target[k];
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
target[k] = structuredClone(b);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/pricing.js
CHANGED
|
@@ -6,21 +6,26 @@
|
|
|
6
6
|
// To customize: edit this file and run `claude-rpc scan --force`.
|
|
7
7
|
|
|
8
8
|
const PRICING = {
|
|
9
|
-
//
|
|
9
|
+
// List prices checked 2026-11-12 against platform.claude.com/docs/en/about-claude/pricing.
|
|
10
|
+
|
|
11
|
+
// Fable family — Anthropic's frontier tier above Opus. 5.1 cut cache reads
|
|
12
|
+
// 4x; 5.2 cut the base rates to $8/$40.
|
|
10
13
|
'fable-5': { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
|
|
11
14
|
'fable-5-1': { input: 10.00, output: 50.00, cacheRead: 0.25, cacheWrite: 12.50 },
|
|
15
|
+
'fable-5-2': { input: 8.00, output: 40.00, cacheRead: 0.20, cacheWrite: 10.00 },
|
|
12
16
|
|
|
13
|
-
// Mythos (
|
|
17
|
+
// Mythos (limited availability): Fable-tier capabilities and prices.
|
|
14
18
|
'mythos-5': { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
|
|
15
19
|
'mythos-5-1': { input: 10.00, output: 50.00, cacheRead: 0.25, cacheWrite: 12.50 },
|
|
20
|
+
'mythos-5-2': { input: 8.00, output: 40.00, cacheRead: 0.20, cacheWrite: 10.00 },
|
|
16
21
|
|
|
17
|
-
// 5.x generation
|
|
18
|
-
//
|
|
19
|
-
//
|
|
22
|
+
// 5.x generation. Haiku 5.5 uses its <=100K-token-prompt rates; past 100K
|
|
23
|
+
// it's 5x, which a per-token table can't express — Claude Code prompts are
|
|
24
|
+
// usually under that.
|
|
20
25
|
'opus-5': { input: 5.00, output: 25.00, cacheRead: 0.50, cacheWrite: 6.25 },
|
|
21
26
|
'opus-5-5': { input: 4.00, output: 20.00, cacheRead: 0.20, cacheWrite: 5.00 },
|
|
22
27
|
'sonnet-5': { input: 2.00, output: 10.00, cacheRead: 0.20, cacheWrite: 2.50 },
|
|
23
|
-
'sonnet-5-5': { input: 2.00, output: 10.00, cacheRead: 0.
|
|
28
|
+
'sonnet-5-5': { input: 2.00, output: 10.00, cacheRead: 0.10, cacheWrite: 2.50 },
|
|
24
29
|
'haiku-5': { input: 0.10, output: 0.50, cacheRead: 0.01, cacheWrite: 0.125 },
|
|
25
30
|
'haiku-5-5': { input: 0.10, output: 0.50, cacheRead: 0.01, cacheWrite: 0.125 },
|
|
26
31
|
|
|
@@ -40,34 +45,45 @@ const PRICING = {
|
|
|
40
45
|
// Haiku 4.x family
|
|
41
46
|
'haiku-4': { input: 1.00, output: 5.00, cacheRead: 0.10, cacheWrite: 1.25 },
|
|
42
47
|
'haiku-4-5': { input: 1.00, output: 5.00, cacheRead: 0.10, cacheWrite: 1.25 },
|
|
43
|
-
|
|
44
|
-
// Generic fallbacks by tier. Opus uses the current-generation rates —
|
|
45
|
-
// unknown/future opus ids are far more likely to be 4.5+ than 4.1-era.
|
|
46
|
-
'fable': { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
|
|
47
|
-
'mythos': { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
|
|
48
|
-
'opus': { input: 5.00, output: 25.00, cacheRead: 0.50, cacheWrite: 6.25 },
|
|
49
|
-
'sonnet': { input: 3.00, output: 15.00, cacheRead: 0.30, cacheWrite: 3.75 },
|
|
50
|
-
'haiku': { input: 1.00, output: 5.00, cacheRead: 0.10, cacheWrite: 1.25 },
|
|
51
48
|
};
|
|
52
49
|
|
|
50
|
+
const TIERS = new Set(['opus', 'sonnet', 'haiku', 'fable', 'mythos']);
|
|
51
|
+
|
|
52
|
+
// Known versions per tier, oldest → newest, derived from the table above so
|
|
53
|
+
// adding a row is the only step when a model ships.
|
|
54
|
+
const VERSIONS = {};
|
|
55
|
+
for (const key of Object.keys(PRICING)) {
|
|
56
|
+
const [tier, major, minor = '0'] = key.split('-');
|
|
57
|
+
(VERSIONS[tier] ||= []).push({ key, major: Number(major), minor: Number(minor) });
|
|
58
|
+
}
|
|
59
|
+
for (const list of Object.values(VERSIONS)) list.sort((a, b) => a.major - b.major || a.minor - b.minor);
|
|
60
|
+
|
|
61
|
+
// Generic tier keys (`opus`, `sonnet`, …) for ids that name a tier but no
|
|
62
|
+
// version. They alias the newest known row: an id we can't place is far more
|
|
63
|
+
// likely to be a current model than a retired one.
|
|
64
|
+
for (const [tier, list] of Object.entries(VERSIONS)) PRICING[tier] = PRICING[list.at(-1).key];
|
|
65
|
+
|
|
53
66
|
const DEFAULT = PRICING.sonnet;
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
// A version token is 1–2 digits; anything longer is a date stamp (20251101).
|
|
69
|
+
const isVer = (t) => typeof t === 'string' && /^\d{1,2}$/.test(t);
|
|
56
70
|
|
|
57
71
|
// Map a model id like "claude-opus-4-7-20251101" to a pricing key.
|
|
58
72
|
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
73
|
+
// Split the id on `-`, find the first explicit tier token (a whole token, so
|
|
74
|
+
// `claude-sonneteer-x` doesn't match `sonnet`), then read the version digits
|
|
75
|
+
// after it — or before it, for legacy ids like `claude-3-5-sonnet-20241022`.
|
|
76
|
+
//
|
|
77
|
+
// An exact row wins. Otherwise the nearest EARLIER known version of that tier
|
|
78
|
+
// prices it: a model released after this table was written (fable-5-3,
|
|
79
|
+
// opus-6) costs what its closest predecessor does, not what the oldest row or
|
|
80
|
+
// a years-old generic rate says. Versions older than every row use the oldest.
|
|
81
|
+
// No tier at all → sonnet-class fallback.
|
|
66
82
|
//
|
|
67
83
|
// Memoized per id string: the scanner calls this (directly and via costFor)
|
|
68
84
|
// for every assistant turn of every transcript, but a corpus only ever holds a
|
|
69
|
-
// handful of distinct model ids. PRICING is never mutated, so the
|
|
70
|
-
// go stale; the size cap just bounds a pathological transcript.
|
|
85
|
+
// handful of distinct model ids. PRICING is never mutated after load, so the
|
|
86
|
+
// cache can't go stale; the size cap just bounds a pathological transcript.
|
|
71
87
|
const keyCache = new Map();
|
|
72
88
|
export function pricingKeyFor(modelId) {
|
|
73
89
|
if (typeof modelId !== 'string') return resolvePricingKey(modelId);
|
|
@@ -79,29 +95,57 @@ export function pricingKeyFor(modelId) {
|
|
|
79
95
|
return k;
|
|
80
96
|
}
|
|
81
97
|
|
|
82
|
-
|
|
83
|
-
|
|
98
|
+
// Pull { tier, major, minor } out of a model id. tier is null when the id
|
|
99
|
+
// names no known family; major is null when it names a tier but no version.
|
|
100
|
+
function parseModel(modelId) {
|
|
84
101
|
// Drop a context-window tag like `[1m]` (claude-opus-5-5[1m]) before parsing.
|
|
85
|
-
const parts = String(modelId).toLowerCase().replace(/\[[^\]]*\]/g, '').split('-');
|
|
102
|
+
const parts = String(modelId || '').toLowerCase().replace(/\[[^\]]*\]/g, '').split('-');
|
|
103
|
+
const tierIdx = parts.findIndex((p) => TIERS.has(p));
|
|
104
|
+
if (tierIdx === -1) return { tier: null, major: null, minor: 0 };
|
|
105
|
+
let major = null;
|
|
106
|
+
let minor = 0;
|
|
107
|
+
if (isVer(parts[tierIdx + 1])) {
|
|
108
|
+
major = Number(parts[tierIdx + 1]);
|
|
109
|
+
if (isVer(parts[tierIdx + 2])) minor = Number(parts[tierIdx + 2]);
|
|
110
|
+
} else {
|
|
111
|
+
// Legacy order: claude-3-5-sonnet-… / claude-3-opus-…
|
|
112
|
+
const before = parts.slice(0, tierIdx).filter(isVer);
|
|
113
|
+
if (before.length) { major = Number(before[0]); minor = Number(before[1] || 0); }
|
|
114
|
+
}
|
|
115
|
+
return { tier: parts[tierIdx], major, minor };
|
|
116
|
+
}
|
|
86
117
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
function resolvePricingKey(modelId) {
|
|
119
|
+
const { tier, major, minor } = parseModel(modelId);
|
|
120
|
+
if (!tier) return 'sonnet'; // unknown family — sonnet-class fallback
|
|
121
|
+
if (major === null) return tier; // tier named, no version — newest rates
|
|
122
|
+
|
|
123
|
+
const known = VERSIONS[tier];
|
|
124
|
+
let best = known[0];
|
|
125
|
+
for (const v of known) {
|
|
126
|
+
if (v.major < major || (v.major === major && v.minor <= minor)) best = v;
|
|
127
|
+
else break;
|
|
91
128
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
return best.key;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The model's own identity as a `tier-major[-minor]` key — what stats are
|
|
133
|
+
// bucketed and labelled by. Unlike pricingKeyFor this never folds a model into
|
|
134
|
+
// a neighbour: a release newer than the table (fable-5-3) is priced like
|
|
135
|
+
// fable-5-2 but still shows up as "Fable 5.3". Ids with no readable version
|
|
136
|
+
// fall back to the pricing key. Any key this returns is itself a valid input
|
|
137
|
+
// to pricingKeyFor/ratesFor.
|
|
138
|
+
const modelKeyCache = new Map();
|
|
139
|
+
export function modelKeyFor(modelId) {
|
|
140
|
+
if (typeof modelId !== 'string') return pricingKeyFor(modelId);
|
|
141
|
+
let k = modelKeyCache.get(modelId);
|
|
142
|
+
if (k === undefined) {
|
|
143
|
+
const { tier, major, minor } = parseModel(modelId);
|
|
144
|
+
k = tier && major !== null ? `${tier}-${major}${minor ? `-${minor}` : ''}` : pricingKeyFor(modelId);
|
|
145
|
+
if (modelKeyCache.size >= 256) modelKeyCache.clear();
|
|
146
|
+
modelKeyCache.set(modelId, k);
|
|
103
147
|
}
|
|
104
|
-
return
|
|
148
|
+
return k;
|
|
105
149
|
}
|
|
106
150
|
|
|
107
151
|
export function ratesFor(modelId) {
|
package/src/scanner.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join, basename } from 'node:path';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { CLAUDE_PROJECTS, SCAN_CACHE_PATH, AGGREGATE_PATH, DATA_DIR, EVENTS_LOG_PATH } from './paths.js';
|
|
5
5
|
import { languageOf } from './languages.js';
|
|
6
|
-
import { costFor,
|
|
6
|
+
import { costFor, modelKeyFor } from './pricing.js';
|
|
7
7
|
import { classifyShip } from './ships.js';
|
|
8
8
|
import { renameSyncRetry } from './atomic-rename.js';
|
|
9
9
|
import { localDateStamp } from './fmt.js';
|
|
@@ -17,7 +17,10 @@ import { localDateStamp } from './fmt.js';
|
|
|
17
17
|
// full rescan that backfills model-mix history for already-scanned files.
|
|
18
18
|
// v8: usage counted at each message's final values (usageDelta), not its first
|
|
19
19
|
// line's — re-parse to correct output tokens/cost in existing history.
|
|
20
|
-
|
|
20
|
+
// v9: model buckets keyed by the model's real version (modelKeyFor) and the
|
|
21
|
+
// 2026-11 price table (Fable 5.2, Sonnet 5.5 cache reads) — re-parse so
|
|
22
|
+
// history stops showing e.g. Fable 5.2 as "Fable 5" at 5.0 rates.
|
|
23
|
+
const CACHE_VERSION = 9;
|
|
21
24
|
|
|
22
25
|
// Cap counted gap between consecutive timestamps. Anything larger is treated
|
|
23
26
|
// as the user walking away — we count only what's plausibly active time.
|
|
@@ -375,8 +378,9 @@ function parseChunkInto(text, summary, pstate) {
|
|
|
375
378
|
const counted = usageDelta(pstate.recentIds, r.message?.id, r.message?.usage);
|
|
376
379
|
const firstSeen = !!counted?.first;
|
|
377
380
|
const u = r.message?.usage ? counted?.delta : null;
|
|
378
|
-
// Per-model split bucket, keyed by
|
|
379
|
-
|
|
381
|
+
// Per-model split bucket, keyed by the model's own version (not its
|
|
382
|
+
// pricing row) so a release newer than the price table keeps its name.
|
|
383
|
+
const mkey = turnModel ? modelKeyFor(turnModel) : null;
|
|
380
384
|
const mb = mkey ? (summary.byModel[mkey] ||= { turns: 0, tokens: 0, cost: 0 }) : null;
|
|
381
385
|
// Per-day model split (day granularity only — week/hour stay lean).
|
|
382
386
|
// Powers model-mix-over-time; the all-time byModel can't trend.
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
<button data-range="all">All</button>
|
|
29
29
|
</div>
|
|
30
30
|
<a class="wrapped-link" href="/wrapped" title="Your animated year-in-review">✦ Wrapped</a>
|
|
31
|
+
<a class="wrapped-link" href="/settings" title="Card, daemon and privacy settings">Settings</a>
|
|
31
32
|
<span class="model" id="model">—</span>
|
|
32
33
|
<span class="status"><span id="statustext">—</span></span>
|
|
33
34
|
</div>
|