{"version":3,"file":"render.mjs","names":[],"sources":["../../../src/batteries/orchestration/render.ts"],"sourcesContent":["/**\n * Prose projection of a plan — the review surface an operator reads at the approval gate, and the\n * re-consumption surface a model reads for a plan it did not author.\n *\n * @module @nhtio/adk/batteries/orchestration/render\n *\n * @remarks\n * There is NO dry run in this design. This prose IS the review surface, and that is what makes the\n * operator view load-bearing rather than cosmetic: an operator who approves a plan they cannot\n * fully see is the failure this replaces. So for `audience: 'operator'` with `view: 'as_planned'`,\n * brevity is NOT a virtue — every side effect with its tool and arguments, every authority claim,\n * every condition with its exact predicate, in traversal order, with branch structure legible.\n *\n * Arguments at approval time are STAGED, NOT RESOLVED, and the renderer says which. A `NodeRef`\n * resolves from the `OutputTable`, which only exists during a run; approval happens before any run\n * and there is no dry run to populate it. So a literal argument renders as its value, and a\n * `NodeRef` renders as its PROVENANCE — never as a fabricated value, never silently as though it\n * were known. The operator is approving what the plan will do with whatever its sources produce,\n * and the AUTHORITY CLAIM is the bound on that — which IS fully known at approval time. The\n * `as_executed` view is where arguments appear resolved, because by then they are.\n *\n * The operator view is a SEPARATE DISPLAY PROJECTION, not the execution payload: no model-written\n * free text rendered as if it were fact, no raw machine identifiers where a human-readable label\n * exists. The model view (`audience: 'model'`) is the inverse: exact identifiers, the same surface\n * forms a model would cite back, so a model can re-consume a plan it did not author without a\n * paraphrase hop.\n *\n * Properties:\n * - **DETERMINISTIC.** Same plan + same options ⇒ byte-identical output. The traversal order is\n *   fixed (entry-first, then graph order, with branch structure rendered by handle), value\n *   formatting is total, and nothing reads a clock, a store, or a global.\n * - **TOTAL.** Every node kind renders. The node-kind switch is exhaustiveness-checked with\n *   `const exhaustive: never = kind`, so a new node kind cannot silently render as nothing.\n *\n * It is NOT reversible — there is no prose parser, and `render(parse(s)) === s` is not promised,\n * because `parse` does not exist. The renderer is a one-way display projection.\n */\n\nimport { NodeRef as NodeRefClass } from './encoding'\nimport { isObject, isInstanceOf } from '../../lib/utils/guards'\nimport { outgoing, incoming, nodeById, entryNodes } from './plan'\nimport type {\n  ArgValue,\n  AuthorityClaim,\n  AuthorityVerb,\n  BranchId,\n  DeclaredField,\n  EdgeHandle,\n  EncodableValue,\n  NodeId,\n  NodeRef,\n  PlanEdge,\n  PlanNode,\n  RawPlanView,\n  RunProjection,\n} from './types'\n\n// ── options ──────────────────────────────────────────────────────────────────\n/**\n * The audience a render targets.\n * - `'operator'` — the approval-gate human: prose, trust framing, side effects legible, a total\n *   authority summary.\n * - `'model'` — a model re-consuming a plan it did not author: exact identifiers and surface\n *   forms, minimal paraphrase.\n */\ntype Audience = 'operator' | 'model'\n\n/**\n * The view of a render.\n * - `'as_planned'` — what the plan WILL do. Arguments are staged; a `NodeRef` renders as its\n *   provenance, never as a fabricated value. This is the approval-gate view.\n * - `'as_executed'` — what the plan DID do, against a `RunProjection`. Arguments appear resolved\n *   from the run's `outputs`.\n */\ntype View = 'as_planned' | 'as_executed'\n\n/**\n * Options for {@link renderPlan}.\n *\n * @remarks\n * The union encodes the two real read modes: `as_planned` carries no run (it is the approval-gate\n * view, before any execution), and `as_executed` requires a `RunProjection` so arguments can be\n * resolved from its `outputs` and node states can be annotated.\n */\nexport type RenderPlanOptions =\n  | { audience: Audience; view: 'as_planned' }\n  | { audience: Audience; view: 'as_executed'; run: RunProjection }\n\n// ── the public function ──────────────────────────────────────────────────────\n/**\n * Render a plan as prose — the review surface an operator reads at the approval gate, or the\n * re-consumption surface a model reads for a plan it did not author.\n *\n * @remarks\n * A PURE function of its arguments — no store access, no I/O, no clock. That is what keeps it\n * testable and deterministic: the same plan plus the same options yields byte-identical output,\n * and a snapshot test is a complete regression contract. It reads no `PlanStore`, resolves no\n * live values, and registers nothing.\n *\n * The `as_planned` view renders staged arguments as their provenance (a `NodeRef` names the node\n * and selection it reads, never a fabricated value); the `as_executed` view resolves them against\n * `run.outputs`. The operator view renders every side effect with its tool and arguments, every\n * authority claim, every condition with its exact predicate, and ends with a deduplicated\n * total-authority summary grouped by capability; the model view renders exact identifiers.\n *\n * DETERMINISTIC and TOTAL — see the module doc. Not reversible.\n *\n * @param plan - the {@link RawPlanView} to render.\n * @param options - audience, view, and (for `as_executed`) the {@link RunProjection} to resolve\n *   against.\n * @returns the prose projection, as a single string.\n */\nexport function renderPlan(plan: RawPlanView, options: RenderPlanOptions): string {\n  const lines: string[] = []\n  const ctx: RenderContext = {\n    plan,\n    audience: options.audience,\n    view: options.view,\n    run: options.view === 'as_executed' ? options.run : undefined,\n  }\n\n  renderHeader(ctx, lines)\n  renderProvenance(ctx, lines)\n  renderBody(ctx, lines)\n  if (ctx.audience === 'operator') {\n    renderTotalAuthority(ctx, lines)\n  }\n\n  return lines.join('\\n')\n}\n\n// ── internal context ─────────────────────────────────────────────────────────\n/**\n * The fixed bundle a render pass threads through its helpers. Carries everything a helper needs\n * so none of them takes a long argument list or reaches outside the function's inputs.\n */\ninterface RenderContext {\n  plan: RawPlanView\n  audience: Audience\n  view: View\n  run: RunProjection | undefined\n}\n\n// ── header ───────────────────────────────────────────────────────────────────\n/**\n * Append the plan header: id, digest, revision, and the view/audience banner.\n */\nconst renderHeader = (ctx: RenderContext, lines: string[]): void => {\n  const { plan, audience, view } = ctx\n  lines.push(`Plan ${plan.planId}`)\n  lines.push(`digest: ${plan.digest}`)\n  lines.push(`revision: ${plan.revision}`)\n  lines.push(\n    `${audience === 'operator' ? 'Operator' : 'Model'} view · ${view === 'as_planned' ? 'as planned' : 'as executed'}`\n  )\n  if (view === 'as_executed' && ctx.run) {\n    lines.push(`run: ${ctx.run.runId} · outcome: ${ctx.run.outcome}`)\n    if (ctx.run.interruption) {\n      lines.push(`interrupted: ${describeInterruption(ctx.run.interruption)}`)\n    }\n  }\n  lines.push('')\n}\n\n// ── provenance ───────────────────────────────────────────────────────────────\n/**\n * Append provenance: the lineage of a cloned or templated plan.\n *\n * @remarks\n * A CLONE must warn that its parent already completed nodes X, Y, Z and that approving it will\n * perform them AGAIN. The completed list is read from `provenance.completedAtClone`, which\n * `clonePlan` snapshotted; needing no store access is what keeps this function pure.\n */\nconst renderProvenance = (ctx: RenderContext, lines: string[]): void => {\n  const p = ctx.plan.provenance\n  if (!p) return\n  if (p.kind === 'clone') {\n    lines.push('Lineage: cloned plan')\n    lines.push(`  parent: ${p.parent} (digest ${p.parentDigest}, revision ${p.parentRevision})`)\n    if (p.completedAtClone.length > 0) {\n      lines.push(\n        `  WARNING: the parent already completed ${p.completedAtClone.length} node(s) at clone time —`\n      )\n      lines.push(`  approving this plan will perform them AGAIN:`)\n      for (const id of p.completedAtClone) {\n        lines.push(`    · ${id}`)\n      }\n    } else {\n      lines.push(`  the parent had completed no nodes at clone time.`)\n    }\n    lines.push('')\n  } else {\n    lines.push('Lineage: instantiated from template')\n    lines.push(`  template: ${p.template}`)\n    const argKeys = Object.keys(p.args).sort()\n    if (argKeys.length > 0) {\n      lines.push(`  args:`)\n      for (const k of argKeys) {\n        lines.push(`    ${k}: ${formatValue(p.args[k], ctx)}`)\n      }\n    }\n    lines.push('')\n  }\n}\n\n// ── body: traversal ──────────────────────────────────────────────────────────\n/**\n * Append the body: every node rendered in traversal order, with branch structure legible.\n *\n * @remarks\n * Traversal starts from the (single) entry node, then walks the graph in a deterministic\n * depth-first order over outgoing edges grouped by handle so a reader sees a step's successors\n * immediately under it. Nodes not reachable from entry (a malformed plan) are still rendered in an\n * \"Unreachable\" tail so the projection stays TOTAL over the node set.\n */\nconst renderBody = (ctx: RenderContext, lines: string[]): void => {\n  const { plan } = ctx\n  const entries = entryNodes(plan)\n  const visited = new Set<NodeId>()\n  let step = 0\n\n  const renderNodeAt = (node: PlanNode, via: string | undefined, depth: number): void => {\n    if (visited.has(node.id)) return\n    visited.add(node.id)\n    step += 1\n    renderNode(ctx, lines, node, step, via, depth)\n    const edges = outgoing(plan, node.id)\n    // Deterministic order: by handle then by target id, so the same graph always renders the same.\n    const ordered = edges\n      .slice()\n      .sort((a, b) => (a.handle < b.handle ? -1 : a.handle > b.handle ? 1 : a.to < b.to ? -1 : 1))\n    for (const edge of ordered) {\n      const target = nodeById(plan, edge.to)\n      if (!target) continue\n      renderEdge(ctx, lines, edge, depth)\n      renderNodeAt(target, edge.handle, depth + 1)\n    }\n  }\n\n  for (const entry of entries) {\n    renderNodeAt(entry, undefined, 0)\n  }\n\n  const unreachable = plan.nodes.filter((n) => !visited.has(n.id))\n  if (unreachable.length > 0) {\n    lines.push('Unreachable nodes (not reachable from entry):')\n    for (const id of unreachable.map((n) => n.id).sort()) {\n      lines.push(`  · \\`${id}\\``)\n    }\n    lines.push('')\n  }\n}\n\n// ── per-node rendering ───────────────────────────────────────────────────────\n/**\n * Append one node's prose, indented to `depth` and numbered `step`.\n *\n * @remarks\n * The node-kind switch is exhaustiveness-checked with `const exhaustive: never = kind` so a new\n * node kind cannot silently render as nothing — the compiler refuses an unhandled kind.\n */\nconst renderNode = (\n  ctx: RenderContext,\n  lines: string[],\n  node: PlanNode,\n  step: number,\n  via: string | undefined,\n  depth: number\n): void => {\n  const indent = '  '.repeat(depth)\n  const kind = node.kind\n  const status = nodeStatus(ctx, node.id)\n\n  switch (kind) {\n    case 'entry': {\n      const def = node.definition\n      lines.push(`${indent}${step}. ENTRY — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      if (def.input.length > 0) {\n        lines.push(`${indent}    inputs:`)\n        for (const field of def.input) {\n          lines.push(`${indent}      · ${describeDeclaredField(field)}`)\n        }\n      } else {\n        lines.push(`${indent}    inputs: (none)`)\n      }\n      break\n    }\n    case 'call': {\n      const def = node.definition\n      lines.push(\n        `${indent}${step}. CALL — \\`${node.id}\\` — ${def.tool}(${status ? ` [${status}]` : ''}`\n      )\n      renderCallArgs(ctx, lines, def.args, indent + '    ')\n      renderAuthority(ctx, lines, def.authority, indent + '    ')\n      renderCallRecovery(ctx, lines, def, def.authority, indent + '    ')\n      if (def.declassifies && def.declassifies.length > 0) {\n        lines.push(`${indent}    declassifies: ${def.declassifies.join(', ')}`)\n      }\n      renderOutputFields(ctx, lines, def.output, indent + '    ')\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    case 'reason': {\n      const def = node.definition\n      lines.push(`${indent}${step}. REASON — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      lines.push(`${indent}    prompt:`)\n      for (const part of def.prompt) {\n        if ('text' in part) {\n          lines.push(`${indent}      text: ${JSON.stringify(part.text)}`)\n        } else {\n          lines.push(`${indent}      ref: ${describeNodeRef(part, ctx)}`)\n        }\n      }\n      lines.push(`${indent}    output schema: ${def.outputSchema}`)\n      lines.push(`${indent}    max attempts: ${def.maxAttempts}`)\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    case 'transform': {\n      const def = node.definition\n      lines.push(`${indent}${step}. TRANSFORM — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      lines.push(`${indent}    source: ${describeNodeRef(def.source, ctx)}`)\n      lines.push(`${indent}    steps:`)\n      def.steps.forEach((s, i) => {\n        const args = s.args ? ` args: ${formatRecord(s.args, ctx)}` : ''\n        lines.push(`${indent}      ${i + 1}. ${s.name}${args}`)\n      })\n      lines.push(\n        `${indent}    emit: ${def.emit.as === 'rows' ? 'rows' : `value → ${def.emit.field}`}`\n      )\n      renderOutputFields(ctx, lines, def.output, indent + '    ')\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    case 'branch': {\n      const def = node.definition\n      lines.push(`${indent}${step}. BRANCH — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      lines.push(`${indent}    evaluator: ${def.evaluator}`)\n      lines.push(`${indent}    predicate: ${formatValue(def.predicate, ctx)}`)\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    case 'select': {\n      const def = node.definition\n      lines.push(`${indent}${step}. SELECT — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      lines.push(`${indent}    evaluator: ${def.evaluator}`)\n      lines.push(`${indent}    predicate: ${formatValue(def.predicate, ctx)}`)\n      lines.push(`${indent}    cases: ${def.cases.join(', ')}`)\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    case 'join': {\n      // `via` is unused here but kept in the signature for uniformity.\n      void via\n      lines.push(`${indent}${step}. JOIN — \\`${node.id}\\`${status ? ` [${status}]` : ''}`)\n      const preds = incoming(ctx.plan, node.id)\n      lines.push(`${indent}    awaits ${preds.length} incoming edge(s):`)\n      for (const e of preds) {\n        lines.push(`${indent}      · ${e.id} from ${e.from} (handle ${e.handle})`)\n      }\n      renderOutcomesByHandle(ctx, lines, node.id, indent + '    ')\n      break\n    }\n    default: {\n      // Exhaustiveness: a new node kind renders as a NAMED gap rather than nothing.\n      const exhaustive: never = kind\n      void exhaustive\n      lines.push(`${indent}${step}. (unrendered node kind: ${String(kind)})`)\n    }\n  }\n}\n\n// ── call arg rendering ───────────────────────────────────────────────────────\n/**\n * Append a call's staged arguments. A `NodeRef` renders as its provenance; a literal renders as\n * its value. In `as_executed`, a `NodeRef` is additionally resolved against `run.outputs` so the\n * reader sees what the reference actually produced.\n */\nconst renderCallArgs = (\n  ctx: RenderContext,\n  lines: string[],\n  args: Record<string, ArgValue>,\n  indent: string\n): void => {\n  const keys = Object.keys(args).sort()\n  if (keys.length === 0) {\n    lines.push(`${indent}args: (none)`)\n    return\n  }\n  lines.push(`${indent}args:`)\n  for (const k of keys) {\n    const value = args[k]\n    lines.push(`${indent}  ${k}: ${describeArgValue(value, ctx)}`)\n  }\n}\n\n/**\n * Describe a single staged argument value: provenance for a `NodeRef`, formatted literal\n * otherwise. In `as_executed`, a `NodeRef` is resolved against the run's outputs and the resolved\n * value is shown alongside the provenance.\n */\nconst describeArgValue = (value: ArgValue, ctx: RenderContext): string => {\n  if (NodeRefClass.isNodeRef(value)) {\n    const provenance = describeNodeRef(value, ctx)\n    if (ctx.view === 'as_executed' && ctx.run) {\n      const resolved = resolveNodeRef(value, ctx.run.outputs)\n      if (resolved !== undefined) {\n        return `${provenance} ⇒ ${resolved}`\n      }\n    }\n    return provenance\n  }\n  if (Array.isArray(value)) {\n    return `[${value.map((v) => describeArgValue(v, ctx)).join(', ')}]`\n  }\n  if (isObject(value)) {\n    return formatRecord(value as Record<string, ArgValue>, ctx)\n  }\n  return formatValue(value as EncodableValue, ctx)\n}\n\n/**\n * Format a record of staged values, key-sorted for determinism.\n */\nconst formatRecord = (rec: Record<string, ArgValue>, ctx: RenderContext): string => {\n  const keys = Object.keys(rec).sort()\n  const parts = keys.map((k) => `${k}: ${describeArgValue(rec[k], ctx)}`)\n  return `{${parts.join(', ')}}`\n}\n\n// ── NodeRef provenance ───────────────────────────────────────────────────────\n/**\n * Describe a `NodeRef` by its PROVENANCE — the node it reads, the selection, and the path — never\n * by a fabricated value. This is what an operator approves: \"what the plan will do with whatever\n * step N produces\", and the authority claim is the bound on that.\n */\nconst describeNodeRef = (ref: NodeRef, ctx: RenderContext): string => {\n  const source = ctx.audience === 'operator' ? '←' : '$ref'\n  const sel = describeSelect(ref.select)\n  const path = ref.path ? ` @ ${ref.path}` : ''\n  const branch = ref.branchId ? ` (branch ${describeBranchId(ref.branchId)})` : ''\n  const sourceNode = nodeById(ctx.plan, ref.node)\n  const sourceTool =\n    sourceNode && sourceNode.kind === 'call' ? ` (${sourceNode.definition.tool})` : ''\n  if (ctx.audience === 'model') {\n    return `${source} {node: ${ref.node}, select: ${sel}${ref.path ? `, path: ${JSON.stringify(ref.path)}` : ''}${ref.branchId ? `, branch: ${describeBranchId(ref.branchId)}` : ''}}`\n  }\n  return `${source} ${sel} output of step ${ref.node}${sourceTool}${path}${branch}`\n}\n\n/**\n * Render the `select` field of a `NodeRef` as prose.\n */\nconst describeSelect = (select: NodeRef['select']): string => {\n  if (typeof select === 'string') {\n    switch (select) {\n      case 'first':\n        return 'the first'\n      case 'last':\n        return 'the last'\n      case 'all':\n        return 'every'\n      default: {\n        const exhaustive: never = select\n        void exhaustive\n        return String(select)\n      }\n    }\n  }\n  return `item ${select.index}`\n}\n\n/**\n * Render a `BranchId` as its canonical key form. The segments carry the route; the key is the\n * injective string form the rest of the battery uses, so this matches what an operator would see\n * in any other diagnostic without inventing a second rendering.\n */\nconst describeBranchId = (branch: BranchId): string => {\n  const segs = branch.segments\n  if (segs.length === 0) return 'entry'\n  return segs.map((s): string => ('edge' in s ? `→${s.edge}` : `→join:${s.join}`)).join('')\n}\n\n// ── authority ────────────────────────────────────────────────────────────────\n/**\n * Append a call's authority claims, one per line, in the form\n * `capability · scope · verb`. These are the bounds the operator is approving, and they are fully\n * known at approval time even when arguments are staged.\n */\nconst renderAuthority = (\n  _ctx: RenderContext,\n  lines: string[],\n  claims: AuthorityClaim[],\n  indent: string\n): void => {\n  if (claims.length === 0) {\n    lines.push(`${indent}authority: (none claimed)`)\n    return\n  }\n  lines.push(`${indent}authority:`)\n  for (const claim of claims) {\n    lines.push(`${indent}  · ${describeAuthority(claim)}`)\n  }\n}\n\n/**\n * Render a single authority claim as `capability · scope · verb`.\n */\nconst describeAuthority = (claim: AuthorityClaim): string => {\n  return `${claim.capability} · ${claim.scope} · ${claim.verb}`\n}\n\n// ── call recovery ────────────────────────────────────────────────────────────\n/**\n * Mutating authority verbs — those that change state. The five `AuthorityVerb`s have NO\n * implication between them by design (`update` does not imply `read`), so each claim is\n * classified independently rather than by hierarchy.\n */\nconst MUTATING_VERBS: ReadonlySet<AuthorityVerb> = new Set(['create', 'update', 'delete'])\n\n/**\n * Append a call's recovery behaviour and side-effect notice. The recovery is inside the approved\n * digest, so it is rendered for every audience. `skip` renders its CONSEQUENCE — downstream nodes\n * proceed against a step whose effect is unknown — rather than reading as a clean recovery.\n *\n * The side-effect marker is decided from the node's AUTHORITY VERBS, not pushed unconditionally:\n * `list`/`read` are non-mutating; `create`/`update`/`delete` are mutating. A call with NO claims\n * is treated as UNKNOWN (potentially mutating) — never silently safe — so an unclaimed side\n * effect stays flagged. The replay-safety and interruption lines are meaningful only for steps\n * that change something, so they stay attached to mutating (and unknown) steps.\n */\nconst renderCallRecovery = (\n  _ctx: RenderContext,\n  lines: string[],\n  def: { replaySafe: boolean; onIndeterminate: 'retry' | 'halt' | 'skip' },\n  claims: AuthorityClaim[],\n  indent: string\n): void => {\n  const mutating = claims.some((c) => MUTATING_VERBS.has(c.verb))\n  const unclaimed = claims.length === 0\n  if (unclaimed) {\n    lines.push(\n      `${indent}NO AUTHORITY CLAIMED — whether this changes anything is UNKNOWN. Treat as potentially mutating.`\n    )\n  } else if (mutating) {\n    lines.push(\n      `${indent}THIS MODIFIES DATA. Repeats are ${def.replaySafe ? 'safe (declared replay-safe)' : 'NOT safe (declared not replay-safe)'}.`\n    )\n  } else {\n    lines.push(`${indent}(no changes made — all declared verbs are read-only)`)\n    return\n  }\n  switch (def.onIndeterminate) {\n    case 'retry':\n      lines.push(`${indent}If interrupted mid-call, this step will be retried.`)\n      break\n    case 'halt':\n      lines.push(`${indent}If interrupted mid-call, this step will stop and wait for you.`)\n      break\n    case 'skip':\n      lines.push(\n        `${indent}If interrupted mid-call, this step will be SKIPPED — downstream nodes proceed against a step whose effect is UNKNOWN.`\n      )\n      break\n    default: {\n      const exhaustive: never = def.onIndeterminate\n      void exhaustive\n      lines.push(`${indent}(unknown recovery: ${String(def.onIndeterminate)})`)\n    }\n  }\n}\n\n// ── output fields ────────────────────────────────────────────────────────────\n/**\n * Append a node's declared output fields, one per line. These are what downstream `NodeRef`s may\n * address, so they are part of the review surface.\n */\nconst renderOutputFields = (\n  _ctx: RenderContext,\n  lines: string[],\n  fields: DeclaredField[],\n  indent: string\n): void => {\n  if (fields.length === 0) {\n    lines.push(`${indent}output: (none declared)`)\n    return\n  }\n  lines.push(`${indent}output:`)\n  for (const field of fields) {\n    lines.push(`${indent}  · ${describeDeclaredField(field)}`)\n  }\n}\n\n/**\n * Render a declared field as `path: type` (with the enum's values or the string's byte cap where\n * present).\n */\nconst describeDeclaredField = (field: DeclaredField): string => {\n  switch (field.type) {\n    case 'string':\n      return field.maxBytes !== undefined\n        ? `${field.path}: string (≤ ${field.maxBytes} bytes)`\n        : `${field.path}: string`\n    case 'number':\n      return `${field.path}: number`\n    case 'boolean':\n      return `${field.path}: boolean`\n    case 'enum':\n      return `${field.path}: enum {${field.values.join(', ')}}`\n    default: {\n      // Exhaustiveness: DeclaredField's type union is closed, so this branch is unreachable.\n      // A new field type cannot silently render as nothing — the compiler refuses it here.\n      const exhaustive: never = field\n      void exhaustive\n      return '(unrendered field type)'\n    }\n  }\n}\n\n// ── edges and outcomes ───────────────────────────────────────────────────────\n/**\n * Append a single edge as a one-line annotation of how control leaves a node. An `error` handle\n * renders as an ABORT, never as a confirmation prompt — there is no mid-run gate in this design,\n * and a mid-run need for an answer means the plan was insufficient.\n */\nconst renderEdge = (ctx: RenderContext, lines: string[], edge: PlanEdge, depth: number): void => {\n  const indent = '  '.repeat(depth)\n  const label = describeHandle(edge.handle)\n  if (edge.handle === 'error') {\n    lines.push(`${indent}→ ABORT on error → step ${edge.to} (${label})`)\n  } else {\n    lines.push(`${indent}→ on ${label} → step ${edge.to}`)\n  }\n  if (ctx.view === 'as_executed' && ctx.run) {\n    const taken = ctx.run.edgesTaken.find((t) => t.edgeId === edge.id)\n    if (taken) {\n      const ev =\n        taken.evidence !== undefined ? ` evidence: ${formatValue(taken.evidence, ctx)}` : ''\n      lines.push(`${indent}  [taken · handle ${taken.handle}${ev}]`)\n    }\n  }\n}\n\n/**\n * Append a summary of a node's outgoing edges grouped by handle, so the branch structure is\n * legible even when a reader scans a single node. Mirrors {@link renderEdge} but without depth.\n */\nconst renderOutcomesByHandle = (\n  ctx: RenderContext,\n  lines: string[],\n  nodeId: NodeId,\n  indent: string\n): void => {\n  const edges = outgoing(ctx.plan, nodeId)\n  if (edges.length === 0) {\n    lines.push(`${indent}on completion: (terminal — no outgoing edges)`)\n    return\n  }\n  lines.push(`${indent}on completion:`)\n  const ordered = edges\n    .slice()\n    .sort((a, b) => (a.handle < b.handle ? -1 : a.handle > b.handle ? 1 : a.to < b.to ? -1 : 1))\n  for (const edge of ordered) {\n    const label = describeHandle(edge.handle)\n    if (edge.handle === 'error') {\n      lines.push(`${indent}  · ABORT on error → step ${edge.to}`)\n    } else {\n      lines.push(`${indent}  · on ${label} → step ${edge.to}`)\n    }\n  }\n}\n\n/**\n * Render an edge handle as a human-readable label. `case_*` strips the reserved prefix so a\n * `select`'s cases read as their authored labels.\n */\nconst describeHandle = (handle: EdgeHandle): string => {\n  switch (handle) {\n    case 'always':\n      return 'always'\n    case 'match':\n      return 'match'\n    case 'no_match':\n      return 'no match'\n    case 'default':\n      return 'default'\n    case 'error':\n      return 'error'\n    default:\n      if (handle.startsWith('case_')) {\n        return `case ${handle.slice('case_'.length)}`\n      }\n      return handle\n  }\n}\n\n// ── total authority summary ──────────────────────────────────────────────────\n/**\n * Append the \"Total authority requested\" summary: the deduplicated union of every call's\n * authority claims, grouped by capability. This is the operator's one-glance answer to \"what is\n * this plan asking to do\".\n */\nconst renderTotalAuthority = (ctx: RenderContext, lines: string[]): void => {\n  const byCapability = new Map<string, AuthorityClaim[]>()\n  for (const node of ctx.plan.nodes) {\n    if (node.kind !== 'call') continue\n    for (const claim of node.definition.authority) {\n      const list = byCapability.get(claim.capability)\n      if (list) list.push(claim)\n      else byCapability.set(claim.capability, [claim])\n    }\n  }\n  lines.push('Total authority requested')\n  if (byCapability.size === 0) {\n    lines.push('  (no authority claimed by any call)')\n    lines.push('')\n    return\n  }\n  const capabilities = [...byCapability.keys()].sort()\n  for (const cap of capabilities) {\n    const claims = byCapability.get(cap)!\n    // Deduplicate by `${scope}|${verb}` and sort for determinism.\n    const seen = new Set<string>()\n    const unique: AuthorityClaim[] = []\n    for (const c of claims) {\n      const key = `${c.scope}|${c.verb}`\n      if (!seen.has(key)) {\n        seen.add(key)\n        unique.push(c)\n      }\n    }\n    unique.sort((a, b) =>\n      a.scope < b.scope ? -1 : a.scope > b.scope ? 1 : verbRank(a.verb) - verbRank(b.verb)\n    )\n    lines.push(`  ${cap}:`)\n    for (const c of unique) {\n      lines.push(`    · ${c.scope} · ${c.verb}`)\n    }\n  }\n  lines.push('')\n}\n\n/**\n * A stable ordering for verbs in the authority summary, so the same claim set always renders in\n * the same order.\n */\nconst verbRank = (verb: AuthorityVerb): number => {\n  switch (verb) {\n    case 'list':\n      return 0\n    case 'read':\n      return 1\n    case 'create':\n      return 2\n    case 'update':\n      return 3\n    case 'delete':\n      return 4\n    default: {\n      const exhaustive: never = verb\n      void exhaustive\n      return 99\n    }\n  }\n}\n\n// ── value formatting ─────────────────────────────────────────────────────────\n/**\n * Format an `EncodableValue` as a stable string. Total over the value domain: every member of\n * `EncodableValue` renders, and the rendering is deterministic so the same value always yields the\n * same bytes.\n *\n * @remarks\n * `Date`, `RegExp`, `Map`, `Set`, typed arrays, `ArrayBuffer`, `DataView`, bigint and the luxon\n * types each have a named rendering rather than collapsing to `{}` (which `JSON.stringify` would\n * do for the class-owned values). Plain records and arrays recurse with sorted keys.\n */\nconst formatValue = (value: EncodableValue, ctx: RenderContext): string => {\n  void ctx\n  switch (typeof value) {\n    case 'string':\n      return JSON.stringify(value)\n    case 'number':\n    case 'boolean':\n      return String(value)\n    case 'bigint':\n      return `${value}n`\n    case 'undefined':\n      return 'undefined'\n    case 'symbol':\n      // Symbols are outside EncodableValue but `typeof` can still surface one through `unknown`;\n      // render the description rather than throwing.\n      return String(value)\n    case 'function':\n      // Functions are outside EncodableValue; render a marker rather than throwing.\n      return '<function>'\n    case 'object':\n      break\n    default: {\n      const exhaustive: never = value\n      void exhaustive\n      return String(value)\n    }\n  }\n  if (value === null) return 'null'\n  if (isInstanceOf(value, 'Date', Date)) return `Date(${value.toISOString()})`\n  if (isInstanceOf(value, 'RegExp', RegExp)) return `RegExp(${value.source})`\n  if (isInstanceOf(value, 'ArrayBuffer', ArrayBuffer))\n    return `ArrayBuffer(${value.byteLength} bytes)`\n  if (isInstanceOf(value, 'DataView', DataView)) return `DataView(${value.byteLength} bytes)`\n  if (isInstanceOf(value, 'Map', Map)) {\n    const entries = [...value.entries()]\n      .map(\n        ([k, v]) =>\n          `${formatValue(k as EncodableValue, ctx)}: ${formatValue(v as EncodableValue, ctx)}`\n      )\n      .join(', ')\n    return `Map{${entries}}`\n  }\n  if (isInstanceOf(value, 'Set', Set)) {\n    const items = [...value.values()].map((v) => formatValue(v as EncodableValue, ctx)).join(', ')\n    return `Set{${items}}`\n  }\n  if (Array.isArray(value)) {\n    return `[${value.map((v) => formatValue(v, ctx)).join(', ')}]`\n  }\n  if (ArrayBuffer.isView(value) && !isInstanceOf(value, 'DataView', DataView)) {\n    // Typed array (Int8Array, Uint8Array, …). Render length plus a byte hint.\n    const ctor = value.constructor as { name?: string }\n    const name = ctor.name ?? 'TypedArray'\n    return `${name}(${(value as unknown as { length: number }).length})`\n  }\n  if (isObject(value)) {\n    // A plain record. Sort keys for determinism.\n    return formatEncodableRecord(value as Record<string, EncodableValue>, ctx)\n  }\n  // An object with a non-plain prototype we did not name above (e.g. a luxon DateTime/Duration/\n  // Interval). Render its constructor name and toString rather than collapsing to {}.\n  const ctor = (value as { constructor?: { name?: string } }).constructor\n  const name = ctor?.name ?? 'object'\n  const text = (() => {\n    try {\n      return String(value)\n    } catch {\n      return '<unstringifiable>'\n    }\n  })()\n  return `${name}(${text})`\n}\n\n/**\n * Format a plain `EncodableValue` record with sorted keys.\n */\nconst formatEncodableRecord = (rec: Record<string, EncodableValue>, ctx: RenderContext): string => {\n  const keys = Object.keys(rec).sort()\n  const parts = keys.map((k) => `${JSON.stringify(k)}: ${formatValue(rec[k], ctx)}`)\n  return `{${parts.join(', ')}}`\n}\n\n// ── run projection helpers ───────────────────────────────────────────────────\n/**\n * The rolled-up status of a node for the `as_executed` view, or `undefined` for `as_planned`.\n */\nconst nodeStatus = (ctx: RenderContext, nodeId: NodeId): string | undefined => {\n  if (ctx.view !== 'as_executed' || !ctx.run) return undefined\n  return ctx.run.nodeStatusById.get(nodeId)\n}\n\n/**\n * Resolve a `NodeRef` against an `OutputTable`, returning a formatted string of its selected\n * value(s) or `undefined` when the referenced output is absent (the run did not produce it).\n *\n * @remarks\n * The key is the same `${nodeId}:${branchKey(branchId)}` the rest of the battery uses, so this\n * resolves exactly what the executor would resolve. `select: 'all'` renders a bracketed list;\n * `select: {index}` renders a single item; `first`/`last` render the obvious endpoint.\n */\nconst resolveNodeRef = (ref: NodeRef, outputs: RunProjection['outputs']): string | undefined => {\n  const key = ref.branchId ? `${ref.node}:${branchKeyOfString(ref.branchId)}` : ref.node\n  // The OutputTable is keyed `${nodeId}:${branchKey}`; when a ref carries no branchId the\n  // executor resolves against the single matching key for that node, so scan for it.\n  let entry: { items: { json: Record<string, EncodableValue> }[] } | undefined\n  if (ref.branchId) {\n    entry = outputs.get(key) as typeof entry\n  } else {\n    for (const [k, v] of outputs.entries()) {\n      if (k.startsWith(`${ref.node}:`)) {\n        entry = v as typeof entry\n        break\n      }\n    }\n  }\n  if (!entry || entry.items.length === 0) return undefined\n  const items = entry.items\n  const pick = (idx: number): Record<string, EncodableValue> | undefined => {\n    const item = items[idx]\n    return item ? item.json : undefined\n  }\n  let selected: unknown\n  if (ref.select === 'first') selected = pick(0)\n  else if (ref.select === 'last') selected = pick(items.length - 1)\n  else if (ref.select === 'all') selected = items.map((i) => i.json)\n  else selected = pick(ref.select.index)\n  if (selected === undefined) return undefined\n  if (ref.path) {\n    if (!isObject(selected)) return undefined\n    selected = readPath(selected as Record<string, EncodableValue>, ref.path)\n    if (selected === undefined) return undefined\n  }\n  return formatResolvedValue(selected)\n}\n\n/**\n * Read a dot-path from a record, returning `undefined` when any segment is absent.\n */\nconst readPath = (\n  root: Record<string, EncodableValue>,\n  path: string\n): EncodableValue | undefined => {\n  let cur: unknown = root\n  for (const seg of path.split('.')) {\n    if (isObject(cur) && seg in cur) {\n      cur = (cur as Record<string, unknown>)[seg]\n    } else {\n      return undefined\n    }\n  }\n  return cur as EncodableValue | undefined\n}\n\n/**\n * Format a resolved value for inline display next to a ref's provenance.\n */\nconst formatResolvedValue = (value: unknown): string => {\n  if (Array.isArray(value)) {\n    return `[${value.map((v) => JSON.stringify(v)).join(', ')}]`\n  }\n  if (isObject(value)) {\n    return JSON.stringify(value)\n  }\n  return JSON.stringify(value)\n}\n\n/**\n * A local re-derivation of the branch-key string for resolution. The canonical `branchKey` lives\n * in the encoding battery and is importable, but to keep this renderer a pure function of the\n * shapes in `./types` plus `./encoding` and `./plan` (and avoid pulling the encoder's\n * registration into a display path), we re-derive the same length-prefixed form the encoding\n * battery documents as its injective key. This mirrors `branchKey` exactly; the encoding battery's\n * own implementation is the authority and this is a display-side echo of it.\n */\nconst branchKeyOfString = (branch: BranchId): string => {\n  if (branch.segments.length === 0) return ''\n  let out = ''\n  for (const seg of branch.segments) {\n    if ('edge' in seg) {\n      out += `e${seg.edge.length}:${seg.edge}`\n    } else {\n      const ofPart = seg.of.map((id: string) => `${id.length}:${id}`).join('')\n      out += `j${seg.join.length}:${seg.join}(${ofPart})`\n    }\n  }\n  return out\n}\n\n/**\n * Render an interruption cause as a one-line label for the header.\n */\nconst describeInterruption = (cause: RunProjection['interruption']): string => {\n  if (!cause) return 'unknown'\n  switch (cause.kind) {\n    case 'turn_abort':\n      return 'turn abort'\n    case 'operator_stop':\n      return 'operator stop'\n    case 'gate_timeout':\n      return 'gate timeout'\n    case 'process_death':\n      return 'process death'\n    case 'budget_exhausted':\n      return `step budget exhausted after ${cause.settled} settlement(s)`\n    case 'deviation_abort':\n      return `deviation abort: ${cause.detail}`\n    case 'node_failed':\n      return `node ${cause.nodeId} failed (unhandled)`\n    case 'predicate_unevaluatable':\n      return `predicate unevaluatable at node ${cause.nodeId}`\n    case 'join_unsatisfiable':\n      return `join ${cause.nodeId} unsatisfiable`\n    case 'output_schema_violation':\n      return `output schema violated at node ${cause.nodeId}`\n    case 'authority_revoked':\n      return `authority revoked: ${describeAuthority(cause.claim)}`\n    default: {\n      const exhaustive: never = cause\n      void exhaustive\n      return String(cause)\n    }\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgH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