@hivey/cli 0.9.73 โ†’ 0.9.74

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.73",
3
+ "version": "0.9.74",
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",
@@ -111,6 +111,7 @@ hivey agent-map nightly [--model sonnet] # a full report now (also: --no-llm,
111
111
  hivey agent-map schedule install [--at 06:30] [--model sonnet] # | remove | status
112
112
  ```
113
113
 
114
+ - **Failing jobs, live:** the fleet page asks `/hv-job-health` on load, every 5 minutes and when the Jobs tab opens (a jobs-only scan, ~0.1 s, no model). Jobs whose last run exited non-zero get a red count on the ๐Ÿ“Š Jobs tab, a "N scheduled jobs failing" chip in the top strip and a banner over the jobs pages (click a job: its error lines, log path and log tail); jobs not loaded, missed or with errors in an ok run are listed folded under "more to check". A run that exited non-zero keeps its error lines even when it ends with "All done!", and the one-line error is the line naming a cause (an HTTP status, `fatal:`, an exception).
114
115
  - **hivey menu โ†’ agent fleet โ†’ ๐Ÿ“Š Jobs tab** (key 4, or `/fleet/?view=jobs`) shows these pages inside the fleet page: the frame loads `/hv-jobs`, which the server redirects to the latest map (else stats, logs, sessions); with no report yet it starts the first build (`agent_map.py open --no-open`) and shows a page that reloads until it is ready. Every jobs page's navbar starts with ๐Ÿš€ Fleet (hidden inside the frame). `hivey agent-map open` still opens `agent-stats.html`,
115
116
  `agent-map.html` and `agent-logs.html` from `~/.hivey/agent-map/reports/latest`.
116
117
  - **hivey's layer on the archify pages** (`enhance.py`, after finalize; `agent_map.py enhance [folder]`
@@ -107,12 +107,18 @@ def log_path(command: str) -> str | None:
107
107
 
108
108
  def _is_err(line: str) -> bool:
109
109
  # "N Failed downloads:" is yfinance warning about delisted tickers, not a failed run
110
- return bool(re.search(r"error|traceback|exception|failed|fatal", line, re.I)
110
+ return bool(re.search(r"error|traceback|exception|failed|fatal|โœ—", line, re.I)
111
111
  and not re.search(r"\b0 failed|failed:? 0\b|0 errors?\b|errors?:? 0\b|rerun picks|failed downloads?:",
112
112
  line, re.I))
113
113
 
114
114
 
115
+ # an error line that names a cause (an HTTP status, a fatal git error, a Python exception...), preferred
116
+ # over headings like "Failed updates:" as the one-line reason a job failed
117
+ CAUSE_RE = re.compile(r"\b[45]\d\d\b|fatal|\w(Error|Exception)\b|denied|forbid|timed? ?out|not found|no such|"
118
+ r"unauthori[sz]ed|refused|could not|cannot|can't", re.I)
119
+
115
120
  # the first and last line of an uncaught Python traceback; an uncaught one always exits non-zero
121
+ TRACE_BODY_RE = re.compile(r'^\s*(raise\b|File "|~*\^)') # a traceback's source and caret lines
116
122
  CRASH_RE = re.compile(r"^\s*(Traceback \(most recent call last\)|[\w.]+(Error|Exception|Interrupt|Exit)\b)")
117
123
 
118
124
 
@@ -142,11 +148,14 @@ def log_info(path: str | None, exit_code: int | None = None) -> dict:
142
148
  # follows is history, not a current problem (a Baserow timeout stayed flagged after good runs)
143
149
  ok = re.compile(r"\b(success(ful(ly)?)?|succeeded|finished|completed?|done|wrote|all ok)\b", re.I)
144
150
  last_ok = max((i for i, l in enumerate(tail) if ok.search(l) and not _is_err(l)), default=-1)
145
- errs = [l.strip() for l in tail[last_ok + 1:] if _is_err(l)]
151
+ # a run that exited non-zero failed even if it printed "All done!" at the end (the nightly
152
+ # upgrade does): its error lines count wherever they are in the tail
153
+ errs = [l.strip() for l in tail[(0 if exit_code else last_ok + 1):] if _is_err(l)]
146
154
  if exit_code == 0: # the latest run exited 0, so any traceback still in the tail is from an earlier run
147
- errs = [l for l in errs if not CRASH_RE.match(l)]
155
+ errs = [l for l in errs if not CRASH_RE.match(l) and not TRACE_BODY_RE.match(l)]
148
156
  if errs:
149
- info["last_error"] = errs[-1][:200]
157
+ causes = [e for e in errs if CAUSE_RE.search(e) and not e.rstrip().endswith(":")]
158
+ info["last_error"] = (causes or errs)[-1][:200]
150
159
  info["errors"] = list(dict.fromkeys(e[:200] for e in errs))[-5:]
151
160
  info["tail"] = tail
152
161
  except OSError:
@@ -269,7 +278,8 @@ def launchd_jobs() -> list[dict]:
269
278
  jobs.append({
270
279
  "id": f"launchd:{label}", "name": re.sub(r"^com\.(jcsancho|hivey)\.", "", label), "kind": "launchd",
271
280
  "schedule": sched, "command": cmd, "agent": job_agent(cmd, d.get("WorkingDirectory")),
272
- "status": state, **log_info(d.get("StandardOutPath") or d.get("StandardErrorPath")),
281
+ "status": state, **log_info(d.get("StandardOutPath") or d.get("StandardErrorPath"),
282
+ int(code) if re.fullmatch(r"-?\d+", code) else None),
273
283
  })
274
284
  mod = jobs[-1].get("log_modified")
275
285
  if period_h and mod and dt.datetime.now() - dt.datetime.fromisoformat(mod) > dt.timedelta(hours=period_h):
@@ -155,6 +155,27 @@ main{position:relative}
155
155
  #jobs{display:none;background:#fff}
156
156
  #jobs iframe{display:block;width:100%;height:calc(100vh - 70px);border:0}
157
157
  body.v-jobs .search{visibility:hidden}
158
+ /* failing scheduled jobs, live from /hv-job-health: a banner over the jobs pages and a count on the tab */
159
+ #jobhealth{background:var(--bg);color:var(--text);padding:10px 18px;border-bottom:1px solid var(--line);max-height:46vh;overflow:auto}
160
+ #jobhealth:empty{display:none}
161
+ #jobhealth.ok{padding:6px 18px;color:var(--muted);font-size:12.5px}
162
+ #jobhealth h4{margin:0 0 6px;font-size:14px;color:var(--block)}
163
+ #jobhealth h4.soft{color:var(--honey);margin-top:10px}
164
+ #jobhealth details{border:1px solid rgba(251,113,133,.35);background:rgba(251,113,133,.07);border-radius:10px;margin:5px 0;font-size:12.5px}
165
+ #jobhealth details.soft{border-color:rgba(245,184,61,.3);background:rgba(245,184,61,.05)}
166
+ #jobhealth summary{cursor:pointer;padding:6px 10px;list-style:none;display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
167
+ #jobhealth summary::-webkit-details-marker{display:none}
168
+ #jobhealth summary b{white-space:nowrap}
169
+ #jobhealth summary .m{color:var(--muted);white-space:nowrap}
170
+ #jobhealth summary .e{color:#fecdd3;word-break:break-word}
171
+ #jobhealth details.soft summary .e{color:#fde68a}
172
+ #jobhealth .body{padding:0 10px 9px}
173
+ #jobhealth ul{margin:4px 0;padding-left:18px;color:#fecdd3}
174
+ #jobhealth pre{background:#0a0e15;border:1px solid var(--line);border-radius:8px;padding:8px;font:11px/1.35 ui-monospace,Menlo,monospace;
175
+ white-space:pre-wrap;max-height:220px;overflow:auto;color:#c9d4e3;margin:6px 0 0}
176
+ #views .jbad{margin-left:5px;padding:0 6px;border-radius:999px;background:var(--block);color:#1b0b10;font-size:11px;font-weight:700}
177
+ #views .jbad.soft{background:var(--honey)}
178
+ .ask.job{border-color:rgba(251,113,133,.5);cursor:pointer}
158
179
  #list{display:none;padding:12px 18px 40px}
159
180
  table{width:100%;border-collapse:collapse;font-size:12.5px}
160
181
  th{text-align:left;color:var(--muted);font-weight:600;padding:7px 8px;border-bottom:1px solid var(--line);cursor:pointer;white-space:nowrap;position:sticky;top:57px;background:var(--bg)}
@@ -247,7 +268,7 @@ td.j{max-width:420px}
247
268
  </section>
248
269
  <section id="board"></section>
249
270
  <section id="list"></section>
250
- <section id="jobs"><iframe id="jobsframe" title="Agent jobs"></iframe></section>
271
+ <section id="jobs"><div id="jobhealth"></div><iframe id="jobsframe" title="Agent jobs"></iframe></section>
251
272
  </main>
252
273
  <aside id="drawer"></aside>
253
274
  <div id="tip"></div>
@@ -26,6 +26,7 @@ let data = null, agents = [], selected = null;
26
26
  const ui = JSON.parse(localStorage.getItem('hv-fleet-ship') || localStorage.getItem('hv-' + 'off' + 'ice-ship') || '{}');
27
27
  ui.view ||= 'fleet';
28
28
  const VIEWS = ['fleet', 'board', 'list', 'jobs'];
29
+ let health = null, healthAt = 0; // failing scheduled jobs (pollHealth)
29
30
  { const v = new URLSearchParams(location.search).get('view'); if (VIEWS.includes(v)) ui.view = v; if (v) history.replaceState(null, '', location.pathname); } // ?view=jobs from the menu or a jobs page
30
31
  ui.filter ||= null;
31
32
  if (ui.toon === undefined) ui.toon = false;
@@ -219,10 +220,15 @@ function renderInbox() {
219
220
  const asked = agents.filter(a => !a.asleep && a.status !== 'blocked' && a.status !== 'working' && a.summary?.needs_you);
220
221
  const need = [...blocked, ...asked];
221
222
  const lead = [blocked.length ? `โœ‹ ${blocked.length} blocked` : '', asked.length ? `<span style="color:var(--honey)">๐Ÿ’ฌ ${asked.length} asked you</span>` : ''].filter(Boolean).join('<br>');
222
- $('#inbox').innerHTML = need.length ? `<span class="lead">${lead}</span>` + need.map(a =>
223
+ const failed = health?.failed || [];
224
+ const jobs = failed.length ? `<div class="ask job" id="jobchip" title="Open the Jobs tab: what failed and its log"><span class="em">โŒ</span>
225
+ <div class="t"><b>${failed.length} scheduled job${failed.length === 1 ? '' : 's'} failing</b>${esc(failed.slice(0, 3).map(j => j.name).join(', ') + (failed.length > 3 ? 'โ€ฆ' : ''))}</div><span class="go">jobs โ†—</span></div>` : '';
226
+ $('#inbox').innerHTML = (need.length ? `<span class="lead">${lead}</span>` + need.map(a =>
223
227
  `<div class="ask ${a.status === 'blocked' ? '' : 'soft'}" data-id="${esc(a.id)}" title="Click: open in hivey ยท right-click: details"><span class="em">${esc(a.emoji)}</span>
224
- <div class="t"><b>${esc(a.name)}</b>${esc(a.summary?.needs_you || a.summary?.bubble || 'waiting in its terminal')}</div><span class="go">open โ†—</span></div>`).join('') : '';
228
+ <div class="t"><b>${esc(a.name)}</b>${esc(a.summary?.needs_you || a.summary?.bubble || 'waiting in its terminal')}</div><span class="go">open โ†—</span></div>`).join('') : '') + jobs;
225
229
  wireActions($('#inbox'));
230
+ const chip = $('#jobchip');
231
+ if (chip) chip.onclick = () => { ui.view = 'jobs'; save(); renderAll(); };
226
232
  }
227
233
 
228
234
  // ---------------------------------------------------------------- board & list
@@ -948,6 +954,7 @@ function showJobs() {
948
954
  document.body.classList.toggle('v-jobs', on);
949
955
  $('#jobs').style.display = on ? 'block' : 'none';
950
956
  if (!on) return;
957
+ if (Date.now() - healthAt > 60000) pollHealth();
951
958
  if (!frame.dataset.loaded) { // an older page server has no /hv-jobs: the latest map straight away
952
959
  frame.dataset.loaded = '1';
953
960
  fetch('/hv-jobs', { cache: 'no-store' }).then(r => { frame.src = r.ok ? r.url : '/latest/agent-map.html'; })
@@ -955,6 +962,45 @@ function showJobs() {
955
962
  }
956
963
  fitJobs();
957
964
  }
965
+ // scheduled jobs that failed (non-zero exit) or need a check, live from the page server: a count on the
966
+ // Jobs tab, a chip in the top strip and a banner over the jobs pages (the nightly report is a day old)
967
+ async function pollHealth() {
968
+ healthAt = Date.now();
969
+ try {
970
+ const r = await fetch('/hv-job-health', { cache: 'no-store' });
971
+ if (!r.ok) return; // an older page server has no /hv-job-health
972
+ health = await r.json();
973
+ } catch { return; }
974
+ renderHealth();
975
+ renderInbox();
976
+ }
977
+ function healthRow(j, soft) {
978
+ const err = j.error || j.words || j.status;
979
+ const errs = (j.errors || []).filter(e => e !== j.error);
980
+ return `<details class="${soft ? 'soft' : ''}"><summary><b>${soft ? 'โš ๏ธ' : 'โŒ'} ${esc(j.name)}</b>
981
+ <span class="m">${esc(j.status)} ยท ${esc(j.kind.split(' ')[0])} ${esc(j.schedule)}${j.when ? ' ยท ' + esc(String(j.when).replace('T', ' ')) : ''}</span>
982
+ <span class="e">${esc(err)}</span></summary><div class="body">
983
+ ${errs.length ? `<ul>${errs.map(e => `<li>${esc(e)}</li>`).join('')}</ul>` : ''}
984
+ ${j.log ? `<div class="m">log: <code>${esc(j.log)}</code></div>` : '<div class="m">no log file</div>'}
985
+ ${j.tail?.length ? `<pre>${esc(j.tail.join('\n'))}</pre>` : ''}</div></details>`;
986
+ }
987
+ function renderHealth() {
988
+ const btn = document.querySelector('#views button[data-v="jobs"]'), box = $('#jobhealth');
989
+ if (!btn || !box || !health) return;
990
+ const failed = health.failed || [], check = health.check || [];
991
+ btn.innerHTML = '๐Ÿ“Š Jobs' + (failed.length ? `<span class="jbad" title="${failed.length} scheduled job(s) failed on their last run">${failed.length}</span>`
992
+ : check.length ? `<span class="jbad soft" title="${check.length} scheduled job(s) need a check">${check.length}</span>` : '');
993
+ const at = health.checked ? new Date(health.checked).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '';
994
+ box.classList.toggle('ok', health.ok && !failed.length && !check.length);
995
+ if (!health.ok) box.innerHTML = `<span class="err">Could not check the scheduled jobs: ${esc(health.error || '?')}</span>`;
996
+ else if (!failed.length && !check.length) box.innerHTML = `โœ… All ${health.total} scheduled jobs ran cleanly ยท checked ${at}`;
997
+ else box.innerHTML =
998
+ (failed.length ? `<h4>โŒ ${failed.length} scheduled job${failed.length === 1 ? '' : 's'} failed on the last run <span class="m" style="font-weight:400;color:var(--muted)">ยท checked ${at} ยท click one for its errors and log</span></h4>` + failed.map(j => healthRow(j, false)).join('') : '') +
999
+ (check.length ? `<details style="border:0;background:none"><summary><h4 class="soft" style="margin:6px 0 0">โš ๏ธ ${check.length} more to check (not loaded, missed a run, or errors in the log but exited ok)</h4></summary>` + check.map(j => healthRow(j, true)).join('') + '</details>' : '');
1000
+ fitJobs();
1001
+ }
1002
+ pollHealth();
1003
+ setInterval(pollHealth, 5 * 60 * 1000);
958
1004
  function fitJobs() {
959
1005
  const frame = $('#jobsframe');
960
1006
  if (ui.view === 'jobs') frame.style.height = Math.max(420, innerHeight - frame.getBoundingClientRect().top) + 'px';
@@ -8,6 +8,9 @@ trigger them:
8
8
  GET /hv-jobs the agent jobs pages for the fleet page's Jobs tab: a redirect to the latest
9
9
  map (else stats, logs, sessions); with no report yet it starts the first build
10
10
  (`agent_map.py open --no-open`) and answers a page that reloads until it is ready
11
+ GET /hv-job-health scheduled jobs whose latest run failed (non-zero exit) or needs a check (not
12
+ loaded, missed its run, errors in its log), from a jobs-only scan (~0.1 s, no
13
+ model), with each one's error lines and log tail: the Jobs tab's warnings
11
14
  POST /hv-refresh `agent_map.py refresh` (free: no model)
12
15
  GET /fleet/ the agent fleet page (files in reports/fleet/; old /fleet/ links redirect here)
13
16
  POST /hv-fleet-refresh `fleet.py run` in the background (the agent fleet, /fleet/)
@@ -56,7 +59,7 @@ IDLE_SECONDS = 2 * 3600
56
59
  PING = "/hv-ping"
57
60
  LEGACY_PAGE = "/office" # the fleet page's address before it was renamed; redirected to /fleet/
58
61
  MARK = b"hivey-agent-map"
59
- VERSION = b"fleet-16" # bump when the server gains actions, so `ensure` replaces an older one
62
+ VERSION = b"fleet-17" # bump when the server gains actions, so `ensure` replaces an older one
60
63
  FLEET_EVERY = 300 # seconds between full fleet refreshes (every terminal re-summarized) while its page is open
61
64
  FLEET_LIVE = 60 # seconds between live passes (status, context, screen; only changed statuses summarized)
62
65
  FLEET_WATCHED = 600 # the page counts as open for this long after its last poll
@@ -508,8 +511,34 @@ class Handler(http.server.SimpleHTTPRequestHandler):
508
511
  Handler.fleet_polled = time.time()
509
512
  if self.path.split("?")[0] == "/hv-jobs":
510
513
  return self.jobs()
514
+ if path == "/hv-job-health":
515
+ return self.job_health()
511
516
  return super().do_GET()
512
517
 
518
+ def job_health(self) -> None:
519
+ """Failing scheduled jobs, live (the nightly report is up to a day old)."""
520
+ port = self.server.server_address[1]
521
+ if self.headers.get("Host") not in (f"127.0.0.1:{port}", f"localhost:{port}"): # log tails stay local
522
+ return self.answer(403, b'{"ok":false,"error":"local pages only"}')
523
+ try:
524
+ import agent_map
525
+ import report
526
+ jobs = agent_map.cron_jobs() + agent_map.launchd_jobs()
527
+ except Exception as e: # a broken scan must not take the fleet page down
528
+ return self.answer(200, json.dumps({"ok": False, "error": str(e)[:300]}).encode())
529
+ out = {"ok": True, "checked": time.strftime("%Y-%m-%dT%H:%M"), "total": len(jobs), "failed": [], "check": []}
530
+ for j in jobs:
531
+ emo, words = report.job_state(j)
532
+ if emo not in ("โŒ", "โš ๏ธ"):
533
+ continue
534
+ failed = j.get("status", "").startswith("exit")
535
+ out["failed" if failed else "check"].append({
536
+ "name": j["name"], "kind": j["kind"], "schedule": j.get("schedule", ""), "status": j.get("status"),
537
+ "words": words, "error": j.get("last_error", ""), "errors": j.get("errors", []),
538
+ "log": j.get("log", ""), "when": j.get("last_run") or j.get("log_modified") or "",
539
+ "tail": (j.get("tail") or [])[-15:]})
540
+ return self.answer(200, json.dumps(out).encode())
541
+
513
542
  def jobs(self) -> None:
514
543
  """The fleet page's Jobs tab: the latest agent jobs page, or the first report being built."""
515
544
  import report