-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheef.js
More file actions
368 lines (328 loc) · 12.7 KB
/
Copy patheef.js
File metadata and controls
368 lines (328 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/usr/bin/env node
"use strict";
/**
* eef-install — installer CLI for Ekosistem Edho Ferdian (EEF).
*
* Zero runtime dependencies on purpose (matches this ecosystem's own
* "standalone, no dependency" design) — plain Node `fs`/`path` only, no
* argument-parsing library. This CLI ships the actual skill content inside
* the published npm package (see package.json's `files` list), the same
* way `ecc-universal` bundles its own content rather than shelling out to
* `git clone` at install time — no git required, works offline once
* installed.
*/
const fs = require("fs");
const path = require("path");
const os = require("os");
const PKG_ROOT = path.resolve(__dirname, "..");
const SKILLS_DIR = path.join(PKG_ROOT, "skills");
const TARGETS = {
claude: {
label: "Claude Code",
scope: "global (or $CLAUDE_SKILLS_DIR)",
install(skillNames) {
const destRoot = process.env.CLAUDE_SKILLS_DIR || path.join(os.homedir(), ".claude", "skills");
fs.mkdirSync(destRoot, { recursive: true });
const names = skillNames.length ? skillNames : listSkillNames();
let count = 0;
for (const name of names) {
const src = path.join(SKILLS_DIR, name);
if (!fs.existsSync(src)) {
console.warn(`Skip: no such skill '${name}'`);
continue;
}
const dest = path.join(destRoot, name);
fs.rmSync(dest, { recursive: true, force: true });
fs.cpSync(src, dest, { recursive: true });
console.log(`Installed: ${name} -> ${dest}`);
count++;
}
console.log(`\nDone. ${count} skill(s) installed to ${destRoot}`);
},
},
cursor: {
label: "Cursor",
scope: "project (current directory)",
install() {
copyDirInto(path.join(PKG_ROOT, ".cursor", "rules"), path.join(process.cwd(), ".cursor", "rules"));
},
},
windsurf: {
label: "Windsurf + Devin",
scope: "project (current directory)",
install() {
copyDirInto(path.join(PKG_ROOT, ".windsurf", "rules"), path.join(process.cwd(), ".windsurf", "rules"));
copyDirInto(path.join(PKG_ROOT, ".devin", "rules"), path.join(process.cwd(), ".devin", "rules"));
},
},
cline: {
label: "Cline",
scope: "project (current directory)",
install() {
copyDirInto(path.join(PKG_ROOT, ".clinerules"), path.join(process.cwd(), ".clinerules"));
},
},
copilot: {
label: "GitHub Copilot",
scope: "project (current directory)",
install() {
const src = path.join(PKG_ROOT, ".github", "copilot-instructions.md");
const destDir = path.join(process.cwd(), ".github");
fs.mkdirSync(destDir, { recursive: true });
const dest = path.join(destDir, "copilot-instructions.md");
fs.copyFileSync(src, dest);
console.log(`Installed: ${dest}`);
},
},
hermes: {
label: "Hermes Agent",
scope: "project by default, --global for ~/.hermes",
install(_skillNames, opts) {
const destRoot = opts.global
? path.join(os.homedir(), ".hermes", "skills")
: path.join(process.cwd(), ".hermes", "skills");
copyDirInto(path.join(PKG_ROOT, ".hermes", "skills"), destRoot);
},
},
openclaw: {
label: "OpenClaw",
scope: "project by default, --global for ~/.agents",
install(_skillNames, opts) {
const destRoot = opts.global
? path.join(os.homedir(), ".agents", "skills")
: path.join(process.cwd(), ".agents", "skills");
copyDirInto(path.join(PKG_ROOT, ".agents", "skills"), destRoot);
},
},
kiro: {
label: "Kiro",
scope: "project by default, --global for ~/.kiro",
install(_skillNames, opts) {
const destRoot = opts.global
? path.join(os.homedir(), ".kiro", "skills")
: path.join(process.cwd(), ".kiro", "skills");
copyDirInto(path.join(PKG_ROOT, ".kiro", "skills"), destRoot);
},
},
zcode: {
label: "ZCode (Z.ai)",
scope: "project by default, --global for ~/.zcode",
install(_skillNames, opts) {
const destRoot = opts.global
? path.join(os.homedir(), ".zcode", "skills")
: path.join(process.cwd(), ".zcode", "skills");
copyDirInto(path.join(PKG_ROOT, ".zcode", "skills"), destRoot);
},
},
"claude-agents": {
label: "Claude Code sub-agents (agents/*/AGENT.md roster)",
scope: "global (or $CLAUDE_AGENTS_DIR)",
install() {
const destRoot = process.env.CLAUDE_AGENTS_DIR || path.join(os.homedir(), ".claude", "agents");
copyDirInto(path.join(PKG_ROOT, ".claude", "agents"), destRoot);
},
},
"claude-rules": {
label: "Claude Code always-on rules (rules/*.md, loaded every session)",
scope: "global (or $CLAUDE_RULES_DIR)",
install() {
const destRoot = process.env.CLAUDE_RULES_DIR || path.join(os.homedir(), ".claude", "rules", "eef");
copyDirInto(path.join(PKG_ROOT, "rules"), destRoot);
},
},
"opencode-agents": {
label: "OpenCode sub-agents (merged into opencode.json, never overwritten)",
scope: "project by default, --global for ~/.config/opencode",
install(_skillNames, opts) {
const destRoot = opts.global
? path.join(os.homedir(), ".config", "opencode")
: process.cwd();
mergeOpencodeAgents(destRoot);
},
},
"zcode-agents": {
label: "ZCode sub-agents (added to ~/.zcode/agents/, existing files never touched)",
scope: "global only (or $ZCODE_AGENTS_DIR — no confirmed project-local Subagent directory)",
install() {
const destRoot = process.env.ZCODE_AGENTS_DIR || path.join(os.homedir(), ".zcode", "agents");
const srcDir = path.join(PKG_ROOT, "dist", "agents", "zcode");
fs.mkdirSync(destRoot, { recursive: true });
let count = 0;
for (const file of fs.readdirSync(srcDir)) {
if (!file.endsWith(".md")) continue;
fs.copyFileSync(path.join(srcDir, file), path.join(destRoot, file));
console.log(`Installed: ${file} -> ${destRoot}`);
count++;
}
console.log(`\nDone. ${count} agent(s) installed to ${destRoot} (other files there untouched).`);
},
},
"agents-md": {
label: "AGENTS.md (Codex, OpenCode, Muse Code, Zed, Antigravity, Cline fallback, ...)",
scope: "project (current directory)",
install() {
copyFileInto(path.join(PKG_ROOT, "AGENTS.md"), path.join(process.cwd(), "AGENTS.md"));
},
},
"gemini-md": {
label: "Gemini CLI",
scope: "project (current directory)",
install() {
copyFileInto(path.join(PKG_ROOT, "GEMINI.md"), path.join(process.cwd(), "GEMINI.md"));
},
},
pi: {
label: "Pi (@earendil-works/pi-coding-agent)",
scope: "no files to copy",
install() {
console.log("Pi resolves a standard skills/ folder directly, no install step needed here.");
console.log("Run this instead: pi install git:github.com/edhoferdian/EEF");
},
},
};
function listSkillNames() {
return fs
.readdirSync(SKILLS_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => d.name)
.sort();
}
function copyDirInto(src, dest) {
if (!fs.existsSync(src)) {
console.error(`Error: ${src} not found in this package — reinstall eef-install.`);
process.exitCode = 1;
return;
}
fs.mkdirSync(dest, { recursive: true });
fs.cpSync(src, dest, { recursive: true });
const count = fs.readdirSync(dest).length;
console.log(`Installed: ${dest} (${count} file(s))`);
}
function copyFileInto(src, dest) {
fs.copyFileSync(src, dest);
console.log(`Installed: ${dest}`);
}
/**
* Merge every dist/agents/opencode/*.agent.json fragment's "agent" block
* into destRoot/opencode.json, without touching any other key in that
* file — a consumer's own mcp/plugin/command config lives in the same
* file and must survive this untouched (this is exactly the mistake this
* ecosystem's own ECC-decommissioning pass had to route around: never
* write a whole config file wholesale when it might carry a user's own
* settings). Existing agents not in this package's roster are preserved;
* an agent with the same name as one already in the file is overwritten
* (this package is the source of truth for its own -edho-ferdian agents).
*
* Also copies each referenced prompts/agents/<name>.txt alongside the
* config, since opencode.json's prompt field is a {file:...} reference
* relative to opencode.json's own directory.
*
* Logs "Added"/"Updated"/"Unchanged" per agent so an overwrite of a
* pre-existing (possibly hand-edited) entry is never silent — found by
* code-reviewer-edho-ferdian's own review of this file: the previous
* single "Merged agent: X" message for every case made a real overwrite
* of a customized entry indistinguishable from a first-time add.
*/
function mergeOpencodeAgents(destRoot) {
const srcDir = path.join(PKG_ROOT, "dist", "agents", "opencode");
if (!fs.existsSync(srcDir)) {
console.error(`Error: ${srcDir} not found in this package — reinstall eef-install.`);
process.exitCode = 1;
return;
}
const configPath = path.join(destRoot, "opencode.json");
let config = { $schema: "https://opencode.ai/config.json" };
if (fs.existsSync(configPath)) {
try {
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
} catch (err) {
console.error(`Error: ${configPath} exists but is not valid JSON — refusing to touch it.`);
console.error(`Fix or remove it, then re-run this install. (${err.message})`);
process.exitCode = 1;
return;
}
}
config.agent = config.agent || {};
const promptsDestDir = path.join(destRoot, "prompts", "agents");
fs.mkdirSync(promptsDestDir, { recursive: true });
let count = 0;
for (const file of fs.readdirSync(srcDir)) {
if (!file.endsWith(".agent.json")) continue;
const fragment = JSON.parse(fs.readFileSync(path.join(srcDir, file), "utf8"));
for (const [name, def] of Object.entries(fragment.agent || {})) {
const existing = config.agent[name];
if (existing === undefined) {
console.log(`Added agent: ${name}`);
} else if (JSON.stringify(existing) !== JSON.stringify(def)) {
console.log(`Updated agent: ${name} (replaced a differing entry already in opencode.json — any hand edits to it are gone)`);
} else {
console.log(`Unchanged agent: ${name}`);
}
config.agent[name] = def;
count++;
}
}
const promptsSrcDir = path.join(srcDir, "prompts", "agents");
if (fs.existsSync(promptsSrcDir)) {
for (const file of fs.readdirSync(promptsSrcDir)) {
fs.copyFileSync(path.join(promptsSrcDir, file), path.join(promptsDestDir, file));
}
}
fs.mkdirSync(destRoot, { recursive: true });
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
console.log(`\nDone. ${count} agent(s) merged into ${configPath} (other keys in that file untouched).`);
}
function printHelp() {
console.log(`eef-install — install Ekosistem Edho Ferdian's skills
Usage:
eef-install Install all 38 skills for Claude Code
eef-install <skill> [<skill> ...] Install only these skills for Claude Code
eef-install --list List all installable skill names
eef-install --target <name> Install for a different harness (see below)
eef-install --help Show this message
Targets (--target):
`);
const widest = Math.max(...Object.keys(TARGETS).map((k) => k.length));
for (const [key, t] of Object.entries(TARGETS)) {
console.log(` ${key.padEnd(widest + 1)} ${t.label} — ${t.scope}`);
}
console.log(`
Env vars:
CLAUDE_SKILLS_DIR Install location for --target claude (default: ~/.claude/skills)
CLAUDE_AGENTS_DIR Install location for --target claude-agents (default: ~/.claude/agents)
CLAUDE_RULES_DIR Install location for --target claude-rules (default: ~/.claude/rules/eef)
ZCODE_AGENTS_DIR Install location for --target zcode-agents (default: ~/.zcode/agents)
Examples:
eef-install
eef-install code-review-edho-ferdian dev-kickoff-edho-ferdian
eef-install --target cursor
eef-install --target kiro --global
`);
}
function main() {
const args = process.argv.slice(2);
if (args.includes("--help") || args.includes("-h")) {
printHelp();
return;
}
if (args.includes("--list")) {
for (const name of listSkillNames()) console.log(name);
return;
}
const targetIdx = args.indexOf("--target");
const targetName = targetIdx !== -1 ? args[targetIdx + 1] : "claude";
const target = TARGETS[targetName];
if (!target) {
console.error(`Unknown target '${targetName}'. Valid targets: ${Object.keys(TARGETS).join(", ")}`);
process.exitCode = 2;
return;
}
const opts = { global: args.includes("--global") };
const skillNames = args.filter((a, i) => {
if (a.startsWith("-")) return false;
if (i > 0 && args[i - 1] === "--target") return false;
return true;
});
target.install(skillNames, opts);
}
main();