import type { ThreadRecord, ThreadId } from '../core/types/thread-types.js'; declare class ThreadRepo { /** In-memory source of truth for all thread records. All sync reads come from here. */ private map; private repo; /** Serializes all persist operations (set, delete, mutate, lifecycle). */ private mutex; /** Promise chain for `set()`/`delete()`-initiated persists, guarded by this.mutex. */ private _pendingPersist; /** Load threads from disk into memory. Populates the Map from threads.json. */ load(): void; generateId(): ThreadId; get(id: ThreadId): ThreadRecord | null; /** * Insert or replace a thread record. Updates `updatedAt` and queues a persist. * Map update is synchronous; disk write is queued through the mutex. * Returns the persist promise for callers that need to await it. */ set(record: ThreadRecord): Promise; /** Remove a thread and queue a persist. */ delete(id: ThreadId): Promise; /** * Mutate a single thread's record in-place, updating `updatedAt` and persisting. * Awaits any pending `set()`/`delete()` persists, then acquires the mutex for * a serialized read-modify-write. */ mutate(id: ThreadId, fn: (t: ThreadRecord) => void): Promise; /** Await all pending `set()`/`delete()` disk writes AND any in-flight `mutate()`. * For graceful SIGTERM drain and test cleanup. * Two awaits because set/delete queue through _pendingPersist while mutate/cleanup/ * markRunningAsFailedOnStartup acquire this.mutex directly after awaiting the chain. */ flush(): Promise; findByChannel(channel: string): ThreadRecord[]; findByProject(projectId: string): ThreadRecord[]; findByPlatformThread(channel: string, platformThreadId: string): ThreadRecord | null; findActive(channel: string): ThreadRecord | null; getAll(): ThreadRecord[]; /** Does this waiting record still await any live (open/pending, unblocked) child TASK? * Reads TASKS.yaml via the zero-dependency core parser (store → core is layer-legal). */ private hasLiveTaskChildren; markRunningAsFailedOnStartup(): Promise; /** Remove threads older than maxAge (default 7 days), including workspace directories. * Auto-records (no workspace) use a shorter 24h TTL since they only need to * survive long enough for !thread add chaining. */ cleanup(maxAgeMs?: number): Promise; /** Queue a persist through the mutex, chaining off any prior persist. Returns the promise. * Errors are caught at the chain level so a single I/O failure does not poison all subsequent * writes (returning a rejected chain would short-circuit every follow-up `.then`). */ queuePersist(): Promise; /** Atomically persist the entire Map to disk. Uses `repo.write()` (no read-modify-write needed). */ private persist; } export declare const threadStore: ThreadRepo; export {};