owenloop 0.5.29 → 0.5.31

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 (58) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/packages/work/src/agent/brief.js +73 -4
  3. package/dist/packages/work/src/agent/loop.d.ts +5 -3
  4. package/dist/packages/work/src/agent/loop.js +24 -3
  5. package/dist/packages/work/src/agent/workdir.d.ts +17 -0
  6. package/dist/packages/work/src/agent/workdir.js +24 -0
  7. package/dist/packages/work/src/exec/loop.d.ts +8 -1
  8. package/dist/packages/work/src/exec/loop.js +24 -1
  9. package/dist/packages/work/src/hub/client.d.ts +10 -3
  10. package/dist/packages/work/src/hub/client.js +5 -4
  11. package/dist/packages/work/src/hub/deadline.d.ts +20 -0
  12. package/dist/packages/work/src/hub/deadline.js +49 -0
  13. package/dist/packages/work/src/hub/types.d.ts +17 -0
  14. package/dist/packages/work/src/roles/agent-run.js +1 -0
  15. package/dist/packages/work/src/roles/exec.js +1 -0
  16. package/dist/packages/work/src/settings/hub-roster-cache.js +5 -23
  17. package/dist/packages/work/src/shift/loop.d.ts +59 -0
  18. package/dist/packages/work/src/shift/loop.js +177 -19
  19. package/dist/packages/work/src/shift/protocol.d.ts +53 -1
  20. package/dist/packages/work/src/shift/runtime.js +10 -1
  21. package/dist/packages/work/src/shift/server.js +2 -0
  22. package/dist/src/bundle/manifest.d.ts +6 -1
  23. package/dist/src/bundle/manifest.js +38 -8
  24. package/dist/src/bundle/runtime.d.ts +1 -1
  25. package/dist/src/bundle/runtime.js +1 -0
  26. package/dist/src/bundle/types.d.ts +3 -2
  27. package/dist/src/cli.js +17 -3
  28. package/dist/src/crypto/records.d.ts +1 -0
  29. package/dist/src/crypto/records.js +11 -0
  30. package/dist/src/defs.js +17 -4
  31. package/dist/src/engine.d.ts +3 -0
  32. package/dist/src/engine.js +55 -10
  33. package/dist/src/factory.d.ts +2 -0
  34. package/dist/src/factory.js +2 -0
  35. package/dist/src/index.d.ts +1 -1
  36. package/dist/src/index.js +1 -1
  37. package/dist/src/schemas/index.d.ts +3 -0
  38. package/dist/src/schemas/order.v1.schema.json +3 -0
  39. package/dist/src/store/def-source.d.ts +1 -1
  40. package/dist/src/store/def-source.js +25 -0
  41. package/dist/src/store/gc.js +9 -7
  42. package/dist/src/store/index.d.ts +1 -0
  43. package/dist/src/store/index.js +1 -0
  44. package/dist/src/store/install.js +9 -3
  45. package/dist/src/store/instruction-source.js +9 -5
  46. package/dist/src/store/verified-lock.d.ts +4 -0
  47. package/dist/src/store/verified-lock.js +38 -0
  48. package/dist/src/store.js +4 -2
  49. package/dist/src/types.d.ts +40 -0
  50. package/docs/authoring.md +12 -0
  51. package/docs/bundles.md +3 -2
  52. package/docs/cli.md +39 -11
  53. package/docs/shift-logs.md +53 -4
  54. package/package.json +1 -1
  55. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
  56. package/plugins/claude-code/plugin/.mcp.json +1 -1
  57. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
  58. package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
package/dist/src/defs.js CHANGED
@@ -29,6 +29,7 @@ import { assertValidSchema } from "./schema.js";
29
29
  // The separator lives with composition/matching (capabilities.ts); the parser
30
30
  // only enforces that an AUTHORED name never contains it.
31
31
  import { MODIFIER_SEPARATOR } from "./capabilities.js";
32
+ import { parseVersionedCallTarget } from "./bundle/manifest.js";
32
33
  import { isCallStep } from "./types.js";
33
34
  /** Hand-maintained key allowlist for RawInput — kept next to the interface so
34
35
  * the two can't silently drift (§27 unknown-key rejection). */
@@ -2290,12 +2291,12 @@ export function digestScopedCallsTargetKey(digest, target) {
2290
2291
  * THREE CASES, checked in this order:
2291
2292
  *
2292
2293
  * 1. `target` contains `/` — an explicitly QUALIFIED reference. When the
2293
- * calling definition carries a lock digest for that exact target, prefer the
2294
+ * calling definition carries a lock digest for its base coordinate, prefer the
2294
2295
  * digest-scoped coordinate alias registered by the CAS loader. That preserves
2295
2296
  * an already-running parent's selection when a project coordinate later
2296
2297
  * shadows the global coordinate it originally pinned. Without a reachable
2297
- * pinned alias, use the direct coordinate/package key so new lookups retain
2298
- * project-over-global precedence and the engine can surface a pin mismatch.
2298
+ * pinned alias, a plain local caller may use the direct coordinate/package
2299
+ * key. A CAS caller's named exact target fails closed without its alias.
2299
2300
  * Never fall back to a bare lookup: an author who wrote a qualified name
2300
2301
  * asked for one specific definition.
2301
2302
  *
@@ -2315,12 +2316,24 @@ export function digestScopedCallsTargetKey(digest, target) {
2315
2316
  */
2316
2317
  function resolveCallsTargetKey(defs, target, from) {
2317
2318
  if (target.includes('/')) {
2318
- const pinnedDigest = from.bundleLock?.[target];
2319
+ let lockKey = target;
2320
+ if (target.includes('#')) {
2321
+ try {
2322
+ lockKey = parseVersionedCallTarget(target).coordinate;
2323
+ }
2324
+ catch {
2325
+ return undefined;
2326
+ }
2327
+ }
2328
+ const pinnedDigest = from.bundleLock?.[lockKey];
2319
2329
  if (pinnedDigest !== undefined) {
2320
2330
  const pinnedKey = digestScopedCallsTargetKey(pinnedDigest, target);
2321
2331
  if (defs.has(pinnedKey))
2322
2332
  return pinnedKey;
2323
2333
  }
2334
+ if (target.includes('#')) {
2335
+ return from.bundleDigest === undefined && defs.has(target) ? target : undefined;
2336
+ }
2324
2337
  return defs.has(target) ? target : undefined;
2325
2338
  }
2326
2339
  if (from.bundleDigest !== undefined) {
@@ -307,6 +307,7 @@ export declare class Engine {
307
307
  * compatibility mode). Public read-only facade: {@link Engine.resolver}.
308
308
  */
309
309
  private readonly instructionSource;
310
+ private readonly readVerifiedBundleLock;
310
311
  readonly resolver: OrderResolver;
311
312
  private readonly reapTtlMs;
312
313
  private readonly maxLeaseMs;
@@ -339,6 +340,8 @@ export declare class Engine {
339
340
  * no legacy fallback).
340
341
  */
341
342
  instructionSource?: OrderInstructionSource;
343
+ /** Verify a persisted CAS parent's manifest lock by bundle digest, without an index lookup. */
344
+ readVerifiedBundleLock?: (digest: string) => Readonly<Record<string, string>>;
342
345
  });
343
346
  /**
344
347
  * Register a synchronous observer of engine changes; returns an idempotent
@@ -15,6 +15,7 @@ import { summarizeIssues, validateValue } from "./schema.js";
15
15
  import { hashDef } from "./defs.js";
16
16
  import { checkInterfaceCompatibility } from "./implements.js";
17
17
  import { isDefDigest, parseWorkflowCoordinate } from "./store/types.js";
18
+ import { parseVersionedCallTarget } from "./bundle/manifest.js";
18
19
  import { applyCapabilityMappings, applyCapabilityRewrites, claimMatches, composeCapabilities } from "./capabilities.js";
19
20
  import { localMidnightMs, nowMs, randId } from "./util.js";
20
21
  import { isCallStep } from "./types.js";
@@ -165,8 +166,9 @@ function hasExactImplementationClaim(def, expected) {
165
166
  * containing bundle's own digest. `childDef.bundleDigest` must equal
166
167
  * `parentDef.bundleDigest`.
167
168
  *
168
- * 2. `target` is an explicit `namespace/name@version` reference AND the parent
169
- * bundle's manifest `lock` names it. The lock value is a canonical BUNDLE
169
+ * 2. `target` is an explicit `namespace/name@version` reference, optionally
170
+ * followed by `#workflow`, AND the parent bundle's manifest `lock` names
171
+ * its base coordinate. The lock value is a canonical BUNDLE
170
172
  * digest (`bundle.yaml.lock` validates lowercase 64-hex; `assertLockCoverage`
171
173
  * requires an entry for every versioned target), so it is compared against
172
174
  * `childDef.bundleDigest` — NOT against `defInstructionDigest`, which
@@ -179,9 +181,13 @@ function hasExactImplementationClaim(def, expected) {
179
181
  */
180
182
  function callsPinViolation(parentDef, childDef, target) {
181
183
  if (target.includes('/')) {
182
- const pinned = parentDef.bundleLock?.[target];
183
- if (pinned === undefined)
184
- return undefined; // no lock entry reachable — unpinned
184
+ const lockKey = target.includes('#') ? parseVersionedCallTarget(target).coordinate : target;
185
+ const pinned = parentDef.bundleLock?.[lockKey];
186
+ if (pinned === undefined) {
187
+ return parentDef.bundleDigest !== undefined && target.includes('#')
188
+ ? `parent bundle has no lock for exact target ${lockKey}`
189
+ : undefined;
190
+ }
185
191
  if (childDef.bundleDigest === undefined) {
186
192
  return `parent bundle pins it to ${pinned} but the resolved definition carries no bundle provenance`;
187
193
  }
@@ -230,6 +236,7 @@ export class Engine {
230
236
  * compatibility mode). Public read-only facade: {@link Engine.resolver}.
231
237
  */
232
238
  instructionSource;
239
+ readVerifiedBundleLock;
233
240
  resolver;
234
241
  reapTtlMs;
235
242
  maxLeaseMs;
@@ -242,6 +249,7 @@ export class Engine {
242
249
  this.store = store;
243
250
  this.resolveDef = resolveDef;
244
251
  this.instructionSource = opts.instructionSource ?? createDefInstructionSource();
252
+ this.readVerifiedBundleLock = opts.readVerifiedBundleLock;
245
253
  this.resolver = new OrderResolver(this.instructionSource);
246
254
  this.reapTtlMs = opts.reapTtlMs ?? DEFAULT_REAP_TTL_MS;
247
255
  this.maxLeaseMs = opts.maxLeaseMs;
@@ -566,6 +574,10 @@ export class Engine {
566
574
  const needsSnapshot = Symbol('needs-workflow-snapshot');
567
575
  let snapshotDef;
568
576
  let optimisticInterfaceBinding;
577
+ const namedExactLockKey = step.calls !== undefined && step.calls.includes('#') && parentDef.bundleDigest !== undefined
578
+ ? parseVersionedCallTarget(step.calls).coordinate
579
+ : undefined;
580
+ let verifiedParentPin;
569
581
  // Interface targets are selected once, stored on the parent, and resolved by
570
582
  // exact digest BEFORE either the workflow-store guard or SQLite write lock.
571
583
  // The transaction below re-reads and compares the persisted selection.
@@ -641,12 +653,19 @@ export class Engine {
641
653
  let created = false;
642
654
  let childDef;
643
655
  if (!child) {
644
- // Resolving a new child's CAS def must happen before its coordinated
645
- // transaction acquires SQLite. Return a read-only sentinel on the
646
- // first pass; `run` resolves, locks/revalidates the bundle store, and
647
- // then repeats every gate/child read under the guarded write tx.
656
+ // Resolve outside SQLite before any parent-pin comparison or child write.
648
657
  if (snapshotDef === undefined)
649
658
  return needsSnapshot;
659
+ if (namedExactLockKey !== undefined) {
660
+ const fresh = parentRow.defSnapshot;
661
+ if (verifiedParentPin === undefined
662
+ || fresh === undefined
663
+ || fresh.bundleDigest !== parentDef.bundleDigest
664
+ || fresh.bundleLock?.[namedExactLockKey] !== verifiedParentPin
665
+ || fresh.steps.find((candidate) => candidate.name === step.name)?.calls !== step.calls) {
666
+ throw new CallsPinError(step.calls, 'the persisted parent or its base-coordinate lock changed before child creation');
667
+ }
668
+ }
650
669
  const childId = randId('wf');
651
670
  // WS-6: resolve IN THE PARENT'S SCOPE. `parentDef` is the parent's own
652
671
  // §28 pin (defFor prefers `defSnapshot` over the live resolver), so a
@@ -748,6 +767,20 @@ export class Engine {
748
767
  return result;
749
768
  // Resolve optimistically outside both locks. The snapshot guard then
750
769
  // revalidates this CAS provenance under add.lock before SQLite begins.
770
+ if (namedExactLockKey !== undefined) {
771
+ if (this.readVerifiedBundleLock === undefined) {
772
+ throw new CallsPinError(step.calls, 'no verified parent bundle lock reader is configured');
773
+ }
774
+ try {
775
+ verifiedParentPin = this.readVerifiedBundleLock(parentDef.bundleDigest)[namedExactLockKey];
776
+ }
777
+ catch (error) {
778
+ throw new CallsPinError(step.calls, `the parent bundle could not be verified: ${error.message}`);
779
+ }
780
+ if (verifiedParentPin === undefined || parentDef.bundleLock?.[namedExactLockKey] !== verifiedParentPin) {
781
+ throw new CallsPinError(step.calls, `the persisted base-coordinate lock differs from the verified parent bundle for ${namedExactLockKey}`);
782
+ }
783
+ }
751
784
  snapshotDef = this.resolveDef(step.calls, parentDef);
752
785
  result = transact();
753
786
  if (result === needsSnapshot)
@@ -1886,6 +1919,7 @@ export class Engine {
1886
1919
  const owes = f.outputs.map((p) => {
1887
1920
  const a = arts.get(p);
1888
1921
  const declared = owedSchema(step, p);
1922
+ const reasons = a?.reasons ?? [];
1889
1923
  return {
1890
1924
  path: p,
1891
1925
  ...(declared !== undefined
@@ -1909,7 +1943,18 @@ export class Engine {
1909
1943
  version: (a?.version ?? 0) + 1,
1910
1944
  judgmentRejects: a?.judgmentRejects ?? 0,
1911
1945
  schemaRejects: a?.schemaRejects ?? 0,
1912
- reasons: a?.reasons ?? [],
1946
+ reasons,
1947
+ // The value the path already holds, but ONLY on a re-offer that
1948
+ // follows a refusal. With an empty reason thread there is no feedback
1949
+ // for a previous value to be feedback ON, so projecting it would put
1950
+ // an artifact-sized payload on every ordinary first offer and buy
1951
+ // nothing. `undefined` is "no value" here, the same reading `consumes`
1952
+ // above gives it. See the field's contract in `types.ts` -- in
1953
+ // particular that this is the REFUSED value only after a judgment or
1954
+ // human reject, since a schema reject never committed one.
1955
+ ...(reasons.length > 0 && a?.value !== undefined
1956
+ ? { previousValue: a.value }
1957
+ : {}),
1913
1958
  };
1914
1959
  });
1915
1960
  const order = {
@@ -73,6 +73,8 @@ export interface CreateEngineOpts {
73
73
  * same reference-mode behavior, no legacy branch.
74
74
  */
75
75
  instructionSource?: OrderInstructionSource;
76
+ /** Verified, index-independent CAS lock reader for replaying named exact calls. */
77
+ readVerifiedBundleLock?: (digest: string) => Readonly<Record<string, string>>;
76
78
  }
77
79
  export interface CreatedEngine {
78
80
  engine: Engine;
@@ -105,6 +105,8 @@ export function createEngine(opts = {}) {
105
105
  if (opts.onListenerError !== undefined)
106
106
  engineOpts.onListenerError = opts.onListenerError;
107
107
  engineOpts.instructionSource = instructionSource;
108
+ if (opts.readVerifiedBundleLock !== undefined)
109
+ engineOpts.readVerifiedBundleLock = opts.readVerifiedBundleLock;
108
110
  const engine = new Engine(store, resolveDef, engineOpts);
109
111
  return { engine, store, defs, resolver: engine.resolver };
110
112
  }
@@ -21,7 +21,7 @@ export { createDefInstructionSource, defInstructionDigest, OrderResolver, substi
21
21
  export type { OrderInstructionLookup, OrderInstructionRef, OrderInstructionSource, OrderRuntimeVars, ResolvedInstructionRecord, ResolvedInstructions, } from './order-resolver.ts';
22
22
  export { Store, openStore, readRuntimeSnapshotBundlePins, StoreVersionError } from './store.ts';
23
23
  export type { ArtifactRow, RunRow, RuntimeSnapshotBundlePins, TaskRow, WorkflowRow } from './store.ts';
24
- export { defDigest, collectWorkflowStoreGarbage, emptyWorkflowStoreIndex, globalStoreRoot, hardenObjectModes, installWorkflowBundle, inspectCasDefs, isDefDigest, loadCasDefs, planWorkflowStoreGc, objectDestRelPath, objectDirForDigest, parseWorkflowCoordinate, parseWorkflowStoreIndex, projectStoreRoot, probeObjectDir, probeStoreRoot, readWorkflowStoreIndex, recoverWorkflowStore, resolveWorkflowCoordinate, resolveWorkflowDigest, serializeWorkflowStoreIndex, storeIndexPath, workflowCoordinate, workflowStoreStatePaths, WORKFLOW_STORE_INDEX_VERSION, WorkflowStoreError, StoreIndexError, StoreDigestError, StoreCoordinateError, StoreAmbiguityError, StoreNotFoundError, StoreIntegrityError, StoreConflictError, StoreDefinitionVerificationError, StoreOriginPolicyError, StorePathError, BundleIngestorUnavailableError, PreCommitVerifierUnavailableError, createExecutionOriginVerifier, originEvidencePath, persistOriginEvidence, readOriginEvidence, } from './store/index.ts';
24
+ export { defDigest, collectWorkflowStoreGarbage, emptyWorkflowStoreIndex, globalStoreRoot, hardenObjectModes, installWorkflowBundle, inspectCasDefs, isDefDigest, loadCasDefs, planWorkflowStoreGc, objectDestRelPath, objectDirForDigest, parseWorkflowCoordinate, parseWorkflowStoreIndex, projectStoreRoot, probeObjectDir, probeStoreRoot, readWorkflowStoreIndex, recoverWorkflowStore, resolveWorkflowCoordinate, resolveWorkflowDigest, serializeWorkflowStoreIndex, storeIndexPath, workflowCoordinate, workflowStoreStatePaths, WORKFLOW_STORE_INDEX_VERSION, WorkflowStoreError, StoreIndexError, StoreDigestError, StoreCoordinateError, StoreAmbiguityError, StoreNotFoundError, StoreIntegrityError, StoreConflictError, StoreDefinitionVerificationError, StoreOriginPolicyError, StorePathError, BundleIngestorUnavailableError, PreCommitVerifierUnavailableError, createExecutionOriginVerifier, createVerifiedBundleLockReader, originEvidencePath, persistOriginEvidence, readOriginEvidence, } from './store/index.ts';
25
25
  export type { BundleInstallResult, BundleIngestor, BundleSource, BundleVerificationEvidence, CasDefInspectionResult, CasDefRegistration, DefDigest, LoadCasDefsArgs, CollectWorkflowStoreGcArgs, InstallWorkflowBundleArgs, PreCommitVerifier, PlanWorkflowStoreGcArgs, ExecutionOriginVerifierInput, RecoverWorkflowStoreArgs, ResolvedWorkflowObject, ResolveWorkflowCoordinateArgs, ResolveWorkflowDigestArgs, ResolutionLevel, StoreLevel, WorkflowCoordinate, WorkflowStoreIndex, WorkflowStoreIndexEntry, WorkflowStoreGcObject, WorkflowStoreGcPlan, WorkflowStoreGcReport, WorkflowStoreStatePaths, } from './store/index.ts';
26
26
  export { buildDef, cancelCleanupSteps, DefError, expandIncludes, finalizeDefs, hashDef, InterfaceCallDefinitionError, lintDef, loadDefFile, loadDefs, loadDefsRaw, parseDef, resolveCallsTarget, SUPPORTED_ENGINE_VERSION, validateDef } from './defs.ts';
27
27
  export { checkInterfaceCompatibility, implementsIssues } from './implements.ts';
package/dist/src/index.js CHANGED
@@ -21,7 +21,7 @@ export { Store, openStore, readRuntimeSnapshotBundlePins, StoreVersionError } fr
21
21
  // The content-addressed WORKFLOW store (distinct from the SQLite runtime
22
22
  // store above): two-level digest-addressed workflow objects + coordinate
23
23
  // index, `.wnlp` bundle installation, and fail-closed resolution.
24
- export { defDigest, collectWorkflowStoreGarbage, emptyWorkflowStoreIndex, globalStoreRoot, hardenObjectModes, installWorkflowBundle, inspectCasDefs, isDefDigest, loadCasDefs, planWorkflowStoreGc, objectDestRelPath, objectDirForDigest, parseWorkflowCoordinate, parseWorkflowStoreIndex, projectStoreRoot, probeObjectDir, probeStoreRoot, readWorkflowStoreIndex, recoverWorkflowStore, resolveWorkflowCoordinate, resolveWorkflowDigest, serializeWorkflowStoreIndex, storeIndexPath, workflowCoordinate, workflowStoreStatePaths, WORKFLOW_STORE_INDEX_VERSION, WorkflowStoreError, StoreIndexError, StoreDigestError, StoreCoordinateError, StoreAmbiguityError, StoreNotFoundError, StoreIntegrityError, StoreConflictError, StoreDefinitionVerificationError, StoreOriginPolicyError, StorePathError, BundleIngestorUnavailableError, PreCommitVerifierUnavailableError, createExecutionOriginVerifier, originEvidencePath, persistOriginEvidence, readOriginEvidence, } from "./store/index.js";
24
+ export { defDigest, collectWorkflowStoreGarbage, emptyWorkflowStoreIndex, globalStoreRoot, hardenObjectModes, installWorkflowBundle, inspectCasDefs, isDefDigest, loadCasDefs, planWorkflowStoreGc, objectDestRelPath, objectDirForDigest, parseWorkflowCoordinate, parseWorkflowStoreIndex, projectStoreRoot, probeObjectDir, probeStoreRoot, readWorkflowStoreIndex, recoverWorkflowStore, resolveWorkflowCoordinate, resolveWorkflowDigest, serializeWorkflowStoreIndex, storeIndexPath, workflowCoordinate, workflowStoreStatePaths, WORKFLOW_STORE_INDEX_VERSION, WorkflowStoreError, StoreIndexError, StoreDigestError, StoreCoordinateError, StoreAmbiguityError, StoreNotFoundError, StoreIntegrityError, StoreConflictError, StoreDefinitionVerificationError, StoreOriginPolicyError, StorePathError, BundleIngestorUnavailableError, PreCommitVerifierUnavailableError, createExecutionOriginVerifier, createVerifiedBundleLockReader, originEvidencePath, persistOriginEvidence, readOriginEvidence, } from "./store/index.js";
25
25
  export { buildDef, cancelCleanupSteps, DefError, expandIncludes, finalizeDefs, hashDef, InterfaceCallDefinitionError, lintDef, loadDefFile, loadDefs, loadDefsRaw, parseDef, resolveCallsTarget, SUPPORTED_ENGINE_VERSION, validateDef } from "./defs.js";
26
26
  export { checkInterfaceCompatibility, implementsIssues } from "./implements.js";
27
27
  export { credentialSlot, hashDefForHub, keychainServiceFor, normalizeOrigin, readStoredCredential } from "./hub.js";
@@ -561,6 +561,9 @@ export declare const WIRE_SCHEMAS: {
561
561
  };
562
562
  };
563
563
  };
564
+ previousValue: {
565
+ description: string;
566
+ };
564
567
  schema: {
565
568
  description: string;
566
569
  oneOf: {
@@ -97,6 +97,9 @@
97
97
  }
98
98
  }
99
99
  },
100
+ "previousValue": {
101
+ "description": "The value this owed path already holds, sent only on a re-offer whose reason thread is non-empty. Absent on a first offer, and absent when the refusal never committed a value. It is the REFUSED value only after a judgment or human reject, which follow a commit; a schema reject refuses the write, so after one this carries the last value that did commit. Any JSON, because it is a def author's artifact value and not a shape this wire contract controls."
102
+ },
100
103
  "schema": {
101
104
  "description": "The JSON Schema the engine will enforce on this owed path at commit time, copied verbatim off the owning produce entry. Absent when that produce declares none, which is the common case and means any JSON is accepted. A JSON Schema is either a keyword object or a bare boolean, so both forms are admitted here.",
102
105
  "oneOf": [{ "type": "object" }, { "type": "boolean" }]
@@ -29,7 +29,7 @@ export interface CasDefRegistration {
29
29
  level: ResolutionLevel;
30
30
  /** Registration purpose. Coordinate aliases are exact versioned call targets. */
31
31
  kind: 'workflow' | 'coordinate';
32
- /** Present only for a full versioned coordinate alias. */
32
+ /** Base package coordinate for an exact alias, including named workflow selectors. */
33
33
  coordinate?: WorkflowCoordinate;
34
34
  }
35
35
  export interface LoadCasDefsArgs {
@@ -325,6 +325,31 @@ function discoverCasDefs(args, tolerant, repairReplacement) {
325
325
  loaded.objectRoot,
326
326
  ])].sort(compareStoreText));
327
327
  }
328
+ // A selector is derived only from this verified coordinate/object pair.
329
+ // Register the digest-scoped alias even for a shadowed global row;
330
+ // the direct alias still obeys project precedence.
331
+ for (const [workflowName, def] of loaded.defs) {
332
+ const selector = `${indexed.coordinate}#${workflowName}`;
333
+ for (const key of [
334
+ digestScopedCallsTargetKey(digest, selector),
335
+ ...(indexed.registerAlias ? [selector] : []),
336
+ ]) {
337
+ if (registeredCoordinateKeys.has(key))
338
+ continue;
339
+ registeredCoordinateKeys.add(key);
340
+ registrations.push({
341
+ key,
342
+ qualified: `${loaded.manifest.package.name}/${workflowName}`,
343
+ bare: workflowName,
344
+ def,
345
+ bundleDigest: digest,
346
+ bundlePackage: loaded.manifest.package.name,
347
+ level: loaded.level,
348
+ kind: 'coordinate',
349
+ coordinate: indexed.coordinate,
350
+ });
351
+ }
352
+ }
328
353
  if (target === undefined) {
329
354
  if (indexed.registerAlias) {
330
355
  args.warn(`warning: coordinate '${indexed.coordinate}' is not callable because the bundle exports ` +
@@ -7,6 +7,7 @@
7
7
  import { lstatSync, readFileSync, readdirSync, } from 'node:fs';
8
8
  import { dirname, join } from 'node:path';
9
9
  import { parseManifestBytes } from "../bundle/manifest.js";
10
+ import { parseVersionedCallTarget } from "../bundle/manifest.js";
10
11
  import { loadDefFile } from "../defs.js";
11
12
  import { acquireInstallLock, ensureDirectoryPathNoSymlink, guardStateFile, probeDirectoryPath, recoverInterruptedInstall, releaseInstallLock, rmRecursiveForce, STAGING_DIRNAME, } from "../install.js";
12
13
  import { randId } from "../util.js";
@@ -158,8 +159,8 @@ export function planWorkflowStoreGc(args) {
158
159
  for (const registration of registrations) {
159
160
  if (registration.kind === 'coordinate'
160
161
  && registration.coordinate !== undefined
161
- && registration.key === registration.coordinate) {
162
- directCoordinateDigests.set(registration.coordinate, registration.bundleDigest);
162
+ && (registration.key === registration.coordinate || registration.key.startsWith(`${registration.coordinate}#`))) {
163
+ directCoordinateDigests.set(registration.key, registration.bundleDigest);
163
164
  }
164
165
  }
165
166
  const projectObjects = scanObjects(projectRoot);
@@ -332,13 +333,14 @@ export function planWorkflowStoreGc(args) {
332
333
  'but no exact callable coordinate with verified bytes is installed');
333
334
  };
334
335
  // A retained filesystem/add/legacy parent carries no bundle digest or lock,
335
- // but its explicit namespace/name@version call still resolves through the
336
- // direct CAS coordinate alias. Root that exact coordinate and the digest it
336
+ // but its exact package or named-workflow call still resolves through the
337
+ // direct CAS alias. Root its base coordinate and the digest it
337
338
  // selects before walking the selected object's own manifest locks.
338
- for (const coordinate of [...retainedExactCalls].sort(compareStoreText)) {
339
- const digest = directCoordinateDigests.get(coordinate);
339
+ for (const target of [...retainedExactCalls].sort(compareStoreText)) {
340
+ const coordinate = parseVersionedCallTarget(target).coordinate;
341
+ const digest = directCoordinateDigests.get(target);
340
342
  if (digest === undefined) {
341
- throw new Error(`workflow-store GC cannot preserve retained exact calls target '${coordinate}': ` +
343
+ throw new Error(`workflow-store GC cannot preserve retained exact calls target '${target}': ` +
342
344
  'no callable exact coordinate is installed');
343
345
  }
344
346
  preserveCoordinate(coordinate, digest, `retained exact calls target '${coordinate}'`, `workflow-store GC cannot preserve retained exact calls target '${coordinate}' at ${digest}: ` +
@@ -18,6 +18,7 @@ export { hardenObjectModes, installWorkflowBundle, objectDestRelPath, recoverWor
18
18
  export { createBundleIngestor, verifyHardenedWorkflowObjectModesSync, verifyWorkflowObjectSync, } from './ingestor.ts';
19
19
  export type { BundleIngestorOptions } from './ingestor.ts';
20
20
  export { inspectCasDefs, loadCasDefs } from './def-source.ts';
21
+ export { createVerifiedBundleLockReader } from './verified-lock.ts';
21
22
  export type { CasDefInspectionResult, CasDefRegistration, LoadCasDefsArgs, } from './def-source.ts';
22
23
  export { collectWorkflowStoreGarbage, planWorkflowStoreGc } from './gc.ts';
23
24
  export type { CollectWorkflowStoreGcArgs, PlanWorkflowStoreGcArgs, WorkflowStoreGcObject, WorkflowStoreGcPlan, WorkflowStoreGcReport, } from './gc.ts';
@@ -16,6 +16,7 @@ export { hardenObjectModes, installWorkflowBundle, objectDestRelPath, recoverWor
16
16
  export { createBundleIngestor, verifyHardenedWorkflowObjectModesSync, verifyWorkflowObjectSync, } from "./ingestor.js";
17
17
  // ---- WS-6 CAS -> calls: def bridge ----
18
18
  export { inspectCasDefs, loadCasDefs } from "./def-source.js";
19
+ export { createVerifiedBundleLockReader } from "./verified-lock.js";
19
20
  // ---- workflow-store reachability GC ----
20
21
  export { collectWorkflowStoreGarbage, planWorkflowStoreGc } from "./gc.js";
21
22
  // ---- WP-E2a origin execution policy ----
@@ -25,7 +25,7 @@ import { chmodSync, existsSync, lstatSync, readFileSync, readdirSync } from 'nod
25
25
  import { dirname, join } from 'node:path';
26
26
  import { randId } from "../util.js";
27
27
  import { DefError, digestScopedCallsTargetKey, finalizeDefs, lintDef, loadDefFile, loadDefsRaw, validateDef, } from "../defs.js";
28
- import { parseManifestBytes } from "../bundle/manifest.js";
28
+ import { isVersionedReference, parseManifestBytes, parseVersionedCallTarget } from "../bundle/manifest.js";
29
29
  import { hasDefiniteCheckDefect, modelCheck } from "../model.js";
30
30
  import { acquireInstallLock, canonicalJsonBytes, commitInstall, createRecoveryMarker, ensureDirectoryPathNoSymlink, finalizeInstallCommit, guardStateFile, multiSegmentPathViolation, probeDirectoryPath, recoverInterruptedInstall, recordRecoveryMarkerPriorIdentity, releaseInstallLock, removeAddJournal, removeRecoveryMarker, rmRecursiveForce, RollbackFailedError, rollbackInstallCommit, sha256Hex, writeAddJournal, } from "../install.js";
31
31
  import { BundleIngestorUnavailableError, PreCommitVerifierUnavailableError, StoreConflictError, StoreIntegrityError, StorePathError, } from "./types.js";
@@ -62,7 +62,9 @@ function assertManifestLocksResolvable(args) {
62
62
  .map((registration) => registration.key));
63
63
  for (const [coordinate, rawDigest] of entries.sort(([a], [b]) => compareStoreText(a, b))) {
64
64
  const digest = defDigest(rawDigest);
65
- if (!callableKeys.has(digestScopedCallsTargetKey(digest, coordinate))) {
65
+ const usedTargets = args.callsTargets.filter((target) => target.includes('@') && parseVersionedCallTarget(target).coordinate === coordinate);
66
+ const targets = usedTargets.length > 0 ? usedTargets : [coordinate];
67
+ if (targets.some((target) => !callableKeys.has(digestScopedCallsTargetKey(digest, target)))) {
66
68
  throw new Error(`refusing bundle install: lock target '${coordinate}' pinned to ${digest} ` +
67
69
  'is no longer exactly callable from the combined workflow store');
68
70
  }
@@ -265,7 +267,6 @@ export async function installWorkflowBundle(args) {
265
267
  staged = new Map();
266
268
  try {
267
269
  const manifest = parseManifestBytes(readFileSync(manifestPath));
268
- externalVersionedCalls = new Set(Object.keys(manifest.lock));
269
270
  stagedBundleLock = manifest.lock;
270
271
  for (const [workflowName, workflowPath] of Object.entries(manifest.workflows)) {
271
272
  const workflowFile = join(stagingDir, workflowPath);
@@ -302,6 +303,10 @@ export async function installWorkflowBundle(args) {
302
303
  staged = loadDefsRaw(stagingDir, failures);
303
304
  reasons.push(...failures.map((failure) => `${failure.file}: ${failure.error}`));
304
305
  }
306
+ if (existsSync(manifestPath)) {
307
+ externalVersionedCalls = new Set([...staged.values()].flatMap((def) => def.steps.map((step) => step.calls)
308
+ .filter((target) => target !== undefined && isVersionedReference(target))));
309
+ }
305
310
  for (const stagedDef of staged.values()) {
306
311
  const lintResult = lintDef(stagedDef);
307
312
  reasons.push(...lintResult.errors.map((err) => `${stagedDef.name}: ${err}`));
@@ -374,6 +379,7 @@ export async function installWorkflowBundle(args) {
374
379
  projectRoot: args.projectRoot,
375
380
  globalRoot: args.globalRoot,
376
381
  lock: stagedBundleLock,
382
+ callsTargets: [...staged.values()].flatMap((def) => def.steps.map((step) => step.calls).filter((target) => target !== undefined)),
377
383
  ...(repairRequired ? { repairReplacement: { root, digest, objectDir: stagingDir } } : {}),
378
384
  });
379
385
  // The post-install index, computed BEFORE the commit point so its exact
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { join } from 'node:path';
11
11
  import { readFileSync } from 'node:fs';
12
- import { isVersionedReference, parseManifestBytes } from "../bundle/manifest.js";
12
+ import { isVersionedReference, parseManifestBytes, parseVersionedCallTarget } from "../bundle/manifest.js";
13
13
  import { defInstructionDigest } from "../order-resolver.js";
14
14
  import { digestScopedCallsTargetKey, finalizeDefs, loadDefFile, resolveCallsTarget } from "../defs.js";
15
15
  import { readWorkflowStoreIndex } from "./index-file.js";
@@ -150,8 +150,11 @@ export function createStoreInstructionSource(args) {
150
150
  };
151
151
  const selectLockedTarget = (target, childDigest, child) => {
152
152
  let coordinate;
153
+ let namedWorkflow;
153
154
  try {
154
- coordinate = parseWorkflowCoordinate(target);
155
+ const parsed = parseVersionedCallTarget(target);
156
+ coordinate = parseWorkflowCoordinate(parsed.coordinate);
157
+ namedWorkflow = parsed.workflow;
155
158
  }
156
159
  catch (error) {
157
160
  throw new StoreIntegrityError('object-corrupt', childDigest, `locked calls target '${target}' has an invalid coordinate: ${errorText(error)}`);
@@ -160,7 +163,7 @@ export function createStoreInstructionSource(args) {
160
163
  || coordinate.version !== child.manifest.package.version) {
161
164
  throw new StoreIntegrityError('object-corrupt', childDigest, `locked calls target '${target}' does not match child manifest package '${child.manifest.package.name}@${child.manifest.package.version}'`);
162
165
  }
163
- const workflowName = child.manifest.default
166
+ const workflowName = namedWorkflow ?? child.manifest.default
164
167
  ?? (child.defs.size === 1 ? child.defs.keys().next().value : undefined);
165
168
  if (workflowName === undefined) {
166
169
  throw new StoreIntegrityError('object-corrupt', childDigest, `locked calls target '${target}' digest ${childDigest} exports multiple workflows and has no default`);
@@ -181,10 +184,11 @@ export function createStoreInstructionSource(args) {
181
184
  if (step.calls === undefined || !isVersionedReference(step.calls))
182
185
  continue;
183
186
  const target = step.calls;
184
- if (!Object.prototype.hasOwnProperty.call(object.manifest.lock, target)) {
187
+ const lockKey = parseVersionedCallTarget(target).coordinate;
188
+ if (!Object.prototype.hasOwnProperty.call(object.manifest.lock, lockKey)) {
185
189
  throw new StoreIntegrityError('object-corrupt', object.bundleDigest, `locked calls target '${target}' has no entry in parent bundle ${object.bundleDigest} manifest lock`);
186
190
  }
187
- const childDigest = defDigest(object.manifest.lock[target]);
191
+ const childDigest = defDigest(object.manifest.lock[lockKey]);
188
192
  let child;
189
193
  for (const candidate of dependencyRoots(object)) {
190
194
  try {
@@ -0,0 +1,4 @@
1
+ export declare function createVerifiedBundleLockReader(args: {
2
+ projectRoot?: string;
3
+ globalRoot: string;
4
+ }): (digest: string) => Readonly<Record<string, string>>;
@@ -0,0 +1,38 @@
1
+ /** Read a bundle lock from verified CAS bytes without requiring an index row. */
2
+ import { readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { parseManifestBytes } from "../bundle/manifest.js";
5
+ import { verifyWorkflowObjectSync } from "./ingestor.js";
6
+ import { coordinateDigestReadSync, probeObjectDir, probeStoreRoot, projectStoreRoot } from "./resolve.js";
7
+ import { defDigest, objectDirForDigest, StoreIntegrityError } from "./types.js";
8
+ export function createVerifiedBundleLockReader(args) {
9
+ const roots = [args.projectRoot, args.globalRoot]
10
+ .filter((root) => root !== undefined)
11
+ .map(projectStoreRoot)
12
+ .filter((root, index, all) => all.indexOf(root) === index);
13
+ return (rawDigest) => {
14
+ const digest = defDigest(rawDigest);
15
+ for (const [index, root] of roots.entries()) {
16
+ const level = index === 0 && args.projectRoot !== undefined ? 'project' : 'global';
17
+ if (probeStoreRoot(root) === 'absent')
18
+ continue;
19
+ const objectDir = objectDirForDigest(root, digest);
20
+ try {
21
+ const lock = coordinateDigestReadSync(root, digest, () => {
22
+ if (probeObjectDir(objectDir, digest, level) === 'absent')
23
+ return undefined;
24
+ verifyWorkflowObjectSync(objectDir, digest, { coordinateRepair: false });
25
+ return parseManifestBytes(readFileSync(join(objectDir, 'bundle.yaml'))).lock;
26
+ });
27
+ if (lock !== undefined)
28
+ return lock;
29
+ }
30
+ catch (error) {
31
+ if (error instanceof StoreIntegrityError)
32
+ throw error;
33
+ throw new StoreIntegrityError('object-corrupt', digest, `${level}-level object could not be verified: ${error.message}`);
34
+ }
35
+ }
36
+ throw new StoreIntegrityError('object-missing', digest, 'parent bundle is absent from the project and global workflow stores');
37
+ };
38
+ }
package/dist/src/store.js CHANGED
@@ -16,6 +16,7 @@ import { DatabaseSync } from 'node:sqlite';
16
16
  import { lstatSync } from 'node:fs';
17
17
  import { detId, nowMs } from "./util.js";
18
18
  import { compareStoreText, defDigest, isDefDigest, parseWorkflowCoordinate } from "./store/types.js";
19
+ import { parseVersionedCallTarget } from "./bundle/manifest.js";
19
20
  import { withWorkflowSnapshotStoreGuard } from "./store/snapshot-guard.js";
20
21
  function exactCallsFromSnapshot(record, workflow) {
21
22
  const rawSteps = record.steps;
@@ -37,8 +38,9 @@ function exactCallsFromSnapshot(record, workflow) {
37
38
  }
38
39
  if (!calls.includes('@'))
39
40
  continue;
41
+ let lockKey;
40
42
  try {
41
- parseWorkflowCoordinate(calls);
43
+ lockKey = parseVersionedCallTarget(calls).coordinate;
42
44
  }
43
45
  catch (error) {
44
46
  throw new Error(`workflow '${workflow}' has malformed exact def_snapshot calls target ${JSON.stringify(calls)}: ` +
@@ -48,7 +50,7 @@ function exactCallsFromSnapshot(record, workflow) {
48
50
  if (typeof rawLock === 'object'
49
51
  && rawLock !== null
50
52
  && !Array.isArray(rawLock)
51
- && Object.prototype.hasOwnProperty.call(rawLock, calls))
53
+ && Object.prototype.hasOwnProperty.call(rawLock, lockKey))
52
54
  continue;
53
55
  exactCalls.add(calls);
54
56
  }
@@ -281,6 +281,46 @@ export interface Order {
281
281
  judgmentRejects: number;
282
282
  schemaRejects: number;
283
283
  reasons: ReasonEntry[];
284
+ /**
285
+ * The value this owed path already holds, projected ONLY when the reason
286
+ * thread above is non-empty -- that is, only on a re-offer that follows a
287
+ * refusal.
288
+ *
289
+ * WHY IT IS ON THE ORDER. The same argument as `schema` below, for content
290
+ * instead of shape. `reasons` already tells a re-offered producer THAT its
291
+ * last submission was refused and why. It does not tell it WHAT it
292
+ * submitted. A producer reading "your plan was rejected because phase 3
293
+ * cites no artifact", with no sight of the plan it wrote, has to rebuild
294
+ * the whole value from memory to change one phase, and the rebuild
295
+ * silently drops the parts nobody objected to. That is the same rework
296
+ * `schema` exists to prevent, arriving through a different door: feedback
297
+ * is actionable only against the thing it is feedback ON.
298
+ *
299
+ * WHAT IT ACTUALLY HOLDS, which is NOT always the refused value:
300
+ *
301
+ * - After a judgment or human reject, it IS the refused value. Those
302
+ * rejects FOLLOW a commit -- `green()` had already written the artifact
303
+ * and bumped `version` -- so what stands here is what the judge read.
304
+ * - After a schema reject or an artifact-bind reject, it is NOT. Those
305
+ * refuse the write itself, so nothing was committed, and this carries
306
+ * the last value that DID commit, or is absent when none ever did.
307
+ *
308
+ * It is deliberately not named `rejectedValue`. Half the refusal kinds
309
+ * that put a reason on this thread never commit the value they refused,
310
+ * and a name asserting otherwise would be read as a guarantee the engine
311
+ * cannot make. A layer that needs the distinction reads `reasons`, which
312
+ * records each refusal's kind.
313
+ *
314
+ * Absent on a first firing, which has no artifact at all, and absent on
315
+ * any re-offer whose reason thread is empty. Gating on the thread is what
316
+ * keeps an artifact-sized payload off the ordinary offer and confines it
317
+ * to the rework path, the only path able to use it.
318
+ *
319
+ * It is a COPY taken at claim time, under the same contract as `schema`:
320
+ * `Store.restampOrderTarget`, the one post-claim writer of a persisted
321
+ * order, touches only `owes[].version`.
322
+ */
323
+ previousValue?: unknown;
284
324
  /**
285
325
  * The JSON Schema the engine will enforce on this output at commit time,
286
326
  * copied verbatim off the owning produce entry. Absent when that produce
package/docs/authoring.md CHANGED
@@ -258,6 +258,18 @@ unresolvable path remains deferred until a valid value arrives.
258
258
  produced it. What bounds where a worker may actually run is machine-side and
259
259
  belongs to the operator running the shift, not to the definition.
260
260
 
261
+ The resolved value can also outlive the directory it names: a cleanup step
262
+ reclaims a worktree, then a rejection re-arms an earlier step whose workdir was
263
+ that worktree. A worker that is handed such an order does not spawn or open a
264
+ session there. It releases the order with the reason
265
+ `step workdir no longer exists: <absolute path>`, which the hub records as a
266
+ routing alert (`owenloop routing alerts --workflow <wf>`). The hub keeps only
267
+ the first such observation per workflow and step, so a worker that is offered
268
+ the same order again and releases it again adds no further rows. The release
269
+ is not a failure: the step stays eligible, and the fix is to supply a workdir
270
+ that exists (re-run the provisioning step, or provide a fresh path) rather
271
+ than to retry the order as-is.
272
+
261
273
  ## `executor:` — declaring the executor
262
274
 
263
275
  Every step in every def written before this feature dispatches to an LLM