@fro.bot/systematic 3.21.6 → 3.21.7

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/dist/index.js CHANGED
@@ -8381,8 +8381,9 @@ function parseReadback(input) {
8381
8381
  "resourceRevisionIdentity",
8382
8382
  "pullRequest",
8383
8383
  "checkState",
8384
- "reviewDecision"
8385
- ])) || !isBoundedString(input.workspaceIdentity) || input.operation !== undefined && !isOperation4(input.operation)) {
8384
+ "reviewDecision",
8385
+ "propagate"
8386
+ ])) || !isBoundedString(input.workspaceIdentity) || input.operation !== undefined && !isOperation4(input.operation) || input.propagate !== undefined && typeof input.propagate !== "boolean") {
8386
8387
  return;
8387
8388
  }
8388
8389
  const after = parseLegacyReadbackAfter({
@@ -8408,7 +8409,8 @@ function parseReadback(input) {
8408
8409
  resourceRevisionIdentity: after.resourceRevisionIdentity,
8409
8410
  pullRequest: after.pullRequest,
8410
8411
  checkState: after.checkState,
8411
- reviewDecision: after.reviewDecision
8412
+ reviewDecision: after.reviewDecision,
8413
+ ...input.propagate === undefined ? {} : { propagate: input.propagate }
8412
8414
  };
8413
8415
  }
8414
8416
  function parseLegacyReadbackAfter(input) {
@@ -8845,7 +8847,7 @@ function createWorkflowGuard(options) {
8845
8847
  const expected = unit ? currentResource(unit, readback.operation) : currentResourceIdentities.get(readback.operation);
8846
8848
  const changed = readback.resourceIdentity !== expected;
8847
8849
  currentResourceIdentities.set(readback.operation, readback.resourceIdentity);
8848
- if (readback.operation === "pr-creation" && unit) {
8850
+ if (readback.operation === "pr-creation" && unit && readback.propagate !== false) {
8849
8851
  propagatePullRequestScope(unit, readback.resourceIdentity);
8850
8852
  }
8851
8853
  return changed;
@@ -10192,6 +10194,9 @@ function createWorkflowGuard(options) {
10192
10194
  currentOperationContext() {
10193
10195
  return currentOperationContext();
10194
10196
  },
10197
+ hasResourceBaseline(operation) {
10198
+ return epoch?.unit ? currentResource(epoch.unit, operation) !== undefined : false;
10199
+ },
10195
10200
  status() {
10196
10201
  return projection();
10197
10202
  },
@@ -10846,14 +10851,15 @@ function isSuccessfulAfter(output) {
10846
10851
  function isSuccessfulSkillAfter(output) {
10847
10852
  return parseHostOutput(output, { maxOutputLength: Number.POSITIVE_INFINITY }) !== undefined;
10848
10853
  }
10849
- function statusForTool(status, unavailableCause) {
10854
+ function statusForTool(status, unavailableCause, seedDeferrals = []) {
10850
10855
  return JSON.stringify({
10851
10856
  state: status.state,
10852
10857
  reasonCode: status.reasonCode,
10853
10858
  ...status.repair ? { repair: status.repair } : {},
10854
10859
  satisfiedOperations: status.satisfiedOperations,
10855
10860
  missingOperations: status.missingOperations,
10856
- ...unavailableCause && status.state === "unavailable" ? { firstUnavailableCause: unavailableCause } : {}
10861
+ ...unavailableCause && status.state === "unavailable" ? { firstUnavailableCause: unavailableCause } : {},
10862
+ ...seedDeferrals.length > 0 ? { seedDeferrals } : {}
10857
10863
  });
10858
10864
  }
10859
10865
  function markerStatusRank(state) {
@@ -11039,10 +11045,15 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
11039
11045
  const blockedQuestionCalls = new Map;
11040
11046
  const consumedQuestionTargets = new Set;
11041
11047
  let firstUnavailableCause;
11048
+ let seedDeferralRecord;
11049
+ let unitStartGeneration = 0;
11042
11050
  function startFreshUnit(input, policy) {
11043
11051
  const result = guard.startUnit(input, policy);
11044
- if (result.status === "started")
11052
+ if (result.status === "started") {
11053
+ unitStartGeneration += 1;
11045
11054
  firstUnavailableCause = undefined;
11055
+ seedDeferralRecord = undefined;
11056
+ }
11046
11057
  return result;
11047
11058
  }
11048
11059
  function recordUnavailable(target, cause) {
@@ -12114,10 +12125,11 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12114
12125
  if (!remoteSnapshot)
12115
12126
  return { operation: classification.category };
12116
12127
  try {
12117
- return {
12118
- operation: classification.category,
12119
- before: await remoteSnapshot(classification.category, "before")
12120
- };
12128
+ let before = await remoteSnapshot(classification.category, "before");
12129
+ if (before.status === "unavailable" && before.reasonCode === "command-timeout" && deferredSeedFor(classification.category)) {
12130
+ before = await remoteSnapshot(classification.category, "before");
12131
+ }
12132
+ return { operation: classification.category, before };
12121
12133
  } catch {
12122
12134
  return { operation: classification.category };
12123
12135
  }
@@ -12125,6 +12137,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12125
12137
  async function prepareOperation(host, args2) {
12126
12138
  if (!options.observer || !isLocalOperationTool(host.tool))
12127
12139
  return;
12140
+ const initiator = currentInitiator();
12128
12141
  const { parentTargetRoot, sessionLocation } = effectiveTargetContext();
12129
12142
  const fingerprint = argsFingerprint(ledger, host.tool, args2, sessionLocation);
12130
12143
  if (!fingerprint) {
@@ -12185,6 +12198,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12185
12198
  observer: operationObserver
12186
12199
  });
12187
12200
  const remote = await remoteIntentForOperation(host, args2, operationObserver);
12201
+ if (remote) {
12202
+ bindDeferredBaseline(remote.operation, remote.before, operationObserver, initiator);
12203
+ }
12188
12204
  pendingOperations.set(callDigest, {
12189
12205
  callID: host.callID,
12190
12206
  tool: host.tool,
@@ -12194,6 +12210,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12194
12210
  registeredWorktreeIdentity: registeredIdentity,
12195
12211
  observer: operationObserver,
12196
12212
  before: result.snapshot,
12213
+ ...initiator ? { initiator } : {},
12197
12214
  ...remote ? { remoteOperation: remote.operation, remoteBefore: remote.before } : {}
12198
12215
  });
12199
12216
  }
@@ -12323,52 +12340,151 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12323
12340
  timedOut: local.reasonCode === "command-timeout"
12324
12341
  };
12325
12342
  }
12326
- for (const operation of remoteOperations) {
12327
- const cause = await seedRemoteScope(remoteSnapshot, operation, local.snapshot);
12328
- if (cause)
12329
- return cause;
12343
+ return seedEachRemoteScope(remoteOperations, remoteSnapshot, local.snapshot);
12344
+ }
12345
+ async function seedEachRemoteScope(operations, reader, local) {
12346
+ for (const operation of operations) {
12347
+ const outcome = await seedRemoteScope(reader, operation, local);
12348
+ if (outcome.kind === "fatal")
12349
+ return outcome.cause;
12350
+ if (outcome.kind === "deferred") {
12351
+ recordSeedDeferral(operation, outcome.reasonCode);
12352
+ }
12330
12353
  }
12331
12354
  return;
12332
12355
  }
12356
+ function recordSeedDeferral(operation, reasonCode) {
12357
+ if (guard.hasResourceBaseline(operation))
12358
+ return;
12359
+ const observer = options.observer;
12360
+ if (!observer)
12361
+ return;
12362
+ seedDeferralEntries(true).push({
12363
+ operation,
12364
+ reasonCode,
12365
+ observer,
12366
+ targetIdentity: observer.targetDigest
12367
+ });
12368
+ }
12369
+ function seedDeferralEntries(reset = false) {
12370
+ const unitId = guard.status().unit?.unitId;
12371
+ if (!unitId)
12372
+ return [];
12373
+ if (seedDeferralRecord?.unitId === unitId)
12374
+ return seedDeferralRecord.entries;
12375
+ if (!reset)
12376
+ return [];
12377
+ seedDeferralRecord = { unitId, entries: [] };
12378
+ return seedDeferralRecord.entries;
12379
+ }
12380
+ function deferredSeedFor(operation) {
12381
+ return seedDeferralEntries().find((entry) => entry.operation === operation);
12382
+ }
12383
+ function clearSeedDeferral(operation) {
12384
+ if (!seedDeferralRecord)
12385
+ return;
12386
+ const index = seedDeferralRecord.entries.findIndex((entry) => entry.operation === operation);
12387
+ if (index !== -1)
12388
+ seedDeferralRecord.entries.splice(index, 1);
12389
+ }
12390
+ function bindDeferredBaseline(operation, before, observer, initiator) {
12391
+ if (!initiator || !isCurrentInitiator(initiator))
12392
+ return;
12393
+ const deferred = deferredSeedFor(operation);
12394
+ if (!deferred)
12395
+ return;
12396
+ if (guard.hasResourceBaseline(operation)) {
12397
+ clearSeedDeferral(operation);
12398
+ return;
12399
+ }
12400
+ if (!before || !sameSeedObserver(deferred, observer))
12401
+ return;
12402
+ bindFromBeforeRead(operation, before);
12403
+ }
12404
+ function bindFromBeforeRead(operation, before) {
12405
+ if (before.status === "missing-resource") {
12406
+ if (operation === "pr-creation")
12407
+ clearSeedDeferral(operation);
12408
+ return;
12409
+ }
12410
+ if (before.status !== "available")
12411
+ return;
12412
+ const observed = guard.observeReadback(deferredBaselineReadback(operation, before.snapshot));
12413
+ if (observed.status !== "rejected")
12414
+ clearSeedDeferral(operation);
12415
+ }
12416
+ function currentInitiator() {
12417
+ const current = guard.status();
12418
+ return current.epoch && current.unit ? {
12419
+ epochId: current.epoch.epochId,
12420
+ unitId: current.unit.unitId,
12421
+ generation: unitStartGeneration
12422
+ } : undefined;
12423
+ }
12424
+ function isCurrentInitiator(initiator) {
12425
+ const current = currentInitiator();
12426
+ return current !== undefined && current.epochId === initiator.epochId && current.unitId === initiator.unitId && current.generation === initiator.generation;
12427
+ }
12428
+ function sameSeedObserver(deferred, observer) {
12429
+ return observer === deferred.observer && observer.targetDigest === deferred.targetIdentity;
12430
+ }
12431
+ function deferredBaselineReadback(operation, snapshot) {
12432
+ return {
12433
+ operation,
12434
+ workspaceIdentity: options.workspaceIdentity,
12435
+ resourceIdentity: snapshot.resourceIdentity,
12436
+ ...operation === "push" ? { resourceRevisionIdentity: snapshot.resourceRevisionIdentity } : {},
12437
+ ...operation === "pr-creation" ? { propagate: false } : {}
12438
+ };
12439
+ }
12440
+ function currentSeedDeferrals() {
12441
+ return seedDeferralEntries().map(({ operation, reasonCode }) => ({
12442
+ operation,
12443
+ reasonCode
12444
+ }));
12445
+ }
12446
+ function fatalSeed(cause) {
12447
+ return { kind: "fatal", cause };
12448
+ }
12333
12449
  async function seedRemoteScope(reader, operation, local) {
12334
12450
  const result = await readRemoteScope(reader, operation, "before");
12335
12451
  if (!result) {
12336
- return {
12452
+ return fatalSeed({
12337
12453
  site: "seed-remote-scope",
12338
12454
  kind: "remote-scope-unreadable",
12339
12455
  operation,
12340
12456
  timedOut: false
12341
- };
12457
+ });
12342
12458
  }
12343
12459
  if (result.status === "missing-resource") {
12344
- const allowed = operation === "pr-creation" || operation === "check-readback" || operation === "review-readback";
12345
- return allowed ? undefined : {
12346
- site: "seed-remote-scope",
12347
- kind: "remote-scope-missing-resource",
12348
- operation,
12349
- timedOut: false
12350
- };
12460
+ if (operation === "push") {
12461
+ return { kind: "deferred", reasonCode: "missing-resource" };
12462
+ }
12463
+ return { kind: "tolerated" };
12351
12464
  }
12352
12465
  if (result.status !== "available") {
12353
- return {
12466
+ if (result.reasonCode === "command-timeout") {
12467
+ return { kind: "deferred", reasonCode: "command-timeout" };
12468
+ }
12469
+ return fatalSeed({
12354
12470
  site: "seed-remote-scope",
12355
12471
  kind: "remote-scope-unavailable",
12356
12472
  operation,
12357
12473
  reasonCode: result.reasonCode,
12358
- timedOut: result.reasonCode === "command-timeout"
12359
- };
12474
+ timedOut: false
12475
+ });
12360
12476
  }
12361
12477
  const observed = guard.observeReadback(remoteReadbackInput(operation, local, options.workspaceIdentity, result.snapshot, operation !== "pr-creation"));
12362
12478
  if (observed.status === "rejected") {
12363
- return {
12479
+ return fatalSeed({
12364
12480
  site: "seed-remote-scope",
12365
12481
  kind: "remote-readback-rejected",
12366
12482
  operation,
12367
12483
  reasonCode: observed.reasonCode,
12368
12484
  timedOut: false
12369
- };
12485
+ });
12370
12486
  }
12371
- return;
12487
+ return { kind: "seeded" };
12372
12488
  }
12373
12489
  async function finishSkill(host, output) {
12374
12490
  const callDigest = digestCall(ledger, host.callID);
@@ -12788,8 +12904,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12788
12904
  tool: host.tool,
12789
12905
  ...command ? { command } : {},
12790
12906
  context: {
12791
- epochId: current.epoch.epochId,
12792
- unitId: current.unit.unitId,
12907
+ epochId: pending.initiator?.epochId ?? current.epoch.epochId,
12908
+ unitId: pending.initiator?.unitId ?? current.unit.unitId,
12793
12909
  workspaceIdentity: options.workspaceIdentity,
12794
12910
  repositoryIdentity: pending.before.repositoryRevisionDigest,
12795
12911
  worktreeIdentity: pending.before.worktreeRevisionDigest,
@@ -12797,7 +12913,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12797
12913
  ...pending.remoteBefore?.status === "available" ? {
12798
12914
  resourceIdentity: pending.remoteBefore.snapshot.resourceIdentity,
12799
12915
  resourceRevisionIdentity: pending.remoteBefore.snapshot.resourceRevisionIdentity
12800
- } : operation === "pr-creation" && remoteAfter ? { resourceIdentity: remoteAfter.resourceIdentity } : {}
12916
+ } : operation === "pr-creation" && remoteAfter && pending.remoteBefore?.status === "missing-resource" ? { resourceIdentity: remoteAfter.resourceIdentity } : {}
12801
12917
  },
12802
12918
  after: {
12803
12919
  workspaceIdentity: options.workspaceIdentity,
@@ -12850,13 +12966,24 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12850
12966
  return;
12851
12967
  }
12852
12968
  }
12969
+ function ownsOperation(pending) {
12970
+ return !pending.initiator || isCurrentInitiator(pending.initiator);
12971
+ }
12972
+ function sealLostOperation(callDigest, pending) {
12973
+ sealOperation(callDigest, pending, true);
12974
+ return { status: "ignored" };
12975
+ }
12853
12976
  async function completeOperationObservation(callDigest, host, pending, output) {
12977
+ if (!ownsOperation(pending))
12978
+ return sealLostOperation(callDigest, pending);
12854
12979
  const parsedOutput = parseHostOutput(output);
12855
12980
  if (!parsedOutput) {
12856
12981
  sealOperation(callDigest, pending, true);
12857
12982
  return { status: "unavailable" };
12858
12983
  }
12859
12984
  const afterSnapshot = await captureAfterOperation(pending);
12985
+ if (!ownsOperation(pending))
12986
+ return sealLostOperation(callDigest, pending);
12860
12987
  if (!afterSnapshot) {
12861
12988
  sealOperation(callDigest, pending, true);
12862
12989
  return { status: "unavailable" };
@@ -12867,6 +12994,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12867
12994
  return { status: "ignored" };
12868
12995
  }
12869
12996
  const classification = await classifyLocalObservation(observation);
12997
+ if (!ownsOperation(pending))
12998
+ return sealLostOperation(callDigest, pending);
12870
12999
  if (classification.status !== "ready") {
12871
13000
  sealOperation(callDigest, pending, true);
12872
13001
  return { status: classification.status };
@@ -12874,6 +13003,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12874
13003
  let finalObservation = classification.observation;
12875
13004
  if (remoteOperation(finalObservation.operation)) {
12876
13005
  const remoteAfter = await captureRemoteAfter(finalObservation.operation, pending.observer);
13006
+ if (!ownsOperation(pending)) {
13007
+ return sealLostOperation(callDigest, pending);
13008
+ }
12877
13009
  if (!remoteAfter) {
12878
13010
  sealOperation(callDigest, pending, true);
12879
13011
  return { status: "unavailable" };
@@ -12884,7 +13016,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12884
13016
  return { status: "ignored" };
12885
13017
  }
12886
13018
  finalObservation = rebuilt;
12887
- if (finalObservation.operation === "pr-creation" && pending.remoteBefore?.status !== "available") {
13019
+ if (finalObservation.operation === "pr-creation" && pending.remoteBefore?.status === "missing-resource") {
12888
13020
  const seeded = guard.observeReadback({
12889
13021
  operation: "pr-creation",
12890
13022
  workspaceIdentity: options.workspaceIdentity,
@@ -12899,6 +13031,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12899
13031
  }
12900
13032
  }
12901
13033
  }
13034
+ if (!ownsOperation(pending))
13035
+ return sealLostOperation(callDigest, pending);
12902
13036
  const observed = await observeClassifiedOperation(finalObservation);
12903
13037
  if (!observed) {
12904
13038
  sealOperation(callDigest, pending, true);
@@ -13045,6 +13179,7 @@ ${marker}` : marker;
13045
13179
  },
13046
13180
  readStatus,
13047
13181
  unavailableCause: () => firstUnavailableCause,
13182
+ seedDeferrals: currentSeedDeferrals,
13048
13183
  refreshReadback,
13049
13184
  observeReceipt: (input) => {
13050
13185
  ensureSynchronousRuntime();
@@ -13164,7 +13299,7 @@ function createOpencodeWorkflowGuard(options) {
13164
13299
  await runtime.refreshReadback();
13165
13300
  return {
13166
13301
  title: "Workflow guard status",
13167
- output: statusToolSchema.safeParse(input).success ? statusForTool(runtime.readStatus(), runtime.unavailableCause()) : unavailableToolResult()
13302
+ output: statusToolSchema.safeParse(input).success ? statusForTool(runtime.readStatus(), runtime.unavailableCause(), runtime.seedDeferrals()) : unavailableToolResult()
13168
13303
  };
13169
13304
  }),
13170
13305
  systematic_workflow_complete: makeWorkflowTool("Request completion of a guarded workflow unit or epoch.", completeToolShape, sessionRuntimeFor, (_runtime, input) => completeToolSchema.safeParse(input).success ? {
@@ -141,6 +141,12 @@ export interface WorkflowGuard {
141
141
  observeTrustedRecoveredOperation(input: unknown): Promise<EvidenceObservationResult>;
142
142
  observeReadback(input: unknown): ReadbackObservationResult;
143
143
  currentOperationContext(): CurrentOperationContext;
144
+ /**
145
+ * Read-only: whether the active unit already has a resource baseline for
146
+ * `operation` (declared on the unit, seeded, or propagated from PR
147
+ * creation). False when there is no active unit.
148
+ */
149
+ hasResourceBaseline(operation: ReceiptOperation): boolean;
144
150
  status(): WorkflowStatus;
145
151
  prepareTransition(input: unknown): TransitionPrepareResult;
146
152
  finalizeTransition(input: unknown): TransitionFinalizeResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fro.bot/systematic",
3
- "version": "3.21.6",
3
+ "version": "3.21.7",
4
4
  "description": "Compound-engineering loops for OpenCode, Pi, and Claude Code",
5
5
  "type": "module",
6
6
  "homepage": "https://fro.bot/systematic",