@hivey/cli 0.9.84 → 0.9.85

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.84",
3
+ "version": "0.9.85",
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",
@@ -65,7 +65,24 @@ IDLE_SECONDS = 2 * 3600
65
65
  PING = "/hv-ping"
66
66
  LEGACY_PAGE = "/office" # the fleet page's address before it was renamed; redirected to /fleet/
67
67
  MARK = b"hivey-agent-map"
68
- VERSION = b"fleet-19" # bump when the server gains actions, so `ensure` replaces an older one
68
+
69
+
70
+ def code_stamp() -> str:
71
+ """A short hash of the server's Python files: a `hivey update` that changes any of them changes it."""
72
+ import hashlib
73
+ h = hashlib.sha1()
74
+ for f in sorted(SCRIPTS.glob("*.py")):
75
+ try:
76
+ h.update(f.name.encode() + f.read_bytes())
77
+ except OSError:
78
+ pass
79
+ return h.hexdigest()[:10]
80
+
81
+
82
+ # `ensure` replaces a server whose version differs, and a running server restarts itself once its files change
83
+ # (bump the number when the server gains actions; the code hash catches every other change)
84
+ STAMP = code_stamp()
85
+ VERSION = b"fleet-19-" + STAMP.encode()
69
86
  FLEET_EVERY = 300 # seconds between full fleet refreshes (every terminal re-summarized) while its page is open
70
87
  FLEET_LIVE = 60 # seconds between live passes (status, context, screen; only changed statuses summarized)
71
88
  FLEET_WATCHED = 600 # the page counts as open for this long after its last poll
@@ -720,16 +737,26 @@ def serve() -> int:
720
737
  migrate_legacy()
721
738
  REPORTS.mkdir(parents=True, exist_ok=True)
722
739
  try:
723
- httpd = http.server.ThreadingHTTPServer(("127.0.0.1", PREFERRED_PORT), Handler)
740
+ # a restart after an update keeps its port, so open pages keep talking to it
741
+ httpd = http.server.ThreadingHTTPServer(("127.0.0.1", int(os.environ.pop("HV_AGENT_MAP_PORT", "") or PREFERRED_PORT)),
742
+ Handler)
724
743
  except OSError: # taken: any free port
725
744
  httpd = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
726
745
  port = httpd.server_address[1]
727
746
  INFO.write_text(json.dumps({"port": port, "pid": os.getpid(), "hivey": hivey_bin()}))
728
747
 
748
+ restart = threading.Event()
749
+
729
750
  def watchdog() -> None:
730
751
  while True:
731
752
  time.sleep(60)
732
- if time.time() - Handler.last_used > IDLE_SECONDS and not Handler.busy.locked():
753
+ if Handler.busy.locked():
754
+ continue
755
+ if time.time() - Handler.last_used > IDLE_SECONDS:
756
+ httpd.shutdown()
757
+ return
758
+ if code_stamp() != STAMP: # a hivey update changed the scripts: restart on the new code
759
+ restart.set()
733
760
  httpd.shutdown()
734
761
  return
735
762
 
@@ -756,6 +783,11 @@ def serve() -> int:
756
783
  threading.Thread(target=fleet_clock, daemon=True).start()
757
784
  print(f"agent map pages: http://127.0.0.1:{port}/latest/agent-stats.html", flush=True)
758
785
  httpd.serve_forever()
786
+ httpd.server_close()
787
+ if restart.is_set(): # same port and pid: open pages keep working and pick up the new code
788
+ print("agent map server: its scripts changed (hivey update), restarting", flush=True)
789
+ os.environ["HV_AGENT_MAP_PORT"] = str(port)
790
+ os.execv(sys.executable, [sys.executable, "-I", str(SCRIPTS / "agent_map.py"), "serve"])
759
791
  try:
760
792
  if json.loads(INFO.read_text()).get("pid") == os.getpid():
761
793
  INFO.unlink()