#!/usr/bin/env node
import*as i from'fs';import*as u from'path';import*as f from'js-yaml';var s=["purpose-coverage","purpose-exists","portal-gates","aspect-anchors","purpose-freshness","aspect-advisory","lore-required","habits-blocking","purpose-required-patterns","drift-detection","portal-compliance","graduation-tracking","orchestration-required"];var A={"purpose-coverage":"block","purpose-exists":"block","portal-gates":"block","aspect-anchors":"block","purpose-freshness":"warn","aspect-advisory":"warn","lore-required":"block","habits-blocking":"block","purpose-required-patterns":"block","drift-detection":"block","portal-compliance":"block","graduation-tracking":"warn","orchestration-required":"block"},O={"purpose-coverage":"block","purpose-exists":"warn","portal-gates":"warn","aspect-anchors":"warn","purpose-freshness":"warn","aspect-advisory":"off","lore-required":"warn","habits-blocking":"block","purpose-required-patterns":"warn","drift-detection":"warn","portal-compliance":"warn","graduation-tracking":"off","orchestration-required":"warn"},P={"purpose-coverage":"warn","purpose-exists":"off","portal-gates":"off","aspect-anchors":"off","purpose-freshness":"off","aspect-advisory":"off","lore-required":"off","habits-blocking":"warn","purpose-required-patterns":"off","drift-detection":"off","portal-compliance":"off","graduation-tracking":"off","orchestration-required":"off"},x={strict:A,balanced:O,minimal:P};function p(e){return {...x[e]}}function V(e,t){return x[e][t]}function b(e){return s.includes(e)}function E(e){return e==="block"||e==="warn"||e==="off"}function S(e){return e==="strict"||e==="balanced"||e==="minimal"}var L="minimal",j={threshold:3,detection:"git-diff",exempt:["*.md","*.yaml","*.yml",".purpose"]};function T(e){let t=u.join(e,".paradigm","config.yaml");if(!i.existsSync(t))return h();try{let n=i.readFileSync(t,"utf8"),r=f.load(n);if(!r||typeof r!="object")return h();let o=r.enforcement;if(!o||typeof o!="object")return h();let y=o.level,q=typeof y=="string"&&S(y)?y:L,v=o.checks,w={};if(v&&typeof v=="object")for(let[d,C]of Object.entries(v))b(d)&&typeof C=="string"&&E(C)&&(w[d]=C);let c=o.orchestration,l={...j};return c&&typeof c=="object"&&(typeof c.threshold=="number"&&(l.threshold=c.threshold),typeof c.detection=="string"&&(l.detection=c.detection),Array.isArray(c.exempt)&&(l.exempt=c.exempt.filter(d=>typeof d=="string"))),{level:q,checks:w,orchestration:l}}catch{return h()}}function h(){return {level:L,checks:{},orchestration:{...j}}}function _(e,t){let n=e.checks[t];return n!==void 0?n:p(e.level)[t]}function D(e){let t=p(e.level);for(let n of s){let r=e.checks[n];r!==void 0&&(t[n]=r);}return t}function k(e){let t=u.join(e,".paradigm","config.yaml");if(!i.existsSync(t))throw new Error(`Config not found: ${t}`);let n=i.readFileSync(t,"utf8"),r=f.load(n);if(!r||typeof r!="object")throw new Error("Config is not a valid YAML object");return [r,n]}function a(e,t){let n=u.join(e,".paradigm","config.yaml"),r=f.dump(t,{lineWidth:-1,noRefs:true,sortKeys:false,quotingType:"'"});i.writeFileSync(n,r,"utf8");}function g(e){return (!e.enforcement||typeof e.enforcement!="object")&&(e.enforcement={level:"minimal",checks:{}}),e.enforcement}function F(e,t){let[n]=k(e),r=g(n);r.level=t,a(e,n);}function H(e,t,n){let[r]=k(e),o=g(r);(!o.checks||typeof o.checks!="object")&&(o.checks={}),o.checks[t]=n,a(e,r);}function K(e,t){let[n]=k(e),r=g(n);r.checks&&typeof r.checks=="object"&&delete r.checks[t],a(e,n);}function M(e){let[t]=k(e),n=g(t);n.checks={},a(e,t);}function N(e){let t=u.join(e,".paradigm","config.yaml");if(!i.existsSync(t))return  false;try{let n=i.readFileSync(t,"utf8"),r=f.load(n);return !r||typeof r!="object"||r.enforcement?!1:(r.enforcement={level:"balanced",checks:{},orchestration:{threshold:3,detection:"git-diff",exempt:["*.md","*.yaml","*.yml",".purpose"]}},a(e,r),!0)}catch{return  false}}export{s as a,p as b,V as c,b as d,E as e,S as f,T as g,_ as h,D as i,F as j,H as k,K as l,M as m,N as n};