Report stale local agent backends

This commit is contained in:
Codex committed 2026-07-07 16:04:40 -04:00
1 parent a122c567f1
commit fb0feb0028
2 files changed
+62 -17

No files matched your search

+18 -12
View File
@@ -17921,7 +17921,7 @@ IMPORTANT: This is an authorized security testing/red team platform. All operati
// ── Local agents: fetch ONCE before the backbone label so both reflect the server's
// actual agent state from the first poll (and t3mpPreferredAgent can route to a live one) ──
let __agents = [];
try { const s = await (await fetch(base + '/api/agents/local/status')).json(); __agents = s.connected || []; } catch (_) {}
try { const s = await (await fetch(base + '/api/agents/local/status?check=1')).json(); __agents = s.connected || []; } catch (_) {}
window.__t3mpServerAgents = __agents;
window.__t3mpConnectedAgents = __agents.length;
window.__t3mpLiveAgents = __agents.filter(a => a.lastPing && a.lastPing.ok).length;
@@ -17931,10 +17931,12 @@ IMPORTANT: This is an authorized security testing/red team platform. All operati
const key = (typeof getApiKey === 'function') ? (getApiKey() || '') : '';
let txt, color;
const serverLLM = !!(health && health.llm && health.llm.connected);
const staleAgents = __agents.filter(a => !a.lastPing || !a.lastPing.ok).length;
const hasBackend = !!(agent || key || serverLLM);
if (!key && agent) { txt = '⚡ ' + agent.toUpperCase() + ' · local, no key'; color = '#00ff88'; }
else if (key) { txt = (key.startsWith('sk-ant-') ? 'Anthropic' : key.startsWith('sk-or-') ? 'OpenRouter' : key.startsWith('sk-') ? 'OpenAI' : 'OpenRouter') + ' · your key'; color = '#0088ff'; }
else if (serverLLM) { txt = (health.llm.provider || 'server') + ' · server key'; color = '#0088ff'; }
else if (staleAgents) { txt = 'local agent stale — model unreachable'; color = '#ffaa00'; }
else { txt = 'none — connect agent / add key'; color = '#ff6b6b'; }
$('sysLLM').innerHTML = '<span style="color:'+color+'">'+txt+'</span>';
// Keyless hero callout: when NO backend is present (no agent, no key, no server LLM),
@@ -17959,7 +17961,11 @@ IMPORTANT: This is an authorized security testing/red team platform. All operati
// ── Local agents cell (reuse the state fetched above; keeps the stale-count latch fresh) ──
if ($('sysAgents')) {
$('sysAgents').innerHTML = __agents.length
? __agents.map(a => { const live = a.lastPing && a.lastPing.ok; return '<span style="color:'+(live?'#00ff88':'#ffaa00')+'">●</span><span style="color:#ccc">'+a.id+'</span>'; }).join('&nbsp;&nbsp;')
? __agents.map(a => {
const live = a.lastPing && a.lastPing.ok;
const err = a.lastPing && a.lastPing.error ? ' title="'+String(a.lastPing.error).replace(/"/g,'&quot;')+'"' : '';
return '<span'+err+'><span style="color:'+(live?'#00ff88':'#ffaa00')+'">●</span><span style="color:#ccc">'+a.id+'</span><span style="color:#777;font-weight:normal;font-size:10px">'+(live?' live':' stale')+'</span></span>';
}).join('&nbsp;&nbsp;')
: '<span style="color:#888;font-weight:normal">none — click to connect</span>';
}
// ── Drive the SitRep pipeline from /api/mission/status (sysPhases/sysFindings status cells were consolidated out) ──
@@ -24747,10 +24753,10 @@ Be specific and actionable. Format as structured JSON.`;
else if (!a.authed) { status='Not authed'; color='amber'; }
else if (stale) { status='⚠ Auth stale'; color='red'; }
else if (live) { status='● Live · '+ps.latencyMs+'ms'; color='green'; }
else if (connected) { status='● Active'; color='green'; }
else if (connected) { status='● Connected · unchecked'; color='amber'; }
else { status='Detected'; color='cyan'; }
const disabled = !a.ready;
const borderColor = stale ? 'rgba(255,80,80,0.4)' : (connected||live) ? 'rgba(0,255,136,0.35)' : 'rgba(0,200,255,0.14)';
const borderColor = stale ? 'rgba(255,80,80,0.4)' : live ? 'rgba(0,255,136,0.35)' : connected ? 'rgba(255,170,0,0.28)' : 'rgba(0,200,255,0.14)';
const sub = !a.installed ? 'binary not found on PATH'
: stale ? ('⚠ '+(ps.error ? ps.error.slice(0,70) : 'authentication failed — re-login this CLI'))
: (a.invokeHint || a.bin);
@@ -24786,10 +24792,10 @@ Be specific and actionable. Format as structured JSON.`;
const live = Object.keys(pingStatus).filter(function(k){return pingStatus[k].ok;}).length;
const sum = document.getElementById('localAgentsSummary');
if (sum) sum.innerHTML = connectedIds.length+' active'+(live?' · '+live+' live':'')+' · '+ready+' ready · '+installed+'/'+agents.length+' installed';
// expose for the War Room backend-gate, and dismiss the nudge once ANY agent is connected
// (a plain connect counts — not only a successful live-ping)
// expose live/connected counts separately. A plain connect is just a registration; only a
// fresh successful ping proves the local model is currently usable.
window.__t3mpLiveAgents = live; window.__t3mpConnectedAgents = connectedIds.length;
if (connectedIds.length > 0 || live > 0) { const nb = document.getElementById('noBackendNudge'); if (nb) nb.style.display = 'none'; }
if (live > 0) { const nb = document.getElementById('noBackendNudge'); if (nb) nb.style.display = 'none'; }
}
// ── remember connected agents + silently re-establish them after a refresh ──
@@ -24866,8 +24872,9 @@ Be specific and actionable. Format as structured JSON.`;
// _isStandalone (no API server) is NOT a backend — client-side mode still needs an API key.
// Counting it here let keyless standalone deploys bypass the "connect an agent / add a key"
// gate and silently fall through to a failing OpenRouter pipeline. A backend = a real LLM:
// the server's own LLM (llmAvailable) or a connected local agent.
return !!(api.llmAvailable || window.__t3mpLiveAgents > 0 || window.__t3mpConnectedAgents > 0);
// the server's own LLM (llmAvailable) or a live local agent. A connected-but-stale
// agent is not enough, because the underlying local model may have gone down.
return !!(api.llmAvailable || window.__t3mpLiveAgents > 0);
}
window.t3mpHasBackend = hasBackend;
// Pick the best connected agent to serve as the mission LLM backend: prefer a live-pinged one, and
@@ -24876,15 +24883,14 @@ Be specific and actionable. Format as structured JSON.`;
var order = ['codex','hermes','claude'];
var connected = (connectedIds || []).slice();
var live = connected.filter(function(id){ return pingStatus[id] && pingStatus[id].ok; });
var pool = live.length ? live : connected;
var pool = live;
// Fall back to the SERVER's reported agents (/api/agents/local/status, stashed by
// refreshSystemStatus). Without this, a War Room loaded without first visiting Settings has an
// empty client connectedIds and would route missions to a key-provider even though the server
// already has a live agent — the exact AI-backbone/mission-routing mismatch we want to avoid.
if (!pool.length && Array.isArray(window.__t3mpServerAgents)) {
var srv = window.__t3mpServerAgents.slice();
var srvLive = srv.filter(function(a){ return a.lastPing && a.lastPing.ok; });
pool = (srvLive.length ? srvLive : srv).map(function(a){ return a.id; });
pool = srv.filter(function(a){ return a.lastPing && a.lastPing.ok; }).map(function(a){ return a.id; });
}
pool.sort(function(a,b){ return order.indexOf(a) - order.indexOf(b); });
return pool[0] || null;