arkgate 4.8.23 → 4.8.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +7 -5
- package/bin/ark-check-runtime.mjs +24 -77
- package/bin/ark-dashboard.mjs +56 -53
- package/bin/ark-layer-match.mjs +596 -112
- package/bin/ark-mcp-runtime.mjs +412 -138
- package/bin/ark-mcp.mjs +68 -4
- package/bin/ark-shared.mjs +39 -0
- package/bin/ark.mjs +65 -97
- package/bin/lib/adapter-contract-types.mjs +5 -0
- package/bin/lib/adapter-contract.mjs +15 -0
- package/bin/lib/agent-projection-command.mjs +5 -1
- package/bin/lib/analysis-engine.mjs +15 -11
- package/bin/lib/architecture-scan.mjs +50 -6
- package/bin/lib/ark-order-doctor.mjs +1 -1
- package/bin/lib/ark-order-facts.mjs +410 -15
- package/bin/lib/ark-order-invariants.mjs +51 -9
- package/bin/lib/ark-order-sensors.mjs +28 -101
- package/bin/lib/ark-order-types.mjs +2 -0
- package/bin/lib/ark-run-doctor.mjs +14 -0
- package/bin/lib/ark-run-facts.mjs +434 -11
- package/bin/lib/ark-run-sensors.mjs +5 -3
- package/bin/lib/arkgate-pins.mjs +91 -0
- package/bin/lib/arkrules-sensors.mjs +50 -249
- package/bin/lib/check-args.mjs +23 -1
- package/bin/lib/ci-and-commands.mjs +16 -6
- package/bin/lib/class-source-scan.mjs +479 -0
- package/bin/lib/codex-home.mjs +4 -2
- package/bin/lib/config-contract-slices.mjs +701 -0
- package/bin/lib/config-contract.mjs +5 -493
- package/bin/lib/config-warnings.mjs +32 -0
- package/bin/lib/dashboard-cli.mjs +62 -0
- package/bin/lib/design-delta.mjs +1 -1
- package/bin/lib/diagnostic-catalog.mjs +16 -9
- package/bin/lib/doctor-advisories.mjs +25 -1
- package/bin/lib/doctor-next-actions.mjs +17 -2
- package/bin/lib/doctor-plan.mjs +6 -8
- package/bin/lib/effective-contract-load.mjs +121 -59
- package/bin/lib/enforcement-profiles.mjs +40 -4
- package/bin/lib/first-run-help.mjs +3 -2
- package/bin/lib/flat-parent-importers.mjs +137 -0
- package/bin/lib/flat-parent-pilot.mjs +40 -100
- package/bin/lib/gate-files.mjs +29 -2
- package/bin/lib/git-change-scope.mjs +109 -0
- package/bin/lib/github-enforcement.mjs +1 -1
- package/bin/lib/hook-templates.mjs +18 -16
- package/bin/lib/host-support-matrix.mjs +3 -1
- package/bin/lib/import-resolve.mjs +13 -1
- package/bin/lib/install-migrate.mjs +50 -73
- package/bin/lib/invariant-coverage.mjs +59 -11
- package/bin/lib/mcp-adoption.mjs +9 -1
- package/bin/lib/mcp-hook-payload.mjs +401 -61
- package/bin/lib/package-manager.mjs +59 -1
- package/bin/lib/passthrough-commands.mjs +83 -0
- package/bin/lib/persistence-write-hint.mjs +81 -0
- package/bin/lib/pin-dependent-gates.mjs +117 -0
- package/bin/lib/policy-delta-io.mjs +168 -10
- package/bin/lib/prepare-change.mjs +120 -6
- package/bin/lib/prepare-write.mjs +1 -0
- package/bin/lib/presets.mjs +3 -5
- package/bin/lib/remediation.mjs +23 -4
- package/bin/lib/resolved-candidate-facts.mjs +315 -55
- package/bin/lib/rules-inventory.mjs +22 -3
- package/bin/lib/rules-under-contract.mjs +179 -5
- package/bin/lib/scan-files.mjs +32 -0
- package/bin/lib/snippet-analysis.mjs +140 -6
- package/bin/lib/source-policy.mjs +34 -0
- package/bin/lib/stable-hash.mjs +90 -0
- package/bin/lib/start-install-recovery.mjs +71 -1
- package/bin/lib/start-preview.mjs +30 -0
- package/bin/lib/status-command.mjs +33 -4
- package/bin/lib/status-manifest.mjs +32 -4
- package/bin/lib/team-parliament-io.mjs +77 -75
- package/bin/lib/team-parliament.mjs +6 -1
- package/bin/lib/write-path-capabilities.mjs +4 -2
- package/dist/chunk-A5EIY3HI.cjs +5 -0
- package/dist/chunk-MBXCFLO4.js +16 -0
- package/dist/chunk-RNQHRDCQ.cjs +16 -0
- package/dist/chunk-SVSQVGFJ.js +5 -0
- package/dist/{configTypes-Bbf_MFGe.d.ts → configTypes-BJbaeoj4.d.cts} +18 -3
- package/dist/configTypes-BJbaeoj4.d.ts +246 -0
- package/dist/eslint/index.cjs +17 -4
- package/dist/eslint/index.d.cts +359 -0
- package/dist/eslint/index.d.ts +130 -156
- package/dist/eslint/index.js +10 -4
- package/dist/index.cjs +35 -34
- package/dist/index.d.cts +5475 -0
- package/dist/index.d.ts +3312 -299
- package/dist/index.js +35 -34
- package/dist/inspectorListen-6DQVJ4DC.js +1 -0
- package/dist/inspectorListen-KGMIQ2TF.cjs +1 -0
- package/dist/nestjs/index.cjs +1 -18
- package/dist/nestjs/index.d.cts +22 -0
- package/dist/nestjs/index.d.ts +1 -3
- package/dist/nestjs/index.js +1 -18
- package/dist/order/index.cjs +1 -1
- package/dist/order/index.d.cts +155 -0
- package/dist/order/index.d.ts +15 -3
- package/dist/order/index.js +1 -1
- package/dist/runtime/index.cjs +13 -30
- package/dist/{diagnosticCatalog-35mrwAHe.d.ts → runtime/index.d.cts} +804 -290
- package/dist/runtime/index.d.ts +2678 -108
- package/dist/runtime/index.js +13 -30
- package/dist/{types-Bdj32QwA.d.ts → types-DRinG-vT.d.cts} +576 -140
- package/dist/types-DRinG-vT.d.ts +1792 -0
- package/docs/README.md +2 -1
- package/docs/agent-guide.md +84 -15
- package/docs/ai-gates.md +160 -26
- package/docs/arkorder.md +32 -15
- package/docs/brownfield-adoption.md +5 -1
- package/docs/configuration.md +196 -26
- package/docs/develop.md +2 -1
- package/docs/diagnostics.md +96 -19
- package/docs/package-surface.md +31 -8
- package/docs/product-voice.md +1 -1
- package/package.json +59 -18
- package/schemas/ark.analysis-result.schema.json +15 -0
- package/schemas/ark.config.schema.json +47 -10
- package/schemas/ark.resolved-candidate-facts.schema.json +1 -1
- package/schemas/ark.status-manifest.schema.json +22 -0
- package/server.json +3 -9
- package/templates/agent-skills/README.md +1 -1
- package/templates/agent-skills/ark-adopt/SKILL.md +4 -1
- package/templates/agent-skills/ark-order/SKILL.md +4 -2
- package/templates/agent-skills/ark-runtime/SKILL.md +6 -1
- package/templates/arkrules/PersistenceAdapters.json +1 -1
- package/templates/arkrules/PresentationAdapters.json +1 -1
- package/templates/skills/ark-adopt.md +4 -1
- package/templates/skills/ark-order.md +4 -2
- package/templates/skills/ark-runtime.md +6 -1
- package/dist/types-Ik_OakcI.d.ts +0 -183
package/dist/order/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var a=(e,r)=>A(e,"name",{value:r,configurable:!0});var V=(e,r)=>{for(var n in r)A(e,n,{get:r[n],enumerable:!0})},W=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of G(r))!q.call(e,o)&&o!==n&&A(e,o,{get:()=>r[o],enumerable:!(s=J(r,o))||s.enumerable});return e};var Q=e=>W(A({},"__esModule",{value:!0}),e);var ce={};V(ce,{ArkOrderError:()=>i,CAPACITY_OPS:()=>S,DEFAULT_MAX_XI_KEYS:()=>f,createMemoryReleaseStore:()=>z,createOrderPlane:()=>U,hashOf:()=>m,hashReleasePayload:()=>m,ingestTravelAction:()=>C});module.exports=Q(ce);var i=class extends Error{static{a(this,"ArkOrderError")}code;constructor(r,n){super(n),this.name="ArkOrderError",this.code=r}};var f=7;var S=["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")}`}a(y,"deterministicHash");function R(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(R).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(n=>`${JSON.stringify(n)}:${R(r[n])}`).join(",")}}`}a(R,"stableSerialize");function C(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}a(C,"ingestTravelAction");var Z=["update","patch","set","mutate"];function j(e){return Z.includes(e)}a(j,"isForbiddenPlaneMethod");function ee(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}a(ee,"isPrimitive");function h(e,r){let n=Object.keys(e);if(n.length===0&&r==="\u03BE")throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let o of n.sort()){let t=e[o];if(!ee(t))throw new i("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(o)} is not a slow primitive (nested values are microstate)`);s[o]=t}return Object.freeze(s)}a(h,"freezeRecord");function k(e,r){let n=Object.keys(e).length;if(n===0)throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(n>r)throw new i("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${n} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}a(k,"assertXiKeyCap");function b(e,r){if(!r)return;let n=r.properties??{},s=r.additionalProperties!==!1;for(let o of Object.keys(e)){let t=n[o];if(!t){if(!s)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(o)} is not in xiSchema.properties`);continue}if(t.enum&&!t.enum.some(l=>l===e[o]))throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(o)} value is not in enum`);if(t.type==="null"&&e[o]!==null)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(o)} must be null`);if(t.type&&t.type!=="null"&&typeof e[o]!==t.type)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(o)} must be ${t.type}`)}}a(b,"assertXiSchema");function v(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}a(v,"catalogDigestFor");function m(e,r,n){let s=v(e,n);return s!==void 0?y(R({xi:e,sigma:r,catalogDigest:s})):y(R({xi:e,sigma:r}))}a(m,"hashReleasePayload");function _(e,r){let n=v(e,r);return n!==void 0?y(R({xi:e,catalogDigest:n})):y(R({xi:e}))}a(_,"hashXiIdentity");function O(e){return y(R({sigma:e}))}a(O,"hashSigmaIdentity");function M(e,r){return R(e)===R(r)}a(M,"xiRecordsEqual");function N(e,r){if(e&&!M(e.xi,r))throw new i("ARKORDER_UNVALVED_RELEASE","\u03BE is frozen; change the pattern with proposeRelease then apply(ProposeResult)")}a(N,"assertUnvalvedRelease");function w(e){k(e.xi,e.maxXiKeys);let r=h(e.xi,"\u03BE");I(r),b(r,e.xiSchema);let n=h(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:m(r,n,e.catalogDigest),xiHash:_(r,e.catalogDigest),sigmaHash:O(n),xi:r,sigma:n,releasedAt:e.now})}a(w,"createFrozenRelease");function H(e){let r=h(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:m(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:O(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}a(H,"refreshSigmaRecord");var re=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;function I(e){for(let r of Object.keys(e))if(re.test(r))throw new i("ARKORDER_XI_TTL",`\u03BE key ${JSON.stringify(r)} is a freshness field; TTL belongs on \u03C3, never on \u03BE`)}a(I,"assertXiHasNoTtl");function P(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 i("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}a(P,"assertInformationBudget");function F(e){if(e.maxAgeMs===void 0)return;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}let n=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof n=="number"&&e.now-n>e.maxAgeMs)throw new i("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}a(F,"assertSigmaFresh");function X(e){return y(R({kind:e.kind,payload:e.payload??null}))}a(X,"fieldEventIdentity");function te(e,r){return{event:e,xiHash:r,eventId:X(e)}}a(te,"bindResidual");var ne=new Set(S);function oe(e){return typeof e=="string"&&ne.has(e)}a(oe,"isCapacityOp");function T(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}a(T,"numericLeaf");function ae(e,r,n){return r==="lte"?e<=n:r==="lt"?e<n:r==="gte"?e>=n:e>n}a(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)}a(x,"packHasFunction");function se(e,r,n){let s=n.capacity??[];for(let o of s){if(x(o)||!oe(o.op))return"pack";if(o.kind!==e.kind)continue;let t=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?T(e.payload[o.payloadKey]):void 0,l=T(r[o.sigmaKey]);if(t===void 0||l===void 0)return"pack";if(!ae(t,o.op,l))return"capacity"}return"ok"}a(se,"evaluateCapacity");function L(e,r,n=[],s="",o=Object.freeze({})){let t=r.kind,l=te(r,s);for(let d of n){if(x(d.capacity)||x(d.escalateKinds))return{...l,kind:"hold",reasonCode:"pack",reason:`pack ${d.id} is not data-only; user predicates are forbidden`};if(d.escalateKinds?.includes(t)){let g=d.escalateTarget??"human";return{...l,kind:"escalate_up",reasonCode:"pack",reason:`pack ${d.id} slaves kind ${JSON.stringify(t)} to a pattern change`,target:g}}}if(!e.allowedKinds.includes(t))return{...l,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(t)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let d of n){let g=se(r,o,d);if(g!=="ok")return{...l,kind:"hold",reasonCode:g,reason:g==="capacity"?`pack ${d.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${d.id} capacity is not numeric data`}}return{...l,kind:"absorb"}}a(L,"classifyIngest");function B(e,r){let n=new Set(e.allowedKinds),s=new Set(r.allowedKinds),o=new Set;for(let t of n)s.has(t)||o.add(t);for(let t of s)n.has(t)||o.add(t);for(let t of r.invalidated)o.add(t);return{blastRadius:[...o].sort(),invalidations:[...r.invalidated].sort()}}a(B,"blastRadiusOf");function $(e){let r={...e.current.xi};for(let[d,g]of Object.entries(e.delta)){if(g===void 0){delete r[d];continue}r[d]=g}let n=w({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(n.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),o=e.projector(n,n.sigma),{blastRadius:t,invalidations:l}=B(s,o);if(t.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{nextXi:n.xi,blastRadius:t,invalidations:l}}a($,"proposePatternChange");function Y(e){let r=w({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(M(r.xi,e.current.xi))throw new i("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let n=e.projector(e.current,e.current.sigma),s=e.projector(r,r.sigma),{blastRadius:o}=B(n,s);if(o.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return r}a(Y,"applyProposedRelease");function U(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,n=e.packs??[],s=e.clocks??{now(){return Date.now()}},o=e.store,t=o?.load()??null,l=t?.version??0,d=e.catalogDigest;function g(c){return t=c,l=c.version,o?.save(c),c}a(g,"persist");function u(){if(!t)throw new i("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return t}a(u,"requireCurrent");let D={release(c,p){return t&&N(t,h(c,"\u03BE")),g(w({xi:c,sigma:p,version:l+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:d}))},project(){let c=u(),p=e.projector(c,c.sigma);return P(p,e.informationBudget),p},ingest(c){let p=u();try{F({sigma:p.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:p.releasedAt})}catch(E){if(E instanceof i&&E.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:c,xiHash:p.xiHash,eventId:X(c),reasonCode:"stale-sigma",reason:E.message};throw E}let K=e.projector(p,p.sigma);return P(K,e.informationBudget),L(K,c,n,p.xiHash,p.sigma)},proposeRelease(c){return $({current:u(),delta:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:d})},apply(c){return g(Y({current:u(),proposal:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:d}))},refreshSigma(c){return g(H({current:u(),sigma:c,now:s.now(),catalogDigest:d}))},restore(c){return g(ie(c,r,e.xiSchema,d))},current(){return t}};for(let c of["update","patch","set","mutate"])Object.defineProperty(D,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(D)}a(U,"createOrderPlane");function ie(e,r,n,s){let o=a(()=>new i("ARKORDER_SCHEMA","restore() requires a frozen Release; hash is the identity (not durable, not K01)"),"closed");if(e===null||typeof e!="object"||Array.isArray(e))throw o();let t=e;if(!Object.isFrozen(t)||!t.xi||typeof t.xi!="object"||Array.isArray(t.xi)||!Object.isFrozen(t.xi)||!t.sigma||typeof t.sigma!="object"||Array.isArray(t.sigma)||!Object.isFrozen(t.sigma)||typeof t.version!="number"||!Number.isInteger(t.version)||t.version<1||typeof t.hash!="string"||t.hash.length===0||typeof t.xiHash!="string"||typeof t.sigmaHash!="string"||typeof t.releasedAt!="number"||!Number.isFinite(t.releasedAt))throw o();try{k(t.xi,r),I(t.xi),b(t.xi,n)}catch(u){throw u instanceof i?u:o()}let l=m(t.xi,t.sigma,s),d=_(t.xi,s),g=O(t.sigma);if(t.hash!==l||t.xiHash!==d||t.sigmaHash!==g)throw o();return t}a(ie,"assertRestorableRelease");function z(e){let r=e??null;return{load(){return r},save(n){r=n}}}a(z,"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 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});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArkOrder vocabulary (ADR 0027–0030). Runtime constants plus types.
|
|
3
|
+
* Haken: a few slow keys (ξ) slave derived fast state (s).
|
|
4
|
+
* The public module `arkgate/order` is runtime (`createOrderPlane`).
|
|
5
|
+
*/
|
|
6
|
+
declare const DEFAULT_MAX_XI_KEYS = 7;
|
|
7
|
+
type XiPrimitive = string | number | boolean | null;
|
|
8
|
+
type XiRecord = Readonly<Record<string, XiPrimitive>>;
|
|
9
|
+
type SigmaRecord = Readonly<Record<string, XiPrimitive>>;
|
|
10
|
+
type FieldEvent = {
|
|
11
|
+
readonly kind: string;
|
|
12
|
+
readonly payload?: Readonly<Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
type Release = {
|
|
15
|
+
readonly version: number;
|
|
16
|
+
/** Combined ξ+σ fingerprint. 4.8.x compatible when no catalog digest is mixed in. */
|
|
17
|
+
readonly hash: string;
|
|
18
|
+
/** ξ identity. Saldo / clock refresh must not change this. */
|
|
19
|
+
readonly xiHash: string;
|
|
20
|
+
/** σ stamp. Independent of xiHash. */
|
|
21
|
+
readonly sigmaHash: string;
|
|
22
|
+
readonly xi: XiRecord;
|
|
23
|
+
readonly sigma: SigmaRecord;
|
|
24
|
+
readonly releasedAt: number;
|
|
25
|
+
};
|
|
26
|
+
type Projection = {
|
|
27
|
+
readonly allowedKinds: readonly string[];
|
|
28
|
+
readonly invalidated: readonly string[];
|
|
29
|
+
};
|
|
30
|
+
type EscalationTarget = 'human' | 'scale' | 'hold';
|
|
31
|
+
declare const INGEST_REASON_CODES: readonly ["not-in-pattern", "stale-sigma", "pack", "capacity"];
|
|
32
|
+
type IngestReasonCode = (typeof INGEST_REASON_CODES)[number];
|
|
33
|
+
type IngestResidualBind = {
|
|
34
|
+
readonly event: FieldEvent;
|
|
35
|
+
readonly xiHash: string;
|
|
36
|
+
readonly eventId: string;
|
|
37
|
+
};
|
|
38
|
+
type IngestAbsorb = IngestResidualBind & {
|
|
39
|
+
readonly kind: 'absorb';
|
|
40
|
+
};
|
|
41
|
+
type IngestHold = IngestResidualBind & {
|
|
42
|
+
readonly kind: 'hold';
|
|
43
|
+
readonly reasonCode: IngestReasonCode;
|
|
44
|
+
readonly reason?: string;
|
|
45
|
+
};
|
|
46
|
+
type IngestEscalateUp = IngestResidualBind & {
|
|
47
|
+
readonly kind: 'escalate_up';
|
|
48
|
+
readonly reasonCode: IngestReasonCode;
|
|
49
|
+
readonly reason?: string;
|
|
50
|
+
readonly target: EscalationTarget;
|
|
51
|
+
readonly proposed_patch?: {
|
|
52
|
+
readonly nextXi: XiRecord;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** Compatibility name — target remains on escalate_up (ADR 0033 D4 / 0034 D4). */
|
|
56
|
+
type IngestEscalate = IngestEscalateUp;
|
|
57
|
+
type IngestResult = IngestAbsorb | IngestHold | IngestEscalateUp;
|
|
58
|
+
type ProposeResult = {
|
|
59
|
+
readonly nextXi: XiRecord;
|
|
60
|
+
readonly blastRadius: readonly string[];
|
|
61
|
+
readonly invalidations: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* The Release this proposal was computed against (ADR 0034 D1). apply() rejects a
|
|
64
|
+
* proposal whose base is not the current Release (ARKORDER_STALE_PROPOSAL). Plain
|
|
65
|
+
* data, so a proposal survives JSON for human review.
|
|
66
|
+
*/
|
|
67
|
+
readonly baseXiHash: string;
|
|
68
|
+
readonly baseVersion: number;
|
|
69
|
+
};
|
|
70
|
+
type Projector = (release: Release, sigma: SigmaRecord) => Projection;
|
|
71
|
+
declare const CAPACITY_OPS: readonly ["lte", "lt", "gte", "gt"];
|
|
72
|
+
type CapacityOp = (typeof CAPACITY_OPS)[number];
|
|
73
|
+
/** Data-only cap. No user predicates (ADR 0016 / 0034 D5). */
|
|
74
|
+
type CapacityConstraint = {
|
|
75
|
+
readonly kind: string;
|
|
76
|
+
readonly sigmaKey: string;
|
|
77
|
+
readonly payloadKey: string;
|
|
78
|
+
readonly op: CapacityOp;
|
|
79
|
+
};
|
|
80
|
+
type ConstraintPack = {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly escalateKinds?: readonly string[];
|
|
83
|
+
readonly escalateTarget?: EscalationTarget;
|
|
84
|
+
readonly capacity?: readonly CapacityConstraint[];
|
|
85
|
+
};
|
|
86
|
+
/** What a scale may not observe (XP04). Denied kinds never appear in allowedKinds. */
|
|
87
|
+
type InformationBudget = {
|
|
88
|
+
readonly cannotObserve: readonly string[];
|
|
89
|
+
};
|
|
90
|
+
type XiPropertySchema = {
|
|
91
|
+
readonly type?: 'string' | 'number' | 'boolean' | 'null';
|
|
92
|
+
readonly enum?: readonly XiPrimitive[];
|
|
93
|
+
};
|
|
94
|
+
type XiSchema = {
|
|
95
|
+
readonly properties?: Readonly<Record<string, XiPropertySchema>>;
|
|
96
|
+
readonly additionalProperties?: boolean;
|
|
97
|
+
};
|
|
98
|
+
type InjectedClock = {
|
|
99
|
+
now(): number;
|
|
100
|
+
};
|
|
101
|
+
type ArkOrderErrorCode = 'ARKORDER_EMPTY_XI' | 'ARKORDER_TOO_MANY_PARAMS' | 'ARKORDER_NESTED_XI' | 'ARKORDER_SCHEMA' | 'ARKORDER_NO_RELEASE' | 'ARKORDER_EMPTY_BLAST' | 'ARKORDER_FORBIDDEN_METHOD' | 'ARKORDER_UNKNOWN_KEY' | 'ARKORDER_INFORMATION_BUDGET' | 'ARKORDER_XI_TTL' | 'ARKORDER_STALE_SIGMA' | 'ARKORDER_UNVALVED_RELEASE' | 'ARKORDER_STALE_PROPOSAL';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Injected ReleaseStore port (ADR 0034 D8). In-memory default is not durable.
|
|
105
|
+
* Does not close K01.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
type ReleaseStore = {
|
|
109
|
+
load(): Release | null;
|
|
110
|
+
save(release: Release): void;
|
|
111
|
+
};
|
|
112
|
+
declare function createMemoryReleaseStore(initial?: Release | null): ReleaseStore;
|
|
113
|
+
|
|
114
|
+
type CreateOrderPlaneOptions = {
|
|
115
|
+
projector: Projector;
|
|
116
|
+
xiSchema?: XiSchema;
|
|
117
|
+
maxXiKeys?: number;
|
|
118
|
+
clocks?: InjectedClock;
|
|
119
|
+
packs?: readonly ConstraintPack[];
|
|
120
|
+
informationBudget?: InformationBudget;
|
|
121
|
+
sigmaMaxAgeMs?: number;
|
|
122
|
+
/** Injected. Default is process-local memory — not durable, not K01. */
|
|
123
|
+
store?: ReleaseStore;
|
|
124
|
+
/** Optional catalog digest keyed by ξ.catalogReleaseId. SKU set does not enter the hash. */
|
|
125
|
+
catalogDigest?: string;
|
|
126
|
+
};
|
|
127
|
+
type OrderPlane = {
|
|
128
|
+
release(xi: Record<string, unknown>, sigma?: Record<string, unknown>): Release;
|
|
129
|
+
project(): Projection;
|
|
130
|
+
ingest(event: FieldEvent): IngestResult;
|
|
131
|
+
proposeRelease(delta: Record<string, unknown>): ProposeResult;
|
|
132
|
+
apply(proposal: ProposeResult): Release;
|
|
133
|
+
refreshSigma(sigma: Record<string, unknown>): Release;
|
|
134
|
+
/**
|
|
135
|
+
* Reinstall a validated Release (frozen or JSON-deserialized; hash is identity).
|
|
136
|
+
* On a live plane it never changes ξ and accepts only the current version or the
|
|
137
|
+
* next one (no rollback, no jump) — a pattern change is proposeRelease then apply.
|
|
138
|
+
* A freeze time after the plane clock fails closed. Not durable; does not close K01.
|
|
139
|
+
*/
|
|
140
|
+
restore(release: Release): Release;
|
|
141
|
+
current(): Release | null;
|
|
142
|
+
};
|
|
143
|
+
declare function createOrderPlane(options: CreateOrderPlaneOptions): OrderPlane;
|
|
144
|
+
|
|
145
|
+
/** Domain error for Haken plane fail-closed paths. Not a gate diagnostic. */
|
|
146
|
+
declare class ArkOrderError extends Error {
|
|
147
|
+
readonly code: ArkOrderErrorCode;
|
|
148
|
+
constructor(code: ArkOrderErrorCode, message: string);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** D7: consumer still owns handlers — this only names the travel verb. */
|
|
152
|
+
declare function ingestTravelAction(residual: IngestResult): 'send' | 'raises' | 'none';
|
|
153
|
+
declare function hashReleasePayload(xi: XiRecord, sigma: SigmaRecord, catalogDigest?: string): string;
|
|
154
|
+
|
|
155
|
+
export { ArkOrderError, type ArkOrderErrorCode, CAPACITY_OPS, type CapacityConstraint, type CapacityOp, type ConstraintPack, type CreateOrderPlaneOptions, DEFAULT_MAX_XI_KEYS, type EscalationTarget, type FieldEvent, type InformationBudget, type IngestAbsorb, type IngestEscalate, type IngestEscalateUp, type IngestHold, type IngestReasonCode, type IngestResult, type InjectedClock, type OrderPlane, type Projection, type Projector, type ProposeResult, type Release, type ReleaseStore, type SigmaRecord, type XiPrimitive, type XiPropertySchema, type XiRecord, type XiSchema, createMemoryReleaseStore, createOrderPlane, hashReleasePayload as hashOf, hashReleasePayload, ingestTravelAction };
|
package/dist/order/index.d.ts
CHANGED
|
@@ -59,6 +59,13 @@ type ProposeResult = {
|
|
|
59
59
|
readonly nextXi: XiRecord;
|
|
60
60
|
readonly blastRadius: readonly string[];
|
|
61
61
|
readonly invalidations: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* The Release this proposal was computed against (ADR 0034 D1). apply() rejects a
|
|
64
|
+
* proposal whose base is not the current Release (ARKORDER_STALE_PROPOSAL). Plain
|
|
65
|
+
* data, so a proposal survives JSON for human review.
|
|
66
|
+
*/
|
|
67
|
+
readonly baseXiHash: string;
|
|
68
|
+
readonly baseVersion: number;
|
|
62
69
|
};
|
|
63
70
|
type Projector = (release: Release, sigma: SigmaRecord) => Projection;
|
|
64
71
|
declare const CAPACITY_OPS: readonly ["lte", "lt", "gte", "gt"];
|
|
@@ -91,7 +98,7 @@ type XiSchema = {
|
|
|
91
98
|
type InjectedClock = {
|
|
92
99
|
now(): number;
|
|
93
100
|
};
|
|
94
|
-
type ArkOrderErrorCode = 'ARKORDER_EMPTY_XI' | 'ARKORDER_TOO_MANY_PARAMS' | 'ARKORDER_NESTED_XI' | 'ARKORDER_SCHEMA' | 'ARKORDER_NO_RELEASE' | 'ARKORDER_EMPTY_BLAST' | 'ARKORDER_FORBIDDEN_METHOD' | 'ARKORDER_UNKNOWN_KEY' | 'ARKORDER_INFORMATION_BUDGET' | 'ARKORDER_XI_TTL' | 'ARKORDER_STALE_SIGMA' | 'ARKORDER_UNVALVED_RELEASE';
|
|
101
|
+
type ArkOrderErrorCode = 'ARKORDER_EMPTY_XI' | 'ARKORDER_TOO_MANY_PARAMS' | 'ARKORDER_NESTED_XI' | 'ARKORDER_SCHEMA' | 'ARKORDER_NO_RELEASE' | 'ARKORDER_EMPTY_BLAST' | 'ARKORDER_FORBIDDEN_METHOD' | 'ARKORDER_UNKNOWN_KEY' | 'ARKORDER_INFORMATION_BUDGET' | 'ARKORDER_XI_TTL' | 'ARKORDER_STALE_SIGMA' | 'ARKORDER_UNVALVED_RELEASE' | 'ARKORDER_STALE_PROPOSAL';
|
|
95
102
|
|
|
96
103
|
/**
|
|
97
104
|
* Injected ReleaseStore port (ADR 0034 D8). In-memory default is not durable.
|
|
@@ -124,7 +131,12 @@ type OrderPlane = {
|
|
|
124
131
|
proposeRelease(delta: Record<string, unknown>): ProposeResult;
|
|
125
132
|
apply(proposal: ProposeResult): Release;
|
|
126
133
|
refreshSigma(sigma: Record<string, unknown>): Release;
|
|
127
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Reinstall a validated Release (frozen or JSON-deserialized; hash is identity).
|
|
136
|
+
* On a live plane it never changes ξ and accepts only the current version or the
|
|
137
|
+
* next one (no rollback, no jump) — a pattern change is proposeRelease then apply.
|
|
138
|
+
* A freeze time after the plane clock fails closed. Not durable; does not close K01.
|
|
139
|
+
*/
|
|
128
140
|
restore(release: Release): Release;
|
|
129
141
|
current(): Release | null;
|
|
130
142
|
};
|
|
@@ -140,4 +152,4 @@ declare class ArkOrderError extends Error {
|
|
|
140
152
|
declare function ingestTravelAction(residual: IngestResult): 'send' | 'raises' | 'none';
|
|
141
153
|
declare function hashReleasePayload(xi: XiRecord, sigma: SigmaRecord, catalogDigest?: string): string;
|
|
142
154
|
|
|
143
|
-
export { ArkOrderError, CAPACITY_OPS, type CapacityConstraint, type CapacityOp, type ConstraintPack, type CreateOrderPlaneOptions, DEFAULT_MAX_XI_KEYS, type EscalationTarget, type FieldEvent, type InformationBudget, type IngestEscalate, type IngestEscalateUp, type IngestHold, type IngestReasonCode, type IngestResult, type InjectedClock, type OrderPlane, type Projection, type Projector, type ProposeResult, type Release, type ReleaseStore, type SigmaRecord, type XiRecord, type XiSchema, createMemoryReleaseStore, createOrderPlane, hashReleasePayload as hashOf, hashReleasePayload, ingestTravelAction };
|
|
155
|
+
export { ArkOrderError, type ArkOrderErrorCode, CAPACITY_OPS, type CapacityConstraint, type CapacityOp, type ConstraintPack, type CreateOrderPlaneOptions, DEFAULT_MAX_XI_KEYS, type EscalationTarget, type FieldEvent, type InformationBudget, type IngestAbsorb, type IngestEscalate, type IngestEscalateUp, type IngestHold, type IngestReasonCode, type IngestResult, type InjectedClock, type OrderPlane, type Projection, type Projector, type ProposeResult, type Release, type ReleaseStore, type SigmaRecord, type XiPrimitive, type XiPropertySchema, type XiRecord, type XiSchema, createMemoryReleaseStore, createOrderPlane, hashReleasePayload as hashOf, hashReleasePayload, ingestTravelAction };
|
package/dist/order/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $=Object.defineProperty;var o=(e,r)=>$(e,"name",{value:r,configurable:!0});var i=class extends Error{static{o(this,"ArkOrderError")}code;constructor(r,n){super(n),this.name="ArkOrderError",this.code=r}};var E=7;var O=["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 R(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(R).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(n=>`${JSON.stringify(n)}:${R(r[n])}`).join(",")}}`}o(R,"stableSerialize");function Y(e){return e.kind==="absorb"?"send":e.kind==="escalate_up"&&e.target==="human"?"raises":"none"}o(Y,"ingestTravelAction");var U=["update","patch","set","mutate"];function T(e){return U.includes(e)}o(T,"isForbiddenPlaneMethod");function z(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}o(z,"isPrimitive");function f(e,r){let n=Object.keys(e);if(n.length===0&&r==="\u03BE")throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");let s={};for(let a of n.sort()){let t=e[a];if(!z(t))throw new i("ARKORDER_NESTED_XI",`${r} key ${JSON.stringify(a)} is not a slow primitive (nested values are microstate)`);s[a]=t}return Object.freeze(s)}o(f,"freezeRecord");function w(e,r){let n=Object.keys(e).length;if(n===0)throw new i("ARKORDER_EMPTY_XI","\u03BE must name at least one slow mode");if(n>r)throw new i("ARKORDER_TOO_MANY_PARAMS",`\u03BE has ${n} keys; maxXiKeys is ${r} (Haken: few slow modes)`)}o(w,"assertXiKeyCap");function k(e,r){if(!r)return;let n=r.properties??{},s=r.additionalProperties!==!1;for(let a of Object.keys(e)){let t=n[a];if(!t){if(!s)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} is not in xiSchema.properties`);continue}if(t.enum&&!t.enum.some(l=>l===e[a]))throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} value is not in enum`);if(t.type==="null"&&e[a]!==null)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be null`);if(t.type&&t.type!=="null"&&typeof e[a]!==t.type)throw new i("ARKORDER_SCHEMA",`\u03BE key ${JSON.stringify(a)} must be ${t.type}`)}}o(k,"assertXiSchema");function C(e,r){if(typeof r=="string"&&Object.prototype.hasOwnProperty.call(e,"catalogReleaseId"))return r}o(C,"catalogDigestFor");function m(e,r,n){let s=C(e,n);return s!==void 0?y(R({xi:e,sigma:r,catalogDigest:s})):y(R({xi:e,sigma:r}))}o(m,"hashReleasePayload");function b(e,r){let n=C(e,r);return n!==void 0?y(R({xi:e,catalogDigest:n})):y(R({xi:e}))}o(b,"hashXiIdentity");function A(e){return y(R({sigma:e}))}o(A,"hashSigmaIdentity");function j(e,r){return R(e)===R(r)}o(j,"xiRecordsEqual");function v(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(v,"assertUnvalvedRelease");function S(e){w(e.xi,e.maxXiKeys);let r=f(e.xi,"\u03BE");_(r),k(r,e.xiSchema);let n=f(e.sigma??{},"\u03C3");return Object.freeze({version:e.version,hash:m(r,n,e.catalogDigest),xiHash:b(r,e.catalogDigest),sigmaHash:A(n),xi:r,sigma:n,releasedAt:e.now})}o(S,"createFrozenRelease");function M(e){let r=f(e.sigma,"\u03C3");return Object.freeze({version:e.current.version,hash:m(e.current.xi,r,e.catalogDigest),xiHash:e.current.xiHash,sigmaHash:A(r),xi:e.current.xi,sigma:r,releasedAt:e.now})}o(M,"refreshSigmaRecord");var J=/^(ttl|freshUntil|fresh_until|maxAge|max_age)$/i;function _(e){for(let r of Object.keys(e))if(J.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(_,"assertXiHasNoTtl");function I(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 i("ARKORDER_INFORMATION_BUDGET",`projection allows ${JSON.stringify(s)}; informationBudget.cannotObserve forbids it`)}o(I,"assertInformationBudget");function N(e){if(e.maxAgeMs===void 0)return;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}let n=typeof e.sigma.releasedAt=="number"?e.sigma.releasedAt:e.releasedAt;if(typeof n=="number"&&e.now-n>e.maxAgeMs)throw new i("ARKORDER_STALE_SIGMA","\u03C3 is older than sigmaMaxAgeMs; \u03BE does not TTL")}o(N,"assertSigmaFresh");function P(e){return y(R({kind:e.kind,payload:e.payload??null}))}o(P,"fieldEventIdentity");function G(e,r){return{event:e,xiHash:r,eventId:P(e)}}o(G,"bindResidual");var q=new Set(O);function V(e){return typeof e=="string"&&q.has(e)}o(V,"isCapacityOp");function K(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}o(K,"numericLeaf");function W(e,r,n){return r==="lte"?e<=n:r==="lt"?e<n:r==="gte"?e>=n:e>n}o(W,"compareCapacity");function h(e){return typeof e=="function"?!0:e===null||typeof e!="object"?!1:Array.isArray(e)?e.some(h):Object.values(e).some(h)}o(h,"packHasFunction");function Q(e,r,n){let s=n.capacity??[];for(let a of s){if(h(a)||!V(a.op))return"pack";if(a.kind!==e.kind)continue;let t=e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?K(e.payload[a.payloadKey]):void 0,l=K(r[a.sigmaKey]);if(t===void 0||l===void 0)return"pack";if(!W(t,a.op,l))return"capacity"}return"ok"}o(Q,"evaluateCapacity");function H(e,r,n=[],s="",a=Object.freeze({})){let t=r.kind,l=G(r,s);for(let d of n){if(h(d.capacity)||h(d.escalateKinds))return{...l,kind:"hold",reasonCode:"pack",reason:`pack ${d.id} is not data-only; user predicates are forbidden`};if(d.escalateKinds?.includes(t)){let g=d.escalateTarget??"human";return{...l,kind:"escalate_up",reasonCode:"pack",reason:`pack ${d.id} slaves kind ${JSON.stringify(t)} to a pattern change`,target:g}}}if(!e.allowedKinds.includes(t))return{...l,kind:"escalate_up",reasonCode:"not-in-pattern",reason:`kind ${JSON.stringify(t)} is not allowed by h(\u03BE); field cannot rewrite the pattern`,target:"human"};for(let d of n){let g=Q(r,a,d);if(g!=="ok")return{...l,kind:"hold",reasonCode:g,reason:g==="capacity"?`pack ${d.id} capacity ${JSON.stringify(r.kind)} does not hold`:`pack ${d.id} capacity is not numeric data`}}return{...l,kind:"absorb"}}o(H,"classifyIngest");function F(e,r){let n=new Set(e.allowedKinds),s=new Set(r.allowedKinds),a=new Set;for(let t of n)s.has(t)||a.add(t);for(let t of s)n.has(t)||a.add(t);for(let t of r.invalidated)a.add(t);return{blastRadius:[...a].sort(),invalidations:[...r.invalidated].sort()}}o(F,"blastRadiusOf");function L(e){let r={...e.current.xi};for(let[d,g]of Object.entries(e.delta)){if(g===void 0){delete r[d];continue}r[d]=g}let n=S({xi:r,sigma:{...e.current.sigma},version:e.current.version+1,now:e.now,maxXiKeys:e.maxXiKeys,xiSchema:e.xiSchema,catalogDigest:e.catalogDigest});if(n.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),a=e.projector(n,n.sigma),{blastRadius:t,invalidations:l}=F(s,a);if(t.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return{nextXi:n.xi,blastRadius:t,invalidations:l}}o(L,"proposePatternChange");function B(e){let r=S({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(r.xi,e.current.xi))throw new i("ARKORDER_EMPTY_BLAST","delta does not change \u03BE; that is not a pattern change");let n=e.projector(e.current,e.current.sigma),s=e.projector(r,r.sigma),{blastRadius:a}=F(n,s);if(a.length===0)throw new i("ARKORDER_EMPTY_BLAST","pattern change has empty blast radius; that key is not an order parameter");return r}o(B,"applyProposedRelease");function Z(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,n=e.packs??[],s=e.clocks??{now(){return Date.now()}},a=e.store,t=a?.load()??null,l=t?.version??0,d=e.catalogDigest;function g(c){return t=c,l=c.version,a?.save(c),c}o(g,"persist");function u(){if(!t)throw new i("ARKORDER_NO_RELEASE","no pattern is frozen; call release(\u03BE) first");return t}o(u,"requireCurrent");let X={release(c,p){return t&&v(t,f(c,"\u03BE")),g(S({xi:c,sigma:p,version:l+1,now:s.now(),maxXiKeys:r,xiSchema:e.xiSchema,catalogDigest:d}))},project(){let c=u(),p=e.projector(c,c.sigma);return I(p,e.informationBudget),p},ingest(c){let p=u();try{N({sigma:p.sigma,now:s.now(),maxAgeMs:e.sigmaMaxAgeMs,releasedAt:p.releasedAt})}catch(x){if(x instanceof i&&x.code==="ARKORDER_STALE_SIGMA")return{kind:"hold",event:c,xiHash:p.xiHash,eventId:P(c),reasonCode:"stale-sigma",reason:x.message};throw x}let D=e.projector(p,p.sigma);return I(D,e.informationBudget),H(D,c,n,p.xiHash,p.sigma)},proposeRelease(c){return L({current:u(),delta:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:d})},apply(c){return g(B({current:u(),proposal:c,projector:e.projector,maxXiKeys:r,xiSchema:e.xiSchema,now:s.now(),catalogDigest:d}))},refreshSigma(c){return g(M({current:u(),sigma:c,now:s.now(),catalogDigest:d}))},restore(c){return g(ee(c,r,e.xiSchema,d))},current(){return t}};for(let c of["update","patch","set","mutate"])Object.defineProperty(X,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(X)}o(Z,"createOrderPlane");function ee(e,r,n,s){let a=o(()=>new i("ARKORDER_SCHEMA","restore() requires a frozen Release; hash is the identity (not durable, not K01)"),"closed");if(e===null||typeof e!="object"||Array.isArray(e))throw a();let t=e;if(!Object.isFrozen(t)||!t.xi||typeof t.xi!="object"||Array.isArray(t.xi)||!Object.isFrozen(t.xi)||!t.sigma||typeof t.sigma!="object"||Array.isArray(t.sigma)||!Object.isFrozen(t.sigma)||typeof t.version!="number"||!Number.isInteger(t.version)||t.version<1||typeof t.hash!="string"||t.hash.length===0||typeof t.xiHash!="string"||typeof t.sigmaHash!="string"||typeof t.releasedAt!="number"||!Number.isFinite(t.releasedAt))throw a();try{w(t.xi,r),_(t.xi),k(t.xi,n)}catch(u){throw u instanceof i?u:a()}let l=m(t.xi,t.sigma,s),d=b(t.xi,s),g=A(t.sigma);if(t.hash!==l||t.xiHash!==d||t.sigmaHash!==g)throw a();return t}o(ee,"assertRestorableRelease");function re(e){let r=e??null;return{load(){return r},save(n){r=n}}}o(re,"createMemoryReleaseStore");export{i as ArkOrderError,O as CAPACITY_OPS,E as DEFAULT_MAX_XI_KEYS,re as createMemoryReleaseStore,Z as createOrderPlane,m as hashOf,m as hashReleasePayload,Y as ingestTravelAction};
|
|
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};
|