/** * Session event handler functions extracted from SessionTracker. * * Contains the event routing, classification, and dispatch logic * extracted from index.ts to satisfy the ≤500 LOC gate (GA-4). * * Each function is a standalone async function that receives a context * object with the dependencies it needs. The SessionTracker class methods * build the context from their `this.*` fields and delegate here. * * @module session-tracker/session-event-handler */ import type { OpenCodeClient } from "../../shared/session-api.js"; import type { HierarchyIndex } from "./persistence/hierarchy-index.js"; import type { SessionClassifier } from "./classification.js"; import type { ToolDelegation } from "./tool-delegation.js"; import type { MessageCapture } from "./capture/message-capture.js"; import type { SessionRouter } from "./session-router.js"; /** * All dependencies the extracted event handlers need from SessionTracker. * * The class builds this from `this.*` fields and passes it to each * handler function. This avoids circular imports and keeps the extraction * boundary clean. */ export interface TrackerHandlerContext { client: OpenCodeClient; projectRoot: string; classifier: SessionClassifier; hierarchyIndex: HierarchyIndex; toolDelegation: ToolDelegation; messageCapture: MessageCapture; bootstrappedSessions: Set; /** Optional capture/event handlers (may be undefined before init). */ eventCapture: { handleSessionEvent(event: unknown): Promise; } | undefined; toolCapture: { handleToolExecuteAfter(input: unknown, output: unknown): Promise; } | undefined; pendingRegistry: { refreshTimestamp(callID: string): void; } | undefined; childWriter: unknown; /** Truthiness-only: checked before fork child-copy logic. */ projectIndexWriter: unknown; /** Truthiness-only: checked before fork child-copy logic. */ sessionIndexWriter: unknown; /** Bootstrap helpers. */ bootstrap: { copyForkedChildren(newID: string, parentID: string): Promise; getSessionSafely(sessionID: string): Promise; }; /** Session router for classify-before-I/O routing. */ sessionRouter: SessionRouter; /** Child recorder for delegation message capture. */ childRecorder: { recordChildMessage(parentID: string, childID: string, msgInput: unknown, msgOutput: unknown): Promise; }; } /** * Handles session lifecycle events from the OpenCode `event` hook. * * @param ctx - Tracker handler context with all dependencies. * @param event - The raw hook input containing eventType, sessionID, and event payload. */ export declare function handleSessionEvent(ctx: TrackerHandlerContext, event: { eventType: string; sessionID: string; event: unknown; }): Promise; /** * Handles chat message events from the OpenCode `chat.message` hook. * * @param ctx - Tracker handler context with all dependencies. * @param input - The hook input containing sessionID, agent, model, messageID, variant. * @param output - The hook output containing the message and parts. * @param ensureSessionReady - Lazy-bootstrap a pre-existing session. */ export declare function handleChatMessage(ctx: TrackerHandlerContext, input: { sessionID: string; agent?: string; model?: { providerID: string; modelID: string; }; messageID?: string; variant?: string; }, output: { message: unknown; parts: unknown[]; }, ensureSessionReady: (sessionID: string) => Promise): Promise; /** * Handles tool execution events from the OpenCode `tool.execute.after` hook. * * @param ctx - Tracker handler context with all dependencies. * @param input - The hook input containing tool name, sessionID, callID, and args. * @param output - The hook output containing title, output, and metadata. * @param ensureSessionReady - Lazy-bootstrap a pre-existing session. */ export declare function handleToolExecuteAfter(ctx: TrackerHandlerContext, input: { tool: string; sessionID: string; callID: string; args: unknown; }, output: { title: string; output: unknown; metadata: unknown; }, ensureSessionReady: (sessionID: string) => Promise): Promise; /** * Checks whether a main-session markdown file already exists. * * Unknown sub-sessions must never create a new main directory. Existing main * sessions, however, may continue receiving message/tool captures after the * router reports `unknownSub` because SDK parent metadata can be absent. * * @param projectRoot - The project root path. * @param sessionID - Session ID to check. * @returns `true` when the main session `.md` file exists on disk. */ export declare function hasMainSessionFile(projectRoot: string, sessionID: string): Promise; /** * Recursively registers a parent session's own parent chain from SDK data. * * Includes MAX_DEPTH guard (F-13 / REQ-21-07) to prevent stack overflow * on corrupt SDK data or deep ancestor chains. * * @param ctx - Tracker handler context. * @param sessionID - Session whose ancestors should be registered. * @param seen - Cycle guard for defensive SDK data handling. * @param depth - Current recursion depth (internal, pass 0 on first call). */ export declare function ensureAncestorRoute(ctx: TrackerHandlerContext, sessionID: string, seen: Set, depth?: number): Promise; //# sourceMappingURL=session-event-handler.d.ts.map