@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/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 re:cinq B.V.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @re-cinq/floor-assembly-lines
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The rules of a floor's assembly line, as pure functions with no I/O and no database. It holds four things: the walk kernel, which says which edge a run takes next and when it ends; the checks a line must pass before a floor stores it; the parameters a prompt is given; and the answers a tool that draws a line needs, which events start and leave each node and what each `{placeholder}` of a prompt is filled with. The floor's store, its cluster agent and the tools that read a line before it reaches a floor all use these, so they cannot disagree.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @re-cinq/floor-assembly-lines
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { getNextTransition, validateLine } from "@re-cinq/floor-assembly-lines";
|
|
11
|
+
|
|
12
|
+
const line = {
|
|
13
|
+
entry: "write",
|
|
14
|
+
exit: "done",
|
|
15
|
+
args: {},
|
|
16
|
+
nodes: [{ id: "write", station: "writer" }, { id: "done" }],
|
|
17
|
+
edges: [{ from: "write", to: "done", on: "success" }],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Every problem a line has, or an empty list.
|
|
21
|
+
validateLine(line, { stations: new Set(["writer"]) });
|
|
22
|
+
|
|
23
|
+
// What the walk does next, from the visits so far.
|
|
24
|
+
getNextTransition(
|
|
25
|
+
{ name: "demo", entry: "write", exit: "done", edges: line.edges },
|
|
26
|
+
[{ nodeId: "write", iteration: 1, outcome: "success" }],
|
|
27
|
+
); // { kind: "finish" }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What it exports
|
|
31
|
+
|
|
32
|
+
| export | what it does |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `getNextTransition`, `selectEdge`, `endsRun`, `isTerminalNode`, `visitsSinceHandRun` | the walk kernel: replay the visits of a run and say what happens next |
|
|
35
|
+
| `definitionHash` | the content hash of a versioned definition |
|
|
36
|
+
| `readAgentVerdict` | reads an agent's verdict from what it reported |
|
|
37
|
+
| `validateLine`, `KnownDefinitions` | every problem a line body has: names, edges, reachability, arguments, outcomes, cycles, needs, fan-outs |
|
|
38
|
+
| `gitArgNames`, `nodeStartedBy`, `requireNode`, `startEventName` | small readers of a line: its git arguments, and the event that starts a node |
|
|
39
|
+
| `promptParameters`, `runParameters`, `WORKSPACE` | the values a prompt's `{placeholders}` are filled with |
|
|
40
|
+
| `declaredParameters`, `needPathOf`, `RUN_PARAMETER_NAMES`, `BROKER_PARAMETER_NAMES` | the names those values have, worked out from a station's declaration instead of a brief |
|
|
41
|
+
| `nodeEvents`, `CollectionLine`, `DISPATCH_EVENT`, `REPORTED_EVENT`, `RUN_SETTLED_EVENT` | the events that start a node, answer it and leave it |
|
|
42
|
+
| `needCoverage`, `coverageContextOf`, `needMissesOf`, `EXEMPT_NEEDS` | how one need at one node is covered: seeded, filled on every path, sometimes empty (with one path), never filled, and the rest |
|
|
43
|
+
| `placeholderPattern` | the `{name}` rule as a fresh `RegExp`; also at the browser-safe subpath `@re-cinq/floor-assembly-lines/placeholder-pattern`, which loads no Node module |
|
|
44
|
+
| `promptPlaceholders`, `placeholderNames` | each `{name}` a prompt reads, what supplies it, whether it is filled on every path into the node, and the needs it never mentions |
|
|
45
|
+
| `Refusal`, `enforce` | the error a request that can never be accepted throws, and the check that throws it |
|
|
46
|
+
| `FAN_STATIONS`, `fanLine` | the stations and the line of a small fan-out, for tests |
|
|
47
|
+
|
|
48
|
+
### Events of a node
|
|
49
|
+
|
|
50
|
+
`nodeEvents(line, node, lines, bodies)` says what starts a node, what answers it and what it raises. `lines` is every line of the collection, so a node that ends a run can name the lines that start on `internal.run.settled`.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const line = {
|
|
54
|
+
entry: "write", exit: "done", args: {},
|
|
55
|
+
nodes: [{ id: "write", station: "writer" }, { id: "done" }],
|
|
56
|
+
edges: [{ from: "write", to: "done", on: "success" }],
|
|
57
|
+
};
|
|
58
|
+
const bodies = new Map([["writer", { kind: "agent", outcomes: ["success", "failed"], needs: [], produces: [] }]]);
|
|
59
|
+
|
|
60
|
+
nodeEvents(line, line.nodes[0], [], bodies);
|
|
61
|
+
// {
|
|
62
|
+
// startedBy: [{ event: "node.write.start", origin: "line-start" }],
|
|
63
|
+
// answeredBy: [],
|
|
64
|
+
// raises: [
|
|
65
|
+
// { kind: "event", event: "station_run.dispatch" },
|
|
66
|
+
// { kind: "event", event: "station_run.reported" },
|
|
67
|
+
// { kind: "outcome", outcome: "success", leadsTo: { on: "success", node: "done", event: "node.done.start" } },
|
|
68
|
+
// { kind: "outcome", outcome: "failed", leadsTo: null },
|
|
69
|
+
// ],
|
|
70
|
+
// }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`origin` is `walk` when an edge leads to the node, `outside` when the node names its own `start`, `line-start` when the line's own start raises it, and `none` when nothing does. `leadsTo` is the edge `selectEdge` takes, so an exact outcome wins over `always`, and `null` when no edge takes that outcome.
|
|
74
|
+
|
|
75
|
+
### Placeholders of a prompt
|
|
76
|
+
|
|
77
|
+
`promptPlaceholders({ prompt, line, node, station, bodies })` gives one row per distinct `{name}` and the needs the prompt never mentions.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
promptPlaceholders({ prompt: "Fix {ticket} in {repo_path}. {typo}", line, node, station, bodies });
|
|
81
|
+
// {
|
|
82
|
+
// placeholders: [
|
|
83
|
+
// { name: "ticket", source: "value-need", state: "sometimes-empty", filledBy: ["open"], path: ["start", "skip", "join"] },
|
|
84
|
+
// { name: "repo_path", source: "need-path", state: "seeded", filledBy: [], path: [] },
|
|
85
|
+
// { name: "typo", source: "none", state: "unsupplied", filledBy: [], path: [] },
|
|
86
|
+
// ],
|
|
87
|
+
// unused: [],
|
|
88
|
+
// }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`source` is `value-need`, `need-path` (a file or git need, read as `{name_path}`), `produce-path`, `floor` or `none`. `state` is `unsupplied` when nothing supplies the name, otherwise how the need is covered. `path` is one walk from a start point to the node that passes no producer, for `sometimes-empty`. A name is letters, digits, `_`, `.` and `-` and starts with a letter or `_`, the agent subsystem's own rule with the first character narrowed, so `a{3}` and a JSON object are not placeholders.
|
|
92
|
+
|
|
93
|
+
The shapes of a line, a station and a brief come from [`@re-cinq/floor-contracts`](https://github.com/re-cinq/floor/tree/main/packages/contracts).
|
|
94
|
+
|
|
95
|
+
## Where this fits
|
|
96
|
+
|
|
97
|
+
The bottom of the stack, and the only part with no I/O at all: given a line and the visits a run
|
|
98
|
+
has so far, it says which edge is taken next. [`packages/store`](../store/README.md) asks it once, inside the transaction that writes a report, and validates a line with it before storing one; the cluster agent asks it for a prompt's parameters. It depends on nothing of ours but the shapes in `@re-cinq/floor-contracts`,
|
|
99
|
+
which is why its tests are plain values and no database.
|
|
100
|
+
|
|
101
|
+
A walk ends in one of two places: at the line's `exit`, which is `finish`, or at its `fail`
|
|
102
|
+
node when it names one, which is `halt` with outcome `failed` and a reason naming the node whose
|
|
103
|
+
edge led there. Neither terminal is ever launched. `isTerminalNode` is that rule for anyone else who
|
|
104
|
+
needs it; line validation asks it which nodes owe no outgoing edge.
|
|
105
|
+
|
|
106
|
+
A transition is one of four: `launch` a node, `await` an open visit, `finish` at the exit, or `halt`,
|
|
107
|
+
which is every other way a walk ends: a spent budget (`iteration_max`), an `error`, or the line's own
|
|
108
|
+
fail node (`failed`). `halt` was called `fail` until a line could name a fail node; the word now means
|
|
109
|
+
only the node. `endsRun` says whether a transition is one of the last two.
|
|
110
|
+
|
|
111
|
+
See [the map](../../README.md) for how a decision here becomes work somewhere else.
|
|
112
|
+
|
|
113
|
+
## Ported from lore
|
|
114
|
+
|
|
115
|
+
Source: `libs/assembly-lines/src/{transition,definition-hash}.ts` in the
|
|
116
|
+
lore monorepo, Apache 2.0, same organisation. `transition.ts` ports with two
|
|
117
|
+
adaptations, documented in its file header:
|
|
118
|
+
|
|
119
|
+
- a node's outcomes are whatever its station declares, not a fixed
|
|
120
|
+
three-value union — `NodeVisit.outcome` widens from `StageOutcome` to `string`
|
|
121
|
+
- there is no failure classification, so every failure spends its edge's
|
|
122
|
+
iteration budget; lore's out-of-credit gate becomes a queue-side
|
|
123
|
+
`not_before` push instead (see the storage doc, "Provider out of credit")
|
|
124
|
+
|
|
125
|
+
`definitionHash` ports with one change: it takes a plain body instead of a
|
|
126
|
+
typed `AssemblyLine`, since this floor content-hashes three kinds of
|
|
127
|
+
definition (line, station, agent definition), not one.
|
|
128
|
+
|
|
129
|
+
## Not ported
|
|
130
|
+
|
|
131
|
+
The line loader and schema (`loader.ts`, `assembly-line-schema.ts`,
|
|
132
|
+
`assembly-line-validate.ts`) are not in this package. They belong to the
|
|
133
|
+
line-authoring layer described in
|
|
134
|
+
[docs/entities/assembly-line.md](../../docs/entities/assembly-line.md) —
|
|
135
|
+
start events, `bind`, the `subject` argument mark — which has no
|
|
136
|
+
counterpart in lore's schema. That doc's "Validation at creation" is built
|
|
137
|
+
in full except for the `git`-write review-gate check (a node whose station
|
|
138
|
+
needs `git` `access: write` must have a review or human node on every path
|
|
139
|
+
in, unless it is the first writer), which waits on a separate decision.
|
|
140
|
+
|
|
141
|
+
## Tests
|
|
142
|
+
|
|
143
|
+
The walk kernel's cases are in `transition*.test.ts` and `definition-hash.test.ts`, ported
|
|
144
|
+
and trimmed from lore's test files; each file's header says what was
|
|
145
|
+
dropped and why (mainly the failure-classification cases, which have no
|
|
146
|
+
counterpart here, and the builtin-line walk, which needs the loader). The line checks and the prompt
|
|
147
|
+
parameters keep their tests beside them in `line-*.test.ts` and `prompt-parameters.test.ts`; the events, the need coverage and the placeholders in `node-events.test.ts`, `need-coverage.test.ts` and `prompt-placeholders.test.ts`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** What the agent said its outcome with: a `LORE_NODE_RESULT:` line, a `REVIEW_RESULT:` verdict and no marker, or neither, so the outcome was read into its silence. */
|
|
2
|
+
export type Spoke = "marker" | "review" | "nothing";
|
|
3
|
+
export interface AgentVerdict {
|
|
4
|
+
outcome: string;
|
|
5
|
+
spoke: Spoke;
|
|
6
|
+
/** What the agent said it produced, by name; the caller keeps only what the station declares. */
|
|
7
|
+
produced: Record<string, string>;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const UNSPOKEN_RESULT = "the agent ended without a LORE_NODE_RESULT or REVIEW_RESULT line, and its station requires one";
|
|
11
|
+
export declare function readAgentVerdict(output: string | undefined, outcomes: readonly string[]): AgentVerdict;
|
|
12
|
+
export declare function requiredVerdict(verdict: AgentVerdict, station: {
|
|
13
|
+
resultRequired?: boolean;
|
|
14
|
+
}): AgentVerdict;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The agent station's contract with its own output, ported from lore's node-outcome.ts: `LORE_NODE_RESULT:` first, then `REVIEW_RESULT:`, then success; a marker present but unusable fails. Outcomes are the station's own, not a closed set.
|
|
2
|
+
// Agents copy the marker out of a prompt that shows it as inline code, backticks included.
|
|
3
|
+
const MARKER = /^`*LORE_NODE_RESULT:[ \t]*(.*?)`*[ \t]*$/gm;
|
|
4
|
+
const REVIEW_VERDICT = /REVIEW_RESULT:\s*(APPROVED|CHANGES_REQUESTED)/i;
|
|
5
|
+
const MAX_ERROR_CHARS = 300;
|
|
6
|
+
export const UNSPOKEN_RESULT = "the agent ended without a LORE_NODE_RESULT or REVIEW_RESULT line, and its station requires one";
|
|
7
|
+
export function readAgentVerdict(output, outcomes) {
|
|
8
|
+
const payload = lastMarkerPayload(output ?? "");
|
|
9
|
+
if (payload === null)
|
|
10
|
+
return reviewVerdict(output ?? "");
|
|
11
|
+
return verdictFromPayload(payload, [...outcomes, "failed"]) ?? malformed(payload);
|
|
12
|
+
}
|
|
13
|
+
export function requiredVerdict(verdict, station) {
|
|
14
|
+
if (!station.resultRequired || verdict.spoke !== "nothing")
|
|
15
|
+
return verdict;
|
|
16
|
+
return { ...verdict, outcome: "failed", error: UNSPOKEN_RESULT };
|
|
17
|
+
}
|
|
18
|
+
// Line-start and last-wins together make the marker safe to discuss: quoting it mid-sentence decides nothing, and printing it after explaining it is read by its final word.
|
|
19
|
+
function lastMarkerPayload(output) {
|
|
20
|
+
const last = [...output.matchAll(MARKER)].at(-1);
|
|
21
|
+
return last ? last[1].trim() : null;
|
|
22
|
+
}
|
|
23
|
+
function reviewVerdict(output) {
|
|
24
|
+
const outcome = /REVIEW_RESULT:\s*CHANGES_REQUESTED/i.test(output) ? "changes_requested" : "success";
|
|
25
|
+
return { outcome, produced: {}, spoke: REVIEW_VERDICT.test(output) ? "review" : "nothing" };
|
|
26
|
+
}
|
|
27
|
+
function verdictFromPayload(payload, allowed) {
|
|
28
|
+
if (allowed.includes(payload))
|
|
29
|
+
return { outcome: payload, produced: {}, spoke: "marker" };
|
|
30
|
+
const parsed = parseObject(payload);
|
|
31
|
+
if (typeof parsed?.outcome !== "string" || !allowed.includes(parsed.outcome))
|
|
32
|
+
return null;
|
|
33
|
+
return { outcome: parsed.outcome, produced: stringsOf(parsed.produced ?? parsed.extras), spoke: "marker" };
|
|
34
|
+
}
|
|
35
|
+
function parseObject(payload) {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(payload);
|
|
38
|
+
return typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function stringsOf(candidate) {
|
|
45
|
+
if (typeof candidate !== "object" || candidate === null)
|
|
46
|
+
return {};
|
|
47
|
+
const strings = Object.entries(candidate).filter((entry) => typeof entry[1] === "string");
|
|
48
|
+
return Object.fromEntries(strings);
|
|
49
|
+
}
|
|
50
|
+
// Spoken but misheard: falling through to success would turn an agent's objection into a pass.
|
|
51
|
+
function malformed(payload) {
|
|
52
|
+
const error = `unparseable LORE_NODE_RESULT line: LORE_NODE_RESULT: ${payload}`.slice(0, MAX_ERROR_CHARS);
|
|
53
|
+
return { outcome: "failed", produced: {}, error, spoke: "marker" };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=agent-verdict.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function definitionHash(body: unknown): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Content hash of a versioned definition (line, station, or agent definition); ported from lore's definition-hash.ts. See README.md.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
// Prose, at any depth — reworded documentation is not a definition change.
|
|
4
|
+
const IGNORED_KEYS = new Set(["description"]);
|
|
5
|
+
export function definitionHash(body) {
|
|
6
|
+
return createHash("sha256").update(canonicalJson(body)).digest("hex");
|
|
7
|
+
}
|
|
8
|
+
function canonicalJson(value) {
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
11
|
+
}
|
|
12
|
+
if (value === null || typeof value !== "object") {
|
|
13
|
+
return JSON.stringify(value ?? null);
|
|
14
|
+
}
|
|
15
|
+
const fields = Object.entries(value)
|
|
16
|
+
.filter(([key, fieldValue]) => fieldValue !== undefined && !IGNORED_KEYS.has(key))
|
|
17
|
+
.sort(([left], [right]) => (left < right ? -1 : 1))
|
|
18
|
+
.map(([key, fieldValue]) => `${JSON.stringify(key)}:${canonicalJson(fieldValue)}`);
|
|
19
|
+
return `{${fields.join(",")}}`;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=definition-hash.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LineBody, NeedSpec, ProduceSpec, StationBody } from "@re-cinq/floor-contracts";
|
|
2
|
+
export declare function agentStation(needs: NeedSpec[], produces?: ProduceSpec[]): StationBody;
|
|
3
|
+
/** The stations of the diamond line: opener produces ticket, skipper and start produce nothing, reader reads ticket. */
|
|
4
|
+
export declare const DIAMOND_STATIONS: ReadonlyMap<string, StationBody>;
|
|
5
|
+
/** start goes to opener on success and to skipper on failed; both lead to join, which reads. Only the opener branch produces ticket. */
|
|
6
|
+
export declare function diamondLine(patch?: Partial<LineBody>): LineBody;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function agentStation(needs, produces = []) {
|
|
2
|
+
return { kind: "agent", outcomes: ["success", "failed"], needs, produces };
|
|
3
|
+
}
|
|
4
|
+
/** The stations of the diamond line: opener produces ticket, skipper and start produce nothing, reader reads ticket. */
|
|
5
|
+
export const DIAMOND_STATIONS = new Map([
|
|
6
|
+
["opener", agentStation([], [{ name: "ticket", kind: "value" }])],
|
|
7
|
+
["skipper", agentStation([])],
|
|
8
|
+
["reader", agentStation([{ name: "ticket", kind: "value" }])],
|
|
9
|
+
]);
|
|
10
|
+
/** start goes to opener on success and to skipper on failed; both lead to join, which reads. Only the opener branch produces ticket. */
|
|
11
|
+
export function diamondLine(patch = {}) {
|
|
12
|
+
return {
|
|
13
|
+
entry: "start",
|
|
14
|
+
exit: "done",
|
|
15
|
+
args: {},
|
|
16
|
+
nodes: [
|
|
17
|
+
{ id: "start", station: "skipper" },
|
|
18
|
+
{ id: "opener", station: "opener" },
|
|
19
|
+
{ id: "skipper", station: "skipper" },
|
|
20
|
+
{ id: "join", station: "reader" },
|
|
21
|
+
{ id: "done" },
|
|
22
|
+
],
|
|
23
|
+
edges: [
|
|
24
|
+
{ from: "start", to: "opener", on: "success" },
|
|
25
|
+
{ from: "start", to: "skipper", on: "failed" },
|
|
26
|
+
{ from: "opener", to: "join", on: "success" },
|
|
27
|
+
{ from: "skipper", to: "join", on: "success" },
|
|
28
|
+
{ from: "join", to: "done", on: "success" },
|
|
29
|
+
],
|
|
30
|
+
...patch,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=diamond.fixtures.js.map
|
package/dist/fanout.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NodeVisit, Transition, WalkGraph } from "./transition.js";
|
|
2
|
+
type Fans = Pick<WalkGraph, "fans">;
|
|
3
|
+
/** One run of the body: the source visit that listed the items and the branch visits that followed it. */
|
|
4
|
+
export interface FanRegion {
|
|
5
|
+
source: NodeVisit;
|
|
6
|
+
/** How many branches the source asked for. */
|
|
7
|
+
expected: number;
|
|
8
|
+
branches: NodeVisit[];
|
|
9
|
+
/** A visit that is not one of its branches came after it, so the walk has moved on. */
|
|
10
|
+
closed: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function isFanBody(graph: Fans, nodeId: string): boolean;
|
|
13
|
+
/** The regions in the history, oldest first. */
|
|
14
|
+
export declare function fanRegions(graph: Fans, visits: readonly NodeVisit[]): FanRegion[];
|
|
15
|
+
/** Starts the branches the newest region has not started yet, when it has started some: a crash between launches leaves this. */
|
|
16
|
+
export declare function relaunchMissing(graph: Fans, visits: readonly NodeVisit[]): Transition | null;
|
|
17
|
+
/** The branches of a region just opened: the source reported items and none has started. */
|
|
18
|
+
export declare function branchesToStart(graph: Fans, visits: readonly NodeVisit[]): number[];
|
|
19
|
+
/** The history with every finished region's branch visits replaced by the one visit of the body the walk routes on. */
|
|
20
|
+
export declare function foldFans(graph: Fans, visits: readonly NodeVisit[]): NodeVisit[];
|
|
21
|
+
/** 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. */
|
|
22
|
+
export declare function launchOf(graph: Fans, visits: readonly NodeVisit[], state: {
|
|
23
|
+
currentId: string;
|
|
24
|
+
iteration: number;
|
|
25
|
+
}): Transition;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LineBody, StationBody } from "@re-cinq/floor-contracts";
|
|
2
|
+
export declare const FAN_STATIONS: Record<string, StationBody>;
|
|
3
|
+
/** The line those stations make: split fans out to work, merge joins, and a failed branch ends the run as failed. */
|
|
4
|
+
export declare const fanLine: (patch?: Partial<LineBody>) => LineBody;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const FAN_STATIONS = {
|
|
2
|
+
splitter: { kind: "service", outcomes: ["success"], needs: [], produces: [{ name: "items", kind: "value" }] },
|
|
3
|
+
worker: {
|
|
4
|
+
kind: "service",
|
|
5
|
+
outcomes: ["success", "failed"],
|
|
6
|
+
needs: [{ name: "item", kind: "value" }],
|
|
7
|
+
produces: [{ name: "result", kind: "value" }],
|
|
8
|
+
},
|
|
9
|
+
merger: { kind: "service", outcomes: ["success"], needs: [{ name: "results", kind: "value", collect: "result" }], produces: [] },
|
|
10
|
+
};
|
|
11
|
+
/** The line those stations make: split fans out to work, merge joins, and a failed branch ends the run as failed. */
|
|
12
|
+
export const fanLine = (patch = {}) => ({
|
|
13
|
+
entry: "split",
|
|
14
|
+
exit: "done",
|
|
15
|
+
fail: "failed",
|
|
16
|
+
args: {},
|
|
17
|
+
nodes: [
|
|
18
|
+
{ id: "split", station: "splitter", fanout: { over: "items", to: "work" } },
|
|
19
|
+
{ id: "work", station: "worker" },
|
|
20
|
+
{ id: "merge", station: "merger" },
|
|
21
|
+
{ id: "done" },
|
|
22
|
+
{ id: "failed" },
|
|
23
|
+
],
|
|
24
|
+
edges: [
|
|
25
|
+
{ from: "split", to: "work", on: "success" },
|
|
26
|
+
{ from: "work", to: "merge", on: "success" },
|
|
27
|
+
{ from: "work", to: "failed", on: "failed" },
|
|
28
|
+
{ from: "merge", to: "done", on: "success" },
|
|
29
|
+
],
|
|
30
|
+
...patch,
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=fanout.fixtures.js.map
|