arkgate 4.8.24 → 4.8.25

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 (166) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +2 -2
  3. package/bin/ark-check-runtime.mjs +17 -14
  4. package/bin/ark-layer-match.mjs +115 -13
  5. package/bin/ark-mcp-runtime.mjs +36 -31
  6. package/bin/ark-shared.mjs +4 -23
  7. package/bin/lib/adoption-stance.mjs +2 -2
  8. package/bin/lib/adr-path.mjs +3 -3
  9. package/bin/lib/agent-gates.mjs +0 -61
  10. package/bin/lib/agent-homes.mjs +12 -21
  11. package/bin/lib/agent-projection-command.mjs +4 -4
  12. package/bin/lib/ambient-state.mjs +9 -30
  13. package/bin/lib/analysis-engine.mjs +14 -14
  14. package/bin/lib/architecture-scan.mjs +11 -9
  15. package/bin/lib/ark-order-doctor.mjs +3 -28
  16. package/bin/lib/ark-order-facts.mjs +6 -99
  17. package/bin/lib/ark-order-types.mjs +1 -2
  18. package/bin/lib/ark-run-doctor.mjs +3 -28
  19. package/bin/lib/ark-run-facts.mjs +30 -40
  20. package/bin/lib/ark-run-sensors.mjs +1 -1
  21. package/bin/lib/arkrule-file-hints.mjs +2 -47
  22. package/bin/lib/arkrules-contract.mjs +124 -133
  23. package/bin/lib/arkrules-sensors.mjs +7 -5
  24. package/bin/lib/check-args.mjs +63 -1
  25. package/bin/lib/ci-and-commands.mjs +8 -72
  26. package/bin/lib/ci-merge-boundary.mjs +1 -1
  27. package/bin/lib/class-source-scan.mjs +5 -5
  28. package/bin/lib/clone-detection.mjs +474 -0
  29. package/bin/lib/codex-home.mjs +1 -1
  30. package/bin/lib/config-contract-slices.mjs +44 -6
  31. package/bin/lib/config-contract.mjs +40 -117
  32. package/bin/lib/config-extras.mjs +16 -22
  33. package/bin/lib/contract-smells.mjs +33 -15
  34. package/bin/lib/core-ratchet.mjs +0 -2
  35. package/bin/lib/dashboard-cli.mjs +2 -2
  36. package/bin/lib/deep-module-coach.mjs +2 -4
  37. package/bin/lib/deploy-path.mjs +13 -38
  38. package/bin/lib/design-smells.mjs +2 -2
  39. package/bin/lib/diagnostic-catalog.mjs +8 -1
  40. package/bin/lib/doctor-advisories.mjs +55 -9
  41. package/bin/lib/doctor-green-cite.mjs +1 -1
  42. package/bin/lib/doctor-human.mjs +1 -1
  43. package/bin/lib/doctor-next-actions.mjs +2 -2
  44. package/bin/lib/doctor-plan.mjs +4 -6
  45. package/bin/lib/duplication-io.mjs +572 -0
  46. package/bin/lib/effective-contract-load.mjs +181 -44
  47. package/bin/lib/entry-points-io.mjs +424 -0
  48. package/bin/lib/extra-merge-teeth.mjs +36 -0
  49. package/bin/lib/field-install.mjs +38 -14
  50. package/bin/lib/first-run-help.mjs +7 -3
  51. package/bin/lib/flat-parent-importers.mjs +5 -3
  52. package/bin/lib/gate-files.mjs +30 -89
  53. package/bin/lib/github-enforcement.mjs +165 -28
  54. package/bin/lib/golden-pattern.mjs +1 -1
  55. package/bin/lib/hook-templates.mjs +16 -16
  56. package/bin/lib/html-report-advisories.mjs +4 -0
  57. package/bin/lib/html-report-depth.mjs +2 -2
  58. package/bin/lib/html-report.mjs +2 -2
  59. package/bin/lib/import-graph-projection.mjs +112 -0
  60. package/bin/lib/improvement-compass-doctor.mjs +1 -24
  61. package/bin/lib/invariant-coverage-io.mjs +4 -3
  62. package/bin/lib/invariant-coverage.mjs +26 -0
  63. package/bin/lib/invariant-probe-cli.mjs +347 -0
  64. package/bin/lib/invariant-probe-io.mjs +165 -0
  65. package/bin/lib/invariant-probe-runner.mjs +268 -0
  66. package/bin/lib/invariant-probe-sites.mjs +174 -0
  67. package/bin/lib/invariant-probe-workspace.mjs +183 -0
  68. package/bin/lib/invariant-probe.mjs +461 -0
  69. package/bin/lib/invariant-tests-path.mjs +16 -22
  70. package/bin/lib/literal-path-drift.mjs +4 -2
  71. package/bin/lib/managed-upgrade.mjs +2 -8
  72. package/bin/lib/mcp-adoption.mjs +4 -5
  73. package/bin/lib/mcp-hook-payload.mjs +4 -4
  74. package/bin/lib/orphan-modules-io.mjs +458 -0
  75. package/bin/lib/orphan-modules.mjs +251 -0
  76. package/bin/lib/outside-importers.mjs +197 -0
  77. package/bin/lib/package-manager.mjs +3 -3
  78. package/bin/lib/parse-health.mjs +1 -1
  79. package/bin/lib/persistence-write-hint.mjs +33 -8
  80. package/bin/lib/pin-dependent-gates.mjs +2 -2
  81. package/bin/lib/policy-delta-io.mjs +55 -8
  82. package/bin/lib/post-green-path.mjs +1 -1
  83. package/bin/lib/prepare-change.mjs +3 -9
  84. package/bin/lib/prepare-write.mjs +1 -2
  85. package/bin/lib/presets.mjs +56 -68
  86. package/bin/lib/product-copy.mjs +1 -6
  87. package/bin/lib/project-root.mjs +31 -62
  88. package/bin/lib/resolved-candidate-facts.mjs +90 -62
  89. package/bin/lib/rules-under-contract.mjs +72 -8
  90. package/bin/lib/scan-files.mjs +4 -4
  91. package/bin/lib/schema-validation.mjs +130 -0
  92. package/bin/lib/sensor-promote-cli.mjs +2 -11
  93. package/bin/lib/sensor-promote-io.mjs +33 -22
  94. package/bin/lib/sensor-promotion.mjs +1 -1
  95. package/bin/lib/skill-catalog-apply.mjs +1 -1
  96. package/bin/lib/skill-install.mjs +42 -38
  97. package/bin/lib/snippet-analysis.mjs +1 -1
  98. package/bin/lib/start-install-recovery.mjs +1 -1
  99. package/bin/lib/start-preview.mjs +1 -1
  100. package/bin/lib/states-transitions-presence.mjs +3 -3
  101. package/bin/lib/status-command.mjs +2 -18
  102. package/bin/lib/status-manifest.mjs +18 -26
  103. package/bin/lib/status-transition-catalog.mjs +0 -6
  104. package/bin/lib/suggestions.mjs +3 -3
  105. package/bin/lib/team-parliament-io.mjs +3 -17
  106. package/bin/lib/team-parliament.mjs +15 -9
  107. package/bin/lib/upgrade-behavior-changes.mjs +2 -2
  108. package/bin/lib/upgrade-command.mjs +2 -24
  109. package/bin/lib/upgrade-outcome.mjs +1 -1
  110. package/bin/lib/upstream-report.mjs +21 -10
  111. package/bin/lib/violations.mjs +10 -9
  112. package/bin/lib/weakest-link.mjs +13 -0
  113. package/bin/lib/write-path-capabilities.mjs +2 -2
  114. package/dist/chunk-AHACEKSV.js +16 -0
  115. package/dist/chunk-UN5EH4QV.cjs +16 -0
  116. package/dist/{configTypes-BJbaeoj4.d.cts → configTypes-GPvvdleM.d.cts} +12 -1
  117. package/dist/{configTypes-BJbaeoj4.d.ts → configTypes-GPvvdleM.d.ts} +12 -1
  118. package/dist/eslint/index.cjs +11 -11
  119. package/dist/eslint/index.d.cts +10 -1
  120. package/dist/eslint/index.d.ts +10 -1
  121. package/dist/eslint/index.js +11 -11
  122. package/dist/index.cjs +34 -34
  123. package/dist/index.d.cts +587 -515
  124. package/dist/index.d.ts +587 -515
  125. package/dist/index.js +34 -34
  126. package/dist/nestjs/index.cjs +1 -1
  127. package/dist/nestjs/index.d.cts +1 -1
  128. package/dist/nestjs/index.d.ts +1 -1
  129. package/dist/nestjs/index.js +1 -1
  130. package/dist/order/index.cjs +1 -1
  131. package/dist/order/index.js +1 -1
  132. package/dist/runtime/index.cjs +12 -12
  133. package/dist/runtime/index.d.cts +174 -136
  134. package/dist/runtime/index.d.ts +174 -136
  135. package/dist/runtime/index.js +12 -12
  136. package/dist/{types-DRinG-vT.d.cts → types-CnauMQQL.d.cts} +33 -25
  137. package/dist/{types-DRinG-vT.d.ts → types-CnauMQQL.d.ts} +33 -25
  138. package/docs/README.md +2 -1
  139. package/docs/agent-guide.md +134 -2
  140. package/docs/ai-gates.md +15 -1
  141. package/docs/configuration.md +40 -11
  142. package/docs/diagnostics.md +118 -2
  143. package/docs/package-surface.md +4 -1
  144. package/docs/product-voice.md +7 -1
  145. package/package.json +11 -2
  146. package/schemas/ark.config.schema.json +31 -3
  147. package/schemas/ark.invariant-probe.schema.json +368 -0
  148. package/server.json +2 -2
  149. package/templates/agent-skills/README.md +1 -1
  150. package/templates/agent-skills/ark-adopt/SKILL.md +1 -0
  151. package/templates/agent-skills/ark-contract/SKILL.md +17 -0
  152. package/templates/agent-skills/ark-coverage/SKILL.md +2 -0
  153. package/templates/agent-skills/ark-explore/SKILL.md +7 -0
  154. package/templates/agent-skills/ark-fix/SKILL.md +20 -0
  155. package/templates/agent-skills/ark-place/SKILL.md +8 -0
  156. package/templates/skills/ark-adopt.md +1 -0
  157. package/templates/skills/ark-contract.md +17 -0
  158. package/templates/skills/ark-coverage.md +2 -0
  159. package/templates/skills/ark-explore.md +7 -0
  160. package/templates/skills/ark-fix.md +20 -0
  161. package/templates/skills/ark-place.md +8 -0
  162. package/bin/lib/ark-order-error.mjs +0 -18
  163. package/bin/lib/ark-order-invariants.mjs +0 -388
  164. package/bin/lib/stable-hash.mjs +0 -90
  165. package/dist/chunk-MBXCFLO4.js +0 -16
  166. package/dist/chunk-RNQHRDCQ.cjs +0 -16
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkRNQHRDCQcjs = require('../chunk-RNQHRDCQ.cjs');var _chunkA5EIY3HIcjs = require('../chunk-A5EIY3HI.cjs');var _common = require('@nestjs/common');var t=Symbol("ARK_KERNEL"),y= exports.InjectArk =_chunkA5EIY3HIcjs.a.call(void 0, ()=>_common.Inject.call(void 0, t),"InjectArk"),e= exports.ArkModule =class{static forRoot(r){let i=r&&"registry"in r?r:_chunkRNQHRDCQcjs.va.call(void 0, r);return{module:e,global:!0,providers:[{provide:t,useValue:i}],exports:[t]}}static forRootAsync(r){return{module:e,global:!0,providers:[{provide:t,useFactory:r.useFactory,inject:_nullishCoalesce(r.inject, () => ([]))}],exports:[t]}}};_chunkA5EIY3HIcjs.a.call(void 0, e,"ArkModule"),e= exports.ArkModule =_chunkA5EIY3HIcjs.b.call(void 0, [_common.Module.call(void 0, {})],e);exports.ARK_KERNEL = t; exports.ArkModule = e; exports.InjectArk = y;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkUN5EH4QVcjs = require('../chunk-UN5EH4QV.cjs');var _chunkA5EIY3HIcjs = require('../chunk-A5EIY3HI.cjs');var _common = require('@nestjs/common');var t=Symbol("ARK_KERNEL"),y= exports.InjectArk =_chunkA5EIY3HIcjs.a.call(void 0, ()=>_common.Inject.call(void 0, t),"InjectArk"),e= exports.ArkModule =class{static forRoot(r){let i=r&&"registry"in r?r:_chunkUN5EH4QVcjs.va.call(void 0, r);return{module:e,global:!0,providers:[{provide:t,useValue:i}],exports:[t]}}static forRootAsync(r){return{module:e,global:!0,providers:[{provide:t,useFactory:r.useFactory,inject:_nullishCoalesce(r.inject, () => ([]))}],exports:[t]}}};_chunkA5EIY3HIcjs.a.call(void 0, e,"ArkModule"),e= exports.ArkModule =_chunkA5EIY3HIcjs.b.call(void 0, [_common.Module.call(void 0, {})],e);exports.ARK_KERNEL = t; exports.ArkModule = e; exports.InjectArk = y;
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
2
- import { A as ArkKernel, C as CreateArkKernelOptions } from '../types-DRinG-vT.cjs';
2
+ import { A as ArkKernel, C as CreateArkKernelOptions } from '../types-CnauMQQL.cjs';
3
3
 
4
4
  /** Injection token for the Ark kernel instance. */
5
5
  declare const ARK_KERNEL: unique symbol;
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
2
- import { A as ArkKernel, C as CreateArkKernelOptions } from '../types-DRinG-vT.js';
2
+ import { A as ArkKernel, C as CreateArkKernelOptions } from '../types-CnauMQQL.js';
3
3
 
4
4
  /** Injection token for the Ark kernel instance. */
5
5
  declare const ARK_KERNEL: unique symbol;
@@ -1 +1 @@
1
- import{va as c}from"../chunk-MBXCFLO4.js";import{a as o,b as n}from"../chunk-SVSQVGFJ.js";import{Inject as p,Module as s}from"@nestjs/common";var t=Symbol("ARK_KERNEL"),y=o(()=>p(t),"InjectArk"),e=class{static forRoot(r){let i=r&&"registry"in r?r:c(r);return{module:e,global:!0,providers:[{provide:t,useValue:i}],exports:[t]}}static forRootAsync(r){return{module:e,global:!0,providers:[{provide:t,useFactory:r.useFactory,inject:r.inject??[]}],exports:[t]}}};o(e,"ArkModule"),e=n([s({})],e);export{t as ARK_KERNEL,e as ArkModule,y as InjectArk};
1
+ import{va as c}from"../chunk-AHACEKSV.js";import{a as o,b as n}from"../chunk-SVSQVGFJ.js";import{Inject as p,Module as s}from"@nestjs/common";var t=Symbol("ARK_KERNEL"),y=o(()=>p(t),"InjectArk"),e=class{static forRoot(r){let i=r&&"registry"in r?r:c(r);return{module:e,global:!0,providers:[{provide:t,useValue:i}],exports:[t]}}static forRootAsync(r){return{module:e,global:!0,providers:[{provide:t,useFactory:r.useFactory,inject:r.inject??[]}],exports:[t]}}};o(e,"ArkModule"),e=n([s({})],e);export{t as ARK_KERNEL,e as ArkModule,y as InjectArk};
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var o=(e,r)=>b(e,"name",{value:r,configurable:!0});var ae=(e,r)=>{for(var t in r)b(e,t,{get:r[t],enumerable:!0})},se=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of ne(r))!oe.call(e,n)&&n!==t&&b(e,n,{get:()=>r[n],enumerable:!(s=te(r,n))||s.enumerable});return e};var ie=e=>se(b({},"__esModule",{value:!0}),e);var Re={};ae(Re,{ArkOrderError:()=>i,CAPACITY_OPS:()=>k,DEFAULT_MAX_XI_KEYS:()=>x,createMemoryReleaseStore:()=>re,createOrderPlane:()=>ee,hashOf:()=>h,hashReleasePayload:()=>h,ingestTravelAction:()=>Y});module.exports=ie(Re);var i=class extends Error{static{o(this,"ArkOrderError")}code;constructor(r,t){super(t),this.name="ArkOrderError",this.code=r}};var x=7,B=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;var k=["lte","lt","gte","gt"];function y(e){let r=2166136261;for(let t=0;t<e.length;t+=1)r^=e.charCodeAt(t),r=Math.imul(r,16777619);return`fnv1a-${(r>>>0).toString(16).padStart(8,"0")}`}o(y,"deterministicHash");function p(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(p).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${p(r[t])}`).join(",")}}`}o(p,"stableSerialize");function Y(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}o(Y,"ingestTravelAction");var ce=["update","patch","set","mutate"];function U(e){return ce.includes(e)}o(U,"isForbiddenPlaneMethod");function de(e){return e===null||typeof e=="string"||typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean"}o(de,"isPrimitive");function m(e,r){let t=Object.keys(e);if(t.length===0&&r==="\u03BE")throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let n of t.sort()){let a=e[n];if(typeof a=="number"&&!Number.isFinite(a))throw new i("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(n)} is a non-finite number (NaN/\xB1Infinity has no stable identity)`);if(!de(a))throw new i("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(n)} is not a slow primitive (nested values are microstate)`);s[n]=Object.is(a,-0)?0:a}return Object.freeze(s)}o(m,"freezeRecord");function D(e,r){let t=Object.keys(e).length;if(t===0)throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(t>r)throw new i("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${t} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}o(D,"assertXiKeyCap");function K(e,r){if(!r)return;let t=r.properties??{},s=r.additionalProperties!==!1;for(let n of Object.keys(e)){let a=t[n];if(!a){if(!s)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(n)} is not in xiSchema.properties`);continue}if(a.enum&&!a.enum.some(l=>l===e[n]))throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(n)} value is not in enum`);if(a.type==="null"&&e[n]!==null)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(n)} must be null`);if(a.type&&a.type!=="null"&&typeof e[n]!==a.type)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(n)} must be ${a.type}`)}}o(K,"assertXiSchema");function z(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}o(z,"catalogDigestFor");function h(e,r,t){let s=z(e,t);return s!==void 0?y(p({xi:e,sigma:r,catalogDigest:s})):y(p({xi:e,sigma:r}))}o(h,"hashReleasePayload");function T(e,r){let t=z(e,r);return t!==void 0?y(p({xi:e,catalogDigest:t})):y(p({xi:e}))}o(T,"hashXiIdentity");function _(e){return y(p({sigma:e}))}o(_,"hashSigmaIdentity");function J(e,r){return p(e)===p(r)}o(J,"xiRecordsEqual");function j(e,r){if(e&&!J(e.xi,r))throw new i("ARKORDER_UNVALVED_RELEASE","\u03BE is frozen; change the pattern with proposeRelease then apply(ProposeResult)")}o(j,"assertUnvalvedRelease");function I(e){D(e.xi,e.maxXiKeys);let r=m(e.xi,"\u03BE");C(r),K(r,e.xiSchema);let t=m(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:h(r,t,e.catalogDigest),xiHash:T(r,e.catalogDigest),sigmaHash:_(t),xi:r,sigma:t,releasedAt:e.now})}o(I,"createFrozenRelease");function G(e){let r=m(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:h(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:_(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}o(G,"refreshSigmaRecord");function C(e){for(let r of Object.keys(e))if(B.test(r))throw new i("ARKORDER_XI_TTL",`\u03BE key ${JSON.stringify(r)} is a freshness field; TTL belongs on \u03C3, never on \u03BE`)}o(C,"assertXiHasNoTtl");function S(e,r){if(!r||r.cannotObserve.length===0)return;let t=new Set(r.cannotObserve);for(let s of e.allowedKinds)if(t.has(s))throw new i("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}o(S,"assertInformationBudget");function V(e){let r=e.sigma.freshUntil;if(typeof r=="number"){if(e.now>r)throw new i("ARKORDER_STALE_SIGMA","\u03C3 freshUntil has elapsed; \u03BE does not TTL");return}if(e.maxAgeMs===void 0)return;let t=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof t=="number"&&e.now-t>e.maxAgeMs)throw new i("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}o(V,"assertSigmaFresh");function v(e){return y(p({kind:e.kind,payload:e.payload??null}))}o(v,"fieldEventIdentity");function le(e,r){return{event:e,xiHash:r,eventId:v(e)}}o(le,"bindResidual");var ue=new Set(k);function ge(e){return typeof e=="string"&&ue.has(e)}o(ge,"isCapacityOp");function L(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}o(L,"numericLeaf");function fe(e,r,t){return r==="lte"?e<=t:r==="lt"?e<t:r==="gte"?e>=t:e>t}o(fe,"compareCapacity");function w(e){return typeof e=="function"?!0:e===null||typeof e!="object"?!1:Array.isArray(e)?e.some(w):Object.values(e).some(w)}o(w,"packHasFunction");function pe(e,r,t){let s=t.capacity??[];for(let n of s){if(w(n)||!ge(n.op))return"pack";if(n.kind!==e.kind)continue;let a=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?L(e.payload[n.payloadKey]):void 0,l=L(r[n.sigmaKey]);if(a===void 0||l===void 0)return"pack";if(!fe(a,n.op,l))return"capacity"}return"ok"}o(pe,"evaluateCapacity");function q(e,r,t=[],s="",n=Object.freeze({})){let a=r.kind,l=le(r,s);for(let u of t){if(w(u.capacity)||w(u.escalateKinds))return{...l,kind:"hold",reasonCode:"pack",reason:`pack ${u.id} is not data-only; user predicates are forbidden`};if(u.escalateKinds?.includes(a)){let d=u.escalateTarget??"human";return{...l,kind:"escalate_up",reasonCode:"pack",reason:`pack ${u.id} slaves kind ${JSON.stringify(a)} to a pattern change`,target:d}}}if(!e.allowedKinds.includes(a))return{...l,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(a)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let u of t){let d=pe(r,n,u);if(d!=="ok")return{...l,kind:"hold",reasonCode:d,reason:d==="capacity"?`pack ${u.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${u.id} capacity is not numeric data`}}return{...l,kind:"absorb"}}o(q,"classifyIngest");function W(e,r){let t=new Set(e.allowedKinds),s=new Set(r.allowedKinds),n=new Set;for(let a of t)s.has(a)||n.add(a);for(let a of s)t.has(a)||n.add(a);for(let a of r.invalidated)n.add(a);return{blastRadius:[...n].sort(),invalidations:[...r.invalidated].sort()}}o(W,"blastRadiusOf");function Q(e){let r={...e.current.xi};for(let[u,d]of Object.entries(e.delta)){if(d===void 0){delete r[u];continue}r[u]=d}let t=I({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(t.hash===e.current.hash)throw new i("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let s=e.projector(e.current,e.current.sigma),n=e.projector(t,t.sigma);S(n,e.informationBudget);let{blastRadius:a,invalidations:l}=W(s,n);if(a.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{nextXi:t.xi,blastRadius:a,invalidations:l,baseXiHash:e.current.xiHash,baseVersion:e.current.version}}o(Q,"proposePatternChange");function F(e,r){return!Array.isArray(e)||e.length!==r.length?!1:[...e].map(String).sort().every((s,n)=>s===r[n])}o(F,"sameSortedList");function X(e){return new i("ARKORDER_STALE_PROPOSAL",`${e}; re-run proposeRelease against the current Release and review the new blast radius`)}o(X,"staleProposal");function Z(e){let r=e.proposal;if(!r||typeof r!="object"||!r.nextXi||typeof r.nextXi!="object")throw X("apply() requires a ProposeResult from proposeRelease");if(r.baseXiHash!==e.current.xiHash||r.baseVersion!==e.current.version)throw X(`proposal was computed against a different Release (base v${String(r.baseVersion)}, current v${e.current.version})`);let t=I({xi:{...e.proposal.nextXi},sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(J(t.xi,e.current.xi))throw new i("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let s=e.projector(e.current,e.current.sigma),n=e.projector(t,t.sigma);S(n,e.informationBudget);let{blastRadius:a,invalidations:l}=W(s,n);if(a.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");if(!F(r.blastRadius,a)||!F(r.invalidations,l))throw X("the reviewed blast radius is not the transition apply() would commit");return t}o(Z,"applyProposedRelease");function A(e,r=""){return new i("ARKORDER_SCHEMA",`${e} requires a valid Release${r}; hash is the identity (not durable, not K01)`)}o(A,"closed");function N(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}o(N,"isPlainRecord");function M(e,r,t="restore()"){if(!N(e)||!N(e.xi))throw A(t);let s=e.sigma??{};if(!N(s))throw A(t);let{version:n,hash:a,xiHash:l,sigmaHash:u,releasedAt:d}=e;if(typeof n!="number"||!Number.isInteger(n)||n<1||typeof a!="string"||a.length===0||typeof l!="string"||typeof u!="string"||typeof d!="number"||!Number.isFinite(d))throw A(t);if(d>r.now)throw A(t,` (releasedAt ${d} is after the plane clock ${r.now})`);D(e.xi,r.maxXiKeys);let R=m(e.xi,"\u03BE"),f=m(s,"\u03C3");if(C(R),K(R,r.xiSchema),typeof f.releasedAt=="number"&&f.releasedAt>r.now)throw A(t,` (\u03C3.releasedAt ${f.releasedAt} is after the plane clock ${r.now})`);if(a!==h(R,f,r.catalogDigest)||l!==T(R,r.catalogDigest)||u!==_(f))throw A(t);return Object.freeze({version:n,hash:a,xiHash:l,sigmaHash:u,xi:R,sigma:f,releasedAt:d})}o(M,"rehydrateRelease");function ee(e){if(typeof e?.projector!="function")throw new i("ARKORDER_SCHEMA","createOrderPlane requires a consumer projector h(\u03BE)");let r=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7,t=e.packs??[],s=e.clocks??{now(){return Date.now()}},n=e.store,a=e.catalogDigest,l=o(c=>({maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:a,now:c}),"integrity"),u=n?n.load():null,d=u==null?null:M(u,l(s.now()),"ReleaseStore.load()"),R=d?.version??0;function f(c){return n?.save(c),d=c,R=c.version,c}o(f,"persist");function P(c){return S(e.projector(c,c.sigma),e.informationBudget),c}o(P,"withinBudget");function E(){if(!d)throw new i("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return d}o(E,"requireCurrent");let H={release(c,g){return d&&j(d,m(c,"\u03BE")),f(P(I({xi:c,sigma:g,version:R+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:a})))},project(){let c=E(),g=e.projector(c,c.sigma);return S(g,e.informationBudget),g},ingest(c){let g=E();try{V({sigma:g.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:g.releasedAt})}catch(O){if(O instanceof i&&O.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:c,xiHash:g.xiHash,eventId:v(c),reasonCode:"stale-sigma",reason:O.message};throw O}let $=e.projector(g,g.sigma);return S($,e.informationBudget),q($,c,t,g.xiHash,g.sigma)},proposeRelease(c){return Q({current:E(),delta:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:a,informationBudget:e.informationBudget})},apply(c){return f(Z({current:E(),proposal:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:a,informationBudget:e.informationBudget}))},refreshSigma(c){return f(P(G({current:E(),sigma:c,now:s.now(),catalogDigest:a})))},restore(c){let g=M(c,l(s.now()));if(d&&(j(d,g.xi),g.version<d.version||g.version>d.version+1))throw new i("ARKORDER_UNVALVED_RELEASE",`restore() on a live plane accepts version ${d.version} or ${d.version+1}, got ${g.version}; change the pattern with proposeRelease then apply`);return f(P(g))},current(){return d}};for(let c of["update","patch","set","mutate"])Object.defineProperty(H,c,{enumerable:!1,configurable:!1,get(){throw new i("ARKORDER_FORBIDDEN_METHOD",`${c}() is not a Haken operation; freeze a pattern with release() or proposeRelease()`)}});return Object.freeze(H)}o(ee,"createOrderPlane");function re(e){let r=e??null;return{load(){return r},save(t){r=t}}}o(re,"createMemoryReleaseStore");0&&(module.exports={ArkOrderError,CAPACITY_OPS,DEFAULT_MAX_XI_KEYS,createMemoryReleaseStore,createOrderPlane,hashOf,hashReleasePayload,ingestTravelAction});
1
+ "use strict";var b=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var o=(e,r)=>b(e,"name",{value:r,configurable:!0});var se=(e,r)=>{for(var n in r)b(e,n,{get:r[n],enumerable:!0})},ie=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of oe(r))!ae.call(e,t)&&t!==n&&b(e,t,{get:()=>r[t],enumerable:!(s=te(r,t))||s.enumerable});return e};var ce=e=>ie(b({},"__esModule",{value:!0}),e);var ye={};se(ye,{ArkOrderError:()=>c,CAPACITY_OPS:()=>k,DEFAULT_MAX_XI_KEYS:()=>E,createMemoryReleaseStore:()=>ne,createOrderPlane:()=>re,hashOf:()=>h,hashReleasePayload:()=>h,ingestTravelAction:()=>Y});module.exports=ce(ye);var c=class extends Error{static{o(this,"ArkOrderError")}code;constructor(r,n){super(n),this.name="ArkOrderError",this.code=r}};var E=7,B=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;var k=["lte","lt","gte","gt"];function y(e){let r=2166136261;for(let n=0;n<e.length;n+=1)r^=e.charCodeAt(n),r=Math.imul(r,16777619);return`fnv1a-${(r>>>0).toString(16).padStart(8,"0")}`}o(y,"deterministicHash");function p(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(p).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(n=>`${JSON.stringify(n)}:${p(r[n])}`).join(",")}}`}o(p,"stableSerialize");function Y(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}o(Y,"ingestTravelAction");var le=["update","patch","set","mutate"];function U(e){return le.includes(e)}o(U,"isForbiddenPlaneMethod");function de(e){return e===null||typeof e=="string"||typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean"}o(de,"isPrimitive");function m(e,r){let n=Object.keys(e);if(n.length===0&&r==="\u03BE")throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let t of n.sort()){let a=e[t];if(typeof a=="number"&&!Number.isFinite(a))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(t)} is a non-finite number (NaN/\xB1Infinity has no stable identity)`);if(!de(a))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(t)} is not a slow primitive (nested values are microstate)`);s[t]=Object.is(a,-0)?0:a}return Object.freeze(s)}o(m,"freezeRecord");function X(e,r){let n=Object.keys(e).length;if(n===0)throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(n>r)throw new c("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${n} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}o(X,"assertXiKeyCap");function D(e,r){if(!r)return;let n=r.properties??{},s=r.additionalProperties!==!1;for(let t of Object.keys(e)){let a=n[t];if(!a){if(!s)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(t)} is not in xiSchema.properties`);continue}if(a.enum&&!a.enum.some(d=>d===e[t]))throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(t)} value is not in enum`);if(a.type==="null"&&e[t]!==null)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(t)} must be null`);if(a.type&&a.type!=="null"&&typeof e[t]!==a.type)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(t)} must be ${a.type}`)}}o(D,"assertXiSchema");function z(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}o(z,"catalogDigestFor");function h(e,r,n){let s=z(e,n);return s!==void 0?y(p({xi:e,sigma:r,catalogDigest:s})):y(p({xi:e,sigma:r}))}o(h,"hashReleasePayload");function T(e,r){let n=z(e,r);return n!==void 0?y(p({xi:e,catalogDigest:n})):y(p({xi:e}))}o(T,"hashXiIdentity");function _(e){return y(p({sigma:e}))}o(_,"hashSigmaIdentity");function J(e,r){return p(e)===p(r)}o(J,"xiRecordsEqual");function K(e,r){if(e&&!J(e.xi,r))throw new c("ARKORDER_UNVALVED_RELEASE","\u03BE is frozen; change the pattern with proposeRelease then apply(ProposeResult)")}o(K,"assertUnvalvedRelease");function j(e){X(e.xi,e.maxXiKeys);let r=m(e.xi,"\u03BE");C(r),D(r,e.xiSchema);let n=m(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:h(r,n,e.catalogDigest),xiHash:T(r,e.catalogDigest),sigmaHash:_(n),xi:r,sigma:n,releasedAt:e.now})}o(j,"createFrozenRelease");function V(e){let r=m(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:h(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:_(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}o(V,"refreshSigmaRecord");function C(e){for(let r of Object.keys(e))if(B.test(r))throw new c("ARKORDER_XI_TTL",`\u03BE key ${JSON.stringify(r)} is a freshness field; TTL belongs on \u03C3, never on \u03BE`)}o(C,"assertXiHasNoTtl");function w(e,r){if(!r||r.cannotObserve.length===0)return;let n=new Set(r.cannotObserve);for(let s of e.allowedKinds)if(n.has(s))throw new c("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}o(w,"assertInformationBudget");function G(e){let r=e.sigma.freshUntil;if(typeof r=="number"){if(e.now>r)throw new c("ARKORDER_STALE_SIGMA","\u03C3 freshUntil has elapsed; \u03BE does not TTL");return}if(e.maxAgeMs===void 0)return;let n=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof n=="number"&&e.now-n>e.maxAgeMs)throw new c("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}o(G,"assertSigmaFresh");function v(e){return y(p({kind:e.kind,payload:e.payload??null}))}o(v,"fieldEventIdentity");function ue(e,r){return{event:e,xiHash:r,eventId:v(e)}}o(ue,"bindResidual");var ge=new Set(k);function fe(e){return typeof e=="string"&&ge.has(e)}o(fe,"isCapacityOp");function L(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}o(L,"numericLeaf");function pe(e,r,n){return r==="lte"?e<=n:r==="lt"?e<n:r==="gte"?e>=n:e>n}o(pe,"compareCapacity");function O(e){return typeof e=="function"?!0:e===null||typeof e!="object"?!1:Array.isArray(e)?e.some(O):Object.values(e).some(O)}o(O,"packHasFunction");function Re(e,r,n){let s=n.capacity??[];for(let t of s){if(O(t)||!fe(t.op))return"pack";if(t.kind!==e.kind)continue;let a=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?L(e.payload[t.payloadKey]):void 0,d=L(r[t.sigmaKey]);if(a===void 0||d===void 0)return"pack";if(!pe(a,t.op,d))return"capacity"}return"ok"}o(Re,"evaluateCapacity");function q(e,r,n=[],s="",t=Object.freeze({})){let a=r.kind,d=ue(r,s);for(let u of n){if(O(u.capacity)||O(u.escalateKinds))return{...d,kind:"hold",reasonCode:"pack",reason:`pack ${u.id} is not data-only; user predicates are forbidden`};if(u.escalateKinds?.includes(a)){let l=u.escalateTarget??"human";return{...d,kind:"escalate_up",reasonCode:"pack",reason:`pack ${u.id} slaves kind ${JSON.stringify(a)} to a pattern change`,target:l}}}if(!e.allowedKinds.includes(a))return{...d,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(a)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let u of n){let l=Re(r,t,u);if(l!=="ok")return{...d,kind:"hold",reasonCode:l,reason:l==="capacity"?`pack ${u.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${u.id} capacity is not numeric data`}}return{...d,kind:"absorb"}}o(q,"classifyIngest");function me(e,r){let n=new Set(e.allowedKinds),s=new Set(r.allowedKinds),t=new Set;for(let a of n)s.has(a)||t.add(a);for(let a of s)n.has(a)||t.add(a);for(let a of r.invalidated)t.add(a);return{blastRadius:[...t].sort(),invalidations:[...r.invalidated].sort()}}o(me,"blastRadiusOf");function W(e,r){return j({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest})}o(W,"successorRelease");function Q(e,r){let n=e.projector(e.current,e.current.sigma),s=e.projector(r,r.sigma);w(s,e.informationBudget);let{blastRadius:t,invalidations:a}=me(n,s);if(t.length===0)throw new c("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{blastRadius:t,invalidations:a}}o(Q,"transitionBlast");function Z(e){let r={...e.current.xi};for(let[a,d]of Object.entries(e.delta)){if(d===void 0){delete r[a];continue}r[a]=d}let n=W(e,r);if(n.hash===e.current.hash)throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let{blastRadius:s,invalidations:t}=Q(e,n);return{nextXi:n.xi,blastRadius:s,invalidations:t,baseXiHash:e.current.xiHash,baseVersion:e.current.version}}o(Z,"proposePatternChange");function F(e,r){return!Array.isArray(e)||e.length!==r.length?!1:[...e].map(String).sort().every((s,t)=>s===r[t])}o(F,"sameSortedList");function I(e){return new c("ARKORDER_STALE_PROPOSAL",`${e}; re-run proposeRelease against the current Release and review the new blast radius`)}o(I,"staleProposal");function ee(e){let r=e.proposal;if(!r||typeof r!="object"||!r.nextXi||typeof r.nextXi!="object")throw I("apply() requires a ProposeResult from proposeRelease");if(r.baseXiHash!==e.current.xiHash||r.baseVersion!==e.current.version)throw I(`proposal was computed against a different Release (base v${String(r.baseVersion)}, current v${e.current.version})`);let n=W(e,{...e.proposal.nextXi});if(J(n.xi,e.current.xi))throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let{blastRadius:s,invalidations:t}=Q(e,n);if(!F(r.blastRadius,s)||!F(r.invalidations,t))throw I("the reviewed blast radius is not the transition apply() would commit");return n}o(ee,"applyProposedRelease");function A(e,r=""){return new c("ARKORDER_SCHEMA",`${e} requires a valid Release${r}; hash is the identity (not durable, not K01)`)}o(A,"closed");function N(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}o(N,"isPlainRecord");function M(e,r,n="restore()"){if(!N(e)||!N(e.xi))throw A(n);let s=e.sigma??{};if(!N(s))throw A(n);let{version:t,hash:a,xiHash:d,sigmaHash:u,releasedAt:l}=e;if(typeof t!="number"||!Number.isInteger(t)||t<1||typeof a!="string"||a.length===0||typeof d!="string"||typeof u!="string"||typeof l!="number"||!Number.isFinite(l))throw A(n);if(l>r.now)throw A(n,` (releasedAt ${l} is after the plane clock ${r.now})`);X(e.xi,r.maxXiKeys);let R=m(e.xi,"\u03BE"),f=m(s,"\u03C3");if(C(R),D(R,r.xiSchema),typeof f.releasedAt=="number"&&f.releasedAt>r.now)throw A(n,` (\u03C3.releasedAt ${f.releasedAt} is after the plane clock ${r.now})`);if(a!==h(R,f,r.catalogDigest)||d!==T(R,r.catalogDigest)||u!==_(f))throw A(n);return Object.freeze({version:t,hash:a,xiHash:d,sigmaHash:u,xi:R,sigma:f,releasedAt:l})}o(M,"rehydrateRelease");function re(e){if(typeof e?.projector!="function")throw new c("ARKORDER_SCHEMA","createOrderPlane requires a consumer projector h(\u03BE)");let r=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7,n=e.packs??[],s=e.clocks??{now(){return Date.now()}},t=e.store,a=e.catalogDigest,d=o(i=>({maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:a,now:i}),"integrity"),u=t?t.load():null,l=u==null?null:M(u,d(s.now()),"ReleaseStore.load()"),R=l?.version??0;function f(i){return t?.save(i),l=i,R=i.version,i}o(f,"persist");function P(i){return w(e.projector(i,i.sigma),e.informationBudget),i}o(P,"withinBudget");function S(){if(!l)throw new c("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return l}o(S,"requireCurrent");let H={release(i,g){return l&&K(l,m(i,"\u03BE")),f(P(j({xi:i,sigma:g,version:R+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:a})))},project(){let i=S(),g=e.projector(i,i.sigma);return w(g,e.informationBudget),g},ingest(i){let g=S();try{G({sigma:g.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:g.releasedAt})}catch(x){if(x instanceof c&&x.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:i,xiHash:g.xiHash,eventId:v(i),reasonCode:"stale-sigma",reason:x.message};throw x}let $=e.projector(g,g.sigma);return w($,e.informationBudget),q($,i,n,g.xiHash,g.sigma)},proposeRelease(i){return Z({current:S(),delta:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:a,informationBudget:e.informationBudget})},apply(i){return f(ee({current:S(),proposal:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:a,informationBudget:e.informationBudget}))},refreshSigma(i){return f(P(V({current:S(),sigma:i,now:s.now(),catalogDigest:a})))},restore(i){let g=M(i,d(s.now()));if(l&&(K(l,g.xi),g.version<l.version||g.version>l.version+1))throw new c("ARKORDER_UNVALVED_RELEASE",`restore() on a live plane accepts version ${l.version} or ${l.version+1}, got ${g.version}; change the pattern with proposeRelease then apply`);return f(P(g))},current(){return l}};for(let i of["update","patch","set","mutate"])Object.defineProperty(H,i,{enumerable:!1,configurable:!1,get(){throw new c("ARKORDER_FORBIDDEN_METHOD",`${i}() is not a Haken operation; freeze a pattern with release() or proposeRelease()`)}});return Object.freeze(H)}o(re,"createOrderPlane");function ne(e){let r=e??null;return{load(){return r},save(n){r=n}}}o(ne,"createMemoryReleaseStore");0&&(module.exports={ArkOrderError,CAPACITY_OPS,DEFAULT_MAX_XI_KEYS,createMemoryReleaseStore,createOrderPlane,hashOf,hashReleasePayload,ingestTravelAction});
@@ -1 +1 @@
1
- var Q=Object.defineProperty;var n=(e,r)=>Q(e,"name",{value:r,configurable:!0});var c=class extends Error{static{n(this,"ArkOrderError")}code;constructor(r,t){super(t),this.name="ArkOrderError",this.code=r}};var O=7,$=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;var I=["lte","lt","gte","gt"];function y(e){let r=2166136261;for(let t=0;t<e.length;t+=1)r^=e.charCodeAt(t),r=Math.imul(r,16777619);return`fnv1a-${(r>>>0).toString(16).padStart(8,"0")}`}n(y,"deterministicHash");function p(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(p).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${p(r[t])}`).join(",")}}`}n(p,"stableSerialize");function Z(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}n(Z,"ingestTravelAction");var ee=["update","patch","set","mutate"];function F(e){return ee.includes(e)}n(F,"isForbiddenPlaneMethod");function re(e){return e===null||typeof e=="string"||typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean"}n(re,"isPrimitive");function m(e,r){let t=Object.keys(e);if(t.length===0&&r==="\u03BE")throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let a of t.sort()){let o=e[a];if(typeof o=="number"&&!Number.isFinite(o))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(a)} is a non-finite number (NaN/\xB1Infinity has no stable identity)`);if(!re(o))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(a)} is not a slow primitive (nested values are microstate)`);s[a]=Object.is(o,-0)?0:o}return Object.freeze(s)}n(m,"freezeRecord");function X(e,r){let t=Object.keys(e).length;if(t===0)throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(t>r)throw new c("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${t} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}n(X,"assertXiKeyCap");function D(e,r){if(!r)return;let t=r.properties??{},s=r.additionalProperties!==!1;for(let a of Object.keys(e)){let o=t[a];if(!o){if(!s)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} is not in xiSchema.properties`);continue}if(o.enum&&!o.enum.some(l=>l===e[a]))throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} value is not in enum`);if(o.type==="null"&&e[a]!==null)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be null`);if(o.type&&o.type!=="null"&&typeof e[a]!==o.type)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be ${o.type}`)}}n(D,"assertXiSchema");function Y(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}n(Y,"catalogDigestFor");function h(e,r,t){let s=Y(e,t);return s!==void 0?y(p({xi:e,sigma:r,catalogDigest:s})):y(p({xi:e,sigma:r}))}n(h,"hashReleasePayload");function K(e,r){let t=Y(e,r);return t!==void 0?y(p({xi:e,catalogDigest:t})):y(p({xi:e}))}n(K,"hashXiIdentity");function b(e){return y(p({sigma:e}))}n(b,"hashSigmaIdentity");function U(e,r){return p(e)===p(r)}n(U,"xiRecordsEqual");function T(e,r){if(e&&!U(e.xi,r))throw new c("ARKORDER_UNVALVED_RELEASE","\u03BE is frozen; change the pattern with proposeRelease then apply(ProposeResult)")}n(T,"assertUnvalvedRelease");function k(e){X(e.xi,e.maxXiKeys);let r=m(e.xi,"\u03BE");j(r),D(r,e.xiSchema);let t=m(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:h(r,t,e.catalogDigest),xiHash:K(r,e.catalogDigest),sigmaHash:b(t),xi:r,sigma:t,releasedAt:e.now})}n(k,"createFrozenRelease");function z(e){let r=m(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:h(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:b(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}n(z,"refreshSigmaRecord");function j(e){for(let r of Object.keys(e))if($.test(r))throw new c("ARKORDER_XI_TTL",`\u03BE key ${JSON.stringify(r)} is a freshness field; TTL belongs on \u03C3, never on \u03BE`)}n(j,"assertXiHasNoTtl");function S(e,r){if(!r||r.cannotObserve.length===0)return;let t=new Set(r.cannotObserve);for(let s of e.allowedKinds)if(t.has(s))throw new c("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}n(S,"assertInformationBudget");function J(e){let r=e.sigma.freshUntil;if(typeof r=="number"){if(e.now>r)throw new c("ARKORDER_STALE_SIGMA","\u03C3 freshUntil has elapsed; \u03BE does not TTL");return}if(e.maxAgeMs===void 0)return;let t=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof t=="number"&&e.now-t>e.maxAgeMs)throw new c("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}n(J,"assertSigmaFresh");function C(e){return y(p({kind:e.kind,payload:e.payload??null}))}n(C,"fieldEventIdentity");function te(e,r){return{event:e,xiHash:r,eventId:C(e)}}n(te,"bindResidual");var ne=new Set(I);function oe(e){return typeof e=="string"&&ne.has(e)}n(oe,"isCapacityOp");function B(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}n(B,"numericLeaf");function ae(e,r,t){return r==="lte"?e<=t:r==="lt"?e<t:r==="gte"?e>=t:e>t}n(ae,"compareCapacity");function x(e){return typeof e=="function"?!0:e===null||typeof e!="object"?!1:Array.isArray(e)?e.some(x):Object.values(e).some(x)}n(x,"packHasFunction");function se(e,r,t){let s=t.capacity??[];for(let a of s){if(x(a)||!oe(a.op))return"pack";if(a.kind!==e.kind)continue;let o=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?B(e.payload[a.payloadKey]):void 0,l=B(r[a.sigmaKey]);if(o===void 0||l===void 0)return"pack";if(!ae(o,a.op,l))return"capacity"}return"ok"}n(se,"evaluateCapacity");function G(e,r,t=[],s="",a=Object.freeze({})){let o=r.kind,l=te(r,s);for(let u of t){if(x(u.capacity)||x(u.escalateKinds))return{...l,kind:"hold",reasonCode:"pack",reason:`pack ${u.id} is not data-only; user predicates are forbidden`};if(u.escalateKinds?.includes(o)){let d=u.escalateTarget??"human";return{...l,kind:"escalate_up",reasonCode:"pack",reason:`pack ${u.id} slaves kind ${JSON.stringify(o)} to a pattern change`,target:d}}}if(!e.allowedKinds.includes(o))return{...l,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(o)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let u of t){let d=se(r,a,u);if(d!=="ok")return{...l,kind:"hold",reasonCode:d,reason:d==="capacity"?`pack ${u.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${u.id} capacity is not numeric data`}}return{...l,kind:"absorb"}}n(G,"classifyIngest");function V(e,r){let t=new Set(e.allowedKinds),s=new Set(r.allowedKinds),a=new Set;for(let o of t)s.has(o)||a.add(o);for(let o of s)t.has(o)||a.add(o);for(let o of r.invalidated)a.add(o);return{blastRadius:[...a].sort(),invalidations:[...r.invalidated].sort()}}n(V,"blastRadiusOf");function q(e){let r={...e.current.xi};for(let[u,d]of Object.entries(e.delta)){if(d===void 0){delete r[u];continue}r[u]=d}let t=k({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(t.hash===e.current.hash)throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let s=e.projector(e.current,e.current.sigma),a=e.projector(t,t.sigma);S(a,e.informationBudget);let{blastRadius:o,invalidations:l}=V(s,a);if(o.length===0)throw new c("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{nextXi:t.xi,blastRadius:o,invalidations:l,baseXiHash:e.current.xiHash,baseVersion:e.current.version}}n(q,"proposePatternChange");function L(e,r){return!Array.isArray(e)||e.length!==r.length?!1:[...e].map(String).sort().every((s,a)=>s===r[a])}n(L,"sameSortedList");function P(e){return new c("ARKORDER_STALE_PROPOSAL",`${e}; re-run proposeRelease against the current Release and review the new blast radius`)}n(P,"staleProposal");function W(e){let r=e.proposal;if(!r||typeof r!="object"||!r.nextXi||typeof r.nextXi!="object")throw P("apply() requires a ProposeResult from proposeRelease");if(r.baseXiHash!==e.current.xiHash||r.baseVersion!==e.current.version)throw P(`proposal was computed against a different Release (base v${String(r.baseVersion)}, current v${e.current.version})`);let t=k({xi:{...e.proposal.nextXi},sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(U(t.xi,e.current.xi))throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let s=e.projector(e.current,e.current.sigma),a=e.projector(t,t.sigma);S(a,e.informationBudget);let{blastRadius:o,invalidations:l}=V(s,a);if(o.length===0)throw new c("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");if(!L(r.blastRadius,o)||!L(r.invalidations,l))throw P("the reviewed blast radius is not the transition apply() would commit");return t}n(W,"applyProposedRelease");function A(e,r=""){return new c("ARKORDER_SCHEMA",`${e} requires a valid Release${r}; hash is the identity (not durable, not K01)`)}n(A,"closed");function v(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}n(v,"isPlainRecord");function N(e,r,t="restore()"){if(!v(e)||!v(e.xi))throw A(t);let s=e.sigma??{};if(!v(s))throw A(t);let{version:a,hash:o,xiHash:l,sigmaHash:u,releasedAt:d}=e;if(typeof a!="number"||!Number.isInteger(a)||a<1||typeof o!="string"||o.length===0||typeof l!="string"||typeof u!="string"||typeof d!="number"||!Number.isFinite(d))throw A(t);if(d>r.now)throw A(t,` (releasedAt ${d} is after the plane clock ${r.now})`);X(e.xi,r.maxXiKeys);let R=m(e.xi,"\u03BE"),f=m(s,"\u03C3");if(j(R),D(R,r.xiSchema),typeof f.releasedAt=="number"&&f.releasedAt>r.now)throw A(t,` (\u03C3.releasedAt ${f.releasedAt} is after the plane clock ${r.now})`);if(o!==h(R,f,r.catalogDigest)||l!==K(R,r.catalogDigest)||u!==b(f))throw A(t);return Object.freeze({version:a,hash:o,xiHash:l,sigmaHash:u,xi:R,sigma:f,releasedAt:d})}n(N,"rehydrateRelease");function ie(e){if(typeof e?.projector!="function")throw new c("ARKORDER_SCHEMA","createOrderPlane requires a consumer projector h(\u03BE)");let r=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7,t=e.packs??[],s=e.clocks??{now(){return Date.now()}},a=e.store,o=e.catalogDigest,l=n(i=>({maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:o,now:i}),"integrity"),u=a?a.load():null,d=u==null?null:N(u,l(s.now()),"ReleaseStore.load()"),R=d?.version??0;function f(i){return a?.save(i),d=i,R=i.version,i}n(f,"persist");function _(i){return S(e.projector(i,i.sigma),e.informationBudget),i}n(_,"withinBudget");function E(){if(!d)throw new c("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return d}n(E,"requireCurrent");let M={release(i,g){return d&&T(d,m(i,"\u03BE")),f(_(k({xi:i,sigma:g,version:R+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:o})))},project(){let i=E(),g=e.projector(i,i.sigma);return S(g,e.informationBudget),g},ingest(i){let g=E();try{J({sigma:g.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:g.releasedAt})}catch(w){if(w instanceof c&&w.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:i,xiHash:g.xiHash,eventId:C(i),reasonCode:"stale-sigma",reason:w.message};throw w}let H=e.projector(g,g.sigma);return S(H,e.informationBudget),G(H,i,t,g.xiHash,g.sigma)},proposeRelease(i){return q({current:E(),delta:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:o,informationBudget:e.informationBudget})},apply(i){return f(W({current:E(),proposal:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:o,informationBudget:e.informationBudget}))},refreshSigma(i){return f(_(z({current:E(),sigma:i,now:s.now(),catalogDigest:o})))},restore(i){let g=N(i,l(s.now()));if(d&&(T(d,g.xi),g.version<d.version||g.version>d.version+1))throw new c("ARKORDER_UNVALVED_RELEASE",`restore() on a live plane accepts version ${d.version} or ${d.version+1}, got ${g.version}; change the pattern with proposeRelease then apply`);return f(_(g))},current(){return d}};for(let i of["update","patch","set","mutate"])Object.defineProperty(M,i,{enumerable:!1,configurable:!1,get(){throw new c("ARKORDER_FORBIDDEN_METHOD",`${i}() is not a Haken operation; freeze a pattern with release() or proposeRelease()`)}});return Object.freeze(M)}n(ie,"createOrderPlane");function ce(e){let r=e??null;return{load(){return r},save(t){r=t}}}n(ce,"createMemoryReleaseStore");export{c as ArkOrderError,I as CAPACITY_OPS,O as DEFAULT_MAX_XI_KEYS,ce as createMemoryReleaseStore,ie as createOrderPlane,h as hashOf,h as hashReleasePayload,Z as ingestTravelAction};
1
+ var Z=Object.defineProperty;var t=(e,r)=>Z(e,"name",{value:r,configurable:!0});var c=class extends Error{static{t(this,"ArkOrderError")}code;constructor(r,n){super(n),this.name="ArkOrderError",this.code=r}};var x=7,$=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;var _=["lte","lt","gte","gt"];function y(e){let r=2166136261;for(let n=0;n<e.length;n+=1)r^=e.charCodeAt(n),r=Math.imul(r,16777619);return`fnv1a-${(r>>>0).toString(16).padStart(8,"0")}`}t(y,"deterministicHash");function p(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(p).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(n=>`${JSON.stringify(n)}:${p(r[n])}`).join(",")}}`}t(p,"stableSerialize");function ee(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}t(ee,"ingestTravelAction");var re=["update","patch","set","mutate"];function F(e){return re.includes(e)}t(F,"isForbiddenPlaneMethod");function ne(e){return e===null||typeof e=="string"||typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean"}t(ne,"isPrimitive");function m(e,r){let n=Object.keys(e);if(n.length===0&&r==="\u03BE")throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let a of n.sort()){let o=e[a];if(typeof o=="number"&&!Number.isFinite(o))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(a)} is a non-finite number (NaN/\xB1Infinity has no stable identity)`);if(!ne(o))throw new c("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(a)} is not a slow primitive (nested values are microstate)`);s[a]=Object.is(o,-0)?0:o}return Object.freeze(s)}t(m,"freezeRecord");function I(e,r){let n=Object.keys(e).length;if(n===0)throw new c("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(n>r)throw new c("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${n} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}t(I,"assertXiKeyCap");function X(e,r){if(!r)return;let n=r.properties??{},s=r.additionalProperties!==!1;for(let a of Object.keys(e)){let o=n[a];if(!o){if(!s)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} is not in xiSchema.properties`);continue}if(o.enum&&!o.enum.some(d=>d===e[a]))throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} value is not in enum`);if(o.type==="null"&&e[a]!==null)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be null`);if(o.type&&o.type!=="null"&&typeof e[a]!==o.type)throw new c("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be ${o.type}`)}}t(X,"assertXiSchema");function Y(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}t(Y,"catalogDigestFor");function h(e,r,n){let s=Y(e,n);return s!==void 0?y(p({xi:e,sigma:r,catalogDigest:s})):y(p({xi:e,sigma:r}))}t(h,"hashReleasePayload");function D(e,r){let n=Y(e,r);return n!==void 0?y(p({xi:e,catalogDigest:n})):y(p({xi:e}))}t(D,"hashXiIdentity");function b(e){return y(p({sigma:e}))}t(b,"hashSigmaIdentity");function U(e,r){return p(e)===p(r)}t(U,"xiRecordsEqual");function T(e,r){if(e&&!U(e.xi,r))throw new c("ARKORDER_UNVALVED_RELEASE","\u03BE is frozen; change the pattern with proposeRelease then apply(ProposeResult)")}t(T,"assertUnvalvedRelease");function K(e){I(e.xi,e.maxXiKeys);let r=m(e.xi,"\u03BE");j(r),X(r,e.xiSchema);let n=m(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:h(r,n,e.catalogDigest),xiHash:D(r,e.catalogDigest),sigmaHash:b(n),xi:r,sigma:n,releasedAt:e.now})}t(K,"createFrozenRelease");function z(e){let r=m(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:h(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:b(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}t(z,"refreshSigmaRecord");function j(e){for(let r of Object.keys(e))if($.test(r))throw new c("ARKORDER_XI_TTL",`\u03BE key ${JSON.stringify(r)} is a freshness field; TTL belongs on \u03C3, never on \u03BE`)}t(j,"assertXiHasNoTtl");function O(e,r){if(!r||r.cannotObserve.length===0)return;let n=new Set(r.cannotObserve);for(let s of e.allowedKinds)if(n.has(s))throw new c("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}t(O,"assertInformationBudget");function J(e){let r=e.sigma.freshUntil;if(typeof r=="number"){if(e.now>r)throw new c("ARKORDER_STALE_SIGMA","\u03C3 freshUntil has elapsed; \u03BE does not TTL");return}if(e.maxAgeMs===void 0)return;let n=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof n=="number"&&e.now-n>e.maxAgeMs)throw new c("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}t(J,"assertSigmaFresh");function C(e){return y(p({kind:e.kind,payload:e.payload??null}))}t(C,"fieldEventIdentity");function te(e,r){return{event:e,xiHash:r,eventId:C(e)}}t(te,"bindResidual");var oe=new Set(_);function ae(e){return typeof e=="string"&&oe.has(e)}t(ae,"isCapacityOp");function B(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}t(B,"numericLeaf");function se(e,r,n){return r==="lte"?e<=n:r==="lt"?e<n:r==="gte"?e>=n:e>n}t(se,"compareCapacity");function E(e){return typeof e=="function"?!0:e===null||typeof e!="object"?!1:Array.isArray(e)?e.some(E):Object.values(e).some(E)}t(E,"packHasFunction");function ie(e,r,n){let s=n.capacity??[];for(let a of s){if(E(a)||!ae(a.op))return"pack";if(a.kind!==e.kind)continue;let o=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?B(e.payload[a.payloadKey]):void 0,d=B(r[a.sigmaKey]);if(o===void 0||d===void 0)return"pack";if(!se(o,a.op,d))return"capacity"}return"ok"}t(ie,"evaluateCapacity");function V(e,r,n=[],s="",a=Object.freeze({})){let o=r.kind,d=te(r,s);for(let u of n){if(E(u.capacity)||E(u.escalateKinds))return{...d,kind:"hold",reasonCode:"pack",reason:`pack ${u.id} is not data-only; user predicates are forbidden`};if(u.escalateKinds?.includes(o)){let l=u.escalateTarget??"human";return{...d,kind:"escalate_up",reasonCode:"pack",reason:`pack ${u.id} slaves kind ${JSON.stringify(o)} to a pattern change`,target:l}}}if(!e.allowedKinds.includes(o))return{...d,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(o)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let u of n){let l=ie(r,a,u);if(l!=="ok")return{...d,kind:"hold",reasonCode:l,reason:l==="capacity"?`pack ${u.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${u.id} capacity is not numeric data`}}return{...d,kind:"absorb"}}t(V,"classifyIngest");function ce(e,r){let n=new Set(e.allowedKinds),s=new Set(r.allowedKinds),a=new Set;for(let o of n)s.has(o)||a.add(o);for(let o of s)n.has(o)||a.add(o);for(let o of r.invalidated)a.add(o);return{blastRadius:[...a].sort(),invalidations:[...r.invalidated].sort()}}t(ce,"blastRadiusOf");function G(e,r){return K({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest})}t(G,"successorRelease");function q(e,r){let n=e.projector(e.current,e.current.sigma),s=e.projector(r,r.sigma);O(s,e.informationBudget);let{blastRadius:a,invalidations:o}=ce(n,s);if(a.length===0)throw new c("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{blastRadius:a,invalidations:o}}t(q,"transitionBlast");function W(e){let r={...e.current.xi};for(let[o,d]of Object.entries(e.delta)){if(d===void 0){delete r[o];continue}r[o]=d}let n=G(e,r);if(n.hash===e.current.hash)throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let{blastRadius:s,invalidations:a}=q(e,n);return{nextXi:n.xi,blastRadius:s,invalidations:a,baseXiHash:e.current.xiHash,baseVersion:e.current.version}}t(W,"proposePatternChange");function L(e,r){return!Array.isArray(e)||e.length!==r.length?!1:[...e].map(String).sort().every((s,a)=>s===r[a])}t(L,"sameSortedList");function P(e){return new c("ARKORDER_STALE_PROPOSAL",`${e}; re-run proposeRelease against the current Release and review the new blast radius`)}t(P,"staleProposal");function Q(e){let r=e.proposal;if(!r||typeof r!="object"||!r.nextXi||typeof r.nextXi!="object")throw P("apply() requires a ProposeResult from proposeRelease");if(r.baseXiHash!==e.current.xiHash||r.baseVersion!==e.current.version)throw P(`proposal was computed against a different Release (base v${String(r.baseVersion)}, current v${e.current.version})`);let n=G(e,{...e.proposal.nextXi});if(U(n.xi,e.current.xi))throw new c("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let{blastRadius:s,invalidations:a}=q(e,n);if(!L(r.blastRadius,s)||!L(r.invalidations,a))throw P("the reviewed blast radius is not the transition apply() would commit");return n}t(Q,"applyProposedRelease");function A(e,r=""){return new c("ARKORDER_SCHEMA",`${e} requires a valid Release${r}; hash is the identity (not durable, not K01)`)}t(A,"closed");function v(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}t(v,"isPlainRecord");function N(e,r,n="restore()"){if(!v(e)||!v(e.xi))throw A(n);let s=e.sigma??{};if(!v(s))throw A(n);let{version:a,hash:o,xiHash:d,sigmaHash:u,releasedAt:l}=e;if(typeof a!="number"||!Number.isInteger(a)||a<1||typeof o!="string"||o.length===0||typeof d!="string"||typeof u!="string"||typeof l!="number"||!Number.isFinite(l))throw A(n);if(l>r.now)throw A(n,` (releasedAt ${l} is after the plane clock ${r.now})`);I(e.xi,r.maxXiKeys);let R=m(e.xi,"\u03BE"),f=m(s,"\u03C3");if(j(R),X(R,r.xiSchema),typeof f.releasedAt=="number"&&f.releasedAt>r.now)throw A(n,` (\u03C3.releasedAt ${f.releasedAt} is after the plane clock ${r.now})`);if(o!==h(R,f,r.catalogDigest)||d!==D(R,r.catalogDigest)||u!==b(f))throw A(n);return Object.freeze({version:a,hash:o,xiHash:d,sigmaHash:u,xi:R,sigma:f,releasedAt:l})}t(N,"rehydrateRelease");function le(e){if(typeof e?.projector!="function")throw new c("ARKORDER_SCHEMA","createOrderPlane requires a consumer projector h(\u03BE)");let r=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7,n=e.packs??[],s=e.clocks??{now(){return Date.now()}},a=e.store,o=e.catalogDigest,d=t(i=>({maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:o,now:i}),"integrity"),u=a?a.load():null,l=u==null?null:N(u,d(s.now()),"ReleaseStore.load()"),R=l?.version??0;function f(i){return a?.save(i),l=i,R=i.version,i}t(f,"persist");function k(i){return O(e.projector(i,i.sigma),e.informationBudget),i}t(k,"withinBudget");function S(){if(!l)throw new c("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return l}t(S,"requireCurrent");let M={release(i,g){return l&&T(l,m(i,"\u03BE")),f(k(K({xi:i,sigma:g,version:R+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:o})))},project(){let i=S(),g=e.projector(i,i.sigma);return O(g,e.informationBudget),g},ingest(i){let g=S();try{J({sigma:g.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:g.releasedAt})}catch(w){if(w instanceof c&&w.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:i,xiHash:g.xiHash,eventId:C(i),reasonCode:"stale-sigma",reason:w.message};throw w}let H=e.projector(g,g.sigma);return O(H,e.informationBudget),V(H,i,n,g.xiHash,g.sigma)},proposeRelease(i){return W({current:S(),delta:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:o,informationBudget:e.informationBudget})},apply(i){return f(Q({current:S(),proposal:i,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:o,informationBudget:e.informationBudget}))},refreshSigma(i){return f(k(z({current:S(),sigma:i,now:s.now(),catalogDigest:o})))},restore(i){let g=N(i,d(s.now()));if(l&&(T(l,g.xi),g.version<l.version||g.version>l.version+1))throw new c("ARKORDER_UNVALVED_RELEASE",`restore() on a live plane accepts version ${l.version} or ${l.version+1}, got ${g.version}; change the pattern with proposeRelease then apply`);return f(k(g))},current(){return l}};for(let i of["update","patch","set","mutate"])Object.defineProperty(M,i,{enumerable:!1,configurable:!1,get(){throw new c("ARKORDER_FORBIDDEN_METHOD",`${i}() is not a Haken operation; freeze a pattern with release() or proposeRelease()`)}});return Object.freeze(M)}t(le,"createOrderPlane");function de(e){let r=e??null;return{load(){return r},save(n){r=n}}}t(de,"createMemoryReleaseStore");export{c as ArkOrderError,_ as CAPACITY_OPS,x as DEFAULT_MAX_XI_KEYS,de as createMemoryReleaseStore,le as createOrderPlane,h as hashOf,h as hashReleasePayload,ee as ingestTravelAction};