@parcha/agentrun-dsl 0.1.0-beta.17 → 0.1.0-beta.170
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/NOTICE +2 -0
- package/README.md +153 -16
- package/dist/author-references.d.ts +8 -0
- package/dist/author-references.js +8 -0
- package/dist/author.d.ts +4 -3
- package/dist/author.js +20 -11
- package/dist/authoring.js +5 -4
- package/dist/cli.js +19 -13
- package/dist/code-exec.d.ts +19 -0
- package/dist/code-exec.js +54 -5
- package/dist/decision-provider.d.ts +166 -0
- package/dist/decision-provider.js +238 -0
- package/dist/decision-receipts.d.ts +64 -3
- package/dist/decision-receipts.js +50 -8
- package/dist/dry-run.d.ts +35 -1
- package/dist/dry-run.js +131 -25
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +63 -0
- package/dist/graph.d.ts +107 -5
- package/dist/graph.js +284 -9
- package/dist/index.d.ts +17 -12
- package/dist/index.js +16 -10
- package/dist/inspection.d.ts +5 -0
- package/dist/inspection.js +14 -1
- package/dist/pattern-screen.d.ts +14 -0
- package/dist/pattern-screen.js +451 -0
- package/dist/predicates.d.ts +29 -0
- package/dist/predicates.js +62 -3
- package/dist/record.d.ts +4 -0
- package/dist/record.js +6 -0
- package/dist/recovery/binding.js +2 -1
- package/dist/recovery/call-key.d.ts +0 -4
- package/dist/recovery/call-key.js +0 -7
- package/dist/recovery/driver.d.ts +59 -24
- package/dist/recovery/driver.js +251 -73
- package/dist/recovery/frozen-snapshot.d.ts +54 -4
- package/dist/recovery/frozen-snapshot.js +44 -14
- package/dist/recovery/handoff-receipts.d.ts +0 -35
- package/dist/recovery/handoff-receipts.js +2 -44
- package/dist/recovery/index.d.ts +4 -8
- package/dist/recovery/index.js +4 -7
- package/dist/recovery/with-recovery.d.ts +9 -3
- package/dist/recovery/with-recovery.js +78 -18
- package/dist/submit-envelope.d.ts +9 -0
- package/dist/submit-envelope.js +44 -0
- package/dist/system-one.d.ts +21 -2
- package/dist/system-one.js +96 -18
- package/dist/testing/decision-provider.d.ts +32 -0
- package/dist/testing/decision-provider.js +183 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/vocabulary.d.ts +11 -3
- package/dist/vocabulary.js +19 -9
- package/dist/workflow-shape.d.ts +7 -0
- package/dist/workflow-shape.js +116 -70
- package/dist/workflow.d.ts +171 -19
- package/dist/workflow.js +1063 -399
- package/dist/zod-json-contract.js +6 -8
- package/package.json +12 -4
- package/schema/workflow.schema.json +366 -1
- package/skills/author/SKILL.md +6 -1
- package/skills/author/references/jev-decisions.md +50 -5
- package/skills/author/references/language.md +19 -14
- package/dist/recovery/effect-failure.d.ts +0 -34
- package/dist/recovery/effect-failure.js +0 -62
- package/dist/recovery/handoff-block.d.ts +0 -36
- package/dist/recovery/handoff-block.js +0 -148
- package/dist/recovery/handoff-digest.d.ts +0 -58
- package/dist/recovery/handoff-digest.js +0 -195
- package/dist/recovery/handoff-files.d.ts +0 -54
- package/dist/recovery/handoff-files.js +0 -162
- package/dist/recovery/handoff-redact.d.ts +0 -12
- package/dist/recovery/handoff-redact.js +0 -44
- package/dist/recovery/handoff.d.ts +0 -44
- package/dist/recovery/handoff.js +0 -46
package/dist/workflow-shape.js
CHANGED
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { Compile } from "typebox/compile";
|
|
3
|
-
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
// A named require lets deployment tracers retain the schema beside this package.
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const documentSchema = require("../schema/workflow.schema.json");
|
|
4
7
|
const fullValidator = Compile(documentSchema);
|
|
5
|
-
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
8
|
// Diagnostics only: the full validator below remains the acceptance authority.
|
|
7
9
|
// Its union errors can fill the entire error limit with unrelated node kinds.
|
|
8
10
|
// Select the declared discriminator's schema, checking nested nodes separately so
|
|
9
11
|
// their own discriminators also get useful errors. Never evaluate authored code.
|
|
10
12
|
const diagnosticDefinitions = { ...documentSchema.definitions, WorkflowNode: {}, Workflow: {} };
|
|
11
|
-
|
|
13
|
+
// A node kind may have more than one schema (a judged route and a route by value are both "route"): every variant is kept.
|
|
14
|
+
const nodeSchemas = new Map();
|
|
15
|
+
for (const schema of documentSchema.definitions.WorkflowNode.anyOf) {
|
|
16
|
+
const kind = schema.properties.node.const;
|
|
17
|
+
nodeSchemas.set(kind, [...(nodeSchemas.get(kind) ?? []), schema]);
|
|
18
|
+
}
|
|
12
19
|
const diagnosticValidators = new Map();
|
|
13
|
-
for (const schema of [documentSchema.definitions.Workflow, ...nodeSchemas.values()]) {
|
|
20
|
+
for (const schema of [documentSchema.definitions.Workflow, ...[...nodeSchemas.values()].flat()]) {
|
|
14
21
|
diagnosticValidators.set(schema, Compile({ ...schema, definitions: diagnosticDefinitions }));
|
|
15
22
|
}
|
|
23
|
+
/** The variant of its kind a node is: the one that accepts it, else the one it has the fewest errors against, so a judged
|
|
24
|
+
* route missing its state is diagnosed as a judged route, not as a route by value missing its valuePath. Nested nodes are
|
|
25
|
+
* opaque to a variant's validator, so the count is of the node's own fields. A tie goes to the variant that comes first in
|
|
26
|
+
* the schema: a bare route is diagnosed as a judged route. */
|
|
27
|
+
const variantOf = (variants, entry) => {
|
|
28
|
+
if (variants.length === 1)
|
|
29
|
+
return variants[0];
|
|
30
|
+
let closest = variants[0], fewest = Infinity;
|
|
31
|
+
for (const variant of variants) {
|
|
32
|
+
const validator = diagnosticValidators.get(variant);
|
|
33
|
+
if (validator.Check(entry))
|
|
34
|
+
return variant;
|
|
35
|
+
const count = [...validator.Errors(entry)].length;
|
|
36
|
+
if (count < fewest) {
|
|
37
|
+
closest = variant;
|
|
38
|
+
fewest = count;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return closest;
|
|
42
|
+
};
|
|
16
43
|
const pointer = (key) => key.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
17
44
|
function discriminatedErrors(value) {
|
|
18
45
|
const errors = [];
|
|
@@ -22,7 +49,7 @@ function discriminatedErrors(value) {
|
|
|
22
49
|
const validator = diagnosticValidators.get(schema);
|
|
23
50
|
if (!validator.Check(entry))
|
|
24
51
|
for (const error of validator.Errors(entry)) {
|
|
25
|
-
errors.push(`workflow${path}${error.instancePath || (path ? "" : "/")}: ${error.message}`);
|
|
52
|
+
errors.push({ path: `${path}${error.instancePath}`, message: `workflow${path}${error.instancePath || (path ? "" : "/")}: ${error.message}` });
|
|
26
53
|
if (errors.length >= 8)
|
|
27
54
|
return;
|
|
28
55
|
}
|
|
@@ -32,9 +59,9 @@ function discriminatedErrors(value) {
|
|
|
32
59
|
if (!schema || typeof schema !== "object" || errors.length >= 8)
|
|
33
60
|
return;
|
|
34
61
|
if (schema.$ref === "#/definitions/WorkflowNode") {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
check(
|
|
62
|
+
const variants = isRecord(entry) && typeof entry.node === "string" ? nodeSchemas.get(entry.node) : undefined;
|
|
63
|
+
if (variants)
|
|
64
|
+
check(variantOf(variants, entry), entry, path);
|
|
38
65
|
return; // Unknown/missing discriminators retain the full validator's fallback.
|
|
39
66
|
}
|
|
40
67
|
if (schema.$ref === "#/definitions/Workflow") {
|
|
@@ -58,128 +85,147 @@ function discriminatedErrors(value) {
|
|
|
58
85
|
check(documentSchema.definitions.Workflow, value, "");
|
|
59
86
|
return errors;
|
|
60
87
|
}
|
|
88
|
+
/** The deepest prefix of `path` that names a value in `document`: a rule about a missing key points at its container. */
|
|
89
|
+
function present(document, path) {
|
|
90
|
+
let cursor = document;
|
|
91
|
+
let reached = "";
|
|
92
|
+
for (const raw of path.split("/").slice(1)) {
|
|
93
|
+
const key = raw.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
94
|
+
if (cursor === null || typeof cursor !== "object" || !Object.hasOwn(cursor, key))
|
|
95
|
+
break;
|
|
96
|
+
cursor = cursor[key];
|
|
97
|
+
reached += `/${raw}`;
|
|
98
|
+
}
|
|
99
|
+
return reached;
|
|
100
|
+
}
|
|
61
101
|
export function workflowShapeErrors(value, complete = false) {
|
|
102
|
+
return workflowShapeIssues(value, complete).map(issue => issue.message);
|
|
103
|
+
}
|
|
104
|
+
export function workflowShapeIssues(value, complete = false) {
|
|
105
|
+
const located = (issues) => issues.map(issue => ({ path: present(value, issue.path), message: issue.message }));
|
|
62
106
|
if (complete) {
|
|
63
107
|
if (fullValidator.Check(value))
|
|
64
108
|
return [];
|
|
65
109
|
const selected = discriminatedErrors(value);
|
|
66
110
|
if (selected.length)
|
|
67
|
-
return selected;
|
|
68
|
-
return [...fullValidator.Errors(value)].slice(0, 8).map(error => `workflow${error.instancePath || "/"}: ${error.message}`);
|
|
111
|
+
return located(selected);
|
|
112
|
+
return located([...fullValidator.Errors(value)].slice(0, 8).map(error => ({ path: error.instancePath, message: `workflow${error.instancePath || "/"}: ${error.message}` })));
|
|
69
113
|
}
|
|
114
|
+
const at = (loc, key) => ({ text: `${loc.text}.${key}`, ptr: `${loc.ptr}/${pointer(key)}` });
|
|
115
|
+
const index = (loc, i) => ({ text: `${loc.text}[${i}]`, ptr: `${loc.ptr}/${i}` });
|
|
70
116
|
const errors = [];
|
|
71
|
-
const fail = (
|
|
72
|
-
const record = (entry,
|
|
117
|
+
const fail = (loc, expected) => { errors.push({ path: loc.ptr, message: `${loc.text} must be ${expected}` }); };
|
|
118
|
+
const record = (entry, loc) => {
|
|
73
119
|
if (isRecord(entry))
|
|
74
120
|
return true;
|
|
75
|
-
fail(
|
|
121
|
+
fail(loc, "an object");
|
|
76
122
|
return false;
|
|
77
123
|
};
|
|
78
|
-
const strings = (entry,
|
|
124
|
+
const strings = (entry, loc, keys) => {
|
|
79
125
|
for (const key of keys)
|
|
80
126
|
if (entry[key] !== undefined && typeof entry[key] !== "string")
|
|
81
|
-
fail(
|
|
127
|
+
fail(at(loc, key), "a string");
|
|
82
128
|
};
|
|
83
|
-
const stringList = (entry,
|
|
129
|
+
const stringList = (entry, loc) => {
|
|
84
130
|
if (entry === undefined)
|
|
85
131
|
return;
|
|
86
132
|
if (!Array.isArray(entry)) {
|
|
87
|
-
fail(
|
|
133
|
+
fail(loc, "an array of strings");
|
|
88
134
|
return;
|
|
89
135
|
}
|
|
90
|
-
entry.forEach((item,
|
|
91
|
-
fail(
|
|
136
|
+
entry.forEach((item, i) => { if (typeof item !== "string")
|
|
137
|
+
fail(index(loc, i), "a string"); });
|
|
92
138
|
};
|
|
93
139
|
// Preserve existing diagnostics for missing, non-finite and out-of-range numbers, and
|
|
94
140
|
// primitive strings such as poll.deadline_s="soon". Objects can throw during coercion.
|
|
95
|
-
const numeric = (entry,
|
|
141
|
+
const numeric = (entry, loc, keys) => {
|
|
96
142
|
for (const key of keys) {
|
|
97
143
|
const item = entry[key];
|
|
98
144
|
if (item !== null && item !== undefined && !["number", "string", "boolean"].includes(typeof item))
|
|
99
|
-
fail(
|
|
145
|
+
fail(at(loc, key), "a number");
|
|
100
146
|
}
|
|
101
147
|
};
|
|
102
|
-
const objectField = (entry,
|
|
148
|
+
const objectField = (entry, loc, key, visit) => {
|
|
103
149
|
if (entry[key] === undefined)
|
|
104
150
|
return;
|
|
105
|
-
if (record(entry[key],
|
|
106
|
-
visit?.(entry[key],
|
|
151
|
+
if (record(entry[key], at(loc, key)))
|
|
152
|
+
visit?.(entry[key], at(loc, key));
|
|
107
153
|
};
|
|
108
|
-
const predicate = (entry,
|
|
109
|
-
strings(entry,
|
|
110
|
-
numeric(entry,
|
|
111
|
-
objectField(entry,
|
|
112
|
-
objectField(entry,
|
|
154
|
+
const predicate = (entry, loc) => {
|
|
155
|
+
strings(entry, loc, ["predicate", "path", "key", "instructions"]);
|
|
156
|
+
numeric(entry, loc, ["n", "gte"]);
|
|
157
|
+
objectField(entry, loc, "state");
|
|
158
|
+
objectField(entry, loc, "criteria", (criteria, here) => strings(criteria, here, ["true", "false"]));
|
|
113
159
|
};
|
|
114
|
-
const node = (entry,
|
|
160
|
+
const node = (entry, loc) => {
|
|
115
161
|
if (entry === undefined)
|
|
116
162
|
return; // missing bodies already receive semantic diagnostics
|
|
117
|
-
if (!record(entry,
|
|
163
|
+
if (!record(entry, loc))
|
|
118
164
|
return;
|
|
119
|
-
strings(entry,
|
|
120
|
-
numeric(entry,
|
|
165
|
+
strings(entry, loc, ["node", "label", "code", "as", "out", "instructions", "itemsPath", "resultPath", "kind", "stage", "summary", "describe", "type", "path", "tool", "command", "via", "where", "effort", "thinking", "tier", "valuePath", "otherwise", "onItemFailure", "failedAs"]);
|
|
166
|
+
numeric(entry, loc, ["maxConcurrency", "maxIters", "expect_iters", "deadline_s"]);
|
|
121
167
|
for (const key of ["requires", "tools", "produces"])
|
|
122
|
-
stringList(entry[key],
|
|
168
|
+
stringList(entry[key], at(loc, key));
|
|
123
169
|
if (entry.sopSection !== undefined && typeof entry.sopSection !== "string")
|
|
124
|
-
stringList(entry.sopSection,
|
|
170
|
+
stringList(entry.sopSection, at(loc, "sopSection"));
|
|
125
171
|
for (const key of ["state", "args", "input", "env"])
|
|
126
|
-
objectField(entry,
|
|
172
|
+
objectField(entry, loc, key);
|
|
127
173
|
// Host-owned and opaque: only its container is checked, never its keys or values.
|
|
128
174
|
if (entry.metadata !== undefined && !isRecord(entry.metadata)) {
|
|
129
|
-
errors.push(`${
|
|
175
|
+
errors.push({ path: at(loc, "metadata").ptr, message: `${loc.text} (${typeof entry.label === "string" && entry.label ? entry.label : String(entry.node)}): metadata must be a plain object of host markers` });
|
|
130
176
|
}
|
|
131
177
|
for (const key of ["until", "when"])
|
|
132
|
-
objectField(entry,
|
|
133
|
-
objectField(entry,
|
|
134
|
-
strings(verify,
|
|
135
|
-
numeric(verify,
|
|
136
|
-
objectField(verify,
|
|
137
|
-
objectField(verify,
|
|
178
|
+
objectField(entry, loc, key, predicate);
|
|
179
|
+
objectField(entry, loc, "verify", (verify, here) => {
|
|
180
|
+
strings(verify, here, ["out"]);
|
|
181
|
+
numeric(verify, here, ["maxDrives"]);
|
|
182
|
+
objectField(verify, here, "state");
|
|
183
|
+
objectField(verify, here, "override", (override, inner) => numeric(override, inner, ["below"]));
|
|
138
184
|
});
|
|
139
|
-
objectField(entry,
|
|
140
|
-
objectField(entry,
|
|
141
|
-
objectField(entry,
|
|
142
|
-
numeric(retry,
|
|
143
|
-
stringList(retry.on,
|
|
185
|
+
objectField(entry, loc, "keep", (keep, here) => { strings(keep, here, ["path"]); numeric(keep, here, ["gte"]); });
|
|
186
|
+
objectField(entry, loc, "unsure", (unsure, here) => { strings(unsure, here, ["branch"]); numeric(unsure, here, ["gte"]); });
|
|
187
|
+
objectField(entry, loc, "retry", (retry, here) => {
|
|
188
|
+
numeric(retry, here, ["attempts", "backoff_s"]);
|
|
189
|
+
stringList(retry.on, at(here, "on"));
|
|
144
190
|
});
|
|
145
|
-
objectField(entry,
|
|
146
|
-
numeric(poll,
|
|
191
|
+
objectField(entry, loc, "poll", (poll, here) => {
|
|
192
|
+
numeric(poll, here, ["interval_s", "deadline_s"]);
|
|
147
193
|
for (const key of ["until", "fail_when"])
|
|
148
|
-
objectField(poll,
|
|
194
|
+
objectField(poll, here, key, predicate);
|
|
149
195
|
});
|
|
150
196
|
if (entry.node === "chain" || entry.node === "parallel") {
|
|
151
197
|
const key = entry.node === "chain" ? "steps" : "branches";
|
|
152
198
|
if (entry[key] !== undefined) {
|
|
153
199
|
if (!Array.isArray(entry[key]))
|
|
154
|
-
fail(
|
|
200
|
+
fail(at(loc, key), "an array of nodes");
|
|
155
201
|
else
|
|
156
|
-
entry[key].forEach((child,
|
|
202
|
+
entry[key].forEach((child, i) => node(child, index(at(loc, key), i)));
|
|
157
203
|
}
|
|
158
204
|
}
|
|
159
205
|
if (entry.node === "map" || entry.node === "loop")
|
|
160
|
-
node(entry.body,
|
|
206
|
+
node(entry.body, at(loc, "body"));
|
|
161
207
|
if (entry.node === "route")
|
|
162
|
-
objectField(entry,
|
|
208
|
+
objectField(entry, loc, "branches", (branches, here) => {
|
|
163
209
|
for (const [name, branch] of Object.entries(branches))
|
|
164
|
-
if (record(branch,
|
|
165
|
-
strings(branch,
|
|
166
|
-
node(branch.body,
|
|
210
|
+
if (record(branch, at(here, name))) {
|
|
211
|
+
strings(branch, at(here, name), ["criteria"]);
|
|
212
|
+
node(branch.body, at(at(here, name), "body"));
|
|
167
213
|
}
|
|
168
214
|
});
|
|
169
215
|
if (entry.node === "workflow")
|
|
170
|
-
workflow(entry.workflow,
|
|
216
|
+
workflow(entry.workflow, at(loc, "workflow"));
|
|
171
217
|
};
|
|
172
|
-
const workflow = (entry,
|
|
173
|
-
if (!record(entry,
|
|
218
|
+
const workflow = (entry, loc) => {
|
|
219
|
+
if (!record(entry, loc))
|
|
174
220
|
return;
|
|
175
|
-
strings(entry,
|
|
176
|
-
record(entry.schemas,
|
|
177
|
-
objectField(entry,
|
|
178
|
-
if (record(entry.output,
|
|
179
|
-
strings(entry.output,
|
|
180
|
-
if (record(entry.root,
|
|
181
|
-
node(entry.root,
|
|
221
|
+
strings(entry, loc, ["name"]);
|
|
222
|
+
record(entry.schemas, at(loc, "schemas"));
|
|
223
|
+
objectField(entry, loc, "input", (input, here) => strings(input, here, ["schemaId"]));
|
|
224
|
+
if (record(entry.output, at(loc, "output")))
|
|
225
|
+
strings(entry.output, at(loc, "output"), ["schemaId", "path"]);
|
|
226
|
+
if (record(entry.root, at(loc, "root")))
|
|
227
|
+
node(entry.root, at(loc, "root"));
|
|
182
228
|
};
|
|
183
|
-
workflow(value, "workflow");
|
|
184
|
-
return errors.slice(0, 8);
|
|
229
|
+
workflow(value, { text: "workflow", ptr: "" });
|
|
230
|
+
return located(errors.slice(0, 8));
|
|
185
231
|
}
|