@caius_kong/ccusage-dashboard 0.2.8 → 0.2.9
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/server.py +35 -10
- package/package.json +1 -1
package/lib/server.py
CHANGED
|
@@ -542,13 +542,13 @@ def main() -> None:
|
|
|
542
542
|
parser.add_argument("--host", default="127.0.0.1")
|
|
543
543
|
parser.add_argument("--budget", type=float, default=None, help="monthly budget cap in USD (default 300)")
|
|
544
544
|
parser.add_argument("--ccusage-path", default=None, help="explicit path to a ccusage binary or src/cli.js")
|
|
545
|
-
parser.add_argument("--no-warm", action="store_true", help="skip
|
|
545
|
+
parser.add_argument("--no-warm", action="store_true", help="skip background warm-up (first requests may be slow)")
|
|
546
546
|
parser.add_argument("--open", action="store_true", help="open browser after start")
|
|
547
547
|
args = parser.parse_args()
|
|
548
548
|
|
|
549
549
|
BUDGET = args.budget if args.budget is not None else float(os_env_budget() or 300.0)
|
|
550
550
|
_CCUSAGE_PATH_OVERRIDE = args.ccusage_path
|
|
551
|
-
print(f"using ccusage → {' '.join(resolve_ccusage())}")
|
|
551
|
+
print(f"using ccusage → {' '.join(resolve_ccusage())}", flush=True)
|
|
552
552
|
|
|
553
553
|
def warm_one(fn):
|
|
554
554
|
fn()
|
|
@@ -566,22 +566,47 @@ def main() -> None:
|
|
|
566
566
|
for t in threads:
|
|
567
567
|
t.join()
|
|
568
568
|
|
|
569
|
+
# warm the caches in the background so the server is reachable immediately;
|
|
570
|
+
# the first page load will wait for warm-up to finish via the TTL cache lock.
|
|
569
571
|
if not args.no_warm:
|
|
570
|
-
print("warming ccusage caches
|
|
571
|
-
warm()
|
|
572
|
-
print("warm-up complete.")
|
|
572
|
+
print("warming ccusage caches in background…", flush=True)
|
|
573
|
+
threading.Thread(target=warm, daemon=True).start()
|
|
573
574
|
|
|
574
575
|
httpd = ThreadingHTTPServer((args.host, args.port), Handler)
|
|
575
|
-
|
|
576
|
+
url = f"http://{args.host}:{args.port}"
|
|
577
|
+
print(f"ccusage-ui → {url} (monthly budget ${BUDGET:g}, Ctrl+C to stop)", flush=True)
|
|
576
578
|
if args.open:
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
webbrowser.open(f"http://{args.host}:{args.port}")
|
|
579
|
+
_open_browser(url)
|
|
580
580
|
|
|
581
581
|
try:
|
|
582
582
|
httpd.serve_forever()
|
|
583
583
|
except KeyboardInterrupt:
|
|
584
|
-
print("\nbye")
|
|
584
|
+
print("\nbye", flush=True)
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def _open_browser(url: str) -> None:
|
|
588
|
+
"""Open the dashboard in the default browser. Prefers the OS-native opener
|
|
589
|
+
(open / xdg-open / start) and logs success/failure so it is verifiable.
|
|
590
|
+
"""
|
|
591
|
+
import subprocess
|
|
592
|
+
import sys
|
|
593
|
+
|
|
594
|
+
if sys.platform == "darwin":
|
|
595
|
+
cmd = ["open", url]
|
|
596
|
+
elif sys.platform.startswith("win"):
|
|
597
|
+
cmd = ["cmd", "/c", "start", "", url]
|
|
598
|
+
else:
|
|
599
|
+
cmd = ["xdg-open", url]
|
|
600
|
+
try:
|
|
601
|
+
r = subprocess.run(cmd, timeout=5, capture_output=True, text=True)
|
|
602
|
+
if r.returncode == 0:
|
|
603
|
+
print(f"browser opened → {url}", flush=True)
|
|
604
|
+
else:
|
|
605
|
+
print(f"browser open failed (rc={r.returncode}): {r.stderr.strip()[:200]}", flush=True)
|
|
606
|
+
except FileNotFoundError:
|
|
607
|
+
print(f"no system opener found; open {url} manually", flush=True)
|
|
608
|
+
except Exception as e: # noqa: BLE001
|
|
609
|
+
print(f"browser open error: {e}", flush=True)
|
|
585
610
|
|
|
586
611
|
|
|
587
612
|
def os_env_budget() -> str:
|
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.9",
|
|
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",
|