@truenine/memory-sync-cli 2026.10202.10343 → 2026.10202.10348
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 +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -607,7 +607,7 @@ API 接口 (Spring WebFlux 6.2)
|
|
|
607
607
|
- \`controllers/\`: 控制器
|
|
608
608
|
- \`dto/\`: 数据传输对象
|
|
609
609
|
\`\`\`
|
|
610
|
-
`};const bt=Object.fromEntries(vt.map(e=>[e,{path:e,content:yt[e]??``}])),xt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`,SHADOW_SOURCE_PROJECT:`$SHADOW_SOURCE_PROJECT`},St=JSON.parse(bt[`public/tnmsc.example.json`].content),M={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`},N={red:e=>`${M.red}${e}${M.reset}`,yellow:e=>`${M.yellow}${e}${M.reset}`,cyan:e=>`${M.cyan}${e}${M.reset}`,magenta:e=>`${M.magenta}${e}${M.reset}`,gray:e=>`${M.gray}${e}${M.reset}`,blue:e=>`${M.blue}${e}${M.reset}`,green:e=>`${M.green}${e}${M.reset}`,white:e=>`${M.white}${e}${M.reset}`,dim:e=>`${M.dim}${e}${M.reset}`,bgRed:e=>`${M.bgRed}${e}${M.reset}`};let Ct;const wt={error:N.red,warn:N.yellow,info:N.cyan,debug:N.magenta,trace:N.gray,fatal:N.bgRed},Tt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Et(e){if(e===null)return N.dim(`null`);if(e===void 0)return N.dim(`undefined`);if(typeof e==`boolean`)return N.yellow(String(e));if(typeof e==`number`)return N.blue(String(e));if(typeof e==`string`)return N.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Et(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 Dt(t)}return typeof e==`object`?Dt(e):String(e)}function Dt(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?N.magenta(e):N.yellow(`"${e}"`)}:${Et(t)}`).join(`,`)}}`}function Ot(){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 kt(e,t,n,r){let i=Ot(),a=wt[e]??N.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=Dt({...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 At(e,t,n){let r=Tt[e],i=Tt[n];return(n,...a)=>r>i?{$:[Ot(),e,t],_:n}:typeof n==`string`?kt(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?kt(e,t,``,n):kt(e,t,n)}function jt(e){Ct=e}function Mt(){return Ct}function Nt(e,t){let n=t??Ct??d.default.env.LOG_LEVEL??`info`;return{error:At(`error`,e,n),warn:At(`warn`,e,n),info:At(`info`,e,n),debug:At(`debug`,e,n),trace:At(`trace`,e,n),fatal:At(`fatal`,e,n)}}const Pt=`.tnmsc.json`,Ft=`.aindex`;function It(){return p.join(m.homedir(),Ft,Pt)}function Lt(){return{...St}}function Rt(e,t){let n=It(),r=p.dirname(n);f.existsSync(r)||f.mkdirSync(r,{recursive:!0}),f.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}var zt=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Pt,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=Nt(`ConfigLoader`)}getSearchPaths(e=d.default.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(p.join(e,this.configFileName)),this.searchGlobal&&t.push(p.join(m.homedir(),Ft,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!f.existsSync(t))return{config:{},source:null,found:!1};let e=f.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=d.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=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));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(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}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`)}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=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?p.join(m.homedir(),e.slice(1)):e}};let Bt=null;function Vt(e){return(e||!Bt)&&(Bt=new zt(e)),Bt}function Ht(e){return Vt().load(e)}function Ut(){let e=Nt(`ConfigLoader`),t=It();if(!f.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),Rt(Lt(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=f.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}),Gt(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}),Gt(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}),Gt(t,e,[`Config must be a JSON object`]);let i=Wt(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return Gt(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function Wt(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);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(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}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 Gt(e,t,n){try{f.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return Rt(Lt(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const Kt=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function qt(e){return Kt.includes(e)}function Jt(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Yt(){return p.join(m.homedir(),Ft,Pt)}function Xt(){let e=Yt();if(!f.existsSync(e))return{};try{let t=f.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Zt(e){let t=Yt(),n=p.dirname(t);f.existsSync(n)||f.mkdirSync(n,{recursive:!0}),f.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}var Qt=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: ${Kt.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=Xt(),r=[],i=[];for(let[e,a]of this.options){if(!qt(e)){r.push(`Invalid key: ${e} (valid keys: ${Kt.join(`, `)})`);continue}if(e===`logLevel`&&!Jt(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Zt(n),t.info(`global config written`,{path:Yt()})),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}}};let $t=function(e){return e.Input=`Input`,e.Output=`Output`,e}({}),en=function(e){return e.GlobalMemory=`GlobalMemory`,e.ProjectRootMemory=`ProjectRootMemory`,e.ProjectChildrenMemory=`ProjectChildrenMemory`,e.FastCommand=`FastCommand`,e.SubAgent=`SubAgent`,e.Skill=`Skill`,e.SkillChildDoc=`SkillChildDoc`,e.SkillResource=`SkillResource`,e.SkillMcpConfig=`SkillMcpConfig`,e.Readme=`Readme`,e}({}),tn=function(e){return e.Red=`Red`,e.Green=`Green`,e.Blue=`Blue`,e.Yellow=`Yellow`,e}({}),nn=function(e){return e.Read=`Read`,e.Write=`Write`,e.Edit=`Edit`,e.Grep=`Grep`,e}({}),rn=function(e){return e.CamelCase=`CamelCase`,e.PascalCase=`PascalCase`,e.SnakeCase=`SnakeCase`,e.KebabCase=`KebabCase`,e.UpperCase=`UpperCase`,e.LowerCase=`LowerCase`,e.Original=`Original`,e}({}),an=function(e){return e.UserHome=`UserHome`,e.External=`External`,e}({}),P=function(e){return e.Relative=`Relative`,e.Absolute=`Absolute`,e.Root=`Root`,e}({}),F=function(e){return e.VSCode=`VSCode`,e.IntellijIDEA=`IntellijIDEA`,e.Git=`Git`,e.EditorConfig=`EditorConfig`,e.Original=`Original`,e}({});function on(e,t){let{requiredFields:n,optionalDefaults:r,filePath:i}=t,a=[],o=[];for(let t of n){let n=String(t);if(!(n in e)||e[n]==null){let e=i==null?`Missing required field "${n}"`:`Missing required field "${n}" in ${i}`;a.push(e)}}if(r!=null){for(let[t,n]of Object.entries(r))if(!(t in e)||e[t]==null){let e=i==null?`Using default value for optional field "${t}": ${JSON.stringify(n)}`:`Using default value for optional field "${t}": ${JSON.stringify(n)} in ${i}`;o.push(e)}}return{valid:a.length===0,errors:a,warnings:o}}function sn(e,t){return on(e,{requiredFields:[`name`,`description`],optionalDefaults:{enabled:!0,keywords:[]},filePath:t})}function cn(e,t){return on(e,{requiredFields:[],optionalDefaults:{},filePath:t})}function ln(e,t){return on(e,{requiredFields:[`name`,`description`],optionalDefaults:{},filePath:t})}function un(e,t){let n={...e};for(let[e,r]of Object.entries(t))(!(e in n)||n[e]==null)&&(n[e]=r);return n}const dn=`.kt,.java,.py,.pyi,.pyx,.ts,.tsx,.js,.jsx,.mjs,.cjs,.go,.rs,.c,.cpp,.cc,.h,.hpp,.hxx,.cs,.fs,.fsx,.vb,.rb,.php,.swift,.scala,.groovy,.lua,.r,.R,.jl,.ex,.exs,.erl,.clj,.cljs,.hs,.ml,.mli,.nim,.zig,.v,.dart,.vue,.svelte,.sql,.json,.jsonc,.json5,.xml,.xsd,.xsl,.xslt,.yaml,.yml,.toml,.csv,.tsv,.graphql,.gql,.proto,.txt,.text,.rtf,.log,.ini,.conf,.cfg,.config,.properties,.env,.envrc,.editorconfig,.gitignore,.gitattributes,.npmrc,.nvmrc,.npmignore,.eslintrc,.prettierrc,.stylelintrc,.babelrc,.browserslistrc,.sh,.bash,.zsh,.fish,.ps1,.psm1,.psd1,.bat,.cmd,.html,.htm,.xhtml,.css,.scss,.sass,.less,.styl,.svg,.ejs,.hbs,.mustache,.pug,.jade,.jinja,.jinja2,.j2,.erb,.haml,.slim,.d.ts,.d.mts,.d.cts,.diff,.patch,.asm,.s,.makefile,.mk,.dockerfile,.tf,.tfvars,.prisma,.mdx`.split(`,`),fn=`.docx,.doc,.xlsx,.xls,.pptx,.ppt,.pdf,.odt,.ods,.odp,.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff,.zip,.tar,.gz,.bz2,.7z,.rar,.pyd,.pyc,.pyo,.class,.jar,.war,.dll,.so,.dylib,.exe,.bin,.wasm,.ttf,.otf,.woff,.woff2,.eot,.mp3,.wav,.ogg,.mp4,.webm,.db,.sqlite,.sqlite3`.split(`,`),I={SRC:`src`,DIST:`dist`,SKILLS:`skills`,COMMANDS:`commands`,AGENTS:`agents`,APP:`app`,IDEA:`.idea`,IDEA_CODE_STYLES:`.idea/codeStyles`,VSCODE:`.vscode`},L={GLOBAL_MEMORY:`global.mdx`,GLOBAL_MEMORY_SRC:`global.cn.mdx`,EDITOR_CONFIG:`.editorconfig`,IDEA_GITIGNORE:`.idea/.gitignore`,IDEA_PROJECT_XML:`.idea/codeStyles/Project.xml`,IDEA_CODE_STYLE_CONFIG_XML:`.idea/codeStyles/codeStyleConfig.xml`,VSCODE_SETTINGS:`.vscode/settings.json`,VSCODE_EXTENSIONS:`.vscode/extensions.json`,QODER_IGNORE:`.qoderignore`,CURSOR_IGNORE:`.cursorignore`,WARP_INDEX_IGNORE:`.warpindexignore`,AI_IGNORE:`.aiignore`},pn={SRC_SKILLS:`src/skills`,SRC_COMMANDS:`src/commands`,SRC_AGENTS:`src/agents`,SRC_GLOBAL_MEMORY:`app/global.cn.mdx`,DIST_SKILLS:`dist/skills`,DIST_COMMANDS:`dist/commands`,DIST_AGENTS:`dist/agents`,DIST_APP:`dist/app`,DIST_GLOBAL_MEMORY:`dist/global.mdx`,APP:`app`},mn={src:{skills:{name:I.SKILLS,required:!1,description:`Skill source files (.cn.mdx)`},commands:{name:I.COMMANDS,required:!1,description:`Fast command source files (.cn.mdx)`},agents:{name:I.AGENTS,required:!1,description:`Sub-agent source files (.cn.mdx)`},globalMemoryFile:{name:L.GLOBAL_MEMORY_SRC,required:!1,description:`Global memory source file`}},dist:{skills:{name:I.SKILLS,required:!1,description:`Compiled skill files (.mdx)`},commands:{name:I.COMMANDS,required:!1,description:`Compiled fast command files (.mdx)`},agents:{name:I.AGENTS,required:!1,description:`Compiled sub-agent files (.mdx)`},globalMemoryFile:{name:L.GLOBAL_MEMORY,required:!1,description:`Compiled global memory file`},app:{name:I.APP,required:!1,description:`Compiled project-specific prompts`}},app:{name:I.APP,required:!1,description:`Project-specific prompts (standalone directory)`},ide:{idea:{name:I.IDEA,required:!1,description:`JetBrains IDE configuration directory`},ideaCodeStyles:{name:I.IDEA_CODE_STYLES,required:!1,description:`JetBrains IDE code styles directory`},vscode:{name:I.VSCODE,required:!1,description:`VS Code configuration directory`}},ideFiles:[{name:L.EDITOR_CONFIG,required:!1,description:`EditorConfig file`},{name:L.IDEA_GITIGNORE,required:!1,description:`JetBrains IDE .gitignore`},{name:L.IDEA_PROJECT_XML,required:!1,description:`JetBrains IDE Project.xml`},{name:L.IDEA_CODE_STYLE_CONFIG_XML,required:!1,description:`JetBrains IDE codeStyleConfig.xml`},{name:L.VSCODE_SETTINGS,required:!1,description:`VS Code settings.json`},{name:L.VSCODE_EXTENSIONS,required:!1,description:`VS Code extensions.json`}],ignoreFiles:[{name:L.QODER_IGNORE,required:!1,description:`Qoder ignore file`},{name:L.CURSOR_IGNORE,required:!1,description:`Cursor ignore file`},{name:L.WARP_INDEX_IGNORE,required:!1,description:`Warp index ignore file`},{name:L.AI_IGNORE,required:!1,description:`AI ignore file`}]};var hn=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 ct(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 pt(n,await lt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await ut(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=p.isAbsolute(n)?n:p.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=p.isAbsolute(e)?e:p.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},gn=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 dt(n,i),o=await ft(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`}}},_n=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await gt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await dt(n,o),c=await ft(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 vn(){return`2026.10202.10343`}var yn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${vn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const R=`tnmsc`,bn=`
|
|
610
|
+
`};const bt=Object.fromEntries(vt.map(e=>[e,{path:e,content:yt[e]??``}])),xt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`,SHADOW_SOURCE_PROJECT:`$SHADOW_SOURCE_PROJECT`},St=JSON.parse(bt[`public/tnmsc.example.json`].content),M={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`},N={red:e=>`${M.red}${e}${M.reset}`,yellow:e=>`${M.yellow}${e}${M.reset}`,cyan:e=>`${M.cyan}${e}${M.reset}`,magenta:e=>`${M.magenta}${e}${M.reset}`,gray:e=>`${M.gray}${e}${M.reset}`,blue:e=>`${M.blue}${e}${M.reset}`,green:e=>`${M.green}${e}${M.reset}`,white:e=>`${M.white}${e}${M.reset}`,dim:e=>`${M.dim}${e}${M.reset}`,bgRed:e=>`${M.bgRed}${e}${M.reset}`};let Ct;const wt={error:N.red,warn:N.yellow,info:N.cyan,debug:N.magenta,trace:N.gray,fatal:N.bgRed},Tt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Et(e){if(e===null)return N.dim(`null`);if(e===void 0)return N.dim(`undefined`);if(typeof e==`boolean`)return N.yellow(String(e));if(typeof e==`number`)return N.blue(String(e));if(typeof e==`string`)return N.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Et(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 Dt(t)}return typeof e==`object`?Dt(e):String(e)}function Dt(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?N.magenta(e):N.yellow(`"${e}"`)}:${Et(t)}`).join(`,`)}}`}function Ot(){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 kt(e,t,n,r){let i=Ot(),a=wt[e]??N.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=Dt({...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 At(e,t,n){let r=Tt[e],i=Tt[n];return(n,...a)=>r>i?{$:[Ot(),e,t],_:n}:typeof n==`string`?kt(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?kt(e,t,``,n):kt(e,t,n)}function jt(e){Ct=e}function Mt(){return Ct}function Nt(e,t){let n=t??Ct??d.default.env.LOG_LEVEL??`info`;return{error:At(`error`,e,n),warn:At(`warn`,e,n),info:At(`info`,e,n),debug:At(`debug`,e,n),trace:At(`trace`,e,n),fatal:At(`fatal`,e,n)}}const Pt=`.tnmsc.json`,Ft=`.aindex`;function It(){return p.join(m.homedir(),Ft,Pt)}function Lt(){return{...St}}function Rt(e,t){let n=It(),r=p.dirname(n);f.existsSync(r)||f.mkdirSync(r,{recursive:!0}),f.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}var zt=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Pt,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=Nt(`ConfigLoader`)}getSearchPaths(e=d.default.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(p.join(e,this.configFileName)),this.searchGlobal&&t.push(p.join(m.homedir(),Ft,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!f.existsSync(t))return{config:{},source:null,found:!1};let e=f.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=d.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=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));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(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}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`)}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=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?p.join(m.homedir(),e.slice(1)):e}};let Bt=null;function Vt(e){return(e||!Bt)&&(Bt=new zt(e)),Bt}function Ht(e){return Vt().load(e)}function Ut(){let e=Nt(`ConfigLoader`),t=It();if(!f.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),Rt(Lt(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=f.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}),Gt(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}),Gt(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}),Gt(t,e,[`Config must be a JSON object`]);let i=Wt(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return Gt(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function Wt(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);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(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}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 Gt(e,t,n){try{f.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return Rt(Lt(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const Kt=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function qt(e){return Kt.includes(e)}function Jt(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Yt(){return p.join(m.homedir(),Ft,Pt)}function Xt(){let e=Yt();if(!f.existsSync(e))return{};try{let t=f.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Zt(e){let t=Yt(),n=p.dirname(t);f.existsSync(n)||f.mkdirSync(n,{recursive:!0}),f.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}var Qt=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: ${Kt.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=Xt(),r=[],i=[];for(let[e,a]of this.options){if(!qt(e)){r.push(`Invalid key: ${e} (valid keys: ${Kt.join(`, `)})`);continue}if(e===`logLevel`&&!Jt(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Zt(n),t.info(`global config written`,{path:Yt()})),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}}};let $t=function(e){return e.Input=`Input`,e.Output=`Output`,e}({}),en=function(e){return e.GlobalMemory=`GlobalMemory`,e.ProjectRootMemory=`ProjectRootMemory`,e.ProjectChildrenMemory=`ProjectChildrenMemory`,e.FastCommand=`FastCommand`,e.SubAgent=`SubAgent`,e.Skill=`Skill`,e.SkillChildDoc=`SkillChildDoc`,e.SkillResource=`SkillResource`,e.SkillMcpConfig=`SkillMcpConfig`,e.Readme=`Readme`,e}({}),tn=function(e){return e.Red=`Red`,e.Green=`Green`,e.Blue=`Blue`,e.Yellow=`Yellow`,e}({}),nn=function(e){return e.Read=`Read`,e.Write=`Write`,e.Edit=`Edit`,e.Grep=`Grep`,e}({}),rn=function(e){return e.CamelCase=`CamelCase`,e.PascalCase=`PascalCase`,e.SnakeCase=`SnakeCase`,e.KebabCase=`KebabCase`,e.UpperCase=`UpperCase`,e.LowerCase=`LowerCase`,e.Original=`Original`,e}({}),an=function(e){return e.UserHome=`UserHome`,e.External=`External`,e}({}),P=function(e){return e.Relative=`Relative`,e.Absolute=`Absolute`,e.Root=`Root`,e}({}),F=function(e){return e.VSCode=`VSCode`,e.IntellijIDEA=`IntellijIDEA`,e.Git=`Git`,e.EditorConfig=`EditorConfig`,e.Original=`Original`,e}({});function on(e,t){let{requiredFields:n,optionalDefaults:r,filePath:i}=t,a=[],o=[];for(let t of n){let n=String(t);if(!(n in e)||e[n]==null){let e=i==null?`Missing required field "${n}"`:`Missing required field "${n}" in ${i}`;a.push(e)}}if(r!=null){for(let[t,n]of Object.entries(r))if(!(t in e)||e[t]==null){let e=i==null?`Using default value for optional field "${t}": ${JSON.stringify(n)}`:`Using default value for optional field "${t}": ${JSON.stringify(n)} in ${i}`;o.push(e)}}return{valid:a.length===0,errors:a,warnings:o}}function sn(e,t){return on(e,{requiredFields:[`name`,`description`],optionalDefaults:{enabled:!0,keywords:[]},filePath:t})}function cn(e,t){return on(e,{requiredFields:[],optionalDefaults:{},filePath:t})}function ln(e,t){return on(e,{requiredFields:[`name`,`description`],optionalDefaults:{},filePath:t})}function un(e,t){let n={...e};for(let[e,r]of Object.entries(t))(!(e in n)||n[e]==null)&&(n[e]=r);return n}const dn=`.kt,.java,.py,.pyi,.pyx,.ts,.tsx,.js,.jsx,.mjs,.cjs,.go,.rs,.c,.cpp,.cc,.h,.hpp,.hxx,.cs,.fs,.fsx,.vb,.rb,.php,.swift,.scala,.groovy,.lua,.r,.R,.jl,.ex,.exs,.erl,.clj,.cljs,.hs,.ml,.mli,.nim,.zig,.v,.dart,.vue,.svelte,.sql,.json,.jsonc,.json5,.xml,.xsd,.xsl,.xslt,.yaml,.yml,.toml,.csv,.tsv,.graphql,.gql,.proto,.txt,.text,.rtf,.log,.ini,.conf,.cfg,.config,.properties,.env,.envrc,.editorconfig,.gitignore,.gitattributes,.npmrc,.nvmrc,.npmignore,.eslintrc,.prettierrc,.stylelintrc,.babelrc,.browserslistrc,.sh,.bash,.zsh,.fish,.ps1,.psm1,.psd1,.bat,.cmd,.html,.htm,.xhtml,.css,.scss,.sass,.less,.styl,.svg,.ejs,.hbs,.mustache,.pug,.jade,.jinja,.jinja2,.j2,.erb,.haml,.slim,.d.ts,.d.mts,.d.cts,.diff,.patch,.asm,.s,.makefile,.mk,.dockerfile,.tf,.tfvars,.prisma,.mdx`.split(`,`),fn=`.docx,.doc,.xlsx,.xls,.pptx,.ppt,.pdf,.odt,.ods,.odp,.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff,.zip,.tar,.gz,.bz2,.7z,.rar,.pyd,.pyc,.pyo,.class,.jar,.war,.dll,.so,.dylib,.exe,.bin,.wasm,.ttf,.otf,.woff,.woff2,.eot,.mp3,.wav,.ogg,.mp4,.webm,.db,.sqlite,.sqlite3`.split(`,`),I={SRC:`src`,DIST:`dist`,SKILLS:`skills`,COMMANDS:`commands`,AGENTS:`agents`,APP:`app`,IDEA:`.idea`,IDEA_CODE_STYLES:`.idea/codeStyles`,VSCODE:`.vscode`},L={GLOBAL_MEMORY:`global.mdx`,GLOBAL_MEMORY_SRC:`global.cn.mdx`,EDITOR_CONFIG:`.editorconfig`,IDEA_GITIGNORE:`.idea/.gitignore`,IDEA_PROJECT_XML:`.idea/codeStyles/Project.xml`,IDEA_CODE_STYLE_CONFIG_XML:`.idea/codeStyles/codeStyleConfig.xml`,VSCODE_SETTINGS:`.vscode/settings.json`,VSCODE_EXTENSIONS:`.vscode/extensions.json`,QODER_IGNORE:`.qoderignore`,CURSOR_IGNORE:`.cursorignore`,WARP_INDEX_IGNORE:`.warpindexignore`,AI_IGNORE:`.aiignore`},pn={SRC_SKILLS:`src/skills`,SRC_COMMANDS:`src/commands`,SRC_AGENTS:`src/agents`,SRC_GLOBAL_MEMORY:`app/global.cn.mdx`,DIST_SKILLS:`dist/skills`,DIST_COMMANDS:`dist/commands`,DIST_AGENTS:`dist/agents`,DIST_APP:`dist/app`,DIST_GLOBAL_MEMORY:`dist/global.mdx`,APP:`app`},mn={src:{skills:{name:I.SKILLS,required:!1,description:`Skill source files (.cn.mdx)`},commands:{name:I.COMMANDS,required:!1,description:`Fast command source files (.cn.mdx)`},agents:{name:I.AGENTS,required:!1,description:`Sub-agent source files (.cn.mdx)`},globalMemoryFile:{name:L.GLOBAL_MEMORY_SRC,required:!1,description:`Global memory source file`}},dist:{skills:{name:I.SKILLS,required:!1,description:`Compiled skill files (.mdx)`},commands:{name:I.COMMANDS,required:!1,description:`Compiled fast command files (.mdx)`},agents:{name:I.AGENTS,required:!1,description:`Compiled sub-agent files (.mdx)`},globalMemoryFile:{name:L.GLOBAL_MEMORY,required:!1,description:`Compiled global memory file`},app:{name:I.APP,required:!1,description:`Compiled project-specific prompts`}},app:{name:I.APP,required:!1,description:`Project-specific prompts (standalone directory)`},ide:{idea:{name:I.IDEA,required:!1,description:`JetBrains IDE configuration directory`},ideaCodeStyles:{name:I.IDEA_CODE_STYLES,required:!1,description:`JetBrains IDE code styles directory`},vscode:{name:I.VSCODE,required:!1,description:`VS Code configuration directory`}},ideFiles:[{name:L.EDITOR_CONFIG,required:!1,description:`EditorConfig file`},{name:L.IDEA_GITIGNORE,required:!1,description:`JetBrains IDE .gitignore`},{name:L.IDEA_PROJECT_XML,required:!1,description:`JetBrains IDE Project.xml`},{name:L.IDEA_CODE_STYLE_CONFIG_XML,required:!1,description:`JetBrains IDE codeStyleConfig.xml`},{name:L.VSCODE_SETTINGS,required:!1,description:`VS Code settings.json`},{name:L.VSCODE_EXTENSIONS,required:!1,description:`VS Code extensions.json`}],ignoreFiles:[{name:L.QODER_IGNORE,required:!1,description:`Qoder ignore file`},{name:L.CURSOR_IGNORE,required:!1,description:`Cursor ignore file`},{name:L.WARP_INDEX_IGNORE,required:!1,description:`Warp index ignore file`},{name:L.AI_IGNORE,required:!1,description:`AI ignore file`}]};var hn=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 ct(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 pt(n,await lt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await ut(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=p.isAbsolute(n)?n:p.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=p.isAbsolute(e)?e:p.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},gn=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 dt(n,i),o=await ft(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`}}},_n=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await gt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await dt(n,o),c=await ft(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 vn(){return`2026.10202.10348`}var yn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${vn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const R=`tnmsc`,bn=`
|
|
611
611
|
${R} v${vn()} - Memory Sync CLI
|
|
612
612
|
|
|
613
613
|
Synchronize AI memory and configuration files across projects.
|
|
@@ -661,7 +661,7 @@ CONFIG OPTIONS:
|
|
|
661
661
|
CONFIGURATION:
|
|
662
662
|
Configure via plugin.config.ts in your project root.
|
|
663
663
|
See documentation for detailed configuration options.
|
|
664
|
-
`.trim();var xn=class{name=`help`;async execute(e){return console.log(bn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Sn(e,t){let n=p.join(e,`.git`),r=f.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 Cn(e,t,n,r,i){if(n==null)return r;let a=p.relative(t,e),o=p.join(n,a);return f.existsSync(o)&&f.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),f.readFileSync(o,`utf8`)):r}function wn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;f.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(f.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(bt)){let o=t.path,l=p.join(e,o),u=p.dirname(l);if(!f.existsSync(u)){f.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=p.dirname(t)}if(f.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=Cn(l,e,n,t.content,r);f.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 Tn(e,t,n){let r=e;return r=r.replace(xt.SHADOW_SOURCE_PROJECT,n),r=r.replace(xt.WORKSPACE,t),r.startsWith(`~`)&&(r=p.join(m.homedir(),r.slice(1))),p.normalize(r)}var En=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Tn(n.workspaceDir,``,``),i=wn(Tn(n.shadowSourceProjectDir,r,``),{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}}};function Dn(){return`@truenine/memory-sync-cli`}function On(){return`https://registry.npmjs.org/${Dn()}/latest`}function kn(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 An(e,t){let n=kn(e),r=kn(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 jn=3e3;async function Mn(){let e=new AbortController,t=setTimeout(()=>e.abort(),jn);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(On(),{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 ${jn}ms`}:{error:e.message}:{error:`Unknown network error`}}}function Nn(){return`2026.10202.10343`}async function Pn(){let e=Nn();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await Mn();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=An(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 Fn(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Dn()}@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 In(){return new Date().getMinutes()%2==0}function Ln(e){In()&&Pn().then(t=>{(t.status===`outdated`||t.error!=null)&&Fn(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var Rn=class{name=`outdated`;async execute(e){let t=await Pn();return Fn(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},zn=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 Bn={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 Vn=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}({}),Hn=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var Un=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=m.platform();return{platform:e,arch:m.arch(),hostname:m.hostname(),homedir:m.homedir(),tmpdir:m.tmpdir(),type:m.type(),release:m.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return Hn.Win;case`darwin`:return Hn.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return Hn.Linux;default:return Hn.Unknown}}detectShellKind(){let e=(d.default.env.SHELL??d.default.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?Vn.Bash:e.includes(`zsh`)?Vn.Zsh:e.includes(`fish`)?Vn.Fish:e.includes(`pwsh`)?Vn.Pwsh:e.includes(`powershell`)?Vn.PowerShell:e.includes(`cmd`)?Vn.Cmd:e.endsWith(`/sh`)?Vn.Sh:Vn.Unknown}collectEnvContext(){return{...d.default.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...Bn.default};return this.toolPreset===`claudeCode`?{...e,...Bn.claudeCode}:this.toolPreset===`kiro`?{...e,...Bn.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let Wn=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 Gn=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=Wn.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 Kn(e){let t=[...e],n=t[0];n!=null&&qn(n)&&t.shift();let r=t[0];return r!=null&&Jn(r)&&t.shift(),t}function qn(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 Jn(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const Yn=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`]),Xn=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),Zn=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function Qn(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=Zn.get(n)??4;for(let e of t){let t=Zn.get(e)??4;t<r&&(r=t,n=e)}return n}function $n(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new yn;if(t)return new xn;if(a!=null)return new zn(a);if(r===`version`)return new yn;if(r===`help`)return new xn;if(r===`outdated`)return new Rn;if(r===`init`)return new En;if(r===`dry-run`)return new gn;if(r===`clean`)return i?new hn:new _t;if(r!==`config`||o.length>0)return new _n;let c=[];for(let e of s){let t=e.indexOf(`=`);t>0&&c.push([e.slice(0,t),e.slice(t+1)])}return new Qt([...o,...c])}function er(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!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=Xn.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`--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;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,Yn.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var tr=class{logger;args;outputPlugins=[];constructor(...e){this.args=er(Kn(e.filter(e=>e!=null)));let t=Qn(this.args);t!=null&&jt(t),this.logger=Nt(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){Ln(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return $n(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:f,path:p,glob:tt.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:f,path:p,glob:tt.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 u.l(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 u.a(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 Un({userConfig:r}).collect(),o=new Gn;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,Wn.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.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],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?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills: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 nr={...St,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[]};function rr(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function ir(...e){return e.reduce((e,t)=>ar(e,t),{...nr})}function ar(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:or(e.excludePatterns,i),fastCommandSeriesOptions:sr(e.fastCommandSeriesOptions,a)}}function or(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function sr(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 cr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function lr(e={}){Ut().shouldExit&&d.default.exit(1);let t,n,r;cr(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=Ht(n);a=e.found,o=e.sources,e.found&&(i=rr(e.config),s=e.config)}let c=ir(i,r),{plugins:l=[],logLevel:u}=c,m=Nt(`defineConfig`,u);a?m.info(`user config loaded`,{sources:o}):m.info(`no user config found, using defaults`,{workspaceDir:nr.workspaceDir,shadowSourceProjectDir:nr.shadowSourceProjectDir,shadowSkillSourceDir:nr.shadowSkillSourceDir,shadowFastCommandDir:nr.shadowFastCommandDir,shadowSubAgentDir:nr.shadowSubAgentDir,globalMemoryFile:nr.globalMemoryFile,shadowProjectsDir:nr.shadowProjectsDir,logLevel:nr.logLevel});let h={logger:m,userConfigOptions:c,fs:f,path:p,glob:tt.default},g=l.filter(e=>e.type===$t.Input),_=l.filter(e=>e.type===$t.Output),v=await new tr().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.externalProjects!=null&&{externalProjects:v.externalProjects},...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...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&&Sn(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:c}}const z=_r(/[A-Za-z]/),B=_r(/[\dA-Za-z]/),ur=_r(/[#-'*+\--9=?A-Z^-~]/);function dr(e){return e!==null&&(e<32||e===127)}const fr=_r(/\d/),pr=_r(/[\dA-Fa-f]/),mr=_r(/[!-/:-@[-`{-~]/);function V(e){return e!==null&&e<-2}function H(e){return e!==null&&(e<0||e===32)}function U(e){return e===-2||e===-1||e===32}const hr=_r(/\p{P}|\p{S}/u),gr=_r(/\s/);function _r(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var vr=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 yr=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,vr.default)(t,...n))}}const xr={}.hasOwnProperty,Sr={yaml:`-`,toml:`+`};function Cr(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(!xr.call(Sr,t))throw yr("Missing matter definition for `%s`",t);t={type:t,marker:Sr[t]}}else if(typeof t!=`object`)throw yr("Expected matter to be an object, not `%j`",t);if(!xr.call(t,`type`))throw yr("Missing `type` in matter `%j`",t);if(!xr.call(t,`fence`)&&!xr.call(t,`marker`))throw yr("Missing `marker` or `fence` in matter `%j`",t);return t}function Tr(e){let t=Cr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=Dr(e,`open`).charCodeAt(0),a=Er(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Er(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=Dr(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),U(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return U(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return V(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=Dr(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||V(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||V(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),U(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return U(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||V(i)?(e.exit(r),t(i)):n(i)}}}function Dr(e,t){return e.marker?Or(e.marker,t).repeat(3):Or(e.fence,t)}function Or(e,t){return typeof e==`string`?e:e[t]}function kr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Ar(e){let t=Cr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=jr(e),r[e.type]=Mr,r[e.type+`Value`]=Nr}return{enter:n,exit:r}}function jr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Mr(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 Nr(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function Pr(e){let t=[],n={},r=Cr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=Fr(e);let a=Ir(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:kr(a.charAt(1))})}return{unsafe:t,handlers:n}}function Fr(e){let t=Ir(e,`open`),n=Ir(e,`close`);return r;function r(e){return t+(e.value?`
|
|
664
|
+
`.trim();var xn=class{name=`help`;async execute(e){return console.log(bn),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Sn(e,t){let n=p.join(e,`.git`),r=f.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 Cn(e,t,n,r,i){if(n==null)return r;let a=p.relative(t,e),o=p.join(n,a);return f.existsSync(o)&&f.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),f.readFileSync(o,`utf8`)):r}function wn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;f.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(f.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(bt)){let o=t.path,l=p.join(e,o),u=p.dirname(l);if(!f.existsSync(u)){f.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=p.dirname(t)}if(f.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=Cn(l,e,n,t.content,r);f.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 Tn(e,t,n){let r=e;return r=r.replace(xt.SHADOW_SOURCE_PROJECT,n),r=r.replace(xt.WORKSPACE,t),r.startsWith(`~`)&&(r=p.join(m.homedir(),r.slice(1))),p.normalize(r)}var En=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Tn(n.workspaceDir,``,``),i=wn(Tn(n.shadowSourceProjectDir,r,``),{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}}};function Dn(){return`@truenine/memory-sync-cli`}function On(){return`https://registry.npmjs.org/${Dn()}/latest`}function kn(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 An(e,t){let n=kn(e),r=kn(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 jn=3e3;async function Mn(){let e=new AbortController,t=setTimeout(()=>e.abort(),jn);typeof t==`object`&&`unref`in t&&t.unref();try{let n=await fetch(On(),{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 ${jn}ms`}:{error:e.message}:{error:`Unknown network error`}}}function Nn(){return`2026.10202.10348`}async function Pn(){let e=Nn();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await Mn();if(`error`in t)return{status:`current`,localVersion:e,remoteVersion:null,error:t.error};let n=t.version,r=An(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 Fn(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g ${Dn()}@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 In(){return new Date().getMinutes()%2==0}function Ln(e){In()&&Pn().then(t=>{(t.status===`outdated`||t.error!=null)&&Fn(t,e)}).catch(t=>{let n=t instanceof Error?t.message:`Unknown error`;e.error(`Version check failed: ${n}`)})}var Rn=class{name=`outdated`;async execute(e){let t=await Pn();return Fn(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}},zn=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 Bn={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 Vn=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}({}),Hn=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var Un=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=m.platform();return{platform:e,arch:m.arch(),hostname:m.hostname(),homedir:m.homedir(),tmpdir:m.tmpdir(),type:m.type(),release:m.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return Hn.Win;case`darwin`:return Hn.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return Hn.Linux;default:return Hn.Unknown}}detectShellKind(){let e=(d.default.env.SHELL??d.default.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?Vn.Bash:e.includes(`zsh`)?Vn.Zsh:e.includes(`fish`)?Vn.Fish:e.includes(`pwsh`)?Vn.Pwsh:e.includes(`powershell`)?Vn.PowerShell:e.includes(`cmd`)?Vn.Cmd:e.endsWith(`/sh`)?Vn.Sh:Vn.Unknown}collectEnvContext(){return{...d.default.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...Bn.default};return this.toolPreset===`claudeCode`?{...e,...Bn.claudeCode}:this.toolPreset===`kiro`?{...e,...Bn.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let Wn=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 Gn=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=Wn.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 Kn(e){let t=[...e],n=t[0];n!=null&&qn(n)&&t.shift();let r=t[0];return r!=null&&Jn(r)&&t.shift(),t}function qn(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 Jn(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const Yn=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`]),Xn=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),Zn=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function Qn(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=Zn.get(n)??4;for(let e of t){let t=Zn.get(e)??4;t<r&&(r=t,n=e)}return n}function $n(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new yn;if(t)return new xn;if(a!=null)return new zn(a);if(r===`version`)return new yn;if(r===`help`)return new xn;if(r===`outdated`)return new Rn;if(r===`init`)return new En;if(r===`dry-run`)return new gn;if(r===`clean`)return i?new hn:new _t;if(r!==`config`||o.length>0)return new _n;let c=[];for(let e of s){let t=e.indexOf(`=`);t>0&&c.push([e.slice(0,t),e.slice(t+1)])}return new Qt([...o,...c])}function er(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!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=Xn.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`--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;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,Yn.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var tr=class{logger;args;outputPlugins=[];constructor(...e){this.args=er(Kn(e.filter(e=>e!=null)));let t=Qn(this.args);t!=null&&jt(t),this.logger=Nt(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){Ln(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return $n(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:f,path:p,glob:tt.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:f,path:p,glob:tt.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 u.l(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 u.a(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 Un({userConfig:r}).collect(),o=new Gn;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,Wn.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.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],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?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills: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 nr={...St,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[]};function rr(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function ir(...e){return e.reduce((e,t)=>ar(e,t),{...nr})}function ar(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:or(e.excludePatterns,i),fastCommandSeriesOptions:sr(e.fastCommandSeriesOptions,a)}}function or(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function sr(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 cr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function lr(e={}){Ut().shouldExit&&d.default.exit(1);let t,n,r;cr(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=Ht(n);a=e.found,o=e.sources,e.found&&(i=rr(e.config),s=e.config)}let c=ir(i,r),{plugins:l=[],logLevel:u}=c,m=Nt(`defineConfig`,u);a?m.info(`user config loaded`,{sources:o}):m.info(`no user config found, using defaults`,{workspaceDir:nr.workspaceDir,shadowSourceProjectDir:nr.shadowSourceProjectDir,shadowSkillSourceDir:nr.shadowSkillSourceDir,shadowFastCommandDir:nr.shadowFastCommandDir,shadowSubAgentDir:nr.shadowSubAgentDir,globalMemoryFile:nr.globalMemoryFile,shadowProjectsDir:nr.shadowProjectsDir,logLevel:nr.logLevel});let h={logger:m,userConfigOptions:c,fs:f,path:p,glob:tt.default},g=l.filter(e=>e.type===$t.Input),_=l.filter(e=>e.type===$t.Output),v=await new tr().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.externalProjects!=null&&{externalProjects:v.externalProjects},...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...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&&Sn(v.shadowSourceProjectDir,m),{context:y,outputPlugins:_,userConfigOptions:c}}const z=_r(/[A-Za-z]/),B=_r(/[\dA-Za-z]/),ur=_r(/[#-'*+\--9=?A-Z^-~]/);function dr(e){return e!==null&&(e<32||e===127)}const fr=_r(/\d/),pr=_r(/[\dA-Fa-f]/),mr=_r(/[!-/:-@[-`{-~]/);function V(e){return e!==null&&e<-2}function H(e){return e!==null&&(e<0||e===32)}function U(e){return e===-2||e===-1||e===32}const hr=_r(/\p{P}|\p{S}/u),gr=_r(/\s/);function _r(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var vr=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 yr=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,vr.default)(t,...n))}}const xr={}.hasOwnProperty,Sr={yaml:`-`,toml:`+`};function Cr(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(!xr.call(Sr,t))throw yr("Missing matter definition for `%s`",t);t={type:t,marker:Sr[t]}}else if(typeof t!=`object`)throw yr("Expected matter to be an object, not `%j`",t);if(!xr.call(t,`type`))throw yr("Missing `type` in matter `%j`",t);if(!xr.call(t,`fence`)&&!xr.call(t,`marker`))throw yr("Missing `marker` or `fence` in matter `%j`",t);return t}function Tr(e){let t=Cr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=Dr(e,`open`).charCodeAt(0),a=Er(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Er(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=Dr(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),U(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return U(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return V(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=Dr(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||V(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||V(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),U(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return U(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||V(i)?(e.exit(r),t(i)):n(i)}}}function Dr(e,t){return e.marker?Or(e.marker,t).repeat(3):Or(e.fence,t)}function Or(e,t){return typeof e==`string`?e:e[t]}function kr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Ar(e){let t=Cr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=jr(e),r[e.type]=Mr,r[e.type+`Value`]=Nr}return{enter:n,exit:r}}function jr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Mr(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 Nr(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function Pr(e){let t=[],n={},r=Cr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=Fr(e);let a=Ir(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:kr(a.charAt(1))})}return{unsafe:t,handlers:n}}function Fr(e){let t=Ir(e,`open`),n=Ir(e,`close`);return r;function r(e){return t+(e.value?`
|
|
665
665
|
`+e.value:``)+`
|
|
666
666
|
`+n}}function Ir(e,t){return e.marker?Lr(e.marker,t).repeat(3):Lr(e.fence,t)}function Lr(e,t){return typeof e==`string`?e:e[t]}function Rr(e){let t=this,n=e||`yaml`,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Tr(n)),a.push(Ar(n)),o.push(Pr(n))}function zr(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 Br=(function(e){if(e==null)return Gr;if(typeof e==`function`)return Wr(e);if(typeof e==`object`)return Array.isArray(e)?Vr(e):Hr(e);if(typeof e==`string`)return Ur(e);throw Error(`Expected function, string, or object as test`)});function Vr(e){let t=[],n=-1;for(;++n<e.length;)t[n]=Br(e[n]);return Wr(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}function Hr(e){let t=e;return Wr(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function Ur(e){return Wr(t);function t(t){return t&&t.type===e}}function Wr(e){return t;function t(t,n,r){return!!(Kr(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function Gr(){return!0}function Kr(e){return typeof e==`object`&&!!e&&`type`in e}function qr(e){return`\x1B[33m`+e+`\x1B[39m`}const Jr=[];function Yr(e,t,n,r){let i;typeof t==`function`&&typeof n!=`function`?(r=n,n=t):i=t;let a=Br(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 (`+qr(e.type+(t?`<`+t+`>`:``))+`)`})}return u;function u(){let l=Jr,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=Xr(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 Xr(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?Jr:[e]}function Zr(e,t,n){let r=Br((n||{}).ignore||[]),i=Qr(t),a=-1;for(;++a<i.length;)Yr(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 Qr(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([$r(e[0]),ei(e[1])])}return t}function $r(e){return typeof e==`string`?new RegExp(kr(e),`g`):e}function ei(e){return typeof e==`function`?e:function(){return e}}const ti=`phrasing`,ni=[`autolink`,`link`,`image`,`label`];function ri(){return{transforms:[di],enter:{literalAutolink:ai,literalAutolinkEmail:oi,literalAutolinkHttp:oi,literalAutolinkWww:oi},exit:{literalAutolink:ui,literalAutolinkEmail:li,literalAutolinkHttp:si,literalAutolinkWww:ci}}}function ii(){return{unsafe:[{character:`@`,before:`[+\\-.\\w]`,after:`[\\-.\\w]`,inConstruct:ti,notInConstruct:ni},{character:`.`,before:`[Ww]`,after:`[\\-.\\w]`,inConstruct:ti,notInConstruct:ni},{character:`:`,before:`[ps]`,after:`\\/`,inConstruct:ti,notInConstruct:ni}]}}function ai(e){this.enter({type:`link`,title:null,url:``,children:[]},e)}function oi(e){this.config.enter.autolinkProtocol.call(this,e)}function si(e){this.config.exit.autolinkProtocol.call(this,e)}function ci(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 li(e){this.config.exit.autolinkEmail.call(this,e)}function ui(e){this.exit(e)}function di(e){Zr(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,fi],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,pi]],{ignore:[`link`,`linkReference`]})}function fi(e,t,n,r,i){let a=``;if(!gi(i)||(/^w/i.test(t)&&(n=t+n,t=``,a=`http://`),!mi(n)))return!1;let o=hi(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 pi(e,t,n,r){return!gi(r,!0)||/[-\d_]$/.test(n)?!1:{type:`link`,title:null,url:`mailto:`+t+`@`+n,children:[{type:`text`,value:t+`@`+n}]}}function mi(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 hi(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=zr(e,`(`),a=zr(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 gi(e,t){let n=e.input.charCodeAt(e.index-1);return(e.index===0||gr(n)||hr(n))&&(!t||n!==47)}function _i(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}Di.peek=Ei;function vi(){this.buffer()}function yi(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function bi(){this.buffer()}function xi(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Si(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=_i(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ci(e){this.exit(e)}function wi(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=_i(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ti(e){this.exit(e)}function Ei(){return`[`}function Di(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 Oi(){return{enter:{gfmFootnoteCallString:vi,gfmFootnoteCall:yi,gfmFootnoteDefinitionLabelString:bi,gfmFootnoteDefinition:xi},exit:{gfmFootnoteCallString:Si,gfmFootnoteCall:Ci,gfmFootnoteDefinitionLabelString:wi,gfmFootnoteDefinition:Ti}}}function ki(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:Di},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?`
|
|
667
667
|
`:` `)+r.indentLines(r.containerFlow(e,a.current()),t?ji:Ai))),s(),o}}function Ai(e,t,n){return t===0?e:ji(e,t,n)}function ji(e,t,n){return(n?``:` `)+e}const Mi=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`];Li.peek=Ri;function Ni(){return{canContainEols:[`delete`],enter:{strikethrough:Fi},exit:{strikethrough:Ii}}}function Pi(){return{unsafe:[{character:`~`,inConstruct:`phrasing`,notInConstruct:Mi}],handlers:{delete:Li}}}function Fi(e){this.enter({type:`delete`,children:[]},e)}function Ii(e){this.exit(e)}function Li(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 Ri(){return`~`}function zi(e){return e.length}function Bi(e,t){let n=t||{},r=(n.align||[]).concat(),i=n.stringLength||zi,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=Vi(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]=Hi(r[d]);else{let e=Hi(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(`
|
|
@@ -798,7 +798,7 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
798
798
|
`,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())}}}})),Td=o((e=>{var t=_d(),n=ed(),r=td(),i=Tu(),a=Y(),o=Cd(),s=wd();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})),Ed=l(o((e=>{var t=_d(),n=ed(),r=Qu(),i=td(),a=_u(),o=Y(),s=Ou(),c=X(),l=Au(),u=Mu();xd();var d=Sd(),f=Cd(),p=wd(),m=Td(),h=du();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 Dd(e,t){let n=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!=null));return Object.keys(n).length===0?`---
|
|
799
799
|
---`:`---\n${Ed.stringify(n,{singleQuote:t?.singleQuote??!1,lineWidth:t?.lineWidth??0}).trimEnd()}\n---`}function Od(e,t,n){return e==null||Object.keys(e).length===0?t:`${Dd(e,n)}\n${t}`}function kd(e){let t=tu().use(zl).use(Xc).use(Rr,[`yaml`]).parse(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){let t=e;r=t.value;try{n=Ed.parse(t.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 Ad(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 jd=class{type;name;_log;get log(){return this._log??=Nt(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}},Z=class extends jd{globalConfigDir;outputFileName;registryWriterCache=new Map;writeEffects=[];cleanEffects=[];constructor(e,t){super(e,$t.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``}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===P.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:P.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let n;n=e.pathKind===P.Absolute?e.path:this.isRelativePath(e)?p.resolve(e.basePath,e.path):p.resolve(d.default.cwd(),e.path);let r=t??this.outputFileName;return r?p.join(n,r):n}createRelativePath(e,t,n){return{pathKind:P.Relative,path:e,basePath:t,getDirectoryName:n,getAbsolutePath:()=>p.join(t,e)}}createFileRelativePath(e,t){let n=p.join(e.path,t);return{pathKind:P.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>e.getDirectoryName(),getAbsolutePath:()=>p.join(e.basePath,n)}}getGlobalConfigDir(){return p.join(this.getHomeDir(),this.globalConfigDir)}getHomeDir(){return m.homedir()}joinPath(...e){return p.join(...e)}resolvePath(...e){return p.resolve(...e)}dirname(e){return p.dirname(e)}basename(e,t){return p.basename(e,t)}writeFileSync(e,t,n=`utf8`){f.writeFileSync(e,t,n)}writeFileSyncBuffer(e,t){f.writeFileSync(e,t)}ensureDirectory(e){f.existsSync(e)||f.mkdirSync(e,{recursive:!0})}existsSync(e){return f.existsSync(e)}lstatSync(e){return rt(e)}isSymlink(e){return nt(e)}createSymlink(e,t,n=`dir`){at(e,t,n)}removeSymlink(e){ot(e)}readdirSync(e,t){return t?.withFileTypes===!0?f.readdirSync(e,{withFileTypes:!0}):f.readdirSync(e)}async writeFile(e,t,n,r){let i=p.dirname(t),a=p.basename(t),o={pathKind:P.Relative,path:a,basePath:i,getDirectoryName:()=>p.basename(i),getAbsolutePath:()=>t};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`file`,path:t,label:r}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(i),f.writeFileSync(t,n,`utf8`),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{let e=p.dirname(i);return this.ensureDirectory(e),f.writeFileSync(i,n,`utf8`),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 Od(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Od(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=`
|
|
800
800
|
|
|
801
|
-
`,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 Md=`AGENTS.md`;var Nd=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Md})}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,Md)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Md));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}}},Q=class extends jd{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,$t.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:h.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.shadowSourceProjectDir;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(xt.USER_HOME)&&(r=r.replace(xt.USER_HOME,m.homedir())),r.includes(xt.SHADOW_SOURCE_PROJECT)&&(r=r.replace(xt.SHADOW_SOURCE_PROJECT,n)),r.includes(xt.WORKSPACE)&&(r=r.replace(xt.WORKSPACE,t)),p.normalize(r)}readAndParseMarkdown(e,t){return kd(t.readFileSync(e,`utf8`))}};const Pd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Fd=class extends Q{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 Pd){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 Id=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Ld=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}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)for(let n of Id){let r=p.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>p.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>p.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t?.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,r){let i=p.join(t.path,n.fileName),a=p.join(t.basePath,i),o={pathKind:P.Relative,path:i,basePath:t.basePath,getDirectoryName:()=>p.basename(t.path),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{return f.writeFileSync(a,n.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}};const Rd=`.agent`,zd=`.gemini`,Bd=`antigravity`,Vd=`skills`,Hd=`workflows`,Ud=`mcp_config.json`,Wd=[Vd,Hd];var Gd=class extends Z{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Rd,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=p.join(m.homedir(),zd,Bd),n=p.join(t,Ud),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp_config.json to empty shell`};try{return this.ensureDirectory(t),f.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp_config.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_config.json`}}})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Wd){let r=p.join(e.dirFromWorkspacePath.path,Rd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>p.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{skills:n,fastCommands:r}=e.collectedInputContext,i=p.join(m.homedir(),zd,Bd);if(n!=null)for(let e of n){let n=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),r=p.join(i,Vd,n);if(t.push({pathKind:P.Relative,path:`SKILL.md`,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>p.join(r,`SKILL.md`)}),e.childDocs!=null)for(let i of e.childDocs){let e=i.dir.path.replace(/\.mdx$/,`.md`),a=p.join(r,e);t.push({pathKind:P.Relative,path:e,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>a})}if(e.resources!=null)for(let i of e.resources){let e=p.join(r,i.relativePath);t.push({pathKind:P.Relative,path:i.relativePath,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>e})}}if(n?.some(e=>e.mcpConfig!=null)??!1){let e=p.join(i,Ud);t.push({pathKind:P.Relative,path:Ud,basePath:i,getDirectoryName:()=>Bd,getAbsolutePath:()=>e})}if(r==null)return t;let a=this.getTransformOptionsFromContext(e),o=p.join(i,Hd);for(let e of r){let n=this.transformFastCommandName(e,a),r=p.join(o,n);t.push({pathKind:P.Relative,path:n,basePath:o,getDirectoryName:()=>Hd,getAbsolutePath:()=>r})}return t}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=(t?.length??0)>0,i=(n?.length??0)>0;return r||i?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=[],a=p.join(m.homedir(),zd,Bd),o=p.join(a,Hd),s=p.join(a,Vd);if(t!=null)for(let n of t){let t=await this.writeFastCommand(e,o,n);r.push(...t)}if(n!=null){for(let t of n){let n=await this.writeSkill(e,s,t);r.push(...n)}let t=await this.writeGlobalMcpConfig(e,a,n);t!=null&&r.push(t)}return this.log.info({action:`write`,message:`Synced ${r.length} files to global directory`,files:r.length,globalDir:a}),{files:r,dirs:i}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,n]of Object.entries(t))r[e]=this.transformMcpConfigForAntigravity({...n})}if(Object.keys(r).length===0)return null;let i=p.join(t,Ud),a={pathKind:P.Relative,path:Ud,basePath:t,getDirectoryName:()=>Bd,getAbsolutePath:()=>i},o={mcpServers:r},s=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(t),f.writeFileSync(i,s),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).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}}}transformMcpConfigForAntigravity(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.httpUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=p.join(t,a),s={pathKind:P.Relative,path:a,basePath:t,getDirectoryName:()=>Hd,getAbsolutePath:()=>o},c=n.content,l=n.yamlFrontMatter,u=typeof l?.description==`string`?{description:l.description}:{},d=e=>this.buildMarkdownContentWithRaw(e,u,n.rawFrontMatter);if(c=n.rawMdxContent==null?d(c):d(n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``)),e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:o}),[{path:s,success:!0,skipped:!1}];try{this.ensureDirectory(t),f.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`fastCommand`,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:`fastCommand`,path:o,error:t}),r.push({path:s,success:!1,error:e})}return r}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=p.join(t,i),o=p.join(a,`SKILL.md`),s={pathKind:P.Relative,path:`SKILL.md`,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),f.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0}),n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,t);r.push(...n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,a,i,t);r.push(...n)}}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})}return r}async writeSkillReferenceDocument(e,t,n,r){let i=[],a=r.dir.path.replace(/\.mdx$/,`.md`),o=p.join(t,a),s={pathKind:P.Relative,path:a,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=p.dirname(o);this.ensureDirectory(e),f.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:o}),i.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:o,error:t}),i.push({path:s,success:!1,error:e})}return i}async writeSkillResource(e,t,n,r){let i=[],a=p.join(t,r.relativePath),o={pathKind:P.Relative,path:r.relativePath,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:a}),[{path:o,success:!0,skipped:!1}];try{let e=p.dirname(a);this.ensureDirectory(e),f.writeFileSync(a,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:a}),i.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:a,error:t}),i.push({path:o,success:!1,error:e})}return i}};function Kd(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=qd(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 qd(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=Jd(i,e);if(o!=null)try{let e=Yd(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=Jd(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=Yd(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 Jd(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===`
|
|
801
|
+
`,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 Md=`AGENTS.md`;var Nd=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Md})}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,Md)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Md));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}}},Q=class extends jd{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,$t.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:h.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.shadowSourceProjectDir;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(xt.USER_HOME)&&(r=r.replace(xt.USER_HOME,m.homedir())),r.includes(xt.SHADOW_SOURCE_PROJECT)&&(r=r.replace(xt.SHADOW_SOURCE_PROJECT,n)),r.includes(xt.WORKSPACE)&&(r=r.replace(xt.WORKSPACE,t)),p.normalize(r)}readAndParseMarkdown(e,t){return kd(t.readFileSync(e,`utf8`))}};const Pd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Fd=class extends Q{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 Pd){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 Id=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Ld=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}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)for(let n of Id){let r=p.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>p.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>p.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t?.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,r){let i=p.join(t.path,n.fileName),a=p.join(t.basePath,i),o={pathKind:P.Relative,path:i,basePath:t.basePath,getDirectoryName:()=>p.basename(t.path),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{return f.writeFileSync(a,n.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}};const Rd=`.agent`,zd=`.gemini`,Bd=`antigravity`,Vd=`skills`,Hd=`workflows`,Ud=`mcp_config.json`,Wd=[Vd,Hd];var Gd=class extends Z{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:Rd,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=p.join(m.homedir(),zd,Bd),n=p.join(t,Ud),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp_config.json to empty shell`};try{return this.ensureDirectory(t),f.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp_config.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_config.json`}}})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Wd){let r=p.join(e.dirFromWorkspacePath.path,Rd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>p.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{skills:n,fastCommands:r}=e.collectedInputContext,i=p.join(m.homedir(),zd,Bd);if(n!=null)for(let e of n){let n=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),r=p.join(i,Vd,n);if(t.push({pathKind:P.Relative,path:`SKILL.md`,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>p.join(r,`SKILL.md`)}),e.childDocs!=null)for(let i of e.childDocs){let e=i.dir.path.replace(/\.mdx$/,`.md`),a=p.join(r,e);t.push({pathKind:P.Relative,path:e,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>a})}if(e.resources!=null)for(let i of e.resources){let e=p.join(r,i.relativePath);t.push({pathKind:P.Relative,path:i.relativePath,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>e})}}if(n?.some(e=>e.mcpConfig!=null)??!1){let e=p.join(i,Ud);t.push({pathKind:P.Relative,path:Ud,basePath:i,getDirectoryName:()=>Bd,getAbsolutePath:()=>e})}if(r==null)return t;let a=this.getTransformOptionsFromContext(e),o=p.join(i,Hd);for(let e of r){let n=this.transformFastCommandName(e,a),r=p.join(o,n);t.push({pathKind:P.Relative,path:n,basePath:o,getDirectoryName:()=>Hd,getAbsolutePath:()=>r})}return t}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=(t?.length??0)>0,i=(n?.length??0)>0;return r||i?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=[],a=p.join(m.homedir(),zd,Bd),o=p.join(a,Hd),s=p.join(a,Vd);if(t!=null)for(let n of t){let t=await this.writeFastCommand(e,o,n);r.push(...t)}if(n!=null){for(let t of n){let n=await this.writeSkill(e,s,t);r.push(...n)}let t=await this.writeGlobalMcpConfig(e,a,n);t!=null&&r.push(t)}return this.log.info({action:`write`,message:`Synced ${r.length} files to global directory`,files:r.length,globalDir:a}),{files:r,dirs:i}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,n]of Object.entries(t))r[e]=this.transformMcpConfigForAntigravity({...n})}if(Object.keys(r).length===0)return null;let i=p.join(t,Ud),a={pathKind:P.Relative,path:Ud,basePath:t,getDirectoryName:()=>Bd,getAbsolutePath:()=>i},o={mcpServers:r},s=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(t),f.writeFileSync(i,s),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).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}}}transformMcpConfigForAntigravity(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=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=p.join(t,a),s={pathKind:P.Relative,path:a,basePath:t,getDirectoryName:()=>Hd,getAbsolutePath:()=>o},c=n.content,l=n.yamlFrontMatter,u=typeof l?.description==`string`?{description:l.description}:{},d=e=>this.buildMarkdownContentWithRaw(e,u,n.rawFrontMatter);if(c=n.rawMdxContent==null?d(c):d(n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``)),e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:o}),[{path:s,success:!0,skipped:!1}];try{this.ensureDirectory(t),f.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`fastCommand`,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:`fastCommand`,path:o,error:t}),r.push({path:s,success:!1,error:e})}return r}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=p.join(t,i),o=p.join(a,`SKILL.md`),s={pathKind:P.Relative,path:`SKILL.md`,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),f.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0}),n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,t);r.push(...n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,a,i,t);r.push(...n)}}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})}return r}async writeSkillReferenceDocument(e,t,n,r){let i=[],a=r.dir.path.replace(/\.mdx$/,`.md`),o=p.join(t,a),s={pathKind:P.Relative,path:a,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=p.dirname(o);this.ensureDirectory(e),f.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:o}),i.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:o,error:t}),i.push({path:s,success:!1,error:e})}return i}async writeSkillResource(e,t,n,r){let i=[],a=p.join(t,r.relativePath),o={pathKind:P.Relative,path:r.relativePath,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:a}),[{path:o,success:!0,skipped:!1}];try{let e=p.dirname(a);this.ensureDirectory(e),f.writeFileSync(a,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:a}),i.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:a,error:t}),i.push({path:o,success:!1,error:e})}return i}};function Kd(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=qd(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 qd(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=Jd(i,e);if(o!=null)try{let e=Yd(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=Jd(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=Yd(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 Jd(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===`
|
|
802
802
|
`){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 Yd(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 Xd(r.slice(1,-1),`"`);if(r.startsWith(`'`)&&r.endsWith(`'`))return Xd(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 Xd(e,"`")}if(r.startsWith(`[`)&&r.endsWith(`]`))return Qd(r,t,n);if(r.startsWith(`{`)&&r.endsWith(`}`))return $d(r,t,n);if(/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r))return Zd(r,t,n);let i=n==null?``:` in file "${n}"`;throw Error(`Expression "${r}" cannot be statically evaluated${i}`)}function Xd(e,t){return e.replaceAll(`\\n`,`
|
|
803
803
|
`).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function Zd(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 Qd(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=ef(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return tf(r).map(e=>Yd(e.trim(),t,n))}function $d(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=ef(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=nf(r);for(let e of a){let r=rf(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]=Yd(o,t,n)}return i}function ef(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 tf(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 nf(e){return tf(e)}function rf(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 af(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=u.n(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function of(e,t,n){return!af(e,t)||e.children.length===0?[]:n(e.children,t)}async function sf(e,t){if(!af(e,t)||e.children.length===0)return[];let n=cf(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function cf(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=u.n(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=cf(r.children,t));return n}function lf(){u.i(`Md`,of),u.i(`Md.Line`,sf)}function uf(e){return tu().use(zl).use(Xc).use(Rr,[`yaml`]).use(_.default).parse(e)}lf();function df(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 ff(e,t){let n=uf(e),r=df(t?.globalScope,t?.scope),i=u.r(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Ed.parse(e.value)}catch{}a=Kd(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 u.t(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=tu().use(Rr,[`yaml`]).use(Xc).use(g.default,{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 pf=class extends Z{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){let r=p.join(t,e);n.push({pathKind:P.Relative,path:e,basePath:t,getDirectoryName:()=>e,getAbsolutePath:()=>r})}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=p.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>p.join(e.dirFromWorkspacePath.basePath,r)})}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=[{pathKind:P.Relative,path:this.outputFileName,basePath:n,getDirectoryName:()=>this.globalConfigDir,getAbsolutePath:()=>p.join(n,this.outputFileName)}],{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),i=p.join(n,this.commandsSubDir,t);r.push({pathKind:P.Relative,path:p.join(this.commandsSubDir,t),basePath:n,getDirectoryName:()=>this.commandsSubDir,getAbsolutePath:()=>i})}if(this.supportsSubAgents&&a!=null)for(let e of a){let t=e.dir.path.endsWith(`.md`)?e.dir.path:`${e.dir.path}.md`,i=p.join(n,this.agentsSubDir,t);r.push({pathKind:P.Relative,path:p.join(this.agentsSubDir,t),basePath:n,getDirectoryName:()=>this.agentsSubDir,getAbsolutePath:()=>i})}if(this.supportsSkills&&o!=null)for(let e of o){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=p.join(this.skillsSubDir,t);if(r.push({pathKind:P.Relative,path:p.join(i,`SKILL.md`),basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>p.join(n,i,`SKILL.md`)}),e.childDocs!=null)for(let a of e.childDocs){let e=a.dir.path.replace(/\.mdx$/,`.md`),o=p.join(i,e);r.push({pathKind:P.Relative,path:o,basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>p.join(n,o)})}if(e.resources!=null)for(let a of e.resources){let e=p.join(i,a.relativePath);r.push({pathKind:P.Relative,path:e,basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>p.join(n,e)})}}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=p.join(s,this.outputFileName),i={pathKind:P.Relative,path:this.outputFileName,basePath:s,getDirectoryName:()=>this.globalConfigDir,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:i,success:!0,skipped:!1});else try{this.ensureDirectory(s),f.writeFileSync(r,t.content,`utf8`),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=p.join(t,this.commandsSubDir),o=p.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 Un({toolPreset:this.toolPreset}).collect(),t=await ff(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.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,i=p.join(t,this.agentsSubDir),a=p.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=p.join(t,this.skillsSubDir,i),o=p.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=p.join(t,a);return[await this.writeFile(e,o,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,i){let a=p.join(t,r.relativePath);return[await this.writeFile(e,a,r.content,`skillResource`)]}},mf=class extends pf{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}};const hf=`AGENTS.md`,gf=`.codex`,_f=`prompts`,vf=`skills`,yf=`SKILL.md`;var bf=class extends Z{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:gf,outputFileName:hf,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=p.join(t,_f);n.push({pathKind:P.Relative,path:_f,basePath:t,getDirectoryName:()=>_f,getAbsolutePath:()=>r});let{skills:i}=e.collectedInputContext;if(i!=null&&i.length>0)for(let e of i){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=p.join(t,vf,r);n.push({pathKind:P.Relative,path:p.join(vf,r),basePath:t,getDirectoryName:()=>r,getAbsolutePath:()=>i})}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:hf,basePath:e,getDirectoryName:()=>gf,getAbsolutePath:()=>p.join(e,hf)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=t!=null,a=(n?.length??0)>0,o=(r?.length??0)>0;return i||a||o?!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=[];if(t!=null){let n=this.getGlobalConfigDir(),r=p.join(n,hf),a={pathKind:P.Relative,path:hf,basePath:n,getDirectoryName:()=>gf,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),f.writeFileSync(r,t.content,`utf8`),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.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}),i.push({path:a,success:!1,error:e})}}if(n!=null&&n.length>0){let t=this.getGlobalConfigDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);i.push(...n)}}if(r==null||r.length===0)return{files:i,dirs:a};let o=this.getGlobalConfigDir();for(let t of r){let n=await this.writeGlobalSkill(e,o,t);i.push(...n)}return{files:i,dirs:a}}async writeGlobalFastCommand(e,t,n){let r=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=p.join(t,_f),s=p.join(o,a),c={pathKind:P.Relative,path:p.join(_f,a),basePath:t,getDirectoryName:()=>_f,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{this.ensureDirectory(o),f.writeFileSync(s,l,`utf8`),this.log.trace({action:`write`,type:`globalFastCommand`,path:s}),r.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalFastCommand`,path:s,error:t}),r.push({path:c,success:!1,error:e})}return r}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=p.join(t,vf,i),o=p.join(a,yf),s={pathKind:P.Relative,path:p.join(vf,i,yf),basePath:t,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildCodexSkillContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalSkill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),f.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`globalSkill`,path:o}),r.push({path:s,success:!0}),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)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalSkill`,path:o,error:t}),r.push({path:s,success:!1,error:e})}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(` `)),Od(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}async writeSkillReferenceDocument(e,t,n,r,i){let a=[],o=r.dir.path.replace(/\.mdx$/,`.md`),s=p.join(t,o),c={pathKind:P.Relative,path:p.join(vf,n,o),basePath:i,getDirectoryName:()=>n,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:s}),[{path:c,success:!0,skipped:!1}];try{let e=p.dirname(s);this.ensureDirectory(e),f.writeFileSync(s,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:s}),a.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:s,error:t}),a.push({path:c,success:!1,error:e})}return a}async writeSkillResource(e,t,n,r,i){let a=[],o=p.join(t,r.relativePath),s={pathKind:P.Relative,path:p.join(vf,n,r.relativePath),basePath:i,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=p.dirname(o);this.ensureDirectory(e),f.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:o}),a.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:o,error:t}),a.push({path:s,success:!1,error:e})}return a}},xf=class extends pf{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=p.join(t,this.skillsSubDir,i),o=p.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}},Sf=class extends Q{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=kd(o),i=await ff(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 u.c([...t.errors],e)}let{content:d}=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 f=this.createPrompt(t.name,e,d,l,r.rawFrontMatter,r,s,o);c.push(f)}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)}},Cf=class extends Sf{constructor(){super(`FastCommandInputPlugin`,{configKey:`shadowFastCommandDir`})}getTargetDir(e,t){let n=e.shadowFastCommandDir,{workspaceDir:r,shadowProjectDir:i}=t;return this.resolvePath(n,r,i)}validateMetadata(e,t){return cn(e,t)}createResult(e){return{fastCommands:e}}extractSeriesInfo(e){let t=e.replace(/\.mdx$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.slice(0,Math.max(0,n)),commandName:t.slice(Math.max(0,n+1))}}createPrompt(e,t,n,r,i,a,o,s){let c=this.extractSeriesInfo(e);return{type:en.FastCommand,content:n,length:n.length,filePathKind:P.Relative,...r!=null&&{yamlFrontMatter:r},...i!=null&&{rawFrontMatter:i},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:P.Relative,path:e,basePath:o,getDirectoryName:()=>e.replace(/\.mdx$/,``),getAbsolutePath:()=>t},...c.series!=null&&{series:c.series},commandName:c.commandName,rawMdxContent:s}}},wf=class extends pf{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:`GEMINI.md`,supportsFastCommands:!1,supportsSubAgents:!1,supportsSkills:!1})}};const Tf=`.skills`,Ef=`.skills`,Df=`SKILL.md`,Of=`mcp.json`;var kf=class extends Z{constructor(){super(`GenericSkillsOutputPlugin`,{globalConfigDir:Ef,outputFileName:Df})}getGlobalSkillsDir(){return this.joinPath(this.getHomeDir(),Ef)}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,Tf);t.push({pathKind:P.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Tf,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,Tf);for(let i of r){let r=i.yamlFrontMatter.name,a=this.joinPath(n,r);t.push({pathKind:P.Relative,path:this.joinPath(Tf,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:P.Relative,path:Ef,basePath:this.getHomeDir(),getDirectoryName:()=>Ef,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:P.Relative,path:this.joinPath(Ef,n,Df),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Df)}),e.mcpConfig!=null&&t.push({pathKind:P.Relative,path:this.joinPath(Ef,n,Of),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Of)}),e.childDocs!=null)for(let r of e.childDocs){let e=r.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:P.Relative,path:this.joinPath(Ef,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:P.Relative,path:this.joinPath(Ef,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,Tf);for(let o of n){let n=o.yamlFrontMatter.name,s=this.joinPath(a,n),c=this.joinPath(t,n),l={pathKind:P.Relative,path:this.joinPath(Tf,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,Df),s={pathKind:P.Relative,path:Df,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildSkillFrontMatter(t),l=t.content,u=Od(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,Of),a={pathKind:P.Relative,path:Of,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:P.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:P.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=v.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}}}},Af=class extends Q{constructor(){super(`GitExcludeInputPlugin`)}collect(e){let{shadowProjectDir:t}=this.resolveBasePaths(e.userConfigOptions),n=p.join(t,`public`,`exclude`);if(!f.existsSync(n))return this.log.debug({action:`collect`,message:`No exclude file found in shadow project`,path:n}),{};let r=f.readFileSync(n,`utf8`);return r.length===0?(this.log.debug({action:`collect`,message:`Exclude file is empty`,path:n}),{}):(this.log.debug({action:`collect`,message:`Loaded git exclude from shadow project`,path:n}),{shadowGitExclude:r})}},jf=class extends Z{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(),i=p.join(r,`.git`,`info`);if(f.existsSync(i)){let e=p.join(n.path,`.git`,`info`,`exclude`),r=n.path,{basePath:i}=n;t.push({pathKind:P.Relative,path:e,basePath:i,getDirectoryName:()=>p.basename(r),getAbsolutePath:()=>p.join(i,e)})}}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=p.join(e.dirFromWorkspacePath.getAbsolutePath(),`.git`,`info`);return f.existsSync(t)}),a=p.join(e.collectedInputContext.workspace.directory.path,`.git`,`info`),o=f.existsSync(a),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;for(let n of o){if(n.dirFromWorkspacePath==null)continue;let r=n.dirFromWorkspacePath.getAbsolutePath(),a=p.join(r,`.git`,`info`),o=p.join(r,`.git`,`info`,`exclude`);if(!f.existsSync(a)){this.log.debug({action:`write`,path:o,message:`Git info directory does not exist, skipping`,project:n.name??`unknown`});continue}this.log.info({action:`write`,path:o,project:n.name??`unknown`});let s=await this.writeGitExcludeFile(e,o,i,`project:${n.name??`unknown`}`);t.push(s)}let s=a.directory.path,c=p.join(s,`.git`,`info`),l=p.join(s,`.git`,`info`,`exclude`);if(new Set(o.map(e=>e.dirFromWorkspacePath?.getAbsolutePath()).filter(Boolean)).has(s)&&f.existsSync(c))return{files:t,dirs:[]};this.log.info({action:`write`,path:l,target:`workspace`});let u=await this.writeGitExcludeFile(e,l,i,`workspace`);return t.push(u),{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(`
|
|
804
804
|
`)}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
|
@@ -607,7 +607,7 @@ API 接口 (Spring WebFlux 6.2)
|
|
|
607
607
|
- \`controllers/\`: 控制器
|
|
608
608
|
- \`dto/\`: 数据传输对象
|
|
609
609
|
\`\`\`
|
|
610
|
-
`};const It=Object.fromEntries(Pt.map(e=>[e,{path:e,content:Ft[e]??``}])),Lt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`,SHADOW_SOURCE_PROJECT:`$SHADOW_SOURCE_PROJECT`},Rt=JSON.parse(It[`public/tnmsc.example.json`].content),N={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`},P={red:e=>`${N.red}${e}${N.reset}`,yellow:e=>`${N.yellow}${e}${N.reset}`,cyan:e=>`${N.cyan}${e}${N.reset}`,magenta:e=>`${N.magenta}${e}${N.reset}`,gray:e=>`${N.gray}${e}${N.reset}`,blue:e=>`${N.blue}${e}${N.reset}`,green:e=>`${N.green}${e}${N.reset}`,white:e=>`${N.white}${e}${N.reset}`,dim:e=>`${N.dim}${e}${N.reset}`,bgRed:e=>`${N.bgRed}${e}${N.reset}`};let zt;const Bt={error:P.red,warn:P.yellow,info:P.cyan,debug:P.magenta,trace:P.gray,fatal:P.bgRed},Vt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Ht(e){if(e===null)return P.dim(`null`);if(e===void 0)return P.dim(`undefined`);if(typeof e==`boolean`)return P.yellow(String(e));if(typeof e==`number`)return P.blue(String(e));if(typeof e==`string`)return P.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Ht(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 Ut(t)}return typeof e==`object`?Ut(e):String(e)}function Ut(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?P.magenta(e):P.yellow(`"${e}"`)}:${Ht(t)}`).join(`,`)}}`}function Wt(){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 Gt(e,t,n,r){let i=Wt(),a=Bt[e]??P.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=Ut({...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 Kt(e,t,n){let r=Vt[e],i=Vt[n];return(n,...a)=>r>i?{$:[Wt(),e,t],_:n}:typeof n==`string`?Gt(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?Gt(e,t,``,n):Gt(e,t,n)}function qt(e){zt=e}function Jt(){return zt}function Yt(e,t){let n=t??zt??m.env.LOG_LEVEL??`info`;return{error:Kt(`error`,e,n),warn:Kt(`warn`,e,n),info:Kt(`info`,e,n),debug:Kt(`debug`,e,n),trace:Kt(`trace`,e,n),fatal:Kt(`fatal`,e,n)}}const Xt=`.tnmsc.json`,Zt=`.aindex`;function Qt(){return g.join(y.homedir(),Zt,Xt)}function $t(){return{...Rt}}function en(e,t){let n=Qt(),r=g.dirname(n);h.existsSync(r)||h.mkdirSync(r,{recursive:!0}),h.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}var tn=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Xt,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=Yt(`ConfigLoader`)}getSearchPaths(e=m.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(g.join(e,this.configFileName)),this.searchGlobal&&t.push(g.join(y.homedir(),Zt,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!h.existsSync(t))return{config:{},source:null,found:!1};let e=h.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=m.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=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));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(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}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`)}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=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?g.join(y.homedir(),e.slice(1)):e}};let nn=null;function rn(e){return(e||!nn)&&(nn=new tn(e)),nn}function an(e){return rn().load(e)}function on(){let e=Yt(`ConfigLoader`),t=Qt();if(!h.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),en($t(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=h.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 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}),cn(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}),cn(t,e,[`Config must be a JSON object`]);let i=sn(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return cn(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function sn(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);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(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}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{h.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return en($t(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const ln=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function un(e){return ln.includes(e)}function dn(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function fn(){return g.join(y.homedir(),Zt,Xt)}function pn(){let e=fn();if(!h.existsSync(e))return{};try{let t=h.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function mn(e){let t=fn(),n=g.dirname(t);h.existsSync(n)||h.mkdirSync(n,{recursive:!0}),h.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}var hn=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: ${ln.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=pn(),r=[],i=[];for(let[e,a]of this.options){if(!un(e)){r.push(`Invalid key: ${e} (valid keys: ${ln.join(`, `)})`);continue}if(e===`logLevel`&&!dn(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(mn(n),t.info(`global config written`,{path:fn()})),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}}};let gn=function(e){return e.Input=`Input`,e.Output=`Output`,e}({}),_n=function(e){return e.GlobalMemory=`GlobalMemory`,e.ProjectRootMemory=`ProjectRootMemory`,e.ProjectChildrenMemory=`ProjectChildrenMemory`,e.FastCommand=`FastCommand`,e.SubAgent=`SubAgent`,e.Skill=`Skill`,e.SkillChildDoc=`SkillChildDoc`,e.SkillResource=`SkillResource`,e.SkillMcpConfig=`SkillMcpConfig`,e.Readme=`Readme`,e}({}),vn=function(e){return e.Red=`Red`,e.Green=`Green`,e.Blue=`Blue`,e.Yellow=`Yellow`,e}({}),yn=function(e){return e.Read=`Read`,e.Write=`Write`,e.Edit=`Edit`,e.Grep=`Grep`,e}({}),bn=function(e){return e.CamelCase=`CamelCase`,e.PascalCase=`PascalCase`,e.SnakeCase=`SnakeCase`,e.KebabCase=`KebabCase`,e.UpperCase=`UpperCase`,e.LowerCase=`LowerCase`,e.Original=`Original`,e}({}),xn=function(e){return e.UserHome=`UserHome`,e.External=`External`,e}({}),F=function(e){return e.Relative=`Relative`,e.Absolute=`Absolute`,e.Root=`Root`,e}({}),I=function(e){return e.VSCode=`VSCode`,e.IntellijIDEA=`IntellijIDEA`,e.Git=`Git`,e.EditorConfig=`EditorConfig`,e.Original=`Original`,e}({});function Sn(e,t){let{requiredFields:n,optionalDefaults:r,filePath:i}=t,a=[],o=[];for(let t of n){let n=String(t);if(!(n in e)||e[n]==null){let e=i==null?`Missing required field "${n}"`:`Missing required field "${n}" in ${i}`;a.push(e)}}if(r!=null){for(let[t,n]of Object.entries(r))if(!(t in e)||e[t]==null){let e=i==null?`Using default value for optional field "${t}": ${JSON.stringify(n)}`:`Using default value for optional field "${t}": ${JSON.stringify(n)} in ${i}`;o.push(e)}}return{valid:a.length===0,errors:a,warnings:o}}function Cn(e,t){return Sn(e,{requiredFields:[`name`,`description`],optionalDefaults:{enabled:!0,keywords:[]},filePath:t})}function wn(e,t){return Sn(e,{requiredFields:[],optionalDefaults:{},filePath:t})}function Tn(e,t){return Sn(e,{requiredFields:[`name`,`description`],optionalDefaults:{},filePath:t})}function En(e,t){let n={...e};for(let[e,r]of Object.entries(t))(!(e in n)||n[e]==null)&&(n[e]=r);return n}const Dn=`.kt,.java,.py,.pyi,.pyx,.ts,.tsx,.js,.jsx,.mjs,.cjs,.go,.rs,.c,.cpp,.cc,.h,.hpp,.hxx,.cs,.fs,.fsx,.vb,.rb,.php,.swift,.scala,.groovy,.lua,.r,.R,.jl,.ex,.exs,.erl,.clj,.cljs,.hs,.ml,.mli,.nim,.zig,.v,.dart,.vue,.svelte,.sql,.json,.jsonc,.json5,.xml,.xsd,.xsl,.xslt,.yaml,.yml,.toml,.csv,.tsv,.graphql,.gql,.proto,.txt,.text,.rtf,.log,.ini,.conf,.cfg,.config,.properties,.env,.envrc,.editorconfig,.gitignore,.gitattributes,.npmrc,.nvmrc,.npmignore,.eslintrc,.prettierrc,.stylelintrc,.babelrc,.browserslistrc,.sh,.bash,.zsh,.fish,.ps1,.psm1,.psd1,.bat,.cmd,.html,.htm,.xhtml,.css,.scss,.sass,.less,.styl,.svg,.ejs,.hbs,.mustache,.pug,.jade,.jinja,.jinja2,.j2,.erb,.haml,.slim,.d.ts,.d.mts,.d.cts,.diff,.patch,.asm,.s,.makefile,.mk,.dockerfile,.tf,.tfvars,.prisma,.mdx`.split(`,`),On=`.docx,.doc,.xlsx,.xls,.pptx,.ppt,.pdf,.odt,.ods,.odp,.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff,.zip,.tar,.gz,.bz2,.7z,.rar,.pyd,.pyc,.pyo,.class,.jar,.war,.dll,.so,.dylib,.exe,.bin,.wasm,.ttf,.otf,.woff,.woff2,.eot,.mp3,.wav,.ogg,.mp4,.webm,.db,.sqlite,.sqlite3`.split(`,`),L={SRC:`src`,DIST:`dist`,SKILLS:`skills`,COMMANDS:`commands`,AGENTS:`agents`,APP:`app`,IDEA:`.idea`,IDEA_CODE_STYLES:`.idea/codeStyles`,VSCODE:`.vscode`},R={GLOBAL_MEMORY:`global.mdx`,GLOBAL_MEMORY_SRC:`global.cn.mdx`,EDITOR_CONFIG:`.editorconfig`,IDEA_GITIGNORE:`.idea/.gitignore`,IDEA_PROJECT_XML:`.idea/codeStyles/Project.xml`,IDEA_CODE_STYLE_CONFIG_XML:`.idea/codeStyles/codeStyleConfig.xml`,VSCODE_SETTINGS:`.vscode/settings.json`,VSCODE_EXTENSIONS:`.vscode/extensions.json`,QODER_IGNORE:`.qoderignore`,CURSOR_IGNORE:`.cursorignore`,WARP_INDEX_IGNORE:`.warpindexignore`,AI_IGNORE:`.aiignore`},kn={SRC_SKILLS:`src/skills`,SRC_COMMANDS:`src/commands`,SRC_AGENTS:`src/agents`,SRC_GLOBAL_MEMORY:`app/global.cn.mdx`,DIST_SKILLS:`dist/skills`,DIST_COMMANDS:`dist/commands`,DIST_AGENTS:`dist/agents`,DIST_APP:`dist/app`,DIST_GLOBAL_MEMORY:`dist/global.mdx`,APP:`app`},An={src:{skills:{name:L.SKILLS,required:!1,description:`Skill source files (.cn.mdx)`},commands:{name:L.COMMANDS,required:!1,description:`Fast command source files (.cn.mdx)`},agents:{name:L.AGENTS,required:!1,description:`Sub-agent source files (.cn.mdx)`},globalMemoryFile:{name:R.GLOBAL_MEMORY_SRC,required:!1,description:`Global memory source file`}},dist:{skills:{name:L.SKILLS,required:!1,description:`Compiled skill files (.mdx)`},commands:{name:L.COMMANDS,required:!1,description:`Compiled fast command files (.mdx)`},agents:{name:L.AGENTS,required:!1,description:`Compiled sub-agent files (.mdx)`},globalMemoryFile:{name:R.GLOBAL_MEMORY,required:!1,description:`Compiled global memory file`},app:{name:L.APP,required:!1,description:`Compiled project-specific prompts`}},app:{name:L.APP,required:!1,description:`Project-specific prompts (standalone directory)`},ide:{idea:{name:L.IDEA,required:!1,description:`JetBrains IDE configuration directory`},ideaCodeStyles:{name:L.IDEA_CODE_STYLES,required:!1,description:`JetBrains IDE code styles directory`},vscode:{name:L.VSCODE,required:!1,description:`VS Code configuration directory`}},ideFiles:[{name:R.EDITOR_CONFIG,required:!1,description:`EditorConfig file`},{name:R.IDEA_GITIGNORE,required:!1,description:`JetBrains IDE .gitignore`},{name:R.IDEA_PROJECT_XML,required:!1,description:`JetBrains IDE Project.xml`},{name:R.IDEA_CODE_STYLE_CONFIG_XML,required:!1,description:`JetBrains IDE codeStyleConfig.xml`},{name:R.VSCODE_SETTINGS,required:!1,description:`VS Code settings.json`},{name:R.VSCODE_EXTENSIONS,required:!1,description:`VS Code extensions.json`}],ignoreFiles:[{name:R.QODER_IGNORE,required:!1,description:`Qoder ignore file`},{name:R.CURSOR_IGNORE,required:!1,description:`Cursor ignore file`},{name:R.WARP_INDEX_IGNORE,required:!1,description:`Warp index ignore file`},{name:R.AI_IGNORE,required:!1,description:`AI ignore file`}]};var jn=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 wt(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 kt(n,await Tt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await Et(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=g.isAbsolute(n)?n:g.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=g.isAbsolute(e)?e:g.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},Mn=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 Dt(n,i),o=await Ot(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`}}},Nn=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await Mt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await Dt(n,o),c=await Ot(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 Pn(){return`2026.10202.10343`}var Fn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${Pn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const z=`tnmsc`,In=`
|
|
610
|
+
`};const It=Object.fromEntries(Pt.map(e=>[e,{path:e,content:Ft[e]??``}])),Lt={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`,SHADOW_SOURCE_PROJECT:`$SHADOW_SOURCE_PROJECT`},Rt=JSON.parse(It[`public/tnmsc.example.json`].content),N={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`},P={red:e=>`${N.red}${e}${N.reset}`,yellow:e=>`${N.yellow}${e}${N.reset}`,cyan:e=>`${N.cyan}${e}${N.reset}`,magenta:e=>`${N.magenta}${e}${N.reset}`,gray:e=>`${N.gray}${e}${N.reset}`,blue:e=>`${N.blue}${e}${N.reset}`,green:e=>`${N.green}${e}${N.reset}`,white:e=>`${N.white}${e}${N.reset}`,dim:e=>`${N.dim}${e}${N.reset}`,bgRed:e=>`${N.bgRed}${e}${N.reset}`};let zt;const Bt={error:P.red,warn:P.yellow,info:P.cyan,debug:P.magenta,trace:P.gray,fatal:P.bgRed},Vt={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Ht(e){if(e===null)return P.dim(`null`);if(e===void 0)return P.dim(`undefined`);if(typeof e==`boolean`)return P.yellow(String(e));if(typeof e==`number`)return P.blue(String(e));if(typeof e==`string`)return P.green(`"${e}"`);if(Array.isArray(e))return e.length===0?`[]`:`[${e.map(e=>Ht(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 Ut(t)}return typeof e==`object`?Ut(e):String(e)}function Ut(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?P.magenta(e):P.yellow(`"${e}"`)}:${Ht(t)}`).join(`,`)}}`}function Wt(){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 Gt(e,t,n,r){let i=Wt(),a=Bt[e]??P.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=Ut({...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 Kt(e,t,n){let r=Vt[e],i=Vt[n];return(n,...a)=>r>i?{$:[Wt(),e,t],_:n}:typeof n==`string`?Gt(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?Gt(e,t,``,n):Gt(e,t,n)}function qt(e){zt=e}function Jt(){return zt}function Yt(e,t){let n=t??zt??m.env.LOG_LEVEL??`info`;return{error:Kt(`error`,e,n),warn:Kt(`warn`,e,n),info:Kt(`info`,e,n),debug:Kt(`debug`,e,n),trace:Kt(`trace`,e,n),fatal:Kt(`fatal`,e,n)}}const Xt=`.tnmsc.json`,Zt=`.aindex`;function Qt(){return g.join(y.homedir(),Zt,Xt)}function $t(){return{...Rt}}function en(e,t){let n=Qt(),r=g.dirname(n);h.existsSync(r)||h.mkdirSync(r,{recursive:!0}),h.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf8`),t.info(`global config created`,{path:n})}var tn=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Xt,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=Yt(`ConfigLoader`)}getSearchPaths(e=m.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(g.join(e,this.configFileName)),this.searchGlobal&&t.push(g.join(y.homedir(),Zt,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!h.existsSync(t))return{config:{},source:null,found:!1};let e=h.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=m.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=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));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(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}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`)}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=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?g.join(y.homedir(),e.slice(1)):e}};let nn=null;function rn(e){return(e||!nn)&&(nn=new tn(e)),nn}function an(e){return rn().load(e)}function on(){let e=Yt(`ConfigLoader`),t=Qt();if(!h.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),en($t(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=h.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 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}),cn(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}),cn(t,e,[`Config must be a JSON object`]);let i=sn(r);if(i.length>0){for(let n of i)e.error(`config validation error`,{path:t,error:n});return cn(t,e,i)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function sn(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);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(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}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{h.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return en($t(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const ln=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function un(e){return ln.includes(e)}function dn(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function fn(){return g.join(y.homedir(),Zt,Xt)}function pn(){let e=fn();if(!h.existsSync(e))return{};try{let t=h.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function mn(e){let t=fn(),n=g.dirname(t);h.existsSync(n)||h.mkdirSync(n,{recursive:!0}),h.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}var hn=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: ${ln.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=pn(),r=[],i=[];for(let[e,a]of this.options){if(!un(e)){r.push(`Invalid key: ${e} (valid keys: ${ln.join(`, `)})`);continue}if(e===`logLevel`&&!dn(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(mn(n),t.info(`global config written`,{path:fn()})),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}}};let gn=function(e){return e.Input=`Input`,e.Output=`Output`,e}({}),_n=function(e){return e.GlobalMemory=`GlobalMemory`,e.ProjectRootMemory=`ProjectRootMemory`,e.ProjectChildrenMemory=`ProjectChildrenMemory`,e.FastCommand=`FastCommand`,e.SubAgent=`SubAgent`,e.Skill=`Skill`,e.SkillChildDoc=`SkillChildDoc`,e.SkillResource=`SkillResource`,e.SkillMcpConfig=`SkillMcpConfig`,e.Readme=`Readme`,e}({}),vn=function(e){return e.Red=`Red`,e.Green=`Green`,e.Blue=`Blue`,e.Yellow=`Yellow`,e}({}),yn=function(e){return e.Read=`Read`,e.Write=`Write`,e.Edit=`Edit`,e.Grep=`Grep`,e}({}),bn=function(e){return e.CamelCase=`CamelCase`,e.PascalCase=`PascalCase`,e.SnakeCase=`SnakeCase`,e.KebabCase=`KebabCase`,e.UpperCase=`UpperCase`,e.LowerCase=`LowerCase`,e.Original=`Original`,e}({}),xn=function(e){return e.UserHome=`UserHome`,e.External=`External`,e}({}),F=function(e){return e.Relative=`Relative`,e.Absolute=`Absolute`,e.Root=`Root`,e}({}),I=function(e){return e.VSCode=`VSCode`,e.IntellijIDEA=`IntellijIDEA`,e.Git=`Git`,e.EditorConfig=`EditorConfig`,e.Original=`Original`,e}({});function Sn(e,t){let{requiredFields:n,optionalDefaults:r,filePath:i}=t,a=[],o=[];for(let t of n){let n=String(t);if(!(n in e)||e[n]==null){let e=i==null?`Missing required field "${n}"`:`Missing required field "${n}" in ${i}`;a.push(e)}}if(r!=null){for(let[t,n]of Object.entries(r))if(!(t in e)||e[t]==null){let e=i==null?`Using default value for optional field "${t}": ${JSON.stringify(n)}`:`Using default value for optional field "${t}": ${JSON.stringify(n)} in ${i}`;o.push(e)}}return{valid:a.length===0,errors:a,warnings:o}}function Cn(e,t){return Sn(e,{requiredFields:[`name`,`description`],optionalDefaults:{enabled:!0,keywords:[]},filePath:t})}function wn(e,t){return Sn(e,{requiredFields:[],optionalDefaults:{},filePath:t})}function Tn(e,t){return Sn(e,{requiredFields:[`name`,`description`],optionalDefaults:{},filePath:t})}function En(e,t){let n={...e};for(let[e,r]of Object.entries(t))(!(e in n)||n[e]==null)&&(n[e]=r);return n}const Dn=`.kt,.java,.py,.pyi,.pyx,.ts,.tsx,.js,.jsx,.mjs,.cjs,.go,.rs,.c,.cpp,.cc,.h,.hpp,.hxx,.cs,.fs,.fsx,.vb,.rb,.php,.swift,.scala,.groovy,.lua,.r,.R,.jl,.ex,.exs,.erl,.clj,.cljs,.hs,.ml,.mli,.nim,.zig,.v,.dart,.vue,.svelte,.sql,.json,.jsonc,.json5,.xml,.xsd,.xsl,.xslt,.yaml,.yml,.toml,.csv,.tsv,.graphql,.gql,.proto,.txt,.text,.rtf,.log,.ini,.conf,.cfg,.config,.properties,.env,.envrc,.editorconfig,.gitignore,.gitattributes,.npmrc,.nvmrc,.npmignore,.eslintrc,.prettierrc,.stylelintrc,.babelrc,.browserslistrc,.sh,.bash,.zsh,.fish,.ps1,.psm1,.psd1,.bat,.cmd,.html,.htm,.xhtml,.css,.scss,.sass,.less,.styl,.svg,.ejs,.hbs,.mustache,.pug,.jade,.jinja,.jinja2,.j2,.erb,.haml,.slim,.d.ts,.d.mts,.d.cts,.diff,.patch,.asm,.s,.makefile,.mk,.dockerfile,.tf,.tfvars,.prisma,.mdx`.split(`,`),On=`.docx,.doc,.xlsx,.xls,.pptx,.ppt,.pdf,.odt,.ods,.odp,.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff,.zip,.tar,.gz,.bz2,.7z,.rar,.pyd,.pyc,.pyo,.class,.jar,.war,.dll,.so,.dylib,.exe,.bin,.wasm,.ttf,.otf,.woff,.woff2,.eot,.mp3,.wav,.ogg,.mp4,.webm,.db,.sqlite,.sqlite3`.split(`,`),L={SRC:`src`,DIST:`dist`,SKILLS:`skills`,COMMANDS:`commands`,AGENTS:`agents`,APP:`app`,IDEA:`.idea`,IDEA_CODE_STYLES:`.idea/codeStyles`,VSCODE:`.vscode`},R={GLOBAL_MEMORY:`global.mdx`,GLOBAL_MEMORY_SRC:`global.cn.mdx`,EDITOR_CONFIG:`.editorconfig`,IDEA_GITIGNORE:`.idea/.gitignore`,IDEA_PROJECT_XML:`.idea/codeStyles/Project.xml`,IDEA_CODE_STYLE_CONFIG_XML:`.idea/codeStyles/codeStyleConfig.xml`,VSCODE_SETTINGS:`.vscode/settings.json`,VSCODE_EXTENSIONS:`.vscode/extensions.json`,QODER_IGNORE:`.qoderignore`,CURSOR_IGNORE:`.cursorignore`,WARP_INDEX_IGNORE:`.warpindexignore`,AI_IGNORE:`.aiignore`},kn={SRC_SKILLS:`src/skills`,SRC_COMMANDS:`src/commands`,SRC_AGENTS:`src/agents`,SRC_GLOBAL_MEMORY:`app/global.cn.mdx`,DIST_SKILLS:`dist/skills`,DIST_COMMANDS:`dist/commands`,DIST_AGENTS:`dist/agents`,DIST_APP:`dist/app`,DIST_GLOBAL_MEMORY:`dist/global.mdx`,APP:`app`},An={src:{skills:{name:L.SKILLS,required:!1,description:`Skill source files (.cn.mdx)`},commands:{name:L.COMMANDS,required:!1,description:`Fast command source files (.cn.mdx)`},agents:{name:L.AGENTS,required:!1,description:`Sub-agent source files (.cn.mdx)`},globalMemoryFile:{name:R.GLOBAL_MEMORY_SRC,required:!1,description:`Global memory source file`}},dist:{skills:{name:L.SKILLS,required:!1,description:`Compiled skill files (.mdx)`},commands:{name:L.COMMANDS,required:!1,description:`Compiled fast command files (.mdx)`},agents:{name:L.AGENTS,required:!1,description:`Compiled sub-agent files (.mdx)`},globalMemoryFile:{name:R.GLOBAL_MEMORY,required:!1,description:`Compiled global memory file`},app:{name:L.APP,required:!1,description:`Compiled project-specific prompts`}},app:{name:L.APP,required:!1,description:`Project-specific prompts (standalone directory)`},ide:{idea:{name:L.IDEA,required:!1,description:`JetBrains IDE configuration directory`},ideaCodeStyles:{name:L.IDEA_CODE_STYLES,required:!1,description:`JetBrains IDE code styles directory`},vscode:{name:L.VSCODE,required:!1,description:`VS Code configuration directory`}},ideFiles:[{name:R.EDITOR_CONFIG,required:!1,description:`EditorConfig file`},{name:R.IDEA_GITIGNORE,required:!1,description:`JetBrains IDE .gitignore`},{name:R.IDEA_PROJECT_XML,required:!1,description:`JetBrains IDE Project.xml`},{name:R.IDEA_CODE_STYLE_CONFIG_XML,required:!1,description:`JetBrains IDE codeStyleConfig.xml`},{name:R.VSCODE_SETTINGS,required:!1,description:`VS Code settings.json`},{name:R.VSCODE_EXTENSIONS,required:!1,description:`VS Code extensions.json`}],ignoreFiles:[{name:R.QODER_IGNORE,required:!1,description:`Qoder ignore file`},{name:R.CURSOR_IGNORE,required:!1,description:`Cursor ignore file`},{name:R.WARP_INDEX_IGNORE,required:!1,description:`Warp index ignore file`},{name:R.AI_IGNORE,required:!1,description:`AI ignore file`}]};var jn=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 wt(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 kt(n,await Tt(n,i),i);return this.logDryRunFiles(o,t),this.logDryRunDirectories(s,t),await Et(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=g.isAbsolute(n)?n:g.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=g.isAbsolute(e)?e:g.resolve(e);t.info(`would delete directory`,{path:n,dryRun:!0})}}},Mn=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 Dt(n,i),o=await Ot(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`}}},Nn=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await Mt(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await Dt(n,o),c=await Ot(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 Pn(){return`2026.10202.10348`}var Fn=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${Pn()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const z=`tnmsc`,In=`
|
|
611
611
|
${z} v${Pn()} - Memory Sync CLI
|
|
612
612
|
|
|
613
613
|
Synchronize AI memory and configuration files across projects.
|
|
@@ -661,7 +661,7 @@ CONFIG OPTIONS:
|
|
|
661
661
|
CONFIGURATION:
|
|
662
662
|
Configure via plugin.config.ts in your project root.
|
|
663
663
|
See documentation for detailed configuration options.
|
|
664
|
-
`.trim();var Ln=class{name=`help`;async execute(e){return console.log(In),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Rn(e,t){let n=g.join(e,`.git`),r=h.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 zn(e,t,n,r,i){if(n==null)return r;let a=g.relative(t,e),o=g.join(n,a);return h.existsSync(o)&&h.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),h.readFileSync(o,`utf8`)):r}function Bn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;h.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(h.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(It)){let o=t.path,l=g.join(e,o),u=g.dirname(l);if(!h.existsSync(u)){h.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=g.dirname(t)}if(h.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=zn(l,e,n,t.content,r);h.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 Vn(e,t,n){let r=e;return r=r.replace(Lt.SHADOW_SOURCE_PROJECT,n),r=r.replace(Lt.WORKSPACE,t),r.startsWith(`~`)&&(r=g.join(y.homedir(),r.slice(1))),g.normalize(r)}var Hn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Vn(n.workspaceDir,``,``),i=Bn(Vn(n.shadowSourceProjectDir,r,``),{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}}};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.10202.10343`}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=`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 nr={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 rr=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}({}),ir=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var ar=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=y.platform();return{platform:e,arch:y.arch(),hostname:y.hostname(),homedir:y.homedir(),tmpdir:y.tmpdir(),type:y.type(),release:y.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return ir.Win;case`darwin`:return ir.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return ir.Linux;default:return ir.Unknown}}detectShellKind(){let e=(m.env.SHELL??m.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?rr.Bash:e.includes(`zsh`)?rr.Zsh:e.includes(`fish`)?rr.Fish:e.includes(`pwsh`)?rr.Pwsh:e.includes(`powershell`)?rr.PowerShell:e.includes(`cmd`)?rr.Cmd:e.endsWith(`/sh`)?rr.Sh:rr.Unknown}collectEnvContext(){return{...m.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...nr.default};return this.toolPreset===`claudeCode`?{...e,...nr.claudeCode}:this.toolPreset===`kiro`?{...e,...nr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let or=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 sr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=or.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 cr(e){let t=[...e],n=t[0];n!=null&&lr(n)&&t.shift();let r=t[0];return r!=null&&ur(r)&&t.shift(),t}function lr(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 ur(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const dr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`]),fr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),pr=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function mr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=pr.get(n)??4;for(let e of t){let t=pr.get(e)??4;t<r&&(r=t,n=e)}return n}function hr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new Fn;if(t)return new Ln;if(a!=null)return new tr(a);if(r===`version`)return new Fn;if(r===`help`)return new Ln;if(r===`outdated`)return new er;if(r===`init`)return new Hn;if(r===`dry-run`)return new Mn;if(r===`clean`)return i?new jn:new Nt;if(r!==`config`||o.length>0)return new Nn;let c=[];for(let e of s){let t=e.indexOf(`=`);t>0&&c.push([e.slice(0,t),e.slice(t+1)])}return new hn([...o,...c])}function gr(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!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=fr.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`--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;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,dr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var _r=class{logger;args;outputPlugins=[];constructor(...e){this.args=gr(cr(e.filter(e=>e!=null)));let t=mr(this.args);t!=null&&qt(t),this.logger=Yt(`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(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return hr(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:h,path:g,glob:_t.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:h,path:g,glob:_t.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 a(n.name,r)}}topologicalSort(t){this.validateDependencies(t);let n=new Map;for(let e of t)n.set(e.name,e);let r=new Map;for(let e of t)r.set(e.name,0);let i=new Map;for(let e of t)i.set(e.name,[]);for(let e of t){let t=e.dependsOn??[];for(let n of t){r.set(e.name,(r.get(e.name)??0)+1);let t=i.get(n)??[];t.push(e.name),i.set(n,t)}}let a=[];for(let e of t)r.get(e.name)===0&&a.push(e.name);let o=[];for(;a.length>0;){let e=a.shift(),s=n.get(e);o.push(s);let c=(i.get(e)??[]).sort((e,n)=>t.findIndex(t=>t.name===e)-t.findIndex(e=>e.name===n));for(let e of c){let t=(r.get(e)??0)-1;r.set(e,t),t===0&&a.push(e)}}if(o.length===t.length)return o;throw new e(this.findCyclePath(t,r))}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 ar({userConfig:r}).collect(),o=new sr;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,or.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.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],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?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills: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 vr={...Rt,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[]};function yr(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function br(...e){return e.reduce((e,t)=>xr(e,t),{...vr})}function xr(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:Sr(e.excludePatterns,i),fastCommandSeriesOptions:Cr(e.fastCommandSeriesOptions,a)}}function Sr(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function Cr(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 wr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Tr(e={}){on().shouldExit&&m.exit(1);let t,n,r;wr(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=an(n);a=e.found,o=e.sources,e.found&&(i=yr(e.config),s=e.config)}let c=br(i,r),{plugins:l=[],logLevel:u}=c,d=Yt(`defineConfig`,u);a?d.info(`user config loaded`,{sources:o}):d.info(`no user config found, using defaults`,{workspaceDir:vr.workspaceDir,shadowSourceProjectDir:vr.shadowSourceProjectDir,shadowSkillSourceDir:vr.shadowSkillSourceDir,shadowFastCommandDir:vr.shadowFastCommandDir,shadowSubAgentDir:vr.shadowSubAgentDir,globalMemoryFile:vr.globalMemoryFile,shadowProjectsDir:vr.shadowProjectsDir,logLevel:vr.logLevel});let f={logger:d,userConfigOptions:c,fs:h,path:g,glob:_t.default},p=l.filter(e=>e.type===gn.Input),_=l.filter(e=>e.type===gn.Output),v=await new _r().executePluginsInOrder(p,f,!1,s);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.externalProjects!=null&&{externalProjects:v.externalProjects},...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...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&&Rn(v.shadowSourceProjectDir,d),{context:y,outputPlugins:_,userConfigOptions:c}}const B=Nr(/[A-Za-z]/),V=Nr(/[\dA-Za-z]/),Er=Nr(/[#-'*+\--9=?A-Z^-~]/);function Dr(e){return e!==null&&(e<32||e===127)}const Or=Nr(/\d/),kr=Nr(/[\dA-Fa-f]/),Ar=Nr(/[!-/:-@[-`{-~]/);function H(e){return e!==null&&e<-2}function U(e){return e!==null&&(e<0||e===32)}function W(e){return e===-2||e===-1||e===32}const jr=Nr(/\p{P}|\p{S}/u),Mr=Nr(/\s/);function Nr(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Pr=ie(j(((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 Fr=Object.assign(Ir(Error),{eval:Ir(EvalError),range:Ir(RangeError),reference:Ir(ReferenceError),syntax:Ir(SyntaxError),type:Ir(TypeError),uri:Ir(URIError)});function Ir(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Pr.default)(t,...n))}}const Lr={}.hasOwnProperty,Rr={yaml:`-`,toml:`+`};function zr(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Br(r[n]);return t}function Br(e){let t=e;if(typeof t==`string`){if(!Lr.call(Rr,t))throw Fr("Missing matter definition for `%s`",t);t={type:t,marker:Rr[t]}}else if(typeof t!=`object`)throw Fr("Expected matter to be an object, not `%j`",t);if(!Lr.call(t,`type`))throw Fr("Missing `type` in matter `%j`",t);if(!Lr.call(t,`fence`)&&!Lr.call(t,`marker`))throw Fr("Missing `marker` or `fence` in matter `%j`",t);return t}function Vr(e){let t=zr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=Ur(e,`open`).charCodeAt(0),a=Hr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Hr(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=Ur(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),W(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return W(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return H(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=Ur(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||H(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||H(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),W(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return W(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||H(i)?(e.exit(r),t(i)):n(i)}}}function Ur(e,t){return e.marker?Wr(e.marker,t).repeat(3):Wr(e.fence,t)}function Wr(e,t){return typeof e==`string`?e:e[t]}function Gr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Kr(e){let t=zr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=qr(e),r[e.type]=Jr,r[e.type+`Value`]=Yr}return{enter:n,exit:r}}function qr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Jr(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 Yr(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function Xr(e){let t=[],n={},r=zr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=Zr(e);let a=Qr(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:Gr(a.charAt(1))})}return{unsafe:t,handlers:n}}function Zr(e){let t=Qr(e,`open`),n=Qr(e,`close`);return r;function r(e){return t+(e.value?`
|
|
664
|
+
`.trim();var Ln=class{name=`help`;async execute(e){return console.log(In),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};function Rn(e,t){let n=g.join(e,`.git`),r=h.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 zn(e,t,n,r,i){if(n==null)return r;let a=g.relative(t,e),o=g.join(n,a);return h.existsSync(o)&&h.statSync(o).isFile()?(i?.debug(`copying from source`,{path:o}),h.readFileSync(o,`utf8`)):r}function Bn(e,t={}){let{sourceDir:n,logger:r}=t,i=[],a=[],o=[],s=[],c=new Set;h.existsSync(e)?(o.push(e),r?.debug(`directory exists`,{path:e})):(h.mkdirSync(e,{recursive:!0}),i.push(e),c.add(e),r?.info(`created directory`,{path:e}));for(let t of Object.values(It)){let o=t.path,l=g.join(e,o),u=g.dirname(l);if(!h.existsSync(u)){h.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=g.dirname(t)}if(h.existsSync(l))s.push(l),r?.debug(`file exists`,{path:l});else{let i=zn(l,e,n,t.content,r);h.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 Vn(e,t,n){let r=e;return r=r.replace(Lt.SHADOW_SOURCE_PROJECT,n),r=r.replace(Lt.WORKSPACE,t),r.startsWith(`~`)&&(r=g.join(y.homedir(),r.slice(1))),g.normalize(r)}var Hn=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Vn(n.workspaceDir,``,``),i=Bn(Vn(n.shadowSourceProjectDir,r,``),{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}}};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.10202.10348`}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=`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 nr={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 rr=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}({}),ir=function(e){return e.Win=`win`,e.Mac=`mac`,e.Linux=`linux`,e.Unknown=`unknown`,e}({});var ar=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=y.platform();return{platform:e,arch:y.arch(),hostname:y.hostname(),homedir:y.homedir(),tmpdir:y.tmpdir(),type:y.type(),release:y.release(),shellKind:this.detectShellKind(),kind:this.detectOsKind(e)}}detectOsKind(e){switch(e){case`win32`:return ir.Win;case`darwin`:return ir.Mac;case`linux`:case`freebsd`:case`openbsd`:case`sunos`:case`aix`:return ir.Linux;default:return ir.Unknown}}detectShellKind(){let e=(m.env.SHELL??m.env.ComSpec??``).toLowerCase();return e.includes(`bash`)?rr.Bash:e.includes(`zsh`)?rr.Zsh:e.includes(`fish`)?rr.Fish:e.includes(`pwsh`)?rr.Pwsh:e.includes(`powershell`)?rr.PowerShell:e.includes(`cmd`)?rr.Cmd:e.endsWith(`/sh`)?rr.Sh:rr.Unknown}collectEnvContext(){return{...m.env}}collectProfile(){return this.userConfig?.profile==null?{}:this.userConfig.profile}collectToolReferences(){let e={...nr.default};return this.toolPreset===`claudeCode`?{...e,...nr.claudeCode}:this.toolPreset===`kiro`?{...e,...nr.kiro}:e}createMdComponent(){let e=(e=>e.when===!1?null:e.children);return e.Line=e=>e.when===!1?null:e.children,e}};let or=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 sr=class{registrations=[];globalScope=null;setGlobalScope(e){this.globalScope=e}getGlobalScope(){return this.globalScope}register(e,t,n=or.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 cr(e){let t=[...e],n=t[0];n!=null&&lr(n)&&t.shift();let r=t[0];return r!=null&&ur(r)&&t.shift(),t}function lr(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 ur(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}const dr=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`config`]),fr=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),pr=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function mr(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=pr.get(n)??4;for(let e of t){let t=pr.get(e)??4;t<r&&(r=t,n=e)}return n}function hr(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new Fn;if(t)return new Ln;if(a!=null)return new tr(a);if(r===`version`)return new Fn;if(r===`help`)return new Ln;if(r===`outdated`)return new er;if(r===`init`)return new Hn;if(r===`dry-run`)return new Mn;if(r===`clean`)return i?new jn:new Nt;if(r!==`config`||o.length>0)return new Nn;let c=[];for(let e of s){let t=e.indexOf(`=`);t>0&&c.push([e.slice(0,t),e.slice(t+1)])}return new hn([...o,...c])}function gr(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!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=fr.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`--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;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,dr.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var _r=class{logger;args;outputPlugins=[];constructor(...e){this.args=gr(cr(e.filter(e=>e!=null)));let t=mr(this.args);t!=null&&qt(t),this.logger=Yt(`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(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return hr(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:h,path:g,glob:_t.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:h,path:g,glob:_t.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 a(n.name,r)}}topologicalSort(t){this.validateDependencies(t);let n=new Map;for(let e of t)n.set(e.name,e);let r=new Map;for(let e of t)r.set(e.name,0);let i=new Map;for(let e of t)i.set(e.name,[]);for(let e of t){let t=e.dependsOn??[];for(let n of t){r.set(e.name,(r.get(e.name)??0)+1);let t=i.get(n)??[];t.push(e.name),i.set(n,t)}}let a=[];for(let e of t)r.get(e.name)===0&&a.push(e.name);let o=[];for(;a.length>0;){let e=a.shift(),s=n.get(e);o.push(s);let c=(i.get(e)??[]).sort((e,n)=>t.findIndex(t=>t.name===e)-t.findIndex(e=>e.name===n));for(let e of c){let t=(r.get(e)??0)-1;r.set(e,t),t===0&&a.push(e)}}if(o.length===t.length)return o;throw new e(this.findCyclePath(t,r))}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 ar({userConfig:r}).collect(),o=new sr;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,or.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.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],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?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills: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 vr={...Rt,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[]};function yr(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function br(...e){return e.reduce((e,t)=>xr(e,t),{...vr})}function xr(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:Sr(e.excludePatterns,i),fastCommandSeriesOptions:Cr(e.fastCommandSeriesOptions,a)}}function Sr(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function Cr(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 wr(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}async function Tr(e={}){on().shouldExit&&m.exit(1);let t,n,r;wr(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=an(n);a=e.found,o=e.sources,e.found&&(i=yr(e.config),s=e.config)}let c=br(i,r),{plugins:l=[],logLevel:u}=c,d=Yt(`defineConfig`,u);a?d.info(`user config loaded`,{sources:o}):d.info(`no user config found, using defaults`,{workspaceDir:vr.workspaceDir,shadowSourceProjectDir:vr.shadowSourceProjectDir,shadowSkillSourceDir:vr.shadowSkillSourceDir,shadowFastCommandDir:vr.shadowFastCommandDir,shadowSubAgentDir:vr.shadowSubAgentDir,globalMemoryFile:vr.globalMemoryFile,shadowProjectsDir:vr.shadowProjectsDir,logLevel:vr.logLevel});let f={logger:d,userConfigOptions:c,fs:h,path:g,glob:_t.default},p=l.filter(e=>e.type===gn.Input),_=l.filter(e=>e.type===gn.Output),v=await new _r().executePluginsInOrder(p,f,!1,s);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y={workspace:v.workspace,ideConfigFiles:v.ideConfigFiles??[],...v.externalProjects!=null&&{externalProjects:v.externalProjects},...v.fastCommands!=null&&{fastCommands:v.fastCommands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...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&&Rn(v.shadowSourceProjectDir,d),{context:y,outputPlugins:_,userConfigOptions:c}}const B=Nr(/[A-Za-z]/),V=Nr(/[\dA-Za-z]/),Er=Nr(/[#-'*+\--9=?A-Z^-~]/);function Dr(e){return e!==null&&(e<32||e===127)}const Or=Nr(/\d/),kr=Nr(/[\dA-Fa-f]/),Ar=Nr(/[!-/:-@[-`{-~]/);function H(e){return e!==null&&e<-2}function U(e){return e!==null&&(e<0||e===32)}function W(e){return e===-2||e===-1||e===32}const jr=Nr(/\p{P}|\p{S}/u),Mr=Nr(/\s/);function Nr(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var Pr=ie(j(((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 Fr=Object.assign(Ir(Error),{eval:Ir(EvalError),range:Ir(RangeError),reference:Ir(ReferenceError),syntax:Ir(SyntaxError),type:Ir(TypeError),uri:Ir(URIError)});function Ir(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){return new e(t&&(0,Pr.default)(t,...n))}}const Lr={}.hasOwnProperty,Rr={yaml:`-`,toml:`+`};function zr(e){let t=[],n=-1,r=Array.isArray(e)?e:e?[e]:[`yaml`];for(;++n<r.length;)t[n]=Br(r[n]);return t}function Br(e){let t=e;if(typeof t==`string`){if(!Lr.call(Rr,t))throw Fr("Missing matter definition for `%s`",t);t={type:t,marker:Rr[t]}}else if(typeof t!=`object`)throw Fr("Expected matter to be an object, not `%j`",t);if(!Lr.call(t,`type`))throw Fr("Missing `type` in matter `%j`",t);if(!Lr.call(t,`fence`)&&!Lr.call(t,`marker`))throw Fr("Missing `marker` or `fence` in matter `%j`",t);return t}function Vr(e){let t=zr(e),n={},r=-1;for(;++r<t.length;){let e=t[r],i=Ur(e,`open`).charCodeAt(0),a=Hr(e),o=n[i];Array.isArray(o)?o.push(a):n[i]=[a]}return{flow:n}}function Hr(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=Ur(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),W(e)?(l.enter(`whitespace`),h(e)):g(e)):e===s.charCodeAt(c++)?(l.consume(e),m):d(e)}function h(e){return W(e)?(l.consume(e),h):(l.exit(`whitespace`),g(e))}function g(t){return H(t)?(l.exit(r),l.enter(`lineEnding`),l.consume(t),l.exit(`lineEnding`),s=Ur(e,`close`),c=0,l.attempt(o,b,_)):d(t)}function _(e){return e===null||H(e)?y(e):(l.enter(a),v(e))}function v(e){return e===null||H(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),W(t)?(e.enter(`whitespace`),l(t)):u(t)):t===s.charCodeAt(a++)?(e.consume(t),c):n(t)}function l(t){return W(t)?(e.consume(t),l):(e.exit(`whitespace`),u(t))}function u(i){return i===null||H(i)?(e.exit(r),t(i)):n(i)}}}function Ur(e,t){return e.marker?Wr(e.marker,t).repeat(3):Wr(e.fence,t)}function Wr(e,t){return typeof e==`string`?e:e[t]}function Gr(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function Kr(e){let t=zr(e),n={},r={},i=-1;for(;++i<t.length;){let e=t[i];n[e.type]=qr(e),r[e.type]=Jr,r[e.type+`Value`]=Yr}return{enter:n,exit:r}}function qr(e){return t;function t(t){this.enter({type:e.type,value:``},t),this.buffer()}}function Jr(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 Yr(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}function Xr(e){let t=[],n={},r=zr(e),i=-1;for(;++i<r.length;){let e=r[i];n[e.type]=Zr(e);let a=Qr(e,`open`);t.push({atBreak:!0,character:a.charAt(0),after:Gr(a.charAt(1))})}return{unsafe:t,handlers:n}}function Zr(e){let t=Qr(e,`open`),n=Qr(e,`close`);return r;function r(e){return t+(e.value?`
|
|
665
665
|
`+e.value:``)+`
|
|
666
666
|
`+n}}function Qr(e,t){return e.marker?$r(e.marker,t).repeat(3):$r(e.fence,t)}function $r(e,t){return typeof e==`string`?e:e[t]}function ei(e){let t=this,n=e||`yaml`,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Vr(n)),a.push(Kr(n)),o.push(Xr(n))}function ti(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 ni=(function(e){if(e==null)return si;if(typeof e==`function`)return oi(e);if(typeof e==`object`)return Array.isArray(e)?ri(e):ii(e);if(typeof e==`string`)return ai(e);throw Error(`Expected function, string, or object as test`)});function ri(e){let t=[],n=-1;for(;++n<e.length;)t[n]=ni(e[n]);return oi(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}function ii(e){let t=e;return oi(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function ai(e){return oi(t);function t(t){return t&&t.type===e}}function oi(e){return t;function t(t,n,r){return!!(ci(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function si(){return!0}function ci(e){return typeof e==`object`&&!!e&&`type`in e}function li(e){return`\x1B[33m`+e+`\x1B[39m`}const ui=[];function di(e,t,n,r){let i;typeof t==`function`&&typeof n!=`function`?(r=n,n=t):i=t;let a=ni(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 (`+li(e.type+(t?`<`+t+`>`:``))+`)`})}return u;function u(){let l=ui,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=fi(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 fi(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?ui:[e]}function pi(e,t,n){let r=ni((n||{}).ignore||[]),i=mi(t),a=-1;for(;++a<i.length;)di(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 mi(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([hi(e[0]),gi(e[1])])}return t}function hi(e){return typeof e==`string`?new RegExp(Gr(e),`g`):e}function gi(e){return typeof e==`function`?e:function(){return e}}const _i=`phrasing`,vi=[`autolink`,`link`,`image`,`label`];function yi(){return{transforms:[Di],enter:{literalAutolink:xi,literalAutolinkEmail:Si,literalAutolinkHttp:Si,literalAutolinkWww:Si},exit:{literalAutolink:Ei,literalAutolinkEmail:Ti,literalAutolinkHttp:Ci,literalAutolinkWww:wi}}}function bi(){return{unsafe:[{character:`@`,before:`[+\\-.\\w]`,after:`[\\-.\\w]`,inConstruct:_i,notInConstruct:vi},{character:`.`,before:`[Ww]`,after:`[\\-.\\w]`,inConstruct:_i,notInConstruct:vi},{character:`:`,before:`[ps]`,after:`\\/`,inConstruct:_i,notInConstruct:vi}]}}function xi(e){this.enter({type:`link`,title:null,url:``,children:[]},e)}function Si(e){this.config.enter.autolinkProtocol.call(this,e)}function Ci(e){this.config.exit.autolinkProtocol.call(this,e)}function wi(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 Ti(e){this.config.exit.autolinkEmail.call(this,e)}function Ei(e){this.exit(e)}function Di(e){pi(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Oi],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,ki]],{ignore:[`link`,`linkReference`]})}function Oi(e,t,n,r,i){let a=``;if(!Mi(i)||(/^w/i.test(t)&&(n=t+n,t=``,a=`http://`),!Ai(n)))return!1;let o=ji(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 ki(e,t,n,r){return!Mi(r,!0)||/[-\d_]$/.test(n)?!1:{type:`link`,title:null,url:`mailto:`+t+`@`+n,children:[{type:`text`,value:t+`@`+n}]}}function Ai(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 ji(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=ti(e,`(`),a=ti(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 Mi(e,t){let n=e.input.charCodeAt(e.index-1);return(e.index===0||Mr(n)||jr(n))&&(!t||n!==47)}function Ni(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}Ui.peek=Hi;function Pi(){this.buffer()}function Fi(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ii(){this.buffer()}function Li(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Ri(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ni(this.sliceSerialize(e)).toLowerCase(),n.label=t}function zi(e){this.exit(e)}function Bi(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ni(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Vi(e){this.exit(e)}function Hi(){return`[`}function Ui(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 Wi(){return{enter:{gfmFootnoteCallString:Pi,gfmFootnoteCall:Fi,gfmFootnoteDefinitionLabelString:Ii,gfmFootnoteDefinition:Li},exit:{gfmFootnoteCallString:Ri,gfmFootnoteCall:zi,gfmFootnoteDefinitionLabelString:Bi,gfmFootnoteDefinition:Vi}}}function Gi(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:Ui},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?`
|
|
667
667
|
`:` `)+r.indentLines(r.containerFlow(e,a.current()),t?qi:Ki))),s(),o}}function Ki(e,t,n){return t===0?e:qi(e,t,n)}function qi(e,t,n){return(n?``:` `)+e}const Ji=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`];$i.peek=ea;function Yi(){return{canContainEols:[`delete`],enter:{strikethrough:Zi},exit:{strikethrough:Qi}}}function Xi(){return{unsafe:[{character:`~`,inConstruct:`phrasing`,notInConstruct:Ji}],handlers:{delete:$i}}}function Zi(e){this.enter({type:`delete`,children:[]},e)}function Qi(e){this.exit(e)}function $i(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 ea(){return`~`}function ta(e){return e.length}function na(e,t){let n=t||{},r=(n.align||[]).concat(),i=n.stringLength||ta,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=ra(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]=ia(r[d]);else{let e=ia(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(`
|
|
@@ -798,7 +798,7 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
798
798
|
`,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())}}}})),Hd=j((e=>{var t=Pd(),n=_d(),r=vd(),i=Hu(),a=Y(),o=Bd(),s=Vd();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})),Ud=ie(j((e=>{var t=Pd(),n=_d(),r=hd(),i=vd(),a=Pu(),o=Y(),s=Gu(),c=X(),l=qu(),u=Yu();Rd();var d=zd(),f=Bd(),p=Vd(),m=Hd(),h=Ou();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 Wd(e,t){let n=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!=null));return Object.keys(n).length===0?`---
|
|
799
799
|
---`:`---\n${Ud.stringify(n,{singleQuote:t?.singleQuote??!1,lineWidth:t?.lineWidth??0}).trimEnd()}\n---`}function Gd(e,t,n){return e==null||Object.keys(e).length===0?t:`${Wd(e,n)}\n${t}`}function Kd(e){let t=vu().use(nu).use(pl).use(ei,[`yaml`]).parse(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){let t=e;r=t.value;try{n=Ud.parse(t.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 qd(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 Jd=class{type;name;_log;get log(){return this._log??=Yt(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}},Z=class extends Jd{globalConfigDir;outputFileName;registryWriterCache=new Map;writeEffects=[];cleanEffects=[];constructor(e,t){super(e,gn.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``}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===F.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:F.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let n;n=e.pathKind===F.Absolute?e.path:this.isRelativePath(e)?g.resolve(e.basePath,e.path):g.resolve(m.cwd(),e.path);let r=t??this.outputFileName;return r?g.join(n,r):n}createRelativePath(e,t,n){return{pathKind:F.Relative,path:e,basePath:t,getDirectoryName:n,getAbsolutePath:()=>g.join(t,e)}}createFileRelativePath(e,t){let n=g.join(e.path,t);return{pathKind:F.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>e.getDirectoryName(),getAbsolutePath:()=>g.join(e.basePath,n)}}getGlobalConfigDir(){return g.join(this.getHomeDir(),this.globalConfigDir)}getHomeDir(){return y.homedir()}joinPath(...e){return g.join(...e)}resolvePath(...e){return g.resolve(...e)}dirname(e){return g.dirname(e)}basename(e,t){return g.basename(e,t)}writeFileSync(e,t,n=`utf8`){h.writeFileSync(e,t,n)}writeFileSyncBuffer(e,t){h.writeFileSync(e,t)}ensureDirectory(e){h.existsSync(e)||h.mkdirSync(e,{recursive:!0})}existsSync(e){return h.existsSync(e)}lstatSync(e){return yt(e)}isSymlink(e){return vt(e)}createSymlink(e,t,n=`dir`){xt(e,t,n)}removeSymlink(e){St(e)}readdirSync(e,t){return t?.withFileTypes===!0?h.readdirSync(e,{withFileTypes:!0}):h.readdirSync(e)}async writeFile(e,t,n,r){let i=g.dirname(t),a=g.basename(t),o={pathKind:F.Relative,path:a,basePath:i,getDirectoryName:()=>g.basename(i),getAbsolutePath:()=>t};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`file`,path:t,label:r}),{path:o,success:!0,skipped:!1};try{return this.ensureDirectory(i),h.writeFileSync(t,n,`utf8`),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{let e=g.dirname(i);return this.ensureDirectory(e),h.writeFileSync(i,n,`utf8`),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 Gd(t,e)}buildMarkdownContentWithRaw(e,t,n){return t!=null&&Object.keys(t).length>0?Gd(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=`
|
|
800
800
|
|
|
801
|
-
`,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 Yd=`AGENTS.md`;var Xd=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Yd})}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,Yd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Yd));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}}},Q=class extends Jd{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,gn.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:S,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.shadowSourceProjectDir;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(Lt.USER_HOME)&&(r=r.replace(Lt.USER_HOME,y.homedir())),r.includes(Lt.SHADOW_SOURCE_PROJECT)&&(r=r.replace(Lt.SHADOW_SOURCE_PROJECT,n)),r.includes(Lt.WORKSPACE)&&(r=r.replace(Lt.WORKSPACE,t)),g.normalize(r)}readAndParseMarkdown(e,t){return Kd(t.readFileSync(e,`utf8`))}};const Zd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Qd=class extends Q{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 Zd){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 $d=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var ef=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}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)for(let n of $d){let r=g.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:F.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>g.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>g.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t?.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,r){let i=g.join(t.path,n.fileName),a=g.join(t.basePath,i),o={pathKind:F.Relative,path:i,basePath:t.basePath,getDirectoryName:()=>g.basename(t.path),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{return h.writeFileSync(a,n.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}};const tf=`.agent`,nf=`.gemini`,rf=`antigravity`,af=`skills`,of=`workflows`,sf=`mcp_config.json`,cf=[af,of];var lf=class extends Z{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:tf,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=g.join(y.homedir(),nf,rf),n=g.join(t,sf),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp_config.json to empty shell`};try{return this.ensureDirectory(t),h.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp_config.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_config.json`}}})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of cf){let r=g.join(e.dirFromWorkspacePath.path,tf,n);t.push({pathKind:F.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>g.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{skills:n,fastCommands:r}=e.collectedInputContext,i=g.join(y.homedir(),nf,rf);if(n!=null)for(let e of n){let n=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),r=g.join(i,af,n);if(t.push({pathKind:F.Relative,path:`SKILL.md`,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>g.join(r,`SKILL.md`)}),e.childDocs!=null)for(let i of e.childDocs){let e=i.dir.path.replace(/\.mdx$/,`.md`),a=g.join(r,e);t.push({pathKind:F.Relative,path:e,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>a})}if(e.resources!=null)for(let i of e.resources){let e=g.join(r,i.relativePath);t.push({pathKind:F.Relative,path:i.relativePath,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>e})}}if(n?.some(e=>e.mcpConfig!=null)??!1){let e=g.join(i,sf);t.push({pathKind:F.Relative,path:sf,basePath:i,getDirectoryName:()=>rf,getAbsolutePath:()=>e})}if(r==null)return t;let a=this.getTransformOptionsFromContext(e),o=g.join(i,of);for(let e of r){let n=this.transformFastCommandName(e,a),r=g.join(o,n);t.push({pathKind:F.Relative,path:n,basePath:o,getDirectoryName:()=>of,getAbsolutePath:()=>r})}return t}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=(t?.length??0)>0,i=(n?.length??0)>0;return r||i?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=[],a=g.join(y.homedir(),nf,rf),o=g.join(a,of),s=g.join(a,af);if(t!=null)for(let n of t){let t=await this.writeFastCommand(e,o,n);r.push(...t)}if(n!=null){for(let t of n){let n=await this.writeSkill(e,s,t);r.push(...n)}let t=await this.writeGlobalMcpConfig(e,a,n);t!=null&&r.push(t)}return this.log.info({action:`write`,message:`Synced ${r.length} files to global directory`,files:r.length,globalDir:a}),{files:r,dirs:i}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,n]of Object.entries(t))r[e]=this.transformMcpConfigForAntigravity({...n})}if(Object.keys(r).length===0)return null;let i=g.join(t,sf),a={pathKind:F.Relative,path:sf,basePath:t,getDirectoryName:()=>rf,getAbsolutePath:()=>i},o={mcpServers:r},s=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(t),h.writeFileSync(i,s),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).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}}}transformMcpConfigForAntigravity(e){let t={};for(let[n,r]of Object.entries(e))if(n===`url`)t.httpUrl=r;else if(n===`type`||n===`enabled`||n===`autoApprove`)continue;else t[n]=r;return t}async writeFastCommand(e,t,n){let r=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=g.join(t,a),s={pathKind:F.Relative,path:a,basePath:t,getDirectoryName:()=>of,getAbsolutePath:()=>o},c=n.content,l=n.yamlFrontMatter,u=typeof l?.description==`string`?{description:l.description}:{},d=e=>this.buildMarkdownContentWithRaw(e,u,n.rawFrontMatter);if(c=n.rawMdxContent==null?d(c):d(n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``)),e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:o}),[{path:s,success:!0,skipped:!1}];try{this.ensureDirectory(t),h.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`fastCommand`,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:`fastCommand`,path:o,error:t}),r.push({path:s,success:!1,error:e})}return r}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=g.join(t,i),o=g.join(a,`SKILL.md`),s={pathKind:F.Relative,path:`SKILL.md`,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),h.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0}),n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,t);r.push(...n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,a,i,t);r.push(...n)}}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})}return r}async writeSkillReferenceDocument(e,t,n,r){let i=[],a=r.dir.path.replace(/\.mdx$/,`.md`),o=g.join(t,a),s={pathKind:F.Relative,path:a,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=g.dirname(o);this.ensureDirectory(e),h.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:o}),i.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:o,error:t}),i.push({path:s,success:!1,error:e})}return i}async writeSkillResource(e,t,n,r){let i=[],a=g.join(t,r.relativePath),o={pathKind:F.Relative,path:r.relativePath,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:a}),[{path:o,success:!0,skipped:!1}];try{let e=g.dirname(a);this.ensureDirectory(e),h.writeFileSync(a,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:a}),i.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:a,error:t}),i.push({path:o,success:!1,error:e})}return i}};function uf(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=df(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 df(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=ff(i,e);if(o!=null)try{let e=pf(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=ff(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=pf(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 ff(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===`
|
|
801
|
+
`,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 Yd=`AGENTS.md`;var Xd=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Yd})}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,Yd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Yd));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}}},Q=class extends Jd{inputEffects=[];registeredScopes=[];constructor(e,t){super(e,gn.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:S,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.shadowSourceProjectDir;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(Lt.USER_HOME)&&(r=r.replace(Lt.USER_HOME,y.homedir())),r.includes(Lt.SHADOW_SOURCE_PROJECT)&&(r=r.replace(Lt.SHADOW_SOURCE_PROJECT,n)),r.includes(Lt.WORKSPACE)&&(r=r.replace(Lt.WORKSPACE,t)),g.normalize(r)}readAndParseMarkdown(e,t){return Kd(t.readFileSync(e,`utf8`))}};const Zd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var Qd=class extends Q{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 Zd){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 $d=[`.qoderignore`,`.cursorignore`,`.warpindexignore`,`.aiignore`];var ef=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}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)for(let n of $d){let r=g.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:F.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>g.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>g.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t?.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,r){let i=g.join(t.path,n.fileName),a=g.join(t.basePath,i),o={pathKind:F.Relative,path:i,basePath:t.basePath,getDirectoryName:()=>g.basename(t.path),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{return h.writeFileSync(a,n.content,`utf8`),this.log.trace({action:`write`,type:`ignoreFile`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}};const tf=`.agent`,nf=`.gemini`,rf=`antigravity`,af=`skills`,of=`workflows`,sf=`mcp_config.json`,cf=[af,of];var lf=class extends Z{constructor(){super(`AntigravityOutputPlugin`,{globalConfigDir:tf,outputFileName:``,dependsOn:[`GeminiCLIOutputPlugin`]}),this.registerCleanEffect(`mcp-config-cleanup`,async e=>{let t=g.join(y.homedir(),nf,rf),n=g.join(t,sf),r={mcpServers:{}};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Would reset mcp_config.json to empty shell`};try{return this.ensureDirectory(t),h.writeFileSync(n,JSON.stringify(r,null,2)),this.log.trace({action:`clean`,type:`mcpConfigCleanup`,path:n}),{success:!0,description:`Reset mcp_config.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_config.json`}}})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of cf){let r=g.join(e.dirFromWorkspacePath.path,tf,n);t.push({pathKind:F.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>g.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{skills:n,fastCommands:r}=e.collectedInputContext,i=g.join(y.homedir(),nf,rf);if(n!=null)for(let e of n){let n=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),r=g.join(i,af,n);if(t.push({pathKind:F.Relative,path:`SKILL.md`,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>g.join(r,`SKILL.md`)}),e.childDocs!=null)for(let i of e.childDocs){let e=i.dir.path.replace(/\.mdx$/,`.md`),a=g.join(r,e);t.push({pathKind:F.Relative,path:e,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>a})}if(e.resources!=null)for(let i of e.resources){let e=g.join(r,i.relativePath);t.push({pathKind:F.Relative,path:i.relativePath,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>e})}}if(n?.some(e=>e.mcpConfig!=null)??!1){let e=g.join(i,sf);t.push({pathKind:F.Relative,path:sf,basePath:i,getDirectoryName:()=>rf,getAbsolutePath:()=>e})}if(r==null)return t;let a=this.getTransformOptionsFromContext(e),o=g.join(i,of);for(let e of r){let n=this.transformFastCommandName(e,a),r=g.join(o,n);t.push({pathKind:F.Relative,path:n,basePath:o,getDirectoryName:()=>of,getAbsolutePath:()=>r})}return t}async canWrite(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=(t?.length??0)>0,i=(n?.length??0)>0;return r||i?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{fastCommands:t,skills:n}=e.collectedInputContext,r=[],i=[],a=g.join(y.homedir(),nf,rf),o=g.join(a,of),s=g.join(a,af);if(t!=null)for(let n of t){let t=await this.writeFastCommand(e,o,n);r.push(...t)}if(n!=null){for(let t of n){let n=await this.writeSkill(e,s,t);r.push(...n)}let t=await this.writeGlobalMcpConfig(e,a,n);t!=null&&r.push(t)}return this.log.info({action:`write`,message:`Synced ${r.length} files to global directory`,files:r.length,globalDir:a}),{files:r,dirs:i}}async writeGlobalMcpConfig(e,t,n){let r={};for(let e of n){if(e.mcpConfig==null)continue;let{mcpServers:t}=e.mcpConfig;for(let[e,n]of Object.entries(t))r[e]=this.transformMcpConfigForAntigravity({...n})}if(Object.keys(r).length===0)return null;let i=g.join(t,sf),a={pathKind:F.Relative,path:sf,basePath:t,getDirectoryName:()=>rf,getAbsolutePath:()=>i},o={mcpServers:r},s=JSON.stringify(o,null,2);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).length}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(t),h.writeFileSync(i,s),this.log.trace({action:`write`,type:`globalMcpConfig`,path:i,serverCount:Object.keys(r).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}}}transformMcpConfigForAntigravity(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=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=g.join(t,a),s={pathKind:F.Relative,path:a,basePath:t,getDirectoryName:()=>of,getAbsolutePath:()=>o},c=n.content,l=n.yamlFrontMatter,u=typeof l?.description==`string`?{description:l.description}:{},d=e=>this.buildMarkdownContentWithRaw(e,u,n.rawFrontMatter);if(c=n.rawMdxContent==null?d(c):d(n.rawMdxContent.replace(/^---\n[\s\S]*?\n---\n/,``)),e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:o}),[{path:s,success:!0,skipped:!1}];try{this.ensureDirectory(t),h.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`fastCommand`,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:`fastCommand`,path:o,error:t}),r.push({path:s,success:!1,error:e})}return r}async writeSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=g.join(t,i),o=g.join(a,`SKILL.md`),s={pathKind:F.Relative,path:`SKILL.md`,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildMarkdownContentWithRaw(n.content,n.yamlFrontMatter,n.rawFrontMatter);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),h.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`skill`,path:o}),r.push({path:s,success:!0}),n.childDocs!=null)for(let t of n.childDocs){let n=await this.writeSkillReferenceDocument(e,a,i,t);r.push(...n)}if(n.resources!=null)for(let t of n.resources){let n=await this.writeSkillResource(e,a,i,t);r.push(...n)}}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})}return r}async writeSkillReferenceDocument(e,t,n,r){let i=[],a=r.dir.path.replace(/\.mdx$/,`.md`),o=g.join(t,a),s={pathKind:F.Relative,path:a,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=g.dirname(o);this.ensureDirectory(e),h.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:o}),i.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:o,error:t}),i.push({path:s,success:!1,error:e})}return i}async writeSkillResource(e,t,n,r){let i=[],a=g.join(t,r.relativePath),o={pathKind:F.Relative,path:r.relativePath,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:a}),[{path:o,success:!0,skipped:!1}];try{let e=g.dirname(a);this.ensureDirectory(e),h.writeFileSync(a,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:a}),i.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:a,error:t}),i.push({path:o,success:!1,error:e})}return i}};function uf(e,t={}){let n={},{yamlFrontMatter:r,scope:i,filePath:a}=t;for(let t of e){let e=df(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 df(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=ff(i,e);if(o!=null)try{let e=pf(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=ff(i,s.index+s[0].length);if(a==null){s=o.exec(i);continue}try{let i=pf(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 ff(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===`
|
|
802
802
|
`){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 pf(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 mf(r.slice(1,-1),`"`);if(r.startsWith(`'`)&&r.endsWith(`'`))return mf(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 mf(e,"`")}if(r.startsWith(`[`)&&r.endsWith(`]`))return gf(r,t,n);if(r.startsWith(`{`)&&r.endsWith(`}`))return _f(r,t,n);if(/^[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*$/i.test(r))return hf(r,t,n);let i=n==null?``:` in file "${n}"`;throw Error(`Expression "${r}" cannot be statically evaluated${i}`)}function mf(e,t){return e.replaceAll(`\\n`,`
|
|
803
803
|
`).replaceAll(`\\r`,`\r`).replaceAll(`\\t`,` `).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(`\\\\`,`\\`)}function hf(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 gf(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return[];if(t==null)try{let t=vf(e),n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return yf(r).map(e=>pf(e.trim(),t,n))}function _f(e,t,n){let r=e.slice(1,-1).trim();if(r===``)return{};if(t==null)try{let t=vf(e),n=JSON.parse(t);if(typeof n==`object`&&n&&!Array.isArray(n))return n}catch{}let i={},a=bf(r);for(let e of a){let r=xf(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]=pf(o,t,n)}return i}function vf(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 yf(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 bf(e){return yf(e)}function xf(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 Sf(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=o(n.value.value,t.scope);return e===`true`||e===`1`}catch{return!1}return!1}async function Cf(e,t,n){return!Sf(e,t)||e.children.length===0?[]:n(e.children,t)}async function wf(e,t){if(!Sf(e,t)||e.children.length===0)return[];let n=Tf(e.children,t);return n===``?[]:[{type:`text`,value:n}]}function Tf(e,t){let n=``;for(let r of e)if(r.type===`text`)n+=r.value;else if(r.type===`mdxTextExpression`)try{n+=o(r.value,t.scope)}catch{}else `children`in r&&Array.isArray(r.children)&&(n+=Tf(r.children,t));return n}function Ef(){i(`Md`,Cf),i(`Md.Line`,wf)}function Df(e){return vu().use(nu).use(pl).use(ei,[`yaml`]).use(w).parse(e)}Ef();function Of(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 kf(e,t){let n=Df(e),r=Of(t?.globalScope,t?.scope),i=c(),a;if(t?.extractMetadata===!0){let e=n.children.find(e=>e.type===`yaml`),i;if(e!=null)try{i=Ud.parse(e.value)}catch{}a=uf(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 u(n,{scope:r,components:i,processingStack:[],...t?.basePath!=null&&{basePath:t.basePath}}),s=vu().use(ei,[`yaml`]).use(pl).use(C,{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 Af=class extends Z{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){let r=g.join(t,e);n.push({pathKind:F.Relative,path:e,basePath:t,getDirectoryName:()=>e,getAbsolutePath:()=>r})}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=g.join(e.dirFromWorkspacePath.path,this.globalConfigDir,n);t.push({pathKind:F.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>g.join(e.dirFromWorkspacePath.basePath,r)})}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=[{pathKind:F.Relative,path:this.outputFileName,basePath:n,getDirectoryName:()=>this.globalConfigDir,getAbsolutePath:()=>g.join(n,this.outputFileName)}],{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),i=g.join(n,this.commandsSubDir,t);r.push({pathKind:F.Relative,path:g.join(this.commandsSubDir,t),basePath:n,getDirectoryName:()=>this.commandsSubDir,getAbsolutePath:()=>i})}if(this.supportsSubAgents&&a!=null)for(let e of a){let t=e.dir.path.endsWith(`.md`)?e.dir.path:`${e.dir.path}.md`,i=g.join(n,this.agentsSubDir,t);r.push({pathKind:F.Relative,path:g.join(this.agentsSubDir,t),basePath:n,getDirectoryName:()=>this.agentsSubDir,getAbsolutePath:()=>i})}if(this.supportsSkills&&o!=null)for(let e of o){let t=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=g.join(this.skillsSubDir,t);if(r.push({pathKind:F.Relative,path:g.join(i,`SKILL.md`),basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>g.join(n,i,`SKILL.md`)}),e.childDocs!=null)for(let a of e.childDocs){let e=a.dir.path.replace(/\.mdx$/,`.md`),o=g.join(i,e);r.push({pathKind:F.Relative,path:o,basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>g.join(n,o)})}if(e.resources!=null)for(let a of e.resources){let e=g.join(i,a.relativePath);r.push({pathKind:F.Relative,path:e,basePath:n,getDirectoryName:()=>t,getAbsolutePath:()=>g.join(n,e)})}}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=g.join(s,this.outputFileName),i={pathKind:F.Relative,path:this.outputFileName,basePath:s,getDirectoryName:()=>this.globalConfigDir,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),n.push({path:i,success:!0,skipped:!1});else try{this.ensureDirectory(s),h.writeFileSync(r,t.content,`utf8`),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=g.join(t,this.commandsSubDir),o=g.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 ar({toolPreset:this.toolPreset}).collect(),t=await kf(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.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,i=g.join(t,this.agentsSubDir),a=g.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=g.join(t,this.skillsSubDir,i),o=g.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=g.join(t,a);return[await this.writeFile(e,o,r.content,`skillRefDoc`)]}async writeSkillResource(e,t,n,r,i){let a=g.join(t,r.relativePath);return[await this.writeFile(e,a,r.content,`skillResource`)]}},jf=class extends Af{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:`CLAUDE.md`,toolPreset:`claudeCode`,supportsFastCommands:!0,supportsSubAgents:!0,supportsSkills:!0})}};const Mf=`AGENTS.md`,Nf=`.codex`,Pf=`prompts`,Ff=`skills`,If=`SKILL.md`;var Lf=class extends Z{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:Nf,outputFileName:Mf,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=g.join(t,Pf);n.push({pathKind:F.Relative,path:Pf,basePath:t,getDirectoryName:()=>Pf,getAbsolutePath:()=>r});let{skills:i}=e.collectedInputContext;if(i!=null&&i.length>0)for(let e of i){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),i=g.join(t,Ff,r);n.push({pathKind:F.Relative,path:g.join(Ff,r),basePath:t,getDirectoryName:()=>r,getAbsolutePath:()=>i})}return n}async registerGlobalOutputFiles(){let e=this.getGlobalConfigDir();return[{pathKind:F.Relative,path:Mf,basePath:e,getDirectoryName:()=>Nf,getAbsolutePath:()=>g.join(e,Mf)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=t!=null,a=(n?.length??0)>0,o=(r?.length??0)>0;return i||a||o?!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=[];if(t!=null){let n=this.getGlobalConfigDir(),r=g.join(n,Mf),a={pathKind:F.Relative,path:Mf,basePath:n,getDirectoryName:()=>Nf,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),h.writeFileSync(r,t.content,`utf8`),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.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}),i.push({path:a,success:!1,error:e})}}if(n!=null&&n.length>0){let t=this.getGlobalConfigDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);i.push(...n)}}if(r==null||r.length===0)return{files:i,dirs:a};let o=this.getGlobalConfigDir();for(let t of r){let n=await this.writeGlobalSkill(e,o,t);i.push(...n)}return{files:i,dirs:a}}async writeGlobalFastCommand(e,t,n){let r=[],i=this.getTransformOptionsFromContext(e),a=this.transformFastCommandName(n,i),o=g.join(t,Pf),s=g.join(o,a),c={pathKind:F.Relative,path:g.join(Pf,a),basePath:t,getDirectoryName:()=>Pf,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{this.ensureDirectory(o),h.writeFileSync(s,l,`utf8`),this.log.trace({action:`write`,type:`globalFastCommand`,path:s}),r.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalFastCommand`,path:s,error:t}),r.push({path:c,success:!1,error:e})}return r}async writeGlobalSkill(e,t,n){let r=[],i=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),a=g.join(t,Ff,i),o=g.join(a,If),s={pathKind:F.Relative,path:g.join(Ff,i,If),basePath:t,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildCodexSkillContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalSkill`,path:o}),[{path:s,success:!0,skipped:!1}];try{if(this.ensureDirectory(a),h.writeFileSync(o,c,`utf8`),this.log.trace({action:`write`,type:`globalSkill`,path:o}),r.push({path:s,success:!0}),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)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalSkill`,path:o,error:t}),r.push({path:s,success:!1,error:e})}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(` `)),Gd(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}async writeSkillReferenceDocument(e,t,n,r,i){let a=[],o=r.dir.path.replace(/\.mdx$/,`.md`),s=g.join(t,o),c={pathKind:F.Relative,path:g.join(Ff,n,o),basePath:i,getDirectoryName:()=>n,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:s}),[{path:c,success:!0,skipped:!1}];try{let e=g.dirname(s);this.ensureDirectory(e),h.writeFileSync(s,r.content,`utf8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:s}),a.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:s,error:t}),a.push({path:c,success:!1,error:e})}return a}async writeSkillResource(e,t,n,r,i){let a=[],o=g.join(t,r.relativePath),s={pathKind:F.Relative,path:g.join(Ff,n,r.relativePath),basePath:i,getDirectoryName:()=>n,getAbsolutePath:()=>o};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillResource`,path:o}),[{path:s,success:!0,skipped:!1}];try{let e=g.dirname(o);this.ensureDirectory(e),h.writeFileSync(o,r.content,`utf8`),this.log.trace({action:`write`,type:`skillResource`,path:o}),a.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillResource`,path:o,error:t}),a.push({path:s,success:!1,error:e})}return a}},Rf=class extends Af{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=g.join(t,this.skillsSubDir,i),o=g.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}},zf=class extends Q{configKey;extension;constructor(e,t){super(e),this.configKey=t.configKey,this.extension=t.extension??`.mdx`}async collect(e){let{userConfigOptions:n,logger:r,path:i,fs:a,globalScope:o}=e,s=this.resolveBasePaths(n),c=this.getTargetDir(n,s),l=[];if(!(a.existsSync(c)&&a.statSync(c).isDirectory()))return this.createResult(l);try{let e=a.readdirSync(c,{withFileTypes:!0});for(let n of e)if(n.isFile()&&n.name.endsWith(this.extension)){let e=i.join(c,n.name),s=a.readFileSync(e,`utf8`);try{let i=Kd(s),a=await kf(s,{globalScope:o,extractMetadata:!0,basePath:c}),u=i.yamlFrontMatter!=null||Object.keys(a.metadata.fields).length>0?{...i.yamlFrontMatter,...a.metadata.fields}:void 0;if(u!=null){let n=this.validateMetadata(u,e);for(let e of n.warnings)r.debug(e);if(!n.valid)throw new t([...n.errors],e)}let{content:d}=a;r.debug(`${this.name} metadata extracted`,{file:n.name,source:a.metadata.source,hasYaml:i.yamlFrontMatter!=null,hasExport:Object.keys(a.metadata.fields).length>0});let f=this.createPrompt(n.name,e,d,u,i.rawFrontMatter,i,c,s);l.push(f)}catch(t){r.error(`failed to parse ${this.name} item`,{file:e,error:t})}}}catch(e){r.error(`Failed to scan directory at ${c}`,{error:e})}return this.createResult(l)}},Bf=class extends zf{constructor(){super(`FastCommandInputPlugin`,{configKey:`shadowFastCommandDir`})}getTargetDir(e,t){let n=e.shadowFastCommandDir,{workspaceDir:r,shadowProjectDir:i}=t;return this.resolvePath(n,r,i)}validateMetadata(e,t){return wn(e,t)}createResult(e){return{fastCommands:e}}extractSeriesInfo(e){let t=e.replace(/\.mdx$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.slice(0,Math.max(0,n)),commandName:t.slice(Math.max(0,n+1))}}createPrompt(e,t,n,r,i,a,o,s){let c=this.extractSeriesInfo(e);return{type:_n.FastCommand,content:n,length:n.length,filePathKind:F.Relative,...r!=null&&{yamlFrontMatter:r},...i!=null&&{rawFrontMatter:i},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:F.Relative,path:e,basePath:o,getDirectoryName:()=>e.replace(/\.mdx$/,``),getAbsolutePath:()=>t},...c.series!=null&&{series:c.series},commandName:c.commandName,rawMdxContent:s}}},Vf=class extends Af{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:`GEMINI.md`,supportsFastCommands:!1,supportsSubAgents:!1,supportsSkills:!1})}};const Hf=`.skills`,Uf=`.skills`,Wf=`SKILL.md`,Gf=`mcp.json`;var Kf=class extends Z{constructor(){super(`GenericSkillsOutputPlugin`,{globalConfigDir:Uf,outputFileName:Wf})}getGlobalSkillsDir(){return this.joinPath(this.getHomeDir(),Uf)}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,Hf);t.push({pathKind:F.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Hf,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,Hf);for(let i of r){let r=i.yamlFrontMatter.name,a=this.joinPath(n,r);t.push({pathKind:F.Relative,path:this.joinPath(Hf,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:F.Relative,path:Uf,basePath:this.getHomeDir(),getDirectoryName:()=>Uf,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:F.Relative,path:this.joinPath(Uf,n,Wf),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Wf)}),e.mcpConfig!=null&&t.push({pathKind:F.Relative,path:this.joinPath(Uf,n,Gf),basePath:this.getHomeDir(),getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(i,Gf)}),e.childDocs!=null)for(let r of e.childDocs){let e=r.relativePath.replace(/\.mdx$/,`.md`);t.push({pathKind:F.Relative,path:this.joinPath(Uf,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:F.Relative,path:this.joinPath(Uf,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,Hf);for(let o of n){let n=o.yamlFrontMatter.name,s=this.joinPath(a,n),c=this.joinPath(t,n),l={pathKind:F.Relative,path:this.joinPath(Hf,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,Wf),s={pathKind:F.Relative,path:Wf,basePath:a,getDirectoryName:()=>i,getAbsolutePath:()=>o},c=this.buildSkillFrontMatter(t),l=t.content,u=Gd(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,Gf),a={pathKind:F.Relative,path:Gf,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:F.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:F.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=T.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}}}},qf=class extends Q{constructor(){super(`GitExcludeInputPlugin`)}collect(e){let{shadowProjectDir:t}=this.resolveBasePaths(e.userConfigOptions),n=g.join(t,`public`,`exclude`);if(!h.existsSync(n))return this.log.debug({action:`collect`,message:`No exclude file found in shadow project`,path:n}),{};let r=h.readFileSync(n,`utf8`);return r.length===0?(this.log.debug({action:`collect`,message:`Exclude file is empty`,path:n}),{}):(this.log.debug({action:`collect`,message:`Loaded git exclude from shadow project`,path:n}),{shadowGitExclude:r})}},Jf=class extends Z{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(),i=g.join(r,`.git`,`info`);if(h.existsSync(i)){let e=g.join(n.path,`.git`,`info`,`exclude`),r=n.path,{basePath:i}=n;t.push({pathKind:F.Relative,path:e,basePath:i,getDirectoryName:()=>g.basename(r),getAbsolutePath:()=>g.join(i,e)})}}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=g.join(e.dirFromWorkspacePath.getAbsolutePath(),`.git`,`info`);return h.existsSync(t)}),a=g.join(e.collectedInputContext.workspace.directory.path,`.git`,`info`),o=h.existsSync(a),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;for(let n of o){if(n.dirFromWorkspacePath==null)continue;let r=n.dirFromWorkspacePath.getAbsolutePath(),a=g.join(r,`.git`,`info`),o=g.join(r,`.git`,`info`,`exclude`);if(!h.existsSync(a)){this.log.debug({action:`write`,path:o,message:`Git info directory does not exist, skipping`,project:n.name??`unknown`});continue}this.log.info({action:`write`,path:o,project:n.name??`unknown`});let s=await this.writeGitExcludeFile(e,o,i,`project:${n.name??`unknown`}`);t.push(s)}let s=a.directory.path,c=g.join(s,`.git`,`info`),l=g.join(s,`.git`,`info`,`exclude`);if(new Set(o.map(e=>e.dirFromWorkspacePath?.getAbsolutePath()).filter(Boolean)).has(s)&&h.existsSync(c))return{files:t,dirs:[]};this.log.info({action:`write`,path:l,target:`workspace`});let u=await this.writeGitExcludeFile(e,l,i,`workspace`);return t.push(u),{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(`
|
|
804
804
|
`)}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