/** * Auto-Learn / Native-Reflection controller. * * Extracted verbatim from interactive-mode.ts (god-file decomposition). Owns the disk-backed * Auto Learn run-state machine (state.json + lockfile), the background-learner spawn/prune * lifecycle, and the interactive task-contract nudge. It takes narrow deps (a live session * accessor, a self-modification-source resolver that stays in the host, and a small UI callback * surface) rather than the whole InteractiveMode instance. */ import type { AgentMessage } from "@caupulican/pi-agent-core"; import type { SelectItem } from "@caupulican/pi-tui"; import type { AgentSession } from "../../core/agent-session.ts"; import type { AutoLearnSettings, AutonomyMode } from "../../core/settings-manager.ts"; export declare const AUTONOMY_MODES: AutonomyMode[]; export declare const AUTO_LEARN_HISTORY_RETENTION_MS: number; export interface AutoLearnHistoryPruneResult { promptFiles: number; logFiles: number; sessionFiles: number; errors: number; } export interface AutoLearnHistoryPruneOptions { dataDir: string; now?: number; retentionMs?: number; activeRunIds?: Iterable; activeSessionIds?: Iterable; } export declare function pruneAutoLearnConversationHistory(options: AutoLearnHistoryPruneOptions): AutoLearnHistoryPruneResult; export interface AutoLearnRunRecord { tenant: string; pid?: number; model: string; reason: string; startedAt: number; expiresAt: number; cwd: string; logPath: string; sessionDir?: string; sessionId?: string; promptPath?: string; kind?: "auto" | "reflection"; autonomyMode?: AutonomyMode; authority?: string; status?: "reserved" | "running"; } export interface AutoLearnState { lastLaunchByTenant?: Record; lastReflectionByTenant?: Record; runs?: Record; } export interface AutoLearnSpawnTarget { command: string; argsPrefix: string[]; } export interface AutoLearnSpawnArgsOptions { name: string; modelPattern: string; thinkingLevel?: string; sessionDir: string; sessionId: string; promptPath: string; } export declare function buildAutoLearnSpawnArgs(spawnTarget: AutoLearnSpawnTarget, options: AutoLearnSpawnArgsOptions): string[]; export declare function findAutoLearnSpawnNullByteInput(command: string, args: readonly string[]): string | undefined; export interface AutoLearnControllerUi { showStatus(message: string): void; readonly footerDataProvider: { setExtensionStatus(key: string, text: string | undefined): void; }; invalidateFooter(): void; requestRender(): void; } export interface AutoLearnControllerDeps { getSession(): AgentSession; resolveSelfModificationSource(settings: { sourcePath?: string; sourcePaths?: string[]; }): string | undefined; ui: AutoLearnControllerUi; } export declare class AutoLearnController { private _taskContractStreak; private readonly deps; constructor(deps: AutoLearnControllerDeps); private get session(); private getAutoLearnModelAuthPriority; private getAutoLearnModelAuthLabel; getAutoLearnModelOptions(): SelectItem[]; getAutoLearnDataDir(): string; private getAutoLearnStatePath; private ensureAutoLearnStateFile; private readAutoLearnState; private writeAutoLearnState; private acquireAutoLearnStateLock; private withAutoLearnStateLock; private appendAutoLearnLog; private isAutoLearnPidAlive; private pruneAutoLearnState; private pruneAutoLearnHistoryFromState; getPrunedAutoLearnState(): AutoLearnState; getAutoLearnPresetForAutonomyMode(mode: AutonomyMode, current?: AutoLearnSettings): Required; getEffectiveAutoLearnSettings(): Required; getCurrentAutoLearnSettings(): Required; getAutoLearnTenantKey(): string; private getAutoLearnTenantId; getAutoLearnTenantDataDir(): string; private getAutoLearnMessageCount; private buildAutoLearnDecisionFromState; /** Read-only readiness projection for the manual Auto Learn command and status report. */ private evaluateAutoLearn; private resolveAutoLearnModelPattern; private getAutoLearnSpawnTarget; validateAutoLearnModelValue(value: string | undefined): string | undefined; private buildAutonomyAuthorityPrompt; private buildAutoLearnPrompt; private reserveAutoLearnRun; private releaseAutoLearnReservation; private reportCompletedAutoLearnUsage; private cleanupCompletedAutoLearnRun; private markAutoLearnReservationRunning; launchAutoLearn(reason: string, force?: boolean, options?: { cooldownKind?: "auto" | "reflection"; promptKind?: "auto" | "reflection"; turnDigest?: string; bypassReflectionCooldown?: boolean; }): string; /** * Current-session reflection is available only to the root orchestrator. It never launches a * learner process; the session provider planner owns its single-request transient cue. */ isNativeReflectionEnabled(): boolean; /** * Cheap turn-boundary task_steps contract check. Reads the current task_steps snapshot, * advances the pure `checkTaskStepsContract` streak, and — on the exact turn a sustained * violation first reaches the threshold — delivers a ONE-LINE advisory harness note through the * session's existing next-turn message surface (`sendCustomMessage(..., {deliverAs:"nextTurn"})`, * the same mechanism `_pendingNextTurnMessages` already injects `memory_context`/ * `task_steps_context` pages through). Zero model calls; a delivery failure is swallowed so this * best-effort nudge can never disrupt the turn. * * Called from both interactive turn-boundary compatibility hooks so it runs regardless of the * current-session reflection setting without adding another provider turn. */ private checkTaskStepsContractNudge; maybeRunNativeReflection(messages: AgentMessage[]): void; maybeStartAutoLearn(): boolean; maybeStartAutonomyReview(messages: AgentMessage[]): boolean; updateAutoLearnFooter(): void; formatAutoLearnStatus(): string; } //# sourceMappingURL=auto-learn-controller.d.ts.map