/** * Monitoring Automation State * * Provides: * - readAutomationState: Reads bounded change-detection state. * - writeAutomationState: Atomically persists state without log evidence. * - withAutomationStateLock: Prevents overlapping runs for one automation key. * - listAutomationStates: Returns dashboard-safe state summaries. * - clearAutomationMonitorState: Clears stale monitor data without resetting write budgets. */ import type { TargetBinding } from "./target-resolution.js"; /** Persisted state used to make scheduled monitoring change-aware. */ export interface AutomationState { schemaVersion: 1; automationKey: string; cursor?: string; digest?: string; lastStatus?: string; consecutiveFailures: number; consecutiveHardwareWrites: number; lastHardwareWriteAt?: string; lastHardwareWriteAction?: string; targetBinding?: TargetBinding; createdAt: string; updatedAt: string; } /** Dashboard-safe automation state without serial evidence or local paths. */ export interface AutomationStateSummary { automationKey: string; state: "healthy" | "stale" | "binding_expired" | "invalid"; lastStatus?: string; consecutiveFailures: number; consecutiveHardwareWrites: number; lastHardwareWriteAt?: string; lastHardwareWriteAction?: string; environment?: string; bindingExpiresAt?: string; createdAt?: string; updatedAt?: string; } /** * Validates an automation key before using it as a filename. * * @param automationKey - User-selected stable automation identifier. * @returns Validated key. */ export declare function validateAutomationKey(automationKey: string): string; /** * Resolves the private workspace state path for an automation. * * @param projectDir - PlatformIO project directory. * @param automationKey - Validated automation key. * @returns Absolute JSON state path. */ export declare function getAutomationStatePath(projectDir: string, automationKey: string): string; /** * Reads current state, recovering safely from stale or malformed content. * * @param projectDir - PlatformIO project directory. * @param automationKey - Stable automation identifier. * @returns Existing or reset state. */ export declare function readAutomationState(projectDir: string, automationKey: string): AutomationState; /** * Reads a write budget without silently recovering from stale or malformed state. * * @param projectDir - PlatformIO project directory. * @param automationKey - Stable automation identifier. * @returns Verified state for a hardware-write policy decision. */ export declare function readAutomationWriteBudgetState(projectDir: string, automationKey: string): AutomationState; /** * Persists monitoring state using an atomic same-directory rename. * * @param projectDir - PlatformIO project directory. * @param state - Complete state record without serial evidence. * @returns Persisted state with a fresh timestamp. */ export declare function writeAutomationState(projectDir: string, state: AutomationState): AutomationState; /** * Lists bounded automation summaries for the authenticated dashboard. * Malformed state is reported as invalid without returning its contents. * * @param projectDir - PlatformIO project directory. * @returns Newest-first state summaries. */ export declare function listAutomationStates(projectDir: string): AutomationStateSummary[]; /** * Clears change-detection state while preserving the hardware-write budget. * This prevents a dashboard reset from bypassing lab-runner flash limits. * * @param projectDir - PlatformIO project directory. * @param automationKey - Stable automation identifier. * @returns Fresh monitoring state with any write budget retained. */ export declare function clearAutomationMonitorState(projectDir: string, automationKey: string): Promise; /** * Runs one automation operation under a per-key cross-process lock. * * @param projectDir - PlatformIO project directory. * @param automationKey - Stable automation identifier. * @param operation - Work that must not overlap for this key. * @returns Operation result. */ export declare function withAutomationStateLock(projectDir: string, automationKey: string, operation: () => Promise): Promise; //# sourceMappingURL=automation-state.d.ts.map