# Function compilePlan

- compilePlan(
  plan: {
  taskId: string;
  stages: {
  id: string;
  type: "analyze" | "validate" | "aggregate" | "execute" | "gate" | "route";
  pluginId: string;
  inputArtifacts: string[];
  outputArtifacts: string[];
  dependencies: string[];
  config: Record<string, unknown>;
  preferredCli?: string;
  maxRetries?: number;
  timeoutMs?: number;
  }[];
  policyGates: {
  id: string;
  afterStage: string;
  beforeStage: string;
  rules: string[];
  onFail: "warn"
  | "block"
  | "escalate";
  }[];
  estimatedCost: {
  totalTokensIn: number;
  totalTokensOut: number;
  estimatedCostUsd: number;
  modelCalls: number;
  };
  approvalRequired: boolean;
  maxIterations: number;
  timeoutMs: number;
  },
  options?: PlanCompileOptions,
  ): CompileResult

  Compiles a PlanContract into a CompiledGraph.

  - Each stage becomes a node with a handler (plugin-backed or placeholder)
  - Dependencies become fixed edges
  - Policy gates become gate nodes between stages
  - Stages with no dependencies get edges from START
  - Stages with no dependents get edges to END

  #### Parameters

  - plan: {
    taskId: string;
    stages: {
    id: string;
    type: "analyze" | "validate" | "aggregate" | "execute" | "gate" | "route";
    pluginId: string;
    inputArtifacts: string[];
    outputArtifacts: string[];
    dependencies: string[];
    config: Record<string, unknown>;
    preferredCli?: string;
    maxRetries?: number;
    timeoutMs?: number;
    }[];
    policyGates: {
    id: string;
    afterStage: string;
    beforeStage: string;
    rules: string[];
    onFail: "warn"
    | "block"
    | "escalate";
    }[];
    estimatedCost: {
    totalTokensIn: number;
    totalTokensOut: number;
    estimatedCostUsd: number;
    modelCalls: number;
    };
    approvalRequired: boolean;
    maxIterations: number;
    timeoutMs: number;
    }
  - `Optional` options: PlanCompileOptions

  #### Returns CompileResult

  - Defined in packages/nexus-agents/src/pipeline/plan-compiler.ts:43