@melonbuild/create 0.0.0-stage → 0.2.1

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/src/agents.mjs ADDED
@@ -0,0 +1,55 @@
1
+ // Registry of AI coding agents that can load the MelonBuild Skill.
2
+ // To support a new agent, add one entry. Research notes and sources: docs/agents-research.md.
3
+ //
4
+ // Path tokens: "~" = home directory, "$XDG_CONFIG_HOME" (defaults to ~/.config), "%LOCALAPPDATA%".
5
+ // skills Global (user-level) skills directory.
6
+ // win32 Optional Windows override for `skills` (default: same path under the home directory).
7
+ // project Project-level skills directory, relative to the project root.
8
+ // shared true when the agent also reads the shared ~/.agents/skills (or .agents/skills in a project).
9
+ // Such agents get the shared copy only, so the Skill is not listed twice.
10
+ // detect Installed if any directory exists or any binary is on PATH.
11
+ // env Environment variable that relocates the agent's config dir; skills live in "<env>/skills".
12
+
13
+ /** @typedef {{id:string,name:string,region:'intl'|'cn',skills:string,win32?:string,project:string|null,shared:boolean,detect:{dirs?:string[],bins?:string[],apps?:string[]},env?:string}} Agent */
14
+
15
+ /** The shared location read by many agents. Always installed. */
16
+ export const SHARED={id:'shared',name:'Shared (~/.agents/skills)',skills:'~/.agents/skills',project:'.agents/skills'};
17
+
18
+ /** @type {Agent[]} */
19
+ export const AGENTS=[
20
+ {id:'claude-code',name:'Claude Code',region:'intl',skills:'~/.claude/skills',project:'.claude/skills',shared:false,env:'CLAUDE_CONFIG_DIR',detect:{dirs:['~/.claude'],bins:['claude']}},
21
+ {id:'codex',name:'OpenAI Codex',region:'intl',skills:'~/.agents/skills',project:'.agents/skills',shared:true,detect:{dirs:['~/.codex'],bins:['codex'],apps:['/Applications/Codex.app']}},
22
+ {id:'cursor',name:'Cursor',region:'intl',skills:'~/.cursor/skills',project:'.cursor/skills',shared:false,detect:{dirs:['~/.cursor'],bins:['cursor','cursor-agent'],apps:['/Applications/Cursor.app']}},
23
+ {id:'github-copilot',name:'GitHub Copilot',region:'intl',skills:'~/.copilot/skills',project:'.github/skills',shared:true,detect:{dirs:['~/.copilot','~/.vscode/extensions/github.copilot-chat-*'],bins:['copilot']}},
24
+ {id:'windsurf',name:'Windsurf',region:'intl',skills:'~/.codeium/windsurf/skills',project:'.windsurf/skills',shared:false,detect:{dirs:['~/.codeium/windsurf'],bins:['windsurf'],apps:['/Applications/Windsurf.app']}},
25
+ {id:'gemini-cli',name:'Gemini CLI',region:'intl',skills:'~/.gemini/skills',project:'.gemini/skills',shared:true,detect:{dirs:['~/.gemini'],bins:['gemini']}},
26
+ {id:'antigravity',name:'Google Antigravity',region:'intl',skills:'~/.gemini/config/skills',project:'.agents/skills',shared:false,detect:{dirs:['~/.gemini/antigravity','~/.gemini/antigravity-cli','~/.gemini/config'],bins:['agy','antigravity'],apps:['/Applications/Antigravity.app']}},
27
+ {id:'opencode',name:'OpenCode',region:'intl',skills:'$XDG_CONFIG_HOME/opencode/skills',project:'.opencode/skills',shared:true,detect:{dirs:['$XDG_CONFIG_HOME/opencode'],bins:['opencode']}},
28
+ {id:'cline',name:'Cline',region:'intl',skills:'~/.cline/skills',project:'.cline/skills',shared:false,detect:{dirs:['~/.cline','~/.vscode/extensions/saoudrizwan.claude-dev-*'],bins:['cline']}},
29
+ {id:'roo-code',name:'Roo Code',region:'intl',skills:'~/.roo/skills',project:'.roo/skills',shared:false,detect:{dirs:['~/.roo','~/.vscode/extensions/rooveterinaryinc.roo-cline-*']}},
30
+ {id:'kilo-code',name:'Kilo Code',region:'intl',skills:'~/.kilo/skills',project:'.kilo/skills',shared:true,detect:{dirs:['~/.kilo','~/.kilocode','~/.vscode/extensions/kilocode.kilo-code-*'],bins:['kilo']}},
31
+ {id:'augment',name:'Augment',region:'intl',skills:'~/.augment/skills',project:'.augment/skills',shared:true,detect:{dirs:['~/.augment'],bins:['auggie']}},
32
+ {id:'amp',name:'Amp',region:'intl',skills:'$XDG_CONFIG_HOME/agents/skills',project:'.agents/skills',shared:true,detect:{dirs:['$XDG_CONFIG_HOME/amp'],bins:['amp']}},
33
+ {id:'factory-droid',name:'Factory Droid',region:'intl',skills:'~/.factory/skills',project:'.factory/skills',shared:true,detect:{dirs:['~/.factory'],bins:['droid']}},
34
+ {id:'goose',name:'Goose',region:'intl',skills:'~/.agents/skills',project:'.agents/skills',shared:true,detect:{dirs:['$XDG_CONFIG_HOME/goose'],bins:['goose'],apps:['/Applications/Goose.app']}},
35
+ {id:'junie',name:'JetBrains Junie',region:'intl',skills:'~/.junie/skills',project:'.junie/skills',shared:false,detect:{dirs:['~/.junie'],bins:['junie']}},
36
+ {id:'zed',name:'Zed',region:'intl',skills:'~/.agents/skills',project:'.agents/skills',shared:true,detect:{dirs:['$XDG_CONFIG_HOME/zed'],bins:['zed'],apps:['/Applications/Zed.app']}},
37
+ {id:'warp',name:'Warp',region:'intl',skills:'~/.agents/skills',project:'.agents/skills',shared:true,detect:{dirs:['~/.warp'],bins:['warp','oz'],apps:['/Applications/Warp.app']}},
38
+ {id:'kiro',name:'Kiro',region:'intl',skills:'~/.kiro/skills',project:'.kiro/skills',shared:false,detect:{dirs:['~/.kiro'],bins:['kiro','kiro-cli'],apps:['/Applications/Kiro.app']}},
39
+ {id:'continue',name:'Continue',region:'intl',skills:'~/.continue/skills',project:'.continue/skills',shared:false,detect:{dirs:['~/.continue'],bins:['cn']}},
40
+ {id:'crush',name:'Crush',region:'intl',skills:'$XDG_CONFIG_HOME/crush/skills',win32:'%LOCALAPPDATA%/crush/skills',project:'.crush/skills',shared:true,detect:{dirs:['$XDG_CONFIG_HOME/crush'],bins:['crush']}},
41
+ {id:'trae',name:'Trae',region:'intl',skills:'~/.trae/skills',project:'.trae/skills',shared:false,detect:{dirs:['~/.trae'],bins:['trae'],apps:['/Applications/Trae.app']}},
42
+ {id:'qoder',name:'Qoder',region:'cn',skills:'~/.qoder/skills',project:'.qoder/skills',shared:false,detect:{dirs:['~/.qoder'],bins:['qodercli','qoder'],apps:['/Applications/Qoder.app']}},
43
+ {id:'qoder-cn',name:'Qoder CN',region:'cn',skills:'~/.qoder-cn/skills',project:'.qoder/skills',shared:false,detect:{dirs:['~/.qoder-cn']}},
44
+ {id:'trae-cn',name:'Trae CN',region:'cn',skills:'~/.trae-cn/skills',project:'.trae/skills',shared:false,detect:{dirs:['~/.trae-cn'],bins:['trae-cn'],apps:['/Applications/Trae CN.app']}},
45
+ {id:'lingma',name:'Lingma 通义灵码',region:'cn',skills:'~/.lingma/skills',project:'.lingma/skills',shared:false,detect:{dirs:['~/.lingma'],apps:['/Applications/Lingma.app']}},
46
+ {id:'codebuddy',name:'CodeBuddy',region:'cn',skills:'~/.codebuddy/skills',project:'.codebuddy/skills',shared:false,detect:{dirs:['~/.codebuddy'],bins:['codebuddy','cbc'],apps:['/Applications/CodeBuddy.app','/Applications/CodeBuddy CN.app']}},
47
+ {id:'qwen-code',name:'Qwen Code',region:'cn',skills:'~/.qwen/skills',project:'.qwen/skills',shared:true,detect:{dirs:['~/.qwen'],bins:['qwen']}},
48
+ {id:'kimi-code',name:'Kimi Code',region:'cn',skills:'~/.kimi-code/skills',project:'.kimi-code/skills',shared:true,env:'KIMI_CODE_HOME',detect:{dirs:['~/.kimi-code','~/.kimi'],bins:['kimi']}},
49
+ {id:'comate',name:'Comate 文心快码',region:'cn',skills:'~/.comate/skills',project:'.comate/skills',shared:false,detect:{dirs:['~/.comate']}},
50
+ {id:'zcode',name:'ZCode',region:'cn',skills:'~/.zcode/skills',project:null,shared:false,detect:{dirs:['~/.zcode'],apps:['/Applications/ZCode.app']}},
51
+ {id:'joycode',name:'JoyCode',region:'cn',skills:'~/.joycode/skills',project:'.joycode/skills',shared:false,detect:{dirs:['~/.joycode']}},
52
+ {id:'minimax-code',name:'MiniMax Code',region:'cn',skills:'~/.minimax/skills',project:'.minimax/skills',shared:false,detect:{dirs:['~/.minimax'],apps:['/Applications/MiniMax Code.app']}},
53
+ {id:'codearts-agent',name:'CodeArts Agent',region:'cn',skills:'~/.codeartsdoer/skills',project:'.codeartsdoer/skills',shared:false,detect:{dirs:['~/.codeartsdoer']}},
54
+ {id:'iflow-cli',name:'iFlow CLI',region:'cn',skills:'~/.iflow/skills',project:'.iflow/skills',shared:false,detect:{dirs:['~/.iflow'],bins:['iflow']}},
55
+ ];
@@ -0,0 +1,116 @@
1
+ import {cpSync,existsSync,mkdirSync,readdirSync,readFileSync,rmSync,statSync} from 'node:fs';
2
+ import {delimiter,dirname,join,resolve} from 'node:path';
3
+ import {AGENTS,SHARED} from './agents.mjs';
4
+
5
+ export const SKILL_NAME='melonbuild';
6
+ /** Files and folders that make up the installed Skill. */
7
+ export const SKILL_FILES=['SKILL.md','references','scripts'];
8
+
9
+ /**
10
+ * @typedef {{home:string,env:Record<string,string|undefined>,platform:NodeJS.Platform,cwd:string}} Context
11
+ * @typedef {import('./agents.mjs').Agent} Agent
12
+ * @typedef {{dir:string,agents:string[]}} Target dir = the skills directory; the Skill goes into dir/melonbuild
13
+ */
14
+
15
+ /** Expands ~, $XDG_CONFIG_HOME and %LOCALAPPDATA% / %APPDATA% in a registry path. */
16
+ export function expand(path,ctx) {
17
+ const xdg=ctx.env.XDG_CONFIG_HOME||join(ctx.home,'.config');
18
+ const local=ctx.env.LOCALAPPDATA||join(ctx.home,'AppData','Local');
19
+ const roaming=ctx.env.APPDATA||join(ctx.home,'AppData','Roaming');
20
+ return resolve(path
21
+ .replace(/^\$XDG_CONFIG_HOME(?=\/|$)/,()=>xdg)
22
+ .replace(/^%LOCALAPPDATA%(?=\/|$)/,()=>local)
23
+ .replace(/^%APPDATA%(?=\/|$)/,()=>roaming)
24
+ .replace(/^~(?=\/|$)/,()=>ctx.home));
25
+ }
26
+
27
+ /** Global skills directory for an agent on this machine. */
28
+ export function globalDir(agent,ctx) {
29
+ if(agent.env&&ctx.env[agent.env])return join(resolve(ctx.env[agent.env]),'skills');
30
+ return expand(ctx.platform==='win32'&&agent.win32?agent.win32:agent.skills,ctx);
31
+ }
32
+
33
+ function onPath(bin,ctx) {
34
+ const exts=ctx.platform==='win32'?['.exe','.cmd','.bat','']:[''];
35
+ for(const dir of (ctx.env.PATH??ctx.env.Path??'').split(delimiter)) {
36
+ if(!dir)continue;
37
+ for(const ext of exts)try{if(statSync(join(dir,bin+ext)).isFile())return true;}catch{}
38
+ }
39
+ return false;
40
+ }
41
+ function dirExists(pattern,ctx) {
42
+ const path=expand(pattern,ctx);
43
+ if(!path.endsWith('*'))return existsSync(path);
44
+ // Trailing wildcard in the last segment, e.g. ~/.vscode/extensions/publisher.name-*
45
+ const parent=dirname(path),prefix=path.slice(parent.length+1,-1);
46
+ try{return readdirSync(parent).some(name=>name.startsWith(prefix));}catch{return false;}
47
+ }
48
+ /** True if the agent looks installed: a config dir exists, a binary is on PATH, or (macOS) its app exists. */
49
+ export function isInstalled(agent,ctx) {
50
+ const d=agent.detect;
51
+ if(agent.env&&ctx.env[agent.env]&&existsSync(ctx.env[agent.env]))return true;
52
+ return (d.dirs??[]).some(p=>dirExists(p,ctx))||(d.bins??[]).some(b=>onPath(b,ctx))||
53
+ (ctx.platform==='darwin'&&(d.apps??[]).some(a=>existsSync(a)));
54
+ }
55
+ export function detect(ctx,agents=AGENTS){return agents.filter(a=>isInstalled(a,ctx));}
56
+
57
+ /**
58
+ * Where to put the Skill. The shared directory is always included; agents that read it are
59
+ * served by that copy, every other agent gets its own copy.
60
+ * @returns {Target[]}
61
+ */
62
+ export function plan(selected,ctx,{project=false}={}) {
63
+ const targets=new Map();
64
+ const add=(dir,name)=>{const t=targets.get(dir)??{dir,agents:[]};if(name&&!t.agents.includes(name))t.agents.push(name);targets.set(dir,t);};
65
+ const sharedDir=project?resolve(ctx.cwd,SHARED.project):expand(SHARED.skills,ctx);
66
+ add(sharedDir);
67
+ for(const agent of selected) {
68
+ if(project) {
69
+ if(!agent.project)continue;
70
+ const dir=resolve(ctx.cwd,agent.project);
71
+ add(agent.shared?sharedDir:dir,agent.name);
72
+ }else add(agent.shared?sharedDir:globalDir(agent,ctx),agent.name);
73
+ }
74
+ return [...targets.values()];
75
+ }
76
+
77
+ /** True when dir holds a MelonBuild Skill (never touch anything else). */
78
+ export function isOurs(dir) {
79
+ try{return /^name:\s*melonbuild\s*$/m.test(readFileSync(join(dir,'SKILL.md'),'utf8'));}catch{return false;}
80
+ }
81
+ export function installedVersion(dir) {
82
+ try{return /^\s+version:\s*(\S+)\s*$/m.exec(readFileSync(join(dir,'SKILL.md'),'utf8'))?.[1]??null;}catch{return null;}
83
+ }
84
+
85
+ /**
86
+ * Copies the Skill into each target. An existing folder is replaced only when it is a MelonBuild Skill.
87
+ * @returns {{dir:string,agents:string[],status:'installed'|'updated'|'skipped',reason?:string}[]}
88
+ */
89
+ export function install(targets,source) {
90
+ return targets.map(t=>{
91
+ const dest=join(t.dir,SKILL_NAME);
92
+ try {
93
+ let status='installed';
94
+ if(existsSync(dest)) {
95
+ if(!isOurs(dest))return {...t,dest,status:'skipped',reason:'exists'};
96
+ for(const f of SKILL_FILES)rmSync(join(dest,f),{recursive:true,force:true});
97
+ status='updated';
98
+ }
99
+ mkdirSync(dest,{recursive:true});
100
+ for(const f of SKILL_FILES)cpSync(join(source,f),join(dest,f),{recursive:true});
101
+ return {...t,dest,status};
102
+ }catch(e){return {...t,dest,status:'skipped',reason:e?.code??'error'};}
103
+ });
104
+ }
105
+
106
+ /** Removes MelonBuild Skill folders from every known location (global and, optionally, this project). */
107
+ export function uninstall(ctx,{project=false}={}) {
108
+ const dirs=new Set([expand(SHARED.skills,ctx),...AGENTS.map(a=>globalDir(a,ctx))]);
109
+ if(project)for(const a of [SHARED,...AGENTS])if(a.project)dirs.add(resolve(ctx.cwd,a.project));
110
+ const removed=[];
111
+ for(const dir of dirs) {
112
+ const dest=join(dir,SKILL_NAME);
113
+ if(isOurs(dest)){rmSync(dest,{recursive:true,force:true});removed.push(dest);}
114
+ }
115
+ return removed;
116
+ }