@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.
- package/LICENSE +201 -0
- package/README.md +146 -2
- package/dist/agent-verdict.d.ts +14 -0
- package/dist/agent-verdict.js +55 -0
- package/dist/definition-hash.d.ts +1 -0
- package/dist/definition-hash.js +21 -0
- package/dist/diamond.fixtures.d.ts +6 -0
- package/dist/diamond.fixtures.js +33 -0
- package/dist/event-names.d.ts +3 -0
- package/dist/event-names.js +4 -0
- package/dist/fanout.d.ts +26 -0
- package/dist/fanout.fixtures.d.ts +4 -0
- package/dist/fanout.fixtures.js +32 -0
- package/dist/fanout.js +120 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/line-args.d.ts +2 -0
- package/dist/line-args.js +5 -0
- package/dist/line-fanout.d.ts +4 -0
- package/dist/line-fanout.js +91 -0
- package/dist/line-graph.d.ts +10 -0
- package/dist/line-graph.js +52 -0
- package/dist/line-needs.d.ts +40 -0
- package/dist/line-needs.js +100 -0
- package/dist/line-stations.d.ts +14 -0
- package/dist/line-stations.js +15 -0
- package/dist/line-validation.d.ts +6 -0
- package/dist/line-validation.js +169 -0
- package/dist/node-events.d.ts +41 -0
- package/dist/node-events.js +57 -0
- package/dist/placeholder-pattern.d.ts +2 -0
- package/dist/placeholder-pattern.js +7 -0
- package/dist/prompt-parameters.d.ts +20 -0
- package/dist/prompt-parameters.js +51 -0
- package/dist/prompt-placeholders.d.ts +28 -0
- package/dist/prompt-placeholders.js +47 -0
- package/dist/refusal.d.ts +3 -0
- package/dist/refusal.js +8 -0
- package/dist/start-events.d.ts +4 -0
- package/dist/start-events.js +13 -0
- package/dist/transition.d.ts +71 -0
- package/dist/transition.js +162 -0
- package/dist/walk-budget.d.ts +8 -0
- package/dist/walk-budget.js +27 -0
- package/package.json +58 -4
package/dist/fanout.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Fan-out and join over the single-cursor walk: a source node reports a list of items, its body node then runs once per item (a branch), and the walk goes on only when every branch has reported. The kernel keeps its one cursor by folding a finished region's branch visits into ONE visit of the body node, whose outcome is `success` when every branch succeeded and `failed` otherwise; budgets, routing and the join edge are then the ordinary ones.
|
|
2
|
+
export function isFanBody(graph, nodeId) {
|
|
3
|
+
return (graph.fans ?? []).some((fan) => fan.body === nodeId);
|
|
4
|
+
}
|
|
5
|
+
/** The regions in the history, oldest first. */
|
|
6
|
+
export function fanRegions(graph, visits) {
|
|
7
|
+
const regions = [];
|
|
8
|
+
for (const visit of visits) {
|
|
9
|
+
place(graph, regions, visit);
|
|
10
|
+
}
|
|
11
|
+
return regions;
|
|
12
|
+
}
|
|
13
|
+
// One visit's place in the regions: it opens one, joins the open one as a branch, or closes it.
|
|
14
|
+
function place(graph, regions, visit) {
|
|
15
|
+
if (opensRegion(graph, visit)) {
|
|
16
|
+
regions.push({
|
|
17
|
+
source: visit,
|
|
18
|
+
expected: visit.branches ?? 0,
|
|
19
|
+
branches: [],
|
|
20
|
+
closed: false,
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const open = regions.at(-1);
|
|
25
|
+
if (open && isBranchOf(graph, open, visit)) {
|
|
26
|
+
open.branches.push(visit);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (open) {
|
|
30
|
+
open.closed = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function opensRegion(graph, visit) {
|
|
34
|
+
return (visit.outcome === "success" &&
|
|
35
|
+
visit.branches !== undefined &&
|
|
36
|
+
fanOf(graph, visit.nodeId) !== undefined);
|
|
37
|
+
}
|
|
38
|
+
function isBranchOf(graph, region, visit) {
|
|
39
|
+
return (!region.closed &&
|
|
40
|
+
visit.branch !== undefined &&
|
|
41
|
+
visit.nodeId === fanOf(graph, region.source.nodeId)?.body);
|
|
42
|
+
}
|
|
43
|
+
/** Starts the branches the newest region has not started yet, when it has started some: a crash between launches leaves this. */
|
|
44
|
+
export function relaunchMissing(graph, visits) {
|
|
45
|
+
const region = fanRegions(graph, visits).at(-1);
|
|
46
|
+
const first = region?.branches.at(0);
|
|
47
|
+
const branches = region && !region.closed ? unstarted(region) : [];
|
|
48
|
+
return first && branches.length > 0
|
|
49
|
+
? {
|
|
50
|
+
kind: "launch-many",
|
|
51
|
+
nodeId: first.nodeId,
|
|
52
|
+
iteration: first.iteration,
|
|
53
|
+
branches,
|
|
54
|
+
}
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
function unstarted(region) {
|
|
58
|
+
const started = new Set(region.branches.map((visit) => visit.branch));
|
|
59
|
+
return range(region.expected).filter((index) => !started.has(index));
|
|
60
|
+
}
|
|
61
|
+
/** The branches of a region just opened: the source reported items and none has started. */
|
|
62
|
+
export function branchesToStart(graph, visits) {
|
|
63
|
+
const region = fanRegions(graph, visits).at(-1);
|
|
64
|
+
return region && region.branches.length === 0 && !region.closed
|
|
65
|
+
? range(region.expected)
|
|
66
|
+
: [];
|
|
67
|
+
}
|
|
68
|
+
/** The history with every finished region's branch visits replaced by the one visit of the body the walk routes on. */
|
|
69
|
+
export function foldFans(graph, visits) {
|
|
70
|
+
const regions = fanRegions(graph, visits);
|
|
71
|
+
return visits.reduce((folded, visit) => [...folded, ...foldedAs(graph, regions, visit, folded)], []);
|
|
72
|
+
}
|
|
73
|
+
function foldedAs(graph, regions, visit, folded) {
|
|
74
|
+
const inside = regions.find((region) => region.branches.includes(visit));
|
|
75
|
+
if (inside) {
|
|
76
|
+
return visit === inside.branches[0] ? [joined(inside)] : [];
|
|
77
|
+
}
|
|
78
|
+
return [visit, ...emptyRegion(graph, regions, visit, folded)];
|
|
79
|
+
}
|
|
80
|
+
// A region that asked for no items has no branch to fold, but the walk still passes through the body once.
|
|
81
|
+
function emptyRegion(graph, regions, visit, folded) {
|
|
82
|
+
const region = regions.find((candidate) => candidate.source === visit);
|
|
83
|
+
const fan = fanOf(graph, visit.nodeId);
|
|
84
|
+
if (!region || region.expected > 0 || !fan) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const earlier = folded.filter((prior) => prior.nodeId === fan.body);
|
|
88
|
+
const highest = Math.max(0, ...earlier.map((prior) => prior.iteration));
|
|
89
|
+
return [{ nodeId: fan.body, iteration: highest + 1, outcome: "success" }];
|
|
90
|
+
}
|
|
91
|
+
function joined(region) {
|
|
92
|
+
const [first] = region.branches;
|
|
93
|
+
const succeeded = region.branches.every((visit) => visit.outcome === "success");
|
|
94
|
+
return {
|
|
95
|
+
nodeId: first.nodeId,
|
|
96
|
+
iteration: first.iteration,
|
|
97
|
+
outcome: succeeded ? "success" : "failed",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function range(count) {
|
|
101
|
+
return [...Array(count).keys()];
|
|
102
|
+
}
|
|
103
|
+
/** The step onto `state`'s node: one visit, or one per item when the node is the body of a fan-out the walk has just entered. */
|
|
104
|
+
export function launchOf(graph, visits, state) {
|
|
105
|
+
const branches = isFanBody(graph, state.currentId)
|
|
106
|
+
? branchesToStart(graph, visits)
|
|
107
|
+
: [];
|
|
108
|
+
return branches.length > 0
|
|
109
|
+
? {
|
|
110
|
+
kind: "launch-many",
|
|
111
|
+
nodeId: state.currentId,
|
|
112
|
+
iteration: state.iteration,
|
|
113
|
+
branches,
|
|
114
|
+
}
|
|
115
|
+
: { kind: "launch", nodeId: state.currentId, iteration: state.iteration };
|
|
116
|
+
}
|
|
117
|
+
function fanOf(graph, source) {
|
|
118
|
+
return (graph.fans ?? []).find((fan) => fan.source === source);
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=fanout.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { endsRun, getNextTransition, isTerminalNode, selectEdge, visitsSinceHandRun, type WalkEdge, type WalkGraph, type NodeVisit, type Transition, type StationKind, } from "./transition.js";
|
|
2
|
+
export { definitionHash } from "./definition-hash.js";
|
|
3
|
+
export { readAgentVerdict, requiredVerdict, type AgentVerdict } from "./agent-verdict.js";
|
|
4
|
+
export { Refusal, enforce } from "./refusal.js";
|
|
5
|
+
export { validateLine, type KnownDefinitions } from "./line-validation.js";
|
|
6
|
+
export { gitArgNames } from "./line-args.js";
|
|
7
|
+
export { nodeStartedBy, requireNode, startEventName } from "./start-events.js";
|
|
8
|
+
export { BROKER_PARAMETER_NAMES, GIT_CREDENTIAL_PARAMETER, GIT_CREDENTIAL_URL_PARAMETER, RUN_PARAMETER_NAMES, WORKSPACE, declaredParameters, needPathOf, promptParameters, runParameters, type DeclaredParameter, } from "./prompt-parameters.js";
|
|
9
|
+
export { downstreamOf } from "./line-graph.js";
|
|
10
|
+
export { EXEMPT_NEEDS, coverageContextOf, needCoverage, needMissesOf, type NeedContext, type NeedCoverage } from "./line-needs.js";
|
|
11
|
+
export { DISPATCH_EVENT, REPORTED_EVENT, RUN_SETTLED_EVENT } from "./event-names.js";
|
|
12
|
+
export { nodeEvents, type AnsweredBy, type CollectionLine, type NodeEvents, type OutcomeTarget, type Raised, type StartOrigin, type StartedBy } from "./node-events.js";
|
|
13
|
+
export { placeholderPattern } from "./placeholder-pattern.js";
|
|
14
|
+
export { placeholderNames, promptPlaceholders, type PlaceholderRow, type PlaceholderSource, type PlaceholderState, type PromptPlaceholderInput, type PromptPlaceholders } from "./prompt-placeholders.js";
|
|
15
|
+
export { FAN_STATIONS, fanLine } from "./fanout.fixtures.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { endsRun, getNextTransition, isTerminalNode, selectEdge, visitsSinceHandRun, } from "./transition.js";
|
|
2
|
+
export { definitionHash } from "./definition-hash.js";
|
|
3
|
+
export { readAgentVerdict, requiredVerdict } from "./agent-verdict.js";
|
|
4
|
+
export { Refusal, enforce } from "./refusal.js";
|
|
5
|
+
export { validateLine } from "./line-validation.js";
|
|
6
|
+
export { gitArgNames } from "./line-args.js";
|
|
7
|
+
export { nodeStartedBy, requireNode, startEventName } from "./start-events.js";
|
|
8
|
+
export { BROKER_PARAMETER_NAMES, GIT_CREDENTIAL_PARAMETER, GIT_CREDENTIAL_URL_PARAMETER, RUN_PARAMETER_NAMES, WORKSPACE, declaredParameters, needPathOf, promptParameters, runParameters, } from "./prompt-parameters.js";
|
|
9
|
+
export { downstreamOf } from "./line-graph.js";
|
|
10
|
+
export { EXEMPT_NEEDS, coverageContextOf, needCoverage, needMissesOf } from "./line-needs.js";
|
|
11
|
+
export { DISPATCH_EVENT, REPORTED_EVENT, RUN_SETTLED_EVENT } from "./event-names.js";
|
|
12
|
+
export { nodeEvents } from "./node-events.js";
|
|
13
|
+
export { placeholderPattern } from "./placeholder-pattern.js";
|
|
14
|
+
export { placeholderNames, promptPlaceholders } from "./prompt-placeholders.js";
|
|
15
|
+
export { FAN_STATIONS, fanLine } from "./fanout.fixtures.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Pure: what makes a fan-out region self-consistent — a source that lists items, a body that runs once per item and can fail, and joins that collect only what a body produces.
|
|
2
|
+
import { hasStation, resolvedStationOf } from "./line-stations.js";
|
|
3
|
+
export function fanoutChecks(line, bodies) {
|
|
4
|
+
const sources = line.nodes.filter(isSource);
|
|
5
|
+
return [
|
|
6
|
+
...sources.flatMap((source) => sourceChecks(line, source, bodies)),
|
|
7
|
+
...bodyChecks(line, sources),
|
|
8
|
+
...collectChecks(line, sources, bodies),
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
function isSource(node) {
|
|
12
|
+
return node.fanout !== undefined;
|
|
13
|
+
}
|
|
14
|
+
function sourceChecks(line, source, bodies) {
|
|
15
|
+
const { over, to } = source.fanout;
|
|
16
|
+
const problems = [];
|
|
17
|
+
if (!line.nodes.some((node) => node.id === to))
|
|
18
|
+
problems.push(`node "${source.id}" fans out to "${to}", which is not a node`);
|
|
19
|
+
if (!producesValue(source, over, bodies))
|
|
20
|
+
problems.push(`node "${source.id}" fans out over "${over}", which its station does not produce as a value`);
|
|
21
|
+
if (!line.edges.some((edge) => edge.from === source.id && edge.to === to && edge.on === "success")) {
|
|
22
|
+
problems.push(`node "${source.id}" fans out to "${to}" but has no success edge to it`);
|
|
23
|
+
}
|
|
24
|
+
return problems;
|
|
25
|
+
}
|
|
26
|
+
// Opaque stations (pinned, unknown, or a line checked without bodies) pass: the check cannot see inside them.
|
|
27
|
+
function producesValue(source, over, bodies) {
|
|
28
|
+
const body = hasStation(source)
|
|
29
|
+
? resolvedStationOf(source, bodies)
|
|
30
|
+
: undefined;
|
|
31
|
+
return (!bodies ||
|
|
32
|
+
!body ||
|
|
33
|
+
body.produces.some((produce) => produce.name === over && produce.kind === "value"));
|
|
34
|
+
}
|
|
35
|
+
function bodyChecks(line, sources) {
|
|
36
|
+
const targets = sources.map((source) => source.fanout.to);
|
|
37
|
+
const sourceIds = new Set(sources.map((source) => source.id));
|
|
38
|
+
const bodyIds = [...new Set(targets)];
|
|
39
|
+
return bodyIds.flatMap((id) => [
|
|
40
|
+
...(targets.filter((to) => to === id).length > 1
|
|
41
|
+
? [`node "${id}" is the body of more than one fan-out`]
|
|
42
|
+
: []),
|
|
43
|
+
...(sourceIds.has(id)
|
|
44
|
+
? [`node "${id}" is the body of a fan-out and cannot fan out itself`]
|
|
45
|
+
: []),
|
|
46
|
+
...failedEdgeChecks(line, id),
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
function failedEdgeChecks(line, id) {
|
|
50
|
+
const routed = line.edges.some((edge) => edge.from === id && (edge.on === "failed" || edge.on === "always"));
|
|
51
|
+
return routed
|
|
52
|
+
? []
|
|
53
|
+
: [`node "${id}" is the body of a fan-out and needs an edge for failed`];
|
|
54
|
+
}
|
|
55
|
+
function collectChecks(line, sources, bodies) {
|
|
56
|
+
const producers = producersByName(line, sources, bodies);
|
|
57
|
+
const stationNodes = line.nodes.filter(hasStation);
|
|
58
|
+
return stationNodes.flatMap((node) => {
|
|
59
|
+
const needs = resolvedStationOf(node, bodies)?.needs ?? [];
|
|
60
|
+
return needs.flatMap((need) => collectProblem(node.id, need.collect, producers));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function collectProblem(nodeId, collect, producers) {
|
|
64
|
+
if (collect === undefined)
|
|
65
|
+
return [];
|
|
66
|
+
const count = producers.get(collect) ?? 0;
|
|
67
|
+
if (count === 0) {
|
|
68
|
+
return [
|
|
69
|
+
`node "${nodeId}" collects "${collect}", which no fan-out body produces`,
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
return count > 1
|
|
73
|
+
? [
|
|
74
|
+
`node "${nodeId}" collects "${collect}", which more than one fan-out body produces`,
|
|
75
|
+
]
|
|
76
|
+
: [];
|
|
77
|
+
}
|
|
78
|
+
// How many fan-out bodies produce each name: a collected name must come from exactly one, or the branches of two fan-outs would mix.
|
|
79
|
+
function producersByName(line, sources, bodies) {
|
|
80
|
+
const bodyIds = new Set(sources.map((source) => source.fanout.to));
|
|
81
|
+
const stationNodes = line.nodes.filter(hasStation);
|
|
82
|
+
const names = stationNodes
|
|
83
|
+
.filter((node) => bodyIds.has(node.id))
|
|
84
|
+
.flatMap((node) => namesProducedBy(node, bodies));
|
|
85
|
+
return names.reduce((counts, name) => counts.set(name, (counts.get(name) ?? 0) + 1), new Map());
|
|
86
|
+
}
|
|
87
|
+
function namesProducedBy(node, bodies) {
|
|
88
|
+
const produces = resolvedStationOf(node, bodies)?.produces ?? [];
|
|
89
|
+
return produces.map((produce) => produce.name);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=line-fanout.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LineBody, LineEdge } from "@re-cinq/floor-contracts";
|
|
2
|
+
export declare function goingOutOf(edges: readonly LineEdge[]): Map<string, string[]>;
|
|
3
|
+
export declare function edgesByFrom(line: LineBody): Map<string, string[]>;
|
|
4
|
+
/** Every node reached by walking `goingOut` from `sources`. A blocked node is recorded as reached but never expanded past. */
|
|
5
|
+
export declare function reachableAvoiding(goingOut: ReadonlyMap<string, string[]>, sources: string[], blocked: ReadonlySet<string>): Set<string>;
|
|
6
|
+
/** Every node an edge path leads to from `start`; `start` itself only when a cycle returns to it. */
|
|
7
|
+
export declare function downstreamOf(start: string, edges: readonly LineEdge[]): Set<string>;
|
|
8
|
+
export declare function reachedFrom(line: LineBody): Set<string>;
|
|
9
|
+
/** One shortest walk of node ids from a source to `target` that goes through no blocked node on the way (the target and the source may themselves be blocked), or null when there is none. */
|
|
10
|
+
export declare function pathAvoiding(goingOut: ReadonlyMap<string, string[]>, sources: string[], blocked: ReadonlySet<string>, target: string): string[] | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function goingOutOf(edges) {
|
|
2
|
+
const goingOut = new Map();
|
|
3
|
+
for (const edge of edges)
|
|
4
|
+
goingOut.set(edge.from, [...(goingOut.get(edge.from) ?? []), edge.to]);
|
|
5
|
+
return goingOut;
|
|
6
|
+
}
|
|
7
|
+
export function edgesByFrom(line) {
|
|
8
|
+
return goingOutOf(line.edges);
|
|
9
|
+
}
|
|
10
|
+
/** Every node reached by walking `goingOut` from `sources`. A blocked node is recorded as reached but never expanded past. */
|
|
11
|
+
export function reachableAvoiding(goingOut, sources, blocked) {
|
|
12
|
+
const reached = new Set(sources);
|
|
13
|
+
const pending = sources.filter((source) => !blocked.has(source));
|
|
14
|
+
while (pending.length > 0) {
|
|
15
|
+
const arrivedAt = goingOut.get(pending.pop()) ?? [];
|
|
16
|
+
const fresh = arrivedAt.filter((to) => !reached.has(to));
|
|
17
|
+
fresh.forEach((to) => reached.add(to));
|
|
18
|
+
pending.push(...fresh.filter((to) => !blocked.has(to)));
|
|
19
|
+
}
|
|
20
|
+
return reached;
|
|
21
|
+
}
|
|
22
|
+
/** Every node an edge path leads to from `start`; `start` itself only when a cycle returns to it. */
|
|
23
|
+
export function downstreamOf(start, edges) {
|
|
24
|
+
const goingOut = goingOutOf(edges);
|
|
25
|
+
return reachableAvoiding(goingOut, goingOut.get(start) ?? [], new Set());
|
|
26
|
+
}
|
|
27
|
+
// From the entry, and from every node the line starts by a name of its own: a person or an outside system arrives there without an edge, and what it leads to is reached too.
|
|
28
|
+
export function reachedFrom(line) {
|
|
29
|
+
const goingOut = edgesByFrom(line);
|
|
30
|
+
const startedByName = line.nodes.filter((node) => node.start);
|
|
31
|
+
const entered = [line.entry, ...startedByName.map((node) => node.id)];
|
|
32
|
+
return reachableAvoiding(goingOut, entered, new Set());
|
|
33
|
+
}
|
|
34
|
+
/** One shortest walk of node ids from a source to `target` that goes through no blocked node on the way (the target and the source may themselves be blocked), or null when there is none. */
|
|
35
|
+
export function pathAvoiding(goingOut, sources, blocked, target) {
|
|
36
|
+
const cameFrom = new Map(sources.map((source) => [source, null]));
|
|
37
|
+
const pending = [...sources];
|
|
38
|
+
for (let index = 0; index < pending.length; index += 1) {
|
|
39
|
+
const current = pending[index];
|
|
40
|
+
const fresh = blocked.has(current) ? [] : (goingOut.get(current) ?? []).filter((to) => !cameFrom.has(to));
|
|
41
|
+
fresh.forEach((to) => cameFrom.set(to, current));
|
|
42
|
+
pending.push(...fresh);
|
|
43
|
+
}
|
|
44
|
+
return cameFrom.has(target) ? walkBack(cameFrom, target) : null;
|
|
45
|
+
}
|
|
46
|
+
function walkBack(cameFrom, target) {
|
|
47
|
+
const path = [target];
|
|
48
|
+
for (let before = cameFrom.get(target); before; before = cameFrom.get(before))
|
|
49
|
+
path.unshift(before);
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=line-graph.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LineBody, LineNode, NeedSpec, StationBody } from "@re-cinq/floor-contracts";
|
|
2
|
+
/** Filled by the floor around a retry (`previous_*`) or a fan-out branch (`item`), never by a line: no station ever declares these as a need to seed or produce. */
|
|
3
|
+
export declare const EXEMPT_NEEDS: readonly string[];
|
|
4
|
+
export interface NeedContext {
|
|
5
|
+
bodies: ReadonlyMap<string, StationBody>;
|
|
6
|
+
seeds: ReadonlySet<string>;
|
|
7
|
+
gitSeeds: ReadonlySet<string>;
|
|
8
|
+
producers: ReadonlyMap<string, string[]>;
|
|
9
|
+
goingOut: ReadonlyMap<string, string[]>;
|
|
10
|
+
startPoints: string[];
|
|
11
|
+
customStartIds: ReadonlySet<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function needChecks(line: LineBody, bodies: ReadonlyMap<string, StationBody> | undefined): string[];
|
|
14
|
+
export declare function coverageContextOf(line: LineBody, bodies: ReadonlyMap<string, StationBody>): NeedContext;
|
|
15
|
+
/** How a need at a node is covered. `filled` and `sometimes-empty` name the stations that produce it; `sometimes-empty` also gives one walk from a start point to the node that passes none of them. */
|
|
16
|
+
export type NeedCoverage = {
|
|
17
|
+
kind: "seeded";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "filled";
|
|
20
|
+
producedBy: string[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: "sometimes-empty";
|
|
23
|
+
producedBy: string[];
|
|
24
|
+
pathWithout: string[];
|
|
25
|
+
} | {
|
|
26
|
+
kind: "never-filled";
|
|
27
|
+
} | {
|
|
28
|
+
kind: "own-start";
|
|
29
|
+
} | {
|
|
30
|
+
kind: "git-unseeded";
|
|
31
|
+
} | {
|
|
32
|
+
kind: "optional";
|
|
33
|
+
} | {
|
|
34
|
+
kind: "floor-filled";
|
|
35
|
+
} | {
|
|
36
|
+
kind: "collected";
|
|
37
|
+
};
|
|
38
|
+
export declare function needCoverage(node: LineNode, need: NeedSpec, context: NeedContext): NeedCoverage;
|
|
39
|
+
/** The floor's own message for a need its coverage leaves open, none for one that is covered. */
|
|
40
|
+
export declare function needMissesOf(node: LineNode, need: NeedSpec, coverage: NeedCoverage): string[];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Pure: a forward must-analysis collapsed to reachability, since the bag's transfer function never drops a name once it holds one — an overwrite keeps it present. A name is missing at a node exactly when that node is reachable from an entry without passing through any producer of it, and it is not itself seeded.
|
|
2
|
+
import { gitArgNames } from "./line-args.js";
|
|
3
|
+
import { edgesByFrom, pathAvoiding, reachedFrom } from "./line-graph.js";
|
|
4
|
+
import { hasStation, resolvedStationOf } from "./line-stations.js";
|
|
5
|
+
/** Filled by the floor around a retry (`previous_*`) or a fan-out branch (`item`), never by a line: no station ever declares these as a need to seed or produce. */
|
|
6
|
+
export const EXEMPT_NEEDS = ["previous_error", "previous_failures", "item"];
|
|
7
|
+
export function needChecks(line, bodies) {
|
|
8
|
+
if (!bodies)
|
|
9
|
+
return [];
|
|
10
|
+
const context = coverageContextOf(line, bodies);
|
|
11
|
+
const reached = reachedFrom(line);
|
|
12
|
+
const stationNodes = line.nodes.filter(hasStation);
|
|
13
|
+
const reachableStationNodes = stationNodes.filter((node) => reached.has(node.id));
|
|
14
|
+
return reachableStationNodes.flatMap((node) => needMissesAt(node, context));
|
|
15
|
+
}
|
|
16
|
+
export function coverageContextOf(line, bodies) {
|
|
17
|
+
const customStartNodes = line.nodes.filter((node) => node.start);
|
|
18
|
+
const customStartIds = new Set(customStartNodes.map((node) => node.id));
|
|
19
|
+
return {
|
|
20
|
+
bodies,
|
|
21
|
+
seeds: seedNamesOf(line),
|
|
22
|
+
gitSeeds: new Set(gitArgNames(line.args)),
|
|
23
|
+
producers: producersOf(line, bodies),
|
|
24
|
+
goingOut: edgesByFrom(line),
|
|
25
|
+
startPoints: [line.entry, ...customStartIds],
|
|
26
|
+
customStartIds,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function seedNamesOf(line) {
|
|
30
|
+
return new Set([...Object.keys(line.args), ...Object.keys(line.files ?? {})]);
|
|
31
|
+
}
|
|
32
|
+
// Every outgoing edge counts as carrying a produce, regardless of the outcome it fires on — this is about what a station's body declares, not any one path through it.
|
|
33
|
+
function producersOf(line, bodies) {
|
|
34
|
+
const byName = new Map();
|
|
35
|
+
for (const node of line.nodes.filter(hasStation)) {
|
|
36
|
+
const body = resolvedStationOf(node, bodies);
|
|
37
|
+
(body?.produces ?? []).forEach((produce) => byName.set(produce.name, [...(byName.get(produce.name) ?? []), node.id]));
|
|
38
|
+
}
|
|
39
|
+
return byName;
|
|
40
|
+
}
|
|
41
|
+
function needMissesAt(node, context) {
|
|
42
|
+
const body = resolvedStationOf(node, context.bodies);
|
|
43
|
+
return (body?.needs ?? []).flatMap((need) => needMissesOf(node, need, needCoverage(node, need, context)));
|
|
44
|
+
}
|
|
45
|
+
export function needCoverage(node, need, context) {
|
|
46
|
+
const bagName = bagNameOf(node, need);
|
|
47
|
+
const coverage = floorCoverage(need, bagName) ?? seedCoverage(node, need, bagName, context);
|
|
48
|
+
return coverage ?? producedCoverage(node.id, context.producers.get(bagName) ?? [], context);
|
|
49
|
+
}
|
|
50
|
+
function floorCoverage(need, bagName) {
|
|
51
|
+
if (need.optional)
|
|
52
|
+
return { kind: "optional" };
|
|
53
|
+
if (isExempt(bagName))
|
|
54
|
+
return { kind: "floor-filled" };
|
|
55
|
+
// A collected need is filled from the branches of a fan-out; the fan-out checks say whether anything produces what it collects.
|
|
56
|
+
return need.collect === undefined ? null : { kind: "collected" };
|
|
57
|
+
}
|
|
58
|
+
// Git first, since nothing ever produces one and the seed check below would otherwise call it "not produced on every path" — a claim that makes no sense for a kind no station can hand on.
|
|
59
|
+
function seedCoverage(node, need, bagName, context) {
|
|
60
|
+
if (need.kind === "git")
|
|
61
|
+
return context.gitSeeds.has(bagName) ? { kind: "seeded" } : { kind: "git-unseeded" };
|
|
62
|
+
if (context.seeds.has(bagName))
|
|
63
|
+
return { kind: "seeded" };
|
|
64
|
+
// A custom-start node is its own entry: nothing upstream is guaranteed to have run before it fires, so only a seed — never a produce — can cover its need.
|
|
65
|
+
return context.customStartIds.has(node.id) ? { kind: "own-start" } : null;
|
|
66
|
+
}
|
|
67
|
+
function producedCoverage(nodeId, producedBy, context) {
|
|
68
|
+
if (producedBy.length === 0)
|
|
69
|
+
return { kind: "never-filled" };
|
|
70
|
+
const pathWithout = pathAvoiding(context.goingOut, context.startPoints, new Set(producedBy), nodeId);
|
|
71
|
+
return pathWithout ? { kind: "sometimes-empty", producedBy, pathWithout } : { kind: "filled", producedBy };
|
|
72
|
+
}
|
|
73
|
+
/** The floor's own message for a need its coverage leaves open, none for one that is covered. */
|
|
74
|
+
export function needMissesOf(node, need, coverage) {
|
|
75
|
+
const bagName = bagNameOf(node, need);
|
|
76
|
+
if (coverage.kind === "git-unseeded")
|
|
77
|
+
return [gitMiss(node, need, bagName)];
|
|
78
|
+
if (coverage.kind === "own-start")
|
|
79
|
+
return [customStartMiss(node, need, bagName)];
|
|
80
|
+
return coverage.kind === "sometimes-empty" || coverage.kind === "never-filled" ? [uncoveredMiss(node, need, bagName)] : [];
|
|
81
|
+
}
|
|
82
|
+
function bagNameOf(node, need) {
|
|
83
|
+
return node.bind?.[need.name] ?? need.name;
|
|
84
|
+
}
|
|
85
|
+
function isExempt(bagName) {
|
|
86
|
+
return EXEMPT_NEEDS.includes(bagName);
|
|
87
|
+
}
|
|
88
|
+
function uncoveredMiss(node, need, bagName) {
|
|
89
|
+
return `node "${node.id}" needs ${needLabel(need, bagName)}, which is not seeded at start and not produced on every path into it`;
|
|
90
|
+
}
|
|
91
|
+
function customStartMiss(node, need, bagName) {
|
|
92
|
+
return `node "${node.id}" starts by its own event, so its need ${needLabel(need, bagName)} must be seeded at start`;
|
|
93
|
+
}
|
|
94
|
+
function gitMiss(node, need, bagName) {
|
|
95
|
+
return `node "${node.id}" needs ${needLabel(need, bagName)} as kind "git", which nothing in the line seeds`;
|
|
96
|
+
}
|
|
97
|
+
function needLabel(need, bagName) {
|
|
98
|
+
return need.name === bagName ? `"${need.name}"` : `"${need.name}" (bound as "${bagName}")`;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=line-needs.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LineNode, StationBody } from "@re-cinq/floor-contracts";
|
|
2
|
+
export declare function hasStation(node: LineNode): node is LineNode & {
|
|
3
|
+
station: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function bareStationOf(node: LineNode & {
|
|
6
|
+
station: string;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function isPinned(node: LineNode & {
|
|
9
|
+
station: string;
|
|
10
|
+
}): boolean;
|
|
11
|
+
/** The station body a bodies map resolves this node to, or undefined when the reference is pinned or the map holds nothing for it. */
|
|
12
|
+
export declare function resolvedStationOf(node: LineNode & {
|
|
13
|
+
station: string;
|
|
14
|
+
}, bodies: ReadonlyMap<string, StationBody> | undefined): StationBody | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function hasStation(node) {
|
|
2
|
+
return Boolean(node.station);
|
|
3
|
+
}
|
|
4
|
+
export function bareStationOf(node) {
|
|
5
|
+
const [name] = node.station.split("@");
|
|
6
|
+
return name;
|
|
7
|
+
}
|
|
8
|
+
export function isPinned(node) {
|
|
9
|
+
return node.station.includes("@");
|
|
10
|
+
}
|
|
11
|
+
/** The station body a bodies map resolves this node to, or undefined when the reference is pinned or the map holds nothing for it. */
|
|
12
|
+
export function resolvedStationOf(node, bodies) {
|
|
13
|
+
return isPinned(node) ? undefined : bodies?.get(bareStationOf(node));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=line-stations.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LineBody, StationBody } from "@re-cinq/floor-contracts";
|
|
2
|
+
export interface KnownDefinitions {
|
|
3
|
+
stations: Set<string>;
|
|
4
|
+
bodies?: ReadonlyMap<string, StationBody>;
|
|
5
|
+
}
|
|
6
|
+
export declare function validateLine(line: LineBody, known: KnownDefinitions): string[];
|