@parcha/agentrun-dsl 0.1.0-beta.2 → 0.1.0-beta.4

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.
@@ -124,6 +124,10 @@ export function workflowShapeErrors(value, complete = false) {
124
124
  stringList(entry.sopSection, `${path}.sopSection`);
125
125
  for (const key of ["state", "args", "input", "env"])
126
126
  objectField(entry, path, key);
127
+ // Host-owned and opaque: only its container is checked, never its keys or values.
128
+ 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`);
130
+ }
127
131
  for (const key of ["until", "when"])
128
132
  objectField(entry, path, key, predicate);
129
133
  objectField(entry, path, "verify", (verify, at) => {
@@ -28,14 +28,21 @@ export type Predicate = MechanicalPredicate | AskPredicate;
28
28
  export type WorkflowEffort = "minimal" | "low" | "medium" | "high";
29
29
  /** The author's thinking dial. There is deliberately no "off": thinking is never off. */
30
30
  export type WorkflowThinking = "low" | "medium" | "high";
31
+ /** Host-owned markers on a node: any JSON object. The engine admits, carries and hashes it with the
32
+ * document and never reads it; it never reaches state, events, prompts or effect identities. */
33
+ export type NodeMetadata = {
34
+ [key: string]: unknown;
35
+ };
31
36
  export type WorkflowNode = {
32
37
  node: "chain";
33
38
  steps: WorkflowNode[];
39
+ metadata?: NodeMetadata;
34
40
  } | {
35
41
  node: "code";
36
42
  label: string;
37
43
  code: string;
38
44
  as?: string;
45
+ metadata?: NodeMetadata;
39
46
  } | {
40
47
  node: "agent";
41
48
  label: string;
@@ -50,6 +57,7 @@ export type WorkflowNode = {
50
57
  thinking?: WorkflowThinking;
51
58
  verify?: VerifyClause;
52
59
  tier?: ModelTier;
60
+ metadata?: NodeMetadata;
53
61
  } | {
54
62
  node: "decide";
55
63
  label: string;
@@ -64,6 +72,7 @@ export type WorkflowNode = {
64
72
  thinking?: WorkflowThinking;
65
73
  verify?: VerifyClause;
66
74
  tier?: ModelTier;
75
+ metadata?: NodeMetadata;
67
76
  } | {
68
77
  node: "extract";
69
78
  label: string;
@@ -78,6 +87,7 @@ export type WorkflowNode = {
78
87
  thinking?: WorkflowThinking;
79
88
  verify?: VerifyClause;
80
89
  tier?: ModelTier;
90
+ metadata?: NodeMetadata;
81
91
  } | {
82
92
  node: "report";
83
93
  label: string;
@@ -88,6 +98,7 @@ export type WorkflowNode = {
88
98
  tools?: string[];
89
99
  effort?: WorkflowEffort;
90
100
  thinking?: WorkflowThinking;
101
+ metadata?: NodeMetadata;
91
102
  } | ArtifactNode | {
92
103
  node: "map";
93
104
  label: string;
@@ -96,16 +107,19 @@ export type WorkflowNode = {
96
107
  as: string;
97
108
  resultPath?: string;
98
109
  maxConcurrency?: number;
110
+ metadata?: NodeMetadata;
99
111
  } | {
100
112
  node: "parallel";
101
113
  label: string;
102
114
  branches: WorkflowNode[];
115
+ metadata?: NodeMetadata;
103
116
  } | {
104
117
  node: "loop";
105
118
  label: string;
106
119
  body: WorkflowNode;
107
120
  until: Predicate;
108
121
  maxIters: number;
122
+ metadata?: NodeMetadata;
109
123
  } | {
110
124
  node: "escalate";
111
125
  label: string;
@@ -113,6 +127,7 @@ export type WorkflowNode = {
113
127
  kind: string;
114
128
  stage: string;
115
129
  summary: string;
130
+ metadata?: NodeMetadata;
116
131
  } | JudgeNode | PickNode | SiftNode | RouteNode | CallNode | WorkflowInvocation;
117
132
  /** A judgment as typed questions. `state` is what the questions see, interpolated by value from the
118
133
  * workflow state (a whole-string placeholder keeps its type); `out` is a flat schema of enums,
@@ -125,6 +140,7 @@ export type JudgeNode = {
125
140
  out: string;
126
141
  as: string;
127
142
  requires?: string[];
143
+ metadata?: NodeMetadata;
128
144
  };
129
145
  /** One choice whose options are the items of a list. `describe` renders each item as its option
130
146
  * text (`{item.field}`); `allowNone` adds a none-of-these option. The result at `as` is
@@ -140,6 +156,7 @@ export type PickNode = {
140
156
  allowNone?: boolean;
141
157
  as: string;
142
158
  requires?: string[];
159
+ metadata?: NodeMetadata;
143
160
  };
144
161
  /** The same question set (`out`, a judge schema) asked of every item of a list in ONE request: item i's
145
162
  * questions are prefixed `i.`; every answer lands in `as.answers[i]` and `as.values[i]`. `keep`
@@ -158,6 +175,7 @@ export type SiftNode = {
158
175
  gte?: number;
159
176
  };
160
177
  requires?: string[];
178
+ metadata?: NodeMetadata;
161
179
  };
162
180
  /** A choice among subgraphs. The options are the branch names, their criteria the branch
163
181
  * descriptions; the chosen branch runs on the state. `as` (optional) records the choice and its
@@ -179,6 +197,7 @@ export type RouteNode = {
179
197
  };
180
198
  as?: string;
181
199
  requires?: string[];
200
+ metadata?: NodeMetadata;
182
201
  };
183
202
  /** A child workflow invoked as one step of its parent. The child is embedded whole, so the parent
184
203
  * digest covers every child byte; `input` is interpolated by value and is the child's ENTIRE initial
@@ -192,6 +211,7 @@ export type WorkflowInvocation = {
192
211
  input: Record<string, unknown>;
193
212
  out: string;
194
213
  as: string;
214
+ metadata?: NodeMetadata;
195
215
  };
196
216
  /** `exit` is a shell command that ended with a non-zero status: retried only when the author
197
217
  * declared retry, since re-running a command is the author's call. */
@@ -214,6 +234,7 @@ export type ArtifactNode = {
214
234
  effort?: WorkflowEffort;
215
235
  thinking?: WorkflowThinking;
216
236
  requires?: string[];
237
+ metadata?: NodeMetadata;
217
238
  };
218
239
  export type ArtifactState = {
219
240
  path: string;
@@ -271,6 +292,7 @@ export type CallNode = {
271
292
  /** Repeat the call until its result settles (a queued job, an eventually consistent read). */
272
293
  poll?: PollClause;
273
294
  requires?: string[];
295
+ metadata?: NodeMetadata;
274
296
  };
275
297
  export declare const SHELL_RESULT_SCHEMA: Record<string, unknown>;
276
298
  export type LlmNode = Extract<WorkflowNode, {
package/dist/workflow.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { isDeepStrictEqual, types as utilTypes } from "node:util";
3
- import { predicateMatches, MECHANICAL_PREDICATE_NAMES } from "./predicates.js";
3
+ import { predicateMatches, getPath, MECHANICAL_PREDICATE_NAMES } from "./predicates.js";
4
+ import { WORKFLOW_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, WORKFLOW_PREDICATES, THINKING_LEVELS, MODEL_TIERS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, PROSE_ARTIFACT_TYPES } from "./vocabulary.js";
4
5
  import { validateAnswers, answerConfidence, answersSidecar, answersToValue, compileQuestions, SYSTEM_ONE_LIMITS } from "./system-one.js";
5
6
  import { Compile } from "typebox/compile";
6
7
  import { compileTransform, compileTransformSyntax } from "./code-exec.js";
@@ -8,7 +9,7 @@ import { workflowShapeErrors } from "./workflow-shape.js";
8
9
  import { resolveSchemaForWorkflow } from "./schema-references.js";
9
10
  export { resolveSchemaForWorkflow } from "./schema-references.js";
10
11
  export function artifactNodeIsProse(node) {
11
- return node.type === "markdown" || node.type === "report";
12
+ return PROSE_ARTIFACT_TYPES.includes(node.type);
12
13
  }
13
14
  export function desugarWorkflow(workflow) {
14
15
  const visit = (node) => {
@@ -75,6 +76,41 @@ export const declaredWrites = (node) => {
75
76
  visit(node);
76
77
  return out;
77
78
  };
79
+ /** The top-level keys a loop body writes, with engine sidecars; null when an unaliased code node makes them unknowable. */
80
+ const loopBodyWrites = (body) => {
81
+ const out = new Set();
82
+ let known = true;
83
+ const visit = (n) => {
84
+ if (!n || typeof n !== "object" || !known)
85
+ return;
86
+ if (n.node === "code" && n.as === undefined) {
87
+ known = false;
88
+ return;
89
+ }
90
+ if (n.node === "report")
91
+ out.add("report_markdown");
92
+ else if (typeof n.as === "string" && n.as.trim())
93
+ out.add(n.as);
94
+ else if (["agent", "decide", "extract"].includes(n.node) && typeof n.label === "string")
95
+ out.add(n.label);
96
+ if (n.node === "map" || n.node === "workflow")
97
+ return;
98
+ if (Array.isArray(n.steps))
99
+ n.steps.forEach(visit);
100
+ if (Array.isArray(n.branches))
101
+ n.branches.forEach(visit);
102
+ else if (n.node === "route" && n.branches && typeof n.branches === "object")
103
+ Object.values(n.branches).forEach((b) => visit(b?.body));
104
+ if (n.body)
105
+ visit(n.body);
106
+ };
107
+ visit(body);
108
+ if (!known)
109
+ return null;
110
+ for (const key of [...out])
111
+ out.add(`${key}$answers`).add(`${key}$verify`);
112
+ return out;
113
+ };
78
114
  const routeBodies = (node) => node.node === "route" ? Object.values(node.branches || {}).map((b) => b?.body).filter(Boolean) : [];
79
115
  const snapshotState = (state) => {
80
116
  try {
@@ -84,7 +120,10 @@ const snapshotState = (state) => {
84
120
  throw new Error("Workflow state must be structured-cloneable", { cause });
85
121
  }
86
122
  };
87
- const KINDS = new Set(["chain", "code", "agent", "decide", "extract", "report", "map", "parallel", "loop", "escalate", "call", "artifact", "workflow", "judge", "pick", "sift", "route"]);
123
+ const KINDS = new Set(WORKFLOW_NODE_KINDS);
124
+ const kindsMatchType = true;
125
+ void kindsMatchType;
126
+ const KIND_KEYS = Object.fromEntries(WORKFLOW_NODE_KINDS.map((kind) => [kind, new Set([...NODE_FIELDS[kind], ...HOST_NODE_FIELDS, ...(IGNORED_NODE_FIELDS[kind] ?? [])])]));
88
127
  export const childSteps = (child) => {
89
128
  const root = child?.root;
90
129
  if (!root || typeof root !== "object")
@@ -114,7 +153,7 @@ function containsReportNode(node) {
114
153
  return routeBodies(node).some(containsReportNode);
115
154
  return false;
116
155
  }
117
- const PREDICATES = new Set([...MECHANICAL_PREDICATE_NAMES, "ask"]);
156
+ const PREDICATES = new Set(WORKFLOW_PREDICATES);
118
157
  function predicateShapeErrors(pred) {
119
158
  const out = [];
120
159
  if (pred.predicate === "in") {
@@ -431,6 +470,54 @@ export function validateWorkflow(workflow, opts) {
431
470
  }
432
471
  return patches;
433
472
  };
473
+ const snapshotKnowledge = () => ({
474
+ available: reachability ? new Set(reachability.available) : null, unknowable: reachability?.unknowable ?? true,
475
+ typed: new Map(typedOutputs), probed: new Map([...probedSubtrees].map(([key, values]) => [key, [...values]])),
476
+ spread: new Set(spreadTaintedKeys), files: new Set(producedFiles),
477
+ });
478
+ const restoreKnowledge = (knowledge) => {
479
+ if (reachability && knowledge.available) {
480
+ reachability.available = new Set(knowledge.available);
481
+ reachability.unknowable = knowledge.unknowable;
482
+ }
483
+ typedOutputs.clear();
484
+ for (const [key, value] of knowledge.typed)
485
+ typedOutputs.set(key, value);
486
+ probedSubtrees.clear();
487
+ for (const [key, values] of knowledge.probed)
488
+ probedSubtrees.set(key, [...values]);
489
+ spreadTaintedKeys.clear();
490
+ for (const key of knowledge.spread)
491
+ spreadTaintedKeys.add(key);
492
+ producedFiles.clear();
493
+ for (const file of knowledge.files)
494
+ producedFiles.add(file);
495
+ };
496
+ /** After a parallel node: each branch's own changes applied over the state before it; keys, files and shapes accumulate. */
497
+ const mergeKnowledge = (before, branches) => {
498
+ restoreKnowledge(before);
499
+ for (const branch of branches) {
500
+ if (reachability && branch.available)
501
+ for (const key of branch.available)
502
+ reachability.available.add(key);
503
+ for (const [key, value] of branch.typed)
504
+ if (before.typed.get(key) !== value)
505
+ typedOutputs.set(key, value);
506
+ for (const key of before.typed.keys())
507
+ if (!branch.typed.has(key))
508
+ typedOutputs.delete(key);
509
+ for (const [key, values] of branch.probed)
510
+ if (before.probed.get(key)?.length !== values.length || before.probed.get(key)?.some((v, i) => v !== values[i]))
511
+ probedSubtrees.set(key, [...values]);
512
+ for (const key of branch.spread)
513
+ spreadTaintedKeys.add(key);
514
+ for (const file of branch.files)
515
+ producedFiles.add(file);
516
+ }
517
+ // The merged state depends on which branches ran how; later reachability checks stand down, as before.
518
+ if (reachability)
519
+ reachability.unknowable = true;
520
+ };
434
521
  const checkPredicatePath = (when, label, path) => {
435
522
  if (!reachability || !when?.path)
436
523
  return;
@@ -464,6 +551,21 @@ export function validateWorkflow(workflow, opts) {
464
551
  }
465
552
  errors.push(`${path} (${label}): predicate path "${when.path}" is not produced by the code node that writes "${head}" (its shape has: ${missingAt && typeof missingAt === "object" ? Object.keys(missingAt).join(", ") : typeof missingAt}); the guard can never fire`);
466
553
  };
554
+ // A mechanical predicate reads one state key; when no input key or earlier node writes it, the guard can never fire.
555
+ const checkPredicateHead = (pred, label, path, field, produced) => {
556
+ if (!reachability || reachability.unknowable || !pred || typeof pred !== "object")
557
+ return;
558
+ const available = produced ?? reachability.available;
559
+ const { predicate, path: at, key } = pred;
560
+ const read = predicate === "no_new_items" ? key : predicate === "ask" ? undefined : at;
561
+ if (typeof read !== "string" || !read.trim())
562
+ return;
563
+ const head = read.split(".")[0];
564
+ if (!available.has(head))
565
+ errors.push(`${path} (${label}): ${field} reads "${read}" but no input key or earlier node produces "${head}"; the guard can never fire`);
566
+ else if (!produced)
567
+ checkTypedPath(read, `${path} (${label}) ${field}`);
568
+ };
467
569
  const checkInterpolations = (value, label, path) => {
468
570
  if (!reachability || reachability.unknowable || value === undefined)
469
571
  return;
@@ -570,27 +672,6 @@ export function validateWorkflow(workflow, opts) {
570
672
  catch { /* Schema diagnostics above retain the original compilation failure. */ }
571
673
  }
572
674
  }
573
- const KIND_KEYS = {
574
- chain: new Set(["node", "steps"]),
575
- code: new Set(["node", "label", "code", "as"]),
576
- // "budget" (agent) and "samples"/"voteField" (decide) are deprecated-and-ignored: tolerated
577
- // for legacy v2 documents. The engine invokes the adapter once per node.
578
- agent: new Set(["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "budget", "verify", "tier"]),
579
- decide: new Set(["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "samples", "voteField", "verify", "tier"]),
580
- extract: new Set(["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "verify", "tier"]),
581
- report: new Set(["node", "label", "state", "instructions", "sopSection", "requires", "tools", "effort", "thinking"]),
582
- artifact: new Set(["node", "label", "state", "type", "path", "instructions", "sopSection", "requires", "tools", "effort", "thinking"]),
583
- map: new Set(["node", "label", "itemsPath", "body", "as", "resultPath", "maxConcurrency"]),
584
- parallel: new Set(["node", "label", "branches"]),
585
- loop: new Set(["node", "label", "body", "until", "maxIters"]),
586
- escalate: new Set(["node", "label", "when", "kind", "stage", "summary"]),
587
- call: new Set(["node", "label", "via", "tool", "args", "code", "input", "command", "where", "out", "as", "produces", "deadline_s", "retry", "poll", "requires", "env"]),
588
- workflow: new Set(["node", "label", "workflow", "input", "out", "as"]),
589
- judge: new Set(["node", "label", "state", "out", "as", "requires"]),
590
- pick: new Set(["node", "label", "itemsPath", "describe", "instructions", "state", "allowNone", "as", "requires"]),
591
- sift: new Set(["node", "label", "itemsPath", "describe", "state", "out", "as", "keep", "requires"]),
592
- route: new Set(["node", "label", "state", "instructions", "branches", "unsure", "as", "requires"]),
593
- };
594
675
  const checkStateMap = (map, label, path, field = "state") => {
595
676
  if (map === undefined)
596
677
  return;
@@ -689,12 +770,12 @@ export function validateWorkflow(workflow, opts) {
689
770
  errors.push(`${path} (${node.label}): instructions required`);
690
771
  if (node.node !== "report" && !Object.hasOwn(workflow.schemas, node.out))
691
772
  errors.push(`${path} (${node.label}): out schema "${node.out}" not in workflow.schemas`);
692
- if (node.thinking !== undefined && !["low", "medium", "high"].includes(String(node.thinking)))
773
+ if (node.thinking !== undefined && !THINKING_LEVELS.includes(String(node.thinking)))
693
774
  errors.push(`${path} (${node.label}): thinking must be low|medium|high — thinking is never off`);
694
775
  if (node.tools !== undefined && (!Array.isArray(node.tools) || node.tools.some((t) => typeof t !== "string" || !t.trim())))
695
776
  errors.push(`${path} (${node.label}): tools must be a list of non-empty tool names when present (an empty list disables tools)`);
696
777
  checkRequires(node, path);
697
- if (node.tier !== undefined && !["fast", "default", "strong"].includes(String(node.tier)))
778
+ if (node.tier !== undefined && !MODEL_TIERS.includes(String(node.tier)))
698
779
  errors.push(`${path} (${node.label}): tier must be fast|default|strong`);
699
780
  if (node.node !== "report" && node.verify !== undefined) {
700
781
  const v = node.verify;
@@ -747,8 +828,6 @@ export function validateWorkflow(workflow, opts) {
747
828
  errors.push(`${path} (${node.label}): parallel needs at least two branches`);
748
829
  if (containsReportNode(node))
749
830
  errors.push(`${path} (${node.label}): a report node cannot live inside a parallel branch — the report is rendered once, after every branch has landed`);
750
- if (reachability)
751
- reachability.unknowable = true;
752
831
  {
753
832
  const writers = new Map();
754
833
  (node.branches || []).forEach((branch, i) => {
@@ -760,7 +839,21 @@ export function validateWorkflow(workflow, opts) {
760
839
  }
761
840
  });
762
841
  }
763
- (node.branches || []).forEach((branch, i) => walk(branch, `${path}.branches[${i}]`));
842
+ {
843
+ // Every branch starts from the state before the parallel node: a branch never sees a sibling's writes.
844
+ // All walk knowledge is restored per branch, then the branches' results merge (their writes are disjoint).
845
+ const before = snapshotKnowledge();
846
+ const after = [];
847
+ (node.branches || []).forEach((branch, i) => {
848
+ restoreKnowledge(before);
849
+ walk(branch, `${path}.branches[${i}]`);
850
+ after.push(snapshotKnowledge());
851
+ });
852
+ if (after.length)
853
+ mergeKnowledge(before, after);
854
+ if (reachability)
855
+ reachability.unknowable = true;
856
+ }
764
857
  return;
765
858
  case "loop":
766
859
  if (!Number.isInteger(node.maxIters) || node.maxIters < 1 || node.maxIters > 20)
@@ -768,6 +861,12 @@ export function validateWorkflow(workflow, opts) {
768
861
  if (containsReportNode(node.body))
769
862
  errors.push(`${path} (${node.label}): a report node cannot live inside a loop body — the report is rendered once, after the record is final`);
770
863
  checkPredicate(node.until, node.label, path, "until");
864
+ {
865
+ // `until` reads the state after the body: the keys before the loop plus every key the body writes.
866
+ const bodyWrites = loopBodyWrites(node.body);
867
+ if (reachability && !reachability.unknowable && bodyWrites)
868
+ checkPredicateHead(node.until, node.label, path, "until", new Set([...reachability.available, ...bodyWrites]));
869
+ }
771
870
  if (reachability)
772
871
  reachability.unknowable = true;
773
872
  walk(node.body, `${path}.body`);
@@ -777,6 +876,7 @@ export function validateWorkflow(workflow, opts) {
777
876
  checkPredicate(node.when, node.label, path, "when");
778
877
  if (!node.kind?.trim() || !node.stage?.trim() || !node.summary?.trim())
779
878
  errors.push(`${path} (${node.label}): kind, stage, summary required`);
879
+ checkPredicateHead(node.when, node.label, path, "when");
780
880
  checkPredicatePath(node.when, node.label, path);
781
881
  return;
782
882
  case "judge": {
@@ -927,6 +1027,8 @@ export function validateWorkflow(workflow, opts) {
927
1027
  errors.push(`${path} (${label}): out schema "${String(node.out)}" not in workflow.schemas`);
928
1028
  if (!node.input || typeof node.input !== "object" || Array.isArray(node.input))
929
1029
  errors.push(`${path} (${label}): input must be an object mapping onto the child's initial state`);
1030
+ else if (Object.hasOwn(node.input, HOST_STATE_KEY))
1031
+ errors.push(`${path} (${label}): input must not contain the reserved "${HOST_STATE_KEY}" key`);
930
1032
  const child = node.workflow;
931
1033
  const steps = childSteps(child);
932
1034
  if (!child || typeof child !== "object" || !steps || !steps.length)
@@ -954,7 +1056,7 @@ export function validateWorkflow(workflow, opts) {
954
1056
  }
955
1057
  case "call": {
956
1058
  const label = node.label || "call";
957
- if (!["tool", "executor", "shell"].includes(String(node.via)))
1059
+ if (!CALL_TRANSPORTS.includes(String(node.via)))
958
1060
  errors.push(`${path} (${label}): via must be tool|executor|shell`);
959
1061
  if (node.via === "tool") {
960
1062
  if (!node.tool?.trim())
@@ -1015,7 +1117,7 @@ export function validateWorkflow(workflow, opts) {
1015
1117
  errors.push(`${path} (${label}): retry.attempts must be 1..5`);
1016
1118
  if (r?.backoff_s !== undefined && !(Number.isFinite(r.backoff_s) && r.backoff_s >= 0 && r.backoff_s <= 60))
1017
1119
  errors.push(`${path} (${label}): retry.backoff_s must be 0..60`);
1018
- if (r?.on !== undefined && (!Array.isArray(r.on) || r.on.some((c) => !["timeout", "http_5xx", "http_429", "connection", "exit"].includes(String(c)))))
1120
+ if (r?.on !== undefined && (!Array.isArray(r.on) || r.on.some((c) => !CALL_RETRY_CLASSES.includes(String(c)))))
1019
1121
  errors.push(`${path} (${label}): retry.on may name only timeout|http_5xx|http_429|connection|exit`);
1020
1122
  }
1021
1123
  if (node.poll !== undefined) {
@@ -1171,9 +1273,6 @@ export function validateWorkflow(workflow, opts) {
1171
1273
  errors.push(...workflowShapeErrors(workflow, true));
1172
1274
  return errors.length ? { ok: false, errors } : { ok: true };
1173
1275
  }
1174
- function getPath(value, path) {
1175
- return path.split(".").reduce((acc, key) => (acc == null ? acc : acc[key]), value);
1176
- }
1177
1276
  function interpolate(template, state) {
1178
1277
  return template.replace(/\{([a-zA-Z0-9_.$]+)\}/g, (_, p) => {
1179
1278
  let v = getPath(state, p);
@@ -2108,15 +2207,21 @@ async function runNodeBody(node, state, workflow, deps) {
2108
2207
  if (hostWriter.has(key) && isDeepStrictEqual(mergedHost[key], value))
2109
2208
  continue;
2110
2209
  const base = baseHost[key];
2210
+ const prior = hostWriter.get(key);
2211
+ const conflict = () => new WorkflowStateError(`parallel node "${node.label}": branches ${prior} and ${i} both wrote host state ${HOST_STATE_KEY}.${key} to different values`, node.label, `${HOST_STATE_KEY}.${key}`, "parallel_write_conflict");
2212
+ // An append is an array that extends the base array (or a new array on a key with no base).
2213
+ // Appends from several branches join in branch order. An append meets a prior non-append
2214
+ // write of the same key as a conflict, whichever branch came first: no shape wins silently.
2111
2215
  if (Array.isArray(value) && (base === undefined || Array.isArray(base)) && (!Array.isArray(base) || (value.length >= base.length && base.every((entry, n) => isDeepStrictEqual(entry, value[n]))))) {
2216
+ if (prior !== undefined && !Array.isArray(mergedHost[key]))
2217
+ throw conflict();
2112
2218
  const appended = value.slice(Array.isArray(base) ? base.length : 0);
2113
2219
  mergedHost[key] = [...(Array.isArray(mergedHost[key]) ? mergedHost[key] : []), ...appended];
2114
2220
  hostWriter.set(key, i);
2115
2221
  continue;
2116
2222
  }
2117
- const prior = hostWriter.get(key);
2118
2223
  if (prior !== undefined && !isDeepStrictEqual(mergedHost[key], value))
2119
- throw new WorkflowStateError(`parallel node "${node.label}": branches ${prior} and ${i} both wrote host state ${HOST_STATE_KEY}.${key} to different values`, node.label, `${HOST_STATE_KEY}.${key}`, "parallel_write_conflict");
2224
+ throw conflict();
2120
2225
  hostWriter.set(key, i);
2121
2226
  mergedHost[key] = value;
2122
2227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-dsl",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Composable, typed workflows for agents",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -23,7 +23,8 @@
23
23
  "README.md",
24
24
  "LICENSE",
25
25
  "NOTICE",
26
- "schema"
26
+ "schema",
27
+ "skills"
27
28
  ],
28
29
  "engines": {
29
30
  "node": ">=22.19.0"