@truenine/memory-sync-cli 2026.10314.10813 → 2026.10317.12338
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/globals.d.cts +1 -1
- package/dist/globals.d.mts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin-runtime.mjs +57 -48
- package/dist/plugin.config-94j_-y7H.mjs +188 -0
- package/dist/plugin.config-DZUQlXdU.mjs +81 -0
- package/dist/plugin.config-DshgEVJW.cjs +188 -0
- package/dist/tnmsc.schema.json +9 -12
- package/package.json +10 -10
- package/dist/plugin.config-CwTid43p.mjs +0 -171
- package/dist/plugin.config-M0Vfj7Yf.cjs +0 -171
- package/dist/plugin.config-PD_T1uuL.mjs +0 -73
|
@@ -1,73 +0,0 @@
|
|
|
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 ee,V as te,W as ne,X as x,Y as S,Z as C,_ as re,a as ie,at as w,b as ae,c as oe,ct as se,d as T,et as ce,f as le,g as ue,h as de,i as fe,it as E,j as pe,k as D,l as me,m as he,n as ge,nt as O,o as _e,ot as ve,p as ye,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as k,u as A,v as Ee,w as De,x as Oe,y as ke,z as Ae}from"./plugin-runtime.mjs";import*as j from"node:fs";import*as M from"node:path";import N from"node:process";import*as P from"node:os";import{Buffer as F}from"node:buffer";import{createHash as je}from"node:crypto";import{parse as Me}from"jsonc-parser";const Ne=`.agents/skills`,Pe=`SKILL.md`;var Fe=class extends T{constructor(){super(`GenericSkillsOutputPlugin`,{outputFileName:Pe,skills:{},cleanup:{delete:{project:{dirs:[Ne]}}},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:i}=e.collectedOutputContext;if(i==null||i.length===0)return t;let a=this.selectSingleScopeItems(i,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)),o=this.selectSingleScopeItems(i,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 i=r(a.items,e.projectConfig,`skills`),s=r(o.items,e.projectConfig,`skills`);if(i.length===0)continue;let c=this.joinPath(n.basePath,n.path,Ne);for(let e of i){let n=e.yamlFrontMatter.name,r=this.joinPath(c,n);if(t.push({path:this.joinPath(r,Pe),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 O(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillMcp`:return n.rawContent;case`skillChildDoc`:return n.content;case`skillResource`:return n.encoding===`base64`?F.from(n.content,`base64`):n.content;default:throw Error(`Unsupported declaration source for ${this.name}`)}}};const Ie=`AGENTS.md`;var Le=class extends T{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Ie,cleanup:{delete:{project:{files:[Ie]}}},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 Re=`CLAUDE.md`;var ze=class extends T{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:`.claude`,outputFileName:Re,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(Se)})},cleanup:{delete:{project:{files:[Re],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 I=pe.CURSOR,Be=m.MCP_CONFIG,Ve=g.COMMANDS,L=g.RULES,He=m.CURSOR_GLOBAL_RULE,R=g.CURSOR_SKILLS,Ue=m.SKILL,We=l.CURSOR;var Ge=class extends T{constructor(){super(`CursorOutputPlugin`,{globalConfigDir:I,outputFileName:``,dependsOn:[o.AgentsOutput],indexignore:p.CURSOR,commands:{subDir:Ve,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:R},rules:{subDir:L,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:[...We].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:i,commands:a,skills:o,rules:s,aiAgentIgnoreConfigFiles:c}=e.collectedOutputContext,l=this.getGlobalConfigDir(),u=this.resolvePromptSourceProjectConfig(e),d=new Set(this.selectPromptScopes(e,[`global`])),f=r((o==null?{items:[]}:this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`))).items,u,`skills`),p=r((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=M.join(l,R,n);if(t.push({path:M.join(r,Ue),scope:`global`,source:{kind:`globalSkill`,skill:e}}),e.mcpConfig!=null&&p.includes(e)&&t.push({path:M.join(r,Be),scope:`global`,source:{kind:`globalSkillMcpConfig`,rawContent:e.mcpConfig.rawContent}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:M.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:M.join(r,n.relativePath),scope:`global`,source:{kind:`globalSkillResource`,content:n.content,encoding:n.encoding}})}if(p.length>0){let n=new Ce({fs:e.fs,logger:this.log}),r=n.collectMcpServers(p);if(r.size>0){let e=n.transformMcpServers(r,oe);t.push({path:M.join(l,Be),scope:`global`,source:{kind:`globalMcpConfig`,mcpServers:e}})}}if(a!=null&&a.length>0){let n=r(this.selectSingleScopeItems(a,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)).items,u,`commands`),i=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of n){let n=this.transformCommandName(e,i);t.push({path:M.join(l,Ve,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:M.join(l,L,this.buildRuleFileName(e)),scope:`global`,source:{kind:`ruleMdc`,rule:e}});if(i!=null&&d.has(`global`)){let e=this.buildGlobalRuleContent(i.content);for(let r of n.projects){let n=r.dirFromWorkspacePath;n!=null&&t.push({path:M.join(n.basePath,n.path,I,L,He),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 i=y(r(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of i)t.push({path:M.join(n.basePath,n.path,I,L,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:M.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 O(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`?F.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 O({description:`Global prompt (synced)`,alwaysApply:!0},e)}isPreservedSkill(e){return We.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(),R,`*`).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(M.basename(t)))return[];try{return[{path:t,kind:e.fs.lstatSync(t).isDirectory()?`directory`:`file`}]}catch{return[]}})}buildRuleMdcContent(e){return O({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 Ke=`AGENTS.md`;var qe=class extends T{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:`.factory`,outputFileName:Ke,commands:{transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{},cleanup:{delete:{project:{files:[Ke],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 Je=`.editorconfig`;var Ye=class extends T{constructor(){super(`EditorConfigOutputPlugin`,{cleanup:{delete:{project:{files:[Je]}}},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,Je),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 Xe=`GEMINI.md`;var Ze=class extends T{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:`.gemini`,outputFileName:Xe,cleanup:{delete:{project:{globs:[Xe]},global:{files:[`.gemini/GEMINI.md`]}}},capabilities:{prompt:{scopes:[`project`,`global`],singleScope:!1}}})}},Qe=class extends T{constructor(){super(`GitExcludeOutputPlugin`,{capabilities:{}})}async declareOutputFiles(e){let t=[],{workspace:n,globalGitIgnore:r,shadowGitExclude:i}=e.collectedOutputContext,o=this.buildManagedContent(r,i);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,...De(n)];for(let e of r){let n=a(e);if(n==null)continue;let r=M.join(n,`exclude`);c.has(r)||(c.add(r),t.push({path:r,scope:`project`,source:{content:s}}))}}let u=n.directory.path,d=a(u);if(d!=null){let e=M.join(d,`exclude`);c.has(e)||(c.add(e),t.push({path:e,scope:`workspace`,source:{content:s}}))}let f=De(u);for(let e of f){let n=a(e);if(n==null)continue;let r=M.join(n,`exclude`);c.has(r)||(c.add(r),t.push({path:r,scope:`workspace`,source:{content:s}}))}let p=M.join(u,`.git`);if(this.existsSync(p)&&this.lstatSync(p).isDirectory())for(let e of b(p)){let n=M.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 z=`AGENTS.md`,B=`prompts`,V=`skills`,$e=[`IntelliJIdea`,`WebStorm`,`RustRover`,`PyCharm`,`PyCharmCE`,`PhpStorm`,`GoLand`,`CLion`,`DataGrip`,`RubyMine`,`Rider`,`DataSpell`,`Aqua`];var et=class extends T{constructor(){super(`JetBrainsAIAssistantCodexOutputPlugin`,{outputFileName:z,commands:{subDir:B,transformFrontMatter:(e,t)=>t.sourceFrontMatter??{}},skills:{subDir:V},dependsOn:[o.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:i,commands:a,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=M.join(n.basePath,n.path,`.aiassistant`,`rules`);if(e.rootMemoryPrompt!=null&&t.push({path:M.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:M.join(r,this.buildChildRuleFileName(n)),scope:`project`,source:{kind:`projectRuleContent`,content:this.buildGlobRuleContent(n)}})}if(l.length>0){let n=this.resolvePromptSourceProjectConfig(e),s=r((a==null?{items:[]}:this.selectSingleScopeItems(a,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`))).items,n,`commands`),c=r((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){i!=null&&u.has(`global`)&&t.push({path:M.join(e,z),scope:`global`,source:{kind:`globalMemory`,content:i.content}});for(let n of s)t.push({path:M.join(e,B,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=M.join(e,V,r);if(t.push({path:M.join(i,`SKILL.md`),scope:`global`,source:{kind:`globalSkill`,skill:n}}),n.childDocs!=null)for(let e of n.childDocs)t.push({path:M.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:M.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:M.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:M.join(e,z),kind:`file`,scope:`global`},{path:M.join(e,B),kind:`directory`,scope:`global`},{path:M.join(e,V),kind:`directory`,scope:`global`}]),i=t.delete??[];return{...t,delete:[...i,...r]}}resolveCodexDirs(){let e=M.join(ve(),`JetBrains`);if(!this.existsSync(e))return[];try{return this.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()?this.isSupportedIdeDir(e.name):!1).map(t=>M.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 O({apply:`始终`},e)}buildGlobRuleContent(e){return O({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(` `)),O(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 T{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(t){let n=t.dir.path;if(t.type===e.EditorConfig)return`.editorconfig`;if(t.type!==e.IntellijIDEA)return this.basename(n);let r=n.indexOf(tt);return r===-1?this.joinPath(tt,`codeStyles`,this.basename(n)):n.slice(Math.max(0,r))}};const rt=`AGENTS.md`,it=`prompts`;var at=class extends T{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:[o.AgentsOutput],capabilities:{prompt:{scopes:[`global`],singleScope:!1},commands:{scopes:[`project`,`workspace`,`global`],singleScope:!0}}})}async declareOutputFiles(e){let{globalMemory:t,commands:n}=e.collectedOutputContext,i=this.getGlobalConfigDir(),a=[],o=new Set(this.selectPromptScopes(e,[`global`]));if(t!=null&&o.has(`global`)&&a.push({path:M.join(i,rt),scope:`global`,source:{kind:`globalMemory`,content:t.content}}),n==null||n.length===0)return a;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 a;let u=r(l.items,s,`commands`);for(let e of u){let t=this.transformCommandName(e,c);a.push({path:M.join(i,it,t),scope:`global`,source:{kind:`command`,command:e}})}return a}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 H=`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 T{constructor(){super(`OpencodeCLIOutputPlugin`,{globalConfigDir:`.config/opencode`,outputFileName:H,commands:{subDir:`commands`,transformFrontMatter:ot},subagents:{subDir:`agents`},skills:{subDir:`skills`},cleanup:{delete:{project:{files:[H],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:[o.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:i,commands:a,subAgents:o,skills:s}=e.collectedOutputContext,c=this.getGlobalConfigDir(),l=new Set(this.selectPromptScopes(e,[`project`,`global`])),u=a==null?{items:[]}:this.selectSingleScopeItems(a,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(i!=null&&l.has(`global`)&&t.push({path:M.join(c,H),scope:`global`,source:{kind:`globalMemory`,content:i.content}}),p.items.length>0){let n=this.resolvePromptSourceProjectConfig(e),i=r(p.items,n,`skills`),a=new Ce({fs:e.fs,logger:this.log}),o=a.collectMcpServers(i);o.size>0&&t.push({path:M.join(c,`opencode.json`),scope:`global`,source:{kind:`globalMcpConfig`,mcpServers:a.transformMcpServers(o,me)}})}let m=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n==null)continue;let i=M.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=r(u.items,e.projectConfig,`commands`);for(let e of n)t.push({path:M.join(i,this.commandsConfig.subDir,this.transformCommandName(e,m)),scope:`project`,source:{kind:`command`,command:e}})}if(this.subAgentOutputEnabled&&d.items.length>0){let n=r(d.items,e.projectConfig,`subAgents`),{subDir:a}=this.subAgentsConfig;for(let e of n)t.push({path:M.join(i,a,this.transformSubAgentName(e)),scope:`project`,source:{kind:`subAgent`,agent:e}})}if(this.skillOutputEnabled&&f.items.length>0){let n=r(f.items,e.projectConfig,`skills`);for(let e of n){let n=this.validateAndNormalizeSkillName(e.yamlFrontMatter?.name??e.dir.getDirectoryName()),r=M.join(i,this.skillsConfig.subDir,n);if(t.push({path:M.join(r,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:e,normalizedSkillName:n}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:M.join(r,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:M.join(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`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`?F.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`,U=`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 T{constructor(){super(`QoderIDEPluginOutputPlugin`,{globalConfigDir:ct,indexignore:`.qoderignore`,commands:{subDir:lt,transformFrontMatter:pt},skills:{subDir:ut},rules:{subDir:U,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:i,commands:a,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(a!=null&&a.length>0){let n=r(this.selectSingleScopeItems(a,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)).items,d,`commands`);for(let e of n)t.push({path:M.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:M.join(u,U,this.buildRuleFileName(n)),scope:`global`,source:{kind:`rulePrompt`,rule:n}})}if(o!=null&&o.length>0){let n=r(this.selectSingleScopeItems(o,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)).items,d,`skills`),i=r(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,r=M.join(u,ut,n);if(t.push({path:M.join(r,`SKILL.md`),scope:`global`,source:{kind:`skillMain`,skill:e}}),e.mcpConfig!=null&&i.includes(e)&&t.push({path:M.join(r,`mcp.json`),scope:`global`,source:{kind:`skillMcpConfig`,rawContent:e.mcpConfig.rawContent}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:M.join(r,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:M.join(r,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 a=M.join(n.basePath,n.path,ct,U);if(i!=null&&m.has(`global`)&&t.push({path:M.join(a,`global.md`),scope:`project`,source:{kind:`ruleContent`,content:this.buildAlwaysRuleContent(i.content)}}),e.rootMemoryPrompt!=null&&m.has(`project`)&&t.push({path:M.join(a,`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:M.join(a,this.buildChildRuleFileName(n)),scope:`project`,source:{kind:`ruleContent`,content:this.buildGlobRuleContent(n)}});if(s!=null&&s.length>0&&p.has(`project`)){let n=y(r(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of n)t.push({path:M.join(a,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:M.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 O(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`?F.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 O({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 O({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 O({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 de[e??`Readme`].out}var gt=class extends T{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=M.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`,W=`.trae`,vt=`commands`,yt=`skills`;var bt=class extends T{constructor(){super(`TraeIDEOutputPlugin`,{globalConfigDir:W,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 M.join(`.trae`,`.ignore`)}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),`steering`)}async declareOutputFiles(e){let t=[],{projects:n}=e.collectedOutputContext.workspace,{commands:i,skills:a,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=r((i==null?{items:[]}:this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`))).items,c,`commands`),d=r((a==null?{items:[]}:this.selectSingleScopeItems(a,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=M.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=O({alwaysApply:!1,globs:this.buildProjectRelativeGlobPattern(e)},[this.buildPathGuardHint(e),``,n.content].join(`
|
|
6
|
-
`));t.push({path:M.join(r,W,`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:M.join(r,W,vt,n),scope:`project`,source:{kind:`command`,command:e}})}for(let e of d){let n=e.yamlFrontMatter.name,i=M.join(r,W,yt,n);if(t.push({path:M.join(i,`SKILL.md`),scope:`project`,source:{kind:`skillMain`,skill:e}}),e.childDocs!=null)for(let n of e.childDocs)t.push({path:M.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:M.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:M.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 O(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillResource`:return n.encoding===`base64`?F.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 T{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(t){let n=t.dir.path;if(t.type!==e.VSCode)return this.basename(n);let r=n.indexOf(xt);return r===-1?this.joinPath(xt,this.basename(n)):n.slice(Math.max(0,r))}};const Ct=`WARP.md`;var wt=class extends T{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,s=this.shouldSkipDueToPlugin(e,o.AgentsOutput),c=new Set(this.selectPromptScopes(e,[`project`,`global`]));if(s){if(r!=null&&c.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&&c.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&&c.has(`project`))for(let n of e.childMemoryPrompts)t.push({path:this.resolveFullPath(n.dir),scope:`project`,source:{content:n.content}})}}}let l=this.getIgnoreOutputPath(),u=this.indexignore==null?void 0:i?.find(e=>e.fileName===this.indexignore);if(l!=null&&u!=null)for(let e of a){let n=e.dirFromWorkspacePath;n==null||e.isPromptSourceProject===!0||t.push({path:this.resolvePath(n.basePath,n.path,l),scope:`project`,source:{content:u.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 G=`.codeium/windsurf`,Tt=`global_workflows`,Et=`memories`,Dt=`skills`,Ot=`.windsurf`;var kt=class extends T{constructor(){super(`WindsurfOutputPlugin`,{globalConfigDir:G,outputFileName:``,dependsOn:[o.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:i,skills:a,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 M.join(d,G);if(t!=null)return M.join(t.basePath,t.path,Ot)};if(o!=null&&f.has(`global`)&&t.push({path:M.join(u,Et,`global_rules.md`),scope:`global`,source:{kind:`globalMemory`,content:o.content}}),a!=null&&a.length>0){let i=this.selectSingleScopeItems(a,this.skillsConfig.sourceScopes,e=>this.resolveSkillSourceScope(e),this.getTopicScopeOverride(e,`skills`)),o=(e,n,r)=>{let i=r.yamlFrontMatter.name,a=M.join(e,Dt,i);if(t.push({path:M.join(a,`SKILL.md`),scope:n,source:{kind:`skillMain`,skill:r}}),r.childDocs!=null)for(let e of r.childDocs)t.push({path:M.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:M.join(a,e.relativePath),scope:n,source:{kind:`skillResource`,content:e.content,encoding:e.encoding}})};if(i.selectedScope===`project`)for(let e of n.projects){let t=e.dirFromWorkspacePath,n=p(`project`,t);if(n==null)continue;let a=r(i.items,e.projectConfig,`skills`);for(let e of a)o(n,`project`,e)}else if(i.selectedScope!=null){let e=p(i.selectedScope);if(e!=null){let t=r(i.items,l,`skills`);for(let n of t)o(e,i.selectedScope,n)}}}if(i!=null&&i.length>0){let a=this.selectSingleScopeItems(i,this.commandsConfig.sourceScopes,e=>this.resolveCommandSourceScope(e),this.getTopicScopeOverride(e,`commands`)),o=this.getTransformOptionsFromContext(e,{includeSeriesPrefix:!0});if(a.selectedScope===`project`)for(let e of n.projects){let n=e.dirFromWorkspacePath,i=p(`project`,n);if(i==null)continue;let s=r(a.items,e.projectConfig,`commands`);for(let e of s)t.push({path:M.join(i,`workflows`,this.transformCommandName(e,o)),scope:`project`,source:{kind:`command`,command:e}})}else if(a.selectedScope!=null){let e=p(a.selectedScope);if(e!=null){let n=r(a.items,l,`commands`);for(let r of n)t.push({path:M.join(e,Tt,this.transformCommandName(r,o)),scope:a.selectedScope,source:{kind:`command`,command:r}})}}}if(s!=null&&s.length>0){let i=new Set(this.selectRuleScopes(e,s)),a=s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`global`);if(i.has(`global`))for(let e of a)t.push({path:M.join(u,Et,this.buildRuleFileName(e)),scope:`global`,source:{kind:`rule`,rule:e}});if(i.has(`project`))for(let e of n.projects){let n=e.dirFromWorkspacePath;if(n==null)continue;let i=y(r(s.filter(e=>this.normalizeSourceScope(this.normalizeRuleScope(e))===`project`),e.projectConfig,`rules`),e.projectConfig);for(let e of i)t.push({path:M.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:M.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 O(this.buildSkillFrontMatter(n.skill),n.skill.content);case`skillResource`:return n.encoding===`base64`?F.from(n.content,`base64`):n.content;case`rule`:return this.buildRuleContent(n.rule);default:throw Error(`Unsupported declaration source for ${this.name}`)}}getCodeiumWindsurfDir(){return M.join(this.getHomeDir(),G)}buildRuleFileName(e,t=`rule-`){return`${t}${e.prefix}-${e.ruleName}.md`}buildRuleContent(e,t){return O({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
|
-
`)}},K=se(we(),1);function At(e,t){let n=M.join(e,`.git`),r=j.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=n(`ConfigLoader`)}getSearchPaths(e=N.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(M.join(e,this.configFileName)),this.searchGlobal&&t.push(M.join(P.homedir(),Mt,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!j.existsSync(t))return{config:{},source:null,found:!1};let e=j.readFileSync(t,`utf8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=N.cwd()){let t=this.getSearchPaths(e),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=Ee.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(`~`)?M.join(P.homedir(),e.slice(1)):e}};let q=null;function Pt(e){return(e||!q)&&(q=new Nt(e)),q}let J=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<=J.Unknown&&t.canHandle(e))return t.createCommand(e);for(let t of this.factories)if(t.priority===J.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 ie:new _e}};const Y=[`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 Y.includes(e)}function Rt(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function X(){return M.join(P.homedir(),Mt,jt)}function zt(){let e=X();if(!j.existsSync(e))return{};try{let t=j.readFileSync(e,`utf8`);return JSON.parse(t)}catch{return{}}}function Bt(e){let t=X(),n=M.dirname(t);j.existsSync(n)||j.mkdirSync(n,{recursive:!0}),j.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: ${Y.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: ${Y.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:X()})),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 N.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=N.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 xe}};function Jt(){return`2026.10314.10813`}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 Z=`tnmsc`,Xt=`
|
|
11
|
-
${Z} v${Jt()} - Memory Sync CLI
|
|
12
|
-
|
|
13
|
-
Synchronize AI memory and configuration files across projects.
|
|
14
|
-
|
|
15
|
-
USAGE:
|
|
16
|
-
${Z} Run the sync pipeline (default)
|
|
17
|
-
${Z} help Show this help message
|
|
18
|
-
${Z} version Show version information
|
|
19
|
-
${Z} init Deprecated; no longer initializes aindex
|
|
20
|
-
${Z} dry-run Preview what would be written
|
|
21
|
-
${Z} clean Remove all generated files
|
|
22
|
-
${Z} clean --dry-run Preview what would be cleaned
|
|
23
|
-
${Z} 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
|
-
${Z} --help, ${Z} -h Same as '${Z} help'
|
|
35
|
-
${Z} --version, ${Z} -v Same as '${Z} version'
|
|
36
|
-
${Z} clean -n Same as '${Z} clean --dry-run'
|
|
37
|
-
${Z} 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
|
-
${Z} config workspaceDir=~/my-project
|
|
64
|
-
${Z} config aindex.skills.src=skills
|
|
65
|
-
${Z} 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=J.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 Te}},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=J.Unknown;canHandle(e){return e.unknownCommand!=null}createCommand(e){return new nn(e.unknownCommand)}},an=class{priority=J.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,J.Subcommand),e.registerWithPriority(new Kt,J.Subcommand),e.registerWithPriority(new It,J.Subcommand),e.registerWithPriority(new tn,J.Subcommand),e.registerWithPriority(new Gt,J.Subcommand),e.registerWithPriority(new qt,J.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 ye(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 le(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&&te(t),this.logger=n(`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&&(te(`silent`),new Set([`config-show`,`plugins`]).has(i.name)||(i=new ge(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:j,path:M,glob:K.default,collectedOutputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:j,path:M,glob:K.default,collectedOutputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}async executePluginsInOrder(e,t,n=!1,r){if(e.length===0)return{};let i=En(e),a=new ke({userConfig:r}).collect(),o=new Oe;o.setGlobalScope(a),this.logger.debug(`global scope collected`,{osInfo:{platform:a.os.platform,arch:a.os.arch,shellKind:a.os.shellKind},hasProfile:Object.keys(a.profile).length>0,hasTool:Object.keys(a.tool).length>0});let s=new Map,c={};for(let e of i){let r=wn(e,s,Cn),i=this.resolveRuntimeCommand(),l={...t,dependencyContext:r,...i!=null&&{runtimeCommand:i},globalScope:a,scopeRegistry:o},u=e;u.executeEffects!=null&&await u.executeEffects(l,n);let d=await e.collect(l);s.set(e.name,d),c=Cn(c,d);let f=e;if(f.getRegisteredScopes!=null){let t=f.getRegisteredScopes();for(let{namespace:n,values:r}of t)o.register(n,r,ae.PluginRegistered),this.logger.debug(`plugin scope registered`,{plugin:e.name,namespace:n,keys:Object.keys(r)})}}return c}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,r,i,a,o;Ln(e)?({pluginOptions:i={},cwd:r,configLoaderOptions:a,pipelineArgs:o}={pluginOptions:e.pluginOptions,cwd:e.cwd,configLoaderOptions:e.configLoaderOptions,pipelineArgs:e.pipelineArgs},t=e.loadUserConfig??!0):(i=e,t=!0,a=void 0,o=void 0);let s={},c=!1,l=[],u;if(t)try{let e=Pt(a).load(r);c=e.found,l=e.sources,e.found&&(s=kn(e.config),u=e.config)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to load user config: ${t}`)}let d=An(s,i),{plugins:f=[],logLevel:p}=d,m=n(`defineConfig`,p);c?m.info(`user config loaded`,{sources:l}):m.info(`no user config found, using defaults/programmatic options`,{workspaceDir:d.workspaceDir,aindexDir:d.aindex.dir,logLevel:d.logLevel});let h={logger:m,userConfigOptions:d,fs:j,path:M,glob:K.default},g=f.filter(e=>e.type===ce.Input),_=f.filter(e=>e.type===ce.Output);he(_,d);let v=await(o==null?new Dn:new Dn(...o)).executePluginsInOrder(g,h,!1,u);if(v.workspace==null)throw Error(`Workspace not initialized by any plugin`);let y=ue({workspace:v.workspace,...v.vscodeConfigFiles!=null&&{vscodeConfigFiles:v.vscodeConfigFiles},...v.jetbrainsConfigFiles!=null&&{jetbrainsConfigFiles:v.jetbrainsConfigFiles},...v.editorConfigFiles!=null&&{editorConfigFiles:v.editorConfigFiles},...v.commands!=null&&{commands:v.commands},...v.subAgents!=null&&{subAgents:v.subAgents},...v.skills!=null&&{skills:v.skills},...v.rules!=null&&{rules:v.rules},...v.globalMemory!=null&&{globalMemory:v.globalMemory},...v.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:v.aiAgentIgnoreConfigFiles},...v.aindexDir!=null&&{aindexDir:v.aindexDir},...v.readmePrompts!=null&&{readmePrompts:v.readmePrompts},...v.globalGitIgnore!=null&&{globalGitIgnore:v.globalGitIgnore},...v.shadowGitExclude!=null&&{shadowGitExclude:v.shadowGitExclude}});return v.aindexDir!=null&&At(v.aindexDir,m),{context:y,outputPlugins:_,userConfigOptions:d}}var zn=class extends t{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 t{constructor(){super(`OrphanFileCleanupEffectInputPlugin`),this.registerEffect(`orphan-file-cleanup`,this.cleanupOrphanFiles.bind(this),20)}buildProtectedDeletionGuard(e){return ne({workspaceDir:e.workspaceDir,aindexDir:e.aindexDir,rules:[...ee(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,l=n.join(r,`dist`);if(!t.existsSync(l))return i.debug({action:`orphan-cleanup`,message:`dist/ directory does not exist, skipping`,distDir:l}),{success:!0,description:`dist/ directory does not exist, nothing to clean`,deletedFiles:[],deletedDirs:[]};let u=a.aindex,d={skills:u?.skills?.src??`skills`,commands:u?.commands?.src??`commands`,agents:u?.subAgents?.src??`subagents`,app:u?.app?.src??`app`},f=this.buildDeletionPlan(e,l,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=s(f.filesToDelete,p),h=s(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 c(`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===``?[...v.map(i=>e.join(t,r,n,`SKILL${i}`)),...v.map(i=>e.join(t,r,n,`skill${i}`))]:v.map(a=>e.join(t,r,n,o,`${i}${a}`))}case`commands`:case`agents`:case`app`:return a===`.`?v.map(n=>e.join(t,r,`${i}${n}`)):v.map(n=>e.join(t,r,a,`${i}${n}`));default:return[]}}collect(e){return{}}},Hn=class extends t{constructor(){super(`SkillNonSrcFileSyncEffectInputPlugin`),this.registerEffect(`skill-non-src-file-sync`,this.syncNonSrcFiles.bind(this),10)}async syncNonSrcFiles(e){let{fs:t,path:n,aindexDir:r,dryRun:i,logger:a}=e,o=n.join(r,`src`,`skills`),s=n.join(r,`dist`,`skills`),c=[],l=[],u=[],d=[];if(!t.existsSync(o))return a.debug({action:`skill-sync`,message:`src/skills/ directory does not exist, skipping`,srcSkillsDir:o}),{success:!0,description:`src/skills/ directory does not exist, nothing to sync`,copiedFiles:c,skippedFiles:l,createdDirs:u};this.syncDirectoryRecursive(e,o,s,``,c,l,u,d,i??!1);let f=d.length>0;return f&&a.warn({action:`skill-sync`,errors:d.map(e=>({path:e.path,error:e.error.message}))}),{success:!f,description:i?`Would copy ${c.length} files, skip ${l.length} files`:`Copied ${c.length} files, skipped ${l.length} files`,copiedFiles:c,skippedFiles:l,createdDirs:u,...f&&{error:Error(`${d.length} errors occurred during sync`)},modifiedFiles:c}}syncDirectoryRecursive(e,t,n,r,i,a,o,s,c){let{fs:l,path:u,logger:d}=e,f=r?u.join(t,r):t;if(!l.existsSync(f))return;let p;try{p=l.readdirSync(f,{withFileTypes:!0})}catch(e){s.push({path:f,error:e}),d.warn({action:`skill-sync`,message:`Failed to read directory`,path:f,error:e.message});return}for(let f of p){let p=r?u.join(r,f.name):f.name,m=u.join(t,p),h=u.join(n,p);if(f.isDirectory())this.syncDirectoryRecursive(e,t,n,p,i,a,o,s,c);else if(f.isFile()){if(Ae(f.name)||f.name.endsWith(`.mdx`))continue;let e=u.dirname(h);if(!l.existsSync(e))if(c)d.debug({action:`skill-sync`,dryRun:!0,wouldCreateDir:e}),o.push(e);else try{l.mkdirSync(e,{recursive:!0}),o.push(e),d.debug({action:`skill-sync`,createdDir:e})}catch(t){s.push({path:e,error:t}),d.warn({action:`skill-sync`,message:`Failed to create directory`,path:e,error:t.message});continue}if(l.existsSync(h))try{let e=l.readFileSync(m),t=l.readFileSync(h);if(this.computeHash(e)===this.computeHash(t)){a.push(h),d.debug({action:`skill-sync`,skipped:h,reason:`identical content`});continue}}catch(e){d.debug({action:`skill-sync`,message:`Could not compare files, will copy`,path:h,error:e.message})}if(c)d.debug({action:`skill-sync`,dryRun:!0,wouldCopy:{from:m,to:h}}),i.push(h);else try{l.copyFileSync(m,h),i.push(h),d.debug({action:`skill-sync`,copied:{from:m,to:h}})}catch(e){s.push({path:h,error:e}),d.warn({action:`skill-sync`,message:`Failed to copy file`,from:m,to:h,error:e.message})}}}}computeHash(e){return je(`sha256`).update(e).digest(`hex`)}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}const Zn={".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`},Qn=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 $n(e){return Qn.has(e.toLowerCase())}function er(e){return Zn[e.toLowerCase()]}function tr(...e){return M.join(...e).replaceAll(`\\`,`/`)}var Q=class{ctx;constructor(e){this.ctx=e}processDirectory(e,t,n){let r=t?`${t}/${e.name}`:e.name;return this.scanSkillDirectory(n,r)}processFile(e,t,n){let r=t?`${t}/${e.name}`:e.name;if(t===``&&e.name===`skill.mdx`||t===``&&e.name===`mcp.json`)return{childDocs:[],resources:[]};if(e.name.endsWith(`.mdx`)){let t=this.processChildDoc(e.name,r,n);return{childDocs:t?[t]:[],resources:[]}}let i=this.processResourceFile(e.name,r,n);return{childDocs:[],resources:i?[i]:[]}}processChildDoc(e,t,n){try{let e=E(this.ctx.fs.readFileSync(n,`utf8`)),r=w(e.contentWithoutFrontMatter);return{type:k.SkillChildDoc,content:r,length:r.length,filePathKind:C.Relative,markdownAst:e.markdownAst,markdownContents:e.markdownContents,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},relativePath:t,dir:{pathKind:C.Relative,path:t,basePath:this.ctx.skillDir,getDirectoryName:()=>M.dirname(t),getAbsolutePath:()=>n}}}catch(e){return this.ctx.logger.warn(`failed to read child doc`,{path:t,error:e}),null}}processResourceFile(e,t,n){let r=M.extname(e);try{let{content:i,encoding:a,length:o}=this.readFileContent(n,r),s=er(r);return{type:k.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($n(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:F.from(n,`utf8`).length}}scanSkillDirectory(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=tr(e,a.name);if(a.isDirectory()){let e=this.processDirectory(a,t,i);n.push(...e.childDocs),r.push(...e.resources);continue}if(!a.isFile())continue;let o=this.processFile(a,t,i);n.push(...o.childDocs),r.push(...o.resources)}return{childDocs:n,resources:r}}};function $(e,t,n){let r=M.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:k.SkillMcpConfig,mcpServers:a.mcpServers,rawContent:i}}catch(t){n.warn(`failed to parse mcp.json`,{skillDir:e,error:t});return}}}async function nr(e,t,n,r,a,o,s,c=[],l=[],u,d){let{logger:f,globalScope:p,fs:m}=o,h=M.join(a,`skill.mdx`),g=e,_,v;if(m.existsSync(h))try{g=m.readFileSync(h,`utf8`),_=E(g);let t=await i(g,{globalScope:p,extractMetadata:!0,basePath:a});e=w(t.content),v=t.metadata.fields}catch(e){f.warn(`failed to recompile skill from dist`,{skill:n,error:e})}let y=v??d??Xn(g),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:n,skillDir:r,yamlDescription:_?.yamlFrontMatter?.description,exportDescription:y?.description,hint:`Add a non-empty description field to the SKILL.md front matter or export default`}),Error(`Skill "${n}" validation failed: description is required and cannot be empty`);let ee={...y,..._?.yamlFrontMatter??{},name:n,description:b};return{type:k.Skill,content:e,length:e.length,filePathKind:C.Relative,yamlFrontMatter:ee,markdownAst:_?.markdownAst,markdownContents:_?.markdownContents??[],dir:{pathKind:C.Relative,path:n,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>M.join(r,n)},..._?.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}}}async function rr(e,t,n,r,a){let{logger:o,globalScope:s,fs:c}=a,l;try{l=c.readFileSync(e,`utf8`)}catch(t){return o.error(`failed to read skill file`,{file:e,error:t}),null}let u;try{u=E(l)}catch(t){return o.error(`failed to parse skill markdown`,{file:e,error:t}),null}let d;try{d=await i(l,{globalScope:s,extractMetadata:!0,basePath:r})}catch(t){return o.error(`failed to compile skill mdx`,{file:e,error:t}),null}let f={...u.yamlFrontMatter,...d.metadata.fields},p=f.description;if(p==null||p.trim().length===0)throw o.error(`SKILL_VALIDATION_FAILED: description is required and cannot be empty`,{skill:n,skillFilePath:e,yamlDescription:u.yamlFrontMatter?.description,exportDescription:d.metadata.fields.description,hint:`Add a non-empty description field to the SKILL.md front matter or export default`}),Error(`Skill "${n}" validation failed: description is required and cannot be empty`);let m=re(f,e);for(let e of m.warnings)o.debug(e);if(!m.valid)throw new h(m.errors,e);let g=w(d.content);o.debug(`skill metadata extracted`,{skill:n,source:d.metadata.source,hasYaml:u.yamlFrontMatter!=null,hasExport:Object.keys(d.metadata.fields).length>0});let{childDocs:_,resources:v}=new Q({fs:c,logger:o,skillDir:r}).scanSkillDirectory(r),y=$(r,c,o),{seriName:b}=f;return{type:k.Skill,content:g,length:g.length,filePathKind:C.Relative,yamlFrontMatter:f.name==null?{name:n,description:``}:f,...u.rawFrontMatter!=null&&{rawFrontMatter:u.rawFrontMatter},markdownAst:u.markdownAst,markdownContents:u.markdownContents,...y!=null&&{mcpConfig:y},..._.length>0&&{childDocs:_},...v.length>0&&{resources:v},...b!=null&&{seriName:b},dir:{pathKind:C.Relative,path:n,basePath:t,getDirectoryName:()=>n,getAbsolutePath:()=>M.join(t,n)}}}var ir=class extends t{constructor(){super(`SkillInputPlugin`)}readMcpConfig(e,t,n){return $(e,t,n)}scanSkillDirectory(e,t,n,r=``){return new Q({fs:t,logger:n,skillDir:e}).scanSkillDirectory(e,r)}async collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i,globalScope:a}=e,{aindexDir:o}=this.resolveBasePaths(t),s=this.resolveAindexPath(t.aindex.skills.src,o),c=this.resolveAindexPath(t.aindex.skills.dist,o),l=[],{prompts:u,errors:d}=await A(r,i,n,a).readDirectoryStructure(s,c,{kind:k.Skill,entryFileName:`skill`,localeExtensions:f,isDirectoryStructure:!0,createPrompt:async(t,a,o,s)=>{let l=i.join(c,o),u=[],d=[],f;if(r.existsSync(l)){let{childDocs:e,resources:t}=new Q({fs:r,logger:n,skillDir:l}).scanSkillDirectory(l);u=e,d=t,f=$(l,r,n)}return nr(t,a,o,c,l,e,f,u,d,void 0,s)}});for(let e of d)n.warn(`Failed to read skill`,{path:e.path,phase:e.phase,error:e.error});for(let e of u){let t=e.dist?.prompt??e.src.default.prompt;t&&l.push(t)}if(r.existsSync(c)){let t=r.readdirSync(c,{withFileTypes:!0}),a=new Set(u.map(e=>e.name));for(let o of t){if(!o.isDirectory()||a.has(o.name))continue;let t=o.name,s=i.join(c,t,`skill.mdx`),u=i.join(c,t);if(r.existsSync(s))try{let n=await rr(s,c,t,u,e);n&&l.push(n)}catch(e){n.error(`failed to parse skill`,{file:s,error:e})}}}return{skills:l}}},ar=class extends t{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=Me(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:C.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:C.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:C.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:l}}}},or=class extends t{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:k.Command,content:e,length:e.length,filePathKind:C.Relative,dir:{pathKind:C.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:n,path:r,fs:i,globalScope:a}=e,o=this.resolveBasePaths(t),s=this.resolveAindexPath(t.aindex.commands.src,o.aindexDir),c=this.resolveAindexPath(t.aindex.commands.dist,o.aindexDir);n.debug(`CommandInputPlugin collecting`,{srcDir:s,distDir:c,aindexDir:o.aindexDir});let{prompts:l,errors:u}=await A(i,r,n,a).readFlatFiles(s,c,{kind:k.Command,localeExtensions:f,isDirectoryStructure:!1,createPrompt:(t,n,r,i)=>this.createCommandPrompt(t,n,r,c,e,i)});n.debug(`CommandInputPlugin read complete`,{commandCount:l.length,errorCount:u.length});for(let e of u)n.warn(`Failed to read command`,{path:e.path,phase:e.phase,error:e.error});let d=[];for(let e of l){let t=e.dist;if(t?.prompt!=null){let{prompt:e,rawMdx:n}=t;d.push(n==null?e:{...e,rawMdxContent:n});continue}let n=e.src.default.prompt;if(n!=null){let{rawMdx:t}=e.src.default;d.push(t==null?n:{...n,rawMdxContent:t})}}return n.debug(`CommandInputPlugin flattened commands`,{count:d.length,commands:d.map(e=>e.commandName)}),{commands:d}}},sr=class extends t{constructor(){super(`EditorConfigInputPlugin`)}collect(t){let{userConfigOptions:n,fs:r}=t,{workspaceDir:i,aindexDir:a}=this.resolveBasePaths(n),o=[],s=S(e.EditorConfig,`.editorconfig`,a,r,{command:t.runtimeCommand,workspaceDir:i});return s!=null&&o.push(s),{editorConfigFiles:o}}},cr=class extends t{constructor(){super(`GitExcludeInputPlugin`)}collect(e){let{workspaceDir:t,aindexDir:n}=this.resolveBasePaths(e.userConfigOptions),r=x(n,be,{command:e.runtimeCommand,workspaceDir:t});if(!e.fs.existsSync(r))return this.log.debug({action:`collect`,message:`File not found`,path:r}),{};let i=e.fs.readFileSync(r,`utf8`);return i.length===0?(this.log.debug({action:`collect`,message:`File is empty`,path:r}),{}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:r,length:i.length}),{shadowGitExclude:i})}},lr=class extends t{constructor(){super(`GitIgnoreInputPlugin`)}collect(e){let{workspaceDir:t,aindexDir:n}=this.resolveBasePaths(e.userConfigOptions),r=x(n,u,{command:e.runtimeCommand,workspaceDir:t});if(!e.fs.existsSync(r))return this.log.debug({action:`collect`,message:`File not found`,path:r}),{};let i=e.fs.readFileSync(r,`utf8`);return i.length===0?(this.log.debug({action:`collect`,message:`File is empty`,path:r}),{}):(this.log.debug({action:`collect`,message:`Loaded file content`,path:r,length:i.length}),{globalGitIgnore:i})}},ur=class extends t{constructor(){super(`GlobalMemoryInputPlugin`)}async collect(e){let{userConfigOptions:t,fs:n,path:r,globalScope:a}=e,{aindexDir:o}=this.resolveBasePaths(t),s=this.resolveAindexPath(t.aindex.globalPrompt.dist,o);if(!n.existsSync(s))return this.log.warn({action:`collect`,reason:`fileNotFound`,path:s}),{};if(!n.statSync(s).isFile())return this.log.warn({action:`collect`,reason:`notAFile`,path:s}),{};let c=n.readFileSync(s,`utf8`),l=E(c),u;if(a!=null)try{u=await i(c,{globalScope:a,basePath:r.dirname(s)})}catch(e){throw e instanceof D&&(this.log.error(`MDX compilation failed: ${e.message}`),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.`),N.exit(1)),e}else u=l.contentWithoutFrontMatter;return this.log.debug({action:`collect`,path:s,contentLength:u.length}),{globalMemory:{type:k.GlobalMemory,content:u,length:u.length,filePathKind:C.Relative,...l.rawFrontMatter!=null&&{rawFrontMatter:l.rawFrontMatter},markdownAst:l.markdownAst,markdownContents:l.markdownContents,dir:{pathKind:C.Relative,path:r.basename(s),basePath:r.dirname(s),getDirectoryName:()=>r.basename(s),getAbsolutePath:()=>s},parentDirectoryPath:{type:_.UserHome,directory:{pathKind:C.Relative,path:``,basePath:P.homedir(),getDirectoryName:()=>r.basename(P.homedir()),getAbsolutePath:()=>P.homedir()}}}}}},dr=class extends t{constructor(){super(`JetBrainsConfigInputPlugin`)}collect(t){let{userConfigOptions:n,fs:r}=t,{workspaceDir:i,aindexDir:a}=this.resolveBasePaths(n),o=[`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`],s=[];for(let n of o){let o=S(e.IntellijIDEA,n,a,r,{command:t.runtimeCommand,workspaceDir:i});o!=null&&s.push(o)}return{jetbrainsConfigFiles:s}}};const fr=`agt.mdx`,pr=[`node_modules`,`.git`];var mr=class extends t{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,t,n){let{fs:r,path:a,logger:o}=e,s=a.join(t,fr);if(!(!r.existsSync(s)||!r.statSync(s).isFile()))try{let e=r.readFileSync(s,`utf8`),a=E(e),c;try{c=await i(e,{globalScope:n,basePath:t})}catch(e){throw e instanceof D&&(o.error(`MDX compilation failed in ${s}: ${e.message}`),o.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),N.exit(1)),e}return{type:k.ProjectRootMemory,content:c,length:c.length,filePathKind:C.Relative,...a.yamlFrontMatter!=null&&{yamlFrontMatter:a.yamlFrontMatter},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,dir:{pathKind:C.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()||pr.includes(l.name))continue;let c=s.join(n,l.name),u=s.join(c,fr);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,t,n,r,a){let{fs:o,path:s,logger:c}=e,l=s.join(n,fr);try{let e=o.readFileSync(l,`utf8`),u=E(e),d;try{d=await i(e,{globalScope:a,basePath:n})}catch(e){throw e instanceof D&&(c.error(`MDX compilation failed in ${l}: ${e.message}`),c.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),N.exit(1)),e}let f=s.relative(t,n),p=s.join(r,f),m=s.basename(n);return{type:k.ProjectChildrenMemory,content:d,length:d.length,filePathKind:C.Relative,...u.yamlFrontMatter!=null&&{yamlFrontMatter:u.yamlFrontMatter},...u.rawFrontMatter!=null&&{rawFrontMatter:u.rawFrontMatter},markdownAst:u.markdownAst,markdownContents:u.markdownContents,dir:{pathKind:C.Relative,path:f,basePath:r,getDirectoryName:()=>m,getAbsolutePath:()=>p},workingChildDirectoryPath:{pathKind:C.Relative,path:f,basePath:r,getDirectoryName:()=>m,getAbsolutePath:()=>p}}}catch(e){c.error(`Failed to read child memory prompt at ${l}`,{error:e});return}}};const hr=Object.entries(de);var gr=class extends t{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,t,n,r,a,o,s){let{fs:c,path:l,logger:u}=e,d=a===``;for(let[e,{src:f}]of hr){let p=l.join(t,f);if(!(!c.existsSync(p)||!c.statSync(p).isFile()))try{let f=c.readFileSync(p,`utf8`),m;if(s!=null)try{m=await i(f,{globalScope:s,basePath:t})}catch(e){throw e instanceof D&&(u.error(`MDX compilation failed in ${p}: ${e.message}`),u.error(`Please check your configuration file (~/.aindex/.tnmsc.json) and ensure all required variables are defined.`),N.exit(1)),e}else m=f;let h=d?n:l.join(n,a),g={pathKind:C.Relative,path:h,basePath:r,getDirectoryName:()=>d?n:l.basename(a),getAbsolutePath:()=>l.resolve(r,h)},_={pathKind:C.Relative,path:l.dirname(p),basePath:r,getDirectoryName:()=>l.basename(l.dirname(p)),getAbsolutePath:()=>l.dirname(p)};o.push({type:k.Readme,content:m,length:m.length,filePathKind:C.Relative,projectName:n,targetDir:g,isRoot:d,fileKind:e,markdownContents:[],dir:_})}catch(t){u.warn(`failed to read readme-family file`,{path:p,fileKind:e,error:t})}}try{let i=c.readdirSync(t,{withFileTypes:!0});for(let c of i)if(c.isDirectory()){let i=d?c.name:l.join(a,c.name),u=l.join(t,c.name);await this.collectReadmeFiles(e,u,n,r,i,o,s)}}catch(e){u.warn(`failed to scan directory`,{path:t,error:e})}}},_r=class extends t{constructor(){super(`RuleInputPlugin`)}async collect(e){let{userConfigOptions:t,logger:n,path:r,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 A(a,r,n,o).readFlatFiles(c,l,{kind:k.Rule,localeExtensions:f,isDirectoryStructure:!1,createPrompt:async(e,t,n,s)=>{let c=r.join(l,`${n}.mdx`),u=[],d=`project`,f,p;try{let{metadata:e}=await i(a.readFileSync(c,`utf8`),{globalScope:o,extractMetadata:!0,basePath:l});e?.fields!=null&&(p=e.fields,u=e.fields.globs??[],d=e.fields.scope??`project`,f=e.fields.seriName)}catch{}let m=n.replaceAll(`\\`,`/`),h=m.includes(`/`)?m.split(`/`)[0]??``:``,g=m.split(`/`).pop()??m,_={type:k.Rule,content:e,length:e.length,filePathKind:C.Relative,dir:{pathKind:C.Relative,path:`${n}.mdx`,basePath:l,getDirectoryName:()=>g,getAbsolutePath:()=>r.join(l,`${n}.mdx`)},prefix:h,ruleName:g,globs:u,scope:d,markdownContents:[]};return p!=null&&Object.assign(_,{yamlFrontMatter:p}),f!=null&&Object.assign(_,{seriName:f}),_}});for(let e of d)n.warn(`Failed to read rule from src`,{path:e.path,phase:e.phase,error:e.error});return{rules:u.map(e=>e.src.default.prompt).filter(Boolean)}}},vr=class extends t{constructor(){super(`AIAgentIgnoreInputPlugin`)}collect(e){let{workspaceDir:t,aindexDir:n}=this.resolveBasePaths(e.userConfigOptions),r=[];for(let i of d){let a=x(n,i,{command:e.runtimeCommand,workspaceDir:t});if(!e.fs.existsSync(a)){this.log.debug({action:`collect`,message:`Ignore file not found`,path:a});continue}let o=e.fs.readFileSync(a,`utf8`);if(o.length===0){this.log.debug({action:`collect`,message:`Ignore file is empty`,path:a});continue}r.push({fileName:i,content:o,sourcePath:a}),this.log.debug({action:`collect`,message:`Loaded ignore file`,path:a,fileName:i})}return r.length===0?{}:{aiAgentIgnoreConfigFiles:r}}},yr=class extends t{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:k.SubAgent,content:e,length:e.length,filePathKind:C.Relative,dir:{pathKind:C.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:n,path:r,fs:i,globalScope:a}=e,o=this.resolveBasePaths(t),s=this.resolveAindexPath(t.aindex.subAgents.src,o.aindexDir),c=this.resolveAindexPath(t.aindex.subAgents.dist,o.aindexDir);n.debug(`SubAgentInputPlugin collecting`,{srcDir:s,distDir:c,aindexDir:o.aindexDir});let{prompts:l,errors:u}=await A(i,r,n,a).readFlatFiles(s,c,{kind:k.SubAgent,localeExtensions:f,isDirectoryStructure:!1,createPrompt:(t,n,r,i)=>this.createSubAgentPrompt(t,n,r,c,e,i)});n.debug(`SubAgentInputPlugin read complete`,{subAgentCount:l.length,errorCount:u.length});for(let e of u)n.warn(`Failed to read subAgent`,{path:e.path,phase:e.phase,error:e.error});let d=[];for(let e of l){let t=e.dist;if(t?.prompt!=null){let{prompt:e,rawMdx:n}=t;d.push(n==null?e:{...e,rawMdxContent:n});continue}let n=e.src.default.prompt;if(n!=null){let{rawMdx:t}=e.src.default;d.push(t==null?n:{...n,rawMdxContent:t})}}return n.debug(`SubAgentInputPlugin flattened subAgents`,{count:d.length,agents:d.map(e=>e.agentName)}),{subAgents:d}}},br=class extends t{constructor(){super(`VSCodeConfigInputPlugin`)}collect(t){let{userConfigOptions:n,fs:r}=t,{workspaceDir:i,aindexDir:a}=this.resolveBasePaths(n),o=[`.vscode/settings.json`,`.vscode/extensions.json`],s=[];for(let n of o){let o=S(e.VSCode,n,a,r,{command:t.runtimeCommand,workspaceDir:i});o!=null&&s.push(o)}return{vscodeConfigFiles:s}}},xr=class extends t{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,aindexDir:r}=this.resolveBasePaths(t);return{workspace:{directory:{pathKind:C.Absolute,path:n,getDirectoryName:()=>M.basename(n)},projects:[]},aindexDir:r}}};const Sr=`GLOBAL.md`;var Cr=class extends T{constructor(){super(`TraeCNIDEOutputPlugin`,{globalConfigDir:`.trae-cn`,outputFileName:Sr,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(),Sr),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}},wr=Rn({pipelineArgs:N.argv,pluginOptions:{plugins:[new Le,new ze,new at,new et,new qe,new Ze,new Fe,new st,new mt,new bt,new Cr,new wt,new kt,new Ge,new Qe,new nt,new Ye,new St,new gt,new Hn,new Vn,new zn,new xr,new ar,new br,new dr,new sr,new ir,new or,new yr,new _r,new ur,new mr,new gr,new lr,new cr,new vr]}});export{wr as default};
|