claude-code-cost 0.24.0-rc.1 → 0.25.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/lib/net-guard.js +1 -1
- package/lib/usage-probe.js +2 -3
- package/package.json +2 -1
- package/public/app.js +35 -15
- package/server.js +7 -6
package/lib/net-guard.js
CHANGED
|
@@ -245,7 +245,7 @@ function createNetGuard(config = {}) {
|
|
|
245
245
|
* @param {{maxHeaderSize?: number, onUpgrade?: (req: any, socket: any, head: Buffer) => void}} [opts]
|
|
246
246
|
*/
|
|
247
247
|
function listenLoopback(app, port, onReady, opts = {}) {
|
|
248
|
-
const http = require('http');
|
|
248
|
+
const http = require('node:http');
|
|
249
249
|
const serverOpts = opts.maxHeaderSize ? { maxHeaderSize: opts.maxHeaderSize } : {};
|
|
250
250
|
const makeServer = (handler) => {
|
|
251
251
|
const s = http.createServer(serverOpts, handler);
|
package/lib/usage-probe.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// The call runs no model turn, and total_cost_usd comes back 0. It still spawns a full CLI process
|
|
9
9
|
// and fires that config dir's SessionStart hooks, so callers must cache rather than poll.
|
|
10
10
|
|
|
11
|
-
const { spawn } = require('child_process');
|
|
11
|
+
const { spawn } = require('node:child_process');
|
|
12
12
|
|
|
13
13
|
// The answer is one HTTPS call plus a scan of every transcript touched in the last seven days.
|
|
14
14
|
const PROBE_TIMEOUT_MS = 60000;
|
|
@@ -54,8 +54,7 @@ function probeUsage({ claudeDir } = {}) {
|
|
|
54
54
|
|
|
55
55
|
child.stdout.on('data', (d) => {
|
|
56
56
|
buf += d.toString();
|
|
57
|
-
let nl;
|
|
58
|
-
while ((nl = buf.indexOf('\n')) >= 0) {
|
|
57
|
+
for (let nl = buf.indexOf('\n'); nl >= 0; nl = buf.indexOf('\n')) {
|
|
59
58
|
const line = buf.slice(0, nl).trim();
|
|
60
59
|
buf = buf.slice(nl + 1);
|
|
61
60
|
if (!line) continue;
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -3365,24 +3365,36 @@ async function refreshIfStale() {
|
|
|
3365
3365
|
// 'π'), so the key alone cannot identify the binding. The hub owns the keymap and normalizes;
|
|
3366
3366
|
// these tests only decide whether a press is the hub's to handle.
|
|
3367
3367
|
document.addEventListener('keydown', (e) => {
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
};
|
|
3372
|
-
if (e.ctrlKey && e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) {
|
|
3373
|
-
fwd();
|
|
3374
|
-
}
|
|
3375
|
-
// Own branch: the Alt+digit case below requires !ctrlKey. The hub owns the Ctrl+Alt+letter
|
|
3376
|
-
// keymap and ignores unbound letters.
|
|
3377
|
-
if (e.ctrlKey && e.altKey && !e.shiftKey && !e.metaKey && (/^[a-z]$/i.test(e.key) || /^Key[A-Z]$/.test(e.code))) {
|
|
3378
|
-
fwd();
|
|
3379
|
-
}
|
|
3380
|
-
if (e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey && (/^[1-9]$/.test(e.key) || /^Digit[1-9]$/.test(e.code))) {
|
|
3381
|
-
fwd();
|
|
3382
|
-
}
|
|
3368
|
+
if (!isHubKey(e)) return;
|
|
3369
|
+
e.preventDefault();
|
|
3370
|
+
hubPost({ type: 'hub:keydown', key: e.key, code: e.code, ctrl: e.ctrlKey, alt: e.altKey, shift: e.shiftKey });
|
|
3383
3371
|
});
|
|
3384
3372
|
})();
|
|
3385
3373
|
|
|
3374
|
+
// The combos the hub binds, from its hub:keys message. Null until one arrives: a hub from before
|
|
3375
|
+
// hub:keys sends none, and the fallback filter below is what such a hub expects.
|
|
3376
|
+
let hubKeys = null;
|
|
3377
|
+
|
|
3378
|
+
// A copy of the hub's comboOf(): its names must match the hub:keys list.
|
|
3379
|
+
function hubCombo(e) {
|
|
3380
|
+
const lower = (e.key || '').toLowerCase();
|
|
3381
|
+
const m = /^(?:Key|Digit)([A-Z1-9])$/.exec(e.code || '');
|
|
3382
|
+
const key = /^[a-z1-9]$/.test(lower) ? lower : m ? m[1].toLowerCase() : e.key;
|
|
3383
|
+
const mods = [e.ctrlKey && 'ctrl', e.altKey && 'alt', e.shiftKey && 'shift', e.metaKey && 'meta'];
|
|
3384
|
+
return [...mods, key].filter(Boolean).join('+');
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
function isHubKey(e) {
|
|
3388
|
+
if (hubKeys) return hubKeys.has(hubCombo(e));
|
|
3389
|
+
if (e.ctrlKey && e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) return true;
|
|
3390
|
+
// Own branch: the Alt+digit case below requires !ctrlKey. The hub owns the Ctrl+Alt+letter
|
|
3391
|
+
// keymap and ignores unbound letters.
|
|
3392
|
+
if (e.ctrlKey && e.altKey && !e.shiftKey && !e.metaKey && (/^[a-z]$/i.test(e.key) || /^Key[A-Z]$/.test(e.code))) {
|
|
3393
|
+
return true;
|
|
3394
|
+
}
|
|
3395
|
+
return e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey && (/^[1-9]$/.test(e.key) || /^Digit[1-9]$/.test(e.code));
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3386
3398
|
// Hoisted out of initHubTheme so initHubProject can share it.
|
|
3387
3399
|
const hubOrigin = () => (window.__HUB__?.url ? new URL(window.__HUB__.url).origin : null);
|
|
3388
3400
|
|
|
@@ -3430,6 +3442,14 @@ window.hubNavigate = function hubNavigate(app, url) {
|
|
|
3430
3442
|
});
|
|
3431
3443
|
})();
|
|
3432
3444
|
|
|
3445
|
+
(function initHubKeys() {
|
|
3446
|
+
window.addEventListener('message', (e) => {
|
|
3447
|
+
if (e.source !== window.parent || e.origin !== hubOrigin()) return;
|
|
3448
|
+
if (e.data?.type !== 'hub:keys' || !Array.isArray(e.data.keys)) return;
|
|
3449
|
+
hubKeys = new Set(e.data.keys.filter((k) => typeof k === 'string'));
|
|
3450
|
+
});
|
|
3451
|
+
})();
|
|
3452
|
+
|
|
3433
3453
|
(function initHubActive() {
|
|
3434
3454
|
window.addEventListener('message', (e) => {
|
|
3435
3455
|
if (e.source !== window.parent || e.origin !== hubOrigin()) return;
|
package/server.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const express = require('express');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const { createReadStream } =
|
|
8
|
-
const { createInterface } = require('readline');
|
|
9
|
-
const os = require('os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const { createReadStream } = fs;
|
|
8
|
+
const { createInterface } = require('node:readline');
|
|
9
|
+
const os = require('node:os');
|
|
10
10
|
const { createNetGuard } = require('./lib/net-guard');
|
|
11
11
|
const { probeUsage, normalizeUsage } = require('./lib/usage-probe');
|
|
12
12
|
|
|
@@ -327,7 +327,8 @@ function rangeBucket(range) {
|
|
|
327
327
|
// bucket total, unlike modelDistribution which drops them entirely.
|
|
328
328
|
function addBucketModelCost(acc, key, model, cost) {
|
|
329
329
|
const mk = isRealModel(model) ? model : 'other';
|
|
330
|
-
|
|
330
|
+
acc[key] ||= {};
|
|
331
|
+
acc[key][mk] = (acc[key][mk] || 0) + cost;
|
|
331
332
|
}
|
|
332
333
|
|
|
333
334
|
// Gap-filled so empty buckets stay visible in the chart. The bucket total is derived from
|