/** * CLI-owned runtime access declarations and lease acquisition. * * These facts deliberately decorate host CommandSpecs only after core has * validated/frozen the public command contract. Tool CommandSpecs never flow * through this module, so third-party tools cannot request host bootstrap * privileges or inspection-only startup. */ import { acquireRuntimeAccessLease, acquireRuntimeReadLease, acquireUserStateReadLease, type CommandScopeRequirement, type FileLockEvent, type RuntimeLease, type RuntimeLeaseEvent } from '@opensip-cli/core'; import type { HostCommandRuntimePolicy } from './host-runtime-policy.js'; import type { DatastoreCloseResult } from '@opensip-cli/datastore'; export { DEFAULT_HOST_RUNTIME_POLICY, defineHostCommand, hostPolicyNeedsProjectCoordination, isInspectionOnlyHostRequest, resolveHostRuntimePolicy, resolveHostRuntimePolicyForScope, } from './host-runtime-policy.js'; export type { HostBootstrapMode, HostCommandRuntimePolicy, HostRuntimeAccess, HostRuntimeCommandSpec, } from './host-runtime-policy.js'; /** * Bounded event projection safe for CLI diagnostics. Raw paths, host identity, * PIDs, metadata, and owner tokens are discarded synchronously at callback * time; callers never retain the core event object. */ export interface SafeRuntimeLeaseEvent { readonly kind: RuntimeLeaseEvent['kind'] | FileLockEvent['kind']; readonly resource: 'runtime'; readonly operation?: string; readonly waitMs?: number; } export interface SafeRuntimeLeaseEventSink { readonly onEvent: (event: SafeRuntimeLeaseEvent) => void; readonly onDropped: (count: number) => void; } export interface SafeRuntimeLeaseEventBuffer { readonly onEvent: (event: RuntimeLeaseEvent | FileLockEvent) => void; /** * Flush buffered projections and synchronously forward later projections. * Sink failures are diagnostic-only and never escape into lease mechanics. */ readonly attach: (sink: SafeRuntimeLeaseEventSink) => void; readonly drain: () => { readonly events: readonly SafeRuntimeLeaseEvent[]; readonly dropped: number; }; } /** Create a one-shot bounded lease-event buffer. */ export declare function createSafeRuntimeLeaseEventBuffer(limit?: number): SafeRuntimeLeaseEventBuffer; export interface AcquireHostRuntimeLeaseInput { readonly command: string; readonly cwd: string; readonly projectDir: string; readonly scope: CommandScopeRequirement; readonly policy: HostCommandRuntimePolicy; readonly ownerToken?: string; readonly onEvent?: (event: RuntimeLeaseEvent | FileLockEvent) => void; } export interface HostRuntimeLeaseAcquisitionDeps { readonly acquireRuntimeReadLease?: typeof acquireRuntimeReadLease; readonly acquireUserStateReadLease?: typeof acquireUserStateReadLease; readonly acquireRuntimeAccessLease?: typeof acquireRuntimeAccessLease; } export type RuntimeLeaseLifecycleState = 'bootstrap' | 'scope' | 'released' | 'retained'; /** * CLI-only ownership controller. It prevents an outer failure path from * releasing a lease after scope teardown failed to prove SQLite was closed. */ export interface RuntimeLeaseLifecycle { readonly lease: RuntimeLease | undefined; readonly state: () => RuntimeLeaseLifecycleState; readonly transferToScope: () => void; readonly releaseBootstrapOwned: () => void; readonly finishAfterDatastoreClose: (result: DatastoreCloseResult) => void; } export declare function createRuntimeLeaseLifecycle(lease: RuntimeLease | undefined, retainedLeases?: readonly RuntimeLease[]): RuntimeLeaseLifecycle; /** Assert the current command holds user-state authority before user-root I/O. */ export declare function assertEnteredUserStateOwner(operation: string): void; /** Assert the current command holds project authority before project-host I/O. */ export declare function assertEnteredProjectOwner(operation: string): void; /** Test-only: clear entered ownership between cases. */ export declare function resetEnteredHostOwnershipForTests(): void; /** Test-only: seed entered ownership without a live coordination lease. */ export declare function enterHostOwnershipForTests(args: { readonly userState?: boolean; readonly project?: boolean; readonly ownerToken?: string; }): void; /** * Run `fn` under entered user-state ownership. Reuses an existing user-state * owner when present; otherwise acquires a short user-state lease (optionally * reentering with the same owner token as an existing project lease) and * releases it before returning. Used by bootstrap update-state writes. */ export declare function runWithUserStateOwnership(opts: { readonly command: string; readonly cwdBasename?: string; readonly ownerToken?: string; }, fn: () => void | Promise): Promise; export declare function acquireHostRuntimeLease(input: AcquireHostRuntimeLeaseInput, deps?: HostRuntimeLeaseAcquisitionDeps): Promise; //# sourceMappingURL=host-runtime-access.d.ts.map