agentpacks 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +32 -0
- package/dist/api.js +2852 -0
- package/dist/cli/export-cmd.d.ts +12 -0
- package/dist/cli/export-cmd.js +786 -0
- package/dist/cli/generate.d.ts +13 -0
- package/dist/cli/generate.js +2018 -0
- package/dist/cli/import-cmd.d.ts +9 -0
- package/dist/cli/import-cmd.js +691 -0
- package/dist/cli/init.d.ts +5 -0
- package/dist/cli/init.js +214 -0
- package/dist/cli/install.d.ts +11 -0
- package/dist/cli/install.js +610 -0
- package/dist/cli/pack/create.d.ts +4 -0
- package/dist/cli/pack/create.js +175 -0
- package/dist/cli/pack/enable.d.ts +8 -0
- package/dist/cli/pack/enable.js +96 -0
- package/dist/cli/pack/list.d.ts +4 -0
- package/dist/cli/pack/list.js +699 -0
- package/dist/cli/pack/validate.d.ts +4 -0
- package/dist/cli/pack/validate.js +364 -0
- package/dist/core/config.d.ts +77 -0
- package/dist/core/config.js +181 -0
- package/dist/core/dependency-resolver.d.ts +38 -0
- package/dist/core/dependency-resolver.js +151 -0
- package/dist/core/feature-merger.d.ts +61 -0
- package/dist/core/feature-merger.js +139 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +924 -0
- package/dist/core/lockfile.d.ts +50 -0
- package/dist/core/lockfile.js +72 -0
- package/dist/core/metarepo.d.ts +26 -0
- package/dist/core/metarepo.js +218 -0
- package/dist/core/pack-loader.d.ts +61 -0
- package/dist/core/pack-loader.js +646 -0
- package/dist/exporters/cursor-plugin.d.ts +29 -0
- package/dist/exporters/cursor-plugin.js +258 -0
- package/dist/exporters/index.d.ts +1 -0
- package/dist/exporters/index.js +258 -0
- package/dist/features/agents.d.ts +48 -0
- package/dist/features/agents.js +190 -0
- package/dist/features/commands.d.ts +33 -0
- package/dist/features/commands.js +190 -0
- package/dist/features/hooks.d.ts +33 -0
- package/dist/features/hooks.js +182 -0
- package/dist/features/ignore.d.ts +21 -0
- package/dist/features/ignore.js +72 -0
- package/dist/features/index.d.ts +8 -0
- package/dist/features/index.js +426 -0
- package/dist/features/mcp.d.ts +34 -0
- package/dist/features/mcp.js +172 -0
- package/dist/features/plugins.d.ts +23 -0
- package/dist/features/plugins.js +168 -0
- package/dist/features/rules.d.ts +53 -0
- package/dist/features/rules.js +198 -0
- package/dist/features/skills.d.ts +42 -0
- package/dist/features/skills.js +198 -0
- package/dist/importers/claude-code.d.ts +5 -0
- package/dist/importers/claude-code.js +224 -0
- package/dist/importers/cursor.d.ts +5 -0
- package/dist/importers/cursor.js +288 -0
- package/dist/importers/opencode.d.ts +5 -0
- package/dist/importers/opencode.js +261 -0
- package/dist/importers/rulesync.d.ts +14 -0
- package/dist/importers/rulesync.js +280 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3464 -0
- package/dist/node/api.js +2852 -0
- package/dist/node/cli/export-cmd.js +786 -0
- package/dist/node/cli/generate.js +2018 -0
- package/dist/node/cli/import-cmd.js +691 -0
- package/dist/node/cli/init.js +214 -0
- package/dist/node/cli/install.js +610 -0
- package/dist/node/cli/pack/create.js +175 -0
- package/dist/node/cli/pack/enable.js +96 -0
- package/dist/node/cli/pack/list.js +699 -0
- package/dist/node/cli/pack/validate.js +364 -0
- package/dist/node/core/config.js +181 -0
- package/dist/node/core/dependency-resolver.js +151 -0
- package/dist/node/core/feature-merger.js +139 -0
- package/dist/node/core/index.js +924 -0
- package/dist/node/core/lockfile.js +72 -0
- package/dist/node/core/metarepo.js +218 -0
- package/dist/node/core/pack-loader.js +646 -0
- package/dist/node/exporters/cursor-plugin.js +258 -0
- package/dist/node/exporters/index.js +258 -0
- package/dist/node/features/agents.js +190 -0
- package/dist/node/features/commands.js +190 -0
- package/dist/node/features/hooks.js +182 -0
- package/dist/node/features/ignore.js +72 -0
- package/dist/node/features/index.js +426 -0
- package/dist/node/features/mcp.js +172 -0
- package/dist/node/features/plugins.js +168 -0
- package/dist/node/features/rules.js +198 -0
- package/dist/node/features/skills.js +198 -0
- package/dist/node/importers/claude-code.js +224 -0
- package/dist/node/importers/cursor.js +288 -0
- package/dist/node/importers/opencode.js +261 -0
- package/dist/node/importers/rulesync.js +280 -0
- package/dist/node/index.js +3464 -0
- package/dist/node/sources/git-ref.js +79 -0
- package/dist/node/sources/git.js +245 -0
- package/dist/node/sources/index.js +416 -0
- package/dist/node/sources/local.js +52 -0
- package/dist/node/sources/npm-ref.js +84 -0
- package/dist/node/sources/npm.js +211 -0
- package/dist/node/targets/additional-targets.js +428 -0
- package/dist/node/targets/agents-md.js +239 -0
- package/dist/node/targets/base-target.js +51 -0
- package/dist/node/targets/claude-code.js +490 -0
- package/dist/node/targets/codex-cli.js +297 -0
- package/dist/node/targets/copilot.js +390 -0
- package/dist/node/targets/cursor.js +441 -0
- package/dist/node/targets/gemini-cli.js +352 -0
- package/dist/node/targets/generic-md-target.js +319 -0
- package/dist/node/targets/index.js +1351 -0
- package/dist/node/targets/opencode.js +556 -0
- package/dist/node/targets/registry.js +1343 -0
- package/dist/node/utils/diff.js +144 -0
- package/dist/node/utils/filesystem.js +152 -0
- package/dist/node/utils/frontmatter.js +52 -0
- package/dist/node/utils/global.js +81 -0
- package/dist/node/utils/markdown.js +62 -0
- package/dist/sources/git-ref.d.ts +27 -0
- package/dist/sources/git-ref.js +79 -0
- package/dist/sources/git.d.ts +29 -0
- package/dist/sources/git.js +245 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.js +416 -0
- package/dist/sources/local.d.ts +8 -0
- package/dist/sources/local.js +52 -0
- package/dist/sources/npm-ref.d.ts +30 -0
- package/dist/sources/npm-ref.js +84 -0
- package/dist/sources/npm.d.ts +20 -0
- package/dist/sources/npm.js +211 -0
- package/dist/targets/additional-targets.d.ts +65 -0
- package/dist/targets/additional-targets.js +428 -0
- package/dist/targets/agents-md.d.ts +13 -0
- package/dist/targets/agents-md.js +239 -0
- package/dist/targets/base-target.d.ts +61 -0
- package/dist/targets/base-target.js +51 -0
- package/dist/targets/claude-code.d.ts +13 -0
- package/dist/targets/claude-code.js +490 -0
- package/dist/targets/codex-cli.d.ts +12 -0
- package/dist/targets/codex-cli.js +297 -0
- package/dist/targets/copilot.d.ts +12 -0
- package/dist/targets/copilot.js +390 -0
- package/dist/targets/cursor.d.ts +13 -0
- package/dist/targets/cursor.js +441 -0
- package/dist/targets/gemini-cli.d.ts +12 -0
- package/dist/targets/gemini-cli.js +352 -0
- package/dist/targets/generic-md-target.d.ts +25 -0
- package/dist/targets/generic-md-target.js +319 -0
- package/dist/targets/index.d.ts +9 -0
- package/dist/targets/index.js +1351 -0
- package/dist/targets/opencode.d.ts +13 -0
- package/dist/targets/opencode.js +556 -0
- package/dist/targets/registry.d.ts +17 -0
- package/dist/targets/registry.js +1343 -0
- package/dist/utils/diff.d.ts +13 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/filesystem.d.ts +49 -0
- package/dist/utils/filesystem.js +152 -0
- package/dist/utils/frontmatter.d.ts +19 -0
- package/dist/utils/frontmatter.js +52 -0
- package/dist/utils/global.d.ts +17 -0
- package/dist/utils/global.js +81 -0
- package/dist/utils/markdown.d.ts +20 -0
- package/dist/utils/markdown.js +62 -0
- package/package.json +808 -0
- package/templates/pack/pack.json +10 -0
- package/templates/pack/rules/overview.md +22 -0
- package/templates/workspace/agentpacks.jsonc +34 -0
|
@@ -0,0 +1,1343 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
30
|
+
var __require = import.meta.require;
|
|
31
|
+
|
|
32
|
+
// src/utils/filesystem.ts
|
|
33
|
+
import {
|
|
34
|
+
existsSync,
|
|
35
|
+
mkdirSync,
|
|
36
|
+
readFileSync,
|
|
37
|
+
writeFileSync,
|
|
38
|
+
readdirSync,
|
|
39
|
+
statSync
|
|
40
|
+
} from "fs";
|
|
41
|
+
import { dirname, relative, join } from "path";
|
|
42
|
+
import { removeSync } from "fs-extra";
|
|
43
|
+
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
44
|
+
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
45
|
+
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
46
|
+
function writeGeneratedFile(filepath, content, options = {}) {
|
|
47
|
+
const { header = true, type } = options;
|
|
48
|
+
const ext = type ?? inferFileType(filepath);
|
|
49
|
+
ensureDir(dirname(filepath));
|
|
50
|
+
let output = content;
|
|
51
|
+
if (header) {
|
|
52
|
+
const headerComment = getHeader(ext);
|
|
53
|
+
if (headerComment) {
|
|
54
|
+
output = `${headerComment}
|
|
55
|
+
${content}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
writeFileSync(filepath, output, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
function writeGeneratedJson(filepath, data, options = {}) {
|
|
61
|
+
const json = JSON.stringify(data, null, 2);
|
|
62
|
+
writeGeneratedFile(filepath, json + `
|
|
63
|
+
`, { ...options, type: "json" });
|
|
64
|
+
}
|
|
65
|
+
function readFileOrNull(filepath) {
|
|
66
|
+
if (!existsSync(filepath))
|
|
67
|
+
return null;
|
|
68
|
+
return readFileSync(filepath, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
function readJsonOrNull(filepath) {
|
|
71
|
+
const content = readFileOrNull(filepath);
|
|
72
|
+
if (content === null)
|
|
73
|
+
return null;
|
|
74
|
+
return JSON.parse(content);
|
|
75
|
+
}
|
|
76
|
+
function ensureDir(dirPath) {
|
|
77
|
+
if (!existsSync(dirPath)) {
|
|
78
|
+
mkdirSync(dirPath, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function removeIfExists(targetPath) {
|
|
82
|
+
if (existsSync(targetPath)) {
|
|
83
|
+
removeSync(targetPath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function listFiles(dirPath, options = {}) {
|
|
87
|
+
const { extension, recursive = false } = options;
|
|
88
|
+
if (!existsSync(dirPath))
|
|
89
|
+
return [];
|
|
90
|
+
const results = [];
|
|
91
|
+
const entries = readdirSync(dirPath);
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const fullPath = join(dirPath, entry);
|
|
94
|
+
const stat = statSync(fullPath);
|
|
95
|
+
if (stat.isDirectory() && recursive) {
|
|
96
|
+
results.push(...listFiles(fullPath, options));
|
|
97
|
+
} else if (stat.isFile()) {
|
|
98
|
+
if (!extension || entry.endsWith(extension)) {
|
|
99
|
+
results.push(fullPath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
function listDirs(dirPath) {
|
|
106
|
+
if (!existsSync(dirPath))
|
|
107
|
+
return [];
|
|
108
|
+
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
109
|
+
}
|
|
110
|
+
function relPath(projectRoot, filepath) {
|
|
111
|
+
return relative(projectRoot, filepath);
|
|
112
|
+
}
|
|
113
|
+
function isGeneratedFile(filepath) {
|
|
114
|
+
const content = readFileOrNull(filepath);
|
|
115
|
+
if (!content)
|
|
116
|
+
return false;
|
|
117
|
+
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
118
|
+
}
|
|
119
|
+
function inferFileType(filepath) {
|
|
120
|
+
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
121
|
+
return "json";
|
|
122
|
+
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
123
|
+
return "ts";
|
|
124
|
+
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
125
|
+
return "js";
|
|
126
|
+
return "md";
|
|
127
|
+
}
|
|
128
|
+
function getHeader(type) {
|
|
129
|
+
switch (type) {
|
|
130
|
+
case "md":
|
|
131
|
+
return GENERATED_HEADER_MD;
|
|
132
|
+
case "json":
|
|
133
|
+
return GENERATED_HEADER_JSON;
|
|
134
|
+
case "js":
|
|
135
|
+
case "ts":
|
|
136
|
+
return GENERATED_HEADER_JS;
|
|
137
|
+
default:
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/frontmatter.ts
|
|
143
|
+
import matter from "gray-matter";
|
|
144
|
+
function parseFrontmatter(source) {
|
|
145
|
+
const { data, content } = matter(source);
|
|
146
|
+
return {
|
|
147
|
+
data,
|
|
148
|
+
content: content.trim(),
|
|
149
|
+
raw: source
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function serializeFrontmatter(data, content) {
|
|
153
|
+
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
154
|
+
if (Object.keys(filtered).length === 0) {
|
|
155
|
+
return content;
|
|
156
|
+
}
|
|
157
|
+
return matter.stringify(content, filtered);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/features/rules.ts
|
|
161
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
162
|
+
import { basename } from "path";
|
|
163
|
+
function parseRules(rulesDir, packName) {
|
|
164
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
165
|
+
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
166
|
+
}
|
|
167
|
+
function parseRuleFile(filepath, packName) {
|
|
168
|
+
const raw = readFileSync2(filepath, "utf-8");
|
|
169
|
+
const { data, content } = parseFrontmatter(raw);
|
|
170
|
+
return {
|
|
171
|
+
name: basename(filepath, ".md"),
|
|
172
|
+
sourcePath: filepath,
|
|
173
|
+
packName,
|
|
174
|
+
meta: data,
|
|
175
|
+
content
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function ruleMatchesTarget(rule, targetId) {
|
|
179
|
+
const { targets } = rule.meta;
|
|
180
|
+
if (!targets || targets === "*")
|
|
181
|
+
return true;
|
|
182
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
183
|
+
return true;
|
|
184
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
185
|
+
}
|
|
186
|
+
function getRootRules(rules) {
|
|
187
|
+
return rules.filter((r) => r.meta.root === true);
|
|
188
|
+
}
|
|
189
|
+
function getDetailRules(rules) {
|
|
190
|
+
return rules.filter((r) => r.meta.root !== true);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/features/commands.ts
|
|
194
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
195
|
+
import { basename as basename2 } from "path";
|
|
196
|
+
function parseCommands(commandsDir, packName) {
|
|
197
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
198
|
+
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
199
|
+
}
|
|
200
|
+
function parseCommandFile(filepath, packName) {
|
|
201
|
+
const raw = readFileSync3(filepath, "utf-8");
|
|
202
|
+
const { data, content } = parseFrontmatter(raw);
|
|
203
|
+
return {
|
|
204
|
+
name: basename2(filepath, ".md"),
|
|
205
|
+
sourcePath: filepath,
|
|
206
|
+
packName,
|
|
207
|
+
meta: data,
|
|
208
|
+
content
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function commandMatchesTarget(cmd, targetId) {
|
|
212
|
+
const { targets } = cmd.meta;
|
|
213
|
+
if (!targets || targets === "*")
|
|
214
|
+
return true;
|
|
215
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
216
|
+
return true;
|
|
217
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/features/agents.ts
|
|
221
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
222
|
+
import { basename as basename3 } from "path";
|
|
223
|
+
function parseAgents(agentsDir, packName) {
|
|
224
|
+
const files = listFiles(agentsDir, { extension: ".md" });
|
|
225
|
+
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
226
|
+
}
|
|
227
|
+
function parseAgentFile(filepath, packName) {
|
|
228
|
+
const raw = readFileSync4(filepath, "utf-8");
|
|
229
|
+
const { data, content } = parseFrontmatter(raw);
|
|
230
|
+
return {
|
|
231
|
+
name: data.name ?? basename3(filepath, ".md"),
|
|
232
|
+
sourcePath: filepath,
|
|
233
|
+
packName,
|
|
234
|
+
meta: data,
|
|
235
|
+
content
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function agentMatchesTarget(agent, targetId) {
|
|
239
|
+
const { targets } = agent.meta;
|
|
240
|
+
if (!targets || targets === "*")
|
|
241
|
+
return true;
|
|
242
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
243
|
+
return true;
|
|
244
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/features/skills.ts
|
|
248
|
+
import { readFileSync as readFileSync5, existsSync as existsSync2 } from "fs";
|
|
249
|
+
import { basename as basename4, join as join2 } from "path";
|
|
250
|
+
function parseSkills(skillsDir, packName) {
|
|
251
|
+
const dirs = listDirs(skillsDir);
|
|
252
|
+
const skills = [];
|
|
253
|
+
for (const dir of dirs) {
|
|
254
|
+
const skillMd = join2(dir, "SKILL.md");
|
|
255
|
+
if (existsSync2(skillMd)) {
|
|
256
|
+
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return skills;
|
|
260
|
+
}
|
|
261
|
+
function parseSkillFile(filepath, skillDir, packName) {
|
|
262
|
+
const raw = readFileSync5(filepath, "utf-8");
|
|
263
|
+
const { data, content } = parseFrontmatter(raw);
|
|
264
|
+
return {
|
|
265
|
+
name: data.name ?? basename4(skillDir),
|
|
266
|
+
sourcePath: filepath,
|
|
267
|
+
sourceDir: skillDir,
|
|
268
|
+
packName,
|
|
269
|
+
meta: data,
|
|
270
|
+
content
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function skillMatchesTarget(skill, targetId) {
|
|
274
|
+
const { targets } = skill.meta;
|
|
275
|
+
if (!targets || targets === "*")
|
|
276
|
+
return true;
|
|
277
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
278
|
+
return true;
|
|
279
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/features/hooks.ts
|
|
283
|
+
import { join as join3 } from "path";
|
|
284
|
+
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
285
|
+
function parseHooks(packDir, packName) {
|
|
286
|
+
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
287
|
+
const raw = readJsonOrNull(hooksPath);
|
|
288
|
+
if (!raw)
|
|
289
|
+
return null;
|
|
290
|
+
const shared = raw.hooks ?? {};
|
|
291
|
+
const targetOverrides = {};
|
|
292
|
+
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
293
|
+
const override = raw[key];
|
|
294
|
+
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
295
|
+
targetOverrides[key] = override.hooks;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
packName,
|
|
300
|
+
sourcePath: hooksPath,
|
|
301
|
+
version: raw.version,
|
|
302
|
+
shared,
|
|
303
|
+
targetOverrides
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function resolveHooksForTarget(hooks, targetId) {
|
|
307
|
+
const merged = {};
|
|
308
|
+
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
309
|
+
merged[event] = [...entries];
|
|
310
|
+
}
|
|
311
|
+
const overrides = hooks.targetOverrides[targetId];
|
|
312
|
+
if (overrides) {
|
|
313
|
+
for (const [event, entries] of Object.entries(overrides)) {
|
|
314
|
+
merged[event] = [...merged[event] ?? [], ...entries];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return merged;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/targets/base-target.ts
|
|
321
|
+
class BaseTarget {
|
|
322
|
+
supportsFeature(feature) {
|
|
323
|
+
return this.supportedFeatures.includes(feature);
|
|
324
|
+
}
|
|
325
|
+
getEffectiveFeatures(enabledFeatures) {
|
|
326
|
+
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
327
|
+
}
|
|
328
|
+
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
329
|
+
return {
|
|
330
|
+
targetId: this.id,
|
|
331
|
+
filesWritten,
|
|
332
|
+
filesDeleted,
|
|
333
|
+
warnings
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/utils/markdown.ts
|
|
339
|
+
function stripGeneratedHeader(content) {
|
|
340
|
+
return content.replace(/^<!-- Generated by agentpacks.*-->\n/, "").replace(/^\/\/ Generated by agentpacks.*\n/, "");
|
|
341
|
+
}
|
|
342
|
+
function packNameToIdentifier(packName) {
|
|
343
|
+
return packName.split(/[-_.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
344
|
+
}
|
|
345
|
+
function extractFirstHeading(content) {
|
|
346
|
+
const match = content.match(/^#{1,6}\s+(.+)$/m);
|
|
347
|
+
return match?.[1]?.trim() ?? null;
|
|
348
|
+
}
|
|
349
|
+
function combineMarkdown(sections, separator = `
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
`) {
|
|
354
|
+
return sections.filter(Boolean).join(separator);
|
|
355
|
+
}
|
|
356
|
+
function wrapSection(heading, content, level = 2) {
|
|
357
|
+
const prefix = "#".repeat(level);
|
|
358
|
+
return `${prefix} ${heading}
|
|
359
|
+
|
|
360
|
+
${content}`;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/targets/opencode.ts
|
|
364
|
+
import { resolve as resolve2, join as join4 } from "path";
|
|
365
|
+
var TARGET_ID = "opencode";
|
|
366
|
+
|
|
367
|
+
class OpenCodeTarget extends BaseTarget {
|
|
368
|
+
id = TARGET_ID;
|
|
369
|
+
name = "OpenCode";
|
|
370
|
+
supportedFeatures = [
|
|
371
|
+
"rules",
|
|
372
|
+
"commands",
|
|
373
|
+
"agents",
|
|
374
|
+
"skills",
|
|
375
|
+
"hooks",
|
|
376
|
+
"plugins",
|
|
377
|
+
"mcp",
|
|
378
|
+
"ignore"
|
|
379
|
+
];
|
|
380
|
+
generate(options) {
|
|
381
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
382
|
+
const root = resolve2(projectRoot, baseDir);
|
|
383
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
384
|
+
const filesWritten = [];
|
|
385
|
+
const filesDeleted = [];
|
|
386
|
+
const warnings = [];
|
|
387
|
+
const opencodeDir = resolve2(root, ".opencode");
|
|
388
|
+
if (effective.includes("agents")) {
|
|
389
|
+
const agentDir = resolve2(opencodeDir, "agent");
|
|
390
|
+
if (deleteExisting) {
|
|
391
|
+
removeIfExists(agentDir);
|
|
392
|
+
filesDeleted.push(agentDir);
|
|
393
|
+
}
|
|
394
|
+
ensureDir(agentDir);
|
|
395
|
+
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
|
|
396
|
+
for (const agent of agents) {
|
|
397
|
+
const filepath = join4(agentDir, `${agent.name}.md`);
|
|
398
|
+
writeGeneratedFile(filepath, agent.content);
|
|
399
|
+
filesWritten.push(filepath);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (effective.includes("skills")) {
|
|
403
|
+
const skillDir = resolve2(opencodeDir, "skill");
|
|
404
|
+
if (deleteExisting) {
|
|
405
|
+
removeIfExists(skillDir);
|
|
406
|
+
filesDeleted.push(skillDir);
|
|
407
|
+
}
|
|
408
|
+
ensureDir(skillDir);
|
|
409
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
|
|
410
|
+
for (const skill of skills) {
|
|
411
|
+
const skillSubDir = join4(skillDir, skill.name);
|
|
412
|
+
ensureDir(skillSubDir);
|
|
413
|
+
const filepath = join4(skillSubDir, "SKILL.md");
|
|
414
|
+
writeGeneratedFile(filepath, skill.content);
|
|
415
|
+
filesWritten.push(filepath);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (effective.includes("commands")) {
|
|
419
|
+
const cmdDir = resolve2(opencodeDir, "command");
|
|
420
|
+
if (deleteExisting) {
|
|
421
|
+
removeIfExists(cmdDir);
|
|
422
|
+
filesDeleted.push(cmdDir);
|
|
423
|
+
}
|
|
424
|
+
ensureDir(cmdDir);
|
|
425
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
|
|
426
|
+
for (const cmd of commands) {
|
|
427
|
+
const filepath = join4(cmdDir, `${cmd.name}.md`);
|
|
428
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
429
|
+
filesWritten.push(filepath);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (effective.includes("hooks") || effective.includes("plugins")) {
|
|
433
|
+
const pluginsDir = resolve2(opencodeDir, "plugins");
|
|
434
|
+
ensureDir(pluginsDir);
|
|
435
|
+
if (effective.includes("hooks")) {
|
|
436
|
+
for (const hookSet of features.hooks) {
|
|
437
|
+
const events = resolveHooksForTarget(hookSet, TARGET_ID);
|
|
438
|
+
if (Object.keys(events).length > 0) {
|
|
439
|
+
const filepath = join4(pluginsDir, `agentpacks-${hookSet.packName}.ts`);
|
|
440
|
+
const content = generateOpenCodeHookPlugin(hookSet.packName, events);
|
|
441
|
+
writeGeneratedFile(filepath, content, { type: "ts" });
|
|
442
|
+
filesWritten.push(filepath);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (effective.includes("plugins")) {
|
|
447
|
+
for (const plugin of features.plugins) {
|
|
448
|
+
const filepath = join4(pluginsDir, `agentpacks-${plugin.packName}-${plugin.name}.${plugin.extension}`);
|
|
449
|
+
writeGeneratedFile(filepath, plugin.content, {
|
|
450
|
+
type: plugin.extension
|
|
451
|
+
});
|
|
452
|
+
filesWritten.push(filepath);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (effective.includes("mcp")) {
|
|
457
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
458
|
+
if (mcpEntries.length > 0) {
|
|
459
|
+
const opencodeConfig = buildOpenCodeMcp(features.mcpServers);
|
|
460
|
+
const filepath = resolve2(root, "opencode.json");
|
|
461
|
+
writeGeneratedJson(filepath, opencodeConfig, { header: false });
|
|
462
|
+
filesWritten.push(filepath);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (effective.includes("rules")) {
|
|
466
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
|
|
467
|
+
const rootRules = getRootRules(rules);
|
|
468
|
+
const detailRules = getDetailRules(rules);
|
|
469
|
+
if (detailRules.length > 0) {
|
|
470
|
+
const memoriesDir = resolve2(opencodeDir, "memories");
|
|
471
|
+
if (deleteExisting) {
|
|
472
|
+
removeIfExists(memoriesDir);
|
|
473
|
+
filesDeleted.push(memoriesDir);
|
|
474
|
+
}
|
|
475
|
+
ensureDir(memoriesDir);
|
|
476
|
+
for (const rule of detailRules) {
|
|
477
|
+
const filepath = join4(memoriesDir, `${rule.name}.md`);
|
|
478
|
+
writeGeneratedFile(filepath, rule.content);
|
|
479
|
+
filesWritten.push(filepath);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function buildOpenCodeMcp(servers) {
|
|
487
|
+
const mcp = {};
|
|
488
|
+
for (const [name, entry] of Object.entries(servers)) {
|
|
489
|
+
if (entry.url) {
|
|
490
|
+
mcp[name] = {
|
|
491
|
+
type: "remote",
|
|
492
|
+
url: entry.url,
|
|
493
|
+
enabled: true,
|
|
494
|
+
...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {}
|
|
495
|
+
};
|
|
496
|
+
} else if (entry.command) {
|
|
497
|
+
const cmd = entry.args ? [entry.command, ...entry.args] : [entry.command];
|
|
498
|
+
mcp[name] = {
|
|
499
|
+
type: "local",
|
|
500
|
+
command: cmd,
|
|
501
|
+
enabled: true,
|
|
502
|
+
...entry.env && Object.keys(entry.env).length > 0 ? { environment: entry.env } : {}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
$schema: "https://opencode.ai/config.json",
|
|
508
|
+
mcp
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function generateOpenCodeHookPlugin(packName, events) {
|
|
512
|
+
const identifier = packNameToIdentifier(packName);
|
|
513
|
+
const hookMap = mapHookEvents(events);
|
|
514
|
+
const hookEntries = Object.entries(hookMap).map(([event, handlers]) => {
|
|
515
|
+
const body = handlers.map((h) => {
|
|
516
|
+
const matcherGuard = h.matcher ? `if (!/(?:${h.matcher})/.test(String(input?.tool ?? ""))) return;
|
|
517
|
+
` : "";
|
|
518
|
+
return ` ${matcherGuard}await $\`${h.command}\`;`;
|
|
519
|
+
}).join(`
|
|
520
|
+
`);
|
|
521
|
+
return ` "${event}": async (input, output) => {
|
|
522
|
+
${body}
|
|
523
|
+
},`;
|
|
524
|
+
}).join(`
|
|
525
|
+
`);
|
|
526
|
+
return `import type { Plugin } from "@opencode-ai/plugin";
|
|
527
|
+
|
|
528
|
+
export const ${identifier}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
529
|
+
return {
|
|
530
|
+
${hookEntries}
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
`;
|
|
534
|
+
}
|
|
535
|
+
function mapHookEvents(events) {
|
|
536
|
+
const mapped = {};
|
|
537
|
+
const eventMapping = {
|
|
538
|
+
sessionStart: "session.created",
|
|
539
|
+
postToolUse: "tool.execute.after",
|
|
540
|
+
preToolUse: "tool.execute.before",
|
|
541
|
+
stop: "session.idle",
|
|
542
|
+
afterFileEdit: "file.edited",
|
|
543
|
+
afterShellExecution: "command.executed"
|
|
544
|
+
};
|
|
545
|
+
for (const [event, handlers] of Object.entries(events)) {
|
|
546
|
+
const opencodeEvent = eventMapping[event] ?? event;
|
|
547
|
+
if (!mapped[opencodeEvent]) {
|
|
548
|
+
mapped[opencodeEvent] = [];
|
|
549
|
+
}
|
|
550
|
+
mapped[opencodeEvent].push(...handlers.filter((h) => h.command));
|
|
551
|
+
}
|
|
552
|
+
return mapped;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/targets/cursor.ts
|
|
556
|
+
import { resolve as resolve3, join as join5 } from "path";
|
|
557
|
+
var TARGET_ID2 = "cursor";
|
|
558
|
+
|
|
559
|
+
class CursorTarget extends BaseTarget {
|
|
560
|
+
id = TARGET_ID2;
|
|
561
|
+
name = "Cursor";
|
|
562
|
+
supportedFeatures = [
|
|
563
|
+
"rules",
|
|
564
|
+
"commands",
|
|
565
|
+
"agents",
|
|
566
|
+
"skills",
|
|
567
|
+
"hooks",
|
|
568
|
+
"mcp",
|
|
569
|
+
"ignore"
|
|
570
|
+
];
|
|
571
|
+
generate(options) {
|
|
572
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
573
|
+
const root = resolve3(projectRoot, baseDir);
|
|
574
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
575
|
+
const filesWritten = [];
|
|
576
|
+
const filesDeleted = [];
|
|
577
|
+
const warnings = [];
|
|
578
|
+
const cursorDir = resolve3(root, ".cursor");
|
|
579
|
+
if (effective.includes("rules")) {
|
|
580
|
+
const rulesDir = resolve3(cursorDir, "rules");
|
|
581
|
+
if (deleteExisting) {
|
|
582
|
+
removeIfExists(rulesDir);
|
|
583
|
+
filesDeleted.push(rulesDir);
|
|
584
|
+
}
|
|
585
|
+
ensureDir(rulesDir);
|
|
586
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID2));
|
|
587
|
+
for (const rule of rules) {
|
|
588
|
+
const cursorMeta = rule.meta.cursor ?? {};
|
|
589
|
+
const frontmatter = {
|
|
590
|
+
description: cursorMeta.description ?? rule.meta.description ?? "",
|
|
591
|
+
alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
|
|
592
|
+
};
|
|
593
|
+
const globs = cursorMeta.globs ?? rule.meta.globs;
|
|
594
|
+
if (globs) {
|
|
595
|
+
frontmatter.globs = globs;
|
|
596
|
+
}
|
|
597
|
+
const filepath = join5(rulesDir, `${rule.name}.mdc`);
|
|
598
|
+
const content = serializeFrontmatter(frontmatter, rule.content);
|
|
599
|
+
writeGeneratedFile(filepath, content);
|
|
600
|
+
filesWritten.push(filepath);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (effective.includes("agents")) {
|
|
604
|
+
const agentsDir = resolve3(cursorDir, "agents");
|
|
605
|
+
if (deleteExisting) {
|
|
606
|
+
removeIfExists(agentsDir);
|
|
607
|
+
filesDeleted.push(agentsDir);
|
|
608
|
+
}
|
|
609
|
+
ensureDir(agentsDir);
|
|
610
|
+
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID2));
|
|
611
|
+
for (const agent of agents) {
|
|
612
|
+
const frontmatter = {
|
|
613
|
+
name: agent.name,
|
|
614
|
+
description: agent.meta.description ?? ""
|
|
615
|
+
};
|
|
616
|
+
const filepath = join5(agentsDir, `${agent.name}.md`);
|
|
617
|
+
const content = serializeFrontmatter(frontmatter, agent.content);
|
|
618
|
+
writeGeneratedFile(filepath, content);
|
|
619
|
+
filesWritten.push(filepath);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (effective.includes("skills")) {
|
|
623
|
+
const skillsDir = resolve3(cursorDir, "skills");
|
|
624
|
+
if (deleteExisting) {
|
|
625
|
+
removeIfExists(skillsDir);
|
|
626
|
+
filesDeleted.push(skillsDir);
|
|
627
|
+
}
|
|
628
|
+
ensureDir(skillsDir);
|
|
629
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID2));
|
|
630
|
+
for (const skill of skills) {
|
|
631
|
+
const skillSubDir = join5(skillsDir, skill.name);
|
|
632
|
+
ensureDir(skillSubDir);
|
|
633
|
+
const frontmatter = {
|
|
634
|
+
name: skill.name,
|
|
635
|
+
description: skill.meta.description ?? ""
|
|
636
|
+
};
|
|
637
|
+
const filepath = join5(skillSubDir, "SKILL.md");
|
|
638
|
+
const content = serializeFrontmatter(frontmatter, skill.content);
|
|
639
|
+
writeGeneratedFile(filepath, content);
|
|
640
|
+
filesWritten.push(filepath);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (effective.includes("commands")) {
|
|
644
|
+
const commandsDir = resolve3(cursorDir, "commands");
|
|
645
|
+
if (deleteExisting) {
|
|
646
|
+
removeIfExists(commandsDir);
|
|
647
|
+
filesDeleted.push(commandsDir);
|
|
648
|
+
}
|
|
649
|
+
ensureDir(commandsDir);
|
|
650
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID2));
|
|
651
|
+
for (const cmd of commands) {
|
|
652
|
+
const filepath = join5(commandsDir, `${cmd.name}.md`);
|
|
653
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
654
|
+
filesWritten.push(filepath);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (effective.includes("mcp")) {
|
|
658
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
659
|
+
if (mcpEntries.length > 0) {
|
|
660
|
+
const mcpConfig = buildCursorMcp(features.mcpServers);
|
|
661
|
+
const filepath = resolve3(cursorDir, "mcp.json");
|
|
662
|
+
writeGeneratedJson(filepath, mcpConfig, { header: false });
|
|
663
|
+
filesWritten.push(filepath);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
if (effective.includes("ignore")) {
|
|
667
|
+
if (features.ignorePatterns.length > 0) {
|
|
668
|
+
const filepath = resolve3(root, ".cursorignore");
|
|
669
|
+
const content = features.ignorePatterns.join(`
|
|
670
|
+
`) + `
|
|
671
|
+
`;
|
|
672
|
+
writeGeneratedFile(filepath, content);
|
|
673
|
+
filesWritten.push(filepath);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function buildCursorMcp(servers) {
|
|
680
|
+
const mcpServers = {};
|
|
681
|
+
for (const [name, entry] of Object.entries(servers)) {
|
|
682
|
+
if (entry.url) {
|
|
683
|
+
mcpServers[name] = { url: entry.url };
|
|
684
|
+
} else if (entry.command) {
|
|
685
|
+
mcpServers[name] = {
|
|
686
|
+
command: entry.command,
|
|
687
|
+
...entry.args ? { args: entry.args } : {},
|
|
688
|
+
...entry.env ? { env: entry.env } : {}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return { mcpServers };
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/targets/claude-code.ts
|
|
696
|
+
import { resolve as resolve4, join as join6 } from "path";
|
|
697
|
+
var TARGET_ID3 = "claudecode";
|
|
698
|
+
|
|
699
|
+
class ClaudeCodeTarget extends BaseTarget {
|
|
700
|
+
id = TARGET_ID3;
|
|
701
|
+
name = "Claude Code";
|
|
702
|
+
supportedFeatures = [
|
|
703
|
+
"rules",
|
|
704
|
+
"commands",
|
|
705
|
+
"agents",
|
|
706
|
+
"skills",
|
|
707
|
+
"hooks",
|
|
708
|
+
"mcp",
|
|
709
|
+
"ignore"
|
|
710
|
+
];
|
|
711
|
+
generate(options) {
|
|
712
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
713
|
+
const root = resolve4(projectRoot, baseDir);
|
|
714
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
715
|
+
const filesWritten = [];
|
|
716
|
+
const filesDeleted = [];
|
|
717
|
+
const warnings = [];
|
|
718
|
+
const claudeDir = resolve4(root, ".claude");
|
|
719
|
+
if (effective.includes("rules")) {
|
|
720
|
+
const rulesDir = resolve4(claudeDir, "rules");
|
|
721
|
+
if (deleteExisting) {
|
|
722
|
+
removeIfExists(rulesDir);
|
|
723
|
+
filesDeleted.push(rulesDir);
|
|
724
|
+
}
|
|
725
|
+
ensureDir(rulesDir);
|
|
726
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID3));
|
|
727
|
+
const rootRules = getRootRules(rules);
|
|
728
|
+
const detailRules = getDetailRules(rules);
|
|
729
|
+
if (rootRules.length > 0) {
|
|
730
|
+
const claudeMd = rootRules.map((r) => r.content).join(`
|
|
731
|
+
|
|
732
|
+
`);
|
|
733
|
+
const filepath = resolve4(claudeDir, "CLAUDE.md");
|
|
734
|
+
writeGeneratedFile(filepath, claudeMd);
|
|
735
|
+
filesWritten.push(filepath);
|
|
736
|
+
}
|
|
737
|
+
for (const rule of detailRules) {
|
|
738
|
+
const filepath = join6(rulesDir, `${rule.name}.md`);
|
|
739
|
+
writeGeneratedFile(filepath, rule.content);
|
|
740
|
+
filesWritten.push(filepath);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (effective.includes("agents")) {
|
|
744
|
+
const agentsDir = resolve4(claudeDir, "agents");
|
|
745
|
+
if (deleteExisting) {
|
|
746
|
+
removeIfExists(agentsDir);
|
|
747
|
+
filesDeleted.push(agentsDir);
|
|
748
|
+
}
|
|
749
|
+
ensureDir(agentsDir);
|
|
750
|
+
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID3));
|
|
751
|
+
for (const agent of agents) {
|
|
752
|
+
const filepath = join6(agentsDir, `${agent.name}.md`);
|
|
753
|
+
writeGeneratedFile(filepath, agent.content);
|
|
754
|
+
filesWritten.push(filepath);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (effective.includes("skills")) {
|
|
758
|
+
const skillsDir = resolve4(claudeDir, "skills");
|
|
759
|
+
if (deleteExisting) {
|
|
760
|
+
removeIfExists(skillsDir);
|
|
761
|
+
filesDeleted.push(skillsDir);
|
|
762
|
+
}
|
|
763
|
+
ensureDir(skillsDir);
|
|
764
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID3));
|
|
765
|
+
for (const skill of skills) {
|
|
766
|
+
const skillSubDir = join6(skillsDir, skill.name);
|
|
767
|
+
ensureDir(skillSubDir);
|
|
768
|
+
const filepath = join6(skillSubDir, "SKILL.md");
|
|
769
|
+
writeGeneratedFile(filepath, skill.content);
|
|
770
|
+
filesWritten.push(filepath);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (effective.includes("commands")) {
|
|
774
|
+
const commandsDir = resolve4(claudeDir, "commands");
|
|
775
|
+
if (deleteExisting) {
|
|
776
|
+
removeIfExists(commandsDir);
|
|
777
|
+
filesDeleted.push(commandsDir);
|
|
778
|
+
}
|
|
779
|
+
ensureDir(commandsDir);
|
|
780
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID3));
|
|
781
|
+
for (const cmd of commands) {
|
|
782
|
+
const filepath = join6(commandsDir, `${cmd.name}.md`);
|
|
783
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
784
|
+
filesWritten.push(filepath);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (effective.includes("hooks") || effective.includes("mcp") || effective.includes("ignore")) {
|
|
788
|
+
const settings = buildClaudeSettings(options, effective);
|
|
789
|
+
if (Object.keys(settings).length > 0) {
|
|
790
|
+
const filepath = resolve4(claudeDir, "settings.json");
|
|
791
|
+
const existing = readJsonOrNull(filepath) ?? {};
|
|
792
|
+
const merged = { ...existing, ...settings };
|
|
793
|
+
writeGeneratedJson(filepath, merged, { header: false });
|
|
794
|
+
filesWritten.push(filepath);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function buildClaudeSettings(options, effective) {
|
|
801
|
+
const settings = {};
|
|
802
|
+
if (effective.includes("hooks")) {
|
|
803
|
+
const allHookEntries = {};
|
|
804
|
+
for (const hookSet of options.features.hooks) {
|
|
805
|
+
const events = resolveHooksForTarget(hookSet, TARGET_ID3);
|
|
806
|
+
for (const [event, entries] of Object.entries(events)) {
|
|
807
|
+
const pascalEvent = toPascalCase(event);
|
|
808
|
+
if (!allHookEntries[pascalEvent]) {
|
|
809
|
+
allHookEntries[pascalEvent] = [];
|
|
810
|
+
}
|
|
811
|
+
allHookEntries[pascalEvent].push(...entries.map((e) => ({
|
|
812
|
+
type: e.type ?? "command",
|
|
813
|
+
...e.matcher ? { matcher: e.matcher } : {},
|
|
814
|
+
command: e.command
|
|
815
|
+
})));
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
if (Object.keys(allHookEntries).length > 0) {
|
|
819
|
+
settings.hooks = allHookEntries;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (effective.includes("mcp")) {
|
|
823
|
+
const mcpEntries = Object.entries(options.features.mcpServers);
|
|
824
|
+
if (mcpEntries.length > 0) {
|
|
825
|
+
const mcpServers = {};
|
|
826
|
+
for (const [name, entry] of mcpEntries) {
|
|
827
|
+
if (entry.url) {
|
|
828
|
+
mcpServers[name] = { url: entry.url };
|
|
829
|
+
} else if (entry.command) {
|
|
830
|
+
mcpServers[name] = {
|
|
831
|
+
command: entry.command,
|
|
832
|
+
...entry.args ? { args: entry.args } : {},
|
|
833
|
+
...entry.env ? { env: entry.env } : {}
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
settings.mcpServers = mcpServers;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return settings;
|
|
841
|
+
}
|
|
842
|
+
function toPascalCase(str) {
|
|
843
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// src/targets/codex-cli.ts
|
|
847
|
+
import { resolve as resolve5, join as join7 } from "path";
|
|
848
|
+
var TARGET_ID4 = "codexcli";
|
|
849
|
+
|
|
850
|
+
class CodexCliTarget extends BaseTarget {
|
|
851
|
+
id = TARGET_ID4;
|
|
852
|
+
name = "Codex CLI";
|
|
853
|
+
supportedFeatures = ["rules", "skills", "mcp", "hooks"];
|
|
854
|
+
generate(options) {
|
|
855
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
856
|
+
const root = resolve5(projectRoot, baseDir);
|
|
857
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
858
|
+
const filesWritten = [];
|
|
859
|
+
const filesDeleted = [];
|
|
860
|
+
const warnings = [];
|
|
861
|
+
const codexDir = resolve5(root, ".codex");
|
|
862
|
+
if (effective.includes("rules")) {
|
|
863
|
+
const memoriesDir = resolve5(codexDir, "memories");
|
|
864
|
+
if (deleteExisting) {
|
|
865
|
+
removeIfExists(memoriesDir);
|
|
866
|
+
filesDeleted.push(memoriesDir);
|
|
867
|
+
}
|
|
868
|
+
ensureDir(memoriesDir);
|
|
869
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID4));
|
|
870
|
+
for (const rule of rules) {
|
|
871
|
+
const filepath = join7(memoriesDir, `${rule.name}.md`);
|
|
872
|
+
writeGeneratedFile(filepath, rule.content);
|
|
873
|
+
filesWritten.push(filepath);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (effective.includes("skills")) {
|
|
877
|
+
const skillsDir = resolve5(codexDir, "skills");
|
|
878
|
+
if (deleteExisting) {
|
|
879
|
+
removeIfExists(skillsDir);
|
|
880
|
+
filesDeleted.push(skillsDir);
|
|
881
|
+
}
|
|
882
|
+
ensureDir(skillsDir);
|
|
883
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID4));
|
|
884
|
+
for (const skill of skills) {
|
|
885
|
+
const skillSubDir = join7(skillsDir, skill.name);
|
|
886
|
+
ensureDir(skillSubDir);
|
|
887
|
+
const filepath = join7(skillSubDir, "SKILL.md");
|
|
888
|
+
writeGeneratedFile(filepath, skill.content);
|
|
889
|
+
filesWritten.push(filepath);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// src/targets/gemini-cli.ts
|
|
897
|
+
import { resolve as resolve6, join as join8 } from "path";
|
|
898
|
+
var TARGET_ID5 = "geminicli";
|
|
899
|
+
|
|
900
|
+
class GeminiCliTarget extends BaseTarget {
|
|
901
|
+
id = TARGET_ID5;
|
|
902
|
+
name = "Gemini CLI";
|
|
903
|
+
supportedFeatures = [
|
|
904
|
+
"rules",
|
|
905
|
+
"commands",
|
|
906
|
+
"mcp",
|
|
907
|
+
"ignore",
|
|
908
|
+
"skills",
|
|
909
|
+
"hooks"
|
|
910
|
+
];
|
|
911
|
+
generate(options) {
|
|
912
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
913
|
+
const root = resolve6(projectRoot, baseDir);
|
|
914
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
915
|
+
const filesWritten = [];
|
|
916
|
+
const filesDeleted = [];
|
|
917
|
+
const warnings = [];
|
|
918
|
+
const geminiDir = resolve6(root, ".gemini");
|
|
919
|
+
if (effective.includes("rules")) {
|
|
920
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID5));
|
|
921
|
+
const rootRules = getRootRules(rules);
|
|
922
|
+
const detailRules = getDetailRules(rules);
|
|
923
|
+
if (rootRules.length > 0) {
|
|
924
|
+
const geminiMd = rootRules.map((r) => r.content).join(`
|
|
925
|
+
|
|
926
|
+
`);
|
|
927
|
+
const filepath = resolve6(root, "GEMINI.md");
|
|
928
|
+
writeGeneratedFile(filepath, geminiMd);
|
|
929
|
+
filesWritten.push(filepath);
|
|
930
|
+
}
|
|
931
|
+
if (detailRules.length > 0) {
|
|
932
|
+
const memoriesDir = resolve6(geminiDir, "memories");
|
|
933
|
+
if (deleteExisting) {
|
|
934
|
+
removeIfExists(memoriesDir);
|
|
935
|
+
filesDeleted.push(memoriesDir);
|
|
936
|
+
}
|
|
937
|
+
ensureDir(memoriesDir);
|
|
938
|
+
for (const rule of detailRules) {
|
|
939
|
+
const filepath = join8(memoriesDir, `${rule.name}.md`);
|
|
940
|
+
writeGeneratedFile(filepath, rule.content);
|
|
941
|
+
filesWritten.push(filepath);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (effective.includes("commands")) {
|
|
946
|
+
const commandsDir = resolve6(geminiDir, "commands");
|
|
947
|
+
if (deleteExisting) {
|
|
948
|
+
removeIfExists(commandsDir);
|
|
949
|
+
filesDeleted.push(commandsDir);
|
|
950
|
+
}
|
|
951
|
+
ensureDir(commandsDir);
|
|
952
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID5));
|
|
953
|
+
for (const cmd of commands) {
|
|
954
|
+
const toml = buildGeminiCommand(cmd.name, cmd.meta.description ?? "", cmd.content);
|
|
955
|
+
const filepath = join8(commandsDir, `${cmd.name}.toml`);
|
|
956
|
+
writeGeneratedFile(filepath, toml, { type: "md" });
|
|
957
|
+
filesWritten.push(filepath);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
if (effective.includes("mcp")) {
|
|
961
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
962
|
+
if (mcpEntries.length > 0) {
|
|
963
|
+
const settings = buildGeminiSettings(features.mcpServers);
|
|
964
|
+
const filepath = resolve6(geminiDir, "settings.json");
|
|
965
|
+
writeGeneratedJson(filepath, settings, { header: false });
|
|
966
|
+
filesWritten.push(filepath);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (effective.includes("ignore")) {
|
|
970
|
+
if (features.ignorePatterns.length > 0) {
|
|
971
|
+
const filepath = resolve6(root, ".geminiignore");
|
|
972
|
+
const content = features.ignorePatterns.join(`
|
|
973
|
+
`) + `
|
|
974
|
+
`;
|
|
975
|
+
writeGeneratedFile(filepath, content);
|
|
976
|
+
filesWritten.push(filepath);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
function buildGeminiCommand(name, description, content) {
|
|
983
|
+
return `[command]
|
|
984
|
+
name = "${name}"
|
|
985
|
+
description = "${description}"
|
|
986
|
+
|
|
987
|
+
[prompt]
|
|
988
|
+
content = """
|
|
989
|
+
${content}
|
|
990
|
+
"""
|
|
991
|
+
`;
|
|
992
|
+
}
|
|
993
|
+
function buildGeminiSettings(servers) {
|
|
994
|
+
const mcpServers = {};
|
|
995
|
+
for (const [name, entry] of Object.entries(servers)) {
|
|
996
|
+
if (entry.command) {
|
|
997
|
+
mcpServers[name] = {
|
|
998
|
+
command: entry.command,
|
|
999
|
+
...entry.args ? { args: entry.args } : {},
|
|
1000
|
+
...entry.env ? { env: entry.env } : {}
|
|
1001
|
+
};
|
|
1002
|
+
} else if (entry.url) {
|
|
1003
|
+
mcpServers[name] = { url: entry.url };
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return { mcpServers };
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// src/targets/copilot.ts
|
|
1010
|
+
import { resolve as resolve7, join as join9 } from "path";
|
|
1011
|
+
var TARGET_ID6 = "copilot";
|
|
1012
|
+
|
|
1013
|
+
class CopilotTarget extends BaseTarget {
|
|
1014
|
+
id = TARGET_ID6;
|
|
1015
|
+
name = "GitHub Copilot";
|
|
1016
|
+
supportedFeatures = [
|
|
1017
|
+
"rules",
|
|
1018
|
+
"commands",
|
|
1019
|
+
"agents",
|
|
1020
|
+
"skills",
|
|
1021
|
+
"mcp",
|
|
1022
|
+
"ignore"
|
|
1023
|
+
];
|
|
1024
|
+
generate(options) {
|
|
1025
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1026
|
+
const root = resolve7(projectRoot, baseDir);
|
|
1027
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1028
|
+
const filesWritten = [];
|
|
1029
|
+
const filesDeleted = [];
|
|
1030
|
+
const warnings = [];
|
|
1031
|
+
const githubDir = resolve7(root, ".github");
|
|
1032
|
+
if (effective.includes("rules")) {
|
|
1033
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID6));
|
|
1034
|
+
if (rules.length > 0) {
|
|
1035
|
+
const combinedContent = rules.map((r) => r.content).join(`
|
|
1036
|
+
|
|
1037
|
+
---
|
|
1038
|
+
|
|
1039
|
+
`);
|
|
1040
|
+
const filepath = resolve7(githubDir, "copilot-instructions.md");
|
|
1041
|
+
ensureDir(githubDir);
|
|
1042
|
+
writeGeneratedFile(filepath, combinedContent);
|
|
1043
|
+
filesWritten.push(filepath);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
if (effective.includes("agents")) {
|
|
1047
|
+
const copilotDir = resolve7(githubDir, "copilot");
|
|
1048
|
+
const agentsDir = resolve7(copilotDir, "agents");
|
|
1049
|
+
if (deleteExisting) {
|
|
1050
|
+
removeIfExists(agentsDir);
|
|
1051
|
+
filesDeleted.push(agentsDir);
|
|
1052
|
+
}
|
|
1053
|
+
ensureDir(agentsDir);
|
|
1054
|
+
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID6));
|
|
1055
|
+
for (const agent of agents) {
|
|
1056
|
+
const filepath = join9(agentsDir, `${agent.name}.md`);
|
|
1057
|
+
writeGeneratedFile(filepath, agent.content);
|
|
1058
|
+
filesWritten.push(filepath);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
if (effective.includes("skills")) {
|
|
1062
|
+
const copilotDir = resolve7(githubDir, "copilot");
|
|
1063
|
+
const skillsDir = resolve7(copilotDir, "skills");
|
|
1064
|
+
if (deleteExisting) {
|
|
1065
|
+
removeIfExists(skillsDir);
|
|
1066
|
+
filesDeleted.push(skillsDir);
|
|
1067
|
+
}
|
|
1068
|
+
ensureDir(skillsDir);
|
|
1069
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID6));
|
|
1070
|
+
for (const skill of skills) {
|
|
1071
|
+
const skillSubDir = join9(skillsDir, skill.name);
|
|
1072
|
+
ensureDir(skillSubDir);
|
|
1073
|
+
const filepath = join9(skillSubDir, "SKILL.md");
|
|
1074
|
+
writeGeneratedFile(filepath, skill.content);
|
|
1075
|
+
filesWritten.push(filepath);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
if (effective.includes("commands")) {
|
|
1079
|
+
const copilotDir = resolve7(githubDir, "copilot");
|
|
1080
|
+
const commandsDir = resolve7(copilotDir, "commands");
|
|
1081
|
+
if (deleteExisting) {
|
|
1082
|
+
removeIfExists(commandsDir);
|
|
1083
|
+
filesDeleted.push(commandsDir);
|
|
1084
|
+
}
|
|
1085
|
+
ensureDir(commandsDir);
|
|
1086
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID6));
|
|
1087
|
+
for (const cmd of commands) {
|
|
1088
|
+
const filepath = join9(commandsDir, `${cmd.name}.md`);
|
|
1089
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
1090
|
+
filesWritten.push(filepath);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (effective.includes("ignore")) {}
|
|
1094
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// src/targets/agents-md.ts
|
|
1099
|
+
import { resolve as resolve8 } from "path";
|
|
1100
|
+
class AgentsMdTarget extends BaseTarget {
|
|
1101
|
+
id = "agentsmd";
|
|
1102
|
+
name = "AGENTS.md";
|
|
1103
|
+
supportedFeatures = ["rules"];
|
|
1104
|
+
generate(options) {
|
|
1105
|
+
const { projectRoot, baseDir, features } = options;
|
|
1106
|
+
const root = resolve8(projectRoot, baseDir);
|
|
1107
|
+
const filesWritten = [];
|
|
1108
|
+
const warnings = [];
|
|
1109
|
+
const rootRules = getRootRules(features.rules);
|
|
1110
|
+
if (rootRules.length === 0) {
|
|
1111
|
+
warnings.push("No root rules found. AGENTS.md will not be generated.");
|
|
1112
|
+
return this.createResult(filesWritten, [], warnings);
|
|
1113
|
+
}
|
|
1114
|
+
const sections = rootRules.map((r) => r.content);
|
|
1115
|
+
const content = sections.join(`
|
|
1116
|
+
|
|
1117
|
+
`);
|
|
1118
|
+
const filepath = resolve8(root, "AGENTS.md");
|
|
1119
|
+
writeGeneratedFile(filepath, content);
|
|
1120
|
+
filesWritten.push(filepath);
|
|
1121
|
+
return this.createResult(filesWritten, [], warnings);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// src/targets/generic-md-target.ts
|
|
1126
|
+
import { resolve as resolve9, join as join10 } from "path";
|
|
1127
|
+
function createGenericMdTarget(config) {
|
|
1128
|
+
return new GenericMdTarget(config);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
class GenericMdTarget extends BaseTarget {
|
|
1132
|
+
id;
|
|
1133
|
+
name;
|
|
1134
|
+
supportedFeatures;
|
|
1135
|
+
config;
|
|
1136
|
+
constructor(config) {
|
|
1137
|
+
super();
|
|
1138
|
+
this.id = config.id;
|
|
1139
|
+
this.name = config.name;
|
|
1140
|
+
this.supportedFeatures = config.supportedFeatures;
|
|
1141
|
+
this.config = config;
|
|
1142
|
+
}
|
|
1143
|
+
generate(options) {
|
|
1144
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1145
|
+
const root = resolve9(projectRoot, baseDir);
|
|
1146
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1147
|
+
const filesWritten = [];
|
|
1148
|
+
const filesDeleted = [];
|
|
1149
|
+
const warnings = [];
|
|
1150
|
+
const configDir = resolve9(root, this.config.configDir);
|
|
1151
|
+
const rulesSubDir = this.config.rulesDir ?? "rules";
|
|
1152
|
+
const ext = this.config.ruleExtension ?? ".md";
|
|
1153
|
+
if (effective.includes("rules")) {
|
|
1154
|
+
const rulesDir = resolve9(configDir, rulesSubDir);
|
|
1155
|
+
if (deleteExisting) {
|
|
1156
|
+
removeIfExists(rulesDir);
|
|
1157
|
+
filesDeleted.push(rulesDir);
|
|
1158
|
+
}
|
|
1159
|
+
ensureDir(rulesDir);
|
|
1160
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
|
|
1161
|
+
for (const rule of rules) {
|
|
1162
|
+
const filepath = join10(rulesDir, `${rule.name}${ext}`);
|
|
1163
|
+
writeGeneratedFile(filepath, rule.content);
|
|
1164
|
+
filesWritten.push(filepath);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (effective.includes("commands")) {
|
|
1168
|
+
const commandsDir = resolve9(configDir, "commands");
|
|
1169
|
+
if (deleteExisting) {
|
|
1170
|
+
removeIfExists(commandsDir);
|
|
1171
|
+
filesDeleted.push(commandsDir);
|
|
1172
|
+
}
|
|
1173
|
+
ensureDir(commandsDir);
|
|
1174
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
|
|
1175
|
+
for (const cmd of commands) {
|
|
1176
|
+
const filepath = join10(commandsDir, `${cmd.name}.md`);
|
|
1177
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
1178
|
+
filesWritten.push(filepath);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (effective.includes("mcp")) {
|
|
1182
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
1183
|
+
if (mcpEntries.length > 0) {
|
|
1184
|
+
const mcpDir = this.config.mcpInConfigDir ? configDir : root;
|
|
1185
|
+
const filepath = resolve9(mcpDir, "mcp.json");
|
|
1186
|
+
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
1187
|
+
header: false
|
|
1188
|
+
});
|
|
1189
|
+
filesWritten.push(filepath);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (effective.includes("ignore") && this.config.ignoreFile) {
|
|
1193
|
+
if (features.ignorePatterns.length > 0) {
|
|
1194
|
+
const filepath = resolve9(root, this.config.ignoreFile);
|
|
1195
|
+
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
1196
|
+
`) + `
|
|
1197
|
+
`);
|
|
1198
|
+
filesWritten.push(filepath);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// src/targets/additional-targets.ts
|
|
1206
|
+
var ClineTarget = createGenericMdTarget({
|
|
1207
|
+
id: "cline",
|
|
1208
|
+
name: "Cline",
|
|
1209
|
+
configDir: ".cline",
|
|
1210
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1211
|
+
ignoreFile: ".clineignore",
|
|
1212
|
+
mcpInConfigDir: true
|
|
1213
|
+
});
|
|
1214
|
+
var KiloTarget = createGenericMdTarget({
|
|
1215
|
+
id: "kilo",
|
|
1216
|
+
name: "Kilo Code",
|
|
1217
|
+
configDir: ".kilo",
|
|
1218
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1219
|
+
ignoreFile: ".kiloignore",
|
|
1220
|
+
mcpInConfigDir: true
|
|
1221
|
+
});
|
|
1222
|
+
var RooTarget = createGenericMdTarget({
|
|
1223
|
+
id: "roo",
|
|
1224
|
+
name: "Roo Code",
|
|
1225
|
+
configDir: ".roo",
|
|
1226
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1227
|
+
ignoreFile: ".rooignore",
|
|
1228
|
+
mcpInConfigDir: true
|
|
1229
|
+
});
|
|
1230
|
+
var QwenCodeTarget = createGenericMdTarget({
|
|
1231
|
+
id: "qwencode",
|
|
1232
|
+
name: "Qwen Code",
|
|
1233
|
+
configDir: ".qwencode",
|
|
1234
|
+
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
1235
|
+
ignoreFile: ".qwencodeignore",
|
|
1236
|
+
mcpInConfigDir: true
|
|
1237
|
+
});
|
|
1238
|
+
var KiroTarget = createGenericMdTarget({
|
|
1239
|
+
id: "kiro",
|
|
1240
|
+
name: "Kiro",
|
|
1241
|
+
configDir: ".kiro",
|
|
1242
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1243
|
+
mcpInConfigDir: true
|
|
1244
|
+
});
|
|
1245
|
+
var FactoryDroidTarget = createGenericMdTarget({
|
|
1246
|
+
id: "factorydroid",
|
|
1247
|
+
name: "Factory Droid",
|
|
1248
|
+
configDir: ".factorydroid",
|
|
1249
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1250
|
+
mcpInConfigDir: true
|
|
1251
|
+
});
|
|
1252
|
+
var AntiGravityTarget = createGenericMdTarget({
|
|
1253
|
+
id: "antigravity",
|
|
1254
|
+
name: "AntiGravity",
|
|
1255
|
+
configDir: ".antigravity",
|
|
1256
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1257
|
+
mcpInConfigDir: true
|
|
1258
|
+
});
|
|
1259
|
+
var JunieTarget = createGenericMdTarget({
|
|
1260
|
+
id: "junie",
|
|
1261
|
+
name: "Junie",
|
|
1262
|
+
configDir: ".junie",
|
|
1263
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1264
|
+
mcpInConfigDir: true
|
|
1265
|
+
});
|
|
1266
|
+
var AugmentCodeTarget = createGenericMdTarget({
|
|
1267
|
+
id: "augmentcode",
|
|
1268
|
+
name: "Augment Code",
|
|
1269
|
+
configDir: ".augmentcode",
|
|
1270
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1271
|
+
mcpInConfigDir: true
|
|
1272
|
+
});
|
|
1273
|
+
var WindsurfTarget = createGenericMdTarget({
|
|
1274
|
+
id: "windsurf",
|
|
1275
|
+
name: "Windsurf",
|
|
1276
|
+
configDir: ".windsurf",
|
|
1277
|
+
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
1278
|
+
ignoreFile: ".windsurfignore",
|
|
1279
|
+
mcpInConfigDir: true
|
|
1280
|
+
});
|
|
1281
|
+
var WarpTarget = createGenericMdTarget({
|
|
1282
|
+
id: "warp",
|
|
1283
|
+
name: "Warp",
|
|
1284
|
+
configDir: ".warp",
|
|
1285
|
+
supportedFeatures: ["rules"]
|
|
1286
|
+
});
|
|
1287
|
+
var ReplitTarget = createGenericMdTarget({
|
|
1288
|
+
id: "replit",
|
|
1289
|
+
name: "Replit Agent",
|
|
1290
|
+
configDir: ".replit",
|
|
1291
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1292
|
+
mcpInConfigDir: true
|
|
1293
|
+
});
|
|
1294
|
+
var ZedTarget = createGenericMdTarget({
|
|
1295
|
+
id: "zed",
|
|
1296
|
+
name: "Zed",
|
|
1297
|
+
configDir: ".zed",
|
|
1298
|
+
supportedFeatures: ["rules", "mcp"],
|
|
1299
|
+
mcpInConfigDir: true
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
// src/targets/registry.ts
|
|
1303
|
+
var TARGETS = [
|
|
1304
|
+
new OpenCodeTarget,
|
|
1305
|
+
new CursorTarget,
|
|
1306
|
+
new ClaudeCodeTarget,
|
|
1307
|
+
new CodexCliTarget,
|
|
1308
|
+
new GeminiCliTarget,
|
|
1309
|
+
new CopilotTarget,
|
|
1310
|
+
new AgentsMdTarget,
|
|
1311
|
+
ClineTarget,
|
|
1312
|
+
KiloTarget,
|
|
1313
|
+
RooTarget,
|
|
1314
|
+
QwenCodeTarget,
|
|
1315
|
+
KiroTarget,
|
|
1316
|
+
FactoryDroidTarget,
|
|
1317
|
+
AntiGravityTarget,
|
|
1318
|
+
JunieTarget,
|
|
1319
|
+
AugmentCodeTarget,
|
|
1320
|
+
WindsurfTarget,
|
|
1321
|
+
WarpTarget,
|
|
1322
|
+
ReplitTarget,
|
|
1323
|
+
ZedTarget
|
|
1324
|
+
];
|
|
1325
|
+
var targetMap = new Map(TARGETS.map((t) => [t.id, t]));
|
|
1326
|
+
function getTarget(id) {
|
|
1327
|
+
return targetMap.get(id);
|
|
1328
|
+
}
|
|
1329
|
+
function getAllTargets() {
|
|
1330
|
+
return [...TARGETS];
|
|
1331
|
+
}
|
|
1332
|
+
function getTargets(ids) {
|
|
1333
|
+
return ids.map((id) => targetMap.get(id)).filter((t) => t !== undefined);
|
|
1334
|
+
}
|
|
1335
|
+
function listTargetIds() {
|
|
1336
|
+
return TARGETS.map((t) => t.id);
|
|
1337
|
+
}
|
|
1338
|
+
export {
|
|
1339
|
+
listTargetIds,
|
|
1340
|
+
getTargets,
|
|
1341
|
+
getTarget,
|
|
1342
|
+
getAllTargets
|
|
1343
|
+
};
|