/** * Async execution logic for subagent tool */ import type { ExtensionAPI } from "@lpb-work/pi-coding-agent"; import type { AgentConfig } from "../../agents/agents.ts"; import { type ChainStep } from "../../shared/settings.ts"; import { type AcceptanceInput, type AgentContract, type ArtifactConfig, type Details, type JsonSchemaObject, type MaxOutputConfig, type NestedRouteInfo, type ResolvedControlConfig, type ResolvedToolBudget, type ResolvedTurnBudget, type SubagentRunMode, type ToolBudgetConfig, type UsageBudgetConfig } from "../../shared/types.ts"; import { type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts"; import type { ContextMode } from "../shared/context-mode.ts"; import { type AvailableModelInfo, type ParentModel } from "../shared/model-fallback.ts"; import type { ModelScopeConfig } from "../shared/model-scope.ts"; import type { RunnerStep } from "../shared/parallel-utils.ts"; import { type PermissionConfig } from "../shared/permissions.ts"; import type { SessionLeaseRequest } from "../shared/session-lease.ts"; import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.ts"; import type { ImportedAsyncRoot } from "./chain-root-attachment.ts"; interface AsyncExecutionContext { pi: ExtensionAPI; cwd: string; currentSessionId: string; /** Parent session id used by permission-system ask forwarding. */ parentSessionId?: string; permissions?: PermissionConfig; currentModelProvider?: string; currentModel?: ParentModel; /** Optional model-scope enforcement resolved from subagent settings. */ modelScope?: ModelScopeConfig; /** Whether the parent session has an interactive UI. */ interactive?: boolean; } interface AsyncChainParams { chain: ChainStep[]; task?: string; /** Raw caller-facing goal used only by the started event. */ goal?: string; attachRoot?: ImportedAsyncRoot & { agent: string; outputName?: string; label?: string; }; resultMode?: Exclude; agents: AgentConfig[]; ctx: AsyncExecutionContext; availableModels?: AvailableModelInfo[]; cwd?: string; maxOutput?: MaxOutputConfig; artifactsDir?: string; artifactConfig: ArtifactConfig; shareEnabled: boolean; sessionRoot?: string; agentContract?: AgentContract; chainSkills?: string[]; sessionFilesByFlatIndex?: (string | undefined)[]; thinkingOverridesByFlatIndex?: (AgentConfig["thinking"] | undefined)[]; contextForAgent?: (agentName: string) => ContextMode; progressDir?: string; dynamicFanoutMaxItems?: number; maxSubagentDepth: number; waitToolEnabled?: boolean; worktreeSetupHook?: string; worktreeSetupHookTimeoutMs?: number; worktreeBaseDir?: string; controlConfig?: ResolvedControlConfig; controlIntercomTarget?: string; childIntercomTarget?: (agent: string, index: number) => string | undefined; nestedRoute?: NestedRouteInfo; acceptance?: AcceptanceInput; timeoutMs?: number; turnBudget?: ResolvedTurnBudget; toolBudget?: ResolvedToolBudget; usageBudget?: UsageBudgetConfig; configToolBudget?: ResolvedToolBudget; /** Global cap on simultaneously-running subagent tasks within the async run. */ globalConcurrencyLimit?: number; capabilityCeiling?: ResolvedSubagentCapabilityCeiling; parentWorkflowRunId?: string; workflowKey?: string; } interface AsyncSingleParams { agent: string; task?: string; /** Raw caller-facing goal used only by the started event. */ goal?: string; agentConfig: AgentConfig; ctx: AsyncExecutionContext; cwd?: string; maxOutput?: MaxOutputConfig; artifactsDir?: string; artifactConfig: ArtifactConfig; shareEnabled: boolean; sessionRoot?: string; sessionDir?: string; sessionFile?: string; revivalLease?: SessionLeaseRequest; context?: ContextMode; skills?: string[]; output?: string | boolean; outputMode?: "inline" | "file-only"; outputBaseDir?: string; agentContract?: AgentContract; structuredOutputSchema?: JsonSchemaObject; modelOverride?: string; thinkingOverride?: AgentConfig["thinking"]; availableModels?: AvailableModelInfo[]; maxSubagentDepth: number; waitToolEnabled?: boolean; worktreeSetupHook?: string; worktreeSetupHookTimeoutMs?: number; worktreeBaseDir?: string; controlConfig?: ResolvedControlConfig; controlIntercomTarget?: string; childIntercomTarget?: (agent: string, index: number) => string | undefined; nestedRoute?: NestedRouteInfo; acceptance?: AcceptanceInput; timeoutMs?: number; absoluteDeadlineAt?: number; turnBudget?: { maxTurns: number; graceTurns?: number; }; toolBudget?: ResolvedToolBudget | ToolBudgetConfig; usageBudget?: UsageBudgetConfig; configToolBudget?: ResolvedToolBudget; allowZeroToolBudget?: boolean; capabilityCeiling?: ResolvedSubagentCapabilityCeiling; parentWorkflowRunId?: string; workflowKey?: string; } interface AsyncExecutionResult { content: Array<{ type: "text"; text: string; }>; details: Details; isError?: boolean; } export interface AsyncRunnerStepBuildParams { chain: ChainStep[]; task?: string; attachRoot?: ImportedAsyncRoot & { agent: string; outputName?: string; label?: string; }; resultMode?: SubagentRunMode; agents: AgentConfig[]; ctx: AsyncExecutionContext; availableModels?: AvailableModelInfo[]; cwd?: string; chainSkills?: string[]; sessionFilesByFlatIndex?: (string | undefined)[]; thinkingOverridesByFlatIndex?: (AgentConfig["thinking"] | undefined)[]; contextForAgent?: (agentName: string) => ContextMode; progressDir?: string; agentContract?: AgentContract; dynamicFanoutMaxItems?: number; maxSubagentDepth: number; waitToolEnabled?: boolean; worktreeBaseDir?: string; asyncDir: string; outputBaseDir?: string; validateOutputBindings?: boolean; toolBudget?: ResolvedToolBudget; configToolBudget?: ResolvedToolBudget; capabilityCeiling?: ResolvedSubagentCapabilityCeiling; } export type AsyncRunnerStepBuildResult = { steps: RunnerStep[]; runnerCwd: string; workflowGraph: ReturnType; eventChain: ChainStep[]; originalTask?: string; } | { error: string; }; export declare function formatAsyncStartedMessage(headline: string, interactive: boolean): string; /** * Check if jiti is available for async execution */ export declare function isAsyncAvailable(): boolean; /** * Resolve the detached runner next to the source or compiled executor. */ export declare function resolveAsyncRunnerPath(modulePath?: string): string; export declare function resolveAsyncRunnerLogPaths(cfg: object): { stdoutPath: string; stderrPath: string; } | undefined; export declare function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildParams): AsyncRunnerStepBuildResult; /** * Execute a chain asynchronously */ export declare function executeAsyncChain(id: string, params: AsyncChainParams): AsyncExecutionResult; /** * Execute a single agent asynchronously */ export declare function executeAsyncSingle(id: string, params: AsyncSingleParams): AsyncExecutionResult; export {}; //# sourceMappingURL=async-execution.d.ts.map