/** * Agent widget visibility/polling lifecycle helpers. * * Centralizes the show/hide/refresh decisions that drive the agent widget so * the wiring in `index.ts` stays declarative and the rules are pure-testable: * * - `runAgentPollTick` — single 30s idle poll (mirrors §6.3.1). * - `startAgentPolling` — schedules `runAgentPollTick` on `setInterval`. * - `onAgentSpawned` — post-spawn: show widget immediately. * - `onAgentMutated` — post-stop/recover: re-read + hide-if-empty. * * All helpers accept injected `listFn` / `factoryFn` so tests can drive the * lifecycle without touching the filesystem. */ import type { AgentStatusFile, WidgetState } from "@pi-orca/core"; export interface AgentSnapshot { id: string; status: string; /** Spec §5.13. Carried so persistent → idle transitions can re-enqueue. */ lifecycle: string; in: number; out: number; cost: number; terminal: boolean; } export interface AgentPollState { previousSnapshot: AgentSnapshot[]; } export interface AgentLifecycleDeps { sessionPath: string; ctx: any; widgetState: WidgetState; listFn?: (sp: string) => Promise>; factoryFn?: (sp: string) => unknown; } export interface AgentPollHandle { stop: () => void; /** Resolves to the most recent in-flight tick (for tests). */ flush: () => Promise; } export declare function buildAgentSnapshot(statuses: Array<[string, AgentStatusFile]>): AgentSnapshot[]; export declare function agentSnapshotsEqual(a: AgentSnapshot[], b: AgentSnapshot[]): boolean; export declare function runAgentPollTick(deps: AgentLifecycleDeps, state: AgentPollState): Promise; export declare function startAgentPolling(deps: AgentLifecycleDeps, state: AgentPollState, intervalMs: number): AgentPollHandle; /** * Post-spawn: unconditionally show the widget (idempotent if already visible) * and refresh the snapshot baseline so the next poll tick won't double-refresh. */ export declare function onAgentSpawned(deps: AgentLifecycleDeps, state: AgentPollState): Promise; /** * Post-stop/recover: re-read; hide if the list is now empty, refresh if still * visible. Mirror of `runAgentPollTick` semantics but always triggered, not on * a tick boundary. */ export declare function onAgentMutated(deps: AgentLifecycleDeps, state: AgentPollState): Promise; //# sourceMappingURL=widget-lifecycle.d.ts.map