/** * Child writer for child session `.json` files. * * Creates and manages JSON files for delegation child sessions under the * parent session's subdirectory. All writes use atomic rename (D-03). * * Files are stored at: * `.hivemind/session-tracker/{parentSessionID}/{childSessionID}.json` * * @module session-tracker/persistence/child-writer */ import type { ChildSessionRecord, Turn, JourneyEntry } from "../types.js"; import type { HierarchyIndex } from "./hierarchy-index.js"; import type { ChildWriteRetryQueue } from "./retry-queue.js"; import type { HierarchyManifestWriter } from "./hierarchy-manifest.js"; export { readChildData, childFileExists } from "./child-reader.js"; /** * Manages child session `.json` files within the parent session's subdirectory. * * All writes use `atomicWriteJson()` for crash safety. */ export declare class ChildWriter { private projectRoot; /** * Optional hierarchy index for resolving the root main session directory. * When present, all child .json writes are routed to the root main's * directory instead of the immediate parent (D-03). */ private hierarchyIndex; /** * Retry queue for failed child writes (RC-5). * Failed writes are enqueued here for automatic retry with exponential backoff. */ private retryQueue; /** * Optional hierarchy manifest writer for syncing turnCount after turn appends. * When present, `appendChildTurn` updates the manifest's child turnCount. */ private manifestWriter; /** * Per-child serial write queues (key: `parentID/childID`). * Prevents concurrent read-modify-write corruption on child .json files. */ private writeQueues; /** * Per-child last write timestamps for stale queue detection. */ private lastWriteTimes; /** * Delegation context map (childID → { agentName, model }) for Bug D-2. * * Stores the agent name and model from the dispatch so that child-recorder * can use them as fallback when the chat.message hook payload has empty * agent/model fields. */ private delegationContext; /** * @param deps - Injected dependencies. * @param deps.projectRoot - Absolute path to the project root. * @param deps.hierarchyIndex - Optional hierarchy index for root main resolution (D-03). * @param deps.retryQueue - Optional retry queue for failed child writes (RC-5). * @param deps.manifestWriter - Optional manifest writer for turnCount sync (Bug C). */ constructor(deps: { projectRoot: string; hierarchyIndex?: HierarchyIndex; retryQueue?: ChildWriteRetryQueue; manifestWriter?: HierarchyManifestWriter; }); /** * Stores delegation context (agentName, model) for a child session. * * Called after child file creation when the dispatch context (from * PendingDispatchRegistry) is available. The stored values are later * retrieved by child-recorder as fallback for actor/model attribution. * * @param childSessionID - The child session identifier. * @param context - The delegation context with agentName and optional model. */ setDelegationContext(childSessionID: string, context: { agentName: string; model?: string; }): void; /** * Retrieves the stored delegation context for a child session. * * @param childSessionID - The child session identifier. * @returns The delegation context, or `undefined` if none was stored. */ getDelegationContext(childSessionID: string): { agentName: string; model?: string; } | undefined; /** * Resolves the correct parent directory for a child .json file. * * Per D-03: all children are stored under the ROOT main session directory, * not the immediate parent. If hierarchyIndex is available, the root main * session is resolved; otherwise falls back to the immediate parent. * * @param childID - The child session identifier. * @param immediateParentID - The immediate parent session identifier. * @returns The session ID whose directory should contain the child .json. */ private resolveWriteParent; /** * Checks if a child session `.json` file exists on disk. * * @param parentSessionID - The parent session ID. * @param childSessionID - The child session ID. * @returns True if the file exists on disk. */ childFileExists(parentSessionID: string, childSessionID: string): Promise; /** * Reads a child session record from disk using only the child session ID. * * @param sessionID - The child session identifier to look up. * @returns The parsed child session record, or `undefined` if not found. */ readChildData(sessionID: string): Promise; /** * Creates a new child session `.json` file. * * @param parentSessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param metadata - The initial child session record. * @returns Promise that resolves when the file is created. */ createChildFile(parentSessionID: string, childSessionID: string, metadata: ChildSessionRecord): Promise; /** * Updates the `status` field of a child session `.json` file. * * @param parentSessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param status - The new status value (e.g. "completed", "error"). * @returns Promise that resolves when the status is updated. * * Silently no-ops when the child file does not exist (ENOENT is caught). */ updateChildStatus(parentSessionID: string, childSessionID: string, status: string): Promise; /** * Appends a turn to the `turns` array of a child session `.json` file. * * @param parentSessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param turn - The turn record to append. * @returns Promise that resolves when the turn is appended. * * Silently no-ops when the child file does not exist (ENOENT is caught). */ appendChildTurn(parentSessionID: string, childSessionID: string, turn: Turn): Promise; /** * Appends a journey entry to the `journey` array of a child session `.json` file. * * @param parentSessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param entry - The journey entry to append. * @returns Promise that resolves when the entry is appended. * * Silently no-ops when the child file does not exist (ENOENT is caught). */ appendJourneyEntry(parentSessionID: string, childSessionID: string, entry: JourneyEntry): Promise; /** * Backfills real agent metadata into a child session `.json` file (F-18). * * @param parentSessionID - The parent session identifier. * @param childSessionID - The child session identifier. * @param metadata - The real agent metadata to backfill. * @returns Promise that resolves when the backfill completes (or no-ops). */ backfillChildMetadata(parentSessionID: string, childSessionID: string, metadata: { agentName: string; model?: string; description?: string; }): Promise; /** * Backfills/replaces turns for an existing child session .json file. * * Updates/merges the turns array and sets lastMessage to the latest assistant turn. */ backfillChildTurns(parentSessionID: string, childSessionID: string, turns: Turn[]): Promise; } //# sourceMappingURL=child-writer.d.ts.map