owenloop 0.5.8 → 0.5.10
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/CHANGELOG.md +69 -0
- package/README.md +81 -39
- package/bin/owenloop.mjs +16 -1
- package/dist/packages/work/src/agent/loop.d.ts +23 -8
- package/dist/packages/work/src/agent/loop.js +55 -6
- package/dist/packages/work/src/bundle/pull.d.ts +21 -0
- package/dist/packages/work/src/bundle/pull.js +118 -0
- package/dist/packages/work/src/consumed-verifier.js +6 -17
- package/dist/packages/work/src/exec/instructions.d.ts +4 -1
- package/dist/packages/work/src/exec/instructions.js +3 -0
- package/dist/packages/work/src/exec/loop.d.ts +2 -2
- package/dist/packages/work/src/exec/loop.js +273 -46
- package/dist/packages/work/src/exec/receipt.d.ts +7 -7
- package/dist/packages/work/src/exec/receipt.js +6 -6
- package/dist/packages/work/src/harness/claude.js +116 -0
- package/dist/packages/work/src/harness/codex.d.ts +8 -0
- package/dist/packages/work/src/harness/codex.js +27 -1
- package/dist/packages/work/src/harness/contract.d.ts +9 -0
- package/dist/packages/work/src/hub/client.d.ts +19 -4
- package/dist/packages/work/src/hub/client.js +7 -3
- package/dist/packages/work/src/hub/types.d.ts +84 -0
- package/dist/packages/work/src/main.js +1 -0
- package/dist/packages/work/src/roles/agent-run.js +57 -32
- package/dist/packages/work/src/roles/exec.js +27 -8
- package/dist/packages/work/src/roles/settings.js +2 -0
- package/dist/packages/work/src/roles/shift.js +14 -2
- package/dist/packages/work/src/roles/util.d.ts +1 -0
- package/dist/packages/work/src/roles/util.js +10 -0
- package/dist/packages/work/src/settings/hub-roster-cache.d.ts +68 -0
- package/dist/packages/work/src/settings/hub-roster-cache.js +370 -0
- package/dist/packages/work/src/settings/roster.d.ts +84 -0
- package/dist/packages/work/src/settings/roster.js +364 -5
- package/dist/packages/work/src/settings/serving.d.ts +17 -0
- package/dist/packages/work/src/settings/serving.js +79 -0
- package/dist/packages/work/src/settings/settings.d.ts +14 -1
- package/dist/packages/work/src/settings/settings.js +14 -0
- package/dist/packages/work/src/shift/loop.d.ts +108 -5
- package/dist/packages/work/src/shift/loop.js +416 -54
- package/dist/packages/work/src/shift/protocol.d.ts +7 -5
- package/dist/packages/work/src/shift/runtime.d.ts +18 -0
- package/dist/packages/work/src/shift/runtime.js +104 -5
- package/dist/packages/work/src/shift/server.js +2 -0
- package/dist/packages/work/src/shift/spawn.d.ts +17 -2
- package/dist/packages/work/src/shift/spawn.js +16 -13
- package/dist/packages/work/src/shift/state.d.ts +29 -2
- package/dist/packages/work/src/shift/state.js +45 -15
- package/dist/packages/work/src/submit-proof.d.ts +11 -8
- package/dist/packages/work/src/submit-proof.js +11 -8
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +7 -1
- package/dist/packages/work/src/util/modifier-init.d.ts +7 -0
- package/dist/packages/work/src/util/modifier-init.js +73 -0
- package/dist/src/bundle/tar.d.ts +9 -4
- package/dist/src/bundle/tar.js +9 -4
- package/dist/src/capabilities.d.ts +76 -6
- package/dist/src/capabilities.js +49 -6
- package/dist/src/capability-mapping-client.d.ts +29 -0
- package/dist/src/capability-mapping-client.js +160 -0
- package/dist/src/cli.d.ts +16 -3
- package/dist/src/cli.js +1925 -281
- package/dist/src/config-dir.d.ts +1 -1
- package/dist/src/config-dir.js +1 -1
- package/dist/src/crypto/index.d.ts +1 -1
- package/dist/src/crypto/index.js +1 -1
- package/dist/src/crypto/org-root.d.ts +30 -12
- package/dist/src/crypto/org-root.js +162 -14
- package/dist/src/crypto/records.d.ts +2 -0
- package/dist/src/crypto/records.js +2 -0
- package/dist/src/defs.d.ts +38 -2
- package/dist/src/defs.js +593 -86
- package/dist/src/engine.d.ts +103 -25
- package/dist/src/engine.js +331 -79
- package/dist/src/hub.d.ts +77 -0
- package/dist/src/hub.js +162 -0
- package/dist/src/implements.d.ts +56 -0
- package/dist/src/implements.js +790 -0
- package/dist/src/index.d.ts +11 -9
- package/dist/src/index.js +6 -5
- package/dist/src/mcp/serve.d.ts +22 -0
- package/dist/src/mcp/serve.js +330 -41
- package/dist/src/mcp/server.d.ts +10 -7
- package/dist/src/mcp/server.js +53 -8
- package/dist/src/model.d.ts +48 -10
- package/dist/src/model.js +252 -99
- package/dist/src/order-resolver.d.ts +1 -0
- package/dist/src/order-resolver.js +8 -1
- package/dist/src/schemas/index.d.ts +11 -0
- package/dist/src/schemas/order.v1.schema.json +7 -1
- package/dist/src/store/def-source.d.ts +19 -0
- package/dist/src/store/def-source.js +87 -17
- package/dist/src/store/gc-recovery.d.ts +46 -0
- package/dist/src/store/gc-recovery.js +258 -0
- package/dist/src/store/gc.d.ts +94 -0
- package/dist/src/store/gc.js +562 -0
- package/dist/src/store/index.d.ts +3 -1
- package/dist/src/store/index.js +2 -0
- package/dist/src/store/install.d.ts +34 -5
- package/dist/src/store/install.js +73 -11
- package/dist/src/store/pre-commit-verifier.js +42 -2
- package/dist/src/store/snapshot-guard.d.ts +18 -0
- package/dist/src/store/snapshot-guard.js +94 -0
- package/dist/src/store.d.ts +69 -4
- package/dist/src/store.js +254 -16
- package/dist/src/types.d.ts +101 -20
- package/dist/src/util.js +4 -1
- package/docs/authoring.md +235 -10
- package/docs/bundles.md +45 -2
- package/docs/cli.md +437 -55
- package/docs/crypto.md +32 -10
- package/docs/design.md +177 -47
- package/docs/evals/mcp-charter-baseline.json +428 -0
- package/docs/mcp-charter-eval.md +124 -0
- package/docs/routing.md +189 -34
- package/docs/shift-logs.md +38 -9
- package/docs/wire-contracts.md +78 -14
- package/examples/workflows/compile-dev-playbook.yaml +1 -1
- package/examples/workflows/delivery.yaml +31 -14
- package/examples/workflows/ship.yaml +38 -4
- package/package.json +2 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/claude-code/plugin/skills/author/SKILL.md +22 -0
- package/plugins/claude-code/plugin/skills/ephemeral/SKILL.md +95 -0
- package/plugins/claude-code/plugin/skills/graduate/SKILL.md +156 -0
- package/plugins/claude-code/plugin/skills/plan/SKILL.md +236 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +22 -0
- package/plugins/codex/plugins/owenloop/skills/ephemeral/SKILL.md +95 -0
- package/plugins/codex/plugins/owenloop/skills/graduate/SKILL.md +156 -0
- package/plugins/codex/plugins/owenloop/skills/plan/SKILL.md +236 -0
package/dist/src/defs.js
CHANGED
|
@@ -32,7 +32,7 @@ import { MODIFIER_SEPARATOR } from "./capabilities.js";
|
|
|
32
32
|
/** Hand-maintained key allowlist for RawInput — kept next to the interface so
|
|
33
33
|
* the two can't silently drift (§27 unknown-key rejection). */
|
|
34
34
|
const RAW_INPUT_KEYS = ['name', 'producer', 'seedOwed', 'schema'];
|
|
35
|
-
const RAW_PRODUCE_KEYS = ['name', 'schema', 'judges', 'maxAttempts', 'maxSchemaFailures'];
|
|
35
|
+
const RAW_PRODUCE_KEYS = ['name', 'schema', 'judges', 'maxAttempts', 'maxSchemaFailures', 'bind'];
|
|
36
36
|
/** Hand-maintained key allowlist for RawGroup — a `group:` entry is a
|
|
37
37
|
* DIFFERENT (smaller) shape than RawProduce, not a produce with extra
|
|
38
38
|
* fields, so it gets its own allowlist rather than folding into
|
|
@@ -45,7 +45,7 @@ const RAW_STEP_KEYS = [
|
|
|
45
45
|
'maxRunsPerDay', 'parallel', 'maxAttempts', 'maxSchemaFailures', 'model',
|
|
46
46
|
'workdir', 'workdirFrom', 'terminal', 'effect', 'on', 'idleAfter', 'body', 'bodyFile',
|
|
47
47
|
'calls', 'reapTtl', 'capabilities', 'maxLease', 'x', 'executor', 'command', 'spec',
|
|
48
|
-
'escalation',
|
|
48
|
+
'escalation', 'onCancel',
|
|
49
49
|
];
|
|
50
50
|
/** Keys valid on a calls: step entry — a DIFFERENT (smaller) shape than RawStep;
|
|
51
51
|
* the `calls:` key is what routes an entry here instead of RAW_STEP_KEYS. */
|
|
@@ -113,7 +113,8 @@ function assertAuthoredCapability(value, ctx) {
|
|
|
113
113
|
*
|
|
114
114
|
* Order is NOT preserved as meaning: the list is a vocabulary, and nothing in
|
|
115
115
|
* the engine compares two modifiers or treats one as higher than another. The
|
|
116
|
-
* array shape is only YAML's way of writing a set.
|
|
116
|
+
* array shape is only YAML's way of writing a set. The vocabulary is fixed
|
|
117
|
+
* here; every downstream gate checks membership in it and nothing else.
|
|
117
118
|
*/
|
|
118
119
|
function parseModifiers(v, ctx) {
|
|
119
120
|
const values = asStringArray(v, ctx);
|
|
@@ -125,6 +126,11 @@ function parseModifiers(v, ctx) {
|
|
|
125
126
|
if (value.trim().length === 0) {
|
|
126
127
|
throw new DefError(`${ctx}: modifier names must not be empty or whitespace`);
|
|
127
128
|
}
|
|
129
|
+
if (/\s/.test(value)) {
|
|
130
|
+
throw new DefError(`${ctx}: modifier '${value}' must not contain whitespace — ` +
|
|
131
|
+
'a modifier is composed onto every authored capability as ' +
|
|
132
|
+
`'<capability>${MODIFIER_SEPARATOR}<modifier>' and travels as a routing key`);
|
|
133
|
+
}
|
|
128
134
|
if (value.includes(MODIFIER_SEPARATOR)) {
|
|
129
135
|
throw new DefError(`${ctx}: modifier '${value}' must not contain '${MODIFIER_SEPARATOR}' — ` +
|
|
130
136
|
'it is the separator the engine composes with');
|
|
@@ -157,6 +163,19 @@ function parseEscalation(v, ctx) {
|
|
|
157
163
|
throw new DefError(`${ctx}.modifier must not be empty`);
|
|
158
164
|
return { after, modifier };
|
|
159
165
|
}
|
|
166
|
+
/** Parse a step's `onCancel:` block. Stem-membership cross-checks live in
|
|
167
|
+
* validateDef because they need the step's parsed consumes. */
|
|
168
|
+
function parseOnCancel(v, ctx) {
|
|
169
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v)) {
|
|
170
|
+
throw new DefError(`${ctx} must be a mapping of { consumes }`);
|
|
171
|
+
}
|
|
172
|
+
const raw = v;
|
|
173
|
+
assertNoUnknownKeys(raw, ['consumes'], ctx);
|
|
174
|
+
if (raw['consumes'] === undefined) {
|
|
175
|
+
throw new DefError(`${ctx} must set 'consumes' (the subset of the step's consumes the cancel-path firing requires; use [] for none)`);
|
|
176
|
+
}
|
|
177
|
+
return { consumes: asStringArray(raw['consumes'], `${ctx}.consumes`) };
|
|
178
|
+
}
|
|
160
179
|
function asNumber(v, fallback, ctx) {
|
|
161
180
|
if (v === undefined)
|
|
162
181
|
return fallback;
|
|
@@ -372,6 +391,14 @@ function parseGroup(v, ctx) {
|
|
|
372
391
|
const of = v.of.map((s, i) => asString(s, `group '${group}'.of[${i}]`));
|
|
373
392
|
return { group, mode, of };
|
|
374
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* The `from` a bind gets when its author omits one: the final segment of
|
|
396
|
+
* `to`. A shorthand `bind: modifier` therefore reads the accepted
|
|
397
|
+
* object's `modifier` key, while `bind: meta.customer` reads `customer`.
|
|
398
|
+
*/
|
|
399
|
+
function defaultBindFrom(to) {
|
|
400
|
+
return to.slice(to.lastIndexOf('.') + 1);
|
|
401
|
+
}
|
|
375
402
|
/**
|
|
376
403
|
* Parse a step's `produces` list. Each entry is either a bare pattern string
|
|
377
404
|
* (`plan`, `gather.source[]`), a mapping `{ name, schema, judges, maxAttempts,
|
|
@@ -423,10 +450,29 @@ function parseProduces(v, ctx, baseDir) {
|
|
|
423
450
|
throw new DefError(`produce '${name}'.maxSchemaFailures must be a non-negative number`);
|
|
424
451
|
pat.maxSchemaFailures = v;
|
|
425
452
|
}
|
|
453
|
+
if (raw.bind !== undefined) {
|
|
454
|
+
// bind.from is always a dot-separated object path. When omitted, it
|
|
455
|
+
// defaults to the final segment of bind.to; missing paths are refused.
|
|
456
|
+
if (typeof raw.bind === 'string') {
|
|
457
|
+
pat.bind = { to: raw.bind, from: defaultBindFrom(raw.bind) };
|
|
458
|
+
}
|
|
459
|
+
else if (typeof raw.bind === 'object' && raw.bind !== null && !Array.isArray(raw.bind)) {
|
|
460
|
+
const bind = raw.bind;
|
|
461
|
+
assertNoUnknownKeys(bind, ['to', 'from'], `produce '${name}'.bind`);
|
|
462
|
+
const to = asString(bind.to, `produce '${name}'.bind.to`);
|
|
463
|
+
const from = bind.from === undefined
|
|
464
|
+
? defaultBindFrom(to)
|
|
465
|
+
: asString(bind.from, `produce '${name}'.bind.from`);
|
|
466
|
+
pat.bind = { to, from };
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
throw new DefError(`produce '${name}'.bind must be a string or a { to, from } mapping`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
426
472
|
patterns.push(pat);
|
|
427
473
|
return;
|
|
428
474
|
}
|
|
429
|
-
throw new DefError(`${ctx}[${i}] must be a string or a { name, schema, judges, maxAttempts, maxSchemaFailures } mapping`);
|
|
475
|
+
throw new DefError(`${ctx}[${i}] must be a string or a { name, schema, judges, maxAttempts, maxSchemaFailures, bind } mapping`);
|
|
430
476
|
});
|
|
431
477
|
return { patterns, groups };
|
|
432
478
|
}
|
|
@@ -717,6 +763,12 @@ function prefixStep(step, prefix, defInputs = []) {
|
|
|
717
763
|
// judges: marker names a local stem (unlike calls:, which names an external
|
|
718
764
|
// workflow) — it must be prefixed to keep pointing at the (now-prefixed) produce.
|
|
719
765
|
const newJudges = step.judges !== undefined ? prefixStem(step.judges) : undefined;
|
|
766
|
+
// onCancel consumes name local stems, so they must follow the same prefixing
|
|
767
|
+
// rule as ordinary consumes. Build a fresh object to avoid aliasing a child
|
|
768
|
+
// definition into an expanded parent.
|
|
769
|
+
const newOnCancel = step.onCancel !== undefined
|
|
770
|
+
? { consumes: step.onCancel.consumes.map(prefixStem) }
|
|
771
|
+
: undefined;
|
|
720
772
|
// workdirFrom names a local consumed stem or a declared input of the included
|
|
721
773
|
// definition, followed by a dotted value path. Prefix only the stem; the value
|
|
722
774
|
// path is a field path inside that artifact's value.
|
|
@@ -744,6 +796,8 @@ function prefixStep(step, prefix, defInputs = []) {
|
|
|
744
796
|
result.effect = newEffect;
|
|
745
797
|
if (newJudges !== undefined)
|
|
746
798
|
result.judges = newJudges;
|
|
799
|
+
if (newOnCancel !== undefined)
|
|
800
|
+
result.onCancel = newOnCancel;
|
|
747
801
|
if (newWorkdirFrom !== undefined)
|
|
748
802
|
result.workdirFrom = newWorkdirFrom;
|
|
749
803
|
return result;
|
|
@@ -831,7 +885,20 @@ export function expandIncludes(def, resolve, stack) {
|
|
|
831
885
|
if (parsed && outer !== undefined)
|
|
832
886
|
rewrittenWorkdirFrom = `${outer}.${parsed.path}`;
|
|
833
887
|
}
|
|
834
|
-
|
|
888
|
+
// onCancel consume stems follow ordinary consume rewrites for mapped
|
|
889
|
+
// child inputs; otherwise the expanded step would name a stem it no
|
|
890
|
+
// longer consumes.
|
|
891
|
+
const rewrittenOnCancel = l.onCancel === undefined
|
|
892
|
+
? undefined
|
|
893
|
+
: { consumes: l.onCancel.consumes.map((stem) => inputRewrites.get(stem) ?? stem) };
|
|
894
|
+
const rewrittenStep = {
|
|
895
|
+
...l,
|
|
896
|
+
consumes: rewrittenConsumes,
|
|
897
|
+
workdirFrom: rewrittenWorkdirFrom,
|
|
898
|
+
};
|
|
899
|
+
if (rewrittenOnCancel !== undefined)
|
|
900
|
+
rewrittenStep.onCancel = rewrittenOnCancel;
|
|
901
|
+
return rewrittenStep;
|
|
835
902
|
});
|
|
836
903
|
resultSteps.push(...rewrittenSteps);
|
|
837
904
|
// (g) merge child outputs
|
|
@@ -848,13 +915,23 @@ export function expandIncludes(def, resolve, stack) {
|
|
|
848
915
|
stepIdx++;
|
|
849
916
|
}
|
|
850
917
|
}
|
|
851
|
-
|
|
918
|
+
const expanded = {
|
|
852
919
|
...def,
|
|
853
920
|
steps: resultSteps,
|
|
854
921
|
inputs: resultInputs,
|
|
855
922
|
outputs: resultOutputs.length > 0 ? resultOutputs : def.outputs,
|
|
856
923
|
_includes: undefined,
|
|
857
924
|
};
|
|
925
|
+
// CAS store roots are live loader provenance, deliberately non-enumerable so
|
|
926
|
+
// they never enter hashes or persisted snapshots. The spread above therefore
|
|
927
|
+
// cannot carry them. Preserve the original descriptor explicitly so an
|
|
928
|
+
// include-expanded CAS definition still coordinates its snapshot writes with
|
|
929
|
+
// bundle GC.
|
|
930
|
+
const storeRoots = Object.getOwnPropertyDescriptor(def, 'bundleStoreRoots');
|
|
931
|
+
if (storeRoots !== undefined) {
|
|
932
|
+
Object.defineProperty(expanded, 'bundleStoreRoots', storeRoots);
|
|
933
|
+
}
|
|
934
|
+
return expanded;
|
|
858
935
|
}
|
|
859
936
|
/** Build a validated `WorkflowDef` from a parsed YAML object (or throw DefError). */
|
|
860
937
|
export function parseDef(raw, source, baseDir) {
|
|
@@ -1054,7 +1131,8 @@ function buildStep(rl, i, baseDir) {
|
|
|
1054
1131
|
}
|
|
1055
1132
|
for (const tok of rawOn) {
|
|
1056
1133
|
if (tok !== 'inputsGreen' && tok !== 'allGreen' && tok !== 'idle') {
|
|
1057
|
-
throw new DefError(`step '${name}': on: token '${tok}' is not supported; supported: 'inputsGreen', 'allGreen', 'idle'`
|
|
1134
|
+
throw new DefError(`step '${name}': on: token '${tok}' is not supported; supported: 'inputsGreen', 'allGreen', 'idle'. ` +
|
|
1135
|
+
'Cleanup that must still run when the run is cancelled is declared with the step-level onCancel: key, not a firing trigger.');
|
|
1058
1136
|
}
|
|
1059
1137
|
}
|
|
1060
1138
|
step.on = rawOn;
|
|
@@ -1080,6 +1158,9 @@ function buildStep(rl, i, baseDir) {
|
|
|
1080
1158
|
if (rl.escalation !== undefined) {
|
|
1081
1159
|
step.escalation = parseEscalation(rl.escalation, `step '${name}'.escalation`);
|
|
1082
1160
|
}
|
|
1161
|
+
if (rl.onCancel !== undefined) {
|
|
1162
|
+
step.onCancel = parseOnCancel(rl.onCancel, `step '${name}'.onCancel`);
|
|
1163
|
+
}
|
|
1083
1164
|
// A3: per-step max total lease lifetime (duration string, same as reapTtl).
|
|
1084
1165
|
if (rl.maxLease !== undefined) {
|
|
1085
1166
|
step.maxLeaseMs = parseDurationMs(asString(rl.maxLease, `step '${name}'.maxLease`));
|
|
@@ -1343,7 +1424,7 @@ export function validateDef(def) {
|
|
|
1343
1424
|
for (const tok of l.on) {
|
|
1344
1425
|
if (tok !== 'inputsGreen' && tok !== 'allGreen' && tok !== 'idle') {
|
|
1345
1426
|
errors.push(`step '${l.name}': on: token '${tok}' is not supported; ` +
|
|
1346
|
-
`supported: 'inputsGreen', 'allGreen', 'idle'.`);
|
|
1427
|
+
`supported: 'inputsGreen', 'allGreen', 'idle'. Cleanup that must still run when the run is cancelled is declared with the step-level onCancel: key, not a firing trigger.`);
|
|
1347
1428
|
}
|
|
1348
1429
|
}
|
|
1349
1430
|
}
|
|
@@ -1368,6 +1449,30 @@ export function validateDef(def) {
|
|
|
1368
1449
|
errors.push(`evaluator step ${l.name} (on: allGreen/idle) must not declare consumes; its firings carry no input fingerprint`);
|
|
1369
1450
|
}
|
|
1370
1451
|
}
|
|
1452
|
+
// onCancel: cross-checks. A cancel-path firing is keyless and fires once, so
|
|
1453
|
+
// it can require only the step's own plain consumes.
|
|
1454
|
+
for (const l of def.steps) {
|
|
1455
|
+
if (l.onCancel === undefined)
|
|
1456
|
+
continue;
|
|
1457
|
+
const seen = new Set();
|
|
1458
|
+
for (const stem of l.onCancel.consumes) {
|
|
1459
|
+
if (seen.has(stem)) {
|
|
1460
|
+
errors.push(`step '${l.name}': onCancel.consumes lists '${stem}' more than once`);
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
seen.add(stem);
|
|
1464
|
+
const consume = l.consumes.find((candidate) => candidate.stem === stem);
|
|
1465
|
+
if (consume === undefined) {
|
|
1466
|
+
errors.push(`step '${l.name}': onCancel.consumes names '${stem}', which is not one of the step's consumes ` +
|
|
1467
|
+
`[${l.consumes.map((candidate) => candidate.stem).join(', ')}]`);
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
if (consume.mode !== 'plain') {
|
|
1471
|
+
errors.push(`step '${l.name}': onCancel.consumes names '${stem}', which the step consumes in ${consume.mode} mode ` +
|
|
1472
|
+
`('${consume.raw}'); the cancel-path firing is keyless, so only plain consumes may be listed`);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1371
1476
|
// M2-VALIDATE: calls: step per-def rules.
|
|
1372
1477
|
// Note: cross-def checks (target-def existence, child input-key validity) cannot be done here
|
|
1373
1478
|
// because validateDef is a pure per-def function with no resolver. Those checks live in loadDefs
|
|
@@ -1379,6 +1484,14 @@ export function validateDef(def) {
|
|
|
1379
1484
|
if (l.produces.length !== 1) {
|
|
1380
1485
|
errors.push(`calls: step '${l.name}' must produce exactly one output (got ${l.produces.length})`);
|
|
1381
1486
|
}
|
|
1487
|
+
// A calls: outcome is published by the composition machinery rather than
|
|
1488
|
+
// accepted through green(), so it has no transactional bind write path.
|
|
1489
|
+
// Refuse it at definition load instead of allowing a silently stale route.
|
|
1490
|
+
for (const produce of l.produces) {
|
|
1491
|
+
if (produce.bind !== undefined) {
|
|
1492
|
+
errors.push(`calls: step '${l.name}' produce '${produce.raw}' declares bind, which is not supported on calls: outcomes`);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1382
1495
|
// (b) callsInputs VALUES must be real parent artifacts (inputs or step-produced stems)
|
|
1383
1496
|
for (const [, parentArtifact] of Object.entries(l.callsInputs ?? {})) {
|
|
1384
1497
|
if (!producerOf.has(parentArtifact)) {
|
|
@@ -1472,6 +1585,33 @@ export function validateDef(def) {
|
|
|
1472
1585
|
// "defs without `modifiers:` run exactly as today". Opting into the
|
|
1473
1586
|
// new routing vocabulary is what turns the stricter rule on.
|
|
1474
1587
|
const declaredModifiers = new Set(def.modifiers ?? []);
|
|
1588
|
+
const modifierBinds = [];
|
|
1589
|
+
for (const l of def.steps) {
|
|
1590
|
+
for (const p of l.produces) {
|
|
1591
|
+
const bind = p.bind;
|
|
1592
|
+
if (bind === undefined)
|
|
1593
|
+
continue;
|
|
1594
|
+
if (p.kind === 'collection') {
|
|
1595
|
+
errors.push(`step '${l.name}' produce '${p.raw}' bind is not supported on collection produces`);
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
if (bind.to === 'modifier') {
|
|
1599
|
+
if (declaredModifiers.size === 0) {
|
|
1600
|
+
errors.push(`step '${l.name}' produce '${p.stem}' binds modifier but workflow '${def.name}' declares no modifiers:`);
|
|
1601
|
+
}
|
|
1602
|
+
modifierBinds.push({ step: l.name, artifact: p.stem });
|
|
1603
|
+
}
|
|
1604
|
+
else if (!/^meta\.[A-Za-z_][A-Za-z0-9_-]*$/.test(bind.to)) {
|
|
1605
|
+
errors.push(`step '${l.name}' produce '${p.stem}' bind.to '${bind.to}' must be 'modifier' or 'meta.<key>'`);
|
|
1606
|
+
}
|
|
1607
|
+
if (!/^[A-Za-z_][A-Za-z0-9_-]*(?:\.[A-Za-z_][A-Za-z0-9_-]*)*$/.test(bind.from)) {
|
|
1608
|
+
errors.push(`step '${l.name}' produce '${p.stem}' bind.from '${bind.from}' must be a non-empty dot-path of identifier segments`);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (modifierBinds.length > 1) {
|
|
1613
|
+
errors.push(`workflow '${def.name}' binds modifier more than once: ${modifierBinds.map((b) => `'${b.step}.${b.artifact}'`).join(', ')}`);
|
|
1614
|
+
}
|
|
1475
1615
|
for (const l of def.steps) {
|
|
1476
1616
|
if (l.escalation === undefined)
|
|
1477
1617
|
continue;
|
|
@@ -1705,6 +1845,208 @@ function danglingReduceSuffixWarnings(def) {
|
|
|
1705
1845
|
}
|
|
1706
1846
|
return warnings;
|
|
1707
1847
|
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Whether a consume can receive a value produced by this exact pattern.
|
|
1850
|
+
*
|
|
1851
|
+
* Keeping map suffixes here is essential: `items[$i].review` does not make a
|
|
1852
|
+
* consumer of `items[*].analysis` (or bare `items[*]`) downstream merely
|
|
1853
|
+
* because both lanes share the `items` stem.
|
|
1854
|
+
*/
|
|
1855
|
+
function consumesProducedPattern(consume, produce) {
|
|
1856
|
+
if (consume.stem !== produce.stem)
|
|
1857
|
+
return false;
|
|
1858
|
+
if (produce.kind === 'singleton')
|
|
1859
|
+
return consume.mode === 'plain';
|
|
1860
|
+
if (produce.kind === 'collection') {
|
|
1861
|
+
return consume.mode !== 'plain' && consume.suffix === '';
|
|
1862
|
+
}
|
|
1863
|
+
return consume.mode !== 'plain' && consume.suffix === produce.suffix;
|
|
1864
|
+
}
|
|
1865
|
+
/** Warn when routed work can run before the artifact that writes the modifier. */
|
|
1866
|
+
function unroutedCapabilityWarnings(def) {
|
|
1867
|
+
let bindingStep;
|
|
1868
|
+
let boundArtifact;
|
|
1869
|
+
for (const step of def.steps) {
|
|
1870
|
+
const bound = step.produces.find((p) => p.bind?.to === 'modifier');
|
|
1871
|
+
if (bound !== undefined) {
|
|
1872
|
+
bindingStep = step;
|
|
1873
|
+
boundArtifact = bound;
|
|
1874
|
+
break;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
if (bindingStep === undefined || boundArtifact === undefined)
|
|
1878
|
+
return [];
|
|
1879
|
+
// Forward graph closure from the bound artifact. The binding step itself is
|
|
1880
|
+
// exempt, but its unbound sibling outputs must not make a branch downstream.
|
|
1881
|
+
const reachedSteps = new Set([bindingStep.name]);
|
|
1882
|
+
const reachedArtifacts = [boundArtifact];
|
|
1883
|
+
let changed = true;
|
|
1884
|
+
while (changed) {
|
|
1885
|
+
changed = false;
|
|
1886
|
+
for (const step of def.steps) {
|
|
1887
|
+
if (reachedSteps.has(step.name))
|
|
1888
|
+
continue;
|
|
1889
|
+
if (!step.consumes.some((consume) => reachedArtifacts.some((produce) => consumesProducedPattern(consume, produce))))
|
|
1890
|
+
continue;
|
|
1891
|
+
reachedSteps.add(step.name);
|
|
1892
|
+
reachedArtifacts.push(...step.produces);
|
|
1893
|
+
changed = true;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
const warnings = [];
|
|
1897
|
+
for (const step of def.steps) {
|
|
1898
|
+
if (step.capabilities === undefined || step.capabilities.length === 0)
|
|
1899
|
+
continue;
|
|
1900
|
+
if (reachedSteps.has(step.name))
|
|
1901
|
+
continue;
|
|
1902
|
+
warnings.push(`step '${step.name}' declares capabilities (${step.capabilities.join(', ')}) but is not downstream of artifact '${boundArtifact.raw}' bound to modifier`);
|
|
1903
|
+
}
|
|
1904
|
+
return warnings;
|
|
1905
|
+
}
|
|
1906
|
+
/** Whether a discovery-convention value is a YAML mapping. */
|
|
1907
|
+
function isDiscoveryMap(value) {
|
|
1908
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Return advisory issues for Owenloop's optional x.discovery convention.
|
|
1912
|
+
*
|
|
1913
|
+
* This deliberately does not assign a severity. W2.1 can promote these same
|
|
1914
|
+
* deterministic issues for library definitions without duplicating validation.
|
|
1915
|
+
* The parser and engine continue to treat all extension contents as opaque.
|
|
1916
|
+
*/
|
|
1917
|
+
function discoveryIssues(def) {
|
|
1918
|
+
const issues = [];
|
|
1919
|
+
const discovery = def.x?.discovery;
|
|
1920
|
+
if (discovery === undefined)
|
|
1921
|
+
return ['x.discovery: missing required discovery metadata'];
|
|
1922
|
+
if (!isDiscoveryMap(discovery))
|
|
1923
|
+
return ['x.discovery: expected a map'];
|
|
1924
|
+
const requiredString = (value, path) => {
|
|
1925
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
1926
|
+
issues.push(path + ': expected a non-empty string');
|
|
1927
|
+
return undefined;
|
|
1928
|
+
}
|
|
1929
|
+
return value;
|
|
1930
|
+
};
|
|
1931
|
+
const requiredPhraseList = (value, path) => {
|
|
1932
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
1933
|
+
issues.push(path + ': expected a non-empty array of non-empty strings');
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1936
|
+
for (const [index, item] of value.entries())
|
|
1937
|
+
requiredString(item, path + '[' + index + ']');
|
|
1938
|
+
};
|
|
1939
|
+
/**
|
|
1940
|
+
* Validate a mapping in the order its fields were authored. Required
|
|
1941
|
+
* fields absent from the mapping follow in the convention's fixed order,
|
|
1942
|
+
* making both kinds of diagnostic deterministic.
|
|
1943
|
+
*/
|
|
1944
|
+
const visitMapFields = (value, allowed, path, visitKnownField) => {
|
|
1945
|
+
const allowedSet = new Set(allowed);
|
|
1946
|
+
const present = new Set();
|
|
1947
|
+
for (const key of Object.keys(value)) {
|
|
1948
|
+
if (!allowedSet.has(key)) {
|
|
1949
|
+
issues.push(path + '.' + key + ': unknown field');
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
present.add(key);
|
|
1953
|
+
visitKnownField(key, value[key]);
|
|
1954
|
+
}
|
|
1955
|
+
for (const key of allowed)
|
|
1956
|
+
if (!present.has(key))
|
|
1957
|
+
visitKnownField(key, undefined);
|
|
1958
|
+
};
|
|
1959
|
+
const inputs = new Map(def.inputs.map((input) => [input.name, { schema: input.schema }]));
|
|
1960
|
+
const outputs = new Map((def.outputs ?? []).map((name) => {
|
|
1961
|
+
const artifact = def.steps.flatMap((step) => [...step.produces, ...(step.generates ?? [])])
|
|
1962
|
+
.find((produce) => produce.stem === name);
|
|
1963
|
+
return [name, { schema: artifact?.schema }];
|
|
1964
|
+
}));
|
|
1965
|
+
const validateInterfaceEntries = (value, path, declared) => {
|
|
1966
|
+
const fieldPath = 'x.discovery.interface.' + path;
|
|
1967
|
+
const singular = path === 'inputs' ? 'input' : 'output';
|
|
1968
|
+
if (!Array.isArray(value)) {
|
|
1969
|
+
issues.push(fieldPath + ': expected an array');
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
const seen = new Set();
|
|
1973
|
+
for (const [index, entry] of value.entries()) {
|
|
1974
|
+
const entryPath = fieldPath + '[' + index + ']';
|
|
1975
|
+
if (!isDiscoveryMap(entry)) {
|
|
1976
|
+
issues.push(entryPath + ': expected a map');
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
visitMapFields(entry, ['name', 'summary', 'schemaRef'], entryPath, (key, fieldValue) => {
|
|
1980
|
+
switch (key) {
|
|
1981
|
+
case 'name': {
|
|
1982
|
+
const name = requiredString(fieldValue, entryPath + '.name');
|
|
1983
|
+
if (name === undefined)
|
|
1984
|
+
break;
|
|
1985
|
+
// Record every non-blank name before declaration lookup. This
|
|
1986
|
+
// preserves both useful findings for repeated unknown names.
|
|
1987
|
+
if (seen.has(name)) {
|
|
1988
|
+
issues.push(entryPath + '.name: duplicate workflow ' + singular + " '" + name + "'");
|
|
1989
|
+
}
|
|
1990
|
+
else {
|
|
1991
|
+
seen.add(name);
|
|
1992
|
+
}
|
|
1993
|
+
const artifact = declared.get(name);
|
|
1994
|
+
if (artifact === undefined) {
|
|
1995
|
+
issues.push(entryPath + '.name: unknown workflow ' + singular + " '" + name + "'");
|
|
1996
|
+
}
|
|
1997
|
+
else if (artifact.schema === undefined) {
|
|
1998
|
+
issues.push(entryPath + '.schemaRef: workflow ' + singular + " '" + name + "' has no schema");
|
|
1999
|
+
}
|
|
2000
|
+
break;
|
|
2001
|
+
}
|
|
2002
|
+
case 'summary':
|
|
2003
|
+
requiredString(fieldValue, entryPath + '.summary');
|
|
2004
|
+
break;
|
|
2005
|
+
case 'schemaRef': {
|
|
2006
|
+
const schemaRef = requiredString(fieldValue, entryPath + '.schemaRef');
|
|
2007
|
+
if (schemaRef !== undefined && !schemaRef.startsWith('#/')) {
|
|
2008
|
+
issues.push(entryPath + '.schemaRef: expected a local JSON pointer starting with \'#/\'');
|
|
2009
|
+
}
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
for (const name of declared.keys()) {
|
|
2016
|
+
if (!seen.has(name))
|
|
2017
|
+
issues.push(fieldPath + ': missing workflow ' + singular + " '" + name + "'");
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
const validateInterface = (value) => {
|
|
2021
|
+
if (!isDiscoveryMap(value)) {
|
|
2022
|
+
issues.push('x.discovery.interface: expected a map');
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
visitMapFields(value, ['inputs', 'outputs'], 'x.discovery.interface', (key, fieldValue) => {
|
|
2026
|
+
if (key === 'inputs')
|
|
2027
|
+
validateInterfaceEntries(fieldValue, 'inputs', inputs);
|
|
2028
|
+
else
|
|
2029
|
+
validateInterfaceEntries(fieldValue, 'outputs', outputs);
|
|
2030
|
+
});
|
|
2031
|
+
};
|
|
2032
|
+
visitMapFields(discovery, ['description', 'whenToUse', 'notFor', 'interface'], 'x.discovery', (key, value) => {
|
|
2033
|
+
switch (key) {
|
|
2034
|
+
case 'description':
|
|
2035
|
+
requiredString(value, 'x.discovery.description');
|
|
2036
|
+
break;
|
|
2037
|
+
case 'whenToUse':
|
|
2038
|
+
requiredPhraseList(value, 'x.discovery.whenToUse');
|
|
2039
|
+
break;
|
|
2040
|
+
case 'notFor':
|
|
2041
|
+
requiredPhraseList(value, 'x.discovery.notFor');
|
|
2042
|
+
break;
|
|
2043
|
+
case 'interface':
|
|
2044
|
+
validateInterface(value);
|
|
2045
|
+
break;
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
return issues;
|
|
2049
|
+
}
|
|
1708
2050
|
/**
|
|
1709
2051
|
* Static lint over a workflow definition. Returns both the hard errors from
|
|
1710
2052
|
* `validateDef` (which `parseDef` / `loadDefFile` would throw on) and
|
|
@@ -1718,10 +2060,17 @@ function danglingReduceSuffixWarnings(def) {
|
|
|
1718
2060
|
export function lintDef(def) {
|
|
1719
2061
|
const errors = validateDef(def);
|
|
1720
2062
|
const warnings = errors.length === 0
|
|
1721
|
-
? [...deadEndWarnings(def), ...danglingReduceSuffixWarnings(def)]
|
|
2063
|
+
? [...deadEndWarnings(def), ...danglingReduceSuffixWarnings(def), ...unroutedCapabilityWarnings(def), ...discoveryIssues(def)]
|
|
1722
2064
|
: [];
|
|
1723
2065
|
return { errors, warnings };
|
|
1724
2066
|
}
|
|
2067
|
+
/**
|
|
2068
|
+
* The steps a def declares as cleanup-on-cancel, in definition order. The
|
|
2069
|
+
* control plane calls this when it cancels a run.
|
|
2070
|
+
*/
|
|
2071
|
+
export function cancelCleanupSteps(def) {
|
|
2072
|
+
return def.steps.filter((step) => step.onCancel !== undefined);
|
|
2073
|
+
}
|
|
1725
2074
|
// ---- WS-6: scope-aware calls: target resolution -------------------------------
|
|
1726
2075
|
/** Stable private-map key for one installed coordinate at one verified digest. */
|
|
1727
2076
|
export function digestScopedCallsTargetKey(digest, target) {
|
|
@@ -1787,49 +2136,195 @@ export function resolveCallsTarget(defs, target, from) {
|
|
|
1787
2136
|
const key = resolveCallsTargetKey(defs, target, from);
|
|
1788
2137
|
return key === undefined ? undefined : defs.get(key);
|
|
1789
2138
|
}
|
|
1790
|
-
|
|
2139
|
+
function buildCallsGraph(defs) {
|
|
2140
|
+
const keys = [...defs.keys()];
|
|
2141
|
+
const edges = new Map();
|
|
2142
|
+
for (const [key, def] of defs) {
|
|
2143
|
+
// WS-6: graph nodes are RESOLVED map keys, not bare calls text. Two bundles
|
|
2144
|
+
// may both export `build` without being fused into one graph node.
|
|
2145
|
+
const children = new Set();
|
|
2146
|
+
for (const step of def.steps) {
|
|
2147
|
+
if (step.calls === undefined)
|
|
2148
|
+
continue;
|
|
2149
|
+
const child = resolveCallsTargetKey(defs, step.calls, def);
|
|
2150
|
+
if (child !== undefined)
|
|
2151
|
+
children.add(child);
|
|
2152
|
+
}
|
|
2153
|
+
edges.set(key, [...children]);
|
|
2154
|
+
}
|
|
2155
|
+
return {
|
|
2156
|
+
keys,
|
|
2157
|
+
order: new Map(keys.map((key, index) => [key, index])),
|
|
2158
|
+
edges,
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
1791
2161
|
/**
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1794
|
-
*
|
|
1795
|
-
*
|
|
1796
|
-
* Called from loadDefs Phase 2 after all defs are expanded and per-def validated.
|
|
2162
|
+
* Preserve the original tri-color DFS exactly for strict loading. It stops at
|
|
2163
|
+
* the first back edge, so finalizeDefs remains O(V+E) and retains its stable
|
|
2164
|
+
* first-cycle message and traversal precedence.
|
|
1797
2165
|
*/
|
|
1798
|
-
function
|
|
2166
|
+
function findFirstCallsCycle(graph) {
|
|
1799
2167
|
const WHITE = 0, GREY = 1, BLACK = 2;
|
|
1800
|
-
const color = new Map(
|
|
2168
|
+
const color = new Map(graph.keys.map((key) => [key, WHITE]));
|
|
1801
2169
|
const stack = [];
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
const callsEdges = new Set((def?.steps ?? []).filter((l) => l.calls).map((l) => l.calls));
|
|
1814
|
-
for (const edge of callsEdges) {
|
|
1815
|
-
const child = def === undefined ? undefined : resolveCallsTargetKey(defs, edge, def);
|
|
1816
|
-
if (child === undefined)
|
|
1817
|
-
continue; // missing-def error is reported separately in loadDefs
|
|
1818
|
-
const c = color.get(child) ?? WHITE;
|
|
1819
|
-
if (c === GREY) {
|
|
1820
|
-
const from = stack.indexOf(child);
|
|
1821
|
-
throw new DefError(`calls cycle: ${[...stack.slice(from), child].join(' -> ')}`);
|
|
2170
|
+
const visit = (key) => {
|
|
2171
|
+
color.set(key, GREY);
|
|
2172
|
+
stack.push(key);
|
|
2173
|
+
for (const child of graph.edges.get(key) ?? []) {
|
|
2174
|
+
const state = color.get(child) ?? WHITE;
|
|
2175
|
+
if (state === GREY)
|
|
2176
|
+
return [...stack.slice(stack.indexOf(child)), child];
|
|
2177
|
+
if (state === WHITE) {
|
|
2178
|
+
const found = visit(child);
|
|
2179
|
+
if (found !== undefined)
|
|
2180
|
+
return found;
|
|
1822
2181
|
}
|
|
1823
|
-
if (c === WHITE)
|
|
1824
|
-
visit(child);
|
|
1825
2182
|
}
|
|
1826
2183
|
stack.pop();
|
|
1827
|
-
color.set(
|
|
2184
|
+
color.set(key, BLACK);
|
|
2185
|
+
return undefined;
|
|
1828
2186
|
};
|
|
1829
|
-
for (const
|
|
1830
|
-
if ((color.get(
|
|
1831
|
-
|
|
2187
|
+
for (const key of graph.keys) {
|
|
2188
|
+
if ((color.get(key) ?? WHITE) !== WHITE)
|
|
2189
|
+
continue;
|
|
2190
|
+
const found = visit(key);
|
|
2191
|
+
if (found !== undefined)
|
|
2192
|
+
return found;
|
|
1832
2193
|
}
|
|
2194
|
+
return undefined;
|
|
2195
|
+
}
|
|
2196
|
+
function cycleFingerprint(cycle) {
|
|
2197
|
+
const members = cycle.slice(0, -1);
|
|
2198
|
+
return members
|
|
2199
|
+
.map((_, index) => [...members.slice(index), ...members.slice(0, index)].join('\u0000'))
|
|
2200
|
+
.sort()[0] ?? '';
|
|
2201
|
+
}
|
|
2202
|
+
function canonicalizeCycle(cycle, order) {
|
|
2203
|
+
const members = cycle.slice(0, -1);
|
|
2204
|
+
let first = 0;
|
|
2205
|
+
for (let index = 1; index < members.length; index++) {
|
|
2206
|
+
if ((order.get(members[index]) ?? Number.MAX_SAFE_INTEGER) < (order.get(members[first]) ?? Number.MAX_SAFE_INTEGER)) {
|
|
2207
|
+
first = index;
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
const rotated = [...members.slice(first), ...members.slice(0, first)];
|
|
2211
|
+
return [...rotated, rotated[0]];
|
|
2212
|
+
}
|
|
2213
|
+
/** Return each cyclic SCC, indexed by every member, using deterministic Tarjan traversal. */
|
|
2214
|
+
function cyclicComponentsByMember(graph) {
|
|
2215
|
+
let nextIndex = 0;
|
|
2216
|
+
const index = new Map();
|
|
2217
|
+
const lowlink = new Map();
|
|
2218
|
+
const stack = [];
|
|
2219
|
+
const onStack = new Set();
|
|
2220
|
+
const byMember = new Map();
|
|
2221
|
+
const visit = (key) => {
|
|
2222
|
+
index.set(key, nextIndex);
|
|
2223
|
+
lowlink.set(key, nextIndex);
|
|
2224
|
+
nextIndex++;
|
|
2225
|
+
stack.push(key);
|
|
2226
|
+
onStack.add(key);
|
|
2227
|
+
for (const child of graph.edges.get(key) ?? []) {
|
|
2228
|
+
if (!index.has(child)) {
|
|
2229
|
+
visit(child);
|
|
2230
|
+
lowlink.set(key, Math.min(lowlink.get(key), lowlink.get(child)));
|
|
2231
|
+
}
|
|
2232
|
+
else if (onStack.has(child)) {
|
|
2233
|
+
lowlink.set(key, Math.min(lowlink.get(key), index.get(child)));
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
if (lowlink.get(key) !== index.get(key))
|
|
2237
|
+
return;
|
|
2238
|
+
const members = [];
|
|
2239
|
+
while (stack.length > 0) {
|
|
2240
|
+
const member = stack.pop();
|
|
2241
|
+
onStack.delete(member);
|
|
2242
|
+
members.push(member);
|
|
2243
|
+
if (member === key)
|
|
2244
|
+
break;
|
|
2245
|
+
}
|
|
2246
|
+
const cyclic = members.length > 1 || (graph.edges.get(key) ?? []).includes(key);
|
|
2247
|
+
if (!cyclic)
|
|
2248
|
+
return;
|
|
2249
|
+
const component = new Set(members);
|
|
2250
|
+
for (const member of members)
|
|
2251
|
+
byMember.set(member, component);
|
|
2252
|
+
};
|
|
2253
|
+
for (const key of graph.keys) {
|
|
2254
|
+
if (!index.has(key))
|
|
2255
|
+
visit(key);
|
|
2256
|
+
}
|
|
2257
|
+
return byMember;
|
|
2258
|
+
}
|
|
2259
|
+
/** Find one deterministic simple cycle through member inside its cyclic SCC. */
|
|
2260
|
+
function cycleThroughMember(member, component, graph) {
|
|
2261
|
+
const pathBack = (key, target, path, seen) => {
|
|
2262
|
+
for (const child of graph.edges.get(key) ?? []) {
|
|
2263
|
+
if (!component.has(child))
|
|
2264
|
+
continue;
|
|
2265
|
+
if (child === target)
|
|
2266
|
+
return [...path, child];
|
|
2267
|
+
if (seen.has(child))
|
|
2268
|
+
continue;
|
|
2269
|
+
seen.add(child);
|
|
2270
|
+
const found = pathBack(child, target, [...path, child], seen);
|
|
2271
|
+
if (found !== undefined)
|
|
2272
|
+
return found;
|
|
2273
|
+
}
|
|
2274
|
+
return undefined;
|
|
2275
|
+
};
|
|
2276
|
+
for (const child of graph.edges.get(member) ?? []) {
|
|
2277
|
+
if (!component.has(child))
|
|
2278
|
+
continue;
|
|
2279
|
+
if (child === member)
|
|
2280
|
+
return [member, member];
|
|
2281
|
+
const found = pathBack(child, member, [child], new Set([member, child]));
|
|
2282
|
+
if (found !== undefined)
|
|
2283
|
+
return [member, ...found];
|
|
2284
|
+
}
|
|
2285
|
+
return undefined;
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Report calls cycles in a flat def map. This is the Mode 2 analogue of the
|
|
2289
|
+
* Mode 1 include-cycle guard in expandIncludes; the two edge kinds stay
|
|
2290
|
+
* deliberately separate. Findings use resolved map identity, not bare call
|
|
2291
|
+
* text, so CAS bundle siblings cannot be accidentally fused. The first finding
|
|
2292
|
+
* is strict loading's legacy DFS witness. Further findings add at most one
|
|
2293
|
+
* deterministic witness for each still-unattributed cyclic member, keeping
|
|
2294
|
+
* authoring attribution polynomial and every finding's members consistent with
|
|
2295
|
+
* its displayed path without enumerating exponentially many simple cycles.
|
|
2296
|
+
*/
|
|
2297
|
+
export function reportCallsCycles(defs) {
|
|
2298
|
+
const graph = buildCallsGraph(defs);
|
|
2299
|
+
const first = findFirstCallsCycle(graph);
|
|
2300
|
+
if (first === undefined)
|
|
2301
|
+
return [];
|
|
2302
|
+
const cycles = [first];
|
|
2303
|
+
const seen = new Set([cycleFingerprint(first)]);
|
|
2304
|
+
const attributed = new Set(first.slice(0, -1));
|
|
2305
|
+
const components = cyclicComponentsByMember(graph);
|
|
2306
|
+
for (const member of graph.keys) {
|
|
2307
|
+
if (attributed.has(member))
|
|
2308
|
+
continue;
|
|
2309
|
+
const component = components.get(member);
|
|
2310
|
+
if (component === undefined)
|
|
2311
|
+
continue;
|
|
2312
|
+
const witness = cycleThroughMember(member, component, graph);
|
|
2313
|
+
if (witness === undefined)
|
|
2314
|
+
continue; // unreachable for a member of a cyclic SCC
|
|
2315
|
+
const cycle = canonicalizeCycle(witness, graph.order);
|
|
2316
|
+
for (const cycleMember of cycle.slice(0, -1))
|
|
2317
|
+
attributed.add(cycleMember);
|
|
2318
|
+
const fingerprint = cycleFingerprint(cycle);
|
|
2319
|
+
if (seen.has(fingerprint))
|
|
2320
|
+
continue;
|
|
2321
|
+
seen.add(fingerprint);
|
|
2322
|
+
cycles.push(cycle);
|
|
2323
|
+
}
|
|
2324
|
+
return cycles.map((cycle) => ({
|
|
2325
|
+
message: `calls cycle: ${cycle.join(' -> ')}`,
|
|
2326
|
+
members: cycle.slice(0, -1),
|
|
2327
|
+
}));
|
|
1833
2328
|
}
|
|
1834
2329
|
// ---- filesystem loading ------------------------------------------------------
|
|
1835
2330
|
/** Load and validate a single workflow definition from a YAML file. */
|
|
@@ -1908,51 +2403,59 @@ export function loadDefsUnfinalized(dir) {
|
|
|
1908
2403
|
}
|
|
1909
2404
|
return raw;
|
|
1910
2405
|
}
|
|
2406
|
+
/**
|
|
2407
|
+
* Return every direct cross-definition `calls:` error for one expanded
|
|
2408
|
+
* definition. Strict loading uses the first result to retain its historical
|
|
2409
|
+
* throw behavior; tolerant authoring commands can present the complete list.
|
|
2410
|
+
*/
|
|
2411
|
+
export function validateCallsEdges(def, defs, options = {}) {
|
|
2412
|
+
const errors = [];
|
|
2413
|
+
for (const step of def.steps) {
|
|
2414
|
+
if (!step.calls)
|
|
2415
|
+
continue;
|
|
2416
|
+
const childDef = resolveCallsTarget(defs, step.calls, def);
|
|
2417
|
+
if (!childDef) {
|
|
2418
|
+
if (options.allowUnresolvedCalls !== true
|
|
2419
|
+
&& options.allowUnresolvedVersionedCalls?.has(step.calls) !== true) {
|
|
2420
|
+
errors.push(`calls names workflow '${step.calls}' which does not exist`);
|
|
2421
|
+
}
|
|
2422
|
+
continue;
|
|
2423
|
+
}
|
|
2424
|
+
const childInputNames = new Set(childDef.inputs.map((input) => input.name));
|
|
2425
|
+
for (const key of Object.keys(step.callsInputs ?? {})) {
|
|
2426
|
+
if (!childInputNames.has(key)) {
|
|
2427
|
+
errors.push(`calls '${step.name}' maps input '${key}' which workflow '${step.calls}' does not declare`);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
const childOutputs = childDef.outputs ?? [];
|
|
2431
|
+
if (childOutputs.length === 0) {
|
|
2432
|
+
errors.push(`calls names workflow '${step.calls}' which declares no outputs:`);
|
|
2433
|
+
}
|
|
2434
|
+
if (childOutputs.length > 1) {
|
|
2435
|
+
errors.push(`calls names workflow '${step.calls}' which declares ${childOutputs.length} outputs:, calls: v1 requires exactly one`);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
return errors;
|
|
2439
|
+
}
|
|
1911
2440
|
export function finalizeDefs(raw, options = {}) {
|
|
1912
2441
|
const out = new Map();
|
|
1913
2442
|
const resolver = (name) => raw.get(name);
|
|
1914
2443
|
for (const [name, def] of raw) {
|
|
1915
2444
|
const expanded = expandIncludes(def, resolver);
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
// WS-6: `calls:` targets resolve through `resolveCallsTarget` (scope-aware),
|
|
1920
|
-
// NOT through the plain `resolver` used for `include:` expansion above.
|
|
1921
|
-
// `include:` is a DIFFERENT edge kind and is deliberately left on the flat
|
|
1922
|
-
// lookup — this workstream is `calls:`-only.
|
|
1923
|
-
for (const l of expanded.steps) {
|
|
1924
|
-
if (!l.calls)
|
|
1925
|
-
continue;
|
|
1926
|
-
const childDef = resolveCallsTarget(raw, l.calls, expanded);
|
|
1927
|
-
if (!childDef) {
|
|
1928
|
-
if (options.allowUnresolvedCalls === true
|
|
1929
|
-
|| options.allowUnresolvedVersionedCalls?.has(l.calls) === true)
|
|
1930
|
-
continue;
|
|
1931
|
-
throw new DefError(`calls names workflow '${l.calls}' which does not exist`);
|
|
1932
|
-
}
|
|
1933
|
-
const childInputNames = new Set(childDef.inputs.map((i) => i.name));
|
|
1934
|
-
for (const k of Object.keys(l.callsInputs ?? {})) {
|
|
1935
|
-
if (!childInputNames.has(k)) {
|
|
1936
|
-
throw new DefError(`calls '${l.name}' maps input '${k}' which workflow '${l.calls}' does not declare`);
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
// M2B-OUTCOME v1: the called workflow must declare exactly one output.
|
|
1940
|
-
const childOutputs = childDef.outputs ?? [];
|
|
1941
|
-
if (childOutputs.length === 0) {
|
|
1942
|
-
throw new DefError(`calls names workflow '${l.calls}' which declares no outputs:`);
|
|
1943
|
-
}
|
|
1944
|
-
if (childOutputs.length > 1) {
|
|
1945
|
-
throw new DefError(`calls names workflow '${l.calls}' which declares ${childOutputs.length} outputs:, calls: v1 requires exactly one`);
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
2445
|
+
const callsErrors = validateCallsEdges(expanded, raw, options);
|
|
2446
|
+
if (callsErrors.length > 0)
|
|
2447
|
+
throw new DefError(callsErrors[0]);
|
|
1948
2448
|
const errors = validateDef(expanded);
|
|
1949
2449
|
if (errors.length) {
|
|
1950
2450
|
throw new DefError(`invalid workflow '${name}' (${def.dir ?? 'unknown'}):\n - ${errors.join('\n - ')}`);
|
|
1951
2451
|
}
|
|
1952
2452
|
out.set(name, expanded);
|
|
1953
2453
|
}
|
|
1954
|
-
//
|
|
1955
|
-
|
|
2454
|
+
// Preserve strict loading's first, stable cycle error after all per-def checks
|
|
2455
|
+
// without paying the wider authoring reporter's per-member attribution cost.
|
|
2456
|
+
const cycle = findFirstCallsCycle(buildCallsGraph(out));
|
|
2457
|
+
if (cycle !== undefined)
|
|
2458
|
+
throw new DefError(`calls cycle: ${cycle.join(' -> ')}`);
|
|
1956
2459
|
return out;
|
|
1957
2460
|
}
|
|
1958
2461
|
/**
|
|
@@ -1964,7 +2467,7 @@ export function finalizeDefs(raw, options = {}) {
|
|
|
1964
2467
|
* Two-phase: Phase 1 collects all defs. Phase 2 expands includes best-effort
|
|
1965
2468
|
* (silently skips expansion failures so the lint caller sees un-expanded defs).
|
|
1966
2469
|
*/
|
|
1967
|
-
export function
|
|
2470
|
+
export function scanDefsRaw(dir, failures) {
|
|
1968
2471
|
// Phase 1: build all defs, skipping (and recording) malformed files.
|
|
1969
2472
|
const raw = new Map();
|
|
1970
2473
|
const tryAdd = (file) => {
|
|
@@ -1994,7 +2497,10 @@ export function loadDefsRaw(dir, failures) {
|
|
|
1994
2497
|
tryAdd(full);
|
|
1995
2498
|
}
|
|
1996
2499
|
}
|
|
1997
|
-
|
|
2500
|
+
return raw;
|
|
2501
|
+
}
|
|
2502
|
+
/** Best-effort include expansion for a complete, already-merged raw map. */
|
|
2503
|
+
export function expandDefsRaw(raw) {
|
|
1998
2504
|
const out = new Map();
|
|
1999
2505
|
const resolver = (name) => raw.get(name);
|
|
2000
2506
|
for (const [name, def] of raw) {
|
|
@@ -2007,12 +2513,13 @@ export function loadDefsRaw(dir, failures) {
|
|
|
2007
2513
|
out.set(name, def);
|
|
2008
2514
|
}
|
|
2009
2515
|
}
|
|
2010
|
-
// M2-CYCLE: best-effort calls-cycle check so lint can surface cycle errors.
|
|
2011
|
-
try {
|
|
2012
|
-
detectCallsCycles(out);
|
|
2013
|
-
}
|
|
2014
|
-
catch {
|
|
2015
|
-
// Cycle errors are surfaced via validateDef in the lint caller; swallow here.
|
|
2016
|
-
}
|
|
2017
2516
|
return out;
|
|
2018
2517
|
}
|
|
2518
|
+
/**
|
|
2519
|
+
* Compatibility wrapper for tolerant single-directory loading. Raw loading
|
|
2520
|
+
* builds and expands includes best-effort; callers explicitly invoke shared
|
|
2521
|
+
* calls validation and cycle reporting against the complete definition map.
|
|
2522
|
+
*/
|
|
2523
|
+
export function loadDefsRaw(dir, failures) {
|
|
2524
|
+
return expandDefsRaw(scanDefsRaw(dir, failures));
|
|
2525
|
+
}
|