/** * Session writer for main session `.md` knowledge files. * * Creates and manages Markdown files with YAML frontmatter under * `.hivemind/session-tracker/{sessionID}/`. All writes use atomic rename. * * Uses `gray-matter` for frontmatter parsing and `yaml` for YAML serialization. * * @module session-tracker/persistence/session-writer */ import type { SessionRecord, JourneyEntry, ChildRef } from "../types.js"; /** * Manages the main session `.md` knowledge file for a single session. * * Files are stored at: * `.hivemind/session-tracker/{sessionID}/{sessionID}.md` * * Writes are append-per-event (D-04) with atomic rename (D-03). */ export declare class SessionWriter { private projectRoot; /** * @param deps - Injected dependencies. * @param deps.projectRoot - Absolute path to the project root. */ constructor(deps: { projectRoot: string; }); /** * Creates the session subdirectory under `.hivemind/session-tracker/`. * * @param sessionID - The session identifier. * @returns The absolute path to the created directory. */ createSessionDir(sessionID: string): Promise; /** * Gets the absolute path to the main session `.md` file. * * @param sessionID - The session identifier. * @returns Absolute path to the session .md file. */ private getSessionFilePath; /** * Writes the initial `.md` file with YAML frontmatter. * * @param sessionID - The session identifier. * @param metadata - Frontmatter data to write. * @returns Promise that resolves when the file is written. */ initializeSessionFile(sessionID: string, metadata: Partial): Promise; /** * Appends a user turn section to the session `.md` file. * * @param sessionID - The session identifier. * @param turnNumber - The one-based turn number. * @param content - The user's message content. * @returns Promise that resolves when the turn is appended. */ appendUserTurn(sessionID: string, turnNumber: number, content: string): Promise; /** * Appends an assistant response section to the session `.md` file. * * Writes the full (unpruned) assistant text so every turn is preserved * in the body, not just the lastMessage in frontmatter. * * @param sessionID - The session identifier. * @param turnNumber - The one-based assistant turn number. * @param content - The assistant's full response text (no pruning). * @returns Promise that resolves when the turn is appended. */ appendAssistantTurn(sessionID: string, turnNumber: number, content: string): Promise; /** * Appends a `main_l0_agent` section to the session `.md` file. * * @param sessionID - The session identifier. * @param agentName - The agent's display name. * @param model - The model identifier. * @param thinkingDuration - Optional thinking duration string (e.g. "19.7s"). * @param content - Optional assistant response text content to capture. * @returns Promise that resolves when the section is appended. */ appendAgentBlock(sessionID: string, agentName: string, model: string, thinkingDuration?: string, content?: string): Promise; /** * Appends a `### Tool:` subsection to the session `.md` file. * * @param sessionID - The session identifier. * @param toolName - The name of the tool invoked. * @param input - The tool's input arguments (will be JSON-stringified). * @param outputPruned - Optional pruned output to include. * @param error - Optional error message to include. * @returns Promise that resolves when the tool block is appended. */ appendToolBlock(sessionID: string, toolName: string, input: unknown, outputPruned?: string, error?: string): Promise; /** * Appends a compaction block to the session `.md` file (D-10). * * Captures the timestamp and references session-continuity.json for * post-compaction context recovery. * * @param sessionID - The session identifier. * @param block - The compaction block markdown content. * @returns Promise that resolves when the block is appended. */ appendCompactionBlock(sessionID: string, block: string): Promise; /** * Reads, merges, and atomically writes updated frontmatter. * * Parses existing YAML frontmatter via `gray-matter`, merges the provided * updates, and writes back atomically. Preserves body content. * * @param sessionID - The session identifier. * @param updates - Partial frontmatter fields to merge. * @returns Promise that resolves when the update is written. */ updateFrontmatter(sessionID: string, updates: Partial): Promise; /** * Checks if the main session file exists on disk. * * @param sessionID - The session identifier. * @returns True if the file exists on disk. */ sessionFileExists(sessionID: string): Promise; /** * Appends a child reference to the root session `.md` frontmatter's * `children` array. Prevents duplicates by checking for existing * sessionID entries before appending. * * This fixes Bug A where `children: []` was never populated after * child sessions were created (Phase 23.2). * * @param rootSessionID - The root/main session whose `.md` file to update. * @param childRef - The child reference to append. * @returns Promise that resolves when the update is written. */ addChildRef(rootSessionID: string, childRef: ChildRef): Promise; /** * Appends a journey entry section to the session `.md` file. * * Journey entries record tool calls, results, and assistant messages * for audit and recovery purposes (CP-ST-05-02). * * @param sessionID - The session identifier. * @param entry - The journey entry to append. * @returns Promise that resolves when the entry is appended. */ appendJourneyEntry(sessionID: string, entry: JourneyEntry): Promise; } //# sourceMappingURL=session-writer.d.ts.map