/** * Tool delegation handler for session tracker. * * Extracts child-session task delegation, polling, tool journey recording, * and utility methods from index.ts to satisfy the ≤500 LOC gate (GA-4). * * @module session-tracker/tool-delegation */ import type { OpenCodeClient } from "../../shared/session-api.js"; import type { SessionClassifier } from "./classification.js"; import type { SessionRouter } from "./session-router.js"; import type { ChildWriter } from "./persistence/child-writer.js"; import type { SessionIndexWriter } from "./persistence/session-index-writer.js"; import type { ProjectIndexWriter } from "./persistence/project-index-writer.js"; import type { HierarchyIndex } from "./persistence/hierarchy-index.js"; import type { PendingDispatchRegistry } from "./persistence/pending-dispatch-registry.js"; import type { HierarchyManifestWriter } from "./persistence/hierarchy-manifest.js"; import type { DelegationLifecycleStatus } from "./types.js"; export { pruneToolInput, pruneToolOutput, extractTaskID, extractTaskResult, deriveSubagentType, deriveAgentNameFromSession, asRecord } from "./tool-delegation-utils.js"; export { getDelegationEventLog, clearDelegationEventLog, recordDelegationTerminal } from "./delegation-event-log.js"; /** Dependencies injected by SessionTracker for tool delegation operations. */ export interface ToolDelegationDeps { client: OpenCodeClient; classifier: SessionClassifier; sessionRouter: SessionRouter; childWriter: ChildWriter; sessionIndexWriter: SessionIndexWriter; projectIndexWriter: ProjectIndexWriter; hierarchyIndex: HierarchyIndex; pendingRegistry: PendingDispatchRegistry; manifestWriter: HierarchyManifestWriter; projectRoot: string; } /** * Manages child-session task delegation, tool journey recording, * and proactive child session discovery via polling. * * Extracted from SessionTracker to keep index.ts under 500 LOC. * All methods are best-effort and catch errors internally. */ export declare class ToolDelegation { private readonly client; private readonly classifier; private readonly sessionRouter; private readonly childWriter; private readonly sessionIndexWriter; private readonly projectIndexWriter; private readonly hierarchyIndex; private readonly pendingRegistry; private readonly manifestWriter; /** Project root for trajectory/contract writes (used by createDelegationTrajectoryAndContract). */ private readonly projectRoot; /** * Creates a new ToolDelegation handler. * * @param deps - Injected dependencies from SessionTracker. */ constructor(deps: ToolDelegationDeps); /** * Handles the tool.execute.before hook — proactive child session discovery. * * Called synchronously from the plugin.ts tool.execute.before hook. * Must NOT block tool execution — fire-and-forget polling only. * * @param params - Hook input parameters. * @param params.sessionID - The parent session ID (tool executor's session). * @param params.callID - The tool call identifier. * @param params.subagentType - The subagent_type from task tool args. * @param params.description - The task description. * @param params.taskId - If present, this is a resume — skip registration. * @param params.tool - The tool name used for dispatch ("task" or "delegate-task"). */ handleToolExecuteBefore(params: { sessionID: string; callID: string; subagentType: string; description: string; taskId?: string; tool?: string; }): Promise; /** * Fire-and-forget polling loop to discover child sessions after task dispatch. * * Per SPEC §3.3: polls client.session.children() every 200ms for up to 5 attempts. * On discovery: registers child in HierarchyIndex and updates pending registry. * * @param parentID - The parent session ID to check children for. * @param callID - The tool call ID for pending registry cleanup. */ private pollForChildSessions; /** * Records a child-session tool event to the child `.json` journey array. * * @param parentID - Immediate parent session ID for the child session. * @param input - Tool execution hook input. * @param output - Tool execution hook output. * @param ensureChildRoute - Callback to ensure child route is registered. */ recordChildToolJourney(parentID: string, input: { tool: string; sessionID: string; callID: string; args: unknown; }, output: { title: string; output: unknown; metadata: unknown; }, ensureChildRoute: (parentID: string, childID: string) => Promise): Promise; /** * Records a child-session task delegation as an L2 child JSON record. * * @param parentID - Immediate parent session ID for the L1 session. * @param input - Task tool execution hook input from the child session. * @param output - Task tool execution hook output containing `task_id`. * @param ensureChildRoute - Callback to ensure child route is registered. */ recordChildTaskDelegation(parentID: string, input: { tool: string; sessionID: string; callID: string; args: unknown; }, output: { title: string; output: unknown; metadata: unknown; }, ensureChildRoute: (parentID: string, childID: string) => Promise): Promise; /** * P58 G6 (REQ-58-06, D-58-14): Emit a delegation-terminal event when a * delegation reaches a final state. Called from DelegationManager's * terminalFallback path and abortDelegation path. * * @param delegationId - The delegation id reaching terminal state. * @param status - The final status. Must be a DelegationLifecycleStatus. * @param tmuxSessionId - Optional tmux session id (null for delegations * without a tmux pane attachment; set for delegations that had a pane). */ recordDelegationTerminal(delegationId: string, status: DelegationLifecycleStatus, tmuxSessionId?: string | null): void; /** * Creates trajectory record and agent-work-contract for a delegation. * Delegates to delegation-trajectory.ts (GA-4 ≤500 LOC). */ private createDelegationTrajectoryAndContract; } //# sourceMappingURL=tool-delegation.d.ts.map