import type { KernelPaths } from "./types.js"; export declare const DEFAULT_LOCK_TIMEOUT_MS = 10000; export declare const DEFAULT_LOCK_STALE_MS = 30000; /** Default exclusive lock under `KernelPaths.lockRoot` (campaign authority). */ export declare const KERNEL_RUNTIME_LOCK_NAME = "runtime.lock"; /** Named lock for v2 skill/agent asset projection (same algorithm, separate holder). */ export declare const V2_PROJECT_LOCK_NAME = "v2-project"; export interface KernelLockMetadata { readonly schema_version: 2; readonly owner_token: string; readonly process_id: number; readonly process_instance_id: string; readonly boot_id: string | null; readonly start_ticks: string | null; readonly created_at: string; readonly note: string | null; } export interface KernelLock { readonly path: string; readonly owner_token: string; readonly metadata: KernelLockMetadata; release(): void; } export interface AcquireKernelLockOptions { readonly paths: KernelPaths; /** * Single path segment under `paths.lockRoot`. Defaults to `runtime.lock`. * Use a distinct name (e.g. `v2-project`) so projection never contends with * campaign authority while still sharing one lock algorithm. */ readonly lockName?: string; readonly ownerToken?: string; readonly note?: string; readonly timeoutMs?: number; readonly staleMs?: number; readonly now?: () => number; /** Test seam: override liveness check for a stored metadata snapshot. */ readonly isLive?: (meta: KernelLockMetadata) => boolean; } /** * Exclusive directory lock: stable lock directory + exclusive owner.json create. * The directory is never removed during normal acquire/release (avoids races with * concurrent writers fsyncing the dir). Stale recovery renames owner.json only * when the on-disk token still matches — a successor owner is never unlinked. * * One algorithm for all v2 holders; distinguish campaigns vs projection via `lockName`. */ export declare function acquireKernelLock(pathsOrOptions: KernelPaths | AcquireKernelLockOptions, ownerOrOptions?: string | Omit): KernelLock; /** * Recover a stale lock only when the on-disk owner_token still matches. * A successor lock with a different token is never removed. */ export declare function recoverStaleLockDir(lockDir: string, expectedOwnerToken: string, isLive?: (meta: KernelLockMetadata) => boolean): boolean; export declare function withKernelLock(paths: KernelPaths, fn: () => T, ownerOrOptions?: string | Omit): T; export declare function readLockMetadata(path: string): KernelLockMetadata;