/** * BackgroundReviewCoordinator — owns the per-session counters that decide when * to nudge the model into running a quiet user-understanding review * after a normal user turn finishes. * * The nudge state and review scheduling are kept out of the per-session agent * instance so: * - `AgentInstance` no longer carries an inline counter object. * - Future changes to the review cadence only touch this file. */ import type { Agent } from '@earendil-works/pi-agent-core'; import type { Config } from '../../config/schema.js'; import type { WorkspaceRuntime } from '../workspace-runtime/registry.js'; export interface BackgroundReviewCoordinatorOptions { /** Effective config snapshot used to look up review-cadence settings. */ getConfig: () => Config | undefined; } export interface ScheduleReviewContext { sessionKey: string; agent: Agent; /** Last assistant text — review is skipped when empty. */ lastAssistantText: string | null; workspaceRuntime: WorkspaceRuntime; } export declare class BackgroundReviewCoordinator { private readonly opts; private readonly states; constructor(opts: BackgroundReviewCoordinatorOptions); /** * Called before the main `agent.prompt` for a user turn — bumps the memory * counter and arms a review when the cadence interval is hit. */ beginUserTurn(sessionKey: string): void; /** * Fire-and-forget review after the main user turn. Decides whether to run a * understanding sweep based on the counter state + last assistant text, * and delegates the actual review to {@link runBackgroundReviewTurn}. */ scheduleAfterUserTurn(ctx: ScheduleReviewContext): void; /** Tear down state for a session (called by `AgentManager.removeAgent`). */ forgetSession(sessionKey: string): void; /** Clear every counter (`AgentManager.dispose` / hot reload). */ clear(): void; private ensureState; private resolveReviewInterval; private runReviewIfNeeded; }