/** * Delegated Work State - Pure helper for bounded subagent execution tracking. * * This module provides a minimal state machine for tracking delegated work * within the current session/branch. It is honest that this is ephemeral * session state, not provenance or cross-session tracking. * * Derived from: * - Subagent tool call arguments (ToolCallEvent.input for "subagent" tool) * - Subagent tool results (ToolResultMessage with toolName "subagent") * - Persisted tool result details (SubagentDetails) */ import type { ToolResultMessage } from "@apholdings/jensen-ai"; import type { ToolCallEvent } from "./extensions/index.js"; /** * Execution mode for a delegated task. */ export type DelegatedMode = "single" | "parallel" | "chain"; /** * Status of a delegated work item. */ export type DelegatedStatus = "active" | "completed" | "error" | "blocked"; /** * Minimal record of a single delegated subagent child task. * * For multi-task modes, multiple DelegatedTask records can share the same * parent toolCallId. `childIndex` disambiguates individual child work items * within one live subagent invocation. */ export interface DelegatedTask { /** Parent subagent tool call identifier. */ toolCallId: string; /** 1-based child position for parallel child tasks. */ childIndex?: number; /** Human-readable agent name. */ agent: string; /** Source scope of the agent (user, project, both, unknown). */ agentSource: "user" | "project" | "both" | "unknown"; /** The task description/prompt delegated to the agent. */ task: string; /** Execution mode: single, parallel, or chain. */ mode: DelegatedMode; /** Current status. */ status: DelegatedStatus; /** Step index for chain mode (1-based, when known). */ step?: number; /** Exit code from the child process (if available). */ exitCode?: number; /** Error or diagnostic message if failed. */ errorMessage?: string; /** Brief output preview extracted from final assistant message. */ outputPreview?: string; /** Tool call arguments as provided (for inspection). */ rawArgs?: Record; /** When the tool call was made. */ timestamp: number; } /** * Aggregated summary of delegated work state. * Used for UI display and debugging. */ export interface DelegatedWorkSummary { /** Tasks that are currently active (no result yet). */ active: DelegatedTask[]; /** Tasks that completed successfully. */ completed: DelegatedTask[]; /** Tasks that failed or were blocked. */ failed: DelegatedTask[]; /** Total tasks across all categories. */ total: number; /** Whether this is current-branch/session state (always true, for honesty). */ isSessionState: true; /** Note clarifying this is not provenance tracking. */ note: "ephemeral current-session state; not persisted across sessions or branches"; } /** * Extract delegated work items from a subagent tool call event. * * Honesty boundary: * - single mode -> one active child entry * - parallel mode -> one active child entry per requested child task * - chain mode -> only the first step is active at tool-call start */ export declare function extractDelegatedTasks(event: ToolCallEvent): DelegatedTask[]; /** * Backwards-compatible singular helper. * * Returns the first extracted delegated task, which preserves prior single-task * helper behavior for callers that only need a representative entry. */ export declare function extractDelegatedTask(event: ToolCallEvent): DelegatedTask | undefined; export declare function reconcileDelegatedResult(tasks: DelegatedTask[], result: ToolResultMessage): DelegatedTask[]; /** * Update a delegated task with result data from a persisted ToolResultMessage. * Returns the updated task or undefined if this result doesn't match. */ export declare function applyDelegatedResult(task: DelegatedTask, result: ToolResultMessage): DelegatedTask | undefined; /** * Build a summary of delegated work state. */ export declare function buildDelegatedWorkSummary(tasks: DelegatedTask[]): DelegatedWorkSummary; /** * Get the most recent tasks, optionally filtered by status. */ export declare function getRecentDelegatedTasks(tasks: DelegatedTask[], options?: { status?: DelegatedStatus; limit?: number; }): DelegatedTask[]; /** * Merge a new task into the existing task list. * If a task with the same logical identity exists, it is replaced. */ export declare function mergeDelegatedTask(tasks: DelegatedTask[], newTask: DelegatedTask): DelegatedTask[]; /** * Synchronize task states with persisted tool results. * This is the main reconciliation function that: * 1. Activates tasks from tool call events * 2. Updates tasks with result data * * Returns the updated task list. */ export declare function syncDelegatedWork(tasks: DelegatedTask[], toolCallEvents: ToolCallEvent[], toolResultMessages: ToolResultMessage[]): DelegatedTask[]; //# sourceMappingURL=delegated-work.d.ts.map