@parcha/agentrun-dsl 0.1.0-beta.257 → 0.1.0-beta.259
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/dist/workflow.js +95 -25
- package/package.json +1 -1
package/dist/workflow.js
CHANGED
|
@@ -485,11 +485,17 @@ export function validateWorkflow(workflow, opts) {
|
|
|
485
485
|
// real input. Derived keys run no authored code: a code node is not probed, as without keys.
|
|
486
486
|
const derived = opts?.input === undefined && opts?.inputKeys === undefined && isRecord(declaredInput) && isRecord(declaredInput.properties);
|
|
487
487
|
const inputKeys = opts?.input !== undefined ? Object.keys(opts.input ?? {}) : opts?.inputKeys ?? (derived ? Object.keys(declaredInput.properties) : undefined);
|
|
488
|
-
|
|
488
|
+
// `past` is set once the walk is inside or past a map or a loop, where these checks used to stop: what they find there
|
|
489
|
+
// is a warning in every mode, never a refusal. `prior` holds what an enclosing loop's body writes: a later pass reads it.
|
|
490
|
+
const reachability = inputKeys ? { available: new Set(inputKeys), unknowable: false, past: false, prior: new Set() } : null;
|
|
491
|
+
/** Whether a read of `key` here may find it: written before, or by an enclosing loop's earlier pass. */
|
|
492
|
+
const reached = (key) => !!reachability && (reachability.available.has(key) || reachability.prior.has(key));
|
|
489
493
|
const derivedWarnings = [];
|
|
490
|
-
/** A finding of the reachability checks: an error with the input keys given, a warning with derived ones
|
|
491
|
-
|
|
492
|
-
|
|
494
|
+
/** A finding of the reachability checks: an error with the input keys given, a warning with derived ones or `past` a
|
|
495
|
+
* map or a loop. The checks that never stopped at a map or a loop (an artifact's file, a predicate against a code
|
|
496
|
+
* node's shape, the output's required fields) pass `past` false and keep their severity. */
|
|
497
|
+
const unreached = (code, path, message, past = reachability?.past ?? false) => {
|
|
498
|
+
if (derived || past)
|
|
493
499
|
derivedWarnings.push(formatPointerWarning(code, path, message));
|
|
494
500
|
else
|
|
495
501
|
fail(code, path, message);
|
|
@@ -532,6 +538,14 @@ export function validateWorkflow(workflow, opts) {
|
|
|
532
538
|
return;
|
|
533
539
|
}
|
|
534
540
|
};
|
|
541
|
+
/** The schema a typed producer declares at `dotted`, through objects' declared properties only. */
|
|
542
|
+
const schemaAt = (dotted) => {
|
|
543
|
+
const [head, ...tail] = dotted.split(".");
|
|
544
|
+
let schema = typedOutputs.get(head);
|
|
545
|
+
for (const segment of tail)
|
|
546
|
+
schema = isRecord(schema) && schema.type === "object" && isRecord(schema.properties) && Object.hasOwn(schema.properties, segment) ? schema.properties[segment] : undefined;
|
|
547
|
+
return isRecord(schema) ? schema : undefined;
|
|
548
|
+
};
|
|
535
549
|
const probedSubtrees = new Map();
|
|
536
550
|
const producedFiles = new Set();
|
|
537
551
|
let mayEscalate = false;
|
|
@@ -635,7 +649,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
635
649
|
return patches;
|
|
636
650
|
};
|
|
637
651
|
const snapshotKnowledge = () => ({
|
|
638
|
-
available: reachability ? new Set(reachability.available) : null, unknowable: reachability?.unknowable ?? true,
|
|
652
|
+
available: reachability ? new Set(reachability.available) : null, unknowable: reachability?.unknowable ?? true, past: reachability?.past ?? false,
|
|
639
653
|
typed: new Map(typedOutputs), probed: new Map([...probedSubtrees].map(([key, values]) => [key, [...values]])),
|
|
640
654
|
spread: new Set(spreadTaintedKeys), files: new Set(producedFiles),
|
|
641
655
|
});
|
|
@@ -643,6 +657,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
643
657
|
if (reachability && knowledge.available) {
|
|
644
658
|
reachability.available = new Set(knowledge.available);
|
|
645
659
|
reachability.unknowable = knowledge.unknowable;
|
|
660
|
+
reachability.past = knowledge.past;
|
|
646
661
|
}
|
|
647
662
|
typedOutputs.clear();
|
|
648
663
|
for (const [key, value] of knowledge.typed)
|
|
@@ -680,8 +695,10 @@ export function validateWorkflow(workflow, opts) {
|
|
|
680
695
|
}
|
|
681
696
|
// Every branch runs, so the state after holds what each one writes: the check goes on past the parallel, unless the state
|
|
682
697
|
// before it, or a branch's own, is not known (a code node's keys are probed, not known).
|
|
683
|
-
if (reachability)
|
|
698
|
+
if (reachability) {
|
|
684
699
|
reachability.unknowable = before.unknowable || branches.some((branch) => branch.unknowable);
|
|
700
|
+
reachability.past = before.past || branches.some((branch) => branch.past);
|
|
701
|
+
}
|
|
685
702
|
};
|
|
686
703
|
/** After a route node: one branch runs, so the state after holds what every branch leaves. A key some branch may not leave
|
|
687
704
|
* is not known; a key's shape is kept only when every branch leaves the same one. A file any branch produces is counted, as
|
|
@@ -690,6 +707,8 @@ export function validateWorkflow(workflow, opts) {
|
|
|
690
707
|
restoreKnowledge(before);
|
|
691
708
|
if (!branches.length)
|
|
692
709
|
return;
|
|
710
|
+
if (reachability)
|
|
711
|
+
reachability.past = before.past || branches.some((branch) => branch.past);
|
|
693
712
|
if (reachability && branches.every((branch) => branch.available)) {
|
|
694
713
|
reachability.available = new Set([...branches[0].available].filter((key) => branches.every((branch) => branch.available.has(key))));
|
|
695
714
|
reachability.unknowable = before.unknowable || branches.some((branch) => branch.unknowable);
|
|
@@ -740,14 +759,14 @@ export function validateWorkflow(workflow, opts) {
|
|
|
740
759
|
if (!missing)
|
|
741
760
|
return;
|
|
742
761
|
}
|
|
743
|
-
unreached("STATE_PATH_EXCLUDED", ptrOf(path), `${path} (${label}): predicate path "${when.path}" is not produced by the code node that writes "${head}" (its shape has: ${missingAt && typeof missingAt === "object" ? Object.keys(missingAt).join(", ") : typeof missingAt}); the guard can never fire
|
|
762
|
+
unreached("STATE_PATH_EXCLUDED", ptrOf(path), `${path} (${label}): predicate path "${when.path}" is not produced by the code node that writes "${head}" (its shape has: ${missingAt && typeof missingAt === "object" ? Object.keys(missingAt).join(", ") : typeof missingAt}); the guard can never fire`, false);
|
|
744
763
|
};
|
|
745
764
|
// A mechanical predicate reads one state key; when no input key or earlier node writes it, the guard can never fire.
|
|
746
765
|
const checkPredicateHead = (pred, label, path, field, produced) => {
|
|
747
766
|
pred = negated(pred);
|
|
748
767
|
if (!reachability || reachability.unknowable || !pred || typeof pred !== "object")
|
|
749
768
|
return;
|
|
750
|
-
const
|
|
769
|
+
const has = (key) => produced ? produced.has(key) : reached(key);
|
|
751
770
|
const { predicate, path: at, key, pages } = pred;
|
|
752
771
|
// quote_missing reads its pages too: a page no input key or earlier node writes holds no text, so every quote misses.
|
|
753
772
|
if (predicate === "quote_missing" && Array.isArray(pages))
|
|
@@ -755,14 +774,14 @@ export function validateWorkflow(workflow, opts) {
|
|
|
755
774
|
if (typeof page !== "string" || !page.trim())
|
|
756
775
|
continue;
|
|
757
776
|
const head = page.split(".")[0];
|
|
758
|
-
if (!
|
|
777
|
+
if (!has(head))
|
|
759
778
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field}.pages reads "${page}" but no input key or earlier node produces "${head}"; every quote would miss`);
|
|
760
779
|
}
|
|
761
780
|
const read = predicate === "no_new_items" ? key : predicate === "ask" ? undefined : at;
|
|
762
781
|
if (typeof read !== "string" || !read.trim())
|
|
763
782
|
return;
|
|
764
783
|
const head = read.split(".")[0];
|
|
765
|
-
if (!
|
|
784
|
+
if (!has(head))
|
|
766
785
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field} reads "${read}" but no input key or earlier node produces "${head}"; the guard can never fire`);
|
|
767
786
|
else if (!produced)
|
|
768
787
|
checkTypedPath(read, `${path} (${label}) ${field}`, ptrOf(path));
|
|
@@ -773,10 +792,10 @@ export function validateWorkflow(workflow, opts) {
|
|
|
773
792
|
for (const m of JSON.stringify(value).matchAll(/\{([a-zA-Z0-9_.$]+)\}/g)) {
|
|
774
793
|
// Runtime tries a literal state.* property before the optional prefix alias.
|
|
775
794
|
// When both namespaces may exist, do not reject either possible resolution.
|
|
776
|
-
if (m[1].startsWith("state.") &&
|
|
795
|
+
if (m[1].startsWith("state.") && reached("state"))
|
|
777
796
|
continue;
|
|
778
797
|
const head = (m[1].startsWith("state.") ? m[1].slice(6) : m[1]).split(".")[0];
|
|
779
|
-
if (!
|
|
798
|
+
if (!reached(head))
|
|
780
799
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): interpolates {${m[1]}} but no upstream node produces "${head}"`);
|
|
781
800
|
else
|
|
782
801
|
checkTypedPath(m[1].startsWith("state.") ? m[1].slice(6) : m[1], `${path} (${label})`, ptrOf(path));
|
|
@@ -793,7 +812,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
793
812
|
return;
|
|
794
813
|
for (const required of node.requires) {
|
|
795
814
|
const head = String(required).split(".")[0];
|
|
796
|
-
if (!
|
|
815
|
+
if (!reached(head)) {
|
|
797
816
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): requires "${required}" but no upstream node produces it; state here has only: ${[...reachability.available].join(", ")}`);
|
|
798
817
|
}
|
|
799
818
|
else
|
|
@@ -804,7 +823,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
804
823
|
if (!reachability || reachability.unknowable || !node.itemsPath)
|
|
805
824
|
return;
|
|
806
825
|
const head = node.itemsPath.split(".")[0];
|
|
807
|
-
if (!
|
|
826
|
+
if (!reached(head))
|
|
808
827
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): itemsPath "${node.itemsPath}" has no upstream producer; read the value under the producing node's as key (or its label when as is omitted)`);
|
|
809
828
|
else
|
|
810
829
|
checkTypedPath(node.itemsPath, `${path} (${node.label}) itemsPath`, ptrOf(path));
|
|
@@ -1111,9 +1130,48 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1111
1130
|
fail("NODE_KEY_UNKNOWN", ptrOf(path), `${path} (${node.label}): failedAs is written only with onItemFailure "collect"`);
|
|
1112
1131
|
if (containsReportNode(node.body))
|
|
1113
1132
|
fail("STRUCTURE_INVALID", ptrOf(path), `${path} (${node.label}): a report node cannot live inside a map body — the report is the workflow's ONE terminal rendering (a mapped copy lands in the item results, never at state.report_markdown)`);
|
|
1114
|
-
if (reachability)
|
|
1115
|
-
|
|
1116
|
-
|
|
1133
|
+
if (!reachability) {
|
|
1134
|
+
walk(node.body, `${path}.body`, `${ptr}/body`);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
{
|
|
1138
|
+
// Each item runs the body on the state before the map with `item` and `item_index`; past the map the state holds
|
|
1139
|
+
// the keys before it, `as` (an array of each item's result) and `failedAs`, never the body's own writes. A code
|
|
1140
|
+
// node in the body stops the check inside the body only.
|
|
1141
|
+
const before = { available: new Set(reachability.available), unknowable: reachability.unknowable, typed: new Map(typedOutputs) };
|
|
1142
|
+
const items = typeof node.itemsPath === "string" ? schemaAt(node.itemsPath) : undefined;
|
|
1143
|
+
reachability.past = true;
|
|
1144
|
+
reachability.available.add("item").add("item_index");
|
|
1145
|
+
rememberOutput("item", items?.type === "array" && !items.prefixItems ? items.items : undefined);
|
|
1146
|
+
typedOutputs.delete("item_index");
|
|
1147
|
+
walk(node.body, `${path}.body`, `${ptr}/body`);
|
|
1148
|
+
const resultPath = typeof node.resultPath === "string" && node.resultPath.trim() ? node.resultPath : undefined;
|
|
1149
|
+
const bodyAs = isRecord(node.body) && typeof node.body.as === "string" ? node.body.as : undefined;
|
|
1150
|
+
let result;
|
|
1151
|
+
if (!reachability.unknowable && resultPath) {
|
|
1152
|
+
if (!reached(resultPath.split(".")[0]))
|
|
1153
|
+
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): resultPath "${resultPath}" is not written by the body on every path; an item whose body leaves it unset fails the map`);
|
|
1154
|
+
else {
|
|
1155
|
+
checkTypedPath(resultPath, `${path} (${node.label}) resultPath`, ptrOf(path));
|
|
1156
|
+
result = schemaAt(resultPath);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
else if (!reachability.unknowable && !resultPath && bodyAs)
|
|
1160
|
+
result = schemaAt(bodyAs);
|
|
1161
|
+
reachability.available = before.available;
|
|
1162
|
+
reachability.unknowable = before.unknowable;
|
|
1163
|
+
typedOutputs.clear();
|
|
1164
|
+
for (const [key, value] of before.typed)
|
|
1165
|
+
typedOutputs.set(key, value);
|
|
1166
|
+
if (node.as) {
|
|
1167
|
+
reachability.available.add(node.as);
|
|
1168
|
+
rememberOutput(node.as, result ? { type: "array", items: result } : undefined);
|
|
1169
|
+
}
|
|
1170
|
+
if (node.onItemFailure === "collect" && typeof node.failedAs === "string") {
|
|
1171
|
+
reachability.available.add(node.failedAs);
|
|
1172
|
+
typedOutputs.delete(node.failedAs);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1117
1175
|
return;
|
|
1118
1176
|
case "parallel":
|
|
1119
1177
|
if (!Array.isArray(node.branches) || node.branches.length < 2)
|
|
@@ -1157,11 +1215,23 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1157
1215
|
// `until` reads the state after the body: the keys before the loop plus every key the body writes.
|
|
1158
1216
|
const bodyWrites = loopBodyWrites(node.body);
|
|
1159
1217
|
if (reachability && !reachability.unknowable && bodyWrites)
|
|
1160
|
-
checkPredicateHead(node.until, node.label, path, "until", new Set([...reachability.available, ...bodyWrites]));
|
|
1218
|
+
checkPredicateHead(node.until, node.label, path, "until", new Set([...reachability.available, ...reachability.prior, ...bodyWrites]));
|
|
1219
|
+
// The body reads its own writes from a later pass (`prior`); past the loop the state is what the body's walk leaves,
|
|
1220
|
+
// never a key only an earlier pass may have written. A body holding an unaliased code node writes keys no walk
|
|
1221
|
+
// knows: the check stops there, as before.
|
|
1222
|
+
if (reachability && !bodyWrites)
|
|
1223
|
+
reachability.unknowable = true;
|
|
1224
|
+
const prior = reachability && bodyWrites ? reachability.prior : undefined;
|
|
1225
|
+
if (reachability && prior) {
|
|
1226
|
+
reachability.past = true;
|
|
1227
|
+
reachability.prior = new Set([...prior, ...bodyWrites]);
|
|
1228
|
+
for (const key of bodyWrites)
|
|
1229
|
+
typedOutputs.delete(key);
|
|
1230
|
+
}
|
|
1231
|
+
walk(node.body, `${path}.body`, `${ptr}/body`);
|
|
1232
|
+
if (reachability && prior)
|
|
1233
|
+
reachability.prior = prior;
|
|
1161
1234
|
}
|
|
1162
|
-
if (reachability)
|
|
1163
|
-
reachability.unknowable = true;
|
|
1164
|
-
walk(node.body, `${path}.body`, `${ptr}/body`);
|
|
1165
1235
|
return;
|
|
1166
1236
|
case "escalate":
|
|
1167
1237
|
mayEscalate = true;
|
|
@@ -1278,7 +1348,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1278
1348
|
fail("NODE_FIELD_INVALID", ptrOf(path), `${path} (${label}): otherwise must name one of the branches`);
|
|
1279
1349
|
if (typeof valuePath === "string" && valuePath.trim() && reachability && !reachability.unknowable) {
|
|
1280
1350
|
const head = valuePath.split(".")[0];
|
|
1281
|
-
if (!
|
|
1351
|
+
if (!reached(head))
|
|
1282
1352
|
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): valuePath "${valuePath}" has no upstream producer; route by the key an earlier node writes`);
|
|
1283
1353
|
else
|
|
1284
1354
|
checkTypedPath(valuePath, `${path} (${label}) valuePath`, ptrOf(path));
|
|
@@ -1354,7 +1424,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1354
1424
|
if (typeof node.path !== "string" || !node.path.trim() || node.path.startsWith("/") || node.path.split("/").includes(".."))
|
|
1355
1425
|
fail("NODE_FIELD_INVALID", ptrOf(path), `${path} (${label}): path must be a workspace-relative file`);
|
|
1356
1426
|
else if (reachability && !producedFiles.has(node.path))
|
|
1357
|
-
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): path "${node.path}" is not produced by any earlier shell call (declare it in that call's produces)
|
|
1427
|
+
unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): path "${node.path}" is not produced by any earlier shell call (declare it in that call's produces)`, false);
|
|
1358
1428
|
checkRequires({ label, requires: node.requires }, path);
|
|
1359
1429
|
if (reachability) {
|
|
1360
1430
|
reachability.available.add("artifact");
|
|
@@ -1573,7 +1643,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1573
1643
|
}
|
|
1574
1644
|
if (reachability && !reachability.unknowable && !mayEscalate && workflow?.output?.path) {
|
|
1575
1645
|
const head = workflow.output.path.split(".")[0];
|
|
1576
|
-
if (!
|
|
1646
|
+
if (!reached(head))
|
|
1577
1647
|
unreached("STATE_PATH_UNPRODUCED", "", `output: path "${workflow.output.path}" has no input or upstream producer; select the final node's as key (or label when as is omitted)`);
|
|
1578
1648
|
else
|
|
1579
1649
|
checkTypedPath(workflow.output.path, "output", "");
|
|
@@ -1622,7 +1692,7 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1622
1692
|
bestMissing = missing;
|
|
1623
1693
|
}
|
|
1624
1694
|
if (bestMissing?.length) {
|
|
1625
|
-
unreached("STATE_PATH_EXCLUDED", "", `output: the code node writing "${workflow.output.path}" never emits required field(s) ${bestMissing.join(", ")} of schema "${workflow.output.schemaId}" — every run would fail output validation
|
|
1695
|
+
unreached("STATE_PATH_EXCLUDED", "", `output: the code node writing "${workflow.output.path}" never emits required field(s) ${bestMissing.join(", ")} of schema "${workflow.output.schemaId}" — every run would fail output validation`, false);
|
|
1626
1696
|
}
|
|
1627
1697
|
}
|
|
1628
1698
|
}
|