/** * Writes a subagent's `result.json` audit file. * * When a subagent runs as a spawned child process (`--task-id `), the parent * SubagentPool verifies `.hoocode/dispatch//result.json` against a fixed * schema (see OutputVerifier). This module derives that file deterministically * from the finished session so subagents never have to write it themselves. */ import type { AgentMessage } from "@kolisachint/hoocode-agent-core"; import type { Task, TaskSource, TaskStatus } from "./task-store.js"; export interface SubagentUsage { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number; } /** * One node in a subagent's task subtree, propagated to the parent so nested * delegation (a subagent that spawns a subagent) is visible above the process * boundary. Serialized from the child's task store at session end and merged * under the dispatching task by the parent (see finalizeDispatchResult). The * `children` are the child's own delegations/MCP calls, recursively. */ export interface SubagentTaskNode { id: number; title: string; status: TaskStatus; /** Origin of the task (subagent/mcp; unset = the subagent's own TodoWrite plan). */ source?: TaskSource; subagentMode?: string; usage?: SubagentUsage; children: SubagentTaskNode[]; } export interface SubagentResultFile { summary: string; files_changed: string[]; confidence: number; status: "complete" | "partial" | "failed"; /** Token and cost usage for the subagent session (extra field; ignored by the verifier). */ usage?: SubagentUsage; /** * The child's own task subtree (its TodoWrite plan, delegations, and MCP calls) * so the parent can render nested work below the dispatching task. Extra field; * ignored by the verifier. */ task_tree?: SubagentTaskNode[]; } /** * Build the nested task forest from a flat task list, linking children to * parents via `parentTaskId`. Roots are tasks with no `parentTaskId`; each * node's children preserve store order. Used to serialize a subagent's task * store into its `result.json` for the parent to merge. */ export declare function buildTaskForest(tasks: readonly Task[]): SubagentTaskNode[]; /** Extra build options that override the status derived from the transcript. */ export interface BuildSubagentResultOptions { /** The run was stopped at its turn cap. Report a usable partial result rather than a failure. */ reachedMaxTurns?: boolean; } /** * Build the `result.json` payload for a finished subagent session. * * The verifier requires a non-empty summary and confidence >= 0.5, so a * successful run with no assistant text still yields a usable summary. * * When the run was stopped at its turn cap (`reachedMaxTurns`), the result is * reported as `partial` with whatever summary the agent managed to produce, * instead of the `failed` status an aborted final message would otherwise yield. */ export declare function buildSubagentResult(messages: readonly AgentMessage[], usage?: SubagentUsage, options?: BuildSubagentResultOptions): SubagentResultFile; /** Write `result.json` for a task. Best-effort: never throws. */ export declare function writeSubagentResult(cwd: string, taskId: string, result: SubagentResultFile): void; //# sourceMappingURL=subagent-result.d.ts.map