/** * In-process queue of pending agent-completion deliveries to the parent's * LLM context. * * Why: the agent status YAML on disk is the canonical persistence layer * (spec §5.5, §5.8), but the parent's runtime uses its own * `SessionManager` instance and does not read our writes from disk. To * surface a completion to the parent LLM we must inject it through the * extension API the parent's runtime actually reads from: * * - `pi.on("context", ...)` — fires before every LLM call. Drain the * queue and push synthetic user messages into `event.messages` so the * in-flight turn sees them. * - `pi.sendUserMessage` — fires a new user-message turn when the * session is idle, so the user actually sees the completion land in * their chat instead of only the next-turn LLM context. * * Both paths drain from the same queue. If a delivery fails (caller's * callback throws), the items are left untouched so the next pass tries * again. The queue is per-process and reset on session-boundary hooks. * * Persistent-agent contract (spec §5.13): the dedup mark is cleared at * every `running → idle` transition (SDK inline, parent notify handler, * poll-tick fallback) so each prompt cycle can enqueue exactly one * completion body. */ export interface PendingCompletion { agentId: string; /** Pre-formatted body per spec §5.8 (one-line prefix + result text). */ body: string; } export declare function enqueueCompletion(item: PendingCompletion): void; export declare function pendingCompletionsCount(): number; /** * Mark an agentId's completion as enqueued. Subsequent callers should * check `hasCompletionBeenEnqueued` and skip their own enqueue. */ export declare function markCompletionEnqueued(agentId: string): void; export declare function hasCompletionBeenEnqueued(agentId: string): boolean; /** * Clear an agentId's dedup mark. Spec §5.13. * * Persistent agents transition `running → idle` on every prompt cycle and * need a fresh completion body each time. Callers invoke this at the moment * of the running → idle flip (SDK inline, parent notify handler, poll-tick * fallback) BEFORE the subsequent `enqueueCompletion` + `markCompletionEnqueued`. */ export declare function clearCompletionEnqueued(agentId: string): void; /** * Drain the queue. The caller passes a synchronous `inject(text)` that * pushes the formatted batch wherever appropriate (context hook target * messages array, or `pi.sendUserMessage`). If `inject` throws, the * queue is left untouched so the next pass retries. */ export declare function drainCompletions(inject: (text: string) => void): { delivered: number; }; /** * Format one or more completions into a single user-message body the * parent LLM will read as context. */ export declare function formatCompletionBatch(items: PendingCompletion[]): string; /** Test/lifecycle helper — clear queue at session boundaries. */ export declare function resetCompletionQueue(): void; //# sourceMappingURL=completion-queue.d.ts.map