@truenine/memory-sync-cli 2026.10314.10813 → 2026.10314.11719

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as ee,X as te,Y as ne,Z as re,_ as ie,a as ae,at as C,b as oe,c as se,ct as ce,d as w,dt as le,et as T,f as ue,g as de,h as E,i as fe,it as D,j as O,k,l as pe,lt as me,m as A,n as he,nt as j,o as ge,ot as _e,p as ve,q as ye,r as be,rt as xe,s as Se,st as M,t as Ce,tt as we,u as N,ut as Te,v as Ee,w as De,x as Oe,y as ke,z as Ae}from"./plugin-runtime.mjs";import*as P from"node:fs";import*as F from"node:path";import I from"node:process";import*as L from"node:os";import{Buffer as R}from"node:buffer";import{parse as je}from"jsonc-parser";const Me=`.agents/skills`,Ne=`SKILL.md`;var Pe=class extends E{constructor(){super(`GenericSkillsOutputPlugin`,{outputFileName:Ne,skills:{},cleanup:{delete:{project:{dirs:[Me]}}},capabilities:{skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0},mcp:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{skills:r}=e.collectedOutputContext;if(r==null||r.length===0)return t;let i=this.selectSingleScopeItems(r,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)),o=this.selectSingleScopeItems(r,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`mcp`)??this.getTopicScopeOverride(e,`skills`));for(let e of n){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=a(i.items,e.projectConfig,`skills`),s=a(o.items,e.projectConfig,`skills`);if(r.length===0)continue;let c=this.joinPath(n.basePath,n.path,Me);for(let e of r){let n=e.yamlFrontMatter.name,r=this.joinPath(c,n);if(t.push({path:this.joinPath(r,Ne),scope:`project`,source:{kind:`skillMain`,skill:e}}),e.mcpConfig!=null&&s.includes(e)&&t.push({path:this.joinPath(r,`mcp.json`),scope:`project`,source:{kind:`skillMcp`,rawContent:e.mcpConfig.rawContent}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:this.joinPath(r,n.relativePath.replace(/\.mdx$/,`.md`)),scope:`project`,source:{kind:`skillChildDoc`,content:n.content}});if(e.resources!=null)for(let n of e.resources)t.push({path:this.joinPath(r,n.relativePath),scope:`project`,source:{kind:`skillResource`,content:n.content,encoding:n.encoding}})}}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`skillMain`:return C(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillMcp`:return n.rawContent;case`skillChildDoc`:return n.content;case`skillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;default:throw Error(`Unsupported declaration source for ${this.name}`)}}};const Fe=`AGENTS.md`;var Ie=class extends E{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Fe,cleanup:{delete:{project:{files:[Fe]}}},capabilities:{prompt:{scopes:[`project`],singleScope:!1}}})}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace;if(!new Set(this.selectPromptScopes(e,[`project`])).has(`project`))return t;for(let[e,r]of n.entries())if(r.rootMemoryPrompt!=null&&r.dirFromWorkspacePath!=null&&t.push({path:this.resolveFullPath(r.dirFromWorkspacePath),scope:`project`,source:{type:`projectRootMemory`,projectIndex:e}}),r.childMemoryPrompts!=null)for(let[n,i]of r.childMemoryPrompts.entries())t.push({path:this.resolveFullPath(i.dir),scope:`project`,source:{type:`projectChildMemory`,projectIndex:e,childIndex:n}});return t}async convertContent(e,t){let{projects:n}=t.collectedOutputContext.workspace,r=e.source,i=r.projectIndex??-1;if(i<0||i>=n.length)throw Error(`Invalid project index in declaration for ${this.name}`);let a=n[i];if(a==null)throw Error(`Project not found for declaration in ${this.name}`);if(r.type===`projectRootMemory`){if(a.rootMemoryPrompt==null)throw Error(`Root memory prompt missing for project index ${i}`);return a.rootMemoryPrompt.content}if(r.type===`projectChildMemory`){let e=r.childIndex??-1,t=a.childMemoryPrompts?.[e];if(t==null)throw Error(`Child memory prompt missing for project ${i}, child ${e}`);return t.content}throw Error(`Unsupported declaration source for ${this.name}`)}};const Le=`CLAUDE.md`;var Re=class extends E{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:Le,toolPreset:`claudeCode`,commands:{subDir:`commands`,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},subagents:{subDir:`agents`,sourceScopes:[`project`],includePrefix:!0,linkSymbol:`-`,ext:`.md`},skills:{subDir:`skills`},rules:{transformFrontMatter:e=>({paths:e.globs.map(_e)})},cleanup:{delete:{project:{files:[Le],dirs:[`.claude/rules`,`.claude/commands`,`.claude/agents`,`.claude/skills`]},workspace:{dirs:[`.claude/rules`,`.claude/commands`,`.claude/agents`,`.claude/skills`]},global:{files:[`.claude/CLAUDE.md`],dirs:[`.claude/rules`,`.claude/commands`,`.claude/agents`,`.claude/skills`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},rules:{scopes:[`project`,`workspace`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},subagents:{scopes:[`project`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}};const z=g.CURSOR,ze=l.MCP_CONFIG,Be=f.COMMANDS,B=f.RULES,Ve=l.CURSOR_GLOBAL_RULE,V=f.CURSOR_SKILLS,He=l.SKILL,Ue=Ae.CURSOR;var We=class extends E{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:z,outputFileName:``,dependsOn:[v.AgentsOutput],indexignore:o.CURSOR,commands:{subDir:Be,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:V},rules:{subDir:B,prefix:`rule`,sourceScopes:[`project`,`global`]},cleanup:{delete:{project:{dirs:[`.cursor/rules`]},global:{files:[`.cursor/mcp.json`],dirs:[`.cursor/commands`,`.cursor/rules`],globs:[`.cursor/skills-cursor/*`]}},protect:{global:{dirs:[...Ue].map(e=>`.cursor/skills-cursor/${e}`)}}},capabilities:{prompt:{scopes:[`global`],singleScope:!1},rules:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0},mcp:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareCleanupPaths(e){let t=await super.declareCleanupPaths(e);return{...t,delete:this.expandCursorSkillCleanupTargets(e,t.delete??[])}}async declareOutputFiles(e){let t=[],{workspace:n,globalMemory:r,commands:i,skills:o,rules:s,aiAgentIgnoreConfigFiles:c}=e.collectedOutputContext,l=this.getGlobalConfigDir(),u=this.resolvePromptSourceProjectConfig(e),d=new Set(this.selectPromptScopes(e,[`global`])),f=a((o==null?{items:[]}:this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`))).items,u,`skills`),p=a((o==null?{items:[]}:this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`mcp`)??this.getTopicScopeOverride(e,`skills`))).items,u,`skills`);if(f.length>0)for(let e of f){let n=e.yamlFrontMatter.name;if(this.isPreservedSkill(n))continue;let r=F.join(l,V,n);if(t.push({path:F.join(r,He),scope:`global`,source:{kind:`globalSkill`,skill:e}}),e.mcpConfig!=null&&p.includes(e)&&t.push({path:F.join(r,ze),scope:`global`,source:{kind:`globalSkillMcpConfig`,rawContent:e.mcpConfig.rawContent}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:F.join(r,n.relativePath.replace(/\.mdx$/,`.md`)),scope:`global`,source:{kind:`globalSkillChildDoc`,content:n.content}});if(e.resources!=null)for(let n of e.resources)t.push({path:F.join(r,n.relativePath),scope:`global`,source:{kind:`globalSkillResource`,content:n.content,encoding:n.encoding}})}if(p.length>0){let n=new Se({fs:e.fs,logger:this.log}),r=n.collectMcpServers(p);if(r.size>0){let e=n.transformMcpServers(r,se);t.push({path:F.join(l,ze),scope:`global`,source:{kind:`globalMcpConfig`,mcpServers:e}})}}if(i!=null&&i.length>0){let n=a(this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)).items,u,`commands`),r=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of n){let n=this.transformCommandName(e,r);t.push({path:F.join(l,Be,n),scope:`global`,source:{kind:`globalCommand`,command:e}})}}let m=new Set(s==null?[]:this.selectRuleScopes(e,s)),h=s?.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`global`);if(h!=null&&m.has(`global`))for(let e of h)t.push({path:F.join(l,B,this.buildRuleFileName(e)),scope:`global`,source:{kind:`ruleMdc`,rule:e}});if(r!=null&&d.has(`global`)){let e=this.buildGlobalRuleContent(r.content);for(let r of n.projects){let n=r.dirFromWorkspacePath;n!=null&&t.push({path:F.join(n.basePath,n.path,z,B,Ve),scope:`project`,source:{kind:`projectGlobalRule`,content:e}})}}if(s!=null&&s.length>0&&m.has(`project`))for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=b(a(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of r)t.push({path:F.join(n.basePath,n.path,z,B,this.buildRuleFileName(e)),scope:`project`,source:{kind:`ruleMdc`,rule:e}})}let g=this.getIgnoreOutputPath(),_=this.indexignore==null?void 0:c?.find(e=>e.fileName===this.indexignore);if(g!=null&&_!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:F.join(n.basePath,n.path,g),scope:`project`,source:{kind:`projectIgnoreFile`,content:_.content}})}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`globalCommand`:return this.buildCommandContent(n.command);case`globalMcpConfig`:return JSON.stringify({mcpServers:n.mcpServers},null,2);case`globalSkill`:return C(this.buildSkillFrontMatter(n.skill),n.skill.content);case`globalSkillMcpConfig`:return n.rawContent;case`globalSkillChildDoc`:case`projectGlobalRule`:case`projectIgnoreFile`:return n.content;case`globalSkillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;case`ruleMdc`:return this.buildRuleMdcContent(n.rule);default:throw Error(`Unsupported declaration source for ${this.name}`)}}buildGlobalRuleContent(e){return C({description:`Global prompt (synced)`,alwaysApply:!0},e)}isPreservedSkill(e){return Ue.has(e)}expandCursorSkillCleanupTargets(e,t){let n=[];for(let r of t){if(!this.isCursorSkillCleanupGlob(r)){n.push(r);continue}for(let t of this.listCursorSkillCleanupTargets(e,r.path))n.push({path:t.path,kind:t.kind,...r.scope==null?{}:{scope:r.scope},...r.label==null?{}:{label:r.label}})}return n}isCursorSkillCleanupGlob(e){if(e.kind!==`glob`)return!1;let t=this.joinPath(this.getGlobalConfigDir(),V,`*`).replaceAll(`\\`,`/`);return e.path.replaceAll(`\\`,`/`)===t}listCursorSkillCleanupTargets(e,t){return e.glob.sync(t.replaceAll(`\\`,`/`),{onlyFiles:!1,dot:!0,absolute:!0,followSymbolicLinks:!1}).flatMap(t=>{if(this.isPreservedSkill(F.basename(t)))return[];try{return[{path:t,kind:e.fs.lstatSync(t).isDirectory()?`directory`:`file`}]}catch{return[]}})}buildRuleMdcContent(e){return C({alwaysApply:!1,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
2
+ `).map(e=>{let t=/^(\s*globs:\s*)(['"])(.*)\2\s*$/.exec(e);if(t==null)return e;let n=t[1]??`globs: `,r=t[3]??``;return r.trim().length===0?e:`${n}${r}`}).join(`
3
+ `)}};const Ge=`AGENTS.md`;var Ke=class extends E{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:`.factory`,outputFileName:Ge,commands:{transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{},cleanup:{delete:{project:{files:[Ge],dirs:[`.factory/commands`,`.factory/skills`]},workspace:{dirs:[`.factory/commands`,`.factory/skills`]},global:{files:[`.factory/AGENTS.md`],dirs:[`.factory/commands`,`.factory/skills`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}buildSkillMainContent(e){let t=e.yamlFrontMatter==null?void 0:{name:e.yamlFrontMatter.name,description:e.yamlFrontMatter.description};return this.buildMarkdownContent(e.content,t)}};const qe=`.editorconfig`;var Je=class extends E{constructor(){super(`EditorConfigOutputPlugin`,{cleanup:{delete:{project:{files:[qe]}}},capabilities:{}})}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{editorConfigFiles:r}=e.collectedOutputContext;if(r==null||r.length===0)return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of r)t.push({path:this.resolvePath(n.basePath,n.path,qe),scope:`project`,source:{content:e.content}})}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}};const Ye=`GEMINI.md`;var Xe=class extends E{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:Ye,cleanup:{delete:{project:{globs:[Ye]},global:{files:[`.gemini/GEMINI.md`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1}}})}},Ze=class extends E{constructor(){super(`GitExcludeOutputPlugin`,{capabilities:{}})}async declareOutputFiles(e){let t=[],{workspace:n,globalGitIgnore:r,shadowGitExclude:a}=e.collectedOutputContext,o=this.buildManagedContent(r,a);if(o.length===0)return t;let s=this.normalizeContent(o),c=new Set,{projects:l}=n;for(let e of l){if(e.dirFromWorkspacePath==null)continue;let n=e.dirFromWorkspacePath.getAbsolutePath(),r=[n,...i(n)];for(let e of r){let n=k(e);if(n==null)continue;let r=F.join(n,`exclude`);c.has(r)||(c.add(r),t.push({path:r,scope:`project`,source:{content:s}}))}}let u=n.directory.path,d=k(u);if(d!=null){let e=F.join(d,`exclude`);c.has(e)||(c.add(e),t.push({path:e,scope:`workspace`,source:{content:s}}))}let f=i(u);for(let e of f){let n=k(e);if(n==null)continue;let r=F.join(n,`exclude`);c.has(r)||(c.add(r),t.push({path:r,scope:`workspace`,source:{content:s}}))}let p=F.join(u,`.git`);if(this.existsSync(p)&&this.lstatSync(p).isDirectory())for(let e of h(p)){let n=F.join(e,`exclude`);c.has(n)||(c.add(n),t.push({path:n,scope:`workspace`,source:{content:s}}))}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}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(`
4
+ `)}sanitizeContent(e){return e.split(/\r?\n/).filter(e=>{let t=e.trim();return t.length===0?!0:!(t.startsWith(`#`)&&!t.startsWith(`\\#`))}).join(`
5
+ `).trim()}normalizeContent(e){let t=e.trim();return t.length===0?``:`${t}\n`}};const H=`AGENTS.md`,Qe=`prompts`,U=`skills`,$e=[`IntelliJIdea`,`WebStorm`,`RustRover`,`PyCharm`,`PyCharmCE`,`PhpStorm`,`GoLand`,`CLion`,`DataGrip`,`RubyMine`,`Rider`,`DataSpell`,`Aqua`];var et=class extends E{constructor(){super(`JetBrainsAIAssistantCodexOutputPlugin`,{outputFileName:H,commands:{subDir:Qe,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:U},dependsOn:[v.AgentsOutput],indexignore:`.aiignore`,cleanup:{delete:{project:{dirs:[`.aiassistant/rules`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let t=[],{workspace:n,globalMemory:r,commands:i,skills:o,aiAgentIgnoreConfigFiles:s}=e.collectedOutputContext,{projects:c}=n,l=this.resolveCodexDirs(),u=new Set(this.selectPromptScopes(e,[`project`,`global`]));if(u.has(`project`))for(let e of c){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=F.join(n.basePath,n.path,`.aiassistant`,`rules`);if(e.rootMemoryPrompt!=null&&t.push({path:F.join(r,`always.md`),scope:`project`,source:{kind:`projectRuleContent`,content:this.buildAlwaysRuleContent(e.rootMemoryPrompt.content)}}),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)t.push({path:F.join(r,this.buildChildRuleFileName(n)),scope:`project`,source:{kind:`projectRuleContent`,content:this.buildGlobRuleContent(n)}})}if(l.length>0){let n=this.resolvePromptSourceProjectConfig(e),s=a((i==null?{items:[]}:this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`))).items,n,`commands`),c=a((o==null?{items:[]}:this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`))).items,n,`skills`),d=this.getTransformOptionsFromContext(e);for(let e of l){r!=null&&u.has(`global`)&&t.push({path:F.join(e,H),scope:`global`,source:{kind:`globalMemory`,content:r.content}});for(let n of s)t.push({path:F.join(e,Qe,this.transformCommandName(n,d)),scope:`global`,source:{kind:`command`,command:n}});for(let n of c){let r=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),i=F.join(e,U,r);if(t.push({path:F.join(i,`SKILL.md`),scope:`global`,source:{kind:`globalSkill`,skill:n}}),n.childDocs!=null)for(let e of n.childDocs)t.push({path:F.join(i,e.dir.path.replace(/\.mdx$/,`.md`)),scope:`global`,source:{kind:`skillReference`,content:e.content}});if(n.resources!=null)for(let e of n.resources)t.push({path:F.join(i,e.relativePath),scope:`global`,source:{kind:`skillResource`,content:e.content}})}}}let d=this.getIgnoreOutputPath(),f=this.indexignore==null?void 0:s?.find(e=>e.fileName===this.indexignore);if(d!=null&&f!=null)for(let e of c){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:F.join(n.basePath,n.path,d),scope:`project`,source:{kind:`ignoreFile`,content:f.content}})}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`projectRuleContent`:case`globalMemory`:case`skillReference`:case`skillResource`:case`ignoreFile`:return n.content;case`command`:return this.buildCommandContent(n.command);case`globalSkill`:return this.buildCodexSkillContent(n.skill);default:throw Error(`Unsupported declaration source for ${this.name}`)}}async declareCleanupPaths(e){let t=await super.declareCleanupPaths(e),n=this.resolveCodexDirs();if(n.length===0)return t;let r=n.flatMap(e=>[{path:F.join(e,H),kind:`file`,scope:`global`},{path:F.join(e,Qe),kind:`directory`,scope:`global`},{path:F.join(e,U),kind:`directory`,scope:`global`}]),i=t.delete??[];return{...t,delete:[...i,...r]}}resolveCodexDirs(){let e=F.join(me(),`JetBrains`);if(!this.existsSync(e))return[];try{return this.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()?this.isSupportedIdeDir(e.name):!1).map(t=>F.join(e,t.name,`aia`,`codex`))}catch(t){let n=t instanceof Error?t.message:String(t);return this.log.warn({action:`scan`,type:`jetbrains`,path:e,error:n}),[]}}buildChildRuleFileName(e){let t=(e.workingChildDirectoryPath?.path??e.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``).replaceAll(`/`,`-`);return`glob-${t.length>0?t:`root`}.md`}buildChildRulePattern(e){let t=(e.workingChildDirectoryPath?.path??e.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``);return t.length===0?`**/*`:`${t}/**`}buildAlwaysRuleContent(e){return C({apply:`始终`},e)}buildGlobRuleContent(e){return C({apply:`按文件模式`,模式:this.buildChildRulePattern(e)},e.content)}isSupportedIdeDir(e){return $e.some(t=>e.startsWith(t))}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(` `)),C(a,e.content)}normalizeSkillName(e,t){let n=e.toLowerCase().replaceAll(/[^a-z0-9-]/g,`-`).replaceAll(/-+/g,`-`).replaceAll(/^-+|-+$/g,``);return n.length>t&&(n=n.slice(0,t).replace(/-+$/,``)),n}normalizeToSingleLine(e,t){let n=e.replaceAll(/[\r\n]+/g,` `).replaceAll(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}};const tt=`.idea`;var nt=class extends E{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`,{cleanup:{delete:{project:{files:[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`]}}},capabilities:{}})}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{jetbrainsConfigFiles:r,editorConfigFiles:i}=e.collectedOutputContext,a=[...r??[],...i??[]];for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of a){let r=this.getTargetRelativePath(e);t.push({path:this.resolvePath(n.basePath,n.path,r),scope:`project`,source:{content:e.content}})}}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}getTargetRelativePath(e){let t=e.dir.path;if(e.type===j.EditorConfig)return`.editorconfig`;if(e.type!==j.IntellijIDEA)return this.basename(t);let n=t.indexOf(tt);return n===-1?this.joinPath(tt,`codeStyles`,this.basename(t)):t.slice(Math.max(0,n))}};const rt=`AGENTS.md`,it=`prompts`;var at=class extends E{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:`.codex`,outputFileName:rt,commands:{subDir:it,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},cleanup:{delete:{global:{files:[`.codex/AGENTS.md`],dirs:[`.codex/prompts`]}},protect:{global:{dirs:[`.codex/skills/.system`]}}},dependsOn:[v.AgentsOutput],capabilities:{prompt:{scopes:[`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let{globalMemory:t,commands:n}=e.collectedOutputContext,r=this.getGlobalConfigDir(),i=[],o=new Set(this.selectPromptScopes(e,[`global`]));if(t!=null&&o.has(`global`)&&i.push({path:F.join(r,rt),scope:`global`,source:{kind:`globalMemory`,content:t.content}}),n==null||n.length===0)return i;let s=this.resolvePromptSourceProjectConfig(e),c=this.getTransformOptionsFromContext(e),l=this.selectSingleScopeItems(n,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`));if(l.items.length===0)return i;let u=a(l.items,s,`commands`);for(let e of u){let t=this.transformCommandName(e,c);i.push({path:F.join(r,it,t),scope:`global`,source:{kind:`command`,command:e}})}return i}async convertContent(e,t){let n=e.source;if(n.kind===`globalMemory`)return n.content;if(n.kind===`command`)return this.buildCommandContent(n.command);throw Error(`Unsupported declaration source for ${this.name}`)}};const W=`AGENTS.md`;function ot(e,t){let n={},r=t.sourceFrontMatter;if(r?.description!=null&&(n.description=r.description),r?.agent!=null&&(n.agent=r.agent),r?.model!=null&&(n.model=r.model),r?.allowTools!=null&&Array.isArray(r.allowTools)){let e={};for(let t of r.allowTools)e[String(t)]=!0;n.tools=e}for(let[e,t]of Object.entries(r??{}))[`description`,`agent`,`model`,`allowTools`,`namingCase`,`argumentHint`].includes(e)||(n[e]=t);return n}var st=class extends E{constructor(){super(`OpencodeCLIOutputPlugin`,{globalConfigDir:`.config/opencode`,outputFileName:W,commands:{subDir:`commands`,transformFrontMatter:ot},subagents:{subDir:`agents`},skills:{subDir:`skills`},cleanup:{delete:{project:{files:[W],dirs:[`.opencode/commands`,`.opencode/agents`,`.opencode/skills`]},global:{files:[`.config/opencode/AGENTS.md`,`.config/opencode/opencode.json`],dirs:[`.config/opencode/commands`,`.config/opencode/agents`,`.config/opencode/skills`]},xdgConfig:{files:[`opencode/AGENTS.md`,`opencode/opencode.json`],dirs:[`opencode/commands`,`opencode/agents`,`opencode/skills`]}}},dependsOn:[v.AgentsOutput],capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},subagents:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0},mcp:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let t=[],{workspace:n,globalMemory:r,commands:i,subAgents:o,skills:s}=e.collectedOutputContext,c=this.getGlobalConfigDir(),l=new Set(this.selectPromptScopes(e,[`project`,`global`])),u=i==null?{items:[]}:this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)),d=o==null?{items:[]}:this.selectSingleScopeItems(o,this.subAgentsConfig.sourceScopes,e=>this.resolveSubAgentSourceScope(e),this.getTopicScopeOverride(e,`subagents`)),f=s==null?{items:[]}:this.selectSingleScopeItems(s,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)),p=s==null?{items:[]}:this.selectSingleScopeItems(s,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`mcp`)??this.getTopicScopeOverride(e,`skills`));if(r!=null&&l.has(`global`)&&t.push({path:F.join(c,W),scope:`global`,source:{kind:`globalMemory`,content:r.content}}),p.items.length>0){let n=this.resolvePromptSourceProjectConfig(e),r=a(p.items,n,`skills`),i=new Se({fs:e.fs,logger:this.log}),o=i.collectMcpServers(r);o.size>0&&t.push({path:F.join(c,`opencode.json`),scope:`global`,source:{kind:`globalMcpConfig`,mcpServers:i.transformMcpServers(o,pe)}})}let m=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=F.join(n.basePath,n.path,`.opencode`);if(e.rootMemoryPrompt!=null&&l.has(`project`)&&t.push({path:this.resolveFullPath(n),scope:`project`,source:{kind:`projectRootMemory`,content:e.rootMemoryPrompt.content}}),e.childMemoryPrompts!=null&&l.has(`project`))for(let n of e.childMemoryPrompts)t.push({path:this.resolveFullPath(n.dir),scope:`project`,source:{kind:`projectChildMemory`,content:n.content}});if(this.commandOutputEnabled&&u.items.length>0){let n=a(u.items,e.projectConfig,`commands`);for(let e of n)t.push({path:F.join(r,this.commandsConfig.subDir,this.transformCommandName(e,m)),scope:`project`,source:{kind:`command`,command:e}})}if(this.subAgentOutputEnabled&&d.items.length>0){let n=a(d.items,e.projectConfig,`subAgents`),{subDir:i}=this.subAgentsConfig;for(let e of n)t.push({path:F.join(r,i,this.transformSubAgentName(e)),scope:`project`,source:{kind:`subAgent`,agent:e}})}if(this.skillOutputEnabled&&f.items.length>0){let n=a(f.items,e.projectConfig,`skills`);for(let e of n){let n=this.validateAndNormalizeSkillName(e.yamlFrontMatter?.name??e.dir.getDirectoryName()),i=F.join(r,this.skillsConfig.subDir,n);if(t.push({path:F.join(i,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:e,normalizedSkillName:n}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:F.join(i,n.dir.path.replace(/\.mdx$/,`.md`)),scope:`project`,source:{kind:`skillReference`,content:n.content}});if(e.resources!=null)for(let n of e.resources)t.push({path:F.join(i,n.relativePath),scope:`project`,source:{kind:`skillResource`,content:n.content,encoding:n.encoding}})}}}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`globalMemory`:case`projectRootMemory`:case`projectChildMemory`:case`skillReference`:return n.content;case`command`:return this.buildCommandContent(n.command);case`subAgent`:{let e=this.buildOpencodeAgentFrontMatter(n.agent);return this.buildMarkdownContent(n.agent.content,e)}case`skillMain`:{let e=this.buildOpencodeSkillFrontMatter(n.skill,n.normalizedSkillName);return this.buildMarkdownContent(n.skill.content,e)}case`skillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;case`globalMcpConfig`:return JSON.stringify({$schema:`https://opencode.ai/config.json`,plugin:[`opencode-rules@latest`],mcp:n.mcpServers},null,2);default:throw Error(`Unsupported declaration source for ${this.name}`)}}buildOpencodeAgentFrontMatter(e){let t={},n=e.yamlFrontMatter;if(n?.description!=null&&(t.description=n.description),t.mode=n?.mode??`subagent`,n?.model!=null&&(t.model=n.model),n?.temperature!=null&&(t.temperature=n.temperature),n?.maxSteps!=null&&(t.maxSteps=n.maxSteps),n?.hidden!=null&&(t.hidden=n.hidden),n?.allowTools!=null&&Array.isArray(n.allowTools)){let e={};for(let t of n.allowTools)e[String(t)]=!0;t.tools=e}n?.permission!=null&&typeof n.permission==`object`&&(t.permission=n.permission);for(let[e,r]of Object.entries(n??{}))[`description`,`mode`,`model`,`temperature`,`maxSteps`,`hidden`,`allowTools`,`permission`,`namingCase`,`name`,`color`].includes(e)||(t[e]=r);return t}buildOpencodeSkillFrontMatter(e,t){let n={},r=e.yamlFrontMatter;n.name=t,r?.description!=null&&(n.description=r.description),n.license=r?.license??`MIT`,n.compatibility=r?.compatibility??`opencode`;let i={};for(let e of[`author`,`version`,`keywords`,`category`,`repository`,`displayName`])r?.[e]!=null&&(i[e]=r[e]);let a=new Set([`name`,`description`,`license`,`compatibility`,`namingCase`,`allowTools`,`keywords`,`displayName`,`author`,`version`]);for(let[e,t]of Object.entries(r??{}))a.has(e)||(i[e]=t);return Object.keys(i).length>0&&(n.metadata=i),n}validateAndNormalizeSkillName(e){let t=e.toLowerCase();return t=t.replaceAll(/[^a-z0-9-]+/g,`-`),t=t.replaceAll(/-+/g,`-`),t=t.replaceAll(/^-|-$/g,``),t.length===0?t=`skill`:t.length>64&&(t=t.slice(0,64),t=t.replace(/-$/,``)),t}};const ct=`.qoder`,G=`rules`,lt=`commands`,ut=`skills`,dt=`glob`,ft=`glob`;function pt(e,t){let n=t.sourceFrontMatter,r={description:`Fast command`,type:`user_command`};return n?.description!=null&&(r.description=n.description),n?.argumentHint!=null&&(r.argumentHint=n.argumentHint),n?.allowTools!=null&&Array.isArray(n.allowTools)&&n.allowTools.length>0&&(r.allowTools=n.allowTools),r}var mt=class extends E{constructor(){super(`QoderIDEPluginOutputPlugin`,{globalConfigDir:ct,indexignore:`.qoderignore`,commands:{subDir:lt,transformFrontMatter:pt},skills:{subDir:ut},rules:{subDir:G,sourceScopes:[`project`,`global`]},cleanup:{delete:{project:{dirs:[`.qoder/rules`]},global:{dirs:[`.qoder/commands`,`.qoder/rules`,`.qoder/skills`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},rules:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0},mcp:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let t=[],{workspace:n,globalMemory:r,commands:i,skills:o,rules:s,aiAgentIgnoreConfigFiles:c}=e.collectedOutputContext,{projects:l}=n,u=this.getGlobalConfigDir(),d=this.resolvePromptSourceProjectConfig(e),f=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0}),p=new Set(s==null?[]:this.selectRuleScopes(e,s)),m=new Set(this.selectPromptScopes(e,[`project`,`global`]));if(i!=null&&i.length>0){let n=a(this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)).items,d,`commands`);for(let e of n)t.push({path:F.join(u,lt,this.transformCommandName(e,f)),scope:`global`,source:{kind:`command`,command:e}})}if(s!=null&&s.length>0&&p.has(`global`)){let e=s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`global`);for(let n of e)t.push({path:F.join(u,G,this.buildRuleFileName(n)),scope:`global`,source:{kind:`rulePrompt`,rule:n}})}if(o!=null&&o.length>0){let n=a(this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)).items,d,`skills`),r=a(this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`mcp`)??this.getTopicScopeOverride(e,`skills`)).items,d,`skills`);for(let e of n){let n=e.yamlFrontMatter.name,i=F.join(u,ut,n);if(t.push({path:F.join(i,`SKILL.md`),scope:`global`,source:{kind:`skillMain`,skill:e}}),e.mcpConfig!=null&&r.includes(e)&&t.push({path:F.join(i,`mcp.json`),scope:`global`,source:{kind:`skillMcpConfig`,rawContent:e.mcpConfig.rawContent}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:F.join(i,n.relativePath.replace(/\.mdx$/,`.md`)),scope:`global`,source:{kind:`skillChildDoc`,content:n.content}});if(e.resources!=null)for(let n of e.resources)t.push({path:F.join(i,n.relativePath),scope:`global`,source:{kind:`skillResource`,content:n.content,encoding:n.encoding}})}}for(let e of l){let n=e.dirFromWorkspacePath;if(n==null)continue;let i=F.join(n.basePath,n.path,ct,G);if(r!=null&&m.has(`global`)&&t.push({path:F.join(i,`global.md`),scope:`project`,source:{kind:`ruleContent`,content:this.buildAlwaysRuleContent(r.content)}}),e.rootMemoryPrompt!=null&&m.has(`project`)&&t.push({path:F.join(i,`always.md`),scope:`project`,source:{kind:`ruleContent`,content:this.buildAlwaysRuleContent(e.rootMemoryPrompt.content)}}),e.childMemoryPrompts!=null&&m.has(`project`))for(let n of e.childMemoryPrompts)t.push({path:F.join(i,this.buildChildRuleFileName(n)),scope:`project`,source:{kind:`ruleContent`,content:this.buildGlobRuleContent(n)}});if(s!=null&&s.length>0&&p.has(`project`)){let n=b(a(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of n)t.push({path:F.join(i,this.buildRuleFileName(e)),scope:`project`,source:{kind:`rulePrompt`,rule:e}})}}let h=this.getIgnoreOutputPath(),g=this.indexignore==null?void 0:c?.find(e=>e.fileName===this.indexignore);if(h!=null&&g!=null)for(let e of l){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:F.join(n.basePath,n.path,h),scope:`project`,source:{kind:`ignoreFile`,content:g.content}})}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`command`:return this.buildCommandContent(n.command);case`ruleContent`:return n.content;case`rulePrompt`:return this.buildRuleContent(n.rule);case`skillMain`:return C(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillMcpConfig`:return n.rawContent;case`skillChildDoc`:case`ignoreFile`:return n.content;case`skillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;default:throw Error(`Unsupported declaration source for ${this.name}`)}}buildChildRuleFileName(e){let t=(e.workingChildDirectoryPath?.path??e.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``).replaceAll(`/`,`-`);return`glob-${t.length>0?t:`root`}.md`}buildAlwaysRuleContent(e){return C({trigger:`always_on`,type:`user_command`},e)}buildGlobRuleContent(e){let t=(e.workingChildDirectoryPath?.path??e.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``),n=t.length===0?`**/*`:`${t}/**`;return C({trigger:dt,[ft]:n,type:`user_command`},e.content)}buildSkillFrontMatter(e){let t=e.yamlFrontMatter;return{name:t.name,description:t.description,type:`user_command`,...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}}}buildRuleFileName(e,t=`rule-`){return`${t}${e.prefix}-${e.ruleName}.md`}buildRuleContent(e){return C({trigger:dt,[ft]:e.globs.length>0?e.globs.join(`, `):`**/*`,type:`user_command`},e.content)}normalizeRuleScope(e){return e.scope??`global`}};function ht(e){return ke[e??`Readme`].out}var gt=class extends E{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:`README.md`,cleanup:{delete:{project:{files:[`README.md`,`CODE_OF_CONDUCT.md`,`SECURITY.md`]}}},capabilities:{}})}async declareOutputFiles(e){let t=[],{readmePrompts:n}=e.collectedOutputContext;if(n==null||n.length===0)return t;for(let e of n){let n=ht(e.fileKind),r=F.join(e.targetDir.basePath,e.targetDir.path,n);t.push({path:r,scope:`project`,source:{content:e.content}})}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}};const _t=`GLOBAL.md`,K=`.trae`,vt=`commands`,yt=`skills`;var bt=class extends E{constructor(){super(`TraeIDEOutputPlugin`,{globalConfigDir:K,outputFileName:_t,indexignore:`.traeignore`,commands:{subDir:vt,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:yt},cleanup:{delete:{project:{dirs:[`.trae/rules`,`.trae/commands`,`.trae/skills`]},workspace:{dirs:[`.trae/commands`,`.trae/skills`]},global:{dirs:[`.trae/steering`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}getIgnoreOutputPath(){if(this.indexignore!=null)return F.join(`.trae`,`.ignore`)}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),`steering`)}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{commands:r,skills:i,globalMemory:o,aiAgentIgnoreConfigFiles:s}=e.collectedOutputContext,c=this.resolvePromptSourceProjectConfig(e),l=new Set(this.selectPromptScopes(e,[`project`,`global`]));o!=null&&l.has(`global`)&&t.push({path:this.joinPath(this.getGlobalSteeringDir(),_t),scope:`global`,source:{kind:`globalMemory`,content:o.content}});let u=a((r==null?{items:[]}:this.selectSingleScopeItems(r,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`))).items,c,`commands`),d=a((i==null?{items:[]}:this.selectSingleScopeItems(i,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`))).items,c,`skills`),f=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of n){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=F.join(n.basePath,n.path);if(e.childMemoryPrompts!=null&&l.has(`project`))for(let n of e.childMemoryPrompts){let e=(n.workingChildDirectoryPath?.path??n.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``),i=C({alwaysApply:!1,globs:this.buildProjectRelativeGlobPattern(e)},[this.buildPathGuardHint(e),``,n.content].join(`
6
+ `));t.push({path:F.join(r,K,`rules`,this.buildSteeringFileName(n)),scope:`project`,source:{kind:`steeringRule`,content:i}})}for(let e of u){let n=this.transformCommandName(e,f);t.push({path:F.join(r,K,vt,n),scope:`project`,source:{kind:`command`,command:e}})}for(let e of d){let n=e.yamlFrontMatter.name,i=F.join(r,K,yt,n);if(t.push({path:F.join(i,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:e}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:F.join(i,n.relativePath.replace(/\.mdx$/,`.md`)),scope:`project`,source:{kind:`skillChildDoc`,content:n.content}});if(e.resources!=null)for(let n of e.resources)t.push({path:F.join(i,n.relativePath),scope:`project`,source:{kind:`skillResource`,content:n.content,encoding:n.encoding}})}}let p=this.getIgnoreOutputPath(),m=this.indexignore==null?void 0:s?.find(e=>e.fileName===this.indexignore);if(p!=null&&m!=null)for(let e of n){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:F.join(n.basePath,n.path,p),scope:`project`,source:{kind:`ignoreFile`,content:m.content}})}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`globalMemory`:case`steeringRule`:case`skillChildDoc`:case`ignoreFile`:return n.content;case`command`:return this.buildCommandContent(n.command);case`skillMain`:return C(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;default:throw Error(`Unsupported declaration source for ${this.name}`)}}buildSkillFrontMatter(e){let t={description:e.yamlFrontMatter.description??``};return e.yamlFrontMatter.displayName!=null&&(t.name=e.yamlFrontMatter.displayName),t}buildSteeringFileName(e){return`trae-${(e.workingChildDirectoryPath?.path??e.dir.path).replaceAll(`\\`,`/`).replaceAll(/^\/+|\/+$/g,``).replaceAll(`/`,`-`)}.md`}buildPathGuardHint(e){return e.length===0?`Scope guard: apply this rule to project source files only; do not apply to generated output directories (for example dist/, build/, out/, .next/, target/).`:[`Scope guard: this rule is for the project-root path "${e}/" only.`,`Do not apply this rule to generated output paths such as "dist/${e}/", "build/${e}/", "out/${e}/", ".next/${e}/", or "target/${e}/".`].join(`
7
+ `)}buildProjectRelativeGlobPattern(e){return e.length===0?`**/*`:`${e}/**`}};const xt=`.vscode`;var St=class extends E{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`,{cleanup:{delete:{project:{files:[`.vscode/settings.json`,`.vscode/extensions.json`]}}},capabilities:{}})}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{vscodeConfigFiles:r}=e.collectedOutputContext,i=r??[];for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null)for(let e of i){let r=this.getTargetRelativePath(e);t.push({path:this.resolvePath(n.basePath,n.path,r),scope:`project`,source:{content:e.content}})}}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}getTargetRelativePath(e){let t=e.dir.path;if(e.type!==j.VSCode)return this.basename(t);let n=t.indexOf(xt);return n===-1?this.joinPath(xt,this.basename(t)):t.slice(Math.max(0,n))}};const Ct=`WARP.md`;var wt=class extends E{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:Ct,indexignore:`.warpindexignore`,cleanup:{delete:{project:{files:[Ct]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1}}})}async declareOutputFiles(e){let t=[],{workspace:n,globalMemory:r,aiAgentIgnoreConfigFiles:i}=e.collectedOutputContext,{projects:a}=n,o=this.shouldSkipDueToPlugin(e,v.AgentsOutput),s=new Set(this.selectPromptScopes(e,[`project`,`global`]));if(o){if(r!=null&&s.has(`global`))for(let e of a){let n=e.dirFromWorkspacePath;n!=null&&t.push({path:this.resolveFullPath(n),scope:`project`,source:{content:r.content}})}}else{let n=this.extractGlobalMemoryContent(e);for(let e of a){let r=e.dirFromWorkspacePath;if(r!=null){if(e.rootMemoryPrompt!=null&&s.has(`project`)){let i=this.combineGlobalWithContent(n,e.rootMemoryPrompt.content);t.push({path:this.resolveFullPath(r),scope:`project`,source:{content:i}})}if(e.childMemoryPrompts!=null&&s.has(`project`))for(let n of e.childMemoryPrompts)t.push({path:this.resolveFullPath(n.dir),scope:`project`,source:{content:n.content}})}}}let c=this.getIgnoreOutputPath(),l=this.indexignore==null?void 0:i?.find(e=>e.fileName===this.indexignore);if(c!=null&&l!=null)for(let e of a){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:this.resolvePath(n.basePath,n.path,c),scope:`project`,source:{content:l.content}})}return t}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}};const q=`.codeium/windsurf`,Tt=`global_workflows`,Et=`memories`,Dt=`skills`,Ot=`.windsurf`;var kt=class extends E{constructor(){super(`WindsurfOutputPlugin`,{globalConfigDir:q,outputFileName:``,dependsOn:[v.AgentsOutput],indexignore:`.codeiumignore`,commands:{subDir:Tt,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:Dt},rules:{sourceScopes:[`project`,`global`]},cleanup:{delete:{project:{dirs:[`.windsurf/rules`,`.windsurf/workflows`,`.windsurf/global_workflows`,`.windsurf/skills`,`.codeium/windsurf/global_workflows`,`.codeium/windsurf/skills`]},workspace:{dirs:[`.codeium/windsurf/global_workflows`,`.codeium/windsurf/skills`]},global:{dirs:[`.codeium/windsurf/global_workflows`,`.codeium/windsurf/memories`,`.codeium/windsurf/skills`]}}},capabilities:{prompt:{scopes:[`global`],singleScope:!1},rules:{scopes:[`project`,`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0},skills:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let t=[],{workspace:n,commands:r,skills:i,globalMemory:o,rules:s,aiAgentIgnoreConfigFiles:c}=e.collectedOutputContext,l=this.resolvePromptSourceProjectConfig(e),u=this.getCodeiumWindsurfDir(),d=this.resolveDirectoryPath(n.directory),f=new Set(this.selectPromptScopes(e,[`global`])),p=(e,t)=>{if(e===`global`)return u;if(e===`workspace`)return F.join(d,q);if(t!=null)return F.join(t.basePath,t.path,Ot)};if(o!=null&&f.has(`global`)&&t.push({path:F.join(u,Et,`global_rules.md`),scope:`global`,source:{kind:`globalMemory`,content:o.content}}),i!=null&&i.length>0){let r=this.selectSingleScopeItems(i,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)),o=(e,n,r)=>{let i=r.yamlFrontMatter.name,a=F.join(e,Dt,i);if(t.push({path:F.join(a,`SKILL.md`),scope:n,source:{kind:`skillMain`,skill:r}}),r.childDocs!=null)for(let e of r.childDocs)t.push({path:F.join(a,e.relativePath.replace(/\.mdx$/,`.md`)),scope:n,source:{kind:`skillChildDoc`,content:e.content}});if(r.resources!=null)for(let e of r.resources)t.push({path:F.join(a,e.relativePath),scope:n,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})};if(r.selectedScope===`project`)for(let e of n.projects){let t=e.dirFromWorkspacePath,n=p(`project`,t);if(n==null)continue;let i=a(r.items,e.projectConfig,`skills`);for(let e of i)o(n,`project`,e)}else if(r.selectedScope!=null){let e=p(r.selectedScope);if(e!=null){let t=a(r.items,l,`skills`);for(let n of t)o(e,r.selectedScope,n)}}}if(r!=null&&r.length>0){let i=this.selectSingleScopeItems(r,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)),o=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});if(i.selectedScope===`project`)for(let e of n.projects){let n=e.dirFromWorkspacePath,r=p(`project`,n);if(r==null)continue;let s=a(i.items,e.projectConfig,`commands`);for(let e of s)t.push({path:F.join(r,`workflows`,this.transformCommandName(e,o)),scope:`project`,source:{kind:`command`,command:e}})}else if(i.selectedScope!=null){let e=p(i.selectedScope);if(e!=null){let n=a(i.items,l,`commands`);for(let r of n)t.push({path:F.join(e,Tt,this.transformCommandName(r,o)),scope:i.selectedScope,source:{kind:`command`,command:r}})}}}if(s!=null&&s.length>0){let r=new Set(this.selectRuleScopes(e,s)),i=s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`global`);if(r.has(`global`))for(let e of i)t.push({path:F.join(u,Et,this.buildRuleFileName(e)),scope:`global`,source:{kind:`rule`,rule:e}});if(r.has(`project`))for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n==null)continue;let r=b(a(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of r)t.push({path:F.join(n.basePath,n.path,Ot,`rules`,this.buildRuleFileName(e)),scope:`project`,source:{kind:`rule`,rule:e}})}}let m=this.getIgnoreOutputPath(),h=this.indexignore==null?void 0:c?.find(e=>e.fileName===this.indexignore);if(m!=null&&h!=null)for(let e of n.projects){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:F.join(n.basePath,n.path,m),scope:`project`,source:{kind:`ignoreFile`,content:h.content}})}return t}async convertContent(e,t){let n=e.source;switch(n.kind){case`globalMemory`:case`skillChildDoc`:case`ignoreFile`:return n.content;case`command`:return this.buildCommandContent(n.command);case`skillMain`:return C(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillResource`:return n.encoding===`base64`?R.from(n.content,`base64`):n.content;case`rule`:return this.buildRuleContent(n.rule);default:throw Error(`Unsupported declaration source for ${this.name}`)}}getCodeiumWindsurfDir(){return F.join(this.getHomeDir(),q)}buildRuleFileName(e,t=`rule-`){return`${t}${e.prefix}-${e.ruleName}.md`}buildRuleContent(e,t){return C({trigger:`glob`,globs:e.globs.length>0?e.globs.join(`, `):``},e.content).split(`
8
+ `).map(e=>{let t=/^(\s*globs:\s*)(['"])(.*)\2\s*$/.exec(e);if(t==null)return e;let n=t[1]??`globs: `,r=t[3]??``;return r.trim().length===0?e:`${n}${r}`}).join(`
9
+ `)}},J=le(Te(),1);function At(e,t){let n=F.join(e,`.git`),r=P.existsSync(n);return r?t?.info(`version control detected`,{path:n}):t?.warn(`no version control detected, please use git to manage your aindex`,{path:e}),{hasGit:r,gitPath:n}}const jt=`.tnmsc.json`,Mt=`.aindex`;var Nt=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??jt,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=x(`ConfigLoader`)}getSearchPaths(e=I.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(F.join(e,this.configFileName)),this.searchGlobal&&t.push(F.join(L.homedir(),Mt,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!P.existsSync(t))return{config:{},source:null,found:!1};let e=P.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=I.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){let n;try{n=JSON.parse(e)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}let r=Oe.safeParse(n);if(r.success)return r.data;let i=r.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`);throw Error(`Config validation failed in ${t}:\n${i.join(`
10
+ `)}`)}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=this.mergeAindex(e.aindex,t.aindex),r=this.mergeOutputScopeOptions(e.outputScopes,t.outputScopes),i=this.mergeCleanupProtectionOptions(e.cleanupProtection,t.cleanupProtection);return{...e,...t,...n==null?{}:{aindex:n},...r==null?{}:{outputScopes:r},...i==null?{}:{cleanupProtection:i}}},{})}mergeAindex(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{dir:t.dir??e.dir,skills:{...e.skills,...t.skills},commands:{...e.commands,...t.commands},subAgents:{...e.subAgents,...t.subAgents},rules:{...e.rules,...t.rules},globalPrompt:{...e.globalPrompt,...t.globalPrompt},workspacePrompt:{...e.workspacePrompt,...t.workspacePrompt},app:{...e.app,...t.app},ext:{...e.ext,...t.ext},arch:{...e.arch,...t.arch}}}mergeOutputScopeTopics(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{...e,...t}}mergeOutputScopeOptions(e,t){if(e==null&&t==null)return;if(e==null)return t;if(t==null)return e;let n={};for(let[t,r]of Object.entries(e.plugins??{}))r!=null&&(n[t]={...r});for(let[e,r]of Object.entries(t.plugins??{})){let t=this.mergeOutputScopeTopics(n[e],r);t!=null&&(n[e]=t)}return Object.keys(n).length===0?{}:{plugins:n}}mergeCleanupProtectionOptions(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{rules:[...e.rules??[],...t.rules??[]]}}resolveTilde(e){return e.startsWith(`~`)?F.join(L.homedir(),e.slice(1)):e}};let Y=null;function Pt(e){return(e||!Y)&&(Y=new Nt(e)),Y}let X=function(e){return e[e.Flags=0]=`Flags`,e[e.Unknown=1]=`Unknown`,e[e.Subcommand=2]=`Subcommand`,e}({});var Ft=class{factories=[];register(e){this.factories.push(e),this.factories.sort((e,t)=>e.priority-t.priority)}registerWithPriority(e,t){let n={priority:t,canHandle:t=>e.canHandle(t),createCommand:t=>e.createCommand(t)};this.factories.push(n),this.factories.sort((e,t)=>e.priority-t.priority)}resolve(e){for(let t of this.factories)if(t.priority<=X.Unknown&&t.canHandle(e))return t.createCommand(e);for(let t of this.factories)if(t.priority===X.Subcommand&&t.canHandle(e))return t.createCommand(e);for(let t of this.factories)if(t.canHandle(e))return t.createCommand(e);throw Error(`No command factory found for the given arguments`)}},It=class{canHandle(e){return e.subcommand===`clean`}createCommand(e){return e.dryRun?new ae:new ge}};const Z=[`workspaceDir`,`aindex.skills.src`,`aindex.skills.dist`,`aindex.commands.src`,`aindex.commands.dist`,`aindex.subAgents.src`,`aindex.subAgents.dist`,`aindex.rules.src`,`aindex.rules.dist`,`aindex.globalPrompt.src`,`aindex.globalPrompt.dist`,`aindex.workspacePrompt.src`,`aindex.workspacePrompt.dist`,`aindex.app.src`,`aindex.app.dist`,`aindex.ext.src`,`aindex.ext.dist`,`aindex.arch.src`,`aindex.arch.dist`,`logLevel`];function Lt(e){return Z.includes(e)}function Rt(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Q(){return F.join(L.homedir(),Mt,jt)}function zt(){let e=Q();if(!P.existsSync(e))return{};try{let t=P.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Bt(e){let t=Q(),n=F.dirname(t);P.existsSync(n)||P.mkdirSync(n,{recursive:!0}),P.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf8`)}function Vt(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e],n=i[t];(typeof n!=`object`||!n||Array.isArray(n))&&(i[t]={}),i=i[t]}i[r.at(-1)]=n}function Ht(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r||Array.isArray(r))return;r=r[e]}return r}var Ut=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: ${Z.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=zt(),r=[],i=[];for(let[e,a]of this.options){if(!Lt(e)){r.push(`Invalid key: ${e} (valid keys: ${Z.join(`, `)})`);continue}if(e===`logLevel`&&!Rt(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=Ht(n,e);Vt(n,e,a),o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Bt(n),t.info(`global config written`,{path:Q()})),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}}},Wt=class{name=`config-show`;async execute(e){let{logger:t}=e,n=new Nt,r=n.load(),i=r.sources.map(e=>{let t=n.loadFromFile(e);return{path:e,layer:this.inferLayer(e),config:t.config}}),a={merged:r.config,sources:i};return I.stdout.write(`${JSON.stringify(a)}\n`),t.info(`config shown`,{sources:r.sources.length}),{success:!0,filesAffected:0,dirsAffected:0,message:`Configuration displayed (${i.length} source(s))`}}inferLayer(e){let t=I.cwd();return e.startsWith(t)?`cwd`:`global`}},Gt=class{canHandle(e){return e.subcommand===`config`}createCommand(e){if(e.showFlag)return new Wt;let t=[];for(let n of e.positional){let e=n.indexOf(`=`);e>0&&t.push([n.slice(0,e),n.slice(e+1)])}return new Ut([...e.setOption,...t])}},Kt=class{canHandle(e){return e.subcommand===`dry-run`}createCommand(e){return new fe}},qt=class{canHandle(e){return!0}createCommand(e){return new be}};function Jt(){return`2026.10314.11719`}var Yt=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${Jt()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const $=`tnmsc`,Xt=`
11
+ ${$} v${Jt()} - Memory Sync CLI
12
+
13
+ Synchronize AI memory and configuration files across projects.
14
+
15
+ USAGE:
16
+ ${$} Run the sync pipeline (default)
17
+ ${$} help Show this help message
18
+ ${$} version Show version information
19
+ ${$} init Deprecated; no longer initializes aindex
20
+ ${$} dry-run Preview what would be written
21
+ ${$} clean Remove all generated files
22
+ ${$} clean --dry-run Preview what would be cleaned
23
+ ${$} config key=value Set configuration value
24
+
25
+ SUBCOMMANDS:
26
+ help Show this help message
27
+ version Show version information
28
+ init Deprecated; keep public target-relative definitions manually
29
+ dry-run Preview changes without writing files
30
+ clean Remove all generated output files and directories
31
+ config Set configuration values in global config file (~/.aindex/.tnmsc.json)
32
+
33
+ ALIASES:
34
+ ${$} --help, ${$} -h Same as '${$} help'
35
+ ${$} --version, ${$} -v Same as '${$} version'
36
+ ${$} clean -n Same as '${$} clean --dry-run'
37
+ ${$} config key=value Set config value in global config file
38
+
39
+ LOG LEVEL OPTIONS:
40
+ --trace Most verbose output
41
+ --debug Debug information
42
+ --info Standard information (default)
43
+ --warn Warnings only
44
+ --error Errors only
45
+
46
+ CLEAN OPTIONS:
47
+ -n, --dry-run Preview cleanup without removing files
48
+
49
+ CONFIG OPTIONS:
50
+ key=value Set a configuration value in global config (~/.aindex/.tnmsc.json)
51
+ Valid keys: workspaceDir, logLevel,
52
+ aindex.skills.src, aindex.skills.dist,
53
+ aindex.commands.src, aindex.commands.dist,
54
+ aindex.subAgents.src, aindex.subAgents.dist,
55
+ aindex.rules.src, aindex.rules.dist,
56
+ aindex.globalPrompt.src, aindex.globalPrompt.dist,
57
+ aindex.workspacePrompt.src, aindex.workspacePrompt.dist,
58
+ aindex.app.src, aindex.app.dist,
59
+ aindex.ext.src, aindex.ext.dist,
60
+ aindex.arch.src, aindex.arch.dist
61
+
62
+ Examples:
63
+ ${$} config workspaceDir=~/my-project
64
+ ${$} config aindex.skills.src=skills
65
+ ${$} config logLevel=debug
66
+
67
+ CONFIGURATION:
68
+ Configure via plugin.config.ts in your project root.
69
+ See documentation for detailed configuration options.
70
+ `.trim();var Zt=class{name=`help`;async execute(e){return e.logger.info(Xt),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}},Qt=class{priority=X.Flags;canHandle(e){return e.helpFlag||e.subcommand===`help`}createCommand(e){return new Zt}},$t=class{name=`init`;async execute(e){let{logger:t}=e;return t.warn(`deprecated init command invoked`,{command:`init`}),{success:!1,filesAffected:0,dirsAffected:0,message:"`tnmsc init` is deprecated and no longer initializes aindex. Maintain the public target-relative definitions manually under `~/workspace/aindex/public/`."}}},en=class{canHandle(e){return e.subcommand===`init`}createCommand(e){return new $t}},tn=class{canHandle(e){return e.subcommand===`plugins`}createCommand(e){return new Ce}},nn=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return e.logger.error(`unknown command`,{command:this.unknownCmd}),e.logger.info(`run "tnmsc help" for available commands`),{success:!1,filesAffected:0,dirsAffected:0,message:`Unknown command: ${this.unknownCmd}`}}},rn=class{priority=X.Unknown;canHandle(e){return e.unknownCommand!=null}createCommand(e){return new nn(e.unknownCommand)}},an=class{priority=X.Flags;canHandle(e){return e.versionFlag||e.subcommand===`version`}createCommand(e){return new Yt}};const on=new Set([`help`,`version`,`init`,`dry-run`,`clean`,`config`,`plugins`]),sn=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),cn=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function ln(e){let t=[...e],n=t[0];n!=null&&un(n)&&t.shift();let r=t[0];return r!=null&&dn(r)&&t.shift(),t}function un(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 dn(e){return/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)?!0:/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`)}function fn(e,t){if(e==null)return t;let n=cn.get(e)??4;return(cn.get(t)??4)<n?t:e}function pn(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,jsonFlag:!1,showFlag:!1,logLevel:void 0,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=sn.get(a);if(o!=null){t.logLevel=fn(t.logLevel,o);continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--json`:t.jsonFlag=!0;break;case`--show`:t.showFlag=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;case`j`:t.jsonFlag=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,on.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}let mn;function hn(){let e=new Ft;return e.register(new an),e.register(new Qt),e.register(new rn),e.registerWithPriority(new en,X.Subcommand),e.registerWithPriority(new Kt,X.Subcommand),e.registerWithPriority(new It,X.Subcommand),e.registerWithPriority(new tn,X.Subcommand),e.registerWithPriority(new Gt,X.Subcommand),e.registerWithPriority(new qt,X.Subcommand),e}function gn(){return mn??=hn(),mn}function _n(e){return gn().resolve(e)}const vn={workspace:{strategy:`mergeProjects`,getter:e=>e.workspace},vscodeConfigFiles:{strategy:`concat`,getter:e=>e.vscodeConfigFiles},jetbrainsConfigFiles:{strategy:`concat`,getter:e=>e.jetbrainsConfigFiles},editorConfigFiles:{strategy:`concat`,getter:e=>e.editorConfigFiles},commands:{strategy:`concat`,getter:e=>e.commands},subAgents:{strategy:`concat`,getter:e=>e.subAgents},skills:{strategy:`concat`,getter:e=>e.skills},rules:{strategy:`concat`,getter:e=>e.rules},aiAgentIgnoreConfigFiles:{strategy:`concat`,getter:e=>e.aiAgentIgnoreConfigFiles},readmePrompts:{strategy:`concat`,getter:e=>e.readmePrompts},globalMemory:{strategy:`override`,getter:e=>e.globalMemory},aindexDir:{strategy:`override`,getter:e=>e.aindexDir},globalGitIgnore:{strategy:`override`,getter:e=>e.globalGitIgnore},shadowGitExclude:{strategy:`override`,getter:e=>e.shadowGitExclude}};function yn(e,t){return t==null?e??[]:e==null?t:[...e,...t]}function bn(e,t){let n=new Map;for(let t of e.projects)n.set(t.name,t);for(let e of t.projects)n.set(e.name,e);return{directory:t.directory??e.directory,projects:[...n.values()]}}function xn(e,t){return t==null?e:e==null?t:bn(e,t)}function Sn(e,t,n){switch(n){case`concat`:return yn(e,t);case`override`:return t??e;case`mergeProjects`:return xn(e,t);default:return t??e}}function Cn(e,t){let n={};for(let[r,i]of Object.entries(vn)){let a=Sn(i.getter(e),i.getter(t),i.strategy);a!=null&&(n[r]=a)}return n}function wn(e,t,n){let r=e.dependsOn??[];if(r.length===0)return{};let i=new Set,a={};for(let e of r){if(i.has(e))continue;i.add(e);let r=t.get(e);r!=null&&(a=n(a,r))}return a}function Tn(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]}function En(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 ie(n.name,r)}let n=new Map;for(let t of e)n.set(t.name,t);let r=new Map;for(let t of e)r.set(t.name,0);let i=new Map;for(let t of e)i.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let n of e){r.set(t.name,(r.get(t.name)??0)+1);let e=i.get(n)??[];e.push(t.name),i.set(n,e)}}let a=[];for(let t of e)r.get(t.name)===0&&a.push(t.name);let o=[],s=new Map;for(let t=0;t<e.length;t++){let n=e[t];n!=null&&s.set(n.name,t)}for(;a.length>0;){let e=a.shift(),t=n.get(e);o.push(t);let c=(i.get(e)??[]).sort((e,t)=>(s.get(e)??-1)-(s.get(t)??-1));for(let e of c){let t=(r.get(e)??0)-1;r.set(e,t),t===0&&a.push(e)}}if(o.length===e.length)return o;throw new de(Tn(e,r))}var Dn=class{logger;args;outputPlugins=[];constructor(...e){this.args=pn(ln(e.filter(e=>e!=null)));let t=this.args.logLevel;t!=null&&ee(t),this.logger=x(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=_n(this.args);this.args.jsonFlag&&(ee(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new he(i)));let a=this.createCommandContext(t,r);return i.execute(a)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedOutputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:P,path:F,glob:J.default,collectedOutputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:P,path:F,glob:J.default,collectedOutputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}async executePluginsInOrder(e,t,n=!1,i){if(e.length===0)return{};let a=En(e),o=new y({userConfig:i}).collect(),s=new De;s.setGlobalScope(o),this.logger.debug(`global scope collected`,{osInfo:{platform:o.os.platform,arch:o.os.arch,shellKind:o.os.shellKind},hasProfile:Object.keys(o.profile).length>0,hasTool:Object.keys(o.tool).length>0});let c=new Map,l={};for(let e of a){let i=wn(e,c,Cn),a=this.resolveRuntimeCommand(),u={...t,dependencyContext:i,...a!=null&&{runtimeCommand:a},globalScope:o,scopeRegistry:s},d=e;d.executeEffects!=null&&await d.executeEffects(u,n);let f=await e.collect(u);c.set(e.name,f),l=Cn(l,f);let p=e;if(p.getRegisteredScopes!=null){let t=p.getRegisteredScopes();for(let{namespace:n,values:i}of t)s.register(n,i,r.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(i)})}}return l}resolveRuntimeCommand(){if(!(this.args.helpFlag||this.args.versionFlag||this.args.unknownCommand!=null)){if(this.args.subcommand===`clean`)return`clean`;if(this.args.subcommand===`plugins`)return`plugins`;if(this.args.subcommand===`dry-run`||this.args.dryRun)return`dry-run`;if(this.args.subcommand==null)return`execute`}}};const On={version:`0.0.0`,workspaceDir:`~/project`,logLevel:`info`,aindex:{dir:`aindex`,skills:{src:`skills`,dist:`dist/skills`},commands:{src:`commands`,dist:`dist/commands`},subAgents:{src:`subagents`,dist:`dist/subagents`},rules:{src:`rules`,dist:`dist/rules`},globalPrompt:{src:`global.src.mdx`,dist:`dist/global.mdx`},workspacePrompt:{src:`workspace.src.mdx`,dist:`dist/workspace.mdx`},app:{src:`app`,dist:`dist/app`},ext:{src:`ext`,dist:`dist/ext`},arch:{src:`arch`,dist:`dist/arch`}},commandSeriesOptions:{},outputScopes:{},cleanupProtection:{},plugins:[]};function kn(e){return{...e.version==null?{}:{version:e.version},...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.aindex==null?{}:{aindex:e.aindex},...e.commandSeriesOptions==null?{}:{commandSeriesOptions:e.commandSeriesOptions},...e.outputScopes==null?{}:{outputScopes:e.outputScopes},...e.cleanupProtection==null?{}:{cleanupProtection:e.cleanupProtection},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function An(...e){return e.reduce((e,t)=>jn(e,t),{...On})}function jn(e,t){let n=t.plugins,r=t.commandSeriesOptions,i=t.outputScopes,a=t.cleanupProtection;return{...e,...t,aindex:Mn(e.aindex,t.aindex),plugins:[...e.plugins,...n??[]],commandSeriesOptions:Nn(e.commandSeriesOptions,r),outputScopes:Fn(e.outputScopes,i),cleanupProtection:In(e.cleanupProtection,a)}}function Mn(e,t){return t==null?e:{dir:t.dir??e.dir,skills:{...e.skills,...t.skills},commands:{...e.commands,...t.commands},subAgents:{...e.subAgents,...t.subAgents},rules:{...e.rules,...t.rules},globalPrompt:{...e.globalPrompt,...t.globalPrompt},workspacePrompt:{...e.workspacePrompt,...t.workspacePrompt},app:{...e.app,...t.app},ext:{...e.ext,...t.ext},arch:{...e.arch,...t.arch}}}function Nn(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 Pn(e,t){if(!(e==null&&t==null))return e==null?t:t==null?e:{...e,...t}}function Fn(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.plugins!=null)for(let[t,r]of Object.entries(e.plugins))r!=null&&(n[t]={...r});if(t.plugins!=null)for(let[e,r]of Object.entries(t.plugins)){let t=Pn(n[e],r);t!=null&&(n[e]=t)}return Object.keys(n).length===0?{}:{plugins:n}}function In(e,t){return t==null?e??{}:e==null?t:{rules:[...e.rules??[],...t.rules??[]]}}function Ln(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e||`cwd`in e||`pipelineArgs`in e}async function Rn(e={}){let t,n,r,i,a;Ln(e)?({pluginOptions:r={},cwd:n,configLoaderOptions:i,pipelineArgs:a}={pluginOptions:e.pluginOptions,cwd:e.cwd,configLoaderOptions:e.configLoaderOptions,pipelineArgs:e.pipelineArgs},t=e.loadUserConfig??!0):(r=e,t=!0,i=void 0,a=void 0);let o={},s=!1,c=[],l;if(t)try{let e=Pt(i).load(n);s=e.found,c=e.sources,e.found&&(o=kn(e.config),l=e.config)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to load user config: ${t}`)}let u=An(o,r),{plugins:d=[],logLevel:f}=u,p=x(`defineConfig`,f);s?p.info(`user config loaded`,{sources:c}):p.info(`no user config found, using defaults/programmatic options`,{workspaceDir:u.workspaceDir,aindexDir:u.aindex.dir,logLevel:u.logLevel});let m={logger:p,userConfigOptions:u,fs:P,path:F,glob:J.default},h=d.filter(e=>e.type===xe.Input),g=d.filter(e=>e.type===xe.Output);Ee(g,u);let _=await(a==null?new Dn:new Dn(...a)).executePluginsInOrder(h,m,!1,l);if(_.workspace==null)throw Error(`Workspace not initialized by any plugin`);let v=oe({workspace:_.workspace,..._.vscodeConfigFiles!=null&&{vscodeConfigFiles:_.vscodeConfigFiles},..._.jetbrainsConfigFiles!=null&&{jetbrainsConfigFiles:_.jetbrainsConfigFiles},..._.editorConfigFiles!=null&&{editorConfigFiles:_.editorConfigFiles},..._.commands!=null&&{commands:_.commands},..._.subAgents!=null&&{subAgents:_.subAgents},..._.skills!=null&&{skills:_.skills},..._.rules!=null&&{rules:_.rules},..._.globalMemory!=null&&{globalMemory:_.globalMemory},..._.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:_.aiAgentIgnoreConfigFiles},..._.aindexDir!=null&&{aindexDir:_.aindexDir},..._.readmePrompts!=null&&{readmePrompts:_.readmePrompts},..._.globalGitIgnore!=null&&{globalGitIgnore:_.globalGitIgnore},..._.shadowGitExclude!=null&&{shadowGitExclude:_.shadowGitExclude}});return _.aindexDir!=null&&At(_.aindexDir,p),{context:v,outputPlugins:g,userConfigOptions:u}}var zn=class extends m{constructor(){super(`MarkdownWhitespaceCleanupEffectInputPlugin`),this.registerEffect(`markdown-whitespace-cleanup`,this.cleanupWhitespace.bind(this),30)}async cleanupWhitespace(e){let{fs:t,path:n,aindexDir:r,dryRun:i,logger:a}=e,o=[],s=[],c=[],l=[n.join(r,`src`),n.join(r,`app`),n.join(r,`dist`)];for(let n of l){if(!t.existsSync(n)){a.debug({action:`whitespace-cleanup`,message:`Directory does not exist, skipping`,dir:n});continue}this.processDirectory(e,n,o,s,c,i??!1)}let u=c.length>0;return u&&a.warn({action:`whitespace-cleanup`,errors:c.map(e=>({path:e.path,error:e.error.message}))}),{success:!u,description:i?`Would modify ${o.length} files, skip ${s.length} files`:`Modified ${o.length} files, skipped ${s.length} files`,modifiedFiles:o,skippedFiles:s,...u&&{error:Error(`${c.length} errors occurred during cleanup`)}}}processDirectory(e,t,n,r,i,a){let{fs:o,path:s,logger:c}=e,l;try{l=o.readdirSync(t,{withFileTypes:!0})}catch(e){i.push({path:t,error:e}),c.warn({action:`whitespace-cleanup`,message:`Failed to read directory`,path:t,error:e.message});return}for(let o of l){let c=s.join(t,o.name);o.isDirectory()?this.processDirectory(e,c,n,r,i,a):o.isFile()&&o.name.endsWith(`.md`)&&this.processMarkdownFile(e,c,n,r,i,a)}}processMarkdownFile(e,t,n,r,i,a){let{fs:o,logger:s}=e;try{let e=o.readFileSync(t,`utf8`),i=this.cleanMarkdownContent(e);if(e===i){r.push(t),s.debug({action:`whitespace-cleanup`,skipped:t,reason:`no changes needed`});return}a?(s.debug({action:`whitespace-cleanup`,dryRun:!0,wouldModify:t}),n.push(t)):(o.writeFileSync(t,i,`utf8`),n.push(t),s.debug({action:`whitespace-cleanup`,modified:t}))}catch(e){i.push({path:t,error:e}),s.warn({action:`whitespace-cleanup`,message:`Failed to process file`,path:t,error:e.message})}}cleanMarkdownContent(e){let t=this.detectLineEnding(e),n=e.split(/\r?\n/).map(e=>e.replace(/[ \t]+$/,``)),r=[],i=0;for(let e of n)e===``?(i++,i<=2&&r.push(e)):(i=0,r.push(e));return r.join(t)}detectLineEnding(e){return e.includes(`\r
71
+ `)?`\r
72
+ `:`
73
+ `}collect(e){return{}}};const Bn=[`skills`,`commands`,`agents`,`app`];var Vn=class extends m{constructor(){super(`OrphanFileCleanupEffectInputPlugin`),this.registerEffect(`orphan-file-cleanup`,this.cleanupOrphanFiles.bind(this),20)}buildProtectedDeletionGuard(e){return ye({workspaceDir:e.workspaceDir,aindexDir:e.aindexDir,rules:[...d(e.userConfigOptions,e.aindexDir,{workspaceDir:e.workspaceDir}),...(e.userConfigOptions.cleanupProtection?.rules??[]).map(e=>({path:e.path,protectionMode:e.protectionMode,reason:e.reason??`configured cleanup protection rule`,source:`configured-cleanup-protection`,matcher:e.matcher??`path`}))]})}buildDeletionPlan(e,t,n){let r=[],i=[],a=[];for(let o of Bn){let s=e.path.join(t,o);e.fs.existsSync(s)&&e.fs.statSync(s).isDirectory()&&this.collectDirectoryPlan(e,s,o,n[o],r,i,a)}return{filesToDelete:r,dirsToDelete:i,errors:a}}async cleanupOrphanFiles(e){let{fs:t,path:n,aindexDir:r,logger:i,userConfigOptions:a,dryRun:o}=e,c=n.join(r,`dist`);if(!t.existsSync(c))return i.debug({action:`orphan-cleanup`,message:`dist/ directory does not exist, skipping`,distDir:c}),{success:!0,description:`dist/ directory does not exist, nothing to clean`,deletedFiles:[],deletedDirs:[]};let l=a.aindex,d={skills:l?.skills?.src??`skills`,commands:l?.commands?.src??`commands`,agents:l?.subAgents?.src??`subagents`,app:l?.app?.src??`app`},f=this.buildDeletionPlan(e,c,d);f.errors.length>0&&i.warn({action:`orphan-cleanup`,errors:f.errors.map(e=>({path:e.path,error:e.error.message}))});let p=this.buildProtectedDeletionGuard(e),m=u(f.filesToDelete,p),h=u(f.dirsToDelete,p),g=[...m.violations,...h.violations].sort((e,t)=>e.targetPath.localeCompare(t.targetPath));if(g.length>0)return{success:!1,description:`Protected deletion guard blocked orphan cleanup for ${g.length} path(s)`,deletedFiles:[],deletedDirs:[],error:new s(`orphan-file-cleanup`,g)};if(o)return{success:!0,description:`Would delete ${m.safePaths.length} files and ${h.safePaths.length} directories`,deletedFiles:[...m.safePaths],deletedDirs:[...h.safePaths].sort((e,t)=>t.length-e.length)};let _=[],v=[],y=[...f.errors];for(let e of m.safePaths)try{t.unlinkSync(e),_.push(e),i.debug({action:`orphan-cleanup`,deleted:e})}catch(t){y.push({path:e,error:t}),i.warn({action:`orphan-cleanup`,message:`Failed to delete file`,path:e,error:t.message})}for(let e of[...h.safePaths].sort((e,t)=>t.length-e.length))try{t.rmdirSync(e),v.push(e),i.debug({action:`orphan-cleanup`,deletedDir:e})}catch(t){y.push({path:e,error:t}),i.warn({action:`orphan-cleanup`,message:`Failed to delete directory`,path:e,error:t.message})}let b=y.length>0;return{success:!b,description:`Deleted ${_.length} files and ${v.length} directories`,deletedFiles:_,deletedDirs:v,...b&&{error:Error(`${y.length} errors occurred during cleanup`)}}}collectDirectoryPlan(e,t,n,r,i,a,o){let{fs:s,path:c,aindexDir:l,logger:u}=e,d;try{d=s.readdirSync(t,{withFileTypes:!0})}catch(e){return o.push({path:t,error:e}),u.warn({action:`orphan-cleanup`,message:`Failed to read directory`,path:t,error:e.message}),!1}let f=!1;for(let s of d){let u=c.join(t,s.name);if(s.isDirectory()){this.collectDirectoryPlan(e,u,n,r,i,a,o)?a.push(u):f=!0;continue}if(!s.isFile()){f=!0;continue}this.isOrphanFile(e,u,n,r,l)?i.push(u):f=!0}return!f}isOrphanFile(e,t,n,r,i){let{fs:a,path:o}=e,s=o.basename(t),c=s.endsWith(`.mdx`),l=o.join(i,`dist`,n),u=o.relative(l,t),d=o.dirname(u),f=s.replace(/\.mdx$/,``);return c?!this.getPossibleSourcePaths(o,i,n,r,f,d).some(e=>a.existsSync(e)):!a.existsSync(o.join(i,r,u))}getPossibleSourcePaths(e,t,n,r,i,a){switch(n){case`skills`:{let n=(a===`.`?[i]:a.split(e.sep))[0]??i,o=a===`.`?``:a.slice(n.length+1);return o===``?[...S.map(i=>e.join(t,r,n,`SKILL${i}`)),...S.map(i=>e.join(t,r,n,`skill${i}`))]:S.map(a=>e.join(t,r,n,o,`${i}${a}`))}case`commands`:case`agents`:case`app`:return a===`.`?S.map(n=>e.join(t,r,`${i}${n}`)):S.map(n=>e.join(t,r,a,`${i}${n}`));default:return[]}}collect(e){return{}}},Hn=class extends m{constructor(){super(`SkillDistCleanupEffectInputPlugin`),this.registerEffect(`skill-dist-cleanup`,this.cleanupDistSkillArtifacts.bind(this),10)}async cleanupDistSkillArtifacts(e){let{fs:t,logger:n,userConfigOptions:r,aindexDir:i,dryRun:a}=e,o=this.resolveAindexPath(r.aindex.skills.src,i),s=this.resolveAindexPath(r.aindex.skills.dist,i);if(!t.existsSync(s))return n.debug({action:`skill-dist-cleanup`,message:`dist skills directory does not exist, skipping`,srcSkillsDir:o,distSkillsDir:s}),{success:!0,description:`dist skills directory does not exist, nothing to clean`,deletedFiles:[],deletedDirs:[]};let c=this.buildCleanupPlan(e,s);if(c.errors.length>0&&n.warn({action:`skill-dist-cleanup`,errors:c.errors.map(e=>({path:e.path,error:e.error.message}))}),a)return{success:!0,description:`Would delete ${c.filesToDelete.length} files and ${c.dirsToDelete.length} directories`,deletedFiles:[...c.filesToDelete],deletedDirs:[...c.dirsToDelete].sort((e,t)=>t.length-e.length)};let l=[],u=[],d=[...c.errors];for(let e of c.filesToDelete)try{t.unlinkSync(e),l.push(e),n.debug({action:`skill-dist-cleanup`,deleted:e})}catch(t){d.push({path:e,error:t}),n.warn({action:`skill-dist-cleanup`,message:`Failed to delete file`,path:e,error:t.message})}for(let e of[...c.dirsToDelete].sort((e,t)=>t.length-e.length))try{t.rmdirSync(e),u.push(e),n.debug({action:`skill-dist-cleanup`,deletedDir:e})}catch(t){d.push({path:e,error:t}),n.warn({action:`skill-dist-cleanup`,message:`Failed to delete directory`,path:e,error:t.message})}let f=d.length>0;return{success:!f,description:`Deleted ${l.length} files and ${u.length} directories`,deletedFiles:l,deletedDirs:u,...f&&{error:Error(`${d.length} errors occurred during cleanup`)}}}buildCleanupPlan(e,t){let n=[],r=[],i=[];return this.collectCleanupPlan(e,t,n,r,i),{filesToDelete:n,dirsToDelete:r,errors:i}}collectCleanupPlan(e,t,n,r,i){let{fs:a,path:o,logger:s}=e,c;try{c=a.readdirSync(t,{withFileTypes:!0})}catch(e){return i.push({path:t,error:e}),s.warn({action:`skill-dist-cleanup`,message:`Failed to read directory`,path:t,error:e.message}),!1}let l=!1;for(let a of c){let s=o.join(t,a.name);if(a.isDirectory()){this.collectCleanupPlan(e,s,n,r,i)?r.push(s):l=!0;continue}if(!a.isFile()){l=!0;continue}if(this.shouldRetainCompiledSkillFile(a.name)){l=!0;continue}n.push(s)}return!l}shouldRetainCompiledSkillFile(e){return e.endsWith(`.mdx`)&&!c(e)}collect(e){return{}}};const Un=/export\s+default\s*\{([\s\S]*?)\}/u,Wn=/description\s*:\s*['"`]([^'"`]+)['"`]/u,Gn=/name\s*:\s*['"`]([^'"`]+)['"`]/u,Kn=/displayName\s*:\s*['"`]([^'"`]+)['"`]/u,qn=/keywords\s*:\s*\[([^\]]+)\]/u,Jn=/author\s*:\s*['"`]([^'"`]+)['"`]/u,Yn=/version\s*:\s*['"`]([^'"`]+)['"`]/u;function Xn(e){let t={},n=Un.exec(e);if(n?.[1]==null)return t;let r=n[1],i=Wn.exec(r);i?.[1]!=null&&(t.description=i[1]);let a=Gn.exec(r);a?.[1]!=null&&(t.name=a[1]);let o=Kn.exec(r);o?.[1]!=null&&(t.displayName=o[1]);let s=qn.exec(r);s?.[1]!=null&&(t.keywords=s[1].split(`,`).map(e=>e.trim().replaceAll(/['"]/gu,``)).filter(e=>e.length>0));let c=Jn.exec(r);c?.[1]!=null&&(t.author=c[1]);let l=Yn.exec(r);return l?.[1]!=null&&(t.version=l[1]),t}function Zn(...e){let t={};for(let n of e)if(n!=null)for(let[e,r]of Object.entries(n))r!==void 0&&(t[e]=r);return t}const Qn={".ts":`text/typescript`,".tsx":`text/typescript`,".js":`text/javascript`,".jsx":`text/javascript`,".json":`application/json`,".py":`text/x-python`,".java":`text/x-java`,".kt":`text/x-kotlin`,".go":`text/x-go`,".rs":`text/x-rust`,".c":`text/x-c`,".cpp":`text/x-c++`,".cs":`text/x-csharp`,".rb":`text/x-ruby`,".php":`text/x-php`,".swift":`text/x-swift`,".scala":`text/x-scala`,".sql":`application/sql`,".xml":`application/xml`,".yaml":`text/yaml`,".yml":`text/yaml`,".toml":`text/toml`,".csv":`text/csv`,".graphql":`application/graphql`,".txt":`text/plain`,".pdf":`application/pdf`,".docx":`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,".xlsx":`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,".html":`text/html`,".css":`text/css`,".svg":`image/svg+xml`,".png":`image/png`,".jpg":`image/jpeg`,".jpeg":`image/jpeg`,".gif":`image/gif`,".webp":`image/webp`,".ico":`image/x-icon`,".bmp":`image/bmp`},$n=new Set(`.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff,.svg,.exe,.dll,.so,.dylib,.bin,.wasm,.class,.jar,.war,.pyd,.pyc,.pyo,.zip,.tar,.gz,.bz2,.7z,.rar,.ttf,.otf,.woff,.woff2,.eot,.db,.sqlite,.sqlite3,.pdf,.docx,.doc,.xlsx,.xls,.pptx,.ppt,.odt,.ods,.odp`.split(`,`));function er(e){return $n.has(e.toLowerCase())}function tr(e){return Qn[e.toLowerCase()]}function nr(...e){return F.join(...e).replaceAll(`\\`,`/`)}var rr=class{ctx;constructor(e){this.ctx=e}async processDirectory(e,t,n){let r=t?`${t}/${e.name}`:e.name;return this.scanSkillDirectoryAsync(n,r)}async processFile(e,t,n){let r=t?`${t}/${e.name}`:e.name;if(this.ctx.scanMode===`distChildDocs`){if(t===``&&e.name===`skill.mdx`||c(e.name)||!e.name.endsWith(`.mdx`))return{childDocs:[],resources:[]};let i=await this.processChildDoc(r,n);return{childDocs:i?[i]:[],resources:[]}}if(t===``&&e.name===`mcp.json`||c(e.name)||e.name.endsWith(`.mdx`))return{childDocs:[],resources:[]};let i=this.processResourceFile(e.name,r,n);return{childDocs:[],resources:i?[i]:[]}}async processChildDoc(e,n){try{let r=this.ctx.fs.readFileSync(n,`utf8`),i=M(r),a=ce((await t(r,{globalScope:this.ctx.globalScope,extractMetadata:!0,basePath:F.dirname(n),filePath:n})).content);return A(a,n),{type:D.SkillChildDoc,content:a,length:a.length,filePathKind:T.Relative,markdownAst:i.markdownAst,markdownContents:i.markdownContents,...i.rawFrontMatter!=null&&{rawFrontMatter:i.rawFrontMatter},relativePath:e,dir:{pathKind:T.Relative,path:e,basePath:this.ctx.skillDir,getDirectoryName:()=>F.dirname(e),getAbsolutePath:()=>n}}}catch(t){throw this.ctx.logger.error(w(t,{operation:`Failed to compile skill child doc.`,promptKind:`skill-child-doc`,logicalName:`${F.basename(this.ctx.skillDir)}/${e.replace(/\.mdx$/u,``)}`,distPath:n,srcPath:ue(F,n,{distRootDir:this.ctx.skillDir,srcRootDir:this.ctx.sourceSkillDir})}),{error:t}),t}}processResourceFile(e,t,n){let r=F.extname(e);try{let{content:i,encoding:a,length:o}=this.readFileContent(n,r),s=tr(r);return{type:D.SkillResource,extension:r,fileName:e,relativePath:t,sourcePath:n,content:i,encoding:a,length:o,...s!=null&&{mimeType:s}}}catch(e){return this.ctx.logger.warn(`failed to read resource file`,{path:t,error:e}),null}}readFileContent(e,t){if(er(t)){let t=this.ctx.fs.readFileSync(e);return{content:t.toString(`base64`),encoding:`base64`,length:t.length}}let n=this.ctx.fs.readFileSync(e,`utf8`);return{content:n,encoding:`text`,length:R.from(n,`utf8`).length}}async scanSkillDirectoryAsync(e,t=``){let n=[],r=[],i;try{i=this.ctx.fs.readdirSync(e,{withFileTypes:!0})}catch(t){return this.ctx.logger.warn(`failed to scan directory`,{path:e,error:t}),{childDocs:n,resources:r}}for(let a of i){let i=nr(e,a.name);if(a.isDirectory()){let e=await this.processDirectory(a,t,i);n.push(...e.childDocs),r.push(...e.resources);continue}if(!a.isFile())continue;let o=await this.processFile(a,t,i);n.push(...o.childDocs),r.push(...o.resources)}return{childDocs:n,resources:r}}};function ir(e,t,n,r=``){let i=[],a=r===``?e:nr(e,r),o;try{o=t.readdirSync(a,{withFileTypes:!0})}catch(e){return n.warn(`failed to scan source child docs`,{path:a,error:e}),i}for(let a of o){let o=r?`${r}/${a.name}`:a.name;if(a.isDirectory()){i.push(...ir(e,t,n,o));continue}!a.isFile()||!c(a.name)||r===``&&a.name===`skill.src.mdx`||i.push(o.replace(/\.src\.mdx$/u,`.mdx`))}return i}function ar(e,t,n,r,i){if(r.existsSync(t))for(let a of ir(t,r,i)){let i=F.join(n,a);if(!r.existsSync(i))throw new ve({kind:`skill child doc`,name:`${e}/${a}`,sourcePath:F.join(t,a.replace(/\.mdx$/u,`.src.mdx`)),expectedDistPath:i})}}function or(e,t,n){let r=F.join(e,`mcp.json`);if(t.existsSync(r)){if(!t.statSync(r).isFile()){n.warn(`mcp.json is not a file`,{skillDir:e});return}try{let i=t.readFileSync(r,`utf8`),a=JSON.parse(i);if(a.mcpServers==null||typeof a.mcpServers!=`object`){n.warn(`mcp.json missing mcpServers field`,{skillDir:e});return}return{type:D.SkillMcpConfig,mcpServers:a.mcpServers,rawContent:i}}catch(t){n.warn(`failed to parse mcp.json`,{skillDir:e,error:t});return}}}async function sr(e,n,r,i,a,o,s,c=[],l=[],u,d){let{logger:f,globalScope:p,fs:m}=o,h=F.join(a,`skill.mdx`),g=e,_,v;if(m.existsSync(h)){g=m.readFileSync(h,`utf8`),_=M(g);let n=await t(g,{globalScope:p,extractMetadata:!0,basePath:a,filePath:h});e=ce(n.content),A(e,h),v=n.metadata.fields}let y=Zn(Xn(g),d,v),b=_?.yamlFrontMatter?.description??y?.description;if(b==null||b.trim().length===0)throw f.error(`SKILL_VALIDATION_FAILED: description is required and cannot be empty`,{skill:r,skillDir:i,yamlDescription:_?.yamlFrontMatter?.description,exportDescription:y?.description,hint:`Add a non-empty description field to the SKILL.md front matter or export default`}),Error(`Skill "${r}" validation failed: description is required and cannot be empty`);let x={...y,..._?.yamlFrontMatter??{},name:r,description:b};return{type:D.Skill,content:e,length:e.length,filePathKind:T.Relative,yamlFrontMatter:x,markdownAst:_?.markdownAst,markdownContents:_?.markdownContents??[],dir:{pathKind:T.Relative,path:r,basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>F.join(i,r)},..._?.rawFrontMatter!=null&&{rawFrontMatter:_.rawFrontMatter},...s!=null&&{mcpConfig:s},...c!=null&&c.length>0&&{childDocs:c},...l!=null&&l.length>0&&{resources:l},...u!=null&&{seriName:u}}}var cr=class extends m{constructor(){super(`SkillInputPlugin`)}readMcpConfig(e,t,n){return or(e,t,n)}async scanSkillDirectory(e,t,n,r=``,i=`srcResources`,a,o){return new rr({fs:t,logger:n,skillDir:e,scanMode:i,...a!=null&&{globalScope:a},...o!=null&&{sourceSkillDir:o}}).scanSkillDirectoryAsync(e,r)}async collect(e){let{userConfigOptions:t,logger:r,fs:i,path:a,globalScope:o}=e,{aindexDir:s}=this.resolveBasePaths(t),c=this.resolveAindexPath(t.aindex.skills.src,s),l=this.resolveAindexPath(t.aindex.skills.dist,s),u=[],d=N(i,a,r,o),f=new Map,p=async e=>{let t=f.get(e);if(t!=null)return t;let n=a.join(c,e),s=a.join(l,e),u=i.existsSync(s)?(await this.scanSkillDirectory(s,i,r,``,`distChildDocs`,o,n)).childDocs:[],d=i.existsSync(n)?(await this.scanSkillDirectory(n,i,r,``,`srcResources`,o)).resources:[],p=or(n,i,r);ar(e,n,s,i,r);let m={childDocs:u,resources:d,...p!=null&&{mcpConfig:p}};return f.set(e,m),m},{prompts:m,errors:h}=await d.readDirectoryStructure(c,l,{kind:D.Skill,entryFileName:`skill`,localeExtensions:n,isDirectoryStructure:!0,createPrompt:async(t,n,r,i)=>{let o=a.join(l,r),{childDocs:s,resources:c,mcpConfig:u}=await p(r);return sr(t,n,r,l,o,e,u,s,c,void 0,i)}});for(let e of h)r.warn(`Failed to read skill`,{path:e.path,phase:e.phase,error:e.error});for(let e of m){let t=e.dist?.prompt;t!=null&&u.push(t)}return{skills:u}}},lr=class extends m{constructor(){super(`AindexInputPlugin`)}loadProjectConfig(e,t,n,r,i,a){let o=i.join(t,n,e,`project.jsonc`);if(r.existsSync(o))try{let t=r.readFileSync(o,`utf8`),n=[],i=je(t,n);if(n.length>0){a.warn(`failed to parse project.jsonc for ${e}`,{path:o,errors:n});return}return i}catch(t){a.warn(`failed to parse project.jsonc for ${e}`,{path:o,error:t});return}}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,aindexDir:o}=this.resolveBasePaths(t),s=this.resolveAindexPath(t.aindex.app.dist,o),c=i.basename(o),l=[];if(r.existsSync(s)&&r.statSync(s).isDirectory())try{let e=r.readdirSync(s,{withFileTypes:!0});for(let s of e)if(s.isDirectory()){let e=s.name===c,u=this.loadProjectConfig(s.name,o,t.aindex.app.src,r,i,n);l.push({name:s.name,...e&&{isPromptSourceProject:!0},...u!=null&&{projectConfig:u},dirFromWorkspacePath:{pathKind:T.Relative,path:s.name,basePath:a,getDirectoryName:()=>s.name,getAbsolutePath:()=>i.resolve(a,s.name)}})}}catch(e){n.error(`failed to scan aindex projects`,{path:s,error:e})}if(l.length===0&&r.existsSync(a)&&r.statSync(a).isDirectory()){n.debug(`no projects in dist/app/, falling back to workspace scan`,{workspaceDir:a});try{let e=r.readdirSync(a,{withFileTypes:!0});for(let s of e)if(s.isDirectory()&&!s.name.startsWith(`.`)){let e=s.name===c,u=this.loadProjectConfig(s.name,o,t.aindex.app.src,r,i,n);l.push({name:s.name,...e&&{isPromptSourceProject:!0},...u!=null&&{projectConfig:u},dirFromWorkspacePath:{pathKind:T.Relative,path:s.name,basePath:a,getDirectoryName:()=>s.name,getAbsolutePath:()=>i.resolve(a,s.name)}})}}catch(e){n.error(`failed to scan workspace directory`,{path:a,error:e})}}return{workspace:{directory:{pathKind:T.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:l}}}},ur=class extends m{constructor(){super(`CommandInputPlugin`)}createCommandPrompt(e,t,n,r,i,a){let{path:o}=i,s=n.replaceAll(`\\`,`/`),c=s.indexOf(`/`),l=c===-1?void 0:s.slice(0,c),u=(c===-1?s:s.slice(c+1)).replace(/\.mdx$/,``),d=u.indexOf(`_`),f=l??(d===-1?void 0:u.slice(0,Math.max(0,d))),p=l!=null||d===-1?u:u.slice(Math.max(0,d+1)),m=o.join(r,`${n}.mdx`),h=`${n}.mdx`,g=a,_={type:D.Command,content:e,length:e.length,filePathKind:T.Relative,dir:{pathKind:T.Relative,path:h,basePath:r,getDirectoryName:()=>h.replace(/\.mdx$/,``),getAbsolutePath:()=>m},...f!=null&&{commandPrefix:f},commandName:p};return g==null?_:(Object.assign(_,{yamlFrontMatter:g}),g.seriName!=null&&Object.assign(_,{seriName:g.seriName}),g.scope===`global`&&Object.assign(_,{globalOnly:!0}),_)}async collect(e){let{userConfigOptions:t,logger:r,path:i,fs:a,globalScope:o}=e,s=this.resolveBasePaths(t),c=this.resolveAindexPath(t.aindex.commands.src,s.aindexDir),l=this.resolveAindexPath(t.aindex.commands.dist,s.aindexDir);r.debug(`CommandInputPlugin collecting`,{srcDir:c,distDir:l,aindexDir:s.aindexDir});let{prompts:u,errors:d}=await N(a,i,r,o).readFlatFiles(c,l,{kind:D.Command,localeExtensions:n,isDirectoryStructure:!1,createPrompt:(t,n,r,i)=>this.createCommandPrompt(t,n,r,l,e,i)});r.debug(`CommandInputPlugin read complete`,{commandCount:u.length,errorCount:d.length});for(let e of d)r.warn(`Failed to read command`,{path:e.path,phase:e.phase,error:e.error});let f=[];for(let e of u){let t=e.dist;if(t?.prompt==null)continue;let{prompt:n,rawMdx:r}=t;f.push(r==null?n:{...n,rawMdxContent:r})}return r.debug(`CommandInputPlugin flattened commands`,{count:f.length,commands:f.map(e=>e.commandName)}),{commands:f}}},dr=class extends m{constructor(){super(`EditorConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n}=e,{workspaceDir:r,aindexDir:i}=this.resolveBasePaths(t),a=[],o=_(j.EditorConfig,`.editorconfig`,i,n,{command:e.runtimeCommand,workspaceDir:r});return o!=null&&a.push(o),{editorConfigFiles:a}}},fr=class extends m{constructor(){super(`GitExcludeInputPlugin`)}collect(t){let{workspaceDir:n,aindexDir:r}=this.resolveBasePaths(t.userConfigOptions),i=e(r,te,{command:t.runtimeCommand,workspaceDir:n});if(!t.fs.existsSync(i))return this.log.debug({action:`collect`,message:`File not found`,path:i}),{};let a=t.fs.readFileSync(i,`utf8`);return a.length===0?(this.log.debug({action:`collect`,message:`File is empty`,path:i}),{}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:i,length:a.length}),{shadowGitExclude:a})}},pr=class extends m{constructor(){super(`GitIgnoreInputPlugin`)}collect(t){let{workspaceDir:n,aindexDir:r}=this.resolveBasePaths(t.userConfigOptions),i=e(r,re,{command:t.runtimeCommand,workspaceDir:n});if(!t.fs.existsSync(i))return this.log.debug({action:`collect`,message:`File not found`,path:i}),{};let a=t.fs.readFileSync(i,`utf8`);return a.length===0?(this.log.debug({action:`collect`,message:`File is empty`,path:i}),{}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:i,length:a.length}),{globalGitIgnore:a})}},mr=class extends m{constructor(){super(`GlobalMemoryInputPlugin`)}async collect(e){let{userConfigOptions:n,fs:r,path:i,globalScope:a}=e,{aindexDir:o}=this.resolveBasePaths(n),s=this.resolveAindexPath(n.aindex.globalPrompt.dist,o);if(!r.existsSync(s))return this.log.warn({action:`collect`,reason:`fileNotFound`,path:s}),{};if(!r.statSync(s).isFile())return this.log.warn({action:`collect`,reason:`notAFile`,path:s}),{};let c=r.readFileSync(s,`utf8`),l=M(c),u;try{u=(await t(c,{...a!=null&&{globalScope:a},extractMetadata:!0,basePath:i.dirname(s),filePath:s})).content,A(u,s)}catch(e){throw e instanceof O&&(this.log.error(w(e,{operation:`Failed to compile global memory prompt.`,promptKind:`global-memory`,logicalName:`global-memory`,distPath:s})),e instanceof p&&(this.log.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),this.log.error(`For example, if using {profile.name}, add a "profile" section with "name" field to your config.`)),I.exit(1)),e}return this.log.debug({action:`collect`,path:s,contentLength:u.length}),{globalMemory:{type:D.GlobalMemory,content:u,length:u.length,filePathKind:T.Relative,...l.rawFrontMatter!=null&&{rawFrontMatter:l.rawFrontMatter},markdownAst:l.markdownAst,markdownContents:l.markdownContents,dir:{pathKind:T.Relative,path:i.basename(s),basePath:i.dirname(s),getDirectoryName:()=>i.basename(s),getAbsolutePath:()=>s},parentDirectoryPath:{type:we.UserHome,directory:{pathKind:T.Relative,path:``,basePath:L.homedir(),getDirectoryName:()=>i.basename(L.homedir()),getAbsolutePath:()=>L.homedir()}}}}}},hr=class extends m{constructor(){super(`JetBrainsConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n}=e,{workspaceDir:r,aindexDir:i}=this.resolveBasePaths(t),a=[`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`],o=[];for(let t of a){let a=_(j.IntellijIDEA,t,i,n,{command:e.runtimeCommand,workspaceDir:r});a!=null&&o.push(a)}return{jetbrainsConfigFiles:o}}};const gr=`agt.mdx`,_r=[`node_modules`,`.git`];var vr=class extends m{constructor(){super(`ProjectPromptInputPlugin`,[`AindexInputPlugin`])}async collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i,globalScope:a}=e,{aindexDir:o}=this.resolveBasePaths(r),s=this.resolveAindexPath(r.aindex.app.dist,o),c=t.workspace;if(c==null)return this.log.warn(`No workspace found in dependency context, skipping project prompt enhancement`),{};let l=c.projects??[],u=await Promise.all(l.map(async t=>{let r=t.name;if(r==null)return t;let o=i.join(s,r);if(!n.existsSync(o)||!n.statSync(o).isDirectory())return t;let c=t.dirFromWorkspacePath?.getAbsolutePath(),l=await this.readRootMemoryPrompt(e,o,a),u=c==null?[]:await this.scanChildMemoryPrompts(e,o,c,a);return{...t,...l!=null&&{rootMemoryPrompt:l},...u.length>0&&{childMemoryPrompts:u}}}));return{workspace:{directory:c.directory,projects:u}}}async readRootMemoryPrompt(e,n,r){let{fs:i,path:a,logger:o}=e,s=a.join(n,gr);if(!(!i.existsSync(s)||!i.statSync(s).isFile()))try{let e=i.readFileSync(s,`utf8`),a=M(e),c;try{let{content:i}=await t(e,{globalScope:r,extractMetadata:!0,basePath:n,filePath:s});c=i,A(c,s)}catch(e){throw e instanceof O&&(o.error(w(e,{operation:`Failed to compile project root memory prompt.`,promptKind:`project-root-memory`,logicalName:s,distPath:s})),e instanceof p&&o.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),I.exit(1)),e}return{type:D.ProjectRootMemory,content:c,length:c.length,filePathKind:T.Relative,...a.yamlFrontMatter!=null&&{yamlFrontMatter:a.yamlFrontMatter},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:T.Root,path:``,getDirectoryName:()=>``}}}catch(e){o.error(`Failed to read root memory prompt at ${s}`,{error:e});return}}async scanChildMemoryPrompts(e,t,n,r){let{logger:i}=e,a=[];try{await this.scanDirectoryRecursive(e,t,t,n,a,r)}catch(e){i.error(`Failed to scan child memory prompts at ${t}`,{error:e})}return a}async scanDirectoryRecursive(e,t,n,r,i,a){let{fs:o,path:s}=e,c=o.readdirSync(n,{withFileTypes:!0});for(let l of c){if(!l.isDirectory()||_r.includes(l.name))continue;let c=s.join(n,l.name),u=s.join(c,gr);if(o.existsSync(u)&&o.statSync(u).isFile()){let n=await this.readChildMemoryPrompt(e,t,c,r,a);n!=null&&i.push(n)}await this.scanDirectoryRecursive(e,t,c,r,i,a)}}async readChildMemoryPrompt(e,n,r,i,a){let{fs:o,path:s,logger:c}=e,l=s.join(r,gr);try{let e=o.readFileSync(l,`utf8`),u=M(e),d;try{let{content:n}=await t(e,{globalScope:a,extractMetadata:!0,basePath:r,filePath:l});d=n,A(d,l)}catch(e){throw e instanceof O&&(c.error(w(e,{operation:`Failed to compile project child memory prompt.`,promptKind:`project-child-memory`,logicalName:l,distPath:l})),e instanceof p&&c.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),I.exit(1)),e}let f=s.relative(n,r),m=s.join(i,f),h=s.basename(r);return{type:D.ProjectChildrenMemory,content:d,length:d.length,filePathKind:T.Relative,...u.yamlFrontMatter!=null&&{yamlFrontMatter:u.yamlFrontMatter},...u.rawFrontMatter!=null&&{rawFrontMatter:u.rawFrontMatter},markdownAst:u.markdownAst,markdownContents:u.markdownContents,dir:{pathKind:T.Relative,path:f,basePath:i,getDirectoryName:()=>h,getAbsolutePath:()=>m},workingChildDirectoryPath:{pathKind:T.Relative,path:f,basePath:i,getDirectoryName:()=>h,getAbsolutePath:()=>m}}}catch(e){c.error(`Failed to read child memory prompt at ${l}`,{error:e});return}}};const yr=Object.entries(ke);var br=class extends m{constructor(){super(`ReadmeMdInputPlugin`,[`AindexInputPlugin`])}async collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i,globalScope:a}=e,{workspaceDir:o,aindexDir:s}=this.resolveBasePaths(t),c=this.resolveAindexPath(t.aindex.app.dist,s),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`aindex projects directory does not exist`,{path:c}),{readmePrompts:l};try{let t=r.readdirSync(c,{withFileTypes:!0});for(let n of t){if(!n.isDirectory())continue;let t=n.name,r=i.join(c,t);await this.collectReadmeFiles(e,r,t,o,``,l,a)}}catch(e){n.error(`failed to scan aindex projects`,{path:c,error:e})}return{readmePrompts:l}}async collectReadmeFiles(e,n,r,i,a,o,s){let{fs:c,path:l,logger:u}=e,d=a===``;for(let[e,{src:f}]of yr){let m=l.join(n,f);if(!(!c.existsSync(m)||!c.statSync(m).isFile()))try{let h=c.readFileSync(m,`utf8`),g;try{let{content:e}=await t(h,{...s!=null&&{globalScope:s},extractMetadata:!0,basePath:n,filePath:m});g=e,A(g,m)}catch(e){throw e instanceof O&&(u.error(w(e,{operation:`Failed to compile readme-family prompt.`,promptKind:`readme-family`,logicalName:`${r}/${f}`,distPath:m})),e instanceof p&&u.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),I.exit(1)),e}let _=d?r:l.join(r,a),v={pathKind:T.Relative,path:_,basePath:i,getDirectoryName:()=>d?r:l.basename(a),getAbsolutePath:()=>l.resolve(i,_)},y={pathKind:T.Relative,path:l.dirname(m),basePath:i,getDirectoryName:()=>l.basename(l.dirname(m)),getAbsolutePath:()=>l.dirname(m)};o.push({type:D.Readme,content:g,length:g.length,filePathKind:T.Relative,projectName:r,targetDir:v,isRoot:d,fileKind:e,markdownContents:[],dir:y})}catch(t){u.warn(`failed to read readme-family file`,{path:m,fileKind:e,error:t})}}try{let t=c.readdirSync(n,{withFileTypes:!0});for(let c of t)if(c.isDirectory()){let t=d?c.name:l.join(a,c.name),u=l.join(n,c.name);await this.collectReadmeFiles(e,u,r,i,t,o,s)}}catch(e){u.warn(`failed to scan directory`,{path:n,error:e})}}},xr=class extends m{constructor(){super(`RuleInputPlugin`)}async collect(e){let{userConfigOptions:t,logger:r,path:i,fs:a,globalScope:o}=e,s=this.resolveBasePaths(t),c=this.resolveAindexPath(t.aindex.rules.src,s.aindexDir),l=this.resolveAindexPath(t.aindex.rules.dist,s.aindexDir),{prompts:u,errors:d}=await N(a,i,r,o).readFlatFiles(c,l,{kind:D.Rule,localeExtensions:n,isDirectoryStructure:!1,createPrompt:async(e,t,n,r)=>{let a=r,o=a?.globs??[],s=a?.scope??`project`,c=a?.seriName,u=n.replaceAll(`\\`,`/`),d=u.includes(`/`)?u.split(`/`)[0]??``:``,f=u.split(`/`).pop()??u,p={type:D.Rule,content:e,length:e.length,filePathKind:T.Relative,dir:{pathKind:T.Relative,path:`${n}.mdx`,basePath:l,getDirectoryName:()=>f,getAbsolutePath:()=>i.join(l,`${n}.mdx`)},prefix:d,ruleName:f,globs:o,scope:s,markdownContents:[]};return a!=null&&Object.assign(p,{yamlFrontMatter:a}),c!=null&&Object.assign(p,{seriName:c}),p}});for(let e of d)r.warn(`Failed to read rule`,{path:e.path,phase:e.phase,error:e.error});return{rules:u.map(e=>e.dist?.prompt).filter(e=>e!=null)}}},Sr=class extends m{constructor(){super(`AIAgentIgnoreInputPlugin`)}collect(t){let{workspaceDir:n,aindexDir:r}=this.resolveBasePaths(t.userConfigOptions),i=[];for(let a of ne){let o=e(r,a,{command:t.runtimeCommand,workspaceDir:n});if(!t.fs.existsSync(o)){this.log.debug({action:`collect`,message:`Ignore file not found`,path:o});continue}let s=t.fs.readFileSync(o,`utf8`);if(s.length===0){this.log.debug({action:`collect`,message:`Ignore file is empty`,path:o});continue}i.push({fileName:a,content:s,sourcePath:o}),this.log.debug({action:`collect`,message:`Loaded ignore file`,path:o,fileName:a})}return i.length===0?{}:{aiAgentIgnoreConfigFiles:i}}},Cr=class extends m{constructor(){super(`SubAgentInputPlugin`)}createSubAgentPrompt(e,t,n,r,i,a){let{path:o}=i,s=n.replaceAll(`\\`,`/`),c=s.indexOf(`/`),l=c===-1?void 0:s.slice(0,c),u=(c===-1?s:s.slice(c+1)).replace(/\.mdx$/,``),d=u.indexOf(`_`),f=l??(d===-1?void 0:u.slice(0,Math.max(0,d))),p=l!=null||d===-1?u:u.slice(Math.max(0,d+1)),m=o.join(r,`${n}.mdx`),h=`${n}.mdx`,g=a,_={type:D.SubAgent,content:e,length:e.length,filePathKind:T.Relative,dir:{pathKind:T.Relative,path:h,basePath:r,getDirectoryName:()=>h.replace(/\.mdx$/,``),getAbsolutePath:()=>m},...f!=null&&{agentPrefix:f},agentName:p};return g==null?_:(Object.assign(_,{yamlFrontMatter:g}),g.seriName!=null&&Object.assign(_,{seriName:g.seriName}),_)}async collect(e){let{userConfigOptions:t,logger:r,path:i,fs:a,globalScope:o}=e,s=this.resolveBasePaths(t),c=this.resolveAindexPath(t.aindex.subAgents.src,s.aindexDir),l=this.resolveAindexPath(t.aindex.subAgents.dist,s.aindexDir);r.debug(`SubAgentInputPlugin collecting`,{srcDir:c,distDir:l,aindexDir:s.aindexDir});let{prompts:u,errors:d}=await N(a,i,r,o).readFlatFiles(c,l,{kind:D.SubAgent,localeExtensions:n,isDirectoryStructure:!1,createPrompt:(t,n,r,i)=>this.createSubAgentPrompt(t,n,r,l,e,i)});r.debug(`SubAgentInputPlugin read complete`,{subAgentCount:u.length,errorCount:d.length});for(let e of d)r.warn(`Failed to read subAgent`,{path:e.path,phase:e.phase,error:e.error});let f=[];for(let e of u){let t=e.dist;if(t?.prompt==null)continue;let{prompt:n,rawMdx:r}=t;f.push(r==null?n:{...n,rawMdxContent:r})}return r.debug(`SubAgentInputPlugin flattened subAgents`,{count:f.length,agents:f.map(e=>e.agentName)}),{subAgents:f}}},wr=class extends m{constructor(){super(`VSCodeConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n}=e,{workspaceDir:r,aindexDir:i}=this.resolveBasePaths(t),a=[`.vscode/settings.json`,`.vscode/extensions.json`],o=[];for(let t of a){let a=_(j.VSCode,t,i,n,{command:e.runtimeCommand,workspaceDir:r});a!=null&&o.push(a)}return{vscodeConfigFiles:o}}},Tr=class extends m{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,aindexDir:r}=this.resolveBasePaths(t);return{workspace:{directory:{pathKind:T.Absolute,path:n,getDirectoryName:()=>F.basename(n)},projects:[]},aindexDir:r}}};const Er=`GLOBAL.md`;var Dr=class extends E{constructor(){super(`TraeCNIDEOutputPlugin`,{globalConfigDir:`.trae-cn`,outputFileName:Er,dependsOn:[`TraeIDEOutputPlugin`],cleanup:{delete:{global:{dirs:[`.trae-cn/user_rules`]}}},capabilities:{prompt:{scopes:[`global`],singleScope:!1}}})}getGlobalUserRulesDir(){return this.joinPath(this.getGlobalConfigDir(),`user_rules`)}async declareOutputFiles(e){if(!new Set(this.selectPromptScopes(e,[`global`])).has(`global`))return[];let{globalMemory:t}=e.collectedOutputContext;return t==null?[]:[{path:this.joinPath(this.getGlobalUserRulesDir(),Er),scope:`global`,source:{content:t.content}}]}async convertContent(e,t){let n=e.source;if(n.content==null)throw Error(`Unsupported declaration source for ${this.name}`);return n.content}},Or=Rn({pipelineArgs:I.argv,pluginOptions:{plugins:[new Ie,new Re,new at,new et,new Ke,new Xe,new Pe,new st,new mt,new bt,new Dr,new wt,new kt,new We,new Ze,new nt,new Je,new St,new gt,new Hn,new Vn,new zn,new Tr,new lr,new wr,new hr,new dr,new cr,new ur,new Cr,new xr,new mr,new vr,new br,new pr,new fr,new Sr]}});export{Or as default};