@parcha/agentrun-dsl 0.1.0-beta.3 → 0.1.0-beta.300
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 +171 -23
- package/dist/author-references.d.ts +8 -0
- package/dist/author-references.js +8 -0
- package/dist/author.d.ts +16 -5
- package/dist/author.js +46 -21
- package/dist/authoring.js +5 -4
- package/dist/cli.js +19 -13
- package/dist/code-exec.d.ts +25 -0
- package/dist/code-exec.js +180 -5
- package/dist/decision-provider.d.ts +166 -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 -27
- package/dist/edit.d.ts +158 -0
- package/dist/edit.js +1486 -0
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +63 -0
- package/dist/graph.d.ts +169 -0
- package/dist/graph.js +433 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +18 -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/pattern-screen.d.ts +14 -0
- package/dist/pattern-screen.js +451 -0
- package/dist/pointer-warning.d.ts +14 -0
- package/dist/pointer-warning.js +22 -0
- package/dist/predicates.d.ts +32 -2
- package/dist/predicates.js +66 -6
- package/dist/record.d.ts +4 -0
- package/dist/record.js +6 -0
- package/dist/recovery/binding.d.ts +10 -0
- package/dist/recovery/binding.js +44 -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 +244 -0
- package/dist/recovery/driver.js +1359 -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 +11 -0
- package/dist/recovery/index.d.ts +14 -0
- package/dist/recovery/index.js +13 -0
- package/dist/recovery/item-state.d.ts +49 -0
- package/dist/recovery/item-state.js +83 -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 +44 -0
- package/dist/system-one.d.ts +37 -2
- package/dist/system-one.js +146 -11
- 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 +27 -3
- package/dist/vocabulary.js +39 -10
- package/dist/workflow-shape.d.ts +7 -0
- package/dist/workflow-shape.js +119 -69
- package/dist/workflow.d.ts +329 -29
- package/dist/workflow.js +1704 -490
- package/dist/zod-json-contract.js +6 -8
- package/package.json +31 -4
- package/schema/workflow.schema.json +599 -12
- package/skills/author/SKILL.md +6 -1
- package/skills/author/references/jev-decisions.md +69 -12
- package/skills/author/references/language.md +31 -21
- package/skills/author/references/sdk-authoring.md +2 -0
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,124 +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);
|
|
173
|
+
// Host-owned and opaque: only its container is checked, never its keys or values.
|
|
174
|
+
if (entry.metadata !== undefined && !isRecord(entry.metadata)) {
|
|
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` });
|
|
176
|
+
}
|
|
127
177
|
for (const key of ["until", "when"])
|
|
128
|
-
objectField(entry,
|
|
129
|
-
objectField(entry,
|
|
130
|
-
strings(verify,
|
|
131
|
-
numeric(verify,
|
|
132
|
-
objectField(verify,
|
|
133
|
-
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"]));
|
|
134
184
|
});
|
|
135
|
-
objectField(entry,
|
|
136
|
-
objectField(entry,
|
|
137
|
-
objectField(entry,
|
|
138
|
-
numeric(retry,
|
|
139
|
-
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"));
|
|
140
190
|
});
|
|
141
|
-
objectField(entry,
|
|
142
|
-
numeric(poll,
|
|
191
|
+
objectField(entry, loc, "poll", (poll, here) => {
|
|
192
|
+
numeric(poll, here, ["interval_s", "deadline_s"]);
|
|
143
193
|
for (const key of ["until", "fail_when"])
|
|
144
|
-
objectField(poll,
|
|
194
|
+
objectField(poll, here, key, predicate);
|
|
145
195
|
});
|
|
146
196
|
if (entry.node === "chain" || entry.node === "parallel") {
|
|
147
197
|
const key = entry.node === "chain" ? "steps" : "branches";
|
|
148
198
|
if (entry[key] !== undefined) {
|
|
149
199
|
if (!Array.isArray(entry[key]))
|
|
150
|
-
fail(
|
|
200
|
+
fail(at(loc, key), "an array of nodes");
|
|
151
201
|
else
|
|
152
|
-
entry[key].forEach((child,
|
|
202
|
+
entry[key].forEach((child, i) => node(child, index(at(loc, key), i)));
|
|
153
203
|
}
|
|
154
204
|
}
|
|
155
205
|
if (entry.node === "map" || entry.node === "loop")
|
|
156
|
-
node(entry.body,
|
|
206
|
+
node(entry.body, at(loc, "body"));
|
|
157
207
|
if (entry.node === "route")
|
|
158
|
-
objectField(entry,
|
|
208
|
+
objectField(entry, loc, "branches", (branches, here) => {
|
|
159
209
|
for (const [name, branch] of Object.entries(branches))
|
|
160
|
-
if (record(branch,
|
|
161
|
-
strings(branch,
|
|
162
|
-
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"));
|
|
163
213
|
}
|
|
164
214
|
});
|
|
165
215
|
if (entry.node === "workflow")
|
|
166
|
-
workflow(entry.workflow,
|
|
216
|
+
workflow(entry.workflow, at(loc, "workflow"));
|
|
167
217
|
};
|
|
168
|
-
const workflow = (entry,
|
|
169
|
-
if (!record(entry,
|
|
218
|
+
const workflow = (entry, loc) => {
|
|
219
|
+
if (!record(entry, loc))
|
|
170
220
|
return;
|
|
171
|
-
strings(entry,
|
|
172
|
-
record(entry.schemas,
|
|
173
|
-
objectField(entry,
|
|
174
|
-
if (record(entry.output,
|
|
175
|
-
strings(entry.output,
|
|
176
|
-
if (record(entry.root,
|
|
177
|
-
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"));
|
|
178
228
|
};
|
|
179
|
-
workflow(value, "workflow");
|
|
180
|
-
return errors.slice(0, 8);
|
|
229
|
+
workflow(value, { text: "workflow", ptr: "" });
|
|
230
|
+
return located(errors.slice(0, 8));
|
|
181
231
|
}
|