/** * Taskflow DSL — schema, types, and validation. * * A taskflow is a declarative, multi-phase workflow. Each phase delegates work * to a subagent (an isolated `pi` process). Phases form a DAG via `dependsOn`. */ import { Type, type Static } from "typebox"; import { type ComposedEffectFlowLike } from "./effects/validate.ts"; /** Hard cap on subagent calls made by one tree-reduce phase. This bounds * author mistakes even when no run budget was declared. */ export declare const TREE_REDUCE_HARD_MAX_CALLS = 256; /** Closed set of native phase kinds — single source of truth for DSL + FlowIR. */ export declare const PHASE_TYPES: readonly ["agent", "parallel", "map", "gate", "reduce", "approval", "flow", "loop", "tournament", "script", /** First completed branch wins (Horizon B). */ "race", /** Dynamic sub-DAG: nested sub-flow or graft-promote into parent (Horizon B). */ "expand"]; export type PhaseType = (typeof PHASE_TYPES)[number]; /** Phase kinds that execute one or more subagents and therefore require an * effective idle watchdog (or a finite wall timeout when the watchdog is off). */ export declare const AGENT_RUNNING_PHASE_TYPES: readonly ["agent", "gate", "reduce", "map", "parallel", "loop", "tournament", "race"]; /** Loop iteration bounds. Authors may lower the max; the hard cap is a runaway guard. */ export declare const LOOP_DEFAULT_MAX_ITERATIONS = 10; export declare const LOOP_HARD_MAX_ITERATIONS = 100; /** Max depth of runtime `flow { def }` sub-flow nesting (runaway guard for * LLM-generated sub-flows that themselves spawn more sub-flows). The existing * `_stack` recursion check guards saved-flow cycles; this bounds inline depth. */ export declare const MAX_DYNAMIC_NESTING = 5; /** Breadth caps applied ONLY to runtime-generated (`flow { def }`) sub-flows, * whose content is LLM-authored and therefore untrusted. Authored/saved flows * are not subject to these (a human reviewed them). They bound DoS blast radius * from a model emitting a graph with thousands of phases / a giant fan-out. */ export declare const MAX_DYNAMIC_PHASES = 100; export declare const MAX_DYNAMIC_MAP_ITEMS = 200; export declare const MAX_DYNAMIC_CONCURRENCY = 16; /** Tournament competitor bounds. */ export declare const TOURNAMENT_DEFAULT_VARIANTS = 3; export declare const TOURNAMENT_HARD_MAX_VARIANTS = 20; declare const TOURNAMENT_MODES: readonly ["best", "aggregate"]; /** @internal */ export type TournamentMode = (typeof TOURNAMENT_MODES)[number]; /** Cross-host thinking levels and compatibility aliases accepted by authored flows. */ export declare const THINKING_LEVELS: readonly ["off", "none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]; export type ThinkingLevel = (typeof THINKING_LEVELS)[number]; declare const CACHE_SCOPES: readonly ["run-only", "cross-run", "off"]; export type CacheScope = (typeof CACHE_SCOPES)[number]; declare const ParallelTaskSchema: Type.TObject<{ task: Type.TOptional; taskFile: Type.TOptional; agent: Type.TOptional; cwd: Type.TOptional; }>; /** Declarative retry policy for a phase's subagent call(s). */ declare const RetrySchema: Type.TObject<{ max: Type.TNumber; backoffMs: Type.TOptional; factor: Type.TOptional; }>; /** * Per-phase cache policy. Defaults to `run-only` which is exactly the historical * behavior (within-run resume only). `cross-run` opts a phase into the persistent * cross-run memoization store; see docs/rfc-cross-run-memoization.md. */ declare const CacheSchema: Type.TObject<{ scope: Type.TOptional>; ttl: Type.TOptional; fingerprint: Type.TOptional>; }>; /** Run-wide cost / token ceiling. Exceeding it halts the run (remaining phases skipped). */ declare const BudgetSchema: Type.TObject<{ maxUSD: Type.TOptional; maxTokens: Type.TOptional; }>; declare const PhaseSchema: Type.TObject<{ id: Type.TString; type: Type.TOptional>; agent: Type.TOptional; task: Type.TOptional; taskFile: Type.TOptional; over: Type.TOptional; as: Type.TOptional; branches: Type.TOptional; taskFile: Type.TOptional; agent: Type.TOptional; cwd: Type.TOptional; }>>>; /** * [race] When true (default), abort in-flight loser branches after the first branch * **succeeds** (best-effort `AbortSignal`). Race semantics are first-**success** * (failed settles do not win). Set `false` to let losers run to natural completion. */ cancelLosers: Type.TOptional; from: Type.TOptional>; /** * [reduce] How the aggregated `from[]` inputs are reduced. `'one-shot'` * (default) feeds all inputs to a single reducer call as `{previous.output}`. * `'tree'` batches the inputs (see `batchSize`) and runs intermediate * reducer calls over each batch, then reduces the round outputs until one * remains — useful when the aggregated input would exceed a single prompt. * Tree reduction uses the SAME agent/model/options/timeout/idleTimeout as * the phase and forces the imperative runtime (the event kernel falls back). * The corrected `{previous.output}` aggregation (all `from[]` sources) always * applies regardless of strategy. */ reduceStrategy: Type.TOptional>; /** [reduce] With `reduceStrategy:'tree'`, the max number of aggregated inputs * fed to each intermediate reducer call (>= 2). Ignored for one-shot. */ batchSize: Type.TOptional; use: Type.TOptional; /** [expand] Fragment source — string interpolation or inline Taskflow / phases (same as flow.def). */ def: Type.TOptional; /** [expand] nested (default) = isolated sub-flow; graft = run fragment then promote phase states onto the parent under prefixed ids. */ expandMode: Type.TOptional>; /** [expand] Max nodes accepted from a dynamic fragment (default 50, hard 100). */ maxNodes: Type.TOptional; with: Type.TOptional>; run: Type.TOptional]>>; input: Type.TOptional; timeout: Type.TOptional; /** * Idle watchdog override (ms) for agent-running phases. A positive value (>= 1000) * replaces the host default (300000ms): if a subagent produces no output for this * long it is killed as stalled. `0` DISABLES the watchdog — but then a finite * wall `timeout` (>= 1000) is REQUIRED on this phase so it can never hang forever. * Overrides the flow-level `idleTimeout`. Absent → flow-level or host default. */ idleTimeout: Type.TOptional; timeoutMs: Type.TOptional; onExpire: Type.TOptional>; until: Type.TOptional; maxIterations: Type.TOptional; convergence: Type.TOptional; reflexion: Type.TOptional; variants: Type.TOptional; judge: Type.TOptional; judgeAgent: Type.TOptional; mode: Type.TOptional>; dependsOn: Type.TOptional>; join: Type.TOptional>; when: Type.TOptional; retry: Type.TOptional; factor: Type.TOptional; }>>; output: Type.TOptional>; expect: Type.TOptional; model: Type.TOptional; thinking: Type.TOptional>; tools: Type.TOptional>; cwd: Type.TOptional; final: Type.TOptional; optional: Type.TOptional; idempotent: Type.TOptional; /** * Trusted Effects (0.3 MVP): declared side effects for this phase. * Validated by the effects verifier (`validateEffectIR`). See * docs/internal/0.3.0-trusted-effects-mvp.md and effects/types.ts. */ effects: Type.TOptional>>; concurrency: Type.TOptional; context: Type.TOptional>; contextLimit: Type.TOptional; onBlock: Type.TOptional>; eval: Type.TOptional>; score: Type.TOptional; cache: Type.TOptional>; ttl: Type.TOptional; fingerprint: Type.TOptional>; }>>; shareContext: Type.TOptional; }>; declare const ArgSpecSchema: Type.TUnion<[Type.TObject<{ type: Type.TOptional; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"string">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"relative-path">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"number">; default: Type.TOptional; minimum: Type.TOptional; maximum: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"boolean">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"enum">; values: Type.TArray>; default: Type.TOptional>; description: Type.TOptional; required: Type.TOptional; }>]>; export declare const TaskflowSchema: Type.TObject<{ name: Type.TString; description: Type.TOptional; version: Type.TOptional; args: Type.TOptional; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"string">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"relative-path">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"number">; default: Type.TOptional; minimum: Type.TOptional; maximum: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"boolean">; default: Type.TOptional; description: Type.TOptional; required: Type.TOptional; }>, Type.TObject<{ type: Type.TLiteral<"enum">; values: Type.TArray>; default: Type.TOptional>; description: Type.TOptional; required: Type.TOptional; }>]>>>; concurrency: Type.TOptional; budget: Type.TOptional; maxTokens: Type.TOptional; }>>; agentScope: Type.TOptional>; strictInterpolation: Type.TOptional; contextSharing: Type.TOptional; incremental: Type.TOptional; scriptCwd: Type.TOptional>; /** * Flow-level idle watchdog (ms) for all agent-running phases that don't set * their own `idleTimeout`. Positive (>= 1000) overrides the host default * (300000ms); `0` disables the watchdog for those phases — but then every * agent-running phase MUST declare a finite wall `timeout` (>= 1000) so the * flow can never hang forever. A per-phase `idleTimeout` overrides this. */ idleTimeout: Type.TOptional; /** * Fire-and-forget terminal notifications. Payload is summary-only * (`taskflow.hook.v1`) — never transcripts. Hook failure does not change run status. */ hooks: Type.TOptional; url: Type.TOptional; timeoutMs: Type.TOptional; path: Type.TOptional; run: Type.TOptional>; }>>>; onFail: Type.TOptional; url: Type.TOptional; timeoutMs: Type.TOptional; path: Type.TOptional; run: Type.TOptional>; }>>>; onBlocked: Type.TOptional; url: Type.TOptional; timeoutMs: Type.TOptional; path: Type.TOptional; run: Type.TOptional>; }>>>; }>>; phases: Type.TArray>; agent: Type.TOptional; task: Type.TOptional; taskFile: Type.TOptional; over: Type.TOptional; as: Type.TOptional; branches: Type.TOptional; taskFile: Type.TOptional; agent: Type.TOptional; cwd: Type.TOptional; }>>>; /** * [race] When true (default), abort in-flight loser branches after the first branch * **succeeds** (best-effort `AbortSignal`). Race semantics are first-**success** * (failed settles do not win). Set `false` to let losers run to natural completion. */ cancelLosers: Type.TOptional; from: Type.TOptional>; /** * [reduce] How the aggregated `from[]` inputs are reduced. `'one-shot'` * (default) feeds all inputs to a single reducer call as `{previous.output}`. * `'tree'` batches the inputs (see `batchSize`) and runs intermediate * reducer calls over each batch, then reduces the round outputs until one * remains — useful when the aggregated input would exceed a single prompt. * Tree reduction uses the SAME agent/model/options/timeout/idleTimeout as * the phase and forces the imperative runtime (the event kernel falls back). * The corrected `{previous.output}` aggregation (all `from[]` sources) always * applies regardless of strategy. */ reduceStrategy: Type.TOptional>; /** [reduce] With `reduceStrategy:'tree'`, the max number of aggregated inputs * fed to each intermediate reducer call (>= 2). Ignored for one-shot. */ batchSize: Type.TOptional; use: Type.TOptional; /** [expand] Fragment source — string interpolation or inline Taskflow / phases (same as flow.def). */ def: Type.TOptional; /** [expand] nested (default) = isolated sub-flow; graft = run fragment then promote phase states onto the parent under prefixed ids. */ expandMode: Type.TOptional>; /** [expand] Max nodes accepted from a dynamic fragment (default 50, hard 100). */ maxNodes: Type.TOptional; with: Type.TOptional>; run: Type.TOptional]>>; input: Type.TOptional; timeout: Type.TOptional; /** * Idle watchdog override (ms) for agent-running phases. A positive value (>= 1000) * replaces the host default (300000ms): if a subagent produces no output for this * long it is killed as stalled. `0` DISABLES the watchdog — but then a finite * wall `timeout` (>= 1000) is REQUIRED on this phase so it can never hang forever. * Overrides the flow-level `idleTimeout`. Absent → flow-level or host default. */ idleTimeout: Type.TOptional; timeoutMs: Type.TOptional; onExpire: Type.TOptional>; until: Type.TOptional; maxIterations: Type.TOptional; convergence: Type.TOptional; reflexion: Type.TOptional; variants: Type.TOptional; judge: Type.TOptional; judgeAgent: Type.TOptional; mode: Type.TOptional>; dependsOn: Type.TOptional>; join: Type.TOptional>; when: Type.TOptional; retry: Type.TOptional; factor: Type.TOptional; }>>; output: Type.TOptional>; expect: Type.TOptional; model: Type.TOptional; thinking: Type.TOptional>; tools: Type.TOptional>; cwd: Type.TOptional; final: Type.TOptional; optional: Type.TOptional; idempotent: Type.TOptional; /** * Trusted Effects (0.3 MVP): declared side effects for this phase. * Validated by the effects verifier (`validateEffectIR`). See * docs/internal/0.3.0-trusted-effects-mvp.md and effects/types.ts. */ effects: Type.TOptional>>; concurrency: Type.TOptional; context: Type.TOptional>; contextLimit: Type.TOptional; onBlock: Type.TOptional>; eval: Type.TOptional>; score: Type.TOptional; cache: Type.TOptional>; ttl: Type.TOptional; fingerprint: Type.TOptional>; }>>; shareContext: Type.TOptional; }>>; }>; export type ParallelTask = Static; export type Phase = Static; export type Taskflow = Static; export type ArgSpec = Static; export type RetryPolicy = Static; export type Budget = Static; export type CachePolicy = Static; export interface ShorthandStep { agent?: string; task?: string; /** Load-time include path; trusted loaders inline this into `task` before desugar. */ taskFile?: string; /** Files to pre-read and inject before the task (pass-through to Phase.context). */ context?: string[]; /** Max characters per context file (pass-through to Phase.contextLimit). */ contextLimit?: number; /** Working directory for this step's subagent (pass-through to Phase.cwd). * A literal path or a reserved workspace keyword ('temp'/'dedicated'/ * 'worktree'). A top-level `cwd` is the default; a step cwd overrides it. */ cwd?: string; } /** True when `def` is a shorthand spec (no `phases`, but a task/tasks/chain field). */ export declare function isShorthand(def: unknown): boolean; /** * Desugar a shorthand spec into a full Taskflow DAG. Throws if no recognizable * shorthand field is present. Carries through optional name/description/ * concurrency/agentScope/args. */ export declare function desugar(def: unknown): Taskflow; /** @internal */ export interface ValidationResult { ok: boolean; errors: string[]; /** Non-fatal issues the user should fix; e.g. `{steps.X}` references that * aren't declared in `dependsOn` (the phase will run in parallel with its * producer and see the literal placeholder). */ warnings: string[]; } /** * Parse a TTL string like '30m', '6h', '7d', '500ms', '90s' into milliseconds. * Returns null for malformed or non-positive values. Plain integers = ms. */ export declare function parseTtlMs(ttl: string): number | null; export interface ValidationOptions { /** Resolved invocation args, used for runtime checks like missing `{args.X}`. */ args?: Record; /** Runtime working directory, used for mismatch warnings (e.g. cwd vs args.codebase). */ cwd?: string; /** Override the flow's own `strictInterpolation` flag for this validation call. */ strict?: boolean; /** When true, this flow is a runtime-generated (`flow { def }`) sub-flow whose * content is LLM-authored / untrusted. Enables hardening checks: breadth caps * (phase count, map items, concurrency) and denial of cwd/context/script * resource capabilities until a FileBroker/sandbox exists. */ dynamic?: boolean; /** Optional saved-flow loader used to resolve `flow{use}` children during * effect label-flow validation. When provided, resolved children are checked * with their real effects; children the loader cannot resolve degrade to * advisory warnings (the runtime loader remains the authoritative gate). */ resolveFlow?: (name: string) => ComposedEffectFlowLike | undefined; /** When true, leftover `taskFile` is allowed (DSL compile / pre-load check). * XOR and dynamic-subflow bans still apply. Runtime loaders must inline. */ allowTaskFile?: boolean; } /** Validate resolved invocation values independently of full flow structure. * Runtime calls this at the Core boundary so direct, resume, and detached * execution cannot bypass adapter-level typed-arg checks. */ export declare function validateInvocationArgs(def: Pick, args: Record): string[]; export declare function validateTaskflow(def: unknown, opts?: ValidationOptions): ValidationResult; export declare function collectRefs(phase: Phase): { steps: string[]; args: string[]; }; /** Coerce a possibly-non-array field to an array so iteration never throws * "not iterable". validateTaskflow reports the non-array as a structured error; * every for..of over an array-shaped phase field routes through here. */ export declare function asArray(v: unknown): T[]; /** Effective dependency ids of a phase (dependsOn ∪ from). */ export declare function dependenciesOf(phase: Phase): string[]; /** * Transitive upstream dependency closure of a phase: every id reachable via * `dependsOn ∪ from`, including indirect ancestors. Cycle-safe (visited set). * Returns the closure EXCLUDING `phaseId` itself. Sorted for deterministic * hashing. Shares the exact edge semantics with `topoLayers`/`detectCycle` so * the closure is complete for every valid flow (validation already rejects * `{steps.X}` refs that aren't reachable via these edges, except for * `join: "any"` phases — handled by callers as needed). * * Hoisted out of `validateTaskflow` so `phaseFingerprint` (M6) and validation * share one source of truth for "what does this phase structurally depend on". */ export declare function transitiveDependencies(phases: Phase[], phaseId: string): string[]; /** Topologically ordered layers; phases in the same layer can run concurrently. */ export declare function topoLayers(phases: Phase[]): Phase[][]; /** Resolve which phase is the result-bearing phase. */ export declare function finalPhase(phases: Phase[]): Phase; /** * Apply a flow's declared arg defaults over the provided values, then pass * through any extra provided keys. Shared by the tool entrypoint (index) and the * sub-flow (`flow`) phase (runtime). */ export declare function resolveArgs(def: Taskflow, provided?: Record): Record; export {}; //# sourceMappingURL=schema.d.ts.map