import type { AgentTool, ToolEffects } from "@apholdings/jensen-agent-core"; import { WorkspaceBoundary } from "./boundary.js"; import { CheckpointStore, type WorkspaceCheckpoint } from "./checkpoint.js"; import { type LeaseRecord, type LeaseResult, WorkspaceLeaseStore } from "./lease.js"; import { PolicyEngine } from "./policy.js"; import { type TransactionRecord, type WorkspaceEdit, WorkspaceTransactionManager } from "./transaction.js"; import type { ExecutionMode, PolicyDecision, PolicyEvaluation, PolicyInput, RecoveryClass, TransactionId } from "./types.js"; export declare class PolicyDeniedError extends Error { readonly decision: PolicyDecision; constructor(decision: PolicyDecision); } export declare class PolicyApprovalRequiredError extends Error { readonly evaluation: PolicyEvaluation; constructor(evaluation: PolicyEvaluation); } export interface WorkspaceSafetyOptions { storageDir: string; timeoutMs?: number; heartbeatMs?: number; now?: () => number; isProcessAlive?: (pid: number) => boolean; } export interface MutationOutcome { transactionId: TransactionId; stage: "confirmed" | "applied" | "rolled_back"; changed: string[]; } /** * Durable mutation-lifecycle events (the canonical long-horizon equivalent for * workspace mutations). These are recorded by the safety manager for audit and * replay. They complement, and never compete with, the long-horizon execution * state machine. */ export type MutationLifecycleEvent = { event: "MUTATION_POLICY_EVALUATED"; transactionId?: string; outcome: string; reasonCode: string; at?: number; } | { event: "WORKSPACE_LEASE_ACQUIRED"; ownerRunId: string; leaseId: string; at?: number; } | { event: "CHECKPOINT_CREATED"; transactionId: string; checkpointId: string; at?: number; } | { event: "TRANSACTION_APPLY_STARTED"; transactionId: string; at?: number; } | { event: "TRANSACTION_APPLIED"; transactionId: string; at?: number; } | { event: "TRANSACTION_VALIDATION_STARTED"; transactionId: string; at?: number; } | { event: "TRANSACTION_VALIDATED"; transactionId: string; result: string; at?: number; } | { event: "TRANSACTION_CONFIRMED"; transactionId: string; at?: number; } | { event: "TRANSACTION_ROLLBACK_STARTED"; transactionId: string; at?: number; } | { event: "TRANSACTION_ROLLED_BACK"; transactionId: string; at?: number; } | { event: "TRANSACTION_RECOVERY_REQUIRED"; transactionId: string; reason: string; at?: number; } | { event: "WORKSPACE_LEASE_RELEASED"; ownerRunId: string; at?: number; }; /** * Plumbs the deterministic safety lifecycle together: policy → boundary → * lease → checkpoint → transactional apply → validate → confirm/rollback → * durable record. Provides a guarded tool wrapper for production tool * execution and a diagnostic surface that never exposes secrets or contents. */ export declare class WorkspaceSafety { readonly storageDir: string; readonly boundary: WorkspaceBoundary; readonly policy: PolicyEngine; readonly leases: WorkspaceLeaseStore; readonly checkpoints: CheckpointStore; readonly transactions: WorkspaceTransactionManager; readonly workspaceId: string; readonly root: string; executionMode: ExecutionMode; constructor(root: string, boundary: WorkspaceBoundary, options: WorkspaceSafetyOptions, mode?: ExecutionMode); static create(root: string, options: WorkspaceSafetyOptions, mode?: ExecutionMode): Promise; private modePath; private journalPath; /** Append a durable mutation-lifecycle event (audit/replay, not authority). */ appendEvent(ev: MutationLifecycleEvent & { at?: number; }): Promise; readEvents(): Promise[]>; /** * Completion gate for long-horizon: a step whose required mutation * transaction is unresolved (unvalidated/unconfirmed/rollback- or * recovery-required) cannot be marked complete. */ gateStepCompletion(mutating: boolean): Promise<{ canComplete: boolean; blockingReason?: string; }>; persistMode(): Promise; setExecutionMode(mode: ExecutionMode): Promise; readMode(): Promise; evaluate(input: Omit & Partial>): PolicyEvaluation; /** Guard a mutation path. Returns resolved abs paths or throws Denied/Approval/Boundary. */ guardMutation(input: Omit): Promise<{ evaluation: PolicyEvaluation; resolved: string[]; }>; /** * High-level transactional mutation over a structured edit batch. * Policy is evaluated, an exclusive lease is acquired, a checkpoint is * created before the first write, the batch is applied, validated, and * confirmed. Any failure rolls back and releases the lease. */ performMutation(opts: { runId?: string; mode?: ExecutionMode; edits: WorkspaceEdit[]; policy?: PolicyDecision | null; validation?: { id: string; label: string; run: (() => Promise<{ exitCode: number; outputArtifact: string; }>) | null; }; effects?: ToolEffects; releaseAuthorized?: boolean; }): Promise; acquireLease(ownerRunId: string): Promise; releaseLease(ownerRunId: string): Promise; leaseStatus(): Promise; lastCheckpoint(): Promise; recoverRollback(transactionId: TransactionId): Promise; classify(transactionId: TransactionId): Promise; /** * Wrap the deterministic mutating tools (edit, write) so that every call is * guarded by policy + lease + checkpoint + transaction confirm/rollback. */ wrapMutationTools(tools: T[], authorize?: (scope: string) => boolean | Promise): T[]; } //# sourceMappingURL=manager.d.ts.map