@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.
Files changed (103) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +171 -23
  3. package/dist/author-references.d.ts +8 -0
  4. package/dist/author-references.js +8 -0
  5. package/dist/author.d.ts +16 -5
  6. package/dist/author.js +46 -21
  7. package/dist/authoring.js +5 -4
  8. package/dist/cli.js +19 -13
  9. package/dist/code-exec.d.ts +25 -0
  10. package/dist/code-exec.js +180 -5
  11. package/dist/decision-provider.d.ts +166 -0
  12. package/dist/decision-provider.js +238 -0
  13. package/dist/decision-receipts.d.ts +159 -0
  14. package/dist/decision-receipts.js +93 -0
  15. package/dist/dry-run.d.ts +45 -2
  16. package/dist/dry-run.js +159 -27
  17. package/dist/edit.d.ts +158 -0
  18. package/dist/edit.js +1486 -0
  19. package/dist/evidence.d.ts +19 -0
  20. package/dist/evidence.js +63 -0
  21. package/dist/graph.d.ts +169 -0
  22. package/dist/graph.js +433 -0
  23. package/dist/index.d.ts +21 -11
  24. package/dist/index.js +18 -9
  25. package/dist/inspection.d.ts +5 -0
  26. package/dist/inspection.js +16 -3
  27. package/dist/job.d.ts +14 -0
  28. package/dist/job.js +5 -0
  29. package/dist/long-timer.d.ts +7 -0
  30. package/dist/long-timer.js +22 -0
  31. package/dist/observer-snapshot.d.ts +3 -0
  32. package/dist/observer-snapshot.js +46 -0
  33. package/dist/pattern-screen.d.ts +14 -0
  34. package/dist/pattern-screen.js +451 -0
  35. package/dist/pointer-warning.d.ts +14 -0
  36. package/dist/pointer-warning.js +22 -0
  37. package/dist/predicates.d.ts +32 -2
  38. package/dist/predicates.js +66 -6
  39. package/dist/record.d.ts +4 -0
  40. package/dist/record.js +6 -0
  41. package/dist/recovery/binding.d.ts +10 -0
  42. package/dist/recovery/binding.js +44 -0
  43. package/dist/recovery/call-key.d.ts +9 -0
  44. package/dist/recovery/call-key.js +17 -0
  45. package/dist/recovery/canonical-hash.d.ts +7 -0
  46. package/dist/recovery/canonical-hash.js +22 -0
  47. package/dist/recovery/driver.d.ts +244 -0
  48. package/dist/recovery/driver.js +1359 -0
  49. package/dist/recovery/errors.d.ts +31 -0
  50. package/dist/recovery/errors.js +51 -0
  51. package/dist/recovery/execution-path.d.ts +53 -0
  52. package/dist/recovery/execution-path.js +167 -0
  53. package/dist/recovery/file-store.d.ts +7 -0
  54. package/dist/recovery/file-store.js +131 -0
  55. package/dist/recovery/frozen-snapshot.d.ts +274 -0
  56. package/dist/recovery/frozen-snapshot.js +187 -0
  57. package/dist/recovery/handoff-receipts.d.ts +7 -0
  58. package/dist/recovery/handoff-receipts.js +11 -0
  59. package/dist/recovery/index.d.ts +14 -0
  60. package/dist/recovery/index.js +13 -0
  61. package/dist/recovery/item-state.d.ts +49 -0
  62. package/dist/recovery/item-state.js +83 -0
  63. package/dist/recovery/journal.d.ts +28 -0
  64. package/dist/recovery/journal.js +139 -0
  65. package/dist/recovery/memory-store.d.ts +4 -0
  66. package/dist/recovery/memory-store.js +20 -0
  67. package/dist/recovery/store.d.ts +105 -0
  68. package/dist/recovery/store.js +6 -0
  69. package/dist/recovery/testing/conformance.d.ts +4 -0
  70. package/dist/recovery/testing/conformance.js +268 -0
  71. package/dist/recovery/testing/crash-points.d.ts +18 -0
  72. package/dist/recovery/testing/crash-points.js +43 -0
  73. package/dist/recovery/testing/crash-sweep.d.ts +65 -0
  74. package/dist/recovery/testing/crash-sweep.js +146 -0
  75. package/dist/recovery/testing/index.d.ts +3 -0
  76. package/dist/recovery/testing/index.js +4 -0
  77. package/dist/recovery/testing/preload.d.ts +1 -0
  78. package/dist/recovery/testing/preload.js +3 -0
  79. package/dist/recovery/transport-facts.d.ts +23 -0
  80. package/dist/recovery/transport-facts.js +46 -0
  81. package/dist/recovery/with-recovery.d.ts +50 -0
  82. package/dist/recovery/with-recovery.js +144 -0
  83. package/dist/submit-envelope.d.ts +9 -0
  84. package/dist/submit-envelope.js +44 -0
  85. package/dist/system-one.d.ts +37 -2
  86. package/dist/system-one.js +146 -11
  87. package/dist/testing/decision-provider.d.ts +32 -0
  88. package/dist/testing/decision-provider.js +183 -0
  89. package/dist/testing/index.d.ts +1 -0
  90. package/dist/testing/index.js +2 -0
  91. package/dist/vocabulary.d.ts +27 -3
  92. package/dist/vocabulary.js +39 -10
  93. package/dist/workflow-shape.d.ts +7 -0
  94. package/dist/workflow-shape.js +119 -69
  95. package/dist/workflow.d.ts +329 -29
  96. package/dist/workflow.js +1704 -490
  97. package/dist/zod-json-contract.js +6 -8
  98. package/package.json +31 -4
  99. package/schema/workflow.schema.json +599 -12
  100. package/skills/author/SKILL.md +6 -1
  101. package/skills/author/references/jev-decisions.md +69 -12
  102. package/skills/author/references/language.md +31 -21
  103. package/skills/author/references/sdk-authoring.md +2 -0
@@ -1,18 +1,45 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { Compile } from "typebox/compile";
3
- const documentSchema = createRequire(import.meta.url)("../schema/workflow.schema.json");
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
- const nodeSchemas = new Map(documentSchema.definitions.WorkflowNode.anyOf.map((schema) => [schema.properties.node.const, schema]));
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 selected = isRecord(entry) && typeof entry.node === "string" ? nodeSchemas.get(entry.node) : undefined;
36
- if (selected)
37
- check(selected, entry, path);
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 = (path, expected) => { errors.push(`${path} must be ${expected}`); };
72
- const record = (entry, path) => {
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(path, "an object");
121
+ fail(loc, "an object");
76
122
  return false;
77
123
  };
78
- const strings = (entry, path, keys) => {
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(`${path}.${key}`, "a string");
127
+ fail(at(loc, key), "a string");
82
128
  };
83
- const stringList = (entry, path) => {
129
+ const stringList = (entry, loc) => {
84
130
  if (entry === undefined)
85
131
  return;
86
132
  if (!Array.isArray(entry)) {
87
- fail(path, "an array of strings");
133
+ fail(loc, "an array of strings");
88
134
  return;
89
135
  }
90
- entry.forEach((item, index) => { if (typeof item !== "string")
91
- fail(`${path}[${index}]`, "a string"); });
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, path, keys) => {
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(`${path}.${key}`, "a number");
145
+ fail(at(loc, key), "a number");
100
146
  }
101
147
  };
102
- const objectField = (entry, path, key, visit) => {
148
+ const objectField = (entry, loc, key, visit) => {
103
149
  if (entry[key] === undefined)
104
150
  return;
105
- if (record(entry[key], `${path}.${key}`))
106
- visit?.(entry[key], `${path}.${key}`);
151
+ if (record(entry[key], at(loc, key)))
152
+ visit?.(entry[key], at(loc, key));
107
153
  };
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"]));
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, path) => {
160
+ const node = (entry, loc) => {
115
161
  if (entry === undefined)
116
162
  return; // missing bodies already receive semantic diagnostics
117
- if (!record(entry, path))
163
+ if (!record(entry, loc))
118
164
  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"]);
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], `${path}.${key}`);
168
+ stringList(entry[key], at(loc, key));
123
169
  if (entry.sopSection !== undefined && typeof entry.sopSection !== "string")
124
- stringList(entry.sopSection, `${path}.sopSection`);
170
+ stringList(entry.sopSection, at(loc, "sopSection"));
125
171
  for (const key of ["state", "args", "input", "env"])
126
- objectField(entry, path, key);
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, path, key, predicate);
129
- objectField(entry, path, "verify", (verify, at) => {
130
- strings(verify, at, ["out"]);
131
- numeric(verify, at, ["maxDrives"]);
132
- objectField(verify, at, "state");
133
- objectField(verify, at, "override", (override, here) => numeric(override, here, ["below"]));
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, path, "keep", (keep, at) => { strings(keep, at, ["path"]); numeric(keep, at, ["gte"]); });
136
- objectField(entry, path, "unsure", (unsure, at) => { strings(unsure, at, ["branch"]); numeric(unsure, at, ["gte"]); });
137
- objectField(entry, path, "retry", (retry, at) => {
138
- numeric(retry, at, ["attempts", "backoff_s"]);
139
- stringList(retry.on, `${at}.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, path, "poll", (poll, at) => {
142
- numeric(poll, at, ["interval_s", "deadline_s"]);
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, at, key, predicate);
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(`${path}.${key}`, "an array of nodes");
200
+ fail(at(loc, key), "an array of nodes");
151
201
  else
152
- entry[key].forEach((child, index) => node(child, `${path}.${key}[${index}]`));
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, `${path}.body`);
206
+ node(entry.body, at(loc, "body"));
157
207
  if (entry.node === "route")
158
- objectField(entry, path, "branches", (branches, at) => {
208
+ objectField(entry, loc, "branches", (branches, here) => {
159
209
  for (const [name, branch] of Object.entries(branches))
160
- if (record(branch, `${at}.${name}`)) {
161
- strings(branch, `${at}.${name}`, ["criteria"]);
162
- node(branch.body, `${at}.${name}.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, `${path}.workflow`);
216
+ workflow(entry.workflow, at(loc, "workflow"));
167
217
  };
168
- const workflow = (entry, path) => {
169
- if (!record(entry, path))
218
+ const workflow = (entry, loc) => {
219
+ if (!record(entry, loc))
170
220
  return;
171
- strings(entry, path, ["name"]);
172
- record(entry.schemas, `${path}.schemas`);
173
- objectField(entry, path, "input", (input, at) => strings(input, at, ["schemaId"]));
174
- if (record(entry.output, `${path}.output`))
175
- strings(entry.output, `${path}.output`, ["schemaId", "path"]);
176
- if (record(entry.root, `${path}.root`))
177
- node(entry.root, `${path}.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
  }