/**
 * The anchor's body as the code reads it — the Steps view's second reading.
 *
 * `steps.ts` walks FORWARD from the anchor and draws what it sets in motion,
 * a row per distance. That is the right picture for a screen, where handlers
 * fire on events and nothing orders them. It is the wrong one for a handler:
 * on proshop's login, `User.findOne`, `jwt.sign`, `200` and `401` are each one
 * step from the anchor and land side by side, when the code says *first the
 * lookup, then IF the password matches sign a token and answer 200, ELSE
 * answer 401* — and the signing happens INSIDE the reply it is part of.
 *
 * This file turns the same walk into that reading: items in source order,
 * forks where the code forks, an arm that replies or leaves ending there, and
 * a folded helper drawn in place at the call. It is a pure function of the
 * records the walk made ({@link ProgramSite}) — no graph, no source, no
 * control-flow graph. A fork exists only where a guard was READ, so a language
 * without rules, or a file that drifted since the index, yields a plain
 * sequence rather than an invented structure.
 *
 * What makes the fold possible is that a guard names the DECISION it belongs
 * to and not just its own words (`BranchGuard.branch`): the `if` and the
 * `else` of one statement carry the same branch with `negated` flipped, an
 * early exit carries the branch of the `if` that returned, and every case of a
 * switch carries the branch of the switch. Two sites are arms of one fork when
 * they agree on the branch and disagree on the arm — which a joined condition
 * string can never say.
 */
import { type BranchGuard, type SiteLoop } from '../../graph/branch-guards';
import type { WireNodeRef } from './wire';
/** How an arm of a fork leaves, when it does — the rail stops there. */
export type WireArmEnd = 'reply' | 'return' | 'throw' | 'exit';
export interface WireArm {
    /** This arm's own condition, in the words the rest of the view uses. */
    when: string;
    /** The arm taken when the fork's condition does NOT hold — the `else` side. */
    not?: true;
    /** How it leaves: it answers the request, returns, or throws. Null = it runs on. */
    ends: WireArmEnd | null;
    body: WireBlock;
}
export type WireBlock = WireItem[];
export type WireItem = 
/**
 * A step of the picture, where the code writes it. `body` is what it does,
 * when the walk entered it; `again` says it happens here too and was read
 * above — a function is read ONCE in a rail, however many times it is called.
 */
{
    kind: 'step';
    step: string;
    link?: string;
    within?: string;
    body?: WireBlock;
    again?: true;
}
/** A decision: `if` / `else`, a `switch`, a ternary, a `try`, or an early exit. */
 | {
    kind: 'fork';
    on: string;
    form: 'if' | 'switch' | 'ternary' | 'try';
    arms: WireArm[];
}
/**
 * A run of items that is not plain sequence: a helper drawn where it is
 * called (`inline`), a body that runs for each item (`loop`), work that runs
 * after this function returns (`later`), or calls started together
 * (`together`).
 */
 | {
    kind: 'block';
    block: 'inline' | 'loop' | 'later' | 'together';
    by?: string;
    /** For a loop: whether it runs once per item or while a condition holds. */
    loop?: 'each' | 'while';
    via?: WireNodeRef;
    within?: string;
    body: WireBlock;
    again?: true;
}
/** Where the reading stopped: a helper that calls itself, or a cap the walk hit. */
 | {
    kind: 'cut';
    why: 'folded' | 'depth';
};
export interface WireProgram {
    root: WireBlock;
    /** Items the reading could not place — a recursion or a cap it hit. */
    truncated: number;
}
/** One thing that happens in one function, and where the code writes it. */
export interface ProgramSite {
    /** The step reached here, when one is. */
    step?: string;
    /** The link that step arrived on — the panel's row for this site. */
    link?: string;
    /** The helper the walk folded into here; its own sites are its body. */
    into?: string;
    /** Where the call is written: its start, and the end of its span. */
    at: {
        line: number;
        column: number;
        end: {
            line: number;
            column: number;
        };
    };
    /** The call this one is written inside the arguments of (`res.json`). */
    within?: string;
    /** The conditions it runs under, outermost first. */
    guards: BranchGuard[];
    /** The loops it is written inside, outermost first. */
    loops?: SiteLoop[];
    /** What fires it, when something binds it — a callback runs LATER. */
    trigger?: {
        kind: string;
        name: string;
        of?: string | null;
    };
}
export interface ProgramInput {
    /** The sites of each function, by the function's node id. */
    sites: ReadonlyMap<string, readonly ProgramSite[]>;
    /** Where the reading starts: the anchor's root function. */
    root: string | null;
    /** A folded helper, for the words on the block it opens. */
    node(id: string): WireNodeRef | null;
    /**
     * What a step is, for the two things the reading needs to know: whether it
     * ANSWERS (a reply ends its arm), and the function to read on into when the
     * walk entered it (null for a boundary, an effect, or a step of its own
     * chapter).
     */
    step(id: string): {
        reply: boolean;
        into: string | null;
    } | null;
}
export declare function buildProgram(input: ProgramInput): WireProgram | null;
//# sourceMappingURL=program.d.ts.map