@parcha/agentrun-dsl 0.1.0-beta.204 → 0.1.0-beta.206

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/README.md CHANGED
@@ -188,7 +188,7 @@ The schema helpers resolve the owning workflow's schema catalog; `stageSchemaFor
188
188
 
189
189
  `@parcha/agentrun-dsl/edit` edits a workflow document as JSON, one pure function per edit, for a visual editor, a CLI or a server. It imports only the graph and the node vocabulary, so a browser bundles it, and it names a node by its graph path. `insert(doc, parentPath, slot, index, node)`, `remove(doc, path)`, `move(doc, fromPath, toParentPath, slot, index)`, `duplicate(doc, path)`, `wrap(doc, paths, kind)` (in a map, loop, route, parallel or chain), `unwrap(doc, path, branch?)`, `addBranch(doc, path, node, name?)`, `removeBranch(doc, path, branch)`, `renameBranch(doc, path, from, to)`, `setField(doc, path, field, value)`, `rename(doc, path, name)` and `renameKey(doc, path, name, options?)` each return `{ doc, moved, added, removed, changed }`. `doc` is the next document: the input is never mutated, and every subtree the edit did not touch is shared with it, byte for byte. `moved` maps each node whose path changed, old path to new; `added` and `removed` list the nodes only one of the two documents has; `changed` lists the nodes whose own fields changed. A slot is where a child sits under its parent: `steps`, `branches`, `body`, `branches/<name>/body`, `workflow/root`, or `root` under the parent path `""`; `locate(doc, path)` says which one holds a node, and `move` counts its index in the document as given, the drop point between two steps. An edit that would break the document's structure (a report inside a map, a chain with no steps, a parallel with one branch, a node of no known kind or without a required field) throws an `EditError` with a `code` from `EDIT_ERROR_CODES` and the `path` it is about, and writes nothing. Whether each reference is produced and each field filled in is still `validateWorkflow`'s to say: `wrap` gives its new container placeholders the validator flags on it (an empty `itemsPath`, `valuePath` or `until` predicate). `rename` changes a label. When the label is the key the node writes (an agent, decide, extract or code node with no `as`; a code node writes there when its code returns something other than a record), every `{placeholder}` and state path that reads the key in scope follows it, and the code and shell sources that mention it, or one of its `<key>$...` keys, are listed in `mentions`, unchanged. A renamed code node's own code is listed too when it names the key, since a record it returns with that key still writes the old name. `renameKey` renames the key a node writes the same way: its `as` when it has one, any kind's, else its label when that is the key, where it gives the document `rename` gives; `{ field: "failedAs" }` renames a map's `failedAs` instead. No edit gives a label, an `as`, a `failedAs` or a route branch a name `Object.prototype` has (`constructor`, `toString`, `__proto__` and the rest) or `prototype`: `rename`, `renameKey`, `renameBranch` and `setField` refuse one, and `insert` and `addBranch` refuse a node with one anywhere inside it. `renameBranch` carries the route's `otherwise` and `unsure`, but not a value elsewhere that compares against the old branch name (a `field_equals` on the route's `as`, or the value a route by value reads), which the caller must change. `duplicate` copies code as it is, so a copied code node writes the same record keys as its source: duplicating a code branch of a parallel gives two branches that write one key, which the run refuses. The copy's reads of a copied code node's label follow its fresh label, so when that code returns a record naming the old label, those reads find nothing; `duplicate` lists the copy's code and shell sources that mention a key it renamed in `mentions`, as `rename` does. `editableFields(node)` and `requiredFields(node)` are the schema's fields for a node, as `setField` writes them.
190
190
 
191
- The same module answers what a property panel asks. `setBranchCriteria(doc, path, branch, criteria)` writes or removes (`undefined`) a judged route branch's criteria. `setSchema(doc, id, schema, scope?)` writes or removes a schema of the document, or of the child workflow of the workflow node at `scope`, and refuses to remove one that `schemaUsers(doc, id, scope?)` says is named: it lists the JSON Pointers of the workflow's `input.schemaId` and `output.schemaId`, each node's `out` and `verify.out`, and each `$ref` to `#/definitions/<id>` in another schema. `namesInScope(doc, path, field?)` lists the names the node at `path` may read, each `{ name, from }` with `from` the path of the node that writes it, `"input"` or `"engine"` (a map body's `item` and `item_index`), by the scope rules `rename` carries a key along; `field` asks for one field where it sees more (a map's `resultPath`, a loop's `until`, `verify`, a pick's or sift's `describe`, a workflow node's `workflow`). It cannot list a key only a code node's returned record writes, nor the keys of an input whose schema lists no properties. `readsOf(doc, path)` lists each `{placeholder}` and state path the node reads as `{ pointer, name }`, the references `rename` carries, and `openPlaceholderAt(text, offset)` finds the `{` open at a cursor and the name typed after it. `freshName(doc, base)` gives `base` or `<base>_<n>`, free in every scope, and `placeholderNode(doc, kind)` the smallest node of a kind that holds no nodes, each required field holding its `FIELD_PLACEHOLDERS` value, which the validator flags until it is filled in.
191
+ The same module answers what a property panel asks. `setBranchCriteria(doc, path, branch, criteria)` writes or removes (`undefined`) a judged route branch's criteria. `setSchema(doc, id, schema, scope?)` writes or removes a schema of the document, or of the child workflow of the workflow node at `scope`, and refuses to remove one that `schemaUsers(doc, id, scope?)` says is named: it lists the JSON Pointers of the workflow's `input.schemaId` and `output.schemaId`, each node's `out` and `verify.out`, and each `$ref` to `#/definitions/<id>` in another schema. `namesInScope(doc, path, field?)` lists the names the node at `path` may read, each `{ name, from }` with `from` the path of the node that writes it, `"input"` or `"engine"` (a map body's `item` and `item_index`), by the scope rules `rename` carries a key along; `field` asks for one field where it sees more (a map's `resultPath`, a loop's `until`, `verify`, a pick's or sift's `describe`, a workflow node's `workflow`). It cannot list a key only a code node's returned record writes, nor the keys of an input whose schema lists no properties. `readsOf(doc, path)` lists each `{placeholder}` and state path the node reads as `{ pointer, name }`, the references `rename` carries, and `openPlaceholderAt(text, offset)` finds the `{` open at a cursor and the name typed after it. `freshName(doc, base)` gives `base` or `<base>_<n>`, free in every scope (a child workflow's with no node yet included), and `placeholderNode(doc, kind)` the smallest node of a kind that holds no nodes, each required field holding its `FIELD_PLACEHOLDERS` value, which the validator flags until it is filled in.
192
192
 
193
193
  The separate `@parcha/agentrun-dsl/demo` entrypoint provides the support-triage example. `@parcha/agentrun-dsl/schema` provides the generated workflow JSON Schema, a JSON file: import it with `import schema from '@parcha/agentrun-dsl/schema' with { type: 'json' };` (a plain `import` throws `ERR_IMPORT_ATTRIBUTE_MISSING`), or load it with `require('@parcha/agentrun-dsl/schema')` in CommonJS.
194
194
 
package/dist/edit.d.ts CHANGED
@@ -141,8 +141,8 @@ export declare function openPlaceholderAt(text: string, offset: number): {
141
141
  prefix: string;
142
142
  } | undefined;
143
143
  /** `base`, or its stem (`base` without a `_<n>` ending) with the smallest `_<n>` from 2, so that no label, key,
144
- * reference, input key or word of code of any scope of the document holds it, nor an engine key or a name
145
- * `Object.prototype` has. `base` is a state key name. */
144
+ * reference, input key or word of code of any scope of the document holds it (a child workflow's that holds no node
145
+ * yet among them), nor an engine key or a name `Object.prototype` has. `base` is a state key name. */
146
146
  export declare function freshName(doc: WorkflowDocument, base: string): string;
147
147
  /** The smallest node of `kind` for `doc`: its required fields in the schema's order, a fresh name as its label (and its
148
148
  * `as`, where it needs one), and each other field's placeholder. A container is made by wrapping nodes that exist. */
package/dist/edit.js CHANGED
@@ -1384,15 +1384,17 @@ export function openPlaceholderAt(text, offset) {
1384
1384
  return { start: start - 1, prefix: text.slice(start, offset) };
1385
1385
  }
1386
1386
  /** `base`, or its stem (`base` without a `_<n>` ending) with the smallest `_<n>` from 2, so that no label, key,
1387
- * reference, input key or word of code of any scope of the document holds it, nor an engine key or a name
1388
- * `Object.prototype` has. `base` is a state key name. */
1387
+ * reference, input key or word of code of any scope of the document holds it (a child workflow's that holds no node
1388
+ * yet among them), nor an engine key or a name `Object.prototype` has. `base` is a state key name. */
1389
1389
  export function freshName(doc, base) {
1390
1390
  const before = documentOf(doc);
1391
1391
  if (typeof base !== "string" || !KEY_NAME.test(base))
1392
1392
  throw new EditError("NAME_INVALID", "", `a name takes letters, digits and "_" only: ${JSON.stringify(base)}`);
1393
1393
  const entries = entriesOf(before);
1394
1394
  const used = new Set([...Object.getOwnPropertyNames(Object.prototype), "prototype"]);
1395
- for (const scope of new Set(["", ...entries.map((entry) => entry.scope)]))
1395
+ // Each workflow node's path is a scope, its child's first node not yet inserted included: that node is named here.
1396
+ const scopes = ["", ...entries.filter((entry) => entry.node.node === "workflow").map((entry) => entry.path)];
1397
+ for (const scope of scopes)
1396
1398
  for (const name of namesUsed(before, entries, scope))
1397
1399
  used.add(name);
1398
1400
  // `base` itself when free, numbered or not; `fresh` alone numbers a numbered base from its stem even when it is free.
@@ -710,6 +710,9 @@ export type ValidationIssue = {
710
710
  * output checks remain authoritative. */
711
711
  export type ValidateWorkflowOptions = {
712
712
  executeCode?: boolean;
713
+ /** The run's input, or only its keys: what the reachability checks (STATE_PATH_UNPRODUCED, STATE_PATH_EXCLUDED) start
714
+ * from, and what they find is an error. Neither given, the input schema's `properties` stand in, and what they find is
715
+ * a warning. */
713
716
  input?: Record<string, unknown>;
714
717
  inputKeys?: string[];
715
718
  probeContext?: {
package/dist/workflow.js CHANGED
@@ -465,8 +465,21 @@ export function validateWorkflow(workflow, opts) {
465
465
  const ptrOf = (path) => pointers.get(path) ?? "";
466
466
  const declaredInput = workflow.input && Object.hasOwn(workflow.schemas, workflow.input.schemaId)
467
467
  ? resolveSchemaForWorkflow(workflow, workflow.schemas[workflow.input.schemaId]) : undefined;
468
- const inputKeys = opts?.input !== undefined ? Object.keys(opts.input ?? {}) : opts?.inputKeys;
468
+ // With no input and no inputKeys, an input schema with properties names the keys a run starts with: they are "derived",
469
+ // and what the reachability checks find from them is a warning (`CODE at <pointer>: <message>`), never an error. An
470
+ // input schema that takes extra properties lets a real input carry a key it does not declare; a run's start checks its
471
+ // real input. Derived keys run no authored code: a code node is not probed, as without keys.
472
+ const derived = opts?.input === undefined && opts?.inputKeys === undefined && isRecord(declaredInput) && isRecord(declaredInput.properties);
473
+ const inputKeys = opts?.input !== undefined ? Object.keys(opts.input ?? {}) : opts?.inputKeys ?? (derived ? Object.keys(declaredInput.properties) : undefined);
469
474
  const reachability = inputKeys ? { available: new Set(inputKeys), unknowable: false } : null;
475
+ const derivedWarnings = [];
476
+ /** A finding of the reachability checks: an error with the input keys given, a warning with derived ones. */
477
+ const unreached = (code, path, message) => {
478
+ if (derived)
479
+ derivedWarnings.push(`${code}${path ? ` at ${path}` : ""}: ${message}`);
480
+ else
481
+ fail(code, path, message);
482
+ };
470
483
  // Closed, typed producers let us reject impossible nested paths without running
471
484
  // authored code. Open schemas, unions, references and dynamic control flow stand
472
485
  // down; this is a conservative edge check, not a second schema validator.
@@ -497,7 +510,7 @@ export function validateWorkflow(workflow, opts) {
497
510
  schema = schema.properties[segment];
498
511
  else {
499
512
  if (schema.additionalProperties === false && !schema.patternProperties)
500
- fail("STATE_PATH_EXCLUDED", node, `${at}: state path "${dotted}" is excluded by the upstream schema at "${head}"; check the producer's as key and declared properties`);
513
+ unreached("STATE_PATH_EXCLUDED", node, `${at}: state path "${dotted}" is excluded by the upstream schema at "${head}"; check the producer's as key and declared properties`);
501
514
  return;
502
515
  }
503
516
  }
@@ -567,7 +580,7 @@ export function validateWorkflow(workflow, opts) {
567
580
  });
568
581
  })() : null;
569
582
  const probeCodePatches = (code, at) => {
570
- if (opts?.executeCode === false)
583
+ if (opts?.executeCode === false || derived)
571
584
  return [];
572
585
  let compiled;
573
586
  try {
@@ -713,7 +726,7 @@ export function validateWorkflow(workflow, opts) {
713
726
  if (!missing)
714
727
  return;
715
728
  }
716
- fail("STATE_PATH_EXCLUDED", ptrOf(path), `${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`);
729
+ unreached("STATE_PATH_EXCLUDED", ptrOf(path), `${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`);
717
730
  };
718
731
  // A mechanical predicate reads one state key; when no input key or earlier node writes it, the guard can never fire.
719
732
  const checkPredicateHead = (pred, label, path, field, produced) => {
@@ -729,14 +742,14 @@ export function validateWorkflow(workflow, opts) {
729
742
  continue;
730
743
  const head = page.split(".")[0];
731
744
  if (!available.has(head))
732
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field}.pages reads "${page}" but no input key or earlier node produces "${head}"; every quote would miss`);
745
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field}.pages reads "${page}" but no input key or earlier node produces "${head}"; every quote would miss`);
733
746
  }
734
747
  const read = predicate === "no_new_items" ? key : predicate === "ask" ? undefined : at;
735
748
  if (typeof read !== "string" || !read.trim())
736
749
  return;
737
750
  const head = read.split(".")[0];
738
751
  if (!available.has(head))
739
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field} reads "${read}" but no input key or earlier node produces "${head}"; the guard can never fire`);
752
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): ${field} reads "${read}" but no input key or earlier node produces "${head}"; the guard can never fire`);
740
753
  else if (!produced)
741
754
  checkTypedPath(read, `${path} (${label}) ${field}`, ptrOf(path));
742
755
  };
@@ -750,7 +763,7 @@ export function validateWorkflow(workflow, opts) {
750
763
  continue;
751
764
  const head = (m[1].startsWith("state.") ? m[1].slice(6) : m[1]).split(".")[0];
752
765
  if (!reachability.available.has(head))
753
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): interpolates {${m[1]}} but no upstream node produces "${head}"`);
766
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): interpolates {${m[1]}} but no upstream node produces "${head}"`);
754
767
  else
755
768
  checkTypedPath(m[1].startsWith("state.") ? m[1].slice(6) : m[1], `${path} (${label})`, ptrOf(path));
756
769
  }
@@ -767,7 +780,7 @@ export function validateWorkflow(workflow, opts) {
767
780
  for (const required of node.requires) {
768
781
  const head = String(required).split(".")[0];
769
782
  if (!reachability.available.has(head)) {
770
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): requires "${required}" but no upstream node produces it; state here has only: ${[...reachability.available].join(", ")}`);
783
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): requires "${required}" but no upstream node produces it; state here has only: ${[...reachability.available].join(", ")}`);
771
784
  }
772
785
  else
773
786
  checkTypedPath(required, `${path} (${node.label}) requires`, ptrOf(path));
@@ -778,7 +791,7 @@ export function validateWorkflow(workflow, opts) {
778
791
  return;
779
792
  const head = node.itemsPath.split(".")[0];
780
793
  if (!reachability.available.has(head))
781
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): itemsPath "${node.itemsPath}" has no upstream producer; read the value under the producing node's as key (or its label when as is omitted)`);
794
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${node.label}): itemsPath "${node.itemsPath}" has no upstream producer; read the value under the producing node's as key (or its label when as is omitted)`);
782
795
  else
783
796
  checkTypedPath(node.itemsPath, `${path} (${node.label}) itemsPath`, ptrOf(path));
784
797
  };
@@ -1234,7 +1247,7 @@ export function validateWorkflow(workflow, opts) {
1234
1247
  if (typeof valuePath === "string" && valuePath.trim() && reachability && !reachability.unknowable) {
1235
1248
  const head = valuePath.split(".")[0];
1236
1249
  if (!reachability.available.has(head))
1237
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): valuePath "${valuePath}" has no upstream producer; route by the key an earlier node writes`);
1250
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): valuePath "${valuePath}" has no upstream producer; route by the key an earlier node writes`);
1238
1251
  else
1239
1252
  checkTypedPath(valuePath, `${path} (${label}) valuePath`, ptrOf(path));
1240
1253
  }
@@ -1309,7 +1322,7 @@ export function validateWorkflow(workflow, opts) {
1309
1322
  if (typeof node.path !== "string" || !node.path.trim() || node.path.startsWith("/") || node.path.split("/").includes(".."))
1310
1323
  fail("NODE_FIELD_INVALID", ptrOf(path), `${path} (${label}): path must be a workspace-relative file`);
1311
1324
  else if (reachability && !producedFiles.has(node.path))
1312
- fail("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): path "${node.path}" is not produced by any earlier shell call (declare it in that call's produces)`);
1325
+ unreached("STATE_PATH_UNPRODUCED", ptrOf(path), `${path} (${label}): path "${node.path}" is not produced by any earlier shell call (declare it in that call's produces)`);
1313
1326
  checkRequires({ label, requires: node.requires }, path);
1314
1327
  if (reachability) {
1315
1328
  reachability.available.add("artifact");
@@ -1526,7 +1539,7 @@ export function validateWorkflow(workflow, opts) {
1526
1539
  if (reachability && !reachability.unknowable && !mayEscalate && workflow?.output?.path) {
1527
1540
  const head = workflow.output.path.split(".")[0];
1528
1541
  if (!reachability.available.has(head))
1529
- fail("STATE_PATH_UNPRODUCED", "", `output: path "${workflow.output.path}" has no input or upstream producer; select the final node's as key (or label when as is omitted)`);
1542
+ unreached("STATE_PATH_UNPRODUCED", "", `output: path "${workflow.output.path}" has no input or upstream producer; select the final node's as key (or label when as is omitted)`);
1530
1543
  else
1531
1544
  checkTypedPath(workflow.output.path, "output", "");
1532
1545
  }
@@ -1574,14 +1587,14 @@ export function validateWorkflow(workflow, opts) {
1574
1587
  bestMissing = missing;
1575
1588
  }
1576
1589
  if (bestMissing?.length) {
1577
- fail("STATE_PATH_EXCLUDED", "", `output: the code node writing "${workflow.output.path}" never emits required field(s) ${bestMissing.join(", ")} of schema "${workflow.output.schemaId}" — every run would fail output validation`);
1590
+ unreached("STATE_PATH_EXCLUDED", "", `output: the code node writing "${workflow.output.path}" never emits required field(s) ${bestMissing.join(", ")} of schema "${workflow.output.schemaId}" — every run would fail output validation`);
1578
1591
  }
1579
1592
  }
1580
1593
  }
1581
1594
  if (!errors.length)
1582
1595
  for (const issue of workflowShapeIssues(workflow, true))
1583
1596
  fail("SHAPE_INVALID", issue.path, issue.message);
1584
- const warnings = workflowWarnings(workflow);
1597
+ const warnings = [...workflowWarnings(workflow), ...derivedWarnings];
1585
1598
  return errors.length ? { ok: false, errors, issues, ...(warnings.length ? { warnings } : {}) } : { ok: true, ...(warnings.length ? { warnings } : {}) };
1586
1599
  }
1587
1600
  /** The value a `{path}` placeholder reads from state, in interpolation's lookup order: the path as written, else, for a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-dsl",
3
- "version": "0.1.0-beta.204",
3
+ "version": "0.1.0-beta.206",
4
4
  "description": "Composable, typed workflows for agents",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",