/** * Hierarchy manifest writer for D-07. * * Writes `hierarchy-manifest.json` in each root main session directory. * This is the AUTHORITATIVE source for the session delegation tree, * replacing ad-hoc gate decisions. * * Uses atomic-write pattern (write-to-tmp → rename) matching the * `atomicWriteJson` utility for crash safety (D-03). * * @module session-tracker/persistence/hierarchy-manifest */ import type { HierarchyManifest, HierarchyManifestChild } from "../types.js"; /** * Persists and reads the hierarchy manifest for each root main session. * * Each root main session directory contains a `hierarchy-manifest.json` * that is the single authoritative source for the session delegation tree. * All child sessions (L1, L2, ...) are registered here with their current * status, depth, and metadata. */ export declare class HierarchyManifestWriter { private projectRoot; /** * @param deps - Injected dependencies. * @param deps.projectRoot - Absolute path to the project root directory. */ constructor(deps: { projectRoot: string; }); /** * Adds or updates a child entry in the root main's `hierarchy-manifest.json`. * * If the child already exists, its metadata is overwritten. Otherwise a * new entry is created with status "active" and turnCount 0. * * @param params - Child entry parameters. * @param params.rootMainSessionID - The root main session that owns the manifest. * @param params.childSessionID - The child session ID to register. * @param params.parentSessionID - The immediate parent of this child. * @param params.delegationDepth - Delegation depth (1 = L1, 2 = L2, etc.). * @param params.delegatedBy - Agent name that performed the delegation. * @param params.subagentType - Subagent type dispatched. * @param params.childFile - Filename of the child .json file. * @returns Promise that resolves when the manifest has been atomically written. */ addChild(params: { rootMainSessionID: string; childSessionID: string; parentSessionID: string; delegationDepth: number; delegatedBy: string; subagentType: string; childFile: string; status?: string; /** * Optional delegation discriminator. Set at the * writer call site (never derived from event payloads — R7 mitigation). */ delegationType?: import("../types.js").DelegationType; }): Promise; /** * Updates the status of a child in the manifest. * * Silently no-ops if the child is not found in the manifest (the child * may belong to a different root main session). * * @param rootMainSessionID - The root main session that owns the manifest. * @param childSessionID - The child session ID to update. * @param status - New status (e.g. "idle", "completed", "error"). * @returns Promise that resolves when the manifest has been updated. */ updateChildStatus(rootMainSessionID: string, childSessionID: string, status: string): Promise; /** * Updates the turnCount for a child session in the manifest. * * Called after each turn append to keep the manifest's turnCount in sync * with the actual number of turns in the child `.json` file. * Silently no-ops if the child is not found in the manifest. * * @param rootMainSessionID - The root main session that owns the manifest. * @param childSessionID - The child session ID to update. * @param turnCount - The current number of turns in the child session. * @returns Promise that resolves when the manifest has been updated. */ updateTurnCount(rootMainSessionID: string, childSessionID: string, turnCount: number): Promise; /** * Returns all child entries from the manifest. * * @param rootMainSessionID - The root main session that owns the manifest. * @returns Promise resolving to a Record of child entries keyed by sessionID. */ getChildren(rootMainSessionID: string): Promise>; /** * Returns a single child entry, or `undefined` if not found. * * @param rootMainSessionID - The root main session that owns the manifest. * @param childSessionID - The child session ID to look up. * @returns Promise resolving to the child entry, or undefined. */ getChild(rootMainSessionID: string, childSessionID: string): Promise; /** * Generates a flattened hierarchy manifest from the continuity tree. * * Per G-1: The continuity tree is the canonical hierarchy source. * The manifest is a derivative cache — generated from the tree at read time * to eliminate drift between the two stores. * * Walks all nested `hierarchy.children` entries in the session-continuity.json * file and flattens them into a single `Record`. * * @param rootMainID - The root main session whose continuity tree to walk. * @returns A flattened hierarchy manifest. */ generateFromContinuity(rootMainID: string): Promise; /** * Loads the hierarchy manifest for a root main session. * * If the file does not exist or is unparseable, returns a fresh empty * manifest. Graceful degradation on parse failure — never throws. * * @param rootMainSessionID - The root main session that owns the manifest. * @returns Promise resolving to the loaded or default manifest. */ private loadManifest; /** * Atomically writes the hierarchy manifest to disk. * * Delegates to {@link atomicWriteJson} which handles write-to-tmp → rename * (D-03), cross-volume detection (G-5 / REQ-21-02), and temp file cleanup * (F-01 / REQ-21-01). * * @param rootMainSessionID - The root main session that owns the manifest. * @param manifest - The manifest to persist. */ private writeManifest; } //# sourceMappingURL=hierarchy-manifest.d.ts.map