arkgate 4.8.2 → 4.8.3
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 +15 -3
- package/README.md +39 -8
- package/bin/lib/analysis-engine.mjs +6 -6
- package/bin/lib/ark-order-facts.mjs +59 -0
- package/bin/lib/ark-order-sensors.mjs +31 -2
- package/bin/lib/arkrule-file-hints.mjs +6 -2
- package/bin/lib/arkrules-contract.mjs +1 -0
- package/bin/lib/arkrules-sensors.mjs +22 -2
- package/bin/lib/config-extras.mjs +2 -0
- package/bin/lib/diagnostic-catalog.mjs +2 -1
- package/bin/lib/remediation.mjs +9 -1
- package/bin/lib/resolved-candidate-facts.mjs +31 -0
- package/dist/{configTypes-BdCe_gvv.d.ts → configTypes-dNJ2C0yx.d.ts} +5 -0
- package/dist/{diagnosticCatalog-CPzH-MLN.d.ts → diagnosticCatalog-C5GgeyEE.d.ts} +97 -7
- package/dist/eslint/index.cjs +6 -6
- package/dist/eslint/index.d.ts +1 -1
- package/dist/eslint/index.js +6 -6
- package/dist/index.cjs +34 -34
- package/dist/index.d.ts +24 -7
- package/dist/index.js +34 -34
- package/dist/nestjs/index.cjs +5 -5
- package/dist/nestjs/index.d.ts +3 -3
- package/dist/nestjs/index.js +5 -5
- package/dist/runtime/index.cjs +15 -15
- package/dist/runtime/index.d.ts +6 -6
- package/dist/runtime/index.js +15 -15
- package/dist/{types-C9KApBzX.d.ts → types-DeK7SYGC.d.ts} +1 -1
- package/dist/{types-DCSlrRnV.d.ts → types-dK24fDZa.d.ts} +1 -1
- package/docs/README.md +4 -4
- package/docs/configuration.md +12 -8
- package/docs/develop.md +23 -2
- package/docs/diagnostics.md +9 -0
- package/docs/enthusiast/README.md +6 -4
- package/docs/package-surface.md +4 -2
- package/docs/product-voice.md +15 -5
- package/docs/use.md +8 -5
- package/package.json +1 -1
- package/schemas/ark.arkrules.schema.json +1 -0
- package/schemas/ark.config.schema.json +9 -0
- package/schemas/ark.resolved-candidate-facts.schema.json +1 -1
- package/server.json +2 -2
- package/templates/agent-skills/README.md +1 -1
- package/templates/agent-skills/ark-adopt/SKILL.md +8 -3
- package/templates/agent-skills/ark-autopilot/SKILL.md +1 -1
- package/templates/agent-skills/ark-contract/SKILL.md +4 -0
- package/templates/agent-skills/ark-place/SKILL.md +6 -2
- package/templates/arkrules/ApplicationOrchestration.json +6 -0
- package/templates/skills/ark-adopt.md +8 -3
- package/templates/skills/ark-autopilot.md +1 -1
- package/templates/skills/ark-contract.md +4 -0
- package/templates/skills/ark-place.md +6 -2
package/dist/eslint/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var bt=Object.defineProperty;var l=(e,t)=>bt(e,"name",{value:t,configurable:!0});import _ from"fs";import m from"path";var Ae=new Map;function ke(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}l(ke,"escapeLiteral");function W(e){let t="";for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="\\"&&r+1<e.length){let o=e[r+1];if("*?{}[],".includes(o)||o==="\\"){t+="\\"+o,r+=1;continue}t+="/";continue}t+=n}return t}l(W,"normalizeGlobSeparators");function Et(e){let t=0;for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="\\"){r+=1;continue}if(n==="{")t+=1;else if(n==="}"&&(t-=1,t<0))return!1}return t===0}l(Et,"bracesBalanced");function L(e){let t=Ae.get(e);if(t)return t;let r=W(e),n=Et(r),o="",a=0;for(let i=0;i<r.length;i+=1){let c=r[i];c==="\\"&&i+1<r.length?(o+=ke(r[i+1]),i+=1):c==="*"?r[i+1]==="*"?r[i+2]==="/"?(o+="(?:.*/)?",i+=2):(o+=".*",i+=1):o+="[^/]*":c==="?"?o+="[^/]":c==="{"&&n?(o+="(?:",a+=1):c==="}"&&n&&a>0?(o+=")",a-=1):c===","&&n&&a>0?o+="|":o+=ke(c)}let s=new RegExp(`^${o}$`);return Ae.set(e,s),s}l(L,"globToRegExp");function St(e){return W(String(e)).split("/").filter(Boolean).filter(r=>r!=="**"&&r!=="*"&&!r.includes("*")&&!r.includes("?")&&!r.includes("{")&&!r.includes("["))}l(St,"concreteGlobSegments");function Ee(e,t){let r=W(String(e)),n=St(r),o=r.replace(/\*/g,"").length,a=n.length*1e4+o;if(t==null||t==="")return a;let s=String(t).split(/[/\\]/).filter(Boolean);if(n.length===0)return o;let i=0,c=-1;for(let p of n){let d=-1;for(let u=i;u<s.length;u+=1)if(s[u]===p){d=u;break}if(d<0)return a;c=d,i=d+1}return(c+1)*1e6+n.length*1e4+o}l(Ee,"patternSpecificity");function E(e,t){let r=String(e).split(/[/\\]/).join("/"),n,o=-1;for(let a of t??[])if(!(a.exclude??[]).some(s=>L(s).test(r))){for(let s of a.patterns??[])if(L(s).test(r)){let i=Ee(s,r);i>o&&(o=i,n=a.name)}}return n}l(E,"layerForRelativePath");function be(e,t){if(!t?.length)return;let r=String(e).split(/[/\\]/).filter(Boolean),n=new Set(t.map(o=>String(o).toLowerCase()));for(let o=0;o<r.length-1;o+=1)if(n.has(r[o].toLowerCase()))return`${r[o].toLowerCase()}/${r[o+1].toLowerCase()}`}l(be,"sliceIdForPath");function It(e){let t=new Set;for(let r of e??[]){let o=W(String(r)).split("/").filter(Boolean);for(let a=0;a<o.length;a+=1){let s=o[a];if((s==="**"||s==="*")&&a>0){let i=o[a-1];i&&!i.includes("*")&&!i.includes("{")&&!i.includes("}")&&t.add(i)}}}return[...t]}l(It,"inferSliceFoldersFromPatterns");function xt(e,t,r){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(o=>typeof o=="string"&&o.length>0);let n=(r??[]).find(o=>o.name===t);return It(n?.patterns)}l(xt,"resolveSliceFolders");function Nt(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}l(Nt,"peerIsolationMustDeny");function re(e,t,r,n){for(let o of e??[])if(!(o.from!==t||o.to!==r)&&o.allowed===!1){if(o.peerIsolation){let a=n?.fromPath,s=n?.toPath,i=xt(o,t,n?.layers),c=a&&s?be(a,i):void 0,p=a&&s?be(s,i):void 0;if(Nt({fromPath:a,toPath:s,folderCount:i.length,fromSlice:c,toSlice:p}))return o;continue}if(t!==r)return o}}l(re,"findDeniedEdgeRule");function Se(e,t,r,n){return re(e,t,r,n)!==void 0}l(Se,"isEdgeDenied");var _t=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function Ct(e){let t=Array.isArray(e?.exclude)?e.exclude.filter(n=>typeof n=="string"):[];return[...e?.excludeGenerated===!1?[]:_t,...t]}l(Ct,"scanExcludePatterns");function Ie(e,t){let r=String(e).split(/[/\\]/).join("/");return Ct(t).some(n=>L(n).test(r))}l(Ie,"isScanExcludedRelative");var xe=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),vt=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),tn=Object.freeze(Object.keys(vt).sort()),ne=Object.freeze({fs:"filesystem","node:fs":"filesystem","fs/promises":"filesystem","node:fs/promises":"filesystem","fs-extra":"filesystem","graceful-fs":"filesystem",memfs:"filesystem",chokidar:"filesystem",http:"network",https:"network",http2:"network",net:"network",tls:"network",dgram:"network",dns:"network","node:http":"network","node:https":"network","node:http2":"network","node:net":"network","node:tls":"network","node:dgram":"network","node:dns":"network",axios:"network",undici:"network","node-fetch":"network",got:"network",ky:"network",superagent:"network",ws:"network",process:"process","node:process":"process",child_process:"process","node:child_process":"process","@prisma/client":"persistence",prisma:"persistence",pg:"persistence",mysql:"persistence",mysql2:"persistence",mongodb:"persistence",mongoose:"persistence",sqlite3:"persistence","better-sqlite3":"persistence",redis:"persistence",ioredis:"persistence",typeorm:"persistence",knex:"persistence","drizzle-orm":"persistence",sequelize:"persistence",kysely:"persistence","@supabase/supabase-js":"persistence"}),Ot=Object.freeze({process:Object.freeze(["process","node:process"])});function Ne(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let t=ne[e];if(t)return t;let r=e.indexOf("/");if(r<0)return null;let n=e.slice(0,r),o=ne[n];if(o)return o;let a=e.indexOf("/",r+1);return a<0?null:ne[e.slice(0,a)]??null}l(Ne,"capabilityForModuleSpecifier");function oe(e,t){for(let r of t)if(Ot[r]?.includes(e))return r;return null}l(oe,"forbiddenGlobalForModuleSpecifier");function _e(e){if(e?.pure===!0)return[...xe].sort();let r=(e?.capabilities?.deny??[]).filter(n=>xe.includes(n));return[...new Set(r)].sort()}l(_e,"effectiveCapabilityDeny");var K={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},Ce={type:"object",additionalProperties:!1,properties:{mode:{type:"string",enum:["advisory","enforced"],default:"advisory"},compositionRoots:{...K,default:[]},kernelRoots:{...K},managedLayers:{...K,default:[]},requireDeclarations:{type:"boolean",default:!0},ignoreDirectNewForErrors:{type:"boolean",default:!0}}},ve={type:"object",additionalProperties:!1,properties:{mode:{type:"string",enum:["advisory","enforced"],default:"advisory"},planeRoots:{...K,default:[]},managedLayers:{...K,default:[]},maxXiKeys:{type:"integer",minimum:1,default:7}}};function M(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(M,"isObject");function Oe(e){let t=new Set;if(!Array.isArray(e.layers))return t;for(let r of e.layers)M(r)&&typeof r.name=="string"&&r.name.length>0&&t.add(r.name);return t}l(Oe,"declaredLayerNames");function we(e){if(!M(e))return e;let t={mode:e.mode===void 0?"advisory":e.mode,compositionRoots:e.compositionRoots===void 0?[]:e.compositionRoots,managedLayers:e.managedLayers===void 0?[]:e.managedLayers,requireDeclarations:e.requireDeclarations===void 0?!0:e.requireDeclarations};return e.kernelRoots!==void 0&&(t.kernelRoots=e.kernelRoots),e.ignoreDirectNewForErrors!==void 0&&(t.ignoreDirectNewForErrors=e.ignoreDirectNewForErrors),{...e,...t}}l(we,"defaultedArkRun");function Le(e){if(!M(e))return e;let t=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7;return{...e,mode:e.mode===void 0?"advisory":e.mode,planeRoots:e.planeRoots===void 0?[]:e.planeRoots,managedLayers:e.managedLayers===void 0?[]:e.managedLayers,maxXiKeys:t}}l(Le,"defaultedArkOrder");function Te(e,t){let r=e.arkRun;if(r===void 0||!M(r))return;let n=Oe(e),o=r.managedLayers;if(Array.isArray(o)&&o.forEach((a,s)=>{typeof a=="string"&&a.length>0&&!n.has(a)&&t.push({path:`$.arkRun.managedLayers[${s}]`,message:`layer ${JSON.stringify(a)} is not declared in layers[]`})}),r.mode==="enforced"){let a=r.kernelRoots??r.compositionRoots;(!Array.isArray(a)||a.length===0)&&t.push({path:r.kernelRoots!==void 0?"$.arkRun.kernelRoots":"$.arkRun.compositionRoots",message:"ARKRUN_MISSING_ROOT: enforced mode requires at least one kernel root"}),(!Array.isArray(o)||o.length===0)&&t.push({path:"$.arkRun.managedLayers",message:"enforced mode requires at least one managed layer"})}}l(Te,"validateArkRunExtra");function De(e,t){let r=e.arkOrder;if(r===void 0||!M(r))return;let n=Oe(e),o=r.managedLayers;if(Array.isArray(o)&&o.forEach((a,s)=>{typeof a=="string"&&a.length>0&&!n.has(a)&&t.push({path:`$.arkOrder.managedLayers[${s}]`,message:`layer ${JSON.stringify(a)} is not declared in layers[]`})}),r.mode==="enforced"){let a=r.planeRoots;(!Array.isArray(a)||a.length===0)&&t.push({path:"$.arkOrder.planeRoots",message:"ARKORDER_MISSING_PLANE: enforced mode requires at least one plane root"}),(!Array.isArray(o)||o.length===0)&&t.push({path:"$.arkOrder.managedLayers",message:"enforced mode requires at least one managed layer"})}}l(De,"validateArkOrderExtra");var S="1.3",se="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",Fe=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],wt=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function Lt(){let e=[];for(let t of Fe)for(let r of Fe)t===r||wt.has(`${t}->${r}`)||e.push({from:t,to:r,allowed:!1});return e}l(Lt,"createDefaultRules");var Ke=Lt(),ie=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"},{from:"1.1",to:"1.2"},{from:"1.2",to:"1.3"}],I={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},Pe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:se,title:"ArkGate architecture contract",description:"Versioned contract consumed identically by ArkGate CLI, MCP, and ESLint surfaces.",type:"object",additionalProperties:!1,required:["$schema","schemaVersion","include","layers","rules"],properties:{$schema:{type:"string",minLength:1,default:se,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:S,default:S},name:{type:"string",minLength:1},include:{...I,minItems:1,default:["src"]},exclude:{...I,default:[]},excludeGenerated:{type:"boolean",default:!0},frameworkOverlay:{type:"string",minLength:1},layers:{type:"array",default:[],items:{$ref:"#/$defs/layer"}},rules:{type:"array",default:Ke,items:{$ref:"#/$defs/rule"}},cyclePolicy:{type:"string",enum:["strict","soft","framework-soft","off"],default:"strict"},dynamicImportAllowlist:{...I,default:[]},safety:{$ref:"#/$defs/safety",default:{maxTsSuppressions:0,maxAnyCasts:0,allowInMemory:!1,allowDisabledPeerIsolation:!1}},arkRules:{type:"object",additionalProperties:{type:"string",minLength:1},default:{}},arkRun:{$ref:"#/$defs/arkRun"},arkOrder:{$ref:"#/$defs/arkOrder"},stewards:{...I,default:[]}},$defs:{layer:{type:"object",additionalProperties:!1,required:["name","patterns"],properties:{name:{type:"string",minLength:1},patterns:{...I,minItems:1},exclude:I,intentPrefixes:I,description:{type:"string",minLength:1},forbiddenGlobals:I,capabilities:{type:"object",additionalProperties:!1,properties:{deny:{type:"array",uniqueItems:!0,items:{type:"string",enum:["network","filesystem","clock","randomness","environment","process","persistence"]}}}},pure:{type:"boolean"},mayImportInfrastructure:{type:"boolean"},optional:{type:"boolean"},reserved:{type:"boolean"},allowEmpty:{type:"boolean"}}},rule:{type:"object",additionalProperties:!1,required:["from","to","allowed"],properties:{from:{type:"string",minLength:1},to:{type:"string",minLength:1},allowed:{type:"boolean"},message:{type:"string",minLength:1},peerIsolation:{type:"boolean"},sliceFolders:{...I,minItems:1}}},safety:{type:"object",additionalProperties:!1,properties:{maxTsSuppressions:{type:"integer",minimum:0,default:0},maxAnyCasts:{type:"integer",minimum:0,default:0},allowInMemory:{type:"boolean",default:!1},allowDisabledPeerIsolation:{type:"boolean",default:!1}}},arkRun:Ce,arkOrder:ve}},x=class extends Error{static{l(this,"ArkConfigValidationError")}issues;source;constructor(t,r){super(`Invalid ArkGate config (${t}):
|
|
2
|
-
${
|
|
3
|
-
`)}`),this.name="ArkConfigValidationError",this.source=t,this.issues=r}};function Me(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(Me,"isObject");function q(e,t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}l(q,"propertyPath");function T(e){return e===null?"null":Array.isArray(e)?"array":typeof e}l(T,"valueType");function Tt(e,t){let r="#/$defs/";if(e.startsWith(r))return t.$defs[e.slice(r.length)]}l(Tt,"resolveSchemaRef");function $(e,t,r,n,o){if(t.$ref){let a=Tt(t.$ref,n);if(!a){o.push({path:r,message:`schema reference ${t.$ref} cannot be resolved`});return}$(e,a,r,n,o);return}if(t.const!==void 0&&!Object.is(e,t.const)){o.push({path:r,message:`must equal ${JSON.stringify(t.const)}`});return}if(t.enum&&!t.enum.some(a=>Object.is(a,e))){o.push({path:r,message:`must be one of ${t.enum.map(String).join(", ")}`});return}if(t.type==="object"){if(!Me(e)){o.push({path:r,message:`must be an object; received ${T(e)}`});return}let a=t.properties??{};for(let s of t.required??[])e[s]===void 0&&o.push({path:q(r,s),message:"is required"});if(t.additionalProperties===!1)for(let s of Object.keys(e))s in a||o.push({path:q(r,s),message:"unknown field"});else if(t.additionalProperties!==void 0&&t.additionalProperties!==!0&&typeof t.additionalProperties=="object"){let s=t.additionalProperties;for(let i of Object.keys(e))i in a||$(e[i],s,q(r,i),n,o)}for(let[s,i]of Object.entries(a))e[s]!==void 0&&$(e[s],i,q(r,s),n,o);return}if(t.type==="array"){if(!Array.isArray(e)){o.push({path:r,message:`must be an array; received ${T(e)}`});return}if(t.minItems!==void 0&&e.length<t.minItems&&o.push({path:r,message:`must contain at least ${t.minItems} item(s)`}),t.uniqueItems){let a=e.map(s=>JSON.stringify(s));new Set(a).size!==a.length&&o.push({path:r,message:"must not contain duplicate items"})}t.items&&e.forEach((a,s)=>$(a,t.items,`${r}[${s}]`,n,o));return}if(t.type==="string"){if(typeof e!="string"){o.push({path:r,message:`must be a string; received ${T(e)}`});return}t.minLength!==void 0&&e.length<t.minLength&&o.push({path:r,message:`must contain at least ${t.minLength} character(s)`});return}if(t.type==="boolean"){typeof e!="boolean"&&o.push({path:r,message:`must be a boolean; received ${T(e)}`});return}if(t.type==="integer"){if(!Number.isInteger(e)){o.push({path:r,message:`must be an integer; received ${T(e)}`});return}t.minimum!==void 0&&e<t.minimum&&o.push({path:r,message:`must be at least ${t.minimum}`})}}l($,"validateNode");function Dt(e){let t={...e,$schema:e.$schema===void 0?se:e.$schema,schemaVersion:e.schemaVersion===void 0?S:e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?Ke.map(r=>({...r})):e.rules};return e.arkRun!==void 0&&(t.arkRun=we(e.arkRun)),e.arkOrder!==void 0&&(t.arkOrder=Le(e.arkOrder)),t}l(Dt,"defaultedConfig");function Ft(e){return e===S?null:e==="unversioned"?"unversioned":e==="1.0"||e==="1.1"||e==="1.2"?e:null}l(Ft,"migratedFromOf");function Pt(){let e=new Set([S]);for(let t of ie)t.from!=="unversioned"&&e.add(t.from),e.add(t.to);return e}l(Pt,"knownInputVersions");function Kt(e,t="ark.config.json"){if(!Me(e))throw new x(t,[{path:"$",message:`must be an object; received ${T(e)}`}]);let r=Pt(),n=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(n===null)throw new x(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected ${S}`}]);if(n!=="unversioned"&&!r.has(n))throw new x(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected ${S}`}]);let o=n,a={...e},s=0;for(;o!==S&&s<ie.length+1;){s+=1;let i=ie.find(c=>c.from===o);if(!i)throw new x(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(o)}; expected ${S}`}]);o=i.to,a.schemaVersion=o}if(o!==S)throw new x(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected ${S}`}]);return{candidate:Dt(a),migratedFrom:Ft(n)}}l(Kt,"migrateArkConfig");function Mt(e,t="ark.config.json"){let{candidate:r,migratedFrom:n}=Kt(e,t),o=[];if($(r,Pe,"$",Pe,o),Te(r,o),De(r,o),o.length>0)throw new x(t,o);return{config:r,migratedFrom:n}}l(Mt,"loadArkConfigContract");function $e(e,t="ark.config.json"){let r;try{r=JSON.parse(e)}catch(n){throw new x(t,[{path:"$",message:`invalid JSON: ${n instanceof Error?n.message:String(n)}`}])}return Mt(r,t)}l($e,"parseArkConfigJson");var $t=/(^|\/)(constants|types|enums|shared-types|shared\/(?:types|constants)|test-projects)(\/|\.|$)|(?:^|\/)[^/]*(?:constants|types)(?:\.[cm]?[jt]sx?)?$/i,Ut=/(^|\/)(?:kernel(?:\/|$)|events?(?:\/|\.|$)|bootstrap(?:\.[cm]?[jt]sx?)?$|emitter(?:\.[cm]?[jt]sx?)?$)|(?:^|\/)(?:intents?|publish)(?:\/|\.|$)/i,Ht=/(use-?cases?|usecases?|application|orchestrat|services?|handlers?)(\/|\.|$)/i;function jt(e,t){let r=String(e??"").replace(/\\/g,"/").trim(),n=String(t?.fromLayer??""),o=String(t?.toLayer??"");return $t.test(r)?"pure-shared":n==="PersistenceAdapters"&&(Ut.test(r)||/events?|intents?|kernel|bootstrap/i.test(`${o} ${r}`))?"kernel-emit":Ht.test(r)||(n==="DomainModel"||n==="ApplicationOrchestration")&&o==="PersistenceAdapters"?"use-case":"unknown"}l(jt,"classifyLayerImportKind");function Vt(e){if(e.typeOnly||e.targetTypeOnlyExports||e.namedBindingsTypeOnly)return"Move the referenced type to a mutually allowed layer, use `import type`, then preflight again.";if(e.peerIsolation)return"Extract the shared dependency to a shared layer, test at the public interface, then preflight again.";let t=jt(typeof e.target=="string"?e.target:"",{fromLayer:typeof e.fromLayer=="string"?e.fromLayer:void 0,toLayer:typeof e.toLayer=="string"?e.toLayer:void 0});return t==="pure-shared"?"Adopt the imported constants/types/pure module into DomainModel or SharedKernel (do not inject a port). Then preflight again.":t==="kernel-emit"?"Persistence must not emit. Inject a port or move the event map to SharedTypes; do not import kernel/events/bootstrap from a repository. Then preflight again.":t==="use-case"||e.portProofEligible?`Define a port in ${e.fromLayer??"the source layer"}, inject the ${e.toLayer??"outer-layer"} implementation, test at the public interface, then preflight again.`:"Classify the import: if it is constants/types/pure, adopt into DomainModel or SharedKernel; define a port only if the target is a real use-case. Then preflight again."}l(Vt,"layerImportNextAction");function Bt(e){return typeof e.target=="string"&&e.target.trim().length>0?e.target.trim():void 0}l(Bt,"arkRunCallSiteName");function Gt(e){let t=Bt(e),r=typeof e.fromLayer=="string"&&e.fromLayer.length>0?e.fromLayer:void 0;switch(e.ruleId){case"ARKRUN_MISSING_ROOT":return t?`Import createStrictArkKernel from arkgate/runtime and call it in composition root ${t} listed in arkRun.compositionRoots, then preflight again.`:"Import createStrictArkKernel from arkgate/runtime (same npm package; @arkgate/runtime is deprecated) and call it in a composition root listed in arkRun.compositionRoots, then preflight again. Never mechanical-safe \u2014 factory placement is a design decision.";case"ARKRUN_KERNEL_IN_DOMAIN":return t?`Move the kernel import of ${t} out of ${r??"the Domain-role layer"} into a composition root or adapter. Import from arkgate/runtime, then preflight again.`:"Move the kernel import out of the Domain-role layer into a composition root or adapter. Import from arkgate/runtime (same npm package; @arkgate/runtime is deprecated), then preflight again. Never mechanical-safe.";case"ARKRUN_DIRECT_NEW":return t?`Resolve ${t} from the kernel instead of constructing it with new, then preflight again.`:"Resolve the type from the kernel instead of constructing it with new, then preflight again. Never mechanical-safe \u2014 rewiring construction is a design decision.";case"ARKRUN_UNDECLARED_EMIT":return t?`Add ${t} to raises or sends on the managed component, then preflight again.`:"Add the existing call-site name to raises or sends on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new emit stays judgment.";case"ARKRUN_UNDECLARED_HANDLE":return t?`Add ${t} to reactsTo on the managed component, then preflight again.`:"Add the existing call-site name to reactsTo on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new handle stays judgment.";case"ARKRUN_UNDECLARED_DEPEND":return t?`Add ${t} to uses on the managed component, then preflight again.`:"Add the existing call-site name to uses on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new depend stays judgment.";case"ARKRUN_TRANSPORT_BYPASS":return t?`Send through the ArkRun kernel transport instead of importing ${t}, then preflight again.`:"Send through the ArkRun kernel transport instead of importing that broker or emitter, then preflight again. Never mechanical-safe \u2014 homemade buses stay judgment.";default:return`Resolve ${typeof e.ruleId=="string"&&e.ruleId.length>0?e.ruleId:"ARK_UNKNOWN"} without weakening ark.config.json, then run Ark again.`}}l(Gt,"arkRunNextAction");function D(e){switch(e.ruleId){case"LAYER_IMPORT_VIOLATION":return Vt(e);case"FORBIDDEN_GLOBAL":return`Inject ${e.target??"the capability"} through a port, test at the public interface, then preflight again.`;case"CAPABILITY_VIOLATION":return`Define a ${String(e.capability??"capability")} port in ${e.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;case"CIRCULAR_DEPENDENCY":return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";case"RAW_EVENT_PUBLISH":return"Publish through a registered intent creator, then run Ark again.";case"PUBLISH_MISSING_SOURCE":return"Add metadata.source to the publish call, then run Ark again.";case"ARKRULE_STRUCTURE":case"ARKRULE_INVARIANT":case"INVARIANT_UNCOVERED":return`Fix the structure or invariant for ${typeof e.arkruleId=="string"&&e.arkruleId.length>0?e.arkruleId:"the ArkRule"} (declared in ${typeof e.arkruleSource=="string"&&e.arkruleSource.length>0?e.arkruleSource:"arkrules/<Layer>.json"}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`;case"ARKRUN_MISSING_ROOT":case"ARKRUN_KERNEL_IN_DOMAIN":case"ARKRUN_DIRECT_NEW":case"ARKRUN_UNDECLARED_EMIT":case"ARKRUN_UNDECLARED_HANDLE":case"ARKRUN_UNDECLARED_DEPEND":case"ARKRUN_TRANSPORT_BYPASS":return Gt(e);case"ARKORDER_MISSING_PLANE":return typeof e.target=="string"&&e.target.length>0?`Import createOrderPlane from arkgate/order and call it in plane root ${e.target} listed in arkOrder.planeRoots, then preflight again.`:"Import createOrderPlane from arkgate/order and call it in a plane root listed in arkOrder.planeRoots, then preflight again. Never mechanical-safe \u2014 factory placement is a design decision.";case"ARKORDER_KERNEL_IN_DOMAIN":return"Move the arkgate/order import out of the Domain-role layer into a plane root or adapter, then preflight again. Never mechanical-safe.";case"ARKORDER_GENERIC_UPDATE":return"Use release() to freeze \u03BE or proposeRelease() for a pattern change with blast radius, then preflight again. Never mechanical-safe.";case"ARKORDER_TOO_MANY_PARAMS":return"Cut \u03BE to the slow keys that actually slave the rest, then preflight again. Never mechanical-safe.";case"ARKORDER_INGEST_WRITES_XI":return"Keep ingest results as absorb/escalate only. Change \u03BE with proposeRelease + release. Never mechanical-safe.";default:return typeof e.ruleId=="string"&&e.ruleId.startsWith("ARKRULE_")?`Fix the ArkRule ${typeof e.arkruleId=="string"?e.arkruleId:e.ruleId}, then preflight again.`:`Resolve ${typeof e.ruleId=="string"&&e.ruleId.length>0?e.ruleId:"ARK_UNKNOWN"} without weakening ark.config.json, then run Ark again.`}}l(D,"deterministicNextAction");var zt="docs/diagnostics.md";function R(e){return typeof e=="string"&&e.length>0?e:void 0}l(R,"text");function Ue(e,t){return Number.isInteger(e)&&Number(e)>0?Number(e):t}l(Ue,"positiveInteger");function Wt(e){let t=typeof e.ruleId=="string"?e.ruleId:typeof e.code=="string"?e.code:void 0,r=typeof e.file=="string"?e.file:void 0,n=typeof e.fromLayer=="string"?e.fromLayer:void 0,o=typeof e.toLayer=="string"?e.toLayer:void 0,a=typeof e.target=="string"?e.target:void 0;return[t,r,n??"",o??"",a??""].join("|")}l(Wt,"adapterFindingTargetKey");function qt(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return`fnv1a-${(t>>>0).toString(16).padStart(8,"0")}`}l(qt,"adapterFindingRefFromTargetKey");function Zt(e){return`${zt}#${e}`}l(Zt,"adapterDocsCodePath");function Yt(e,t,r){return D({ruleId:e,target:R(t.target)??R(r.target)??void 0,fromLayer:R(t.fromLayer)??void 0,toLayer:R(t.toLayer)??void 0,typeOnly:t.typeOnly===!0,targetTypeOnlyExports:t.targetTypeOnlyExports===!0,namedBindingsTypeOnly:t.namedBindingsTypeOnly===!0,portProofEligible:t.portProofEligible===!0,peerIsolation:t.peerIsolation===!0,sourcePureTypeModule:t.sourcePureTypeModule===!0,edgeKind:R(t.edgeKind)??void 0,capability:R(t.capability)??R(r.capability)??void 0,arkruleId:R(t.arkruleId)??void 0,arkruleSource:R(t.arkruleSource)??void 0})}l(Yt,"nextActionForDiagnostic");function He(e,t="error",r){let n=R(e.ruleId)??R(e.code)??"ARK_UNKNOWN",o=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":t,a={...R(e.target)?{target:R(e.target)}:{},...R(e.fromLayer)?{fromLayer:R(e.fromLayer)}:{},...R(e.toLayer)?{toLayer:R(e.toLayer)}:{},...typeof e.typeOnly=="boolean"?{typeOnly:e.typeOnly}:{},...typeof e.targetTypeOnlyExports=="boolean"?{targetTypeOnlyExports:e.targetTypeOnlyExports}:{},...typeof e.sourcePureTypeModule=="boolean"?{sourcePureTypeModule:e.sourcePureTypeModule}:{},...typeof e.namedBindingsTypeOnly=="boolean"?{namedBindingsTypeOnly:e.namedBindingsTypeOnly}:{},...typeof e.portProofEligible=="boolean"?{portProofEligible:e.portProofEligible}:{},...typeof e.peerIsolation=="boolean"?{peerIsolation:e.peerIsolation}:{},...R(e.capability)?{capability:R(e.capability)}:{},...R(e.edgeKind)?{edgeKind:R(e.edgeKind)}:{},...R(e.arkruleId)?{arkruleId:R(e.arkruleId)}:{},...R(e.arkruleSource)?{arkruleSource:R(e.arkruleSource)}:{}},s=r??Wt(e),i=qt(s);return{ruleId:n,severity:o,message:R(e.message)??n,location:{file:R(e.file)??"<unknown>",line:Ue(e.line,1),column:Ue(e.column,1)},evidence:a,nextAction:R(e.nextAction)??Yt(n,a,e),findingRef:i,targetKey:s,docsCodePath:Zt(n)}}l(He,"toAdapterDiagnostic");var je={RAW_EVENT_PUBLISH:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts and tooling.",PUBLISH_MISSING_SOURCE:"Strict Ark publish calls must include metadata.source."},mn=Object.freeze([{layer:"DomainModel",prefixes:["Domain."]},{layer:"ApplicationOrchestration",prefixes:["Application."]},{layer:"PersistenceAdapters",prefixes:["Adapter.Persistence.","Adapter.Repository."]},{layer:"IntegrationAdapters",prefixes:["Adapter.Integration.","Adapter.External."]},{layer:"WorkflowSagaEngine",prefixes:["Workflow."]},{layer:"BackgroundJobsScheduling",prefixes:["Job."]},{layer:"PresentationAdapters",prefixes:["Presentation.","Adapter.Presentation.","Adapter.Api."]},{layer:"ReportingReadModels",prefixes:["Reporting."]},{layer:"ExtensibilityMetadata",prefixes:["Metadata."]},{layer:"SecurityAuditObservability",prefixes:["Security.","Audit.","Observability."]},{layer:"Kernel",prefixes:["Kernel."]}]);function Jt(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}l(Jt,"looksLikeArkIntent");function ae(e){if(!e.publishCall)return[];let t=[];return(e.rawIntentName!==void 0&&Jt(e.rawIntentName)||e.objectHasIntent)&&t.push({ruleId:"RAW_EVENT_PUBLISH",message:je.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&t.push({ruleId:"PUBLISH_MISSING_SOURCE",message:je.PUBLISH_MISSING_SOURCE}),t}l(ae,"classifyPublishFacts");import Xe from"fs";import O from"path";var Xt=["createArkKernel","createStrictArkKernel","createArkKernelFromConfig","createStrictArkKernelFromConfig"];var Qt=new Set(Xt),er=new Set(["AggregateError","Array","ArrayBuffer","BigInt64Array","BigUint64Array","Boolean","DataView","Date","Error","EvalError","FinalizationRegistry","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Number","Object","Promise","Proxy","RangeError","ReferenceError","RegExp","Set","SharedArrayBuffer","String","Symbol","SyntaxError","TypeError","URIError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","WeakRef","WeakSet"]),tr=new Set(["Array","Atomics","Buffer","JSON","Math","Number","Object","Promise","Reflect","String","console","fs","path","url","util"]);function F(e){return e==="@arkgate/runtime"||e.startsWith("@arkgate/runtime/")||e==="arkgate/runtime"||e.startsWith("arkgate/runtime/")}l(F,"isArkRunKernelModuleSpecifier");var rr=["events","node:events","eventemitter2","eventemitter3","emittery","kafkajs","kafka-node","amqplib","amqp","bull","bullmq","mqtt","nats","@aws-sdk/client-sqs","@aws-sdk/client-sns","@aws-sdk/client-eventbridge","@google-cloud/pubsub","@azure/service-bus"],le=new Set(rr);function Ge(e){if(!e||e.startsWith(".")||e.startsWith("/"))return!1;if(le.has(e))return!0;let t=e.indexOf("/");if(t<0)return!1;let r=e.slice(0,t);if(le.has(r))return!0;let n=e.indexOf("/",t+1);return n<0?!1:le.has(e.slice(0,n))}l(Ge,"isArkRunTransportBypassSpecifier");function Ve(e){if(Qt.has(e))return"factory";switch(e){case"publisher":return"publisher";case"publish":return"publish";case"raise":case"raiseAsync":return"raise";case"send":case"sendTo":return"send";case"subscribe":return"subscribe";case"registerHandler":return"register-handler";case"resolve":return"resolve";case"resolveSingleton":return"resolve-singleton";default:return}}l(Ve,"arkRunKernelCallKind");function ze(e,t){let r=1;for(let n=0;n<t;n+=1)e.charCodeAt(n)===10&&(r+=1);return r}l(ze,"lineAt");function ce(e){return e.replace(/\/\*[\s\S]*?\*\//g,t=>t.replace(/[^\n]/g," ")).replace(/(^|[^:\\])\/\/.*$/gm,t=>t.replace(/\/\/.*$/,r=>" ".repeat(r.length)))}l(ce,"stripCommentsPreservingLines");function nr(e,t){let r=e.slice(t),n=/^\s*(['"])((?:\\.|[^\\])*?)\1/.exec(r);if(!n)return;let o=n[2]??"";return o.length>0?o:void 0}l(nr,"firstStringLiteralArg");function Be(e,t,r){let n=Math.max(0,t-r.length-8),o=e.slice(n,t);return new RegExp(`\\b${r}\\s+$`).test(o)}l(Be,"keywordBefore");function Z(e,t){let r=/\b(?:import|export)(\s+type)?\s+([\s\S]*?)\s+from\s*['"]([^'"]+)['"]/g,n;for(;(n=r.exec(e))!==null;)n[1]||t(n[2]??"",n[3]??"")}l(Z,"parseValueImportClause");function We(e,t){Z(ce(e),t)}l(We,"forEachArkRunValueImportClause");function or(e){let t=new Map,r=new Set;return Z(e,(n,o)=>{if(!F(o))return;let a=/\*\s+as\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(n);a?.[1]&&r.add(a[1]);let s=/^([A-Za-z_][A-Za-z0-9_]*)\s*(?:,|$)/.exec(n.trim());s?.[1]&&t.set(s[1],s[1]);let i=/\{([^}]*)\}/.exec(n);if(i?.[1])for(let c of i[1].split(",")){let p=c.trim();if(!p||p.startsWith("type "))continue;let d=/^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/.exec(p);if(d){t.set(d[2],d[1]);continue}let u=/^([A-Za-z_][A-Za-z0-9_]*)$/.exec(p);u?.[1]&&t.set(u[1],u[1])}}),{named:t,namespaces:r}}l(or,"collectKernelImportBindings");function sr(e,t){let r=new Set(t);return Z(e,(n,o)=>{let a=/\{([^}]*)\}/.exec(n);if(a?.[1])for(let s of a[1].split(",")){let i=s.trim();if(!i||i.startsWith("type "))continue;let c=/^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/.exec(i),p=c?.[2]??/^([A-Za-z_][A-Za-z0-9_]*)$/.exec(i)?.[1],d=c?.[1]??p;!p||!d||!/^[A-Z]/.test(d)||(F(o)||t.has(d)||t.has(p))&&(r.add(p),r.add(d))}}),r}l(sr,"collectImportedConstructors");function ir(e,t){let r;return Z(e,(n,o)=>{!r&&new RegExp(`\\b${t}\\b`).test(n)&&(r=o)}),r}l(ir,"importedFromForName");function Y(e,t){let r=ce(t),n=or(r),o=[],a=/\b([A-Za-z_][A-Za-z0-9_]*)\s*(?:<[^>]*>)?\s*\(/g,s;for(;(s=a.exec(r))!==null;){let i=s[1],c=s.index;if(Be(r,c,"function")||Be(r,c,"class"))continue;let d=r.slice(0,c).match(/([A-Za-z_][A-Za-z0-9_]*)\s*\.\s*$/)?.[1],u=n.named.get(i)??i,f=Ve(u)??Ve(i);if(!f)continue;let g=n.named.has(i)||d!==void 0&&n.namespaces.has(d);if(f!=="factory"&&(!g&&d===void 0||d&&tr.has(d)&&!g))continue;let y=nr(r,c+s[0].length);o.push({file:e,line:ze(t,c),kind:f,callee:i,viaImport:g,...d?{receiver:d}:{},...y?{nameLiteral:y}:{}})}return o}l(Y,"extractArkRunKernelCallsFromSource");function ue(e,t,r){let n=ce(t),o=sr(n,r),a=[],s=/\bnew\s+(?:[A-Za-z_][A-Za-z0-9_]*\s*\.\s*)*([A-Z][A-Za-z0-9_]*)\s*(?:<[^>]*>)?\s*\(/g,i;for(;(i=s.exec(n))!==null;){let c=i[1];if(er.has(c)||!o.has(c))continue;let p=ir(n,c);a.push({file:e,line:ze(t,i.index),typeName:c,...p?{importedFrom:p}:{}})}return a}l(ue,"extractArkRunManagedNewsFromSource");function de(e,t){let r=[],n=/export\s+(?:abstract\s+)?class\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?:extends\s+[^{]+)?(?:implements\s+[^{]+)?\{/g,o;for(;(o=n.exec(t))!==null;){let a=o[1],s=o.index+o[0].length,i=1,c=s;for(;c<t.length&&i>0;){let b=t[c];b==="{"?i+=1:b==="}"&&(i-=1),c+=1}let p=t.slice(s,c-1),d=p.split(`
|
|
1
|
+
var Ir=Object.defineProperty;var c=(e,r)=>Ir(e,"name",{value:r,configurable:!0});import C from"fs";import m from"path";var Ee=new Map;function Se(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}c(Se,"escapeLiteral");function Z(e){let r="";for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="\\"&&t+1<e.length){let s=e[t+1];if("*?{}[],".includes(s)||s==="\\"){r+="\\"+s,t+=1;continue}r+="/";continue}r+=n}return r}c(Z,"normalizeGlobSeparators");function Nr(e){let r=0;for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="\\"){t+=1;continue}if(n==="{")r+=1;else if(n==="}"&&(r-=1,r<0))return!1}return r===0}c(Nr,"bracesBalanced");function T(e){let r=Ee.get(e);if(r)return r;let t=Z(e),n=Nr(t),s="",o=0;for(let a=0;a<t.length;a+=1){let l=t[a];l==="\\"&&a+1<t.length?(s+=Se(t[a+1]),a+=1):l==="*"?t[a+1]==="*"?t[a+2]==="/"?(s+="(?:.*/)?",a+=2):(s+=".*",a+=1):s+="[^/]*":l==="?"?s+="[^/]":l==="{"&&n?(s+="(?:",o+=1):l==="}"&&n&&o>0?(s+=")",o-=1):l===","&&n&&o>0?s+="|":s+=Se(l)}let i=new RegExp(`^${s}$`);return Ee.set(e,i),i}c(T,"globToRegExp");function _r(e){return Z(String(e)).split("/").filter(Boolean).filter(t=>t!=="**"&&t!=="*"&&!t.includes("*")&&!t.includes("?")&&!t.includes("{")&&!t.includes("["))}c(_r,"concreteGlobSegments");function Ie(e,r){let t=Z(String(e)),n=_r(t),s=t.replace(/\*/g,"").length,o=n.length*1e4+s;if(r==null||r==="")return o;let i=String(r).split(/[/\\]/).filter(Boolean);if(n.length===0)return s;let a=0,l=-1;for(let d of n){let u=-1;for(let p=a;p<i.length;p+=1)if(i[p]===d){u=p;break}if(u<0)return o;l=u,a=u+1}return(l+1)*1e6+n.length*1e4+s}c(Ie,"patternSpecificity");function E(e,r){let t=String(e).split(/[/\\]/).join("/"),n,s=-1;for(let o of r??[])if(!(o.exclude??[]).some(i=>T(i).test(t))){for(let i of o.patterns??[])if(T(i).test(t)){let a=Ie(i,t);a>s&&(s=a,n=o.name)}}return n}c(E,"layerForRelativePath");function xe(e,r){if(!r?.length)return;let t=String(e).split(/[/\\]/).filter(Boolean),n=new Set(r.map(s=>String(s).toLowerCase()));for(let s=0;s<t.length-1;s+=1)if(n.has(t[s].toLowerCase()))return`${t[s].toLowerCase()}/${t[s+1].toLowerCase()}`}c(xe,"sliceIdForPath");function Cr(e){let r=new Set;for(let t of e??[]){let s=Z(String(t)).split("/").filter(Boolean);for(let o=0;o<s.length;o+=1){let i=s[o];if((i==="**"||i==="*")&&o>0){let a=s[o-1];a&&!a.includes("*")&&!a.includes("{")&&!a.includes("}")&&r.add(a)}}}return[...r]}c(Cr,"inferSliceFoldersFromPatterns");function Or(e,r,t){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(s=>typeof s=="string"&&s.length>0);let n=(t??[]).find(s=>s.name===r);return Cr(n?.patterns)}c(Or,"resolveSliceFolders");function wr(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}c(wr,"peerIsolationMustDeny");function oe(e,r,t,n){for(let s of e??[])if(!(s.from!==r||s.to!==t)&&s.allowed===!1){if(s.peerIsolation){let o=n?.fromPath,i=n?.toPath,a=Or(s,r,n?.layers),l=o&&i?xe(o,a):void 0,d=o&&i?xe(i,a):void 0;if(wr({fromPath:o,toPath:i,folderCount:a.length,fromSlice:l,toSlice:d}))return s;continue}if(r!==t)return s}}c(oe,"findDeniedEdgeRule");function Ne(e,r,t,n){return oe(e,r,t,n)!==void 0}c(Ne,"isEdgeDenied");var vr=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function Lr(e){let r=Array.isArray(e?.exclude)?e.exclude.filter(n=>typeof n=="string"):[];return[...e?.excludeGenerated===!1?[]:vr,...r]}c(Lr,"scanExcludePatterns");function _e(e,r){let t=String(e).split(/[/\\]/).join("/");return Lr(r).some(n=>T(n).test(t))}c(_e,"isScanExcludedRelative");var Ce=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),Tr=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),ln=Object.freeze(Object.keys(Tr).sort()),ie=Object.freeze({fs:"filesystem","node:fs":"filesystem","fs/promises":"filesystem","node:fs/promises":"filesystem","fs-extra":"filesystem","graceful-fs":"filesystem",memfs:"filesystem",chokidar:"filesystem",http:"network",https:"network",http2:"network",net:"network",tls:"network",dgram:"network",dns:"network","node:http":"network","node:https":"network","node:http2":"network","node:net":"network","node:tls":"network","node:dgram":"network","node:dns":"network",axios:"network",undici:"network","node-fetch":"network",got:"network",ky:"network",superagent:"network",ws:"network",process:"process","node:process":"process",child_process:"process","node:child_process":"process","@prisma/client":"persistence",prisma:"persistence",pg:"persistence",mysql:"persistence",mysql2:"persistence",mongodb:"persistence",mongoose:"persistence",sqlite3:"persistence","better-sqlite3":"persistence",redis:"persistence",ioredis:"persistence",typeorm:"persistence",knex:"persistence","drizzle-orm":"persistence",sequelize:"persistence",kysely:"persistence","@supabase/supabase-js":"persistence"}),Dr=Object.freeze({process:Object.freeze(["process","node:process"])});function Oe(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let r=ie[e];if(r)return r;let t=e.indexOf("/");if(t<0)return null;let n=e.slice(0,t),s=ie[n];if(s)return s;let o=e.indexOf("/",t+1);return o<0?null:ie[e.slice(0,o)]??null}c(Oe,"capabilityForModuleSpecifier");function ae(e,r){for(let t of r)if(Dr[t]?.includes(e))return t;return null}c(ae,"forbiddenGlobalForModuleSpecifier");function we(e){if(e?.pure===!0)return[...Ce].sort();let t=(e?.capabilities?.deny??[]).filter(n=>Ce.includes(n));return[...new Set(t)].sort()}c(we,"effectiveCapabilityDeny");var D={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},ve={type:"object",additionalProperties:!1,properties:{mode:{type:"string",enum:["advisory","enforced"],default:"advisory"},compositionRoots:{...D,default:[]},kernelRoots:{...D},managedLayers:{...D,default:[]},requireDeclarations:{type:"boolean",default:!0},ignoreDirectNewForErrors:{type:"boolean",default:!0}}},Le={type:"object",additionalProperties:!1,properties:{mode:{type:"string",enum:["advisory","enforced"],default:"advisory"},planeRoots:{...D,default:[]},managedLayers:{...D,default:[]},maxXiKeys:{type:"integer",minimum:1,default:7},xiKeys:{...D,default:[]}}};function $(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}c($,"isObject");function Te(e){let r=new Set;if(!Array.isArray(e.layers))return r;for(let t of e.layers)$(t)&&typeof t.name=="string"&&t.name.length>0&&r.add(t.name);return r}c(Te,"declaredLayerNames");function De(e){if(!$(e))return e;let r={mode:e.mode===void 0?"advisory":e.mode,compositionRoots:e.compositionRoots===void 0?[]:e.compositionRoots,managedLayers:e.managedLayers===void 0?[]:e.managedLayers,requireDeclarations:e.requireDeclarations===void 0?!0:e.requireDeclarations};return e.kernelRoots!==void 0&&(r.kernelRoots=e.kernelRoots),e.ignoreDirectNewForErrors!==void 0&&(r.ignoreDirectNewForErrors=e.ignoreDirectNewForErrors),{...e,...r}}c(De,"defaultedArkRun");function Fe(e){if(!$(e))return e;let r=typeof e.maxXiKeys=="number"&&e.maxXiKeys>0?e.maxXiKeys:7;return{...e,mode:e.mode===void 0?"advisory":e.mode,planeRoots:e.planeRoots===void 0?[]:e.planeRoots,managedLayers:e.managedLayers===void 0?[]:e.managedLayers,maxXiKeys:r,xiKeys:e.xiKeys===void 0?[]:e.xiKeys}}c(Fe,"defaultedArkOrder");function Ke(e,r){let t=e.arkRun;if(t===void 0||!$(t))return;let n=Te(e),s=t.managedLayers;if(Array.isArray(s)&&s.forEach((o,i)=>{typeof o=="string"&&o.length>0&&!n.has(o)&&r.push({path:`$.arkRun.managedLayers[${i}]`,message:`layer ${JSON.stringify(o)} is not declared in layers[]`})}),t.mode==="enforced"){let o=t.kernelRoots??t.compositionRoots;(!Array.isArray(o)||o.length===0)&&r.push({path:t.kernelRoots!==void 0?"$.arkRun.kernelRoots":"$.arkRun.compositionRoots",message:"ARKRUN_MISSING_ROOT: enforced mode requires at least one kernel root"}),(!Array.isArray(s)||s.length===0)&&r.push({path:"$.arkRun.managedLayers",message:"enforced mode requires at least one managed layer"})}}c(Ke,"validateArkRunExtra");function Pe(e,r){let t=e.arkOrder;if(t===void 0||!$(t))return;let n=Te(e),s=t.managedLayers;if(Array.isArray(s)&&s.forEach((o,i)=>{typeof o=="string"&&o.length>0&&!n.has(o)&&r.push({path:`$.arkOrder.managedLayers[${i}]`,message:`layer ${JSON.stringify(o)} is not declared in layers[]`})}),t.mode==="enforced"){let o=t.planeRoots;(!Array.isArray(o)||o.length===0)&&r.push({path:"$.arkOrder.planeRoots",message:"ARKORDER_MISSING_PLANE: enforced mode requires at least one plane root"}),(!Array.isArray(s)||s.length===0)&&r.push({path:"$.arkOrder.managedLayers",message:"enforced mode requires at least one managed layer"})}}c(Pe,"validateArkOrderExtra");var S="1.3",le="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",Me=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],Fr=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function Kr(){let e=[];for(let r of Me)for(let t of Me)r===t||Fr.has(`${r}->${t}`)||e.push({from:r,to:t,allowed:!1});return e}c(Kr,"createDefaultRules");var Ue=Kr(),ce=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"},{from:"1.1",to:"1.2"},{from:"1.2",to:"1.3"}],x={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},$e={$schema:"https://json-schema.org/draft/2020-12/schema",$id:le,title:"ArkGate architecture contract",description:"Versioned contract consumed identically by ArkGate CLI, MCP, and ESLint surfaces.",type:"object",additionalProperties:!1,required:["$schema","schemaVersion","include","layers","rules"],properties:{$schema:{type:"string",minLength:1,default:le,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:S,default:S},name:{type:"string",minLength:1},include:{...x,minItems:1,default:["src"]},exclude:{...x,default:[]},excludeGenerated:{type:"boolean",default:!0},frameworkOverlay:{type:"string",minLength:1},layers:{type:"array",default:[],items:{$ref:"#/$defs/layer"}},rules:{type:"array",default:Ue,items:{$ref:"#/$defs/rule"}},cyclePolicy:{type:"string",enum:["strict","soft","framework-soft","off"],default:"strict"},dynamicImportAllowlist:{...x,default:[]},safety:{$ref:"#/$defs/safety",default:{maxTsSuppressions:0,maxAnyCasts:0,allowInMemory:!1,allowDisabledPeerIsolation:!1}},arkRules:{type:"object",additionalProperties:{type:"string",minLength:1},default:{}},arkRun:{$ref:"#/$defs/arkRun"},arkOrder:{$ref:"#/$defs/arkOrder"},stewards:{...x,default:[]}},$defs:{layer:{type:"object",additionalProperties:!1,required:["name","patterns"],properties:{name:{type:"string",minLength:1},patterns:{...x,minItems:1},exclude:x,intentPrefixes:x,description:{type:"string",minLength:1},forbiddenGlobals:x,capabilities:{type:"object",additionalProperties:!1,properties:{deny:{type:"array",uniqueItems:!0,items:{type:"string",enum:["network","filesystem","clock","randomness","environment","process","persistence"]}}}},pure:{type:"boolean"},mayImportInfrastructure:{type:"boolean"},optional:{type:"boolean"},reserved:{type:"boolean"},allowEmpty:{type:"boolean"}}},rule:{type:"object",additionalProperties:!1,required:["from","to","allowed"],properties:{from:{type:"string",minLength:1},to:{type:"string",minLength:1},allowed:{type:"boolean"},message:{type:"string",minLength:1},peerIsolation:{type:"boolean"},sliceFolders:{...x,minItems:1}}},safety:{type:"object",additionalProperties:!1,properties:{maxTsSuppressions:{type:"integer",minimum:0,default:0},maxAnyCasts:{type:"integer",minimum:0,default:0},allowInMemory:{type:"boolean",default:!1},allowDisabledPeerIsolation:{type:"boolean",default:!1}}},arkRun:ve,arkOrder:Le}},I=class extends Error{static{c(this,"ArkConfigValidationError")}issues;source;constructor(r,t){super(`Invalid ArkGate config (${r}):
|
|
2
|
+
${t.map(n=>`- ${n.path}: ${n.message}`).join(`
|
|
3
|
+
`)}`),this.name="ArkConfigValidationError",this.source=r,this.issues=t}};function He(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}c(He,"isObject");function Y(e,r){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(r)?`${e}.${r}`:`${e}[${JSON.stringify(r)}]`}c(Y,"propertyPath");function F(e){return e===null?"null":Array.isArray(e)?"array":typeof e}c(F,"valueType");function Pr(e,r){let t="#/$defs/";if(e.startsWith(t))return r.$defs[e.slice(t.length)]}c(Pr,"resolveSchemaRef");function U(e,r,t,n,s){if(r.$ref){let o=Pr(r.$ref,n);if(!o){s.push({path:t,message:`schema reference ${r.$ref} cannot be resolved`});return}U(e,o,t,n,s);return}if(r.const!==void 0&&!Object.is(e,r.const)){s.push({path:t,message:`must equal ${JSON.stringify(r.const)}`});return}if(r.enum&&!r.enum.some(o=>Object.is(o,e))){s.push({path:t,message:`must be one of ${r.enum.map(String).join(", ")}`});return}if(r.type==="object"){if(!He(e)){s.push({path:t,message:`must be an object; received ${F(e)}`});return}let o=r.properties??{};for(let i of r.required??[])e[i]===void 0&&s.push({path:Y(t,i),message:"is required"});if(r.additionalProperties===!1)for(let i of Object.keys(e))i in o||s.push({path:Y(t,i),message:"unknown field"});else if(r.additionalProperties!==void 0&&r.additionalProperties!==!0&&typeof r.additionalProperties=="object"){let i=r.additionalProperties;for(let a of Object.keys(e))a in o||U(e[a],i,Y(t,a),n,s)}for(let[i,a]of Object.entries(o))e[i]!==void 0&&U(e[i],a,Y(t,i),n,s);return}if(r.type==="array"){if(!Array.isArray(e)){s.push({path:t,message:`must be an array; received ${F(e)}`});return}if(r.minItems!==void 0&&e.length<r.minItems&&s.push({path:t,message:`must contain at least ${r.minItems} item(s)`}),r.uniqueItems){let o=e.map(i=>JSON.stringify(i));new Set(o).size!==o.length&&s.push({path:t,message:"must not contain duplicate items"})}r.items&&e.forEach((o,i)=>U(o,r.items,`${t}[${i}]`,n,s));return}if(r.type==="string"){if(typeof e!="string"){s.push({path:t,message:`must be a string; received ${F(e)}`});return}r.minLength!==void 0&&e.length<r.minLength&&s.push({path:t,message:`must contain at least ${r.minLength} character(s)`});return}if(r.type==="boolean"){typeof e!="boolean"&&s.push({path:t,message:`must be a boolean; received ${F(e)}`});return}if(r.type==="integer"){if(!Number.isInteger(e)){s.push({path:t,message:`must be an integer; received ${F(e)}`});return}r.minimum!==void 0&&e<r.minimum&&s.push({path:t,message:`must be at least ${r.minimum}`})}}c(U,"validateNode");function Mr(e){let r={...e,$schema:e.$schema===void 0?le:e.$schema,schemaVersion:e.schemaVersion===void 0?S:e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?Ue.map(t=>({...t})):e.rules};return e.arkRun!==void 0&&(r.arkRun=De(e.arkRun)),e.arkOrder!==void 0&&(r.arkOrder=Fe(e.arkOrder)),r}c(Mr,"defaultedConfig");function $r(e){return e===S?null:e==="unversioned"?"unversioned":e==="1.0"||e==="1.1"||e==="1.2"?e:null}c($r,"migratedFromOf");function Ur(){let e=new Set([S]);for(let r of ce)r.from!=="unversioned"&&e.add(r.from),e.add(r.to);return e}c(Ur,"knownInputVersions");function Hr(e,r="ark.config.json"){if(!He(e))throw new I(r,[{path:"$",message:`must be an object; received ${F(e)}`}]);let t=Ur(),n=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(n===null)throw new I(r,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected ${S}`}]);if(n!=="unversioned"&&!t.has(n))throw new I(r,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected ${S}`}]);let s=n,o={...e},i=0;for(;s!==S&&i<ce.length+1;){i+=1;let a=ce.find(l=>l.from===s);if(!a)throw new I(r,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(s)}; expected ${S}`}]);s=a.to,o.schemaVersion=s}if(s!==S)throw new I(r,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected ${S}`}]);return{candidate:Mr(o),migratedFrom:$r(n)}}c(Hr,"migrateArkConfig");function jr(e,r="ark.config.json"){let{candidate:t,migratedFrom:n}=Hr(e,r),s=[];if(U(t,$e,"$",$e,s),Ke(t,s),Pe(t,s),s.length>0)throw new I(r,s);return{config:t,migratedFrom:n}}c(jr,"loadArkConfigContract");function je(e,r="ark.config.json"){let t;try{t=JSON.parse(e)}catch(n){throw new I(r,[{path:"$",message:`invalid JSON: ${n instanceof Error?n.message:String(n)}`}])}return jr(t,r)}c(je,"parseArkConfigJson");var Vr=/(^|\/)(constants|types|enums|shared-types|shared\/(?:types|constants)|test-projects)(\/|\.|$)|(?:^|\/)[^/]*(?:constants|types)(?:\.[cm]?[jt]sx?)?$/i,Br=/(^|\/)(?:kernel(?:\/|$)|events?(?:\/|\.|$)|bootstrap(?:\.[cm]?[jt]sx?)?$|emitter(?:\.[cm]?[jt]sx?)?$)|(?:^|\/)(?:intents?|publish)(?:\/|\.|$)/i,Gr=/(use-?cases?|usecases?|application|orchestrat|services?|handlers?)(\/|\.|$)/i;function Wr(e,r){let t=String(e??"").replace(/\\/g,"/").trim(),n=String(r?.fromLayer??""),s=String(r?.toLayer??"");return Vr.test(t)?"pure-shared":n==="PersistenceAdapters"&&(Br.test(t)||/events?|intents?|kernel|bootstrap/i.test(`${s} ${t}`))?"kernel-emit":Gr.test(t)||(n==="DomainModel"||n==="ApplicationOrchestration")&&s==="PersistenceAdapters"?"use-case":"unknown"}c(Wr,"classifyLayerImportKind");function zr(e){if(e.typeOnly||e.targetTypeOnlyExports||e.namedBindingsTypeOnly)return"Move the referenced type to a mutually allowed layer, use `import type`, then preflight again.";if(e.peerIsolation)return"Extract the shared dependency to a shared layer, test at the public interface, then preflight again.";let r=Wr(typeof e.target=="string"?e.target:"",{fromLayer:typeof e.fromLayer=="string"?e.fromLayer:void 0,toLayer:typeof e.toLayer=="string"?e.toLayer:void 0});return r==="pure-shared"?"Adopt the imported constants/types/pure module into DomainModel or SharedKernel (do not inject a port). Then preflight again.":r==="kernel-emit"?"Persistence must not emit. Inject a port or move the event map to SharedTypes; do not import kernel/events/bootstrap from a repository. Then preflight again.":r==="use-case"||e.portProofEligible?`Define a port in ${e.fromLayer??"the source layer"}, inject the ${e.toLayer??"outer-layer"} implementation, test at the public interface, then preflight again.`:"Classify the import: if it is constants/types/pure, adopt into DomainModel or SharedKernel; define a port only if the target is a real use-case. Then preflight again."}c(zr,"layerImportNextAction");function qr(e){return typeof e.target=="string"&&e.target.trim().length>0?e.target.trim():void 0}c(qr,"arkRunCallSiteName");function Zr(e){let r=qr(e),t=typeof e.fromLayer=="string"&&e.fromLayer.length>0?e.fromLayer:void 0;switch(e.ruleId){case"ARKRUN_MISSING_ROOT":return r?`Import createStrictArkKernel from arkgate/runtime and call it in composition root ${r} listed in arkRun.compositionRoots, then preflight again.`:"Import createStrictArkKernel from arkgate/runtime (same npm package; @arkgate/runtime is deprecated) and call it in a composition root listed in arkRun.compositionRoots, then preflight again. Never mechanical-safe \u2014 factory placement is a design decision.";case"ARKRUN_KERNEL_IN_DOMAIN":return r?`Move the kernel import of ${r} out of ${t??"the Domain-role layer"} into a composition root or adapter. Import from arkgate/runtime, then preflight again.`:"Move the kernel import out of the Domain-role layer into a composition root or adapter. Import from arkgate/runtime (same npm package; @arkgate/runtime is deprecated), then preflight again. Never mechanical-safe.";case"ARKRUN_DIRECT_NEW":return r?`Resolve ${r} from the kernel instead of constructing it with new, then preflight again.`:"Resolve the type from the kernel instead of constructing it with new, then preflight again. Never mechanical-safe \u2014 rewiring construction is a design decision.";case"ARKRUN_UNDECLARED_EMIT":return r?`Add ${r} to raises or sends on the managed component, then preflight again.`:"Add the existing call-site name to raises or sends on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new emit stays judgment.";case"ARKRUN_UNDECLARED_HANDLE":return r?`Add ${r} to reactsTo on the managed component, then preflight again.`:"Add the existing call-site name to reactsTo on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new handle stays judgment.";case"ARKRUN_UNDECLARED_DEPEND":return r?`Add ${r} to uses on the managed component, then preflight again.`:"Add the existing call-site name to uses on the managed component, then preflight again. Mechanical-safe only when that literal already exists and the edit is the declaration list; inventing a new depend stays judgment.";case"ARKRUN_TRANSPORT_BYPASS":return r?`Send through the ArkRun kernel transport instead of importing ${r}, then preflight again.`:"Send through the ArkRun kernel transport instead of importing that broker or emitter, then preflight again. Never mechanical-safe \u2014 homemade buses stay judgment.";default:return`Resolve ${typeof e.ruleId=="string"&&e.ruleId.length>0?e.ruleId:"ARK_UNKNOWN"} without weakening ark.config.json, then run Ark again.`}}c(Zr,"arkRunNextAction");function K(e){switch(e.ruleId){case"LAYER_IMPORT_VIOLATION":return zr(e);case"FORBIDDEN_GLOBAL":return`Inject ${e.target??"the capability"} through a port, test at the public interface, then preflight again.`;case"CAPABILITY_VIOLATION":return`Define a ${String(e.capability??"capability")} port in ${e.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;case"CIRCULAR_DEPENDENCY":return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";case"RAW_EVENT_PUBLISH":return"Publish through a registered intent creator, then run Ark again.";case"PUBLISH_MISSING_SOURCE":return"Add metadata.source to the publish call, then run Ark again.";case"ARKRULE_STRUCTURE":case"ARKRULE_INVARIANT":case"INVARIANT_UNCOVERED":return`Fix the structure or invariant for ${typeof e.arkruleId=="string"&&e.arkruleId.length>0?e.arkruleId:"the ArkRule"} (declared in ${typeof e.arkruleSource=="string"&&e.arkruleSource.length>0?e.arkruleSource:"arkrules/<Layer>.json"}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`;case"ARKRUN_MISSING_ROOT":case"ARKRUN_KERNEL_IN_DOMAIN":case"ARKRUN_DIRECT_NEW":case"ARKRUN_UNDECLARED_EMIT":case"ARKRUN_UNDECLARED_HANDLE":case"ARKRUN_UNDECLARED_DEPEND":case"ARKRUN_TRANSPORT_BYPASS":return Zr(e);case"ARKORDER_MISSING_PLANE":return typeof e.target=="string"&&e.target.length>0?`Import createOrderPlane from arkgate/order and call it in plane root ${e.target} listed in arkOrder.planeRoots, then preflight again.`:"Import createOrderPlane from arkgate/order and call it in a plane root listed in arkOrder.planeRoots, then preflight again. Never mechanical-safe \u2014 factory placement is a design decision.";case"ARKORDER_KERNEL_IN_DOMAIN":return"Move the arkgate/order import out of the Domain-role layer into a plane root or adapter, then preflight again. Never mechanical-safe.";case"ARKORDER_GENERIC_UPDATE":return"Use release() to freeze \u03BE or proposeRelease() for a pattern change with blast radius, then preflight again. Never mechanical-safe.";case"ARKORDER_TOO_MANY_PARAMS":return"Cut \u03BE to the slow keys that actually slave the rest, then preflight again. Never mechanical-safe.";case"ARKORDER_INGEST_WRITES_XI":return"Keep ingest results as absorb/escalate only. Change \u03BE with proposeRelease + release. Never mechanical-safe.";case"ARKORDER_XI_FIELD_WRITE":return typeof e.target=="string"&&e.target.length>0?`Do not persist slow key ${e.target} from a use-case. Absorb the field with ingest() or change the pattern with proposeRelease(), then preflight again.`:"Do not persist a declared slow key from a use-case. Absorb the field with ingest() or change the pattern with proposeRelease(), then preflight again. Never mechanical-safe.";default:return typeof e.ruleId=="string"&&e.ruleId.startsWith("ARKRULE_")?`Fix the ArkRule ${typeof e.arkruleId=="string"?e.arkruleId:e.ruleId}, then preflight again.`:`Resolve ${typeof e.ruleId=="string"&&e.ruleId.length>0?e.ruleId:"ARK_UNKNOWN"} without weakening ark.config.json, then run Ark again.`}}c(K,"deterministicNextAction");var Yr="docs/diagnostics.md";function R(e){return typeof e=="string"&&e.length>0?e:void 0}c(R,"text");function Ve(e,r){return Number.isInteger(e)&&Number(e)>0?Number(e):r}c(Ve,"positiveInteger");function Xr(e){let r=typeof e.ruleId=="string"?e.ruleId:typeof e.code=="string"?e.code:void 0,t=typeof e.file=="string"?e.file:void 0,n=typeof e.fromLayer=="string"?e.fromLayer:void 0,s=typeof e.toLayer=="string"?e.toLayer:void 0,o=typeof e.target=="string"?e.target:void 0;return[r,t,n??"",s??"",o??""].join("|")}c(Xr,"adapterFindingTargetKey");function Jr(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")}`}c(Jr,"adapterFindingRefFromTargetKey");function Qr(e){return`${Yr}#${e}`}c(Qr,"adapterDocsCodePath");function et(e,r,t){return K({ruleId:e,target:R(r.target)??R(t.target)??void 0,fromLayer:R(r.fromLayer)??void 0,toLayer:R(r.toLayer)??void 0,typeOnly:r.typeOnly===!0,targetTypeOnlyExports:r.targetTypeOnlyExports===!0,namedBindingsTypeOnly:r.namedBindingsTypeOnly===!0,portProofEligible:r.portProofEligible===!0,peerIsolation:r.peerIsolation===!0,sourcePureTypeModule:r.sourcePureTypeModule===!0,edgeKind:R(r.edgeKind)??void 0,capability:R(r.capability)??R(t.capability)??void 0,arkruleId:R(r.arkruleId)??void 0,arkruleSource:R(r.arkruleSource)??void 0})}c(et,"nextActionForDiagnostic");function Be(e,r="error",t){let n=R(e.ruleId)??R(e.code)??"ARK_UNKNOWN",s=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":r,o={...R(e.target)?{target:R(e.target)}:{},...R(e.fromLayer)?{fromLayer:R(e.fromLayer)}:{},...R(e.toLayer)?{toLayer:R(e.toLayer)}:{},...typeof e.typeOnly=="boolean"?{typeOnly:e.typeOnly}:{},...typeof e.targetTypeOnlyExports=="boolean"?{targetTypeOnlyExports:e.targetTypeOnlyExports}:{},...typeof e.sourcePureTypeModule=="boolean"?{sourcePureTypeModule:e.sourcePureTypeModule}:{},...typeof e.namedBindingsTypeOnly=="boolean"?{namedBindingsTypeOnly:e.namedBindingsTypeOnly}:{},...typeof e.portProofEligible=="boolean"?{portProofEligible:e.portProofEligible}:{},...typeof e.peerIsolation=="boolean"?{peerIsolation:e.peerIsolation}:{},...R(e.capability)?{capability:R(e.capability)}:{},...R(e.edgeKind)?{edgeKind:R(e.edgeKind)}:{},...R(e.arkruleId)?{arkruleId:R(e.arkruleId)}:{},...R(e.arkruleSource)?{arkruleSource:R(e.arkruleSource)}:{}},i=t??Xr(e),a=Jr(i);return{ruleId:n,severity:s,message:R(e.message)??n,location:{file:R(e.file)??"<unknown>",line:Ve(e.line,1),column:Ve(e.column,1)},evidence:o,nextAction:R(e.nextAction)??et(n,o,e),findingRef:a,targetKey:i,docsCodePath:Qr(n)}}c(Be,"toAdapterDiagnostic");var Ge={RAW_EVENT_PUBLISH:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts and tooling.",PUBLISH_MISSING_SOURCE:"Strict Ark publish calls must include metadata.source."},bn=Object.freeze([{layer:"DomainModel",prefixes:["Domain."]},{layer:"ApplicationOrchestration",prefixes:["Application."]},{layer:"PersistenceAdapters",prefixes:["Adapter.Persistence.","Adapter.Repository."]},{layer:"IntegrationAdapters",prefixes:["Adapter.Integration.","Adapter.External."]},{layer:"WorkflowSagaEngine",prefixes:["Workflow."]},{layer:"BackgroundJobsScheduling",prefixes:["Job."]},{layer:"PresentationAdapters",prefixes:["Presentation.","Adapter.Presentation.","Adapter.Api."]},{layer:"ReportingReadModels",prefixes:["Reporting."]},{layer:"ExtensibilityMetadata",prefixes:["Metadata."]},{layer:"SecurityAuditObservability",prefixes:["Security.","Audit.","Observability."]},{layer:"Kernel",prefixes:["Kernel."]}]);function rt(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}c(rt,"looksLikeArkIntent");function ue(e){if(!e.publishCall)return[];let r=[];return(e.rawIntentName!==void 0&&rt(e.rawIntentName)||e.objectHasIntent)&&r.push({ruleId:"RAW_EVENT_PUBLISH",message:Ge.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&r.push({ruleId:"PUBLISH_MISSING_SOURCE",message:Ge.PUBLISH_MISSING_SOURCE}),r}c(ue,"classifyPublishFacts");import rr from"fs";import v from"path";var tt=["createArkKernel","createStrictArkKernel","createArkKernelFromConfig","createStrictArkKernelFromConfig"];var nt=new Set(tt),st=new Set(["AggregateError","Array","ArrayBuffer","BigInt64Array","BigUint64Array","Boolean","DataView","Date","Error","EvalError","FinalizationRegistry","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Number","Object","Promise","Proxy","RangeError","ReferenceError","RegExp","Set","SharedArrayBuffer","String","Symbol","SyntaxError","TypeError","URIError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","WeakRef","WeakSet"]),ot=new Set(["Array","Atomics","Buffer","JSON","Math","Number","Object","Promise","Reflect","String","console","fs","path","url","util"]);function P(e){return e==="@arkgate/runtime"||e.startsWith("@arkgate/runtime/")||e==="arkgate/runtime"||e.startsWith("arkgate/runtime/")}c(P,"isArkRunKernelModuleSpecifier");var it=["events","node:events","eventemitter2","eventemitter3","emittery","kafkajs","kafka-node","amqplib","amqp","bull","bullmq","mqtt","nats","@aws-sdk/client-sqs","@aws-sdk/client-sns","@aws-sdk/client-eventbridge","@google-cloud/pubsub","@azure/service-bus"],de=new Set(it);function qe(e){if(!e||e.startsWith(".")||e.startsWith("/"))return!1;if(de.has(e))return!0;let r=e.indexOf("/");if(r<0)return!1;let t=e.slice(0,r);if(de.has(t))return!0;let n=e.indexOf("/",r+1);return n<0?!1:de.has(e.slice(0,n))}c(qe,"isArkRunTransportBypassSpecifier");function We(e){if(nt.has(e))return"factory";switch(e){case"publisher":return"publisher";case"publish":return"publish";case"raise":case"raiseAsync":return"raise";case"send":case"sendTo":return"send";case"subscribe":return"subscribe";case"registerHandler":return"register-handler";case"resolve":return"resolve";case"resolveSingleton":return"resolve-singleton";default:return}}c(We,"arkRunKernelCallKind");function Ze(e,r){let t=1;for(let n=0;n<r;n+=1)e.charCodeAt(n)===10&&(t+=1);return t}c(Ze,"lineAt");function pe(e){return e.replace(/\/\*[\s\S]*?\*\//g,r=>r.replace(/[^\n]/g," ")).replace(/(^|[^:\\])\/\/.*$/gm,r=>r.replace(/\/\/.*$/,t=>" ".repeat(t.length)))}c(pe,"stripCommentsPreservingLines");function at(e,r){let t=e.slice(r),n=/^\s*(['"])((?:\\.|[^\\])*?)\1/.exec(t);if(!n)return;let s=n[2]??"";return s.length>0?s:void 0}c(at,"firstStringLiteralArg");function ze(e,r,t){let n=Math.max(0,r-t.length-8),s=e.slice(n,r);return new RegExp(`\\b${t}\\s+$`).test(s)}c(ze,"keywordBefore");function X(e,r){let t=/\b(?:import|export)(\s+type)?\s+([\s\S]*?)\s+from\s*['"]([^'"]+)['"]/g,n;for(;(n=t.exec(e))!==null;)n[1]||r(n[2]??"",n[3]??"")}c(X,"parseValueImportClause");function Ye(e,r){X(pe(e),r)}c(Ye,"forEachArkRunValueImportClause");function lt(e){let r=new Map,t=new Set;return X(e,(n,s)=>{if(!P(s))return;let o=/\*\s+as\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(n);o?.[1]&&t.add(o[1]);let i=/^([A-Za-z_][A-Za-z0-9_]*)\s*(?:,|$)/.exec(n.trim());i?.[1]&&r.set(i[1],i[1]);let a=/\{([^}]*)\}/.exec(n);if(a?.[1])for(let l of a[1].split(",")){let d=l.trim();if(!d||d.startsWith("type "))continue;let u=/^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/.exec(d);if(u){r.set(u[2],u[1]);continue}let p=/^([A-Za-z_][A-Za-z0-9_]*)$/.exec(d);p?.[1]&&r.set(p[1],p[1])}}),{named:r,namespaces:t}}c(lt,"collectKernelImportBindings");function ct(e,r){let t=new Set(r);return X(e,(n,s)=>{let o=/\{([^}]*)\}/.exec(n);if(o?.[1])for(let i of o[1].split(",")){let a=i.trim();if(!a||a.startsWith("type "))continue;let l=/^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/.exec(a),d=l?.[2]??/^([A-Za-z_][A-Za-z0-9_]*)$/.exec(a)?.[1],u=l?.[1]??d;!d||!u||!/^[A-Z]/.test(u)||(P(s)||r.has(u)||r.has(d))&&(t.add(d),t.add(u))}}),t}c(ct,"collectImportedConstructors");function ut(e,r){let t;return X(e,(n,s)=>{!t&&new RegExp(`\\b${r}\\b`).test(n)&&(t=s)}),t}c(ut,"importedFromForName");function J(e,r){let t=pe(r),n=lt(t),s=[],o=/\b([A-Za-z_][A-Za-z0-9_]*)\s*(?:<[^>]*>)?\s*\(/g,i;for(;(i=o.exec(t))!==null;){let a=i[1],l=i.index;if(ze(t,l,"function")||ze(t,l,"class"))continue;let u=t.slice(0,l).match(/([A-Za-z_][A-Za-z0-9_]*)\s*\.\s*$/)?.[1],p=n.named.get(a)??a,f=We(p)??We(a);if(!f)continue;let g=n.named.has(a)||u!==void 0&&n.namespaces.has(u);if(f!=="factory"&&(!g&&u===void 0||u&&ot.has(u)&&!g))continue;let y=at(t,l+i[0].length);s.push({file:e,line:Ze(r,l),kind:f,callee:a,viaImport:g,...u?{receiver:u}:{},...y?{nameLiteral:y}:{}})}return s}c(J,"extractArkRunKernelCallsFromSource");function fe(e,r,t){let n=pe(r),s=ct(n,t),o=[],i=/\bnew\s+(?:[A-Za-z_][A-Za-z0-9_]*\s*\.\s*)*([A-Z][A-Za-z0-9_]*)\s*(?:<[^>]*>)?\s*\(/g,a;for(;(a=i.exec(n))!==null;){let l=a[1];if(st.has(l)||!s.has(l))continue;let d=ut(n,l);o.push({file:e,line:Ze(r,a.index),typeName:l,...d?{importedFrom:d}:{}})}return o}c(fe,"extractArkRunManagedNewsFromSource");function ge(e,r){let t=[],n=/export\s+(?:abstract\s+)?class\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?:extends\s+[^{]+)?(?:implements\s+[^{]+)?\{/g,s;for(;(s=n.exec(r))!==null;){let o=s[1],i=s.index+s[0].length,a=1,l=i;for(;l<r.length&&a>0;){let b=r[l];b==="{"?a+=1:b==="}"&&(a-=1),l+=1}let d=r.slice(i,l-1),u=d.split(`
|
|
4
4
|
`).map(b=>/^\s*\/\//.test(b)||/^\s*\/\*|\*\//.test(b)?b:b.replace(/(?:public\s+|protected\s+)?readonly\s+[a-zA-Z_][a-zA-Z0-9_]*\s*(?::[^=;]+)?(?:=\s*[^;]+)?[;,]?/g,"").replace(/(?:^|[\s;{])readonly\s+[a-zA-Z_][a-zA-Z0-9_]*\s*(?::[^=;]+)?(?:=\s*[^;]+)?[;,]?/g," ")).join(`
|
|
5
|
-
`),
|
|
5
|
+
`),p=/(?:^|\n)\s*(?:public\s+)?[a-zA-Z_][a-zA-Z0-9_]*\s*[:=]/m.test(u.replace(/(?:public\s+|private\s+|protected\s+|static\s+|async\s+|get\s+|set\s+)/g,""))&&/(?:^|\n)\s*(public\s+)?(?!constructor|static|get|set|private|protected|readonly)[a-zA-Z_][a-zA-Z0-9_]*\s*[:=]/m.test(u),f=/(?:^|\n)\s*public\s+(?!static|async|get|set|constructor|readonly)[a-zA-Z_]/.test(u)||/(?:^|[\n;])\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*[^=;\n]+[;=]/m.test(u.split(`
|
|
6
6
|
`).filter(b=>!/^\s*(private|protected|static|constructor|get |set |async |\/)/.test(b)).join(`
|
|
7
|
-
`)),g=/(?:^|[\n;{])\s*(?:public\s+)?set\s+[a-zA-Z_]/.test(p),y=/(?:^|[\n;{])\s*private\s+constructor\s*\(/.test(p),h=/(?:^|[\n;{])\s*(?:public\s+)?constructor\s*\(/.test(p)&&!y,A=/(?:^|[\n;{])\s*static\s+(?:async\s+)?(?:create|of|from|parse|build|make|new)\s*[<(]/.test(p)||/(?:^|[\n;{])\s*static\s+(?:async\s+)?[A-Za-z_][A-Za-z0-9_]*\s*\([^)]*\)\s*:\s*[A-Za-z_]/.test(p),k=[],G=new Set(["if","match","when"]),z=/(?:^|\n)\s*(?:public\s+|private\s+|protected\s+|async\s+)*(?!constructor|get|set|static)([a-zA-Z_][a-zA-Z0-9_]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?\{/g,v;for(;(v=z.exec(p))!==null;){let b=v[1];if(G.has(b))continue;let Re=v.index+v[0].length,te=1,P=Re;for(;P<p.length&&te>0;)p[P]==="{"?te+=1:p[P]==="}"&&(te-=1),P+=1;let he=p.slice(Re,P-1);if(!/this\.\w+\s*=/.test(he))continue;let kt=/\b(ensureInvariants|assertInvariants|validate|publish|emit|raise|record)\b/.test(he);k.push({name:b,referencesGuardOrPublish:kt})}let Rt=(p.match(/(?:^|\n)\s*(?:public\s+|private\s+|protected\s+)?(?:async\s+)?[a-zA-Z_][a-zA-Z0-9_]*\s*\(/g)??[]).length,ht=(d.match(/(?:^|[\n;])\s*(?:public\s+)?(?!constructor|static|get|set|private|protected|readonly)[a-zA-Z_][a-zA-Z0-9_]*\s*[:=]/g)??[]).length,At=Rt<=1&&ht>=2&&(f||u);r.push({file:e,className:a,exported:!0,hasPublicMutableFields:f||u,hasPublicSetters:g,hasPublicConstructor:h,hasStaticFactory:A,mutatingMethods:[...k],dataOnly:At})}return r}l(de,"extractClassShapesFromSource");function ar(e){if(!e)return{};let t=typeof e.governedPercent=="number"?e.governedPercent:null,r=typeof e.populatedLayerCount=="number"?e.populatedLayerCount:null;return r==null&&typeof e.classifiedFiles=="number"&&(r=e.classifiedFiles>0?1:0),{governedPercent:t,populatedLayerCount:r}}l(ar,"normalizeExtraMergeTeethClassification");function J(e){let t=ar(e),r=typeof t.governedPercent=="number"?t.governedPercent:null,n=typeof t.populatedLayerCount=="number"?t.populatedLayerCount:null;return r==null&&n==null?!0:(r??0)>=50&&(n??0)>=1}l(J,"extraMergeTeethAllowed");var lr=["arkrun-kernel-in-domain","arkrun-direct-new","arkrun-transport-bypass"],cr=new Set(lr);function ur(e){return cr.has(e)}l(ur,"isArkRunEditorSensor");var qe={"arkrun-missing-root":"ARKRUN_MISSING_ROOT","arkrun-kernel-in-domain":"ARKRUN_KERNEL_IN_DOMAIN","arkrun-direct-new":"ARKRUN_DIRECT_NEW","arkrun-undeclared-emit":"ARKRUN_UNDECLARED_EMIT","arkrun-undeclared-handle":"ARKRUN_UNDECLARED_HANDLE","arkrun-undeclared-depend":"ARKRUN_UNDECLARED_DEPEND","arkrun-transport-bypass":"ARKRUN_TRANSPORT_BYPASS"},dr="ARKRUN_INTERACTION_NAME_INCOMPLETE";function Je(e,t=[]){let r=e.trim();return/^domain(?:model)?$/i.test(r)||/^domain(?=[A-Z_\-\s])/i.test(r)||/^(?:entit(?:y|ies)|aggregates?)(?:$|(?=[A-Z_\-\s]))/i.test(r)?!0:t.some(n=>{let o=n.trim().replace(/\.+$/,"");return o==="Domain"||o.startsWith("Domain.")})}l(Je,"isDomainRoleLayer");function pr(e,t){return e.file.localeCompare(t.file)||e.ruleId.localeCompare(t.ruleId)||e.line-t.line||e.message.localeCompare(t.message)}l(pr,"compareFindings");function N(e,t,r,n,o,a,s){let i=e.mode==="enforced"&&s;return{ruleId:qe[t],sensor:t,message:o,file:r,line:n,...a?.fromLayer?{fromLayer:a.fromLayer}:{},...a?.target?{target:a.target}:{},severity:i?"error":"warning",failsStrict:i,nextAction:D({ruleId:qe[t],fromLayer:a?.fromLayer,target:a?.target})}}l(N,"finding");function fr(e,t){let r=[],n=[],o=[],a=[];for(let s of e)s.file===t&&(r.push(...s.uses),n.push(...s.reactsTo),o.push(...s.raises),a.push(...s.sends));return{uses:new Set(r),reactsTo:new Set(n),raises:new Set(o),sends:new Set(a)}}l(fr,"bagForFile");function Ze(e){return e==="publisher"||e==="publish"||e==="raise"||e==="send"}l(Ze,"emitKinds");function Ye(e){return e==="subscribe"||e==="register-handler"}l(Ye,"handleKinds");function gr(e){return e==="resolve"||e==="resolve-singleton"}l(gr,"dependKinds");function mr(e,t,r){let n=[],o=e.kernelRoots??e.compositionRoots;if(o.length===0)return n.push(N(e,"arkrun-missing-root","ark.config.json",1,"ArkRun kernelRoots is empty; no createArkKernel factory site is declared.",void 0,r)),n;let a=new Map;for(let s of t){let i=a.get(s.matchedRoot)??[];i.push(s),a.set(s.matchedRoot,i)}for(let s of o){let i=[...a.get(s)??[]].sort((p,d)=>p.file.localeCompare(d.file));if(i.length===0){n.push(N(e,"arkrun-missing-root","ark.config.json",1,`ArkRun kernel root ${JSON.stringify(s)} matched no governed files and has no createArkKernel factory.`,{target:s},r));continue}if(i.some(p=>p.hasKernelFactory))continue;let c=i[0];n.push(N(e,"arkrun-missing-root",c.file,1,`ArkRun kernel root ${JSON.stringify(s)} has no createArkKernel / createStrictArkKernel factory.`,{target:s},r))}return n}l(mr,"evaluateMissingRoot");function yr(e,t,r,n,o){let a=new Map(t.map(i=>[i.name,i.intentPrefixes??[]])),s=[];for(let i of r){let c=i.specifier;if(!c||!F(c))continue;let p=n(i.from);p&&Je(p,a.get(p)??[])&&s.push(N(e,"arkrun-kernel-in-domain",i.from,i.line,`${p} must not import kernel module ${JSON.stringify(c)}.`,{fromLayer:p,target:c},o))}return s}l(yr,"evaluateKernelInDomain");function Rr(e,t,r,n,o,a){let s=new Set(e.managedLayers);if(s.size===0)return[];let i=new Map(t.map(d=>[d.name,d.intentPrefixes??[]])),c=new Set(n.filter(d=>d.hasKernelFactory).map(d=>d.file)),p=[];for(let d of r){if(c.has(d.file))continue;let u=d.typeName;if(e.ignoreDirectNewForErrors!==!1&&(u.endsWith("Error")||u==="Error")||u.endsWith("DTO")||u.endsWith("VO"))continue;let f=o(d.file);!f||!s.has(f)||Je(f,i.get(f)??[])||p.push(N(e,"arkrun-direct-new",d.file,d.line,`${f} must not construct ${d.typeName} with new outside an ArkRun composition-root factory.`,{fromLayer:f,target:d.typeName},a))}return p}l(Rr,"evaluateDirectNew");function hr(e,t,r,n,o){let a=[],s=[];if(e.requireDeclarations!==!0)return{findings:a,completenessReasons:s};let i=new Set(e.managedLayers);if(i.size===0)return{findings:a,completenessReasons:s};for(let c of t){if(!Ze(c.kind)&&!Ye(c.kind)&&!gr(c.kind))continue;let p=n(c.file);if(!p||!i.has(p))continue;if(!c.nameLiteral){e.mode==="enforced"&&s.push({code:dr,file:c.file,message:`ArkRun ${c.kind} call in ${c.file} has no string-literal name; enforced extra cannot prove the declaration.`});continue}let d=fr(r,c.file);if(Ze(c.kind)){if(d.raises.has(c.nameLiteral)||d.sends.has(c.nameLiteral))continue;a.push(N(e,"arkrun-undeclared-emit",c.file,c.line,`Emit ${JSON.stringify(c.nameLiteral)} is not declared in raises or sends.`,{fromLayer:p,target:c.nameLiteral},o));continue}if(Ye(c.kind)){if(d.reactsTo.has(c.nameLiteral))continue;a.push(N(e,"arkrun-undeclared-handle",c.file,c.line,`Handle ${JSON.stringify(c.nameLiteral)} is not declared in reactsTo.`,{fromLayer:p,target:c.nameLiteral},o));continue}d.uses.has(c.nameLiteral)||a.push(N(e,"arkrun-undeclared-depend",c.file,c.line,`Depend ${JSON.stringify(c.nameLiteral)} is not declared in uses.`,{fromLayer:p,target:c.nameLiteral},o))}return{findings:a,completenessReasons:s}}l(hr,"evaluateUndeclared");function Ar(e,t,r,n){let o=new Set(e.managedLayers);if(o.size===0)return[];let a=[];for(let s of t){if(s.typeOnly)continue;let i=s.specifier;if(!i||!Ge(i))continue;let c=r(s.from);!c||!o.has(c)||a.push(N(e,"arkrun-transport-bypass",s.from,s.line,`${c} must not import broker/queue/emitter ${JSON.stringify(i)}; use the ArkRun kernel transport.`,{fromLayer:c,target:i},n))}return a}l(Ar,"evaluateTransportBypass");function kr(e){let t=e.arkRun;if(!t)return{findings:[],completenessReasons:[]};let r=J(e.classification),n=hr(t,e.kernelCalls,e.declarations,e.layerForFile,r),o=[...mr(t,e.compositionRootHits,r),...yr(t,e.layers,e.dependencies,e.layerForFile,r),...Rr(t,e.layers,e.managedNews,e.compositionRootHits,e.layerForFile,r),...n.findings,...Ar(t,e.dependencies,e.layerForFile,r)].sort(pr),a=[...n.completenessReasons].sort((s,i)=>{let c=`${s.code}\0${s.file??""}\0${s.message}`,p=`${i.code}\0${i.file??""}\0${i.message}`;return c<p?-1:c>p?1:0});return{findings:o,completenessReasons:a}}l(kr,"evaluateArkRunSensors");function pe(e){return{findings:kr(e).findings.filter(r=>ur(r.sensor)),completenessReasons:[]}}l(pe,"evaluateArkRunEditorSensors");function br(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let t=e.specifiers??[];return t.length===0?!1:t.every(r=>r.type==="ImportSpecifier")?t.every(r=>r.importKind==="type"):t.every(r=>r.exportKind==="type")}l(br,"declarationIsTypeOnly");function et(e){try{return Xe.existsSync(e)?Xe.readFileSync(e,"utf8"):null}catch{return null}}l(et,"readUtf8");function Qe(e,t){let r=e.lintedFilename(t),n=e.findConfigPath(r),o=n?e.loadArkConfig(n):null;if(!o?.arkRun||!n||!r)return null;let a=O.dirname(n),s=O.isAbsolute(r)?r:O.resolve(r),i=O.relative(a,s).split(O.sep).join("/");if(!e.sourceIsInAnalysisScope(o,i))return null;let c=E(i,o.layers);return c?{extra:o.arkRun,config:o,root:a,absFile:s,relFile:i,fromLayer:c}:null}l(Qe,"loadEditorFile");function Er(e,t,r){let n=Y(t,r).some(a=>a.kind==="factory"),o=[];for(let a of e.compositionRoots){try{if(!L(a).test(t))continue}catch{continue}o.push({file:t,matchedRoot:a,hasKernelFactory:n})}return o}l(Er,"compositionRootHitsForFile");function Sr(e,t,r){let n=new Set(de(t.relFile,r).map(o=>o.className));return We(r,(o,a)=>{if(F(a))return;let s=e.resolveImportSpecifier(t.absFile,a,t.root);if(!s)return;let i=O.relative(t.root,s).split(O.sep).join("/");if(i.startsWith(".."))return;let c=et(s);if(c!==null)for(let p of de(i,c))n.add(p.className)}),n}l(Sr,"admittedTypeNamesForEditor");function tt(e,t,r,n,o,a){e.reportAdapterDiagnostic(t,r,n,{ruleId:o.ruleId,file:o.file,fromLayer:o.fromLayer,target:o.target,message:o.message,line:o.line,severity:o.severity,failsStrict:o.failsStrict,nextAction:o.nextAction},a)}l(tt,"reportFinding");function Ir(e){let t=e.callee;if(t?.type==="Identifier"&&t.name&&/^[A-Z]/.test(t.name))return t.name;let r=t?.property?.name;if(r&&/^[A-Z]/.test(r)&&t?.computed!==!0)return r}l(Ir,"constructedTypeName");function xr(e,t){return e.type?.startsWith("Export")?"export":t}l(xr,"specifierEdgeKind");function Nr(e,t,r,n,o){let a=l((s,i,c,p)=>{if(typeof i!="string"||i.length===0)return;let d=s.loc?.start?.line??1,u={from:r.relFile,specifier:i,kind:p,typeOnly:c,line:d,resolution:"resolved-external"},{findings:f}=pe({arkRun:r.extra,layers:r.config.layers,kernelCalls:[],managedNews:[],compositionRootHits:[],declarations:[],dependencies:[u],layerForFile:l(g=>g===r.relFile?r.fromLayer:E(g,r.config.layers),"layerForFile")});for(let g of f)g.sensor===n&&tt(e,t,s,o,g,{fromLayer:g.fromLayer??r.fromLayer,specifier:i,target:g.target??i})},"check");return{ImportDeclaration(s){let i=s,c=(i.specifiers??[]).filter(d=>d.type==="ImportSpecifier"),p=c.length>0&&c.length===(i.specifiers??[]).length&&c.every(d=>d.importKind==="type");a(s,i.source?.value,i.importKind==="type"||p||br(s),"import")},ImportExpression(s){let i=s;i.source?.type==="Literal"&&a(s,i.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(s){let i=s;a(s,i.moduleReference?.expression?.value,i.importKind==="type"||i.isTypeOnly===!0,"require")},ExportNamedDeclaration(s){let i=s;if(!i.source)return;let c=i.specifiers??[],p=c.length>0&&c.every(d=>d.exportKind==="type");a(s,i.source.value,i.exportKind==="type"||p,xr(s,"export"))},ExportAllDeclaration(s){let i=s;a(s,i.source?.value,i.exportKind==="type","export")},CallExpression(s){let i=s;i.callee?.type==="Identifier"&&i.callee.name==="require"&&i.arguments?.[0]?.type==="Literal"&&!e.isLocallyBound(t,s,"require")&&a(s,i.arguments[0].value,!1,"require")}}}l(Nr,"importListeners");function _r(e,t,r){let n=et(r.absFile)??"",o=Sr(e,r,n),a=ue(r.relFile,n,o),{findings:s}=pe({arkRun:r.extra,layers:r.config.layers,kernelCalls:Y(r.relFile,n),managedNews:a,compositionRootHits:Er(r.extra,r.relFile,n),declarations:[],dependencies:[],layerForFile:l(c=>c===r.relFile?r.fromLayer:E(c,r.config.layers),"layerForFile")}),i=s.filter(c=>c.sensor==="arkrun-direct-new");return{NewExpression(c){let p=Ir(c);if(!p)return;let d=c.loc?.start?.line,u=i.find(f=>f.target===p&&(d===void 0||f.line===d))??i.find(f=>f.target===p);u&&tt(e,t,c,"directNew",u,{fromLayer:u.fromLayer??r.fromLayer,typeName:p,target:u.target??p})}}}l(_r,"directNewListener");function rt(e){let t=l((r,n,o,a)=>({meta:{type:"problem",docs:{description:n},messages:{[o]:a},schema:[]},create(s){let i=Qe(e,s);return i?Nr(e,s,i,r,o):{}}}),"createImportRule");return{noArkRunKernelInDomain:t("arkrun-kernel-in-domain","Disallow Domain-role imports of arkgate/runtime when arkRun is on (same sensor as ark-check).","kernelInDomain",'{{fromLayer}} must not import kernel module "{{specifier}}".'),noArkRunTransportBypass:t("arkrun-transport-bypass","Disallow homemade broker/queue/emitter imports in arkRun managed layers (same sensor as ark-check).","transportBypass",'{{fromLayer}} must not import broker/queue/emitter "{{specifier}}"; use the ArkRun kernel transport.'),noArkRunDirectNew:{meta:{type:"problem",docs:{description:"Disallow `new` of ArkRun-admitted types outside a composition-root factory (on-disk import/`new` envelope)."},messages:{directNew:"{{fromLayer}} must not construct {{typeName}} with new outside an ArkRun composition-root factory."},schema:[]},create(r){let n=Qe(e,r);return n?_r(e,r,n):{}}}}}l(rt,"createArkRunEslintRules");var Cr="createOrderPlane";function X(e){return e==="arkgate/order"||e.startsWith("arkgate/order/")}l(X,"isArkOrderModuleSpecifier");function nt(e,t){let r=1;for(let n=0;n<t&&n<e.length;n+=1)e[n]===`
|
|
8
|
-
`&&(r+=1);return r}l(nt,"lineAt");function ot(e){return e.replace(/\/\*[\s\S]*?\*\//g,t=>t.replace(/[^\n]/g," ")).replace(/(^|[^:])\/\/.*$/gm,t=>t.replace(/\/\/.*$/,r=>" ".repeat(r.length)))}l(ot,"stripCommentsPreservingLines");function st(e,t){let r=ot(t),n=[],o=/\bcreateOrderPlane\s*(?:<[^>]*>)?\s*\(/g,a;for(;(a=o.exec(r))!==null;)n.push({file:e,line:nt(t,a.index),callee:Cr});return n}l(st,"extractArkOrderPlaneCallsFromSource");function it(e,t){let r=ot(t),n=[],o=/\.((?:update|patch|set|mutate))\s*\(/g,a;for(;(a=o.exec(r))!==null;){let s=a[1],i=r.slice(Math.max(0,a.index-80),a.index);!/\b(?:plane|orderPlane|order)\s*$/.test(i)&&!/\bcreateOrderPlane\b/.test(r)||n.push({file:e,line:nt(t,a.index),method:s})}return n}l(it,"extractArkOrderGenericUpdatesFromSource");var at={"arkorder-missing-plane":"ARKORDER_MISSING_PLANE","arkorder-kernel-in-domain":"ARKORDER_KERNEL_IN_DOMAIN","arkorder-generic-update":"ARKORDER_GENERIC_UPDATE","arkorder-too-many-params":"ARKORDER_TOO_MANY_PARAMS","arkorder-ingest-writes-xi":"ARKORDER_INGEST_WRITES_XI"};function vr(e,t=[]){let r=e.trim();return/^domain(?:model)?$/i.test(r)||/^domain(?=[A-Z_\-\s])/i.test(r)?!0:t.some(n=>{let o=n.trim().replace(/\.+$/,"");return o==="Domain"||o.startsWith("Domain.")})}l(vr,"isDomainRoleLayer");function U(e,t,r,n,o,a,s){let i=e.mode==="enforced"&&s;return{ruleId:at[t],sensor:t,message:o,file:r,line:n,...a?.fromLayer?{fromLayer:a.fromLayer}:{},...a?.target?{target:a.target}:{},severity:i?"error":"warning",failsStrict:i,nextAction:D({ruleId:at[t],fromLayer:a?.fromLayer,target:a?.target})}}l(U,"finding");function Or(e){let t=e.arkOrder;if(!t)return{findings:[],completenessReasons:[]};let r=J(e.classification),n=[],o=t.planeRoots;if(t.mode==="enforced"&&o.length===0)n.push(U(t,"arkorder-missing-plane","ark.config.json",1,"ArkOrder planeRoots is empty; no createOrderPlane site is declared.",void 0,r));else{let s=new Map;for(let i of e.planeRootHits){let c=s.get(i.matchedRoot)??[];c.push(i),s.set(i.matchedRoot,c)}for(let i of o){let c=s.get(i)??[];if(c.length===0){n.push(U(t,"arkorder-missing-plane","ark.config.json",1,`ArkOrder plane root ${JSON.stringify(i)} matched no governed files and has no createOrderPlane factory.`,{target:i},r));continue}c.some(p=>p.hasPlaneFactory)||n.push(U(t,"arkorder-missing-plane",c[0].file,1,`ArkOrder plane root ${JSON.stringify(i)} has no createOrderPlane factory.`,{target:i},r))}}let a=new Map(e.layers.map(s=>[s.name,s.intentPrefixes??[]]));for(let s of e.dependencies){let i=s.specifier;if(!i||!X(i))continue;let c=e.layerForFile(s.from);c&&vr(c,a.get(c)??[])&&n.push(U(t,"arkorder-kernel-in-domain",s.from,s.line,"Domain-role layer imports arkgate/order; Domain stays plane-free.",{fromLayer:c,target:i},r))}for(let s of e.genericUpdates)n.push(U(t,"arkorder-generic-update",s.file,s.line,`Generic ${s.method}() on the order plane rewrites \u03BE; Haken forbids it.`,{target:s.method},r));return n.sort((s,i)=>s.file.localeCompare(i.file)||s.ruleId.localeCompare(i.ruleId)||s.line-i.line),{findings:n,completenessReasons:[]}}l(Or,"evaluateArkOrderSensors");function lt(e){if(!e.arkOrder)return[];let t=st(e.file,e.source),r=it(e.file,e.source);return Or({arkOrder:e.arkOrder,layers:[],planeCalls:t,genericUpdates:r,planeRootHits:[],dependencies:[],layerForFile:l(()=>e.fromLayer,"layerForFile")}).findings.filter(n=>n.sensor==="arkorder-generic-update"||n.sensor==="arkorder-kernel-in-domain")}l(lt,"evaluateArkOrderEditorSensors");function wr(e){let t=e;return t.sourceCode?.getText?.()??t.getSourceCode?.()?.getText?.()??""}l(wr,"eslintSourceText");function ct(e){function t(r){return{meta:{type:"problem",docs:{description:r},messages:{denied:"{{message}}"},schema:[]},create(n){let o=e.lintedFilename(n),a=e.findConfigPath(o),s=a?e.loadArkConfig(a):null;if(!s?.arkOrder)return{};let i=e.toProjectRelative(a,o);if(!e.sourceIsInAnalysisScope(s,i))return{};let c=E(i,s.layers);return{ImportDeclaration(p){let d=typeof p.source?.value=="string"?p.source.value:"";if(r==="ARKORDER_KERNEL_IN_DOMAIN"){if(!X(d)||c!=="DomainModel"&&!/^domain/i.test(c??""))return;e.reportAdapterDiagnostic(n,p,"denied",{ruleId:r,file:i,line:p.loc?.start?.line??1,message:"Domain-role layer imports arkgate/order; Domain stays plane-free."})}},Program(){if(r!=="ARKORDER_GENERIC_UPDATE")return;let p=wr(n),d=lt({arkOrder:s.arkOrder,file:i,source:p,fromLayer:c}).filter(u=>u.ruleId==="ARKORDER_GENERIC_UPDATE");for(let u of d)e.reportAdapterDiagnostic(n,{loc:{start:{line:u.line}}},"denied",{ruleId:u.ruleId,file:u.file,line:u.line,message:u.message})}}}}}return l(t,"createImportRule"),{noArkOrderKernelInDomain:t("ARKORDER_KERNEL_IN_DOMAIN"),noArkOrderGenericUpdate:t("ARKORDER_GENERIC_UPDATE")}}l(ct,"createArkOrderEslintRules");function w(e){if(typeof e.physicalFilename=="string"&&e.physicalFilename.length>0)return e.physicalFilename;if(typeof e.filename=="string"&&e.filename.length>0)return e.filename;if(typeof e.getFilename=="function")try{let t=e.getFilename();if(typeof t=="string"&&t.length>0)return t}catch{}return""}l(w,"lintedFilename");function C(e,t,r,n,o){let a=He({...n,line:n.line??t.loc?.start?.line,column:n.column??(typeof t.loc?.start?.column=="number"?t.loc.start.column+1:void 0)});return e.report({node:t,messageId:r,...o?{data:o}:{},diagnostic:a}),a}l(C,"reportAdapterDiagnostic");function j(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let t=m.dirname(m.resolve(e));for(;;){let r=m.join(t,"ark.config.json");if(_.existsSync(r))return r;let n=m.dirname(t);if(n===t)return null;t=n}}l(j,"findConfigPath");var ut=new Map;function V(e){if(!_.existsSync(e))return null;let t=_.readFileSync(e,"utf8"),r=ut.get(e);if(r?.source===t)return r.config;let n=$e(t,e).config;return ut.set(e,{source:t,config:n}),n}l(V,"loadArkConfig");function B(e,t){return(e.include??[]).some(n=>{let o=String(n).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return o==="."||t===o||t.startsWith(`${o}/`)})&&!Ie(t,e)}l(B,"sourceIsInAnalysisScope");function dt(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,m.join(e,"index.ts"),m.join(e,"index.tsx"),m.join(e,"index.js")];for(let r of t)try{if(_.existsSync(r)&&_.statSync(r).isFile())return r}catch{}return null}l(dt,"existingSourceFile");function Lr(e){let t=m.resolve(e),r=null;for(;;){let p=m.join(t,"tsconfig.json");if(_.existsSync(p)){r=p;break}let d=m.dirname(t);if(d===t)break;t=d}if(!r)return{baseUrl:e,aliases:[]};let n=l(p=>{try{let d=_.readFileSync(p,"utf8");return d=d.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(d)}catch{return null}},"loadJsonc"),o=l((p,d)=>{if(d>4)return{};let u=n(p);if(!u)return{};let f=u.compilerOptions??{},g=f.baseUrl,y=f.paths,h=u.extends;if(typeof h=="string"&&!h.startsWith("@")){let A=m.resolve(m.dirname(p),h.endsWith(".json")?h:`${h}.json`);if(_.existsSync(A)){let k=o(A,d+1);g=g??k.baseUrl,y={...k.paths??{},...y??{}}}}return{baseUrl:g,paths:y}},"mergePaths"),a=o(r,0),s=m.dirname(r),i=m.resolve(s,a.baseUrl||"."),c=[];for(let[p,d]of Object.entries(a.paths||{})){if(!Array.isArray(d)||d.length===0)continue;let u=p.replace(/\*$/,"");u&&c.push({from:u,to:String(d[0]).replace(/\*$/,"")})}return c.sort((p,d)=>d.from.length-p.from.length),{baseUrl:i,aliases:c}}l(Lr,"readTsconfigPathAliases");function Tr(e,t){if(!t.startsWith("."))return null;let r=m.resolve(m.dirname(e),t);return dt(r)}l(Tr,"resolveRelativeImport");function pt(e,t,r){if(!t)return null;if(t.startsWith("."))return Tr(e,t);let n=r||m.dirname(e),{baseUrl:o,aliases:a}=Lr(n),s=a.find(c=>t.startsWith(c.from));if(!s)return null;let i=m.resolve(o,`${s.to}${t.slice(s.from.length)}`);return dt(i)}l(pt,"resolveImportSpecifier");function ee(e){return typeof e?.value=="string"?e.value:void 0}l(ee,"stringValue");function me(e){return e?.name??ee(e)}l(me,"propertyName");function ye(e){return e.sourceCode??e.getSourceCode?.()}l(ye,"sourceCodeFor");function ft(e,t){let r=ye(e)?.getScope?.(t);for(;r;){let n=r.references?.find(o=>o.identifier===t);if(n)return n;r=r.upper??void 0}}l(ft,"referenceFor");function H(e,t,r){let n=ft(e,t);if(n?.resolved)return(n.resolved.defs?.length??0)>0;let o=ye(e)?.getScope?.(t);for(;o;){let a=o.set?.get(r);if(a)return(a.defs?.length??0)>0;o=o.upper??void 0}return!1}l(H,"isLocallyBound");function Dr(e,t){let r=ft(e,t);return r?r.isValueReference!==!1:t.parent?.type==="VariableDeclarator"&&t.parent.init===t}l(Dr,"isValueIdentifierReference");function gt(e){if(e?.type==="Identifier"&&e.name)return{root:e,segments:[e.name]};if(!e||!(e.type==="MemberExpression"||!!(e.object&&e.property))||e.computed===!0)return;let r=gt(e.object),n=me(e.property);if(!(!r||!n))return{root:r.root,segments:[...r.segments,n]}}l(gt,"memberExpressionPath");function Fr(e){return me(e.callee?.property)}l(Fr,"calleePropertyName");function mt(e,t){return e?.properties?.find(r=>me(r.key)===t)}l(mt,"objectProperty");function Q(e,t){return mt(e,t)!==void 0}l(Q,"objectHasProperty");function Pr(e){let t=mt(e,"metadata")?.value;return Q(t,"source")}l(Pr,"objectHasMetadataSource");function yt(e){return Fr(e)==="publish"}l(yt,"isPublishCall");function fe(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let t=e.specifiers??[];return t.length===0?!1:t.every(r=>r.type==="ImportSpecifier")?t.every(r=>r.importKind==="type"):t.every(r=>r.exportKind==="type")}l(fe,"declarationIsTypeOnly");function Kr(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}l(Kr,"containingProgram");function Mr(e){let t=Kr(e)?.body;if(!t)return!1;let r=!1;for(let n of t){if(n.type==="ImportDeclaration"){if(!fe(n))return!1;continue}if(!(n.type==="TSInterfaceDeclaration"||n.type==="TSTypeAliasDeclaration")){if(n.type==="ExportNamedDeclaration"){if(n.declaration){if(n.declaration.type!=="TSInterfaceDeclaration"&&n.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!fe(n))return!1;r=!0;continue}return!1}}return r}l(Mr,"sourceProgramExportsOnlyTypes");var $r={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{fromLayer}} must not import {{toLayer}} (ark.config.json). Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let t=w(e),r=j(t),n=r?V(r):null,o=r?m.dirname(r):null,a=l(s=>{let i=ee(s.source);if(i&&n&&o&&t){let c=m.isAbsolute(t)?t:m.resolve(t),p=m.relative(o,c).split(m.sep).join("/");if(!B(n,p))return;let d=E(p,n.layers);if(!d)return;let u=pt(c,i,o);if(!u)return;let f=m.relative(o,u).split(m.sep).join("/");if(f.startsWith(".."))return;let g=E(f,n.layers);if(!g)return;let y={fromPath:p,toPath:f,layers:n.layers},h=re(n.rules,d,g,y);if(h||Se(n.rules,d,g,y)){let A=s.type?.startsWith("Export")?"export":"import",k=fe(s),G=!!h?.peerIsolation,z=k&&!G,v=h?.message??`${d} must not ${A} ${g}.`;C(e,s,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:p,fromLayer:d,toLayer:g,target:f,edgeKind:A,...G?{peerIsolation:!0}:{},...k?{typeOnly:!0}:{},...z?{severity:"warning"}:{},...Mr(s)?{sourcePureTypeModule:!0}:{},message:z?`${v} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:v},{fromLayer:d,toLayer:g,specifier:i})}return}},"check");return{ImportDeclaration:a,ExportNamedDeclaration:a,ExportAllDeclaration:a}}},Ur={meta:{type:"problem",docs:{description:"Require event bus publish calls to use registered intent creators instead of raw event objects or intent strings."},messages:{rawPublish:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts."},schema:[]},create(e){return{CallExpression(t){let r=t.arguments?.[0],n=ee(r),o=ae({publishCall:yt(t),rawIntentName:n,objectHasIntent:Q(r,"intent"),arkPublishCandidate:!1,hasSource:!0});if(o.some(a=>a.ruleId==="RAW_EVENT_PUBLISH")){let a=o.find(s=>s.ruleId==="RAW_EVENT_PUBLISH");C(e,t,"rawPublish",{...a,file:w(e)})}}}}},Hr={meta:{type:"problem",docs:{description:"Require event bus publish calls to include source metadata."},messages:{missingSource:"Strict Ark publish calls must include metadata.source."},schema:[]},create(e){return{CallExpression(t){let r=t.arguments?.[0],n=t.arguments?.[2],a=ae({publishCall:yt(t),rawIntentName:ee(r),objectHasIntent:Q(r,"intent"),arkPublishCandidate:!0,hasSource:Pr(r)||Q(n,"source")}).find(s=>s.ruleId==="PUBLISH_MISSING_SOURCE");a&&C(e,t,"missingSource",{...a,file:w(e)})}}}},jr={meta:{type:"problem",docs:{description:"Disallow ambient globals from the layer\u2019s forbiddenGlobals in ark.config.json (same purity surface as ark-check). Option `globals` is a standalone fallback when no project config applies."},messages:{forbiddenGlobal:'Ambient global "{{name}}" is forbidden in {{layer}} (ark.config.json); inject the capability through a port instead.',forbiddenGlobalDefault:'Ambient global "{{name}}" is forbidden here; inject the capability through a port instead.',forbiddenModule:'{{layer}} must not use module "{{specifier}}" because it is the import form of forbidden global "{{name}}".'},schema:[{type:"object",properties:{globals:{type:"array",items:{type:"string"}}},additionalProperties:!1}]},create(e){let t=w(e),r=e.options?.[0],n=j(t),o=n?V(n):null,a=n?m.dirname(n):null,s=null,i="this layer";if(o&&a&&t){let u=m.isAbsolute(t)?t:m.resolve(t),f=m.relative(a,u).split(m.sep).join("/");if(!B(o,f))return{};let g=o.layers?.find(y=>y.name===E(f,o.layers));g?.forbiddenGlobals?.length?(s=new Set(g.forbiddenGlobals),i=g.name):s=null}else r?.globals&&(s=new Set(r.globals));if(!s)return{};let c=typeof ye(e)?.getScope=="function",p=l((u,f)=>{let g=m.isAbsolute(t)?t:m.resolve(t),y=a?m.relative(a,g).split(m.sep).join("/"):t;C(e,u,o?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:y,fromLayer:i,target:f,message:`${i} must not use the ambient global "${f}".`},{name:f,layer:i})},"report"),d=l((u,f,g,y)=>{if(g||typeof f!="string")return;let h=oe(f,s);if(!h)return;let A=m.isAbsolute(t)?t:m.resolve(t),k=a?m.relative(a,A).split(m.sep).join("/"):t;C(e,u,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:k,fromLayer:i,target:f,edgeKind:y,message:`${i} must not use module "${f}" because it is the import form of forbidden global "${h}".`},{layer:i,name:h,specifier:f,importKind:y})},"reportModule");return{MemberExpression(u){if(u.parent?.type==="MemberExpression"&&u.parent.object===u)return;let f=gt(u);if(!f||H(e,f.root,f.segments[0]))return;let g=f.segments[0]==="globalThis",y=g?f.segments.slice(1):f.segments,h;for(let A=y.length;A>=(g?1:2);A-=1){let k=y.slice(0,A).join(".");if(s.has(k)){h=k;break}}h?p(u,h):!c&&s.has(f.segments[0])&&p(u,f.segments[0])},CallExpression(u){let f=u;if(f.callee?.type==="Identifier"&&f.callee.name==="require"&&f.arguments?.[0]?.type==="Literal"&&!H(e,u,"require")&&d(u,f.arguments[0].value,!1,"require"),c)return;let g=f.callee?.type==="Identifier"?f.callee.name:void 0;g&&s.has(g)&&p(u,g)},ImportDeclaration(u){let f=u,g=(f.specifiers??[]).filter(h=>h.type==="ImportSpecifier"),y=g.length>0&&g.length===(f.specifiers??[]).length&&g.every(h=>h.importKind==="type");d(u,f.source?.value,f.importKind==="type"||y,"import")},ImportExpression(u){let f=u;f.source?.type==="Literal"&&d(u,f.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(u){let f=u;d(u,f.moduleReference?.expression?.value,f.importKind==="type"||f.isTypeOnly===!0,"require")},ExportNamedDeclaration(u){let f=u;if(!f.source)return;let g=f.specifiers??[],y=g.length>0&&g.every(h=>h.exportKind==="type");d(u,f.source.value,f.exportKind==="type"||y,"export")},ExportAllDeclaration(u){let f=u;d(u,f.source?.value,f.exportKind==="type","export")},NewExpression(u){if(c)return;let f=u.callee?.type==="Identifier"?u.callee.name:void 0;f&&s.has(f)&&p(u,f)},Identifier(u){!c||!u.name||!s.has(u.name)||!Dr(e,u)||H(e,u,u.name)||p(u,u.name)}}}},Vr={meta:{type:"problem",docs:{description:"Disallow importing modules whose effect capability the layer denies (ark.config.json capabilities.deny / pure \u2014 same wall surface as ark-check). Import dimension only: ambient globals stay with no-forbidden-globals and the CLI/hook symbol path."},messages:{deniedCapability:'{{layer}} denies the {{capability}} capability (ark.config.json); "{{specifier}}" imports it. Define a port and bind the implementation in an adapter layer.'},schema:[]},create(e){let t=w(e),r=j(t),n=r?V(r):null,o=r?m.dirname(r):null;if(!n||!o||!t)return{};let a=m.isAbsolute(t)?t:m.resolve(t),s=m.relative(o,a).split(m.sep).join("/");if(!B(n,s))return{};let i=n.layers?.find(d=>d.name===E(s,n.layers));if(!i)return{};let c=new Set(_e(i));if(c.size===0)return{};let p=l((d,u,f,g)=>{if(f||typeof u!="string"||oe(u,i.forbiddenGlobals??[]))return;let y=Ne(u);!y||!c.has(y)||C(e,d,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:s,fromLayer:i.name,target:u,capability:y,edgeKind:g,message:`${i.name} denies the ${y} capability; found import of "${u}".`},{layer:i.name,capability:y,specifier:u})},"check");return{ImportDeclaration(d){let u=d,f=(u.specifiers??[]).filter(y=>y.type==="ImportSpecifier"),g=f.length>0&&f.length===(u.specifiers??[]).length&&f.every(y=>y.importKind==="type");p(d,u.source?.value,u.importKind==="type"||g,"import")},ImportExpression(d){let u=d;u.source?.type==="Literal"&&p(d,u.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(d){let u=d;p(d,u.moduleReference?.expression?.value,u.importKind==="type"||u.isTypeOnly===!0,"require")},ExportNamedDeclaration(d){let u=d;if(!u.source)return;let f=u.specifiers??[],g=f.length>0&&f.every(y=>y.exportKind==="type");p(d,u.source.value,u.exportKind==="type"||g,"export")},ExportAllDeclaration(d){let u=d;p(d,u.source?.value,u.exportKind==="type","export")},CallExpression(d){let u=d;u.callee?.type==="Identifier"&&u.callee.name==="require"&&u.arguments?.[0]?.type==="Literal"&&!H(e,d,"require")&&p(d,u.arguments[0].value,!1,"require")}}}},{noArkRunKernelInDomain:Br,noArkRunDirectNew:Gr,noArkRunTransportBypass:zr}=rt({findConfigPath:j,loadArkConfig:V,resolveImportSpecifier:pt,lintedFilename:w,sourceIsInAnalysisScope:B,isLocallyBound:H,reportAdapterDiagnostic:C});function Wr(e,t){let r=m.dirname(m.resolve(e));return m.relative(r,m.resolve(t)).split(m.sep).join("/")}l(Wr,"toProjectRelative");var{noArkOrderKernelInDomain:qr,noArkOrderGenericUpdate:Zr}=ct({findConfigPath:j,loadArkConfig:V,lintedFilename:w,sourceIsInAnalysisScope:B,reportAdapterDiagnostic:C,toProjectRelative:Wr});var Yr={"no-domain-infra-imports":$r,"no-raw-event-publish":Ur,"require-publish-source":Hr,"no-forbidden-globals":jr,"no-denied-capabilities":Vr,"no-arkrun-kernel-in-domain":Br,"no-arkrun-direct-new":Gr,"no-arkrun-transport-bypass":zr,"no-arkorder-kernel-in-domain":qr,"no-arkorder-generic-update":Zr},ge={rules:Yr};ge.configs={recommended:{plugins:{ark:ge},rules:{"ark/no-domain-infra-imports":"error","ark/no-raw-event-publish":"error","ark/require-publish-source":"error","ark/no-forbidden-globals":"error","ark/no-denied-capabilities":"error","ark/no-arkrun-kernel-in-domain":"error","ark/no-arkrun-direct-new":"error","ark/no-arkrun-transport-bypass":"error","ark/no-arkorder-kernel-in-domain":"error","ark/no-arkorder-generic-update":"error"}}};var ao=ge;export{ao as default,j as findConfigPath,L as globToRegExp,Se as isEdgeDenied,E as layerForRelativePath,V as loadArkConfig,Zr as noArkOrderGenericUpdate,qr as noArkOrderKernelInDomain,Gr as noArkRunDirectNew,Br as noArkRunKernelInDomain,zr as noArkRunTransportBypass,Vr as noDeniedCapabilities,$r as noDomainInfraImports,jr as noForbiddenGlobals,Ur as noRawEventPublish,Ee as patternSpecificity,ge as plugin,Lr as readTsconfigPathAliases,Hr as requirePublishSource,pt as resolveImportSpecifier,Tr as resolveRelativeImport};
|
|
7
|
+
`)),g=/(?:^|[\n;{])\s*(?:public\s+)?set\s+[a-zA-Z_]/.test(d),y=/(?:^|[\n;{])\s*private\s+constructor\s*\(/.test(d),h=/(?:^|[\n;{])\s*(?:public\s+)?constructor\s*\(/.test(d)&&!y,A=/(?:^|[\n;{])\s*static\s+(?:async\s+)?(?:create|of|from|parse|build|make|new)\s*[<(]/.test(d)||/(?:^|[\n;{])\s*static\s+(?:async\s+)?[A-Za-z_][A-Za-z0-9_]*\s*\([^)]*\)\s*:\s*[A-Za-z_]/.test(d),k=[],z=new Set(["if","match","when"]),q=/(?:^|\n)\s*(?:public\s+|private\s+|protected\s+|async\s+)*(?!constructor|get|set|static)([a-zA-Z_][a-zA-Z0-9_]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?\{/g,w;for(;(w=q.exec(d))!==null;){let b=w[1];if(z.has(b))continue;let ke=w.index+w[0].length,se=1,M=ke;for(;M<d.length&&se>0;)d[M]==="{"?se+=1:d[M]==="}"&&(se-=1),M+=1;let be=d.slice(ke,M-1);if(!/this\.\w+\s*=/.test(be))continue;let xr=/\b(ensureInvariants|assertInvariants|validate|publish|emit|raise|record)\b/.test(be);k.push({name:b,referencesGuardOrPublish:xr})}let br=(d.match(/(?:^|\n)\s*(?:public\s+|private\s+|protected\s+)?(?:async\s+)?[a-zA-Z_][a-zA-Z0-9_]*\s*\(/g)??[]).length,Er=(u.match(/(?:^|[\n;])\s*(?:public\s+)?(?!constructor|static|get|set|private|protected|readonly)[a-zA-Z_][a-zA-Z0-9_]*\s*[:=]/g)??[]).length,Sr=br<=1&&Er>=2&&(f||p);t.push({file:e,className:o,exported:!0,hasPublicMutableFields:f||p,hasPublicSetters:g,hasPublicConstructor:h,hasStaticFactory:A,mutatingMethods:[...k],dataOnly:Sr})}return t}c(ge,"extractClassShapesFromSource");function dt(e){if(!e)return{};let r=typeof e.governedPercent=="number"?e.governedPercent:null,t=typeof e.populatedLayerCount=="number"?e.populatedLayerCount:null;return t==null&&typeof e.classifiedFiles=="number"&&(t=e.classifiedFiles>0?1:0),{governedPercent:r,populatedLayerCount:t}}c(dt,"normalizeExtraMergeTeethClassification");function Q(e){let r=dt(e),t=typeof r.governedPercent=="number"?r.governedPercent:null,n=typeof r.populatedLayerCount=="number"?r.populatedLayerCount:null;return t==null&&n==null?!0:(t??0)>=50&&(n??0)>=1}c(Q,"extraMergeTeethAllowed");var pt=["arkrun-kernel-in-domain","arkrun-direct-new","arkrun-transport-bypass"],ft=new Set(pt);function gt(e){return ft.has(e)}c(gt,"isArkRunEditorSensor");var Xe={"arkrun-missing-root":"ARKRUN_MISSING_ROOT","arkrun-kernel-in-domain":"ARKRUN_KERNEL_IN_DOMAIN","arkrun-direct-new":"ARKRUN_DIRECT_NEW","arkrun-undeclared-emit":"ARKRUN_UNDECLARED_EMIT","arkrun-undeclared-handle":"ARKRUN_UNDECLARED_HANDLE","arkrun-undeclared-depend":"ARKRUN_UNDECLARED_DEPEND","arkrun-transport-bypass":"ARKRUN_TRANSPORT_BYPASS"},mt="ARKRUN_INTERACTION_NAME_INCOMPLETE";function er(e,r=[]){let t=e.trim();return/^domain(?:model)?$/i.test(t)||/^domain(?=[A-Z_\-\s])/i.test(t)||/^(?:entit(?:y|ies)|aggregates?)(?:$|(?=[A-Z_\-\s]))/i.test(t)?!0:r.some(n=>{let s=n.trim().replace(/\.+$/,"");return s==="Domain"||s.startsWith("Domain.")})}c(er,"isDomainRoleLayer");function yt(e,r){return e.file.localeCompare(r.file)||e.ruleId.localeCompare(r.ruleId)||e.line-r.line||e.message.localeCompare(r.message)}c(yt,"compareFindings");function N(e,r,t,n,s,o,i){let a=e.mode==="enforced"&&i;return{ruleId:Xe[r],sensor:r,message:s,file:t,line:n,...o?.fromLayer?{fromLayer:o.fromLayer}:{},...o?.target?{target:o.target}:{},severity:a?"error":"warning",failsStrict:a,nextAction:K({ruleId:Xe[r],fromLayer:o?.fromLayer,target:o?.target})}}c(N,"finding");function Rt(e,r){let t=[],n=[],s=[],o=[];for(let i of e)i.file===r&&(t.push(...i.uses),n.push(...i.reactsTo),s.push(...i.raises),o.push(...i.sends));return{uses:new Set(t),reactsTo:new Set(n),raises:new Set(s),sends:new Set(o)}}c(Rt,"bagForFile");function Je(e){return e==="publisher"||e==="publish"||e==="raise"||e==="send"}c(Je,"emitKinds");function Qe(e){return e==="subscribe"||e==="register-handler"}c(Qe,"handleKinds");function ht(e){return e==="resolve"||e==="resolve-singleton"}c(ht,"dependKinds");function At(e,r,t){let n=[],s=e.kernelRoots??e.compositionRoots;if(s.length===0)return n.push(N(e,"arkrun-missing-root","ark.config.json",1,"ArkRun kernelRoots is empty; no createArkKernel factory site is declared.",void 0,t)),n;let o=new Map;for(let i of r){let a=o.get(i.matchedRoot)??[];a.push(i),o.set(i.matchedRoot,a)}for(let i of s){let a=[...o.get(i)??[]].sort((d,u)=>d.file.localeCompare(u.file));if(a.length===0){n.push(N(e,"arkrun-missing-root","ark.config.json",1,`ArkRun kernel root ${JSON.stringify(i)} matched no governed files and has no createArkKernel factory.`,{target:i},t));continue}if(a.some(d=>d.hasKernelFactory))continue;let l=a[0];n.push(N(e,"arkrun-missing-root",l.file,1,`ArkRun kernel root ${JSON.stringify(i)} has no createArkKernel / createStrictArkKernel factory.`,{target:i},t))}return n}c(At,"evaluateMissingRoot");function kt(e,r,t,n,s){let o=new Map(r.map(a=>[a.name,a.intentPrefixes??[]])),i=[];for(let a of t){let l=a.specifier;if(!l||!P(l))continue;let d=n(a.from);d&&er(d,o.get(d)??[])&&i.push(N(e,"arkrun-kernel-in-domain",a.from,a.line,`${d} must not import kernel module ${JSON.stringify(l)}.`,{fromLayer:d,target:l},s))}return i}c(kt,"evaluateKernelInDomain");function bt(e,r,t,n,s,o){let i=new Set(e.managedLayers);if(i.size===0)return[];let a=new Map(r.map(u=>[u.name,u.intentPrefixes??[]])),l=new Set(n.filter(u=>u.hasKernelFactory).map(u=>u.file)),d=[];for(let u of t){if(l.has(u.file))continue;let p=u.typeName;if(e.ignoreDirectNewForErrors!==!1&&(p.endsWith("Error")||p==="Error")||p.endsWith("DTO")||p.endsWith("VO"))continue;let f=s(u.file);!f||!i.has(f)||er(f,a.get(f)??[])||d.push(N(e,"arkrun-direct-new",u.file,u.line,`${f} must not construct ${u.typeName} with new outside an ArkRun composition-root factory.`,{fromLayer:f,target:u.typeName},o))}return d}c(bt,"evaluateDirectNew");function Et(e,r,t,n,s){let o=[],i=[];if(e.requireDeclarations!==!0)return{findings:o,completenessReasons:i};let a=new Set(e.managedLayers);if(a.size===0)return{findings:o,completenessReasons:i};for(let l of r){if(!Je(l.kind)&&!Qe(l.kind)&&!ht(l.kind))continue;let d=n(l.file);if(!d||!a.has(d))continue;if(!l.nameLiteral){e.mode==="enforced"&&i.push({code:mt,file:l.file,message:`ArkRun ${l.kind} call in ${l.file} has no string-literal name; enforced extra cannot prove the declaration.`});continue}let u=Rt(t,l.file);if(Je(l.kind)){if(u.raises.has(l.nameLiteral)||u.sends.has(l.nameLiteral))continue;o.push(N(e,"arkrun-undeclared-emit",l.file,l.line,`Emit ${JSON.stringify(l.nameLiteral)} is not declared in raises or sends.`,{fromLayer:d,target:l.nameLiteral},s));continue}if(Qe(l.kind)){if(u.reactsTo.has(l.nameLiteral))continue;o.push(N(e,"arkrun-undeclared-handle",l.file,l.line,`Handle ${JSON.stringify(l.nameLiteral)} is not declared in reactsTo.`,{fromLayer:d,target:l.nameLiteral},s));continue}u.uses.has(l.nameLiteral)||o.push(N(e,"arkrun-undeclared-depend",l.file,l.line,`Depend ${JSON.stringify(l.nameLiteral)} is not declared in uses.`,{fromLayer:d,target:l.nameLiteral},s))}return{findings:o,completenessReasons:i}}c(Et,"evaluateUndeclared");function St(e,r,t,n){let s=new Set(e.managedLayers);if(s.size===0)return[];let o=[];for(let i of r){if(i.typeOnly)continue;let a=i.specifier;if(!a||!qe(a))continue;let l=t(i.from);!l||!s.has(l)||o.push(N(e,"arkrun-transport-bypass",i.from,i.line,`${l} must not import broker/queue/emitter ${JSON.stringify(a)}; use the ArkRun kernel transport.`,{fromLayer:l,target:a},n))}return o}c(St,"evaluateTransportBypass");function xt(e){let r=e.arkRun;if(!r)return{findings:[],completenessReasons:[]};let t=Q(e.classification),n=Et(r,e.kernelCalls,e.declarations,e.layerForFile,t),s=[...At(r,e.compositionRootHits,t),...kt(r,e.layers,e.dependencies,e.layerForFile,t),...bt(r,e.layers,e.managedNews,e.compositionRootHits,e.layerForFile,t),...n.findings,...St(r,e.dependencies,e.layerForFile,t)].sort(yt),o=[...n.completenessReasons].sort((i,a)=>{let l=`${i.code}\0${i.file??""}\0${i.message}`,d=`${a.code}\0${a.file??""}\0${a.message}`;return l<d?-1:l>d?1:0});return{findings:s,completenessReasons:o}}c(xt,"evaluateArkRunSensors");function me(e){return{findings:xt(e).findings.filter(t=>gt(t.sensor)),completenessReasons:[]}}c(me,"evaluateArkRunEditorSensors");function It(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let r=e.specifiers??[];return r.length===0?!1:r.every(t=>t.type==="ImportSpecifier")?r.every(t=>t.importKind==="type"):r.every(t=>t.exportKind==="type")}c(It,"declarationIsTypeOnly");function nr(e){try{return rr.existsSync(e)?rr.readFileSync(e,"utf8"):null}catch{return null}}c(nr,"readUtf8");function tr(e,r){let t=e.lintedFilename(r),n=e.findConfigPath(t),s=n?e.loadArkConfig(n):null;if(!s?.arkRun||!n||!t)return null;let o=v.dirname(n),i=v.isAbsolute(t)?t:v.resolve(t),a=v.relative(o,i).split(v.sep).join("/");if(!e.sourceIsInAnalysisScope(s,a))return null;let l=E(a,s.layers);return l?{extra:s.arkRun,config:s,root:o,absFile:i,relFile:a,fromLayer:l}:null}c(tr,"loadEditorFile");function Nt(e,r,t){let n=J(r,t).some(o=>o.kind==="factory"),s=[];for(let o of e.compositionRoots){try{if(!T(o).test(r))continue}catch{continue}s.push({file:r,matchedRoot:o,hasKernelFactory:n})}return s}c(Nt,"compositionRootHitsForFile");function _t(e,r,t){let n=new Set(ge(r.relFile,t).map(s=>s.className));return Ye(t,(s,o)=>{if(P(o))return;let i=e.resolveImportSpecifier(r.absFile,o,r.root);if(!i)return;let a=v.relative(r.root,i).split(v.sep).join("/");if(a.startsWith(".."))return;let l=nr(i);if(l!==null)for(let d of ge(a,l))n.add(d.className)}),n}c(_t,"admittedTypeNamesForEditor");function sr(e,r,t,n,s,o){e.reportAdapterDiagnostic(r,t,n,{ruleId:s.ruleId,file:s.file,fromLayer:s.fromLayer,target:s.target,message:s.message,line:s.line,severity:s.severity,failsStrict:s.failsStrict,nextAction:s.nextAction},o)}c(sr,"reportFinding");function Ct(e){let r=e.callee;if(r?.type==="Identifier"&&r.name&&/^[A-Z]/.test(r.name))return r.name;let t=r?.property?.name;if(t&&/^[A-Z]/.test(t)&&r?.computed!==!0)return t}c(Ct,"constructedTypeName");function Ot(e,r){return e.type?.startsWith("Export")?"export":r}c(Ot,"specifierEdgeKind");function wt(e,r,t,n,s){let o=c((i,a,l,d)=>{if(typeof a!="string"||a.length===0)return;let u=i.loc?.start?.line??1,p={from:t.relFile,specifier:a,kind:d,typeOnly:l,line:u,resolution:"resolved-external"},{findings:f}=me({arkRun:t.extra,layers:t.config.layers,kernelCalls:[],managedNews:[],compositionRootHits:[],declarations:[],dependencies:[p],layerForFile:c(g=>g===t.relFile?t.fromLayer:E(g,t.config.layers),"layerForFile")});for(let g of f)g.sensor===n&&sr(e,r,i,s,g,{fromLayer:g.fromLayer??t.fromLayer,specifier:a,target:g.target??a})},"check");return{ImportDeclaration(i){let a=i,l=(a.specifiers??[]).filter(u=>u.type==="ImportSpecifier"),d=l.length>0&&l.length===(a.specifiers??[]).length&&l.every(u=>u.importKind==="type");o(i,a.source?.value,a.importKind==="type"||d||It(i),"import")},ImportExpression(i){let a=i;a.source?.type==="Literal"&&o(i,a.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(i){let a=i;o(i,a.moduleReference?.expression?.value,a.importKind==="type"||a.isTypeOnly===!0,"require")},ExportNamedDeclaration(i){let a=i;if(!a.source)return;let l=a.specifiers??[],d=l.length>0&&l.every(u=>u.exportKind==="type");o(i,a.source.value,a.exportKind==="type"||d,Ot(i,"export"))},ExportAllDeclaration(i){let a=i;o(i,a.source?.value,a.exportKind==="type","export")},CallExpression(i){let a=i;a.callee?.type==="Identifier"&&a.callee.name==="require"&&a.arguments?.[0]?.type==="Literal"&&!e.isLocallyBound(r,i,"require")&&o(i,a.arguments[0].value,!1,"require")}}}c(wt,"importListeners");function vt(e,r,t){let n=nr(t.absFile)??"",s=_t(e,t,n),o=fe(t.relFile,n,s),{findings:i}=me({arkRun:t.extra,layers:t.config.layers,kernelCalls:J(t.relFile,n),managedNews:o,compositionRootHits:Nt(t.extra,t.relFile,n),declarations:[],dependencies:[],layerForFile:c(l=>l===t.relFile?t.fromLayer:E(l,t.config.layers),"layerForFile")}),a=i.filter(l=>l.sensor==="arkrun-direct-new");return{NewExpression(l){let d=Ct(l);if(!d)return;let u=l.loc?.start?.line,p=a.find(f=>f.target===d&&(u===void 0||f.line===u))??a.find(f=>f.target===d);p&&sr(e,r,l,"directNew",p,{fromLayer:p.fromLayer??t.fromLayer,typeName:d,target:p.target??d})}}}c(vt,"directNewListener");function or(e){let r=c((t,n,s,o)=>({meta:{type:"problem",docs:{description:n},messages:{[s]:o},schema:[]},create(i){let a=tr(e,i);return a?wt(e,i,a,t,s):{}}}),"createImportRule");return{noArkRunKernelInDomain:r("arkrun-kernel-in-domain","Disallow Domain-role imports of arkgate/runtime when arkRun is on (same sensor as ark-check).","kernelInDomain",'{{fromLayer}} must not import kernel module "{{specifier}}".'),noArkRunTransportBypass:r("arkrun-transport-bypass","Disallow homemade broker/queue/emitter imports in arkRun managed layers (same sensor as ark-check).","transportBypass",'{{fromLayer}} must not import broker/queue/emitter "{{specifier}}"; use the ArkRun kernel transport.'),noArkRunDirectNew:{meta:{type:"problem",docs:{description:"Disallow `new` of ArkRun-admitted types outside a composition-root factory (on-disk import/`new` envelope)."},messages:{directNew:"{{fromLayer}} must not construct {{typeName}} with new outside an ArkRun composition-root factory."},schema:[]},create(t){let n=tr(e,t);return n?vt(e,t,n):{}}}}}c(or,"createArkRunEslintRules");var Lt="createOrderPlane";var Tt=/\bfrom\s+['"](?:@?prisma\/client|@supabase\/|drizzle-orm|typeorm|knex|mongodb|pg|mysql2|mongoose|better-sqlite3|ioredis|redis|kysely|sequelize)['"]|require\(\s*['"](?:@?prisma\/client|pg|knex|typeorm|mongoose)/,Dt=/\.(?:insert(?:One|Many)?|update(?:One|Many)?|upsert|delete(?:One|Many)?|createMany|create|replaceOne|findOneAnd(?:Update|Delete|Replace))\s*\(|\bINSERT\s+INTO\b|\bUPDATE\s+[A-Za-z_][\w.]*\s+SET\b|\bDELETE\s+FROM\b/i;function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c(ee,"escapeRegExp");function re(e){return e==="arkgate/order"||e.startsWith("arkgate/order/")}c(re,"isArkOrderModuleSpecifier");function H(e,r){let t=1;for(let n=0;n<r&&n<e.length;n+=1)e[n]===`
|
|
8
|
+
`&&(t+=1);return t}c(H,"lineAt");function j(e){return e.replace(/\/\*[\s\S]*?\*\//g,r=>r.replace(/[^\n]/g," ")).replace(/(^|[^:])\/\/.*$/gm,r=>r.replace(/\/\/.*$/,t=>" ".repeat(t.length)))}c(j,"stripCommentsPreservingLines");function ir(e,r){let t=j(r),n=[],s=/\bcreateOrderPlane\s*(?:<[^>]*>)?\s*\(/g,o;for(;(o=s.exec(t))!==null;)n.push({file:e,line:H(r,o.index),callee:Lt});return n}c(ir,"extractArkOrderPlaneCallsFromSource");function ar(e,r){let t=j(r),n=[],s=/\.((?:update|patch|set|mutate))\s*\(/g,o;for(;(o=s.exec(t))!==null;){let i=o[1],a=t.slice(Math.max(0,o.index-80),o.index);!/\b(?:plane|orderPlane|order)\s*$/.test(a)&&!/\bcreateOrderPlane\b/.test(t)||n.push({file:e,line:H(r,o.index),method:i})}return n}c(ar,"extractArkOrderGenericUpdatesFromSource");function lr(e,r,t){if(t.length===0)return[];let n=j(r);if(!Tt.test(n)||!Dt.test(n))return[];let s=[],o=new Set;for(let i of t){if(!i)continue;let a=new RegExp(`(?:\\b${ee(i)}\\s*:\\s*(?!string\\b|number\\b|boolean\\b|null\\b|[A-Z])|['"]${ee(i)}['"]\\s*:|[{\\,]\\s*${ee(i)}\\s*[\\,}]|\\.${ee(i)}\\s*=)`,"g"),l;for(;(l=a.exec(n))!==null;){let d=`${i}:${l.index}`;if(!o.has(d)){o.add(d),s.push({file:e,line:H(r,l.index),key:i});break}}}return s}c(lr,"extractArkOrderXiFieldWritesFromSource");function cr(e,r){let t=j(r),n=[],s=/(?:\b(?:xi|release|current|pattern|house)\w*|\.xi)\s*=\s*[^\n;]{0,160}?\bingest\s*\(/gi,o;for(;(o=s.exec(t))!==null;)n.push({file:e,line:H(r,o.index)});return n}c(cr,"extractArkOrderIngestWritesXiFromSource");function ur(e,r){let t=j(r),n=[],s=/\.release\s*\(\s*\{([^}]*)\}/g,o;for(;(o=s.exec(t))!==null;){let a=(o[1]??"").match(/\b[A-Za-z_][\w]*\s*:/g)??[];a.length!==0&&n.push({file:e,line:H(r,o.index),keyCount:a.length})}return n}c(ur,"extractArkOrderReleaseKeyCountsFromSource");var dr={"arkorder-missing-plane":"ARKORDER_MISSING_PLANE","arkorder-kernel-in-domain":"ARKORDER_KERNEL_IN_DOMAIN","arkorder-generic-update":"ARKORDER_GENERIC_UPDATE","arkorder-too-many-params":"ARKORDER_TOO_MANY_PARAMS","arkorder-ingest-writes-xi":"ARKORDER_INGEST_WRITES_XI","arkorder-xi-field-write":"ARKORDER_XI_FIELD_WRITE"};function Ft(e,r=[]){let t=e.trim();return/^domain(?:model)?$/i.test(t)||/^domain(?=[A-Z_\-\s])/i.test(t)?!0:r.some(n=>{let s=n.trim().replace(/\.+$/,"");return s==="Domain"||s.startsWith("Domain.")})}c(Ft,"isDomainRoleLayer");function _(e,r,t,n,s,o,i){let a=e.mode==="enforced"&&i;return{ruleId:dr[r],sensor:r,message:s,file:t,line:n,...o?.fromLayer?{fromLayer:o.fromLayer}:{},...o?.target?{target:o.target}:{},severity:a?"error":"warning",failsStrict:a,nextAction:K({ruleId:dr[r],fromLayer:o?.fromLayer,target:o?.target})}}c(_,"finding");function Kt(e){let r=e.arkOrder;if(!r)return{findings:[],completenessReasons:[]};let t=Q(e.classification),n=[],s=r.planeRoots;if(r.mode==="enforced"&&s.length===0)n.push(_(r,"arkorder-missing-plane","ark.config.json",1,"ArkOrder planeRoots is empty; no createOrderPlane site is declared.",void 0,t));else{let l=new Map;for(let d of e.planeRootHits){let u=l.get(d.matchedRoot)??[];u.push(d),l.set(d.matchedRoot,u)}for(let d of s){let u=l.get(d)??[];if(u.length===0){n.push(_(r,"arkorder-missing-plane","ark.config.json",1,`ArkOrder plane root ${JSON.stringify(d)} matched no governed files and has no createOrderPlane factory.`,{target:d},t));continue}u.some(p=>p.hasPlaneFactory)||n.push(_(r,"arkorder-missing-plane",u[0].file,1,`ArkOrder plane root ${JSON.stringify(d)} has no createOrderPlane factory.`,{target:d},t))}}let o=new Map(e.layers.map(l=>[l.name,l.intentPrefixes??[]]));for(let l of e.dependencies){let d=l.specifier;if(!d||!re(d))continue;let u=e.layerForFile(l.from);u&&Ft(u,o.get(u)??[])&&n.push(_(r,"arkorder-kernel-in-domain",l.from,l.line,"Domain-role layer imports arkgate/order; Domain stays plane-free.",{fromLayer:u,target:d},t))}for(let l of e.genericUpdates)n.push(_(r,"arkorder-generic-update",l.file,l.line,`Generic ${l.method}() on the order plane rewrites \u03BE; Haken forbids it.`,{target:l.method},t));let i=r.xiKeys??[];i.length>r.maxXiKeys&&n.push(_(r,"arkorder-too-many-params","ark.config.json",1,`arkOrder.xiKeys has ${i.length} keys; maxXiKeys is ${r.maxXiKeys} (few slow modes).`,{target:String(i.length)},t));for(let l of e.releaseKeyCounts??[])l.keyCount<=r.maxXiKeys||n.push(_(r,"arkorder-too-many-params",l.file,l.line,`release() freezes ${l.keyCount} keys; maxXiKeys is ${r.maxXiKeys} (few slow modes).`,{target:String(l.keyCount)},t));for(let l of e.ingestWritesXi??[])n.push(_(r,"arkorder-ingest-writes-xi",l.file,l.line,"ingest() result is assigned into a Release or \u03BE store; ingest may absorb or escalate, never mint a pattern.",void 0,t));let a=new Set(r.managedLayers);for(let l of i.length===0?[]:e.xiFieldWrites??[]){let d=e.layerForFile(l.file);!d||!a.has(d)||n.push(_(r,"arkorder-xi-field-write",l.file,l.line,`File writes slow key ${JSON.stringify(l.key)} through a persistence driver; route the field through ingest or a pattern change through proposeRelease.`,{fromLayer:d,target:l.key},t))}return n.sort((l,d)=>l.file.localeCompare(d.file)||l.ruleId.localeCompare(d.ruleId)||l.line-d.line),{findings:n,completenessReasons:[]}}c(Kt,"evaluateArkOrderSensors");function pr(e){if(!e.arkOrder)return[];let r=ir(e.file,e.source),t=ar(e.file,e.source),n=e.arkOrder.xiKeys??[];return Kt({arkOrder:e.arkOrder,layers:[],planeCalls:r,genericUpdates:t,planeRootHits:[],xiFieldWrites:lr(e.file,e.source,n),ingestWritesXi:cr(e.file,e.source),releaseKeyCounts:ur(e.file,e.source),dependencies:[],layerForFile:c(()=>e.fromLayer,"layerForFile")}).findings.filter(s=>s.sensor==="arkorder-generic-update"||s.sensor==="arkorder-kernel-in-domain"||s.sensor==="arkorder-xi-field-write"||s.sensor==="arkorder-ingest-writes-xi"||s.sensor==="arkorder-too-many-params")}c(pr,"evaluateArkOrderEditorSensors");function Pt(e){let r=e;return r.sourceCode?.getText?.()??r.getSourceCode?.()?.getText?.()??""}c(Pt,"eslintSourceText");function fr(e){function r(t){return{meta:{type:"problem",docs:{description:t},messages:{denied:"{{message}}"},schema:[]},create(n){let s=e.lintedFilename(n),o=e.findConfigPath(s),i=o?e.loadArkConfig(o):null;if(!i?.arkOrder)return{};let a=e.toProjectRelative(o,s);if(!e.sourceIsInAnalysisScope(i,a))return{};let l=E(a,i.layers);return{ImportDeclaration(d){let u=typeof d.source?.value=="string"?d.source.value:"";if(t==="ARKORDER_KERNEL_IN_DOMAIN"){if(!re(u)||l!=="DomainModel"&&!/^domain/i.test(l??""))return;e.reportAdapterDiagnostic(n,d,"denied",{ruleId:t,file:a,line:d.loc?.start?.line??1,message:"Domain-role layer imports arkgate/order; Domain stays plane-free."})}},Program(){if(t!=="ARKORDER_GENERIC_UPDATE")return;let d=Pt(n),u=pr({arkOrder:i.arkOrder,file:a,source:d,fromLayer:l}).filter(p=>p.ruleId!=="ARKORDER_KERNEL_IN_DOMAIN");for(let p of u)e.reportAdapterDiagnostic(n,{loc:{start:{line:p.line}}},"denied",{ruleId:p.ruleId,file:p.file,line:p.line,message:p.message})}}}}}return c(r,"createImportRule"),{noArkOrderKernelInDomain:r("ARKORDER_KERNEL_IN_DOMAIN"),noArkOrderGenericUpdate:r("ARKORDER_GENERIC_UPDATE")}}c(fr,"createArkOrderEslintRules");function L(e){if(typeof e.physicalFilename=="string"&&e.physicalFilename.length>0)return e.physicalFilename;if(typeof e.filename=="string"&&e.filename.length>0)return e.filename;if(typeof e.getFilename=="function")try{let r=e.getFilename();if(typeof r=="string"&&r.length>0)return r}catch{}return""}c(L,"lintedFilename");function O(e,r,t,n,s){let o=Be({...n,line:n.line??r.loc?.start?.line,column:n.column??(typeof r.loc?.start?.column=="number"?r.loc.start.column+1:void 0)});return e.report({node:r,messageId:t,...s?{data:s}:{},diagnostic:o}),o}c(O,"reportAdapterDiagnostic");function B(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let r=m.dirname(m.resolve(e));for(;;){let t=m.join(r,"ark.config.json");if(C.existsSync(t))return t;let n=m.dirname(r);if(n===r)return null;r=n}}c(B,"findConfigPath");var gr=new Map;function G(e){if(!C.existsSync(e))return null;let r=C.readFileSync(e,"utf8"),t=gr.get(e);if(t?.source===r)return t.config;let n=je(r,e).config;return gr.set(e,{source:r,config:n}),n}c(G,"loadArkConfig");function W(e,r){return(e.include??[]).some(n=>{let s=String(n).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||r===s||r.startsWith(`${s}/`)})&&!_e(r,e)}c(W,"sourceIsInAnalysisScope");function mr(e){let r=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,m.join(e,"index.ts"),m.join(e,"index.tsx"),m.join(e,"index.js")];for(let t of r)try{if(C.existsSync(t)&&C.statSync(t).isFile())return t}catch{}return null}c(mr,"existingSourceFile");function Mt(e){let r=m.resolve(e),t=null;for(;;){let d=m.join(r,"tsconfig.json");if(C.existsSync(d)){t=d;break}let u=m.dirname(r);if(u===r)break;r=u}if(!t)return{baseUrl:e,aliases:[]};let n=c(d=>{try{let u=C.readFileSync(d,"utf8");return u=u.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(u)}catch{return null}},"loadJsonc"),s=c((d,u)=>{if(u>4)return{};let p=n(d);if(!p)return{};let f=p.compilerOptions??{},g=f.baseUrl,y=f.paths,h=p.extends;if(typeof h=="string"&&!h.startsWith("@")){let A=m.resolve(m.dirname(d),h.endsWith(".json")?h:`${h}.json`);if(C.existsSync(A)){let k=s(A,u+1);g=g??k.baseUrl,y={...k.paths??{},...y??{}}}}return{baseUrl:g,paths:y}},"mergePaths"),o=s(t,0),i=m.dirname(t),a=m.resolve(i,o.baseUrl||"."),l=[];for(let[d,u]of Object.entries(o.paths||{})){if(!Array.isArray(u)||u.length===0)continue;let p=d.replace(/\*$/,"");p&&l.push({from:p,to:String(u[0]).replace(/\*$/,"")})}return l.sort((d,u)=>u.from.length-d.from.length),{baseUrl:a,aliases:l}}c(Mt,"readTsconfigPathAliases");function $t(e,r){if(!r.startsWith("."))return null;let t=m.resolve(m.dirname(e),r);return mr(t)}c($t,"resolveRelativeImport");function yr(e,r,t){if(!r)return null;if(r.startsWith("."))return $t(e,r);let n=t||m.dirname(e),{baseUrl:s,aliases:o}=Mt(n),i=o.find(l=>r.startsWith(l.from));if(!i)return null;let a=m.resolve(s,`${i.to}${r.slice(i.from.length)}`);return mr(a)}c(yr,"resolveImportSpecifier");function ne(e){return typeof e?.value=="string"?e.value:void 0}c(ne,"stringValue");function he(e){return e?.name??ne(e)}c(he,"propertyName");function Ae(e){return e.sourceCode??e.getSourceCode?.()}c(Ae,"sourceCodeFor");function Rr(e,r){let t=Ae(e)?.getScope?.(r);for(;t;){let n=t.references?.find(s=>s.identifier===r);if(n)return n;t=t.upper??void 0}}c(Rr,"referenceFor");function V(e,r,t){let n=Rr(e,r);if(n?.resolved)return(n.resolved.defs?.length??0)>0;let s=Ae(e)?.getScope?.(r);for(;s;){let o=s.set?.get(t);if(o)return(o.defs?.length??0)>0;s=s.upper??void 0}return!1}c(V,"isLocallyBound");function Ut(e,r){let t=Rr(e,r);return t?t.isValueReference!==!1:r.parent?.type==="VariableDeclarator"&&r.parent.init===r}c(Ut,"isValueIdentifierReference");function hr(e){if(e?.type==="Identifier"&&e.name)return{root:e,segments:[e.name]};if(!e||!(e.type==="MemberExpression"||!!(e.object&&e.property))||e.computed===!0)return;let t=hr(e.object),n=he(e.property);if(!(!t||!n))return{root:t.root,segments:[...t.segments,n]}}c(hr,"memberExpressionPath");function Ht(e){return he(e.callee?.property)}c(Ht,"calleePropertyName");function Ar(e,r){return e?.properties?.find(t=>he(t.key)===r)}c(Ar,"objectProperty");function te(e,r){return Ar(e,r)!==void 0}c(te,"objectHasProperty");function jt(e){let r=Ar(e,"metadata")?.value;return te(r,"source")}c(jt,"objectHasMetadataSource");function kr(e){return Ht(e)==="publish"}c(kr,"isPublishCall");function ye(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let r=e.specifiers??[];return r.length===0?!1:r.every(t=>t.type==="ImportSpecifier")?r.every(t=>t.importKind==="type"):r.every(t=>t.exportKind==="type")}c(ye,"declarationIsTypeOnly");function Vt(e){let r=e;for(;r?.parent;)r=r.parent;return r?.type==="Program"?r:void 0}c(Vt,"containingProgram");function Bt(e){let r=Vt(e)?.body;if(!r)return!1;let t=!1;for(let n of r){if(n.type==="ImportDeclaration"){if(!ye(n))return!1;continue}if(!(n.type==="TSInterfaceDeclaration"||n.type==="TSTypeAliasDeclaration")){if(n.type==="ExportNamedDeclaration"){if(n.declaration){if(n.declaration.type!=="TSInterfaceDeclaration"&&n.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!ye(n))return!1;t=!0;continue}return!1}}return t}c(Bt,"sourceProgramExportsOnlyTypes");var Gt={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{fromLayer}} must not import {{toLayer}} (ark.config.json). Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let r=L(e),t=B(r),n=t?G(t):null,s=t?m.dirname(t):null,o=c(i=>{let a=ne(i.source);if(a&&n&&s&&r){let l=m.isAbsolute(r)?r:m.resolve(r),d=m.relative(s,l).split(m.sep).join("/");if(!W(n,d))return;let u=E(d,n.layers);if(!u)return;let p=yr(l,a,s);if(!p)return;let f=m.relative(s,p).split(m.sep).join("/");if(f.startsWith(".."))return;let g=E(f,n.layers);if(!g)return;let y={fromPath:d,toPath:f,layers:n.layers},h=oe(n.rules,u,g,y);if(h||Ne(n.rules,u,g,y)){let A=i.type?.startsWith("Export")?"export":"import",k=ye(i),z=!!h?.peerIsolation,q=k&&!z,w=h?.message??`${u} must not ${A} ${g}.`;O(e,i,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:d,fromLayer:u,toLayer:g,target:f,edgeKind:A,...z?{peerIsolation:!0}:{},...k?{typeOnly:!0}:{},...q?{severity:"warning"}:{},...Bt(i)?{sourcePureTypeModule:!0}:{},message:q?`${w} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:w},{fromLayer:u,toLayer:g,specifier:a})}return}},"check");return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},Wt={meta:{type:"problem",docs:{description:"Require event bus publish calls to use registered intent creators instead of raw event objects or intent strings."},messages:{rawPublish:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts."},schema:[]},create(e){return{CallExpression(r){let t=r.arguments?.[0],n=ne(t),s=ue({publishCall:kr(r),rawIntentName:n,objectHasIntent:te(t,"intent"),arkPublishCandidate:!1,hasSource:!0});if(s.some(o=>o.ruleId==="RAW_EVENT_PUBLISH")){let o=s.find(i=>i.ruleId==="RAW_EVENT_PUBLISH");O(e,r,"rawPublish",{...o,file:L(e)})}}}}},zt={meta:{type:"problem",docs:{description:"Require event bus publish calls to include source metadata."},messages:{missingSource:"Strict Ark publish calls must include metadata.source."},schema:[]},create(e){return{CallExpression(r){let t=r.arguments?.[0],n=r.arguments?.[2],o=ue({publishCall:kr(r),rawIntentName:ne(t),objectHasIntent:te(t,"intent"),arkPublishCandidate:!0,hasSource:jt(t)||te(n,"source")}).find(i=>i.ruleId==="PUBLISH_MISSING_SOURCE");o&&O(e,r,"missingSource",{...o,file:L(e)})}}}},qt={meta:{type:"problem",docs:{description:"Disallow ambient globals from the layer\u2019s forbiddenGlobals in ark.config.json (same purity surface as ark-check). Option `globals` is a standalone fallback when no project config applies."},messages:{forbiddenGlobal:'Ambient global "{{name}}" is forbidden in {{layer}} (ark.config.json); inject the capability through a port instead.',forbiddenGlobalDefault:'Ambient global "{{name}}" is forbidden here; inject the capability through a port instead.',forbiddenModule:'{{layer}} must not use module "{{specifier}}" because it is the import form of forbidden global "{{name}}".'},schema:[{type:"object",properties:{globals:{type:"array",items:{type:"string"}}},additionalProperties:!1}]},create(e){let r=L(e),t=e.options?.[0],n=B(r),s=n?G(n):null,o=n?m.dirname(n):null,i=null,a="this layer";if(s&&o&&r){let p=m.isAbsolute(r)?r:m.resolve(r),f=m.relative(o,p).split(m.sep).join("/");if(!W(s,f))return{};let g=s.layers?.find(y=>y.name===E(f,s.layers));g?.forbiddenGlobals?.length?(i=new Set(g.forbiddenGlobals),a=g.name):i=null}else t?.globals&&(i=new Set(t.globals));if(!i)return{};let l=typeof Ae(e)?.getScope=="function",d=c((p,f)=>{let g=m.isAbsolute(r)?r:m.resolve(r),y=o?m.relative(o,g).split(m.sep).join("/"):r;O(e,p,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:y,fromLayer:a,target:f,message:`${a} must not use the ambient global "${f}".`},{name:f,layer:a})},"report"),u=c((p,f,g,y)=>{if(g||typeof f!="string")return;let h=ae(f,i);if(!h)return;let A=m.isAbsolute(r)?r:m.resolve(r),k=o?m.relative(o,A).split(m.sep).join("/"):r;O(e,p,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:k,fromLayer:a,target:f,edgeKind:y,message:`${a} must not use module "${f}" because it is the import form of forbidden global "${h}".`},{layer:a,name:h,specifier:f,importKind:y})},"reportModule");return{MemberExpression(p){if(p.parent?.type==="MemberExpression"&&p.parent.object===p)return;let f=hr(p);if(!f||V(e,f.root,f.segments[0]))return;let g=f.segments[0]==="globalThis",y=g?f.segments.slice(1):f.segments,h;for(let A=y.length;A>=(g?1:2);A-=1){let k=y.slice(0,A).join(".");if(i.has(k)){h=k;break}}h?d(p,h):!l&&i.has(f.segments[0])&&d(p,f.segments[0])},CallExpression(p){let f=p;if(f.callee?.type==="Identifier"&&f.callee.name==="require"&&f.arguments?.[0]?.type==="Literal"&&!V(e,p,"require")&&u(p,f.arguments[0].value,!1,"require"),l)return;let g=f.callee?.type==="Identifier"?f.callee.name:void 0;g&&i.has(g)&&d(p,g)},ImportDeclaration(p){let f=p,g=(f.specifiers??[]).filter(h=>h.type==="ImportSpecifier"),y=g.length>0&&g.length===(f.specifiers??[]).length&&g.every(h=>h.importKind==="type");u(p,f.source?.value,f.importKind==="type"||y,"import")},ImportExpression(p){let f=p;f.source?.type==="Literal"&&u(p,f.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(p){let f=p;u(p,f.moduleReference?.expression?.value,f.importKind==="type"||f.isTypeOnly===!0,"require")},ExportNamedDeclaration(p){let f=p;if(!f.source)return;let g=f.specifiers??[],y=g.length>0&&g.every(h=>h.exportKind==="type");u(p,f.source.value,f.exportKind==="type"||y,"export")},ExportAllDeclaration(p){let f=p;u(p,f.source?.value,f.exportKind==="type","export")},NewExpression(p){if(l)return;let f=p.callee?.type==="Identifier"?p.callee.name:void 0;f&&i.has(f)&&d(p,f)},Identifier(p){!l||!p.name||!i.has(p.name)||!Ut(e,p)||V(e,p,p.name)||d(p,p.name)}}}},Zt={meta:{type:"problem",docs:{description:"Disallow importing modules whose effect capability the layer denies (ark.config.json capabilities.deny / pure \u2014 same wall surface as ark-check). Import dimension only: ambient globals stay with no-forbidden-globals and the CLI/hook symbol path."},messages:{deniedCapability:'{{layer}} denies the {{capability}} capability (ark.config.json); "{{specifier}}" imports it. Define a port and bind the implementation in an adapter layer.'},schema:[]},create(e){let r=L(e),t=B(r),n=t?G(t):null,s=t?m.dirname(t):null;if(!n||!s||!r)return{};let o=m.isAbsolute(r)?r:m.resolve(r),i=m.relative(s,o).split(m.sep).join("/");if(!W(n,i))return{};let a=n.layers?.find(u=>u.name===E(i,n.layers));if(!a)return{};let l=new Set(we(a));if(l.size===0)return{};let d=c((u,p,f,g)=>{if(f||typeof p!="string"||ae(p,a.forbiddenGlobals??[]))return;let y=Oe(p);!y||!l.has(y)||O(e,u,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:i,fromLayer:a.name,target:p,capability:y,edgeKind:g,message:`${a.name} denies the ${y} capability; found import of "${p}".`},{layer:a.name,capability:y,specifier:p})},"check");return{ImportDeclaration(u){let p=u,f=(p.specifiers??[]).filter(y=>y.type==="ImportSpecifier"),g=f.length>0&&f.length===(p.specifiers??[]).length&&f.every(y=>y.importKind==="type");d(u,p.source?.value,p.importKind==="type"||g,"import")},ImportExpression(u){let p=u;p.source?.type==="Literal"&&d(u,p.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(u){let p=u;d(u,p.moduleReference?.expression?.value,p.importKind==="type"||p.isTypeOnly===!0,"require")},ExportNamedDeclaration(u){let p=u;if(!p.source)return;let f=p.specifiers??[],g=f.length>0&&f.every(y=>y.exportKind==="type");d(u,p.source.value,p.exportKind==="type"||g,"export")},ExportAllDeclaration(u){let p=u;d(u,p.source?.value,p.exportKind==="type","export")},CallExpression(u){let p=u;p.callee?.type==="Identifier"&&p.callee.name==="require"&&p.arguments?.[0]?.type==="Literal"&&!V(e,u,"require")&&d(u,p.arguments[0].value,!1,"require")}}}},{noArkRunKernelInDomain:Yt,noArkRunDirectNew:Xt,noArkRunTransportBypass:Jt}=or({findConfigPath:B,loadArkConfig:G,resolveImportSpecifier:yr,lintedFilename:L,sourceIsInAnalysisScope:W,isLocallyBound:V,reportAdapterDiagnostic:O});function Qt(e,r){let t=m.dirname(m.resolve(e));return m.relative(t,m.resolve(r)).split(m.sep).join("/")}c(Qt,"toProjectRelative");var{noArkOrderKernelInDomain:en,noArkOrderGenericUpdate:rn}=fr({findConfigPath:B,loadArkConfig:G,lintedFilename:L,sourceIsInAnalysisScope:W,reportAdapterDiagnostic:O,toProjectRelative:Qt});var tn={"no-domain-infra-imports":Gt,"no-raw-event-publish":Wt,"require-publish-source":zt,"no-forbidden-globals":qt,"no-denied-capabilities":Zt,"no-arkrun-kernel-in-domain":Yt,"no-arkrun-direct-new":Xt,"no-arkrun-transport-bypass":Jt,"no-arkorder-kernel-in-domain":en,"no-arkorder-generic-update":rn},Re={rules:tn};Re.configs={recommended:{plugins:{ark:Re},rules:{"ark/no-domain-infra-imports":"error","ark/no-raw-event-publish":"error","ark/require-publish-source":"error","ark/no-forbidden-globals":"error","ark/no-denied-capabilities":"error","ark/no-arkrun-kernel-in-domain":"error","ark/no-arkrun-direct-new":"error","ark/no-arkrun-transport-bypass":"error","ark/no-arkorder-kernel-in-domain":"error","ark/no-arkorder-generic-update":"error"}}};var fs=Re;export{fs as default,B as findConfigPath,T as globToRegExp,Ne as isEdgeDenied,E as layerForRelativePath,G as loadArkConfig,rn as noArkOrderGenericUpdate,en as noArkOrderKernelInDomain,Xt as noArkRunDirectNew,Yt as noArkRunKernelInDomain,Jt as noArkRunTransportBypass,Zt as noDeniedCapabilities,Gt as noDomainInfraImports,qt as noForbiddenGlobals,Wt as noRawEventPublish,Ie as patternSpecificity,Re as plugin,Mt as readTsconfigPathAliases,zt as requirePublishSource,yr as resolveImportSpecifier,$t as resolveRelativeImport};
|