import { type ProcessJobErrorCode, type ProcessJobProjection, type ProcessJobState } from "@mono-agent/agent-contracts"; import { type ProcessJobsSettings } from "./process-jobs-config.js"; import { type ProcessIncarnation } from "./process-incarnation.js"; export declare const PROCESS_JOB_RECORD_SCHEMA = 1; export declare const PROCESS_JOB_RECORDS_DIRECTORY = "records-v1"; export declare const PROCESS_JOB_ARTIFACTS_DIRECTORY = "artifacts"; export declare const PROCESS_JOB_MANIFEST_FILE = "process-jobs-store-v1.json"; export declare const PROCESS_JOB_TRANSACTION_FILE = "process-jobs-transaction-v1.json"; export declare const PROCESS_JOB_QUARANTINE_DIRECTORY = "quarantine-v1"; export declare const PROCESS_JOB_SECRET_FILE = "process-jobs-secret"; export declare const PROCESS_JOB_HEALTH_FILE = "process-jobs-health-v1.json"; export declare const PROCESS_JOB_ROLLBACK_GUARD = "PROCESS-JOBS-STORE-V1"; export declare const PROCESS_JOB_ROLLBACK_GUARD_CONTENT = "This state directory uses mono-agent process-job records v1. Older runtimes must not open it.\n"; export declare const PROCESS_JOB_ORPHAN_RECONCILIATION_INTERVAL = 64; export declare const PROCESS_JOB_DESTINATION_UNAVAILABLE_ATTEMPTS = 3; export declare const PROCESS_JOB_CONVERSATION_BUSY_ATTEMPT_COUNTER_MAX = 65535; export declare const PROCESS_JOB_CONVERSATION_BUSY_MAX_AGE_MS: number; /** Maximum simultaneously retained records plus pending wake obligations. */ export declare const PROCESS_JOB_STORE_MAX_RECORD_ENTRIES: number; export declare const MAX_PROCESS_JOB_HEALTH_BYTES: number; export declare const PROCESS_JOB_ENV_KEYS_CAPS: Readonly<{ maxItems: 128; maxItemBytes: 256; maxTotalBytes: number; }>; export interface ProcessJobOriginRecord { readonly conversationId: string; readonly baseConversationId: string; readonly bucket: string | null; readonly replyToConversationId: string; readonly normalizedReplyTarget: string; readonly runId: string; readonly historyBoundary: string; /** Opted-in addressable conversation-id scheme owned by the origin driver. */ readonly channel: string; } export interface DurableProcessJobRecord { readonly schemaVersion: typeof PROCESS_JOB_RECORD_SCHEMA; generation: string; readonly jobId: string; readonly tool: "Exec" | "Bash"; state: ProcessJobState; readonly summary: string; readonly agentIncarnation: ProcessIncarnation; processIncarnation?: ProcessIncarnation; pid: number | null; pgid: number | null; readonly sandboxSettingsPath: string | null; readonly argvSummary: string; readonly cwd: string; readonly envKeys: readonly string[]; readonly origin: ProcessJobOriginRecord; readonly chainDepth: number; readonly maxRuntimeMs: number; readonly maxOutputBytes: number; readonly previewChars: number; readonly admittedAt: string; readonly queueDeadlineAt: string; startedAt: string | null; runtimeDeadlineAt: string | null; completedAt: string | null; exitCode: number | null; signal: string | null; durationMs: number | null; stdoutBytes: number; stderrBytes: number; truncated: boolean; preview: string; stdoutRef: string | null; stderrRef: string | null; cancelRequested: boolean; wake: { state: "pending" | "delivered" | "failed"; attempts: number; readonly deliveryKey: string; lastAttemptAt: string | null; /** Private durable proof that the last adapter result explicitly permitted retry. */ retrySafe?: boolean; /** Optional in pre-integration record v1; omission means zero for older branch records. */ destinationUnavailableAttempts?: number; /** Optional in older record v1; counts durable pre-dispatch busy refusals. */ conversationBusyAttempts?: number; /** Optional in older record v1; first durable busy refusal, null before one occurs. */ conversationBusySinceAt?: string | null; }; lastError: { readonly code: ProcessJobErrorCode; readonly message: string; } | null; } export interface ProcessJobStoreWorkCounter { mutationEntriesExamined: number; mutationRecordsValidated: number; mutationEntriesPersisted: number; artifactDirectoriesInspected: number; orphanReconciliations: number; /** Optional open-path scale seam; older callers need not initialize it. */ recordEntriesExaminedAtOpen?: number; } export interface OpenProcessJobStoreOptions { /** Deterministic internal work seam for scale regressions; omitted in production. */ readonly workCounter?: ProcessJobStoreWorkCounter; /** Lower-only internal seam for deterministic bounded-open regressions. */ readonly maxRecordEntries?: number; } /** Internal touched-entry view over one transactional mutation. */ export interface ProcessJobStoreMutationDraft extends Map { candidateEntries(): IterableIterator<[string, DurableProcessJobRecord]>; deletedKeys(): IterableIterator; } export interface ProcessJobStore { readonly stateDir: string; readonly recordsDir: string; readonly artifactsDir: string; readonly health: { readonly state: "ok" | "degraded"; readonly quarantinedTransactions: number; }; get(jobId: string): Promise; list(): Promise; mutate(operation: (records: ProcessJobStoreMutationDraft) => T | Promise): Promise; ensureArtifacts(jobId: string): Promise<{ readonly stdoutRef: string; readonly stderrRef: string; }>; discardArtifacts(jobId: string): Promise; writeArtifact(jobId: string, stream: "stdout" | "stderr", contents: string): Promise; applyRetention(settings: ProcessJobsSettings, now?: Date): Promise; } export interface ProcessJobHealthIncident { readonly schemaVersion: 1; readonly state: "degraded"; readonly operation: string; readonly detectedAt: string; } /** Open and recover the independent per-record v1 process-job store. */ export declare function openProcessJobStore(agentRoot: string, stateDir: string, options?: OpenProcessJobStoreOptions): Promise; /** Prepare only the confined private state root, before acquiring its live-owner lock. */ export declare function prepareProcessJobStateDirectory(agentRoot: string, stateDir: string): Promise; /** Read-only migration probe for one exact configured/default durable store. */ export declare function hasExactProcessJobStateMarkers(agentRoot: string, stateDir: string): Promise; export declare function loadOrCreateProcessJobSecret(stateDir: string): Promise; /** Persist only a bounded, secret-free health fact for detached status/doctor readers. */ export declare function recordProcessJobHealthIncident(stateDir: string, operation: string, detectedAt?: Date): Promise; /** Clear a prior runtime incident only after startup recovery and retention succeed. */ export declare function clearProcessJobHealthIncident(stateDir: string): Promise; export declare function processJobOperatorToken(secret: Uint8Array): string; export declare function projectProcessJob(record: DurableProcessJobRecord): ProcessJobProjection; export declare function isTerminalProcessJobState(state: ProcessJobState): boolean; /** Validate the exact durable wake identity, including its normalized base. */ export declare function isProcessJobOriginRecord(value: unknown): value is ProcessJobOriginRecord; //# sourceMappingURL=process-jobs-store.d.ts.map