/** * Session-local continuity index writer. * * Manages the `session-continuity.json` file inside each main session's * subdirectory. Tracks parent-child hierarchy within a single session. * All writes use `atomicWriteJson()` for crash safety. * * File location: `.hivemind/session-tracker/{sessionID}/session-continuity.json` * * @module session-tracker/persistence/session-index-writer */ /** Minimal structured logger matching the harness pattern. */ interface Logger { debug: (msg: string, data?: unknown) => void; warn: (msg: string, data?: unknown) => void; error: (msg: string, data?: unknown) => void; } /** * Manages the session-local continuity index file. * * Provides methods to initialize the index, add child session references, * update child statuses, increment turn counts, and track tool usage. */ export declare class SessionIndexWriter { private projectRoot; private log; /** * Per-session serial write queues to prevent concurrent read-modify-write * corruption. Each session gets its own queue because SessionIndexWriter * writes to DIFFERENT files per session. */ private writeQueues; /** * Timestamp of the last successful write per session, used for stale * queue detection. */ private lastWriteTimes; /** * Threshold (in milliseconds) before a per-session queue is considered * stale and auto-reset. */ private static readonly STALE_QUEUE_MS; /** * @param deps - Injected dependencies. * @param deps.projectRoot - Absolute path to the project root. */ constructor(deps: { projectRoot: string; }); /** * Inject a structured logger. Default is no-op. * Called by the plugin composition root to wire the harness-level logger. */ setLogger(injected: Logger): void; /** * Returns the absolute path to the session-continuity.json file. * * @param sessionID - The session identifier. * @returns Absolute file path. */ private getIndexPath; /** * Detects and resets a stale write queue for a given session. * * If no write has completed for this session within `STALE_QUEUE_MS`, * the queue is replaced with a fresh resolved promise so subsequent * writes are not blocked by a stuck preceding promise. * * @param sessionID - The session identifier. */ private detectStaleQueue; /** * Enqueues a write operation into the per-session serial queue. * * Stale-queue detection runs first to auto-recover from a frozen pipeline. * Chains the provided function onto the end of the session's write queue * so that only one write per session is in-flight at a time. Records * `lastWriteTime` on success. Errors are caught silently to prevent a * failed write from breaking the queue entirely. A final `.then()` ensures * the promise chain always resolves to void. * * @param sessionID - The session identifier (queue key). * @param fn - The write operation to enqueue. * @returns Promise that resolves when the enqueued write completes. */ private enqueueWrite; /** * Reads an existing index or returns a default. * * @param sessionID - The session identifier. * @returns The parsed index (or a new default if the file doesn't exist). */ private readIndex; /** * Creates a default session continuity index. * * @param sessionID - The session identifier. * @returns A fresh default index. */ private createDefault; /** * Initializes a new session-local continuity index file. * * Creates the session subdirectory and writes the default index atomically. * * @param sessionID - The session identifier. * @returns Promise that resolves when the index is written. */ initializeIndex(sessionID: string): Promise; /** * Adds a child session to the hierarchy tree and writes the updated index. * * When `parentSessionID` is provided, the child is inserted as a nested * entry under the specified parent within the hierarchy tree (RC-2). * * @param sessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param childFile - The child's `.json` filename. * @param depth - The delegation depth of the child. * @param delegatedBy - Who delegated this child (agent name). * @param parentSessionID - Optional nested parent session ID for L2+ children. * @returns Promise that resolves when the index is updated. */ addChild(sessionID: string, childSessionID: string, childFile: string, depth: number, delegatedBy: string, parentSessionID?: string): Promise; /** * Recursively finds a child entry in the hierarchy tree by session ID. * * Walks the nested `children` maps of each `ChildHierarchyEntry` until * the target session ID is found. Returns `undefined` if not found. * * @param children - The current level of children to search. * @param targetID - The session ID to find. * @returns The matching `ChildHierarchyEntry`, or `undefined`. */ private findChildEntry; /** * Updates a child session's status in the index. * * Uses recursive lookup to find nested children (L2+) within the * hierarchy tree. The full tree structure is preserved — no top-level * flattening occurs (RC-2). * * @param sessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param status - The new status (e.g. "completed", "error"). * @returns Promise that resolves when the index is updated. */ updateChildStatus(sessionID: string, childSessionID: string, status: string): Promise; /** * Increments the turn counter in the index. * * @param sessionID - The session identifier. * @returns Promise that resolves when the index is updated. */ incrementTurnCount(sessionID: string): Promise; /** * Increments the tool usage count for a specific tool in the index. * * @param sessionID - The session identifier. * @param toolName - The name of the tool to increment. * @returns Promise that resolves when the index is updated. */ updateToolSummary(sessionID: string, toolName: string): Promise; } export {}; //# sourceMappingURL=session-index-writer.d.ts.map