@caius_kong/ccusage-dashboard 0.2.10 → 0.2.11

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 CHANGED
@@ -38,7 +38,8 @@ npx @caius_kong/ccusage-dashboard
38
38
  ```
39
39
 
40
40
  That's it. npx downloads the package (including its own `ccusage` dependency),
41
- starts a local server on `http://127.0.0.1:8799`, and opens your browser.
41
+ starts a local server on `http://127.0.0.1:8799`, and prints the dashboard URL
42
+ for you to open.
42
43
 
43
44
  > Requirements: **Node.js** (for the launcher) and **Python 3.8+** (for the server).
44
45
  > On macOS: `brew install python3`. No other installs, no build step, no config.
@@ -48,10 +49,12 @@ starts a local server on `http://127.0.0.1:8799`, and opens your browser.
48
49
  ```bash
49
50
  npx @caius_kong/ccusage-dashboard --port 9000 # change port
50
51
  npx @caius_kong/ccusage-dashboard --budget 500 # monthly budget cap (default $300)
51
- npx @caius_kong/ccusage-dashboard --no-warm # skip 3s startup warm-up
52
- CCUSAGE_UI_NO_OPEN=1 npx @caius_kong/ccusage-dashboard # don't auto-open browser
52
+ npx @caius_kong/ccusage-dashboard --no-warm # skip background warm-up
53
53
  ```
54
54
 
55
+ Once started, the launcher prints the dashboard URL — open it in your browser
56
+ (no browser is auto-launched).
57
+
55
58
  ## What it shows
56
59
 
57
60
  | | |
@@ -80,7 +83,7 @@ ccusage (bundled dependency — the real cost engine)
80
83
  - `lib/server.py` — Python stdlib HTTP server. Resolves a local ccusage
81
84
  (bundled dep → PATH → npx cache), warms caches on boot (~3s), then serves instant responses.
82
85
  - `lib/index.html` — single-file dashboard. No build step, no CDN.
83
- - `bin/ccusage-ui.js` — Node launcher (finds python3, starts server, opens browser).
86
+ - `bin/ccusage-ui.js` — Node launcher (finds python3, starts server, prints URL).
84
87
 
85
88
  ## Local development
86
89
 
package/bin/ccusage-ui.js CHANGED
@@ -6,10 +6,8 @@
6
6
  * the local python3, forwarding any CLI args. The server itself shells out to
7
7
  * ccusage for all numbers, so the dashboard always matches ccusage.
8
8
  *
9
- * Startup UX:
10
- * - the server tries to auto-open the default browser (best effort)
11
- * - regardless of that, this launcher prints a clear URL banner once the
12
- * server is up, so the user can always click/copy it manually.
9
+ * Startup UX: once the server is up, a clear URL banner is printed so the
10
+ * user can click/copy it to open the dashboard. No background magic.
13
11
  */
14
12
  'use strict';
15
13
 
@@ -58,9 +56,6 @@ const port = parseInt(argValue('--port', '8799'), 10);
58
56
  const url = `http://${host}:${port}`;
59
57
 
60
58
  const args = rawArgs.slice();
61
- if (!args.includes('--open') && !process.env.CCUSAGE_UI_NO_OPEN) {
62
- args.push('--open'); // default: try to auto-open the browser (best effort)
63
- }
64
59
 
65
60
  const child = spawn(py, [serverPy, ...args], { stdio: 'inherit', env: { ...process.env } });
66
61
 
package/lib/server.py CHANGED
@@ -12,7 +12,7 @@ Because all numbers come from ccusage itself, the figures always match what
12
12
  to maintain, no third-party packages — only the Python standard library.
13
13
 
14
14
  Usage:
15
- python3 server.py [--port 8799] [--budget 300] [--open]
15
+ python3 server.py [--port 8799] [--budget 300]
16
16
  """
17
17
  from __future__ import annotations
18
18
 
@@ -543,7 +543,6 @@ def main() -> None:
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
545
  parser.add_argument("--no-warm", action="store_true", help="skip background warm-up (first requests may be slow)")
546
- parser.add_argument("--open", action="store_true", help="open browser after start")
547
546
  args = parser.parse_args()
548
547
 
549
548
  BUDGET = args.budget if args.budget is not None else float(os_env_budget() or 300.0)
@@ -575,10 +574,6 @@ def main() -> None:
575
574
  httpd = ThreadingHTTPServer((args.host, args.port), Handler)
576
575
  url = f"http://{args.host}:{args.port}"
577
576
  print(f"ccusage-ui → {url} (monthly budget ${BUDGET:g}, Ctrl+C to stop)", flush=True)
578
- if args.open:
579
- _open_browser(url)
580
- else:
581
- print(f"dashboard ready at {url} — open it in your browser", flush=True)
582
577
 
583
578
  try:
584
579
  httpd.serve_forever()
@@ -586,46 +581,6 @@ def main() -> None:
586
581
  print("\nbye", flush=True)
587
582
 
588
583
 
589
- def _open_browser(url: str) -> None:
590
- """Open the dashboard in a browser. Tries, in order:
591
- 1. $BROWSER (e.g. 'Google Chrome', 'Safari', 'firefox')
592
- 2. the OS default opener (open / xdg-open / start)
593
- 3. prints the URL as a fallback so the user can open it manually.
594
- Every attempt logs its outcome so auto-open is verifiable.
595
- """
596
- import os
597
- import subprocess
598
- import sys
599
-
600
- browser = os.environ.get("BROWSER", "").strip()
601
- attempts = []
602
- if sys.platform == "darwin":
603
- if browser:
604
- attempts.append(["open", "-a", browser, url])
605
- attempts.append(["open", url])
606
- elif sys.platform.startswith("win"):
607
- if browser:
608
- attempts.append(["cmd", "/c", "start", "", "chrome", url])
609
- attempts.append(["cmd", "/c", "start", "", url])
610
- else:
611
- if browser:
612
- attempts.append([browser, url])
613
- attempts.append(["xdg-open", url])
614
-
615
- for cmd in attempts:
616
- try:
617
- r = subprocess.run(cmd, timeout=5, capture_output=True, text=True)
618
- if r.returncode == 0:
619
- print(f"browser opened → {url} ({' '.join(cmd[:2])})", flush=True)
620
- return
621
- print(f"browser attempt failed (rc={r.returncode}): {' '.join(cmd[:2])}", flush=True)
622
- except FileNotFoundError:
623
- print(f"opener not found: {' '.join(cmd[:2])}", flush=True)
624
- except Exception as e: # noqa: BLE001
625
- print(f"browser open error: {e}", flush=True)
626
- print(f"could not auto-open a browser — open it manually: {url}", flush=True)
627
-
628
-
629
584
  def os_env_budget() -> str:
630
585
  import os
631
586
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caius_kong/ccusage-dashboard",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
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",