Principle:23blocks OS Ai maestro Server Feed Aggregation
| Knowledge Sources | |
|---|---|
| Domains | Status_Presence, Real_Time_Feed |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
A server-side feed aggregation pattern that merges hook states (authoritative when fresh) with terminal activity timestamps (fallback), and broadcasts updates to all connected WebSocket clients.
Description
The `getActivity` function is the single server-side source of agent status. It merges the in-memory `sessionActivity` map (terminal output timestamps from `server.mjs`) with hook states read from working directories. The hook is the authority when it has a fresh report: it fires the moment a turn starts and ends, and when the agent blocks on the user. Terminal activity only decides for agents with no hook report (Codex, a plain shell).
`broadcastStatusUpdate` pushes each status change to all connected WebSocket status clients. The browser subscribes via the `/status` WebSocket channel and uses `useSyncExternalStore` to update React.
Usage
Use this principle when designing a real-time status feed where:
- Multiple signal sources (hook + terminal) must be merged with clear precedence
- Updates must be pushed to all connected clients (not polled)
- The hook is authoritative when fresh, with terminal as fallback
Theoretical Basis
The aggregation is a priority merge with fallback:
for each session:
hookState = getHookState(workingDir, TTL)
if hookState (fresh):
status = normalizeActivityStatus(hookState.status, hookState.notificationType)
else:
status = terminalIdle ? 'idle' : 'active'
// After approval: fresh terminal output means working again
if status == 'waiting' && freshTerminalAfter(hookState):
status = 'active'
The hook-priority rule ensures that Claude Code's status line redraws (which happen while idle) don't make an idle agent look busy. The terminal is only consulted when the hook is silent.