claude-code-cost 0.20.0 → 0.22.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 -1
- package/package.json +1 -1
- package/public/app.js +237 -49
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512-maskable.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/index.html +17 -30
- package/public/manifest.json +7 -0
- package/public/style.css +177 -28
- package/server.js +9 -5
package/README.md
CHANGED
|
@@ -18,6 +18,10 @@ npx claude-code-cost --open
|
|
|
18
18
|
|
|
19
19
|
That's it — no hooks, no config. The dashboard reads the JSONL session logs Claude Code already writes to `~/.claude/projects/` and aggregates them server-side. Completely read-only; nothing leaves your machine.
|
|
20
20
|
|
|
21
|
+
### Install as a desktop app
|
|
22
|
+
|
|
23
|
+
The dashboard is a PWA. With the server running, open it in Chrome or Edge and click **Install** in the top bar (or the install icon in the address bar). Safari on macOS: **File → Add to Dock**. The app opens in its own window with a Start menu / Dock entry and right-click shortcuts to Overview and Insights. The server still has to be running; the installed app is a window onto `http://localhost:3543`.
|
|
24
|
+
|
|
21
25
|
## Features
|
|
22
26
|
|
|
23
27
|
- **Top-down drill-down** — total → project → session → message; every number is one click from its breakdown
|
|
@@ -44,7 +48,7 @@ That's it — no hooks, no config. The dashboard reads the JSONL session logs Cl
|
|
|
44
48
|
--open Open browser on start
|
|
45
49
|
```
|
|
46
50
|
|
|
47
|
-
The config dir can also be set via the `CLAUDE_CONFIG_DIR` environment variable.
|
|
51
|
+
The config dir can also be set via the `CLAUDE_CONFIG_DIR` environment variable. With a custom dir only `<dir>/projects` is scanned; the default profile also picks up `~/.config/claude/projects`.
|
|
48
52
|
|
|
49
53
|
## License
|
|
50
54
|
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -284,7 +284,7 @@ function migrateStoredPreset(value) {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// Reads the JSON tagged union and the legacy bare "3" / "today" scalar that predates it: the key is
|
|
287
|
-
// a preference, so
|
|
287
|
+
// a preference, so purgeLegacyLocalCache() never evicts it and old values outlive any cache clear.
|
|
288
288
|
// Anything unrecognized returns null, which lands on the default preset.
|
|
289
289
|
function parseStoredRange(raw) {
|
|
290
290
|
if (!raw) return null;
|
|
@@ -444,61 +444,41 @@ function updateUrl() {
|
|
|
444
444
|
// #region FETCH
|
|
445
445
|
|
|
446
446
|
const BROWSER_CACHE_TTL = 5 * 60 * 1000; // 5 min
|
|
447
|
-
const
|
|
447
|
+
const MAX_CACHE_ENTRIES = 20;
|
|
448
448
|
let forceRefresh = false;
|
|
449
449
|
// Age of the data on screen, for the auto-refresh staleness check. A cache hit carries its own
|
|
450
|
-
// timestamp forward, so a
|
|
450
|
+
// timestamp forward, so a re-render from cache doesn't look freshly fetched.
|
|
451
451
|
let dataFetchedAt = 0;
|
|
452
452
|
|
|
453
|
+
// In memory on purpose: the server can be restarted against another CLAUDE_CONFIG_DIR (the hub does
|
|
454
|
+
// this on a config-dir switch and reloads the page), and a cache that outlives the page would keep
|
|
455
|
+
// showing the previous dir's data. The server's own 30 s cache absorbs the reload cost.
|
|
456
|
+
const dataCache = new Map();
|
|
457
|
+
|
|
453
458
|
function getCached(key) {
|
|
454
459
|
if (forceRefresh) return null;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (v !== CACHE_VERSION || Date.now() - ts > BROWSER_CACHE_TTL) return null;
|
|
460
|
-
dataFetchedAt = Math.max(dataFetchedAt, ts);
|
|
461
|
-
return data;
|
|
462
|
-
} catch {
|
|
460
|
+
const hit = dataCache.get(key);
|
|
461
|
+
if (!hit) return null;
|
|
462
|
+
if (Date.now() - hit.ts > BROWSER_CACHE_TTL) {
|
|
463
|
+
dataCache.delete(key);
|
|
463
464
|
return null;
|
|
464
465
|
}
|
|
466
|
+
dataFetchedAt = Math.max(dataFetchedAt, hit.ts);
|
|
467
|
+
return hit.data;
|
|
465
468
|
}
|
|
466
469
|
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
} catch {
|
|
472
|
-
/* storage full — ignore */
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function pruneLocalCache() {
|
|
477
|
-
const MAX_ENTRIES = 20;
|
|
478
|
-
const entries = [];
|
|
479
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
480
|
-
const k = localStorage.key(i);
|
|
481
|
-
if (!k.startsWith('cc-cost:')) continue;
|
|
482
|
-
// Prefs are not cache entries — they have no ts, so they'd sort oldest-first and be
|
|
483
|
-
// evicted ahead of real data while also eating the entry budget.
|
|
484
|
-
if (isPrefKey(k)) continue;
|
|
485
|
-
try {
|
|
486
|
-
const { ts } = JSON.parse(localStorage.getItem(k));
|
|
487
|
-
entries.push({ k, ts });
|
|
488
|
-
} catch {
|
|
489
|
-
entries.push({ k, ts: 0 });
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
if (entries.length <= MAX_ENTRIES) return;
|
|
493
|
-
entries.sort((a, b) => a.ts - b.ts);
|
|
494
|
-
const toRemove = entries.length - MAX_ENTRIES;
|
|
495
|
-
for (let i = 0; i < toRemove; i++) localStorage.removeItem(entries[i].k);
|
|
470
|
+
function cacheData(key, data) {
|
|
471
|
+
dataCache.delete(key);
|
|
472
|
+
dataCache.set(key, { data, ts: Date.now() });
|
|
473
|
+
if (dataCache.size > MAX_CACHE_ENTRIES) dataCache.delete(dataCache.keys().next().value);
|
|
496
474
|
}
|
|
497
475
|
|
|
498
476
|
function isPrefKey(k) {
|
|
499
|
-
return k.startsWith('cc-cost:sort:') || k === 'cc-cost:range' || k === 'cc-cost:scope';
|
|
477
|
+
return k.startsWith('cc-cost:sort:') || k === 'cc-cost:range' || k === 'cc-cost:scope' || k === 'cc-cost:view';
|
|
500
478
|
}
|
|
501
|
-
|
|
479
|
+
|
|
480
|
+
// Earlier versions persisted API payloads under cc-cost:<url>; drop what they left behind.
|
|
481
|
+
function purgeLegacyLocalCache() {
|
|
502
482
|
const keys = [];
|
|
503
483
|
for (let i = 0; i < localStorage.length; i++) {
|
|
504
484
|
const k = localStorage.key(i);
|
|
@@ -516,7 +496,7 @@ async function fetchJSON(url, skipCache) {
|
|
|
516
496
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
517
497
|
const data = await res.json();
|
|
518
498
|
dataFetchedAt = Date.now();
|
|
519
|
-
if (!skipCache)
|
|
499
|
+
if (!skipCache) cacheData(url, data);
|
|
520
500
|
return data;
|
|
521
501
|
}
|
|
522
502
|
|
|
@@ -2469,7 +2449,6 @@ async function navigate(view, params) {
|
|
|
2469
2449
|
if (view !== 'detail') selectRow(0);
|
|
2470
2450
|
}
|
|
2471
2451
|
|
|
2472
|
-
// biome-ignore lint/correctness/noUnusedVariables: called from HTML onclick
|
|
2473
2452
|
async function navigateToSessions(encodedPath, name) {
|
|
2474
2453
|
lastSelectedProject = encodedPath;
|
|
2475
2454
|
currentProjectPath = encodedPath;
|
|
@@ -2570,7 +2549,7 @@ async function refreshData() {
|
|
|
2570
2549
|
const minWait = new Promise((r) => setTimeout(r, 250));
|
|
2571
2550
|
try {
|
|
2572
2551
|
await fetch('/api/refresh', { method: 'POST' });
|
|
2573
|
-
|
|
2552
|
+
dataCache.clear();
|
|
2574
2553
|
forceRefresh = true;
|
|
2575
2554
|
lastRenderHash = {};
|
|
2576
2555
|
await loadAndRender(currentView);
|
|
@@ -2668,7 +2647,183 @@ function ensureViewElements() {
|
|
|
2668
2647
|
|
|
2669
2648
|
// #region MODAL
|
|
2670
2649
|
|
|
2650
|
+
// The picker drills in — it navigates to a project's sessions view. That is a different act
|
|
2651
|
+
// from the hub's scope chip, which filters every view without moving the cursor.
|
|
2652
|
+
let pickerProjects = [];
|
|
2653
|
+
let pickerRows = [];
|
|
2654
|
+
let pickerIdx = 0;
|
|
2655
|
+
|
|
2656
|
+
async function openProjectPicker() {
|
|
2657
|
+
const modal = document.getElementById('projectPickerModal');
|
|
2658
|
+
const input = document.getElementById('projectPickerInput');
|
|
2659
|
+
const list = document.getElementById('projectPickerList');
|
|
2660
|
+
modal.classList.add('visible');
|
|
2661
|
+
input.value = '';
|
|
2662
|
+
input.focus();
|
|
2663
|
+
list.innerHTML = '<div class="picker-empty">Loading...</div>';
|
|
2664
|
+
try {
|
|
2665
|
+
// Deliberately unscoped: a switcher that only lists the project you are already scoped to
|
|
2666
|
+
// cannot switch anything.
|
|
2667
|
+
pickerProjects = ((await fetchJSON(`/api/projects?${rangeParams()}`)) || []).sort((a, b) =>
|
|
2668
|
+
sortCompare(a, b, 'totalCost', 'desc'),
|
|
2669
|
+
);
|
|
2670
|
+
} catch {
|
|
2671
|
+
pickerProjects = [];
|
|
2672
|
+
list.innerHTML = '<div class="picker-empty">Failed to load projects</div>';
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
renderProjectPicker();
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
function closeProjectPicker() {
|
|
2679
|
+
document.getElementById('projectPickerModal').classList.remove('visible');
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
function renderProjectPicker() {
|
|
2683
|
+
const list = document.getElementById('projectPickerList');
|
|
2684
|
+
const q = document.getElementById('projectPickerInput').value.trim().toLowerCase();
|
|
2685
|
+
pickerRows = q ? pickerProjects.filter((p) => p.name.toLowerCase().includes(q)) : pickerProjects;
|
|
2686
|
+
if (!pickerRows.length) {
|
|
2687
|
+
list.innerHTML = '<div class="picker-empty">No projects match</div>';
|
|
2688
|
+
return;
|
|
2689
|
+
}
|
|
2690
|
+
list.innerHTML = pickerRows
|
|
2691
|
+
.map(
|
|
2692
|
+
(p, i) => `<button class="picker-row" onclick="pickProject(${i})">
|
|
2693
|
+
<span class="picker-name">${esc(p.name)}</span>
|
|
2694
|
+
<span class="picker-cost">${formatCost(p.totalCost)}</span>
|
|
2695
|
+
</button>`,
|
|
2696
|
+
)
|
|
2697
|
+
.join('');
|
|
2698
|
+
setPickerCursor(0);
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2701
|
+
function setPickerCursor(idx) {
|
|
2702
|
+
const list = document.getElementById('projectPickerList');
|
|
2703
|
+
list.children[pickerIdx]?.classList.remove('selected');
|
|
2704
|
+
pickerIdx = Math.min(Math.max(idx, 0), pickerRows.length - 1);
|
|
2705
|
+
const row = list.children[pickerIdx];
|
|
2706
|
+
row?.classList.add('selected');
|
|
2707
|
+
row?.scrollIntoView({ block: 'nearest' });
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
function pickProject(idx) {
|
|
2711
|
+
const p = pickerRows[idx];
|
|
2712
|
+
if (!p) return;
|
|
2713
|
+
closeProjectPicker();
|
|
2714
|
+
navigateToSessions(p.encodedPath, p.name);
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
function initProjectPicker() {
|
|
2718
|
+
const input = document.getElementById('projectPickerInput');
|
|
2719
|
+
input.addEventListener('input', renderProjectPicker);
|
|
2720
|
+
// Bound on the input because the global handler bails out on INPUT targets.
|
|
2721
|
+
input.addEventListener('keydown', (e) => {
|
|
2722
|
+
if (e.key === 'Escape') {
|
|
2723
|
+
e.preventDefault();
|
|
2724
|
+
closeProjectPicker();
|
|
2725
|
+
} else if (e.key === 'ArrowDown' || (e.key === 'n' && e.ctrlKey)) {
|
|
2726
|
+
e.preventDefault();
|
|
2727
|
+
setPickerCursor(pickerIdx + 1);
|
|
2728
|
+
} else if (e.key === 'ArrowUp' || (e.key === 'p' && e.ctrlKey)) {
|
|
2729
|
+
e.preventDefault();
|
|
2730
|
+
setPickerCursor(pickerIdx - 1);
|
|
2731
|
+
} else if (e.key === 'Enter') {
|
|
2732
|
+
e.preventDefault();
|
|
2733
|
+
pickProject(pickerIdx);
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
// Each entry pairs a left and a right group onto the same grid rows, so their
|
|
2739
|
+
// headings sit level and the shorter group just leaves empty rows.
|
|
2740
|
+
// `combo` joins the keys with a plus (a chord) instead of listing them as
|
|
2741
|
+
// alternatives; `hub` marks rows that only work inside Claude Code Hub.
|
|
2742
|
+
const SHORTCUT_PAIRS = [
|
|
2743
|
+
[
|
|
2744
|
+
{
|
|
2745
|
+
title: 'Navigate',
|
|
2746
|
+
rows: [
|
|
2747
|
+
{ keys: ['1'], label: 'Overview' },
|
|
2748
|
+
{ keys: ['2'], label: 'Insights' },
|
|
2749
|
+
{ keys: ['Backspace'], label: 'Go back' },
|
|
2750
|
+
{ keys: ['Shift', 'P'], combo: true, label: 'Switch project' },
|
|
2751
|
+
{ keys: ['Esc'], label: 'Close modal / go back' },
|
|
2752
|
+
],
|
|
2753
|
+
},
|
|
2754
|
+
{
|
|
2755
|
+
title: 'Table',
|
|
2756
|
+
rows: [
|
|
2757
|
+
{ keys: ['J', '↓'], label: 'Next row' },
|
|
2758
|
+
{ keys: ['K', '↑'], label: 'Previous row' },
|
|
2759
|
+
{ keys: ['Enter', 'Space'], label: 'Open selected row' },
|
|
2760
|
+
],
|
|
2761
|
+
},
|
|
2762
|
+
],
|
|
2763
|
+
[
|
|
2764
|
+
{
|
|
2765
|
+
title: 'Timeline range',
|
|
2766
|
+
rows: [
|
|
2767
|
+
{ keys: ['←', '→'], label: 'Pan one step' },
|
|
2768
|
+
{ keys: ['Shift', '←/→'], combo: true, label: 'Pan a full window' },
|
|
2769
|
+
{ keys: ['Home', 'End'], label: 'Jump to start / end' },
|
|
2770
|
+
],
|
|
2771
|
+
},
|
|
2772
|
+
{
|
|
2773
|
+
title: 'View',
|
|
2774
|
+
rows: [
|
|
2775
|
+
{ keys: ['R'], label: 'Refresh data' },
|
|
2776
|
+
{ keys: ['T'], label: 'Toggle theme' },
|
|
2777
|
+
{ keys: ['?'], label: 'Show this help' },
|
|
2778
|
+
],
|
|
2779
|
+
},
|
|
2780
|
+
],
|
|
2781
|
+
[
|
|
2782
|
+
{
|
|
2783
|
+
title: 'Hub',
|
|
2784
|
+
hub: true,
|
|
2785
|
+
rows: [
|
|
2786
|
+
{ keys: ['Ctrl', 'Alt', '←/→'], combo: true, label: 'Previous / next hub app' },
|
|
2787
|
+
{ keys: ['Alt', '1…9'], combo: true, label: 'Jump to hub app by number' },
|
|
2788
|
+
{ keys: ['Ctrl', 'Alt', 'P'], combo: true, label: 'Project picker' },
|
|
2789
|
+
],
|
|
2790
|
+
},
|
|
2791
|
+
],
|
|
2792
|
+
];
|
|
2793
|
+
|
|
2794
|
+
const EMPTY_GROUP = { title: '', rows: [] };
|
|
2795
|
+
|
|
2796
|
+
// Interleaves each pair's rows left-then-right so CSS grid auto-placement lands
|
|
2797
|
+
// them on shared row tracks (see .shortcuts in style.css).
|
|
2798
|
+
function buildHelpShortcuts() {
|
|
2799
|
+
const cells = [];
|
|
2800
|
+
SHORTCUT_PAIRS.forEach(([left, right = EMPTY_GROUP], pair) => {
|
|
2801
|
+
const first = pair === 0 ? ' sc-first' : '';
|
|
2802
|
+
const sides = [
|
|
2803
|
+
[left, 'sc-l'],
|
|
2804
|
+
[right, 'sc-r'],
|
|
2805
|
+
];
|
|
2806
|
+
const head = (g, side) =>
|
|
2807
|
+
g.title ? `<div class="${esc(`sc-group ${side}${first}${g.hub ? ' sc-hub' : ''}`)}">${g.title}</div>` : '';
|
|
2808
|
+
cells.push(sides.map(([g, side]) => head(g, side)).join(''));
|
|
2809
|
+
for (let i = 0; i < Math.max(left.rows.length, right.rows.length); i++) {
|
|
2810
|
+
for (const [group, side] of sides) {
|
|
2811
|
+
const row = group.rows[i];
|
|
2812
|
+
if (!row) continue;
|
|
2813
|
+
const sep = row.combo ? '<span class="sc-plus">+</span>' : '<span class="sc-or">/</span>';
|
|
2814
|
+
const keys = row.keys.map((k) => `<kbd>${esc(k)}</kbd>`).join(sep);
|
|
2815
|
+
const cls = side + (group.hub ? ' sc-hub' : '');
|
|
2816
|
+
cells.push(`<dt class="${esc(cls)}">${keys}</dt><dd class="${esc(cls)}">${esc(row.label)}</dd>`);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
});
|
|
2820
|
+
return cells.join('');
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2671
2823
|
function toggleHelpModal() {
|
|
2824
|
+
const list = document.getElementById('helpShortcuts');
|
|
2825
|
+
if (!list.childElementCount) list.innerHTML = buildHelpShortcuts();
|
|
2826
|
+
list.classList.toggle('sc-standalone', !window.__HUB__?.enabled);
|
|
2672
2827
|
document.getElementById('helpModal').classList.toggle('visible');
|
|
2673
2828
|
}
|
|
2674
2829
|
|
|
@@ -2733,7 +2888,7 @@ document.addEventListener('keydown', (e) => {
|
|
|
2733
2888
|
|
|
2734
2889
|
const anyModal = document.querySelector('.modal-overlay.visible');
|
|
2735
2890
|
if (anyModal) {
|
|
2736
|
-
if (e.key === 'Escape') {
|
|
2891
|
+
if (e.key === 'Escape' || (e.key === '?' && anyModal.id === 'helpModal')) {
|
|
2737
2892
|
anyModal.classList.remove('visible');
|
|
2738
2893
|
e.preventDefault();
|
|
2739
2894
|
}
|
|
@@ -2752,6 +2907,13 @@ document.addEventListener('keydown', (e) => {
|
|
|
2752
2907
|
|
|
2753
2908
|
if (e.ctrlKey || e.altKey || e.metaKey) return;
|
|
2754
2909
|
|
|
2910
|
+
// Shift+P is the project switcher across the hub apps; matches memory and marketplace.
|
|
2911
|
+
if (e.key === 'P' && e.shiftKey) {
|
|
2912
|
+
e.preventDefault();
|
|
2913
|
+
openProjectPicker();
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2755
2917
|
if (e.key === '?' || (e.key === '/' && e.shiftKey)) {
|
|
2756
2918
|
e.preventDefault();
|
|
2757
2919
|
toggleHelpModal();
|
|
@@ -2851,7 +3013,7 @@ function isAppActive() {
|
|
|
2851
3013
|
async function refreshIfStale() {
|
|
2852
3014
|
if (refreshing || !isAppActive()) return;
|
|
2853
3015
|
if (Date.now() - dataFetchedAt < BROWSER_CACHE_TTL) return;
|
|
2854
|
-
// No
|
|
3016
|
+
// No dataCache.clear() unlike refreshData: forceRefresh already bypasses the cache read, and the
|
|
2855
3017
|
// fresh payloads overwrite their own keys. Views the user isn't on keep their cache.
|
|
2856
3018
|
refreshing = true;
|
|
2857
3019
|
forceRefresh = true;
|
|
@@ -2892,8 +3054,9 @@ async function refreshIfStale() {
|
|
|
2892
3054
|
if (e.ctrlKey && e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) {
|
|
2893
3055
|
fwd(e.key);
|
|
2894
3056
|
}
|
|
2895
|
-
//
|
|
2896
|
-
|
|
3057
|
+
// Own branch: the Alt+digit case below requires !ctrlKey. The hub owns the Ctrl+Alt+letter
|
|
3058
|
+
// keymap and ignores unbound letters.
|
|
3059
|
+
if (e.ctrlKey && e.altKey && !e.shiftKey && !e.metaKey && /^[a-z]$/i.test(e.key)) {
|
|
2897
3060
|
fwd(e.key);
|
|
2898
3061
|
}
|
|
2899
3062
|
if (e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey && /^[1-9]$/.test(e.key)) {
|
|
@@ -2985,10 +3148,12 @@ document.addEventListener('click', async (e) => {
|
|
|
2985
3148
|
});
|
|
2986
3149
|
|
|
2987
3150
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
3151
|
+
purgeLegacyLocalCache();
|
|
2988
3152
|
const state = getUrlState();
|
|
2989
3153
|
dateRange = loadDateRange();
|
|
2990
3154
|
buildRangePresets();
|
|
2991
3155
|
renderRangeTrigger();
|
|
3156
|
+
initProjectPicker();
|
|
2992
3157
|
|
|
2993
3158
|
// Resolve the scope before any navigate() so the first /api/overview already carries
|
|
2994
3159
|
// &project=. Read window.location.search directly, not getUrlState() — that falls back to
|
|
@@ -3042,4 +3207,27 @@ if ('serviceWorker' in navigator) {
|
|
|
3042
3207
|
navigator.serviceWorker.register('/sw.js').catch(() => {});
|
|
3043
3208
|
}
|
|
3044
3209
|
|
|
3210
|
+
const installBtn = document.getElementById('installBtn');
|
|
3211
|
+
let deferredInstallPrompt = null;
|
|
3212
|
+
|
|
3213
|
+
function setInstallPrompt(e) {
|
|
3214
|
+
deferredInstallPrompt = e;
|
|
3215
|
+
installBtn.hidden = !e;
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
window.addEventListener('beforeinstallprompt', (e) => {
|
|
3219
|
+
e.preventDefault();
|
|
3220
|
+
setInstallPrompt(e);
|
|
3221
|
+
});
|
|
3222
|
+
|
|
3223
|
+
window.addEventListener('appinstalled', () => setInstallPrompt(null));
|
|
3224
|
+
|
|
3225
|
+
// biome-ignore lint/correctness/noUnusedVariables: called from topbar markup
|
|
3226
|
+
async function promptInstall() {
|
|
3227
|
+
const e = deferredInstallPrompt;
|
|
3228
|
+
if (!e) return;
|
|
3229
|
+
setInstallPrompt(null);
|
|
3230
|
+
await e.prompt();
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3045
3233
|
// #endregion
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/public/index.html
CHANGED
|
@@ -85,6 +85,10 @@
|
|
|
85
85
|
<button class="topbar-btn" id="themeBtn" title="Toggle theme" onclick="toggleTheme()">
|
|
86
86
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" id="themeIcon"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
|
|
87
87
|
</button>
|
|
88
|
+
<button class="topbar-btn" id="installBtn" title="Install as desktop app" onclick="promptInstall()" hidden>
|
|
89
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
|
90
|
+
Install
|
|
91
|
+
</button>
|
|
88
92
|
<button class="topbar-btn" id="infoBtn" title="Help & About (?)" onclick="toggleHelpModal()">
|
|
89
93
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><circle cx="12" cy="17" r="0.5" fill="currentColor"/></svg>
|
|
90
94
|
<kbd>?</kbd>
|
|
@@ -95,9 +99,10 @@
|
|
|
95
99
|
</div>
|
|
96
100
|
|
|
97
101
|
<div class="modal-overlay" id="helpModal" onclick="if(event.target===this)toggleHelpModal()">
|
|
98
|
-
<div class="modal-box">
|
|
102
|
+
<div class="modal-box modal-help">
|
|
99
103
|
<div class="modal-header">
|
|
100
104
|
<div class="modal-title">Cost Dashboard</div>
|
|
105
|
+
<button class="modal-close" aria-label="Close dialog" onclick="toggleHelpModal()">✕</button>
|
|
101
106
|
</div>
|
|
102
107
|
<div class="modal-body">
|
|
103
108
|
<div class="modal-section">
|
|
@@ -106,36 +111,18 @@
|
|
|
106
111
|
</div>
|
|
107
112
|
<hr class="modal-divider">
|
|
108
113
|
<h4 class="shortcut-section">Keyboard Shortcuts</h4>
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
</div>
|
|
119
|
-
<div>
|
|
120
|
-
<h4 class="shortcut-section">Table</h4>
|
|
121
|
-
<table class="shortcut-table">
|
|
122
|
-
<tr><td><kbd>J</kbd> / <kbd>↓</kbd></td><td>Next row</td></tr>
|
|
123
|
-
<tr><td><kbd>K</kbd> / <kbd>↑</kbd></td><td>Previous row</td></tr>
|
|
124
|
-
<tr><td><kbd>Enter</kbd></td><td>Open selected row</td></tr>
|
|
125
|
-
</table>
|
|
126
|
-
</div>
|
|
127
|
-
<div>
|
|
128
|
-
<h4 class="shortcut-section">Actions</h4>
|
|
129
|
-
<table class="shortcut-table">
|
|
130
|
-
<tr><td><kbd>R</kbd></td><td>Refresh data</td></tr>
|
|
131
|
-
<tr><td><kbd>T</kbd></td><td>Toggle theme</td></tr>
|
|
132
|
-
<tr><td><kbd>?</kbd></td><td>Show this help</td></tr>
|
|
133
|
-
<tr><td><kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>P</kbd></td><td>Switch project (hub only)</td></tr>
|
|
134
|
-
</table>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
114
|
+
<dl class="shortcuts" id="helpShortcuts"></dl>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<div class="modal-overlay" id="projectPickerModal" onclick="if(event.target===this)closeProjectPicker()">
|
|
120
|
+
<div class="modal-box picker-box">
|
|
121
|
+
<div class="modal-header">
|
|
122
|
+
<div class="modal-title">Switch project</div>
|
|
137
123
|
</div>
|
|
138
|
-
<
|
|
124
|
+
<input class="picker-input" id="projectPickerInput" type="text" placeholder="Filter projects..." autocomplete="off" spellcheck="false">
|
|
125
|
+
<div class="picker-list" id="projectPickerList"></div>
|
|
139
126
|
</div>
|
|
140
127
|
</div>
|
|
141
128
|
|
package/public/manifest.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
+
"id": "/",
|
|
2
3
|
"name": "Claude Code Cost",
|
|
3
4
|
"short_name": "CC Cost",
|
|
4
5
|
"description": "Cost dashboard for Claude Code usage",
|
|
5
6
|
"start_url": "/",
|
|
7
|
+
"scope": "/",
|
|
6
8
|
"display": "standalone",
|
|
7
9
|
"theme_color": "#101114",
|
|
8
10
|
"background_color": "#101114",
|
|
9
11
|
"icons": [
|
|
10
12
|
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
|
|
11
13
|
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" },
|
|
14
|
+
{ "src": "/icons/icon-512-maskable.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" },
|
|
12
15
|
{ "src": "/icons/icon-svg.svg", "sizes": "any", "type": "image/svg+xml" }
|
|
16
|
+
],
|
|
17
|
+
"shortcuts": [
|
|
18
|
+
{ "name": "Overview", "url": "/?view=overview" },
|
|
19
|
+
{ "name": "Insights", "url": "/?view=insights" }
|
|
13
20
|
]
|
|
14
21
|
}
|
package/public/style.css
CHANGED
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
padding: 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
[hidden] {
|
|
46
|
+
/* biome-ignore lint/complexity/noImportantStyles: must beat every component's own display */
|
|
47
|
+
display: none !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
body {
|
|
46
51
|
font-family: var(--mono);
|
|
47
52
|
font-size: 13px;
|
|
@@ -137,10 +142,6 @@ body {
|
|
|
137
142
|
max-width: 220px;
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
.scope-chip[hidden] {
|
|
141
|
-
display: none;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
145
|
.scope-chip > span {
|
|
145
146
|
overflow: hidden;
|
|
146
147
|
text-overflow: ellipsis;
|
|
@@ -1379,21 +1380,16 @@ body.light .rb-window {
|
|
|
1379
1380
|
}
|
|
1380
1381
|
|
|
1381
1382
|
.modal-close {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
border: 1px solid var(--border);
|
|
1387
|
-
border-radius: 6px;
|
|
1388
|
-
color: var(--text-secondary);
|
|
1383
|
+
padding: 2px;
|
|
1384
|
+
background: none;
|
|
1385
|
+
border: none;
|
|
1386
|
+
color: var(--text-muted);
|
|
1389
1387
|
cursor: pointer;
|
|
1390
|
-
font-
|
|
1391
|
-
|
|
1392
|
-
text-transform: uppercase;
|
|
1388
|
+
font-size: 16px;
|
|
1389
|
+
line-height: 1;
|
|
1393
1390
|
}
|
|
1394
1391
|
|
|
1395
1392
|
.modal-close:hover {
|
|
1396
|
-
background: var(--bg-hover);
|
|
1397
1393
|
color: var(--text-primary);
|
|
1398
1394
|
}
|
|
1399
1395
|
|
|
@@ -1408,18 +1404,93 @@ body.light .rb-window {
|
|
|
1408
1404
|
margin-bottom: 0;
|
|
1409
1405
|
}
|
|
1410
1406
|
|
|
1407
|
+
/* The paired shortcut columns need room the 500px default cannot give. */
|
|
1408
|
+
.modal-box.modal-help {
|
|
1409
|
+
max-width: 960px;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
.picker-box {
|
|
1413
|
+
max-width: 560px;
|
|
1414
|
+
padding: 16px;
|
|
1415
|
+
display: flex;
|
|
1416
|
+
flex-direction: column;
|
|
1417
|
+
gap: 10px;
|
|
1418
|
+
overflow: hidden;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
.picker-input {
|
|
1422
|
+
width: 100%;
|
|
1423
|
+
padding: 8px 10px;
|
|
1424
|
+
background: var(--bg-deep);
|
|
1425
|
+
border: 1px solid var(--border);
|
|
1426
|
+
border-radius: 6px;
|
|
1427
|
+
color: var(--text-primary);
|
|
1428
|
+
font-family: inherit;
|
|
1429
|
+
font-size: 13px;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
.picker-input:focus {
|
|
1433
|
+
outline: none;
|
|
1434
|
+
border-color: var(--accent);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
.picker-list {
|
|
1438
|
+
max-height: 50vh;
|
|
1439
|
+
overflow-y: auto;
|
|
1440
|
+
display: flex;
|
|
1441
|
+
flex-direction: column;
|
|
1442
|
+
gap: 2px;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
.picker-row {
|
|
1446
|
+
display: flex;
|
|
1447
|
+
align-items: center;
|
|
1448
|
+
justify-content: space-between;
|
|
1449
|
+
gap: 12px;
|
|
1450
|
+
width: 100%;
|
|
1451
|
+
padding: 7px 10px;
|
|
1452
|
+
background: none;
|
|
1453
|
+
border: 1px solid transparent;
|
|
1454
|
+
border-radius: 6px;
|
|
1455
|
+
color: var(--text-primary);
|
|
1456
|
+
font-family: inherit;
|
|
1457
|
+
font-size: 13px;
|
|
1458
|
+
text-align: left;
|
|
1459
|
+
cursor: pointer;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
.picker-row:hover {
|
|
1463
|
+
background: var(--bg-hover);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
.picker-row.selected {
|
|
1467
|
+
background: var(--bg-hover);
|
|
1468
|
+
border-color: var(--accent);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
.picker-name {
|
|
1472
|
+
overflow: hidden;
|
|
1473
|
+
text-overflow: ellipsis;
|
|
1474
|
+
white-space: nowrap;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
.picker-cost {
|
|
1478
|
+
color: var(--text-secondary);
|
|
1479
|
+
white-space: nowrap;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
.picker-empty {
|
|
1483
|
+
padding: 12px 10px;
|
|
1484
|
+
color: var(--text-muted);
|
|
1485
|
+
font-size: 12px;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1411
1488
|
.modal-divider {
|
|
1412
1489
|
border: none;
|
|
1413
1490
|
border-top: 1px solid var(--border);
|
|
1414
1491
|
margin: 16px 0;
|
|
1415
1492
|
}
|
|
1416
1493
|
|
|
1417
|
-
.shortcut-grid {
|
|
1418
|
-
display: grid;
|
|
1419
|
-
grid-template-columns: 1fr 1fr;
|
|
1420
|
-
gap: 20px;
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
1494
|
.shortcut-section {
|
|
1424
1495
|
margin: 0 0 8px 0;
|
|
1425
1496
|
color: var(--text-primary);
|
|
@@ -1427,22 +1498,100 @@ body.light .rb-window {
|
|
|
1427
1498
|
font-weight: 600;
|
|
1428
1499
|
}
|
|
1429
1500
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1501
|
+
/* One shared grid for both halves (key | label | spacer | key | label): each key
|
|
1502
|
+
gutter is sized by its column's widest combo, and left/right rows share row
|
|
1503
|
+
tracks, so paired groups line up — a shorter group just leaves empty rows.
|
|
1504
|
+
Cells opt into a half via sc-l / sc-r; the markup is generated from
|
|
1505
|
+
SHORTCUT_PAIRS in app.js. */
|
|
1506
|
+
.shortcuts {
|
|
1507
|
+
margin: 0;
|
|
1508
|
+
display: grid;
|
|
1509
|
+
grid-template-columns: max-content 1fr 28px max-content 1fr;
|
|
1510
|
+
column-gap: 14px;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
.shortcuts dt.sc-l {
|
|
1514
|
+
grid-column: 1;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
.shortcuts dd.sc-l {
|
|
1518
|
+
grid-column: 2;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
.shortcuts dt.sc-r {
|
|
1522
|
+
grid-column: 4;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
.shortcuts dd.sc-r {
|
|
1526
|
+
grid-column: 5;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
.shortcuts .sc-group.sc-l {
|
|
1530
|
+
grid-column: 1 / 3;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
.shortcuts .sc-group.sc-r {
|
|
1534
|
+
grid-column: 4 / 6;
|
|
1433
1535
|
}
|
|
1434
1536
|
|
|
1435
|
-
.
|
|
1537
|
+
.shortcuts dt {
|
|
1538
|
+
margin: 0;
|
|
1539
|
+
display: flex;
|
|
1540
|
+
align-items: center;
|
|
1541
|
+
align-self: center;
|
|
1542
|
+
gap: 4px;
|
|
1436
1543
|
padding: 3px 0;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
.shortcuts dd {
|
|
1547
|
+
margin: 0;
|
|
1548
|
+
font-size: 13px;
|
|
1437
1549
|
color: var(--text-secondary);
|
|
1550
|
+
align-self: center;
|
|
1551
|
+
padding: 3px 0;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
/* Section headings carry the column: full-width rule + primary ink, so the eye
|
|
1555
|
+
finds the group before it reads any single row. */
|
|
1556
|
+
.shortcuts .sc-group {
|
|
1557
|
+
padding: 18px 0 6px;
|
|
1558
|
+
margin-bottom: 6px;
|
|
1559
|
+
font-size: 11px;
|
|
1560
|
+
font-weight: 700;
|
|
1561
|
+
letter-spacing: 0.16em;
|
|
1562
|
+
text-transform: uppercase;
|
|
1563
|
+
color: var(--text-primary);
|
|
1564
|
+
border-bottom: 1px solid var(--border);
|
|
1438
1565
|
}
|
|
1439
1566
|
|
|
1440
|
-
.
|
|
1441
|
-
|
|
1567
|
+
.shortcuts .sc-group.sc-first {
|
|
1568
|
+
padding-top: 2px;
|
|
1442
1569
|
}
|
|
1443
1570
|
|
|
1444
|
-
|
|
1571
|
+
/* keycap chips: thicker bottom border reads as a key */
|
|
1572
|
+
.shortcuts kbd {
|
|
1573
|
+
display: inline-flex;
|
|
1574
|
+
align-items: center;
|
|
1575
|
+
justify-content: center;
|
|
1576
|
+
min-width: 22px;
|
|
1577
|
+
height: 22px;
|
|
1578
|
+
padding: 0 6px;
|
|
1579
|
+
box-sizing: border-box;
|
|
1445
1580
|
color: var(--text-primary);
|
|
1581
|
+
border-bottom-width: 2px;
|
|
1582
|
+
border-radius: 5px;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
.shortcuts .sc-plus,
|
|
1586
|
+
.shortcuts .sc-or {
|
|
1587
|
+
color: var(--text-muted);
|
|
1588
|
+
font-size: 11px;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/* Hub keys do nothing outside Claude Code Hub, so the standalone app hides that
|
|
1592
|
+
whole column rather than listing keys that no-op. */
|
|
1593
|
+
.shortcuts.sc-standalone .sc-hub {
|
|
1594
|
+
display: none;
|
|
1446
1595
|
}
|
|
1447
1596
|
|
|
1448
1597
|
kbd {
|
package/server.js
CHANGED
|
@@ -21,17 +21,21 @@ function getArg(name) {
|
|
|
21
21
|
|
|
22
22
|
const PORT = getArg('port') || process.env.PORT || 3543;
|
|
23
23
|
const claudeDirArg = getArg('dir') || process.env.CLAUDE_CONFIG_DIR || process.env.CLAUDE_DIR;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
: path.join(os.homedir(), '.claude');
|
|
24
|
+
const DEFAULT_CLAUDE_DIR = path.join(os.homedir(), '.claude');
|
|
25
|
+
const CLAUDE_DIR = claudeDirArg ? claudeDirArg.replace(/^~/, os.homedir()) : DEFAULT_CLAUDE_DIR;
|
|
27
26
|
|
|
28
27
|
const PROJECTS_DIR = path.join(CLAUDE_DIR, 'projects');
|
|
29
|
-
|
|
28
|
+
// XDG-style location some builds used for the default profile only. A custom
|
|
29
|
+
// CLAUDE_CONFIG_DIR holds everything itself, so scanning it there would leak
|
|
30
|
+
// the home profile's sessions into the custom one.
|
|
31
|
+
const ALT_PROJECTS_DIR = path.resolve(CLAUDE_DIR) === path.resolve(DEFAULT_CLAUDE_DIR)
|
|
32
|
+
? path.join(os.homedir(), '.config', 'claude', 'projects')
|
|
33
|
+
: null;
|
|
30
34
|
|
|
31
35
|
function getProjectsDirs() {
|
|
32
36
|
const dirs = [];
|
|
33
37
|
if (fs.existsSync(PROJECTS_DIR)) dirs.push(PROJECTS_DIR);
|
|
34
|
-
if (fs.existsSync(ALT_PROJECTS_DIR)) dirs.push(ALT_PROJECTS_DIR);
|
|
38
|
+
if (ALT_PROJECTS_DIR && fs.existsSync(ALT_PROJECTS_DIR)) dirs.push(ALT_PROJECTS_DIR);
|
|
35
39
|
return dirs;
|
|
36
40
|
}
|
|
37
41
|
|