fwdloop 0.2.1 → 0.4.0

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.
@@ -0,0 +1,419 @@
1
+ // derived-from: poc/m0/validator.mjs@288cb8a parseLines/parseArbiterGuardrails
2
+ // — rewritten, never imported. src must not import from poc (CLAUDE.md:
3
+ // "borrow, never import" — complete separation between poc/ and src/).
4
+ //
5
+ // M1 piece 1 (docs/wiki/the-module-ladder.md, "M1 — scope, exit, negative —
6
+ // SIGNED"): the human's signed text is numbered job lines, an optional
7
+ // `guardrail:` directly under a line (strict 1-for-1), then an
8
+ // "Arbiter guardrails" heading followed by `guardrail: <field>` lines in a
9
+ // fixed, typed grammar. This module turns that text into
10
+ // `{ lines, arbiter }` or a list of reds — it does not run anything, author
11
+ // a step, or touch declaration.json (that is the drafter's, later piece).
12
+ //
13
+ // ReDoS / "patterns are literal or typed, never user regex" (M1 signed scope
14
+ // item 6): every regex below is a fixed literal, anchored, with no nested
15
+ // quantifiers (no `(x+)+` shape), compiled once at module load. Signed text
16
+ // is only ever matched against these fixed patterns — never used to build a
17
+ // pattern. This file never constructs a RegExp dynamically at runtime.
18
+
19
+ /** @typedef {import('./types.js').SignedTextResult} SignedTextResult */
20
+
21
+ /** The arbiter fields this grammar defines — kept in sync with the parser
22
+ * below so a mutation suite can assert it tested every one of them. */
23
+ export const ARBITER_FIELDS = Object.freeze([
24
+ 'capUsd',
25
+ 'asks',
26
+ 'redoCap',
27
+ 'sends',
28
+ 'skills',
29
+ 'sources',
30
+ 'roundBudgetMs',
31
+ ]);
32
+
33
+ const HEADING_RE = /^arbiter guardrails\b/i;
34
+ const NUMBERED_RE = /^(\d+)\.\s?(.*)$/;
35
+ const GUARDRAIL_RE = /^guardrail:\s?(.*)$/i;
36
+
37
+ const CAP_RE = /^cap \$([^\s]+) per run$/i;
38
+ // M1 amendment 3 (docs/wiki/the-module-ladder.md, "M1 amendment 3 — the ask
39
+ // is a mark on its own line — SIGNED by hamr 2026-09-21"): the ask is no
40
+ // longer a bottom-block arbiter line — it is a mark at the START of a
41
+ // numbered job line's own text: `ask:` (default 30m wait) or
42
+ // `ask <int><s|m|h>:` (explicit wait), the words after the mark being the
43
+ // human's own question. OLD_ASK_ARBITER_RE below only detects the RETIRED
44
+ // bottom-block form (`guardrail: ask at line N`) so it can be refused by
45
+ // name, one red, never silently accepted.
46
+ const ASK_MARK_ATTEMPT_RE = /^ask[: ]/i;
47
+ const ASK_MARK_DEFAULT_RE = /^ask:(.*)$/i;
48
+ const ASK_MARK_TIMED_RE = /^ask (\d+)(s|m|h):(.*)$/i;
49
+ const OLD_ASK_ARBITER_RE = /^ask at\b/i;
50
+ const REDO_RE = /^redo cap (\S+)$/i;
51
+ const SEND_PREFIX_RE = /^send at\b/i;
52
+ const SEND_RE = /^send at line (\d+) to (.+)$/i;
53
+ const SKILLS_RE = /^skills (.+)$/i;
54
+ const SKILL_NAME_RE = /^[a-z][a-z0-9_-]*$/;
55
+ const SOURCE_RE = /^([a-z][a-z0-9_-]*) = (.+)$/;
56
+ // One source per line (M1 review correction b): a red only when the text
57
+ // after the first "file:" contains a second `source <role> =` clause — a
58
+ // fixed literal, anchored fragment, no nested quantifiers, so a legitimate
59
+ // path containing "," or ";" (e.g. "file:/tmp/a,b; c.docx") is not flagged.
60
+ const SECOND_SOURCE_RE = /[;,]\s*source\s+[a-z][a-z0-9_-]*\s*=/i;
61
+ const ROUND_RE = /^round budget (\d+)(s|m|h)$/i;
62
+
63
+ const INT_RE = /^\d+$/;
64
+ const DECIMAL_RE = /^\d+(?:\.\d+)?$/;
65
+ const UNIT_MS = Object.freeze({ s: 1000, m: 60000, h: 3600000 });
66
+ const DEFAULT_ASK_TTL_MS = 30 * 60000;
67
+ const DEFAULT_REDO_CAP = 3;
68
+ const DEFAULT_SKILLS = Object.freeze(['core']);
69
+ const DEFAULT_ROUND_BUDGET_MS = 120000;
70
+
71
+ /**
72
+ * Detect and parse the ask mark at the start of a numbered line's own text
73
+ * (already trimmed). Returns `{ attempted: false }` when the text is plain
74
+ * prose (never a mark, never a red — e.g. "asking the customer...",
75
+ * "askew..."). When `attempted` is true, either `ok: true` with
76
+ * `{ ttlMs, question }`, or `ok: false` with a human-readable `error`
77
+ * fragment naming what's wrong (the caller prefixes it with the file line
78
+ * and field "asks").
79
+ *
80
+ * @param {string} text
81
+ * @returns {{ attempted: false }
82
+ * | { attempted: true, ok: false, error: string }
83
+ * | { attempted: true, ok: true, ttlMs: number, question: string }}
84
+ */
85
+ function parseAskMark(text) {
86
+ if (!ASK_MARK_ATTEMPT_RE.test(text)) {
87
+ return { attempted: false };
88
+ }
89
+ const def = ASK_MARK_DEFAULT_RE.exec(text);
90
+ if (def) {
91
+ const question = def[1].trim();
92
+ if (question.length === 0) {
93
+ return { attempted: true, ok: false, error: 'has no words after the mark' };
94
+ }
95
+ return { attempted: true, ok: true, ttlMs: DEFAULT_ASK_TTL_MS, question };
96
+ }
97
+ const timed = ASK_MARK_TIMED_RE.exec(text);
98
+ if (timed) {
99
+ const value = Number(timed[1]);
100
+ const unit = timed[2].toLowerCase();
101
+ const question = timed[3].trim();
102
+ if (value <= 0) {
103
+ return { attempted: true, ok: false, error: 'wait must be greater than 0' };
104
+ }
105
+ if (question.length === 0) {
106
+ return { attempted: true, ok: false, error: 'has no words after the mark' };
107
+ }
108
+ return { attempted: true, ok: true, ttlMs: value * UNIT_MS[unit], question };
109
+ }
110
+ return { attempted: true, ok: false, error: 'is not "ask:" or "ask <int><s|m|h>:"' };
111
+ }
112
+
113
+ /**
114
+ * Parse the human's signed text. Never throws — any input that isn't a
115
+ * usable signed text comes back as `{ ok: false, reds }`, never an
116
+ * exception, and a non-string input is itself a red.
117
+ *
118
+ * @param {unknown} rawText
119
+ * @returns {SignedTextResult}
120
+ */
121
+ export function parseSignedText(rawText) {
122
+ if (typeof rawText !== 'string') {
123
+ return deepFreeze({ ok: false, reds: ['signed-text: input must be a string'] });
124
+ }
125
+
126
+ const rawLines = rawText.split(/\r?\n/);
127
+ const reds = [];
128
+ const lines = [];
129
+ const arbiterRawLines = [];
130
+ const asks = [];
131
+ let current = null;
132
+ let inArbiter = false;
133
+ let lastN = 0;
134
+
135
+ for (let i = 0; i < rawLines.length; i += 1) {
136
+ const fileLine = i + 1;
137
+ const trimmed = rawLines[i].trim();
138
+ if (trimmed.length === 0) continue;
139
+
140
+ if (HEADING_RE.test(trimmed)) {
141
+ inArbiter = true;
142
+ current = null;
143
+ continue;
144
+ }
145
+
146
+ if (inArbiter) {
147
+ const gm = GUARDRAIL_RE.exec(trimmed);
148
+ if (gm) {
149
+ arbiterRawLines.push({ fileLine, text: gm[1].trim() });
150
+ } else {
151
+ reds.push(`arbiter: line ${fileLine} "${trimmed}" is not in the grammar`);
152
+ }
153
+ continue;
154
+ }
155
+
156
+ const nm = NUMBERED_RE.exec(trimmed);
157
+ if (nm) {
158
+ const n = Number(nm[1]);
159
+ if (n <= lastN) {
160
+ reds.push(`signed-text: line ${fileLine} number ${n} is not increasing after ${lastN}`);
161
+ }
162
+ lastN = Math.max(lastN, n);
163
+ const rawLineText = nm[2].trim();
164
+ let lineText = rawLineText;
165
+ const mark = parseAskMark(rawLineText);
166
+ if (mark.attempted) {
167
+ if (!mark.ok) {
168
+ reds.push(`signed-text: line ${fileLine} field "asks" ${mark.error}: "${rawLineText}"`);
169
+ } else {
170
+ lineText = mark.question;
171
+ asks.push({ line: n, ttlMs: mark.ttlMs, question: mark.question });
172
+ }
173
+ }
174
+ current = { n, text: lineText, guardrail: '' };
175
+ lines.push(current);
176
+ continue;
177
+ }
178
+
179
+ const gm2 = GUARDRAIL_RE.exec(trimmed);
180
+ if (gm2) {
181
+ if (!current) {
182
+ reds.push(`signed-text: line ${fileLine} "guardrail:" has no numbered line above it`);
183
+ continue;
184
+ }
185
+ if (current.guardrail) {
186
+ reds.push(`signed-text: line ${fileLine} is a second "guardrail:" for line ${current.n}`);
187
+ continue;
188
+ }
189
+ current.guardrail = gm2[1].trim();
190
+ continue;
191
+ }
192
+
193
+ reds.push(`signed-text: line ${fileLine} "${trimmed}" is neither a numbered line nor a guardrail`);
194
+ }
195
+
196
+ if (!inArbiter) {
197
+ reds.push('arbiter: missing "Arbiter guardrails" heading (field "capUsd" is required)');
198
+ }
199
+
200
+ const sortedAsks = [...asks].sort((a, b) => a.line - b.line);
201
+ const arbiter = parseArbiter(arbiterRawLines, new Set(lines.map((l) => l.n)), reds, sortedAsks);
202
+
203
+ if (reds.length > 0) {
204
+ return deepFreeze({ ok: false, reds });
205
+ }
206
+
207
+ return deepFreeze({
208
+ ok: true,
209
+ lines: lines.map(({ n, text, guardrail }) => ({ n, text, guardrail })),
210
+ arbiter,
211
+ });
212
+ }
213
+
214
+ /**
215
+ * Parse the arbiter lines into the typed grammar, pushing every red found
216
+ * onto `reds` (in the order the lines appear) and returning the assembled
217
+ * fields. Called even when `reds` already carries earlier failures, so all
218
+ * reds in the document are reported together, in source-line order.
219
+ */
220
+ function parseArbiter(arbiterRawLines, lineNumbers, reds, asks) {
221
+ let capUsd;
222
+ let capSeen = 0;
223
+ let redoCap;
224
+ let redoSeen = 0;
225
+ const sends = [];
226
+ let skills;
227
+ let skillsSeen = 0;
228
+ const sources = [];
229
+ const sourceRolesSeen = new Set();
230
+ let roundBudgetMs;
231
+ let roundSeen = 0;
232
+
233
+ for (const { fileLine, text } of arbiterRawLines) {
234
+ const lower = text.toLowerCase();
235
+
236
+ if (lower.startsWith('cap ') || lower === 'cap') {
237
+ capSeen += 1;
238
+ const m = CAP_RE.exec(text);
239
+ if (!m || !DECIMAL_RE.test(m[1])) {
240
+ reds.push(`arbiter: line ${fileLine} field "capUsd" is not "cap $<decimal> per run": "${text}"`);
241
+ continue;
242
+ }
243
+ const value = Number(m[1]);
244
+ if (!(value > 0)) {
245
+ reds.push(`arbiter: line ${fileLine} field "capUsd" must be > 0, got ${m[1]}`);
246
+ continue;
247
+ }
248
+ if (capSeen > 1) {
249
+ reds.push(`arbiter: line ${fileLine} field "capUsd" is duplicated (cap is allowed exactly once)`);
250
+ continue;
251
+ }
252
+ capUsd = value;
253
+ continue;
254
+ }
255
+
256
+ if (OLD_ASK_ARBITER_RE.test(text)) {
257
+ // M1 amendment 3 item 5: this bottom-block form is retired — the ask
258
+ // is now a mark on the numbered line itself. One red naming it, never
259
+ // also falling through to the generic "not in the grammar" red below.
260
+ reds.push(`arbiter: line ${fileLine} field "asks" "guardrail: ask at line N" is no longer grammar — mark the numbered line itself with "ask:" (or "ask <int><s|m|h>:") instead: "${text}"`);
261
+ continue;
262
+ }
263
+
264
+ if (lower.startsWith('redo cap')) {
265
+ redoSeen += 1;
266
+ const m = REDO_RE.exec(text);
267
+ if (!m || !INT_RE.test(m[1])) {
268
+ reds.push(`arbiter: line ${fileLine} field "redoCap" is not "redo cap <int>": "${text}"`);
269
+ continue;
270
+ }
271
+ const value = Number(m[1]);
272
+ if (value < 1 || value > 3) {
273
+ reds.push(`arbiter: line ${fileLine} field "redoCap" must be 1..3, got ${value}`);
274
+ continue;
275
+ }
276
+ if (redoSeen > 1) {
277
+ reds.push(`arbiter: line ${fileLine} field "redoCap" is duplicated (allowed at most once)`);
278
+ continue;
279
+ }
280
+ redoCap = value;
281
+ continue;
282
+ }
283
+
284
+ if (SEND_PREFIX_RE.test(text)) {
285
+ const m = SEND_RE.exec(text);
286
+ if (!m) {
287
+ reds.push(`arbiter: line ${fileLine} field "sends" is not "send at line <int> to <target>": "${text}"`);
288
+ continue;
289
+ }
290
+ const line = Number(m[1]);
291
+ const target = m[2];
292
+ const colon = target.indexOf(':');
293
+ const kind = colon === -1 ? target : target.slice(0, colon);
294
+ const path = colon === -1 ? '' : target.slice(colon + 1).trim();
295
+ if (!lineNumbers.has(line)) {
296
+ reds.push(`arbiter: line ${fileLine} field "sends" names line ${line}, which is not one of the numbered lines`);
297
+ continue;
298
+ }
299
+ if (sends.some((s) => s.line === line)) {
300
+ reds.push(`arbiter: line ${fileLine} field "sends" duplicates a send at line ${line} (at most one send per line)`);
301
+ continue;
302
+ }
303
+ if (kind.toLowerCase() !== 'file') {
304
+ reds.push(`arbiter: line ${fileLine} field "sends" send target kind "${kind}" is not available until M9`);
305
+ continue;
306
+ }
307
+ if (!path) {
308
+ reds.push(`arbiter: line ${fileLine} field "sends" has an empty path`);
309
+ continue;
310
+ }
311
+ sends.push({ line, target: { kind: 'file', path } });
312
+ continue;
313
+ }
314
+
315
+ if (lower.startsWith('skills')) {
316
+ skillsSeen += 1;
317
+ const m = SKILLS_RE.exec(text);
318
+ if (!m) {
319
+ reds.push(`arbiter: line ${fileLine} field "skills" is not "skills <name>[, <name>...]": "${text}"`);
320
+ continue;
321
+ }
322
+ const names = m[1].split(',').map((s) => s.trim());
323
+ let anyBad = false;
324
+ for (const name of names) {
325
+ if (!SKILL_NAME_RE.test(name)) {
326
+ reds.push(`arbiter: line ${fileLine} field "skills" name "${name}" is not [a-z][a-z0-9_-]*`);
327
+ anyBad = true;
328
+ }
329
+ }
330
+ if (anyBad) continue;
331
+ if (skillsSeen > 1) {
332
+ reds.push(`arbiter: line ${fileLine} field "skills" is duplicated (allowed at most once)`);
333
+ continue;
334
+ }
335
+ skills = names;
336
+ continue;
337
+ }
338
+
339
+ if (lower.startsWith('source ')) {
340
+ const fileIdx = lower.indexOf('file:');
341
+ const afterFile = fileIdx === -1 ? '' : text.slice(fileIdx);
342
+ if (SECOND_SOURCE_RE.test(afterFile)) {
343
+ reds.push(`arbiter: line ${fileLine} field "sources" carries more than one source (";"/"," joined), one source per line: "${text}"`);
344
+ continue;
345
+ }
346
+ const rest = text.slice('source '.length);
347
+ const m = SOURCE_RE.exec(rest);
348
+ if (!m) {
349
+ reds.push(`arbiter: line ${fileLine} field "sources" is not "source <role> = file:<path>": "${text}"`);
350
+ continue;
351
+ }
352
+ const role = m[1];
353
+ const rhs = m[2];
354
+ if (sourceRolesSeen.has(role)) {
355
+ reds.push(`arbiter: line ${fileLine} field "sources" duplicates role "${role}"`);
356
+ continue;
357
+ }
358
+ const colon = rhs.indexOf(':');
359
+ const kind = colon === -1 ? rhs : rhs.slice(0, colon);
360
+ const path = colon === -1 ? '' : rhs.slice(colon + 1).trim();
361
+ if (kind.toLowerCase() !== 'file') {
362
+ reds.push(`arbiter: line ${fileLine} field "sources" source kind "${kind}" is not available until M9`);
363
+ continue;
364
+ }
365
+ if (!path) {
366
+ reds.push(`arbiter: line ${fileLine} field "sources" has an empty path`);
367
+ continue;
368
+ }
369
+ sourceRolesSeen.add(role);
370
+ sources.push({ role, kind: 'file', path });
371
+ continue;
372
+ }
373
+
374
+ if (lower.startsWith('round budget')) {
375
+ roundSeen += 1;
376
+ const m = ROUND_RE.exec(text);
377
+ if (!m) {
378
+ reds.push(`arbiter: line ${fileLine} field "roundBudgetMs" is not "round budget <int><s|m|h>": "${text}"`);
379
+ continue;
380
+ }
381
+ if (roundSeen > 1) {
382
+ reds.push(`arbiter: line ${fileLine} field "roundBudgetMs" is duplicated (allowed at most once)`);
383
+ continue;
384
+ }
385
+ roundBudgetMs = Number(m[1]) * UNIT_MS[m[2].toLowerCase()];
386
+ continue;
387
+ }
388
+
389
+ reds.push(`arbiter: line ${fileLine} "${text}" is not in the grammar`);
390
+ }
391
+
392
+ if (capUsd === undefined && capSeen === 0) {
393
+ reds.push('arbiter: field "capUsd" is required ("cap $<decimal> per run") and is missing');
394
+ }
395
+
396
+ for (const s of sends) {
397
+ if (!asks.some((a) => a.line < s.line)) {
398
+ reds.push(`arbiter: field "sends" send at line ${s.line} has no ask at an earlier line (asks: [${asks.map((a) => a.line).join(', ')}])`);
399
+ }
400
+ }
401
+
402
+ return {
403
+ capUsd,
404
+ asks,
405
+ redoCap: redoCap ?? DEFAULT_REDO_CAP,
406
+ sends,
407
+ skills: skills ?? DEFAULT_SKILLS.slice(),
408
+ sources,
409
+ roundBudgetMs: roundBudgetMs ?? DEFAULT_ROUND_BUDGET_MS,
410
+ };
411
+ }
412
+
413
+ function deepFreeze(value) {
414
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
415
+ Object.freeze(value);
416
+ for (const key of Object.keys(value)) deepFreeze(value[key]);
417
+ }
418
+ return value;
419
+ }
package/src/types.js ADDED
@@ -0,0 +1,233 @@
1
+ // Shared @typedefs for the public API. No runtime code — JSDoc only, so
2
+ // `tsc` (per LIBRARY_CONVENTIONS §2) generates `types/types.d.ts` from this
3
+ // file and every other module imports the shapes from here.
4
+
5
+ /**
6
+ * @typedef {object} SignedLine
7
+ * @property {number} n - the number the human wrote, used as the join key.
8
+ * @property {string} text - the line's text, trimmed.
9
+ * @property {string} guardrail - the guardrail directly under this line, or
10
+ * `''` when the human left it blank.
11
+ */
12
+
13
+ /**
14
+ * @typedef {object} AskSlot
15
+ * @property {number} line - the numbered line this ask binds to (the line
16
+ * carries the `ask:`/`ask <int><s|m|h>:` mark itself, M1 amendment 3).
17
+ * @property {number} ttlMs - the ask's time-to-live in milliseconds.
18
+ * @property {string} question - the words after the mark, trimmed — the
19
+ * human's own question. Nothing reads this yet outside signed-text.js.
20
+ */
21
+
22
+ /**
23
+ * @typedef {object} SendTarget
24
+ * @property {'file'} kind - only `file:` targets are available before M9.
25
+ * @property {string} path - everything after `file:` to end of line, trimmed.
26
+ */
27
+
28
+ /**
29
+ * @typedef {object} SendSlot
30
+ * @property {number} line - the numbered line this send binds to.
31
+ * @property {SendTarget} target
32
+ */
33
+
34
+ /**
35
+ * @typedef {object} SourceSlot
36
+ * @property {string} role - `[a-z][a-z0-9_-]*`, unique across sources.
37
+ * @property {'file'} kind - only `file:` sources are available before M9.
38
+ * @property {string} path - everything after `file:` to end of line, trimmed.
39
+ */
40
+
41
+ /**
42
+ * @typedef {object} Arbiter
43
+ * @property {number} capUsd - `cap $<decimal> per run`. Required, > 0.
44
+ * @property {AskSlot[]} asks - zero or more marked lines (`ask:` /
45
+ * `ask <int><s|m|h>:` at the start of a numbered job line, M1 amendment 3).
46
+ * @property {number} redoCap - `redo cap <int>`, 1..3. Default 3.
47
+ * @property {SendSlot[]} sends - zero or more `send at line <int> to ...`.
48
+ * @property {string[]} skills - `skills <name>[, <name>...]`. Default ['core'].
49
+ * @property {SourceSlot[]} sources - zero or more `source <role> = file:<path>`.
50
+ * @property {number} roundBudgetMs - `round budget <int><s|m|h>`. Default 120000.
51
+ */
52
+
53
+ /**
54
+ * @typedef {object} SignedTextOk
55
+ * @property {true} ok
56
+ * @property {SignedLine[]} lines
57
+ * @property {Arbiter} arbiter
58
+ */
59
+
60
+ /**
61
+ * @typedef {object} SignedTextRed
62
+ * @property {false} ok
63
+ * @property {string[]} reds
64
+ */
65
+
66
+ /** @typedef {SignedTextOk | SignedTextRed} SignedTextResult */
67
+
68
+ /**
69
+ * @typedef {object} CanonicalBytesOk
70
+ * @property {true} ok
71
+ * @property {Buffer} bytes
72
+ */
73
+
74
+ /**
75
+ * @typedef {object} CanonicalBytesRed
76
+ * @property {false} ok
77
+ * @property {string} red
78
+ */
79
+
80
+ /** @typedef {CanonicalBytesOk | CanonicalBytesRed} CanonicalBytesResult */
81
+
82
+ /**
83
+ * sha256 hex digests of each signed file's canonical bytes.
84
+ * @typedef {{ 'prose.txt': string, 'declaration.json': string }} SignatureFiles
85
+ */
86
+
87
+ /**
88
+ * @typedef {object} Signature
89
+ * @property {2} version
90
+ * @property {'sha256'} algorithm
91
+ * @property {SignatureFiles} files
92
+ * @property {string} flow - sha256 hex of
93
+ * `JSON.stringify([files['prose.txt'], files['declaration.json'], signedBy, signedAt])`,
94
+ * in that fixed order — pins WHAT was signed (the two file hashes) and
95
+ * WHO/WHEN (signedBy/signedAt); editing any of the four after signing
96
+ * changes this hash.
97
+ * @property {string} signedBy
98
+ * @property {string} signedAt - ISO-8601.
99
+ */
100
+
101
+ /**
102
+ * @typedef {object} SignFlowOk
103
+ * @property {true} ok
104
+ * @property {Signature} signature
105
+ */
106
+
107
+ /**
108
+ * @typedef {object} SignFlowRed
109
+ * @property {false} ok
110
+ * @property {string[]} reds
111
+ */
112
+
113
+ /** @typedef {SignFlowOk | SignFlowRed} SignFlowResult */
114
+
115
+ /**
116
+ * @typedef {object} VerifyFlowOk
117
+ * @property {true} ok
118
+ */
119
+
120
+ /**
121
+ * @typedef {object} VerifyFlowRed
122
+ * @property {false} ok
123
+ * @property {string[]} reds
124
+ */
125
+
126
+ /** @typedef {VerifyFlowOk | VerifyFlowRed} VerifyFlowResult */
127
+
128
+ /**
129
+ * One catalogue primitive entry. M1 piece 3 only needed `verb`/`skill`/
130
+ * `class` (the catalogue was a caller-supplied parameter); piece 4 makes
131
+ * `src/catalogue.json` the real data file, so this typedef grew the rest
132
+ * of the fields the file actually carries. `method`/`tool` are mutually
133
+ * exclusive and optional.
134
+ * @typedef {object} CatalogueEntry
135
+ * @property {string} verb
136
+ * @property {string} component
137
+ * @property {string} package
138
+ * @property {string} symbol
139
+ * @property {string} [method]
140
+ * @property {string} [tool]
141
+ * @property {string} class
142
+ * @property {string} skill
143
+ * @property {string} desc
144
+ */
145
+
146
+ /**
147
+ * One catalogue plumbing entry — the runner wires these around every step;
148
+ * the drafter never selects them, so they never appear in `primitives`,
149
+ * `menu()`, or `primitiveFor()`.
150
+ * @typedef {object} PlumbingEntry
151
+ * @property {string} name
152
+ * @property {string} package
153
+ * @property {string} symbol
154
+ */
155
+
156
+ /**
157
+ * @typedef {object} ParseCatalogueOk
158
+ * @property {true} ok
159
+ * @property {CatalogueEntry[]} primitives
160
+ * @property {PlumbingEntry[]} plumbing
161
+ */
162
+
163
+ /**
164
+ * @typedef {object} ParseCatalogueRed
165
+ * @property {false} ok
166
+ * @property {string[]} reds
167
+ */
168
+
169
+ /** @typedef {ParseCatalogueOk | ParseCatalogueRed} ParseCatalogueResult */
170
+
171
+ /**
172
+ * @typedef {object} ValidateDeclarationOk
173
+ * @property {true} ok
174
+ * @property {Record<string, string>} classes - keyed by each step's `emits`
175
+ * id, value the step's effective guardrail class.
176
+ */
177
+
178
+ /**
179
+ * @typedef {object} ValidateDeclarationRed
180
+ * @property {false} ok
181
+ * @property {string[]} reds
182
+ */
183
+
184
+ /** @typedef {ValidateDeclarationOk | ValidateDeclarationRed} ValidateDeclarationResult */
185
+
186
+ /**
187
+ * @typedef {object} CheckFlowNameOk
188
+ * @property {true} ok
189
+ */
190
+
191
+ /**
192
+ * @typedef {object} CheckFlowNameRed
193
+ * @property {false} ok
194
+ * @property {string} red
195
+ */
196
+
197
+ /** @typedef {CheckFlowNameOk | CheckFlowNameRed} CheckFlowNameResult */
198
+
199
+ /**
200
+ * @typedef {object} WriteFlowOk
201
+ * @property {true} ok
202
+ * @property {string} dir
203
+ * @property {Signature} signature
204
+ */
205
+
206
+ /**
207
+ * @typedef {object} WriteFlowRed
208
+ * @property {false} ok
209
+ * @property {string[]} reds
210
+ */
211
+
212
+ /** @typedef {WriteFlowOk | WriteFlowRed} WriteFlowResult */
213
+
214
+ /**
215
+ * @typedef {object} ReadFlowOk
216
+ * @property {true} ok
217
+ * @property {string} dir
218
+ * @property {SignedLine[]} lines
219
+ * @property {Arbiter} arbiter
220
+ * @property {Record<string, any>} declaration
221
+ * @property {Signature} signature
222
+ * @property {Record<string, string>} classes
223
+ */
224
+
225
+ /**
226
+ * @typedef {object} ReadFlowRed
227
+ * @property {false} ok
228
+ * @property {string[]} reds
229
+ */
230
+
231
+ /** @typedef {ReadFlowOk | ReadFlowRed} ReadFlowResult */
232
+
233
+ export {};