@caius_kong/ccusage-dashboard 0.2.17 → 0.2.18
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 +2 -3
- package/lib/server.py +7 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,9 +98,8 @@ server.py (Python stdlib, zero deps)
|
|
|
98
98
|
ccusage (your installed version — the real cost engine)
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
- `lib/server.py` — Python stdlib HTTP server. Resolves
|
|
102
|
-
(PATH →
|
|
103
|
-
always matches the system's `ccusage`; warms caches on boot (~3s), then serves instant responses.
|
|
101
|
+
- `lib/server.py` — Python stdlib HTTP server. Resolves ccusage the same way you run
|
|
102
|
+
it (PATH → `npx ccusage`), so it always uses the system's version; warms caches on boot (~3s), then serves instant responses.
|
|
104
103
|
- `lib/index.html` — single-file dashboard. No build step, no CDN.
|
|
105
104
|
- `bin/ccusage-ui.js` — Node launcher (finds python3, starts server, prints URL).
|
|
106
105
|
|
package/lib/server.py
CHANGED
|
@@ -43,67 +43,25 @@ _lock = threading.Lock()
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
def resolve_ccusage() -> list[str]:
|
|
46
|
-
"""Resolve
|
|
46
|
+
"""Resolve the ccusage CLI the system itself uses, and only that.
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
Hard constraint: every number comes from the ccusage CLI, and it must be
|
|
49
|
+
the same one the user runs (`npx ccusage ...`). So we look for, in order,
|
|
50
|
+
an explicit --ccusage-path, a `ccusage` on PATH, then `npx --yes ccusage`.
|
|
51
|
+
No cache-scanning and no version-picking: the version is whatever the
|
|
52
|
+
system resolves, never a stale copy we chose ourselves.
|
|
53
53
|
"""
|
|
54
|
-
def _pkg_version(cli: Path) -> tuple | None:
|
|
55
|
-
"""Real version of the ccusage package owning `cli`.
|
|
56
|
-
|
|
57
|
-
Read it from package.json, NEVER from the directory path: npm's npx
|
|
58
|
-
cache uses opaque hash dirs (no "ccusage@x.y.z"), so path-regex would
|
|
59
|
-
degrade every candidate to (0, 0, 0) and make "pick highest" a silent
|
|
60
|
-
no-op that picks an arbitrary (often stale) version.
|
|
61
|
-
"""
|
|
62
|
-
pj = cli.parent.parent / "package.json"
|
|
63
|
-
try:
|
|
64
|
-
m = re.search(r'"version"\s*:\s*"(\d+)\.(\d+)\.(\d+)', pj.read_text())
|
|
65
|
-
except OSError:
|
|
66
|
-
return None
|
|
67
|
-
return tuple(map(int, m.groups())) if m else None
|
|
68
|
-
|
|
69
|
-
def _npx_cached_cli() -> str | None:
|
|
70
|
-
"""Highest-versioned ccusage in the npx/bun caches, or None.
|
|
71
|
-
|
|
72
|
-
Only candidates whose real version is readable are considered, so we
|
|
73
|
-
never fall back to an arbitrary pick. Returning None lets the caller
|
|
74
|
-
defer to `npx ccusage@latest`, which resolves the system's version.
|
|
75
|
-
"""
|
|
76
|
-
roots = []
|
|
77
|
-
npm_target = Path.home() / ".npm/_npx"
|
|
78
|
-
if npm_target.is_dir():
|
|
79
|
-
roots.extend(npm_target.glob("*/node_modules/ccusage/src/cli.js"))
|
|
80
|
-
bun_target = Path.home() / ".bun/install/cache"
|
|
81
|
-
if bun_target.is_dir():
|
|
82
|
-
roots.extend(bun_target.glob("ccusage*/src/cli.js"))
|
|
83
|
-
scored = [(v, p) for p in roots if (v := _pkg_version(p)) is not None]
|
|
84
|
-
return str(max(scored)[1]) if scored else None
|
|
85
|
-
|
|
86
54
|
explicit = _CCUSAGE_PATH_OVERRIDE
|
|
87
55
|
if explicit:
|
|
88
56
|
return [explicit]
|
|
89
57
|
p = shutil.which("ccusage")
|
|
90
58
|
if p:
|
|
91
59
|
return [p]
|
|
92
|
-
|
|
93
|
-
if cli:
|
|
94
|
-
return [_node(), str(cli)]
|
|
95
|
-
return ["npx", "--yes", "ccusage@latest"]
|
|
60
|
+
return ["npx", "--yes", "ccusage"]
|
|
96
61
|
|
|
97
62
|
|
|
98
63
|
_CCUSAGE_PATH_OVERRIDE: str | None = None
|
|
99
64
|
|
|
100
|
-
|
|
101
|
-
def _node() -> str:
|
|
102
|
-
import shutil as _s
|
|
103
|
-
|
|
104
|
-
n = _s.which("node") or "node"
|
|
105
|
-
return n
|
|
106
|
-
|
|
107
65
|
BUDGET = 300.0 # monthly cap in USD (override via --budget or CCUSAGE_BUDGET)
|
|
108
66
|
TTL = {"/api/today": 15, "/api/week": 60, "/api/month": 60, "/api/range": 120, "/api/trend": 120, "/api/sessions": 60}
|
|
109
67
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caius_kong/ccusage-dashboard",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "One-command local dashboard for ccusage: today/week/month/custom cost by model, 30-day trend, monthly budget alert. Numbers straight from ccusage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|