@hivey/cli 0.9.83 β†’ 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.83",
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",
@@ -228,7 +228,8 @@ each swarm's coordinator get a desk; a swarm's workers and critics stand beside
228
228
  with the token added as a query parameter (`token_param`, default `token`), so the page never holds tokens; the
229
229
  dashboard trades it for its own session cookie (token login: hivey-dashboards skill, `references/token-login.md`).
230
230
  A site that sends you to another site first (a hosting login wall) or forbids framing shows why and an Open in
231
- tab button.
231
+ tab button. Each dashboard's `open` is `""` (inside the page) or `"tab"` (clicking it in the list opens a new
232
+ browser tab, no frame; form Open β†’ in a new tab, or `--open tab|page`); new claude.ai links default to a tab.
232
233
  - **CEO**: the space named `ceo` gets the captain's bridge, its own room in the ship's nose (gold trim, main
233
234
  viewscreen); its master sits at the captain's console.
234
235
 
@@ -1,6 +1,6 @@
1
1
  """The dashboards your agents keep: one list, shown on the fleet page's πŸ–₯ Dashboards tab.
2
2
 
3
- Each entry is {"id", "name", "url", "agent", "note", "token", "token_param"}; they live in
3
+ Each entry is {"id", "name", "url", "agent", "note", "token", "token_param", "open"}; they live in
4
4
  ~/.hivey/agent-map/fleet-settings.json (owner-only) under "dashboards", so every browser sees the same list.
5
5
  The page lists them on the left and shows the one you pick in a frame on the right; it adds, edits and
6
6
  removes them (POST /hv-fleet-settings {"dashboards": [...]}). An agent that builds or deploys a dashboard
@@ -48,7 +48,8 @@ MAX = 100
48
48
  LIMITS = {"name": 80, "url": 2000, "agent": 80, "note": 300}
49
49
  DEFAULT = "default" # the token value meaning "my default dashboard token"
50
50
  PARAM = re.compile(r"^[A-Za-z0-9_.-]{1,64}$")
51
- FIELDS = ("name", "url", "agent", "note", "token", "token_param")
51
+ FIELDS = ("name", "url", "agent", "note", "token", "token_param", "open")
52
+ OPEN_MODES = ("", "tab") # "" shows it inside the fleet page, "tab" opens it straight in a new browser tab
52
53
  # Each known user's default dashboard token (their DASHBOARD_TOKEN_<USER> EnvSave key), used until they save
53
54
  # their own (`dashboard token es_…`, or the Edit form). Matched on the Mac login and full name. Anyone else
54
55
  # types theirs once in the form, and it is saved for next time.
@@ -94,6 +95,8 @@ def clean(items: object, old: list[dict] | None = None) -> list[dict]:
94
95
  e["token"] = str(token or "").strip()[:4000]
95
96
  param = str(d.get("token_param") or (prev.get("token_param") if "token_param" not in d else "") or "").strip()
96
97
  e["token_param"] = param if PARAM.match(param) else ""
98
+ mode = str(d["open"] if "open" in d else prev.get("open", "") or "").strip().lower()
99
+ e["open"] = mode if mode in OPEN_MODES else ""
97
100
  base = _slug(str(d.get("id") or "") or e["name"])
98
101
  i, n = base, 2
99
102
  while i in ids:
@@ -143,9 +146,13 @@ def _match(d: dict, key: str) -> bool:
143
146
  return k in (d["id"].lower(), d["name"].lower(), d["url"].lower().rstrip("/"), d["url"].lower())
144
147
 
145
148
 
146
- def _changes(name=None, url=None, agent=None, note=None, token=None, token_param=None) -> dict:
147
- ch = {k: v for k, v in dict(name=name, url=url, agent=agent, note=note, token=token, token_param=token_param).items()
148
- if v is not None}
149
+ def _changes(name=None, url=None, agent=None, note=None, token=None, token_param=None, open_in=None) -> dict:
150
+ ch = {k: v for k, v in dict(name=name, url=url, agent=agent, note=note, token=token, token_param=token_param,
151
+ open=open_in).items() if v is not None}
152
+ if "open" in ch:
153
+ ch["open"] = {"page": "", "frame": "", "inside": ""}.get(ch["open"].strip().lower(), ch["open"].strip().lower())
154
+ if ch["open"] not in OPEN_MODES:
155
+ raise ValueError(f"--open must be page or tab, not {open_in}")
149
156
  if "url" in ch and not valid_url(ch["url"]):
150
157
  raise ValueError(f"not an http(s) URL: {ch['url']}")
151
158
  if ch.get("token_param") and not PARAM.match(ch["token_param"]):
@@ -153,16 +160,24 @@ def _changes(name=None, url=None, agent=None, note=None, token=None, token_param
153
160
  return ch
154
161
 
155
162
 
163
+ def never_framed(url: str) -> bool:
164
+ """Sites known to refuse every frame, so a new dashboard there opens in a tab (claude.ai artifacts)."""
165
+ host = (urllib.parse.urlsplit(url).hostname or "").lower()
166
+ return host in ("claude.ai", "claude.site") or host.endswith((".claude.ai", ".claude.site"))
167
+
168
+
156
169
  def add(name: str, url: str, agent: str = "", note: str = "", token: str | None = None,
157
- token_param: str | None = None) -> dict:
158
- ch = _changes(name=name, url=url, agent=agent or None, note=note or None, token=token, token_param=token_param)
170
+ token_param: str | None = None, open_in: str | None = None) -> dict:
171
+ ch = _changes(name=name, url=url, agent=agent or None, note=note or None, token=token, token_param=token_param,
172
+ open_in=open_in)
159
173
  items = load()
160
174
  for i, d in enumerate(items):
161
175
  if _match(d, name) or _match(d, url.rstrip("/")):
162
176
  items[i] = {**d, **ch, "id": d["id"]}
163
177
  break
164
178
  else:
165
- items.append({"token": DEFAULT, **ch}) # a new dashboard logs in with your default token unless told not to
179
+ # a new dashboard logs in with your default token unless told not to; claude.ai never frames, so: a tab
180
+ items.append({"token": DEFAULT, "open": "tab" if never_framed(url) else "", **ch})
166
181
  saved = save(items)
167
182
  return next(d for d in saved if d["url"] == url or d["name"] == name)
168
183
 
@@ -307,6 +322,8 @@ def main(argv: list[str] | None = None) -> int:
307
322
  p.add_argument("--token-param", help="the query parameter the dashboard reads it from (default token)")
308
323
  p.add_argument("--no-token", dest="token", action="store_const", const="",
309
324
  help="it needs no login token (a new dashboard uses your default token otherwise)")
325
+ p.add_argument("--open", choices=("page", "tab"),
326
+ help="page: show it inside the fleet page (default); tab: clicking it opens a new browser tab")
310
327
 
311
328
  a = sub.add_parser("add", help="add a dashboard (or update the one with this name or URL)")
312
329
  a.add_argument("name")
@@ -316,7 +333,7 @@ def main(argv: list[str] | None = None) -> int:
316
333
  login_args(a)
317
334
  ls = sub.add_parser("list")
318
335
  ls.add_argument("--json", action="store_true")
319
- ed = sub.add_parser("edit", help="change a dashboard's name, URL, agent, note or token")
336
+ ed = sub.add_parser("edit", help="change a dashboard's name, URL, agent, note, token or where it opens")
320
337
  ed.add_argument("key", help="name, id or URL")
321
338
  for f in ("name", "url", "agent", "note"):
322
339
  ed.add_argument(f"--{f}")
@@ -338,16 +355,16 @@ def main(argv: list[str] | None = None) -> int:
338
355
  return 0
339
356
  try:
340
357
  if args.cmd == "add":
341
- d = add(args.name, args.url, args.agent, args.note, args.token, args.token_param)
342
- print(f"saved {d['name']} β†’ {d['url']}{' (with login token)' if d['token'] else ''} (fleet page β†’ πŸ–₯ Dashboards)")
358
+ d = add(args.name, args.url, args.agent, args.note, args.token, args.token_param, args.open)
359
+ print(f"saved {d['name']} β†’ {d['url']}{' (with login token)' if d['token'] else ''}{' (opens in a new tab)' if d['open'] else ''} (fleet page β†’ πŸ–₯ Dashboards)")
343
360
  return 0
344
361
  if args.cmd == "edit":
345
362
  d = edit(args.key, name=args.name, url=args.url, agent=args.agent, note=args.note, token=args.token,
346
- token_param=args.token_param)
363
+ token_param=args.token_param, open_in=args.open)
347
364
  if not d:
348
365
  print(f"dashboards: no dashboard named {args.key}", file=sys.stderr)
349
366
  return 1
350
- print(f"saved {d['name']} β†’ {d['url']}{' (with login token)' if d['token'] else ''}")
367
+ print(f"saved {d['name']} β†’ {d['url']}{' (with login token)' if d['token'] else ''}{' (opens in a new tab)' if d['open'] else ''}")
351
368
  return 0
352
369
  except ValueError as e:
353
370
  print(f"dashboards: {e}", file=sys.stderr)
@@ -359,7 +376,7 @@ def main(argv: list[str] | None = None) -> int:
359
376
  else:
360
377
  for d in items:
361
378
  print(f"{d['name']:<28} {d['url']}" + (f" [{d['agent']}]" if d["agent"] else "")
362
- + (f" πŸ”‘ {d['login']}" if d["login"] else ""))
379
+ + (f" πŸ”‘ {d['login']}" if d["login"] else "") + (" β†— tab" if d.get("open") == "tab" else ""))
363
380
  if not items:
364
381
  print("no dashboards yet (fleet page β†’ πŸ–₯ Dashboards β†’ + Add, or `hivey agent-map dashboard add NAME URL`)")
365
382
  return 0
@@ -1011,11 +1011,13 @@ function buildDash() {
1011
1011
  <div class="dlist" id="dlist"></div>
1012
1012
  <div class="dfoot">Agents add theirs: <code>hivey agent-map dashboard add NAME URL</code>, or ask any agent β€œadd this dashboard to the agent fleet”.</div></div>
1013
1013
  <div class="dmain"><div class="dbar" id="dbar"></div><div class="dview"><iframe id="dframe" title="Dashboard" referrerpolicy="no-referrer"></iframe><div class="dmsg" id="dmsg" hidden></div></div></div>`;
1014
- $('#dadd').onclick = () => { $('#dmsg').innerHTML = ''; dashForm = { name: '', url: '', agent: '', note: '', token: '' }; dashArm = false; renderDash(); $('#dmsg input')?.focus(); };
1014
+ $('#dadd').onclick = () => { $('#dmsg').innerHTML = ''; dashForm = { name: '', url: '', agent: '', note: '', token: '', open: '' }; dashArm = false; renderDash(); $('#dmsg input')?.focus(); };
1015
1015
  $('#dlist').onclick = e => {
1016
1016
  const it = e.target.closest('.ditem');
1017
1017
  if (!it) return;
1018
1018
  ui.dash = it.dataset.id; saveDashSel(); dashForm = null; dashArm = false; renderDash();
1019
+ const d = (dashes || []).find(x => x.id === it.dataset.id);
1020
+ if (d && d.open === 'tab') window.open(dashOpenUrl(d), '_blank', 'noopener');
1019
1021
  };
1020
1022
  dashBuilt = true;
1021
1023
  $('#dash').classList.toggle('fold', localStorage.getItem('hv-fleet-dash-fold') === '1');
@@ -1040,6 +1042,9 @@ function dashFormHtml(f) {
1040
1042
  <label>URL</label><input type="url" name="url" value="${esc(f.url)}" placeholder="https://…" required>
1041
1043
  <label>Agent</label><input type="text" name="agent" value="${esc(f.agent)}" placeholder="the agent that keeps it (optional)">
1042
1044
  <label>Note</label><input type="text" name="note" value="${esc(f.note)}" placeholder="what it shows (optional)">
1045
+ <label>Open</label><span class="chk" style="grid-column:auto;flex-wrap:wrap;gap:12px" title="A new tab is quicker for sites that refuse to be shown inside other pages (claude.ai artifacts, many logins)">
1046
+ <label class="chk" style="grid-column:auto"><input type="radio" name="open" value="" ${f.open !== 'tab' ? 'checked' : ''}> inside this page</label>
1047
+ <label class="chk" style="grid-column:auto"><input type="radio" name="open" value="tab" ${f.open === 'tab' ? 'checked' : ''}> in a new tab</label></span>
1043
1048
  <label>Login</label><span class="chk" style="grid-column:auto;flex-wrap:wrap;gap:12px">
1044
1049
  <label class="chk" style="grid-column:auto" title="Untick for a dashboard that opens without a token"><input type="checkbox" name="uselogin" ${use ? 'checked' : ''}> login token</label>
1045
1050
  ${use ? `<label class="chk" style="grid-column:auto"><input type="radio" name="mode" value="default" ${mode === 'default' ? 'checked' : ''}> my dashboard token</label>
@@ -1071,9 +1076,9 @@ function renderDash() {
1071
1076
  const tip = !s ? 'checking…' : !s.ok ? `not answering: ${s.error || s.code}` : s.elsewhere ? `sends you to ${s.elsewhere} (a login wall?)`
1072
1077
  : s.frame === false ? 'opens only in a new tab' : `up Β· ${s.code} Β· ${s.ms} ms`;
1073
1078
  let origin = ''; try { origin = new URL(d.url).origin; } catch { }
1074
- return `<div class="ditem ${d.id === ui.dash && !(dashForm && !dashForm.id) ? 'sel' : ''}" data-id="${esc(d.id)}" title="${esc(d.note || d.url)}">
1079
+ return `<div class="ditem ${d.id === ui.dash && !(dashForm && !dashForm.id) ? 'sel' : ''}" data-id="${esc(d.id)}" title="${esc((d.note || d.url) + (d.open === 'tab' ? ' Β· click: opens in a new tab' : ''))}">
1075
1080
  <div class="fav">${origin ? `<img src="${esc(origin)}/favicon.ico" alt="" onerror="this.replaceWith('πŸ–₯')">` : 'πŸ–₯'}</div>
1076
- <div class="tx"><div class="nm"><span class="dot ${cls}" title="${esc(tip)}"></span>${esc(d.name)}${d.login ? ' <span title="opens with its login token">πŸ”‘</span>' : ''}</div>
1081
+ <div class="tx"><div class="nm"><span class="dot ${cls}" title="${esc(tip)}"></span>${esc(d.name)}${d.login ? ' <span title="opens with its login token">πŸ”‘</span>' : ''}${d.open === 'tab' ? ' <span title="opens in a new tab">β†—</span>' : ''}</div>
1077
1082
  <div class="host">${esc(d.agent ? 'πŸ€– ' + d.agent + ' Β· ' : '')}${esc(dashHost(d.url))}</div></div></div>`;
1078
1083
  }).join('');
1079
1084
  // the bar and the frame on the right
@@ -1099,6 +1104,13 @@ function renderDash() {
1099
1104
  $('#dtab').onclick = () => window.open(dashOpenUrl(cur), '_blank', 'noopener');
1100
1105
  $('#dedit').onclick = () => { dashForm = { ...cur }; renderDash(); };
1101
1106
  $('#ddel').onclick = () => { if (!dashArm) { dashArm = true; renderDash(); return; } saveDash(list.filter(x => x.id !== cur.id), `Removed ${cur.name}`); };
1107
+ if (cur.open === 'tab') { // set to open in a new tab: the click on the list opened it; no frame, no frame error
1108
+ msg.hidden = false;
1109
+ msg.innerHTML = `<div><b>${esc(cur.name)} opens in a new tab</b><br>Clicking it in the list opens it in a new browser tab. To show it here instead: Edit β†’ Open: inside this page.<br><button id="dtab2">Open it again β†—</button></div>`;
1110
+ $('#dtab2').onclick = () => window.open(dashOpenUrl(cur), '_blank', 'noopener');
1111
+ frame.removeAttribute('src'); frame.dataset.src = '';
1112
+ return;
1113
+ }
1102
1114
  const blocked = s && s.ok && s.frame === false;
1103
1115
  if (blocked) { // the site refuses to be shown inside another page (or Vercel's login does)
1104
1116
  msg.hidden = false;
@@ -1106,7 +1118,7 @@ function renderDash() {
1106
1118
  ? `It sends you to <b>${esc(s.elsewhere)}</b> first, a login page that refuses frames. Turn that hosting login off (for a Vercel project: Settings β†’ Deployment Protection) and give the dashboard token login instead (hivey-dashboards skill).`
1107
1119
  : /(^|\.)claude\.(ai|site)$/i.test(dashHost(cur.url))
1108
1120
  ? 'claude.ai artifacts can\'t be shown inside another page. Open it in a new tab instead.'
1109
- : 'The site does not allow being shown inside other pages (X-Frame-Options or frame-ancestors).'}<br><button id="dtab2">Open in a new tab β†—</button></div>`;
1121
+ : 'The site does not allow being shown inside other pages (X-Frame-Options or frame-ancestors).'}<br><span class="meta">Edit β†’ Open: in a new tab, and clicking it opens it straight away.</span><br><button id="dtab2">Open in a new tab β†—</button></div>`;
1110
1122
  $('#dtab2').onclick = () => window.open(dashOpenUrl(cur), '_blank', 'noopener');
1111
1123
  frame.removeAttribute('src'); frame.dataset.src = '';
1112
1124
  return;
@@ -1130,7 +1142,7 @@ function wireDashForm(list) {
1130
1142
  let url = v.url.trim();
1131
1143
  if (!/^https?:\/\//i.test(url)) url = 'https://' + url;
1132
1144
  try { new URL(url); } catch { toast('That URL does not look right'); return; }
1133
- const entry = { name: v.name.trim(), url, agent: v.agent.trim(), note: v.note.trim(), token_param: (v.token_param || '').trim() };
1145
+ const entry = { name: v.name.trim(), url, agent: v.agent.trim(), note: v.note.trim(), token_param: (v.token_param || '').trim(), open: v.open === 'tab' ? 'tab' : '' };
1134
1146
  if (!f.uselogin.checked) entry.token = '';
1135
1147
  else if (v.mode === 'default') entry.token = 'default';
1136
1148
  else if ((v.token || '').trim()) entry.token = v.token.trim(); // no "token" key: the server keeps the saved one
@@ -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()
@@ -59,6 +59,7 @@ hivey agent-map dashboard add "Trading dashboard" https://trading.example.app \
59
59
  hivey agent-map dashboard edit "Trading dashboard" --name "Paper trading" --url https://new.example.app
60
60
  hivey agent-map dashboard edit "Trading dashboard" --token default # or es_… for its own token, "" for none
61
61
  hivey agent-map dashboard add "Status page" https://status.example.app --no-token # opens without a login
62
+ hivey agent-map dashboard edit "Status page" --open tab # clicking it opens a new browser tab (--open page: back inside)
62
63
  hivey agent-map dashboard remove "Paper trading" # by name, id or URL; removes the card only
63
64
  hivey agent-map dashboard token # is a default dashboard token set?
64
65
  hivey agent-map dashboard token es_… # set it (the user's DASHBOARD_TOKEN_<USER> key)
@@ -84,6 +85,8 @@ hivey agent-map dashboard token es_… # set it (the user's DASHBO
84
85
  The page says why. "Sends you to another site": a hosting login wall (turn it off and use the token login);
85
86
  "does not allow being shown inside other pages": remove `X-Frame-Options` / `frame-ancestors` from the
86
87
  site. A red dot means the site did not answer, or its token could not be read.
87
- claude.ai artifact links (`claude.ai/artifact/…`, `claude.ai/public/artifacts/…`, `/embed` too) can never
88
- show in the frame (claude.ai sends `frame-ancestors 'self'`). Registering them is fine: the page says so and
89
- its "Open in a new tab" button opens them.
88
+ Each dashboard opens either inside the page (default) or in a new tab (form: Open β†’ in a new tab, or
89
+ `--open tab`): clicking a tab one in the list opens it straight away, with no frame and no frame error. Use a
90
+ tab for any site that refuses frames. claude.ai artifact links (`claude.ai/artifact/…`,
91
+ `claude.ai/public/artifacts/…`, `/embed` too) never show in a frame (`frame-ancestors 'self'`), so new ones
92
+ get a tab automatically.