owenloop 0.5.8 → 0.5.9

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 (87) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +4 -2
  3. package/dist/packages/work/src/agent/loop.d.ts +23 -8
  4. package/dist/packages/work/src/agent/loop.js +48 -6
  5. package/dist/packages/work/src/consumed-verifier.js +6 -17
  6. package/dist/packages/work/src/exec/loop.d.ts +1 -1
  7. package/dist/packages/work/src/exec/loop.js +181 -32
  8. package/dist/packages/work/src/exec/receipt.d.ts +7 -7
  9. package/dist/packages/work/src/exec/receipt.js +6 -6
  10. package/dist/packages/work/src/harness/claude.js +100 -0
  11. package/dist/packages/work/src/hub/client.d.ts +19 -4
  12. package/dist/packages/work/src/hub/client.js +7 -3
  13. package/dist/packages/work/src/hub/types.d.ts +84 -0
  14. package/dist/packages/work/src/main.js +1 -0
  15. package/dist/packages/work/src/roles/agent-run.js +19 -22
  16. package/dist/packages/work/src/roles/exec.js +2 -0
  17. package/dist/packages/work/src/roles/settings.js +2 -0
  18. package/dist/packages/work/src/roles/shift.js +14 -2
  19. package/dist/packages/work/src/roles/util.d.ts +1 -0
  20. package/dist/packages/work/src/roles/util.js +10 -0
  21. package/dist/packages/work/src/settings/hub-roster-cache.d.ts +68 -0
  22. package/dist/packages/work/src/settings/hub-roster-cache.js +370 -0
  23. package/dist/packages/work/src/settings/roster.d.ts +84 -0
  24. package/dist/packages/work/src/settings/roster.js +364 -5
  25. package/dist/packages/work/src/settings/serving.d.ts +17 -0
  26. package/dist/packages/work/src/settings/serving.js +79 -0
  27. package/dist/packages/work/src/settings/settings.d.ts +14 -1
  28. package/dist/packages/work/src/settings/settings.js +14 -0
  29. package/dist/packages/work/src/shift/loop.d.ts +108 -5
  30. package/dist/packages/work/src/shift/loop.js +299 -51
  31. package/dist/packages/work/src/shift/protocol.d.ts +7 -5
  32. package/dist/packages/work/src/shift/runtime.d.ts +15 -0
  33. package/dist/packages/work/src/shift/runtime.js +94 -4
  34. package/dist/packages/work/src/shift/server.js +2 -0
  35. package/dist/packages/work/src/shift/spawn.d.ts +17 -2
  36. package/dist/packages/work/src/shift/spawn.js +16 -13
  37. package/dist/packages/work/src/shift/state.d.ts +29 -2
  38. package/dist/packages/work/src/shift/state.js +45 -15
  39. package/dist/packages/work/src/usage.d.ts +1 -1
  40. package/dist/packages/work/src/usage.js +7 -1
  41. package/dist/packages/work/src/util/modifier-init.d.ts +7 -0
  42. package/dist/packages/work/src/util/modifier-init.js +73 -0
  43. package/dist/src/bundle/tar.d.ts +9 -4
  44. package/dist/src/bundle/tar.js +9 -4
  45. package/dist/src/capabilities.d.ts +6 -0
  46. package/dist/src/cli.d.ts +14 -1
  47. package/dist/src/cli.js +687 -75
  48. package/dist/src/config-dir.d.ts +1 -1
  49. package/dist/src/config-dir.js +1 -1
  50. package/dist/src/crypto/index.d.ts +1 -1
  51. package/dist/src/crypto/index.js +1 -1
  52. package/dist/src/crypto/org-root.d.ts +30 -12
  53. package/dist/src/crypto/org-root.js +162 -14
  54. package/dist/src/crypto/records.d.ts +2 -0
  55. package/dist/src/crypto/records.js +2 -0
  56. package/dist/src/defs.d.ts +6 -1
  57. package/dist/src/defs.js +203 -8
  58. package/dist/src/engine.d.ts +42 -7
  59. package/dist/src/engine.js +158 -16
  60. package/dist/src/index.d.ts +4 -4
  61. package/dist/src/index.js +2 -2
  62. package/dist/src/mcp/serve.d.ts +22 -0
  63. package/dist/src/mcp/serve.js +88 -8
  64. package/dist/src/model.d.ts +2 -0
  65. package/dist/src/model.js +32 -25
  66. package/dist/src/order-resolver.d.ts +1 -0
  67. package/dist/src/order-resolver.js +8 -1
  68. package/dist/src/schemas/index.d.ts +11 -0
  69. package/dist/src/schemas/order.v1.schema.json +7 -1
  70. package/dist/src/store.d.ts +5 -0
  71. package/dist/src/store.js +43 -8
  72. package/dist/src/types.d.ts +40 -3
  73. package/docs/authoring.md +90 -2
  74. package/docs/bundles.md +26 -2
  75. package/docs/cli.md +170 -28
  76. package/docs/crypto.md +19 -3
  77. package/docs/design.md +70 -1
  78. package/docs/routing.md +189 -34
  79. package/docs/shift-logs.md +20 -9
  80. package/docs/wire-contracts.md +50 -7
  81. package/examples/workflows/delivery.yaml +31 -14
  82. package/examples/workflows/ship.yaml +10 -2
  83. package/package.json +1 -1
  84. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
  85. package/plugins/claude-code/plugin/.mcp.json +1 -1
  86. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
  87. package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
package/dist/src/defs.js CHANGED
@@ -32,7 +32,7 @@ import { MODIFIER_SEPARATOR } from "./capabilities.js";
32
32
  /** Hand-maintained key allowlist for RawInput — kept next to the interface so
33
33
  * the two can't silently drift (§27 unknown-key rejection). */
34
34
  const RAW_INPUT_KEYS = ['name', 'producer', 'seedOwed', 'schema'];
35
- const RAW_PRODUCE_KEYS = ['name', 'schema', 'judges', 'maxAttempts', 'maxSchemaFailures'];
35
+ const RAW_PRODUCE_KEYS = ['name', 'schema', 'judges', 'maxAttempts', 'maxSchemaFailures', 'bind'];
36
36
  /** Hand-maintained key allowlist for RawGroup — a `group:` entry is a
37
37
  * DIFFERENT (smaller) shape than RawProduce, not a produce with extra
38
38
  * fields, so it gets its own allowlist rather than folding into
@@ -45,7 +45,7 @@ const RAW_STEP_KEYS = [
45
45
  'maxRunsPerDay', 'parallel', 'maxAttempts', 'maxSchemaFailures', 'model',
46
46
  'workdir', 'workdirFrom', 'terminal', 'effect', 'on', 'idleAfter', 'body', 'bodyFile',
47
47
  'calls', 'reapTtl', 'capabilities', 'maxLease', 'x', 'executor', 'command', 'spec',
48
- 'escalation',
48
+ 'escalation', 'onCancel',
49
49
  ];
50
50
  /** Keys valid on a calls: step entry — a DIFFERENT (smaller) shape than RawStep;
51
51
  * the `calls:` key is what routes an entry here instead of RAW_STEP_KEYS. */
@@ -113,7 +113,8 @@ function assertAuthoredCapability(value, ctx) {
113
113
  *
114
114
  * Order is NOT preserved as meaning: the list is a vocabulary, and nothing in
115
115
  * the engine compares two modifiers or treats one as higher than another. The
116
- * array shape is only YAML's way of writing a set.
116
+ * array shape is only YAML's way of writing a set. The vocabulary is fixed
117
+ * here; every downstream gate checks membership in it and nothing else.
117
118
  */
118
119
  function parseModifiers(v, ctx) {
119
120
  const values = asStringArray(v, ctx);
@@ -125,6 +126,11 @@ function parseModifiers(v, ctx) {
125
126
  if (value.trim().length === 0) {
126
127
  throw new DefError(`${ctx}: modifier names must not be empty or whitespace`);
127
128
  }
129
+ if (/\s/.test(value)) {
130
+ throw new DefError(`${ctx}: modifier '${value}' must not contain whitespace — ` +
131
+ 'a modifier is composed onto every authored capability as ' +
132
+ `'<capability>${MODIFIER_SEPARATOR}<modifier>' and travels as a routing key`);
133
+ }
128
134
  if (value.includes(MODIFIER_SEPARATOR)) {
129
135
  throw new DefError(`${ctx}: modifier '${value}' must not contain '${MODIFIER_SEPARATOR}' — ` +
130
136
  'it is the separator the engine composes with');
@@ -157,6 +163,19 @@ function parseEscalation(v, ctx) {
157
163
  throw new DefError(`${ctx}.modifier must not be empty`);
158
164
  return { after, modifier };
159
165
  }
166
+ /** Parse a step's `onCancel:` block. Stem-membership cross-checks live in
167
+ * validateDef because they need the step's parsed consumes. */
168
+ function parseOnCancel(v, ctx) {
169
+ if (typeof v !== 'object' || v === null || Array.isArray(v)) {
170
+ throw new DefError(`${ctx} must be a mapping of { consumes }`);
171
+ }
172
+ const raw = v;
173
+ assertNoUnknownKeys(raw, ['consumes'], ctx);
174
+ if (raw['consumes'] === undefined) {
175
+ throw new DefError(`${ctx} must set 'consumes' (the subset of the step's consumes the cancel-path firing requires; use [] for none)`);
176
+ }
177
+ return { consumes: asStringArray(raw['consumes'], `${ctx}.consumes`) };
178
+ }
160
179
  function asNumber(v, fallback, ctx) {
161
180
  if (v === undefined)
162
181
  return fallback;
@@ -372,6 +391,14 @@ function parseGroup(v, ctx) {
372
391
  const of = v.of.map((s, i) => asString(s, `group '${group}'.of[${i}]`));
373
392
  return { group, mode, of };
374
393
  }
394
+ /**
395
+ * The `from` a bind gets when its author omits one: the final segment of
396
+ * `to`. A shorthand `bind: modifier` therefore reads the accepted
397
+ * object's `modifier` key, while `bind: meta.customer` reads `customer`.
398
+ */
399
+ function defaultBindFrom(to) {
400
+ return to.slice(to.lastIndexOf('.') + 1);
401
+ }
375
402
  /**
376
403
  * Parse a step's `produces` list. Each entry is either a bare pattern string
377
404
  * (`plan`, `gather.source[]`), a mapping `{ name, schema, judges, maxAttempts,
@@ -423,10 +450,29 @@ function parseProduces(v, ctx, baseDir) {
423
450
  throw new DefError(`produce '${name}'.maxSchemaFailures must be a non-negative number`);
424
451
  pat.maxSchemaFailures = v;
425
452
  }
453
+ if (raw.bind !== undefined) {
454
+ // bind.from is always a dot-separated object path. When omitted, it
455
+ // defaults to the final segment of bind.to; missing paths are refused.
456
+ if (typeof raw.bind === 'string') {
457
+ pat.bind = { to: raw.bind, from: defaultBindFrom(raw.bind) };
458
+ }
459
+ else if (typeof raw.bind === 'object' && raw.bind !== null && !Array.isArray(raw.bind)) {
460
+ const bind = raw.bind;
461
+ assertNoUnknownKeys(bind, ['to', 'from'], `produce '${name}'.bind`);
462
+ const to = asString(bind.to, `produce '${name}'.bind.to`);
463
+ const from = bind.from === undefined
464
+ ? defaultBindFrom(to)
465
+ : asString(bind.from, `produce '${name}'.bind.from`);
466
+ pat.bind = { to, from };
467
+ }
468
+ else {
469
+ throw new DefError(`produce '${name}'.bind must be a string or a { to, from } mapping`);
470
+ }
471
+ }
426
472
  patterns.push(pat);
427
473
  return;
428
474
  }
429
- throw new DefError(`${ctx}[${i}] must be a string or a { name, schema, judges, maxAttempts, maxSchemaFailures } mapping`);
475
+ throw new DefError(`${ctx}[${i}] must be a string or a { name, schema, judges, maxAttempts, maxSchemaFailures, bind } mapping`);
430
476
  });
431
477
  return { patterns, groups };
432
478
  }
@@ -717,6 +763,12 @@ function prefixStep(step, prefix, defInputs = []) {
717
763
  // judges: marker names a local stem (unlike calls:, which names an external
718
764
  // workflow) — it must be prefixed to keep pointing at the (now-prefixed) produce.
719
765
  const newJudges = step.judges !== undefined ? prefixStem(step.judges) : undefined;
766
+ // onCancel consumes name local stems, so they must follow the same prefixing
767
+ // rule as ordinary consumes. Build a fresh object to avoid aliasing a child
768
+ // definition into an expanded parent.
769
+ const newOnCancel = step.onCancel !== undefined
770
+ ? { consumes: step.onCancel.consumes.map(prefixStem) }
771
+ : undefined;
720
772
  // workdirFrom names a local consumed stem or a declared input of the included
721
773
  // definition, followed by a dotted value path. Prefix only the stem; the value
722
774
  // path is a field path inside that artifact's value.
@@ -744,6 +796,8 @@ function prefixStep(step, prefix, defInputs = []) {
744
796
  result.effect = newEffect;
745
797
  if (newJudges !== undefined)
746
798
  result.judges = newJudges;
799
+ if (newOnCancel !== undefined)
800
+ result.onCancel = newOnCancel;
747
801
  if (newWorkdirFrom !== undefined)
748
802
  result.workdirFrom = newWorkdirFrom;
749
803
  return result;
@@ -831,7 +885,20 @@ export function expandIncludes(def, resolve, stack) {
831
885
  if (parsed && outer !== undefined)
832
886
  rewrittenWorkdirFrom = `${outer}.${parsed.path}`;
833
887
  }
834
- return { ...l, consumes: rewrittenConsumes, workdirFrom: rewrittenWorkdirFrom };
888
+ // onCancel consume stems follow ordinary consume rewrites for mapped
889
+ // child inputs; otherwise the expanded step would name a stem it no
890
+ // longer consumes.
891
+ const rewrittenOnCancel = l.onCancel === undefined
892
+ ? undefined
893
+ : { consumes: l.onCancel.consumes.map((stem) => inputRewrites.get(stem) ?? stem) };
894
+ const rewrittenStep = {
895
+ ...l,
896
+ consumes: rewrittenConsumes,
897
+ workdirFrom: rewrittenWorkdirFrom,
898
+ };
899
+ if (rewrittenOnCancel !== undefined)
900
+ rewrittenStep.onCancel = rewrittenOnCancel;
901
+ return rewrittenStep;
835
902
  });
836
903
  resultSteps.push(...rewrittenSteps);
837
904
  // (g) merge child outputs
@@ -1054,7 +1121,8 @@ function buildStep(rl, i, baseDir) {
1054
1121
  }
1055
1122
  for (const tok of rawOn) {
1056
1123
  if (tok !== 'inputsGreen' && tok !== 'allGreen' && tok !== 'idle') {
1057
- throw new DefError(`step '${name}': on: token '${tok}' is not supported; supported: 'inputsGreen', 'allGreen', 'idle'`);
1124
+ throw new DefError(`step '${name}': on: token '${tok}' is not supported; supported: 'inputsGreen', 'allGreen', 'idle'. ` +
1125
+ 'Cleanup that must still run when the run is cancelled is declared with the step-level onCancel: key, not a firing trigger.');
1058
1126
  }
1059
1127
  }
1060
1128
  step.on = rawOn;
@@ -1080,6 +1148,9 @@ function buildStep(rl, i, baseDir) {
1080
1148
  if (rl.escalation !== undefined) {
1081
1149
  step.escalation = parseEscalation(rl.escalation, `step '${name}'.escalation`);
1082
1150
  }
1151
+ if (rl.onCancel !== undefined) {
1152
+ step.onCancel = parseOnCancel(rl.onCancel, `step '${name}'.onCancel`);
1153
+ }
1083
1154
  // A3: per-step max total lease lifetime (duration string, same as reapTtl).
1084
1155
  if (rl.maxLease !== undefined) {
1085
1156
  step.maxLeaseMs = parseDurationMs(asString(rl.maxLease, `step '${name}'.maxLease`));
@@ -1343,7 +1414,7 @@ export function validateDef(def) {
1343
1414
  for (const tok of l.on) {
1344
1415
  if (tok !== 'inputsGreen' && tok !== 'allGreen' && tok !== 'idle') {
1345
1416
  errors.push(`step '${l.name}': on: token '${tok}' is not supported; ` +
1346
- `supported: 'inputsGreen', 'allGreen', 'idle'.`);
1417
+ `supported: 'inputsGreen', 'allGreen', 'idle'. Cleanup that must still run when the run is cancelled is declared with the step-level onCancel: key, not a firing trigger.`);
1347
1418
  }
1348
1419
  }
1349
1420
  }
@@ -1368,6 +1439,30 @@ export function validateDef(def) {
1368
1439
  errors.push(`evaluator step ${l.name} (on: allGreen/idle) must not declare consumes; its firings carry no input fingerprint`);
1369
1440
  }
1370
1441
  }
1442
+ // onCancel: cross-checks. A cancel-path firing is keyless and fires once, so
1443
+ // it can require only the step's own plain consumes.
1444
+ for (const l of def.steps) {
1445
+ if (l.onCancel === undefined)
1446
+ continue;
1447
+ const seen = new Set();
1448
+ for (const stem of l.onCancel.consumes) {
1449
+ if (seen.has(stem)) {
1450
+ errors.push(`step '${l.name}': onCancel.consumes lists '${stem}' more than once`);
1451
+ continue;
1452
+ }
1453
+ seen.add(stem);
1454
+ const consume = l.consumes.find((candidate) => candidate.stem === stem);
1455
+ if (consume === undefined) {
1456
+ errors.push(`step '${l.name}': onCancel.consumes names '${stem}', which is not one of the step's consumes ` +
1457
+ `[${l.consumes.map((candidate) => candidate.stem).join(', ')}]`);
1458
+ continue;
1459
+ }
1460
+ if (consume.mode !== 'plain') {
1461
+ errors.push(`step '${l.name}': onCancel.consumes names '${stem}', which the step consumes in ${consume.mode} mode ` +
1462
+ `('${consume.raw}'); the cancel-path firing is keyless, so only plain consumes may be listed`);
1463
+ }
1464
+ }
1465
+ }
1371
1466
  // M2-VALIDATE: calls: step per-def rules.
1372
1467
  // Note: cross-def checks (target-def existence, child input-key validity) cannot be done here
1373
1468
  // because validateDef is a pure per-def function with no resolver. Those checks live in loadDefs
@@ -1379,6 +1474,14 @@ export function validateDef(def) {
1379
1474
  if (l.produces.length !== 1) {
1380
1475
  errors.push(`calls: step '${l.name}' must produce exactly one output (got ${l.produces.length})`);
1381
1476
  }
1477
+ // A calls: outcome is published by the composition machinery rather than
1478
+ // accepted through green(), so it has no transactional bind write path.
1479
+ // Refuse it at definition load instead of allowing a silently stale route.
1480
+ for (const produce of l.produces) {
1481
+ if (produce.bind !== undefined) {
1482
+ errors.push(`calls: step '${l.name}' produce '${produce.raw}' declares bind, which is not supported on calls: outcomes`);
1483
+ }
1484
+ }
1382
1485
  // (b) callsInputs VALUES must be real parent artifacts (inputs or step-produced stems)
1383
1486
  for (const [, parentArtifact] of Object.entries(l.callsInputs ?? {})) {
1384
1487
  if (!producerOf.has(parentArtifact)) {
@@ -1472,6 +1575,33 @@ export function validateDef(def) {
1472
1575
  // "defs without `modifiers:` run exactly as today". Opting into the
1473
1576
  // new routing vocabulary is what turns the stricter rule on.
1474
1577
  const declaredModifiers = new Set(def.modifiers ?? []);
1578
+ const modifierBinds = [];
1579
+ for (const l of def.steps) {
1580
+ for (const p of l.produces) {
1581
+ const bind = p.bind;
1582
+ if (bind === undefined)
1583
+ continue;
1584
+ if (p.kind === 'collection') {
1585
+ errors.push(`step '${l.name}' produce '${p.raw}' bind is not supported on collection produces`);
1586
+ continue;
1587
+ }
1588
+ if (bind.to === 'modifier') {
1589
+ if (declaredModifiers.size === 0) {
1590
+ errors.push(`step '${l.name}' produce '${p.stem}' binds modifier but workflow '${def.name}' declares no modifiers:`);
1591
+ }
1592
+ modifierBinds.push({ step: l.name, artifact: p.stem });
1593
+ }
1594
+ else if (!/^meta\.[A-Za-z_][A-Za-z0-9_-]*$/.test(bind.to)) {
1595
+ errors.push(`step '${l.name}' produce '${p.stem}' bind.to '${bind.to}' must be 'modifier' or 'meta.<key>'`);
1596
+ }
1597
+ if (!/^[A-Za-z_][A-Za-z0-9_-]*(?:\.[A-Za-z_][A-Za-z0-9_-]*)*$/.test(bind.from)) {
1598
+ errors.push(`step '${l.name}' produce '${p.stem}' bind.from '${bind.from}' must be a non-empty dot-path of identifier segments`);
1599
+ }
1600
+ }
1601
+ }
1602
+ if (modifierBinds.length > 1) {
1603
+ errors.push(`workflow '${def.name}' binds modifier more than once: ${modifierBinds.map((b) => `'${b.step}.${b.artifact}'`).join(', ')}`);
1604
+ }
1475
1605
  for (const l of def.steps) {
1476
1606
  if (l.escalation === undefined)
1477
1607
  continue;
@@ -1705,6 +1835,64 @@ function danglingReduceSuffixWarnings(def) {
1705
1835
  }
1706
1836
  return warnings;
1707
1837
  }
1838
+ /**
1839
+ * Whether a consume can receive a value produced by this exact pattern.
1840
+ *
1841
+ * Keeping map suffixes here is essential: `items[$i].review` does not make a
1842
+ * consumer of `items[*].analysis` (or bare `items[*]`) downstream merely
1843
+ * because both lanes share the `items` stem.
1844
+ */
1845
+ function consumesProducedPattern(consume, produce) {
1846
+ if (consume.stem !== produce.stem)
1847
+ return false;
1848
+ if (produce.kind === 'singleton')
1849
+ return consume.mode === 'plain';
1850
+ if (produce.kind === 'collection') {
1851
+ return consume.mode !== 'plain' && consume.suffix === '';
1852
+ }
1853
+ return consume.mode !== 'plain' && consume.suffix === produce.suffix;
1854
+ }
1855
+ /** Warn when routed work can run before the artifact that writes the modifier. */
1856
+ function unroutedCapabilityWarnings(def) {
1857
+ let bindingStep;
1858
+ let boundArtifact;
1859
+ for (const step of def.steps) {
1860
+ const bound = step.produces.find((p) => p.bind?.to === 'modifier');
1861
+ if (bound !== undefined) {
1862
+ bindingStep = step;
1863
+ boundArtifact = bound;
1864
+ break;
1865
+ }
1866
+ }
1867
+ if (bindingStep === undefined || boundArtifact === undefined)
1868
+ return [];
1869
+ // Forward graph closure from the bound artifact. The binding step itself is
1870
+ // exempt, but its unbound sibling outputs must not make a branch downstream.
1871
+ const reachedSteps = new Set([bindingStep.name]);
1872
+ const reachedArtifacts = [boundArtifact];
1873
+ let changed = true;
1874
+ while (changed) {
1875
+ changed = false;
1876
+ for (const step of def.steps) {
1877
+ if (reachedSteps.has(step.name))
1878
+ continue;
1879
+ if (!step.consumes.some((consume) => reachedArtifacts.some((produce) => consumesProducedPattern(consume, produce))))
1880
+ continue;
1881
+ reachedSteps.add(step.name);
1882
+ reachedArtifacts.push(...step.produces);
1883
+ changed = true;
1884
+ }
1885
+ }
1886
+ const warnings = [];
1887
+ for (const step of def.steps) {
1888
+ if (step.capabilities === undefined || step.capabilities.length === 0)
1889
+ continue;
1890
+ if (reachedSteps.has(step.name))
1891
+ continue;
1892
+ warnings.push(`step '${step.name}' declares capabilities (${step.capabilities.join(', ')}) but is not downstream of artifact '${boundArtifact.raw}' bound to modifier`);
1893
+ }
1894
+ return warnings;
1895
+ }
1708
1896
  /**
1709
1897
  * Static lint over a workflow definition. Returns both the hard errors from
1710
1898
  * `validateDef` (which `parseDef` / `loadDefFile` would throw on) and
@@ -1718,10 +1906,17 @@ function danglingReduceSuffixWarnings(def) {
1718
1906
  export function lintDef(def) {
1719
1907
  const errors = validateDef(def);
1720
1908
  const warnings = errors.length === 0
1721
- ? [...deadEndWarnings(def), ...danglingReduceSuffixWarnings(def)]
1909
+ ? [...deadEndWarnings(def), ...danglingReduceSuffixWarnings(def), ...unroutedCapabilityWarnings(def)]
1722
1910
  : [];
1723
1911
  return { errors, warnings };
1724
1912
  }
1913
+ /**
1914
+ * The steps a def declares as cleanup-on-cancel, in definition order. The
1915
+ * control plane calls this when it cancels a run.
1916
+ */
1917
+ export function cancelCleanupSteps(def) {
1918
+ return def.steps.filter((step) => step.onCancel !== undefined);
1919
+ }
1725
1920
  // ---- WS-6: scope-aware calls: target resolution -------------------------------
1726
1921
  /** Stable private-map key for one installed coordinate at one verified digest. */
1727
1922
  export function digestScopedCallsTargetKey(digest, target) {
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import type { WorkflowStatus } from './model.ts';
13
13
  import type { SchemaIssue } from './schema.ts';
14
- import type { CapabilityRewrites } from './capabilities.ts';
14
+ import type { CapabilityRewrites, CrewStamps } from './capabilities.ts';
15
15
  import type { MatchMode } from './capabilities.ts';
16
16
  import type { Store } from './store.ts';
17
17
  import type { Author, Fingerprint, Order, WorkflowDef } from './types.ts';
@@ -160,14 +160,16 @@ export interface CreateOpts {
160
160
  parentPath: string;
161
161
  };
162
162
  /**
163
- * The ONE routing modifier this instance carries for its whole life. Must be
164
- * a member of the def's declared `modifiers` set — `createInstance` throws
163
+ * The ONE routing modifier this instance carries at a time. Must be a member
164
+ * of the def's declared `modifiers` set — `createInstance` throws
165
165
  * {@link ModifierRefusalError} otherwise, rather than starting a run that
166
- * would compose capabilities no crew was ever bound to.
166
+ * would compose capabilities no crew was ever bound to. After creation, the
167
+ * engine may replace it only through a def-declared artifact bind during
168
+ * acceptance.
167
169
  *
168
170
  * Absent = an unmodified run: every step is offered on bare capabilities.
169
- * Never mutated after creation; an escalated re-offer carries its own target
170
- * modifier per-offer without rewriting this.
171
+ * An escalated re-offer carries its own target modifier per-offer without
172
+ * rewriting this stored value.
171
173
  */
172
174
  modifier?: string;
173
175
  }
@@ -559,6 +561,12 @@ export declare class Engine {
559
561
  * record still shows the grade of service that was requested.
560
562
  */
561
563
  capabilityRewrites?: CapabilityRewrites;
564
+ /**
565
+ * Per-offered-capability crews matched by the caller that owns routing
566
+ * bindings. The pure engine cannot compute this; it stamps the supplied
567
+ * match result onto the order that is actually served.
568
+ */
569
+ crewStamps?: CrewStamps;
562
570
  }): TickResult;
563
571
  /**
564
572
  * The recursive tick worker. Runs this instance's own maintain → reap →
@@ -708,6 +716,33 @@ export declare class Engine {
708
716
  * the order's digest — before any caller can execute a prompt or command.
709
717
  */
710
718
  resolveOrder(order: Order): ResolvedInstructions;
719
+ /** Return the binding declaration that owns this artifact path, if any. */
720
+ private artifactBind;
721
+ /** Resolve a declared dot-path of object keys against an accepted artifact value. */
722
+ private boundValue;
723
+ /**
724
+ * The bind-time and reject-time modifier gate: membership in the def's
725
+ * declared `modifiers` set, and nothing else — byte for byte the rule the
726
+ * start path applies in `createInstanceInTx`. One value cannot be legal to
727
+ * start a run with and illegal to bind.
728
+ *
729
+ * `def` here is the PINNED snapshot, so the vocabulary checked is the one
730
+ * stamped on this run, not a later republish.
731
+ *
732
+ * The SHAPE of a name is constrained where a name is authored:
733
+ * `parseModifiers` in `src/defs.ts` refuses an empty name, a name containing
734
+ * whitespace, a name containing `MODIFIER_SEPARATOR`, and a duplicate.
735
+ * Re-testing shape here is what split the vocabulary in the first place — a
736
+ * value the parser admitted and `start_run` accepted, refused at bind.
737
+ */
738
+ private assertBoundModifier;
739
+ /** Validate extraction before an acceptance branch changes an artifact. */
740
+ private validateArtifactBind;
741
+ /**
742
+ * Persist a declared instance-routing write and its single artifact-level
743
+ * audit event. Call only from an already-accepted branch inside its tx.
744
+ */
745
+ private applyArtifactBind;
711
746
  /**
712
747
  * Commit a singleton/map output green — or born-reject it if an input moved.
713
748
  *
@@ -769,7 +804,7 @@ export declare class Engine {
769
804
  * See `docs/design.md` §24.9 for the full writeup and operator mitigations
770
805
  * (`parallel: 1`, a generous `reapTtl:` on slow judge steps).
771
806
  */
772
- reject(workflow: string, path: string, by: Author, text: string): {
807
+ reject(workflow: string, path: string, by: Author, text: string, requested?: string): {
773
808
  outcome: 'rejected' | 'born-rejected';
774
809
  reason?: string;
775
810
  };