@truenine/memory-sync-cli 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -18
- package/dist/index.mjs +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TrueNine Life CLI
|
|
2
2
|
|
|
3
|
-
Cross-
|
|
3
|
+
Cross-AI programming tool prompt synchronisation utility. One ruleset, multi-platform adaptation.
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
@@ -8,28 +8,28 @@ Cross-platform prompt sync tool for AI coding assistants. One ruleset, multi-tar
|
|
|
8
8
|
npx @truenine/memory-sync-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Global
|
|
11
|
+
## Global Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
pnpm add -g @truenine/memory-sync-cli
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
## Update
|
|
17
|
+
## Update Version
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
pnpm update -g @truenine/memory-sync-cli --latest
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
After installation, use directly:
|
|
23
|
+
After installation, use the command directly:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
tnmsc
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Available
|
|
29
|
+
Available features:
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
#
|
|
32
|
+
# Direct sync
|
|
33
33
|
tnmsc
|
|
34
34
|
|
|
35
35
|
# Get help
|
|
@@ -37,7 +37,15 @@ tnmsc help
|
|
|
37
37
|
tnmsc --help
|
|
38
38
|
tnmsc -h
|
|
39
39
|
|
|
40
|
-
#
|
|
40
|
+
# View version
|
|
41
|
+
tnmsc version
|
|
42
|
+
tnmsc --version
|
|
43
|
+
tnmsc -v
|
|
44
|
+
|
|
45
|
+
# Check for updates
|
|
46
|
+
tnmsc outdated
|
|
47
|
+
|
|
48
|
+
# Initialise directory and file structure based on config file and defaults
|
|
41
49
|
tnmsc init
|
|
42
50
|
|
|
43
51
|
# Preview export
|
|
@@ -50,25 +58,28 @@ tnmsc clean
|
|
|
50
58
|
tnmsc clean --dry-run
|
|
51
59
|
tnmsc clean -n
|
|
52
60
|
|
|
61
|
+
# Set config options
|
|
62
|
+
tnmsc set key=value
|
|
63
|
+
tnmsc --set key=value
|
|
64
|
+
|
|
53
65
|
# Set log level
|
|
66
|
+
tnmsc --trace
|
|
54
67
|
tnmsc --debug
|
|
55
68
|
tnmsc --info
|
|
56
69
|
tnmsc --warn
|
|
57
70
|
tnmsc --error
|
|
58
|
-
tnmsc clean --info
|
|
59
|
-
tnmsc dry-run --debug
|
|
60
|
-
tnmsc clean dry-run --info
|
|
61
71
|
```
|
|
62
72
|
|
|
63
|
-
## CLI
|
|
73
|
+
## CLI Configuration
|
|
64
74
|
|
|
65
|
-
|
|
75
|
+
Configuration can be created in two locations. Example below shows default config:
|
|
66
76
|
|
|
67
77
|
```text
|
|
68
78
|
~/.aindex/.tnmsc.json
|
|
69
79
|
cwd()/.tnmsc.json
|
|
70
80
|
```
|
|
71
|
-
> cwd() represents current
|
|
81
|
+
> cwd() represents the current command execution directory.
|
|
82
|
+
|
|
72
83
|
|
|
73
84
|
```json
|
|
74
85
|
{
|
|
@@ -83,7 +94,24 @@ cwd()/.tnmsc.json
|
|
|
83
94
|
"excludePatterns": {},
|
|
84
95
|
"logLevel": "info"
|
|
85
96
|
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### SET Available Config Options
|
|
86
100
|
|
|
101
|
+
- `workspaceDir` - Workspace directory
|
|
102
|
+
- `shadowSourceProjectDir` - Shadow source project directory
|
|
103
|
+
- `shadowSkillSourceDir` - Skill source directory
|
|
104
|
+
- `shadowFastCommandDir` - Fast command directory
|
|
105
|
+
- `shadowSubAgentDir` - Sub-agent directory
|
|
106
|
+
- `globalMemoryFile` - Global memory file
|
|
107
|
+
- `shadowProjectsDir` - Shadow projects directory
|
|
108
|
+
- `logLevel` - Log level (trace/debug/info/warn/error)
|
|
109
|
+
|
|
110
|
+
Example:
|
|
111
|
+
```bash
|
|
112
|
+
tnmsc --set workspaceDir=~/my-project
|
|
113
|
+
tnmsc --set logLevel=debug
|
|
114
|
+
tnmsc set workspaceDir=~/workspace
|
|
87
115
|
```
|
|
88
116
|
|
|
89
117
|
## Supported AI Tools
|
|
@@ -108,15 +136,21 @@ cwd()/.tnmsc.json
|
|
|
108
136
|
|
|
109
137
|
## Plugin System
|
|
110
138
|
|
|
111
|
-
|
|
139
|
+
Uses input → transform → output pipeline architecture:
|
|
112
140
|
|
|
113
|
-
- **Input Plugins**: Read
|
|
141
|
+
- **Input Plugins**: Read source files (Aindex, Ref, WorkspaceGroup)
|
|
114
142
|
- **Transform Plugins**: Process content
|
|
115
|
-
- **Output Plugins**: Write target formats (IDE/CLI adapters)
|
|
143
|
+
- **Output Plugins**: Write to target formats (various IDE/CLI adapters)
|
|
144
|
+
|
|
145
|
+
## Configuration
|
|
146
|
+
|
|
147
|
+
Config file priority: `cwd()/.tnmsc.json` > `~/.aindex/.tnmsc.json`
|
|
148
|
+
|
|
149
|
+
## Created by
|
|
116
150
|
|
|
117
|
-
|
|
151
|
+
- [Truenine](https://github.com/TrueNine)
|
|
152
|
+
- [zjarlin](https://github.com/zjarlin)
|
|
118
153
|
|
|
119
|
-
Priority: `cwd()/.tnmsc.json` > `~/.aindex/.tnmsc.json`
|
|
120
154
|
|
|
121
155
|
## License
|
|
122
156
|
|
package/dist/index.mjs
CHANGED
|
@@ -153,7 +153,7 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
153
153
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
154
154
|
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;case`space`:case`comment`:default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Ul=g((e=>{var t=Fl(),n=vl(),r=yl(),i=Uc(),a=Y(),o=Vl(),s=Hl();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Wl=y(g((e=>{var t=Fl(),n=vl(),r=gl(),i=yl(),a=Fc(),o=Y(),s=Kc(),c=X(),l=Jc(),u=Xc();zl();var d=Bl(),f=Vl(),p=Hl(),m=Ul(),h=kc();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync}))(),1);function Gl(e){let t=yc().use(rc).use(ms).use(tn,[`yaml`]).parse(e),n,r,i=[];for(let e of t.children)if(e.type===`yaml`){let t=e;r=t.value;try{n=Wl.parse(t.value)}catch{}}else i.push(e);let a=e;return r!=null&&(a=e.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``)),{...n!=null&&{yamlFrontMatter:n},...r!=null&&{rawFrontMatter:r},markdownAst:t,markdownContents:i,contentWithoutFrontMatter:a}}let Kl;function ql(e){Kl=e}function Jl(){return Kl}const Yl={error:l.red,warn:l.yellow,info:l.cyan,debug:l.magenta,trace:l.gray,fatal:l.bgRed},Xl={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};function Zl(e){return e===null?l.dim(`null`):e===void 0?l.dim(`undefined`):typeof e==`boolean`?l.yellow(String(e)):typeof e==`number`?l.blue(String(e)):typeof e==`string`?l.green(`"${e}"`):Array.isArray(e)?e.length===0?`[]`:`[${e.map(e=>Zl(e)).join(`,`)}]`:typeof e==`object`?Ql(e):String(e)}function Ql(e){let t=Object.entries(e);return t.length===0?`{}`:`{${t.map(([e,t])=>`${/^[\w$]+$/.test(e)?l.magenta(e):l.yellow(`"${e}"`)}:${Zl(t)}`).join(`,`)}}`}function $l(){let e=new Date;return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}:${String(e.getSeconds()).padStart(2,`0`)}.${String(e.getMilliseconds()).padStart(3,`0`)}`}function eu(e,t,n,r){let i=$l(),a=Yl[e]??l.white,o={$:[i,e,t],_:r!=null&&Object.keys(r).length>0?{[String(n)]:r}:n},s={$:[i,a(e.toUpperCase()),t]},c=r!=null&&Object.keys(r).length>0?{[String(n)]:r}:n,u=Ql({...s,_:c});return console.log(u),o}function tu(e,t,n){let r=Xl[e],i=Xl[n];return(n,...a)=>r>i?{$:[$l(),e,t],_:n}:typeof n==`string`?eu(e,t,n,a.length===1&&typeof a[0]==`object`&&a[0]!==null?a[0]:a.length>0?{args:a}:void 0):typeof n==`object`&&n?eu(e,t,``,n):eu(e,t,n)}function nu(e,t){let r=t??Kl??n.env.LOG_LEVEL??`info`;return{error:tu(`error`,e,r),warn:tu(`warn`,e,r),info:tu(`info`,e,r),debug:tu(`debug`,e,r),trace:tu(`trace`,e,r),fatal:tu(`fatal`,e,r)}}var ru=class{type;name;_log;get log(){return this._log??=nu(this.name),this._log}dependsOn;constructor(e,t,n){this.name=e,this.type=t,n!=null&&(this.dependsOn=n)}},iu=class extends ru{constructor(e,t){super(e,ut.Input,t)}resolveBasePaths(e){let t=e.workspaceDir??bt,n=this.resolvePath(t,``,``),r=e.shadowSourceProjectDir??`${yt.WORKSPACE}/${xt}`;return{workspaceDir:n,shadowProjectDir:this.resolvePath(r,n,``)}}resolvePath(e,t,n){let r=e;return r.startsWith(yt.USER_HOME)&&(r=r.replace(yt.USER_HOME,o.homedir())),r.includes(yt.SHADOW_SOURCE_PROJECT)&&(r=r.replace(yt.SHADOW_SOURCE_PROJECT,n)),r.includes(yt.WORKSPACE)&&(r=r.replace(yt.WORKSPACE,t)),i.normalize(r)}readAndParseMarkdown(e,t){return Gl(t.readFileSync(e,`utf-8`))}},Z=class extends ru{globalConfigDir;outputFileName;registryWriterCache=new Map;constructor(e,t){super(e,ut.Output,t?.dependsOn),this.globalConfigDir=t?.globalConfigDir??``,this.outputFileName=t?.outputFileName??``}isRelativePath(e){return e.pathKind===P.Relative}toRelativePath(e){return this.isRelativePath(e)?e:{pathKind:P.Relative,path:e.path,basePath:``,getDirectoryName:e.getDirectoryName,getAbsolutePath:()=>e.path}}resolveFullPath(e,t){let r;r=e.pathKind===P.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:P.Relative,path:e,basePath:t,getDirectoryName:n,getAbsolutePath:()=>i.join(t,e)}}createFileRelativePath(e,t){let n=i.join(e.path,t);return{pathKind:P.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:P.Relative,path:s,basePath:o,getDirectoryName:()=>i.basename(o),getAbsolutePath:()=>t};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`file`,path:t,label:a}),{path:c,success:!0,skipped:!1};try{return this.ensureDirectory(o),r.writeFileSync(t,n,`utf-8`),this.log.trace({action:`write`,type:`file`,path:t,label:a}),{path:c,success:!0}}catch(e){let n=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`file`,path:t,label:a,error:n}),{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.trace({action:`dryRun`,type:`promptFile`,path:o,label:a}),{path:s,success:!0,skipped:!1};try{let e=i.dirname(o);return this.ensureDirectory(e),r.writeFileSync(o,n,`utf-8`),this.log.trace({action:`write`,type:`promptFile`,path:o,label:a}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`promptFile`,path:o,label:a,error:t}),{path:s,success:!1,error:e}}}buildMarkdownContent(e,t){return e!=null&&e.length>0?`---\n${e}\n---\n${t}`:t}extractGlobalMemoryContent(e){return e.collectedInputContext.globalMemory?.content}combineGlobalWithContent(e,t,n){let{separator:r=`
|
|
155
155
|
|
|
156
|
-
`,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`_`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,n=t?.pluginOverrides?.[this.name],r=n?.includeSeriesPrefix??t?.includeSeriesPrefix,i=n?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}getTransformOptionsFromContext(e,t){let n=this.getFastCommandSeriesOptions(e),r=n.includeSeriesPrefix??t?.includeSeriesPrefix,i=n.seriesSeparator??t?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}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;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i})}getRegistryWriter(e){let t=e.name,n=this.registryWriterCache.get(t);if(n!=null)return n;let r=new e(this.log);return this.registryWriterCache.set(t,r),r}async registerInRegistry(e,t,n){return e.register(t,n.dryRun)}},au=class{registryPath;log;constructor(e,t){this.registryPath=this.resolvePath(e),this.log=t??nu(this.constructor.name)}resolvePath(e){return e.startsWith(`~`)?i.join(o.homedir(),e.slice(1)):i.resolve(e)}getRegistryDir(){return i.dirname(this.registryPath)}ensureRegistryDir(){let e=this.getRegistryDir();r.existsSync(e)||r.mkdirSync(e,{recursive:!0})}read(){if(!r.existsSync(this.registryPath))return this.log.debug(`registry not found`,{path:this.registryPath}),this.createInitialRegistry();try{let e=r.readFileSync(this.registryPath,`utf-8`);return JSON.parse(e)}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`parse failed`,{path:this.registryPath,error:t}),this.createInitialRegistry()}}write(e,t){let n={...e,lastUpdated:new Date().toISOString()};if(t===!0)return this.log.trace({action:`dryRun`,type:`registry`,path:this.registryPath}),!0;let i=`${this.registryPath}.tmp.${Date.now()}`;try{this.ensureRegistryDir();let e=JSON.stringify(n,null,2);return r.writeFileSync(i,e,`utf-8`),r.renameSync(i,this.registryPath),this.log.trace({action:`write`,type:`registry`,path:this.registryPath}),!0}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`registry`,path:this.registryPath,error:t});try{r.existsSync(i)&&r.unlinkSync(i)}catch{}return!1}}register(e,t){let n=[],r=this.read(),i=this.merge(r,e),a=this.write(i,t);for(let r of e){let e=this.getEntryName(r);a?(n.push({success:!0,entryName:e}),t===!0?this.log.trace({action:`dryRun`,type:`registerEntry`,entryName:e}):this.log.trace({action:`register`,type:`entry`,entryName:e})):(n.push({success:!1,entryName:e,error:Error(`Failed to write registry file`)}),this.log.error(`register entry failed`,{entryName:e}))}return n}generateEntryId(e){let t=`${Date.now()}-${Math.random().toString(36).substring(2,8)}`;return e==null?t:`${e}-${t}`}},ou=class e extends au{static REGISTRY_PATH=`~/.kiro/powers/registry.json`;static DEFAULT_VERSION=`1.0.0`;constructor(t){super(e.REGISTRY_PATH,t)}createInitialRegistry(){return{version:e.DEFAULT_VERSION,powers:{},repoSources:{},lastUpdated:new Date().toISOString()}}getEntryName(e){return e.name}merge(e,t){let n={...e.powers},r={...e.repoSources};for(let e of t){n[e.name]=e;let t=this.buildRepoSource(e),i=e.source.repoId??e.name;r[i]=t}return{version:e.version,powers:n,repoSources:r,...e.kiroRecommendedRepo!=null&&{kiroRecommendedRepo:e.kiroRecommendedRepo},lastUpdated:e.lastUpdated}}buildPowerEntry(e,t){let{yamlFrontMatter:n}=e,r={type:`repo`,repoId:this.generateEntryId(`local`),repoName:t};return{name:n.name,description:n.description,...n.author!=null&&{author:n.author},keywords:n.keywords??[],...n.displayName!=null&&{displayName:n.displayName},installed:!0,installedAt:new Date().toISOString(),installPath:t,source:r,sourcePath:t}}buildRepoSource(e){let t=new Date().toISOString();return{name:e.sourcePath??e.installPath??e.name,type:`local`,enabled:!0,addedAt:t,powerCount:1,...e.sourcePath!=null&&{path:e.sourcePath},lastSync:t}}},su=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`dry-run-clean`,dryRun:!0});let i=r(!0),a=await et(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await tt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i);return this.logDryRunFiles(s,t),this.logDryRunDirectories(c,t),await nt(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:s.length,dirsAffected:c.length}),{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(`would delete file`,{path:e,dryRun:!0})}}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(`would delete directory`,{path:n,dryRun:!0})}}},cu=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`started`,{command:`dry-run-output`,dryRun:!0});let i=r(!0),a=await rt(n,i),o=await it(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(`plugin result`,{plugin:e,files:n.files.length,dirs:n.dirs.length,dryRun:!0});return t.info(`complete`,{command:`dry-run-output`,totalFiles:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},lu=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await ct(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await rt(n,o),c=await it(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function uu(){return`1.0.
|
|
156
|
+
`,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}`}transformFastCommandName(e,t){let{includeSeriesPrefix:n=!0,seriesSeparator:r=`_`}=t??{};return!n||e.series==null?`${e.commandName}.md`:`${e.series}${r}${e.commandName}.md`}getFastCommandSeriesOptions(e){let t=e.pluginOptions?.fastCommandSeriesOptions,n=t?.pluginOverrides?.[this.name],r=n?.includeSeriesPrefix??t?.includeSeriesPrefix,i=n?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}getTransformOptionsFromContext(e,t){let n=this.getFastCommandSeriesOptions(e),r=n.includeSeriesPrefix??t?.includeSeriesPrefix,i=n.seriesSeparator??t?.seriesSeparator;return r!=null&&i!=null?{includeSeriesPrefix:r,seriesSeparator:i}:r==null?i==null?{}:{seriesSeparator:i}:{includeSeriesPrefix:r}}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;this.log.trace({action:e.dryRun===!0?`dryRun`:`complete`,type:`writeSummary`,success:n,skipped:r,failed:i})}getRegistryWriter(e){let t=e.name,n=this.registryWriterCache.get(t);if(n!=null)return n;let r=new e(this.log);return this.registryWriterCache.set(t,r),r}async registerInRegistry(e,t,n){return e.register(t,n.dryRun)}},au=class{registryPath;log;constructor(e,t){this.registryPath=this.resolvePath(e),this.log=t??nu(this.constructor.name)}resolvePath(e){return e.startsWith(`~`)?i.join(o.homedir(),e.slice(1)):i.resolve(e)}getRegistryDir(){return i.dirname(this.registryPath)}ensureRegistryDir(){let e=this.getRegistryDir();r.existsSync(e)||r.mkdirSync(e,{recursive:!0})}read(){if(!r.existsSync(this.registryPath))return this.log.debug(`registry not found`,{path:this.registryPath}),this.createInitialRegistry();try{let e=r.readFileSync(this.registryPath,`utf-8`);return JSON.parse(e)}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error(`parse failed`,{path:this.registryPath,error:t}),this.createInitialRegistry()}}write(e,t){let n={...e,lastUpdated:new Date().toISOString()};if(t===!0)return this.log.trace({action:`dryRun`,type:`registry`,path:this.registryPath}),!0;let i=`${this.registryPath}.tmp.${Date.now()}`;try{this.ensureRegistryDir();let e=JSON.stringify(n,null,2);return r.writeFileSync(i,e,`utf-8`),r.renameSync(i,this.registryPath),this.log.trace({action:`write`,type:`registry`,path:this.registryPath}),!0}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`registry`,path:this.registryPath,error:t});try{r.existsSync(i)&&r.unlinkSync(i)}catch{}return!1}}register(e,t){let n=[],r=this.read(),i=this.merge(r,e),a=this.write(i,t);for(let r of e){let e=this.getEntryName(r);a?(n.push({success:!0,entryName:e}),t===!0?this.log.trace({action:`dryRun`,type:`registerEntry`,entryName:e}):this.log.trace({action:`register`,type:`entry`,entryName:e})):(n.push({success:!1,entryName:e,error:Error(`Failed to write registry file`)}),this.log.error(`register entry failed`,{entryName:e}))}return n}generateEntryId(e){let t=`${Date.now()}-${Math.random().toString(36).substring(2,8)}`;return e==null?t:`${e}-${t}`}},ou=class e extends au{static REGISTRY_PATH=`~/.kiro/powers/registry.json`;static DEFAULT_VERSION=`1.0.0`;constructor(t){super(e.REGISTRY_PATH,t)}createInitialRegistry(){return{version:e.DEFAULT_VERSION,powers:{},repoSources:{},lastUpdated:new Date().toISOString()}}getEntryName(e){return e.name}merge(e,t){let n={...e.powers},r={...e.repoSources};for(let e of t){n[e.name]=e;let t=this.buildRepoSource(e),i=e.source.repoId??e.name;r[i]=t}return{version:e.version,powers:n,repoSources:r,...e.kiroRecommendedRepo!=null&&{kiroRecommendedRepo:e.kiroRecommendedRepo},lastUpdated:e.lastUpdated}}buildPowerEntry(e,t){let{yamlFrontMatter:n}=e,r={type:`repo`,repoId:this.generateEntryId(`local`),repoName:t};return{name:n.name,description:n.description,...n.author!=null&&{author:n.author},keywords:n.keywords??[],...n.displayName!=null&&{displayName:n.displayName},installed:!0,installedAt:new Date().toISOString(),installPath:t,source:r,sourcePath:t}}buildRepoSource(e){let t=new Date().toISOString();return{name:e.sourcePath??e.installPath??e.name,type:`local`,enabled:!0,addedAt:t,powerCount:1,...e.sourcePath!=null&&{path:e.sourcePath},lastSync:t}}},su=class{name=`dry-run-clean`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r}=e;t.info(`running clean pipeline`,{command:`dry-run-clean`,dryRun:!0});let i=r(!0),a=await et(n,i);t.info(`collected outputs for cleanup`,{dryRun:!0,projectDirs:a.projectDirs.length,projectFiles:a.projectFiles.length,globalDirs:a.globalDirs.length,globalFiles:a.globalFiles.length});let o=await tt(n,i),{filesToDelete:s,dirsToDelete:c}=await this.collectDeletionTargets(e,o,i);return this.logDryRunFiles(s,t),this.logDryRunDirectories(c,t),await nt(n,i),t.info(`clean complete`,{dryRun:!0,filesAffected:s.length,dirsAffected:c.length}),{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(`would delete file`,{path:e,dryRun:!0})}}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(`would delete directory`,{path:n,dryRun:!0})}}},cu=class{name=`dry-run-output`;async execute(e){let{logger:t,outputPlugins:n,createWriteContext:r}=e;t.info(`started`,{command:`dry-run-output`,dryRun:!0});let i=r(!0),a=await rt(n,i),o=await it(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(`plugin result`,{plugin:e,files:n.files.length,dirs:n.dirs.length,dryRun:!0});return t.info(`complete`,{command:`dry-run-output`,totalFiles:s,totalDirs:c,dryRun:!0}),{success:!0,filesAffected:s,dirsAffected:c,message:`Dry-run complete, no files were written`}}},lu=class{name=`execute`;async execute(e){let{logger:t,outputPlugins:n,createCleanContext:r,createWriteContext:i}=e;t.info(`started`,{command:`execute`});let a=await ct(n,r(!1),t,{executeHooks:!1});t.info(`cleanup complete`,{deletedFiles:a.deletedFiles,deletedDirs:a.deletedDirs});let o=i(!1),s=await rt(n,o),c=await it(n.filter(e=>s.get(e.name)?.project??!0),o),l=0,u=0;for(let e of c.values())l+=e.files.length,u+=e.dirs.length;return t.info(`complete`,{command:`execute`,pluginCount:c.size}),{success:!0,filesAffected:l,dirsAffected:u}}};function uu(){return`1.0.5`}var du=class{name=`version`;async execute(e){return e.logger.error(`tnmsc v${uu()}`),{success:!0,filesAffected:0,dirsAffected:0,message:`Version displayed`}}};const Q=`tnmsc`,fu=`
|
|
157
157
|
${Q} v${uu()} - Memory Sync CLI
|
|
158
158
|
|
|
159
159
|
Synchronize AI memory and configuration files across projects.
|
|
@@ -162,6 +162,7 @@ USAGE:
|
|
|
162
162
|
${Q} Run the sync pipeline (default)
|
|
163
163
|
${Q} help Show this help message
|
|
164
164
|
${Q} version Show version information
|
|
165
|
+
${Q} outdated Check for version updates
|
|
165
166
|
${Q} init Initialize directories and files
|
|
166
167
|
${Q} dry-run Preview what would be written
|
|
167
168
|
${Q} clean Remove all generated files
|
|
@@ -172,6 +173,7 @@ USAGE:
|
|
|
172
173
|
SUBCOMMANDS:
|
|
173
174
|
help Show this help message
|
|
174
175
|
version Show version information
|
|
176
|
+
outdated Check if CLI version is outdated against npm registry
|
|
175
177
|
init Initialize directory structure based on configuration
|
|
176
178
|
dry-run Preview changes without writing files
|
|
177
179
|
clean Remove all generated output files and directories
|
|
@@ -256,8 +258,8 @@ Thumbs.db
|
|
|
256
258
|
|
|
257
259
|
# Logs
|
|
258
260
|
*.log
|
|
259
|
-
`}function Du(e,t,n){let r=e;return r=r.replace(yt.SHADOW_SOURCE_PROJECT,n),r=r.replace(yt.WORKSPACE,t),r.startsWith(`~`)&&(r=i.join(o.homedir(),r.slice(1))),i.normalize(r)}var Ou=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Du(n.workspaceDir,``,``),i=yu(Du(n.shadowSourceProjectDir,r,``),{logger:t}),a=i.createdDirs.length===0&&i.createdFiles.length===0?`All ${i.existedDirs.length} directories and ${i.existedFiles.length} files already exist`:`Created ${i.createdDirs.length} directories and ${i.createdFiles.length} files (${i.existedDirs.length} dirs, ${i.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:i.createdDirs.length,filesCreated:i.createdFiles.length,dirsExisted:i.existedDirs.length,filesExisted:i.existedFiles.length}),{success:i.success,filesAffected:i.createdFiles.length,dirsAffected:i.createdDirs.length,message:a}}};const ku=`.tnmsc.json`,Au=`.aindex`;function ju(){return i.join(o.homedir(),Au,ku)}function Mu(){return{workspaceDir:bt,shadowSourceProjectDir:`$WORKSPACE/${xt}`,shadowSkillSourceDir:St,shadowFastCommandDir:Ct,shadowSubAgentDir:wt,globalMemoryFile:Et,shadowProjectsDir:Tt,logLevel:`info`}}function Nu(e,t){let n=ju(),a=i.dirname(n);r.existsSync(a)||r.mkdirSync(a,{recursive:!0}),r.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf-8`),t.info(`global config created`,{path:n})}var Pu=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??ku,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=nu(`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(),Au,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!r.existsSync(t))return{config:{},source:null,found:!1};let e=r.readFileSync(t,`utf-8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=n.cwd()){let t=this.getSearchPaths(e),r=[];for(let e of t){let t=this.loadFromFile(e);t.found&&r.push(t)}return{config:this.mergeConfigs(r.map(e=>e.config)),sources:r.map(e=>e.source).filter(e=>e!==null),found:r.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?i.join(o.homedir(),e.slice(1)):e}};let Fu=null;function Iu(e){return(e||!Fu)&&(Fu=new Pu(e)),Fu}function Lu(e){return Iu().load(e)}function Ru(){let e=nu(`ConfigLoader`),t=ju();if(!r.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),Nu(Mu(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=r.readFileSync(t,`utf-8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),Bu(t,e,[`Failed to read config: ${r}`])}let i;try{i=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),Bu(t,e,[`Invalid JSON: ${r}`])}if(typeof i!=`object`||!i||Array.isArray(i))return e.error(`global config must be a JSON object`,{path:t}),Bu(t,e,[`Config must be a JSON object`]);let a=zu(i);if(a.length>0){for(let n of a)e.error(`config validation error`,{path:t,error:n});return Bu(t,e,a)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function zu(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}return t}function Bu(e,t,n){try{r.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return Nu(Mu(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const Vu=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function Hu(e){return Vu.includes(e)}function Uu(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function Wu(){return i.join(o.homedir(),Au,ku)}function Gu(){let e=Wu();if(!r.existsSync(e))return{};try{let t=r.readFileSync(e,`utf-8`);return JSON.parse(t)}catch{return{}}}function Ku(e){let t=Wu(),n=i.dirname(t);r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`)}var qu=class{name=`set`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc --set key=value or tnmsc set key=value`),t.info(`Valid keys: ${Vu.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=Gu(),r=[],i=[];for(let[e,a]of this.options){if(!Hu(e)){r.push(`Invalid key: ${e} (valid keys: ${Vu.join(`, `)})`);continue}if(e===`logLevel`&&!Uu(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(Ku(n),t.info(`global config written`,{path:Wu()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},Ju=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};function Yu(e){let t=[...e],n=t[0];n!=null&&Xu(n)&&t.shift();let r=t[0];return r!=null&&Zu(r)&&t.shift(),t}function Xu(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 Zu(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}const Qu=new Set([`help`,`version`,`init`,`dry-run`,`clean`,`set`]),$u=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),ed=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function td(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=ed.get(n)??4;for(let e of t){let t=ed.get(e)??4;t<r&&(r=t,n=e)}return n}function nd(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new du;if(t)return new pu;if(a!=null)return new Ju(a);if(r===`version`)return new du;if(r===`help`)return new pu;if(r===`init`)return new Ou;if(r===`dry-run`)return new cu;if(r===`clean`)return i?new su:new lt;if(r===`set`||o.length>0){let e=[];for(let t of s){let n=t.indexOf(`=`);n>0&&e.push([t.slice(0,n),t.slice(n+1)])}return new qu([...o,...e])}return new lu}function rd(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=$u.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,Qu.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var id=class{logger;args;outputPlugins=[];constructor(...e){this.args=rd(Yu(e.filter(e=>e!=null)));let t=td(this.args);t!=null&&ql(t),this.logger=nu(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return nd(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new _t(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length!==e.length)throw new gt(this.findCyclePath(e,n));return a}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a[a.length-1]);return a.slice(e)}i.clear(),a.length=0}return Array.from(n)}executePluginsInOrder(e,t){if(e.length===0)return{};let n=this.topologicalSort(e),r=new Map,i={};for(let e of n){let n=this.buildDependencyContext(e,r),a={...t,dependencyContext:n},o=e.collect(a);r.set(e.name,o),i=this.mergeContexts(i,o)}return i}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let n=e.workspace;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:Array.from(e.values())}}else n=t.workspace;let r=t.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts];return{...n==null?{}:{workspace:n},...r==null?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d}}}};const ad={workspaceDir:bt,shadowSourceProjectDir:`$WORKSPACE/${xt}`,shadowSkillSourceDir:St,shadowFastCommandDir:Ct,shadowSubAgentDir:wt,globalMemoryFile:Et,shadowProjectsDir:Tt,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[],logLevel:`info`};function od(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function sd(...e){return e.reduce((e,t)=>cd(e,t),{...ad})}function cd(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:ld(e.excludePatterns,i),fastCommandSeriesOptions:ud(e.fastCommandSeriesOptions,a)}}function ld(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function ud(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function dd(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function fd(e={}){Ru().shouldExit&&n.exit(1);let t,a,o;dd(e)?(t=e.pluginOptions??{},a=e.loadUserConfig??!0,o=e.cwd):(t=e,a=!0);let s={},c=!1,l=[];if(a){let e=Lu(o);c=e.found,l=e.sources,e.found&&(s=od(e.config))}let u=sd(s,t),{plugins:d=[],logLevel:f}=u,p=nu(`defineConfig`,f);c?p.info(`user config loaded`,{sources:l}):p.info(`no user config found, using defaults`,{workspaceDir:ad.workspaceDir,shadowSourceProjectDir:ad.shadowSourceProjectDir,shadowSkillSourceDir:ad.shadowSkillSourceDir,shadowFastCommandDir:ad.shadowFastCommandDir,shadowSubAgentDir:ad.shadowSubAgentDir,globalMemoryFile:ad.globalMemoryFile,shadowProjectsDir:ad.shadowProjectsDir,logLevel:ad.logLevel});let m={logger:p,userConfigOptions:u,fs:r,path:i,glob:$e.default},h=d.filter(e=>e.type===ut.Input),g=d.filter(e=>e.type===ut.Output),_=new id().executePluginsInOrder(h,m);if(_.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:_.workspace,ideConfigFiles:_.ideConfigFiles??[],..._.externalProjects!=null&&{externalProjects:_.externalProjects},..._.fastCommands!=null&&{fastCommands:_.fastCommands},..._.subAgents!=null&&{subAgents:_.subAgents},..._.skills!=null&&{skills:_.skills},..._.globalMemory!=null&&{globalMemory:_.globalMemory},..._.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:_.aiAgentIgnoreConfigFiles},..._.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:_.shadowSourceProjectDir},..._.readmePrompts!=null&&{readmePrompts:_.readmePrompts}},outputPlugins:g,userConfigOptions:u}}const pd=`AGENTS.md`;var md=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:pd})}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,pd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,pd));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}};const hd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var gd=class extends iu{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of hd){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf-8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const _d=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var vd=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.isPromptSourceProject!==!0)for(let n of _d){let r=i.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>i.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,a){let o=i.join(t.path,n.fileName),s=i.join(t.basePath,o),c={pathKind:P.Relative,path:o,basePath:t.basePath,getDirectoryName:()=>i.basename(t.path),getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0,skipped:!1};try{return r.writeFileSync(s,n.content,`utf-8`),this.log.trace({action:`write`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:s,label:a,error:t}),{path:c,success:!1,error:e}}}};const yd=`CLAUDE.md`,bd=`.claude`,xd=`commands`,Sd=`agents`,Cd=`skills`,wd=[xd,Sd,Cd];var Td=class extends Z{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:bd,outputFileName:yd})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of wd){let r=i.join(e.dirFromWorkspacePath.path,bd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,yd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,yd));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:yd,basePath:n,getDirectoryName:()=>bd,getAbsolutePath:()=>i.join(n,yd)}]}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=(r?.length??0)>0,l=(i?.length??0)>0,u=(a?.length??0)>0;return!o&&!s&&!c&&!l&&!u?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.name??`unknown`,s=o.dirFromWorkspacePath;if(s!=null){if(o.rootMemoryPrompt!=null){let n=await this.writePromptFile(e,s,o.rootMemoryPrompt.content,`project:${t}/root`);a.push(n)}if(o.childMemoryPrompts!=null)for(let n of o.childMemoryPrompts){let r=await this.writePromptFile(e,n.dir,n.content,`project:${t}/child:${n.workingChildDirectoryPath?.path??`unknown`}`);a.push(r)}if(n!=null)for(let t of n){let n=await this.writeFastCommand(e,s,t);a.push(...n)}if(r!=null)for(let t of r){let n=await this.writeSubAgent(e,s,t);a.push(...n)}if(i!=null)for(let t of i){let n=await this.writeSkill(e,s,t);a.push(...n)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,yd),c={pathKind:P.Relative,path:yd,basePath:o,getDirectoryName:()=>bd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,bd,xd),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,bd,xd,s),basePath:t.basePath,getDirectoryName:()=>xd,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,bd,Sd),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,bd,Sd,o),basePath:t.basePath,getDirectoryName:()=>Sd,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,bd,Cd,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,bd,Cd,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,bd,Cd,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Ed=`AGENTS.md`,Dd=`.codex`,Od=`prompts`,kd=`skills`,Ad=`SKILL.md`;var jd=class extends Z{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:Dd,outputFileName:Ed,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(e){return[]}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=i.join(t,Od);n.push({pathKind:P.Relative,path:Od,basePath:t,getDirectoryName:()=>Od,getAbsolutePath:()=>r});let{skills:a}=e.collectedInputContext;if(a!=null&&a.length>0)for(let e of a){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),a=i.join(t,kd,r);n.push({pathKind:P.Relative,path:i.join(kd,r),basePath:t,getDirectoryName:()=>r,getAbsolutePath:()=>a})}return n}async registerGlobalOutputFiles(e){let t=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Ed,basePath:t,getDirectoryName:()=>Dd,getAbsolutePath:()=>i.join(t,Ed)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=t!=null,a=(n?.length??0)>0,o=(r?.length??0)>0;return!i&&!a&&!o?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:a}=e.collectedInputContext,o=[],s=[];if(t!=null){let n=this.getGlobalConfigDir(),a=i.join(n,Ed),s={pathKind:P.Relative,path:Ed,basePath:n,getDirectoryName:()=>Dd,getAbsolutePath:()=>a};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:a}),o.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(n),r.writeFileSync(a,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:a}),o.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:a,error:t}),o.push({path:s,success:!1,error:e})}}if(n!=null&&n.length>0){let t=this.getGlobalConfigDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);o.push(...n)}}if(a!=null&&a.length>0){let t=this.getGlobalConfigDir();for(let n of a){let r=await this.writeGlobalSkill(e,t,n);o.push(...r)}}return{files:o,dirs:s}}async writeGlobalFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t,Od),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(Od,s),basePath:t,getDirectoryName:()=>Od,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`globalFastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalFastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeGlobalSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t,kd,o),c=i.join(s,Ad),l={pathKind:P.Relative,path:i.join(kd,o,Ad),basePath:t,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildCodexSkillContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalSkill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`globalSkill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalSkill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeToSingleLine(t.description,500),r=this.normalizeToSingleLine(t.name,100),i=[`---`];return i.push(`name: ${this.yamlQuoteIfNeeded(r)}`),i.push(`description: ${this.yamlQuoteIfNeeded(n)}`),t.displayName!=null&&(i.push(`metadata:`),i.push(` short-description: ${this.yamlQuoteIfNeeded(t.displayName)}`)),i.push(`---`),`${i.join(`
|
|
260
|
-
`)}\n${e.content}`}normalizeToSingleLine(e,t){let n=e.replace(/[\r\n]+/g,` `).replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}yamlQuoteIfNeeded(e){return/[:[\]{}#&*!|>'"%@`]/.test(e)||/^[\s-]/.test(e)?`"${e.replace(/"/g,`\\"`)}"`:e}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(kd,n,c),basePath:o,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Md=`AGENTS.md`,Nd=`.factory`,Pd=`commands`,Fd=`agents`,Id=`skills`,Ld=[Pd,Fd,Id];var Rd=class extends Z{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:Nd,outputFileName:Md})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Ld){let r=i.join(e.dirFromWorkspacePath.path,Nd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Md,basePath:n,getDirectoryName:()=>Nd,getAbsolutePath:()=>i.join(n,Md)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=t!=null,o=(n?.length??0)>0,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.dirFromWorkspacePath;if(t!=null){if(n!=null)for(let r of n){let n=await this.writeFastCommand(e,t,r);a.push(...n)}if(r!=null)for(let n of r){let r=await this.writeSubAgent(e,t,n);a.push(...r)}if(i!=null)for(let n of i){let r=await this.writeSkill(e,t,n);a.push(...r)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Md),c={pathKind:P.Relative,path:Md,basePath:o,getDirectoryName:()=>Nd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,Nd,Pd),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,Nd,Pd,s),basePath:t.basePath,getDirectoryName:()=>Pd,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Nd,Fd),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,Nd,Fd,o),basePath:t.basePath,getDirectoryName:()=>Fd,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,Nd,Id,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,Nd,Id,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,Nd,Id,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}},zd=class extends iu{constructor(){super(`FastCommandInputPlugin`)}extractSeriesInfo(e){let t=e.replace(/\.md$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.substring(0,n),commandName:t.substring(n+1)}}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??Ct,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=Gl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter,a=this.extractSeriesInfo(n.name);s.push({type:dt.FastCommand,content:i,length:i.length,filePathKind:P.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:P.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t},...a.series!=null&&{series:a.series},commandName:a.commandName})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}};const Bd=`GEMINI.md`,Vd=`.gemini`;var Hd=class extends Z{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:Vd,outputFileName:Bd})}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,Bd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Bd));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Bd,basePath:n,getDirectoryName:()=>Vd,getAbsolutePath:()=>i.join(n,Bd)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)&&n==null?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Bd),c={pathKind:P.Relative,path:Bd,basePath:o,getDirectoryName:()=>Vd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}},Ud=class extends iu{constructor(){super(`GlobalMemoryInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??Et,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Gl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:dt.GlobalMemory,content:t,length:t.length,filePathKind:P.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:ht.UserHome,directory:{pathKind:P.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},Wd=class extends iu{constructor(){super(`IdeConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{shadowProjectDir:i}=this.resolveBasePaths(t),a=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`,`.vscode/settings.json`,`.vscode/extensions.json`],o=[];for(let e of a){let t=r.join(i,e);if(n.existsSync(t)&&n.statSync(t).isFile()){let i=n.readFileSync(t,`utf-8`),a=F.Original;e.includes(`.vscode`)?a=F.VSCode:e.includes(`.idea`)?a=F.IntellijIDEA:e.includes(`.editorconfig`)&&(a=F.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:P.Absolute,dir:{pathKind:P.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const Gd=`.idea`,Kd=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`];var qd=class extends Z{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of Kd){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig)?!0:(this.log.debug(`skipped`,{reason:`no JetBrains IDE config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.EditorConfig)return`.editorconfig`;if(e.type===F.IntellijIDEA){let e=t.indexOf(Gd);return e===-1?this.joinPath(Gd,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const Jd=`GLOBAL.md`,Yd=`.kiro`,$=`steering`,Xd=`POWER.md`;var Zd=class extends Z{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:Yd,outputFileName:Jd})}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,Yd,$);t.push({pathKind:P.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts){let r=this.buildSteeringFileName(n),i=this.joinPath(e.dirFromWorkspacePath.path,Yd,$,r);t.push({pathKind:P.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir(),n=[{pathKind:P.Relative,path:$,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>$,getAbsolutePath:()=>t}],{skills:r}=e.collectedInputContext;if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let r=t.yamlFrontMatter.name,i=this.joinPath(e,r);n.push({pathKind:P.Relative,path:r,basePath:e,getDirectoryName:()=>r,getAbsolutePath:()=>i})}}return n}async registerGlobalOutputFiles(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalSteeringDir();if(t!=null&&i.push({pathKind:P.Relative,path:Jd,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,Jd)}),n!=null)for(let e of n){let t=this.buildFastCommandSteeringFileName(e);i.push({pathKind:P.Relative,path:t,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,t)})}if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let n=t.yamlFrontMatter.name,r=this.joinPath(e,n);if(i.push({pathKind:P.Relative,path:Xd,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(r,Xd)}),t.referenceDocuments!=null){let e=this.joinPath(r,$);for(let n of t.referenceDocuments){let t=n.dir.path;i.push({pathKind:P.Relative,path:this.joinPath($,t),basePath:r,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e,t)})}}}}return i}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,skills:i}=e.collectedInputContext,a=t.projects.some(e=>(e.childMemoryPrompts?.length??0)>0),o=n!=null,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t)if(r.dirFromWorkspacePath!=null&&r.childMemoryPrompts!=null)for(let t of r.childMemoryPrompts){let i=await this.writeSteeringFile(e,r,t);n.push(i)}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=[],o=[];if(t!=null){let n=this.getGlobalSteeringDir(),r=this.joinPath(n,Jd),a={pathKind:P.Relative,path:Jd,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),this.writeFileSync(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),i.push({path:a,success:!1,error:e})}}if(n!=null)for(let t of n){let n=await this.writeFastCommandSteeringFile(e,t);i.push(n)}if(r!=null&&r.length>0){this.log.debug(`Processing ${r.length} skills as Kiro Powers`);for(let t of r){let{fileResults:n,registryResult:r}=await this.writeSkillAsPower(e,t);i.push(...n),o.push(r)}this.logRegistryResults(o,e.dryRun)}return{files:i,dirs:a}}logRegistryResults(e,t){let n=e.filter(e=>e.success).length,r=e.filter(e=>!e.success).length;if(n>0&&this.log.trace({action:t===!0?`dryRun`:`register`,type:`registrySummary`,successCount:n}),r>0){this.log.error({action:`register`,type:`registrySummary`,failCount:r});for(let t of e)if(!t.success){let e=t.error?.message??`Unknown error`;this.log.error({action:`register`,type:`registryEntry`,entryName:t.entryName,error:e})}}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),$)}getKiroPowersDir(){return this.joinPath(this.getHomeDir(),`.kiro/powers/installed`)}getHomeDir(){return s.homedir()}buildPowerFrontMatter(e){let t=e.name,n=e.description,r=e.displayName,i=e.keywords,a=e.author,o=[`---`];if(o.push(`name: "${t}"`),r!=null&&r.length>0&&o.push(`displayName: "${r}"`),n.length>0&&o.push(`description: "${n}"`),i!=null&&i.length>0){let e=i.map(e=>`"${e}"`).join(`, `);o.push(`keywords: [${e}]`)}return a!=null&&a.length>0&&o.push(`author: "${a}"`),o.push(`---`),o.join(`
|
|
261
|
-
`)}async writeSkillAsPower(e,t){let n=[],r=t.yamlFrontMatter.name,i=this.joinPath(this.getKiroPowersDir(),r),a=this.joinPath(i,
|
|
261
|
+
`}function Du(e,t,n){let r=e;return r=r.replace(yt.SHADOW_SOURCE_PROJECT,n),r=r.replace(yt.WORKSPACE,t),r.startsWith(`~`)&&(r=i.join(o.homedir(),r.slice(1))),i.normalize(r)}var Ou=class{name=`init`;async execute(e){let{logger:t,userConfigOptions:n}=e;t.info(`initializing shadow source project structure`,{command:`init`});let r=Du(n.workspaceDir,``,``),i=yu(Du(n.shadowSourceProjectDir,r,``),{logger:t}),a=i.createdDirs.length===0&&i.createdFiles.length===0?`All ${i.existedDirs.length} directories and ${i.existedFiles.length} files already exist`:`Created ${i.createdDirs.length} directories and ${i.createdFiles.length} files (${i.existedDirs.length} dirs, ${i.existedFiles.length} files already existed)`;return t.info(`initialization complete`,{dirsCreated:i.createdDirs.length,filesCreated:i.createdFiles.length,dirsExisted:i.existedDirs.length,filesExisted:i.existedFiles.length}),{success:i.success,filesAffected:i.createdFiles.length,dirsAffected:i.createdDirs.length,message:a}}};function ku(e){let t=e.replace(/^v/,``),n=/^(\d+)\.(\d+)\.(\d+)/.exec(t);return n==null?null:[Number.parseInt(n[1],10),Number.parseInt(n[2],10),Number.parseInt(n[3],10)]}function Au(e,t){let n=ku(e),r=ku(t);if(n==null||r==null)return 0;for(let e=0;e<3;e++){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1}return 0}async function ju(){try{let e=await fetch(`https://registry.npmjs.org/@truenine/memory-sync-cli/latest`,{headers:{Accept:`application/json`},signal:AbortSignal.timeout(5e3)});return e.ok?(await e.json()).version??null:null}catch{return null}}function Mu(){return`1.0.5`}async function Nu(){let e=Mu();if(e===`dev`)return{status:`development`,localVersion:e,remoteVersion:null};let t=await ju();if(t==null)return{status:`current`,localVersion:e,remoteVersion:null,error:`Failed to fetch remote version`};let n=Au(e,t);return n<0?{status:`outdated`,localVersion:e,remoteVersion:t}:n>0?{status:`development`,localVersion:e,remoteVersion:t}:{status:`current`,localVersion:e,remoteVersion:t}}function Pu(e,t){let{status:n,localVersion:r,remoteVersion:i}=e;switch(n){case`outdated`:t.warn(`Version outdated: ${r} → ${i}. Run 'npm i -g @truenine/memory-sync-cli@latest' to update.`);break;case`current`:e.error==null?t.info(`Version ${r} is up to date.`):t.debug(`Version check skipped: ${e.error}`);break;case`development`:i==null?t.debug(`Running in development mode, version check skipped.`):t.info(`Development version detected: ${r} > ${i}. Thanks for contributing!`);break}}function Fu(){return new Date().getMinutes()%2==0}async function Iu(e){if(Fu())try{let t=await Nu();t.status===`outdated`&&Pu(t,e)}catch{}}var Lu=class{name=`outdated`;async execute(e){let t=await Nu();return Pu(t,e.logger),{success:!0,filesAffected:0,dirsAffected:0,message:`Version status: ${t.status}`}}};const Ru=`.tnmsc.json`,zu=`.aindex`;function Bu(){return i.join(o.homedir(),zu,Ru)}function Vu(){return{workspaceDir:bt,shadowSourceProjectDir:`$WORKSPACE/${xt}`,shadowSkillSourceDir:St,shadowFastCommandDir:Ct,shadowSubAgentDir:wt,globalMemoryFile:Et,shadowProjectsDir:Tt,logLevel:`info`}}function Hu(e,t){let n=Bu(),a=i.dirname(n);r.existsSync(a)||r.mkdirSync(a,{recursive:!0}),r.writeFileSync(n,`${JSON.stringify(e,null,2)}\n`,`utf-8`),t.info(`global config created`,{path:n})}var Uu=class{configFileName;searchCwd;searchGlobal;customSearchPaths;logger;constructor(e={}){this.configFileName=e.configFileName??Ru,this.searchCwd=e.searchCwd??!0,this.searchGlobal=e.searchGlobal??!0,this.customSearchPaths=e.searchPaths??[],this.logger=nu(`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(),zu,this.configFileName)),t}loadFromFile(e){let t=this.resolveTilde(e);try{if(!r.existsSync(t))return{config:{},source:null,found:!1};let e=r.readFileSync(t,`utf-8`),n=this.parseConfig(e,t);return this.logger.debug(`loaded`,{source:t}),{config:n,source:t,found:!0}}catch(e){return this.logger.warn(`load failed`,{path:t,error:e}),{config:{},source:null,found:!1}}}load(e=n.cwd()){let t=this.getSearchPaths(e),r=[];for(let e of t){let t=this.loadFromFile(e);t.found&&r.push(t)}return{config:this.mergeConfigs(r.map(e=>e.config)),sources:r.map(e=>e.source).filter(e=>e!==null),found:r.length>0}}parseConfig(e,t){try{let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`Config must be a JSON object`);return this.validateConfig(n,t)}catch(e){throw e instanceof SyntaxError?Error(`Invalid JSON in ${t}: ${e.message}`):e}}validateConfig(e,t){let n={},r=[];for(let t of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])t in e&&(typeof e[t]==`string`?n[t]=e[t]:r.push(`${t} must be a string`));if(`logLevel`in e){let t=[`trace`,`debug`,`info`,`warn`,`error`],i=e.logLevel;typeof i==`string`&&t.includes(i)?n.logLevel=i:r.push(`logLevel must be one of: ${t.join(`, `)}`)}if(`externalProjects`in e){let t=e.externalProjects;Array.isArray(t)?t.every(e=>typeof e==`string`)?n.externalProjects=t:r.push(`externalProjects must be an array of strings`):r.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let t=e.excludePatterns;if(typeof t==`object`&&t){let e=t,i={},a=!0;for(let[t,n]of Object.entries(e))Array.isArray(n)&&n.every(e=>typeof e==`string`)?i[t]=n:(r.push(`excludePatterns.${t} must be an array of strings`),a=!1);a&&(n.excludePatterns=i)}else r.push(`excludePatterns must be an object`)}return r.length>0&&this.logger.warn(`validation warnings`,{path:t,errors:r}),n}mergeConfigs(e){if(e.length===0)return{};let t=e[0];return e.length===1&&t!=null?t:[...e].reverse().reduce((e,t)=>{let n=[...e.externalProjects??[],...t.externalProjects??[]],r=this.mergeExcludePatterns(e.excludePatterns,t.excludePatterns);return{...e,...t,...n.length>0?{externalProjects:n}:{},...r==null?{}:{excludePatterns:r}}},{})}mergeExcludePatterns(e,t){if(e==null&&t==null)return null;if(e==null)return t??null;if(t==null)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}resolveTilde(e){return e.startsWith(`~`)?i.join(o.homedir(),e.slice(1)):e}};let Wu=null;function Gu(e){return(e||!Wu)&&(Wu=new Uu(e)),Wu}function Ku(e){return Gu().load(e)}function qu(){let e=nu(`ConfigLoader`),t=Bu();if(!r.existsSync(t))return e.warn(`global config not found, creating default config`,{path:t}),Hu(Vu(),e),{valid:!0,exists:!1,errors:[],shouldExit:!1};let n;try{n=r.readFileSync(t,`utf-8`)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`failed to read global config`,{path:t,error:r}),Yu(t,e,[`Failed to read config: ${r}`])}let i;try{i=JSON.parse(n)}catch(n){let r=n instanceof Error?n.message:String(n);return e.error(`invalid JSON in global config`,{path:t,error:r}),Yu(t,e,[`Invalid JSON: ${r}`])}if(typeof i!=`object`||!i||Array.isArray(i))return e.error(`global config must be a JSON object`,{path:t}),Yu(t,e,[`Config must be a JSON object`]);let a=Ju(i);if(a.length>0){for(let n of a)e.error(`config validation error`,{path:t,error:n});return Yu(t,e,a)}return{valid:!0,exists:!0,errors:[],shouldExit:!1}}function Ju(e){let t=[];for(let n of[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`])n in e&&typeof e[n]!=`string`&&t.push(`${n} must be a string`);if(`logLevel`in e){let n=[`trace`,`debug`,`info`,`warn`,`error`],r=e.logLevel;(typeof r!=`string`||!n.includes(r))&&t.push(`logLevel must be one of: ${n.join(`, `)}`)}if(`externalProjects`in e){let n=e.externalProjects;Array.isArray(n)?n.every(e=>typeof e==`string`)||t.push(`externalProjects must be an array of strings`):t.push(`externalProjects must be an array`)}if(`excludePatterns`in e){let n=e.excludePatterns;if(typeof n!=`object`||!n||Array.isArray(n))t.push(`excludePatterns must be an object`);else{let e=n;for(let[n,r]of Object.entries(e))(!Array.isArray(r)||!r.every(e=>typeof e==`string`))&&t.push(`excludePatterns.${n} must be an array of strings`)}}return t}function Yu(e,t,n){try{r.unlinkSync(e),t.info(`deleted invalid config`,{path:e})}catch{t.warn(`failed to delete invalid config`,{path:e})}return Hu(Vu(),t),t.error(`recreated default config, please review and restart`,{path:e}),{valid:!1,exists:!0,errors:n,shouldExit:!0}}const Xu=[`workspaceDir`,`shadowSourceProjectDir`,`shadowSkillSourceDir`,`shadowFastCommandDir`,`shadowSubAgentDir`,`globalMemoryFile`,`shadowProjectsDir`,`logLevel`];function Zu(e){return Xu.includes(e)}function Qu(e){return[`trace`,`debug`,`info`,`warn`,`error`].includes(e)}function $u(){return i.join(o.homedir(),zu,Ru)}function ed(){let e=$u();if(!r.existsSync(e))return{};try{let t=r.readFileSync(e,`utf-8`);return JSON.parse(t)}catch{return{}}}function td(e){let t=$u(),n=i.dirname(t);r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.writeFileSync(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`)}var nd=class{name=`set`;constructor(e){this.options=e}async execute(e){let{logger:t}=e;if(this.options.length===0)return t.error(`No configuration key-value pairs provided`),t.info(`Usage: tnmsc --set key=value or tnmsc set key=value`),t.info(`Valid keys: ${Xu.join(`, `)}`),{success:!1,filesAffected:0,dirsAffected:0,message:`No options provided`};let n=ed(),r=[],i=[];for(let[e,a]of this.options){if(!Zu(e)){r.push(`Invalid key: ${e} (valid keys: ${Xu.join(`, `)})`);continue}if(e===`logLevel`&&!Qu(a)){r.push(`Invalid logLevel value: ${a} (must be: trace, debug, info, warn, or error)`);continue}let o=n[e];n[e]=a,o!==a&&i.push(`${e}=${a}`),t.info(`configuration updated`,{key:e,value:a})}if(i.length>0&&(td(n),t.info(`global config written`,{path:$u()})),r.length>0)for(let e of r)t.error(e);let a=r.length===0,o=a?`Configuration updated: ${i.join(`, `)}`:`Partial update: ${i.join(`, `)}. Errors: ${r.join(`, `)}`;return{success:a,filesAffected:i.length>0?1:0,dirsAffected:0,message:o}}},rd=class{name=`unknown`;constructor(e){this.unknownCmd=e}async execute(e){return console.error(`Unknown command: ${this.unknownCmd}`),console.error(`Run "tnmsc help" for available commands.`),{success:!1,filesAffected:0,dirsAffected:0}}};function id(e){let t=[...e],n=t[0];n!=null&&ad(n)&&t.shift();let r=t[0];return r!=null&&od(r)&&t.shift(),t}function ad(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 od(e){return!!(/\.(?:m?[jt]s|cjs)$/.test(e)||/[/\\]/.test(e)&&!e.startsWith(`-`)||/^(?:@[\w-]+\/)?[\w-]+$/.test(e)&&!e.startsWith(`-`))}const sd=new Set([`help`,`version`,`outdated`,`init`,`dry-run`,`clean`,`set`]),cd=new Map([[`--trace`,`trace`],[`--debug`,`debug`],[`--info`,`info`],[`--warn`,`warn`],[`--error`,`error`]]),ld=new Map([[`trace`,0],[`debug`,1],[`info`,2],[`warn`,3],[`error`,4]]);function ud(e){let{logLevelFlags:t}=e;if(t.length===0)return;let n=t[0],r=ld.get(n)??4;for(let e of t){let t=ld.get(e)??4;t<r&&(r=t,n=e)}return n}function dd(e){let{helpFlag:t,versionFlag:n,subcommand:r,dryRun:i,unknownCommand:a,setOption:o,positional:s}=e;if(n)return new du;if(t)return new pu;if(a!=null)return new rd(a);if(r===`version`)return new du;if(r===`help`)return new pu;if(r===`outdated`)return new Lu;if(r===`init`)return new Ou;if(r===`dry-run`)return new cu;if(r===`clean`)return i?new su:new lt;if(r===`set`||o.length>0){let e=[];for(let t of s){let n=t.indexOf(`=`);n>0&&e.push([t.slice(0,n),t.slice(n+1)])}return new nd([...o,...e])}return new lu}function fd(e){let t={subcommand:void 0,helpFlag:!1,versionFlag:!1,dryRun:!1,logLevel:void 0,logLevelFlags:[],setOption:[],unknownCommand:void 0,positional:[],unknown:[]},n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i!=null){if(i===`--`){t.positional.push(...e.slice(r+1).filter(e=>e!=null));break}if(i.startsWith(`--`)){let n=i.split(`=`),a=n[0]??``,o=cd.get(a);if(o!=null){t.logLevelFlags.push(o),t.logLevel=o;continue}switch(a){case`--help`:t.helpFlag=!0;break;case`--version`:t.versionFlag=!0;break;case`--dry-run`:t.dryRun=!0;break;case`--set`:if(n.length>1){let e=n.slice(1).join(`=`),r=e.indexOf(`=`);r>0&&t.setOption.push([e.slice(0,r),e.slice(r+1)])}else{let n=e[r+1];if(n!=null){let e=n.indexOf(`=`);e>0&&(t.setOption.push([n.slice(0,e),n.slice(e+1)]),r++)}}break;default:t.unknown.push(i)}continue}if(i.startsWith(`-`)&&i.length>1){let e=i.slice(1);for(let n of e)switch(n){case`h`:t.helpFlag=!0;break;case`v`:t.versionFlag=!0;break;case`n`:t.dryRun=!0;break;default:t.unknown.push(`-${n}`)}continue}if(!n){n=!0,sd.has(i)?t.subcommand=i:t.unknownCommand=i;continue}t.positional.push(i)}}return t}var pd=class{logger;args;outputPlugins=[];constructor(...e){this.args=fd(id(e.filter(e=>e!=null)));let t=ud(this.args);t!=null&&ql(t),this.logger=nu(`PluginPipeline`,t),this.logger.debug(`initialized`,{args:this.args})}registerOutputPlugins(e){return this.outputPlugins.push(...e),this}async run(e){await Iu(this.logger);let{context:t,outputPlugins:n,userConfigOptions:r}=e;this.registerOutputPlugins([...n]);let i=this.resolveCommand(),a=this.createCommandContext(t,r);await i.execute(a)}resolveCommand(){return dd(this.args)}createCommandContext(e,t){return{logger:this.logger,outputPlugins:this.outputPlugins,collectedInputContext:e,userConfigOptions:t,createCleanContext:t=>this.createCleanContext(e,t),createWriteContext:t=>this.createWriteContext(e,t)}}createCleanContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t}}createWriteContext(e,t){return{logger:this.logger,fs:r,path:i,glob:$e.default,collectedInputContext:e,dryRun:t,registeredPluginNames:this.outputPlugins.map(e=>e.name)}}buildDependencyGraph(e){let t=new Map;for(let n of e){let e=n.dependsOn??[];t.set(n.name,[...e])}return t}validateDependencies(e){let t=new Set(e.map(e=>e.name));for(let n of e){let e=n.dependsOn??[];for(let r of e)if(!t.has(r))throw new _t(n.name,r)}}topologicalSort(e){this.validateDependencies(e);let t=new Map;for(let n of e)t.set(n.name,n);let n=new Map;for(let t of e)n.set(t.name,0);let r=new Map;for(let t of e)r.set(t.name,[]);for(let t of e){let e=t.dependsOn??[];for(let i of e){n.set(t.name,(n.get(t.name)??0)+1);let e=r.get(i)??[];e.push(t.name),r.set(i,e)}}let i=[];for(let t of e)n.get(t.name)===0&&i.push(t.name);let a=[];for(;i.length>0;){let o=i.shift(),s=t.get(o);a.push(s);let c=(r.get(o)??[]).sort((t,n)=>e.findIndex(e=>e.name===t)-e.findIndex(e=>e.name===n));for(let e of c){let t=(n.get(e)??0)-1;n.set(e,t),t===0&&i.push(e)}}if(a.length!==e.length)throw new gt(this.findCyclePath(e,n));return a}findCyclePath(e,t){let n=new Set;for(let[e,r]of t)r>0&&n.add(e);let r=new Map;for(let t of e)if(n.has(t.name)){let e=(t.dependsOn??[]).filter(e=>n.has(e));r.set(t.name,e)}let i=new Set,a=[],o=e=>{if(a.includes(e))return a.push(e),!0;if(i.has(e))return!1;i.add(e),a.push(e);for(let t of r.get(e)??[])if(o(t))return!0;return a.pop(),!1};for(let e of n){if(o(e)){let e=a.indexOf(a[a.length-1]);return a.slice(e)}i.clear(),a.length=0}return Array.from(n)}executePluginsInOrder(e,t){if(e.length===0)return{};let n=this.topologicalSort(e),r=new Map,i={};for(let e of n){let n=this.buildDependencyContext(e,r),a={...t,dependencyContext:n},o=e.collect(a);r.set(e.name,o),i=this.mergeContexts(i,o)}return i}buildDependencyContext(e,t){if((e.dependsOn??[]).length===0)return{};let n=this.collectTransitiveDependencies(e,t),r={};for(let e of n){let n=t.get(e);n!=null&&(r=this.mergeContexts(r,n))}return r}collectTransitiveDependencies(e,t){let n=new Set,r=[];return(e=>{for(let i of e)n.has(i)||(n.add(i),t.get(i)!=null&&r.push(i))})(e.dependsOn??[]),r}mergeContexts(e,t){let n=e.workspace;if(t.workspace!=null)if(n!=null){let e=new Map;for(let t of n.projects)e.set(t.name,t);for(let n of t.workspace.projects)e.set(n.name,n);n={directory:t.workspace.directory??n.directory,projects:Array.from(e.values())}}else n=t.workspace;let r=t.externalProjects==null?e.externalProjects:[...e.externalProjects??[],...t.externalProjects],i=t.ideConfigFiles==null?e.ideConfigFiles:[...e.ideConfigFiles??[],...t.ideConfigFiles],a=t.fastCommands==null?e.fastCommands:[...e.fastCommands??[],...t.fastCommands],o=t.subAgents==null?e.subAgents:[...e.subAgents??[],...t.subAgents],s=t.skills==null?e.skills:[...e.skills??[],...t.skills],c=t.aiAgentIgnoreConfigFiles==null?e.aiAgentIgnoreConfigFiles:[...e.aiAgentIgnoreConfigFiles??[],...t.aiAgentIgnoreConfigFiles],l=t.globalMemory??e.globalMemory,u=t.shadowSourceProjectDir??e.shadowSourceProjectDir,d=t.readmePrompts==null?e.readmePrompts:[...e.readmePrompts??[],...t.readmePrompts];return{...n==null?{}:{workspace:n},...r==null?{}:{externalProjects:r},...i==null?{}:{ideConfigFiles:i},...a==null?{}:{fastCommands:a},...o==null?{}:{subAgents:o},...s==null?{}:{skills:s},...c==null?{}:{aiAgentIgnoreConfigFiles:c},...l==null?{}:{globalMemory:l},...u==null?{}:{shadowSourceProjectDir:u},...d==null?{}:{readmePrompts:d}}}};const md={workspaceDir:bt,shadowSourceProjectDir:`$WORKSPACE/${xt}`,shadowSkillSourceDir:St,shadowFastCommandDir:Ct,shadowSubAgentDir:wt,globalMemoryFile:Et,shadowProjectsDir:Tt,externalProjects:[],excludePatterns:{},fastCommandSeriesOptions:{},plugins:[],logLevel:`info`};function hd(e){return{...e.workspaceDir==null?{}:{workspaceDir:e.workspaceDir},...e.shadowSourceProjectDir==null?{}:{shadowSourceProjectDir:e.shadowSourceProjectDir},...e.shadowSkillSourceDir==null?{}:{shadowSkillSourceDir:e.shadowSkillSourceDir},...e.shadowFastCommandDir==null?{}:{shadowFastCommandDir:e.shadowFastCommandDir},...e.shadowSubAgentDir==null?{}:{shadowSubAgentDir:e.shadowSubAgentDir},...e.globalMemoryFile==null?{}:{globalMemoryFile:e.globalMemoryFile},...e.shadowProjectsDir==null?{}:{shadowProjectsDir:e.shadowProjectsDir},...e.externalProjects==null?{}:{externalProjects:e.externalProjects},...e.excludePatterns==null?{}:{excludePatterns:e.excludePatterns},...e.fastCommandSeriesOptions==null?{}:{fastCommandSeriesOptions:e.fastCommandSeriesOptions},...e.logLevel==null?{}:{logLevel:e.logLevel}}}function gd(...e){return e.reduce((e,t)=>_d(e,t),{...md})}function _d(e,t){let n=t.externalProjects,r=t.plugins,i=t.excludePatterns,a=t.fastCommandSeriesOptions;return{...e,...t,externalProjects:[...e.externalProjects,...n??[]],plugins:[...e.plugins,...r??[]],excludePatterns:vd(e.excludePatterns,i),fastCommandSeriesOptions:yd(e.fastCommandSeriesOptions,a)}}function vd(e,t){let n={...e};if(t)for(let[e,r]of Object.entries(t))n[e]=[...n[e]??[],...r];return n}function yd(e,t){if(t==null)return e??{};if(e==null)return t;let n={};if(e.pluginOverrides!=null)for(let[t,r]of Object.entries(e.pluginOverrides))n[t]={...r};if(t.pluginOverrides!=null)for(let[e,r]of Object.entries(t.pluginOverrides))n[e]={...n[e],...r};let r=t.includeSeriesPrefix??e.includeSeriesPrefix,i=Object.keys(n).length>0;return r!=null&&i?{includeSeriesPrefix:r,pluginOverrides:n}:r==null?i?{pluginOverrides:n}:{}:{includeSeriesPrefix:r}}function bd(e){return`pluginOptions`in e||`configLoaderOptions`in e||`loadUserConfig`in e}function xd(e={}){qu().shouldExit&&n.exit(1);let t,a,o;bd(e)?(t=e.pluginOptions??{},a=e.loadUserConfig??!0,o=e.cwd):(t=e,a=!0);let s={},c=!1,l=[];if(a){let e=Ku(o);c=e.found,l=e.sources,e.found&&(s=hd(e.config))}let u=gd(s,t),{plugins:d=[],logLevel:f}=u,p=nu(`defineConfig`,f);c?p.info(`user config loaded`,{sources:l}):p.info(`no user config found, using defaults`,{workspaceDir:md.workspaceDir,shadowSourceProjectDir:md.shadowSourceProjectDir,shadowSkillSourceDir:md.shadowSkillSourceDir,shadowFastCommandDir:md.shadowFastCommandDir,shadowSubAgentDir:md.shadowSubAgentDir,globalMemoryFile:md.globalMemoryFile,shadowProjectsDir:md.shadowProjectsDir,logLevel:md.logLevel});let m={logger:p,userConfigOptions:u,fs:r,path:i,glob:$e.default},h=d.filter(e=>e.type===ut.Input),g=d.filter(e=>e.type===ut.Output),_=new pd().executePluginsInOrder(h,m);if(_.workspace==null)throw Error(`Workspace not initialized by any plugin`);return{context:{workspace:_.workspace,ideConfigFiles:_.ideConfigFiles??[],..._.externalProjects!=null&&{externalProjects:_.externalProjects},..._.fastCommands!=null&&{fastCommands:_.fastCommands},..._.subAgents!=null&&{subAgents:_.subAgents},..._.skills!=null&&{skills:_.skills},..._.globalMemory!=null&&{globalMemory:_.globalMemory},..._.aiAgentIgnoreConfigFiles!=null&&{aiAgentIgnoreConfigFiles:_.aiAgentIgnoreConfigFiles},..._.shadowSourceProjectDir!=null&&{shadowSourceProjectDir:_.shadowSourceProjectDir},..._.readmePrompts!=null&&{readmePrompts:_.readmePrompts}},outputPlugins:g,userConfigOptions:u}}const Sd=`AGENTS.md`;var Cd=class extends Z{constructor(){super(`AgentsOutputPlugin`,{outputFileName:Sd})}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,Sd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Sd));return t}async canWrite(e){let{workspace:t}=e.collectedInputContext;return t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.trace({action:`skip`,reason:`noOutputs`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}};const wd=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Td=class extends iu{constructor(){super(`AIAgentIgnoreConfigFileInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{shadowProjectDir:a}=this.resolveBasePaths(t),o=[];for(let e of wd){let t=i.join(a,e);if(r.existsSync(t)&&r.statSync(t).isFile())try{let i=r.readFileSync(t,`utf-8`);o.push({fileName:e,content:i}),n.debug(`read ignore file`,{path:t})}catch(e){n.warn(`failed to read ignore file`,{path:t,error:e})}}return{aiAgentIgnoreConfigFiles:o}}};const Ed=[`.qoderignore`,`.cursorignore`,`.warpindexignore`];var Dd=class extends Z{constructor(){super(`AIAgentIgnoreConfigFileOutputPlugin`)}async registerProjectOutputDirs(){return[]}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.isPromptSourceProject!==!0)for(let n of Ed){let r=i.join(e.dirFromWorkspacePath.path,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>i.basename(e.dirFromWorkspacePath.path),getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerGlobalOutputDirs(){return[]}async registerGlobalOutputFiles(){return[]}async canWrite(e){let{aiAgentIgnoreConfigFiles:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no ignore config files to write`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{aiAgentIgnoreConfigFiles:n}=e.collectedInputContext,r=[],i=[];if(n==null||n.length===0)return{files:r,dirs:i};for(let i of t){let t=i.dirFromWorkspacePath;if(t==null)continue;let a=i.name??`unknown`;for(let i of n){let n=await this.writeIgnoreFile(e,t,i,`project:${a}/${i.fileName}`);r.push(n)}}return{files:r,dirs:i}}async writeIgnoreFile(e,t,n,a){let o=i.join(t.path,n.fileName),s=i.join(t.basePath,o),c={pathKind:P.Relative,path:o,basePath:t.basePath,getDirectoryName:()=>i.basename(t.path),getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0,skipped:!1};try{return r.writeFileSync(s,n.content,`utf-8`),this.log.trace({action:`write`,type:`ignoreFile`,path:s,label:a}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`ignoreFile`,path:s,label:a,error:t}),{path:c,success:!1,error:e}}}};const Od=`CLAUDE.md`,kd=`.claude`,Ad=`commands`,jd=`agents`,Md=`skills`,Nd=[Ad,jd,Md];var Pd=class extends Z{constructor(){super(`ClaudeCodeCLIOutputPlugin`,{globalConfigDir:kd,outputFileName:Od})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Nd){let r=i.join(e.dirFromWorkspacePath.path,kd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.rootMemoryPrompt!=null&&e.dirFromWorkspacePath!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,Od)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Od));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Od,basePath:n,getDirectoryName:()=>kd,getAbsolutePath:()=>i.join(n,Od)}]}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,subAgents:i,skills:a}=e.collectedInputContext,o=t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0),s=n!=null,c=(r?.length??0)>0,l=(i?.length??0)>0,u=(a?.length??0)>0;return!o&&!s&&!c&&!l&&!u?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.name??`unknown`,s=o.dirFromWorkspacePath;if(s!=null){if(o.rootMemoryPrompt!=null){let n=await this.writePromptFile(e,s,o.rootMemoryPrompt.content,`project:${t}/root`);a.push(n)}if(o.childMemoryPrompts!=null)for(let n of o.childMemoryPrompts){let r=await this.writePromptFile(e,n.dir,n.content,`project:${t}/child:${n.workingChildDirectoryPath?.path??`unknown`}`);a.push(r)}if(n!=null)for(let t of n){let n=await this.writeFastCommand(e,s,t);a.push(...n)}if(r!=null)for(let t of r){let n=await this.writeSubAgent(e,s,t);a.push(...n)}if(i!=null)for(let t of i){let n=await this.writeSkill(e,s,t);a.push(...n)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Od),c={pathKind:P.Relative,path:Od,basePath:o,getDirectoryName:()=>kd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,kd,Ad),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,kd,Ad,s),basePath:t.basePath,getDirectoryName:()=>Ad,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,kd,jd),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,kd,jd,o),basePath:t.basePath,getDirectoryName:()=>jd,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,kd,Md,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,kd,Md,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,kd,Md,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Fd=`AGENTS.md`,Id=`.codex`,Ld=`prompts`,Rd=`skills`,zd=`SKILL.md`;var Bd=class extends Z{constructor(){super(`CodexCLIOutputPlugin`,{globalConfigDir:Id,outputFileName:Fd,dependsOn:[`AgentsOutputPlugin`]})}async registerProjectOutputDirs(e){return[]}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputDirs(e){let t=this.getGlobalConfigDir(),n=[],r=i.join(t,Ld);n.push({pathKind:P.Relative,path:Ld,basePath:t,getDirectoryName:()=>Ld,getAbsolutePath:()=>r});let{skills:a}=e.collectedInputContext;if(a!=null&&a.length>0)for(let e of a){let r=e.yamlFrontMatter?.name??e.dir.getDirectoryName(),a=i.join(t,Rd,r);n.push({pathKind:P.Relative,path:i.join(Rd,r),basePath:t,getDirectoryName:()=>r,getAbsolutePath:()=>a})}return n}async registerGlobalOutputFiles(e){let t=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Fd,basePath:t,getDirectoryName:()=>Id,getAbsolutePath:()=>i.join(t,Fd)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=t!=null,a=(n?.length??0)>0,o=(r?.length??0)>0;return!i&&!a&&!o?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){return{files:[],dirs:[]}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:a}=e.collectedInputContext,o=[],s=[];if(t!=null){let n=this.getGlobalConfigDir(),a=i.join(n,Fd),s={pathKind:P.Relative,path:Fd,basePath:n,getDirectoryName:()=>Id,getAbsolutePath:()=>a};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:a}),o.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(n),r.writeFileSync(a,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:a}),o.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:a,error:t}),o.push({path:s,success:!1,error:e})}}if(n!=null&&n.length>0){let t=this.getGlobalConfigDir();for(let r of n){let n=await this.writeGlobalFastCommand(e,t,r);o.push(...n)}}if(a!=null&&a.length>0){let t=this.getGlobalConfigDir();for(let n of a){let r=await this.writeGlobalSkill(e,t,n);o.push(...r)}}return{files:o,dirs:s}}async writeGlobalFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t,Ld),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(Ld,s),basePath:t,getDirectoryName:()=>Ld,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalFastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`globalFastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalFastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeGlobalSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t,Rd,o),c=i.join(s,zd),l={pathKind:P.Relative,path:i.join(Rd,o,zd),basePath:t,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildCodexSkillContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalSkill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`globalSkill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalSkill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}buildCodexSkillContent(e){let t=e.yamlFrontMatter,n=this.normalizeToSingleLine(t.description,500),r=this.normalizeToSingleLine(t.name,100),i=[`---`];return i.push(`name: ${this.yamlQuoteIfNeeded(r)}`),i.push(`description: ${this.yamlQuoteIfNeeded(n)}`),t.displayName!=null&&(i.push(`metadata:`),i.push(` short-description: ${this.yamlQuoteIfNeeded(t.displayName)}`)),i.push(`---`),`${i.join(`
|
|
262
|
+
`)}\n${e.content}`}normalizeToSingleLine(e,t){let n=e.replace(/[\r\n]+/g,` `).replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-3)}...`:n}yamlQuoteIfNeeded(e){return/[:[\]{}#&*!|>'"%@`]/.test(e)||/^[\s-]/.test(e)?`"${e.replace(/"/g,`\\"`)}"`:e}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(Rd,n,c),basePath:o,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}};const Vd=`AGENTS.md`,Hd=`.factory`,Ud=`commands`,Wd=`agents`,Gd=`skills`,Kd=[Ud,Wd,Gd];var qd=class extends Z{constructor(){super(`DroidCLIOutputPlugin`,{globalConfigDir:Hd,outputFileName:Vd})}async registerProjectOutputDirs(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null)for(let n of Kd){let r=i.join(e.dirFromWorkspacePath.path,Hd,n);t.push({pathKind:P.Relative,path:r,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>i.join(e.dirFromWorkspacePath.basePath,r)})}return t}async registerProjectOutputFiles(e){return[]}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Vd,basePath:n,getDirectoryName:()=>Hd,getAbsolutePath:()=>i.join(n,Vd)}]}async canWrite(e){let{globalMemory:t,fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=t!=null,o=(n?.length??0)>0,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{fastCommands:n,subAgents:r,skills:i}=e.collectedInputContext,a=[],o=[];for(let o of t){let t=o.dirFromWorkspacePath;if(t!=null){if(n!=null)for(let r of n){let n=await this.writeFastCommand(e,t,r);a.push(...n)}if(r!=null)for(let n of r){let r=await this.writeSubAgent(e,t,n);a.push(...r)}if(i!=null)for(let n of i){let r=await this.writeSkill(e,t,n);a.push(...r)}}}return{files:a,dirs:o}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Vd),c={pathKind:P.Relative,path:Vd,basePath:o,getDirectoryName:()=>Hd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}async writeFastCommand(e,t,n){let a=[],o=this.getTransformOptionsFromContext(e),s=this.transformFastCommandName(n,o),c=i.join(t.basePath,t.path,Hd,Ud),l=i.join(c,s),u={pathKind:P.Relative,path:i.join(t.path,Hd,Ud,s),basePath:t.basePath,getDirectoryName:()=>Ud,getAbsolutePath:()=>l},d=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommand`,path:l}),[{path:u,success:!0,skipped:!1}];try{this.ensureDirectory(c),r.writeFileSync(l,d,`utf-8`),this.log.trace({action:`write`,type:`fastCommand`,path:l}),a.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`fastCommand`,path:l,error:t}),a.push({path:u,success:!1,error:e})}return a}async writeSubAgent(e,t,n){let a=[],o=n.dir.path.endsWith(`.md`)?n.dir.path:`${n.dir.path}.md`,s=i.join(t.basePath,t.path,Hd,Wd),c=i.join(s,o),l={pathKind:P.Relative,path:i.join(t.path,Hd,Wd,o),basePath:t.basePath,getDirectoryName:()=>Wd,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`subAgent`,path:c}),[{path:l,success:!0,skipped:!1}];try{this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`subAgent`,path:c}),a.push({path:l,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`subAgent`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkill(e,t,n){let a=[],o=n.yamlFrontMatter?.name??n.dir.getDirectoryName(),s=i.join(t.basePath,t.path,Hd,Gd,o),c=i.join(s,`SKILL.md`),l={pathKind:P.Relative,path:i.join(t.path,Hd,Gd,o,`SKILL.md`),basePath:t.basePath,getDirectoryName:()=>o,getAbsolutePath:()=>c},u=this.buildMarkdownContent(n.rawFrontMatter,n.content);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skill`,path:c}),[{path:l,success:!0,skipped:!1}];try{if(this.ensureDirectory(s),r.writeFileSync(c,u,`utf-8`),this.log.trace({action:`write`,type:`skill`,path:c}),a.push({path:l,success:!0}),n.referenceDocuments!=null)for(let r of n.referenceDocuments){let n=await this.writeSkillReferenceDocument(e,s,o,r,t);a.push(...n)}}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skill`,path:c,error:t}),a.push({path:l,success:!1,error:e})}return a}async writeSkillReferenceDocument(e,t,n,a,o){let s=[],c=a.dir.path,l=i.join(t,c),u={pathKind:P.Relative,path:i.join(o.path,Hd,Gd,n,c),basePath:o.basePath,getDirectoryName:()=>n,getAbsolutePath:()=>l};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`skillRefDoc`,path:l}),[{path:u,success:!0,skipped:!1}];try{r.writeFileSync(l,a.content,`utf-8`),this.log.trace({action:`write`,type:`skillRefDoc`,path:l}),s.push({path:u,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillRefDoc`,path:l,error:t}),s.push({path:u,success:!1,error:e})}return s}},Jd=class extends iu{constructor(){super(`FastCommandInputPlugin`)}extractSeriesInfo(e){let t=e.replace(/\.md$/,``),n=t.indexOf(`_`);return n===-1?{commandName:t}:{series:t.substring(0,n),commandName:t.substring(n+1)}}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:i}=this.resolveBasePaths(t),a=t.shadowFastCommandDir??Ct,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=Gl(e.fs.readFileSync(t,`utf-8`)),i=r.contentWithoutFrontMatter,a=this.extractSeriesInfo(n.name);s.push({type:dt.FastCommand,content:i,length:i.length,filePathKind:P.Relative,...r.yamlFrontMatter!=null&&{yamlFrontMatter:r.yamlFrontMatter},...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},markdownAst:r.markdownAst,markdownContents:r.markdownContents,dir:{pathKind:P.Relative,path:n.name,basePath:o,getDirectoryName:()=>n.name.replace(/\.md$/,``),getAbsolutePath:()=>t},...a.series!=null&&{series:a.series},commandName:a.commandName})}}catch(e){n.error(`Failed to scan fast commands at ${o}`,{error:e})}return{fastCommands:s}}};const Yd=`GEMINI.md`,Xd=`.gemini`;var Zd=class extends Z{constructor(){super(`GeminiCLIOutputPlugin`,{globalConfigDir:Xd,outputFileName:Yd})}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,Yd)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,Yd));return t}async registerGlobalOutputFiles(e){let{globalMemory:t}=e.collectedInputContext;if(t==null)return[];let n=this.getGlobalConfigDir();return[{pathKind:P.Relative,path:Yd,basePath:n,getDirectoryName:()=>Xd,getAbsolutePath:()=>i.join(n,Yd)}]}async canWrite(e){let{workspace:t,globalMemory:n}=e.collectedInputContext;return!t.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)&&n==null?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t){let t=r.name??`unknown`,i=r.dirFromWorkspacePath;if(i!=null){if(r.rootMemoryPrompt!=null){let a=await this.writePromptFile(e,i,r.rootMemoryPrompt.content,`project:${t}/root`);n.push(a)}if(r.childMemoryPrompts!=null)for(let i of r.childMemoryPrompts){let r=await this.writePromptFile(e,i.dir,i.content,`project:${t}/child:${i.workingChildDirectoryPath?.path??`unknown`}`);n.push(r)}}}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t}=e.collectedInputContext,n=[],a=[];if(t==null)return{files:n,dirs:a};let o=this.getGlobalConfigDir(),s=i.join(o,Yd),c={pathKind:P.Relative,path:Yd,basePath:o,getDirectoryName:()=>Xd,getAbsolutePath:()=>s};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`globalMemory`,path:s}),{files:[{path:c,success:!0,skipped:!1}],dirs:a};try{this.ensureDirectory(o),r.writeFileSync(s,t.content,`utf-8`),this.log.trace({action:`write`,type:`globalMemory`,path:s}),n.push({path:c,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:s,error:t}),n.push({path:c,success:!1,error:e})}return{files:n,dirs:a}}},Qd=class extends iu{constructor(){super(`GlobalMemoryInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{workspaceDir:i,shadowProjectDir:a}=this.resolveBasePaths(t),s=t.globalMemoryFile??Et,c=this.resolvePath(s,i,a);if(n.existsSync(c)&&n.statSync(c).isFile()){let e=Gl(n.readFileSync(c,`utf-8`)),t=e.contentWithoutFrontMatter;return{globalMemory:{type:dt.GlobalMemory,content:t,length:t.length,filePathKind:P.Relative,...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:r.basename(c),basePath:r.dirname(c),getDirectoryName:()=>r.basename(c),getAbsolutePath:()=>c},parentDirectoryPath:{type:ht.UserHome,directory:{pathKind:P.Relative,path:``,basePath:o.homedir(),getDirectoryName:()=>r.basename(o.homedir()),getAbsolutePath:()=>o.homedir()}}}}}return{}}},$d=class extends iu{constructor(){super(`IdeConfigInputPlugin`)}collect(e){let{userConfigOptions:t,fs:n,path:r}=e,{shadowProjectDir:i}=this.resolveBasePaths(t),a=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`,`.vscode/settings.json`,`.vscode/extensions.json`],o=[];for(let e of a){let t=r.join(i,e);if(n.existsSync(t)&&n.statSync(t).isFile()){let i=n.readFileSync(t,`utf-8`),a=F.Original;e.includes(`.vscode`)?a=F.VSCode:e.includes(`.idea`)?a=F.IntellijIDEA:e.includes(`.editorconfig`)&&(a=F.EditorConfig),o.push({type:a,content:i,length:i.length,filePathKind:P.Absolute,dir:{pathKind:P.Absolute,path:t,getDirectoryName:()=>r.basename(t)}})}}return{ideConfigFiles:o}}};const ef=`.idea`,tf=[`.editorconfig`,`.idea/codeStyles/Project.xml`,`.idea/codeStyles/codeStyleConfig.xml`,`.idea/.gitignore`];var nf=class extends Z{constructor(){super(`JetBrainsIDECodeStyleConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of tf){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig)?!0:(this.log.debug(`skipped`,{reason:`no JetBrains IDE config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.IntellijIDEA||e.type===F.EditorConfig);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.EditorConfig)return`.editorconfig`;if(e.type===F.IntellijIDEA){let e=t.indexOf(ef);return e===-1?this.joinPath(ef,`codeStyles`,this.basename(t)):t.substring(e)}return this.basename(t)}};const rf=`GLOBAL.md`,af=`.kiro`,$=`steering`,of=`POWER.md`;var sf=class extends Z{constructor(){super(`KiroCLIOutputPlugin`,{globalConfigDir:af,outputFileName:rf})}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,af,$);t.push({pathKind:P.Relative,path:n,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,n)})}return t}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace;for(let e of n)if(e.dirFromWorkspacePath!=null&&e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts){let r=this.buildSteeringFileName(n),i=this.joinPath(e.dirFromWorkspacePath.path,af,$,r);t.push({pathKind:P.Relative,path:i,basePath:e.dirFromWorkspacePath.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e.dirFromWorkspacePath.basePath,i)})}return t}async registerGlobalOutputDirs(e){let t=this.getGlobalSteeringDir(),n=[{pathKind:P.Relative,path:$,basePath:this.joinPath(this.getGlobalConfigDir()),getDirectoryName:()=>$,getAbsolutePath:()=>t}],{skills:r}=e.collectedInputContext;if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let r=t.yamlFrontMatter.name,i=this.joinPath(e,r);n.push({pathKind:P.Relative,path:r,basePath:e,getDirectoryName:()=>r,getAbsolutePath:()=>i})}}return n}async registerGlobalOutputFiles(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=this.getGlobalSteeringDir();if(t!=null&&i.push({pathKind:P.Relative,path:rf,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,rf)}),n!=null)for(let e of n){let t=this.buildFastCommandSteeringFileName(e);i.push({pathKind:P.Relative,path:t,basePath:a,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(a,t)})}if(r!=null){let e=this.getKiroPowersDir();for(let t of r){let n=t.yamlFrontMatter.name,r=this.joinPath(e,n);if(i.push({pathKind:P.Relative,path:of,basePath:r,getDirectoryName:()=>n,getAbsolutePath:()=>this.joinPath(r,of)}),t.referenceDocuments!=null){let e=this.joinPath(r,$);for(let n of t.referenceDocuments){let t=n.dir.path;i.push({pathKind:P.Relative,path:this.joinPath($,t),basePath:r,getDirectoryName:()=>$,getAbsolutePath:()=>this.joinPath(e,t)})}}}}return i}async canWrite(e){let{workspace:t,globalMemory:n,fastCommands:r,skills:i}=e.collectedInputContext,a=t.projects.some(e=>(e.childMemoryPrompts?.length??0)>0),o=n!=null,s=(r?.length??0)>0,c=(i?.length??0)>0;return!a&&!o&&!s&&!c?(this.log.trace({action:`skip`,reason:`noOutputs`}),!1):!0}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,n=[],r=[];for(let r of t)if(r.dirFromWorkspacePath!=null&&r.childMemoryPrompts!=null)for(let t of r.childMemoryPrompts){let i=await this.writeSteeringFile(e,r,t);n.push(i)}return{files:n,dirs:r}}async writeGlobalOutputs(e){let{globalMemory:t,fastCommands:n,skills:r}=e.collectedInputContext,i=[],a=[],o=[];if(t!=null){let n=this.getGlobalSteeringDir(),r=this.joinPath(n,rf),a={pathKind:P.Relative,path:rf,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>r};if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`globalMemory`,path:r}),i.push({path:a,success:!0,skipped:!1});else try{this.ensureDirectory(n),this.writeFileSync(r,t.content),this.log.trace({action:`write`,type:`globalMemory`,path:r}),i.push({path:a,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`globalMemory`,path:r,error:t}),i.push({path:a,success:!1,error:e})}}if(n!=null)for(let t of n){let n=await this.writeFastCommandSteeringFile(e,t);i.push(n)}if(r!=null&&r.length>0){this.log.debug(`Processing ${r.length} skills as Kiro Powers`);for(let t of r){let{fileResults:n,registryResult:r}=await this.writeSkillAsPower(e,t);i.push(...n),o.push(r)}this.logRegistryResults(o,e.dryRun)}return{files:i,dirs:a}}logRegistryResults(e,t){let n=e.filter(e=>e.success).length,r=e.filter(e=>!e.success).length;if(n>0&&this.log.trace({action:t===!0?`dryRun`:`register`,type:`registrySummary`,successCount:n}),r>0){this.log.error({action:`register`,type:`registrySummary`,failCount:r});for(let t of e)if(!t.success){let e=t.error?.message??`Unknown error`;this.log.error({action:`register`,type:`registryEntry`,entryName:t.entryName,error:e})}}}getGlobalSteeringDir(){return this.joinPath(this.getGlobalConfigDir(),$)}getKiroPowersDir(){return this.joinPath(this.getHomeDir(),`.kiro/powers/installed`)}getHomeDir(){return s.homedir()}buildPowerFrontMatter(e){let t=e.name,n=e.description,r=e.displayName,i=e.keywords,a=e.author,o=[`---`];if(o.push(`name: "${t}"`),r!=null&&r.length>0&&o.push(`displayName: "${r}"`),n.length>0&&o.push(`description: "${n}"`),i!=null&&i.length>0){let e=i.map(e=>`"${e}"`).join(`, `);o.push(`keywords: [${e}]`)}return a!=null&&a.length>0&&o.push(`author: "${a}"`),o.push(`---`),o.join(`
|
|
263
|
+
`)}async writeSkillAsPower(e,t){let n=[],r=t.yamlFrontMatter.name,i=this.joinPath(this.getKiroPowersDir(),r),a=this.joinPath(i,of),o={pathKind:P.Relative,path:of,basePath:i,getDirectoryName:()=>r,getAbsolutePath:()=>a},s=`${this.buildPowerFrontMatter(t.yamlFrontMatter)}\n${t.content}`;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`skillPower`,path:a}),n.push({path:o,success:!0,skipped:!1});else try{this.ensureDirectory(i),this.writeFileSync(a,s),this.log.trace({action:`write`,type:`skillPower`,path:a}),n.push({path:o,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`skillPower`,path:a,error:t}),n.push({path:o,success:!1,error:e})}if(t.referenceDocuments!=null){let r=this.joinPath(i,$);for(let a of t.referenceDocuments){let t=a.dir.path,o=this.joinPath(r,t),s={pathKind:P.Relative,path:this.joinPath($,t),basePath:i,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=a.content;if(e.dryRun===!0)this.log.trace({action:`dryRun`,type:`refDoc`,path:o}),n.push({path:s,success:!0,skipped:!1});else try{this.ensureDirectory(r),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`refDoc`,path:o}),n.push({path:s,success:!0})}catch(e){let t=e instanceof Error?e.message:String(e);this.log.error({action:`write`,type:`refDoc`,path:o,error:t}),n.push({path:s,success:!1,error:e})}}}let c=this.getRegistryWriter(ou),l=c.buildPowerEntry(t,i);return{fileResults:n,registryResult:(await this.registerInRegistry(c,[l],e))[0]??{success:!1,entryName:r,error:Error(`No registry result returned`)}}}buildFastCommandSteeringFileName(e){return this.transformFastCommandName(e,{includeSeriesPrefix:!0,seriesSeparator:`-`})}buildFastCommandSteeringContent(e){let t=e.yamlFrontMatter?.description??``,n=[`---`,`inclusion: manual`];return t.length>0&&n.push(`description: '${t}'`),n.push(`---`),`${n.join(`
|
|
262
264
|
`)}\n${e.content}`}async writeFastCommandSteeringFile(e,t){let n=this.getGlobalSteeringDir(),r=this.buildFastCommandSteeringFileName(t),i=this.joinPath(n,r),a={pathKind:P.Relative,path:r,basePath:n,getDirectoryName:()=>$,getAbsolutePath:()=>i},o=this.buildFastCommandSteeringContent(t);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`fastCommandSteering`,path:i}),{path:a,success:!0,skipped:!1};try{return this.ensureDirectory(n),this.writeFileSync(i,o),this.log.trace({action:`write`,type:`fastCommandSteering`,path:i}),{path:a,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`fastCommandSteering`,path:i,error:t}),{path:a,success:!1,error:e}}}buildSteeringFileName(e){return`kiro-${(e.workingChildDirectoryPath?.path??e.dir.path).replace(/\\/g,`/`).replace(/^\/+|\/+$/g,``).replace(/\//g,`-`)}.md`}buildSteeringContent(e){return`${[`---`,`inclusion: fileMatch`,`fileMatchPattern: '${(e.workingChildDirectoryPath?.path??e.dir.path).replace(/\\/g,`/`)}/**'`,`---`].join(`
|
|
263
|
-
`)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,Yd,$),o=this.joinPath(a,i),s={pathKind:P.Relative,path:this.joinPath(r.path,Yd,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`steeringFile`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`steeringFile`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`steeringFile`,path:o,error:t}),{path:s,success:!1,error:e}}}};const Qd=`AGENTS.md`;var $d=class extends iu{constructor(){super(`ProjectPromptInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=t.workspace;if(l==null)return this.log.warn(`No workspace found in dependency context, skipping project prompt enhancement`),{};let u=(l.projects??[]).map(t=>{let r=t.name;if(r==null)return t;let a=i.join(c,r);if(!n.existsSync(a)||!n.statSync(a).isDirectory())return t;let o=t.dirFromWorkspacePath?.getAbsolutePath(),s=this.readRootMemoryPrompt(e,a),l=o==null?[]:this.scanChildMemoryPrompts(e,a,o);return{...t,...s!=null&&{rootMemoryPrompt:s},...l.length>0&&{childMemoryPrompts:l}}});return{workspace:{directory:l.directory,projects:u}}}readRootMemoryPrompt(e,t){let{fs:n,path:r,logger:i}=e,a=r.join(t,Qd);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Gl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:dt.ProjectRootMemory,content:t,length:t.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Root,path:``,getDirectoryName:()=>``}}}catch(e){i.error(`Failed to read root memory prompt at ${a}`,{error:e});return}}scanChildMemoryPrompts(e,t,n){let{logger:r}=e,i=[];try{this.scanDirectoryRecursive(e,t,t,n,i)}catch(e){r.error(`Failed to scan child memory prompts at ${t}`,{error:e})}return i}scanDirectoryRecursive(e,t,n,r,i){let{fs:a,path:o}=e,s=a.readdirSync(n,{withFileTypes:!0});for(let c of s){if(!c.isDirectory()||c.name.startsWith(`.`)||c.name===`node_modules`)continue;let s=o.join(n,c.name),l=o.join(s,Qd);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,Qd);try{let e=Gl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:dt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}};const ef=`README.md`;var tf=class extends Z{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:ef})}async registerProjectOutputFiles(e){let t=[],{readmePrompts:n}=e.collectedInputContext;if(n==null||n.length===0)return t;for(let e of n){let n=e.targetDir,r=i.join(n.path,ef);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>i.join(n.basePath,r)})}return t}async canWrite(e){let{readmePrompts:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no README prompts to write`}),!1):!0}async writeProjectOutputs(e){let t=[],n=[],{readmePrompts:r}=e.collectedInputContext;if(r==null||r.length===0)return{files:t,dirs:n};for(let n of r){let r=await this.writeReadmeFile(e,n);t.push(r)}return{files:t,dirs:n}}async writeReadmeFile(e,t){let n=t.targetDir,a=i.join(n.path,ef),o=i.join(n.basePath,a),s=t.content,c={pathKind:P.Relative,path:a,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>o},l=t.isRoot?`project:${t.projectName}/README.md`:`project:${t.projectName}/${n.path}/README.md`;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`readme`,path:o,label:l}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(o);return r.existsSync(e)||r.mkdirSync(e,{recursive:!0}),r.writeFileSync(o,s,`utf-8`),this.log.trace({action:`write`,type:`readme`,path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`readme`,path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},nf=class extends iu{constructor(){super(`ReadmeMdInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow projects directory does not exist`,{path:c}),{readmePrompts:l};try{let t=r.readdirSync(c,{withFileTypes:!0});for(let n of t){if(!n.isDirectory())continue;let t=n.name,r=i.join(c,t);this.collectReadmeFiles(e,r,t,a,``,l)}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{readmePrompts:l}}collectReadmeFiles(e,t,n,r,i,a){let{fs:o,path:s,logger:c}=e,l=i===``,u=s.join(t,`README.md`);if(o.existsSync(u)&&o.statSync(u).isFile())try{let e=o.readFileSync(u,`utf-8`),t=l?n:s.join(n,i),c={pathKind:P.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:P.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:dt.Readme,content:e,length:e.length,filePathKind:P.Relative,projectName:n,targetDir:c,isRoot:l,markdownContents:[],dir:d})}catch(e){c.warn(`failed to read README.md`,{path:u,error:e})}try{let c=o.readdirSync(t,{withFileTypes:!0});for(let o of c)if(o.isDirectory()){let c=l?o.name:s.join(i,o.name),u=s.join(t,o.name);this.collectReadmeFiles(e,u,n,r,c,a)}}catch(e){c.warn(`failed to scan directory`,{path:t,error:e})}}},rf=class extends iu{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=i.basename(o),u=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isDirectory()){let e=t.name===l;u.push({name:t.name,...e&&{isPromptSourceProject:!0},dirFromWorkspacePath:{pathKind:P.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:P.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},af=class extends iu{constructor(){super(`SkillInputPlugin`)}extractReferenceDocumentLinks(e){let t=[],n=e=>{if(e.type===`link`){let n=e,r=n.url;if(r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`))return;let i=[];for(let e of n.children)e.type===`text`&&e.value!=null&&i.push(e.value);t.push({text:i.join(``),path:r})}if(`children`in e&&Array.isArray(e.children))for(let t of e.children)n(t)};for(let t of e)n(t);return t}readReferenceDocuments(e,t,n,r){let a=[];for(let o of t){let t=i.resolve(e,o.path);if(!n.existsSync(t)){r.warn(`reference document not found`,{path:o.path,skillDir:e});continue}if(!n.statSync(t).isFile()){r.warn(`reference document path is not a file`,{path:o.path});continue}try{let r=Gl(n.readFileSync(t,`utf-8`)),s=r.contentWithoutFrontMatter,c=i.dirname(o.path);a.push({type:dt.SkillReferenceDocument,content:s,length:s.length,filePathKind:P.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:P.Relative,path:o.path,basePath:e,getDirectoryName:()=>c===`.`?``:c,getAbsolutePath:()=>t}})}catch(e){r.warn(`failed to read reference document`,{path:o.path,error:e})}}return a}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??St,s=this.resolvePath(o,r,a),c=[];if(e.fs.existsSync(s)&&e.fs.statSync(s).isDirectory())try{let t=e.fs.readdirSync(s,{withFileTypes:!0});for(let r of t)if(r.isDirectory()){let t=e.path.join(s,r.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let a=Gl(e.fs.readFileSync(t,`utf-8`)),o=a.contentWithoutFrontMatter,l=this.extractReferenceDocumentLinks(a.markdownContents),u=e.path.join(s,r.name),d=this.readReferenceDocuments(u,l,e.fs,n);c.push({type:dt.Skill,content:o,length:o.length,filePathKind:P.Relative,yamlFrontMatter:a.yamlFrontMatter??{name:r.name,description:``},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,...d.length>0&&{referenceDocuments:d},dir:{pathKind:P.Relative,path:r.name,basePath:s,getDirectoryName:()=>r.name,getAbsolutePath:()=>i.join(s,r.name)}})}}}catch(e){n.error(`failed to scan skills`,{path:s,error:e})}return{skills:c}}},of=class extends iu{constructor(){super(`SubAgentInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??wt,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=Gl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:dt.SubAgent,content:a,length:a.length,filePathKind:P.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:P.Relative,path:t.name,basePath:c,getDirectoryName:()=>t.name.replace(/\.md$/,``),getAbsolutePath:()=>e}})}}catch(e){n.error(`Failed to scan sub agents at ${c}`,{error:e})}return{subAgents:l}}};const sf=`WARP.md`;var cf=class extends Z{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:sf})}isAgentsPluginRegistered(e){return`registeredPluginNames`in e&&e.registeredPluginNames!=null?e.registeredPluginNames.includes(`AgentsOutputPlugin`):!1}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=this.isAgentsPluginRegistered(e);for(let e of n)if(e.dirFromWorkspacePath!=null){if(r)t.push(this.createFileRelativePath(e.dirFromWorkspacePath,sf));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,sf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,sf))}return t}async canWrite(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext;return t?r==null?(this.log.debug(`skipped`,{reason:`AgentsOutputPlugin registered but no global memory`}),!1):!0:n.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.debug(`skipped`,{reason:`no outputs to write`}),!1)}async writeProjectOutputs(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext,{projects:i}=n,a=[],o=[];if(t){if(r==null)return{files:[],dirs:[]};for(let t of i){let n=t.dirFromWorkspacePath;if(n==null)continue;let i=t.name??`unknown`,o=await this.writePromptFile(e,n,r.content,`project:${i}/global-warp`);a.push(o)}return{files:a,dirs:o}}let s=this.extractGlobalMemoryContent(e);for(let t of i){let n=t.name??`unknown`,r=t.dirFromWorkspacePath;if(r!=null){if(t.rootMemoryPrompt!=null){let i=this.combineGlobalWithContent(s,t.rootMemoryPrompt.content),o=await this.writePromptFile(e,r,i,`project:${n}/root`);a.push(o)}if(t.childMemoryPrompts!=null)for(let r of t.childMemoryPrompts){let t=await this.writePromptFile(e,r.dir,r.content,`project:${n}/child:${r.workingChildDirectoryPath?.path??`unknown`}`);a.push(t)}}}return{files:a,dirs:o}}},lf=class extends iu{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,shadowProjectDir:r}=this.resolveBasePaths(t),a=(t.externalProjects||[]).map(e=>{let t=this.resolvePath(e,n,r);return{name:i.basename(t),dirFromWorkspacePath:{pathKind:P.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:P.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowSourceProjectDir:r,...a.length>0&&{externalProjects:a}}}};const uf=`.vscode`,df=[`.vscode/settings.json`,`.vscode/extensions.json`];var ff=class extends Z{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of df){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.VSCode)?!0:(this.log.debug(`skipped`,{reason:`no VS Code config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.VSCode);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.VSCode){let e=t.indexOf(uf);return e===-1?this.joinPath(uf,this.basename(t)):t.substring(e)}return this.basename(t)}},pf=fd({plugins:[new md,new vd,new Td,new jd,new Rd,new Hd,new Zd,new cf,new qd,new ff,new tf,new lf,new rf,new gd,new Wd,new af,new zd,new of,new Ud,new $d,new nf]}),mf=pf;async function hf(){await new id(...n.argv).run(pf)}hf().catch(e=>{console.error(e)});export{iu as AbstractInputPlugin,Z as AbstractOutputPlugin,ru as AbstractPlugin,gt as CircularDependencyError,ft as ClaudeCodeCLISubAgentColors,pt as CodingAgentTools,Pu as ConfigLoader,ku as DEFAULT_CONFIG_FILE_NAME,Au as DEFAULT_GLOBAL_CONFIG_DIR,Et as DEFAULT_GLOBAL_MEMORY_FILE,Ct as DEFAULT_SHADOW_FAST_COMMAND_DIR,Tt as DEFAULT_SHADOW_PROJECTS_DIR,xt as DEFAULT_SHADOW_PROJECT_SUFFIX,St as DEFAULT_SHADOW_SKILL_SOURCE_DIR,vt as DEFAULT_SHADOW_SOURCE_PROJECT_STRUCTURE,wt as DEFAULT_SHADOW_SUB_AGENT_DIR,bt as DEFAULT_WORKSPACE_DIR,P as FilePathKind,ht as GlobalConfigDirectoryType,F as IDEKind,_t as MissingDependencyError,mt as NamingCaseKind,yt as PathPlaceholders,ut as PluginKind,dt as PromptKind,I as SHADOW_SOURCE_DIR_NAMES,L as SHADOW_SOURCE_FILE_NAMES,R as SHADOW_SOURCE_RELATIVE_PATHS,tt as checkCanClean,rt as checkCanWrite,et as collectAllPluginOutputs,nu as createLogger,mf as default,fd as defineConfig,nt as executeOnCleanComplete,it as executeWriteOutputs,yu as generateShadowSourceProject,Iu as getConfigLoader,Mu as getDefaultUserConfig,ju as getGlobalConfigPath,Jl as getGlobalLogLevel,Lu as loadUserConfig,sd as mergeConfig,ql as setGlobalLogLevel,Ru as validateAndEnsureGlobalConfig,mu as validateShadowSourceProject};
|
|
265
|
+
`)}\n${e.content}`}async writeSteeringFile(e,t,n){let r=t.dirFromWorkspacePath,i=this.buildSteeringFileName(n),a=this.joinPath(r.basePath,r.path,af,$),o=this.joinPath(a,i),s={pathKind:P.Relative,path:this.joinPath(r.path,af,$,i),basePath:r.basePath,getDirectoryName:()=>$,getAbsolutePath:()=>o},c=this.buildSteeringContent(n);if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`steeringFile`,path:o}),{path:s,success:!0,skipped:!1};try{return this.ensureDirectory(a),this.writeFileSync(o,c),this.log.trace({action:`write`,type:`steeringFile`,path:o}),{path:s,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`steeringFile`,path:o,error:t}),{path:s,success:!1,error:e}}}};const cf=`AGENTS.md`;var lf=class extends iu{constructor(){super(`ProjectPromptInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{dependencyContext:t,fs:n,userConfigOptions:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(r),s=r.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=t.workspace;if(l==null)return this.log.warn(`No workspace found in dependency context, skipping project prompt enhancement`),{};let u=(l.projects??[]).map(t=>{let r=t.name;if(r==null)return t;let a=i.join(c,r);if(!n.existsSync(a)||!n.statSync(a).isDirectory())return t;let o=t.dirFromWorkspacePath?.getAbsolutePath(),s=this.readRootMemoryPrompt(e,a),l=o==null?[]:this.scanChildMemoryPrompts(e,a,o);return{...t,...s!=null&&{rootMemoryPrompt:s},...l.length>0&&{childMemoryPrompts:l}}});return{workspace:{directory:l.directory,projects:u}}}readRootMemoryPrompt(e,t){let{fs:n,path:r,logger:i}=e,a=r.join(t,cf);if(!(!n.existsSync(a)||!n.statSync(a).isFile()))try{let e=Gl(n.readFileSync(a,`utf-8`)),t=e.contentWithoutFrontMatter;return{type:dt.ProjectRootMemory,content:t,length:t.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Root,path:``,getDirectoryName:()=>``}}}catch(e){i.error(`Failed to read root memory prompt at ${a}`,{error:e});return}}scanChildMemoryPrompts(e,t,n){let{logger:r}=e,i=[];try{this.scanDirectoryRecursive(e,t,t,n,i)}catch(e){r.error(`Failed to scan child memory prompts at ${t}`,{error:e})}return i}scanDirectoryRecursive(e,t,n,r,i){let{fs:a,path:o}=e,s=a.readdirSync(n,{withFileTypes:!0});for(let c of s){if(!c.isDirectory()||c.name.startsWith(`.`)||c.name===`node_modules`)continue;let s=o.join(n,c.name),l=o.join(s,cf);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,cf);try{let e=Gl(i.readFileSync(s,`utf-8`)),o=e.contentWithoutFrontMatter,c=a.relative(t,n),l=a.join(r,c),u=a.basename(n);return{type:dt.ProjectChildrenMemory,content:o,length:o.length,filePathKind:P.Relative,...e.yamlFrontMatter!=null&&{yamlFrontMatter:e.yamlFrontMatter},...e.rawFrontMatter!=null&&{rawFrontMatter:e.rawFrontMatter},markdownAst:e.markdownAst,markdownContents:e.markdownContents,dir:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l},workingChildDirectoryPath:{pathKind:P.Relative,path:c,basePath:r,getDirectoryName:()=>u,getAbsolutePath:()=>l}}}catch(e){o.error(`Failed to read child memory prompt at ${s}`,{error:e});return}}};const uf=`README.md`;var df=class extends Z{constructor(){super(`ReadmeMdConfigFileOutputPlugin`,{outputFileName:uf})}async registerProjectOutputFiles(e){let t=[],{readmePrompts:n}=e.collectedInputContext;if(n==null||n.length===0)return t;for(let e of n){let n=e.targetDir,r=i.join(n.path,uf);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>i.join(n.basePath,r)})}return t}async canWrite(e){let{readmePrompts:t}=e.collectedInputContext;return t==null||t.length===0?(this.log.debug(`skipped`,{reason:`no README prompts to write`}),!1):!0}async writeProjectOutputs(e){let t=[],n=[],{readmePrompts:r}=e.collectedInputContext;if(r==null||r.length===0)return{files:t,dirs:n};for(let n of r){let r=await this.writeReadmeFile(e,n);t.push(r)}return{files:t,dirs:n}}async writeReadmeFile(e,t){let n=t.targetDir,a=i.join(n.path,uf),o=i.join(n.basePath,a),s=t.content,c={pathKind:P.Relative,path:a,basePath:n.basePath,getDirectoryName:()=>n.getDirectoryName(),getAbsolutePath:()=>o},l=t.isRoot?`project:${t.projectName}/README.md`:`project:${t.projectName}/${n.path}/README.md`;if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`readme`,path:o,label:l}),{path:c,success:!0,skipped:!1};try{let e=i.dirname(o);return r.existsSync(e)||r.mkdirSync(e,{recursive:!0}),r.writeFileSync(o,s,`utf-8`),this.log.trace({action:`write`,type:`readme`,path:o,label:l}),{path:c,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`readme`,path:o,label:l,error:t}),{path:c,success:!1,error:e}}}},ff=class extends iu{constructor(){super(`ReadmeMdInputPlugin`,[`ShadowProjectInputPlugin`])}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=[];if(!r.existsSync(c)||!r.statSync(c).isDirectory())return n.debug(`shadow projects directory does not exist`,{path:c}),{readmePrompts:l};try{let t=r.readdirSync(c,{withFileTypes:!0});for(let n of t){if(!n.isDirectory())continue;let t=n.name,r=i.join(c,t);this.collectReadmeFiles(e,r,t,a,``,l)}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{readmePrompts:l}}collectReadmeFiles(e,t,n,r,i,a){let{fs:o,path:s,logger:c}=e,l=i===``,u=s.join(t,`README.md`);if(o.existsSync(u)&&o.statSync(u).isFile())try{let e=o.readFileSync(u,`utf-8`),t=l?n:s.join(n,i),c={pathKind:P.Relative,path:t,basePath:r,getDirectoryName:()=>l?n:s.basename(i),getAbsolutePath:()=>s.resolve(r,t)},d={pathKind:P.Relative,path:s.dirname(u),basePath:r,getDirectoryName:()=>s.basename(s.dirname(u)),getAbsolutePath:()=>s.dirname(u)};a.push({type:dt.Readme,content:e,length:e.length,filePathKind:P.Relative,projectName:n,targetDir:c,isRoot:l,markdownContents:[],dir:d})}catch(e){c.warn(`failed to read README.md`,{path:u,error:e})}try{let c=o.readdirSync(t,{withFileTypes:!0});for(let o of c)if(o.isDirectory()){let c=l?o.name:s.join(i,o.name),u=s.join(t,o.name);this.collectReadmeFiles(e,u,n,r,c,a)}}catch(e){c.warn(`failed to scan directory`,{path:t,error:e})}}},pf=class extends iu{constructor(){super(`ShadowProjectInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowProjectsDir??Tt,c=this.resolvePath(s,a,o),l=i.basename(o),u=[];if(r.existsSync(c)&&r.statSync(c).isDirectory())try{let e=r.readdirSync(c,{withFileTypes:!0});for(let t of e)if(t.isDirectory()){let e=t.name===l;u.push({name:t.name,...e&&{isPromptSourceProject:!0},dirFromWorkspacePath:{pathKind:P.Relative,path:t.name,basePath:a,getDirectoryName:()=>t.name,getAbsolutePath:()=>i.resolve(a,t.name)}})}}catch(e){n.error(`failed to scan shadow projects`,{path:c,error:e})}return{workspace:{directory:{pathKind:P.Absolute,path:a,getDirectoryName:()=>i.basename(a)},projects:u}}}},mf=class extends iu{constructor(){super(`SkillInputPlugin`)}extractReferenceDocumentLinks(e){let t=[],n=e=>{if(e.type===`link`){let n=e,r=n.url;if(r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`))return;let i=[];for(let e of n.children)e.type===`text`&&e.value!=null&&i.push(e.value);t.push({text:i.join(``),path:r})}if(`children`in e&&Array.isArray(e.children))for(let t of e.children)n(t)};for(let t of e)n(t);return t}readReferenceDocuments(e,t,n,r){let a=[];for(let o of t){let t=i.resolve(e,o.path);if(!n.existsSync(t)){r.warn(`reference document not found`,{path:o.path,skillDir:e});continue}if(!n.statSync(t).isFile()){r.warn(`reference document path is not a file`,{path:o.path});continue}try{let r=Gl(n.readFileSync(t,`utf-8`)),s=r.contentWithoutFrontMatter,c=i.dirname(o.path);a.push({type:dt.SkillReferenceDocument,content:s,length:s.length,filePathKind:P.Relative,markdownAst:r.markdownAst,markdownContents:r.markdownContents,...r.rawFrontMatter!=null&&{rawFrontMatter:r.rawFrontMatter},dir:{pathKind:P.Relative,path:o.path,basePath:e,getDirectoryName:()=>c===`.`?``:c,getAbsolutePath:()=>t}})}catch(e){r.warn(`failed to read reference document`,{path:o.path,error:e})}}return a}collect(e){let{userConfigOptions:t,logger:n}=e,{workspaceDir:r,shadowProjectDir:a}=this.resolveBasePaths(t),o=t.shadowSkillSourceDir??St,s=this.resolvePath(o,r,a),c=[];if(e.fs.existsSync(s)&&e.fs.statSync(s).isDirectory())try{let t=e.fs.readdirSync(s,{withFileTypes:!0});for(let r of t)if(r.isDirectory()){let t=e.path.join(s,r.name,`SKILL.md`);if(e.fs.existsSync(t)&&e.fs.statSync(t).isFile()){let a=Gl(e.fs.readFileSync(t,`utf-8`)),o=a.contentWithoutFrontMatter,l=this.extractReferenceDocumentLinks(a.markdownContents),u=e.path.join(s,r.name),d=this.readReferenceDocuments(u,l,e.fs,n);c.push({type:dt.Skill,content:o,length:o.length,filePathKind:P.Relative,yamlFrontMatter:a.yamlFrontMatter??{name:r.name,description:``},...a.rawFrontMatter!=null&&{rawFrontMatter:a.rawFrontMatter},markdownAst:a.markdownAst,markdownContents:a.markdownContents,...d.length>0&&{referenceDocuments:d},dir:{pathKind:P.Relative,path:r.name,basePath:s,getDirectoryName:()=>r.name,getAbsolutePath:()=>i.join(s,r.name)}})}}}catch(e){n.error(`failed to scan skills`,{path:s,error:e})}return{skills:c}}},hf=class extends iu{constructor(){super(`SubAgentInputPlugin`)}collect(e){let{userConfigOptions:t,logger:n,fs:r,path:i}=e,{workspaceDir:a,shadowProjectDir:o}=this.resolveBasePaths(t),s=t.shadowSubAgentDir??wt,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=Gl(r.readFileSync(e,`utf-8`)),a=n.contentWithoutFrontMatter;l.push({type:dt.SubAgent,content:a,length:a.length,filePathKind:P.Relative,...n.yamlFrontMatter!=null&&{yamlFrontMatter:n.yamlFrontMatter},...n.rawFrontMatter!=null&&{rawFrontMatter:n.rawFrontMatter},markdownAst:n.markdownAst,markdownContents:n.markdownContents,dir:{pathKind:P.Relative,path:t.name,basePath:c,getDirectoryName:()=>t.name.replace(/\.md$/,``),getAbsolutePath:()=>e}})}}catch(e){n.error(`Failed to scan sub agents at ${c}`,{error:e})}return{subAgents:l}}};const gf=`WARP.md`;var _f=class extends Z{constructor(){super(`WarpIDEOutputPlugin`,{outputFileName:gf})}isAgentsPluginRegistered(e){return`registeredPluginNames`in e&&e.registeredPluginNames!=null?e.registeredPluginNames.includes(`AgentsOutputPlugin`):!1}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,r=this.isAgentsPluginRegistered(e);for(let e of n)if(e.dirFromWorkspacePath!=null){if(r)t.push(this.createFileRelativePath(e.dirFromWorkspacePath,gf));else if(e.rootMemoryPrompt!=null&&t.push(this.createFileRelativePath(e.dirFromWorkspacePath,gf)),e.childMemoryPrompts!=null)for(let n of e.childMemoryPrompts)n.dir!=null&&this.isRelativePath(n.dir)&&t.push(this.createFileRelativePath(n.dir,gf))}return t}async canWrite(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext;return t?r==null?(this.log.debug(`skipped`,{reason:`AgentsOutputPlugin registered but no global memory`}),!1):!0:n.projects.some(e=>e.rootMemoryPrompt!=null||(e.childMemoryPrompts?.length??0)>0)?!0:(this.log.debug(`skipped`,{reason:`no outputs to write`}),!1)}async writeProjectOutputs(e){let t=this.isAgentsPluginRegistered(e),{workspace:n,globalMemory:r}=e.collectedInputContext,{projects:i}=n,a=[],o=[];if(t){if(r==null)return{files:[],dirs:[]};for(let t of i){let n=t.dirFromWorkspacePath;if(n==null)continue;let i=t.name??`unknown`,o=await this.writePromptFile(e,n,r.content,`project:${i}/global-warp`);a.push(o)}return{files:a,dirs:o}}let s=this.extractGlobalMemoryContent(e);for(let t of i){let n=t.name??`unknown`,r=t.dirFromWorkspacePath;if(r!=null){if(t.rootMemoryPrompt!=null){let i=this.combineGlobalWithContent(s,t.rootMemoryPrompt.content),o=await this.writePromptFile(e,r,i,`project:${n}/root`);a.push(o)}if(t.childMemoryPrompts!=null)for(let r of t.childMemoryPrompts){let t=await this.writePromptFile(e,r.dir,r.content,`project:${n}/child:${r.workingChildDirectoryPath?.path??`unknown`}`);a.push(t)}}}return{files:a,dirs:o}}},vf=class extends iu{constructor(){super(`WorkspaceInputPlugin`)}collect(e){let{userConfigOptions:t}=e,{workspaceDir:n,shadowProjectDir:r}=this.resolveBasePaths(t),a=(t.externalProjects||[]).map(e=>{let t=this.resolvePath(e,n,r);return{name:i.basename(t),dirFromWorkspacePath:{pathKind:P.Relative,path:t,basePath:n,getDirectoryName:()=>i.basename(t)}}});return{workspace:{directory:{pathKind:P.Absolute,path:n,getDirectoryName:()=>i.basename(n)},projects:[]},shadowSourceProjectDir:r,...a.length>0&&{externalProjects:a}}}};const yf=`.vscode`,bf=[`.vscode/settings.json`,`.vscode/extensions.json`];var xf=class extends Z{constructor(){super(`VisualStudioCodeIDEConfigOutputPlugin`)}async registerProjectOutputFiles(e){let t=[],{projects:n}=e.collectedInputContext.workspace,{ideConfigFiles:r}=e.collectedInputContext;if(!r.some(e=>e.type===F.VSCode))return t;for(let e of n){let n=e.dirFromWorkspacePath;if(n!=null&&e.isPromptSourceProject!==!0)for(let e of bf){let r=this.joinPath(n.path,e);t.push({pathKind:P.Relative,path:r,basePath:n.basePath,getDirectoryName:()=>this.dirname(e),getAbsolutePath:()=>this.resolvePath(n.basePath,r)})}}return t}async canWrite(e){let{ideConfigFiles:t}=e.collectedInputContext;return t.some(e=>e.type===F.VSCode)?!0:(this.log.debug(`skipped`,{reason:`no VS Code config files found`}),!1)}async writeProjectOutputs(e){let{projects:t}=e.collectedInputContext.workspace,{ideConfigFiles:n}=e.collectedInputContext,r=[],i=[],a=n.filter(e=>e.type===F.VSCode);for(let n of t){let t=n.dirFromWorkspacePath;if(t==null)continue;let i=n.name??`unknown`;for(let n of a){let a=await this.writeConfigFile(e,t,n,`project:${i}`);r.push(a)}}return{files:r,dirs:i}}async writeConfigFile(e,t,n,r){let i=this.getTargetRelativePath(n),a=this.resolvePath(t.basePath,t.path,i),o={pathKind:P.Relative,path:this.joinPath(t.path,i),basePath:t.basePath,getDirectoryName:()=>this.dirname(i),getAbsolutePath:()=>a};if(e.dryRun===!0)return this.log.trace({action:`dryRun`,type:`config`,path:a,label:r}),{path:o,success:!0,skipped:!1};try{let e=this.dirname(a);return this.ensureDirectory(e),this.writeFileSync(a,n.content),this.log.trace({action:`write`,type:`config`,path:a,label:r}),{path:o,success:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return this.log.error({action:`write`,type:`config`,path:a,label:r,error:t}),{path:o,success:!1,error:e}}}getTargetRelativePath(e){let t=e.dir.path;if(e.type===F.VSCode){let e=t.indexOf(yf);return e===-1?this.joinPath(yf,this.basename(t)):t.substring(e)}return this.basename(t)}},Sf=xd({plugins:[new Cd,new Dd,new Pd,new Bd,new qd,new Zd,new sf,new _f,new nf,new xf,new df,new vf,new pf,new Td,new $d,new mf,new Jd,new hf,new Qd,new lf,new ff]}),Cf=Sf;async function wf(){await new pd(...n.argv).run(Sf)}wf().catch(e=>{console.error(e)});export{iu as AbstractInputPlugin,Z as AbstractOutputPlugin,ru as AbstractPlugin,gt as CircularDependencyError,ft as ClaudeCodeCLISubAgentColors,pt as CodingAgentTools,Uu as ConfigLoader,Ru as DEFAULT_CONFIG_FILE_NAME,zu as DEFAULT_GLOBAL_CONFIG_DIR,Et as DEFAULT_GLOBAL_MEMORY_FILE,Ct as DEFAULT_SHADOW_FAST_COMMAND_DIR,Tt as DEFAULT_SHADOW_PROJECTS_DIR,xt as DEFAULT_SHADOW_PROJECT_SUFFIX,St as DEFAULT_SHADOW_SKILL_SOURCE_DIR,vt as DEFAULT_SHADOW_SOURCE_PROJECT_STRUCTURE,wt as DEFAULT_SHADOW_SUB_AGENT_DIR,bt as DEFAULT_WORKSPACE_DIR,P as FilePathKind,ht as GlobalConfigDirectoryType,F as IDEKind,_t as MissingDependencyError,mt as NamingCaseKind,yt as PathPlaceholders,ut as PluginKind,dt as PromptKind,I as SHADOW_SOURCE_DIR_NAMES,L as SHADOW_SOURCE_FILE_NAMES,R as SHADOW_SOURCE_RELATIVE_PATHS,tt as checkCanClean,rt as checkCanWrite,et as collectAllPluginOutputs,nu as createLogger,Cf as default,xd as defineConfig,nt as executeOnCleanComplete,it as executeWriteOutputs,yu as generateShadowSourceProject,Gu as getConfigLoader,Vu as getDefaultUserConfig,Bu as getGlobalConfigPath,Jl as getGlobalLogLevel,Ku as loadUserConfig,gd as mergeConfig,ql as setGlobalLogLevel,qu as validateAndEnsureGlobalConfig,mu as validateShadowSourceProject};
|