@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.
Files changed (93) hide show
  1. package/README.md +167 -23
  2. package/dist/author-references.d.ts +8 -0
  3. package/dist/author-references.js +8 -0
  4. package/dist/author.d.ts +13 -5
  5. package/dist/author.js +47 -18
  6. package/dist/authoring.js +2 -2
  7. package/dist/cli.js +17 -12
  8. package/dist/code-exec.d.ts +6 -0
  9. package/dist/code-exec.js +126 -0
  10. package/dist/decision-provider.d.ts +165 -0
  11. package/dist/decision-provider.js +238 -0
  12. package/dist/decision-receipts.d.ts +159 -0
  13. package/dist/decision-receipts.js +93 -0
  14. package/dist/dry-run.d.ts +45 -2
  15. package/dist/dry-run.js +159 -26
  16. package/dist/evidence.d.ts +19 -0
  17. package/dist/evidence.js +62 -0
  18. package/dist/graph.d.ts +169 -0
  19. package/dist/graph.js +433 -0
  20. package/dist/index.d.ts +19 -11
  21. package/dist/index.js +14 -9
  22. package/dist/inspection.d.ts +5 -0
  23. package/dist/inspection.js +16 -3
  24. package/dist/job.d.ts +14 -0
  25. package/dist/job.js +5 -0
  26. package/dist/long-timer.d.ts +7 -0
  27. package/dist/long-timer.js +22 -0
  28. package/dist/observer-snapshot.d.ts +3 -0
  29. package/dist/observer-snapshot.js +46 -0
  30. package/dist/predicates.d.ts +32 -0
  31. package/dist/predicates.js +61 -0
  32. package/dist/recovery/binding.d.ts +10 -0
  33. package/dist/recovery/binding.js +43 -0
  34. package/dist/recovery/call-key.d.ts +9 -0
  35. package/dist/recovery/call-key.js +17 -0
  36. package/dist/recovery/canonical-hash.d.ts +7 -0
  37. package/dist/recovery/canonical-hash.js +22 -0
  38. package/dist/recovery/driver.d.ts +235 -0
  39. package/dist/recovery/driver.js +1333 -0
  40. package/dist/recovery/errors.d.ts +31 -0
  41. package/dist/recovery/errors.js +51 -0
  42. package/dist/recovery/execution-path.d.ts +53 -0
  43. package/dist/recovery/execution-path.js +167 -0
  44. package/dist/recovery/file-store.d.ts +7 -0
  45. package/dist/recovery/file-store.js +131 -0
  46. package/dist/recovery/frozen-snapshot.d.ts +274 -0
  47. package/dist/recovery/frozen-snapshot.js +187 -0
  48. package/dist/recovery/handoff-receipts.d.ts +7 -0
  49. package/dist/recovery/handoff-receipts.js +10 -0
  50. package/dist/recovery/index.d.ts +14 -0
  51. package/dist/recovery/index.js +13 -0
  52. package/dist/recovery/item-state.d.ts +48 -0
  53. package/dist/recovery/item-state.js +89 -0
  54. package/dist/recovery/journal.d.ts +28 -0
  55. package/dist/recovery/journal.js +139 -0
  56. package/dist/recovery/memory-store.d.ts +4 -0
  57. package/dist/recovery/memory-store.js +20 -0
  58. package/dist/recovery/store.d.ts +105 -0
  59. package/dist/recovery/store.js +6 -0
  60. package/dist/recovery/testing/conformance.d.ts +4 -0
  61. package/dist/recovery/testing/conformance.js +268 -0
  62. package/dist/recovery/testing/crash-points.d.ts +18 -0
  63. package/dist/recovery/testing/crash-points.js +43 -0
  64. package/dist/recovery/testing/crash-sweep.d.ts +65 -0
  65. package/dist/recovery/testing/crash-sweep.js +146 -0
  66. package/dist/recovery/testing/index.d.ts +3 -0
  67. package/dist/recovery/testing/index.js +4 -0
  68. package/dist/recovery/testing/preload.d.ts +1 -0
  69. package/dist/recovery/testing/preload.js +3 -0
  70. package/dist/recovery/transport-facts.d.ts +23 -0
  71. package/dist/recovery/transport-facts.js +46 -0
  72. package/dist/recovery/with-recovery.d.ts +50 -0
  73. package/dist/recovery/with-recovery.js +144 -0
  74. package/dist/submit-envelope.d.ts +9 -0
  75. package/dist/submit-envelope.js +40 -0
  76. package/dist/system-one.d.ts +40 -2
  77. package/dist/system-one.js +141 -6
  78. package/dist/testing/decision-provider.d.ts +32 -0
  79. package/dist/testing/decision-provider.js +183 -0
  80. package/dist/testing/index.d.ts +1 -0
  81. package/dist/testing/index.js +2 -0
  82. package/dist/vocabulary.d.ts +31 -3
  83. package/dist/vocabulary.js +46 -14
  84. package/dist/workflow-shape.d.ts +7 -0
  85. package/dist/workflow-shape.js +112 -68
  86. package/dist/workflow.d.ts +362 -29
  87. package/dist/workflow.js +1844 -430
  88. package/package.json +27 -4
  89. package/schema/workflow.schema.json +551 -12
  90. package/skills/author/SKILL.md +6 -1
  91. package/skills/author/references/jev-decisions.md +69 -12
  92. package/skills/author/references/language.md +41 -24
  93. package/skills/author/references/sdk-authoring.md +2 -0
@@ -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
- const nodeSchemas = new Map(documentSchema.definitions.WorkflowNode.anyOf.map((schema) => [schema.properties.node.const, schema]));
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 selected = isRecord(entry) && typeof entry.node === "string" ? nodeSchemas.get(entry.node) : undefined;
36
- if (selected)
37
- check(selected, entry, path);
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 = (path, expected) => { errors.push(`${path} must be ${expected}`); };
72
- const record = (entry, path) => {
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(path, "an object");
119
+ fail(loc, "an object");
76
120
  return false;
77
121
  };
78
- const strings = (entry, path, keys) => {
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(`${path}.${key}`, "a string");
125
+ fail(at(loc, key), "a string");
82
126
  };
83
- const stringList = (entry, path) => {
127
+ const stringList = (entry, loc) => {
84
128
  if (entry === undefined)
85
129
  return;
86
130
  if (!Array.isArray(entry)) {
87
- fail(path, "an array of strings");
131
+ fail(loc, "an array of strings");
88
132
  return;
89
133
  }
90
- entry.forEach((item, index) => { if (typeof item !== "string")
91
- fail(`${path}[${index}]`, "a string"); });
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, path, keys) => {
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(`${path}.${key}`, "a number");
143
+ fail(at(loc, key), "a number");
100
144
  }
101
145
  };
102
- const objectField = (entry, path, key, visit) => {
146
+ const objectField = (entry, loc, key, visit) => {
103
147
  if (entry[key] === undefined)
104
148
  return;
105
- if (record(entry[key], `${path}.${key}`))
106
- visit?.(entry[key], `${path}.${key}`);
149
+ if (record(entry[key], at(loc, key)))
150
+ visit?.(entry[key], at(loc, key));
107
151
  };
108
- const predicate = (entry, path) => {
109
- strings(entry, path, ["predicate", "path", "key", "instructions"]);
110
- numeric(entry, path, ["n", "gte"]);
111
- objectField(entry, path, "state");
112
- objectField(entry, path, "criteria", (criteria, at) => strings(criteria, at, ["true", "false"]));
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, path) => {
158
+ const node = (entry, loc) => {
115
159
  if (entry === undefined)
116
160
  return; // missing bodies already receive semantic diagnostics
117
- if (!record(entry, path))
161
+ if (!record(entry, loc))
118
162
  return;
119
- strings(entry, path, ["node", "label", "code", "as", "out", "instructions", "itemsPath", "resultPath", "kind", "stage", "summary", "describe", "type", "path", "tool", "command", "via", "where", "effort", "thinking", "tier"]);
120
- numeric(entry, path, ["maxConcurrency", "maxIters", "deadline_s"]);
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], `${path}.${key}`);
166
+ stringList(entry[key], at(loc, key));
123
167
  if (entry.sopSection !== undefined && typeof entry.sopSection !== "string")
124
- stringList(entry.sopSection, `${path}.sopSection`);
168
+ stringList(entry.sopSection, at(loc, "sopSection"));
125
169
  for (const key of ["state", "args", "input", "env"])
126
- objectField(entry, path, key);
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(`${path} (${typeof entry.label === "string" && entry.label ? entry.label : String(entry.node)}): metadata must be a plain object of host markers`);
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, path, key, predicate);
133
- objectField(entry, path, "verify", (verify, at) => {
134
- strings(verify, at, ["out"]);
135
- numeric(verify, at, ["maxDrives"]);
136
- objectField(verify, at, "state");
137
- objectField(verify, at, "override", (override, here) => numeric(override, here, ["below"]));
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, path, "keep", (keep, at) => { strings(keep, at, ["path"]); numeric(keep, at, ["gte"]); });
140
- objectField(entry, path, "unsure", (unsure, at) => { strings(unsure, at, ["branch"]); numeric(unsure, at, ["gte"]); });
141
- objectField(entry, path, "retry", (retry, at) => {
142
- numeric(retry, at, ["attempts", "backoff_s"]);
143
- stringList(retry.on, `${at}.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, path, "poll", (poll, at) => {
146
- numeric(poll, at, ["interval_s", "deadline_s"]);
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, at, key, predicate);
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(`${path}.${key}`, "an array of nodes");
198
+ fail(at(loc, key), "an array of nodes");
155
199
  else
156
- entry[key].forEach((child, index) => node(child, `${path}.${key}[${index}]`));
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, `${path}.body`);
204
+ node(entry.body, at(loc, "body"));
161
205
  if (entry.node === "route")
162
- objectField(entry, path, "branches", (branches, at) => {
206
+ objectField(entry, loc, "branches", (branches, here) => {
163
207
  for (const [name, branch] of Object.entries(branches))
164
- if (record(branch, `${at}.${name}`)) {
165
- strings(branch, `${at}.${name}`, ["criteria"]);
166
- node(branch.body, `${at}.${name}.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, `${path}.workflow`);
214
+ workflow(entry.workflow, at(loc, "workflow"));
171
215
  };
172
- const workflow = (entry, path) => {
173
- if (!record(entry, path))
216
+ const workflow = (entry, loc) => {
217
+ if (!record(entry, loc))
174
218
  return;
175
- strings(entry, path, ["name"]);
176
- record(entry.schemas, `${path}.schemas`);
177
- objectField(entry, path, "input", (input, at) => strings(input, at, ["schemaId"]));
178
- if (record(entry.output, `${path}.output`))
179
- strings(entry.output, `${path}.output`, ["schemaId", "path"]);
180
- if (record(entry.root, `${path}.root`))
181
- node(entry.root, `${path}.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
  }