@hivey/cli 0.9.70 → 0.9.71

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.
Files changed (65) hide show
  1. package/native/darwin-arm64/hivey +0 -0
  2. package/package.json +1 -1
  3. package/repo/skills/hivey-agent-map/SKILL.md +11 -11
  4. package/repo/skills/hivey-agent-map/scripts/agent_map.py +8 -6
  5. package/repo/skills/hivey-agent-map/scripts/enhance.py +6 -2
  6. package/repo/skills/hivey-agent-map/scripts/{office/office.html → fleet/fleet.html} +13 -8
  7. package/repo/skills/hivey-agent-map/scripts/{office/office.js → fleet/fleet.js} +71 -48
  8. package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/README.txt +1 -1
  9. package/repo/skills/hivey-agent-map/scripts/{office → fleet}/ship.js +2 -2
  10. package/repo/skills/hivey-agent-map/scripts/{office.py → fleet.py} +25 -23
  11. package/repo/skills/hivey-agent-map/scripts/report.py +4 -4
  12. package/repo/skills/hivey-agent-map/scripts/serve.py +117 -62
  13. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/OutlineEffect.js +0 -0
  14. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/RoomEnvironment.js +0 -0
  15. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/loaders/GLTFLoader.js +0 -0
  16. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/LICENSE-kenney-space-kit.txt +0 -0
  17. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/LICENSE-kenney-space-station-kit.txt +0 -0
  18. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/LICENSE-robot.txt +0 -0
  19. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/astronautA.glb.b64 +0 -0
  20. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/astronautB.glb.b64 +0 -0
  21. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/barrels.glb.b64 +0 -0
  22. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/barrels_rail.glb.b64 +0 -0
  23. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/craft_cargoA.glb.b64 +0 -0
  24. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/craft_racer.glb.b64 +0 -0
  25. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/craft_speederA.glb.b64 +0 -0
  26. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/desk_chairArms.glb.b64 +0 -0
  27. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/desk_computer.glb.b64 +0 -0
  28. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/machine_generator.glb.b64 +0 -0
  29. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/machine_generatorLarge.glb.b64 +0 -0
  30. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/machine_wireless.glb.b64 +0 -0
  31. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/robot.glb.b64 +0 -0
  32. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/satelliteDish_detailed.glb.b64 +0 -0
  33. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/satelliteDish_large.glb.b64 +0 -0
  34. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/Textures/colormap.png.b64 +0 -0
  35. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/chair-cushion-headrest.glb.b64 +0 -0
  36. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/computer-system.glb.b64 +0 -0
  37. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/computer-wide.glb.b64 +0 -0
  38. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/container-flat.glb.b64 +0 -0
  39. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/container-tall.glb.b64 +0 -0
  40. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/container-wide.glb.b64 +0 -0
  41. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/display-wall-wide.glb.b64 +0 -0
  42. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/models/station/pipe-ring-colored.glb.b64 +0 -0
  43. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/space.mp3.b64 +0 -0
  44. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/space_02.mp3.b64 +0 -0
  45. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_01.mp3.b64 +0 -0
  46. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_02.mp3.b64 +0 -0
  47. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_03.mp3.b64 +0 -0
  48. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_04.mp3.b64 +0 -0
  49. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_05.mp3.b64 +0 -0
  50. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_06.mp3.b64 +0 -0
  51. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_07.mp3.b64 +0 -0
  52. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/music/track_08.mp3.b64 +0 -0
  53. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/EffectComposer.js +0 -0
  54. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/MaskPass.js +0 -0
  55. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/OutputPass.js +0 -0
  56. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/Pass.js +0 -0
  57. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/RenderPass.js +0 -0
  58. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/ShaderPass.js +0 -0
  59. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/postprocessing/UnrealBloomPass.js +0 -0
  60. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/shaders/CopyShader.js +0 -0
  61. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/shaders/LuminosityHighPassShader.js +0 -0
  62. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/shaders/OutputShader.js +0 -0
  63. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/three.module.min.js +0 -0
  64. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/utils/BufferGeometryUtils.js +0 -0
  65. /package/repo/skills/hivey-agent-map/scripts/{office → fleet}/utils/SkeletonUtils.js +0 -0
@@ -1,4 +1,4 @@
1
- """The agent office: what every live agent is doing now, drawn as a 3D office of desks.
1
+ """The agent fleet: what every live agent is doing now, drawn as a 3D fleet of desks.
2
2
 
3
3
  One desk per agent you talk to in hivey: solo agents, extra sessions in a space, and each swarm's
4
4
  coordinator (a swarm's workers and critics are folded into their coordinator's desk as its team).
@@ -16,11 +16,11 @@ desk: the current job, a speech-bubble line, what it achieved, what it waits for
16
16
  sent again, in batches, so 100 agents cost a few calls per refresh. Without a model (--no-llm, or the
17
17
  call fails) the summary comes from the recap and the last prompt.
18
18
 
19
- Output: ~/.hivey/agent-map/reports/office/office.json, read by office.html (Three.js, vendored), served
19
+ Output: ~/.hivey/agent-map/reports/fleet/fleet.json, read by fleet.html (Three.js, vendored), served
20
20
  by serve.py, which reruns this every 5 minutes while the page is open. Python standard library only.
21
21
 
22
- office.py run [--no-llm] [--quick] [--model haiku] one refresh (--quick: the 1-minute live pass)
23
- office.py open start the server, refresh if stale, open the page
22
+ fleet.py run [--no-llm] [--quick] [--model haiku] one refresh (--quick: the 1-minute live pass)
23
+ fleet.py open start the server, refresh if stale, open the page
24
24
  """
25
25
  from __future__ import annotations
26
26
 
@@ -45,10 +45,10 @@ import context_window # noqa: E402
45
45
 
46
46
  HOME = Path.home()
47
47
  STATE = HOME / ".hivey" / "agent-map"
48
- OUT = STATE / "reports" / "office"
49
- CACHE = STATE / "office-cache.json"
50
- LOCK = STATE / "office.lock"
51
- RUN_DIR = STATE / "office-run" # neutral cwd for the model calls (no CLAUDE.md, no project)
48
+ OUT = STATE / "reports" / "fleet"
49
+ CACHE = STATE / "fleet-cache.json"
50
+ LOCK = STATE / "fleet.lock"
51
+ RUN_DIR = STATE / "fleet-run" # neutral cwd for the model calls (no CLAUDE.md, no project)
52
52
 
53
53
  STANDARD_WINDOW = 200_000
54
54
  LARGE_WINDOW = 1_000_000
@@ -94,7 +94,7 @@ def now_iso() -> str:
94
94
  return dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds")
95
95
 
96
96
 
97
- # ---------------------------------------------------------------- who is in the office
97
+ # ---------------------------------------------------------------- who is in the fleet
98
98
 
99
99
  def hv_sessions(hv: str) -> list[dict]:
100
100
  """Every named hivey session: [{name, running, default, socket}] (the default one first)."""
@@ -404,7 +404,7 @@ def window_for(desk: dict, ctx: int) -> int:
404
404
 
405
405
  # ---------------------------------------------------------------- the summaries
406
406
 
407
- PROMPT = """You are the receptionist of an office of AI coding agents. For each agent below you get its
407
+ PROMPT = """You are the receptionist of a fleet of AI coding agents. For each agent below you get its
408
408
  status, its terminal screen (bottom of the screen = now) and, for Claude Code agents, facts from its session
409
409
  log. Write what a busy manager needs at a glance. Plain words, no jargon, no markdown.
410
410
 
@@ -542,9 +542,11 @@ def collect(hv: str, sessions: list[dict] | None = None) -> list[dict]:
542
542
 
543
543
 
544
544
  def run(model: str = "haiku", use_llm: bool = True, quick: bool = False) -> int:
545
+ import serve
546
+ serve.migrate_legacy()
545
547
  hv = hivey_bin()
546
548
  if not hv:
547
- print("office: hivey not found", file=sys.stderr)
549
+ print("fleet: hivey not found", file=sys.stderr)
548
550
  return 1
549
551
  STATE.mkdir(parents=True, exist_ok=True)
550
552
  try:
@@ -553,7 +555,7 @@ def run(model: str = "haiku", use_llm: bool = True, quick: bool = False) -> int:
553
555
  os.close(fd)
554
556
  except FileExistsError:
555
557
  if time.time() - LOCK.stat().st_mtime < 600:
556
- print("office: a refresh is already running")
558
+ print("fleet: a refresh is already running")
557
559
  return 0
558
560
  LOCK.unlink(missing_ok=True)
559
561
  return run(model, use_llm, quick)
@@ -637,7 +639,7 @@ def _run(hv: str, model: str, use_llm: bool, quick: bool = False) -> int:
637
639
  full_at = now_iso()
638
640
  if quick: # a live pass: the last full summary pass stays the one already on the page
639
641
  try:
640
- full_at = json.loads((OUT / "office.json").read_text()).get("full_at") or full_at
642
+ full_at = json.loads((OUT / "fleet.json").read_text()).get("full_at") or full_at
641
643
  except (OSError, ValueError):
642
644
  pass
643
645
  data = {"generated": now_iso(), "kind": "quick" if quick else "full", "full_at": full_at, "seconds": round(time.time() - start, 1), "model": model if use_llm else None,
@@ -648,14 +650,14 @@ def _run(hv: str, model: str, use_llm: bool, quick: bool = False) -> int:
648
650
  "advice": {k: sum(1 for d in people if d["summary"].get("advice") == k and not d.get("asleep"))
649
651
  for k in ("compact", "clear")}}
650
652
  write(data)
651
- print(f"office: {len(people)} desks, {len(todo) if use_llm else 0} summarized"
653
+ print(f"fleet: {len(people)} desks, {len(todo) if use_llm else 0} summarized"
652
654
  f"{' (' + error + ')' if error else ''} in {data['seconds']}s → {OUT / 'index.html'}")
653
655
  return 0
654
656
 
655
657
 
656
658
  def write(data: dict) -> None:
657
659
  OUT.mkdir(parents=True, exist_ok=True)
658
- assets = SCRIPTS / "office" # the page and its modules (Three.js, post-processing, the ship)
660
+ assets = SCRIPTS / "fleet" # the page and its modules (Three.js, post-processing, the ship)
659
661
  for src in assets.rglob("*"):
660
662
  if not src.is_file() or src.name.startswith("."):
661
663
  continue
@@ -663,35 +665,35 @@ def write(data: dict) -> None:
663
665
  blob = src.read_bytes()
664
666
  if rel.suffix == ".b64": # binary models travel base64 (skills install text files)
665
667
  rel, blob = rel.with_suffix(""), base64.b64decode(blob)
666
- dst = OUT / ("index.html" if rel.as_posix() == "office.html" else rel)
668
+ dst = OUT / ("index.html" if rel.as_posix() == "fleet.html" else rel)
667
669
  if not dst.is_file() or dst.read_bytes() != blob:
668
670
  dst.parent.mkdir(parents=True, exist_ok=True)
669
671
  dst.write_bytes(blob)
670
- tmp = OUT / "office.json.tmp"
672
+ tmp = OUT / "fleet.json.tmp"
671
673
  tmp.write_text(json.dumps(data, ensure_ascii=False))
672
- os.replace(tmp, OUT / "office.json")
674
+ os.replace(tmp, OUT / "fleet.json")
673
675
 
674
676
 
675
677
  def open_page(model: str) -> int:
676
678
  import serve
677
- data = OUT / "office.json"
679
+ data = OUT / "fleet.json"
678
680
  fresh = data.is_file() and time.time() - data.stat().st_mtime < STALE_SECONDS
679
681
  if not fresh:
680
682
  run(model, use_llm=False) # seconds: desks and terminal lines now, summaries follow
681
683
  port = serve.ensure()
682
684
  if not port:
683
- print("office: the local page server did not start (see ~/.hivey/agent-map/server.log)", file=sys.stderr)
685
+ print("fleet: the local page server did not start (see ~/.hivey/agent-map/server.log)", file=sys.stderr)
684
686
  return 1
685
687
  if not fresh:
686
- serve.request_office_refresh(port)
687
- url = f"http://127.0.0.1:{port}/office/"
688
+ serve.request_fleet_refresh(port)
689
+ url = f"http://127.0.0.1:{port}/fleet/"
688
690
  subprocess.run(["open", url], capture_output=True)
689
691
  print(f"agent fleet: {url}")
690
692
  return 0
691
693
 
692
694
 
693
695
  def main(argv: list[str] | None = None) -> int:
694
- ap = argparse.ArgumentParser(prog="office.py", description=__doc__.split("\n\n")[0])
696
+ ap = argparse.ArgumentParser(prog="fleet.py", description=__doc__.split("\n\n")[0])
695
697
  sub = ap.add_subparsers(dest="cmd")
696
698
  r = sub.add_parser("run")
697
699
  r.add_argument("--no-llm", action="store_true")
@@ -792,10 +792,10 @@ def first_run_busy() -> bool:
792
792
  return False
793
793
 
794
794
 
795
- def open_latest(model: str) -> int:
795
+ def open_latest(model: str, show: bool = True) -> int:
796
796
  folder = latest_report()
797
797
  if folder:
798
- return 0 if open_page(folder) else 1
798
+ return 0 if not show or open_page(folder) else 1
799
799
  # No report yet: the pages without a model first (seconds), open them, then the map in the background.
800
800
  if first_run_busy(): # a second click while the first report is being built
801
801
  notify("Your first agent map is still being built; it opens when ready.")
@@ -807,13 +807,13 @@ def open_latest(model: str) -> int:
807
807
  subprocess.run([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "refresh"], stdout=fh, stderr=fh,
808
808
  stdin=subprocess.DEVNULL, timeout=600)
809
809
  folder = latest_report()
810
- if folder:
810
+ if folder and show:
811
811
  open_page(folder)
812
812
  # the map needs the model: drawn in the background; the page's Refresh (or reopening) shows it
813
813
  bg = subprocess.Popen([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "nightly", "--model", model],
814
814
  stdout=fh, stderr=fh, stdin=subprocess.DEVNULL, start_new_session=True)
815
815
  FIRST_RUN.write_text(json.dumps({"pid": bg.pid, "started": time.time()}))
816
- if folder:
816
+ if folder and show:
817
817
  notify("Stats, logs and sessions are open; the map is being drawn (a few minutes).")
818
818
  print("first report: pages built; the map is being drawn in the background (log: ~/.hivey/agent-map/first-run.log)")
819
819
  return 0
@@ -5,22 +5,26 @@ http://127.0.0.1:<port>/latest/. It listens on 127.0.0.1 only, serves ~/.hivey/a
5
5
  has these actions, answered only for the pages it serves (Origin check), so other web pages can't
6
6
  trigger them:
7
7
 
8
+ GET /hv-jobs the agent jobs pages for the fleet page's Jobs tab: a redirect to the latest
9
+ map (else stats, logs, sessions); with no report yet it starts the first build
10
+ (`agent_map.py open --no-open`) and answers a page that reloads until it is ready
8
11
  POST /hv-refresh `agent_map.py refresh` (free: no model)
9
- POST /hv-office-refresh `office.py run` in the background (the agent office, /office/)
10
- POST /hv-office-action {"action": "session", "session": "<name>"} shows a hivey session in a terminal (a
12
+ GET /fleet/ the agent fleet page (files in reports/fleet/; old /fleet/ links redirect here)
13
+ POST /hv-fleet-refresh `fleet.py run` in the background (the agent fleet, /fleet/)
14
+ POST /hv-fleet-action {"action": "session", "session": "<name>"} shows a hivey session in a terminal (a
11
15
  new one if none shows it; `hivey session attach` starts a stopped session),
12
16
  {"action": "stop-session", "session": "<name>"} stops a non-default session (all
13
17
  its agents) and closes its terminal windows, or
14
18
  {"id": "wN:p1" | "<session>/wN:p1", "action": "focus" | "compact" | "clear"} for a desk on the
15
- office page: focus opens the agent's terminal in hivey (and brings the
19
+ fleet page: focus opens the agent's terminal in hivey (and brings the
16
20
  terminal app forward); compact/clear type /compact or /clear into an agent
17
21
  that is not working
18
22
 
19
- While an office page is open (it polls /office/office.json), a live pass runs every minute (status,
23
+ While a fleet page is open (it polls /fleet/fleet.json), a live pass runs every minute (status,
20
24
  context, screen; only desks whose status changed go to the model) and a full re-summary every 5 minutes.
21
- The office page's ⏱ setting (POST /hv-office-settings {"every": "minute" | "5min" | "15min" | "1h" | "reload"}, saved in
22
- ~/.hivey/agent-map/office-settings.json) picks every minute (above), every 5 / 15 minutes or every hour (full passes only)
23
- or on reload only (no clock). POST /hv-office-refresh: {} a full pass now (⟳), {"load": true} when a page
25
+ The fleet page's ⏱ setting (POST /hv-fleet-settings {"every": "minute" | "5min" | "15min" | "1h" | "reload"}, saved in
26
+ ~/.hivey/agent-map/fleet-settings.json) picks every minute (above), every 5 / 15 minutes or every hour (full passes only)
27
+ or on reload only (no clock). POST /hv-fleet-refresh: {} a full pass now (⟳), {"load": true} when a page
24
28
  opens (a quick pass in minute mode, a full one otherwise), {"quick": true} a quick pass.
25
29
  It stops after 2 hours unused. Python standard library only.
26
30
  """
@@ -41,7 +45,7 @@ import urllib.request
41
45
  from pathlib import Path
42
46
 
43
47
  STATE = Path.home() / ".hivey" / "agent-map"
44
- OFFICE_SETTINGS = STATE / "office-settings.json" # {"every": "minute" | ..., "ships": {"<session>": {"x", "z"}}}
48
+ FLEET_SETTINGS = STATE / "fleet-settings.json" # {"every": "minute" | ..., "ships": {"<session>": {"x", "z"}}}
45
49
  EVERY_MODES = ("minute", "5min", "15min", "1h", "reload")
46
50
  FULL_EVERY = {"minute": 300, "5min": 300, "15min": 900, "1h": 3600} # seconds between full passes per mode
47
51
  REPORTS = STATE / "reports"
@@ -50,12 +54,13 @@ SCRIPTS = Path(__file__).resolve().parent
50
54
  PREFERRED_PORT = 42817 # unregistered and below macOS's temporary-port range, so no other app picks it
51
55
  IDLE_SECONDS = 2 * 3600
52
56
  PING = "/hv-ping"
57
+ LEGACY_PAGE = "/office" # the fleet page's address before it was renamed; redirected to /fleet/
53
58
  MARK = b"hivey-agent-map"
54
- VERSION = b"office-13" # bump when the server gains actions, so `ensure` replaces an older one
55
- OFFICE_EVERY = 300 # seconds between full office refreshes (every terminal re-summarized) while its page is open
56
- OFFICE_LIVE = 60 # seconds between live passes (status, context, screen; only changed statuses summarized)
57
- OFFICE_WATCHED = 600 # the page counts as open for this long after its last poll
58
- OFFICE_JSON = REPORTS / "office" / "office.json"
59
+ VERSION = b"fleet-16" # bump when the server gains actions, so `ensure` replaces an older one
60
+ FLEET_EVERY = 300 # seconds between full fleet refreshes (every terminal re-summarized) while its page is open
61
+ FLEET_LIVE = 60 # seconds between live passes (status, context, screen; only changed statuses summarized)
62
+ FLEET_WATCHED = 600 # the page counts as open for this long after its last poll
63
+ FLEET_JSON = REPORTS / "fleet" / "fleet.json"
59
64
  PANE = re.compile(r"^[\w-]{1,24}:[\w-]{1,24}$")
60
65
  TERMINAL_APPS = {"Apple_Terminal": "Terminal", "iTerm.app": "iTerm", "ghostty": "Ghostty",
61
66
  "WezTerm": "WezTerm", "WarpTerminal": "Warp", "vscode": "Visual Studio Code"}
@@ -66,16 +71,16 @@ def hivey_bin() -> str | None:
66
71
  return exe if exe and os.path.isfile(exe) else shutil.which("hivey")
67
72
 
68
73
 
69
- def office_settings() -> dict:
74
+ def fleet_settings() -> dict:
70
75
  try:
71
- got = json.loads(OFFICE_SETTINGS.read_text())
76
+ got = json.loads(FLEET_SETTINGS.read_text())
72
77
  return got if isinstance(got, dict) else {}
73
78
  except (OSError, ValueError):
74
79
  return {}
75
80
 
76
81
 
77
82
  def clean_ships(ships: object) -> dict:
78
- """{session: {x, z}} where you dragged each ship on the office page (bad entries dropped)."""
83
+ """{session: {x, z}} where you dragged each ship on the fleet page (bad entries dropped)."""
79
84
  out = {}
80
85
  for name, p in (ships.items() if isinstance(ships, dict) else []):
81
86
  try:
@@ -87,25 +92,25 @@ def clean_ships(ships: object) -> dict:
87
92
  return out
88
93
 
89
94
 
90
- def office_every() -> str:
91
- """The office page's refresh setting (every minute by default)."""
95
+ def fleet_every() -> str:
96
+ """The fleet page's refresh setting (every minute by default)."""
92
97
  try:
93
- mode = office_settings().get("every")
98
+ mode = fleet_settings().get("every")
94
99
  except (OSError, ValueError, AttributeError):
95
100
  mode = None
96
101
  return mode if mode in EVERY_MODES else "minute"
97
102
 
98
103
 
99
- def start_office_refresh(llm: bool = True, quick: bool = False) -> None:
100
- """office.py run in the background (it holds its own lock, so overlapping starts are dropped)."""
101
- cmd = [sys.executable, "-I", str(SCRIPTS / "office.py"), "run"] + ([] if llm else ["--no-llm"]) \
104
+ def start_fleet_refresh(llm: bool = True, quick: bool = False) -> None:
105
+ """fleet.py run in the background (it holds its own lock, so overlapping starts are dropped)."""
106
+ cmd = [sys.executable, "-I", str(SCRIPTS / "fleet.py"), "run"] + ([] if llm else ["--no-llm"]) \
102
107
  + (["--quick"] if quick else [])
103
- with open(STATE / "office.log", "a") as fh:
108
+ with open(STATE / "fleet.log", "a") as fh:
104
109
  subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=fh, stderr=fh, start_new_session=True)
105
110
 
106
111
 
107
- def request_office_refresh(port: int) -> None:
108
- req = urllib.request.Request(f"http://127.0.0.1:{port}/hv-office-refresh", data=b"{}", method="POST",
112
+ def request_fleet_refresh(port: int) -> None:
113
+ req = urllib.request.Request(f"http://127.0.0.1:{port}/hv-fleet-refresh", data=b"{}", method="POST",
109
114
  headers={"Origin": f"http://127.0.0.1:{port}", "Content-Type": "application/json"})
110
115
  try:
111
116
  urllib.request.urlopen(req, timeout=3).read()
@@ -264,10 +269,10 @@ def raise_terminal(session: str | None = None) -> str:
264
269
  return "raised"
265
270
 
266
271
 
267
- def office_desk(desk_id: str) -> dict | None:
268
- """The desk on the office page with this id (pane id, or "<session>/<pane>" outside the default session)."""
272
+ def fleet_desk(desk_id: str) -> dict | None:
273
+ """The desk on the fleet page with this id (pane id, or "<session>/<pane>" outside the default session)."""
269
274
  try:
270
- agents = json.loads(OFFICE_JSON.read_text()).get("agents", [])
275
+ agents = json.loads(FLEET_JSON.read_text()).get("agents", [])
271
276
  except (OSError, ValueError):
272
277
  return None
273
278
  return next((a for a in agents if a.get("id") == desk_id), None) \
@@ -334,7 +339,7 @@ def stop_session(session: str) -> tuple[bool, str]:
334
339
  if not exe or not SESSION_NAME.match(session or ""):
335
340
  return False, "unknown session"
336
341
  if session == "default":
337
- return False, "the default session is not stopped from here (it runs this office); quit it in hivey"
342
+ return False, "the default session is not stopped from here (it runs this fleet); quit it in hivey"
338
343
  ttys = client_ttys(session, only=True)
339
344
  p = subprocess.run([exe, "session", "stop", session], capture_output=True, text=True, timeout=60)
340
345
  if p.returncode != 0:
@@ -380,7 +385,7 @@ def open_wiki_page(desk: dict, rel: str) -> tuple[bool, str]:
380
385
  return True, f"opened (not an Obsidian vault yet: in Obsidian, Open folder as vault → {wiki.get('short')})"
381
386
 
382
387
 
383
- def office_action(desk_id: str, action: str, session: str = "", path: str = "") -> tuple[bool, str]:
388
+ def fleet_action(desk_id: str, action: str, session: str = "", path: str = "") -> tuple[bool, str]:
384
389
  if action == "session":
385
390
  return session_action(session)
386
391
  if action == "stop-session":
@@ -388,7 +393,7 @@ def office_action(desk_id: str, action: str, session: str = "", path: str = "")
388
393
  exe = hivey_bin()
389
394
  if not exe:
390
395
  return False, "hivey not found"
391
- desk = office_desk(desk_id)
396
+ desk = fleet_desk(desk_id)
392
397
  pane = (desk or {}).get("pane") or ""
393
398
  if not desk or not PANE.match(pane):
394
399
  return False, "unknown agent"
@@ -468,8 +473,8 @@ class Handler(http.server.SimpleHTTPRequestHandler):
468
473
  server_version = "hivey-agent-map"
469
474
  busy = threading.Lock()
470
475
  last_used = time.time()
471
- office_polled = 0.0
472
- office_full = 0.0 # last full (all re-summarized) office refresh started by this server
476
+ fleet_polled = 0.0
477
+ fleet_full = 0.0 # last full (all re-summarized) fleet refresh started by this server
473
478
 
474
479
  def __init__(self, *args, **kwargs):
475
480
  super().__init__(*args, directory=str(REPORTS), **kwargs)
@@ -492,26 +497,60 @@ class Handler(http.server.SimpleHTTPRequestHandler):
492
497
  Handler.last_used = time.time()
493
498
  if self.path == PING:
494
499
  return self.answer(200, MARK + b" " + VERSION, "text/plain")
495
- if self.path.split("?")[0] == "/office/office.json":
496
- Handler.office_polled = time.time()
500
+ path, _, query = self.path.partition("?")
501
+ if path == "/fleet" or path == LEGACY_PAGE or path.startswith(LEGACY_PAGE + "/"): # old links: /fleet/
502
+ self.send_response(301)
503
+ self.send_header("Location", "/fleet/" + ("?" + query if query else ""))
504
+ self.send_header("Content-Length", "0")
505
+ self.end_headers()
506
+ return None
507
+ if path == "/fleet/fleet.json":
508
+ Handler.fleet_polled = time.time()
509
+ if self.path.split("?")[0] == "/hv-jobs":
510
+ return self.jobs()
497
511
  return super().do_GET()
498
512
 
513
+ def jobs(self) -> None:
514
+ """The fleet page's Jobs tab: the latest agent jobs page, or the first report being built."""
515
+ import report
516
+ folder = report.latest_report()
517
+ page = next((p for p in report.PAGES if folder and (folder / p).is_file()), None)
518
+ if folder and page:
519
+ rel = "latest" if report.LATEST.exists() and report.LATEST.resolve() == folder.resolve() else folder.name
520
+ self.send_response(302)
521
+ self.send_header("Location", f"/{rel}/{page}")
522
+ self.send_header("Content-Length", "0")
523
+ self.end_headers()
524
+ return None
525
+ if not report.first_run_busy():
526
+ log = open(STATE / "first-run.log", "a")
527
+ subprocess.Popen([sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "open", "--no-open"],
528
+ stdout=log, stderr=log, stdin=subprocess.DEVNULL, start_new_session=True)
529
+ log.close()
530
+ body = ("<!doctype html><meta charset=utf-8><meta http-equiv=refresh content=5>"
531
+ "<body style=\"font:15px system-ui;background:#0b0e15;color:#cbd5e1;display:grid;place-items:center;"
532
+ "height:90vh;margin:0\"><div style=\"text-align:center\"><div style=\"font-size:34px\">📊</div>"
533
+ "<p><b>Building your first agent jobs report…</b></p><p style=\"opacity:.7\">Stats, logs and "
534
+ "sessions take a few seconds; the map is drawn in the background. This page reloads by itself."
535
+ "</p></div></body>")
536
+ return self.answer(200, body.encode(), "text/html; charset=utf-8")
537
+
499
538
  def do_POST(self) -> None:
500
539
  Handler.last_used = time.time()
501
540
  port = self.server.server_address[1]
502
- if self.path not in ("/hv-refresh", "/hv-office-refresh", "/hv-office-action", "/hv-office-settings"):
541
+ if self.path not in ("/hv-refresh", "/hv-fleet-refresh", "/hv-fleet-action", "/hv-fleet-settings"):
503
542
  return self.answer(404, b'{"ok":false,"error":"not found"}')
504
543
  if self.headers.get("Origin") not in (f"http://127.0.0.1:{port}", f"http://localhost:{port}"):
505
544
  return self.answer(403, b'{"ok":false,"error":"only the agent map pages can do this"}')
506
- if self.path in ("/hv-office-refresh", "/hv-office-settings"):
545
+ if self.path in ("/hv-fleet-refresh", "/hv-fleet-settings"):
507
546
  try:
508
547
  length = min(int(self.headers.get("Content-Length") or 0), 4096)
509
548
  req = json.loads(self.rfile.read(length) or b"{}")
510
549
  req = req if isinstance(req, dict) else {}
511
550
  except ValueError:
512
551
  req = {}
513
- if self.path == "/hv-office-settings":
514
- cur = office_settings()
552
+ if self.path == "/hv-fleet-settings":
553
+ cur = fleet_settings()
515
554
  if "every" in req:
516
555
  if req.get("every") not in EVERY_MODES:
517
556
  return self.answer(400, b'{"ok":false,"error":"every: minute, 5min, 15min, 1h or reload"}')
@@ -524,26 +563,26 @@ class Handler(http.server.SimpleHTTPRequestHandler):
524
563
  if not re.fullmatch(r"random|[1-9]|10", str(req["track"])):
525
564
  return self.answer(400, b'{"ok":false,"error":"track: random or 1..10"}')
526
565
  cur["track"] = str(req["track"])
527
- if "ships" in req: # the ship positions you dragged on the office page
566
+ if "ships" in req: # the ship positions you dragged on the fleet page
528
567
  cur["ships"] = clean_ships(req["ships"])
529
- OFFICE_SETTINGS.write_text(json.dumps(cur))
530
- return self.answer(200, json.dumps({"ok": True, "every": office_every(), "space": cur.get("space"), "track": cur.get("track"),
568
+ FLEET_SETTINGS.write_text(json.dumps(cur))
569
+ return self.answer(200, json.dumps({"ok": True, "every": fleet_every(), "space": cur.get("space"), "track": cur.get("track"),
531
570
  "ships": cur.get("ships", {})}).encode())
532
- every = office_every()
571
+ every = fleet_every()
533
572
  # a page load: a quick pass when updating every minute, a full one otherwise; ⟳: always full
534
573
  quick = bool(req.get("quick")) or (bool(req.get("load")) and every == "minute")
535
- Handler.office_polled = time.time()
574
+ Handler.fleet_polled = time.time()
536
575
  if not quick:
537
- Handler.office_full = time.time()
538
- start_office_refresh(quick=quick)
576
+ Handler.fleet_full = time.time()
577
+ start_fleet_refresh(quick=quick)
539
578
  return self.answer(200, json.dumps({"ok": True, "started": True, "every": every,
540
- "space": office_settings().get("space"), "track": office_settings().get("track"),
541
- "ships": clean_ships(office_settings().get("ships"))}).encode())
542
- if self.path == "/hv-office-action":
579
+ "space": fleet_settings().get("space"), "track": fleet_settings().get("track"),
580
+ "ships": clean_ships(fleet_settings().get("ships"))}).encode())
581
+ if self.path == "/hv-fleet-action":
543
582
  try:
544
583
  length = min(int(self.headers.get("Content-Length") or 0), 4096)
545
584
  req = json.loads(self.rfile.read(length) or b"{}")
546
- ok, msg = office_action(str(req.get("id") or req.get("pane") or ""), str(req.get("action", "")),
585
+ ok, msg = fleet_action(str(req.get("id") or req.get("pane") or ""), str(req.get("action", "")),
547
586
  str(req.get("session") or ""), str(req.get("path") or ""))
548
587
  except (ValueError, OSError, subprocess.SubprocessError) as e:
549
588
  ok, msg = False, str(e)[:200]
@@ -563,7 +602,23 @@ class Handler(http.server.SimpleHTTPRequestHandler):
563
602
  return self.answer(200, json.dumps(body).encode())
564
603
 
565
604
 
605
+ def migrate_legacy() -> None:
606
+ """The fleet page was called the agent office: move its saved files to their new names, once."""
607
+ old = "off" + "ice" # spelled apart so a search for the old name finds only this migration
608
+ for name, new in ((f"{old}-settings.json", FLEET_SETTINGS), (f"{old}-cache.json", STATE / "fleet-cache.json"),
609
+ (f"{old}.log", STATE / "fleet.log")):
610
+ src = STATE / name
611
+ try:
612
+ if src.is_file() and not new.exists():
613
+ src.rename(new)
614
+ except OSError:
615
+ pass
616
+ shutil.rmtree(STATE / f"{old}-run", ignore_errors=True) # an empty working folder, now fleet-run/
617
+ shutil.rmtree(REPORTS / old, ignore_errors=True) # the old page and data; fleet.py writes reports/fleet/
618
+
619
+
566
620
  def serve() -> int:
621
+ migrate_legacy()
567
622
  REPORTS.mkdir(parents=True, exist_ok=True)
568
623
  try:
569
624
  httpd = http.server.ThreadingHTTPServer(("127.0.0.1", PREFERRED_PORT), Handler)
@@ -579,27 +634,27 @@ def serve() -> int:
579
634
  httpd.shutdown()
580
635
  return
581
636
 
582
- def office_clock() -> None:
583
- """While an office page is open: a live pass every minute, a full re-summary every 5 minutes."""
637
+ def fleet_clock() -> None:
638
+ """While a fleet page is open: a live pass every minute, a full re-summary every 5 minutes."""
584
639
  while True:
585
640
  time.sleep(10)
586
- every = office_every()
587
- if every == "reload" or time.time() - Handler.office_polled > OFFICE_WATCHED:
641
+ every = fleet_every()
642
+ if every == "reload" or time.time() - Handler.fleet_polled > FLEET_WATCHED:
588
643
  continue
589
644
  try:
590
- age = time.time() - OFFICE_JSON.stat().st_mtime
645
+ age = time.time() - FLEET_JSON.stat().st_mtime
591
646
  except OSError:
592
- age = OFFICE_EVERY
593
- if time.time() - Handler.office_full >= FULL_EVERY.get(every, OFFICE_EVERY):
594
- Handler.office_full = time.time()
595
- start_office_refresh()
647
+ age = FLEET_EVERY
648
+ if time.time() - Handler.fleet_full >= FULL_EVERY.get(every, FLEET_EVERY):
649
+ Handler.fleet_full = time.time()
650
+ start_fleet_refresh()
596
651
  time.sleep(30) # give it time to write before checking the age again
597
- elif every == "minute" and age >= OFFICE_LIVE:
598
- start_office_refresh(quick=True)
652
+ elif every == "minute" and age >= FLEET_LIVE:
653
+ start_fleet_refresh(quick=True)
599
654
  time.sleep(20)
600
655
 
601
656
  threading.Thread(target=watchdog, daemon=True).start()
602
- threading.Thread(target=office_clock, daemon=True).start()
657
+ threading.Thread(target=fleet_clock, daemon=True).start()
603
658
  print(f"agent map pages: http://127.0.0.1:{port}/latest/agent-stats.html", flush=True)
604
659
  httpd.serve_forever()
605
660
  try: