@truenine/memory-sync-cli 0.0.19 → 1.0.0

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -207,4 +207,4 @@ CONFIGURATION:
207
207
  `,`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}}},vf=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 yf(e){let t=[...e],n=t[0];n!=null&&bf(n)&&t.shift();let r=t[0];return r!=null&&xf(r)&&t.shift(),t}function bf(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 xf(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}const Sf=new Set([`help`,`init`,`dry-run`,`clean`]),Cf=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),wf=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function Tf(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=wf.get(n)??4;for(let e of t){let t=wf.get(e)??4;t<r&&(r=t,n=e)}return n}function Ef(e){let{helpFlag:t,subcommand:n,dryRun:r,unknownCommand:i}=e;return t?new lf:i==null?n===`help`?new lf:n===`init`?new _f:n===`dry-run`?new of:n===`clean`?r?new af:new st:new sf:new vf(i)}function Df(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=Cf.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,Sf.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var Of=class{logger;args;outputPlugins=[];constructor(...e){this.args=Df(yf(e.filter(e=>e!=null))),this.logger=Qd(`PluginPipeline`,Tf(this.args)),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 Ef(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:Ze.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:Ze.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 ht(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 mt(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.shadowProjectDir??e.shadowProjectDir,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?{}:{shadowProjectDir:u},...d==null?{}:{readmePrompts:d}}}};const kf={workspaceDir:_t,shadowProjectDir:`$WORKSPACE/${vt}`,shadowSkillSourceDir:yt,shadowFastCommandDir:bt,shadowSubAgentDir:xt,globalMemoryFile:Ct,shadowSourceProjectDir:St,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[],logLevel:`info`};function Af(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowProjectDir==null?{}:{shadowProjectDir:e.shadowProjectDir},...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.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...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 jf(...e){return e.reduce((e,t)=>Mf(e,t),{...kf})}function Mf(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:Nf(e.excludePatterns,i),fastCommandSeriesOptions:Pf(e.fastCommandSeriesOptions,a)}}function Nf(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function Pf(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 Ff(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function If(e={}){let t,n,a;Ff(e)?(t=e.pluginOptions??{},n=e.loadUserConfig??!0,a=e.cwd):(t=e,n=!0);let o={};if(n){let e=hf(a);e.found&&(o=Af(e.config),Qd(`defineConfig`,t.logLevel??e.config.logLevel).debug(`loaded`,{sources:e.sources}))}let s=jf(o,t),{plugins:c=[],logLevel:l}=s,u={logger:Qd(`defineConfig`,l),userConfigOptions:s,fs:r,path:i,glob:Ze.default},d=c.filter(e=>e.type===ct.Input),f=c.filter(e=>e.type===ct.Output),p=new Of().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.shadowProjectDir!=null&&{shadowProjectDir:p.shadowProjectDir},...p.readmePrompts!=null&&{readmePrompts:p.readmePrompts}},outputPlugins:f}}const Lf=`AGENTS.md`;var Rf=class extends tf{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Lf})}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,Lf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Lf));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.info(`No outputs to write, skipping`),!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 zf=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Bf=class extends ef{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 zf){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 Vf=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Hf=class extends tf{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 Vf){let r=i.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:I.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:I.Relative,path:o,basePath:t.basePath,getDirectoryName:()=>i.basename(t.path),getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.info(`would write`,{path:s,label:a,dryRun:!0}),{path:c,success:!0,skipped:!1};try{return r.writeFileSync(s,n.content,`utf-8`),this.log.info(`written`,{path:s,label:a}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:s,label:a,error:t}),{path:c,success:!1,error:e}}}};const Uf=`CLAUDE.md`,Wf=`.claude`,Gf=`commands`,Kf=`agents`,qf=`skills`,Jf=[Gf,Kf,qf];var Yf=class extends tf{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:Wf,outputFileName:Uf})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Jf){let r=i.join(e.dirFromWorkspacePath.path,Wf,n);t.push({pathKind:I.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,Uf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Uf));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:I.Relative,path:Uf,basePath:n,getDirectoryName:()=>Wf,getAbsolutePath:()=>i.join(n,Uf)}]}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.info(`No outputs to write, skipping`),!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,Uf),c={pathKind:I.Relative,path:Uf,basePath:o,getDirectoryName:()=>Wf,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write global memory -> ${s}`),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.info(`Written global memory -> ${s}`),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write global memory: ${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,Wf,Gf),l=i.join(c,s),u={pathKind:I.Relative,path:i.join(t.path,Wf,Gf,s),basePath:t.basePath,getDirectoryName:()=>Gf,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${l}`),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.info(`Written fast command -> ${l}`),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write fast command: ${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,Wf,Kf),c=i.join(s,o),l={pathKind:I.Relative,path:i.join(t.path,Wf,Kf,o),basePath:t.basePath,getDirectoryName:()=>Kf,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write sub agent -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written sub agent -> ${c}`),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write sub agent: ${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,Wf,qf,o),c=i.join(s,`SKILL.md`),l={pathKind:I.Relative,path:i.join(t.path,Wf,qf,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write skill -> ${c}`),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written skill -> ${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(`Failed to write skill: ${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:I.Relative,path:i.join(o.path,Wf,qf,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write skill reference doc -> ${l}`),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.info(`Written skill reference doc -> ${l}`),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write skill reference doc: ${t}`),s.push({path:u,success:!1,error:e})}return s}};const Xf=`AGENTS.md`,Zf=`.factory`,Qf=`commands`,$f=`agents`,ep=`skills`,tp=[Qf,$f,ep];var np=class extends tf{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:Zf,outputFileName:Xf})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of tp){let r=i.join(e.dirFromWorkspacePath.path,Zf,n);t.push({pathKind:I.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:I.Relative,path:Xf,basePath:n,getDirectoryName:()=>Zf,getAbsolutePath:()=>i.join(n,Xf)}]}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.info(`No outputs to write, skipping`),!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,Xf),c={pathKind:I.Relative,path:Xf,basePath:o,getDirectoryName:()=>Zf,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write global memory -> ${s}`),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.info(`Written global memory -> ${s}`),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write global memory: ${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,Zf,Qf),l=i.join(c,s),u={pathKind:I.Relative,path:i.join(t.path,Zf,Qf,s),basePath:t.basePath,getDirectoryName:()=>Qf,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${l}`),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.info(`Written fast command -> ${l}`),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write fast command: ${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,Zf,$f),c=i.join(s,o),l={pathKind:I.Relative,path:i.join(t.path,Zf,$f,o),basePath:t.basePath,getDirectoryName:()=>$f,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write sub agent -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written sub agent -> ${c}`),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write sub agent: ${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,Zf,ep,o),c=i.join(s,`SKILL.md`),l={pathKind:I.Relative,path:i.join(t.path,Zf,ep,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write skill -> ${c}`),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written skill -> ${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(`Failed to write skill: ${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:I.Relative,path:i.join(o.path,Zf,ep,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write skill reference doc -> ${l}`),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.info(`Written skill reference doc -> ${l}`),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write skill reference doc: ${t}`),s.push({path:u,success:!1,error:e})}return s}},rp=class extends ef{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??bt,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:lt.FastCommand,content:i,length:i.length,filePathKind:I.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:I.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 ip=`GEMINI.md`,ap=`.gemini`;var op=class extends tf{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:ap,outputFileName:ip})}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,ip)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,ip));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:I.Relative,path:ip,basePath:n,getDirectoryName:()=>ap,getAbsolutePath:()=>i.join(n,ip)}]}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.info(`No outputs to write, skipping`),!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,ip),c={pathKind:I.Relative,path:ip,basePath:o,getDirectoryName:()=>ap,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write global memory -> ${s}`),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.info(`Written global memory -> ${s}`),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write global memory: ${t}`),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}},sp=class extends ef{constructor(){super(`GlobalMemoryInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??Ct,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:lt.GlobalMemory,content:t,length:t.length,filePathKind:I.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:I.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:pt.UserHome,directory:{pathKind:I.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},cp=class extends ef{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=L.Original;e.includes(`.vscode`)?a=L.VSCode:e.includes(`.idea`)?a=L.IntellijIDEA:e.includes(`.editorconfig`)&&(a=L.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:I.Absolute,dir:{pathKind:I.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const lp=`.idea`,up=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`];var dp=class extends tf{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===L.IntellijIDEA||e.type===L.EditorConfig))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of up){let r=this.joinPath(n.path,e);t.push({pathKind:I.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===L.IntellijIDEA||e.type===L.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===L.IntellijIDEA||e.type===L.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:I.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`would write`,{path:a,label:r,dryRun:!0}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.info(`written`,{path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===L.EditorConfig)return`.editorconfig`;if(e.type===L.IntellijIDEA){let e=t.indexOf(lp);return e===-1?this.joinPath(lp,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const fp=`GLOBAL.md`,pp=`.kiro`,$=`steering`,mp=`POWER.md`;var hp=class extends tf{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:pp,outputFileName:fp})}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,pp,$);t.push({pathKind:I.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,pp,$,r);t.push({pathKind:I.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:I.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:I.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:I.Relative,path:fp,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,fp)}),n!=null)for(let e of n){let t=this.buildFastCommandSteeringFileName(e);i.push({pathKind:I.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:I.Relative,path:mp,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(r,mp)}),t.referenceDocuments!=null){let e=this.joinPath(r,$);for(let n of t.referenceDocuments){let t=n.dir.path;i.push({pathKind:I.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.info(`No outputs to write, skipping`),!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,fp),a={pathKind:I.Relative,path:fp,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.info(`[DRY-RUN] Would write global memory -> ${r}`),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),this.writeFileSync(r,t.content),this.log.info(`Written global memory -> ${r}`),i.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write global memory: ${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=t===!0?`[DRY-RUN] `:``,r=e.filter(e=>e.success).length,i=e.filter(e=>!e.success).length;if(r>0&&this.log.info(`${n}Registry: ${r} power(s) registered successfully`),i>0){this.log.error(`${n}Registry: ${i} power(s) failed to register`);for(let t of e)if(!t.success){let e=t.error?.message??`Unknown error`;this.log.error(` - ${t.entryName}: ${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(`
208
208
  `)}async writeSkillAsPower(e,t){let n=[],r=t.yamlFrontMatter.name,i=this.joinPath(this.getKiroPowersDir(),r),a=this.joinPath(i,mp),o={pathKind:I.Relative,path:mp,basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=`${this.buildPowerFrontMatter(t.yamlFrontMatter)}\n${t.content}`;if(e.dryRun===!0)this.log.info(`[DRY-RUN] Would write skill power -> ${a}`),n.push({path:o,success:!0,skipped:!1});else try{this.ensureDirectory(i),this.writeFileSync(a,s),this.log.info(`Written skill power -> ${a}`),n.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write skill power: ${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:I.Relative,path:this.joinPath($,t),basePath:i,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=a.content;if(e.dryRun===!0)this.log.info(`[DRY-RUN] Would write reference document -> ${o}`),n.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(r),this.writeFileSync(o,c),this.log.info(`Written reference document -> ${o}`),n.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error(`Failed to write reference document: ${t}`),n.push({path:s,success:!1,error:e})}}}let c=this.getRegistryWriter(rf),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(`
209
209
  `)}\n${e.content}`}async writeFastCommandSteeringFile(e,t){let n=this.getGlobalSteeringDir(),r=this.buildFastCommandSteeringFileName(t),i=this.joinPath(n,r),a={pathKind:I.Relative,path:r,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>i},o=this.buildFastCommandSteeringContent(t);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command steering -> ${i}`),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(i,o),this.log.info(`Written fast command steering -> ${i}`),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write fast command steering: ${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(`
210
- `)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,pp,$),o=this.joinPath(a,i),s={pathKind:I.Relative,path:this.joinPath(r.path,pp,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write steering file -> ${o}`),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.info(`Written steering file -> ${o}`),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write steering file: ${t}`),{path:s,success:!1,error:e}}}};const gp=`AGENTS.md`;var _p=class extends ef{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.shadowSourceProjectDir??St,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,`dist`);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,gp);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Hl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:lt.ProjectRootMemory,content:t,length:t.length,filePathKind:I.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:I.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,gp);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,gp);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:lt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:I.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:I.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:I.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 vp=`README.md`;var yp=class extends tf{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:vp})}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,vp);t.push({pathKind:I.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,vp),o=i.join(n.basePath,a),s=t.content,c={pathKind:I.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.info(`would write`,{path:o,label:l,dryRun:!0}),{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.info(`written`,{path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},bp=class extends ef{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.shadowSourceProjectDir??St,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow source project 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,o=i.join(c,t,`dist`);!r.existsSync(o)||!r.statSync(o).isDirectory()||this.collectReadmeFiles(e,o,t,a,``,l)}}catch(e){n.error(`failed to scan shadow source 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:I.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:I.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:lt.Readme,content:e,length:e.length,filePathKind:I.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})}}},xp=class extends ef{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSourceProjectDir??St,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:I.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow source projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:I.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},Sp=class extends ef{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:lt.SkillReferenceDocument,content:s,length:s.length,filePathKind:I.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:I.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??yt,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:lt.Skill,content:o,length:o.length,filePathKind:I.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:I.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}}},Cp=class extends ef{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??xt,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:lt.SubAgent,content:a,length:a.length,filePathKind:I.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:I.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 wp=`WARP.md`;var Tp=class extends tf{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:wp})}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,wp));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,wp)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,wp))}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}}},Ep=class extends ef{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:I.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:I.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowProjectDir:r,...a.length>0&&{externalProjects:a}}}};const Dp=`.vscode`,Op=[`.vscode/settings.json`,`.vscode/extensions.json`];var kp=class extends tf{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===L.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of Op){let r=this.joinPath(n.path,e);t.push({pathKind:I.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===L.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===L.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:I.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`would write`,{path:a,label:r,dryRun:!0}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.info(`written`,{path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===L.VSCode){let e=t.indexOf(Dp);return e===-1?this.joinPath(Dp,this.basename(t)):t.substring(e)}return this.basename(t)}},Ap=If({plugins:[new Rf,new Hf,new Yf,new np,new op,new hp,new Tp,new dp,new kp,new yp,new Ep,new xp,new Bf,new cp,new Sp,new rp,new Cp,new sp,new _p,new bp]}),jp=Ap;async function Mp(){await new Of(...n.argv).run(Ap)}Mp().catch(e=>{console.error(e)});export{ef as AbstractInputPlugin,tf as AbstractOutputPlugin,$d as AbstractPlugin,mt as CircularDependencyError,ut as ClaudeCodeCLISubAgentColors,dt as CodingAgentTools,ff as ConfigLoader,uf as DEFAULT_CONFIG_FILE_NAME,df as DEFAULT_GLOBAL_CONFIG_DIR,Ct as DEFAULT_GLOBAL_MEMORY_FILE,bt as DEFAULT_SHADOW_FAST_COMMAND_DIR,vt as DEFAULT_SHADOW_PROJECT_SUFFIX,yt as DEFAULT_SHADOW_SKILL_SOURCE_DIR,St as DEFAULT_SHADOW_SOURCE_PROJECT_DIR,xt as DEFAULT_SHADOW_SUB_AGENT_DIR,_t as DEFAULT_WORKSPACE_DIR,I as FilePathKind,pt as GlobalConfigDirectoryType,L as IDEKind,ht as MissingDependencyError,ft as NamingCaseKind,gt as PathPlaceholders,ct as PluginKind,lt as PromptKind,$e as checkCanClean,tt as checkCanWrite,Qe as collectAllPluginOutputs,Qd as createLogger,jp as default,If as defineConfig,et as executeOnCleanComplete,nt as executeWriteOutputs,mf as getConfigLoader,hf as loadUserConfig,jf as mergeConfig};
210
+ `)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,pp,$),o=this.joinPath(a,i),s={pathKind:I.Relative,path:this.joinPath(r.path,pp,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write steering file -> ${o}`),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.info(`Written steering file -> ${o}`),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write steering file: ${t}`),{path:s,success:!1,error:e}}}};const gp=`AGENTS.md`;var _p=class extends ef{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.shadowSourceProjectDir??St,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,gp);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Hl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:lt.ProjectRootMemory,content:t,length:t.length,filePathKind:I.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:I.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,gp);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,gp);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:lt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:I.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:I.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:I.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 vp=`README.md`;var yp=class extends tf{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:vp})}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,vp);t.push({pathKind:I.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,vp),o=i.join(n.basePath,a),s=t.content,c={pathKind:I.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.info(`would write`,{path:o,label:l,dryRun:!0}),{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.info(`written`,{path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},bp=class extends ef{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.shadowSourceProjectDir??St,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow source project 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 source 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:I.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:I.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:lt.Readme,content:e,length:e.length,filePathKind:I.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})}}},xp=class extends ef{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSourceProjectDir??St,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:I.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow source projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:I.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},Sp=class extends ef{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:lt.SkillReferenceDocument,content:s,length:s.length,filePathKind:I.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:I.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??yt,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:lt.Skill,content:o,length:o.length,filePathKind:I.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:I.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}}},Cp=class extends ef{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??xt,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:lt.SubAgent,content:a,length:a.length,filePathKind:I.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:I.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 wp=`WARP.md`;var Tp=class extends tf{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:wp})}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,wp));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,wp)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,wp))}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}}},Ep=class extends ef{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:I.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:I.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowProjectDir:r,...a.length>0&&{externalProjects:a}}}};const Dp=`.vscode`,Op=[`.vscode/settings.json`,`.vscode/extensions.json`];var kp=class extends tf{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===L.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of Op){let r=this.joinPath(n.path,e);t.push({pathKind:I.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===L.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===L.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:I.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`would write`,{path:a,label:r,dryRun:!0}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.info(`written`,{path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`write failed`,{path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===L.VSCode){let e=t.indexOf(Dp);return e===-1?this.joinPath(Dp,this.basename(t)):t.substring(e)}return this.basename(t)}},Ap=If({plugins:[new Rf,new Hf,new Yf,new np,new op,new hp,new Tp,new dp,new kp,new yp,new Ep,new xp,new Bf,new cp,new Sp,new rp,new Cp,new sp,new _p,new bp]}),jp=Ap;async function Mp(){await new Of(...n.argv).run(Ap)}Mp().catch(e=>{console.error(e)});export{ef as AbstractInputPlugin,tf as AbstractOutputPlugin,$d as AbstractPlugin,mt as CircularDependencyError,ut as ClaudeCodeCLISubAgentColors,dt as CodingAgentTools,ff as ConfigLoader,uf as DEFAULT_CONFIG_FILE_NAME,df as DEFAULT_GLOBAL_CONFIG_DIR,Ct as DEFAULT_GLOBAL_MEMORY_FILE,bt as DEFAULT_SHADOW_FAST_COMMAND_DIR,vt as DEFAULT_SHADOW_PROJECT_SUFFIX,yt as DEFAULT_SHADOW_SKILL_SOURCE_DIR,St as DEFAULT_SHADOW_SOURCE_PROJECT_DIR,xt as DEFAULT_SHADOW_SUB_AGENT_DIR,_t as DEFAULT_WORKSPACE_DIR,I as FilePathKind,pt as GlobalConfigDirectoryType,L as IDEKind,ht as MissingDependencyError,ft as NamingCaseKind,gt as PathPlaceholders,ct as PluginKind,lt as PromptKind,$e as checkCanClean,tt as checkCanWrite,Qe as collectAllPluginOutputs,Qd as createLogger,jp as default,If as defineConfig,et as executeOnCleanComplete,nt as executeWriteOutputs,mf as getConfigLoader,hf as loadUserConfig,jf as mergeConfig};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@truenine/memory-sync-cli",
3
3
  "type": "module",
4
- "version": "0.0.19",
4
+ "version": "1.0.0",
5
5
  "description": "TrueNine Life CLI Tools",
6
6
  "author": "TrueNine",
7
7
  "license": "UNLICENSED",