mancode 0.3.18 → 0.4.1

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.
@@ -592,6 +592,7 @@ var AUTHORIZATION_ACTIONS = /* @__PURE__ */ new Set([
592
592
  "handoff_offer_cancel",
593
593
  "handoff_accept_reject",
594
594
  "review_skip_or_waiver",
595
+ "project_maintenance",
595
596
  "team_policy_config_transport",
596
597
  "actor_profile_publish",
597
598
  "confirmed_decision_publish"
@@ -601,7 +602,7 @@ function evaluateAuthorization(input) {
601
602
  validateRequest(input);
602
603
  const failures = [];
603
604
  requireActiveSession(input, failures);
604
- if (input.action !== "local_workflow_mutation") {
605
+ if (input.action !== "local_workflow_mutation" && input.action !== "project_maintenance") {
605
606
  if (input.action !== "actor_profile_publish" && !input.joined) {
606
607
  failures.push("MANCODE_JOIN_REQUIRED");
607
608
  }
@@ -750,6 +751,15 @@ function evaluateAuthorization(input) {
750
751
  failures.push("MANCODE_WAIVER_FORBIDDEN");
751
752
  }
752
753
  break;
754
+ case "project_maintenance":
755
+ requireExpectedRevision(input, failures);
756
+ requireCondition(
757
+ input,
758
+ "explicitConfirmation",
759
+ "MANCODE_EXPLICIT_CONFIRMATION_REQUIRED",
760
+ failures
761
+ );
762
+ break;
753
763
  case "team_policy_config_transport":
754
764
  requireExpectedRevision(input, failures);
755
765
  requireCondition(
@@ -1043,6 +1053,7 @@ function authorizationDecisionProjection(input) {
1043
1053
  var OPERATION_TYPES = /* @__PURE__ */ new Set([
1044
1054
  "workflow_create",
1045
1055
  "workflow_update",
1056
+ "requirements_draft",
1046
1057
  "requirements_finalize",
1047
1058
  "plan_revision",
1048
1059
  "review_remediation",
@@ -1059,10 +1070,13 @@ var OPERATION_TYPES = /* @__PURE__ */ new Set([
1059
1070
  "claim_revalidation",
1060
1071
  "checkpoint_create",
1061
1072
  "solo_handoff",
1073
+ "reframe",
1062
1074
  "child_result_merge",
1063
1075
  "task_head_reconcile",
1064
1076
  "transport_migrate",
1065
1077
  "greenfield_initialize",
1078
+ "adapter_upgrade",
1079
+ "project_policy_upgrade",
1066
1080
  "v3_activate"
1067
1081
  ]);
1068
1082
  var OPERATION_STATES = /* @__PURE__ */ new Set([
@@ -1369,7 +1383,7 @@ function allowedOperationTransitions(from) {
1369
1383
  case "applying":
1370
1384
  return /* @__PURE__ */ new Set(["committed", "repair_required", "aborted"]);
1371
1385
  case "repair_required":
1372
- return /* @__PURE__ */ new Set(["committed"]);
1386
+ return /* @__PURE__ */ new Set(["committed", "aborted"]);
1373
1387
  case "committed":
1374
1388
  case "aborted":
1375
1389
  return /* @__PURE__ */ new Set();
@@ -1553,6 +1567,7 @@ function isNotFound2(error) {
1553
1567
  var CHECKPOINT_KINDS = /* @__PURE__ */ new Set([
1554
1568
  "plan_confirmed",
1555
1569
  "scope_changed",
1570
+ "requirements_reframed",
1556
1571
  "diagnostic_started",
1557
1572
  "base_changed",
1558
1573
  "verification_completed",
@@ -3601,6 +3616,28 @@ function allowedTransitions(from) {
3601
3616
  }
3602
3617
 
3603
3618
  // src/context/workflow-metadata.ts
3619
+ var SUPPORTED_WORKFLOW_POLICY_VERSIONS = {
3620
+ planning: [1, 2],
3621
+ review: [1, 2],
3622
+ verification: [1]
3623
+ };
3624
+ var WorkflowPolicyVersionUnsupportedError = class extends Error {
3625
+ constructor(component, observedVersion, supportedVersions, requiredWriter) {
3626
+ super(
3627
+ `MANCODE_POLICY_VERSION_UNSUPPORTED: component=${component} observed=${String(observedVersion)} supported=${supportedVersions.join(",")} requiredWriter=${requiredWriter}`
3628
+ );
3629
+ this.component = component;
3630
+ this.observedVersion = observedVersion;
3631
+ this.supportedVersions = supportedVersions;
3632
+ this.requiredWriter = requiredWriter;
3633
+ this.name = "WorkflowPolicyVersionUnsupportedError";
3634
+ }
3635
+ component;
3636
+ observedVersion;
3637
+ supportedVersions;
3638
+ requiredWriter;
3639
+ code = "MANCODE_POLICY_VERSION_UNSUPPORTED";
3640
+ };
3604
3641
  var TRANSITION_STATES = /* @__PURE__ */ new Set([
3605
3642
  "stable",
3606
3643
  "operation_pending",
@@ -3991,20 +4028,24 @@ function parsePolicyVersions(value) {
3991
4028
  "workflow metadata policyVersions"
3992
4029
  );
3993
4030
  return {
3994
- planning: parsePositiveIntegerOrNull2(
3995
- value.planning,
3996
- "workflow metadata planning policy version"
3997
- ),
3998
- review: parsePositiveIntegerOrNull2(
3999
- value.review,
4000
- "workflow metadata review policy version"
4001
- ),
4002
- verification: parsePositiveIntegerOrNull2(
4003
- value.verification,
4004
- "workflow metadata verification policy version"
4005
- )
4031
+ planning: parsePolicyVersionOrNull(value.planning, "planning"),
4032
+ review: parsePolicyVersionOrNull(value.review, "review"),
4033
+ verification: parsePolicyVersionOrNull(value.verification, "verification")
4006
4034
  };
4007
4035
  }
4036
+ function parsePolicyVersionOrNull(value, component) {
4037
+ if (value === null) return null;
4038
+ const supported = SUPPORTED_WORKFLOW_POLICY_VERSIONS[component];
4039
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || !supported.some((version) => version === value)) {
4040
+ throw new WorkflowPolicyVersionUnsupportedError(
4041
+ component,
4042
+ value,
4043
+ supported,
4044
+ component === "planning" && value === 2 ? "0.4.0" : ">0.4.0"
4045
+ );
4046
+ }
4047
+ return value;
4048
+ }
4008
4049
  function parsePlanDecision(value) {
4009
4050
  if (value === null) return null;
4010
4051
  if (typeof value !== "string" || !PLAN_DECISIONS.has(value)) {
@@ -4194,9 +4235,6 @@ function parsePositiveInteger7(value, label) {
4194
4235
  }
4195
4236
  return value;
4196
4237
  }
4197
- function parsePositiveIntegerOrNull2(value, label) {
4198
- return value === null ? null : parsePositiveInteger7(value, label);
4199
- }
4200
4238
  function parseNonNegativeInteger4(value, label) {
4201
4239
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
4202
4240
  throw new Error(`${label} must be a non-negative integer`);
@@ -5827,6 +5865,12 @@ var VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
5827
5865
  var DIGEST_PATTERN13 = /^sha256:[a-f0-9]{64}$/;
5828
5866
  function parseSchemaManifest(value) {
5829
5867
  assertRecord(value, "schema manifest");
5868
+ if (value.manifestVersion !== 1 && value.manifestVersion !== 2) {
5869
+ throw new Error(
5870
+ `MANCODE_MANIFEST_VERSION_UNSUPPORTED: observed=${String(value.manifestVersion)} supported=1,2 requiredWriter=0.4.0`
5871
+ );
5872
+ }
5873
+ const manifestVersion = value.manifestVersion;
5830
5874
  assertKnownKeys(
5831
5875
  value,
5832
5876
  [
@@ -5839,21 +5883,19 @@ function parseSchemaManifest(value) {
5839
5883
  "activatedAt",
5840
5884
  "legacyBaseline",
5841
5885
  "managedAdapters",
5842
- "lastOperationId"
5886
+ "lastOperationId",
5887
+ ...manifestVersion === 2 ? ["workflowPolicyDefaults"] : []
5843
5888
  ],
5844
5889
  "schema manifest"
5845
5890
  );
5846
- if (value.manifestVersion !== 1 || value.layoutVersion !== 3) {
5847
- throw new Error(
5848
- "schema manifest must use manifestVersion 1 and layoutVersion 3"
5849
- );
5891
+ if (value.layoutVersion !== 3) {
5892
+ throw new Error("schema manifest must use layoutVersion 3");
5850
5893
  }
5851
5894
  assertUlid(value.epoch, "schema manifest epoch");
5852
5895
  if (typeof value.activationState !== "string" || !ACTIVATION_STATES.has(value.activationState)) {
5853
5896
  throw new Error("schema manifest activationState is invalid");
5854
5897
  }
5855
- const manifest = {
5856
- manifestVersion: 1,
5898
+ const common = {
5857
5899
  layoutVersion: 3,
5858
5900
  epoch: value.epoch,
5859
5901
  activationState: value.activationState,
@@ -5864,11 +5906,48 @@ function parseSchemaManifest(value) {
5864
5906
  managedAdapters: parseManagedAdapters(value.managedAdapters),
5865
5907
  lastOperationId: parseUlidOrNull9(value.lastOperationId, "lastOperationId")
5866
5908
  };
5909
+ const manifest = manifestVersion === 1 ? { manifestVersion: 1, ...common } : {
5910
+ manifestVersion: 2,
5911
+ ...common,
5912
+ workflowPolicyDefaults: parseWorkflowPolicyDefaults(
5913
+ value.workflowPolicyDefaults
5914
+ )
5915
+ };
5867
5916
  assertManifestStateShape(manifest);
5917
+ if (manifest.manifestVersion === 2 && (compareVersions(manifest.minReaderVersion, "0.4.0") < 0 || compareVersions(manifest.minWriterVersion, "0.4.0") < 0)) {
5918
+ throw new Error(
5919
+ "schema manifest V2 requires minReaderVersion and minWriterVersion 0.4.0 or newer"
5920
+ );
5921
+ }
5922
+ return manifest;
5923
+ }
5924
+ function serializeSchemaManifest(value) {
5925
+ return `${JSON.stringify(parseSchemaManifest(value), null, 2)}
5926
+ `;
5927
+ }
5928
+ function managedAdapterNames(inventory) {
5929
+ return MANAGED_ADAPTERS.filter((adapter) => inventory[adapter] !== void 0);
5930
+ }
5931
+ function parseSchemaManifestV1(value) {
5932
+ const manifest = parseSchemaManifest(value);
5933
+ if (manifest.manifestVersion !== 1) {
5934
+ throw new Error(
5935
+ `MANCODE_MANIFEST_VERSION_UNSUPPORTED: observed=${manifest.manifestVersion} supported=1 requiredWriter=0.3.x`
5936
+ );
5937
+ }
5938
+ return manifest;
5939
+ }
5940
+ function parseSchemaManifestV2(value) {
5941
+ const manifest = parseSchemaManifest(value);
5942
+ if (manifest.manifestVersion !== 2) {
5943
+ throw new Error(
5944
+ `MANCODE_MANIFEST_VERSION_UNSUPPORTED: observed=${manifest.manifestVersion} supported=2 requiredWriter=0.4.0`
5945
+ );
5946
+ }
5868
5947
  return manifest;
5869
5948
  }
5870
5949
  function assertSchemaManifestTransition(previous, next) {
5871
- if (previous.manifestVersion !== next.manifestVersion || previous.layoutVersion !== next.layoutVersion || previous.epoch !== next.epoch || !sameLegacyBaseline(previous.legacyBaseline, next.legacyBaseline)) {
5950
+ if (previous.manifestVersion !== next.manifestVersion || previous.layoutVersion !== next.layoutVersion || previous.epoch !== next.epoch || !sameLegacyBaseline(previous.legacyBaseline, next.legacyBaseline) || compareVersions(next.minReaderVersion, previous.minReaderVersion) < 0 || compareVersions(next.minWriterVersion, previous.minWriterVersion) < 0) {
5872
5951
  throw new Error(
5873
5952
  "schema manifest identity and legacy baseline are immutable"
5874
5953
  );
@@ -5882,11 +5961,33 @@ function assertSchemaManifestTransition(previous, next) {
5882
5961
  );
5883
5962
  }
5884
5963
  }
5964
+ function assertSchemaManifestPolicyUpgrade(previous, next) {
5965
+ if (previous.manifestVersion !== 1 || next.manifestVersion !== 2 || previous.layoutVersion !== next.layoutVersion || previous.epoch !== next.epoch || previous.activationState !== "v3_active" || next.activationState !== "v3_active" || previous.activatedAt !== next.activatedAt || !sameLegacyBaseline(previous.legacyBaseline, next.legacyBaseline) || !managedAdapterInventoriesMatch(
5966
+ previous.managedAdapters,
5967
+ next.managedAdapters
5968
+ ) || compareVersions(next.minReaderVersion, previous.minReaderVersion) < 0 || compareVersions(next.minWriterVersion, previous.minWriterVersion) < 0 || next.workflowPolicyDefaults.planning !== 2 || next.lastOperationId === null || next.lastOperationId === previous.lastOperationId) {
5969
+ throw new Error("invalid schema manifest Policy 2 upgrade");
5970
+ }
5971
+ }
5885
5972
  function assertActivationRollbackManifestTransition(previous, next) {
5886
5973
  if (previous.manifestVersion !== next.manifestVersion || previous.layoutVersion !== next.layoutVersion || previous.epoch !== next.epoch || !sameLegacyBaseline(previous.legacyBaseline, next.legacyBaseline) || previous.activationState !== "v3_active" || next.activationState !== "dual_read" || previous.activatedAt === null || next.activatedAt !== null) {
5887
5974
  throw new Error("invalid activation rollback manifest transition");
5888
5975
  }
5889
5976
  }
5977
+ function parseWorkflowPolicyDefaults(value) {
5978
+ assertRecord(value, "schema manifest workflowPolicyDefaults");
5979
+ assertKnownKeys(
5980
+ value,
5981
+ ["planning"],
5982
+ "schema manifest workflowPolicyDefaults"
5983
+ );
5984
+ if (value.planning !== 2) {
5985
+ throw new Error(
5986
+ `MANCODE_POLICY_VERSION_UNSUPPORTED: component=planning observed=${String(value.planning)} supported=2 requiredWriter=0.4.0`
5987
+ );
5988
+ }
5989
+ return { planning: 2 };
5990
+ }
5890
5991
  function parseVersion(value, label) {
5891
5992
  if (typeof value !== "string" || !VERSION_PATTERN.test(value)) {
5892
5993
  throw new Error(`schema manifest ${label} must be a semantic version`);
@@ -5925,10 +6026,14 @@ function parseManagedAdapters(value) {
5925
6026
  assertKnownKeys(value, MANAGED_ADAPTERS, "schema manifest managedAdapters");
5926
6027
  const adapters = {};
5927
6028
  for (const adapter of MANAGED_ADAPTERS) {
5928
- if (typeof value[adapter] !== "string" || !value[adapter].trim()) {
5929
- throw new Error(`schema manifest managedAdapters.${adapter} is required`);
6029
+ const version = value[adapter];
6030
+ if (version === void 0) continue;
6031
+ if (typeof version !== "string" || !version.trim()) {
6032
+ throw new Error(
6033
+ `schema manifest managedAdapters.${adapter} must be a non-empty version`
6034
+ );
5930
6035
  }
5931
- adapters[adapter] = value[adapter];
6036
+ adapters[adapter] = version;
5932
6037
  }
5933
6038
  return adapters;
5934
6039
  }
@@ -5957,6 +6062,46 @@ function assertManifestStateShape(manifest) {
5957
6062
  );
5958
6063
  }
5959
6064
  }
6065
+ function managedAdapterInventoriesMatch(left, right) {
6066
+ const leftKeys = managedAdapterNames(left);
6067
+ const rightKeys = managedAdapterNames(right);
6068
+ return leftKeys.length === rightKeys.length && leftKeys.every(
6069
+ (adapter, index) => adapter === rightKeys[index] && left[adapter] === right[adapter]
6070
+ );
6071
+ }
6072
+ function compareVersions(left, right) {
6073
+ const [leftCore = "", leftPrerelease] = left.split("-", 2);
6074
+ const [rightCore = "", rightPrerelease] = right.split("-", 2);
6075
+ const leftParts = leftCore.split(".").map(Number);
6076
+ const rightParts = rightCore.split(".").map(Number);
6077
+ for (let index = 0; index < 3; index += 1) {
6078
+ const delta = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);
6079
+ if (delta !== 0) return delta;
6080
+ }
6081
+ if (leftPrerelease === rightPrerelease) return 0;
6082
+ if (leftPrerelease === void 0) return 1;
6083
+ if (rightPrerelease === void 0) return -1;
6084
+ return comparePrerelease(leftPrerelease, rightPrerelease);
6085
+ }
6086
+ function comparePrerelease(left, right) {
6087
+ const leftParts = left.split(".");
6088
+ const rightParts = right.split(".");
6089
+ for (let index = 0; index < Math.max(leftParts.length, rightParts.length); index += 1) {
6090
+ const leftPart = leftParts[index];
6091
+ const rightPart = rightParts[index];
6092
+ if (leftPart === void 0) return -1;
6093
+ if (rightPart === void 0) return 1;
6094
+ if (leftPart === rightPart) continue;
6095
+ const leftNumeric = /^\d+$/.test(leftPart);
6096
+ const rightNumeric = /^\d+$/.test(rightPart);
6097
+ if (leftNumeric && rightNumeric)
6098
+ return Number(leftPart) - Number(rightPart);
6099
+ if (leftNumeric) return -1;
6100
+ if (rightNumeric) return 1;
6101
+ return leftPart.localeCompare(rightPart, "en");
6102
+ }
6103
+ return 0;
6104
+ }
5960
6105
  function sameLegacyBaseline(left, right) {
5961
6106
  return left === right || left !== null && right !== null && left.stateDigest === right.stateDigest && left.workflowIndexDigest === right.workflowIndexDigest;
5962
6107
  }
@@ -7020,10 +7165,20 @@ function storedTaskAggregateDigest(snapshot) {
7020
7165
  }
7021
7166
 
7022
7167
  export {
7168
+ isUlid,
7023
7169
  assertUlid,
7024
7170
  createUlid,
7025
7171
  assertRecord,
7026
7172
  assertKnownKeys,
7173
+ parseSchemaManifest,
7174
+ serializeSchemaManifest,
7175
+ managedAdapterNames,
7176
+ parseSchemaManifestV1,
7177
+ parseSchemaManifestV2,
7178
+ assertSchemaManifestTransition,
7179
+ assertSchemaManifestPolicyUpgrade,
7180
+ assertActivationRollbackManifestTransition,
7181
+ managedAdapterInventoriesMatch,
7027
7182
  formatTaskRef,
7028
7183
  parseTaskRef,
7029
7184
  parseTaskRefValue,
@@ -7036,6 +7191,9 @@ export {
7036
7191
  claimDirectory,
7037
7192
  handoffDirectory,
7038
7193
  taskHeadDirectory,
7194
+ gitRefWorkflowRepairJournalPath,
7195
+ listGitRefWorkflowRepairJournalSummaries,
7196
+ listUnfinishedGitRefWorkflowRepairs,
7039
7197
  canonicalizeJson,
7040
7198
  digestCanonicalJson,
7041
7199
  sortUtf8StringSet,
@@ -7053,9 +7211,14 @@ export {
7053
7211
  operationReservationJournalDigest,
7054
7212
  assertOperationReservationTopology,
7055
7213
  withOperationReservationDigests,
7056
- parseSchemaManifest,
7057
- assertSchemaManifestTransition,
7058
- assertActivationRollbackManifestTransition,
7214
+ parseOperationReservation,
7215
+ createOperationReservation,
7216
+ writeOperationReservation,
7217
+ readOperationReservation,
7218
+ removeOperationReservation,
7219
+ parseCheckpoint,
7220
+ parseCheckpointKind,
7221
+ checkpointDigest,
7059
7222
  parseRequirementsLedger,
7060
7223
  requirementsLedgerDigest,
7061
7224
  assertRequirementsLedgerTransition,
@@ -7079,9 +7242,13 @@ export {
7079
7242
  workflowMetadataDigest,
7080
7243
  assertWorkflowMetadataTransition,
7081
7244
  assertParentWorkflowRelation,
7082
- parseCheckpoint,
7083
- parseCheckpointKind,
7084
- checkpointDigest,
7245
+ buildTaskAggregateManifest,
7246
+ taskAggregateDigest,
7247
+ parseTaskAggregateManifest,
7248
+ assertTaskCompletionGate,
7249
+ parseTaskHeadFence,
7250
+ assertTaskHeadFenceMatchesAggregate,
7251
+ assertTaskHeadFenceTransition,
7085
7252
  parseClaim,
7086
7253
  assertClaimTransition,
7087
7254
  normalizeClaimScope,
@@ -7094,21 +7261,6 @@ export {
7094
7261
  assertConfigPolicyConsistency,
7095
7262
  assertProjectConfigTransition,
7096
7263
  assertTeamPolicyTransition,
7097
- buildTaskAggregateManifest,
7098
- taskAggregateDigest,
7099
- parseTaskAggregateManifest,
7100
- assertTaskCompletionGate,
7101
- parseTaskHeadFence,
7102
- assertTaskHeadFenceMatchesAggregate,
7103
- assertTaskHeadFenceTransition,
7104
- parseOperationReservation,
7105
- createOperationReservation,
7106
- writeOperationReservation,
7107
- readOperationReservation,
7108
- removeOperationReservation,
7109
- gitRefWorkflowRepairJournalPath,
7110
- listGitRefWorkflowRepairJournalSummaries,
7111
- listUnfinishedGitRefWorkflowRepairs,
7112
7264
  createConfirmedDecision,
7113
7265
  publishConfirmedDecision,
7114
7266
  readConfirmedDecision,
@@ -7123,4 +7275,4 @@ export {
7123
7275
  V3ContextStore,
7124
7276
  storedTaskAggregateDigest
7125
7277
  };
7126
- //# sourceMappingURL=chunk-LMXUPBCN.js.map
7278
+ //# sourceMappingURL=chunk-S3BAOJPP.js.map