/** * DeciderHandler — Single-choice conditional branching. * * Handles scope-based deciders (stage IS the decider, returns branch ID). * Logs flow control decisions and narrative sentences. * * Two entry points: * - `prepareDispatch` — runs the decider stage, commits, resolves the chosen * branch, fires narrative, and returns the chosen node + branch context * WITHOUT executing it. The traverser's trampoline driver uses this so a * decider with no continuation of its own can hand the branch to the * driver as a flat hop (loop-heavy decider charts stay flat-stacked). * - `handleScopeBased` — prepareDispatch + immediate branch execution via * the provided `executeNode` callback. Kept for direct/advanced callers * and for deciders whose own `.next` must run after the branch completes. */ import type { StageContext } from '../../memory/StageContext.js'; import type { StageNode } from '../graph/StageNode.js'; import type { TraversalContext } from '../narrative/types.js'; import type { HandlerDeps, StageFunction } from '../types.js'; import type { ExecuteNodeFn, RunStageFn } from './types.js'; export type { ExecuteNodeFn, RunStageFn }; /** * Result of `prepareDispatch` — either the decider stage broke (no branch * runs; `branchId` is the decider's return value), or a branch was chosen * and is ready to execute in `branchContext`. */ export type DeciderDispatch = { kind: 'break'; branchId: string; } | { kind: 'dispatch'; chosen: StageNode; branchContext: StageContext; }; export declare class DeciderHandler { private readonly deps; constructor(deps: HandlerDeps); /** * Handle a scope-based decider (created via addDeciderFunction). * The stage function IS the decider — its return value is the branch ID. * Execution order: runStage(fn) → commit → resolve child → log → executeNode(child). */ handleScopeBased(node: StageNode, stageFunc: StageFunction, context: StageContext, breakFlag: { shouldBreak: boolean; }, branchPath: string | undefined, runStage: RunStageFn, executeNode: ExecuteNodeFn, traversalContext?: TraversalContext): Promise; /** * Run the decider stage and resolve the chosen branch WITHOUT executing it. * Everything up to (and including) the `onDecision`/`onStageExecuted` * narrative and the branch context creation happens here — only the * branch execution itself is left to the caller. */ prepareDispatch(node: StageNode, stageFunc: StageFunction, context: StageContext, breakFlag: { shouldBreak: boolean; }, branchPath: string | undefined, runStage: RunStageFn, traversalContext?: TraversalContext): Promise>; }