@hivey/cli 0.9.71 → 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.
- package/native/darwin-arm64/hivey +0 -0
- package/package.json +1 -1
- package/repo/skills/hivey-agent-map/SKILL.md +5 -1
- package/repo/skills/hivey-agent-map/scripts/agent_map.py +15 -5
- package/repo/skills/hivey-agent-map/scripts/enhance.py +17 -1
- package/repo/skills/hivey-agent-map/scripts/fleet/fleet.html +22 -1
- package/repo/skills/hivey-agent-map/scripts/fleet/fleet.js +48 -2
- package/repo/skills/hivey-agent-map/scripts/report.py +32 -5
- package/repo/skills/hivey-agent-map/scripts/serve.py +30 -1
|
Binary file
|
package/package.json
CHANGED
|
@@ -77,7 +77,10 @@ schemas, `finalize`, repair rules).
|
|
|
77
77
|
X content, radars, trading, research swarms). Draw only confirmed links, labelled with what flows
|
|
78
78
|
(≤ 17 characters: "top-20 tweets", "transcripts"). Fold the rest: a job that belongs to an agent
|
|
79
79
|
merges into it ("+ nightly 03:15" in its sublabel), many similar jobs become one node ("12 trading
|
|
80
|
-
jobs"), and unlinked housekeeping (git auto-commits, upgrades, purges)
|
|
80
|
+
jobs"), and unlinked housekeeping (git auto-commits, upgrades, purges) becomes one box ("8 housekeeping
|
|
81
|
+
jobs"). **Every scanned job is on the map**: its own box, a group box or its agent's box, listed in that
|
|
82
|
+
box's `map-meta.json` refs. The nightly run gives the model the jobs last night's map left out
|
|
83
|
+
(`enhance.jobs_off_map`), and the map page names any still missing under its legend.
|
|
81
84
|
**Node tags do not show at default zoom: put cost and status in the sublabel** ("$110 · posts → n8n",
|
|
82
85
|
"launchd 04:30 · exit 1"). Put an agent that shares no data at a free cell where no line crosses it.
|
|
83
86
|
Providers and totals go in cards (spend by provider and model, needs attention, spend gaps, not
|
|
@@ -108,6 +111,7 @@ hivey agent-map nightly [--model sonnet] # a full report now (also: --no-llm,
|
|
|
108
111
|
hivey agent-map schedule install [--at 06:30] [--model sonnet] # | remove | status
|
|
109
112
|
```
|
|
110
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).
|
|
111
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`,
|
|
112
116
|
`agent-map.html` and `agent-logs.html` from `~/.hivey/agent-map/reports/latest`.
|
|
113
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
|
-
|
|
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
|
-
|
|
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):
|
|
@@ -50,6 +50,7 @@ NAV_CSS = """
|
|
|
50
50
|
"""
|
|
51
51
|
|
|
52
52
|
MAP_CSS = """
|
|
53
|
+
.hv-off{margin-top:6px;padding-top:6px;border-top:1px solid rgba(127,127,127,.25);max-width:340px;line-height:1.35}
|
|
53
54
|
.hv-legend{position:fixed;left:14px;bottom:14px;z-index:40;padding:8px 10px;border-radius:10px;
|
|
54
55
|
font:12px/1.3 -apple-system,BlinkMacSystemFont,sans-serif;background:rgba(255,255,255,.92);color:#1d2330;
|
|
55
56
|
border:1px solid rgba(127,127,127,.3);box-shadow:0 2px 10px rgba(0,0,0,.08)}
|
|
@@ -264,6 +265,16 @@ new MutationObserver(refill).observe(document.body,{childList:true,subtree:true,
|
|
|
264
265
|
"""
|
|
265
266
|
|
|
266
267
|
|
|
268
|
+
def jobs_off_map(spec: dict, meta: dict, snap: dict) -> list[dict]:
|
|
269
|
+
"""The scanned jobs no map box stands for: a job is on the map when a box's map-meta refs list it,
|
|
270
|
+
or list the agent it belongs to (links_candidates.belongs_to). The nightly model gets this list
|
|
271
|
+
so new jobs reach the map, and the map page names any still missing."""
|
|
272
|
+
boxes = {str(n.get("id")) for n in spec.get("nodes") or []}
|
|
273
|
+
refs = {r for k, v in (meta.get("nodes") or {}).items() if k in boxes for r in (v or {}).get("refs") or []}
|
|
274
|
+
owner = {b.get("job"): b.get("agent") for b in (snap.get("links_candidates") or {}).get("belongs_to") or []}
|
|
275
|
+
return [j for j in snap.get("jobs") or [] if j.get("id") and j["id"] not in refs and owner.get(j["id"]) not in refs]
|
|
276
|
+
|
|
277
|
+
|
|
267
278
|
def enhance_folder(folder: Path, snap: dict, job_state) -> None:
|
|
268
279
|
generated, days = snap.get("generated", ""), snap.get("window_days", 7)
|
|
269
280
|
stats = folder / "agent-stats.html"
|
|
@@ -277,6 +288,11 @@ def enhance_folder(folder: Path, snap: dict, job_state) -> None:
|
|
|
277
288
|
except (OSError, ValueError):
|
|
278
289
|
meta = {}
|
|
279
290
|
data, top = node_data(snap, spec, meta, job_state)
|
|
291
|
+
off = jobs_off_map(spec, meta, snap)
|
|
292
|
+
off_note = (f'<div class="hv-off" title="{html.escape(", ".join(j["id"] for j in off))}">'
|
|
293
|
+
f'<b>Not on the map yet ({len(off)}):</b> {html.escape(", ".join(j.get("name") or j["id"] for j in off))}'
|
|
294
|
+
'<br><span style="opacity:.65">the next nightly run adds them; the Logs page has every job</span></div>'
|
|
295
|
+
if off else "")
|
|
280
296
|
stages = dict(STAGE_HELP)
|
|
281
297
|
stages.update({k.lower(): v for k, v in (meta.get("stages") or {}).items()})
|
|
282
298
|
script = (MAP_JS.replace("__DATA__", json.dumps(data)).replace("__STAGES__", json.dumps(stages))
|
|
@@ -284,5 +300,5 @@ def enhance_folder(folder: Path, snap: dict, job_state) -> None:
|
|
|
284
300
|
legend = (f'<div class="hv-legend"><b>Spend, last {span(days)}</b><div class="bar"></div>'
|
|
285
301
|
f'<div class="ends"><span>$0</span><span>{money(top)}</span></div>'
|
|
286
302
|
f'<div style="opacity:.65;margin-top:3px">click a box for what it does, tokens and models</div>'
|
|
287
|
-
f'<div style="opacity:.65">⚠️ its last run failed, was missed or logged errors</div
|
|
303
|
+
f'<div style="opacity:.65">⚠️ its last run failed, was missed or logged errors</div>{off_note}</div>')
|
|
288
304
|
page.write_text(inject(page.read_text(), NAV_CSS + MAP_CSS, nav("agent-map.html", generated, days) + legend, script))
|
|
@@ -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
|
-
|
|
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';
|
|
@@ -420,7 +420,14 @@ already built: do not touch stats.archify.md or agent-stats.html.
|
|
|
420
420
|
and keep a consumer agent (one a job feeds) without its interactive cost. Each node's sublabel holds
|
|
421
421
|
its schedule with its start time (a box folding several jobs shows the earliest: "cron from 00:30")
|
|
422
422
|
or its role, its models and its automated cost when it has one ("cron 04:15 · Grok + Sonnet ·
|
|
423
|
-
$0.40"); spend is usage.agents (automated only).
|
|
423
|
+
$0.40"); spend is usage.agents (automated only). EVERY job in snapshot.json "jobs" must be on the map:
|
|
424
|
+
in its own box, or folded into a box with related jobs (e.g. "5 git backups", "11 trading jobs", "4 X
|
|
425
|
+
jobs") or into the box of the agent it belongs to (links_candidates.belongs_to); map-meta.json refs
|
|
426
|
+
(step 3) list every job id a box stands for. Fold more when space runs out, never drop a job.
|
|
427
|
+
Never fold an agent or swarm into a job's box: a job that feeds its agent (a links_confirmed link)
|
|
428
|
+
gets its own box with an arrow into the agent's box; otherwise it merges into the agent's box,
|
|
429
|
+
named after the agent ("+ nightly 02:45" in its sublabel).
|
|
430
|
+
Keep at most 25 nodes on 5 stages x rows 0-4;
|
|
424
431
|
refresh the numbers in the cards (automated spend, models in use, needs attention).
|
|
425
432
|
3. Descriptions: every node in snapshot.json has a "description" (what it does). snapshot.json
|
|
426
433
|
"descriptions_to_write" lists the ids whose description is empty, cut off, copied from a brief
|
|
@@ -478,13 +485,30 @@ def set_token_command(command: str) -> int:
|
|
|
478
485
|
return 0
|
|
479
486
|
|
|
480
487
|
|
|
481
|
-
def
|
|
488
|
+
def off_map_task(prev: Path | None, snap: dict) -> str:
|
|
489
|
+
"""The map step's words for the scanned jobs last night's map leaves out (see enhance.jobs_off_map)."""
|
|
490
|
+
import enhance
|
|
491
|
+
try:
|
|
492
|
+
spec = json.loads((prev / "map.json").read_text()) if prev else {}
|
|
493
|
+
meta = json.loads((prev / "map-meta.json").read_text()) if prev else {}
|
|
494
|
+
except (OSError, ValueError):
|
|
495
|
+
spec, meta = {}, {}
|
|
496
|
+
off = enhance.jobs_off_map(spec, meta, snap) if spec else []
|
|
497
|
+
if not off:
|
|
498
|
+
return ""
|
|
499
|
+
lines = "\n".join(f" - {j['id']} ({j.get('schedule') or 'no schedule'}): {(j.get('description') or '')[:110]}"
|
|
500
|
+
for j in off)
|
|
501
|
+
return ("\n These scheduled jobs are not on the map yet; add every one of them:\n" + lines)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def run_llm(folder: Path, model: str, has_map: bool, prev: Path | None = None, snap: dict | None = None) -> bool:
|
|
482
505
|
claude = shutil.which("claude")
|
|
483
506
|
archify = archify_bin()
|
|
484
507
|
if not claude or not archify:
|
|
485
508
|
log(folder, "skipping the map update: claude or archify not found")
|
|
486
509
|
return False
|
|
487
|
-
task = ("map.json is last night's map: update it, adding nodes and flows for newly confirmed links
|
|
510
|
+
task = ("map.json is last night's map: update it, adding nodes and flows for newly confirmed links and "
|
|
511
|
+
"every scheduled job that is not on it yet." + off_map_task(prev, snap or {})
|
|
488
512
|
if has_map else "there is no map.json yet: write it following the skill's map rules.")
|
|
489
513
|
prompt = MAP_PROMPT.format(folder=folder, scripts=SCRIPTS, archify=archify, map_task=task)
|
|
490
514
|
tools = ("Read,Write,Edit,Glob,Grep,Bash(python3:*),Bash(node:*),Bash(ls:*),Bash(cat:*),"
|
|
@@ -600,13 +624,16 @@ def start_time_labels(spec: dict, meta: dict, snap: dict) -> dict[str, list[str]
|
|
|
600
624
|
owned: dict[str, list[str]] = {}
|
|
601
625
|
for b in (snap.get("links_candidates") or {}).get("belongs_to") or []:
|
|
602
626
|
owned.setdefault(b.get("agent", ""), []).append(b.get("job", ""))
|
|
627
|
+
boxes = {str(n.get("id")) for n in spec.get("nodes") or []}
|
|
628
|
+
own_box = {r for k, v in (meta.get("nodes") or {}).items() if k in boxes for r in (v or {}).get("refs") or [] if r in jobs}
|
|
603
629
|
out = {}
|
|
604
630
|
for n in spec.get("nodes") or []:
|
|
605
631
|
sub = str(n.get("sublabel", ""))
|
|
606
632
|
if n.get("type") == "database" or re.search(r"\b\d\d:\d\d\b", sub):
|
|
607
633
|
continue
|
|
608
634
|
refs = ((meta.get("nodes") or {}).get(n.get("id")) or {}).get("refs") or []
|
|
609
|
-
|
|
635
|
+
# an agent's box borrows the times of its jobs, except jobs drawn in a box of their own
|
|
636
|
+
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 and j not in own_box]
|
|
610
637
|
starts = [s for s in (job_start(jobs[j].get("schedule", "")) for j in dict.fromkeys(ids)) if s]
|
|
611
638
|
if not starts:
|
|
612
639
|
continue
|
|
@@ -686,7 +713,7 @@ def nightly(scan, days: int, model: str, use_llm: bool) -> int:
|
|
|
686
713
|
shutil.copy2(prev, folder / "map.json")
|
|
687
714
|
has_map = (folder / "map.json").is_file()
|
|
688
715
|
if use_llm:
|
|
689
|
-
run_llm(folder, model, has_map)
|
|
716
|
+
run_llm(folder, model, has_map, prev.parent if has_map and prev else None, snap)
|
|
690
717
|
if (folder / "map.json").is_file() and not html_current(folder, "agent-map.html", "map.json"):
|
|
691
718
|
good, why = finalize(folder, "dataflow", "map.json", "agent-map.html")
|
|
692
719
|
if not good and prev and prev.is_file(): # the model broke it: last night's map, unchanged
|
|
@@ -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-
|
|
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
|