arkgate 4.8.25 → 4.8.26

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.
@@ -8,7 +8,7 @@ ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
8
8
  `)}`),this.name="ArkRulesValidationError",this.source=t,this.issues=n}};function lc(e){return{...e,$schema:e.$schema===void 0?Mt:e.$schema,schemaVersion:e.schemaVersion===void 0?Le:e.schemaVersion,structure:e.structure===void 0?[]:e.structure,invariants:e.invariants===void 0?[]:e.invariants}}a(lc,"defaultedArkRules");function is(e){return e==="enforced"?"enforced":"advisory"}a(is,"normalizeMode");function cc(e){return ac.includes(e)}a(cc,"isTier2Sensor");function dc(e,t){let n=Array.isArray(e.structure)?e.structure:[],r=Array.isArray(e.invariants)?e.invariants:[],s=new Set;n.forEach((o,i)=>{if(!J(o))return;let l=typeof o.id=="string"?o.id:"";l&&(s.has(l)&&t.push({path:`$.structure[${i}].id`,message:`duplicate rule id ${JSON.stringify(l)}`}),s.add(l)),typeof o.sensor=="string"&&cc(o.sensor)&&o.mode==="enforced"&&t.push({path:`$.structure[${i}].mode`,message:`${l?`rule ${JSON.stringify(l)} uses sensor `:"sensor "}${JSON.stringify(o.sensor)}, which is Tier-2 advisory-only and cannot be enforced${l?" (arkgate-check --sensors lists which sensors can)":""}`}),Array.isArray(o.appliesTo)&&o.appliesTo.length===0&&t.push({path:`$.structure[${i}].appliesTo`,message:"must not be an empty array (omit the field to apply to the whole layer)"})}),r.forEach((o,i)=>{if(!J(o))return;let l=typeof o.id=="string"?o.id:"";l&&(s.has(l)&&t.push({path:`$.invariants[${i}].id`,message:`duplicate rule id ${JSON.stringify(l)}`}),s.add(l)),Array.isArray(o.appliesTo)&&o.appliesTo.length===0&&t.push({path:`$.invariants[${i}].appliesTo`,message:"must not be an empty array (omit the field to apply to the whole layer)"})})}a(dc,"validateSemantics");function Kt(e,t="arkrules.json",n){if(!J(e))throw new he(t,[{path:"$",message:`must be an object; received ${H(e)}`}]);let r=lc(e),s=[];if(X(r,os,"$",os,s),dc(r,s),n!==void 0&&typeof r.layer=="string"&&r.layer!==n&&s.push({path:"$.layer",message:`must match referencing key ${JSON.stringify(n)}; received ${JSON.stringify(r.layer)}`}),s.length>0)throw new he(t,s);return{config:r}}a(Kt,"loadArkRulesContract");function lt(e,t){return e.childId?`${e.childId}#${t}`:t}a(lt,"effectiveRuleId");function as(e,t){if(t&&t.length>0)return[...t];if(e.childId&&e.defaultAppliesTo&&e.defaultAppliesTo.length>0)return[...e.defaultAppliesTo]}a(as,"effectiveAppliesTo");function ls(e,t){return{sourceFile:e.sourceFile,ruleId:lt(e,t),layer:e.layer,...e.childId?{childId:e.childId}:{}}}a(ls,"provenanceFor");function cs(e,t){let n=t.replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase(),r=e.trim().replace(/\\/g,"/").replace(/^\.\//,"").toLowerCase();if(!r||!n||r.includes(".."))return!1;if(r===n||r===`${n}/**`||r===`${n}/*`)return!0;if(r.startsWith(`${n}/`)){let i=r.slice(n.length+1).split("/"),l=i.indexOf("**");return l!==-1&&l!==i.length-1?!1:i.every(c=>c.length>0)}let s=n.replace(/^(?:src|app)\//,""),o=r.replace(/^(?:src|app)\//,"");return s!==n||o!==r?cs(o,s):!1}a(cs,"appliesToPatternInsideSlice");function ds(e){if(!e.childId||!e.defaultAppliesTo?.length)return[];let t=String(e.defaultAppliesTo[0]).replace(/\/\*\*$/,""),n=[],r=[...e.file.structure??[],...e.file.invariants??[]];for(let s of r)for(let o of s.appliesTo??[])cs(o,t)||n.push({id:s.id,pattern:o});return n}a(ds,"sliceScopeEscapes");function us(e){let t=new Map,n=new Map;for(let r of e){let s=[...(r.file.structure??[]).map(o=>o.id),...(r.file.invariants??[]).map(o=>o.id)];for(let o of s){let i=lt(r,o),l=`${r.layer}\0${i}`,c=t.get(l);if(!c){t.set(l,{id:i,layer:r.layer,sourceFiles:[r.sourceFile]});continue}let d=n.get(l)??{id:i,layer:r.layer,sourceFiles:[...c.sourceFiles]};d.sourceFiles.includes(r.sourceFile)||d.sourceFiles.push(r.sourceFile),n.set(l,d)}}return[...n.values()]}a(us,"duplicateArkRuleIds");function fs(e){let t={},n=[],r=[],s=[...e].sort((o,i)=>o.layer.localeCompare(i.layer)||o.sourceFile.localeCompare(i.sourceFile));for(let o of s){let i=(o.file.structure??[]).map(d=>{let u=as(o,d.appliesTo);return{...d,id:lt(o,d.id),...u?{appliesTo:u}:{appliesTo:void 0},mode:is(d.mode),provenance:ls(o,d.id)}}),l=(o.file.invariants??[]).map(d=>{let u=as(o,d.appliesTo);return{...d,id:lt(o,d.id),...u?{appliesTo:u}:{appliesTo:void 0},mode:is(d.mode),provenance:ls(o,d.id)}}),c=t[o.layer];c?(c.sourceFiles||(c.sourceFiles=[c.sourceFile]),c.sourceFiles.includes(o.sourceFile)||c.sourceFiles.push(o.sourceFile),c.structure.push(...i),c.invariants.push(...l)):t[o.layer]={sourceFile:o.sourceFile,sourceFiles:[o.sourceFile],structure:i,invariants:l},n.push(...i),r.push(...l)}return n.sort((o,i)=>{let l=o.provenance.layer.localeCompare(i.provenance.layer);return l!==0?l:o.id.localeCompare(i.id)}),r.sort((o,i)=>{let l=o.provenance.layer.localeCompare(i.provenance.layer);return l!==0?l:o.id.localeCompare(i.id)}),{schemaVersion:Le,byLayer:t,structure:n,invariants:r}}a(fs,"buildEffectiveArkRules");function se(){return{schemaVersion:Le,byLayer:{},structure:[],invariants:[]}}a(se,"emptyEffectiveArkRules");var Ut=class extends Error{static{a(this,"EffectiveContractError")}issues;source;constructor(t,n){super(`Invalid Effective Contract (${t}):
9
9
  ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
10
10
  `)}`),this.name="EffectiveContractError",this.source=t,this.issues=n}};function ps(e){return e.replace(/\\/g,"/").replace(/^\.\//,"")}a(ps,"normalizeRel");function gs(e,t="ark.config.json"){let n=e.config.arkRules??{},r=[],s=Object.keys(n).length>0,o=!!(e.governedFiles&&e.governedFiles.length>0);if(!s&&!o){if(e.discoveredArkRulesFiles&&e.discoveredArkRulesFiles.length>0)for(let f of[...e.discoveredArkRulesFiles].sort())r.push({path:f,message:`ArkRules file ${JSON.stringify(f)} is not referenced by arkRules and will not be enforced`,severity:"advisory"});return{config:e.config,arkRules:se(),warnings:r}}let i=new Set(e.config.layers.map(f=>f.name)),l=[],c=[],d=new Set,u=a((f,p,g)=>{if(g instanceof he){for(let m of g.issues)l.push({path:`${f}${m.path==="$"?"":m.path.replace(/^\$/,"")}`,message:`${p}: ${m.message}`});return}if(g instanceof SyntaxError){l.push({path:f,message:`referenced ArkRules file ${JSON.stringify(p)} is not valid JSON: ${g.message}`});return}l.push({path:f,message:`referenced ArkRules file ${JSON.stringify(p)} failed to load: ${g instanceof Error?g.message:String(g)}`})},"pushLoadIssue");for(let f of Object.keys(n).sort()){let p=n[f],g=`$.arkRules[${JSON.stringify(f)}]`,m=Array.isArray(p)?p:typeof p=="string"?[p]:null;if(!m||m.length===0||m.some(R=>typeof R!="string"||R.length===0)){l.push({path:g,message:"must be a non-empty path string or an array of paths"});continue}if(!i.has(f)){l.push({path:g,message:`layer ${JSON.stringify(f)} is not declared in layers[]`});continue}m.forEach((R,k)=>{let y=m.length===1&&typeof p=="string"?g:`${g}[${k}]`;if(R.startsWith("/")||/^[A-Za-z]:[\\/]/.test(R)){l.push({path:y,message:"must be a project-relative path (absolute paths are not allowed)"});return}let A=ps(R);d.add(A);let S=e.fileContents[A]??e.fileContents[R];if(S===void 0){l.push({path:y,message:`referenced ArkRules file ${JSON.stringify(A)} is missing`});return}try{let v=Kt(JSON.parse(S),A,f);c.push({layer:f,sourceFile:A,file:v.config})}catch(v){u(y,A,v)}})}if(e.governedFiles&&e.governedFiles.length>0){let f=Ge({files:e.governedFiles,rules:e.config.rules,layers:[...i]});for(let p of f){let g=e.fileContents[p.path];if(g!==void 0){d.add(p.path);try{let m=Kt(JSON.parse(g),p.path,p.layer),R={layer:p.layer,sourceFile:p.path,file:m.config,childId:p.childId,defaultAppliesTo:p.defaultAppliesTo},k=ds(R);if(k.length>0){l.push({path:p.path,message:`ARKRULE_SCOPE_ESCAPES_SLICE: ${p.path} appliesTo ${k.map(y=>y.pattern).join(", ")} escapes ${p.childId}`});continue}c.push(R)}catch(m){u(p.path,p.path,m)}}}}for(let f of us(c))l.push({path:`$.arkRules[${JSON.stringify(f.layer)}]`,message:`ARKRULE_DUPLICATE_ID: ${f.id} is declared in ${f.sourceFiles.join(", ")}`});if(e.discoveredArkRulesFiles)for(let f of[...e.discoveredArkRulesFiles].sort()){let p=ps(f);d.has(p)||r.push({path:p,message:`ArkRules file ${JSON.stringify(p)} is not referenced by arkRules and will not be enforced`,severity:"advisory"})}if(l.length>0)throw new Ut(t,l);return{config:e.config,arkRules:fs(c),warnings:r}}a(gs,"resolveEffectiveContract");var uc=2e3,hs=new Map;function ms(e){try{return U.default.statSync(e).isFile()}catch{return!1}}a(ms,"isFile");function Ht(e){let t=hs.get(e);if(t){if(t.found!==null&&ms(t.found))return t.found;if(t.found===null&&Date.now()-t.at<uc)return null}let n=I.default.join(e,"ark.config.json"),r;if(ms(n))r=n;else{let s=I.default.dirname(e);r=s===e?null:Ht(s)}return hs.set(e,{found:r,at:Date.now()}),r}a(Ht,"findConfigInDir");function D(e){return!e||e==="<input>"||e.startsWith("stdin")?null:Ht(I.default.dirname(I.default.resolve(e)))}a(D,"findConfigPath");var me=new Map,fc=64;function pc(e){try{let t=U.default.statSync(e,{throwIfNoEntry:!1});return t?.isFile()?`${t.mtimeMs}:${t.size}:${t.ino}`:null}catch{return null}}a(pc,"configFileStamp");function gc(e,t){if(!me.has(e)&&me.size>=fc){let n=me.keys().next().value;n!==void 0&&me.delete(n)}me.set(e,t)}a(gc,"rememberContract");var hc=/\.[cm]?[tj]sx?$/,mc=/(^test(?:[-_.]).*|\.(spec|test)(?:-d)?\.)(tsx?|jsx?|mjsx?|cjsx?|mts|cts)$/i,yc=new Set(["node_modules","dist","coverage","bench","benches","benchmark","benchmarks","docs","documentation","example","examples","fixture","fixtures","testdata","playground","scaffold","scaffolds","__tests__","__mocks__","e2e","test","tests"]);function Ac(e){return hc.test(e)&&!e.endsWith(".d.ts")&&!mc.test(e)}a(Ac,"isGovernableSourceName");function Rc(e){let t=e?.arkRules;if(!t||typeof t!="object")return[];let n=[];for(let r of Object.values(t))if(typeof r=="string"&&r.length>0)n.push(r);else if(Array.isArray(r))for(let s of r)typeof s=="string"&&s.length>0&&n.push(s);return n}a(Rc,"arkRulesRefs");function Ss(e,t){let n=t.include&&t.include.length>0?t.include:["src"],r=[],s=a(o=>{let i;try{i=U.default.readdirSync(o,{withFileTypes:!0})}catch{return}for(let l of i){if(l.name.startsWith("."))continue;let c=I.default.join(o,l.name);if(l.isDirectory()){if(yc.has(l.name))continue;s(c);continue}if(!l.isFile()||!Ac(l.name))continue;let d=I.default.relative(e,c).split(I.default.sep).join("/");!d||d.startsWith("..")||ht(d,t)||r.push(d)}},"walk");for(let o of n){let i=String(o).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");s(I.default.resolve(e,i==="."?"":i))}return r}a(Ss,"governedRelativeFiles");function Sc(e,t){return Ge({files:t,rules:e.rules,layers:e.layers.map(n=>n.name)}).map(n=>n.path)}a(Sc,"plannedSlicePaths");function kc(e,t){let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=I.default.resolve(e,n),s=I.default.relative(e,r);if(!(s.startsWith("..")||I.default.isAbsolute(s)))try{return U.default.readFileSync(r,"utf8")}catch{return}}a(kc,"readReferencedFile");function ks(e,t){if(!e)return[];let n=new Set,r=[],s=a(o=>{let i=o.replace(/\\/g,"/").replace(/^\.\//,"");!i||n.has(i)||(n.add(i),r.push(i))},"add");for(let o of Rc(e))s(o);for(let o of Sc(e,t))s(o);return r}a(ks,"contractSourcePaths");function jt(e,t){let n=t?Ss(e,t):[];return ks(t,n).map(r=>{try{let s=U.default.statSync(I.default.resolve(e,r));return`${r}:${s.mtimeMs}:${s.size}`}catch{return`${r}:missing`}}).join("|")}a(jt,"refStampsFor");function ys(e){return e instanceof Error?e.message:String(e)}a(ys,"errorText");function bc(e,t){let n=I.default.dirname(e),r;try{r=at(t,e).config}catch(c){return{config:null,arkRules:se(),error:ys(c),fingerprint:null}}let s=Ss(n,r),o=ks(r,s),i=(0,Gt.createHash)("sha256").update(t);if(o.length===0)return{config:r,arkRules:se(),error:null,fingerprint:i.digest("hex")};let l={};for(let c of o){let d=kc(n,c);if(d===void 0)continue;let u=c.replace(/\\/g,"/").replace(/^\.\//,"");l[u]=d,i.update(`\0${u}\0${d}`)}try{let c=gs({config:r,fileContents:l,governedFiles:s},e);return{config:r,arkRules:c.arkRules,error:null,fingerprint:i.digest("hex")}}catch(c){return{config:null,arkRules:se(),error:ys(c),fingerprint:null}}}a(bc,"resolveContract");function ye(e){let t=I.default.dirname(e),n=pc(e),r=me.get(e);if(r&&n!==null&&r.stamp===n&&jt(t,r.refConfig)===r.refStamps)return r.result;let s;try{s=U.default.readFileSync(e,"utf8")}catch{return{config:null,arkRules:se(),error:null,fingerprint:null}}if(r?.source===s&&jt(t,r.refConfig)===r.refStamps)return r.stamp=n,r.result;let o=bc(e,s),i=o.config??Ec(s,e);return gc(e,{source:s,stamp:n,refConfig:i,refStamps:jt(t,i),result:o}),o}a(ye,"loadArkContract");function Ec(e,t){try{return at(e,t).config}catch{return null}}a(Ec,"safeConfig");function bs(e){if(!U.default.existsSync(e))return null;let t=ye(e);return t.config?t.config:at(U.default.readFileSync(e,"utf8"),e).config}a(bs,"loadArkConfig");function Q(e,t){return(e.include??[]).some(r=>{let s=String(r).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!ht(t,e)}a(Q,"sourceIsInAnalysisScope");function ct(e,t,n){let r=I.default.isAbsolute(n)?n:I.default.resolve(n),s=I.default.relative(t,r).split(I.default.sep).join("/");if(!Q(e,s))return null;let o=e.layers?.find(i=>i.name===w(s,e.layers));return{relFile:s,layer:o}}a(ct,"lintedFileInScope");function V(e){return e?ye(e).config:null}a(V,"configForRule");var As="configInvalid",Ic="Ark contract is invalid, so no architecture verdict is possible (fix it; ark-check fails closed the same way): {{detail}}",Rs=new WeakSet;function Bt(e){let t=D(e);return t?ye(t).error:null}a(Bt,"contractErrorForFile");function F(e){return{meta:{...e.meta,messages:{...e.meta.messages,[As]:Ic,[Xe]:ir}},create(t){let n=Bt(x(t));return n?{Program(r){let s=z(t);if(s&&typeof s=="object"){if(Rs.has(s))return;Rs.add(s)}t.report({...r?.loc?.start?{node:r}:{loc:{line:1,column:0}},messageId:As,data:{detail:n.replace(/\s*\n\s*/g," ")}})}}:Je(e,t,"blocking")}}}a(F,"withContractGuard");function Vt(e=process.cwd()){let t=Ht(I.default.resolve(e));if(!t)return null;let n=ye(t);if(n.fingerprint)return n.fingerprint;try{return(0,Gt.createHash)("sha256").update(U.default.readFileSync(t,"utf8")).digest("hex")}catch{return null}}a(Vt,"contractFingerprint");var vc=256*1024;function wc(e){try{return Es.default.readFileSync(e,"utf8")}catch{return""}}a(wc,"readUtf8");function xc(e,t){if(!/\.(tsx?|mts|cts)$/i.test(e))return[];try{return Ce(e,t)}catch{return[]}}a(xc,"classShapesFor");function Cc(e,t){if(!/\.(tsx?|mts|cts|jsx?|mjs|cjs)$/i.test(e)||e.endsWith(".d.ts"))return{};if(t.length>vc)return{};let n=qn(e,t);return n?{[e]:n}:{}}a(Cc,"hintsFor");function Is(e){return{meta:{type:"problem",docs:{description:"Report ArkRules structure-sensor findings for the linted file (same Effective Contract and evaluators as ark-check; file-local sensors only)."},messages:{structure:"ArkRules {{arkruleId}} ({{sensor}}): {{message}}"},schema:[]},create(t){let n=x(t),r=D(n);if(!r||!n)return{};let s=ye(r),o=s.config;if(!o||s.arkRules.structure.length===0)return{};let i=De.default.dirname(r),l=De.default.resolve(n),c=De.default.relative(i,l).split(De.default.sep).join("/");if(!e(o,c))return{};let d=w(c,o.layers);return{Program(u){let f=de(t)??wc(l),p=Yn({arkRules:s.arkRules,classShapes:xc(c,f),files:[c],layerForFile:a(g=>g===c?d:w(g,o.layers),"layerForFile"),fileHints:Cc(c,f)}).filter(g=>g.file===c);for(let g of p)N(t,{loc:{start:{line:g.line}},parent:u},"structure",{ruleId:g.ruleId,code:g.code,file:c,line:g.line,fromLayer:g.fromLayer,arkruleId:g.arkruleId,arkruleSource:g.arkruleSource,severity:g.severity,failsStrict:g.failsStrict,message:g.message},{arkruleId:g.arkruleId,sensor:g.sensor,message:g.message})}}}}}a(Is,"createArkRulesStructureRule");var Ae=P(require("path"),1);function vs(e,t,n){for(let r=t.length;r>=n;r-=1){let s=t.slice(0,r).join(".");if(e.has(s))return s}}a(vs,"longestForbidden");var ws={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=x(e),n=e.options?.[0],r=D(t),s=V(r),o=r?Ae.default.dirname(r):null,i=null,l="this layer";if(s&&o&&t){let y=ct(s,o,t);if(!y)return{};let{layer:A}=y;A?.forbiddenGlobals?.length?(i=new Set(A.forbiddenGlobals),l=A.name):i=null}else n?.globals&&(i=new Set(n.globals));if(!i)return{};let c=i,d=typeof z(e)?.getScope=="function",u=Ae.default.isAbsolute(t)?t:Ae.default.resolve(t),f=o?Ae.default.relative(o,u).split(Ae.default.sep).join("/"):t,p=a((y,A)=>{N(e,y,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:f,fromLayer:l,target:A,message:`${l} must not use the ambient global "${A}".`},{name:A,layer:l})},"report"),g=a((y,A,S,v)=>{if(S||typeof A!="string")return;let O=He(A,c);O&&N(e,y,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:f,fromLayer:l,target:A,edgeKind:v,message:`${l} must not use module "${A}" because it is the import form of forbidden global "${O}".`},{layer:l,name:O,specifier:A,importKind:v})},"reportModule"),m=a((y,A)=>{if(y?.type==="ObjectPattern")for(let S of y.properties??[]){if(S.type==="RestElement")continue;let v=_t(S.key,S.computed);if(!v)continue;let O=[...A,v],be=vs(c,O,A.length+1);if(be){p(S,be);continue}let oe=S.value,Qs=oe?.type==="AssignmentPattern"?oe.left:oe;m(Qs,O)}},"checkPattern"),R=a((y,A)=>{if(y?.type!=="ObjectPattern")return;let S=_e(A);if(!S||Y(e,S.root,S.segments[0]))return;let v=S.segments[0]==="globalThis"?S.segments.slice(1):S.segments;m(y,v)},"checkDestructure"),k=ue(e,g);return{MemberExpression(y){if(y.parent?.type==="MemberExpression"&&y.parent.object===y)return;let A=_e(y);if(!A||Y(e,A.root,A.segments[0]))return;let S=A.segments[0]==="globalThis",v=S?A.segments.slice(1):A.segments,O=vs(c,v,S?1:2);O?p(y,O):!d&&c.has(A.segments[0])&&p(y,A.segments[0])},VariableDeclarator(y){R(y.id,y.init)},AssignmentExpression(y){R(y.left,y.right)},CallExpression(y){if(k.CallExpression(y),d)return;let A=y.callee?.type==="Identifier"?y.callee.name:void 0;A&&c.has(A)&&p(y,A)},ImportDeclaration:k.ImportDeclaration,ImportExpression:k.ImportExpression,TSImportEqualsDeclaration:k.TSImportEqualsDeclaration,ExportNamedDeclaration:k.ExportNamedDeclaration,ExportAllDeclaration:k.ExportAllDeclaration,NewExpression(y){if(d)return;let A=y.callee?.type==="Identifier"?y.callee.name:void 0;A&&c.has(A)&&p(y,A)},Identifier(y){!d||!y.name||!c.has(y.name)||!ur(e,y)||Y(e,y,y.name)||p(y,y.name)}}}};var Fe=P(require("path"),1);function xs(e,t){if(!(e?.type&&e.type!=="ObjectExpression"))return e?.properties?.find(n=>et(n.key)===t)}a(xs,"objectProperty");function Re(e,t){return xs(e,t)!==void 0}a(Re,"objectHasProperty");function _c(e){let t=xs(e,"metadata")?.value;return Re(t,"source")}a(_c,"objectHasMetadataSource");function Cs(e){let t=e.callee;return t?.type==="Identifier"?t.name==="publish":t?.computed!==!0&&et(t?.property)==="publish"}a(Cs,"isPublishCall");function _s(e){return e?e.type==="Identifier"||e.type===void 0&&e.name?/^[A-Z]/.test(e.name??""):e.type==="MemberExpression"&&e.computed!==!0?_s(e.property):!1:!1}a(_s,"looksLikeIntentCreator");function Oc(e){let t=Oe(e);return t!==void 0&&ve(t)||Re(e,"intent")||_s(e)}a(Oc,"isArkPublishCandidate");function Tc(e){let[t,n,r]=e;return _c(t)||Re(n,"source")||Re(r,"source")}a(Tc,"publishHasSource");function Nc(e){let t=x(e),n=D(t),r=V(n);if(!r||!n||!t)return null;let s=Fe.default.relative(Fe.default.dirname(n),Fe.default.resolve(t)).split(Fe.default.sep).join("/");return Q(r,s)?s:null}a(Nc,"scopedFile");var Os={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 n=t.arguments?.[0],s=yt({publishCall:Cs(t),rawIntentName:Oe(n),objectHasIntent:Re(n,"intent"),arkPublishCandidate:!1,hasSource:!0}).find(o=>o.ruleId==="RAW_EVENT_PUBLISH");s&&N(e,t,"rawPublish",{...s,file:x(e)})}}}},Ts={meta:{type:"problem",docs:{description:"Require Ark publish calls (intent creator / Ark intent first argument) to include source metadata. Silent without an ark.config.json or outside its include scope, like ark-check."},messages:{missingSource:"Strict Ark publish calls must include metadata.source."},schema:[]},create(e){let t=Nc(e);return t?{CallExpression(n){let r=n.arguments??[],s=r[0],i=yt({publishCall:Cs(n),rawIntentName:Oe(s),objectHasIntent:Re(s,"intent"),arkPublishCandidate:Oc(s),hasSource:Tc(r)}).find(l=>l.ruleId==="PUBLISH_MISSING_SOURCE");i&&N(e,n,"missingSource",{...i,file:t})}}:{}}};var Pe=P(require("fs"),1),E=P(require("path"),1);function Ns(e,t){let n=t,r=e.length;for(;;){for(;n<r&&/\s/.test(e[n]);)n+=1;if(e[n]==="/"&&e[n+1]==="/"){for(;n<r&&e[n]!==`
11
- `;)n+=1;continue}if(e[n]==="/"&&e[n+1]==="*"){let s=e.indexOf("*/",n+2);n=s<0?r:s+2;continue}return n}}a(Ns,"skipTrivia");function Lc(e){let t=e.replace(/^/,""),n="",r=0,s=t.length;for(;r<s;){let o=t[r];if(o==='"'){let i=r+1;for(;i<s&&t[i]!=='"';)i+=t[i]==="\\"?2:1;n+=t.slice(r,i+1),r=i+1;continue}if(o==="/"&&(t[r+1]==="/"||t[r+1]==="*")){n+=" ",r=Ns(t,r);continue}if(o===","){let i=Ns(t,r+1);if(t[i]==="}"||t[i]==="]"){r+=1;continue}}n+=o,r+=1}return n}a(Lc,"stripJsonc");function Ls(e){return JSON.parse(Lc(e))}a(Ls,"parseJsonc");var Ds=new Map,Se=new Map,Dc=64;function Wt(e){try{let t=Pe.default.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"missing"}}a(Wt,"fileStamp");function ee(e){try{return Pe.default.statSync(e).isFile()}catch{return!1}}a(ee,"isFile");function Fs(e){let t=E.default.resolve(e),n=Ds.get(t);if(n!==void 0&&(n===null||ee(n)))return n;let r=E.default.join(t,"tsconfig.json"),s;if(ee(r))s=r;else{let o=E.default.dirname(t);s=o===t?null:Fs(o)}return Ds.set(t,s),s}a(Fs,"findNearestTsconfig");function Fc(e,t){let n=e;for(;;){let r=E.default.join(n,"node_modules",t);for(let i of[r,`${r}.json`])if(ee(i))return i;let s=E.default.join(r,"package.json");if(ee(s))try{let i=JSON.parse(Pe.default.readFileSync(s,"utf8"));if(typeof i.tsconfig=="string"&&ee(E.default.join(r,i.tsconfig)))return E.default.join(r,i.tsconfig)}catch{}if(ee(E.default.join(r,"tsconfig.json")))return E.default.join(r,"tsconfig.json");let o=E.default.dirname(n);if(o===n)return null;n=o}}a(Fc,"resolvePackageExtends");function Pc(e,t){let n=E.default.dirname(e);if(t.startsWith(".")||E.default.isAbsolute(t)){let r=E.default.resolve(n,t);for(let s of[r,`${r}.json`])if(ee(s))return s;return null}return Fc(n,t)}a(Pc,"resolveExtends");function zt(e,t){return e.split("${configDir}").join(t)}a(zt,"substituteConfigDir");function Ps(e,t,n,r,s){if(n>8||r.has(e))return{};r.add(e),s.push({file:e,stamp:Wt(e)});let o;try{o=Ls(Pe.default.readFileSync(e,"utf8"))??{}}catch{return{}}let i={},l=o.extends,c=typeof l=="string"?[l]:Array.isArray(l)?l:[];for(let f of c){if(typeof f!="string")continue;let p=zt(f,t),g=Pc(e,p);if(!g){if(p.startsWith(".")||E.default.isAbsolute(p)){let R=E.default.resolve(E.default.dirname(e),p);for(let k of[R,`${R}.json`])s.push({file:k,stamp:Wt(k)})}continue}let m=Ps(g,t,n+1,r,s);m.baseUrl!==void 0&&(i.baseUrl=m.baseUrl),m.paths!==void 0&&(i.paths=m.paths,i.pathsBase=m.pathsBase)}let d=o.compilerOptions??{},u=E.default.dirname(e);return typeof d.baseUrl=="string"&&(i.baseUrl=E.default.resolve(u,zt(d.baseUrl,t))),d.paths&&typeof d.paths=="object"&&(i.paths=d.paths,i.pathsBase=u),i}a(Ps,"loadChain");function $c(e,t){let n=e.baseUrl??e.pathsBase??t,r=[];for(let[s,o]of Object.entries(e.paths??{})){if(!Array.isArray(o)||o.length===0)continue;let i=o.filter(f=>typeof f=="string").map(f=>zt(f,t));if(i.length===0)continue;let l=s.indexOf("*"),c=l>=0,d=c?s.slice(0,l):s,u=c?s.slice(l+1):"";c&&!d&&!u||r.push({from:d,to:i[0].replace(/\*$/,""),suffix:u,wildcard:c,targets:i})}return r.sort((s,o)=>Number(s.wildcard)-Number(o.wildcard)||o.from.length-s.from.length),{baseUrl:n,aliases:r}}a($c,"buildAliasSet");function Mc(e){let t=Se.get(e);if(t&&t.chain.every(i=>Wt(i.file)===i.stamp))return t.result;let n=[],r=E.default.dirname(e),s=Ps(e,r,0,new Set,n),o=$c(s,r);if(!Se.has(e)&&Se.size>=Dc){let i=Se.keys().next().value;i!==void 0&&Se.delete(i)}return Se.set(e,{chain:n,result:o}),o}a(Mc,"aliasesForTsconfig");function Yt(e){let t=Fs(e);return t?Mc(t):{baseUrl:E.default.resolve(e),aliases:[]}}a(Yt,"readTsconfigPathAliases");function $s(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,E.default.join(e,"index.ts"),E.default.join(e,"index.tsx"),E.default.join(e,"index.js")];for(let n of t)if(ee(n))return n;return null}a($s,"existingSourceFile");function qt(e,t){if(!t.startsWith("."))return null;let n=E.default.resolve(E.default.dirname(e),t);return $s(n)}a(qt,"resolveRelativeImport");function Kc(e,t){return e.wildcard?!t.startsWith(e.from)||!t.endsWith(e.suffix)||t.length<e.from.length+e.suffix.length?null:t.slice(e.from.length,t.length-e.suffix.length):t===e.from?"":null}a(Kc,"matchAlias");function dt(e,t,n){if(!t)return null;if(t.startsWith("."))return qt(e,t);let r=e?E.default.dirname(E.default.resolve(e)):n??".",{baseUrl:s,aliases:o}=Yt(r);for(let i of o){let l=Kc(i,t);if(l!==null){for(let c of i.targets){let d=i.wildcard?c.split("*").join(l):c,u=$s(E.default.resolve(s,d));if(u)return u}return null}}return null}a(dt,"resolveImportSpecifier");var Uc="4.8.25";function jc(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}a(jc,"containingProgram");function Gc(e){let t=jc(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!tt(r))return!1;continue}if(!(r.type==="TSInterfaceDeclaration"||r.type==="TSTypeAliasDeclaration")){if(r.type==="ExportNamedDeclaration"){if(r.declaration){if(r.declaration.type!=="TSInterfaceDeclaration"&&r.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!tt(r))return!1;n=!0;continue}return!1}}return n}a(Gc,"sourceProgramExportsOnlyTypes");var Ms={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{message}} Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let t=x(e),n=D(t),r=V(n),s=n?_.default.dirname(n):null,o=a(i=>{let l=Qe(i.source);if(l&&r&&s&&t){let c=_.default.isAbsolute(t)?t:_.default.resolve(t),d=_.default.relative(s,c).split(_.default.sep).join("/");if(!Q(r,d))return;let u=w(d,r.layers);if(!u)return;let f=dt(c,l,s);if(!f)return;let p=_.default.relative(s,f).split(_.default.sep).join("/");if(p.startsWith(".."))return;let g=w(p,r.layers);if(!g)return;let m={fromPath:d,toPath:p,layers:r.layers},R=gt(r.rules,u,g,m),k=R?.rule;if(k){let y=i.type?.startsWith("Export")?"export":"import",A=tt(i),S=!!k?.peerIsolation,v=A&&!S,O=R?.sliceVerdict,be=O?Rn({surface:"import",verdict:O,fromLayer:u,toLayer:g,kind:y,fromPath:d,toPath:p,ruleMessage:k?.message,childMessage:k?.childSlices?.message}):k?.message??`${u} must not ${y} ${g}.`,oe=v?`${be} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:be;N(e,i,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:d,fromLayer:u,toLayer:g,target:p,edgeKind:y,...S?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...Sn(O),...v?{failsStrict:!1,severity:"warning"}:{},...Gc(i)?{sourcePureTypeModule:!0}:{},message:oe},{fromLayer:u,toLayer:g,specifier:l,message:oe})}return}},"check");return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},Hc={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=x(e),n=D(t),r=V(n),s=n?_.default.dirname(n):null;if(!r||!s||!t)return{};let o=ct(r,s,t);if(!o?.layer)return{};let{relFile:i,layer:l}=o,c=new Set(In(l));return c.size===0?{}:ue(e,a((u,f,p,g)=>{if(p||typeof f!="string"||He(f,l.forbiddenGlobals??[]))return;let m=En(f);!m||!c.has(m)||N(e,u,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:i,fromLayer:l.name,target:f,capability:m,edgeKind:g,message:`${l.name} denies the ${m} capability; found import of "${f}".`},{layer:l.name,capability:m,specifier:f})},"check"))}},ke=hr({findConfigPath:D,loadArkConfig:V,resolveImportSpecifier:dt,lintedFilename:x,sourceIsInAnalysisScope:Q,isLocallyBound:Y,reportAdapterDiagnostic:N});function Bc(e,t){let n=_.default.dirname(_.default.resolve(e));return _.default.relative(n,_.default.resolve(t)).split(_.default.sep).join("/")}a(Bc,"toProjectRelative");var ut=Dr({findConfigPath:D,loadArkConfig:V,lintedFilename:x,sourceIsInAnalysisScope:Q,isLocallyBound:Y,reportAdapterDiagnostic:N,toProjectRelative:Bc}),Ks=Is(Q),Vc=[Ms,ke.noArkRunKernelInDomain,ke.noArkRunDirectNew,ke.noArkRunTransportBypass,ut.noArkOrderKernelInDomain,ut.noArkOrderGenericUpdate,Ks],Wc={meta:{type:"problem",docs:{description:"Report non-blocking Ark findings (type-only placement debt, advisory slice walls, advisory arkRun / arkOrder / ArkRules) as warnings \u2014 the same findings ark-check reports as warnings."},messages:{[Ct]:or},schema:[]},create(e){return Bt(x(e))?{}:cr(Vc.map(t=>Je(t,e,"advisory")))}},Us=F(Ms),js=F(Os),Gs=F(Ts),Hs=F(ws),Bs=F(Hc),Vs=F(ke.noArkRunKernelInDomain),Ws=F(ke.noArkRunDirectNew),zs=F(ke.noArkRunTransportBypass),Ys=F(ut.noArkOrderKernelInDomain),qs=F(ut.noArkOrderGenericUpdate),Zs=F(Ks),Xs=Wc,Js={"no-domain-infra-imports":Us,"no-raw-event-publish":js,"require-publish-source":Gs,"no-forbidden-globals":Hs,"no-denied-capabilities":Bs,"no-arkrun-kernel-in-domain":Vs,"no-arkrun-direct-new":Ws,"no-arkrun-transport-bypass":zs,"no-arkorder-kernel-in-domain":Ys,"no-arkorder-generic-update":qs,"arkrules-structure":Zs,"architecture-advisory":Xs},zc={"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","ark/arkrules-structure":"error","ark/architecture-advisory":"warn"},ft={meta:{name:"arkgate",version:Uc},rules:Js};function Yc(){let e=Vt();return{plugins:{ark:ft},rules:{...zc},...e?{settings:{ark:{contractHash:e}}}:{}}}a(Yc,"recommendedConfig");var Zt={};Object.defineProperty(Zt,"recommended",{enumerable:!0,configurable:!0,get:Yc});ft.configs=Zt;var qc=ft;0&&(module.exports={architectureAdvisory,arkRulesStructureRule,configs,contractFingerprint,findConfigPath,globToRegExp,isEdgeDenied,layerForRelativePath,loadArkConfig,noArkOrderGenericUpdate,noArkOrderKernelInDomain,noArkRunDirectNew,noArkRunKernelInDomain,noArkRunTransportBypass,noDeniedCapabilities,noDomainInfraImports,noForbiddenGlobals,noRawEventPublish,patternSpecificity,plugin,readTsconfigPathAliases,requirePublishSource,resolveImportSpecifier,resolveRelativeImport,rules});
11
+ `;)n+=1;continue}if(e[n]==="/"&&e[n+1]==="*"){let s=e.indexOf("*/",n+2);n=s<0?r:s+2;continue}return n}}a(Ns,"skipTrivia");function Lc(e){let t=e.replace(/^/,""),n="",r=0,s=t.length;for(;r<s;){let o=t[r];if(o==='"'){let i=r+1;for(;i<s&&t[i]!=='"';)i+=t[i]==="\\"?2:1;n+=t.slice(r,i+1),r=i+1;continue}if(o==="/"&&(t[r+1]==="/"||t[r+1]==="*")){n+=" ",r=Ns(t,r);continue}if(o===","){let i=Ns(t,r+1);if(t[i]==="}"||t[i]==="]"){r+=1;continue}}n+=o,r+=1}return n}a(Lc,"stripJsonc");function Ls(e){return JSON.parse(Lc(e))}a(Ls,"parseJsonc");var Ds=new Map,Se=new Map,Dc=64;function Wt(e){try{let t=Pe.default.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"missing"}}a(Wt,"fileStamp");function ee(e){try{return Pe.default.statSync(e).isFile()}catch{return!1}}a(ee,"isFile");function Fs(e){let t=E.default.resolve(e),n=Ds.get(t);if(n!==void 0&&(n===null||ee(n)))return n;let r=E.default.join(t,"tsconfig.json"),s;if(ee(r))s=r;else{let o=E.default.dirname(t);s=o===t?null:Fs(o)}return Ds.set(t,s),s}a(Fs,"findNearestTsconfig");function Fc(e,t){let n=e;for(;;){let r=E.default.join(n,"node_modules",t);for(let i of[r,`${r}.json`])if(ee(i))return i;let s=E.default.join(r,"package.json");if(ee(s))try{let i=JSON.parse(Pe.default.readFileSync(s,"utf8"));if(typeof i.tsconfig=="string"&&ee(E.default.join(r,i.tsconfig)))return E.default.join(r,i.tsconfig)}catch{}if(ee(E.default.join(r,"tsconfig.json")))return E.default.join(r,"tsconfig.json");let o=E.default.dirname(n);if(o===n)return null;n=o}}a(Fc,"resolvePackageExtends");function Pc(e,t){let n=E.default.dirname(e);if(t.startsWith(".")||E.default.isAbsolute(t)){let r=E.default.resolve(n,t);for(let s of[r,`${r}.json`])if(ee(s))return s;return null}return Fc(n,t)}a(Pc,"resolveExtends");function zt(e,t){return e.split("${configDir}").join(t)}a(zt,"substituteConfigDir");function Ps(e,t,n,r,s){if(n>8||r.has(e))return{};r.add(e),s.push({file:e,stamp:Wt(e)});let o;try{o=Ls(Pe.default.readFileSync(e,"utf8"))??{}}catch{return{}}let i={},l=o.extends,c=typeof l=="string"?[l]:Array.isArray(l)?l:[];for(let f of c){if(typeof f!="string")continue;let p=zt(f,t),g=Pc(e,p);if(!g){if(p.startsWith(".")||E.default.isAbsolute(p)){let R=E.default.resolve(E.default.dirname(e),p);for(let k of[R,`${R}.json`])s.push({file:k,stamp:Wt(k)})}continue}let m=Ps(g,t,n+1,r,s);m.baseUrl!==void 0&&(i.baseUrl=m.baseUrl),m.paths!==void 0&&(i.paths=m.paths,i.pathsBase=m.pathsBase)}let d=o.compilerOptions??{},u=E.default.dirname(e);return typeof d.baseUrl=="string"&&(i.baseUrl=E.default.resolve(u,zt(d.baseUrl,t))),d.paths&&typeof d.paths=="object"&&(i.paths=d.paths,i.pathsBase=u),i}a(Ps,"loadChain");function $c(e,t){let n=e.baseUrl??e.pathsBase??t,r=[];for(let[s,o]of Object.entries(e.paths??{})){if(!Array.isArray(o)||o.length===0)continue;let i=o.filter(f=>typeof f=="string").map(f=>zt(f,t));if(i.length===0)continue;let l=s.indexOf("*"),c=l>=0,d=c?s.slice(0,l):s,u=c?s.slice(l+1):"";c&&!d&&!u||r.push({from:d,to:i[0].replace(/\*$/,""),suffix:u,wildcard:c,targets:i})}return r.sort((s,o)=>Number(s.wildcard)-Number(o.wildcard)||o.from.length-s.from.length),{baseUrl:n,aliases:r}}a($c,"buildAliasSet");function Mc(e){let t=Se.get(e);if(t&&t.chain.every(i=>Wt(i.file)===i.stamp))return t.result;let n=[],r=E.default.dirname(e),s=Ps(e,r,0,new Set,n),o=$c(s,r);if(!Se.has(e)&&Se.size>=Dc){let i=Se.keys().next().value;i!==void 0&&Se.delete(i)}return Se.set(e,{chain:n,result:o}),o}a(Mc,"aliasesForTsconfig");function Yt(e){let t=Fs(e);return t?Mc(t):{baseUrl:E.default.resolve(e),aliases:[]}}a(Yt,"readTsconfigPathAliases");function $s(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,E.default.join(e,"index.ts"),E.default.join(e,"index.tsx"),E.default.join(e,"index.js")];for(let n of t)if(ee(n))return n;return null}a($s,"existingSourceFile");function qt(e,t){if(!t.startsWith("."))return null;let n=E.default.resolve(E.default.dirname(e),t);return $s(n)}a(qt,"resolveRelativeImport");function Kc(e,t){return e.wildcard?!t.startsWith(e.from)||!t.endsWith(e.suffix)||t.length<e.from.length+e.suffix.length?null:t.slice(e.from.length,t.length-e.suffix.length):t===e.from?"":null}a(Kc,"matchAlias");function dt(e,t,n){if(!t)return null;if(t.startsWith("."))return qt(e,t);let r=e?E.default.dirname(E.default.resolve(e)):n??".",{baseUrl:s,aliases:o}=Yt(r);for(let i of o){let l=Kc(i,t);if(l!==null){for(let c of i.targets){let d=i.wildcard?c.split("*").join(l):c,u=$s(E.default.resolve(s,d));if(u)return u}return null}}return null}a(dt,"resolveImportSpecifier");var Uc="4.8.26";function jc(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}a(jc,"containingProgram");function Gc(e){let t=jc(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!tt(r))return!1;continue}if(!(r.type==="TSInterfaceDeclaration"||r.type==="TSTypeAliasDeclaration")){if(r.type==="ExportNamedDeclaration"){if(r.declaration){if(r.declaration.type!=="TSInterfaceDeclaration"&&r.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!tt(r))return!1;n=!0;continue}return!1}}return n}a(Gc,"sourceProgramExportsOnlyTypes");var Ms={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{message}} Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let t=x(e),n=D(t),r=V(n),s=n?_.default.dirname(n):null,o=a(i=>{let l=Qe(i.source);if(l&&r&&s&&t){let c=_.default.isAbsolute(t)?t:_.default.resolve(t),d=_.default.relative(s,c).split(_.default.sep).join("/");if(!Q(r,d))return;let u=w(d,r.layers);if(!u)return;let f=dt(c,l,s);if(!f)return;let p=_.default.relative(s,f).split(_.default.sep).join("/");if(p.startsWith(".."))return;let g=w(p,r.layers);if(!g)return;let m={fromPath:d,toPath:p,layers:r.layers},R=gt(r.rules,u,g,m),k=R?.rule;if(k){let y=i.type?.startsWith("Export")?"export":"import",A=tt(i),S=!!k?.peerIsolation,v=A&&!S,O=R?.sliceVerdict,be=O?Rn({surface:"import",verdict:O,fromLayer:u,toLayer:g,kind:y,fromPath:d,toPath:p,ruleMessage:k?.message,childMessage:k?.childSlices?.message}):k?.message??`${u} must not ${y} ${g}.`,oe=v?`${be} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:be;N(e,i,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:d,fromLayer:u,toLayer:g,target:p,edgeKind:y,...S?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...Sn(O),...v?{failsStrict:!1,severity:"warning"}:{},...Gc(i)?{sourcePureTypeModule:!0}:{},message:oe},{fromLayer:u,toLayer:g,specifier:l,message:oe})}return}},"check");return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},Hc={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=x(e),n=D(t),r=V(n),s=n?_.default.dirname(n):null;if(!r||!s||!t)return{};let o=ct(r,s,t);if(!o?.layer)return{};let{relFile:i,layer:l}=o,c=new Set(In(l));return c.size===0?{}:ue(e,a((u,f,p,g)=>{if(p||typeof f!="string"||He(f,l.forbiddenGlobals??[]))return;let m=En(f);!m||!c.has(m)||N(e,u,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:i,fromLayer:l.name,target:f,capability:m,edgeKind:g,message:`${l.name} denies the ${m} capability; found import of "${f}".`},{layer:l.name,capability:m,specifier:f})},"check"))}},ke=hr({findConfigPath:D,loadArkConfig:V,resolveImportSpecifier:dt,lintedFilename:x,sourceIsInAnalysisScope:Q,isLocallyBound:Y,reportAdapterDiagnostic:N});function Bc(e,t){let n=_.default.dirname(_.default.resolve(e));return _.default.relative(n,_.default.resolve(t)).split(_.default.sep).join("/")}a(Bc,"toProjectRelative");var ut=Dr({findConfigPath:D,loadArkConfig:V,lintedFilename:x,sourceIsInAnalysisScope:Q,isLocallyBound:Y,reportAdapterDiagnostic:N,toProjectRelative:Bc}),Ks=Is(Q),Vc=[Ms,ke.noArkRunKernelInDomain,ke.noArkRunDirectNew,ke.noArkRunTransportBypass,ut.noArkOrderKernelInDomain,ut.noArkOrderGenericUpdate,Ks],Wc={meta:{type:"problem",docs:{description:"Report non-blocking Ark findings (type-only placement debt, advisory slice walls, advisory arkRun / arkOrder / ArkRules) as warnings \u2014 the same findings ark-check reports as warnings."},messages:{[Ct]:or},schema:[]},create(e){return Bt(x(e))?{}:cr(Vc.map(t=>Je(t,e,"advisory")))}},Us=F(Ms),js=F(Os),Gs=F(Ts),Hs=F(ws),Bs=F(Hc),Vs=F(ke.noArkRunKernelInDomain),Ws=F(ke.noArkRunDirectNew),zs=F(ke.noArkRunTransportBypass),Ys=F(ut.noArkOrderKernelInDomain),qs=F(ut.noArkOrderGenericUpdate),Zs=F(Ks),Xs=Wc,Js={"no-domain-infra-imports":Us,"no-raw-event-publish":js,"require-publish-source":Gs,"no-forbidden-globals":Hs,"no-denied-capabilities":Bs,"no-arkrun-kernel-in-domain":Vs,"no-arkrun-direct-new":Ws,"no-arkrun-transport-bypass":zs,"no-arkorder-kernel-in-domain":Ys,"no-arkorder-generic-update":qs,"arkrules-structure":Zs,"architecture-advisory":Xs},zc={"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","ark/arkrules-structure":"error","ark/architecture-advisory":"warn"},ft={meta:{name:"arkgate",version:Uc},rules:Js};function Yc(){let e=Vt();return{plugins:{ark:ft},rules:{...zc},...e?{settings:{ark:{contractHash:e}}}:{}}}a(Yc,"recommendedConfig");var Zt={};Object.defineProperty(Zt,"recommended",{enumerable:!0,configurable:!0,get:Yc});ft.configs=Zt;var qc=ft;0&&(module.exports={architectureAdvisory,arkRulesStructureRule,configs,contractFingerprint,findConfigPath,globToRegExp,isEdgeDenied,layerForRelativePath,loadArkConfig,noArkOrderGenericUpdate,noArkOrderKernelInDomain,noArkRunDirectNew,noArkRunKernelInDomain,noArkRunTransportBypass,noDeniedCapabilities,noDomainInfraImports,noForbiddenGlobals,noRawEventPublish,patternSpecificity,plugin,readTsconfigPathAliases,requirePublishSource,resolveImportSpecifier,resolveRelativeImport,rules});
12
12
 
13
13
  /* arkgate:eslint-cjs-plugin-shape */
14
14
  ;(function(){var m=module.exports,p=m&&m.default;if(!p||typeof p!=="object")return;
@@ -8,4 +8,4 @@ ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
8
8
  `)}`),this.name="ArkRulesValidationError",this.source=t,this.issues=n}};function Ml(e){return{...e,$schema:e.$schema===void 0?Nt:e.$schema,schemaVersion:e.schemaVersion===void 0?Oe:e.schemaVersion,structure:e.structure===void 0?[]:e.structure,invariants:e.invariants===void 0?[]:e.invariants}}a(Ml,"defaultedArkRules");function Xr(e){return e==="enforced"?"enforced":"advisory"}a(Xr,"normalizeMode");function Kl(e){return $l.includes(e)}a(Kl,"isTier2Sensor");function Ul(e,t){let n=Array.isArray(e.structure)?e.structure:[],r=Array.isArray(e.invariants)?e.invariants:[],s=new Set;n.forEach((o,i)=>{if(!Z(o))return;let l=typeof o.id=="string"?o.id:"";l&&(s.has(l)&&t.push({path:`$.structure[${i}].id`,message:`duplicate rule id ${JSON.stringify(l)}`}),s.add(l)),typeof o.sensor=="string"&&Kl(o.sensor)&&o.mode==="enforced"&&t.push({path:`$.structure[${i}].mode`,message:`${l?`rule ${JSON.stringify(l)} uses sensor `:"sensor "}${JSON.stringify(o.sensor)}, which is Tier-2 advisory-only and cannot be enforced${l?" (arkgate-check --sensors lists which sensors can)":""}`}),Array.isArray(o.appliesTo)&&o.appliesTo.length===0&&t.push({path:`$.structure[${i}].appliesTo`,message:"must not be an empty array (omit the field to apply to the whole layer)"})}),r.forEach((o,i)=>{if(!Z(o))return;let l=typeof o.id=="string"?o.id:"";l&&(s.has(l)&&t.push({path:`$.invariants[${i}].id`,message:`duplicate rule id ${JSON.stringify(l)}`}),s.add(l)),Array.isArray(o.appliesTo)&&o.appliesTo.length===0&&t.push({path:`$.invariants[${i}].appliesTo`,message:"must not be an empty array (omit the field to apply to the whole layer)"})})}a(Ul,"validateSemantics");function Lt(e,t="arkrules.json",n){if(!Z(e))throw new ge(t,[{path:"$",message:`must be an object; received ${j(e)}`}]);let r=Ml(e),s=[];if(q(r,Zr,"$",Zr,s),Ul(r,s),n!==void 0&&typeof r.layer=="string"&&r.layer!==n&&s.push({path:"$.layer",message:`must match referencing key ${JSON.stringify(n)}; received ${JSON.stringify(r.layer)}`}),s.length>0)throw new ge(t,s);return{config:r}}a(Lt,"loadArkRulesContract");function rt(e,t){return e.childId?`${e.childId}#${t}`:t}a(rt,"effectiveRuleId");function Jr(e,t){if(t&&t.length>0)return[...t];if(e.childId&&e.defaultAppliesTo&&e.defaultAppliesTo.length>0)return[...e.defaultAppliesTo]}a(Jr,"effectiveAppliesTo");function Qr(e,t){return{sourceFile:e.sourceFile,ruleId:rt(e,t),layer:e.layer,...e.childId?{childId:e.childId}:{}}}a(Qr,"provenanceFor");function es(e,t){let n=t.replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase(),r=e.trim().replace(/\\/g,"/").replace(/^\.\//,"").toLowerCase();if(!r||!n||r.includes(".."))return!1;if(r===n||r===`${n}/**`||r===`${n}/*`)return!0;if(r.startsWith(`${n}/`)){let i=r.slice(n.length+1).split("/"),l=i.indexOf("**");return l!==-1&&l!==i.length-1?!1:i.every(c=>c.length>0)}let s=n.replace(/^(?:src|app)\//,""),o=r.replace(/^(?:src|app)\//,"");return s!==n||o!==r?es(o,s):!1}a(es,"appliesToPatternInsideSlice");function ts(e){if(!e.childId||!e.defaultAppliesTo?.length)return[];let t=String(e.defaultAppliesTo[0]).replace(/\/\*\*$/,""),n=[],r=[...e.file.structure??[],...e.file.invariants??[]];for(let s of r)for(let o of s.appliesTo??[])es(o,t)||n.push({id:s.id,pattern:o});return n}a(ts,"sliceScopeEscapes");function ns(e){let t=new Map,n=new Map;for(let r of e){let s=[...(r.file.structure??[]).map(o=>o.id),...(r.file.invariants??[]).map(o=>o.id)];for(let o of s){let i=rt(r,o),l=`${r.layer}\0${i}`,c=t.get(l);if(!c){t.set(l,{id:i,layer:r.layer,sourceFiles:[r.sourceFile]});continue}let d=n.get(l)??{id:i,layer:r.layer,sourceFiles:[...c.sourceFiles]};d.sourceFiles.includes(r.sourceFile)||d.sourceFiles.push(r.sourceFile),n.set(l,d)}}return[...n.values()]}a(ns,"duplicateArkRuleIds");function rs(e){let t={},n=[],r=[],s=[...e].sort((o,i)=>o.layer.localeCompare(i.layer)||o.sourceFile.localeCompare(i.sourceFile));for(let o of s){let i=(o.file.structure??[]).map(d=>{let u=Jr(o,d.appliesTo);return{...d,id:rt(o,d.id),...u?{appliesTo:u}:{appliesTo:void 0},mode:Xr(d.mode),provenance:Qr(o,d.id)}}),l=(o.file.invariants??[]).map(d=>{let u=Jr(o,d.appliesTo);return{...d,id:rt(o,d.id),...u?{appliesTo:u}:{appliesTo:void 0},mode:Xr(d.mode),provenance:Qr(o,d.id)}}),c=t[o.layer];c?(c.sourceFiles||(c.sourceFiles=[c.sourceFile]),c.sourceFiles.includes(o.sourceFile)||c.sourceFiles.push(o.sourceFile),c.structure.push(...i),c.invariants.push(...l)):t[o.layer]={sourceFile:o.sourceFile,sourceFiles:[o.sourceFile],structure:i,invariants:l},n.push(...i),r.push(...l)}return n.sort((o,i)=>{let l=o.provenance.layer.localeCompare(i.provenance.layer);return l!==0?l:o.id.localeCompare(i.id)}),r.sort((o,i)=>{let l=o.provenance.layer.localeCompare(i.provenance.layer);return l!==0?l:o.id.localeCompare(i.id)}),{schemaVersion:Oe,byLayer:t,structure:n,invariants:r}}a(rs,"buildEffectiveArkRules");function re(){return{schemaVersion:Oe,byLayer:{},structure:[],invariants:[]}}a(re,"emptyEffectiveArkRules");var Dt=class extends Error{static{a(this,"EffectiveContractError")}issues;source;constructor(t,n){super(`Invalid Effective Contract (${t}):
9
9
  ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
10
10
  `)}`),this.name="EffectiveContractError",this.source=t,this.issues=n}};function ss(e){return e.replace(/\\/g,"/").replace(/^\.\//,"")}a(ss,"normalizeRel");function os(e,t="ark.config.json"){let n=e.config.arkRules??{},r=[],s=Object.keys(n).length>0,o=!!(e.governedFiles&&e.governedFiles.length>0);if(!s&&!o){if(e.discoveredArkRulesFiles&&e.discoveredArkRulesFiles.length>0)for(let f of[...e.discoveredArkRulesFiles].sort())r.push({path:f,message:`ArkRules file ${JSON.stringify(f)} is not referenced by arkRules and will not be enforced`,severity:"advisory"});return{config:e.config,arkRules:re(),warnings:r}}let i=new Set(e.config.layers.map(f=>f.name)),l=[],c=[],d=new Set,u=a((f,p,g)=>{if(g instanceof ge){for(let m of g.issues)l.push({path:`${f}${m.path==="$"?"":m.path.replace(/^\$/,"")}`,message:`${p}: ${m.message}`});return}if(g instanceof SyntaxError){l.push({path:f,message:`referenced ArkRules file ${JSON.stringify(p)} is not valid JSON: ${g.message}`});return}l.push({path:f,message:`referenced ArkRules file ${JSON.stringify(p)} failed to load: ${g instanceof Error?g.message:String(g)}`})},"pushLoadIssue");for(let f of Object.keys(n).sort()){let p=n[f],g=`$.arkRules[${JSON.stringify(f)}]`,m=Array.isArray(p)?p:typeof p=="string"?[p]:null;if(!m||m.length===0||m.some(R=>typeof R!="string"||R.length===0)){l.push({path:g,message:"must be a non-empty path string or an array of paths"});continue}if(!i.has(f)){l.push({path:g,message:`layer ${JSON.stringify(f)} is not declared in layers[]`});continue}m.forEach((R,k)=>{let y=m.length===1&&typeof p=="string"?g:`${g}[${k}]`;if(R.startsWith("/")||/^[A-Za-z]:[\\/]/.test(R)){l.push({path:y,message:"must be a project-relative path (absolute paths are not allowed)"});return}let A=ss(R);d.add(A);let S=e.fileContents[A]??e.fileContents[R];if(S===void 0){l.push({path:y,message:`referenced ArkRules file ${JSON.stringify(A)} is missing`});return}try{let I=Lt(JSON.parse(S),A,f);c.push({layer:f,sourceFile:A,file:I.config})}catch(I){u(y,A,I)}})}if(e.governedFiles&&e.governedFiles.length>0){let f=$e({files:e.governedFiles,rules:e.config.rules,layers:[...i]});for(let p of f){let g=e.fileContents[p.path];if(g!==void 0){d.add(p.path);try{let m=Lt(JSON.parse(g),p.path,p.layer),R={layer:p.layer,sourceFile:p.path,file:m.config,childId:p.childId,defaultAppliesTo:p.defaultAppliesTo},k=ts(R);if(k.length>0){l.push({path:p.path,message:`ARKRULE_SCOPE_ESCAPES_SLICE: ${p.path} appliesTo ${k.map(y=>y.pattern).join(", ")} escapes ${p.childId}`});continue}c.push(R)}catch(m){u(p.path,p.path,m)}}}}for(let f of ns(c))l.push({path:`$.arkRules[${JSON.stringify(f.layer)}]`,message:`ARKRULE_DUPLICATE_ID: ${f.id} is declared in ${f.sourceFiles.join(", ")}`});if(e.discoveredArkRulesFiles)for(let f of[...e.discoveredArkRulesFiles].sort()){let p=ss(f);d.has(p)||r.push({path:p,message:`ArkRules file ${JSON.stringify(p)} is not referenced by arkRules and will not be enforced`,severity:"advisory"})}if(l.length>0)throw new Dt(t,l);return{config:e.config,arkRules:rs(c),warnings:r}}a(os,"resolveEffectiveContract");var jl=2e3,is=new Map;function as(e){try{return H.statSync(e).isFile()}catch{return!1}}a(as,"isFile");function Pt(e){let t=is.get(e);if(t){if(t.found!==null&&as(t.found))return t.found;if(t.found===null&&Date.now()-t.at<jl)return null}let n=v.join(e,"ark.config.json"),r;if(as(n))r=n;else{let s=v.dirname(e);r=s===e?null:Pt(s)}return is.set(e,{found:r,at:Date.now()}),r}a(Pt,"findConfigInDir");function D(e){return!e||e==="<input>"||e.startsWith("stdin")?null:Pt(v.dirname(v.resolve(e)))}a(D,"findConfigPath");var he=new Map,Gl=64;function Hl(e){try{let t=H.statSync(e,{throwIfNoEntry:!1});return t?.isFile()?`${t.mtimeMs}:${t.size}:${t.ino}`:null}catch{return null}}a(Hl,"configFileStamp");function Bl(e,t){if(!he.has(e)&&he.size>=Gl){let n=he.keys().next().value;n!==void 0&&he.delete(n)}he.set(e,t)}a(Bl,"rememberContract");var Vl=/\.[cm]?[tj]sx?$/,Wl=/(^test(?:[-_.]).*|\.(spec|test)(?:-d)?\.)(tsx?|jsx?|mjsx?|cjsx?|mts|cts)$/i,zl=new Set(["node_modules","dist","coverage","bench","benches","benchmark","benchmarks","docs","documentation","example","examples","fixture","fixtures","testdata","playground","scaffold","scaffolds","__tests__","__mocks__","e2e","test","tests"]);function Yl(e){return Vl.test(e)&&!e.endsWith(".d.ts")&&!Wl.test(e)}a(Yl,"isGovernableSourceName");function ql(e){let t=e?.arkRules;if(!t||typeof t!="object")return[];let n=[];for(let r of Object.values(t))if(typeof r=="string"&&r.length>0)n.push(r);else if(Array.isArray(r))for(let s of r)typeof s=="string"&&s.length>0&&n.push(s);return n}a(ql,"arkRulesRefs");function fs(e,t){let n=t.include&&t.include.length>0?t.include:["src"],r=[],s=a(o=>{let i;try{i=H.readdirSync(o,{withFileTypes:!0})}catch{return}for(let l of i){if(l.name.startsWith("."))continue;let c=v.join(o,l.name);if(l.isDirectory()){if(zl.has(l.name))continue;s(c);continue}if(!l.isFile()||!Yl(l.name))continue;let d=v.relative(e,c).split(v.sep).join("/");!d||d.startsWith("..")||dt(d,t)||r.push(d)}},"walk");for(let o of n){let i=String(o).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");s(v.resolve(e,i==="."?"":i))}return r}a(fs,"governedRelativeFiles");function Zl(e,t){return $e({files:t,rules:e.rules,layers:e.layers.map(n=>n.name)}).map(n=>n.path)}a(Zl,"plannedSlicePaths");function Xl(e,t){let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=v.resolve(e,n),s=v.relative(e,r);if(!(s.startsWith("..")||v.isAbsolute(s)))try{return H.readFileSync(r,"utf8")}catch{return}}a(Xl,"readReferencedFile");function ps(e,t){if(!e)return[];let n=new Set,r=[],s=a(o=>{let i=o.replace(/\\/g,"/").replace(/^\.\//,"");!i||n.has(i)||(n.add(i),r.push(i))},"add");for(let o of ql(e))s(o);for(let o of Zl(e,t))s(o);return r}a(ps,"contractSourcePaths");function Ft(e,t){let n=t?fs(e,t):[];return ps(t,n).map(r=>{try{let s=H.statSync(v.resolve(e,r));return`${r}:${s.mtimeMs}:${s.size}`}catch{return`${r}:missing`}}).join("|")}a(Ft,"refStampsFor");function ls(e){return e instanceof Error?e.message:String(e)}a(ls,"errorText");function Jl(e,t){let n=v.dirname(e),r;try{r=nt(t,e).config}catch(c){return{config:null,arkRules:re(),error:ls(c),fingerprint:null}}let s=fs(n,r),o=ps(r,s),i=us("sha256").update(t);if(o.length===0)return{config:r,arkRules:re(),error:null,fingerprint:i.digest("hex")};let l={};for(let c of o){let d=Xl(n,c);if(d===void 0)continue;let u=c.replace(/\\/g,"/").replace(/^\.\//,"");l[u]=d,i.update(`\0${u}\0${d}`)}try{let c=os({config:r,fileContents:l,governedFiles:s},e);return{config:r,arkRules:c.arkRules,error:null,fingerprint:i.digest("hex")}}catch(c){return{config:null,arkRules:re(),error:ls(c),fingerprint:null}}}a(Jl,"resolveContract");function me(e){let t=v.dirname(e),n=Hl(e),r=he.get(e);if(r&&n!==null&&r.stamp===n&&Ft(t,r.refConfig)===r.refStamps)return r.result;let s;try{s=H.readFileSync(e,"utf8")}catch{return{config:null,arkRules:re(),error:null,fingerprint:null}}if(r?.source===s&&Ft(t,r.refConfig)===r.refStamps)return r.stamp=n,r.result;let o=Jl(e,s),i=o.config??Ql(s,e);return Bl(e,{source:s,stamp:n,refConfig:i,refStamps:Ft(t,i),result:o}),o}a(me,"loadArkContract");function Ql(e,t){try{return nt(e,t).config}catch{return null}}a(Ql,"safeConfig");function ec(e){if(!H.existsSync(e))return null;let t=me(e);return t.config?t.config:nt(H.readFileSync(e,"utf8"),e).config}a(ec,"loadArkConfig");function X(e,t){return(e.include??[]).some(r=>{let s=String(r).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!dt(t,e)}a(X,"sourceIsInAnalysisScope");function st(e,t,n){let r=v.isAbsolute(n)?n:v.resolve(n),s=v.relative(t,r).split(v.sep).join("/");if(!X(e,s))return null;let o=e.layers?.find(i=>i.name===w(s,e.layers));return{relFile:s,layer:o}}a(st,"lintedFileInScope");function B(e){return e?me(e).config:null}a(B,"configForRule");var cs="configInvalid",tc="Ark contract is invalid, so no architecture verdict is possible (fix it; ark-check fails closed the same way): {{detail}}",ds=new WeakSet;function $t(e){let t=D(e);return t?me(t).error:null}a($t,"contractErrorForFile");function F(e){return{meta:{...e.meta,messages:{...e.meta.messages,[cs]:tc,[We]:Zn}},create(t){let n=$t(x(t));return n?{Program(r){let s=W(t);if(s&&typeof s=="object"){if(ds.has(s))return;ds.add(s)}t.report({...r?.loc?.start?{node:r}:{loc:{line:1,column:0}},messageId:cs,data:{detail:n.replace(/\s*\n\s*/g," ")}})}}:ze(e,t,"blocking")}}}a(F,"withContractGuard");function gs(e=process.cwd()){let t=Pt(v.resolve(e));if(!t)return null;let n=me(t);if(n.fingerprint)return n.fingerprint;try{return us("sha256").update(H.readFileSync(t,"utf8")).digest("hex")}catch{return null}}a(gs,"contractFingerprint");var rc=256*1024;function sc(e){try{return nc.readFileSync(e,"utf8")}catch{return""}}a(sc,"readUtf8");function oc(e,t){if(!/\.(tsx?|mts|cts)$/i.test(e))return[];try{return ve(e,t)}catch{return[]}}a(oc,"classShapesFor");function ic(e,t){if(!/\.(tsx?|mts|cts|jsx?|mjs|cjs)$/i.test(e)||e.endsWith(".d.ts"))return{};if(t.length>rc)return{};let n=Kn(e,t);return n?{[e]:n}:{}}a(ic,"hintsFor");function hs(e){return{meta:{type:"problem",docs:{description:"Report ArkRules structure-sensor findings for the linted file (same Effective Contract and evaluators as ark-check; file-local sensors only)."},messages:{structure:"ArkRules {{arkruleId}} ({{sensor}}): {{message}}"},schema:[]},create(t){let n=x(t),r=D(n);if(!r||!n)return{};let s=me(r),o=s.config;if(!o||s.arkRules.structure.length===0)return{};let i=ot.dirname(r),l=ot.resolve(n),c=ot.relative(i,l).split(ot.sep).join("/");if(!e(o,c))return{};let d=w(c,o.layers);return{Program(u){let f=ce(t)??sc(l),p=Mn({arkRules:s.arkRules,classShapes:oc(c,f),files:[c],layerForFile:a(g=>g===c?d:w(g,o.layers),"layerForFile"),fileHints:ic(c,f)}).filter(g=>g.file===c);for(let g of p)O(t,{loc:{start:{line:g.line}},parent:u},"structure",{ruleId:g.ruleId,code:g.code,file:c,line:g.line,fromLayer:g.fromLayer,arkruleId:g.arkruleId,arkruleSource:g.arkruleSource,severity:g.severity,failsStrict:g.failsStrict,message:g.message},{arkruleId:g.arkruleId,sensor:g.sensor,message:g.message})}}}}}a(hs,"createArkRulesStructureRule");import Te from"path";function ms(e,t,n){for(let r=t.length;r>=n;r-=1){let s=t.slice(0,r).join(".");if(e.has(s))return s}}a(ms,"longestForbidden");var ys={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=x(e),n=e.options?.[0],r=D(t),s=B(r),o=r?Te.dirname(r):null,i=null,l="this layer";if(s&&o&&t){let y=st(s,o,t);if(!y)return{};let{layer:A}=y;A?.forbiddenGlobals?.length?(i=new Set(A.forbiddenGlobals),l=A.name):i=null}else n?.globals&&(i=new Set(n.globals));if(!i)return{};let c=i,d=typeof W(e)?.getScope=="function",u=Te.isAbsolute(t)?t:Te.resolve(t),f=o?Te.relative(o,u).split(Te.sep).join("/"):t,p=a((y,A)=>{O(e,y,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:f,fromLayer:l,target:A,message:`${l} must not use the ambient global "${A}".`},{name:A,layer:l})},"report"),g=a((y,A,S,I)=>{if(S||typeof A!="string")return;let _=Me(A,c);_&&O(e,y,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:f,fromLayer:l,target:A,edgeKind:I,message:`${l} must not use module "${A}" because it is the import form of forbidden global "${_}".`},{layer:l,name:_,specifier:A,importKind:I})},"reportModule"),m=a((y,A)=>{if(y?.type==="ObjectPattern")for(let S of y.properties??[]){if(S.type==="RestElement")continue;let I=It(S.key,S.computed);if(!I)continue;let _=[...A,I],Se=ms(c,_,A.length+1);if(Se){p(S,Se);continue}let se=S.value,Ds=se?.type==="AssignmentPattern"?se.left:se;m(Ds,_)}},"checkPattern"),R=a((y,A)=>{if(y?.type!=="ObjectPattern")return;let S=we(A);if(!S||z(e,S.root,S.segments[0]))return;let I=S.segments[0]==="globalThis"?S.segments.slice(1):S.segments;m(y,I)},"checkDestructure"),k=de(e,g);return{MemberExpression(y){if(y.parent?.type==="MemberExpression"&&y.parent.object===y)return;let A=we(y);if(!A||z(e,A.root,A.segments[0]))return;let S=A.segments[0]==="globalThis",I=S?A.segments.slice(1):A.segments,_=ms(c,I,S?1:2);_?p(y,_):!d&&c.has(A.segments[0])&&p(y,A.segments[0])},VariableDeclarator(y){R(y.id,y.init)},AssignmentExpression(y){R(y.left,y.right)},CallExpression(y){if(k.CallExpression(y),d)return;let A=y.callee?.type==="Identifier"?y.callee.name:void 0;A&&c.has(A)&&p(y,A)},ImportDeclaration:k.ImportDeclaration,ImportExpression:k.ImportExpression,TSImportEqualsDeclaration:k.TSImportEqualsDeclaration,ExportNamedDeclaration:k.ExportNamedDeclaration,ExportAllDeclaration:k.ExportAllDeclaration,NewExpression(y){if(d)return;let A=y.callee?.type==="Identifier"?y.callee.name:void 0;A&&c.has(A)&&p(y,A)},Identifier(y){!d||!y.name||!c.has(y.name)||!tr(e,y)||z(e,y,y.name)||p(y,y.name)}}}};import it from"path";function As(e,t){if(!(e?.type&&e.type!=="ObjectExpression"))return e?.properties?.find(n=>qe(n.key)===t)}a(As,"objectProperty");function ye(e,t){return As(e,t)!==void 0}a(ye,"objectHasProperty");function ac(e){let t=As(e,"metadata")?.value;return ye(t,"source")}a(ac,"objectHasMetadataSource");function Rs(e){let t=e.callee;return t?.type==="Identifier"?t.name==="publish":t?.computed!==!0&&qe(t?.property)==="publish"}a(Rs,"isPublishCall");function Ss(e){return e?e.type==="Identifier"||e.type===void 0&&e.name?/^[A-Z]/.test(e.name??""):e.type==="MemberExpression"&&e.computed!==!0?Ss(e.property):!1:!1}a(Ss,"looksLikeIntentCreator");function lc(e){let t=xe(e);return t!==void 0&&be(t)||ye(e,"intent")||Ss(e)}a(lc,"isArkPublishCandidate");function cc(e){let[t,n,r]=e;return ac(t)||ye(n,"source")||ye(r,"source")}a(cc,"publishHasSource");function dc(e){let t=x(e),n=D(t),r=B(n);if(!r||!n||!t)return null;let s=it.relative(it.dirname(n),it.resolve(t)).split(it.sep).join("/");return X(r,s)?s:null}a(dc,"scopedFile");var ks={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 n=t.arguments?.[0],s=ft({publishCall:Rs(t),rawIntentName:xe(n),objectHasIntent:ye(n,"intent"),arkPublishCandidate:!1,hasSource:!0}).find(o=>o.ruleId==="RAW_EVENT_PUBLISH");s&&O(e,t,"rawPublish",{...s,file:x(e)})}}}},bs={meta:{type:"problem",docs:{description:"Require Ark publish calls (intent creator / Ark intent first argument) to include source metadata. Silent without an ark.config.json or outside its include scope, like ark-check."},messages:{missingSource:"Strict Ark publish calls must include metadata.source."},schema:[]},create(e){let t=dc(e);return t?{CallExpression(n){let r=n.arguments??[],s=r[0],i=ft({publishCall:Rs(n),rawIntentName:xe(s),objectHasIntent:ye(s,"intent"),arkPublishCandidate:lc(s),hasSource:cc(r)}).find(l=>l.ruleId==="PUBLISH_MISSING_SOURCE");i&&O(e,n,"missingSource",{...i,file:t})}}:{}}};import at from"fs";import E from"path";function Es(e,t){let n=t,r=e.length;for(;;){for(;n<r&&/\s/.test(e[n]);)n+=1;if(e[n]==="/"&&e[n+1]==="/"){for(;n<r&&e[n]!==`
11
- `;)n+=1;continue}if(e[n]==="/"&&e[n+1]==="*"){let s=e.indexOf("*/",n+2);n=s<0?r:s+2;continue}return n}}a(Es,"skipTrivia");function uc(e){let t=e.replace(/^/,""),n="",r=0,s=t.length;for(;r<s;){let o=t[r];if(o==='"'){let i=r+1;for(;i<s&&t[i]!=='"';)i+=t[i]==="\\"?2:1;n+=t.slice(r,i+1),r=i+1;continue}if(o==="/"&&(t[r+1]==="/"||t[r+1]==="*")){n+=" ",r=Es(t,r);continue}if(o===","){let i=Es(t,r+1);if(t[i]==="}"||t[i]==="]"){r+=1;continue}}n+=o,r+=1}return n}a(uc,"stripJsonc");function Is(e){return JSON.parse(uc(e))}a(Is,"parseJsonc");var vs=new Map,Ae=new Map,fc=64;function Mt(e){try{let t=at.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"missing"}}a(Mt,"fileStamp");function J(e){try{return at.statSync(e).isFile()}catch{return!1}}a(J,"isFile");function ws(e){let t=E.resolve(e),n=vs.get(t);if(n!==void 0&&(n===null||J(n)))return n;let r=E.join(t,"tsconfig.json"),s;if(J(r))s=r;else{let o=E.dirname(t);s=o===t?null:ws(o)}return vs.set(t,s),s}a(ws,"findNearestTsconfig");function pc(e,t){let n=e;for(;;){let r=E.join(n,"node_modules",t);for(let i of[r,`${r}.json`])if(J(i))return i;let s=E.join(r,"package.json");if(J(s))try{let i=JSON.parse(at.readFileSync(s,"utf8"));if(typeof i.tsconfig=="string"&&J(E.join(r,i.tsconfig)))return E.join(r,i.tsconfig)}catch{}if(J(E.join(r,"tsconfig.json")))return E.join(r,"tsconfig.json");let o=E.dirname(n);if(o===n)return null;n=o}}a(pc,"resolvePackageExtends");function gc(e,t){let n=E.dirname(e);if(t.startsWith(".")||E.isAbsolute(t)){let r=E.resolve(n,t);for(let s of[r,`${r}.json`])if(J(s))return s;return null}return pc(n,t)}a(gc,"resolveExtends");function Kt(e,t){return e.split("${configDir}").join(t)}a(Kt,"substituteConfigDir");function xs(e,t,n,r,s){if(n>8||r.has(e))return{};r.add(e),s.push({file:e,stamp:Mt(e)});let o;try{o=Is(at.readFileSync(e,"utf8"))??{}}catch{return{}}let i={},l=o.extends,c=typeof l=="string"?[l]:Array.isArray(l)?l:[];for(let f of c){if(typeof f!="string")continue;let p=Kt(f,t),g=gc(e,p);if(!g){if(p.startsWith(".")||E.isAbsolute(p)){let R=E.resolve(E.dirname(e),p);for(let k of[R,`${R}.json`])s.push({file:k,stamp:Mt(k)})}continue}let m=xs(g,t,n+1,r,s);m.baseUrl!==void 0&&(i.baseUrl=m.baseUrl),m.paths!==void 0&&(i.paths=m.paths,i.pathsBase=m.pathsBase)}let d=o.compilerOptions??{},u=E.dirname(e);return typeof d.baseUrl=="string"&&(i.baseUrl=E.resolve(u,Kt(d.baseUrl,t))),d.paths&&typeof d.paths=="object"&&(i.paths=d.paths,i.pathsBase=u),i}a(xs,"loadChain");function hc(e,t){let n=e.baseUrl??e.pathsBase??t,r=[];for(let[s,o]of Object.entries(e.paths??{})){if(!Array.isArray(o)||o.length===0)continue;let i=o.filter(f=>typeof f=="string").map(f=>Kt(f,t));if(i.length===0)continue;let l=s.indexOf("*"),c=l>=0,d=c?s.slice(0,l):s,u=c?s.slice(l+1):"";c&&!d&&!u||r.push({from:d,to:i[0].replace(/\*$/,""),suffix:u,wildcard:c,targets:i})}return r.sort((s,o)=>Number(s.wildcard)-Number(o.wildcard)||o.from.length-s.from.length),{baseUrl:n,aliases:r}}a(hc,"buildAliasSet");function mc(e){let t=Ae.get(e);if(t&&t.chain.every(i=>Mt(i.file)===i.stamp))return t.result;let n=[],r=E.dirname(e),s=xs(e,r,0,new Set,n),o=hc(s,r);if(!Ae.has(e)&&Ae.size>=fc){let i=Ae.keys().next().value;i!==void 0&&Ae.delete(i)}return Ae.set(e,{chain:n,result:o}),o}a(mc,"aliasesForTsconfig");function Cs(e){let t=ws(e);return t?mc(t):{baseUrl:E.resolve(e),aliases:[]}}a(Cs,"readTsconfigPathAliases");function _s(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,E.join(e,"index.ts"),E.join(e,"index.tsx"),E.join(e,"index.js")];for(let n of t)if(J(n))return n;return null}a(_s,"existingSourceFile");function Os(e,t){if(!t.startsWith("."))return null;let n=E.resolve(E.dirname(e),t);return _s(n)}a(Os,"resolveRelativeImport");function yc(e,t){return e.wildcard?!t.startsWith(e.from)||!t.endsWith(e.suffix)||t.length<e.from.length+e.suffix.length?null:t.slice(e.from.length,t.length-e.suffix.length):t===e.from?"":null}a(yc,"matchAlias");function Ut(e,t,n){if(!t)return null;if(t.startsWith("."))return Os(e,t);let r=e?E.dirname(E.resolve(e)):n??".",{baseUrl:s,aliases:o}=Cs(r);for(let i of o){let l=yc(i,t);if(l!==null){for(let c of i.targets){let d=i.wildcard?c.split("*").join(l):c,u=_s(E.resolve(s,d));if(u)return u}return null}}return null}a(Ut,"resolveImportSpecifier");var Ac="4.8.25";function Rc(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}a(Rc,"containingProgram");function Sc(e){let t=Rc(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!Ze(r))return!1;continue}if(!(r.type==="TSInterfaceDeclaration"||r.type==="TSTypeAliasDeclaration")){if(r.type==="ExportNamedDeclaration"){if(r.declaration){if(r.declaration.type!=="TSInterfaceDeclaration"&&r.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!Ze(r))return!1;n=!0;continue}return!1}}return n}a(Sc,"sourceProgramExportsOnlyTypes");var Ts={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{message}} Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let t=x(e),n=D(t),r=B(n),s=n?N.dirname(n):null,o=a(i=>{let l=Ye(i.source);if(l&&r&&s&&t){let c=N.isAbsolute(t)?t:N.resolve(t),d=N.relative(s,c).split(N.sep).join("/");if(!X(r,d))return;let u=w(d,r.layers);if(!u)return;let f=Ut(c,l,s);if(!f)return;let p=N.relative(s,f).split(N.sep).join("/");if(p.startsWith(".."))return;let g=w(p,r.layers);if(!g)return;let m={fromPath:d,toPath:p,layers:r.layers},R=ct(r.rules,u,g,m),k=R?.rule;if(k){let y=i.type?.startsWith("Export")?"export":"import",A=Ze(i),S=!!k?.peerIsolation,I=A&&!S,_=R?.sliceVerdict,Se=_?dn({surface:"import",verdict:_,fromLayer:u,toLayer:g,kind:y,fromPath:d,toPath:p,ruleMessage:k?.message,childMessage:k?.childSlices?.message}):k?.message??`${u} must not ${y} ${g}.`,se=I?`${Se} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:Se;O(e,i,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:d,fromLayer:u,toLayer:g,target:p,edgeKind:y,...S?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...un(_),...I?{failsStrict:!1,severity:"warning"}:{},...Sc(i)?{sourcePureTypeModule:!0}:{},message:se},{fromLayer:u,toLayer:g,specifier:l,message:se})}return}},"check");return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},kc={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=x(e),n=D(t),r=B(n),s=n?N.dirname(n):null;if(!r||!s||!t)return{};let o=st(r,s,t);if(!o?.layer)return{};let{relFile:i,layer:l}=o,c=new Set(gn(l));return c.size===0?{}:de(e,a((u,f,p,g)=>{if(p||typeof f!="string"||Me(f,l.forbiddenGlobals??[]))return;let m=pn(f);!m||!c.has(m)||O(e,u,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:i,fromLayer:l.name,target:f,capability:m,edgeKind:g,message:`${l.name} denies the ${m} capability; found import of "${f}".`},{layer:l.name,capability:m,specifier:f})},"check"))}},Re=ir({findConfigPath:D,loadArkConfig:B,resolveImportSpecifier:Ut,lintedFilename:x,sourceIsInAnalysisScope:X,isLocallyBound:z,reportAdapterDiagnostic:O});function bc(e,t){let n=N.dirname(N.resolve(e));return N.relative(n,N.resolve(t)).split(N.sep).join("/")}a(bc,"toProjectRelative");var lt=vr({findConfigPath:D,loadArkConfig:B,lintedFilename:x,sourceIsInAnalysisScope:X,isLocallyBound:z,reportAdapterDiagnostic:O,toProjectRelative:bc}),Ns=hs(X),Ec=[Ts,Re.noArkRunKernelInDomain,Re.noArkRunDirectNew,Re.noArkRunTransportBypass,lt.noArkOrderKernelInDomain,lt.noArkOrderGenericUpdate,Ns],Ic={meta:{type:"problem",docs:{description:"Report non-blocking Ark findings (type-only placement debt, advisory slice walls, advisory arkRun / arkOrder / ArkRules) as warnings \u2014 the same findings ark-check reports as warnings."},messages:{[Et]:qn},schema:[]},create(e){return $t(x(e))?{}:Qn(Ec.map(t=>ze(t,e,"advisory")))}},vc=F(Ts),wc=F(ks),xc=F(bs),Cc=F(ys),_c=F(kc),Oc=F(Re.noArkRunKernelInDomain),Tc=F(Re.noArkRunDirectNew),Nc=F(Re.noArkRunTransportBypass),Lc=F(lt.noArkOrderKernelInDomain),Dc=F(lt.noArkOrderGenericUpdate),Fc=F(Ns),Pc=Ic,$c={"no-domain-infra-imports":vc,"no-raw-event-publish":wc,"require-publish-source":xc,"no-forbidden-globals":Cc,"no-denied-capabilities":_c,"no-arkrun-kernel-in-domain":Oc,"no-arkrun-direct-new":Tc,"no-arkrun-transport-bypass":Nc,"no-arkorder-kernel-in-domain":Lc,"no-arkorder-generic-update":Dc,"arkrules-structure":Fc,"architecture-advisory":Pc},Mc={"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","ark/arkrules-structure":"error","ark/architecture-advisory":"warn"},jt={meta:{name:"arkgate",version:Ac},rules:$c};function Kc(){let e=gs();return{plugins:{ark:jt},rules:{...Mc},...e?{settings:{ark:{contractHash:e}}}:{}}}a(Kc,"recommendedConfig");var Ls={};Object.defineProperty(Ls,"recommended",{enumerable:!0,configurable:!0,get:Kc});jt.configs=Ls;var Mf=jt;export{Pc as architectureAdvisory,Fc as arkRulesStructureRule,Ls as configs,gs as contractFingerprint,Mf as default,D as findConfigPath,L as globToRegExp,bo as isEdgeDenied,w as layerForRelativePath,ec as loadArkConfig,Dc as noArkOrderGenericUpdate,Lc as noArkOrderKernelInDomain,Tc as noArkRunDirectNew,Oc as noArkRunKernelInDomain,Nc as noArkRunTransportBypass,_c as noDeniedCapabilities,vc as noDomainInfraImports,Cc as noForbiddenGlobals,wc as noRawEventPublish,en as patternSpecificity,jt as plugin,Cs as readTsconfigPathAliases,xc as requirePublishSource,Ut as resolveImportSpecifier,Os as resolveRelativeImport,$c as rules};
11
+ `;)n+=1;continue}if(e[n]==="/"&&e[n+1]==="*"){let s=e.indexOf("*/",n+2);n=s<0?r:s+2;continue}return n}}a(Es,"skipTrivia");function uc(e){let t=e.replace(/^/,""),n="",r=0,s=t.length;for(;r<s;){let o=t[r];if(o==='"'){let i=r+1;for(;i<s&&t[i]!=='"';)i+=t[i]==="\\"?2:1;n+=t.slice(r,i+1),r=i+1;continue}if(o==="/"&&(t[r+1]==="/"||t[r+1]==="*")){n+=" ",r=Es(t,r);continue}if(o===","){let i=Es(t,r+1);if(t[i]==="}"||t[i]==="]"){r+=1;continue}}n+=o,r+=1}return n}a(uc,"stripJsonc");function Is(e){return JSON.parse(uc(e))}a(Is,"parseJsonc");var vs=new Map,Ae=new Map,fc=64;function Mt(e){try{let t=at.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"missing"}}a(Mt,"fileStamp");function J(e){try{return at.statSync(e).isFile()}catch{return!1}}a(J,"isFile");function ws(e){let t=E.resolve(e),n=vs.get(t);if(n!==void 0&&(n===null||J(n)))return n;let r=E.join(t,"tsconfig.json"),s;if(J(r))s=r;else{let o=E.dirname(t);s=o===t?null:ws(o)}return vs.set(t,s),s}a(ws,"findNearestTsconfig");function pc(e,t){let n=e;for(;;){let r=E.join(n,"node_modules",t);for(let i of[r,`${r}.json`])if(J(i))return i;let s=E.join(r,"package.json");if(J(s))try{let i=JSON.parse(at.readFileSync(s,"utf8"));if(typeof i.tsconfig=="string"&&J(E.join(r,i.tsconfig)))return E.join(r,i.tsconfig)}catch{}if(J(E.join(r,"tsconfig.json")))return E.join(r,"tsconfig.json");let o=E.dirname(n);if(o===n)return null;n=o}}a(pc,"resolvePackageExtends");function gc(e,t){let n=E.dirname(e);if(t.startsWith(".")||E.isAbsolute(t)){let r=E.resolve(n,t);for(let s of[r,`${r}.json`])if(J(s))return s;return null}return pc(n,t)}a(gc,"resolveExtends");function Kt(e,t){return e.split("${configDir}").join(t)}a(Kt,"substituteConfigDir");function xs(e,t,n,r,s){if(n>8||r.has(e))return{};r.add(e),s.push({file:e,stamp:Mt(e)});let o;try{o=Is(at.readFileSync(e,"utf8"))??{}}catch{return{}}let i={},l=o.extends,c=typeof l=="string"?[l]:Array.isArray(l)?l:[];for(let f of c){if(typeof f!="string")continue;let p=Kt(f,t),g=gc(e,p);if(!g){if(p.startsWith(".")||E.isAbsolute(p)){let R=E.resolve(E.dirname(e),p);for(let k of[R,`${R}.json`])s.push({file:k,stamp:Mt(k)})}continue}let m=xs(g,t,n+1,r,s);m.baseUrl!==void 0&&(i.baseUrl=m.baseUrl),m.paths!==void 0&&(i.paths=m.paths,i.pathsBase=m.pathsBase)}let d=o.compilerOptions??{},u=E.dirname(e);return typeof d.baseUrl=="string"&&(i.baseUrl=E.resolve(u,Kt(d.baseUrl,t))),d.paths&&typeof d.paths=="object"&&(i.paths=d.paths,i.pathsBase=u),i}a(xs,"loadChain");function hc(e,t){let n=e.baseUrl??e.pathsBase??t,r=[];for(let[s,o]of Object.entries(e.paths??{})){if(!Array.isArray(o)||o.length===0)continue;let i=o.filter(f=>typeof f=="string").map(f=>Kt(f,t));if(i.length===0)continue;let l=s.indexOf("*"),c=l>=0,d=c?s.slice(0,l):s,u=c?s.slice(l+1):"";c&&!d&&!u||r.push({from:d,to:i[0].replace(/\*$/,""),suffix:u,wildcard:c,targets:i})}return r.sort((s,o)=>Number(s.wildcard)-Number(o.wildcard)||o.from.length-s.from.length),{baseUrl:n,aliases:r}}a(hc,"buildAliasSet");function mc(e){let t=Ae.get(e);if(t&&t.chain.every(i=>Mt(i.file)===i.stamp))return t.result;let n=[],r=E.dirname(e),s=xs(e,r,0,new Set,n),o=hc(s,r);if(!Ae.has(e)&&Ae.size>=fc){let i=Ae.keys().next().value;i!==void 0&&Ae.delete(i)}return Ae.set(e,{chain:n,result:o}),o}a(mc,"aliasesForTsconfig");function Cs(e){let t=ws(e);return t?mc(t):{baseUrl:E.resolve(e),aliases:[]}}a(Cs,"readTsconfigPathAliases");function _s(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,E.join(e,"index.ts"),E.join(e,"index.tsx"),E.join(e,"index.js")];for(let n of t)if(J(n))return n;return null}a(_s,"existingSourceFile");function Os(e,t){if(!t.startsWith("."))return null;let n=E.resolve(E.dirname(e),t);return _s(n)}a(Os,"resolveRelativeImport");function yc(e,t){return e.wildcard?!t.startsWith(e.from)||!t.endsWith(e.suffix)||t.length<e.from.length+e.suffix.length?null:t.slice(e.from.length,t.length-e.suffix.length):t===e.from?"":null}a(yc,"matchAlias");function Ut(e,t,n){if(!t)return null;if(t.startsWith("."))return Os(e,t);let r=e?E.dirname(E.resolve(e)):n??".",{baseUrl:s,aliases:o}=Cs(r);for(let i of o){let l=yc(i,t);if(l!==null){for(let c of i.targets){let d=i.wildcard?c.split("*").join(l):c,u=_s(E.resolve(s,d));if(u)return u}return null}}return null}a(Ut,"resolveImportSpecifier");var Ac="4.8.26";function Rc(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}a(Rc,"containingProgram");function Sc(e){let t=Rc(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!Ze(r))return!1;continue}if(!(r.type==="TSInterfaceDeclaration"||r.type==="TSTypeAliasDeclaration")){if(r.type==="ExportNamedDeclaration"){if(r.declaration){if(r.declaration.type!=="TSInterfaceDeclaration"&&r.declaration.type!=="TSTypeAliasDeclaration")return!1}else if(!Ze(r))return!1;n=!0;continue}return!1}}return n}a(Sc,"sourceProgramExportsOnlyTypes");var Ts={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{message}} Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let t=x(e),n=D(t),r=B(n),s=n?N.dirname(n):null,o=a(i=>{let l=Ye(i.source);if(l&&r&&s&&t){let c=N.isAbsolute(t)?t:N.resolve(t),d=N.relative(s,c).split(N.sep).join("/");if(!X(r,d))return;let u=w(d,r.layers);if(!u)return;let f=Ut(c,l,s);if(!f)return;let p=N.relative(s,f).split(N.sep).join("/");if(p.startsWith(".."))return;let g=w(p,r.layers);if(!g)return;let m={fromPath:d,toPath:p,layers:r.layers},R=ct(r.rules,u,g,m),k=R?.rule;if(k){let y=i.type?.startsWith("Export")?"export":"import",A=Ze(i),S=!!k?.peerIsolation,I=A&&!S,_=R?.sliceVerdict,Se=_?dn({surface:"import",verdict:_,fromLayer:u,toLayer:g,kind:y,fromPath:d,toPath:p,ruleMessage:k?.message,childMessage:k?.childSlices?.message}):k?.message??`${u} must not ${y} ${g}.`,se=I?`${Se} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:Se;O(e,i,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:d,fromLayer:u,toLayer:g,target:p,edgeKind:y,...S?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...un(_),...I?{failsStrict:!1,severity:"warning"}:{},...Sc(i)?{sourcePureTypeModule:!0}:{},message:se},{fromLayer:u,toLayer:g,specifier:l,message:se})}return}},"check");return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},kc={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=x(e),n=D(t),r=B(n),s=n?N.dirname(n):null;if(!r||!s||!t)return{};let o=st(r,s,t);if(!o?.layer)return{};let{relFile:i,layer:l}=o,c=new Set(gn(l));return c.size===0?{}:de(e,a((u,f,p,g)=>{if(p||typeof f!="string"||Me(f,l.forbiddenGlobals??[]))return;let m=pn(f);!m||!c.has(m)||O(e,u,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:i,fromLayer:l.name,target:f,capability:m,edgeKind:g,message:`${l.name} denies the ${m} capability; found import of "${f}".`},{layer:l.name,capability:m,specifier:f})},"check"))}},Re=ir({findConfigPath:D,loadArkConfig:B,resolveImportSpecifier:Ut,lintedFilename:x,sourceIsInAnalysisScope:X,isLocallyBound:z,reportAdapterDiagnostic:O});function bc(e,t){let n=N.dirname(N.resolve(e));return N.relative(n,N.resolve(t)).split(N.sep).join("/")}a(bc,"toProjectRelative");var lt=vr({findConfigPath:D,loadArkConfig:B,lintedFilename:x,sourceIsInAnalysisScope:X,isLocallyBound:z,reportAdapterDiagnostic:O,toProjectRelative:bc}),Ns=hs(X),Ec=[Ts,Re.noArkRunKernelInDomain,Re.noArkRunDirectNew,Re.noArkRunTransportBypass,lt.noArkOrderKernelInDomain,lt.noArkOrderGenericUpdate,Ns],Ic={meta:{type:"problem",docs:{description:"Report non-blocking Ark findings (type-only placement debt, advisory slice walls, advisory arkRun / arkOrder / ArkRules) as warnings \u2014 the same findings ark-check reports as warnings."},messages:{[Et]:qn},schema:[]},create(e){return $t(x(e))?{}:Qn(Ec.map(t=>ze(t,e,"advisory")))}},vc=F(Ts),wc=F(ks),xc=F(bs),Cc=F(ys),_c=F(kc),Oc=F(Re.noArkRunKernelInDomain),Tc=F(Re.noArkRunDirectNew),Nc=F(Re.noArkRunTransportBypass),Lc=F(lt.noArkOrderKernelInDomain),Dc=F(lt.noArkOrderGenericUpdate),Fc=F(Ns),Pc=Ic,$c={"no-domain-infra-imports":vc,"no-raw-event-publish":wc,"require-publish-source":xc,"no-forbidden-globals":Cc,"no-denied-capabilities":_c,"no-arkrun-kernel-in-domain":Oc,"no-arkrun-direct-new":Tc,"no-arkrun-transport-bypass":Nc,"no-arkorder-kernel-in-domain":Lc,"no-arkorder-generic-update":Dc,"arkrules-structure":Fc,"architecture-advisory":Pc},Mc={"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","ark/arkrules-structure":"error","ark/architecture-advisory":"warn"},jt={meta:{name:"arkgate",version:Ac},rules:$c};function Kc(){let e=gs();return{plugins:{ark:jt},rules:{...Mc},...e?{settings:{ark:{contractHash:e}}}:{}}}a(Kc,"recommendedConfig");var Ls={};Object.defineProperty(Ls,"recommended",{enumerable:!0,configurable:!0,get:Kc});jt.configs=Ls;var Mf=jt;export{Pc as architectureAdvisory,Fc as arkRulesStructureRule,Ls as configs,gs as contractFingerprint,Mf as default,D as findConfigPath,L as globToRegExp,bo as isEdgeDenied,w as layerForRelativePath,ec as loadArkConfig,Dc as noArkOrderGenericUpdate,Lc as noArkOrderKernelInDomain,Tc as noArkRunDirectNew,Oc as noArkRunKernelInDomain,Nc as noArkRunTransportBypass,_c as noDeniedCapabilities,vc as noDomainInfraImports,Cc as noForbiddenGlobals,wc as noRawEventPublish,en as patternSpecificity,jt as plugin,Cs as readTsconfigPathAliases,xc as requirePublishSource,Ut as resolveImportSpecifier,Os as resolveRelativeImport,$c as rules};