@truenine/memory-sync-cli 0.0.9 → 0.0.11

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 +3 -3
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -166,7 +166,7 @@ var n=v(`buffer`),r=n.Buffer;function i(e,t){for(var n in e)t[n]=e[n]}r.from&&r.
166
166
  `));g&&this.exceptions.handle(g),_&&this.rejections.handle(_)}getHighestLogLevel(){let e=g(this.levels,this.level);return!this.transports||this.transports.length===0?e:this.transports.reduce((e,t)=>{let n=g(this.levels,t.level);return n!==null&&n>e?n:e},e)}isLevelEnabled(e){let t=g(this.levels,e);if(t===null)return!1;let n=g(this.levels,this.level);return n===null?!1:!this.transports||this.transports.length===0?n>=t:this.transports.findIndex(e=>{let r=g(this.levels,e.level);return r===null&&(r=n),r>=t})!==-1}log(e,t,...n){if(arguments.length===1)return e[a]=e.level,this._addDefaultMeta(e),this.write(e),this;if(arguments.length===2)return t&&typeof t==`object`?(t[a]=t.level=e,this._addDefaultMeta(t),this.write(t),this):(t={[a]:e,level:e,message:t},this._addDefaultMeta(t),this.write(t),this);let[r]=n;if(typeof r==`object`&&r&&!(t&&t.match&&t.match(m))){let i=Object.assign({},this.defaultMeta,r,{[a]:e,[o]:n,level:e,message:t});return r.message&&(i.message=`${i.message} ${r.message}`),r.stack&&(i.stack=r.stack),r.cause&&(i.cause=r.cause),this.write(i),this}return this.write(Object.assign({},this.defaultMeta,{[a]:e,[o]:n,level:e,message:t})),this}_transform(e,t,n){if(this.silent)return n();e[a]||(e[a]=e.level),!this.levels[e[a]]&&this.levels[e[a]]!==0&&console.error(`[winston] Unknown logger level: %s`,e[a]),this._readableState.pipes||console.error(`[winston] Attempt to write logs with no transports, which can increase memory usage: %j`,e);try{this.push(this.format.transform(e,this.format.options))}finally{this._writableState.sync=!1,n()}}_final(e){i(this.transports.slice(),(e,t)=>{if(!e||e.finished)return setImmediate(t);e.once(`finish`,t),e.end()},e)}add(e){let t=!s(e)||e.log.length>2?new u({transport:e}):e;if(!t._writableState||!t._writableState.objectMode)throw Error(`Transports must WritableStreams in objectMode. Set { objectMode: true }.`);return this._onEvent(`error`,t),this._onEvent(`warn`,t),this.pipe(t),e.handleExceptions&&this.exceptions.handle(),e.handleRejections&&this.rejections.handle(),this}remove(e){if(!e)return this;let t=e;return(!s(e)||e.log.length>2)&&(t=this.transports.filter(t=>t.transport===e)[0]),t&&this.unpipe(t),this}clear(){return this.unpipe(),this}close(){return this.exceptions.unhandle(),this.rejections.unhandle(),this.clear(),this.emit(`close`),this}setLevels(){f.deprecated(`setLevels`)}query(e,t){typeof e==`function`&&(t=e,e={}),e||={};let n={},r=Object.assign({},e.query||{});function a(t,n){e.query&&typeof t.formatQuery==`function`&&(e.query=t.formatQuery(r)),t.query(e,(r,i)=>{if(r)return n(r);typeof t.formatResults==`function`&&(i=t.formatResults(i,e.format)),n(null,i)})}function o(e,t){a(e,(r,i)=>{t&&(i=r||i,i&&(n[e.name]=i),t()),t=null})}i(this.transports.filter(e=>!!e.query),o,()=>t(null,n))}stream(e={}){let t=new n,r=[];return t._streams=r,t.destroy=()=>{let e=r.length;for(;e--;)r[e].destroy()},this.transports.filter(e=>!!e.stream).forEach(n=>{let i=n.stream(e);i&&(r.push(i),i.on(`log`,e=>{e.transport=e.transport||[],e.transport.push(n.name),t.emit(`log`,e)}),i.on(`error`,e=>{e.transport=e.transport||[],e.transport.push(n.name),t.emit(`error`,e)}))}),t}startTimer(){return new d(this)}profile(e,...t){let n=Date.now();if(this.profilers[e]){let r=this.profilers[e];delete this.profilers[e],typeof t[t.length-2]==`function`&&(console.warn(`Callback function no longer supported as of winston@3.0.0`),t.pop());let i=typeof t[t.length-1]==`object`?t.pop():{};return i.level=i.level||`info`,i.durationMs=n-r,i.message=i.message||e,this.write(i)}return this.profilers[e]=n,this}handleExceptions(...e){console.warn(`Deprecated: .handleExceptions() will be removed in winston@4. Use .exceptions.handle()`),this.exceptions.handle(...e)}unhandleExceptions(...e){console.warn(`Deprecated: .unhandleExceptions() will be removed in winston@4. Use .exceptions.unhandle()`),this.exceptions.unhandle(...e)}cli(){throw Error([`Logger.cli() was removed in winston@3.0.0`,`Use a custom winston.formats.cli() instead.`,`See: https://github.com/winstonjs/winston/tree/master/UPGRADE-3.0.md`].join(`
167
167
  `))}_onEvent(e,t){function n(n){e===`error`&&!this.transports.includes(t)&&this.add(t),this.emit(e,n,t)}t[`__winston`+e]||(t[`__winston`+e]=n.bind(this),t.on(e,t[`__winston`+e]))}_addDefaultMeta(e){this.defaultMeta&&Object.assign(e,this.defaultMeta)}};function g(e,t){let n=e[t];return!n&&n!==0?null:n}Object.defineProperty(h.prototype,`transports`,{configurable:!1,enumerable:!0,get(){let{pipes:e}=this._readableState;return Array.isArray(e)?e:[e].filter(Boolean)}}),t.exports=h})),Od=m(((e,t)=>{let{LEVEL:n}=$(),r=hd(),i=Dd(),a=cd()(`winston:create-logger`);function o(e){return`is`+e.charAt(0).toUpperCase()+e.slice(1)+`Enabled`}t.exports=function(e={}){e.levels=e.levels||r.npm.levels;class t extends i{constructor(e){super(e)}}let s=new t(e);return Object.keys(e.levels).forEach(function(e){if(a(`Define prototype method for "%s"`,e),e===`log`){console.warn(`Level "log" not defined: conflicts with the method "log". Use a different level name.`);return}t.prototype[e]=function(...t){let r=this||s;if(t.length===1){let[i]=t,a=i&&i.message&&i||{message:i};return a.level=a[n]=e,r._addDefaultMeta(a),r.write(a),this||s}return t.length===0?(r.log(e,``),r):r.log(e,...t)},t.prototype[o(e)]=function(){return(this||s).isLevelEnabled(e)}}),s}})),kd=m(((e,t)=>{let n=Od();t.exports=class{constructor(e={}){this.loggers=new Map,this.options=e}add(e,t){if(!this.loggers.has(e)){t=Object.assign({},t||this.options);let r=t.transports||this.options.transports;r?t.transports=Array.isArray(r)?r.slice():[r]:t.transports=[];let i=n(t);i.on(`close`,()=>this._delete(e)),this.loggers.set(e,i)}return this.loggers.get(e)}get(e,t){return this.add(e,t)}has(e){return!!this.loggers.has(e)}close(e){if(e)return this._removeLogger(e);this.loggers.forEach((e,t)=>this._removeLogger(t))}_removeLogger(e){this.loggers.has(e)&&(this.loggers.get(e).close(),this._delete(e))}_delete(e){this.loggers.delete(e)}}})),Ad=_(m((e=>{let t=cu(),{warn:n}=lu();e.version=uu().version,e.transports=md(),e.config=hd(),e.addColors=t.levels,e.format=t.format,e.createLogger=Od(),e.Logger=Dd(),e.ExceptionHandler=Cd(),e.RejectionHandler=Td(),e.Container=kd(),e.Transport=ku(),e.loggers=new e.Container;let r=e.createLogger();Object.keys(e.config.npm.levels).concat([`log`,`query`,`stream`,`add`,`remove`,`clear`,`profile`,`startTimer`,`handleExceptions`,`unhandleExceptions`,`handleRejections`,`unhandleRejections`,`configure`,`child`]).forEach(t=>e[t]=(...e)=>r[t](...e)),Object.defineProperty(e,`level`,{get(){return r.level},set(e){r.level=e}}),Object.defineProperty(e,`exceptions`,{get(){return r.exceptions}}),Object.defineProperty(e,`rejections`,{get(){return r.rejections}}),[`exitOnError`].forEach(t=>{Object.defineProperty(e,t,{get(){return r[t]},set(e){r[t]=e}})}),Object.defineProperty(e,`default`,{get(){return{exceptionHandlers:r.exceptionHandlers,rejectionHandlers:r.rejectionHandlers,transports:r.transports}}}),n.deprecated(e,`setLevels`),n.forFunctions(e,`useFormat`,[`cli`]),n.forProperties(e,`useFormat`,[`padLevels`,`stripColors`]),n.forFunctions(e,`deprecated`,[`addRewriter`,`addFilter`,`clone`,`extend`]),n.forProperties(e,`deprecated`,[`emitErrs`,`levelLength`])}))(),1);function jd(e,t){return Ad.createLogger({level:t??n.env.LOG_LEVEL??`info`,defaultMeta:{scope:e},format:Ad.format.combine(Ad.format.timestamp({format:()=>Date.now().toString()}),Ad.format.printf(e=>{let{timestamp:t,level:n,message:r,scope:i,...a}=e,o=Object.keys(a).length>0,s={$:[Number(t),n,i]};return r==null?JSON.stringify(s):JSON.stringify({...s,msg:o?{[r]:a}:r})})),transports:[new Ad.transports.Console]})}var Md=class{type;name;log;dependsOn;constructor(e,t,n){this.name=e,this.type=t,this.log=jd(e),n!=null&&(this.dependsOn=n)}};const Nd=`$SHADOW_PROJECT`,Pd=`$WORKSPACE`;var Fd=class extends Md{constructor(e,t){super(e,Je.Input,t)}resolveBasePaths(e){let t=e.workspaceDir??`~/project`,n=this.resolvePath(t,``,``),r=e.shadowProjectDir??`${Pd}/aindex`;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(`~`)&&(r=r.replace(`~`,o.homedir())),r.includes(Nd)&&(r=r.replace(Nd,n)),r.includes(Pd)&&(r=r.replace(Pd,t)),i.normalize(r)}readAndParseMarkdown(e,t){return Tl(t.readFileSync(e,`utf-8`))}},Id=class extends Md{globalConfigDir;outputFileName;constructor(e,t){super(e,Je.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``}isRelativePath(e){return e.pathKind===R.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:R.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let r;r=e.pathKind===R.Absolute?e.path:this.isRelativePath(e)?i.resolve(e.basePath,e.path):i.resolve(n.cwd(),e.path);let a=t??this.outputFileName;return a?i.join(r,a):r}createRelativePath(e,t,n){return{pathKind:R.Relative,path:e,basePath:t,getDirectoryName:n,getAbsolutePath:()=>i.join(t,e)}}createFileRelativePath(e,t){let n=i.join(e.path,t);return{pathKind:R.Relative,path:n,basePath:e.basePath,getDirectoryName:()=>e.getDirectoryName(),getAbsolutePath:()=>i.join(e.basePath,n)}}getGlobalConfigDir(){return i.join(o.homedir(),this.globalConfigDir)}joinPath(...e){return i.join(...e)}resolvePath(...e){return i.resolve(...e)}dirname(e){return i.dirname(e)}basename(e,t){return i.basename(e,t)}writeFileSync(e,t,n=`utf-8`){r.writeFileSync(e,t,n)}ensureDirectory(e){r.existsSync(e)||r.mkdirSync(e,{recursive:!0})}async writeFile(e,t,n,a){let o=i.dirname(t),s=i.basename(t),c={pathKind:R.Relative,path:s,basePath:o,getDirectoryName:()=>i.basename(o),getAbsolutePath:()=>t};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${a} -> ${t}`),{path:c,success:!0,skipped:!1};try{return this.ensureDirectory(o),r.writeFileSync(t,n,`utf-8`),this.log.info(`Written ${a} -> ${t}`),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${a}: ${t}`),{path:c,success:!1,error:e}}}async writePromptFile(e,t,n,a){let o=this.resolveFullPath(t),s=this.toRelativePath(t);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${a} -> ${o}`),{path:s,success:!0,skipped:!1};try{let e=i.dirname(o);return this.ensureDirectory(e),r.writeFileSync(o,n,`utf-8`),this.log.info(`Written ${a} -> ${o}`),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${a}: ${t}`),{path:s,success:!1,error:e}}}buildMarkdownContent(e,t){return e!=null&&e.length>0?`${e}\n${t}`:t}extractGlobalMemoryContent(e){return e.collectedInputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
168
168
 
169
- `,skipIfEmpty:i=!0,position:a=`before`}=n??{};if(i&&(e==null||e.trim().length===0))return t;let o=e??``;return a===`after`?`${t}${r}${o}`:`${o}${r}${t}`}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length,a=e.dryRun===!0?`[DRY-RUN]`:``;this.log.info(`${a} Write complete: ${n} success, ${r} skipped, ${i} failed`)}},Ld=class{name=`clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`Running clean pipeline`);let i=r(!1),a=await nt(n,i);t.info(`Collected outputs for cleanup`,{projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await rt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i),l=this.deleteFiles(s,t),u=this.deleteDirectories(c,t);return await it(n,i),t.info(`Clean complete: ${l} files, ${u} directories`),{success:!0,filesAffected:l,dirsAffected:u}}async collectDeletionTargets(e,t,n){let r=[],i=[];for(let a of e.outputPlugins){let e=t.get(a.name);if(e?.project){let e=await a.registerProjectOutputFiles?.(n)??[],t=await a.registerProjectOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}if(e?.global){let e=await a.registerGlobalOutputFiles?.(n)??[],t=await a.registerGlobalOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}}return{filesToDelete:r,dirsToDelete:i}}deleteFiles(e,t){let n=0;for(let a of e){let e=i.isAbsolute(a)?a:i.resolve(a);try{r.existsSync(e)&&(r.unlinkSync(e),t.info(`Deleted file: ${e}`),n++)}catch(n){t.warn(`Failed to delete file: ${e}`,{error:n})}}return n}deleteDirectories(e,t){let n=0,a=[...e].sort((e,t)=>t.length-e.length);for(let e of a){let a=i.isAbsolute(e)?e:i.resolve(e);try{r.existsSync(a)&&(r.rmSync(a,{recursive:!0,force:!0}),t.info(`Deleted directory: ${a}`),n++)}catch(e){t.warn(`Failed to delete directory: ${a}`,{error:e})}}return n}},Rd=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`[DRY-RUN] Running clean pipeline`);let i=r(!0),a=await nt(n,i);t.info(`[DRY-RUN] Collected outputs for cleanup`,{projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await rt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i);return this.logDryRunFiles(s,t),this.logDryRunDirectories(c,t),await it(n,i),t.info(`[DRY-RUN] Clean complete: ${s.length} files, ${c.length} directories would be deleted`),{success:!0,filesAffected:s.length,dirsAffected:c.length,message:`Dry-run complete, no files were deleted`}}async collectDeletionTargets(e,t,n){let r=[],i=[];for(let a of e.outputPlugins){let e=t.get(a.name);if(e?.project){let e=await a.registerProjectOutputFiles?.(n)??[],t=await a.registerProjectOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}if(e?.global){let e=await a.registerGlobalOutputFiles?.(n)??[],t=await a.registerGlobalOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}}return{filesToDelete:r,dirsToDelete:i}}logDryRunFiles(e,t){for(let n of e){let e=i.isAbsolute(n)?n:i.resolve(n);t.info(`[DRY-RUN] Would delete file: ${e}`)}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=i.isAbsolute(e)?e:i.resolve(e);t.info(`[DRY-RUN] Would delete directory: ${n}`)}}},zd=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`[DRY-RUN] Running dry-run pipeline`);let i=r(!0),a=await at(n,i),o=await ot(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=n.dirs.length,t.info(`[DRY-RUN] ${e}: ${n.files.length} files, ${n.dirs.length} dirs`);return t.info(`[DRY-RUN] Total: ${s} files, ${c} dirs would be written`),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},Bd=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`Running execute pipeline`);let i=r(!1),a=await at(n,i),o=await ot(n.filter(e=>a.get(e.name)?.project??!0),i),s=0,c=0;for(let e of o.values())s+=e.files.length,c+=e.dirs.length;return t.info(`Execute pipeline complete`,{pluginCount:o.size}),{success:!0,filesAffected:s,dirsAffected:c}}};const Vd=`tnmsc`,Hd=`
169
+ `,skipIfEmpty:i=!0,position:a=`before`}=n??{};if(i&&(e==null||e.trim().length===0))return t;let o=e??``;return a===`after`?`${t}${r}${o}`:`${o}${r}${t}`}shouldSkipDueToPlugin(e,t){let n=e.registeredPluginNames;return n==null?!1:n.includes(t)}async onWriteComplete(e,t){let n=t.files.filter(e=>e.success).length,r=t.files.filter(e=>e.skipped).length,i=t.files.filter(e=>!e.success&&!e.skipped).length,a=e.dryRun===!0?`[DRY-RUN]`:``;this.log.info(`${a} Write complete: ${n} success, ${r} skipped, ${i} failed`)}},Ld=class{name=`clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`Running clean pipeline`);let i=r(!1),a=await nt(n,i);t.info(`Collected outputs for cleanup`,{projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await rt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i),l=this.deleteFiles(s,t),u=this.deleteDirectories(c,t);return await it(n,i),t.info(`Clean complete: ${l} files, ${u} directories`),{success:!0,filesAffected:l,dirsAffected:u}}async collectDeletionTargets(e,t,n){let r=[],i=[];for(let a of e.outputPlugins){let e=t.get(a.name);if(e?.project){let e=await a.registerProjectOutputFiles?.(n)??[],t=await a.registerProjectOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}if(e?.global){let e=await a.registerGlobalOutputFiles?.(n)??[],t=await a.registerGlobalOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}}return{filesToDelete:r,dirsToDelete:i}}deleteFiles(e,t){let n=0;for(let a of e){let e=i.isAbsolute(a)?a:i.resolve(a);try{r.existsSync(e)&&(r.unlinkSync(e),t.info(`Deleted file: ${e}`),n++)}catch(n){t.warn(`Failed to delete file: ${e}`,{error:n})}}return n}deleteDirectories(e,t){let n=0,a=[...e].sort((e,t)=>t.length-e.length);for(let e of a){let a=i.isAbsolute(e)?e:i.resolve(e);try{r.existsSync(a)&&(r.rmSync(a,{recursive:!0,force:!0}),t.info(`Deleted directory: ${a}`),n++)}catch(e){t.warn(`Failed to delete directory: ${a}`,{error:e})}}return n}},Rd=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`[DRY-RUN] Running clean pipeline`);let i=r(!0),a=await nt(n,i);t.info(`[DRY-RUN] Collected outputs for cleanup`,{projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await rt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i);return this.logDryRunFiles(s,t),this.logDryRunDirectories(c,t),await it(n,i),t.info(`[DRY-RUN] Clean complete: ${s.length} files, ${c.length} directories would be deleted`),{success:!0,filesAffected:s.length,dirsAffected:c.length,message:`Dry-run complete, no files were deleted`}}async collectDeletionTargets(e,t,n){let r=[],i=[];for(let a of e.outputPlugins){let e=t.get(a.name);if(e?.project){let e=await a.registerProjectOutputFiles?.(n)??[],t=await a.registerProjectOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}if(e?.global){let e=await a.registerGlobalOutputFiles?.(n)??[],t=await a.registerGlobalOutputDirs?.(n)??[];r.push(...e.map(e=>e.getAbsolutePath())),i.push(...t.map(e=>e.getAbsolutePath()))}}return{filesToDelete:r,dirsToDelete:i}}logDryRunFiles(e,t){for(let n of e){let e=i.isAbsolute(n)?n:i.resolve(n);t.info(`[DRY-RUN] Would delete file: ${e}`)}}logDryRunDirectories(e,t){let n=[...e].sort((e,t)=>t.length-e.length);for(let e of n){let n=i.isAbsolute(e)?e:i.resolve(e);t.info(`[DRY-RUN] Would delete directory: ${n}`)}}},zd=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`[DRY-RUN] Running dry-run pipeline`);let i=r(!0),a=await at(n,i),o=await ot(n.filter(e=>!!(a.get(e.name)?.project??!0)),i),s=0,c=0;for(let[e,n]of o)s+=n.files.length,c+=n.dirs.length,t.info(`[DRY-RUN] ${e}: ${n.files.length} files, ${n.dirs.length} dirs`);return t.info(`[DRY-RUN] Total: ${s} files, ${c} dirs would be written`),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},Bd=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`Running execute pipeline`);let i=r(!1),a=await at(n,i),o=await ot(n.filter(e=>a.get(e.name)?.project??!0),i),s=0,c=0;for(let e of o.values())s+=e.files.length,c+=e.dirs.length;return t.info(`Execute pipeline complete`,{pluginCount:o.size}),{success:!0,filesAffected:s,dirsAffected:c}}};const Vd=`tnmsc`,Hd=`
170
170
  ${Vd} v0.0.6 - Memory Sync CLI
171
171
 
172
172
  Synchronize AI memory and configuration files across projects.
@@ -193,5 +193,5 @@ CONFIGURATION:
193
193
  `.trim();var Ud=class{name=`help`;async execute(e){return console.log(Hd),{success:!0,filesAffected:0,dirsAffected:0,message:`Help displayed`}}};const Wd=`.tnmsc.json`,Gd=`.aindex`;var Kd=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Wd,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=jd(`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(),Gd,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 config from: ${t}`),{config:n,source:t,found:!0}}catch(e){let n=e instanceof Error?e.message:String(e);return this.logger.warn(`Failed to load config from ${t}: ${n}`),{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`,`shadowProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowSourceProjectDir`])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(`Config validation warnings in ${t}:\n - ${r.join(`
194
194
  - `)}`),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 qd=null;function Jd(e){return(e||!qd)&&(qd=new Kd(e)),qd}function Yd(e){return Jd().load(e)}const Xd={USER_HOME:`~`,WORKSPACE:`$WORKSPACE`,SHADOW_PROJECT:`$SHADOW_PROJECT`},Zd=`~/project`,Qd=`aindex`,$d=`$SHADOW_PROJECT/dist/skills`,ef=`$SHADOW_PROJECT/dist/commands`,tf=`$SHADOW_PROJECT/dist/agents`,nf=`$SHADOW_PROJECT/ref`,rf=`$SHADOW_PROJECT/dist/GLOBAL.md`;function af(e,t,n){let r=e;return r=r.replace(Xd.SHADOW_PROJECT,n),r=r.replace(Xd.WORKSPACE,t),r.startsWith(`~`)&&(r=i.join(o.homedir(),r.slice(1))),i.normalize(r)}var of=class{name=`init`;async execute(e){let{logger:t}=e;t.info(`Initializing directory structure...`);let n=Yd().config,a=af(n.workspaceDir??Zd,``,``),o=af(n.shadowProjectDir??`${Xd.WORKSPACE}/${Qd}`,a,``),s=af(n.shadowSkillSourceDir??$d,a,o),c=af(n.shadowFastCommandDir??ef,a,o),l=af(n.shadowSubAgentDir??tf,a,o),u=af(n.shadowSourceProjectDir??nf,a,o),d=af(n.globalMemoryFile??rf,a,o),f=[{path:a,name:`workspace`},{path:o,name:`shadow project`},{path:s,name:`skills`},{path:c,name:`commands`},{path:l,name:`agents`},{path:u,name:`ref`}],p=0,m=0,h=0,g=0;for(let e of f)r.existsSync(e.path)?(t.info(`${e.name} directory already exists: ${e.path}`),m++):(r.mkdirSync(e.path,{recursive:!0}),t.info(`Created ${e.name} directory: ${e.path}`),p++);let _=i.dirname(d);r.existsSync(_)||(r.mkdirSync(_,{recursive:!0}),p++),r.existsSync(d)?(t.info(`Global memory file already exists: ${d}`),g++):(r.writeFileSync(d,`# Global Memory
195
195
 
196
- `,`utf-8`),t.info(`Created global memory file: ${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}}};function sf(e){let t=[...e],n=t[0];n!=null&&cf(n)&&t.shift();let r=t[0];return r!=null&&lf(r)&&t.shift(),t}function cf(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 lf(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}function uf(e){let t={help:!1,clean:!1,dryRun:!1,init:!1,positional:[],unknown:[]};for(let n=0;n<e.length;n++){let r=e[n];if(r!=null){if(r===`--`){t.positional.push(...e.slice(n+1).filter(e=>e!=null));break}if(r.startsWith(`--`)){switch(r.slice(2).split(`=`)[0]??``){case`help`:t.help=!0;break;case`clean`:t.clean=!0;break;case`dry-run`:t.dryRun=!0;break;case`init`:t.init=!0;break;default:t.unknown.push(r)}continue}if(r.startsWith(`-`)&&r.length>1){let e=r.slice(1);for(let n of e)switch(n){case`h`:t.help=!0;break;case`c`:t.clean=!0;break;case`n`:t.dryRun=!0;break;case`i`:t.init=!0;break;default:t.unknown.push(`-${n}`)}continue}t.positional.push(r)}}return t}var df=class{logger;args;outputPlugins=[];constructor(...e){this.logger=jd(`PluginPipeline`),this.args=uf(sf(e.filter(e=>e!=null))),this.logger.info(`PluginPipeline 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(){let{help:e,clean:t,dryRun:n,init:r}=this.args;return e?new Ud:r?new of:t&&n?new Rd:t?new Ld:n?new zd:new Bd}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:qe.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:qe.default,collectedInputContext:e,dryRun:t}}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 tt(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 et(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.globalMemory??e.globalMemory,l=t.shadowProjectDir??e.shadowProjectDir;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?{}:{globalMemory:c},...l==null?{}:{shadowProjectDir:l}}}};const ff={workspaceDir:Zd,shadowProjectDir:`$WORKSPACE/${Qd}`,shadowSkillSourceDir:$d,shadowFastCommandDir:ef,shadowSubAgentDir:tf,globalMemoryFile:rf,shadowSourceProjectDir:nf,externalProjects:[],excludePatterns:{},plugins:[],logLevel:`info`};function pf(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.logLevel==null?{}:{logLevel:e.logLevel}}}function mf(...e){return e.reduce((e,t)=>hf(e,t),{...ff})}function hf(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:gf(e.excludePatterns,i)}}function gf(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function _f(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function vf(e={}){let t,n,a;_f(e)?(t=e.pluginOptions??{},n=e.loadUserConfig??!0,a=e.cwd):(t=e,n=!0);let o={};if(n){let e=Yd(a);e.found&&(o=pf(e.config),jd(`defineConfig`,t.logLevel??e.config.logLevel).debug(`Loaded config from: ${e.sources.join(`, `)}`))}let{plugins:s=[],logLevel:c}=mf(o,t),l={logger:jd(`defineConfig`,c),userConfigOptions:t,fs:r,path:i,glob:qe.default},u=s.filter(e=>e.type===Je.Input),d=s.filter(e=>e.type===Je.Output),f=new df().executePluginsInOrder(u,l);if(f.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:f.workspace,ideConfigFiles:f.ideConfigFiles??[],...f.externalProjects!=null&&{externalProjects:f.externalProjects},...f.fastCommands!=null&&{fastCommands:f.fastCommands},...f.subAgents!=null&&{subAgents:f.subAgents},...f.skills!=null&&{skills:f.skills},...f.globalMemory!=null&&{globalMemory:f.globalMemory}},outputPlugins:d}}const yf=`AGENTS.md`;var bf=class extends Id{constructor(){super(`AgentsOutputPlugin`,{outputFileName:yf})}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,yf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,yf));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 xf=`CLAUDE.md`,Sf=`.claude`,Cf=`commands`,wf=`agents`,Tf=`skills`,Ef=[Cf,wf,Tf];var Df=class extends Id{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:Sf,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 Ef){let r=i.join(e.dirFromWorkspacePath.path,Sf,n);t.push({pathKind:R.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,xf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,xf));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:R.Relative,path:xf,basePath:n,getDirectoryName:()=>Sf,getAbsolutePath:()=>i.join(n,xf)}]}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,xf),c={pathKind:R.Relative,path:xf,basePath:o,getDirectoryName:()=>Sf,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=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Sf,Cf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,Sf,Cf,o),basePath:t.basePath,getDirectoryName:()=>Cf,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written fast command -> ${c}`),a.push({path:l,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:l,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,Sf,wf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,Sf,wf,o),basePath:t.basePath,getDirectoryName:()=>wf,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,Sf,Tf,o),c=i.join(s,`SKILL.md`),l={pathKind:R.Relative,path:i.join(t.path,Sf,Tf,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:R.Relative,path:i.join(o.path,Sf,Tf,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 Of=`AGENTS.md`,kf=`.factory`,Af=`commands`,jf=`agents`,Mf=`skills`,Nf=[Af,jf,Mf];var Pf=class extends Id{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:kf,outputFileName:Of})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Nf){let r=i.join(e.dirFromWorkspacePath.path,kf,n);t.push({pathKind:R.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:R.Relative,path:Of,basePath:n,getDirectoryName:()=>kf,getAbsolutePath:()=>i.join(n,Of)}]}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,Of),c={pathKind:R.Relative,path:Of,basePath:o,getDirectoryName:()=>kf,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=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,kf,Af),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,kf,Af,o),basePath:t.basePath,getDirectoryName:()=>Af,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written fast command -> ${c}`),a.push({path:l,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:l,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,kf,jf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,kf,jf,o),basePath:t.basePath,getDirectoryName:()=>jf,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,kf,Mf,o),c=i.join(s,`SKILL.md`),l={pathKind:R.Relative,path:i.join(t.path,kf,Mf,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:R.Relative,path:i.join(o.path,kf,Mf,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}},Ff=class extends Fd{constructor(){super(`FileSystemFastCommandPlugin`)}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??ef,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=Tl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter;s.push({type:Ye.FastCommand,content:i,length:i.length,filePathKind:R.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:R.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t}})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}},If=class extends Fd{constructor(){super(`FileSystemGlobalMemoryPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??rf,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Tl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:Ye.GlobalMemory,content:t,length:t.length,filePathKind:R.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:$e.UserHome,directory:{pathKind:R.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},Lf=class extends Fd{constructor(){super(`FileSystemIdeConfigPlugin`)}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=z.Original;e.includes(`.vscode`)?a=z.VSCode:e.includes(`.idea`)?a=z.IntellijIDEA:e.includes(`.editorconfig`)&&(a=z.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:R.Absolute,dir:{pathKind:R.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const Rf=`AGENTS.md`;var zf=class extends Fd{constructor(){super(`FileSystemProjectPromptPlugin`,[`FileSystemShadowProjectPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowSourceProjectDir??nf,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,Rf);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Tl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:Ye.ProjectRootMemory,content:t,length:t.length,filePathKind:R.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.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,Rf);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,Rf);try{let e=Tl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:Ye.ProjectChildrenMemory,content:o,length:o.length,filePathKind:R.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:R.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}},Bf=class extends Fd{constructor(){super(`FileSystemShadowProjectPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSourceProjectDir??nf,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)t.isDirectory()&&l.push({name:t.name,dirFromWorkspacePath:{pathKind:R.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 at ${c}`,{error:e})}return{workspace:{directory:{pathKind:R.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:l}}}},Vf=class extends Fd{constructor(){super(`FileSystemSkillPlugin`)}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??$d,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 n of t)if(n.isDirectory()){let t=e.path.join(s,n.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let r=Tl(e.fs.readFileSync(t,`utf-8`)),a=r.contentWithoutFrontMatter;c.push({type:Ye.Skill,content:a,length:a.length,filePathKind:R.Relative,yamlFrontMatter:r.yamlFrontMatter??{name:n.name,description:``},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:R.Relative,path:n.name,basePath:s,getDirectoryName:()=>n.name,getAbsolutePath:()=>i.join(s,n.name)}})}}}catch(e){n.error(`Failed to scan skills at ${s}`,{error:e})}return{skills:c}}},Hf=class extends Fd{constructor(){super(`FileSystemSubAgentPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??tf,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=Tl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:Ye.SubAgent,content:a,length:a.length,filePathKind:R.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:R.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}}},Uf=class extends Fd{constructor(){super(`FileSystemWorkspacePlugin`)}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:R.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:R.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowProjectDir:r,...a.length>0&&{externalProjects:a}}}};const Wf=`GEMINI.md`,Gf=`.gemini`;var Kf=class extends Id{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:Gf,outputFileName:Wf})}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,Wf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Wf));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:R.Relative,path:Wf,basePath:n,getDirectoryName:()=>Gf,getAbsolutePath:()=>i.join(n,Wf)}]}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,Wf),c={pathKind:R.Relative,path:Wf,basePath:o,getDirectoryName:()=>Gf,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}}};const qf=`.idea`,Jf=`codeStyles`;var Yf=class extends Id{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{shadowProjectDir:r}=e.collectedInputContext;for(let e of n){let n=e.dirFromWorkspacePath;if(n==null||r!=null&&n.getAbsolutePath().startsWith(r))continue;let i={pathKind:R.Relative,path:this.joinPath(n.path,qf,Jf),basePath:n.basePath,getDirectoryName:()=>Jf,getAbsolutePath:()=>this.resolvePath(n.basePath,n.path,qf,Jf)};t.push(i)}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===z.IntellijIDEA||e.type===z.EditorConfig)?!0:(this.log.info(`No JetBrains IDE config files found, skipping`),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===z.IntellijIDEA||e.type===z.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:R.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${r} -> ${a}`),{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 ${r} -> ${a}`),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${r}: ${t}`),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===z.EditorConfig)return`.editorconfig`;if(e.type===z.IntellijIDEA){let e=t.indexOf(qf);return e===-1?this.joinPath(qf,Jf,this.basename(t)):t.substring(e)}return this.basename(t)}};const Xf=`GLOBAL.md`,Zf=`.kiro`,Qf=`steering`;var $f=class extends Id{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:Zf,outputFileName:Xf})}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,Zf,Qf);t.push({pathKind:R.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Qf,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,Zf,Qf,r);t.push({pathKind:R.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Qf,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir();return[{pathKind:R.Relative,path:Qf,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>Qf,getAbsolutePath:()=>t}]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalSteeringDir();return[{pathKind:R.Relative,path:Xf,basePath:n,getDirectoryName:()=>Qf,getAbsolutePath:()=>this.joinPath(n,Xf)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>(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)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}=e.collectedInputContext,n=[],r=[];if(t==null)return this.log.info(`No global memory found, skipping global output`),{files:n,dirs:r};let i=this.getGlobalSteeringDir(),a=this.joinPath(i,Xf),o={pathKind:R.Relative,path:Xf,basePath:i,getDirectoryName:()=>Qf,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write global memory -> ${a}`),{files:[{path:o,success:!0,skipped:!1}],dirs:r};try{this.ensureDirectory(i),this.writeFileSync(a,t.content),this.log.info(`Written global memory -> ${a}`),n.push({path:o,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:o,success:!1,error:e})}return{files:n,dirs:r}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),Qf)}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,Zf,Qf),o=this.joinPath(a,i),s={pathKind:R.Relative,path:this.joinPath(r.path,Zf,Qf,i),basePath:r.basePath,getDirectoryName:()=>Qf,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 ep=`WARP.md`;var tp=class extends Id{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:ep})}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,ep)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,ep));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{workspace:t}=e.collectedInputContext,{projects:n}=t,r=[],i=[],a=this.extractGlobalMemoryContent(e);for(let t of n){let n=t.name??`unknown`,i=t.dirFromWorkspacePath;if(i!=null){if(t.rootMemoryPrompt!=null){let o=this.combineGlobalWithContent(a,t.rootMemoryPrompt.content),s=await this.writePromptFile(e,i,o,`project:${n}/root`);r.push(s)}if(t.childMemoryPrompts!=null)for(let i of t.childMemoryPrompts){let t=await this.writePromptFile(e,i.dir,i.content,`project:${n}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);r.push(t)}}}return{files:r,dirs:i}}};const np=`.vscode`;var rp=class extends Id{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{shadowProjectDir:r}=e.collectedInputContext;for(let e of n){let n=e.dirFromWorkspacePath;if(n==null||r!=null&&n.getAbsolutePath().startsWith(r))continue;let i={pathKind:R.Relative,path:this.joinPath(n.path,np),basePath:n.basePath,getDirectoryName:()=>np,getAbsolutePath:()=>this.resolvePath(n.basePath,n.path,np)};t.push(i)}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===z.VSCode)?!0:(this.log.info(`No VS Code config files found, skipping`),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===z.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:R.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${r} -> ${a}`),{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 ${r} -> ${a}`),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${r}: ${t}`),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===z.VSCode){let e=t.indexOf(np);return e===-1?this.joinPath(np,this.basename(t)):t.substring(e)}return this.basename(t)}},ip=vf({plugins:[new bf,new Df,new Pf,new Kf,new $f,new tp,new Yf,new rp,new Uf,new Bf,new Lf,new Vf,new Ff,new Hf,new If,new zf]}),ap=ip;async function op(){await new df(...n.argv).run(ip)}op().catch(e=>{console.error(e)});export{Fd as AbstractInputPlugin,Id as AbstractOutputPlugin,Md as AbstractPlugin,et as CircularDependencyError,Xe as ClaudeCodeCLISubAgentColors,Ze as CodingAgentTools,Kd as ConfigLoader,Wd as DEFAULT_CONFIG_FILE_NAME,Gd as DEFAULT_GLOBAL_CONFIG_DIR,rf as DEFAULT_GLOBAL_MEMORY_FILE,ef as DEFAULT_SHADOW_FAST_COMMAND_DIR,Qd as DEFAULT_SHADOW_PROJECT_SUFFIX,$d as DEFAULT_SHADOW_SKILL_SOURCE_DIR,nf as DEFAULT_SHADOW_SOURCE_PROJECT_DIR,tf as DEFAULT_SHADOW_SUB_AGENT_DIR,Zd as DEFAULT_WORKSPACE_DIR,R as FilePathKind,$e as GlobalConfigDirectoryType,z as IDEKind,tt as MissingDependencyError,Qe as NamingCaseKind,Xd as PathPlaceholders,Je as PluginKind,Ye as PromptKind,rt as checkCanClean,at as checkCanWrite,nt as collectAllPluginOutputs,jd as createLogger,ap as default,vf as defineConfig,it as executeOnCleanComplete,ot as executeWriteOutputs,Jd as getConfigLoader,Yd as loadUserConfig,mf as mergeConfig};
196
+ `,`utf-8`),t.info(`Created global memory file: ${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}}};function sf(e){let t=[...e],n=t[0];n!=null&&cf(n)&&t.shift();let r=t[0];return r!=null&&lf(r)&&t.shift(),t}function cf(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 lf(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}function uf(e){let t={help:!1,clean:!1,dryRun:!1,init:!1,positional:[],unknown:[]};for(let n=0;n<e.length;n++){let r=e[n];if(r!=null){if(r===`--`){t.positional.push(...e.slice(n+1).filter(e=>e!=null));break}if(r.startsWith(`--`)){switch(r.slice(2).split(`=`)[0]??``){case`help`:t.help=!0;break;case`clean`:t.clean=!0;break;case`dry-run`:t.dryRun=!0;break;case`init`:t.init=!0;break;default:t.unknown.push(r)}continue}if(r.startsWith(`-`)&&r.length>1){let e=r.slice(1);for(let n of e)switch(n){case`h`:t.help=!0;break;case`c`:t.clean=!0;break;case`n`:t.dryRun=!0;break;case`i`:t.init=!0;break;default:t.unknown.push(`-${n}`)}continue}t.positional.push(r)}}return t}var df=class{logger;args;outputPlugins=[];constructor(...e){this.logger=jd(`PluginPipeline`),this.args=uf(sf(e.filter(e=>e!=null))),this.logger.info(`PluginPipeline 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(){let{help:e,clean:t,dryRun:n,init:r}=this.args;return e?new Ud:r?new of:t&&n?new Rd:t?new Ld:n?new zd:new Bd}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:qe.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:qe.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 tt(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 et(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.globalMemory??e.globalMemory,l=t.shadowProjectDir??e.shadowProjectDir;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?{}:{globalMemory:c},...l==null?{}:{shadowProjectDir:l}}}};const ff={workspaceDir:Zd,shadowProjectDir:`$WORKSPACE/${Qd}`,shadowSkillSourceDir:$d,shadowFastCommandDir:ef,shadowSubAgentDir:tf,globalMemoryFile:rf,shadowSourceProjectDir:nf,externalProjects:[],excludePatterns:{},plugins:[],logLevel:`info`};function pf(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.logLevel==null?{}:{logLevel:e.logLevel}}}function mf(...e){return e.reduce((e,t)=>hf(e,t),{...ff})}function hf(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:gf(e.excludePatterns,i)}}function gf(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function _f(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function vf(e={}){let t,n,a;_f(e)?(t=e.pluginOptions??{},n=e.loadUserConfig??!0,a=e.cwd):(t=e,n=!0);let o={};if(n){let e=Yd(a);e.found&&(o=pf(e.config),jd(`defineConfig`,t.logLevel??e.config.logLevel).debug(`Loaded config from: ${e.sources.join(`, `)}`))}let{plugins:s=[],logLevel:c}=mf(o,t),l={logger:jd(`defineConfig`,c),userConfigOptions:t,fs:r,path:i,glob:qe.default},u=s.filter(e=>e.type===Je.Input),d=s.filter(e=>e.type===Je.Output),f=new df().executePluginsInOrder(u,l);if(f.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:f.workspace,ideConfigFiles:f.ideConfigFiles??[],...f.externalProjects!=null&&{externalProjects:f.externalProjects},...f.fastCommands!=null&&{fastCommands:f.fastCommands},...f.subAgents!=null&&{subAgents:f.subAgents},...f.skills!=null&&{skills:f.skills},...f.globalMemory!=null&&{globalMemory:f.globalMemory}},outputPlugins:d}}const yf=`AGENTS.md`;var bf=class extends Id{constructor(){super(`AgentsOutputPlugin`,{outputFileName:yf})}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,yf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,yf));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 xf=`CLAUDE.md`,Sf=`.claude`,Cf=`commands`,wf=`agents`,Tf=`skills`,Ef=[Cf,wf,Tf];var Df=class extends Id{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:Sf,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 Ef){let r=i.join(e.dirFromWorkspacePath.path,Sf,n);t.push({pathKind:R.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,xf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,xf));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:R.Relative,path:xf,basePath:n,getDirectoryName:()=>Sf,getAbsolutePath:()=>i.join(n,xf)}]}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,xf),c={pathKind:R.Relative,path:xf,basePath:o,getDirectoryName:()=>Sf,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=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Sf,Cf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,Sf,Cf,o),basePath:t.basePath,getDirectoryName:()=>Cf,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written fast command -> ${c}`),a.push({path:l,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:l,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,Sf,wf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,Sf,wf,o),basePath:t.basePath,getDirectoryName:()=>wf,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,Sf,Tf,o),c=i.join(s,`SKILL.md`),l={pathKind:R.Relative,path:i.join(t.path,Sf,Tf,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:R.Relative,path:i.join(o.path,Sf,Tf,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 Of=`AGENTS.md`,kf=`.factory`,Af=`commands`,jf=`agents`,Mf=`skills`,Nf=[Af,jf,Mf];var Pf=class extends Id{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:kf,outputFileName:Of})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Nf){let r=i.join(e.dirFromWorkspacePath.path,kf,n);t.push({pathKind:R.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:R.Relative,path:Of,basePath:n,getDirectoryName:()=>kf,getAbsolutePath:()=>i.join(n,Of)}]}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,Of),c={pathKind:R.Relative,path:Of,basePath:o,getDirectoryName:()=>kf,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=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,kf,Af),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,kf,Af,o),basePath:t.basePath,getDirectoryName:()=>Af,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write fast command -> ${c}`),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.info(`Written fast command -> ${c}`),a.push({path:l,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:l,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,kf,jf),c=i.join(s,o),l={pathKind:R.Relative,path:i.join(t.path,kf,jf,o),basePath:t.basePath,getDirectoryName:()=>jf,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,kf,Mf,o),c=i.join(s,`SKILL.md`),l={pathKind:R.Relative,path:i.join(t.path,kf,Mf,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:R.Relative,path:i.join(o.path,kf,Mf,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}},Ff=class extends Fd{constructor(){super(`FileSystemFastCommandPlugin`)}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??ef,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=Tl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter;s.push({type:Ye.FastCommand,content:i,length:i.length,filePathKind:R.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:R.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t}})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}},If=class extends Fd{constructor(){super(`FileSystemGlobalMemoryPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??rf,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Tl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:Ye.GlobalMemory,content:t,length:t.length,filePathKind:R.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:$e.UserHome,directory:{pathKind:R.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},Lf=class extends Fd{constructor(){super(`FileSystemIdeConfigPlugin`)}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=z.Original;e.includes(`.vscode`)?a=z.VSCode:e.includes(`.idea`)?a=z.IntellijIDEA:e.includes(`.editorconfig`)&&(a=z.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:R.Absolute,dir:{pathKind:R.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const Rf=`AGENTS.md`;var zf=class extends Fd{constructor(){super(`FileSystemProjectPromptPlugin`,[`FileSystemShadowProjectPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowSourceProjectDir??nf,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,Rf);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Tl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:Ye.ProjectRootMemory,content:t,length:t.length,filePathKind:R.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.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,Rf);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,Rf);try{let e=Tl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:Ye.ProjectChildrenMemory,content:o,length:o.length,filePathKind:R.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:R.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:R.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}},Bf=class extends Fd{constructor(){super(`FileSystemShadowProjectPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSourceProjectDir??nf,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)t.isDirectory()&&l.push({name:t.name,dirFromWorkspacePath:{pathKind:R.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 at ${c}`,{error:e})}return{workspace:{directory:{pathKind:R.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:l}}}},Vf=class extends Fd{constructor(){super(`FileSystemSkillPlugin`)}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??$d,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 n of t)if(n.isDirectory()){let t=e.path.join(s,n.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let r=Tl(e.fs.readFileSync(t,`utf-8`)),a=r.contentWithoutFrontMatter;c.push({type:Ye.Skill,content:a,length:a.length,filePathKind:R.Relative,yamlFrontMatter:r.yamlFrontMatter??{name:n.name,description:``},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:R.Relative,path:n.name,basePath:s,getDirectoryName:()=>n.name,getAbsolutePath:()=>i.join(s,n.name)}})}}}catch(e){n.error(`Failed to scan skills at ${s}`,{error:e})}return{skills:c}}},Hf=class extends Fd{constructor(){super(`FileSystemSubAgentPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??tf,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=Tl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:Ye.SubAgent,content:a,length:a.length,filePathKind:R.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:R.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}}},Uf=class extends Fd{constructor(){super(`FileSystemWorkspacePlugin`)}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:R.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:R.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowProjectDir:r,...a.length>0&&{externalProjects:a}}}};const Wf=`GEMINI.md`,Gf=`.gemini`;var Kf=class extends Id{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:Gf,outputFileName:Wf})}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,Wf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Wf));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:R.Relative,path:Wf,basePath:n,getDirectoryName:()=>Gf,getAbsolutePath:()=>i.join(n,Wf)}]}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,Wf),c={pathKind:R.Relative,path:Wf,basePath:o,getDirectoryName:()=>Gf,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}}};const qf=`.idea`;var Jf=class extends Id{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===z.IntellijIDEA||e.type===z.EditorConfig)?!0:(this.log.info(`No JetBrains IDE config files found, skipping`),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===z.IntellijIDEA||e.type===z.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:R.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${r} -> ${a}`),{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 ${r} -> ${a}`),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${r}: ${t}`),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===z.EditorConfig)return`.editorconfig`;if(e.type===z.IntellijIDEA){let e=t.indexOf(qf);return e===-1?this.joinPath(qf,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const Yf=`GLOBAL.md`,Xf=`.kiro`,Zf=`steering`;var Qf=class extends Id{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:Xf,outputFileName:Yf})}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,Xf,Zf);t.push({pathKind:R.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Zf,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,Xf,Zf,r);t.push({pathKind:R.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>Zf,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir();return[{pathKind:R.Relative,path:Zf,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>Zf,getAbsolutePath:()=>t}]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalSteeringDir();return[{pathKind:R.Relative,path:Yf,basePath:n,getDirectoryName:()=>Zf,getAbsolutePath:()=>this.joinPath(n,Yf)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>(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)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}=e.collectedInputContext,n=[],r=[];if(t==null)return this.log.info(`No global memory found, skipping global output`),{files:n,dirs:r};let i=this.getGlobalSteeringDir(),a=this.joinPath(i,Yf),o={pathKind:R.Relative,path:Yf,basePath:i,getDirectoryName:()=>Zf,getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write global memory -> ${a}`),{files:[{path:o,success:!0,skipped:!1}],dirs:r};try{this.ensureDirectory(i),this.writeFileSync(a,t.content),this.log.info(`Written global memory -> ${a}`),n.push({path:o,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:o,success:!1,error:e})}return{files:n,dirs:r}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),Zf)}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,Xf,Zf),o=this.joinPath(a,i),s={pathKind:R.Relative,path:this.joinPath(r.path,Xf,Zf,i),basePath:r.basePath,getDirectoryName:()=>Zf,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 $f=`WARP.md`;var ep=class extends Id{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:$f})}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,$f)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,$f));return t}async canWrite(e){if(`registeredPluginNames`in e&&e.registeredPluginNames!=null&&Array.from(e.registeredPluginNames).includes(`AgentsOutputPlugin`))return this.log.info(`Skipping WARP.md output, AgentsOutputPlugin is registered`),!1;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{workspace:t}=e.collectedInputContext,{projects:n}=t,r=[],i=[],a=this.extractGlobalMemoryContent(e);for(let t of n){let n=t.name??`unknown`,i=t.dirFromWorkspacePath;if(i!=null){if(t.rootMemoryPrompt!=null){let o=this.combineGlobalWithContent(a,t.rootMemoryPrompt.content),s=await this.writePromptFile(e,i,o,`project:${n}/root`);r.push(s)}if(t.childMemoryPrompts!=null)for(let i of t.childMemoryPrompts){let t=await this.writePromptFile(e,i.dir,i.content,`project:${n}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);r.push(t)}}}return{files:r,dirs:i}}};const tp=`.vscode`;var np=class extends Id{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===z.VSCode)?!0:(this.log.info(`No VS Code config files found, skipping`),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===z.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:R.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.info(`[DRY-RUN] Would write ${r} -> ${a}`),{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 ${r} -> ${a}`),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`Failed to write ${r}: ${t}`),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===z.VSCode){let e=t.indexOf(tp);return e===-1?this.joinPath(tp,this.basename(t)):t.substring(e)}return this.basename(t)}},rp=vf({plugins:[new bf,new Df,new Pf,new Kf,new Qf,new ep,new Jf,new np,new Uf,new Bf,new Lf,new Vf,new Ff,new Hf,new If,new zf]}),ip=rp;async function ap(){await new df(...n.argv).run(rp)}ap().catch(e=>{console.error(e)});export{Fd as AbstractInputPlugin,Id as AbstractOutputPlugin,Md as AbstractPlugin,et as CircularDependencyError,Xe as ClaudeCodeCLISubAgentColors,Ze as CodingAgentTools,Kd as ConfigLoader,Wd as DEFAULT_CONFIG_FILE_NAME,Gd as DEFAULT_GLOBAL_CONFIG_DIR,rf as DEFAULT_GLOBAL_MEMORY_FILE,ef as DEFAULT_SHADOW_FAST_COMMAND_DIR,Qd as DEFAULT_SHADOW_PROJECT_SUFFIX,$d as DEFAULT_SHADOW_SKILL_SOURCE_DIR,nf as DEFAULT_SHADOW_SOURCE_PROJECT_DIR,tf as DEFAULT_SHADOW_SUB_AGENT_DIR,Zd as DEFAULT_WORKSPACE_DIR,R as FilePathKind,$e as GlobalConfigDirectoryType,z as IDEKind,tt as MissingDependencyError,Qe as NamingCaseKind,Xd as PathPlaceholders,Je as PluginKind,Ye as PromptKind,rt as checkCanClean,at as checkCanWrite,nt as collectAllPluginOutputs,jd as createLogger,ip as default,vf as defineConfig,it as executeOnCleanComplete,ot as executeWriteOutputs,Jd as getConfigLoader,Yd as loadUserConfig,mf 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.9",
4
+ "version": "0.0.11",
5
5
  "description": "TrueNine Life CLI Tools",
6
6
  "author": "TrueNine",
7
7
  "license": "UNLICENSED",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@clack/prompts": "^0.11.0",
35
35
  "fast-glob": "^3.3.3",
36
- "fs-extra": "^11.3.2",
36
+ "fs-extra": "^11.3.3",
37
37
  "picocolors": "^1.1.1",
38
38
  "picomatch": "^4.0.3",
39
39
  "remark-frontmatter": "^5.0.0",
@@ -52,8 +52,8 @@
52
52
  "@types/picomatch": "^4.0.2",
53
53
  "@vitest/coverage-v8": "4.0.16",
54
54
  "eslint": "^9.39.2",
55
- "fast-check": "^4.4.0",
56
- "tsdown": "0.18.1",
55
+ "fast-check": "^4.5.1",
56
+ "tsdown": "0.18.2",
57
57
  "tsx": "^4.21.0",
58
58
  "typescript": "^5.9.3",
59
59
  "vite": "^7.3.0",