mancode 0.6.2 → 0.6.4

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.
@@ -1163,7 +1163,11 @@ function parseOperationJournal(value) {
1163
1163
  return journal;
1164
1164
  }
1165
1165
  function assertOperationJournalTransition(previous, next, options) {
1166
- assertJournalIdentityIsStable(previous, next);
1166
+ assertJournalIdentityIsStable(
1167
+ previous,
1168
+ next,
1169
+ options.reframeCheckpointReplacement
1170
+ );
1167
1171
  assertStepProgresses(previous.steps, next.steps);
1168
1172
  if (previous.state === next.state) return;
1169
1173
  if (!allowedOperationTransitions(previous.state).has(next.state)) {
@@ -1335,10 +1339,40 @@ function parseTimestamp2(value, label) {
1335
1339
  }
1336
1340
  return value;
1337
1341
  }
1338
- function assertJournalIdentityIsStable(previous, next) {
1339
- if (previous.operationId !== next.operationId || previous.type !== next.type || previous.primaryStoreId !== next.primaryStoreId || previous.checkoutId !== next.checkoutId || previous.actorId !== next.actorId || previous.sessionId !== next.sessionId || JSON.stringify(previous.authorizationBasis) !== JSON.stringify(next.authorizationBasis) || previous.recoveryPayloadDigest !== next.recoveryPayloadDigest || previous.startedAt !== next.startedAt || JSON.stringify(previous.secondaryReservations) !== JSON.stringify(next.secondaryReservations) || JSON.stringify(previous.entityLocks) !== JSON.stringify(next.entityLocks) || JSON.stringify(previous.expectedRevisions) !== JSON.stringify(next.expectedRevisions)) {
1342
+ function assertJournalIdentityIsStable(previous, next, replacement) {
1343
+ if (previous.operationId !== next.operationId || previous.type !== next.type || previous.primaryStoreId !== next.primaryStoreId || previous.checkoutId !== next.checkoutId || previous.actorId !== next.actorId || previous.sessionId !== next.sessionId || JSON.stringify(previous.authorizationBasis) !== JSON.stringify(next.authorizationBasis) || previous.startedAt !== next.startedAt || JSON.stringify(previous.secondaryReservations) !== JSON.stringify(next.secondaryReservations)) {
1340
1344
  throw new Error("operation journal identity fields are immutable");
1341
1345
  }
1346
+ if (replacement === void 0) {
1347
+ if (previous.recoveryPayloadDigest !== next.recoveryPayloadDigest || JSON.stringify(previous.entityLocks) !== JSON.stringify(next.entityLocks) || JSON.stringify(previous.expectedRevisions) !== JSON.stringify(next.expectedRevisions)) {
1348
+ throw new Error("operation journal identity fields are immutable");
1349
+ }
1350
+ return;
1351
+ }
1352
+ assertReframeCheckpointReplacement(previous, next, replacement);
1353
+ }
1354
+ function assertReframeCheckpointReplacement(previous, next, replacement) {
1355
+ assertUlid(replacement.fromCheckpointId, "reframe replacement checkpointId");
1356
+ assertUlid(replacement.toCheckpointId, "reframe replacement checkpointId");
1357
+ if (replacement.fromCheckpointId === replacement.toCheckpointId || previous.type !== "reframe" || next.type !== "reframe" || previous.state !== "repair_required" || next.state !== "repair_required" || previous.secondaryReservations.length !== 0 || previous.recoveryPayloadDigest === void 0 || next.recoveryPayloadDigest === void 0 || previous.recoveryPayloadDigest === next.recoveryPayloadDigest || JSON.stringify(previous.steps) !== JSON.stringify(next.steps)) {
1358
+ throw new Error("MANCODE_REFRAME_CHECKPOINT_REPLACEMENT_INVALID");
1359
+ }
1360
+ const fromKey = `checkpoint:${replacement.fromCheckpointId}`;
1361
+ const toKey = `checkpoint:${replacement.toCheckpointId}`;
1362
+ if (previous.entityLocks.filter((key) => key === fromKey).length !== 1 || previous.entityLocks.includes(toKey) || JSON.stringify(next.entityLocks) !== JSON.stringify(
1363
+ previous.entityLocks.map((key) => key === fromKey ? toKey : key)
1364
+ ) || previous.expectedRevisions[fromKey] !== 0 || previous.expectedRevisions[toKey] !== void 0) {
1365
+ throw new Error("MANCODE_REFRAME_CHECKPOINT_REPLACEMENT_INVALID");
1366
+ }
1367
+ const expectedRevisions = Object.fromEntries(
1368
+ Object.entries(previous.expectedRevisions).map(([key, revision]) => [
1369
+ key === fromKey ? toKey : key,
1370
+ revision
1371
+ ])
1372
+ );
1373
+ if (JSON.stringify(next.expectedRevisions) !== JSON.stringify(expectedRevisions)) {
1374
+ throw new Error("MANCODE_REFRAME_CHECKPOINT_REPLACEMENT_INVALID");
1375
+ }
1342
1376
  }
1343
1377
  function assertStepProgresses(previous, next) {
1344
1378
  if (previous.length !== next.length) {
@@ -1722,6 +1756,93 @@ function parseTimestamp4(value, label) {
1722
1756
  return value;
1723
1757
  }
1724
1758
 
1759
+ // src/context/man-delivery-evidence.ts
1760
+ var MAN_VERIFICATION_SURFACES = /* @__PURE__ */ new Set([
1761
+ "unit",
1762
+ "component",
1763
+ "handler",
1764
+ "real_http",
1765
+ "browser",
1766
+ "device",
1767
+ "external_service",
1768
+ "manual_observation"
1769
+ ]);
1770
+ function parseManEvidenceSubject(value) {
1771
+ assertRecord(value, "man evidence subject");
1772
+ assertKnownKeys(
1773
+ value,
1774
+ ["contentDigest", "environment"],
1775
+ "man evidence subject"
1776
+ );
1777
+ if (typeof value.contentDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value.contentDigest)) {
1778
+ throw new Error("MANCODE_MAN_EVIDENCE_SUBJECT_INVALID");
1779
+ }
1780
+ return {
1781
+ contentDigest: value.contentDigest,
1782
+ environment: text(value.environment)
1783
+ };
1784
+ }
1785
+ function parseManVerificationSurface(value) {
1786
+ if (typeof value !== "string" || !MAN_VERIFICATION_SURFACES.has(value))
1787
+ throw new Error("MANCODE_MAN_VERIFICATION_SURFACE_INVALID");
1788
+ return value;
1789
+ }
1790
+ function parseManReviewEvidence(value) {
1791
+ assertRecord(value, "man review evidence");
1792
+ assertKnownKeys(
1793
+ value,
1794
+ [
1795
+ "subject",
1796
+ "reviewer",
1797
+ "direction",
1798
+ "correctness",
1799
+ "proportionality",
1800
+ "nextAction",
1801
+ "coverage"
1802
+ ],
1803
+ "man review evidence"
1804
+ );
1805
+ if (value.reviewer !== "independent" && value.reviewer !== "self")
1806
+ throw new Error("MANCODE_MAN_REVIEWER_INVALID");
1807
+ if (!Array.isArray(value.coverage))
1808
+ throw new Error("MANCODE_MAN_REVIEW_COVERAGE_INVALID");
1809
+ const ids = /* @__PURE__ */ new Set();
1810
+ const coverage = value.coverage.map(
1811
+ (item) => {
1812
+ assertRecord(item, "man review coverage");
1813
+ assertKnownKeys(
1814
+ item,
1815
+ ["acceptanceId", "status", "evidence"],
1816
+ "man review coverage"
1817
+ );
1818
+ const acceptanceId = text(item.acceptanceId);
1819
+ if (ids.has(acceptanceId) || item.status !== "met" && item.status !== "missing" && item.status !== "unverified") {
1820
+ throw new Error("MANCODE_MAN_REVIEW_COVERAGE_INVALID");
1821
+ }
1822
+ ids.add(acceptanceId);
1823
+ return {
1824
+ acceptanceId,
1825
+ status: item.status,
1826
+ evidence: text(item.evidence)
1827
+ };
1828
+ }
1829
+ );
1830
+ return {
1831
+ subject: parseManEvidenceSubject(value.subject),
1832
+ reviewer: value.reviewer,
1833
+ direction: text(value.direction),
1834
+ correctness: text(value.correctness),
1835
+ proportionality: text(value.proportionality),
1836
+ nextAction: text(value.nextAction),
1837
+ coverage
1838
+ };
1839
+ }
1840
+ function text(value) {
1841
+ if (typeof value !== "string" || !value.trim())
1842
+ throw new Error("MANCODE_MAN_EVIDENCE_TEXT_REQUIRED");
1843
+ return value;
1844
+ }
1845
+
1725
1846
  // src/context/requirements-ledger.ts
1726
1847
  var REQUIREMENT_DIMENSIONS = [
1727
1848
  "platform",
@@ -2079,7 +2200,8 @@ function parseAcceptanceCriteria(value) {
2079
2200
  "requirementIds",
2080
2201
  "statement",
2081
2202
  "required",
2082
- "verificationRequirement"
2203
+ "verificationRequirement",
2204
+ "verificationSurfaces"
2083
2205
  ],
2084
2206
  "requirements ledger acceptance criterion"
2085
2207
  );
@@ -2094,6 +2216,11 @@ function parseAcceptanceCriteria(value) {
2094
2216
  "requirements ledger criterion verificationRequirement is invalid"
2095
2217
  );
2096
2218
  }
2219
+ const verificationRequirement = item.verificationRequirement;
2220
+ const verificationSurfaces = parseVerificationSurfaces(
2221
+ item.verificationSurfaces,
2222
+ verificationRequirement
2223
+ );
2097
2224
  return {
2098
2225
  ...identity,
2099
2226
  criterionId: item.criterionId,
@@ -2106,10 +2233,40 @@ function parseAcceptanceCriteria(value) {
2106
2233
  "requirements ledger criterion statement"
2107
2234
  ),
2108
2235
  required: item.required,
2109
- verificationRequirement: item.verificationRequirement
2236
+ verificationRequirement,
2237
+ ...verificationSurfaces === void 0 ? {} : { verificationSurfaces }
2110
2238
  };
2111
2239
  });
2112
2240
  }
2241
+ function assertManDeliveryVerificationSurfaces(ledger) {
2242
+ for (const criterion of ledger.acceptanceCriteria) {
2243
+ if (criterion.required && criterion.verificationSurfaces === void 0) {
2244
+ throw new Error(
2245
+ `MANCODE_MAN_ACCEPTANCE_SURFACE_REQUIRED: ${criterion.displayId}`
2246
+ );
2247
+ }
2248
+ }
2249
+ }
2250
+ function parseVerificationSurfaces(value, requirement) {
2251
+ if (value === void 0) return void 0;
2252
+ assertRecord(value, "requirements ledger acceptance verificationSurfaces");
2253
+ assertKnownKeys(
2254
+ value,
2255
+ ["automated", "manual"],
2256
+ "requirements ledger acceptance verificationSurfaces"
2257
+ );
2258
+ const automated = value.automated === void 0 ? void 0 : parseManVerificationSurface(value.automated);
2259
+ const manual = value.manual === void 0 ? void 0 : parseManVerificationSurface(value.manual);
2260
+ if (requirement === "automated" && (automated === void 0 || manual !== void 0) || requirement === "manual" && (automated !== void 0 || manual === void 0) || requirement === "hybrid" && (automated === void 0 || manual === void 0)) {
2261
+ throw new Error(
2262
+ "requirements ledger acceptance verificationSurfaces must match verificationRequirement slots"
2263
+ );
2264
+ }
2265
+ return {
2266
+ ...automated === void 0 ? {} : { automated },
2267
+ ...manual === void 0 ? {} : { manual }
2268
+ };
2269
+ }
2113
2270
  function parseBlockingUnknowns(value) {
2114
2271
  if (!Array.isArray(value)) {
2115
2272
  throw new Error("requirements ledger blockingUnknowns must be an array");
@@ -2342,7 +2499,8 @@ function parseReviewLedger(value) {
2342
2499
  "legacySource",
2343
2500
  "contentDigest",
2344
2501
  "lastOperationId",
2345
- "updatedAt"
2502
+ "updatedAt",
2503
+ "delivery"
2346
2504
  ],
2347
2505
  "review ledger"
2348
2506
  );
@@ -2357,6 +2515,7 @@ function parseReviewLedger(value) {
2357
2515
  }
2358
2516
  const taskRef = parseTaskRefValue(value.taskRef);
2359
2517
  const ledger = {
2518
+ ...value.delivery === void 0 ? {} : { delivery: parseManReviewEvidence(value.delivery) },
2360
2519
  schemaVersion: 1,
2361
2520
  canonicalizationVersion: "mancode-jcs-v1",
2362
2521
  taskRef,
@@ -2394,6 +2553,8 @@ function parseReviewLedger(value) {
2394
2553
  updatedAt: parseTimestamp6(value.updatedAt, "review ledger updatedAt")
2395
2554
  };
2396
2555
  assertReviewLedgerShape(ledger);
2556
+ if (taskRef.namespace === "shared" && ledger.delivery)
2557
+ assertSharedTextSafe(JSON.stringify(ledger.delivery), "man module review");
2397
2558
  if (ledger.contentDigest !== reviewLedgerDigest(ledger)) {
2398
2559
  throw new Error(
2399
2560
  "review ledger contentDigest does not match canonical content"
@@ -2404,6 +2565,7 @@ function parseReviewLedger(value) {
2404
2565
  }
2405
2566
  function reviewLedgerDigest(ledger) {
2406
2567
  return digestCanonicalJson({
2568
+ ...ledger.delivery === void 0 ? {} : { delivery: ledger.delivery },
2407
2569
  schemaVersion: ledger.schemaVersion,
2408
2570
  canonicalizationVersion: ledger.canonicalizationVersion,
2409
2571
  taskRef: ledger.taskRef,
@@ -3026,7 +3188,7 @@ function assertVerificationLedgerRequirements(ledger, requirements) {
3026
3188
  }
3027
3189
  }
3028
3190
  }
3029
- function assertVerificationLedgerTransition(previous, next) {
3191
+ function assertVerificationLedgerTransition(previous, next, contentInvalidated = false) {
3030
3192
  if (next.revision !== previous.revision + 1) {
3031
3193
  throw new Error(
3032
3194
  "verification ledger revision must increase exactly once per mutation"
@@ -3046,7 +3208,9 @@ function assertVerificationLedgerTransition(previous, next) {
3046
3208
  if (previous.legacySource === null && next.legacySource !== null) {
3047
3209
  throw new Error("verification ledger cannot introduce a legacy source");
3048
3210
  }
3049
- if (!allowedVerificationTransitions(previous.status).has(next.status)) {
3211
+ if (!allowedVerificationTransitions(
3212
+ contentInvalidated ? "stale" : previous.status
3213
+ ).has(next.status)) {
3050
3214
  throw new Error(
3051
3215
  `invalid verification ledger status transition: ${previous.status} -> ${next.status}`
3052
3216
  );
@@ -3168,6 +3332,8 @@ function parseEvidence(value, taskRef, kind) {
3168
3332
  "artifactRef",
3169
3333
  "confirmedByActorId",
3170
3334
  "confirmationSource",
3335
+ "subject",
3336
+ "surface",
3171
3337
  "updatedAt"
3172
3338
  ],
3173
3339
  `verification ledger ${kind} evidence`
@@ -3223,6 +3389,11 @@ function parseEvidence(value, taskRef, kind) {
3223
3389
  `verification ledger ${kind} evidence command`
3224
3390
  );
3225
3391
  if (taskRef.namespace === "shared") {
3392
+ if (value.subject !== void 0)
3393
+ assertSharedTextSafe(
3394
+ parseManEvidenceSubject(value.subject).environment,
3395
+ "man verification environment"
3396
+ );
3226
3397
  if (summary !== null) {
3227
3398
  assertSharedTextSafe(
3228
3399
  summary,
@@ -3238,6 +3409,8 @@ function parseEvidence(value, taskRef, kind) {
3238
3409
  }
3239
3410
  return {
3240
3411
  evidenceId: value.evidenceId,
3412
+ ...value.subject === void 0 ? {} : { subject: parseManEvidenceSubject(value.subject) },
3413
+ ...value.surface === void 0 ? {} : { surface: parseManVerificationSurface(value.surface) },
3241
3414
  status,
3242
3415
  summary,
3243
3416
  command,
@@ -3625,7 +3798,7 @@ function allowedTransitions(from) {
3625
3798
 
3626
3799
  // src/context/workflow-metadata.ts
3627
3800
  var SUPPORTED_WORKFLOW_POLICY_VERSIONS = {
3628
- planning: [1, 2],
3801
+ planning: [1, 2, 3],
3629
3802
  review: [1, 2],
3630
3803
  verification: [1]
3631
3804
  };
@@ -3848,6 +4021,9 @@ function assertWorkflowMetadataTransition(previous, next, operation) {
3848
4021
  "workflow metadata revision must increase exactly once per mutation"
3849
4022
  );
3850
4023
  }
4024
+ if ((previous.governance.policyVersions.planning === 3 || next.governance.policyVersions.planning === 3) && previous.governance.policyVersions.planning !== next.governance.policyVersions.planning) {
4025
+ throw new Error("MANCODE_MAN_DELIVERY_POLICY_IMMUTABLE");
4026
+ }
3851
4027
  if (previous.workflowMode !== next.workflowMode || previous.visibility !== next.visibility || previous.coordination !== next.coordination || previous.taskRef.namespace !== next.taskRef.namespace || previous.taskRef.taskId !== next.taskRef.taskId || JSON.stringify(previous.parent) !== JSON.stringify(next.parent)) {
3852
4028
  throw new Error(
3853
4029
  "workflow mode, dimensions, TaskRef, and parent are immutable"
@@ -4127,6 +4303,9 @@ function parseLegacyCompatibility(value) {
4127
4303
  };
4128
4304
  }
4129
4305
  function assertWorkflowMetadataShape(metadata) {
4306
+ if (metadata.governance.policyVersions.planning === 3 && metadata.workflowMode !== "man") {
4307
+ throw new Error("MANCODE_MAN_DELIVERY_MODE_REQUIRED");
4308
+ }
4130
4309
  if (metadata.workflowMode === "man") {
4131
4310
  if (metadata.coordination !== "single" || metadata.parent !== null) {
4132
4311
  throw new Error(
@@ -5947,15 +6126,6 @@ function serializeSchemaManifest(value) {
5947
6126
  function managedAdapterNames(inventory) {
5948
6127
  return MANAGED_ADAPTERS.filter((adapter) => inventory[adapter] !== void 0);
5949
6128
  }
5950
- function parseSchemaManifestV1(value) {
5951
- const manifest = parseSchemaManifest(value);
5952
- if (manifest.manifestVersion !== 1) {
5953
- throw new Error(
5954
- `MANCODE_MANIFEST_VERSION_UNSUPPORTED: observed=${manifest.manifestVersion} supported=1 requiredWriter=0.3.x`
5955
- );
5956
- }
5957
- return manifest;
5958
- }
5959
6129
  function parseSchemaManifestV2(value) {
5960
6130
  const manifest = parseSchemaManifest(value);
5961
6131
  if (manifest.manifestVersion !== 2) {
@@ -7234,7 +7404,6 @@ export {
7234
7404
  parseSchemaManifest,
7235
7405
  serializeSchemaManifest,
7236
7406
  managedAdapterNames,
7237
- parseSchemaManifestV1,
7238
7407
  parseSchemaManifestV2,
7239
7408
  assertSchemaManifestTransition,
7240
7409
  assertSchemaManifestPolicyUpgrade,
@@ -7280,11 +7449,14 @@ export {
7280
7449
  parseCheckpoint,
7281
7450
  parseCheckpointKind,
7282
7451
  checkpointDigest,
7452
+ parseManVerificationSurface,
7453
+ parseManReviewEvidence,
7283
7454
  parseRequirementsLedger,
7284
7455
  requirementsLedgerDigest,
7285
7456
  assertRequirementsLedgerTransition,
7286
7457
  requirementsAreReady,
7287
7458
  assertRequirementsScopeConsistent,
7459
+ assertManDeliveryVerificationSurfaces,
7288
7460
  parseArtifactRef,
7289
7461
  parseReviewLedger,
7290
7462
  reviewLedgerDigest,
@@ -7339,4 +7511,4 @@ export {
7339
7511
  V3ContextStore,
7340
7512
  storedTaskAggregateDigest
7341
7513
  };
7342
- //# sourceMappingURL=chunk-44UHUCE6.js.map
7514
+ //# sourceMappingURL=chunk-7HPP3KYG.js.map