import { type SessionState } from '../hooks/session.js'; export declare const VERIFIED_SESSION_BINDING_FIELDS: readonly ['session_id', 'native_session_id', 'codex_session_id', 'previous_native_session_id', 'owner_omx_session_id', 'owner_codex_session_id']; export type VerifiedSessionBindingField = (typeof VERIFIED_SESSION_BINDING_FIELDS)[number]; export type CanonicalSessionBindingStatus = 'resolution-error' | 'absent' | 'read-error' | 'malformed' | 'missing-recorded-cwd' | 'root-mismatch' | 'foreign-cwd' | 'usable' | 'stale-dead' | 'identity-indeterminate'; export interface CanonicalSessionBindingSnapshot { cwd: string; status: CanonicalSessionBindingStatus; rootSource?: StateRootSource; baseStateDir?: string; selectedSessionJson?: string; recordedCwd?: string; state?: SessionState; raw?: string; liveness?: 'usable' | 'stale-dead' | 'identity-indeterminate'; verifiedAliases: Partial>; } export declare const SESSION_ID_PATTERN: RegExp; export declare const STATE_MODE_SEGMENT_PATTERN: RegExp; export declare const WRITABLE_STATE_SCOPE_ERRORS: { readonly unusableSession: 'Cannot resolve writable state scope: session.json is present but unusable.'; readonly unboundEnvironment: 'Cannot resolve writable state scope: OMX_SESSION_ID is not bound to session.json.'; readonly sessionBindingMismatch: 'Cannot resolve writable state scope: OMX_SESSION_ID does not match the live session recorded in session.json.'; readonly scopeChangedDuringWrite: 'Cannot commit the state write: the writable state scope changed while the write was in progress.'; }; export type StateRootSource = 'team-env' | 'omx-root-env' | 'omx-state-root-env' | 'session-authority' | 'cwd-default'; export type SessionScopeSource = 'explicit' | 'env' | 'session-json' | 'native-alias' | 'root'; export interface ResolvedSessionMetadata { sessionId: string; nativeSessionId?: string; nativeSessionAliases: string[]; ownerOmxSessionId?: string; ownerCodexSessionId?: string; ownerCodexThreadId?: string; leaderPaneId?: string; tmuxSessionName?: string; displayName?: string; raw?: SessionState; sourcePath?: string; } export interface ResolvedRuntimeStateScope { cwd: string; baseStateDir: string; stateDir: string; rootSource: StateRootSource; sessionId?: string; source: SessionScopeSource; metadata?: ResolvedSessionMetadata; isSessionScoped: boolean; authoritativeActiveDirs: string[]; compatibilityReadDirs: string[]; } export type StateFileScope = 'root' | 'session'; export interface ModeStateFileRef { mode: string; path: string; scope: StateFileScope; } export declare function normalizeSessionId(sessionId: unknown): string | undefined; export declare function validateSessionId(sessionId: unknown): string | undefined; export declare function validateStateModeSegment(mode: unknown): string; export declare function getStateFilename(mode: string): string; export declare function validateStateFileName(fileName: unknown): string; export declare function resolveWorkingDirectoryForState(workingDirectory?: string, env?: NodeJS.ProcessEnv): string; export declare function getBaseStateDirWithSource(workingDirectory?: string, env?: NodeJS.ProcessEnv): { baseStateDir: string; rootSource: StateRootSource; }; export declare function getBaseStateDir(workingDirectory?: string, env?: NodeJS.ProcessEnv): string; /** * Read the selected session pointer once and classify its canonical binding. * This is intentionally read-only: it never probes fallback roots, repairs * pointers, touches tmux, or mutates the supplied environment. */ export declare function readCanonicalSessionBindingSnapshot(workingDirectory?: string, env?: NodeJS.ProcessEnv): Promise; export declare function getStateDir(workingDirectory?: string, sessionId?: string): string; export declare function getStatePath(mode: string, workingDirectory?: string, sessionId?: string): string; export declare function getStateFilePath(fileName: string, workingDirectory?: string, sessionId?: string): string; export type StateScopeSource = 'explicit' | 'session' | 'root'; export interface ResolvedStateScope { source: StateScopeSource; sessionId?: string; stateDir: string; } export declare function readSessionMetadataFromBaseStateDir(cwd: string, baseStateDir?: string, options?: { allowLegacyBoundHud?: boolean; }): Promise; export declare function readCurrentSessionId(workingDirectory?: string): Promise; export type WritableCommitOperation = 'startMode' | 'updateModeState' | 'state_write' | 'state_clear' | 'completeRalplanSession'; export type WritableCommitKind = 'write' | 'unlink'; export type WritableCommitSite = 'transition.source-mode-detail' | 'mode.primary' | 'run-state.mode-sync' | 'skill-active.root-copy' | 'skill-active.session-copy' | 'skill-active.session-unlink' | 'state-clear.primary' | 'native-stop.root' | 'native-stop.session' | 'ralplan.root-state' | 'ralplan.session-state' | 'ralplan.root-skill-write' | 'ralplan.root-skill-unlink' | 'ralplan.session-skill-write'; export interface WritableCommitAttempt { site: WritableCommitSite; kind: WritableCommitKind; path: string; } export interface WritableScopeRevalidationEvent extends WritableCommitAttempt { operation: WritableCommitOperation; commitOrdinal: number; } export type BeforeWritableCommit = (event: WritableCommitAttempt) => Promise; export interface WritableStateScopeTestHooks { beforeRecoveryReread?: () => Promise; beforeScopeRevalidation?: (event: Readonly) => Promise; onSelectedDecisionSnapshotRead?: (event: Readonly<{ ordinal: number; raw: string; }>) => void; onRecoveryStabilityReread?: (event: Readonly<{ ordinal: number; raw: string | undefined; }>) => void; } export declare function __setWritableStateScopeTestHooksForTests(hooks: WritableStateScopeTestHooks): void; /** * Writable scope precedence: * - explicit session_id preserves explicit fork writes; * - a usable session.json supplies the only implicit session scope; * - OMX_SESSION_ID may bind a known alias only when the live tmux pane proves * the canonical session tag; * - a stale-dead session.json yields to an explicit exact-current * OMX_SESSION_ID binding (the dead owner holds no authority; SessionStart * remains the only pointer writer); * - an identity-indeterminate session.json may recover only when OMX_SESSION_ID * exactly matches the pointer's own session_id (the owner may still be alive, * so unlike stale-dead recovery, no looser validated binding is accepted); * - root writes are allowed only when session.json is absent. */ export declare function resolveWritableStateScope(workingDirectory?: string, explicitSessionId?: string): Promise; /** * Point-in-time check performed immediately before the caller's commit. It * reduces, but does not eliminate, the window for a pointer or root * publication to move the selected target: one can still land after this * check returns and before the caller's write, rename, or unlink. Multi-file * sequences are not atomic. */ export declare function assertWritableStateScopeUnchanged(workingDirectory: string | undefined, explicitSessionId: string | undefined, expected: ResolvedStateScope, expectedBaseStateDir: string, event?: Readonly): Promise; export declare function createWritableCommitRevalidator(options: { operation: WritableCommitOperation; cwd: string; explicitSessionId: string | undefined; capturedScope: ResolvedStateScope; baseStateDir: string; }): BeforeWritableCommit; export declare function resolveStateScope(workingDirectory?: string, explicitSessionId?: string): Promise; export declare function resolveRuntimeStateScope(workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getCompatibilityReadScopedStateDirs(workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getCompatibilityReadScopedStatePaths(mode: string, workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getCompatibilityReadScopedStateFilePaths(fileName: string, workingDirectory?: string, explicitSessionId?: string): Promise; /** * Read scope precedence: * - explicit session_id => session path only * - implicit current session => session path first, root as compatibility fallback * - no session => root path only * * This is a compatibility read surface. Do not use it for active-mode * decisions that drive Stop hooks or runtime continuation; use * getAuthoritativeActiveStateDirs instead so stale root state cannot * reactivate an explicitly session-scoped turn. */ export declare function getReadScopedStateDirs(workingDirectory?: string, explicitSessionId?: string): Promise; /** * Active-decision scope precedence: * - explicit/current session => that session path only, even if it is missing * - no session => root path only * * Stop hooks, list-active, and other continuation gates should use this path * instead of compatibility reads. A missing session directory means no active * state for that session; root fallback remains available only to explicit * read/status compatibility surfaces. */ export declare function getAuthoritativeActiveStateDirs(workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getAuthoritativeActiveStatePaths(mode: string, workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getReadScopedStatePaths(mode: string, workingDirectory?: string, explicitSessionId?: string): Promise; export declare function getReadScopedStateFilePaths(fileName: string, workingDirectory?: string, explicitSessionId?: string, options?: { rootFallback?: boolean; }): Promise; export declare function getAllSessionScopedStatePaths(mode: string, workingDirectory?: string): Promise; export declare function getAllScopedStatePaths(mode: string, workingDirectory?: string): Promise; export declare function getAllSessionScopedStateDirs(workingDirectory?: string): Promise; export declare function getAllScopedStateDirs(workingDirectory?: string): Promise; export declare function isModeStateFilename(filename: string): boolean; export declare function listModeStateFilesWithScopePreference(workingDirectory?: string, explicitSessionId?: string): Promise; //# sourceMappingURL=state-paths.d.ts.map