@truenine/memory-sync-cli 2026.10218.12326 → 2026.10219.10049

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/index.cjs CHANGED
@@ -433,7 +433,7 @@ node_modules/
433
433
  pnpm-lock.yaml
434
434
  .DS_Store
435
435
  `,"public/tnmsc.example.json":`{
436
- "version": "2026.10218.12326",
436
+ "version": "2026.10219.10049",
437
437
  "workspaceDir": "~/project",
438
438
  "shadowSourceProject": {
439
439
  "name": "tnmsc-shadow",
@@ -978,7 +978,7 @@ API 接口 (Spring WebFlux 6.2)
978
978
  - \`controllers/\`: 控制器
979
979
  - \`dto/\`: 数据传输对象
980
980
  \`\`\`
981
- `};const Ut=Object.fromEntries(Vt.map(e=>[e,{path:e,content:Ht[e]??``}])),R={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Wt=JSON.parse(Ut[`public/tnmsc.example.json`].content),z={reset:`\x1B[0m`,red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`,gray:`\x1B[90m`,blue:`\x1B[34m`,green:`\x1B[32m`,white:`\x1B[37m`,dim:`\x1B[2m`,bgRed:`\x1B[41m`},Gt={red:e=>`${z.red}${e}${z.reset}`,yellow:e=>`${z.yellow}${e}${z.reset}`,cyan:e=>`${z.cyan}${e}${z.reset}`,magenta:e=>`${z.magenta}${e}${z.reset}`,gray:e=>`${z.gray}${e}${z.reset}`,blue:e=>`${z.blue}${e}${z.reset}`,green:e=>`${z.green}${e}${z.reset}`,white:e=>`${z.white}${e}${z.reset}`,dim:e=>`${z.dim}${e}${z.reset}`,bgRed:e=>`${z.bgRed}${e}${z.reset}`};let Kt;const qt={error:Gt.red,warn:Gt.yellow,info:Gt.cyan,debug:Gt.magenta,trace:Gt.gray,fatal:Gt.bgRed},Jt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Yt(e){if(e===null)return Gt.dim(`null`);if(e===void 0)return Gt.dim(`undefined`);if(typeof e==`boolean`)return Gt.yellow(String(e));if(typeof e==`number`)return Gt.blue(String(e));if(typeof e==`string`)return Gt.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Yt(e)).join(`,`)}]`;if(e instanceof Error){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 Xt(t)}return typeof e==`object`?Xt(e):String(e)}function Xt(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?Gt.magenta(e):Gt.yellow(`"${e}"`)}:${Yt(t)}`).join(`,`)}}`}function Zt(){let e=new Date;return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}:${String(e.getSeconds()).padStart(2,`0`)}.${String(e.getMilliseconds()).padStart(3,`0`)}`}function Qt(e,t,n,r){let i=Zt(),a=qt[e]??Gt.white,o=String(n),s=r!=null&&Object.keys(r).length>0,c=o===``,l={$:[i,e,t],_:s?c?r:{[o]:r}:n},u={$:[i,a(e.toUpperCase()),t]},d=s?c?r:{[o]:r}:n,f=Xt({...u,_:d});return e===`error`||e===`fatal`?console.error(f):e===`warn`?console.warn(f):e===`debug`||e===`trace`?console.debug(f):console.log(f),l}function $t(e,t,n){let r=Jt[e],i=Jt[n];return(n,...a)=>r>i?{$:[Zt(),e,t],_:n}:typeof n==`string`?Qt(e,t,n,a.length===1&&typeof a[0]==`object`&&a[0]!==null?a[0]:a.length>0?{args:a}:void 0):typeof n==`object`&&n?Qt(e,t,``,n):Qt(e,t,n)}function en(e){Kt=e}function tn(){return Kt}function nn(e,t){let n=t??Kt??process.env.LOG_LEVEL??`info`;return{error:$t(`error`,e,n),warn:$t(`warn`,e,n),info:$t(`info`,e,n),debug:$t(`debug`,e,n),trace:$t(`trace`,e,n),fatal:$t(`fatal`,e,n)}}const rn=`.tnmsc.json`,an=`.aindex`;function on(){return f.join(p.homedir(),an,rn)}function sn(){return{...Wt}}function cn(e,t){let n=on(),r=f.dirname(n);d.existsSync(r)||d.mkdirSync(r,{recursive:!0}),d.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}function ln(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object with "src" and "dist" string fields`),n;let r=e;return(!(`src`in r)||typeof r.src!=`string`)&&n.push(`${t}.src must be a string`),(!(`dist`in r)||typeof r.dist!=`string`)&&n.push(`${t}.dist must be a string`),n}function un(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object`),{errors:n,config:void 0};let r=e;(!(`name`in r)||typeof r.name!=`string`)&&n.push(`${t}.name must be a string`);let i=[`skill`,`fastCommand`,`subAgent`,`rule`,`globalMemory`,`workspaceMemory`,`project`],a={};for(let e of i)if(e in r){let i=ln(r[e],`${t}.${e}`);if(n.push(...i),i.length===0){let t=r[e];a[e]={src:t.src,dist:t.dist}}}return n.length>0?{errors:n,config:void 0}:{errors:n,config:{name:r.name,skill:a.skill??{src:`src/skills`,dist:`dist/skills`},fastCommand:a.fastCommand??{src:`src/commands`,dist:`dist/commands`},subAgent:a.subAgent??{src:`src/agents`,dist:`dist/agents`},rule:a.rule??{src:`src/rules`,dist:`dist/rules`},globalMemory:a.globalMemory??{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:a.workspaceMemory??{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:a.project??{src:`app`,dist:`dist/app`}}}}var dn=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??rn,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=nn(`ConfigLoader`)}getSearchPaths(e=u.default.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(f.join(e,this.configFileName)),this.searchGlobal&&t.push(f.join(p.homedir(),an,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!d.existsSync(t))return{config:{},source:null,found:!1};let e=d.readFileSync(t,`utf8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=u.default.cwd()){let t=this.getSearchPaths(e),n=[];for(let e of t){let t=this.loadFromFile(e);t.found&&n.push(t)}return{config:this.mergeConfigs(n.map(e=>e.config)),sources:n.map(e=>e.source).filter(e=>e!==null),found:n.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];if(`version`in e&&(typeof e.version==`string`?n.version=e.version:r.push(`version must be a string`)),`workspaceDir`in e&&(typeof e.workspaceDir==`string`?n.workspaceDir=e.workspaceDir:r.push(`workspaceDir must be a string`)),`shadowSourceProject`in e){let{errors:t,config:i}=un(e.shadowSourceProject,`shadowSourceProject`);r.push(...t),i!=null&&(n.shadowSourceProject=i)}if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`profile`in e){let t=e.profile;typeof t==`object`&&t&&!Array.isArray(t)?n.profile=t:r.push(`profile must be an object`)}if(`tool`in e){let t=e.tool;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))typeof n==`string`||n===void 0?i[t]=n:(r.push(`tool.${t} must be a string`),a=!1);a&&(n.tool=i)}else r.push(`tool must be an object`)}if(`fastCommandSeriesOptions`in e){let t=e.fastCommandSeriesOptions;typeof t==`object`&&t&&!Array.isArray(t)?n.fastCommandSeriesOptions=t:r.push(`fastCommandSeriesOptions must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=this.mergeShadowSourceProject(e.shadowSourceProject,t.shadowSourceProject);return{...e,...t,...n==null?{}:{shadowSourceProject:n}}},{})}mergeShadowSourceProject(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}resolveTilde(e){return e.startsWith(`~`)?f.join(p.homedir(),e.slice(1)):e}};let fn=null;function pn(e){return(e||!fn)&&(fn=new dn(e)),fn}function mn(e){return pn().load(e)}function hn(){let e=nn(`ConfigLoader`),t=on();if(!d.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),cn(sn(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=d.readFileSync(t,`utf8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),_n(t,e,[`Failed to read config: ${r}`])}let r;try{r=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),_n(t,e,[`Invalid JSON: ${r}`])}if(typeof r!=`object`||!r||Array.isArray(r))return e.error(`global config must be a JSON object`,{path:t}),_n(t,e,[`Config must be a JSON object`]);let i=gn(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return _n(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function gn(e){let t=[];if(`version`in e&&typeof e.version!=`string`&&t.push(`version must be a string`),`workspaceDir`in e&&typeof e.workspaceDir!=`string`&&t.push(`workspaceDir must be a string`),`shadowSourceProject`in e){let{errors:n}=un(e.shadowSourceProject,`shadowSourceProject`);t.push(...n)}if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`profile`in e){let n=e.profile;(typeof n!=`object`||!n||Array.isArray(n))&&t.push(`profile must be an object`)}if(!(`tool`in e))return t;let n=e.tool;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`tool must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))typeof r!=`string`&&r!==void 0&&t.push(`tool.${n} must be a string`)}return t}function _n(e,t,n){try{d.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return cn(sn(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const vn=[`workspaceDir`,`shadowSourceProject.name`,`shadowSourceProject.skill.src`,`shadowSourceProject.skill.dist`,`shadowSourceProject.fastCommand.src`,`shadowSourceProject.fastCommand.dist`,`shadowSourceProject.subAgent.src`,`shadowSourceProject.subAgent.dist`,`shadowSourceProject.rule.src`,`shadowSourceProject.rule.dist`,`shadowSourceProject.globalMemory.src`,`shadowSourceProject.globalMemory.dist`,`shadowSourceProject.workspaceMemory.src`,`shadowSourceProject.workspaceMemory.dist`,`shadowSourceProject.project.src`,`shadowSourceProject.project.dist`,`logLevel`];function yn(e){return vn.includes(e)}function bn(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function xn(){return f.join(p.homedir(),an,rn)}function Sn(){let e=xn();if(!d.existsSync(e))return{};try{let t=d.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Cn(e){let t=xn(),n=f.dirname(t);d.existsSync(n)||d.mkdirSync(n,{recursive:!0}),d.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}function wn(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];(typeof i[t]!=`object`||i[t]===null)&&(i[t]={}),i=i[t]}i[r.at(-1)]=n}function Tn(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return r}var En=class{name=`config`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc config key=value`),t.info(`Valid keys: ${vn.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=Sn(),r=[],i=[];for(let[e,a]of this.options){if(!yn(e)){r.push(`Invalid key: ${e} (valid keys: ${vn.join(`, `)})`);continue}if(e===`logLevel`&&!bn(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=Tn(n,e);wn(n,e,a),o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Cn(n),t.info(`global config written`,{path:xn()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},Dn=class{name=`config-show`;async execute(e){let{logger:t}=e,n=new dn,r=n.load(),i=r.sources.map(e=>{let t=n.loadFromFile(e);return{path:e,layer:this.inferLayer(e),config:t.config}}),a={merged:r.config,sources:i};return u.default.stdout.write(`${JSON.stringify(a)}\n`),t.info(`config shown`,{sources:r.sources.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Configuration displayed (${i.length} source(s))`}}inferLayer(e){let t=u.default.cwd();return e.startsWith(t)?`cwd`:`global`}},On=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 ut(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s}=await ht(n,await dt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await ft(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`}}logDryRunFiles(e,t){for(let n of e){let e=f.isAbsolute(n)?n:f.resolve(n);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=f.isAbsolute(e)?e:f.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},kn=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=r(!0),a=await pt(n,i),o=await mt(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=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:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},An=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await vt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await pt(n,o),c=await mt(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function jn(){return`2026.10218.12326`}var Mn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${jn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const Nn=`tnmsc`,Pn=`
981
+ `};const Ut=Object.fromEntries(Vt.map(e=>[e,{path:e,content:Ht[e]??``}])),R={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Wt=JSON.parse(Ut[`public/tnmsc.example.json`].content),z={reset:`\x1B[0m`,red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`,gray:`\x1B[90m`,blue:`\x1B[34m`,green:`\x1B[32m`,white:`\x1B[37m`,dim:`\x1B[2m`,bgRed:`\x1B[41m`},Gt={red:e=>`${z.red}${e}${z.reset}`,yellow:e=>`${z.yellow}${e}${z.reset}`,cyan:e=>`${z.cyan}${e}${z.reset}`,magenta:e=>`${z.magenta}${e}${z.reset}`,gray:e=>`${z.gray}${e}${z.reset}`,blue:e=>`${z.blue}${e}${z.reset}`,green:e=>`${z.green}${e}${z.reset}`,white:e=>`${z.white}${e}${z.reset}`,dim:e=>`${z.dim}${e}${z.reset}`,bgRed:e=>`${z.bgRed}${e}${z.reset}`};let Kt;const qt={error:Gt.red,warn:Gt.yellow,info:Gt.cyan,debug:Gt.magenta,trace:Gt.gray,fatal:Gt.bgRed},Jt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Yt(e){if(e===null)return Gt.dim(`null`);if(e===void 0)return Gt.dim(`undefined`);if(typeof e==`boolean`)return Gt.yellow(String(e));if(typeof e==`number`)return Gt.blue(String(e));if(typeof e==`string`)return Gt.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Yt(e)).join(`,`)}]`;if(e instanceof Error){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 Xt(t)}return typeof e==`object`?Xt(e):String(e)}function Xt(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?Gt.magenta(e):Gt.yellow(`"${e}"`)}:${Yt(t)}`).join(`,`)}}`}function Zt(){let e=new Date;return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}:${String(e.getSeconds()).padStart(2,`0`)}.${String(e.getMilliseconds()).padStart(3,`0`)}`}function Qt(e,t,n,r){let i=Zt(),a=qt[e]??Gt.white,o=String(n),s=r!=null&&Object.keys(r).length>0,c=o===``,l={$:[i,e,t],_:s?c?r:{[o]:r}:n},u={$:[i,a(e.toUpperCase()),t]},d=s?c?r:{[o]:r}:n,f=Xt({...u,_:d});return e===`error`||e===`fatal`?console.error(f):e===`warn`?console.warn(f):e===`debug`||e===`trace`?console.debug(f):console.log(f),l}function $t(e,t,n){let r=Jt[e],i=Jt[n];return(n,...a)=>r>i?{$:[Zt(),e,t],_:n}:typeof n==`string`?Qt(e,t,n,a.length===1&&typeof a[0]==`object`&&a[0]!==null?a[0]:a.length>0?{args:a}:void 0):typeof n==`object`&&n?Qt(e,t,``,n):Qt(e,t,n)}function en(e){Kt=e}function tn(){return Kt}function nn(e,t){let n=t??Kt??process.env.LOG_LEVEL??`info`;return{error:$t(`error`,e,n),warn:$t(`warn`,e,n),info:$t(`info`,e,n),debug:$t(`debug`,e,n),trace:$t(`trace`,e,n),fatal:$t(`fatal`,e,n)}}const rn=`.tnmsc.json`,an=`.aindex`;function on(){return f.join(p.homedir(),an,rn)}function sn(){return{...Wt}}function cn(e,t){let n=on(),r=f.dirname(n);d.existsSync(r)||d.mkdirSync(r,{recursive:!0}),d.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}function ln(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object with "src" and "dist" string fields`),n;let r=e;return(!(`src`in r)||typeof r.src!=`string`)&&n.push(`${t}.src must be a string`),(!(`dist`in r)||typeof r.dist!=`string`)&&n.push(`${t}.dist must be a string`),n}function un(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object`),{errors:n,config:void 0};let r=e;(!(`name`in r)||typeof r.name!=`string`)&&n.push(`${t}.name must be a string`);let i=[`skill`,`fastCommand`,`subAgent`,`rule`,`globalMemory`,`workspaceMemory`,`project`],a={};for(let e of i)if(e in r){let i=ln(r[e],`${t}.${e}`);if(n.push(...i),i.length===0){let t=r[e];a[e]={src:t.src,dist:t.dist}}}return n.length>0?{errors:n,config:void 0}:{errors:n,config:{name:r.name,skill:a.skill??{src:`src/skills`,dist:`dist/skills`},fastCommand:a.fastCommand??{src:`src/commands`,dist:`dist/commands`},subAgent:a.subAgent??{src:`src/agents`,dist:`dist/agents`},rule:a.rule??{src:`src/rules`,dist:`dist/rules`},globalMemory:a.globalMemory??{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:a.workspaceMemory??{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:a.project??{src:`app`,dist:`dist/app`}}}}var dn=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??rn,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=nn(`ConfigLoader`)}getSearchPaths(e=u.default.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(f.join(e,this.configFileName)),this.searchGlobal&&t.push(f.join(p.homedir(),an,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!d.existsSync(t))return{config:{},source:null,found:!1};let e=d.readFileSync(t,`utf8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=u.default.cwd()){let t=this.getSearchPaths(e),n=[];for(let e of t){let t=this.loadFromFile(e);t.found&&n.push(t)}return{config:this.mergeConfigs(n.map(e=>e.config)),sources:n.map(e=>e.source).filter(e=>e!==null),found:n.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];if(`version`in e&&(typeof e.version==`string`?n.version=e.version:r.push(`version must be a string`)),`workspaceDir`in e&&(typeof e.workspaceDir==`string`?n.workspaceDir=e.workspaceDir:r.push(`workspaceDir must be a string`)),`shadowSourceProject`in e){let{errors:t,config:i}=un(e.shadowSourceProject,`shadowSourceProject`);r.push(...t),i!=null&&(n.shadowSourceProject=i)}if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`profile`in e){let t=e.profile;typeof t==`object`&&t&&!Array.isArray(t)?n.profile=t:r.push(`profile must be an object`)}if(`tool`in e){let t=e.tool;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))typeof n==`string`||n===void 0?i[t]=n:(r.push(`tool.${t} must be a string`),a=!1);a&&(n.tool=i)}else r.push(`tool must be an object`)}if(`fastCommandSeriesOptions`in e){let t=e.fastCommandSeriesOptions;typeof t==`object`&&t&&!Array.isArray(t)?n.fastCommandSeriesOptions=t:r.push(`fastCommandSeriesOptions must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=this.mergeShadowSourceProject(e.shadowSourceProject,t.shadowSourceProject);return{...e,...t,...n==null?{}:{shadowSourceProject:n}}},{})}mergeShadowSourceProject(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}resolveTilde(e){return e.startsWith(`~`)?f.join(p.homedir(),e.slice(1)):e}};let fn=null;function pn(e){return(e||!fn)&&(fn=new dn(e)),fn}function mn(e){return pn().load(e)}function hn(){let e=nn(`ConfigLoader`),t=on();if(!d.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),cn(sn(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=d.readFileSync(t,`utf8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),_n(t,e,[`Failed to read config: ${r}`])}let r;try{r=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),_n(t,e,[`Invalid JSON: ${r}`])}if(typeof r!=`object`||!r||Array.isArray(r))return e.error(`global config must be a JSON object`,{path:t}),_n(t,e,[`Config must be a JSON object`]);let i=gn(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return _n(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function gn(e){let t=[];if(`version`in e&&typeof e.version!=`string`&&t.push(`version must be a string`),`workspaceDir`in e&&typeof e.workspaceDir!=`string`&&t.push(`workspaceDir must be a string`),`shadowSourceProject`in e){let{errors:n}=un(e.shadowSourceProject,`shadowSourceProject`);t.push(...n)}if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`profile`in e){let n=e.profile;(typeof n!=`object`||!n||Array.isArray(n))&&t.push(`profile must be an object`)}if(!(`tool`in e))return t;let n=e.tool;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`tool must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))typeof r!=`string`&&r!==void 0&&t.push(`tool.${n} must be a string`)}return t}function _n(e,t,n){try{d.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return cn(sn(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const vn=[`workspaceDir`,`shadowSourceProject.name`,`shadowSourceProject.skill.src`,`shadowSourceProject.skill.dist`,`shadowSourceProject.fastCommand.src`,`shadowSourceProject.fastCommand.dist`,`shadowSourceProject.subAgent.src`,`shadowSourceProject.subAgent.dist`,`shadowSourceProject.rule.src`,`shadowSourceProject.rule.dist`,`shadowSourceProject.globalMemory.src`,`shadowSourceProject.globalMemory.dist`,`shadowSourceProject.workspaceMemory.src`,`shadowSourceProject.workspaceMemory.dist`,`shadowSourceProject.project.src`,`shadowSourceProject.project.dist`,`logLevel`];function yn(e){return vn.includes(e)}function bn(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function xn(){return f.join(p.homedir(),an,rn)}function Sn(){let e=xn();if(!d.existsSync(e))return{};try{let t=d.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Cn(e){let t=xn(),n=f.dirname(t);d.existsSync(n)||d.mkdirSync(n,{recursive:!0}),d.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}function wn(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];(typeof i[t]!=`object`||i[t]===null)&&(i[t]={}),i=i[t]}i[r.at(-1)]=n}function Tn(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return r}var En=class{name=`config`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc config key=value`),t.info(`Valid keys: ${vn.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=Sn(),r=[],i=[];for(let[e,a]of this.options){if(!yn(e)){r.push(`Invalid key: ${e} (valid keys: ${vn.join(`, `)})`);continue}if(e===`logLevel`&&!bn(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=Tn(n,e);wn(n,e,a),o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Cn(n),t.info(`global config written`,{path:xn()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},Dn=class{name=`config-show`;async execute(e){let{logger:t}=e,n=new dn,r=n.load(),i=r.sources.map(e=>{let t=n.loadFromFile(e);return{path:e,layer:this.inferLayer(e),config:t.config}}),a={merged:r.config,sources:i};return u.default.stdout.write(`${JSON.stringify(a)}\n`),t.info(`config shown`,{sources:r.sources.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Configuration displayed (${i.length} source(s))`}}inferLayer(e){let t=u.default.cwd();return e.startsWith(t)?`cwd`:`global`}},On=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 ut(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s}=await ht(n,await dt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await ft(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`}}logDryRunFiles(e,t){for(let n of e){let e=f.isAbsolute(n)?n:f.resolve(n);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=f.isAbsolute(e)?e:f.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},kn=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=r(!0),a=await pt(n,i),o=await mt(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=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:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},An=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await vt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await pt(n,o),c=await mt(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function jn(){return`2026.10219.10049`}var Mn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${jn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const Nn=`tnmsc`,Pn=`
982
982
  ${Nn} v${jn()} - Memory Sync CLI
983
983
 
984
984
  Synchronize AI memory and configuration files across projects.
@@ -1039,7 +1039,7 @@ CONFIG OPTIONS:
1039
1039
  CONFIGURATION:
1040
1040
  Configure via plugin.config.ts in your project root.
1041
1041
  See documentation for detailed configuration options.
1042
- `.trim();var Fn=class{name=`help`;async execute(e){return console.log(Pn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function In(e,t){let n=f.join(e,`.git`),r=d.existsSync(n);return r?t?.info(`version control detected`,{path:n}):t?.warn(`no version control detected, please use git to manage your shadow source project`,{path:e}),{hasGit:r,gitPath:n}}function Ln(e,t,n,r,i){if(n==null)return r;let a=f.relative(t,e),o=f.join(n,a);return d.existsSync(o)&&d.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),d.readFileSync(o,`utf8`)):r}function Rn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;d.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(d.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(Ut)){let o=t.path,l=f.join(e,o),u=f.dirname(l);if(!d.existsSync(u)){d.mkdirSync(u,{recursive:!0});let t=u;for(;t!==e&&!c.has(t);)c.add(t),i.push(t),r?.info(`created directory`,{path:t}),t=f.dirname(t)}if(d.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=Ln(l,e,n,t.content,r);d.writeFileSync(l,i,`utf8`),a.push(l),r?.info(`created file`,{path:l})}}return{success:!0,rootPath:e,createdDirs:i,createdFiles:a,existedDirs:o,existedFiles:s}}function zn(e){let t=e;return t.startsWith(`~`)&&(t=f.join(p.homedir(),t.slice(1))),f.normalize(t)}var Bn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=zn(n.workspaceDir),i=Rn(f.join(r,n.shadowSourceProject.name),{logger:t}),a=i.createdDirs.length===0&&i.createdFiles.length===0?`All ${i.existedDirs.length} directories and ${i.existedFiles.length} files already exist`:`Created ${i.createdDirs.length} directories and ${i.createdFiles.length} files (${i.existedDirs.length} dirs, ${i.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:i.createdDirs.length,filesCreated:i.createdFiles.length,dirsExisted:i.existedDirs.length,filesExisted:i.existedFiles.length}),{success:i.success,filesAffected:i.createdFiles.length,dirsAffected:i.createdDirs.length,message:a}}},Vn=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),n=Hn(t);return u.default.stdout.write(`${JSON.stringify(n)}\n`),t}};function Hn(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:[]}}function Un(){return`@truenine/memory-sync-cli`}function Wn(){return`https://registry.npmjs.org/${Un()}/latest`}function Gn(e){let t=e.replace(/^v/,``),n=/^(\d+)\.(\d+)\.(\d+)/.exec(t);return n==null?null:[Number.parseInt(n[1],10),Number.parseInt(n[2],10),Number.parseInt(n[3],10)]}function Kn(e,t){let n=Gn(e),r=Gn(t);if(n==null||r==null)return 0;for(let e=0;e<3;e++){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1}return 0}const qn=3e3;async function Jn(){let e=new AbortController,t=setTimeout(()=>e.abort(),qn);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(Wn(),{headers:{Accept:`application/json`},signal:e.signal});if(clearTimeout(t),!n.ok)return{error:`HTTP ${n.status}: ${n.statusText}`};let r=await n.json();return r.version==null?{error:`Invalid response: missing version field`}:{version:r.version}}catch(e){return clearTimeout(t),e instanceof Error?e.name===`TimeoutError`||e.name===`AbortError`?{error:`Request timeout after ${qn}ms`}:{error:e.message}:{error:`Unknown network error`}}}function Yn(){return`2026.10218.12326`}async function Xn(){let e=Yn();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await Jn();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=Kn(e,n);return r<0?{status:`outdated`,localVersion:e,remoteVersion:n}:r>0?{status:`development`,localVersion:e,remoteVersion:n}:{status:`current`,localVersion:e,remoteVersion:n}}function Zn(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Un()}@latest' to update.`);break;case`current`:e.error==null?t.info(`Version ${r} is up to date.`):t.error(`Version check failed: ${e.error}`);break;case`development`:i==null?t.debug(`Running in development mode, version check skipped.`):t.info(`Development version detected: ${r} > ${i}. Thanks for contributing!`);break}}function Qn(){return new Date().getMinutes()%2==0}function $n(e){Qn()&&Xn().then(t=>{(t.status===`outdated`||t.error!=null)&&Zn(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var er=class{name=`outdated`;async execute(e){let t=await Xn();return Zn(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},tr=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===bt.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let o=new Set(a.map(e=>e.name));for(let e of n)o.has(e.name)||a.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return u.default.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)`}}},nr=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};const rr={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 ir=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}({}),ar=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var or=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=p.platform();return{platform:e,arch:p.arch(),hostname:p.hostname(),homedir:p.homedir(),tmpdir:p.tmpdir(),type:p.type(),release:p.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return ar.Win;case`darwin`:return ar.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return ar.Linux;default:return ar.Unknown}}detectShellKind(){let e=(u.default.env.SHELL??u.default.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?ir.Bash:e.includes(`zsh`)?ir.Zsh:e.includes(`fish`)?ir.Fish:e.includes(`pwsh`)?ir.Pwsh:e.includes(`powershell`)?ir.PowerShell:e.includes(`cmd`)?ir.Cmd:e.endsWith(`/sh`)?ir.Sh:ir.Unknown}collectEnvContext(){return{...u.default.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...rr.default};return this.toolPreset===`claudeCode`?{...e,...rr.claudeCode}:this.toolPreset===`kiro`?{...e,...rr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let sr=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 cr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=sr.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}clear(){this.registrations.length=0,this.globalScope=null}};function lr(e){let t=[...e],n=t[0];n!=null&&ur(n)&&t.shift();let r=t[0];return r!=null&&dr(r)&&t.shift(),t}function ur(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replaceAll(`\\`,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function dr(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const fr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`,`plugins`]),pr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),mr=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function hr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=mr.get(n)??4;for(let e of t){let t=mr.get(e)??4;t<r&&(r=t,n=e)}return n}function gr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s,showFlag:c}=e;if(n)return new Mn;if(t)return new Fn;if(a!=null)return new nr(a);if(r===`version`)return new Mn;if(r===`help`)return new Fn;if(r===`outdated`)return new er;if(r===`init`)return new Bn;if(r===`dry-run`)return new kn;if(r===`clean`)return i?new On:new yt;if(r===`plugins`)return new tr;if(r===`config`&&c)return new Dn;if(r!==`config`||o.length>0)return new An;let l=[];for(let e of s){let t=e.indexOf(`=`);t>0&&l.push([e.slice(0,t),e.slice(t+1)])}return new En([...o,...l])}function _r(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,jsonFlag:!1,showFlag:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=pr.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--json`:t.jsonFlag=!0;break;case`--show`:t.showFlag=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;case`j`:t.jsonFlag=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,fr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var vr=class{logger;args;outputPlugins=[];constructor(...e){this.args=_r(lr(e.filter(e=>e!=null)));let t=hr(this.args);t!=null&&en(t),this.logger=nn(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){$n(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand();this.args.jsonFlag&&(en(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new Vn(i)));let a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return gr(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:d,path:f,glob:Je.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:d,path:f,glob:Je.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new Dt(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length===e.length)return a;throw new Et(this.findCyclePath(e,n))}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a.at(-1));return a.slice(e)}i.clear(),a.length=0}return[...n]}async executePluginsInOrder(e,t,n=!1,r){if(e.length===0)return{};let i=this.topologicalSort(e),a=new or({userConfig:r}).collect(),o=new cr;o.setGlobalScope(a),this.logger.debug(`global scope collected`,{osInfo:{platform:a.os.platform,arch:a.os.arch,shellKind:a.os.shellKind},hasProfile:Object.keys(a.profile).length>0,hasTool:Object.keys(a.tool).length>0});let s=new Map,c={};for(let e of i){let r=this.buildDependencyContext(e,s),i={...t,dependencyContext:r,globalScope:a,scopeRegistry:o},l=e;l.executeEffects!=null&&await l.executeEffects(i,n);let u=await e.collect(i);s.set(e.name,u),c=this.mergeContexts(c,u);let d=e;if(d.getRegisteredScopes!=null){let t=d.getRegisteredScopes();for(let{namespace:n,values:r}of t)o.register(n,r,sr.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(r)})}}return c}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let{workspace:n}=e;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:[...e.values()]}}else ({workspace:n}=t);let r=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],i=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],a=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],o=t.skills==null?e.skills:[...e.skills??[],...t.skills],s=t.rules==null?e.rules:[...e.rules??[],...t.rules],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts],f=t.globalGitIgnore??e.globalGitIgnore,p=t.shadowGitExclude??e.shadowGitExclude;return{...n==null?{}:{workspace:n},...r==null?{}:{ideConfigFiles:r},...i==null?{}:{fastCommands:i},...a==null?{}:{subAgents:a},...o==null?{}:{skills:o},...s==null?{}:{rules:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d},...f==null?{}:{globalGitIgnore:f},...p==null?{}:{shadowGitExclude:p}}}};const yr={name:`tnmsc-shadow`,skill:{src:`src/skills`,dist:`dist/skills`},fastCommand:{src:`src/commands`,dist:`dist/commands`},subAgent:{src:`src/agents`,dist:`dist/agents`},rule:{src:`src/rules`,dist:`dist/rules`},globalMemory:{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:{src:`app`,dist:`dist/app`}},br={...Wt,shadowSourceProject:yr,fastCommandSeriesOptions:{},plugins:[]};function xr(e){return{...e.version==null?{}:{version:e.version},...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProject==null?{}:{shadowSourceProject:e.shadowSourceProject},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function Sr(...e){return e.reduce((e,t)=>Cr(e,t),{...br})}function Cr(e,t){let n=t.plugins,r=t.fastCommandSeriesOptions;return{...e,...t,shadowSourceProject:wr(e.shadowSourceProject,t.shadowSourceProject),plugins:[...e.plugins,...n??[]],fastCommandSeriesOptions:Tr(e.fastCommandSeriesOptions,r)}}function wr(e,t){return t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}function Tr(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function Er(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Dr(e={}){hn().shouldExit&&u.default.exit(1);let t,n,r;Er(e)?({pluginOptions:r={},cwd:n}={pluginOptions:e.pluginOptions,cwd:e.cwd},t=e.loadUserConfig??!0):(r=e,t=!0);let i={},a=!1,o=[],s;if(t){let e=mn(n);a=e.found,o=e.sources,e.found&&(i=xr(e.config),s=e.config)}let c=Sr(i,r),{plugins:l=[],logLevel:p}=c,m=nn(`defineConfig`,p);a?m.info(`user config loaded`,{sources:o}):m.info(`no user config found, using defaults`,{workspaceDir:br.workspaceDir,shadowSourceProjectName:br.shadowSourceProject.name,logLevel:br.logLevel});let h={logger:m,userConfigOptions:c,fs:d,path:f,glob:Je.default},g=l.filter(e=>e.type===bt.Input),_=l.filter(e=>e.type===bt.Output),v=await new vr().executePluginsInOrder(g,h,!1,s);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...v.rules!=null&&{rules:v.rules},...v.globalMemory!=null&&{globalMemory:v.globalMemory},...v.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:v.aiAgentIgnoreConfigFiles},...v.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:v.shadowSourceProjectDir},...v.readmePrompts!=null&&{readmePrompts:v.readmePrompts},...v.globalGitIgnore!=null&&{globalGitIgnore:v.globalGitIgnore},...v.shadowGitExclude!=null&&{shadowGitExclude:v.shadowGitExclude}};return v.shadowSourceProjectDir!=null&&In(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:c}}const Or=Lr(/[A-Za-z]/),kr=Lr(/[\dA-Za-z]/),Ar=Lr(/[#-'*+\--9=?A-Z^-~]/);function jr(e){return e!==null&&(e<32||e===127)}const Mr=Lr(/\d/),Nr=Lr(/[\dA-Fa-f]/),Pr=Lr(/[!-/:-@[-`{-~]/);function B(e){return e!==null&&e<-2}function V(e){return e!==null&&(e<0||e===32)}function H(e){return e===-2||e===-1||e===32}const Fr=Lr(/\p{P}|\p{S}/u),Ir=Lr(/\s/);function Lr(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Rr=l(o(((e,t)=>{(function(){var e=t===void 0?function(){return this||(0,eval)(`this`)}():t.exports=i;e.format=i,e.vsprintf=r,typeof console<`u`&&typeof console.log==`function`&&(e.printf=n);function n(){console.log(i.apply(null,arguments))}function r(e,t){return i.apply(null,[e].concat(t))}function i(e){for(var t=1,n=[].slice.call(arguments),r=0,i=e.length,a=``,o,s=!1,c,l,u=!1,d,f=function(){return n[t++]},p=function(){for(var t=``;/\d/.test(e[r]);)t+=e[r++],o=e[r];return t.length>0?parseInt(t):null};r<i;++r)if(o=e[r],s)switch(s=!1,o==`.`?(u=!1,o=e[++r]):o==`0`&&e[r+1]==`.`?(u=!0,r+=2,o=e[r]):u=!0,d=p(),o){case`b`:a+=parseInt(f(),10).toString(2);break;case`c`:c=f(),typeof c==`string`||c instanceof String?a+=c:a+=String.fromCharCode(parseInt(c,10));break;case`d`:a+=parseInt(f(),10);break;case`f`:l=String(parseFloat(f()).toFixed(d||6)),a+=u?l:l.replace(/^0/,``);break;case`j`:a+=JSON.stringify(f());break;case`o`:a+=`0`+parseInt(f(),10).toString(8);break;case`s`:a+=f();break;case`x`:a+=`0x`+parseInt(f(),10).toString(16);break;case`X`:a+=`0x`+parseInt(f(),10).toString(16).toUpperCase();break;default:a+=o;break}else o===`%`?s=!0:a+=o;return a}})()}))(),1);const zr=Object.assign(Br(Error),{eval:Br(EvalError),range:Br(RangeError),reference:Br(ReferenceError),syntax:Br(SyntaxError),type:Br(TypeError),uri:Br(URIError)});function Br(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Rr.default)(t,...n))}}const Vr={}.hasOwnProperty,Hr={yaml:`-`,toml:`+`};function Ur(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Wr(r[n]);return t}function Wr(e){let t=e;if(typeof t==`string`){if(!Vr.call(Hr,t))throw zr("Missing matter definition for `%s`",t);t={type:t,marker:Hr[t]}}else if(typeof t!=`object`)throw zr("Expected matter to be an object, not `%j`",t);if(!Vr.call(t,`type`))throw zr("Missing `type` in matter `%j`",t);if(!Vr.call(t,`fence`)&&!Vr.call(t,`marker`))throw zr("Missing `marker` or `fence` in matter `%j`",t);return t}function Gr(e){let t=Ur(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=qr(e,`open`).charCodeAt(0),a=Kr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Kr(e){let t=e.anywhere,n=e.type,r=n+`Fence`,i=r+`Sequence`,a=n+`Value`,o={tokenize:u,partial:!0},s,c=0;return{tokenize:l,concrete:!0};function l(l,u,d){let f=this;return p;function p(a){let o=f.now();return o.column===1&&(o.line===1||t)&&(s=qr(e,`open`),c=0,a===s.charCodeAt(c))?(l.enter(n),l.enter(r),l.enter(i),m(a)):d(a)}function m(e){return c===s.length?(l.exit(i),H(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return H(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return B(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=qr(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||B(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||B(e)?(l.exit(a),y(e)):(l.consume(e),v)}function y(e){return e===null?d(e):(l.enter(`lineEnding`),l.consume(e),l.exit(`lineEnding`),l.attempt(o,b,_))}function b(e){return l.exit(n),u(e)}}function u(e,t,n){let a=0;return o;function o(t){return t===s.charCodeAt(a)?(e.enter(r),e.enter(i),c(t)):n(t)}function c(t){return a===s.length?(e.exit(i),H(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return H(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||B(i)?(e.exit(r),t(i)):n(i)}}}function qr(e,t){return e.marker?Jr(e.marker,t).repeat(3):Jr(e.fence,t)}function Jr(e,t){return typeof e==`string`?e:e[t]}function Yr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Xr(e){let t=Ur(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=Zr(e),r[e.type]=Qr,r[e.type+`Value`]=$r}return{enter:n,exit:r}}function Zr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Qr(e){let t=this.resume(),n=this.stack[this.stack.length-1];`value`in n,this.exit(e),n.value=t.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``)}function $r(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function ei(e){let t=[],n={},r=Ur(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=ti(e);let a=ni(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:Yr(a.charAt(1))})}return{unsafe:t,handlers:n}}function ti(e){let t=ni(e,`open`),n=ni(e,`close`);return r;function r(e){return t+(e.value?`
1042
+ `.trim();var Fn=class{name=`help`;async execute(e){return console.log(Pn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function In(e,t){let n=f.join(e,`.git`),r=d.existsSync(n);return r?t?.info(`version control detected`,{path:n}):t?.warn(`no version control detected, please use git to manage your shadow source project`,{path:e}),{hasGit:r,gitPath:n}}function Ln(e,t,n,r,i){if(n==null)return r;let a=f.relative(t,e),o=f.join(n,a);return d.existsSync(o)&&d.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),d.readFileSync(o,`utf8`)):r}function Rn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;d.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(d.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(Ut)){let o=t.path,l=f.join(e,o),u=f.dirname(l);if(!d.existsSync(u)){d.mkdirSync(u,{recursive:!0});let t=u;for(;t!==e&&!c.has(t);)c.add(t),i.push(t),r?.info(`created directory`,{path:t}),t=f.dirname(t)}if(d.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=Ln(l,e,n,t.content,r);d.writeFileSync(l,i,`utf8`),a.push(l),r?.info(`created file`,{path:l})}}return{success:!0,rootPath:e,createdDirs:i,createdFiles:a,existedDirs:o,existedFiles:s}}function zn(e){let t=e;return t.startsWith(`~`)&&(t=f.join(p.homedir(),t.slice(1))),f.normalize(t)}var Bn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=zn(n.workspaceDir),i=Rn(f.join(r,n.shadowSourceProject.name),{logger:t}),a=i.createdDirs.length===0&&i.createdFiles.length===0?`All ${i.existedDirs.length} directories and ${i.existedFiles.length} files already exist`:`Created ${i.createdDirs.length} directories and ${i.createdFiles.length} files (${i.existedDirs.length} dirs, ${i.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:i.createdDirs.length,filesCreated:i.createdFiles.length,dirsExisted:i.existedDirs.length,filesExisted:i.existedFiles.length}),{success:i.success,filesAffected:i.createdFiles.length,dirsAffected:i.createdDirs.length,message:a}}},Vn=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),n=Hn(t);return u.default.stdout.write(`${JSON.stringify(n)}\n`),t}};function Hn(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:[]}}function Un(){return`@truenine/memory-sync-cli`}function Wn(){return`https://registry.npmjs.org/${Un()}/latest`}function Gn(e){let t=e.replace(/^v/,``),n=/^(\d+)\.(\d+)\.(\d+)/.exec(t);return n==null?null:[Number.parseInt(n[1],10),Number.parseInt(n[2],10),Number.parseInt(n[3],10)]}function Kn(e,t){let n=Gn(e),r=Gn(t);if(n==null||r==null)return 0;for(let e=0;e<3;e++){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1}return 0}const qn=3e3;async function Jn(){let e=new AbortController,t=setTimeout(()=>e.abort(),qn);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(Wn(),{headers:{Accept:`application/json`},signal:e.signal});if(clearTimeout(t),!n.ok)return{error:`HTTP ${n.status}: ${n.statusText}`};let r=await n.json();return r.version==null?{error:`Invalid response: missing version field`}:{version:r.version}}catch(e){return clearTimeout(t),e instanceof Error?e.name===`TimeoutError`||e.name===`AbortError`?{error:`Request timeout after ${qn}ms`}:{error:e.message}:{error:`Unknown network error`}}}function Yn(){return`2026.10219.10049`}async function Xn(){let e=Yn();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await Jn();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=Kn(e,n);return r<0?{status:`outdated`,localVersion:e,remoteVersion:n}:r>0?{status:`development`,localVersion:e,remoteVersion:n}:{status:`current`,localVersion:e,remoteVersion:n}}function Zn(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Un()}@latest' to update.`);break;case`current`:e.error==null?t.info(`Version ${r} is up to date.`):t.error(`Version check failed: ${e.error}`);break;case`development`:i==null?t.debug(`Running in development mode, version check skipped.`):t.info(`Development version detected: ${r} > ${i}. Thanks for contributing!`);break}}function Qn(){return new Date().getMinutes()%2==0}function $n(e){Qn()&&Xn().then(t=>{(t.status===`outdated`||t.error!=null)&&Zn(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var er=class{name=`outdated`;async execute(e){let t=await Xn();return Zn(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},tr=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===bt.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let o=new Set(a.map(e=>e.name));for(let e of n)o.has(e.name)||a.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return u.default.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)`}}},nr=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};const rr={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 ir=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}({}),ar=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var or=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=p.platform();return{platform:e,arch:p.arch(),hostname:p.hostname(),homedir:p.homedir(),tmpdir:p.tmpdir(),type:p.type(),release:p.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return ar.Win;case`darwin`:return ar.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return ar.Linux;default:return ar.Unknown}}detectShellKind(){let e=(u.default.env.SHELL??u.default.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?ir.Bash:e.includes(`zsh`)?ir.Zsh:e.includes(`fish`)?ir.Fish:e.includes(`pwsh`)?ir.Pwsh:e.includes(`powershell`)?ir.PowerShell:e.includes(`cmd`)?ir.Cmd:e.endsWith(`/sh`)?ir.Sh:ir.Unknown}collectEnvContext(){return{...u.default.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...rr.default};return this.toolPreset===`claudeCode`?{...e,...rr.claudeCode}:this.toolPreset===`kiro`?{...e,...rr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let sr=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 cr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=sr.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}clear(){this.registrations.length=0,this.globalScope=null}};function lr(e){let t=[...e],n=t[0];n!=null&&ur(n)&&t.shift();let r=t[0];return r!=null&&dr(r)&&t.shift(),t}function ur(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replaceAll(`\\`,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function dr(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const fr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`,`plugins`]),pr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),mr=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function hr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=mr.get(n)??4;for(let e of t){let t=mr.get(e)??4;t<r&&(r=t,n=e)}return n}function gr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s,showFlag:c}=e;if(n)return new Mn;if(t)return new Fn;if(a!=null)return new nr(a);if(r===`version`)return new Mn;if(r===`help`)return new Fn;if(r===`outdated`)return new er;if(r===`init`)return new Bn;if(r===`dry-run`)return new kn;if(r===`clean`)return i?new On:new yt;if(r===`plugins`)return new tr;if(r===`config`&&c)return new Dn;if(r!==`config`||o.length>0)return new An;let l=[];for(let e of s){let t=e.indexOf(`=`);t>0&&l.push([e.slice(0,t),e.slice(t+1)])}return new En([...o,...l])}function _r(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,jsonFlag:!1,showFlag:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=pr.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--json`:t.jsonFlag=!0;break;case`--show`:t.showFlag=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;case`j`:t.jsonFlag=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,fr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var vr=class{logger;args;outputPlugins=[];constructor(...e){this.args=_r(lr(e.filter(e=>e!=null)));let t=hr(this.args);t!=null&&en(t),this.logger=nn(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){$n(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand();this.args.jsonFlag&&(en(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new Vn(i)));let a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return gr(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:d,path:f,glob:Je.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:d,path:f,glob:Je.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new Dt(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length===e.length)return a;throw new Et(this.findCyclePath(e,n))}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a.at(-1));return a.slice(e)}i.clear(),a.length=0}return[...n]}async executePluginsInOrder(e,t,n=!1,r){if(e.length===0)return{};let i=this.topologicalSort(e),a=new or({userConfig:r}).collect(),o=new cr;o.setGlobalScope(a),this.logger.debug(`global scope collected`,{osInfo:{platform:a.os.platform,arch:a.os.arch,shellKind:a.os.shellKind},hasProfile:Object.keys(a.profile).length>0,hasTool:Object.keys(a.tool).length>0});let s=new Map,c={};for(let e of i){let r=this.buildDependencyContext(e,s),i={...t,dependencyContext:r,globalScope:a,scopeRegistry:o},l=e;l.executeEffects!=null&&await l.executeEffects(i,n);let u=await e.collect(i);s.set(e.name,u),c=this.mergeContexts(c,u);let d=e;if(d.getRegisteredScopes!=null){let t=d.getRegisteredScopes();for(let{namespace:n,values:r}of t)o.register(n,r,sr.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(r)})}}return c}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let{workspace:n}=e;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:[...e.values()]}}else ({workspace:n}=t);let r=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],i=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],a=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],o=t.skills==null?e.skills:[...e.skills??[],...t.skills],s=t.rules==null?e.rules:[...e.rules??[],...t.rules],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts],f=t.globalGitIgnore??e.globalGitIgnore,p=t.shadowGitExclude??e.shadowGitExclude;return{...n==null?{}:{workspace:n},...r==null?{}:{ideConfigFiles:r},...i==null?{}:{fastCommands:i},...a==null?{}:{subAgents:a},...o==null?{}:{skills:o},...s==null?{}:{rules:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d},...f==null?{}:{globalGitIgnore:f},...p==null?{}:{shadowGitExclude:p}}}};const yr={name:`tnmsc-shadow`,skill:{src:`src/skills`,dist:`dist/skills`},fastCommand:{src:`src/commands`,dist:`dist/commands`},subAgent:{src:`src/agents`,dist:`dist/agents`},rule:{src:`src/rules`,dist:`dist/rules`},globalMemory:{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:{src:`app`,dist:`dist/app`}},br={...Wt,shadowSourceProject:yr,fastCommandSeriesOptions:{},plugins:[]};function xr(e){return{...e.version==null?{}:{version:e.version},...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProject==null?{}:{shadowSourceProject:e.shadowSourceProject},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function Sr(...e){return e.reduce((e,t)=>Cr(e,t),{...br})}function Cr(e,t){let n=t.plugins,r=t.fastCommandSeriesOptions;return{...e,...t,shadowSourceProject:wr(e.shadowSourceProject,t.shadowSourceProject),plugins:[...e.plugins,...n??[]],fastCommandSeriesOptions:Tr(e.fastCommandSeriesOptions,r)}}function wr(e,t){return t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}function Tr(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function Er(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Dr(e={}){hn().shouldExit&&u.default.exit(1);let t,n,r;Er(e)?({pluginOptions:r={},cwd:n}={pluginOptions:e.pluginOptions,cwd:e.cwd},t=e.loadUserConfig??!0):(r=e,t=!0);let i={},a=!1,o=[],s;if(t){let e=mn(n);a=e.found,o=e.sources,e.found&&(i=xr(e.config),s=e.config)}let c=Sr(i,r),{plugins:l=[],logLevel:p}=c,m=nn(`defineConfig`,p);a?m.info(`user config loaded`,{sources:o}):m.info(`no user config found, using defaults`,{workspaceDir:br.workspaceDir,shadowSourceProjectName:br.shadowSourceProject.name,logLevel:br.logLevel});let h={logger:m,userConfigOptions:c,fs:d,path:f,glob:Je.default},g=l.filter(e=>e.type===bt.Input),_=l.filter(e=>e.type===bt.Output),v=await new vr().executePluginsInOrder(g,h,!1,s);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...v.rules!=null&&{rules:v.rules},...v.globalMemory!=null&&{globalMemory:v.globalMemory},...v.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:v.aiAgentIgnoreConfigFiles},...v.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:v.shadowSourceProjectDir},...v.readmePrompts!=null&&{readmePrompts:v.readmePrompts},...v.globalGitIgnore!=null&&{globalGitIgnore:v.globalGitIgnore},...v.shadowGitExclude!=null&&{shadowGitExclude:v.shadowGitExclude}};return v.shadowSourceProjectDir!=null&&In(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:c}}const Or=Lr(/[A-Za-z]/),kr=Lr(/[\dA-Za-z]/),Ar=Lr(/[#-'*+\--9=?A-Z^-~]/);function jr(e){return e!==null&&(e<32||e===127)}const Mr=Lr(/\d/),Nr=Lr(/[\dA-Fa-f]/),Pr=Lr(/[!-/:-@[-`{-~]/);function B(e){return e!==null&&e<-2}function V(e){return e!==null&&(e<0||e===32)}function H(e){return e===-2||e===-1||e===32}const Fr=Lr(/\p{P}|\p{S}/u),Ir=Lr(/\s/);function Lr(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Rr=l(o(((e,t)=>{(function(){var e=t===void 0?function(){return this||(0,eval)(`this`)}():t.exports=i;e.format=i,e.vsprintf=r,typeof console<`u`&&typeof console.log==`function`&&(e.printf=n);function n(){console.log(i.apply(null,arguments))}function r(e,t){return i.apply(null,[e].concat(t))}function i(e){for(var t=1,n=[].slice.call(arguments),r=0,i=e.length,a=``,o,s=!1,c,l,u=!1,d,f=function(){return n[t++]},p=function(){for(var t=``;/\d/.test(e[r]);)t+=e[r++],o=e[r];return t.length>0?parseInt(t):null};r<i;++r)if(o=e[r],s)switch(s=!1,o==`.`?(u=!1,o=e[++r]):o==`0`&&e[r+1]==`.`?(u=!0,r+=2,o=e[r]):u=!0,d=p(),o){case`b`:a+=parseInt(f(),10).toString(2);break;case`c`:c=f(),typeof c==`string`||c instanceof String?a+=c:a+=String.fromCharCode(parseInt(c,10));break;case`d`:a+=parseInt(f(),10);break;case`f`:l=String(parseFloat(f()).toFixed(d||6)),a+=u?l:l.replace(/^0/,``);break;case`j`:a+=JSON.stringify(f());break;case`o`:a+=`0`+parseInt(f(),10).toString(8);break;case`s`:a+=f();break;case`x`:a+=`0x`+parseInt(f(),10).toString(16);break;case`X`:a+=`0x`+parseInt(f(),10).toString(16).toUpperCase();break;default:a+=o;break}else o===`%`?s=!0:a+=o;return a}})()}))(),1);const zr=Object.assign(Br(Error),{eval:Br(EvalError),range:Br(RangeError),reference:Br(ReferenceError),syntax:Br(SyntaxError),type:Br(TypeError),uri:Br(URIError)});function Br(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Rr.default)(t,...n))}}const Vr={}.hasOwnProperty,Hr={yaml:`-`,toml:`+`};function Ur(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Wr(r[n]);return t}function Wr(e){let t=e;if(typeof t==`string`){if(!Vr.call(Hr,t))throw zr("Missing matter definition for `%s`",t);t={type:t,marker:Hr[t]}}else if(typeof t!=`object`)throw zr("Expected matter to be an object, not `%j`",t);if(!Vr.call(t,`type`))throw zr("Missing `type` in matter `%j`",t);if(!Vr.call(t,`fence`)&&!Vr.call(t,`marker`))throw zr("Missing `marker` or `fence` in matter `%j`",t);return t}function Gr(e){let t=Ur(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=qr(e,`open`).charCodeAt(0),a=Kr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Kr(e){let t=e.anywhere,n=e.type,r=n+`Fence`,i=r+`Sequence`,a=n+`Value`,o={tokenize:u,partial:!0},s,c=0;return{tokenize:l,concrete:!0};function l(l,u,d){let f=this;return p;function p(a){let o=f.now();return o.column===1&&(o.line===1||t)&&(s=qr(e,`open`),c=0,a===s.charCodeAt(c))?(l.enter(n),l.enter(r),l.enter(i),m(a)):d(a)}function m(e){return c===s.length?(l.exit(i),H(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return H(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return B(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=qr(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||B(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||B(e)?(l.exit(a),y(e)):(l.consume(e),v)}function y(e){return e===null?d(e):(l.enter(`lineEnding`),l.consume(e),l.exit(`lineEnding`),l.attempt(o,b,_))}function b(e){return l.exit(n),u(e)}}function u(e,t,n){let a=0;return o;function o(t){return t===s.charCodeAt(a)?(e.enter(r),e.enter(i),c(t)):n(t)}function c(t){return a===s.length?(e.exit(i),H(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return H(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||B(i)?(e.exit(r),t(i)):n(i)}}}function qr(e,t){return e.marker?Jr(e.marker,t).repeat(3):Jr(e.fence,t)}function Jr(e,t){return typeof e==`string`?e:e[t]}function Yr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Xr(e){let t=Ur(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=Zr(e),r[e.type]=Qr,r[e.type+`Value`]=$r}return{enter:n,exit:r}}function Zr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Qr(e){let t=this.resume(),n=this.stack[this.stack.length-1];`value`in n,this.exit(e),n.value=t.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``)}function $r(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function ei(e){let t=[],n={},r=Ur(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=ti(e);let a=ni(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:Yr(a.charAt(1))})}return{unsafe:t,handlers:n}}function ti(e){let t=ni(e,`open`),n=ni(e,`close`);return r;function r(e){return t+(e.value?`
1043
1043
  `+e.value:``)+`
1044
1044
  `+n}}function ni(e,t){return e.marker?ri(e.marker,t).repeat(3):ri(e.fence,t)}function ri(e,t){return typeof e==`string`?e:e[t]}function ii(e){let t=this,n=e||`yaml`,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Gr(n)),a.push(Xr(n)),o.push(ei(n))}function ai(e,t){let n=String(e);if(typeof t!=`string`)throw TypeError(`Expected character`);let r=0,i=n.indexOf(t);for(;i!==-1;)r++,i=n.indexOf(t,i+t.length);return r}const oi=(function(e){if(e==null)return di;if(typeof e==`function`)return ui(e);if(typeof e==`object`)return Array.isArray(e)?si(e):ci(e);if(typeof e==`string`)return li(e);throw Error(`Expected function, string, or object as test`)});function si(e){let t=[],n=-1;for(;++n<e.length;)t[n]=oi(e[n]);return ui(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}function ci(e){let t=e;return ui(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function li(e){return ui(t);function t(t){return t&&t.type===e}}function ui(e){return t;function t(t,n,r){return!!(fi(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function di(){return!0}function fi(e){return typeof e==`object`&&!!e&&`type`in e}function pi(e){return`\x1B[33m`+e+`\x1B[39m`}const mi=[];function hi(e,t,n,r){let i;typeof t==`function`&&typeof n!=`function`?(r=n,n=t):i=t;let a=oi(i),o=r?-1:1;s(e,void 0,[])();function s(e,i,c){let l=e&&typeof e==`object`?e:{};if(typeof l.type==`string`){let t=typeof l.tagName==`string`?l.tagName:typeof l.name==`string`?l.name:void 0;Object.defineProperty(u,`name`,{value:`node (`+pi(e.type+(t?`<`+t+`>`:``))+`)`})}return u;function u(){let l=mi,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=gi(n(e,c)),l[0]===!1))return l;if(`children`in e&&e.children){let t=e;if(t.children&&l[0]!==`skip`)for(d=(r?t.children.length:-1)+o,f=c.concat(t);d>-1&&d<t.children.length;){let e=t.children[d];if(u=s(e,d,f)(),u[0]===!1)return u;d=typeof u[1]==`number`?u[1]:d+o}}return l}}}function gi(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?mi:[e]}function _i(e,t,n){let r=oi((n||{}).ignore||[]),i=vi(t),a=-1;for(;++a<i.length;)hi(e,`text`,o);function o(e,t){let n=-1,i;for(;++n<t.length;){let e=t[n],a=i?i.children:void 0;if(r(e,a?a.indexOf(e):void 0,i))return;i=e}if(i)return s(e,t)}function s(e,t){let n=t[t.length-1],r=i[a][0],o=i[a][1],s=0,c=n.children.indexOf(e),l=!1,u=[];r.lastIndex=0;let d=r.exec(e.value);for(;d;){let n=d.index,i={index:d.index,input:d.input,stack:[...t,e]},a=o(...d,i);if(typeof a==`string`&&(a=a.length>0?{type:`text`,value:a}:void 0),a===!1?r.lastIndex=n+1:(s!==n&&u.push({type:`text`,value:e.value.slice(s,n)}),Array.isArray(a)?u.push(...a):a&&u.push(a),s=n+d[0].length,l=!0),!r.global)break;d=r.exec(e.value)}return l?(s<e.value.length&&u.push({type:`text`,value:e.value.slice(s)}),n.children.splice(c,1,...u)):u=[e],c+u.length}}function vi(e){let t=[];if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([yi(e[0]),bi(e[1])])}return t}function yi(e){return typeof e==`string`?new RegExp(Yr(e),`g`):e}function bi(e){return typeof e==`function`?e:function(){return e}}const xi=`phrasing`,Si=[`autolink`,`link`,`image`,`label`];function Ci(){return{transforms:[ji],enter:{literalAutolink:Ti,literalAutolinkEmail:Ei,literalAutolinkHttp:Ei,literalAutolinkWww:Ei},exit:{literalAutolink:Ai,literalAutolinkEmail:ki,literalAutolinkHttp:Di,literalAutolinkWww:Oi}}}function wi(){return{unsafe:[{character:`@`,before:`[+\\-.\\w]`,after:`[\\-.\\w]`,inConstruct:xi,notInConstruct:Si},{character:`.`,before:`[Ww]`,after:`[\\-.\\w]`,inConstruct:xi,notInConstruct:Si},{character:`:`,before:`[ps]`,after:`\\/`,inConstruct:xi,notInConstruct:Si}]}}function Ti(e){this.enter({type:`link`,title:null,url:``,children:[]},e)}function Ei(e){this.config.enter.autolinkProtocol.call(this,e)}function Di(e){this.config.exit.autolinkProtocol.call(this,e)}function Oi(e){this.config.exit.data.call(this,e);let t=this.stack[this.stack.length-1];t.type,t.url=`http://`+this.sliceSerialize(e)}function ki(e){this.config.exit.autolinkEmail.call(this,e)}function Ai(e){this.exit(e)}function ji(e){_i(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Mi],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,Ni]],{ignore:[`link`,`linkReference`]})}function Mi(e,t,n,r,i){let a=``;if(!Ii(i)||(/^w/i.test(t)&&(n=t+n,t=``,a=`http://`),!Pi(n)))return!1;let o=Fi(n+r);if(!o[0])return!1;let s={type:`link`,title:null,url:a+t+o[0],children:[{type:`text`,value:t+o[0]}]};return o[1]?[s,{type:`text`,value:o[1]}]:s}function Ni(e,t,n,r){return!Ii(r,!0)||/[-\d_]$/.test(n)?!1:{type:`link`,title:null,url:`mailto:`+t+`@`+n,children:[{type:`text`,value:t+`@`+n}]}}function Pi(e){let t=e.split(`.`);return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function Fi(e){let t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(`)`),i=ai(e,`(`),a=ai(e,`)`);for(;r!==-1&&i>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(`)`),a++;return[e,n]}function Ii(e,t){let n=e.input.charCodeAt(e.index-1);return(e.index===0||Ir(n)||Fr(n))&&(!t||n!==47)}function Li(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}qi.peek=Ki;function Ri(){this.buffer()}function zi(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Bi(){this.buffer()}function Vi(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Hi(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Li(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ui(e){this.exit(e)}function Wi(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Li(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Gi(e){this.exit(e)}function Ki(){return`[`}function qi(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function Ji(){return{enter:{gfmFootnoteCallString:Ri,gfmFootnoteCall:zi,gfmFootnoteDefinitionLabelString:Bi,gfmFootnoteDefinition:Vi},exit:{gfmFootnoteCallString:Hi,gfmFootnoteCall:Ui,gfmFootnoteDefinitionLabelString:Wi,gfmFootnoteDefinition:Gi}}}function Yi(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:qi},unsafe:[{character:`[`,inConstruct:[`label`,`phrasing`,`reference`]}]};function n(e,n,r,i){let a=r.createTracker(i),o=a.move(`[^`),s=r.enter(`footnoteDefinition`),c=r.enter(`label`);return o+=a.move(r.safe(r.associationId(e),{before:o,after:`]`})),c(),o+=a.move(`]:`),e.children&&e.children.length>0&&(a.shift(4),o+=a.move((t?`
1045
1045
  `:` `)+r.indentLines(r.containerFlow(e,a.current()),t?Zi:Xi))),s(),o}}function Xi(e,t,n){return t===0?e:Zi(e,t,n)}function Zi(e,t,n){return(n?``:` `)+e}const Qi=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`];ra.peek=ia;function $i(){return{canContainEols:[`delete`],enter:{strikethrough:ta},exit:{strikethrough:na}}}function ea(){return{unsafe:[{character:`~`,inConstruct:`phrasing`,notInConstruct:Qi}],handlers:{delete:ra}}}function ta(e){this.enter({type:`delete`,children:[]},e)}function na(e){this.exit(e)}function ra(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ia(){return`~`}function aa(e){return e.length}function oa(e,t){let n=t||{},r=(n.align||[]).concat(),i=n.stringLength||aa,a=[],o=[],s=[],c=[],l=0,u=-1;for(;++u<e.length;){let t=[],r=[],a=-1;for(e[u].length>l&&(l=e[u].length);++a<e[u].length;){let o=sa(e[u][a]);if(n.alignDelimiters!==!1){let e=i(o);r[a]=e,(c[a]===void 0||e>c[a])&&(c[a]=e)}t.push(o)}o[u]=t,s[u]=r}let d=-1;if(typeof r==`object`&&`length`in r)for(;++d<l;)a[d]=ca(r[d]);else{let e=ca(r);for(;++d<l;)a[d]=e}d=-1;let f=[],p=[];for(;++d<l;){let e=a[d],t=``,r=``;e===99?(t=`:`,r=`:`):e===108?t=`:`:e===114&&(r=`:`);let i=n.alignDelimiters===!1?1:Math.max(1,c[d]-t.length-r.length),o=t+`-`.repeat(i)+r;n.alignDelimiters!==!1&&(i=t.length+i+r.length,i>c[d]&&(c[d]=i),p[d]=i),f[d]=o}o.splice(1,0,f),s.splice(1,0,p),u=-1;let m=[];for(;++u<o.length;){let e=o[u],t=s[u];d=-1;let r=[];for(;++d<l;){let i=e[d]||``,o=``,s=``;if(n.alignDelimiters!==!1){let e=c[d]-(t[d]||0),n=a[d];n===114?o=` `.repeat(e):n===99?e%2?(o=` `.repeat(e/2+.5),s=` `.repeat(e/2-.5)):(o=` `.repeat(e/2),s=o):s=` `.repeat(e)}n.delimiterStart!==!1&&!d&&r.push(`|`),n.padding!==!1&&!(n.alignDelimiters===!1&&i===``)&&(n.delimiterStart!==!1||d)&&r.push(` `),n.alignDelimiters!==!1&&r.push(o),r.push(i),n.alignDelimiters!==!1&&r.push(s),n.padding!==!1&&r.push(` `),(n.delimiterEnd!==!1||d!==l-1)&&r.push(`|`)}m.push(n.delimiterEnd===!1?r.join(``).replace(/ +$/,``):r.join(``))}return m.join(`
@@ -1225,9 +1225,9 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
1225
1225
  `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Dg=o((e=>{var t=yg(),n=ng(),r=rg(),i=Dh(),a=$(),o=Tg(),s=Eg();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Og=l(o((e=>{var t=yg(),n=ng(),r=eg(),i=rg(),a=vh(),o=$(),s=Ah(),c=yh(),l=Mh(),u=Ph();Cg();var d=wg(),f=Tg(),p=Eg(),m=Dg(),h=fh();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync}))(),1);function kg(e,t){let n=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!=null));return Object.keys(n).length===0?`---
1226
1226
  ---`:`---\n${Og.stringify(n,{singleQuote:t?.singleQuote??!1,lineWidth:t?.lineWidth??0}).trimEnd()}\n---`}function Ag(e,t,n){return e==null||Object.keys(e).length===0?t:`${kg(e,n)}\n${t}`}function jg(e){let t=dh(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){r=e.value;try{n=Og.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 Mg(e){return 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}`})}var Ng=class{type;name;_log;get log(){return this._log??=nn(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}},Pg=class extends Ng{globalConfigDir;outputFileName;indexignore;registryWriterCache=new Map;writeEffects=[];cleanEffects=[];constructor(e,t){super(e,bt.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``,this.indexignore=t?.indexignore}registerWriteEffect(e,t){this.writeEffects.push({name:e,handler:t})}registerCleanEffect(e,t){this.cleanEffects.push({name:e,handler:t})}async executeWriteEffects(e){let t=[];for(let n of this.writeEffects){if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`effect`,name:n.name}),t.push({success:!0,description:`Would execute write effect: ${n.name}`});continue}try{let r=await n.handler(e);if(r.success)this.log.trace({action:`effect`,name:n.name,status:`success`});else{let e=r.error instanceof Error?r.error.message:String(r.error);this.log.error({action:`effect`,name:n.name,status:`failed`,error:e})}t.push(r)}catch(e){let r=e instanceof Error?e.message:String(e);this.log.error({action:`effect`,name:n.name,status:`failed`,error:r}),t.push({success:!1,error:e,description:`Write effect failed: ${n.name}`})}}return t}async executeCleanEffects(e){let t=[];for(let n of this.cleanEffects){if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`effect`,name:n.name}),t.push({success:!0,description:`Would execute clean effect: ${n.name}`});continue}try{let r=await n.handler(e);if(r.success)this.log.trace({action:`effect`,name:n.name,status:`success`});else{let e=r.error instanceof Error?r.error.message:String(r.error);this.log.error({action:`effect`,name:n.name,status:`failed`,error:e})}t.push(r)}catch(e){let r=e instanceof Error?e.message:String(e);this.log.error({action:`effect`,name:n.name,status:`failed`,error:r}),t.push({success:!1,error:e,description:`Clean effect failed: ${n.name}`})}}return t}isRelativePath(e){return e.pathKind===L.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:L.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let n;n=e.pathKind===L.Absolute?e.path:this.isRelativePath(e)?f.resolve(e.basePath,e.path):f.resolve(u.default.cwd(),e.path);let r=t??this.outputFileName;return r?f.join(n,r):n}createRelativePath(e,t,n){return ct(e,t,n)}createFileRelativePath(e,t){return lt(e,t)}getGlobalConfigDir(){return f.join(this.getHomeDir(),this.globalConfigDir)}getHomeDir(){return p.homedir()}joinPath(...e){return f.join(...e)}resolvePath(...e){return f.resolve(...e)}dirname(e){return f.dirname(e)}basename(e,t){return f.basename(e,t)}writeFileSync(e,t,n=`utf8`){it(e,t,n)}writeFileSyncBuffer(e,t){it(e,t)}ensureDirectory(e){$e(e)}existsSync(e){return d.existsSync(e)}lstatSync(e){return Qe(e)}isSymlink(e){return Ze(e)}createSymlink(e,t,n=`dir`){tt(e,t,n)}removeSymlink(e){nt(e)}async writeDirectorySymlink(e,t,n,r){let i=f.dirname(n),a=ct(f.basename(n),i,()=>f.basename(i));if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`symlink`,target:t,link:n,label:r}),{path:a,success:!0,skipped:!1};try{return this.createSymlink(t,n,`dir`),this.log.trace({action:`write`,type:`symlink`,target:t,link:n,label:r}),{path:a,success:!0}}catch(e){let i=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`symlink`,target:t,link:n,label:r,error:i}),{path:a,success:!1,error:e}}}readdirSync(e,t){return t?.withFileTypes===!0?d.readdirSync(e,{withFileTypes:!0}):d.readdirSync(e)}getIgnoreOutputPath(){if(this.indexignore!=null)return this.indexignore===`.traeignore`?f.join(`.trae`,`.ignore`):this.indexignore}registerProjectIgnoreOutputFiles(e){let t=this.getIgnoreOutputPath();if(t==null)return[];let n=[];for(let r of e){let e=r.dirFromWorkspacePath;if(e==null||r.isPromptSourceProject===!0)continue;let i=f.join(e.path,t);n.push({pathKind:L.Relative,path:i,basePath:e.basePath,getDirectoryName:()=>f.basename(e.path),getAbsolutePath:()=>f.join(e.basePath,i)})}return n}async writeProjectIgnoreFiles(e){let t=this.getIgnoreOutputPath();if(t==null)return[];let{workspace:n,aiAgentIgnoreConfigFiles:r}=e.collectedInputContext,i=[];if(r==null||r.length===0)return i;let a=r.find(e=>e.fileName===this.indexignore);if(a==null)return i;for(let r of n.projects){let n=r.dirFromWorkspacePath;if(n==null||r.isPromptSourceProject===!0)continue;let o=`project:${r.name??`unknown`}/${a.fileName}`,s=f.join(n.path,t),c=f.join(n.basePath,s),l={pathKind:L.Relative,path:s,basePath:n.basePath,getDirectoryName:()=>f.basename(n.path),getAbsolutePath:()=>c};if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`ignoreFile`,path:c,label:o}),i.push({path:l,success:!0,skipped:!1});continue}try{if(t===f.join(`.trae`,`.ignore`)){let e=f.join(n.basePath,n.path,`.trae`);d.mkdirSync(e,{recursive:!0})}d.writeFileSync(c,a.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:c,label:o}),i.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`ignoreFile`,path:c,label:o,error:t}),i.push({path:l,success:!1,error:e})}}return i}async writeFile(e,t,n,r){let i=f.dirname(t),a=ct(f.basename(t),i,()=>f.basename(i));if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`file`,path:t,label:r}),{path:a,success:!0,skipped:!1};try{return it(t,n),this.log.trace({action:`write`,type:`file`,path:t,label:r}),{path:a,success:!0}}catch(e){let n=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`file`,path:t,label:r,error:n}),{path:a,success:!1,error:e}}}async writePromptFile(e,t,n,r){let i=this.resolveFullPath(t),a=this.toRelativePath(t);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`promptFile`,path:i,label:r}),{path:a,success:!0,skipped:!1};try{return it(i,n),this.log.trace({action:`write`,type:`promptFile`,path:i,label:r}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`promptFile`,path:i,label:r,error:t}),{path:a,success:!1,error:e}}}buildMarkdownContent(e,t){return Ag(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Ag(t,e):n!=null&&n.length>0?`---\n${n}\n---\n${e}`:e}extractGlobalMemoryContent(e){return e.collectedInputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
1227
1227
 
1228
- `,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,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.getFastCommandSeriesOptions(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)}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i}),await this.executeWriteEffects(e)}async onCleanComplete(e){await this.executeCleanEffects(e)}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)}};const Fg=`AGENTS.md`;var Ig=class extends Pg{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Fg})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Fg)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Fg));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}},Lg=class extends Ng{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,bt.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,shadowProjectDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:m.spawn,userConfigOptions:e.userConfigOptions,workspaceDir:r,shadowProjectDir: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{let n=t.error instanceof Error?t.error.message:String(t.error);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:n})}n.push(t)}catch(t){let r=t instanceof Error?t.message:String(t);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:r}),n.push({success:!1,error:t,description:`Input effect failed: ${e.name}`})}}return n}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,n=this.resolvePath(t,``),r=e.shadowSourceProject.name;return{workspaceDir:n,shadowProjectDir:f.join(n,r)}}resolvePath(e,t){let n=e;return n.startsWith(R.USER_HOME)&&(n=n.replace(R.USER_HOME,p.homedir())),n.includes(R.WORKSPACE)&&(n=n.replace(R.WORKSPACE,t)),f.normalize(n)}resolveShadowPath(e,t){return f.join(t,e)}readAndParseMarkdown(e,t){return jg(t.readFileSync(e,`utf8`))}};const Rg=[`.qoderignore`,`.cursorignore`,`.kiroignore`,`.warpindexignore`,`.aiignore`,`.codeignore`,`.traeignore`];var zg=class extends Lg{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Rg){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const Bg=`.agent`,Vg=`antigravity`,Hg=`skills`,Ug=`workflows`,Wg=`mcp_config.json`,Gg=[Hg,Ug];var Kg=class extends Pg{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Bg,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=f.join(this.getAntigravityDir(),Wg),n=JSON.stringify({mcpServers:{}},null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:t}),{success:!0,description:`Would reset mcp_config.json`};let r=await this.writeFile(e,t,n,`mcpConfigCleanup`);return r.success?{success:!0,description:`Reset mcp_config.json`}:{success:!1,description:`Failed`,error:r.error??Error(`Cleanup failed`)}})}getAntigravityDir(){return f.join(p.homedir(),`.gemini`,Vg)}async registerProjectOutputDirs(e){let{projects:t}=e.collectedInputContext.workspace,n=[];for(let e of t)if(e.dirFromWorkspacePath!=null)for(let t of Gg)n.push(this.createRelativePath(f.join(e.dirFromWorkspacePath.path,Bg,t),e.dirFromWorkspacePath.basePath,()=>t));return n}async registerProjectOutputFiles(e){let{skills:t,fastCommands:n}=e.collectedInputContext,r=this.getAntigravityDir(),i=[];if(t!=null)for(let e of t){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),n=f.join(r,Hg,t);if(i.push(this.createRelativePath(`SKILL.md`,n,()=>t)),e.childDocs!=null)for(let r of e.childDocs)i.push(this.createRelativePath(r.dir.path.replace(/\.mdx$/,`.md`),n,()=>t));if(e.resources!=null)for(let r of e.resources)i.push(this.createRelativePath(r.relativePath,n,()=>t))}if(t?.some(e=>e.mcpConfig!=null)&&i.push(this.createRelativePath(Wg,r,()=>Vg)),n==null)return i;let a=this.getTransformOptionsFromContext(e),o=f.join(r,Ug);for(let e of n)i.push(this.createRelativePath(this.transformFastCommandName(e,a),o,()=>Ug));return i}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext;return(t?.length??0)>0||(n?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=this.getAntigravityDir();if(t!=null){let n=f.join(i,Ug);for(let i of t)r.push(await this.writeFastCommand(e,n,i))}if(n!=null){let t=f.join(i,Hg);for(let i of n)r.push(...await this.writeSkill(e,t,i));let a=await this.writeGlobalMcpConfig(e,i,n);a!=null&&r.push(a)}return this.log.info({action:`write`,message:`Synced ${r.length} files`,globalDir:i}),{files:r,dirs:[]}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n)if(e.mcpConfig!=null)for(let[t,n]of Object.entries(e.mcpConfig.mcpServers))r[t]=this.transformMcpConfig(n);if(Object.keys(r).length===0)return null;let i=f.join(t,Wg),a=JSON.stringify({mcpServers:r},null,2);return this.writeFile(e,i,a,`globalMcpConfig`)}transformMcpConfig(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.serverUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,i),o=typeof n.yamlFrontMatter?.description==`string`?{description:n.yamlFrontMatter.description}:{},s;if(n.rawMdxContent!=null){let e=n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``);s=this.buildMarkdownContentWithRaw(e,o,n.rawFrontMatter)}else s=this.buildMarkdownContentWithRaw(n.content,o,n.rawFrontMatter);return this.writeFile(e,a,s,`fastCommand`)}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,i),o=f.join(a,`SKILL.md`),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(r.push(await this.writeFile(e,o,s,`skill`)),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`);r.push(await this.writeFile(e,f.join(a,n),t.content,`skillRefDoc`))}if(n.resources!=null)for(let t of n.resources)r.push(await this.writeFile(e,f.join(a,t.relativePath),t.content,`skillResource`));return r}},qg=class extends Error{constructor(e,t,n){super(e),this.expression=t,this.filePath=n,this.name=`ScopeError`}},Jg=class extends qg{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`}},Yg=class extends qg{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`}},Xg=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`}},Zg=Object.defineProperty,Qg=(e,t)=>{let n={};for(var r in e)Zg(n,r,{get:e[r],enumerable:!0});return t||Zg(n,Symbol.toStringTag,{value:`Module`}),n};const $g=new Map;function e_(e,t){$g.set(e,t)}function t_(){return new Map($g)}function n_(e){return $g.has(e)}function r_(e,t,n){let r=e.trim();return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?i_(r,t,n?.filePath):a_(r,t,n?.filePath)}function i_(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new Yg(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 Jg(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 Jg(i,e,n);a=o[i]}return o_(a)}function a_(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return o_(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 Yg(t[1],e,n)}let i=n==null?``:` (file: ${n})`;throw Error(`Failed to evaluate expression: "${e}"${i}\nCause: ${r}`)}}function o_(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 s_(e,t){return e===null?!1:t.components.has(e)||n_(e)}async function c_(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function l_(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 c_(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 u_(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return p_(e,t);case`a`:return m_(e,t);case`strong`:case`b`:return h_(e,t);case`em`:case`i`:return g_(e,t);case`img`:return __(e,t);case`blockquote`:return v_(e,t);default:return null}}function d_(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`?r_(r.value.value,n.scope):r.value===null?``:null}function f_(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=r_(r.value,t.scope):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=f_(r,t));return n}function p_(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=d_(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=f_(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function m_(e,t){let n=d_(e,`href`,t);if(n==null||n===``)return null;let r=f_(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:d_(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function h_(e,t){let n={type:`strong`,children:[{type:`text`,value:f_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function g_(e,t){let n={type:`emphasis`,children:[{type:`text`,value:f_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function __(e,t){let n=d_(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:d_(e,`alt`,t)??``,title:d_(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function v_(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:f_(e,t)}]}]}]}function y_(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function b_(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`?x_(i.expression,t,n):[]}async function x_(e,t,n){return e.type===`JSXElement`?D_(e,t,n):e.type===`JSXFragment`?O_(e,t,n):e.type===`LogicalExpression`?S_(e,t,n):e.type===`ConditionalExpression`?C_(e,t,n):e.type===`SequenceExpression`?w_(e,t,n):e.type===`ArrayExpression`?T_(e,t,n):L_(e,t)}async function S_(e,t,n){let r=await E_(e.left,t,n);return e.operator===`&&`?F_(r)?x_(e.right,t,n):[]:e.operator===`||`?F_(r)?P_(e.left)?x_(e.left,t,n):I_(r):x_(e.right,t,n):e.operator===`??`?r==null?x_(e.right,t,n):P_(e.left)?x_(e.left,t,n):I_(r):[]}async function C_(e,t,n){return F_(await E_(e.test,t,n))?x_(e.consequent,t,n):x_(e.alternate,t,n)}async function w_(e,t,n){let r=[];for(let i of e.expressions){let e=await x_(i,t,n);r.push(...e)}return r}async function T_(e,t,n){let r=[];for(let i of e.elements)if(i!=null)if(i.type===`SpreadElement`){let e=await x_(i.argument,t,n);r.push(...e)}else{let e=await x_(i,t,n);r.push(...e)}return r}async function E_(e,t,n){if(P_(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 E_(e.argument,t,n);return e.operator===`!`?!F_(r):e.operator===`-`?-r:e.operator===`+`?+r:e.operator===`typeof`?typeof r:void 0}if(e.type===`BinaryExpression`){let r=await E_(e.left,t,n),i=await E_(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 E_(e.left,t,n);return e.operator===`&&`?F_(r)?E_(e.right,t,n):r:e.operator===`||`?F_(r)?r:E_(e.right,t,n):e.operator===`??`?r??E_(e.right,t,n):void 0}if(e.type===`MemberExpression`){let r=await E_(e.object,t,n);if(r==null)return;if(e.computed)return r[await E_(e.property,t,n)];let{name:i}=e.property;return r[i]}if(e.type===`ConditionalExpression`)return F_(await E_(e.test,t,n))?E_(e.consequent,t,n):E_(e.alternate,t,n);let r=N_(e);if(r!==``)try{let e=r_(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 D_(e,t,n){let r=A_(e,t);if(r.name!=null&&s_(r.name,t)){let{processAst:e}=await Promise.resolve().then(()=>R_);return l_(r,t,e)}return u_(r,t)??(r.children.length>0?n(r.children,t):[])}async function O_(e,t,n){let r=[];for(let i of e.children){let e=await k_(i,t,n);r.push(...e)}return r}async function k_(e,t,n){if(e.type===`JSXElement`)return D_(e,t,n);if(e.type===`JSXFragment`)return O_(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`?[]:x_(e.expression,t,n):e.type===`JSXSpreadChild`?x_(e.expression,t,n):[]}function A_(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=j_(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:N_(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${N_(e.argument)}`});let a=[];for(let n of e.children){let e=M_(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function j_(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${j_(e.object)}.${e.property.name}`}function M_(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[A_(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=M_(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:N_(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${N_(e.expression)}`}]}]:null}function N_(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=N_(e.object);return e.computed?`${t}[${N_(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${N_(e.callee)}(${e.arguments.map(e=>N_(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=N_(e.left),n=N_(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=N_(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${N_(e.test)} ? ${N_(e.consequent)} : ${N_(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>N_(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:N_(e.key)}: ${N_(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+=`\${${N_(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${N_(e.argument)}`:``}function P_(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function F_(e){return!!e}function I_(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 L_(e,t){let n=N_(e);if(n===``)return[];try{return I_(r_(n,t.scope))}catch{return[]}}var R_=Qg({processAst:()=>B_});function z_(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function B_(e,t){return V_(e,t)}async function V_(e,t){let n=[];for(let r of e.children){let e=await H_(r,t);n.push(...e)}return{type:`root`,children:n}}async function H_(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(y_(r))return b_(n,t,async(e,t)=>(await B_({type:`root`,children:e},t)).children);let a=r_(n.value,t.scope);return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return U_(e,t);if(e.type===`link`){let n=e,r=(await W_(n.children,t)).map(e=>e.type===`text`?{...e,value:z_(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await W_(e.children,t);return[{...e,children:n}]}async function U_(e,t){return e.name!=null&&s_(e.name,t)?l_(e,t,B_):u_(e,t)??[]}async function W_(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(y_(i)){let r=await b_(e,t,async(e,t)=>(await B_({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=r_(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:r_(e.value,t.scope)};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&s_(e.name,t)){let r=await l_(e,t,B_);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=u_(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 W_(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:z_(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function G_(e){let t=this;t.compiler=n;function n(n){return Bo(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function K_(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=q_(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 q_(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=J_(i,e);if(o!=null)try{let e=Y_(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=J_(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=Y_(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 J_(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===`
1228
+ `,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,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.getFastCommandSeriesOptions(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)}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i}),await this.executeWriteEffects(e)}async onCleanComplete(e){await this.executeCleanEffects(e)}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`}};const Fg=`AGENTS.md`;var Ig=class extends Pg{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Fg})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Fg)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Fg));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}},Lg=class extends Ng{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,bt.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,shadowProjectDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:m.spawn,userConfigOptions:e.userConfigOptions,workspaceDir:r,shadowProjectDir: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{let n=t.error instanceof Error?t.error.message:String(t.error);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:n})}n.push(t)}catch(t){let r=t instanceof Error?t.message:String(t);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:r}),n.push({success:!1,error:t,description:`Input effect failed: ${e.name}`})}}return n}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,n=this.resolvePath(t,``),r=e.shadowSourceProject.name;return{workspaceDir:n,shadowProjectDir:f.join(n,r)}}resolvePath(e,t){let n=e;return n.startsWith(R.USER_HOME)&&(n=n.replace(R.USER_HOME,p.homedir())),n.includes(R.WORKSPACE)&&(n=n.replace(R.WORKSPACE,t)),f.normalize(n)}resolveShadowPath(e,t){return f.join(t,e)}readAndParseMarkdown(e,t){return jg(t.readFileSync(e,`utf8`))}};const Rg=[`.qoderignore`,`.cursorignore`,`.kiroignore`,`.warpindexignore`,`.aiignore`,`.codeignore`,`.traeignore`];var zg=class extends Lg{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Rg){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const Bg=`.agent`,Vg=`antigravity`,Hg=`skills`,Ug=`workflows`,Wg=`mcp_config.json`,Gg=[Hg,Ug];var Kg=class extends Pg{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Bg,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=f.join(this.getAntigravityDir(),Wg),n=JSON.stringify({mcpServers:{}},null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:t}),{success:!0,description:`Would reset mcp_config.json`};let r=await this.writeFile(e,t,n,`mcpConfigCleanup`);return r.success?{success:!0,description:`Reset mcp_config.json`}:{success:!1,description:`Failed`,error:r.error??Error(`Cleanup failed`)}})}getAntigravityDir(){return f.join(p.homedir(),`.gemini`,Vg)}async registerProjectOutputDirs(e){let{projects:t}=e.collectedInputContext.workspace,n=[];for(let e of t)if(e.dirFromWorkspacePath!=null)for(let t of Gg)n.push(this.createRelativePath(f.join(e.dirFromWorkspacePath.path,Bg,t),e.dirFromWorkspacePath.basePath,()=>t));return n}async registerProjectOutputFiles(e){let{skills:t,fastCommands:n}=e.collectedInputContext,r=this.getAntigravityDir(),i=[];if(t!=null)for(let e of t){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),n=f.join(r,Hg,t);if(i.push(this.createRelativePath(`SKILL.md`,n,()=>t)),e.childDocs!=null)for(let r of e.childDocs)i.push(this.createRelativePath(r.dir.path.replace(/\.mdx$/,`.md`),n,()=>t));if(e.resources!=null)for(let r of e.resources)i.push(this.createRelativePath(r.relativePath,n,()=>t))}if(t?.some(e=>e.mcpConfig!=null)&&i.push(this.createRelativePath(Wg,r,()=>Vg)),n==null)return i;let a=this.getTransformOptionsFromContext(e),o=f.join(r,Ug);for(let e of n)i.push(this.createRelativePath(this.transformFastCommandName(e,a),o,()=>Ug));return i}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext;return(t?.length??0)>0||(n?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=this.getAntigravityDir();if(t!=null){let n=f.join(i,Ug);for(let i of t)r.push(await this.writeFastCommand(e,n,i))}if(n!=null){let t=f.join(i,Hg);for(let i of n)r.push(...await this.writeSkill(e,t,i));let a=await this.writeGlobalMcpConfig(e,i,n);a!=null&&r.push(a)}return this.log.info({action:`write`,message:`Synced ${r.length} files`,globalDir:i}),{files:r,dirs:[]}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n)if(e.mcpConfig!=null)for(let[t,n]of Object.entries(e.mcpConfig.mcpServers))r[t]=this.transformMcpConfig(n);if(Object.keys(r).length===0)return null;let i=f.join(t,Wg),a=JSON.stringify({mcpServers:r},null,2);return this.writeFile(e,i,a,`globalMcpConfig`)}transformMcpConfig(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.serverUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,i),o=typeof n.yamlFrontMatter?.description==`string`?{description:n.yamlFrontMatter.description}:{},s;if(n.rawMdxContent!=null){let e=n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``);s=this.buildMarkdownContentWithRaw(e,o,n.rawFrontMatter)}else s=this.buildMarkdownContentWithRaw(n.content,o,n.rawFrontMatter);return this.writeFile(e,a,s,`fastCommand`)}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,i),o=f.join(a,`SKILL.md`),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(r.push(await this.writeFile(e,o,s,`skill`)),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`);r.push(await this.writeFile(e,f.join(a,n),t.content,`skillRefDoc`))}if(n.resources!=null)for(let t of n.resources)r.push(await this.writeFile(e,f.join(a,t.relativePath),t.content,`skillResource`));return r}},qg=class extends Error{constructor(e,t,n){super(e),this.expression=t,this.filePath=n,this.name=`ScopeError`}},Jg=class extends qg{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`}},Yg=class extends qg{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`}},Xg=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`}},Zg=Object.defineProperty,Qg=(e,t)=>{let n={};for(var r in e)Zg(n,r,{get:e[r],enumerable:!0});return t||Zg(n,Symbol.toStringTag,{value:`Module`}),n};const $g=new Map;function e_(e,t){$g.set(e,t)}function t_(){return new Map($g)}function n_(e){return $g.has(e)}function r_(e,t,n){let r=e.trim();return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?i_(r,t,n?.filePath):a_(r,t,n?.filePath)}function i_(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new Yg(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 Jg(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 Jg(i,e,n);a=o[i]}return o_(a)}function a_(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return o_(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 Yg(t[1],e,n)}let i=n==null?``:` (file: ${n})`;throw Error(`Failed to evaluate expression: "${e}"${i}\nCause: ${r}`)}}function o_(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 s_(e,t){return e===null?!1:t.components.has(e)||n_(e)}async function c_(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function l_(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 c_(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 u_(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return p_(e,t);case`a`:return m_(e,t);case`strong`:case`b`:return h_(e,t);case`em`:case`i`:return g_(e,t);case`img`:return __(e,t);case`blockquote`:return v_(e,t);default:return null}}function d_(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`?r_(r.value.value,n.scope):r.value===null?``:null}function f_(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=r_(r.value,t.scope):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=f_(r,t));return n}function p_(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=d_(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=f_(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function m_(e,t){let n=d_(e,`href`,t);if(n==null||n===``)return null;let r=f_(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:d_(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function h_(e,t){let n={type:`strong`,children:[{type:`text`,value:f_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function g_(e,t){let n={type:`emphasis`,children:[{type:`text`,value:f_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function __(e,t){let n=d_(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:d_(e,`alt`,t)??``,title:d_(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function v_(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:f_(e,t)}]}]}]}function y_(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function b_(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`?x_(i.expression,t,n):[]}async function x_(e,t,n){return e.type===`JSXElement`?D_(e,t,n):e.type===`JSXFragment`?O_(e,t,n):e.type===`LogicalExpression`?S_(e,t,n):e.type===`ConditionalExpression`?C_(e,t,n):e.type===`SequenceExpression`?w_(e,t,n):e.type===`ArrayExpression`?T_(e,t,n):L_(e,t)}async function S_(e,t,n){let r=await E_(e.left,t,n);return e.operator===`&&`?F_(r)?x_(e.right,t,n):[]:e.operator===`||`?F_(r)?P_(e.left)?x_(e.left,t,n):I_(r):x_(e.right,t,n):e.operator===`??`?r==null?x_(e.right,t,n):P_(e.left)?x_(e.left,t,n):I_(r):[]}async function C_(e,t,n){return F_(await E_(e.test,t,n))?x_(e.consequent,t,n):x_(e.alternate,t,n)}async function w_(e,t,n){let r=[];for(let i of e.expressions){let e=await x_(i,t,n);r.push(...e)}return r}async function T_(e,t,n){let r=[];for(let i of e.elements)if(i!=null)if(i.type===`SpreadElement`){let e=await x_(i.argument,t,n);r.push(...e)}else{let e=await x_(i,t,n);r.push(...e)}return r}async function E_(e,t,n){if(P_(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 E_(e.argument,t,n);return e.operator===`!`?!F_(r):e.operator===`-`?-r:e.operator===`+`?+r:e.operator===`typeof`?typeof r:void 0}if(e.type===`BinaryExpression`){let r=await E_(e.left,t,n),i=await E_(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 E_(e.left,t,n);return e.operator===`&&`?F_(r)?E_(e.right,t,n):r:e.operator===`||`?F_(r)?r:E_(e.right,t,n):e.operator===`??`?r??E_(e.right,t,n):void 0}if(e.type===`MemberExpression`){let r=await E_(e.object,t,n);if(r==null)return;if(e.computed)return r[await E_(e.property,t,n)];let{name:i}=e.property;return r[i]}if(e.type===`ConditionalExpression`)return F_(await E_(e.test,t,n))?E_(e.consequent,t,n):E_(e.alternate,t,n);let r=N_(e);if(r!==``)try{let e=r_(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 D_(e,t,n){let r=A_(e,t);if(r.name!=null&&s_(r.name,t)){let{processAst:e}=await Promise.resolve().then(()=>R_);return l_(r,t,e)}return u_(r,t)??(r.children.length>0?n(r.children,t):[])}async function O_(e,t,n){let r=[];for(let i of e.children){let e=await k_(i,t,n);r.push(...e)}return r}async function k_(e,t,n){if(e.type===`JSXElement`)return D_(e,t,n);if(e.type===`JSXFragment`)return O_(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`?[]:x_(e.expression,t,n):e.type===`JSXSpreadChild`?x_(e.expression,t,n):[]}function A_(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=j_(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:N_(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${N_(e.argument)}`});let a=[];for(let n of e.children){let e=M_(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function j_(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${j_(e.object)}.${e.property.name}`}function M_(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[A_(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=M_(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:N_(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${N_(e.expression)}`}]}]:null}function N_(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=N_(e.object);return e.computed?`${t}[${N_(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${N_(e.callee)}(${e.arguments.map(e=>N_(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=N_(e.left),n=N_(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=N_(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${N_(e.test)} ? ${N_(e.consequent)} : ${N_(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>N_(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:N_(e.key)}: ${N_(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+=`\${${N_(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${N_(e.argument)}`:``}function P_(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function F_(e){return!!e}function I_(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 L_(e,t){let n=N_(e);if(n===``)return[];try{return I_(r_(n,t.scope))}catch{return[]}}var R_=Qg({processAst:()=>B_});function z_(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function B_(e,t){return V_(e,t)}async function V_(e,t){let n=[];for(let r of e.children){let e=await H_(r,t);n.push(...e)}return{type:`root`,children:n}}async function H_(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(y_(r))return b_(n,t,async(e,t)=>(await B_({type:`root`,children:e},t)).children);let a=r_(n.value,t.scope);return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return U_(e,t);if(e.type===`link`){let n=e,r=(await W_(n.children,t)).map(e=>e.type===`text`?{...e,value:z_(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await W_(e.children,t);return[{...e,children:n}]}async function U_(e,t){return e.name!=null&&s_(e.name,t)?l_(e,t,B_):u_(e,t)??[]}async function W_(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(y_(i)){let r=await b_(e,t,async(e,t)=>(await B_({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=r_(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:r_(e.value,t.scope)};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&s_(e.name,t)){let r=await l_(e,t,B_);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=u_(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 W_(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:z_(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function G_(e){let t=this;t.compiler=n;function n(n){return Bo(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function K_(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=q_(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 q_(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=J_(i,e);if(o!=null)try{let e=Y_(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=J_(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=Y_(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 J_(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===`
1229
1229
  `){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 Y_(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 X_(r.slice(1,-1),`"`);if(r.startsWith(`'`)&&r.endsWith(`'`))return X_(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 X_(e,"`")}if(r.startsWith(`[`)&&r.endsWith(`]`))return Q_(r,t,n);if(r.startsWith(`{`)&&r.endsWith(`}`))return $_(r,t,n);if(/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r))return Z_(r,t,n);let i=n==null?``:` in file "${n}"`;throw Error(`Expression "${r}" cannot be statically evaluated${i}`)}function X_(e,t){return e.replaceAll(`\\n`,`
1230
- `).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function Z_(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 Q_(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=ev(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return tv(r).map(e=>Y_(e.trim(),t,n))}function $_(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=ev(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=nv(r);for(let e of a){let r=rv(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]=Y_(o,t,n)}return i}function ev(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 tv(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 nv(e){return tv(e)}function rv(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 iv(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=r_(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function av(e,t,n){return!iv(e,t)||e.children.length===0?[]:n(e.children,t)}async function ov(e,t){if(!iv(e,t)||e.children.length===0)return[];let n=sv(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function sv(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=r_(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=sv(r.children,t));return n}function cv(){e_(`Md`,av),e_(`Md.Line`,ov)}cv();function lv(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 uv(e,t){let n=dh(e),r=lv(t?.globalScope,t?.scope),i=t_(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Og.parse(e.value)}catch{}a=K_(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 B_(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=pu().use(ii,[`yaml`]).use(ql).use(G_,{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}var dv=class extends Pg{commandsSubDir;agentsSubDir;skillsSubDir;supportsFastCommands;supportsSubAgents;supportsSkills;toolPreset;constructor(e,t){super(e,t),this.commandsSubDir=t.commandsSubDir??`commands`,this.agentsSubDir=t.agentsSubDir??`agents`,this.skillsSubDir=t.skillsSubDir??`skills`,this.supportsFastCommands=t.supportsFastCommands??!0,this.supportsSubAgents=t.supportsSubAgents??!0,this.supportsSkills=t.supportsSkills??!0,t.toolPreset!==void 0&&(this.toolPreset=t.toolPreset)}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=[];this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir);for(let e of r)n.push(this.createRelativePath(e,t,()=>e));return n}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=[];if(this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir),r.length===0)return[];for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of r){let r=f.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push(this.createRelativePath(r,e.dirFromWorkspacePath.basePath,()=>n))}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,this.outputFileName)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,this.outputFileName));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir(),r=[this.createRelativePath(this.outputFileName,n,()=>this.globalConfigDir)],{fastCommands:i,subAgents:a,skills:o}=e.collectedInputContext,s={includeSeriesPrefix:!0};if(this.supportsFastCommands&&i!=null)for(let e of i){let t=this.transformFastCommandName(e,s);r.push(this.createRelativePath(f.join(this.commandsSubDir,t),n,()=>this.commandsSubDir))}if(this.supportsSubAgents&&a!=null)for(let e of a){let t=e.dir.path.replace(/\.mdx$/,`.md`);r.push(this.createRelativePath(f.join(this.agentsSubDir,t),n,()=>this.agentsSubDir))}if(this.supportsSkills&&o!=null)for(let e of o){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=f.join(this.skillsSubDir,t);if(r.push(this.createRelativePath(f.join(i,`SKILL.md`),n,()=>t)),e.childDocs!=null)for(let a of e.childDocs){let e=a.dir.path.replace(/\.mdx$/,`.md`),o=f.join(i,e);r.push(this.createRelativePath(o,n,()=>t))}if(e.resources!=null)for(let a of e.resources){let e=f.join(i,a.relativePath);r.push(this.createRelativePath(e,n,()=>t))}}return r}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=this.supportsFastCommands&&(r?.length??0)>0,l=this.supportsSubAgents&&(i?.length??0)>0,u=this.supportsSkills&&(a?.length??0)>0;return o||s||c||l||u?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],r=[];if([{enabled:!0,data:t},{enabled:this.supportsFastCommands,data:e.collectedInputContext.fastCommands},{enabled:this.supportsSubAgents,data:e.collectedInputContext.subAgents},{enabled:this.supportsSkills,data:e.collectedInputContext.skills}].every(e=>!e.enabled||e.data==null))return{files:n,dirs:r};let{fastCommands:i,subAgents:a,skills:o}=e.collectedInputContext,s=this.getGlobalConfigDir();if(t!=null){let r=f.join(s,this.outputFileName),i=this.createRelativePath(this.outputFileName,s,()=>this.globalConfigDir);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:i,success:!0,skipped:!1});else try{it(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),n.push({path:i,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),n.push({path:i,success:!1,error:e})}}if(this.supportsFastCommands&&i!=null)for(let t of i){let r=await this.writeFastCommand(e,s,t);n.push(...r)}if(this.supportsSubAgents&&a!=null)for(let t of a){let r=await this.writeSubAgent(e,s,t);n.push(...r)}if(this.supportsSkills&&o!=null)for(let t of o){let r=await this.writeSkill(e,s,t);n.push(...r)}return{files:n,dirs:r}}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,this.commandsSubDir),o=f.join(a,i),s=n.content,c=n.yamlFrontMatter,l=!1;if(n.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling fast command with tool preset`,{file:n.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});try{let e=new or({toolPreset:this.toolPreset}).collect(),t=await uv(n.rawMdxContent,{globalScope:e,extractMetadata:!0,basePath:n.dir.basePath});s=t.content,c=t.metadata.fields,l=!0}catch(e){this.log.warn(`failed to recompile fast command, using default`,{file:n.dir.getAbsolutePath(),error:e instanceof Error?e.message:String(e)})}}let u=l?this.buildMarkdownContent(s,c):this.buildMarkdownContentWithRaw(s,c,n.rawFrontMatter);return[await this.writeFile(e,o,u,`fastCommand`)]}async writeSubAgent(e,t,n){let r=n.dir.path.replace(/\.mdx$/,`.md`),i=f.join(t,this.agentsSubDir),a=f.join(i,r),o=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return[await this.writeFile(e,a,o,`subAgent`)]}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,this.skillsSubDir,i),o=f.join(a,`SKILL.md`),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter),c=await this.writeFile(e,o,s,`skill`);if(r.push(c),n.childDocs!=null)for(let o of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,o,t);r.push(...n)}if(n.resources!=null)for(let o of n.resources){let n=await this.writeSkillResource(e,a,i,o,t);r.push(...n)}return r}async writeSkillReferenceDocument(e,t,n,r,i){let a=r.dir.path.replace(/\.mdx$/,`.md`),o=f.join(t,a);return[await this.writeFile(e,o,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,i){let a=f.join(t,r.relativePath);return[await this.writeFile(e,a,r.content,`skillResource`)]}};const fv=`rules`;var pv=class extends dv{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.md`}buildRuleContent(e){return e.globs.length===0?e.content:this.buildMarkdownContent(e.content,{paths:[...e.globs]})}async registerGlobalOutputDirs(e){let t=await super.registerGlobalOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);return n!=null&&n.length>0&&t.push(this.createRelativePath(fv,this.getGlobalConfigDir(),()=>fv)),t}async registerGlobalOutputFiles(e){let t=await super.registerGlobalOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(n==null||n.length===0)return t;let r=f.join(this.getGlobalConfigDir(),fv);for(let e of n)t.push(this.createRelativePath(this.buildRuleFileName(e),r,()=>fv));return t}async registerProjectOutputDirs(e){let t=await super.registerProjectOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;for(let n of e.collectedInputContext.workspace.projects){if(n.dirFromWorkspacePath==null)continue;let e=f.join(n.dirFromWorkspacePath.path,this.globalConfigDir,fv);t.push(this.createRelativePath(e,n.dirFromWorkspacePath.basePath,()=>fv))}return t}async registerProjectOutputFiles(e){let t=await super.registerProjectOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;for(let r of e.collectedInputContext.workspace.projects)if(r.dirFromWorkspacePath!=null)for(let e of n){let n=f.join(r.dirFromWorkspacePath.path,this.globalConfigDir,fv,this.buildRuleFileName(e));t.push(this.createRelativePath(n,r.dirFromWorkspacePath.basePath,()=>fv))}return t}async canWrite(e){return(e.collectedInputContext.rules?.length??0)>0?!0:super.canWrite(e)}async writeGlobalOutputs(e){let t=await super.writeGlobalOutputs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(n==null||n.length===0)return t;let r=f.join(this.getGlobalConfigDir(),fv),i=[];for(let t of n)i.push(await this.writeFile(e,f.join(r,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`));return{files:[...t.files,...i],dirs:t.dirs}}async writeProjectOutputs(e){let t=await super.writeProjectOutputs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;let r=[];for(let t of e.collectedInputContext.workspace.projects){if(t.dirFromWorkspacePath==null)continue;let i=f.join(t.dirFromWorkspacePath.basePath,t.dirFromWorkspacePath.path,this.globalConfigDir,fv);for(let t of n)r.push(await this.writeFile(e,f.join(i,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`))}return{files:[...t.files,...r],dirs:t.dirs}}};const mv=`AGENTS.md`,hv=`.codex`,gv=`prompts`,_v=`skills`;var vv=class extends Pg{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:hv,outputFileName:mv,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[this.createRelativePath(gv,t,()=>gv)],{skills:r}=e.collectedInputContext;if(r!=null&&r.length>0)for(let e of r){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName();n.push(this.createRelativePath(f.join(_v,r),t,()=>r))}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[this.createRelativePath(mv,e,()=>hv)]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext;return t!=null||(n?.length??0)>0||(r?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalConfigDir();if(t!=null){let n=f.join(a,mv),r=await this.writeFile(e,n,t.content,`globalMemory`);i.push(r)}if(n!=null&&n.length>0)for(let t of n){let n=await this.writeGlobalFastCommand(e,a,t);i.push(n)}if(r!=null&&r.length>0)for(let t of r){let n=await this.writeGlobalSkill(e,a,t);i.push(...n)}return{files:i,dirs:[]}}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,gv,i),o=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return this.writeFile(e,a,o,`globalFastCommand`)}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,_v,i),o=f.join(a,`SKILL.md`),s=this.buildCodexSkillContent(n),c=await this.writeFile(e,o,s,`globalSkill`);if(r.push(c),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`),i=f.join(a,n),o=await this.writeFile(e,i,t.content,`skillRefDoc`);r.push(o)}if(n.resources!=null)for(let t of n.resources){let n=f.join(a,t.relativePath),i=await this.writeFile(e,n,t.content,`skillResource`);r.push(i)}return r}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeSkillName(t.name,64),r=this.normalizeToSingleLine(t.description,1024),i={};t.displayName!=null&&(i[`short-description`]=t.displayName),t.version!=null&&(i.version=t.version),t.author!=null&&(i.author=t.author),t.keywords!=null&&t.keywords.length>0&&(i.keywords=[...t.keywords]);let a={name:n,description:r};return Object.keys(i).length>0&&(a.metadata=i),t.allowTools!=null&&t.allowTools.length>0&&(a[`allowed-tools`]=t.allowTools.join(` `)),Ag(a,e.content)}normalizeSkillName(e,t){let n=e.toLowerCase().replaceAll(/[^a-z0-9-]/g,`-`).replaceAll(/-+/g,`-`).replaceAll(/^-+|-+$/g,``);return n.length>t&&(n=n.slice(0,t).replace(/-+$/,``)),n}normalizeToSingleLine(e,t){let n=e.replaceAll(/[\r\n]+/g,` `).replaceAll(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}};const yv=`.cursor`,bv=`mcp.json`,xv=`commands`,Sv=`rules`,Cv=`global.mdc`,wv=`skills-cursor`,Tv=`SKILL.md`,Ev=new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`]);var Dv=class extends Pg{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:yv,outputFileName:``,dependsOn:[`AgentsOutputPlugin`],indexignore:`.cursorignore`}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=this.getGlobalConfigDir(),n=f.join(t,bv),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp.json to empty shell`};try{return this.ensureDirectory(t),d.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp.json to empty shell`}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`mcpConfigCleanup`,path:n,error:t}),{success:!1,error:e,description:`Failed to reset mcp.json`}}})}async registerGlobalOutputDirs(e){let t=[],n=this.getGlobalConfigDir(),{fastCommands:r,skills:i,rules:a}=e.collectedInputContext;if(r!=null&&r.length>0){let e=this.getGlobalCommandsDir();t.push({pathKind:L.Relative,path:xv,basePath:n,getDirectoryName:()=>xv,getAbsolutePath:()=>e})}if(i!=null&&i.length>0)for(let e of i){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let i=f.join(n,wv,r);t.push({pathKind:L.Relative,path:f.join(wv,r),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i})}let o=a?.filter(e=>e.scope===`global`);if(o==null||o.length===0)return t;let s=f.join(n,Sv);return t.push({pathKind:L.Relative,path:Sv,basePath:n,getDirectoryName:()=>Sv,getAbsolutePath:()=>s}),t}async registerGlobalOutputFiles(e){let t=[],n=this.getGlobalConfigDir(),{skills:r,fastCommands:i}=e.collectedInputContext;if(r?.some(e=>e.mcpConfig!=null)??!1){let e=f.join(n,bv);t.push({pathKind:L.Relative,path:bv,basePath:n,getDirectoryName:()=>yv,getAbsolutePath:()=>e})}if(i!=null&&i.length>0){let r=this.getGlobalCommandsDir(),a=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of i){let i=this.transformFastCommandName(e,a),o=f.join(r,i);t.push({pathKind:L.Relative,path:f.join(xv,i),basePath:n,getDirectoryName:()=>xv,getAbsolutePath:()=>o})}}let a=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(a!=null&&a.length>0){let e=f.join(n,Sv);for(let r of a){let i=this.buildRuleFileName(r),a=f.join(e,i);t.push({pathKind:L.Relative,path:f.join(Sv,i),basePath:n,getDirectoryName:()=>Sv,getAbsolutePath:()=>a})}}if(r==null||r.length===0)return t;let o=this.getSkillsCursorDir();for(let e of r){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let i=f.join(o,r);if(t.push({pathKind:L.Relative,path:f.join(wv,r,Tv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,Tv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:f.join(wv,r,bv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,bv)}),e.childDocs!=null)for(let a of e.childDocs){let e=a.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:f.join(wv,r,e),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,e)})}if(e.resources!=null)for(let a of e.resources)t.push({pathKind:L.Relative,path:f.join(wv,r,a.relativePath),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,a.relativePath)})}return t}async registerProjectOutputDirs(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.some(e=>e.scope===`project`)??!1;if(r==null&&!a)return t;for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRulesDirRelativePath(n))}return t}async registerProjectOutputFiles(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.filter(e=>e.scope===`project`),o=a!=null&&a.length>0;if(r==null&&!o)return t;if(r!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRuleFileRelativePath(n,Cv))}if(o)for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of a){let r=this.buildRuleFileName(e);t.push(this.createProjectRuleFileRelativePath(n,r))}}return t.push(...this.registerProjectIgnoreOutputFiles(n.projects)),t}async canWrite(e){let{workspace:t,skills:n,fastCommands:r,globalMemory:i,rules:a,aiAgentIgnoreConfigFiles:o}=e.collectedInputContext,s=(n?.length??0)>0,c=(r?.length??0)>0,l=(a?.length??0)>0,u=i!=null&&t.projects.some(e=>e.dirFromWorkspacePath!=null),d=o?.some(e=>e.fileName===`.cursorignore`)??!1;return s||c||u||l||d?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeGlobalOutputs(e){let{skills:t,fastCommands:n,rules:r}=e.collectedInputContext,i=[],a=[];if(t!=null&&t.length>0){let n=await this.writeGlobalMcpConfig(e,t);n!=null&&i.push(n);let r=this.getSkillsCursorDir();for(let n of t){let t=n.yamlFrontMatter.name;if(this.isPreservedSkill(t))continue;let a=await this.writeGlobalSkill(e,r,n);i.push(...a)}}if(n!=null&&n.length>0){let t=this.getGlobalCommandsDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);i.push(n)}}let o=r?.filter(e=>e.scope===`global`);if(o==null||o.length===0)return{files:i,dirs:a};let s=f.join(this.getGlobalConfigDir(),Sv);for(let t of o){let n=await this.writeRuleMdcFile(e,s,t,this.getGlobalConfigDir());i.push(n)}return{files:i,dirs:a}}async writeProjectOutputs(e){let t=[],n=[],{workspace:r,globalMemory:i,rules:a}=e.collectedInputContext;if(i!=null){let n=this.buildGlobalRuleContent(i.content);for(let i of r.projects){if(i.dirFromWorkspacePath==null)continue;let r=await this.writeProjectGlobalRule(e,i,n);t.push(r)}}let o=a?.filter(e=>e.scope===`project`);if(o!=null&&o.length>0)for(let n of r.projects){let r=n.dirFromWorkspacePath;if(r==null)continue;let i=f.join(r.basePath,r.path,yv,Sv);for(let n of o){let a=await this.writeRuleMdcFile(e,i,n,r.basePath);t.push(a)}}let s=await this.writeProjectIgnoreFiles(e);return t.push(...s),{files:t,dirs:n}}createProjectRulesDirRelativePath(e){let t=f.join(e.path,yv,Sv);return{pathKind:L.Relative,path:t,basePath:e.basePath,getDirectoryName:()=>Sv,getAbsolutePath:()=>f.join(e.basePath,t)}}createProjectRuleFileRelativePath(e,t){let n=f.join(e.path,yv,Sv,t);return{pathKind:L.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>Sv,getAbsolutePath:()=>f.join(e.basePath,n)}}buildGlobalRuleContent(e){return Ag({description:`Global prompt (synced)`,alwaysApply:!0},e)}async writeProjectGlobalRule(e,t,n){let r=t.dirFromWorkspacePath,i=f.join(r.basePath,r.path,yv,Sv),a=f.join(i,Cv),o=this.createProjectRuleFileRelativePath(r,Cv);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalRule`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(i),this.writeFileSync(a,n),this.log.trace({action:`write`,type:`globalRule`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalRule`,path:a,error:t}),{path:o,success:!1,error:e}}}isPreservedSkill(e){return Ev.has(e)}getSkillsCursorDir(){return f.join(this.getGlobalConfigDir(),wv)}getGlobalCommandsDir(){return f.join(this.getGlobalConfigDir(),xv)}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0}),i=this.transformFastCommandName(n,r),a=f.join(t,i),o={pathKind:L.Relative,path:f.join(xv,i),basePath:this.getGlobalConfigDir(),getDirectoryName:()=>xv,getAbsolutePath:()=>a},s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(t),d.writeFileSync(a,s),this.log.trace({action:`write`,type:`globalFastCommand`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalFastCommand`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeGlobalMcpConfig(e,t){let n={};for(let e of t){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,r]of Object.entries(t))n[e]=this.transformMcpConfigForCursor({...r})}if(Object.keys(n).length===0)return null;let r=this.getGlobalConfigDir(),i=f.join(r,bv),a={pathKind:L.Relative,path:bv,basePath:r,getDirectoryName:()=>yv,getAbsolutePath:()=>i},o={};try{if(this.existsSync(i)){let e=d.readFileSync(i,`utf8`);o=JSON.parse(e)}}catch{o={}}let s={...o.mcpServers??{},...n};o.mcpServers=s;let c=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(n).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(r),d.writeFileSync(i,c),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(n).length}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalMcpConfig`,path:i,error:t}),{path:a,success:!1,error:e}}}transformMcpConfigForCursor(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.url??e.serverUrl;return n==null?t:(t.url=n,e.headers!=null&&(t.headers=e.headers),t)}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter.name,a=f.join(t,i),o=f.join(a,Tv),s=this.getGlobalConfigDir(),c={pathKind:L.Relative,path:f.join(wv,i,Tv),basePath:s,getDirectoryName:()=>i,getAbsolutePath:()=>o},l=this.buildSkillFrontMatter(n),u=n.content,d=Ag(l,u);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:o}),r.push({path:c,success:!0,skipped:!1});else try{this.ensureDirectory(a),this.writeFileSync(o,d),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:o,error:t}),r.push({path:c,success:!1,error:e})}if(n.mcpConfig!=null){let t=await this.writeSkillMcpConfig(e,n,a,s);r.push(t)}if(n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillChildDoc(e,t,a,i,s);r.push(n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,t,a,i,s);r.push(n)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeSkillMcpConfig(e,t,n,r){let i=t.yamlFrontMatter.name,a=f.join(n,bv),o={pathKind:L.Relative,path:f.join(wv,i,bv),basePath:r,getDirectoryName:()=>i,getAbsolutePath:()=>a},s=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`mcpConfig`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeSkillChildDoc(e,t,n,r,i){let a=t.relativePath.replace(/\.mdx$/,`.md`),o=f.join(n,a),s={pathKind:L.Relative,path:f.join(wv,r,a),basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>o},c=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:o}),{path:s,success:!0,skipped:!1};try{let e=f.dirname(o);return this.ensureDirectory(e),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`childDoc`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:o,error:t}),{path:s,success:!1,error:e}}}async writeSkillResource(e,t,n,r,i){let a=f.join(n,t.relativePath),o={pathKind:L.Relative,path:f.join(wv,r,t.relativePath),basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:a}),{path:o,success:!0,skipped:!1};try{let e=f.dirname(a);if(this.ensureDirectory(e),t.encoding===`base64`){let e=h.Buffer.from(t.content,`base64`);this.writeFileSyncBuffer(a,e)}else this.writeFileSync(a,t.content);return this.log.trace({action:`write`,type:`resource`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:a,error:t}),{path:o,success:!1,error:e}}}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.mdc`}buildRuleMdcContent(e){return Ag({alwaysApply:!1,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
1230
+ `).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function Z_(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 Q_(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=ev(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return tv(r).map(e=>Y_(e.trim(),t,n))}function $_(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=ev(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=nv(r);for(let e of a){let r=rv(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]=Y_(o,t,n)}return i}function ev(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 tv(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 nv(e){return tv(e)}function rv(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 iv(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=r_(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function av(e,t,n){return!iv(e,t)||e.children.length===0?[]:n(e.children,t)}async function ov(e,t){if(!iv(e,t)||e.children.length===0)return[];let n=sv(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function sv(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=r_(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=sv(r.children,t));return n}function cv(){e_(`Md`,av),e_(`Md.Line`,ov)}cv();function lv(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 uv(e,t){let n=dh(e),r=lv(t?.globalScope,t?.scope),i=t_(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Og.parse(e.value)}catch{}a=K_(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 B_(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=pu().use(ii,[`yaml`]).use(ql).use(G_,{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}var dv=class extends Pg{commandsSubDir;agentsSubDir;skillsSubDir;supportsFastCommands;supportsSubAgents;supportsSkills;toolPreset;constructor(e,t){super(e,t),this.commandsSubDir=t.commandsSubDir??`commands`,this.agentsSubDir=t.agentsSubDir??`agents`,this.skillsSubDir=t.skillsSubDir??`skills`,this.supportsFastCommands=t.supportsFastCommands??!0,this.supportsSubAgents=t.supportsSubAgents??!0,this.supportsSkills=t.supportsSkills??!0,t.toolPreset!==void 0&&(this.toolPreset=t.toolPreset)}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=[];this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir);for(let e of r)n.push(this.createRelativePath(e,t,()=>e));return n}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=[];if(this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir),r.length===0)return[];for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of r){let r=f.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push(this.createRelativePath(r,e.dirFromWorkspacePath.basePath,()=>n))}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,this.outputFileName)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,this.outputFileName));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir(),r=[this.createRelativePath(this.outputFileName,n,()=>this.globalConfigDir)],{fastCommands:i,subAgents:a,skills:o}=e.collectedInputContext,s={includeSeriesPrefix:!0};if(this.supportsFastCommands&&i!=null)for(let e of i){let t=this.transformFastCommandName(e,s);r.push(this.createRelativePath(f.join(this.commandsSubDir,t),n,()=>this.commandsSubDir))}if(this.supportsSubAgents&&a!=null)for(let e of a){let t=e.dir.path.replace(/\.mdx$/,`.md`);r.push(this.createRelativePath(f.join(this.agentsSubDir,t),n,()=>this.agentsSubDir))}if(this.supportsSkills&&o!=null)for(let e of o){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=f.join(this.skillsSubDir,t);if(r.push(this.createRelativePath(f.join(i,`SKILL.md`),n,()=>t)),e.childDocs!=null)for(let a of e.childDocs){let e=a.dir.path.replace(/\.mdx$/,`.md`),o=f.join(i,e);r.push(this.createRelativePath(o,n,()=>t))}if(e.resources!=null)for(let a of e.resources){let e=f.join(i,a.relativePath);r.push(this.createRelativePath(e,n,()=>t))}}return r}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=this.supportsFastCommands&&(r?.length??0)>0,l=this.supportsSubAgents&&(i?.length??0)>0,u=this.supportsSkills&&(a?.length??0)>0;return o||s||c||l||u?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],r=[];if([{enabled:!0,data:t},{enabled:this.supportsFastCommands,data:e.collectedInputContext.fastCommands},{enabled:this.supportsSubAgents,data:e.collectedInputContext.subAgents},{enabled:this.supportsSkills,data:e.collectedInputContext.skills}].every(e=>!e.enabled||e.data==null))return{files:n,dirs:r};let{fastCommands:i,subAgents:a,skills:o}=e.collectedInputContext,s=this.getGlobalConfigDir();if(t!=null){let r=f.join(s,this.outputFileName),i=this.createRelativePath(this.outputFileName,s,()=>this.globalConfigDir);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:i,success:!0,skipped:!1});else try{it(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),n.push({path:i,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),n.push({path:i,success:!1,error:e})}}if(this.supportsFastCommands&&i!=null)for(let t of i){let r=await this.writeFastCommand(e,s,t);n.push(...r)}if(this.supportsSubAgents&&a!=null)for(let t of a){let r=await this.writeSubAgent(e,s,t);n.push(...r)}if(this.supportsSkills&&o!=null)for(let t of o){let r=await this.writeSkill(e,s,t);n.push(...r)}return{files:n,dirs:r}}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,this.commandsSubDir),o=f.join(a,i),s=n.content,c=n.yamlFrontMatter,l=!1;if(n.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling fast command with tool preset`,{file:n.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});try{let e=new or({toolPreset:this.toolPreset}).collect(),t=await uv(n.rawMdxContent,{globalScope:e,extractMetadata:!0,basePath:n.dir.basePath});s=t.content,c=t.metadata.fields,l=!0}catch(e){this.log.warn(`failed to recompile fast command, using default`,{file:n.dir.getAbsolutePath(),error:e instanceof Error?e.message:String(e)})}}let u=l?this.buildMarkdownContent(s,c):this.buildMarkdownContentWithRaw(s,c,n.rawFrontMatter);return[await this.writeFile(e,o,u,`fastCommand`)]}async writeSubAgent(e,t,n){let r=n.dir.path.replace(/\.mdx$/,`.md`),i=f.join(t,this.agentsSubDir),a=f.join(i,r),o=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return[await this.writeFile(e,a,o,`subAgent`)]}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,this.skillsSubDir,i),o=f.join(a,`SKILL.md`),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter),c=await this.writeFile(e,o,s,`skill`);if(r.push(c),n.childDocs!=null)for(let o of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,o,t);r.push(...n)}if(n.resources!=null)for(let o of n.resources){let n=await this.writeSkillResource(e,a,i,o,t);r.push(...n)}return r}async writeSkillReferenceDocument(e,t,n,r,i){let a=r.dir.path.replace(/\.mdx$/,`.md`),o=f.join(t,a);return[await this.writeFile(e,o,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,i){let a=f.join(t,r.relativePath);return[await this.writeFile(e,a,r.content,`skillResource`)]}normalizeRuleScope(e){return e.scope??`project`}};const fv=`rules`;var pv=class extends dv{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.md`}buildRuleContent(e){return e.globs.length===0?e.content:this.buildMarkdownContent(e.content,{paths:[...e.globs]})}async registerGlobalOutputDirs(e){let t=await super.registerGlobalOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);return n!=null&&n.length>0&&t.push(this.createRelativePath(fv,this.getGlobalConfigDir(),()=>fv)),t}async registerGlobalOutputFiles(e){let t=await super.registerGlobalOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(n==null||n.length===0)return t;let r=f.join(this.getGlobalConfigDir(),fv);for(let e of n)t.push(this.createRelativePath(this.buildRuleFileName(e),r,()=>fv));return t}async registerProjectOutputDirs(e){let t=await super.registerProjectOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;for(let n of e.collectedInputContext.workspace.projects){if(n.dirFromWorkspacePath==null)continue;let e=f.join(n.dirFromWorkspacePath.path,this.globalConfigDir,fv);t.push(this.createRelativePath(e,n.dirFromWorkspacePath.basePath,()=>fv))}return t}async registerProjectOutputFiles(e){let t=await super.registerProjectOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;for(let r of e.collectedInputContext.workspace.projects)if(r.dirFromWorkspacePath!=null)for(let e of n){let n=f.join(r.dirFromWorkspacePath.path,this.globalConfigDir,fv,this.buildRuleFileName(e));t.push(this.createRelativePath(n,r.dirFromWorkspacePath.basePath,()=>fv))}return t}async canWrite(e){return(e.collectedInputContext.rules?.length??0)>0?!0:super.canWrite(e)}async writeGlobalOutputs(e){let t=await super.writeGlobalOutputs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(n==null||n.length===0)return t;let r=f.join(this.getGlobalConfigDir(),fv),i=[];for(let t of n)i.push(await this.writeFile(e,f.join(r,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`));return{files:[...t.files,...i],dirs:t.dirs}}async writeProjectOutputs(e){let t=await super.writeProjectOutputs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;let r=[];for(let t of e.collectedInputContext.workspace.projects){if(t.dirFromWorkspacePath==null)continue;let i=f.join(t.dirFromWorkspacePath.basePath,t.dirFromWorkspacePath.path,this.globalConfigDir,fv);for(let t of n)r.push(await this.writeFile(e,f.join(i,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`))}return{files:[...t.files,...r],dirs:t.dirs}}};const mv=`AGENTS.md`,hv=`.codex`,gv=`prompts`,_v=`skills`;var vv=class extends Pg{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:hv,outputFileName:mv,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[this.createRelativePath(gv,t,()=>gv)],{skills:r}=e.collectedInputContext;if(r!=null&&r.length>0)for(let e of r){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName();n.push(this.createRelativePath(f.join(_v,r),t,()=>r))}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[this.createRelativePath(mv,e,()=>hv)]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext;return t!=null||(n?.length??0)>0||(r?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalConfigDir();if(t!=null){let n=f.join(a,mv),r=await this.writeFile(e,n,t.content,`globalMemory`);i.push(r)}if(n!=null&&n.length>0)for(let t of n){let n=await this.writeGlobalFastCommand(e,a,t);i.push(n)}if(r!=null&&r.length>0)for(let t of r){let n=await this.writeGlobalSkill(e,a,t);i.push(...n)}return{files:i,dirs:[]}}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),i=this.transformFastCommandName(n,r),a=f.join(t,gv,i),o=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return this.writeFile(e,a,o,`globalFastCommand`)}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,_v,i),o=f.join(a,`SKILL.md`),s=this.buildCodexSkillContent(n),c=await this.writeFile(e,o,s,`globalSkill`);if(r.push(c),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`),i=f.join(a,n),o=await this.writeFile(e,i,t.content,`skillRefDoc`);r.push(o)}if(n.resources!=null)for(let t of n.resources){let n=f.join(a,t.relativePath),i=await this.writeFile(e,n,t.content,`skillResource`);r.push(i)}return r}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeSkillName(t.name,64),r=this.normalizeToSingleLine(t.description,1024),i={};t.displayName!=null&&(i[`short-description`]=t.displayName),t.version!=null&&(i.version=t.version),t.author!=null&&(i.author=t.author),t.keywords!=null&&t.keywords.length>0&&(i.keywords=[...t.keywords]);let a={name:n,description:r};return Object.keys(i).length>0&&(a.metadata=i),t.allowTools!=null&&t.allowTools.length>0&&(a[`allowed-tools`]=t.allowTools.join(` `)),Ag(a,e.content)}normalizeSkillName(e,t){let n=e.toLowerCase().replaceAll(/[^a-z0-9-]/g,`-`).replaceAll(/-+/g,`-`).replaceAll(/^-+|-+$/g,``);return n.length>t&&(n=n.slice(0,t).replace(/-+$/,``)),n}normalizeToSingleLine(e,t){let n=e.replaceAll(/[\r\n]+/g,` `).replaceAll(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}};const yv=`.cursor`,bv=`mcp.json`,xv=`commands`,Sv=`rules`,Cv=`global.mdc`,wv=`skills-cursor`,Tv=`SKILL.md`,Ev=new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`]);var Dv=class extends Pg{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:yv,outputFileName:``,dependsOn:[`AgentsOutputPlugin`],indexignore:`.cursorignore`}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=this.getGlobalConfigDir(),n=f.join(t,bv),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp.json to empty shell`};try{return this.ensureDirectory(t),d.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp.json to empty shell`}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`mcpConfigCleanup`,path:n,error:t}),{success:!1,error:e,description:`Failed to reset mcp.json`}}})}async registerGlobalOutputDirs(e){let t=[],n=this.getGlobalConfigDir(),{fastCommands:r,skills:i,rules:a}=e.collectedInputContext;if(r!=null&&r.length>0){let e=this.getGlobalCommandsDir();t.push({pathKind:L.Relative,path:xv,basePath:n,getDirectoryName:()=>xv,getAbsolutePath:()=>e})}if(i!=null&&i.length>0)for(let e of i){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let i=f.join(n,wv,r);t.push({pathKind:L.Relative,path:f.join(wv,r),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i})}let o=a?.filter(e=>this.normalizeRuleScope(e)===`global`);if(o==null||o.length===0)return t;let s=f.join(n,Sv);return t.push({pathKind:L.Relative,path:Sv,basePath:n,getDirectoryName:()=>Sv,getAbsolutePath:()=>s}),t}async registerGlobalOutputFiles(e){let t=[],n=this.getGlobalConfigDir(),{skills:r,fastCommands:i}=e.collectedInputContext;if(r?.some(e=>e.mcpConfig!=null)??!1){let e=f.join(n,bv);t.push({pathKind:L.Relative,path:bv,basePath:n,getDirectoryName:()=>yv,getAbsolutePath:()=>e})}if(i!=null&&i.length>0){let r=this.getGlobalCommandsDir(),a=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of i){let i=this.transformFastCommandName(e,a),o=f.join(r,i);t.push({pathKind:L.Relative,path:f.join(xv,i),basePath:n,getDirectoryName:()=>xv,getAbsolutePath:()=>o})}}let a=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(a!=null&&a.length>0){let e=f.join(n,Sv);for(let r of a){let i=this.buildRuleFileName(r),a=f.join(e,i);t.push({pathKind:L.Relative,path:f.join(Sv,i),basePath:n,getDirectoryName:()=>Sv,getAbsolutePath:()=>a})}}if(r==null||r.length===0)return t;let o=this.getSkillsCursorDir();for(let e of r){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let i=f.join(o,r);if(t.push({pathKind:L.Relative,path:f.join(wv,r,Tv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,Tv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:f.join(wv,r,bv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,bv)}),e.childDocs!=null)for(let a of e.childDocs){let e=a.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:f.join(wv,r,e),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,e)})}if(e.resources!=null)for(let a of e.resources)t.push({pathKind:L.Relative,path:f.join(wv,r,a.relativePath),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>f.join(i,a.relativePath)})}return t}async registerProjectOutputDirs(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.some(e=>this.normalizeRuleScope(e)===`project`)??!1;if(r==null&&!a)return t;for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRulesDirRelativePath(n))}return t}async registerProjectOutputFiles(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.filter(e=>this.normalizeRuleScope(e)===`project`),o=a!=null&&a.length>0;if(r==null&&!o)return t;if(r!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRuleFileRelativePath(n,Cv))}if(o)for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of a){let r=this.buildRuleFileName(e);t.push(this.createProjectRuleFileRelativePath(n,r))}}return t.push(...this.registerProjectIgnoreOutputFiles(n.projects)),t}async canWrite(e){let{workspace:t,skills:n,fastCommands:r,globalMemory:i,rules:a,aiAgentIgnoreConfigFiles:o}=e.collectedInputContext,s=(n?.length??0)>0,c=(r?.length??0)>0,l=(a?.length??0)>0,u=i!=null&&t.projects.some(e=>e.dirFromWorkspacePath!=null),d=o?.some(e=>e.fileName===`.cursorignore`)??!1;return s||c||u||l||d?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeGlobalOutputs(e){let{skills:t,fastCommands:n,rules:r}=e.collectedInputContext,i=[],a=[];if(t!=null&&t.length>0){let n=await this.writeGlobalMcpConfig(e,t);n!=null&&i.push(n);let r=this.getSkillsCursorDir();for(let n of t){let t=n.yamlFrontMatter.name;if(this.isPreservedSkill(t))continue;let a=await this.writeGlobalSkill(e,r,n);i.push(...a)}}if(n!=null&&n.length>0){let t=this.getGlobalCommandsDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);i.push(n)}}let o=r?.filter(e=>this.normalizeRuleScope(e)===`global`);if(o==null||o.length===0)return{files:i,dirs:a};let s=f.join(this.getGlobalConfigDir(),Sv);for(let t of o){let n=await this.writeRuleMdcFile(e,s,t,this.getGlobalConfigDir());i.push(n)}return{files:i,dirs:a}}async writeProjectOutputs(e){let t=[],n=[],{workspace:r,globalMemory:i,rules:a}=e.collectedInputContext;if(i!=null){let n=this.buildGlobalRuleContent(i.content);for(let i of r.projects){if(i.dirFromWorkspacePath==null)continue;let r=await this.writeProjectGlobalRule(e,i,n);t.push(r)}}let o=a?.filter(e=>this.normalizeRuleScope(e)===`project`);if(o!=null&&o.length>0)for(let n of r.projects){let r=n.dirFromWorkspacePath;if(r==null)continue;let i=f.join(r.basePath,r.path,yv,Sv);for(let n of o){let a=await this.writeRuleMdcFile(e,i,n,r.basePath);t.push(a)}}let s=await this.writeProjectIgnoreFiles(e);return t.push(...s),{files:t,dirs:n}}createProjectRulesDirRelativePath(e){let t=f.join(e.path,yv,Sv);return{pathKind:L.Relative,path:t,basePath:e.basePath,getDirectoryName:()=>Sv,getAbsolutePath:()=>f.join(e.basePath,t)}}createProjectRuleFileRelativePath(e,t){let n=f.join(e.path,yv,Sv,t);return{pathKind:L.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>Sv,getAbsolutePath:()=>f.join(e.basePath,n)}}buildGlobalRuleContent(e){return Ag({description:`Global prompt (synced)`,alwaysApply:!0},e)}async writeProjectGlobalRule(e,t,n){let r=t.dirFromWorkspacePath,i=f.join(r.basePath,r.path,yv,Sv),a=f.join(i,Cv),o=this.createProjectRuleFileRelativePath(r,Cv);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalRule`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(i),this.writeFileSync(a,n),this.log.trace({action:`write`,type:`globalRule`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalRule`,path:a,error:t}),{path:o,success:!1,error:e}}}isPreservedSkill(e){return Ev.has(e)}getSkillsCursorDir(){return f.join(this.getGlobalConfigDir(),wv)}getGlobalCommandsDir(){return f.join(this.getGlobalConfigDir(),xv)}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0}),i=this.transformFastCommandName(n,r),a=f.join(t,i),o={pathKind:L.Relative,path:f.join(xv,i),basePath:this.getGlobalConfigDir(),getDirectoryName:()=>xv,getAbsolutePath:()=>a},s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(t),d.writeFileSync(a,s),this.log.trace({action:`write`,type:`globalFastCommand`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalFastCommand`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeGlobalMcpConfig(e,t){let n={};for(let e of t){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,r]of Object.entries(t))n[e]=this.transformMcpConfigForCursor({...r})}if(Object.keys(n).length===0)return null;let r=this.getGlobalConfigDir(),i=f.join(r,bv),a={pathKind:L.Relative,path:bv,basePath:r,getDirectoryName:()=>yv,getAbsolutePath:()=>i},o={};try{if(this.existsSync(i)){let e=d.readFileSync(i,`utf8`);o=JSON.parse(e)}}catch{o={}}let s={...o.mcpServers??{},...n};o.mcpServers=s;let c=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(n).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(r),d.writeFileSync(i,c),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(n).length}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalMcpConfig`,path:i,error:t}),{path:a,success:!1,error:e}}}transformMcpConfigForCursor(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.url??e.serverUrl;return n==null?t:(t.url=n,e.headers!=null&&(t.headers=e.headers),t)}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter.name,a=f.join(t,i),o=f.join(a,Tv),s=this.getGlobalConfigDir(),c={pathKind:L.Relative,path:f.join(wv,i,Tv),basePath:s,getDirectoryName:()=>i,getAbsolutePath:()=>o},l=this.buildSkillFrontMatter(n),u=n.content,d=Ag(l,u);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:o}),r.push({path:c,success:!0,skipped:!1});else try{this.ensureDirectory(a),this.writeFileSync(o,d),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:o,error:t}),r.push({path:c,success:!1,error:e})}if(n.mcpConfig!=null){let t=await this.writeSkillMcpConfig(e,n,a,s);r.push(t)}if(n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillChildDoc(e,t,a,i,s);r.push(n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,t,a,i,s);r.push(n)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeSkillMcpConfig(e,t,n,r){let i=t.yamlFrontMatter.name,a=f.join(n,bv),o={pathKind:L.Relative,path:f.join(wv,i,bv),basePath:r,getDirectoryName:()=>i,getAbsolutePath:()=>a},s=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`mcpConfig`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeSkillChildDoc(e,t,n,r,i){let a=t.relativePath.replace(/\.mdx$/,`.md`),o=f.join(n,a),s={pathKind:L.Relative,path:f.join(wv,r,a),basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>o},c=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:o}),{path:s,success:!0,skipped:!1};try{let e=f.dirname(o);return this.ensureDirectory(e),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`childDoc`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:o,error:t}),{path:s,success:!1,error:e}}}async writeSkillResource(e,t,n,r,i){let a=f.join(n,t.relativePath),o={pathKind:L.Relative,path:f.join(wv,r,t.relativePath),basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:a}),{path:o,success:!0,skipped:!1};try{let e=f.dirname(a);if(this.ensureDirectory(e),t.encoding===`base64`){let e=h.Buffer.from(t.content,`base64`);this.writeFileSyncBuffer(a,e)}else this.writeFileSync(a,t.content);return this.log.trace({action:`write`,type:`resource`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:a,error:t}),{path:o,success:!1,error:e}}}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.mdc`}buildRuleMdcContent(e){return Ag({alwaysApply:!1,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
1231
1231
  `).map(e=>{let t=/^(\s*globs:\s*)(['"])(.*)\2\s*$/.exec(e);if(t==null)return e;let n=t[1]??`globs: `,r=t[3]??``;return r.trim().length===0?e:`${n}${r}`}).join(`
1232
1232
  `)}async writeRuleMdcFile(e,t,n,r){let i=this.buildRuleFileName(n),a=f.join(t,i),o={pathKind:L.Relative,path:f.join(yv,Sv,i),basePath:r,getDirectoryName:()=>Sv,getAbsolutePath:()=>a},s=this.buildRuleMdcContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ruleFile`,path:a}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(t),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`ruleFile`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ruleFile`,path:a,error:t}),{path:o,success:!1,error:e}}}},Ov=class extends dv{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:`.factory`,outputFileName:`AGENTS.md`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=f.join(t,this.skillsSubDir,i),o=f.join(a,`SKILL.md`),s=n.yamlFrontMatter==null?void 0:{name:n.yamlFrontMatter.name,description:n.yamlFrontMatter.description},c=this.buildMarkdownContent(n.content,s),l=await this.writeFile(e,o,c,`skill`);if(r.push(l),n.childDocs!=null)for(let o of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,o,t);r.push(...n)}if(n.resources!=null)for(let o of n.resources){let n=await this.writeSkillResource(e,a,i,o,t);r.push(...n)}return r}},kv=class extends Lg{configKey;extension;constructor(e,t){super(e),this.configKey=t.configKey,this.extension=t.extension??`.mdx`}async collect(e){let{userConfigOptions:t,logger:n,path:r,fs:i,globalScope:a}=e,o=this.resolveBasePaths(t),s=this.getTargetDir(t,o),c=[];if(!(i.existsSync(s)&&i.statSync(s).isDirectory()))return this.createResult(c);try{let e=i.readdirSync(s,{withFileTypes:!0});for(let t of e)if(t.isFile()&&t.name.endsWith(this.extension)){let e=r.join(s,t.name),o=i.readFileSync(e,`utf8`);try{let r=jg(o),i=await uv(o,{globalScope:a,extractMetadata:!0,basePath:s}),l=r.yamlFrontMatter!=null||Object.keys(i.metadata.fields).length>0?{...r.yamlFrontMatter,...i.metadata.fields}:void 0;if(l!=null){let t=this.validateMetadata(l,e);for(let e of t.warnings)n.debug(e);if(!t.valid)throw new Xg([...t.errors],e)}let{content:u}=i;n.debug(`${this.name} metadata extracted`,{file:t.name,source:i.metadata.source,hasYaml:r.yamlFrontMatter!=null,hasExport:Object.keys(i.metadata.fields).length>0});let d=this.createPrompt(t.name,e,u,l,r.rawFrontMatter,r,s,o);c.push(d)}catch(t){n.error(`failed to parse ${this.name} item`,{file:e,error:t})}}}catch(e){n.error(`Failed to scan directory at ${s}`,{error:e})}return this.createResult(c)}},Av=class extends kv{constructor(){super(`FastCommandInputPlugin`,{configKey:`shadowSourceProject.fastCommand.dist`})}getTargetDir(e,t){return this.resolveShadowPath(e.shadowSourceProject.fastCommand.dist,t.shadowProjectDir)}validateMetadata(e,t){return jt(e,t)}createResult(e){return{fastCommands:e}}extractSeriesInfo(e,t){let n=e.replace(/\.mdx$/,``);if(t!=null)return{series:t,commandName:n};let r=n.indexOf(`_`);return r===-1?{commandName:n}:{series:n.slice(0,Math.max(0,r)),commandName:n.slice(Math.max(0,r+1))}}async collect(e){let{userConfigOptions:t,logger:n,path:r,fs:i}=e,a=this.resolveBasePaths(t),o=this.getTargetDir(t,a),s=[];if(!(i.existsSync(o)&&i.statSync(o).isDirectory()))return this.createResult(s);try{let t=i.readdirSync(o,{withFileTypes:!0});for(let a of t)if(a.isFile()&&a.name.endsWith(this.extension)){let t=await this.processFile(a.name,r.join(o,a.name),o,void 0,e);t!=null&&s.push(t)}else if(a.isDirectory()){let t=r.join(o,a.name);try{let n=i.readdirSync(t,{withFileTypes:!0});for(let i of n)if(i.isFile()&&i.name.endsWith(this.extension)){let n=await this.processFile(i.name,r.join(t,i.name),o,a.name,e);n!=null&&s.push(n)}}catch(e){n.error(`Failed to scan subdirectory at ${t}`,{error:e})}}}catch(e){n.error(`Failed to scan directory at ${o}`,{error:e})}return this.createResult(s)}async processFile(e,t,n,r,i){let{logger:a,globalScope:o}=i,s=i.fs.readFileSync(t,`utf8`);try{let c=jg(s),l=await uv(s,{globalScope:o,extractMetadata:!0,basePath:r==null?n:i.path.join(n,r)}),u=c.yamlFrontMatter!=null||Object.keys(l.metadata.fields).length>0?{...c.yamlFrontMatter,...l.metadata.fields}:void 0;if(u!=null){let e=this.validateMetadata(u,t);for(let t of e.warnings)a.debug(t);if(!e.valid)throw new Xg([...e.errors],t)}let{content:d}=l,f=r==null?e:`${r}/${e}`;return a.debug(`${this.name} metadata extracted`,{file:f,source:l.metadata.source,hasYaml:c.yamlFrontMatter!=null,hasExport:Object.keys(l.metadata.fields).length>0}),this.createPrompt(f,t,d,u,c.rawFrontMatter,c,n,s)}catch(e){a.error(`failed to parse ${this.name} item`,{file:t,error:e});return}}createPrompt(e,t,n,r,i,a,o,s){let c=e.indexOf(`/`),l=c===-1?void 0:e.slice(0,c),u=c===-1?e:e.slice(c+1),d=this.extractSeriesInfo(u,l);return{type:xt.FastCommand,content:n,length:n.length,filePathKind:L.Relative,...r!=null&&{yamlFrontMatter:r},...i!=null&&{rawFrontMatter:i},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:L.Relative,path:e,basePath:o,getDirectoryName:()=>e.replace(/\.mdx$/,``),getAbsolutePath:()=>t},...d.series!=null&&{series:d.series},commandName:d.commandName,rawMdxContent:s}}},jv=class extends dv{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:`GEMINI.md`,supportsFastCommands:!1,supportsSubAgents:!1,supportsSkills:!1})}};const Mv=`.skills`,Nv=`.aindex/.skills`,Pv=`SKILL.md`,Fv=`mcp.json`;var Iv=class extends Pg{constructor(){super(`GenericSkillsOutputPlugin`,{globalConfigDir:Nv,outputFileName:Pv}),this.registerCleanEffect(`legacy-global-skills-cleanup`,async e=>{let t=this.joinPath(this.getHomeDir(),`.skills`);if(!this.existsSync(t))return{success:!0,description:`Legacy global skills dir does not exist, nothing to clean`};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`legacyCleanup`,path:t}),{success:!0,description:`Would clean legacy global skills dir: ${t}`};try{let e=this.readdirSync(t,{withFileTypes:!0}),n=0;for(let r of e)if(r.isDirectory()){let e=this.joinPath(t,r.name),i=this.joinPath(e,Pv);this.existsSync(i)&&(d.rmSync(e,{recursive:!0}),n++)}return this.readdirSync(t).length===0&&d.rmdirSync(t),this.log.trace({action:`clean`,type:`legacySkills`,dir:t,cleanedCount:n}),{success:!0,description:`Cleaned ${n} legacy skills from ${t}`}}catch(e){let n=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`legacySkills`,dir:t,error:n}),{success:!1,description:`Failed to clean legacy skills dir`,error:e}}})}getGlobalSkillsDir(){return this.joinPath(this.getHomeDir(),Nv)}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{skills:r}=e.collectedInputContext;if(r==null||r.length===0)return t;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.path,Mv);t.push({pathKind:L.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Mv,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{skills:r}=e.collectedInputContext;if(r==null||r.length===0)return t;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.basePath,e.dirFromWorkspacePath.path,Mv);for(let i of r){let r=i.yamlFrontMatter.name,a=this.joinPath(n,r);t.push({pathKind:L.Relative,path:this.joinPath(Mv,r),basePath:this.joinPath(e.dirFromWorkspacePath.basePath,e.dirFromWorkspacePath.path),getDirectoryName:()=>r,getAbsolutePath:()=>a})}}return t}async registerGlobalOutputDirs(e){let{skills:t}=e.collectedInputContext;if(t==null||t.length===0)return[];let n=this.getGlobalSkillsDir();return[{pathKind:L.Relative,path:Nv,basePath:this.getHomeDir(),getDirectoryName:()=>Nv,getAbsolutePath:()=>n}]}async registerGlobalOutputFiles(e){let t=[],{skills:n}=e.collectedInputContext;if(n==null||n.length===0)return t;let r=this.getGlobalSkillsDir();for(let e of n){let n=e.yamlFrontMatter.name,i=this.joinPath(r,n);if(t.push({pathKind:L.Relative,path:this.joinPath(Nv,n,Pv),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Pv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:this.joinPath(Nv,n,Fv),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Fv)}),e.childDocs!=null)for(let r of e.childDocs){let e=r.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:this.joinPath(Nv,n,e),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,e)})}if(e.resources!=null)for(let r of e.resources)t.push({pathKind:L.Relative,path:this.joinPath(Nv,n,r.relativePath),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,r.relativePath)})}return t}async canWrite(e){let{skills:t}=e.collectedInputContext,{projects:n}=e.collectedInputContext.workspace;return t==null||t.length===0?(this.log.trace({action:`skip`,reason:`noSkills`}),!1):n.length===0?(this.log.trace({action:`skip`,reason:`noProjects`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{skills:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};let a=this.getGlobalSkillsDir();for(let i of t){if(i.dirFromWorkspacePath==null)continue;let t=this.joinPath(i.dirFromWorkspacePath.basePath,i.dirFromWorkspacePath.path,Mv);for(let o of n){let n=o.yamlFrontMatter.name,s=this.joinPath(a,n),c=this.joinPath(t,n),l={pathKind:L.Relative,path:this.joinPath(Mv,n),basePath:this.joinPath(i.dirFromWorkspacePath.basePath,i.dirFromWorkspacePath.path),getDirectoryName:()=>n,getAbsolutePath:()=>c};if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`symlink`,target:s,link:c}),r.push({path:l,success:!0,skipped:!1});continue}try{this.createSymlink(s,c,`dir`),this.log.trace({action:`symlink`,type:`skill`,target:s,link:c}),r.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`symlink`,type:`skill`,target:s,link:c,error:t}),r.push({path:l,success:!1,error:e})}}}return{files:r,dirs:i}}async writeGlobalOutputs(e){let{skills:t}=e.collectedInputContext,n=[],r=[];if(t==null||t.length===0)return{files:n,dirs:r};let i=this.getGlobalSkillsDir();for(let r of t){let t=await this.writeSkill(e,r,i);n.push(...t)}return{files:n,dirs:r}}async writeSkill(e,t,n){let r=[],i=t.yamlFrontMatter.name,a=this.joinPath(n,i),o=this.joinPath(a,Pv),s={pathKind:L.Relative,path:Pv,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildSkillFrontMatter(t),l=t.content,u=Ag(c,l);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:o}),r.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(a),this.writeFileSync(o,u),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:o,error:t}),r.push({path:s,success:!1,error:e})}if(t.mcpConfig!=null){let n=await this.writeMcpConfig(e,t,a);r.push(n)}if(t.childDocs!=null)for(let n of t.childDocs){let t=await this.writeChildDoc(e,n,a,i);r.push(t)}if(t.resources!=null)for(let n of t.resources){let t=await this.writeResource(e,n,a,i);r.push(t)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeMcpConfig(e,t,n){let r=t.yamlFrontMatter.name,i=this.joinPath(n,Fv),a={pathKind:L.Relative,path:Fv,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i},o=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:i}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(i,o),this.log.trace({action:`write`,type:`mcpConfig`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:i,error:t}),{path:a,success:!1,error:e}}}async writeChildDoc(e,t,n,r){let i=t.relativePath.replace(/\.mdx$/,`.md`),a=this.joinPath(n,i),o={pathKind:L.Relative,path:i,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:a}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`childDoc`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeResource(e,t,n,r){let i=this.joinPath(n,t.relativePath),a={pathKind:L.Relative,path:t.relativePath,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:i}),{path:a,success:!0,skipped:!1};try{let e=this.dirname(i);if(this.ensureDirectory(e),t.encoding===`base64`){let e=h.Buffer.from(t.content,`base64`);this.writeFileSyncBuffer(i,e)}else this.writeFileSync(i,t.content);return this.log.trace({action:`write`,type:`resource`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:i,error:t}),{path:a,success:!1,error:e}}}},Lv=class extends Lg{options;constructor(e,t){super(e),this.options=t??{}}transformContent(e){return e}collect(e){let{shadowProjectDir:t}=this.resolveBasePaths(e.userConfigOptions),n=this.getFilePath(t);if(!e.fs.existsSync(n))return this.options.fallbackContent==null?(this.log.debug({action:`collect`,message:`File not found`,path:n}),{}):(this.log.debug({action:`collect`,message:`Using fallback content`,path:n}),{[this.getResultKey()]:this.transformContent(this.options.fallbackContent)});let r=e.fs.readFileSync(n,`utf8`);return r.length===0?this.options.fallbackContent==null?(this.log.debug({action:`collect`,message:`File is empty`,path:n}),{}):(this.log.debug({action:`collect`,message:`File empty, using fallback`,path:n}),{[this.getResultKey()]:this.transformContent(this.options.fallbackContent)}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:n,length:r.length}),{[this.getResultKey()]:this.transformContent(r)})}},Rv=class extends Lv{constructor(){super(`GitExcludeInputPlugin`)}getFilePath(e){return f.join(e,`public`,`exclude`)}getResultKey(){return`shadowGitExclude`}};function zv(e){let t=f.join(e,`.git`);if(!d.existsSync(t))return null;let n=d.lstatSync(t);if(n.isDirectory())return f.join(t,`info`);if(n.isFile())try{let n=d.readFileSync(t,`utf8`).trim(),r=/^gitdir: (.+)$/.exec(n);if(r?.[1]!=null){let t=f.resolve(e,r[1]);return f.join(t,`info`)}}catch{}return null}function Bv(e,t=5){let n=[],r=new Set([`node_modules`,`.turbo`,`dist`,`build`,`out`,`.cache`]);function i(a,o){if(o>t)return;let s;try{let e=d.readdirSync(a,{withFileTypes:!0});if(!Array.isArray(e))return;s=e}catch{return}s.some(e=>e.name===`.git`)&&a!==e&&n.push(a);for(let e of s)e.isDirectory()&&(e.name===`.git`||r.has(e.name)||i(f.join(a,e.name),o+1))}return i(e,0),n}function Vv(e){let t=f.join(e,`modules`);if(!d.existsSync(t))return[];let n=[];function r(e){let t;try{let n=d.readdirSync(e,{withFileTypes:!0});if(!Array.isArray(n))return;t=n}catch{return}if(t.some(e=>e.name===`info`&&e.isDirectory())&&n.push(f.join(e,`info`)),t.find(e=>e.name===`modules`&&e.isDirectory())==null)return;let i;try{let t=d.readdirSync(f.join(e,`modules`),{withFileTypes:!0});if(!Array.isArray(t))return;i=t}catch{return}for(let t of i)t.isDirectory()&&r(f.join(e,`modules`,t.name))}let i;try{let e=d.readdirSync(t,{withFileTypes:!0});if(!Array.isArray(e))return n;i=e}catch{return n}for(let e of i)e.isDirectory()&&r(f.join(t,e.name));return n}var Hv=class extends Pg{constructor(){super(`GitExcludeOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n){if(e.dirFromWorkspacePath==null||e.isPromptSourceProject===!0)continue;let n=e.dirFromWorkspacePath,r=n.getAbsolutePath(),{basePath:i}=n,a=[r,...Bv(r)];for(let e of a){let n=zv(e);if(n==null)continue;let r=f.join(n,`exclude`),a=f.relative(i,r);t.push({pathKind:L.Relative,path:a,basePath:i,getDirectoryName:()=>f.basename(e),getAbsolutePath:()=>r})}}let r=e.collectedInputContext.workspace.directory.path,i=f.join(r,`.git`);if(d.existsSync(i)&&d.lstatSync(i).isDirectory())for(let e of Vv(i)){let n=f.join(e,`exclude`),i=f.relative(r,n);t.push({pathKind:L.Relative,path:i,basePath:r,getDirectoryName:()=>f.basename(f.dirname(e)),getAbsolutePath:()=>n})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{globalGitIgnore:t,shadowGitExclude:n}=e.collectedInputContext;if(!(t!=null&&t.length>0||n!=null&&n.length>0))return this.log.debug({action:`canWrite`,result:!1,reason:`No gitignore or exclude content found`}),!1;let{projects:r}=e.collectedInputContext.workspace,i=r.some(e=>{if(e.dirFromWorkspacePath==null)return!1;let t=e.dirFromWorkspacePath.getAbsolutePath();return zv(t)==null?Bv(t).some(e=>zv(e)!=null):!0}),a=e.collectedInputContext.workspace.directory.path,o=zv(a)!=null,s=i||o;return this.log.debug({action:`canWrite`,result:s,hasGitProjects:i,hasWorkspaceGit:o,reason:s?`Found git repositories to update`:`No git repositories found`}),s}async writeProjectOutputs(e){let t=[],{globalGitIgnore:n,shadowGitExclude:r}=e.collectedInputContext,i=this.buildManagedContent(n,r);if(i.length===0)return this.log.debug({action:`write`,message:`No gitignore or exclude content found, skipping`}),{files:[],dirs:[]};let{workspace:a}=e.collectedInputContext,{projects:o}=a,s=new Set;for(let n of o){if(n.dirFromWorkspacePath==null)continue;let r=n.dirFromWorkspacePath.getAbsolutePath(),a=[r,...Bv(r)];for(let o of a){let a=zv(o);if(a==null)continue;let c=f.join(a,`exclude`);if(s.has(c))continue;s.add(c);let l=o===r?`project:${n.name??`unknown`}`:`nested:${f.relative(r,o)}`;this.log.trace({action:`write`,path:c,label:l});let u=await this.writeGitExcludeFile(e,c,i,l);t.push(u)}}let c=a.directory.path,l=zv(c);if(l!=null){let n=f.join(l,`exclude`);if(!s.has(n)){this.log.trace({action:`write`,path:n,target:`workspace`});let r=await this.writeGitExcludeFile(e,n,i,`workspace`);t.push(r),s.add(n)}}let u=Bv(c);for(let n of u){let r=zv(n);if(r==null)continue;let a=f.join(r,`exclude`);if(s.has(a))continue;s.add(a);let o=`workspace-nested:${f.relative(c,n)}`;this.log.trace({action:`write`,path:a,label:o});let l=await this.writeGitExcludeFile(e,a,i,o);t.push(l)}let p=f.join(c,`.git`);if(d.existsSync(p)&&d.lstatSync(p).isDirectory())for(let n of Vv(p)){let r=f.join(n,`exclude`);if(s.has(r))continue;s.add(r);let a=`git-module:${f.relative(p,n)}`;this.log.trace({action:`write`,path:r,label:a});let o=await this.writeGitExcludeFile(e,r,i,a);t.push(o)}return{files:t,dirs:[]}}buildManagedContent(e,t){let n=[];if(e!=null&&e.trim().length>0){let t=this.sanitizeContent(e);t.length>0&&n.push(t)}if(t!=null&&t.trim().length>0){let e=this.sanitizeContent(t);e.length>0&&n.push(e)}return n.length===0?``:n.join(`
1233
1233
  `)}sanitizeContent(e){return e.split(/\r?\n/).filter(e=>{let t=e.trim();return t.length===0?!0:!(t.startsWith(`#`)&&!t.startsWith(`\\#`))}).join(`
package/dist/index.mjs CHANGED
@@ -433,7 +433,7 @@ node_modules/
433
433
  pnpm-lock.yaml
434
434
  .DS_Store
435
435
  `,"public/tnmsc.example.json":`{
436
- "version": "2026.10218.12326",
436
+ "version": "2026.10219.10049",
437
437
  "workspaceDir": "~/project",
438
438
  "shadowSourceProject": {
439
439
  "name": "tnmsc-shadow",
@@ -978,7 +978,7 @@ API 接口 (Spring WebFlux 6.2)
978
978
  - \`controllers/\`: 控制器
979
979
  - \`dto/\`: 数据传输对象
980
980
  \`\`\`
981
- `};const qt=Object.fromEntries(Gt.map(e=>[e,{path:e,content:Kt[e]??``}])),Jt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Yt=JSON.parse(qt[`public/tnmsc.example.json`].content),Xt={reset:`\x1B[0m`,red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`,gray:`\x1B[90m`,blue:`\x1B[34m`,green:`\x1B[32m`,white:`\x1B[37m`,dim:`\x1B[2m`,bgRed:`\x1B[41m`},Zt={red:e=>`${Xt.red}${e}${Xt.reset}`,yellow:e=>`${Xt.yellow}${e}${Xt.reset}`,cyan:e=>`${Xt.cyan}${e}${Xt.reset}`,magenta:e=>`${Xt.magenta}${e}${Xt.reset}`,gray:e=>`${Xt.gray}${e}${Xt.reset}`,blue:e=>`${Xt.blue}${e}${Xt.reset}`,green:e=>`${Xt.green}${e}${Xt.reset}`,white:e=>`${Xt.white}${e}${Xt.reset}`,dim:e=>`${Xt.dim}${e}${Xt.reset}`,bgRed:e=>`${Xt.bgRed}${e}${Xt.reset}`};let Qt;const $t={error:Zt.red,warn:Zt.yellow,info:Zt.cyan,debug:Zt.magenta,trace:Zt.gray,fatal:Zt.bgRed},en={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function tn(e){if(e===null)return Zt.dim(`null`);if(e===void 0)return Zt.dim(`undefined`);if(typeof e==`boolean`)return Zt.yellow(String(e));if(typeof e==`number`)return Zt.blue(String(e));if(typeof e==`string`)return Zt.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>tn(e)).join(`,`)}]`;if(e instanceof Error){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 nn(t)}return typeof e==`object`?nn(e):String(e)}function nn(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?Zt.magenta(e):Zt.yellow(`"${e}"`)}:${tn(t)}`).join(`,`)}}`}function rn(){let e=new Date;return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}:${String(e.getSeconds()).padStart(2,`0`)}.${String(e.getMilliseconds()).padStart(3,`0`)}`}function an(e,t,n,r){let i=rn(),a=$t[e]??Zt.white,o=String(n),s=r!=null&&Object.keys(r).length>0,c=o===``,l={$:[i,e,t],_:s?c?r:{[o]:r}:n},u={$:[i,a(e.toUpperCase()),t]},d=s?c?r:{[o]:r}:n,f=nn({...u,_:d});return e===`error`||e===`fatal`?console.error(f):e===`warn`?console.warn(f):e===`debug`||e===`trace`?console.debug(f):console.log(f),l}function on(e,t,n){let r=en[e],i=en[n];return(n,...a)=>r>i?{$:[rn(),e,t],_:n}:typeof n==`string`?an(e,t,n,a.length===1&&typeof a[0]==`object`&&a[0]!==null?a[0]:a.length>0?{args:a}:void 0):typeof n==`object`&&n?an(e,t,``,n):an(e,t,n)}function sn(e){Qt=e}function cn(){return Qt}function ln(e,t){let n=t??Qt??process.env.LOG_LEVEL??`info`;return{error:on(`error`,e,n),warn:on(`warn`,e,n),info:on(`info`,e,n),debug:on(`debug`,e,n),trace:on(`trace`,e,n),fatal:on(`fatal`,e,n)}}const un=`.tnmsc.json`,dn=`.aindex`;function fn(){return i.join(s.homedir(),dn,un)}function pn(){return{...Yt}}function mn(e,t){let n=fn(),a=i.dirname(n);r.existsSync(a)||r.mkdirSync(a,{recursive:!0}),r.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}function hn(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object with "src" and "dist" string fields`),n;let r=e;return(!(`src`in r)||typeof r.src!=`string`)&&n.push(`${t}.src must be a string`),(!(`dist`in r)||typeof r.dist!=`string`)&&n.push(`${t}.dist must be a string`),n}function gn(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object`),{errors:n,config:void 0};let r=e;(!(`name`in r)||typeof r.name!=`string`)&&n.push(`${t}.name must be a string`);let i=[`skill`,`fastCommand`,`subAgent`,`rule`,`globalMemory`,`workspaceMemory`,`project`],a={};for(let e of i)if(e in r){let i=hn(r[e],`${t}.${e}`);if(n.push(...i),i.length===0){let t=r[e];a[e]={src:t.src,dist:t.dist}}}return n.length>0?{errors:n,config:void 0}:{errors:n,config:{name:r.name,skill:a.skill??{src:`src/skills`,dist:`dist/skills`},fastCommand:a.fastCommand??{src:`src/commands`,dist:`dist/commands`},subAgent:a.subAgent??{src:`src/agents`,dist:`dist/agents`},rule:a.rule??{src:`src/rules`,dist:`dist/rules`},globalMemory:a.globalMemory??{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:a.workspaceMemory??{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:a.project??{src:`app`,dist:`dist/app`}}}}var _n=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??un,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=ln(`ConfigLoader`)}getSearchPaths(e=n.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(i.join(e,this.configFileName)),this.searchGlobal&&t.push(i.join(s.homedir(),dn,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!r.existsSync(t))return{config:{},source:null,found:!1};let e=r.readFileSync(t,`utf8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=n.cwd()){let t=this.getSearchPaths(e),r=[];for(let e of t){let t=this.loadFromFile(e);t.found&&r.push(t)}return{config:this.mergeConfigs(r.map(e=>e.config)),sources:r.map(e=>e.source).filter(e=>e!==null),found:r.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];if(`version`in e&&(typeof e.version==`string`?n.version=e.version:r.push(`version must be a string`)),`workspaceDir`in e&&(typeof e.workspaceDir==`string`?n.workspaceDir=e.workspaceDir:r.push(`workspaceDir must be a string`)),`shadowSourceProject`in e){let{errors:t,config:i}=gn(e.shadowSourceProject,`shadowSourceProject`);r.push(...t),i!=null&&(n.shadowSourceProject=i)}if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`profile`in e){let t=e.profile;typeof t==`object`&&t&&!Array.isArray(t)?n.profile=t:r.push(`profile must be an object`)}if(`tool`in e){let t=e.tool;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))typeof n==`string`||n===void 0?i[t]=n:(r.push(`tool.${t} must be a string`),a=!1);a&&(n.tool=i)}else r.push(`tool must be an object`)}if(`fastCommandSeriesOptions`in e){let t=e.fastCommandSeriesOptions;typeof t==`object`&&t&&!Array.isArray(t)?n.fastCommandSeriesOptions=t:r.push(`fastCommandSeriesOptions must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=this.mergeShadowSourceProject(e.shadowSourceProject,t.shadowSourceProject);return{...e,...t,...n==null?{}:{shadowSourceProject:n}}},{})}mergeShadowSourceProject(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}resolveTilde(e){return e.startsWith(`~`)?i.join(s.homedir(),e.slice(1)):e}};let vn=null;function yn(e){return(e||!vn)&&(vn=new _n(e)),vn}function bn(e){return yn().load(e)}function xn(){let e=ln(`ConfigLoader`),t=fn();if(!r.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),mn(pn(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=r.readFileSync(t,`utf8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),Cn(t,e,[`Failed to read config: ${r}`])}let i;try{i=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),Cn(t,e,[`Invalid JSON: ${r}`])}if(typeof i!=`object`||!i||Array.isArray(i))return e.error(`global config must be a JSON object`,{path:t}),Cn(t,e,[`Config must be a JSON object`]);let a=Sn(i);if(a.length>0){for(let n of a)e.error(`config validation error`,{path:t,error:n});return Cn(t,e,a)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function Sn(e){let t=[];if(`version`in e&&typeof e.version!=`string`&&t.push(`version must be a string`),`workspaceDir`in e&&typeof e.workspaceDir!=`string`&&t.push(`workspaceDir must be a string`),`shadowSourceProject`in e){let{errors:n}=gn(e.shadowSourceProject,`shadowSourceProject`);t.push(...n)}if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`profile`in e){let n=e.profile;(typeof n!=`object`||!n||Array.isArray(n))&&t.push(`profile must be an object`)}if(!(`tool`in e))return t;let n=e.tool;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`tool must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))typeof r!=`string`&&r!==void 0&&t.push(`tool.${n} must be a string`)}return t}function Cn(e,t,n){try{r.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return mn(pn(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const wn=[`workspaceDir`,`shadowSourceProject.name`,`shadowSourceProject.skill.src`,`shadowSourceProject.skill.dist`,`shadowSourceProject.fastCommand.src`,`shadowSourceProject.fastCommand.dist`,`shadowSourceProject.subAgent.src`,`shadowSourceProject.subAgent.dist`,`shadowSourceProject.rule.src`,`shadowSourceProject.rule.dist`,`shadowSourceProject.globalMemory.src`,`shadowSourceProject.globalMemory.dist`,`shadowSourceProject.workspaceMemory.src`,`shadowSourceProject.workspaceMemory.dist`,`shadowSourceProject.project.src`,`shadowSourceProject.project.dist`,`logLevel`];function Tn(e){return wn.includes(e)}function En(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Dn(){return i.join(s.homedir(),dn,un)}function On(){let e=Dn();if(!r.existsSync(e))return{};try{let t=r.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function kn(e){let t=Dn(),n=i.dirname(t);r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}function An(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];(typeof i[t]!=`object`||i[t]===null)&&(i[t]={}),i=i[t]}i[r.at(-1)]=n}function jn(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return r}var Mn=class{name=`config`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc config key=value`),t.info(`Valid keys: ${wn.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=On(),r=[],i=[];for(let[e,a]of this.options){if(!Tn(e)){r.push(`Invalid key: ${e} (valid keys: ${wn.join(`, `)})`);continue}if(e===`logLevel`&&!En(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=jn(n,e);An(n,e,a),o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(kn(n),t.info(`global config written`,{path:Dn()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},Nn=class{name=`config-show`;async execute(e){let{logger:t}=e,r=new _n,i=r.load(),a=i.sources.map(e=>{let t=r.loadFromFile(e);return{path:e,layer:this.inferLayer(e),config:t.config}}),o={merged:i.config,sources:a};return n.stdout.write(`${JSON.stringify(o)}\n`),t.info(`config shown`,{sources:i.sources.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Configuration displayed (${a.length} source(s))`}}inferLayer(e){let t=n.cwd();return e.startsWith(t)?`cwd`:`global`}},Pn=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 gt(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s}=await xt(n,await _t(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await vt(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`}}logDryRunFiles(e,t){for(let n of e){let e=i.isAbsolute(n)?n:i.resolve(n);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=i.isAbsolute(e)?e:i.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},Fn=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=r(!0),a=await yt(n,i),o=await bt(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=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:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},In=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await Ct(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await yt(n,o),c=await bt(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function Ln(){return`2026.10218.12326`}var Rn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${Ln()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const zn=`tnmsc`,Bn=`
981
+ `};const qt=Object.fromEntries(Gt.map(e=>[e,{path:e,content:Kt[e]??``}])),Jt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`},Yt=JSON.parse(qt[`public/tnmsc.example.json`].content),Xt={reset:`\x1B[0m`,red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`,gray:`\x1B[90m`,blue:`\x1B[34m`,green:`\x1B[32m`,white:`\x1B[37m`,dim:`\x1B[2m`,bgRed:`\x1B[41m`},Zt={red:e=>`${Xt.red}${e}${Xt.reset}`,yellow:e=>`${Xt.yellow}${e}${Xt.reset}`,cyan:e=>`${Xt.cyan}${e}${Xt.reset}`,magenta:e=>`${Xt.magenta}${e}${Xt.reset}`,gray:e=>`${Xt.gray}${e}${Xt.reset}`,blue:e=>`${Xt.blue}${e}${Xt.reset}`,green:e=>`${Xt.green}${e}${Xt.reset}`,white:e=>`${Xt.white}${e}${Xt.reset}`,dim:e=>`${Xt.dim}${e}${Xt.reset}`,bgRed:e=>`${Xt.bgRed}${e}${Xt.reset}`};let Qt;const $t={error:Zt.red,warn:Zt.yellow,info:Zt.cyan,debug:Zt.magenta,trace:Zt.gray,fatal:Zt.bgRed},en={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function tn(e){if(e===null)return Zt.dim(`null`);if(e===void 0)return Zt.dim(`undefined`);if(typeof e==`boolean`)return Zt.yellow(String(e));if(typeof e==`number`)return Zt.blue(String(e));if(typeof e==`string`)return Zt.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>tn(e)).join(`,`)}]`;if(e instanceof Error){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 nn(t)}return typeof e==`object`?nn(e):String(e)}function nn(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?Zt.magenta(e):Zt.yellow(`"${e}"`)}:${tn(t)}`).join(`,`)}}`}function rn(){let e=new Date;return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}:${String(e.getSeconds()).padStart(2,`0`)}.${String(e.getMilliseconds()).padStart(3,`0`)}`}function an(e,t,n,r){let i=rn(),a=$t[e]??Zt.white,o=String(n),s=r!=null&&Object.keys(r).length>0,c=o===``,l={$:[i,e,t],_:s?c?r:{[o]:r}:n},u={$:[i,a(e.toUpperCase()),t]},d=s?c?r:{[o]:r}:n,f=nn({...u,_:d});return e===`error`||e===`fatal`?console.error(f):e===`warn`?console.warn(f):e===`debug`||e===`trace`?console.debug(f):console.log(f),l}function on(e,t,n){let r=en[e],i=en[n];return(n,...a)=>r>i?{$:[rn(),e,t],_:n}:typeof n==`string`?an(e,t,n,a.length===1&&typeof a[0]==`object`&&a[0]!==null?a[0]:a.length>0?{args:a}:void 0):typeof n==`object`&&n?an(e,t,``,n):an(e,t,n)}function sn(e){Qt=e}function cn(){return Qt}function ln(e,t){let n=t??Qt??process.env.LOG_LEVEL??`info`;return{error:on(`error`,e,n),warn:on(`warn`,e,n),info:on(`info`,e,n),debug:on(`debug`,e,n),trace:on(`trace`,e,n),fatal:on(`fatal`,e,n)}}const un=`.tnmsc.json`,dn=`.aindex`;function fn(){return i.join(s.homedir(),dn,un)}function pn(){return{...Yt}}function mn(e,t){let n=fn(),a=i.dirname(n);r.existsSync(a)||r.mkdirSync(a,{recursive:!0}),r.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}function hn(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object with "src" and "dist" string fields`),n;let r=e;return(!(`src`in r)||typeof r.src!=`string`)&&n.push(`${t}.src must be a string`),(!(`dist`in r)||typeof r.dist!=`string`)&&n.push(`${t}.dist must be a string`),n}function gn(e,t){let n=[];if(typeof e!=`object`||!e||Array.isArray(e))return n.push(`${t} must be an object`),{errors:n,config:void 0};let r=e;(!(`name`in r)||typeof r.name!=`string`)&&n.push(`${t}.name must be a string`);let i=[`skill`,`fastCommand`,`subAgent`,`rule`,`globalMemory`,`workspaceMemory`,`project`],a={};for(let e of i)if(e in r){let i=hn(r[e],`${t}.${e}`);if(n.push(...i),i.length===0){let t=r[e];a[e]={src:t.src,dist:t.dist}}}return n.length>0?{errors:n,config:void 0}:{errors:n,config:{name:r.name,skill:a.skill??{src:`src/skills`,dist:`dist/skills`},fastCommand:a.fastCommand??{src:`src/commands`,dist:`dist/commands`},subAgent:a.subAgent??{src:`src/agents`,dist:`dist/agents`},rule:a.rule??{src:`src/rules`,dist:`dist/rules`},globalMemory:a.globalMemory??{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:a.workspaceMemory??{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:a.project??{src:`app`,dist:`dist/app`}}}}var _n=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??un,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=ln(`ConfigLoader`)}getSearchPaths(e=n.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(i.join(e,this.configFileName)),this.searchGlobal&&t.push(i.join(s.homedir(),dn,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!r.existsSync(t))return{config:{},source:null,found:!1};let e=r.readFileSync(t,`utf8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=n.cwd()){let t=this.getSearchPaths(e),r=[];for(let e of t){let t=this.loadFromFile(e);t.found&&r.push(t)}return{config:this.mergeConfigs(r.map(e=>e.config)),sources:r.map(e=>e.source).filter(e=>e!==null),found:r.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];if(`version`in e&&(typeof e.version==`string`?n.version=e.version:r.push(`version must be a string`)),`workspaceDir`in e&&(typeof e.workspaceDir==`string`?n.workspaceDir=e.workspaceDir:r.push(`workspaceDir must be a string`)),`shadowSourceProject`in e){let{errors:t,config:i}=gn(e.shadowSourceProject,`shadowSourceProject`);r.push(...t),i!=null&&(n.shadowSourceProject=i)}if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`profile`in e){let t=e.profile;typeof t==`object`&&t&&!Array.isArray(t)?n.profile=t:r.push(`profile must be an object`)}if(`tool`in e){let t=e.tool;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))typeof n==`string`||n===void 0?i[t]=n:(r.push(`tool.${t} must be a string`),a=!1);a&&(n.tool=i)}else r.push(`tool must be an object`)}if(`fastCommandSeriesOptions`in e){let t=e.fastCommandSeriesOptions;typeof t==`object`&&t&&!Array.isArray(t)?n.fastCommandSeriesOptions=t:r.push(`fastCommandSeriesOptions must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=this.mergeShadowSourceProject(e.shadowSourceProject,t.shadowSourceProject);return{...e,...t,...n==null?{}:{shadowSourceProject:n}}},{})}mergeShadowSourceProject(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}resolveTilde(e){return e.startsWith(`~`)?i.join(s.homedir(),e.slice(1)):e}};let vn=null;function yn(e){return(e||!vn)&&(vn=new _n(e)),vn}function bn(e){return yn().load(e)}function xn(){let e=ln(`ConfigLoader`),t=fn();if(!r.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),mn(pn(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=r.readFileSync(t,`utf8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),Cn(t,e,[`Failed to read config: ${r}`])}let i;try{i=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),Cn(t,e,[`Invalid JSON: ${r}`])}if(typeof i!=`object`||!i||Array.isArray(i))return e.error(`global config must be a JSON object`,{path:t}),Cn(t,e,[`Config must be a JSON object`]);let a=Sn(i);if(a.length>0){for(let n of a)e.error(`config validation error`,{path:t,error:n});return Cn(t,e,a)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function Sn(e){let t=[];if(`version`in e&&typeof e.version!=`string`&&t.push(`version must be a string`),`workspaceDir`in e&&typeof e.workspaceDir!=`string`&&t.push(`workspaceDir must be a string`),`shadowSourceProject`in e){let{errors:n}=gn(e.shadowSourceProject,`shadowSourceProject`);t.push(...n)}if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`profile`in e){let n=e.profile;(typeof n!=`object`||!n||Array.isArray(n))&&t.push(`profile must be an object`)}if(!(`tool`in e))return t;let n=e.tool;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`tool must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))typeof r!=`string`&&r!==void 0&&t.push(`tool.${n} must be a string`)}return t}function Cn(e,t,n){try{r.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return mn(pn(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const wn=[`workspaceDir`,`shadowSourceProject.name`,`shadowSourceProject.skill.src`,`shadowSourceProject.skill.dist`,`shadowSourceProject.fastCommand.src`,`shadowSourceProject.fastCommand.dist`,`shadowSourceProject.subAgent.src`,`shadowSourceProject.subAgent.dist`,`shadowSourceProject.rule.src`,`shadowSourceProject.rule.dist`,`shadowSourceProject.globalMemory.src`,`shadowSourceProject.globalMemory.dist`,`shadowSourceProject.workspaceMemory.src`,`shadowSourceProject.workspaceMemory.dist`,`shadowSourceProject.project.src`,`shadowSourceProject.project.dist`,`logLevel`];function Tn(e){return wn.includes(e)}function En(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Dn(){return i.join(s.homedir(),dn,un)}function On(){let e=Dn();if(!r.existsSync(e))return{};try{let t=r.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function kn(e){let t=Dn(),n=i.dirname(t);r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}function An(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];(typeof i[t]!=`object`||i[t]===null)&&(i[t]={}),i=i[t]}i[r.at(-1)]=n}function jn(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return r}var Mn=class{name=`config`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc config key=value`),t.info(`Valid keys: ${wn.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=On(),r=[],i=[];for(let[e,a]of this.options){if(!Tn(e)){r.push(`Invalid key: ${e} (valid keys: ${wn.join(`, `)})`);continue}if(e===`logLevel`&&!En(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=jn(n,e);An(n,e,a),o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(kn(n),t.info(`global config written`,{path:Dn()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},Nn=class{name=`config-show`;async execute(e){let{logger:t}=e,r=new _n,i=r.load(),a=i.sources.map(e=>{let t=r.loadFromFile(e);return{path:e,layer:this.inferLayer(e),config:t.config}}),o={merged:i.config,sources:a};return n.stdout.write(`${JSON.stringify(o)}\n`),t.info(`config shown`,{sources:i.sources.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Configuration displayed (${a.length} source(s))`}}inferLayer(e){let t=n.cwd();return e.startsWith(t)?`cwd`:`global`}},Pn=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 gt(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let{filesToDelete:o,dirsToDelete:s}=await xt(n,await _t(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await vt(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:o.length,dirsAffected:s.length}),{success:!0,filesAffected:o.length,dirsAffected:s.length,message:`Dry-run complete, no files were deleted`}}logDryRunFiles(e,t){for(let n of e){let e=i.isAbsolute(n)?n:i.resolve(n);t.info(`would delete file`,{path:e,dryRun:!0})}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=i.isAbsolute(e)?e:i.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},Fn=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=r(!0),a=await yt(n,i),o=await bt(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=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:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},In=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await Ct(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await yt(n,o),c=await bt(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function Ln(){return`2026.10219.10049`}var Rn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${Ln()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const zn=`tnmsc`,Bn=`
982
982
  ${zn} v${Ln()} - Memory Sync CLI
983
983
 
984
984
  Synchronize AI memory and configuration files across projects.
@@ -1039,7 +1039,7 @@ CONFIG OPTIONS:
1039
1039
  CONFIGURATION:
1040
1040
  Configure via plugin.config.ts in your project root.
1041
1041
  See documentation for detailed configuration options.
1042
- `.trim();var Vn=class{name=`help`;async execute(e){return console.log(Bn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Hn(e,t){let n=i.join(e,`.git`),a=r.existsSync(n);return a?t?.info(`version control detected`,{path:n}):t?.warn(`no version control detected, please use git to manage your shadow source project`,{path:e}),{hasGit:a,gitPath:n}}function Un(e,t,n,a,o){if(n==null)return a;let s=i.relative(t,e),c=i.join(n,s);return r.existsSync(c)&&r.statSync(c).isFile()?(o?.debug(`copying from source`,{path:c}),r.readFileSync(c,`utf8`)):a}function Wn(e,t={}){let{sourceDir:n,logger:a}=t,o=[],s=[],c=[],l=[],u=new Set;r.existsSync(e)?(c.push(e),a?.debug(`directory exists`,{path:e})):(r.mkdirSync(e,{recursive:!0}),o.push(e),u.add(e),a?.info(`created directory`,{path:e}));for(let t of Object.values(qt)){let c=t.path,d=i.join(e,c),f=i.dirname(d);if(!r.existsSync(f)){r.mkdirSync(f,{recursive:!0});let t=f;for(;t!==e&&!u.has(t);)u.add(t),o.push(t),a?.info(`created directory`,{path:t}),t=i.dirname(t)}if(r.existsSync(d))l.push(d),a?.debug(`file exists`,{path:d});else{let i=Un(d,e,n,t.content,a);r.writeFileSync(d,i,`utf8`),s.push(d),a?.info(`created file`,{path:d})}}return{success:!0,rootPath:e,createdDirs:o,createdFiles:s,existedDirs:c,existedFiles:l}}function Gn(e){let t=e;return t.startsWith(`~`)&&(t=i.join(s.homedir(),t.slice(1))),i.normalize(t)}var Kn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Gn(n.workspaceDir),a=Wn(i.join(r,n.shadowSourceProject.name),{logger:t}),o=a.createdDirs.length===0&&a.createdFiles.length===0?`All ${a.existedDirs.length} directories and ${a.existedFiles.length} files already exist`:`Created ${a.createdDirs.length} directories and ${a.createdFiles.length} files (${a.existedDirs.length} dirs, ${a.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:a.createdDirs.length,filesCreated:a.createdFiles.length,dirsExisted:a.existedDirs.length,filesExisted:a.existedFiles.length}),{success:a.success,filesAffected:a.createdFiles.length,dirsAffected:a.createdDirs.length,message:o}}},qn=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),r=Jn(t);return n.stdout.write(`${JSON.stringify(r)}\n`),t}};function Jn(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:[]}}function Yn(){return`@truenine/memory-sync-cli`}function Xn(){return`https://registry.npmjs.org/${Yn()}/latest`}function Zn(e){let t=e.replace(/^v/,``),n=/^(\d+)\.(\d+)\.(\d+)/.exec(t);return n==null?null:[Number.parseInt(n[1],10),Number.parseInt(n[2],10),Number.parseInt(n[3],10)]}function Qn(e,t){let n=Zn(e),r=Zn(t);if(n==null||r==null)return 0;for(let e=0;e<3;e++){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1}return 0}const $n=3e3;async function er(){let e=new AbortController,t=setTimeout(()=>e.abort(),$n);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(Xn(),{headers:{Accept:`application/json`},signal:e.signal});if(clearTimeout(t),!n.ok)return{error:`HTTP ${n.status}: ${n.statusText}`};let r=await n.json();return r.version==null?{error:`Invalid response: missing version field`}:{version:r.version}}catch(e){return clearTimeout(t),e instanceof Error?e.name===`TimeoutError`||e.name===`AbortError`?{error:`Request timeout after ${$n}ms`}:{error:e.message}:{error:`Unknown network error`}}}function tr(){return`2026.10218.12326`}async function nr(){let e=tr();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await er();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=Qn(e,n);return r<0?{status:`outdated`,localVersion:e,remoteVersion:n}:r>0?{status:`development`,localVersion:e,remoteVersion:n}:{status:`current`,localVersion:e,remoteVersion:n}}function rr(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Yn()}@latest' to update.`);break;case`current`:e.error==null?t.info(`Version ${r} is up to date.`):t.error(`Version check failed: ${e.error}`);break;case`development`:i==null?t.debug(`Running in development mode, version check skipped.`):t.info(`Development version detected: ${r} > ${i}. Thanks for contributing!`);break}}function ir(){return new Date().getMinutes()%2==0}function ar(e){ir()&&nr().then(t=>{(t.status===`outdated`||t.error!=null)&&rr(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var or=class{name=`outdated`;async execute(e){let t=await nr();return rr(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},sr=class{name=`plugins`;async execute(e){let{logger:t,outputPlugins:r,userConfigOptions:i}=e,a=i.plugins,o=[];for(let e of a)o.push({name:e.name,kind:e.type===Tt.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let s=new Set(o.map(e=>e.name));for(let e of r)s.has(e.name)||o.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return n.stdout.write(`${JSON.stringify(o)}\n`),t.info(`plugins listed`,{count:o.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Listed ${o.length} plugin(s)`}}},cr=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};const lr={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 ur=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}({}),dr=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var fr=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 dr.Win;case`darwin`:return dr.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return dr.Linux;default:return dr.Unknown}}detectShellKind(){let e=(n.env.SHELL??n.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?ur.Bash:e.includes(`zsh`)?ur.Zsh:e.includes(`fish`)?ur.Fish:e.includes(`pwsh`)?ur.Pwsh:e.includes(`powershell`)?ur.PowerShell:e.includes(`cmd`)?ur.Cmd:e.endsWith(`/sh`)?ur.Sh:ur.Unknown}collectEnvContext(){return{...n.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...lr.default};return this.toolPreset===`claudeCode`?{...e,...lr.claudeCode}:this.toolPreset===`kiro`?{...e,...lr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let pr=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 mr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=pr.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}clear(){this.registrations.length=0,this.globalScope=null}};function hr(e){let t=[...e],n=t[0];n!=null&&gr(n)&&t.shift();let r=t[0];return r!=null&&_r(r)&&t.shift(),t}function gr(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replaceAll(`\\`,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function _r(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const vr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`,`plugins`]),yr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),br=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function xr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=br.get(n)??4;for(let e of t){let t=br.get(e)??4;t<r&&(r=t,n=e)}return n}function Sr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s,showFlag:c}=e;if(n)return new Rn;if(t)return new Vn;if(a!=null)return new cr(a);if(r===`version`)return new Rn;if(r===`help`)return new Vn;if(r===`outdated`)return new or;if(r===`init`)return new Kn;if(r===`dry-run`)return new Fn;if(r===`clean`)return i?new Pn:new wt;if(r===`plugins`)return new sr;if(r===`config`&&c)return new Nn;if(r!==`config`||o.length>0)return new In;let l=[];for(let e of s){let t=e.indexOf(`=`);t>0&&l.push([e.slice(0,t),e.slice(t+1)])}return new Mn([...o,...l])}function Cr(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,jsonFlag:!1,showFlag:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=yr.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--json`:t.jsonFlag=!0;break;case`--show`:t.showFlag=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;case`j`:t.jsonFlag=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,vr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var wr=class{logger;args;outputPlugins=[];constructor(...e){this.args=Cr(hr(e.filter(e=>e!=null)));let t=xr(this.args);t!=null&&sn(t),this.logger=ln(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){ar(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand();this.args.jsonFlag&&(sn(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new qn(i)));let a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return Sr(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:et.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:et.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new Mt(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length===e.length)return a;throw new jt(this.findCyclePath(e,n))}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a.at(-1));return a.slice(e)}i.clear(),a.length=0}return[...n]}async executePluginsInOrder(e,t,n=!1,r){if(e.length===0)return{};let i=this.topologicalSort(e),a=new fr({userConfig:r}).collect(),o=new mr;o.setGlobalScope(a),this.logger.debug(`global scope collected`,{osInfo:{platform:a.os.platform,arch:a.os.arch,shellKind:a.os.shellKind},hasProfile:Object.keys(a.profile).length>0,hasTool:Object.keys(a.tool).length>0});let s=new Map,c={};for(let e of i){let r=this.buildDependencyContext(e,s),i={...t,dependencyContext:r,globalScope:a,scopeRegistry:o},l=e;l.executeEffects!=null&&await l.executeEffects(i,n);let u=await e.collect(i);s.set(e.name,u),c=this.mergeContexts(c,u);let d=e;if(d.getRegisteredScopes!=null){let t=d.getRegisteredScopes();for(let{namespace:n,values:r}of t)o.register(n,r,pr.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(r)})}}return c}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let{workspace:n}=e;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:[...e.values()]}}else ({workspace:n}=t);let r=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],i=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],a=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],o=t.skills==null?e.skills:[...e.skills??[],...t.skills],s=t.rules==null?e.rules:[...e.rules??[],...t.rules],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts],f=t.globalGitIgnore??e.globalGitIgnore,p=t.shadowGitExclude??e.shadowGitExclude;return{...n==null?{}:{workspace:n},...r==null?{}:{ideConfigFiles:r},...i==null?{}:{fastCommands:i},...a==null?{}:{subAgents:a},...o==null?{}:{skills:o},...s==null?{}:{rules:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d},...f==null?{}:{globalGitIgnore:f},...p==null?{}:{shadowGitExclude:p}}}};const Tr={name:`tnmsc-shadow`,skill:{src:`src/skills`,dist:`dist/skills`},fastCommand:{src:`src/commands`,dist:`dist/commands`},subAgent:{src:`src/agents`,dist:`dist/agents`},rule:{src:`src/rules`,dist:`dist/rules`},globalMemory:{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:{src:`app`,dist:`dist/app`}},Er={...Yt,shadowSourceProject:Tr,fastCommandSeriesOptions:{},plugins:[]};function Dr(e){return{...e.version==null?{}:{version:e.version},...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProject==null?{}:{shadowSourceProject:e.shadowSourceProject},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function Or(...e){return e.reduce((e,t)=>kr(e,t),{...Er})}function kr(e,t){let n=t.plugins,r=t.fastCommandSeriesOptions;return{...e,...t,shadowSourceProject:Ar(e.shadowSourceProject,t.shadowSourceProject),plugins:[...e.plugins,...n??[]],fastCommandSeriesOptions:jr(e.fastCommandSeriesOptions,r)}}function Ar(e,t){return t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}function jr(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function Mr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Nr(e={}){xn().shouldExit&&n.exit(1);let t,a,o;Mr(e)?({pluginOptions:o={},cwd:a}={pluginOptions:e.pluginOptions,cwd:e.cwd},t=e.loadUserConfig??!0):(o=e,t=!0);let s={},c=!1,l=[],u;if(t){let e=bn(a);c=e.found,l=e.sources,e.found&&(s=Dr(e.config),u=e.config)}let d=Or(s,o),{plugins:f=[],logLevel:p}=d,m=ln(`defineConfig`,p);c?m.info(`user config loaded`,{sources:l}):m.info(`no user config found, using defaults`,{workspaceDir:Er.workspaceDir,shadowSourceProjectName:Er.shadowSourceProject.name,logLevel:Er.logLevel});let h={logger:m,userConfigOptions:d,fs:r,path:i,glob:et.default},g=f.filter(e=>e.type===Tt.Input),_=f.filter(e=>e.type===Tt.Output),v=await new wr().executePluginsInOrder(g,h,!1,u);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...v.rules!=null&&{rules:v.rules},...v.globalMemory!=null&&{globalMemory:v.globalMemory},...v.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:v.aiAgentIgnoreConfigFiles},...v.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:v.shadowSourceProjectDir},...v.readmePrompts!=null&&{readmePrompts:v.readmePrompts},...v.globalGitIgnore!=null&&{globalGitIgnore:v.globalGitIgnore},...v.shadowGitExclude!=null&&{shadowGitExclude:v.shadowGitExclude}};return v.shadowSourceProjectDir!=null&&Hn(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:d}}const Pr=Ur(/[A-Za-z]/),Fr=Ur(/[\dA-Za-z]/),Ir=Ur(/[#-'*+\--9=?A-Z^-~]/);function Lr(e){return e!==null&&(e<32||e===127)}const Rr=Ur(/\d/),zr=Ur(/[\dA-Fa-f]/),Br=Ur(/[!-/:-@[-`{-~]/);function B(e){return e!==null&&e<-2}function V(e){return e!==null&&(e<0||e===32)}function H(e){return e===-2||e===-1||e===32}const Vr=Ur(/\p{P}|\p{S}/u),Hr=Ur(/\s/);function Ur(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Wr=S(y(((e,t)=>{(function(){var e=t===void 0?function(){return this||(0,eval)(`this`)}():t.exports=i;e.format=i,e.vsprintf=r,typeof console<`u`&&typeof console.log==`function`&&(e.printf=n);function n(){console.log(i.apply(null,arguments))}function r(e,t){return i.apply(null,[e].concat(t))}function i(e){for(var t=1,n=[].slice.call(arguments),r=0,i=e.length,a=``,o,s=!1,c,l,u=!1,d,f=function(){return n[t++]},p=function(){for(var t=``;/\d/.test(e[r]);)t+=e[r++],o=e[r];return t.length>0?parseInt(t):null};r<i;++r)if(o=e[r],s)switch(s=!1,o==`.`?(u=!1,o=e[++r]):o==`0`&&e[r+1]==`.`?(u=!0,r+=2,o=e[r]):u=!0,d=p(),o){case`b`:a+=parseInt(f(),10).toString(2);break;case`c`:c=f(),typeof c==`string`||c instanceof String?a+=c:a+=String.fromCharCode(parseInt(c,10));break;case`d`:a+=parseInt(f(),10);break;case`f`:l=String(parseFloat(f()).toFixed(d||6)),a+=u?l:l.replace(/^0/,``);break;case`j`:a+=JSON.stringify(f());break;case`o`:a+=`0`+parseInt(f(),10).toString(8);break;case`s`:a+=f();break;case`x`:a+=`0x`+parseInt(f(),10).toString(16);break;case`X`:a+=`0x`+parseInt(f(),10).toString(16).toUpperCase();break;default:a+=o;break}else o===`%`?s=!0:a+=o;return a}})()}))(),1);const Gr=Object.assign(Kr(Error),{eval:Kr(EvalError),range:Kr(RangeError),reference:Kr(ReferenceError),syntax:Kr(SyntaxError),type:Kr(TypeError),uri:Kr(URIError)});function Kr(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Wr.default)(t,...n))}}const qr={}.hasOwnProperty,Jr={yaml:`-`,toml:`+`};function Yr(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Xr(r[n]);return t}function Xr(e){let t=e;if(typeof t==`string`){if(!qr.call(Jr,t))throw Gr("Missing matter definition for `%s`",t);t={type:t,marker:Jr[t]}}else if(typeof t!=`object`)throw Gr("Expected matter to be an object, not `%j`",t);if(!qr.call(t,`type`))throw Gr("Missing `type` in matter `%j`",t);if(!qr.call(t,`fence`)&&!qr.call(t,`marker`))throw Gr("Missing `marker` or `fence` in matter `%j`",t);return t}function Zr(e){let t=Yr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=$r(e,`open`).charCodeAt(0),a=Qr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Qr(e){let t=e.anywhere,n=e.type,r=n+`Fence`,i=r+`Sequence`,a=n+`Value`,o={tokenize:u,partial:!0},s,c=0;return{tokenize:l,concrete:!0};function l(l,u,d){let f=this;return p;function p(a){let o=f.now();return o.column===1&&(o.line===1||t)&&(s=$r(e,`open`),c=0,a===s.charCodeAt(c))?(l.enter(n),l.enter(r),l.enter(i),m(a)):d(a)}function m(e){return c===s.length?(l.exit(i),H(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return H(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return B(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=$r(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||B(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||B(e)?(l.exit(a),y(e)):(l.consume(e),v)}function y(e){return e===null?d(e):(l.enter(`lineEnding`),l.consume(e),l.exit(`lineEnding`),l.attempt(o,b,_))}function b(e){return l.exit(n),u(e)}}function u(e,t,n){let a=0;return o;function o(t){return t===s.charCodeAt(a)?(e.enter(r),e.enter(i),c(t)):n(t)}function c(t){return a===s.length?(e.exit(i),H(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return H(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||B(i)?(e.exit(r),t(i)):n(i)}}}function $r(e,t){return e.marker?ei(e.marker,t).repeat(3):ei(e.fence,t)}function ei(e,t){return typeof e==`string`?e:e[t]}function ti(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function ni(e){let t=Yr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=ri(e),r[e.type]=ii,r[e.type+`Value`]=ai}return{enter:n,exit:r}}function ri(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function ii(e){let t=this.resume(),n=this.stack[this.stack.length-1];`value`in n,this.exit(e),n.value=t.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``)}function ai(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function oi(e){let t=[],n={},r=Yr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=si(e);let a=ci(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:ti(a.charAt(1))})}return{unsafe:t,handlers:n}}function si(e){let t=ci(e,`open`),n=ci(e,`close`);return r;function r(e){return t+(e.value?`
1042
+ `.trim();var Vn=class{name=`help`;async execute(e){return console.log(Bn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Hn(e,t){let n=i.join(e,`.git`),a=r.existsSync(n);return a?t?.info(`version control detected`,{path:n}):t?.warn(`no version control detected, please use git to manage your shadow source project`,{path:e}),{hasGit:a,gitPath:n}}function Un(e,t,n,a,o){if(n==null)return a;let s=i.relative(t,e),c=i.join(n,s);return r.existsSync(c)&&r.statSync(c).isFile()?(o?.debug(`copying from source`,{path:c}),r.readFileSync(c,`utf8`)):a}function Wn(e,t={}){let{sourceDir:n,logger:a}=t,o=[],s=[],c=[],l=[],u=new Set;r.existsSync(e)?(c.push(e),a?.debug(`directory exists`,{path:e})):(r.mkdirSync(e,{recursive:!0}),o.push(e),u.add(e),a?.info(`created directory`,{path:e}));for(let t of Object.values(qt)){let c=t.path,d=i.join(e,c),f=i.dirname(d);if(!r.existsSync(f)){r.mkdirSync(f,{recursive:!0});let t=f;for(;t!==e&&!u.has(t);)u.add(t),o.push(t),a?.info(`created directory`,{path:t}),t=i.dirname(t)}if(r.existsSync(d))l.push(d),a?.debug(`file exists`,{path:d});else{let i=Un(d,e,n,t.content,a);r.writeFileSync(d,i,`utf8`),s.push(d),a?.info(`created file`,{path:d})}}return{success:!0,rootPath:e,createdDirs:o,createdFiles:s,existedDirs:c,existedFiles:l}}function Gn(e){let t=e;return t.startsWith(`~`)&&(t=i.join(s.homedir(),t.slice(1))),i.normalize(t)}var Kn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Gn(n.workspaceDir),a=Wn(i.join(r,n.shadowSourceProject.name),{logger:t}),o=a.createdDirs.length===0&&a.createdFiles.length===0?`All ${a.existedDirs.length} directories and ${a.existedFiles.length} files already exist`:`Created ${a.createdDirs.length} directories and ${a.createdFiles.length} files (${a.existedDirs.length} dirs, ${a.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:a.createdDirs.length,filesCreated:a.createdFiles.length,dirsExisted:a.existedDirs.length,filesExisted:a.existedFiles.length}),{success:a.success,filesAffected:a.createdFiles.length,dirsAffected:a.createdDirs.length,message:o}}},qn=class{name;inner;constructor(e){this.inner=e,this.name=`json:${e.name}`}async execute(e){let t=await this.inner.execute(e),r=Jn(t);return n.stdout.write(`${JSON.stringify(r)}\n`),t}};function Jn(e){return{success:e.success,filesAffected:e.filesAffected,dirsAffected:e.dirsAffected,...e.message!=null&&{message:e.message},pluginResults:[],errors:[]}}function Yn(){return`@truenine/memory-sync-cli`}function Xn(){return`https://registry.npmjs.org/${Yn()}/latest`}function Zn(e){let t=e.replace(/^v/,``),n=/^(\d+)\.(\d+)\.(\d+)/.exec(t);return n==null?null:[Number.parseInt(n[1],10),Number.parseInt(n[2],10),Number.parseInt(n[3],10)]}function Qn(e,t){let n=Zn(e),r=Zn(t);if(n==null||r==null)return 0;for(let e=0;e<3;e++){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1}return 0}const $n=3e3;async function er(){let e=new AbortController,t=setTimeout(()=>e.abort(),$n);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(Xn(),{headers:{Accept:`application/json`},signal:e.signal});if(clearTimeout(t),!n.ok)return{error:`HTTP ${n.status}: ${n.statusText}`};let r=await n.json();return r.version==null?{error:`Invalid response: missing version field`}:{version:r.version}}catch(e){return clearTimeout(t),e instanceof Error?e.name===`TimeoutError`||e.name===`AbortError`?{error:`Request timeout after ${$n}ms`}:{error:e.message}:{error:`Unknown network error`}}}function tr(){return`2026.10219.10049`}async function nr(){let e=tr();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await er();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=Qn(e,n);return r<0?{status:`outdated`,localVersion:e,remoteVersion:n}:r>0?{status:`development`,localVersion:e,remoteVersion:n}:{status:`current`,localVersion:e,remoteVersion:n}}function rr(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Yn()}@latest' to update.`);break;case`current`:e.error==null?t.info(`Version ${r} is up to date.`):t.error(`Version check failed: ${e.error}`);break;case`development`:i==null?t.debug(`Running in development mode, version check skipped.`):t.info(`Development version detected: ${r} > ${i}. Thanks for contributing!`);break}}function ir(){return new Date().getMinutes()%2==0}function ar(e){ir()&&nr().then(t=>{(t.status===`outdated`||t.error!=null)&&rr(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var or=class{name=`outdated`;async execute(e){let t=await nr();return rr(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},sr=class{name=`plugins`;async execute(e){let{logger:t,outputPlugins:r,userConfigOptions:i}=e,a=i.plugins,o=[];for(let e of a)o.push({name:e.name,kind:e.type===Tt.Input?`Input`:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});let s=new Set(o.map(e=>e.name));for(let e of r)s.has(e.name)||o.push({name:e.name,kind:`Output`,description:e.name,dependencies:[...e.dependsOn??[]]});return n.stdout.write(`${JSON.stringify(o)}\n`),t.info(`plugins listed`,{count:o.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Listed ${o.length} plugin(s)`}}},cr=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};const lr={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 ur=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}({}),dr=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var fr=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 dr.Win;case`darwin`:return dr.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return dr.Linux;default:return dr.Unknown}}detectShellKind(){let e=(n.env.SHELL??n.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?ur.Bash:e.includes(`zsh`)?ur.Zsh:e.includes(`fish`)?ur.Fish:e.includes(`pwsh`)?ur.Pwsh:e.includes(`powershell`)?ur.PowerShell:e.includes(`cmd`)?ur.Cmd:e.endsWith(`/sh`)?ur.Sh:ur.Unknown}collectEnvContext(){return{...n.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...lr.default};return this.toolPreset===`claudeCode`?{...e,...lr.claudeCode}:this.toolPreset===`kiro`?{...e,...lr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let pr=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 mr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=pr.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}clear(){this.registrations.length=0,this.globalScope=null}};function hr(e){let t=[...e],n=t[0];n!=null&&gr(n)&&t.shift();let r=t[0];return r!=null&&_r(r)&&t.shift(),t}function gr(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replaceAll(`\\`,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function _r(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const vr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`,`plugins`]),yr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),br=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function xr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=br.get(n)??4;for(let e of t){let t=br.get(e)??4;t<r&&(r=t,n=e)}return n}function Sr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s,showFlag:c}=e;if(n)return new Rn;if(t)return new Vn;if(a!=null)return new cr(a);if(r===`version`)return new Rn;if(r===`help`)return new Vn;if(r===`outdated`)return new or;if(r===`init`)return new Kn;if(r===`dry-run`)return new Fn;if(r===`clean`)return i?new Pn:new wt;if(r===`plugins`)return new sr;if(r===`config`&&c)return new Nn;if(r!==`config`||o.length>0)return new In;let l=[];for(let e of s){let t=e.indexOf(`=`);t>0&&l.push([e.slice(0,t),e.slice(t+1)])}return new Mn([...o,...l])}function Cr(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,jsonFlag:!1,showFlag:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=yr.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--json`:t.jsonFlag=!0;break;case`--show`:t.showFlag=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;case`j`:t.jsonFlag=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,vr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var wr=class{logger;args;outputPlugins=[];constructor(...e){this.args=Cr(hr(e.filter(e=>e!=null)));let t=xr(this.args);t!=null&&sn(t),this.logger=ln(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){ar(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand();this.args.jsonFlag&&(sn(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new qn(i)));let a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return Sr(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:et.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:et.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new Mt(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length===e.length)return a;throw new jt(this.findCyclePath(e,n))}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a.at(-1));return a.slice(e)}i.clear(),a.length=0}return[...n]}async executePluginsInOrder(e,t,n=!1,r){if(e.length===0)return{};let i=this.topologicalSort(e),a=new fr({userConfig:r}).collect(),o=new mr;o.setGlobalScope(a),this.logger.debug(`global scope collected`,{osInfo:{platform:a.os.platform,arch:a.os.arch,shellKind:a.os.shellKind},hasProfile:Object.keys(a.profile).length>0,hasTool:Object.keys(a.tool).length>0});let s=new Map,c={};for(let e of i){let r=this.buildDependencyContext(e,s),i={...t,dependencyContext:r,globalScope:a,scopeRegistry:o},l=e;l.executeEffects!=null&&await l.executeEffects(i,n);let u=await e.collect(i);s.set(e.name,u),c=this.mergeContexts(c,u);let d=e;if(d.getRegisteredScopes!=null){let t=d.getRegisteredScopes();for(let{namespace:n,values:r}of t)o.register(n,r,pr.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(r)})}}return c}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let{workspace:n}=e;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:[...e.values()]}}else ({workspace:n}=t);let r=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],i=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],a=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],o=t.skills==null?e.skills:[...e.skills??[],...t.skills],s=t.rules==null?e.rules:[...e.rules??[],...t.rules],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts],f=t.globalGitIgnore??e.globalGitIgnore,p=t.shadowGitExclude??e.shadowGitExclude;return{...n==null?{}:{workspace:n},...r==null?{}:{ideConfigFiles:r},...i==null?{}:{fastCommands:i},...a==null?{}:{subAgents:a},...o==null?{}:{skills:o},...s==null?{}:{rules:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d},...f==null?{}:{globalGitIgnore:f},...p==null?{}:{shadowGitExclude:p}}}};const Tr={name:`tnmsc-shadow`,skill:{src:`src/skills`,dist:`dist/skills`},fastCommand:{src:`src/commands`,dist:`dist/commands`},subAgent:{src:`src/agents`,dist:`dist/agents`},rule:{src:`src/rules`,dist:`dist/rules`},globalMemory:{src:`app/global.cn.mdx`,dist:`dist/global.mdx`},workspaceMemory:{src:`app/workspace.cn.mdx`,dist:`dist/app/workspace.mdx`},project:{src:`app`,dist:`dist/app`}},Er={...Yt,shadowSourceProject:Tr,fastCommandSeriesOptions:{},plugins:[]};function Dr(e){return{...e.version==null?{}:{version:e.version},...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProject==null?{}:{shadowSourceProject:e.shadowSourceProject},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function Or(...e){return e.reduce((e,t)=>kr(e,t),{...Er})}function kr(e,t){let n=t.plugins,r=t.fastCommandSeriesOptions;return{...e,...t,shadowSourceProject:Ar(e.shadowSourceProject,t.shadowSourceProject),plugins:[...e.plugins,...n??[]],fastCommandSeriesOptions:jr(e.fastCommandSeriesOptions,r)}}function Ar(e,t){return t==null?e:{name:t.name??e.name,skill:{...e.skill,...t.skill},fastCommand:{...e.fastCommand,...t.fastCommand},subAgent:{...e.subAgent,...t.subAgent},rule:{...e.rule,...t.rule},globalMemory:{...e.globalMemory,...t.globalMemory},workspaceMemory:{...e.workspaceMemory,...t.workspaceMemory},project:{...e.project,...t.project}}}function jr(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function Mr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Nr(e={}){xn().shouldExit&&n.exit(1);let t,a,o;Mr(e)?({pluginOptions:o={},cwd:a}={pluginOptions:e.pluginOptions,cwd:e.cwd},t=e.loadUserConfig??!0):(o=e,t=!0);let s={},c=!1,l=[],u;if(t){let e=bn(a);c=e.found,l=e.sources,e.found&&(s=Dr(e.config),u=e.config)}let d=Or(s,o),{plugins:f=[],logLevel:p}=d,m=ln(`defineConfig`,p);c?m.info(`user config loaded`,{sources:l}):m.info(`no user config found, using defaults`,{workspaceDir:Er.workspaceDir,shadowSourceProjectName:Er.shadowSourceProject.name,logLevel:Er.logLevel});let h={logger:m,userConfigOptions:d,fs:r,path:i,glob:et.default},g=f.filter(e=>e.type===Tt.Input),_=f.filter(e=>e.type===Tt.Output),v=await new wr().executePluginsInOrder(g,h,!1,u);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...v.rules!=null&&{rules:v.rules},...v.globalMemory!=null&&{globalMemory:v.globalMemory},...v.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:v.aiAgentIgnoreConfigFiles},...v.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:v.shadowSourceProjectDir},...v.readmePrompts!=null&&{readmePrompts:v.readmePrompts},...v.globalGitIgnore!=null&&{globalGitIgnore:v.globalGitIgnore},...v.shadowGitExclude!=null&&{shadowGitExclude:v.shadowGitExclude}};return v.shadowSourceProjectDir!=null&&Hn(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:d}}const Pr=Ur(/[A-Za-z]/),Fr=Ur(/[\dA-Za-z]/),Ir=Ur(/[#-'*+\--9=?A-Z^-~]/);function Lr(e){return e!==null&&(e<32||e===127)}const Rr=Ur(/\d/),zr=Ur(/[\dA-Fa-f]/),Br=Ur(/[!-/:-@[-`{-~]/);function B(e){return e!==null&&e<-2}function V(e){return e!==null&&(e<0||e===32)}function H(e){return e===-2||e===-1||e===32}const Vr=Ur(/\p{P}|\p{S}/u),Hr=Ur(/\s/);function Ur(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Wr=S(y(((e,t)=>{(function(){var e=t===void 0?function(){return this||(0,eval)(`this`)}():t.exports=i;e.format=i,e.vsprintf=r,typeof console<`u`&&typeof console.log==`function`&&(e.printf=n);function n(){console.log(i.apply(null,arguments))}function r(e,t){return i.apply(null,[e].concat(t))}function i(e){for(var t=1,n=[].slice.call(arguments),r=0,i=e.length,a=``,o,s=!1,c,l,u=!1,d,f=function(){return n[t++]},p=function(){for(var t=``;/\d/.test(e[r]);)t+=e[r++],o=e[r];return t.length>0?parseInt(t):null};r<i;++r)if(o=e[r],s)switch(s=!1,o==`.`?(u=!1,o=e[++r]):o==`0`&&e[r+1]==`.`?(u=!0,r+=2,o=e[r]):u=!0,d=p(),o){case`b`:a+=parseInt(f(),10).toString(2);break;case`c`:c=f(),typeof c==`string`||c instanceof String?a+=c:a+=String.fromCharCode(parseInt(c,10));break;case`d`:a+=parseInt(f(),10);break;case`f`:l=String(parseFloat(f()).toFixed(d||6)),a+=u?l:l.replace(/^0/,``);break;case`j`:a+=JSON.stringify(f());break;case`o`:a+=`0`+parseInt(f(),10).toString(8);break;case`s`:a+=f();break;case`x`:a+=`0x`+parseInt(f(),10).toString(16);break;case`X`:a+=`0x`+parseInt(f(),10).toString(16).toUpperCase();break;default:a+=o;break}else o===`%`?s=!0:a+=o;return a}})()}))(),1);const Gr=Object.assign(Kr(Error),{eval:Kr(EvalError),range:Kr(RangeError),reference:Kr(ReferenceError),syntax:Kr(SyntaxError),type:Kr(TypeError),uri:Kr(URIError)});function Kr(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Wr.default)(t,...n))}}const qr={}.hasOwnProperty,Jr={yaml:`-`,toml:`+`};function Yr(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Xr(r[n]);return t}function Xr(e){let t=e;if(typeof t==`string`){if(!qr.call(Jr,t))throw Gr("Missing matter definition for `%s`",t);t={type:t,marker:Jr[t]}}else if(typeof t!=`object`)throw Gr("Expected matter to be an object, not `%j`",t);if(!qr.call(t,`type`))throw Gr("Missing `type` in matter `%j`",t);if(!qr.call(t,`fence`)&&!qr.call(t,`marker`))throw Gr("Missing `marker` or `fence` in matter `%j`",t);return t}function Zr(e){let t=Yr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=$r(e,`open`).charCodeAt(0),a=Qr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Qr(e){let t=e.anywhere,n=e.type,r=n+`Fence`,i=r+`Sequence`,a=n+`Value`,o={tokenize:u,partial:!0},s,c=0;return{tokenize:l,concrete:!0};function l(l,u,d){let f=this;return p;function p(a){let o=f.now();return o.column===1&&(o.line===1||t)&&(s=$r(e,`open`),c=0,a===s.charCodeAt(c))?(l.enter(n),l.enter(r),l.enter(i),m(a)):d(a)}function m(e){return c===s.length?(l.exit(i),H(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return H(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return B(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=$r(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||B(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||B(e)?(l.exit(a),y(e)):(l.consume(e),v)}function y(e){return e===null?d(e):(l.enter(`lineEnding`),l.consume(e),l.exit(`lineEnding`),l.attempt(o,b,_))}function b(e){return l.exit(n),u(e)}}function u(e,t,n){let a=0;return o;function o(t){return t===s.charCodeAt(a)?(e.enter(r),e.enter(i),c(t)):n(t)}function c(t){return a===s.length?(e.exit(i),H(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return H(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||B(i)?(e.exit(r),t(i)):n(i)}}}function $r(e,t){return e.marker?ei(e.marker,t).repeat(3):ei(e.fence,t)}function ei(e,t){return typeof e==`string`?e:e[t]}function ti(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function ni(e){let t=Yr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=ri(e),r[e.type]=ii,r[e.type+`Value`]=ai}return{enter:n,exit:r}}function ri(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function ii(e){let t=this.resume(),n=this.stack[this.stack.length-1];`value`in n,this.exit(e),n.value=t.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``)}function ai(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function oi(e){let t=[],n={},r=Yr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=si(e);let a=ci(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:ti(a.charAt(1))})}return{unsafe:t,handlers:n}}function si(e){let t=ci(e,`open`),n=ci(e,`close`);return r;function r(e){return t+(e.value?`
1043
1043
  `+e.value:``)+`
1044
1044
  `+n}}function ci(e,t){return e.marker?li(e.marker,t).repeat(3):li(e.fence,t)}function li(e,t){return typeof e==`string`?e:e[t]}function ui(e){let t=this,n=e||`yaml`,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Zr(n)),a.push(ni(n)),o.push(oi(n))}function di(e,t){let n=String(e);if(typeof t!=`string`)throw TypeError(`Expected character`);let r=0,i=n.indexOf(t);for(;i!==-1;)r++,i=n.indexOf(t,i+t.length);return r}const fi=(function(e){if(e==null)return _i;if(typeof e==`function`)return gi(e);if(typeof e==`object`)return Array.isArray(e)?pi(e):mi(e);if(typeof e==`string`)return hi(e);throw Error(`Expected function, string, or object as test`)});function pi(e){let t=[],n=-1;for(;++n<e.length;)t[n]=fi(e[n]);return gi(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}function mi(e){let t=e;return gi(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function hi(e){return gi(t);function t(t){return t&&t.type===e}}function gi(e){return t;function t(t,n,r){return!!(vi(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function _i(){return!0}function vi(e){return typeof e==`object`&&!!e&&`type`in e}function yi(e){return`\x1B[33m`+e+`\x1B[39m`}const bi=[];function xi(e,t,n,r){let i;typeof t==`function`&&typeof n!=`function`?(r=n,n=t):i=t;let a=fi(i),o=r?-1:1;s(e,void 0,[])();function s(e,i,c){let l=e&&typeof e==`object`?e:{};if(typeof l.type==`string`){let t=typeof l.tagName==`string`?l.tagName:typeof l.name==`string`?l.name:void 0;Object.defineProperty(u,`name`,{value:`node (`+yi(e.type+(t?`<`+t+`>`:``))+`)`})}return u;function u(){let l=bi,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=Si(n(e,c)),l[0]===!1))return l;if(`children`in e&&e.children){let t=e;if(t.children&&l[0]!==`skip`)for(d=(r?t.children.length:-1)+o,f=c.concat(t);d>-1&&d<t.children.length;){let e=t.children[d];if(u=s(e,d,f)(),u[0]===!1)return u;d=typeof u[1]==`number`?u[1]:d+o}}return l}}}function Si(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?bi:[e]}function Ci(e,t,n){let r=fi((n||{}).ignore||[]),i=wi(t),a=-1;for(;++a<i.length;)xi(e,`text`,o);function o(e,t){let n=-1,i;for(;++n<t.length;){let e=t[n],a=i?i.children:void 0;if(r(e,a?a.indexOf(e):void 0,i))return;i=e}if(i)return s(e,t)}function s(e,t){let n=t[t.length-1],r=i[a][0],o=i[a][1],s=0,c=n.children.indexOf(e),l=!1,u=[];r.lastIndex=0;let d=r.exec(e.value);for(;d;){let n=d.index,i={index:d.index,input:d.input,stack:[...t,e]},a=o(...d,i);if(typeof a==`string`&&(a=a.length>0?{type:`text`,value:a}:void 0),a===!1?r.lastIndex=n+1:(s!==n&&u.push({type:`text`,value:e.value.slice(s,n)}),Array.isArray(a)?u.push(...a):a&&u.push(a),s=n+d[0].length,l=!0),!r.global)break;d=r.exec(e.value)}return l?(s<e.value.length&&u.push({type:`text`,value:e.value.slice(s)}),n.children.splice(c,1,...u)):u=[e],c+u.length}}function wi(e){let t=[];if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([Ti(e[0]),Ei(e[1])])}return t}function Ti(e){return typeof e==`string`?new RegExp(ti(e),`g`):e}function Ei(e){return typeof e==`function`?e:function(){return e}}const Di=`phrasing`,Oi=[`autolink`,`link`,`image`,`label`];function ki(){return{transforms:[Li],enter:{literalAutolink:ji,literalAutolinkEmail:Mi,literalAutolinkHttp:Mi,literalAutolinkWww:Mi},exit:{literalAutolink:Ii,literalAutolinkEmail:Fi,literalAutolinkHttp:Ni,literalAutolinkWww:Pi}}}function Ai(){return{unsafe:[{character:`@`,before:`[+\\-.\\w]`,after:`[\\-.\\w]`,inConstruct:Di,notInConstruct:Oi},{character:`.`,before:`[Ww]`,after:`[\\-.\\w]`,inConstruct:Di,notInConstruct:Oi},{character:`:`,before:`[ps]`,after:`\\/`,inConstruct:Di,notInConstruct:Oi}]}}function ji(e){this.enter({type:`link`,title:null,url:``,children:[]},e)}function Mi(e){this.config.enter.autolinkProtocol.call(this,e)}function Ni(e){this.config.exit.autolinkProtocol.call(this,e)}function Pi(e){this.config.exit.data.call(this,e);let t=this.stack[this.stack.length-1];t.type,t.url=`http://`+this.sliceSerialize(e)}function Fi(e){this.config.exit.autolinkEmail.call(this,e)}function Ii(e){this.exit(e)}function Li(e){Ci(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Ri],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,zi]],{ignore:[`link`,`linkReference`]})}function Ri(e,t,n,r,i){let a=``;if(!Hi(i)||(/^w/i.test(t)&&(n=t+n,t=``,a=`http://`),!Bi(n)))return!1;let o=Vi(n+r);if(!o[0])return!1;let s={type:`link`,title:null,url:a+t+o[0],children:[{type:`text`,value:t+o[0]}]};return o[1]?[s,{type:`text`,value:o[1]}]:s}function zi(e,t,n,r){return!Hi(r,!0)||/[-\d_]$/.test(n)?!1:{type:`link`,title:null,url:`mailto:`+t+`@`+n,children:[{type:`text`,value:t+`@`+n}]}}function Bi(e){let t=e.split(`.`);return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function Vi(e){let t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(`)`),i=di(e,`(`),a=di(e,`)`);for(;r!==-1&&i>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(`)`),a++;return[e,n]}function Hi(e,t){let n=e.input.charCodeAt(e.index-1);return(e.index===0||Hr(n)||Vr(n))&&(!t||n!==47)}function Ui(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}$i.peek=Qi;function Wi(){this.buffer()}function Gi(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ki(){this.buffer()}function qi(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Ji(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ui(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Yi(e){this.exit(e)}function Xi(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ui(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zi(e){this.exit(e)}function Qi(){return`[`}function $i(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function ea(){return{enter:{gfmFootnoteCallString:Wi,gfmFootnoteCall:Gi,gfmFootnoteDefinitionLabelString:Ki,gfmFootnoteDefinition:qi},exit:{gfmFootnoteCallString:Ji,gfmFootnoteCall:Yi,gfmFootnoteDefinitionLabelString:Xi,gfmFootnoteDefinition:Zi}}}function ta(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:$i},unsafe:[{character:`[`,inConstruct:[`label`,`phrasing`,`reference`]}]};function n(e,n,r,i){let a=r.createTracker(i),o=a.move(`[^`),s=r.enter(`footnoteDefinition`),c=r.enter(`label`);return o+=a.move(r.safe(r.associationId(e),{before:o,after:`]`})),c(),o+=a.move(`]:`),e.children&&e.children.length>0&&(a.shift(4),o+=a.move((t?`
1045
1045
  `:` `)+r.indentLines(r.containerFlow(e,a.current()),t?ra:na))),s(),o}}function na(e,t,n){return t===0?e:ra(e,t,n)}function ra(e,t,n){return(n?``:` `)+e}const ia=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`];la.peek=ua;function aa(){return{canContainEols:[`delete`],enter:{strikethrough:sa},exit:{strikethrough:ca}}}function oa(){return{unsafe:[{character:`~`,inConstruct:`phrasing`,notInConstruct:ia}],handlers:{delete:la}}}function sa(e){this.enter({type:`delete`,children:[]},e)}function ca(e){this.exit(e)}function la(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ua(){return`~`}function da(e){return e.length}function fa(e,t){let n=t||{},r=(n.align||[]).concat(),i=n.stringLength||da,a=[],o=[],s=[],c=[],l=0,u=-1;for(;++u<e.length;){let t=[],r=[],a=-1;for(e[u].length>l&&(l=e[u].length);++a<e[u].length;){let o=pa(e[u][a]);if(n.alignDelimiters!==!1){let e=i(o);r[a]=e,(c[a]===void 0||e>c[a])&&(c[a]=e)}t.push(o)}o[u]=t,s[u]=r}let d=-1;if(typeof r==`object`&&`length`in r)for(;++d<l;)a[d]=ma(r[d]);else{let e=ma(r);for(;++d<l;)a[d]=e}d=-1;let f=[],p=[];for(;++d<l;){let e=a[d],t=``,r=``;e===99?(t=`:`,r=`:`):e===108?t=`:`:e===114&&(r=`:`);let i=n.alignDelimiters===!1?1:Math.max(1,c[d]-t.length-r.length),o=t+`-`.repeat(i)+r;n.alignDelimiters!==!1&&(i=t.length+i+r.length,i>c[d]&&(c[d]=i),p[d]=i),f[d]=o}o.splice(1,0,f),s.splice(1,0,p),u=-1;let m=[];for(;++u<o.length;){let e=o[u],t=s[u];d=-1;let r=[];for(;++d<l;){let i=e[d]||``,o=``,s=``;if(n.alignDelimiters!==!1){let e=c[d]-(t[d]||0),n=a[d];n===114?o=` `.repeat(e):n===99?e%2?(o=` `.repeat(e/2+.5),s=` `.repeat(e/2-.5)):(o=` `.repeat(e/2),s=o):s=` `.repeat(e)}n.delimiterStart!==!1&&!d&&r.push(`|`),n.padding!==!1&&!(n.alignDelimiters===!1&&i===``)&&(n.delimiterStart!==!1||d)&&r.push(` `),n.alignDelimiters!==!1&&r.push(o),r.push(i),n.alignDelimiters!==!1&&r.push(s),n.padding!==!1&&r.push(` `),(n.delimiterEnd!==!1||d!==l-1)&&r.push(`|`)}m.push(n.delimiterEnd===!1?r.join(``).replace(/ +$/,``):r.join(``))}return m.join(`
@@ -1225,9 +1225,9 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
1225
1225
  `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Ng=y((e=>{var t=Tg(),n=cg(),r=lg(),i=Nh(),a=$(),o=jg(),s=Mg();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Pg=S(y((e=>{var t=Tg(),n=cg(),r=og(),i=lg(),a=wh(),o=$(),s=Ih(),c=Th(),l=Rh(),u=Bh();kg();var d=Ag(),f=jg(),p=Mg(),m=Ng(),h=vh();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync}))(),1);function Fg(e,t){let n=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!=null));return Object.keys(n).length===0?`---
1226
1226
  ---`:`---\n${Pg.stringify(n,{singleQuote:t?.singleQuote??!1,lineWidth:t?.lineWidth??0}).trimEnd()}\n---`}function Ig(e,t,n){return e==null||Object.keys(e).length===0?t:`${Fg(e,n)}\n${t}`}function Lg(e){let t=_h(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){r=e.value;try{n=Pg.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 Rg(e){return 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}`})}var zg=class{type;name;_log;get log(){return this._log??=ln(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}},Bg=class extends zg{globalConfigDir;outputFileName;indexignore;registryWriterCache=new Map;writeEffects=[];cleanEffects=[];constructor(e,t){super(e,Tt.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``,this.indexignore=t?.indexignore}registerWriteEffect(e,t){this.writeEffects.push({name:e,handler:t})}registerCleanEffect(e,t){this.cleanEffects.push({name:e,handler:t})}async executeWriteEffects(e){let t=[];for(let n of this.writeEffects){if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`effect`,name:n.name}),t.push({success:!0,description:`Would execute write effect: ${n.name}`});continue}try{let r=await n.handler(e);if(r.success)this.log.trace({action:`effect`,name:n.name,status:`success`});else{let e=r.error instanceof Error?r.error.message:String(r.error);this.log.error({action:`effect`,name:n.name,status:`failed`,error:e})}t.push(r)}catch(e){let r=e instanceof Error?e.message:String(e);this.log.error({action:`effect`,name:n.name,status:`failed`,error:r}),t.push({success:!1,error:e,description:`Write effect failed: ${n.name}`})}}return t}async executeCleanEffects(e){let t=[];for(let n of this.cleanEffects){if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`effect`,name:n.name}),t.push({success:!0,description:`Would execute clean effect: ${n.name}`});continue}try{let r=await n.handler(e);if(r.success)this.log.trace({action:`effect`,name:n.name,status:`success`});else{let e=r.error instanceof Error?r.error.message:String(r.error);this.log.error({action:`effect`,name:n.name,status:`failed`,error:e})}t.push(r)}catch(e){let r=e instanceof Error?e.message:String(e);this.log.error({action:`effect`,name:n.name,status:`failed`,error:r}),t.push({success:!1,error:e,description:`Clean effect failed: ${n.name}`})}}return t}isRelativePath(e){return e.pathKind===L.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:L.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let r;r=e.pathKind===L.Absolute?e.path:this.isRelativePath(e)?i.resolve(e.basePath,e.path):i.resolve(n.cwd(),e.path);let a=t??this.outputFileName;return a?i.join(r,a):r}createRelativePath(e,t,n){return mt(e,t,n)}createFileRelativePath(e,t){return ht(e,t)}getGlobalConfigDir(){return i.join(this.getHomeDir(),this.globalConfigDir)}getHomeDir(){return s.homedir()}joinPath(...e){return i.join(...e)}resolvePath(...e){return i.resolve(...e)}dirname(e){return i.dirname(e)}basename(e,t){return i.basename(e,t)}writeFileSync(e,t,n=`utf8`){ut(e,t,n)}writeFileSyncBuffer(e,t){ut(e,t)}ensureDirectory(e){at(e)}existsSync(e){return r.existsSync(e)}lstatSync(e){return it(e)}isSymlink(e){return rt(e)}createSymlink(e,t,n=`dir`){st(e,t,n)}removeSymlink(e){ct(e)}async writeDirectorySymlink(e,t,n,r){let a=i.dirname(n),o=mt(i.basename(n),a,()=>i.basename(a));if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`symlink`,target:t,link:n,label:r}),{path:o,success:!0,skipped:!1};try{return this.createSymlink(t,n,`dir`),this.log.trace({action:`write`,type:`symlink`,target:t,link:n,label:r}),{path:o,success:!0}}catch(e){let i=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`symlink`,target:t,link:n,label:r,error:i}),{path:o,success:!1,error:e}}}readdirSync(e,t){return t?.withFileTypes===!0?r.readdirSync(e,{withFileTypes:!0}):r.readdirSync(e)}getIgnoreOutputPath(){if(this.indexignore!=null)return this.indexignore===`.traeignore`?i.join(`.trae`,`.ignore`):this.indexignore}registerProjectIgnoreOutputFiles(e){let t=this.getIgnoreOutputPath();if(t==null)return[];let n=[];for(let r of e){let e=r.dirFromWorkspacePath;if(e==null||r.isPromptSourceProject===!0)continue;let a=i.join(e.path,t);n.push({pathKind:L.Relative,path:a,basePath:e.basePath,getDirectoryName:()=>i.basename(e.path),getAbsolutePath:()=>i.join(e.basePath,a)})}return n}async writeProjectIgnoreFiles(e){let t=this.getIgnoreOutputPath();if(t==null)return[];let{workspace:n,aiAgentIgnoreConfigFiles:a}=e.collectedInputContext,o=[];if(a==null||a.length===0)return o;let s=a.find(e=>e.fileName===this.indexignore);if(s==null)return o;for(let a of n.projects){let n=a.dirFromWorkspacePath;if(n==null||a.isPromptSourceProject===!0)continue;let c=`project:${a.name??`unknown`}/${s.fileName}`,l=i.join(n.path,t),u=i.join(n.basePath,l),d={pathKind:L.Relative,path:l,basePath:n.basePath,getDirectoryName:()=>i.basename(n.path),getAbsolutePath:()=>u};if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`ignoreFile`,path:u,label:c}),o.push({path:d,success:!0,skipped:!1});continue}try{if(t===i.join(`.trae`,`.ignore`)){let e=i.join(n.basePath,n.path,`.trae`);r.mkdirSync(e,{recursive:!0})}r.writeFileSync(u,s.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:u,label:c}),o.push({path:d,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`ignoreFile`,path:u,label:c,error:t}),o.push({path:d,success:!1,error:e})}}return o}async writeFile(e,t,n,r){let a=i.dirname(t),o=mt(i.basename(t),a,()=>i.basename(a));if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`file`,path:t,label:r}),{path:o,success:!0,skipped:!1};try{return ut(t,n),this.log.trace({action:`write`,type:`file`,path:t,label:r}),{path:o,success:!0}}catch(e){let n=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`file`,path:t,label:r,error:n}),{path:o,success:!1,error:e}}}async writePromptFile(e,t,n,r){let i=this.resolveFullPath(t),a=this.toRelativePath(t);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`promptFile`,path:i,label:r}),{path:a,success:!0,skipped:!1};try{return ut(i,n),this.log.trace({action:`write`,type:`promptFile`,path:i,label:r}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`promptFile`,path:i,label:r,error:t}),{path:a,success:!1,error:e}}}buildMarkdownContent(e,t){return Ig(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Ig(t,e):n!=null&&n.length>0?`---\n${n}\n---\n${e}`:e}extractGlobalMemoryContent(e){return e.collectedInputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
1227
1227
 
1228
- `,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,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.getFastCommandSeriesOptions(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)}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i}),await this.executeWriteEffects(e)}async onCleanComplete(e){await this.executeCleanEffects(e)}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)}};const Vg=`AGENTS.md`;var Hg=class extends Bg{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Vg})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Vg)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Vg));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}},Ug=class extends zg{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,Tt.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,shadowProjectDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:u,userConfigOptions:e.userConfigOptions,workspaceDir:r,shadowProjectDir: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{let n=t.error instanceof Error?t.error.message:String(t.error);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:n})}n.push(t)}catch(t){let r=t instanceof Error?t.message:String(t);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:r}),n.push({success:!1,error:t,description:`Input effect failed: ${e.name}`})}}return n}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,n=this.resolvePath(t,``),r=e.shadowSourceProject.name;return{workspaceDir:n,shadowProjectDir:i.join(n,r)}}resolvePath(e,t){let n=e;return n.startsWith(Jt.USER_HOME)&&(n=n.replace(Jt.USER_HOME,s.homedir())),n.includes(Jt.WORKSPACE)&&(n=n.replace(Jt.WORKSPACE,t)),i.normalize(n)}resolveShadowPath(e,t){return i.join(t,e)}readAndParseMarkdown(e,t){return Lg(t.readFileSync(e,`utf8`))}};const Wg=[`.qoderignore`,`.cursorignore`,`.kiroignore`,`.warpindexignore`,`.aiignore`,`.codeignore`,`.traeignore`];var Gg=class extends Ug{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Wg){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const Kg=`.agent`,qg=`antigravity`,Jg=`skills`,Yg=`workflows`,Xg=`mcp_config.json`,Zg=[Jg,Yg];var Qg=class extends Bg{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Kg,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=i.join(this.getAntigravityDir(),Xg),n=JSON.stringify({mcpServers:{}},null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:t}),{success:!0,description:`Would reset mcp_config.json`};let r=await this.writeFile(e,t,n,`mcpConfigCleanup`);return r.success?{success:!0,description:`Reset mcp_config.json`}:{success:!1,description:`Failed`,error:r.error??Error(`Cleanup failed`)}})}getAntigravityDir(){return i.join(s.homedir(),`.gemini`,qg)}async registerProjectOutputDirs(e){let{projects:t}=e.collectedInputContext.workspace,n=[];for(let e of t)if(e.dirFromWorkspacePath!=null)for(let t of Zg)n.push(this.createRelativePath(i.join(e.dirFromWorkspacePath.path,Kg,t),e.dirFromWorkspacePath.basePath,()=>t));return n}async registerProjectOutputFiles(e){let{skills:t,fastCommands:n}=e.collectedInputContext,r=this.getAntigravityDir(),a=[];if(t!=null)for(let e of t){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),n=i.join(r,Jg,t);if(a.push(this.createRelativePath(`SKILL.md`,n,()=>t)),e.childDocs!=null)for(let r of e.childDocs)a.push(this.createRelativePath(r.dir.path.replace(/\.mdx$/,`.md`),n,()=>t));if(e.resources!=null)for(let r of e.resources)a.push(this.createRelativePath(r.relativePath,n,()=>t))}if(t?.some(e=>e.mcpConfig!=null)&&a.push(this.createRelativePath(Xg,r,()=>qg)),n==null)return a;let o=this.getTransformOptionsFromContext(e),s=i.join(r,Yg);for(let e of n)a.push(this.createRelativePath(this.transformFastCommandName(e,o),s,()=>Yg));return a}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext;return(t?.length??0)>0||(n?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],a=this.getAntigravityDir();if(t!=null){let n=i.join(a,Yg);for(let i of t)r.push(await this.writeFastCommand(e,n,i))}if(n!=null){let t=i.join(a,Jg);for(let i of n)r.push(...await this.writeSkill(e,t,i));let o=await this.writeGlobalMcpConfig(e,a,n);o!=null&&r.push(o)}return this.log.info({action:`write`,message:`Synced ${r.length} files`,globalDir:a}),{files:r,dirs:[]}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n)if(e.mcpConfig!=null)for(let[t,n]of Object.entries(e.mcpConfig.mcpServers))r[t]=this.transformMcpConfig(n);if(Object.keys(r).length===0)return null;let a=i.join(t,Xg),o=JSON.stringify({mcpServers:r},null,2);return this.writeFile(e,a,o,`globalMcpConfig`)}transformMcpConfig(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.serverUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,a),s=typeof n.yamlFrontMatter?.description==`string`?{description:n.yamlFrontMatter.description}:{},c;if(n.rawMdxContent!=null){let e=n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``);c=this.buildMarkdownContentWithRaw(e,s,n.rawFrontMatter)}else c=this.buildMarkdownContentWithRaw(n.content,s,n.rawFrontMatter);return this.writeFile(e,o,c,`fastCommand`)}async writeSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,a),s=i.join(o,`SKILL.md`),c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(r.push(await this.writeFile(e,s,c,`skill`)),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`);r.push(await this.writeFile(e,i.join(o,n),t.content,`skillRefDoc`))}if(n.resources!=null)for(let t of n.resources)r.push(await this.writeFile(e,i.join(o,t.relativePath),t.content,`skillResource`));return r}},$g=class extends Error{constructor(e,t,n){super(e),this.expression=t,this.filePath=n,this.name=`ScopeError`}},e_=class extends $g{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`}},t_=class extends $g{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`}},n_=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`}},r_=Object.defineProperty,i_=(e,t)=>{let n={};for(var r in e)r_(n,r,{get:e[r],enumerable:!0});return t||r_(n,Symbol.toStringTag,{value:`Module`}),n};const a_=new Map;function o_(e,t){a_.set(e,t)}function s_(){return new Map(a_)}function c_(e){return a_.has(e)}function l_(e,t,n){let r=e.trim();return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?u_(r,t,n?.filePath):d_(r,t,n?.filePath)}function u_(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new t_(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 e_(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 e_(i,e,n);a=o[i]}return f_(a)}function d_(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return f_(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 t_(t[1],e,n)}let i=n==null?``:` (file: ${n})`;throw Error(`Failed to evaluate expression: "${e}"${i}\nCause: ${r}`)}}function f_(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 p_(e,t){return e===null?!1:t.components.has(e)||c_(e)}async function m_(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function h_(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 m_(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 g_(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return y_(e,t);case`a`:return b_(e,t);case`strong`:case`b`:return x_(e,t);case`em`:case`i`:return S_(e,t);case`img`:return C_(e,t);case`blockquote`:return w_(e,t);default:return null}}function __(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`?l_(r.value.value,n.scope):r.value===null?``:null}function v_(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=l_(r.value,t.scope):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=v_(r,t));return n}function y_(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=__(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=v_(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function b_(e,t){let n=__(e,`href`,t);if(n==null||n===``)return null;let r=v_(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:__(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function x_(e,t){let n={type:`strong`,children:[{type:`text`,value:v_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function S_(e,t){let n={type:`emphasis`,children:[{type:`text`,value:v_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function C_(e,t){let n=__(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:__(e,`alt`,t)??``,title:__(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function w_(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:v_(e,t)}]}]}]}function T_(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function E_(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`?D_(i.expression,t,n):[]}async function D_(e,t,n){return e.type===`JSXElement`?N_(e,t,n):e.type===`JSXFragment`?P_(e,t,n):e.type===`LogicalExpression`?O_(e,t,n):e.type===`ConditionalExpression`?k_(e,t,n):e.type===`SequenceExpression`?A_(e,t,n):e.type===`ArrayExpression`?j_(e,t,n):U_(e,t)}async function O_(e,t,n){let r=await M_(e.left,t,n);return e.operator===`&&`?V_(r)?D_(e.right,t,n):[]:e.operator===`||`?V_(r)?B_(e.left)?D_(e.left,t,n):H_(r):D_(e.right,t,n):e.operator===`??`?r==null?D_(e.right,t,n):B_(e.left)?D_(e.left,t,n):H_(r):[]}async function k_(e,t,n){return V_(await M_(e.test,t,n))?D_(e.consequent,t,n):D_(e.alternate,t,n)}async function A_(e,t,n){let r=[];for(let i of e.expressions){let e=await D_(i,t,n);r.push(...e)}return r}async function j_(e,t,n){let r=[];for(let i of e.elements)if(i!=null)if(i.type===`SpreadElement`){let e=await D_(i.argument,t,n);r.push(...e)}else{let e=await D_(i,t,n);r.push(...e)}return r}async function M_(e,t,n){if(B_(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 M_(e.argument,t,n);return e.operator===`!`?!V_(r):e.operator===`-`?-r:e.operator===`+`?+r:e.operator===`typeof`?typeof r:void 0}if(e.type===`BinaryExpression`){let r=await M_(e.left,t,n),i=await M_(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 M_(e.left,t,n);return e.operator===`&&`?V_(r)?M_(e.right,t,n):r:e.operator===`||`?V_(r)?r:M_(e.right,t,n):e.operator===`??`?r??M_(e.right,t,n):void 0}if(e.type===`MemberExpression`){let r=await M_(e.object,t,n);if(r==null)return;if(e.computed)return r[await M_(e.property,t,n)];let{name:i}=e.property;return r[i]}if(e.type===`ConditionalExpression`)return V_(await M_(e.test,t,n))?M_(e.consequent,t,n):M_(e.alternate,t,n);let r=z_(e);if(r!==``)try{let e=l_(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 N_(e,t,n){let r=I_(e,t);if(r.name!=null&&p_(r.name,t)){let{processAst:e}=await Promise.resolve().then(()=>W_);return h_(r,t,e)}return g_(r,t)??(r.children.length>0?n(r.children,t):[])}async function P_(e,t,n){let r=[];for(let i of e.children){let e=await F_(i,t,n);r.push(...e)}return r}async function F_(e,t,n){if(e.type===`JSXElement`)return N_(e,t,n);if(e.type===`JSXFragment`)return P_(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`?[]:D_(e.expression,t,n):e.type===`JSXSpreadChild`?D_(e.expression,t,n):[]}function I_(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=L_(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:z_(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${z_(e.argument)}`});let a=[];for(let n of e.children){let e=R_(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function L_(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${L_(e.object)}.${e.property.name}`}function R_(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[I_(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=R_(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:z_(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${z_(e.expression)}`}]}]:null}function z_(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=z_(e.object);return e.computed?`${t}[${z_(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${z_(e.callee)}(${e.arguments.map(e=>z_(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=z_(e.left),n=z_(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=z_(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${z_(e.test)} ? ${z_(e.consequent)} : ${z_(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>z_(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:z_(e.key)}: ${z_(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+=`\${${z_(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${z_(e.argument)}`:``}function B_(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function V_(e){return!!e}function H_(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 U_(e,t){let n=z_(e);if(n===``)return[];try{return H_(l_(n,t.scope))}catch{return[]}}var W_=i_({processAst:()=>K_});function G_(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function K_(e,t){return q_(e,t)}async function q_(e,t){let n=[];for(let r of e.children){let e=await J_(r,t);n.push(...e)}return{type:`root`,children:n}}async function J_(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(T_(r))return E_(n,t,async(e,t)=>(await K_({type:`root`,children:e},t)).children);let a=l_(n.value,t.scope);return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return Y_(e,t);if(e.type===`link`){let n=e,r=(await X_(n.children,t)).map(e=>e.type===`text`?{...e,value:G_(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await X_(e.children,t);return[{...e,children:n}]}async function Y_(e,t){return e.name!=null&&p_(e.name,t)?h_(e,t,K_):g_(e,t)??[]}async function X_(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(T_(i)){let r=await E_(e,t,async(e,t)=>(await K_({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=l_(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:l_(e.value,t.scope)};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&p_(e.name,t)){let r=await h_(e,t,K_);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=g_(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 X_(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:G_(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function Z_(e){let t=this;t.compiler=n;function n(n){return Ko(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function Q_(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=$_(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 $_(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=ev(i,e);if(o!=null)try{let e=tv(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=ev(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=tv(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 ev(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===`
1228
+ `,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`-`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,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.getFastCommandSeriesOptions(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)}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i}),await this.executeWriteEffects(e)}async onCleanComplete(e){await this.executeCleanEffects(e)}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`}};const Vg=`AGENTS.md`;var Hg=class extends Bg{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Vg})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Vg)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Vg));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}},Ug=class extends zg{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,Tt.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,shadowProjectDir:i}=this.resolveBasePaths(e.userConfigOptions),a={logger:this.log,fs:e.fs,path:e.path,glob:e.glob,spawn:u,userConfigOptions:e.userConfigOptions,workspaceDir:r,shadowProjectDir: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{let n=t.error instanceof Error?t.error.message:String(t.error);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:n})}n.push(t)}catch(t){let r=t instanceof Error?t.message:String(t);this.log.error({action:`inputEffect`,name:e.name,status:`failed`,error:r}),n.push({success:!1,error:t,description:`Input effect failed: ${e.name}`})}}return n}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,n=this.resolvePath(t,``),r=e.shadowSourceProject.name;return{workspaceDir:n,shadowProjectDir:i.join(n,r)}}resolvePath(e,t){let n=e;return n.startsWith(Jt.USER_HOME)&&(n=n.replace(Jt.USER_HOME,s.homedir())),n.includes(Jt.WORKSPACE)&&(n=n.replace(Jt.WORKSPACE,t)),i.normalize(n)}resolveShadowPath(e,t){return i.join(t,e)}readAndParseMarkdown(e,t){return Lg(t.readFileSync(e,`utf8`))}};const Wg=[`.qoderignore`,`.cursorignore`,`.kiroignore`,`.warpindexignore`,`.aiignore`,`.codeignore`,`.traeignore`];var Gg=class extends Ug{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Wg){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const Kg=`.agent`,qg=`antigravity`,Jg=`skills`,Yg=`workflows`,Xg=`mcp_config.json`,Zg=[Jg,Yg];var Qg=class extends Bg{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Kg,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=i.join(this.getAntigravityDir(),Xg),n=JSON.stringify({mcpServers:{}},null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:t}),{success:!0,description:`Would reset mcp_config.json`};let r=await this.writeFile(e,t,n,`mcpConfigCleanup`);return r.success?{success:!0,description:`Reset mcp_config.json`}:{success:!1,description:`Failed`,error:r.error??Error(`Cleanup failed`)}})}getAntigravityDir(){return i.join(s.homedir(),`.gemini`,qg)}async registerProjectOutputDirs(e){let{projects:t}=e.collectedInputContext.workspace,n=[];for(let e of t)if(e.dirFromWorkspacePath!=null)for(let t of Zg)n.push(this.createRelativePath(i.join(e.dirFromWorkspacePath.path,Kg,t),e.dirFromWorkspacePath.basePath,()=>t));return n}async registerProjectOutputFiles(e){let{skills:t,fastCommands:n}=e.collectedInputContext,r=this.getAntigravityDir(),a=[];if(t!=null)for(let e of t){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),n=i.join(r,Jg,t);if(a.push(this.createRelativePath(`SKILL.md`,n,()=>t)),e.childDocs!=null)for(let r of e.childDocs)a.push(this.createRelativePath(r.dir.path.replace(/\.mdx$/,`.md`),n,()=>t));if(e.resources!=null)for(let r of e.resources)a.push(this.createRelativePath(r.relativePath,n,()=>t))}if(t?.some(e=>e.mcpConfig!=null)&&a.push(this.createRelativePath(Xg,r,()=>qg)),n==null)return a;let o=this.getTransformOptionsFromContext(e),s=i.join(r,Yg);for(let e of n)a.push(this.createRelativePath(this.transformFastCommandName(e,o),s,()=>Yg));return a}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext;return(t?.length??0)>0||(n?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],a=this.getAntigravityDir();if(t!=null){let n=i.join(a,Yg);for(let i of t)r.push(await this.writeFastCommand(e,n,i))}if(n!=null){let t=i.join(a,Jg);for(let i of n)r.push(...await this.writeSkill(e,t,i));let o=await this.writeGlobalMcpConfig(e,a,n);o!=null&&r.push(o)}return this.log.info({action:`write`,message:`Synced ${r.length} files`,globalDir:a}),{files:r,dirs:[]}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n)if(e.mcpConfig!=null)for(let[t,n]of Object.entries(e.mcpConfig.mcpServers))r[t]=this.transformMcpConfig(n);if(Object.keys(r).length===0)return null;let a=i.join(t,Xg),o=JSON.stringify({mcpServers:r},null,2);return this.writeFile(e,a,o,`globalMcpConfig`)}transformMcpConfig(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.serverUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,a),s=typeof n.yamlFrontMatter?.description==`string`?{description:n.yamlFrontMatter.description}:{},c;if(n.rawMdxContent!=null){let e=n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``);c=this.buildMarkdownContentWithRaw(e,s,n.rawFrontMatter)}else c=this.buildMarkdownContentWithRaw(n.content,s,n.rawFrontMatter);return this.writeFile(e,o,c,`fastCommand`)}async writeSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,a),s=i.join(o,`SKILL.md`),c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(r.push(await this.writeFile(e,s,c,`skill`)),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`);r.push(await this.writeFile(e,i.join(o,n),t.content,`skillRefDoc`))}if(n.resources!=null)for(let t of n.resources)r.push(await this.writeFile(e,i.join(o,t.relativePath),t.content,`skillResource`));return r}},$g=class extends Error{constructor(e,t,n){super(e),this.expression=t,this.filePath=n,this.name=`ScopeError`}},e_=class extends $g{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`}},t_=class extends $g{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`}},n_=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`}},r_=Object.defineProperty,i_=(e,t)=>{let n={};for(var r in e)r_(n,r,{get:e[r],enumerable:!0});return t||r_(n,Symbol.toStringTag,{value:`Module`}),n};const a_=new Map;function o_(e,t){a_.set(e,t)}function s_(){return new Map(a_)}function c_(e){return a_.has(e)}function l_(e,t,n){let r=e.trim();return r===``?``:/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r)?u_(r,t,n?.filePath):d_(r,t,n?.filePath)}function u_(e,t,n){let r=e.split(`.`),i=r[0];if(i==null||!(i in t))throw new t_(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 e_(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 e_(i,e,n);a=o[i]}return f_(a)}function d_(e,t,n){let r=Object.keys(t),i=r.map(e=>t[e]);try{return f_(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 t_(t[1],e,n)}let i=n==null?``:` (file: ${n})`;throw Error(`Failed to evaluate expression: "${e}"${i}\nCause: ${r}`)}}function f_(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 p_(e,t){return e===null?!1:t.components.has(e)||c_(e)}async function m_(e){return async(t,n)=>(await e({type:`root`,children:t},n)).children}async function h_(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 m_(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 g_(e,t){let n=e.name?.toLowerCase();if(n==null)return null;switch(n){case`pre`:return y_(e,t);case`a`:return b_(e,t);case`strong`:case`b`:return x_(e,t);case`em`:case`i`:return S_(e,t);case`img`:return C_(e,t);case`blockquote`:return w_(e,t);default:return null}}function __(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`?l_(r.value.value,n.scope):r.value===null?``:null}function v_(e,t){let n=``;for(let r of e.children)r.type===`text`?n+=r.value:r.type===`mdxTextExpression`?n+=l_(r.value,t.scope):(r.type===`mdxJsxFlowElement`||r.type===`mdxJsxTextElement`)&&(n+=v_(r,t));return n}function y_(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=__(n,`className`,t)??``,i=/language-(\w+)/.exec(r)?.[1],a=v_(n,t);return[{type:`code`,lang:i??null,value:a.trim()}]}function b_(e,t){let n=__(e,`href`,t);if(n==null||n===``)return null;let r=v_(e,t);return[{type:`paragraph`,children:[{type:`link`,url:n,title:__(e,`title`,t)??null,children:[{type:`text`,value:r}]}]}]}function x_(e,t){let n={type:`strong`,children:[{type:`text`,value:v_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function S_(e,t){let n={type:`emphasis`,children:[{type:`text`,value:v_(e,t)}]};return e.type,[{type:`paragraph`,children:[n]}]}function C_(e,t){let n=__(e,`src`,t);if(n==null||n===``)return null;let r={type:`image`,url:n,alt:__(e,`alt`,t)??``,title:__(e,`title`,t)??null};return e.type,[{type:`paragraph`,children:[r]}]}function w_(e,t){return[{type:`blockquote`,children:[{type:`paragraph`,children:[{type:`text`,value:v_(e,t)}]}]}]}function T_(e){return e==null?!1:JSON.stringify(e).includes(`"JSX`)}async function E_(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`?D_(i.expression,t,n):[]}async function D_(e,t,n){return e.type===`JSXElement`?N_(e,t,n):e.type===`JSXFragment`?P_(e,t,n):e.type===`LogicalExpression`?O_(e,t,n):e.type===`ConditionalExpression`?k_(e,t,n):e.type===`SequenceExpression`?A_(e,t,n):e.type===`ArrayExpression`?j_(e,t,n):U_(e,t)}async function O_(e,t,n){let r=await M_(e.left,t,n);return e.operator===`&&`?V_(r)?D_(e.right,t,n):[]:e.operator===`||`?V_(r)?B_(e.left)?D_(e.left,t,n):H_(r):D_(e.right,t,n):e.operator===`??`?r==null?D_(e.right,t,n):B_(e.left)?D_(e.left,t,n):H_(r):[]}async function k_(e,t,n){return V_(await M_(e.test,t,n))?D_(e.consequent,t,n):D_(e.alternate,t,n)}async function A_(e,t,n){let r=[];for(let i of e.expressions){let e=await D_(i,t,n);r.push(...e)}return r}async function j_(e,t,n){let r=[];for(let i of e.elements)if(i!=null)if(i.type===`SpreadElement`){let e=await D_(i.argument,t,n);r.push(...e)}else{let e=await D_(i,t,n);r.push(...e)}return r}async function M_(e,t,n){if(B_(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 M_(e.argument,t,n);return e.operator===`!`?!V_(r):e.operator===`-`?-r:e.operator===`+`?+r:e.operator===`typeof`?typeof r:void 0}if(e.type===`BinaryExpression`){let r=await M_(e.left,t,n),i=await M_(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 M_(e.left,t,n);return e.operator===`&&`?V_(r)?M_(e.right,t,n):r:e.operator===`||`?V_(r)?r:M_(e.right,t,n):e.operator===`??`?r??M_(e.right,t,n):void 0}if(e.type===`MemberExpression`){let r=await M_(e.object,t,n);if(r==null)return;if(e.computed)return r[await M_(e.property,t,n)];let{name:i}=e.property;return r[i]}if(e.type===`ConditionalExpression`)return V_(await M_(e.test,t,n))?M_(e.consequent,t,n):M_(e.alternate,t,n);let r=z_(e);if(r!==``)try{let e=l_(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 N_(e,t,n){let r=I_(e,t);if(r.name!=null&&p_(r.name,t)){let{processAst:e}=await Promise.resolve().then(()=>W_);return h_(r,t,e)}return g_(r,t)??(r.children.length>0?n(r.children,t):[])}async function P_(e,t,n){let r=[];for(let i of e.children){let e=await F_(i,t,n);r.push(...e)}return r}async function F_(e,t,n){if(e.type===`JSXElement`)return N_(e,t,n);if(e.type===`JSXFragment`)return P_(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`?[]:D_(e.expression,t,n):e.type===`JSXSpreadChild`?D_(e.expression,t,n):[]}function I_(e,t){let n=e.openingElement,r=null;n.name.type===`JSXIdentifier`?{name:r}=n.name:n.name.type===`JSXMemberExpression`?r=L_(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:z_(e.value.expression)}),i.push({type:`mdxJsxAttribute`,name:t,value:n})}else e.type===`JSXSpreadAttribute`&&i.push({type:`mdxJsxExpressionAttribute`,value:`...${z_(e.argument)}`});let a=[];for(let n of e.children){let e=R_(n,t);e!=null&&a.push(...e)}return{type:`mdxJsxFlowElement`,name:r,attributes:i,children:a}}function L_(e){return e.object.type===`JSXIdentifier`?`${e.object.name}.${e.property.name}`:`${L_(e.object)}.${e.property.name}`}function R_(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[I_(e,t)];if(e.type===`JSXFragment`){let n=[];for(let r of e.children){let e=R_(r,t);e!=null&&n.push(...e)}return n}return e.type===`JSXExpressionContainer`?e.expression.type===`JSXEmptyExpression`?null:[{type:`paragraph`,children:[{type:`text`,value:z_(e.expression)}]}]:e.type===`JSXSpreadChild`?[{type:`paragraph`,children:[{type:`text`,value:`...${z_(e.expression)}`}]}]:null}function z_(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=z_(e.object);return e.computed?`${t}[${z_(e.property)}]`:`${t}.${e.property.name}`}if(e.type===`CallExpression`)return`${z_(e.callee)}(${e.arguments.map(e=>z_(e)).join(`, `)})`;if(e.type===`BinaryExpression`||e.type===`LogicalExpression`){let t=z_(e.left),n=z_(e.right);return`(${t} ${e.operator} ${n})`}if(e.type===`UnaryExpression`){let t=z_(e.argument);return`${e.operator}${t}`}if(e.type===`ConditionalExpression`)return`(${z_(e.test)} ? ${z_(e.consequent)} : ${z_(e.alternate)})`;if(e.type===`ArrayExpression`)return`[${e.elements.filter(e=>e!=null&&e.type!==`SpreadElement`).map(e=>z_(e)).join(`, `)}]`;if(e.type===`ObjectExpression`)return`{${e.properties.filter(e=>e.type===`Property`).map(e=>`${e.key.type===`Identifier`?e.key.name:z_(e.key)}: ${z_(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+=`\${${z_(e.expressions[n])}}`);return t+="`",t}return e.type===`SpreadElement`?`...${z_(e.argument)}`:``}function B_(e){return e.type===`JSXElement`||e.type===`JSXFragment`}function V_(e){return!!e}function H_(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 U_(e,t){let n=z_(e);if(n===``)return[];try{return H_(l_(n,t.scope))}catch{return[]}}var W_=i_({processAst:()=>K_});function G_(e){if(!(e.includes(`/`)&&/\.\w+$/.test(e)))return e;let t=e.lastIndexOf(`/`);return e.slice(t+1)}async function K_(e,t){return q_(e,t)}async function q_(e,t){let n=[];for(let r of e.children){let e=await J_(r,t);n.push(...e)}return{type:`root`,children:n}}async function J_(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(T_(r))return E_(n,t,async(e,t)=>(await K_({type:`root`,children:e},t)).children);let a=l_(n.value,t.scope);return a===``?[]:[{type:`paragraph`,children:[{type:`text`,value:a}]}]}if(e.type===`mdxJsxFlowElement`)return Y_(e,t);if(e.type===`link`){let n=e,r=(await X_(n.children,t)).map(e=>e.type===`text`?{...e,value:G_(e.value)}:e);return[{...n,children:r}]}if(!(`children`in e&&Array.isArray(e.children)))return[e];let n=await X_(e.children,t);return[{...e,children:n}]}async function Y_(e,t){return e.name!=null&&p_(e.name,t)?h_(e,t,K_):g_(e,t)??[]}async function X_(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(T_(i)){let r=await E_(e,t,async(e,t)=>(await K_({type:`root`,children:e},t)).children);for(let e of r)n.push(e);continue}let o=l_(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:l_(e.value,t.scope)};n.push(a);continue}if(r.type===`mdxJsxTextElement`){let e=r;if(e.name!=null&&p_(e.name,t)){let r=await h_(e,t,K_);for(let e of r)e.type===`paragraph`&&`children`in e?n.push(...e.children):n.push(e);continue}let i=g_(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 X_(r.children,t);if(r.type===`link`){let t=e.map(e=>e.type===`text`?{...e,value:G_(e.value)}:e);n.push({...r,children:t});continue}n.push({...r,children:e});continue}n.push(r)}return n}function Z_(e){let t=this;t.compiler=n;function n(n){return Ko(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}function Q_(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=$_(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 $_(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=ev(i,e);if(o!=null)try{let e=tv(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=ev(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=tv(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 ev(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===`
1229
1229
  `){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 tv(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 nv(r.slice(1,-1),`"`);if(r.startsWith(`'`)&&r.endsWith(`'`))return nv(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 nv(e,"`")}if(r.startsWith(`[`)&&r.endsWith(`]`))return iv(r,t,n);if(r.startsWith(`{`)&&r.endsWith(`}`))return av(r,t,n);if(/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r))return rv(r,t,n);let i=n==null?``:` in file "${n}"`;throw Error(`Expression "${r}" cannot be statically evaluated${i}`)}function nv(e,t){return e.replaceAll(`\\n`,`
1230
- `).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function rv(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 iv(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=ov(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return sv(r).map(e=>tv(e.trim(),t,n))}function av(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=ov(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=cv(r);for(let e of a){let r=lv(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]=tv(o,t,n)}return i}function ov(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 sv(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 cv(e){return sv(e)}function lv(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 uv(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=l_(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function dv(e,t,n){return!uv(e,t)||e.children.length===0?[]:n(e.children,t)}async function fv(e,t){if(!uv(e,t)||e.children.length===0)return[];let n=pv(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function pv(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=l_(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=pv(r.children,t));return n}function mv(){o_(`Md`,dv),o_(`Md.Line`,fv)}mv();function hv(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 gv(e,t){let n=_h(e),r=hv(t?.globalScope,t?.scope),i=s_(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Pg.parse(e.value)}catch{}a=Q_(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 K_(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=yu().use(ui,[`yaml`]).use($l).use(Z_,{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}var _v=class extends Bg{commandsSubDir;agentsSubDir;skillsSubDir;supportsFastCommands;supportsSubAgents;supportsSkills;toolPreset;constructor(e,t){super(e,t),this.commandsSubDir=t.commandsSubDir??`commands`,this.agentsSubDir=t.agentsSubDir??`agents`,this.skillsSubDir=t.skillsSubDir??`skills`,this.supportsFastCommands=t.supportsFastCommands??!0,this.supportsSubAgents=t.supportsSubAgents??!0,this.supportsSkills=t.supportsSkills??!0,t.toolPreset!==void 0&&(this.toolPreset=t.toolPreset)}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=[];this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir);for(let e of r)n.push(this.createRelativePath(e,t,()=>e));return n}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=[];if(this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir),r.length===0)return[];for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of r){let r=i.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push(this.createRelativePath(r,e.dirFromWorkspacePath.basePath,()=>n))}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,this.outputFileName)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,this.outputFileName));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir(),r=[this.createRelativePath(this.outputFileName,n,()=>this.globalConfigDir)],{fastCommands:a,subAgents:o,skills:s}=e.collectedInputContext,c={includeSeriesPrefix:!0};if(this.supportsFastCommands&&a!=null)for(let e of a){let t=this.transformFastCommandName(e,c);r.push(this.createRelativePath(i.join(this.commandsSubDir,t),n,()=>this.commandsSubDir))}if(this.supportsSubAgents&&o!=null)for(let e of o){let t=e.dir.path.replace(/\.mdx$/,`.md`);r.push(this.createRelativePath(i.join(this.agentsSubDir,t),n,()=>this.agentsSubDir))}if(this.supportsSkills&&s!=null)for(let e of s){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),a=i.join(this.skillsSubDir,t);if(r.push(this.createRelativePath(i.join(a,`SKILL.md`),n,()=>t)),e.childDocs!=null)for(let o of e.childDocs){let e=o.dir.path.replace(/\.mdx$/,`.md`),s=i.join(a,e);r.push(this.createRelativePath(s,n,()=>t))}if(e.resources!=null)for(let o of e.resources){let e=i.join(a,o.relativePath);r.push(this.createRelativePath(e,n,()=>t))}}return r}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=this.supportsFastCommands&&(r?.length??0)>0,l=this.supportsSubAgents&&(i?.length??0)>0,u=this.supportsSkills&&(a?.length??0)>0;return o||s||c||l||u?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],r=[];if([{enabled:!0,data:t},{enabled:this.supportsFastCommands,data:e.collectedInputContext.fastCommands},{enabled:this.supportsSubAgents,data:e.collectedInputContext.subAgents},{enabled:this.supportsSkills,data:e.collectedInputContext.skills}].every(e=>!e.enabled||e.data==null))return{files:n,dirs:r};let{fastCommands:a,subAgents:o,skills:s}=e.collectedInputContext,c=this.getGlobalConfigDir();if(t!=null){let r=i.join(c,this.outputFileName),a=this.createRelativePath(this.outputFileName,c,()=>this.globalConfigDir);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:a,success:!0,skipped:!1});else try{ut(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),n.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),n.push({path:a,success:!1,error:e})}}if(this.supportsFastCommands&&a!=null)for(let t of a){let r=await this.writeFastCommand(e,c,t);n.push(...r)}if(this.supportsSubAgents&&o!=null)for(let t of o){let r=await this.writeSubAgent(e,c,t);n.push(...r)}if(this.supportsSkills&&s!=null)for(let t of s){let r=await this.writeSkill(e,c,t);n.push(...r)}return{files:n,dirs:r}}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,this.commandsSubDir),s=i.join(o,a),c=n.content,l=n.yamlFrontMatter,u=!1;if(n.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling fast command with tool preset`,{file:n.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});try{let e=new fr({toolPreset:this.toolPreset}).collect(),t=await gv(n.rawMdxContent,{globalScope:e,extractMetadata:!0,basePath:n.dir.basePath});c=t.content,l=t.metadata.fields,u=!0}catch(e){this.log.warn(`failed to recompile fast command, using default`,{file:n.dir.getAbsolutePath(),error:e instanceof Error?e.message:String(e)})}}let d=u?this.buildMarkdownContent(c,l):this.buildMarkdownContentWithRaw(c,l,n.rawFrontMatter);return[await this.writeFile(e,s,d,`fastCommand`)]}async writeSubAgent(e,t,n){let r=n.dir.path.replace(/\.mdx$/,`.md`),a=i.join(t,this.agentsSubDir),o=i.join(a,r),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return[await this.writeFile(e,o,s,`subAgent`)]}async writeSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,this.skillsSubDir,a),s=i.join(o,`SKILL.md`),c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter),l=await this.writeFile(e,s,c,`skill`);if(r.push(l),n.childDocs!=null)for(let i of n.childDocs){let n=await this.writeSkillReferenceDocument(e,o,a,i,t);r.push(...n)}if(n.resources!=null)for(let i of n.resources){let n=await this.writeSkillResource(e,o,a,i,t);r.push(...n)}return r}async writeSkillReferenceDocument(e,t,n,r,a){let o=r.dir.path.replace(/\.mdx$/,`.md`),s=i.join(t,o);return[await this.writeFile(e,s,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,a){let o=i.join(t,r.relativePath);return[await this.writeFile(e,o,r.content,`skillResource`)]}};const vv=`rules`;var yv=class extends _v{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.md`}buildRuleContent(e){return e.globs.length===0?e.content:this.buildMarkdownContent(e.content,{paths:[...e.globs]})}async registerGlobalOutputDirs(e){let t=await super.registerGlobalOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);return n!=null&&n.length>0&&t.push(this.createRelativePath(vv,this.getGlobalConfigDir(),()=>vv)),t}async registerGlobalOutputFiles(e){let t=await super.registerGlobalOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(n==null||n.length===0)return t;let r=i.join(this.getGlobalConfigDir(),vv);for(let e of n)t.push(this.createRelativePath(this.buildRuleFileName(e),r,()=>vv));return t}async registerProjectOutputDirs(e){let t=await super.registerProjectOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;for(let n of e.collectedInputContext.workspace.projects){if(n.dirFromWorkspacePath==null)continue;let e=i.join(n.dirFromWorkspacePath.path,this.globalConfigDir,vv);t.push(this.createRelativePath(e,n.dirFromWorkspacePath.basePath,()=>vv))}return t}async registerProjectOutputFiles(e){let t=await super.registerProjectOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;for(let r of e.collectedInputContext.workspace.projects)if(r.dirFromWorkspacePath!=null)for(let e of n){let n=i.join(r.dirFromWorkspacePath.path,this.globalConfigDir,vv,this.buildRuleFileName(e));t.push(this.createRelativePath(n,r.dirFromWorkspacePath.basePath,()=>vv))}return t}async canWrite(e){return(e.collectedInputContext.rules?.length??0)>0?!0:super.canWrite(e)}async writeGlobalOutputs(e){let t=await super.writeGlobalOutputs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(n==null||n.length===0)return t;let r=i.join(this.getGlobalConfigDir(),vv),a=[];for(let t of n)a.push(await this.writeFile(e,i.join(r,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`));return{files:[...t.files,...a],dirs:t.dirs}}async writeProjectOutputs(e){let t=await super.writeProjectOutputs(e),n=e.collectedInputContext.rules?.filter(e=>e.scope===`project`);if(n==null||n.length===0)return t;let r=[];for(let t of e.collectedInputContext.workspace.projects){if(t.dirFromWorkspacePath==null)continue;let a=i.join(t.dirFromWorkspacePath.basePath,t.dirFromWorkspacePath.path,this.globalConfigDir,vv);for(let t of n)r.push(await this.writeFile(e,i.join(a,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`))}return{files:[...t.files,...r],dirs:t.dirs}}};const bv=`AGENTS.md`,xv=`.codex`,Sv=`prompts`,Cv=`skills`;var wv=class extends Bg{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:xv,outputFileName:bv,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[this.createRelativePath(Sv,t,()=>Sv)],{skills:r}=e.collectedInputContext;if(r!=null&&r.length>0)for(let e of r){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName();n.push(this.createRelativePath(i.join(Cv,r),t,()=>r))}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[this.createRelativePath(bv,e,()=>xv)]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext;return t!=null||(n?.length??0)>0||(r?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,a=[],o=this.getGlobalConfigDir();if(t!=null){let n=i.join(o,bv),r=await this.writeFile(e,n,t.content,`globalMemory`);a.push(r)}if(n!=null&&n.length>0)for(let t of n){let n=await this.writeGlobalFastCommand(e,o,t);a.push(n)}if(r!=null&&r.length>0)for(let t of r){let n=await this.writeGlobalSkill(e,o,t);a.push(...n)}return{files:a,dirs:[]}}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,Sv,a),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return this.writeFile(e,o,s,`globalFastCommand`)}async writeGlobalSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,Cv,a),s=i.join(o,`SKILL.md`),c=this.buildCodexSkillContent(n),l=await this.writeFile(e,s,c,`globalSkill`);if(r.push(l),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`),a=i.join(o,n),s=await this.writeFile(e,a,t.content,`skillRefDoc`);r.push(s)}if(n.resources!=null)for(let t of n.resources){let n=i.join(o,t.relativePath),a=await this.writeFile(e,n,t.content,`skillResource`);r.push(a)}return r}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeSkillName(t.name,64),r=this.normalizeToSingleLine(t.description,1024),i={};t.displayName!=null&&(i[`short-description`]=t.displayName),t.version!=null&&(i.version=t.version),t.author!=null&&(i.author=t.author),t.keywords!=null&&t.keywords.length>0&&(i.keywords=[...t.keywords]);let a={name:n,description:r};return Object.keys(i).length>0&&(a.metadata=i),t.allowTools!=null&&t.allowTools.length>0&&(a[`allowed-tools`]=t.allowTools.join(` `)),Ig(a,e.content)}normalizeSkillName(e,t){let n=e.toLowerCase().replaceAll(/[^a-z0-9-]/g,`-`).replaceAll(/-+/g,`-`).replaceAll(/^-+|-+$/g,``);return n.length>t&&(n=n.slice(0,t).replace(/-+$/,``)),n}normalizeToSingleLine(e,t){let n=e.replaceAll(/[\r\n]+/g,` `).replaceAll(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}};const Tv=`.cursor`,Ev=`mcp.json`,Dv=`commands`,Ov=`rules`,kv=`global.mdc`,Av=`skills-cursor`,jv=`SKILL.md`,Mv=new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`]);var Nv=class extends Bg{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:Tv,outputFileName:``,dependsOn:[`AgentsOutputPlugin`],indexignore:`.cursorignore`}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=this.getGlobalConfigDir(),n=i.join(t,Ev),a={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp.json to empty shell`};try{return this.ensureDirectory(t),r.writeFileSync(n,JSON.stringify(a,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp.json to empty shell`}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`mcpConfigCleanup`,path:n,error:t}),{success:!1,error:e,description:`Failed to reset mcp.json`}}})}async registerGlobalOutputDirs(e){let t=[],n=this.getGlobalConfigDir(),{fastCommands:r,skills:a,rules:o}=e.collectedInputContext;if(r!=null&&r.length>0){let e=this.getGlobalCommandsDir();t.push({pathKind:L.Relative,path:Dv,basePath:n,getDirectoryName:()=>Dv,getAbsolutePath:()=>e})}if(a!=null&&a.length>0)for(let e of a){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let a=i.join(n,Av,r);t.push({pathKind:L.Relative,path:i.join(Av,r),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>a})}let s=o?.filter(e=>e.scope===`global`);if(s==null||s.length===0)return t;let c=i.join(n,Ov);return t.push({pathKind:L.Relative,path:Ov,basePath:n,getDirectoryName:()=>Ov,getAbsolutePath:()=>c}),t}async registerGlobalOutputFiles(e){let t=[],n=this.getGlobalConfigDir(),{skills:r,fastCommands:a}=e.collectedInputContext;if(r?.some(e=>e.mcpConfig!=null)??!1){let e=i.join(n,Ev);t.push({pathKind:L.Relative,path:Ev,basePath:n,getDirectoryName:()=>Tv,getAbsolutePath:()=>e})}if(a!=null&&a.length>0){let r=this.getGlobalCommandsDir(),o=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of a){let a=this.transformFastCommandName(e,o),s=i.join(r,a);t.push({pathKind:L.Relative,path:i.join(Dv,a),basePath:n,getDirectoryName:()=>Dv,getAbsolutePath:()=>s})}}let o=e.collectedInputContext.rules?.filter(e=>e.scope===`global`);if(o!=null&&o.length>0){let e=i.join(n,Ov);for(let r of o){let a=this.buildRuleFileName(r),o=i.join(e,a);t.push({pathKind:L.Relative,path:i.join(Ov,a),basePath:n,getDirectoryName:()=>Ov,getAbsolutePath:()=>o})}}if(r==null||r.length===0)return t;let s=this.getSkillsCursorDir();for(let e of r){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let a=i.join(s,r);if(t.push({pathKind:L.Relative,path:i.join(Av,r,jv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,jv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:i.join(Av,r,Ev),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,Ev)}),e.childDocs!=null)for(let o of e.childDocs){let e=o.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:i.join(Av,r,e),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,e)})}if(e.resources!=null)for(let o of e.resources)t.push({pathKind:L.Relative,path:i.join(Av,r,o.relativePath),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,o.relativePath)})}return t}async registerProjectOutputDirs(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.some(e=>e.scope===`project`)??!1;if(r==null&&!a)return t;for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRulesDirRelativePath(n))}return t}async registerProjectOutputFiles(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.filter(e=>e.scope===`project`),o=a!=null&&a.length>0;if(r==null&&!o)return t;if(r!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRuleFileRelativePath(n,kv))}if(o)for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of a){let r=this.buildRuleFileName(e);t.push(this.createProjectRuleFileRelativePath(n,r))}}return t.push(...this.registerProjectIgnoreOutputFiles(n.projects)),t}async canWrite(e){let{workspace:t,skills:n,fastCommands:r,globalMemory:i,rules:a,aiAgentIgnoreConfigFiles:o}=e.collectedInputContext,s=(n?.length??0)>0,c=(r?.length??0)>0,l=(a?.length??0)>0,u=i!=null&&t.projects.some(e=>e.dirFromWorkspacePath!=null),d=o?.some(e=>e.fileName===`.cursorignore`)??!1;return s||c||u||l||d?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeGlobalOutputs(e){let{skills:t,fastCommands:n,rules:r}=e.collectedInputContext,a=[],o=[];if(t!=null&&t.length>0){let n=await this.writeGlobalMcpConfig(e,t);n!=null&&a.push(n);let r=this.getSkillsCursorDir();for(let n of t){let t=n.yamlFrontMatter.name;if(this.isPreservedSkill(t))continue;let i=await this.writeGlobalSkill(e,r,n);a.push(...i)}}if(n!=null&&n.length>0){let t=this.getGlobalCommandsDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);a.push(n)}}let s=r?.filter(e=>e.scope===`global`);if(s==null||s.length===0)return{files:a,dirs:o};let c=i.join(this.getGlobalConfigDir(),Ov);for(let t of s){let n=await this.writeRuleMdcFile(e,c,t,this.getGlobalConfigDir());a.push(n)}return{files:a,dirs:o}}async writeProjectOutputs(e){let t=[],n=[],{workspace:r,globalMemory:a,rules:o}=e.collectedInputContext;if(a!=null){let n=this.buildGlobalRuleContent(a.content);for(let i of r.projects){if(i.dirFromWorkspacePath==null)continue;let r=await this.writeProjectGlobalRule(e,i,n);t.push(r)}}let s=o?.filter(e=>e.scope===`project`);if(s!=null&&s.length>0)for(let n of r.projects){let r=n.dirFromWorkspacePath;if(r==null)continue;let a=i.join(r.basePath,r.path,Tv,Ov);for(let n of s){let i=await this.writeRuleMdcFile(e,a,n,r.basePath);t.push(i)}}let c=await this.writeProjectIgnoreFiles(e);return t.push(...c),{files:t,dirs:n}}createProjectRulesDirRelativePath(e){let t=i.join(e.path,Tv,Ov);return{pathKind:L.Relative,path:t,basePath:e.basePath,getDirectoryName:()=>Ov,getAbsolutePath:()=>i.join(e.basePath,t)}}createProjectRuleFileRelativePath(e,t){let n=i.join(e.path,Tv,Ov,t);return{pathKind:L.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>Ov,getAbsolutePath:()=>i.join(e.basePath,n)}}buildGlobalRuleContent(e){return Ig({description:`Global prompt (synced)`,alwaysApply:!0},e)}async writeProjectGlobalRule(e,t,n){let r=t.dirFromWorkspacePath,a=i.join(r.basePath,r.path,Tv,Ov),o=i.join(a,kv),s=this.createProjectRuleFileRelativePath(r,kv);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalRule`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,n),this.log.trace({action:`write`,type:`globalRule`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalRule`,path:o,error:t}),{path:s,success:!1,error:e}}}isPreservedSkill(e){return Mv.has(e)}getSkillsCursorDir(){return i.join(this.getGlobalConfigDir(),Av)}getGlobalCommandsDir(){return i.join(this.getGlobalConfigDir(),Dv)}async writeGlobalFastCommand(e,t,n){let a=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0}),o=this.transformFastCommandName(n,a),s=i.join(t,o),c={pathKind:L.Relative,path:i.join(Dv,o),basePath:this.getGlobalConfigDir(),getDirectoryName:()=>Dv,getAbsolutePath:()=>s},l=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:s}),{path:c,success:!0,skipped:!1};try{return this.ensureDirectory(t),r.writeFileSync(s,l),this.log.trace({action:`write`,type:`globalFastCommand`,path:s}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalFastCommand`,path:s,error:t}),{path:c,success:!1,error:e}}}async writeGlobalMcpConfig(e,t){let n={};for(let e of t){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,r]of Object.entries(t))n[e]=this.transformMcpConfigForCursor({...r})}if(Object.keys(n).length===0)return null;let a=this.getGlobalConfigDir(),o=i.join(a,Ev),s={pathKind:L.Relative,path:Ev,basePath:a,getDirectoryName:()=>Tv,getAbsolutePath:()=>o},c={};try{if(this.existsSync(o)){let e=r.readFileSync(o,`utf8`);c=JSON.parse(e)}}catch{c={}}let l={...c.mcpServers??{},...n};c.mcpServers=l;let u=JSON.stringify(c,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:o,serverCount:Object.keys(n).length}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),r.writeFileSync(o,u),this.log.trace({action:`write`,type:`globalMcpConfig`,path:o,serverCount:Object.keys(n).length}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalMcpConfig`,path:o,error:t}),{path:s,success:!1,error:e}}}transformMcpConfigForCursor(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.url??e.serverUrl;return n==null?t:(t.url=n,e.headers!=null&&(t.headers=e.headers),t)}async writeGlobalSkill(e,t,n){let r=[],a=n.yamlFrontMatter.name,o=i.join(t,a),s=i.join(o,jv),c=this.getGlobalConfigDir(),l={pathKind:L.Relative,path:i.join(Av,a,jv),basePath:c,getDirectoryName:()=>a,getAbsolutePath:()=>s},u=this.buildSkillFrontMatter(n),d=n.content,f=Ig(u,d);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:s}),r.push({path:l,success:!0,skipped:!1});else try{this.ensureDirectory(o),this.writeFileSync(s,f),this.log.trace({action:`write`,type:`skill`,path:s}),r.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:s,error:t}),r.push({path:l,success:!1,error:e})}if(n.mcpConfig!=null){let t=await this.writeSkillMcpConfig(e,n,o,c);r.push(t)}if(n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillChildDoc(e,t,o,a,c);r.push(n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,t,o,a,c);r.push(n)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeSkillMcpConfig(e,t,n,r){let a=t.yamlFrontMatter.name,o=i.join(n,Ev),s={pathKind:L.Relative,path:i.join(Av,a,Ev),basePath:r,getDirectoryName:()=>a,getAbsolutePath:()=>o},c=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`mcpConfig`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:o,error:t}),{path:s,success:!1,error:e}}}async writeSkillChildDoc(e,t,n,r,a){let o=t.relativePath.replace(/\.mdx$/,`.md`),s=i.join(n,o),c={pathKind:L.Relative,path:i.join(Av,r,o),basePath:a,getDirectoryName:()=>r,getAbsolutePath:()=>s},l=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:s}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(s);return this.ensureDirectory(e),this.writeFileSync(s,l),this.log.trace({action:`write`,type:`childDoc`,path:s}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:s,error:t}),{path:c,success:!1,error:e}}}async writeSkillResource(e,t,n,r,a){let o=i.join(n,t.relativePath),s={pathKind:L.Relative,path:i.join(Av,r,t.relativePath),basePath:a,getDirectoryName:()=>r,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:o}),{path:s,success:!0,skipped:!1};try{let e=i.dirname(o);if(this.ensureDirectory(e),t.encoding===`base64`){let e=d.from(t.content,`base64`);this.writeFileSyncBuffer(o,e)}else this.writeFileSync(o,t.content);return this.log.trace({action:`write`,type:`resource`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:o,error:t}),{path:s,success:!1,error:e}}}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.mdc`}buildRuleMdcContent(e){return Ig({alwaysApply:!1,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
1230
+ `).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function rv(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 iv(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=ov(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return sv(r).map(e=>tv(e.trim(),t,n))}function av(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=ov(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=cv(r);for(let e of a){let r=lv(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]=tv(o,t,n)}return i}function ov(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 sv(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 cv(e){return sv(e)}function lv(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 uv(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=l_(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function dv(e,t,n){return!uv(e,t)||e.children.length===0?[]:n(e.children,t)}async function fv(e,t){if(!uv(e,t)||e.children.length===0)return[];let n=pv(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function pv(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=l_(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=pv(r.children,t));return n}function mv(){o_(`Md`,dv),o_(`Md.Line`,fv)}mv();function hv(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 gv(e,t){let n=_h(e),r=hv(t?.globalScope,t?.scope),i=s_(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Pg.parse(e.value)}catch{}a=Q_(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 K_(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=yu().use(ui,[`yaml`]).use($l).use(Z_,{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}var _v=class extends Bg{commandsSubDir;agentsSubDir;skillsSubDir;supportsFastCommands;supportsSubAgents;supportsSkills;toolPreset;constructor(e,t){super(e,t),this.commandsSubDir=t.commandsSubDir??`commands`,this.agentsSubDir=t.agentsSubDir??`agents`,this.skillsSubDir=t.skillsSubDir??`skills`,this.supportsFastCommands=t.supportsFastCommands??!0,this.supportsSubAgents=t.supportsSubAgents??!0,this.supportsSkills=t.supportsSkills??!0,t.toolPreset!==void 0&&(this.toolPreset=t.toolPreset)}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=[];this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir);for(let e of r)n.push(this.createRelativePath(e,t,()=>e));return n}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=[];if(this.supportsFastCommands&&r.push(this.commandsSubDir),this.supportsSubAgents&&r.push(this.agentsSubDir),this.supportsSkills&&r.push(this.skillsSubDir),r.length===0)return[];for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of r){let r=i.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push(this.createRelativePath(r,e.dirFromWorkspacePath.basePath,()=>n))}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,this.outputFileName)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,this.outputFileName));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir(),r=[this.createRelativePath(this.outputFileName,n,()=>this.globalConfigDir)],{fastCommands:a,subAgents:o,skills:s}=e.collectedInputContext,c={includeSeriesPrefix:!0};if(this.supportsFastCommands&&a!=null)for(let e of a){let t=this.transformFastCommandName(e,c);r.push(this.createRelativePath(i.join(this.commandsSubDir,t),n,()=>this.commandsSubDir))}if(this.supportsSubAgents&&o!=null)for(let e of o){let t=e.dir.path.replace(/\.mdx$/,`.md`);r.push(this.createRelativePath(i.join(this.agentsSubDir,t),n,()=>this.agentsSubDir))}if(this.supportsSkills&&s!=null)for(let e of s){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),a=i.join(this.skillsSubDir,t);if(r.push(this.createRelativePath(i.join(a,`SKILL.md`),n,()=>t)),e.childDocs!=null)for(let o of e.childDocs){let e=o.dir.path.replace(/\.mdx$/,`.md`),s=i.join(a,e);r.push(this.createRelativePath(s,n,()=>t))}if(e.resources!=null)for(let o of e.resources){let e=i.join(a,o.relativePath);r.push(this.createRelativePath(e,n,()=>t))}}return r}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=this.supportsFastCommands&&(r?.length??0)>0,l=this.supportsSubAgents&&(i?.length??0)>0,u=this.supportsSkills&&(a?.length??0)>0;return o||s||c||l||u?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],r=[];if([{enabled:!0,data:t},{enabled:this.supportsFastCommands,data:e.collectedInputContext.fastCommands},{enabled:this.supportsSubAgents,data:e.collectedInputContext.subAgents},{enabled:this.supportsSkills,data:e.collectedInputContext.skills}].every(e=>!e.enabled||e.data==null))return{files:n,dirs:r};let{fastCommands:a,subAgents:o,skills:s}=e.collectedInputContext,c=this.getGlobalConfigDir();if(t!=null){let r=i.join(c,this.outputFileName),a=this.createRelativePath(this.outputFileName,c,()=>this.globalConfigDir);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:a,success:!0,skipped:!1});else try{ut(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),n.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),n.push({path:a,success:!1,error:e})}}if(this.supportsFastCommands&&a!=null)for(let t of a){let r=await this.writeFastCommand(e,c,t);n.push(...r)}if(this.supportsSubAgents&&o!=null)for(let t of o){let r=await this.writeSubAgent(e,c,t);n.push(...r)}if(this.supportsSkills&&s!=null)for(let t of s){let r=await this.writeSkill(e,c,t);n.push(...r)}return{files:n,dirs:r}}async writeFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,this.commandsSubDir),s=i.join(o,a),c=n.content,l=n.yamlFrontMatter,u=!1;if(n.rawMdxContent!=null&&this.toolPreset!=null){this.log.debug(`recompiling fast command with tool preset`,{file:n.dir.getAbsolutePath(),toolPreset:this.toolPreset,hasRawContent:!0});try{let e=new fr({toolPreset:this.toolPreset}).collect(),t=await gv(n.rawMdxContent,{globalScope:e,extractMetadata:!0,basePath:n.dir.basePath});c=t.content,l=t.metadata.fields,u=!0}catch(e){this.log.warn(`failed to recompile fast command, using default`,{file:n.dir.getAbsolutePath(),error:e instanceof Error?e.message:String(e)})}}let d=u?this.buildMarkdownContent(c,l):this.buildMarkdownContentWithRaw(c,l,n.rawFrontMatter);return[await this.writeFile(e,s,d,`fastCommand`)]}async writeSubAgent(e,t,n){let r=n.dir.path.replace(/\.mdx$/,`.md`),a=i.join(t,this.agentsSubDir),o=i.join(a,r),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return[await this.writeFile(e,o,s,`subAgent`)]}async writeSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,this.skillsSubDir,a),s=i.join(o,`SKILL.md`),c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter),l=await this.writeFile(e,s,c,`skill`);if(r.push(l),n.childDocs!=null)for(let i of n.childDocs){let n=await this.writeSkillReferenceDocument(e,o,a,i,t);r.push(...n)}if(n.resources!=null)for(let i of n.resources){let n=await this.writeSkillResource(e,o,a,i,t);r.push(...n)}return r}async writeSkillReferenceDocument(e,t,n,r,a){let o=r.dir.path.replace(/\.mdx$/,`.md`),s=i.join(t,o);return[await this.writeFile(e,s,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,a){let o=i.join(t,r.relativePath);return[await this.writeFile(e,o,r.content,`skillResource`)]}normalizeRuleScope(e){return e.scope??`project`}};const vv=`rules`;var yv=class extends _v{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.md`}buildRuleContent(e){return e.globs.length===0?e.content:this.buildMarkdownContent(e.content,{paths:[...e.globs]})}async registerGlobalOutputDirs(e){let t=await super.registerGlobalOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);return n!=null&&n.length>0&&t.push(this.createRelativePath(vv,this.getGlobalConfigDir(),()=>vv)),t}async registerGlobalOutputFiles(e){let t=await super.registerGlobalOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(n==null||n.length===0)return t;let r=i.join(this.getGlobalConfigDir(),vv);for(let e of n)t.push(this.createRelativePath(this.buildRuleFileName(e),r,()=>vv));return t}async registerProjectOutputDirs(e){let t=await super.registerProjectOutputDirs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;for(let n of e.collectedInputContext.workspace.projects){if(n.dirFromWorkspacePath==null)continue;let e=i.join(n.dirFromWorkspacePath.path,this.globalConfigDir,vv);t.push(this.createRelativePath(e,n.dirFromWorkspacePath.basePath,()=>vv))}return t}async registerProjectOutputFiles(e){let t=await super.registerProjectOutputFiles(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;for(let r of e.collectedInputContext.workspace.projects)if(r.dirFromWorkspacePath!=null)for(let e of n){let n=i.join(r.dirFromWorkspacePath.path,this.globalConfigDir,vv,this.buildRuleFileName(e));t.push(this.createRelativePath(n,r.dirFromWorkspacePath.basePath,()=>vv))}return t}async canWrite(e){return(e.collectedInputContext.rules?.length??0)>0?!0:super.canWrite(e)}async writeGlobalOutputs(e){let t=await super.writeGlobalOutputs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(n==null||n.length===0)return t;let r=i.join(this.getGlobalConfigDir(),vv),a=[];for(let t of n)a.push(await this.writeFile(e,i.join(r,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`));return{files:[...t.files,...a],dirs:t.dirs}}async writeProjectOutputs(e){let t=await super.writeProjectOutputs(e),n=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`project`);if(n==null||n.length===0)return t;let r=[];for(let t of e.collectedInputContext.workspace.projects){if(t.dirFromWorkspacePath==null)continue;let a=i.join(t.dirFromWorkspacePath.basePath,t.dirFromWorkspacePath.path,this.globalConfigDir,vv);for(let t of n)r.push(await this.writeFile(e,i.join(a,this.buildRuleFileName(t)),this.buildRuleContent(t),`rule`))}return{files:[...t.files,...r],dirs:t.dirs}}};const bv=`AGENTS.md`,xv=`.codex`,Sv=`prompts`,Cv=`skills`;var wv=class extends Bg{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:xv,outputFileName:bv,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[this.createRelativePath(Sv,t,()=>Sv)],{skills:r}=e.collectedInputContext;if(r!=null&&r.length>0)for(let e of r){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName();n.push(this.createRelativePath(i.join(Cv,r),t,()=>r))}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[this.createRelativePath(bv,e,()=>xv)]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext;return t!=null||(n?.length??0)>0||(r?.length??0)>0?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,a=[],o=this.getGlobalConfigDir();if(t!=null){let n=i.join(o,bv),r=await this.writeFile(e,n,t.content,`globalMemory`);a.push(r)}if(n!=null&&n.length>0)for(let t of n){let n=await this.writeGlobalFastCommand(e,o,t);a.push(n)}if(r!=null&&r.length>0)for(let t of r){let n=await this.writeGlobalSkill(e,o,t);a.push(...n)}return{files:a,dirs:[]}}async writeGlobalFastCommand(e,t,n){let r=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,r),o=i.join(t,Sv,a),s=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);return this.writeFile(e,o,s,`globalFastCommand`)}async writeGlobalSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,Cv,a),s=i.join(o,`SKILL.md`),c=this.buildCodexSkillContent(n),l=await this.writeFile(e,s,c,`globalSkill`);if(r.push(l),n.childDocs!=null)for(let t of n.childDocs){let n=t.dir.path.replace(/\.mdx$/,`.md`),a=i.join(o,n),s=await this.writeFile(e,a,t.content,`skillRefDoc`);r.push(s)}if(n.resources!=null)for(let t of n.resources){let n=i.join(o,t.relativePath),a=await this.writeFile(e,n,t.content,`skillResource`);r.push(a)}return r}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeSkillName(t.name,64),r=this.normalizeToSingleLine(t.description,1024),i={};t.displayName!=null&&(i[`short-description`]=t.displayName),t.version!=null&&(i.version=t.version),t.author!=null&&(i.author=t.author),t.keywords!=null&&t.keywords.length>0&&(i.keywords=[...t.keywords]);let a={name:n,description:r};return Object.keys(i).length>0&&(a.metadata=i),t.allowTools!=null&&t.allowTools.length>0&&(a[`allowed-tools`]=t.allowTools.join(` `)),Ig(a,e.content)}normalizeSkillName(e,t){let n=e.toLowerCase().replaceAll(/[^a-z0-9-]/g,`-`).replaceAll(/-+/g,`-`).replaceAll(/^-+|-+$/g,``);return n.length>t&&(n=n.slice(0,t).replace(/-+$/,``)),n}normalizeToSingleLine(e,t){let n=e.replaceAll(/[\r\n]+/g,` `).replaceAll(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}};const Tv=`.cursor`,Ev=`mcp.json`,Dv=`commands`,Ov=`rules`,kv=`global.mdc`,Av=`skills-cursor`,jv=`SKILL.md`,Mv=new Set([`create-rule`,`create-skill`,`create-subagent`,`migrate-to-skills`,`update-cursor-settings`]);var Nv=class extends Bg{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:Tv,outputFileName:``,dependsOn:[`AgentsOutputPlugin`],indexignore:`.cursorignore`}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=this.getGlobalConfigDir(),n=i.join(t,Ev),a={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp.json to empty shell`};try{return this.ensureDirectory(t),r.writeFileSync(n,JSON.stringify(a,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp.json to empty shell`}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`mcpConfigCleanup`,path:n,error:t}),{success:!1,error:e,description:`Failed to reset mcp.json`}}})}async registerGlobalOutputDirs(e){let t=[],n=this.getGlobalConfigDir(),{fastCommands:r,skills:a,rules:o}=e.collectedInputContext;if(r!=null&&r.length>0){let e=this.getGlobalCommandsDir();t.push({pathKind:L.Relative,path:Dv,basePath:n,getDirectoryName:()=>Dv,getAbsolutePath:()=>e})}if(a!=null&&a.length>0)for(let e of a){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let a=i.join(n,Av,r);t.push({pathKind:L.Relative,path:i.join(Av,r),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>a})}let s=o?.filter(e=>this.normalizeRuleScope(e)===`global`);if(s==null||s.length===0)return t;let c=i.join(n,Ov);return t.push({pathKind:L.Relative,path:Ov,basePath:n,getDirectoryName:()=>Ov,getAbsolutePath:()=>c}),t}async registerGlobalOutputFiles(e){let t=[],n=this.getGlobalConfigDir(),{skills:r,fastCommands:a}=e.collectedInputContext;if(r?.some(e=>e.mcpConfig!=null)??!1){let e=i.join(n,Ev);t.push({pathKind:L.Relative,path:Ev,basePath:n,getDirectoryName:()=>Tv,getAbsolutePath:()=>e})}if(a!=null&&a.length>0){let r=this.getGlobalCommandsDir(),o=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of a){let a=this.transformFastCommandName(e,o),s=i.join(r,a);t.push({pathKind:L.Relative,path:i.join(Dv,a),basePath:n,getDirectoryName:()=>Dv,getAbsolutePath:()=>s})}}let o=e.collectedInputContext.rules?.filter(e=>this.normalizeRuleScope(e)===`global`);if(o!=null&&o.length>0){let e=i.join(n,Ov);for(let r of o){let a=this.buildRuleFileName(r),o=i.join(e,a);t.push({pathKind:L.Relative,path:i.join(Ov,a),basePath:n,getDirectoryName:()=>Ov,getAbsolutePath:()=>o})}}if(r==null||r.length===0)return t;let s=this.getSkillsCursorDir();for(let e of r){let r=e.yamlFrontMatter.name;if(this.isPreservedSkill(r))continue;let a=i.join(s,r);if(t.push({pathKind:L.Relative,path:i.join(Av,r,jv),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,jv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:i.join(Av,r,Ev),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,Ev)}),e.childDocs!=null)for(let o of e.childDocs){let e=o.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:i.join(Av,r,e),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,e)})}if(e.resources!=null)for(let o of e.resources)t.push({pathKind:L.Relative,path:i.join(Av,r,o.relativePath),basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i.join(a,o.relativePath)})}return t}async registerProjectOutputDirs(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.some(e=>this.normalizeRuleScope(e)===`project`)??!1;if(r==null&&!a)return t;for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRulesDirRelativePath(n))}return t}async registerProjectOutputFiles(e){let t=[],{workspace:n,globalMemory:r,rules:i}=e.collectedInputContext,a=i?.filter(e=>this.normalizeRuleScope(e)===`project`),o=a!=null&&a.length>0;if(r==null&&!o)return t;if(r!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n!=null&&t.push(this.createProjectRuleFileRelativePath(n,kv))}if(o)for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of a){let r=this.buildRuleFileName(e);t.push(this.createProjectRuleFileRelativePath(n,r))}}return t.push(...this.registerProjectIgnoreOutputFiles(n.projects)),t}async canWrite(e){let{workspace:t,skills:n,fastCommands:r,globalMemory:i,rules:a,aiAgentIgnoreConfigFiles:o}=e.collectedInputContext,s=(n?.length??0)>0,c=(r?.length??0)>0,l=(a?.length??0)>0,u=i!=null&&t.projects.some(e=>e.dirFromWorkspacePath!=null),d=o?.some(e=>e.fileName===`.cursorignore`)??!1;return s||c||u||l||d?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeGlobalOutputs(e){let{skills:t,fastCommands:n,rules:r}=e.collectedInputContext,a=[],o=[];if(t!=null&&t.length>0){let n=await this.writeGlobalMcpConfig(e,t);n!=null&&a.push(n);let r=this.getSkillsCursorDir();for(let n of t){let t=n.yamlFrontMatter.name;if(this.isPreservedSkill(t))continue;let i=await this.writeGlobalSkill(e,r,n);a.push(...i)}}if(n!=null&&n.length>0){let t=this.getGlobalCommandsDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);a.push(n)}}let s=r?.filter(e=>this.normalizeRuleScope(e)===`global`);if(s==null||s.length===0)return{files:a,dirs:o};let c=i.join(this.getGlobalConfigDir(),Ov);for(let t of s){let n=await this.writeRuleMdcFile(e,c,t,this.getGlobalConfigDir());a.push(n)}return{files:a,dirs:o}}async writeProjectOutputs(e){let t=[],n=[],{workspace:r,globalMemory:a,rules:o}=e.collectedInputContext;if(a!=null){let n=this.buildGlobalRuleContent(a.content);for(let i of r.projects){if(i.dirFromWorkspacePath==null)continue;let r=await this.writeProjectGlobalRule(e,i,n);t.push(r)}}let s=o?.filter(e=>this.normalizeRuleScope(e)===`project`);if(s!=null&&s.length>0)for(let n of r.projects){let r=n.dirFromWorkspacePath;if(r==null)continue;let a=i.join(r.basePath,r.path,Tv,Ov);for(let n of s){let i=await this.writeRuleMdcFile(e,a,n,r.basePath);t.push(i)}}let c=await this.writeProjectIgnoreFiles(e);return t.push(...c),{files:t,dirs:n}}createProjectRulesDirRelativePath(e){let t=i.join(e.path,Tv,Ov);return{pathKind:L.Relative,path:t,basePath:e.basePath,getDirectoryName:()=>Ov,getAbsolutePath:()=>i.join(e.basePath,t)}}createProjectRuleFileRelativePath(e,t){let n=i.join(e.path,Tv,Ov,t);return{pathKind:L.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>Ov,getAbsolutePath:()=>i.join(e.basePath,n)}}buildGlobalRuleContent(e){return Ig({description:`Global prompt (synced)`,alwaysApply:!0},e)}async writeProjectGlobalRule(e,t,n){let r=t.dirFromWorkspacePath,a=i.join(r.basePath,r.path,Tv,Ov),o=i.join(a,kv),s=this.createProjectRuleFileRelativePath(r,kv);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalRule`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,n),this.log.trace({action:`write`,type:`globalRule`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalRule`,path:o,error:t}),{path:s,success:!1,error:e}}}isPreservedSkill(e){return Mv.has(e)}getSkillsCursorDir(){return i.join(this.getGlobalConfigDir(),Av)}getGlobalCommandsDir(){return i.join(this.getGlobalConfigDir(),Dv)}async writeGlobalFastCommand(e,t,n){let a=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0}),o=this.transformFastCommandName(n,a),s=i.join(t,o),c={pathKind:L.Relative,path:i.join(Dv,o),basePath:this.getGlobalConfigDir(),getDirectoryName:()=>Dv,getAbsolutePath:()=>s},l=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:s}),{path:c,success:!0,skipped:!1};try{return this.ensureDirectory(t),r.writeFileSync(s,l),this.log.trace({action:`write`,type:`globalFastCommand`,path:s}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalFastCommand`,path:s,error:t}),{path:c,success:!1,error:e}}}async writeGlobalMcpConfig(e,t){let n={};for(let e of t){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,r]of Object.entries(t))n[e]=this.transformMcpConfigForCursor({...r})}if(Object.keys(n).length===0)return null;let a=this.getGlobalConfigDir(),o=i.join(a,Ev),s={pathKind:L.Relative,path:Ev,basePath:a,getDirectoryName:()=>Tv,getAbsolutePath:()=>o},c={};try{if(this.existsSync(o)){let e=r.readFileSync(o,`utf8`);c=JSON.parse(e)}}catch{c={}}let l={...c.mcpServers??{},...n};c.mcpServers=l;let u=JSON.stringify(c,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:o,serverCount:Object.keys(n).length}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),r.writeFileSync(o,u),this.log.trace({action:`write`,type:`globalMcpConfig`,path:o,serverCount:Object.keys(n).length}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`globalMcpConfig`,path:o,error:t}),{path:s,success:!1,error:e}}}transformMcpConfigForCursor(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.url??e.serverUrl;return n==null?t:(t.url=n,e.headers!=null&&(t.headers=e.headers),t)}async writeGlobalSkill(e,t,n){let r=[],a=n.yamlFrontMatter.name,o=i.join(t,a),s=i.join(o,jv),c=this.getGlobalConfigDir(),l={pathKind:L.Relative,path:i.join(Av,a,jv),basePath:c,getDirectoryName:()=>a,getAbsolutePath:()=>s},u=this.buildSkillFrontMatter(n),d=n.content,f=Ig(u,d);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:s}),r.push({path:l,success:!0,skipped:!1});else try{this.ensureDirectory(o),this.writeFileSync(s,f),this.log.trace({action:`write`,type:`skill`,path:s}),r.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:s,error:t}),r.push({path:l,success:!1,error:e})}if(n.mcpConfig!=null){let t=await this.writeSkillMcpConfig(e,n,o,c);r.push(t)}if(n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillChildDoc(e,t,o,a,c);r.push(n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,t,o,a,c);r.push(n)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeSkillMcpConfig(e,t,n,r){let a=t.yamlFrontMatter.name,o=i.join(n,Ev),s={pathKind:L.Relative,path:i.join(Av,a,Ev),basePath:r,getDirectoryName:()=>a,getAbsolutePath:()=>o},c=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`mcpConfig`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:o,error:t}),{path:s,success:!1,error:e}}}async writeSkillChildDoc(e,t,n,r,a){let o=t.relativePath.replace(/\.mdx$/,`.md`),s=i.join(n,o),c={pathKind:L.Relative,path:i.join(Av,r,o),basePath:a,getDirectoryName:()=>r,getAbsolutePath:()=>s},l=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:s}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(s);return this.ensureDirectory(e),this.writeFileSync(s,l),this.log.trace({action:`write`,type:`childDoc`,path:s}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:s,error:t}),{path:c,success:!1,error:e}}}async writeSkillResource(e,t,n,r,a){let o=i.join(n,t.relativePath),s={pathKind:L.Relative,path:i.join(Av,r,t.relativePath),basePath:a,getDirectoryName:()=>r,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:o}),{path:s,success:!0,skipped:!1};try{let e=i.dirname(o);if(this.ensureDirectory(e),t.encoding===`base64`){let e=d.from(t.content,`base64`);this.writeFileSyncBuffer(o,e)}else this.writeFileSync(o,t.content);return this.log.trace({action:`write`,type:`resource`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:o,error:t}),{path:s,success:!1,error:e}}}buildRuleFileName(e){return`rule-${e.series}-${e.ruleName}.mdc`}buildRuleMdcContent(e){return Ig({alwaysApply:!1,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
1231
1231
  `).map(e=>{let t=/^(\s*globs:\s*)(['"])(.*)\2\s*$/.exec(e);if(t==null)return e;let n=t[1]??`globs: `,r=t[3]??``;return r.trim().length===0?e:`${n}${r}`}).join(`
1232
1232
  `)}async writeRuleMdcFile(e,t,n,r){let a=this.buildRuleFileName(n),o=i.join(t,a),s={pathKind:L.Relative,path:i.join(Tv,Ov,a),basePath:r,getDirectoryName:()=>Ov,getAbsolutePath:()=>o},c=this.buildRuleMdcContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ruleFile`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(t),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`ruleFile`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ruleFile`,path:o,error:t}),{path:s,success:!1,error:e}}}},Pv=class extends _v{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:`.factory`,outputFileName:`AGENTS.md`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}async writeSkill(e,t,n){let r=[],a=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),o=i.join(t,this.skillsSubDir,a),s=i.join(o,`SKILL.md`),c=n.yamlFrontMatter==null?void 0:{name:n.yamlFrontMatter.name,description:n.yamlFrontMatter.description},l=this.buildMarkdownContent(n.content,c),u=await this.writeFile(e,s,l,`skill`);if(r.push(u),n.childDocs!=null)for(let i of n.childDocs){let n=await this.writeSkillReferenceDocument(e,o,a,i,t);r.push(...n)}if(n.resources!=null)for(let i of n.resources){let n=await this.writeSkillResource(e,o,a,i,t);r.push(...n)}return r}},Fv=class extends Ug{configKey;extension;constructor(e,t){super(e),this.configKey=t.configKey,this.extension=t.extension??`.mdx`}async collect(e){let{userConfigOptions:t,logger:n,path:r,fs:i,globalScope:a}=e,o=this.resolveBasePaths(t),s=this.getTargetDir(t,o),c=[];if(!(i.existsSync(s)&&i.statSync(s).isDirectory()))return this.createResult(c);try{let e=i.readdirSync(s,{withFileTypes:!0});for(let t of e)if(t.isFile()&&t.name.endsWith(this.extension)){let e=r.join(s,t.name),o=i.readFileSync(e,`utf8`);try{let r=Lg(o),i=await gv(o,{globalScope:a,extractMetadata:!0,basePath:s}),l=r.yamlFrontMatter!=null||Object.keys(i.metadata.fields).length>0?{...r.yamlFrontMatter,...i.metadata.fields}:void 0;if(l!=null){let t=this.validateMetadata(l,e);for(let e of t.warnings)n.debug(e);if(!t.valid)throw new n_([...t.errors],e)}let{content:u}=i;n.debug(`${this.name} metadata extracted`,{file:t.name,source:i.metadata.source,hasYaml:r.yamlFrontMatter!=null,hasExport:Object.keys(i.metadata.fields).length>0});let d=this.createPrompt(t.name,e,u,l,r.rawFrontMatter,r,s,o);c.push(d)}catch(t){n.error(`failed to parse ${this.name} item`,{file:e,error:t})}}}catch(e){n.error(`Failed to scan directory at ${s}`,{error:e})}return this.createResult(c)}},Iv=class extends Fv{constructor(){super(`FastCommandInputPlugin`,{configKey:`shadowSourceProject.fastCommand.dist`})}getTargetDir(e,t){return this.resolveShadowPath(e.shadowSourceProject.fastCommand.dist,t.shadowProjectDir)}validateMetadata(e,t){return It(e,t)}createResult(e){return{fastCommands:e}}extractSeriesInfo(e,t){let n=e.replace(/\.mdx$/,``);if(t!=null)return{series:t,commandName:n};let r=n.indexOf(`_`);return r===-1?{commandName:n}:{series:n.slice(0,Math.max(0,r)),commandName:n.slice(Math.max(0,r+1))}}async collect(e){let{userConfigOptions:t,logger:n,path:r,fs:i}=e,a=this.resolveBasePaths(t),o=this.getTargetDir(t,a),s=[];if(!(i.existsSync(o)&&i.statSync(o).isDirectory()))return this.createResult(s);try{let t=i.readdirSync(o,{withFileTypes:!0});for(let a of t)if(a.isFile()&&a.name.endsWith(this.extension)){let t=await this.processFile(a.name,r.join(o,a.name),o,void 0,e);t!=null&&s.push(t)}else if(a.isDirectory()){let t=r.join(o,a.name);try{let n=i.readdirSync(t,{withFileTypes:!0});for(let i of n)if(i.isFile()&&i.name.endsWith(this.extension)){let n=await this.processFile(i.name,r.join(t,i.name),o,a.name,e);n!=null&&s.push(n)}}catch(e){n.error(`Failed to scan subdirectory at ${t}`,{error:e})}}}catch(e){n.error(`Failed to scan directory at ${o}`,{error:e})}return this.createResult(s)}async processFile(e,t,n,r,i){let{logger:a,globalScope:o}=i,s=i.fs.readFileSync(t,`utf8`);try{let c=Lg(s),l=await gv(s,{globalScope:o,extractMetadata:!0,basePath:r==null?n:i.path.join(n,r)}),u=c.yamlFrontMatter!=null||Object.keys(l.metadata.fields).length>0?{...c.yamlFrontMatter,...l.metadata.fields}:void 0;if(u!=null){let e=this.validateMetadata(u,t);for(let t of e.warnings)a.debug(t);if(!e.valid)throw new n_([...e.errors],t)}let{content:d}=l,f=r==null?e:`${r}/${e}`;return a.debug(`${this.name} metadata extracted`,{file:f,source:l.metadata.source,hasYaml:c.yamlFrontMatter!=null,hasExport:Object.keys(l.metadata.fields).length>0}),this.createPrompt(f,t,d,u,c.rawFrontMatter,c,n,s)}catch(e){a.error(`failed to parse ${this.name} item`,{file:t,error:e});return}}createPrompt(e,t,n,r,i,a,o,s){let c=e.indexOf(`/`),l=c===-1?void 0:e.slice(0,c),u=c===-1?e:e.slice(c+1),d=this.extractSeriesInfo(u,l);return{type:Et.FastCommand,content:n,length:n.length,filePathKind:L.Relative,...r!=null&&{yamlFrontMatter:r},...i!=null&&{rawFrontMatter:i},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:L.Relative,path:e,basePath:o,getDirectoryName:()=>e.replace(/\.mdx$/,``),getAbsolutePath:()=>t},...d.series!=null&&{series:d.series},commandName:d.commandName,rawMdxContent:s}}},Lv=class extends _v{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:`GEMINI.md`,supportsFastCommands:!1,supportsSubAgents:!1,supportsSkills:!1})}};const Rv=`.skills`,zv=`.aindex/.skills`,Bv=`SKILL.md`,Vv=`mcp.json`;var Hv=class extends Bg{constructor(){super(`GenericSkillsOutputPlugin`,{globalConfigDir:zv,outputFileName:Bv}),this.registerCleanEffect(`legacy-global-skills-cleanup`,async e=>{let t=this.joinPath(this.getHomeDir(),`.skills`);if(!this.existsSync(t))return{success:!0,description:`Legacy global skills dir does not exist, nothing to clean`};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`legacyCleanup`,path:t}),{success:!0,description:`Would clean legacy global skills dir: ${t}`};try{let e=this.readdirSync(t,{withFileTypes:!0}),n=0;for(let i of e)if(i.isDirectory()){let e=this.joinPath(t,i.name),a=this.joinPath(e,Bv);this.existsSync(a)&&(r.rmSync(e,{recursive:!0}),n++)}return this.readdirSync(t).length===0&&r.rmdirSync(t),this.log.trace({action:`clean`,type:`legacySkills`,dir:t,cleanedCount:n}),{success:!0,description:`Cleaned ${n} legacy skills from ${t}`}}catch(e){let n=e instanceof Error?e.message:String(e);return this.log.error({action:`clean`,type:`legacySkills`,dir:t,error:n}),{success:!1,description:`Failed to clean legacy skills dir`,error:e}}})}getGlobalSkillsDir(){return this.joinPath(this.getHomeDir(),zv)}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{skills:r}=e.collectedInputContext;if(r==null||r.length===0)return t;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.path,Rv);t.push({pathKind:L.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Rv,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{skills:r}=e.collectedInputContext;if(r==null||r.length===0)return t;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.basePath,e.dirFromWorkspacePath.path,Rv);for(let i of r){let r=i.yamlFrontMatter.name,a=this.joinPath(n,r);t.push({pathKind:L.Relative,path:this.joinPath(Rv,r),basePath:this.joinPath(e.dirFromWorkspacePath.basePath,e.dirFromWorkspacePath.path),getDirectoryName:()=>r,getAbsolutePath:()=>a})}}return t}async registerGlobalOutputDirs(e){let{skills:t}=e.collectedInputContext;if(t==null||t.length===0)return[];let n=this.getGlobalSkillsDir();return[{pathKind:L.Relative,path:zv,basePath:this.getHomeDir(),getDirectoryName:()=>zv,getAbsolutePath:()=>n}]}async registerGlobalOutputFiles(e){let t=[],{skills:n}=e.collectedInputContext;if(n==null||n.length===0)return t;let r=this.getGlobalSkillsDir();for(let e of n){let n=e.yamlFrontMatter.name,i=this.joinPath(r,n);if(t.push({pathKind:L.Relative,path:this.joinPath(zv,n,Bv),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Bv)}),e.mcpConfig!=null&&t.push({pathKind:L.Relative,path:this.joinPath(zv,n,Vv),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Vv)}),e.childDocs!=null)for(let r of e.childDocs){let e=r.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:L.Relative,path:this.joinPath(zv,n,e),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,e)})}if(e.resources!=null)for(let r of e.resources)t.push({pathKind:L.Relative,path:this.joinPath(zv,n,r.relativePath),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,r.relativePath)})}return t}async canWrite(e){let{skills:t}=e.collectedInputContext,{projects:n}=e.collectedInputContext.workspace;return t==null||t.length===0?(this.log.trace({action:`skip`,reason:`noSkills`}),!1):n.length===0?(this.log.trace({action:`skip`,reason:`noProjects`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{skills:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};let a=this.getGlobalSkillsDir();for(let i of t){if(i.dirFromWorkspacePath==null)continue;let t=this.joinPath(i.dirFromWorkspacePath.basePath,i.dirFromWorkspacePath.path,Rv);for(let o of n){let n=o.yamlFrontMatter.name,s=this.joinPath(a,n),c=this.joinPath(t,n),l={pathKind:L.Relative,path:this.joinPath(Rv,n),basePath:this.joinPath(i.dirFromWorkspacePath.basePath,i.dirFromWorkspacePath.path),getDirectoryName:()=>n,getAbsolutePath:()=>c};if(e.dryRun===!0){this.log.trace({action:`dryRun`,type:`symlink`,target:s,link:c}),r.push({path:l,success:!0,skipped:!1});continue}try{this.createSymlink(s,c,`dir`),this.log.trace({action:`symlink`,type:`skill`,target:s,link:c}),r.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`symlink`,type:`skill`,target:s,link:c,error:t}),r.push({path:l,success:!1,error:e})}}}return{files:r,dirs:i}}async writeGlobalOutputs(e){let{skills:t}=e.collectedInputContext,n=[],r=[];if(t==null||t.length===0)return{files:n,dirs:r};let i=this.getGlobalSkillsDir();for(let r of t){let t=await this.writeSkill(e,r,i);n.push(...t)}return{files:n,dirs:r}}async writeSkill(e,t,n){let r=[],i=t.yamlFrontMatter.name,a=this.joinPath(n,i),o=this.joinPath(a,Bv),s={pathKind:L.Relative,path:Bv,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildSkillFrontMatter(t),l=t.content,u=Ig(c,l);if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skill`,path:o}),r.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(a),this.writeFileSync(o,u),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:o,error:t}),r.push({path:s,success:!1,error:e})}if(t.mcpConfig!=null){let n=await this.writeMcpConfig(e,t,a);r.push(n)}if(t.childDocs!=null)for(let n of t.childDocs){let t=await this.writeChildDoc(e,n,a,i);r.push(t)}if(t.resources!=null)for(let n of t.resources){let t=await this.writeResource(e,n,a,i);r.push(t)}return r}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,...t.displayName!=null&&{displayName:t.displayName},...t.keywords!=null&&t.keywords.length>0&&{keywords:t.keywords},...t.author!=null&&{author:t.author},...t.version!=null&&{version:t.version},...t.allowTools!=null&&t.allowTools.length>0&&{allowTools:t.allowTools}}}async writeMcpConfig(e,t,n){let r=t.yamlFrontMatter.name,i=this.joinPath(n,Vv),a={pathKind:L.Relative,path:Vv,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i},o=t.mcpConfig.rawContent;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfig`,path:i}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(i,o),this.log.trace({action:`write`,type:`mcpConfig`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`mcpConfig`,path:i,error:t}),{path:a,success:!1,error:e}}}async writeChildDoc(e,t,n,r){let i=t.relativePath.replace(/\.mdx$/,`.md`),a=this.joinPath(n,i),o={pathKind:L.Relative,path:i,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=t.content;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`childDoc`,path:a}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`childDoc`,path:a}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`childDoc`,path:a,error:t}),{path:o,success:!1,error:e}}}async writeResource(e,t,n,r){let i=this.joinPath(n,t.relativePath),a={pathKind:L.Relative,path:t.relativePath,basePath:n,getDirectoryName:()=>r,getAbsolutePath:()=>i};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`resource`,path:i}),{path:a,success:!0,skipped:!1};try{let e=this.dirname(i);if(this.ensureDirectory(e),t.encoding===`base64`){let e=d.from(t.content,`base64`);this.writeFileSyncBuffer(i,e)}else this.writeFileSync(i,t.content);return this.log.trace({action:`write`,type:`resource`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`resource`,path:i,error:t}),{path:a,success:!1,error:e}}}},Uv=class extends Ug{options;constructor(e,t){super(e),this.options=t??{}}transformContent(e){return e}collect(e){let{shadowProjectDir:t}=this.resolveBasePaths(e.userConfigOptions),n=this.getFilePath(t);if(!e.fs.existsSync(n))return this.options.fallbackContent==null?(this.log.debug({action:`collect`,message:`File not found`,path:n}),{}):(this.log.debug({action:`collect`,message:`Using fallback content`,path:n}),{[this.getResultKey()]:this.transformContent(this.options.fallbackContent)});let r=e.fs.readFileSync(n,`utf8`);return r.length===0?this.options.fallbackContent==null?(this.log.debug({action:`collect`,message:`File is empty`,path:n}),{}):(this.log.debug({action:`collect`,message:`File empty, using fallback`,path:n}),{[this.getResultKey()]:this.transformContent(this.options.fallbackContent)}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:n,length:r.length}),{[this.getResultKey()]:this.transformContent(r)})}},Wv=class extends Uv{constructor(){super(`GitExcludeInputPlugin`)}getFilePath(e){return i.join(e,`public`,`exclude`)}getResultKey(){return`shadowGitExclude`}};function Gv(e){let t=i.join(e,`.git`);if(!r.existsSync(t))return null;let n=r.lstatSync(t);if(n.isDirectory())return i.join(t,`info`);if(n.isFile())try{let n=r.readFileSync(t,`utf8`).trim(),a=/^gitdir: (.+)$/.exec(n);if(a?.[1]!=null){let t=i.resolve(e,a[1]);return i.join(t,`info`)}}catch{}return null}function Kv(e,t=5){let n=[],a=new Set([`node_modules`,`.turbo`,`dist`,`build`,`out`,`.cache`]);function o(s,c){if(c>t)return;let l;try{let e=r.readdirSync(s,{withFileTypes:!0});if(!Array.isArray(e))return;l=e}catch{return}l.some(e=>e.name===`.git`)&&s!==e&&n.push(s);for(let e of l)e.isDirectory()&&(e.name===`.git`||a.has(e.name)||o(i.join(s,e.name),c+1))}return o(e,0),n}function qv(e){let t=i.join(e,`modules`);if(!r.existsSync(t))return[];let n=[];function a(e){let t;try{let n=r.readdirSync(e,{withFileTypes:!0});if(!Array.isArray(n))return;t=n}catch{return}if(t.some(e=>e.name===`info`&&e.isDirectory())&&n.push(i.join(e,`info`)),t.find(e=>e.name===`modules`&&e.isDirectory())==null)return;let o;try{let t=r.readdirSync(i.join(e,`modules`),{withFileTypes:!0});if(!Array.isArray(t))return;o=t}catch{return}for(let t of o)t.isDirectory()&&a(i.join(e,`modules`,t.name))}let o;try{let e=r.readdirSync(t,{withFileTypes:!0});if(!Array.isArray(e))return n;o=e}catch{return n}for(let e of o)e.isDirectory()&&a(i.join(t,e.name));return n}var Jv=class extends Bg{constructor(){super(`GitExcludeOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n){if(e.dirFromWorkspacePath==null||e.isPromptSourceProject===!0)continue;let n=e.dirFromWorkspacePath,r=n.getAbsolutePath(),{basePath:a}=n,o=[r,...Kv(r)];for(let e of o){let n=Gv(e);if(n==null)continue;let r=i.join(n,`exclude`),o=i.relative(a,r);t.push({pathKind:L.Relative,path:o,basePath:a,getDirectoryName:()=>i.basename(e),getAbsolutePath:()=>r})}}let a=e.collectedInputContext.workspace.directory.path,o=i.join(a,`.git`);if(r.existsSync(o)&&r.lstatSync(o).isDirectory())for(let e of qv(o)){let n=i.join(e,`exclude`),r=i.relative(a,n);t.push({pathKind:L.Relative,path:r,basePath:a,getDirectoryName:()=>i.basename(i.dirname(e)),getAbsolutePath:()=>n})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{globalGitIgnore:t,shadowGitExclude:n}=e.collectedInputContext;if(!(t!=null&&t.length>0||n!=null&&n.length>0))return this.log.debug({action:`canWrite`,result:!1,reason:`No gitignore or exclude content found`}),!1;let{projects:r}=e.collectedInputContext.workspace,i=r.some(e=>{if(e.dirFromWorkspacePath==null)return!1;let t=e.dirFromWorkspacePath.getAbsolutePath();return Gv(t)==null?Kv(t).some(e=>Gv(e)!=null):!0}),a=e.collectedInputContext.workspace.directory.path,o=Gv(a)!=null,s=i||o;return this.log.debug({action:`canWrite`,result:s,hasGitProjects:i,hasWorkspaceGit:o,reason:s?`Found git repositories to update`:`No git repositories found`}),s}async writeProjectOutputs(e){let t=[],{globalGitIgnore:n,shadowGitExclude:a}=e.collectedInputContext,o=this.buildManagedContent(n,a);if(o.length===0)return this.log.debug({action:`write`,message:`No gitignore or exclude content found, skipping`}),{files:[],dirs:[]};let{workspace:s}=e.collectedInputContext,{projects:c}=s,l=new Set;for(let n of c){if(n.dirFromWorkspacePath==null)continue;let r=n.dirFromWorkspacePath.getAbsolutePath(),a=[r,...Kv(r)];for(let s of a){let a=Gv(s);if(a==null)continue;let c=i.join(a,`exclude`);if(l.has(c))continue;l.add(c);let u=s===r?`project:${n.name??`unknown`}`:`nested:${i.relative(r,s)}`;this.log.trace({action:`write`,path:c,label:u});let d=await this.writeGitExcludeFile(e,c,o,u);t.push(d)}}let u=s.directory.path,d=Gv(u);if(d!=null){let n=i.join(d,`exclude`);if(!l.has(n)){this.log.trace({action:`write`,path:n,target:`workspace`});let r=await this.writeGitExcludeFile(e,n,o,`workspace`);t.push(r),l.add(n)}}let f=Kv(u);for(let n of f){let r=Gv(n);if(r==null)continue;let a=i.join(r,`exclude`);if(l.has(a))continue;l.add(a);let s=`workspace-nested:${i.relative(u,n)}`;this.log.trace({action:`write`,path:a,label:s});let c=await this.writeGitExcludeFile(e,a,o,s);t.push(c)}let p=i.join(u,`.git`);if(r.existsSync(p)&&r.lstatSync(p).isDirectory())for(let n of qv(p)){let r=i.join(n,`exclude`);if(l.has(r))continue;l.add(r);let a=`git-module:${i.relative(p,n)}`;this.log.trace({action:`write`,path:r,label:a});let s=await this.writeGitExcludeFile(e,r,o,a);t.push(s)}return{files:t,dirs:[]}}buildManagedContent(e,t){let n=[];if(e!=null&&e.trim().length>0){let t=this.sanitizeContent(e);t.length>0&&n.push(t)}if(t!=null&&t.trim().length>0){let e=this.sanitizeContent(t);e.length>0&&n.push(e)}return n.length===0?``:n.join(`
1233
1233
  `)}sanitizeContent(e){return e.split(/\r?\n/).filter(e=>{let t=e.trim();return t.length===0?!0:!(t.startsWith(`#`)&&!t.startsWith(`\\#`))}).join(`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@truenine/memory-sync-cli",
3
3
  "type": "module",
4
- "version": "2026.10218.12326",
4
+ "version": "2026.10219.10049",
5
5
  "description": "TrueNine Memory Synchronization CLI",
6
6
  "author": "TrueNine",
7
7
  "license": "AGPL-3.0-only",
@@ -53,10 +53,10 @@
53
53
  "fast-check": "^4.5.3",
54
54
  "tsx": "^4.21.0",
55
55
  "typescript": "^5.9.3",
56
- "@truenine/desk-paths": "1.0.0",
57
56
  "@truenine/init-bundle": "1.0.0",
58
- "@truenine/logger": "1.0.0",
59
- "@truenine/md-compiler": "1.0.0"
57
+ "@truenine/desk-paths": "1.0.0",
58
+ "@truenine/md-compiler": "1.0.0",
59
+ "@truenine/logger": "1.0.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "run-s build:deps check bundle",