@caius_kong/ccusage-dashboard 0.2.7 → 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/index.html CHANGED
@@ -109,8 +109,9 @@
109
109
  <div class="panel"><h2>Models <span class="tot" id="modelSum"></span></h2><div id="modelList"><div class="empty">loading…</div></div></div>
110
110
 
111
111
  <div class="panel" id="sessionsPanel">
112
- <h2>Sessions <span class="tot" id="sessSum"></span>
112
+ <h2>Sessions
113
113
  <span class="pill" id="sessRange"></span>
114
+ <span class="tot" id="sessSum" style="margin-left:8px"></span>
114
115
  </h2>
115
116
  <div id="sessionsList"><div class="empty">loading…</div></div>
116
117
  </div>
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 blocking warm-up (first requests may be slow)")
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 (first load will be instant after this)…", flush=True)
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
- print(f"ccusage-ui → http://{args.host}:{args.port} (monthly budget ${BUDGET:g}, Ctrl+C to stop)")
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
- import webbrowser
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.7",
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",