@fro.bot/systematic 3.22.5 → 3.22.6
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 +36 -8
- package/dist/lib/workflow-guard.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9286,6 +9286,7 @@ function createWorkflowGuard(options) {
|
|
|
9286
9286
|
const runtimeRequired = normalizeOperations(options.runtimeRequiredOperations);
|
|
9287
9287
|
const runtimeScopes = normalizeResourceScopes2(options.runtimeResourceScopes);
|
|
9288
9288
|
let mode = options.mode ?? "protected";
|
|
9289
|
+
let declarationGeneration = 0;
|
|
9289
9290
|
let epoch;
|
|
9290
9291
|
let globalIssue;
|
|
9291
9292
|
const transitionsByCall = new Map;
|
|
@@ -9920,6 +9921,7 @@ function createWorkflowGuard(options) {
|
|
|
9920
9921
|
}
|
|
9921
9922
|
}
|
|
9922
9923
|
epoch.unit.status = "completed";
|
|
9924
|
+
declarationGeneration += 1;
|
|
9923
9925
|
return {
|
|
9924
9926
|
status: "completed",
|
|
9925
9927
|
target: lifecycle.target,
|
|
@@ -10118,6 +10120,7 @@ function createWorkflowGuard(options) {
|
|
|
10118
10120
|
if (!declarationChanged(unit, requiredOperations, resourceScopes)) {
|
|
10119
10121
|
return { status: "rejected", reasonCode: "unit-active" };
|
|
10120
10122
|
}
|
|
10123
|
+
declarationGeneration += 1;
|
|
10121
10124
|
unit.requiredOperations = requiredOperations;
|
|
10122
10125
|
unit.declaredResourceOperations = Object.freeze([...resourceScopes.keys()]);
|
|
10123
10126
|
unit.resourceScopes = resourceScopes;
|
|
@@ -10219,6 +10222,7 @@ function createWorkflowGuard(options) {
|
|
|
10219
10222
|
};
|
|
10220
10223
|
}
|
|
10221
10224
|
async function processOperation(input, parsed, unit, trustedClassification) {
|
|
10225
|
+
const generation = declarationGeneration;
|
|
10222
10226
|
if (!unit.requiredOperations.includes(parsed.operation)) {
|
|
10223
10227
|
markTerminalOperation(parsed, input);
|
|
10224
10228
|
return { status: "rejected", reasonCode: "operation-not-required" };
|
|
@@ -10237,28 +10241,45 @@ function createWorkflowGuard(options) {
|
|
|
10237
10241
|
if (prepared.status !== "prepared") {
|
|
10238
10242
|
return prepared.reasonCode === "call-context-conflict" ? { status: "rejected", reasonCode: "call-context-conflict" } : { status: "rejected", reasonCode: "rejected-operation" };
|
|
10239
10243
|
}
|
|
10240
|
-
const
|
|
10241
|
-
return
|
|
10244
|
+
const outcome = trustedClassification ? { kind: "classified", classification: trustedClassification } : await classifyPreparedOperation(parsed, input, unit, generation);
|
|
10245
|
+
return settleClassifiedOperation(parsed, input, unit, generation, outcome);
|
|
10246
|
+
}
|
|
10247
|
+
function settleClassifiedOperation(parsed, input, unit, generation, outcome) {
|
|
10248
|
+
if (outcome.kind === "stale" || generation !== declarationGeneration) {
|
|
10249
|
+
return supersedeOperation(parsed, input);
|
|
10250
|
+
}
|
|
10251
|
+
if (outcome.kind === "unclassified") {
|
|
10252
|
+
return { status: "rejected", reasonCode: "guard-unavailable" };
|
|
10253
|
+
}
|
|
10254
|
+
return finalizeOperation(parsed, input, unit, outcome.classification);
|
|
10255
|
+
}
|
|
10256
|
+
function supersedeOperation(parsed, input) {
|
|
10257
|
+
abandonPreparedOperation(parsed);
|
|
10258
|
+
markTerminalOperation(parsed, input);
|
|
10259
|
+
return { status: "rejected", reasonCode: "declaration-superseded" };
|
|
10242
10260
|
}
|
|
10243
10261
|
function rejectParsedOperation(parsed, input, unit, reasonCode) {
|
|
10244
10262
|
markTerminalOperation(parsed, input);
|
|
10245
10263
|
return recordUnitEvidenceIssue(unit, parsed.operation, reasonCode);
|
|
10246
10264
|
}
|
|
10247
|
-
async function classifyPreparedOperation(parsed, input, unit) {
|
|
10265
|
+
async function classifyPreparedOperation(parsed, input, unit, generation) {
|
|
10248
10266
|
const classifyOperation = options.classifier?.classifyOperation;
|
|
10249
10267
|
if (!classifyOperation) {
|
|
10250
10268
|
abandonPreparedOperation(parsed);
|
|
10251
10269
|
markTerminalOperation(parsed, input);
|
|
10252
10270
|
recordUnitEvidenceIssue(unit, parsed.operation, "guard-unavailable");
|
|
10253
|
-
return;
|
|
10271
|
+
return { kind: "unclassified" };
|
|
10254
10272
|
}
|
|
10255
10273
|
try {
|
|
10256
|
-
|
|
10274
|
+
const classification = await classifyOperation(input);
|
|
10275
|
+
return classification ? { kind: "classified", classification } : { kind: "unclassified" };
|
|
10257
10276
|
} catch {
|
|
10277
|
+
if (generation !== declarationGeneration)
|
|
10278
|
+
return { kind: "stale" };
|
|
10258
10279
|
abandonPreparedOperation(parsed);
|
|
10259
10280
|
markTerminalOperation(parsed, input);
|
|
10260
10281
|
recordUnitEvidenceIssue(unit, parsed.operation, "guard-unavailable");
|
|
10261
|
-
return;
|
|
10282
|
+
return { kind: "unclassified" };
|
|
10262
10283
|
}
|
|
10263
10284
|
}
|
|
10264
10285
|
function abandonPreparedOperation(parsed) {
|
|
@@ -10855,6 +10876,7 @@ function createWorkflowGuard(options) {
|
|
|
10855
10876
|
if (parsed.mode === mode)
|
|
10856
10877
|
return { status: "unchanged", mode };
|
|
10857
10878
|
mode = parsed.mode;
|
|
10879
|
+
declarationGeneration += 1;
|
|
10858
10880
|
for (const lifecycle of transitionsByCall.values()) {
|
|
10859
10881
|
if (lifecycle.state === "prepared")
|
|
10860
10882
|
lifecycle.state = "abandoned";
|
|
@@ -13358,7 +13380,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13358
13380
|
return;
|
|
13359
13381
|
}
|
|
13360
13382
|
function recordSeedDeferral(operation, reasonCode) {
|
|
13361
|
-
if (
|
|
13383
|
+
if (hasDeclaredResourceScope(operation))
|
|
13362
13384
|
return;
|
|
13363
13385
|
const observer = options.observer;
|
|
13364
13386
|
if (!observer)
|
|
@@ -13370,6 +13392,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13370
13392
|
targetIdentity: observer.targetDigest
|
|
13371
13393
|
});
|
|
13372
13394
|
}
|
|
13395
|
+
function hasDeclaredResourceScope(operation) {
|
|
13396
|
+
const unit = requireGuard().status().unit;
|
|
13397
|
+
return unit?.requiredResourceOperations.includes(operation) ?? false;
|
|
13398
|
+
}
|
|
13373
13399
|
function seedDeferralEntries(reset = false) {
|
|
13374
13400
|
const unitId = requireGuard().status().unit?.unitId;
|
|
13375
13401
|
if (!unitId)
|
|
@@ -13398,7 +13424,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13398
13424
|
if (!deferred)
|
|
13399
13425
|
return;
|
|
13400
13426
|
if (requireGuard().hasResourceBaseline(operation)) {
|
|
13401
|
-
|
|
13427
|
+
if (before?.status === "available" && sameSeedObserver(deferred, observer)) {
|
|
13428
|
+
clearSeedDeferral(operation);
|
|
13429
|
+
}
|
|
13402
13430
|
return;
|
|
13403
13431
|
}
|
|
13404
13432
|
if (!before || !sameSeedObserver(deferred, observer))
|
|
@@ -6,7 +6,7 @@ export type WorkflowState = 'protected' | 'waiting' | 'rejected' | 'disabled' |
|
|
|
6
6
|
export type RepairKind = 'fresh-readback' | 'rerun-operation' | 'question-attestation';
|
|
7
7
|
export type TransitionTarget = 'unit' | 'epoch';
|
|
8
8
|
export type EpochFamily = 'work' | 'shipping';
|
|
9
|
-
export type WorkflowReasonCode = 'abandoned-transition' | 'call-context-conflict' | 'cancelled-operation' | 'consumed-receipt' | 'disabled' | 'epoch-completed' | 'epoch-mismatch' | 'failed-operation' | 'family-conflict' | 'finalization-failed' | 'foreign-registration' | 'forbidden-field' | 'guard-unavailable' | 'incompatible-receipt' | 'invalid-configuration' | 'invalid-control' | 'invalid-receipt' | 'invalid-transition' | 'missing-evidence' | 'no-supported-repair' | 'no-active-epoch' | 'no-active-unit' | 'no-op-operation' | 'operation-not-required' | 'operation-target-mismatch' | 'readback-timeout' | 'receipt-mismatch' | 'rejected-operation' | 'resource-mismatch' | 'running-operation' | 'snapshot-blocked' | 'stale-receipt' | 'transition-finalized' | 'transition-terminal' | 'transition-replayed' | 'unattributed-operation' | 'unit-active' | 'unit-completed' | 'unit-incomplete' | 'unit-mismatch' | 'unit-ready' | 'workspace-mismatch' | 'runtime-scope-conflict' | 'invalid-recovery' | 'recovery-conflict' | 'fork-copy-not-lineage';
|
|
9
|
+
export type WorkflowReasonCode = 'abandoned-transition' | 'call-context-conflict' | 'cancelled-operation' | 'consumed-receipt' | 'declaration-superseded' | 'disabled' | 'epoch-completed' | 'epoch-mismatch' | 'failed-operation' | 'family-conflict' | 'finalization-failed' | 'foreign-registration' | 'forbidden-field' | 'guard-unavailable' | 'incompatible-receipt' | 'invalid-configuration' | 'invalid-control' | 'invalid-receipt' | 'invalid-transition' | 'missing-evidence' | 'no-supported-repair' | 'no-active-epoch' | 'no-active-unit' | 'no-op-operation' | 'operation-not-required' | 'operation-target-mismatch' | 'readback-timeout' | 'receipt-mismatch' | 'rejected-operation' | 'resource-mismatch' | 'running-operation' | 'snapshot-blocked' | 'stale-receipt' | 'transition-finalized' | 'transition-terminal' | 'transition-replayed' | 'unattributed-operation' | 'unit-active' | 'unit-completed' | 'unit-incomplete' | 'unit-mismatch' | 'unit-ready' | 'workspace-mismatch' | 'runtime-scope-conflict' | 'invalid-recovery' | 'recovery-conflict' | 'fork-copy-not-lineage';
|
|
10
10
|
export interface WorkflowGuardOptions {
|
|
11
11
|
ledger: ReceiptLedger;
|
|
12
12
|
classifier?: ReceiptClassifier;
|