import { type AgentState, type GraphNode, type SkillGraph } from "./graph.ts"; export declare const PREPARATION_SCHEMA_VERSION = 1; export declare const DEFAULT_LEASE_DURATION_MS = 300000; export declare const DEFAULT_MUTATION_LOCK_TIMEOUT_MS = 5000; export interface FileInventoryEntry { size: number; mtimeMs: number; hash: string; } export interface StagePreparation { schemaVersion: 1; id: string; nodeId: string; runId: string; ownerToken: string; leaseExpiresAt: string; graphVersion: number; contractVersion: string; nodeContractHash?: string; immutableDependencies: string[]; immutableHash: string; editableInputs: string[]; expectedOutputs: string[]; protectedSourceFingerprint: string; captureFingerprint: string; reviewSubjectHash?: string; baselineInventory: Record; packetHash: string; manifestHash?: string; promptHash?: string; overflowHash?: string; attempt: number; status: "prepared" | "consumed" | "canceled" | "invalidated"; preparedAt: string; consumedAt?: string; manifestId?: string; authoringPolicy?: { mode: string; lessonRelease: string | null; hash: string; }; mediaAuditSnapshot?: string; capabilitiesSnapshot?: Record; ownershipSnapshot?: { workOwnership: string; packetReduced: boolean; outcomes: Array<{ taskId: string; eligible: boolean; reasons: string[]; coveredObligationIds: string[]; }>; }; invalidationReason?: string; result?: { ok: boolean; failures: string[]; }; agentUsage?: { inputTokens?: number; outputTokens?: number; measured: boolean; }; } export interface ToolExecutionReceipt { nodeId: string; kind: "tool"; command: string[]; exitCode: number; durationMs: number; startedAt: string; failures: string[]; outputPath: string; } export interface CommitJournalEntry { transactionId: string; preparationId: string; nodeId: string; phase: "intent" | "graded" | "state_written" | "consumed"; preparationPath?: string; receiptPath?: string; statePath: string; targetState?: AgentState; updatedPreparation?: StagePreparation | ToolExecutionReceipt; createdAt: string; effects?: string[]; } export interface LeaseRecord { leaseName: string; ownerToken: string; pid: number; acquiredAt: string; expiresAt: string; } /** Compute SHA-256 content hash of a file or string. */ export declare function sha256Hex(content: string | Buffer): string; /** Hash a file safely; returns empty string if unreadable. */ export declare function hashFileSafe(filePath: string): string; /** Standard directories to snapshot for inventory checks. */ export declare const INVENTORY_ROOT_SCAN_DIRS: string[]; /** Standard top-level files to snapshot. */ export declare const INVENTORY_ROOT_SCAN_FILES: string[]; /** * Snapshots repository file inventory across standard source, output, and agent directories. * Relative paths are normalized using forward slashes. */ export declare function snapshotInventory(root: string): Record; /** Standard authorized bookkeeping paths that any stage may write to. */ export declare const AUTHORIZED_BOOKKEEPING_PREFIXES: string[]; /** * Checks created, modified, and deleted files against allowed writes. * Preserves pre-existing dirty changes that were present in baseline. */ export declare function verifyAllowedWrites(opts: { root: string; node: GraphNode; baselineInventory: Record; allowedWrites: string[]; }): { ok: boolean; violations: string[]; modified: string[]; created: string[]; deleted: string[]; }; /** Check if process with PID is alive. */ export declare function isProcessAlive(pid: number): boolean; /** Short-lived filesystem mutation lock with token-safe release to prevent unlinking successor locks. */ export declare function acquireMutationLock(root: string, timeoutMs?: number): (() => void) & { release: () => void; }; /** Run a synchronous operation within a short-lived mutation lock, re-entrant within the same process. */ export declare function withMutationLock(root: string, fn: () => T, timeoutMs?: number): T; /** Run an asynchronous operation within a short-lived mutation lock, re-entrant within the same process. */ export declare function withMutationLockAsync(root: string, fn: () => Promise, timeoutMs?: number): Promise; /** Durable lease management for stage preparation and tool execution. */ export declare function acquireDurableLease(opts: { root: string; leaseName: string; durationMs?: number; isAgentStage?: boolean; }): { token: string; release: () => void; }; /** Releases a durable lease safely if the token matches. */ export declare function releaseDurableLease(root: string, leaseName: string, ownerToken: string): void; /** Check if a durable lease is currently held by a live or unexpired owner. */ export declare function isDurableLeaseHeld(root: string, leaseName: string): boolean; /** Check if any active stage lease is held across agent/leases. */ export declare function hasActiveStageLease(root: string): { held: boolean; leaseName?: string; expiresAt?: string; ownerToken?: string; }; /** Enforces global outstanding-stage exclusion: no two active stage preparations at once. */ export declare function checkGlobalStageExclusion(root: string, targetNodeId: string): void; /** Commit Journal Operations for Crash-Safe State Transitions. */ export declare function writeCommitJournal(root: string, entry: CommitJournalEntry): void; export declare function updateCommitJournalPhase(root: string, phase: "state_written" | "consumed"): void; export declare function clearCommitJournal(root: string): void; /** * Recovers an uncommitted or interrupted transaction from agent/.commit-journal.json. * Guarantees crash safety across STATE.json, preparations, receipts, and side-effects. */ export declare function recoverCommitJournal(root: string, graph: SkillGraph): { recovered: boolean; transactionId?: string; phase?: string; targetState?: AgentState; }; /** Preparation Record I/O */ export declare function preparationPathForId(root: string, id: string): string; export declare function savePreparation(root: string, prep: StagePreparation): string; export declare function loadPreparation(root: string, id: string): StagePreparation | undefined; export declare function findActivePreparation(root: string, nodeId: string): StagePreparation | undefined; /** The first interactive production preparation already owns inventory writes. */ export declare function preparedProductionOwner(root: string, graphVersion: number): StagePreparation | undefined; export declare function invalidatePreparation(root: string, id: string, reason: string): void; /** * Categorize a node's dependencies into immutable dependencies, editable inputs, and expected outputs. */ export declare function categorizeNodeDependencies(opts: { root: string; node: GraphNode; }): { immutableDependencies: string[]; editableInputs: string[]; expectedOutputs: string[]; }; /** Fingerprint only immutable dependencies. */ export declare function computeImmutableHash(root: string, immutableDependencies: string[], nodeId: string): string;