import type { LaunchctlRunner, LaunchdPaths } from "./launchd.js"; import type { LaunchdLogInspection } from "./launchd-logs.js"; import type { PollOptions } from "./background-lifecycle-utils.js"; import type { BackgroundDeps, BackgroundLifecycleTarget } from "./background.js"; export interface ManagedLaunchdLogInspectionDependencies { readonly inspectLaunchdLogs: (paths: Pick) => Promise; readonly runner: LaunchctlRunner; readonly getuid: () => number; /** Monotonic clock: cooldown authority never depends on wall-clock movement. */ readonly monotonicNow?: () => number; readonly wallClockNow?: () => number; readonly isStopped?: () => boolean; } export interface ManagedLaunchdLogMonitorDependencies extends ManagedLaunchdLogInspectionDependencies { readonly stderr: (text: string) => void | Promise; readonly recordStatus?: (status: ManagedLaunchdLogMonitorStatus) => void | Promise; } export interface ManagedLaunchdLogMonitor { stop(): void; } export interface AdditionalLaunchdLogInspection { readonly needsMaintenance: boolean; readonly canMaintain: boolean; readonly issues: readonly string[]; } export interface AdditionalLaunchdLogMaintenanceResult { readonly refusals: readonly string[]; } /** Narrow mutation port shared by agent maintenance and the isolated web helper. */ export interface LaunchdLogMaintenanceDeps { readonly runner: LaunchctlRunner; readonly getuid: () => number; readonly now: () => number; readonly sleep: (ms: number) => Promise; readonly stderr: (text: string) => void; readonly inspectLaunchdLogs: BackgroundDeps["inspectLaunchdLogs"]; readonly rotateStoppedLaunchdLogs: BackgroundDeps["rotateStoppedLaunchdLogs"]; readonly readLaunchdLogMaintenanceIntent: BackgroundDeps["readLaunchdLogMaintenanceIntent"]; readonly beginLaunchdLogMaintenanceIntent: BackgroundDeps["beginLaunchdLogMaintenanceIntent"]; readonly markLaunchdLogMaintenanceStopped: BackgroundDeps["markLaunchdLogMaintenanceStopped"]; readonly markLaunchdLogMaintenanceRestoring: BackgroundDeps["markLaunchdLogMaintenanceRestoring"]; readonly clearLaunchdLogMaintenanceIntent: BackgroundDeps["clearLaunchdLogMaintenanceIntent"]; readonly verifyLaunchdPlist: BackgroundDeps["verifyLaunchdPlist"]; readonly isAlive: (pid: number) => boolean; /** Optional bounded compatibility seam; it cannot read or mutate intent/journal state. */ readonly inspectAdditionalLaunchdLogArtifacts?: (paths: Pick) => Promise; /** Runs only after durable stopped-writer proof and before core rotation. */ readonly maintainAdditionalLaunchdLogArtifacts?: (paths: Pick) => Promise; readonly recordAdditionalLaunchdLogRefusals?: (refusals: readonly string[]) => Promise; readonly recordMaintenancePhase?: (phase: "inspecting" | "stopping" | "stopped" | "rotating" | "restoring" | "complete") => Promise; } export type ManagedLaunchdLogMonitorOutcome = "idle" | "shared-only" | "pending-artifact" | "cooldown" | "stopped" | "helper-unloaded" | "helper-running" | "requested" | "request-failed" | "inspection-failed"; export interface ManagedLaunchdLogMonitorStatus { readonly version: 1; readonly lastInspectionAt: string; readonly wakeCount: number; readonly lastOutcome: ManagedLaunchdLogMonitorOutcome; readonly cooldownDeadline: string; } export interface ManagedLaunchdLogWakeState { cooldownIndex: number; cooldownDeadlineMonotonicMs: number; wakeCount: number; lastOutcome: ManagedLaunchdLogMonitorOutcome; lastReportedOutcome: ManagedLaunchdLogMonitorOutcome | undefined; } export declare function createManagedLaunchdLogWakeState(monotonicNow?: typeof defaultMonotonicNow): ManagedLaunchdLogWakeState; /** * Run the managed worker's bounded metadata fast path. The dependency surface * intentionally excludes config validation, snapshots, and runtime recovery: * only a concrete safe maintenance inventory may wake the authenticated helper. */ export declare function requestLaunchdLogMaintenanceIfNeeded(target: BackgroundLifecycleTarget, deps: ManagedLaunchdLogInspectionDependencies, state?: ManagedLaunchdLogWakeState): Promise; /** * Inspect active logs in the already-running worker every five minutes. One * inspection may be in flight at a time, so a slow filesystem cannot build an * overlapping timer queue. Consecutive failures are reported only once. */ export declare function startManagedLaunchdLogMonitor(target: BackgroundLifecycleTarget, deps: ManagedLaunchdLogMonitorDependencies): ManagedLaunchdLogMonitor; declare function defaultMonotonicNow(): number; /** Run one authenticated, crash-recoverable stopped-writer log rotation pass. */ export declare function maintainLaunchdLogsOperation(target: BackgroundLifecycleTarget, deps: BackgroundDeps, poll: PollOptions, acquireSharedLogLock: () => Promise<(() => Promise) | undefined>): Promise; /** Acquire the shared lease after the caller already owns this agent's lifecycle. */ export declare function maintainLaunchdLogsWithLifecycleLockOperation(target: BackgroundLifecycleTarget, deps: BackgroundDeps, poll: PollOptions, acquireSharedLogLock: () => Promise<(() => Promise) | undefined>): Promise; /** Execute log maintenance only while the caller owns per-agent then shared leases. */ export declare function maintainLaunchdLogsWithSharedLockOperation(target: BackgroundLifecycleTarget, deps: LaunchdLogMaintenanceDeps, poll: PollOptions): Promise; export declare function reportMaintenanceFailure(target: BackgroundLifecycleTarget, deps: Pick, action: string, error: unknown): void; export {}; //# sourceMappingURL=background-log-maintenance.d.ts.map