{"version":3,"file":"step-runner.mjs","names":[],"sources":["../../../../../../../ai/src/workflow/step-runner.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Logger } from \"@warlock.js/logger\";\nimport type { AgentResult } from \"../contracts/result/agent-result.type\";\nimport type { BaseReport } from \"../contracts/result/base-report.type\";\nimport type { AgentReport } from \"../contracts/result/execution-report.type\";\nimport type { AttemptEntry, StepSnapshot } from \"../contracts/result/step-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport type { RetryConfig } from \"../contracts/workflow/retry-config.type\";\nimport type { StepDefinition } from \"../contracts/workflow/step.contract\";\nimport type { WorkflowContext } from \"../contracts/workflow/workflow-context.type\";\nimport type { WorkflowEventHandlers } from \"../contracts/workflow/workflow.contract\";\nimport { mergeUsage } from \"../utils/compute-cost\";\nimport { withoutRunFrame, withRunFrame } from \"../utils/run-context\";\nimport {\n  AIError,\n  SchemaValidationError,\n  StepFailedError,\n  WorkflowCancelledError,\n  WorkflowError,\n} from \"../errors\";\nimport { createCancelledError, sleep } from \"./cancellation\";\nimport type { WorkflowEventSink } from \"./emitter\";\nimport { isAbortError, resolveBackoff, resolveRetryConfig } from \"./retry\";\nimport { cloneState, deepFreeze } from \"./state\";\n\n/**\n * Mutable snapshot used by the step runner — finalized (deep-frozen)\n * by the engine before being written to `ctx.steps` / `report.steps`.\n */\nexport type MutableStepSnapshot = {\n  output: unknown;\n  skipped: boolean;\n  status: \"completed\" | \"skipped\" | \"failed\";\n  startedAt: string;\n  endedAt: string;\n  duration: number;\n  attempts: number;\n  attemptHistory: AttemptEntry[];\n  error?: AIError;\n  state: Record<string, unknown>;\n  executionResult?: unknown;\n  agentReport?: AgentReport;\n  agentUsage?: Usage;\n  children?: BaseReport[];\n  steps?: Record<string, StepSnapshot>;\n};\n\n/**\n * Narrow an `executionResult` to an `AgentResult` when the step ran\n * an agent. Custom `run` steps return arbitrary values, so the\n * `type: \"agent\"` discriminant keeps us honest.\n */\nfunction asAgentResult(result: unknown): AgentResult<unknown> | undefined {\n  if (!result || typeof result !== \"object\") return undefined;\n  if ((result as { type?: unknown }).type !== \"agent\") return undefined;\n  return result as AgentResult<unknown>;\n}\n\nexport type ExecuteStepParams = {\n  step: StepDefinition;\n  state: Record<string, unknown>;\n  emitter: WorkflowEventSink;\n  executionHandlers?: WorkflowEventHandlers;\n  logger: Logger;\n  logModule: string;\n  signal?: AbortSignal;\n  buildContext: (current?: {\n    state: Record<string, unknown>;\n    agentResult?: unknown;\n  }) => WorkflowContext;\n  usage: Usage;\n  workflowDefaultRetry?: RetryConfig | false;\n  /**\n   * The enclosing workflow's own run-id — the `rootRunId` / `parentRunId`\n   * a `run` step's ambient {@link RunFrame} stamps onto anything it\n   * captures. `stampReportLineage`'s single authoritative pass (run once\n   * on the assembled workflow report) is what makes the exact value here\n   * safe to be provisional.\n   */\n  runId: string;\n  /** Propagated onto anything a `run` step's ambient run-frame captures. */\n  sessionId?: string;\n};\n\n/**\n * Drive one step's full lifecycle — skip evaluation, parallel\n * dispatch, retry loop around before → run|agent → output → after.\n * Returns a mutable snapshot; the engine deep-freezes it before\n * exposing.\n */\nexport async function executeStep(params: ExecuteStepParams): Promise<MutableStepSnapshot> {\n  const { step, emitter, executionHandlers, logger, logModule, signal } = params;\n  const startedAt = new Date().toISOString();\n  const stepStartPerf = performance.now();\n\n  params.step.on?.starting?.({ step: step.name });\n  emitter.emit(\"workflow.step.starting\", { step: step.name }, executionHandlers);\n  logger.debug(logModule, \"step.starting\", `${step.name} step starting`, {\n    step: step.name,\n  });\n\n  const stepState: Record<string, unknown> = cloneState(params.state);\n\n  // SKIP\n  try {\n    if (step.skip) {\n      const shouldSkip = await step.skip(params.buildContext({ state: stepState }));\n      if (shouldSkip) {\n        const endedAt = new Date().toISOString();\n        const duration = performance.now() - stepStartPerf;\n        emitter.emit(\"workflow.step.skipped\", { step: step.name }, executionHandlers);\n        logger.debug(logModule, \"step.skipped\", `${step.name} step skipped`, {\n          step: step.name,\n        });\n\n        return {\n          output: undefined,\n          skipped: true,\n          status: \"skipped\",\n          startedAt,\n          endedAt,\n          duration,\n          attempts: 0,\n          attemptHistory: [],\n          state: stepState,\n        };\n      }\n    }\n  } catch (err) {\n    return buildFailedSnapshot(step, stepState, startedAt, stepStartPerf, 1, [\n      failedAttempt(1, err, new Date().toISOString(), performance.now()),\n    ]);\n  }\n\n  // PARALLEL\n  if (step.parallel && step.parallel.length > 0) {\n    return runParallelStep({\n      ...params,\n      step,\n      stepState,\n      startedAt,\n      startPerf: stepStartPerf,\n    });\n  }\n\n  const retryConfig = resolveRetryConfig(step, params.workflowDefaultRetry);\n\n  const attempts: AttemptEntry[] = [];\n  const totalAttempts = Math.max(1, retryConfig.attempts ?? 1);\n  let lastError: unknown;\n  let executionResult: unknown;\n  let output: unknown;\n  let succeeded = false;\n  // Reports a `run` step's callback captured via its ambient run-frame\n  // (see below) — reset each attempt so a failed attempt's captures\n  // never bleed into a later retry's snapshot.\n  let stepChildren: BaseReport[] | undefined;\n\n  for (let attempt = 1; attempt <= totalAttempts; attempt++) {\n    if (signal?.aborted) throw createCancelledError(signal);\n\n    const attemptStart = new Date().toISOString();\n    const attemptStartPerf = performance.now();\n    try {\n      // Fresh deep-clone per attempt — retries restart cleanly.\n      const attemptState: Record<string, unknown> = cloneState(params.state);\n\n      if (step.before) {\n        await step.before(params.buildContext({ state: attemptState }));\n      }\n\n      if (step.agent) {\n        const agent = step.agent;\n        const agentInput = step.input\n          ? await step.input(params.buildContext({ state: attemptState }))\n          : { prompt: \"\" };\n\n        const { prompt, ...agentOpts } = agentInput;\n\n        // Run the step's agent inside a nested frame so observe-all does NOT\n        // also self-route it as a standalone trace — the workflow already\n        // captures it into report.steps (explicit capture, like the supervisor).\n        const result = await withoutRunFrame(() =>\n          agent.execute(prompt, {\n            ...agentOpts,\n            signal,\n          }),\n        );\n\n        executionResult = result;\n\n        if (result.usage) {\n          mergeUsage(params.usage, result.usage);\n        }\n\n        if (result.error) throw result.error;\n      } else if (step.run) {\n        // Custom `run` callbacks can call anything — an ambient RunFrame\n        // (mirroring the supervisor/team/orchestrator callback pattern)\n        // is the only way to observe what they invoke, since (unlike\n        // `step.agent` above) there's no single known executable to\n        // explicitly capture. Any `agent.execute(...)` the callback\n        // invokes DIRECTLY self-attaches its report onto `runChildren`\n        // via `captureChildReport` and is suppressed from also\n        // self-routing as a standalone observed trace.\n        const runChildren: BaseReport[] = [];\n\n        try {\n          executionResult = await withRunFrame(\n            {\n              sink: runChildren,\n              rootRunId: params.runId,\n              parentRunId: params.runId,\n              sessionId: params.sessionId,\n            },\n            () => step.run!(params.buildContext({ state: attemptState })),\n          );\n        } finally {\n          // Runs whether the callback resolved or threw — a callback that\n          // calls an agent and THEN throws still gets that call's report\n          // preserved on the failed snapshot (forensic trace, same intent\n          // as the file's other failed-snapshot preservation). Unconditional\n          // reassign (not a conditional-append): a retry whose callback\n          // captures nothing must clear a prior failed attempt's captures.\n          stepChildren = runChildren.length > 0 ? runChildren : undefined;\n\n          for (const child of runChildren) {\n            mergeUsage(params.usage, child.usage);\n          }\n        }\n      }\n\n      if (step.output) {\n        const extracted = await step.output.extract(\n          params.buildContext({\n            state: attemptState,\n            agentResult: executionResult,\n          }),\n        );\n        output = await validateSchema(step.output.schema, extracted);\n      } else {\n        output = undefined;\n      }\n\n      if (step.after) {\n        await step.after(\n          params.buildContext({\n            state: attemptState,\n            agentResult: executionResult,\n          }),\n        );\n      }\n\n      Object.assign(stepState, attemptState);\n\n      attempts.push({\n        index: attempt,\n        startedAt: attemptStart,\n        endedAt: new Date().toISOString(),\n        duration: performance.now() - attemptStartPerf,\n        status: \"success\",\n      });\n      succeeded = true;\n      break;\n    } catch (err) {\n      if (isAbortError(err) || err instanceof WorkflowCancelledError) {\n        throw createCancelledError(signal);\n      }\n\n      attempts.push({\n        index: attempt,\n        startedAt: attemptStart,\n        endedAt: new Date().toISOString(),\n        duration: performance.now() - attemptStartPerf,\n        status: \"failed\",\n        error: toAIError(err),\n      });\n\n      lastError = err;\n\n      const shouldRetry =\n        attempt < totalAttempts &&\n        (retryConfig.retryOn ? retryConfig.retryOn(err, attempt) !== false : true);\n\n      if (!shouldRetry) break;\n\n      emitter.emit(\n        \"workflow.step.retrying\",\n        {\n          step: step.name,\n          attempt: attempt + 1,\n          totalAttempts,\n          lastError: err,\n        },\n        params.executionHandlers,\n      );\n\n      step.on?.retrying?.({\n        step: step.name,\n        attempt: attempt + 1,\n        totalAttempts,\n        lastError: err,\n      });\n\n      logger.warn(logModule, \"step.retrying\", `${step.name} step retrying`, {\n        step: step.name,\n        attempt: attempt + 1,\n      });\n\n      retryConfig.onRetry?.(attempt + 1, err);\n\n      const delay = resolveBackoff(attempt, retryConfig.backoff);\n      if (delay > 0) await sleep(delay, signal);\n    }\n  }\n\n  const endedAt = new Date().toISOString();\n  const duration = performance.now() - stepStartPerf;\n\n  if (!succeeded) {\n    const aiError = toAIError(lastError);\n    const stepError = new StepFailedError(\n      `step \"${step.name}\" failed after ${attempts.length} attempt(s): ${aiError.message}`,\n      { stepName: step.name, attempts: attempts.length, cause: aiError },\n    );\n\n    emitter.emit(\n      \"workflow.step.failed\",\n      { step: step.name, error: stepError, attempts: attempts.length },\n      params.executionHandlers,\n    );\n\n    step.on?.failed?.({\n      step: step.name,\n      error: stepError,\n      attempts: attempts.length,\n    });\n\n    logger.error(logModule, \"step.failed\", `${step.name} step failed`, {\n      step: step.name,\n      attempts: attempts.length,\n      code: stepError.code,\n    });\n\n    const failedAgentResult = asAgentResult(executionResult);\n    return {\n      output: undefined,\n      skipped: false,\n      status: \"failed\",\n      startedAt,\n      endedAt,\n      duration,\n      attempts: attempts.length,\n      attemptHistory: attempts,\n      error: stepError,\n      state: stepState,\n      executionResult:\n        executionResult && typeof executionResult === \"object\" ? executionResult : undefined,\n      agentReport: failedAgentResult?.report,\n      agentUsage: failedAgentResult?.usage,\n      children: stepChildren,\n    };\n  }\n\n  emitter.emit(\n    \"workflow.step.completed\",\n    { step: step.name, output, duration },\n    params.executionHandlers,\n  );\n  step.on?.completed?.({ step: step.name, output, duration });\n  logger.debug(logModule, \"step.completed\", \"step completed\", {\n    step: step.name,\n    duration,\n  });\n\n  const completedAgentResult = asAgentResult(executionResult);\n  return {\n    output,\n    skipped: false,\n    status: \"completed\",\n    startedAt,\n    endedAt,\n    duration,\n    attempts: attempts.length,\n    attemptHistory: attempts,\n    state: stepState,\n    executionResult:\n      executionResult && typeof executionResult === \"object\" ? executionResult : undefined,\n    agentReport: completedAgentResult?.report,\n    agentUsage: completedAgentResult?.usage,\n    children: stepChildren,\n  };\n}\n\n// ---------------------------------------------------------------------------\n// Parallel runner\n// ---------------------------------------------------------------------------\n\ntype ParallelParams = ExecuteStepParams & {\n  stepState: Record<string, unknown>;\n  startedAt: string;\n  startPerf: number;\n};\n\nasync function runParallelStep(params: ParallelParams): Promise<MutableStepSnapshot> {\n  const { step, emitter, executionHandlers, logger, logModule, signal } = params;\n\n  const sharedState = params.stepState;\n  const childSnapshots: Record<string, StepSnapshot> = {};\n  let firstError: AIError | undefined;\n\n  const results = await Promise.all(\n    (step.parallel ?? []).map(async (child) => {\n      const snap = await executeStep({\n        step: child,\n        state: sharedState,\n        emitter,\n        executionHandlers,\n        logger,\n        logModule,\n        signal,\n        buildContext: params.buildContext,\n        usage: params.usage,\n        runId: params.runId,\n        sessionId: params.sessionId,\n      });\n\n      return { child, snap };\n    }),\n  );\n\n  // Merge each child's resulting state into the shared parent state in\n  // DECLARATION order — not completion order. Every child cloned the\n  // same initial `sharedState` synchronously at dispatch, so the merge\n  // here is the only thing that decides conflicting keys; `Promise.all`\n  // preserves input order in `results`, so a key written by multiple\n  // children deterministically resolves to the last-declared child's\n  // value regardless of which settled first (C3). An optional\n  // `mergeState` reducer overrides this per key for advanced workflows.\n  for (const { child, snap } of results) {\n    childSnapshots[child.name] = finalizeSnapshot(snap);\n\n    if (step.mergeState) {\n      step.mergeState(sharedState, snap.state, child.name);\n    } else {\n      Object.assign(sharedState, snap.state);\n    }\n\n    if (snap.status === \"failed\" && !firstError && snap.error) {\n      firstError = snap.error;\n    }\n  }\n\n  const endedAt = new Date().toISOString();\n  const duration = performance.now() - params.startPerf;\n\n  let output: unknown;\n\n  if (step.output) {\n    try {\n      const ctx = params.buildContext({ state: sharedState });\n      const ctxWithChildren = {\n        ...ctx,\n        steps: {\n          ...ctx.steps,\n          [step.name]: {\n            ...(childSnapshots as unknown as StepSnapshot),\n            steps: childSnapshots,\n            status: firstError ? \"failed\" : \"completed\",\n          } as StepSnapshot,\n        } as Readonly<Record<string, StepSnapshot>>,\n      };\n\n      const extracted = await step.output.extract(ctxWithChildren);\n      output = await validateSchema(step.output.schema, extracted);\n    } catch (err) {\n      firstError = firstError ?? toAIError(err);\n    }\n  }\n\n  const status: \"completed\" | \"failed\" = firstError ? \"failed\" : \"completed\";\n\n  if (status === \"completed\") {\n    emitter.emit(\n      \"workflow.step.completed\",\n      { step: step.name, output, duration },\n      executionHandlers,\n    );\n    step.on?.completed?.({ step: step.name, output, duration });\n  } else {\n    emitter.emit(\n      \"workflow.step.failed\",\n      { step: step.name, error: firstError!, attempts: 1 },\n      executionHandlers,\n    );\n    step.on?.failed?.({ step: step.name, error: firstError!, attempts: 1 });\n  }\n\n  return {\n    output,\n    skipped: false,\n    status,\n    startedAt: params.startedAt,\n    endedAt,\n    duration,\n    attempts: 1,\n    attemptHistory: [],\n    error: firstError,\n    state: sharedState,\n    steps: childSnapshots,\n  };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nexport function finalizeSnapshot(snap: MutableStepSnapshot): StepSnapshot {\n  return Object.freeze({\n    output: snap.output,\n    skipped: snap.skipped,\n    status: snap.status,\n    startedAt: snap.startedAt,\n    endedAt: snap.endedAt,\n    duration: snap.duration,\n    attempts: snap.attempts,\n    attemptHistory: snap.attemptHistory,\n    error: snap.error,\n    state: deepFreeze(cloneState(snap.state)),\n    executionResult: snap.executionResult as StepSnapshot[\"executionResult\"],\n    agentReport: snap.agentReport,\n    agentUsage: snap.agentUsage,\n    children: snap.children,\n    steps: snap.steps,\n  }) as StepSnapshot;\n}\n\nfunction buildFailedSnapshot(\n  step: StepDefinition,\n  state: Record<string, unknown>,\n  startedAt: string,\n  startPerf: number,\n  attemptsCount: number,\n  attemptHistory: AttemptEntry[],\n): MutableStepSnapshot {\n  const endedAt = new Date().toISOString();\n  const duration = performance.now() - startPerf;\n  const lastErr = attemptHistory[attemptHistory.length - 1]?.error;\n  const wrapped = lastErr\n    ? new StepFailedError(`step \"${step.name}\" skip threw: ${lastErr.message}`, {\n        stepName: step.name,\n        attempts: attemptsCount,\n        cause: lastErr,\n      })\n    : new StepFailedError(`step \"${step.name}\" failed`, {\n        stepName: step.name,\n        attempts: attemptsCount,\n      });\n\n  return {\n    output: undefined,\n    skipped: false,\n    status: \"failed\",\n    startedAt,\n    endedAt,\n    duration,\n    attempts: attemptsCount,\n    attemptHistory,\n    error: wrapped,\n    state,\n  };\n}\n\nfunction failedAttempt(\n  index: number,\n  err: unknown,\n  startedAt: string,\n  startPerf: number,\n): AttemptEntry {\n  return {\n    index,\n    startedAt,\n    endedAt: new Date().toISOString(),\n    duration: performance.now() - startPerf,\n    status: \"failed\",\n    error: toAIError(err),\n  };\n}\n\nexport function toAIError(err: unknown): AIError {\n  if (err instanceof AIError) return err;\n  if (err instanceof Error) return new WorkflowError(err.message, { cause: err });\n  return new WorkflowError(String(err));\n}\n\nasync function validateSchema(\n  schema: StandardSchemaV1<unknown> | undefined,\n  value: unknown,\n): Promise<unknown> {\n  if (!schema) return value;\n  const result = await schema[\"~standard\"].validate(value);\n\n  if (\"issues\" in result && result.issues) {\n    throw new SchemaValidationError(\"workflow step output failed schema validation\", {\n      issues: result.issues,\n    });\n  }\n\n  return (result as { value: unknown }).value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,SAAS,cAAc,QAAmD;CACxE,IAAI,CAAC,UAAU,OAAO,WAAW,UAAU,OAAO;CAClD,IAAK,OAA8B,SAA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