/** * Session classification logic extracted from index.ts. * * Provides dual-gate (SDK parentID + hierarchy index) plus Gate 3 * (pending dispatch registry) classification for distinguishing * child sessions from main sessions. * * @module session-tracker/classification */ import type { HierarchyIndex } from "./persistence/hierarchy-index.js"; import type { PendingDispatchRegistry } from "./persistence/pending-dispatch-registry.js"; /** * Discriminated classification result — impossible to misroute. * * `kind: "root"` — explicit real root/main session confirmed by SDK root metadata. * `kind: "child"` — classified as child with known parent. * `kind: "unknownSub"` — all gates failed; defaults to child/sub treatment, never root. * * RC-3: `gate:"none"` is represented as `kind:"unknownSub"`, never as root/main. * Only an explicit real root/main user turn may create a main session directory. */ export type ClassificationResult = { kind: "root"; gate: "sdk"; } | { kind: "child"; parentID: string; gate: "sdk" | "hierarchy" | "pending" | "none"; } | { kind: "unknownSub"; gate: "none"; }; /** * Legacy shape for backward compatibility during migration. * Consumers that haven't been updated yet can use this helper. */ export interface LegacyClassificationResult { /** Parent session ID if classified as child, undefined if main session. */ parentID: string | undefined; /** How the classification was determined. */ gate: "sdk" | "hierarchy" | "pending" | "none"; } /** * Converts a discriminated ClassificationResult to the legacy shape. * * @param result - The new discriminated result. * @returns Legacy shape with parentID and gate. */ export declare function toLegacy(result: ClassificationResult): LegacyClassificationResult; /** * Classifies sessions as child or main using a three-gate fallback chain. */ export declare class SessionClassifier { private hierarchyIndex; private pendingRegistry; /** * @param deps - Injected dependencies. */ constructor(deps: { hierarchyIndex?: HierarchyIndex; pendingRegistry?: PendingDispatchRegistry; }); /** * Classifies a session as child or main using three-gate fallback. * * Gate 1: SDK parentID (fastest — avoids disk I/O). * Gate 2: Hierarchy index (fallback when SDK doesn't report parentID). * Gate 3: Pending dispatch registry (race condition guard). * * @param sessionID - The session to classify. * @param getSessionSafely - Function to fetch session from SDK. * @returns Classification result with parentID and gate used. */ classify(sessionID: string, getSessionSafely: (id: string) => Promise): Promise; /** * Updates the hierarchy index when a child session is discovered. * * @param parentID - The parent session ID. * @param childID - The child session ID. */ registerChild(parentID: string, childID: string): void; /** * Updates the pending registry with a real child ID. * * @param callID - The tool call ID. * @param childID - The discovered child session ID. */ updatePendingWithChildID(callID: string, childID: string): void; /** * Checks if a child is already registered in the hierarchy index. * * @param childID - The child session ID. * @returns `true` if already registered. */ isChildRegistered(childID: string): boolean; } //# sourceMappingURL=classification.d.ts.map