@caius_kong/ccusage-dashboard 0.2.16 → 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 +6 -6
- package/lib/server.py +7 -45
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -37,9 +37,9 @@ to what ccusage itself reports** — the source you already trust.
|
|
|
37
37
|
npx @caius_kong/ccusage-dashboard
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
That's it. npx downloads the package
|
|
41
|
-
starts a local server on `http://127.0.0.1:8799`,
|
|
42
|
-
for you to open.
|
|
40
|
+
That's it. npx downloads the package, uses the `ccusage` already on your machine
|
|
41
|
+
(or fetches the latest via `npx`), starts a local server on `http://127.0.0.1:8799`,
|
|
42
|
+
and prints the dashboard URL for you to open.
|
|
43
43
|
|
|
44
44
|
> Requirements: **Node.js** (for the launcher) and **Python 3.8+** (for the server).
|
|
45
45
|
> On macOS: `brew install python3`. No other installs, no build step, no config.
|
|
@@ -95,11 +95,11 @@ Browser (index.html)
|
|
|
95
95
|
server.py (Python stdlib, zero deps)
|
|
96
96
|
│ spawns: ccusage daily/monthly/weekly ... --json --offline
|
|
97
97
|
▼
|
|
98
|
-
ccusage (
|
|
98
|
+
ccusage (your installed version — the real cost engine)
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
- `lib/server.py` — Python stdlib HTTP server. Resolves
|
|
102
|
-
(
|
|
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.
|
|
103
103
|
- `lib/index.html` — single-file dashboard. No build step, no CDN.
|
|
104
104
|
- `bin/ccusage-ui.js` — Node launcher (finds python3, starts server, prints URL).
|
|
105
105
|
|
package/lib/server.py
CHANGED
|
@@ -43,63 +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 _npx_cached_cli() -> str | None:
|
|
55
|
-
for base in ("npm", "bun"):
|
|
56
|
-
roots = []
|
|
57
|
-
if base == "npm":
|
|
58
|
-
target = Path.home() / ".npm/_npx"
|
|
59
|
-
if target.is_dir():
|
|
60
|
-
roots.extend(p for p in target.glob("*/node_modules/ccusage/src/cli.js"))
|
|
61
|
-
# also newer npm layout
|
|
62
|
-
roots.extend((Path.home() / ".npm/_npx").glob("*/node_modules/ccusage/src/cli.js"))
|
|
63
|
-
else:
|
|
64
|
-
target = Path.home() / ".bun/install/cache"
|
|
65
|
-
if target.is_dir():
|
|
66
|
-
roots.extend(p for p in target.glob("ccusage*/src/cli.js"))
|
|
67
|
-
# prefer highest semver-ish (sort by version suffix descending)
|
|
68
|
-
def _ver(p: Path) -> tuple:
|
|
69
|
-
s = p.as_posix()
|
|
70
|
-
m = re.search(r"ccusage@?(\d+)\.(\d+)\.(\d+)", s)
|
|
71
|
-
return tuple(map(int, m.groups())) if m else (0, 0, 0)
|
|
72
|
-
best = max(roots, key=_ver, default=None)
|
|
73
|
-
if best:
|
|
74
|
-
return str(best)
|
|
75
|
-
return None
|
|
76
|
-
|
|
77
54
|
explicit = _CCUSAGE_PATH_OVERRIDE
|
|
78
55
|
if explicit:
|
|
79
56
|
return [explicit]
|
|
80
57
|
p = shutil.which("ccusage")
|
|
81
58
|
if p:
|
|
82
59
|
return [p]
|
|
83
|
-
|
|
84
|
-
for parent in APP_DIR.parents:
|
|
85
|
-
bundled = parent / "node_modules" / "ccusage" / "src" / "cli.js"
|
|
86
|
-
if bundled.exists():
|
|
87
|
-
return [_node(), str(bundled)]
|
|
88
|
-
cli = _npx_cached_cli()
|
|
89
|
-
if cli:
|
|
90
|
-
return [_node(), str(cli)]
|
|
91
|
-
return ["npx", "--yes", "ccusage@latest"]
|
|
60
|
+
return ["npx", "--yes", "ccusage"]
|
|
92
61
|
|
|
93
62
|
|
|
94
63
|
_CCUSAGE_PATH_OVERRIDE: str | None = None
|
|
95
64
|
|
|
96
|
-
|
|
97
|
-
def _node() -> str:
|
|
98
|
-
import shutil as _s
|
|
99
|
-
|
|
100
|
-
n = _s.which("node") or "node"
|
|
101
|
-
return n
|
|
102
|
-
|
|
103
65
|
BUDGET = 300.0 # monthly cap in USD (override via --budget or CCUSAGE_BUDGET)
|
|
104
66
|
TTL = {"/api/today": 15, "/api/week": 60, "/api/month": 60, "/api/range": 120, "/api/trend": 120, "/api/sessions": 60}
|
|
105
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",
|
|
@@ -32,9 +32,7 @@
|
|
|
32
32
|
"url": "https://github.com/caius-kong/ccusage-dashboard"
|
|
33
33
|
},
|
|
34
34
|
"author": "Caius Kong",
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"ccusage": "^20.0.20"
|
|
37
|
-
},
|
|
35
|
+
"dependencies": {},
|
|
38
36
|
"publishConfig": {
|
|
39
37
|
"access": "public"
|
|
40
38
|
}
|