/** * Thread registry CRUD operations for the memory system. * * Manages the thread_registry SQLite table — tracks all threads * (root, daily, branch, worker) with their configuration and status. */ import type { Database } from "./schema.js"; import type { IThreadRepository } from "../interfaces.js"; export interface ThreadRegistryEntry { id: number; threadId: number; name: string; type: "root" | "daily" | "branch" | "worker"; rootThreadId: number | null; badge: string; client: string; maxRetries: number; cooldownMs: number; keepAlive: boolean; dailyRotation: boolean; autonomousMode: boolean; telegramTopicId: number | null; identityPrompt: string | null; workingDirectory: string | null; createdAt: string; lastActiveAt: string | null; sessionResetAt: string | null; cleanShutdown: boolean; status: "active" | "archived" | "expired" | "exited"; archivedAt: string | null; summary: string | null; } type RegisterThreadEntry = { threadId: number; name: string; type: ThreadRegistryEntry["type"]; rootThreadId?: number; badge?: string; client?: string; maxRetries?: number; cooldownMs?: number; keepAlive?: boolean; dailyRotation?: boolean; workingDirectory?: string; }; type UpdateThreadPatch = Partial>; export declare class ThreadRepository implements IThreadRepository { registerThread(db: Database, entry: RegisterThreadEntry): ThreadRegistryEntry; updateThread(db: Database, threadId: number, updates: UpdateThreadPatch): boolean; archiveThread(db: Database, threadId: number): boolean; getThread(db: Database, threadId: number): ThreadRegistryEntry | null; getAllThreads(db: Database): ThreadRegistryEntry[]; getRootThreads(db: Database): ThreadRegistryEntry[]; } export declare const threadRepository: ThreadRepository; export declare function registerThread(db: Database, entry: RegisterThreadEntry): ThreadRegistryEntry; export declare function getThread(db: Database, threadId: number): ThreadRegistryEntry | null; export declare function getThreadByName(db: Database, name: string): ThreadRegistryEntry | null; export declare function getThreadsByRoot(db: Database, rootThreadId: number): ThreadRegistryEntry[]; export declare function getRootThreads(db: Database): ThreadRegistryEntry[]; /** * All non-worker, non-archived threads. The nightly memory pass (consolidation, * reflection, narrative) runs for every one of these — memory integrity is * required by all threads, not just those opted into session rotation. Workers * are excluded because their memory is no-persist (discarded on decommission). */ export declare function getConsolidationThreads(db: Database): ThreadRegistryEntry[]; export declare function getKeepAliveThreads(db: Database): ThreadRegistryEntry[]; export declare function getAllThreads(db: Database): ThreadRegistryEntry[]; export declare function getActiveThreads(db: Database): ThreadRegistryEntry[]; /** All non-archived threads — for dashboard display. */ export declare function getDashboardThreads(db: Database): ThreadRegistryEntry[]; export declare function updateThread(db: Database, threadId: number, updates: UpdateThreadPatch): boolean; export declare function archiveThread(db: Database, threadId: number): boolean; export declare function unarchiveThread(db: Database, threadId: number): boolean; export declare function getArchivedThreads(db: Database): ThreadRegistryEntry[]; export declare function deleteThread(db: Database, threadId: number): boolean; /** * Purge archived threads older than `maxAgeMs` (default 180 days). * Deletes the thread's associated data and registry entry. * Returns the number of threads purged. */ export declare function purgeOldArchivedThreads(db: Database, maxAgeMs?: number): number; /** * Reset the daily session timestamp for a thread. * Sets session_reset_at = now, used by bootstrap to filter the message buffer. */ export declare function resetDailySession(db: Database, threadId: number): boolean; /** * Mark a thread's session as running (clean_shutdown = 0). Called at session * start; if the process dies before a graceful exit flips it back to 1, the * next resume sees 0 and knows the previous session was interrupted. */ export declare function markSessionRunning(db: Database, threadId: number): boolean; /** * Mark cleanly shut down every active thread whose agent process was still * alive at graceful exit (SIGTERM/SIGINT, maintenance restart), so a planned * server stop is not mistaken for a crash by the threads it takes down. * A thread that had already crashed lingers as status='active' but is absent * from aliveThreadIds, so its clean_shutdown stays 0 and the next resume * correctly detects the interruption. An empty list marks nothing. */ export declare function markAliveThreadsCleanShutdown(db: Database, aliveThreadIds: number[]): number; /** * Resolve the Telegram topic ID for a logical thread. * Returns telegram_topic_id if set, otherwise falls back to thread_id itself. */ export declare function resolveTelegramTopicId(db: Database, threadId: number): number; /** * Returns the explicit telegram_topic_id for a thread, or null if not set. * Unlike resolveTelegramTopicId, does NOT fall back to threadId. * Use this for destructive operations (topic deletion) to avoid accidentally * deleting a root thread's topic when a worker's telegram_topic_id is NULL. */ export declare function getExplicitTelegramTopicId(db: Database, threadId: number): number | null; /** * Backfill thread names from topic_registry for threads with empty/missing names. * Returns the number of threads updated. */ export declare function backfillMissingNames(db: Database): number; export {}; //# sourceMappingURL=thread-registry.d.ts.map