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