@hivey/cli 0.9.60 → 0.9.61

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.60",
3
+ "version": "0.9.61",
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",
@@ -104,8 +104,8 @@ surprising link). If archify is missing, give the stats as Markdown tables and t
104
104
 
105
105
  ```bash
106
106
  hivey agent-map open # the latest report; builds the first one when none exists
107
- hivey agent-map nightly [--model haiku] # a full report now (also: --no-llm, --open)
108
- hivey agent-map schedule install [--at 06:30] [--model haiku] # | remove | status
107
+ hivey agent-map nightly [--model sonnet] # a full report now (also: --no-llm, --open)
108
+ hivey agent-map schedule install [--at 06:30] [--model sonnet] # | remove | status
109
109
  ```
110
110
 
111
111
  - **hivey menu → agent map** runs `hivey agent-map open`: it opens `agent-stats.html`,
@@ -162,7 +162,7 @@ hivey agent-map schedule install [--at 06:30] [--model haiku] # | remove | sta
162
162
  why a job or agent is not working, read its entry in `snapshot.json` (`jobs[].errors`, `tail`,
163
163
  `agent_logs`) or open this page, then the full log it names.
164
164
  - **`nightly`** (`report.py`): scan → stats page written and finalized by code (no LLM) → last night's
165
- `map.json` copied in → one `claude -p --model haiku` run (in the report folder, limited tools) that
165
+ `map.json` copied in → one `claude -p --model sonnet` run (in the report folder, limited tools) that
166
166
  confirms new links and updates the map → if the model fails or breaks the map, last night's map is
167
167
  rendered unchanged. `reports/latest` moves only when the stats page passed; the 30 newest reports
168
168
  are kept. About 2 minutes and $0.03 with Haiku. Log: `nightly.log` and `llm.log` in the report.
@@ -8,10 +8,10 @@
8
8
  add one entry to the spend log
9
9
  agent_map.py link FROM TO --via WHAT [--evidence TEXT] [--remove]
10
10
  confirm (or remove) a link between two nodes
11
- agent_map.py nightly [--model haiku] [--no-llm] [--open]
11
+ agent_map.py nightly [--model sonnet] [--no-llm] [--open]
12
12
  a full report in ~/.hivey/agent-map/reports/<date>/
13
13
  agent_map.py open open the latest report (hivey menu → agent map)
14
- agent_map.py schedule [install|remove|status|offer] [--at 06:30] [--model haiku]
14
+ agent_map.py schedule [install|remove|status|offer] [--at 06:30] [--model sonnet]
15
15
  agent_map.py schedule token --command "envsave get es_…" long-lived Claude login for the run
16
16
  the nightly launchd run (com.hivey.agent-map)
17
17
 
@@ -1057,19 +1057,19 @@ def main() -> int:
1057
1057
  lg.add_argument("--note")
1058
1058
  nt = sub.add_parser("nightly", help="scan, stats page, map update with a cheap model, reports/latest")
1059
1059
  nt.add_argument("--days", type=int, default=7)
1060
- nt.add_argument("--model", default="haiku")
1060
+ nt.add_argument("--model", default="sonnet")
1061
1061
  nt.add_argument("--no-llm", action="store_true", help="no model run: last night's map, unchanged")
1062
1062
  nt.add_argument("--open", action="store_true", help="open the report when done")
1063
1063
  en = sub.add_parser("enhance", help="re-apply hivey's layer (navbar, colours, info) to a report")
1064
1064
  en.add_argument("folder", nargs="?", default=str(STATE / "reports" / "latest"))
1065
1065
  op = sub.add_parser("open", help="open the latest report (builds the first one if there is none)")
1066
- op.add_argument("--model", default="haiku")
1066
+ op.add_argument("--model", default="sonnet")
1067
1067
  sc = sub.add_parser("schedule", help="the nightly launchd run: install | remove | status")
1068
1068
  sc.add_argument("action", choices=["install", "remove", "status", "offer", "token"], nargs="?", default="status")
1069
1069
  sc.add_argument("--command", help='token: the command printing the `claude setup-token` token, '
1070
1070
  'e.g. "envsave get es_…" ("" = the normal claude login)')
1071
1071
  sc.add_argument("--at", default="06:30", help="HH:MM, local time (default 06:30, after the night's jobs)")
1072
- sc.add_argument("--model", default="haiku")
1072
+ sc.add_argument("--model", default="sonnet")
1073
1073
  rf = sub.add_parser("refresh", help="new scan into the latest report's pages, no model (the Refresh button)")
1074
1074
  rf.add_argument("--days", type=int, default=7)
1075
1075
  sub.add_parser("serve", help="serve the report pages on 127.0.0.1 (`open` starts it)")
@@ -1123,7 +1123,7 @@ def main() -> int:
1123
1123
  return 0 if entry else 1
1124
1124
  if a.cmd == "refresh":
1125
1125
  import report
1126
- return report.refresh(scan, a.days, "haiku")
1126
+ return report.refresh(scan, a.days, "sonnet")
1127
1127
  if a.cmd == "serve":
1128
1128
  import serve
1129
1129
  return serve.serve()
@@ -418,7 +418,8 @@ already built: do not touch stats.archify.md or agent-stats.html.
418
418
  nodes[].llm_api.models in snapshot.json). People chatting with agents (interactive sessions) are on
419
419
  another page: never show their spend; drop an agent that has no automated runs and no data links,
420
420
  and keep a consumer agent (one a job feeds) without its interactive cost. Each node's sublabel holds
421
- its schedule or role, its models and its automated cost when it has one ("cron 04:15 · Grok + Sonnet ·
421
+ its schedule with its start time (a box folding several jobs shows the earliest: "cron from 00:30")
422
+ or its role, its models and its automated cost when it has one ("cron 04:15 · Grok + Sonnet ·
422
423
  $0.40"); spend is usage.agents (automated only). Keep at most 25 nodes on 5 stages x rows 0-4;
423
424
  refresh the numbers in the cards (automated spend, models in use, needs attention).
424
425
  3. Descriptions: every node in snapshot.json has a "description" (what it does). snapshot.json
@@ -565,6 +566,96 @@ def day_spec(spec: dict) -> dict:
565
566
  return {**spec, "meta": meta, "nodes": nodes, "cards": cards}
566
567
 
567
568
 
569
+ DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
570
+
571
+
572
+ def job_start(schedule: str) -> tuple[str, str] | None:
573
+ """(HH:MM, the schedule's words for one job) from a cron line or a launchd description, or None
574
+ when the job has no fixed start time (hourly, every N s, always on, at login, on demand)."""
575
+ s = (schedule or "").strip()
576
+ f = s.split()
577
+ if len(f) == 5: # cron: minute hour day-of-month month day-of-week
578
+ mm, hh = (re.split(r"[,-]", x)[0] for x in f[:2])
579
+ if not (mm.isdigit() and hh.isdigit()):
580
+ return None
581
+ t = f"{int(hh):02d}:{int(mm):02d}"
582
+ if f[4].isdigit():
583
+ return t, f"{DAYS[int(f[4]) % 7]} {t}"
584
+ if f[2].isdigit():
585
+ return t, f"day {f[2]} {t}"
586
+ return t, t
587
+ m = re.search(r"(\d\d):(\d\d)", s)
588
+ if not m:
589
+ return None
590
+ return m.group(0), re.sub(r"^daily\s+", "", s)
591
+
592
+
593
+ def start_time_labels(spec: dict, meta: dict, snap: dict) -> dict[str, list[str]]:
594
+ """Every scheduled box on the map shows when it starts. The model writes the sublabels and leaves
595
+ the time out of folded boxes ("11 trading jobs") and of agents run by jobs; the scan knows each
596
+ job's schedule, so a box without a time gets its job's time, or "from <earliest>" when it stands
597
+ for several jobs. Data stores get none. Returns {box id: sublabels to try, longest first}: when a
598
+ box is too narrow, the model names go before the cost and the errors."""
599
+ jobs = {j["id"]: j for j in snap.get("jobs") or [] if j.get("id")}
600
+ owned: dict[str, list[str]] = {}
601
+ for b in (snap.get("links_candidates") or {}).get("belongs_to") or []:
602
+ owned.setdefault(b.get("agent", ""), []).append(b.get("job", ""))
603
+ out = {}
604
+ for n in spec.get("nodes") or []:
605
+ sub = str(n.get("sublabel", ""))
606
+ if n.get("type") == "database" or re.search(r"\b\d\d:\d\d\b", sub):
607
+ continue
608
+ refs = ((meta.get("nodes") or {}).get(n.get("id")) or {}).get("refs") or []
609
+ ids = [r for r in refs if r in jobs] or [j for r in refs for j in owned.get(r, []) if j in jobs]
610
+ starts = [s for s in (job_start(jobs[j].get("schedule", "")) for j in dict.fromkeys(ids)) if s]
611
+ if not starts:
612
+ continue
613
+ when = starts[0][1] if len(starts) == 1 else "from " + min(t for t, _ in starts)
614
+ m = re.match(r"(cron|launchd|nightly|daily|weekly|\d+ jobs)\b", sub)
615
+ first = (sub[:m.end()] + " " + when + sub[m.end():]) if m else " · ".join(x for x in (when, sub) if x)
616
+ parts = [x.strip() for x in first.split("·")]
617
+ tries = [first]
618
+ while len(parts) > 1:
619
+ keep = lambda x: re.search(r"\$|error|exit|fail", x, re.I)
620
+ drop = next((i for i in range(len(parts) - 1, 0, -1) if not keep(parts[i])), len(parts) - 1)
621
+ parts.pop(drop)
622
+ tries.append(" · ".join(parts))
623
+ out[str(n.get("id"))] = tries
624
+ return out
625
+
626
+
627
+ def place_start_times(folder: Path) -> None:
628
+ """Put the start times on the map (start_time_labels) and redraw it. A box the drawing rejects as
629
+ too narrow tries its next, shorter sublabel; when nothing fits, the night's map stays as it was."""
630
+ spec_path, meta_path, snap_path = folder / "map.json", folder / "map-meta.json", folder / "snapshot.json"
631
+ try:
632
+ original = spec_path.read_text()
633
+ spec, meta, snap = json.loads(original), json.loads(meta_path.read_text()), json.loads(snap_path.read_text())
634
+ except (OSError, ValueError):
635
+ return
636
+ tries = start_time_labels(spec, meta, snap)
637
+ if not tries:
638
+ return
639
+ step = dict.fromkeys(tries, 0)
640
+ for _ in range(8):
641
+ for n in spec.get("nodes") or []:
642
+ if n.get("id") in step:
643
+ n["sublabel"] = tries[n["id"]][step[n["id"]]]
644
+ spec_path.write_text(json.dumps(spec, indent=1))
645
+ good, why = finalize(folder, "dataflow", "map.json", "agent-map.html")
646
+ if good:
647
+ log(folder, f"map start times: {len(step)} boxes")
648
+ return
649
+ bad = [i for i in re.findall(r'node "([^"]+)"', why) if i in step]
650
+ if not bad or any(step[i] + 1 >= len(tries[i]) for i in bad):
651
+ break
652
+ for i in bad:
653
+ step[i] += 1
654
+ log(folder, f"map start times did not fit ({why}); map unchanged")
655
+ spec_path.write_text(original)
656
+ finalize(folder, "dataflow", "map.json", "agent-map.html")
657
+
658
+
568
659
  def day_view(scan, folder: Path) -> None:
569
660
  try:
570
661
  ok, msg = write_day_view(scan, folder)
@@ -605,6 +696,8 @@ def nightly(scan, days: int, model: str, use_llm: bool) -> int:
605
696
  log(folder, f"map: {'ok' if good else 'FAILED ' + why}")
606
697
  else:
607
698
  log(folder, "map: ok" if (folder / "agent-map.html").is_file() else "map: none yet")
699
+ if (folder / "agent-map.html").is_file():
700
+ place_start_times(folder)
608
701
 
609
702
  try:
610
703
  import enhance
@@ -640,6 +733,7 @@ def refresh(scan, days: int, model: str) -> int:
640
733
  import sessions_page
641
734
  sessions_page.write_sessions_page(snap, folder)
642
735
  ok, msg = finalize(folder, "explainer", "stats.archify.md", "agent-stats.html")
736
+ place_start_times(folder)
643
737
  try:
644
738
  import enhance
645
739
  enhance.enhance_folder(folder, json.loads((folder / "snapshot.json").read_text()), job_state)
@@ -733,6 +827,15 @@ OFFER = STATE / "offer.json"
733
827
  def offer(hour: int, minute: int, model: str) -> int:
734
828
  """Asked once, by install.sh and `hivey update`: set up the nightly run? The answer is kept in
735
829
  offer.json so it is never asked again; with no terminal nothing is asked (asked next time)."""
830
+ if sys.platform == "darwin" and PLIST.is_file(): # nights set up with Haiku move to Sonnet, same time:
831
+ try: # Haiku did not follow the map rules well
832
+ with open(PLIST, "rb") as fh:
833
+ d = plistlib.load(fh)
834
+ if d.get("ProgramArguments", [])[-2:] == ["--model", "haiku"]:
835
+ cal = d.get("StartCalendarInterval", {})
836
+ return schedule("install", cal.get("Hour", hour), cal.get("Minute", minute), "sonnet")
837
+ except (OSError, ValueError, plistlib.InvalidFileException):
838
+ pass
736
839
  if sys.platform != "darwin" or PLIST.is_file() or OFFER.is_file() or not sys.stdin.isatty():
737
840
  return 0 # not a person at a terminal (remote or scripted update): asked next time
738
841
  try:
@@ -744,7 +847,7 @@ def offer(hour: int, minute: int, model: str) -> int:
744
847
  "\nhivey can watch this computer every night: scheduled jobs (cron, launchd), agents and\n"
745
848
  "swarms, token use and estimated cost per agent and provider, failing jobs, and how\n"
746
849
  "agents feed each other. The report opens from the hivey menu → agent map.\n"
747
- f"It runs at {hour:02}:{minute:02} with Claude {model} (a few cents a night).\n"
850
+ f"It runs at {hour:02}:{minute:02} with Claude {model} (well under a dollar a night).\n"
748
851
  "Set up the nightly agent monitoring? [Y/n] ")
749
852
  tty.flush()
750
853
  answer = tty.readline().strip().lower()