fwdloop 0.4.0 → 0.4.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/package.json +1 -1
- package/src/declaration.js +90 -8
- package/src/flow.js +25 -1
- package/types/declaration.d.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/declaration.js
CHANGED
|
@@ -94,13 +94,37 @@ function checkOwnKeys(obj, allowed, path, reds) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
/** The typed `close.shape` vocabulary, signed by hamr 2026-09-23 (v1):
|
|
98
|
+
* exactly these four top-level keys. Anything else inside `shape` reds by
|
|
99
|
+
* name. */
|
|
100
|
+
export const SHAPE_KEYS = Object.freeze(['maxWords', 'sections', 'linesPerInvoice', 'mustCarry']);
|
|
101
|
+
|
|
102
|
+
const SHAPE_TYPE_CHECKS = Object.freeze({
|
|
103
|
+
maxWords: {
|
|
104
|
+
expected: 'a positive integer',
|
|
105
|
+
check: (v) => Number.isInteger(v) && v > 0,
|
|
106
|
+
},
|
|
107
|
+
linesPerInvoice: {
|
|
108
|
+
expected: 'a positive integer',
|
|
109
|
+
check: (v) => Number.isInteger(v) && v > 0,
|
|
110
|
+
},
|
|
111
|
+
sections: {
|
|
112
|
+
expected: 'a non-empty array of non-empty strings',
|
|
113
|
+
check: (v) => Array.isArray(v) && v.length > 0 && v.every((s) => typeof s === 'string' && s.length > 0),
|
|
114
|
+
},
|
|
115
|
+
mustCarry: {
|
|
116
|
+
expected: 'a non-empty array of non-empty strings',
|
|
117
|
+
check: (v) => Array.isArray(v) && v.length > 0 && v.every((s) => typeof s === 'string' && s.length > 0),
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/** Arbiter-key refusal recursively through a `close.shape` value — any
|
|
122
|
+
* depth, any key named after the arbiter's vocabulary, in an object or
|
|
123
|
+
* nested inside an array (e.g. inside a `sections` array entry that turns
|
|
124
|
+
* out to be an object). */
|
|
125
|
+
function scanForArbiterKeys(value, path, reds) {
|
|
102
126
|
if (Array.isArray(value)) {
|
|
103
|
-
value.forEach((entry, i) =>
|
|
127
|
+
value.forEach((entry, i) => scanForArbiterKeys(entry, `${path}[${i}]`, reds));
|
|
104
128
|
return;
|
|
105
129
|
}
|
|
106
130
|
if (isPlainObject(value)) {
|
|
@@ -109,11 +133,69 @@ function scanShapeForArbiterKeys(value, path, reds) {
|
|
|
109
133
|
if (ARBITER_KEYS.includes(key)) {
|
|
110
134
|
reds.push(`declaration: arbiter field "${key}" at ${childPath} — the drafter cannot author it`);
|
|
111
135
|
}
|
|
112
|
-
|
|
136
|
+
scanForArbiterKeys(value[key], childPath, reds);
|
|
113
137
|
}
|
|
114
138
|
}
|
|
115
139
|
}
|
|
116
140
|
|
|
141
|
+
/** `close.shape`'s own top-level keys must each be in SHAPE_KEYS (the signed
|
|
142
|
+
* v1 vocabulary) — an arbiter key gets the existing arbiter-red wording, any
|
|
143
|
+
* other unknown key reds by name, and a known key is type-checked. Nested
|
|
144
|
+
* arbiter-key refusal still applies at any depth inside a shape value. */
|
|
145
|
+
function checkShapeKeys(shape, path, reds) {
|
|
146
|
+
for (const key of Object.keys(shape)) {
|
|
147
|
+
const childPath = `${path}.${key}`;
|
|
148
|
+
const value = shape[key];
|
|
149
|
+
if (ARBITER_KEYS.includes(key)) {
|
|
150
|
+
reds.push(`declaration: arbiter field "${key}" at ${childPath} — the drafter cannot author it`);
|
|
151
|
+
} else if (!SHAPE_KEYS.includes(key)) {
|
|
152
|
+
reds.push(`declaration: unknown shape key "${key}" at ${childPath}`);
|
|
153
|
+
} else {
|
|
154
|
+
const typeCheck = SHAPE_TYPE_CHECKS[key];
|
|
155
|
+
if (!typeCheck.check(value)) {
|
|
156
|
+
reds.push(`declaration: shape key "${key}" at ${childPath} must be ${typeCheck.expected}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
scanForArbiterKeys(value, childPath, reds);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A small, pure walker over `declaration.steps` for callers that only want
|
|
165
|
+
* the shape-key verdict (e.g. poc/m1/slot-batch.mjs's `shape` column) —
|
|
166
|
+
* never a substitute for `validateDeclaration`, which is still the one
|
|
167
|
+
* check that decides pass/fail for a real declaration. Reuses the same
|
|
168
|
+
* `checkShapeKeys` `validateDeclaration` calls, so the two can never drift
|
|
169
|
+
* apart on what counts as a known shape key.
|
|
170
|
+
*
|
|
171
|
+
* A non-array `declaration.steps` (or a non-object `declaration` at all)
|
|
172
|
+
* reds `'no steps array'` rather than throwing. `shapedSteps` counts every
|
|
173
|
+
* step whose `close` carries a `shape` key at all — a step that TRIED to
|
|
174
|
+
* carry a shape, known-key or not, plain-object or not. A `shape` that
|
|
175
|
+
* isn't a plain object (array, string, number, null) reds
|
|
176
|
+
* `"... .close.shape must be an object"`, matching `validateDeclaration`'s
|
|
177
|
+
* own red for the same malformed input.
|
|
178
|
+
*/
|
|
179
|
+
export function checkShapes(declaration) {
|
|
180
|
+
const steps = isPlainObject(declaration) && Array.isArray(declaration.steps) ? declaration.steps : null;
|
|
181
|
+
if (steps === null) {
|
|
182
|
+
return { verdict: 'red', reds: ['no steps array'], shapedSteps: 0 };
|
|
183
|
+
}
|
|
184
|
+
const reds = [];
|
|
185
|
+
let shapedSteps = 0;
|
|
186
|
+
steps.forEach((step, i) => {
|
|
187
|
+
if (!isPlainObject(step?.close) || !('shape' in step.close)) return;
|
|
188
|
+
const shape = step.close.shape;
|
|
189
|
+
shapedSteps += 1;
|
|
190
|
+
if (isPlainObject(shape)) {
|
|
191
|
+
checkShapeKeys(shape, `declaration.steps[${i}].close.shape`, reds);
|
|
192
|
+
} else {
|
|
193
|
+
reds.push(`declaration.steps[${i}].close.shape must be an object`);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return { verdict: reds.length > 0 ? 'red' : 'green', reds, shapedSteps };
|
|
197
|
+
}
|
|
198
|
+
|
|
117
199
|
/**
|
|
118
200
|
* Resolve one line's class from `guardrailClasses`, exactly as
|
|
119
201
|
* poc/m0/validator.mjs's `resolveGuardrailClass` does: blank guardrail is
|
|
@@ -417,7 +499,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
417
499
|
if (!isPlainObject(step.close.shape)) {
|
|
418
500
|
reds.push(`declaration: ${label}.close.shape must be an object`);
|
|
419
501
|
} else {
|
|
420
|
-
|
|
502
|
+
checkShapeKeys(step.close.shape, `declaration.${label}.close.shape`, reds);
|
|
421
503
|
}
|
|
422
504
|
}
|
|
423
505
|
}
|
package/src/flow.js
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
// caught and returned as a red naming the file or path involved.
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
|
-
existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync,
|
|
23
|
+
accessSync, constants as fsConstants, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync,
|
|
24
|
+
writeFileSync,
|
|
24
25
|
} from 'node:fs';
|
|
25
26
|
import path from 'node:path';
|
|
26
27
|
|
|
@@ -284,6 +285,29 @@ export function readFlow({ root, name, catalogue }) {
|
|
|
284
285
|
}
|
|
285
286
|
}
|
|
286
287
|
|
|
288
|
+
// runs/ (M1 only creates the empty directory; reading inside it is M2's
|
|
289
|
+
// job — this only checks it exists, isn't a symlink, and is a directory).
|
|
290
|
+
const runsPath = path.join(dir, RUNS_DIR);
|
|
291
|
+
let runsStat;
|
|
292
|
+
try {
|
|
293
|
+
runsStat = lstatSync(runsPath);
|
|
294
|
+
} catch {
|
|
295
|
+
reds.push(`flow: directory "${dir}/${RUNS_DIR}" is missing`);
|
|
296
|
+
}
|
|
297
|
+
if (runsStat) {
|
|
298
|
+
if (runsStat.isSymbolicLink()) {
|
|
299
|
+
reds.push(`flow: directory "${dir}/${RUNS_DIR}" is a symlink, refused`);
|
|
300
|
+
} else if (!runsStat.isDirectory()) {
|
|
301
|
+
reds.push(`flow: "${dir}/${RUNS_DIR}" is not a directory`);
|
|
302
|
+
} else {
|
|
303
|
+
try {
|
|
304
|
+
accessSync(runsPath, fsConstants.R_OK | fsConstants.X_OK);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
reds.push(`flow: directory "${dir}/${RUNS_DIR}" is not readable (${err.code})`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
287
311
|
if (reds.length > 0) return { ok: false, reds };
|
|
288
312
|
|
|
289
313
|
// Verify against the bytes on disk, not a re-serialised object.
|
package/types/declaration.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small, pure walker over `declaration.steps` for callers that only want
|
|
3
|
+
* the shape-key verdict (e.g. poc/m1/slot-batch.mjs's `shape` column) —
|
|
4
|
+
* never a substitute for `validateDeclaration`, which is still the one
|
|
5
|
+
* check that decides pass/fail for a real declaration. Reuses the same
|
|
6
|
+
* `checkShapeKeys` `validateDeclaration` calls, so the two can never drift
|
|
7
|
+
* apart on what counts as a known shape key.
|
|
8
|
+
*
|
|
9
|
+
* A non-array `declaration.steps` (or a non-object `declaration` at all)
|
|
10
|
+
* reds `'no steps array'` rather than throwing. `shapedSteps` counts every
|
|
11
|
+
* step whose `close` carries a `shape` key at all — a step that TRIED to
|
|
12
|
+
* carry a shape, known-key or not, plain-object or not. A `shape` that
|
|
13
|
+
* isn't a plain object (array, string, number, null) reds
|
|
14
|
+
* `"... .close.shape must be an object"`, matching `validateDeclaration`'s
|
|
15
|
+
* own red for the same malformed input.
|
|
16
|
+
*/
|
|
17
|
+
export function checkShapes(declaration: any): {
|
|
18
|
+
verdict: string;
|
|
19
|
+
reds: any[];
|
|
20
|
+
shapedSteps: number;
|
|
21
|
+
};
|
|
1
22
|
/**
|
|
2
23
|
* Validate a drafter declaration against the M1 closed schema. `arbiter`
|
|
3
24
|
* and `lines` are `parseSignedText`'s output; `catalogue` is a plain array
|
|
@@ -22,6 +43,10 @@ export function validateDeclaration(declaration: unknown, context?: {
|
|
|
22
43
|
* kept in sync with the checks below so a mutation suite can assert it
|
|
23
44
|
* tested every one of them (same trick as ARBITER_FIELDS/SIGNATURE_FIELDS). */
|
|
24
45
|
export const DECLARATION_FIELDS: readonly string[];
|
|
46
|
+
/** The typed `close.shape` vocabulary, signed by hamr 2026-09-23 (v1):
|
|
47
|
+
* exactly these four top-level keys. Anything else inside `shape` reds by
|
|
48
|
+
* name. */
|
|
49
|
+
export const SHAPE_KEYS: readonly string[];
|
|
25
50
|
export type Arbiter = import("./types.js").Arbiter;
|
|
26
51
|
export type SignedLine = import("./types.js").SignedLine;
|
|
27
52
|
export type CatalogueEntry = import("./types.js").CatalogueEntry;
|