arkgate 4.6.3 → 4.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +64 -5
  2. package/README.md +7 -5
  3. package/bin/ark-check-runtime.mjs +98 -14
  4. package/bin/ark-mcp-runtime.mjs +54 -33
  5. package/bin/ark.mjs +1 -0
  6. package/bin/lib/adapter-contract.mjs +13 -9
  7. package/bin/lib/agent-projection-command.mjs +18 -0
  8. package/bin/lib/agent-projection.mjs +2 -2
  9. package/bin/lib/analysis-engine.mjs +5 -5
  10. package/bin/lib/ci-and-commands.mjs +3 -3
  11. package/bin/lib/ci-merge-boundary.mjs +89 -0
  12. package/bin/lib/config-contract.mjs +2 -0
  13. package/bin/lib/diagnostic-catalog.mjs +5 -4
  14. package/bin/lib/doctor-next-actions.mjs +17 -5
  15. package/bin/lib/doctor-plan.mjs +14 -0
  16. package/bin/lib/enforcement-honesty.mjs +2 -0
  17. package/bin/lib/graph-blind.mjs +15 -6
  18. package/bin/lib/install-migrate.mjs +10 -0
  19. package/bin/lib/invariant-coverage.mjs +6 -2
  20. package/bin/lib/managed-upgrade.mjs +9 -4
  21. package/bin/lib/presets.mjs +22 -0
  22. package/bin/lib/remediation.mjs +74 -10
  23. package/bin/lib/skill-install.mjs +2 -0
  24. package/bin/lib/snippet-analysis.mjs +40 -8
  25. package/bin/lib/upgrade-command.mjs +37 -4
  26. package/bin/lib/upgrade-whats-new.mjs +19 -1
  27. package/dist/{configTypes-B8uIcLaG.d.ts → configTypes-l6XiwiC1.d.ts} +7 -0
  28. package/dist/eslint/index.cjs +3 -3
  29. package/dist/eslint/index.d.ts +1 -1
  30. package/dist/eslint/index.js +3 -3
  31. package/dist/index.cjs +26 -26
  32. package/dist/index.d.ts +11 -2
  33. package/dist/index.js +29 -29
  34. package/docs/README.md +5 -4
  35. package/docs/agent-guide.md +12 -1
  36. package/docs/ai-gates.md +5 -0
  37. package/docs/brownfield-adoption.md +7 -1
  38. package/docs/configuration.md +2 -1
  39. package/docs/develop.md +5 -2
  40. package/docs/diagnostics.md +15 -5
  41. package/docs/package-surface.md +6 -5
  42. package/docs/threat-model.md +1 -1
  43. package/package.json +1 -1
  44. package/schemas/ark.config.schema.json +6 -0
  45. package/server.json +2 -2
  46. package/templates/agent-skills/README.md +1 -1
  47. package/templates/agent-skills/ark-adopt/SKILL.md +7 -0
  48. package/templates/agent-skills/ark-explore/SKILL.md +6 -0
  49. package/templates/agent-skills/ark-place/SKILL.md +11 -4
  50. package/templates/agent-skills/ark-upgrade/SKILL.md +22 -4
  51. package/templates/skills/ark-adopt.md +7 -0
  52. package/templates/skills/ark-explore.md +6 -0
  53. package/templates/skills/ark-place.md +11 -4
  54. package/templates/skills/ark-upgrade.md +22 -4
@@ -148,8 +148,9 @@ function staleCliRefuseMessage(detail) {
148
148
  * project's installed arkgate. Legacy global 2.x mutates skills; a newer
149
149
  * project pin must not be managed by an older outside-tree binary.
150
150
  *
151
- * Allow: no local install; CLI package root inside the project install tree
152
- * (realpath); running CLI version >= project installed version (including newer globals).
151
+ * Allow directly: no local install or CLI package root inside the project install tree
152
+ * (realpath). Any outside-tree modern CLI prefers a project-local handoff, even at the same
153
+ * or newer version, so one checkout never manages another through PATH state.
153
154
  *
154
155
  * @param {string} root project root for --root
155
156
  * @param {{
@@ -157,7 +158,7 @@ function staleCliRefuseMessage(detail) {
157
158
  * cliPackageRoot?: string|null,
158
159
  * projectPackageJsonPath?: string|null,
159
160
  * }} [options]
160
- * @returns {{ refuse: boolean, reason: string, message?: string, cliVersion?: string|null, projectVersion?: string|null, cliPackageRoot?: string|null, projectPackageRoot?: string|null }}
161
+ * @returns {{ refuse: boolean, handoff?: boolean, reason: string, message?: string, cliVersion?: string|null, projectVersion?: string|null, cliPackageRoot?: string|null, projectPackageRoot?: string|null }}
161
162
  */
162
163
  export function evaluateStaleUpgradeCli(root, options = {}) {
163
164
  const projectPkgPath =
@@ -272,7 +273,8 @@ export function evaluateStaleUpgradeCli(root, options = {}) {
272
273
 
273
274
  return {
274
275
  refuse: false,
275
- reason: 'outside-cli-ok',
276
+ handoff: true,
277
+ reason: 'outside-cli-project-local-preferred',
276
278
  cliVersion,
277
279
  projectVersion,
278
280
  cliPackageRoot,
@@ -325,6 +327,15 @@ function verify(root, json, arkCheck, runArkCheck) {
325
327
  return { exitCode: result.status ?? 1, stderr: result.stderr?.trim() || undefined };
326
328
  }
327
329
 
330
+ function runProjectLocalCli({ root, script, argv }) {
331
+ const result = spawnSync(process.execPath, [script, ...argv], {
332
+ cwd: root,
333
+ stdio: 'inherit',
334
+ env: { ...process.env, ARK_PROJECT_LOCAL_HANDOFF: '1' },
335
+ });
336
+ return result.status ?? 1;
337
+ }
338
+
328
339
  export function runUpgradeCommand(args, dependencies) {
329
340
  const root = args.root;
330
341
  // Fail closed before install/plan when PATH resolves a global/stale CLI older
@@ -339,6 +350,28 @@ export function runUpgradeCommand(args, dependencies) {
339
350
  cliVersion: dependencies?.cliVersion,
340
351
  cliPackageRoot: dependencies?.cliPackageRoot,
341
352
  });
353
+ if (staleGuard?.refuse || staleGuard?.handoff) {
354
+ const projectLocalScript =
355
+ typeof staleGuard.projectPackageRoot === 'string'
356
+ ? path.join(staleGuard.projectPackageRoot, 'bin', 'ark.mjs')
357
+ : null;
358
+ if (
359
+ process.env.ARK_PROJECT_LOCAL_HANDOFF !== '1' &&
360
+ Array.isArray(dependencies?.rawArgv) &&
361
+ projectLocalScript &&
362
+ fs.existsSync(projectLocalScript)
363
+ ) {
364
+ const handoff =
365
+ typeof dependencies.runProjectLocalCli === 'function'
366
+ ? dependencies.runProjectLocalCli
367
+ : runProjectLocalCli;
368
+ return handoff({
369
+ root,
370
+ script: projectLocalScript,
371
+ argv: dependencies.rawArgv,
372
+ });
373
+ }
374
+ }
342
375
  if (staleGuard?.refuse) {
343
376
  const message = staleGuard.message || 'Refusing ark upgrade: stale CLI.';
344
377
  if (args.json) {
@@ -65,6 +65,15 @@ export function buildUpgradeWhatsNewSuggestions() {
65
65
  why:
66
66
  'Project skills follow this pin. Shared homes stay on the newest ArkGate on the machine (additive; never downgrade). Orphan 2.x global skills stop coaching the wrong version.',
67
67
  },
68
+ {
69
+ id: 'codex-hard-write',
70
+ title: 'Codex complete local apply_patch block',
71
+ try: 'npx arkgate-check --install-agent-gates --tools codex --force',
72
+ inspect:
73
+ '.codex/hooks.json trust + doctor.writePath after a runtime-observed apply_patch',
74
+ why:
75
+ 'After upgrade, refresh the project hook, restart Codex or local Desktop, and trust the exact hook definition. Only a complete observed apply_patch is hard; hosted, specialized, shell/direct, incomplete, and human paths still rely on required CI.',
76
+ },
68
77
  {
69
78
  id: 'deep-module-coach',
70
79
  title: 'Deep-module coach (hot paths + deepening)',
@@ -129,7 +138,16 @@ export function buildUpgradeWhatsNewSuggestions() {
129
138
  try: 'ark_identity with project.expectedRoot; read processPackage on every tool',
130
139
  inspect: 'processPackage.processPackageMismatch / processStale + nextAction',
131
140
  why:
132
- 'One user, many checkouts: after package bump, restart MCP so process arkgateVersion matches install. Prefer project-local CLI until identity matched and versions align.',
141
+ 'One user, many checkouts: after package bump, restart MCP so process arkgateVersion matches install. A stale process is non-authoritative and project tools fail closed until restart.',
142
+ },
143
+ {
144
+ id: 'process-version-recovery',
145
+ title: 'Stale MCP / global CLI recovery',
146
+ try: 'npx arkgate upgrade --json',
147
+ inspect:
148
+ 'processPackage.processStale + PROCESS_PACKAGE_STALE; project-local CLI handoff for stale global upgrade',
149
+ why:
150
+ 'A long-lived MCP on an older package can no longer return authoritative project evidence. A newer global ArkGate that is older than this project automatically hands `ark upgrade` to the project-local CLI instead of staying stuck on PATH.',
133
151
  },
134
152
  ],
135
153
  };
@@ -24,6 +24,13 @@ type ArkConfigLayer = {
24
24
  pure?: boolean;
25
25
  mayImportInfrastructure?: boolean;
26
26
  optional?: boolean;
27
+ /**
28
+ * Future house: empty globs are expected. `--strict-config` must not fail.
29
+ * Typo warning (`CONFIG_LAYER_PATTERN_NO_MATCHES`) is skipped.
30
+ */
31
+ reserved?: boolean;
32
+ /** Alias of reserved — empty pattern matches are allowed. */
33
+ allowEmpty?: boolean;
27
34
  };
28
35
  type ArkConfigRule = {
29
36
  from: string;
@@ -1,3 +1,3 @@
1
- "use strict";var Oe=Object.create;var N=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Te=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})},Q=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pe(t))!ve.call(e,s)&&s!==n&&N(e,s,{get:()=>t[s],enumerable:!(r=_e(t,s))||r.enumerable});return e};var ee=(e,t,n)=>(n=e!=null?Oe($e(e)):{},Q(t||!e||!e.__esModule?N(n,"default",{value:e,enumerable:!0}):n,e)),je=e=>Q(N({},"__esModule",{value:!0}),e);var ut={};Te(ut,{default:()=>pt,findConfigPath:()=>T,globToRegExp:()=>E,isEdgeDenied:()=>F,layerForRelativePath:()=>R,loadArkConfig:()=>j,noDeniedCapabilities:()=>Ne,noDomainInfraImports:()=>we,noForbiddenGlobals:()=>Le,noRawEventPublish:()=>Ee,patternSpecificity:()=>M,plugin:()=>v,readTsconfigPathAliases:()=>be,requirePublishSource:()=>Ce,resolveImportSpecifier:()=>Se,resolveRelativeImport:()=>Ae});module.exports=je(ut);var I=ee(require("fs"),1),p=ee(require("path"),1);var te=new Map;function ne(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}function O(e){let t="";for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if("*?{}[],".includes(s)||s==="\\"){t+="\\"+s,n+=1;continue}t+="/";continue}t+=r}return t}function De(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"){n+=1;continue}if(r==="{")t+=1;else if(r==="}"&&(t-=1,t<0))return!1}return t===0}function E(e){let t=te.get(e);if(t)return t;let n=O(e),r=De(n),s="",i=0;for(let c=0;c<n.length;c+=1){let g=n[c];g==="\\"&&c+1<n.length?(s+=ne(n[c+1]),c+=1):g==="*"?n[c+1]==="*"?n[c+2]==="/"?(s+="(?:.*/)?",c+=2):(s+=".*",c+=1):s+="[^/]*":g==="?"?s+="[^/]":g==="{"&&r?(s+="(?:",i+=1):g==="}"&&r&&i>0?(s+=")",i-=1):g===","&&r&&i>0?s+="|":s+=ne(g)}let a=new RegExp(`^${s}$`);return te.set(e,a),a}function Me(e){return O(String(e)).split("/").filter(Boolean).filter(n=>n!=="**"&&n!=="*"&&!n.includes("*")&&!n.includes("?")&&!n.includes("{")&&!n.includes("["))}function M(e,t){let n=O(String(e)),r=Me(n),s=n.replace(/\*/g,"").length,i=r.length*1e4+s;if(t==null||t==="")return i;let a=String(t).split(/[/\\]/).filter(Boolean);if(r.length===0)return s;let c=0,g=-1;for(let f of r){let d=-1;for(let o=c;o<a.length;o+=1)if(a[o]===f){d=o;break}if(d<0)return i;g=d,c=d+1}return(g+1)*1e6+r.length*1e4+s}function R(e,t){let n=String(e).split(/[/\\]/).join("/"),r,s=-1;for(let i of t??[])if(!(i.exclude??[]).some(a=>E(a).test(n))){for(let a of i.patterns??[])if(E(a).test(n)){let c=M(a,n);c>s&&(s=c,r=i.name)}}return r}function re(e,t){if(!t?.length)return;let n=String(e).split(/[/\\]/).filter(Boolean),r=new Set(t.map(s=>String(s).toLowerCase()));for(let s=0;s<n.length-1;s+=1)if(r.has(n[s].toLowerCase()))return`${n[s].toLowerCase()}/${n[s+1].toLowerCase()}`}function Ve(e){let t=new Set;for(let n of e??[]){let s=O(String(n)).split("/").filter(Boolean);for(let i=0;i<s.length;i+=1){let a=s[i];if((a==="**"||a==="*")&&i>0){let c=s[i-1];c&&!c.includes("*")&&!c.includes("{")&&!c.includes("}")&&t.add(c)}}}return[...t]}function Fe(e,t,n){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(s=>typeof s=="string"&&s.length>0);let r=(n??[]).find(s=>s.name===t);return Ve(r?.patterns)}function Ke(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}function V(e,t,n,r){for(let s of e??[])if(!(s.from!==t||s.to!==n)&&s.allowed===!1){if(s.peerIsolation){let i=r?.fromPath,a=r?.toPath,c=Fe(s,t,r?.layers),g=i&&a?re(i,c):void 0,f=i&&a?re(a,c):void 0;if(Ke({fromPath:i,toPath:a,folderCount:c.length,fromSlice:g,toSlice:f}))return s;continue}if(t!==n)return s}}function F(e,t,n,r){return V(e,t,n,r)!==void 0}var He=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function Ge(e){let t=Array.isArray(e?.exclude)?e.exclude.filter(r=>typeof r=="string"):[];return[...e?.excludeGenerated===!1?[]:He,...t]}function se(e,t){let n=String(e).split(/[/\\]/).join("/");return Ge(t).some(r=>E(r).test(n))}var oe=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),Be=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),mt=Object.freeze(Object.keys(Be).sort()),K=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"}),Ue=Object.freeze({process:Object.freeze(["process","node:process"])});function ie(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let t=K[e];if(t)return t;let n=e.indexOf("/");if(n<0)return null;let r=e.slice(0,n),s=K[r];if(s)return s;let i=e.indexOf("/",n+1);return i<0?null:K[e.slice(0,i)]??null}function H(e,t){for(let n of t)if(Ue[n]?.includes(e))return n;return null}function ae(e){if(e?.pure===!0)return[...oe].sort();let n=(e?.capabilities?.deny??[]).filter(r=>oe.includes(r));return[...new Set(n)].sort()}var G="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",le=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],qe=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function We(){let e=[];for(let t of le)for(let n of le)t===n||qe.has(`${t}->${n}`)||e.push({from:t,to:n,allowed:!1});return e}var de=We(),B=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"}],S={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},ce={$schema:"https://json-schema.org/draft/2020-12/schema",$id:G,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:G,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:"1.1",default:"1.1"},name:{type:"string",minLength:1},include:{...S,minItems:1,default:["src"]},exclude:{...S,default:[]},excludeGenerated:{type:"boolean",default:!0},frameworkOverlay:{type:"string",minLength:1},layers:{type:"array",default:[],items:{$ref:"#/$defs/layer"}},rules:{type:"array",default:de,items:{$ref:"#/$defs/rule"}},cyclePolicy:{type:"string",enum:["strict","soft","framework-soft","off"],default:"strict"},dynamicImportAllowlist:{...S,default:[]},safety:{$ref:"#/$defs/safety",default:{maxTsSuppressions:0,maxAnyCasts:0,allowInMemory:!1,allowDisabledPeerIsolation:!1}},arkRules:{type:"object",additionalProperties:{type:"string",minLength:1},default:{}},stewards:{...S,default:[]}},$defs:{layer:{type:"object",additionalProperties:!1,required:["name","patterns"],properties:{name:{type:"string",minLength:1},patterns:{...S,minItems:1},exclude:S,intentPrefixes:S,description:{type:"string",minLength:1},forbiddenGlobals:S,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"}}},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:{...S,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}}}}},k=class extends Error{issues;source;constructor(t,n){super(`Invalid ArkGate config (${t}):
2
- ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
3
- `)}`),this.name="ArkConfigValidationError",this.source=t,this.issues=n}};function pe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function _(e,t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}function x(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Ye(e,t){let n="#/$defs/";if(e.startsWith(n))return t.$defs[e.slice(n.length)]}function C(e,t,n,r,s){if(t.$ref){let i=Ye(t.$ref,r);if(!i){s.push({path:n,message:`schema reference ${t.$ref} cannot be resolved`});return}C(e,i,n,r,s);return}if(t.const!==void 0&&!Object.is(e,t.const)){s.push({path:n,message:`must equal ${JSON.stringify(t.const)}`});return}if(t.enum&&!t.enum.some(i=>Object.is(i,e))){s.push({path:n,message:`must be one of ${t.enum.map(String).join(", ")}`});return}if(t.type==="object"){if(!pe(e)){s.push({path:n,message:`must be an object; received ${x(e)}`});return}let i=t.properties??{};for(let a of t.required??[])e[a]===void 0&&s.push({path:_(n,a),message:"is required"});if(t.additionalProperties===!1)for(let a of Object.keys(e))a in i||s.push({path:_(n,a),message:"unknown field"});else if(t.additionalProperties!==void 0&&t.additionalProperties!==!0&&typeof t.additionalProperties=="object"){let a=t.additionalProperties;for(let c of Object.keys(e))c in i||C(e[c],a,_(n,c),r,s)}for(let[a,c]of Object.entries(i))e[a]!==void 0&&C(e[a],c,_(n,a),r,s);return}if(t.type==="array"){if(!Array.isArray(e)){s.push({path:n,message:`must be an array; received ${x(e)}`});return}if(t.minItems!==void 0&&e.length<t.minItems&&s.push({path:n,message:`must contain at least ${t.minItems} item(s)`}),t.uniqueItems){let i=e.map(a=>JSON.stringify(a));new Set(i).size!==i.length&&s.push({path:n,message:"must not contain duplicate items"})}t.items&&e.forEach((i,a)=>C(i,t.items,`${n}[${a}]`,r,s));return}if(t.type==="string"){if(typeof e!="string"){s.push({path:n,message:`must be a string; received ${x(e)}`});return}t.minLength!==void 0&&e.length<t.minLength&&s.push({path:n,message:`must contain at least ${t.minLength} character(s)`});return}if(t.type==="boolean"){typeof e!="boolean"&&s.push({path:n,message:`must be a boolean; received ${x(e)}`});return}if(t.type==="integer"){if(!Number.isInteger(e)){s.push({path:n,message:`must be an integer; received ${x(e)}`});return}t.minimum!==void 0&&e<t.minimum&&s.push({path:n,message:`must be at least ${t.minimum}`})}}function Je(e){return{...e,$schema:e.$schema===void 0?G:e.$schema,schemaVersion:e.schemaVersion===void 0?"1.1":e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?de.map(t=>({...t})):e.rules}}function ze(){let e=new Set(["1.1"]);for(let t of B)t.from!=="unversioned"&&e.add(t.from),e.add(t.to);return e}function Ze(e,t="ark.config.json"){if(!pe(e))throw new k(t,[{path:"$",message:`must be an object; received ${x(e)}`}]);let n=ze(),r=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(r===null)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected 1.1`}]);if(r!=="unversioned"&&!n.has(r))throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(r)}; expected 1.1`}]);let s=r,i={...e},a=0;for(;s!=="1.1"&&a<B.length+1;){a+=1;let g=B.find(f=>f.from===s);if(!g)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(s)}; expected 1.1`}]);s=g.to,i.schemaVersion=s}if(s!=="1.1")throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(r)}; expected 1.1`}]);let c=r==="unversioned"?"unversioned":r==="1.0"?"1.0":null;return{candidate:Je(i),migratedFrom:c}}function Xe(e,t="ark.config.json"){let{candidate:n,migratedFrom:r}=Ze(e,t),s=[];if(C(n,ce,"$",ce,s),s.length>0)throw new k(t,s);return{config:n,migratedFrom:r}}function ue(e,t="ark.config.json"){let n;try{n=JSON.parse(e)}catch(r){throw new k(t,[{path:"$",message:`invalid JSON: ${r instanceof Error?r.message:String(r)}`}])}return Xe(n,t)}var Qe="docs/diagnostics.md";function h(e){return typeof e=="string"&&e.length>0?e:void 0}function fe(e,t){return Number.isInteger(e)&&Number(e)>0?Number(e):t}function et(e){let t=typeof e.ruleId=="string"?e.ruleId:typeof e.code=="string"?e.code:void 0,n=typeof e.file=="string"?e.file:void 0,r=typeof e.fromLayer=="string"?e.fromLayer:void 0,s=typeof e.toLayer=="string"?e.toLayer:void 0,i=typeof e.target=="string"?e.target:void 0;return[t,n,r??"",s??"",i??""].join("|")}function tt(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return`fnv1a-${(t>>>0).toString(16).padStart(8,"0")}`}function nt(e){return`${Qe}#${e}`}function rt(e,t,n){if(e==="LAYER_IMPORT_VIOLATION")return t.typeOnly||n.targetTypeOnlyExports===!0||n.namedBindingsTypeOnly===!0?"Move the referenced type to a mutually allowed layer, use `import type`, then preflight again.":n.peerIsolation===!0?"Extract the shared dependency to a shared layer, test at the public interface, then preflight again.":`Define a port in ${t.fromLayer??"the source layer"}, inject the ${t.toLayer??"outer-layer"} implementation, test at the public interface, then preflight again.`;if(e==="FORBIDDEN_GLOBAL")return`Inject ${t.target??"the capability"} through a port, test at the public interface, then preflight again.`;if(e==="CAPABILITY_VIOLATION")return`Define a ${h(n.capability)??"capability"} port in ${t.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;if(e==="CIRCULAR_DEPENDENCY")return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";if(e==="RAW_EVENT_PUBLISH")return"Publish through a registered intent creator, then run Ark again.";if(e==="PUBLISH_MISSING_SOURCE")return"Add metadata.source to the publish call, then run Ark again.";if(e==="ARKRULE_STRUCTURE"||e==="ARKRULE_INVARIANT"||e==="INVARIANT_UNCOVERED"||e.startsWith("ARKRULE_")){let r=t.arkruleSource??"arkrules/<Layer>.json";return`Fix the structure or invariant for ${t.arkruleId??"the ArkRule"} (declared in ${r}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`}return`Resolve ${e} without weakening ark.config.json, then run Ark again.`}function ge(e,t="error",n){let r=h(e.ruleId)??h(e.code)??"ARK_UNKNOWN",s=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":t,i={...h(e.target)?{target:h(e.target)}:{},...h(e.fromLayer)?{fromLayer:h(e.fromLayer)}:{},...h(e.toLayer)?{toLayer:h(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}:{},...h(e.capability)?{capability:h(e.capability)}:{},...h(e.edgeKind)?{edgeKind:h(e.edgeKind)}:{},...h(e.arkruleId)?{arkruleId:h(e.arkruleId)}:{},...h(e.arkruleSource)?{arkruleSource:h(e.arkruleSource)}:{}},a=n??et(e),c=tt(a);return{ruleId:r,severity:s,message:h(e.message)??r,location:{file:h(e.file)??"<unknown>",line:fe(e.line,1),column:fe(e.column,1)},evidence:i,nextAction:h(e.nextAction)??rt(r,i,e),findingRef:c,targetKey:a,docsCodePath:nt(r)}}var me={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."},At=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 st(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}function U(e){if(!e.publishCall)return[];let t=[];return(e.rawIntentName!==void 0&&st(e.rawIntentName)||e.objectHasIntent)&&t.push({ruleId:"RAW_EVENT_PUBLISH",message:me.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&t.push({ruleId:"PUBLISH_MISSING_SOURCE",message:me.PUBLISH_MISSING_SOURCE}),t}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 t=e.getFilename();if(typeof t=="string"&&t.length>0)return t}catch{}return""}function w(e,t,n,r,s){let i=ge({...r,line:r.line??t.loc?.start?.line,column:r.column??(typeof t.loc?.start?.column=="number"?t.loc.start.column+1:void 0)});return e.report({node:t,messageId:n,...s?{data:s}:{},diagnostic:i}),i}function T(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let t=p.default.dirname(p.default.resolve(e));for(;;){let n=p.default.join(t,"ark.config.json");if(I.default.existsSync(n))return n;let r=p.default.dirname(t);if(r===t)return null;t=r}}var ye=new Map;function j(e){if(!I.default.existsSync(e))return null;let t=I.default.readFileSync(e,"utf8"),n=ye.get(e);if(n?.source===t)return n.config;let r=ue(t,e).config;return ye.set(e,{source:t,config:r}),r}function W(e,t){return(e.include??[]).some(r=>{let s=String(r).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!se(t,e)}function he(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,p.default.join(e,"index.ts"),p.default.join(e,"index.tsx"),p.default.join(e,"index.js")];for(let n of t)try{if(I.default.existsSync(n)&&I.default.statSync(n).isFile())return n}catch{}return null}function be(e){let t=p.default.resolve(e),n=null;for(;;){let f=p.default.join(t,"tsconfig.json");if(I.default.existsSync(f)){n=f;break}let d=p.default.dirname(t);if(d===t)break;t=d}if(!n)return{baseUrl:e,aliases:[]};let r=f=>{try{let d=I.default.readFileSync(f,"utf8");return d=d.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(d)}catch{return null}},s=(f,d)=>{if(d>4)return{};let o=r(f);if(!o)return{};let l=o.compilerOptions??{},u=l.baseUrl,m=l.paths,y=o.extends;if(typeof y=="string"&&!y.startsWith("@")){let b=p.default.resolve(p.default.dirname(f),y.endsWith(".json")?y:`${y}.json`);if(I.default.existsSync(b)){let A=s(b,d+1);u=u??A.baseUrl,m={...A.paths??{},...m??{}}}}return{baseUrl:u,paths:m}},i=s(n,0),a=p.default.dirname(n),c=p.default.resolve(a,i.baseUrl||"."),g=[];for(let[f,d]of Object.entries(i.paths||{})){if(!Array.isArray(d)||d.length===0)continue;let o=f.replace(/\*$/,"");o&&g.push({from:o,to:String(d[0]).replace(/\*$/,"")})}return g.sort((f,d)=>d.from.length-f.from.length),{baseUrl:c,aliases:g}}function Ae(e,t){if(!t.startsWith("."))return null;let n=p.default.resolve(p.default.dirname(e),t);return he(n)}function Se(e,t,n){if(!t)return null;if(t.startsWith("."))return Ae(e,t);let r=n||p.default.dirname(e),{baseUrl:s,aliases:i}=be(r),a=i.find(g=>t.startsWith(g.from));if(!a)return null;let c=p.default.resolve(s,`${a.to}${t.slice(a.from.length)}`);return he(c)}function D(e){return typeof e?.value=="string"?e.value:void 0}function Y(e){return e?.name??D(e)}function J(e){return e.sourceCode??e.getSourceCode?.()}function ke(e,t){let n=J(e)?.getScope?.(t);for(;n;){let r=n.references?.find(s=>s.identifier===t);if(r)return r;n=n.upper??void 0}}function P(e,t,n){let r=ke(e,t);if(r?.resolved)return(r.resolved.defs?.length??0)>0;let s=J(e)?.getScope?.(t);for(;s;){let i=s.set?.get(n);if(i)return(i.defs?.length??0)>0;s=s.upper??void 0}return!1}function ot(e,t){let n=ke(e,t);return n?n.isValueReference!==!1:t.parent?.type==="VariableDeclarator"&&t.parent.init===t}function Ie(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 n=Ie(e.object),r=Y(e.property);if(!(!n||!r))return{root:n.root,segments:[...n.segments,r]}}function it(e){return Y(e.callee?.property)}function Re(e,t){return e?.properties?.find(n=>Y(n.key)===t)}function $(e,t){return Re(e,t)!==void 0}function at(e){let t=Re(e,"metadata")?.value;return $(t,"source")}function xe(e){return it(e)==="publish"}function q(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let t=e.specifiers??[];return t.length===0?!1:t.every(n=>n.type==="ImportSpecifier")?t.every(n=>n.importKind==="type"):t.every(n=>n.exportKind==="type")}function lt(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}function ct(e){let t=lt(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!q(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(!q(r))return!1;n=!0;continue}return!1}}return n}var we={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=L(e),n=T(t),r=n?j(n):null,s=n?p.default.dirname(n):null,i=a=>{let c=D(a.source);if(c&&r&&s&&t){let g=p.default.isAbsolute(t)?t:p.default.resolve(t),f=p.default.relative(s,g).split(p.default.sep).join("/");if(!W(r,f))return;let d=R(f,r.layers);if(!d)return;let o=Se(g,c,s);if(!o)return;let l=p.default.relative(s,o).split(p.default.sep).join("/");if(l.startsWith(".."))return;let u=R(l,r.layers);if(!u)return;let m={fromPath:f,toPath:l,layers:r.layers},y=V(r.rules,d,u,m);if(y||F(r.rules,d,u,m)){let b=a.type?.startsWith("Export")?"export":"import",A=q(a),z=!!y?.peerIsolation,Z=A&&!z,X=y?.message??`${d} must not ${b} ${u}.`;w(e,a,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:f,fromLayer:d,toLayer:u,target:l,edgeKind:b,...z?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...Z?{severity:"warning"}:{},...ct(a)?{sourcePureTypeModule:!0}:{},message:Z?`${X} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:X},{fromLayer:d,toLayer:u,specifier:c})}return}};return{ImportDeclaration:i,ExportNamedDeclaration:i,ExportAllDeclaration:i}}},Ee={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],r=D(n),s=U({publishCall:xe(t),rawIntentName:r,objectHasIntent:$(n,"intent"),arkPublishCandidate:!1,hasSource:!0});if(s.some(i=>i.ruleId==="RAW_EVENT_PUBLISH")){let i=s.find(a=>a.ruleId==="RAW_EVENT_PUBLISH");w(e,t,"rawPublish",{...i,file:L(e)})}}}}},Ce={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 n=t.arguments?.[0],r=t.arguments?.[2],i=U({publishCall:xe(t),rawIntentName:D(n),objectHasIntent:$(n,"intent"),arkPublishCandidate:!0,hasSource:at(n)||$(r,"source")}).find(a=>a.ruleId==="PUBLISH_MISSING_SOURCE");i&&w(e,t,"missingSource",{...i,file:L(e)})}}}},Le={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=L(e),n=e.options?.[0],r=T(t),s=r?j(r):null,i=r?p.default.dirname(r):null,a=null,c="this layer";if(s&&i&&t){let o=p.default.isAbsolute(t)?t:p.default.resolve(t),l=p.default.relative(i,o).split(p.default.sep).join("/");if(!W(s,l))return{};let u=s.layers?.find(m=>m.name===R(l,s.layers));u?.forbiddenGlobals?.length?(a=new Set(u.forbiddenGlobals),c=u.name):a=null}else n?.globals&&(a=new Set(n.globals));if(!a)return{};let g=typeof J(e)?.getScope=="function",f=(o,l)=>{let u=p.default.isAbsolute(t)?t:p.default.resolve(t),m=i?p.default.relative(i,u).split(p.default.sep).join("/"):t;w(e,o,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:m,fromLayer:c,target:l,message:`${c} must not use the ambient global "${l}".`},{name:l,layer:c})},d=(o,l,u,m)=>{if(u||typeof l!="string")return;let y=H(l,a);if(!y)return;let b=p.default.isAbsolute(t)?t:p.default.resolve(t),A=i?p.default.relative(i,b).split(p.default.sep).join("/"):t;w(e,o,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:A,fromLayer:c,target:l,edgeKind:m,message:`${c} must not use module "${l}" because it is the import form of forbidden global "${y}".`},{layer:c,name:y,specifier:l,importKind:m})};return{MemberExpression(o){if(o.parent?.type==="MemberExpression"&&o.parent.object===o)return;let l=Ie(o);if(!l||P(e,l.root,l.segments[0]))return;let u=l.segments[0]==="globalThis",m=u?l.segments.slice(1):l.segments,y;for(let b=m.length;b>=(u?1:2);b-=1){let A=m.slice(0,b).join(".");if(a.has(A)){y=A;break}}y?f(o,y):!g&&a.has(l.segments[0])&&f(o,l.segments[0])},CallExpression(o){let l=o;if(l.callee?.type==="Identifier"&&l.callee.name==="require"&&l.arguments?.[0]?.type==="Literal"&&!P(e,o,"require")&&d(o,l.arguments[0].value,!1,"require"),g)return;let u=l.callee?.type==="Identifier"?l.callee.name:void 0;u&&a.has(u)&&f(o,u)},ImportDeclaration(o){let l=o,u=(l.specifiers??[]).filter(y=>y.type==="ImportSpecifier"),m=u.length>0&&u.length===(l.specifiers??[]).length&&u.every(y=>y.importKind==="type");d(o,l.source?.value,l.importKind==="type"||m,"import")},ImportExpression(o){let l=o;l.source?.type==="Literal"&&d(o,l.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(o){let l=o;d(o,l.moduleReference?.expression?.value,l.importKind==="type"||l.isTypeOnly===!0,"require")},ExportNamedDeclaration(o){let l=o;if(!l.source)return;let u=l.specifiers??[],m=u.length>0&&u.every(y=>y.exportKind==="type");d(o,l.source.value,l.exportKind==="type"||m,"export")},ExportAllDeclaration(o){let l=o;d(o,l.source?.value,l.exportKind==="type","export")},NewExpression(o){if(g)return;let l=o.callee?.type==="Identifier"?o.callee.name:void 0;l&&a.has(l)&&f(o,l)},Identifier(o){!g||!o.name||!a.has(o.name)||!ot(e,o)||P(e,o,o.name)||f(o,o.name)}}}},Ne={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=L(e),n=T(t),r=n?j(n):null,s=n?p.default.dirname(n):null;if(!r||!s||!t)return{};let i=p.default.isAbsolute(t)?t:p.default.resolve(t),a=p.default.relative(s,i).split(p.default.sep).join("/");if(!W(r,a))return{};let c=r.layers?.find(d=>d.name===R(a,r.layers));if(!c)return{};let g=new Set(ae(c));if(g.size===0)return{};let f=(d,o,l,u)=>{if(l||typeof o!="string"||H(o,c.forbiddenGlobals??[]))return;let m=ie(o);!m||!g.has(m)||w(e,d,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:a,fromLayer:c.name,target:o,capability:m,edgeKind:u,message:`${c.name} denies the ${m} capability; found import of "${o}".`},{layer:c.name,capability:m,specifier:o})};return{ImportDeclaration(d){let o=d,l=(o.specifiers??[]).filter(m=>m.type==="ImportSpecifier"),u=l.length>0&&l.length===(o.specifiers??[]).length&&l.every(m=>m.importKind==="type");f(d,o.source?.value,o.importKind==="type"||u,"import")},ImportExpression(d){let o=d;o.source?.type==="Literal"&&f(d,o.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(d){let o=d;f(d,o.moduleReference?.expression?.value,o.importKind==="type"||o.isTypeOnly===!0,"require")},ExportNamedDeclaration(d){let o=d;if(!o.source)return;let l=o.specifiers??[],u=l.length>0&&l.every(m=>m.exportKind==="type");f(d,o.source.value,o.exportKind==="type"||u,"export")},ExportAllDeclaration(d){let o=d;f(d,o.source?.value,o.exportKind==="type","export")},CallExpression(d){let o=d;o.callee?.type==="Identifier"&&o.callee.name==="require"&&o.arguments?.[0]?.type==="Literal"&&!P(e,d,"require")&&f(d,o.arguments[0].value,!1,"require")}}}},dt={"no-domain-infra-imports":we,"no-raw-event-publish":Ee,"require-publish-source":Ce,"no-forbidden-globals":Le,"no-denied-capabilities":Ne},v={rules:dt};v.configs={recommended:{plugins:{ark:v},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"}}};var pt=v;0&&(module.exports={findConfigPath,globToRegExp,isEdgeDenied,layerForRelativePath,loadArkConfig,noDeniedCapabilities,noDomainInfraImports,noForbiddenGlobals,noRawEventPublish,patternSpecificity,plugin,readTsconfigPathAliases,requirePublishSource,resolveImportSpecifier,resolveRelativeImport});
1
+ "use strict";var _e=Object.create;var N=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var De=(e,t)=>{for(var r in t)N(e,r,{get:t[r],enumerable:!0})},Q=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pe(t))!je.call(e,s)&&s!==r&&N(e,s,{get:()=>t[s],enumerable:!(n=Te(t,s))||n.enumerable});return e};var ee=(e,t,r)=>(r=e!=null?_e($e(e)):{},Q(t||!e||!e.__esModule?N(r,"default",{value:e,enumerable:!0}):r,e)),ve=e=>Q(N({},"__esModule",{value:!0}),e);var ht={};De(ht,{default:()=>yt,findConfigPath:()=>j,globToRegExp:()=>L,isEdgeDenied:()=>M,layerForRelativePath:()=>S,loadArkConfig:()=>D,noDeniedCapabilities:()=>Oe,noDomainInfraImports:()=>Le,noForbiddenGlobals:()=>Ne,noRawEventPublish:()=>Ce,patternSpecificity:()=>V,plugin:()=>$,readTsconfigPathAliases:()=>Ae,requirePublishSource:()=>we,resolveImportSpecifier:()=>ke,resolveRelativeImport:()=>Ie});module.exports=ve(ht);var R=ee(require("fs"),1),p=ee(require("path"),1);var te=new Map;function re(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}function O(e){let t="";for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="\\"&&r+1<e.length){let s=e[r+1];if("*?{}[],".includes(s)||s==="\\"){t+="\\"+s,r+=1;continue}t+="/";continue}t+=n}return t}function Ve(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}function L(e){let t=te.get(e);if(t)return t;let r=O(e),n=Ve(r),s="",o=0;for(let c=0;c<r.length;c+=1){let g=r[c];g==="\\"&&c+1<r.length?(s+=re(r[c+1]),c+=1):g==="*"?r[c+1]==="*"?r[c+2]==="/"?(s+="(?:.*/)?",c+=2):(s+=".*",c+=1):s+="[^/]*":g==="?"?s+="[^/]":g==="{"&&n?(s+="(?:",o+=1):g==="}"&&n&&o>0?(s+=")",o-=1):g===","&&n&&o>0?s+="|":s+=re(g)}let a=new RegExp(`^${s}$`);return te.set(e,a),a}function Ke(e){return O(String(e)).split("/").filter(Boolean).filter(r=>r!=="**"&&r!=="*"&&!r.includes("*")&&!r.includes("?")&&!r.includes("{")&&!r.includes("["))}function V(e,t){let r=O(String(e)),n=Ke(r),s=r.replace(/\*/g,"").length,o=n.length*1e4+s;if(t==null||t==="")return o;let a=String(t).split(/[/\\]/).filter(Boolean);if(n.length===0)return s;let c=0,g=-1;for(let f of n){let d=-1;for(let i=c;i<a.length;i+=1)if(a[i]===f){d=i;break}if(d<0)return o;g=d,c=d+1}return(g+1)*1e6+n.length*1e4+s}function S(e,t){let r=String(e).split(/[/\\]/).join("/"),n,s=-1;for(let o of t??[])if(!(o.exclude??[]).some(a=>L(a).test(r))){for(let a of o.patterns??[])if(L(a).test(r)){let c=V(a,r);c>s&&(s=c,n=o.name)}}return n}function ne(e,t){if(!t?.length)return;let r=String(e).split(/[/\\]/).filter(Boolean),n=new Set(t.map(s=>String(s).toLowerCase()));for(let s=0;s<r.length-1;s+=1)if(n.has(r[s].toLowerCase()))return`${r[s].toLowerCase()}/${r[s+1].toLowerCase()}`}function Me(e){let t=new Set;for(let r of e??[]){let s=O(String(r)).split("/").filter(Boolean);for(let o=0;o<s.length;o+=1){let a=s[o];if((a==="**"||a==="*")&&o>0){let c=s[o-1];c&&!c.includes("*")&&!c.includes("{")&&!c.includes("}")&&t.add(c)}}}return[...t]}function He(e,t,r){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(s=>typeof s=="string"&&s.length>0);let n=(r??[]).find(s=>s.name===t);return Me(n?.patterns)}function Fe(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}function K(e,t,r,n){for(let s of e??[])if(!(s.from!==t||s.to!==r)&&s.allowed===!1){if(s.peerIsolation){let o=n?.fromPath,a=n?.toPath,c=He(s,t,n?.layers),g=o&&a?ne(o,c):void 0,f=o&&a?ne(a,c):void 0;if(Fe({fromPath:o,toPath:a,folderCount:c.length,fromSlice:g,toSlice:f}))return s;continue}if(t!==r)return s}}function M(e,t,r,n){return K(e,t,r,n)!==void 0}var Ue=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function Be(e){let t=Array.isArray(e?.exclude)?e.exclude.filter(n=>typeof n=="string"):[];return[...e?.excludeGenerated===!1?[]:Ue,...t]}function se(e,t){let r=String(e).split(/[/\\]/).join("/");return Be(t).some(n=>L(n).test(r))}var ie=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),Ge=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),It=Object.freeze(Object.keys(Ge).sort()),H=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"}),qe=Object.freeze({process:Object.freeze(["process","node:process"])});function oe(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let t=H[e];if(t)return t;let r=e.indexOf("/");if(r<0)return null;let n=e.slice(0,r),s=H[n];if(s)return s;let o=e.indexOf("/",r+1);return o<0?null:H[e.slice(0,o)]??null}function F(e,t){for(let r of t)if(qe[r]?.includes(e))return r;return null}function ae(e){if(e?.pure===!0)return[...ie].sort();let r=(e?.capabilities?.deny??[]).filter(n=>ie.includes(n));return[...new Set(r)].sort()}var U="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",le=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],We=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function Ye(){let e=[];for(let t of le)for(let r of le)t===r||We.has(`${t}->${r}`)||e.push({from:t,to:r,allowed:!1});return e}var de=Ye(),B=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"}],I={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},ce={$schema:"https://json-schema.org/draft/2020-12/schema",$id:U,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:U,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:"1.1",default:"1.1"},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:de,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:{}},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}}}}},k=class extends Error{issues;source;constructor(t,r){super(`Invalid ArkGate config (${t}):
2
+ ${r.map(n=>`- ${n.path}: ${n.message}`).join(`
3
+ `)}`),this.name="ArkConfigValidationError",this.source=t,this.issues=r}};function pe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function _(e,t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}function x(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ze(e,t){let r="#/$defs/";if(e.startsWith(r))return t.$defs[e.slice(r.length)]}function C(e,t,r,n,s){if(t.$ref){let o=ze(t.$ref,n);if(!o){s.push({path:r,message:`schema reference ${t.$ref} cannot be resolved`});return}C(e,o,r,n,s);return}if(t.const!==void 0&&!Object.is(e,t.const)){s.push({path:r,message:`must equal ${JSON.stringify(t.const)}`});return}if(t.enum&&!t.enum.some(o=>Object.is(o,e))){s.push({path:r,message:`must be one of ${t.enum.map(String).join(", ")}`});return}if(t.type==="object"){if(!pe(e)){s.push({path:r,message:`must be an object; received ${x(e)}`});return}let o=t.properties??{};for(let a of t.required??[])e[a]===void 0&&s.push({path:_(r,a),message:"is required"});if(t.additionalProperties===!1)for(let a of Object.keys(e))a in o||s.push({path:_(r,a),message:"unknown field"});else if(t.additionalProperties!==void 0&&t.additionalProperties!==!0&&typeof t.additionalProperties=="object"){let a=t.additionalProperties;for(let c of Object.keys(e))c in o||C(e[c],a,_(r,c),n,s)}for(let[a,c]of Object.entries(o))e[a]!==void 0&&C(e[a],c,_(r,a),n,s);return}if(t.type==="array"){if(!Array.isArray(e)){s.push({path:r,message:`must be an array; received ${x(e)}`});return}if(t.minItems!==void 0&&e.length<t.minItems&&s.push({path:r,message:`must contain at least ${t.minItems} item(s)`}),t.uniqueItems){let o=e.map(a=>JSON.stringify(a));new Set(o).size!==o.length&&s.push({path:r,message:"must not contain duplicate items"})}t.items&&e.forEach((o,a)=>C(o,t.items,`${r}[${a}]`,n,s));return}if(t.type==="string"){if(typeof e!="string"){s.push({path:r,message:`must be a string; received ${x(e)}`});return}t.minLength!==void 0&&e.length<t.minLength&&s.push({path:r,message:`must contain at least ${t.minLength} character(s)`});return}if(t.type==="boolean"){typeof e!="boolean"&&s.push({path:r,message:`must be a boolean; received ${x(e)}`});return}if(t.type==="integer"){if(!Number.isInteger(e)){s.push({path:r,message:`must be an integer; received ${x(e)}`});return}t.minimum!==void 0&&e<t.minimum&&s.push({path:r,message:`must be at least ${t.minimum}`})}}function Je(e){return{...e,$schema:e.$schema===void 0?U:e.$schema,schemaVersion:e.schemaVersion===void 0?"1.1":e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?de.map(t=>({...t})):e.rules}}function Xe(){let e=new Set(["1.1"]);for(let t of B)t.from!=="unversioned"&&e.add(t.from),e.add(t.to);return e}function Ze(e,t="ark.config.json"){if(!pe(e))throw new k(t,[{path:"$",message:`must be an object; received ${x(e)}`}]);let r=Xe(),n=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(n===null)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected 1.1`}]);if(n!=="unversioned"&&!r.has(n))throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected 1.1`}]);let s=n,o={...e},a=0;for(;s!=="1.1"&&a<B.length+1;){a+=1;let g=B.find(f=>f.from===s);if(!g)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(s)}; expected 1.1`}]);s=g.to,o.schemaVersion=s}if(s!=="1.1")throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected 1.1`}]);let c=n==="unversioned"?"unversioned":n==="1.0"?"1.0":null;return{candidate:Je(o),migratedFrom:c}}function Qe(e,t="ark.config.json"){let{candidate:r,migratedFrom:n}=Ze(e,t),s=[];if(C(r,ce,"$",ce,s),s.length>0)throw new k(t,s);return{config:r,migratedFrom:n}}function ue(e,t="ark.config.json"){let r;try{r=JSON.parse(e)}catch(n){throw new k(t,[{path:"$",message:`invalid JSON: ${n instanceof Error?n.message:String(n)}`}])}return Qe(r,t)}var et=/(^|\/)(constants|types|enums|shared-types|shared\/(?:types|constants)|test-projects)(\/|\.|$)|(?:^|\/)[^/]*(?:constants|types)(?:\.[cm]?[jt]sx?)?$/i,tt=/(^|\/)(?:kernel(?:\/|$)|events?(?:\/|\.|$)|bootstrap(?:\.[cm]?[jt]sx?)?$|emitter(?:\.[cm]?[jt]sx?)?$)|(?:^|\/)(?:intents?|publish)(?:\/|\.|$)/i,rt=/(use-?cases?|usecases?|application|orchestrat|services?|handlers?)(\/|\.|$)/i;function nt(e,t){let r=String(e??"").replace(/\\/g,"/").trim(),n=String(t?.fromLayer??""),s=String(t?.toLayer??"");return et.test(r)?"pure-shared":n==="PersistenceAdapters"&&(tt.test(r)||/events?|intents?|kernel|bootstrap/i.test(`${s} ${r}`))?"kernel-emit":rt.test(r)||(n==="DomainModel"||n==="ApplicationOrchestration")&&s==="PersistenceAdapters"?"use-case":"unknown"}function fe(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=nt(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."}var st="docs/diagnostics.md";function y(e){return typeof e=="string"&&e.length>0?e:void 0}function ge(e,t){return Number.isInteger(e)&&Number(e)>0?Number(e):t}function it(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,s=typeof e.toLayer=="string"?e.toLayer:void 0,o=typeof e.target=="string"?e.target:void 0;return[t,r,n??"",s??"",o??""].join("|")}function ot(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")}`}function at(e){return`${st}#${e}`}function lt(e,t,r){if(e==="LAYER_IMPORT_VIOLATION")return fe({ruleId:e,typeOnly:t.typeOnly===!0,targetTypeOnlyExports:r.targetTypeOnlyExports===!0,namedBindingsTypeOnly:r.namedBindingsTypeOnly===!0,peerIsolation:r.peerIsolation===!0,portProofEligible:r.portProofEligible===!0,fromLayer:y(t.fromLayer)??void 0,toLayer:y(t.toLayer)??void 0,target:y(t.target)??y(r.target)??void 0});if(e==="FORBIDDEN_GLOBAL")return`Inject ${t.target??"the capability"} through a port, test at the public interface, then preflight again.`;if(e==="CAPABILITY_VIOLATION")return`Define a ${y(r.capability)??"capability"} port in ${t.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;if(e==="CIRCULAR_DEPENDENCY")return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";if(e==="RAW_EVENT_PUBLISH")return"Publish through a registered intent creator, then run Ark again.";if(e==="PUBLISH_MISSING_SOURCE")return"Add metadata.source to the publish call, then run Ark again.";if(e==="ARKRULE_STRUCTURE"||e==="ARKRULE_INVARIANT"||e==="INVARIANT_UNCOVERED"||e.startsWith("ARKRULE_")){let n=t.arkruleSource??"arkrules/<Layer>.json";return`Fix the structure or invariant for ${t.arkruleId??"the ArkRule"} (declared in ${n}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`}return`Resolve ${e} without weakening ark.config.json, then run Ark again.`}function me(e,t="error",r){let n=y(e.ruleId)??y(e.code)??"ARK_UNKNOWN",s=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":t,o={...y(e.target)?{target:y(e.target)}:{},...y(e.fromLayer)?{fromLayer:y(e.fromLayer)}:{},...y(e.toLayer)?{toLayer:y(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}:{},...y(e.capability)?{capability:y(e.capability)}:{},...y(e.edgeKind)?{edgeKind:y(e.edgeKind)}:{},...y(e.arkruleId)?{arkruleId:y(e.arkruleId)}:{},...y(e.arkruleSource)?{arkruleSource:y(e.arkruleSource)}:{}},a=r??it(e),c=ot(a);return{ruleId:n,severity:s,message:y(e.message)??n,location:{file:y(e.file)??"<unknown>",line:ge(e.line,1),column:ge(e.column,1)},evidence:o,nextAction:y(e.nextAction)??lt(n,o,e),findingRef:c,targetKey:a,docsCodePath:at(n)}}var ye={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."},Lt=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 ct(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}function G(e){if(!e.publishCall)return[];let t=[];return(e.rawIntentName!==void 0&&ct(e.rawIntentName)||e.objectHasIntent)&&t.push({ruleId:"RAW_EVENT_PUBLISH",message:ye.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&t.push({ruleId:"PUBLISH_MISSING_SOURCE",message:ye.PUBLISH_MISSING_SOURCE}),t}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""}function E(e,t,r,n,s){let o=me({...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,...s?{data:s}:{},diagnostic:o}),o}function j(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let t=p.default.dirname(p.default.resolve(e));for(;;){let r=p.default.join(t,"ark.config.json");if(R.default.existsSync(r))return r;let n=p.default.dirname(t);if(n===t)return null;t=n}}var he=new Map;function D(e){if(!R.default.existsSync(e))return null;let t=R.default.readFileSync(e,"utf8"),r=he.get(e);if(r?.source===t)return r.config;let n=ue(t,e).config;return he.set(e,{source:t,config:n}),n}function W(e,t){return(e.include??[]).some(n=>{let s=String(n).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!se(t,e)}function be(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,p.default.join(e,"index.ts"),p.default.join(e,"index.tsx"),p.default.join(e,"index.js")];for(let r of t)try{if(R.default.existsSync(r)&&R.default.statSync(r).isFile())return r}catch{}return null}function Ae(e){let t=p.default.resolve(e),r=null;for(;;){let f=p.default.join(t,"tsconfig.json");if(R.default.existsSync(f)){r=f;break}let d=p.default.dirname(t);if(d===t)break;t=d}if(!r)return{baseUrl:e,aliases:[]};let n=f=>{try{let d=R.default.readFileSync(f,"utf8");return d=d.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(d)}catch{return null}},s=(f,d)=>{if(d>4)return{};let i=n(f);if(!i)return{};let l=i.compilerOptions??{},u=l.baseUrl,m=l.paths,h=i.extends;if(typeof h=="string"&&!h.startsWith("@")){let b=p.default.resolve(p.default.dirname(f),h.endsWith(".json")?h:`${h}.json`);if(R.default.existsSync(b)){let A=s(b,d+1);u=u??A.baseUrl,m={...A.paths??{},...m??{}}}}return{baseUrl:u,paths:m}},o=s(r,0),a=p.default.dirname(r),c=p.default.resolve(a,o.baseUrl||"."),g=[];for(let[f,d]of Object.entries(o.paths||{})){if(!Array.isArray(d)||d.length===0)continue;let i=f.replace(/\*$/,"");i&&g.push({from:i,to:String(d[0]).replace(/\*$/,"")})}return g.sort((f,d)=>d.from.length-f.from.length),{baseUrl:c,aliases:g}}function Ie(e,t){if(!t.startsWith("."))return null;let r=p.default.resolve(p.default.dirname(e),t);return be(r)}function ke(e,t,r){if(!t)return null;if(t.startsWith("."))return Ie(e,t);let n=r||p.default.dirname(e),{baseUrl:s,aliases:o}=Ae(n),a=o.find(g=>t.startsWith(g.from));if(!a)return null;let c=p.default.resolve(s,`${a.to}${t.slice(a.from.length)}`);return be(c)}function v(e){return typeof e?.value=="string"?e.value:void 0}function Y(e){return e?.name??v(e)}function z(e){return e.sourceCode??e.getSourceCode?.()}function Re(e,t){let r=z(e)?.getScope?.(t);for(;r;){let n=r.references?.find(s=>s.identifier===t);if(n)return n;r=r.upper??void 0}}function T(e,t,r){let n=Re(e,t);if(n?.resolved)return(n.resolved.defs?.length??0)>0;let s=z(e)?.getScope?.(t);for(;s;){let o=s.set?.get(r);if(o)return(o.defs?.length??0)>0;s=s.upper??void 0}return!1}function dt(e,t){let r=Re(e,t);return r?r.isValueReference!==!1:t.parent?.type==="VariableDeclarator"&&t.parent.init===t}function Se(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=Se(e.object),n=Y(e.property);if(!(!r||!n))return{root:r.root,segments:[...r.segments,n]}}function pt(e){return Y(e.callee?.property)}function xe(e,t){return e?.properties?.find(r=>Y(r.key)===t)}function P(e,t){return xe(e,t)!==void 0}function ut(e){let t=xe(e,"metadata")?.value;return P(t,"source")}function Ee(e){return pt(e)==="publish"}function q(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")}function ft(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}function gt(e){let t=ft(e)?.body;if(!t)return!1;let r=!1;for(let n of t){if(n.type==="ImportDeclaration"){if(!q(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(!q(n))return!1;r=!0;continue}return!1}}return r}var Le={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?D(r):null,s=r?p.default.dirname(r):null,o=a=>{let c=v(a.source);if(c&&n&&s&&t){let g=p.default.isAbsolute(t)?t:p.default.resolve(t),f=p.default.relative(s,g).split(p.default.sep).join("/");if(!W(n,f))return;let d=S(f,n.layers);if(!d)return;let i=ke(g,c,s);if(!i)return;let l=p.default.relative(s,i).split(p.default.sep).join("/");if(l.startsWith(".."))return;let u=S(l,n.layers);if(!u)return;let m={fromPath:f,toPath:l,layers:n.layers},h=K(n.rules,d,u,m);if(h||M(n.rules,d,u,m)){let b=a.type?.startsWith("Export")?"export":"import",A=q(a),J=!!h?.peerIsolation,X=A&&!J,Z=h?.message??`${d} must not ${b} ${u}.`;E(e,a,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:f,fromLayer:d,toLayer:u,target:l,edgeKind:b,...J?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...X?{severity:"warning"}:{},...gt(a)?{sourcePureTypeModule:!0}:{},message:X?`${Z} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:Z},{fromLayer:d,toLayer:u,specifier:c})}return}};return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},Ce={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=v(r),s=G({publishCall:Ee(t),rawIntentName:n,objectHasIntent:P(r,"intent"),arkPublishCandidate:!1,hasSource:!0});if(s.some(o=>o.ruleId==="RAW_EVENT_PUBLISH")){let o=s.find(a=>a.ruleId==="RAW_EVENT_PUBLISH");E(e,t,"rawPublish",{...o,file:w(e)})}}}}},we={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],o=G({publishCall:Ee(t),rawIntentName:v(r),objectHasIntent:P(r,"intent"),arkPublishCandidate:!0,hasSource:ut(r)||P(n,"source")}).find(a=>a.ruleId==="PUBLISH_MISSING_SOURCE");o&&E(e,t,"missingSource",{...o,file:w(e)})}}}},Ne={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),s=n?D(n):null,o=n?p.default.dirname(n):null,a=null,c="this layer";if(s&&o&&t){let i=p.default.isAbsolute(t)?t:p.default.resolve(t),l=p.default.relative(o,i).split(p.default.sep).join("/");if(!W(s,l))return{};let u=s.layers?.find(m=>m.name===S(l,s.layers));u?.forbiddenGlobals?.length?(a=new Set(u.forbiddenGlobals),c=u.name):a=null}else r?.globals&&(a=new Set(r.globals));if(!a)return{};let g=typeof z(e)?.getScope=="function",f=(i,l)=>{let u=p.default.isAbsolute(t)?t:p.default.resolve(t),m=o?p.default.relative(o,u).split(p.default.sep).join("/"):t;E(e,i,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:m,fromLayer:c,target:l,message:`${c} must not use the ambient global "${l}".`},{name:l,layer:c})},d=(i,l,u,m)=>{if(u||typeof l!="string")return;let h=F(l,a);if(!h)return;let b=p.default.isAbsolute(t)?t:p.default.resolve(t),A=o?p.default.relative(o,b).split(p.default.sep).join("/"):t;E(e,i,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:A,fromLayer:c,target:l,edgeKind:m,message:`${c} must not use module "${l}" because it is the import form of forbidden global "${h}".`},{layer:c,name:h,specifier:l,importKind:m})};return{MemberExpression(i){if(i.parent?.type==="MemberExpression"&&i.parent.object===i)return;let l=Se(i);if(!l||T(e,l.root,l.segments[0]))return;let u=l.segments[0]==="globalThis",m=u?l.segments.slice(1):l.segments,h;for(let b=m.length;b>=(u?1:2);b-=1){let A=m.slice(0,b).join(".");if(a.has(A)){h=A;break}}h?f(i,h):!g&&a.has(l.segments[0])&&f(i,l.segments[0])},CallExpression(i){let l=i;if(l.callee?.type==="Identifier"&&l.callee.name==="require"&&l.arguments?.[0]?.type==="Literal"&&!T(e,i,"require")&&d(i,l.arguments[0].value,!1,"require"),g)return;let u=l.callee?.type==="Identifier"?l.callee.name:void 0;u&&a.has(u)&&f(i,u)},ImportDeclaration(i){let l=i,u=(l.specifiers??[]).filter(h=>h.type==="ImportSpecifier"),m=u.length>0&&u.length===(l.specifiers??[]).length&&u.every(h=>h.importKind==="type");d(i,l.source?.value,l.importKind==="type"||m,"import")},ImportExpression(i){let l=i;l.source?.type==="Literal"&&d(i,l.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(i){let l=i;d(i,l.moduleReference?.expression?.value,l.importKind==="type"||l.isTypeOnly===!0,"require")},ExportNamedDeclaration(i){let l=i;if(!l.source)return;let u=l.specifiers??[],m=u.length>0&&u.every(h=>h.exportKind==="type");d(i,l.source.value,l.exportKind==="type"||m,"export")},ExportAllDeclaration(i){let l=i;d(i,l.source?.value,l.exportKind==="type","export")},NewExpression(i){if(g)return;let l=i.callee?.type==="Identifier"?i.callee.name:void 0;l&&a.has(l)&&f(i,l)},Identifier(i){!g||!i.name||!a.has(i.name)||!dt(e,i)||T(e,i,i.name)||f(i,i.name)}}}},Oe={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?D(r):null,s=r?p.default.dirname(r):null;if(!n||!s||!t)return{};let o=p.default.isAbsolute(t)?t:p.default.resolve(t),a=p.default.relative(s,o).split(p.default.sep).join("/");if(!W(n,a))return{};let c=n.layers?.find(d=>d.name===S(a,n.layers));if(!c)return{};let g=new Set(ae(c));if(g.size===0)return{};let f=(d,i,l,u)=>{if(l||typeof i!="string"||F(i,c.forbiddenGlobals??[]))return;let m=oe(i);!m||!g.has(m)||E(e,d,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:a,fromLayer:c.name,target:i,capability:m,edgeKind:u,message:`${c.name} denies the ${m} capability; found import of "${i}".`},{layer:c.name,capability:m,specifier:i})};return{ImportDeclaration(d){let i=d,l=(i.specifiers??[]).filter(m=>m.type==="ImportSpecifier"),u=l.length>0&&l.length===(i.specifiers??[]).length&&l.every(m=>m.importKind==="type");f(d,i.source?.value,i.importKind==="type"||u,"import")},ImportExpression(d){let i=d;i.source?.type==="Literal"&&f(d,i.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(d){let i=d;f(d,i.moduleReference?.expression?.value,i.importKind==="type"||i.isTypeOnly===!0,"require")},ExportNamedDeclaration(d){let i=d;if(!i.source)return;let l=i.specifiers??[],u=l.length>0&&l.every(m=>m.exportKind==="type");f(d,i.source.value,i.exportKind==="type"||u,"export")},ExportAllDeclaration(d){let i=d;f(d,i.source?.value,i.exportKind==="type","export")},CallExpression(d){let i=d;i.callee?.type==="Identifier"&&i.callee.name==="require"&&i.arguments?.[0]?.type==="Literal"&&!T(e,d,"require")&&f(d,i.arguments[0].value,!1,"require")}}}},mt={"no-domain-infra-imports":Le,"no-raw-event-publish":Ce,"require-publish-source":we,"no-forbidden-globals":Ne,"no-denied-capabilities":Oe},$={rules:mt};$.configs={recommended:{plugins:{ark:$},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"}}};var yt=$;0&&(module.exports={findConfigPath,globToRegExp,isEdgeDenied,layerForRelativePath,loadArkConfig,noDeniedCapabilities,noDomainInfraImports,noForbiddenGlobals,noRawEventPublish,patternSpecificity,plugin,readTsconfigPathAliases,requirePublishSource,resolveImportSpecifier,resolveRelativeImport});
@@ -1,4 +1,4 @@
1
- import { A as ArkConfig } from '../configTypes-B8uIcLaG.js';
1
+ import { A as ArkConfig } from '../configTypes-l6XiwiC1.js';
2
2
 
3
3
  /**
4
4
  * Pure layer-glob matching for ark.config.json.
@@ -1,3 +1,3 @@
1
- import I from"fs";import p from"path";var z=new Map;function Z(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}function N(e){let t="";for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if("*?{}[],".includes(s)||s==="\\"){t+="\\"+s,n+=1;continue}t+="/";continue}t+=r}return t}function Ae(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"){n+=1;continue}if(r==="{")t+=1;else if(r==="}"&&(t-=1,t<0))return!1}return t===0}function L(e){let t=z.get(e);if(t)return t;let n=N(e),r=Ae(n),s="",i=0;for(let c=0;c<n.length;c+=1){let g=n[c];g==="\\"&&c+1<n.length?(s+=Z(n[c+1]),c+=1):g==="*"?n[c+1]==="*"?n[c+2]==="/"?(s+="(?:.*/)?",c+=2):(s+=".*",c+=1):s+="[^/]*":g==="?"?s+="[^/]":g==="{"&&r?(s+="(?:",i+=1):g==="}"&&r&&i>0?(s+=")",i-=1):g===","&&r&&i>0?s+="|":s+=Z(g)}let a=new RegExp(`^${s}$`);return z.set(e,a),a}function Se(e){return N(String(e)).split("/").filter(Boolean).filter(n=>n!=="**"&&n!=="*"&&!n.includes("*")&&!n.includes("?")&&!n.includes("{")&&!n.includes("["))}function Q(e,t){let n=N(String(e)),r=Se(n),s=n.replace(/\*/g,"").length,i=r.length*1e4+s;if(t==null||t==="")return i;let a=String(t).split(/[/\\]/).filter(Boolean);if(r.length===0)return s;let c=0,g=-1;for(let f of r){let d=-1;for(let o=c;o<a.length;o+=1)if(a[o]===f){d=o;break}if(d<0)return i;g=d,c=d+1}return(g+1)*1e6+r.length*1e4+s}function w(e,t){let n=String(e).split(/[/\\]/).join("/"),r,s=-1;for(let i of t??[])if(!(i.exclude??[]).some(a=>L(a).test(n))){for(let a of i.patterns??[])if(L(a).test(n)){let c=Q(a,n);c>s&&(s=c,r=i.name)}}return r}function X(e,t){if(!t?.length)return;let n=String(e).split(/[/\\]/).filter(Boolean),r=new Set(t.map(s=>String(s).toLowerCase()));for(let s=0;s<n.length-1;s+=1)if(r.has(n[s].toLowerCase()))return`${n[s].toLowerCase()}/${n[s+1].toLowerCase()}`}function ke(e){let t=new Set;for(let n of e??[]){let s=N(String(n)).split("/").filter(Boolean);for(let i=0;i<s.length;i+=1){let a=s[i];if((a==="**"||a==="*")&&i>0){let c=s[i-1];c&&!c.includes("*")&&!c.includes("{")&&!c.includes("}")&&t.add(c)}}}return[...t]}function Ie(e,t,n){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(s=>typeof s=="string"&&s.length>0);let r=(n??[]).find(s=>s.name===t);return ke(r?.patterns)}function Re(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}function v(e,t,n,r){for(let s of e??[])if(!(s.from!==t||s.to!==n)&&s.allowed===!1){if(s.peerIsolation){let i=r?.fromPath,a=r?.toPath,c=Ie(s,t,r?.layers),g=i&&a?X(i,c):void 0,f=i&&a?X(a,c):void 0;if(Re({fromPath:i,toPath:a,folderCount:c.length,fromSlice:g,toSlice:f}))return s;continue}if(t!==n)return s}}function ee(e,t,n,r){return v(e,t,n,r)!==void 0}var xe=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function we(e){let t=Array.isArray(e?.exclude)?e.exclude.filter(r=>typeof r=="string"):[];return[...e?.excludeGenerated===!1?[]:xe,...t]}function te(e,t){let n=String(e).split(/[/\\]/).join("/");return we(t).some(r=>L(r).test(n))}var ne=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),Ee=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),nt=Object.freeze(Object.keys(Ee).sort()),T=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"}),Ce=Object.freeze({process:Object.freeze(["process","node:process"])});function re(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let t=T[e];if(t)return t;let n=e.indexOf("/");if(n<0)return null;let r=e.slice(0,n),s=T[r];if(s)return s;let i=e.indexOf("/",n+1);return i<0?null:T[e.slice(0,i)]??null}function j(e,t){for(let n of t)if(Ce[n]?.includes(e))return n;return null}function se(e){if(e?.pure===!0)return[...ne].sort();let n=(e?.capabilities?.deny??[]).filter(r=>ne.includes(r));return[...new Set(n)].sort()}var D="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",oe=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],Le=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function Ne(){let e=[];for(let t of oe)for(let n of oe)t===n||Le.has(`${t}->${n}`)||e.push({from:t,to:n,allowed:!1});return e}var ae=Ne(),M=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"}],S={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},ie={$schema:"https://json-schema.org/draft/2020-12/schema",$id:D,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:D,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:"1.1",default:"1.1"},name:{type:"string",minLength:1},include:{...S,minItems:1,default:["src"]},exclude:{...S,default:[]},excludeGenerated:{type:"boolean",default:!0},frameworkOverlay:{type:"string",minLength:1},layers:{type:"array",default:[],items:{$ref:"#/$defs/layer"}},rules:{type:"array",default:ae,items:{$ref:"#/$defs/rule"}},cyclePolicy:{type:"string",enum:["strict","soft","framework-soft","off"],default:"strict"},dynamicImportAllowlist:{...S,default:[]},safety:{$ref:"#/$defs/safety",default:{maxTsSuppressions:0,maxAnyCasts:0,allowInMemory:!1,allowDisabledPeerIsolation:!1}},arkRules:{type:"object",additionalProperties:{type:"string",minLength:1},default:{}},stewards:{...S,default:[]}},$defs:{layer:{type:"object",additionalProperties:!1,required:["name","patterns"],properties:{name:{type:"string",minLength:1},patterns:{...S,minItems:1},exclude:S,intentPrefixes:S,description:{type:"string",minLength:1},forbiddenGlobals:S,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"}}},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:{...S,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}}}}},k=class extends Error{issues;source;constructor(t,n){super(`Invalid ArkGate config (${t}):
2
- ${n.map(r=>`- ${r.path}: ${r.message}`).join(`
3
- `)}`),this.name="ArkConfigValidationError",this.source=t,this.issues=n}};function le(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function O(e,t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}function R(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Oe(e,t){let n="#/$defs/";if(e.startsWith(n))return t.$defs[e.slice(n.length)]}function E(e,t,n,r,s){if(t.$ref){let i=Oe(t.$ref,r);if(!i){s.push({path:n,message:`schema reference ${t.$ref} cannot be resolved`});return}E(e,i,n,r,s);return}if(t.const!==void 0&&!Object.is(e,t.const)){s.push({path:n,message:`must equal ${JSON.stringify(t.const)}`});return}if(t.enum&&!t.enum.some(i=>Object.is(i,e))){s.push({path:n,message:`must be one of ${t.enum.map(String).join(", ")}`});return}if(t.type==="object"){if(!le(e)){s.push({path:n,message:`must be an object; received ${R(e)}`});return}let i=t.properties??{};for(let a of t.required??[])e[a]===void 0&&s.push({path:O(n,a),message:"is required"});if(t.additionalProperties===!1)for(let a of Object.keys(e))a in i||s.push({path:O(n,a),message:"unknown field"});else if(t.additionalProperties!==void 0&&t.additionalProperties!==!0&&typeof t.additionalProperties=="object"){let a=t.additionalProperties;for(let c of Object.keys(e))c in i||E(e[c],a,O(n,c),r,s)}for(let[a,c]of Object.entries(i))e[a]!==void 0&&E(e[a],c,O(n,a),r,s);return}if(t.type==="array"){if(!Array.isArray(e)){s.push({path:n,message:`must be an array; received ${R(e)}`});return}if(t.minItems!==void 0&&e.length<t.minItems&&s.push({path:n,message:`must contain at least ${t.minItems} item(s)`}),t.uniqueItems){let i=e.map(a=>JSON.stringify(a));new Set(i).size!==i.length&&s.push({path:n,message:"must not contain duplicate items"})}t.items&&e.forEach((i,a)=>E(i,t.items,`${n}[${a}]`,r,s));return}if(t.type==="string"){if(typeof e!="string"){s.push({path:n,message:`must be a string; received ${R(e)}`});return}t.minLength!==void 0&&e.length<t.minLength&&s.push({path:n,message:`must contain at least ${t.minLength} character(s)`});return}if(t.type==="boolean"){typeof e!="boolean"&&s.push({path:n,message:`must be a boolean; received ${R(e)}`});return}if(t.type==="integer"){if(!Number.isInteger(e)){s.push({path:n,message:`must be an integer; received ${R(e)}`});return}t.minimum!==void 0&&e<t.minimum&&s.push({path:n,message:`must be at least ${t.minimum}`})}}function _e(e){return{...e,$schema:e.$schema===void 0?D:e.$schema,schemaVersion:e.schemaVersion===void 0?"1.1":e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?ae.map(t=>({...t})):e.rules}}function Pe(){let e=new Set(["1.1"]);for(let t of M)t.from!=="unversioned"&&e.add(t.from),e.add(t.to);return e}function $e(e,t="ark.config.json"){if(!le(e))throw new k(t,[{path:"$",message:`must be an object; received ${R(e)}`}]);let n=Pe(),r=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(r===null)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected 1.1`}]);if(r!=="unversioned"&&!n.has(r))throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(r)}; expected 1.1`}]);let s=r,i={...e},a=0;for(;s!=="1.1"&&a<M.length+1;){a+=1;let g=M.find(f=>f.from===s);if(!g)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(s)}; expected 1.1`}]);s=g.to,i.schemaVersion=s}if(s!=="1.1")throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(r)}; expected 1.1`}]);let c=r==="unversioned"?"unversioned":r==="1.0"?"1.0":null;return{candidate:_e(i),migratedFrom:c}}function ve(e,t="ark.config.json"){let{candidate:n,migratedFrom:r}=$e(e,t),s=[];if(E(n,ie,"$",ie,s),s.length>0)throw new k(t,s);return{config:n,migratedFrom:r}}function ce(e,t="ark.config.json"){let n;try{n=JSON.parse(e)}catch(r){throw new k(t,[{path:"$",message:`invalid JSON: ${r instanceof Error?r.message:String(r)}`}])}return ve(n,t)}var Te="docs/diagnostics.md";function h(e){return typeof e=="string"&&e.length>0?e:void 0}function de(e,t){return Number.isInteger(e)&&Number(e)>0?Number(e):t}function je(e){let t=typeof e.ruleId=="string"?e.ruleId:typeof e.code=="string"?e.code:void 0,n=typeof e.file=="string"?e.file:void 0,r=typeof e.fromLayer=="string"?e.fromLayer:void 0,s=typeof e.toLayer=="string"?e.toLayer:void 0,i=typeof e.target=="string"?e.target:void 0;return[t,n,r??"",s??"",i??""].join("|")}function De(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return`fnv1a-${(t>>>0).toString(16).padStart(8,"0")}`}function Me(e){return`${Te}#${e}`}function Ve(e,t,n){if(e==="LAYER_IMPORT_VIOLATION")return t.typeOnly||n.targetTypeOnlyExports===!0||n.namedBindingsTypeOnly===!0?"Move the referenced type to a mutually allowed layer, use `import type`, then preflight again.":n.peerIsolation===!0?"Extract the shared dependency to a shared layer, test at the public interface, then preflight again.":`Define a port in ${t.fromLayer??"the source layer"}, inject the ${t.toLayer??"outer-layer"} implementation, test at the public interface, then preflight again.`;if(e==="FORBIDDEN_GLOBAL")return`Inject ${t.target??"the capability"} through a port, test at the public interface, then preflight again.`;if(e==="CAPABILITY_VIOLATION")return`Define a ${h(n.capability)??"capability"} port in ${t.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;if(e==="CIRCULAR_DEPENDENCY")return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";if(e==="RAW_EVENT_PUBLISH")return"Publish through a registered intent creator, then run Ark again.";if(e==="PUBLISH_MISSING_SOURCE")return"Add metadata.source to the publish call, then run Ark again.";if(e==="ARKRULE_STRUCTURE"||e==="ARKRULE_INVARIANT"||e==="INVARIANT_UNCOVERED"||e.startsWith("ARKRULE_")){let r=t.arkruleSource??"arkrules/<Layer>.json";return`Fix the structure or invariant for ${t.arkruleId??"the ArkRule"} (declared in ${r}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`}return`Resolve ${e} without weakening ark.config.json, then run Ark again.`}function pe(e,t="error",n){let r=h(e.ruleId)??h(e.code)??"ARK_UNKNOWN",s=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":t,i={...h(e.target)?{target:h(e.target)}:{},...h(e.fromLayer)?{fromLayer:h(e.fromLayer)}:{},...h(e.toLayer)?{toLayer:h(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}:{},...h(e.capability)?{capability:h(e.capability)}:{},...h(e.edgeKind)?{edgeKind:h(e.edgeKind)}:{},...h(e.arkruleId)?{arkruleId:h(e.arkruleId)}:{},...h(e.arkruleSource)?{arkruleSource:h(e.arkruleSource)}:{}},a=n??je(e),c=De(a);return{ruleId:r,severity:s,message:h(e.message)??r,location:{file:h(e.file)??"<unknown>",line:de(e.line,1),column:de(e.column,1)},evidence:i,nextAction:h(e.nextAction)??Ve(r,i,e),findingRef:c,targetKey:a,docsCodePath:Me(r)}}var ue={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."},it=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 Fe(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}function V(e){if(!e.publishCall)return[];let t=[];return(e.rawIntentName!==void 0&&Fe(e.rawIntentName)||e.objectHasIntent)&&t.push({ruleId:"RAW_EVENT_PUBLISH",message:ue.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&t.push({ruleId:"PUBLISH_MISSING_SOURCE",message:ue.PUBLISH_MISSING_SOURCE}),t}function C(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""}function x(e,t,n,r,s){let i=pe({...r,line:r.line??t.loc?.start?.line,column:r.column??(typeof t.loc?.start?.column=="number"?t.loc.start.column+1:void 0)});return e.report({node:t,messageId:n,...s?{data:s}:{},diagnostic:i}),i}function H(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let t=p.dirname(p.resolve(e));for(;;){let n=p.join(t,"ark.config.json");if(I.existsSync(n))return n;let r=p.dirname(t);if(r===t)return null;t=r}}var fe=new Map;function G(e){if(!I.existsSync(e))return null;let t=I.readFileSync(e,"utf8"),n=fe.get(e);if(n?.source===t)return n.config;let r=ce(t,e).config;return fe.set(e,{source:t,config:r}),r}function B(e,t){return(e.include??[]).some(r=>{let s=String(r).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!te(t,e)}function ge(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,p.join(e,"index.ts"),p.join(e,"index.tsx"),p.join(e,"index.js")];for(let n of t)try{if(I.existsSync(n)&&I.statSync(n).isFile())return n}catch{}return null}function Ke(e){let t=p.resolve(e),n=null;for(;;){let f=p.join(t,"tsconfig.json");if(I.existsSync(f)){n=f;break}let d=p.dirname(t);if(d===t)break;t=d}if(!n)return{baseUrl:e,aliases:[]};let r=f=>{try{let d=I.readFileSync(f,"utf8");return d=d.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(d)}catch{return null}},s=(f,d)=>{if(d>4)return{};let o=r(f);if(!o)return{};let l=o.compilerOptions??{},u=l.baseUrl,m=l.paths,y=o.extends;if(typeof y=="string"&&!y.startsWith("@")){let b=p.resolve(p.dirname(f),y.endsWith(".json")?y:`${y}.json`);if(I.existsSync(b)){let A=s(b,d+1);u=u??A.baseUrl,m={...A.paths??{},...m??{}}}}return{baseUrl:u,paths:m}},i=s(n,0),a=p.dirname(n),c=p.resolve(a,i.baseUrl||"."),g=[];for(let[f,d]of Object.entries(i.paths||{})){if(!Array.isArray(d)||d.length===0)continue;let o=f.replace(/\*$/,"");o&&g.push({from:o,to:String(d[0]).replace(/\*$/,"")})}return g.sort((f,d)=>d.from.length-f.from.length),{baseUrl:c,aliases:g}}function He(e,t){if(!t.startsWith("."))return null;let n=p.resolve(p.dirname(e),t);return ge(n)}function Ge(e,t,n){if(!t)return null;if(t.startsWith("."))return He(e,t);let r=n||p.dirname(e),{baseUrl:s,aliases:i}=Ke(r),a=i.find(g=>t.startsWith(g.from));if(!a)return null;let c=p.resolve(s,`${a.to}${t.slice(a.from.length)}`);return ge(c)}function $(e){return typeof e?.value=="string"?e.value:void 0}function U(e){return e?.name??$(e)}function q(e){return e.sourceCode??e.getSourceCode?.()}function me(e,t){let n=q(e)?.getScope?.(t);for(;n;){let r=n.references?.find(s=>s.identifier===t);if(r)return r;n=n.upper??void 0}}function _(e,t,n){let r=me(e,t);if(r?.resolved)return(r.resolved.defs?.length??0)>0;let s=q(e)?.getScope?.(t);for(;s;){let i=s.set?.get(n);if(i)return(i.defs?.length??0)>0;s=s.upper??void 0}return!1}function Be(e,t){let n=me(e,t);return n?n.isValueReference!==!1:t.parent?.type==="VariableDeclarator"&&t.parent.init===t}function ye(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 n=ye(e.object),r=U(e.property);if(!(!n||!r))return{root:n.root,segments:[...n.segments,r]}}function Ue(e){return U(e.callee?.property)}function he(e,t){return e?.properties?.find(n=>U(n.key)===t)}function P(e,t){return he(e,t)!==void 0}function qe(e){let t=he(e,"metadata")?.value;return P(t,"source")}function be(e){return Ue(e)==="publish"}function F(e){if(e.importKind==="type"||e.exportKind==="type")return!0;let t=e.specifiers??[];return t.length===0?!1:t.every(n=>n.type==="ImportSpecifier")?t.every(n=>n.importKind==="type"):t.every(n=>n.exportKind==="type")}function We(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}function Ye(e){let t=We(e)?.body;if(!t)return!1;let n=!1;for(let r of t){if(r.type==="ImportDeclaration"){if(!F(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(!F(r))return!1;n=!0;continue}return!1}}return n}var Je={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=C(e),n=H(t),r=n?G(n):null,s=n?p.dirname(n):null,i=a=>{let c=$(a.source);if(c&&r&&s&&t){let g=p.isAbsolute(t)?t:p.resolve(t),f=p.relative(s,g).split(p.sep).join("/");if(!B(r,f))return;let d=w(f,r.layers);if(!d)return;let o=Ge(g,c,s);if(!o)return;let l=p.relative(s,o).split(p.sep).join("/");if(l.startsWith(".."))return;let u=w(l,r.layers);if(!u)return;let m={fromPath:f,toPath:l,layers:r.layers},y=v(r.rules,d,u,m);if(y||ee(r.rules,d,u,m)){let b=a.type?.startsWith("Export")?"export":"import",A=F(a),W=!!y?.peerIsolation,Y=A&&!W,J=y?.message??`${d} must not ${b} ${u}.`;x(e,a,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:f,fromLayer:d,toLayer:u,target:l,edgeKind:b,...W?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...Y?{severity:"warning"}:{},...Ye(a)?{sourcePureTypeModule:!0}:{},message:Y?`${J} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:J},{fromLayer:d,toLayer:u,specifier:c})}return}};return{ImportDeclaration:i,ExportNamedDeclaration:i,ExportAllDeclaration:i}}},ze={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],r=$(n),s=V({publishCall:be(t),rawIntentName:r,objectHasIntent:P(n,"intent"),arkPublishCandidate:!1,hasSource:!0});if(s.some(i=>i.ruleId==="RAW_EVENT_PUBLISH")){let i=s.find(a=>a.ruleId==="RAW_EVENT_PUBLISH");x(e,t,"rawPublish",{...i,file:C(e)})}}}}},Ze={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 n=t.arguments?.[0],r=t.arguments?.[2],i=V({publishCall:be(t),rawIntentName:$(n),objectHasIntent:P(n,"intent"),arkPublishCandidate:!0,hasSource:qe(n)||P(r,"source")}).find(a=>a.ruleId==="PUBLISH_MISSING_SOURCE");i&&x(e,t,"missingSource",{...i,file:C(e)})}}}},Xe={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=C(e),n=e.options?.[0],r=H(t),s=r?G(r):null,i=r?p.dirname(r):null,a=null,c="this layer";if(s&&i&&t){let o=p.isAbsolute(t)?t:p.resolve(t),l=p.relative(i,o).split(p.sep).join("/");if(!B(s,l))return{};let u=s.layers?.find(m=>m.name===w(l,s.layers));u?.forbiddenGlobals?.length?(a=new Set(u.forbiddenGlobals),c=u.name):a=null}else n?.globals&&(a=new Set(n.globals));if(!a)return{};let g=typeof q(e)?.getScope=="function",f=(o,l)=>{let u=p.isAbsolute(t)?t:p.resolve(t),m=i?p.relative(i,u).split(p.sep).join("/"):t;x(e,o,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:m,fromLayer:c,target:l,message:`${c} must not use the ambient global "${l}".`},{name:l,layer:c})},d=(o,l,u,m)=>{if(u||typeof l!="string")return;let y=j(l,a);if(!y)return;let b=p.isAbsolute(t)?t:p.resolve(t),A=i?p.relative(i,b).split(p.sep).join("/"):t;x(e,o,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:A,fromLayer:c,target:l,edgeKind:m,message:`${c} must not use module "${l}" because it is the import form of forbidden global "${y}".`},{layer:c,name:y,specifier:l,importKind:m})};return{MemberExpression(o){if(o.parent?.type==="MemberExpression"&&o.parent.object===o)return;let l=ye(o);if(!l||_(e,l.root,l.segments[0]))return;let u=l.segments[0]==="globalThis",m=u?l.segments.slice(1):l.segments,y;for(let b=m.length;b>=(u?1:2);b-=1){let A=m.slice(0,b).join(".");if(a.has(A)){y=A;break}}y?f(o,y):!g&&a.has(l.segments[0])&&f(o,l.segments[0])},CallExpression(o){let l=o;if(l.callee?.type==="Identifier"&&l.callee.name==="require"&&l.arguments?.[0]?.type==="Literal"&&!_(e,o,"require")&&d(o,l.arguments[0].value,!1,"require"),g)return;let u=l.callee?.type==="Identifier"?l.callee.name:void 0;u&&a.has(u)&&f(o,u)},ImportDeclaration(o){let l=o,u=(l.specifiers??[]).filter(y=>y.type==="ImportSpecifier"),m=u.length>0&&u.length===(l.specifiers??[]).length&&u.every(y=>y.importKind==="type");d(o,l.source?.value,l.importKind==="type"||m,"import")},ImportExpression(o){let l=o;l.source?.type==="Literal"&&d(o,l.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(o){let l=o;d(o,l.moduleReference?.expression?.value,l.importKind==="type"||l.isTypeOnly===!0,"require")},ExportNamedDeclaration(o){let l=o;if(!l.source)return;let u=l.specifiers??[],m=u.length>0&&u.every(y=>y.exportKind==="type");d(o,l.source.value,l.exportKind==="type"||m,"export")},ExportAllDeclaration(o){let l=o;d(o,l.source?.value,l.exportKind==="type","export")},NewExpression(o){if(g)return;let l=o.callee?.type==="Identifier"?o.callee.name:void 0;l&&a.has(l)&&f(o,l)},Identifier(o){!g||!o.name||!a.has(o.name)||!Be(e,o)||_(e,o,o.name)||f(o,o.name)}}}},Qe={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=C(e),n=H(t),r=n?G(n):null,s=n?p.dirname(n):null;if(!r||!s||!t)return{};let i=p.isAbsolute(t)?t:p.resolve(t),a=p.relative(s,i).split(p.sep).join("/");if(!B(r,a))return{};let c=r.layers?.find(d=>d.name===w(a,r.layers));if(!c)return{};let g=new Set(se(c));if(g.size===0)return{};let f=(d,o,l,u)=>{if(l||typeof o!="string"||j(o,c.forbiddenGlobals??[]))return;let m=re(o);!m||!g.has(m)||x(e,d,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:a,fromLayer:c.name,target:o,capability:m,edgeKind:u,message:`${c.name} denies the ${m} capability; found import of "${o}".`},{layer:c.name,capability:m,specifier:o})};return{ImportDeclaration(d){let o=d,l=(o.specifiers??[]).filter(m=>m.type==="ImportSpecifier"),u=l.length>0&&l.length===(o.specifiers??[]).length&&l.every(m=>m.importKind==="type");f(d,o.source?.value,o.importKind==="type"||u,"import")},ImportExpression(d){let o=d;o.source?.type==="Literal"&&f(d,o.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(d){let o=d;f(d,o.moduleReference?.expression?.value,o.importKind==="type"||o.isTypeOnly===!0,"require")},ExportNamedDeclaration(d){let o=d;if(!o.source)return;let l=o.specifiers??[],u=l.length>0&&l.every(m=>m.exportKind==="type");f(d,o.source.value,o.exportKind==="type"||u,"export")},ExportAllDeclaration(d){let o=d;f(d,o.source?.value,o.exportKind==="type","export")},CallExpression(d){let o=d;o.callee?.type==="Identifier"&&o.callee.name==="require"&&o.arguments?.[0]?.type==="Literal"&&!_(e,d,"require")&&f(d,o.arguments[0].value,!1,"require")}}}},et={"no-domain-infra-imports":Je,"no-raw-event-publish":ze,"require-publish-source":Ze,"no-forbidden-globals":Xe,"no-denied-capabilities":Qe},K={rules:et};K.configs={recommended:{plugins:{ark:K},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"}}};var mt=K;export{mt as default,H as findConfigPath,L as globToRegExp,ee as isEdgeDenied,w as layerForRelativePath,G as loadArkConfig,Qe as noDeniedCapabilities,Je as noDomainInfraImports,Xe as noForbiddenGlobals,ze as noRawEventPublish,Q as patternSpecificity,K as plugin,Ke as readTsconfigPathAliases,Ze as requirePublishSource,Ge as resolveImportSpecifier,He as resolveRelativeImport};
1
+ import R from"fs";import p from"path";var J=new Map;function X(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}function N(e){let t="";for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="\\"&&r+1<e.length){let s=e[r+1];if("*?{}[],".includes(s)||s==="\\"){t+="\\"+s,r+=1;continue}t+="/";continue}t+=n}return t}function Ie(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}function w(e){let t=J.get(e);if(t)return t;let r=N(e),n=Ie(r),s="",o=0;for(let c=0;c<r.length;c+=1){let g=r[c];g==="\\"&&c+1<r.length?(s+=X(r[c+1]),c+=1):g==="*"?r[c+1]==="*"?r[c+2]==="/"?(s+="(?:.*/)?",c+=2):(s+=".*",c+=1):s+="[^/]*":g==="?"?s+="[^/]":g==="{"&&n?(s+="(?:",o+=1):g==="}"&&n&&o>0?(s+=")",o-=1):g===","&&n&&o>0?s+="|":s+=X(g)}let a=new RegExp(`^${s}$`);return J.set(e,a),a}function ke(e){return N(String(e)).split("/").filter(Boolean).filter(r=>r!=="**"&&r!=="*"&&!r.includes("*")&&!r.includes("?")&&!r.includes("{")&&!r.includes("["))}function Q(e,t){let r=N(String(e)),n=ke(r),s=r.replace(/\*/g,"").length,o=n.length*1e4+s;if(t==null||t==="")return o;let a=String(t).split(/[/\\]/).filter(Boolean);if(n.length===0)return s;let c=0,g=-1;for(let f of n){let d=-1;for(let i=c;i<a.length;i+=1)if(a[i]===f){d=i;break}if(d<0)return o;g=d,c=d+1}return(g+1)*1e6+n.length*1e4+s}function E(e,t){let r=String(e).split(/[/\\]/).join("/"),n,s=-1;for(let o of t??[])if(!(o.exclude??[]).some(a=>w(a).test(r))){for(let a of o.patterns??[])if(w(a).test(r)){let c=Q(a,r);c>s&&(s=c,n=o.name)}}return n}function Z(e,t){if(!t?.length)return;let r=String(e).split(/[/\\]/).filter(Boolean),n=new Set(t.map(s=>String(s).toLowerCase()));for(let s=0;s<r.length-1;s+=1)if(n.has(r[s].toLowerCase()))return`${r[s].toLowerCase()}/${r[s+1].toLowerCase()}`}function Re(e){let t=new Set;for(let r of e??[]){let s=N(String(r)).split("/").filter(Boolean);for(let o=0;o<s.length;o+=1){let a=s[o];if((a==="**"||a==="*")&&o>0){let c=s[o-1];c&&!c.includes("*")&&!c.includes("{")&&!c.includes("}")&&t.add(c)}}}return[...t]}function Se(e,t,r){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(s=>typeof s=="string"&&s.length>0);let n=(r??[]).find(s=>s.name===t);return Re(n?.patterns)}function xe(e){return!e.fromPath||!e.toPath||e.folderCount<=0||!e.fromSlice||!e.toSlice?!0:e.fromSlice!==e.toSlice}function $(e,t,r,n){for(let s of e??[])if(!(s.from!==t||s.to!==r)&&s.allowed===!1){if(s.peerIsolation){let o=n?.fromPath,a=n?.toPath,c=Se(s,t,n?.layers),g=o&&a?Z(o,c):void 0,f=o&&a?Z(a,c):void 0;if(xe({fromPath:o,toPath:a,folderCount:c.length,fromSlice:g,toSlice:f}))return s;continue}if(t!==r)return s}}function ee(e,t,r,n){return $(e,t,r,n)!==void 0}var Ee=["**/*.gen.ts","**/*.gen.tsx","**/*.generated.ts","**/*.generated.tsx"];function Le(e){let t=Array.isArray(e?.exclude)?e.exclude.filter(n=>typeof n=="string"):[];return[...e?.excludeGenerated===!1?[]:Ee,...t]}function te(e,t){let r=String(e).split(/[/\\]/).join("/");return Le(t).some(n=>w(n).test(r))}var re=Object.freeze(["network","filesystem","clock","randomness","environment","process","persistence"]),Ce=Object.freeze({fetch:"network",XMLHttpRequest:"network",Date:"clock","Date.now":"clock","Math.random":"randomness","process.env":"environment",process:"process"}),at=Object.freeze(Object.keys(Ce).sort()),j=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"}),we=Object.freeze({process:Object.freeze(["process","node:process"])});function ne(e){if(!e||e.startsWith(".")||e.startsWith("/"))return null;let t=j[e];if(t)return t;let r=e.indexOf("/");if(r<0)return null;let n=e.slice(0,r),s=j[n];if(s)return s;let o=e.indexOf("/",r+1);return o<0?null:j[e.slice(0,o)]??null}function D(e,t){for(let r of t)if(we[r]?.includes(e))return r;return null}function se(e){if(e?.pure===!0)return[...re].sort();let r=(e?.capabilities?.deny??[]).filter(n=>re.includes(n));return[...new Set(r)].sort()}var v="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",ie=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],Ne=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function Oe(){let e=[];for(let t of ie)for(let r of ie)t===r||Ne.has(`${t}->${r}`)||e.push({from:t,to:r,allowed:!1});return e}var ae=Oe(),V=[{from:"unversioned",to:"1.0"},{from:"1.0",to:"1.1"}],I={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},oe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:v,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:v,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:"1.1",default:"1.1"},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:ae,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:{}},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}}}}},k=class extends Error{issues;source;constructor(t,r){super(`Invalid ArkGate config (${t}):
2
+ ${r.map(n=>`- ${n.path}: ${n.message}`).join(`
3
+ `)}`),this.name="ArkConfigValidationError",this.source=t,this.issues=r}};function le(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function O(e,t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}function S(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function _e(e,t){let r="#/$defs/";if(e.startsWith(r))return t.$defs[e.slice(r.length)]}function L(e,t,r,n,s){if(t.$ref){let o=_e(t.$ref,n);if(!o){s.push({path:r,message:`schema reference ${t.$ref} cannot be resolved`});return}L(e,o,r,n,s);return}if(t.const!==void 0&&!Object.is(e,t.const)){s.push({path:r,message:`must equal ${JSON.stringify(t.const)}`});return}if(t.enum&&!t.enum.some(o=>Object.is(o,e))){s.push({path:r,message:`must be one of ${t.enum.map(String).join(", ")}`});return}if(t.type==="object"){if(!le(e)){s.push({path:r,message:`must be an object; received ${S(e)}`});return}let o=t.properties??{};for(let a of t.required??[])e[a]===void 0&&s.push({path:O(r,a),message:"is required"});if(t.additionalProperties===!1)for(let a of Object.keys(e))a in o||s.push({path:O(r,a),message:"unknown field"});else if(t.additionalProperties!==void 0&&t.additionalProperties!==!0&&typeof t.additionalProperties=="object"){let a=t.additionalProperties;for(let c of Object.keys(e))c in o||L(e[c],a,O(r,c),n,s)}for(let[a,c]of Object.entries(o))e[a]!==void 0&&L(e[a],c,O(r,a),n,s);return}if(t.type==="array"){if(!Array.isArray(e)){s.push({path:r,message:`must be an array; received ${S(e)}`});return}if(t.minItems!==void 0&&e.length<t.minItems&&s.push({path:r,message:`must contain at least ${t.minItems} item(s)`}),t.uniqueItems){let o=e.map(a=>JSON.stringify(a));new Set(o).size!==o.length&&s.push({path:r,message:"must not contain duplicate items"})}t.items&&e.forEach((o,a)=>L(o,t.items,`${r}[${a}]`,n,s));return}if(t.type==="string"){if(typeof e!="string"){s.push({path:r,message:`must be a string; received ${S(e)}`});return}t.minLength!==void 0&&e.length<t.minLength&&s.push({path:r,message:`must contain at least ${t.minLength} character(s)`});return}if(t.type==="boolean"){typeof e!="boolean"&&s.push({path:r,message:`must be a boolean; received ${S(e)}`});return}if(t.type==="integer"){if(!Number.isInteger(e)){s.push({path:r,message:`must be an integer; received ${S(e)}`});return}t.minimum!==void 0&&e<t.minimum&&s.push({path:r,message:`must be at least ${t.minimum}`})}}function Te(e){return{...e,$schema:e.$schema===void 0?v:e.$schema,schemaVersion:e.schemaVersion===void 0?"1.1":e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?ae.map(t=>({...t})):e.rules}}function Pe(){let e=new Set(["1.1"]);for(let t of V)t.from!=="unversioned"&&e.add(t.from),e.add(t.to);return e}function $e(e,t="ark.config.json"){if(!le(e))throw new k(t,[{path:"$",message:`must be an object; received ${S(e)}`}]);let r=Pe(),n=e.schemaVersion===void 0?"unversioned":typeof e.schemaVersion=="string"?e.schemaVersion:null;if(n===null)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected 1.1`}]);if(n!=="unversioned"&&!r.has(n))throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected 1.1`}]);let s=n,o={...e},a=0;for(;s!=="1.1"&&a<V.length+1;){a+=1;let g=V.find(f=>f.from===s);if(!g)throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(s)}; expected 1.1`}]);s=g.to,o.schemaVersion=s}if(s!=="1.1")throw new k(t,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(n)}; expected 1.1`}]);let c=n==="unversioned"?"unversioned":n==="1.0"?"1.0":null;return{candidate:Te(o),migratedFrom:c}}function je(e,t="ark.config.json"){let{candidate:r,migratedFrom:n}=$e(e,t),s=[];if(L(r,oe,"$",oe,s),s.length>0)throw new k(t,s);return{config:r,migratedFrom:n}}function ce(e,t="ark.config.json"){let r;try{r=JSON.parse(e)}catch(n){throw new k(t,[{path:"$",message:`invalid JSON: ${n instanceof Error?n.message:String(n)}`}])}return je(r,t)}var De=/(^|\/)(constants|types|enums|shared-types|shared\/(?:types|constants)|test-projects)(\/|\.|$)|(?:^|\/)[^/]*(?:constants|types)(?:\.[cm]?[jt]sx?)?$/i,ve=/(^|\/)(?:kernel(?:\/|$)|events?(?:\/|\.|$)|bootstrap(?:\.[cm]?[jt]sx?)?$|emitter(?:\.[cm]?[jt]sx?)?$)|(?:^|\/)(?:intents?|publish)(?:\/|\.|$)/i,Ve=/(use-?cases?|usecases?|application|orchestrat|services?|handlers?)(\/|\.|$)/i;function Ke(e,t){let r=String(e??"").replace(/\\/g,"/").trim(),n=String(t?.fromLayer??""),s=String(t?.toLayer??"");return De.test(r)?"pure-shared":n==="PersistenceAdapters"&&(ve.test(r)||/events?|intents?|kernel|bootstrap/i.test(`${s} ${r}`))?"kernel-emit":Ve.test(r)||(n==="DomainModel"||n==="ApplicationOrchestration")&&s==="PersistenceAdapters"?"use-case":"unknown"}function de(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=Ke(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."}var Me="docs/diagnostics.md";function y(e){return typeof e=="string"&&e.length>0?e:void 0}function pe(e,t){return Number.isInteger(e)&&Number(e)>0?Number(e):t}function He(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,s=typeof e.toLayer=="string"?e.toLayer:void 0,o=typeof e.target=="string"?e.target:void 0;return[t,r,n??"",s??"",o??""].join("|")}function Fe(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")}`}function Ue(e){return`${Me}#${e}`}function Be(e,t,r){if(e==="LAYER_IMPORT_VIOLATION")return de({ruleId:e,typeOnly:t.typeOnly===!0,targetTypeOnlyExports:r.targetTypeOnlyExports===!0,namedBindingsTypeOnly:r.namedBindingsTypeOnly===!0,peerIsolation:r.peerIsolation===!0,portProofEligible:r.portProofEligible===!0,fromLayer:y(t.fromLayer)??void 0,toLayer:y(t.toLayer)??void 0,target:y(t.target)??y(r.target)??void 0});if(e==="FORBIDDEN_GLOBAL")return`Inject ${t.target??"the capability"} through a port, test at the public interface, then preflight again.`;if(e==="CAPABILITY_VIOLATION")return`Define a ${y(r.capability)??"capability"} port in ${t.fromLayer??"the walled layer"}, bind the implementation outside it, test at the public interface, then preflight again.`;if(e==="CIRCULAR_DEPENDENCY")return"Extract the shared dependency into a third module, test at the public interface, then preflight again.";if(e==="RAW_EVENT_PUBLISH")return"Publish through a registered intent creator, then run Ark again.";if(e==="PUBLISH_MISSING_SOURCE")return"Add metadata.source to the publish call, then run Ark again.";if(e==="ARKRULE_STRUCTURE"||e==="ARKRULE_INVARIANT"||e==="INVARIANT_UNCOVERED"||e.startsWith("ARKRULE_")){let n=t.arkruleSource??"arkrules/<Layer>.json";return`Fix the structure or invariant for ${t.arkruleId??"the ArkRule"} (declared in ${n}), then preflight again. Do not demote the rule without a hash-bound policy acknowledgement.`}return`Resolve ${e} without weakening ark.config.json, then run Ark again.`}function ue(e,t="error",r){let n=y(e.ruleId)??y(e.code)??"ARK_UNKNOWN",s=e.severity==="warning"||e.failsStrict===!1||e.typeOnly===!0&&e.peerIsolation!==!0?"warning":t,o={...y(e.target)?{target:y(e.target)}:{},...y(e.fromLayer)?{fromLayer:y(e.fromLayer)}:{},...y(e.toLayer)?{toLayer:y(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}:{},...y(e.capability)?{capability:y(e.capability)}:{},...y(e.edgeKind)?{edgeKind:y(e.edgeKind)}:{},...y(e.arkruleId)?{arkruleId:y(e.arkruleId)}:{},...y(e.arkruleSource)?{arkruleSource:y(e.arkruleSource)}:{}},a=r??He(e),c=Fe(a);return{ruleId:n,severity:s,message:y(e.message)??n,location:{file:y(e.file)??"<unknown>",line:pe(e.line,1),column:pe(e.column,1)},evidence:o,nextAction:y(e.nextAction)??Be(n,o,e),findingRef:c,targetKey:a,docsCodePath:Ue(n)}}var fe={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."},ft=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 Ge(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}function K(e){if(!e.publishCall)return[];let t=[];return(e.rawIntentName!==void 0&&Ge(e.rawIntentName)||e.objectHasIntent)&&t.push({ruleId:"RAW_EVENT_PUBLISH",message:fe.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&t.push({ruleId:"PUBLISH_MISSING_SOURCE",message:fe.PUBLISH_MISSING_SOURCE}),t}function C(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""}function x(e,t,r,n,s){let o=ue({...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,...s?{data:s}:{},diagnostic:o}),o}function F(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let t=p.dirname(p.resolve(e));for(;;){let r=p.join(t,"ark.config.json");if(R.existsSync(r))return r;let n=p.dirname(t);if(n===t)return null;t=n}}var ge=new Map;function U(e){if(!R.existsSync(e))return null;let t=R.readFileSync(e,"utf8"),r=ge.get(e);if(r?.source===t)return r.config;let n=ce(t,e).config;return ge.set(e,{source:t,config:n}),n}function B(e,t){return(e.include??[]).some(n=>{let s=String(n).replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"");return s==="."||t===s||t.startsWith(`${s}/`)})&&!te(t,e)}function me(e){let t=[e,`${e}.ts`,`${e}.tsx`,`${e}.mts`,`${e}.cts`,`${e}.js`,`${e}.jsx`,p.join(e,"index.ts"),p.join(e,"index.tsx"),p.join(e,"index.js")];for(let r of t)try{if(R.existsSync(r)&&R.statSync(r).isFile())return r}catch{}return null}function qe(e){let t=p.resolve(e),r=null;for(;;){let f=p.join(t,"tsconfig.json");if(R.existsSync(f)){r=f;break}let d=p.dirname(t);if(d===t)break;t=d}if(!r)return{baseUrl:e,aliases:[]};let n=f=>{try{let d=R.readFileSync(f,"utf8");return d=d.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),JSON.parse(d)}catch{return null}},s=(f,d)=>{if(d>4)return{};let i=n(f);if(!i)return{};let l=i.compilerOptions??{},u=l.baseUrl,m=l.paths,h=i.extends;if(typeof h=="string"&&!h.startsWith("@")){let b=p.resolve(p.dirname(f),h.endsWith(".json")?h:`${h}.json`);if(R.existsSync(b)){let A=s(b,d+1);u=u??A.baseUrl,m={...A.paths??{},...m??{}}}}return{baseUrl:u,paths:m}},o=s(r,0),a=p.dirname(r),c=p.resolve(a,o.baseUrl||"."),g=[];for(let[f,d]of Object.entries(o.paths||{})){if(!Array.isArray(d)||d.length===0)continue;let i=f.replace(/\*$/,"");i&&g.push({from:i,to:String(d[0]).replace(/\*$/,"")})}return g.sort((f,d)=>d.from.length-f.from.length),{baseUrl:c,aliases:g}}function We(e,t){if(!t.startsWith("."))return null;let r=p.resolve(p.dirname(e),t);return me(r)}function Ye(e,t,r){if(!t)return null;if(t.startsWith("."))return We(e,t);let n=r||p.dirname(e),{baseUrl:s,aliases:o}=qe(n),a=o.find(g=>t.startsWith(g.from));if(!a)return null;let c=p.resolve(s,`${a.to}${t.slice(a.from.length)}`);return me(c)}function P(e){return typeof e?.value=="string"?e.value:void 0}function G(e){return e?.name??P(e)}function q(e){return e.sourceCode??e.getSourceCode?.()}function ye(e,t){let r=q(e)?.getScope?.(t);for(;r;){let n=r.references?.find(s=>s.identifier===t);if(n)return n;r=r.upper??void 0}}function _(e,t,r){let n=ye(e,t);if(n?.resolved)return(n.resolved.defs?.length??0)>0;let s=q(e)?.getScope?.(t);for(;s;){let o=s.set?.get(r);if(o)return(o.defs?.length??0)>0;s=s.upper??void 0}return!1}function ze(e,t){let r=ye(e,t);return r?r.isValueReference!==!1:t.parent?.type==="VariableDeclarator"&&t.parent.init===t}function he(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=he(e.object),n=G(e.property);if(!(!r||!n))return{root:r.root,segments:[...r.segments,n]}}function Je(e){return G(e.callee?.property)}function be(e,t){return e?.properties?.find(r=>G(r.key)===t)}function T(e,t){return be(e,t)!==void 0}function Xe(e){let t=be(e,"metadata")?.value;return T(t,"source")}function Ae(e){return Je(e)==="publish"}function M(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")}function Ze(e){let t=e;for(;t?.parent;)t=t.parent;return t?.type==="Program"?t:void 0}function Qe(e){let t=Ze(e)?.body;if(!t)return!1;let r=!1;for(let n of t){if(n.type==="ImportDeclaration"){if(!M(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(!M(n))return!1;r=!0;continue}return!1}}return r}var et={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=C(e),r=F(t),n=r?U(r):null,s=r?p.dirname(r):null,o=a=>{let c=P(a.source);if(c&&n&&s&&t){let g=p.isAbsolute(t)?t:p.resolve(t),f=p.relative(s,g).split(p.sep).join("/");if(!B(n,f))return;let d=E(f,n.layers);if(!d)return;let i=Ye(g,c,s);if(!i)return;let l=p.relative(s,i).split(p.sep).join("/");if(l.startsWith(".."))return;let u=E(l,n.layers);if(!u)return;let m={fromPath:f,toPath:l,layers:n.layers},h=$(n.rules,d,u,m);if(h||ee(n.rules,d,u,m)){let b=a.type?.startsWith("Export")?"export":"import",A=M(a),W=!!h?.peerIsolation,Y=A&&!W,z=h?.message??`${d} must not ${b} ${u}.`;x(e,a,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:f,fromLayer:d,toLayer:u,target:l,edgeKind:b,...W?{peerIsolation:!0}:{},...A?{typeOnly:!0}:{},...Y?{severity:"warning"}:{},...Qe(a)?{sourcePureTypeModule:!0}:{},message:Y?`${z} (type-only \u2014 type placement debt; prefer SharedTypes / owning layer; not runtime coupling)`:z},{fromLayer:d,toLayer:u,specifier:c})}return}};return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},tt={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=P(r),s=K({publishCall:Ae(t),rawIntentName:n,objectHasIntent:T(r,"intent"),arkPublishCandidate:!1,hasSource:!0});if(s.some(o=>o.ruleId==="RAW_EVENT_PUBLISH")){let o=s.find(a=>a.ruleId==="RAW_EVENT_PUBLISH");x(e,t,"rawPublish",{...o,file:C(e)})}}}}},rt={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],o=K({publishCall:Ae(t),rawIntentName:P(r),objectHasIntent:T(r,"intent"),arkPublishCandidate:!0,hasSource:Xe(r)||T(n,"source")}).find(a=>a.ruleId==="PUBLISH_MISSING_SOURCE");o&&x(e,t,"missingSource",{...o,file:C(e)})}}}},nt={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=C(e),r=e.options?.[0],n=F(t),s=n?U(n):null,o=n?p.dirname(n):null,a=null,c="this layer";if(s&&o&&t){let i=p.isAbsolute(t)?t:p.resolve(t),l=p.relative(o,i).split(p.sep).join("/");if(!B(s,l))return{};let u=s.layers?.find(m=>m.name===E(l,s.layers));u?.forbiddenGlobals?.length?(a=new Set(u.forbiddenGlobals),c=u.name):a=null}else r?.globals&&(a=new Set(r.globals));if(!a)return{};let g=typeof q(e)?.getScope=="function",f=(i,l)=>{let u=p.isAbsolute(t)?t:p.resolve(t),m=o?p.relative(o,u).split(p.sep).join("/"):t;x(e,i,s?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:m,fromLayer:c,target:l,message:`${c} must not use the ambient global "${l}".`},{name:l,layer:c})},d=(i,l,u,m)=>{if(u||typeof l!="string")return;let h=D(l,a);if(!h)return;let b=p.isAbsolute(t)?t:p.resolve(t),A=o?p.relative(o,b).split(p.sep).join("/"):t;x(e,i,"forbiddenModule",{ruleId:"FORBIDDEN_GLOBAL",file:A,fromLayer:c,target:l,edgeKind:m,message:`${c} must not use module "${l}" because it is the import form of forbidden global "${h}".`},{layer:c,name:h,specifier:l,importKind:m})};return{MemberExpression(i){if(i.parent?.type==="MemberExpression"&&i.parent.object===i)return;let l=he(i);if(!l||_(e,l.root,l.segments[0]))return;let u=l.segments[0]==="globalThis",m=u?l.segments.slice(1):l.segments,h;for(let b=m.length;b>=(u?1:2);b-=1){let A=m.slice(0,b).join(".");if(a.has(A)){h=A;break}}h?f(i,h):!g&&a.has(l.segments[0])&&f(i,l.segments[0])},CallExpression(i){let l=i;if(l.callee?.type==="Identifier"&&l.callee.name==="require"&&l.arguments?.[0]?.type==="Literal"&&!_(e,i,"require")&&d(i,l.arguments[0].value,!1,"require"),g)return;let u=l.callee?.type==="Identifier"?l.callee.name:void 0;u&&a.has(u)&&f(i,u)},ImportDeclaration(i){let l=i,u=(l.specifiers??[]).filter(h=>h.type==="ImportSpecifier"),m=u.length>0&&u.length===(l.specifiers??[]).length&&u.every(h=>h.importKind==="type");d(i,l.source?.value,l.importKind==="type"||m,"import")},ImportExpression(i){let l=i;l.source?.type==="Literal"&&d(i,l.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(i){let l=i;d(i,l.moduleReference?.expression?.value,l.importKind==="type"||l.isTypeOnly===!0,"require")},ExportNamedDeclaration(i){let l=i;if(!l.source)return;let u=l.specifiers??[],m=u.length>0&&u.every(h=>h.exportKind==="type");d(i,l.source.value,l.exportKind==="type"||m,"export")},ExportAllDeclaration(i){let l=i;d(i,l.source?.value,l.exportKind==="type","export")},NewExpression(i){if(g)return;let l=i.callee?.type==="Identifier"?i.callee.name:void 0;l&&a.has(l)&&f(i,l)},Identifier(i){!g||!i.name||!a.has(i.name)||!ze(e,i)||_(e,i,i.name)||f(i,i.name)}}}},st={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=C(e),r=F(t),n=r?U(r):null,s=r?p.dirname(r):null;if(!n||!s||!t)return{};let o=p.isAbsolute(t)?t:p.resolve(t),a=p.relative(s,o).split(p.sep).join("/");if(!B(n,a))return{};let c=n.layers?.find(d=>d.name===E(a,n.layers));if(!c)return{};let g=new Set(se(c));if(g.size===0)return{};let f=(d,i,l,u)=>{if(l||typeof i!="string"||D(i,c.forbiddenGlobals??[]))return;let m=ne(i);!m||!g.has(m)||x(e,d,"deniedCapability",{ruleId:"CAPABILITY_VIOLATION",file:a,fromLayer:c.name,target:i,capability:m,edgeKind:u,message:`${c.name} denies the ${m} capability; found import of "${i}".`},{layer:c.name,capability:m,specifier:i})};return{ImportDeclaration(d){let i=d,l=(i.specifiers??[]).filter(m=>m.type==="ImportSpecifier"),u=l.length>0&&l.length===(i.specifiers??[]).length&&l.every(m=>m.importKind==="type");f(d,i.source?.value,i.importKind==="type"||u,"import")},ImportExpression(d){let i=d;i.source?.type==="Literal"&&f(d,i.source.value,!1,"dynamic-import")},TSImportEqualsDeclaration(d){let i=d;f(d,i.moduleReference?.expression?.value,i.importKind==="type"||i.isTypeOnly===!0,"require")},ExportNamedDeclaration(d){let i=d;if(!i.source)return;let l=i.specifiers??[],u=l.length>0&&l.every(m=>m.exportKind==="type");f(d,i.source.value,i.exportKind==="type"||u,"export")},ExportAllDeclaration(d){let i=d;f(d,i.source?.value,i.exportKind==="type","export")},CallExpression(d){let i=d;i.callee?.type==="Identifier"&&i.callee.name==="require"&&i.arguments?.[0]?.type==="Literal"&&!_(e,d,"require")&&f(d,i.arguments[0].value,!1,"require")}}}},it={"no-domain-infra-imports":et,"no-raw-event-publish":tt,"require-publish-source":rt,"no-forbidden-globals":nt,"no-denied-capabilities":st},H={rules:it};H.configs={recommended:{plugins:{ark:H},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"}}};var Rt=H;export{Rt as default,F as findConfigPath,w as globToRegExp,ee as isEdgeDenied,E as layerForRelativePath,U as loadArkConfig,st as noDeniedCapabilities,et as noDomainInfraImports,nt as noForbiddenGlobals,tt as noRawEventPublish,Q as patternSpecificity,H as plugin,qe as readTsconfigPathAliases,rt as requirePublishSource,Ye as resolveImportSpecifier,We as resolveRelativeImport};