@truenine/memory-sync-cli 2026.10314.10813 → 2026.10314.11719
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/dist/globals.d.cts +1 -1
- package/dist/globals.d.mts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin-runtime.mjs +8 -5
- package/dist/plugin.config-BxRsHOpl.mjs +73 -0
- package/dist/{plugin.config-M0Vfj7Yf.cjs → plugin.config-CiXDoU08.cjs} +73 -70
- package/dist/plugin.config-DEsNe6a1.mjs +174 -0
- package/package.json +9 -9
- package/dist/plugin.config-CwTid43p.mjs +0 -171
- package/dist/plugin.config-PD_T1uuL.mjs +0 -73
package/dist/globals.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../libraries/md-compiler/dist/index-
|
|
1
|
+
//#region ../libraries/md-compiler/dist/index-C0N3q7pl.d.mts
|
|
2
2
|
//#region src/globals/index.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* // These types are available to users when writing MDX templates. // Global type declarations for MDX expression scope. // src/globals/index.ts
|
package/dist/globals.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../libraries/md-compiler/dist/index-
|
|
1
|
+
//#region ../libraries/md-compiler/dist/index-C0N3q7pl.d.mts
|
|
2
2
|
//#region src/globals/index.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* // These types are available to users when writing MDX templates. // Global type declarations for MDX expression scope. // src/globals/index.ts
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./plugin.config-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./plugin.config-CiXDoU08.cjs`);let t=require(`node:process`);t=e.y(t);async function n(){let n=new e.s(...t.default.argv),{default:r}=await Promise.resolve().then(()=>require(`./plugin.config-CiXDoU08.cjs`)).then(e=>e.n),i=await r;(await n.run(i)).success||t.default.exit(1)}function r(e){return e.some(e=>e===`--json`||e===`-j`||/^-[^-]*j/.test(e))}function i(e){t.default.stdout.write(`${JSON.stringify({success:!1,filesAffected:0,dirsAffected:0,message:e,pluginResults:[],errors:[e]})}\n`)}n().catch(n=>{let a=n instanceof Error?n.message:String(n);r(t.default.argv)&&(i(a),t.default.exit(1)),e.v(`main`,`error`).error(`unhandled error`,{error:a}),t.default.exit(1)}),exports.ConfigLoader=e.c,exports.DEFAULT_CONFIG_FILE_NAME=e.l,exports.DEFAULT_GLOBAL_CONFIG_DIR=e.u,exports.DEFAULT_USER_CONFIG=e.g,exports.PathPlaceholders=e._,exports.checkVersionControl=e.a,exports.default=e.t,exports.defineConfig=e.r,exports.ensureConfigLink=e.d,exports.generateAindex=e.o,exports.getConfigLoader=e.f,exports.getGlobalConfigPath=e.p,exports.loadUserConfig=e.m,exports.mergeConfig=e.i,exports.validateGlobalConfig=e.h;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,o as u,p as d,r as f,s as p,t as m,u as h,v as g}from"./plugin.config-
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,o as u,p as d,r as f,s as p,t as m,u as h,v as g}from"./plugin.config-DEsNe6a1.mjs";import _ from"node:process";async function v(){let e=new p(..._.argv),{default:t}=await import(`./plugin.config-DEsNe6a1.mjs`).then(e=>e.n),n=await t;(await e.run(n)).success||_.exit(1)}function y(e){return e.some(e=>e===`--json`||e===`-j`||/^-[^-]*j/.test(e))}function b(e){_.stdout.write(`${JSON.stringify({success:!1,filesAffected:0,dirsAffected:0,message:e,pluginResults:[],errors:[e]})}\n`)}v().catch(e=>{let t=e instanceof Error?e.message:String(e);y(_.argv)&&(b(t),_.exit(1)),g(`main`,`error`).error(`unhandled error`,{error:t}),_.exit(1)});export{n as ConfigLoader,c as DEFAULT_CONFIG_FILE_NAME,h as DEFAULT_GLOBAL_CONFIG_DIR,a as DEFAULT_USER_CONFIG,e as PathPlaceholders,t as checkVersionControl,m as default,f as defineConfig,r as ensureConfigLink,u as generateAindex,i as getConfigLoader,d as getGlobalConfigPath,l as loadUserConfig,s as mergeConfig,o as validateGlobalConfig};
|
package/dist/plugin-runtime.mjs
CHANGED
|
@@ -90,9 +90,12 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
|
|
|
90
90
|
---`:`---\n${f.stringify(n,{singleQuote:t?.singleQuote??!1,lineWidth:t?.lineWidth??0}).trimEnd()}\n---`}function Jf(e,t,n){return Kf!=null&&n==null?e==null||Object.keys(e).length===0?t:Kf.buildMarkdownWithFrontMatter(JSON.stringify(e),t):e==null||Object.keys(e).length===0?t:`${qf(e,n)}\n${t}`}function Yf(e){let t=e.trim();return t.length===0?`---
|
|
91
91
|
---`:`---\n${t}\n---`}function Xf(e,t){return`${Yf(e)}\n${t}`}function Zf(e){let t=new f.Scalar(e);return t.type=f.Scalar.QUOTE_DOUBLE,t}function Qf(e){if(Kf!=null){let t=Kf.parseMarkdown(e),n=t.yamlFrontMatterJson==null?void 0:JSON.parse(t.yamlFrontMatterJson),r=Gf(e),i=[];for(let e of r.children)e.type!==`yaml`&&i.push(e);return{...n!=null&&{yamlFrontMatter:n},...t.rawFrontMatter!=null&&{rawFrontMatter:t.rawFrontMatter},markdownAst:r,markdownContents:i,contentWithoutFrontMatter:t.contentWithoutFrontMatter}}let t=Gf(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){r=e.value;try{n=f.parse(e.value??``)}catch{}}else i.push(e);let a=e;return r!=null&&(a=e.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``)),{...n!=null&&{yamlFrontMatter:n},...r!=null&&{rawFrontMatter:r},markdownAst:t,markdownContents:i,contentWithoutFrontMatter:a}}function $f(e){return Kf==null?e.replaceAll(/(!?\[)([^\]]*)(\]\()([^)]+)(\))/g,(e,t,n,r,i,a)=>{let o=n.replaceAll(/\.mdx$/g,`.md`).replaceAll(/\.mdx(?=#|\?|$)/g,`.md`);return/^(?:https?:)?\/\//.test(i)?`${t}${o}${r}${i}${a}`:`${t}${o}${r}${i.replace(/\.mdx$/,`.md`).replace(/\.mdx#/,`.md#`).replace(/\.mdx\?/,`.md?`)}${a}`}):Kf.transformMdxReferencesToMd(e)}const ep={"win32-x64":{local:`napi-script-runtime.win32-x64-msvc`,suffix:`win32-x64-msvc`},"linux-x64":{local:`napi-script-runtime.linux-x64-gnu`,suffix:`linux-x64-gnu`},"linux-arm64":{local:`napi-script-runtime.linux-arm64-gnu`,suffix:`linux-arm64-gnu`},"darwin-arm64":{local:`napi-script-runtime.darwin-arm64`,suffix:`darwin-arm64`},"darwin-x64":{local:`napi-script-runtime.darwin-x64`,suffix:`darwin-x64`}};let tp,np;function rp(){let e=ep[`${o.platform}-${o.arch}`];if(e!=null)return e;throw Error(`Unsupported platform for @truenine/script-runtime native binding: ${o.platform}-${o.arch}`)}function ip(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.validate_public_path==`function`||typeof t.validatePublicPath==`function`||typeof t.resolve_public_path==`function`||typeof t.resolvePublicPath==`function`}function ap(e,t,n){let r=e instanceof Error?e.message:String(e),i=t instanceof Error?t.message:String(t);return Error([`Failed to load @truenine/script-runtime native binding.`,`Tried local binary "./${ep[`${o.platform}-${o.arch}`]?.local??`unknown`}.node" and package "@truenine/memory-sync-cli-${n}".`,`Local error: ${r}`,`Package error: ${i}`,"Run `pnpm -F @truenine/script-runtime run build` to build the native module."].join(`
|
|
92
92
|
`))}function op(){let t=e(import.meta.url),{local:n,suffix:r}=rp();try{return t(`./${n}.node`)}catch(e){try{let e=t(`@truenine/memory-sync-cli-${r}`).scriptRuntime;if(ip(e))return e;throw Error(`Package "@truenine/memory-sync-cli-${r}" does not export a scriptRuntime binding`)}catch(t){throw ap(e,t,r)}}}function sp(){if(tp!=null)return tp;if(np!=null)throw np;try{return tp=op(),tp}catch(e){throw np=e instanceof Error?e:Error(String(e)),np}}function cp(e,t,n){let r=sp(),i=r.resolve_public_path??r.resolvePublicPath;if(i==null)throw Error(`resolve_public_path native binding is unavailable`);return i(e,t,n)}function lp(){let e=[u(new URL(`./resolve-proxy-worker.mjs`,import.meta.url)),u(new URL(`./script-runtime-worker.mjs`,import.meta.url))];for(let n of e)if(t.existsSync(n))return n;return e[0]}function up(e,t,n,r=5e3){return cp(e,JSON.stringify({...t,workerPath:lp(),timeoutMs:r}),n)}const dp={SRC:`src`,DIST:`dist`,SKILLS:`skills`,COMMANDS:`commands`,AGENTS:`agents`,RULES:`rules`,APP:`app`,IDEA:`.idea`,IDEA_CODE_STYLES:`.idea/codeStyles`,VSCODE:`.vscode`},Q={GLOBAL_MEMORY:`global.mdx`,GLOBAL_MEMORY_SRC:`global.src.mdx`,WORKSPACE_MEMORY:`workspace.mdx`,WORKSPACE_MEMORY_SRC:`workspace.src.mdx`,EDITOR_CONFIG:`.editorconfig`,IDEA_GITIGNORE:`.idea/.gitignore`,IDEA_PROJECT_XML:`.idea/codeStyles/Project.xml`,IDEA_CODE_STYLE_CONFIG_XML:`.idea/codeStyles/codeStyleConfig.xml`,VSCODE_SETTINGS:`.vscode/settings.json`,VSCODE_EXTENSIONS:`.vscode/extensions.json`,QODER_IGNORE:`.qoderignore`,CURSOR_IGNORE:`.cursorignore`,WARP_INDEX_IGNORE:`.warpindexignore`,AI_IGNORE:`.aiignore`,CODEIUM_IGNORE:`.codeiumignore`};dp.SKILLS,dp.COMMANDS,dp.AGENTS,dp.RULES,Q.GLOBAL_MEMORY_SRC,Q.WORKSPACE_MEMORY_SRC,dp.SKILLS,dp.COMMANDS,dp.AGENTS,dp.RULES,Q.GLOBAL_MEMORY,Q.WORKSPACE_MEMORY,dp.APP,dp.APP,dp.IDEA,dp.IDEA_CODE_STYLES,dp.VSCODE,Q.EDITOR_CONFIG,Q.IDEA_GITIGNORE,Q.IDEA_PROJECT_XML,Q.IDEA_CODE_STYLE_CONFIG_XML,Q.VSCODE_SETTINGS,Q.VSCODE_EXTENSIONS,Q.QODER_IGNORE,Q.CURSOR_IGNORE,Q.WARP_INDEX_IGNORE,Q.AI_IGNORE,Q.CODEIUM_IGNORE;let fp=function(e){return e.Input=`input`,e.Output=`output`,e}({}),pp=function(e){return e.GlobalMemory=`globalMemory`,e.ProjectRootMemory=`projectRootMemory`,e.ProjectChildrenMemory=`projectChildrenMemory`,e.Command=`command`,e.SubAgent=`subAgent`,e.Skill=`skill`,e.SkillChildDoc=`skillChildDoc`,e.SkillResource=`skillResource`,e.SkillMcpConfig=`skillMcpConfig`,e.Readme=`readme`,e.Rule=`rule`,e}({}),mp=function(e){return e.Relative=`relative`,e.Absolute=`absolute`,e.Root=`root`,e}({}),hp=function(e){return e.VSCode=`vscode`,e.IntellijIDEA=`intellijIdea`,e.Git=`git`,e.EditorConfig=`editorconfig`,e.Original=`original`,e}({}),gp=function(e){return e.UserHome=`userHome`,e.External=`external`,e}({});const _p=`proxy.ts`,vp=`.gitignore`,yp=`.git/info/exclude`,bp=[Q.QODER_IGNORE,Q.CURSOR_IGNORE,Q.WARP_INDEX_IGNORE,Q.AI_IGNORE,Q.CODEIUM_IGNORE,`.kiroignore`,`.traeignore`],xp=[vp,yp,Q.EDITOR_CONFIG,Q.VSCODE_SETTINGS,Q.VSCODE_EXTENSIONS,Q.IDEA_PROJECT_XML,Q.IDEA_CODE_STYLE_CONFIG_XML,Q.IDEA_GITIGNORE,...bp],Sp=new Map;function Cp(e){let t=e.split(/[\\/]+/).filter(e=>e.length>0).join(`/`);if(t.length===0)throw Error(`public target relative path cannot be empty`);return t}function wp(e){return n.join(e,`public`)}function Tp(e){return n.join(wp(e),_p)}function Ep(e){return e?.command??`execute`}function Dp(e,t){return n.resolve(t?.workspaceDir??n.dirname(e))}function Op(e,t,r){return{cwd:t,workspaceDir:t,aindexDir:n.resolve(e),command:r,platform:o.platform}}function kp(e,n,r){let i=Cp(n);if(i===_p)return _p;let a=Tp(e);if(!(t.existsSync(a)&&t.statSync(a).isFile()))return i;let o=Ep(r),s=Dp(e,r),c=[a,s,o,i].join(`::`),l=Sp.get(c);if(l!=null)return l;let u=up(a,Op(e,s,o),i);return Sp.set(c,u),u}function Ap(e,t,r){let i=kp(e,t,r);return n.join(wp(e),...i.split(/[\\/]+/))}function jp(e,t){let n=new Set([Ap(e,_p)]);for(let r of xp)n.add(Ap(e,r,t));return[...n]}function Mp(e,t,r,i,a){let o=Ap(r,t,a);if(!(i.existsSync(o)&&i.statSync(o).isFile()))return;let s=i.readFileSync(o,`utf8`);return{type:e,content:s,length:s.length,filePathKind:mp.Absolute,dir:{pathKind:mp.Absolute,path:o,getDirectoryName:()=>n.basename(o)}}}var Np=class extends Error{operation;violations;constructor(e,t){super(dm(e,t)),this.name=`ProtectedDeletionGuardError`,this.operation=e,this.violations=t}};const Pp=[`skills`,`commands`,`subAgents`,`rules`,`app`,`ext`,`arch`],Fp=[`globalPrompt`,`workspacePrompt`];function Ip(e){let t=o.env.XDG_CONFIG_HOME;return typeof t==`string`&&t.trim().length>0?t:n.join(e,`.config`)}function Lp(e){let t=o.env.XDG_DATA_HOME;return typeof t==`string`&&t.trim().length>0?t:n.join(e,`.local`,`share`)}function Rp(e){let t=o.env.XDG_STATE_HOME;return typeof t==`string`&&t.trim().length>0?t:n.join(e,`.local`,`state`)}function zp(e){let t=o.env.XDG_CACHE_HOME;return typeof t==`string`&&t.trim().length>0?t:n.join(e,`.cache`)}function Bp(e){if(e!=null){if(typeof e.getAbsolutePath==`function`)try{let t=e.getAbsolutePath();if(t.length>0)return n.resolve(t)}catch{}if(e.pathKind===`absolute`)return n.resolve(e.path);if(typeof e.basePath==`string`&&e.basePath.length>0)return n.resolve(e.basePath,e.path)}}function Vp(e){return e===`~`?s.homedir():e.startsWith(`~/`)||e.startsWith(`~\\`)?n.resolve(s.homedir(),e.slice(2)):e}function Hp(e){return n.resolve(Vp(e))}function Up(e){let t=n.normalize(Hp(e));return o.platform===`win32`?t.toLowerCase():t}function Wp(e){let{root:t}=n.parse(e);return e===t?e:e.endsWith(n.sep)?e.slice(0,-1):e}function Gp(e,t){let r=Wp(e),i=Wp(t);return r===i?!0:r.startsWith(`${i}${n.sep}`)}function Kp(e){let n=Hp(e),r=new Set([Up(n)]);try{if(t.existsSync(n)){let e=t.realpathSync.native(n);r.add(Up(e))}}catch{}return[...r]}function $(e,t,n,r,i=`path`){return{path:Hp(e),protectionMode:t,reason:n,source:r,matcher:i}}function qp(e){let t=Up(e.path);return{...e,path:Hp(e.path),comparisonKeys:Kp(e.path),normalizedPath:t,specificity:Wp(t).length}}function Jp(e){let t=new Map;for(let n of e){let e=qp(n);t.set(`${e.protectionMode}:${e.normalizedPath}`,e)}return[...t.values()].sort((e,t)=>{let n=t.specificity-e.specificity;return n===0?e.protectionMode===t.protectionMode?e.path.localeCompare(t.path):e.protectionMode===`recursive`?-1:1:n})}function Yp(e){return Hp(e).replaceAll(`\\`,`/`)}function Xp(e){let t=[];for(let n of e){if(n.matcher!==`glob`){t.push($(n.path,n.protectionMode,n.reason,n.source));continue}let e=nt.default.sync(Yp(n.path),{onlyFiles:!1,dot:!0,absolute:!0,followSymbolicLinks:!1});for(let r of e)t.push($(r,n.protectionMode,n.reason,n.source))}return t}function Zp(e,t,n){return n===`direct`?Gp(t,e):Gp(e,t)||Gp(t,e)}function Qp(e,n){let r=Hp(e);try{if(t.existsSync(r)&&t.lstatSync(r).isDirectory())return`recursive`}catch{}return n}function $p(){let e=s.homedir();return[$(n.parse(e).root,`direct`,`built-in dangerous root path`,`built-in-dangerous-root`),$(e,`direct`,`built-in dangerous home directory`,`built-in-dangerous-root`),$(Ip(e),`direct`,`built-in dangerous config directory`,`built-in-dangerous-root`),$(Lp(e),`direct`,`built-in dangerous data directory`,`built-in-dangerous-root`),$(Rp(e),`direct`,`built-in dangerous state directory`,`built-in-dangerous-root`),$(zp(e),`direct`,`built-in dangerous cache directory`,`built-in-dangerous-root`),$(n.join(e,`.aindex`),`direct`,`built-in global aindex directory`,`built-in-dangerous-root`),$(n.join(e,`.aindex`,`.tnmsc.json`),`direct`,`built-in global config file`,`built-in-config`)]}function em(e,t,r){let i=[$(e,`direct`,`workspace root`,`workspace-reserved`),$(n.join(e,`aindex`),`direct`,`reserved workspace aindex root`,`workspace-reserved`),$(n.join(e,`knowladge`),`direct`,`reserved workspace knowladge root`,`workspace-reserved`)];for(let e of t)i.push($(e,`direct`,`workspace project root`,`workspace-project-root`));return r&&i.push($(n.join(e,`aindex`,`dist`,`**`,`*.mdx`),`direct`,`reserved workspace aindex dist mdx files`,`workspace-reserved`,`glob`),$(n.join(e,`aindex`,`app`,`**`,`*.mdx`),`direct`,`reserved workspace aindex app mdx files`,`workspace-reserved`,`glob`)),i}function tm(e){return[$(e,`direct`,`resolved aindex root`,`aindex-root`)]}function nm(e,t){return jp(e,t)}function rm(e,t,r){let i=[];for(let r of Pp)i.push($(n.join(t,e.aindex[r].src),`recursive`,`configured aindex ${r} source directory`,`configured-aindex-source`));for(let r of Fp)i.push($(n.join(t,e.aindex[r].src),`direct`,`configured aindex ${r} source file`,`configured-aindex-source`));for(let e of nm(t,r))i.push($(e,`direct`,`known aindex input config file`,`known-aindex-config`));return i}function im(e){let t=[],n=new Set,r=(e,r,i,a)=>{if(e==null||e.length===0)return;let o=$(e,r,i,a),s=`${o.protectionMode}:${Up(o.path)}`;n.has(s)||(n.add(s),t.push(o))},i=(e,t,n,i)=>{let a=Bp(e);a!=null&&r(a,t,n,i)};i(e.globalMemory?.dir,`recursive`,`global memory source directory`,`collected-input-source`);for(let t of e.commands??[])i(t.dir,`recursive`,`command source directory`,`collected-input-source`);for(let t of e.subAgents??[])i(t.dir,`recursive`,`sub-agent source directory`,`collected-input-source`);for(let t of e.rules??[])i(t.dir,`recursive`,`rule source directory`,`collected-input-source`);for(let t of e.skills??[]){i(t.dir,`recursive`,`skill source directory`,`collected-input-source`);for(let e of t.childDocs??[])i(e.dir,`recursive`,`skill child document directory`,`collected-input-source`);for(let e of t.resources??[])e.sourcePath==null||e.sourcePath.length===0||r(e.sourcePath,Qp(e.sourcePath,`direct`),`skill resource source path`,`collected-input-source`)}for(let t of e.vscodeConfigFiles??[])i(t.dir,`direct`,`vscode input config file`,`collected-input-config`);for(let t of e.jetbrainsConfigFiles??[])i(t.dir,`direct`,`jetbrains input config file`,`collected-input-config`);for(let t of e.editorConfigFiles??[])i(t.dir,`direct`,`editorconfig input file`,`collected-input-config`);for(let t of e.aiAgentIgnoreConfigFiles??[])r(t.sourcePath,`direct`,`AI agent ignore config file`,`collected-input-config`);if(e.aindexDir!=null)for(let t of nm(e.aindexDir,{workspaceDir:e.workspace.directory.path}))r(t,`direct`,`known aindex input config file`,`known-aindex-config`);return t}function am(e){let t=[];for(let n of e.exactProtectedPaths??[])t.push($(n,`direct`,`legacy direct protected path`,`legacy-direct`));for(let n of e.subtreeProtectedPaths??[])t.push($(n,`recursive`,`legacy recursive protected path`,`legacy-recursive`));return t}function om(e={}){let t=e.includeReservedWorkspaceContentRoots??!0,n=Jp(Xp([...$p(),...am(e),...e.workspaceDir==null?[]:em(e.workspaceDir,e.projectRoots??[],t),...e.aindexDir==null?[]:tm(e.aindexDir),...e.rules??[]]));return{rules:n.map(e=>({path:e.path,protectionMode:e.protectionMode,reason:e.reason,source:e.source,...e.matcher==null?{}:{matcher:e.matcher}})),exactProtectedPaths:n.filter(e=>e.protectionMode===`direct`).map(e=>e.path),subtreeProtectedPaths:n.filter(e=>e.protectionMode===`recursive`).map(e=>e.path),compiledRules:n}}function sm(e){let t=new Set;for(let n of e.workspace.projects){let e=n.dirFromWorkspacePath?.getAbsolutePath?.();e!=null&&e.length>0&&t.add(Hp(e))}return[...t]}function cm(e,t){return t==null?e:e.specificity===t.specificity?e.protectionMode===t.protectionMode?e.path.localeCompare(t.path)<0?e:t:e.protectionMode===`recursive`?e:t:e.specificity>t.specificity?e:t}function lm(e,t){let n=Hp(e),r=Kp(n),i;for(let e of t.compiledRules){let t=!1;for(let n of r){for(let r of e.comparisonKeys)if(Zp(n,r,e.protectionMode)){i=cm(e,i),t=!0;break}if(t)break}}if(i!=null)return{targetPath:n,protectedPath:i.path,protectionMode:i.protectionMode,reason:i.reason,source:i.source}}function um(e,t){let n=[],r=new Map;for(let i of e){let e=Hp(i),a=lm(e,t);if(a==null){n.push(e);continue}r.has(a.targetPath)||r.set(a.targetPath,a)}return{safePaths:n,violations:[...r.values()].sort((e,t)=>e.targetPath.localeCompare(t.targetPath))}}function dm(e,t){let n=t.map(e=>e.targetPath).join(`, `);return`Protected deletion guard blocked ${e} for ${t.length} path(s): ${n}`}function fm(e,t,n){e.error(`protected deletion guard triggered`,{operation:t,count:n.length,violations:n.map(e=>({targetPath:e.targetPath,protectedPath:e.protectedPath,protectionMode:e.protectionMode,source:e.source,reason:e.reason}))})}const pm={"win32-x64":{local:`napi-logger.win32-x64-msvc`,suffix:`win32-x64-msvc`},"linux-x64":{local:`napi-logger.linux-x64-gnu`,suffix:`linux-x64-gnu`},"linux-arm64":{local:`napi-logger.linux-arm64-gnu`,suffix:`linux-arm64-gnu`},"darwin-arm64":{local:`napi-logger.darwin-arm64`,suffix:`darwin-arm64`},"darwin-x64":{local:`napi-logger.darwin-x64`,suffix:`darwin-x64`}},mm=[`error`,`warn`,`info`,`debug`,`trace`,`fatal`];let hm,gm;function _m(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.createLogger==`function`&&typeof t.setGlobalLogLevel==`function`&&typeof t.getGlobalLogLevel==`function`}function vm(){let e=pm[`${o.platform}-${o.arch}`];if(e!=null)return e;throw Error(`Unsupported platform for @truenine/logger native binding: ${o.platform}-${o.arch}`)}function ym(e,t,n){let r=e instanceof Error?e.message:String(e),i=t instanceof Error?t.message:String(t);return Error([`Failed to load @truenine/logger native binding.`,`Tried local binary "./${pm[`${o.platform}-${o.arch}`]?.local??`unknown`}.node" and package "@truenine/memory-sync-cli-${n}".`,`Local error: ${r}`,`Package error: ${i}`,"Run `pnpm -F @truenine/logger run build` to build the native module."].join(`
|
|
93
|
-
`))}function bm(){let t=import.meta.url,n=e(t),{local:r,suffix:i}=vm();try{return n(`./${r}.node`)}catch(e){try{let e=n(`@truenine/memory-sync-cli-${i}`).logger;if(_m(e))return e;throw Error(`Package "@truenine/memory-sync-cli-${i}" does not export a logger binding`)}catch(t){throw ym(e,t,i)}}}function xm(){if(hm!=null)return hm;if(gm!=null)throw gm;try{return hm=bm(),hm}catch(e){throw gm=e instanceof Error?e:Error(String(e)),gm}}function Sm(e){let t={name:e.name,message:e.message,stack:e.stack};for(let n of Object.getOwnPropertyNames(e))n===`name`||n===`message`||n===`stack`||(t[n]=e[n]);return t}function Cm(){let e=new WeakSet;return function(t,n){return n instanceof Error?Sm(n):typeof n==`bigint`?n.toString():typeof n==`function`?`[Function ${n.name||`anonymous`}]`:typeof n==`symbol`?n.toString():typeof n!=`object`||!n?n:e.has(n)?`[Circular]`:(e.add(n),n)}}function wm(e){return JSON.stringify(e,Cm())??`null`}function Tm(e,t){if(typeof e!=`string`)return{message:``,metaJson:wm(e)};let n=t.length===1&&typeof t[0]==`object`&&t[0]!==null?t[0]:t.length>0?{args:t}:void 0;return{message:e,metaJson:n==null?void 0:wm(n)}}function Em(e,t){return(n,...r)=>{let{message:i,metaJson:a}=Tm(n,r);e.log(t,i,a)}}function Dm(e){let t=mm.reduce((t,n)=>(t[n]=Em(e,n),t),{});return{error:t.error,warn:t.warn,info:t.info,debug:t.debug,trace:t.trace,fatal:t.fatal}}function Om(e){xm().setGlobalLogLevel(e)}function km(e,t){return Dm(xm().createLogger(e,t))}var Am=class{type;name;_log;get log(){return this._log??=km(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}};const jm={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Mm={AgentsOutput:`AgentsOutputPlugin`,GeminiCLIOutput:`GeminiCLIOutputPlugin`,CursorOutput:`CursorOutputPlugin`,WindsurfOutput:`WindsurfOutputPlugin`,ClaudeCodeCLIOutput:`ClaudeCodeCLIOutputPlugin`,KiroIDEOutput:`KiroCLIOutputPlugin`,OpencodeCLIOutput:`OpencodeCLIOutputPlugin`,OpenAICodexCLIOutput:`CodexCLIOutputPlugin`,DroidCLIOutput:`DroidCLIOutputPlugin`,WarpIDEOutput:`WarpIDEOutputPlugin`,TraeIDEOutput:`TraeIDEOutputPlugin`,TraeCNIDEOutput:`TraeCNIDEOutputPlugin`,QoderIDEOutput:`QoderIDEPluginOutputPlugin`,JetBrainsCodeStyleOutput:`JetBrainsIDECodeStyleConfigOutputPlugin`,JetBrainsAICodexOutput:`JetBrainsAIAssistantCodexOutputPlugin`,AgentSkillsCompactOutput:`GenericSkillsOutputPlugin`,GitExcludeOutput:`GitExcludeOutputPlugin`,ReadmeOutput:`ReadmeMdConfigFileOutputPlugin`,VSCodeOutput:`VisualStudioCodeIDEConfigOutputPlugin`,EditorConfigOutput:`EditorConfigOutputPlugin`,AntigravityOutput:`AntigravityOutputPlugin`},Nm={SKILL:`SKILL.md`,CURSOR_GLOBAL_RULE:`global.mdc`,CURSOR_PROJECT_RULE:`always.md`,MCP_CONFIG:`mcp.json`,CLAUDE_MEMORY:`CLAUDE.md`,WINDSURF_GLOBAL_RULE:`global_rules.md`},Pm={RULES:`rules`,COMMANDS:`commands`,SKILLS:`skills`,AGENTS:`agents`,CURSOR_SKILLS:`skills-cursor`},Fm={MD:`.md`,MDC:`.mdc`,MDX:`.mdx`,JSON:`.json`},Im=[{PRIMARY:`.src.mdx`}.PRIMARY],Lm={zh:Im,en:Fm.MDX};function Rm(e){return Im.some(t=>e.endsWith(t))}const zm={CURSOR:`.cursor`,CLAUDE:`.claude`,WINDSURF:`.codeium/windsurf`,WINDSURF_RULES:`.windsurf`},Bm={CURSOR:`.cursorignore`,WINDSURF:`.codeiumignore`},Vm={CURSOR:new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`])};var Hm=class extends Am{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,fp.Input,t)}registerEffect(e,t,n=0){this.inputEffects.push({name:e,handler:t,priority:n}),this.inputEffects.sort((e,t)=>(e.priority??0)-(t.priority??0))}async executeEffects(e,t=!1){let n=[];if(this.inputEffects.length===0)return n;let{workspaceDir:r,aindexDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:l,userConfigOptions:e.userConfigOptions,workspaceDir:r,aindexDir:i,dryRun:t};for(let e of this.inputEffects){if(t){this.log.trace({action:`dryRun`,type:`inputEffect`,name:e.name}),n.push({success:!0,description:`Would execute input effect: ${e.name}`});continue}try{let t=await e.handler(a);if(t.success)this.log.trace({action:`inputEffect`,name:e.name,status:`success`,description:t.description}),t.modifiedFiles!=null&&t.modifiedFiles.length>0&&this.log.debug({action:`inputEffect`,name:e.name,modifiedFiles:t.modifiedFiles}),t.deletedFiles!=null&&t.deletedFiles.length>0&&this.log.debug({action:`inputEffect`,name:e.name,deletedFiles:t.deletedFiles});else throw t.error??Error(`Input effect failed: ${e.name}`);n.push(t)}catch(t){let r=t instanceof Error?t:Error(String(t));throw this.logInputEffectFailure(e.name,r),n.push({success:!1,error:r,description:`Input effect failed: ${e.name}`}),r}}return n}logInputEffectFailure(e,t){if(t instanceof Np){fm(this.log,t.operation,t.violations);return}this.log.error({action:`inputEffect`,name:e,status:`failed`,error:t.message})}hasEffects(){return this.inputEffects.length>0}getEffectCount(){return this.inputEffects.length}registerScope(e,t){this.registeredScopes.push({namespace:e,values:t}),this.log.debug({action:`registerScope`,namespace:e,keys:Object.keys(t)})}getRegisteredScopes(){return this.registeredScopes}clearRegisteredScopes(){this.registeredScopes.length=0,this.log.debug({action:`clearRegisteredScopes`})}resolveBasePaths(e){let t=e.workspaceDir,r=this.resolvePath(t,``),i=e.aindex?.dir??`aindex`;return{workspaceDir:r,aindexDir:n.join(r,i)}}resolvePath(e,t){let r=e;return r.startsWith(jm.USER_HOME)&&(r=r.replace(jm.USER_HOME,s.homedir())),r.includes(jm.WORKSPACE)&&(r=r.replace(jm.WORKSPACE,t)),n.normalize(r)}resolveAindexPath(e,t){return n.join(t,e)}readAndParseMarkdown(e,t){return Qf(t.readFileSync(e,`utf8`))}},Um=class extends Error{constructor(e,t,n){super(e),this.expression=t,this.filePath=n,this.name=`ScopeError`}},Wm=class extends Um{constructor(e,t,n){let r=n!=null&&n.length>0?`Undefined variable "${e}" in expression "${t}" (file: ${n})`:`Undefined variable "${e}" in expression "${t}"`;super(r,t,n),this.variableName=e,this.name=`UndefinedVariableError`}},Gm=class extends Um{constructor(e,t,n){let r=n!=null&&n.length>0?`Undefined namespace "${e}" in expression "${t}" (file: ${n})`:`Undefined namespace "${e}" in expression "${t}"`;super(r,t,n),this.namespace=e,this.name=`UndefinedNamespaceError`}},Km=class extends Error{constructor(e,t){let n=t!=null&&t.length>0?`Missing required metadata fields: ${e.join(`, `)} (file: ${t})`:`Missing required metadata fields: ${e.join(`, `)}`;super(n),this.missingFields=e,this.filePath=t,this.name=`MetadataValidationError`}},qm=Object.defineProperty,Jm=(e,t)=>{let n={};for(var r in e)qm(n,r,{get:e[r],enumerable:!0});return t||qm(n,Symbol.toStringTag,{value:`Module`}),n};const Ym=new Map;function Xm(e,t){Ym.set(e,t)}function Zm(){return new Map(Ym)}function Qm(e){return Ym.has(e)}function $m(e,t,n){let r=e.trim();return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?eh(r,t,n?.filePath):th(r,t,n?.filePath)}function eh(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new Gm(i??``,e,n);let a=t[i];for(let t=1;t<r.length;t++){let i=r[t];if(i==null)continue;if(a==null)throw new Wm(i,e,n);if(typeof a!=`object`)throw TypeError(`Cannot read property "${i}" of ${typeof a} in expression "${e}"`);let o=a;if(!(i in o))throw new Wm(i,e,n);a=o[i]}return nh(a)}function th(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return nh(Function(...r,`return (${e})`)(...i))}catch(t){let r=t instanceof Error?t.message:String(t);if(r.includes(`is not defined`)){let t=/(\w+) is not defined/.exec(r);if(t?.[1]!=null)throw new Gm(t[1],e,n)}let i=n==null?``:` (file: ${n})`;throw Error(`Failed to evaluate expression: "${e}"${i}\nCause: ${r}`)}}function nh(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(typeof e==`object`)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}function rh(e,t){return e===null?!1:t.components.has(e)||Qm(e)}async function ih(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function ah(e,t,n){let r=e.name;if(r==null||r===``)return[];let i=t.components.get(r);if(i==null)return[];if(t.processingStack.includes(r)){let e=[...t.processingStack,r].join(` → `);throw Error(`Circular dependency detected: ${e}`)}let a={scope:t.scope,components:t.components,processingStack:[...t.processingStack,r],...t.basePath==null?{}:{basePath:t.basePath}},o=await ih(n);try{return await i(e,a,o)}catch(e){let n=e instanceof Error?e.message:String(e),i=t.processingStack.join(` → `);throw Error(`Failed to process component "${r}"${i===``?``:` (called from: ${i})`}:\n${n}`,{cause:e})}}function oh(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return lh(e,t);case`a`:return uh(e,t);case`strong`:case`b`:return dh(e,t);case`em`:case`i`:return fh(e,t);case`img`:return ph(e,t);case`blockquote`:return mh(e,t);default:return null}}function sh(e,t,n){let r=e.attributes.find(e=>e.type===`mdxJsxAttribute`&&e.name===t);return r==null?null:typeof r.value==`string`?r.value:r.value!=null&&typeof r.value==`object`&&r.value.type===`mdxJsxAttributeValueExpression`?$m(r.value.value,n.scope):r.value===null?``:null}function ch(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=$m(r.value,t.scope):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=ch(r,t));return n}function lh(e,t){let n=null;for(let t of e.children){if((t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)&&t.name?.toLowerCase()===`code`){n=t;break}if(t.type===`paragraph`&&`children`in t){let e=t.children;for(let t of e)if((t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)&&t.name?.toLowerCase()===`code`){n=t;break}if(n!=null)break}}if(n==null)return null;let r=sh(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=ch(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function uh(e,t){let n=sh(e,`href`,t);if(n==null||n===``)return null;let r=ch(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:sh(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function dh(e,t){let n={type:`strong`,children:[{type:`text`,value:ch(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function fh(e,t){let n={type:`emphasis`,children:[{type:`text`,value:ch(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function ph(e,t){let n=sh(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:sh(e,`alt`,t)??``,title:sh(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function mh(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:ch(e,t)}]}]}]}function hh(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function gh(e,t,n){let r=e.data?.estree;if(r==null||r.body.length===0)return[];let i=r.body[0];return i?.type===`ExpressionStatement`?_h(i.expression,t,n):[]}async function _h(e,t,n){return e.type===`JSXElement`?Ch(e,t,n):e.type===`JSXFragment`?wh(e,t,n):e.type===`LogicalExpression`?vh(e,t,n):e.type===`ConditionalExpression`?yh(e,t,n):e.type===`SequenceExpression`?bh(e,t,n):e.type===`ArrayExpression`?xh(e,t,n):Nh(e,t)}async function vh(e,t,n){let r=await Sh(e.left,t,n);return e.operator===`&&`?jh(r)?_h(e.right,t,n):[]:e.operator===`||`?jh(r)?Ah(e.left)?_h(e.left,t,n):Mh(r):_h(e.right,t,n):e.operator===`??`?r==null?_h(e.right,t,n):Ah(e.left)?_h(e.left,t,n):Mh(r):[]}async function yh(e,t,n){return jh(await Sh(e.test,t,n))?_h(e.consequent,t,n):_h(e.alternate,t,n)}async function bh(e,t,n){let r=[];for(let i of e.expressions){let e=await _h(i,t,n);r.push(...e)}return r}async function xh(e,t,n){let r=[];for(let i of e.elements)if(i!=null)if(i.type===`SpreadElement`){let e=await _h(i.argument,t,n);r.push(...e)}else{let e=await _h(i,t,n);r.push(...e)}return r}async function Sh(e,t,n){if(Ah(e))return!0;if(e.type===`Literal`)return e.value;if(e.type===`Identifier`)return e.name===`undefined`?void 0:e.name===`NaN`?NaN:e.name===`Infinity`?1/0:t.scope[e.name];if(e.type===`UnaryExpression`){let r=await Sh(e.argument,t,n);return e.operator===`!`?!jh(r):e.operator===`-`?-r:e.operator===`+`?+r:e.operator===`typeof`?typeof r:void 0}if(e.type===`BinaryExpression`){let r=await Sh(e.left,t,n),i=await Sh(e.right,t,n);return e.operator===`===`?r===i:e.operator===`!==`?r!==i:e.operator===`==`?r===i:e.operator===`!=`?r!==i:e.operator===`<`?r<i:e.operator===`<=`?r<=i:e.operator===`>`?r>i:e.operator===`>=`?r>=i:e.operator===`+`?r+i:e.operator===`-`?r-i:e.operator===`*`?r*i:e.operator===`/`?r/i:e.operator===`%`?r%i:void 0}if(e.type===`LogicalExpression`){let r=await Sh(e.left,t,n);return e.operator===`&&`?jh(r)?Sh(e.right,t,n):r:e.operator===`||`?jh(r)?r:Sh(e.right,t,n):e.operator===`??`?r??Sh(e.right,t,n):void 0}if(e.type===`MemberExpression`){let r=await Sh(e.object,t,n);if(r==null)return;if(e.computed)return r[await Sh(e.property,t,n)];let{name:i}=e.property;return r[i]}if(e.type===`ConditionalExpression`)return jh(await Sh(e.test,t,n))?Sh(e.consequent,t,n):Sh(e.alternate,t,n);let r=kh(e);if(r!==``)try{let e=$m(r,t.scope);return e===`true`?!0:e===`false`?!1:e===`null`?null:e===`undefined`||e===``?void 0:/^-?\d+(?:\.\d+)?$/.test(e)?Number(e):e}catch{return}}async function Ch(e,t,n){let r=Eh(e,t);if(r.name!=null&&rh(r.name,t)){let{processAst:e}=await Promise.resolve().then(()=>Ph);return ah(r,t,e)}return oh(r,t)??(r.children.length>0?n(r.children,t):[])}async function wh(e,t,n){let r=[];for(let i of e.children){let e=await Th(i,t,n);r.push(...e)}return r}async function Th(e,t,n){if(e.type===`JSXElement`)return Ch(e,t,n);if(e.type===`JSXFragment`)return wh(e,t,n);if(e.type===`JSXText`){let t=e.value.trim();return t===``?[]:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?[]:_h(e.expression,t,n):e.type===`JSXSpreadChild`?_h(e.expression,t,n):[]}function Eh(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=Dh(n.name):n.name.type===`JSXNamespacedName`&&(r=`${n.name.namespace.name}:${n.name.name.name}`);let i=[];for(let e of n.attributes)if(e.type===`JSXAttribute`){let t=e.name.type===`JSXIdentifier`?e.name.name:`${e.name.namespace.name}:${e.name.name.name}`,n=null;e.value==null?n=null:e.value.type===`Literal`?n=String(e.value.value):e.value.type===`JSXExpressionContainer`&&e.value.expression.type!==`JSXEmptyExpression`&&(n={type:`mdxJsxAttributeValueExpression`,value:kh(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${kh(e.argument)}`});let a=[];for(let n of e.children){let e=Oh(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function Dh(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${Dh(e.object)}.${e.property.name}`}function Oh(e,t){if(e.type===`JSXText`){let{value:t}=e;return t.trim()===``?null:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}if(e.type===`JSXElement`)return[Eh(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=Oh(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:kh(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${kh(e.expression)}`}]}]:null}function kh(e){if(e.type===`Identifier`)return e.name;if(e.type===`Literal`)return typeof e.value==`string`?JSON.stringify(e.value):String(e.value);if(e.type===`MemberExpression`){let t=kh(e.object);return e.computed?`${t}[${kh(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${kh(e.callee)}(${e.arguments.map(e=>kh(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=kh(e.left),n=kh(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=kh(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${kh(e.test)} ? ${kh(e.consequent)} : ${kh(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>kh(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:kh(e.key)}: ${kh(e.value)}`).join(`, `)}}`;if(e.type===`TemplateLiteral`){let t="`";for(let n=0;n<e.quasis.length;n++)t+=e.quasis[n]?.value.raw??``,n<e.expressions.length&&(t+=`\${${kh(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${kh(e.argument)}`:``}function Ah(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function jh(e){return!!e}function Mh(e){if(e==null)return[];let t=typeof e==`string`?e:String(e);return t===``||t===`undefined`||t===`null`?[]:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}function Nh(e,t){let n=kh(e);if(n===``)return[];try{return Mh($m(n,t.scope))}catch{return[]}}var Ph=Jm({processAst:()=>Ih});function Fh(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function Ih(e,t){return Lh(e,t)}async function Lh(e,t){let n=[];for(let r of e.children){let e=await Rh(r,t);n.push(...e)}return{type:`root`,children:n}}async function Rh(e,t){if(e.type===`mdxjsEsm`)return[];if(e.type===`mdxFlowExpression`){let n=e,r=n.data?.estree,i=n.value.trim();if(i.startsWith(`/*`)&&i.endsWith(`*/`))return[];if(hh(r))return gh(n,t,async(e,t)=>(await Ih({type:`root`,children:e},t)).children);let a=$m(n.value,t.scope);return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return zh(e,t);if(e.type===`link`){let n=e,r=(await Bh(n.children,t)).map(e=>e.type===`text`?{...e,value:Fh(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await Bh(e.children,t);return[{...e,children:n}]}async function zh(e,t){return e.name!=null&&rh(e.name,t)?ah(e,t,Ih):oh(e,t)??[]}async function Bh(e,t){let n=[];for(let r of e){if(r.type===`mdxFlowExpression`){let e=r,i=e.data?.estree,a=e.value.trim();if(a.startsWith(`/*`)&&a.endsWith(`*/`))continue;if(hh(i)){let r=await gh(e,t,async(e,t)=>(await Ih({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=$m(e.value,t.scope);o!==``&&n.push({type:`paragraph`,children:[{type:`text`,value:o}]});continue}if(r.type===`mdxTextExpression`){let e=r,i=e.value.trim();if(i.startsWith(`/*`)&&i.endsWith(`*/`))continue;let a={type:`text`,value:$m(e.value,t.scope)};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&rh(e.name,t)){let r=await ah(e,t,Ih);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=oh(e,t);if(i!=null)for(let e of i)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}if(`children`in r&&Array.isArray(r.children)){let e=await Bh(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:Fh(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function Vh(e){let t=this;t.compiler=n;function n(n){return vi(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function Hh(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=Uh(t,i,a);Object.assign(n,e)}let o=Object.keys(n).length>0,s=r!=null&&Object.keys(r).length>0,c;return c=o&&s?`mixed`:o?`export`:`yaml`,{fields:{...r,...n},source:c}}function Uh(e,t,n){let r={},i=e.value.trim(),a=/^export\s+default\s+/.exec(i);if(a!=null){let e=a[0].length,o=Wh(i,e);if(o!=null)try{let e=Gh(o.trim(),t,n);typeof e==`object`&&e&&!Array.isArray(e)&&Object.assign(r,e)}catch(e){let t=e instanceof Error?e.message:String(e),r=n==null?``:` in file "${n}"`;throw Error(`Cannot statically evaluate export default${r}: ${t}`)}return r}let o=/export\s+const\s+(\w+)\s*=\s*/g,s=o.exec(i);for(;s!==null;){let e=s[1];if(e==null){s=o.exec(i);continue}let a=Wh(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=Gh(a.trim(),t,n);e===`metadata`&&typeof i==`object`&&i&&!Array.isArray(i)?Object.assign(r,i):r[e]=i}catch(t){let r=t instanceof Error?t.message:String(t),i=n==null?``:` in file "${n}"`;throw Error(`Cannot statically evaluate export "${e}"${i}: ${r}`)}s=o.exec(i)}return r}function Wh(e,t){let n=0,r=null,i=!1,a=t;for(let o=t;o<e.length;o++){let t=e[o];if(i){i=!1;continue}if(t===`\\`){i=!0;continue}if(r!=null){t===r&&(r=null);continue}if(t===`"`||t===`'`||t==="`"){r=t;continue}if(t===`{`||t===`[`){n++;continue}if(t===`}`||t===`]`){n--;continue}if(n===0){if(t===`;`||t===`
|
|
94
|
-
`)
|
|
95
|
-
`).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function qh(e,t,n){if(t==null){let t=n==null?``:` in file "${n}"`;throw Error(`Variable reference "${e}" cannot be resolved without scope${t}`)}let r=e.split(`.`),i=r[0];if(i==null||!(i in t)){let r=n==null?``:` in file "${n}"`,a=Object.keys(t).join(`, `);throw Error(`Undefined namespace "${i}" in expression "${e}"${r}. Available: ${a}`)}let a=t[i];for(let t=1;t<r.length;t++){let i=r[t];if(i==null)continue;if(a==null){let t=n==null?``:` in file "${n}"`;throw Error(`Cannot read property "${i}" of null/undefined in "${e}"${t}`)}if(typeof a!=`object`){let t=n==null?``:` in file "${n}"`;throw Error(`Cannot read property "${i}" of ${typeof a} in "${e}"${t}`)}let o=a;if(!(i in o)){let t=n==null?``:` in file "${n}"`,r=Object.keys(o).join(`, `);throw Error(`Undefined property "${i}" in "${e}"${t}. Available: ${r}`)}a=o[i]}if(typeof a==`string`||typeof a==`number`||typeof a==`boolean`||a===null||Array.isArray(a)||typeof a==`object`)return a;let o=n==null?``:` in file "${n}"`;throw Error(`Variable "${e}" resolved to unsupported type: ${typeof a}${o}`)}function Jh(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=Xh(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return Zh(r).map(e=>Gh(e.trim(),t,n))}function Yh(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=Xh(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=Qh(r);for(let e of a){let r=$h(e);if(r===-1)continue;let a=e.slice(0,r).trim(),o=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)||a.startsWith(`'`)&&a.endsWith(`'`))&&(a=a.slice(1,-1)),i[a]=Gh(o,t,n)}return i}function Xh(e){let t=``,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){t+=a,r=!1;continue}if(a===`\\`){t+=a,r=!0;continue}if(n!=null){a===n?(t+=`"`,n=null):a===`"`&&n===`'`?t+=`\\"`:t+=a;continue}if(a===`"`||a===`'`){t+=`"`,n=a;continue}if(a===`:`&&i>0){let e=t.length-1;for(;e>=0&&/\s/.test(t.charAt(e));)e--;let n=e+1;for(;e>=0&&/[\w$]/.test(t.charAt(e));)e--;if(e++,e>0&&t.charAt(e-1)!==`"`){let r=t.slice(e,n);r.length>0&&/^[\w$]+$/.test(r)&&(t=`${t.slice(0,e)}"${r}"`)}}t+=a}return t}function Zh(e){let t=[],n=``,r=0,i=null,a=!1;for(let o of e){if(a){n+=o,a=!1;continue}if(o===`\\`){n+=o,a=!0;continue}if(i!=null){n+=o,o===i&&(i=null);continue}if(o===`"`||o===`'`||o==="`"){n+=o,i=o;continue}if(o===`[`||o===`{`){r++,n+=o;continue}if(o===`]`||o===`}`){r--,n+=o;continue}if(o===`,`&&r===0){n.trim()!==``&&t.push(n.trim()),n=``;continue}n+=o}return n.trim()!==``&&t.push(n.trim()),t}function Qh(e){return Zh(e)}function $h(e){let t=null,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){n=!1;continue}if(i===`\\`){n=!0;continue}if(t!=null){i===t&&(t=null);continue}if(i===`"`||i===`'`||i==="`"){t=i;continue}if(i===`:`)return r}return-1}function eg(e,t){let n=e.attributes.find(e=>e.type===`mdxJsxAttribute`&&e.name===`when`);if(n?.type!==`mdxJsxAttribute`)return!0;if(typeof n.value==`string`)return n.value===`true`;if(n.value!=null&&typeof n.value==`object`&&n.value.type===`mdxJsxAttributeValueExpression`)try{let e=$m(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function tg(e,t,n){return!eg(e,t)||e.children.length===0?[]:n(e.children,t)}async function ng(e,t){if(!eg(e,t)||e.children.length===0)return[];let n=rg(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function rg(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=$m(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=rg(r.children,t));return n}function ig(){Xm(`Md`,tg),Xm(`Md.Line`,ng)}ig();function ag(e,t){let n={};if(e!=null&&(n.os={...e.os},n.env={...e.env},n.profile={...e.profile},n.tool={...e.tool}),t!=null)for(let[e,r]of Object.entries(t)){let t=n[e];n[e]=typeof r==`object`&&r&&!Array.isArray(r)&&typeof t==`object`&&t&&!Array.isArray(t)?{...t,...r}:r}return n}async function og(e,t){let n=Gf(e),r=ag(t?.globalScope,t?.scope),i=Zm(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=f.parse(e.value)}catch{}a=Hh(n.children.filter(e=>e.type===`mdxjsEsm`),{...i!=null&&{yamlFrontMatter:i},scope:r,...t?.basePath!=null&&{filePath:t.basePath}}),n.children=n.children.filter(e=>e.type!==`yaml`&&e.type!==`mdxjsEsm`)}let o=await Ih(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=Ff().use(Lt,[`yaml`]).use(Es).use(Vh,{bullet:`-`,fence:"`",fences:!0,emphasis:`*`,strong:`*`,rule:`-`,handlers:{text(e){return e.value}}}).stringify(o).trim();return t?.extractMetadata===!0&&a!=null?{content:s,metadata:a}:s}let sg=null;try{let t=e(import.meta.url),{platform:n,arch:r}=o,i={"win32-x64":[`napi-md-compiler.win32-x64-msvc`,`win32-x64-msvc`],"linux-x64":[`napi-md-compiler.linux-x64-gnu`,`linux-x64-gnu`],"linux-arm64":[`napi-md-compiler.linux-arm64-gnu`,`linux-arm64-gnu`],"darwin-arm64":[`napi-md-compiler.darwin-arm64`,`darwin-arm64`],"darwin-x64":[`napi-md-compiler.darwin-x64`,`darwin-x64`]}[`${n}-${r}`];if(i!=null){let[e,n]=i;try{sg=t(`./${e}.node`)}catch{try{sg=t(`@truenine/memory-sync-cli-${n}`).mdCompiler}catch{}}}}catch{}async function cg(e,t){let n=t?.extractMetadata===!0?{...t,extractMetadata:!0}:null,r=lg(e,t);if(r!=null){if(n!=null){let{metadata:t}=r;return t==null?og(e,n):{content:r.content,metadata:t}}return r.content}return n==null?t==null?og(e):og(e,{...t,extractMetadata:!1}):og(e,n)}function lg(e,t){if(sg==null)return null;try{let n=sg.compileMdxToMd(e,ug(t)),r=JSON.parse(n);return t?.extractMetadata===!0&&r.metadata==null?null:r}catch{return null}}function ug(e){if(e==null)return null;let t={...e,...e.globalScope==null?{}:{globalScope:{os:e.globalScope.os,env:e.globalScope.env,profile:e.globalScope.profile,tool:e.globalScope.tool}}};return JSON.stringify(t)}function dg(e,t){return e==null&&t==null?[]:[...new Set([...e??[],...t??[]])]}function fg(e,t){return e==null||t.length===0?!0:typeof e==`string`?t.includes(e):e.some(e=>t.includes(e))}function pg(e,t){if(e==null&&t==null)return{};let n={};for(let[t,r]of Object.entries(e??{}))n[t]=[...r];for(let[e,r]of Object.entries(t??{}))n[e]=Object.hasOwn(n,e)?[...new Set([...n[e],...r])]:[...r];return n}function mg(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.matchesSeries==`function`&&typeof t.resolveEffectiveIncludeSeries==`function`&&typeof t.resolveSubSeries==`function`}function hg(){let t={"win32-x64":`win32-x64-msvc`,"linux-x64":`linux-x64-gnu`,"linux-arm64":`linux-arm64-gnu`,"darwin-arm64":`darwin-arm64`,"darwin-x64":`darwin-x64`}[`${o.platform}-${o.arch}`];if(t==null)return;let n=`@truenine/memory-sync-cli-${t}`,r=`napi-memory-sync-cli.${t}.node`;try{let t=e(import.meta.url),i=[n,`${n}/${r}`,`./${r}`];for(let e of i)try{let n=t(e),r=[n,n?.default,n?.config];for(let e of r)if(mg(e))return e}catch{}}catch{}}const{resolveEffectiveIncludeSeries:gg,matchesSeries:_g,resolveSubSeries:vg}=hg()??{resolveEffectiveIncludeSeries:dg,matchesSeries:fg,resolveSubSeries:pg};function yg(e,t,n){let r=gg(t?.includeSeries,t?.[n]?.includeSeries);return e.filter(e=>_g(e.seriName,r))}function bg(e){let t=e.replaceAll(/\.\/+/g,``);return t=t.replaceAll(/\/+$/g,``),t}function xg(e,t){return t.startsWith(`**/`)?`${e}/${t}`:t.startsWith(`*`)?`${e}/**/${t}`:`${e}/${t}`}function Sg(e,t){for(let n of t){let t=n.replaceAll(/\/+$/g,``),r=[{prefix:t,pattern:`${t}/`},{prefix:t,pattern:`${t}\\`}];for(let{prefix:t,pattern:n}of r)if(e.startsWith(n))return{prefix:t,baseGlob:e.slice(n.length)};if(e===t)return{prefix:t,baseGlob:`**/*`}}return{prefix:null,baseGlob:e}}function Cg(e,t){let n=vg(t?.subSeries,t?.rules?.subSeries);if(Object.keys(n).length===0)return e;let r={};for(let[e,t]of Object.entries(n)){let n=bg(e);r[n]=t}let i=Object.keys(r);return e.map(e=>{if(e.seriName==null)return e;let t=[];for(let[n,i]of Object.entries(r))(Array.isArray(e.seriName)?e.seriName.some(e=>i.includes(e)):i.includes(e.seriName))&&t.push(n);if(t.length===0)return e;let n=[];for(let r of e.globs){let{prefix:e,baseGlob:a}=Sg(r,i);e!=null&&n.push(r);for(let r of t){if(r===e)continue;let t=xg(r,a);n.includes(t)||n.push(t)}}return{...e,globs:n}})}function wg(e){let r=n.join(e,`.git`);if(!t.existsSync(r))return null;let i=t.lstatSync(r);if(i.isDirectory())return n.join(r,`info`);if(i.isFile())try{let i=t.readFileSync(r,`utf8`).trim(),a=/^gitdir: (.+)$/.exec(i);if(a?.[1]!=null){let t=n.resolve(e,a[1]);return n.join(t,`info`)}}catch{}return null}function Tg(e,r=5){let i=[],a=new Set([`node_modules`,`.turbo`,`dist`,`build`,`out`,`.cache`]);function o(s,c){if(c>r)return;let l;try{let e=t.readdirSync(s,{withFileTypes:!0});if(!Array.isArray(e))return;l=e}catch{return}l.some(e=>e.name===`.git`)&&s!==e&&i.push(s);for(let e of l)e.isDirectory()&&(e.name===`.git`||a.has(e.name)||o(n.join(s,e.name),c+1))}return o(e,0),i}function Eg(e){let r=n.join(e,`modules`);if(!t.existsSync(r))return[];let i=[];function a(e){let r;try{let n=t.readdirSync(e,{withFileTypes:!0});if(!Array.isArray(n))return;r=n}catch{return}if(r.some(e=>e.name===`info`&&e.isDirectory())&&i.push(n.join(e,`info`)),r.find(e=>e.name===`modules`&&e.isDirectory())==null)return;let o;try{let r=t.readdirSync(n.join(e,`modules`),{withFileTypes:!0});if(!Array.isArray(r))return;o=r}catch{return}for(let t of o)t.isDirectory()&&a(n.join(e,`modules`,t.name))}let o;try{let e=t.readdirSync(r,{withFileTypes:!0});if(!Array.isArray(e))return i;o=e}catch{return i}for(let e of o)e.isDirectory()&&a(n.join(r,e.name));return i}const Dg={default:{websearch:`web_search`,webfetch:`web_fetch`,readFile:`read_file`,writeFile:`write_file`,executeCommand:`execute_command`,todolistWrite:`todolist_write`,grep:`grep`,listDirectory:`list_directory`},claudeCode:{readFile:`Read`,writeFile:`Write`,executeCommand:`Execute`,todolistWrite:`TodoWrite`,listDirectory:`List`},kiro:{websearch:`remote_web_search`,webfetch:`webFetch`,readFile:`readFile`,writeFile:`fsWrite`,executeCommand:`executeBash`,todolistWrite:`todolistWrite`,grep:`grepSearch`,listDirectory:`listDir`}};let Og=function(e){return e.Bash=`bash`,e.Zsh=`zsh`,e.Fish=`fish`,e.Sh=`sh`,e.PowerShell=`powershell`,e.Pwsh=`pwsh`,e.Cmd=`cmd`,e.Unknown=`unknown`,e}({}),kg=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var Ag=class{userConfig;toolPreset;constructor(e={}){this.userConfig=e.userConfig,this.toolPreset=e.toolPreset??`default`}collect(){return{os:this.collectOsInfo(),env:this.collectEnvContext(),profile:this.collectProfile(),tool:this.collectToolReferences(),Md:this.createMdComponent()}}collectOsInfo(){let e=s.platform();return{platform:e,arch:s.arch(),hostname:s.hostname(),homedir:s.homedir(),tmpdir:s.tmpdir(),type:s.type(),release:s.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return kg.Win;case`darwin`:return kg.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return kg.Linux;default:return kg.Unknown}}detectShellKind(){let e=(o.env.SHELL??o.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?Og.Bash:e.includes(`zsh`)?Og.Zsh:e.includes(`fish`)?Og.Fish:e.includes(`pwsh`)?Og.Pwsh:e.includes(`powershell`)?Og.PowerShell:e.includes(`cmd`)?Og.Cmd:e.endsWith(`/sh`)?Og.Sh:Og.Unknown}collectEnvContext(){return{...o.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...Dg.default};return this.toolPreset===`claudeCode`?{...e,...Dg.claudeCode}:this.toolPreset===`kiro`?{...e,...Dg.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let jg=function(e){return e[e.SystemDefault=0]=`SystemDefault`,e[e.UserConfig=10]=`UserConfig`,e[e.PluginRegistered=20]=`PluginRegistered`,e[e.CompileTime=30]=`CompileTime`,e}({});var Mg=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=jg.PluginRegistered){this.registrations.push({namespace:e,values:t,priority:n})}getRegistrations(){return this.registrations}merge(e){let t={};this.globalScope!=null&&(t.os={...this.globalScope.os},t.env={...this.globalScope.env},t.profile={...this.globalScope.profile},t.tool={...this.globalScope.tool});let n=[...this.registrations].sort((e,t)=>e.priority-t.priority);for(let e of n)t[e.namespace]=this.deepMerge(t[e.namespace],e.values);if(e!=null)for(let[n,r]of Object.entries(e))t[n]=typeof r==`object`&&r&&!Array.isArray(r)?this.deepMerge(t[n],r):r;return t}deepMerge(e,t){if(e==null)return{...t};let n={...e};for(let[e,r]of Object.entries(t))n[e]=typeof r==`object`&&r&&!Array.isArray(r)&&typeof n[e]==`object`&&n[e]!==null&&!Array.isArray(n[e])?this.deepMerge(n[e],r):r;return n}resolve(e){let t=this.merge();return e.replaceAll(/\$\{([^}]+)\}/g,(e,n)=>{let r=n.split(`.`),i=t;for(let e of r)i=i?.[e];return i==null?`\${${n}}`:String(i)})}clear(){this.registrations.length=0,this.globalScope=null}};const Ng=[`project`,`workspace`,`global`];function Pg(e){if(e==null)return[];if(typeof e==`string`)return[e];let t=[];for(let n of e)t.includes(n)||t.push(n);return t}function Fg(e,t){let n=new Map;for(let[e,r]of t.entries())n.set(r,e);return[...e].sort((e,t)=>(n.get(e)??2**53-1)-(n.get(t)??2**53-1))}function Ig(e){let{requestedScopes:t,defaultScopes:n,supportedScopes:r,singleScope:i,availableScopes:a,priority:o=Ng}=e,s=Pg(t),c=Pg(n),l=new Set(Pg(r)),u=(s.length>0?s:c).filter(e=>l.has(e));if(u.length===0)return[];let d=Fg(u,o);if(!i)return d;if(a!=null&&a.length>0){let e=new Set(a),t=d.find(t=>e.has(t));return t==null?[]:[t]}let[f]=d;return f==null?[]:[f]}const Lg=m.object({src:m.string(),dist:m.string()}),Rg=m.object({dir:m.string().default(`aindex`),skills:Lg,commands:Lg,subAgents:Lg,rules:Lg,globalPrompt:Lg,workspacePrompt:Lg,app:Lg,ext:Lg,arch:Lg}),zg=m.object({includeSeriesPrefix:m.boolean().optional(),seriesSeparator:m.string().optional()}),Bg=m.object({includeSeriesPrefix:m.boolean().optional(),pluginOverrides:m.record(m.string(),zg).optional()}),Vg=m.enum([`project`,`workspace`,`global`]),Hg=m.union([Vg,m.array(Vg).min(1)]),Ug=m.object({prompt:Hg.optional(),rules:Hg.optional(),commands:Hg.optional(),subagents:Hg.optional(),skills:Hg.optional(),mcp:Hg.optional()}),Wg=m.object({plugins:m.record(m.string(),Ug).optional()}),Gg=m.enum([`direct`,`recursive`]),Kg=m.enum([`path`,`glob`]),qg=m.object({path:m.string(),protectionMode:Gg,matcher:Kg.optional(),reason:m.string().optional()}),Jg=m.object({rules:m.array(qg).optional()}),Yg=m.object({name:m.string().optional(),username:m.string().optional(),gender:m.string().optional(),birthday:m.string().optional()}).catchall(m.unknown()),Xg=m.object({version:m.string().optional(),workspaceDir:m.string().optional(),aindex:Rg.optional(),logLevel:m.enum([`trace`,`debug`,`info`,`warn`,`error`]).optional(),commandSeriesOptions:Bg.optional(),outputScopes:Wg.optional(),cleanupProtection:Jg.optional(),profile:Yg.optional()}),Zg=m.object({names:m.array(m.string()).optional()}),Qg=m.object({includeSeries:m.array(m.string()).optional(),subSeries:m.record(m.string(),m.array(m.string())).optional()});m.object({mcp:Zg.optional(),includeSeries:m.array(m.string()).optional(),subSeries:m.record(m.string(),m.array(m.string())).optional(),rules:Qg.optional(),skills:Qg.optional(),subAgents:Qg.optional(),commands:Qg.optional()}),m.object({configFileName:m.string().optional(),searchPaths:m.array(m.string()).optional(),searchCwd:m.boolean().optional(),searchGlobal:m.boolean().optional()});function $g(e,t){let n=t==null?``:` in ${t}`,r=[],i=[];return(!(`name`in e)||e.name==null)&&r.push(`Missing required field "name"${n}`),!(`description`in e)||e.description==null?r.push(`Missing required field "description"${n}`):(typeof e.description!=`string`||e.description.trim().length===0)&&r.push(`Required field "description" cannot be empty${n}`),e.enabled??i.push(`Using default value for optional field "enabled": true${n}`),e.keywords??i.push(`Using default value for optional field "keywords": []${n}`),{valid:r.length===0,errors:r,warnings:i}}function e_(e){return{workspace:{directory:e.workspace.directory,projects:[...e.workspace.projects]},...e.skills!=null&&{skills:[...e.skills]},...e.commands!=null&&{commands:[...e.commands]},...e.subAgents!=null&&{subAgents:[...e.subAgents]},...e.rules!=null&&{rules:[...e.rules]},...e.readmePrompts!=null&&{readmePrompts:[...e.readmePrompts]},...e.globalMemory!=null&&{globalMemory:e.globalMemory},...e.vscodeConfigFiles!=null&&{vscodeConfigFiles:[...e.vscodeConfigFiles]},...e.jetbrainsConfigFiles!=null&&{jetbrainsConfigFiles:[...e.jetbrainsConfigFiles]},...e.editorConfigFiles!=null&&{editorConfigFiles:[...e.editorConfigFiles]},...e.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles]},...e.globalGitIgnore!=null&&{globalGitIgnore:e.globalGitIgnore},...e.shadowGitExclude!=null&&{shadowGitExclude:e.shadowGitExclude},...e.aindexDir!=null&&{aindexDir:e.aindexDir}}}const t_={Readme:{src:`rdm.mdx`,out:`README.md`},CodeOfConduct:{src:`coc.mdx`,out:`CODE_OF_CONDUCT.md`},Security:{src:`security.mdx`,out:`SECURITY.md`}},n_=[`prompt`,`rules`,`commands`,`subagents`,`skills`,`mcp`];function r_(e){return p.isBuffer(e)}function i_(e){if(typeof e==`string`)return[e];let t=[];for(let n of e)t.includes(n)||t.push(n);return t}function a_(e,t){return t?.outputScopes?.plugins?.[e]}function o_(e){for(let t of n_){let n=e.outputCapabilities[t];if(n!=null&&n.scopes.length===0)throw Error(`Plugin ${e.name} declares empty scopes for topic "${t}"`)}}function s_(e,t){let n=a_(e.name,t);if(n!=null)for(let t of n_){let r=n[t];if(r==null)continue;let i=e.outputCapabilities[t];if(i==null)throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} is set, but plugin ${e.name} does not support topic "${t}".`);let a=i_(r);if(i.singleScope&&a.length>1){let n=a.join(`, `);throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} is single-scope and cannot request multiple scopes [${n}].`)}let o=new Set(i.scopes),s=a.filter(e=>!o.has(e));if(s.length>0){let n=i.scopes.join(`, `),r=s.join(`, `);throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} requests unsupported scopes [${r}]. Allowed scopes: [${n}].`)}}}function c_(e,t){for(let n of e)o_(n),s_(n,t)}async function l_(e,t){let n=new Map;c_(e,t.pluginOptions);for(let r of e){let e=await r.declareOutputFiles(t),i=[];for(let n of e){if(t.dryRun===!0){i.push({path:n.path,success:!0,skipped:!1});continue}try{let e=t.path.dirname(n.path);if(t.fs.mkdirSync(e,{recursive:!0}),n.ifExists===`skip`&&t.fs.existsSync(n.path)){i.push({path:n.path,success:!0,skipped:!0});continue}if(n.ifExists===`error`&&t.fs.existsSync(n.path))throw Error(`Refusing to overwrite existing file: ${n.path}`);if(n.symlinkTarget!=null){t.fs.existsSync(n.path)&&t.fs.rmSync(n.path,{force:!0,recursive:!1}),t.fs.symlinkSync(n.symlinkTarget,n.path,`file`),i.push({path:n.path,success:!0});continue}let a=await r.convertContent(n,t);r_(a)?t.fs.writeFileSync(n.path,a):t.fs.writeFileSync(n.path,a,`utf8`),i.push({path:n.path,success:!0})}catch(e){i.push({path:n.path,success:!1,error:e})}}let a={files:i,dirs:[]};n.set(r.name,a)}return n}async function u_(e,t){let n=[],r=[],i=[],a=[],o=[],s=[];c_(e,t.pluginOptions);for(let n of e){let e=await n.declareOutputFiles({...t,dryRun:!0});for(let t of e)t.scope===`global`?s.push(t.path):t.scope===`workspace`?a.push(t.path):r.push(t.path)}return{projectDirs:n,projectFiles:r,workspaceDirs:i,workspaceFiles:a,globalDirs:o,globalFiles:s}}var d_=class extends Error{pluginName;missingDependency;constructor(e,t){super(`Plugin "${e}" depends on missing plugin "${t}"`),this.name=`MissingDependencyError`,this.pluginName=e,this.missingDependency=t}},f_=class extends Error{cyclePath;constructor(e){super(`Circular plugin dependency detected: ${e.join(` -> `)}`),this.name=`CircularDependencyError`,this.cyclePath=[...e]}},p_=class extends Am{declarativeOutput=!0;outputCapabilities;globalConfigDir;outputFileName;indexignore;commandsConfig;subAgentsConfig;commandOutputEnabled;subAgentOutputEnabled;skillsConfig;skillOutputEnabled;toolPreset;rulesConfig;ruleOutputEnabled;cleanupConfig;registryWriterCache=new Map;constructor(e,t){super(e,fp.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``,this.indexignore=t?.indexignore;let n=t?.commands?.transformFrontMatter;this.commandOutputEnabled=t?.commands!=null,this.commandsConfig={subDir:t?.commands?.subDir??`commands`,sourceScopes:t?.commands?.sourceScopes??[`project`,`workspace`,`global`],...n!=null&&{transformFrontMatter:n}},this.subAgentOutputEnabled=t?.subagents!=null,this.subAgentsConfig={subDir:t?.subagents?.subDir??`agents`,sourceScopes:t?.subagents?.sourceScopes??[`project`,`workspace`,`global`],includePrefix:t?.subagents?.includePrefix??!0,linkSymbol:t?.subagents?.linkSymbol??`-`,ext:t?.subagents?.ext??`.md`,...t?.subagents?.transformFrontMatter!=null&&{transformFrontMatter:t.subagents.transformFrontMatter}},this.skillOutputEnabled=t?.skills!=null,this.skillsConfig={subDir:t?.skills?.subDir??`skills`,sourceScopes:t?.skills?.sourceScopes??[`project`,`workspace`,`global`]},this.toolPreset=t?.toolPreset,this.ruleOutputEnabled=t?.rules!=null,this.rulesConfig={...t?.rules,sourceScopes:t?.rules?.sourceScopes??[`project`,`workspace`,`global`]},this.cleanupConfig=t?.cleanup??{},this.outputCapabilities=t?.capabilities==null?this.buildInferredCapabilities():this.normalizeCapabilities(t.capabilities)}buildInferredCapabilities(){let e={};return this.outputFileName.length>0&&(e.prompt={scopes:[`project`,`global`],singleScope:!1}),this.ruleOutputEnabled&&(e.rules={scopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],singleScope:!1}),this.commandOutputEnabled&&(e.commands={scopes:this.commandsConfig.sourceScopes,singleScope:!0}),this.subAgentOutputEnabled&&(e.subagents={scopes:this.subAgentsConfig.sourceScopes,singleScope:!0}),this.skillOutputEnabled&&(e.skills={scopes:this.skillsConfig.sourceScopes,singleScope:!0}),e}normalizeCapabilities(e){let t={};for(let n of n_){let r=e[n];if(r==null)continue;let i=this.normalizeCapability(r);i!=null&&(t[n]=i)}return t}normalizeCapability(e){let t=[];for(let n of e.scopes)t.includes(n)||t.push(n);if(t.length!==0)return{scopes:t,singleScope:e.singleScope}}resolvePromptSourceProjectConfig(e){let{projects:t}=e.collectedOutputContext.workspace;return t.find(e=>e.isPromptSourceProject===!0)?.projectConfig??t[0]?.projectConfig}isRelativePath(e){return e.pathKind===mp.Relative}toRelativePath(e){return e.path}resolveFullPath(e,t){let r=this.resolveDirectoryPath(e),i=t??this.outputFileName;return i?n.join(r,i):r}resolveDirectoryPath(e){return e.pathKind===mp.Absolute?e.path:`basePath`in e?n.resolve(e.basePath,e.path):n.resolve(o.cwd(),e.path)}getWorkspaceConfigDir(e){let t=this.resolveDirectoryPath(e.collectedOutputContext.workspace.directory);return n.join(t,this.globalConfigDir)}createRelativePath(e,t,r){return n.join(t,e)}createFileRelativePath(e,t){return n.join(e,t)}getGlobalConfigDir(){return n.join(this.getHomeDir(),this.globalConfigDir)}getXdgConfigHomeDir(){let e=o.env.XDG_CONFIG_HOME;return typeof e==`string`&&e.trim().length>0?e:n.join(this.getHomeDir(),`.config`)}getHomeDir(){return s.homedir()}joinPath(...e){return n.join(...e)}resolvePath(...e){return n.resolve(...e)}dirname(e){return n.dirname(e)}basename(e,t){return n.basename(e,t)}existsSync(e){return t.existsSync(e)}lstatSync(e){return t.lstatSync(e)}readdirSync(e,n){return n?.withFileTypes===!0?t.readdirSync(e,{withFileTypes:!0}):t.readdirSync(e)}getIgnoreOutputPath(){if(this.indexignore!=null)return this.indexignore}resolveCleanupScopeBasePaths(e,t){if(e===`global`)return[this.getHomeDir()];if(e===`workspace`)return[this.resolveDirectoryPath(t.collectedOutputContext.workspace.directory)];if(e===`xdgConfig`)return[this.getXdgConfigHomeDir()];let n=[];for(let e of t.collectedOutputContext.workspace.projects){let t=e.dirFromWorkspacePath;t!=null&&n.push(this.resolveDirectoryPath(t))}return n}resolveCleanupDeclaredPath(e,t){return n.isAbsolute(t)?n.resolve(t):t===`~`?this.getHomeDir():t.startsWith(`~/`)||t.startsWith(`~\\`)?n.resolve(this.getHomeDir(),t.slice(2)):n.resolve(e,t)}normalizeGlobPattern(e){return e.replaceAll(`\\`,`/`)}buildCleanupTargetsFromScopeConfig(e,t,r){if(e==null)return[];let i=[],a=[`project`,`workspace`,`global`,`xdgConfig`],o=(e,a,o)=>{if(o==null||o.length===0)return;let s=this.resolveCleanupScopeBasePaths(e,r);for(let r of o)for(let o of s){let s=n.isAbsolute(r)?n.resolve(r):this.resolveCleanupDeclaredPath(o,r);i.push({path:a===`glob`?this.normalizeGlobPattern(s):s,kind:a,scope:e,label:`${t}.${e}`})}};for(let t of a){let n=e[t];n!=null&&(o(t,`file`,n.files),o(t,`directory`,n.dirs),o(t,`glob`,n.globs))}return i}buildMarkdownContent(e,t){return Jf(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Jf(t,e):n!=null&&n.length>0?Xf(n,e):e}extractGlobalMemoryContent(e){return e.collectedOutputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
|
|
93
|
+
`))}function bm(){let t=import.meta.url,n=e(t),{local:r,suffix:i}=vm();try{return n(`./${r}.node`)}catch(e){try{let e=n(`@truenine/memory-sync-cli-${i}`).logger;if(_m(e))return e;throw Error(`Package "@truenine/memory-sync-cli-${i}" does not export a logger binding`)}catch(t){throw ym(e,t,i)}}}function xm(){if(hm!=null)return hm;if(gm!=null)throw gm;try{return hm=bm(),hm}catch(e){throw gm=e instanceof Error?e:Error(String(e)),gm}}function Sm(e){let t={name:e.name,message:e.message,stack:e.stack};for(let n of Object.getOwnPropertyNames(e))n===`name`||n===`message`||n===`stack`||(t[n]=e[n]);return t}function Cm(){let e=new WeakSet;return function(t,n){return n instanceof Error?Sm(n):typeof n==`bigint`?n.toString():typeof n==`function`?`[Function ${n.name||`anonymous`}]`:typeof n==`symbol`?n.toString():typeof n!=`object`||!n?n:e.has(n)?`[Circular]`:(e.add(n),n)}}function wm(e){return JSON.stringify(e,Cm())??`null`}function Tm(e,t){if(typeof e!=`string`)return{message:``,metaJson:wm(e)};let n=t.length===1&&typeof t[0]==`object`&&t[0]!==null?t[0]:t.length>0?{args:t}:void 0;return{message:e,metaJson:n==null?void 0:wm(n)}}function Em(e,t){return(n,...r)=>{let{message:i,metaJson:a}=Tm(n,r);e.log(t,i,a)}}function Dm(e){let t=mm.reduce((t,n)=>(t[n]=Em(e,n),t),{});return{error:t.error,warn:t.warn,info:t.info,debug:t.debug,trace:t.trace,fatal:t.fatal}}function Om(e){xm().setGlobalLogLevel(e)}function km(e,t){return Dm(xm().createLogger(e,t))}var Am=class{type;name;_log;get log(){return this._log??=km(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}};const jm={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Mm={AgentsOutput:`AgentsOutputPlugin`,GeminiCLIOutput:`GeminiCLIOutputPlugin`,CursorOutput:`CursorOutputPlugin`,WindsurfOutput:`WindsurfOutputPlugin`,ClaudeCodeCLIOutput:`ClaudeCodeCLIOutputPlugin`,KiroIDEOutput:`KiroCLIOutputPlugin`,OpencodeCLIOutput:`OpencodeCLIOutputPlugin`,OpenAICodexCLIOutput:`CodexCLIOutputPlugin`,DroidCLIOutput:`DroidCLIOutputPlugin`,WarpIDEOutput:`WarpIDEOutputPlugin`,TraeIDEOutput:`TraeIDEOutputPlugin`,TraeCNIDEOutput:`TraeCNIDEOutputPlugin`,QoderIDEOutput:`QoderIDEPluginOutputPlugin`,JetBrainsCodeStyleOutput:`JetBrainsIDECodeStyleConfigOutputPlugin`,JetBrainsAICodexOutput:`JetBrainsAIAssistantCodexOutputPlugin`,AgentSkillsCompactOutput:`GenericSkillsOutputPlugin`,GitExcludeOutput:`GitExcludeOutputPlugin`,ReadmeOutput:`ReadmeMdConfigFileOutputPlugin`,VSCodeOutput:`VisualStudioCodeIDEConfigOutputPlugin`,EditorConfigOutput:`EditorConfigOutputPlugin`,AntigravityOutput:`AntigravityOutputPlugin`},Nm={SKILL:`SKILL.md`,CURSOR_GLOBAL_RULE:`global.mdc`,CURSOR_PROJECT_RULE:`always.md`,MCP_CONFIG:`mcp.json`,CLAUDE_MEMORY:`CLAUDE.md`,WINDSURF_GLOBAL_RULE:`global_rules.md`},Pm={RULES:`rules`,COMMANDS:`commands`,SKILLS:`skills`,AGENTS:`agents`,CURSOR_SKILLS:`skills-cursor`},Fm={MD:`.md`,MDC:`.mdc`,MDX:`.mdx`,JSON:`.json`},Im=[{PRIMARY:`.src.mdx`}.PRIMARY],Lm={zh:Im,en:Fm.MDX};function Rm(e){return Im.some(t=>e.endsWith(t))}const zm={CURSOR:`.cursor`,CLAUDE:`.claude`,WINDSURF:`.codeium/windsurf`,WINDSURF_RULES:`.windsurf`},Bm={CURSOR:`.cursorignore`,WINDSURF:`.codeiumignore`},Vm={CURSOR:new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`])};var Hm=class extends Am{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,fp.Input,t)}registerEffect(e,t,n=0){this.inputEffects.push({name:e,handler:t,priority:n}),this.inputEffects.sort((e,t)=>(e.priority??0)-(t.priority??0))}async executeEffects(e,t=!1){let n=[];if(this.inputEffects.length===0)return n;let{workspaceDir:r,aindexDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:l,userConfigOptions:e.userConfigOptions,workspaceDir:r,aindexDir:i,dryRun:t};for(let e of this.inputEffects){if(t){this.log.trace({action:`dryRun`,type:`inputEffect`,name:e.name}),n.push({success:!0,description:`Would execute input effect: ${e.name}`});continue}try{let t=await e.handler(a);if(t.success)this.log.trace({action:`inputEffect`,name:e.name,status:`success`,description:t.description}),t.modifiedFiles!=null&&t.modifiedFiles.length>0&&this.log.debug({action:`inputEffect`,name:e.name,modifiedFiles:t.modifiedFiles}),t.deletedFiles!=null&&t.deletedFiles.length>0&&this.log.debug({action:`inputEffect`,name:e.name,deletedFiles:t.deletedFiles});else throw t.error??Error(`Input effect failed: ${e.name}`);n.push(t)}catch(t){let r=t instanceof Error?t:Error(String(t));throw this.logInputEffectFailure(e.name,r),n.push({success:!1,error:r,description:`Input effect failed: ${e.name}`}),r}}return n}logInputEffectFailure(e,t){if(t instanceof Np){fm(this.log,t.operation,t.violations);return}this.log.error({action:`inputEffect`,name:e,status:`failed`,error:t.message})}hasEffects(){return this.inputEffects.length>0}getEffectCount(){return this.inputEffects.length}registerScope(e,t){this.registeredScopes.push({namespace:e,values:t}),this.log.debug({action:`registerScope`,namespace:e,keys:Object.keys(t)})}getRegisteredScopes(){return this.registeredScopes}clearRegisteredScopes(){this.registeredScopes.length=0,this.log.debug({action:`clearRegisteredScopes`})}resolveBasePaths(e){let t=e.workspaceDir,r=this.resolvePath(t,``),i=e.aindex?.dir??`aindex`;return{workspaceDir:r,aindexDir:n.join(r,i)}}resolvePath(e,t){let r=e;return r.startsWith(jm.USER_HOME)&&(r=r.replace(jm.USER_HOME,s.homedir())),r.includes(jm.WORKSPACE)&&(r=r.replace(jm.WORKSPACE,t)),n.normalize(r)}resolveAindexPath(e,t){return n.join(t,e)}readAndParseMarkdown(e,t){return Qf(t.readFileSync(e,`utf8`))}};function Um(e={}){let{filePath:t,position:n,sourceText:r,expression:i,exportName:a,nodeType:o,phase:s,hint:c,cause:l}=e,u=n?.start.line,d=n?.start.column,f=n?.end?.line,p=n?.end?.column,m=n?.start.offset,h=n?.end?.offset,g=u!=null&&r!=null?Wm(r,u):void 0,_=Gm(r,m,h,g),v=u!=null&&d!=null&&g!=null?Km(u,d,p,g):void 0,y={};return t!=null&&t.length>0&&Object.assign(y,{filePath:t}),u!=null&&Object.assign(y,{line:u}),d!=null&&Object.assign(y,{column:d}),f!=null&&Object.assign(y,{endLine:f}),p!=null&&Object.assign(y,{endColumn:p}),m!=null&&Object.assign(y,{offset:m}),h!=null&&Object.assign(y,{endOffset:h}),_!=null&&_.length>0&&Object.assign(y,{snippet:_}),g!=null&&g.length>0&&Object.assign(y,{sourceLine:g}),v!=null&&v.length>0&&Object.assign(y,{codeFrame:v}),i!=null&&i.length>0&&Object.assign(y,{expression:i}),a!=null&&a.length>0&&Object.assign(y,{exportName:a}),o!=null&&o.length>0&&Object.assign(y,{nodeType:o}),s!=null&&s.length>0&&Object.assign(y,{phase:s}),c!=null&&c.length>0&&Object.assign(y,{hint:c}),l!=null&&l.length>0&&Object.assign(y,{cause:l}),y}function Wm(e,t){return e.split(/\r?\n/u)[t-1]}function Gm(e,t,n,r){if(e!=null&&t!=null){let r=n!=null&&n>=t?n:t+1,i=e.slice(t,r).trim();if(i.length>0)return i.length>240?`${i.slice(0,240)}...`:i}let i=r?.trim();if(i!=null&&i.length>0)return i}function Km(e,t,n,r){let i=`${e} | `,a=` `.repeat(i.length+Math.max(0,t-1)),o=Math.max(1,(n??t+1)-t);return`${i}${r}\n${a}${`^`.repeat(o)}`}function qm(e){if(!(e.line==null||e.column==null))return e.endLine!=null&&e.endColumn!=null?`${e.line}:${e.column}-${e.endLine}:${e.endColumn}`:`${e.line}:${e.column}`}function Jm(e,t){let n=[e];t.phase!=null&&n.push(`phase: ${t.phase}`),t.nodeType!=null&&n.push(`node: ${t.nodeType}`),t.filePath!=null&&n.push(`file: ${t.filePath}`);let r=qm(t);return r!=null&&n.push(`location: ${r}`),t.expression!=null&&n.push(`expression: ${t.expression}`),t.exportName!=null&&n.push(`export: ${t.exportName}`),t.sourceLine!=null&&n.push(`source line: ${t.sourceLine.trimEnd()}`),t.codeFrame!=null&&(n.push(`code frame:`),n.push(t.codeFrame)),t.hint!=null&&n.push(`hint: ${t.hint}`),t.cause!=null&&n.push(`cause: ${t.cause}`),n.join(`
|
|
94
|
+
`)}function Ym(e,t={}){return e instanceof Xm||e instanceof Error?e.message:Jm(t.summary??`Compiler diagnostic`,e)}var Xm=class extends Error{diagnostic;filePath;line;column;endLine;endColumn;snippet;sourceLine;codeFrame;phase;nodeType;constructor(e,t,n){super(Jm(t,n)),this.name=e,this.diagnostic=n,n.filePath!=null&&(this.filePath=n.filePath),n.line!=null&&(this.line=n.line),n.column!=null&&(this.column=n.column),n.endLine!=null&&(this.endLine=n.endLine),n.endColumn!=null&&(this.endColumn=n.endColumn),n.snippet!=null&&(this.snippet=n.snippet),n.sourceLine!=null&&(this.sourceLine=n.sourceLine),n.codeFrame!=null&&(this.codeFrame=n.codeFrame),n.phase!=null&&(this.phase=n.phase),n.nodeType!=null&&(this.nodeType=n.nodeType)}};function Zm(e){if(e===`mdxTextExpression`||e===`mdxFlowExpression`)return`Literal braces in MDX text are parsed as expressions. Escape the braces or wrap the placeholder in code if you meant plain text.`;if(e===`mdxJsxAttributeValueExpression`)return`JSX attribute expressions must reference values that exist in scope.`}var Qm=class extends Xm{expression;constructor(e,t){super(`ScopeError`,e,t),t.expression!=null&&(this.expression=t.expression)}},$m=class extends Qm{variableName;constructor(e,t,n={}){let r=Um({...n,expression:t,phase:n.phase??`expression-evaluation`,hint:n.hint??Zm(n.nodeType)}),i=`Undefined variable "${e}" in expression "${t??``}"`;super(i,r),this.name=`UndefinedVariableError`,this.variableName=e}},eh=class extends Qm{namespace;constructor(e,t,n={}){let r=Um({...n,expression:t,phase:n.phase??`expression-evaluation`,hint:n.hint??Zm(n.nodeType)}),i=`Undefined namespace "${e}" in expression "${t??``}"`;super(i,r),this.name=`UndefinedNamespaceError`,this.namespace=e}},th=class extends Xm{exportName;constructor(e,t,n={}){let r=Um({...n,exportName:t,phase:n.phase??`export-parsing`,hint:n.hint??`Export metadata must be statically evaluable. Use plain literals, arrays, objects, or scope-backed references only.`});super(`ExportParseError`,e,r),t!=null&&(this.exportName=t)}},nh=Object.defineProperty,rh=(e,t)=>{let n={};for(var r in e)nh(n,r,{get:e[r],enumerable:!0});return t||nh(n,Symbol.toStringTag,{value:`Module`}),n};const ih=new Map;function ah(e,t){ih.set(e,t)}function oh(){return new Map(ih)}function sh(e){return ih.has(e)}function ch(e,t,n){let r=e.trim(),i=lh(n,e);return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?uh(r,t,i):dh(r,t,i)}function lh(e,t){return{expression:t,...e?.filePath!=null&&{filePath:e.filePath},...e?.sourceText!=null&&{sourceText:e.sourceText},...e?.position!=null&&{position:e.position},...e?.nodeType!=null&&{nodeType:e.nodeType}}}function uh(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new eh(i??``,e,n);let a=t[i];for(let t=1;t<r.length;t++){let i=r[t];if(i==null)continue;if(a==null)throw new $m(i,e,n);if(typeof a!=`object`)throw TypeError(`Cannot read property "${i}" of ${typeof a} in expression "${e}"`);let o=a;if(!(i in o))throw new $m(i,e,n);a=o[i]}return fh(a)}function dh(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return fh(Function(...r,`return (${e})`)(...i))}catch(t){let r=t instanceof Error?t.message:String(t);if(r.includes(`is not defined`)){let t=/(\w+) is not defined/.exec(r);if(t?.[1]!=null)throw new eh(t[1],e,{...n,cause:r})}throw Error([`Failed to evaluate expression: "${e}"`,...n?.filePath==null?[]:[`file: ${n.filePath}`],...n?.position?.start==null?[]:[`location: ${n.position.start.line}:${n.position.start.column}`],`Cause: ${r}`].join(`
|
|
95
|
+
`))}}function fh(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(typeof e==`object`)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}function ph(e,t){return e===null?!1:t.components.has(e)||sh(e)}async function mh(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function hh(e,t,n){let r=e.name;if(r==null||r===``)return[];let i=t.components.get(r);if(i==null)return[];if(t.processingStack.includes(r)){let e=[...t.processingStack,r].join(` → `);throw Error(`Circular dependency detected: ${e}`)}let a={scope:t.scope,components:t.components,processingStack:[...t.processingStack,r],...t.basePath==null?{}:{basePath:t.basePath}},o=await mh(n);try{return await i(e,a,o)}catch(e){let n=e instanceof Error?e.message:String(e),i=t.processingStack.join(` → `);throw Error(`Failed to process component "${r}"${i===``?``:` (called from: ${i})`}:\n${n}`,{cause:e})}}function gh(e,t,n){return{...e.filePath!=null&&{filePath:e.filePath},...e.sourceText!=null&&{sourceText:e.sourceText},...n?.position!=null&&{position:n.position},nodeType:t}}function _h(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return bh(e,t);case`a`:return xh(e,t);case`strong`:case`b`:return Sh(e,t);case`em`:case`i`:return Ch(e,t);case`img`:return wh(e,t);case`blockquote`:return Th(e,t);default:return null}}function vh(e,t,n){let r=e.attributes.find(e=>e.type===`mdxJsxAttribute`&&e.name===t);return r==null?null:typeof r.value==`string`?r.value:r.value!=null&&typeof r.value==`object`&&r.value.type===`mdxJsxAttributeValueExpression`?ch(r.value.value,n.scope,gh(n,`mdxJsxAttributeValueExpression`,r)):r.value===null?``:null}function yh(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=ch(r.value,t.scope,gh(t,`mdxTextExpression`,r)):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=yh(r,t));return n}function bh(e,t){let n=null;for(let t of e.children){if((t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)&&t.name?.toLowerCase()===`code`){n=t;break}if(t.type===`paragraph`&&`children`in t){let e=t.children;for(let t of e)if((t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)&&t.name?.toLowerCase()===`code`){n=t;break}if(n!=null)break}}if(n==null)return null;let r=vh(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=yh(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function xh(e,t){let n=vh(e,`href`,t);if(n==null||n===``)return null;let r=yh(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:vh(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function Sh(e,t){let n={type:`strong`,children:[{type:`text`,value:yh(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function Ch(e,t){let n={type:`emphasis`,children:[{type:`text`,value:yh(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function wh(e,t){let n=vh(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:vh(e,`alt`,t)??``,title:vh(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function Th(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:yh(e,t)}]}]}]}function Eh(e,t){return{...e.filePath!=null&&{filePath:e.filePath},...e.sourceText!=null&&{sourceText:e.sourceText},...t.position!=null&&{position:t.position},nodeType:t.type}}function Dh(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function Oh(e,t,n){let r=e.data?.estree;if(r==null||r.body.length===0)return[];let i=r.body[0];return i?.type===`ExpressionStatement`?kh(i.expression,t,n,e):[]}async function kh(e,t,n,r){return e.type===`JSXElement`?Fh(e,t,n,r):e.type===`JSXFragment`?Ih(e,t,n,r):e.type===`LogicalExpression`?Ah(e,t,n,r):e.type===`ConditionalExpression`?jh(e,t,n,r):e.type===`SequenceExpression`?Mh(e,t,n,r):e.type===`ArrayExpression`?Nh(e,t,n,r):Gh(e,t,r)}async function Ah(e,t,n,r){let i=await Ph(e.left,t,n,r);return e.operator===`&&`?Uh(i)?kh(e.right,t,n,r):[]:e.operator===`||`?Uh(i)?Hh(e.left)?kh(e.left,t,n,r):Wh(i):kh(e.right,t,n,r):e.operator===`??`?i==null?kh(e.right,t,n,r):Hh(e.left)?kh(e.left,t,n,r):Wh(i):[]}async function jh(e,t,n,r){return Uh(await Ph(e.test,t,n,r))?kh(e.consequent,t,n,r):kh(e.alternate,t,n,r)}async function Mh(e,t,n,r){let i=[];for(let a of e.expressions){let e=await kh(a,t,n,r);i.push(...e)}return i}async function Nh(e,t,n,r){let i=[];for(let a of e.elements)if(a!=null)if(a.type===`SpreadElement`){let e=await kh(a.argument,t,n,r);i.push(...e)}else{let e=await kh(a,t,n,r);i.push(...e)}return i}async function Ph(e,t,n,r){if(Hh(e))return!0;if(e.type===`Literal`)return e.value;if(e.type===`Identifier`)return e.name===`undefined`?void 0:e.name===`NaN`?NaN:e.name===`Infinity`?1/0:t.scope[e.name];if(e.type===`UnaryExpression`){let i=await Ph(e.argument,t,n,r);return e.operator===`!`?!Uh(i):e.operator===`-`?-i:e.operator===`+`?+i:e.operator===`typeof`?typeof i:void 0}if(e.type===`BinaryExpression`){let i=await Ph(e.left,t,n,r),a=await Ph(e.right,t,n,r);return e.operator===`===`?i===a:e.operator===`!==`?i!==a:e.operator===`==`?i===a:e.operator===`!=`?i!==a:e.operator===`<`?i<a:e.operator===`<=`?i<=a:e.operator===`>`?i>a:e.operator===`>=`?i>=a:e.operator===`+`?i+a:e.operator===`-`?i-a:e.operator===`*`?i*a:e.operator===`/`?i/a:e.operator===`%`?i%a:void 0}if(e.type===`LogicalExpression`){let i=await Ph(e.left,t,n,r);return e.operator===`&&`?Uh(i)?Ph(e.right,t,n,r):i:e.operator===`||`?Uh(i)?i:Ph(e.right,t,n,r):e.operator===`??`?i??Ph(e.right,t,n,r):void 0}if(e.type===`MemberExpression`){let i=await Ph(e.object,t,n,r);if(i==null)return;if(e.computed)return i[await Ph(e.property,t,n,r)];let{name:a}=e.property;return i[a]}if(e.type===`ConditionalExpression`)return Uh(await Ph(e.test,t,n,r))?Ph(e.consequent,t,n,r):Ph(e.alternate,t,n,r);let i=Vh(e);if(i!==``)try{let e=ch(i,t.scope,Eh(t,r));return e===`true`?!0:e===`false`?!1:e===`null`?null:e===`undefined`||e===``?void 0:/^-?\d+(?:\.\d+)?$/.test(e)?Number(e):e}catch{return}}async function Fh(e,t,n,r){let i=Rh(e,t);if(i.name!=null&&ph(i.name,t)){let{processAst:e}=await Promise.resolve().then(()=>Kh);return hh(i,t,e)}return _h(i,t)??(i.children.length>0?n(i.children,t):[])}async function Ih(e,t,n,r){let i=[];for(let a of e.children){let e=await Lh(a,t,n,r);i.push(...e)}return i}async function Lh(e,t,n,r){if(e.type===`JSXElement`)return Fh(e,t,n,r);if(e.type===`JSXFragment`)return Ih(e,t,n,r);if(e.type===`JSXText`){let t=e.value.trim();return t===``?[]:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?[]:kh(e.expression,t,n,r):e.type===`JSXSpreadChild`?kh(e.expression,t,n,r):[]}function Rh(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=zh(n.name):n.name.type===`JSXNamespacedName`&&(r=`${n.name.namespace.name}:${n.name.name.name}`);let i=[];for(let e of n.attributes)if(e.type===`JSXAttribute`){let t=e.name.type===`JSXIdentifier`?e.name.name:`${e.name.namespace.name}:${e.name.name.name}`,n=null;e.value==null?n=null:e.value.type===`Literal`?n=String(e.value.value):e.value.type===`JSXExpressionContainer`&&e.value.expression.type!==`JSXEmptyExpression`&&(n={type:`mdxJsxAttributeValueExpression`,value:Vh(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${Vh(e.argument)}`});let a=[];for(let n of e.children){let e=Bh(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function zh(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${zh(e.object)}.${e.property.name}`}function Bh(e,t){if(e.type===`JSXText`){let{value:t}=e;return t.trim()===``?null:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}if(e.type===`JSXElement`)return[Rh(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=Bh(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:Vh(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${Vh(e.expression)}`}]}]:null}function Vh(e){if(e.type===`Identifier`)return e.name;if(e.type===`Literal`)return typeof e.value==`string`?JSON.stringify(e.value):String(e.value);if(e.type===`MemberExpression`){let t=Vh(e.object);return e.computed?`${t}[${Vh(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${Vh(e.callee)}(${e.arguments.map(e=>Vh(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=Vh(e.left),n=Vh(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=Vh(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${Vh(e.test)} ? ${Vh(e.consequent)} : ${Vh(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>Vh(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:Vh(e.key)}: ${Vh(e.value)}`).join(`, `)}}`;if(e.type===`TemplateLiteral`){let t="`";for(let n=0;n<e.quasis.length;n++)t+=e.quasis[n]?.value.raw??``,n<e.expressions.length&&(t+=`\${${Vh(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${Vh(e.argument)}`:``}function Hh(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function Uh(e){return!!e}function Wh(e){if(e==null)return[];let t=typeof e==`string`?e:String(e);return t===``||t===`undefined`||t===`null`?[]:[{type:`paragraph`,children:[{type:`text`,value:t}]}]}function Gh(e,t,n){let r=Vh(e);if(r===``)return[];try{return Wh(ch(r,t.scope,Eh(t,n)))}catch{return[]}}var Kh=rh({processAst:()=>Yh});function qh(e,t,n){return{...e.filePath!=null&&{filePath:e.filePath},...e.sourceText!=null&&{sourceText:e.sourceText},...t.position!=null&&{position:t.position},nodeType:n}}function Jh(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function Yh(e,t){return Xh(e,t)}async function Xh(e,t){let n=[];for(let r of e.children){let e=await Zh(r,t);n.push(...e)}return{type:`root`,children:n}}async function Zh(e,t){if(e.type===`mdxjsEsm`)return[];if(e.type===`mdxFlowExpression`){let n=e,r=n.data?.estree,i=n.value.trim();if(i.startsWith(`/*`)&&i.endsWith(`*/`))return[];if(Dh(r))return Oh(n,t,async(e,t)=>(await Yh({type:`root`,children:e},t)).children);let a=ch(n.value,t.scope,qh(t,n,`mdxFlowExpression`));return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return Qh(e,t);if(e.type===`link`){let n=e,r=(await $h(n.children,t)).map(e=>e.type===`text`?{...e,value:Jh(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await $h(e.children,t);return[{...e,children:n}]}async function Qh(e,t){return e.name!=null&&ph(e.name,t)?hh(e,t,Yh):_h(e,t)??[]}async function $h(e,t){let n=[];for(let r of e){if(r.type===`mdxFlowExpression`){let e=r,i=e.data?.estree,a=e.value.trim();if(a.startsWith(`/*`)&&a.endsWith(`*/`))continue;if(Dh(i)){let r=await Oh(e,t,async(e,t)=>(await Yh({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=ch(e.value,t.scope,qh(t,e,`mdxFlowExpression`));o!==``&&n.push({type:`paragraph`,children:[{type:`text`,value:o}]});continue}if(r.type===`mdxTextExpression`){let e=r,i=e.value.trim();if(i.startsWith(`/*`)&&i.endsWith(`*/`))continue;let a={type:`text`,value:ch(e.value,t.scope,qh(t,e,`mdxTextExpression`))};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&ph(e.name,t)){let r=await hh(e,t,Yh);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=_h(e,t);if(i!=null)for(let e of i)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}if(`children`in r&&Array.isArray(r.children)){let e=await $h(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:Jh(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function eg(e){let t=this;t.compiler=n;function n(n){return vi(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function tg(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a,sourceText:o}=t;for(let t of e){let e=ng(t,i,{...a!=null&&{filePath:a},...o!=null&&{sourceText:o}});Object.assign(n,e)}let s=Object.keys(n).length>0,c=r!=null&&Object.keys(r).length>0,l;return l=s&&c?`mixed`:s?`export`:`yaml`,{fields:{...r,...n},source:l}}function ng(e,t,n={}){let r={},{filePath:i,sourceText:a}=n,o=e.value.trim(),s=/^export\s+default\s+/.exec(o);if(s!=null){let n=s[0].length,c=rg(o,n);if(c!=null)try{let e=ig(c.trim(),t,i);typeof e==`object`&&e&&!Array.isArray(e)&&Object.assign(r,e)}catch(t){let n=t instanceof Error?t.message:String(t);throw new th(`Cannot statically evaluate export default`,`default`,{...i!=null&&{filePath:i},...a!=null&&{sourceText:a},...e.position!=null&&{position:e.position},nodeType:`mdxjsEsm`,phase:`export-parsing`,cause:n})}return r}let c=/export\s+const\s+(\w+)\s*=\s*/g,l=c.exec(o);for(;l!==null;){let n=l[1];if(n==null){l=c.exec(o);continue}let s=rg(o,l.index+l[0].length);if(s==null){l=c.exec(o);continue}try{let e=ig(s.trim(),t,i);n===`metadata`&&typeof e==`object`&&e&&!Array.isArray(e)?Object.assign(r,e):r[n]=e}catch(t){let r=t instanceof Error?t.message:String(t);throw new th(`Cannot statically evaluate export "${n}"`,n,{...i!=null&&{filePath:i},...a!=null&&{sourceText:a},...e.position!=null&&{position:e.position},nodeType:`mdxjsEsm`,phase:`export-parsing`,cause:r})}l=c.exec(o)}return r}function rg(e,t){let n=0,r=null,i=!1,a=t;for(let o=t;o<e.length;o++){let t=e[o];if(i){i=!1;continue}if(t===`\\`){i=!0;continue}if(r!=null){t===r&&(r=null);continue}if(t===`"`||t===`'`||t==="`"){r=t;continue}if(t===`{`||t===`[`){n++;continue}if(t===`}`||t===`]`){n--;continue}if(n===0){if(t===`;`||t===`
|
|
96
|
+
`){a=o;break}if(t===`/`&&o+1<e.length&&e[o+1]===`/`){a=o;break}}o===e.length-1&&(a=e.length)}a<=t&&(a=e.length);let o=e.slice(t,a).trim();return o.endsWith(`;`)?o.slice(0,-1).trim():o}function ig(e,t,n){let r=e.trim();if(r===``)throw Error(`Empty value cannot be evaluated`);if(r===`true`)return!0;if(r===`false`)return!1;if(r===`null`)return null;if(/^-?\d+(?:\.\d+)?$/.test(r))return Number(r);if(r.startsWith(`"`)&&r.endsWith(`"`))return ag(r.slice(1,-1),`"`);if(r.startsWith(`'`)&&r.endsWith(`'`))return ag(r.slice(1,-1),`'`);if(r.startsWith("`")&&r.endsWith("`")){let e=r.slice(1,-1);if(e.includes("${"))throw Error(`Template literal with expressions cannot be statically evaluated: ${r}`);return ag(e,"`")}if(r.startsWith(`[`)&&r.endsWith(`]`))return sg(r,t,n);if(r.startsWith(`{`)&&r.endsWith(`}`))return cg(r,t,n);if(/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r))return og(r,t,n);let i=n==null?``:` in file "${n}"`;throw Error(`Expression "${r}" cannot be statically evaluated${i}`)}function ag(e,t){return e.replaceAll(`\\n`,`
|
|
97
|
+
`).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function og(e,t,n){if(t==null){let t=n==null?``:` in file "${n}"`;throw Error(`Variable reference "${e}" cannot be resolved without scope${t}`)}let r=e.split(`.`),i=r[0];if(i==null||!(i in t)){let r=n==null?``:` in file "${n}"`,a=Object.keys(t).join(`, `);throw Error(`Undefined namespace "${i}" in expression "${e}"${r}. Available: ${a}`)}let a=t[i];for(let t=1;t<r.length;t++){let i=r[t];if(i==null)continue;if(a==null){let t=n==null?``:` in file "${n}"`;throw Error(`Cannot read property "${i}" of null/undefined in "${e}"${t}`)}if(typeof a!=`object`){let t=n==null?``:` in file "${n}"`;throw Error(`Cannot read property "${i}" of ${typeof a} in "${e}"${t}`)}let o=a;if(!(i in o)){let t=n==null?``:` in file "${n}"`,r=Object.keys(o).join(`, `);throw Error(`Undefined property "${i}" in "${e}"${t}. Available: ${r}`)}a=o[i]}if(typeof a==`string`||typeof a==`number`||typeof a==`boolean`||a===null||Array.isArray(a)||typeof a==`object`)return a;let o=n==null?``:` in file "${n}"`;throw Error(`Variable "${e}" resolved to unsupported type: ${typeof a}${o}`)}function sg(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=lg(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return ug(r).map(e=>ig(e.trim(),t,n))}function cg(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=lg(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=dg(r);for(let e of a){let r=fg(e);if(r===-1)continue;let a=e.slice(0,r).trim(),o=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)||a.startsWith(`'`)&&a.endsWith(`'`))&&(a=a.slice(1,-1)),i[a]=ig(o,t,n)}return i}function lg(e){let t=``,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){t+=a,r=!1;continue}if(a===`\\`){t+=a,r=!0;continue}if(n!=null){a===n?(t+=`"`,n=null):a===`"`&&n===`'`?t+=`\\"`:t+=a;continue}if(a===`"`||a===`'`){t+=`"`,n=a;continue}if(a===`:`&&i>0){let e=t.length-1;for(;e>=0&&/\s/.test(t.charAt(e));)e--;let n=e+1;for(;e>=0&&/[\w$]/.test(t.charAt(e));)e--;if(e++,e>0&&t.charAt(e-1)!==`"`){let r=t.slice(e,n);r.length>0&&/^[\w$]+$/.test(r)&&(t=`${t.slice(0,e)}"${r}"`)}}t+=a}return t}function ug(e){let t=[],n=``,r=0,i=null,a=!1;for(let o of e){if(a){n+=o,a=!1;continue}if(o===`\\`){n+=o,a=!0;continue}if(i!=null){n+=o,o===i&&(i=null);continue}if(o===`"`||o===`'`||o==="`"){n+=o,i=o;continue}if(o===`[`||o===`{`){r++,n+=o;continue}if(o===`]`||o===`}`){r--,n+=o;continue}if(o===`,`&&r===0){n.trim()!==``&&t.push(n.trim()),n=``;continue}n+=o}return n.trim()!==``&&t.push(n.trim()),t}function dg(e){return ug(e)}function fg(e){let t=null,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){n=!1;continue}if(i===`\\`){n=!0;continue}if(t!=null){i===t&&(t=null);continue}if(i===`"`||i===`'`||i==="`"){t=i;continue}if(i===`:`)return r}return-1}function pg(e,t,n){return{...e.filePath!=null&&{filePath:e.filePath},...e.sourceText!=null&&{sourceText:e.sourceText},...n?.position!=null&&{position:n.position},nodeType:t}}function mg(e,t){let n=e.attributes.find(e=>e.type===`mdxJsxAttribute`&&e.name===`when`);if(n?.type!==`mdxJsxAttribute`)return!0;if(typeof n.value==`string`)return n.value===`true`;if(n.value!=null&&typeof n.value==`object`&&n.value.type===`mdxJsxAttributeValueExpression`)try{let e=ch(n.value.value,t.scope,pg(t,`mdxJsxAttributeValueExpression`,n));return e===`true`||e===`1`}catch{return!1}return!1}async function hg(e,t,n){return!mg(e,t)||e.children.length===0?[]:n(e.children,t)}async function gg(e,t){if(!mg(e,t)||e.children.length===0)return[];let n=_g(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function _g(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=ch(r.value,t.scope,pg(t,`mdxTextExpression`,r))}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=_g(r.children,t));return n}function vg(){ah(`Md`,hg),ah(`Md.Line`,gg)}vg();function yg(e,t){let n={};if(e!=null&&(n.os={...e.os},n.env={...e.env},n.profile={...e.profile},n.tool={...e.tool}),t!=null)for(let[e,r]of Object.entries(t)){let t=n[e];n[e]=typeof r==`object`&&r&&!Array.isArray(r)&&typeof t==`object`&&t&&!Array.isArray(t)?{...t,...r}:r}return n}async function bg(e,t){let n=Gf(e),r=yg(t?.globalScope,t?.scope),i=oh(),a;if(t?.extractMetadata===!0){let i=n.children.find(e=>e.type===`yaml`),o;if(i!=null)try{o=f.parse(i.value)}catch{}a=tg(n.children.filter(e=>e.type===`mdxjsEsm`),{...o!=null&&{yamlFrontMatter:o},scope:r,...t?.filePath!=null&&{filePath:t.filePath},sourceText:e}),n.children=n.children.filter(e=>e.type!==`yaml`&&e.type!==`mdxjsEsm`)}let o=await Yh(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath},...t?.filePath!=null&&{filePath:t.filePath},sourceText:e}),s=Ff().use(Lt,[`yaml`]).use(Es).use(eg,{bullet:`-`,fence:"`",fences:!0,emphasis:`*`,strong:`*`,rule:`-`,handlers:{text(e){return e.value}}}).stringify(o).trim();return t?.extractMetadata===!0&&a!=null?{content:s,metadata:a}:s}const xg=/^\s*(```|~~~)/u,Sg=[/^\s*export\s+default\b/u,/^\s*export\s+const\b/u,/^\s*import\b/u];let Cg=null;try{let t=e(import.meta.url),{platform:n,arch:r}=o,i={"win32-x64":[`napi-md-compiler.win32-x64-msvc`,`win32-x64-msvc`],"linux-x64":[`napi-md-compiler.linux-x64-gnu`,`linux-x64-gnu`],"linux-arm64":[`napi-md-compiler.linux-arm64-gnu`,`linux-arm64-gnu`],"darwin-arm64":[`napi-md-compiler.darwin-arm64`,`darwin-arm64`],"darwin-x64":[`napi-md-compiler.darwin-x64`,`darwin-x64`]}[`${n}-${r}`];if(i!=null){let[e,n]=i;try{Cg=t(`./${e}.node`)}catch{try{Cg=t(`@truenine/memory-sync-cli-${n}`).mdCompiler}catch{}}}}catch{}async function wg(e,t){let n=t?.extractMetadata===!0?{...t,extractMetadata:!0}:null,r=Tg(e,t);if(r!=null){if(n!=null){let{metadata:t}=r;return t==null||Dg(r.content)?bg(e,n):{content:r.content,metadata:t}}return r.content}return n==null?t==null?bg(e):bg(e,{...t,extractMetadata:!1}):bg(e,n)}function Tg(e,t){if(Cg==null)return null;try{let n=Cg.compileMdxToMd(e,Eg(t)),r=JSON.parse(n);return t?.extractMetadata===!0&&r.metadata==null?null:r}catch{return null}}function Eg(e){if(e==null)return null;let t={...e,...e.globalScope==null?{}:{globalScope:{os:e.globalScope.os,env:e.globalScope.env,profile:e.globalScope.profile,tool:e.globalScope.tool}}};return JSON.stringify(t)}function Dg(e){let t;for(let n of e.split(/\r?\n/u)){let e=xg.exec(n);if(e?.[1]!=null){let n=e[1];t==null?t=n:t===n&&(t=void 0);continue}if(t==null&&Sg.some(e=>e.test(n)))return!0}return!1}function Og(e,t){return e==null&&t==null?[]:[...new Set([...e??[],...t??[]])]}function kg(e,t){return e==null||t.length===0?!0:typeof e==`string`?t.includes(e):e.some(e=>t.includes(e))}function Ag(e,t){if(e==null&&t==null)return{};let n={};for(let[t,r]of Object.entries(e??{}))n[t]=[...r];for(let[e,r]of Object.entries(t??{}))n[e]=Object.hasOwn(n,e)?[...new Set([...n[e],...r])]:[...r];return n}function jg(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.matchesSeries==`function`&&typeof t.resolveEffectiveIncludeSeries==`function`&&typeof t.resolveSubSeries==`function`}function Mg(){let t={"win32-x64":`win32-x64-msvc`,"linux-x64":`linux-x64-gnu`,"linux-arm64":`linux-arm64-gnu`,"darwin-arm64":`darwin-arm64`,"darwin-x64":`darwin-x64`}[`${o.platform}-${o.arch}`];if(t==null)return;let n=`@truenine/memory-sync-cli-${t}`,r=`napi-memory-sync-cli.${t}.node`;try{let t=e(import.meta.url),i=[n,`${n}/${r}`,`./${r}`];for(let e of i)try{let n=t(e),r=[n,n?.default,n?.config];for(let e of r)if(jg(e))return e}catch{}}catch{}}const{resolveEffectiveIncludeSeries:Ng,matchesSeries:Pg,resolveSubSeries:Fg}=Mg()??{resolveEffectiveIncludeSeries:Og,matchesSeries:kg,resolveSubSeries:Ag};function Ig(e,t,n){let r=Ng(t?.includeSeries,t?.[n]?.includeSeries);return e.filter(e=>Pg(e.seriName,r))}function Lg(e){let t=e.replaceAll(/\.\/+/g,``);return t=t.replaceAll(/\/+$/g,``),t}function Rg(e,t){return t.startsWith(`**/`)?`${e}/${t}`:t.startsWith(`*`)?`${e}/**/${t}`:`${e}/${t}`}function zg(e,t){for(let n of t){let t=n.replaceAll(/\/+$/g,``),r=[{prefix:t,pattern:`${t}/`},{prefix:t,pattern:`${t}\\`}];for(let{prefix:t,pattern:n}of r)if(e.startsWith(n))return{prefix:t,baseGlob:e.slice(n.length)};if(e===t)return{prefix:t,baseGlob:`**/*`}}return{prefix:null,baseGlob:e}}function Bg(e,t){let n=Fg(t?.subSeries,t?.rules?.subSeries);if(Object.keys(n).length===0)return e;let r={};for(let[e,t]of Object.entries(n)){let n=Lg(e);r[n]=t}let i=Object.keys(r);return e.map(e=>{if(e.seriName==null)return e;let t=[];for(let[n,i]of Object.entries(r))(Array.isArray(e.seriName)?e.seriName.some(e=>i.includes(e)):i.includes(e.seriName))&&t.push(n);if(t.length===0)return e;let n=[];for(let r of e.globs){let{prefix:e,baseGlob:a}=zg(r,i);e!=null&&n.push(r);for(let r of t){if(r===e)continue;let t=Rg(r,a);n.includes(t)||n.push(t)}}return{...e,globs:n}})}function Vg(e){let r=n.join(e,`.git`);if(!t.existsSync(r))return null;let i=t.lstatSync(r);if(i.isDirectory())return n.join(r,`info`);if(i.isFile())try{let i=t.readFileSync(r,`utf8`).trim(),a=/^gitdir: (.+)$/.exec(i);if(a?.[1]!=null){let t=n.resolve(e,a[1]);return n.join(t,`info`)}}catch{}return null}function Hg(e,r=5){let i=[],a=new Set([`node_modules`,`.turbo`,`dist`,`build`,`out`,`.cache`]);function o(s,c){if(c>r)return;let l;try{let e=t.readdirSync(s,{withFileTypes:!0});if(!Array.isArray(e))return;l=e}catch{return}l.some(e=>e.name===`.git`)&&s!==e&&i.push(s);for(let e of l)e.isDirectory()&&(e.name===`.git`||a.has(e.name)||o(n.join(s,e.name),c+1))}return o(e,0),i}function Ug(e){let r=n.join(e,`modules`);if(!t.existsSync(r))return[];let i=[];function a(e){let r;try{let n=t.readdirSync(e,{withFileTypes:!0});if(!Array.isArray(n))return;r=n}catch{return}if(r.some(e=>e.name===`info`&&e.isDirectory())&&i.push(n.join(e,`info`)),r.find(e=>e.name===`modules`&&e.isDirectory())==null)return;let o;try{let r=t.readdirSync(n.join(e,`modules`),{withFileTypes:!0});if(!Array.isArray(r))return;o=r}catch{return}for(let t of o)t.isDirectory()&&a(n.join(e,`modules`,t.name))}let o;try{let e=t.readdirSync(r,{withFileTypes:!0});if(!Array.isArray(e))return i;o=e}catch{return i}for(let e of o)e.isDirectory()&&a(n.join(r,e.name));return i}const Wg={default:{websearch:`web_search`,webfetch:`web_fetch`,readFile:`read_file`,writeFile:`write_file`,executeCommand:`execute_command`,todolistWrite:`todolist_write`,grep:`grep`,listDirectory:`list_directory`},claudeCode:{readFile:`Read`,writeFile:`Write`,executeCommand:`Execute`,todolistWrite:`TodoWrite`,listDirectory:`List`},kiro:{websearch:`remote_web_search`,webfetch:`webFetch`,readFile:`readFile`,writeFile:`fsWrite`,executeCommand:`executeBash`,todolistWrite:`todolistWrite`,grep:`grepSearch`,listDirectory:`listDir`}};let Gg=function(e){return e.Bash=`bash`,e.Zsh=`zsh`,e.Fish=`fish`,e.Sh=`sh`,e.PowerShell=`powershell`,e.Pwsh=`pwsh`,e.Cmd=`cmd`,e.Unknown=`unknown`,e}({}),Kg=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var qg=class{userConfig;toolPreset;constructor(e={}){this.userConfig=e.userConfig,this.toolPreset=e.toolPreset??`default`}collect(){return{os:this.collectOsInfo(),env:this.collectEnvContext(),profile:this.collectProfile(),tool:this.collectToolReferences(),Md:this.createMdComponent()}}collectOsInfo(){let e=s.platform();return{platform:e,arch:s.arch(),hostname:s.hostname(),homedir:s.homedir(),tmpdir:s.tmpdir(),type:s.type(),release:s.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return Kg.Win;case`darwin`:return Kg.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return Kg.Linux;default:return Kg.Unknown}}detectShellKind(){let e=(o.env.SHELL??o.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?Gg.Bash:e.includes(`zsh`)?Gg.Zsh:e.includes(`fish`)?Gg.Fish:e.includes(`pwsh`)?Gg.Pwsh:e.includes(`powershell`)?Gg.PowerShell:e.includes(`cmd`)?Gg.Cmd:e.endsWith(`/sh`)?Gg.Sh:Gg.Unknown}collectEnvContext(){return{...o.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...Wg.default};return this.toolPreset===`claudeCode`?{...e,...Wg.claudeCode}:this.toolPreset===`kiro`?{...e,...Wg.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let Jg=function(e){return e[e.SystemDefault=0]=`SystemDefault`,e[e.UserConfig=10]=`UserConfig`,e[e.PluginRegistered=20]=`PluginRegistered`,e[e.CompileTime=30]=`CompileTime`,e}({});var Yg=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=Jg.PluginRegistered){this.registrations.push({namespace:e,values:t,priority:n})}getRegistrations(){return this.registrations}merge(e){let t={};this.globalScope!=null&&(t.os={...this.globalScope.os},t.env={...this.globalScope.env},t.profile={...this.globalScope.profile},t.tool={...this.globalScope.tool});let n=[...this.registrations].sort((e,t)=>e.priority-t.priority);for(let e of n)t[e.namespace]=this.deepMerge(t[e.namespace],e.values);if(e!=null)for(let[n,r]of Object.entries(e))t[n]=typeof r==`object`&&r&&!Array.isArray(r)?this.deepMerge(t[n],r):r;return t}deepMerge(e,t){if(e==null)return{...t};let n={...e};for(let[e,r]of Object.entries(t))n[e]=typeof r==`object`&&r&&!Array.isArray(r)&&typeof n[e]==`object`&&n[e]!==null&&!Array.isArray(n[e])?this.deepMerge(n[e],r):r;return n}resolve(e){let t=this.merge();return e.replaceAll(/\$\{([^}]+)\}/g,(e,n)=>{let r=n.split(`.`),i=t;for(let e of r)i=i?.[e];return i==null?`\${${n}}`:String(i)})}clear(){this.registrations.length=0,this.globalScope=null}};const Xg=[`project`,`workspace`,`global`];function Zg(e){if(e==null)return[];if(typeof e==`string`)return[e];let t=[];for(let n of e)t.includes(n)||t.push(n);return t}function Qg(e,t){let n=new Map;for(let[e,r]of t.entries())n.set(r,e);return[...e].sort((e,t)=>(n.get(e)??2**53-1)-(n.get(t)??2**53-1))}function $g(e){let{requestedScopes:t,defaultScopes:n,supportedScopes:r,singleScope:i,availableScopes:a,priority:o=Xg}=e,s=Zg(t),c=Zg(n),l=new Set(Zg(r)),u=(s.length>0?s:c).filter(e=>l.has(e));if(u.length===0)return[];let d=Qg(u,o);if(!i)return d;if(a!=null&&a.length>0){let e=new Set(a),t=d.find(t=>e.has(t));return t==null?[]:[t]}let[f]=d;return f==null?[]:[f]}const e_=m.object({src:m.string(),dist:m.string()}),t_=m.object({dir:m.string().default(`aindex`),skills:e_,commands:e_,subAgents:e_,rules:e_,globalPrompt:e_,workspacePrompt:e_,app:e_,ext:e_,arch:e_}),n_=m.object({includeSeriesPrefix:m.boolean().optional(),seriesSeparator:m.string().optional()}),r_=m.object({includeSeriesPrefix:m.boolean().optional(),pluginOverrides:m.record(m.string(),n_).optional()}),i_=m.enum([`project`,`workspace`,`global`]),a_=m.union([i_,m.array(i_).min(1)]),o_=m.object({prompt:a_.optional(),rules:a_.optional(),commands:a_.optional(),subagents:a_.optional(),skills:a_.optional(),mcp:a_.optional()}),s_=m.object({plugins:m.record(m.string(),o_).optional()}),c_=m.enum([`direct`,`recursive`]),l_=m.enum([`path`,`glob`]),u_=m.object({path:m.string(),protectionMode:c_,matcher:l_.optional(),reason:m.string().optional()}),d_=m.object({rules:m.array(u_).optional()}),f_=m.object({name:m.string().optional(),username:m.string().optional(),gender:m.string().optional(),birthday:m.string().optional()}).catchall(m.unknown()),p_=m.object({version:m.string().optional(),workspaceDir:m.string().optional(),aindex:t_.optional(),logLevel:m.enum([`trace`,`debug`,`info`,`warn`,`error`]).optional(),commandSeriesOptions:r_.optional(),outputScopes:s_.optional(),cleanupProtection:d_.optional(),profile:f_.optional()}),m_=m.object({names:m.array(m.string()).optional()}),h_=m.object({includeSeries:m.array(m.string()).optional(),subSeries:m.record(m.string(),m.array(m.string())).optional()});m.object({mcp:m_.optional(),includeSeries:m.array(m.string()).optional(),subSeries:m.record(m.string(),m.array(m.string())).optional(),rules:h_.optional(),skills:h_.optional(),subAgents:h_.optional(),commands:h_.optional()}),m.object({configFileName:m.string().optional(),searchPaths:m.array(m.string()).optional(),searchCwd:m.boolean().optional(),searchGlobal:m.boolean().optional()});function g_(e){return{workspace:{directory:e.workspace.directory,projects:[...e.workspace.projects]},...e.skills!=null&&{skills:[...e.skills]},...e.commands!=null&&{commands:[...e.commands]},...e.subAgents!=null&&{subAgents:[...e.subAgents]},...e.rules!=null&&{rules:[...e.rules]},...e.readmePrompts!=null&&{readmePrompts:[...e.readmePrompts]},...e.globalMemory!=null&&{globalMemory:e.globalMemory},...e.vscodeConfigFiles!=null&&{vscodeConfigFiles:[...e.vscodeConfigFiles]},...e.jetbrainsConfigFiles!=null&&{jetbrainsConfigFiles:[...e.jetbrainsConfigFiles]},...e.editorConfigFiles!=null&&{editorConfigFiles:[...e.editorConfigFiles]},...e.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles]},...e.globalGitIgnore!=null&&{globalGitIgnore:e.globalGitIgnore},...e.shadowGitExclude!=null&&{shadowGitExclude:e.shadowGitExclude},...e.aindexDir!=null&&{aindexDir:e.aindexDir}}}const __={Readme:{src:`rdm.mdx`,out:`README.md`},CodeOfConduct:{src:`coc.mdx`,out:`CODE_OF_CONDUCT.md`},Security:{src:`security.mdx`,out:`SECURITY.md`}},v_=[`prompt`,`rules`,`commands`,`subagents`,`skills`,`mcp`];function y_(e){return p.isBuffer(e)}function b_(e){if(typeof e==`string`)return[e];let t=[];for(let n of e)t.includes(n)||t.push(n);return t}function x_(e,t){return t?.outputScopes?.plugins?.[e]}function S_(e){for(let t of v_){let n=e.outputCapabilities[t];if(n!=null&&n.scopes.length===0)throw Error(`Plugin ${e.name} declares empty scopes for topic "${t}"`)}}function C_(e,t){let n=x_(e.name,t);if(n!=null)for(let t of v_){let r=n[t];if(r==null)continue;let i=e.outputCapabilities[t];if(i==null)throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} is set, but plugin ${e.name} does not support topic "${t}".`);let a=b_(r);if(i.singleScope&&a.length>1){let n=a.join(`, `);throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} is single-scope and cannot request multiple scopes [${n}].`)}let o=new Set(i.scopes),s=a.filter(e=>!o.has(e));if(s.length>0){let n=i.scopes.join(`, `),r=s.join(`, `);throw Error(`Invalid outputScopes configuration: outputScopes.plugins.${e.name}.${t} requests unsupported scopes [${r}]. Allowed scopes: [${n}].`)}}}function w_(e,t){for(let n of e)S_(n),C_(n,t)}async function T_(e,t){let n=new Map;w_(e,t.pluginOptions);for(let r of e){let e=await r.declareOutputFiles(t),i=[];for(let n of e){if(t.dryRun===!0){i.push({path:n.path,success:!0,skipped:!1});continue}try{let e=t.path.dirname(n.path);if(t.fs.mkdirSync(e,{recursive:!0}),n.ifExists===`skip`&&t.fs.existsSync(n.path)){i.push({path:n.path,success:!0,skipped:!0});continue}if(n.ifExists===`error`&&t.fs.existsSync(n.path))throw Error(`Refusing to overwrite existing file: ${n.path}`);if(n.symlinkTarget!=null){t.fs.existsSync(n.path)&&t.fs.rmSync(n.path,{force:!0,recursive:!1}),t.fs.symlinkSync(n.symlinkTarget,n.path,`file`),i.push({path:n.path,success:!0});continue}let a=await r.convertContent(n,t);y_(a)?t.fs.writeFileSync(n.path,a):t.fs.writeFileSync(n.path,a,`utf8`),i.push({path:n.path,success:!0})}catch(e){i.push({path:n.path,success:!1,error:e})}}let a={files:i,dirs:[]};n.set(r.name,a)}return n}async function E_(e,t){let n=[],r=[],i=[],a=[],o=[],s=[];w_(e,t.pluginOptions);for(let n of e){let e=await n.declareOutputFiles({...t,dryRun:!0});for(let t of e)t.scope===`global`?s.push(t.path):t.scope===`workspace`?a.push(t.path):r.push(t.path)}return{projectDirs:n,projectFiles:r,workspaceDirs:i,workspaceFiles:a,globalDirs:o,globalFiles:s}}var D_=class extends Error{pluginName;missingDependency;constructor(e,t){super(`Plugin "${e}" depends on missing plugin "${t}"`),this.name=`MissingDependencyError`,this.pluginName=e,this.missingDependency=t}},O_=class extends Error{cyclePath;constructor(e){super(`Circular plugin dependency detected: ${e.join(` -> `)}`),this.name=`CircularDependencyError`,this.cyclePath=[...e]}},k_=class extends Am{declarativeOutput=!0;outputCapabilities;globalConfigDir;outputFileName;indexignore;commandsConfig;subAgentsConfig;commandOutputEnabled;subAgentOutputEnabled;skillsConfig;skillOutputEnabled;toolPreset;rulesConfig;ruleOutputEnabled;cleanupConfig;registryWriterCache=new Map;constructor(e,t){super(e,fp.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``,this.indexignore=t?.indexignore;let n=t?.commands?.transformFrontMatter;this.commandOutputEnabled=t?.commands!=null,this.commandsConfig={subDir:t?.commands?.subDir??`commands`,sourceScopes:t?.commands?.sourceScopes??[`project`,`workspace`,`global`],...n!=null&&{transformFrontMatter:n}},this.subAgentOutputEnabled=t?.subagents!=null,this.subAgentsConfig={subDir:t?.subagents?.subDir??`agents`,sourceScopes:t?.subagents?.sourceScopes??[`project`,`workspace`,`global`],includePrefix:t?.subagents?.includePrefix??!0,linkSymbol:t?.subagents?.linkSymbol??`-`,ext:t?.subagents?.ext??`.md`,...t?.subagents?.transformFrontMatter!=null&&{transformFrontMatter:t.subagents.transformFrontMatter}},this.skillOutputEnabled=t?.skills!=null,this.skillsConfig={subDir:t?.skills?.subDir??`skills`,sourceScopes:t?.skills?.sourceScopes??[`project`,`workspace`,`global`]},this.toolPreset=t?.toolPreset,this.ruleOutputEnabled=t?.rules!=null,this.rulesConfig={...t?.rules,sourceScopes:t?.rules?.sourceScopes??[`project`,`workspace`,`global`]},this.cleanupConfig=t?.cleanup??{},this.outputCapabilities=t?.capabilities==null?this.buildInferredCapabilities():this.normalizeCapabilities(t.capabilities)}buildInferredCapabilities(){let e={};return this.outputFileName.length>0&&(e.prompt={scopes:[`project`,`global`],singleScope:!1}),this.ruleOutputEnabled&&(e.rules={scopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],singleScope:!1}),this.commandOutputEnabled&&(e.commands={scopes:this.commandsConfig.sourceScopes,singleScope:!0}),this.subAgentOutputEnabled&&(e.subagents={scopes:this.subAgentsConfig.sourceScopes,singleScope:!0}),this.skillOutputEnabled&&(e.skills={scopes:this.skillsConfig.sourceScopes,singleScope:!0}),e}normalizeCapabilities(e){let t={};for(let n of v_){let r=e[n];if(r==null)continue;let i=this.normalizeCapability(r);i!=null&&(t[n]=i)}return t}normalizeCapability(e){let t=[];for(let n of e.scopes)t.includes(n)||t.push(n);if(t.length!==0)return{scopes:t,singleScope:e.singleScope}}resolvePromptSourceProjectConfig(e){let{projects:t}=e.collectedOutputContext.workspace;return t.find(e=>e.isPromptSourceProject===!0)?.projectConfig??t[0]?.projectConfig}isRelativePath(e){return e.pathKind===mp.Relative}toRelativePath(e){return e.path}resolveFullPath(e,t){let r=this.resolveDirectoryPath(e),i=t??this.outputFileName;return i?n.join(r,i):r}resolveDirectoryPath(e){return e.pathKind===mp.Absolute?e.path:`basePath`in e?n.resolve(e.basePath,e.path):n.resolve(o.cwd(),e.path)}getWorkspaceConfigDir(e){let t=this.resolveDirectoryPath(e.collectedOutputContext.workspace.directory);return n.join(t,this.globalConfigDir)}createRelativePath(e,t,r){return n.join(t,e)}createFileRelativePath(e,t){return n.join(e,t)}getGlobalConfigDir(){return n.join(this.getHomeDir(),this.globalConfigDir)}getXdgConfigHomeDir(){let e=o.env.XDG_CONFIG_HOME;return typeof e==`string`&&e.trim().length>0?e:n.join(this.getHomeDir(),`.config`)}getHomeDir(){return s.homedir()}joinPath(...e){return n.join(...e)}resolvePath(...e){return n.resolve(...e)}dirname(e){return n.dirname(e)}basename(e,t){return n.basename(e,t)}existsSync(e){return t.existsSync(e)}lstatSync(e){return t.lstatSync(e)}readdirSync(e,n){return n?.withFileTypes===!0?t.readdirSync(e,{withFileTypes:!0}):t.readdirSync(e)}getIgnoreOutputPath(){if(this.indexignore!=null)return this.indexignore}resolveCleanupScopeBasePaths(e,t){if(e===`global`)return[this.getHomeDir()];if(e===`workspace`)return[this.resolveDirectoryPath(t.collectedOutputContext.workspace.directory)];if(e===`xdgConfig`)return[this.getXdgConfigHomeDir()];let n=[];for(let e of t.collectedOutputContext.workspace.projects){let t=e.dirFromWorkspacePath;t!=null&&n.push(this.resolveDirectoryPath(t))}return n}resolveCleanupDeclaredPath(e,t){return n.isAbsolute(t)?n.resolve(t):t===`~`?this.getHomeDir():t.startsWith(`~/`)||t.startsWith(`~\\`)?n.resolve(this.getHomeDir(),t.slice(2)):n.resolve(e,t)}normalizeGlobPattern(e){return e.replaceAll(`\\`,`/`)}buildCleanupTargetsFromScopeConfig(e,t,r){if(e==null)return[];let i=[],a=[`project`,`workspace`,`global`,`xdgConfig`],o=(e,a,o)=>{if(o==null||o.length===0)return;let s=this.resolveCleanupScopeBasePaths(e,r);for(let r of o)for(let o of s){let s=n.isAbsolute(r)?n.resolve(r):this.resolveCleanupDeclaredPath(o,r);i.push({path:a===`glob`?this.normalizeGlobPattern(s):s,kind:a,scope:e,label:`${t}.${e}`})}};for(let t of a){let n=e[t];n!=null&&(o(t,`file`,n.files),o(t,`directory`,n.dirs),o(t,`glob`,n.globs))}return i}buildMarkdownContent(e,t){return Jf(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Jf(t,e):n!=null&&n.length>0?Xf(n,e):e}extractGlobalMemoryContent(e){return e.collectedOutputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
|
|
96
98
|
|
|
97
|
-
`,skipIfEmpty:i=!0,position:a=`before`}=n??{};if(i&&(e==null||e.trim().length===0))return t;let o=e??``;return a===`after`?`${t}${r}${o}`:`${o}${r}${t}`}transformCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.commandPrefix==null?`${e.commandName}.md`:`${e.commandPrefix}${r}${e.commandName}.md`}transformSubAgentName(e,t){let n=t?.includePrefix??this.subAgentsConfig.includePrefix,r=t?.linkSymbol??this.subAgentsConfig.linkSymbol,i=t?.ext??this.subAgentsConfig.ext,a=i.startsWith(`.`)?i:`.${i}`;return n&&e.agentPrefix!=null&&e.agentPrefix.length>0?`${e.agentPrefix}${r}${e.agentName}${a}`:`${e.agentName}${a}`}getCommandSeriesOptions(e){let t=e.pluginOptions?.commandSeriesOptions,n=t?.pluginOverrides?.[this.name],r=n?.includeSeriesPrefix??t?.includeSeriesPrefix,i=n?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}getTransformOptionsFromContext(e,t){let n=this.getCommandSeriesOptions(e),r=n.includeSeriesPrefix??t?.includeSeriesPrefix,i=n.seriesSeparator??t?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}shouldSkipDueToPlugin(e,t){let n=e.registeredPluginNames;return n==null?!1:n.includes(t)}getRegistryWriter(e){let t=e.name,n=this.registryWriterCache.get(t);if(n!=null)return n;let r=new e(this.log);return this.registryWriterCache.set(t,r),r}async registerInRegistry(e,t,n){return e.register(t,n.dryRun)}normalizeRuleScope(e){return e.scope??`project`}normalizeSourceScope(e){return e===`workspace`||e===`global`||e===`project`?e:`project`}resolveCommandSourceScope(e){if(e.globalOnly===!0)return`global`;let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}resolveSubAgentSourceScope(e){let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}resolveSkillSourceScope(e){let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}selectSingleScopeItems(e,t,n,r){if(e.length===0)return{items:[]};let[i]=Ig({requestedScopes:r,defaultScopes:t,supportedScopes:t,singleScope:!0,availableScopes:[...new Set(e.map(n))]});return i==null?{items:[]}:{selectedScope:i,items:e.filter(e=>n(e)===i)}}selectRuleScopes(e,t){let n=[...new Set(t.map(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))))];return Ig({requestedScopes:this.getTopicScopeOverride(e,`rules`),defaultScopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],supportedScopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],singleScope:!1,availableScopes:n})}selectPromptScopes(e,t=[`project`,`global`],n=t){return Ig({requestedScopes:this.getTopicScopeOverride(e,`prompt`),defaultScopes:n,supportedScopes:t,singleScope:!1})}getTopicScopeOverride(e,t){return e.pluginOptions?.outputScopes?.plugins?.[this.name]?.[t]}buildSkillFrontMatter(e,t){let n=e.yamlFrontMatter,r={name:n.name,description:n.description};return`displayName`in n&&n.displayName!=null&&(r.displayName=n.displayName),`keywords`in n&&n.keywords!=null&&n.keywords.length>0&&(r.keywords=n.keywords),`author`in n&&n.author!=null&&(r.author=n.author),`version`in n&&n.version!=null&&(r.version=n.version),(t?.includeTools??!0)&&`allowTools`in n&&n.allowTools!=null&&n.allowTools.length>0&&(r.allowTools=(t?.toolFormat??`array`)===`string`?n.allowTools.join(`,`):n.allowTools),t?.additionalFields!=null&&Object.assign(r,t.additionalFields),r}buildRuleContent(e){let t=this.rulesConfig.transformFrontMatter?this.rulesConfig.transformFrontMatter(e):{globs:e.globs.join(`, `)};return Jf(t==null||Object.keys(t).length===0?void 0:t,e.content)}buildRuleFileName(e){let t=`${`${this.rulesConfig.prefix??`rule`}${this.rulesConfig.linkSymbol??`-`}`}${e.prefix}${this.rulesConfig.linkSymbol??`-`}${e.ruleName}${this.rulesConfig.ext??`.md`}`;return this.log.trace(`buildRuleFileName`,{plugin:this.name,rulePrefix:e.prefix,ruleName:e.ruleName,prefix:this.rulesConfig.prefix??`rule`,linkSymbol:this.rulesConfig.linkSymbol??`-`,ext:this.rulesConfig.ext??`.md`,result:t}),t}async declareOutputFiles(e){return this.buildDefaultOutputDeclarations(e)}async declareCleanupPaths(e){let t=this.buildCleanupTargetsFromScopeConfig(this.cleanupConfig.delete,`delete`,e),n=this.buildCleanupTargetsFromScopeConfig(this.cleanupConfig.protect,`protect`,e),{excludeScanGlobs:r}=this.cleanupConfig;return t.length===0&&n.length===0&&(r==null||r.length===0)?{}:{...t.length>0&&{delete:t},...n.length>0&&{protect:n},...r!=null&&r.length>0&&{excludeScanGlobs:r}}}async convertContent(e,t){let n=e.source;switch(n.kind){case`projectRootMemory`:case`projectChildMemory`:case`globalMemory`:case`skillReference`:case`ignoreFile`:return n.content;case`command`:return this.buildCommandContent(n.command);case`subAgent`:return this.buildSubAgentContent(n.subAgent);case`skillMain`:return this.buildSkillMainContent(n.skill);case`skillResource`:return n.encoding===`base64`?p.from(n.content,`base64`):n.content;case`rule`:return this.buildRuleContent(n.rule);default:throw Error(`Unsupported declaration source for plugin ${this.name}`)}}async buildDefaultOutputDeclarations(e){let t=[],{workspace:r,globalMemory:i,commands:a,subAgents:o,skills:s,rules:c,aiAgentIgnoreConfigFiles:l}=e.collectedOutputContext,u=this.getTransformOptionsFromContext(e),d=this.getIgnoreOutputPath(),f=this.indexignore==null?void 0:l?.find(e=>e.fileName===this.indexignore),p=this.commandOutputEnabled&&a!=null?this.selectSingleScopeItems(a,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)):{items:[]},m=this.subAgentOutputEnabled&&o!=null?this.selectSingleScopeItems(o,this.subAgentsConfig.sourceScopes,e=>this.resolveSubAgentSourceScope(e),this.getTopicScopeOverride(e,`subagents`)):{items:[]},h=this.skillOutputEnabled&&s!=null?this.selectSingleScopeItems(s,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)):{items:[]},g=c??[],_=this.ruleOutputEnabled&&g.length>0?new Set(this.selectRuleScopes(e,g)):new Set,v=new Set(this.selectPromptScopes(e)),y={project:[],workspace:[],global:[]};for(let e of g)y[this.normalizeSourceScope(this.normalizeRuleScope(e))].push(e);for(let e of r.projects){let r=e.dirFromWorkspacePath;if(r==null)continue;if(this.outputFileName.length>0&&v.has(`project`)&&(e.rootMemoryPrompt!=null&&t.push({path:this.resolveFullPath(r),scope:`project`,source:{kind:`projectRootMemory`,content:e.rootMemoryPrompt.content}}),e.childMemoryPrompts!=null))for(let n of e.childMemoryPrompts)t.push({path:this.resolveFullPath(n.dir),scope:`project`,source:{kind:`projectChildMemory`,content:n.content}});let i=n.join(r.basePath,r.path,this.globalConfigDir),{projectConfig:a}=e;if(p.selectedScope===`project`&&p.items.length>0){let e=yg(p.items,a,`commands`);for(let r of e){let e=this.transformCommandName(r,u);t.push({path:n.join(i,this.commandsConfig.subDir,e),scope:`project`,source:{kind:`command`,command:r}})}}if(m.selectedScope===`project`&&m.items.length>0){let e=yg(m.items,a,`subAgents`);for(let r of e){let e=this.transformSubAgentName(r);t.push({path:n.join(i,this.subAgentsConfig.subDir,e),scope:`project`,source:{kind:`subAgent`,subAgent:r}})}}if(h.selectedScope===`project`&&h.items.length>0){let e=yg(h.items,a,`skills`);for(let r of e){let e=r.yamlFrontMatter?.name??r.dir.getDirectoryName(),a=n.join(i,this.skillsConfig.subDir,e);if(t.push({path:n.join(a,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:r}}),r.childDocs!=null)for(let e of r.childDocs)t.push({path:n.join(a,e.dir.path.replace(/\.mdx$/,`.md`)),scope:`project`,source:{kind:`skillReference`,content:e.content}});if(r.resources!=null)for(let e of r.resources)t.push({path:n.join(a,e.relativePath),scope:`project`,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})}}if(_.has(`project`)){let e=Cg(yg(y.project,a,`rules`),a),r=n.join(i,this.rulesConfig.subDir??`rules`);for(let i of e)t.push({path:n.join(r,this.buildRuleFileName(i)),scope:`project`,source:{kind:`rule`,rule:i}})}d!=null&&f!=null&&e.isPromptSourceProject!==!0&&t.push({path:n.join(r.basePath,r.path,d),scope:`project`,source:{kind:`ignoreFile`,content:f.content}})}let b=this.resolvePromptSourceProjectConfig(e),x=t=>t===`global`?this.getGlobalConfigDir():this.getWorkspaceConfigDir(e);if((p.selectedScope===`global`||p.selectedScope===`workspace`)&&p.items.length>0){let e=yg(p.items,b,`commands`),r=x(p.selectedScope);for(let i of e){let e=this.transformCommandName(i,u);t.push({path:n.join(r,this.commandsConfig.subDir,e),scope:p.selectedScope,source:{kind:`command`,command:i}})}}if((m.selectedScope===`global`||m.selectedScope===`workspace`)&&m.items.length>0){let e=yg(m.items,b,`subAgents`),r=x(m.selectedScope);for(let i of e){let e=this.transformSubAgentName(i);t.push({path:n.join(r,this.subAgentsConfig.subDir,e),scope:m.selectedScope,source:{kind:`subAgent`,subAgent:i}})}}if((h.selectedScope===`global`||h.selectedScope===`workspace`)&&h.items.length>0){let e=yg(h.items,b,`skills`),r=x(h.selectedScope);for(let i of e){let e=i.yamlFrontMatter?.name??i.dir.getDirectoryName(),a=n.join(r,this.skillsConfig.subDir,e);if(t.push({path:n.join(a,`SKILL.md`),scope:h.selectedScope,source:{kind:`skillMain`,skill:i}}),i.childDocs!=null)for(let e of i.childDocs)t.push({path:n.join(a,e.dir.path.replace(/\.mdx$/,`.md`)),scope:h.selectedScope,source:{kind:`skillReference`,content:e.content}});if(i.resources!=null)for(let e of i.resources)t.push({path:n.join(a,e.relativePath),scope:h.selectedScope,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})}}for(let e of[`global`,`workspace`]){if(!_.has(e))continue;let r=x(e),i=Cg(yg(y[e],b,`rules`),b),a=n.join(r,this.rulesConfig.subDir??`rules`);for(let r of i)t.push({path:n.join(a,this.buildRuleFileName(r)),scope:e,source:{kind:`rule`,rule:r}})}return i!=null&&this.outputFileName.length>0&&v.has(`global`)&&t.push({path:n.join(this.getGlobalConfigDir(),this.outputFileName),scope:`global`,source:{kind:`globalMemory`,content:i.content}}),t}async buildCommandContent(e){let t=e.content,n=e.yamlFrontMatter,r=!1;if(e.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling command with tool preset`,{file:e.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});let i=new Ag({toolPreset:this.toolPreset}).collect(),a=await cg(e.rawMdxContent,{globalScope:i,extractMetadata:!0,basePath:e.dir.basePath});t=a.content,n=a.metadata.fields,r=!0}let i=this.commandsConfig.transformFrontMatter;if(i==null)throw Error(`commands.transformFrontMatter is required for command output plugin: ${this.name}`);let a=i(e,{isRecompiled:r,...n!=null&&{sourceFrontMatter:n}});return this.buildMarkdownContent(t,a)}buildSubAgentContent(e){let t=this.subAgentsConfig.transformFrontMatter;if(t!=null){let n=t(e,{...e.yamlFrontMatter!=null&&{sourceFrontMatter:e.yamlFrontMatter}});return this.buildMarkdownContent(e.content,n)}return this.buildMarkdownContentWithRaw(e.content,e.yamlFrontMatter,e.rawFrontMatter)}buildSkillMainContent(e){return this.buildMarkdownContentWithRaw(e.content,e.yamlFrontMatter,e.rawFrontMatter)}},m_=class{constructor(e,t,n,r){this.fs=e,this.path=t,this.logger=n,this.globalScope=r}async readDirectoryStructure(e,t,n){let r=[],i=[];if(!this.exists(e))return{prompts:r,errors:i};try{let a=this.fs.readdirSync(e,{withFileTypes:!0});for(let o of a){if(!o.isDirectory())continue;let{name:a}=o,s=this.path.join(e,a),c=this.path.join(t,a);try{let e=await this.readEntry(a,s,c,n,!0);e&&r.push(e)}catch(e){i.push({path:s,error:e,phase:`read`}),this.logger.error(`Failed to read entry: ${a}`,{error:e})}}}catch(t){i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t})}return{prompts:r,errors:i}}async readFlatFiles(e,t,n){let r=[],i=[],a=this.exists(e),o=this.exists(t);if(this.logger.debug(`readFlatFiles: srcDir=${e}, exists=${a}`),this.logger.debug(`readFlatFiles: distDir=${t}, exists=${o}`),!a&&!o)return{prompts:r,errors:i};let s=this.normalizeExtensions(n.localeExtensions.zh),c=new Set,l=async(a,o)=>{if(!c.has(a)){c.add(a);try{let i=await this.readFlatEntry(a,e,t,a,n);i&&r.push(i)}catch(e){i.push({path:o,error:e,phase:`read`}),this.logger.error(`Failed to read file: ${o}`,{error:e})}}},u=async(e,t=``)=>{if(this.exists(e))try{let n=this.fs.readdirSync(e,{withFileTypes:!0});for(let r of n){let n=t?this.path.join(t,r.name):r.name;if(r.isDirectory()){await u(this.path.join(e,r.name),n);continue}let i=this.findMatchingExtension(r.name,s);if(!r.isFile()||i==null)continue;let a=r.name.slice(0,-i.length);await l(t?this.path.join(t,a):a,this.path.join(e,r.name))}}catch(t){i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t})}},d=async(e,t=``)=>{if(this.exists(e))try{let n=this.fs.readdirSync(e,{withFileTypes:!0});for(let r of n){let n=t?this.path.join(t,r.name):r.name;if(r.isDirectory()){await d(this.path.join(e,r.name),n);continue}if(!r.isFile()||!r.name.endsWith(`.mdx`))continue;let i=r.name.slice(0,-4);await l(t?this.path.join(t,i):i,this.path.join(e,r.name))}}catch(t){i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t})}};return a&&await u(e),o&&await d(t),{prompts:r,errors:i}}async readSingleFile(e,t,n){let r=this.path.basename(e);return this.readFlatEntry(r,this.path.dirname(e),this.path.dirname(t),e,n,!0)}async readEntry(e,t,n,r,i=!0){let{localeExtensions:a,entryFileName:o,createPrompt:s,kind:c}=r,l=o??e,u=this.normalizeExtensions(a.zh),d=this.normalizeExtensions(a.en),f=this.resolveLocalizedPath(t,l,u),p=this.resolveLocalizedPath(t,l,d),m=this.path.join(n,`${l}.mdx`),h=await this.readDistContent(m,s,e),g=await this.readLocaleContent(f,`zh`,s,e),_=await this.readLocaleContent(p,`en`,s,e),v=h!=null,y=g!=null,b=_!=null;if(!v&&!y)return this.logger.warn(`Missing both dist and source file for: ${e}`),null;let x=y?{zh:g,...b&&{en:_},default:g,defaultLocale:`zh`}:{zh:h,default:h,defaultLocale:`zh`},S;if(i){let e=v?n:t;S=this.scanChildren(e,l,u)}return{name:e,type:c,src:x,...v&&{dist:h},metadata:{hasDist:v,hasMultipleLocales:b,isDirectoryStructure:i,...S&&S.length>0&&{children:S}},paths:{...(y||!v)&&{zh:f},...b&&{en:p},...v&&{dist:m}}}}async readFlatEntry(e,t,n,r,i,a=!1){let{localeExtensions:o,createPrompt:s,kind:c}=i,l=this.normalizeExtensions(o.zh),u=this.normalizeExtensions(o.en),d=this.resolveLocalizedPath(``,r,l),f=this.resolveLocalizedPath(``,r,u),p=this.path.join(n,`${e}.mdx`),m=a?d:this.path.join(t,d),h=a?f:this.path.join(t,f),g=await this.readDistContent(p,s,e),_=await this.readLocaleContent(m,`zh`,s,e),v=await this.readLocaleContent(h,`en`,s,e),y=g!=null,b=_!=null,x=v!=null;return!y&&!b?(this.logger.warn(`Missing both dist and source file for: ${e}`),null):{name:e,type:c,src:b?{zh:_,...x&&{en:v},default:_,defaultLocale:`zh`}:{zh:g,default:g,defaultLocale:`zh`},...y&&{dist:g},metadata:{hasDist:y,hasMultipleLocales:x,isDirectoryStructure:!1},paths:{...(b||!y)&&{zh:m},...x&&{en:h},...y&&{dist:p}}}}async readLocaleContent(e,t,n,r){if(!this.exists(e))return null;try{let i=this.fs.readFileSync(e,`utf8`),a=this.fs.statSync(e),o=await cg(i,{globalScope:this.globalScope,extractMetadata:!0,basePath:this.path.dirname(e)}),s=Qf(i),c=await n(o.content,t,r,o.metadata.fields),l={content:o.content,lastModified:a.mtime,filePath:e};return i.length>0&&Object.assign(l,{rawMdx:i}),s.yamlFrontMatter!=null&&Object.assign(l,{frontMatter:s.yamlFrontMatter}),c!=null&&Object.assign(l,{prompt:c}),l}catch(t){throw this.logger.error(`Failed to read locale content: ${e}`,{error:t}),t}}async readDistContent(e,t,n){if(!this.exists(e))return null;try{let r=this.fs.readFileSync(e,`utf8`),i=this.fs.statSync(e),a=await cg(r,{globalScope:this.globalScope,extractMetadata:!0,basePath:this.path.dirname(e)}),o=Qf(r),s=await t(a.content,`zh`,n,a.metadata.fields),c={content:a.content,lastModified:i.mtime,prompt:s,filePath:e,rawMdx:r};return o.yamlFrontMatter!=null&&Object.assign(c,{frontMatter:o.yamlFrontMatter}),c}catch(t){return this.logger.warn(`Failed to read dist content: ${e}`,{error:t}),null}}scanChildren(e,t,n){let r=[];if(!this.exists(e))return r;let i=new Set(n.map(e=>`${t}${e}`));try{let t=(e,a)=>{let o=this.fs.readdirSync(e,{withFileTypes:!0});for(let s of o){let o=this.path.join(e,s.name),c=a?this.path.join(a,s.name):s.name;if(s.isDirectory())t(o,c);else{let e=this.findMatchingExtension(s.name,n);if(e==null||i.has(s.name))continue;let t=s.name.slice(0,-e.length),a=this.path.dirname(c),o=a===`.`?t:this.path.join(a,t);r.push(o)}}};t(e,``)}catch(t){this.logger.warn(`Failed to scan children: ${e}`,{error:t})}return r}exists(e){try{return this.fs.existsSync(e)}catch{return!1}}normalizeExtensions(e){return typeof e==`string`?[e]:e}findMatchingExtension(e,t){return t.find(t=>e.endsWith(t))}resolveLocalizedPath(e,t,n){let r=e===``?`${t}${n[0]}`:this.path.join(e,`${t}${n[0]}`);for(let r of n){let n=e===``?`${t}${r}`:this.path.join(e,`${t}${r}`);if(this.exists(n))return n}return r}};function h_(e,t,n,r){return new m_(e,t,n,r)}var g_=class{fs;logger;constructor(e){this.fs=e.fs,this.logger=e.logger}collectMcpServers(e){let t=new Map;for(let n of e)if(n.mcpConfig!=null)for(let[e,r]of Object.entries(n.mcpConfig.mcpServers))t.set(e,r),this.logger.debug(`mcp server collected`,{skill:n.yamlFrontMatter.name,mcpName:e});return t}transformMcpServers(e,t){let n={};for(let[r,i]of e)n[r]=t(i);return n}readExistingConfig(e){try{if(this.fs.existsSync(e)){let t=this.fs.readFileSync(e,`utf8`);return JSON.parse(t)}}catch{this.logger.warn(`failed to read existing mcp config, starting fresh`,{path:e})}return{}}writeCursorMcpConfig(e,t,n){let r=this.readExistingConfig(e);r.mcpServers={...r.mcpServers??{},...t};let i=JSON.stringify(r,null,2);return this.writeConfigFile(e,i,Object.keys(t).length,n)}writeOpencodeMcpConfig(e,t,n,r){let i={...this.readExistingConfig(e),...r,mcp:t},a=JSON.stringify(i,null,2);return this.writeConfigFile(e,a,Object.keys(t).length,n)}writeSkillMcpConfig(e,t,n){return this.writeConfigFile(e,t,1,n)}ensureDirectory(e){this.fs.existsSync(e)||this.fs.mkdirSync(e,{recursive:!0})}writeConfigFile(e,t,r,i){if(i)return this.logger.trace({action:`dryRun`,type:`mcpConfig`,path:e,serverCount:r}),{success:!0,path:e,serverCount:r,skipped:!0};try{return this.ensureDirectory(n.dirname(e)),this.fs.writeFileSync(e,t),this.logger.trace({action:`write`,type:`mcpConfig`,path:e,serverCount:r}),{success:!0,path:e,serverCount:r}}catch(t){let n=t instanceof Error?t.message:String(t);return this.logger.error({action:`write`,type:`mcpConfig`,path:e,error:n}),{success:!1,path:e,serverCount:0,error:t}}}};function __(e){let t={};if(e.command!=null)return t.command=e.command,e.args!=null&&(t.args=e.args),e.env!=null&&(t.env=e.env),t;let n=e,r=n.url??n.serverUrl;if(r==null)return t;t.url=r;let{headers:i}=n;return i!=null&&(t.headers=i),t}function v_(e){let t={};if(e.command!=null){t.type=`local`;let n=[e.command];e.args!=null&&n.push(...e.args),t.command=n,e.env!=null&&(t.environment=e.env)}else{t.type=`remote`;let n=e;n.url==null?n.serverUrl!=null&&(t.url=n.serverUrl):t.url=n.url}return t.enabled=e.disabled!==!0,t}var y_=class extends Error{conflicts;constructor(e){super(D_(e)),this.name=`CleanupProtectionConflictError`,this.conflicts=e}};const b_=[`**/node_modules/**`,`**/.git/**`,`**/.turbo/**`,`**/.pnpm-store/**`,`**/.yarn/**`,`**/.next/**`];function x_(e){return Hp(e).replaceAll(`\\`,`/`)}function S_(e){let{root:t}=n.parse(e);return e===t?e:e.endsWith(n.sep)?e.slice(0,-1):e}function C_(e,t){let r=S_(e),i=S_(t);return r===i?!0:r.startsWith(`${i}${n.sep}`)}function w_(e,t,n){let r=x_(e);return t.glob.sync(r,{onlyFiles:!1,dot:!0,absolute:!0,followSymbolicLinks:!1,ignore:[...n]})}async function T_(e,t){return e.declareCleanupPaths==null?{}:e.declareCleanupPaths({...t,dryRun:!0})}function E_(e,t){let n=new Map,r=[...t.entries()].sort((e,t)=>e[0].length-t[0].length);for(let[e,t]of r){let r=!1;for(let t of n.keys())if(C_(e,t)){r=!0;break}r||n.set(e,t)}let i=[];for(let[t,r]of e){let e=!1;for(let r of n.keys())if(C_(t,r)){e=!0;break}e||i.push(r)}return i.sort((e,t)=>e.localeCompare(t)),{files:i,dirs:[...n.values()].sort((e,t)=>e.localeCompare(t))}}function D_(e){let t=e.map(e=>e.outputPath).join(`, `);return`Cleanup protection conflict: ${e.length} output path(s) are also protected: ${t}`}function O_(e,t){let n=[];for(let[r,i]of e.entries()){let e=new Set(Kp(r));for(let a of t.compiledRules)if(a.comparisonKeys.some(t=>e.has(t)))for(let e of i)n.push({outputPath:r,outputPlugin:e,protectedPath:a.path,protectionMode:a.protectionMode,protectedBy:a.source,reason:a.reason})}return n.sort((e,t)=>{let n=e.outputPath.localeCompare(t.outputPath);return n===0?e.protectedPath.localeCompare(t.protectedPath):n})}function k_(e,t){e.error(`cleanup protection conflict detected`,{count:t.length,conflicts:t.map(e=>({outputPath:e.outputPath,outputPlugin:e.outputPlugin,protectedPath:e.protectedPath,protectionMode:e.protectionMode,protectedBy:e.protectedBy,reason:e.reason}))})}async function A_(e,n){let r=new Set,i=new Set,a=new Map,o=new Set(b_),s=new Map,c=[],l=(e,t)=>{t===`directory`?i.add(Hp(e)):r.add(Hp(e))},u=(e,t,n,r,i=`path`)=>{let o=Hp(e);a.set(`${i}:${t}:${o}`,{path:o,protectionMode:t,reason:n,source:r,matcher:i})},d=e=>e.protectionMode==null?e.kind===`file`?`direct`:`recursive`:e.protectionMode;for(let e of im(n.collectedOutputContext))u(e.path,e.protectionMode,e.reason,e.source);for(let e of n.pluginOptions?.cleanupProtection?.rules??[])u(e.path,e.protectionMode,e.reason??`configured cleanup protection rule`,`configured-cleanup-protection`,e.matcher??`path`);for(let t of e){let e=await t.declareOutputFiles({...n,dryRun:!0});for(let n of e){let e=Hp(n.path);l(e,`file`);let r=s.get(e);r==null?s.set(e,[t.name]):r.includes(t.name)||r.push(t.name)}let r=await T_(t,n);for(let e of r.excludeScanGlobs??[])o.add(x_(e));c.push({plugin:t,cleanup:r})}let f=[...o],p=e=>{for(let r of w_(e.path,n,f))try{t.lstatSync(r).isDirectory()?l(r,`directory`):l(r,`file`)}catch{}},m=(e,t)=>{let r=d(e),i=e.label==null?`plugin cleanup protect declaration`:`plugin cleanup protect declaration (${e.label})`;for(let a of w_(e.path,n,f))u(a,r,i,`plugin-cleanup-protect:${t}`)};for(let{plugin:e,cleanup:t}of c){for(let n of t.protect??[]){if(n.kind===`glob`){m(n,e.name);continue}u(n.path,d(n),n.label==null?`plugin cleanup protect declaration`:`plugin cleanup protect declaration (${n.label})`,`plugin-cleanup-protect:${e.name}`)}for(let e of t.delete??[]){if(e.kind===`glob`){p(e);continue}e.kind===`directory`?l(e.path,`directory`):l(e.path,`file`)}}let h=om({workspaceDir:n.collectedOutputContext.workspace.directory.path,projectRoots:sm(n.collectedOutputContext),rules:[...a.values()],...n.collectedOutputContext.aindexDir==null?{}:{aindexDir:n.collectedOutputContext.aindexDir}}),g=O_(s,h);if(g.length>0)throw new y_(g);let _=um([...r],h),v=um([...i],h),y=E_(new Map(_.safePaths.map(e=>[e,e])),new Map(v.safePaths.map(e=>[e,e])));return{filesToDelete:y.files,dirsToDelete:y.dirs,violations:[..._.violations,...v.violations].sort((e,t)=>e.targetPath.localeCompare(t.targetPath)),conflicts:[],excludedScanGlobs:[...o].sort((e,t)=>e.localeCompare(t))}}function j_(e,t){let r=e.map(e=>n.isAbsolute(e)?e:n.resolve(e)),i=ot(r);for(let e of r)i.errors.some(t=>t.path===e)||t.debug({action:`delete`,type:`file`,path:e});let a=i.errors.map(e=>{let n=e.error instanceof Error?e.error.message:String(e.error);return t.warn(`failed to delete file`,{path:e.path,error:n}),{path:e.path,type:`file`,error:e.error}});return{deleted:i.deleted,errors:a}}function M_(e,t){let r=e.map(e=>n.isAbsolute(e)?e:n.resolve(e)),i=st(r);for(let e of r)i.errors.some(t=>t.path===e)||t.debug({action:`delete`,type:`directory`,path:e});let a=i.errors.map(e=>{let n=e.error instanceof Error?e.error.message:String(e.error);return t.warn(`failed to delete directory`,{path:e.path,error:n}),{path:e.path,type:`directory`,error:e.error}});return{deleted:i.deleted,errors:a}}function N_(e,t){e.debug(`cleanup plan built`,{filesToDelete:t.filesToDelete.length,dirsToDelete:t.dirsToDelete.length,violations:t.violations.length,conflicts:t.conflicts.length,excludedScanGlobs:t.excludedScanGlobs})}async function P_(e,t,n){let r=await u_(e,t);n.debug(`Collected outputs for cleanup`,{projectDirs:r.projectDirs.length,projectFiles:r.projectFiles.length,workspaceDirs:r.workspaceDirs.length,workspaceFiles:r.workspaceFiles.length,globalDirs:r.globalDirs.length,globalFiles:r.globalFiles.length});let i;try{i=await A_(e,t)}catch(e){if(e instanceof y_)return k_(n,e.conflicts),{deletedFiles:0,deletedDirs:0,errors:[],violations:[],conflicts:e.conflicts,message:e.message};throw e}let a={filesToDelete:i.filesToDelete,dirsToDelete:i.dirsToDelete,violations:i.violations,conflicts:i.conflicts,excludedScanGlobs:i.excludedScanGlobs};if(N_(n,a),a.violations.length>0)return fm(n,`cleanup`,a.violations),{deletedFiles:0,deletedDirs:0,errors:[],violations:a.violations,conflicts:[],message:`Protected deletion guard blocked cleanup for ${a.violations.length} path(s)`};let o=j_(a.filesToDelete,n),s=M_(a.dirsToDelete,n);return{deletedFiles:o.deleted,deletedDirs:s.deleted,errors:[...o.errors,...s.errors],violations:[],conflicts:[]}}var F_=class{name=`clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`clean`});let i=await P_(n,r(!1),t);return i.violations.length>0||i.conflicts.length>0?{success:!1,filesAffected:0,dirsAffected:0,...i.message==null?{}:{message:i.message}}:(t.info(`clean complete`,{deletedFiles:i.deletedFiles,deletedDirs:i.deletedDirs}),{success:!0,filesAffected:i.deletedFiles,dirsAffected:i.deletedDirs})}},I_=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`dry-run-clean`,dryRun:!0});let i=r(!0),a=await u_(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,workspaceDirs:a.workspaceDirs.length,workspaceFiles:a.workspaceFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s,violations:c,excludedScanGlobs:l}=await A_(n,i);return c.length>0?(fm(t,`dry-run-cleanup`,c),{success:!1,filesAffected:0,dirsAffected:0,message:`Protected deletion guard blocked cleanup for ${c.length} path(s)`}):(this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length,violations:0,excludedScanGlobs:l}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`})}logDryRunFiles(e,t){for(let r of e){let e=n.isAbsolute(r)?r:n.resolve(r);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let r=[...e].sort((e,t)=>t.length-e.length);for(let e of r){let r=n.isAbsolute(e)?e:n.resolve(e);t.info(`would delete directory`,{path:r,dryRun:!0})}}},L_=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`started`,{command:`dry-run-output`,dryRun:!0});let i=await l_(n,r(!0)),a=0,o=0;for(let[e,n]of i)a+=n.files.length,o+=n.dirs.length,t.info(`plugin result`,{plugin:e,files:n.files.length,dirs:n.dirs.length,dryRun:!0});return t.info(`complete`,{command:`dry-run-output`,totalFiles:a,totalDirs:o,dryRun:!0}),{success:!0,filesAffected:a,dirsAffected:o,message:`Dry-run complete, no files were written`}}},R_=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await P_(n,r(!1),t);if(a.violations.length>0||a.conflicts.length>0)return{success:!1,filesAffected:0,dirsAffected:0,...a.message==null?{}:{message:a.message}};t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=await l_(n,i(!1)),s=0,c=0,l=[];for(let e of o.values()){s+=e.files.length,c+=e.dirs.length;for(let t of e.files)t.success||l.push(t.error?.message??`Failed to write ${t.path}`)}return l.length>0?{success:!1,filesAffected:s,dirsAffected:c,message:l.join(`
|
|
98
|
-
`)}:(t.info(`complete`,{command:`execute`,pluginCount:o.size}),{success:!0,filesAffected:s,dirsAffected:c})}},z_=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),n=B_(t);return o.stdout.write(`${JSON.stringify(n)}\n`),t}};function B_(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:e.success||e.message==null?[]:[e.message]}}var V_=class{name=`plugins`;async execute(e){let{logger:t,outputPlugins:n,userConfigOptions:r}=e,i=r.plugins,a=[];for(let e of i)a.push({name:e.name,kind:e.type===fp.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let s=new Set(a.map(e=>e.name));for(let e of n)s.has(e.name)||a.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return o.stdout.write(`${JSON.stringify(a)}\n`),t.info(`plugins listed`,{count:a.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Listed ${a.length} plugin(s)`}}};function H_(e){let t=e.slice(2),n=`execute`,r=!1,i=!1;for(let e of t)e===`--json`||e===`-j`?r=!0:e===`--dry-run`||e===`-n`?i=!0:e.startsWith(`-`)||(n=e);return{subcommand:n,json:r,dryRun:i}}function U_(e,t){switch(e){case`execute`:return new R_;case`dry-run`:return new L_;case`clean`:return t?new I_:new F_;case`plugins`:return new V_;default:return new R_}}async function W_(){let{subcommand:e,json:r,dryRun:i}=H_(o.argv);r&&Om(`silent`);let{default:a}=await import(`./plugin.config-PD_T1uuL.mjs`),s=await a,c=U_(e,i);r&&(new Set([`plugins`]).has(c.name)||(c=new z_(c)));let{context:l,outputPlugins:u,userConfigOptions:d}=s,f=km(`PluginRuntime`),p=e=>({logger:f,fs:t,path:n,glob:nt.default,collectedOutputContext:l,pluginOptions:d,dryRun:e}),m=e=>({logger:f,fs:t,path:n,glob:nt.default,collectedOutputContext:l,dryRun:e,registeredPluginNames:[...u].map(e=>e.name)}),h={logger:f,outputPlugins:[...u],collectedOutputContext:l,userConfigOptions:d,createCleanContext:p,createWriteContext:m};(await c.execute(h)).success||o.exit(1)}function G_(e){o.stdout.write(`${JSON.stringify({success:!1,filesAffected:0,dirsAffected:0,message:e,pluginResults:[],errors:[e]})}\n`)}W_().catch(e=>{let t=e instanceof Error?e.message:String(e),{json:n}=H_(o.argv);n&&(G_(t),o.exit(1)),km(`plugin-runtime`,`error`).error(`unhandled error`,{error:t}),o.exit(1)});export{hp as $,Hm as A,km as B,yg as C,cg as D,wg as E,Mm as F,um as G,Np as H,Vm as I,vp as J,bp as K,Lm as L,Bm as M,Nm as N,Km as O,Pm as P,gp as Q,Im as R,Cg as S,Eg as T,rm as U,Om as V,om as W,Ap as X,Mp as Y,mp as Z,$g as _,I_ as a,$f as at,jg as b,__ as c,w as ct,p_ as d,fp as et,f_ as f,e_ as g,t_ as h,L_ as i,Qf as it,zm as j,Um as k,v_ as l,c_ as m,z_ as n,Jf as nt,F_ as o,it as ot,d_ as p,yp as q,R_ as r,Zf as rt,g_ as s,tt as st,V_ as t,pp as tt,h_ as u,Xg as v,Tg as w,Mg as x,Ag as y,Rm as z};
|
|
99
|
+
`,skipIfEmpty:i=!0,position:a=`before`}=n??{};if(i&&(e==null||e.trim().length===0))return t;let o=e??``;return a===`after`?`${t}${r}${o}`:`${o}${r}${t}`}transformCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.commandPrefix==null?`${e.commandName}.md`:`${e.commandPrefix}${r}${e.commandName}.md`}transformSubAgentName(e,t){let n=t?.includePrefix??this.subAgentsConfig.includePrefix,r=t?.linkSymbol??this.subAgentsConfig.linkSymbol,i=t?.ext??this.subAgentsConfig.ext,a=i.startsWith(`.`)?i:`.${i}`;return n&&e.agentPrefix!=null&&e.agentPrefix.length>0?`${e.agentPrefix}${r}${e.agentName}${a}`:`${e.agentName}${a}`}getCommandSeriesOptions(e){let t=e.pluginOptions?.commandSeriesOptions,n=t?.pluginOverrides?.[this.name],r=n?.includeSeriesPrefix??t?.includeSeriesPrefix,i=n?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}getTransformOptionsFromContext(e,t){let n=this.getCommandSeriesOptions(e),r=n.includeSeriesPrefix??t?.includeSeriesPrefix,i=n.seriesSeparator??t?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}shouldSkipDueToPlugin(e,t){let n=e.registeredPluginNames;return n==null?!1:n.includes(t)}getRegistryWriter(e){let t=e.name,n=this.registryWriterCache.get(t);if(n!=null)return n;let r=new e(this.log);return this.registryWriterCache.set(t,r),r}async registerInRegistry(e,t,n){return e.register(t,n.dryRun)}normalizeRuleScope(e){return e.scope??`project`}normalizeSourceScope(e){return e===`workspace`||e===`global`||e===`project`?e:`project`}resolveCommandSourceScope(e){if(e.globalOnly===!0)return`global`;let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}resolveSubAgentSourceScope(e){let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}resolveSkillSourceScope(e){let t=e.yamlFrontMatter?.scope;return this.normalizeSourceScope(t)}selectSingleScopeItems(e,t,n,r){if(e.length===0)return{items:[]};let[i]=$g({requestedScopes:r,defaultScopes:t,supportedScopes:t,singleScope:!0,availableScopes:[...new Set(e.map(n))]});return i==null?{items:[]}:{selectedScope:i,items:e.filter(e=>n(e)===i)}}selectRuleScopes(e,t){let n=[...new Set(t.map(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))))];return $g({requestedScopes:this.getTopicScopeOverride(e,`rules`),defaultScopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],supportedScopes:this.rulesConfig.sourceScopes??[`project`,`workspace`,`global`],singleScope:!1,availableScopes:n})}selectPromptScopes(e,t=[`project`,`global`],n=t){return $g({requestedScopes:this.getTopicScopeOverride(e,`prompt`),defaultScopes:n,supportedScopes:t,singleScope:!1})}getTopicScopeOverride(e,t){return e.pluginOptions?.outputScopes?.plugins?.[this.name]?.[t]}buildSkillFrontMatter(e,t){let n=e.yamlFrontMatter,r={name:n.name,description:n.description};return`displayName`in n&&n.displayName!=null&&(r.displayName=n.displayName),`keywords`in n&&n.keywords!=null&&n.keywords.length>0&&(r.keywords=n.keywords),`author`in n&&n.author!=null&&(r.author=n.author),`version`in n&&n.version!=null&&(r.version=n.version),(t?.includeTools??!0)&&`allowTools`in n&&n.allowTools!=null&&n.allowTools.length>0&&(r.allowTools=(t?.toolFormat??`array`)===`string`?n.allowTools.join(`,`):n.allowTools),t?.additionalFields!=null&&Object.assign(r,t.additionalFields),r}buildRuleContent(e){let t=this.rulesConfig.transformFrontMatter?this.rulesConfig.transformFrontMatter(e):{globs:e.globs.join(`, `)};return Jf(t==null||Object.keys(t).length===0?void 0:t,e.content)}buildRuleFileName(e){let t=`${`${this.rulesConfig.prefix??`rule`}${this.rulesConfig.linkSymbol??`-`}`}${e.prefix}${this.rulesConfig.linkSymbol??`-`}${e.ruleName}${this.rulesConfig.ext??`.md`}`;return this.log.trace(`buildRuleFileName`,{plugin:this.name,rulePrefix:e.prefix,ruleName:e.ruleName,prefix:this.rulesConfig.prefix??`rule`,linkSymbol:this.rulesConfig.linkSymbol??`-`,ext:this.rulesConfig.ext??`.md`,result:t}),t}async declareOutputFiles(e){return this.buildDefaultOutputDeclarations(e)}async declareCleanupPaths(e){let t=this.buildCleanupTargetsFromScopeConfig(this.cleanupConfig.delete,`delete`,e),n=this.buildCleanupTargetsFromScopeConfig(this.cleanupConfig.protect,`protect`,e),{excludeScanGlobs:r}=this.cleanupConfig;return t.length===0&&n.length===0&&(r==null||r.length===0)?{}:{...t.length>0&&{delete:t},...n.length>0&&{protect:n},...r!=null&&r.length>0&&{excludeScanGlobs:r}}}async convertContent(e,t){let n=e.source;switch(n.kind){case`projectRootMemory`:case`projectChildMemory`:case`globalMemory`:case`skillReference`:case`ignoreFile`:return n.content;case`command`:return this.buildCommandContent(n.command);case`subAgent`:return this.buildSubAgentContent(n.subAgent);case`skillMain`:return this.buildSkillMainContent(n.skill);case`skillResource`:return n.encoding===`base64`?p.from(n.content,`base64`):n.content;case`rule`:return this.buildRuleContent(n.rule);default:throw Error(`Unsupported declaration source for plugin ${this.name}`)}}async buildDefaultOutputDeclarations(e){let t=[],{workspace:r,globalMemory:i,commands:a,subAgents:o,skills:s,rules:c,aiAgentIgnoreConfigFiles:l}=e.collectedOutputContext,u=this.getTransformOptionsFromContext(e),d=this.getIgnoreOutputPath(),f=this.indexignore==null?void 0:l?.find(e=>e.fileName===this.indexignore),p=this.commandOutputEnabled&&a!=null?this.selectSingleScopeItems(a,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)):{items:[]},m=this.subAgentOutputEnabled&&o!=null?this.selectSingleScopeItems(o,this.subAgentsConfig.sourceScopes,e=>this.resolveSubAgentSourceScope(e),this.getTopicScopeOverride(e,`subagents`)):{items:[]},h=this.skillOutputEnabled&&s!=null?this.selectSingleScopeItems(s,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)):{items:[]},g=c??[],_=this.ruleOutputEnabled&&g.length>0?new Set(this.selectRuleScopes(e,g)):new Set,v=new Set(this.selectPromptScopes(e)),y={project:[],workspace:[],global:[]};for(let e of g)y[this.normalizeSourceScope(this.normalizeRuleScope(e))].push(e);for(let e of r.projects){let r=e.dirFromWorkspacePath;if(r==null)continue;if(this.outputFileName.length>0&&v.has(`project`)&&(e.rootMemoryPrompt!=null&&t.push({path:this.resolveFullPath(r),scope:`project`,source:{kind:`projectRootMemory`,content:e.rootMemoryPrompt.content}}),e.childMemoryPrompts!=null))for(let n of e.childMemoryPrompts)t.push({path:this.resolveFullPath(n.dir),scope:`project`,source:{kind:`projectChildMemory`,content:n.content}});let i=n.join(r.basePath,r.path,this.globalConfigDir),{projectConfig:a}=e;if(p.selectedScope===`project`&&p.items.length>0){let e=Ig(p.items,a,`commands`);for(let r of e){let e=this.transformCommandName(r,u);t.push({path:n.join(i,this.commandsConfig.subDir,e),scope:`project`,source:{kind:`command`,command:r}})}}if(m.selectedScope===`project`&&m.items.length>0){let e=Ig(m.items,a,`subAgents`);for(let r of e){let e=this.transformSubAgentName(r);t.push({path:n.join(i,this.subAgentsConfig.subDir,e),scope:`project`,source:{kind:`subAgent`,subAgent:r}})}}if(h.selectedScope===`project`&&h.items.length>0){let e=Ig(h.items,a,`skills`);for(let r of e){let e=r.yamlFrontMatter?.name??r.dir.getDirectoryName(),a=n.join(i,this.skillsConfig.subDir,e);if(t.push({path:n.join(a,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:r}}),r.childDocs!=null)for(let e of r.childDocs)t.push({path:n.join(a,e.dir.path.replace(/\.mdx$/,`.md`)),scope:`project`,source:{kind:`skillReference`,content:e.content}});if(r.resources!=null)for(let e of r.resources)t.push({path:n.join(a,e.relativePath),scope:`project`,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})}}if(_.has(`project`)){let e=Bg(Ig(y.project,a,`rules`),a),r=n.join(i,this.rulesConfig.subDir??`rules`);for(let i of e)t.push({path:n.join(r,this.buildRuleFileName(i)),scope:`project`,source:{kind:`rule`,rule:i}})}d!=null&&f!=null&&e.isPromptSourceProject!==!0&&t.push({path:n.join(r.basePath,r.path,d),scope:`project`,source:{kind:`ignoreFile`,content:f.content}})}let b=this.resolvePromptSourceProjectConfig(e),x=t=>t===`global`?this.getGlobalConfigDir():this.getWorkspaceConfigDir(e);if((p.selectedScope===`global`||p.selectedScope===`workspace`)&&p.items.length>0){let e=Ig(p.items,b,`commands`),r=x(p.selectedScope);for(let i of e){let e=this.transformCommandName(i,u);t.push({path:n.join(r,this.commandsConfig.subDir,e),scope:p.selectedScope,source:{kind:`command`,command:i}})}}if((m.selectedScope===`global`||m.selectedScope===`workspace`)&&m.items.length>0){let e=Ig(m.items,b,`subAgents`),r=x(m.selectedScope);for(let i of e){let e=this.transformSubAgentName(i);t.push({path:n.join(r,this.subAgentsConfig.subDir,e),scope:m.selectedScope,source:{kind:`subAgent`,subAgent:i}})}}if((h.selectedScope===`global`||h.selectedScope===`workspace`)&&h.items.length>0){let e=Ig(h.items,b,`skills`),r=x(h.selectedScope);for(let i of e){let e=i.yamlFrontMatter?.name??i.dir.getDirectoryName(),a=n.join(r,this.skillsConfig.subDir,e);if(t.push({path:n.join(a,`SKILL.md`),scope:h.selectedScope,source:{kind:`skillMain`,skill:i}}),i.childDocs!=null)for(let e of i.childDocs)t.push({path:n.join(a,e.dir.path.replace(/\.mdx$/,`.md`)),scope:h.selectedScope,source:{kind:`skillReference`,content:e.content}});if(i.resources!=null)for(let e of i.resources)t.push({path:n.join(a,e.relativePath),scope:h.selectedScope,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})}}for(let e of[`global`,`workspace`]){if(!_.has(e))continue;let r=x(e),i=Bg(Ig(y[e],b,`rules`),b),a=n.join(r,this.rulesConfig.subDir??`rules`);for(let r of i)t.push({path:n.join(a,this.buildRuleFileName(r)),scope:e,source:{kind:`rule`,rule:r}})}return i!=null&&this.outputFileName.length>0&&v.has(`global`)&&t.push({path:n.join(this.getGlobalConfigDir(),this.outputFileName),scope:`global`,source:{kind:`globalMemory`,content:i.content}}),t}async buildCommandContent(e){let t=e.content,n=e.yamlFrontMatter,r=!1;if(e.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling command with tool preset`,{file:e.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});let i=new qg({toolPreset:this.toolPreset}).collect(),a=await wg(e.rawMdxContent,{globalScope:i,extractMetadata:!0,basePath:e.dir.basePath,filePath:e.dir.getAbsolutePath()});t=a.content,n=a.metadata.fields,r=!0}let i=this.commandsConfig.transformFrontMatter;if(i==null)throw Error(`commands.transformFrontMatter is required for command output plugin: ${this.name}`);let a=i(e,{isRecompiled:r,...n!=null&&{sourceFrontMatter:n}});return this.buildMarkdownContent(t,a)}buildSubAgentContent(e){let t=this.subAgentsConfig.transformFrontMatter;if(t!=null){let n=t(e,{...e.yamlFrontMatter!=null&&{sourceFrontMatter:e.yamlFrontMatter}});return this.buildMarkdownContent(e.content,n)}return this.buildMarkdownContentWithRaw(e.content,e.yamlFrontMatter,e.rawFrontMatter)}buildSkillMainContent(e){return this.buildMarkdownContentWithRaw(e.content,e.yamlFrontMatter,e.rawFrontMatter)}},A_=class extends Error{kind;nameOfPrompt;sourcePath;expectedDistPath;constructor(e){let{kind:t,name:n,sourcePath:r,expectedDistPath:i}=e;super([`Missing compiled dist prompt for ${t} "${n}".`,...r==null?[]:[`source: ${r}`],`expected dist: ${i}`].join(` `)),this.name=`MissingCompiledPromptError`,this.kind=t,this.nameOfPrompt=n,r!=null&&(this.sourcePath=r),this.expectedDistPath=i}},j_=class extends Error{filePath;lineNumber;constructor(e,t,n){super(`Compiled prompt still contains residual module syntax at ${e}:${t}: ${n.trim()}`),this.name=`ResidualModuleSyntaxError`,this.filePath=e,this.lineNumber=t}};const M_=/^\s*(```|~~~)/u,N_=[/^\s*export\s+default\b/u,/^\s*export\s+const\b/u,/^\s*import\b/u];function P_(e,t){let n,r=e.split(/\r?\n/u);for(let[e,i]of r.entries()){let r=M_.exec(i);if(r?.[1]!=null){let e=r[1];n==null?n=e:n===e&&(n=void 0);continue}if(n==null&&N_.some(e=>e.test(i)))throw new j_(t,e+1,i)}}function F_(e,t,n={}){let{preferredSourcePath:r,distRootDir:i,srcRootDir:a}=n;if(t==null||t.length===0||r!=null&&r.length>0)return r;if(i==null||a==null)return;let o=e.relative(i,t);if(!(o.startsWith(`..`)||e.isAbsolute(o)))return e.join(a,o.replace(/\.mdx$/u,`.src.mdx`))}function I_(e){if(e instanceof Xm&&e.filePath!=null)return e.filePath;if(!(e instanceof Error)||!(`filePath`in e))return;let{filePath:t}=e;if(typeof t==`string`&&t.length>0)return t}function L_(e,t){let n=I_(e)??t.distPath,r=[t.operation??`Prompt compilation failed.`,`prompt kind: ${t.promptKind}`,`logical name: ${t.logicalName}`];return t.entryDistPath!=null&&t.entryDistPath.length>0&&t.entryDistPath!==n&&r.push(`entry dist file: ${t.entryDistPath}`),n!=null&&n.length>0&&r.push(`dist file: ${n}`),r.push(`src file: ${t.srcPath??`<unresolved>`}`),r.push(`diagnostic:`),r.push(e instanceof Error?Ym(e):String(e)),r.join(`
|
|
100
|
+
`)}function R_(e){return e instanceof A_||e instanceof j_}var z_=class{constructor(e,t,n,r){this.fs=e,this.path=t,this.logger=n,this.globalScope=r}async readDirectoryStructure(e,t,n){let r=[],i=[];if(!this.exists(e))return{prompts:r,errors:i};try{let a=this.fs.readdirSync(e,{withFileTypes:!0});for(let o of a){if(!o.isDirectory())continue;let{name:a}=o,s=this.path.join(e,a),c=this.path.join(t,a);try{let e=await this.readEntry(a,s,c,n,!0);e&&r.push(e)}catch(e){if(i.push({path:s,error:e,phase:`read`}),this.logger.error(`Failed to read entry: ${a}`,{error:e}),R_(e))throw e}}}catch(t){if(i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t}),R_(t))throw t}return{prompts:r,errors:i}}async readFlatFiles(e,t,n){let r=[],i=[],a=this.exists(e),o=this.exists(t);if(this.logger.debug(`readFlatFiles: srcDir=${e}, exists=${a}`),this.logger.debug(`readFlatFiles: distDir=${t}, exists=${o}`),!a&&!o)return{prompts:r,errors:i};let s=this.normalizeExtensions(n.localeExtensions.zh),c=new Set,l=async(a,o)=>{if(!c.has(a)){c.add(a);try{let i=await this.readFlatEntry(a,e,t,a,n);i&&r.push(i)}catch(e){if(i.push({path:o,error:e,phase:`read`}),this.logger.error(`Failed to read file: ${o}`,{error:e}),R_(e))throw e}}},u=async(e,t=``)=>{if(this.exists(e))try{let n=this.fs.readdirSync(e,{withFileTypes:!0});for(let r of n){let n=t?this.path.join(t,r.name):r.name;if(r.isDirectory()){await u(this.path.join(e,r.name),n);continue}let i=this.findMatchingExtension(r.name,s);if(!r.isFile()||i==null)continue;let a=r.name.slice(0,-i.length);await l(t?this.path.join(t,a):a,this.path.join(e,r.name))}}catch(t){if(i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t}),R_(t))throw t}},d=async(e,t=``)=>{if(this.exists(e))try{let n=this.fs.readdirSync(e,{withFileTypes:!0});for(let r of n){let n=t?this.path.join(t,r.name):r.name;if(r.isDirectory()){await d(this.path.join(e,r.name),n);continue}if(!r.isFile()||!r.name.endsWith(`.mdx`))continue;let i=r.name.slice(0,-4);await l(t?this.path.join(t,i):i,this.path.join(e,r.name))}}catch(t){if(i.push({path:e,error:t,phase:`scan`}),this.logger.error(`Failed to scan directory: ${e}`,{error:t}),R_(t))throw t}};return a&&await u(e),o&&await d(t),{prompts:r,errors:i}}async readSingleFile(e,t,n){let r=this.path.basename(e);return this.readFlatEntry(r,this.path.dirname(e),this.path.dirname(t),e,n,!0)}async readEntry(e,t,n,r,i=!0){let{localeExtensions:a,entryFileName:o,createPrompt:s,kind:c}=r,l=o??e,u=this.normalizeExtensions(a.zh),d=this.normalizeExtensions(a.en),f=this.resolveLocalizedPath(t,l,u),p=this.resolveLocalizedPath(t,l,d),m=this.path.join(n,`${l}.mdx`),h=this.exists(f)?f:this.exists(p)?p:void 0,g={promptKind:String(c),logicalName:e,entryDistPath:m,...h!=null&&{srcPath:h}},_=await this.readDistContent(m,s,e,g),v=await this.readLocaleContent(f,`zh`,s,e),y=await this.readLocaleContent(p,`en`,s,e),b=_!=null,x=v!=null,S=y!=null,C=x?f:S?p:void 0;if(!b&&!x&&!S)return this.logger.warn(`Missing both dist and source file for: ${e}`),null;if(!b)throw new A_({kind:String(c),name:e,...C!=null&&{sourcePath:C},expectedDistPath:m});let w=x?{zh:v,...S&&{en:y},default:v,defaultLocale:`zh`}:void 0,T=i?this.scanChildren(n,l,[`.mdx`]):void 0;return{name:e,type:c,...w!=null&&{src:w},...b&&{dist:_},metadata:{hasDist:b,hasMultipleLocales:S,isDirectoryStructure:i,...T&&T.length>0&&{children:T}},paths:{...x&&{zh:f},...S&&{en:p},...b&&{dist:m}}}}async readFlatEntry(e,t,n,r,i,a=!1){let{localeExtensions:o,createPrompt:s,kind:c}=i,l=this.normalizeExtensions(o.zh),u=this.normalizeExtensions(o.en),d=this.resolveLocalizedPath(``,r,l),f=this.resolveLocalizedPath(``,r,u),p=this.path.join(n,`${e}.mdx`),m=a?d:this.path.join(t,d),h=a?f:this.path.join(t,f),g=this.exists(m)?m:this.exists(h)?h:void 0,_={promptKind:String(c),logicalName:e,entryDistPath:p,...g!=null&&{srcPath:g}},v=await this.readDistContent(p,s,e,_),y=await this.readLocaleContent(m,`zh`,s,e),b=await this.readLocaleContent(h,`en`,s,e),x=v!=null,S=y!=null,C=b!=null,w=S?m:C?h:void 0;if(!x&&!S&&!C)return this.logger.warn(`Missing both dist and source file for: ${e}`),null;if(!x)throw new A_({kind:String(c),name:e,...w!=null&&{sourcePath:w},expectedDistPath:p});let T=S?{zh:y,...C&&{en:b},default:y,defaultLocale:`zh`}:void 0;return{name:e,type:c,...T!=null&&{src:T},...x&&{dist:v},metadata:{hasDist:x,hasMultipleLocales:C,isDirectoryStructure:!1},paths:{...S&&{zh:m},...C&&{en:h},...x&&{dist:p}}}}async readLocaleContent(e,t,n,r){if(!this.exists(e))return null;try{let i=this.fs.readFileSync(e,`utf8`),a=this.fs.statSync(e),o=await wg(i,{globalScope:this.globalScope,extractMetadata:!0,basePath:this.path.dirname(e),filePath:e});P_(o.content,e);let s=Qf(i),c=await n(o.content,t,r,o.metadata.fields),l={content:o.content,lastModified:a.mtime,filePath:e};return i.length>0&&Object.assign(l,{rawMdx:i}),s.yamlFrontMatter!=null&&Object.assign(l,{frontMatter:s.yamlFrontMatter}),c!=null&&Object.assign(l,{prompt:c}),l}catch(t){throw this.logger.error(`Failed to read locale content: ${e}`,{error:t}),t}}async readDistContent(e,t,n,r){if(!this.exists(e))return null;try{let r=this.fs.readFileSync(e,`utf8`),i=this.fs.statSync(e),a=await wg(r,{globalScope:this.globalScope,extractMetadata:!0,basePath:this.path.dirname(e),filePath:e});P_(a.content,e);let o=Qf(r),s=await t(a.content,`zh`,n,a.metadata.fields),c={content:a.content,lastModified:i.mtime,prompt:s,filePath:e,rawMdx:r};return o.yamlFrontMatter!=null&&Object.assign(c,{frontMatter:o.yamlFrontMatter}),c}catch(t){throw this.logger.error(this.formatDistReadError(t,e,r),{error:t}),t}}formatDistReadError(e,t,n){let r=F_(this.path,t,{preferredSourcePath:t===n.entryDistPath?n.srcPath:void 0,distRootDir:this.path.dirname(n.entryDistPath),srcRootDir:n.srcPath==null?void 0:this.path.dirname(n.srcPath)});return L_(e,{operation:`Failed to read dist content.`,promptKind:n.promptKind,logicalName:n.logicalName,entryDistPath:n.entryDistPath,distPath:t,srcPath:r})}scanChildren(e,t,n){let r=[];if(!this.exists(e))return r;let i=new Set(n.map(e=>`${t}${e}`));try{let t=(e,a)=>{let o=this.fs.readdirSync(e,{withFileTypes:!0});for(let s of o){let o=this.path.join(e,s.name),c=a?this.path.join(a,s.name):s.name;if(s.isDirectory())t(o,c);else{let e=this.findMatchingExtension(s.name,n);if(e==null||i.has(s.name))continue;let t=s.name.slice(0,-e.length),a=this.path.dirname(c),o=a===`.`?t:this.path.join(a,t);r.push(o)}}};t(e,``)}catch(t){this.logger.warn(`Failed to scan children: ${e}`,{error:t})}return r}exists(e){try{return this.fs.existsSync(e)}catch{return!1}}normalizeExtensions(e){return typeof e==`string`?[e]:e}findMatchingExtension(e,t){return t.find(t=>e.endsWith(t))}resolveLocalizedPath(e,t,n){let r=e===``?`${t}${n[0]}`:this.path.join(e,`${t}${n[0]}`);for(let r of n){let n=e===``?`${t}${r}`:this.path.join(e,`${t}${r}`);if(this.exists(n))return n}return r}};function B_(e,t,n,r){return new z_(e,t,n,r)}var V_=class{fs;logger;constructor(e){this.fs=e.fs,this.logger=e.logger}collectMcpServers(e){let t=new Map;for(let n of e)if(n.mcpConfig!=null)for(let[e,r]of Object.entries(n.mcpConfig.mcpServers))t.set(e,r),this.logger.debug(`mcp server collected`,{skill:n.yamlFrontMatter.name,mcpName:e});return t}transformMcpServers(e,t){let n={};for(let[r,i]of e)n[r]=t(i);return n}readExistingConfig(e){try{if(this.fs.existsSync(e)){let t=this.fs.readFileSync(e,`utf8`);return JSON.parse(t)}}catch{this.logger.warn(`failed to read existing mcp config, starting fresh`,{path:e})}return{}}writeCursorMcpConfig(e,t,n){let r=this.readExistingConfig(e);r.mcpServers={...r.mcpServers??{},...t};let i=JSON.stringify(r,null,2);return this.writeConfigFile(e,i,Object.keys(t).length,n)}writeOpencodeMcpConfig(e,t,n,r){let i={...this.readExistingConfig(e),...r,mcp:t},a=JSON.stringify(i,null,2);return this.writeConfigFile(e,a,Object.keys(t).length,n)}writeSkillMcpConfig(e,t,n){return this.writeConfigFile(e,t,1,n)}ensureDirectory(e){this.fs.existsSync(e)||this.fs.mkdirSync(e,{recursive:!0})}writeConfigFile(e,t,r,i){if(i)return this.logger.trace({action:`dryRun`,type:`mcpConfig`,path:e,serverCount:r}),{success:!0,path:e,serverCount:r,skipped:!0};try{return this.ensureDirectory(n.dirname(e)),this.fs.writeFileSync(e,t),this.logger.trace({action:`write`,type:`mcpConfig`,path:e,serverCount:r}),{success:!0,path:e,serverCount:r}}catch(t){let n=t instanceof Error?t.message:String(t);return this.logger.error({action:`write`,type:`mcpConfig`,path:e,error:n}),{success:!1,path:e,serverCount:0,error:t}}}};function H_(e){let t={};if(e.command!=null)return t.command=e.command,e.args!=null&&(t.args=e.args),e.env!=null&&(t.env=e.env),t;let n=e,r=n.url??n.serverUrl;if(r==null)return t;t.url=r;let{headers:i}=n;return i!=null&&(t.headers=i),t}function U_(e){let t={};if(e.command!=null){t.type=`local`;let n=[e.command];e.args!=null&&n.push(...e.args),t.command=n,e.env!=null&&(t.environment=e.env)}else{t.type=`remote`;let n=e;n.url==null?n.serverUrl!=null&&(t.url=n.serverUrl):t.url=n.url}return t.enabled=e.disabled!==!0,t}var W_=class extends Error{conflicts;constructor(e){super(Q_(e)),this.name=`CleanupProtectionConflictError`,this.conflicts=e}};const G_=[`**/node_modules/**`,`**/.git/**`,`**/.turbo/**`,`**/.pnpm-store/**`,`**/.yarn/**`,`**/.next/**`];function K_(e){return Hp(e).replaceAll(`\\`,`/`)}function q_(e){let{root:t}=n.parse(e);return e===t?e:e.endsWith(n.sep)?e.slice(0,-1):e}function J_(e,t){let r=q_(e),i=q_(t);return r===i?!0:r.startsWith(`${i}${n.sep}`)}function Y_(e,t,n){let r=K_(e);return t.glob.sync(r,{onlyFiles:!1,dot:!0,absolute:!0,followSymbolicLinks:!1,ignore:[...n]})}async function X_(e,t){return e.declareCleanupPaths==null?{}:e.declareCleanupPaths({...t,dryRun:!0})}function Z_(e,t){let n=new Map,r=[...t.entries()].sort((e,t)=>e[0].length-t[0].length);for(let[e,t]of r){let r=!1;for(let t of n.keys())if(J_(e,t)){r=!0;break}r||n.set(e,t)}let i=[];for(let[t,r]of e){let e=!1;for(let r of n.keys())if(J_(t,r)){e=!0;break}e||i.push(r)}return i.sort((e,t)=>e.localeCompare(t)),{files:i,dirs:[...n.values()].sort((e,t)=>e.localeCompare(t))}}function Q_(e){let t=e.map(e=>e.outputPath).join(`, `);return`Cleanup protection conflict: ${e.length} output path(s) are also protected: ${t}`}function $_(e,t){let n=[];for(let[r,i]of e.entries()){let e=new Set(Kp(r));for(let a of t.compiledRules)if(a.comparisonKeys.some(t=>e.has(t)))for(let e of i)n.push({outputPath:r,outputPlugin:e,protectedPath:a.path,protectionMode:a.protectionMode,protectedBy:a.source,reason:a.reason})}return n.sort((e,t)=>{let n=e.outputPath.localeCompare(t.outputPath);return n===0?e.protectedPath.localeCompare(t.protectedPath):n})}function ev(e,t){e.error(`cleanup protection conflict detected`,{count:t.length,conflicts:t.map(e=>({outputPath:e.outputPath,outputPlugin:e.outputPlugin,protectedPath:e.protectedPath,protectionMode:e.protectionMode,protectedBy:e.protectedBy,reason:e.reason}))})}async function tv(e,n){let r=new Set,i=new Set,a=new Map,o=new Set(G_),s=new Map,c=[],l=(e,t)=>{t===`directory`?i.add(Hp(e)):r.add(Hp(e))},u=(e,t,n,r,i=`path`)=>{let o=Hp(e);a.set(`${i}:${t}:${o}`,{path:o,protectionMode:t,reason:n,source:r,matcher:i})},d=e=>e.protectionMode==null?e.kind===`file`?`direct`:`recursive`:e.protectionMode;for(let e of im(n.collectedOutputContext))u(e.path,e.protectionMode,e.reason,e.source);for(let e of n.pluginOptions?.cleanupProtection?.rules??[])u(e.path,e.protectionMode,e.reason??`configured cleanup protection rule`,`configured-cleanup-protection`,e.matcher??`path`);for(let t of e){let e=await t.declareOutputFiles({...n,dryRun:!0});for(let n of e){let e=Hp(n.path);l(e,`file`);let r=s.get(e);r==null?s.set(e,[t.name]):r.includes(t.name)||r.push(t.name)}let r=await X_(t,n);for(let e of r.excludeScanGlobs??[])o.add(K_(e));c.push({plugin:t,cleanup:r})}let f=[...o],p=e=>{for(let r of Y_(e.path,n,f))try{t.lstatSync(r).isDirectory()?l(r,`directory`):l(r,`file`)}catch{}},m=(e,t)=>{let r=d(e),i=e.label==null?`plugin cleanup protect declaration`:`plugin cleanup protect declaration (${e.label})`;for(let a of Y_(e.path,n,f))u(a,r,i,`plugin-cleanup-protect:${t}`)};for(let{plugin:e,cleanup:t}of c){for(let n of t.protect??[]){if(n.kind===`glob`){m(n,e.name);continue}u(n.path,d(n),n.label==null?`plugin cleanup protect declaration`:`plugin cleanup protect declaration (${n.label})`,`plugin-cleanup-protect:${e.name}`)}for(let e of t.delete??[]){if(e.kind===`glob`){p(e);continue}e.kind===`directory`?l(e.path,`directory`):l(e.path,`file`)}}let h=om({workspaceDir:n.collectedOutputContext.workspace.directory.path,projectRoots:sm(n.collectedOutputContext),rules:[...a.values()],...n.collectedOutputContext.aindexDir==null?{}:{aindexDir:n.collectedOutputContext.aindexDir}}),g=$_(s,h);if(g.length>0)throw new W_(g);let _=um([...r],h),v=um([...i],h),y=Z_(new Map(_.safePaths.map(e=>[e,e])),new Map(v.safePaths.map(e=>[e,e])));return{filesToDelete:y.files,dirsToDelete:y.dirs,violations:[..._.violations,...v.violations].sort((e,t)=>e.targetPath.localeCompare(t.targetPath)),conflicts:[],excludedScanGlobs:[...o].sort((e,t)=>e.localeCompare(t))}}function nv(e,t){let r=e.map(e=>n.isAbsolute(e)?e:n.resolve(e)),i=ot(r);for(let e of r)i.errors.some(t=>t.path===e)||t.debug({action:`delete`,type:`file`,path:e});let a=i.errors.map(e=>{let n=e.error instanceof Error?e.error.message:String(e.error);return t.warn(`failed to delete file`,{path:e.path,error:n}),{path:e.path,type:`file`,error:e.error}});return{deleted:i.deleted,errors:a}}function rv(e,t){let r=e.map(e=>n.isAbsolute(e)?e:n.resolve(e)),i=st(r);for(let e of r)i.errors.some(t=>t.path===e)||t.debug({action:`delete`,type:`directory`,path:e});let a=i.errors.map(e=>{let n=e.error instanceof Error?e.error.message:String(e.error);return t.warn(`failed to delete directory`,{path:e.path,error:n}),{path:e.path,type:`directory`,error:e.error}});return{deleted:i.deleted,errors:a}}function iv(e,t){e.debug(`cleanup plan built`,{filesToDelete:t.filesToDelete.length,dirsToDelete:t.dirsToDelete.length,violations:t.violations.length,conflicts:t.conflicts.length,excludedScanGlobs:t.excludedScanGlobs})}async function av(e,t,n){let r=await E_(e,t);n.debug(`Collected outputs for cleanup`,{projectDirs:r.projectDirs.length,projectFiles:r.projectFiles.length,workspaceDirs:r.workspaceDirs.length,workspaceFiles:r.workspaceFiles.length,globalDirs:r.globalDirs.length,globalFiles:r.globalFiles.length});let i;try{i=await tv(e,t)}catch(e){if(e instanceof W_)return ev(n,e.conflicts),{deletedFiles:0,deletedDirs:0,errors:[],violations:[],conflicts:e.conflicts,message:e.message};throw e}let a={filesToDelete:i.filesToDelete,dirsToDelete:i.dirsToDelete,violations:i.violations,conflicts:i.conflicts,excludedScanGlobs:i.excludedScanGlobs};if(iv(n,a),a.violations.length>0)return fm(n,`cleanup`,a.violations),{deletedFiles:0,deletedDirs:0,errors:[],violations:a.violations,conflicts:[],message:`Protected deletion guard blocked cleanup for ${a.violations.length} path(s)`};let o=nv(a.filesToDelete,n),s=rv(a.dirsToDelete,n);return{deletedFiles:o.deleted,deletedDirs:s.deleted,errors:[...o.errors,...s.errors],violations:[],conflicts:[]}}var ov=class{name=`clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`clean`});let i=await av(n,r(!1),t);return i.violations.length>0||i.conflicts.length>0?{success:!1,filesAffected:0,dirsAffected:0,...i.message==null?{}:{message:i.message}}:(t.info(`clean complete`,{deletedFiles:i.deletedFiles,deletedDirs:i.deletedDirs}),{success:!0,filesAffected:i.deletedFiles,dirsAffected:i.deletedDirs})}},sv=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`dry-run-clean`,dryRun:!0});let i=r(!0),a=await E_(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,workspaceDirs:a.workspaceDirs.length,workspaceFiles:a.workspaceFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s,violations:c,excludedScanGlobs:l}=await tv(n,i);return c.length>0?(fm(t,`dry-run-cleanup`,c),{success:!1,filesAffected:0,dirsAffected:0,message:`Protected deletion guard blocked cleanup for ${c.length} path(s)`}):(this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length,violations:0,excludedScanGlobs:l}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`})}logDryRunFiles(e,t){for(let r of e){let e=n.isAbsolute(r)?r:n.resolve(r);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let r=[...e].sort((e,t)=>t.length-e.length);for(let e of r){let r=n.isAbsolute(e)?e:n.resolve(e);t.info(`would delete directory`,{path:r,dryRun:!0})}}},cv=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`started`,{command:`dry-run-output`,dryRun:!0});let i=await T_(n,r(!0)),a=0,o=0;for(let[e,n]of i)a+=n.files.length,o+=n.dirs.length,t.info(`plugin result`,{plugin:e,files:n.files.length,dirs:n.dirs.length,dryRun:!0});return t.info(`complete`,{command:`dry-run-output`,totalFiles:a,totalDirs:o,dryRun:!0}),{success:!0,filesAffected:a,dirsAffected:o,message:`Dry-run complete, no files were written`}}},lv=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await av(n,r(!1),t);if(a.violations.length>0||a.conflicts.length>0)return{success:!1,filesAffected:0,dirsAffected:0,...a.message==null?{}:{message:a.message}};t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=await T_(n,i(!1)),s=0,c=0,l=[];for(let e of o.values()){s+=e.files.length,c+=e.dirs.length;for(let t of e.files)t.success||l.push(t.error?.message??`Failed to write ${t.path}`)}return l.length>0?{success:!1,filesAffected:s,dirsAffected:c,message:l.join(`
|
|
101
|
+
`)}:(t.info(`complete`,{command:`execute`,pluginCount:o.size}),{success:!0,filesAffected:s,dirsAffected:c})}},uv=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),n=dv(t);return o.stdout.write(`${JSON.stringify(n)}\n`),t}};function dv(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:e.success||e.message==null?[]:[e.message]}}var fv=class{name=`plugins`;async execute(e){let{logger:t,outputPlugins:n,userConfigOptions:r}=e,i=r.plugins,a=[];for(let e of i)a.push({name:e.name,kind:e.type===fp.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let s=new Set(a.map(e=>e.name));for(let e of n)s.has(e.name)||a.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return o.stdout.write(`${JSON.stringify(a)}\n`),t.info(`plugins listed`,{count:a.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Listed ${a.length} plugin(s)`}}};function pv(e){let t=e.slice(2),n=`execute`,r=!1,i=!1;for(let e of t)e===`--json`||e===`-j`?r=!0:e===`--dry-run`||e===`-n`?i=!0:e.startsWith(`-`)||(n=e);return{subcommand:n,json:r,dryRun:i}}function mv(e,t){switch(e){case`execute`:return new lv;case`dry-run`:return new cv;case`clean`:return t?new sv:new ov;case`plugins`:return new fv;default:return new lv}}async function hv(){let{subcommand:e,json:r,dryRun:i}=pv(o.argv);r&&Om(`silent`);let{default:a}=await import(`./plugin.config-BxRsHOpl.mjs`),s=await a,c=mv(e,i);r&&(new Set([`plugins`]).has(c.name)||(c=new uv(c)));let{context:l,outputPlugins:u,userConfigOptions:d}=s,f=km(`PluginRuntime`),p=e=>({logger:f,fs:t,path:n,glob:nt.default,collectedOutputContext:l,pluginOptions:d,dryRun:e}),m=e=>({logger:f,fs:t,path:n,glob:nt.default,collectedOutputContext:l,dryRun:e,registeredPluginNames:[...u].map(e=>e.name)}),h={logger:f,outputPlugins:[...u],collectedOutputContext:l,userConfigOptions:d,createCleanContext:p,createWriteContext:m};(await c.execute(h)).success||o.exit(1)}function gv(e){o.stdout.write(`${JSON.stringify({success:!1,filesAffected:0,dirsAffected:0,message:e,pluginResults:[],errors:[e]})}\n`)}hv().catch(e=>{let t=e instanceof Error?e.message:String(e),{json:n}=pv(o.argv);n&&(gv(t),o.exit(1)),km(`plugin-runtime`,`error`).error(`unhandled error`,{error:t}),o.exit(1)});export{Ap as $,wg as A,Lm as B,Jg as C,Hg as D,Ig as E,Bm as F,Np as G,Rm as H,Nm as I,um as J,rm as K,Pm as L,Qm as M,Hm as N,Ug as O,zm as P,Mp as Q,Mm as R,qg as S,Bg as T,km as U,Im as V,Om as W,yp as X,bp as Y,vp as Z,D_ as _,sv as a,Jf as at,g_ as b,H_ as c,$f as ct,L_ as d,w as dt,mp as et,F_ as f,O_ as g,k_ as h,cv as i,pp as it,Xm as j,Vg as k,U_ as l,it as lt,P_ as m,uv as n,hp as nt,ov as o,Zf as ot,A_ as p,om as q,lv as r,fp as rt,V_ as s,Qf as st,fv as t,gp as tt,B_ as u,tt as ut,w_ as v,Yg as w,p_ as x,__ as y,Vm as z};
|