import type { RuntimeDriverName, RuntimeEvent, RuntimeSessionId, RuntimeSessionState } from "@pi-claude-code-agent/runtime"; import type { ClaudeCodeRuntime } from "@pi-claude-code-agent/runtime/internal"; export type SubagentRunner = "pi" | "claude-code-agent"; export type SubagentContextMode = "fresh" | "fork"; export type SubagentRunState = "queued" | "starting" | "running" | "idle" | "interrupted" | "failed" | "completed" | "stopped"; export interface SubagentDefinition { name: string; prompt?: string; runner?: SubagentRunner; cwd?: string; model?: string; } export interface StartRunInput { agent: SubagentDefinition; task: string; driver?: RuntimeDriverName; cwd?: string; model?: string; async?: boolean; context?: SubagentContextMode; } export interface RunResult { summary: string; events: RuntimeEvent[]; runtimeState: RuntimeSessionState; } export interface SubagentRunRecord { runId: string; runner: SubagentRunner; agentName: string; sessionId?: RuntimeSessionId; cwd: string; driver?: RuntimeDriverName; model?: string; state: SubagentRunState; context: SubagentContextMode; createdAt: string; updatedAt: string; lastActivityAt: string; task: string; result?: RunResult; note?: string; raw?: Record; } export interface SubagentRunChunk { items: RuntimeEvent[]; nextCursor: number; } export interface SubagentBackend { readonly runner: SubagentRunner; startRun(input: StartRunInput): Promise; statusRun(runId: string): Promise; listRuns(): Promise; eventsRun(runId: string, cursor?: number): Promise; interruptRun(runId: string): Promise; stopRun(runId: string): Promise; collectResult(runId: string): Promise; } export interface RuntimeSubagentBackendOptions { runtime?: ClaudeCodeRuntime; storageDir?: string; pollIntervalMs?: number; completionTimeoutMs?: number; needsAttentionAfterMs?: number; attentionPollIntervalMs?: number; } export interface PersistedRunStatus { runId: string; sessionId?: RuntimeSessionId; state: SubagentRunState; updatedAt: string; lastActivityAt: string; }