Implementation:23blocks OS Ai maestro Wake Chain
| Knowledge Sources | |
|---|---|
| Domains | Agent_Messaging, Wake_Notification |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
Concrete tool for delivering wake notifications through ordered wake routes with proven-arrival stopping, provided by AI Maestro's `lib/wake-chain.ts`.
Description
The runWakeChain function tries each wake adapter in order (streaming session, Claude Code channel, tmux pane, inbox sweeper, doorbell) and stops at the first one that PROVES arrival. `sent` and `deferred` do not stop the chain: an unproven or postponed wake is worth nothing to an agent that is waiting, and a duplicate nudge is cheaper than a lost message. A thrown adapter is recorded as `failed` and the chain continues.
The enqueueWake function (in `lib/wake-queue.ts`) queues a wake for an agent whose pane is busy. It holds the wake until the agent's idle transition, with a backoff for unconfirmed retries. One wake is delivered per idle tick — each pane send costs a readback.
The notifyAgent function (in `lib/notification-service.ts`) pushes text into the agent's tmux pane. The messageRef function generates an 8-char alphanumeric ref from a message ID for pane display correlation.
Usage
- Call `runWakeChain` from `deliver` to notify a recipient agent.
- Call `enqueueWake` when a wake is unconfirmed or the pane is busy.
- Call `messageRef` to generate the short ref for pane display.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/wake-chain.ts (L232-268), lib/wake-queue.ts (L126-149), lib/notification-service.ts (L160-163, L325-400)
Signature
export async function runWakeChain(
ctx: WakeContext,
adapters: WakeAdapter[] = DEFAULT_WAKE_CHAIN
): Promise<WakeResult>
export function enqueueWake(
item: Omit<QueuedWake, 'queuedAt' | 'reason' | 'attempts' | 'notBefore'> & {
reason?: WakeQueueReason
attempts?: number
}
): number
export async function notifyAgent(options: NotificationOptions): Promise<NotificationResult>
export function messageRef(messageId: string): string
interface WakeResult {
confirmed: boolean
notified: boolean
deferred: boolean
confirmedBy?: string
attempts: WakeOutcome[]
}
type WakeOutcome = {
adapter: string
status: 'confirmed' | 'sent' | 'deferred' | 'unavailable' | 'failed'
detail?: string
}
Import
import { runWakeChain } from '@/lib/wake-chain'
import { enqueueWake } from '@/lib/wake-queue'
import { notifyAgent, messageRef } from '@/lib/notification-service'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ctx.agentId | string | Yes | Recipient agent UUID |
| ctx.injectText | string | Yes | Wake notification text |
| ctx.messageId | string | Yes | AMP message ID for dedup |
| item.agentId | string | Yes (enqueue) | Agent to queue wake for |
| messageId | string | Yes (messageRef) | Full AMP message ID |
Outputs
| Name | Type | Description |
|---|---|---|
| runWakeChain() returns | WakeResult | confirmed/notified/deferred + per-route attempts |
| enqueueWake() returns | number | Queue depth for that agent after insertion |
| messageRef() returns | string | 8-char alphanumeric ref (e.g. 'msg17878') |
Usage Examples
import { runWakeChain } from '@/lib/wake-chain'
import { messageRef } from '@/lib/notification-service'
const result = await runWakeChain({
agentId: 'agent-uuid',
agentName: 'website',
injectText: '[AMP #msg17878] New message from api — "Deploy when ready"',
injectBody: 'Deploy when ready',
messageId: 'msg-uuid-1234',
})
if (result.confirmed) {
console.log(`Proven via ${result.confirmedBy}`)
} else {
console.log(`Unconfirmed: ${result.attempts.map(a => `${a.adapter}:${a.status}`).join(' → ')}`)
}