/** * Daemon inbox pumps: the periodic mention + stranded-assignment poll and * the reconnect re-sync drain. Both used to be inline in startAgentLoop and * dominated daemon.ts; they only need a small deps bag (API client, config * getter, wake queue, settings cache). Split out of daemon.ts (line budget). */ import { TeamshareApi } from '../lib/api'; import { loadConfig } from '../lib/config'; import { type WakeEvent } from './wake-routing'; import type { SessionSettings } from './spawn'; /** Cadence of the periodic mention + stranded-assignment poll. */ export declare const MENTION_POLL_MS: number; /** Everything the two inbox pumps need from the daemon/agent loop. */ /** * Is this assigned task STRANDED — an agent should be working it and nobody * is? * * ONE predicate for BOTH recovery paths (the periodic stranded sweep and the * reconnect re-sync). They used to be two near-identical filters that drifted, * which is how a finished task stayed reachable from one and not the other. * * `open` is the "assignment never landed" case. `in_progress` is the bigger one: * the bridge moves a task `open -> in_progress` on pickup, so a run that dies * WITHOUT its cleanup (killed process, power loss, reboot) leaves the task * `in_progress` with no claim, no lock and no session — and both paths filtered * it out, so it stayed stuck until a human pressed "Run task". That is what * "a failed trigger must not leave the task stuck" means. * * Excluded, each for a reason: * - a CLAIMED task is being worked (a live run renews its lease), * - an OPEN QUESTION means the run paused to ask a human: it released its * claim on purpose (a live claim would block the answer's resume) and is * waiting for the Answer badge. Re-waking it starts a second session beside * the paused one and works the task without the answer it asked for, * - `autoRunSuspendedAt` = a human pressed Stop work (sticky), or repeated * harness failures, * - `combinedIntoId` = worked through the combined task, never on its own, * - an already-planned plan-mode task is never re-planned by recovery. * * Anything else (`resolved`/`closed`/`in_review`) is not stranded at all: only a * manual trigger may work it — see lib/task-work-gate.ts. */ export declare function isStrandedAssignedTask(task: Record): boolean; export interface InboxDeps { /** Authenticated API client for this agent (inbox fetches). */ api: TeamshareApi; /** Base URL so a fresh client can be built with `TeamshareApi.forAgent`. */ apiBase: string; agent: { agentId: string; apiKey: string; }; /** Fresh config getter - project links / wake rules apply live. */ config: () => ReturnType; wakeQueue: Map; recentSpawns: Map; gateWarned: Set; settingsByAgent: Map; } /** * Periodic mention poll (catches wakes lost while connected - WS emits are * best-effort, so a silent hiccup loses the wake until the next reconnect) * plus stranded-assignment recovery: open assigned tasks no session has * claimed yet. Queued/deferred/blocked outcomes stay unmarked so the next * cycle retries them. * * MENTION ID SEMANTICS (2026-09): on this path `mention.id` IS the hub's * AgentMention row id - the handle `/mentions/:id/trigger` claims and * `/mentions/:id/answer` closes - while `mention.targetId` is the underlying * chat message / comment id. The WS wake already carried `mentionId`; the poll * and the re-sync did not, so a mention delivered while the daemon was offline * or mid-blip was never claimed and never closed, and every reconnect replayed * it into a second session. Both now set it. */ /** * The ONE wake type an inbox mention is delivered as. * * Both the dedupe CHECK and the dedupe RECORD must use this exact string * (2026-11). They used to disagree - the check passed `mention.type` * (`"chat"` / `"comment"`) while the record used the wake type * (`"chat.mention"` / `"comment.mention"` / …) - so a delivered mention was * never seen as processed and every poll AND every reconnect re-spawned it, * including mentions that were already answered. Keep the surface resolution in * one place so the two sides cannot drift again. */ export type MentionWakeType = 'chat.mention' | 'comment.mention' | 'document.mention' | 'document.edit_request' | 'board.mention' | 'workflow.mention'; export declare function mentionWakeType(mention: { type?: unknown; documentId?: unknown; whiteboardId?: unknown; workflowId?: unknown; body?: unknown; }): MentionWakeType; export declare function pollInboxMentions(deps: InboxDeps): Promise; /** * Re-sync (IMP-562): a wake emitted while the socket was down is LOST * (nothing queues it server-side). On every (re)connect, drain the agent * inbox and re-wake for assigned tasks still open - the server-side claim * guard makes concurrent spawns safe. Also replays inbox.mentions (task + * document comment mentions) which used to be consumed and dropped. * A drain loop handles >50 item backlogs (server caps each bucket at 50). */ export declare function resyncInbox(deps: InboxDeps): void;