@parcha/agentrun-dsl 0.1.0-beta.15 → 0.1.0-beta.152
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/graph.js
CHANGED
|
@@ -2,27 +2,73 @@
|
|
|
2
2
|
// (the static viewer inlines it) and the pi session's text view draw the same graph; nothing here validates, runs or
|
|
3
3
|
// reads a store. `workflowGraph` reads the workflow JSON as written; `nodeStatus` reads the driver's record of a run
|
|
4
4
|
// (the `agentrun.driver` frame of the frozen snapshot, and the `agentrun.items` of a keyed-layout run) and says, for
|
|
5
|
-
// each node of that graph, whether it is done, working, failed or not run
|
|
5
|
+
// each node of that graph, whether it is done, working, failed or not run, or, given the run's terminal result, where an
|
|
6
|
+
// escalation stopped it; `graphNodeOf` names the node an execution path ran
|
|
7
|
+
// at, and the map items and loop iterations around it; `graphDiff` says what changed between two graphs of a workflow.
|
|
6
8
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
9
|
const pointer = (part) => part.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
8
10
|
/** The nesting depth `validateWorkflow` and `inspectWorkflow` accept (128 JSON levels): a node nests at least one level deeper than its parent, so every node of such a document is within it. */
|
|
9
11
|
const MAX_DEPTH = 128;
|
|
12
|
+
/** A value as canonical JSON: object keys sorted, undefined members left out, other values as JSON writes them. Deeper
|
|
13
|
+
* than `MAX_DEPTH` a value is written as one marker, so a value that is not JSON (a cycle) still ends. A leaf JSON
|
|
14
|
+
* cannot encode (a bigint, a symbol) is written as a marker of its type, so changeCheck is total: `workflowGraph` never
|
|
15
|
+
* throws on a node the validator accepts, and such a leaf still changes the check when it changes value. */
|
|
16
|
+
const leaf = (value) => {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.stringify(value) ?? "null";
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return JSON.stringify(`[${typeof value}:${String(value)}]`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const canonicalJson = (value, depth = 0) => {
|
|
25
|
+
if (depth > MAX_DEPTH)
|
|
26
|
+
return '"…"';
|
|
27
|
+
if (Array.isArray(value))
|
|
28
|
+
return `[${value.map((item) => canonicalJson(item, depth + 1)).join(",")}]`;
|
|
29
|
+
if (isObject(value))
|
|
30
|
+
return `{${Object.keys(value).filter((key) => value[key] !== undefined).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key], depth + 1)}`).join(",")}}`;
|
|
31
|
+
return leaf(value);
|
|
32
|
+
};
|
|
33
|
+
/** FNV-1a (32 bits) over the UTF-16 code units of `text`, as 8 hex digits. */
|
|
34
|
+
const fnv1a = (text) => {
|
|
35
|
+
let hash = 0x811c9dc5;
|
|
36
|
+
for (let i = 0; i < text.length; i += 1)
|
|
37
|
+
hash = Math.imul(hash ^ text.charCodeAt(i), 0x01000193);
|
|
38
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
39
|
+
};
|
|
40
|
+
const without = (value, key) => Object.fromEntries(Object.entries(value).filter(([name]) => name !== key));
|
|
41
|
+
/** A node's own fields: the node with the children the walk visits left out. */
|
|
42
|
+
const ownFields = (node) => {
|
|
43
|
+
switch (node.node) {
|
|
44
|
+
case "chain": return without(node, "steps");
|
|
45
|
+
case "parallel": return without(node, "branches");
|
|
46
|
+
case "map":
|
|
47
|
+
case "loop": return without(node, "body");
|
|
48
|
+
case "route": return isObject(node.branches)
|
|
49
|
+
? { ...node, branches: Object.fromEntries(Object.entries(node.branches).map(([name, branch]) => [name, isObject(branch) ? without(branch, "body") : branch])) }
|
|
50
|
+
: node;
|
|
51
|
+
case "workflow": return isObject(node.workflow) ? { ...node, workflow: without(node.workflow, "root") } : node;
|
|
52
|
+
default: return node;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
10
55
|
/** The graph of `workflow`, computed from its JSON alone: nodes in document order (a node, then its descendants), and the
|
|
11
56
|
* edges between them. A value that is not a workflow, or a node the walk does not know, adds nothing and never throws:
|
|
12
57
|
* validation is `validateWorkflow`'s. */
|
|
13
58
|
export function workflowGraph(workflow) {
|
|
14
59
|
const nodes = [];
|
|
15
60
|
const edges = [];
|
|
16
|
-
const visit = (node, path, depth) => {
|
|
61
|
+
const visit = (node, path, depth, schemas) => {
|
|
17
62
|
if (!isObject(node) || typeof node.node !== "string" || depth > MAX_DEPTH)
|
|
18
63
|
return;
|
|
19
64
|
nodes.push({ path, kind: node.node, label: typeof node.label === "string" ? node.label : node.node,
|
|
20
|
-
...(node.node === "call" && typeof node.via === "string" ? { via: node.via } : {})
|
|
21
|
-
|
|
65
|
+
...(node.node === "call" && typeof node.via === "string" ? { via: node.via } : {}), changeCheck: fnv1a(canonicalJson(ownFields(node))),
|
|
66
|
+
...decisionOf(node, schemas) });
|
|
67
|
+
const child = (target, at, kind, from = path, inner = schemas) => {
|
|
22
68
|
if (!isObject(target) || typeof target.node !== "string" || depth + 1 > MAX_DEPTH)
|
|
23
69
|
return;
|
|
24
70
|
edges.push({ from, to: at, kind });
|
|
25
|
-
visit(target, at, depth + 1);
|
|
71
|
+
visit(target, at, depth + 1, inner);
|
|
26
72
|
};
|
|
27
73
|
switch (node.node) {
|
|
28
74
|
case "chain":
|
|
@@ -47,20 +93,86 @@ export function workflowGraph(workflow) {
|
|
|
47
93
|
break;
|
|
48
94
|
case "workflow":
|
|
49
95
|
if (isObject(node.workflow))
|
|
50
|
-
child(node.workflow.root, `${path}/workflow/root`, "child");
|
|
96
|
+
child(node.workflow.root, `${path}/workflow/root`, "child", path, isObject(node.workflow.schemas) ? node.workflow.schemas : {});
|
|
51
97
|
break;
|
|
52
98
|
}
|
|
53
99
|
};
|
|
54
|
-
visit(isObject(workflow) ? workflow.root : undefined, "/root", 0);
|
|
100
|
+
visit(isObject(workflow) ? workflow.root : undefined, "/root", 0, isObject(workflow) && isObject(workflow.schemas) ? workflow.schemas : {});
|
|
55
101
|
return { nodes, edges };
|
|
56
102
|
}
|
|
103
|
+
/** The questions of a question schema (`out` of a judge or sift): a flat object whose properties are the questions, a
|
|
104
|
+
* string enum a choice, a boolean a noul, an integer a score; a local `#/definitions/<id>` reference is followed. */
|
|
105
|
+
const schemaQuestions = (schemaId, schemas) => {
|
|
106
|
+
const root = typeof schemaId === "string" && Object.hasOwn(schemas, schemaId) ? schemas[schemaId] : undefined;
|
|
107
|
+
const resolve = (spec) => {
|
|
108
|
+
for (let hops = 0; isObject(spec) && typeof spec.$ref === "string" && hops < 8; hops += 1) {
|
|
109
|
+
const id = /^#\/definitions\/(.+)$/.exec(spec.$ref)?.[1];
|
|
110
|
+
const inline = isObject(root) && isObject(root.definitions) ? root.definitions : {};
|
|
111
|
+
spec = id === undefined ? undefined : Object.hasOwn(inline, id) ? inline[id] : Object.hasOwn(schemas, id) ? schemas[id] : undefined;
|
|
112
|
+
}
|
|
113
|
+
return spec;
|
|
114
|
+
};
|
|
115
|
+
const object = resolve(root);
|
|
116
|
+
if (!isObject(object) || !isObject(object.properties))
|
|
117
|
+
return [];
|
|
118
|
+
return Object.entries(object.properties).map(([id, raw]) => {
|
|
119
|
+
const spec = resolve(raw);
|
|
120
|
+
const instructions = isObject(spec) && typeof spec.description === "string" ? spec.description : "";
|
|
121
|
+
const types = isObject(spec) ? (Array.isArray(spec.type) ? spec.type : [spec.type]).filter((type) => type !== "null") : [];
|
|
122
|
+
if (isObject(spec) && Array.isArray(spec.enum))
|
|
123
|
+
return { id, type: "choice", instructions, options: spec.enum.map(String) };
|
|
124
|
+
if (types.length === 1 && types[0] === "boolean")
|
|
125
|
+
return { id, type: "noul", instructions };
|
|
126
|
+
if (types.length === 1 && types[0] === "integer")
|
|
127
|
+
return { id, type: "score", instructions };
|
|
128
|
+
return { id, type: "unknown", instructions };
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
/** A decision node's provider, model, questions and image tokens, as written. */
|
|
132
|
+
const decisionOf = (node, schemas) => {
|
|
133
|
+
let source = node;
|
|
134
|
+
let questions;
|
|
135
|
+
const text = (value) => typeof value === "string" ? value : "";
|
|
136
|
+
switch (node.node) {
|
|
137
|
+
case "judge":
|
|
138
|
+
case "sift":
|
|
139
|
+
questions = schemaQuestions(node.out, schemas);
|
|
140
|
+
break;
|
|
141
|
+
case "pick":
|
|
142
|
+
questions = [{ id: "pick", type: "choice", instructions: text(node.instructions) }];
|
|
143
|
+
break;
|
|
144
|
+
case "route":
|
|
145
|
+
if (node.valuePath !== undefined)
|
|
146
|
+
return {};
|
|
147
|
+
questions = [{ id: "branch", type: "choice", instructions: text(node.instructions), options: isObject(node.branches) ? Object.keys(node.branches) : [] }];
|
|
148
|
+
break;
|
|
149
|
+
case "loop":
|
|
150
|
+
case "escalate": {
|
|
151
|
+
const predicate = node.node === "loop" ? node.until : node.when;
|
|
152
|
+
if (!isObject(predicate) || predicate.predicate !== "ask")
|
|
153
|
+
return {};
|
|
154
|
+
source = predicate;
|
|
155
|
+
questions = [{ id: "holds", type: "noul", instructions: text(predicate.instructions) }];
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
default: return {};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
...(typeof source.provider === "string" ? { provider: source.provider } : {}),
|
|
162
|
+
...(typeof source.model === "string" ? { model: source.model } : {}),
|
|
163
|
+
questions,
|
|
164
|
+
...(isObject(source.images) && Object.keys(source.images).length ? { images: Object.keys(source.images) } : {}),
|
|
165
|
+
};
|
|
166
|
+
};
|
|
57
167
|
/** The execution path an instance of a node ran at, as the node's path in the document: a map's item and a loop's
|
|
58
168
|
* iteration have no node of their own. */
|
|
59
169
|
const definitionPath = (path) => path.replace(/\/items\/\d+\/body/g, "/body").replace(/\/iterations\/\d+(?=\/|$)/g, "");
|
|
60
170
|
const RANK = { working: 1, done: 2, failed: 3 };
|
|
61
171
|
/** For every node of `graph`, the state the record shows. `source` is what the driver kept: its frame and, in the keyed
|
|
62
172
|
* layout, the records of the map items (a run's whole story is the frame and the items together). A source that is not
|
|
63
|
-
* one of those shows no node run.
|
|
173
|
+
* one of those shows no node run. With the run's terminal `result`, an escalation that names a node of the graph marks
|
|
174
|
+
* that node and every container on its path `escalated`, and the maps and loops on that path have ended, so what finished
|
|
175
|
+
* inside them is done; without one, or when it names no node of the graph, nothing else changes. */
|
|
64
176
|
export function nodeStatus(graph, source, options = {}) {
|
|
65
177
|
const instances = new Map();
|
|
66
178
|
const note = (path, state) => {
|
|
@@ -107,6 +219,19 @@ export function nodeStatus(graph, source, options = {}) {
|
|
|
107
219
|
}
|
|
108
220
|
else
|
|
109
221
|
readFrame(raw);
|
|
222
|
+
// The node a run's escalation ended at, from its terminal result: by its execution path, as the node it ran as.
|
|
223
|
+
const result = isObject(raw) && isObject(raw.pin) && isObject(raw.result) ? raw.result : undefined;
|
|
224
|
+
const escalation = result?.status === "escalated" && isObject(result.escalation) ? result.escalation : undefined;
|
|
225
|
+
const escalatedExecPath = typeof escalation?.executionPath === "string" ? escalation.executionPath : undefined;
|
|
226
|
+
// When one map item or loop iteration is read on its own (`options.item`), the escalation belongs to this view only if
|
|
227
|
+
// it fired inside that same instance: another item's escalation, reduced to the shared body, must not mark this one's
|
|
228
|
+
// body escalated. The item index is in the raw execution path, which `definitionPath` then strips.
|
|
229
|
+
const itemScope = typeof options.item === "string" ? options.item.replace(/\/$/, "") : undefined;
|
|
230
|
+
const inThisItem = escalatedExecPath !== undefined
|
|
231
|
+
&& (itemScope === undefined || escalatedExecPath === itemScope || escalatedExecPath.startsWith(`${itemScope}/`));
|
|
232
|
+
const stoppedAt = escalatedExecPath !== undefined && inThisItem ? definitionPath(escalatedExecPath) : undefined;
|
|
233
|
+
const ended = stoppedAt !== undefined && graph.nodes.some((node) => node.path === stoppedAt) ? stoppedAt : undefined;
|
|
234
|
+
const onPath = (path) => ended !== undefined && (path === ended || ended.startsWith(`${path}/`));
|
|
110
235
|
// A done mark outranks a working one at the same path (a step's record stays after its node commits); a failure outranks both.
|
|
111
236
|
const byNode = new Map();
|
|
112
237
|
for (const [path, state] of instances) {
|
|
@@ -146,7 +271,8 @@ export function nodeStatus(graph, source, options = {}) {
|
|
|
146
271
|
// The map or loop an `item` belongs to is the exception, and so is every one that encloses it: that item is the instance, and
|
|
147
272
|
// the source holds nothing of the items around it. A map or loop inside the item still stands for its own items.
|
|
148
273
|
const owner = typeof options.item === "string" ? definitionPath(options.item.replace(/\/(?:items|iterations)\/\d+$/, "")) : undefined;
|
|
149
|
-
|
|
274
|
+
// A map or loop on an escalation's path has ended: no other item or iteration will run, so what finished inside it is done.
|
|
275
|
+
const containers = graph.nodes.filter((node) => (node.kind === "map" || node.kind === "loop") && !onPath(node.path)
|
|
150
276
|
&& !(owner !== undefined && (node.path === owner || owner.startsWith(`${node.path}/body`))));
|
|
151
277
|
for (const node of graph.nodes) {
|
|
152
278
|
if (out[node.path] !== "done")
|
|
@@ -154,5 +280,154 @@ export function nodeStatus(graph, source, options = {}) {
|
|
|
154
280
|
if (containers.some((container) => node.path.startsWith(`${container.path}/body`) && out[container.path] !== "done"))
|
|
155
281
|
out[node.path] = "working";
|
|
156
282
|
}
|
|
283
|
+
// The run ended at the escalate node that fired, and in each container on its path; a failure recorded below a container
|
|
284
|
+
// still shows.
|
|
285
|
+
for (const node of graph.nodes)
|
|
286
|
+
if (onPath(node.path) && (node.path === ended || out[node.path] !== "failed"))
|
|
287
|
+
out[node.path] = "escalated";
|
|
157
288
|
return out;
|
|
158
289
|
}
|
|
290
|
+
/** An item or iteration index as an execution path writes it: a whole number with no sign and no leading zero. */
|
|
291
|
+
const indexOf = (segment) => segment !== undefined && /^(0|[1-9][0-9]*)$/.test(segment) && Number.isSafeInteger(Number(segment)) ? Number(segment) : undefined;
|
|
292
|
+
/** The graph node an execution path ran at. An execution path is the node's JSON Pointer with two runtime segments added:
|
|
293
|
+
* a map's item (`items/<i>` before the map's `body`) and a loop's iteration (`iterations/<i>` before the loop's `body`); the
|
|
294
|
+
* graph has `/body` for both, and the indexes are returned in `at`. The path is read by walking the graph from `/root`, by
|
|
295
|
+
* each node's kind, never by matching its text, so a route branch named `items` or `iterations` is a branch. Undefined for
|
|
296
|
+
* a path the graph does not have, or one that is not an execution path (a map's `body` without an item, an item without
|
|
297
|
+
* its `body`). */
|
|
298
|
+
export function graphNodeOf(graph, executionPath) {
|
|
299
|
+
if (typeof executionPath !== "string")
|
|
300
|
+
return undefined;
|
|
301
|
+
const kinds = new Map(graph.nodes.map((node) => [node.path, node.kind]));
|
|
302
|
+
const parts = executionPath.split("/");
|
|
303
|
+
if (parts[0] !== "" || parts[1] !== "root" || !kinds.has("/root"))
|
|
304
|
+
return undefined;
|
|
305
|
+
let path = "/root";
|
|
306
|
+
const at = [];
|
|
307
|
+
for (let i = 2; i < parts.length;) {
|
|
308
|
+
const [first, second, third] = [parts[i], parts[i + 1], parts[i + 2]];
|
|
309
|
+
let next;
|
|
310
|
+
switch (kinds.get(path)) {
|
|
311
|
+
case "chain":
|
|
312
|
+
if (first === "steps" && indexOf(second) !== undefined) {
|
|
313
|
+
next = `${path}/steps/${second}`;
|
|
314
|
+
i += 2;
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
case "parallel":
|
|
318
|
+
if (first === "branches" && indexOf(second) !== undefined) {
|
|
319
|
+
next = `${path}/branches/${second}`;
|
|
320
|
+
i += 2;
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
case "route":
|
|
324
|
+
// The branch's name, pointer-escaped as in the graph, whatever it is: `items`, `iterations`, `0`, and the empty name a
|
|
325
|
+
// route Jev chooses may give a branch, included.
|
|
326
|
+
if (first === "branches" && second !== undefined && third === "body") {
|
|
327
|
+
next = `${path}/branches/${second}/body`;
|
|
328
|
+
i += 3;
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
case "workflow":
|
|
332
|
+
if (first === "workflow" && second === "root") {
|
|
333
|
+
next = `${path}/workflow/root`;
|
|
334
|
+
i += 2;
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
case "map": {
|
|
338
|
+
const index = indexOf(second);
|
|
339
|
+
if (first === "items" && index !== undefined && third === "body") {
|
|
340
|
+
at.push({ kind: "item", index });
|
|
341
|
+
next = `${path}/body`;
|
|
342
|
+
i += 3;
|
|
343
|
+
}
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case "loop": {
|
|
347
|
+
const index = indexOf(second);
|
|
348
|
+
if (first === "iterations" && index !== undefined && third === "body") {
|
|
349
|
+
at.push({ kind: "iteration", index });
|
|
350
|
+
next = `${path}/body`;
|
|
351
|
+
i += 3;
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (next === undefined || !kinds.has(next))
|
|
357
|
+
return undefined;
|
|
358
|
+
path = next;
|
|
359
|
+
}
|
|
360
|
+
return { path, at };
|
|
361
|
+
}
|
|
362
|
+
/** What changed between two graphs of a workflow, such as two saved revisions of one. A node is the same in both when its
|
|
363
|
+
* `(kind, label)` is unique in each graph, wherever it is: a step inserted before others is one `added` node and the rest
|
|
364
|
+
* `moved`, never a run of changes. A node whose `(kind, label)` repeats in either graph, or is in one only, is the same
|
|
365
|
+
* as the other graph's node at its path, unless that node is already matched by its identity; with a new kind or label
|
|
366
|
+
* it is `changed`. A matched node with its kind and label as they were and another `changeCheck` is `rewritten`; a node
|
|
367
|
+
* without a check in either graph is never reported rewritten. An edge is the same when both its ends are the same nodes
|
|
368
|
+
* and its kind is the same. Every list is in its graph's node or edge order. */
|
|
369
|
+
export function graphDiff(prev, next) {
|
|
370
|
+
const identity = (node) => JSON.stringify([node.kind, node.label]);
|
|
371
|
+
const counts = (graph) => {
|
|
372
|
+
const count = new Map();
|
|
373
|
+
for (const node of graph.nodes)
|
|
374
|
+
count.set(identity(node), (count.get(identity(node)) ?? 0) + 1);
|
|
375
|
+
return count;
|
|
376
|
+
};
|
|
377
|
+
const [inPrev, inNext] = [counts(prev), counts(next)];
|
|
378
|
+
const unique = (node) => inPrev.get(identity(node)) === 1 && inNext.get(identity(node)) === 1;
|
|
379
|
+
// The matched nodes, each way: a path of `next` to its node's path in `prev`, and back.
|
|
380
|
+
const prevOf = new Map();
|
|
381
|
+
const nextOf = new Map();
|
|
382
|
+
const match = (from, to) => { prevOf.set(to, from); nextOf.set(from, to); };
|
|
383
|
+
const uniqueInPrev = new Map(prev.nodes.filter(unique).map((node) => [identity(node), node.path]));
|
|
384
|
+
for (const node of next.nodes) {
|
|
385
|
+
const at = unique(node) ? uniqueInPrev.get(identity(node)) : undefined;
|
|
386
|
+
if (at !== undefined)
|
|
387
|
+
match(at, node.path);
|
|
388
|
+
}
|
|
389
|
+
const prevAt = new Map(prev.nodes.map((node) => [node.path, node]));
|
|
390
|
+
const changed = [];
|
|
391
|
+
for (const node of next.nodes) {
|
|
392
|
+
const old = prevAt.get(node.path);
|
|
393
|
+
if (prevOf.has(node.path) || old === undefined || nextOf.has(old.path))
|
|
394
|
+
continue;
|
|
395
|
+
match(old.path, node.path);
|
|
396
|
+
if (old.kind !== node.kind || old.label !== node.label) {
|
|
397
|
+
changed.push({ prev: old.path, next: node.path, was: { kind: old.kind, label: old.label }, now: { kind: node.kind, label: node.label } });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const rewritten = [];
|
|
401
|
+
for (const node of next.nodes) {
|
|
402
|
+
const from = prevOf.get(node.path);
|
|
403
|
+
const old = from === undefined ? undefined : prevAt.get(from);
|
|
404
|
+
if (old === undefined || old.kind !== node.kind || old.label !== node.label)
|
|
405
|
+
continue;
|
|
406
|
+
if (old.changeCheck !== undefined && node.changeCheck !== undefined && old.changeCheck !== node.changeCheck) {
|
|
407
|
+
rewritten.push({ prev: old.path, next: node.path, kind: node.kind, label: node.label });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const reported = ({ path, kind, label }) => ({ path, kind, label });
|
|
411
|
+
const edgeKey = (from, to, kind) => JSON.stringify([from, to, kind]);
|
|
412
|
+
const prevEdges = new Set(prev.edges.map((edge) => edgeKey(edge.from, edge.to, edge.kind)));
|
|
413
|
+
const nextEdges = new Set(next.edges.map((edge) => edgeKey(edge.from, edge.to, edge.kind)));
|
|
414
|
+
// Whether the other graph has this edge: both its ends matched there, joined by an edge of the same kind.
|
|
415
|
+
const theirs = (edge, map, edges) => {
|
|
416
|
+
const [from, to] = [map.get(edge.from), map.get(edge.to)];
|
|
417
|
+
return from !== undefined && to !== undefined && edges.has(edgeKey(from, to, edge.kind));
|
|
418
|
+
};
|
|
419
|
+
return {
|
|
420
|
+
added: next.nodes.filter((node) => !prevOf.has(node.path)).map(reported),
|
|
421
|
+
removed: prev.nodes.filter((node) => !nextOf.has(node.path)).map(reported),
|
|
422
|
+
changed,
|
|
423
|
+
moved: next.nodes.flatMap((node) => {
|
|
424
|
+
const from = prevOf.get(node.path);
|
|
425
|
+
return from !== undefined && from !== node.path ? [{ prev: from, next: node.path }] : [];
|
|
426
|
+
}),
|
|
427
|
+
rewritten,
|
|
428
|
+
edges: {
|
|
429
|
+
added: next.edges.filter((edge) => !theirs(edge, prevOf, prevEdges)).map(({ from, to, kind }) => ({ from, to, kind })),
|
|
430
|
+
removed: prev.edges.filter((edge) => !theirs(edge, nextOf, nextEdges)).map(({ from, to, kind }) => ({ from, to, kind })),
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
export { defineWorkflow, runTypedWorkflow, WorkflowSchemaConversionError } from "./authoring.js";
|
|
2
2
|
export type { StandardJSONSchema, AuthoringSchema, TypedWorkflow, TypedWorkflowRunResult, WorkflowInput, WorkflowOutput, } from "./authoring.js";
|
|
3
|
-
export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, } from "./workflow.js";
|
|
3
|
+
export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, isItemFailure, MAP_LIMITS, } from "./workflow.js";
|
|
4
4
|
export { defineJob } from "./job.js";
|
|
5
5
|
export type { Job } from "./job.js";
|
|
6
|
-
export { DECISION_RECEIPT_VERSION, rederiveDecision } from "./decision-receipts.js";
|
|
7
|
-
export type { DecisionKind, DecisionReceipt, DecisionRule } from "./decision-receipts.js";
|
|
8
|
-
export type { Workflow, WorkflowNode, NodeMetadata, WorkflowDeps, WorkflowEvent, WorkflowRunResult, HostPolicy, HostPolicyContext, Escalation, EffectSettlement, MapItem, DecisionExchange, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, RouteByJudgmentNode, RouteByValueNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CodeNode, CallRetryClass, EffectFailureCode, CallPredicate, PollClause, ModelTier, AgentContext, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, MechanicalPredicate, Predicate, } from "./workflow.js";
|
|
9
|
-
export { dryRunWorkflow, synthesizeInstance } from "./dry-run.js";
|
|
6
|
+
export { DECISION_RECEIPT_VERSION, DECISION_INTERRUPTED, DECISION_REFUSED, DECISION_STATE_MAX_BYTES, rederiveDecision } from "./decision-receipts.js";
|
|
7
|
+
export type { DecisionImageDigest, DecisionKind, DecisionReceipt, DecisionRule, DecisionStateCut, DecisionStateSent } from "./decision-receipts.js";
|
|
8
|
+
export type { Workflow, WorkflowNode, NodeMetadata, WorkflowDeps, MapLimits, WorkflowEvent, WorkflowRunResult, HostPolicy, HostPolicyContext, Escalation, EffectSettlement, MapItem, MapItemFailure, DecisionExchange, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, RouteByJudgmentNode, RouteByValueNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CodeNode, CallRetryClass, EffectFailureCode, CallPredicate, PollClause, ModelTier, AgentContext, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, DecisionEvidenceMode, DecisionImages, MechanicalPredicate, Predicate, ValidationCode, ValidationIssue, ValidateWorkflowOptions, } from "./workflow.js";
|
|
9
|
+
export { dryRunWorkflow, SYNTHESIS_BUDGET, SynthesisTooLarge, synthesizeInstance, type SynthesisBudget } from "./dry-run.js";
|
|
10
10
|
export type { DryRunOptions, DryRunResult } from "./dry-run.js";
|
|
11
|
-
export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, } from "./system-one.js";
|
|
12
|
-
export type { SystemOneQuestion, SystemOneAnswer, SystemOneBox, SystemOneResult, SystemOneRetryClass, SystemOneResponseReason, CompiledQuestions, AnswersSidecar, } from "./system-one.js";
|
|
11
|
+
export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, deriveConfidence, completeConfidence, refusedQuestions, } from "./system-one.js";
|
|
12
|
+
export type { SystemOneQuestion, SystemOneAnswer, SystemOneBox, SystemOneResult, SystemOneRetryClass, SystemOneResponseReason, CompiledQuestions, AnswersSidecar, ConfidenceSource, } from "./system-one.js";
|
|
13
|
+
export { judgeFromProvider, judgeFromProviders, checkCapabilities, chargedCost, DecisionProviderError, imageDimensions } from "./decision-provider.js";
|
|
14
|
+
export { evidenceOf, EVIDENCE_EXCERPT_MAX, EVIDENCE_EXCERPTS_PER_ITEM, EVIDENCE_ITEMS_MAX, EVIDENCE_TEXT_MAX, EVIDENCE_TITLE_MAX, type EvidenceOptions } from "./evidence.js";
|
|
15
|
+
export type { DecisionProvider, DecisionCapabilities, DecisionInput, DecisionRequest, DecisionContext, DecisionEvidence, DecisionOutcome, ProviderAnswer, CostBasis, DecisionProviderErrorCode, DecisionImage, LoadImage, JudgeFromProviderOptions, } from "./decision-provider.js";
|
|
13
16
|
export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
|
|
14
17
|
export type { WorkflowInspection, WorkflowInspectionNode } from "./inspection.js";
|
|
15
|
-
export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, childSteps, declaredWrites,
|
|
16
|
-
export { compileTransform, compileTransformSyntax, deniedGlobalReferences } from "./code-exec.js";
|
|
18
|
+
export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY, normalizeStringNullsForSchema, placeholderValue, placeholdersOf, } from "./workflow.js";
|
|
19
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences, type TransformOutcome, transformScript } from "./code-exec.js";
|
|
17
20
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
21
|
+
export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
|
|
22
|
+
export { submitParameters } from "./submit-envelope.js";
|
|
18
23
|
export { getPath, predicateMatches } from "./predicates.js";
|
|
19
24
|
export type { StopPredicate, AcceptPredicate } from "./predicates.js";
|
|
20
|
-
export { authorContract, renderAuthorContract, renderAuthorHostAddendum,
|
|
25
|
+
export { authorContract, renderAuthorContract, renderAuthorHostAddendum, applyHostOutputTypes, authorWorkflow, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
|
|
21
26
|
export type { AuthorHostAddendum, CandidatePolicyOptions, AuthorWorkflowOptions, AuthoredWorkflow, HostOutputTypeOptions } from "./author.js";
|
|
22
|
-
export {
|
|
23
|
-
export type { WorkflowNodeKind, WorkflowPredicateName } from "./vocabulary.js";
|
|
27
|
+
export { GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, FIELD_TYPES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
|
28
|
+
export type { WorkflowNodeKind, WorkflowPredicateName, FieldType } from "./vocabulary.js";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
export { defineWorkflow, runTypedWorkflow, WorkflowSchemaConversionError } from "./authoring.js";
|
|
2
|
-
export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, } from "./workflow.js";
|
|
2
|
+
export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, isItemFailure, MAP_LIMITS, } from "./workflow.js";
|
|
3
3
|
export { defineJob } from "./job.js";
|
|
4
|
-
export { DECISION_RECEIPT_VERSION, rederiveDecision } from "./decision-receipts.js";
|
|
5
|
-
export { dryRunWorkflow, synthesizeInstance } from "./dry-run.js";
|
|
6
|
-
export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, } from "./system-one.js";
|
|
4
|
+
export { DECISION_RECEIPT_VERSION, DECISION_INTERRUPTED, DECISION_REFUSED, DECISION_STATE_MAX_BYTES, rederiveDecision } from "./decision-receipts.js";
|
|
5
|
+
export { dryRunWorkflow, SYNTHESIS_BUDGET, SynthesisTooLarge, synthesizeInstance } from "./dry-run.js";
|
|
6
|
+
export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, deriveConfidence, completeConfidence, refusedQuestions, } from "./system-one.js";
|
|
7
|
+
export { judgeFromProvider, judgeFromProviders, checkCapabilities, chargedCost, DecisionProviderError, imageDimensions } from "./decision-provider.js";
|
|
8
|
+
export { evidenceOf, EVIDENCE_EXCERPT_MAX, EVIDENCE_EXCERPTS_PER_ITEM, EVIDENCE_ITEMS_MAX, EVIDENCE_TEXT_MAX, EVIDENCE_TITLE_MAX } from "./evidence.js";
|
|
7
9
|
export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
|
|
8
10
|
export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA,
|
|
9
11
|
// Document helpers a host facade needs to speak about a workflow without re-implementing the walk.
|
|
10
|
-
childSteps, declaredWrites,
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY,
|
|
13
|
+
// The host-side normalization the interpreter itself uses.
|
|
14
|
+
normalizeStringNullsForSchema,
|
|
15
|
+
// Interpolation's placeholders in a string and its lookup order for one, for a host check of what a step reads.
|
|
16
|
+
placeholderValue, placeholdersOf, } from "./workflow.js";
|
|
17
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences, transformScript } from "./code-exec.js";
|
|
14
18
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
19
|
+
export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
|
|
20
|
+
export { submitParameters } from "./submit-envelope.js";
|
|
15
21
|
export { getPath, predicateMatches } from "./predicates.js";
|
|
16
|
-
export { authorContract, renderAuthorContract, renderAuthorHostAddendum,
|
|
17
|
-
export {
|
|
22
|
+
export { authorContract, renderAuthorContract, renderAuthorHostAddendum, applyHostOutputTypes, authorWorkflow, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
|
|
23
|
+
export { GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, FIELD_TYPES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
package/dist/inspection.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export type WorkflowInspectionNode = {
|
|
|
11
11
|
/** Effective selection from completed map-item state; absent means whole item state. */
|
|
12
12
|
resultPath?: string;
|
|
13
13
|
childWorkflow?: string;
|
|
14
|
+
/** A decision node's (or an `ask` predicate's) provider and pinned model, when it names them, and the tokens of the
|
|
15
|
+
* images it sends. */
|
|
16
|
+
provider?: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
images?: string[];
|
|
14
19
|
};
|
|
15
20
|
export type WorkflowInspection = {
|
|
16
21
|
name: string;
|
package/dist/inspection.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { routesByValue, workflowDocumentError, workflowSha256 } from "./workflow.js";
|
|
2
2
|
import { workflowShapeErrors } from "./workflow-shape.js";
|
|
3
|
+
/** What a decision node, or a loop's or escalate's `ask` predicate, names of its provider, model and images. */
|
|
4
|
+
function decisionFields(node) {
|
|
5
|
+
const source = node.node === "loop" ? node.until : node.node === "escalate" ? node.when
|
|
6
|
+
: ["judge", "pick", "sift"].includes(node.node) || node.node === "route" && !routesByValue(node) ? node : undefined;
|
|
7
|
+
if (!source || ((node.node === "loop" || node.node === "escalate") && source.predicate !== "ask"))
|
|
8
|
+
return {};
|
|
9
|
+
const { provider, model, images } = source;
|
|
10
|
+
return {
|
|
11
|
+
...(typeof provider === "string" ? { provider } : {}), ...(typeof model === "string" ? { model } : {}),
|
|
12
|
+
...(images && typeof images === "object" && Object.keys(images).length ? { images: Object.keys(images) } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
3
15
|
const pointer = (part) => part.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4
16
|
/** Inspect a workflow's structure without running authored code, adapters, or schema probes.
|
|
5
17
|
* The input must be plain JSON data. This is a review aid, not execution admission: use
|
|
@@ -26,7 +38,8 @@ export function inspectWorkflow(value) {
|
|
|
26
38
|
...("out" in node && node.out && node.node !== "sift" ? { outputSchema: node.out } : {}),
|
|
27
39
|
...(node.node === "map" && (node.resultPath || "as" in node.body && node.body.as)
|
|
28
40
|
? { resultPath: node.resultPath || node.body.as } : {}),
|
|
29
|
-
...(node.node === "workflow" ? { childWorkflow: node.workflow.name } : {}),
|
|
41
|
+
...(node.node === "workflow" ? { childWorkflow: node.workflow.name } : {}),
|
|
42
|
+
...decisionFields(node), });
|
|
30
43
|
if (["agent", "decide", "extract", "report"].includes(node.node) ||
|
|
31
44
|
node.node === "artifact" && ["markdown", "report"].includes(node.type))
|
|
32
45
|
adapters.add("runNode");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The longest pattern read (characters), and the most quantifiers in one: a schema pattern is a few dozen of each. */
|
|
2
|
+
export declare const PATTERN_SCREEN_LIMITS: {
|
|
3
|
+
readonly chars: 4096;
|
|
4
|
+
readonly quantifiers: 128;
|
|
5
|
+
};
|
|
6
|
+
/** Why `pattern` may backtrack exponentially (or could not be read), or undefined when it is safe to test strings
|
|
7
|
+
* against. */
|
|
8
|
+
export declare function patternRisk(pattern: string): string | undefined;
|
|
9
|
+
/** Each pattern `schema` would test strings with (a `pattern`, a `patternProperties` key) that may backtrack
|
|
10
|
+
* exponentially, with why. */
|
|
11
|
+
export declare function riskyPatterns(schema: unknown): {
|
|
12
|
+
pattern: string;
|
|
13
|
+
why: string;
|
|
14
|
+
}[];
|