feat(steps): the same walk, read in the code's order
The picture answers "what does this set in motion", a row per distance from the anchor. On proshop's login that puts `User.findOne`, `jwt.sign`, `200` and `401` side by side — all one step out — when the code says: look the user up, then IF the password matches sign a token and answer 200, ELSE answer 401. The signing is not beside the 200, it happens INSIDE the reply it is part of. So the walk now records what happens in each function where the code writes it — the step reached (or the helper folded into), the call's position and span, and the branch guards, structured — and `api/program.ts` folds those records into the anchor's body: items in source order, a fork wherever two sites are arms of one decision, a helper drawn in place at its call, an arm that answers the request or leaves ending there. A call written inside another call's arguments comes first, so the token is signed before the reply that carries it. It is a derivation, not a second walk: the records are made by the pass that makes the links, so the two readings can never hold different steps. A fork exists only where a guard was READ — a language without rules, or a file that changed since the index, reads as a plain sequence rather than an invented structure. The reading opens each function once, however many times it is called (`again`), and is capped like everything else here. The payload carries it as `program`, with `defaultView`: the code's order for a handler, an endpoint or any function; the tree for a screen, where handlers fire on events and have no order between them. Measured on a 87-step / 160-link screen: +3% wall clock, +95 KB. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01REFyW9hmNrxhwN5wxRoAkC
This commit is contained in:
co-authored by
Claude Opus 5
parent
482690b62d
commit
b02e192ffa
@@ -806,6 +806,46 @@ export interface WireStepLink {
|
||||
trigger?: WireStepTrigger;
|
||||
}
|
||||
|
||||
/* ------------------------------------------- the same walk, in the code's order -- */
|
||||
|
||||
/** 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;
|
||||
/** 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'; label: string; 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;
|
||||
}
|
||||
|
||||
export interface WireStepsPayload {
|
||||
anchor: WireNodeRef;
|
||||
/** Other symbols that share the anchor's name, when it was given by name. */
|
||||
@@ -814,6 +854,13 @@ export interface WireStepsPayload {
|
||||
project: 'app' | 'api' | 'web';
|
||||
steps: WireStep[];
|
||||
links: WireStepLink[];
|
||||
/**
|
||||
* The same walk read in the code's ORDER — the anchor's body as a rail that
|
||||
* forks where the code forks. Null when the anchor has no body to read.
|
||||
*/
|
||||
program: WireProgram | null;
|
||||
/** Which reading to open with; the URL's `view` overrides it. */
|
||||
defaultView: 'order' | 'tree';
|
||||
depth: number;
|
||||
limit: number;
|
||||
/** Screens reached from the anchor were entered rather than drawn as boundaries. */
|
||||
|
||||
Reference in New Issue
Block a user