@truenine/memory-sync-cli 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +4 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -191,7 +191,8 @@ CONFIGURATION:
|
|
|
191
191
|
See documentation for detailed configuration options.
|
|
192
192
|
`.trim();var su=class{name=`help`;async execute(e){return console.log(ou),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};const cu=`.tnmsc.json`,lu=`.aindex`;var uu=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??cu,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=$l(`ConfigLoader`)}getSearchPaths(e=n.cwd()){let t=[];for(let e of this.customSearchPaths)t.push(this.resolveTilde(e));return this.searchCwd&&t.push(i.join(e,this.configFileName)),this.searchGlobal&&t.push(i.join(o.homedir(),lu,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!r.existsSync(t))return{config:{},source:null,found:!1};let e=r.readFileSync(t,`utf-8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=n.cwd()){let t=this.getSearchPaths(e),r=[];for(let e of t){let t=this.loadFromFile(e);t.found&&r.push(t)}return{config:this.mergeConfigs(r.map(e=>e.config)),sources:r.map(e=>e.source).filter(e=>e!==null),found:r.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?i.join(o.homedir(),e.slice(1)):e}};let du=null;function fu(e){return(e||!du)&&(du=new uu(e)),du}function pu(e){return fu().load(e)}function mu(e,t,n){let r=e;return r=r.replace(I.SHADOW_SOURCE_PROJECT,n),r=r.replace(I.WORKSPACE,t),r.startsWith(`~`)&&(r=i.join(o.homedir(),r.slice(1))),i.normalize(r)}var hu=class{name=`init`;async execute(e){let{logger:t}=e;t.info(`initializing directory structure`,{command:`init`});let n=pu().config,a=mu(n.workspaceDir??vt,``,``),o=mu(n.shadowSourceProjectDir??`${I.WORKSPACE}/${yt}`,a,``),s=mu(n.shadowSkillSourceDir??bt,a,o),c=mu(n.shadowFastCommandDir??xt,a,o),l=mu(n.shadowSubAgentDir??St,a,o),u=mu(n.shadowProjectsDir??Ct,a,o),d=mu(n.globalMemoryFile??wt,a,o),f=[{path:a,name:`workspace`},{path:o,name:`shadow source project`},{path:s,name:`skills`},{path:c,name:`commands`},{path:l,name:`agents`},{path:u,name:`shadow projects`}],p=0,m=0,h=0,g=0;for(let e of f)r.existsSync(e.path)?(t.debug(`directory already exists`,{name:e.name,path:e.path}),m++):(r.mkdirSync(e.path,{recursive:!0}),t.info(`created directory`,{name:e.name,path:e.path}),p++);let _=i.dirname(d);r.existsSync(_)||(r.mkdirSync(_,{recursive:!0}),p++),r.existsSync(d)?(t.debug(`global memory file already exists`,{path:d}),g++):(r.writeFileSync(d,`# Global Memory
|
|
193
193
|
|
|
194
|
-
`,`utf-8`),t.info(`created global memory file`,{path:d}),h++),t.info(`Initialization complete`,{dirsCreated:p,dirsExisted:m,filesCreated:h,filesExisted:g});let v=p===0&&h===0?`All ${m} directories and ${g} files already exist`:`Created ${p} directories and ${h} files (${m} dirs, ${g} files already existed)`;return{success:!0,filesAffected:h,dirsAffected:p,message:v}}},gu=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};function _u(e){let t=[...e],n=t[0];n!=null&&vu(n)&&t.shift();let r=t[0];return r!=null&&yu(r)&&t.shift(),t}function vu(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replace(/\\/g,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function yu(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}const bu=new Set([`help`,`init`,`dry-run`,`clean`]),xu=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),Su=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function Cu(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=Su.get(n)??4;for(let e of t){let t=Su.get(e)??4;t<r&&(r=t,n=e)}return n}function wu(e){let{helpFlag:t,subcommand:n,dryRun:r,unknownCommand:i}=e;return t?new su:i==null?n===`help`?new su:n===`init`?new hu:n===`dry-run`?new iu:n===`clean`?r?new ru:new lt:new au:new gu(i)}function Tu(e){let t={subcommand:void 0,helpFlag:!1,dryRun:!1,logLevel:void 0,logLevelFlags:[],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 e=i.split(`=`)[0]??``,n=xu.get(e);if(n!=null){t.logLevelFlags.push(n),t.logLevel=n;continue}switch(e){case`--help`:t.helpFlag=!0;break;case`--dry-run`:t.dryRun=!0;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`n`:t.dryRun=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,bu.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var Eu=class{logger;args;outputPlugins=[];constructor(...e){this.args=Tu(_u(e.filter(e=>e!=null)));let t=Cu(this.args);t!=null&&Wl(t),this.logger=$l(`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}=e;this.registerOutputPlugins([...n]);let r=this.resolveCommand(),i=this.createCommandContext(t);await r.execute(i)}resolveCommand(){return wu(this.args)}createCommandContext(e){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new _t(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length!==e.length)throw new gt(this.findCyclePath(e,n));return a}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a[a.length-1]);return a.slice(e)}i.clear(),a.length=0}return Array.from(n)}executePluginsInOrder(e,t){if(e.length===0)return{};let n=this.topologicalSort(e),r=new Map,i={};for(let e of n){let n=this.buildDependencyContext(e,r),a={...t,dependencyContext:n},o=e.collect(a);r.set(e.name,o),i=this.mergeContexts(i,o)}return i}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let n=e.workspace;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:Array.from(e.values())}}else n=t.workspace;let r=t.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts];return{...n==null?{}:{workspace:n},...r==null?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d}}}};const Du={workspaceDir:vt,shadowSourceProjectDir:`$WORKSPACE/${yt}`,shadowSkillSourceDir:bt,shadowFastCommandDir:xt,shadowSubAgentDir:St,globalMemoryFile:wt,shadowProjectsDir:Ct,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[],logLevel:`info`};function Ou(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function ku(...e){return e.reduce((e,t)=>Au(e,t),{...Du})}function Au(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:ju(e.excludePatterns,i),fastCommandSeriesOptions:Mu(e.fastCommandSeriesOptions,a)}}function ju(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function Mu(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 Nu(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function Pu(e={}){let t,n,a;Nu(e)?(t=e.pluginOptions??{},n=e.loadUserConfig??!0,a=e.cwd):(t=e,n=!0);let o={};if(n){let e=pu(a);e.found&&(o=Ou(e.config),$l(`defineConfig`,t.logLevel??e.config.logLevel).debug(`loaded`,{sources:e.sources}))}let s=ku(o,t),{plugins:c=[],logLevel:l}=s,u={logger:$l(`defineConfig`,l),userConfigOptions:s,fs:r,path:i,glob:$e.default},d=c.filter(e=>e.type===ut.Input),f=c.filter(e=>e.type===ut.Output),p=new Eu().executePluginsInOrder(d,u);if(p.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:p.workspace,ideConfigFiles:p.ideConfigFiles??[],...p.externalProjects!=null&&{externalProjects:p.externalProjects},...p.fastCommands!=null&&{fastCommands:p.fastCommands},...p.subAgents!=null&&{subAgents:p.subAgents},...p.skills!=null&&{skills:p.skills},...p.globalMemory!=null&&{globalMemory:p.globalMemory},...p.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:p.aiAgentIgnoreConfigFiles},...p.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:p.shadowSourceProjectDir},...p.readmePrompts!=null&&{readmePrompts:p.readmePrompts}},outputPlugins:f}}const Fu=`AGENTS.md`;var Iu=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Fu})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Fu)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Fu));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}};const Lu=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Ru=class extends X{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Lu){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf-8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const zu=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Bu=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.isPromptSourceProject!==!0)for(let n of zu){let r=i.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>i.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,a){let o=i.join(t.path,n.fileName),s=i.join(t.basePath,o),c={pathKind:P.Relative,path:o,basePath:t.basePath,getDirectoryName:()=>i.basename(t.path),getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0,skipped:!1};try{return r.writeFileSync(s,n.content,`utf-8`),this.log.trace({action:`write`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:s,label:a,error:t}),{path:c,success:!1,error:e}}}};const Vu=`CLAUDE.md`,Hu=`.claude`,Uu=`commands`,Wu=`agents`,Gu=`skills`,Ku=[Uu,Wu,Gu];var qu=class extends Z{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:Hu,outputFileName:Vu})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Ku){let r=i.join(e.dirFromWorkspacePath.path,Hu,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Vu)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Vu));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Vu,basePath:n,getDirectoryName:()=>Hu,getAbsolutePath:()=>i.join(n,Vu)}]}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=(r?.length??0)>0,l=(i?.length??0)>0,u=(a?.length??0)>0;return!o&&!s&&!c&&!l&&!u?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.name??`unknown`,s=o.dirFromWorkspacePath;if(s!=null){if(o.rootMemoryPrompt!=null){let n=await this.writePromptFile(e,s,o.rootMemoryPrompt.content,`project:${t}/root`);a.push(n)}if(o.childMemoryPrompts!=null)for(let n of o.childMemoryPrompts){let r=await this.writePromptFile(e,n.dir,n.content,`project:${t}/child:${n.workingChildDirectoryPath?.path??`unknown`}`);a.push(r)}if(n!=null)for(let t of n){let n=await this.writeFastCommand(e,s,t);a.push(...n)}if(r!=null)for(let t of r){let n=await this.writeSubAgent(e,s,t);a.push(...n)}if(i!=null)for(let t of i){let n=await this.writeSkill(e,s,t);a.push(...n)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Vu),c={pathKind:P.Relative,path:Vu,basePath:o,getDirectoryName:()=>Hu,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,Hu,Uu),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,Hu,Uu,s),basePath:t.basePath,getDirectoryName:()=>Uu,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Hu,Wu),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,Hu,Wu,o),basePath:t.basePath,getDirectoryName:()=>Wu,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,Hu,Gu,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,Hu,Gu,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,Hu,Gu,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Ju=`AGENTS.md`,Yu=`.factory`,Xu=`commands`,Zu=`agents`,Qu=`skills`,$u=[Xu,Zu,Qu];var ed=class extends Z{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:Yu,outputFileName:Ju})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of $u){let r=i.join(e.dirFromWorkspacePath.path,Yu,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Ju,basePath:n,getDirectoryName:()=>Yu,getAbsolutePath:()=>i.join(n,Ju)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=t!=null,o=(n?.length??0)>0,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.dirFromWorkspacePath;if(t!=null){if(n!=null)for(let r of n){let n=await this.writeFastCommand(e,t,r);a.push(...n)}if(r!=null)for(let n of r){let r=await this.writeSubAgent(e,t,n);a.push(...r)}if(i!=null)for(let n of i){let r=await this.writeSkill(e,t,n);a.push(...r)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Ju),c={pathKind:P.Relative,path:Ju,basePath:o,getDirectoryName:()=>Yu,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,Yu,Xu),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,Yu,Xu,s),basePath:t.basePath,getDirectoryName:()=>Xu,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Yu,Zu),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,Yu,Zu,o),basePath:t.basePath,getDirectoryName:()=>Zu,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,Yu,Qu,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,Yu,Qu,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,Yu,Qu,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}},td=class extends X{constructor(){super(`FastCommandInputPlugin`)}extractSeriesInfo(e){let t=e.replace(/\.md$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.substring(0,n),commandName:t.substring(n+1)}}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??xt,o=this.resolvePath(a,r,i),s=[];if(e.fs.existsSync(o)&&e.fs.statSync(o).isDirectory())try{let t=e.fs.readdirSync(o,{withFileTypes:!0});for(let n of t)if(n.isFile()&&n.name.endsWith(`.md`)){let t=e.path.join(o,n.name),r=Hl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter,a=this.extractSeriesInfo(n.name);s.push({type:dt.FastCommand,content:i,length:i.length,filePathKind:P.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:P.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t},...a.series!=null&&{series:a.series},commandName:a.commandName})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}};const nd=`GEMINI.md`,rd=`.gemini`;var id=class extends Z{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:rd,outputFileName:nd})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,nd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,nd));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:nd,basePath:n,getDirectoryName:()=>rd,getAbsolutePath:()=>i.join(n,nd)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)&&n==null?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,nd),c={pathKind:P.Relative,path:nd,basePath:o,getDirectoryName:()=>rd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}},ad=class extends X{constructor(){super(`GlobalMemoryInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??wt,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Hl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:dt.GlobalMemory,content:t,length:t.length,filePathKind:P.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:ht.UserHome,directory:{pathKind:P.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},od=class extends X{constructor(){super(`IdeConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{shadowProjectDir:i}=this.resolveBasePaths(t),a=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`,`.vscode/settings.json`,`.vscode/extensions.json`],o=[];for(let e of a){let t=r.join(i,e);if(n.existsSync(t)&&n.statSync(t).isFile()){let i=n.readFileSync(t,`utf-8`),a=F.Original;e.includes(`.vscode`)?a=F.VSCode:e.includes(`.idea`)?a=F.IntellijIDEA:e.includes(`.editorconfig`)&&(a=F.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:P.Absolute,dir:{pathKind:P.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const sd=`.idea`,cd=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`];var ld=class extends Z{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of cd){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig)?!0:(this.log.debug(`skipped`,{reason:`no JetBrains IDE config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.EditorConfig)return`.editorconfig`;if(e.type===F.IntellijIDEA){let e=t.indexOf(sd);return e===-1?this.joinPath(sd,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const ud=`GLOBAL.md`,dd=`.kiro`,$=`steering`,fd=`POWER.md`;var pd=class extends Z{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:dd,outputFileName:ud})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.path,dd,$);t.push({pathKind:P.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts){let r=this.buildSteeringFileName(n),i=this.joinPath(e.dirFromWorkspacePath.path,dd,$,r);t.push({pathKind:P.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir(),n=[{pathKind:P.Relative,path:$,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>$,getAbsolutePath:()=>t}],{skills:r}=e.collectedInputContext;if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let r=t.yamlFrontMatter.name,i=this.joinPath(e,r);n.push({pathKind:P.Relative,path:r,basePath:e,getDirectoryName:()=>r,getAbsolutePath:()=>i})}}return n}async registerGlobalOutputFiles(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalSteeringDir();if(t!=null&&i.push({pathKind:P.Relative,path:ud,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,ud)}),n!=null)for(let e of n){let t=this.buildFastCommandSteeringFileName(e);i.push({pathKind:P.Relative,path:t,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,t)})}if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let n=t.yamlFrontMatter.name,r=this.joinPath(e,n);if(i.push({pathKind:P.Relative,path:fd,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(r,fd)}),t.referenceDocuments!=null){let e=this.joinPath(r,$);for(let n of t.referenceDocuments){let t=n.dir.path;i.push({pathKind:P.Relative,path:this.joinPath($,t),basePath:r,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e,t)})}}}}return i}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,skills:i}=e.collectedInputContext,a=t.projects.some(e=>(e.childMemoryPrompts?.length??0)>0),o=n!=null,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t)if(r.dirFromWorkspacePath!=null&&r.childMemoryPrompts!=null)for(let t of r.childMemoryPrompts){let i=await this.writeSteeringFile(e,r,t);n.push(i)}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=[],o=[];if(t!=null){let n=this.getGlobalSteeringDir(),r=this.joinPath(n,ud),a={pathKind:P.Relative,path:ud,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),this.writeFileSync(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),i.push({path:a,success:!1,error:e})}}if(n!=null)for(let t of n){let n=await this.writeFastCommandSteeringFile(e,t);i.push(n)}if(r!=null&&r.length>0){this.log.debug(`Processing ${r.length} skills as Kiro Powers`);for(let t of r){let{fileResults:n,registryResult:r}=await this.writeSkillAsPower(e,t);i.push(...n),o.push(r)}this.logRegistryResults(o,e.dryRun)}return{files:i,dirs:a}}logRegistryResults(e,t){let n=e.filter(e=>e.success).length,r=e.filter(e=>!e.success).length;if(n>0&&this.log.trace({action:t===!0?`dryRun`:`register`,type:`registrySummary`,successCount:n}),r>0){this.log.error({action:`register`,type:`registrySummary`,failCount:r});for(let t of e)if(!t.success){let e=t.error?.message??`Unknown error`;this.log.error({action:`register`,type:`registryEntry`,entryName:t.entryName,error:e})}}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),$)}getKiroPowersDir(){return this.joinPath(this.getHomeDir(),`.kiro/powers/installed`)}getHomeDir(){return s.homedir()}buildPowerFrontMatter(e){let t=e.name,n=e.description,r=e.displayName,i=e.keywords,a=e.author,o=[`---`];if(o.push(`name: "${t}"`),r!=null&&r.length>0&&o.push(`displayName: "${r}"`),n.length>0&&o.push(`description: "${n}"`),i!=null&&i.length>0){let e=i.map(e=>`"${e}"`).join(`, `);o.push(`keywords: [${e}]`)}return a!=null&&a.length>0&&o.push(`author: "${a}"`),o.push(`---`),o.join(`
|
|
195
|
-
`)}async writeSkillAsPower(e,t){let n=[],r=t.yamlFrontMatter.name,i=this.joinPath(this.getKiroPowersDir(),r),a=this.joinPath(i,fd),o={pathKind:P.Relative,path:fd,basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=`${this.buildPowerFrontMatter(t.yamlFrontMatter)}\n${t.content}`;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skillPower`,path:a}),n.push({path:o,success:!0,skipped:!1});else try{this.ensureDirectory(i),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`skillPower`,path:a}),n.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillPower`,path:a,error:t}),n.push({path:o,success:!1,error:e})}if(t.referenceDocuments!=null){let r=this.joinPath(i,$);for(let a of t.referenceDocuments){let t=a.dir.path,o=this.joinPath(r,t),s={pathKind:P.Relative,path:this.joinPath($,t),basePath:i,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=a.content;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`refDoc`,path:o}),n.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(r),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`refDoc`,path:o}),n.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`refDoc`,path:o,error:t}),n.push({path:s,success:!1,error:e})}}}let c=this.getRegistryWriter(nu),l=c.buildPowerEntry(t,i);return{fileResults:n,registryResult:(await this.registerInRegistry(c,[l],e))[0]??{success:!1,entryName:r,error:Error(`No registry result returned`)}}}buildFastCommandSteeringFileName(e){return this.transformFastCommandName(e,{includeSeriesPrefix:!0,seriesSeparator:`-`})}buildFastCommandSteeringContent(e){let t=e.yamlFrontMatter?.description??``,n=[`---`,`inclusion: manual`];return t.length>0&&n.push(`description: '${t}'`),n.push(`---`),`${n.join(`
|
|
194
|
+
`,`utf-8`),t.info(`created global memory file`,{path:d}),h++),t.info(`Initialization complete`,{dirsCreated:p,dirsExisted:m,filesCreated:h,filesExisted:g});let v=p===0&&h===0?`All ${m} directories and ${g} files already exist`:`Created ${p} directories and ${h} files (${m} dirs, ${g} files already existed)`;return{success:!0,filesAffected:h,dirsAffected:p,message:v}}},gu=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};function _u(e){let t=[...e],n=t[0];n!=null&&vu(n)&&t.shift();let r=t[0];return r!=null&&yu(r)&&t.shift(),t}function vu(e){let t=[`node`,`nodejs`,`bun`,`deno`,`tsx`,`ts-node`,`npx`,`pnpx`,`yarn`,`pnpm`],n=e.toLowerCase().replace(/\\/g,`/`);return t.some(e=>RegExp(`(?:^|/)${e}(?:\\.exe|\\.cmd|\\.ps1)?$`,`i`).test(n)||n===e)}function yu(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}const bu=new Set([`help`,`init`,`dry-run`,`clean`]),xu=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),Su=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function Cu(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=Su.get(n)??4;for(let e of t){let t=Su.get(e)??4;t<r&&(r=t,n=e)}return n}function wu(e){let{helpFlag:t,subcommand:n,dryRun:r,unknownCommand:i}=e;return t?new su:i==null?n===`help`?new su:n===`init`?new hu:n===`dry-run`?new iu:n===`clean`?r?new ru:new lt:new au:new gu(i)}function Tu(e){let t={subcommand:void 0,helpFlag:!1,dryRun:!1,logLevel:void 0,logLevelFlags:[],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 e=i.split(`=`)[0]??``,n=xu.get(e);if(n!=null){t.logLevelFlags.push(n),t.logLevel=n;continue}switch(e){case`--help`:t.helpFlag=!0;break;case`--dry-run`:t.dryRun=!0;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`n`:t.dryRun=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,bu.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var Eu=class{logger;args;outputPlugins=[];constructor(...e){this.args=Tu(_u(e.filter(e=>e!=null)));let t=Cu(this.args);t!=null&&Wl(t),this.logger=$l(`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}=e;this.registerOutputPlugins([...n]);let r=this.resolveCommand(),i=this.createCommandContext(t);await r.execute(i)}resolveCommand(){return wu(this.args)}createCommandContext(e){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new _t(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length!==e.length)throw new gt(this.findCyclePath(e,n));return a}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a[a.length-1]);return a.slice(e)}i.clear(),a.length=0}return Array.from(n)}executePluginsInOrder(e,t){if(e.length===0)return{};let n=this.topologicalSort(e),r=new Map,i={};for(let e of n){let n=this.buildDependencyContext(e,r),a={...t,dependencyContext:n},o=e.collect(a);r.set(e.name,o),i=this.mergeContexts(i,o)}return i}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let n=e.workspace;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:Array.from(e.values())}}else n=t.workspace;let r=t.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts];return{...n==null?{}:{workspace:n},...r==null?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d}}}};const Du={workspaceDir:vt,shadowSourceProjectDir:`$WORKSPACE/${yt}`,shadowSkillSourceDir:bt,shadowFastCommandDir:xt,shadowSubAgentDir:St,globalMemoryFile:wt,shadowProjectsDir:Ct,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[],logLevel:`info`};function Ou(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function ku(...e){return e.reduce((e,t)=>Au(e,t),{...Du})}function Au(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:ju(e.excludePatterns,i),fastCommandSeriesOptions:Mu(e.fastCommandSeriesOptions,a)}}function ju(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function Mu(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 Nu(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function Pu(e={}){let t,n,a;Nu(e)?(t=e.pluginOptions??{},n=e.loadUserConfig??!0,a=e.cwd):(t=e,n=!0);let o={};if(n){let e=pu(a);e.found&&(o=Ou(e.config),$l(`defineConfig`,t.logLevel??e.config.logLevel).debug(`loaded`,{sources:e.sources}))}let s=ku(o,t),{plugins:c=[],logLevel:l}=s,u={logger:$l(`defineConfig`,l),userConfigOptions:s,fs:r,path:i,glob:$e.default},d=c.filter(e=>e.type===ut.Input),f=c.filter(e=>e.type===ut.Output),p=new Eu().executePluginsInOrder(d,u);if(p.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:p.workspace,ideConfigFiles:p.ideConfigFiles??[],...p.externalProjects!=null&&{externalProjects:p.externalProjects},...p.fastCommands!=null&&{fastCommands:p.fastCommands},...p.subAgents!=null&&{subAgents:p.subAgents},...p.skills!=null&&{skills:p.skills},...p.globalMemory!=null&&{globalMemory:p.globalMemory},...p.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:p.aiAgentIgnoreConfigFiles},...p.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:p.shadowSourceProjectDir},...p.readmePrompts!=null&&{readmePrompts:p.readmePrompts}},outputPlugins:f}}const Fu=`AGENTS.md`;var Iu=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Fu})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Fu)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Fu));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}};const Lu=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Ru=class extends X{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of Lu){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf-8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const zu=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Bu=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.isPromptSourceProject!==!0)for(let n of zu){let r=i.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>i.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,a){let o=i.join(t.path,n.fileName),s=i.join(t.basePath,o),c={pathKind:P.Relative,path:o,basePath:t.basePath,getDirectoryName:()=>i.basename(t.path),getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0,skipped:!1};try{return r.writeFileSync(s,n.content,`utf-8`),this.log.trace({action:`write`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:s,label:a,error:t}),{path:c,success:!1,error:e}}}};const Vu=`CLAUDE.md`,Hu=`.claude`,Uu=`commands`,Wu=`agents`,Gu=`skills`,Ku=[Uu,Wu,Gu];var qu=class extends Z{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:Hu,outputFileName:Vu})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Ku){let r=i.join(e.dirFromWorkspacePath.path,Hu,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Vu)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Vu));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Vu,basePath:n,getDirectoryName:()=>Hu,getAbsolutePath:()=>i.join(n,Vu)}]}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=(r?.length??0)>0,l=(i?.length??0)>0,u=(a?.length??0)>0;return!o&&!s&&!c&&!l&&!u?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.name??`unknown`,s=o.dirFromWorkspacePath;if(s!=null){if(o.rootMemoryPrompt!=null){let n=await this.writePromptFile(e,s,o.rootMemoryPrompt.content,`project:${t}/root`);a.push(n)}if(o.childMemoryPrompts!=null)for(let n of o.childMemoryPrompts){let r=await this.writePromptFile(e,n.dir,n.content,`project:${t}/child:${n.workingChildDirectoryPath?.path??`unknown`}`);a.push(r)}if(n!=null)for(let t of n){let n=await this.writeFastCommand(e,s,t);a.push(...n)}if(r!=null)for(let t of r){let n=await this.writeSubAgent(e,s,t);a.push(...n)}if(i!=null)for(let t of i){let n=await this.writeSkill(e,s,t);a.push(...n)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Vu),c={pathKind:P.Relative,path:Vu,basePath:o,getDirectoryName:()=>Hu,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,Hu,Uu),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,Hu,Uu,s),basePath:t.basePath,getDirectoryName:()=>Uu,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Hu,Wu),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,Hu,Wu,o),basePath:t.basePath,getDirectoryName:()=>Wu,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,Hu,Gu,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,Hu,Gu,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,Hu,Gu,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Ju=`AGENTS.md`,Yu=`.codex`,Xu=`prompts`,Zu=`skills`,Qu=`SKILL.md`;var $u=class extends Z{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:Yu,outputFileName:Ju,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(e){return[]}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=i.join(t,Xu);n.push({pathKind:P.Relative,path:Xu,basePath:t,getDirectoryName:()=>Xu,getAbsolutePath:()=>r});let{skills:a}=e.collectedInputContext;if(a!=null&&a.length>0)for(let e of a){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),a=i.join(t,Zu,r);n.push({pathKind:P.Relative,path:i.join(Zu,r),basePath:t,getDirectoryName:()=>r,getAbsolutePath:()=>a})}return n}async registerGlobalOutputFiles(e){let t=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Ju,basePath:t,getDirectoryName:()=>Yu,getAbsolutePath:()=>i.join(t,Ju)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=t!=null,a=(n?.length??0)>0,o=(r?.length??0)>0;return!i&&!a&&!o?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:a}=e.collectedInputContext,o=[],s=[];if(t!=null){let n=this.getGlobalConfigDir(),a=i.join(n,Ju),s={pathKind:P.Relative,path:Ju,basePath:n,getDirectoryName:()=>Yu,getAbsolutePath:()=>a};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:a}),o.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(n),r.writeFileSync(a,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:a}),o.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:a,error:t}),o.push({path:s,success:!1,error:e})}}if(n!=null&&n.length>0){let t=this.getGlobalConfigDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);o.push(...n)}}if(a!=null&&a.length>0){let t=this.getGlobalConfigDir();for(let n of a){let r=await this.writeGlobalSkill(e,t,n);o.push(...r)}}return{files:o,dirs:s}}async writeGlobalFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t,Xu),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(Xu,s),basePath:t,getDirectoryName:()=>Xu,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`globalFastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalFastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeGlobalSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t,Zu,o),c=i.join(s,Qu),l={pathKind:P.Relative,path:i.join(Zu,o,Qu),basePath:t,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildCodexSkillContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalSkill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`globalSkill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalSkill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeToSingleLine(t.description,500),r=this.normalizeToSingleLine(t.name,100),i=[`---`];return i.push(`name: ${this.yamlQuoteIfNeeded(r)}`),i.push(`description: ${this.yamlQuoteIfNeeded(n)}`),t.displayName!=null&&(i.push(`metadata:`),i.push(` short-description: ${this.yamlQuoteIfNeeded(t.displayName)}`)),i.push(`---`),`${i.join(`
|
|
195
|
+
`)}\n${e.content}`}normalizeToSingleLine(e,t){let n=e.replace(/[\r\n]+/g,` `).replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}yamlQuoteIfNeeded(e){return/[:[\]{}#&*!|>'"%@`]/.test(e)||/^[\s-]/.test(e)?`"${e.replace(/"/g,`\\"`)}"`:e}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(Zu,n,c),basePath:o,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const ed=`AGENTS.md`,td=`.factory`,nd=`commands`,rd=`agents`,id=`skills`,ad=[nd,rd,id];var od=class extends Z{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:td,outputFileName:ed})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of ad){let r=i.join(e.dirFromWorkspacePath.path,td,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:ed,basePath:n,getDirectoryName:()=>td,getAbsolutePath:()=>i.join(n,ed)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=t!=null,o=(n?.length??0)>0,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.dirFromWorkspacePath;if(t!=null){if(n!=null)for(let r of n){let n=await this.writeFastCommand(e,t,r);a.push(...n)}if(r!=null)for(let n of r){let r=await this.writeSubAgent(e,t,n);a.push(...r)}if(i!=null)for(let n of i){let r=await this.writeSkill(e,t,n);a.push(...r)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,ed),c={pathKind:P.Relative,path:ed,basePath:o,getDirectoryName:()=>td,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,td,nd),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,td,nd,s),basePath:t.basePath,getDirectoryName:()=>nd,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,td,rd),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,td,rd,o),basePath:t.basePath,getDirectoryName:()=>rd,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,td,id,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,td,id,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,td,id,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}},sd=class extends X{constructor(){super(`FastCommandInputPlugin`)}extractSeriesInfo(e){let t=e.replace(/\.md$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.substring(0,n),commandName:t.substring(n+1)}}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??xt,o=this.resolvePath(a,r,i),s=[];if(e.fs.existsSync(o)&&e.fs.statSync(o).isDirectory())try{let t=e.fs.readdirSync(o,{withFileTypes:!0});for(let n of t)if(n.isFile()&&n.name.endsWith(`.md`)){let t=e.path.join(o,n.name),r=Hl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter,a=this.extractSeriesInfo(n.name);s.push({type:dt.FastCommand,content:i,length:i.length,filePathKind:P.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:P.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t},...a.series!=null&&{series:a.series},commandName:a.commandName})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}};const cd=`GEMINI.md`,ld=`.gemini`;var ud=class extends Z{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:ld,outputFileName:cd})}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,cd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,cd));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:cd,basePath:n,getDirectoryName:()=>ld,getAbsolutePath:()=>i.join(n,cd)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)&&n==null?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,cd),c={pathKind:P.Relative,path:cd,basePath:o,getDirectoryName:()=>ld,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}},dd=class extends X{constructor(){super(`GlobalMemoryInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??wt,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Hl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:dt.GlobalMemory,content:t,length:t.length,filePathKind:P.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:ht.UserHome,directory:{pathKind:P.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},fd=class extends X{constructor(){super(`IdeConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{shadowProjectDir:i}=this.resolveBasePaths(t),a=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`,`.vscode/settings.json`,`.vscode/extensions.json`],o=[];for(let e of a){let t=r.join(i,e);if(n.existsSync(t)&&n.statSync(t).isFile()){let i=n.readFileSync(t,`utf-8`),a=F.Original;e.includes(`.vscode`)?a=F.VSCode:e.includes(`.idea`)?a=F.IntellijIDEA:e.includes(`.editorconfig`)&&(a=F.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:P.Absolute,dir:{pathKind:P.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const pd=`.idea`,md=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`];var hd=class extends Z{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of md){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig)?!0:(this.log.debug(`skipped`,{reason:`no JetBrains IDE config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.EditorConfig)return`.editorconfig`;if(e.type===F.IntellijIDEA){let e=t.indexOf(pd);return e===-1?this.joinPath(pd,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const gd=`GLOBAL.md`,_d=`.kiro`,$=`steering`,vd=`POWER.md`;var yd=class extends Z{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:_d,outputFileName:gd})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n){if(e.dirFromWorkspacePath==null)continue;let n=this.joinPath(e.dirFromWorkspacePath.path,_d,$);t.push({pathKind:P.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts){let r=this.buildSteeringFileName(n),i=this.joinPath(e.dirFromWorkspacePath.path,_d,$,r);t.push({pathKind:P.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir(),n=[{pathKind:P.Relative,path:$,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>$,getAbsolutePath:()=>t}],{skills:r}=e.collectedInputContext;if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let r=t.yamlFrontMatter.name,i=this.joinPath(e,r);n.push({pathKind:P.Relative,path:r,basePath:e,getDirectoryName:()=>r,getAbsolutePath:()=>i})}}return n}async registerGlobalOutputFiles(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalSteeringDir();if(t!=null&&i.push({pathKind:P.Relative,path:gd,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,gd)}),n!=null)for(let e of n){let t=this.buildFastCommandSteeringFileName(e);i.push({pathKind:P.Relative,path:t,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,t)})}if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let n=t.yamlFrontMatter.name,r=this.joinPath(e,n);if(i.push({pathKind:P.Relative,path:vd,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(r,vd)}),t.referenceDocuments!=null){let e=this.joinPath(r,$);for(let n of t.referenceDocuments){let t=n.dir.path;i.push({pathKind:P.Relative,path:this.joinPath($,t),basePath:r,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e,t)})}}}}return i}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,skills:i}=e.collectedInputContext,a=t.projects.some(e=>(e.childMemoryPrompts?.length??0)>0),o=n!=null,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t)if(r.dirFromWorkspacePath!=null&&r.childMemoryPrompts!=null)for(let t of r.childMemoryPrompts){let i=await this.writeSteeringFile(e,r,t);n.push(i)}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=[],o=[];if(t!=null){let n=this.getGlobalSteeringDir(),r=this.joinPath(n,gd),a={pathKind:P.Relative,path:gd,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),this.writeFileSync(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),i.push({path:a,success:!1,error:e})}}if(n!=null)for(let t of n){let n=await this.writeFastCommandSteeringFile(e,t);i.push(n)}if(r!=null&&r.length>0){this.log.debug(`Processing ${r.length} skills as Kiro Powers`);for(let t of r){let{fileResults:n,registryResult:r}=await this.writeSkillAsPower(e,t);i.push(...n),o.push(r)}this.logRegistryResults(o,e.dryRun)}return{files:i,dirs:a}}logRegistryResults(e,t){let n=e.filter(e=>e.success).length,r=e.filter(e=>!e.success).length;if(n>0&&this.log.trace({action:t===!0?`dryRun`:`register`,type:`registrySummary`,successCount:n}),r>0){this.log.error({action:`register`,type:`registrySummary`,failCount:r});for(let t of e)if(!t.success){let e=t.error?.message??`Unknown error`;this.log.error({action:`register`,type:`registryEntry`,entryName:t.entryName,error:e})}}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),$)}getKiroPowersDir(){return this.joinPath(this.getHomeDir(),`.kiro/powers/installed`)}getHomeDir(){return s.homedir()}buildPowerFrontMatter(e){let t=e.name,n=e.description,r=e.displayName,i=e.keywords,a=e.author,o=[`---`];if(o.push(`name: "${t}"`),r!=null&&r.length>0&&o.push(`displayName: "${r}"`),n.length>0&&o.push(`description: "${n}"`),i!=null&&i.length>0){let e=i.map(e=>`"${e}"`).join(`, `);o.push(`keywords: [${e}]`)}return a!=null&&a.length>0&&o.push(`author: "${a}"`),o.push(`---`),o.join(`
|
|
196
|
+
`)}async writeSkillAsPower(e,t){let n=[],r=t.yamlFrontMatter.name,i=this.joinPath(this.getKiroPowersDir(),r),a=this.joinPath(i,vd),o={pathKind:P.Relative,path:vd,basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=`${this.buildPowerFrontMatter(t.yamlFrontMatter)}\n${t.content}`;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skillPower`,path:a}),n.push({path:o,success:!0,skipped:!1});else try{this.ensureDirectory(i),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`skillPower`,path:a}),n.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillPower`,path:a,error:t}),n.push({path:o,success:!1,error:e})}if(t.referenceDocuments!=null){let r=this.joinPath(i,$);for(let a of t.referenceDocuments){let t=a.dir.path,o=this.joinPath(r,t),s={pathKind:P.Relative,path:this.joinPath($,t),basePath:i,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=a.content;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`refDoc`,path:o}),n.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(r),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`refDoc`,path:o}),n.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`refDoc`,path:o,error:t}),n.push({path:s,success:!1,error:e})}}}let c=this.getRegistryWriter(nu),l=c.buildPowerEntry(t,i);return{fileResults:n,registryResult:(await this.registerInRegistry(c,[l],e))[0]??{success:!1,entryName:r,error:Error(`No registry result returned`)}}}buildFastCommandSteeringFileName(e){return this.transformFastCommandName(e,{includeSeriesPrefix:!0,seriesSeparator:`-`})}buildFastCommandSteeringContent(e){let t=e.yamlFrontMatter?.description??``,n=[`---`,`inclusion: manual`];return t.length>0&&n.push(`description: '${t}'`),n.push(`---`),`${n.join(`
|
|
196
197
|
`)}\n${e.content}`}async writeFastCommandSteeringFile(e,t){let n=this.getGlobalSteeringDir(),r=this.buildFastCommandSteeringFileName(t),i=this.joinPath(n,r),a={pathKind:P.Relative,path:r,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>i},o=this.buildFastCommandSteeringContent(t);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommandSteering`,path:i}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(i,o),this.log.trace({action:`write`,type:`fastCommandSteering`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`fastCommandSteering`,path:i,error:t}),{path:a,success:!1,error:e}}}buildSteeringFileName(e){return`kiro-${(e.workingChildDirectoryPath?.path??e.dir.path).replace(/\\/g,`/`).replace(/^\/+|\/+$/g,``).replace(/\//g,`-`)}.md`}buildSteeringContent(e){return`${[`---`,`inclusion: fileMatch`,`fileMatchPattern: '${(e.workingChildDirectoryPath?.path??e.dir.path).replace(/\\/g,`/`)}/**'`,`---`].join(`
|
|
197
|
-
`)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,dd,$),o=this.joinPath(a,i),s={pathKind:P.Relative,path:this.joinPath(r.path,dd,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`steeringFile`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`steeringFile`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`steeringFile`,path:o,error:t}),{path:s,success:!1,error:e}}}};const md=`AGENTS.md`;var hd=class extends X{constructor(){super(`ProjectPromptInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=t.workspace;if(l==null)return this.log.warn(`No workspace found in dependency context, skipping project prompt enhancement`),{};let u=(l.projects??[]).map(t=>{let r=t.name;if(r==null)return t;let a=i.join(c,r);if(!n.existsSync(a)||!n.statSync(a).isDirectory())return t;let o=t.dirFromWorkspacePath?.getAbsolutePath(),s=this.readRootMemoryPrompt(e,a),l=o==null?[]:this.scanChildMemoryPrompts(e,a,o);return{...t,...s!=null&&{rootMemoryPrompt:s},...l.length>0&&{childMemoryPrompts:l}}});return{workspace:{directory:l.directory,projects:u}}}readRootMemoryPrompt(e,t){let{fs:n,path:r,logger:i}=e,a=r.join(t,md);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Hl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:dt.ProjectRootMemory,content:t,length:t.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Root,path:``,getDirectoryName:()=>``}}}catch(e){i.error(`Failed to read root memory prompt at ${a}`,{error:e});return}}scanChildMemoryPrompts(e,t,n){let{logger:r}=e,i=[];try{this.scanDirectoryRecursive(e,t,t,n,i)}catch(e){r.error(`Failed to scan child memory prompts at ${t}`,{error:e})}return i}scanDirectoryRecursive(e,t,n,r,i){let{fs:a,path:o}=e,s=a.readdirSync(n,{withFileTypes:!0});for(let c of s){if(!c.isDirectory()||c.name.startsWith(`.`)||c.name===`node_modules`)continue;let s=o.join(n,c.name),l=o.join(s,md);if(a.existsSync(l)&&a.statSync(l).isFile()){let n=this.readChildMemoryPrompt(e,t,s,r);n!=null&&i.push(n)}this.scanDirectoryRecursive(e,t,s,r,i)}}readChildMemoryPrompt(e,t,n,r){let{fs:i,path:a,logger:o}=e,s=a.join(n,md);try{let e=Hl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:dt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}};const gd=`README.md`;var _d=class extends Z{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:gd})}async registerProjectOutputFiles(e){let t=[],{readmePrompts:n}=e.collectedInputContext;if(n==null||n.length===0)return t;for(let e of n){let n=e.targetDir,r=i.join(n.path,gd);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>i.join(n.basePath,r)})}return t}async canWrite(e){let{readmePrompts:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no README prompts to write`}),!1):!0}async writeProjectOutputs(e){let t=[],n=[],{readmePrompts:r}=e.collectedInputContext;if(r==null||r.length===0)return{files:t,dirs:n};for(let n of r){let r=await this.writeReadmeFile(e,n);t.push(r)}return{files:t,dirs:n}}async writeReadmeFile(e,t){let n=t.targetDir,a=i.join(n.path,gd),o=i.join(n.basePath,a),s=t.content,c={pathKind:P.Relative,path:a,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>o},l=t.isRoot?`project:${t.projectName}/README.md`:`project:${t.projectName}/${n.path}/README.md`;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`readme`,path:o,label:l}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(o);return r.existsSync(e)||r.mkdirSync(e,{recursive:!0}),r.writeFileSync(o,s,`utf-8`),this.log.trace({action:`write`,type:`readme`,path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`readme`,path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},vd=class extends X{constructor(){super(`ReadmeMdInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow 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);this.collectReadmeFiles(e,r,t,a,``,l)}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{readmePrompts:l}}collectReadmeFiles(e,t,n,r,i,a){let{fs:o,path:s,logger:c}=e,l=i===``,u=s.join(t,`README.md`);if(o.existsSync(u)&&o.statSync(u).isFile())try{let e=o.readFileSync(u,`utf-8`),t=l?n:s.join(n,i),c={pathKind:P.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:P.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:dt.Readme,content:e,length:e.length,filePathKind:P.Relative,projectName:n,targetDir:c,isRoot:l,markdownContents:[],dir:d})}catch(e){c.warn(`failed to read README.md`,{path:u,error:e})}try{let c=o.readdirSync(t,{withFileTypes:!0});for(let o of c)if(o.isDirectory()){let c=l?o.name:s.join(i,o.name),u=s.join(t,o.name);this.collectReadmeFiles(e,u,n,r,c,a)}}catch(e){c.warn(`failed to scan directory`,{path:t,error:e})}}},yd=class extends X{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=i.basename(o),u=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isDirectory()){let e=t.name===l;u.push({name:t.name,...e&&{isPromptSourceProject:!0},dirFromWorkspacePath:{pathKind:P.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:P.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},bd=class extends X{constructor(){super(`SkillInputPlugin`)}extractReferenceDocumentLinks(e){let t=[],n=e=>{if(e.type===`link`){let n=e,r=n.url;if(r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`))return;let i=[];for(let e of n.children)e.type===`text`&&e.value!=null&&i.push(e.value);t.push({text:i.join(``),path:r})}if(`children`in e&&Array.isArray(e.children))for(let t of e.children)n(t)};for(let t of e)n(t);return t}readReferenceDocuments(e,t,n,r){let a=[];for(let o of t){let t=i.resolve(e,o.path);if(!n.existsSync(t)){r.warn(`reference document not found`,{path:o.path,skillDir:e});continue}if(!n.statSync(t).isFile()){r.warn(`reference document path is not a file`,{path:o.path});continue}try{let r=Hl(n.readFileSync(t,`utf-8`)),s=r.contentWithoutFrontMatter,c=i.dirname(o.path);a.push({type:dt.SkillReferenceDocument,content:s,length:s.length,filePathKind:P.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:P.Relative,path:o.path,basePath:e,getDirectoryName:()=>c===`.`?``:c,getAbsolutePath:()=>t}})}catch(e){r.warn(`failed to read reference document`,{path:o.path,error:e})}}return a}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??bt,s=this.resolvePath(o,r,a),c=[];if(e.fs.existsSync(s)&&e.fs.statSync(s).isDirectory())try{let t=e.fs.readdirSync(s,{withFileTypes:!0});for(let r of t)if(r.isDirectory()){let t=e.path.join(s,r.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let a=Hl(e.fs.readFileSync(t,`utf-8`)),o=a.contentWithoutFrontMatter,l=this.extractReferenceDocumentLinks(a.markdownContents),u=e.path.join(s,r.name),d=this.readReferenceDocuments(u,l,e.fs,n);c.push({type:dt.Skill,content:o,length:o.length,filePathKind:P.Relative,yamlFrontMatter:a.yamlFrontMatter??{name:r.name,description:``},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,...d.length>0&&{referenceDocuments:d},dir:{pathKind:P.Relative,path:r.name,basePath:s,getDirectoryName:()=>r.name,getAbsolutePath:()=>i.join(s,r.name)}})}}}catch(e){n.error(`failed to scan skills`,{path:s,error:e})}return{skills:c}}},xd=class extends X{constructor(){super(`SubAgentInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??St,c=this.resolvePath(s,a,o),l=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isFile()&&t.name.endsWith(`.md`)){let e=i.join(c,t.name),n=Hl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:dt.SubAgent,content:a,length:a.length,filePathKind:P.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:P.Relative,path:t.name,basePath:c,getDirectoryName:()=>t.name.replace(/\.md$/,``),getAbsolutePath:()=>e}})}}catch(e){n.error(`Failed to scan sub agents at ${c}`,{error:e})}return{subAgents:l}}};const Sd=`WARP.md`;var Cd=class extends Z{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:Sd})}isAgentsPluginRegistered(e){return`registeredPluginNames`in e&&e.registeredPluginNames!=null?e.registeredPluginNames.includes(`AgentsOutputPlugin`):!1}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=this.isAgentsPluginRegistered(e);for(let e of n)if(e.dirFromWorkspacePath!=null){if(r)t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Sd));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Sd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Sd))}return t}async canWrite(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext;return t?r==null?(this.log.debug(`skipped`,{reason:`AgentsOutputPlugin registered but no global memory`}),!1):!0:n.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.debug(`skipped`,{reason:`no outputs to write`}),!1)}async writeProjectOutputs(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext,{projects:i}=n,a=[],o=[];if(t){if(r==null)return{files:[],dirs:[]};for(let t of i){let n=t.dirFromWorkspacePath;if(n==null)continue;let i=t.name??`unknown`,o=await this.writePromptFile(e,n,r.content,`project:${i}/global-warp`);a.push(o)}return{files:a,dirs:o}}let s=this.extractGlobalMemoryContent(e);for(let t of i){let n=t.name??`unknown`,r=t.dirFromWorkspacePath;if(r!=null){if(t.rootMemoryPrompt!=null){let i=this.combineGlobalWithContent(s,t.rootMemoryPrompt.content),o=await this.writePromptFile(e,r,i,`project:${n}/root`);a.push(o)}if(t.childMemoryPrompts!=null)for(let r of t.childMemoryPrompts){let t=await this.writePromptFile(e,r.dir,r.content,`project:${n}/child:${r.workingChildDirectoryPath?.path??`unknown`}`);a.push(t)}}}return{files:a,dirs:o}}},wd=class extends X{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,shadowProjectDir:r}=this.resolveBasePaths(t),a=(t.externalProjects||[]).map(e=>{let t=this.resolvePath(e,n,r);return{name:i.basename(t),dirFromWorkspacePath:{pathKind:P.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:P.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowSourceProjectDir:r,...a.length>0&&{externalProjects:a}}}};const Td=`.vscode`,Ed=[`.vscode/settings.json`,`.vscode/extensions.json`];var Dd=class extends Z{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of Ed){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.VSCode)?!0:(this.log.debug(`skipped`,{reason:`no VS Code config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.VSCode);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.VSCode){let e=t.indexOf(Td);return e===-1?this.joinPath(Td,this.basename(t)):t.substring(e)}return this.basename(t)}},Od=Pu({plugins:[new Iu,new Bu,new qu,new ed,new id,new pd,new Cd,new ld,new Dd,new _d,new wd,new yd,new Ru,new od,new bd,new td,new xd,new ad,new hd,new vd]}),kd=Od;async function Ad(){await new Eu(...n.argv).run(Od)}Ad().catch(e=>{console.error(e)});export{X as AbstractInputPlugin,Z as AbstractOutputPlugin,eu as AbstractPlugin,gt as CircularDependencyError,ft as ClaudeCodeCLISubAgentColors,pt as CodingAgentTools,uu as ConfigLoader,cu as DEFAULT_CONFIG_FILE_NAME,lu as DEFAULT_GLOBAL_CONFIG_DIR,wt as DEFAULT_GLOBAL_MEMORY_FILE,xt as DEFAULT_SHADOW_FAST_COMMAND_DIR,Ct as DEFAULT_SHADOW_PROJECTS_DIR,yt as DEFAULT_SHADOW_PROJECT_SUFFIX,bt as DEFAULT_SHADOW_SKILL_SOURCE_DIR,St as DEFAULT_SHADOW_SUB_AGENT_DIR,vt as DEFAULT_WORKSPACE_DIR,P as FilePathKind,ht as GlobalConfigDirectoryType,F as IDEKind,_t as MissingDependencyError,mt as NamingCaseKind,I as PathPlaceholders,ut as PluginKind,dt as PromptKind,tt as checkCanClean,rt as checkCanWrite,et as collectAllPluginOutputs,$l as createLogger,kd as default,Pu as defineConfig,nt as executeOnCleanComplete,it as executeWriteOutputs,fu as getConfigLoader,Gl as getGlobalLogLevel,pu as loadUserConfig,ku as mergeConfig,Wl as setGlobalLogLevel};
|
|
198
|
+
`)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,_d,$),o=this.joinPath(a,i),s={pathKind:P.Relative,path:this.joinPath(r.path,_d,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`steeringFile`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`steeringFile`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`steeringFile`,path:o,error:t}),{path:s,success:!1,error:e}}}};const bd=`AGENTS.md`;var xd=class extends X{constructor(){super(`ProjectPromptInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=t.workspace;if(l==null)return this.log.warn(`No workspace found in dependency context, skipping project prompt enhancement`),{};let u=(l.projects??[]).map(t=>{let r=t.name;if(r==null)return t;let a=i.join(c,r);if(!n.existsSync(a)||!n.statSync(a).isDirectory())return t;let o=t.dirFromWorkspacePath?.getAbsolutePath(),s=this.readRootMemoryPrompt(e,a),l=o==null?[]:this.scanChildMemoryPrompts(e,a,o);return{...t,...s!=null&&{rootMemoryPrompt:s},...l.length>0&&{childMemoryPrompts:l}}});return{workspace:{directory:l.directory,projects:u}}}readRootMemoryPrompt(e,t){let{fs:n,path:r,logger:i}=e,a=r.join(t,bd);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Hl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:dt.ProjectRootMemory,content:t,length:t.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Root,path:``,getDirectoryName:()=>``}}}catch(e){i.error(`Failed to read root memory prompt at ${a}`,{error:e});return}}scanChildMemoryPrompts(e,t,n){let{logger:r}=e,i=[];try{this.scanDirectoryRecursive(e,t,t,n,i)}catch(e){r.error(`Failed to scan child memory prompts at ${t}`,{error:e})}return i}scanDirectoryRecursive(e,t,n,r,i){let{fs:a,path:o}=e,s=a.readdirSync(n,{withFileTypes:!0});for(let c of s){if(!c.isDirectory()||c.name.startsWith(`.`)||c.name===`node_modules`)continue;let s=o.join(n,c.name),l=o.join(s,bd);if(a.existsSync(l)&&a.statSync(l).isFile()){let n=this.readChildMemoryPrompt(e,t,s,r);n!=null&&i.push(n)}this.scanDirectoryRecursive(e,t,s,r,i)}}readChildMemoryPrompt(e,t,n,r){let{fs:i,path:a,logger:o}=e,s=a.join(n,bd);try{let e=Hl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:dt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}};const Sd=`README.md`;var Cd=class extends Z{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:Sd})}async registerProjectOutputFiles(e){let t=[],{readmePrompts:n}=e.collectedInputContext;if(n==null||n.length===0)return t;for(let e of n){let n=e.targetDir,r=i.join(n.path,Sd);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>i.join(n.basePath,r)})}return t}async canWrite(e){let{readmePrompts:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no README prompts to write`}),!1):!0}async writeProjectOutputs(e){let t=[],n=[],{readmePrompts:r}=e.collectedInputContext;if(r==null||r.length===0)return{files:t,dirs:n};for(let n of r){let r=await this.writeReadmeFile(e,n);t.push(r)}return{files:t,dirs:n}}async writeReadmeFile(e,t){let n=t.targetDir,a=i.join(n.path,Sd),o=i.join(n.basePath,a),s=t.content,c={pathKind:P.Relative,path:a,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>o},l=t.isRoot?`project:${t.projectName}/README.md`:`project:${t.projectName}/${n.path}/README.md`;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`readme`,path:o,label:l}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(o);return r.existsSync(e)||r.mkdirSync(e,{recursive:!0}),r.writeFileSync(o,s,`utf-8`),this.log.trace({action:`write`,type:`readme`,path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`readme`,path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},wd=class extends X{constructor(){super(`ReadmeMdInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow 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);this.collectReadmeFiles(e,r,t,a,``,l)}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{readmePrompts:l}}collectReadmeFiles(e,t,n,r,i,a){let{fs:o,path:s,logger:c}=e,l=i===``,u=s.join(t,`README.md`);if(o.existsSync(u)&&o.statSync(u).isFile())try{let e=o.readFileSync(u,`utf-8`),t=l?n:s.join(n,i),c={pathKind:P.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:P.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:dt.Readme,content:e,length:e.length,filePathKind:P.Relative,projectName:n,targetDir:c,isRoot:l,markdownContents:[],dir:d})}catch(e){c.warn(`failed to read README.md`,{path:u,error:e})}try{let c=o.readdirSync(t,{withFileTypes:!0});for(let o of c)if(o.isDirectory()){let c=l?o.name:s.join(i,o.name),u=s.join(t,o.name);this.collectReadmeFiles(e,u,n,r,c,a)}}catch(e){c.warn(`failed to scan directory`,{path:t,error:e})}}},Td=class extends X{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Ct,c=this.resolvePath(s,a,o),l=i.basename(o),u=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isDirectory()){let e=t.name===l;u.push({name:t.name,...e&&{isPromptSourceProject:!0},dirFromWorkspacePath:{pathKind:P.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:P.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},Ed=class extends X{constructor(){super(`SkillInputPlugin`)}extractReferenceDocumentLinks(e){let t=[],n=e=>{if(e.type===`link`){let n=e,r=n.url;if(r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`))return;let i=[];for(let e of n.children)e.type===`text`&&e.value!=null&&i.push(e.value);t.push({text:i.join(``),path:r})}if(`children`in e&&Array.isArray(e.children))for(let t of e.children)n(t)};for(let t of e)n(t);return t}readReferenceDocuments(e,t,n,r){let a=[];for(let o of t){let t=i.resolve(e,o.path);if(!n.existsSync(t)){r.warn(`reference document not found`,{path:o.path,skillDir:e});continue}if(!n.statSync(t).isFile()){r.warn(`reference document path is not a file`,{path:o.path});continue}try{let r=Hl(n.readFileSync(t,`utf-8`)),s=r.contentWithoutFrontMatter,c=i.dirname(o.path);a.push({type:dt.SkillReferenceDocument,content:s,length:s.length,filePathKind:P.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:P.Relative,path:o.path,basePath:e,getDirectoryName:()=>c===`.`?``:c,getAbsolutePath:()=>t}})}catch(e){r.warn(`failed to read reference document`,{path:o.path,error:e})}}return a}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??bt,s=this.resolvePath(o,r,a),c=[];if(e.fs.existsSync(s)&&e.fs.statSync(s).isDirectory())try{let t=e.fs.readdirSync(s,{withFileTypes:!0});for(let r of t)if(r.isDirectory()){let t=e.path.join(s,r.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let a=Hl(e.fs.readFileSync(t,`utf-8`)),o=a.contentWithoutFrontMatter,l=this.extractReferenceDocumentLinks(a.markdownContents),u=e.path.join(s,r.name),d=this.readReferenceDocuments(u,l,e.fs,n);c.push({type:dt.Skill,content:o,length:o.length,filePathKind:P.Relative,yamlFrontMatter:a.yamlFrontMatter??{name:r.name,description:``},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,...d.length>0&&{referenceDocuments:d},dir:{pathKind:P.Relative,path:r.name,basePath:s,getDirectoryName:()=>r.name,getAbsolutePath:()=>i.join(s,r.name)}})}}}catch(e){n.error(`failed to scan skills`,{path:s,error:e})}return{skills:c}}},Dd=class extends X{constructor(){super(`SubAgentInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??St,c=this.resolvePath(s,a,o),l=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isFile()&&t.name.endsWith(`.md`)){let e=i.join(c,t.name),n=Hl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:dt.SubAgent,content:a,length:a.length,filePathKind:P.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:P.Relative,path:t.name,basePath:c,getDirectoryName:()=>t.name.replace(/\.md$/,``),getAbsolutePath:()=>e}})}}catch(e){n.error(`Failed to scan sub agents at ${c}`,{error:e})}return{subAgents:l}}};const Od=`WARP.md`;var kd=class extends Z{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:Od})}isAgentsPluginRegistered(e){return`registeredPluginNames`in e&&e.registeredPluginNames!=null?e.registeredPluginNames.includes(`AgentsOutputPlugin`):!1}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=this.isAgentsPluginRegistered(e);for(let e of n)if(e.dirFromWorkspacePath!=null){if(r)t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Od));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Od)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Od))}return t}async canWrite(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext;return t?r==null?(this.log.debug(`skipped`,{reason:`AgentsOutputPlugin registered but no global memory`}),!1):!0:n.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.debug(`skipped`,{reason:`no outputs to write`}),!1)}async writeProjectOutputs(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext,{projects:i}=n,a=[],o=[];if(t){if(r==null)return{files:[],dirs:[]};for(let t of i){let n=t.dirFromWorkspacePath;if(n==null)continue;let i=t.name??`unknown`,o=await this.writePromptFile(e,n,r.content,`project:${i}/global-warp`);a.push(o)}return{files:a,dirs:o}}let s=this.extractGlobalMemoryContent(e);for(let t of i){let n=t.name??`unknown`,r=t.dirFromWorkspacePath;if(r!=null){if(t.rootMemoryPrompt!=null){let i=this.combineGlobalWithContent(s,t.rootMemoryPrompt.content),o=await this.writePromptFile(e,r,i,`project:${n}/root`);a.push(o)}if(t.childMemoryPrompts!=null)for(let r of t.childMemoryPrompts){let t=await this.writePromptFile(e,r.dir,r.content,`project:${n}/child:${r.workingChildDirectoryPath?.path??`unknown`}`);a.push(t)}}}return{files:a,dirs:o}}},Ad=class extends X{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,shadowProjectDir:r}=this.resolveBasePaths(t),a=(t.externalProjects||[]).map(e=>{let t=this.resolvePath(e,n,r);return{name:i.basename(t),dirFromWorkspacePath:{pathKind:P.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:P.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowSourceProjectDir:r,...a.length>0&&{externalProjects:a}}}};const jd=`.vscode`,Md=[`.vscode/settings.json`,`.vscode/extensions.json`];var Nd=class extends Z{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of Md){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.VSCode)?!0:(this.log.debug(`skipped`,{reason:`no VS Code config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.VSCode);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.VSCode){let e=t.indexOf(jd);return e===-1?this.joinPath(jd,this.basename(t)):t.substring(e)}return this.basename(t)}},Pd=Pu({plugins:[new Iu,new Bu,new qu,new $u,new od,new ud,new yd,new kd,new hd,new Nd,new Cd,new Ad,new Td,new Ru,new fd,new Ed,new sd,new Dd,new dd,new xd,new wd]}),Fd=Pd;async function Id(){await new Eu(...n.argv).run(Pd)}Id().catch(e=>{console.error(e)});export{X as AbstractInputPlugin,Z as AbstractOutputPlugin,eu as AbstractPlugin,gt as CircularDependencyError,ft as ClaudeCodeCLISubAgentColors,pt as CodingAgentTools,uu as ConfigLoader,cu as DEFAULT_CONFIG_FILE_NAME,lu as DEFAULT_GLOBAL_CONFIG_DIR,wt as DEFAULT_GLOBAL_MEMORY_FILE,xt as DEFAULT_SHADOW_FAST_COMMAND_DIR,Ct as DEFAULT_SHADOW_PROJECTS_DIR,yt as DEFAULT_SHADOW_PROJECT_SUFFIX,bt as DEFAULT_SHADOW_SKILL_SOURCE_DIR,St as DEFAULT_SHADOW_SUB_AGENT_DIR,vt as DEFAULT_WORKSPACE_DIR,P as FilePathKind,ht as GlobalConfigDirectoryType,F as IDEKind,_t as MissingDependencyError,mt as NamingCaseKind,I as PathPlaceholders,ut as PluginKind,dt as PromptKind,tt as checkCanClean,rt as checkCanWrite,et as collectAllPluginOutputs,$l as createLogger,Fd as default,Pu as defineConfig,nt as executeOnCleanComplete,it as executeWriteOutputs,fu as getConfigLoader,Gl as getGlobalLogLevel,pu as loadUserConfig,ku as mergeConfig,Wl as setGlobalLogLevel};
|