import { type WakeLaneInput } from './wake-lanes'; /** Mirrors the hub's `TRIGGER_META_MAX`. */ export declare const TRIGGER_MAX = 20; export interface OutboxTrigger { type: string; at: string; /** The identity the lane prefers - `taskId`, `runId`, `messageId`, ... */ entityId?: string | null; by?: { id: string; name: string; } | null; } export interface OutboxLane { lane: string; /** Last-write-wins payload: the newest thing the agent must act on. */ event: Record; priority: number; firstSeenAt: string; lastSeenAt: string; /** Every trigger folded into this lane, oldest first, capped. */ triggers: OutboxTrigger[]; /** Delivery attempts. A lane that keeps failing is dropped after this many. */ attempts: number; /** * Do not attempt this lane before this ISO time (2026-11). * * Exists for the "skipped but still owes a human an answer" case: a lane that * was skipped because another session was handling the mention must be * retried AFTER that session ends, not dropped. A backoff keeps the retry out * of the next 30-second tick without losing the obligation. */ retryAfter?: string; } /** Read one agent's outbox. A corrupt file yields an empty queue, never throws. */ export declare function readOutbox(agentId: string): OutboxLane[]; /** * Drain order: highest priority first, then oldest lane first within a band. * * Priority first is the fix for a starvation bug - a `session.stop` queued for an * agent that had been offline sat behind every stale chat mention ever queued for * it. `session.stop` is its own lane at priority 100 and goes out first. */ export declare function sortLanes(lanes: OutboxLane[]): OutboxLane[]; /** * Add a wake to the outbox, coalescing on its lane. * * Returns the lane it landed in. A wake with NO lane is refused rather than * bucketed: two identity-less wakes are indistinguishable, and a shared bucket * would drop one of them. The hub refuses those too (`PendingWakeService.enqueue`), * so the two sides behave identically - the wake is simply not queued, and the * live path still emitted it. * * Accepts any structurally-lane-shaped event (not `Record`): * `WakeEvent` is an interface with no index signature, so an index-signature * parameter would reject every real caller for no benefit. The payload is stored * opaquely and only ever read back out as a wake event. */ export declare function enqueueOutbox(agentId: string, event: WakeLaneInput & { type: string; }): OutboxLane | null; /** Remove one lane (it was delivered, or must never run again). */ export declare function removeLane(agentId: string, lane: string): void; /** * The mention ids a lane still owes an answer for. * * Exists so the drain can SAY something before it drops a lane that carried a * human request. `daemon.ts` removes a lane on `'skipped'` as well as on * `'spawned'`, and a skip is exactly when a mention can be discarded unread - so * the drop is logged loudly rather than being made conditional. It is * deliberately NOT a veto: refusing to clear the lane would wedge the queue * behind a mention the agent will never read, which is the same silence with a * different shape. The hub's `PendingWake` row still holds these ids and stays * reclaimable, so the request is recoverable rather than lost. */ export declare function laneMentionIds(lane: OutboxLane | null | undefined): string[]; /** * Record a failed attempt, dropping the lane after `maxAttempts`. * * Dropping is deliberate and loud: the hub's `PendingWake` keeps its own copy * with a DEAD-LETTER state, so the work is still recorded there after it stops * being retried from here. The alternative - retrying forever - is what the old * sweep did. */ export declare function noteAttempt(agentId: string, lane: string, maxAttempts?: number): OutboxLane | null; /** * Put a lane back with a BACKOFF instead of dropping it (2026-11). * * WHY: `daemon.ts` removed a lane on `'skipped'` as well as on `'spawned'`, and * a skip is exactly when a human request can be discarded unread. The live case * (Aga Autos): a chat run was stopped while it owed two mentions; the drain * skipped the lane because the newest mention was "already being handled" by * the session that had just been killed, dropped the lane, and nothing retried * it. The hub row survived but the bridge had forgotten the obligation. * * A skipped lane is therefore DEFERRED, not dropped: the mention is retried * after the session that held it has ended, and the attempt budget (default 3) * still guarantees a permanently un-claimable mention cannot spin forever. * * Returns null when the lane has exhausted its attempts and was removed. */ export declare function deferLane(agentId: string, lane: string, delayMs: number, maxAttempts?: number): OutboxLane | null; /** True when a lane's backoff has not elapsed yet. */ export declare function laneDeferred(lane: OutboxLane, now?: number): boolean; /** Queued lane count, for `/ping` and `bridge-state`. */ /** * Drop EVERY queued lane for an agent (2026-11). * * Used by `teamshare-agent stop`: a lane-keyed outbox is durable on purpose, so * a human's stop must empty it or the very next drain re-spawns the work that * was just stopped. */ export declare function clearOutbox(agentId: string): number; export declare function outboxDepth(agentId: string): number; /** Queued trigger count - what the human actually asked about. */ export declare function outboxTriggerCount(agentId: string): number; /** Every agent with an outbox file, for the daemon boot log and `doctor`. */ export declare function listOutboxAgentIds(): string[];