Implementation:23blocks OS Ai maestro Get Activity
| Knowledge Sources | |
|---|---|
| Domains | Status_Presence, Real_Time_Feed |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
Concrete tool for aggregating agent activity from hook states and terminal timestamps, provided by AI Maestro's `services/sessions-service.ts`.
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). The result is a map of session name → `SessionActivityInfo` that flows to the browser via the `/status` WebSocket channel.
broadcastStatusUpdate (in `services/shared-state-bridge.mjs`) pushes each status change to all connected WebSocket status clients. The `sessionActivity` Map (in `services/shared-state.ts`) is the module-level in-memory store of terminal activity timestamps.
Usage
- Call `getActivity` from the status API route or the status WebSocket to get all agents' current activity.
- Call `broadcastStatusUpdate` whenever a hook reports a status change or the activity monitor detects one.
- Read/write `sessionActivity` from `shared-state.ts` to record terminal output timestamps.
Code Reference
Source Location
- Repository: ai-maestro
- File: services/sessions-service.ts (L652-750), services/shared-state-bridge.mjs (L67-83), services/shared-state.ts (L115)
Signature
export async function getActivity(): Promise<Record<string, SessionActivityInfo>>
export function broadcastStatusUpdate(
sessionName: string,
status: string,
hookStatus: string,
notificationType: string,
agentId: string
): void
// Module-level export in shared-state.ts
export const sessionActivity: Map<string, number>
interface SessionActivityInfo {
lastActivity: string // ISO timestamp
status: 'active' | 'waiting' | 'idle'
hookStatus?: string
notificationType?: string
}
Import
import { getActivity } from '@/services/sessions-service'
import { broadcastStatusUpdate } from '@/services/shared-state-bridge.mjs'
import { sessionActivity } from '@/services/shared-state'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (getActivity) | (none) | — | Reads sessionActivity map + hook states from disk |
| sessionName | string | Yes (broadcast) | Tmux session name |
| status | string | Yes (broadcast) | Normalized status word |
| hookStatus | string | Yes (broadcast) | Raw hook status word |
Outputs
| Name | Type | Description |
|---|---|---|
| getActivity() returns | Record<string, SessionActivityInfo> | Map of session name → activity info |
| broadcastStatusUpdate() returns | void | Pushes JSON message to all WebSocket status subscribers |
Usage Examples
import { getActivity } from '@/services/sessions-service'
// Server status endpoint: return all agents' activity
export async function GET() {
const activity = await getActivity()
return Response.json(activity)
}