Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Agent Presence

From Leeroopedia
Knowledge Sources
Domains Status_Presence
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for normalizing agent status into a shared vocabulary (working / needs-you / ready / offline), provided by AI Maestro's `lib/agent-presence.ts` and `hooks/useSessionActivity.ts`.

Description

The agent-presence module is the one place that maps raw hook statuses and notification types into the sidebar vocabulary. It exposes:

  • claimsActivity — does a hook status say anything about what the agent is doing right now?
  • hookNeedsYou — is this hook report the agent blocked on the user (permission request or elicitation dialog)?
  • normalizeActivityStatus — any status word → 'active' | 'waiting' | 'idle'
  • presenceFrom — full presence value from online flag + activity + hook state
  • PRESENCE_STYLE — the visual style (dot, text, ring, line colours) for each presence value

The useSessionActivity hook is the single browser store. It uses `useSyncExternalStore` (React 18) to subscribe to the `/status` WebSocket, and exposes presenceOf(agent) which every view reads via the hook. No view computes status from its own data.

Usage

  • Call `presenceOf(agent)` from any React component that renders agent status — read it from `useSessionActivity()`.
  • Call `normalizeActivityStatus` or `hookNeedsYou` on the server when building the activity feed.
  • Use `PRESENCE_STYLE[presence]` to get the visual classes for a presence value.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/agent-presence.ts (L35-58, L60-80, L96-129), hooks/useSessionActivity.ts (L229-264)
  • Supporting: lib/transcript-codex.mjs (codexLiveStatusFromFile), lib/observed-permission.mjs (observedPermissionVerdict)

Signature

export function claimsActivity(hookStatus?: string | null): boolean

export function hookNeedsYou(
  hookStatus?: string | null,
  notificationType?: string | null
): boolean

export function normalizeActivityStatus(
  status?: string | null,
  notificationType?: string | null
): 'active' | 'waiting' | 'idle'

export function presenceFrom(opts: {
  online: boolean
  activity?: string | null
  hookStatus?: string | null
  notificationType?: string | null
}): AgentPresence

export const PRESENCE_STYLE: Record<AgentPresence, PresenceStyle>

// In hooks/useSessionActivity.ts:
export function useSessionActivity(): {
  activity: Record<string, SessionActivityInfo>
  snapshots: SnapshotMap
  presenceOf: (agent: PresenceSubject, opts?: { online?: boolean }) => AgentPresence
  snapshotOf: (agent: ...) => StatusSnapshot | null
  loading: boolean
  error: string | null
  connected: boolean
}

export type AgentPresence = 'working' | 'needs-you' | 'ready' | 'offline'

Import

import { normalizeActivityStatus, hookNeedsYou, presenceFrom, PRESENCE_STYLE } from '@/lib/agent-presence'
import { useSessionActivity } from '@/hooks/useSessionActivity'

I/O Contract

Inputs

Name Type Required Description
hookStatus null No Raw hook status word
notificationType null No Hook notification type
online boolean Yes (presenceFrom) Whether the session is live
agent PresenceSubject Yes (presenceOf) Agent with id/name/session

Outputs

Name Type Description
claimsActivity() returns boolean true unless 'ended' or 'started'
hookNeedsYou() returns boolean true if permission_request or waiting_for_input with blocking notification
normalizeActivityStatus() returns 'waiting' \| 'idle' Normalised status
presenceFrom() returns AgentPresence working, needs-you, ready, or offline

Usage Examples

Read presence in a React component

import { useSessionActivity } from '@/hooks/useSessionActivity'
import { PRESENCE_STYLE } from '@/lib/agent-presence'

function AgentBadge({ agent }) {
  const { presenceOf } = useSessionActivity()
  const presence = presenceOf(agent, { online: true })
  const style = PRESENCE_STYLE[presence]

  return (
    <div className={style.dot}>
      <span className={style.text}>{style.label}</span>
    </div>
  )
}

Normalise a raw hook status on the server

import { normalizeActivityStatus, hookNeedsYou } from '@/lib/agent-presence'

const normalized = normalizeActivityStatus(hookState.status, hookState.notificationType)
const blocked = hookNeedsYou(hookState.status, hookState.notificationType)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment