@hivey/cli 0.9.53 → 0.9.54

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hivey/cli",
3
- "version": "0.9.53",
3
+ "version": "0.9.54",
4
4
  "description": "All your AI swarms, one terminal: a workspace and lead agent for teams of Claude Code and Codex agents",
5
5
  "keywords": [
6
6
  "hivey",
@@ -130,6 +130,10 @@ hivey agent-map schedule install [--at 06:30] [--model haiku] # | remove | sta
130
130
  People chatting with agents (Claude Code, Codex, Grok in a terminal; snapshot `interactive`, with one
131
131
  entry per session) go to **`agent-sessions.html`**: cost by agent and by day, the costliest sessions with
132
132
  their peak context (⚠️ over 300k tokens), length and first message, and tips to spend less.
133
+ - **Open:** `hivey agent-map open` (hivey menu → agent map) opens `http://127.0.0.1:8754/latest/agent-map.html`
134
+ (the map first; the stats page when there is no map yet). With no report yet it builds the pages without
135
+ a model in seconds, opens them, then draws the map in the background (`first-run.json` stops a second
136
+ click from starting another build). If a stats page fails, the logs and sessions pages still publish.
133
137
  - **Refresh:** `hivey agent-map open` serves the pages from 127.0.0.1 (`serve.py`, port 8754 or any
134
138
  free one, in `~/.hivey/agent-map/server.json`; stops after 2 h unused) so the navbar's ↻ Refresh
135
139
  button works: it runs `agent_map.py refresh` (new scan into the latest report's pages, no model, a few
@@ -19,6 +19,7 @@ import re
19
19
  import shutil
20
20
  import subprocess
21
21
  import sys
22
+ import time
22
23
  from pathlib import Path
23
24
 
24
25
  HOME = Path.home()
@@ -546,7 +547,7 @@ def nightly(scan, days: int, model: str, use_llm: bool) -> int:
546
547
  enhance.enhance_folder(folder, json.loads((folder / "snapshot.json").read_text()), job_state)
547
548
  except Exception as e: # the pages still work without hivey's layer
548
549
  log(folder, f"enhance failed: {e}")
549
- if ok:
550
+ if ok or (folder / "agent-logs.html").is_file(): # a failed stats page still publishes logs and sessions
550
551
  tmp = REPORTS / ".latest-new"
551
552
  if tmp.is_symlink() or tmp.exists():
552
553
  tmp.unlink()
@@ -586,9 +587,11 @@ def refresh(scan, days: int, model: str) -> int:
586
587
  # ---------------------------------------------------------------- open
587
588
 
588
589
  def latest_report() -> Path | None:
589
- if LATEST.exists() and (LATEST / "agent-stats.html").is_file():
590
+ def has_pages(p: Path) -> bool:
591
+ return (p / "agent-stats.html").is_file() or (p / "agent-logs.html").is_file()
592
+ if LATEST.exists() and has_pages(LATEST):
590
593
  return LATEST.resolve()
591
- folders = sorted(p for p in REPORTS.glob("*-*-*-*") if (p / "agent-stats.html").is_file()) if REPORTS.is_dir() else []
594
+ folders = sorted(p for p in REPORTS.glob("*-*-*-*") if has_pages(p)) if REPORTS.is_dir() else []
592
595
  return folders[-1] if folders else None
593
596
 
594
597
 
@@ -598,25 +601,61 @@ def notify(text: str) -> None:
598
601
  capture_output=True)
599
602
 
600
603
 
604
+ PAGES = ("agent-map.html", "agent-stats.html", "agent-logs.html", "agent-sessions.html") # the first one found opens
605
+ FIRST_RUN = STATE / "first-run.json"
606
+
607
+
608
+ def open_page(folder: Path) -> bool:
609
+ """Open the map (else the first page there is) from the local server, so Refresh works; the
610
+ navbar reaches the other pages. Without the server, the file itself."""
611
+ page = next((p for p in PAGES if (folder / p).is_file()), None)
612
+ if not page:
613
+ return False
614
+ import serve
615
+ port = serve.ensure()
616
+ rel = "latest" if LATEST.exists() and LATEST.resolve() == folder.resolve() else folder.name
617
+ target = f"http://127.0.0.1:{port}/{rel}/{page}" if port else str(folder / page)
618
+ p = subprocess.run(["open", target], capture_output=True, text=True)
619
+ if p.returncode:
620
+ notify(f"Could not open the agent map: {(p.stderr or '').strip()[:120]}")
621
+ return False
622
+ print(f"opened {target}")
623
+ return True
624
+
625
+
626
+ def first_run_busy() -> bool:
627
+ try:
628
+ info = json.loads(FIRST_RUN.read_text())
629
+ os.kill(int(info["pid"]), 0)
630
+ return time.time() - info.get("started", 0) < 1800
631
+ except (OSError, ValueError, KeyError, TypeError):
632
+ return False
633
+
634
+
601
635
  def open_latest(model: str) -> int:
602
636
  folder = latest_report()
603
637
  if folder:
604
- import serve # served from 127.0.0.1 so the pages' Refresh button works; else the files
605
- port = serve.ensure()
606
- base = f"http://127.0.0.1:{port}/{os.path.relpath(LATEST if LATEST.exists() else folder, REPORTS)}/" \
607
- if port else None
608
- for page in ("agent-stats.html", "agent-map.html", "agent-logs.html", "agent-sessions.html"):
609
- if (folder / page).is_file():
610
- subprocess.run(["open", base + page if base else str(folder / page)], capture_output=True)
611
- print(f"opened {base or folder}")
638
+ return 0 if open_page(folder) else 1
639
+ # No report yet: the pages without a model first (seconds), open them, then the map in the background.
640
+ if first_run_busy(): # a second click while the first report is being built
641
+ notify("Your first agent map is still being built; it opens when ready.")
612
642
  return 0
613
- # No report yet: build the first one in the background and open it when it is ready.
614
643
  REPORTS.mkdir(parents=True, exist_ok=True)
644
+ FIRST_RUN.write_text(json.dumps({"pid": os.getpid(), "started": time.time()}))
645
+ notify("Building your first agent map (a few seconds)…")
615
646
  with open(STATE / "first-run.log", "a") as fh:
616
- subprocess.Popen([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "nightly", "--model", model, "--open"],
617
- stdout=fh, stderr=fh, stdin=subprocess.DEVNULL, start_new_session=True)
618
- notify("Building your first agent map (a few minutes); it opens when ready.")
619
- print("no report yet: building the first one in the background (log: ~/.hivey/agent-map/first-run.log)")
647
+ subprocess.run([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "refresh"], stdout=fh, stderr=fh,
648
+ stdin=subprocess.DEVNULL, timeout=600)
649
+ folder = latest_report()
650
+ if folder:
651
+ open_page(folder)
652
+ # the map needs the model: drawn in the background; the page's Refresh (or reopening) shows it
653
+ bg = subprocess.Popen([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "nightly", "--model", model],
654
+ stdout=fh, stderr=fh, stdin=subprocess.DEVNULL, start_new_session=True)
655
+ FIRST_RUN.write_text(json.dumps({"pid": bg.pid, "started": time.time()}))
656
+ if folder:
657
+ notify("Stats, logs and sessions are open; the map is being drawn (a few minutes).")
658
+ print("first report: pages built; the map is being drawn in the background (log: ~/.hivey/agent-map/first-run.log)")
620
659
  return 0
621
660
 
622
661