cyber-agentkit 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/CHANGELOG.md +181 -0
- package/dist/cli.js +8687 -4886
- package/dist/commands.d.ts +159 -87
- package/dist/commands.js +1099 -838
- package/dist/index.d.ts +335 -70
- package/dist/index.js +26 -22
- package/dist/reference-where-BsBpwLyg.d.ts +735 -0
- package/dist/{reference-where-C84J6MsR.js → reference-where-CVmGFOwR.js} +5468 -1864
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/readme.md +59 -26
- package/skills/asset/scripts/asset.mjs +82 -69
- package/skills/prose-update/SKILL.md +1 -1
- package/skills/prose-update/scripts/prose-update.mjs +82 -69
- package/skills/reference/README.md +7 -7
- package/skills/reference/SKILL.md +64 -58
- package/skills/reference/references/create.md +29 -24
- package/skills/reference/references/customize.md +82 -0
- package/skills/reference/references/load.md +58 -37
- package/skills/reference/scripts/reference.mjs +82 -69
- package/dist/resolve-reference-D62VJZc0.d.ts +0 -246
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
// Compiled by `universal-plugin plugin build` from src/assets/asset.skill-script.ts. Edit the source, not this file.
|
|
2
|
-
globalThis.__SKILL_SCRIPT__ = {"package":"cyber-agentkit","bin":"cyber-agentkit","version":"
|
|
3
|
-
import{createRequire as e}from"node:module";import{fileURLToPath as t}from"node:url";import{copyFileSync as n,existsSync as r,lstatSync as i,mkdirSync as a,readFileSync as o,readdirSync as s,realpathSync as c,rmSync as l,rmdirSync as u,statSync as d,writeFileSync as f}from"node:fs";import{basename as p,dirname as m,extname as h,join as g,posix as _,relative as v,resolve as y,sep as b,win32 as x}from"node:path";import{inspect as S,styleText as C}from"node:util";import{homedir as w}from"node:os";import{readFile as T,readdir as E}from"node:fs/promises";var D=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),O=/* @__PURE__ */ e(import.meta.url),ee=`1.2.0`,k=`cyber-agentkit`,te;const A={success:0,error:1,usage:2},ne=Symbol.for(`clibuilder.CliError`),re=Symbol.for(`clibuilder.CliError.reported`),ie=[`error`,`code`,`help`];var j=class e extends Error{static reported(t=A.error,n=`the error was already reported`){let r=new e(n,{exitCode:t});return r[re]=!0,r}constructor(e,t){let n=typeof e==`string`?{...t,message:e}:e;super(n.message),this.name=`CliError`,this[te]=!0,this.exitCode=se(n.exitCode??A.error),this.code=ce(n.code??`error`),this.details=le(n.details??{}),this.help=n.help===void 0?[]:typeof n.help==`string`?[n.help]:[...n.help],this.cause=n.cause}};te=ne;function ae(e){return!!e&&typeof e==`object`&&e[ne]===!0}function oe(e){return e[re]===!0}function se(e){if(Number.isInteger(e)&&e>=1&&e<=255)return e;throw RangeError(`CliError exitCode must be an integer from 1 to 255, received ${e}`)}function ce(e){if(/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))return e;throw RangeError(`CliError code must be a kebab-case string such as "not-found", received "${e}"`)}function le(e){for(let t of ie)if(t in e)throw RangeError(`CliError details may not have the key "${t}"`);return{...e}}function M(e){return e}function ue(e){let t=e.kind===`array`?e.element:e;return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function de(e){switch(e.kind){case`string`:return e.pattern?`string ${e.pattern}`:`string`;case`number`:case`int`:return`${e.kind}${fe(e.min,e.max)}`;case`boolean`:case`json`:return e.kind;case`literal`:return String(e.value);case`enum`:return e.values.join(`|`);case`custom`:return`value`;case`array`:return de(e.element)}}function fe(e,t){return e!==void 0&&t!==void 0?` ${e}..${t}`:e===void 0?t===void 0?``:` <=${t}`:` >=${e}`}const pe={optional(){return me({...this,isOptional:!0})},check(e){let t=typeof e==`function`?{type:`fn`,fn:e}:{type:`schema`,schema:e};if(typeof e!=`function`&&!he(e))throw TypeError(`check() takes a function or a Standard Schema`);return me({...this,checks:[...this.checks,t]})}};function me(e){return Object.freeze(Object.assign(Object.create(pe),e))}function N(e){return me({...e,isOptional:!1,checks:Object.freeze([])})}function he(e){let t=e?.[`~standard`];return typeof t==`object`&&!!t&&typeof t.validate==`function`}function ge(e,t,n){let{min:r,max:i}=t??{};for(let[t,a]of[[`min`,r],[`max`,i]])if(a!==void 0){if(typeof a!=`number`||Number.isNaN(a))throw TypeError(`${e}: ${t} must be a number`);if(n&&Number.isFinite(a)&&!Number.isInteger(a))throw RangeError(`${e}: ${t} must be an integer, got ${a}`)}if(r!==void 0&&i!==void 0&&r>i)throw RangeError(`${e}: min (${r}) is greater than max (${i})`);return{...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}}function _e(e){let t=e?.pattern;if(t!==void 0&&!(t instanceof RegExp))throw TypeError(`t.string: pattern must be a RegExp`);return N(t===void 0?{kind:`string`}:{kind:`string`,pattern:t})}function ve(e){if(e===void 0)return N({kind:`json`});if(!he(e))throw TypeError(`t.json: schema must be a Standard Schema`);return N({kind:`json`,schema:e})}const P={string:_e,number(e){return N({kind:`number`,...ge(`t.number`,e,!1)})},int(e){return N({kind:`int`,...ge(`t.int`,e,!0)})},boolean(){return N({kind:`boolean`})},literal(e){let t=typeof e;if(!(t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)))throw TypeError(`t.literal: value must be a string, a finite number or a boolean, got ${String(e)}`);return N({kind:`literal`,value:e})},enum(e){if(!Array.isArray(e)||e.length===0)throw TypeError(`t.enum: values must be a non-empty array`);for(let t of e)if(typeof t!=`string`)throw TypeError(`t.enum: values must be strings, got ${String(t)}`);return N({kind:`enum`,values:Object.freeze([...e])})},array(e){let t=e;if(typeof t?.kind!=`string`||!Object.prototype.isPrototypeOf.call(pe,t))throw TypeError(`t.array: element must be a descriptor`);if(t.kind===`array`)throw TypeError(`t.array: element cannot be an array`);if(t.isOptional)throw TypeError(`t.array: element cannot be optional`);return N({kind:`array`,element:e})},custom(e){if(typeof e!=`function`)throw TypeError(`t.custom: convert must be a function`);return N({kind:`custom`,convert:e})},json:ve};function ye(e){return typeof e==`object`&&!!e&&Object.prototype.isPrototypeOf.call(pe,e)}String.prototype.charCodeAt;const be=String.prototype.slice;Array.prototype.forEach,Array.prototype.map,Array.prototype.reduce;const xe=Array.prototype.slice,Se=Array.prototype.push,Ce={modifiers:`-`,terminator:`--`};function we(e){let t=/* @__PURE__ */ new Set,n=e?.modifiers??Ce.modifiers;for(let e of typeof n==`string`?Array.from(n):n){if(e.length!==1||e===`=`)throw Error(`Invalid modifier '${e}': a modifier must be a single character other than '='`);t.add(e)}if(t.size===0)throw Error(`At least one modifier is required`);let r=e?.terminator??Ce.terminator;if(r===``)throw Error(`The terminator must not be empty`);return{modifiers:t,terminator:r}}function Te(e,t){let n=0;for(;n<e.length&&t.has(e[n]);)n++;return[be.call(e,n),n]}function Ee(e,t){let{modifiers:n,terminator:r}=we(t),i=[],a=0,o=xe.call(e);for(;o.length>0;){let e=o.shift();if(e===r){Se.call(i,{kind:`option-terminator`,index:a}),a++,Se.apply(i,o.map((e,t)=>({kind:`positional`,index:a+t,value:e})));break}let[t,s]=Te(e,n);if(s===0||!t)Se.call(i,{kind:`positional`,index:a,value:t||e});else{let n=t.indexOf(`=`),[r,o]=n===-1?[t,void 0]:[be.call(t,0,n),be.call(t,n+1)];Se.call(i,{kind:`option`,index:a,name:r,dashes:s,raw:e,value:o})}a++}return i}var De=class extends Error{constructor(e,t,n,r={}){super(e),Object.defineProperty(this,"option",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"input",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"kind",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"issues",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"detail",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=`ParseArgsError`,this.kind=r.kind??`invalid-value`,this.index=r.index,this.issues=r.issues,this.value=r.value,this.detail=r.detail??e}};function Oe(e){let t=je(e),n=t.next();for(;!n.done;){let{value:e,option:r}=n.value;if(Ae(e))throw e.then(void 0,()=>{}),t.return(void 0),Error(`Option '${r}' has an asynchronous converter or check: use parseArgsAsync() to parse it`);n=t.next(e)}return n.value}async function ke(e){let t=je(e),n=t.next();for(;!n.done;)n=await Promise.resolve(n.value.value).then(e=>t.next(e),e=>t.throw(e));return n.value}function Ae(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&typeof e.then==`function`}function*je(e){let t=Ee(e.args,e.grammar),n=e.options;Me(n);let r=Pe(n),i=Object.create(null),a=Object.create(null),o=[],s=[],c=t.slice();for(;c.length>0;){let t=c.shift();switch(t.kind){case`positional`:Ne(e,t.value),o.push(t.value);break;case`option`:{let o=t.dashes===1?Array.from(t.name):[t.name];for(let s=0;s<o.length;s++){let l=o[s],u=s===o.length-1,d=r.get(l)??l,f=n?.[d];if(e.strict&&!f)throw new De(`Unknown option '${l}' (from '${t.raw}')`,l,t.raw,{kind:`unknown-option`});if(!u&&f&&Ie(f))throw new De(`Invalid option group '${t.raw}': '${l}' takes a value, so it can only be the last option in a group`,d,t.raw,{kind:`invalid-group`,detail:`takes a value, so it can only be the last option in a group`});let p=u?t.value??Re(f,c):void 0;if(f&&ye(f.type)){let e=f.type;if(e.kind===`array`){let n=i[d]??(i[d]=[]);(a[d]??(a[d]=[])).push(t.raw);let r={name:d,label:`${d}[${n.length}]`,index:n.length,token:t};n.push(yield*Ge(e.element,p,r))}else i[d]=yield*Ge(e,p,{name:d,label:d,index:void 0,token:t});continue}let m=ze(f,d,p,t);f?.multiple?(i[d]??(i[d]=[])).push(m):i[d]=m}break}case`option-terminator`:for(let t of c)Ne(e,t.value);s.push(...c.map(e=>e.value)),c.length=0}}for(let[e,t]of Object.entries(n??{})){let n=ye(t.type)?t.type:void 0;if(i[e]!==void 0){if(n?.kind===`array`){let t=a[e].join(` `);yield*Xe(n,i[e],e,(n,r)=>We(e,e,t,n,{issues:r}))}continue}if(t.default!==void 0)n&&(yield*Qe(t,e)),i[e]=Array.isArray(t.default)?[...t.default]:t.default;else if(n&&!n.isOptional)throw new De(`Missing required option '${e}'`,e,``,{kind:`missing-option`,detail:`a value is required`})}let l={_:o,__:s,options:i};return e.tokens&&(l.tokens=t),l}function Me(e){for(let[t,n]of Object.entries(e??{})){let e=n.type;if(typeof e==`object`&&e&&!ye(e))throw TypeError(`Option '${t}' has a type that is neither a type name nor a descriptor from t`);if(ye(e)&&n.multiple!==void 0)throw TypeError(`Option '${t}' cannot set 'multiple' with a descriptor: use t.array(element)`)}}function Ne(e,t){if(e.allowPositionals===!1)throw new De(`Unexpected positional argument '${t}'`,void 0,t,{kind:`unexpected-positional`})}function Pe(e){let t=/* @__PURE__ */ new Map;if(!e)return t;for(let n of Object.keys(e))t.set(n,n);for(let[n,r]of Object.entries(e)){let e=r.alias;for(let r of e===void 0?[]:Array.isArray(e)?e:[e]){let e=t.get(r);if(e!==void 0&&e!==n)throw Error(`Alias '${r}' of option '${n}' is already used by option '${e}'`);t.set(r,n)}}return t}function Fe(e){return e.kind===`array`?e.element:e}function Ie(e){if(!ye(e.type))return e.type!==`boolean`;let t=Fe(e.type);return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function Le(e){if(!ye(e.type))return e.type===`number`;let t=Fe(e.type);return t.kind===`number`||t.kind===`int`||t.kind===`literal`&&typeof t.value==`number`}function Re(e,t){if(!e||!Ie(e))return;let n=t[0];if(n){if(n.kind===`positional`)return t.shift(),n.value;if(n.kind===`option`&&Le(e)&&Number.isFinite(Ve(n.raw)))return t.shift(),n.raw}}function ze(e,t,n,r){if(!e)return n??!0;switch(e.type){case`boolean`:return Ue(t,n,r);case`number`:return He(t,n,r);default:if(n===void 0)throw Be(t,`a value is required`,r,`missing-value`);return n}}function Be(e,t,n,r,i){return new De(`Invalid value for option '${e}': ${t} (from '${n.raw}')`,e,n.raw,{kind:r,value:i,detail:t})}function Ve(e){return e.trim()===``?NaN:Number(e)}function He(e,t,n){if(t===void 0)throw Be(e,`a number is required`,n,`missing-value`);let r=Ve(t);if(!Number.isFinite(r))throw Be(e,t,n,`invalid-value`,t);return r}function Ue(e,t,n){if(t===void 0)return!0;if(t===`false`||t===`f`||t===`0`)return!1;if(t===`true`||t===`t`)return!0;let r=Ve(t);if(!Number.isNaN(r))return r>0;throw Be(e,t,n,`invalid-value`,t)}function We(e,t,n,r,i,a=r){return new De(`Invalid value for option '${t}': ${a} (from '${n}')`,e,n,{...i,detail:r})}function*Ge(e,t,n){let r=(e,r,i)=>We(n.name,n.label,n.token.raw,e,{index:n.index,issues:r,value:t},i),i=yield*Je(e,t,n,r);return yield*Xe(e,i,n.label,r),i}function Ke(e){return`'${e}'`}function qe(e){switch(e.kind){case`string`:return`a string matching ${e.pattern}`;case`number`:case`int`:{let t=e.kind===`int`?`an integer`:`a number`;return e.min!==void 0&&e.max!==void 0?`${t} from ${e.min} to ${e.max}`:e.min===void 0?e.max===void 0?t:`${t} of at most ${e.max}`:`${t} of at least ${e.min}`}case`boolean`:return`no value, true or false`;case`literal`:return typeof e.value==`string`?Ke(e.value):String(e.value);case`enum`:return`one of ${e.values.map(Ke).join(`, `)}`}}function*Je(e,t,n,r){let i=e=>r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got ${Ke(t)}`);if(e.kind===`boolean`||e.kind===`literal`&&typeof e.value==`boolean`){let n=t===void 0||t===`true`||t!==`false`&&void 0;if(n===void 0||e.kind===`literal`&&n!==e.value)throw t===void 0?r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got no value`):i(e);return n}if(t===void 0)throw We(n.name,n.label,n.token.raw,`a value is required`,{kind:`missing-value`,index:n.index});switch(e.kind){case`string`:if(e.pattern&&(e.pattern.lastIndex=0,!e.pattern.test(t)))throw i(e);return t;case`number`:case`int`:{let n=Ve(t);if(!Number.isFinite(n)||e.kind===`int`&&!Number.isInteger(n)||e.min!==void 0&&n<e.min||e.max!==void 0&&n>e.max)throw i(e);return n}case`literal`:{let n=typeof e.value==`number`?Ve(t):t;if(n!==e.value)throw i(e);return n}case`enum`:if(!e.values.includes(t))throw i(e);return t;case`custom`:try{return yield{value:e.convert(t),option:n.label}}catch(e){throw Ye(e,r)}case`json`:{let i;try{i=JSON.parse(t)}catch{throw r(`not valid JSON`,void 0,`${Ke(t)} is not valid JSON`)}if(!e.schema)return i;let a=yield{value:e.schema[`~standard`].validate(i),option:n.label};if(a.issues)throw r(`does not match the expected shape`,a.issues);return a.value}}}function Ye(e,t){return e instanceof Error&&e.constructor===Error?t(e.message):e}function*Xe(e,t,n,r){for(let i of e.checks)if(i.type===`fn`){let e=yield{value:i.fn(t),option:n};if(e===!1)throw r(`failed a check`);if(typeof e==`string`)throw r(e)}else{let e=yield{value:i.schema[`~standard`].validate(t),option:n};if(e.issues)throw r(`failed a check`,e.issues)}}const Ze=/* @__PURE__ */ new WeakMap;function*Qe(e,t){if(Ze.has(e))return;let n=e.type,r=e=>t=>/* @__PURE__ */ Error(`The default of option '${e}' failed a check${t===`failed a check`?``:`: ${t}`}`);if(n.kind===`array`){let i=e.default;for(let e=0;e<i.length;e++){let a=`${t}[${e}]`;yield*Xe(n.element,i[e],a,r(a))}}yield*Xe(n,e.default,t,r(t)),Ze.set(e,!0)}const $e=/* @__PURE__ */ new WeakMap;function et(e,t,n){let r=tt(e,nt(t,n)),[i,a]=rt(t,r,n);return ct(r,i,a)}function tt(e,t){if(e.commands){let n=e.commands,r=t.peek(e);for(let e=n.length-1;e>=0;e--){let i=n[e];if(!i.name)return i;if(r===i.name||i.alias?.includes(r))return t.consume(),i.commands?tt(i,t):i}}return e}function nt(e,t){let n=$e.get(e)??[],r,i=-1,a=0;return{peek(o){if(r=void 0,i<0){if(a<e._.length)return(r=[e._,a])[0][a];i=0,a=-1}for(;t&&i<n.length;){let e=n[i];if(a<0){let n=F(t,e.key)[1];if(!n)return;a=it(F(o,e.key)[1]??n,e)}if(a<e.following.length)return(r=[e.following,a])[0][a];i++,a=-1}},consume(){r[0].splice(r[1],1)}}}function rt(e,t,n){let r=$e.get(e);if(!r)return[e,void 0];let i={},a=[],o=[];for(let e of r){let r=F(t,e.key)[1],s=it(r??(n&&F(n,e.key)[1]),e),c=e.following.slice(0,s);r&&o.push({key:e.key,tokens:[e.raw,...c]}),a.push(...e.following.slice(s));let l=e.inline.length+c.length>0?[...e.inline,...c]:[`true`];i[e.key]=[...i[e.key]??[],...l]}let s={...e,_:[...e._,...a]};for(let t of Object.keys(i))e[t]&&(s[t]=i[t]);return[s,o]}function it(e,t){return e?t.inline.length===0&&ue(st(e))?1:0:t.following.length}const at=P.boolean().optional(),ot=P.string();function st(e){return e.type??at}function ct(e,t,n){return ft(dt(ut(lt({command:e,rawArgs:t,args:{_:[]},errors:[],descriptors:[]}))),n)}function lt(e){let t=e.command,n=[...e.rawArgs._],r=t.arguments||[];for(let t of r){let r=t.type??ot;if(n.length===0){r.isOptional||e.errors.push({type:`missing-argument`,name:t.name});continue}let i=r.kind===`array`?n.splice(0):[n.shift()];e.descriptors.push({type:`argument`,name:t.name,descriptor:r,values:i})}return n.length>0&&e.errors.push({type:`extra-arguments`,name:t.name,values:n}),e}function ut(e){for(let t of Object.keys(e.rawArgs)){if(t===`_`)continue;if(/^-/.test(t)){e.errors.push({type:`invalid-key`,key:t});continue}let[n,r]=F(e.command,t);if(!n){e.errors.push({type:`invalid-key`,key:t});continue}let i=st(r),a=e.rawArgs[t];i.kind!==`array`&&a.length>1&&e.errors.push({type:`expect-single`,key:t,keyKind:i.kind,value:a})}return e}function dt(e){let t=e.command.options;if(!t)return e;let n=/* @__PURE__ */ new Map;for(let t of Object.keys(e.rawArgs)){let[r]=F(e.command,t);r&&!n.has(r)&&n.set(r,t)}let r=[...n.keys()];for(let i=0;i<r.length;i++)for(let a=i+1;a<r.length;a++){let[o,s]=[r[i],r[a]];if(!t[o].conflicts?.includes(s)&&!t[s].conflicts?.includes(o))continue;let[c,l]=t[o].conflicts?.includes(s)?[o,s]:[s,o];e.errors.push({type:`conflicting-options`,key:n.get(c),conflictsWith:n.get(l)})}return e}function ft(e,t){let n=e.command.options??{};for(let r of Object.keys(n)){let i=n[r],a=Object.keys(e.rawArgs).filter(t=>t!==`_`&&F(e.command,t)[0]===r);e.errors.some(e=>e.type===`expect-single`&&a.includes(e.key))||e.descriptors.push({type:`option`,name:r,entry:{...i,type:st(i)},occurrences:t?t.filter(e=>a.includes(e.key)):a.flatMap(t=>e.rawArgs[t].map(e=>({key:t,tokens:[`--${r}=${e}`]})))})}return e}function F(e,t){let n=e.options;if(!n)return[];let r=n[t];if(r)return[t,r];let i=Object.keys(n).find(e=>{let r=n[e];return r.alias?r.alias.some(e=>e===t||e.alias===t):!1});return i?[i,n[i]]:[]}const pt={comma:`,`,tab:` `,pipe:`|`},mt=pt.comma;function ht(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`).replace(/[\u0000-\u001F]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function gt(e){return e===`true`||e===`false`||e===`null`}function _t(e,t,n){if(t===`__proto__`){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0});return}e[t]=n}const vt=/* @__PURE__ */ RegExp(`(?:^?|\\n) *#`);var yt=class{constructor(e){if(vt.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function bt(e){return e instanceof yt}const xt=/[\uD800-\uDFFF]/;function St(e){if(e===null)return null;if(bt(e))return e;if(typeof e==`object`&&e&&`toJSON`in e&&typeof e.toJSON==`function`){let t=e.toJSON();if(t!==e)return St(t)}if(typeof e==`string`)return Ct(e,`string value`),e;if(typeof e==`boolean`)return e;if(typeof e==`number`)return Object.is(e,-0)?0:Number.isFinite(e)?e:null;if(typeof e==`bigint`)return e>=-(2**53-1)&&e<=2**53-1?Number(e):e.toString();if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(St);if(e instanceof Set)return Array.from(e).map(St);if(e instanceof Map)return Object.fromEntries(Array.from(e,([e,t])=>[String(e),St(t)]));if(kt(e)){let t={};for(let n in e)Object.hasOwn(e,n)&&(Ct(n,`object key`),_t(t,n,St(e[n])));return t}return null}function Ct(e,t){if(xt.test(e))for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<55296||r>57343)continue;let i=r<=56319,a=e.charCodeAt(n+1);if(i&&a>=56320&&a<=57343){n++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${r.toString(16).toUpperCase()} at index ${n}`)}}function wt(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function Tt(e){return wt(e)||bt(e)}function Et(e){return Array.isArray(e)}function Dt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!bt(e)}function Ot(e){return Object.keys(e).length===0}function kt(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function At(e){return e.length===0||e.every(e=>Tt(e))}function jt(e){return e.length===0||e.every(e=>Et(e))}function Mt(e){return e.length===0||e.every(e=>Dt(e))}const Nt=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Pt(e){if(!Object.values(pt).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Ft(e){return/^[A-Z_][\w.]*$/i.test(e)}function It(e,t=mt){return!(!e||/^[ \t]|[ \t]$/.test(e)||gt(e)||Lt(e)||e.includes(`:`)||e.includes(`"`)||e.includes(`\\`)||/[[\]{}]/.test(e)||/[\u0000-\u001F]/.test(e)||e.includes(t)||e.startsWith(`-`)||e.startsWith(`#`))}function Lt(e){return Nt.test(e)}function Rt(e,t){return bt(e)?e.value:e===null?`null`:typeof e==`boolean`||typeof e==`number`?String(e):zt(e,t)}function zt(e,t=mt){return It(e,t)?e:`"${ht(e)}"`}function Bt(e){return Ft(e)?e:`"${ht(e)}"`}function Vt(e,t=mt){return e.map(e=>Rt(e,t)).join(t)}function Ht(e,t){let n=t?.key,r=t?.fields,i=t?.delimiter??`,`,a=``;return n!=null&&(a+=Bt(n)),a+=`[${e}${t?.keyed?`:`:``}${i===mt?``:i}]`,r&&(a+=`{${Ut(r,i)}}`),a+=`:`,a}function Ut(e,t){return e.map(e=>Bt(e.name)+(e.children?`{${Ut(e.children,t)}}`:``)).join(t)}function Wt(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let e of t)if(!Object.hasOwn(n,e))return}let n=[];for(let r of t){let t=qt(r,e.map(e=>e[r]));if(!t)return;n.push(t)}return n}function Gt(e){let t=Object.values(e);if(!(t.length<2)&&t.every(e=>Dt(e)&&!Ot(e)))return Wt(t)}function Kt(e,t){let n=[];return Jt(e,t,n),n}function qt(e,t){if(t.every(e=>Tt(e)))return{name:e};if(!t.every(e=>Dt(e)&&!Ot(e)))return;let n=Wt(t);if(n)return{name:e,children:n}}function Jt(e,t,n){for(let r of t){let t=e[r.name];r.children?Jt(t,r.children,n):n.push(t)}}function*Yt(e,t,n){if(Tt(e)){let n=Rt(e,t.delimiter);n!==``&&(yield n);return}if(Et(e))yield*en(void 0,e,n,t);else if(Dt(e)){let r=Gt(e);if(r){yield*Qt(void 0,e,r,n,t);return}yield*Xt(e,n,t)}}function*Xt(e,t,n){for(let[r,i]of Object.entries(e))yield*Zt(r,i,t,n)}function*Zt(e,t,n,r){let i=Bt(e);if(Tt(t))yield I(n,`${i}: ${Rt(t,r.delimiter)}`,r.indentSize);else if(Et(t))yield*en(e,t,n,r);else if(Dt(t)){let a=Gt(t);if(a){yield*Qt(e,t,a,n,r);return}yield I(n,`${i}:`,r.indentSize),Ot(t)||(yield*Xt(t,n+1,r))}}function*Qt(e,t,n,r,i){let a=Object.entries(t);yield I(r,Ht(a.length,{key:e,fields:n,delimiter:i.delimiter,keyed:!0}),i.indentSize),yield*$t(a,n,r+1,i)}function*$t(e,t,n,r){for(let[i,a]of e){let e=Kt(a,t);yield I(n,`${Bt(i)}: ${Vt(e,r.delimiter)}`,r.indentSize)}}function*en(e,t,n,r){if(t.length===0){yield I(n,e==null?`[]`:`${Bt(e)}: []`,r.indentSize);return}if(At(t)){yield I(n,nn(t,r.delimiter,e),r.indentSize);return}if(jt(t)&&t.every(e=>At(e))){yield*tn(e,t,n,r);return}if(Mt(t)){let i=Wt(t);i?yield*rn(e,t,i,n,r):yield*on(e,t,n,r);return}yield*on(e,t,n,r)}function*tn(e,t,n,r){yield I(n,Ht(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)if(At(e)){let t=nn(e,r.delimiter);yield L(n+1,t,r.indentSize)}}function nn(e,t,n){let r=Ht(e.length,{key:n,delimiter:t}),i=Vt(e,t);return e.length===0?r:`${r} ${i}`}function*rn(e,t,n,r,i){yield I(r,Ht(t.length,{key:e,fields:n,delimiter:i.delimiter}),i.indentSize),yield*an(t,n,r+1,i)}function*an(e,t,n,r){for(let i of e)yield I(n,Vt(Kt(i,t),r.delimiter),r.indentSize)}function*on(e,t,n,r){yield I(n,Ht(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)yield*cn(e,n+1,r)}function*sn(e,t,n){if(Ot(e)){yield I(t,`-`,n.indentSize);return}let r=Object.entries(e),[i,a]=r[0],o=r.slice(1);if(Et(a)&&Mt(a)){let e=Wt(a);if(e){yield L(t,Ht(a.length,{key:i,fields:e,delimiter:n.delimiter}),n.indentSize),yield*an(a,e,t+2,n),o.length>0&&(yield*Xt(Object.fromEntries(o),t+1,n));return}}if(Dt(a)){let e=Gt(a);if(e){let r=Object.entries(a);yield L(t,Ht(r.length,{key:i,fields:e,delimiter:n.delimiter,keyed:!0}),n.indentSize),yield*$t(r,e,t+2,n),o.length>0&&(yield*Xt(Object.fromEntries(o),t+1,n));return}}let s=Bt(i);if(Tt(a))yield L(t,`${s}: ${Rt(a,n.delimiter)}`,n.indentSize);else if(Et(a)){if(a.length===0)yield L(t,`${s}: []`,n.indentSize);else if(At(a))yield L(t,`${s}${nn(a,n.delimiter)}`,n.indentSize);else{yield L(t,`${s}${Ht(a.length,{delimiter:n.delimiter})}`,n.indentSize);for(let e of a)yield*cn(e,t+2,n)}}else Dt(a)&&(yield L(t,`${s}:`,n.indentSize),Ot(a)||(yield*Xt(a,t+2,n)));o.length>0&&(yield*Xt(Object.fromEntries(o),t+1,n))}function*cn(e,t,n){if(Tt(e))yield L(t,Rt(e,n.delimiter),n.indentSize);else if(Et(e)){if(At(e))yield L(t,nn(e,n.delimiter),n.indentSize);else{yield L(t,Ht(e.length,{delimiter:n.delimiter}),n.indentSize);for(let r of e)yield*cn(r,t+1,n)}}else Dt(e)&&(yield*sn(e,t,n))}function I(e,t,n){return` `.repeat(n*e)+t}function L(e,t,n){return I(e,`- `+t,n)}function ln(e,t){let n=t(``,e,[]);return n===void 0?dn(e,t,[]):un(e,n,t,[])}function un(e,t,n,r){return bt(t)&&!Tt(e)?dn(e,n,r):dn(St(t),n,r)}function dn(e,t,n){return Dt(e)?fn(e,t,n):Et(e)?pn(e,t,n):e}function fn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=[...n,i],o=t(i,a,e);o!==void 0&&_t(r,i,un(a,o,t,e))}return r}function pn(e,t,n){let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=[...n,i],s=t(String(i),a,o);s!==void 0&&r.push(un(a,s,t,o))}return r}function mn(e,t){return Array.from(hn(e,t)).join(`
|
|
4
|
-
`)}function
|
|
5
|
-
`)}const
|
|
2
|
+
globalThis.__SKILL_SCRIPT__ = {"package":"cyber-agentkit","bin":"cyber-agentkit","version":"2.0.0","entry":"skills/asset/scripts/asset.mjs","commands":{}};
|
|
3
|
+
import{createRequire as e}from"node:module";import{fileURLToPath as t}from"node:url";import{copyFileSync as n,existsSync as r,lstatSync as i,mkdirSync as a,readFileSync as o,readdirSync as s,realpathSync as c,rmSync as l,rmdirSync as u,statSync as d,writeFileSync as f}from"node:fs";import{basename as p,dirname as m,extname as h,isAbsolute as g,join as _,posix as v,relative as y,resolve as b,sep as x,win32 as S}from"node:path";import{inspect as C,styleText as w}from"node:util";import{homedir as T}from"node:os";import{readFile as E,readdir as D}from"node:fs/promises";import{execFileSync as ee}from"node:child_process";var O=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),te=/* @__PURE__ */ e(import.meta.url),ne=`2.0.0`,k=`cyber-agentkit`,re;const A={success:0,error:1,usage:2},ie=Symbol.for(`clibuilder.CliError`),ae=Symbol.for(`clibuilder.CliError.reported`),oe=[`error`,`code`,`help`];var j=class e extends Error{static reported(t=A.error,n=`the error was already reported`){let r=new e(n,{exitCode:t});return r[ae]=!0,r}constructor(e,t){let n=typeof e==`string`?{...t,message:e}:e;super(n.message),this.name=`CliError`,this[re]=!0,this.exitCode=le(n.exitCode??A.error),this.code=ue(n.code??`error`),this.details=de(n.details??{}),this.help=n.help===void 0?[]:typeof n.help==`string`?[n.help]:[...n.help],this.cause=n.cause}};re=ie;function se(e){return!!e&&typeof e==`object`&&e[ie]===!0}function ce(e){return e[ae]===!0}function le(e){if(Number.isInteger(e)&&e>=1&&e<=255)return e;throw RangeError(`CliError exitCode must be an integer from 1 to 255, received ${e}`)}function ue(e){if(/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))return e;throw RangeError(`CliError code must be a kebab-case string such as "not-found", received "${e}"`)}function de(e){for(let t of oe)if(t in e)throw RangeError(`CliError details may not have the key "${t}"`);return{...e}}function M(e){return e}function fe(e){let t=e.kind===`array`?e.element:e;return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function pe(e){switch(e.kind){case`string`:return e.pattern?`string ${e.pattern}`:`string`;case`number`:case`int`:return`${e.kind}${me(e.min,e.max)}`;case`boolean`:case`json`:return e.kind;case`literal`:return String(e.value);case`enum`:return e.values.join(`|`);case`custom`:return`value`;case`array`:return pe(e.element)}}function me(e,t){return e!==void 0&&t!==void 0?` ${e}..${t}`:e===void 0?t===void 0?``:` <=${t}`:` >=${e}`}const he={optional(){return ge({...this,isOptional:!0})},check(e){let t=typeof e==`function`?{type:`fn`,fn:e}:{type:`schema`,schema:e};if(typeof e!=`function`&&!ve(e))throw TypeError(`check() takes a function or a Standard Schema`);return ge({...this,checks:[...this.checks,t]})}};function ge(e){return Object.freeze(Object.assign(Object.create(he),e))}function _e(e){return ge({...e,isOptional:!1,checks:Object.freeze([])})}function ve(e){let t=e?.[`~standard`];return typeof t==`object`&&!!t&&typeof t.validate==`function`}function ye(e,t,n){let{min:r,max:i}=t??{};for(let[t,a]of[[`min`,r],[`max`,i]])if(a!==void 0){if(typeof a!=`number`||Number.isNaN(a))throw TypeError(`${e}: ${t} must be a number`);if(n&&Number.isFinite(a)&&!Number.isInteger(a))throw RangeError(`${e}: ${t} must be an integer, got ${a}`)}if(r!==void 0&&i!==void 0&&r>i)throw RangeError(`${e}: min (${r}) is greater than max (${i})`);return{...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}}function be(e){let t=e?.pattern;if(t!==void 0&&!(t instanceof RegExp))throw TypeError(`t.string: pattern must be a RegExp`);return _e(t===void 0?{kind:`string`}:{kind:`string`,pattern:t})}function xe(e){if(e===void 0)return _e({kind:`json`});if(!ve(e))throw TypeError(`t.json: schema must be a Standard Schema`);return _e({kind:`json`,schema:e})}const N={string:be,number(e){return _e({kind:`number`,...ye(`t.number`,e,!1)})},int(e){return _e({kind:`int`,...ye(`t.int`,e,!0)})},boolean(){return _e({kind:`boolean`})},literal(e){let t=typeof e;if(!(t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)))throw TypeError(`t.literal: value must be a string, a finite number or a boolean, got ${String(e)}`);return _e({kind:`literal`,value:e})},enum(e){if(!Array.isArray(e)||e.length===0)throw TypeError(`t.enum: values must be a non-empty array`);for(let t of e)if(typeof t!=`string`)throw TypeError(`t.enum: values must be strings, got ${String(t)}`);return _e({kind:`enum`,values:Object.freeze([...e])})},array(e){let t=e;if(typeof t?.kind!=`string`||!Object.prototype.isPrototypeOf.call(he,t))throw TypeError(`t.array: element must be a descriptor`);if(t.kind===`array`)throw TypeError(`t.array: element cannot be an array`);if(t.isOptional)throw TypeError(`t.array: element cannot be optional`);return _e({kind:`array`,element:e})},custom(e){if(typeof e!=`function`)throw TypeError(`t.custom: convert must be a function`);return _e({kind:`custom`,convert:e})},json:xe};function Se(e){return typeof e==`object`&&!!e&&Object.prototype.isPrototypeOf.call(he,e)}String.prototype.charCodeAt;const Ce=String.prototype.slice;Array.prototype.forEach,Array.prototype.map,Array.prototype.reduce;const we=Array.prototype.slice,Te=Array.prototype.push,Ee={modifiers:`-`,terminator:`--`};function De(e){let t=/* @__PURE__ */ new Set,n=e?.modifiers??Ee.modifiers;for(let e of typeof n==`string`?Array.from(n):n){if(e.length!==1||e===`=`)throw Error(`Invalid modifier '${e}': a modifier must be a single character other than '='`);t.add(e)}if(t.size===0)throw Error(`At least one modifier is required`);let r=e?.terminator??Ee.terminator;if(r===``)throw Error(`The terminator must not be empty`);return{modifiers:t,terminator:r}}function Oe(e,t){let n=0;for(;n<e.length&&t.has(e[n]);)n++;return[Ce.call(e,n),n]}function ke(e,t){let{modifiers:n,terminator:r}=De(t),i=[],a=0,o=we.call(e);for(;o.length>0;){let e=o.shift();if(e===r){Te.call(i,{kind:`option-terminator`,index:a}),a++,Te.apply(i,o.map((e,t)=>({kind:`positional`,index:a+t,value:e})));break}let[t,s]=Oe(e,n);if(s===0||!t)Te.call(i,{kind:`positional`,index:a,value:t||e});else{let n=t.indexOf(`=`),[r,o]=n===-1?[t,void 0]:[Ce.call(t,0,n),Ce.call(t,n+1)];Te.call(i,{kind:`option`,index:a,name:r,dashes:s,raw:e,value:o})}a++}return i}var Ae=class extends Error{constructor(e,t,n,r={}){super(e),Object.defineProperty(this,"option",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"input",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"kind",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"issues",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"detail",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=`ParseArgsError`,this.kind=r.kind??`invalid-value`,this.index=r.index,this.issues=r.issues,this.value=r.value,this.detail=r.detail??e}};function je(e){let t=Pe(e),n=t.next();for(;!n.done;){let{value:e,option:r}=n.value;if(Ne(e))throw e.then(void 0,()=>{}),t.return(void 0),Error(`Option '${r}' has an asynchronous converter or check: use parseArgsAsync() to parse it`);n=t.next(e)}return n.value}async function Me(e){let t=Pe(e),n=t.next();for(;!n.done;)n=await Promise.resolve(n.value.value).then(e=>t.next(e),e=>t.throw(e));return n.value}function Ne(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&typeof e.then==`function`}function*Pe(e){let t=ke(e.args,e.grammar),n=e.options;Fe(n);let r=Le(n),i=Object.create(null),a=Object.create(null),o=[],s=[],c=t.slice();for(;c.length>0;){let t=c.shift();switch(t.kind){case`positional`:Ie(e,t.value),o.push(t.value);break;case`option`:{let o=t.dashes===1?Array.from(t.name):[t.name];for(let s=0;s<o.length;s++){let l=o[s],u=s===o.length-1,d=r.get(l)??l,f=n?.[d];if(e.strict&&!f)throw new Ae(`Unknown option '${l}' (from '${t.raw}')`,l,t.raw,{kind:`unknown-option`});if(!u&&f&&ze(f))throw new Ae(`Invalid option group '${t.raw}': '${l}' takes a value, so it can only be the last option in a group`,d,t.raw,{kind:`invalid-group`,detail:`takes a value, so it can only be the last option in a group`});let p=u?t.value??Ve(f,c):void 0;if(f&&Se(f.type)){let e=f.type;if(e.kind===`array`){let n=i[d]??(i[d]=[]);(a[d]??(a[d]=[])).push(t.raw);let r={name:d,label:`${d}[${n.length}]`,index:n.length,token:t};n.push(yield*Je(e.element,p,r))}else i[d]=yield*Je(e,p,{name:d,label:d,index:void 0,token:t});continue}let m=He(f,d,p,t);f?.multiple?(i[d]??(i[d]=[])).push(m):i[d]=m}break}case`option-terminator`:for(let t of c)Ie(e,t.value);s.push(...c.map(e=>e.value)),c.length=0}}for(let[e,t]of Object.entries(n??{})){let n=Se(t.type)?t.type:void 0;if(i[e]!==void 0){if(n?.kind===`array`){let t=a[e].join(` `);yield*$e(n,i[e],e,(n,r)=>qe(e,e,t,n,{issues:r}))}continue}if(t.default!==void 0)n&&(yield*tt(t,e)),i[e]=Array.isArray(t.default)?[...t.default]:t.default;else if(n&&!n.isOptional)throw new Ae(`Missing required option '${e}'`,e,``,{kind:`missing-option`,detail:`a value is required`})}let l={_:o,__:s,options:i};return e.tokens&&(l.tokens=t),l}function Fe(e){for(let[t,n]of Object.entries(e??{})){let e=n.type;if(typeof e==`object`&&e&&!Se(e))throw TypeError(`Option '${t}' has a type that is neither a type name nor a descriptor from t`);if(Se(e)&&n.multiple!==void 0)throw TypeError(`Option '${t}' cannot set 'multiple' with a descriptor: use t.array(element)`)}}function Ie(e,t){if(e.allowPositionals===!1)throw new Ae(`Unexpected positional argument '${t}'`,void 0,t,{kind:`unexpected-positional`})}function Le(e){let t=/* @__PURE__ */ new Map;if(!e)return t;for(let n of Object.keys(e))t.set(n,n);for(let[n,r]of Object.entries(e)){let e=r.alias;for(let r of e===void 0?[]:Array.isArray(e)?e:[e]){let e=t.get(r);if(e!==void 0&&e!==n)throw Error(`Alias '${r}' of option '${n}' is already used by option '${e}'`);t.set(r,n)}}return t}function Re(e){return e.kind===`array`?e.element:e}function ze(e){if(!Se(e.type))return e.type!==`boolean`;let t=Re(e.type);return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function Be(e){if(!Se(e.type))return e.type===`number`;let t=Re(e.type);return t.kind===`number`||t.kind===`int`||t.kind===`literal`&&typeof t.value==`number`}function Ve(e,t){if(!e||!ze(e))return;let n=t[0];if(n){if(n.kind===`positional`)return t.shift(),n.value;if(n.kind===`option`&&Be(e)&&Number.isFinite(We(n.raw)))return t.shift(),n.raw}}function He(e,t,n,r){if(!e)return n??!0;switch(e.type){case`boolean`:return Ke(t,n,r);case`number`:return Ge(t,n,r);default:if(n===void 0)throw Ue(t,`a value is required`,r,`missing-value`);return n}}function Ue(e,t,n,r,i){return new Ae(`Invalid value for option '${e}': ${t} (from '${n.raw}')`,e,n.raw,{kind:r,value:i,detail:t})}function We(e){return e.trim()===``?NaN:Number(e)}function Ge(e,t,n){if(t===void 0)throw Ue(e,`a number is required`,n,`missing-value`);let r=We(t);if(!Number.isFinite(r))throw Ue(e,t,n,`invalid-value`,t);return r}function Ke(e,t,n){if(t===void 0)return!0;if(t===`false`||t===`f`||t===`0`)return!1;if(t===`true`||t===`t`)return!0;let r=We(t);if(!Number.isNaN(r))return r>0;throw Ue(e,t,n,`invalid-value`,t)}function qe(e,t,n,r,i,a=r){return new Ae(`Invalid value for option '${t}': ${a} (from '${n}')`,e,n,{...i,detail:r})}function*Je(e,t,n){let r=(e,r,i)=>qe(n.name,n.label,n.token.raw,e,{index:n.index,issues:r,value:t},i),i=yield*Ze(e,t,n,r);return yield*$e(e,i,n.label,r),i}function Ye(e){return`'${e}'`}function Xe(e){switch(e.kind){case`string`:return`a string matching ${e.pattern}`;case`number`:case`int`:{let t=e.kind===`int`?`an integer`:`a number`;return e.min!==void 0&&e.max!==void 0?`${t} from ${e.min} to ${e.max}`:e.min===void 0?e.max===void 0?t:`${t} of at most ${e.max}`:`${t} of at least ${e.min}`}case`boolean`:return`no value, true or false`;case`literal`:return typeof e.value==`string`?Ye(e.value):String(e.value);case`enum`:return`one of ${e.values.map(Ye).join(`, `)}`}}function*Ze(e,t,n,r){let i=e=>r(`expected ${Xe(e)}`,void 0,`expected ${Xe(e)}, got ${Ye(t)}`);if(e.kind===`boolean`||e.kind===`literal`&&typeof e.value==`boolean`){let n=t===void 0||t===`true`||t!==`false`&&void 0;if(n===void 0||e.kind===`literal`&&n!==e.value)throw t===void 0?r(`expected ${Xe(e)}`,void 0,`expected ${Xe(e)}, got no value`):i(e);return n}if(t===void 0)throw qe(n.name,n.label,n.token.raw,`a value is required`,{kind:`missing-value`,index:n.index});switch(e.kind){case`string`:if(e.pattern&&(e.pattern.lastIndex=0,!e.pattern.test(t)))throw i(e);return t;case`number`:case`int`:{let n=We(t);if(!Number.isFinite(n)||e.kind===`int`&&!Number.isInteger(n)||e.min!==void 0&&n<e.min||e.max!==void 0&&n>e.max)throw i(e);return n}case`literal`:{let n=typeof e.value==`number`?We(t):t;if(n!==e.value)throw i(e);return n}case`enum`:if(!e.values.includes(t))throw i(e);return t;case`custom`:try{return yield{value:e.convert(t),option:n.label}}catch(e){throw Qe(e,r)}case`json`:{let i;try{i=JSON.parse(t)}catch{throw r(`not valid JSON`,void 0,`${Ye(t)} is not valid JSON`)}if(!e.schema)return i;let a=yield{value:e.schema[`~standard`].validate(i),option:n.label};if(a.issues)throw r(`does not match the expected shape`,a.issues);return a.value}}}function Qe(e,t){return e instanceof Error&&e.constructor===Error?t(e.message):e}function*$e(e,t,n,r){for(let i of e.checks)if(i.type===`fn`){let e=yield{value:i.fn(t),option:n};if(e===!1)throw r(`failed a check`);if(typeof e==`string`)throw r(e)}else{let e=yield{value:i.schema[`~standard`].validate(t),option:n};if(e.issues)throw r(`failed a check`,e.issues)}}const et=/* @__PURE__ */ new WeakMap;function*tt(e,t){if(et.has(e))return;let n=e.type,r=e=>t=>/* @__PURE__ */ Error(`The default of option '${e}' failed a check${t===`failed a check`?``:`: ${t}`}`);if(n.kind===`array`){let i=e.default;for(let e=0;e<i.length;e++){let a=`${t}[${e}]`;yield*$e(n.element,i[e],a,r(a))}}yield*$e(n,e.default,t,r(t)),et.set(e,!0)}const nt=/* @__PURE__ */ new WeakMap;function rt(e,t,n){let r=it(e,at(t,n)),[i,a]=ot(t,r,n);return dt(r,i,a)}function it(e,t){if(e.commands){let n=e.commands,r=t.peek(e);for(let e=n.length-1;e>=0;e--){let i=n[e];if(!i.name)return i;if(r===i.name||i.alias?.includes(r))return t.consume(),i.commands?it(i,t):i}}return e}function at(e,t){let n=nt.get(e)??[],r,i=-1,a=0;return{peek(o){if(r=void 0,i<0){if(a<e._.length)return(r=[e._,a])[0][a];i=0,a=-1}for(;t&&i<n.length;){let e=n[i];if(a<0){let n=P(t,e.key)[1];if(!n)return;a=st(P(o,e.key)[1]??n,e)}if(a<e.following.length)return(r=[e.following,a])[0][a];i++,a=-1}},consume(){r[0].splice(r[1],1)}}}function ot(e,t,n){let r=nt.get(e);if(!r)return[e,void 0];let i={},a=[],o=[];for(let e of r){let r=P(t,e.key)[1],s=st(r??(n&&P(n,e.key)[1]),e),c=e.following.slice(0,s);r&&o.push({key:e.key,tokens:[e.raw,...c]}),a.push(...e.following.slice(s));let l=e.inline.length+c.length>0?[...e.inline,...c]:[`true`];i[e.key]=[...i[e.key]??[],...l]}let s={...e,_:[...e._,...a]};for(let t of Object.keys(i))e[t]&&(s[t]=i[t]);return[s,o]}function st(e,t){return e?t.inline.length===0&&fe(ut(e))?1:0:t.following.length}const ct=N.boolean().optional(),lt=N.string();function ut(e){return e.type??ct}function dt(e,t,n){return ht(mt(pt(ft({command:e,rawArgs:t,args:{_:[]},errors:[],descriptors:[]}))),n)}function ft(e){let t=e.command,n=[...e.rawArgs._],r=t.arguments||[];for(let t of r){let r=t.type??lt;if(n.length===0){r.isOptional||e.errors.push({type:`missing-argument`,name:t.name});continue}let i=r.kind===`array`?n.splice(0):[n.shift()];e.descriptors.push({type:`argument`,name:t.name,descriptor:r,values:i})}return n.length>0&&e.errors.push({type:`extra-arguments`,name:t.name,values:n}),e}function pt(e){for(let t of Object.keys(e.rawArgs)){if(t===`_`)continue;if(/^-/.test(t)){e.errors.push({type:`invalid-key`,key:t});continue}let[n,r]=P(e.command,t);if(!n){e.errors.push({type:`invalid-key`,key:t});continue}let i=ut(r),a=e.rawArgs[t];i.kind!==`array`&&a.length>1&&e.errors.push({type:`expect-single`,key:t,keyKind:i.kind,value:a})}return e}function mt(e){let t=e.command.options;if(!t)return e;let n=/* @__PURE__ */ new Map;for(let t of Object.keys(e.rawArgs)){let[r]=P(e.command,t);r&&!n.has(r)&&n.set(r,t)}let r=[...n.keys()];for(let i=0;i<r.length;i++)for(let a=i+1;a<r.length;a++){let[o,s]=[r[i],r[a]];if(!t[o].conflicts?.includes(s)&&!t[s].conflicts?.includes(o))continue;let[c,l]=t[o].conflicts?.includes(s)?[o,s]:[s,o];e.errors.push({type:`conflicting-options`,key:n.get(c),conflictsWith:n.get(l)})}return e}function ht(e,t){let n=e.command.options??{};for(let r of Object.keys(n)){let i=n[r],a=Object.keys(e.rawArgs).filter(t=>t!==`_`&&P(e.command,t)[0]===r);e.errors.some(e=>e.type===`expect-single`&&a.includes(e.key))||e.descriptors.push({type:`option`,name:r,entry:{...i,type:ut(i)},occurrences:t?t.filter(e=>a.includes(e.key)):a.flatMap(t=>e.rawArgs[t].map(e=>({key:t,tokens:[`--${r}=${e}`]})))})}return e}function P(e,t){let n=e.options;if(!n)return[];let r=n[t];if(r)return[t,r];let i=Object.keys(n).find(e=>{let r=n[e];return r.alias?r.alias.some(e=>e===t||e.alias===t):!1});return i?[i,n[i]]:[]}const gt={comma:`,`,tab:` `,pipe:`|`},_t=gt.comma;function vt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`).replace(/[\u0000-\u001F]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function yt(e){return e===`true`||e===`false`||e===`null`}function bt(e,t,n){if(t===`__proto__`){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0});return}e[t]=n}const xt=/* @__PURE__ */ RegExp(`(?:^?|\\n) *#`);var St=class{constructor(e){if(xt.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function Ct(e){return e instanceof St}const wt=/[\uD800-\uDFFF]/;function Tt(e){if(e===null)return null;if(Ct(e))return e;if(typeof e==`object`&&e&&`toJSON`in e&&typeof e.toJSON==`function`){let t=e.toJSON();if(t!==e)return Tt(t)}if(typeof e==`string`)return Et(e,`string value`),e;if(typeof e==`boolean`)return e;if(typeof e==`number`)return Object.is(e,-0)?0:Number.isFinite(e)?e:null;if(typeof e==`bigint`)return e>=-(2**53-1)&&e<=2**53-1?Number(e):e.toString();if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(Tt);if(e instanceof Set)return Array.from(e).map(Tt);if(e instanceof Map)return Object.fromEntries(Array.from(e,([e,t])=>[String(e),Tt(t)]));if(Mt(e)){let t={};for(let n in e)Object.hasOwn(e,n)&&(Et(n,`object key`),bt(t,n,Tt(e[n])));return t}return null}function Et(e,t){if(wt.test(e))for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<55296||r>57343)continue;let i=r<=56319,a=e.charCodeAt(n+1);if(i&&a>=56320&&a<=57343){n++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${r.toString(16).toUpperCase()} at index ${n}`)}}function Dt(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function Ot(e){return Dt(e)||Ct(e)}function kt(e){return Array.isArray(e)}function At(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!Ct(e)}function jt(e){return Object.keys(e).length===0}function Mt(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function Nt(e){return e.length===0||e.every(e=>Ot(e))}function Pt(e){return e.length===0||e.every(e=>kt(e))}function Ft(e){return e.length===0||e.every(e=>At(e))}const It=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Lt(e){if(!Object.values(gt).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Rt(e){return/^[A-Z_][\w.]*$/i.test(e)}function zt(e,t=_t){return!(!e||/^[ \t]|[ \t]$/.test(e)||yt(e)||Bt(e)||e.includes(`:`)||e.includes(`"`)||e.includes(`\\`)||/[[\]{}]/.test(e)||/[\u0000-\u001F]/.test(e)||e.includes(t)||e.startsWith(`-`)||e.startsWith(`#`))}function Bt(e){return It.test(e)}function Vt(e,t){return Ct(e)?e.value:e===null?`null`:typeof e==`boolean`||typeof e==`number`?String(e):Ht(e,t)}function Ht(e,t=_t){return zt(e,t)?e:`"${vt(e)}"`}function Ut(e){return Rt(e)?e:`"${vt(e)}"`}function Wt(e,t=_t){return e.map(e=>Vt(e,t)).join(t)}function Gt(e,t){let n=t?.key,r=t?.fields,i=t?.delimiter??`,`,a=``;return n!=null&&(a+=Ut(n)),a+=`[${e}${t?.keyed?`:`:``}${i===_t?``:i}]`,r&&(a+=`{${Kt(r,i)}}`),a+=`:`,a}function Kt(e,t){return e.map(e=>Ut(e.name)+(e.children?`{${Kt(e.children,t)}}`:``)).join(t)}function qt(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let e of t)if(!Object.hasOwn(n,e))return}let n=[];for(let r of t){let t=Xt(r,e.map(e=>e[r]));if(!t)return;n.push(t)}return n}function Jt(e){let t=Object.values(e);if(!(t.length<2)&&t.every(e=>At(e)&&!jt(e)))return qt(t)}function Yt(e,t){let n=[];return Zt(e,t,n),n}function Xt(e,t){if(t.every(e=>Ot(e)))return{name:e};if(!t.every(e=>At(e)&&!jt(e)))return;let n=qt(t);if(n)return{name:e,children:n}}function Zt(e,t,n){for(let r of t){let t=e[r.name];r.children?Zt(t,r.children,n):n.push(t)}}function*Qt(e,t,n){if(Ot(e)){let n=Vt(e,t.delimiter);n!==``&&(yield n);return}if(kt(e))yield*rn(void 0,e,n,t);else if(At(e)){let r=Jt(e);if(r){yield*tn(void 0,e,r,n,t);return}yield*$t(e,n,t)}}function*$t(e,t,n){for(let[r,i]of Object.entries(e))yield*en(r,i,t,n)}function*en(e,t,n,r){let i=Ut(e);if(Ot(t))yield F(n,`${i}: ${Vt(t,r.delimiter)}`,r.indentSize);else if(kt(t))yield*rn(e,t,n,r);else if(At(t)){let a=Jt(t);if(a){yield*tn(e,t,a,n,r);return}yield F(n,`${i}:`,r.indentSize),jt(t)||(yield*$t(t,n+1,r))}}function*tn(e,t,n,r,i){let a=Object.entries(t);yield F(r,Gt(a.length,{key:e,fields:n,delimiter:i.delimiter,keyed:!0}),i.indentSize),yield*nn(a,n,r+1,i)}function*nn(e,t,n,r){for(let[i,a]of e){let e=Yt(a,t);yield F(n,`${Ut(i)}: ${Wt(e,r.delimiter)}`,r.indentSize)}}function*rn(e,t,n,r){if(t.length===0){yield F(n,e==null?`[]`:`${Ut(e)}: []`,r.indentSize);return}if(Nt(t)){yield F(n,on(t,r.delimiter,e),r.indentSize);return}if(Pt(t)&&t.every(e=>Nt(e))){yield*an(e,t,n,r);return}if(Ft(t)){let i=qt(t);i?yield*sn(e,t,i,n,r):yield*ln(e,t,n,r);return}yield*ln(e,t,n,r)}function*an(e,t,n,r){yield F(n,Gt(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)if(Nt(e)){let t=on(e,r.delimiter);yield I(n+1,t,r.indentSize)}}function on(e,t,n){let r=Gt(e.length,{key:n,delimiter:t}),i=Wt(e,t);return e.length===0?r:`${r} ${i}`}function*sn(e,t,n,r,i){yield F(r,Gt(t.length,{key:e,fields:n,delimiter:i.delimiter}),i.indentSize),yield*cn(t,n,r+1,i)}function*cn(e,t,n,r){for(let i of e)yield F(n,Wt(Yt(i,t),r.delimiter),r.indentSize)}function*ln(e,t,n,r){yield F(n,Gt(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)yield*dn(e,n+1,r)}function*un(e,t,n){if(jt(e)){yield F(t,`-`,n.indentSize);return}let r=Object.entries(e),[i,a]=r[0],o=r.slice(1);if(kt(a)&&Ft(a)){let e=qt(a);if(e){yield I(t,Gt(a.length,{key:i,fields:e,delimiter:n.delimiter}),n.indentSize),yield*cn(a,e,t+2,n),o.length>0&&(yield*$t(Object.fromEntries(o),t+1,n));return}}if(At(a)){let e=Jt(a);if(e){let r=Object.entries(a);yield I(t,Gt(r.length,{key:i,fields:e,delimiter:n.delimiter,keyed:!0}),n.indentSize),yield*nn(r,e,t+2,n),o.length>0&&(yield*$t(Object.fromEntries(o),t+1,n));return}}let s=Ut(i);if(Ot(a))yield I(t,`${s}: ${Vt(a,n.delimiter)}`,n.indentSize);else if(kt(a)){if(a.length===0)yield I(t,`${s}: []`,n.indentSize);else if(Nt(a))yield I(t,`${s}${on(a,n.delimiter)}`,n.indentSize);else{yield I(t,`${s}${Gt(a.length,{delimiter:n.delimiter})}`,n.indentSize);for(let e of a)yield*dn(e,t+2,n)}}else At(a)&&(yield I(t,`${s}:`,n.indentSize),jt(a)||(yield*$t(a,t+2,n)));o.length>0&&(yield*$t(Object.fromEntries(o),t+1,n))}function*dn(e,t,n){if(Ot(e))yield I(t,Vt(e,n.delimiter),n.indentSize);else if(kt(e)){if(Nt(e))yield I(t,on(e,n.delimiter),n.indentSize);else{yield I(t,Gt(e.length,{delimiter:n.delimiter}),n.indentSize);for(let r of e)yield*dn(r,t+1,n)}}else At(e)&&(yield*un(e,t,n))}function F(e,t,n){return` `.repeat(n*e)+t}function I(e,t,n){return F(e,`- `+t,n)}function fn(e,t){let n=t(``,e,[]);return n===void 0?mn(e,t,[]):pn(e,n,t,[])}function pn(e,t,n,r){return Ct(t)&&!Ot(e)?mn(e,n,r):mn(Tt(t),n,r)}function mn(e,t,n){return At(e)?hn(e,t,n):kt(e)?gn(e,t,n):e}function hn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=[...n,i],o=t(i,a,e);o!==void 0&&bt(r,i,pn(a,o,t,e))}return r}function gn(e,t,n){let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=[...n,i],s=t(String(i),a,o);s!==void 0&&r.push(pn(a,s,t,o))}return r}function _n(e,t){return Array.from(vn(e,t)).join(`
|
|
4
|
+
`)}function vn(e,t){let n=Tt(e),r=yn(t);return Qt(r.replacer?fn(n,r.replacer):n,r,0)}function yn(e){let t=e?.delimiter??_t;return Lt(t),{indentSize:e?.indentSize??e?.indent??2,delimiter:t,replacer:e?.replacer}}function bn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xn(e){return e===void 0?``:String(e)}function Sn(e){let t=[...new Set(e.flatMap(e=>Object.keys(e)))],n=t.map(t=>Math.max(t.length,...e.map(e=>xn(e[t]).length))),r=e=>` ${e.map((e,t)=>e.padEnd(n[t])).join(` `)}`.trimEnd();return[r(t),...e.map(e=>r(t.map(t=>xn(e[t]))))]}function Cn(e){let t=Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>{if(!Array.isArray(t))return[`${e}: ${bn(t)?JSON.stringify(t):String(t)}`];if(!t.length)return[`${e}: (none)`];let n=t.every(bn)?Sn(t):t.map(e=>` - ${String(e)}`);return[`${e}:`,...n]});return t.flatMap((e,n)=>{let r=t[n-1];return r&&(r.length>1||e.length>1)?[``,...e]:e}).join(`
|
|
5
|
+
`)}const wn=[`toon`,`json`,`text`];function Tn(e,t){return t===`json`?JSON.stringify(e):t===`text`?Cn(e):_n(e)}function En({message:e,code:t,details:n,help:r}){let i={error:e,code:t,...n};return r&&r.length>0&&(i.help=[...r]),i}const Dn=Symbol.for(`clibuilder.global-format`),On=Symbol.for(`clibuilder.defers-to-global-format`);function kn(e,t){return M({name:``,description:e,options:{help:{type:N.boolean().optional(),description:`Print help message`,alias:[`h`]},version:{type:N.boolean().optional(),description:`Print the CLI version`,alias:[`v`]},verbose:{type:N.boolean().optional(),description:`Turn on verbose logging`,alias:[`V`]},silent:{type:N.boolean().optional(),description:`Turn off logging`},"debug-cli":{type:N.boolean().optional(),description:`Display clibuilder debug messages`},...t?.options,format:An(t?.format??`toon`)},commands:[]})}function An(e){return Object.defineProperty({type:N.enum(wn),description:`Output format: 'toon' for agents, 'json' to pipe, 'text' for humans`,default:e},Dn,{value:!0})}function jn(e){return!!e&&e[Dn]===!0}function Mn(e){let[t,n]=P(e,`format`);if(!t||jn(n))return e;if(!n[On]){let n=e.name?`command '${e.name}'`:`the default command`;throw Error(`${n} declares its own option '${t}', which conflicts with the global --format option. Delete the local declaration and read this.format in run() instead. See docs/rfcs/axi-native.md section 3.4: https://github.com/clibuilder/clibuilder/blob/main/docs/rfcs/axi-native.md#34---format-is-not-first-class-6394`)}let{[t]:r,...i}=e.options;return{...e,options:i}}function Nn(e){return{id:e,kind:`value`}}function Pn(){let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map;function n(n){return n.kind===`collection`?t.get(n.id)??[]:e.get(n.id)?.value}return{register(n,r,i){if(r.kind===`collection`){let e=t.get(r.id)??[];return e.push({source:n,value:i}),t.set(r.id,e),{accepted:!0}}let a=e.get(r.id);return a?{accepted:!1,source:a.source}:(e.set(r.id,{source:n,value:i}),{accepted:!0})},get:n,has(n){return n.kind===`collection`?t.has(n.id):e.has(n.id)},describe(n){if(n.kind===`collection`)return(t.get(n.id)??[]).map(({source:e})=>e);let r=e.get(n.id)?.source;return r?[r]:[]}}}const Fn=Nn(`clibuilder.config`);function In(e){let t=[],n=e.slice(2).reduce((e,n)=>(e.args.__?e.args.__.push(n):Rn(n)?(Ln(e)&&(e=Un(e)),e=zn(e,n,t)):Ln(e)?(e.values.push(n),t[t.length-1].following.push(n)):n===`--`?e.args.__=[]:e.args._.push(n),e),{args:{_:[]},key:``,values:[]}),r=(Ln(n)?Un(n):n).args;return nt.set(r,t),r}function Ln(e){return!!e.key}function Rn(e){return e.startsWith(`-`)&&/\w+/.test(e)}function zn(e,t,n){return e=/^-\w+/.test(t)?Bn(e,t,n):Hn(e,t),n.push({key:e.key,raw:t,inline:[...e.values],following:[]}),e}function Bn(e,t,n){let r=t.indexOf(`=`),[i,a]=r>0?[t.slice(1,r),[t.slice(r+1)]]:[t.slice(1),[]],o=i.split(``),s=o.pop();for(let e of o)n.push({key:e,raw:t,inline:[`true`],following:[]});return e=Vn(e,o),e.key=s,e.values=a,e}function Vn(e,t){return t.length<=0?e:(e.key=t.pop(),e.values=[`true`],Vn(Un(e),t))}function Hn(e,t){let n=t.indexOf(`=`);return n>0?(e.key=t.slice(2,n),e.values=[t.slice(n+1)]):(e.key=t.slice(2),e.values=[]),e}function Un(e){let{key:t,values:n}=e,r={...e.args};return r[t]||(r[t]=[]),n.length===0?r[t].push(`true`):r[t].push(...n),{args:r,key:``,values:[]}}const Wn=/* @__PURE__ */ new WeakMap;async function Gn(e){for(let t of e.descriptors)try{Yn(e,t,await Me(Jn(t)))}catch(n){Xn(e,t,n)}}function Kn(e){for(let t of e.descriptors)try{Yn(e,t,je(Jn(t)))}catch(n){Xn(e,t,n)}}function qn(e,t){let n={...e,args:{...e.args},errors:[],descriptors:e.descriptors.filter(e=>e.type===`option`&&t.includes(e.name)&&e.entry.type.kind===`boolean`&&e.entry.type.checks.length===0)};return Kn(n),n.args}function Jn(e){return e.type===`option`?{args:e.occurrences.flatMap(e=>e.tokens),options:{[e.name]:Zn(e.entry)}}:{args:e.values.map(t=>`--${e.name}=${t}`),options:{[e.name]:{type:e.descriptor}}}}function Yn(e,t,{options:n}){n[t.name]!==void 0&&(e.args[t.name]=n[t.name])}function Xn(e,t,n){if(!(n instanceof Ae))throw n;e.errors.push(Qn(n,t))}function Zn(e){let t=Wn.get(e);if(!t){let n=e.alias?.map(e=>typeof e==`string`?e:e.alias);t={type:e.type,...n?{alias:n}:{},...e.default===void 0?{}:{default:e.default}},Wn.set(e,t)}return t}function Qn(e,t){if(e.kind===`missing-option`)return{type:`missing-argument`,name:t.name};let n=t.type===`option`?t.entry.type:t.descriptor,r=n.kind===`array`?n.element:n;return{type:`invalid-value`,key:$n(e,t),message:e.detail,value:e.value??(e.kind===`invalid-value`?er(t):void 0),keyKind:n.kind,constraint:pe(r),...r.kind===`enum`?{allowed:r.values}:{},...e.index===void 0?{}:{index:e.index}}}function $n(e,t){if(t.type===`argument`)return t.name;let n=t.occurrences;return(e.index===void 0?n[n.length-1]:n[e.index])?.key??t.name}function er(e){return e.type===`argument`?e.values:e.occurrences.map(e=>e.tokens.join(` `))}const tr=Symbol.for(`clibuilder.answer`);function L(e,t={}){return{[tr]:`result`,value:e,help:ur(t.help),render:t.render}}function R(e){return{[tr]:`document`,value:String(e)}}function nr(e,t={}){return{[tr]:`empty`,value:String(e),help:ur(t.help)}}function rr(e){return typeof e==`object`&&!!e&&typeof e[tr]==`string`}function ir(e){return rr(e)?e.value:e}function ar(e,t){if(e!==void 0){if(!rr(e))return or(e,[],t);switch(e[tr]){case`written`:return;case`document`:return dr(e.value);case`empty`:return dr(Tn(lr({empty:e.value},e.help),t));case`result`:{let n=e.render?.[t];return n?sr(n(e.value),e.help,t):or(e.value,e.help,t)}}}}function or(e,t,n){return typeof e==`string`?sr(e,t,n):dr(Tn(lr(cr(e),t),n))}function sr(e,t,n){return t.length===0?dr(e):dr(`${e}${e.endsWith(`
|
|
6
6
|
`)?`
|
|
7
7
|
`:`
|
|
8
8
|
|
|
9
|
-
`}${
|
|
10
|
-
`)?e:`${e}\n`}function
|
|
9
|
+
`}${Tn({help:[...t]},n)}`)}function cr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{result:e}}function lr(e,t){if(t.length===0)return e;let{help:n,...r}=e;return{...r,help:[...t]}}function ur(e){return e===void 0?[]:typeof e==`string`?[e]:[...e]}function dr(e){return e.endsWith(`
|
|
10
|
+
`)?e:`${e}\n`}function fr(e,t){switch(e.type){case`invalid-key`:return`unknown option ${mr(e.key)}`;case`missing-argument`:return`missing required ${pr(e.name,t,`argument`)}`;case`extra-arguments`:return`unexpected argument${e.values.length>1?`s`:``}: ${e.values.join(`, `)}`;case`invalid-value`:{let n=e.index===void 0?``:`[${e.index}]`,r=e.value===void 0?``:`, received "${e.value}"`;return`invalid value for ${pr(e.key,t)}${n}: ${e.message}${r}`}case`conflicting-options`:return`option ${mr(e.key)} cannot be used with option ${mr(e.conflictsWith)}`;case`expect-single`:return`${pr(e.key,t)} expects a single value, received: ${hr(e.value).join(`, `)}`}}function pr(e,t,n=`option`){return t.arguments?.some(t=>t.name===e)||n===`argument`&&!t.options?.[e]?`argument <${e}>`:`option ${mr(e)}`}function mr(e){return e.length===1?`-${e}`:`--${e}`}function hr(e){return Array.isArray(e)?e:[e]}function gr(e,t){let n=[``];for(let r of e.split(/(\S+\s+)/)){if(r===``)continue;let e=r.replace(/\t/g,` `),i=n.length-1;if(n[i].length+e.length>t){n[i]=n[i].replace(/\s+$/,``);for(let t of e.split(`
|
|
11
11
|
`))n.push(t.replace(/^\s+/,``))}else if(e.includes(`
|
|
12
12
|
`)){let[t,...r]=e.split(`
|
|
13
13
|
`);n[i]+=t;for(let e of r)n.push(e.replace(/^\s+/,``))}else n[i]+=e}return n.join(`
|
|
14
|
-
`)}function
|
|
15
|
-
${[
|
|
14
|
+
`)}function _r(e,t){return`
|
|
15
|
+
${[vr(e,t),br(t),Sr(t),wr(t),Tr(t),jr(t),Mr(t),Pr(t)].filter(e=>!!e).join(`
|
|
16
16
|
|
|
17
17
|
`)}
|
|
18
|
-
`}function
|
|
19
|
-
${
|
|
20
|
-
|
|
21
|
-
${(e.name?`${e.name} <command> -h`:` <command> -h`).padEnd(25)}Get help for <command>`}function
|
|
22
|
-
`,n=[],r=0;e.arguments.forEach(e=>{let t=e.type?
|
|
23
|
-
`),t}function
|
|
24
|
-
`,n=[],r=0;for(let t in e.options){let i=e.options[t],a=
|
|
25
|
-
`),t}function
|
|
26
|
-
${
|
|
27
|
-
${t}`}function
|
|
18
|
+
`}function vr(e,t){let n=xr(e,t),r=t.commands&&t.commands.length>0,i=`Usage: ${n.join(` `)}${r?` <command>`:``}`;if(t.arguments&&(i+=t.arguments.some(e=>yr(e,!0))?` <arguments>`:` [arguments]`),t.options){let e=t.options;i+=Object.keys(e).some(t=>yr(e[t],!1))?` <options>`:` [options]`}return i}function yr({type:e,default:t},n){return e?!e.isOptional&&t===void 0:n}function br(e){return e.description?` ${e.description}`:``}function xr(e,t){let n=[t];for(;t.parent;)n.unshift(t.parent),t=t.parent;return[e,...n.map(e=>e.name).filter(e=>e)]}function Sr(e){let t=Cr(e.commands);return t.length===0?``:`Commands:
|
|
19
|
+
${gr(t.join(`, `),80)}
|
|
20
|
+
|
|
21
|
+
${(e.name?`${e.name} <command> -h`:` <command> -h`).padEnd(25)}Get help for <command>`}function Cr(e){let t=[];return e&&e.forEach(e=>{e.alias?t.push(`${e.name} (${e.alias.join(`|`)})`):t.push(e.name)}),t}function wr(e){if(!e.arguments)return``;let t=`Arguments:
|
|
22
|
+
`,n=[],r=0;e.arguments.forEach(e=>{let t=e.type?Or(e.name,e.type):`<${e.name}>`;r=Math.max(r,t.length),n.push([t,e.description||``])});let i=Math.max(23,r+2);return t+=n.map(e=>` ${e[0].padEnd(i)}${e[1]}`.trimEnd()).join(`
|
|
23
|
+
`),t}function Tr(e){if(!e.options)return``;let t=`Options:
|
|
24
|
+
`,n=[],r=0;for(let t in e.options){let i=e.options[t],a=Er(t,i),o=kr(i,Ar(t,e.options));n.push([a,o]),r=Math.max(r,a.length)}let i=Math.max(23,r+2);return t+=n.map(e=>` ${e[0].padEnd(i)}${e[1]}`).join(`
|
|
25
|
+
`),t}function Er(e,t){let n=[...t.alias?t.alias.map(e=>typeof e==`string`?e:e.hidden?void 0:e.alias).filter(e=>e):[],e].sort((e,t)=>e.length-t.length).map(e=>e.length===1?`-${e}`:`--${e}`).join(`|`);return t.type?Dr(n,t.type,yr(t,!1)):`[${n}]`}function Dr(e,t,n){let r=`${e}${fe(t)?` <${pe(t)}>`:``}${t.kind===`array`?`...`:``}`;return n?r:`[${r}]`}function Or(e,t){let n=`${e}: ${pe(t)}${t.kind===`array`?`...`:``}`;return t.isOptional?`[${n}]`:`<${n}>`}function kr(e,t){let n=typeof e.default==`string`?`'${e.default}'`:e.default,r=e.default?`${e.description} (default ${n})`:e.description;return t.length===0?r:`${r} (conflicts with ${t.map(e=>e.length===1?`-${e}`:`--${e}`).join(`, `)})`}function Ar(e,t){return Object.keys(t).filter(n=>n!==e&&(t[e].conflicts?.includes(n)||t[n].conflicts?.includes(e)))}function jr(e){return e.alias?`Alias:
|
|
26
|
+
${gr(e.alias.join(`, `),80)}`:``}function Mr(e){let t=Nr(e);return t===void 0?``:`Config:
|
|
27
|
+
${t}`}function Nr(e){if(e.config)return Fr(e.config)}function Pr(e){return!e.examples||e.examples.length===0?``:`Examples:
|
|
28
28
|
${e.examples.map(e=>` ${e.description}\n ${e.command}`).join(`
|
|
29
|
-
`)}`}function
|
|
30
|
-
`)[0];return n&&(t.description=n),t})),t.arguments&&t.arguments.length>0&&(r.arguments=t.arguments.map(e=>{let t={name:e.name,required:
|
|
29
|
+
`)}`}function Fr(e){let t=e[`~standard`]?.jsonSchema;if(t)try{return Ir(t.input({target:`draft-2020-12`}))}catch{return}}function Ir(e){if(Array.isArray(e.enum))return e.enum.map(e=>JSON.stringify(e)).join(` | `);if(`const`in e)return JSON.stringify(e.const);let t=e.anyOf??e.oneOf;if(Array.isArray(t))return t.map(Ir).join(` | `);switch(e.type){case`object`:{let t=e.properties??{},n=e.required??[],r=Object.keys(t).map(e=>`${e}${n.includes(e)?``:`?`}: ${Ir(t[e])}`);return r.length===0?`{}`:`{ ${r.join(`, `)} }`}case`array`:{let t=e.items&&typeof e.items==`object`?e.items:{};return t.type===`object`?`Array<${Ir(t)}>`:`${Ir(t)}[]`}case`string`:case`boolean`:case`number`:case`null`:return e.type;case`integer`:return`number`;default:return`unknown`}}function Lr(e,t,n){let r={name:xr(e,t).join(` `),usage:vr(e,t).slice(7)};t.description&&(r.description=t.description),t.alias&&t.alias.length>0&&(r.aliases=[...t.alias]),t.commands&&t.commands.length>0&&(r.commands=t.commands.map(e=>{let t={name:e.name};e.alias&&e.alias.length>0&&(t.aliases=[...e.alias]);let n=e.description?.split(`
|
|
30
|
+
`)[0];return n&&(t.description=n),t})),t.arguments&&t.arguments.length>0&&(r.arguments=t.arguments.map(e=>{let t={name:e.name,required:yr(e,!0),...zr(e.type)};return e.description&&(t.description=e.description),t}));let i=!t.parent&&!t.name,a=Rr(t.options,i?Object.keys(n):[]);a.length>0&&(r.options=a);let o=Nr(t);return o!==void 0&&(r.config=o),t.examples&&t.examples.length>0&&(r.examples=t.examples.map(({command:e,description:t})=>({command:e,description:t}))),r.globalOptions=Rr(n,[]),r}function Rr(e,t){return e?Object.keys(e).filter(e=>!t.includes(e)).map(t=>{let n=e[t],r={name:t},i=(n.alias??[]).map(e=>typeof e==`string`?e:e.hidden?void 0:e.alias).filter(e=>!!e);i.length>0&&(r.aliases=i),Object.assign(r,zr(n.type)),r.required=yr(n,!1),n.default!==void 0&&(r.default=n.default),n.description&&(r.description=n.description);let a=Ar(t,e);return a.length>0&&(r.conflicts=a),r}):[]}function zr(e){return e?Br(e):{}}function Br(e){switch(e.kind){case`string`:return e.pattern?{type:`string`,pattern:String(e.pattern)}:{type:`string`};case`number`:case`int`:{let t={type:e.kind};return e.min!==void 0&&(t.min=e.min),e.max!==void 0&&(t.max=e.max),t}case`literal`:return{type:`literal`,values:[e.value]};case`enum`:return{type:`enum`,values:[...e.values]};case`array`:return{...Br(e.element),array:!0};default:return{type:e.kind}}}const Vr={"invalid-key":0,"conflicting-options":1,"invalid-value":2,"expect-single":3,"missing-argument":4,"extra-arguments":5};function Hr(e){return e.reduce((e,t)=>!e||Vr[t.type]<Vr[e.type]?t:e,void 0)}const Ur={"invalid-key":`unknown-option`,"conflicting-options":`conflicting-options`,"invalid-value":`invalid-value`,"expect-single":`expect-single`,"missing-argument":`missing-argument`,"extra-arguments":`extra-arguments`};function Wr(e){return Ur[e.type]}function Gr(e,t,n){let r=vr(n,t),i=fr(e,t),a=Wr(e);switch(e.type){case`invalid-key`:return{message:i,code:a,details:{option:qr(e.key)},help:[r,Qr(t,n)]};case`conflicting-options`:return{message:i,code:a,details:{option:qr(e.key),conflictsWith:qr(e.conflictsWith)},help:[r]};case`invalid-value`:{let n=Jr(e.key,t);return{message:i,code:a,details:{...n.details,...e.value===void 0?{}:{value:ei(e.value)}},help:[r,...$r(e,n.label)]}}case`expect-single`:return{message:i,code:a,details:{...Jr(e.key,t).details,value:ni(e.value).map(String)},help:[r]};case`missing-argument`:return!t.arguments?.some(t=>t.name===e.name)&&t.options?.[e.name]?{message:i,code:a,details:{option:qr(e.name)},help:[r,Qr(t,n)]}:{message:i,code:a,details:{argument:e.name},help:[r,Zr(t,n)]};case`extra-arguments`:return{message:i,code:a,details:{arguments:e.values},help:[r,Zr(t,n)]}}}function Kr(e,t){let n=Yr(e,t),r=(e.commands??[]).map(e=>e.name);return{message:`missing command for \`${n}\``,code:`missing-command`,details:{command:n},help:[vr(t,e),r.length>0?`valid commands for \`${n}\`: ${r.join(`, `)}`:`\`${n}\` has no commands (--help always allowed)`]}}function qr(e){return e.length===1?`-${e}`:`--${e}`}function Jr(e,t){return t.arguments?.some(t=>t.name===e)?{label:`<${e}>`,details:{argument:e}}:{label:qr(e),details:{option:qr(e)}}}function Yr(e,t){let n=[];for(let t=e;t;t=t.parent)t.name&&n.unshift(t.name);return[t,...n].join(` `)}function Xr(e){return!!e?.isOptional}function Zr(e,t){let n=e.name||t,r=(e.commands??[]).map(e=>e.name);if(!e.arguments?.length&&r.length>0)return`valid commands for \`${n}\`: ${r.join(`, `)}`;let i=(e.arguments??[]).map(e=>Xr(e.type)?`[${e.name}]`:`<${e.name}>`);return i.length>0?`\`${n}\` takes: ${i.join(` `)}`:`\`${n}\` takes no arguments`}function Qr(e,t){let n=e.name||t,r=Object.keys(e.options??{}).map(qr);return r.length>0?`valid options for \`${n}\`: ${r.join(`, `)} (--help always allowed)`:`\`${n}\` takes no options (--help always allowed)`}function $r(e,t){let n=e.index===void 0?``:`[${e.index}]`,r=e.value===void 0?``:` (received ${ni(e.value).map(ti).join(`, `)})`;return e.allowed?.length?[`allowed for ${t}${n}: ${e.allowed.join(`, `)}${r}`]:e.constraint?[`expected for ${t}${n}: ${e.constraint}${r}`]:[]}function ei(e){return Array.isArray(e)?e.map(String):String(e)}function ti(e){return`"${String(e)}"`}function ni(e){return Array.isArray(e)?e:[e]}function ri(e){let{name:t,description:n=``,version:r}=e;return{name:t,description:n,version:r,displayLevel:`info`,command:kn(n,{format:e.format})}}function ii(e,t,n){let r=rt(e,t);Kn(r);let{args:i,errors:a}=r,o=a.filter(t=>`key`in t&&si(e,t.key)).map(ui(e)),s=!o.some(t=>`key`in t&&li(e,t.key));return{help:i.help,version:i.version,verbose:i.verbose,silent:i.silent,"debug-cli":i[`debug-cli`],values:i,format:s&&i.format||n,errors:o}}function ai(e,t,n,r){return e.flatMap(e=>!(`key`in e)||!si(n,e.key)||ci(t,e.key)?[e]:r.errors.filter(t=>`key`in t&&t.key===e.key)).map(oi)}function oi(e){return Object.defineProperty(e,"code",{value:Wr(e),enumerable:!1,configurable:!0})}function si(e,t){return P(e,t).length>0}function ci(e,t){let[n,r]=P(e,t);return!!n&&!jn(r)}function li(e,t){return jn(P(e,t)[1])}function ui(e){return t=>t.type===`invalid-value`&&li(e,t.key)?{...t,allowed:wn}:t}function di(e,t){let n=ri(t),r=t.format??`toon`,i=t.output??`axi`;if(!wn.includes(r))throw TypeError(`cli({ format }) must be one of ${wn.join(`, `)}, received ${String(r)}`);let a=n.description,o=Pn(),s=/* @__PURE__ */ new Map,c=[],l={},u={},d=[],f=n.command.options,p,m=!1;return{name:n.name,version:n.version||``,description:a,default(e){return n.command=T(n.command,{...n.command,...e}),delete this.default,{...this,parse:v}},command(e){return n.command.commands.push(T(n.command,e)),{...this,parse:v}},use(e){return c.push(e),{...this,parse:v}}};function h(){return p??=(async()=>{let t={host:{name:n.name,version:n.version||``},cwd:e.cwd,ui:pi(e,n),registry:o,shared:{get:e=>s.get(e.id),set(e,t){s.set(e.id,t)},has:e=>s.has(e.id)},addCommand(e){n.command.commands.push(T(n.command,e))},addGlobalOption(e,t,n){l[e]=t,u[e]=n},beforeRun(e){d.push(e)},async resolveConfig(){return m=!0,s.get(Fn.id)??{config:void 0,source:{type:`none`},candidates:[]}}};for(let e of c)await e(t);g(),_()})()}function g(){if(Object.keys(l).length===0)return;let{format:e,...t}=f;for(let e of Object.keys(f))delete f[e];Object.assign(f,t,l,{format:e})}function _(){let t=s.get(Fn.id)?.config?.plugins;!m&&Array.isArray(t)&&t.length!==0&&e.ui.warn(`the config lists plugins, but this cli loads none. Plugin loading moved out of clibuilder 12 into @clibuilder/plugins: add .use(plugins()) to the cli.`)}async function v(a){if(fi(a)){e.writeStdout(`${n.version||`not versioned`}\n`);return}e.ui.debug(`argv:`,a.join(` `));let c=In(a);await h();let f=kn(n.description,{format:r,options:l}),p=ii(f,c,r);p.silent&&(delete c.silent,n.displayLevel=`none`),p.verbose&&(delete c.verbose,n.displayLevel=`debug`),p[`debug-cli`]&&(delete c[`debug-cli`],n.displayLevel=`trace`),e.ui.displayLevel=n.displayLevel,e.ui.dump();for(let t of Object.keys(u)){let r=p.values[t];if(r===void 0)continue;let a=gi(e,n,n.command);return x(await u[t]({value:r,format:p.format,output:i,ui:a}),p.format)}let m=rt(n.command,c,f),{args:g,command:_}=m,v=qn(m,[`help`,`version`]);if(p.version||v.version)return i===`axi`?C():hi(e,n,m.command,o).ui.showVersion();if(p.help||v.help)return i===`axi`?S(m.command,f,p.format):hi(e,n,m.command,o).ui.showHelp();await Gn(m);let T=ai(m.errors,_,f,p);if(T.length>0){let r=hi(e,n,m.command,o).ui,a=mi(_)??t.onUsageError;if(a){let e=await a(T,{command:_,ui:r,format:p.format,exitCode:A.usage});return w(typeof e==`number`?e:A.usage)}if(i===`axi`)return b(Gr(Hr(T),_,n.name),p.format),w(A.usage);for(let e of T)r.error(fr(e,_));return r.showHelp(),w(A.usage)}if(_.config&&!s.has(Fn.id)){let e=_.name?`command '${_.name}'`:`the default command`;throw Error(`${e} declares config, but the cli does not load config. Add .use(config()) from 'clibuilder/config' to the cli.`)}if(d.length>0){let t=hi(e,n,m.command,o).ui,r={command:_,config:n.config,format:p.format,output:i,ui:t};try{for(let e of d)await e(r)}catch(e){if(!se(e))throw e;return y(e,p.format,t),w(e.exitCode)}n.config=r.config}let E=hi(e,n,_,o,p.format,i);if(!E.run)return i===`axi`?b(Kr(_,n.name),p.format):E.ui.showHelp(),w(A.usage);i===`axi`&&(E.ui.showHelp=()=>S(_,f,p.format),E.ui.showVersion=()=>C());try{return x(await E.run(g),p.format)}catch(e){if(!se(e))throw e;return y(e,p.format,E.ui),w(e.exitCode)}}function y(t,n,r){if(!ce(t)){if(i===`axi`){let i=En({message:t.message,code:t.code??`error`,details:t.details,help:t.help});e.writeStdout(`${Tn(i,n)}\n`),r.debug(t);return}r.error(t.message);for(let e of t.help)r.error(e)}}function b(t,n){e.writeStdout(`${Tn(En(t),n)}\n`)}function x(t,n){if(i===`axi`){let r=ar(t,n);r!==void 0&&e.writeStdout(r)}return ir(t)}function S(t,r,i){e.writeStdout(i===`text`?`${_r(n.name,t)}\n`:`${Tn(Lr(n.name,t,r.options),i)}\n`)}function C(){e.writeStdout(`${n.version||`not versioned`}\n`)}function w(t){return e.exit(t),t}function T(e,t){return _i(e,t)}}function fi(e){let t=e.slice(2);return t.length===1&&(t[0]===`--version`||t[0]===`-v`)}function pi(e,t){let n=e.ui;return{get displayLevel(){return n.displayLevel},set displayLevel(e){n.displayLevel=e},info:(...e)=>n.info(...e),warn:(...e)=>n.warn(...e),error:(...e)=>n.error(...e),debug:(...e)=>n.debug(...e),showHelp:()=>n.showHelp(t.name,t.command),showVersion:()=>n.showVersion(t.version)}}function mi(e){for(let t=e;t;t=t.parent)if(t.onUsageError)return t.onUsageError}function hi(e,t,n,r,i=`toon`,a=`axi`){return{...n,run:n.run,ui:gi(e,t,n),format:i,output:a,config:t.config,cwd:e.cwd,registry:r}}function gi(e,t,n){let r=e.createCommandUI(n.name||t.name);
|
|
31
31
|
// istanbul ignore next
|
|
32
|
-
return r.displayLevel=t.displayLevel,{...r,showVersion:()=>r.showVersion(t.version),showHelp:()=>r.showHelp(t.name,n)}}function
|
|
32
|
+
return r.displayLevel=t.displayLevel,{...r,showVersion:()=>r.showVersion(t.version),showHelp:()=>r.showHelp(t.name,n)}}function _i(e,t){return t=Mn(t),t.name&&(t.parent=e),t.commands&&(t.commands=t.commands.map(e=>_i(t,e))),t}function vi(e){let t=!0,n=[];
|
|
33
33
|
// istanbul ignore next
|
|
34
|
-
return{...e,get displayLevel(){return e.displayLevel},set displayLevel(t){e.displayLevel=t},debug:(...r)=>t?n.push([`debug`,r]):e.debug(...r),info:(...r)=>t?n.push([`info`,r]):e.info(...r),warn:(...r)=>t?n.push([`warn`,r]):e.warn(...r),error:(...r)=>t?n.push([`error`,r]):e.error(...r),dump:()=>{t=!1;for(let[t,r]of n.splice(0))e[t](...r)}}}const
|
|
35
|
-
`;)n++;else if(r===`/`&&e[n+1]===`*`){let t=e.indexOf(`*/`,n+2);n=t===-1?e.length:t+2}else t+=r,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function
|
|
36
|
-
`)}};a.defaultYaml={explicit:!1,version:`1.2`},a.defaultTags={"!!":`tag:yaml.org,2002:`},e.Directives=a})),
|
|
34
|
+
return{...e,get displayLevel(){return e.displayLevel},set displayLevel(t){e.displayLevel=t},debug:(...r)=>t?n.push([`debug`,r]):e.debug(...r),info:(...r)=>t?n.push([`info`,r]):e.info(...r),warn:(...r)=>t?n.push([`warn`,r]):e.warn(...r),error:(...r)=>t?n.push([`error`,r]):e.error(...r),dump:()=>{t=!1;for(let[t,r]of n.splice(0))e[t](...r)}}}const yi={console:{debug:`stdout`,info:`stdout`,warn:`stderr`,error:`stderr`,answer:`stdout`},axi:{debug:`stderr`,info:`stderr`,warn:`stderr`,error:`stderr`,answer:`stdout`}},bi={none:0,info:1,debug:2,trace:3},xi={error:1,warn:1,info:1,answer:1,debug:2},Si={error:`red`,warn:`yellow`};function Ci(e,t){let n=`info`,r=yi[t];function i(t,i){if(xi[t]>bi[n])return;let a=e[r[t]],o=wi(i,a.colour),s=Si[t];a.write(`${s&&a.colour?w(s,o,{validateStream:!1}):o}\n`)}return{get displayLevel(){return n},set displayLevel(e){n=e},debug:(...e)=>i(`debug`,e),info:(...e)=>i(`info`,e),warn:(...e)=>i(`warn`,e),error:(...e)=>i(`error`,e),showHelp(e,t){i(`answer`,[_r(e,t)])},showVersion(e){i(`answer`,[e||`not versioned`])}}}function wi(e,t){return e.map(e=>typeof e==`object`&&e?C(e,{colors:t}):e).join(` `)}function Ti(e,t=process.env){if(!e.isTTY)return!1;let n=t.FORCE_COLOR;return n===void 0?t.NO_COLOR?!1:typeof e.hasColors!=`function`||e.hasColors(t):n!==`0`&&n!==`false`}function Ei(e,t=process.env){return e.stdout===process.stdout&&Ai(process.stdout),{stdout:Di(e.stdout,t),stderr:Di(e.stderr,t)}}function Di(e,t){return{colour:Ti(e,t),write(t){ki.has(e)||e.write(t)}}}const Oi=/* @__PURE__ */ new WeakSet,ki=/* @__PURE__ */ new WeakSet;function Ai(e){Oi.has(e)||(Oi.add(e),e.on(`error`,t=>{if(t?.code!==`EPIPE`)throw t;ki.add(e),process.exitCode=0}))}function ji(e={}){let t=process.cwd(),n=Ei(e.streams??{stdout:process.stdout,stderr:process.stderr}),r=e.output??`axi`;return{cwd:t,exit(e){process.exitCode=e},writeStdout(e){n.stdout.write(e)},createCommandUI(){return Ci(n,r)},ui:vi(Ci(n,r))}}function Mi(e){return di(ji({streams:e.streams,output:e.output}),e)}async function Ni(e){try{return await E(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return;throw e}}function Pi(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===`"`){let r=n+1;for(;r<e.length&&e[r]!==`"`;)r+=e[r]===`\\`?2:1;t+=e.slice(n,r+1),n=r+1}else if(r===`/`&&e[n+1]===`/`)for(;n<e.length&&e[n]!==`
|
|
35
|
+
`;)n++;else if(r===`/`&&e[n+1]===`*`){let t=e.indexOf(`*/`,n+2);n=t===-1?e.length:t+2}else t+=r,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Fi(e){if(!e||typeof e!=`object`)return[];let t=e,n=/* @__PURE__ */ new Set;for(let e of[`dependencies`,`devDependencies`]){let r=t[e];if(r&&typeof r==`object`)for(let e of Object.keys(r))n.add(e)}return[...n].sort()}function Ii(e,t){let n=t.split(`/`),r=[],i=e;for(;;){r.push(_(i,`node_modules`,...n));let e=m(i);if(e===i)break;i=e}return r}function Li(t,n){try{let r=e(n);return m(r.resolve(`${t}/package.json`))}catch{}for(let e of Ii(m(n),t))if(r(_(e,`package.json`)))return e}const Ri=[`plugin.json`,`.claude-plugin/plugin.json`,`.cursor-plugin/plugin.json`,`.codex-plugin/plugin.json`,`.github/plugin.json`,`.github/plugin/plugin.json`];function zi(e){for(let t of Ri){let n;try{n=JSON.parse(o(_(e,t),`utf8`))}catch{continue}if(z(n)&&typeof n.name==`string`&&n.name)return n}}function Bi(e){return zi(e)?.name}function Vi(e){let t=zi(e)?.version;return typeof t==`string`&&t?t:void 0}function Hi(e){try{let t=JSON.parse(o(_(e,`package.json`),`utf8`)),n=z(t)?t.version:void 0;return typeof n==`string`&&n?n:void 0}catch{return}}function Ui(e,t){return t||Vi(e)||Hi(e)}var B=/* @__PURE__ */ O((e=>{let t=Symbol.for(`yaml.alias`),n=Symbol.for(`yaml.document`),r=Symbol.for(`yaml.map`),i=Symbol.for(`yaml.pair`),a=Symbol.for(`yaml.scalar`),o=Symbol.for(`yaml.seq`),s=Symbol.for(`yaml.node.type`),c=e=>!!e&&typeof e==`object`&&e[s]===t,l=e=>!!e&&typeof e==`object`&&e[s]===n,u=e=>!!e&&typeof e==`object`&&e[s]===r,d=e=>!!e&&typeof e==`object`&&e[s]===i,f=e=>!!e&&typeof e==`object`&&e[s]===a,p=e=>!!e&&typeof e==`object`&&e[s]===o;function m(e){if(e&&typeof e==`object`)switch(e[s]){case r:case o:return!0}return!1}function h(e){if(e&&typeof e==`object`)switch(e[s]){case t:case r:case a:case o:return!0}return!1}e.ALIAS=t,e.DOC=n,e.MAP=r,e.NODE_TYPE=s,e.PAIR=i,e.SCALAR=a,e.SEQ=o,e.hasAnchor=e=>(f(e)||m(e))&&!!e.anchor,e.isAlias=c,e.isCollection=m,e.isDocument=l,e.isMap=u,e.isNode=h,e.isPair=d,e.isScalar=f,e.isSeq=p})),Wi=/* @__PURE__ */ O((e=>{var t=B();let n=Symbol(`break visit`),r=Symbol(`skip children`),i=Symbol(`remove node`);function a(e,n){let r=l(n);t.isDocument(e)?o(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):o(null,e,r,Object.freeze([]))}a.BREAK=n,a.SKIP=r,a.REMOVE=i;function o(e,r,a,s){let c=u(e,r,a,s);if(t.isNode(c)||t.isPair(c))return d(e,s,c),o(e,c,a,s);if(typeof c!=`symbol`){if(t.isCollection(r)){s=Object.freeze(s.concat(r));for(let e=0;e<r.items.length;++e){let t=o(e,r.items[e],a,s);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){s=Object.freeze(s.concat(r));let e=o(`key`,r.key,a,s);if(e===n)return n;e===i&&(r.key=null);let t=o(`value`,r.value,a,s);if(t===n)return n;t===i&&(r.value=null)}}return c}async function s(e,n){let r=l(n);t.isDocument(e)?await c(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):await c(null,e,r,Object.freeze([]))}s.BREAK=n,s.SKIP=r,s.REMOVE=i;async function c(e,r,a,o){let s=await u(e,r,a,o);if(t.isNode(s)||t.isPair(s))return d(e,o,s),c(e,s,a,o);if(typeof s!=`symbol`){if(t.isCollection(r)){o=Object.freeze(o.concat(r));for(let e=0;e<r.items.length;++e){let t=await c(e,r.items[e],a,o);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){o=Object.freeze(o.concat(r));let e=await c(`key`,r.key,a,o);if(e===n)return n;e===i&&(r.key=null);let t=await c(`value`,r.value,a,o);if(t===n)return n;t===i&&(r.value=null)}}return s}function l(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function u(e,n,r,i){if(typeof r==`function`)return r(e,n,i);if(t.isMap(n))return r.Map?.(e,n,i);if(t.isSeq(n))return r.Seq?.(e,n,i);if(t.isPair(n))return r.Pair?.(e,n,i);if(t.isScalar(n))return r.Scalar?.(e,n,i);if(t.isAlias(n))return r.Alias?.(e,n,i)}function d(e,n,r){let i=n[n.length-1];if(t.isCollection(i))i.items[e]=r;else if(t.isPair(i))e===`key`?i.key=r:i.value=r;else if(t.isDocument(i))i.contents=r;else{let e=t.isAlias(i)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}e.visit=a,e.visitAsync=s})),Gi=/* @__PURE__ */ O((e=>{var t=B(),n=Wi();let r={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},i=e=>e.replace(/[!,[\]{}]/g,e=>r[e]);var a=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags)}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+i(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let r=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],i=Object.entries(this.tags),a;if(e&&i.length>0&&t.isNode(e.contents)){let r={};n.visit(e.contents,(e,n)=>{t.isNode(n)&&n.tag&&(r[n.tag]=!0)}),a=Object.keys(r)}else a=[];for(let[t,n]of i)(t!==`!!`||n!==`tag:yaml.org,2002:`)&&(!e||a.some(e=>e.startsWith(n)))&&r.push(`%TAG ${t} ${n}`);return r.join(`
|
|
36
|
+
`)}};a.defaultYaml={explicit:!1,version:`1.2`},a.defaultTags={"!!":`tag:yaml.org,2002:`},e.Directives=a})),Ki=/* @__PURE__ */ O((e=>{var t=B(),n=Wi();function r(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function i(e){let t=/* @__PURE__ */ new Set;return n.visit(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function a(e,t){for(let n=1;;++n){let r=`${e}${n}`;if(!t.has(r))return r}}function o(e,n){let r=[],o=/* @__PURE__ */ new Map,s=null;return{onAnchor:t=>{r.push(t),s??=i(e);let o=a(n,s);return s.add(o),o},setAnchors:()=>{for(let e of r){let n=o.get(e);if(typeof n==`object`&&n.anchor&&(t.isScalar(n.node)||t.isCollection(n.node)))n.node.anchor=n.anchor;else{let t=/* @__PURE__ */ Error(`Failed to resolve repeated object (this should not happen)`);throw t.source=e,t}}},sourceObjects:o}}e.anchorIsValid=r,e.anchorNames=i,e.createNodeAnchors=o,e.findNewAnchor=a})),qi=/* @__PURE__ */ O((e=>{function t(e,n,r,i){if(i&&typeof i==`object`){if(Array.isArray(i))for(let n=0,r=i.length;n<r;++n){let r=i[n],a=t(e,i,String(n),r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}else if(i instanceof Map)for(let n of Array.from(i.keys())){let r=i.get(n),a=t(e,i,n,r);a===void 0?i.delete(n):a!==r&&i.set(n,a)}else if(i instanceof Set)for(let n of Array.from(i)){let r=t(e,i,n,n);r===void 0?i.delete(n):r!==n&&(i.delete(n),i.add(r))}else for(let[n,r]of Object.entries(i)){let a=t(e,i,n,r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}}return e.call(n,r,i)}e.applyReviver=t})),Ji=/* @__PURE__ */ O((e=>{var t=B();function n(e,r,i){if(Array.isArray(e))return e.map((e,t)=>n(e,String(t),i));if(e&&typeof e.toJSON==`function`){if(!i||!t.hasAnchor(e))return e.toJSON(r,i);let n={aliasCount:0,count:1,res:void 0};i.anchors.set(e,n),i.onCreate=e=>{n.res=e,delete i.onCreate};let a=e.toJSON(r,i);return i.onCreate&&i.onCreate(a),a}return typeof e==`bigint`&&!i?.keep?Number(e):e}e.toJS=n})),Yi=/* @__PURE__ */ O((e=>{var t=qi(),n=B(),r=Ji();e.NodeBase=class{constructor(e){Object.defineProperty(this,n.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:i,maxAliasCount:a,onAnchor:o,reviver:s}={}){if(!n.isDocument(e))throw TypeError(`A document argument is required`);let c={anchors:/* @__PURE__ */ new Map,doc:e,keep:!0,mapAsMap:i===!0,mapKeyWarned:!1,maxAliasCount:typeof a==`number`?a:100},l=r.toJS(this,``,c);if(typeof o==`function`)for(let{count:e,res:t}of c.anchors.values())o(t,e);return typeof s==`function`?t.applyReviver(s,{"":l},``,l):l}}})),Xi=/* @__PURE__ */ O((e=>{var t=Ki(),n=Wi(),r=B(),i=Yi(),a=Ji(),o=class extends i.NodeBase{constructor(e){super(r.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let i;t?.aliasResolveCache?i=t.aliasResolveCache:(i=[],n.visit(e,{Node:(e,t)=>{(r.isAlias(t)||r.hasAnchor(t))&&i.push(t)}}),t&&(t.aliasResolveCache=i));let o;for(let e of i){if(e===this)break;e.anchor===this.source&&(o=e)}if(o&&t){let{anchors:e,doc:n,maxAliasCount:r}=t,i=e.get(o);
|
|
37
37
|
/* istanbul ignore if */
|
|
38
|
-
if(i||=(a.toJS(o,null,t),e.get(o)),i?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(r>=0&&(i.count+=1,i.aliasCount===0&&(i.aliasCount=s(n,o,e)),i.count*i.aliasCount>r))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return o}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,n,r){let i=`*${this.source}`;if(e){if(t.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${i} `}return i}};function s(e,t,n){if(r.isAlias(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(r.isCollection(t)){let r=0;for(let i of t.items){let t=s(e,i,n);t>r&&(r=t)}return r}if(r.isPair(t)){let r=s(e,t.key,n),i=s(e,t.value,n);return Math.max(r,i)}return 1}e.Alias=o})),
|
|
38
|
+
if(i||=(a.toJS(o,null,t),e.get(o)),i?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(r>=0&&(i.count+=1,i.aliasCount===0&&(i.aliasCount=s(n,o,e)),i.count*i.aliasCount>r))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return o}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,n,r){let i=`*${this.source}`;if(e){if(t.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${i} `}return i}};function s(e,t,n){if(r.isAlias(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(r.isCollection(t)){let r=0;for(let i of t.items){let t=s(e,i,n);t>r&&(r=t)}return r}if(r.isPair(t)){let r=s(e,t.key,n),i=s(e,t.value,n);return Math.max(r,i)}return 1}e.Alias=o})),V=/* @__PURE__ */ O((e=>{var t=B(),n=Yi(),r=Ji();let i=e=>!e||typeof e!=`function`&&typeof e!=`object`;var a=class extends n.NodeBase{constructor(e){super(t.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:r.toJS(this.value,e,t)}toString(){return String(this.value)}};a.BLOCK_FOLDED=`BLOCK_FOLDED`,a.BLOCK_LITERAL=`BLOCK_LITERAL`,a.PLAIN=`PLAIN`,a.QUOTE_DOUBLE=`QUOTE_DOUBLE`,a.QUOTE_SINGLE=`QUOTE_SINGLE`,e.Scalar=a,e.isScalarValue=i})),Zi=/* @__PURE__ */ O((e=>{var t=Xi(),n=B(),r=V();function i(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function a(e,a,o){if(n.isDocument(e)&&(e=e.contents),n.isNode(e))return e;if(n.isPair(e)){let t=o.schema[n.MAP].createNode?.(o.schema,null,o);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:s,onAnchor:c,onTagObj:l,schema:u,sourceObjects:d}=o,f;if(s&&e&&typeof e==`object`){if(f=d.get(e),f)return f.anchor??(f.anchor=c(e)),new t.Alias(f.anchor);f={anchor:null,node:null},d.set(e,f)}a?.startsWith(`!!`)&&(a=`tag:yaml.org,2002:`+a.slice(2));let p=i(e,a,u.tags);if(!p){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new r.Scalar(e);return f&&(f.node=t),t}p=e instanceof Map?u[n.MAP]:Symbol.iterator in Object(e)?u[n.SEQ]:u[n.MAP]}l&&(l(p),delete o.onTagObj);let m=p?.createNode?p.createNode(o.schema,e,o):typeof p?.nodeClass?.from==`function`?p.nodeClass.from(o.schema,e,o):new r.Scalar(e);return a?m.tag=a:p.default||(m.tag=p.tag),f&&(f.node=m),m}e.createNode=a})),Qi=/* @__PURE__ */ O((e=>{var t=Zi(),n=B(),r=Yi();function i(e,n,r){let i=r;for(let e=n.length-1;e>=0;--e){let t=n[e];if(typeof t==`number`&&Number.isInteger(t)&&t>=0){let e=[];e[t]=i,i=e}else i=/* @__PURE__ */ new Map([[t,i]])}return t.createNode(i,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error(`This should not happen, please report a bug.`)},schema:e,sourceObjects:/* @__PURE__ */ new Map})}let a=e=>e==null||typeof e==`object`&&!!e[Symbol.iterator]().next().done;e.Collection=class extends r.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(t=>n.isNode(t)||n.isPair(t)?t.clone(e):t),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(a(e))this.add(t);else{let[r,...a]=e,o=this.get(r,!0);if(n.isCollection(o))o.addIn(a,t);else if(o===void 0&&this.schema)this.set(r,i(this.schema,a,t));else throw Error(`Expected YAML collection at ${r}. Remaining path: ${a}`)}}deleteIn(e){let[t,...r]=e;if(r.length===0)return this.delete(t);let i=this.get(t,!0);if(n.isCollection(i))return i.deleteIn(r);throw Error(`Expected YAML collection at ${t}. Remaining path: ${r}`)}getIn(e,t){let[r,...i]=e,a=this.get(r,!0);return i.length===0?!t&&n.isScalar(a)?a.value:a:n.isCollection(a)?a.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!n.isPair(t))return!1;let r=t.value;return r==null||e&&n.isScalar(r)&&r.value==null&&!r.commentBefore&&!r.comment&&!r.tag})}hasIn(e){let[t,...r]=e;if(r.length===0)return this.has(t);let i=this.get(t,!0);return n.isCollection(i)?i.hasIn(r):!1}setIn(e,t){let[r,...a]=e;if(a.length===0)this.set(r,t);else{let e=this.get(r,!0);if(n.isCollection(e))e.setIn(a,t);else if(e===void 0&&this.schema)this.set(r,i(this.schema,a,t));else throw Error(`Expected YAML collection at ${r}. Remaining path: ${a}`)}}},e.collectionFromPath=i,e.isEmptyPath=a})),$i=/* @__PURE__ */ O((e=>{let t=e=>e.replace(/^(?!$)(?: $)?/gm,`#`);function n(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}e.indentComment=n,e.lineComment=(e,t,r)=>e.endsWith(`
|
|
39
39
|
`)?n(r,t):r.includes(`
|
|
40
40
|
`)?`
|
|
41
|
-
`+n(r,t):(e.endsWith(` `)?``:` `)+r,e.stringifyComment=t})),
|
|
41
|
+
`+n(r,t):(e.endsWith(` `)?``:` `)+r,e.stringifyComment=t})),ea=/* @__PURE__ */ O((e=>{let t=`block`,n=`quoted`;function r(e,r,a=`flow`,{indentAtStart:o,lineWidth:s=80,minContentWidth:c=20,onFold:l,onOverflow:u}={}){if(!s||s<0)return e;s<c&&(c=0);let d=Math.max(1+c,1+s-r.length);if(e.length<=d)return e;let f=[],p={},m=s-r.length;typeof o==`number`&&(o>s-Math.max(2,c)?f.push(0):m=s-o);let h,g,_=!1,v=-1,y=-1,b=-1;a===t&&(v=i(e,v,r.length),v!==-1&&(m=v+d));for(let o;o=e[v+=1];){if(a===n&&o===`\\`){switch(y=v,e[v+1]){case`x`:v+=3;break;case`u`:v+=5;break;case`U`:v+=9;break;default:v+=1}b=v}if(o===`
|
|
42
42
|
`)a===t&&(v=i(e,v,r.length)),m=v+r.length+d,h=void 0;else{if(o===` `&&g&&g!==` `&&g!==`
|
|
43
43
|
`&&g!==` `){let t=e[v+1];t&&t!==` `&&t!==`
|
|
44
44
|
`&&t!==` `&&(h=v)}if(v>=m){if(h)f.push(h),m=h+d,h=void 0;else if(a===n){for(;g===` `||g===` `;)g=o,o=e[v+=1],_=!0;let t=v>b+1?v-2:y-1;if(p[t])return e;f.push(t),p[t]=!0,m=t+d,h=void 0}else _=!0}}g=o}if(_&&u&&u(),f.length===0)return e;l&&l();let x=e.slice(0,f[0]);for(let t=0;t<f.length;++t){let i=f[t],o=f[t+1]||e.length;i===0?x=`\n${r}${e.slice(0,o)}`:(a===n&&p[i]&&(x+=`${e[i]}\\`),x+=`\n${r}${e.slice(i+1,o)}`)}return x}function i(e,t,n){let r=t,i=t+1,a=e[i];for(;a===` `||a===` `;)if(t<i+n)a=e[++t];else{do a=e[++t];while(a&&a!==`
|
|
45
|
-
`);r=t,i=t+1,a=e[i]}return r}e.FOLD_BLOCK=t,e.FOLD_FLOW=`flow`,e.FOLD_QUOTED=n,e.foldFlowLines=r})),
|
|
45
|
+
`);r=t,i=t+1,a=e[i]}return r}e.FOLD_BLOCK=t,e.FOLD_FLOW=`flow`,e.FOLD_QUOTED=n,e.foldFlowLines=r})),ta=/* @__PURE__ */ O((e=>{var t=V(),n=ea();let r=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),i=e=>/^(%|---|\.\.\.)/m.test(e);function a(e,t,n){if(!t||t<0)return!1;let r=t-n,i=e.length;if(i<=r)return!1;for(let t=0,n=0;t<i;++t)if(e[t]===`
|
|
46
46
|
`){if(t-n>r)return!0;if(n=t+1,i-n<=r)return!1}return!0}function o(e,t){let a=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return a;let{implicitKey:o}=t,s=t.options.doubleQuotedMinMultiLineLength,c=t.indent||(i(e)?` `:``),l=``,u=0;for(let e=0,t=a[e];t;t=a[++e])if(t===` `&&a[e+1]===`\\`&&a[e+2]===`n`&&(l+=a.slice(u,e)+`\\ `,e+=1,u=e,t=`\\`),t===`\\`)switch(a[e+1]){case`u`:{l+=a.slice(u,e);let t=a.substr(e+2,4);switch(t){case`0000`:l+=`\\0`;break;case`0007`:l+=`\\a`;break;case`000b`:l+=`\\v`;break;case`001b`:l+=`\\e`;break;case`0085`:l+=`\\N`;break;case`00a0`:l+=`\\_`;break;case`2028`:l+=`\\L`;break;case`2029`:l+=`\\P`;break;default:t.substr(0,2)===`00`?l+=`\\x`+t.substr(2):l+=a.substr(e,6)}e+=5,u=e+1}break;case`n`:if(o||a[e+2]===`"`||a.length<s)e+=1;else{for(l+=a.slice(u,e)+`
|
|
47
47
|
|
|
48
48
|
`;a[e+2]===`\\`&&a[e+3]===`n`&&a[e+4]!==`"`;)l+=`
|
|
@@ -60,29 +60,29 @@ if(i||=(a.toJS(o,null,t),e.get(o)),i?.res===void 0)throw ReferenceError(`This sh
|
|
|
60
60
|
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\n+/g,`$&${g}`),i=!1,a=r(u,!0);p!==`folded`&&o!==t.Scalar.BLOCK_FOLDED&&(a.onOverflow=()=>{i=!0});let c=n.foldFlowLines(`${T}${e}${b}`,g,n.FOLD_BLOCK,a);if(!i)return`>${E}\n${g}${c}`}return s=s.replace(/\n+/g,`$&${g}`),`|${E}\n${g}${T}${s}${b}`}function d(e,a,o,s){let{type:l,value:d}=e,{actualString:f,implicitKey:p,indent:m,indentStep:h,inFlow:g}=a;if(p&&d.includes(`
|
|
61
61
|
`)||g&&/[[\]{},]/.test(d))return c(d,a);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(d))return p||g||!d.includes(`
|
|
62
62
|
`)?c(d,a):u(e,a,o,s);if(!p&&!g&&l!==t.Scalar.PLAIN&&d.includes(`
|
|
63
|
-
`))return u(e,a,o,s);if(i(d)){if(m===``)return a.forceBlockIndent=!0,u(e,a,o,s);if(p&&m===h)return c(d,a)}let _=d.replace(/\n+/g,`$&\n${m}`);if(f){let e=e=>e.default&&e.tag!==`tag:yaml.org,2002:str`&&e.test?.test(_),{compat:t,tags:n}=a.doc.schema;if(n.some(e)||t?.some(e))return c(d,a)}return p?_:n.foldFlowLines(_,m,n.FOLD_FLOW,r(a,!1))}function f(e,n,r,i){let{implicitKey:a,inFlow:l}=n,f=typeof e.value==`string`?e:Object.assign({},e,{value:String(e.value)}),{type:p}=e;p!==t.Scalar.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(f.value)&&(p=t.Scalar.QUOTE_DOUBLE);let m=e=>{switch(e){case t.Scalar.BLOCK_FOLDED:case t.Scalar.BLOCK_LITERAL:return a||l?c(f.value,n):u(f,n,r,i);case t.Scalar.QUOTE_DOUBLE:return o(f.value,n);case t.Scalar.QUOTE_SINGLE:return s(f.value,n);case t.Scalar.PLAIN:return d(f,n,r,i);default:return null}},h=m(p);if(h===null){let{defaultKeyType:e,defaultStringType:t}=n.options,r=a&&e||t;if(h=m(r),h===null)throw Error(`Unsupported default string type ${r}`)}return h}e.stringifyString=f})),
|
|
63
|
+
`))return u(e,a,o,s);if(i(d)){if(m===``)return a.forceBlockIndent=!0,u(e,a,o,s);if(p&&m===h)return c(d,a)}let _=d.replace(/\n+/g,`$&\n${m}`);if(f){let e=e=>e.default&&e.tag!==`tag:yaml.org,2002:str`&&e.test?.test(_),{compat:t,tags:n}=a.doc.schema;if(n.some(e)||t?.some(e))return c(d,a)}return p?_:n.foldFlowLines(_,m,n.FOLD_FLOW,r(a,!1))}function f(e,n,r,i){let{implicitKey:a,inFlow:l}=n,f=typeof e.value==`string`?e:Object.assign({},e,{value:String(e.value)}),{type:p}=e;p!==t.Scalar.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(f.value)&&(p=t.Scalar.QUOTE_DOUBLE);let m=e=>{switch(e){case t.Scalar.BLOCK_FOLDED:case t.Scalar.BLOCK_LITERAL:return a||l?c(f.value,n):u(f,n,r,i);case t.Scalar.QUOTE_DOUBLE:return o(f.value,n);case t.Scalar.QUOTE_SINGLE:return s(f.value,n);case t.Scalar.PLAIN:return d(f,n,r,i);default:return null}},h=m(p);if(h===null){let{defaultKeyType:e,defaultStringType:t}=n.options,r=a&&e||t;if(h=m(r),h===null)throw Error(`Unsupported default string type ${r}`)}return h}e.stringifyString=f})),na=/* @__PURE__ */ O((e=>{var t=Ki(),n=B(),r=$i(),i=ta();function a(e,t){let n=Object.assign({blockQuote:!0,commentString:r.stringifyComment,defaultKeyType:null,defaultStringType:`PLAIN`,directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:`false`,flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:`null`,simpleKeys:!1,singleQuote:null,trailingComma:!1,trueStr:`true`,verifyAliasOrder:!0},e.schema.toStringOptions,t),i;switch(n.collectionStyle){case`block`:i=!1;break;case`flow`:i=!0;break;default:i=null}return{anchors:/* @__PURE__ */ new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?` `:``,indent:``,indentStep:typeof n.indent==`number`?` `.repeat(n.indent):` `,inFlow:i,options:n}}function o(e,t){if(t.tag){let n=e.filter(e=>e.tag===t.tag);if(n.length>0)return n.find(e=>e.format===t.format)??n[0]}let r,i;if(n.isScalar(t)){i=t.value;let n=e.filter(e=>e.identify?.(i));if(n.length>1){let e=n.filter(e=>e.test);e.length>0&&(n=e)}r=n.find(e=>e.format===t.format)??n.find(e=>!e.format)}else i=t,r=e.find(e=>e.nodeClass&&i instanceof e.nodeClass);if(!r){let e=i?.constructor?.name??(i===null?`null`:typeof i);throw Error(`Tag not resolved for ${e} value`)}return r}function s(e,r,{anchors:i,doc:a}){if(!a.directives)return``;let o=[],s=(n.isScalar(e)||n.isCollection(e))&&e.anchor;s&&t.anchorIsValid(s)&&(i.add(s),o.push(`&${s}`));let c=e.tag??(r.default?null:r.tag);return c&&o.push(a.directives.tagString(c)),o.join(` `)}function c(e,t,r,a){if(n.isPair(e))return e.toString(t,r,a);if(n.isAlias(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw TypeError(`Cannot stringify circular structure without alias nodes`);t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=/* @__PURE__ */ new Set([e]),e=e.resolve(t.doc)}let c,l=n.isNode(e)?e:t.doc.createNode(e,{onTagObj:e=>c=e});c??=o(t.doc.schema.tags,l);let u=s(l,c,t);u.length>0&&(t.indentAtStart=(t.indentAtStart??0)+u.length+1);let d=typeof c.stringify==`function`?c.stringify(l,t,r,a):n.isScalar(l)?i.stringifyString(l,t,r,a):l.toString(t,r,a);return u?n.isScalar(l)||d[0]===`{`||d[0]===`[`?`${u} ${d}`:`${u}\n${t.indent}${d}`:d}e.createStringifyContext=a,e.stringify=c})),ra=/* @__PURE__ */ O((e=>{var t=B(),n=V(),r=na(),i=$i();function a({key:e,value:a},o,s,c){let{allNullValues:l,doc:u,indent:d,indentStep:f,options:{commentString:p,indentSeq:m,simpleKeys:h}}=o,g=t.isNode(e)&&e.comment||null;if(h){if(g)throw Error(`With simple keys, key nodes cannot have comments`);if(t.isCollection(e)||!t.isNode(e)&&typeof e==`object`)throw Error(`With simple keys, collection cannot be used as a key value`)}let _=!h&&(!e||g&&a==null&&!o.inFlow||t.isCollection(e)||(t.isScalar(e)?e.type===n.Scalar.BLOCK_FOLDED||e.type===n.Scalar.BLOCK_LITERAL:typeof e==`object`));o=Object.assign({},o,{allNullValues:!1,implicitKey:!_&&(h||!l),indent:d+f});let v=!1,y=!1,b=r.stringify(e,o,()=>v=!0,()=>y=!0);if(!_&&!o.inFlow&&b.length>1024){if(h)throw Error(`With simple keys, single line scalar must not span more than 1024 characters`);_=!0}if(o.inFlow){if(l||a==null)return v&&s&&s(),b===``?`?`:_?`? ${b}`:b}else if(l&&!h||a==null&&_)return b=`? ${b}`,g&&!v?b+=i.lineComment(b,o.indent,p(g)):y&&c&&c(),b;v&&(g=null),_?(g&&(b+=i.lineComment(b,o.indent,p(g))),b=`? ${b}\n${d}:`):(b=`${b}:`,g&&(b+=i.lineComment(b,o.indent,p(g))));let x,S,C;t.isNode(a)?(x=!!a.spaceBefore,S=a.commentBefore,C=a.comment):(x=!1,S=null,C=null,a&&typeof a==`object`&&(a=u.createNode(a))),o.implicitKey=!1,!_&&!g&&t.isScalar(a)&&(o.indentAtStart=b.length+1),y=!1,!m&&f.length>=2&&!o.inFlow&&!_&&t.isSeq(a)&&!a.flow&&!a.tag&&!a.anchor&&(o.indent=o.indent.substring(2));let w=!1,T=r.stringify(a,o,()=>w=!0,()=>y=!0),E=` `;if(g||x||S){if(E=x?`
|
|
64
64
|
`:``,S){let e=p(S);E+=`\n${i.indentComment(e,o.indent)}`}T===``&&!o.inFlow?E===`
|
|
65
65
|
`&&C&&(E=`
|
|
66
66
|
|
|
67
67
|
`):E+=`\n${o.indent}`}else if(!_&&t.isCollection(a)){let e=T[0],t=T.indexOf(`
|
|
68
68
|
`),n=t!==-1,r=o.inFlow??a.flow??a.items.length===0;if(n||!r){let r=!1;if(n&&(e===`&`||e===`!`)){let n=T.indexOf(` `);e===`&`&&n!==-1&&n<t&&T[n+1]===`!`&&(n=T.indexOf(` `,n+1)),(n===-1||t<n)&&(r=!0)}r||(E=`\n${o.indent}`)}}else(T===``||T[0]===`
|
|
69
|
-
`)&&(E=``);return b+=E+T,o.inFlow?w&&s&&s():C&&!w?b+=i.lineComment(b,o.indent,p(C)):y&&c&&c(),b}e.stringifyPair=a})),
|
|
69
|
+
`)&&(E=``);return b+=E+T,o.inFlow?w&&s&&s():C&&!w?b+=i.lineComment(b,o.indent,p(C)):y&&c&&c(),b}e.stringifyPair=a})),ia=/* @__PURE__ */ O((e=>{var t=te(`process`);function n(e,...t){e===`debug`&&console.log(...t)}function r(e,n){(e===`debug`||e===`warn`)&&(typeof t.emitWarning==`function`?t.emitWarning(n):console.warn(n))}e.debug=n,e.warn=r})),aa=/* @__PURE__ */ O((e=>{var t=B(),n=V();let r={identify:e=>e===`<<`||typeof e==`symbol`&&e.description===`<<`,default:`key`,tag:`tag:yaml.org,2002:merge`,test:/^<<$/,resolve:()=>Object.assign(new n.Scalar(Symbol(`<<`)),{addToJSMap:a}),stringify:()=>`<<`},i=(e,i)=>(r.identify(i)||t.isScalar(i)&&(!i.type||i.type===n.Scalar.PLAIN)&&r.identify(i.value))&&e?.doc.schema.tags.some(e=>e.tag===r.tag&&e.default);function a(e,n,r){let i=s(e,r);if(t.isSeq(i))for(let t of i.items)o(e,n,t);else if(Array.isArray(i))for(let t of i)o(e,n,t);else o(e,n,i)}function o(e,n,r){let i=s(e,r);if(!t.isMap(i))throw Error(`Merge sources must be maps or map aliases`);let a=i.toJSON(null,e,Map);for(let[e,t]of a)n instanceof Map?n.has(e)||n.set(e,t):n instanceof Set?n.add(e):Object.prototype.hasOwnProperty.call(n,e)||Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0});return n}function s(e,n){return e&&t.isAlias(n)?n.resolve(e.doc,e):n}e.addMergeToJSMap=a,e.isMergeKey=i,e.merge=r})),oa=/* @__PURE__ */ O((e=>{var t=ia(),n=aa(),r=na(),i=B(),a=Ji();function o(e,t,{key:r,value:o}){if(i.isNode(r)&&r.addToJSMap)r.addToJSMap(e,t,o);else if(n.isMergeKey(e,r))n.addMergeToJSMap(e,t,o);else{let n=a.toJS(r,``,e);if(t instanceof Map)t.set(n,a.toJS(o,n,e));else if(t instanceof Set)t.add(n);else{let i=s(r,n,e),c=a.toJS(o,i,e);i in t?Object.defineProperty(t,i,{value:c,writable:!0,enumerable:!0,configurable:!0}):t[i]=c}}return t}function s(e,n,a){if(n===null)return``;if(typeof n!=`object`)return String(n);if(i.isNode(e)&&a?.doc){let n=r.createStringifyContext(a.doc,{});n.anchors=/* @__PURE__ */ new Set;for(let e of a.anchors.keys())n.anchors.add(e.anchor);n.inFlow=!0,n.inStringifyKey=!0;let i=e.toString(n);if(!a.mapKeyWarned){let e=JSON.stringify(i);e.length>40&&(e=e.substring(0,36)+`..."`),t.warn(a.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${e}. Set mapAsMap: true to use object keys.`),a.mapKeyWarned=!0}return i}return JSON.stringify(n)}e.addPairToJSMap=o})),sa=/* @__PURE__ */ O((e=>{var t=Zi(),n=ra(),r=oa(),i=B();function a(e,n,r){return new o(t.createNode(e,void 0,r),t.createNode(n,void 0,r))}var o=class e{constructor(e,t=null){Object.defineProperty(this,i.NODE_TYPE,{value:i.PAIR}),this.key=e,this.value=t}clone(t){let{key:n,value:r}=this;return i.isNode(n)&&(n=n.clone(t)),i.isNode(r)&&(r=r.clone(t)),new e(n,r)}toJSON(e,t){let n=t?.mapAsMap?/* @__PURE__ */ new Map:{};return r.addPairToJSMap(t,n,this)}toString(e,t,r){return e?.doc?n.stringifyPair(this,e,t,r):JSON.stringify(this)}};e.Pair=o,e.createPair=a})),ca=/* @__PURE__ */ O((e=>{var t=B(),n=na(),r=$i();function i(e,t,n){return(t.inFlow??e.flow?o:a)(e,t,n)}function a({comment:e,items:i},a,{blockItemPrefix:o,flowChars:c,itemIndent:l,onChompKeep:u,onComment:d}){let{indent:f,options:{commentString:p}}=a,m=Object.assign({},a,{indent:l,type:null}),h=!1,g=[];for(let e=0;e<i.length;++e){let c=i[e],u=null;if(t.isNode(c))!h&&c.spaceBefore&&g.push(``),s(a,g,c.commentBefore,h),c.comment&&(u=c.comment);else if(t.isPair(c)){let e=t.isNode(c.key)?c.key:null;e&&(!h&&e.spaceBefore&&g.push(``),s(a,g,e.commentBefore,h))}h=!1;let d=n.stringify(c,m,()=>u=null,()=>h=!0);u&&(d+=r.lineComment(d,l,p(u))),h&&u&&(h=!1),g.push(o+d)}let _;if(g.length===0)_=c.start+c.end;else{_=g[0];for(let e=1;e<g.length;++e){let t=g[e];_+=t?`\n${f}${t}`:`
|
|
70
70
|
`}}return e?(_+=`
|
|
71
71
|
`+r.indentComment(p(e),f),d&&d()):h&&u&&u(),_}function o({items:e},i,{flowChars:a,itemIndent:o}){let{indent:c,indentStep:l,flowCollectionPadding:u,options:{commentString:d}}=i;o+=l;let f=Object.assign({},i,{indent:o,inFlow:!0,type:null}),p=!1,m=0,h=[];for(let a=0;a<e.length;++a){let c=e[a],l=null;if(t.isNode(c))c.spaceBefore&&h.push(``),s(i,h,c.commentBefore,!1),c.comment&&(l=c.comment);else if(t.isPair(c)){let e=t.isNode(c.key)?c.key:null;e&&(e.spaceBefore&&h.push(``),s(i,h,e.commentBefore,!1),e.comment&&(p=!0));let n=t.isNode(c.value)?c.value:null;n?(n.comment&&(l=n.comment),n.commentBefore&&(p=!0)):c.value==null&&e?.comment&&(l=e.comment)}l&&(p=!0);let u=n.stringify(c,f,()=>l=null);p||=h.length>m||u.includes(`
|
|
72
72
|
`),a<e.length-1?u+=`,`:i.options.trailingComma&&(i.options.lineWidth>0&&(p||=h.reduce((e,t)=>e+t.length+2,2)+(u.length+2)>i.options.lineWidth),p&&(u+=`,`)),l&&(u+=r.lineComment(u,o,d(l))),h.push(u),m=h.length}let{start:g,end:_}=a;if(h.length===0)return g+_;if(!p){let e=h.reduce((e,t)=>e+t.length+2,2);p=i.options.lineWidth>0&&e>i.options.lineWidth}if(p){let e=g;for(let t of h)e+=t?`\n${l}${c}${t}`:`
|
|
73
|
-
`;return`${e}\n${c}${_}`}return`${g}${u}${h.join(` `)}${u}${_}`}function s({indent:e,options:{commentString:t}},n,i,a){if(i&&a&&(i=i.replace(/^\n+/,``)),i){let a=r.indentComment(t(i),e);n.push(a.trimStart())}}e.stringifyCollection=i})),
|
|
74
|
-
`:` `)}return r.stringifyString({comment:e,type:i,value:u},o,s,c)}}})),la=/* @__PURE__ */ D((e=>{var t=H(),n=Ji(),r=U(),i=Qi();function a(e,i){if(t.isSeq(e))for(let a=0;a<e.items.length;++a){let o=e.items[a];if(!t.isPair(o)){if(t.isMap(o)){o.items.length>1&&i(`Each pair must have its own sequence indicator`);let e=o.items[0]||new n.Pair(new r.Scalar(null));if(o.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${o.commentBefore}\n${e.key.commentBefore}`:o.commentBefore),o.comment){let t=e.value??e.key;t.comment=t.comment?`${o.comment}\n${t.comment}`:o.comment}o=e}e.items[a]=t.isPair(o)?o:new n.Pair(o)}}else i(`Expected a sequence for this tag`);return e}function o(e,t,r){let{replacer:a}=r,o=new i.YAMLSeq(e);o.tag=`tag:yaml.org,2002:pairs`;let s=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof a==`function`&&(e=a.call(t,String(s++),e));let i,c;if(Array.isArray(e)){if(e.length===2)i=e[0],c=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`)}else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)i=t[0],c=e[i];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else i=e;o.items.push(n.createPair(i,c,r))}return o}let s={collection:`seq`,default:!1,tag:`tag:yaml.org,2002:pairs`,resolve:a,createNode:o};e.createPairs=o,e.pairs=s,e.resolvePairs=a})),ua=/* @__PURE__ */ D((e=>{var t=H(),n=Fi(),r=Xi(),i=Qi(),a=la(),o=class e extends i.YAMLSeq{constructor(){super(),this.add=r.YAMLMap.prototype.add.bind(this),this.delete=r.YAMLMap.prototype.delete.bind(this),this.get=r.YAMLMap.prototype.get.bind(this),this.has=r.YAMLMap.prototype.has.bind(this),this.set=r.YAMLMap.prototype.set.bind(this),this.tag=e.tag}toJSON(e,r){if(!r)return super.toJSON(e);let i=/* @__PURE__ */ new Map;r?.onCreate&&r.onCreate(i);for(let e of this.items){let a,o;if(t.isPair(e)?(a=n.toJS(e.key,``,r),o=n.toJS(e.value,a,r)):a=n.toJS(e,``,r),i.has(a))throw Error(`Ordered maps must not include duplicate keys`);i.set(a,o)}return i}static from(e,t,n){let r=a.createPairs(e,t,n),i=new this;return i.items=r.items,i}};o.tag=`tag:yaml.org,2002:omap`;let s={collection:`seq`,identify:e=>e instanceof Map,nodeClass:o,default:!1,tag:`tag:yaml.org,2002:omap`,resolve(e,n){let r=a.resolvePairs(e,n),i=[];for(let{key:e}of r.items)t.isScalar(e)&&(i.includes(e.value)?n(`Ordered maps must not include duplicate keys: ${e.value}`):i.push(e.value));return Object.assign(new o,r)},createNode:(e,t,n)=>o.from(e,t,n)};e.YAMLOMap=o,e.omap=s})),da=/* @__PURE__ */ D((e=>{var t=U();function n({value:e,source:t},n){return t&&(e?r:i).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}let r={identify:e=>e===!0,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new t.Scalar(!0),stringify:n},i={identify:e=>e===!1,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new t.Scalar(!1),stringify:n};e.falseTag=i,e.trueTag=r})),fa=/* @__PURE__ */ D((e=>{var t=U(),n=ra();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){let n=new t.Scalar(parseFloat(e.replace(/_/g,``))),r=e.indexOf(`.`);if(r!==-1){let t=e.substring(r+1).replace(/_/g,``);t[t.length-1]===`0`&&(n.minFractionDigits=t.length)}return n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,``)),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),pa=/* @__PURE__ */ D((e=>{var t=ra();let n=e=>typeof e==`bigint`||Number.isInteger(e);function r(e,t,n,{intAsBigInt:r}){let i=e[0];if((i===`-`||i===`+`)&&(t+=1),e=e.substring(t).replace(/_/g,``),r){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`}let t=BigInt(e);return i===`-`?BigInt(-1)*t:t}let a=parseInt(e,n);return i===`-`?-1*a:a}function i(e,r,i){let{value:a}=e;if(n(a)){let e=a.toString(r);return a<0?`-`+i+e.substr(1):i+e}return t.stringifyNumber(e)}let a={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`BIN`,test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>r(e,2,2,n),stringify:e=>i(e,2,`0b`)},o={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>r(e,1,8,n),stringify:e=>i(e,8,`0`)},s={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},c={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)};e.int=s,e.intBin=a,e.intHex=c,e.intOct=o})),ma=/* @__PURE__ */ D((e=>{var t=H(),n=Ji(),r=Xi(),i=class e extends r.YAMLMap{constructor(t){super(t),this.tag=e.tag}add(e){let i;i=t.isPair(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new n.Pair(e.key,null):new n.Pair(e,null),r.findPair(this.items,i.key)||this.items.push(i)}get(e,n){let i=r.findPair(this.items,e);return!n&&t.isPair(i)?t.isScalar(i.key)?i.key.value:i.key:i}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let i=r.findPair(this.items,e);i&&!t?this.items.splice(this.items.indexOf(i),1):!i&&t&&this.items.push(new n.Pair(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,r){let{replacer:i}=r,a=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof i==`function`&&(e=i.call(t,e,e)),a.items.push(n.createPair(e,null,r));return a}};i.tag=`tag:yaml.org,2002:set`;let a={collection:`map`,identify:e=>e instanceof Set,nodeClass:i,default:!1,tag:`tag:yaml.org,2002:set`,createNode:(e,t,n)=>i.from(e,t,n),resolve(e,n){if(t.isMap(e)){if(e.hasAllNullValues(!0))return Object.assign(new i,e);n(`Set items must all have null values`)}else n(`Expected a mapping for this tag`);return e}};e.YAMLSet=i,e.set=a})),ha=/* @__PURE__ */ D((e=>{var t=ra();function n(e,t){let n=e[0],r=n===`-`||n===`+`?e.substring(1):e,i=e=>t?BigInt(e):Number(e),a=r.replace(/_/g,``).split(`:`).reduce((e,t)=>e*i(60)+i(t),i(0));return n===`-`?i(-1)*a:a}function r(e){let{value:n}=e,r=e=>e;if(typeof n==`bigint`)r=e=>BigInt(e);else if(isNaN(n)||!isFinite(n))return t.stringifyNumber(e);let i=``;n<0&&(i=`-`,n*=r(-1));let a=r(60),o=[n%a];return n<60?o.unshift(0):(n=(n-o[0])/a,o.unshift(n%a),n>=60&&(n=(n-o[0])/a,o.unshift(n))),i+o.map(e=>String(e).padStart(2,`0`)).join(`:`).replace(/000000\d*$/,``)}let i={identify:e=>typeof e==`bigint`||Number.isInteger(e),default:!0,tag:`tag:yaml.org,2002:int`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:r})=>n(e,r),stringify:r},a={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>n(e,!1),stringify:r},o={identify:e=>e instanceof Date,default:!0,tag:`tag:yaml.org,2002:timestamp`,test:RegExp(`^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$`),resolve(e){let t=e.match(o.test);if(!t)throw Error(`!!timestamp expects a date, starting with yyyy-mm-dd`);let[,r,i,a,s,c,l]=t.map(Number),u=t[7]?Number((t[7]+`00`).substr(1,3)):0,d=Date.UTC(r,i-1,a,s||0,c||0,l||0,u),f=t[8];if(f&&f!==`Z`){let e=n(f,!1);Math.abs(e)<30&&(e*=60),d-=6e4*e}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,``)??``};e.floatTime=a,e.intTime=i,e.timestamp=o})),ga=/* @__PURE__ */ D((e=>{var t=Zi(),n=ta(),r=$i(),i=ea(),a=ca(),o=da(),s=fa(),c=pa(),l=Ki(),u=ua(),d=la(),f=ma(),p=ha();e.schema=[t.map,r.seq,i.string,n.nullTag,o.trueTag,o.falseTag,c.intBin,c.intOct,c.int,c.intHex,s.floatNaN,s.floatExp,s.float,a.binary,l.merge,u.omap,d.pairs,f.set,p.intTime,p.floatTime,p.timestamp]})),_a=/* @__PURE__ */ D((e=>{var t=Zi(),n=ta(),r=$i(),i=ea(),a=na(),o=ia(),s=aa(),c=oa(),l=sa(),u=ca(),d=Ki(),f=ua(),p=la(),m=ga(),h=ma(),g=ha();let _=/* @__PURE__ */ new Map([[`core`,c.schema],[`failsafe`,[t.map,r.seq,i.string]],[`json`,l.schema],[`yaml11`,m.schema],[`yaml-1.1`,m.schema]]),v={binary:u.binary,bool:a.boolTag,float:o.float,floatExp:o.floatExp,floatNaN:o.floatNaN,floatTime:g.floatTime,int:s.int,intHex:s.intHex,intOct:s.intOct,intTime:g.intTime,map:t.map,merge:d.merge,null:n.nullTag,omap:f.omap,pairs:p.pairs,seq:r.seq,set:h.set,timestamp:g.timestamp},y={"tag:yaml.org,2002:binary":u.binary,"tag:yaml.org,2002:merge":d.merge,"tag:yaml.org,2002:omap":f.omap,"tag:yaml.org,2002:pairs":p.pairs,"tag:yaml.org,2002:set":h.set,"tag:yaml.org,2002:timestamp":g.timestamp};function b(e,t,n){let r=_.get(t);if(r&&!e)return n&&!r.includes(d.merge)?r.concat(d.merge):r.slice();let i=r;if(!i){if(Array.isArray(e))i=[];else{let e=Array.from(_.keys()).filter(e=>e!==`yaml11`).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}}if(Array.isArray(e))for(let t of e)i=i.concat(t);else typeof e==`function`&&(i=e(i.slice()));return n&&(i=i.concat(d.merge)),i.reduce((e,t)=>{let n=typeof t==`string`?v[t]:t;if(!n){let e=JSON.stringify(t),n=Object.keys(v).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e},[])}e.coreKnownTags=y,e.getTags=b})),va=/* @__PURE__ */ D((e=>{var t=H(),n=Zi(),r=$i(),i=ea(),a=_a();let o=(e,t)=>e.key<t.key?-1:+(e.key>t.key);e.Schema=class e{constructor({compat:e,customTags:s,merge:c,resolveKnownTags:l,schema:u,sortMapEntries:d,toStringDefaults:f}){this.compat=Array.isArray(e)?a.getTags(e,`compat`):e?a.getTags(null,e):null,this.name=typeof u==`string`&&u||`core`,this.knownTags=l?a.coreKnownTags:{},this.tags=a.getTags(s,this.name,c),this.toStringOptions=f??null,Object.defineProperty(this,t.MAP,{value:n.map}),Object.defineProperty(this,t.SCALAR,{value:i.string}),Object.defineProperty(this,t.SEQ,{value:r.seq}),this.sortMapEntries=typeof d==`function`?d:d===!0?o:null}clone(){let t=Object.create(e.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}})),ya=/* @__PURE__ */ D((e=>{var t=H(),n=Ui(),r=Bi();function i(e,i){let a=[],o=i.directives===!0;if(i.directives!==!1&&e.directives){let t=e.directives.toString(e);t?(a.push(t),o=!0):e.directives.docStart&&(o=!0)}o&&a.push(`---`);let s=n.createStringifyContext(e,i),{commentString:c}=s.options;if(e.commentBefore){a.length!==1&&a.unshift(``);let t=c(e.commentBefore);a.unshift(r.indentComment(t,``))}let l=!1,u=null;if(e.contents){if(t.isNode(e.contents)){if(e.contents.spaceBefore&&o&&a.push(``),e.contents.commentBefore){let t=c(e.contents.commentBefore);a.push(r.indentComment(t,``))}s.forceBlockIndent=!!e.comment,u=e.contents.comment}let i=u?void 0:()=>l=!0,d=n.stringify(e.contents,s,()=>u=null,i);u&&(d+=r.lineComment(d,``,c(u))),(d[0]===`|`||d[0]===`>`)&&a[a.length-1]===`---`?a[a.length-1]=`--- ${d}`:a.push(d)}else a.push(n.stringify(e.contents,s));if(e.directives?.docEnd){if(e.comment){let t=c(e.comment);t.includes(`
|
|
73
|
+
`;return`${e}\n${c}${_}`}return`${g}${u}${h.join(` `)}${u}${_}`}function s({indent:e,options:{commentString:t}},n,i,a){if(i&&a&&(i=i.replace(/^\n+/,``)),i){let a=r.indentComment(t(i),e);n.push(a.trimStart())}}e.stringifyCollection=i})),la=/* @__PURE__ */ O((e=>{var t=ca(),n=oa(),r=Qi(),i=B(),a=sa(),o=V();function s(e,t){let n=i.isScalar(t)?t.value:t;for(let r of e)if(i.isPair(r)&&(r.key===t||r.key===n||i.isScalar(r.key)&&r.key.value===n))return r}e.YAMLMap=class extends r.Collection{static get tagName(){return`tag:yaml.org,2002:map`}constructor(e){super(i.MAP,e),this.items=[]}static from(e,t,n){let{keepUndefined:r,replacer:i}=n,o=new this(e),s=(e,s)=>{if(typeof i==`function`)s=i.call(t,e,s);else if(Array.isArray(i)&&!i.includes(e))return;(s!==void 0||r)&&o.items.push(a.createPair(e,s,n))};if(t instanceof Map)for(let[e,n]of t)s(e,n);else if(t&&typeof t==`object`)for(let e of Object.keys(t))s(e,t[e]);return typeof e.sortMapEntries==`function`&&o.items.sort(e.sortMapEntries),o}add(e,t){let n;n=i.isPair(e)?e:!e||typeof e!=`object`||!(`key`in e)?new a.Pair(e,e?.value):new a.Pair(e.key,e.value);let r=s(this.items,n.key),c=this.schema?.sortMapEntries;if(r){if(!t)throw Error(`Key ${n.key} already set`);i.isScalar(r.value)&&o.isScalarValue(n.value)?r.value.value=n.value:r.value=n.value}else if(c){let e=this.items.findIndex(e=>c(n,e)<0);e===-1?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){let t=s(this.items,e);return t?this.items.splice(this.items.indexOf(t),1).length>0:!1}get(e,t){let n=s(this.items,e)?.value;return(!t&&i.isScalar(n)?n.value:n)??void 0}has(e){return!!s(this.items,e)}set(e,t){this.add(new a.Pair(e,t),!0)}toJSON(e,t,r){let i=r?new r:t?.mapAsMap?/* @__PURE__ */ new Map:{};t?.onCreate&&t.onCreate(i);for(let e of this.items)n.addPairToJSMap(t,i,e);return i}toString(e,n,r){if(!e)return JSON.stringify(this);for(let e of this.items)if(!i.isPair(e))throw Error(`Map items must all be pairs; found ${JSON.stringify(e)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),t.stringifyCollection(this,e,{blockItemPrefix:``,flowChars:{start:`{`,end:`}`},itemIndent:e.indent||``,onChompKeep:r,onComment:n})}},e.findPair=s})),ua=/* @__PURE__ */ O((e=>{var t=B(),n=la();e.map={collection:`map`,default:!0,nodeClass:n.YAMLMap,tag:`tag:yaml.org,2002:map`,resolve(e,n){return t.isMap(e)||n(`Expected a mapping for this tag`),e},createNode:(e,t,r)=>n.YAMLMap.from(e,t,r)}})),da=/* @__PURE__ */ O((e=>{var t=Zi(),n=ca(),r=Qi(),i=B(),a=V(),o=Ji(),s=class extends r.Collection{static get tagName(){return`tag:yaml.org,2002:seq`}constructor(e){super(i.SEQ,e),this.items=[]}add(e){this.items.push(e)}delete(e){let t=c(e);return typeof t==`number`&&this.items.splice(t,1).length>0}get(e,t){let n=c(e);if(typeof n!=`number`)return;let r=this.items[n];return!t&&i.isScalar(r)?r.value:r}has(e){let t=c(e);return typeof t==`number`&&t<this.items.length}set(e,t){let n=c(e);if(typeof n!=`number`)throw Error(`Expected a valid index, not ${e}.`);let r=this.items[n];i.isScalar(r)&&a.isScalarValue(t)?r.value=t:this.items[n]=t}toJSON(e,t){let n=[];t?.onCreate&&t.onCreate(n);let r=0;for(let e of this.items)n.push(o.toJS(e,String(r++),t));return n}toString(e,t,r){return e?n.stringifyCollection(this,e,{blockItemPrefix:`- `,flowChars:{start:`[`,end:`]`},itemIndent:(e.indent||``)+` `,onChompKeep:r,onComment:t}):JSON.stringify(this)}static from(e,n,r){let{replacer:i}=r,a=new this(e);if(n&&Symbol.iterator in Object(n)){let e=0;for(let o of n){if(typeof i==`function`){let t=n instanceof Set?o:String(e++);o=i.call(n,t,o)}a.items.push(t.createNode(o,void 0,r))}}return a}};function c(e){let t=i.isScalar(e)?e.value:e;return t&&typeof t==`string`&&(t=Number(t)),typeof t==`number`&&Number.isInteger(t)&&t>=0?t:null}e.YAMLSeq=s})),fa=/* @__PURE__ */ O((e=>{var t=B(),n=da();e.seq={collection:`seq`,default:!0,nodeClass:n.YAMLSeq,tag:`tag:yaml.org,2002:seq`,resolve(e,n){return t.isSeq(e)||n(`Expected a sequence for this tag`),e},createNode:(e,t,r)=>n.YAMLSeq.from(e,t,r)}})),pa=/* @__PURE__ */ O((e=>{var t=ta();e.string={identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify(e,n,r,i){return n=Object.assign({actualString:!0},n),t.stringifyString(e,n,r,i)}}})),ma=/* @__PURE__ */ O((e=>{var t=V();let n={identify:e=>e==null,createNode:()=>new t.Scalar(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new t.Scalar(null),stringify:({source:e},t)=>typeof e==`string`&&n.test.test(e)?e:t.options.nullStr};e.nullTag=n})),ha=/* @__PURE__ */ O((e=>{var t=V();let n={identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new t.Scalar(e[0]===`t`||e[0]===`T`),stringify({source:e,value:t},r){return e&&n.test.test(e)&&t===(e[0]===`t`||e[0]===`T`)?e:t?r.options.trueStr:r.options.falseStr}};e.boolTag=n})),ga=/* @__PURE__ */ O((e=>{function t({format:e,minFractionDigits:t,tag:n,value:r}){if(typeof r==`bigint`)return String(r);let i=typeof r==`number`?r:Number(r);if(!isFinite(i))return isNaN(i)?`.nan`:i<0?`-.inf`:`.inf`;let a=Object.is(r,-0)?`-0`:JSON.stringify(r);if(!e&&t&&(!n||n===`tag:yaml.org,2002:float`)&&/^-?\d/.test(a)&&!a.includes(`e`)){let e=a.indexOf(`.`);e<0&&(e=a.length,a+=`.`);let n=t-(a.length-e-1);for(;n-->0;)a+=`0`}return a}e.stringifyNumber=t})),_a=/* @__PURE__ */ O((e=>{var t=V(),n=ga();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(e){let n=new t.Scalar(parseFloat(e)),r=e.indexOf(`.`);return r!==-1&&e[e.length-1]===`0`&&(n.minFractionDigits=e.length-r-1),n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),va=/* @__PURE__ */ O((e=>{var t=ga();let n=e=>typeof e==`bigint`||Number.isInteger(e),r=(e,t,n,{intAsBigInt:r})=>r?BigInt(e):parseInt(e.substring(t),n);function i(e,r,i){let{value:a}=e;return n(a)&&a>=0?i+a.toString(r):t.stringifyNumber(e)}e.int={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},e.intHex={identify:e=>n(e)&&e>=0,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)},e.intOct={identify:e=>n(e)&&e>=0,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^0o[0-7]+$/,resolve:(e,t,n)=>r(e,2,8,n),stringify:e=>i(e,8,`0o`)}})),ya=/* @__PURE__ */ O((e=>{var t=ua(),n=ma(),r=fa(),i=pa(),a=ha(),o=_a(),s=va();e.schema=[t.map,r.seq,i.string,n.nullTag,a.boolTag,s.intOct,s.int,s.intHex,o.floatNaN,o.floatExp,o.float]})),ba=/* @__PURE__ */ O((e=>{var t=V(),n=ua(),r=fa();function i(e){return typeof e==`bigint`||Number.isInteger(e)}let a=({value:e})=>JSON.stringify(e),o=[{identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify:a},{identify:e=>e==null,createNode:()=>new t.Scalar(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^null$/,resolve:()=>null,stringify:a},{identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^true$|^false$/,resolve:e=>e===`true`,stringify:a},{identify:i,default:!0,tag:`tag:yaml.org,2002:int`,test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>i(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:a}];e.schema=[n.map,r.seq].concat(o,{default:!0,tag:``,test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}})})),xa=/* @__PURE__ */ O((e=>{var t=te(`buffer`),n=V(),r=ta();e.binary={identify:e=>e instanceof Uint8Array,default:!1,tag:`tag:yaml.org,2002:binary`,resolve(e,n){if(typeof t.Buffer==`function`)return t.Buffer.from(e,`base64`);if(typeof atob==`function`){let t=atob(e.replace(/[\n\r]/g,``)),n=new Uint8Array(t.length);for(let e=0;e<t.length;++e)n[e]=t.charCodeAt(e);return n}return n(`This environment does not support reading binary tags; either Buffer or atob is required`),e},stringify({comment:e,type:i,value:a},o,s,c){if(!a)return``;let l=a,u;if(typeof t.Buffer==`function`)u=l instanceof t.Buffer?l.toString(`base64`):t.Buffer.from(l.buffer).toString(`base64`);else if(typeof btoa==`function`){let e=``;for(let t=0;t<l.length;++t)e+=String.fromCharCode(l[t]);u=btoa(e)}else throw Error(`This environment does not support writing binary tags; either Buffer or btoa is required`);if(i??=n.Scalar.BLOCK_LITERAL,i!==n.Scalar.QUOTE_DOUBLE){let e=Math.max(o.options.lineWidth-o.indent.length,o.options.minContentWidth),t=Math.ceil(u.length/e),r=Array(t);for(let n=0,i=0;n<t;++n,i+=e)r[n]=u.substr(i,e);u=r.join(i===n.Scalar.BLOCK_LITERAL?`
|
|
74
|
+
`:` `)}return r.stringifyString({comment:e,type:i,value:u},o,s,c)}}})),Sa=/* @__PURE__ */ O((e=>{var t=B(),n=sa(),r=V(),i=da();function a(e,i){if(t.isSeq(e))for(let a=0;a<e.items.length;++a){let o=e.items[a];if(!t.isPair(o)){if(t.isMap(o)){o.items.length>1&&i(`Each pair must have its own sequence indicator`);let e=o.items[0]||new n.Pair(new r.Scalar(null));if(o.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${o.commentBefore}\n${e.key.commentBefore}`:o.commentBefore),o.comment){let t=e.value??e.key;t.comment=t.comment?`${o.comment}\n${t.comment}`:o.comment}o=e}e.items[a]=t.isPair(o)?o:new n.Pair(o)}}else i(`Expected a sequence for this tag`);return e}function o(e,t,r){let{replacer:a}=r,o=new i.YAMLSeq(e);o.tag=`tag:yaml.org,2002:pairs`;let s=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof a==`function`&&(e=a.call(t,String(s++),e));let i,c;if(Array.isArray(e)){if(e.length===2)i=e[0],c=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`)}else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)i=t[0],c=e[i];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else i=e;o.items.push(n.createPair(i,c,r))}return o}let s={collection:`seq`,default:!1,tag:`tag:yaml.org,2002:pairs`,resolve:a,createNode:o};e.createPairs=o,e.pairs=s,e.resolvePairs=a})),Ca=/* @__PURE__ */ O((e=>{var t=B(),n=Ji(),r=la(),i=da(),a=Sa(),o=class e extends i.YAMLSeq{constructor(){super(),this.add=r.YAMLMap.prototype.add.bind(this),this.delete=r.YAMLMap.prototype.delete.bind(this),this.get=r.YAMLMap.prototype.get.bind(this),this.has=r.YAMLMap.prototype.has.bind(this),this.set=r.YAMLMap.prototype.set.bind(this),this.tag=e.tag}toJSON(e,r){if(!r)return super.toJSON(e);let i=/* @__PURE__ */ new Map;r?.onCreate&&r.onCreate(i);for(let e of this.items){let a,o;if(t.isPair(e)?(a=n.toJS(e.key,``,r),o=n.toJS(e.value,a,r)):a=n.toJS(e,``,r),i.has(a))throw Error(`Ordered maps must not include duplicate keys`);i.set(a,o)}return i}static from(e,t,n){let r=a.createPairs(e,t,n),i=new this;return i.items=r.items,i}};o.tag=`tag:yaml.org,2002:omap`;let s={collection:`seq`,identify:e=>e instanceof Map,nodeClass:o,default:!1,tag:`tag:yaml.org,2002:omap`,resolve(e,n){let r=a.resolvePairs(e,n),i=[];for(let{key:e}of r.items)t.isScalar(e)&&(i.includes(e.value)?n(`Ordered maps must not include duplicate keys: ${e.value}`):i.push(e.value));return Object.assign(new o,r)},createNode:(e,t,n)=>o.from(e,t,n)};e.YAMLOMap=o,e.omap=s})),wa=/* @__PURE__ */ O((e=>{var t=V();function n({value:e,source:t},n){return t&&(e?r:i).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}let r={identify:e=>e===!0,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new t.Scalar(!0),stringify:n},i={identify:e=>e===!1,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new t.Scalar(!1),stringify:n};e.falseTag=i,e.trueTag=r})),Ta=/* @__PURE__ */ O((e=>{var t=V(),n=ga();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){let n=new t.Scalar(parseFloat(e.replace(/_/g,``))),r=e.indexOf(`.`);if(r!==-1){let t=e.substring(r+1).replace(/_/g,``);t[t.length-1]===`0`&&(n.minFractionDigits=t.length)}return n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,``)),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),Ea=/* @__PURE__ */ O((e=>{var t=ga();let n=e=>typeof e==`bigint`||Number.isInteger(e);function r(e,t,n,{intAsBigInt:r}){let i=e[0];if((i===`-`||i===`+`)&&(t+=1),e=e.substring(t).replace(/_/g,``),r){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`}let t=BigInt(e);return i===`-`?BigInt(-1)*t:t}let a=parseInt(e,n);return i===`-`?-1*a:a}function i(e,r,i){let{value:a}=e;if(n(a)){let e=a.toString(r);return a<0?`-`+i+e.substr(1):i+e}return t.stringifyNumber(e)}let a={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`BIN`,test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>r(e,2,2,n),stringify:e=>i(e,2,`0b`)},o={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>r(e,1,8,n),stringify:e=>i(e,8,`0`)},s={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},c={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)};e.int=s,e.intBin=a,e.intHex=c,e.intOct=o})),Da=/* @__PURE__ */ O((e=>{var t=B(),n=sa(),r=la(),i=class e extends r.YAMLMap{constructor(t){super(t),this.tag=e.tag}add(e){let i;i=t.isPair(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new n.Pair(e.key,null):new n.Pair(e,null),r.findPair(this.items,i.key)||this.items.push(i)}get(e,n){let i=r.findPair(this.items,e);return!n&&t.isPair(i)?t.isScalar(i.key)?i.key.value:i.key:i}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let i=r.findPair(this.items,e);i&&!t?this.items.splice(this.items.indexOf(i),1):!i&&t&&this.items.push(new n.Pair(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,r){let{replacer:i}=r,a=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof i==`function`&&(e=i.call(t,e,e)),a.items.push(n.createPair(e,null,r));return a}};i.tag=`tag:yaml.org,2002:set`;let a={collection:`map`,identify:e=>e instanceof Set,nodeClass:i,default:!1,tag:`tag:yaml.org,2002:set`,createNode:(e,t,n)=>i.from(e,t,n),resolve(e,n){if(t.isMap(e)){if(e.hasAllNullValues(!0))return Object.assign(new i,e);n(`Set items must all have null values`)}else n(`Expected a mapping for this tag`);return e}};e.YAMLSet=i,e.set=a})),Oa=/* @__PURE__ */ O((e=>{var t=ga();function n(e,t){let n=e[0],r=n===`-`||n===`+`?e.substring(1):e,i=e=>t?BigInt(e):Number(e),a=r.replace(/_/g,``).split(`:`).reduce((e,t)=>e*i(60)+i(t),i(0));return n===`-`?i(-1)*a:a}function r(e){let{value:n}=e,r=e=>e;if(typeof n==`bigint`)r=e=>BigInt(e);else if(isNaN(n)||!isFinite(n))return t.stringifyNumber(e);let i=``;n<0&&(i=`-`,n*=r(-1));let a=r(60),o=[n%a];return n<60?o.unshift(0):(n=(n-o[0])/a,o.unshift(n%a),n>=60&&(n=(n-o[0])/a,o.unshift(n))),i+o.map(e=>String(e).padStart(2,`0`)).join(`:`).replace(/000000\d*$/,``)}let i={identify:e=>typeof e==`bigint`||Number.isInteger(e),default:!0,tag:`tag:yaml.org,2002:int`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:r})=>n(e,r),stringify:r},a={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>n(e,!1),stringify:r},o={identify:e=>e instanceof Date,default:!0,tag:`tag:yaml.org,2002:timestamp`,test:RegExp(`^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$`),resolve(e){let t=e.match(o.test);if(!t)throw Error(`!!timestamp expects a date, starting with yyyy-mm-dd`);let[,r,i,a,s,c,l]=t.map(Number),u=t[7]?Number((t[7]+`00`).substr(1,3)):0,d=Date.UTC(r,i-1,a,s||0,c||0,l||0,u),f=t[8];if(f&&f!==`Z`){let e=n(f,!1);Math.abs(e)<30&&(e*=60),d-=6e4*e}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,``)??``};e.floatTime=a,e.intTime=i,e.timestamp=o})),ka=/* @__PURE__ */ O((e=>{var t=ua(),n=ma(),r=fa(),i=pa(),a=xa(),o=wa(),s=Ta(),c=Ea(),l=aa(),u=Ca(),d=Sa(),f=Da(),p=Oa();e.schema=[t.map,r.seq,i.string,n.nullTag,o.trueTag,o.falseTag,c.intBin,c.intOct,c.int,c.intHex,s.floatNaN,s.floatExp,s.float,a.binary,l.merge,u.omap,d.pairs,f.set,p.intTime,p.floatTime,p.timestamp]})),Aa=/* @__PURE__ */ O((e=>{var t=ua(),n=ma(),r=fa(),i=pa(),a=ha(),o=_a(),s=va(),c=ya(),l=ba(),u=xa(),d=aa(),f=Ca(),p=Sa(),m=ka(),h=Da(),g=Oa();let _=/* @__PURE__ */ new Map([[`core`,c.schema],[`failsafe`,[t.map,r.seq,i.string]],[`json`,l.schema],[`yaml11`,m.schema],[`yaml-1.1`,m.schema]]),v={binary:u.binary,bool:a.boolTag,float:o.float,floatExp:o.floatExp,floatNaN:o.floatNaN,floatTime:g.floatTime,int:s.int,intHex:s.intHex,intOct:s.intOct,intTime:g.intTime,map:t.map,merge:d.merge,null:n.nullTag,omap:f.omap,pairs:p.pairs,seq:r.seq,set:h.set,timestamp:g.timestamp},y={"tag:yaml.org,2002:binary":u.binary,"tag:yaml.org,2002:merge":d.merge,"tag:yaml.org,2002:omap":f.omap,"tag:yaml.org,2002:pairs":p.pairs,"tag:yaml.org,2002:set":h.set,"tag:yaml.org,2002:timestamp":g.timestamp};function b(e,t,n){let r=_.get(t);if(r&&!e)return n&&!r.includes(d.merge)?r.concat(d.merge):r.slice();let i=r;if(!i){if(Array.isArray(e))i=[];else{let e=Array.from(_.keys()).filter(e=>e!==`yaml11`).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}}if(Array.isArray(e))for(let t of e)i=i.concat(t);else typeof e==`function`&&(i=e(i.slice()));return n&&(i=i.concat(d.merge)),i.reduce((e,t)=>{let n=typeof t==`string`?v[t]:t;if(!n){let e=JSON.stringify(t),n=Object.keys(v).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e},[])}e.coreKnownTags=y,e.getTags=b})),ja=/* @__PURE__ */ O((e=>{var t=B(),n=ua(),r=fa(),i=pa(),a=Aa();let o=(e,t)=>e.key<t.key?-1:+(e.key>t.key);e.Schema=class e{constructor({compat:e,customTags:s,merge:c,resolveKnownTags:l,schema:u,sortMapEntries:d,toStringDefaults:f}){this.compat=Array.isArray(e)?a.getTags(e,`compat`):e?a.getTags(null,e):null,this.name=typeof u==`string`&&u||`core`,this.knownTags=l?a.coreKnownTags:{},this.tags=a.getTags(s,this.name,c),this.toStringOptions=f??null,Object.defineProperty(this,t.MAP,{value:n.map}),Object.defineProperty(this,t.SCALAR,{value:i.string}),Object.defineProperty(this,t.SEQ,{value:r.seq}),this.sortMapEntries=typeof d==`function`?d:d===!0?o:null}clone(){let t=Object.create(e.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}})),Ma=/* @__PURE__ */ O((e=>{var t=B(),n=na(),r=$i();function i(e,i){let a=[],o=i.directives===!0;if(i.directives!==!1&&e.directives){let t=e.directives.toString(e);t?(a.push(t),o=!0):e.directives.docStart&&(o=!0)}o&&a.push(`---`);let s=n.createStringifyContext(e,i),{commentString:c}=s.options;if(e.commentBefore){a.length!==1&&a.unshift(``);let t=c(e.commentBefore);a.unshift(r.indentComment(t,``))}let l=!1,u=null;if(e.contents){if(t.isNode(e.contents)){if(e.contents.spaceBefore&&o&&a.push(``),e.contents.commentBefore){let t=c(e.contents.commentBefore);a.push(r.indentComment(t,``))}s.forceBlockIndent=!!e.comment,u=e.contents.comment}let i=u?void 0:()=>l=!0,d=n.stringify(e.contents,s,()=>u=null,i);u&&(d+=r.lineComment(d,``,c(u))),(d[0]===`|`||d[0]===`>`)&&a[a.length-1]===`---`?a[a.length-1]=`--- ${d}`:a.push(d)}else a.push(n.stringify(e.contents,s));if(e.directives?.docEnd){if(e.comment){let t=c(e.comment);t.includes(`
|
|
75
75
|
`)?(a.push(`...`),a.push(r.indentComment(t,``))):a.push(`... ${t}`)}else a.push(`...`)}else{let t=e.comment;t&&l&&(t=t.replace(/^\n+/,``)),t&&((!l||u)&&a[a.length-1]!==``&&a.push(``),a.push(r.indentComment(c(t),``)))}return a.join(`
|
|
76
76
|
`)+`
|
|
77
|
-
`}e.stringifyDocument=i})),
|
|
78
|
-
`),o=n+o}if(/[^ ]/.test(o)){let e=1,t=n.linePos[1];t?.line===r&&t.col>i&&(e=Math.max(1,Math.min(t.col-i,80-a)));let s=` `.repeat(a)+`^`.repeat(e);n.message+=`:\n\n${o}\n${s}\n`}}})),
|
|
79
|
-
`))return!0;if(e.end){for(let t of e.end)if(t.type===`newline`)return!0}return!1;case`flow-collection`:for(let n of e.items){for(let e of n.start)if(e.type===`newline`)return!0;if(n.sep){for(let e of n.sep)if(e.type===`newline`)return!0}if(t(n.key)||t(n.value))return!0}return!1;default:return!0}}e.containsNewline=t})),
|
|
77
|
+
`}e.stringifyDocument=i})),Na=/* @__PURE__ */ O((e=>{var t=Xi(),n=Qi(),r=B(),i=sa(),a=Ji(),o=ja(),s=Ma(),c=Ki(),l=qi(),u=Zi(),d=Gi(),f=class e{constructor(e,t,n){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,r.NODE_TYPE,{value:r.DOC});let i=null;typeof t==`function`||Array.isArray(t)?i=t:n===void 0&&t&&(n=t,t=void 0);let a=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:`warn`,prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:`1.2`},n);this.options=a;let{version:o}=a;n?._directives?(this.directives=n._directives.atDocument(),this.directives.yaml.explicit&&(o=this.directives.yaml.version)):this.directives=new d.Directives({version:o}),this.setSchema(o,n),this.contents=e===void 0?null:this.createNode(e,i,n)}clone(){let t=Object.create(e.prototype,{[r.NODE_TYPE]:{value:r.DOC}});return t.commentBefore=this.commentBefore,t.comment=this.comment,t.errors=this.errors.slice(),t.warnings=this.warnings.slice(),t.options=Object.assign({},this.options),this.directives&&(t.directives=this.directives.clone()),t.schema=this.schema.clone(),t.contents=r.isNode(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(e){p(this.contents)&&this.contents.add(e)}addIn(e,t){p(this.contents)&&this.contents.addIn(e,t)}createAlias(e,n){if(!e.anchor){let t=c.anchorNames(this);e.anchor=!n||t.has(n)?c.findNewAnchor(n||`a`,t):n}return new t.Alias(e.anchor)}createNode(e,t,n){let i;if(typeof t==`function`)e=t.call({"":e},``,e),i=t;else if(Array.isArray(t)){let e=t.filter(e=>typeof e==`number`||e instanceof String||e instanceof Number).map(String);e.length>0&&(t=t.concat(e)),i=t}else n===void 0&&t&&(n=t,t=void 0);let{aliasDuplicateObjects:a,anchorPrefix:o,flow:s,keepUndefined:l,onTagObj:d,tag:f}=n??{},{onAnchor:p,setAnchors:m,sourceObjects:h}=c.createNodeAnchors(this,o||`a`),g={aliasDuplicateObjects:a??!0,keepUndefined:l??!1,onAnchor:p,onTagObj:d,replacer:i,schema:this.schema,sourceObjects:h},_=u.createNode(e,f,g);return s&&r.isCollection(_)&&(_.flow=!0),m(),_}createPair(e,t,n={}){let r=this.createNode(e,null,n),a=this.createNode(t,null,n);return new i.Pair(r,a)}delete(e){return p(this.contents)?this.contents.delete(e):!1}deleteIn(e){return n.isEmptyPath(e)?this.contents!=null&&(this.contents=null,!0):p(this.contents)?this.contents.deleteIn(e):!1}get(e,t){return r.isCollection(this.contents)?this.contents.get(e,t):void 0}getIn(e,t){return n.isEmptyPath(e)?!t&&r.isScalar(this.contents)?this.contents.value:this.contents:r.isCollection(this.contents)?this.contents.getIn(e,t):void 0}has(e){return r.isCollection(this.contents)?this.contents.has(e):!1}hasIn(e){return n.isEmptyPath(e)?this.contents!==void 0:r.isCollection(this.contents)?this.contents.hasIn(e):!1}set(e,t){this.contents==null?this.contents=n.collectionFromPath(this.schema,[e],t):p(this.contents)&&this.contents.set(e,t)}setIn(e,t){n.isEmptyPath(e)?this.contents=t:this.contents==null?this.contents=n.collectionFromPath(this.schema,Array.from(e),t):p(this.contents)&&this.contents.setIn(e,t)}setSchema(e,t={}){typeof e==`number`&&(e=String(e));let n;switch(e){case`1.1`:this.directives?this.directives.yaml.version=`1.1`:this.directives=new d.Directives({version:`1.1`}),n={resolveKnownTags:!1,schema:`yaml-1.1`};break;case`1.2`:case`next`:this.directives?this.directives.yaml.version=e:this.directives=new d.Directives({version:e}),n={resolveKnownTags:!0,schema:`core`};break;case null:this.directives&&delete this.directives,n=null;break;default:{let t=JSON.stringify(e);throw Error(`Expected '1.1', '1.2' or null as first argument, but found: ${t}`)}}if(t.schema instanceof Object)this.schema=t.schema;else if(n)this.schema=new o.Schema(Object.assign(n,t));else throw Error(`With a null YAML version, the { schema: Schema } option is required`)}toJS({json:e,jsonArg:t,mapAsMap:n,maxAliasCount:r,onAnchor:i,reviver:o}={}){let s={anchors:/* @__PURE__ */ new Map,doc:this,keep:!e,mapAsMap:n===!0,mapKeyWarned:!1,maxAliasCount:typeof r==`number`?r:100},c=a.toJS(this.contents,t??``,s);if(typeof i==`function`)for(let{count:e,res:t}of s.anchors.values())i(t,e);return typeof o==`function`?l.applyReviver(o,{"":c},``,c):c}toJSON(e,t){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:t})}toString(e={}){if(this.errors.length>0)throw Error(`Document with errors cannot be stringified`);if(`indent`in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){let t=JSON.stringify(e.indent);throw Error(`"indent" option must be a positive integer, not ${t}`)}return s.stringifyDocument(this,e)}};function p(e){if(r.isCollection(e))return!0;throw Error(`Expected a YAML collection as document contents`)}e.Document=f})),Pa=/* @__PURE__ */ O((e=>{var t=class extends Error{constructor(e,t,n,r){super(),this.name=e,this.code=n,this.message=r,this.pos=t}},n=class extends t{constructor(e,t,n){super(`YAMLParseError`,e,t,n)}},r=class extends t{constructor(e,t,n){super(`YAMLWarning`,e,t,n)}};e.YAMLError=t,e.YAMLParseError=n,e.YAMLWarning=r,e.prettifyError=(e,t)=>n=>{if(n.pos[0]===-1)return;n.linePos=n.pos.map(e=>t.linePos(e));let{line:r,col:i}=n.linePos[0];n.message+=` at line ${r}, column ${i}`;let a=i-1,o=e.substring(t.lineStarts[r-1],t.lineStarts[r]).replace(/[\n\r]+$/,``);if(a>=60&&o.length>80){let e=Math.min(a-39,o.length-79);o=`…`+o.substring(e),a-=e-1}if(o.length>80&&(o=o.substring(0,79)+`…`),r>1&&/^ *$/.test(o.substring(0,a))){let n=e.substring(t.lineStarts[r-2],t.lineStarts[r-1]);n.length>80&&(n=n.substring(0,79)+`…
|
|
78
|
+
`),o=n+o}if(/[^ ]/.test(o)){let e=1,t=n.linePos[1];t?.line===r&&t.col>i&&(e=Math.max(1,Math.min(t.col-i,80-a)));let s=` `.repeat(a)+`^`.repeat(e);n.message+=`:\n\n${o}\n${s}\n`}}})),Fa=/* @__PURE__ */ O((e=>{function t(e,{flow:t,indicator:n,next:r,offset:i,onError:a,parentIndent:o,startOnNewline:s}){let c=!1,l=s,u=s,d=``,f=``,p=!1,m=!1,h=null,g=null,_=null,v=null,y=null,b=null,x=null;for(let i of e)switch(m&&=(i.type!==`space`&&i.type!==`newline`&&i.type!==`comma`&&a(i.offset,`MISSING_CHAR`,`Tags and anchors must be separated from the next token by white space`),!1),h&&=(l&&i.type!==`comment`&&i.type!==`newline`&&a(h,`TAB_AS_INDENT`,`Tabs are not allowed as indentation`),null),i.type){case`space`:!t&&(n!==`doc-start`||r?.type!==`flow-collection`)&&i.source.includes(` `)&&(h=i),u=!0;break;case`comment`:{u||a(i,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`);let e=i.source.substring(1)||` `;d?d+=f+e:d=e,f=``,l=!1;break}case`newline`:l?d?d+=i.source:(!b||n!==`seq-item-ind`)&&(c=!0):f+=i.source,l=!0,p=!0,(g||_)&&(v=i),u=!0;break;case`anchor`:g&&a(i,`MULTIPLE_ANCHORS`,`A node can have at most one anchor`),i.source.endsWith(`:`)&&a(i.offset+i.source.length-1,`BAD_ALIAS`,`Anchor ending in : is ambiguous`,!0),g=i,x??=i.offset,l=!1,u=!1,m=!0;break;case`tag`:_&&a(i,`MULTIPLE_TAGS`,`A node can have at most one tag`),_=i,x??=i.offset,l=!1,u=!1,m=!0;break;case n:(g||_)&&a(i,`BAD_PROP_ORDER`,`Anchors and tags must be after the ${i.source} indicator`),b&&a(i,`UNEXPECTED_TOKEN`,`Unexpected ${i.source} in ${t??`collection`}`),b=i,l=n===`seq-item-ind`||n===`explicit-key-ind`,u=!1;break;case`comma`:if(t){y&&a(i,`UNEXPECTED_TOKEN`,`Unexpected , in ${t}`),y=i,l=!1,u=!1;break}default:a(i,`UNEXPECTED_TOKEN`,`Unexpected ${i.type} token`),l=!1,u=!1}let S=e[e.length-1],C=S?S.offset+S.source.length:i;return m&&r&&r.type!==`space`&&r.type!==`newline`&&r.type!==`comma`&&(r.type!==`scalar`||r.source!==``)&&a(r.offset,`MISSING_CHAR`,`Tags and anchors must be separated from the next token by white space`),h&&(l&&h.indent<=o||r?.type===`block-map`||r?.type===`block-seq`)&&a(h,`TAB_AS_INDENT`,`Tabs are not allowed as indentation`),{comma:y,found:b,spaceBefore:c,comment:d,hasNewline:p,anchor:g,tag:_,newlineAfterProp:v,end:C,start:x??C}}e.resolveProps=t})),Ia=/* @__PURE__ */ O((e=>{function t(e){if(!e)return null;switch(e.type){case`alias`:case`scalar`:case`double-quoted-scalar`:case`single-quoted-scalar`:if(e.source.includes(`
|
|
79
|
+
`))return!0;if(e.end){for(let t of e.end)if(t.type===`newline`)return!0}return!1;case`flow-collection`:for(let n of e.items){for(let e of n.start)if(e.type===`newline`)return!0;if(n.sep){for(let e of n.sep)if(e.type===`newline`)return!0}if(t(n.key)||t(n.value))return!0}return!1;default:return!0}}e.containsNewline=t})),La=/* @__PURE__ */ O((e=>{var t=Ia();function n(e,n,r){if(n?.type===`flow-collection`){let i=n.end[0];i.indent===e&&(i.source===`]`||i.source===`}`)&&t.containsNewline(n)&&r(i,`BAD_INDENT`,`Flow end indicator should be more indented than parent`,!0)}}e.flowIndentCheck=n})),Ra=/* @__PURE__ */ O((e=>{var t=B();function n(e,n,r){let{uniqueKeys:i}=e.options;if(i===!1)return!1;let a=typeof i==`function`?i:(e,n)=>e===n||t.isScalar(e)&&t.isScalar(n)&&e.value===n.value;return n.some(e=>a(e.key,r))}e.mapIncludes=n})),za=/* @__PURE__ */ O((e=>{var t=sa(),n=la(),r=Fa(),i=Ia(),a=La(),o=Ra();let s=`All mapping items must start at the same column`;function c({composeNode:e,composeEmptyNode:c},l,u,d,f){let p=new((f?.nodeClass)??n.YAMLMap)(l.schema);l.atRoot&&=!1;let m=u.offset,h=null;for(let n of u.items){let{start:f,key:g,sep:_,value:v}=n,y=r.resolveProps(f,{indicator:`explicit-key-ind`,next:g??_?.[0],offset:m,onError:d,parentIndent:u.indent,startOnNewline:!0}),b=!y.found;if(b){if(g&&(g.type===`block-seq`?d(m,`BLOCK_AS_IMPLICIT_KEY`,`A block sequence may not be used as an implicit map key`):`indent`in g&&g.indent!==u.indent&&d(m,`BAD_INDENT`,s)),!y.anchor&&!y.tag&&!_){h=y.end,y.comment&&(p.comment?p.comment+=`
|
|
80
80
|
`+y.comment:p.comment=y.comment);continue}(y.newlineAfterProp||i.containsNewline(g))&&d(g??f[f.length-1],`MULTILINE_IMPLICIT_KEY`,`Implicit keys need to be on a single line`)}else y.found?.indent!==u.indent&&d(m,`BAD_INDENT`,s);l.atKey=!0;let x=y.end,S=g?e(l,g,y,d):c(l,x,f,null,y,d);l.schema.compat&&a.flowIndentCheck(u.indent,g,d),l.atKey=!1,o.mapIncludes(l,p.items,S)&&d(x,`DUPLICATE_KEY`,`Map keys must be unique`);let C=r.resolveProps(_??[],{indicator:`map-value-ind`,next:v,offset:S.range[2],onError:d,parentIndent:u.indent,startOnNewline:!g||g.type===`block-scalar`});if(m=C.end,C.found){b&&(v?.type===`block-map`&&!C.hasNewline&&d(m,`BLOCK_AS_IMPLICIT_KEY`,`Nested mappings are not allowed in compact mappings`),l.options.strict&&y.start<C.found.offset-1024&&d(S.range,`KEY_OVER_1024_CHARS`,`The : indicator must be at most 1024 chars after the start of an implicit block mapping key`));let r=v?e(l,v,C,d):c(l,m,_,null,C,d);l.schema.compat&&a.flowIndentCheck(u.indent,v,d),m=r.range[2];let i=new t.Pair(S,r);l.options.keepSourceTokens&&(i.srcToken=n),p.items.push(i)}else{b&&d(S.range,`MISSING_CHAR`,`Implicit map keys need to be followed by map values`),C.comment&&(S.comment?S.comment+=`
|
|
81
|
-
`+C.comment:S.comment=C.comment);let e=new t.Pair(S);l.options.keepSourceTokens&&(e.srcToken=n),p.items.push(e)}}return h&&h<m&&d(h,`IMPOSSIBLE`,`Map comment with trailing content`),p.range=[u.offset,m,h??m],p}e.resolveBlockMap=c})),
|
|
81
|
+
`+C.comment:S.comment=C.comment);let e=new t.Pair(S);l.options.keepSourceTokens&&(e.srcToken=n),p.items.push(e)}}return h&&h<m&&d(h,`IMPOSSIBLE`,`Map comment with trailing content`),p.range=[u.offset,m,h??m],p}e.resolveBlockMap=c})),Ba=/* @__PURE__ */ O((e=>{var t=da(),n=Fa(),r=La();function i({composeNode:e,composeEmptyNode:i},a,o,s,c){let l=new((c?.nodeClass)??t.YAMLSeq)(a.schema);a.atRoot&&=!1,a.atKey&&=!1;let u=o.offset,d=null;for(let{start:t,value:c}of o.items){let f=n.resolveProps(t,{indicator:`seq-item-ind`,next:c,offset:u,onError:s,parentIndent:o.indent,startOnNewline:!0});if(!f.found){if(f.anchor||f.tag||c)c?.type===`block-seq`?s(f.end,`BAD_INDENT`,`All sequence items must start at the same column`):s(u,`MISSING_CHAR`,`Sequence item without - indicator`);else{d=f.end,f.comment&&(l.comment=f.comment);continue}}let p=c?e(a,c,f,s):i(a,f.end,t,null,f,s);a.schema.compat&&r.flowIndentCheck(o.indent,c,s),u=p.range[2],l.items.push(p)}return l.range=[o.offset,u,d??u],l}e.resolveBlockSeq=i})),Va=/* @__PURE__ */ O((e=>{function t(e,t,n,r){let i=``;if(e){let a=!1,o=``;for(let s of e){let{source:e,type:c}=s;switch(c){case`space`:a=!0;break;case`comment`:{n&&!a&&r(s,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`);let t=e.substring(1)||` `;i?i+=o+t:i=t,o=``;break}case`newline`:i&&(o+=e),a=!0;break;default:r(s,`UNEXPECTED_TOKEN`,`Unexpected ${c} at node end`)}t+=e.length}}return{comment:i,offset:t}}e.resolveEnd=t})),Ha=/* @__PURE__ */ O((e=>{var t=B(),n=sa(),r=la(),i=da(),a=Va(),o=Fa(),s=Ia(),c=Ra();let l=`Block collections are not allowed within flow collections`,u=e=>e&&(e.type===`block-map`||e.type===`block-seq`);function d({composeNode:e,composeEmptyNode:d},f,p,m,h){let g=p.start.source===`{`,_=g?`flow map`:`flow sequence`,v=new((h?.nodeClass)??(g?r.YAMLMap:i.YAMLSeq))(f.schema);v.flow=!0;let y=f.atRoot;y&&(f.atRoot=!1),f.atKey&&=!1;let b=p.offset+p.start.source.length;for(let i=0;i<p.items.length;++i){let a=p.items[i],{start:h,key:y,sep:x,value:S}=a,C=o.resolveProps(h,{flow:_,indicator:`explicit-key-ind`,next:y??x?.[0],offset:b,onError:m,parentIndent:p.indent,startOnNewline:!1});if(!C.found){if(!C.anchor&&!C.tag&&!x&&!S){i===0&&C.comma?m(C.comma,`UNEXPECTED_TOKEN`,`Unexpected , in ${_}`):i<p.items.length-1&&m(C.start,`UNEXPECTED_TOKEN`,`Unexpected empty item in ${_}`),C.comment&&(v.comment?v.comment+=`
|
|
82
82
|
`+C.comment:v.comment=C.comment),b=C.end;continue}!g&&f.options.strict&&s.containsNewline(y)&&m(y,`MULTILINE_IMPLICIT_KEY`,`Implicit keys of flow sequence pairs need to be on a single line`)}if(i===0)C.comma&&m(C.comma,`UNEXPECTED_TOKEN`,`Unexpected , in ${_}`);else if(C.comma||m(C.start,`MISSING_CHAR`,`Missing , between ${_} items`),C.comment){let e=``;loop:for(let t of h)switch(t.type){case`comma`:case`space`:break;case`comment`:e=t.source.substring(1);break loop;default:break loop}if(e){let n=v.items[v.items.length-1];t.isPair(n)&&(n=n.value??n.key),n.comment?n.comment+=`
|
|
83
83
|
`+e:n.comment=e,C.comment=C.comment.substring(e.length+1)}}if(!g&&!x&&!C.found){let t=S?e(f,S,C,m):d(f,C.end,x,null,C,m);v.items.push(t),b=t.range[2],u(S)&&m(t.range,`BLOCK_IN_FLOW`,l)}else{f.atKey=!0;let t=C.end,i=y?e(f,y,C,m):d(f,t,h,null,C,m);u(y)&&m(i.range,`BLOCK_IN_FLOW`,l),f.atKey=!1;let s=o.resolveProps(x??[],{flow:_,indicator:`map-value-ind`,next:S,offset:i.range[2],onError:m,parentIndent:p.indent,startOnNewline:!1});if(s.found){if(!g&&!C.found&&f.options.strict){if(x)for(let e of x){if(e===s.found)break;if(e.type===`newline`){m(e,`MULTILINE_IMPLICIT_KEY`,`Implicit keys of flow sequence pairs need to be on a single line`);break}}C.start<s.found.offset-1024&&m(s.found,`KEY_OVER_1024_CHARS`,`The : indicator must be at most 1024 chars after the start of an implicit flow sequence key`)}}else S&&(`source`in S&&S.source?.[0]===`:`?m(S,`MISSING_CHAR`,`Missing space after : in ${_}`):m(s.start,`MISSING_CHAR`,`Missing , or : between ${_} items`));let w=S?e(f,S,s,m):s.found?d(f,s.end,x,null,s,m):null;w?u(S)&&m(w.range,`BLOCK_IN_FLOW`,l):s.comment&&(i.comment?i.comment+=`
|
|
84
84
|
`+s.comment:i.comment=s.comment);let T=new n.Pair(i,w);if(f.options.keepSourceTokens&&(T.srcToken=a),g){let e=v;c.mapIncludes(f,e.items,i)&&m(t,`DUPLICATE_KEY`,`Map keys must be unique`),e.items.push(T)}else{let e=new r.YAMLMap(f.schema);e.flow=!0,e.items.push(T);let t=(w??i).range;e.range=[i.range[0],t[1],t[2]],v.items.push(e)}b=w?w.range[2]:s.end}}let x=g?`}`:`]`,[S,...C]=p.end,w=b;if(S?.source===x)w=S.offset+S.source.length;else{let e=_[0].toUpperCase()+_.substring(1),t=y?`${e} must end with a ${x}`:`${e} in block collection must be sufficiently indented and end with a ${x}`;m(b,y?`MISSING_CHAR`:`BAD_INDENT`,t),S&&S.source.length!==1&&C.unshift(S)}if(C.length>0){let e=a.resolveEnd(C,w,f.options.strict,m);e.comment&&(v.comment?v.comment+=`
|
|
85
|
-
`+e.comment:v.comment=e.comment),v.range=[p.offset,w,e.offset]}else v.range=[p.offset,w,w];return v}e.resolveFlowCollection=d})),
|
|
85
|
+
`+e.comment:v.comment=e.comment),v.range=[p.offset,w,e.offset]}else v.range=[p.offset,w,w];return v}e.resolveFlowCollection=d})),Ua=/* @__PURE__ */ O((e=>{var t=B(),n=V(),r=la(),i=da(),a=za(),o=Ba(),s=Ha();function c(e,t,n,r,i,c){let l=n.type===`block-map`?a.resolveBlockMap(e,t,n,r,c):n.type===`block-seq`?o.resolveBlockSeq(e,t,n,r,c):s.resolveFlowCollection(e,t,n,r,c),u=l.constructor;return i===`!`||i===u.tagName?(l.tag=u.tagName,l):(i&&(l.tag=i),l)}function l(e,a,o,s,l){let u=s.tag,d=u?a.directives.tagName(u.source,e=>l(u,`TAG_RESOLVE_FAILED`,e)):null;if(o.type===`block-seq`){let{anchor:e,newlineAfterProp:t}=s,n=e&&u?e.offset>u.offset?e:u:e??u;n&&(!t||t.offset<n.offset)&&l(n,`MISSING_CHAR`,`Missing newline after block sequence props`)}let f=o.type===`block-map`?`map`:o.type===`block-seq`?`seq`:o.start.source===`{`?`map`:`seq`;if(!u||!d||d===`!`||d===r.YAMLMap.tagName&&f===`map`||d===i.YAMLSeq.tagName&&f===`seq`)return c(e,a,o,l,d);let p=a.schema.tags.find(e=>e.tag===d&&e.collection===f);if(!p){let t=a.schema.knownTags[d];if(t?.collection===f)a.schema.tags.push(Object.assign({},t,{default:!1})),p=t;else return t?l(u,`BAD_COLLECTION_TYPE`,`${t.tag} used for ${f} collection, but expects ${t.collection??`scalar`}`,!0):l(u,`TAG_RESOLVE_FAILED`,`Unresolved tag: ${d}`,!0),c(e,a,o,l,d)}let m=c(e,a,o,l,d,p),h=p.resolve?.(m,e=>l(u,`TAG_RESOLVE_FAILED`,e),a.options)??m,g=t.isNode(h)?h:new n.Scalar(h);return g.range=m.range,g.tag=d,p?.format&&(g.format=p.format),g}e.composeCollection=l})),Wa=/* @__PURE__ */ O((e=>{var t=V();function n(e,n,a){let o=n.offset,s=r(n,e.options.strict,a);if(!s)return{value:``,type:null,comment:``,range:[o,o,o]};let c=s.mode===`>`?t.Scalar.BLOCK_FOLDED:t.Scalar.BLOCK_LITERAL,l=n.source?i(n.source):[],u=l.length;for(let e=l.length-1;e>=0;--e){let t=l[e][1];if(t===``||t===`\r`)u=e;else break}if(u===0){let e=s.chomp===`+`&&l.length>0?`
|
|
86
86
|
`.repeat(Math.max(1,l.length-1)):``,t=o+s.length;return n.source&&(t+=n.source.length),{value:e,type:c,comment:s.comment,range:[o,t,t]}}let d=n.indent+s.indent,f=n.offset+s.length,p=0;for(let t=0;t<u;++t){let[n,r]=l[t];if(r===``||r===`\r`)s.indent===0&&n.length>d&&(d=n.length);else{n.length<d&&a(f+n.length,`MISSING_CHAR`,`Block scalars with more-indented leading empty lines must use an explicit indentation indicator`),s.indent===0&&(d=n.length),p=t,d===0&&!e.atRoot&&a(f,`BAD_INDENT`,`Block scalar values in collections must be indented`);break}f+=n.length+r.length+1}for(let e=l.length-1;e>=u;--e)l[e][0].length>d&&(u=e+1);let m=``,h=``,g=!1;for(let e=0;e<p;++e)m+=l[e][0].slice(d)+`
|
|
87
87
|
`;for(let e=p;e<u;++e){let[n,r]=l[e];f+=n.length+r.length+1;let i=r[r.length-1]===`\r`;
|
|
88
88
|
/* istanbul ignore if already caught in lexer */
|
|
@@ -103,7 +103,7 @@ if(i&&(r=r.slice(0,-1)),r&&n.length<d){let e=`Block scalar lines must not be les
|
|
|
103
103
|
/* istanbul ignore if should not happen */
|
|
104
104
|
if(t[0].type!==`block-scalar-header`)return r(t[0],`IMPOSSIBLE`,`Block scalar header not found`),null;let{source:i}=t[0],a=i[0],o=0,s=``,c=-1;for(let t=1;t<i.length;++t){let n=i[t];if(!s&&(n===`-`||n===`+`))s=n;else{let r=Number(n);!o&&r?o=r:c===-1&&(c=e+t)}}c!==-1&&r(c,`UNEXPECTED_TOKEN`,`Block scalar header includes extra characters: ${i}`);let l=!1,u=``,d=i.length;for(let e=1;e<t.length;++e){let i=t[e];switch(i.type){case`space`:l=!0;case`newline`:d+=i.source.length;break;case`comment`:n&&!l&&r(i,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`),d+=i.source.length,u=i.source.substring(1);break;case`error`:r(i,`UNEXPECTED_TOKEN`,i.message),d+=i.source.length;break;
|
|
105
105
|
/* istanbul ignore next should not happen */
|
|
106
|
-
default:{r(i,`UNEXPECTED_TOKEN`,`Unexpected token in block scalar header: ${i.type}`);let e=i.source;e&&typeof e==`string`&&(d+=e.length)}}}return{mode:a,indent:o,chomp:s,comment:u,length:d}}function i(e){let t=e.split(/\n( *)/),n=t[0],r=n.match(/^( *)/),i=[r?.[1]?[r[1],n.slice(r[1].length)]:[``,n]];for(let e=1;e<t.length;e+=2)i.push([t[e],t[e+1]]);return i}e.resolveBlockScalar=n})),
|
|
106
|
+
default:{r(i,`UNEXPECTED_TOKEN`,`Unexpected token in block scalar header: ${i.type}`);let e=i.source;e&&typeof e==`string`&&(d+=e.length)}}}return{mode:a,indent:o,chomp:s,comment:u,length:d}}function i(e){let t=e.split(/\n( *)/),n=t[0],r=n.match(/^( *)/),i=[r?.[1]?[r[1],n.slice(r[1].length)]:[``,n]];for(let e=1;e<t.length;e+=2)i.push([t[e],t[e+1]]);return i}e.resolveBlockScalar=n})),Ga=/* @__PURE__ */ O((e=>{var t=V(),n=Va();function r(e,r,o){let{offset:c,type:l,source:u,end:d}=e,f,p,m=(e,t,n)=>o(c+e,t,n);switch(l){case`scalar`:f=t.Scalar.PLAIN,p=i(u,m);break;case`single-quoted-scalar`:f=t.Scalar.QUOTE_SINGLE,p=a(u,m);break;case`double-quoted-scalar`:f=t.Scalar.QUOTE_DOUBLE,p=s(u,m);break;
|
|
107
107
|
/* istanbul ignore next should not happen */
|
|
108
108
|
default:return o(e,`UNEXPECTED_TOKEN`,`Expected a flow scalar value, but found: ${l}`),{value:``,type:null,comment:``,range:[c,c+u.length,c+u.length]}}let h=c+u.length,g=n.resolveEnd(d,h,r,o);return{value:p,type:f,comment:g.comment,range:[c,h,g.offset]}}function i(e,t){let n=``;switch(e[0]){
|
|
109
109
|
/* istanbul ignore next should not happen */
|
|
@@ -120,10 +120,10 @@ case` `:n=`a tab character`;break;case`,`:n=`flow indicator character ,`;break;c
|
|
|
120
120
|
`);)r===`
|
|
121
121
|
`&&(n+=`
|
|
122
122
|
`),t+=1,r=e[t+1];return n||=` `,{fold:n,offset:t}}let l={0:`\0`,a:`\x07`,b:`\b`,e:`\x1B`,f:`\f`,n:`
|
|
123
|
-
`,r:`\r`,t:` `,v:`\v`,N:`
`,_:`\xA0`,L:`\u2028`,P:`\u2029`," ":` `,'"':`"`,"/":`/`,"\\":`\\`," ":` `};function u(e,t,n,r){let i=e.substr(t,n),a=i.length===n&&/^[0-9a-fA-F]+$/.test(i)?parseInt(i,16):NaN;try{return String.fromCodePoint(a)}catch{let i=e.substr(t-2,n+2);return r(t-2,`BAD_DQ_ESCAPE`,`Invalid escape sequence ${i}`),i}}e.resolveFlowScalar=r})),
|
|
123
|
+
`,r:`\r`,t:` `,v:`\v`,N:`
`,_:`\xA0`,L:`\u2028`,P:`\u2029`," ":` `,'"':`"`,"/":`/`,"\\":`\\`," ":` `};function u(e,t,n,r){let i=e.substr(t,n),a=i.length===n&&/^[0-9a-fA-F]+$/.test(i)?parseInt(i,16):NaN;try{return String.fromCodePoint(a)}catch{let i=e.substr(t-2,n+2);return r(t-2,`BAD_DQ_ESCAPE`,`Invalid escape sequence ${i}`),i}}e.resolveFlowScalar=r})),Ka=/* @__PURE__ */ O((e=>{var t=B(),n=V(),r=Wa(),i=Ga();function a(e,a,c,l){let{value:u,type:d,comment:f,range:p}=a.type===`block-scalar`?r.resolveBlockScalar(e,a,l):i.resolveFlowScalar(a,e.options.strict,l),m=c?e.directives.tagName(c.source,e=>l(c,`TAG_RESOLVE_FAILED`,e)):null,h;h=e.options.stringKeys&&e.atKey?e.schema[t.SCALAR]:m?o(e.schema,u,m,c,l):a.type===`scalar`?s(e,u,a,l):e.schema[t.SCALAR];let g;try{let r=h.resolve(u,e=>l(c??a,`TAG_RESOLVE_FAILED`,e),e.options);g=t.isScalar(r)?r:new n.Scalar(r)}catch(e){let t=e instanceof Error?e.message:String(e);l(c??a,`TAG_RESOLVE_FAILED`,t),g=new n.Scalar(u)}return g.range=p,g.source=u,d&&(g.type=d),m&&(g.tag=m),h.format&&(g.format=h.format),f&&(g.comment=f),g}function o(e,n,r,i,a){if(r===`!`)return e[t.SCALAR];let o=[];for(let t of e.tags)if(!t.collection&&t.tag===r){if(t.default&&t.test)o.push(t);else return t}for(let e of o)if(e.test?.test(n))return e;let s=e.knownTags[r];return s&&!s.collection?(e.tags.push(Object.assign({},s,{default:!1,test:void 0})),s):(a(i,`TAG_RESOLVE_FAILED`,`Unresolved tag: ${r}`,r!==`tag:yaml.org,2002:str`),e[t.SCALAR])}function s({atKey:e,directives:n,schema:r},i,a,o){let s=r.tags.find(t=>(t.default===!0||e&&t.default===`key`)&&t.test?.test(i))||r[t.SCALAR];if(r.compat){let e=r.compat.find(e=>e.default&&e.test?.test(i))??r[t.SCALAR];s.tag!==e.tag&&o(a,`TAG_RESOLVE_FAILED`,`Value may be parsed as either ${n.tagString(s.tag)} or ${n.tagString(e.tag)}`,!0)}return s}e.composeScalar=a})),qa=/* @__PURE__ */ O((e=>{function t(e,t,n){if(t){n??=t.length;for(let r=n-1;r>=0;--r){let n=t[r];switch(n.type){case`space`:case`comment`:case`newline`:e-=n.source.length;continue}for(n=t[++r];n?.type===`space`;)e+=n.source.length,n=t[++r];break}}return e}e.emptyScalarPosition=t})),Ja=/* @__PURE__ */ O((e=>{var t=Xi(),n=B(),r=Ua(),i=Ka(),a=Va(),o=qa();let s={composeNode:c,composeEmptyNode:l};function c(e,t,a,o){let c=e.atKey,{spaceBefore:d,comment:f,anchor:p,tag:m}=a,h,g=!0;switch(t.type){case`alias`:h=u(e,t,o),(p||m)&&o(t,`ALIAS_PROPS`,`An alias node must not specify any properties`);break;case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:case`block-scalar`:h=i.composeScalar(e,t,m,o),p&&(h.anchor=p.source.substring(1));break;case`block-map`:case`block-seq`:case`flow-collection`:try{h=r.composeCollection(s,e,t,a,o),p&&(h.anchor=p.source.substring(1))}catch(e){o(t,`RESOURCE_EXHAUSTION`,e instanceof Error?e.message:String(e))}break;default:o(t,`UNEXPECTED_TOKEN`,t.type===`error`?t.message:`Unsupported token (type: ${t.type})`),g=!1}return h??=l(e,t.offset,void 0,null,a,o),p&&h.anchor===``&&o(p,`BAD_ALIAS`,`Anchor cannot be an empty string`),c&&e.options.stringKeys&&(!n.isScalar(h)||typeof h.value!=`string`||h.tag&&h.tag!==`tag:yaml.org,2002:str`)&&o(m??t,`NON_STRING_KEY`,`With stringKeys, all keys must be strings`),d&&(h.spaceBefore=!0),f&&(t.type===`scalar`&&t.source===``?h.comment=f:h.commentBefore=f),e.options.keepSourceTokens&&g&&(h.srcToken=t),h}function l(e,t,n,r,{spaceBefore:a,comment:s,anchor:c,tag:l,end:u},d){let f={type:`scalar`,offset:o.emptyScalarPosition(t,n,r),indent:-1,source:``},p=i.composeScalar(e,f,l,d);return c&&(p.anchor=c.source.substring(1),p.anchor===``&&d(c,`BAD_ALIAS`,`Anchor cannot be an empty string`)),a&&(p.spaceBefore=!0),s&&(p.comment=s,p.range[2]=u),p}function u({options:e},{offset:n,source:r,end:i},o){let s=new t.Alias(r.substring(1));s.source===``&&o(n,`BAD_ALIAS`,`Alias cannot be an empty string`),s.source.endsWith(`:`)&&o(n+r.length-1,`BAD_ALIAS`,`Alias ending in : is ambiguous`,!0);let c=n+r.length,l=a.resolveEnd(i,c,e.strict,o);return s.range=[n,c,l.offset],l.comment&&(s.comment=l.comment),s}e.composeEmptyNode=l,e.composeNode=c})),Ya=/* @__PURE__ */ O((e=>{var t=Na(),n=Ja(),r=Va(),i=Fa();function a(e,a,{offset:o,start:s,value:c,end:l},u){let d=Object.assign({_directives:a},e),f=new t.Document(void 0,d),p={atKey:!1,atRoot:!0,directives:f.directives,options:f.options,schema:f.schema},m=i.resolveProps(s,{indicator:`doc-start`,next:c??l?.[0],offset:o,onError:u,parentIndent:0,startOnNewline:!0});m.found&&(f.directives.docStart=!0,c&&(c.type===`block-map`||c.type===`block-seq`)&&!m.hasNewline&&u(m.end,`MISSING_CHAR`,`Block collection cannot start on same line with directives-end marker`)),f.contents=c?n.composeNode(p,c,m,u):n.composeEmptyNode(p,m.end,s,null,m,u);let h=f.contents.range[2],g=r.resolveEnd(l,h,!1,u);return g.comment&&(f.comment=g.comment),f.range=[o,h,g.offset],f}e.composeDoc=a})),Xa=/* @__PURE__ */ O((e=>{var t=te(`process`),n=Gi(),r=Na(),i=Pa(),a=B(),o=Ya(),s=Va();function c(e){if(typeof e==`number`)return[e,e+1];if(Array.isArray(e))return e.length===2?e:[e[0],e[1]];let{offset:t,source:n}=e;return[t,t+(typeof n==`string`?n.length:1)]}function l(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;++i){let a=e[i];switch(a[0]){case`#`:t+=(t===``?``:r?`
|
|
124
124
|
|
|
125
125
|
`:`
|
|
126
|
-
`)+(a.substring(1)||` `),n=!0,r=!1;break;case`%`:e[i+1]?.[0]!==`#`&&(i+=1),n=!1;break;default:n||(r=!0),n=!1}}return{comment:t,afterEmptyLine:r}}e.Composer=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,r)=>{let a=c(e);r?this.warnings.push(new i.YAMLWarning(a,t,n)):this.errors.push(new i.YAMLParseError(a,t,n))},this.directives=new n.Directives({version:e.version||`1.2`}),this.options=e}decorate(e,t){let{comment:n,afterEmptyLine:r}=l(this.prelude);if(n){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(r||e.directives.docStart||!i)e.commentBefore=n;else if(a.isCollection(i)&&!i.flow&&i.items.length>0){let e=i.items[0];a.isPair(e)&&(e=e.key);let t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{let e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}if(t){for(let t=0;t<this.errors.length;++t)e.errors.push(this.errors[t]);for(let t=0;t<this.warnings.length;++t)e.warnings.push(this.warnings[t])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:l(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(let t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(t.env.LOG_STREAM&&console.dir(e,{depth:null}),e.type){case`directive`:this.directives.add(e.source,(t,n,r)=>{let i=c(e);i[0]+=t,this.onError(i,`BAD_DIRECTIVE`,n,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case`document`:{let t=o.composeDoc(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,`MISSING_CHAR`,`Missing directives-end/doc-start indicator line`),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case`byte-order-mark`:case`space`:break;case`comment`:case`newline`:this.prelude.push(e.source);break;case`error`:{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case`doc-end`:{if(!this.doc){this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unexpected doc-end without preceding document`));break}this.doc.directives.docEnd=!0;let t=s.resolveEnd(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let e=Object.assign({_directives:this.directives},this.options),n=new r.Document(void 0,e);this.atDirectives&&this.onError(t,`MISSING_CHAR`,`Missing directives-end indicator line`),n.range=[0,t,t],this.decorate(n,!1),yield n}}}})),
|
|
126
|
+
`)+(a.substring(1)||` `),n=!0,r=!1;break;case`%`:e[i+1]?.[0]!==`#`&&(i+=1),n=!1;break;default:n||(r=!0),n=!1}}return{comment:t,afterEmptyLine:r}}e.Composer=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,r)=>{let a=c(e);r?this.warnings.push(new i.YAMLWarning(a,t,n)):this.errors.push(new i.YAMLParseError(a,t,n))},this.directives=new n.Directives({version:e.version||`1.2`}),this.options=e}decorate(e,t){let{comment:n,afterEmptyLine:r}=l(this.prelude);if(n){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(r||e.directives.docStart||!i)e.commentBefore=n;else if(a.isCollection(i)&&!i.flow&&i.items.length>0){let e=i.items[0];a.isPair(e)&&(e=e.key);let t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{let e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}if(t){for(let t=0;t<this.errors.length;++t)e.errors.push(this.errors[t]);for(let t=0;t<this.warnings.length;++t)e.warnings.push(this.warnings[t])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:l(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(let t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(t.env.LOG_STREAM&&console.dir(e,{depth:null}),e.type){case`directive`:this.directives.add(e.source,(t,n,r)=>{let i=c(e);i[0]+=t,this.onError(i,`BAD_DIRECTIVE`,n,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case`document`:{let t=o.composeDoc(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,`MISSING_CHAR`,`Missing directives-end/doc-start indicator line`),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case`byte-order-mark`:case`space`:break;case`comment`:case`newline`:this.prelude.push(e.source);break;case`error`:{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case`doc-end`:{if(!this.doc){this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unexpected doc-end without preceding document`));break}this.doc.directives.docEnd=!0;let t=s.resolveEnd(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let e=Object.assign({_directives:this.directives},this.options),n=new r.Document(void 0,e);this.atDirectives&&this.onError(t,`MISSING_CHAR`,`Missing directives-end indicator line`),n.range=[0,t,t],this.decorate(n,!1),yield n}}}})),Za=/* @__PURE__ */ O((e=>{var t=Wa(),n=Ga(),r=Pa(),i=ta();function a(e,i=!0,a){if(e){let o=(e,t,n)=>{let i=typeof e==`number`?e:Array.isArray(e)?e[0]:e.offset;if(a)a(i,t,n);else throw new r.YAMLParseError([i,i+1],t,n)};switch(e.type){case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return n.resolveFlowScalar(e,i,o);case`block-scalar`:return t.resolveBlockScalar({options:{strict:i}},e,o)}}return null}function o(e,t){let{implicitKey:n=!1,indent:r,inFlow:a=!1,offset:o=-1,type:s=`PLAIN`}=t,c=i.stringifyString({type:s,value:e},{implicitKey:n,indent:r>0?` `.repeat(r):``,inFlow:a,options:{blockQuote:!0,lineWidth:-1}}),u=t.end??[{type:`newline`,offset:-1,indent:r,source:`
|
|
127
127
|
`}];switch(c[0]){case`|`:case`>`:{let e=c.indexOf(`
|
|
128
128
|
`),t=c.substring(0,e),n=c.substring(e+1)+`
|
|
129
129
|
`,i=[{type:`block-scalar-header`,offset:o,indent:r,source:t}];return l(i,u)||i.push({type:`newline`,offset:-1,indent:r,source:`
|
|
@@ -131,11 +131,11 @@ case` `:n=`a tab character`;break;case`,`:n=`flow indicator character ,`;break;c
|
|
|
131
131
|
`),r=t.substring(0,n),i=t.substring(n+1)+`
|
|
132
132
|
`;if(e.type===`block-scalar`){let t=e.props[0];if(t.type!==`block-scalar-header`)throw Error(`Invalid block scalar header`);t.source=r,e.source=i}else{let{offset:t}=e,n=`indent`in e?e.indent:-1,a=[{type:`block-scalar-header`,offset:t,indent:n,source:r}];l(a,`end`in e?e.end:void 0)||a.push({type:`newline`,offset:-1,indent:n,source:`
|
|
133
133
|
`});for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:`block-scalar`,indent:n,props:a,source:i})}}function l(e,t){if(t)for(let n of t)switch(n.type){case`space`:case`comment`:e.push(n);break;case`newline`:return e.push(n),!0}return!1}function u(e,t,n){switch(e.type){case`scalar`:case`double-quoted-scalar`:case`single-quoted-scalar`:e.type=n,e.source=t;break;case`block-scalar`:{let r=e.props.slice(1),i=t.length;e.props[0].type===`block-scalar-header`&&(i-=e.props[0].source.length);for(let e of r)e.offset+=i;delete e.props,Object.assign(e,{type:n,source:t,end:r});break}case`block-map`:case`block-seq`:{let r={type:`newline`,offset:e.offset+t.length,indent:e.indent,source:`
|
|
134
|
-
`};delete e.items,Object.assign(e,{type:n,source:t,end:[r]});break}default:{let r=`indent`in e?e.indent:-1,i=`end`in e&&Array.isArray(e.end)?e.end.filter(e=>e.type===`space`||e.type===`comment`||e.type===`newline`):[];for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:n,indent:r,source:t,end:i})}}}e.createScalarToken=o,e.resolveAsScalar=a,e.setScalarValue=s})),
|
|
134
|
+
`};delete e.items,Object.assign(e,{type:n,source:t,end:[r]});break}default:{let r=`indent`in e?e.indent:-1,i=`end`in e&&Array.isArray(e.end)?e.end.filter(e=>e.type===`space`||e.type===`comment`||e.type===`newline`):[];for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:n,indent:r,source:t,end:i})}}}e.createScalarToken=o,e.resolveAsScalar=a,e.setScalarValue=s})),Qa=/* @__PURE__ */ O((e=>{let t=e=>`type`in e?n(e):r(e);function n(e){switch(e.type){case`block-scalar`:{let t=``;for(let r of e.props)t+=n(r);return t+e.source}case`block-map`:case`block-seq`:{let t=``;for(let n of e.items)t+=r(n);return t}case`flow-collection`:{let t=e.start.source;for(let n of e.items)t+=r(n);for(let n of e.end)t+=n.source;return t}case`document`:{let t=r(e);if(e.end)for(let n of e.end)t+=n.source;return t}default:{let t=e.source;if(`end`in e&&e.end)for(let n of e.end)t+=n.source;return t}}}function r({start:e,key:t,sep:r,value:i}){let a=``;for(let t of e)a+=t.source;if(t&&(a+=n(t)),r)for(let e of r)a+=e.source;return i&&(a+=n(i)),a}e.stringify=t})),$a=/* @__PURE__ */ O((e=>{let t=Symbol(`break visit`),n=Symbol(`skip children`),r=Symbol(`remove item`);function i(e,t){`type`in e&&e.type===`document`&&(e={start:e.start,value:e.value}),a(Object.freeze([]),e,t)}i.BREAK=t,i.SKIP=n,i.REMOVE=r,i.itemAtPath=(e,t)=>{let n=e;for(let[e,r]of t){let t=n?.[e];if(t&&`items`in t)n=t.items[r];else return}return n},i.parentCollection=(e,t)=>{let n=i.itemAtPath(e,t.slice(0,-1)),r=t[t.length-1][0],a=n?.[r];if(a&&`items`in a)return a;throw Error(`Parent collection not found`)};function a(e,n,i){let o=i(n,e);if(typeof o==`symbol`)return o;for(let s of[`key`,`value`]){let c=n[s];if(c&&`items`in c){for(let n=0;n<c.items.length;++n){let o=a(Object.freeze(e.concat([[s,n]])),c.items[n],i);if(typeof o==`number`)n=o-1;else if(o===t)return t;else o===r&&(c.items.splice(n,1),--n)}typeof o==`function`&&s===`key`&&(o=o(n,e))}}return typeof o==`function`?o(n,e):o}e.visit=i})),eo=/* @__PURE__ */ O((e=>{var t=Za(),n=Qa(),r=$a();let i=e=>!!e&&`items`in e,a=e=>!!e&&(e.type===`scalar`||e.type===`single-quoted-scalar`||e.type===`double-quoted-scalar`||e.type===`block-scalar`);
|
|
135
135
|
/* istanbul ignore next */
|
|
136
136
|
function o(e){switch(e){case``:return`<BOM>`;case``:return`<DOC>`;case``:return`<FLOW_END>`;case``:return`<SCALAR>`;default:return JSON.stringify(e)}}function s(e){switch(e){case``:return`byte-order-mark`;case``:return`doc-mode`;case``:return`flow-error-end`;case``:return`scalar`;case`---`:return`doc-start`;case`...`:return`doc-end`;case``:case`
|
|
137
137
|
`:case`\r
|
|
138
|
-
`:return`newline`;case`-`:return`seq-item-ind`;case`?`:return`explicit-key-ind`;case`:`:return`map-value-ind`;case`{`:return`flow-map-start`;case`}`:return`flow-map-end`;case`[`:return`flow-seq-start`;case`]`:return`flow-seq-end`;case`,`:return`comma`}switch(e[0]){case` `:case` `:return`space`;case`#`:return`comment`;case`%`:return`directive-line`;case`*`:return`alias`;case`&`:return`anchor`;case`!`:return`tag`;case`'`:return`single-quoted-scalar`;case`"`:return`double-quoted-scalar`;case`|`:case`>`:return`block-scalar-header`}return null}e.createScalarToken=t.createScalarToken,e.resolveAsScalar=t.resolveAsScalar,e.setScalarValue=t.setScalarValue,e.stringify=n.stringify,e.visit=r.visit,e.BOM=``,e.DOCUMENT=``,e.FLOW_END=``,e.SCALAR=``,e.isCollection=i,e.isScalar=a,e.prettyToken=o,e.tokenType=s})),
|
|
138
|
+
`:return`newline`;case`-`:return`seq-item-ind`;case`?`:return`explicit-key-ind`;case`:`:return`map-value-ind`;case`{`:return`flow-map-start`;case`}`:return`flow-map-end`;case`[`:return`flow-seq-start`;case`]`:return`flow-seq-end`;case`,`:return`comma`}switch(e[0]){case` `:case` `:return`space`;case`#`:return`comment`;case`%`:return`directive-line`;case`*`:return`alias`;case`&`:return`anchor`;case`!`:return`tag`;case`'`:return`single-quoted-scalar`;case`"`:return`double-quoted-scalar`;case`|`:case`>`:return`block-scalar-header`}return null}e.createScalarToken=t.createScalarToken,e.resolveAsScalar=t.resolveAsScalar,e.setScalarValue=t.setScalarValue,e.stringify=n.stringify,e.visit=r.visit,e.BOM=``,e.DOCUMENT=``,e.FLOW_END=``,e.SCALAR=``,e.isCollection=i,e.isScalar=a,e.prettyToken=o,e.tokenType=s})),to=/* @__PURE__ */ O((e=>{var t=eo();function n(e){switch(e){case void 0:case` `:case`
|
|
139
139
|
`:case`\r`:case` `:return!0;default:return!1}}let r=/* @__PURE__ */ new Set(`0123456789ABCDEFabcdef`),i=/* @__PURE__ */ new Set(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()`),a=/* @__PURE__ */ new Set(`,[]{}`),o=/* @__PURE__ */ new Set(` ,[]{}
|
|
140
140
|
\r `),s=e=>!e||o.has(e);e.Lexer=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer=``,this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if(typeof e!=`string`)throw TypeError(`source is not a string`);this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let n=this.next??`stream`;for(;n&&(t||this.hasChars(1));)n=yield*this.parseNext(n)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;t===` `||t===` `;)t=this.buffer[++e];return!t||t===`#`||t===`
|
|
141
141
|
`||t===`\r`&&this.buffer[e+1]===`
|
|
@@ -154,7 +154,7 @@ function o(e){switch(e){case``:return`<BOM>`;case``:return`<DOC>`;case``:re
|
|
|
154
154
|
`,t=this.buffer[i+1]):r=i),t===`#`||e&&a.has(t))break;if(o===`
|
|
155
155
|
`){let e=this.continueScalar(i+1);if(e===-1)break;i=Math.max(i,e-2)}}else{if(e&&a.has(o))break;r=i}return!o&&!this.atEnd?this.setNext(`plain-scalar`):(yield t.SCALAR,yield*this.pushToIndex(r+1,!0),e?`flow`:`doc`)}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){let n=this.buffer.slice(this.pos,e);return n?(yield n,this.pos+=n.length,n.length):(t&&(yield``),0)}*pushIndicators(){let e=0;loop:for(;;){switch(this.charAt(0)){case`!`:e+=yield*this.pushTag(),e+=yield*this.pushSpaces(!0);continue loop;case`&`:e+=yield*this.pushUntil(s),e+=yield*this.pushSpaces(!0);continue loop;case`-`:case`?`:case`:`:{let t=this.flowLevel>0,r=this.charAt(1);if(n(r)||t&&a.has(r)){t?this.flowKey&&=!1:this.indentNext=this.indentValue+1,e+=yield*this.pushCount(1),e+=yield*this.pushSpaces(!0);continue loop}}}break loop}return e}*pushTag(){if(this.charAt(1)===`<`){let e=this.pos+2,t=this.buffer[e];for(;!n(t)&&t!==`>`;)t=this.buffer[++e];return yield*this.pushToIndex(t===`>`?e+1:e,!1)}{let e=this.pos+1,t=this.buffer[e];for(;t;)if(i.has(t))t=this.buffer[++e];else if(t===`%`&&r.has(this.buffer[e+1])&&r.has(this.buffer[e+2]))t=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
|
|
156
156
|
`?yield*this.pushCount(1):e===`\r`&&this.charAt(1)===`
|
|
157
|
-
`?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,n;do n=this.buffer[++t];while(n===` `||e&&n===` `);let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}}})),
|
|
157
|
+
`?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,n;do n=this.buffer[++t];while(n===` `||e&&n===` `);let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}}})),no=/* @__PURE__ */ O((e=>{e.LineCounter=class{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let t=0,n=this.lineStarts.length;for(;t<n;){let r=t+n>>1;this.lineStarts[r]<e?t=r+1:n=r}if(this.lineStarts[t]===e)return{line:t+1,col:1};if(t===0)return{line:0,col:e};let r=this.lineStarts[t-1];return{line:t,col:e-r+1}}}}})),ro=/* @__PURE__ */ O((e=>{var t=te(`process`),n=eo(),r=to();function i(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function a(e){for(let t=0;t<e.length;++t)switch(e[t].type){case`space`:case`comment`:case`newline`:break;default:return t}return-1}function o(e){switch(e?.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:case`flow-collection`:return!0;default:return!1}}function s(e){switch(e.type){case`document`:return e.start;case`block-map`:{let t=e.items[e.items.length-1];return t.sep??t.start}case`block-seq`:return e.items[e.items.length-1].start;
|
|
158
158
|
/* istanbul ignore next should not happen */
|
|
159
159
|
default:return[]}}function c(e){if(e.length===0)return[];let t=e.length;loop:for(;--t>=0;)switch(e[t].type){case`doc-start`:case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:case`newline`:break loop}for(;e[++t]?.type===`space`;);return e.splice(t,e.length)}function l(e,t){if(t.length<1e5)Array.prototype.push.apply(e,t);else for(let n=0;n<t.length;++n)e.push(t[n])}function u(e){if(e.start.type===`flow-seq-start`)for(let t of e.items)t.sep&&!t.value&&!i(t.start,`explicit-key-ind`)&&!i(t.sep,`map-value-ind`)&&(t.key&&(t.value=t.key),delete t.key,o(t.value)?t.value.end?l(t.value.end,t.sep):t.value.end=t.sep:l(t.start,t.sep),delete t.sep)}e.Parser=class{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source=``,this.type=``,this.lexer=new r.Lexer,this.onNewLine=e}*parse(e,t=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(let n of this.lexer.lex(e,t))yield*this.next(n);t||(yield*this.end())}*next(e){if(this.source=e,t.env.LOG_TOKENS&&console.log(`|`,n.prettyToken(e)),this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=e.length;return}let r=n.tokenType(e);if(!r){let t=`Not a YAML token: ${e}`;yield*this.pop({type:`error`,offset:this.offset,message:t,source:e}),this.offset+=e.length}else if(r===`scalar`)this.atNewLine=!1,this.atScalar=!0,this.type=`scalar`;else{switch(this.type=r,yield*this.step(),r){case`newline`:this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case`space`:this.atNewLine&&e[0]===` `&&(this.indent+=e.length);break;case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:this.atNewLine&&(this.indent+=e.length);break;case`doc-mode`:case`flow-error-end`:return;default:this.atNewLine=!1}this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){let e=this.peek(1);if(this.type===`doc-end`&&e?.type!==`doc-end`){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:`doc-end`,offset:this.offset,source:this.source});return}if(!e)return yield*this.stream();switch(e.type){case`document`:return yield*this.document(e);case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return yield*this.scalar(e);case`block-scalar`:return yield*this.blockScalar(e);case`block-map`:return yield*this.blockMap(e);case`block-seq`:return yield*this.blockSequence(e);case`flow-collection`:return yield*this.flowCollection(e);case`doc-end`:return yield*this.documentEnd(e)}
|
|
160
160
|
/* istanbul ignore next should not happen */
|
|
@@ -170,21 +170,21 @@ default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.l
|
|
|
170
170
|
/* istanbul ignore else should not happen */
|
|
171
171
|
n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=c(s(t));u(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
|
|
172
172
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
173
|
-
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Ga=/* @__PURE__ */ D((e=>{var t=La(),n=ba(),r=xa(),i=Gi(),a=H(),o=Ua(),s=Wa();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Ka=(/* @__PURE__ */ D((e=>{var t=La(),n=ba(),r=va(),i=xa(),a=Li(),o=H(),s=Ji(),c=U(),l=Xi(),u=Qi();Va();var d=Ha(),f=Ua(),p=Wa(),m=Ga(),h=ji();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();const qa=[`replace`,`patch`,`combine`,`remove`];function Ja(e){return qa.includes(e)}const Ya=/^---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;function Xa(e,t){let n=Ya.exec(e);if(!n)return{metadata:{},body:e};let r=e.slice(n[0].length);try{let e=(0,Ka.parse)(n[1]);if(e==null)return{metadata:{},body:r};if(V(e))return{metadata:e,body:r}}catch{}return t(`frontmatter-invalid`,`frontmatter is not a YAML mapping; it is ignored`),{metadata:{},body:r}}function Za(e,t){let n=e.merge;if(n!==void 0)return Ja(n)?n:(t(`merge-unknown`,`unknown merge "${String(n)}"; read as patch`),`patch`)}function Qa(e){return ro(e).trim().length>0}const $a=/^\s*<!--\s*merge:\s*([\w-]*)\s*-->\s*$/,eo=/^ {0,3}(#{1,6})(?:[ \t]+(.*?))?(?:[ \t]+#+)?[ \t]*$/,to=/^ {0,3}(`{3,}|~{3,})/;function no(){let e;return t=>{if(e)return RegExp(`^ {0,3}${e[0]==="`"?"`":`~`}{${e.length},}\\s*$`).test(t)&&(e=void 0),!0;let n=to.exec(t);return n?(e=n[1],!0):!1}}function ro(e){let t=no();return e.split(`
|
|
174
|
-
`).
|
|
175
|
-
|
|
176
|
-
`)){if(t(r))
|
|
177
|
-
`)
|
|
178
|
-
`)
|
|
179
|
-
`)
|
|
180
|
-
|
|
181
|
-
`)}\n`:``}function vo(e){let t=[];e.preambleSources.length&&t.push({path:`(before the first heading)`,sources:e.preambleSources});let n=(e,r)=>{let i=lo(r,e.title);t.push({path:i,sources:e.sources});for(let t of e.children)n(t,i)};for(let t of e.children)n(t,``);return t}function yo(e){let t=[],n=(e,r)=>{let i=lo(r,e.title);t.push(i);for(let t of e.children)n(t,i)};for(let t of oo(e,()=>{}).children)n(t,``);return t}const W=[{extension:`.json`,format:`json`},{extension:`.yaml`,format:`yaml`},{extension:`.yml`,format:`yaml`},{extension:`.toml`,format:`toml`},{extension:`.txt`,format:`txt`}];function bo(e){return W.find(({extension:t})=>e.endsWith(t))?.format??`markdown`}const xo=`.interface`,So=/^([a-z0-9]+(?:[-.][a-z0-9]+)*)@(\d+)$/i;function Co(e){return e.endsWith(`.interface`)&&e.length>10?e.slice(0,-10):void 0}function wo(e){return typeof e==`number`&&Number.isInteger(e)&&e>0}function To(e){if(typeof e==`string`&&e.trim())return e.trim();if(V(e)){let t=Object.keys(e),[n]=t;if(t.length===1&&n?.trim())return n.trim()}return{problem:`section ${JSON.stringify(e)} is not a heading name`}}function Eo(e){return e.trim().replace(/\s+/g,` `).toLowerCase()}function Do(e,t){let n=t.interface;if(!V(n))return{problems:[n===void 0?"has no `interface:` block in its frontmatter":"`interface:` is not a mapping"]};let r=[],i=n.cardinality;i!==`one`&&i!==`many`&&r.push(`cardinality is ${JSON.stringify(i)}; it is one or many`);let a=n.version;wo(a)||r.push(`version is ${JSON.stringify(a)}; it is a positive integer`);let o=n.versions,s=wo(a)?[a]:[];o!==void 0&&(Array.isArray(o)&&o.length&&o.every(wo)?s=o:r.push(`versions is not a list of positive integers`));let c=n.sections,l=[];if(!Array.isArray(c)||!c.length)r.push(`sections is not a list of headings`);else{let e=/* @__PURE__ */ new Set;for(let t of c){let n=To(t);if(typeof n!=`string`){r.push(n.problem);continue}let i=Eo(n);e.has(i)&&r.push(`section "${n}" is listed more than once`),e.add(i),l.push(n)}}return r.length?{problems:r}:{value:{id:e,cardinality:i,version:a,versions:s,sections:l},problems:r}}function Oo(e){let t=e.implements;if(t===void 0)return{problems:[]};let n=Array.isArray(t)?t:[t];if(n.length!==1)return{problems:[n.length?`implements lists ${n.length} interfaces; an implementation implements one`:`implements is an empty list`]};let[r]=n,i=typeof r==`string`?So.exec(r.trim()):null;return i?{entry:{id:i[1],version:Number(i[2])},problems:[]}:{problems:[`implements ${JSON.stringify(r)} is not <id>@<version>`]}}function ko(e,t){return e.cardinality===`one`?t===e.id:t.startsWith(`${e.id}.`)&&t.length>e.id.length+1&&!t.endsWith(`.interface`)}function Ao(e){let t=[],n=e=>{if(e.depth===0){let n=e.text.find(e=>e.trim());t.push({title:e.title,unsupported:n?.trim().startsWith(`**Unsupported.**`)??!1})}for(let t of e.children)n(t)};for(let t of oo(e,()=>{}).children)n(t);return t}function jo(e,{name:t,version:n,content:r,accept:i=e.versions}){let a=[],o=(t,n)=>a.push({check:t,interface:e.id,message:n});i.includes(n)||o(`version`,`unknown version ${n}`),ko(e,t)||o(`name`,`name ${t} is not ${e.cardinality===`one`?e.id:`${e.id}.<key>`}`);let s=Ao(r),c=e.sections.map(Eo),l=e.sections.filter(e=>{let t=s.find(t=>Eo(t.title)===Eo(e));return!t||t.unsupported}),u=-1,d=``,f=/* @__PURE__ */ new Set;for(let e of s){let t=Eo(e.title),n=c.indexOf(t);n!==-1&&(f.has(t)?o(`order`,`section ${e.title} appears more than once`):n<u&&o(`order`,`section ${e.title} comes after ${d}`),f.add(t),n>u&&(u=n,d=e.title))}return{failures:a,unsupported:l}}const Mo=/^[a-z0-9]+(?:[-.][a-z0-9]+)*$/i,No=`.default`;function G(e){let t=t=>({raw:e,name:e,invalid:t});if(e.endsWith(`.md`))return t(`"${e}" names a file. Ask for the reference by name, without the .md extension.`);let n=W.find(t=>e.endsWith(t.extension));if(n)return t(`"${e}" names a file. Ask for the reference by name, without the ${n.extension} extension.`);let r=e.split(`/`);if(r.length>2||e.includes(`\\`))return t(`"${e}" is a path. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/".`);let[i,a]=r,o=a??i,s=a===void 0?void 0:i;return o.endsWith(`.default`)?t(`"${e}" names a skill's default file. Ask for "${o.slice(0,-8)}"; the default joins when its skill loads it.`):!Mo.test(o)||s!==void 0&&!Mo.test(s)?t(`"${e}" is not a reference name. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/", where <plugin> is a plugin's manifest name.`):s===void 0?{raw:e,name:o}:{raw:e,name:o,plugin:s}}function Po(e){return Array.isArray(e)?{layers:[...e],harnesses:[]}:e}function Fo(e){try{return o(e,`utf8`)}catch{return}}function Io(e,t){return e.whole?[`${t}.md`,...W.map(({extension:e})=>`${t}${e}`)]:e.tier==="default"?[`${t}${No}.md`,...W.map(({extension:e})=>`${t}${No}${e}`)]:[`${t}.md`,`${t}/README.md`,...W.map(({extension:e})=>`${t}${e}`)]}function Lo(e,t,n){return e.tier===`plugin`?`plugin ${e.plugin}`:e.tier==="default"?`default of ${e.skill}`:`${e.tier} ${n(t)}`}function Ro(e,t){if(e===void 0)return;let n=e=>{t(`extends-invalid`,`\`extends\` ${e}; it is read as not written`)},r=typeof e==`string`?[e]:Array.isArray(e)?e:void 0;if(!r)return n(`is not a list of plugins`);let i=[];for(let e of r){let r=zo(e,t);if(typeof r==`string`)return n(r);i.push(r)}return i}function zo(e,t){if(typeof e==`string`)return Mo.test(e)?{target:e}:`names "${e}", which is not a plugin name or default`;if(!V(e)||Object.keys(e).length!==1)return`holds ${JSON.stringify(e)}, which is not a step`;let[n,r]=Object.entries(e)[0];if(!Mo.test(n))return`names "${n}", which is not a plugin name or default`;if(r==null)return{target:n};let i={target:n};if(typeof r==`string`)return i.merge=Bo(r,n,t),i;if(!V(r)||Object.keys(r).some(e=>e!==`merge`&&e!==`extends`))return`gives "${n}" keys other than merge and extends`;if(r.merge!==void 0&&(i.merge=Bo(r.merge,n,t)),r.extends!==void 0){let e=Ro(r.extends,t);if(!e)return`gives "${n}" a malformed extends`;i.extends=e}return i}function Bo(e,t,n){return Ja(e)?e:(n(`merge-unknown`,`unknown merge "${String(e)}" on the step ${t}; read as patch`),`patch`)}function Vo(e,t,n,r,i){let a={entries:[],missing:[],allMissing:!1,replaced:[]},o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=(e,t,n)=>{let r=[];for(let o of e){if(o.target===n){i(`extends-self`,`${t} lists itself in its extends; that entry is ignored`);continue}r.at(-1)?.target!==o.target&&(r.some(({target:e})=>e===o.target)&&!a.ambiguous&&(a.ambiguous={cause:`repeat`,message:`${t}'s extends lists ${o.target} at two places`}),r.push(o))}return r},l=c(e,t),u=new Set(l.map(({target:e})=>e)),d=(e,l,f)=>{if(a.ambiguous||o.has(e.target))return;if(s.has(e.target)){n===`plugins`&&(a.ambiguous={cause:`cycle`,message:`the plugins' own extends form a cycle: ${[...f,e.target].join(` → `)}`});return}if(!l&&u.has(e.target))return;let p=r(e.target);if(`reason`in p){a.missing.push({target:e.target,reason:p.reason}),e.target!=="default"&&i(`extends-step-missing`,`the step ${e.target} in ${f.at(-1)??t}'s extends ${p.reason}; it is skipped`);return}s.add(e.target);let m=p.steps??[];if(e.extends){let t=new Set(e.extends.map(({target:e})=>e));for(let{target:n}of m)t.has(n)||a.replaced.push({target:n,step:e.target})}for(let t of c(e.extends??m,`plugin ${e.target}`,e.target))d(t,!1,[...f,e.target]);s.delete(e.target);let h=e.merge??p.merge??`patch`,g=e.merge?`step`:p.merge?`contribution`:`default`;a.entries.push({target:e.target,contribution:p,operation:h,from:g}),o.add(e.target)};for(let e of l)d(e,!0,[]);return a.allMissing=l.length>0&&l.every(({target:e})=>!o.has(e))&&l.some(({target:e})=>e!=="default"),a}const Ho=()=>{};function Uo(e,t,n,r,i,a){let o;for(let n of t){if(!n.steps)continue;if(e.plugin!==void 0){n.entry.extendsOutcome=`not used (qualified name)`;continue}if(o){Vo(n.steps,n.label,`written`,r,Ho).entries.map(({target:e})=>e).join(` `)!==o.targets&&(n.entry.extendsOutcome=`not used (${o.builder.label}'s extends builds the stack)`,a(`extends-not-used`,`${n.label} builds a different stack from ${o.builder.label}, whose extends is used`));continue}let t=Vo(n.steps,n.label,`written`,r,a);if(t.ambiguous)return{status:`ambiguous`,...t.ambiguous};if(t.allMissing){n.entry.extendsOutcome=`not used (every step is missing)`,a(`extends-all-missing`,`every step in ${n.label}'s extends is missing; it is read as not written`);continue}o={entries:t.entries,builtBy:n.label,replaced:t.replaced,replacedBy:n.label,builder:n,targets:t.entries.map(({target:e})=>e).join(` `)}}if(o)return o;if(e.plugin!==void 0){let t=r(e.plugin);if(`reason`in t)return{status:`missing`,message:`the plugin ${e.plugin} ${t.reason}`};let n=Vo([{target:e.plugin}],`plugin ${e.plugin}`,`plugins`,r,a);return n.ambiguous?{status:`ambiguous`,...n.ambiguous}:{entries:n.entries,builtBy:`qualified name`,replaced:[],replacedBy:``}}return Ko(n,r,i,e.name,a)}function Wo(e,t,n,r,i,a,o){let s=(e,t)=>({target:e,contribution:t,operation:`replace`,from:`default`}),c=a?[s(`default`,a)]:[];if(e.plugin!==void 0){let t=i(e.plugin);return`reason`in t?{status:`missing`,message:`the plugin ${e.plugin} ${t.reason}`}:{entries:[s(e.plugin,t)],builtBy:`qualified name`,replaced:[],replacedBy:``}}if(n.some(({hasBody:e})=>e))return{entries:c,builtBy:`none`,replaced:[],replacedBy:``};let l=Go(t,e.name,o);if(l!==void 0){if(l==="default"&&a)return{entries:c,builtBy:`selection`,replaced:[],replacedBy:``};let t=r.get(l);if(t)return{entries:[...c,s(l,t)],builtBy:`selection`,replaced:[],replacedBy:``};o(`selection-invalid`,`the selection of "${e.name}" names ${l}, which holds no such asset; it is ignored`)}let u=[...r.entries()];if(u.length>1){let t=u.map(([e])=>e);return{status:`ambiguous`,cause:`unordered`,message:`the plugins ${t.join(`, `)} hold it; run "asset select ${e.name} <option>" (options: ${t.join(`, `)}${a?`, default`:``}), ask for ${t[0]}/${e.name}, or put the file in a project or user assets folder`}}let[d]=u;return{entries:[...c,...d?[s(d[0],d[1])]:[]],builtBy:`none`,replaced:[],replacedBy:``}}function Go(e,t,n){for(let r of e){if(r.skipped||![`managed`,`project`,`user`].includes(r.tier))continue;let e=Fo(g(r.dir,`${t}.select`));if(e===void 0)continue;let i=e.trim();if(!Mo.test(i)){n(`selection-invalid`,`${r.tier} ${t}.select holds "${i}", which is not a plugin name or default; it is ignored`);continue}return i}}function Ko(e,t,n,r,i){let a=()=>n?[{target:`default`,contribution:n,operation:n.merge??`patch`,from:n.merge?`contribution`:`default`}]:[],o=[...e.keys()];if(!o.length)return{entries:a(),builtBy:`none`,replaced:[],replacedBy:``};let s=/* @__PURE__ */ new Map;for(let e of o){let n=Vo([{target:e}],`plugin ${e}`,`plugins`,t,Ho);if(n.ambiguous)return{status:`ambiguous`,...n.ambiguous};s.set(e,new Set(n.entries.map(({target:e})=>e).filter(t=>t!==e)))}let c=o.filter(e=>!o.some(t=>t!==e&&s.get(t)?.has(e))),l=()=>({status:`ambiguous`,cause:`unordered`,message:`the plugins ${o.join(`, `)} hold it, and no extends orders them`});if(c.length!==1)return l();let u=c[0],d=Vo([{target:u}],`plugin ${u}`,`plugins`,t,i);if(d.ambiguous)return{status:`ambiguous`,...d.ambiguous};let f=new Set(d.entries.map(({target:e})=>e));if(o.some(e=>!f.has(e)))return l();let p=d.entries;if(n&&!f.has(`default`)){p.unshift(...a());let e=o.join(`, `);i(`default-not-selected`,`${o.length>1?`the plugins`:`the plugin`} ${e} ${o.length>1?`answer`:`answers`} over the default of ${n.layer.skill}, and no extends names either; run "reference select ${r} <option>..." to choose (options: ${[...o,`default`].join(`, `)})`)}return{entries:p,builtBy:u&&(e.get(u)?.steps?.length??0)>0?`plugin ${u}'s extends`:`none`,replaced:[],replacedBy:``}}function qo(e){return(e??[]).some(e=>e.target==="default"||qo(e.extends))}function Jo(e){return{stack:[],builtBy:`none`,contributions:[],sections:[],layers:[],harnesses:[...e]}}function Yo(e){return e.endsWith(`
|
|
182
|
-
`)?e:`${e}\n`}function Xo(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``)}function K(e,t,{display:n=e=>e,without:r,below:i}={}){let a=typeof e==`string`?G(e):e,{layers:o,harnesses:s}=Po(t),c=Jo(s),l=[],u={name:a.raw,status:`missing`,warnings:l,trace:c};if(a.invalid)return{...u,status:`invalid`,code:`reference-invalid`,message:a.invalid};let d=/* @__PURE__ */ new Set,f=e=>(t,n)=>{let r=e?`${e}: ${n}`:n;d.has(`${t} ${r}`)||(d.add(`${t} ${r}`),l.push({code:t,message:r}))},p=f(``),m=i===void 0?-1:o.findIndex(e=>e.dir===i),h=m===-1?o:o.slice(m+1),g=[];for(let e of h){e.warning&&p(e.warning.code,e.warning.message);let t={tier:e.tier,path:e.dir,outcome:`missing`};if(e.plugin!==void 0&&(t.plugin=e.plugin),e.skill!==void 0&&(t.skill=e.skill),c.layers.push(t),e.skipped){t.outcome=`not read (${e.skipped})`;continue}let i=Qo(e,a.name,t,{display:n,without:r,warnAt:f});i?g.push(i):e.tier==="default"&&(t.outcome=`not read (no default)`)}let _=/* @__PURE__ */ new Map;for(let e of g.filter(({layer:e})=>e.tier===`plugin`)){let t=e.layer.plugin,r=_.get(t);r?e.entry.outcome=`not read (plugin ${t} answers from ${n(r.path)})`:_.set(t,e)}let v=g.find(({layer:e})=>e.tier==="default"),y=g.filter(({layer:e})=>e.tier!==`plugin`&&e.tier!=="default"),b=new Set(h.flatMap(({plugin:e,skipped:t})=>e&&!t?[e]:[])),x=e=>e==="default"?v??{reason:`has no default`}:_.get(e)??{reason:b.has(e)?`holds no ${a.name}`:`is not installed`},S=()=>[...[..._.keys()].map(e=>`${e}/${a.name}`),...v?[`default`]:[]];if(Co(a.name)!==void 0)return $o(a,g,_,v,u,p,S);let C=h.some(({whole:e})=>e)?Wo(a,h,y,_,x,v,p):Uo(a,y,_,x,v,p);if(`status`in C){if(C.status===`ambiguous`){for(let{entry:e}of g)e.outcome===``&&(e.outcome=`ambiguous`);return{...u,status:`ambiguous`,code:`reference-ambiguous`,message:C.message,cause:C.cause,options:S()}}for(let{entry:e}of g)e.outcome===``&&(e.outcome=`not used (qualified name)`);return{...u,status:`missing`,code:`reference-missing`,message:C.message}}!h.some(({tier:e})=>e==="default")&&g.some(({steps:e})=>qo(e))&&c.layers.push({tier:`default`,path:`(no skill folder given)`,outcome:`not read (no default)`}),c.stack=C.entries.map(({target:e})=>e),c.builtBy=C.builtBy;let w=new Set(c.stack);for(let[e,t]of[..._.entries(),...v?[[`default`,v]]:[]]){if(w.has(e))continue;let n=C.replaced.find(t=>t.target===e);t.entry.outcome=a.plugin===void 0?n?`not used (${n.step}'s extends replaced by ${C.replacedBy})`:`not used (not in extends)`:`not used (qualified name)`}let T=[...C.entries,...[...y].reverse().map(e=>({contribution:e,operation:e.merge??`patch`,from:e.merge?`contribution`:`default`}))],E=co(),D=[],O,ee=[],k;for(let{contribution:e,operation:t,from:n}of T){let{entry:r}=e;if(e.whole&&e.hasBody){r.operation=`replace`,r.operationFrom=`default`;for(let t of D)t.entry.outcome=`shadowed by ${e.label} (replace)`;D=[e],E={...co(),removed:E.removed},k=e,O=void 0,r.outcome=`used`,ee.push(e);continue}if(k&&t!==`remove`&&e.hasBody){r.operation=t,r.operationFrom=n,r.outcome=`not used (format differs from ${k.format})`,f(e.label)(`format-mismatch`,`it is ignored: ${k.label} is ${k.format}, which a Markdown contribution cannot compose with`);continue}t===`remove`&&(k=void 0),r.operation=t,r.operationFrom=n;let i=f(e.label);if(t===`remove`){e.hasBody&&i(`remove-body-ignored`,`a merge: remove contribution has a body; it is ignored`);for(let t of D)t.entry.outcome=`shadowed by ${e.label} (remove)`;for(let t of vo(E))t.path!==`(before the first heading)`&&E.removed.push({path:t.path,by:e.label});let t=E.removed;D=[],E={...co(),removed:t},O=e,r.outcome=`used`,ee.push(e);continue}if(!e.hasBody){r.outcome=r.extendsOutcome??`used`,r.extendsOutcome||ee.push(e);continue}if(t===`replace`){for(let t of D)t.entry.outcome=`shadowed by ${e.label} (replace)`;D=[]}E=go(E,e.body,t,e.label,i),D.push(e),O=void 0,r.outcome=`used`,ee.push(e)}if(c.sections=E.removed.map(({path:e,by:t})=>({path:e,contributions:[],removedBy:t})),!D.length){if(O)return{...u,status:`missing`,code:`reference-missing`,message:`"${a.name}" is turned off by ${O.label} (remove)`,removedBy:O.label};let e=a.plugin===void 0?`no tier holds a document for "${a.name}"`:`the plugin ${a.plugin} holds no document for "${a.name}"`;return{...u,status:`missing`,code:`reference-missing`,message:e}}let te=ee.filter(({entry:e})=>e.outcome===`used`);if(c.contributions=D.map(({layer:e,entry:t})=>{let n={tier:e.tier,path:t.path,operation:t.operation};return t.plugin!==void 0&&(n.plugin=t.plugin),t.skill!==void 0&&(n.skill=t.skill),n}),c.sections=[...vo(E).map(({path:e,sources:t})=>({path:e,contributions:t})),...c.sections],k)return{...u,status:`found`,content:k.body,format:k.format,metadata:{}};let A=D.length===1&&!E.removed.length?D[0].body:void 0,ne=A!==void 0&&ro(A)===A?Yo(Xo(A)):_o(E);return{...u,status:`found`,content:ne,format:`markdown`,metadata:Zo(te)}}function Zo(e){let t=Object.assign({},...e.map(({metadata:e})=>e));return delete t.merge,delete t.extends,t}function Qo(e,t,n,{display:r,without:i,warnAt:a}){if(e.tier!=="default"){let n=g(e.dir,`${t}${No}.md`);n!==i&&Fo(n)!==void 0&&a(r(n))(`default-in-tier`,`it is ignored: a default goes in a skill's references/ folder`)}let[o,...s]=Io(e,t).flatMap(t=>{let n=g(e.dir,t),r=n===i?void 0:Fo(n);return r===void 0?[]:[{file:t,path:n,raw:r}]});if(!o)return;for(let e of s)a(r(e.path))(`file-ignored`,`it is ignored: ${o.file} answers first in that folder`);let c=Lo(e,o.path,r),l=a(c),u=bo(o.file);if(u!==`markdown`||e.whole){Object.assign(n,{path:o.path,file:o.file,outcome:``});let t=o.raw.trim().length>0;return t||(n.empty=!0),{layer:e,entry:n,label:c,path:o.path,metadata:{},body:o.raw,hasBody:t,whole:!0,format:u,merge:`replace`,steps:void 0}}let{metadata:d,body:f}=Xa(o.raw,l),p=Za(d,l),m=Ro(d.extends,l);Object.assign(n,{path:o.path,file:o.file,frontmatter:d,outcome:``}),typeof d.description==`string`&&(n.description=d.description);let h=Qa(f);return h||(n.empty=!0),m&&!h&&p!==`remove`&&(n.selection=!0),{layer:e,entry:n,label:c,path:o.path,metadata:d,body:f,hasBody:h,format:u,whole:!1,merge:p,steps:m}}function $o(e,t,n,r,i,a,o){for(let e of t)(e.merge!==void 0||e.steps!==void 0)&&a(`interface-not-composed`,`${e.label}: merge and extends on an interface document are ignored; an interface is never composed`);if(e.plugin===void 0&&n.size>1){for(let{entry:e}of t)e.outcome===``&&(e.outcome=`ambiguous`);return{...i,status:`ambiguous`,code:`reference-ambiguous`,message:`the plugins ${[...n.keys()].join(`, `)} each hold the interface document`,cause:`unordered`,options:o()}}let s=e.plugin===void 0?[...n.values()]:n.has(e.plugin)?[n.get(e.plugin)]:[];if(e.plugin!==void 0){for(let[t,r]of n)t!==e.plugin&&(r.entry.outcome=`not used (qualified name)`);if(!s.length)return{...i,status:`missing`,code:`reference-missing`,message:`the plugin ${e.plugin} holds no "${e.name}"`}}let c=t.filter(({layer:e})=>e.tier!==`plugin`&&e.tier!=="default"),[l,...u]=[...e.plugin===void 0&&r?[r]:[],...s,...[...c].reverse()];if(!l)return{...i,status:`missing`,code:`reference-missing`,message:`no tier holds a document for "${e.name}"`};for(let e of u)e.entry.outcome=`not used (an interface document is never composed)`,a(`interface-not-composed`,`${e.label} is ignored: an interface document is never composed; define a new interface id instead`);r&&r!==l&&(r.entry.outcome=`not used (qualified name)`),l.entry.outcome=`used`,l.entry.operation=`replace`,l.entry.operationFrom=`default`;let{trace:d}=i;return l.layer.tier===`plugin`&&(d.stack=[l.layer.plugin]),l.layer.tier==="default"&&(d.stack=[`default`]),d.contributions=[{tier:l.layer.tier,...l.entry.plugin?{plugin:l.entry.plugin}:{},...l.entry.skill?{skill:l.entry.skill}:{},path:l.path,operation:`replace`}],{...i,status:`found`,content:Yo(Xo(ro(l.body))),metadata:Zo([l])}}function es(e){if(e.skipped)return[];let t;try{t=s(e.dir,{withFileTypes:!0})}catch{return[]}let n=/* @__PURE__ */ new Set,r=e.tier==="default"&&!e.whole;for(let i of t){let t;if(r){let e=[`${No}.md`,...W.map(e=>`${No}${e.extension}`)].find(e=>i.name.endsWith(e));e&&(t=i.name.slice(0,-e.length))}else!i.isDirectory()&&[`.md`,...W.map(e=>e.extension)].some(e=>i.name.endsWith(e))?t=i.name.slice(0,i.name.lastIndexOf(`.`)):!e.whole&&!i.isFile()&&Fo(g(e.dir,i.name,`README.md`))!==void 0&&(t=i.name);t===void 0||G(t).invalid||n.add(t)}return[...n]}function ts(e){return[...new Set(Po(e).layers.flatMap(es))].sort((e,t)=>e.localeCompare(t))}function ns(e){if(!e||typeof e!=`object`)return[];let t=e,n=/* @__PURE__ */ new Set;for(let e of[`dependencies`,`devDependencies`]){let r=t[e];if(r&&typeof r==`object`)for(let e of Object.keys(r))n.add(e)}return[...n].sort()}function rs(e,t){let n=t.split(`/`),r=[],i=e;for(;;){r.push(g(i,`node_modules`,...n));let e=m(i);if(e===i)break;i=e}return r}function is(t,n){try{let r=e(n);return m(r.resolve(`${t}/package.json`))}catch{}for(let e of rs(m(n),t))if(r(g(e,`package.json`)))return e}const as=[`plugin.json`,`.claude-plugin/plugin.json`,`.cursor-plugin/plugin.json`,`.codex-plugin/plugin.json`,`.github/plugin.json`,`.github/plugin/plugin.json`];function os(e){for(let t of as){let n;try{n=JSON.parse(o(g(e,t),`utf8`))}catch{continue}if(V(n)&&typeof n.name==`string`&&n.name)return n.name}}function ss(e){switch(e){case`claude-code`:return{project:[`.claude/skills`],user:[`.claude/skills`],research:[`E-CC-L1`]};case`cursor`:return{project:[`.cursor/skills`,`.claude/skills`,`.codex/skills`,`.grok/skills`,`.agents/skills`],user:[`.cursor/skills`,`.claude/skills`,`.codex/skills`,`.grok/skills`,`.agents/skills`],research:[`E-CUR-L1`,`E-SR-CUR-10`]};case`codex`:return{project:[`.agents/skills`],user:[`.agents/skills`],research:[`E-CODEX-L1`]};case`copilot-cli`:return{project:[`.github/skills`,`.agents/skills`,`.claude/skills`],user:[`.copilot/skills`,`.agents/skills`],research:[`E-COPILOT-S5`,`E-SR-COPILOT-9`],relocatedBy:{variable:`COPILOT_HOME`,skills:`skills`}};case`vscode-copilot`:return{project:[`.github/skills`,`.claude/skills`,`.agents/skills`],user:[`.copilot/skills`,`.claude/skills`,`.agents/skills`],research:[`E-VSC-P1`]};case`opencode`:return{project:[`.opencode/skills`,`.claude/skills`,`.agents/skills`],user:[`.config/opencode/skills`,`.claude/skills`,`.agents/skills`],research:[`E-OC-S1`]};case`gemini-cli`:return{project:[`.agents/skills`,`.gemini/skills`],user:[`.agents/skills`,`.gemini/skills`],research:[`E-GEM-L1`]};case`cline`:return{project:[`.cline/skills`,`.clinerules/skills`,`.claude/skills`,`.agents/skills`],user:[`.cline/skills`,`.agents/skills`],research:[`E-CLINE-S1`,`E-CLINE-S3`]};case`augment`:return{project:[`.augment/skills`,`.claude/skills`,`.agents/skills`],user:[`.augment/skills`,`.claude/skills`,`.agents/skills`],research:[`E-AUG-S4`]};case`kilo`:return{project:[`.kilo/skills`,`.agents/skills`,`.claude/skills`],user:[`.kilo/skills`,`.agents/skills`,`.claude/skills`],research:[`E-KILO-L2`]};case`qwen-code`:case`crush`:case`openhands`:return}}const cs=[`claude-code`,`cursor`,`codex`,`copilot-cli`,`opencode`,`gemini-cli`];function ls(e,t,n={}){let r=n.ProgramData||`C:\\ProgramData`;switch(e){case`claude-code`:return t===`darwin`?[`/Library/Application Support/ClaudeCode/.claude/skills`]:t===`win32`?[x.join(`C:\\Program Files\\ClaudeCode`,`.claude`,`skills`)]:[`/etc/claude-code/.claude/skills`];case`codex`:return t===`win32`?[]:[`/etc/codex/skills`];case`opencode`:{let e=t===`darwin`?`/Library/Application Support/opencode`:t===`win32`?x.join(r,`opencode`):`/etc/opencode`,n=t===`win32`?x:{join:g};return[n.join(e,`skill`),n.join(e,`skills`)]}default:return[]}}function us(e,{chain:t,home:n,platform:r,env:i={}}){if(!cs.includes(e))return;let a=ss(e);if(!a)return;let o=t.flatMap(e=>a.project.map(t=>g(e,t))),s=a.relocatedBy&&i[a.relocatedBy.variable],c=s&&y(s)!==g(n,`.copilot`)?[g(s,a.relocatedBy.skills)]:a.user.map(e=>g(n,e));return[...o,...c,...ls(e,r,i)]}function ds(e){for(let t of as){let n;try{n=JSON.parse(o(g(e,t),`utf8`))}catch{continue}if(!V(n))return;let r=n.skills;return typeof r==`string`?[r]:Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}function fs(e,t){if(e===`opencode`)return[];let n=e===`gemini-cli`?void 0:ds(t),r=g(t,`skills`);if(!n)return[r];let i=n.map(e=>g(t,e));return e===`claude-code`?[r,...i]:i}const ps=/^---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;function ms(e){let t;try{t=o(g(e,`SKILL.md`),`utf8`)}catch{return}let n=ps.exec(t);if(n)try{let e=(0,Ka.parse)(n[1]);if(V(e)&&typeof e.name==`string`&&e.name.trim())return e.name.trim()}catch{}return p(e)}function hs(e){try{return d(e).isDirectory()}catch{return!1}}function gs(e){let t=[],n=/* @__PURE__ */ new Set,r=(e,r)=>{let i=e;try{i=c(e)}catch{}n.has(i)||(n.add(i),t.push({name:r,folder:i}))};for(let t of e){let e=ms(t);if(e!==void 0){r(t,e);continue}let n;try{n=s(t)}catch{continue}for(let e of n.sort()){let n=g(t,e);if(!hs(n))continue;let i=ms(n);i!==void 0&&r(n,i)}}return t}const q=e=>e===`1`,J=e=>e!==``,_s={name:`CLAUDECODE`,matches:q,description:`Claude Code sets CLAUDECODE=1 in subprocesses it spawns; IDE extensions also set it in integrated terminals`,research:`E-CC-D1`},vs=[{harness:`claude-code`,all:[_s,{name:`CLAUDE_CODE_CHILD_SESSION`,matches:q,description:`Claude Code sets CLAUDE_CODE_CHILD_SESSION=1 for tool, hook, and status line subprocesses`,research:`E-CC-D3`}]},{harness:`claude-code`,all:[_s,{name:`CLAUDE_CODE_SESSION_ID`,matches:J,description:`Claude Code sets CLAUDE_CODE_SESSION_ID in tool, hook, and stdio MCP server subprocesses`,research:`E-CC-D6`}]},{harness:`cursor`,all:[{name:`CURSOR_AGENT`,matches:q,description:`Cursor sets CURSOR_AGENT=1 on terminal commands its agent runs`,research:`E-CUR-D1`}]},{harness:`cursor`,all:[{name:`CURSOR_VERSION`,matches:J,description:`Cursor sets CURSOR_VERSION for hook commands`,research:`E-CUR-D10`},{name:`CURSOR_PROJECT_DIR`,matches:J,description:`Cursor sets CURSOR_PROJECT_DIR for hook commands`,research:`E-CUR-D10`}]},{harness:`codex`,all:[{name:`CODEX_THREAD_ID`,matches:J,description:`Codex injects CODEX_THREAD_ID into shell tool commands, even under a restrictive shell env policy`,research:`E-CODEX-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_CLI`,matches:q,description:`Copilot CLI sets COPILOT_CLI=1 in its subprocesses`,research:`E-COPILOT-D1`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_AGENT_SESSION_ID`,matches:J,description:`Copilot CLI passes COPILOT_AGENT_SESSION_ID to shell commands and MCP servers`,research:`E-COPILOT-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_PLUGIN_ROOT`,matches:J,description:`Copilot CLI passes COPILOT_PLUGIN_ROOT to plugin hooks`,research:`E-COPILOT-D6`}]},{harness:`opencode`,all:[{name:`OPENCODE`,matches:q,description:`OpenCode sets OPENCODE=1 for shell tool commands and MCP servers; Kilo Code, its fork, sets it too`,research:`E-OC-D1`},{name:`OPENCODE_PID`,matches:J,description:`OpenCode sets OPENCODE_PID for shell tool commands and MCP servers; Kilo Code sets KILO_PID instead`,research:`E-OC-D2`}]},{harness:`kilo`,all:[{name:`KILO`,matches:q,description:`Kilo Code sets KILO=1 for shell tool commands and MCP servers`,research:`E-KILO-D2`},{name:`KILO_PID`,matches:J,description:`Kilo Code sets KILO_PID for shell tool commands and MCP servers`,research:`E-KILO-D1`}]},{harness:`gemini-cli`,all:[{name:`GEMINI_CLI`,matches:q,description:`Gemini CLI sets GEMINI_CLI=1 for shell tool commands and MCP stdio servers`,research:`E-GEM-D1`}]},{harness:`qwen-code`,all:[{name:`QWEN_CODE`,matches:q,description:`Qwen Code sets QWEN_CODE=1 for shell tool commands, not for MCP servers or hooks`,research:`E-QWEN-D1`}]},{harness:`vscode-copilot`,all:[{name:`COPILOT_AGENT`,matches:q,description:`VS Code 1.121+ sets COPILOT_AGENT=1 on terminals its Copilot agent runs commands in`,research:`E-VSC-D1`}]},{harness:`cline`,all:[{name:`CLINE_ACTIVE`,matches:e=>e===`true`,description:`Cline's VS Code extension sets CLINE_ACTIVE=true on the terminals it creates; the Cline CLI does not`,research:`E-CLINE-D1`}]},{harness:`crush`,all:[{name:`CRUSH`,matches:q,description:`Crush sets CRUSH=1 for bash tool and hook commands, not for MCP servers`,research:`E-CRUSH-D1`}]},{harness:`openhands`,all:[{name:`AI_AGENT`,matches:e=>e===`openhands`,description:`OpenHands (SDK 1.40.1 and later) sets AI_AGENT=openhands for terminal tool and hook commands when AI_AGENT is unset; other vendors use the name with other values`,research:`E-OH-D1`}]},{harness:`openhands`,all:[{name:`OPENHANDS_EVENT_TYPE`,matches:J,description:`OpenHands sets OPENHANDS_EVENT_TYPE for hook commands`,research:`E-OH-D4`},{name:`OPENHANDS_PROJECT_DIR`,matches:J,description:`OpenHands sets OPENHANDS_PROJECT_DIR for hook commands`,research:`E-OH-D4`}]},{harness:`augment`,all:[{name:`AUGMENT_HOOK_EVENT`,matches:J,description:`The Auggie CLI sets AUGMENT_HOOK_EVENT for hook commands; its shell commands carry no marker`,research:`E-AUG-D3`},{name:`AUGMENT_PROJECT_DIR`,matches:J,description:`The Auggie CLI sets AUGMENT_PROJECT_DIR for hook commands`,research:`E-AUG-D3`}]}];function ys(e={}){let t=e.env??process.env,n=[],r=[];for(let e of vs){let i=e.all.filter(e=>{let n=t[e.name];return n!==void 0&&e.matches(n)});for(let t of i)n.some(n=>n.harness===e.harness&&n.signal===t.name)||n.push({harness:e.harness,signal:t.name,description:t.description,research:t.research});i.length===e.all.length&&!r.includes(e.harness)&&r.push(e.harness)}return{harness:r.length===1?r[0]:`unknown`,evidence:n,candidates:r}}function bs(e,t={}){let n=t.platform??process.platform,r=t.env??process.env;return Ts[e](n,r)}const xs=e=>e===`win32`?x.join:_.join,Ss=e=>e===`win32`?x.dirname:_.dirname;function Cs(e,t,n,r){let i={darwin:`/Library/Application Support/${n}`,linux:`/etc/${n}`,win32:x.join(t.ProgramData??`C:\\ProgramData`,n)}[e];return[...Y(e===`darwin`,{kind:`macos-managed-preferences`,location:`ai.opencode.managed`,description:`MDM configuration profile; outranks the managed config folder`,research:r.preferences}),...Y(i!==void 0,{kind:`directory`,location:i??``,description:`Managed config files; outrank user and project config`,research:r.directory})]}function ws(e,t,n){let r=e===`darwin`||e===`win32`?n.dirs[e]:n.dirs.linux,i=t[n.settingsVariable]||xs(e)(r,`settings.json`),a=t[n.defaultsVariable]||xs(e)(Ss(e)(i),`system-defaults.json`);return[{kind:`file`,location:i,description:`System settings; outrank user and workspace settings. ${n.settingsVariable} overrides the path`,research:n.research},{kind:`file`,location:a,description:`System defaults; user and workspace settings override them. ${n.defaultsVariable} overrides the path`,research:n.research}]}const Y=(e,...t)=>e?t:[],Ts={"claude-code":e=>{let t={darwin:`/Library/Application Support/ClaudeCode`,linux:`/etc/claude-code`,win32:`C:\\Program Files\\ClaudeCode`}[e],n=xs(e);return[{kind:`server`,location:`claude.ai admin console or a self-hosted Claude apps gateway`,description:`Server-managed settings; the highest-ranked managed source`,research:`E-CC-M6`},...Y(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.anthropic.claudecode`,description:`MDM configuration profile with the same top-level keys as managed-settings.json`,research:`E-CC-M6`}),...Y(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\ClaudeCode`,description:`MDM or Group Policy; the Settings value holds managed-settings JSON`,research:`E-CC-M6`}),...Y(t!==void 0,{kind:`file`,location:n(t??``,`managed-settings.json`),description:`Managed settings, same shape as settings.json`,research:`E-CC-M1`},{kind:`directory`,location:n(t??``,`managed-settings.d`),description:`Drop-in managed settings files, merged with managed-settings.json`,research:`E-CC-M1`},{kind:`file`,location:n(t??``,`managed-mcp.json`),description:`Managed MCP servers`,research:`E-CC-M1`}),...Y(e===`win32`,{kind:`windows-registry`,location:`HKCU\\SOFTWARE\\Policies\\ClaudeCode`,description:`User-writable; used only when no other managed source delivers a policy key`,research:`E-CC-M6`})]},cursor:e=>{let t={darwin:`/Library/Application Support/Cursor/hooks.json`,linux:`/etc/cursor/hooks.json`,win32:`C:\\ProgramData\\Cursor\\hooks.json`}[e];return[...Y(t!==void 0,{kind:`file`,location:t??``,description:`Enterprise hooks deployed by MDM; hooks only, not other enterprise settings`,research:`E-CUR-M1`}),{kind:`server`,location:`Cursor dashboard`,description:`Team hooks and other enterprise settings, synced from the dashboard`,research:`E-CUR-M1`}]},codex:(e,t)=>{let n={kind:`server`,location:`ChatGPT workspace admin settings`,description:`Cloud-managed requirements; outrank every local source`,research:`E-CODEX-M8`};return e===`win32`?[n,{kind:`file`,location:x.join(t.ProgramData??`C:\\ProgramData`,`OpenAI`,`Codex`,`requirements.toml`),description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M4`}]:[n,...Y(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.openai.codex`,description:`MDM keys requirements_toml_base64 (enforced) and config_toml_base64 (managed defaults)`,research:`E-CODEX-M6`}),{kind:`file`,location:`/etc/codex/requirements.toml`,description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M3`},{kind:`file`,location:`/etc/codex/managed_config.toml`,description:`Managed defaults; a user can override them within a session`,research:`E-CODEX-M2`},{kind:`file`,location:`/etc/codex/config.toml`,description:`System-wide config`,research:`E-CODEX-M1`}]},"copilot-cli":(e,t)=>{let n={darwin:`/Library/Application Support/GitHubCopilot/managed-settings.json`,linux:`/etc/github-copilot/managed-settings.json`,win32:x.join(t.ProgramFiles??`C:\\Program Files`,`GitHubCopilot`,`managed-settings.json`)}[e];return[...Y(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.github.copilot`,description:`MDM-managed settings; the highest-ranked source`,research:`E-COPILOT-M2`}),...Y(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\GitHubCopilot`,description:`MDM-managed settings as REG_SZ values; the highest-ranked source`,research:`E-COPILOT-M2`}),{kind:`server`,location:`copilot/managed-settings.json in the enterprise's .github-private repository`,description:`Server-managed settings, fetched for the signed-in account`,research:`E-COPILOT-M3`},...Y(n!==void 0,{kind:`file`,location:n??``,description:`File-based managed settings; on macOS and Linux it must be a root-owned regular file`,research:`E-COPILOT-M1`})]},opencode:(e,t)=>[...Cs(e,t,`opencode`,{directory:`E-OC-M1`,preferences:`E-OC-M1`}),{kind:`server`,location:`Remote config at the organization domain /.well-known/opencode`,description:`Organization defaults; the lowest-ranked config source, so user config overrides them`,research:`E-OC-M2`}],kilo:(e,t)=>Cs(e,t,`kilo`,{directory:`E-KILO-M1`,preferences:`E-KILO-M2`}),"gemini-cli":(e,t)=>ws(e,t,{settingsVariable:`GEMINI_CLI_SYSTEM_SETTINGS_PATH`,defaultsVariable:`GEMINI_CLI_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/GeminiCli`,linux:`/etc/gemini-cli`,win32:`C:\\ProgramData\\gemini-cli`},research:`E-GEM-M1`}),"qwen-code":(e,t)=>ws(e,t,{settingsVariable:`QWEN_CODE_SYSTEM_SETTINGS_PATH`,defaultsVariable:`QWEN_CODE_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/QwenCode`,linux:`/etc/qwen-code`,win32:`C:\\ProgramData\\qwen-code`},research:`E-QWEN-M1`}),"vscode-copilot":e=>[...Y(e===`win32`,{kind:`windows-registry`,location:`Software\\Policies\\Microsoft\\VSCode`,description:`VS Code policies set by Group Policy (ADMX templates ship with VS Code)`,research:`E-VSC-M1`}),...Y(e===`linux`,{kind:`file`,location:`/etc/vscode/policy.json`,description:`VS Code policies as JSON, read by VS Code 1.106 and later`,research:`E-VSC-M3`})],cline:()=>[{kind:`server`,location:`Cline Enterprise admin console`,description:`Provider, model, and tool policy pushed to clients; no local policy file is documented`,research:`E-CLINE-M1`}],crush:e=>Y(e!==`win32`,{kind:`file`,location:`/etc/crush/crush.json`,description:`System config; the lowest-ranked source, so user and project config override it`,research:`E-CRUSH-M1`}),openhands:()=>[{kind:`server`,location:`OpenHands Cloud or Enterprise deployment`,description:`Organization controls held server-side; no local policy file is known`,research:`E-OH-D8`}],augment:(e,t)=>[{kind:`file`,location:e===`win32`?x.join(t.ProgramData||`C:\\ProgramData`,`augment`,`settings.json`):`/etc/augment/settings.json`,description:`System settings, read from the Auggie CLI bundle; its rank against user settings is not documented`,research:`E-AUG-M1`}]};function Es(e={}){return{env:e.env??process.env,homedir:e.homedir??w(),cwd:e.cwd??process.cwd(),platform:e.platform??process.platform}}function Ds(e,t={}){return As[e](Es(t))}const Os=({env:e,homedir:t})=>e.XDG_CONFIG_HOME||g(t,`.config`);function ks({env:e,homedir:t,platform:n}){if(n===`win32`){let n=x.join(e.APPDATA||x.join(t,`AppData`,`Roaming`),`Code`);return{configDir:n,path:x.join(n,`agentPlugins`)}}let r=n===`darwin`?g(t,`Library`,`Application Support`,`Code`):g(t,`.config`,`Code`);return{configDir:r,path:g(r,`agentPlugins`)}}const As={"claude-code":({env:e,homedir:t})=>{let n=e.CLAUDE_CONFIG_DIR||g(t,`.claude`),r=g(n,`plugins`);return{harness:`claude-code`,configDir:n,locations:[{kind:`plugin-cache`,path:g(r,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CC-P1`},{kind:`marketplaces`,path:g(r,`marketplaces`),description:`Marketplace checkouts`,research:`E-CC-P1`},{kind:`install-record`,path:g(r,`installed_plugins.json`),description:`Installs keyed by plugin@marketplace, each with scope, installPath, and version`,research:`E-CC-P2`},{kind:`enabled-record`,path:g(n,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-CC-P3`}]}},cursor:({homedir:e})=>{let t=g(e,`.cursor`);return{harness:`cursor`,configDir:t,locations:[{kind:`local-plugins`,path:g(t,`plugins`,`local`),description:`Plugins under development, one folder each`,research:`E-CUR-P2`},{kind:`marketplaces`,path:g(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-CUR-P3`}]}},codex:({env:e,homedir:t})=>{let n=e.CODEX_HOME||g(t,`.codex`);return{harness:`codex`,configDir:n,locations:[{kind:`plugin-cache`,path:g(n,`plugins`,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CODEX-P3`},{kind:`enabled-record`,path:g(n,`config.toml`),description:`User config; [plugins."<plugin>@<marketplace>"] tables carry enabled = <bool>`,research:`E-CODEX-P2`}]}},"copilot-cli":({env:e,homedir:t})=>{let n=e.COPILOT_HOME||g(t,`.copilot`);return{harness:`copilot-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:g(n,`installed-plugins`),description:`Installed plugins as <marketplace>/<plugin>/, or _direct/<source-id>/ for direct installs`,research:`E-COPILOT-P9`},{kind:`install-record`,path:g(n,`config.json`),description:`Application state, including installedPlugins`,research:`E-COPILOT-P9`},{kind:`enabled-record`,path:g(n,`settings.json`),description:`User settings (JSON with comments); enabledPlugins maps plugin specs to a boolean`,research:`E-COPILOT-P4`}]}},opencode:e=>{let t=g(Os(e),`opencode`);return{harness:`opencode`,configDir:t,locations:[{kind:`local-plugins`,path:g(t,`plugins`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-OC-P2`}]}},kilo:e=>{let t=g(Os(e),`kilo`);return{harness:`kilo`,configDir:t,locations:[{kind:`local-plugins`,path:g(t,`plugin`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-KILO-P2`}]}},"gemini-cli":({env:e,homedir:t})=>{let n=g(e.GEMINI_CLI_HOME||t,`.gemini`),r=g(n,`extensions`);return{harness:`gemini-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a gemini-extension.json manifest`,research:`E-GEM-P1`},{kind:`enabled-record`,path:g(r,`extension-enablement.json`),description:`Per-extension path-glob overrides that enable or disable it by folder, not a boolean`,research:`E-GEM-P3`}]}},"qwen-code":({env:e,homedir:t})=>{let n=e.QWEN_HOME||g(t,`.qwen`),r=g(n,`extensions`);return{harness:`qwen-code`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a qwen-extension.json manifest`,research:`E-QWEN-P1`},{kind:`enabled-record`,path:g(r,`extension-enablement.json`),description:`Extension enable/disable state, inherited from Gemini CLI's format`,research:`E-QWEN-P2`}]}},"vscode-copilot":e=>{let{configDir:t,path:n}=ks(e);return{harness:`vscode-copilot`,configDir:t,locations:[{kind:`installed-plugins`,path:n,description:`Installed agent plugins as <host>/<org>/<repo>/`,research:`E-VSC-P3`}]}},cline:({homedir:e})=>{let t=g(e,`.cline`);return{harness:`cline`,configDir:t,locations:[{kind:`installed-plugins`,path:g(t,`plugins`,`_installed`),description:`Installed plugins, grouped by source: npm, git, remote, or local`,research:`E-CLINE-P3`}]}},crush:({env:e,homedir:t})=>({harness:`crush`,configDir:e.CRUSH_GLOBAL_CONFIG||g(e.XDG_CONFIG_HOME||g(t,`.config`),`crush`),locations:[]}),openhands:({env:e,homedir:t})=>{let n=e.OH_PERSISTENCE_DIR||e.OPENHANDS_PERSISTENCE_DIR||g(t,`.openhands`),r=g(n,`plugins`,`installed`);return{harness:`openhands`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed plugins, one folder each`,research:`E-OH-P3`},{kind:`enabled-record`,path:g(r,`.installed.json`),description:`Install metadata keyed by plugin name, each with enabled: <bool>`,research:`E-OH-P4`}]}},augment:({homedir:e})=>{let t=g(e,`.augment`);return{harness:`augment`,configDir:t,locations:[{kind:`marketplaces`,path:g(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-AUG-P2`},{kind:`enabled-record`,path:g(t,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-AUG-P4`}]}}};async function js(e,t={}){let n=Bs[e](Es(t),t.managedSettingsPath),r=/* @__PURE__ */ new Map,i=[];for(let e of n.sources){let t;try{let n=await ki(e.path);if(n===void 0){i.push({scope:e.scope,path:e.path,found:!1});continue}t=e.parse(n)}catch(t){i.push({scope:e.scope,path:e.path,found:!0,error:String(t)});continue}i.push({scope:e.scope,path:e.path,found:!0});for(let[n,i]of Object.entries(t))r.has(n)||r.set(n,{id:n,enabled:i,scope:e.scope,source:e.path})}return{harness:e,supported:n.supported,plugins:[...r.values()],sources:i,unread:n.unread,research:n.research}}function Ms(e){let t=JSON.parse(e),n=V(t)?t.enabledPlugins:void 0;return V(n)?Object.fromEntries(Object.entries(n).filter(e=>typeof e[1]==`boolean`)):{}}const Ns=/^\[\s*plugins\s*\.\s*(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_-]+))\s*\]\s*(?:#.*)?$/,Ps=/^enabled\s*=\s*(true|false)\s*(?:#.*)?$/;function Fs(e){let t={},n;for(let r of e.split(/\r?\n/)){let e=r.trim();if(e.startsWith(`[`)){let t=Ns.exec(e);n=t?t[1]??t[2]??t[3]:void 0;continue}let i=n===void 0?null:Ps.exec(e);n!==void 0&&i&&(t[n]=i[1]===`true`)}return t}const Is={server:`server-managed settings`,"macos-managed-preferences":`MDM managed preferences`,"windows-registry":`Windows registry policy`,directory:`drop-in managed settings`,file:`managed file`};function Ls(e,t,n=[]){return e.filter(e=>e.location!==t&&!n.some(t=>e.location.endsWith(t))).map(e=>`${Is[e.kind]} (${e.location})`)}function Rs(e,t){return e.find(e=>e.kind===`file`&&e.location.endsWith(t))?.location}function zs(e){return Ms(Ai(e))}const X=(...e)=>({supported:!1,sources:[],unread:[],research:e}),Bs={"claude-code":(e,t)=>{let{configDir:n}=Ds(`claude-code`,e),r=bs(`claude-code`,e),i=Rs(r,`managed-settings.json`),a=t??i,o=g(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:Ms}],{scope:`local`,path:g(o,`settings.local.json`),parse:Ms},{scope:`project`,path:g(o,`settings.json`),parse:Ms},{scope:`user`,path:g(n,`settings.json`),parse:Ms}],unread:Ls(r,i,[`managed-mcp.json`]),research:[`E-CC-P3`,`E-CC-P7`,`E-CC-M1`,`E-CC-M6`]}},cursor:()=>X(),opencode:()=>X(`E-OC-P3`),kilo:()=>X(`E-KILO-P3`),"gemini-cli":()=>X(`E-GEM-P3`),"qwen-code":()=>X(`E-QWEN-P2`),"vscode-copilot":()=>X(`E-VSC-P4`),cline:()=>X(`E-CLINE-P4`),crush:()=>X(`E-CRUSH-P2`),openhands:()=>X(`E-OH-P4`),augment:()=>X(`E-AUG-P4`),codex:e=>{let t=Ds(`codex`,e);return{supported:!0,sources:[{scope:`user`,path:g(t.configDir,`config.toml`),parse:Fs}],unread:Ls(bs(`codex`,e),void 0),research:[`E-CODEX-P2`,`E-CODEX-M7`]}},"copilot-cli":(e,t)=>{let n=Ds(`copilot-cli`,e),r=bs(`copilot-cli`,e),i=Rs(r,`managed-settings.json`),a=t??i,o=g(e.cwd,`.github`,`copilot`),s=g(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:zs}],{scope:`local`,path:g(o,`settings.local.json`),parse:zs},{scope:`project`,path:g(o,`settings.json`),parse:zs},{scope:`user`,path:g(n.configDir,`settings.json`),parse:zs}],unread:[...Ls(r,i),`Claude Code project settings (${g(s,`settings.json`)})`,`Claude Code local settings (${g(s,`settings.local.json`)})`],research:[`E-COPILOT-P4`,`E-COPILOT-M1`,`E-COPILOT-M2`,`E-COPILOT-M4`]}}};async function Vs(e,t={}){let n=sc[e](Es(t)),r={harness:e,supported:n.supported,unread:n.unread,research:n.research};if(n.source===void 0)return{...r,plugins:[],unresolved:[],sources:[]};let i=n.source;try{let e=await n.read(i);return e===void 0?{...r,plugins:[],unresolved:[],sources:[{path:i,found:!1}]}:{...r,plugins:e.plugins,unresolved:e.unresolved??[],sources:[{path:i,found:!0}]}}catch(e){return{...r,plugins:[],unresolved:[],sources:[{path:i,found:!0,error:String(e)}]}}}const Hs=[`managed`,`local`,`project`,`user`],Us=e=>typeof e==`string`&&e!==``?e:void 0;async function Ws(e){let t=await ki(e);if(t===void 0)return;let n=JSON.parse(t),r=V(n)?n.plugins:void 0;if(!V(r))return{plugins:[]};let i=[];for(let[e,t]of Object.entries(r))if(Array.isArray(t))for(let n of t){let t=V(n)?Us(n.installPath):void 0;if(!V(n)||t===void 0)continue;let r=Us(n.version),a=typeof n.scope==`string`&&Hs.includes(n.scope)?n.scope:void 0,o=Us(n.projectPath);i.push({id:e,path:t,...r===void 0?{}:{version:r},...a===void 0?{}:{scope:a},...o===void 0?{}:{projectPath:o},research:[`E-CC-P2`]})}return{plugins:i}}async function Gs(e){let t=await ki(e);if(t===void 0)return;let n=JSON.parse(Ai(t)),r=V(n)?n.installedPlugins:void 0;if(!Array.isArray(r))return{plugins:[]};let i=[];for(let e of r){if(!V(e))continue;let t=Us(e.name),n=Us(e.cache_path);if(t===void 0||n===void 0)continue;let r=Us(e.marketplace),a=Us(e.version);i.push({id:r===void 0?t:`${t}@${r}`,path:n,...a===void 0?{}:{version:a},research:r===void 0?[`E-COPILOT-P10`,`E-COPILOT-P11`]:[`E-COPILOT-P10`]})}return{plugins:i}}const Ks=`local`,qs=/^[A-Za-z0-9_-]+$/,Js=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/,Ys=/^[A-Za-z0-9._+-]+$/;async function Xs(e){let t=await Qs(e);if(t===void 0)return;let n=[],r=[];for(let i of t.filter(e=>qs.test(e)))for(let t of await Qs(g(e,i))??[]){if(!Js.test(t))continue;let a=`${t}@${i}`,o=(await Qs(g(e,i,t))??[]).filter(e=>Ys.test(e)&&e!==`.`&&e!==`..`);if(o.length===0)continue;let s=Zs(o);if(s===void 0){r.push(a);continue}n.push({id:a,path:g(e,i,t,s),version:s,research:[`E-CODEX-P3`,`E-CODEX-P8`]})}return{plugins:n,unresolved:r}}function Zs(e){if(e.includes(Ks))return Ks;let t=e.filter(e=>ec(e)!==void 0).length;if(!(e.length>2&&t!==0&&t!==e.length))return[...e].sort(tc).at(-1)}async function Qs(e){try{return(await E(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(e.code===`ENOENT`)return;throw e}}const $s=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;function ec(e){let t=$s.exec(e);if(t)return{core:[t[1],t[2],t[3]],pre:t[4]===void 0?[]:t[4].split(`.`),build:t[5]===void 0?[]:t[5].split(`.`)}}function tc(e,t){let n=ec(e),r=ec(t);if(n===void 0||r===void 0)return ac(e,t);for(let e=0;e<3;e++){let t=ic(n.core[e],r.core[e]);if(t!==0)return t}let i=n.pre.length===0||r.pre.length===0?r.pre.length-n.pre.length:rc(n.pre,r.pre);return i===0?rc(n.build,r.build):Math.sign(i)}const nc=/^\d+$/;function rc(e,t){for(let n=0;n<Math.min(e.length,t.length);n++){let r=e[n],i=t[n],a=nc.test(r),o=nc.test(i),s=a&&o?ic(r,i):a===o?ac(r,i):a?-1:1;if(s!==0)return s}return e.length-t.length}function ic(e,t){let n=e.replace(/^0+(?=\d)/,``),r=t.replace(/^0+(?=\d)/,``);return n.length-r.length||ac(n,r)||e.length-t.length}const ac=(e,t)=>e<t?-1:+(e>t),oc={supported:!1,read:async()=>void 0,unread:[],research:[]},sc={"claude-code":e=>({supported:!0,source:g(Ds(`claude-code`,e).configDir,`plugins`,`installed_plugins.json`),read:Ws,unread:[],research:[`E-CC-P2`]}),codex:e=>({supported:!0,source:g(Ds(`codex`,e).configDir,`plugins`,`cache`),read:Xs,unread:[],research:[`E-CODEX-P3`,`E-CODEX-P8`]}),"copilot-cli":e=>{let{configDir:t}=Ds(`copilot-cli`,e);return{supported:!0,source:g(t,`config.json`),read:Gs,unread:[`plugins from marketplaces added by local path (extraKnownMarketplaces in ${g(t,`settings.json`)})`],research:[`E-COPILOT-P10`,`E-COPILOT-P11`,`E-COPILOT-P12`,`E-COPILOT-P13`]}},cursor:()=>oc,opencode:()=>oc,kilo:()=>oc,"gemini-cli":()=>oc,"qwen-code":()=>oc,"vscode-copilot":()=>oc,cline:()=>oc,crush:()=>oc,openhands:()=>oc,augment:()=>oc};function cc(e){return ys({env:e}).candidates}const lc={"macos-managed-preferences":`a macOS managed-preferences domain delivered by MDM`,"windows-registry":`a Windows registry key delivered by MDM or Group Policy`,server:`server-side settings`};function uc(e,t,n,r){return r===void 0?{tier:e,dir:t,skipped:n}:{tier:e,dir:t,plugin:r,skipped:n}}function dc(e,t,n){let r=t===`win32`?x:_,i=bs(e,{platform:t,env:n}),a=[...new Set(i.flatMap(({kind:e,location:t})=>e===`file`?[r.dirname(t)]:e===`directory`?[t]:[]))];return{read:a.filter(e=>!a.some(t=>e.startsWith(t+r.sep))).map(e=>r.join(e,`references`)),unread:i.flatMap(({kind:t,location:n})=>{let r=lc[t];return r?[{location:n,reason:`${e} keeps this policy in ${r}, which cannot be read locally`}]:[]})}}function fc(e,t,n){return e.length?e.flatMap(e=>{let{read:r,unread:i}=dc(e,t,n);return[...r.map(e=>({tier:`managed`,dir:e})),...i.map(({location:e,reason:t})=>uc(`managed`,e,t))]}):[uc(`managed`,`(no harness detected)`,`no harness detected, so no managed folder`)]}function pc(e,t){for(let n of t){let t=e.find(({projectPath:e})=>e===n);if(t)return t}return e.find(({projectPath:e})=>e===void 0)}async function mc(e,t,n){let r=[];for(let i of e){let[e,a]=await Promise.all([js(i,n),Vs(i,n)]);if(!e.supported){r.push(uc(`plugin`,`(${i} enabled plugins)`,`${i} keeps no readable record of enabled plugins`));continue}e.unread.length&&r.push(uc(`plugin`,`(${i} plugin policy)`,`${e.unread.join(`; `)} may also enable or disable ${i} plugins`));for(let{id:n,enabled:o}of e.plugins){if(!o)continue;let e=n.split(`@`)[0],s=pc(a.plugins.filter(e=>e.id===n),t);if(s){let t=os(s.path)??e;r.push({tier:`plugin`,dir:g(s.path,`references`),plugin:t});continue}r.push(uc(`plugin`,`(${n})`,`enabled in ${i}, but no install folder for this project is recorded`,e))}}return r}function hc(e){return g(e,`.agents`,`references`)}function gc(e){return g(e,`.agents`,`references`)}function _c(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}function vc(e){if(r(g(e,`.git`))||r(g(e,`pnpm-workspace.yaml`)))return!0;let t=_c(g(e,`package.json`));return V(t)&&t.workspaces!==void 0}function yc(e){let t=y(e),n=[],r=t;for(;;){if(n.push(r),vc(r))return n;let e=m(r);if(e===r)return[t];r=e}}function bc(e){let t=yc(e).at(-1);return vc(t)?t:void 0}function xc(e){try{return d(e).isDirectory()}catch{return!1}}function Sc(e){let t=e;for(;;){let e=g(t,`package.json`);if(r(e))return e;let n=m(t);if(n===t)return;t=n}}function Cc(e){try{return c(e)}catch{return e}}function wc(e,t,n){let r=Sc(e);if(!r)return[];let i=[];for(let e of ns(_c(r))){let a=is(e,r);if(!a||t.has(Cc(a)))continue;let o=g(a,n);if(!xc(o))continue;let s=os(a);i.push(s?{tier:`plugin`,dir:o,plugin:s}:{tier:`plugin`,dir:o,skipped:`not a plugin`})}return i}function Tc(e){let t=Sc(e);return t?ns(_c(t)).flatMap(e=>{let n=is(e,t);return n&&os(n)?[n]:[]}):[]}function Ec(e){try{return s(g(e,`references`)).some(e=>e.endsWith(`.default.md`))}catch{return!1}}function Dc(e,t,n){if(!e.length)return{skills:[],unverified:`no harness detected, so no skill folder is read and no skill's default is listed`};let r=[],i=[];for(let a of e){let e=us(a,t);if(!e){i.push(a);continue}r.push(...e,...n.flatMap(e=>fs(a,e)))}let a=n.filter(e=>ms(e)!==void 0),o=r.length?gs([...r,...a]).filter(({folder:e})=>Ec(e)):[];return i.length?{skills:o,unverified:`the skill folders ${i.join(`, `)} ${i.length===1?`reads are`:`read are`} not verified, so ${i.length===1?`its`:`their`} skills' defaults are not listed`}:{skills:o}}function Oc(e,t){if(t===`references`||p(e.dir)!==`references`)return e;let n=g(m(e.dir),t);return{...e,dir:n,whole:!0}}function kc(e){let t=g(e,`references`);return xc(e)?{tier:`default`,dir:t,skill:ms(e)??p(e)}:{tier:`default`,dir:t,skill:p(e),skipped:`no skill folder`,warning:{code:`default-folder-missing`,message:`the skill folder ${e} does not exist; the name resolves without its default`}}}async function Ac({root:e,home:t,platform:n,plugin:r,defaultSkill:i,folder:a=`references`,env:o=process.env}){let s=cc(o),c=yc(e),l=r&&Cc(r.root),u=await mc(s,c,{env:o,homedir:t,cwd:y(e),platform:n}),d=[...r?[r.root]:[],...u.flatMap(({dir:e,skipped:t})=>t?[]:[m(e)]),...Tc(e)],f=a===`assets`?void 0:Dc(s,{chain:c,home:t,platform:n,env:o},d),p=[...fc(s,n,o),...c.map(e=>({tier:`project`,dir:hc(e)})),{tier:`user`,dir:gc(t)},...r?[{tier:`plugin`,dir:g(r.root,`references`),plugin:r.name}]:[],...u.filter(e=>e.skipped||xc(Oc(e,a).dir)&&Cc(m(e.dir))!==l),...wc(e,new Set(l?[l]:[]),a),...i===void 0?[]:[kc(y(i))]],h=/* @__PURE__ */ new Set;return{layers:p.map(e=>Oc(e,a)).filter(({dir:e})=>!h.has(e)&&h.add(e)),harnesses:s,skills:f}}function jc(e){return(Array.isArray(e)?[]:e.skills?.skills??[]).flatMap(e=>es(kc(e.folder)).map(t=>({name:t,skill:e}))).sort((e,t)=>e.name.localeCompare(t.name)||e.skill.name.localeCompare(t.skill.name))}function Mc(e){return Array.isArray(e)?void 0:e.skills?.unverified}function Nc(e,t){let{layers:n,harnesses:r,skills:i}=Array.isArray(e)?{layers:e,harnesses:[],skills:void 0}:e;return{layers:[...n.filter(({tier:e})=>e!=="default"),kc(t)],harnesses:r,skills:i}}function Pc(e){let t=e.split(`*`).map(e=>e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`));return RegExp(`^${t.join(`.*`)}$`,`s`)}function Fc(e){return typeof e==`string`&&e.split(`
|
|
183
|
-
|
|
184
|
-
`))
|
|
185
|
-
`)
|
|
186
|
-
`)
|
|
187
|
-
`)}`,`the ${e.id} interface`)}function
|
|
173
|
+
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),io=/* @__PURE__ */ O((e=>{var t=Xa(),n=Na(),r=Pa(),i=ia(),a=B(),o=no(),s=ro();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),ao=(/* @__PURE__ */ O((e=>{var t=Xa(),n=Na(),r=ja(),i=Pa(),a=Xi(),o=B(),s=sa(),c=V(),l=la(),u=da();eo();var d=to(),f=no(),p=ro(),m=io(),h=Wi();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();const oo=/^---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;function so(e){let t;try{t=o(_(e,`SKILL.md`),`utf8`)}catch{return}let n=oo.exec(t);if(n)try{let e=(0,ao.parse)(n[1]);if(z(e)&&typeof e.name==`string`&&e.name.trim())return e.name.trim()}catch{}return p(e)}function co(e){try{return d(e).isDirectory()}catch{return!1}}function lo(e){let t=[],n=/* @__PURE__ */ new Set,r=(e,r)=>{let i=e;try{i=c(e)}catch{}n.has(i)||(n.add(i),t.push({name:r,folder:i}))};for(let t of e){let e=so(t);if(e!==void 0){r(t,e);continue}let n;try{n=s(t)}catch{continue}for(let e of n.sort()){let n=_(t,e);if(!co(n))continue;let i=so(n);i!==void 0&&r(n,i)}}return t}const H=e=>e===`1`,U=e=>e!==``,uo={name:`CLAUDECODE`,matches:H,description:`Claude Code sets CLAUDECODE=1 in subprocesses it spawns; IDE extensions also set it in integrated terminals`,research:`E-CC-D1`},fo=[{harness:`claude-code`,all:[uo,{name:`CLAUDE_CODE_CHILD_SESSION`,matches:H,description:`Claude Code sets CLAUDE_CODE_CHILD_SESSION=1 for tool, hook, and status line subprocesses`,research:`E-CC-D3`}]},{harness:`claude-code`,all:[uo,{name:`CLAUDE_CODE_SESSION_ID`,matches:U,description:`Claude Code sets CLAUDE_CODE_SESSION_ID in tool, hook, and stdio MCP server subprocesses`,research:`E-CC-D6`}]},{harness:`cursor`,all:[{name:`CURSOR_AGENT`,matches:H,description:`Cursor sets CURSOR_AGENT=1 on terminal commands its agent runs`,research:`E-CUR-D1`}]},{harness:`cursor`,all:[{name:`CURSOR_VERSION`,matches:U,description:`Cursor sets CURSOR_VERSION for hook commands`,research:`E-CUR-D10`},{name:`CURSOR_PROJECT_DIR`,matches:U,description:`Cursor sets CURSOR_PROJECT_DIR for hook commands`,research:`E-CUR-D10`}]},{harness:`codex`,all:[{name:`CODEX_THREAD_ID`,matches:U,description:`Codex injects CODEX_THREAD_ID into shell tool commands, even under a restrictive shell env policy`,research:`E-CODEX-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_CLI`,matches:H,description:`Copilot CLI sets COPILOT_CLI=1 in its subprocesses`,research:`E-COPILOT-D1`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_AGENT_SESSION_ID`,matches:U,description:`Copilot CLI passes COPILOT_AGENT_SESSION_ID to shell commands and MCP servers`,research:`E-COPILOT-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_PLUGIN_ROOT`,matches:U,description:`Copilot CLI passes COPILOT_PLUGIN_ROOT to plugin hooks`,research:`E-COPILOT-D6`}]},{harness:`opencode`,all:[{name:`OPENCODE`,matches:H,description:`OpenCode sets OPENCODE=1 for shell tool commands and MCP servers; Kilo Code, its fork, sets it too`,research:`E-OC-D1`},{name:`OPENCODE_PID`,matches:U,description:`OpenCode sets OPENCODE_PID for shell tool commands and MCP servers; Kilo Code sets KILO_PID instead`,research:`E-OC-D2`}]},{harness:`kilo`,all:[{name:`KILO`,matches:H,description:`Kilo Code sets KILO=1 for shell tool commands and MCP servers`,research:`E-KILO-D2`},{name:`KILO_PID`,matches:U,description:`Kilo Code sets KILO_PID for shell tool commands and MCP servers`,research:`E-KILO-D1`}]},{harness:`gemini-cli`,all:[{name:`GEMINI_CLI`,matches:H,description:`Gemini CLI sets GEMINI_CLI=1 for shell tool commands and MCP stdio servers`,research:`E-GEM-D1`}]},{harness:`qwen-code`,all:[{name:`QWEN_CODE`,matches:H,description:`Qwen Code sets QWEN_CODE=1 for shell tool commands, not for MCP servers or hooks`,research:`E-QWEN-D1`}]},{harness:`vscode-copilot`,all:[{name:`COPILOT_AGENT`,matches:H,description:`VS Code 1.121+ sets COPILOT_AGENT=1 on terminals its Copilot agent runs commands in`,research:`E-VSC-D1`}]},{harness:`cline`,all:[{name:`CLINE_ACTIVE`,matches:e=>e===`true`,description:`Cline's VS Code extension sets CLINE_ACTIVE=true on the terminals it creates; the Cline CLI does not`,research:`E-CLINE-D1`}]},{harness:`crush`,all:[{name:`CRUSH`,matches:H,description:`Crush sets CRUSH=1 for bash tool and hook commands, not for MCP servers`,research:`E-CRUSH-D1`}]},{harness:`openhands`,all:[{name:`AI_AGENT`,matches:e=>e===`openhands`,description:`OpenHands (SDK 1.40.1 and later) sets AI_AGENT=openhands for terminal tool and hook commands when AI_AGENT is unset; other vendors use the name with other values`,research:`E-OH-D1`}]},{harness:`openhands`,all:[{name:`OPENHANDS_EVENT_TYPE`,matches:U,description:`OpenHands sets OPENHANDS_EVENT_TYPE for hook commands`,research:`E-OH-D4`},{name:`OPENHANDS_PROJECT_DIR`,matches:U,description:`OpenHands sets OPENHANDS_PROJECT_DIR for hook commands`,research:`E-OH-D4`}]},{harness:`augment`,all:[{name:`AUGMENT_HOOK_EVENT`,matches:U,description:`The Auggie CLI sets AUGMENT_HOOK_EVENT for hook commands; its shell commands carry no marker`,research:`E-AUG-D3`},{name:`AUGMENT_PROJECT_DIR`,matches:U,description:`The Auggie CLI sets AUGMENT_PROJECT_DIR for hook commands`,research:`E-AUG-D3`}]}];function po(e={}){let t=e.env??process.env,n=[],r=[];for(let e of fo){let i=e.all.filter(e=>{let n=t[e.name];return n!==void 0&&e.matches(n)});for(let t of i)n.some(n=>n.harness===e.harness&&n.signal===t.name)||n.push({harness:e.harness,signal:t.name,description:t.description,research:t.research});i.length===e.all.length&&!r.includes(e.harness)&&r.push(e.harness)}return{harness:r.length===1?r[0]:`unknown`,evidence:n,candidates:r}}function mo(e,t={}){let n=t.platform??process.platform,r=t.env??process.env;return yo[e](n,r)}const ho=e=>e===`win32`?S.join:v.join,go=e=>e===`win32`?S.dirname:v.dirname;function _o(e,t,n,r){let i={darwin:`/Library/Application Support/${n}`,linux:`/etc/${n}`,win32:S.join(t.ProgramData??`C:\\ProgramData`,n)}[e];return[...W(e===`darwin`,{kind:`macos-managed-preferences`,location:`ai.opencode.managed`,description:`MDM configuration profile; outranks the managed config folder`,research:r.preferences}),...W(i!==void 0,{kind:`directory`,location:i??``,description:`Managed config files; outrank user and project config`,research:r.directory})]}function vo(e,t,n){let r=e===`darwin`||e===`win32`?n.dirs[e]:n.dirs.linux,i=t[n.settingsVariable]||ho(e)(r,`settings.json`),a=t[n.defaultsVariable]||ho(e)(go(e)(i),`system-defaults.json`);return[{kind:`file`,location:i,description:`System settings; outrank user and workspace settings. ${n.settingsVariable} overrides the path`,research:n.research},{kind:`file`,location:a,description:`System defaults; user and workspace settings override them. ${n.defaultsVariable} overrides the path`,research:n.research}]}const W=(e,...t)=>e?t:[],yo={"claude-code":e=>{let t={darwin:`/Library/Application Support/ClaudeCode`,linux:`/etc/claude-code`,win32:`C:\\Program Files\\ClaudeCode`}[e],n=ho(e);return[{kind:`server`,location:`claude.ai admin console or a self-hosted Claude apps gateway`,description:`Server-managed settings; the highest-ranked managed source`,research:`E-CC-M6`},...W(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.anthropic.claudecode`,description:`MDM configuration profile with the same top-level keys as managed-settings.json`,research:`E-CC-M6`}),...W(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\ClaudeCode`,description:`MDM or Group Policy; the Settings value holds managed-settings JSON`,research:`E-CC-M6`}),...W(t!==void 0,{kind:`file`,location:n(t??``,`managed-settings.json`),description:`Managed settings, same shape as settings.json`,research:`E-CC-M1`},{kind:`directory`,location:n(t??``,`managed-settings.d`),description:`Drop-in managed settings files, merged with managed-settings.json`,research:`E-CC-M1`},{kind:`file`,location:n(t??``,`managed-mcp.json`),description:`Managed MCP servers`,research:`E-CC-M1`}),...W(e===`win32`,{kind:`windows-registry`,location:`HKCU\\SOFTWARE\\Policies\\ClaudeCode`,description:`User-writable; used only when no other managed source delivers a policy key`,research:`E-CC-M6`})]},cursor:e=>{let t={darwin:`/Library/Application Support/Cursor/hooks.json`,linux:`/etc/cursor/hooks.json`,win32:`C:\\ProgramData\\Cursor\\hooks.json`}[e];return[...W(t!==void 0,{kind:`file`,location:t??``,description:`Enterprise hooks deployed by MDM; hooks only, not other enterprise settings`,research:`E-CUR-M1`}),{kind:`server`,location:`Cursor dashboard`,description:`Team hooks and other enterprise settings, synced from the dashboard`,research:`E-CUR-M1`}]},codex:(e,t)=>{let n={kind:`server`,location:`ChatGPT workspace admin settings`,description:`Cloud-managed requirements; outrank every local source`,research:`E-CODEX-M8`};return e===`win32`?[n,{kind:`file`,location:S.join(t.ProgramData??`C:\\ProgramData`,`OpenAI`,`Codex`,`requirements.toml`),description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M4`}]:[n,...W(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.openai.codex`,description:`MDM keys requirements_toml_base64 (enforced) and config_toml_base64 (managed defaults)`,research:`E-CODEX-M6`}),{kind:`file`,location:`/etc/codex/requirements.toml`,description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M3`},{kind:`file`,location:`/etc/codex/managed_config.toml`,description:`Managed defaults; a user can override them within a session`,research:`E-CODEX-M2`},{kind:`file`,location:`/etc/codex/config.toml`,description:`System-wide config`,research:`E-CODEX-M1`}]},"copilot-cli":(e,t)=>{let n={darwin:`/Library/Application Support/GitHubCopilot/managed-settings.json`,linux:`/etc/github-copilot/managed-settings.json`,win32:S.join(t.ProgramFiles??`C:\\Program Files`,`GitHubCopilot`,`managed-settings.json`)}[e];return[...W(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.github.copilot`,description:`MDM-managed settings; the highest-ranked source`,research:`E-COPILOT-M2`}),...W(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\GitHubCopilot`,description:`MDM-managed settings as REG_SZ values; the highest-ranked source`,research:`E-COPILOT-M2`}),{kind:`server`,location:`copilot/managed-settings.json in the enterprise's .github-private repository`,description:`Server-managed settings, fetched for the signed-in account`,research:`E-COPILOT-M3`},...W(n!==void 0,{kind:`file`,location:n??``,description:`File-based managed settings; on macOS and Linux it must be a root-owned regular file`,research:`E-COPILOT-M1`})]},opencode:(e,t)=>[..._o(e,t,`opencode`,{directory:`E-OC-M1`,preferences:`E-OC-M1`}),{kind:`server`,location:`Remote config at the organization domain /.well-known/opencode`,description:`Organization defaults; the lowest-ranked config source, so user config overrides them`,research:`E-OC-M2`}],kilo:(e,t)=>_o(e,t,`kilo`,{directory:`E-KILO-M1`,preferences:`E-KILO-M2`}),"gemini-cli":(e,t)=>vo(e,t,{settingsVariable:`GEMINI_CLI_SYSTEM_SETTINGS_PATH`,defaultsVariable:`GEMINI_CLI_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/GeminiCli`,linux:`/etc/gemini-cli`,win32:`C:\\ProgramData\\gemini-cli`},research:`E-GEM-M1`}),"qwen-code":(e,t)=>vo(e,t,{settingsVariable:`QWEN_CODE_SYSTEM_SETTINGS_PATH`,defaultsVariable:`QWEN_CODE_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/QwenCode`,linux:`/etc/qwen-code`,win32:`C:\\ProgramData\\qwen-code`},research:`E-QWEN-M1`}),"vscode-copilot":e=>[...W(e===`win32`,{kind:`windows-registry`,location:`Software\\Policies\\Microsoft\\VSCode`,description:`VS Code policies set by Group Policy (ADMX templates ship with VS Code)`,research:`E-VSC-M1`}),...W(e===`linux`,{kind:`file`,location:`/etc/vscode/policy.json`,description:`VS Code policies as JSON, read by VS Code 1.106 and later`,research:`E-VSC-M3`})],cline:()=>[{kind:`server`,location:`Cline Enterprise admin console`,description:`Provider, model, and tool policy pushed to clients; no local policy file is documented`,research:`E-CLINE-M1`}],crush:e=>W(e!==`win32`,{kind:`file`,location:`/etc/crush/crush.json`,description:`System config; the lowest-ranked source, so user and project config override it`,research:`E-CRUSH-M1`}),openhands:()=>[{kind:`server`,location:`OpenHands Cloud or Enterprise deployment`,description:`Organization controls held server-side; no local policy file is known`,research:`E-OH-D8`}],augment:(e,t)=>[{kind:`file`,location:e===`win32`?S.join(t.ProgramData||`C:\\ProgramData`,`augment`,`settings.json`):`/etc/augment/settings.json`,description:`System settings, read from the Auggie CLI bundle; its rank against user settings is not documented`,research:`E-AUG-M1`}]};function bo(e={}){return{env:e.env??process.env,homedir:e.homedir??T(),cwd:e.cwd??process.cwd(),platform:e.platform??process.platform}}function xo(e,t={}){return wo[e](bo(t))}const So=({env:e,homedir:t})=>e.XDG_CONFIG_HOME||_(t,`.config`);function Co({env:e,homedir:t,platform:n}){if(n===`win32`){let n=S.join(e.APPDATA||S.join(t,`AppData`,`Roaming`),`Code`);return{configDir:n,path:S.join(n,`agentPlugins`)}}let r=n===`darwin`?_(t,`Library`,`Application Support`,`Code`):_(t,`.config`,`Code`);return{configDir:r,path:_(r,`agentPlugins`)}}const wo={"claude-code":({env:e,homedir:t})=>{let n=e.CLAUDE_CONFIG_DIR||_(t,`.claude`),r=_(n,`plugins`);return{harness:`claude-code`,configDir:n,locations:[{kind:`plugin-cache`,path:_(r,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CC-P1`},{kind:`marketplaces`,path:_(r,`marketplaces`),description:`Marketplace checkouts`,research:`E-CC-P1`},{kind:`install-record`,path:_(r,`installed_plugins.json`),description:`Installs keyed by plugin@marketplace, each with scope, installPath, and version`,research:`E-CC-P2`},{kind:`enabled-record`,path:_(n,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-CC-P3`}]}},cursor:({homedir:e})=>{let t=_(e,`.cursor`);return{harness:`cursor`,configDir:t,locations:[{kind:`local-plugins`,path:_(t,`plugins`,`local`),description:`Plugins under development, one folder each`,research:`E-CUR-P2`},{kind:`marketplaces`,path:_(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-CUR-P3`}]}},codex:({env:e,homedir:t})=>{let n=e.CODEX_HOME||_(t,`.codex`);return{harness:`codex`,configDir:n,locations:[{kind:`plugin-cache`,path:_(n,`plugins`,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CODEX-P3`},{kind:`enabled-record`,path:_(n,`config.toml`),description:`User config; [plugins."<plugin>@<marketplace>"] tables carry enabled = <bool>`,research:`E-CODEX-P2`}]}},"copilot-cli":({env:e,homedir:t})=>{let n=e.COPILOT_HOME||_(t,`.copilot`);return{harness:`copilot-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:_(n,`installed-plugins`),description:`Installed plugins as <marketplace>/<plugin>/, or _direct/<source-id>/ for direct installs`,research:`E-COPILOT-P9`},{kind:`install-record`,path:_(n,`config.json`),description:`Application state, including installedPlugins`,research:`E-COPILOT-P9`},{kind:`enabled-record`,path:_(n,`settings.json`),description:`User settings (JSON with comments); enabledPlugins maps plugin specs to a boolean`,research:`E-COPILOT-P4`}]}},opencode:e=>{let t=_(So(e),`opencode`);return{harness:`opencode`,configDir:t,locations:[{kind:`local-plugins`,path:_(t,`plugins`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-OC-P2`}]}},kilo:e=>{let t=_(So(e),`kilo`);return{harness:`kilo`,configDir:t,locations:[{kind:`local-plugins`,path:_(t,`plugin`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-KILO-P2`}]}},"gemini-cli":({env:e,homedir:t})=>{let n=_(e.GEMINI_CLI_HOME||t,`.gemini`),r=_(n,`extensions`);return{harness:`gemini-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a gemini-extension.json manifest`,research:`E-GEM-P1`},{kind:`enabled-record`,path:_(r,`extension-enablement.json`),description:`Per-extension path-glob overrides that enable or disable it by folder, not a boolean`,research:`E-GEM-P3`}]}},"qwen-code":({env:e,homedir:t})=>{let n=e.QWEN_HOME||_(t,`.qwen`),r=_(n,`extensions`);return{harness:`qwen-code`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a qwen-extension.json manifest`,research:`E-QWEN-P1`},{kind:`enabled-record`,path:_(r,`extension-enablement.json`),description:`Extension enable/disable state, inherited from Gemini CLI's format`,research:`E-QWEN-P2`}]}},"vscode-copilot":e=>{let{configDir:t,path:n}=Co(e);return{harness:`vscode-copilot`,configDir:t,locations:[{kind:`installed-plugins`,path:n,description:`Installed agent plugins as <host>/<org>/<repo>/`,research:`E-VSC-P3`}]}},cline:({homedir:e})=>{let t=_(e,`.cline`);return{harness:`cline`,configDir:t,locations:[{kind:`installed-plugins`,path:_(t,`plugins`,`_installed`),description:`Installed plugins, grouped by source: npm, git, remote, or local`,research:`E-CLINE-P3`}]}},crush:({env:e,homedir:t})=>({harness:`crush`,configDir:e.CRUSH_GLOBAL_CONFIG||_(e.XDG_CONFIG_HOME||_(t,`.config`),`crush`),locations:[]}),openhands:({env:e,homedir:t})=>{let n=e.OH_PERSISTENCE_DIR||e.OPENHANDS_PERSISTENCE_DIR||_(t,`.openhands`),r=_(n,`plugins`,`installed`);return{harness:`openhands`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed plugins, one folder each`,research:`E-OH-P3`},{kind:`enabled-record`,path:_(r,`.installed.json`),description:`Install metadata keyed by plugin name, each with enabled: <bool>`,research:`E-OH-P4`}]}},augment:({homedir:e})=>{let t=_(e,`.augment`);return{harness:`augment`,configDir:t,locations:[{kind:`marketplaces`,path:_(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-AUG-P2`},{kind:`enabled-record`,path:_(t,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-AUG-P4`}]}}};async function To(e,t={}){let n=Fo[e](bo(t),t.managedSettingsPath),r=/* @__PURE__ */ new Map,i=[];for(let e of n.sources){let t;try{let n=await Ni(e.path);if(n===void 0){i.push({scope:e.scope,path:e.path,found:!1});continue}t=e.parse(n)}catch(t){i.push({scope:e.scope,path:e.path,found:!0,error:String(t)});continue}i.push({scope:e.scope,path:e.path,found:!0});for(let[n,i]of Object.entries(t))r.has(n)||r.set(n,{id:n,enabled:i,scope:e.scope,source:e.path})}return{harness:e,supported:n.supported,plugins:[...r.values()],sources:i,unread:n.unread,research:n.research}}function Eo(e){let t=JSON.parse(e),n=z(t)?t.enabledPlugins:void 0;return z(n)?Object.fromEntries(Object.entries(n).filter(e=>typeof e[1]==`boolean`)):{}}const Do=/^\[\s*plugins\s*\.\s*(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_-]+))\s*\]\s*(?:#.*)?$/,Oo=/^enabled\s*=\s*(true|false)\s*(?:#.*)?$/;function ko(e){let t={},n;for(let r of e.split(/\r?\n/)){let e=r.trim();if(e.startsWith(`[`)){let t=Do.exec(e);n=t?t[1]??t[2]??t[3]:void 0;continue}let i=n===void 0?null:Oo.exec(e);n!==void 0&&i&&(t[n]=i[1]===`true`)}return t}const Ao={server:`server-managed settings`,"macos-managed-preferences":`MDM managed preferences`,"windows-registry":`Windows registry policy`,directory:`drop-in managed settings`,file:`managed file`};function jo(e,t,n=[]){return e.filter(e=>e.location!==t&&!n.some(t=>e.location.endsWith(t))).map(e=>`${Ao[e.kind]} (${e.location})`)}function Mo(e,t){return e.find(e=>e.kind===`file`&&e.location.endsWith(t))?.location}function No(e){return Eo(Pi(e))}const Po=(...e)=>({supported:!1,sources:[],unread:[],research:e}),Fo={"claude-code":(e,t)=>{let{configDir:n}=xo(`claude-code`,e),r=mo(`claude-code`,e),i=Mo(r,`managed-settings.json`),a=t??i,o=_(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:Eo}],{scope:`local`,path:_(o,`settings.local.json`),parse:Eo},{scope:`project`,path:_(o,`settings.json`),parse:Eo},{scope:`user`,path:_(n,`settings.json`),parse:Eo}],unread:jo(r,i,[`managed-mcp.json`]),research:[`E-CC-P3`,`E-CC-P7`,`E-CC-M1`,`E-CC-M6`]}},cursor:()=>Po(),opencode:()=>Po(`E-OC-P3`),kilo:()=>Po(`E-KILO-P3`),"gemini-cli":()=>Po(`E-GEM-P3`),"qwen-code":()=>Po(`E-QWEN-P2`),"vscode-copilot":()=>Po(`E-VSC-P4`),cline:()=>Po(`E-CLINE-P4`),crush:()=>Po(`E-CRUSH-P2`),openhands:()=>Po(`E-OH-P4`),augment:()=>Po(`E-AUG-P4`),codex:e=>{let t=xo(`codex`,e);return{supported:!0,sources:[{scope:`user`,path:_(t.configDir,`config.toml`),parse:ko}],unread:jo(mo(`codex`,e),void 0),research:[`E-CODEX-P2`,`E-CODEX-M7`]}},"copilot-cli":(e,t)=>{let n=xo(`copilot-cli`,e),r=mo(`copilot-cli`,e),i=Mo(r,`managed-settings.json`),a=t??i,o=_(e.cwd,`.github`,`copilot`),s=_(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:No}],{scope:`local`,path:_(o,`settings.local.json`),parse:No},{scope:`project`,path:_(o,`settings.json`),parse:No},{scope:`user`,path:_(n.configDir,`settings.json`),parse:No}],unread:[...jo(r,i),`Claude Code project settings (${_(s,`settings.json`)})`,`Claude Code local settings (${_(s,`settings.local.json`)})`],research:[`E-COPILOT-P4`,`E-COPILOT-M1`,`E-COPILOT-M2`,`E-COPILOT-M4`]}}};async function Io(e,t={}){let n=ns[e](bo(t)),r={harness:e,supported:n.supported,unread:n.unread,research:n.research};if(n.source===void 0)return{...r,plugins:[],unresolved:[],sources:[]};let i=n.source;try{let e=await n.read(i);return e===void 0?{...r,plugins:[],unresolved:[],sources:[{path:i,found:!1}]}:{...r,plugins:e.plugins,unresolved:e.unresolved??[],sources:[{path:i,found:!0}]}}catch(e){return{...r,plugins:[],unresolved:[],sources:[{path:i,found:!0,error:String(e)}]}}}const Lo=[`managed`,`local`,`project`,`user`],Ro=e=>typeof e==`string`&&e!==``?e:void 0;async function zo(e){let t=await Ni(e);if(t===void 0)return;let n=JSON.parse(t),r=z(n)?n.plugins:void 0;if(!z(r))return{plugins:[]};let i=[];for(let[e,t]of Object.entries(r))if(Array.isArray(t))for(let n of t){let t=z(n)?Ro(n.installPath):void 0;if(!z(n)||t===void 0)continue;let r=Ro(n.version),a=typeof n.scope==`string`&&Lo.includes(n.scope)?n.scope:void 0,o=Ro(n.projectPath);i.push({id:e,path:t,...r===void 0?{}:{version:r},...a===void 0?{}:{scope:a},...o===void 0?{}:{projectPath:o},research:[`E-CC-P2`]})}return{plugins:i}}async function Bo(e){let t=await Ni(e);if(t===void 0)return;let n=JSON.parse(Pi(t)),r=z(n)?n.installedPlugins:void 0;if(!Array.isArray(r))return{plugins:[]};let i=[];for(let e of r){if(!z(e))continue;let t=Ro(e.name),n=Ro(e.cache_path);if(t===void 0||n===void 0)continue;let r=Ro(e.marketplace),a=Ro(e.version);i.push({id:r===void 0?t:`${t}@${r}`,path:n,...a===void 0?{}:{version:a},research:r===void 0?[`E-COPILOT-P10`,`E-COPILOT-P11`]:[`E-COPILOT-P10`]})}return{plugins:i}}const Vo=`local`,Ho=/^[A-Za-z0-9_-]+$/,Uo=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/,Wo=/^[A-Za-z0-9._+-]+$/;async function Go(e){let t=await qo(e);if(t===void 0)return;let n=[],r=[];for(let i of t.filter(e=>Ho.test(e)))for(let t of await qo(_(e,i))??[]){if(!Uo.test(t))continue;let a=`${t}@${i}`,o=(await qo(_(e,i,t))??[]).filter(e=>Wo.test(e)&&e!==`.`&&e!==`..`);if(o.length===0)continue;let s=Ko(o);if(s===void 0){r.push(a);continue}n.push({id:a,path:_(e,i,t,s),version:s,research:[`E-CODEX-P3`,`E-CODEX-P8`]})}return{plugins:n,unresolved:r}}function Ko(e){if(e.includes(Vo))return Vo;let t=e.filter(e=>Yo(e)!==void 0).length;if(!(e.length>2&&t!==0&&t!==e.length))return[...e].sort(Xo).at(-1)}async function qo(e){try{return(await D(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Jo=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;function Yo(e){let t=Jo.exec(e);if(t)return{core:[t[1],t[2],t[3]],pre:t[4]===void 0?[]:t[4].split(`.`),build:t[5]===void 0?[]:t[5].split(`.`)}}function Xo(e,t){let n=Yo(e),r=Yo(t);if(n===void 0||r===void 0)return es(e,t);for(let e=0;e<3;e++){let t=$o(n.core[e],r.core[e]);if(t!==0)return t}let i=n.pre.length===0||r.pre.length===0?r.pre.length-n.pre.length:Qo(n.pre,r.pre);return i===0?Qo(n.build,r.build):Math.sign(i)}const Zo=/^\d+$/;function Qo(e,t){for(let n=0;n<Math.min(e.length,t.length);n++){let r=e[n],i=t[n],a=Zo.test(r),o=Zo.test(i),s=a&&o?$o(r,i):a===o?es(r,i):a?-1:1;if(s!==0)return s}return e.length-t.length}function $o(e,t){let n=e.replace(/^0+(?=\d)/,``),r=t.replace(/^0+(?=\d)/,``);return n.length-r.length||es(n,r)||e.length-t.length}const es=(e,t)=>e<t?-1:+(e>t),ts={supported:!1,read:async()=>void 0,unread:[],research:[]},ns={"claude-code":e=>({supported:!0,source:_(xo(`claude-code`,e).configDir,`plugins`,`installed_plugins.json`),read:zo,unread:[],research:[`E-CC-P2`]}),codex:e=>({supported:!0,source:_(xo(`codex`,e).configDir,`plugins`,`cache`),read:Go,unread:[],research:[`E-CODEX-P3`,`E-CODEX-P8`]}),"copilot-cli":e=>{let{configDir:t}=xo(`copilot-cli`,e);return{supported:!0,source:_(t,`config.json`),read:Bo,unread:[`plugins from marketplaces added by local path (extraKnownMarketplaces in ${_(t,`settings.json`)})`],research:[`E-COPILOT-P10`,`E-COPILOT-P11`,`E-COPILOT-P12`,`E-COPILOT-P13`]}},cursor:()=>ts,opencode:()=>ts,kilo:()=>ts,"gemini-cli":()=>ts,"qwen-code":()=>ts,"vscode-copilot":()=>ts,cline:()=>ts,crush:()=>ts,openhands:()=>ts,augment:()=>ts};function rs(e){return po({env:e}).candidates}const is={"macos-managed-preferences":`a macOS managed-preferences domain delivered by MDM`,"windows-registry":`a Windows registry key delivered by MDM or Group Policy`,server:`server-side settings`};function as(e,t,n,r){return r===void 0?{tier:e,dir:t,skipped:n}:{tier:e,dir:t,plugin:r,skipped:n}}function os(e,t,n){let r=t===`win32`?S:v,i=mo(e,{platform:t,env:n}),a=[...new Set(i.flatMap(({kind:e,location:t})=>e===`file`?[r.dirname(t)]:e===`directory`?[t]:[]))];return{read:a.filter(e=>!a.some(t=>e.startsWith(t+r.sep))).map(e=>r.join(e,`assets`)),unread:i.flatMap(({kind:t,location:n})=>{let r=is[t];return r?[{location:n,reason:`${e} keeps this policy in ${r}, which cannot be read locally`}]:[]})}}function ss(e,t,n){return e.length?e.flatMap(e=>{let{read:r,unread:i}=os(e,t,n);return[...r.map(e=>({tier:`managed`,dir:e})),...i.map(({location:e,reason:t})=>as(`managed`,e,t))]}):[as(`managed`,`(no harness detected)`,`no harness detected, so no managed folder`)]}function cs(e,t){for(let n of t){let t=e.find(({projectPath:e})=>e===n);if(t)return t}return e.find(({projectPath:e})=>e===void 0)}async function ls(e,t,n){let r=[];for(let i of e){let[e,a]=await Promise.all([To(i,n),Io(i,n)]);if(!e.supported){r.push(as(`plugin`,`(${i} enabled plugins)`,`${i} keeps no readable record of enabled plugins`));continue}e.unread.length&&r.push(as(`plugin`,`(${i} plugin policy)`,`${e.unread.join(`; `)} may also enable or disable ${i} plugins`));for(let{id:n,enabled:o}of e.plugins){if(!o)continue;let e=n.split(`@`)[0],s=cs(a.plugins.filter(e=>e.id===n),t);if(s){let t=Bi(s.path)??e;r.push({tier:`plugin`,dir:_(s.path,`assets`),plugin:t});continue}r.push(as(`plugin`,`(${n})`,`enabled in ${i}, but no install folder for this project is recorded`,e))}}return r}function us(e){return _(e,`.agents`,`assets`)}function ds(e){return _(e,`.agents`,`assets`)}function fs(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}function ps(e){if(r(_(e,`.git`))||r(_(e,`pnpm-workspace.yaml`)))return!0;let t=fs(_(e,`package.json`));return z(t)&&t.workspaces!==void 0}function ms(e){let t=b(e),n=[],r=t;for(;;){if(n.push(r),ps(r))return n;let e=m(r);if(e===r)return[t];r=e}}function hs(e){try{return d(e).isDirectory()}catch{return!1}}function gs(e){let t=e;for(;;){let e=_(t,`package.json`);if(r(e))return e;let n=m(t);if(n===t)return;t=n}}function _s(e){try{return c(e)}catch{return e}}function vs(e,t){let n=gs(e);if(!n)return[];let r=[];for(let e of Fi(fs(n))){let i=Li(e,n);if(!i||t.has(_s(i)))continue;let a=_(i,`assets`);if(!hs(a))continue;let o=Bi(i);r.push(o?{tier:`plugin`,dir:a,plugin:o}:{tier:`plugin`,dir:a,skipped:`not a plugin`})}return r}function ys(e){let t=_(e,`assets`);return hs(e)?{tier:`default`,dir:t,skill:so(e)??p(e)}:{tier:`default`,dir:t,skill:p(e),skipped:`no skill folder`,warning:{code:`default-folder-missing`,message:`the skill folder ${e} does not exist; the name resolves without its default`}}}async function bs({root:e,home:t,platform:n,plugin:r,defaultSkill:i,env:a=process.env}){let o=rs(a),s=ms(e),c=r&&_s(r.root),l=await ls(o,s,{env:a,homedir:t,cwd:b(e),platform:n}),u=[...ss(o,n,a),...s.map(e=>({tier:`project`,dir:us(e)})),{tier:`user`,dir:ds(t)},...r?[{tier:`plugin`,dir:_(r.root,`assets`),plugin:r.name}]:[],...l.filter(e=>e.skipped||hs(e.dir)&&_s(m(e.dir))!==c),...vs(e,new Set(c?[c]:[])),...i===void 0?[]:[ys(b(i))]],d=/* @__PURE__ */ new Set;return{layers:u.filter(({dir:e})=>!d.has(e)&&d.add(e)),harnesses:o}}function G(e,t){return e&&t.startsWith(e+x)?`~${t.slice(e.length)}`:t}const xs=[{extension:`.json`,format:`json`},{extension:`.yaml`,format:`yaml`},{extension:`.yml`,format:`yaml`},{extension:`.toml`,format:`toml`},{extension:`.txt`,format:`txt`}];function Ss(e){return xs.find(({extension:t})=>e.endsWith(t))?.format??`markdown`}const Cs=/^[a-z0-9]+(?:[-.][a-z0-9]+)*$/i;function ws(e){let t=t=>({raw:e,name:e,invalid:t});if(e.endsWith(`.md`))return t(`"${e}" names a file. Ask for the reference by name, without the .md extension.`);let n=xs.find(t=>e.endsWith(t.extension));if(n)return t(`"${e}" names a file. Ask for the reference by name, without the ${n.extension} extension.`);let r=e.split(`/`);if(r.length>2||e.includes(`\\`))return t(`"${e}" is a path. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/".`);let[i,a]=r,o=a??i,s=a===void 0?void 0:i;return o.endsWith(`.default`)?t(`"${e}" names a skill's default file. Ask for "${o.slice(0,-8)}"; the default joins when its skill loads it.`):!Cs.test(o)||s!==void 0&&!Cs.test(s)?t(`"${e}" is not a reference name. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/", where <plugin> is a plugin's manifest name.`):s===void 0?{raw:e,name:o}:{raw:e,name:o,plugin:s}}function Ts(e){return Array.isArray(e)?{layers:[...e],harnesses:[]}:e}function Es(e){try{return o(e,`utf8`)}catch{return}}function Ds(e){return[`${e}.md`,...xs.map(({extension:t})=>`${e}${t}`)]}function Os(e,t,n){return e.tier===`plugin`?`plugin ${e.plugin}`:e.tier==="default"?`default of ${e.skill}`:`${e.tier} ${n(t)}`}function ks(e,t,n){for(let r of e){if(r.skipped||![`managed`,`project`,`user`].includes(r.tier))continue;let e=Es(_(r.dir,`${t}.select`));if(e===void 0)continue;let i=e.trim();if(!Cs.test(i)){n(`selection-invalid`,`${r.tier} ${t}.select holds "${i}", which is not a plugin name or default; it is ignored`);continue}return i}}function As(e,t,n,r,i,a,o){let s=(e,t)=>({target:e,contribution:t,from:`default`}),c=a?[s(`default`,a)]:[];if(e.plugin!==void 0){let t=i(e.plugin);return`reason`in t?{status:`missing`,message:`the plugin ${e.plugin} ${t.reason}`}:{entries:[s(e.plugin,t)],builtBy:`qualified name`}}if(n.some(({hasBody:e})=>e))return{entries:c,builtBy:`none`};let l=ks(t,e.name,o);if(l!==void 0){if(l==="default"&&a)return{entries:c,builtBy:`selection`};let t=r.get(l);if(t)return{entries:[...c,s(l,t)],builtBy:`selection`};o(`selection-invalid`,`the selection of "${e.name}" names ${l}, which holds no such asset; it is ignored`)}let u=[...r.entries()];if(u.length>1){let t=u.map(([e])=>e);return{status:`ambiguous`,cause:`unordered`,message:`the plugins ${t.join(`, `)} hold it; run "asset select ${e.name} <option>" (options: ${t.join(`, `)}${a?`, default`:``}), ask for ${t[0]}/${e.name}, or put the file in a project or user assets folder`}}let[d]=u;return{entries:[...c,...d?[s(d[0],d[1])]:[]],builtBy:`none`}}function js(e,t,n,r,i,a){if(e.tier!=="default"){let n=_(e.dir,`${t}.default.md`);n!==i&&Es(n)!==void 0&&a(r(n))(`default-in-tier`,`it is ignored: a default goes in a skill's references/ folder`)}let[o,...s]=Ds(t).flatMap(t=>{let n=_(e.dir,t),r=n===i?void 0:Es(n);return r===void 0?[]:[{file:t,path:n,raw:r}]});if(!o)return;for(let e of s)a(r(e.path))(`file-ignored`,`it is ignored: ${o.file} answers first in that folder`);let c=Os(e,o.path,r);Object.assign(n,{path:o.path,file:o.file,outcome:``});let l=o.raw.trim().length>0;return l||(n.empty=!0),{layer:e,entry:n,label:c,path:o.path,body:o.raw,hasBody:l,format:Ss(o.file)}}function Ms(e,t,{display:n=e=>e,without:r}={}){let i=typeof e==`string`?ws(e):e,{layers:a,harnesses:o}=Ts(t),s={stack:[],builtBy:`none`,contributions:[],sections:[],layers:[],harnesses:[...o]},c=[],l={name:i.raw,status:`missing`,warnings:c,trace:s};if(i.invalid)return{...l,status:`invalid`,code:`reference-invalid`,message:i.invalid};let u=/* @__PURE__ */ new Set,d=e=>(t,n)=>{let r=e?`${e}: ${n}`:n;u.has(`${t} ${r}`)||(u.add(`${t} ${r}`),c.push({code:t,message:r}))},f=d(``),p=[];for(let e of a){e.warning&&f(e.warning.code,e.warning.message);let t={tier:e.tier,path:e.dir,outcome:`missing`};if(e.plugin!==void 0&&(t.plugin=e.plugin),e.skill!==void 0&&(t.skill=e.skill),s.layers.push(t),e.skipped){t.outcome=`not read (${e.skipped})`;continue}let a=js(e,i.name,t,n,r,d);a?p.push(a):e.tier==="default"&&(t.outcome=`not read (no default)`)}let m=/* @__PURE__ */ new Map;for(let e of p.filter(({layer:e})=>e.tier===`plugin`)){let t=e.layer.plugin,r=m.get(t);r?e.entry.outcome=`not read (plugin ${t} answers from ${n(r.path)})`:m.set(t,e)}let h=p.find(({layer:e})=>e.tier==="default"),g=p.filter(({layer:e})=>e.tier!==`plugin`&&e.tier!=="default"),_=new Set(a.flatMap(({plugin:e,skipped:t})=>e&&!t?[e]:[])),v=As(i,a,g,m,e=>e==="default"?h??{reason:`has no default`}:m.get(e)??{reason:_.has(e)?`holds no ${i.name}`:`is not installed`},h,f);if(`status`in v){if(v.status===`ambiguous`){for(let{entry:e}of p)e.outcome===``&&(e.outcome=`ambiguous`);return{...l,status:`ambiguous`,code:`reference-ambiguous`,message:v.message,cause:`unordered`,options:[...[...m.keys()].map(e=>`${e}/${i.name}`),...h?[`default`]:[]]}}for(let{entry:e}of p)e.outcome===``&&(e.outcome=`not used (qualified name)`);return{...l,status:`missing`,code:`reference-missing`,message:v.message}}s.stack=v.entries.map(({target:e})=>e),s.builtBy=v.builtBy;let y=new Set(s.stack);for(let[e,t]of[...m.entries(),...h?[[`default`,h]]:[]])y.has(e)||(t.entry.outcome=i.plugin===void 0?`not used (not in extends)`:`not used (qualified name)`);let b=[...v.entries,...[...g].reverse().map(e=>({contribution:e,from:`contribution`}))],x=[],S;for(let{contribution:e,from:t}of b){let{entry:n}=e;if(n.operation=`replace`,e.hasBody){n.operationFrom=`default`;for(let t of x)t.entry.outcome=`shadowed by ${e.label} (replace)`;x=[e],S=e}else n.operationFrom=t;n.outcome=`used`}if(!x.length){let e=i.plugin===void 0?`no tier holds a document for "${i.name}"`:`the plugin ${i.plugin} holds no document for "${i.name}"`;return{...l,status:`missing`,code:`reference-missing`,message:e}}s.contributions=x.map(({layer:e,entry:t})=>{let n={tier:e.tier,path:t.path,operation:`replace`};return t.plugin!==void 0&&(n.plugin=t.plugin),t.skill!==void 0&&(n.skill=t.skill),n});let C=S;return{...l,status:`found`,content:C.body,format:C.format,metadata:{}}}function Ns(e){if(e.skipped)return[];let t;try{t=s(e.dir,{withFileTypes:!0})}catch{return[]}let n=/* @__PURE__ */ new Set;for(let e of t){if(e.isDirectory()||![`.md`,...xs.map(e=>e.extension)].some(t=>e.name.endsWith(t)))continue;let t=e.name.slice(0,e.name.lastIndexOf(`.`));ws(t).invalid||n.add(t)}return[...n]}function Ps(e){return[...new Set(Ts(e).layers.flatMap(Ns))].sort((e,t)=>e.localeCompare(t))}function Fs(e){let t=e.split(`*`).map(e=>e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`));return RegExp(`^${t.join(`.*`)}$`,`s`)}function Is(e,{pattern:t,...n}={}){let r=t===void 0?void 0:Fs(t),i={references:[],layers:[],warnings:[]},a=/* @__PURE__ */ new Set;for(let t of Ps(e)){if(r&&!r.test(t))continue;let o=Ms(t,e,n);for(let e of o.warnings){let t=`${e.code} ${e.message}`;a.has(t)||i.warnings.push(e),a.add(t)}let s={name:t,status:o.status};o.format&&o.format!==`markdown`&&(s.format=o.format),o.options&&(s.options=o.options.filter(e=>e!=="default")),i.references.push(s);for(let e of o.trace.layers){if(e.file===void 0||e.tier==="default")continue;let n={name:t,tier:e.tier,path:e.path,outcome:e.outcome};e.plugin!==void 0&&(n.plugin=e.plugin),e.skill!==void 0&&(n.skill=e.skill),i.layers.push(n)}}return i}const Ls={project:`everyone working in this repository`,user:`only you, in every repository`};function Rs(e,t,{root:n,display:r=e=>e}){let i=typeof e==`string`?ws(e):e,a=Ms(i,t,{display:r}),o={name:i.raw,status:a.status,places:[],layers:a.trace.layers,warnings:a.warnings};if(a.options&&(o.options=a.options),i.invalid)return o;let s=(Array.isArray(t)?t:t.layers).find(({tier:e})=>e===`user`)?.dir,c=[{scope:`project`,dir:us(n)},...s?[{scope:`user`,dir:s}]:[]];for(let{scope:e,dir:t}of c){let s=[_(t,`${i.name}.md`),...xs.map(({extension:e})=>_(t,`${i.name}${e}`))],c=a.trace.layers.find(e=>s.includes(e.path));o.places.push({scope:e,path:`${e===`project`?y(n,t):r(t)}/${i.name}.<ext>`,reaches:Ls[e],status:c?.file?c.outcome:`empty`,sections:[]})}return o}const zs={description:"Directory the project tier is read from, and each folder above it up to the repository root; a project write goes to its `.agents/references/`. Defaults to the current directory.",type:N.string().optional()},Bs={description:`Add the trace: every layer checked, with its outcome, and how the result was built.`,type:N.boolean().optional()},Vs={description:"The calling skill's folder: its `references/<name>.default.md` joins as the `default` tier.",type:N.string().optional()};function Hs(e){return(t,n)=>bs({root:t.root??process.cwd(),home:n,platform:process.platform,env:process.env,plugin:e,defaultSkill:t.default})}function Us(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``&&!(Array.isArray(e)&&!e.length)))}function Ws(e,t){throw se(e)?e:(process.stderr.write(`error: ${e instanceof Error?e.message:t}\n`),j.reported(A.error))}function Gs(e){throw process.stderr.write(`error: usage: ${e}\n`),j.reported(A.usage)}function Ks(e,t){let n=ar(e,t);throw n!==void 0&&process.stdout.write(n),j.reported(A.error)}function qs(e){for(let{code:t,message:n}of e)process.stderr.write(`warning: ${t}: ${n}\n`)}function Js(e,t){let n=e=>G(t,e);return{...e,contributions:e.contributions.map(e=>({...e,path:n(e.path)})),layers:e.layers.map(e=>({...e,path:n(e.path)}))}}function Ys(e,t){let n=Js(e.trace,t),r=[`${e.name}: ${e.status}; stack: ${n.stack.join(` → `)||`none`}; built by ${n.builtBy}; harnesses: ${n.harnesses.join(`, `)||`none detected`}`];e.message&&r.push(` ${e.message}`),r.push(`layers:`);for(let e of n.layers){let t=e.plugin?` ${e.plugin}`:e.skill?` ${e.skill}`:``,n=e.operation?`; ${e.operation} from ${e.operationFrom}`:``;r.push(` ${e.tier}${t} ${e.path}: ${e.outcome}${n}`)}return`${r.join(`
|
|
174
|
+
`)}\n`}function Xs(e){let t=e.options?.length?`; options: ${e.options.join(`, `)}`:``;return`${e.name}: ${e.message}${t}`}function Zs(e,t,{metadata:n,trace:r}){return e.status===`found`&&!e.warnings.length&&!n&&!r&&e.format===`markdown`?e.content:Us({name:e.name,status:e.status,content:e.content,format:e.format===`markdown`?void 0:e.format,code:e.code,options:e.options,metadata:n?e.metadata:void 0,warnings:e.warnings,trace:r?Js(e.trace,t):void 0})}const Qs={toon:e=>Tn(e,`toon`),json:e=>Tn(e,`json`)};function $s(e){if(e.length===1){let[t]=e;return t.content===void 0?void 0:R(t.content)}return R(e.map(e=>e.content===void 0?`<reference name="${e.name}" status="${e.status}" />`:`<reference name="${e.name}">\n${e.content}</reference>`).join(`
|
|
175
|
+
|
|
176
|
+
`))}function ec(e){return M({name:`load`,description:`Print one or more references, each composed from its contributions as their extends and merge declare.`,arguments:[{name:`names`,description:"Reference names, without the `.md` extension; `<plugin>/<name>` builds that plugin’s own stack.",type:N.array(N.string())}],options:{root:zs,default:Vs,metadata:{description:`Make every entry a record with its status and composed frontmatter.`,type:N.boolean().optional()},trace:Bs},async run(t){let n=this.format;t.names.length||Gs(`name at least one reference.`);try{let r=T(),i=await e(t,r),a=e=>G(r,e),o=t.names.map(e=>Ms(ws(e),i,{display:a})),s=o.every(e=>e.status===`found`);if(n===`text`){for(let e of o)qs(e.warnings),e.status!==`found`&&process.stderr.write(`error: ${e.code}: ${Xs(e)}\n`),t.trace&&process.stderr.write(Ys(e,r));let e=$s(o);if(e===void 0)throw j.reported(A.error);return s?e:Ks(e,n)}let c={metadata:!!t.metadata,trace:!!t.trace},l=L(o.map(e=>Zs(e,r,c)),{render:Qs});return s?l:Ks(l,n)}catch(e){return Ws(e,`Reference lookup failed.`)}}})}function tc(e){return M({name:`names`,description:`List every reference name, one row each, with its description, and its status when not found. A pattern keeps only the names it matches exactly.`,arguments:[{name:`pattern`,description:"Exact name pattern, where `*` stands for any run of characters, such as `project-tracker.capabilities.*`.",type:N.string().optional()}],options:{root:zs,trace:{...Bs,description:`Add one row per name per layer holding it, with its outcome.`}},async run(t){try{let n=T(),r=e=>G(n,e),i=Is(await e(t,n),{display:r,pattern:t.pattern}),a=Us({references:i.references.length?i.references.map(e=>Us({name:e.name,format:e.format,status:e.status===`found`?void 0:e.status,options:e.options})):t.pattern?`0 references match "${t.pattern}"`:`0 references — no layer holds one`});return t.trace&&(a.layers=i.layers.map(e=>Us({...e,path:r(e.path)}))),i.warnings.length&&(a.warnings=i.warnings),L(a)}catch(e){return Ws(e,`Reference listing failed.`)}}})}function nc(e){return M({name:`where`,description:`Give the project and user files a customization or a selection of a reference is written to, who each reaches, and the heading paths of the document below each.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:N.string()}],options:{root:zs,default:Vs,trace:{...Bs,description:`Add every layer checked, with its outcome.`}},async run(t){let n=this.format;try{let r=T(),i=e=>G(r,e),a=Rs(t.name,await e(t,r),{root:b(t.root??process.cwd()),display:i}),o=Us({name:a.name,status:a.status,places:a.places.map(e=>Us(e)),options:a.options,layers:t.trace?a.layers.map(e=>({...e,path:i(e.path)})):void 0,warnings:a.warnings});n===`text`&&qs(a.warnings);let s=L(o);return a.status===`invalid`?(process.stderr.write(`error: reference-invalid: ${ws(t.name).invalid}\n`),Ks(s,n)):s}catch(e){return Ws(e,`Reference placement lookup failed.`)}}})}function rc({plugin:e}={}){let t=Hs(e);return{load:ec(t),names:tc(t),where:nc(t)}}const ic=[`replace`,`patch`,`combine`,`remove`];function ac(e){return ic.includes(e)}const oc=/^---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;function K(e,t){let n=oc.exec(e);if(!n)return{metadata:{},body:e};let r=e.slice(n[0].length);try{let e=(0,ao.parse)(n[1]);if(e==null)return{metadata:{},body:r};if(z(e))return{metadata:e,body:r}}catch{}return t(`frontmatter-invalid`,`frontmatter is not a YAML mapping; it is ignored`),{metadata:{},body:r}}function sc(e,t){let n=e.merge;if(n!==void 0)return ac(n)?n:(t(`merge-unknown`,`unknown merge "${String(n)}"; read as patch`),`patch`)}function cc(e){return pc(e).trim().length>0}const lc=/^\s*<!--\s*merge:\s*([\w-]*)\s*-->\s*$/,uc=/^ {0,3}(#{1,6})(?:[ \t]+(.*?))?(?:[ \t]+#+)?[ \t]*$/,dc=/^ {0,3}(`{3,}|~{3,})/;function fc(){let e;return t=>{if(e)return RegExp(`^ {0,3}${e[0]==="`"?"`":`~`}{${e.length},}\\s*$`).test(t)&&(e=void 0),!0;let n=dc.exec(t);return n?(e=n[1],!0):!1}}function pc(e){let t=fc();return e.split(`
|
|
177
|
+
`).filter(e=>t(e)||!lc.test(e)).join(`
|
|
178
|
+
`)}function mc(e){return e.trim().replace(/\s+/g,` `).toLowerCase()}function hc(e){let t=fc(),n;for(let r of e.split(`
|
|
179
|
+
`)){if(t(r))continue;let e=uc.exec(r);e&&(n=Math.min(n??6,e[1].length))}return n}function gc(e,t){let n=hc(e),r={top:n,preamble:[],children:[]},i=[],a=fc(),o;for(let s of e.split(`
|
|
180
|
+
`)){let e=a(s),c=e?null:uc.exec(s);if(c){let e=c[1].length,t={depth:e-(n??e),level:e,title:(c[2]??``).trim(),heading:s.trimEnd(),marker:void 0,text:[],children:[]};for(;(i.at(-1)?.level??0)>=e;)i.pop();(i.at(-1)?.children??r.children).push(t),i.push(t),o=t;continue}if(o&&!e){if(!s.trim())continue;let e=lc.exec(s);if(e){let n=e[1];ac(n)?o.marker=n:(t(`marker-unknown`,`unknown merge "${n}" on "${o.title}"; read as patch`),o.marker=`patch`),o=void 0;continue}}o=void 0,(i.at(-1)?.text??r.preamble).push(s)}return r}function _c(e){let t=0,n=e.length;for(;t<n&&!e[t].trim();)t++;for(;n>t&&!e[n-1].trim();)n--;return e.slice(t,n)}function vc(){return{top:void 0,preamble:[],preambleSources:[],children:[],removed:[],joined:!1,preambleJoined:!1}}function yc(e,t){return e?`${e} > ${t}`:t}function bc(e,t,{warn:n}){let r=/* @__PURE__ */ new Set;for(let i of e){let e=mc(i.title);r.has(e)&&n(`heading-repeated`,`heading path "${yc(t,i.title)}" appears more than once; the first is matched`),r.add(e),bc(i.children,yc(t,i.title),{warn:n})}}function xc(e,t,{warn:n}){n(`marker-unmatched`,`"<!-- merge: ${e.marker} -->" on "${yc(t,e.title)}" matches no section below`)}function Sc(e,t,n,r){let i=yc(n,e.title),a=e.children.flatMap(e=>(e.marker&&xc(e,i,r),e.marker===`remove`?[]:[Sc(e,e.marker??t,i,r)])),o=_c(e.text);return{depth:e.depth,title:e.title,heading:e.heading,level:e.level,text:o,sources:o.length?[{contribution:r.label,operation:t}]:[],children:a}}function Cc(e,t){return e.length&&t.length?[...e,``,...t]:[...e,...t]}function wc(e,t,n,r,i){let a=[...e],o=[],s=/* @__PURE__ */ new Set;for(let c of t){let t=c.marker??n,l=mc(c.title),u=s.has(l)?-1:e.findIndex(e=>mc(e.title)===l);if(s.add(l),u===-1){if(i.matchedOnly)continue;c.marker&&xc(c,r,i),t!==`remove`&&o.push(Sc(c,t,r,i));continue}let d=e[u],f=yc(r,d.title);if(t===`remove`){a[u]=void 0,i.composed.removed.push({path:f,by:i.label});continue}if(t===`replace`){a[u]={...Sc(c,`replace`,r,i),depth:d.depth};continue}let p=_c(c.text),m=p.length?[{contribution:i.label,operation:t}]:[];if(t===`combine`){let e=!!(p.length&&d.text.length);e&&(i.composed.joined=!0),a[u]={...d,...e?{joined:!0}:{},text:Cc(d.text,p),sources:[...d.sources,...m],children:wc(d.children,c.children,`combine`,f,i)};continue}let{joined:h,...g}=d;a[u]={...p.length?g:d,text:p.length?p:d.text,sources:p.length?m:d.sources,children:wc(d.children,c.children,`replace`,f,i)}}return[...a.filter(e=>e!==void 0),...o]}function Tc(e,t,n,r,i,{matchedOnly:a=!1}={}){let o=gc(t,i),s=n===`replace`?vc():e,c={...s,removed:[...s.removed]},l={label:r,warn:i,composed:c,matchedOnly:a};bc(o.children,``,l);let u=a&&!s.preamble.length?[]:_c(o.preamble);return n===`combine`?(u.length&&s.preamble.length&&(c.joined=!0,c.preambleJoined=!0),c.preamble=Cc(s.preamble,u),u.length&&(c.preambleSources=[...s.preambleSources,{contribution:r,operation:n}])):u.length&&(c.preamble=u,c.preambleSources=[{contribution:r,operation:n}],c.preambleJoined=!1),c.top=s.top??o.top,c.children=wc(s.children,o.children,n,``,l),c}function Ec(e){let t=[],n=!1,r=e=>{e&&!n&&(t.push(`Where these sections conflict, the later text wins.`),n=!0)};e.preamble.length&&(r(e.preambleJoined),t.push(e.preamble.join(`
|
|
181
|
+
`)));let i=e.top??1,a=e=>{let n=Math.min(6,i+e.depth),o=n===e.level?e.heading:`${`#`.repeat(n)} ${e.title}`.trimEnd();r(e.joined),t.push(e.text.length?`${o}\n\n${e.text.join(`
|
|
182
|
+
`)}`:o);for(let t of e.children)a(t)};for(let t of e.children)a(t);return t.length?`${t.join(`
|
|
183
|
+
|
|
184
|
+
`)}\n`:``}function Dc(e){let t=[];e.preambleSources.length&&t.push({path:`(before the first heading)`,sources:e.preambleSources});let n=(e,r)=>{let i=yc(r,e.title);t.push({path:i,sources:e.sources});for(let t of e.children)n(t,i)};for(let t of e.children)n(t,``);return t}function Oc(e){let t=[],n=(e,r)=>{let i=yc(r,e.title);t.push(i);for(let t of e.children)n(t,i)};for(let t of gc(e,()=>{}).children)n(t,``);return t}function kc(e,t){let n=hc(e),r=fc(),i=[];for(let t of e.split(`
|
|
185
|
+
`)){let e=r(t)?null:uc.exec(t);if(e&&e[1].length===n){i.push({key:mc(e[2]??``),lines:[t]});continue}i.at(-1)?.lines.push(t)}let a=new Map(t.map(e=>[mc(e.heading),e])),o=/* @__PURE__ */ new Set,s=[];for(let e of i){let t=a.get(e.key);if(!t||o.has(e.key))continue;o.add(e.key);let[n,...r]=e.lines;if(t.merge===void 0){s.push(n,...r);continue}let i=r.findIndex(e=>e.trim()),c=i!==-1&&lc.test(r[i])?r.filter((e,t)=>t!==i):r;s.push(n,`<!-- merge: ${t.merge} -->`,...c)}let c=t.filter(e=>!o.has(mc(e.heading))).map(({heading:e})=>e);return{body:s.join(`
|
|
186
|
+
`),missing:c}}const Ac={"reference-missing":{kind:`status`,when:`no tier holds the name, or the plugin a qualified name asks for is not installed (UC1.1)`},"reference-removed":{kind:`status`,when:"a `missing` name a `remove` turned off (UC1.1, R49)"},"reference-ambiguous":{kind:`status`,when:`contributions that cannot be put in one order, or a name two names list as an alias (UC1.2, R98)`},"reference-invalid":{kind:`status`,when:`not a name (UC1.3, R1)`},"frontmatter-invalid":{kind:`warning`,when:`malformed frontmatter (R105)`},"merge-unknown":{kind:`warning`,when:"an unknown `merge` value (R7)"},"marker-unknown":{kind:`warning`,when:`an unknown merge marker (R7)`},"marker-unmatched":{kind:`warning`,when:`an explicit marker that matches nothing below (R7)`},"heading-repeated":{kind:`warning`,when:`a document repeating a heading (R7)`},"remove-body-ignored":{kind:`warning`,when:"a `remove` with a body (R49)"},"extends-invalid":{kind:`warning`,when:"a malformed `extends` (R106)"},"extends-self":{kind:`warning`,when:`a plugin listing itself (R54)`},"extends-step-missing":{kind:`warning`,when:`a step that cannot be used (R55)`},"extends-all-missing":{kind:`warning`,when:`every step cannot be used (R55)`},"extends-not-used":{kind:`warning`,when:"a lower `extends` that builds a different stack (R53); picks written under a managed `extends` that builds it (R109)"},"section-not-held":{kind:`warning`,when:"a `sections` entry the plugin does not hold (R52)"},"default-not-selected":{kind:`warning`,when:"a plugin answering over the default with no `extends` naming either, and no own `extends` of the plugin naming `default` (R56)"},"plugin-not-selected":{kind:`warning`,when:"a plugin holding the name that the `repo` or `user` `extends` building the stack neither places nor declines (R113)"},"default-folder-missing":{kind:`warning`,when:"a `--default` folder that does not exist (R41)"},"default-in-tier":{kind:`warning`,when:"a `<name>.default.md` in a tier folder (R51)"},"file-ignored":{kind:`warning`,when:`a second file for a name in one folder, one under an older name beside the new name's included (R67, R97)`},"format-mismatch":{kind:`warning`,when:`a Markdown contribution above a non-Markdown one (R68)`},"metadata-ignored":{kind:`warning`,when:"a misplaced metadata file, or a body, `merge`, or `implements` in one (R94)"},"project-section-key-ignored":{kind:`warning`,when:"`merge`, `extends`, `implements`, or `aliases` in a project section, or dropped from one `create --in --template` writes (R27, R110)"},"interface-not-composed":{kind:`warning`,when:"`extends`, `merge`, or a higher copy on an interface document (R14)"},"interface-check":{kind:`warning`,when:`a loaded document failing its interface check (R37)`},"base-moved":{kind:`warning`,when:"`check` on a plugin or default file whose extended base has a newer version (R86)"},"reference-stale":{kind:`warning`,when:`a generated document or project section with a changed or missing source (R101)`},"reference-renamed":{kind:`warning`,when:`a name or file under an older name, or an interface's older id (R96, R97)`},"alias-not-used":{kind:`warning`,when:`an alias a name holds as its own (R98)`},"alias-invalid":{kind:`warning`,when:`an invalid or misplaced alias (R96)`},"project-section-not-markdown":{kind:`warning`,when:`a Markdown project section for a name whose main document is not Markdown, or a non-Markdown file in a project folder (R99)`},"reference-hidden":{kind:`warning`,when:"a file hidden by a `replace` or `remove` above it: one `create` or `customize` wrote (R26), or one `check` finds (R112)"},"repo-hides-user":{kind:`warning`,when:"a `user` file this repository's `repo` contribution hides (R26, R112)"},"root-missing":{kind:`refused`,when:"a `--root` that does not exist (R12)"},"file-unreadable":{kind:`refused`,when:"a `--request` or `--body` file that cannot be read (R81, R82)"},"folder-invalid":{kind:`refused`,when:"a `--plugin` or `--default` folder that does not qualify (R24)"},"file-exists":{kind:`refused`,when:"`create` on a file with a body, or where the target folder holds a file answering the name in another form (R60)"},"extends-replace":{kind:`refused`,when:"a `--plugin` or `--default` file extending a plugin with `replace` (R103)"},"interface-invalid":{kind:`refused`,when:"`--implements` with an unknown interface (R28, R111)"},"interface-unknown":{kind:`refused`,when:"`implementations` of an unknown interface (R35)"},"template-title":{kind:`refused`,when:`a title template (R32)`},"template-invalid":{kind:`refused`,when:`an unreadable template, or one whose frontmatter is not a mapping (R32)`},"extends-file-invalid":{kind:`refused`,when:"an `--extends-file` that is unreadable or not a YAML `extends` list (R79)"},"step-invalid":{kind:`refused`,when:"a step neither `default` nor a plugin holding the name (R79)"},"no-selection":{kind:`notice`,when:"`--extends none` with no `extends` there: a no-op (R80)"},"body-not-generated":{kind:`refused`,when:"`--request` on a body that records no request (R82)"},"pick-required":{kind:`refused`,when:"`--request` without `--extends` on an `ambiguous` name (R82)"},"name-outside-interface":{kind:`refused`,when:"`customize --implements` on a name outside the interface's namespace (R111)"},"implements-required":{kind:`refused`,when:"`--request` without `--implements` on a `missing` name under a found interface's namespace (R111)"},"in-not-markdown":{kind:`refused`,when:"`create --in` or `customize --in` for a name whose main document is not Markdown, which has no project sections (R82)"},"in-folder-missing":{kind:`refused`,when:"`--in` on `create`, `customize`, or `delete` naming a folder that does not exist (J8)"},"in-folder-ignored":{kind:`refused`,when:"`--in` on `create`, `customize`, or `delete` naming a folder git ignores (J8)"},"no-file":{kind:`notice`,when:"`delete` with no file there: a no-op (R30)"},"name-missing":{kind:`usage`,when:`a command that needs a name, given none (UC1.7)`},"name-invalid":{kind:`usage`,when:"a write given a string that is not a name, such as `../x` (J1, R1)"},"reference-qualified":{kind:`usage`,when:`a qualified name given to a write (R25)`},"query-missing":{kind:`usage`,when:"`search` with an empty query (UC3.2)"},"change-missing":{kind:`usage`,when:"`customize` with neither `--extends` nor `--request` (R82)"},"options-conflict":{kind:`usage`,when:"flags that exclude each other, such as two of `--scope`, `--in`, `--plugin`, `--default` on `create` and `delete`, `--scope` with `--in` on `customize`, or `--merge` or `--extends` with `--in` (R24, R27, R82)"},"options-missing":{kind:`usage`,when:"a flag given without the one it needs: `--request` without `--body`, or the reverse (R82)"},"option-invalid":{kind:`usage`,when:"a flag given a value it does not accept, such as an unknown `--merge` operation (R27)"},"in-not-below-root":{kind:`usage`,when:"`--in` naming the root or a folder outside it (R24)"},"remove-with-template":{kind:`usage`,when:"`--merge remove` with `--template` (R27)"},"template-with-implements":{kind:`usage`,when:"`--template` with `--implements` (R28)"}};var q=class extends Error{name=`ReferenceError`;code;usage;details;help;constructor(e,t,{details:n={},help:r}={}){super(t),this.code=e,this.usage=Ac[e].kind===`usage`,this.details=n,this.help=r===void 0?[]:typeof r==`string`?[r]:[...r]}};function jc(e){let t=e.sections.map(({heading:e,holds:t})=>`## ${e}\n\n**Unsupported.** ${t??`Replace this line with the section, or say in one sentence why it is not supported.`}\n`);return Nc(`---\ndescription: What this ${e.id} implementation covers, and when an agent should read it.\nimplements: ${e.id}@${e.version}\n---\n\n${t.join(`
|
|
187
|
+
`)}`,`the ${e.id} interface`)}function Mc(e){if(e===void 0)return Nc(`---
|
|
188
188
|
description: What this reference covers, and when an agent should read it.
|
|
189
189
|
tags: [topic]
|
|
190
190
|
---
|
|
@@ -192,29 +192,42 @@ tags: [topic]
|
|
|
192
192
|
## Overview
|
|
193
193
|
|
|
194
194
|
Write the guidance here. Give each topic its own top-level \`##\` section.
|
|
195
|
-
`,`the default template`);let t;try{t=o(e,`utf8`)}catch(t){throw
|
|
196
|
-
`:``;return`---\n${i.toString({lineWidth:0,flowCollectionPadding:!1})}---\n${a}${r}`}
|
|
197
|
-
`)}\n`}function Pl(e){let t=e.options?.length?`; options: ${e.options.join(`, `)}`:``;return`${e.name}: ${e.message}${t}`}function Fl(e,t,{metadata:n,trace:r}){return e.status===`found`&&!e.warnings.length&&!n&&!r&&e.format===`markdown`?e.content:Q({name:e.name,status:e.status,content:e.content,format:e.format===`markdown`?void 0:e.format,code:e.code,options:e.options,metadata:n?e.metadata:void 0,warnings:e.warnings,trace:r?Ml(e.trace,t):void 0})}const Il={toon:e=>Sn(e,`toon`),json:e=>Sn(e,`json`)};function Ll(e){if(e.length===1){let[t]=e;return t.content===void 0?void 0:z(t.content)}return z(e.map(e=>e.content===void 0?`<reference name="${e.name}" status="${e.status}" />`:`<reference name="${e.name}">\n${e.content}</reference>`).join(`
|
|
195
|
+
`,`the default template`);let t;try{t=o(e,`utf8`)}catch(t){throw new q(`template-invalid`,`cannot read the template ${e}: ${t.message}`,{details:{path:e}})}return Nc(t,`the template ${e}`)}function Nc(e,t){let n=!0,{metadata:r,body:i}=K(e,()=>{n=!1});if(!n)throw new q(`template-invalid`,`${t} has frontmatter that is not a YAML mapping.`);return{content:e,metadata:r,body:i}}function Pc({body:e}){let t=gc(e,()=>{}),[n]=t.children;return t.children.length===1&&n?.children.length?n.heading.trim():void 0}function Fc({metadata:e}){return typeof e.description==`string`&&e.description.trim().length>0}function Ic(e,t){let n=oc.exec(e),r=n?e.slice(n[0].length):e,i=(0,ao.parseDocument)(n?n[1]:``);for(let[e,n]of Object.entries(t))if(n===void 0)(0,ao.isMap)(i.contents)&&i.delete(e);else{let t=Array.isArray(n)&&n.every(e=>typeof e!=`object`||!e),r=i.createNode(n,{flow:t});i.set(e,r)}if(!i.contents?.items?.length)return r.replace(/^(?:[ \t]*\r?\n)+/,``);let a=!n&&r.trim()?`
|
|
196
|
+
`:``;return`---\n${i.toString({lineWidth:0,flowCollectionPadding:!1})}---\n${a}${r}`}const Lc=[{extension:`.json`,format:`json`},{extension:`.yaml`,format:`yaml`},{extension:`.yml`,format:`yaml`},{extension:`.toml`,format:`toml`},{extension:`.txt`,format:`txt`}];function Rc(e){return Lc.find(({extension:t})=>e.endsWith(t))?.format??`markdown`}function zc(e){return e===`managed`||e===`repo`||e===`project`||e===`user`}function Bc(e){return!e.file||e.outcome!==`used`&&e.outcome!==`stale`?!1:e.operation===`remove`||e.operation===`replace`&&!e.empty}function Vc(e){return e.tier==="default"?`default`:e.plugin??``}function Hc(e,t,n){let r=e.trace.layers,i=r.findIndex(e=>e.path===t||e.path===n),a=r[i];if(!a)return[];let o=e=>r.slice(0,e).filter(({tier:e})=>zc(e)).reverse();if(zc(a.tier))return o(i);let{stack:s}=e.trace,c=s.indexOf(Vc(a));return[...c===-1?[]:r.filter(e=>!zc(e.tier)&&s.indexOf(Vc(e))>c).sort((e,t)=>s.indexOf(Vc(e))-s.indexOf(Vc(t))),...o(r.length)]}function Uc(e,t=e=>e){return`${e.tier}${e.plugin?` ${e.plugin}`:``} ${t(e.path)} (${e.operation})`}function Wc(e,t,n){return Hc(e,t,n).find(Bc)}function Gc(e){return e.trace.layers.find(e=>e.tier===`managed`&&Bc(e))}function Kc(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function qc(e){if(typeof e==`string`)return e.trim()?e.trim():void 0;if(typeof e==`number`)return String(e)}function Jc(e){if(!Kc(e))return;let t=qc(e.plugin),n=qc(e.version),r=qc(e.default);if(r!==void 0)return{default:r,...t===void 0?{}:{plugin:t},...t!==void 0&&n!==void 0?{version:n}:{}};if(t!==void 0)return n===void 0?{plugin:t}:{plugin:t,version:n}}function Yc(e,t){let n={},r=e.request;typeof r==`string`&&r.trim()&&(n.request=r);let i=e.sources;if(i==null)return n;if(!Array.isArray(i))return t?.(`frontmatter-invalid`,"`sources` is not a list; it is read as recording no sources"),n;let a=i.flatMap(e=>{let n=Jc(e);return n||t?.(`frontmatter-invalid`,"a source in `sources` is not {plugin, version} or {default, plugin, version}; it is left out"),n?[n]:[]});return a.length&&(n.sources=a),n}function Xc(e){return e!==void 0&&Yc(e).request!==void 0}function Zc(e,{tier:t}){let n=Array.isArray(e)?e:e.layers,r=Array.isArray(e)?n.flatMap(({tier:e,plugin:t,version:n,origin:r,skipped:i})=>e===`plugin`&&t!==void 0&&!i?[{plugin:t,version:n,origin:r}]:[]):e.plugins??n.flatMap(({tier:e,plugin:t,version:n,origin:r,skipped:i})=>e===`plugin`&&t!==void 0&&!i?[{plugin:t,version:n,origin:r}]:[]),i=/* @__PURE__ */ new Map;for(let e of r)(t!==`user`||e.origin!==`dependency`)&&(i.has(e.plugin)||i.set(e.plugin,e));let a=n.flatMap(({tier:e,skill:t,skipped:n})=>e==="default"&&t!==void 0&&!n?[t]:[]),o=Array.isArray(e)?void 0:e.skills;return{plugins:i,skills:o&&!o.unverified?/* @__PURE__ */ new Set([...a,...o.skills.map(({name:e})=>e)]):void 0}}function Qc(e,{plugins:t,skills:n}){return e.map(e=>{let r={status:`current`};if(`default`in e&&(r.default=e.default),e.plugin!==void 0&&(r.plugin=e.plugin),e.version!==void 0&&(r.recorded=e.version),e.plugin===void 0)return`default`in e&&n&&!n.has(e.default)&&(r.status=`missing`),r;let i=t.get(e.plugin);return i?(i.version!==void 0&&(r.installed=i.version),e.version!==void 0&&e.version!==i.version&&(r.status=`changed`),r):(r.status=`missing`,r)})}function $c(e){let t=e.default===void 0?`plugin ${e.plugin}`:`the default of ${e.default}`;return e.status===`missing`?e.plugin!==void 0&&e.default!==void 0?`${t} (plugin ${e.plugin}) is not installed`:`${t} is not installed`:`${t}${e.default===void 0?``:` (plugin ${e.plugin})`} is ${e.installed??`installed with no version`}, recorded ${e.recorded}`}function el(e,t){return`it is stale: ${t.filter(({status:e})=>e!==`current`).map($c).join(`; `)}. Customize mode revises "${e}" from its recorded request`}function tl(e,t,n){let r=Yc(e,n);if(r.sources===void 0&&r.request===void 0)return;let i=Qc(r.sources??[],t),a={sources:i,stale:i.some(({status:e})=>e!==`current`)};return r.request!==void 0&&(a.request=r.request),a}function nl(e,t,n){return e.flatMap(e=>{if(e==="default"){if(!n)return[];let e=n.plugin===void 0?void 0:t.plugins.get(n.plugin);return e?[e.version===void 0?{default:n.skill,plugin:e.plugin}:{default:n.skill,plugin:e.plugin,version:e.version}]:[{default:n.skill}]}let r=t.plugins.get(e);return r?[r.version===void 0?{plugin:e}:{plugin:e,version:r.version}]:[]})}function rl(e){let t={};return e.sources?.length&&(t.sources=e.sources.map(e=>({...e}))),e.request!==void 0&&(t.request=e.request.endsWith(`
|
|
197
|
+
`)?e.request:`${e.request}\n`),t}const il=/^[a-z0-9]+(?:[-.][a-z0-9]+)*$/i,al=`.default`;function ol(e){if(!e.trim())throw new q(`name-missing`,`name a reference.`,{help:"Run `reference list` for every name."})}function J(e){let t=t=>({raw:e,name:e,invalid:t});if(e.endsWith(`.md`))return t(`"${e}" names a file. Ask for the reference by name, without the .md extension.`);let n=Lc.find(t=>e.endsWith(t.extension));if(n)return t(`"${e}" names a file. Ask for the reference by name, without the ${n.extension} extension.`);let r=e.split(`/`);if(r.length>2||e.includes(`\\`))return t(`"${e}" is a path. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/".`);let[i,a]=r,o=a??i,s=a===void 0?void 0:i;return o.endsWith(`.default`)?t(`"${e}" names a skill's default file. Ask for "${o.slice(0,-8)}"; the default joins when its skill loads it.`):o.endsWith(`.meta`)?t(`"${e}" names a metadata file, which never answers a name. Ask for "${o.slice(0,-5)}".`):!il.test(o)||s!==void 0&&!il.test(s)?t(`"${e}" is not a reference name. A name is letters, digits, hyphens, and dots, optionally after "<plugin>/", where <plugin> is a plugin's manifest name.`):s===void 0?{raw:e,name:o}:{raw:e,name:o,plugin:s}}const sl=[`merge`,`implements`];function cl(e,t){return`${t}${e.tier==="default"?al:``}.meta.md`}function ll(e,t,n,{without:r,display:i,warnAt:a,read:o}){let s=cl(e,t),c=_(e.dir,s),l=c===r?void 0:o(c);if(l===void 0)return;let u=a(i(c));if(n===`markdown`){u(`metadata-ignored`,`it is ignored: a metadata file goes beside a non-Markdown file, and a Markdown contribution carries its keys in its own frontmatter`);return}let{metadata:d,body:f}=K(l,u),p=d.extends!==void 0;if(n===void 0&&!p){u(`metadata-ignored`,`it is ignored: no non-Markdown file for "${t}" is beside it, and it writes no extends to select one`);return}cc(f)&&u(`metadata-ignored`,`its body is ignored: a metadata file holds frontmatter only`);let m={...d};for(let e of sl)e in m&&(delete m[e],u(`metadata-ignored`,e===`merge`?"`merge` in it is ignored: a non-Markdown contribution always replaces what is below it":"`implements` in it is ignored: an interface's sections are Markdown"));return{path:c,file:s,frontmatter:d,metadata:m,selects:p}}function Y(e,t){if(e===void 0)return;let n=e=>{t(`extends-invalid`,`\`extends\` ${e}; it is read as not written`)},r=typeof e==`string`?[e]:Array.isArray(e)?e:void 0;if(!r)return n(`is not a list of plugins`);let i=[];for(let e of r){let r=dl(e,t);if(typeof r==`string`)return n(r);i.push(r)}return i}const ul=[`merge`,`extends`,`sections`];function dl(e,t){if(typeof e==`string`)return il.test(e)?{target:e}:`names "${e}", which is not a plugin name or default`;if(!z(e)||Object.keys(e).length!==1)return`holds ${JSON.stringify(e)}, which is not a step`;let[n,r]=Object.entries(e)[0];if(!il.test(n))return`names "${n}", which is not a plugin name or default`;if(r==null)return{target:n};let i={target:n};if(typeof r==`string`)return i.merge=pl(r,n,t),i;if(!z(r)||Object.keys(r).some(e=>!ul.includes(e)))return`gives "${n}" keys other than merge, extends, and sections`;if(r.merge!==void 0&&(i.merge=pl(r.merge,n,t)),r.extends!==void 0){let e=Y(r.extends,t);if(!e)return`gives "${n}" a malformed extends`;i.extends=e}if(r.sections!==void 0){let e=fl(r.sections,n,t);if(!e)return`gives "${n}" sections that are not a list of headings`;i.sections=e}return i}function fl(e,t,n){let r=typeof e==`string`?[e]:Array.isArray(e)?e:void 0;if(!r)return;let i=[];for(let e of r){if(typeof e==`string`&&e.trim()){i.push({heading:e.trim()});continue}if(!z(e)||Object.keys(e).length!==1)return;let[r,a]=Object.entries(e)[0];if(!r.trim())return;let o={heading:r.trim()};a!=null&&(o.merge=pl(a,`${t} > ${r}`,n)),i.push(o)}return i}function pl(e,t,n){return ac(e)?e:(n(`merge-unknown`,`unknown merge "${String(e)}" on the step ${t}; read as patch`),`patch`)}function ml(e,t,n,r,i){let a={entries:[],missing:[],allMissing:!1,replaced:[]},o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=(e,t,n)=>{let r=[];for(let o of e){if(o.target===n){i(`extends-self`,`${t} lists itself in its extends; that entry is ignored`);continue}r.at(-1)?.target!==o.target&&(r.some(({target:e})=>e===o.target)&&!a.ambiguous&&(a.ambiguous={cause:`repeat`,message:`${t}'s extends lists ${o.target} at two places`}),r.push(o))}return r},l=c(e,t),u=new Set(l.map(({target:e})=>e)),d=(e,l,f)=>{if(a.ambiguous||o.has(e.target))return;if(s.has(e.target)){n===`plugins`&&(a.ambiguous={cause:`cycle`,message:`the plugins' own extends form a cycle: ${[...f,e.target].join(` → `)}`});return}if(!l&&u.has(e.target))return;let p=r(e.target);if(`reason`in p){a.missing.push({target:e.target,reason:p.reason}),e.target!=="default"&&i(`extends-step-missing`,`the step ${e.target} in ${f.at(-1)??t}'s extends ${p.reason}; it is skipped`);return}s.add(e.target);let m=p.steps??[];if(e.extends){let t=new Set(e.extends.map(({target:e})=>e));for(let{target:n}of m)t.has(n)||a.replaced.push({target:n,step:e.target})}for(let t of c(e.extends??m,`plugin ${e.target}`,e.target))d(t,!1,[...f,e.target]);s.delete(e.target);let h=e.merge??p.merge??`patch`,g=e.merge?`step`:p.merge?`contribution`:`default`,_={target:e.target,contribution:p,operation:h,from:g};e.sections&&(_.sections=e.sections),a.entries.push(_),o.add(e.target)};for(let e of l)d(e,!0,[]);return a.allMissing=l.length>0&&l.every(({target:e})=>!o.has(e))&&l.some(({target:e})=>e!=="default"),a}const hl=()=>{};function gl(e,t,n,r,i,a){let o;for(let n of t){if(!n.steps)continue;if(e.plugin!==void 0){n.entry.extendsOutcome=`not used (qualified name)`;continue}if(o){ml(n.steps,n.label,`written`,r,hl).entries.map(({target:e})=>e).join(` `)!==o.targets&&(n.entry.extendsOutcome=`not used (${o.builder.label}'s extends builds the stack)`,a(`extends-not-used`,`${n.label} builds a different stack from ${o.builder.label}, whose extends is used`));continue}let t=ml(n.steps,n.label,`written`,r,a);if(t.ambiguous)return{status:`ambiguous`,...t.ambiguous};if(t.allMissing){n.entry.extendsOutcome=`not used (every step is missing)`,a(`extends-all-missing`,`every step in ${n.label}'s extends is missing; it is read as not written`);continue}o={entries:t.entries,builtBy:n.label,replaced:t.replaced,replacedBy:n.label,builder:n,targets:t.entries.map(({target:e})=>e).join(` `)}}if(o)return o;if(e.plugin!==void 0){let t=r(e.plugin);if(`reason`in t)return{status:`missing`,message:`the plugin ${e.plugin} ${t.reason}`};let n=ml([{target:e.plugin}],`plugin ${e.plugin}`,`plugins`,r,a);return n.ambiguous?{status:`ambiguous`,...n.ambiguous}:{entries:n.entries,builtBy:`qualified name`,replaced:[],replacedBy:``}}return _l(n,r,i,e.name,a)}function _l(e,t,n,r,i){let a=()=>n?[{target:`default`,contribution:n,operation:n.merge??`patch`,from:n.merge?`contribution`:`default`}]:[],o=[...e.keys()];if(!o.length)return{entries:a(),builtBy:`none`,replaced:[],replacedBy:``};let s=/* @__PURE__ */ new Map;for(let e of o){let n=ml([{target:e}],`plugin ${e}`,`plugins`,t,hl);if(n.ambiguous)return{status:`ambiguous`,...n.ambiguous};s.set(e,new Set(n.entries.map(({target:e})=>e).filter(t=>t!==e)))}let c=o.filter(e=>!o.some(t=>t!==e&&s.get(t)?.has(e))),l=()=>({status:`ambiguous`,cause:`unordered`,message:`the plugins ${o.join(`, `)} hold it, and no extends orders them`});if(c.length!==1)return l();let u=c[0],d=ml([{target:u}],`plugin ${u}`,`plugins`,t,i);if(d.ambiguous)return{status:`ambiguous`,...d.ambiguous};let f=new Set(d.entries.map(({target:e})=>e));if(o.some(e=>!f.has(e)))return l();let p=d.entries;if(n&&!f.has(`default`)){p.unshift(...a());let e=o.join(`, `);i(`default-not-selected`,`${o.length>1?`the plugins`:`the plugin`} ${e} ${o.length>1?`answer`:`answers`} over the default of ${n.layer.skill}, and no extends names either; run "reference customize ${r} --extends <option>..." to choose (options: ${[...o,`default`].join(`, `)})`)}return{entries:p,builtBy:u&&(e.get(u)?.steps?.length??0)>0?`plugin ${u}'s extends`:`none`,replaced:[],replacedBy:``}}function vl(e,t){if(e==null)return[];if(!Array.isArray(e))return t(`frontmatter-invalid`,"`declined` is not a list; it is read as declining nothing"),[];let n=e.filter(e=>typeof e==`string`&&il.test(e));return n.length!==e.length&&t(`frontmatter-invalid`,"an entry in `declined` is not a plugin name; it is left out"),n}function yl(e){if(!e.some(e=>e.extends!==void 0||e.sections!==void 0))return e.map(({target:e,merge:t})=>t?`${e}:${t}`:e)}function bl(e){return(e??[]).some(e=>e.target==="default"||bl(e.extends))}function xl(e){try{return o(e,`utf8`)}catch{return}}function Sl(e,t){return e.tier==="default"?[`${t}${al}.md`,...Lc.map(({extension:e})=>`${t}${al}${e}`)]:[`${t}.md`,`${t}/README.md`,...Lc.map(({extension:e})=>`${t}${e}`)]}function Cl(e,t,n){return e.tier===`plugin`?`plugin ${e.plugin}`:e.tier==="default"?`default of ${e.skill}`:`${e.tier} ${n(t)}`}function wl(e,t,n,{display:r,without:i,warnAt:a,older:o=[]}){if(e.tier!=="default"){let n=_(e.dir,`${t}${al}.md`);n!==i&&xl(n)!==void 0&&a(r(n))(`default-in-tier`,`it is ignored: a default goes in a skill's references/ folder`)}let s=e.tier===`plugin`||e.tier==="default",[c,...l]=[t,...s?[]:o].flatMap(t=>Sl(e,t).flatMap(n=>{let r=_(e.dir,n),a=r===i?void 0:xl(r);return a===void 0?[]:[{file:n,path:r,raw:a,as:t}]}));for(let e of l)a(r(e.path))(`file-ignored`,`it is ignored: ${c?.file} answers first in that folder`);let u=c?Rc(c.file):void 0,d={without:i,display:r,warnAt:a,read:xl},f=ll(e,c?.as??t,u,d);if(!c&&!f&&!s){for(let i of o)if(f=ll(e,i,void 0,d),f){Tl(n,i,t,f.path,r,a);break}}if(c&&c.as!==t&&Tl(n,c.as,t,c.path,r,a),!c)return f?El(e,n,f,r,a):void 0;let p=Cl(e,c.path,r),m=a(p);if(u!==`markdown`){Object.assign(n,{path:c.path,file:c.file,outcome:``});let t=c.raw.trim().length>0;t||(n.empty=!0);let i=f?.metadata??{};return f&&(n.frontmatter=f.frontmatter),typeof i.description==`string`&&(n.description=i.description),{layer:e,entry:n,label:p,path:c.path,metadata:i,body:c.raw,hasBody:t,whole:!0,format:u,merge:`replace`,steps:f?Y(f.metadata.extends,a(r(f.path))):void 0}}let{metadata:h,body:g}=K(c.raw,m),v=sc(h,m),y=Y(h.extends,m);Object.assign(n,{path:c.path,file:c.file,frontmatter:h,outcome:``}),typeof h.description==`string`&&(n.description=h.description);let b=cc(g);return b||(n.empty=!0),y&&!b&&v!==`remove`&&(n.selection=!0),{layer:e,entry:n,label:p,path:c.path,metadata:h,body:g,hasBody:b,format:u,whole:!1,merge:v,steps:y}}function Tl(e,t,n,r,i,a){e.alias=t,a(i(r))(`reference-renamed`,`it is filed under the older name "${t}" and applies as "${n}"; rename it to the new name`)}function El(e,t,n,r,i){let a=Cl(e,n.path,r),o=Y(n.metadata.extends,i(a));return Object.assign(t,{path:n.path,file:n.file,frontmatter:n.frontmatter,outcome:``}),typeof n.metadata.description==`string`&&(t.description=n.metadata.description),t.empty=!0,o&&(t.selection=!0),{layer:e,entry:t,label:a,path:n.path,metadata:n.metadata,body:``,hasBody:!1,format:`markdown`,whole:!1,merge:void 0,steps:o}}function Dl(e){if(e.skipped)return[];let t;try{t=s(e.dir,{withFileTypes:!0})}catch{return[]}let n=/* @__PURE__ */ new Set,r=e.tier==="default";for(let i of t){let t;if(r){let e=[`${al}.md`,...Lc.map(e=>`${al}${e.extension}`)].find(e=>i.name.endsWith(e));e&&(t=i.name.slice(0,-e.length))}else!i.isDirectory()&&[`.md`,...Lc.map(e=>e.extension)].some(e=>i.name.endsWith(e))?t=i.name.slice(0,i.name.lastIndexOf(`.`)):!i.isFile()&&xl(_(e.dir,i.name,`README.md`))!==void 0&&(t=i.name);t===void 0||J(t).invalid||n.add(t)}return[...n]}const Ol=`.interface`,kl=/^([a-z0-9]+(?:[-.][a-z0-9]+)*)@(\d+)$/i;function Al(e){return e.endsWith(`.interface`)&&e.length>10?e.slice(0,-10):void 0}function jl(e){return typeof e==`number`&&Number.isInteger(e)&&e>0}function Ml(e){return JSON.stringify(e)??String(e)}function Nl(e,t){return t===`required`||t===!0?`{heading: ${e}, required: true}`:`{heading: ${e}}`}function Pl(e){if(typeof e==`string`&&e.trim())return{heading:e.trim(),required:!1};if(!z(e))return{problems:[`section ${Ml(e)} is not a heading`]};let t=e.heading;if(t===void 0){let t=Object.keys(e),[n]=t;return t.length===1&&n?.trim()?{problems:[`section ${Ml(e)} is in the old form; write it as ${Nl(n.trim(),e[n])}`]}:{problems:[`section ${Ml(e)} has no heading`]}}if(typeof t!=`string`||!t.trim())return{problems:[`section ${Ml(e)}: heading is not text`]};let n=t.trim(),r=[],i=e.required;i!==void 0&&typeof i!=`boolean`&&r.push(`section "${n}": required is ${Ml(i)}; it is true or false`);let a=e.holds;if(a!==void 0&&(typeof a!=`string`||!a.trim()||a.trim().includes(`
|
|
198
|
+
`))&&r.push(`section "${n}": holds is ${Ml(a)}; it is one line of text`),r.length)return{problems:r};let o={heading:n,required:i===!0};return typeof a==`string`&&(o.holds=a.trim()),o}function Fl(e){return e.trim().replace(/\s+/g,` `).toLowerCase()}function Il(e,t){let n=t.interface;if(!z(n))return{problems:[n===void 0?"has no `interface:` block in its frontmatter":"`interface:` is not a mapping"]};let r=[],i=n.cardinality;i!==`one`&&i!==`many`&&r.push(`cardinality is ${JSON.stringify(i)}; it is one or many`);let a=n.version;jl(a)||r.push(`version is ${JSON.stringify(a)}; it is a positive integer`);let o=n.versions,s=jl(a)?[a]:[];o!==void 0&&(Array.isArray(o)&&o.length&&o.every(jl)?s=o:r.push(`versions is not a list of positive integers`));let c=n.sections,l=[];if(!Array.isArray(c)||!c.length)r.push(`sections is not a list of headings`);else{let e=/* @__PURE__ */ new Set;for(let t of c){let n=Pl(t);if(`problems`in n){r.push(...n.problems);continue}let i=Fl(n.heading);e.has(i)&&r.push(`section "${n.heading}" is listed more than once`),e.add(i),l.push(n)}}return r.length?{problems:r}:{value:{id:e,cardinality:i,version:a,versions:s,sections:l},problems:r}}function Ll(e){let t=e.implements;if(t===void 0)return{problems:[]};let n=Array.isArray(t)?t:[t];if(n.length!==1)return{problems:[n.length?`implements lists ${n.length} interfaces; an implementation implements one`:`implements is an empty list`]};let[r]=n,i=typeof r==`string`?kl.exec(r.trim()):null;return i?{entry:{id:i[1],version:Number(i[2])},problems:[]}:{problems:[`implements ${JSON.stringify(r)} is not <id>@<version>`]}}function Rl(e,t){return e.cardinality===`one`?t===e.id:t.startsWith(`${e.id}.`)&&t.length>e.id.length+1&&!t.endsWith(`.interface`)}function zl(e){let t=[],n=e=>{if(e.depth===0){let n=e.text.find(e=>e.trim());t.push({title:e.title,unsupported:n?.trim().startsWith(`**Unsupported.**`)??!1})}for(let t of e.children)n(t)};for(let t of gc(e,()=>{}).children)n(t);return t}function Bl(e,{name:t,version:n,content:r,accept:i=e.versions,declaredId:a=e.id}){let o=[],s=(t,n)=>o.push({check:t,interface:e.id,message:n});i.includes(n)||s(`version`,`unknown version ${n}`),Rl({id:a,cardinality:e.cardinality},t)||s(`name`,`name ${t} is not ${e.cardinality===`one`?a:`${a}.<key>`}`);let c=zl(r),l=e.sections.map(({heading:e})=>Fl(e)),u=e.sections.filter(({heading:e})=>{let t=c.find(t=>Fl(t.title)===Fl(e));return!t||t.unsupported}),d=u.filter(({required:e})=>!e).map(({heading:e})=>e),f=-1,p=``,m=/* @__PURE__ */ new Set;for(let e of c){let t=Fl(e.title),n=l.indexOf(t);n!==-1&&(m.has(t)?s(`order`,`section ${e.title} appears more than once`):n<f&&s(`order`,`section ${e.title} comes after ${p}`),m.add(t),n>f&&(f=n,p=e.title))}let h=u.filter(({required:e})=>e).map(({heading:e})=>e);return h.length&&s(`required`,`required ${h.length===1?`section`:`sections`} ${h.join(`, `)} ${h.length===1?`is`:`are`} left out or marked **Unsupported.**`),{failures:o,unsupported:d}}const Vl=/* @__PURE__ */ new WeakMap,Hl=()=>()=>{};function Ul(e){return e.tier===`plugin`?`plugin ${e.plugin}`:`default of ${e.skill}`}function Wl(e,t,n){let r=e.get(t);r?r.push(n):e.set(t,[n])}function Gl(e){return e==null?[]:Array.isArray(e)?e:[e]}function Kl(e){let t=Array.isArray(e)?void 0:e,n=t&&Vl.get(t);if(n)return n;let r=Array.isArray(e)?e:e.layers,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;for(let e of r)if(!(e.tier!==`plugin`&&e.tier!=="default"||e.skipped))for(let t of Dl(e)){let n=wl(e,t,{tier:e.tier,path:e.dir,outcome:``},{display:e=>e,without:void 0,warnAt:Hl});if(!n)continue;let r={name:t,tier:e.tier,path:ql(n)};e.plugin!==void 0&&(r.plugin=e.plugin),e.skill!==void 0&&(r.skill=e.skill),Wl(o,t,Ul(r));let l=Al(t);for(let e of Gl(n.metadata.aliases)){let n=typeof e==`string`?e.trim():void 0,o=n===void 0?void 0:J(n);if(n===void 0||!o||o.invalid||o.plugin!==void 0||n===(l??t)){Wl(s,t,{code:`alias-invalid`,message:`${Ul(r)}: the alias ${JSON.stringify(e)} is not a reference name of its own; it is ignored`});continue}if(l!==void 0){Wl(c,l,{alias:n,owner:r});continue}Wl(i,n,r);let u=a.get(t)??[];u.includes(n)||a.set(t,[...u,n])}}let l={byAlias:i,byName:a,owned:o,warnings:s,interfaces:c};return t&&Vl.set(t,l),l}function ql(e){return e.entry.frontmatter&&e.whole?e.path.replace(/\.[^./]+$/,`.meta.md`):e.path}function Jl(e,t,n){if(e.invalid)return{kind:`own`};let r=(t.byAlias.get(e.name)??[]).filter(t=>e.plugin===void 0||t.plugin===e.plugin);if(!r.length)return{kind:`own`};let i=t.owned.get(e.name);if(i)return n(`alias-not-used`,Yl(e.name,i,r)),{kind:`own`};let a=[...new Set(r.map(({name:e})=>e))].sort((e,t)=>e.localeCompare(t));if(a.length>1)return{kind:`ambiguous`,names:e.plugin===void 0?a:a.map(t=>`${e.plugin}/${t}`),message:`"${e.name}" is an older name of ${a.join(` and `)}; load one of them by its own name`};let o=a[0];n(`reference-renamed`,`"${e.raw}" is renamed "${o}"; load "${o}" instead`);let s={raw:e.raw,name:o};return e.plugin!==void 0&&(s.plugin=e.plugin),{kind:`renamed`,ref:s,alias:e.name}}function Yl(e,t,n){return`the alias "${e}" that ${[...new Set(n.map(e=>`${Ul(e)}'s "${e.name}"`))].join(` and `)} lists is not used: ${t.join(` and `)} ${t.length>1?`hold`:`holds`} "${e}" as its own name`}function Xl(e,t,n){for(let r of t.warnings.get(e)??[])n(r.code,r.message);let r=[];for(let i of t.byName.get(e)??[]){let e=t.byAlias.get(i)??[],a=t.owned.get(i);if(a){n(`alias-not-used`,Yl(i,a,e));continue}new Set(e.map(e=>e.name)).size>1||r.push(i)}return r}function Zl(e,t){if(t.owned.has(e))return e;let n=new Set((t.byAlias.get(e)??[]).map(e=>e.name));return n.size===1?[...n][0]:e}function Ql(e,t){for(let n of e){let{tier:e}=n.layer;e!==`plugin`&&e!=="default"&&`aliases`in n.metadata&&t(n.label)(`alias-invalid`,"`aliases` is ignored: only the owner's contribution, a plugin's or a skill's default, renames a name")}}function $l(e,t){let{contribution:n,sections:r}=e;if(!r||n.whole)return n;let i=kc(n.body,r);for(let e of i.missing)t(n.label)(`section-not-held`,`the step's sections list "${e}", which it does not hold; that entry is skipped`);return{...n,body:i.body,hasBody:cc(i.body)}}function eu(e,t){let n=vc(),r=[],i,a=[],o;for(let s of e){let{operation:e,from:c}=s,l=$l(s,t),{entry:u}=l;if(l.whole&&l.hasBody){u.operation=`replace`,u.operationFrom=`default`;for(let e of r)e.entry.outcome=`shadowed by ${l.label} (replace)`;r=[l],n={...vc(),removed:n.removed},o=l,i=void 0,u.outcome=`used`,a.push(l);continue}if(o&&e!==`remove`&&l.hasBody){u.operation=e,u.operationFrom=c,u.outcome=`not used (format differs from ${o.format})`,t(l.label)(`format-mismatch`,`it is ignored: ${o.label} is ${o.format}, which a Markdown contribution cannot compose with`);continue}e===`remove`&&(o=void 0),u.operation=e,u.operationFrom=c;let d=t(l.label);if(e===`remove`){l.hasBody&&d(`remove-body-ignored`,`a merge: remove contribution has a body; it is ignored`);for(let e of r)e.entry.outcome=`shadowed by ${l.label} (remove)`;for(let e of Dc(n))e.path!==`(before the first heading)`&&n.removed.push({path:e.path,by:l.label});let e=n.removed;r=[],n={...vc(),removed:e},i=l,u.outcome=`used`,a.push(l);continue}if(!l.hasBody){u.outcome=u.extendsOutcome??`used`,u.extendsOutcome||a.push(l);continue}if(e===`replace`){for(let e of r)e.entry.outcome=`shadowed by ${l.label} (replace)`;r=[]}n=Tc(n,l.body,e,l.label,d),r.push(l),i=void 0,u.outcome=`used`,a.push(l)}return{composed:n,applied:r,removedBy:i,used:a,whole:o}}const tu=[`merge`,`extends`,`sources`,`request`];function nu(e){let t=Object.assign({},...e.map(({metadata:e})=>e));for(let e of tu)delete t[e];return t}function ru(e){return e.endsWith(`
|
|
199
|
+
`)?e:`${e}\n`}function iu(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``)}function au(e){switch(e){case`claude-code`:return{project:[`.claude/skills`],user:[`.claude/skills`],research:[`E-CC-L1`]};case`cursor`:return{project:[`.cursor/skills`,`.claude/skills`,`.codex/skills`,`.grok/skills`,`.agents/skills`],user:[`.cursor/skills`,`.claude/skills`,`.codex/skills`,`.grok/skills`,`.agents/skills`],research:[`E-CUR-L1`,`E-SR-CUR-10`]};case`codex`:return{project:[`.agents/skills`],user:[`.agents/skills`],research:[`E-CODEX-L1`]};case`copilot-cli`:return{project:[`.github/skills`,`.agents/skills`,`.claude/skills`],user:[`.copilot/skills`,`.agents/skills`],research:[`E-COPILOT-S5`,`E-SR-COPILOT-9`],relocatedBy:{variable:`COPILOT_HOME`,skills:`skills`}};case`vscode-copilot`:return{project:[`.github/skills`,`.claude/skills`,`.agents/skills`],user:[`.copilot/skills`,`.claude/skills`,`.agents/skills`],research:[`E-VSC-P1`]};case`opencode`:return{project:[`.opencode/skills`,`.claude/skills`,`.agents/skills`],user:[`.config/opencode/skills`,`.claude/skills`,`.agents/skills`],research:[`E-OC-S1`]};case`gemini-cli`:return{project:[`.agents/skills`,`.gemini/skills`],user:[`.agents/skills`,`.gemini/skills`],research:[`E-GEM-L1`]};case`cline`:return{project:[`.cline/skills`,`.clinerules/skills`,`.claude/skills`,`.agents/skills`],user:[`.cline/skills`,`.agents/skills`],research:[`E-CLINE-S1`,`E-CLINE-S3`]};case`augment`:return{project:[`.augment/skills`,`.claude/skills`,`.agents/skills`],user:[`.augment/skills`,`.claude/skills`,`.agents/skills`],research:[`E-AUG-S4`]};case`kilo`:return{project:[`.kilo/skills`,`.agents/skills`,`.claude/skills`],user:[`.kilo/skills`,`.agents/skills`,`.claude/skills`],research:[`E-KILO-L2`]};case`qwen-code`:case`crush`:case`openhands`:return}}const ou=[`claude-code`,`cursor`,`codex`,`copilot-cli`,`opencode`,`gemini-cli`];function su(e,t,n={}){let r=n.ProgramData||`C:\\ProgramData`;switch(e){case`claude-code`:return t===`darwin`?[`/Library/Application Support/ClaudeCode/.claude/skills`]:t===`win32`?[S.join(`C:\\Program Files\\ClaudeCode`,`.claude`,`skills`)]:[`/etc/claude-code/.claude/skills`];case`codex`:return t===`win32`?[]:[`/etc/codex/skills`];case`opencode`:{let e=t===`darwin`?`/Library/Application Support/opencode`:t===`win32`?S.join(r,`opencode`):`/etc/opencode`,n=t===`win32`?S:{join:_};return[n.join(e,`skill`),n.join(e,`skills`)]}default:return[]}}function cu(e,{chain:t,home:n,platform:r,env:i={}}){if(!ou.includes(e))return;let a=au(e);if(!a)return;let o=t.flatMap(e=>a.project.map(t=>_(e,t))),s=a.relocatedBy&&i[a.relocatedBy.variable],c=s&&b(s)!==_(n,`.copilot`)?[_(s,a.relocatedBy.skills)]:a.user.map(e=>_(n,e));return[...o,...c,...su(e,r,i)]}function lu(e){for(let t of Ri){let n;try{n=JSON.parse(o(_(e,t),`utf8`))}catch{continue}if(!z(n))return;let r=n.skills;return typeof r==`string`?[r]:Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}function uu(e,t){if(e===`opencode`)return[];let n=e===`gemini-cli`?void 0:lu(t),r=_(t,`skills`);if(!n)return[r];let i=n.map(e=>_(t,e));return e===`claude-code`?[r,...i]:i}function du(e){return po({env:e}).candidates}const fu={"macos-managed-preferences":`a macOS managed-preferences domain delivered by MDM`,"windows-registry":`a Windows registry key delivered by MDM or Group Policy`,server:`server-side settings`};function pu(e,t,n,r){let i={tier:e,dir:t,skipped:n};return e===`plugin`&&(i.origin=`enabled`),r!==void 0&&(i.plugin=r),i}function mu(e,t,n){let r=t===`win32`?S:v,i=mo(e,{platform:t,env:n}),a=[...new Set(i.flatMap(({kind:e,location:t})=>e===`file`?[r.dirname(t)]:e===`directory`?[t]:[]))];return{read:a.filter(e=>!a.some(t=>e.startsWith(t+r.sep))).map(e=>r.join(e,`references`)),unread:i.flatMap(({kind:t,location:n})=>{let r=fu[t];return r?[{location:n,reason:`${e} keeps this policy in ${r}, which cannot be read locally`}]:[]})}}function hu(e,t,n){let[r]=e;if(r===void 0)return[pu(`managed`,`(no harness detected)`,`no harness detected, so no managed folder is read`)];if(e.length>1)return[pu(`managed`,`(several harnesses detected)`,`detection names several harnesses (${e.join(`, `)}), so no managed folder is read`)];let{read:i,unread:a}=mu(r,t,n);return[...i.map(e=>({tier:`managed`,dir:e})),...a.map(({location:e,reason:t})=>pu(`managed`,e,t))]}function gu(e,t){for(let n of t){let t=e.find(({projectPath:e})=>e===n);if(t)return t}return e.find(({projectPath:e})=>e===void 0)}async function _u(e,t,n){let r=[];for(let i of e){let[e,a]=await Promise.all([To(i,n),Io(i,n)]);if(!e.supported){r.push(pu(`plugin`,`(${i} enabled plugins)`,`${i} keeps no readable record of enabled plugins`));continue}e.unread.length&&r.push(pu(`plugin`,`(${i} plugin policy)`,`${e.unread.join(`; `)} may also enable or disable ${i} plugins`));for(let{id:n,enabled:o}of e.plugins){if(!o)continue;let e=n.split(`@`)[0],s=gu(a.plugins.filter(e=>e.id===n),t);if(s){let t=Bi(s.path)??e;r.push({tier:`plugin`,dir:_(s.path,`references`),plugin:t,origin:`enabled`,version:Ui(s.path,s.version)});continue}r.push(pu(`plugin`,`(${n})`,`enabled in ${i}, but no install folder for this project is recorded`,e))}}return r}function vu(e){return _(e,`.agents`,`references`)}function yu(e){return _(e,`.agents`,`references`)}function bu(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}function xu(e){try{return d(e).isDirectory()}catch{return!1}}function Su(e){let t=b(e);for(let e=t;;){if(r(_(e,`.git`)))return e;let n=m(e);if(n===e)return t;e=n}}function Cu(e,t=process.cwd()){if(e===void 0)return Su(t);let n=b(t,e);if(!xu(n))throw new q(`root-missing`,`the root ${n} does not exist or is not a folder.`,{details:{root:n}});return n}function wu(e,t){let n=b(t),r=[];for(let t=b(e);;){if(r.push(t),t===n)return r;let e=m(t);if(e===t)return[n];t=e}}function Tu(e){try{return c(e)}catch{return e}}function Eu(e){let t=_(e,`package.json`),n=bu(t);return n===void 0?[]:Fi(n).flatMap(e=>{let n=Li(e,t);return n?[n]:[]})}function Du(e,t){let n=[];for(let r of e){if(t.has(Tu(r)))continue;let e=_(r,`references`);if(!xu(e))continue;let i=Bi(r);n.push(i?{tier:`plugin`,dir:e,plugin:i,origin:`dependency`,version:Ui(r)}:{tier:`plugin`,dir:e,origin:`dependency`,skipped:`not a plugin`})}return n}function Ou(e){try{return s(_(e,`references`)).some(e=>e.endsWith(`.default.md`))}catch{return!1}}function ku(e,t,n){if(!e.length)return{skills:[],unverified:`no harness detected, so no skill folder is read and no skill's default is listed`};let r=[],i=[];for(let a of e){let e=cu(a,t);if(!e){i.push(a);continue}r.push(...e,...n.flatMap(e=>uu(a,e)))}let a=n.filter(e=>so(e)!==void 0),o=r.length?lo([...r,...a]).filter(({folder:e})=>Ou(e)):[];return i.length?{skills:o,unverified:`the skill folders ${i.join(`, `)} ${i.length===1?`reads are`:`read are`} not verified, so ${i.length===1?`its`:`their`} skills' defaults are not listed`}:{skills:o}}function Au(e){let t=_(e,`references`);return xu(e)?{tier:`default`,dir:t,skill:so(e)??p(e)}:{tier:`default`,dir:t,skill:p(e),skipped:`no skill folder`,warning:{code:`default-folder-missing`,message:`the skill folder ${e} does not exist; the name resolves without its default`}}}async function ju({root:e,cwd:t=process.cwd(),home:n,platform:r,plugin:i,defaultSkill:a,env:o=process.env}){let s=Cu(e,t),c=du(o),l=wu(t,s),u=i&&Tu(i.root),d=await _u(c,l,{env:o,homedir:n,cwd:s,platform:r}),f=Eu(s),p=[...i?[i.root]:[],...d.flatMap(({dir:e,skipped:t})=>t?[]:[m(e)]),...f.filter(e=>Bi(e))],h=ku(c,{chain:l,home:n,platform:r,env:o},p),g=i?[{tier:`plugin`,dir:_(i.root,`references`),plugin:i.name,origin:`host`,version:Ui(i.root)}]:[],v=[...hu(c,r,o),{tier:`repo`,dir:vu(s)},{tier:`user`,dir:yu(n)},...g,...d.filter(e=>e.skipped||xu(e.dir)&&Tu(m(e.dir))!==u),...Du(f,new Set(u?[u]:[])),...a===void 0?[]:[Au(b(t,a))]],y=/* @__PURE__ */ new Set,x=v.filter(({dir:e})=>!y.has(e)&&y.add(e)),S=[...g,...d.filter(({skipped:e})=>!e),...f.flatMap(e=>{let t=Bi(e);return t?[{tier:`plugin`,dir:e,plugin:t,origin:`dependency`,version:Ui(e)}]:[]})].flatMap(({plugin:e,version:t,origin:n})=>e===void 0?[]:[{plugin:e,version:t,origin:n}]);return{layers:x,root:s,projects:/* @__PURE__ */ new Map,harnesses:c,skills:h,plugins:S}}const X=[`.agents`,`references`];function Mu(e,...t){return ee(`git`,[`ls-files`,`-z`,...t,`--exclude-standard`],{cwd:e,encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],maxBuffer:268435456}).split(`\0`).filter(Boolean)}function Nu(e){try{let t=Mu(e,`-coi`,`--directory`),n=new Set(t);return{files:Mu(e,`-co`).filter(e=>!n.has(e)),ignored:t}}catch{return}}function Pu(e){let t=e.split(`/`);for(let e=1;e+X.length<t.length;e++)if(t[e]===X[0]&&t[e+1]===X[1])return t.slice(0,e).join(`/`)}function Fu(e,t){if(!t.endsWith(`/`))return Pu(t);let n=t.slice(0,-1).split(`/`);n.at(-1)===X[1]&&n.at(-2)===X[0]?n.splice(-2):n.at(-1)===X[0]&&n.splice(-1);let r=n.join(`/`);return r&&xu(_(e,...n,...X))?r:void 0}function Iu(e){try{return s(e,{withFileTypes:!0})}catch{return[]}}function Lu(e){let t=[],n=[],r=i=>{let a=Iu(_(e,i));i&&!i.split(`/`).includes(`node_modules`)&&a.some(e=>e.isFile()&&e.name===`package.json`)&&n.push(i);for(let n of a){if(!n.isDirectory())continue;let a=i?`${i}/${n.name}`:n.name;if(n.name!==X[0]){r(a);continue}i&&Iu(_(e,a,X[1])).length&&t.push(i);for(let t of Iu(_(e,a)))t.isDirectory()&&t.name!==X[1]&&r(`${a}/${t.name}`)}};return r(``),{folders:t,packages:n}}function Ru(e,t){let n=e.split(`/`),r=t.split(`/`);for(let e=0;e<Math.min(n.length,r.length);e++){let t=n[e],i=r[e];if(t!==i)return t<i?-1:1}return n.length-r.length}function zu(e,t){return[...t].sort(Ru).map(t=>({folder:t,dir:_(e,...t.split(`/`),...X)})).filter(({dir:e})=>xu(e))}function Bu(e){let t=Nu(e);if(t===void 0){let t=Lu(e);return{folders:zu(e,t.folders),ignored:[],packages:t.packages.sort(Ru)}}let n=new Set(t.files.flatMap(e=>Pu(e)??[])),r=new Set(t.ignored.flatMap(t=>{let r=Fu(e,t);return r===void 0||n.has(r)?[]:[r]})),i=t.files.flatMap(e=>e.endsWith(`/package.json`)?[e.slice(0,-13)]:[]);return{folders:zu(e,n),ignored:zu(e,r),listed:new Set(t.files),packages:i.sort(Ru)}}function Vu(e,t=/* @__PURE__ */ new Map){let n=b(e),r=t.get(n);if(r)return r;let i=Bu(n);return t.set(n,i),i}function Hu(e,t){try{return ee(`git`,[`check-ignore`,`-q`,`--`,t],{cwd:e,stdio:`ignore`}),!0}catch{return!1}}const Uu=/* @__PURE__ */ new WeakMap;function Wu(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}function Gu(e,t){let n=[];for(let r of t){let t=_(e,...r.split(`/`),`package.json`),i=Wu(t);for(let e of Fi(i)){let i=Li(e,t),a=i&&Bi(i);i&&a&&(n.some(e=>e.plugin===a&&r.startsWith(`${e.folder}/`))||n.some(e=>e.plugin===a&&e.folder===r)||n.push({folder:r,plugin:a,root:i,version:Ui(i)}))}}return n}function Ku(e,t,n){let r=Vu(e,t),i=Uu.get(r);return i||(i=Gu(e,r.packages),Uu.set(r,i)),i.filter(({plugin:e})=>!n.has(e))}function qu(e){return _(e.root,`references`)}function Ju({layers:e,plugins:t=[]}){return/* @__PURE__ */ new Set([...e.flatMap(({tier:e,plugin:t,skipped:n})=>e===`plugin`&&t&&!n?[t]:[]),...t.flatMap(({plugin:e,origin:t})=>t===`package`?[]:[e])])}const Yu=[`merge`,`extends`,`implements`,`aliases`],Xu=[`sources`,`request`];function Zu(e){try{return new Set(s(e))}catch{return/* @__PURE__ */ new Set}}function Qu(e,t,n){let r=Zu(e.dir),i=n=>({folder:e,file:n,as:t,path:_(e.dir,...n.split(`/`)),relative:`${e.folder}/.agents/references/${n}`});return{markdown:[`${t}.md`,`${t}/README.md`].filter(e=>r.has(e.split(`/`)[0])).map(i).filter(({path:e})=>e!==n&&xl(e)!==void 0),data:Lc.map(({extension:e})=>`${t}${e}`).filter(e=>r.has(e)).map(i).filter(({path:e})=>e!==n)}}function $u(e,t){let n=/* @__PURE__ */ new Map,r=e=>{let t=n.get(e);return t||(t={folder:e,ignored:!1,plugins:[]},n.set(e,t)),t};for(let t of e.folders)r(t.folder).own=t;for(let t of e.ignored)Object.assign(r(t.folder),{own:t,ignored:!0});for(let e of t)r(e.folder).plugins.push(e);return[...n.values()].sort((e,t)=>Ru(e.folder,t.folder))}function ed(e,t){let{root:n,cache:r,catalog:i,held:a=/* @__PURE__ */ new Set}=t,o=Vu(n,r),s=Ku(n,r,a),c={...t,older:t.older??[],catalog:i&&td(i,s),dropping:ad(t.managed),listed:e=>!o.listed||o.listed.has(e.relative)},l={sections:[],trace:[]};for(let t of $u(o,s)){for(let n of nd(e,t,c))rd(e,n,c,l);t.own&&id(e,t.own,t.ignored,c,l)}return l}function td(e,t){if(!t.length)return e;let n=new Map(e.plugins);for(let{plugin:e,version:r}of t)n.has(e)||n.set(e,{plugin:e,version:r,origin:`package`});return{...e,plugins:n}}function nd(e,t,n){let r=[];for(let i of[...t.plugins].sort((e,t)=>e.plugin.localeCompare(t.plugin))){let a={folder:t.folder,dir:qu(i)},[o]=[e,...n.older].flatMap(e=>Qu(a,e,n.without).markdown);if(!o)continue;let{metadata:s,body:c}=K(xl(o.path)??``,n.warnAt(`plugin ${n.display(o.path)}`)),l=Y(s.extends,()=>{})??[];r.push({plugin:i,hit:o,metadata:s,body:c,after:l.map(({target:e})=>e)})}let i=[],a=new Set(r.map(({plugin:e})=>e.plugin));for(;r.length;){let e=new Set(i.map(({plugin:e})=>e.plugin)),t=r.findIndex(({after:t})=>t.every(t=>!a.has(t)||e.has(t)));i.push(...r.splice(t===-1?0:t,1))}return i}function rd(e,t,n,r){let{plugin:i,hit:a,metadata:o,body:s}=t,c={folder:i.folder,path:a.path,file:a.file,frontmatter:o,outcome:`used`,plugin:i.plugin};i.version!==void 0&&(c.version=i.version),a.as!==e&&(c.alias=a.as),r.trace.push(c);let l=`plugin ${n.display(a.path)}`;if(n.format!==void 0&&n.format!==`markdown`){c.outcome=`not used (format differs from ${n.format})`,n.warnAt(l)(`project-section-not-markdown`,`it is not delivered: the main document of "${e}" is ${n.format}, which has no project sections`);return}if(n.dropping){c.outcome=`shadowed by ${n.dropping.label} (${n.dropping.operation})`;return}if(!cc(s)){c.outcome=`not used (no body)`;return}let u={...o};for(let e of[...Yu,...Xu,`declined`])delete u[e];let d=od(s,l,n.managed,n.warnAt);d.sections&&(c.sections=d.sections),r.sections.push({folder:i.folder,path:a.path,content:d.content,metadata:u,plugin:i.plugin})}function id(e,t,n,r,i){let{trace:a,sections:o}=i,{format:s,display:c,without:l,warnAt:u,catalog:d,older:f,listed:p,dropping:m,managed:h}=r,g=[e,...f].map(e=>Qu(t,e,l)),_=g.flatMap(e=>e.markdown),v=g.flatMap(e=>e.data);if(n||![..._,...v].some(p)){(_.length||v.length)&&a.push({folder:t.folder,path:t.dir,outcome:`not read (ignored)`});return}for(let t of v.filter(p))u(c(t.path))(`project-section-not-markdown`,`it is not delivered: a project section is Markdown, written as ${e}.md`);let[y,...b]=_.filter(p);if(!y)return;for(let e of b)u(c(e.path))(`file-ignored`,`it is ignored: ${y.file} answers first in that folder`);let x={folder:t.folder,path:y.path,file:y.file,outcome:`used`};a.push(x);let S=`project ${c(y.path)}`;if(y.as!==e&&(x.alias=y.as,u(c(y.path))(`reference-renamed`,`it is filed under the older name "${y.as}" and applies as "${e}"; rename it to the new name`)),s!==void 0&&s!==`markdown`){x.outcome=`not used (format differs from ${s})`,u(S)(`project-section-not-markdown`,`it is not delivered: the main document of "${e}" is ${s}, which has no project sections`);return}let{metadata:C,body:w}=K(xl(y.path)??``,u(S));x.frontmatter=C;let T={...C};for(let e of Yu)e in T&&(delete T[e],u(S)(`project-section-key-ignored`,`\`${e}\` is ignored in the project section for ${t.folder}: a project section states only what differs in its folder`));if(m){x.outcome=`shadowed by ${m.label} (${m.operation})`;return}if(!cc(w)){x.outcome=`not used (no body)`;return}for(let e of Xu)delete T[e];let E=od(w,S,h,u);E.sections&&(x.sections=E.sections);let D=d&&tl(C,d,u(S));D&&(D.sources.length&&(x.sources=D.sources),D.request!==void 0&&(x.request=D.request),D.stale&&(x.outcome=`stale`,u(S)(`reference-stale`,el(e,D.sources)))),o.push({folder:t.folder,path:y.path,content:E.content,metadata:T})}function ad(e){if(e?.entry.outcome!==`used`)return;let t=e.merge??`patch`;if(t===`remove`||t===`replace`&&e.hasBody)return{label:e.label,operation:t}}function od(e,t,n,r){let i=ru(iu(pc(e)));if(n?.entry.outcome!==`used`||!n.hasBody||n.whole)return{content:i};let a=n.merge??`patch`;if(a===`remove`||a===`replace`)return{content:i};let o=Tc(vc(),e,`patch`,t,r(t)),s=Tc(o,n.body,a,n.label,r(n.label),{matchedOnly:!0}),c=Ec(s);return c===Ec(o)?{content:i}:{content:c,sections:Dc(s).map(({path:e,sources:t})=>({path:e,contributions:t}))}}function sd(e,t,n=/* @__PURE__ */ new Set){let r=Vu(e,t),i=/* @__PURE__ */ new Set;for(let e of r.folders)for(let t of Dl({tier:`project`,dir:e.dir})){let{markdown:n}=Qu(e,t,void 0);n.some(e=>!r.listed||r.listed.has(e.relative))&&i.add(t)}for(let r of Ku(e,t,n)){let e=qu(r);for(let t of Dl({tier:`plugin`,dir:e}))Qu({folder:r.folder,dir:e},t,void 0).markdown.length&&i.add(t)}return[...i]}function cd(e){return Array.isArray(e)?{layers:[...e],harnesses:[]}:e}function ld(e){return{stack:[],builtBy:`none`,contributions:[],sections:[],layers:[],harnesses:[...e],projectSections:[]}}function ud(e,t){let n=e=>{if(e.tier!==`plugin`&&e.tier!=="default")return-1;let n=t.indexOf(e.tier==="default"?`default`:e.plugin??``);return n===-1?t.length:t.length-1-n};return e.map((e,t)=>({layer:e,index:t,rank:n(e)})).sort((e,t)=>e.rank-t.rank||e.index-t.index).map(({layer:e})=>e)}function Z(e,t,n={}){return dd(e,t,n,void 0)}function dd(e,t,{display:n=e=>e,without:r,below:i,projectSections:a=!0},o){let s=typeof e==`string`?J(e):e,{layers:c,harnesses:l,root:u,projects:d}=cd(t),f=ld(l),p=[],m={name:s.raw,status:`missing`,projectSections:[],warnings:p,trace:f};if(s.invalid)return{...m,status:`invalid`,code:`reference-invalid`,message:s.invalid};let h=/* @__PURE__ */ new Set,g=e=>(t,n)=>{let r=e?`${e}: ${n}`:n;h.has(`${t} ${r}`)||(h.add(`${t} ${r}`),p.push({code:t,message:r}))},_=g(``),v=Kl(t),y=Jl(s,v,_);if(y.kind===`ambiguous`)return{...m,status:`ambiguous`,code:`reference-ambiguous`,message:y.message,cause:`alias`,options:y.names};let b=y.kind===`renamed`?y.ref:s;y.kind===`renamed`&&(f.alias={name:y.alias,resolvedAs:b.name});let x=Xl(b.name,v,_),S=i===void 0?-1:c.findIndex(e=>e.dir===i),C=S===-1?c:c.slice(S+1),w=[];for(let e of C){e.warning&&_(e.warning.code,e.warning.message);let t={tier:e.tier,path:e.dir,outcome:`missing`};if(e.plugin!==void 0&&(t.plugin=e.plugin),e.skill!==void 0&&(t.skill=e.skill),f.layers.push(t),e.skipped){t.outcome=`not read (${e.skipped})`;continue}let i=wl(e,b.name,t,{display:n,without:r,warnAt:g,older:x}),a=o?o(e,i,t):i;a?w.push(a):e.tier==="default"&&(t.outcome=`not read (no default)`)}Ql(w,g);let T=/* @__PURE__ */ new Map;for(let e of w.filter(({layer:e})=>e.tier===`plugin`)){let t=e.layer.plugin,r=T.get(t);r?e.entry.outcome=`not read (plugin ${t} answers from ${n(r.path)})`:T.set(t,e)}let E=w.find(({layer:e})=>e.tier==="default"),D=w.filter(({layer:e})=>e.tier!==`plugin`&&e.tier!=="default"),ee=new Set(C.flatMap(({plugin:e,skipped:t})=>e&&!t?[e]:[])),O=e=>e==="default"?E??{reason:`has no default`}:T.get(e)??{reason:ee.has(e)?`holds no ${b.name}`:`is not installed`},te=()=>[...[...T.keys()].map(e=>`${e}/${b.name}`),...E?[`default`]:[]];if(Al(b.name)!==void 0)return md(b,w,T,E,m,_,te);let ne=e=>{if(u===void 0||i!==void 0||!a)return{sections:[],trace:[]};let o=D.find(({layer:e})=>e.tier===`managed`),s=Zc(t,{tier:`project`}),c=ed(b.name,{root:u,cache:d,managed:o,format:e,display:n,without:r,warnAt:g,catalog:s,older:x,held:Ju(cd(t))});return f.projectSections=c.trace,c},k=gl(b,D,T,O,E,_);if(`status`in k){if(k.status===`ambiguous`){for(let{entry:e}of w)e.outcome===``&&(e.outcome=`ambiguous`);return{...m,status:`ambiguous`,code:`reference-ambiguous`,message:k.message,cause:k.cause,options:te()}}for(let{entry:e}of w)e.outcome===``&&(e.outcome=`not used (qualified name)`);return{...m,status:`missing`,code:`reference-missing`,message:k.message}}!C.some(({tier:e})=>e==="default")&&w.some(({steps:e})=>bl(e))&&f.layers.push({tier:`default`,path:`(no skill folder given)`,outcome:`not read (no default)`}),f.stack=k.entries.map(({target:e})=>e),f.builtBy=k.builtBy,f.layers=ud(f.layers,f.stack);let re=new Set(f.stack);for(let[e,t]of[...T.entries(),...E?[[`default`,E]]:[]]){if(re.has(e))continue;let n=k.replaced.find(t=>t.target===e);t.entry.outcome=b.plugin===void 0?n?`not used (${n.step}'s extends replaced by ${k.replacedBy})`:`not used (not in extends)`:`not used (qualified name)`}b.plugin===void 0&&pd(b.name,k,T,re,g);let{composed:A,applied:ie,removedBy:ae,used:oe,whole:j}=eu([...k.entries,...[...D].reverse().map(e=>({contribution:e,operation:e.merge??`patch`,from:e.merge?`contribution`:`default`}))],g);if(fd(b.name,oe,t,g),f.sections=A.removed.map(({path:e,by:t})=>({path:e,contributions:[],removedBy:t})),!ie.length){let e=ne(void 0).sections;if(e.length)return{...m,status:`found`,content:``,format:`markdown`,metadata:{},projectSections:e};if(ae)return f.removedBy=ae.label,{...m,status:`missing`,code:`reference-removed`,message:`"${b.name}" is turned off by ${ae.label} (remove)`};let t=b.plugin===void 0?`no tier holds a document for "${b.name}"`:`the plugin ${b.plugin} holds no document for "${b.name}"`;return{...m,status:`missing`,code:`reference-missing`,message:t}}let se=oe.filter(({entry:e})=>e.outcome===`used`||e.outcome===`stale`);if(f.contributions=ie.map(({layer:e,entry:t})=>{let n={tier:e.tier,path:t.path,operation:t.operation};return t.plugin!==void 0&&(n.plugin=t.plugin),t.skill!==void 0&&(n.skill=t.skill),n}),f.sections=[...Dc(A).map(({path:e,sources:t})=>({path:e,contributions:t})),...f.sections],j)return ne(j.format),{...m,status:`found`,content:j.body,format:j.format,metadata:nu(se)};let ce=ie.length===1&&!A.removed.length?ie[0].body:void 0,le=ce!==void 0&&pc(ce)===ce?ru(iu(ce)):Ec(A);return{...m,status:`found`,content:le,format:`markdown`,metadata:nu(se),projectSections:ne(`markdown`).sections}}function fd(e,t,n,r){for(let i of t){let{layer:t,entry:a}=i;if(a.outcome!==`used`||t.tier!==`repo`&&t.tier!==`user`)continue;let o=r(i.label),s=tl(i.metadata,Zc(n,{tier:t.tier}),o);s&&(s.sources.length&&(a.sources=s.sources),s.request!==void 0&&(a.request=s.request),s.stale&&(a.outcome=`stale`,o(`reference-stale`,el(e,s.sources))))}}function pd(e,t,n,r,i){let a=t.builder;if(!a||a.layer.tier!==`repo`&&a.layer.tier!==`user`)return;let o=new Set(vl(a.metadata.declined,i(a.label))),s=[];for(let[e,t]of n)r.has(e)||(a.layer.tier!==`user`||t.layer.origin!==`dependency`)&&(o.has(e)?t.entry.outcome=`not used (declined by ${a.label})`:s.push(e));if(!s.length)return;let c=a.layer.tier===`user`?` --scope user`:``,l=yl(a.steps??[]),u=l?`run "reference customize ${e}${c} --extends ${[...l,...s].join(` `)}" to add ${s.length>1?`them`:`it`}, or "reference customize ${e}${c} --extends ${l.join(` `)}" to leave ${s.length>1?`them`:`it`} out`:`add ${s.length>1?`them`:`it`} to the extends with "reference customize ${e}${c} --extends-file <file>", or write the same extends again to leave ${s.length>1?`them`:`it`} out`,d=s.join(`, `);i(a.label)(`plugin-not-selected`,`${s.length>1?`the plugins`:`the plugin`} ${d} ${s.length>1?`hold`:`holds`} "${e}" but ${s.length>1?`are`:`is`} neither in its extends nor declined, so ${s.length>1?`they are`:`it is`} not used; ${u}`)}function md(e,t,n,r,i,a,o){for(let e of t)(e.merge!==void 0||e.steps!==void 0)&&a(`interface-not-composed`,`${e.label}: merge and extends on an interface document are ignored; an interface is never composed`);if(e.plugin===void 0&&n.size>1){for(let{entry:e}of t)e.outcome===``&&(e.outcome=`ambiguous`);return{...i,status:`ambiguous`,code:`reference-ambiguous`,message:`the plugins ${[...n.keys()].join(`, `)} each hold the interface document`,cause:`unordered`,options:o()}}let s=e.plugin===void 0?[...n.values()]:n.has(e.plugin)?[n.get(e.plugin)]:[];if(e.plugin!==void 0){for(let[t,r]of n)t!==e.plugin&&(r.entry.outcome=`not used (qualified name)`);if(!s.length)return{...i,status:`missing`,code:`reference-missing`,message:`the plugin ${e.plugin} holds no "${e.name}"`}}let c=t.filter(({layer:e})=>e.tier!==`plugin`&&e.tier!=="default"),[l,...u]=[...e.plugin===void 0&&r?[r]:[],...s,...[...c].reverse()];if(!l)return{...i,status:`missing`,code:`reference-missing`,message:`no tier holds a document for "${e.name}"`};for(let e of u)e.entry.outcome=`not used (an interface document is never composed)`,a(`interface-not-composed`,`${e.label} is ignored: an interface document is never composed; define a new interface id instead`);r&&r!==l&&(r.entry.outcome=`not used (qualified name)`),l.entry.outcome=`used`,l.entry.operation=`replace`,l.entry.operationFrom=`default`;let{trace:d}=i;return l.layer.tier===`plugin`&&(d.stack=[l.layer.plugin]),l.layer.tier==="default"&&(d.stack=[`default`]),d.contributions=[{tier:l.layer.tier,...l.entry.plugin?{plugin:l.entry.plugin}:{},...l.entry.skill?{skill:l.entry.skill}:{},path:l.path,operation:`replace`}],{...i,status:`found`,content:ru(iu(pc(l.body))),metadata:nu([l])}}function hd(e){return[...new Set(cd(e).layers.flatMap(Dl))].sort((e,t)=>e.localeCompare(t))}function gd(e,t){let n=t.scope===`user`,r=e.layers.filter(e=>n?e.tier!==`repo`&&(e.tier!==`plugin`||e.origin!==`dependency`):e.tier!==`user`),i=n?e.plugins?.filter(({origin:e})=>e!==`dependency`):e.plugins;return{...e,layers:r,...i?{plugins:i}:{}}}function _d(e,t){return e.entry.empty=!0,{...e,body:``,hasBody:!1,merge:void 0,steps:t}}function vd(e,t,n,r,i={}){let a=i.display??(e=>e),o=dd(e,gd(t,n),i,(t,i,o)=>{if(t.tier===`managed`){if(!i)return;if(i.whole){o.outcome=`not read (managed text is left out)`;return}return _d(i,i.steps)}if(n.scope===`project`||t.dir!==n.dir)return i;let s=r===void 0?i?.steps:r??void 0;if(!s){i&&(o.outcome=`not read (the target is left out)`);return}return i&&!i.whole?_d(i,s):(Object.assign(o,{path:n.path,file:`${e.name}.md`,outcome:``,selection:!0}),{layer:t,entry:o,label:Cl(t,n.path,a),path:n.path,metadata:{},body:``,hasBody:!1,format:`markdown`,whole:!1,merge:void 0,steps:s})}),s=n.folder,c=s===void 0?[]:o.projectSections.filter(e=>s.startsWith(`${e.folder}/`)||e.folder===s&&e.plugin!==void 0);return{...o,projectSections:c}}function yd(e,t){let n=t?jc(t).body.trim():void 0,r=[n,e.status===`found`?(e.content??``).trim():``].filter(e=>!!e),i={content:r.length?`${r.join(`
|
|
198
200
|
|
|
199
|
-
`))}function Rl(e,t=`show`){return M({name:t,description:`Print one or more references, each composed from its contributions as their extends and merge declare.`,arguments:[{name:`names`,description:"Reference names, without the `.md` extension; `<plugin>/<name>` builds that plugin’s own stack.",type:P.array(P.string())}],options:{root:wl,default:El,metadata:{description:`Make every entry a record with its status and composed frontmatter.`,type:P.boolean().optional()},trace:Tl},async run(t){let n=this.format;t.names.length||kl(`name at least one reference.`);try{let r=w(),i=await e(t,r),a=e=>B(r,e),o=Kc(i,{display:a}),s=t.names.map(e=>{let t=K(G(e),i,{display:a});for(let e of Xc(t,o).failures)e.check!==`compose`&&t.warnings.push({code:`interface-check`,message:`it fails its interface check (${e.check}): ${e.message}`});return t}),c=s.every(e=>e.status===`found`);if(n===`text`){for(let e of s)jl(e.warnings),e.status!==`found`&&process.stderr.write(`error: ${e.code}: ${Pl(e)}\n`),t.trace&&process.stderr.write(Nl(e,r));let e=Ll(s);if(e===void 0)throw j.reported(A.error);return c?e:Al(e,n)}let l={metadata:!!t.metadata,trace:!!t.trace},u=R(s.map(e=>Fl(e,r,l)),{render:Il});return c?u:Al(u,n)}catch(e){return Ol(e,`Reference lookup failed.`)}}})}function zl(e,t=`list`){return M({name:t,description:`List every reference name, one row each, with its description, and its status when not found. A pattern keeps only the names it matches exactly.`,arguments:[{name:`pattern`,description:"Exact name pattern, where `*` stands for any run of characters, such as `project-tracker.capabilities.*`.",type:P.string().optional()}],options:{root:wl,trace:{...Tl,description:`Add one row per name per layer holding it, with its outcome.`}},async run(t){try{let n=w(),r=e=>B(n,e),i=Rc(await e(t,n),{display:r,pattern:t.pattern}),a=Q({references:i.references.length?i.references.map(e=>Q({name:e.name,description:e.description,format:e.format,status:e.status===`found`?void 0:e.status,options:e.options})):t.pattern?`0 references match "${t.pattern}"`:`0 references — no layer holds one`,defaults:i.defaults});return t.trace&&(a.layers=i.layers.map(e=>Q({...e,path:r(e.path)}))),i.warnings.length&&(a.warnings=i.warnings),R(a)}catch(e){return Ol(e,`Reference listing failed.`)}}})}function Bl(e){return M({name:`search`,description:`Find references by name, description, tags, headings, or body, best match first.`,arguments:[{name:`query`,description:`What the reference is about.`,type:P.string()}],options:{root:wl,trace:{...Tl,description:`Add the tier and plugin or skill of each match.`}},async run(t){let n=t.query.trim();n||kl(`search needs a query.`);try{let r=w(),{matches:i,defaults:a}=Gc(n,await e(t,r),{display:e=>B(r,e)});return R(Q({references:i.length?i.map(({name:e,description:n,match:r,tier:i,plugin:a,skill:o,loadedBy:s})=>Q(t.trace?{name:e,description:n,match:r,loadedBy:s,tier:i,plugin:a,skill:o}:{name:e,description:n,match:r,loadedBy:s})):`0 references match "${n}"`,defaults:a}))}catch(e){return Ol(e,`Reference search failed.`)}}})}function Vl(e,t=!1,n=`where`){return M({name:n,description:`Give the project and user files a customization or a selection of a reference is written to, who each reaches, and the heading paths of the document below each.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:P.string()}],options:{root:wl,default:El,trace:{...Tl,description:`Add every layer checked, with its outcome.`}},async run(n){let r=this.format;try{let i=w(),a=e=>B(i,e),o=il(n.name,await e(n,i),{root:y(n.root??process.cwd()),display:a,assets:t}),s=Q({name:o.name,status:o.status,places:o.places.map(e=>Q(e)),options:o.options,layers:n.trace?o.layers.map(e=>({...e,path:a(e.path)})):void 0,warnings:o.warnings});r===`text`&&jl(o.warnings);let c=R(s);return o.status===`invalid`?(process.stderr.write(`error: reference-invalid: ${G(n.name).invalid}\n`),Al(c,r)):c}catch(e){return Ol(e,`Reference placement lookup failed.`)}}})}function Hl(e){if(e===void 0)return;let t=e.split(`,`).map(e=>e.trim());return(!t.length||t.some(e=>!/^[1-9]\d*$/.test(e)))&&kl(`--accept is a comma-separated list of versions, such as 1,2; got "${e}".`),t.map(Number)}function Ul(e){return M({name:`implementations`,description:`List the implementations of an interface a consumer can load, each with its pin, description, and unsupported sections.`,arguments:[{name:`id`,description:"Interface id, the name of its `<id>.interface` document without the suffix.",type:P.string()}],options:{root:wl,accept:{description:"Versions the consumer knows, comma-separated, such as 1,2. Defaults to the interface's `versions`.",type:P.string().optional()},trace:{...Tl,description:`Add each one's name, tier, and version, the interface's cardinality and accepted versions, and the ones left out with why.`}},async run(t){let n=Hl(t.accept);try{let r=w(),i=nl(t.id,await e(t,r),{accept:n,display:e=>B(r,e)}),a=i.implementations.map(({pin:e,description:n,unsupported:r,name:i,tier:a,version:o})=>Q(t.trace?{pin:e,description:n,unsupported:r,name:i,tier:a,version:o}:{pin:e,description:n,unsupported:r})),o={implementations:a.length?a:`0 implementations of ${t.id}`};return t.trace&&Object.assign(o,Q({interface:i.interface,cardinality:i.cardinality,accept:i.accept,excluded:i.excluded,warnings:i.warnings})),R(o)}catch(e){return Ol(e,`Implementation lookup failed.`)}}})}function Wl(e){return M({name:`check`,description:"Check interface documents and their implementations, each composed as `show` composes it. With no names, checks every one found. Exits 1 on any failure.",arguments:[{name:`names`,description:"Reference names, without the `.md` extension; `<plugin>/<name>` builds that plugin’s own stack.",type:P.array(P.string()).optional()}],options:{root:wl,trace:{...Tl,description:`Add every entry checked, with its kind and unsupported sections.`}},async run(t){let n=this.format;try{let r=w(),i=$c(await e(t,r),{names:t.names??[],display:e=>B(r,e)}),a=i.filter(e=>e.status!==`passed`),o=e=>e.map(({check:e,message:t})=>({check:e,message:t})),s=R(Q({failed:a.map(({name:e,loadedBy:t,failures:n})=>Q({name:e,loadedBy:t,failures:o(n)})),passed:i.length-a.length,references:t.trace?i.map(({name:e,loadedBy:t,kind:n,status:r,failures:i,unsupported:a})=>Q({name:e,loadedBy:t,kind:n,status:r,failures:o(i),unsupported:a})):void 0}));return a.length?(n===`text`&&process.stderr.write(`error: interface-check: ${a.length} of ${i.length} references fail their check.\n`),Al(s,n)):s}catch(e){return Ol(e,`Reference check failed.`)}}})}const Gl={description:"Tier to write: project (default), `.agents/references/` at the root, or user, `~/.agents/references/`.",type:P.string().optional()},Kl={description:"A plugin's source folder in this repository: acts on its `references/<name>.md`.",type:P.string().optional()},ql={description:"A skill's source folder in this repository: acts on its `references/<name>.default.md`.",type:P.string().optional()};function Jl(e){return M({name:`create`,description:`Start a contribution in the project or user tier, or in a plugin's or a skill's source folder, from a template or an interface. Never overwrites a file with a body.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:P.string()}],options:{root:wl,scope:Gl,plugin:Kl,default:ql,merge:{description:`How it applies over what is below: replace, patch (default), combine, or remove. remove writes no body.`,type:P.string().optional()},template:{description:"File whose text is written as it is, frontmatter included. Defaults to a built-in template of top-level `##` sections.",type:P.string().optional()},implements:{description:"Interface id to implement: the interface's sections become `##` headings, each stubbed `**Unsupported.**`, with `merge: replace`. Not with --template.",type:P.string().optional()},"dry-run":{description:`Print the target path and the exact content, and write nothing.`,type:P.boolean().optional()},trace:{...Tl,description:`After the write, add the trace, in which the new file applies.`}},async run(t){let n=this.format;try{let r=w(),i=y(t.root??process.cwd()),a=e=>B(r,e),o=bl(await e({root:i,default:t.default},r),{root:i,home:r,name:t.name,scope:t.scope,plugin:t.plugin,default:t.default,merge:t.merge,template:t.template,implements:t.implements,dryRun:t[`dry-run`]},{display:a}),s=Q({path:a(o.path),hint:o.dryRun?`Nothing was written. Run again without --dry-run to write it.`:`Run \`show ${o.name}\` for the composed document.`,content:o.dryRun?o.content:void 0,hints:o.hints,trace:t.trace&&o.after?Ml(o.after.trace,r):void 0});if(n!==`text`)return R(s);for(let e of o.hints)process.stderr.write(`hint: ${e}\n`);return t.trace&&o.after&&process.stderr.write(Nl(o.after,r)),z(o.dryRun?`${s.path}\n\n${o.content}`:`${s.path}\n\n${s.hint}\n`)}catch(e){return Ol(e,`Reference creation failed.`)}}})}function Yl(e){return M({name:`select`,description:"Choose what a name builds on: write an `extends` listing the options, bottom first, in the project or user file. Its body and other keys are kept.",arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:P.string()},{name:`options`,description:"Bottom first: each a plugin holding the name (or `<plugin>/<name>`), or `default`.",type:P.array(P.string()).optional()}],options:{root:wl,scope:Gl,clear:{description:`Remove the selection; a file left with nothing in it is deleted.`,type:P.boolean().optional()}},async run(t){let n=this.format;try{let r=w(),i=y(t.root??process.cwd()),a=e=>B(r,e),o=xl(await e({root:i},r),{root:i,home:r,name:t.name,options:t.options??[],scope:t.scope,clear:t.clear},{display:a}),s=Q({path:a(o.path),extends:o.extends,deleted:o.deleted||void 0,status:o.after.status,stack:o.after.trace.stack,answer:hl(o.after,a)});if(n!==`text`)return R(s);jl(o.after.warnings);let c=t.clear?o.deleted?`selection cleared; the file was left empty and deleted`:`selection cleared`:`extends: [${o.extends.join(`, `)}]`;return z(`${s.path}\n\n${c}. ${s.answer}\n`)}catch(e){return Ol(e,`Reference selection failed.`)}}})}function Xl(e,t){let n=e.selection?`the selection extends: [${e.selection.join(`, `)}] went with it; run \`reference select ${e.name} <option>...\` to restore it`:void 0;return Q({path:B(t,e.path),dryRun:e.dryRun||void 0,status:e.after.status,stack:e.after.trace.stack,answer:hl(e.after,e=>B(t,e)),selection:n,options:e.after.options})}function Zl(e){return M({name:`delete`,description:`Delete a project or user contribution, or one in a plugin's or a skill's source folder, and report what answers the name afterwards. Never deletes an installed or managed one.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:P.string()}],options:{root:wl,scope:{...Gl,description:`Tier to delete from: project (default) or user.`},plugin:Kl,default:ql,"dry-run":{description:`Print the file that would be deleted and what would answer the name then, and delete nothing.`,type:P.boolean().optional()}},async run(t){let n=this.format;try{let r=w(),i=y(t.root??process.cwd()),a=Cl(await e({root:i,default:t.default},r),{root:i,home:r,name:t.name,scope:t.scope,plugin:t.plugin,default:t.default,dryRun:t[`dry-run`]},{display:e=>B(r,e)}),o=Xl(a,r);if(n!==`text`)return R(o);let s=o.selection?` Also, ${o.selection}.`:``;return z(`${o.path}\n\n${a.dryRun?`would delete`:`deleted`}. ${o.answer}${s}\n`)}catch(e){return Ol(e,`Reference deletion failed.`)}}})}function Ql({plugin:e}={}){let t=Dl(e);return{show:Rl(t),list:zl(t),search:Bl(t),where:Vl(t),create:Jl(t),select:Yl(t),delete:Zl(t),check:Wl(t),implementations:Ul(t)}}function $l(e={}){let{show:t,list:n,search:r,where:i,create:a,select:o,delete:s,check:c,implementations:l}=Ql(e);return M({name:`reference`,description:`Read reference documents by name, composed from the managed, project, user, plugin, and default tiers, and write, select, or delete a contribution.`,commands:[t,n,r,i,a,o,s,l,c]})}function eu({plugin:e}={}){let t=Dl(e,`assets`);return{load:Rl(t,`load`),names:zl(t,`names`),where:Vl(t,!0)}}var $=class extends Error{code;usage;constructor(e,t,n=!1){super(t),this.code=e,this.usage=n}};function tu(e,t,n){let r=y(e);if(ms(r)===void 0)throw new $(`folder-invalid`,`${r} holds no SKILL.md, so it is not a skill folder.`);if(n&&!fl(r,t))throw new $(`folder-invalid`,`${r} is outside the repository, such as an installed copy; write to the skill's source instead.`);return g(r,`assets`)}function nu(e,t){let n=t.split(`/`);if(!t||t.includes(`\\`)||t.startsWith(`/`)||n.some(e=>e===``||e===`.`||e===`..`))throw new $(`path-invalid`,`"${t}" is not an asset path. Use a relative path inside assets/, with "/" separators and no "..".`,!0);return g(e,...n)}function ru(e,t){if(!r(e))return!0;let n=c(e),i=t;for(;!r(i);)i=m(i);let a=c(i);return a===n||a.startsWith(n+b)}function iu(e,t,n){if(!ru(e,t))throw new $(`path-invalid`,`"${n}" leaves the assets/ folder through a link.`,!0)}function au(e,t){let n=tu(e,t,!1),r=[],a=(e,t)=>{let n;try{n=s(e,{withFileTypes:!0})}catch{return}for(let o of n){let n=g(e,o.name),s=i(n);s.isSymbolicLink()||(s.isDirectory()?a(n,`${t}${o.name}/`):s.isFile()&&r.push({path:`${t}${o.name}`,bytes:s.size}))}};return a(n,``),r.sort((e,t)=>e.path.localeCompare(t.path))}function ou(e,t,n){let a=tu(e,t,!1),s=nu(a,n);if(iu(a,s,n),!r(s)||!i(s).isFile())throw new $(`no-file`,`${n} does not exist in assets/.`);let c=o(s);if(c.includes(0))throw new $(`binary`,`${n} is binary (${c.length} bytes); point to it by path instead of showing it.`);return c.toString(`utf8`)}function su(e,t,n,i,o){let s=tu(t,n,!0),c=nu(s,i);iu(s,c,i);let l=r(c);if(e===`create`&&l)throw new $(`exists`,`${i} already exists in assets/; use update to replace it.`);if(e===`update`&&!l)throw new $(`no-file`,`${i} does not exist in assets/; use create to add it.`);return a(m(c),{recursive:!0}),f(c,o),c}function cu(e,t,n){let a=tu(e,t,!0),o=nu(a,n);if(iu(a,o,n),!r(o)||!i(o).isFile())throw new $(`no-file`,`${n} does not exist in assets/.`);l(o);for(let e=m(o);e!==a&&e.startsWith(a+b);e=m(e))try{u(e)}catch{break}return o}function lu(e,t){let i=G(t.name);if(i.invalid||i.plugin!==void 0)throw new $(`name-invalid`,i.invalid??`create takes a bare name.`,!0);if(t.scope!==`project`&&t.scope!==`user`)throw new $(`options-invalid`,`--scope is project or user.`,!0);if(t.copy===`managed`)throw new $(`managed-copy-refused`,`the managed tier is policy and is never copied into a project or user folder. Ask the administrator, or read it with "asset load".`);let o=K(i.name,e).trace.layers.filter(({file:e})=>e),s=o.find(e=>t.copy==="default"||t.copy===`project`||t.copy===`user`?e.tier===t.copy:e.tier===`plugin`&&e.plugin===t.copy);if(!s){let e=o.map(e=>e.tier===`plugin`?e.plugin:e.tier);throw new $(`no-source`,`"${t.copy}" holds no asset "${i.name}". Held by: ${e.filter(e=>e!==`managed`).join(`, `)||`nothing`}.`)}let c=h(s.path);if(s.file&&![...W.map(e=>e.extension),`.md`].includes(c))throw new $(`no-source`,`${p(s.path)} is not a file an asset name resolves to.`);let l=t.scope===`user`?gc(t.home):hc(y(t.root)),u=g(m(l),`assets`),d=[`.md`,...W.map(e=>e.extension)].map(e=>g(u,`${i.name}${e}`)).find(e=>r(e));if(d)throw new $(`exists`,`${d} already exists; edit it, or delete it first.`);let f=g(u,`${i.name}${c}`);return a(u,{recursive:!0}),n(s.path,f),{path:f,source:s.path,from:t.copy}}function uu(e,t){let n=K(t,e).trace.layers;return[...n.filter(({tier:e,file:t})=>e===`plugin`&&t).map(({plugin:e})=>e),...n.some(({tier:e,file:t})=>e==="default"&&t)?[`default`]:[]]}function du(e,t){let n=G(t.name);if(n.invalid||n.plugin!==void 0)throw new $(`name-invalid`,n.invalid??`select takes a bare name.`,!0);if(t.scope!==void 0&&t.scope!==`project`&&t.scope!==`user`)throw new $(`options-invalid`,`--scope is project or user.`,!0);let i=t.scope===`user`?gc(t.home):hc(y(t.root)),o=g(m(i),`assets`,`${n.name}.select`);if(t.clear){if(!r(o))throw new $(`no-file`,`${o} does not exist, so there is no selection to clear.`);l(o)}else{let r=uu(e,n.name);if(!t.option||!r.includes(t.option))throw new $(`option-invalid`,`"${t.option??``}" cannot be selected for "${n.name}". Options: ${r.join(`, `)||`none, no plugin or default holds it`}.`,!t.option);a(m(o),{recursive:!0}),f(o,`${t.option}\n`)}let s={path:o,cleared:!!t.clear,after:K(n.name,e,{without:t.clear?o:void 0})};return t.clear?s:{...s,selected:t.option}}const fu={description:"A skill's source folder in this repository: its `assets/` folder is acted on.",type:P.string()},pu={description:`The directory the repository is found from. Defaults to the current directory.`,type:P.string().optional()};function mu(e,t){throw ae(e)?e:e instanceof $?(process.stderr.write(`error: ${e.code}: ${e.message}\n`),j.reported(e.usage?A.usage:A.error)):(process.stderr.write(`error: ${e instanceof Error?e.message:t}\n`),j.reported(A.error))}function hu(e){throw process.stderr.write(`error: usage: ${e}\n`),j.reported(A.usage)}const gu="Asset path inside `assets/`, such as `data/rules.json`.";function _u(e){return y(e.root??process.cwd())}function vu(){return M({name:`list`,description:`List every file in a skill's assets/ folder with its size.`,options:{skill:fu,root:pu},async run(e){try{let t=au(e.skill,_u(e));return R({assets:t.length?t:`0 assets — the skill holds none`})}catch(e){return mu(e,`Asset listing failed.`)}}})}function yu(){return M({name:`show`,description:`Print a text asset as written.`,arguments:[{name:`path`,description:gu,type:P.string()}],options:{skill:fu,root:pu},async run(e){try{return z(ou(e.skill,_u(e),e.path))}catch(e){return mu(e,`Asset read failed.`)}}})}function bu(e,t){let n=e===`create`;return M({name:e,description:n?`Add a new asset: by path in a skill from --content or --from, or, with --copy, by name in the project or user assets folder as a copy of what a plugin, the default, or another tier holds (never the managed tier). Never overwrites a file.`:`Replace an existing asset from --content or --from.`,arguments:[{name:`path`,description:`${gu} With --copy, the asset name.`,type:P.string()}],options:{skill:{...fu,type:P.string().optional()},root:pu,content:{description:`The text to write.`,type:P.string().optional()},from:{description:`A local file whose bytes to write.`,type:P.string().optional()},...n?{default:{description:"With --copy, the calling skill's folder: its `assets/<name>.<ext>` is the `default` source.",type:P.string().optional()},copy:{description:"Copy the asset of this source: a plugin's name, `default` (the skill's own file), `project`, or `user`. `managed` is refused.",type:P.string().optional()},scope:{description:"With --copy, where the copy goes: project (default), `.agents/assets/`, or user, `~/.agents/assets/`.",type:P.string().optional()}}:{}},async run(r){try{if(r.copy!==void 0){(r.content!==void 0||r.from!==void 0)&&hu(`--copy takes neither --content nor --from.`);let e=w(),n=_u(r),i=lu(await Ac({root:n,home:e,platform:process.platform,env:process.env,plugin:t.plugin,defaultSkill:r.default??r.skill,folder:`assets`}),{root:n,home:e,name:r.path,scope:r.scope??`project`,copy:r.copy});return z(`${i.path}\n\ncopied from ${i.from}. Edit it; it now answers over the plugin tier.\n`)}r.skill||hu(`pass --skill, or --copy to create an override by name.`),r.content===void 0==(r.from===void 0)&&hu(`pass exactly one of --content and --from.`);let i=r.content??o(y(r.from),`utf8`);return z(`${su(e,r.skill,_u(r),r.path,i)}\n\n${n?`created`:`updated`}.\n`)}catch(t){return mu(t,`Asset ${e} failed.`)}}})}function xu(){return M({name:`delete`,description:`Delete an asset from a skill's source folder, and any folder it leaves empty.`,arguments:[{name:`path`,description:gu,type:P.string()}],options:{skill:fu,root:pu},async run(e){try{return z(`${cu(e.skill,_u(e),e.path)}\n\ndeleted.\n`)}catch(e){return mu(e,`Asset deletion failed.`)}}})}function Su(e){return M({name:`select`,description:"Choose which plugin, or the skill itself, answers an asset name that several hold, by writing `<name>.select` in the project or user assets folder.",arguments:[{name:`name`,description:`Asset name, without its extension.`,type:P.string()},{name:`option`,description:"A plugin name, or `default` for the skill's own file. Not used with --clear.",type:P.string().optional()}],options:{root:pu,default:{description:"The calling skill's folder: its `assets/<name>.<ext>` is the `default` option.",type:P.string().optional()},scope:{description:"Where to write: project (default), `.agents/assets/`, or user, `~/.agents/assets/`.",type:P.string().optional()},clear:{description:`Remove the selection.`,type:P.boolean().optional()}},async run(t){try{let n=w(),r=y(t.root??process.cwd()),i=du(await Ac({root:r,home:n,platform:process.platform,env:process.env,plugin:e.plugin,defaultSkill:t.default,folder:`assets`}),{...t,root:r,home:n}),a=i.after.status===`found`?`${t.name} now answers from ${i.after.trace.stack.join(`, `)||`a tier`}.`:`${t.name} is ${i.after.status}: ${i.after.message??``}`;return z(`${i.path}\n\n${i.cleared?`selection cleared`:`selected ${i.selected}`}. ${a}\n`)}catch(e){return mu(e,`Asset selection failed.`)}}})}function Cu(e={}){let{load:t,names:n,where:r}=eu(e);return M({name:`asset`,description:`Manage a skill's assets/ files by path (list, show, create, update, delete), and load one by name through the tiers (load, names, where, select).`,commands:[vu(),yu(),bu(`create`,e),bu(`update`,e),xu(),t,n,r,Su(e)]})}const wu=[`e.g.`,`i.e.`,`etc.`,`vs.`],Tu=/^\s*(`{3,}|~{3,})/,Eu=/^#{1,6}\s/,Du=/^\s*(?:[-*+]|\d+[.)])\s/,Ou=/^\s*\|/,ku=/^\s*>/;function Au(e){return wu.some(t=>{if(!e.endsWith(t))return!1;let n=e.length-t.length;return n===0||/\s/.test(e[n-1])})}function ju(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(!`.;?!`.includes(e[r]))continue;let i=e[r+1];(i===void 0||/\s/.test(i))&&(e[r]===`.`&&Au(e.slice(n,r+1))||(t.push(e.slice(n,r+1)),n=r+1))}return t.push(e.slice(n)),t.map(e=>e.trim()).filter(Boolean)}function Mu(e){let t=e.split(/\r?\n/),n=[],r=[],i=!1,a=()=>n.length===0?``:i?`
|
|
201
|
+
`)}\n`:``,projectSections:e.status===`found`?e.projectSections:[],resolved:e};return n!==void 0&&(i.stub=`${n}\n`),i}function bd(e){return(Array.isArray(e)?[]:e.skills?.skills??[]).flatMap(e=>Dl(Au(e.folder)).map(t=>({name:t,skill:e}))).sort((e,t)=>e.name.localeCompare(t.name)||e.skill.name.localeCompare(t.skill.name))}function xd(e){return Array.isArray(e)?void 0:e.skills?.unverified}function Sd(e,t){let n=Array.isArray(e)?{layers:[...e],harnesses:[]}:e;return{...n,layers:[...n.layers.filter(({tier:e})=>e!=="default"),Au(t)]}}function Cd(e){let t=e.split(`*`).map(e=>e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`));return RegExp(`^${t.join(`.*`)}$`,`s`)}function wd(e){return typeof e==`string`&&e.split(`
|
|
202
|
+
`)[0]?.trim()||``}function Td(e,t,n){for(let r of n){let n=`${r.code} ${r.message}`;t.has(n)||e.push(r),t.add(n)}}function Ed(e,t){let n={name:e,tier:t.tier,path:t.path,description:wd(t.description),outcome:t.outcome};return t.plugin!==void 0&&(n.plugin=t.plugin),t.skill!==void 0&&(n.skill=t.skill),t.selection?n.kind=`selection`:Xc(t.frontmatter)&&(n.kind=`generated`),n}function Dd(e,t){return{name:e,tier:`project`,path:t.path,description:wd(t.frontmatter?.description),outcome:t.outcome,kind:`project-section`,folder:t.folder,...t.plugin===void 0?{}:{plugin:t.plugin}}}function Od(e){let t=Array.isArray(e)?void 0:e,n=t?.root===void 0?[]:sd(t.root,t.projects,Ju(t)),r=Kl(e);return[...new Set([...hd(e),...n].map(e=>Zl(e,r)))]}function kd(e,t={}){let{pattern:n,...r}=t,i=n===void 0?void 0:Cd(n),a={references:[],layers:[],warnings:[]},o=xd(e);o&&(a.defaults=o);let s=/* @__PURE__ */ new Set,c=bd(e),l=[.../* @__PURE__ */ new Set([...Od(e),...c.map(({name:e})=>e)])].sort((e,t)=>e.localeCompare(t));for(let t of l){if(i&&!i.test(t))continue;let n=c.filter(e=>e.name===t),o=Z(t,e,r);!(o.trace.layers.some(({file:e,tier:t})=>e&&t!=="default")||o.trace.projectSections.some(({file:e})=>e))&&n[0]&&(o=Z(t,Sd(e,n[0].skill.folder),r)),Td(a.warnings,s,o.warnings);let l={name:t,description:o.status===`found`?wd(o.metadata?.description):``,status:o.status};if(o.code&&(l.code=o.code),o.format&&o.format!==`markdown`&&(l.format=o.format),o.options){let e=n.map(({skill:e})=>`default of ${e.name}`);l.options=[.../* @__PURE__ */ new Set([...o.options.filter(e=>e!=="default"),...e])]}a.references.push(l);for(let e of o.trace.layers)e.file!==void 0&&e.tier!=="default"&&a.layers.push(Ed(t,e));for(let e of o.trace.projectSections)e.file!==void 0&&a.layers.push(Dd(t,e));for(let{skill:i}of n)a.layers.push(Ad(t,i.name,i.folder,e,r))}return a}function Ad(e,t,n,r,i){return{...Ed(e,Z(e,Sd(r,n),i).trace.layers.find(({tier:e,file:t})=>e==="default"&&t)),reachedBy:`the default step, when ${t} loads ${e}`}}const jd=[`name`,`prefix`,`close name`,`description`,`heading`,`body`];function Md(e,t){let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=n[a-1]+(e[r-1]===t[a-1]?0:1);i.push(Math.min(n[a]+1,i[a-1]+1,o))}n=i}return n[t.length]}function Nd(e){let t=!1,n=[];for(let r of e.split(`
|
|
203
|
+
`))/^ {0,3}(`{3,}|~{3,})/.test(r)?t=!t:!t&&/^ {0,3}#{1,6}\s/.test(r)&&n.push(r);return n.join(`
|
|
204
|
+
`)}function Pd(e){return Array.isArray(e)?e.map(String).join(` `):typeof e==`string`?e:``}function Fd(e,t,n){let r=e.slice(e.lastIndexOf(`/`)+1).toLowerCase();if(r===n||e.toLowerCase()===n)return`name`;if(r.startsWith(n))return`prefix`;if(r.includes(n)||Md(r,n)<=Math.max(1,Math.floor(n.length/4)))return`close name`;let i=n.split(/\s+/),a=e=>{let t=e.toLowerCase();return i.every(e=>t.includes(e))},o=t.metadata??{};return a(`${typeof o.description==`string`?o.description:``} ${Pd(o.tags)}`)?`description`:Id(t.content??``,a)}function Id(e,t){if(t(Nd(e)))return`heading`;if(t(e))return`body`}function Ld(e,t){let n=t.split(/\s+/),r=e=>{let t=e.toLowerCase();return n.every(e=>t.includes(e))},{metadata:i}=e;return r(`${typeof i.description==`string`?i.description:``} ${Pd(i.tags)}`)?`description`:Id(e.content,r)}function Rd(e,t,n={}){let r=e.trim().toLowerCase();if(!r)throw new q(`query-missing`,`search needs a query: what the reference is about.`,{help:"Run `reference list` for every name."});let i=[],a=/* @__PURE__ */ new Set,o=e=>{let t=J(e.name).name;for(let n of e.projectSections){let o=`${t}\0${n.folder}\0${n.plugin??``}`;if(a.has(o))continue;a.add(o);let s=Ld(n,r);s&&i.push({name:e.name,description:wd(n.metadata.description),match:s,tier:`project`,folder:n.folder,...n.plugin===void 0?{}:{plugin:n.plugin}})}},s=(e,t)=>{if(e.status!==`found`)return;o(e);let n=Fd(e.name,e,r);if(!n)return;let a=e.trace.contributions.at(-1),s={name:e.name,description:wd(e.metadata?.description),match:n,tier:a?.tier??`plugin`};a?.plugin!==void 0&&(s.plugin=a.plugin),a?.skill!==void 0&&(s.skill=a.skill),t!==void 0&&(s.loadedBy=t),i.push(s)},c=/* @__PURE__ */ new Map;for(let e of Od(t)){let r=Z(e,t,n);if(c.set(e,r.content),r.status!==`ambiguous`)s(r);else for(let e of r.options??[])e!=="default"&&s(Z(e,t,n))}for(let{name:e,skill:r}of bd(t)){let i=Z(e,Sd(t,r.folder),n);i.trace.layers.some(({tier:e,outcome:t})=>e==="default"&&t===`used`)&&i.content!==c.get(e)&&s(i,r.name)}i.sort((e,t)=>jd.indexOf(e.match)-jd.indexOf(t.match)||e.name.localeCompare(t.name)||Ru(e.folder??``,t.folder??``));let l=xd(t);return l?{matches:i,defaults:l}:{matches:i}}const zd={"frontmatter-invalid":`defect`,"merge-unknown":`defect`,"marker-unknown":`defect`,"marker-unmatched":`defect`,"heading-repeated":`defect`,"remove-body-ignored":`defect`,"extends-invalid":`defect`,"extends-self":`defect`,"extends-step-missing":`environment`,"extends-all-missing":`environment`,"extends-not-used":`environment`,"section-not-held":`environment`,"default-not-selected":`environment`,"plugin-not-selected":`environment`,"default-folder-missing":`environment`,"default-in-tier":`defect`,"file-ignored":`defect`,"format-mismatch":`defect`,"metadata-ignored":`defect`,"project-section-key-ignored":`project-section`,"interface-not-composed":`defect`,"interface-check":`environment`,"base-moved":`environment`,"reference-stale":`environment`,"reference-renamed":`environment`,"alias-not-used":`environment`,"alias-invalid":`defect`,"project-section-not-markdown":`project-section`,"reference-hidden":`environment`,"repo-hides-user":`environment`};function Bd(e){let t=[],n=[];for(let r of e){let e=zd[r.code];e===`defect`?t.push(r):e===`environment`&&n.push(r)}return{defects:t,passed:n}}function Vd(e,t){let n=[],r=(e,n)=>`${t(e)} is hidden: ${n} applies above it, so load does not read it until that contribution changes`;for(let i of e.trace.layers){if(i.tier!==`repo`&&i.tier!==`user`||!i.file)continue;let a=Wc(e,i.path,i.path);a&&n.push({code:i.tier===`user`&&a.tier===`repo`?`repo-hides-user`:`reference-hidden`,message:r(i.path,Uc(a,t))})}let i=Gc(e);if(i)for(let a of e.trace.projectSections)a.file&&a.plugin===void 0&&a.outcome.startsWith(`shadowed by`)&&n.push({code:`reference-hidden`,message:r(a.path,Uc(i,t))});return n}function Hd(e,t){let n=[],r;for(let i of e.trace.layers){if(i.tier!==`plugin`&&i.tier!=="default"||!i.file||!i.frontmatter||i.outcome!==`used`&&i.outcome!==`stale`)continue;let{sources:e}=Yc(i.frontmatter);if(!e)continue;r??=Zc(t,{tier:`plugin`});let a=i.tier===`plugin`?`plugin ${i.plugin}`:`default of ${i.skill}`;for(let t of Qc(e,r)){if(t.status!==`changed`)continue;let e=t.default===void 0?`plugin ${t.plugin}`:`the default of ${t.default} (plugin ${t.plugin})`;n.push({code:`base-moved`,message:`${a}: it records ${e} at ${t.recorded}, and ${t.installed??`a version with no number`} is installed; review it against the installed base and record the new version`})}}return n}function Ud(e,t={}){let n=/* @__PURE__ */ new Map;return r=>{let i=n.get(r);if(i)return i;let a=Wd(r,e,t);return n.set(r,a),a}}function Wd(e,t,n){let r=Z(`${e}${Ol}`,t,n);if(r.status===`missing`){let r=[...Kl(t).interfaces].filter(([,t])=>t.some(({alias:t})=>t===e)).map(([e])=>e);if(r.length>1)return Gd(e,`${e} is an older id of ${r.join(` and `)}; implement one of them by its own id`);if(r.length===1){let e=r[0],i=Kd(e,Z(`${e}${Ol}`,t,n));return i.value?{...i,renamed:e}:i}}return Kd(e,r)}function Gd(e,t){return{failure:{check:`interface-found`,interface:e,message:t}}}function Kd(e,t){let n=`${e}${Ol}`;if(t.status===`invalid`)return Gd(e,`${e} is not an interface id`);if(t.status===`missing`)return Gd(e,`no interface document ${n}`);if(t.status===`ambiguous`)return Gd(e,`${n} is ambiguous between ${(t.options??[]).join(` and `)}`);let{value:r,problems:i}=Il(e,t.metadata??{});return r?{value:r}:Gd(e,`${n} is malformed: ${i.join(`; `)}`)}function qd(e){return e.slice(e.lastIndexOf(`/`)+1)}function Jd(e){let t=e.metadata??{};return Al(qd(e.name))!==void 0||t.interface!==void 0?`interface`:t.implements===void 0?`none`:`implementation`}function Yd(e){let{defects:t}=Bd(e);if(t.length)return{check:`compose`,message:`composing it raised ${t.length===1?`a warning`:`${t.length} warnings`}: ${t.map(({code:e,message:t})=>`${e}: ${t}`).join(`; `)}`}}function Xd(e,t,n){let r={failures:[],unsupported:[],warnings:[]};if(e.status!==`found`)return r;let{failures:i,warnings:a}=r,o=qd(e.name),s=e.metadata??{};if(Jd(e)===`interface`){let e=Al(o);if(e===void 0)i.push({check:`interface`,message:`${o} has an \`interface:\` block; an interface document is named <id>${Ol}`});else for(let t of Il(e,s).problems)i.push({check:`interface`,interface:e,message:t})}else{let{entry:c,problems:l}=Ll(s);for(let e of l)i.push({check:`interface-found`,message:e});if(c){let s=t(c.id);if(s.value){let t=s.value.id;s.renamed!==void 0&&a.push({code:`reference-renamed`,message:`implements names ${c.id}@${c.version}, an older id of ${t}; declare implements: ${t}@${c.version}`});let l=Bl(s.value,{name:o,version:c.version,content:e.content??``,accept:n?.id===t?n.versions:void 0,declaredId:c.id});i.push(...l.failures),r.unsupported=l.unsupported}else i.push(s.failure)}}let c=Yd(e.warnings);return c&&i.push(c),r}function Zd(e){let t=/* @__PURE__ */ new Set;return e.filter(({code:e,message:n})=>{let r=`${e} ${n}`;return!t.has(r)&&(t.add(r),!0)})}const Qd=({code:e,message:t})=>`${e} ${t}`;function $d({main:e,full:t}){if(t===e)return[];let n=new Set(e.warnings.map(Qd));return t.warnings.filter(e=>!n.has(Qd(e)))}function ef(e,t,n=[]){let{main:r,full:i}=e,a=r.status===`found`||i.status===`found`,o=r.status===`found`?Xd(r,t):{failures:[],unsupported:[],warnings:[]},s=[...o.failures];if(r.status!==`found`){!a&&r.code!==`reference-removed`&&s.push({check:r.code,message:r.message??r.status});let e=Yd(r.warnings);e&&s.push(e)}return{name:r.name,kind:r.status===`found`?Jd(r):`none`,status:a?s.length?`failed`:`passed`:r.status,failures:s,unsupported:o.unsupported,warnings:Zd([...o.warnings,...Bd(r.warnings).passed,...$d(e),...n])}}function tf(e,t){let n=[...new Set(t.trace.layers.flatMap(({plugin:e,file:t})=>e!==void 0&&t?[e]:[]))];return n.length>1?n.map(t=>`${t}/${e}`):[]}function nf(e,t={}){let{names:n,...r}=t,i=r.display??(e=>e),a={...r,projectSections:!1},o=Ud(e,r),s=Array.isArray(e)?void 0:e,c=new Set(s?.root===void 0?[]:sd(s.root,s.projects,Ju(s))),l=t=>{let n=J(t),i=Z(n,e,a);return{main:i,full:n.plugin===void 0&&c.has(n.name)?Z(n,e,r):i}},u=({main:t,full:n})=>[...Vd(n,i),...Hd(t,e)];if(n?.length)return n.map(e=>{let t=l(e);return ef(t,o,u(t))});let d=[],f=/* @__PURE__ */ new Map;for(let t of Od(e)){let n=l(t);f.set(t,n.main.content),d.push(ef(n,o,u(n)));for(let r of tf(t,n.main).map(l))d.push(ef(r,o,Hd(r.main,e)))}for(let{name:t,skill:n}of bd(e)){let r=Sd(e,n.folder),i=Z(t,r,a),s=i.trace.layers.some(({tier:e,outcome:t})=>e==="default"&&t===`used`);if(i.status!==`found`||!s)continue;let c=Hd(i,r);(i.content!==f.get(t)||c.length)&&d.push({...ef({main:i,full:i},o,c),loadedBy:n.name})}return d}function rf(e){ol(e);let t=J(e);if(t.invalid)throw new q(`name-invalid`,t.invalid);if(t.plugin!==void 0)throw new q(`reference-qualified`,`a contribution is written under the bare name, which every tier resolves; ask for "${t.name}".`);return t}function af(e,t){let n=Tu(b(t)),r=Tu(e);return r!==n&&!r.startsWith(n+x)?!1:!r.slice(n.length).split(x).includes(`node_modules`)}function of(e,t){let n=y(e,t);return n&&!n.startsWith(`..`)&&!g(n)?n:void 0}function sf(e,t){let n=b(e),r=of(b(t),n)??of(Tu(b(t)),Tu(n));if(r===void 0)throw new q(`in-not-below-root`,`--in names ${n}, which is ${n===b(t)?`the root itself`:`outside the root`}; a project section is written for a folder strictly below the root ${b(t)}.`);return{folder:r.split(x).join(`/`),path:n}}function cf(e,t){if([e.scope,e.in,e.plugin,e.default].filter(e=>e!==void 0).length>1)throw new q(`options-conflict`,`pass one of ${t}.`)}function lf(e){if(e!==void 0&&e!==`repo`&&e!==`user`)throw new q(`option-invalid`,`--scope is repo or user; got "${e}".`)}function uf(e,t,n){let r=b(e);if(!(n===`plugin`?Bi(r):so(r)!==void 0))throw new q(`folder-invalid`,n===`plugin`?`${r} holds no plugin manifest, so it is not a plugin folder.`:`${r} holds no SKILL.md, so it is not a skill folder.`);if(!af(r,t))throw new q(`folder-invalid`,`${r} is outside the repository, such as an installed copy; write to the ${n}'s source instead.`);return r}function df(e,t){let{root:n,home:r,scope:i,plugin:a,default:o}=t;if(a!==void 0){let t=_(uf(a,n,`plugin`),`references`);return{scope:`plugin`,dir:t,path:_(t,`${e.name}.md`)}}if(o!==void 0){let t=_(uf(o,n,`skill`),`references`);return{scope:`default`,dir:t,path:_(t,`${e.name}.default.md`)}}if(t.in!==void 0){let{folder:r,path:i}=sf(t.in,n),a=_(i,`.agents`,`references`);return{scope:`project`,dir:a,path:_(a,`${e.name}.md`),folder:r,folderPath:i}}let s=i===`user`?yu(r):vu(b(n));return{scope:i===`user`?`user`:`repo`,dir:s,path:_(s,`${e.name}.md`)}}function ff(e,t){return Sl({tier:e.scope==="default"?`default`:`repo`},t).map(t=>_(e.dir,...t.split(`/`)))}function pf(e,t,n){return ff(e,t).find(e=>e!==n&&r(e))}function mf(e,t){return _(e.dir,`${t}${e.scope==="default"?`.default`:``}.meta.md`)}function hf(e){return e.scope===`user`?`only you, in every repository`:e.scope===`project`?`everyone working in ${e.folder}`:`everyone working in this repository`}const gf=`a project section carries no merge (K24); drop --merge or --in.`;function _f(e,t){if(e.includes(`none`)){if(e.length>1)throw new q(`option-invalid`,`--extends none removes the picks, so it takes no other step; got ${e.join(` `)}.`);return`none`}if(!e.length)throw new q(`option-invalid`,`--extends names one or more steps, or none.`);return{values:e.map(e=>{let n=e.indexOf(`:`),r=n===-1?e:e.slice(0,n),i=n===-1?void 0:e.slice(n+1),a=r.endsWith(`/${t}`)?r.slice(0,-t.length-1):r;if(!il.test(a))throw new q(`option-invalid`,`--extends takes a plugin, \`<plugin>/${t}\`, or default, each optionally \`:<merge>\`; got "${e}".`);if(i===void 0)return a;if(!ac(i))throw new q(`option-invalid`,`the merge in "${e}" is replace, patch, combine, or remove; got "${i}".`);return{[a]:i}})}}function vf(e,t){let n=e.extends!==void 0||e.extendsFile!==void 0,r=e.request!==void 0||e.body!==void 0;if(!e.base&&!n&&!r)throw new q(`change-missing`,`say what to change: --extends or --extends-file picks what the name builds on, and --request with --body writes a generated body.`,{help:`Run \`reference customize ${t.name} --base\` for what the generator reads.`});let i=e=>new q(`options-conflict`,e);if(e.plugin!==void 0)throw i("customize never writes a file a plugin ships; an author writes one with `create --plugin`.");if(e.scope!==void 0&&e.in!==void 0)throw i(`pass --scope or --in, not both: a customization goes to one place.`);if(e.in!==void 0&&e.merge!==void 0)throw i(gf);if(e.in!==void 0&&n)throw i(`a project section has no stack, so it takes no picks; pick for the main document with --scope.`);if(e.extends!==void 0&&e.extendsFile!==void 0)throw i(`pass --extends or --extends-file, not both.`);if(e.implements!==void 0&&n)throw i(`an implementation is a whole document that replaces the stack, so it takes no picks.`);if(e.base&&(r||e.merge!==void 0||e.dryRun))throw i(`--base writes nothing; it takes only --extends or --extends-file, --scope or --in, --default, and --implements.`);if(r&&e.extends?.includes(`none`))throw i(`--extends none removes the picks and writes no body; pass it without --request and --body.`);if(r&&(e.request===void 0||e.body===void 0))throw new q(`options-missing`,e.request===void 0?`--body needs --request: a generated body records the request it was written from.`:`--request needs --body: the command writes the body the generator wrote, and runs no model.`);lf(e.scope),yf(e.merge);let a=e.extends===void 0?void 0:_f(e.extends,t.name);return e.in!==void 0&&sf(e.in,e.root),a?{picks:a}:{}}function yf(e){if(e!==void 0&&!ac(e))throw new q(`option-invalid`,`--merge is replace, patch, combine, or remove; got "${e}".`)}function bf(e){let t=rf(e.name);if(e.command===`customize`)return{name:t,merge:e.merge,...vf(e,t)};if(cf(e,`--scope, --in, --plugin, and --default`),e.command===`create`&&e.in!==void 0&&e.merge!==void 0)throw new q(`options-conflict`,gf);lf(e.scope),yf(e.merge);let n=e.merge;if(e.in!==void 0&&sf(e.in,e.root),e.command===`create`){if(n===`remove`&&e.template!==void 0)throw new q(`remove-with-template`,`--merge remove writes no body, so it takes no --template.`);if(e.template!==void 0&&e.implements!==void 0)throw new q(`template-with-implements`,`pass --template or --implements, not both.`)}return{name:t,merge:n}}function xf(e,t,n){let r=J(e);if(r.invalid||r.plugin!==void 0)throw new q(`interface-invalid`,`"${e}" is not an interface id.`);let i=Ud(t,n)(e);if(!i.value)throw new q(`interface-invalid`,i.failure?.message??`no interface ${e}`);return i.value}function Sf(e){try{return o(e,`utf8`)}catch{return}}function Cf(e,t,n,r){if(t.scope===`project`)return;if(e.implements!==void 0)return`replace`;if(t.scope===`plugin`||t.scope==="default")return n;let i=r.metadata.merge;return n??(ac(i)?i:void 0)??`patch`}function wf(e,t,n={}){let r=bf(e);if(!t)return r;let{name:i,merge:a}=r,o=n.display??(e=>e);if(!xu(e.root))throw new q(`root-missing`,`the root ${e.root} does not exist or is not a folder.`,{details:{root:e.root}});if(e.command===`customize`)return Rf(e,r,t,n);let s=df(i,e);if(e.command===`delete`)return Ef(s,i.name),{name:i,merge:a,target:s,before:Z(i,t,n),extended:[]};let c=e.implements!==void 0||a===`remove`?{content:``,metadata:{},body:``}:Mc(e.template),l=Pc(c);if(l)throw new q(`template-title`,`the template's top level is the single heading "${l}" holding the others; patch matches by heading path, so make its sections top-level.`);let u=e.implements===void 0?void 0:xf(e.implements,t,n);Df(u,s,i);let d=u?jc(u):c;Ef(s,i.name);let f=Z(i,t,n);Of(f,s,i);let p={name:i,merge:a,target:s,template:d,before:f,extended:[]};u&&(p.iface=u);let m=Sf(s.path),h=m===void 0?void 0:K(m,()=>{});if(p.operation=Cf(e,s,a,d),p.extended=(Y(h?.metadata.extends,()=>{})??Y(d.metadata.extends,()=>{})??[]).map(({target:e})=>e).filter(e=>e!=="default"),(s.scope===`plugin`||s.scope==="default")&&p.operation===`replace`&&p.extended.length)throw new q(`extends-replace`,`a ${s.scope===`plugin`?`plugin's file`:`skill's default`} that extends ${p.extended.join(`, `)} states only the sections it changes, so it takes no merge: replace; to replace the base entirely, write a snapshot of your own with no extends on it.`);if(h&&cc(h.body))throw new q(`file-exists`,`${o(s.path)} already holds "${i.name}"; change it with the reference skill's Update mode.`,{details:{path:o(s.path)}});let g=pf(s,i.name,s.path)??Tf(s,i.name);if(g)throw new q(`file-exists`,`${o(g)} already answers "${i.name}" in that folder; change it there, or delete it first.`,{details:{path:o(g)}});return m!==void 0&&(p.existing=m),p}function Tf(e,t){if(e.scope===`project`)return;let n=mf(e,t),r=Ff(Sf(n));return r&&r.metadata.extends!==void 0?n:void 0}function Ef(e,t){if(e.scope===`project`&&e.folderPath!==void 0&&e.folder!==void 0){if(!xu(e.folderPath))throw new q(`in-folder-missing`,`--in names ${e.folderPath}, which does not exist.`,{details:{folder:e.folder}});if(Hu(e.folderPath,e.path))throw new q(`in-folder-ignored`,`git ignores ${e.folder}/.agents/references/${t}.md, so load would never read a project section there.`,{details:{folder:e.folder}})}}function Df(e,t,n){if(!e||t.scope===`project`||Rl(e,n.name))return;let r=e.cardinality===`one`?e.id:`${e.id}.<key>`;throw new q(`name-outside-interface`,`an implementation of ${e.id} is named ${r}, not "${n.name}".`,{help:`Name it ${r}, or write it for one folder with --in.`})}function Of(e,t,n){if(t.scope===`project`&&e.status===`found`&&e.format!==`markdown`)throw new q(`in-not-markdown`,`the main document of "${n.name}" is ${e.format}, which has no project sections; customize the main document instead.`)}function kf(e,t){try{return o(e,`utf8`)}catch(n){throw new q(`file-unreadable`,`cannot read the ${t} file ${e}: ${n.message}`,{details:{path:e}})}}function Af(e){if(typeof e==`string`)return il.test(e);if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.entries(e);if(t.length!==1)return!1;let[n,r]=t[0];if(!il.test(n))return!1;if(r==null)return!0;if(typeof r==`string`)return ac(r);if(typeof r!=`object`||Array.isArray(r))return!1;let i=r;return Object.keys(i).some(e=>e!==`merge`&&e!==`extends`&&e!==`sections`)||i.merge!==void 0&&!ac(i.merge)||i.sections!==void 0&&!Array.isArray(i.sections)?!1:i.extends===void 0||Array.isArray(i.extends)&&i.extends.every(Af)}function jf(e){let t=t=>new q(`extends-file-invalid`,`the --extends-file ${e} ${t}.`,{details:{path:e}}),n;try{n=o(e,`utf8`)}catch(e){throw t(`cannot be read: ${e.message}`)}let r;try{r=(0,ao.parse)(n)}catch(e){throw t(`is not YAML: ${e.message}`)}let i=r&&typeof r==`object`&&!Array.isArray(r)?r.extends:r;if(!Array.isArray(i)||!i.length||!i.every(Af))throw t("is not a YAML `extends` list: each step a plugin or default, with only merge, extends, and sections");return{values:i}}function Mf(e){if(e===void 0)return;if(e===`none`)return null;let t=e=>{if(typeof e!=`object`||!e)return e;let[n,r]=Object.entries(e)[0];if(typeof r!=`object`||!r)return e;let{sections:i,extends:a,...o}=r;return{[n]:Array.isArray(a)?{...o,extends:a.map(t)}:o}};return Y(e.values.map(t),()=>{})??[]}function Nf(e,t,n,r){let i=new Set(r.layers.flatMap(({tier:e,plugin:t,skipped:n})=>e===`plugin`&&t&&!n?[t]:[])),a=new Set(n.trace.layers.flatMap(({tier:e,plugin:t,file:n})=>e===`plugin`&&t!==void 0&&n&&i.has(t)?[t]:[])),o=e.map(({target:e})=>e).filter(e=>e!=="default"&&!a.has(e));if(o.length)throw new q(`step-invalid`,`${o.join(`, `)} ${o.length===1?`is`:`are`} neither default nor a plugin holding "${t}"${a.size?`; the plugins holding it are ${[...a].join(`, `)}`:``}.`,{details:{steps:o}})}function Pf(e,t,n){let r=Ud(t,n),i=e.split(`.`);for(let t=i.length;t>=1;t--){let n=r(i.slice(0,t).join(`.`)).value;if(n&&Rl(n,e))return n}}function Ff(e){return e===void 0?void 0:K(e,()=>{})}function If(e,t,n){let r=e.scope===`project`?[e.path,_(e.dir,t,`README.md`)]:[e.path,_(e.dir,t,`README.md`),...Lc.map(({extension:n})=>_(e.dir,`${t}${n}`))],i=pf(e,t),a=i!==void 0&&r.includes(i)?i:void 0,o=_(e.dir,t,`README.md`),s=e.path,c=`markdown`;if(a!==void 0&&a!==o)s=a,c=Rc(a);else if(a===void 0&&e.scope!==`project`&&n.status===`found`&&n.format!==void 0&&n.format!==`markdown`){c=n.format;let r=[...n.trace.contributions].reverse().find(({path:e})=>Rc(e)===c),i=r?h(r.path):Lc.find(e=>e.format===c)?.extension;s=_(e.dir,`${t}${i}`)}return{file:s,format:c,holder:c===`markdown`?s:mf(e,t),other:a===o?o:void 0}}function Lf(e,t,n){let r=Array.isArray(e)?e[0]:e,i=typeof r==`string`?/^(.+)@\d+$/.exec(r.trim())?.[1]:void 0;return i===void 0?void 0:Ud(t,n)(i).value}function Rf(e,t,n,r){let{name:i}=t,a=r.display??(e=>e),o=df(i,{root:e.root,home:e.home,scope:e.scope,in:e.in}),s=e.request===void 0?void 0:kf(e.request,`--request`),c=e.body===void 0?void 0:kf(e.body,`--body`),l=e.extendsFile===void 0?t.picks:jf(e.extendsFile),u=e.implements===void 0?void 0:xf(e.implements,n,r);Df(u,o,i),Ef(o,i.name);let d=Z(i,n,r);Of(d,o,i);let f=Mf(l);f&&Nf(f,i.name,d,gd(n,o));let p=If(o,i.name,d),m=Sf(p.file),h=p.holder===p.file?m:Sf(p.holder),g=Ff(h),_=u||o.scope===`project`?void 0:g?.metadata.implements,v=u??(_===void 0?void 0:Lf(_,n,r)),y=vd(i,n,o,f,r),b=s!==void 0||!!e.base;if(b&&l===void 0&&y.status===`ambiguous`)throw new q(`pick-required`,`"${i.name}" is ambiguous: ${y.message}; pick what it builds on before the request is applied.`,{details:{options:y.options??[]},help:`Pass --extends with the picks, bottom first, from: ${(y.options??[]).join(`, `)}.`});if(b&&!v&&_===void 0&&y.status===`missing`){let e=Pf(i.name,n,r);if(e)throw new q(`implements-required`,`"${i.name}" is in the namespace of the interface ${e.id}, and nothing implements it; name the interface.`,{details:{interface:e.id},help:`Run \`reference customize ${i.name} --implements ${e.id} --request <file> --body <file>\`.`})}let x=p.format===`markdown`?cc(g?.body??``):!!m?.trim();if(s!==void 0&&x&&!Xc(g?.metadata))throw new q(`body-not-generated`,`${a(p.file)} holds a body that records no request, written with create or by hand; customizing would replace it.`,{details:{path:a(p.file)},help:`Change it with the reference skill's Update mode, or delete it first.`});if(p.other&&!e.base)throw new q(`file-exists`,`${a(p.other)} already answers "${i.name}" in that folder; change it there, or delete it first.`,{details:{path:a(p.other)}});let S={...t,picks:l,target:o,before:d,base:y,file:p.file,format:p.format,holder:p.holder};return f!==void 0&&(S.steps=f),s!==void 0&&(S.request=s),c!==void 0&&(S.body=c),v&&(S.iface=v),u?S.implementsValue=`${u.id}@${u.version}`:typeof _==`string`&&(S.implementsValue=_),m!==void 0&&(S.existing=m),h!==void 0&&(S.held=h),S}function zf(e){try{return o(e,`utf8`)}catch{return}}function Bf(e,t=e=>e){if(e.status===`found`){let n=e.trace.contributions.at(-1),r=n?n.tier===`plugin`?`plugin ${n.plugin}`:n.tier==="default"?`the default of ${n.skill}`:`the ${n.tier} file ${t(n.path)}`:void 0,i=e.trace.stack.length?`, on the stack ${e.trace.stack.join(` → `)}`:``,a=[...new Set(e.projectSections.map(({folder:e})=>e))];if(!r)return`"${e.name}" is answered only by the project sections of ${a.join(`, `)}.`;let o=a.length?`, with the project sections of ${a.join(`, `)}`:``;return`"${e.name}" is answered by ${r}${i}${o}.`}return e.status===`ambiguous`?`"${e.name}" is ambiguous: ${e.message}; the options are ${(e.options??[]).join(`, `)}.`:`"${e.name}" is ${e.status}: ${e.message}.`}const Vf=[`merge`,`extends`,`implements`,`aliases`];function Hf(e,t){let n=K(e,()=>{}).metadata,r={};for(let[e,i]of Object.entries(t.metadata))e!==`merge`&&!(e in n)&&(r[e]=i);return r}function Uf(e,t){let n=t.replace(/^(?:[ \t]*\r?\n)+/,``);return n?`${e.replace(/\s*$/,``)}\n\n${n}`:e}function Wf(e,t,n,r){let i=t.scope===`project`?Gc(e):Wc(e,t.dir,t.path);if(i)return{code:t.scope===`user`&&i.tier===`repo`?`repo-hides-user`:`reference-hidden`,message:`${r(n)} is written, but ${Uc(i,r)} applies above it, so load does not read it until that contribution changes.`}}function Gf(e,t,n={}){let r=wf({command:`create`,...t},e,n),{name:i,target:o,existing:s,operation:c}=r,l=r.template,u=n.display??(e=>e),d=[],p={merge:c};if(o.scope===`project`)for(let e of Vf)p[e]=void 0,!r.iface&&e in l.metadata&&d.push({code:`project-section-key-ignored`,message:`\`${e}\` is dropped from the project section for ${o.folder}: a project section states only what differs in its folder.`});if((o.scope===`plugin`||o.scope==="default")&&r.extended.length){let t=nl(r.extended,Zc(e,{tier:o.scope}));Object.assign(p,rl({sources:t}))}let m=s===void 0?Ic(l.content,p):Uf(Ic(s,{...Hf(s,l),...p}),l.body),h=Wf(r.before,o,o.path,u);h&&d.push(h);let g=Fc(K(m,()=>{}))?[]:["it has no `description` in its frontmatter, so `list` and `search` show it blank"],_={name:i.name,scope:o.scope,path:o.path,content:m,dryRun:!!t.dryRun,hints:g,warnings:d};return o.folder!==void 0&&(_.folder=o.folder),_.dryRun?_:(a(o.dir,{recursive:!0}),f(o.path,m,s===void 0?{flag:`wx`}:{}),(o.scope===`project`||r.before.trace.layers.some(e=>e.path===o.dir||e.path===o.path))&&(_.after=Z(i,{...e,projects:/* @__PURE__ */ new Map},n)),_)}function Kf(e){return e.scope===`project`?`project section for ${e.folder}`:e.scope==="default"?`default`:`${e.scope} contribution`}function qf(e,t,n={}){let{name:i,target:a,before:o}=wf({command:`delete`,...t},e,n),s=n.display??(e=>e),c=!!t.dryRun,d=pf(a,i.name,n.without),f=mf(a,i.name),p=f!==n.without&&r(f),h=d??(p?f:void 0),g={name:i.name,scope:a.scope};if(a.folder!==void 0&&(g.folder=a.folder),!h)return{...g,path:a.path,dryRun:c,code:`no-file`,message:`${s(a.path)} does not exist, so there is no ${Kf(a)} of "${i.name}" to delete; nothing was deleted. ${Bf(o,n.display)} An installed plugin's, a managed, or an installed skill's contribution is never deleted.`,after:o};let _=d&&Rc(d)!==`markdown`&&p?f:void 0,v=Rc(h)===`markdown`?h:_,y=v===void 0?void 0:Y(K(zf(v)??``,()=>{}).metadata.extends,()=>{});if(!c&&(l(h),_&&l(_),m(h)!==a.dir))try{u(m(h))}catch{}let b={...g,path:h,dryRun:c,after:Z(i,{...e,projects:/* @__PURE__ */ new Map},{...n,without:c?h:void 0})};return _&&(b.metadataFile=_),y&&(b.selection=y.map(({target:e})=>e)),b}var Q=class extends Error{code;usage;constructor(e,t,n=!1){super(t),this.code=e,this.usage=n}};function Jf(e,t,n){let r=b(e);if(so(r)===void 0)throw new Q(`folder-invalid`,`${r} holds no SKILL.md, so it is not a skill folder.`);if(n&&!af(r,t))throw new Q(`folder-invalid`,`${r} is outside the repository, such as an installed copy; write to the skill's source instead.`);return _(r,`assets`)}function Yf(e,t){let n=t.split(`/`);if(!t||t.includes(`\\`)||t.startsWith(`/`)||n.some(e=>e===``||e===`.`||e===`..`))throw new Q(`path-invalid`,`"${t}" is not an asset path. Use a relative path inside assets/, with "/" separators and no "..".`,!0);return _(e,...n)}function Xf(e,t){if(!r(e))return!0;let n=c(e),i=t;for(;!r(i);)i=m(i);let a=c(i);return a===n||a.startsWith(n+x)}function Zf(e,t,n){if(!Xf(e,t))throw new Q(`path-invalid`,`"${n}" leaves the assets/ folder through a link.`,!0)}function Qf(e,t){let n=Jf(e,t,!1),r=[],a=(e,t)=>{let n;try{n=s(e,{withFileTypes:!0})}catch{return}for(let o of n){let n=_(e,o.name),s=i(n);s.isSymbolicLink()||(s.isDirectory()?a(n,`${t}${o.name}/`):s.isFile()&&r.push({path:`${t}${o.name}`,bytes:s.size}))}};return a(n,``),r.sort((e,t)=>e.path.localeCompare(t.path))}function $f(e,t,n){let a=Jf(e,t,!1),s=Yf(a,n);if(Zf(a,s,n),!r(s)||!i(s).isFile())throw new Q(`no-file`,`${n} does not exist in assets/.`);let c=o(s);if(c.includes(0))throw new Q(`binary`,`${n} is binary (${c.length} bytes); point to it by path instead of showing it.`);return c.toString(`utf8`)}function ep(e,t,n,i,o){let s=Jf(t,n,!0),c=Yf(s,i);Zf(s,c,i);let l=r(c);if(e===`create`&&l)throw new Q(`exists`,`${i} already exists in assets/; use update to replace it.`);if(e===`update`&&!l)throw new Q(`no-file`,`${i} does not exist in assets/; use create to add it.`);return a(m(c),{recursive:!0}),f(c,o),c}function tp(e,t,n){let a=Jf(e,t,!0),o=Yf(a,n);if(Zf(a,o,n),!r(o)||!i(o).isFile())throw new Q(`no-file`,`${n} does not exist in assets/.`);l(o);for(let e=m(o);e!==a&&e.startsWith(a+x);e=m(e))try{u(e)}catch{break}return o}function np(e,t){let i=ws(t.name);if(i.invalid||i.plugin!==void 0)throw new Q(`name-invalid`,i.invalid??`create takes a bare name.`,!0);if(t.scope!==`project`&&t.scope!==`user`)throw new Q(`options-invalid`,`--scope is project or user.`,!0);if(t.copy===`managed`)throw new Q(`managed-copy-refused`,`the managed tier is policy and is never copied into a project or user folder. Ask the administrator, or read it with "asset load".`);let o=Ms(i.name,e).trace.layers.filter(({file:e})=>e),s=o.find(e=>t.copy==="default"||t.copy===`project`||t.copy===`user`?e.tier===t.copy:e.tier===`plugin`&&e.plugin===t.copy);if(!s){let e=o.map(e=>e.tier===`plugin`?e.plugin:e.tier);throw new Q(`no-source`,`"${t.copy}" holds no asset "${i.name}". Held by: ${e.filter(e=>e!==`managed`).join(`, `)||`nothing`}.`)}let c=h(s.path);if(s.file&&![...xs.map(e=>e.extension),`.md`].includes(c))throw new Q(`no-source`,`${p(s.path)} is not a file an asset name resolves to.`);let l=t.scope===`user`?ds(t.home):us(b(t.root)),u=[`.md`,...xs.map(e=>e.extension)].map(e=>_(l,`${i.name}${e}`)).find(e=>r(e));if(u)throw new Q(`exists`,`${u} already exists; edit it, or delete it first.`);let d=_(l,`${i.name}${c}`);return a(l,{recursive:!0}),n(s.path,d),{path:d,source:s.path,from:t.copy}}function rp(e,t){let n=Ms(t,e).trace.layers;return[...n.filter(({tier:e,file:t})=>e===`plugin`&&t).map(({plugin:e})=>e),...n.some(({tier:e,file:t})=>e==="default"&&t)?[`default`]:[]]}function ip(e,t){let n=ws(t.name);if(n.invalid||n.plugin!==void 0)throw new Q(`name-invalid`,n.invalid??`select takes a bare name.`,!0);if(t.scope!==void 0&&t.scope!==`project`&&t.scope!==`user`)throw new Q(`options-invalid`,`--scope is project or user.`,!0);let i=t.scope===`user`?ds(t.home):us(b(t.root)),o=_(i,`${n.name}.select`);if(t.clear){if(!r(o))throw new Q(`no-file`,`${o} does not exist, so there is no selection to clear.`);l(o)}else{let r=rp(e,n.name);if(!t.option||!r.includes(t.option))throw new Q(`option-invalid`,`"${t.option??``}" cannot be selected for "${n.name}". Options: ${r.join(`, `)||`none, no plugin or default holds it`}.`,!t.option);a(m(o),{recursive:!0}),f(o,`${t.option}\n`)}let s={path:o,cleared:!!t.clear,after:Ms(n.name,e,{without:t.clear?o:void 0})};return t.clear?s:{...s,selected:t.option}}const ap={description:"A skill's source folder in this repository: its `assets/` folder is acted on.",type:N.string()},op={description:`The directory the repository is found from. Defaults to the current directory.`,type:N.string().optional()};function sp(e,t){throw se(e)?e:e instanceof Q?(process.stderr.write(`error: ${e.code}: ${e.message}\n`),j.reported(e.usage?A.usage:A.error)):(process.stderr.write(`error: ${e instanceof Error?e.message:t}\n`),j.reported(A.error))}function cp(e){throw process.stderr.write(`error: usage: ${e}\n`),j.reported(A.usage)}const lp="Asset path inside `assets/`, such as `data/rules.json`.";function up(e){return b(e.root??process.cwd())}function dp(){return M({name:`list`,description:`List every file in a skill's assets/ folder with its size.`,options:{skill:ap,root:op},async run(e){try{let t=Qf(e.skill,up(e));return L({assets:t.length?t:`0 assets — the skill holds none`})}catch(e){return sp(e,`Asset listing failed.`)}}})}function fp(){return M({name:`show`,description:`Print a text asset as written.`,arguments:[{name:`path`,description:lp,type:N.string()}],options:{skill:ap,root:op},async run(e){try{return R($f(e.skill,up(e),e.path))}catch(e){return sp(e,`Asset read failed.`)}}})}function pp(e,t){let n=e===`create`;return M({name:e,description:n?`Add a new asset: by path in a skill from --content or --from, or, with --copy, by name in the project or user assets folder as a copy of what a plugin, the default, or another tier holds (never the managed tier). Never overwrites a file.`:`Replace an existing asset from --content or --from.`,arguments:[{name:`path`,description:`${lp} With --copy, the asset name.`,type:N.string()}],options:{skill:{...ap,type:N.string().optional()},root:op,content:{description:`The text to write.`,type:N.string().optional()},from:{description:`A local file whose bytes to write.`,type:N.string().optional()},...n?{default:{description:"With --copy, the calling skill's folder: its `assets/<name>.<ext>` is the `default` source.",type:N.string().optional()},copy:{description:"Copy the asset of this source: a plugin's name, `default` (the skill's own file), `project`, or `user`. `managed` is refused.",type:N.string().optional()},scope:{description:"With --copy, where the copy goes: project (default), `.agents/assets/`, or user, `~/.agents/assets/`.",type:N.string().optional()}}:{}},async run(r){try{if(r.copy!==void 0){(r.content!==void 0||r.from!==void 0)&&cp(`--copy takes neither --content nor --from.`);let e=T(),n=up(r),i=np(await bs({root:n,home:e,platform:process.platform,env:process.env,plugin:t.plugin,defaultSkill:r.default??r.skill}),{root:n,home:e,name:r.path,scope:r.scope??`project`,copy:r.copy});return R(`${i.path}\n\ncopied from ${i.from}. Edit it; it now answers over the plugin tier.\n`)}r.skill||cp(`pass --skill, or --copy to create an override by name.`),r.content===void 0==(r.from===void 0)&&cp(`pass exactly one of --content and --from.`);let i=r.content??o(b(r.from),`utf8`);return R(`${ep(e,r.skill,up(r),r.path,i)}\n\n${n?`created`:`updated`}.\n`)}catch(t){return sp(t,`Asset ${e} failed.`)}}})}function mp(){return M({name:`delete`,description:`Delete an asset from a skill's source folder, and any folder it leaves empty.`,arguments:[{name:`path`,description:lp,type:N.string()}],options:{skill:ap,root:op},async run(e){try{return R(`${tp(e.skill,up(e),e.path)}\n\ndeleted.\n`)}catch(e){return sp(e,`Asset deletion failed.`)}}})}function hp(e){return M({name:`select`,description:"Choose which plugin, or the skill itself, answers an asset name that several hold, by writing `<name>.select` in the project or user assets folder.",arguments:[{name:`name`,description:`Asset name, without its extension.`,type:N.string()},{name:`option`,description:"A plugin name, or `default` for the skill's own file. Not used with --clear.",type:N.string().optional()}],options:{root:op,default:{description:"The calling skill's folder: its `assets/<name>.<ext>` is the `default` option.",type:N.string().optional()},scope:{description:"Where to write: project (default), `.agents/assets/`, or user, `~/.agents/assets/`.",type:N.string().optional()},clear:{description:`Remove the selection.`,type:N.boolean().optional()}},async run(t){try{let n=T(),r=b(t.root??process.cwd()),i=ip(await bs({root:r,home:n,platform:process.platform,env:process.env,plugin:e.plugin,defaultSkill:t.default}),{...t,root:r,home:n}),a=i.after.status===`found`?`${t.name} now answers from ${i.after.trace.stack.join(`, `)||`a tier`}.`:`${t.name} is ${i.after.status}: ${i.after.message??``}`;return R(`${i.path}\n\n${i.cleared?`selection cleared`:`selected ${i.selected}`}. ${a}\n`)}catch(e){return sp(e,`Asset selection failed.`)}}})}function gp(e={}){let{load:t,names:n,where:r}=rc(e);return M({name:`asset`,description:`Manage a skill's assets/ files by path (list, show, create, update, delete), and load one by name through the tiers (load, names, where, select).`,commands:[dp(),fp(),pp(`create`,e),pp(`update`,e),mp(),t,n,r,hp(e)]})}const _p=[`e.g.`,`i.e.`,`etc.`,`vs.`],vp=/^\s*(`{3,}|~{3,})/,yp=/^#{1,6}\s/,bp=/^\s*(?:[-*+]|\d+[.)])\s/,xp=/^\s*\|/,Sp=/^\s*>/;function Cp(e){return _p.some(t=>{if(!e.endsWith(t))return!1;let n=e.length-t.length;return n===0||/\s/.test(e[n-1])})}function wp(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(!`.;?!`.includes(e[r]))continue;let i=e[r+1];(i===void 0||/\s/.test(i))&&(e[r]===`.`&&Cp(e.slice(n,r+1))||(t.push(e.slice(n,r+1)),n=r+1))}return t.push(e.slice(n)),t.map(e=>e.trim()).filter(Boolean)}function Tp(e){let t=e.split(/\r?\n/),n=[],r=[],i=!1,a=()=>n.length===0?``:i?`
|
|
200
205
|
|
|
201
206
|
`:`
|
|
202
|
-
`,o=(e,t)=>{n.push({text:e,kind:t,gap:a()}),i=!1},s=()=>{r.length&&(
|
|
203
|
-
`),`fence`)}else if(!n.trim())s(),i=!0;else if(
|
|
204
|
-
`),`quote`)}else
|
|
205
|
-
`,n),i=r===-1?e.length:r;if(t.push({text:e.slice(n,i),start:n,end:i}),r===-1)break;n=r+1}return t}function
|
|
207
|
+
`,o=(e,t)=>{n.push({text:e,kind:t,gap:a()}),i=!1},s=()=>{r.length&&(wp(r.join(` `)).forEach((e,t)=>{t===0?o(e,`text`):n.push({text:e,kind:`text`,gap:` `})}),r=[])};for(let e=0;e<t.length;e++){let n=t[e],a=vp.exec(n);if(a){s();let r=a[1][0],i=[n.trimEnd()];for(;++e<t.length;){i.push(t[e].trimEnd());let n=vp.exec(t[e]);if(n&&n[1][0]===r&&t[e].trim()===n[1])break}o(i.join(`
|
|
208
|
+
`),`fence`)}else if(!n.trim())s(),i=!0;else if(yp.test(n))s(),o(n.trim(),`heading`);else if(Sp.test(n)){s();let r=[n.trim()];for(;e+1<t.length&&Sp.test(t[e+1]);)r.push(t[++e].trim());o(r.join(`
|
|
209
|
+
`),`quote`)}else xp.test(n)?(s(),o(n.trim(),`row`)):bp.test(n)?(s(),o(n.trim(),`item`)):r.push(n.trim())}return s(),n}function Ep(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}function Dp(e,t){let n=Array.from({length:e.length+1},()=>Array(t.length+1).fill(0)),r=(e,t)=>n[e][t];for(let i=e.length-1;i>=0;i--)for(let a=t.length-1;a>=0;a--)n[i][a]=Ep(e[i].text,t[a].text)?r(i+1,a+1)+1:Math.max(r(i+1,a),r(i,a+1));let i=[],a=0,o=0;for(;a<e.length&&o<t.length;)Ep(e[a].text,t[o].text)&&r(a,o)===r(a+1,o+1)+1?i.push([a++,o++]):r(a+1,o)>=r(a,o+1)?a++:o++;return i}function Op(e,t){return Dp(e,t).length}const kp=/^## Superseded(?:\s+(.*))?$/,Ap=/^(`{3,}|~{3,})(.*)$/;function jp(e){let t=[],n=0;for(;n<=e.length;){let r=e.indexOf(`
|
|
210
|
+
`,n),i=r===-1?e.length:r;if(t.push({text:e.slice(n,i),start:n,end:i}),r===-1)break;n=r+1}return t}function Mp(e){let t=[],n;return e.forEach((e,r)=>{let i=Ap.exec(e.text);n?i&&i[1]===n&&!i[2]?.trim()&&(n=void 0):i?n=i[1]:kp.test(e.text)&&t.push(r)}),t}function Np(e){let t=jp(e),n=Mp(t),r=[],i=[];return n.forEach((a,o)=>{let s=t[a],c=n[o+1]??t.length,l=()=>{i.push({position:o,line:a+1,heading:s.text})},u=t.findIndex((e,t)=>t>a&&t<c&&Ap.test(e.text));if(u===-1){l();return}let d=t[u],f=Ap.exec(d.text)[1],p=t.findIndex((e,t)=>t>u&&t<c&&e.text.trimEnd()===f),m=t[p];if(!m){l();return}let h=kp.exec(s.text)[1]??``,g=h.indexOf(` — `),_=e.slice(d.end+1,Math.max(d.end+1,m.start-1));r.push({wording:_,date:g===-1?h.trim():h.slice(0,g).trim(),reason:g===-1?``:h.slice(g+3).trim()})}),{entries:r,invalid:i}}function Pp(e){let t=Math.max(0,...(e.match(/^\s*`{3,}/gm)??[]).map(e=>e.trim().length));return"`".repeat(Math.max(3,t+1))}function Fp(e,t,n,r){if(Np(e).entries[0]?.wording===t)return e;let i=Pp(t),a=`## Superseded ${n} — ${r}\n\n${i}markdown\n${t}\n${i}\n`,o=jp(e),s=Mp(o)[0];if(s!==void 0){let t=o[s].start;return`${e.slice(0,t)}${a}\n${e.slice(t)}`}let c=e.endsWith(`
|
|
206
211
|
`)||e===``?e:`${e}\n`;return`${c}${c?`
|
|
207
|
-
`:``}${a}`}function
|
|
212
|
+
`:``}${a}`}function Ip(e,t){return e.length===t.length&&e.every((e,n)=>Ep(e.text,t[n].text))}function Lp(e,t){return t.length>=e.length&&Ip(e,t.slice(0,e.length))?`append`:`rewrite`}function Rp(e,t,n){let r=Dp(e,t).find(([t])=>t===e.length-1),i=[...t],a=r?r[1]+1:i.length;for(let e of n){let t=i.findIndex((t,n)=>n>=a&&Ep(t.text,e.text));t===-1?i.splice(a++,0,e):a=t+1}return i}function zp(e,t,n){let r=Lp(e,n);if(r===`append`)return{revision:r,merged:Rp(e,t,n.slice(e.length)),collisions:[]};let i=new Map(Dp(e,t)),a=new Map(Dp(e,n)),o=[...i.keys()].filter(e=>a.has(e)).sort((e,t)=>e-t),s=[],c=[],l=0,u=0,d=0;for(let r of[...o,e.length]){let o=r,f=r===e.length?t.length:i.get(r),p=r===e.length?n.length:a.get(r),m={base:e.slice(l,o),found:t.slice(u,f),offered:n.slice(d,p)};Ip(m.found,m.base)?s.push(...m.offered):Ip(m.offered,m.base)||Ip(m.found,m.offered)?s.push(...m.found):(s.push(...m.found),c.push(m)),r<e.length&&s.push(t[f]),l=o+1,u=f+1,d=p+1}return{revision:r,merged:s,collisions:c}}const Bp=/^(#{1,6})[ \t](.*)$/,Vp=/^\s*(`{3,}|~{3,})/;function Hp(e){let t=e.trimEnd().length;for(;t>0&&e[t-1]===`#`;)t--;return e.slice(0,t).trim()}function Up(e){let t=e.split(/\r?\n/),n=[{level:0,title:``,body:[]}],r;for(let e of t){let t=Vp.exec(e);if(r)t&&t[1][0]===r[0]&&e.trim()===t[1]&&(r=void 0);else if(t)r=t[1];else{let t=Bp.exec(e);if(t){n.push({heading:e.trim(),level:t[1].length,title:Hp(t[2]),body:[]});continue}}n[n.length-1]?.body.push(e)}let i=[],a=/* @__PURE__ */ new Map,o=[];for(let e of n){let t=Tp(e.body.join(`
|
|
208
213
|
`)),n=t[0];if(e.heading!==void 0&&n&&(n.gap=e.body[0]?.trim()===``?`
|
|
209
214
|
|
|
210
215
|
`:`
|
|
211
216
|
`),e.heading===void 0){if(!t.length)continue}else{for(;i.length&&i[i.length-1].level>=e.level;)i.pop();i.push({level:e.level,title:e.title})}let r=i.map(e=>e.title),s=r.join(` > `),c=(a.get(s)??0)+1;a.set(s,c),o.push({path:r,key:c===1?s:`${s} #${c}`,heading:e.heading,sentences:t,raw:[e.heading,...e.body].filter(e=>e!==void 0).join(`
|
|
212
|
-
`).trimEnd().replace(/^\n+/,``)})}return o}function
|
|
217
|
+
`).trimEnd().replace(/^\n+/,``)})}return o}function Wp(e,t){let n=e??``;return t.forEach((t,r)=>{r>0?n+=t.gap||` `:e!==void 0&&(n+=t.gap===`
|
|
213
218
|
`?`
|
|
214
219
|
`:`
|
|
215
220
|
|
|
216
|
-
`),n+=t.text}),n}function
|
|
221
|
+
`),n+=t.text}),n}function Gp(e){let t=/* @__PURE__ */ new Map;return e.forEach((n,r)=>{for(let i of n){let n=t.get(i.key)??{key:i.key,parts:e.map(()=>void 0)};n.parts[r]=i,t.set(i.key,n)}}),[...t.values()]}var Kp=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`ProseUpdateError`}};const qp=[`conflict`,`undetermined`,`update`,`owners`,`up-to-date`],Jp=e=>e.replace(/\s+/g,` `).trim(),Yp=(e,t)=>e.length===t.length&&e.every((e,n)=>Ep(e.text,t[n].text));function Xp(e){let t=typeof e==`string`?Np(e).entries.map(({wording:e,date:t})=>({wording:e,date:t})):e.map(e=>({wording:e,date:void 0})),n=/* @__PURE__ */ new Set;return t.map(({wording:e,date:t},n)=>({text:e,date:t,sentences:Tp(e),index:n})).filter(e=>{let t=e.sentences.map(e=>Jp(e.text)).join(`\0`);return!n.has(t)&&(n.add(t),!0)})}function Zp(e,t){let n=t.map(t=>({r:t,count:Op(e,t.sentences)})),r=Math.max(0,...n.map(e=>e.count));if(r<1)return{};let i=n.filter(e=>e.count===r).map(e=>e.r);return i.length>1?{tied:i}:{base:i[0]}}function Qp(e,t,n){return Wp(t??e?.heading,n)}function $p(e){if(!Tp(e.offered).length)throw new Kp(`empty-offered`,`The offered wording is empty.`);let t=Tp(e.found),n=Up(e.found),r=Up(e.offered),i=Xp(e.history),a=(t,i={})=>{let a=Gp([n,r]);return{outcome:`undetermined`,reason:t,parts:(a.length?a:[{key:``,parts:[]}]).map(e=>({path:(e.parts[0]??e.parts[1])?.path??[],key:e.key,outcome:`undetermined`,reason:t,...i})),text:e.found}};if(!t.length)return a(`empty-section`);if(!i.length)return a(`no-history`);let{base:o,tied:s}=Zp(t,i);if(s)return a(`tied-base`,{tied:s.map(e=>e.index)});let c=o?Up(o.text):[],l=new Set(i.flatMap(e=>e.sentences.map(e=>Jp(e.text)))),u=o&&{index:o.index,date:o.date},d=Gp([c,n,r]),f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Map;for(let e of d){let[t,n,r]=e.parts,i={path:(n??r??t)?.path??[],key:e.key,outcome:`owners`};f.set(e.key,i);let a=(e,t,n,r)=>{i.outcome=e,u&&(i.base=u),i.shared=Op(n,t),i.baseSentences=t.length,i.revision=Lp(t,r)};if(!n&&r)t?Yp(t.sentences,r.sentences)?(i.outcome=`up-to-date`,i.text=``):(a(`conflict`,t.sentences,[],r.sentences),i.collisions=[{base:t.sentences,found:[],offered:r.sentences}]):(i.outcome=`update`,i.text=r.raw,p.set(e.key,r.raw));else if(n&&!r)t?Yp(t.sentences,n.sentences)?(i.outcome=`update`,i.text=``,p.set(e.key,``)):(a(`conflict`,t.sentences,n.sentences,[]),i.collisions=[{base:t.sentences,found:n.sentences,offered:[]}]):i.text=n.raw;else if(n&&r){let s=n.sentences.some(e=>l.has(Jp(e.text))&&!r.sentences.some(t=>Ep(t.text,e.text))),c=Op(n.sentences,r.sentences);if(!n.sentences.length)i.outcome=`undetermined`,i.reason=`empty-section`;else if(c===r.sentences.length&&!s)i.outcome=`up-to-date`,i.text=n.raw;else if(!o||!t?.sentences.length)c>0?(i.outcome=`undetermined`,i.reason=`no-base`):i.text=n.raw;else if(!Op(n.sentences,t.sentences)&&c===0)i.text=n.raw;else{let o=zp(t.sentences,n.sentences,r.sentences);a(o.collisions.length?`conflict`:`update`,t.sentences,n.sentences,r.sentences),i.text=Qp(n,n.heading??r.heading,o.merged),p.set(e.key,i.text),o.collisions.length&&(i.collisions=o.collisions)}}}let m=qp.find(e=>[...f.values()].some(t=>t.outcome===e)),h=[...f.values()].some(e=>e.outcome===`update`||e.outcome===`conflict`),g=em(n,r,f).map(e=>f.get(e)),_=h?tm(e.found,n,r,p,f):e.found,v=m===`undetermined`?g.find(e=>e.outcome===`undetermined`)?.reason:void 0;return{outcome:m,...v?{reason:v}:{},...u?{base:u}:{},parts:g,text:_}}function em(e,t,n){let r=new Set(e.map(e=>e.key)),i=/* @__PURE__ */ new Map;t.forEach((e,n)=>{if(r.has(e.key))return;let a=t.slice(0,n).reverse().find(e=>r.has(e.key))?.key;i.set(a,[...i.get(a)??[],e.key])});let a=[...i.get(void 0)??[]];for(let t of e)a.push(t.key,...i.get(t.key)??[]);let o=[...n.keys()].filter(e=>!a.includes(e));return[...a,...o]}function tm(e,t,n,r,i){let a=new Map([...n,...t].map(e=>[e.key,e.raw]));return em(t,n,i).filter(e=>i.get(e).outcome!==`up-to-date`||t.some(t=>t.key===e)).map(e=>r.get(e)??(t.some(t=>t.key===e)?a.get(e):void 0)).filter(e=>e!==void 0&&e!==``).join(`
|
|
217
222
|
|
|
218
223
|
`)+(e.endsWith(`
|
|
219
224
|
`)?`
|
|
220
|
-
`:``)}const
|
|
225
|
+
`:``)}const nm=e=>({description:`${e}, as text.`,type:N.string().optional()}),rm=e=>({description:`${e}, read from this file.`,type:N.string().optional()});function im(e){throw process.stderr.write(`error: usage: ${e}\n`),j.reported(A.usage)}function am(e,t,n){return t===void 0==(n===void 0)&&im(`pass exactly one of --${e} and --${e}-from.`),t??o(b(n),`utf8`)}function om(){return M({name:`classify`,description:`Compare found prose with an offered wording and the retired wordings: the outcome for each part and the merged text, with no judgment involved.`,options:{offered:nm(`The wording offered now`),"offered-from":rm(`The wording offered now`),found:nm(`The text found in the file being updated`),"found-from":rm(`The text found in the file being updated`),history:nm(`A history text of retired wordings, newest first`),"history-from":rm(`A history text of retired wordings, newest first`),retired:{description:`A retired wording, as text. Repeat for several, newest first. Used when no history text is given.`,type:N.array(N.string()).optional()},"retired-from":{description:`A file holding a retired wording. Repeat for several, newest first.`,type:N.array(N.string()).optional()}},async run(e){let t=am(`offered`,e.offered,e[`offered-from`]),n=am(`found`,e.found,e[`found-from`]),r=[...e.retired??[],...(e[`retired-from`]??[]).map(e=>o(b(e),`utf8`))],i=e.history!==void 0||e[`history-from`]!==void 0;i&&r.length&&im(`pass a history text or retired wordings, not both.`);let a=i?am(`history`,e.history,e[`history-from`]):r;if(typeof a==`string`){let{invalid:e}=Np(a);for(let t of e)process.stderr.write(`warning: history entry ${t.position+1} (line ${t.line}) did not parse: ${t.heading}\n`)}try{let e=$p({found:n,offered:t,history:a});return L({outcome:e.outcome,...e.reason?{reason:e.reason}:{},...e.base?{base:e.base}:{},parts:e.parts.map(e=>({path:e.path.join(` > `),outcome:e.outcome,...e.reason?{reason:e.reason}:{},...e.tied?{tied:e.tied}:{},...e.base?{base:e.base}:{},...e.shared===void 0?{}:{shared:e.shared,baseSentences:e.baseSentences},...e.revision?{revision:e.revision}:{},...e.text===void 0?{}:{text:e.text},...e.collisions?{collisions:e.collisions.map(e=>({base:e.base.map(e=>e.text),found:e.found.map(e=>e.text),offered:e.offered.map(e=>e.text)}))}:{}})),text:e.text})}catch(e){throw e instanceof Kp?(process.stderr.write(`error: ${e.code}: ${e.message}\n`),j.reported(A.error)):e}}})}function sm(){return M({name:`retire`,description:`Print the history text with the outgoing wording added as its newest entry. Writes no file: the caller saves the answer.`,options:{history:nm(`The history text`),"history-from":rm(`The history text`),wording:nm(`The outgoing wording`),"wording-from":rm(`The outgoing wording`),date:{description:`The date of the entry, written as given.`,type:N.string()},reason:{description:`Why the wording was replaced.`,type:N.string()}},async run(e){return R(Fp(am(`history`,e.history,e[`history-from`]),am(`wording`,e.wording,e[`wording-from`]),e.date,e.reason))}})}function cm(){return M({name:`prose-update`,description:`Bring prose a tool wrote earlier to its offered wording without losing the owner’s edits: classify found prose, and extend the history of retired wordings.`,commands:[om(),sm()]})}const lm={description:"The repository root: its `.agents/references/` is the repo tier, and its `package.json` names the dependency plugins. Defaults to the nearest folder at or above the current directory holding `.git`, else the current directory.",type:N.string().optional()},um={description:`Add the trace: every layer checked, with its outcome, and how the result was built.`,type:N.boolean().optional()},dm={description:"The calling skill's folder: its `references/<name>.default.md` joins as the `default` tier.",type:N.string().optional()};function fm(e){return(t,n)=>ju({root:t.root,cwd:process.cwd(),home:n,platform:process.platform,env:process.env,plugin:e,defaultSkill:t.default})}function $(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``&&!(Array.isArray(e)&&!e.length)))}function pm(e,t){throw se(e)?e:e instanceof q?new j(e.message,{code:e.code,exitCode:e.usage?A.usage:A.error,details:e.details,help:e.help}):new j(e instanceof Error?e.message:t,{cause:e})}function mm(e){for(let{code:t,message:n}of e)process.stderr.write(`warning: ${t}: ${n}\n`)}function hm(e,t){let n=e=>G(t,e);return{...e,contributions:e.contributions.map(e=>({...e,path:n(e.path)})),layers:e.layers.map(e=>({...e,path:n(e.path)})),projectSections:e.projectSections.map(e=>({...e,path:n(e.path)}))}}function gm(e,t){let n=(e.sources??[]).map(e=>`${t}source ${e.default===void 0?`plugin ${e.plugin}`:`default ${e.default}${e.plugin?` (plugin ${e.plugin})`:``}`}: recorded ${e.recorded??`no version`}, installed ${e.status===`missing`?`not installed`:e.installed??`no version`} (${e.status})`);return e.request!==void 0&&n.push(`${t}request:`,...e.request.replace(/\n$/,``).split(`
|
|
226
|
+
`).map(e=>`${t} ${e}`)),n}function _m(e,t){let n=hm(e.trace,t),r=[`${e.name}: ${e.status}; stack: ${n.stack.join(` → `)||`none`}; built by ${n.builtBy}; harnesses: ${n.harnesses.join(`, `)||`none detected`}`];if(e.message&&r.push(` ${e.message}`),n.sections.length){r.push(`sections:`);for(let e of n.sections){let t=e.removedBy?`removed by ${e.removedBy}`:e.contributions.map(({contribution:e,operation:t})=>`${e} (${t})`).join(`, `)||`no text`;r.push(` ${e.path}: ${t}`)}}r.push(`layers:`);for(let e of n.layers){let t=e.plugin?` ${e.plugin}`:e.skill?` ${e.skill}`:``,n=e.operation?`; ${e.operation} from ${e.operationFrom}`:``,i=e.extendsOutcome?`; extends ${e.extendsOutcome}`:``,a=e.selection?`; selection`:``,o=e.frontmatter&&Object.keys(e.frontmatter).length?` ${JSON.stringify(e.frontmatter)}`:``;r.push(` ${e.tier}${t} ${e.path}: ${e.outcome}${n}${i}${a}${o}`),r.push(...gm(e,` `))}if(n.projectSections.length){r.push(`project sections:`);for(let e of n.projectSections){let t=e.frontmatter&&Object.keys(e.frontmatter).length?` ${JSON.stringify(e.frontmatter)}`:``,n=e.plugin===void 0?``:` (plugin ${e.plugin}${e.version?`@${e.version}`:``})`;r.push(` ${e.folder}${n} ${e.path}: ${e.outcome}${t}`),r.push(...gm(e,` `));for(let t of e.sections??[]){let e=t.contributions.map(({contribution:e,operation:t})=>`${e} (${t})`).join(`, `);r.push(` ${t.path}: ${e||`no text`}`)}}}return`${r.join(`
|
|
227
|
+
`)}\n`}function vm(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function ym(e){return vm(e).replace(/"/g,`"`)}function bm(e){let t=e.options?.length?`; options: ${e.options.join(`, `)}`:``;return`<reference name="${ym(e.name)}" status="${e.status}" code="${e.code}">${vm(`${e.message??e.status}${t}`)}</reference>`}function xm(e){let t=e.content??``;return e.projectSections.length?`${[...t.trim()?[t.trimEnd()]:[],...e.projectSections.map(({folder:e,plugin:t,content:n})=>`<project folder="${ym(e)}"${t===void 0?``:` plugin="${ym(t)}"`}>\n${n}</project>`)].join(`
|
|
228
|
+
|
|
229
|
+
`)}\n`:t}function Sm(e,t){return`<reference name="${ym(e)}">\n${t}</reference>`}const Cm={description:"Tier to write: repo (default), `.agents/references/` at the root, or user, `~/.agents/references/`.",type:N.string().optional()},wm={description:"A folder strictly below the root, which must exist and not be ignored by git: acts on its project section, `<folder>/.agents/references/<name>.md`.",type:N.string().optional()};function Tm(e){return e===void 0?Su(process.cwd()):b(e)}const Em={description:"A plugin's source folder in this repository: acts on its `references/<name>.md`.",type:N.string().optional()},Dm={description:"A skill's source folder in this repository: acts on its `references/<name>.default.md`.",type:N.string().optional()};function Om(e){return M({name:`check`,description:"Check references, each composed as `load` composes it: an interface document against its shape, an implementation against its interface, and every document for the defects composing it raises. With no names, checks every name found. Every warning `load` raises is reported. A failure is an entry in `failed`, not an error; a warning never fails a check.",arguments:[{name:`names`,description:"Reference names, without the `.md` extension; `<plugin>/<name>` builds that plugin’s own stack.",type:N.array(N.string()).optional()}],options:{root:lm,trace:{...um,description:`Add every entry checked, with its kind and unsupported sections.`}},async run(t){try{let n=T(),r=nf(await e(t,n),{names:t.names??[],display:e=>G(n,e)}),i=r.filter(e=>e.failures.length),a=e=>e.map(({check:e,message:t})=>({check:e,message:t}));return L($({failed:i.map(({name:e,loadedBy:t,failures:n,warnings:r})=>$({name:e,loadedBy:t,failures:a(n),warnings:r})),warned:r.filter(e=>!e.failures.length&&e.warnings.length).map(({name:e,loadedBy:t,warnings:n})=>$({name:e,loadedBy:t,warnings:n})),passed:r.length-i.length,references:t.trace?r.map(({name:e,loadedBy:t,kind:n,status:r,failures:i,unsupported:o,warnings:s})=>$({name:e,loadedBy:t,kind:n,status:r,failures:a(i),unsupported:o,warnings:s})):void 0}))}catch(e){return pm(e,`Reference check failed.`)}}})}function km(e){return M({name:`create`,description:`Start a contribution in the repo or user tier, a folder's project section, or a plugin's or a skill's source folder, from a template or an interface. Never overwrites a file with a body; writes a file a contribution above hides, with a warning.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:N.string()}],options:{root:lm,scope:Cm,in:wm,plugin:Em,default:Dm,merge:{description:`How it applies over what is below: replace, patch (default), combine, or remove. remove writes no body.`,type:N.string().optional()},template:{description:"File whose text is written as it is, frontmatter included. Defaults to a built-in template of top-level `##` sections.",type:N.string().optional()},implements:{description:"Interface id to implement: the interface's sections become `##` headings, each stubbed `**Unsupported.**` with what it holds, and `merge: replace`; with --in, a project section with neither. Not with --template.",type:N.string().optional()},"dry-run":{description:`Print the target path and the exact content, and write nothing.`,type:N.boolean().optional()},trace:{...um,description:`After the write, add the trace, in which the new file applies.`}},async run(t){let n=this.format;try{let r=T(),i=e=>G(r,e),a={root:Tm(t.root),home:r,name:t.name,scope:t.scope,in:t.in,plugin:t.plugin,default:t.default,merge:t.merge,template:t.template,implements:t.implements,dryRun:t[`dry-run`]};wf({command:`create`,...a});let o=await e({root:t.root,default:t.default},r),s=Gf(o,{...a,root:o.root??a.root},{display:i}),c=$({path:i(s.path),folder:s.folder,hint:s.dryRun?`Nothing was written. Run again without --dry-run to write it.`:`Run \`load ${s.name}\` for the composed document.`,content:s.dryRun?s.content:void 0,hints:s.hints,warnings:s.warnings,trace:t.trace&&s.after?hm(s.after.trace,r):void 0});if(n!==`text`)return L(c);mm(s.warnings);for(let e of s.hints)process.stderr.write(`hint: ${e}\n`);return t.trace&&s.after&&process.stderr.write(_m(s.after,r)),R(s.dryRun?`${c.path}\n\n${s.content}`:`${c.path}\n\n${c.hint}\n`)}catch(e){return pm(e,`Reference creation failed.`)}}})}function Am(e){let t=e.layers.find(({tier:e,skipped:t})=>e==="default"&&!t);if(t?.skill===void 0)return;let n=m(t.dir),r=e.layers.find(({tier:e,plugin:t,dir:r})=>e===`plugin`&&t!==void 0&&n.startsWith(m(r)+x));return r?.plugin===void 0?{skill:t.skill}:{skill:t.skill,plugin:r.plugin}}function jm(e){let t=e.held===void 0?void 0:K(e.held,()=>{}),n=e.format===`markdown`?cc(t?.body??``):!!e.existing?.trim();return{metadata:t?.metadata??{},held:n}}function Mm(e,t){a(m(e),{recursive:!0}),f(e,t)}function Nm(e,t,n,r){let i=r.display??(e=>e),{name:a,holder:o,picks:s,before:c}=e;n.path=o;let{metadata:u,held:d}=jm(e);if(s===`none`){if(e.held===void 0||!(`extends`in u))return{...n,action:`cleared`,code:`no-selection`,message:`${i(o)} holds no selection of "${a.name}", so nothing was removed. ${Bf(c,r.display)}`,after:c};let s=Ic(e.held,{extends:void 0,declined:void 0}),d=!s.trim();return n.action=`cleared`,d?n.deleted=!0:n.content=s,n.dryRun?n:(d?l(o):Mm(o,s),Lm(n,e,t,r))}let f=s?s.values:[],p=Ic(e.held??``,{extends:f,declined:Im(e,f)});Object.assign(n,{action:`selection`,content:p,extends:f});let m=Wf(c,e.target,o,i);return m&&n.warnings.push(m),e.base.trace.builtBy.startsWith(`managed `)&&n.warnings.push({code:`extends-not-used`,message:`the picks are written to ${i(o)}, but ${e.base.trace.builtBy}'s extends builds the stack, so they are not used while it does.`}),d&&Xc(u)&&n.hints.push(`its body was generated from a request against the old stack; customize "${a.name}" again with that request (\`reference customize ${a.name} --request <file> --body <file>\`) to regenerate it on the new picks.`),n.dryRun?n:(Mm(o,p),Lm(n,e,t,r))}function Pm(e){let t=new Set(e.trace.stack),n=new Set(e.projectSections.flatMap(({plugin:e})=>e===void 0?[]:[e])),r=/* @__PURE__ */ new Map;for(let{plugin:i,version:a}of e.trace.projectSections)i===void 0||!n.has(i)||t.has(i)||r.has(i)||r.set(i,a===void 0?{plugin:i}:{plugin:i,version:a});return[...r.values()]}function Fm(e,t,n,r){let i=r.display??(e=>e),{target:a,base:o,picks:s}=e,c=a.scope===`project`,l=!c&&e.implementsValue!==void 0,{metadata:u}=jm(e),d=s&&s!==`none`?s.values:u.extends,f=l||o.status!==`found`?[]:[...nl(o.trace.stack,Zc(gd(t,a),{tier:a.scope===`user`?`user`:`repo`}),Am(t)),...c?Pm(o):[]],p=!c&&!l&&d!==void 0,m={extends:p?d:void 0,declined:p?Im(e,d):void 0,sources:void 0,request:void 0,...rl({sources:f,request:e.request})},h=e.body;n.action=`generated`,n.path=e.file,e.format===`markdown`?n.content=Ic(h,{merge:c?void 0:l?`replace`:e.merge??`patch`,implements:l?e.implementsValue:void 0,...m}):(n.content=h,n.metadataFile=e.holder,n.metadataContent=Ic(e.held??``,{merge:void 0,implements:void 0,...m}));let g=Wf(e.before,a,e.file,i);return g&&n.warnings.push(g),n.dryRun?n:(Mm(e.file,n.content),n.metadataContent!==void 0&&Mm(e.holder,n.metadataContent),Lm(n,e,t,r))}function Im(e,t){let n=Y(t,()=>{});if(!n)return;let r=/* @__PURE__ */ new Map;for(let{tier:t,plugin:n,file:i,outcome:a,frontmatter:o}of e.base.trace.layers)t!==`plugin`||n===void 0||i===void 0||a.startsWith(`not read`)||r.has(n)||r.set(n,o?.extends);let i=/* @__PURE__ */ new Set,a=e=>{for(let t of e)i.has(t.target)||(i.add(t.target),a(t.extends??Y(r.get(t.target),()=>{})??[]))};a(n);let o=[...r.keys()].filter(e=>!i.has(e));return o.length?o:void 0}function Lm(e,t,n,r){return{...e,after:Z(t.name,{...n,projects:/* @__PURE__ */ new Map},r)}}function Rm(e,t,n={}){let r=wf({command:`customize`,...t},e,n),i={name:r.name.name,scope:r.target.scope,action:`base`,path:r.file,dryRun:!!t.dryRun,hints:[],warnings:[]};return r.target.folder!==void 0&&(i.folder=r.target.folder),t.base?{...i,base:yd(r.base,r.iface)}:r.request===void 0?Nm(r,e,i,n):Fm(r,e,i,n)}function zm(e){let t=e.base,n=t?.resolved;return $({status:n?.status??`missing`,stack:n?.trace.stack,content:t?.content??``,projectSections:t?.projectSections.map(({folder:e,content:t})=>({folder:e,content:t}))})}function Bm(e){let t=e.base;return t?!t.content&&!t.projectSections.length&&t.resolved.status!==`found`?`${bm(t.resolved)}\n`:xm({...t.resolved,content:t.content,projectSections:t.projectSections}):``}function Vm(e,t,n){let r=e=>G(n,e),i=e.after;return $({path:r(e.path),folder:e.folder,metadataFile:e.metadataFile===void 0?void 0:r(e.metadataFile),code:e.code,message:e.message,extends:e.extends,deleted:e.deleted,status:i?.status,stack:i?.trace.stack,answer:i?Bf(i,r):void 0,hint:e.dryRun?`Nothing was written. Run again without --dry-run to write it.`:e.code?void 0:`Run \`load ${e.name}\` for the composed document.`,content:e.dryRun?e.content:void 0,metadataContent:e.dryRun?e.metadataContent:void 0,hints:e.hints,warnings:e.warnings,trace:t.trace&&i&&!e.code?hm(i.trace,n):void 0})}function Hm(e,t){if(e.code)return`${t.path}\n\n${e.code}: ${e.message}\n`;if(e.dryRun){let n=e.deleted?`would delete the file, left with nothing in it.
|
|
230
|
+
`:e.content??``,r=e.metadataContent===void 0?``:`\n${t.metadataFile}\n\n${e.metadataContent}`;return`${t.path}\n\n${n}${r}`}if(e.action===`cleared`){let n=e.deleted?`selection removed; the file was left empty and deleted`:`selection removed`;return`${t.path}\n\n${n}. ${t.answer}\n`}if(e.action===`selection`)return`${t.path}\n\nextends: ${JSON.stringify(e.extends)}. ${t.answer}\n`;let n=t.metadataFile?` Its record is in ${t.metadataFile}.`:``;return`${t.path}\n\n${t.hint}${n}\n`}function Um(e){return M({name:`customize`,description:"Customize a name for the repo or user tier, or a folder's project section, running no model: pick what it builds on (`extends`), write a body generated from a request with its record, or print what the generator reads (--base). Writes a file a contribution above hides, with a warning.",arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:N.string()},{name:`steps`,description:"More steps for --extends, so `--extends a b` lists both, bottom first.",type:N.array(N.string()).optional()}],options:{root:lm,scope:Cm,in:{...wm,description:`${wm.description} Takes no --extends or --merge.`},default:{description:"The calling skill's folder, read only: its `references/<name>.default.md` joins the stack as the `default` tier.",type:N.string().optional()},plugin:{description:"Not accepted: customize never writes a plugin's file; an author uses `create --plugin`.",type:N.string().optional()},extends:{description:"The picks, bottom first: each a plugin holding the name, `<plugin>:<merge>` (such as `house-style:combine`), or `default`; `none` removes them. A file with no body is a selection.",type:N.array(N.string()).optional()},"extends-file":{description:"A YAML file holding the whole `extends` list, with every step key (`merge`, `extends`, `sections`).",type:N.string().optional()},request:{description:"A file holding the customizer's request, in their own words; recorded as `request`. Needs --body.",type:N.string().optional()},body:{description:`A file holding the body the generator wrote; written as given, with the picks, sources, and request recorded. Needs --request.`,type:N.string().optional()},merge:{description:`How the body applies over what is below: patch (default), combine, or replace for a whole document.`,type:N.string().optional()},implements:{description:"Interface id the body implements: a whole document recording `implements` and `merge: replace`; with --in, a project section from the interface's stub.",type:N.string().optional()},base:{description:`Print what the generator reads for the target, and write nothing: the name resolved with the picks, leaving out the target file, managed text, the tier above, and personal text; with --implements, the interface's stub first.`,type:N.boolean().optional()},"dry-run":{description:`Print the target path and the exact content, and write nothing.`,type:N.boolean().optional()},trace:{...um,description:`After the write, add the trace, in which the written file applies.`}},async run(t){let n=this.format;try{let r=T(),i=e=>G(r,e),a=t.extends===void 0?void 0:[...t.extends,...t.steps??[]],o={root:Tm(t.root),home:r,name:t.name,scope:t.scope,in:t.in,plugin:t.plugin,default:t.default,extends:a,extendsFile:t[`extends-file`],request:t.request,body:t.body,merge:t.merge,implements:t.implements,base:t.base,dryRun:t[`dry-run`]};if(wf({command:`customize`,...o}),t.steps?.length&&t.extends===void 0)throw new q(`options-missing`,`${t.steps.join(` `)} follow no --extends; pass --extends before the steps.`);let s=await e({root:t.root,default:t.default},r),c=Rm(s,{...o,root:s.root??o.root},{display:i});if(c.action===`base`)return n===`text`?R(Bm(c)):L(zm(c));let l=Vm(c,t,r);if(n!==`text`)return L(l);mm(c.warnings);for(let e of c.hints)process.stderr.write(`hint: ${e}\n`);return t.trace&&c.after&&!c.code&&process.stderr.write(_m(c.after,r)),R(Hm(c,l))}catch(e){return pm(e,`Reference customization failed.`)}}})}function Wm(e,t){let n=e.selection?`the selection extends: [${e.selection.join(`, `)}] went with it; run \`reference customize ${e.name} --extends ${e.selection.join(` `)}\` to restore it`:void 0;return $({path:G(t,e.path),folder:e.folder,metadataFile:e.metadataFile===void 0?void 0:G(t,e.metadataFile),code:e.code,message:e.message,dryRun:e.dryRun||void 0,status:e.after.status,stack:e.after.trace.stack,answer:Bf(e.after,e=>G(t,e)),selection:n,options:e.after.options})}function Gm(e){return M({name:`delete`,description:`Delete a repo or user contribution, a folder's project section, or one in a plugin's or a skill's source folder, with a non-Markdown file's metadata file, and report what answers the name afterwards. Never deletes an installed or managed one.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:N.string()}],options:{root:lm,scope:{...Cm,description:`Tier to delete from: repo (default) or user.`},in:wm,plugin:Em,default:Dm,"dry-run":{description:`Print the file that would be deleted and what would answer the name then, and delete nothing.`,type:N.boolean().optional()}},async run(t){let n=this.format;try{let r=T(),i={root:Tm(t.root),home:r,name:t.name,scope:t.scope,in:t.in,plugin:t.plugin,default:t.default,dryRun:t[`dry-run`]};wf({command:`delete`,...i});let a=await e({root:t.root,default:t.default},r),o=qf(a,{...i,root:a.root??i.root},{display:e=>G(r,e)}),s=Wm(o,r);if(n!==`text`)return L(s);if(o.code)return R(`${s.path}\n\n${o.code}: ${o.message}\n`);let c=s.selection?` Also, ${s.selection}.`:``,l=s.metadataFile?` Its metadata file ${s.metadataFile} went with it.`:``;return R(`${s.path}\n\n${o.dryRun?`would delete`:`deleted`}. ${s.answer}${l}${c}\n`)}catch(e){return pm(e,`Reference deletion failed.`)}}})}function Km(e){return typeof e==`string`&&e.split(`
|
|
231
|
+
`)[0]?.trim()||``}function qm(e,t,n){return t!==void 0&&t!==n&&(e===t||e.startsWith(`${t}.`))}function Jm(e){return e.trace.layers.find(e=>(e.tier===`repo`||e.tier===`user`)&&e.file&&(e.outcome===`used`||e.outcome===`stale`)&&!e.selection&&!e.empty)?.tier}function Ym(e){return[...new Set(e.trace.layers.flatMap(({tier:e,plugin:t,file:n})=>e===`plugin`&&t!==void 0&&n?[t]:[]))]}function Xm(e,t,n={}){let{accept:r,...i}=n,a={...i,projectSections:!1},o=J(`${e}${Ol}`);if(o.invalid||o.plugin!==void 0)throw new q(`interface-unknown`,`"${e}" is not an interface id.`);let s=Ud(t,i),c=s(e),l=c.value;if(!l)throw new q(`interface-unknown`,c.failure?.message??`no interface ${e}`);let u=Kl(t),d=[l.id,...(u.interfaces.get(l.id)??[]).map(({alias:e})=>e)],f=[...r?.length?r:l.versions],p={interface:l.id,cardinality:l.cardinality,accept:f,implementations:[],excluded:[],warnings:[]},m=/* @__PURE__ */ new Set,h=e=>{for(let t of e){let e=`${t.code} ${t.message}`;m.has(e)||p.warnings.push(t),m.add(e)}};c.renamed!==void 0&&h([{code:`reference-renamed`,message:`${e} is an older id of ${l.id}; ask for ${l.id} instead`}]);let g=e=>d.some(t=>e===t||e.startsWith(`${t}.`)),_=(e,t)=>{let n=Ll(t.metadata??{}).entry?.id;return n!==void 0&&d.includes(n)?!0:g(e)&&!d.some(t=>qm(e,n,t))},v=({pin:e,name:t,resolved:n,tier:r})=>{h(n.warnings);let i=Ll(n.metadata??{}).entry;if(!i||!d.includes(i.id)){let n=Zm(l.cardinality,d,t)?``:` and is not named ${l.cardinality===`one`?l.id:`${l.id}.<key>`}`;p.excluded.push({name:e,reasons:[`declares no implements ${l.id}@<version>${n}`]});return}let a=Xd(n,s,{id:l.id,versions:f});if(h(a.warnings),a.failures.length){p.excluded.push({name:e,reasons:a.failures.map(({check:e,message:t})=>`${e}: ${t}`)});return}p.implementations.push({pin:e,description:Km(n.metadata?.description),unsupported:a.unsupported,name:t,tier:r,version:i.version})},y=(e,n)=>Z(J(`${e}/${n}`),t,a),b=[...new Set(hd(t).map(e=>Zl(e,u)))];for(let e of b){if(Al(e)!==void 0)continue;let n=Z(e,t,a);if(n.status===`ambiguous`){for(let r of n.options??[]){if(r==="default")continue;let i=Z(J(r),t,a);i.status===`found`&&_(e,i)&&(h(i.warnings),p.excluded.push({name:r,reasons:[`ambiguous: ${n.message}; each is left out until a customizer picks one`]}))}continue}if(n.status!==`found`||!_(e,n))continue;let r=Ym(n),i=l.cardinality===`many`?Jm(n):void 0;if(i!==void 0){v({pin:e,name:e,resolved:n,tier:i});for(let t of r)p.excluded.push({name:`${t}/${e}`,reasons:[`the ${i} implementation answers ${e}; a consumer loads it by that name`]});continue}let o=n.trace.stack.filter(e=>e!=="default").at(-1);if(o!==void 0){v({pin:`${o}/${e}`,name:e,resolved:y(o,e),tier:`plugin`});for(let t of r)t!==o&&p.excluded.push({name:`${t}/${e}`,reasons:[`${e} loads the stack of ${o}, the pick; load ${o}/${e}`]})}}return p}function Zm(e,t,n){return t.some(t=>e===`one`?n===t:n.startsWith(`${t}.`)&&n.length>t.length+1)}function Qm(e){if(e===void 0)return;let t=e.split(`,`).map(e=>e.trim());if(!t.length||t.some(e=>!/^[1-9]\d*$/.test(e)))throw new q(`option-invalid`,`--accept is a comma-separated list of versions, such as 1,2; got "${e}".`,{details:{option:`--accept`,value:e}});return t.map(Number)}function $m(e){return M({name:`implementations`,description:`List the implementations of an interface a consumer can load, each with its pin, description, and unsupported sections.`,arguments:[{name:`id`,description:"Interface id, the name of its `<id>.interface` document without the suffix.",type:N.string()}],options:{root:lm,accept:{description:"Versions the consumer knows, comma-separated, such as 1,2. Defaults to the interface's `versions`.",type:N.string().optional()},trace:{...um,description:`Add each one's name, tier, and version, the interface's cardinality and accepted versions, and the ones left out with why.`}},async run(t){try{let n=Qm(t.accept),r=T(),i=Xm(t.id,await e(t,r),{accept:n,display:e=>G(r,e)}),a=i.implementations.map(({pin:e,description:n,unsupported:r,name:i,tier:a,version:o})=>$(t.trace?{pin:e,description:n,unsupported:r,name:i,tier:a,version:o}:{pin:e,...a===`plugin`?{}:{tier:a},description:n,unsupported:r}));if(!a.length&&!t.trace)return nr(`0 implementations of ${t.id}`,{help:`Run \`reference implementations ${t.id} --trace\` for the ones left out, with why.`});let o={implementations:a};return t.trace&&Object.assign(o,$({interface:i.interface,cardinality:i.cardinality,accept:i.accept,excluded:i.excluded,warnings:i.warnings})),L(o)}catch(e){return pm(e,`Implementation lookup failed.`)}}})}function eh(e){return M({name:`list`,description:`List every reference name, one row each, with its description, and its status when not found. A pattern keeps only the names it matches exactly.`,arguments:[{name:`pattern`,description:"Exact name pattern, where `*` stands for any run of characters, such as `project-tracker.capabilities.*`.",type:N.string().optional()}],options:{root:lm,trace:{...um,description:`Add one row per name per layer holding it, with its outcome.`}},async run(t){try{let n=T(),r=e=>G(n,e),i=kd(await e(t,n),{display:r,pattern:t.pattern}),a=t.trace&&i.layers.length>0;if(!i.references.length&&!a&&!i.warnings.length)return nr(t.pattern?`0 references match "${t.pattern}"`:`0 references — no layer holds one`,{help:[...i.defaults?[i.defaults]:[],t.pattern?"Run `reference list` with no pattern for every name, or `reference search <query>` by topic.":"Run `reference create <name>` to start one."]});let o={references:i.references.map(e=>$({name:e.name,description:e.description,format:e.format,status:e.status===`found`?void 0:e.status,code:e.code,options:e.options}))};return i.defaults&&(o.defaults=i.defaults),t.trace&&(o.layers=i.layers.map(e=>$({...e,path:r(e.path)}))),i.warnings.length&&(o.warnings=i.warnings),L(o)}catch(e){return pm(e,`Reference listing failed.`)}}})}function th(e,t,{metadata:n,trace:r}){return e.status===`found`&&!e.warnings.length&&!e.projectSections.length&&!n&&!r&&e.format===`markdown`?e.content:$({name:e.name,status:e.status,content:e.content,projectSections:e.projectSections.map(({folder:e,plugin:t,content:n})=>t===void 0?{folder:e,content:n}:{folder:e,plugin:t,content:n}),format:e.format===`markdown`?void 0:e.format,code:e.code,options:e.options,metadata:n?e.metadata:void 0,warnings:e.warnings,trace:r?hm(e.trace,t):void 0})}const nh={toon:e=>Tn(e,`toon`),json:e=>Tn(e,`json`)};function rh(e){let t=e=>e.status===`found`?Sm(e.name,xm(e)):bm(e);if(e.length===1){let[t]=e;return R(t.status===`found`?xm(t):bm(t))}return R(e.map(t).join(`
|
|
232
|
+
|
|
233
|
+
`))}function ih(e){return M({name:`load`,description:`Print one or more references, each composed from its contributions as their extends and merge declare.`,arguments:[{name:`names`,description:"Reference names, without the `.md` extension; `<plugin>/<name>` builds that plugin’s own stack.",type:N.array(N.string())}],options:{root:lm,default:dm,metadata:{description:`Make every entry a record with its status and composed frontmatter.`,type:N.boolean().optional()},trace:um},async run(t){let n=this.format;try{if(!t.names.length)throw new q(`name-missing`,`name at least one reference to load.`,{help:"Run `reference load <name>...`, or `reference list` for every name."});for(let e of t.names)ol(e);let r=T(),i=await e(t,r),a=e=>G(r,e),o=Ud(i,{display:a}),s=t.names.map(e=>{let t=Z(J(e),i,{display:a}),n=Xd(t,o);t.warnings.push(...n.warnings);for(let e of n.failures)e.check!==`compose`&&t.warnings.push({code:`interface-check`,message:`it fails its interface check (${e.check}): ${e.message}`});return t});if(n===`text`){for(let e of s)mm(e.warnings),t.trace&&process.stderr.write(_m(e,r));return rh(s)}let c={metadata:!!t.metadata,trace:!!t.trace};return L(s.map(e=>th(e,r,c)),{render:nh})}catch(e){return pm(e,`Reference lookup failed.`)}}})}function ah(e){return M({name:`search`,description:`Find references by name, description, tags, headings, or body, best match first.`,arguments:[{name:`query`,description:`What the reference is about.`,type:N.string()}],options:{root:lm,trace:{...um,description:`Add the tier and plugin or skill of each match.`}},async run(t){let n=t.query.trim();try{let r=T(),{matches:i,defaults:a}=Rd(n,await e(t,r),{display:e=>G(r,e)});return i.length?L($({references:i.map(({name:e,description:n,match:r,folder:i,tier:a,plugin:o,skill:s,loadedBy:c})=>$(t.trace?{name:e,description:n,match:r,folder:i,loadedBy:c,tier:a,plugin:o,skill:s}:{name:e,description:n,match:r,folder:i,loadedBy:c})),defaults:a})):nr(`0 references match "${n}"`,{help:[...a?[a]:[],"Try other words, or run `reference list` for every name."]})}catch(e){return pm(e,`Reference search failed.`)}}})}function oh(e,t,{root:n,display:r=e=>e,in:i}){typeof e==`string`&&ol(e);let a=i===void 0?void 0:sf(i,n),o=typeof e==`string`?J(e):e,s=Z(o,t,{display:r}),c={name:o.raw,status:s.status,files:[],headings:s.status===`found`&&s.format===`markdown`?Oc(s.content??``):[],used:s.trace.stack,layers:s.trace.layers,warnings:s.warnings};if(s.options&&(c.options=s.options),o.invalid)return c;let l=(Array.isArray(t)?t:t.layers).find(({tier:e})=>e===`user`)?.dir,u=[{scope:`repo`,dir:vu(n),path:``},...l?[{scope:`user`,dir:l,path:``}]:[],...a?[{scope:`project`,dir:_(a.path,`.agents`,`references`),path:``,folder:a.folder}]:[]];for(let e of u){let t=pf(e,o.name)??_(e.dir,`${o.name}.md`),i=e.scope===`project`?Gc(s):Wc(s,e.dir,t),a={scope:e.folder??e.scope,path:e.scope===`user`?r(t):y(n,t),reaches:hf(e)};i&&(a.hiddenBy=Uc(i,r)),c.files.push(a)}return c}function sh(e){return M({name:`where`,description:`Give the repo and user files, and with --in a folder's project section, a customization or a selection of a reference is written to, who each reaches and what hides it, the main document's heading paths, and the read-only plugins and default the stack uses.`,arguments:[{name:`name`,description:"Reference name, without the `.md` extension.",type:N.string()}],options:{root:lm,default:dm,in:{...wm,description:`A folder strictly below the root: also give its project section's file.`},trace:{...um,description:`Add every layer checked, with its outcome.`}},async run(t){let n=this.format;try{let r=T(),i=e=>G(r,e),a=await e(t,r),o=oh(t.name,a,{root:a.root??Tm(t.root),display:i,in:t.in}),s=$({name:o.name,status:o.status,files:o.files,headings:o.headings,used:o.used,options:o.options,hint:o.used.length?`${o.used.join(`, `)} ${o.used.length===1?`is`:`are`} read-only; a customization goes in one of the files.`:void 0,layers:t.trace?o.layers.map(e=>({...e,path:i(e.path)})):void 0,warnings:o.warnings});return n===`text`&&mm(o.warnings),L(s)}catch(e){return pm(e,`Reference placement lookup failed.`)}}})}function ch({plugin:e}={}){let t=fm(e);return{load:ih(t),list:eh(t),search:ah(t),where:sh(t),create:km(t),customize:Um(t),delete:Gm(t),check:Om(t),implementations:$m(t)}}function lh(e={}){let{load:t,list:n,search:r,where:i,create:a,customize:o,delete:s,check:c,implementations:l}=ch(e);return M({name:`reference`,description:`Read reference documents by name, composed from the managed, repo, user, plugin, and default tiers, and create, customize, or delete a contribution.`,commands:[t,n,r,i,a,o,s,l,c]})}function uh(e){return JSON.parse(o(e,`utf8`))}function dh(){let e=new URL(`../package.json`,import.meta.url),{name:n}=uh(new URL(`../plugin.json`,import.meta.url)),{version:r}=uh(e);return{name:n,version:r,root:m(t(e))}}function fh({name:e,version:t,root:n},r){return Mi({format:r,name:`cyber-agentkit`,version:t,description:`Work with the AI agent harness running here: read its layered reference documents, and update prose a tool wrote earlier.`}).command(lh({plugin:{name:e,root:n}})).command(gp({plugin:{name:e,root:n}})).command(cm())}function ph(e){let t=e.slice(2);if(t.some(e=>e===`--format`||e.startsWith(`--format=`)))return`toon`;let n=t[0]===`reference`||t[0]===`asset`||t[0]===`prose-update`?t[1]:void 0;return[`show`,`load`,`create`,`customize`,`update`,`select`,`delete`,`retire`].includes(n??``)?`text`:`toon`}async function mh(e,t=dh()){try{let n=await fh(t,ph(e)).parse(e);return typeof n==`number`?n:A.success}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`Invalid command.`}\n`),A.usage}}process.exitCode=await mh([...process.argv.slice(0,2),`asset`,...process.argv.slice(2)],{name:k,version:ne,root:t(new URL(`../../..`,import.meta.url))});export{};
|