@re-cinq/floor-assembly-lines 0.0.0-stage → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +146 -2
  3. package/dist/agent-verdict.d.ts +14 -0
  4. package/dist/agent-verdict.js +55 -0
  5. package/dist/definition-hash.d.ts +1 -0
  6. package/dist/definition-hash.js +21 -0
  7. package/dist/diamond.fixtures.d.ts +6 -0
  8. package/dist/diamond.fixtures.js +33 -0
  9. package/dist/event-names.d.ts +3 -0
  10. package/dist/event-names.js +4 -0
  11. package/dist/fanout.d.ts +26 -0
  12. package/dist/fanout.fixtures.d.ts +4 -0
  13. package/dist/fanout.fixtures.js +32 -0
  14. package/dist/fanout.js +120 -0
  15. package/dist/index.d.ts +15 -0
  16. package/dist/index.js +16 -0
  17. package/dist/line-args.d.ts +2 -0
  18. package/dist/line-args.js +5 -0
  19. package/dist/line-fanout.d.ts +4 -0
  20. package/dist/line-fanout.js +91 -0
  21. package/dist/line-graph.d.ts +10 -0
  22. package/dist/line-graph.js +52 -0
  23. package/dist/line-needs.d.ts +40 -0
  24. package/dist/line-needs.js +100 -0
  25. package/dist/line-stations.d.ts +14 -0
  26. package/dist/line-stations.js +15 -0
  27. package/dist/line-validation.d.ts +6 -0
  28. package/dist/line-validation.js +169 -0
  29. package/dist/node-events.d.ts +41 -0
  30. package/dist/node-events.js +57 -0
  31. package/dist/placeholder-pattern.d.ts +2 -0
  32. package/dist/placeholder-pattern.js +7 -0
  33. package/dist/prompt-parameters.d.ts +20 -0
  34. package/dist/prompt-parameters.js +51 -0
  35. package/dist/prompt-placeholders.d.ts +28 -0
  36. package/dist/prompt-placeholders.js +47 -0
  37. package/dist/refusal.d.ts +3 -0
  38. package/dist/refusal.js +8 -0
  39. package/dist/start-events.d.ts +4 -0
  40. package/dist/start-events.js +13 -0
  41. package/dist/transition.d.ts +71 -0
  42. package/dist/transition.js +162 -0
  43. package/dist/walk-budget.d.ts +8 -0
  44. package/dist/walk-budget.js +27 -0
  45. package/package.json +58 -4
@@ -0,0 +1,169 @@
1
+ // Pure: what makes a line body self-consistent, beyond its JSON shape — every problem, not the first.
2
+ import { isTerminalNode } from "./transition.js";
3
+ import { fanoutChecks } from "./line-fanout.js";
4
+ import { goingOutOf, reachableAvoiding, reachedFrom } from "./line-graph.js";
5
+ import { needChecks } from "./line-needs.js";
6
+ import { bareStationOf, hasStation, isPinned, resolvedStationOf } from "./line-stations.js";
7
+ export function validateLine(line, known) {
8
+ const ids = new Set(line.nodes.map((node) => node.id));
9
+ return [
10
+ ...nodeNameChecks(line, ids),
11
+ ...uniqueNodeIdChecks(line),
12
+ ...outgoingEdgeChecks(line),
13
+ ...reachabilityChecks(line, ids),
14
+ ...startArgChecks(line),
15
+ ...subjectArgChecks(line),
16
+ ...stationChecks(line, known),
17
+ ...reportChecks(line),
18
+ ...outcomeEdgeChecks(line, known),
19
+ ...cycleChecks(line, known),
20
+ ...needChecks(line, known.bodies),
21
+ ...fanoutChecks(line, known.bodies),
22
+ ];
23
+ }
24
+ function nodeNameChecks(line, ids) {
25
+ const problems = [];
26
+ if (!ids.has(line.entry))
27
+ problems.push(`entry "${line.entry}" is not a node`);
28
+ if (!ids.has(line.exit))
29
+ problems.push(`exit "${line.exit}" is not a node`);
30
+ problems.push(...failNameChecks(line, ids));
31
+ line.edges.forEach((edge, index) => {
32
+ if (!ids.has(edge.from))
33
+ problems.push(`edge ${index}: from "${edge.from}" is not a node`);
34
+ if (!ids.has(edge.to))
35
+ problems.push(`edge ${index}: to "${edge.to}" is not a node`);
36
+ });
37
+ return problems;
38
+ }
39
+ function failNameChecks(line, ids) {
40
+ const fail = line.fail;
41
+ if (fail === undefined)
42
+ return [];
43
+ const problems = [];
44
+ if (!ids.has(fail))
45
+ problems.push(`fail "${fail}" is not a node`);
46
+ if (fail === line.exit)
47
+ problems.push(`fail "${fail}" is also the exit`);
48
+ if (fail === line.entry)
49
+ problems.push(`fail "${fail}" is also the entry`);
50
+ return problems;
51
+ }
52
+ function uniqueNodeIdChecks(line) {
53
+ const seen = new Set();
54
+ const duplicates = new Set();
55
+ for (const node of line.nodes) {
56
+ if (seen.has(node.id))
57
+ duplicates.add(node.id);
58
+ seen.add(node.id);
59
+ }
60
+ return [...duplicates].map((id) => `node id "${id}" is used more than once`);
61
+ }
62
+ function outgoingEdgeChecks(line) {
63
+ const problems = [];
64
+ const sourcesWithEdge = new Set();
65
+ line.edges.forEach((edge, index) => {
66
+ if (edge.from === line.exit)
67
+ problems.push(`edge ${index}: exit "${line.exit}" cannot have an outgoing edge`);
68
+ if (edge.from === line.fail)
69
+ problems.push(`edge ${index}: fail "${line.fail}" cannot have an outgoing edge`);
70
+ sourcesWithEdge.add(edge.from);
71
+ });
72
+ for (const node of line.nodes) {
73
+ if (!isTerminalNode(line, node.id) && !sourcesWithEdge.has(node.id))
74
+ problems.push(`node "${node.id}" has no outgoing edge`);
75
+ }
76
+ return problems;
77
+ }
78
+ // A node the walk can never arrive at is dead weight the walk would never report on; a back edge still counts as arriving. Silent when the entry is not a node at all, which nodeNameChecks already says.
79
+ function reachabilityChecks(line, ids) {
80
+ if (!ids.has(line.entry))
81
+ return [];
82
+ const reached = reachedFrom(line);
83
+ const stranded = line.nodes.filter((node) => !reached.has(node.id));
84
+ return stranded.map((node) => `node "${node.id}" is not reachable from entry "${line.entry}"`);
85
+ }
86
+ function startArgChecks(line) {
87
+ const declared = new Set(Object.keys(line.args));
88
+ return Object.keys(line.start?.args ?? {})
89
+ .filter((name) => !declared.has(name))
90
+ .map((name) => `start.args names "${name}", which is not a declared argument`);
91
+ }
92
+ function subjectArgChecks(line) {
93
+ const subjectCount = Object.values(line.args).filter((spec) => spec.subject).length;
94
+ return subjectCount > 1 ? ["more than one argument is marked subject"] : [];
95
+ }
96
+ function stationChecks(line, known) {
97
+ const stationNodes = line.nodes.filter(hasStation);
98
+ return stationNodes.flatMap((node) => {
99
+ const bareStation = bareStationOf(node);
100
+ return known.stations.has(bareStation) ? [] : [`node "${node.id}" names unknown station "${bareStation}"`];
101
+ });
102
+ }
103
+ // A marker reports success the moment it opens, so an event has nothing of its to answer.
104
+ function reportChecks(line) {
105
+ const markersWithReports = line.nodes.filter((node) => !node.station && (node.reports ?? []).length > 0);
106
+ return markersWithReports.map((node) => `node "${node.id}" declares reports but names no station to wait at`);
107
+ }
108
+ // Every outcome a reachable, resolvable station declares needs a way out: an exact edge, or an `always` that catches whatever has none. Pinned and unknown stations are opaque here — stationChecks already says when a name resolves nowhere at all.
109
+ function outcomeEdgeChecks(line, known) {
110
+ const bodies = known.bodies;
111
+ if (!bodies)
112
+ return [];
113
+ const reached = reachedFrom(line);
114
+ const stationNodes = line.nodes.filter(hasStation);
115
+ const checkedNodes = stationNodes.filter((node) => !isTerminalNode(line, node.id) && reached.has(node.id));
116
+ return checkedNodes.flatMap((node) => outcomesMissingEdges(line, node, bodies));
117
+ }
118
+ function outcomesMissingEdges(line, node, bodies) {
119
+ const body = resolvedStationOf(node, bodies);
120
+ if (!body)
121
+ return [];
122
+ const fromNode = line.edges.filter((edge) => edge.from === node.id);
123
+ if (fromNode.some((edge) => edge.on === "always"))
124
+ return [];
125
+ const covered = new Set(fromNode.map((edge) => edge.on));
126
+ const missing = body.outcomes.filter((outcome) => !covered.has(outcome));
127
+ return missing.map((outcome) => `node "${node.id}" has no edge for outcome "${outcome}"`);
128
+ }
129
+ // A cycle is safe when something can stop it going round forever: a spent iteration_max, or a human deciding whether to send it round again. Everything else survives the prune below, and a node still reaching itself there is an unguarded cycle. Only a station node can be flagged as part of one — a marker does no work of its own to retry, though it still carries the walk through when it sits between two stations that do.
130
+ function cycleChecks(line, known) {
131
+ const unbudgeted = goingOutOf(line.edges.filter((edge) => edge.iterationMax === undefined));
132
+ const guardNodes = line.nodes.filter((node) => isCycleGuard(node, known.bodies));
133
+ const guards = new Set(guardNodes.map((node) => node.id));
134
+ const stationNodes = line.nodes.filter((node) => hasStation(node) && !guards.has(node.id));
135
+ const candidates = stationNodes.map((node) => node.id);
136
+ const groups = groupCyclicNodes(unbudgeted, guards, candidates);
137
+ return groups.map(cycleMessage);
138
+ }
139
+ function isCycleGuard(node, bodies) {
140
+ if (!hasStation(node))
141
+ return false;
142
+ if (isPinned(node))
143
+ return true;
144
+ if (!bodies)
145
+ return false;
146
+ const body = bodies.get(bareStationOf(node));
147
+ return !body || body.kind === "human";
148
+ }
149
+ // Which candidates can walk back to themselves through the pruned graph, grouped so a cycle of several nodes is reported once, not once per member.
150
+ function groupCyclicNodes(unbudgeted, guards, candidates) {
151
+ const reachesFromNeighbors = candidates.map((id) => ({ id, reaches: reachableAvoiding(unbudgeted, unbudgeted.get(id) ?? [], guards) }));
152
+ const cyclic = reachesFromNeighbors.filter(({ id, reaches }) => reaches.has(id));
153
+ const seen = new Set();
154
+ const groups = [];
155
+ for (const { id, reaches } of cyclic) {
156
+ if (seen.has(id))
157
+ continue;
158
+ const mutual = cyclic.filter((other) => other.id === id || (reaches.has(other.id) && other.reaches.has(id)));
159
+ const group = mutual.map((other) => other.id);
160
+ group.forEach((member) => seen.add(member));
161
+ groups.push(group);
162
+ }
163
+ return groups;
164
+ }
165
+ function cycleMessage(members) {
166
+ const names = members.map((id) => `"${id}"`).join(", ");
167
+ return `cycle through ${names} has no iteration_max and no human node`;
168
+ }
169
+ //# sourceMappingURL=line-validation.js.map
@@ -0,0 +1,41 @@
1
+ import type { LineBody, LineNode, StationBody, WhenValue } from "@re-cinq/floor-contracts";
2
+ export interface CollectionLine {
3
+ id: string;
4
+ body: LineBody;
5
+ }
6
+ /** `walk`: an edge leads here. `outside`: the node names its own start event. `line-start`: the line's own start raises it. `none`: nothing does. */
7
+ export type StartOrigin = "walk" | "outside" | "line-start" | "none";
8
+ export interface StartedBy {
9
+ event: string;
10
+ origin: StartOrigin;
11
+ when?: Record<string, WhenValue>;
12
+ }
13
+ export interface AnsweredBy {
14
+ event: string;
15
+ when?: Record<string, WhenValue>;
16
+ outcome: string;
17
+ }
18
+ export interface OutcomeTarget {
19
+ /** The edge's `on`: the outcome itself, or `always`. */
20
+ on: string;
21
+ node: string;
22
+ event: string;
23
+ }
24
+ export type Raised = {
25
+ kind: "event";
26
+ event: string;
27
+ } | {
28
+ kind: "outcome";
29
+ outcome: string;
30
+ leadsTo: OutcomeTarget | null;
31
+ } | {
32
+ kind: "starts-line";
33
+ line: string;
34
+ when?: Record<string, WhenValue>;
35
+ };
36
+ export interface NodeEvents {
37
+ startedBy: StartedBy[];
38
+ answeredBy: AnsweredBy[];
39
+ raises: Raised[];
40
+ }
41
+ export declare function nodeEvents(line: LineBody, node: LineNode, lines: readonly CollectionLine[], bodies: ReadonlyMap<string, StationBody>): NodeEvents;
@@ -0,0 +1,57 @@
1
+ // Pure: the events a node is started by, answered by and raises, for a tool that draws a line. It reads the same rules the dispatcher walks: a node's start event, a station's outcomes and the edge `selectEdge` takes for each.
2
+ import { DISPATCH_EVENT, REPORTED_EVENT, RUN_SETTLED_EVENT } from "./event-names.js";
3
+ import { hasStation, resolvedStationOf } from "./line-stations.js";
4
+ import { startEventName } from "./start-events.js";
5
+ import { isTerminalNode, selectEdge } from "./transition.js";
6
+ export function nodeEvents(line, node, lines, bodies) {
7
+ return {
8
+ startedBy: startedByOf(line, node),
9
+ answeredBy: (node.reports ?? []).map(({ on, when, outcome }) => ({ event: on, ...(when && { when }), outcome })),
10
+ raises: raisesOf(line, node, lines, bodies),
11
+ };
12
+ }
13
+ function startedByOf(line, node) {
14
+ const own = { event: startEventName(node), origin: originOf(line, node) };
15
+ const entryEvents = node.id === line.entry ? (line.start?.on ?? []) : [];
16
+ const fromLineStart = entryEvents.map((event) => ({ event, origin: "line-start", ...(line.start?.when && { when: line.start.when }) }));
17
+ return [own, ...fromLineStart];
18
+ }
19
+ function originOf(line, node) {
20
+ if (node.start)
21
+ return "outside";
22
+ if (line.edges.some((edge) => edge.to === node.id))
23
+ return "walk";
24
+ return node.id === line.entry ? "line-start" : "none";
25
+ }
26
+ function raisesOf(line, node, lines, bodies) {
27
+ if (isTerminalNode(line, node.id))
28
+ return settledBy(lines);
29
+ const station = hasStation(node) ? resolvedStationOf(node, bodies) : undefined;
30
+ const stationEvents = hasStation(node) ? reportedEvents(station) : [];
31
+ return [...stationEvents, ...outcomesOf(line, node, station)];
32
+ }
33
+ function settledBy(lines) {
34
+ const waiting = lines.filter(({ body }) => startsOn(body, RUN_SETTLED_EVENT));
35
+ const started = waiting.map(({ id, body }) => ({ kind: "starts-line", line: id, ...(body.start?.when && { when: body.start.when }) }));
36
+ return [{ kind: "event", event: RUN_SETTLED_EVENT }, ...started];
37
+ }
38
+ function startsOn(line, eventName) {
39
+ const events = line.start?.on ?? [];
40
+ return events.includes(eventName);
41
+ }
42
+ function reportedEvents(station) {
43
+ const dispatched = station?.kind === "agent" || station?.kind === "service";
44
+ const dispatch = dispatched ? [{ kind: "event", event: DISPATCH_EVENT }] : [];
45
+ return [...dispatch, { kind: "event", event: REPORTED_EVENT }];
46
+ }
47
+ // A marker reports success the moment it opens, so that is the one outcome it can take an edge on.
48
+ function outcomesOf(line, node, station) {
49
+ const outcomes = hasStation(node) ? (station?.outcomes ?? []) : ["success"];
50
+ return outcomes.map((outcome) => ({ kind: "outcome", outcome, leadsTo: targetOf(line, node.id, outcome) }));
51
+ }
52
+ function targetOf(line, nodeId, outcome) {
53
+ const edge = selectEdge({ name: "", ...line }, nodeId, outcome);
54
+ const next = line.nodes.find((candidate) => candidate.id === edge?.to);
55
+ return edge && next ? { on: edge.on, node: next.id, event: startEventName(next) } : null;
56
+ }
57
+ //# sourceMappingURL=node-events.js.map
@@ -0,0 +1,2 @@
1
+ /** A fresh `{name}` pattern capturing the name; fresh so a global one's `lastIndex` is never shared. */
2
+ export declare function placeholderPattern(flags?: string): RegExp;
@@ -0,0 +1,7 @@
1
+ // The agent subsystem's `renderPrompt` replaces `{key}` for letters, digits, `_`, `.` and `-`, and leaves what it does not know as it is. A name here must also start with a letter or `_`, as every need does, so `a{3}` and `{}` are not read as placeholders; a JSON object never matches, its braces enclose quotes.
2
+ const PLACEHOLDER_SOURCE = String.raw `\{([A-Za-z_][A-Za-z0-9_.-]*)\}`;
3
+ /** A fresh `{name}` pattern capturing the name; fresh so a global one's `lastIndex` is never shared. */
4
+ export function placeholderPattern(flags = "") {
5
+ return new RegExp(PLACEHOLDER_SOURCE, flags);
6
+ }
7
+ //# sourceMappingURL=placeholder-pattern.js.map
@@ -0,0 +1,20 @@
1
+ import type { BriefNeed, NeedSpec, ProduceSpec, StationBody, VisitBrief } from "@re-cinq/floor-contracts";
2
+ /** Where the subsystem clones, downloads and watches. With no repo cloned the agent's own working directory is `/`, which is why a bare relative path in a prompt lands in the wrong place. */
3
+ export declare const WORKSPACE = "/workspace";
4
+ export declare const RUN_PARAMETER_NAMES: readonly string[];
5
+ /** Given to a visit that has a git need, and to none other: the subsystem lifts them into the clone's credential helper. */
6
+ export declare const GIT_CREDENTIAL_PARAMETER = "git_credential";
7
+ export declare const GIT_CREDENTIAL_URL_PARAMETER = "git_credential_url";
8
+ export declare const BROKER_PARAMETER_NAMES: readonly string[];
9
+ export declare function runParameters(run: Pick<VisitBrief, "runId" | "lineId" | "nodeId">): Record<string, string>;
10
+ export declare function promptParameters(needs: readonly BriefNeed[], produces: readonly ProduceSpec[]): Record<string, string>;
11
+ /** Where a non-value need lands in the workspace: the path it declares, or its own name. */
12
+ export declare function needPathOf(need: Pick<NeedSpec, "name" | "path">): string;
13
+ export interface DeclaredParameter {
14
+ name: string;
15
+ from: "value-need" | "need-path" | "produce-path";
16
+ /** The need or produce that gives it. */
17
+ source: string;
18
+ }
19
+ /** The parameters a station's declaration gives its prompt, named by the rules `promptParameters` applies to a brief. Paths first and values last, so the last of a name is the one that wins. */
20
+ export declare function declaredParameters(station: Pick<StationBody, "needs" | "produces">): DeclaredParameter[];
@@ -0,0 +1,51 @@
1
+ // What fills a prompt's `{placeholders}`: each value need under its own name, and `{<name>_path}` for everything that has a place in the workspace, so a prompt never has to know where the workspace is. Beneath those, the visit's own three, `{run_id}`, `{line_id}` and `{node_id}`: a value need of the same name wins.
2
+ import { posix } from "node:path";
3
+ /** Where the subsystem clones, downloads and watches. With no repo cloned the agent's own working directory is `/`, which is why a bare relative path in a prompt lands in the wrong place. */
4
+ export const WORKSPACE = "/workspace";
5
+ const PATH_SUFFIX = "_path";
6
+ const RUN_PARAMETERS = { run_id: "runId", line_id: "lineId", node_id: "nodeId" };
7
+ export const RUN_PARAMETER_NAMES = Object.keys(RUN_PARAMETERS);
8
+ /** Given to a visit that has a git need, and to none other: the subsystem lifts them into the clone's credential helper. */
9
+ export const GIT_CREDENTIAL_PARAMETER = "git_credential";
10
+ export const GIT_CREDENTIAL_URL_PARAMETER = "git_credential_url";
11
+ export const BROKER_PARAMETER_NAMES = [GIT_CREDENTIAL_PARAMETER, GIT_CREDENTIAL_URL_PARAMETER];
12
+ export function runParameters(run) {
13
+ return Object.fromEntries(Object.entries(RUN_PARAMETERS).map(([name, field]) => [name, run[field]]));
14
+ }
15
+ export function promptParameters(needs, produces) {
16
+ const placed = [...needs, ...produces].flatMap((entry) => placeOf(entry));
17
+ const values = needs.flatMap((need) => (need.kind === "value" ? [[need.name, need.value]] : []));
18
+ return Object.fromEntries([...placed, ...values]);
19
+ }
20
+ /** Where a non-value need lands in the workspace: the path it declares, or its own name. */
21
+ export function needPathOf(need) {
22
+ return need.path ?? need.name;
23
+ }
24
+ /** The parameters a station's declaration gives its prompt, named by the rules `promptParameters` applies to a brief. Paths first and values last, so the last of a name is the one that wins. */
25
+ export function declaredParameters(station) {
26
+ const { needs, produces } = station;
27
+ const needPaths = needs.filter(isPlaced).flatMap((need) => placed(need.name, needPathOf(need), "need-path"));
28
+ const producePaths = produces.flatMap((produce) => placed(produce.name, produce.path, "produce-path"));
29
+ const values = needs.filter((need) => !isPlaced(need)).map((need) => ({ name: need.name, from: "value-need", source: need.name }));
30
+ return [...needPaths, ...producePaths, ...values];
31
+ }
32
+ function isPlaced(need) {
33
+ return need.kind !== "value";
34
+ }
35
+ function placed(source, path, from) {
36
+ const place = placementOf(source, path);
37
+ return place ? [{ name: place.parameter, from, source }] : [];
38
+ }
39
+ // A value need wins over a path of the same name: it is what the station declared.
40
+ function placeOf(entry) {
41
+ const place = placementOf(entry.name, "path" in entry ? entry.path : undefined);
42
+ return place ? [[place.parameter, place.absolute]] : [];
43
+ }
44
+ function placementOf(name, path) {
45
+ if (path === undefined)
46
+ return null;
47
+ const absolute = posix.join(WORKSPACE, path);
48
+ const inside = absolute === WORKSPACE || absolute.startsWith(`${WORKSPACE}/`);
49
+ return inside ? { parameter: `${name}${PATH_SUFFIX}`, absolute } : null;
50
+ }
51
+ //# sourceMappingURL=prompt-parameters.js.map
@@ -0,0 +1,28 @@
1
+ import { type NeedCoverage } from "./line-needs.js";
2
+ import type { LineBody, LineNode, StationBody } from "@re-cinq/floor-contracts";
3
+ export type PlaceholderSource = "value-need" | "need-path" | "produce-path" | "floor" | "none";
4
+ export type PlaceholderState = "unsupplied" | "filled" | NeedCoverage["kind"];
5
+ export interface PlaceholderRow {
6
+ name: string;
7
+ source: PlaceholderSource;
8
+ state: PlaceholderState;
9
+ /** The nodes that produce it, for `filled` and `sometimes-empty`. */
10
+ filledBy: string[];
11
+ /** For `sometimes-empty`: one walk of node ids, from a start point to this node, that passes none of `filledBy`. */
12
+ path: string[];
13
+ }
14
+ export interface PromptPlaceholders {
15
+ placeholders: PlaceholderRow[];
16
+ /** Needs the prompt never mentions, as `{name}` or `{name_path}`, leaving out those the floor fills. */
17
+ unused: string[];
18
+ }
19
+ export interface PromptPlaceholderInput {
20
+ prompt: string;
21
+ line: LineBody;
22
+ node: LineNode;
23
+ station: StationBody;
24
+ bodies: ReadonlyMap<string, StationBody>;
25
+ }
26
+ /** Each distinct name in `{name}` form, in order of first appearance. */
27
+ export declare function placeholderNames(prompt: string): string[];
28
+ export declare function promptPlaceholders(input: PromptPlaceholderInput): PromptPlaceholders;
@@ -0,0 +1,47 @@
1
+ // Pure: every `{name}` a prompt reads, what supplies it, and whether it is filled on every path into the node — answered from the same naming rules `promptParameters` applies, so a tool and the cluster agent cannot disagree.
2
+ import { EXEMPT_NEEDS, coverageContextOf, needCoverage } from "./line-needs.js";
3
+ import { placeholderPattern } from "./placeholder-pattern.js";
4
+ import { BROKER_PARAMETER_NAMES, RUN_PARAMETER_NAMES, declaredParameters } from "./prompt-parameters.js";
5
+ const PATH_SUFFIX = "_path";
6
+ /** Each distinct name in `{name}` form, in order of first appearance. */
7
+ export function placeholderNames(prompt) {
8
+ return [...new Set([...prompt.matchAll(placeholderPattern("g"))].map(([, name]) => name))];
9
+ }
10
+ export function promptPlaceholders(input) {
11
+ const names = placeholderNames(input.prompt);
12
+ const context = coverageContextOf(input.line, input.bodies);
13
+ const parameters = declaredParameters(input.station);
14
+ return {
15
+ placeholders: names.map((name) => rowOf(name, input, { parameters, context })),
16
+ unused: unusedNeeds(input, new Set(names)),
17
+ };
18
+ }
19
+ function rowOf(name, input, supply) {
20
+ const given = supply.parameters.findLast((parameter) => parameter.name === name);
21
+ if (given)
22
+ return givenRow(name, given, input, supply.context);
23
+ const byFloor = floorNamesOf(input.station).includes(name);
24
+ return { name, source: byFloor ? "floor" : "none", state: byFloor ? "filled" : "unsupplied", filledBy: [], path: [] };
25
+ }
26
+ function givenRow(name, given, input, context) {
27
+ const { station, node } = input;
28
+ const need = station.needs.find((candidate) => given.from !== "produce-path" && candidate.name === given.source);
29
+ const coverage = need ? needCoverage(node, need, context) : { kind: "filled", producedBy: [] };
30
+ return {
31
+ name,
32
+ source: given.from,
33
+ state: coverage.kind,
34
+ filledBy: "producedBy" in coverage ? coverage.producedBy : [],
35
+ path: "pathWithout" in coverage ? coverage.pathWithout : [],
36
+ };
37
+ }
38
+ // The visit's broker parameters go only to a visit that has a git need.
39
+ function floorNamesOf(station) {
40
+ const hasGitNeed = station.needs.some((need) => need.kind === "git");
41
+ return [...RUN_PARAMETER_NAMES, ...EXEMPT_NEEDS, ...(hasGitNeed ? BROKER_PARAMETER_NAMES : [])];
42
+ }
43
+ function unusedNeeds({ station, node }, mentioned) {
44
+ const unmentioned = station.needs.filter((need) => !mentioned.has(need.name) && !mentioned.has(`${need.name}${PATH_SUFFIX}`));
45
+ return unmentioned.filter((need) => !EXEMPT_NEEDS.includes(node.bind?.[need.name] ?? need.name)).map((need) => need.name);
46
+ }
47
+ //# sourceMappingURL=prompt-placeholders.js.map
@@ -0,0 +1,3 @@
1
+ export declare class Refusal extends Error {
2
+ }
3
+ export declare function enforce(condition: unknown, message: string): asserts condition;
@@ -0,0 +1,8 @@
1
+ // A request the store understood and will never accept: retrying it cannot help, which is what separates it from a database error.
2
+ export class Refusal extends Error {
3
+ }
4
+ export function enforce(condition, message) {
5
+ if (!condition)
6
+ throw new Refusal(message);
7
+ }
8
+ //# sourceMappingURL=refusal.js.map
@@ -0,0 +1,4 @@
1
+ import type { LineBody, LineNode } from "@re-cinq/floor-contracts";
2
+ export declare function startEventName(node: LineNode): string;
3
+ export declare function nodeStartedBy(line: LineBody, eventName: string): LineNode | null;
4
+ export declare function requireNode(line: LineBody, nodeId: string): LineNode;
@@ -0,0 +1,13 @@
1
+ import { enforce } from "./refusal.js";
2
+ export function startEventName(node) {
3
+ return node.start ?? `node.${node.id}.start`;
4
+ }
5
+ export function nodeStartedBy(line, eventName) {
6
+ return line.nodes.find((node) => startEventName(node) === eventName) ?? null;
7
+ }
8
+ export function requireNode(line, nodeId) {
9
+ const node = line.nodes.find((candidate) => candidate.id === nodeId);
10
+ enforce(node, `no node "${nodeId}" in this line`);
11
+ return node;
12
+ }
13
+ //# sourceMappingURL=start-events.js.map
@@ -0,0 +1,71 @@
1
+ export interface WalkEdge {
2
+ from: string;
3
+ to: string;
4
+ on: string;
5
+ iterationMax?: number;
6
+ }
7
+ export type StationKind = "agent" | "service" | "human";
8
+ export interface WalkGraph {
9
+ name: string;
10
+ entry: string;
11
+ exit: string;
12
+ /** A second terminal beside `exit`: a walk that arrives here ends the run as failed on purpose. */
13
+ fail?: string;
14
+ edges: readonly WalkEdge[];
15
+ /** Fan-out regions: `source` reports a list of items and `body` then runs once per item; the edge out of `body` is the join and is taken once every branch has reported. */
16
+ fans?: readonly {
17
+ source: string;
18
+ body: string;
19
+ }[];
20
+ /** Node kind, so the node ceiling can tell a person's pass from a machine's; a run recorded without them counts every visit. `kind` absent = marker. */
21
+ nodes?: readonly {
22
+ id: string;
23
+ kind?: StationKind;
24
+ }[];
25
+ }
26
+ /** One visit's (station run's) contribution to the walk state (outcome null = still open). */
27
+ export interface NodeVisit {
28
+ nodeId: string;
29
+ iteration: number;
30
+ outcome: string | null;
31
+ /** The person who opened this visit by hand (docs/assembly_run_storage.md, "reports from outside"); the walk restarts here, so what came before routes nothing and spends no budget. */
32
+ requestedBy?: string | null;
33
+ /** Which item of a fan-out this visit is the body for; absent on an ordinary visit. */
34
+ branch?: number;
35
+ /** On a fan-out source's visit: how many items it reported, so how many branches follow. */
36
+ branches?: number;
37
+ }
38
+ export type Transition = {
39
+ kind: "launch";
40
+ nodeId: string;
41
+ iteration: number;
42
+ } | {
43
+ kind: "launch-many";
44
+ nodeId: string;
45
+ iteration: number;
46
+ branches: number[];
47
+ } | {
48
+ kind: "await";
49
+ } | {
50
+ kind: "finish";
51
+ } | {
52
+ kind: "halt";
53
+ outcome: "iteration_max" | "error" | "failed";
54
+ reason: string;
55
+ };
56
+ type EndingTransition = Extract<Transition, {
57
+ kind: "finish" | "halt";
58
+ }>;
59
+ export declare function endsRun(transition: Transition): transition is EndingTransition;
60
+ /** The exit and the fail node are both terminal: a walk that arrives at either stops there. */
61
+ export declare function isTerminalNode(assemblyLine: Pick<WalkGraph, "exit" | "fail">, nodeId: string): boolean;
62
+ export declare function selectEdge(assemblyLine: WalkGraph, from: string, outcome: string): WalkEdge | null;
63
+ export interface WalkAccounting {
64
+ backEdgeCounts: Map<string, number>;
65
+ highestIteration: Map<string, number>;
66
+ visited: Set<string>;
67
+ }
68
+ export declare function getNextTransition(assemblyLine: WalkGraph, visits: NodeVisit[], maxNodes?: number): Transition;
69
+ /** The visits the walk routes on: from the last one a person ran by hand, or all of them when nobody did. */
70
+ export declare function visitsSinceHandRun<T extends Pick<NodeVisit, "requestedBy">>(visits: readonly T[]): T[];
71
+ export {};