beadboard/src/components/sessions/sessions-header-logic.ts
zenchantlive 173937c1f3 chore: add utility scripts and additional test coverage
STORY:
Development requires supporting scripts and comprehensive test coverage.
This commit adds utility scripts and extends test suites.

COLLABORATION:
- scripts/capture-sessions.mjs: Screenshot capture for sessions hub
- scripts/capture-timeline.mjs: Timeline view capture utility
- sessions-header-logic.ts: Session header business logic
- Additional test files for sessions, hooks, and snapshot diffing
2026-02-15 21:19:31 -08:00

47 lines
1.1 KiB
TypeScript

import type { AgentRecord, AgentLiveness } from '../../lib/agent-registry';
export interface SwarmHealth {
status: 'active' | 'warning' | 'critical' | 'offline';
color: string;
}
export function getSwarmHealth(
members: AgentRecord[],
livenessMap: Record<string, AgentLiveness | string>
): SwarmHealth {
if (members.length === 0) {
return { status: 'offline', color: 'text-zinc-500' };
}
let hasStale = false;
let hasEvicted = false;
let allIdle = true;
for (const member of members) {
const liveness = livenessMap[member.agent_id] as AgentLiveness || 'active';
if (liveness !== 'idle') {
allIdle = false;
}
if (liveness === 'stale') {
hasStale = true;
} else if (liveness === 'evicted') {
hasEvicted = true;
}
}
if (allIdle) {
return { status: 'offline', color: 'text-zinc-500' };
}
if (hasEvicted) {
return { status: 'critical', color: 'text-rose-400' };
}
if (hasStale) {
return { status: 'warning', color: 'text-amber-400' };
}
return { status: 'active', color: 'text-emerald-400' };
}