@r5n/ariadne 0.5.0 → 0.5.1

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 (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -100,7 +100,7 @@ ${a}
100
100
  `))});return`${p?"[":"{"}${I}${A.join(G)}${C}${p?"]":"}"}`}function c(l,u,d){if(!d)return Fu(l,i);let p=t.lastIndexOf(`
101
101
  `,u-1)+1,g=t.slice(p,u).match(/^[\t ]*/)?.[0]??"";return JSON.stringify(l,null,o).replaceAll(`
102
102
  `,s+g)}return t.slice(0,r.start)+a(r,n)+t.slice(r.end)}function Fu(t,e){if(Array.isArray(t))return`[${t.map((o)=>Fu(o,e)).join(`,${e}`)}]`;if(t===null||typeof t!=="object")return JSON.stringify(t);let n=Object.entries(t);if(n.length===0)return"{}";let r=n.map(([o,s])=>`${JSON.stringify(o)}:${e}${Fu(s,e)}`);return`{${e}${r.join(`,${e}`)}${e}}`}function PR(t){let e=t.matchAll(/"(?:[^"\\]|\\.)*"|[^\s{}[\],:]+|[{}[\],:]/g),n=e.next().value;function r(){if(!n)throw Error("Unexpected end of JSON");let s=n;return n=e.next().value,s}function o(){let s=r(),i=[],a=s[0]==="{";if(!a&&s[0]!=="[")return{end:s.index+s[0].length,entries:i,start:s.index,value:JSON.parse(s[0])};let c=a?"}":"]";while(n&&n[0]!==c){let u=n.index,d=a?JSON.parse(r()[0]):String(i.length);if(a)r();if(i.push({key:d,node:o(),start:u}),n?.[0]===",")r()}let l=r().index+1;return{end:l,entries:i,start:s.index,value:JSON.parse(t.slice(s.index,l))}}return o()}var NR=2,Uu="ConfigError",DR=ws(Object);class Ku{loaded;configPath;defaultConfig;options;constructor(t,e,n={}){this.configPath=Hu.resolve(t),this.defaultConfig=e,this.options=n}get path(){return this.configPath}get failure(){return this.state().failure}get(t){return this.current()[t]}set(t,e){let n=this.writable();this.update((r)=>({...r,[t]:e})),n.config={...n.config,[t]:e}}delete(t){let e=this.writable();this.update((n)=>(delete n[t],n)),delete e.config[t]}exists(){return tn.existsSync(this.configPath)}getAll(){return structuredClone(this.current())}save(t){let e=this.writable();if(t)e.config={...t};this.update(()=>e.config)}state(){return this.loaded??=this.load(),this.loaded}current(){let{config:t,failure:e}=this.state();if(e)throw e;return t}writable(){let t=this.state();if(t.failure)throw t.failure;if(t.error)throw this.unreadable(t.error);return t}unreadable(t){return new m(`Cannot overwrite unreadable config at ${this.configPath}`,"Repair the file and try again",void 0,{cause:t,tag:Uu})}readStored(){try{let t=this.readConfigFile();if(t===void 0)return structuredClone(this.defaultConfig);return ks(structuredClone(this.defaultConfig),gh(t))}catch(t){throw this.unreadable(t)}}update(t){try{let e=this.savePath();ah(e,()=>this.write(e,t(this.readStored())))}catch(e){throw e instanceof m?e:this.saveFailure(e)}}savePath(){let t=this.exists()?tn.realpathSync(this.configPath):ph(this.configPath);return tn.mkdirSync(Hu.dirname(t),{recursive:!0}),t}write(t,e){let n=`${t}.${crypto.randomUUID()}.tmp`;try{let r=this.exists()?tn.statSync(this.configPath).mode:void 0,o=this.exists()?Gu(tn.readFileSync(this.configPath,"utf-8"),e):`${JSON.stringify(e,null,NR)}
103
- `;if(tn.writeFileSync(n,o,{flag:"wx",mode:r}),r!==void 0)tn.chmodSync(n,r);tn.renameSync(n,t)}finally{tn.rmSync(n,{force:!0})}}saveFailure(t){return new m(`Cannot save config at ${this.configPath}: ${mh(t)}`,`Check that ${Hu.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:t,tag:Uu})}load(){let{parse:t,strict:e}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=ks(structuredClone(this.defaultConfig),gh(n));return{config:t?t(r):r}}catch(n){if(e)return{config:structuredClone(this.defaultConfig),failure:this.loadFailure(n)};return bt.warn(w.yellow(`Config file corrupted at ${this.configPath}. Using defaults.`),{output:Ki()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(t){return new m(`Cannot read config at ${this.configPath}: ${mh(t)}`,"Repair the file and try again",void 0,{cause:t,tag:Uu})}readConfigFile(){try{return tn.readFileSync(this.configPath,"utf-8")}catch(t){if(t.code==="ENOENT")return;throw t}}}function gh(t){let e=JSON.parse(t);if(Array.isArray(e))throw Error("Config must be an object");return DR(e)}function mh(t){return t instanceof Error?t.message:String(t)}var ya="0.5.0";var E=Fi();var fh=new Map;function et(t,e){return e.some((n)=>jR(n).match(t))}function Bu(t){if(t.trim().length===0)return"is empty";if(t!==t.trim())return"has leading or trailing white space";if(t.includes("\x00"))return"contains a NUL character";if(t.startsWith("!"))return"must not be negated with a leading !";if(t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return"must be relative to the repository root";if(t.startsWith("./"))return"must not start with ./";if(t.split("/").includes(".."))return"must not contain a .. segment";return MR(t)}function wr(t){let e=Bu(t);if(e!==null)return e;if(t.endsWith("/"))return"ends with /, so it matches no file; use a pattern such as dir/**";return t.split("/").includes("")?"has an empty path segment, so it matches no file":null}function MR(t){let e=0,n=!1;for(let r=0;r<t.length;r++){let o=t[r];if(o==="\\"){if(r===t.length-1)return"ends with a lone backslash";r++;continue}if(n){n=o!=="]";continue}if(o==="[")n=!0;if(o==="{")e++;if(o==="}"){if(e===0)return"has an unmatched }";e--}}if(n)return"has an unclosed [";return e>0?"has an unclosed {":null}function jR(t){let e=fh.get(t);if(e)return e;let n=new Bun.Glob(t);return fh.set(t,n),n}class b extends Error{_tag="ValidationError"}var FR=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,GR=/^[A-Za-z_$][A-Za-z0-9_$]*$/,HR="must be lower-case letters and digits separated by single hyphens",UR=new Set(Object.getOwnPropertyNames(Object.prototype)),KR=X(),BR=ha(),ka=yr(),VR=no(rh()),WR=X().or(Bn());function At(t,e,n){try{return n()}catch(r){if(r instanceof b)throw new m(`Invalid ${t}: ${r.message}`,e);throw r}}function k(t,e){if(typeof e==="number")return`${t}[${e}]`;if(!GR.test(e))return`${t}[${JSON.stringify(e)}]`;return t.length===0?e:`${t}.${e}`}function T(t,e,n){let r=kh(t,e),o=Object.keys(r).find((s)=>!n.includes(s));if(o!==void 0)throw new b(`${e} has unknown key ${JSON.stringify(o)}; expected ${n.join(", ")}`);return r}function bn(t,e,n){return Object.entries(kh(t,e)).map(([r,o])=>{if(UR.has(r))throw new b(`${k(e,r)} uses a reserved name`);return[r,n(o,k(e,r),r)]})}function D(t,e,n){return t===void 0?e:n(t)}function lt(t,e,n){return t===void 0||t===null?e:n(t)}function ft(t,e,n){if(t===void 0||t===null)throw new b(`${e} is required`);return n(t,e)}function x(t,e){return En(KR,t,e,"must be a string")}function nt(t,e){let n=x(t,e);if(n.trim().length===0)throw new b(`${e} must not be empty`);return n}function Ct(t,e){return En(WR,t,e,"must be a string or null")}function je(t,e){let n=x(t,e);if(!FR.test(n))throw new b(`${e} ${HR}, got ${JSON.stringify(n)}`);return n}function $t(t,e){return En(BR,t,e,"must be true or false")}function Kt(t,e){let n=En(ka,t,e,"must be a positive integer");if(!Number.isInteger(n)||n<=0)throw new b(`${e} must be a positive integer`);return n}function ht(t,e){let n=En(ka,t,e,"must be a non-negative integer");if(!Number.isInteger(n)||n<0)throw new b(`${e} must be a non-negative integer`);return n}function Vn(t,e){let n=En(ka,t,e,"must be a positive number");if(!Number.isFinite(n)||n<=0)throw new b(`${e} must be a positive number`);return n}function Vu(t,e){let n=En(ka,t,e,"must be a number greater than 0 and at most 1");if(!(n>0&&n<=1))throw new b(`${e} must be a number greater than 0 and at most 1`);return n}function K(t,e,n){return En(oh(t),e,n,`must be one of ${t.join(", ")}`)}function L(t,e,n){return En(VR,t,e,"must be a list").map((o,s)=>n(o,k(e,s)))}function Dt(t,e){return L(t,e,x)}function wa(t,e){return L(t,e,(n,r)=>yh(n,r,Bu))}function hh(t,e){return L(t,e,(n,r)=>yh(n,r,wr))}function yh(t,e,n){let r=x(t,e),o=n(r);if(o!==null)throw new b(`${e} ${o}`);return r}function kh(t,e){if(typeof t!=="object"||t===null||Array.isArray(t))throw new b(`${e} must be an object`);return t}function En(t,e,n,r){try{return t(e)}catch{throw new b(`${n} ${r}`)}}var JR=["task","review"],Wu=["task"],Zt="{prompt}",vs="{model}",qR=["command","reviewCommand","model","modelFlag","env","inheritEnv","timeoutSeconds","roles"],YR=["default","stages","review"],XR=["agent","model"],zR=/^[A-Za-z_][A-Za-z0-9_]*$/,ZR=":",QR="-",Sa={default:null,review:null,stages:{}};function Sr(t){return t.roles??Wu}function Sh(t){let e=bn(t,"agents",tI);for(let[n]of e)je(n,"agent name");return Object.fromEntries(e)}function tI(t,e){let n=T(t,e,qR),r={command:wh(n.command,k(e,"command"))};if(n.reviewCommand!==void 0)r.reviewCommand=wh(n.reviewCommand,k(e,"reviewCommand"));if(n.model!==void 0)r.model=nt(n.model,k(e,"model"));if(n.modelFlag!==void 0)r.modelFlag=rI(n.modelFlag,k(e,"modelFlag"));if(n.env!==void 0)r.env=oI(n.env,k(e,"env"));if(n.inheritEnv!==void 0)r.inheritEnv=$t(n.inheritEnv,k(e,"inheritEnv"));if(r.inheritEnv===!0&&r.env!==void 0){let[o,s]=[k(e,"inheritEnv"),k(e,"env")];throw new b(`${o} and ${s} are alternatives; set only one of them`)}if(n.timeoutSeconds!==void 0)r.timeoutSeconds=Vn(n.timeoutSeconds,k(e,"timeoutSeconds"));if(n.roles!==void 0)r.roles=sI(n.roles,k(e,"roles"));return r}function vh(t){let e=T(t,"routing",YR);return{default:D(e.default,Sa.default,(n)=>Ss(n,"routing.default")),review:D(e.review,Sa.review,(n)=>Ss(n,"routing.review")),stages:Object.fromEntries(D(e.stages,[],(n)=>bn(n,"routing.stages",eI)))}}function Ss(t,e){if(t===null)return null;if(typeof t==="string")return nI(t,e);let n=T(t,e,XR),r=je(n.agent,k(e,"agent")),o=D(n.model,null,(s)=>nt(s,k(e,"model")));return{agent:r,model:o}}function eI(t,e){let n=Ss(t,e);if(n!==null)return n;throw new b(`${e} must name an agent; leave the stage out to use routing.default`)}function nI(t,e){let n=t.indexOf(ZR);if(n===-1)return{agent:je(t,e),model:null};let r=je(t.slice(0,n),`${e} (agent)`),o=nt(t.slice(n+1),`${e} (model)`);return{agent:r,model:o}}function bh(t){let{agents:e,review:n,routing:r}=t,o=[["routing.default",r.default,"task"],...Object.entries(r.stages).map(([s,i])=>[k("routing.stages",s),i,"task"]),["routing.review",r.review,"review"],["review.agent",n.agent===void 0?null:{agent:n.agent,model:null},"review"]];for(let[s,i,a]of o){if(i===null)continue;let c=e[i.agent];if(c===void 0)throw new b(`${s} names agent "${i.agent}", which agents does not define`);if(!Sr(c).includes(a))throw new b(`${s} names agent "${i.agent}", whose roles do not include "${a}"; add it to agents.${i.agent}.roles`)}}function wh(t,e){let n=L(t,e,nt);if(n.length===0)throw new b(`${e} must not be empty`);return n}function rI(t,e){let n=x(t,e);if(n.startsWith(QR)&&n.trim()===n&&n.length>1)return n;throw new b(`${e} must be an option such as "--model"`)}function oI(t,e){let n=L(t,e,(r,o)=>{let s=x(r,o);if(zR.test(s))return s;throw new b(`${o} must be an environment variable name, not a value`)});return Eh(n,e)}function sI(t,e){let n=Eh(L(t,e,(r,o)=>K(JR,r,o)),e);if(n.length===0)throw new b(`${e} must name at least one role`);return n}function Eh(t,e){let n=t.find((r,o)=>t.indexOf(r)!==o);if(n!==void 0)throw new b(`${e} repeats ${JSON.stringify(n)}`);return t}var iI=["GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_DIR","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_PREFIX","GIT_WORK_TREE"],Fe=Object.fromEntries(iI.map((t)=>[t,void 0]));var Ah={SIGHUP:129,SIGINT:130,SIGTERM:143},$h=Object.keys(Ah),Th={SIGHUP:()=>Ju("SIGHUP"),SIGINT:()=>Ju("SIGINT"),SIGTERM:()=>Ju("SIGTERM")},oo=[],qu={interrupted:!1};function Qt(t){if(oo.length===0)for(let e of $h)process.on(e,Th[e]);return oo.push(t),()=>{let e=oo.indexOf(t);if(e===-1)return;if(oo.splice(e,1),oo.length===0)for(let n of $h)process.off(n,Th[n])}}function Ch(){return qu.interrupted}function Ju(t){if(qu.interrupted)return;qu.interrupted=!0;let e=Ah[t],n=oo.toReversed().flatMap((r)=>aI(r)??[]);if(n.length===0)process.exit(e);Promise.all(n).finally(()=>process.exit(e))}function aI(t){try{let e=t();return e instanceof Promise?e.catch(xh):null}catch(e){return xh(e),null}}function xh(t){let e=t instanceof Error?t.message:String(t);process.stderr.write(`ari could not clean up after an interrupt: ${e}
103
+ `;if(tn.writeFileSync(n,o,{flag:"wx",mode:r}),r!==void 0)tn.chmodSync(n,r);tn.renameSync(n,t)}finally{tn.rmSync(n,{force:!0})}}saveFailure(t){return new m(`Cannot save config at ${this.configPath}: ${mh(t)}`,`Check that ${Hu.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:t,tag:Uu})}load(){let{parse:t,strict:e}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=ks(structuredClone(this.defaultConfig),gh(n));return{config:t?t(r):r}}catch(n){if(e)return{config:structuredClone(this.defaultConfig),failure:this.loadFailure(n)};return bt.warn(w.yellow(`Config file corrupted at ${this.configPath}. Using defaults.`),{output:Ki()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(t){return new m(`Cannot read config at ${this.configPath}: ${mh(t)}`,"Repair the file and try again",void 0,{cause:t,tag:Uu})}readConfigFile(){try{return tn.readFileSync(this.configPath,"utf-8")}catch(t){if(t.code==="ENOENT")return;throw t}}}function gh(t){let e=JSON.parse(t);if(Array.isArray(e))throw Error("Config must be an object");return DR(e)}function mh(t){return t instanceof Error?t.message:String(t)}var ya="0.5.1";var E=Fi();var fh=new Map;function et(t,e){return e.some((n)=>jR(n).match(t))}function Bu(t){if(t.trim().length===0)return"is empty";if(t!==t.trim())return"has leading or trailing white space";if(t.includes("\x00"))return"contains a NUL character";if(t.startsWith("!"))return"must not be negated with a leading !";if(t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return"must be relative to the repository root";if(t.startsWith("./"))return"must not start with ./";if(t.split("/").includes(".."))return"must not contain a .. segment";return MR(t)}function wr(t){let e=Bu(t);if(e!==null)return e;if(t.endsWith("/"))return"ends with /, so it matches no file; use a pattern such as dir/**";return t.split("/").includes("")?"has an empty path segment, so it matches no file":null}function MR(t){let e=0,n=!1;for(let r=0;r<t.length;r++){let o=t[r];if(o==="\\"){if(r===t.length-1)return"ends with a lone backslash";r++;continue}if(n){n=o!=="]";continue}if(o==="[")n=!0;if(o==="{")e++;if(o==="}"){if(e===0)return"has an unmatched }";e--}}if(n)return"has an unclosed [";return e>0?"has an unclosed {":null}function jR(t){let e=fh.get(t);if(e)return e;let n=new Bun.Glob(t);return fh.set(t,n),n}class b extends Error{_tag="ValidationError"}var FR=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,GR=/^[A-Za-z_$][A-Za-z0-9_$]*$/,HR="must be lower-case letters and digits separated by single hyphens",UR=new Set(Object.getOwnPropertyNames(Object.prototype)),KR=X(),BR=ha(),ka=yr(),VR=no(rh()),WR=X().or(Bn());function At(t,e,n){try{return n()}catch(r){if(r instanceof b)throw new m(`Invalid ${t}: ${r.message}`,e);throw r}}function k(t,e){if(typeof e==="number")return`${t}[${e}]`;if(!GR.test(e))return`${t}[${JSON.stringify(e)}]`;return t.length===0?e:`${t}.${e}`}function T(t,e,n){let r=kh(t,e),o=Object.keys(r).find((s)=>!n.includes(s));if(o!==void 0)throw new b(`${e} has unknown key ${JSON.stringify(o)}; expected ${n.join(", ")}`);return r}function bn(t,e,n){return Object.entries(kh(t,e)).map(([r,o])=>{if(UR.has(r))throw new b(`${k(e,r)} uses a reserved name`);return[r,n(o,k(e,r),r)]})}function D(t,e,n){return t===void 0?e:n(t)}function lt(t,e,n){return t===void 0||t===null?e:n(t)}function ft(t,e,n){if(t===void 0||t===null)throw new b(`${e} is required`);return n(t,e)}function x(t,e){return En(KR,t,e,"must be a string")}function nt(t,e){let n=x(t,e);if(n.trim().length===0)throw new b(`${e} must not be empty`);return n}function Ct(t,e){return En(WR,t,e,"must be a string or null")}function je(t,e){let n=x(t,e);if(!FR.test(n))throw new b(`${e} ${HR}, got ${JSON.stringify(n)}`);return n}function $t(t,e){return En(BR,t,e,"must be true or false")}function Kt(t,e){let n=En(ka,t,e,"must be a positive integer");if(!Number.isInteger(n)||n<=0)throw new b(`${e} must be a positive integer`);return n}function ht(t,e){let n=En(ka,t,e,"must be a non-negative integer");if(!Number.isInteger(n)||n<0)throw new b(`${e} must be a non-negative integer`);return n}function Vn(t,e){let n=En(ka,t,e,"must be a positive number");if(!Number.isFinite(n)||n<=0)throw new b(`${e} must be a positive number`);return n}function Vu(t,e){let n=En(ka,t,e,"must be a number greater than 0 and at most 1");if(!(n>0&&n<=1))throw new b(`${e} must be a number greater than 0 and at most 1`);return n}function K(t,e,n){return En(oh(t),e,n,`must be one of ${t.join(", ")}`)}function L(t,e,n){return En(VR,t,e,"must be a list").map((o,s)=>n(o,k(e,s)))}function Dt(t,e){return L(t,e,x)}function wa(t,e){return L(t,e,(n,r)=>yh(n,r,Bu))}function hh(t,e){return L(t,e,(n,r)=>yh(n,r,wr))}function yh(t,e,n){let r=x(t,e),o=n(r);if(o!==null)throw new b(`${e} ${o}`);return r}function kh(t,e){if(typeof t!=="object"||t===null||Array.isArray(t))throw new b(`${e} must be an object`);return t}function En(t,e,n,r){try{return t(e)}catch{throw new b(`${n} ${r}`)}}var JR=["task","review"],Wu=["task"],Zt="{prompt}",vs="{model}",qR=["command","reviewCommand","model","modelFlag","env","inheritEnv","timeoutSeconds","roles"],YR=["default","stages","review"],XR=["agent","model"],zR=/^[A-Za-z_][A-Za-z0-9_]*$/,ZR=":",QR="-",Sa={default:null,review:null,stages:{}};function Sr(t){return t.roles??Wu}function Sh(t){let e=bn(t,"agents",tI);for(let[n]of e)je(n,"agent name");return Object.fromEntries(e)}function tI(t,e){let n=T(t,e,qR),r={command:wh(n.command,k(e,"command"))};if(n.reviewCommand!==void 0)r.reviewCommand=wh(n.reviewCommand,k(e,"reviewCommand"));if(n.model!==void 0)r.model=nt(n.model,k(e,"model"));if(n.modelFlag!==void 0)r.modelFlag=rI(n.modelFlag,k(e,"modelFlag"));if(n.env!==void 0)r.env=oI(n.env,k(e,"env"));if(n.inheritEnv!==void 0)r.inheritEnv=$t(n.inheritEnv,k(e,"inheritEnv"));if(r.inheritEnv===!0&&r.env!==void 0){let[o,s]=[k(e,"inheritEnv"),k(e,"env")];throw new b(`${o} and ${s} are alternatives; set only one of them`)}if(n.timeoutSeconds!==void 0)r.timeoutSeconds=Vn(n.timeoutSeconds,k(e,"timeoutSeconds"));if(n.roles!==void 0)r.roles=sI(n.roles,k(e,"roles"));return r}function vh(t){let e=T(t,"routing",YR);return{default:D(e.default,Sa.default,(n)=>Ss(n,"routing.default")),review:D(e.review,Sa.review,(n)=>Ss(n,"routing.review")),stages:Object.fromEntries(D(e.stages,[],(n)=>bn(n,"routing.stages",eI)))}}function Ss(t,e){if(t===null)return null;if(typeof t==="string")return nI(t,e);let n=T(t,e,XR),r=je(n.agent,k(e,"agent")),o=D(n.model,null,(s)=>nt(s,k(e,"model")));return{agent:r,model:o}}function eI(t,e){let n=Ss(t,e);if(n!==null)return n;throw new b(`${e} must name an agent; leave the stage out to use routing.default`)}function nI(t,e){let n=t.indexOf(ZR);if(n===-1)return{agent:je(t,e),model:null};let r=je(t.slice(0,n),`${e} (agent)`),o=nt(t.slice(n+1),`${e} (model)`);return{agent:r,model:o}}function bh(t){let{agents:e,review:n,routing:r}=t,o=[["routing.default",r.default,"task"],...Object.entries(r.stages).map(([s,i])=>[k("routing.stages",s),i,"task"]),["routing.review",r.review,"review"],["review.agent",n.agent===void 0?null:{agent:n.agent,model:null},"review"]];for(let[s,i,a]of o){if(i===null)continue;let c=e[i.agent];if(c===void 0)throw new b(`${s} names agent "${i.agent}", which agents does not define`);if(!Sr(c).includes(a))throw new b(`${s} names agent "${i.agent}", whose roles do not include "${a}"; add it to agents.${i.agent}.roles`)}}function wh(t,e){let n=L(t,e,nt);if(n.length===0)throw new b(`${e} must not be empty`);return n}function rI(t,e){let n=x(t,e);if(n.startsWith(QR)&&n.trim()===n&&n.length>1)return n;throw new b(`${e} must be an option such as "--model"`)}function oI(t,e){let n=L(t,e,(r,o)=>{let s=x(r,o);if(zR.test(s))return s;throw new b(`${o} must be an environment variable name, not a value`)});return Eh(n,e)}function sI(t,e){let n=Eh(L(t,e,(r,o)=>K(JR,r,o)),e);if(n.length===0)throw new b(`${e} must name at least one role`);return n}function Eh(t,e){let n=t.find((r,o)=>t.indexOf(r)!==o);if(n!==void 0)throw new b(`${e} repeats ${JSON.stringify(n)}`);return t}var iI=["GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_DIR","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_PREFIX","GIT_WORK_TREE"],Fe=Object.fromEntries(iI.map((t)=>[t,void 0]));var Ah={SIGHUP:129,SIGINT:130,SIGTERM:143},$h=Object.keys(Ah),Th={SIGHUP:()=>Ju("SIGHUP"),SIGINT:()=>Ju("SIGINT"),SIGTERM:()=>Ju("SIGTERM")},oo=[],qu={interrupted:!1};function Qt(t){if(oo.length===0)for(let e of $h)process.on(e,Th[e]);return oo.push(t),()=>{let e=oo.indexOf(t);if(e===-1)return;if(oo.splice(e,1),oo.length===0)for(let n of $h)process.off(n,Th[n])}}function Ch(){return qu.interrupted}function Ju(t){if(qu.interrupted)return;qu.interrupted=!0;let e=Ah[t],n=oo.toReversed().flatMap((r)=>aI(r)??[]);if(n.length===0)process.exit(e);Promise.all(n).finally(()=>process.exit(e))}function aI(t){try{let e=t();return e instanceof Promise?e.catch(xh):null}catch(e){return xh(e),null}}function xh(t){let e=t instanceof Error?t.message:String(t);process.stderr.write(`ari could not clean up after an interrupt: ${e}
104
104
  `)}var cI=["ESRCH","EPERM"];function Ge(t,e){try{process.kill(-t,e)}catch(n){if(!cI.includes(n.code))throw n}}import{randomUUID as lI}from"crypto";import{existsSync as uI,mkdirSync as dI,readFileSync as pI,realpathSync as gI,renameSync as mI,rmSync as Rh,writeFileSync as fI}from"fs";import{homedir as hI}from"os";import{join as Ih}from"path";function Z(t){return new Bun.CryptoHasher("sha256").update(t).digest("hex")}var yI=".ari",kI="trust",wI=".json",SI=384,vI=Et({root:X(),sha256:X(),trustedAt:X()});function Oh(){let t=process.env.HOME;return Ih(t===void 0||t===""?hI():t,yI,kI)}function bs(t){try{return gI(t)}catch{return t}}function _h(t){let e=bs(t);try{let n=vI(JSON.parse(pI(Yu(e),"utf8")));return n.root===e?n:null}catch{return null}}function Ph(t,e,n=new Date){let r=bs(t),o={root:r,sha256:e,trustedAt:n.toISOString()},s=Yu(r),i=`${s}.${process.pid}.${lI()}.tmp`;dI(Oh(),{recursive:!0});try{fI(i,`${JSON.stringify(o,null,2)}
105
105
  `,{mode:SI}),mI(i,s)}finally{Rh(i,{force:!0})}return o}function Nh(t){let e=Yu(bs(t));if(!uI(e))return!1;return Rh(e,{force:!0}),!0}function Yu(t){return Ih(Oh(),`${Z(t)}${wI}`)}import{existsSync as cN}from"fs";import{join as lN}from"path";function O(t,e){if(t<e)return-1;if(t>e)return 1;return 0}var bI=2;function pt(t){return`${JSON.stringify(t,EI,bI)}
106
106
  `}function EI(t,e){if(typeof e!=="object"||e===null||Array.isArray(e))return e;return Object.fromEntries(Object.entries(e).sort(([n],[r])=>O(n,r)))}var $I=["cached","run"],Dh="TYPESAFE_API_URL",TI=["TYPESAFE_API_KEY","CLOUDFLARE_ACCOUNT_ID","CLOUDFLARE_API_TOKEN","CLOUDFLARE_AUTH_TOKEN"],xI=["argus"],AI="cached",CI=25,RI=6000,II=1000,OI=20000,_I=["config","command","mode","limit","maxBytes","timeoutSeconds","verdicts"];function Mh(t){let e=T(t,"review.argus",_I),n=D(e.timeoutSeconds,null,(o)=>Vn(o,"review.argus.timeoutSeconds")),r=D(e.verdicts,!1,(o)=>$t(o,"review.argus.verdicts"));return{command:D(e.command,[...xI],NI),config:ft(e.config,"review.argus.config",nt),limit:D(e.limit,CI,(o)=>Lh(o,"limit",II)),maxBytes:D(e.maxBytes,RI,(o)=>Lh(o,"maxBytes",OI)),mode:D(e.mode,AI,(o)=>K($I,o,"review.argus.mode")),...n===null?{}:{timeoutSeconds:n},...r?{verdicts:r}:{}}}function PI(t){return t==="run"?[Dh,...TI]:[Dh]}function va(t){let e=t.mode==="run";if(t.verdicts!==!0)return[e?"run":"check"];return e?["run","snapshot","import"]:["snapshot","import"]}function ba(t){return PI(t==="run"?"run":"cached")}function so(t,e,n){let{base:r,configPath:o,file:s,only:i}=n,a=["--config",o,"--base",r],c=i===null?[]:["--only",i],l=t.command;switch(e){case"check":return[...l,"check",...a,"--json"];case"run":return[...l,"run",...a,"--limit",String(t.limit),...c,"--json"];case"snapshot":return[...l,"report","create",...a,...c,"--json"];case"import":return[...l,"verify","--import",s??"",...a,"--json"]}}function NI(t){let e=L(t,"review.argus.command",nt);if(e.length===0)throw new b("review.argus.command must list at least the program to start");return e}function Lh(t,e,n){let r=`review.argus.${e}`,o=Kt(t,r);if(o>n)throw new b(`${r} must be at most ${n}`);return o}import{randomUUID as BP}from"crypto";import{appendFileSync as VP,existsSync as Cn,linkSync as WP,mkdirSync as Ly,readdirSync as JP,readFileSync as Rs,renameSync as My,rmSync as Ua,writeFileSync as jy}from"fs";import{basename as qP,dirname as Fy,join as Rt}from"path";function Es(t){if(typeof t!=="object"||t===null||Object.isFrozen(t))return t;for(let e of Object.values(t))Es(e);return Object.freeze(t)}var DI="basic",LI=300,MI=6000,jI=20,FI=2000,GI=!0,HI=1200,UI=60000,KI=25,BI=0.95,VI=0.75,WI=10,JI=!1,qI=!0,YI=25,XI=["**/*.test.*","**/*.spec.*","**/*_test.*","**/*-test.{js,cjs,mjs,ts,cts,mts}","**/test-*.{js,cjs,mjs,ts,cts,mts}","**/test.{js,cjs,mjs,ts,cts,mts}","**/test_*.py","**/test/**","**/tests/**","**/__tests__/**"],zI="Fix the reported value in .ari/config.json",ZI=["$schema","pack","requireTask","checkTimeoutSeconds","testGlobs","regression","review","context","knowledge","snapshots","hooks","agents","routing"],QI=["maxEntryBytes","maxBytes","decayAfterTasks","duplicateSimilarity","mergeSimilarity","rehearsalTasks","sleepOnStop"],Tt=Es({agents:{},checkTimeoutSeconds:LI,context:{briefBytes:FI,budget:MI,journalTail:jI},hooks:{brief:GI},knowledge:{decayAfterTasks:KI,duplicateSimilarity:BI,maxBytes:UI,maxEntryBytes:HI,mergeSimilarity:VI,rehearsalTasks:WI,sleepOnStop:JI},pack:DI,regression:{setup:[]},requireTask:!1,review:{command:null},routing:Sa,snapshots:{auto:qI,keep:YI},testGlobs:XI});function vr(t){return structuredClone(At("config",zI,()=>jh(t)))}function Ea(t){try{return jh(t),null}catch(e){if(e instanceof b)return e.message;throw e}}function jh(t){let e=T(t,"config",ZI);if(e.$schema!==void 0)x(e.$schema,"$schema");let n={agents:D(e.agents,Tt.agents,Sh),checkTimeoutSeconds:D(e.checkTimeoutSeconds,Tt.checkTimeoutSeconds,(r)=>Vn(r,"checkTimeoutSeconds")),context:D(e.context,Tt.context,tO),hooks:D(e.hooks,Tt.hooks,eO),knowledge:D(e.knowledge,Tt.knowledge,nO),pack:D(e.pack,Tt.pack,(r)=>je(r,"pack")),regression:D(e.regression,Tt.regression,oO),requireTask:D(e.requireTask,Tt.requireTask,(r)=>$t(r,"requireTask")),review:D(e.review,Tt.review,sO),routing:D(e.routing,Tt.routing,vh),snapshots:D(e.snapshots,Tt.snapshots,rO),testGlobs:D(e.testGlobs,Tt.testGlobs,(r)=>hh(r,"testGlobs"))};return bh(n),n}function tO(t){let e=T(t,"context",["budget","journalTail","briefBytes"]),n=Tt.context;return{briefBytes:D(e.briefBytes,n.briefBytes,(r)=>Kt(r,"context.briefBytes")),budget:D(e.budget,n.budget,(r)=>Kt(r,"context.budget")),journalTail:D(e.journalTail,n.journalTail,(r)=>ht(r,"context.journalTail"))}}function eO(t){let e=T(t,"hooks",["brief"]);return{brief:D(e.brief,Tt.hooks.brief,(n)=>$t(n,"hooks.brief"))}}function nO(t){let e=T(t,"knowledge",QI),n={decayAfterTasks:io(e,"decayAfterTasks",Kt),duplicateSimilarity:io(e,"duplicateSimilarity",Vu),maxBytes:io(e,"maxBytes",Kt),maxEntryBytes:io(e,"maxEntryBytes",Kt),mergeSimilarity:io(e,"mergeSimilarity",Vu),rehearsalTasks:io(e,"rehearsalTasks",ht),sleepOnStop:D(e.sleepOnStop,Tt.knowledge.sleepOnStop,(r)=>$t(r,"knowledge.sleepOnStop"))};if(n.mergeSimilarity>n.duplicateSimilarity)throw new b("knowledge.mergeSimilarity must not exceed knowledge.duplicateSimilarity");if(n.maxEntryBytes>n.maxBytes)throw new b("knowledge.maxEntryBytes must not exceed knowledge.maxBytes");return n}function rO(t){let e=T(t,"snapshots",["auto","keep"]),n=Tt.snapshots;return{auto:D(e.auto,n.auto,(r)=>$t(r,"snapshots.auto")),keep:D(e.keep,n.keep,(r)=>Kt(r,"snapshots.keep"))}}function io(t,e,n){return D(t[e],Tt.knowledge[e],(r)=>n(r,`knowledge.${e}`))}function oO(t){let e=T(t,"regression",["setup"]);return{setup:D(e.setup,Tt.regression.setup,(n)=>L(n,"regression.setup",nt))}}function sO(t){let e=T(t,"review",["command","agent","model","argus"]),n=D(e.command,Tt.review.command,(i)=>Ct(i,"review.command"));if(n!==null&&n.trim().length===0)throw new b("review.command must be a command or null");let r=D(e.agent,null,(i)=>i===null?null:je(i,"review.agent")),o=D(e.model,null,(i)=>i===null?null:nt(i,"review.model"));if(n!==null&&r!==null)throw new b("review.command and review.agent are alternatives; set only one of them");if(o!==null&&r===null)throw new b("review.model needs review.agent");let s=e.argus===void 0?null:Mh(e.argus);return{command:n,...r===null?{}:{agent:r},...o===null?{}:{model:o},...s===null?{}:{argus:s}}}var $s='writes a key with a tag, an anchor, an alias, a "?" or a collection; use plain keys',iO=/"(?:[^"\\]|\\.)*"|'(?:[^']|'')*'/sy,aO=/(?:[^,[\]{}:#\n]|:(?![ \t\n,[\]{}]|$)|(?<![ \t\n])#)+/sy,cO=/(?:[ \t\n]|(?<=[ \t\n])#[^\n]*)+/sy,lO=/[&!*][^\s,[\]{}]*|\?(?=[ \t\n])/sy,uO=/[ \t\n,[\]{}]/;function zu(t){return`defines "${t}" twice`}function Zu(t,e){return $a(iO,t,e)}function Qu(t){return String(Bun.YAML.parse(t))}function Fh(t,e){let n=[],r=e,o=!1;while(r<t.length){let s=pO(t,r,o);if(r+=s.text.length,s.kind==="space")continue;let i=dO(s,n);if(i!==null)return{end:r,problem:i};if(n.length===0)return{end:r,problem:null};o=s.kind==="quoted"||s.kind==="close"}return{end:r,problem:null}}function dO(t,e){let n=e.at(-1),r=n?.keys!=null&&n.inKey;switch(t.kind){case"open":{if(r)return'writes a key with a tag, an anchor, an alias, a "?" or a collection; use plain keys';let o=t.text==="{"?new Set:null;return e.push({inKey:o!==null,key:null,keys:o}),null}case"close":return e.pop(),r?Xu(n):null;case"comma":{let o=r?Xu(n):null;if(n!==void 0)Object.assign(n,{inKey:n.keys!==null,key:null});return o}case"colon":if(!r)return null;return n.inKey=!1,Xu(n);case"special":return r?'writes a key with a tag, an anchor, an alias, a "?" or a collection; use plain keys':null;case"quoted":case"plain":if(r)n.key=t.kind==="quoted"?Qu(t.text):t.text.trim();return null;case"space":return null}}function Xu(t){let{key:e,keys:n}=t;if(e===null||n===null)return null;if(n.has(e))return zu(e);return n.add(e),null}function pO(t,e,n){let r=t[e]??"";if(r==="{"||r==="[")return{kind:"open",text:r};if(r==="}"||r==="]")return{kind:"close",text:r};if(r===",")return{kind:"comma",text:r};if(r===":"&&(n||uO.test(t[e+1]??" ")))return{kind:"colon",text:r};let o=$a(cO,t,e);if(o!==null)return{kind:"space",text:o};let s=Zu(t,e);if(s!==null)return{kind:"quoted",text:s};let i=$a(lO,t,e);if(i!==null)return{kind:"special",text:i};return{kind:"plain",text:$a(aO,t,e)??r}}function $a(t,e,n){return t.lastIndex=n,t.exec(e)?.[0]??null}var gO=/^(?:---|\.\.\.)(?=[ \t]|$)/,mO=/^( *)((?:-(?: +|$))*)(.*)$/s,Gh=/^(?:[&!][^ \t]*(?:[ \t]+|$))+/,fO=/^#/,hO=/^[{[]/,yO=/^\?(?:[ \t]|$)/,kO=/^\*.*:(?:[ \t]|$)/s,Hh=/^[ \t]*:(?:[ \t]+|$)/,wO=/^([^\s|>%@`"'&*!#,[\]{}](?:(?![ \t]#).)*?)[ \t]*:(?:[ \t]+(.*))?$/s,Uh=-1;function Kh(t){let e=[],n=null,r=0,o=0;for(let s of t.split(`
package/package.json CHANGED
@@ -39,5 +39,5 @@
39
39
  "package:publish": "bun ../../tools/scripts/publish-package.ts ."
40
40
  },
41
41
  "type": "module",
42
- "version": "0.5.0"
42
+ "version": "0.5.1"
43
43
  }