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.
Files changed (172) hide show
  1. package/dist/api.d.ts +32 -0
  2. package/dist/api.js +2852 -0
  3. package/dist/cli/export-cmd.d.ts +12 -0
  4. package/dist/cli/export-cmd.js +786 -0
  5. package/dist/cli/generate.d.ts +13 -0
  6. package/dist/cli/generate.js +2018 -0
  7. package/dist/cli/import-cmd.d.ts +9 -0
  8. package/dist/cli/import-cmd.js +691 -0
  9. package/dist/cli/init.d.ts +5 -0
  10. package/dist/cli/init.js +214 -0
  11. package/dist/cli/install.d.ts +11 -0
  12. package/dist/cli/install.js +610 -0
  13. package/dist/cli/pack/create.d.ts +4 -0
  14. package/dist/cli/pack/create.js +175 -0
  15. package/dist/cli/pack/enable.d.ts +8 -0
  16. package/dist/cli/pack/enable.js +96 -0
  17. package/dist/cli/pack/list.d.ts +4 -0
  18. package/dist/cli/pack/list.js +699 -0
  19. package/dist/cli/pack/validate.d.ts +4 -0
  20. package/dist/cli/pack/validate.js +364 -0
  21. package/dist/core/config.d.ts +77 -0
  22. package/dist/core/config.js +181 -0
  23. package/dist/core/dependency-resolver.d.ts +38 -0
  24. package/dist/core/dependency-resolver.js +151 -0
  25. package/dist/core/feature-merger.d.ts +61 -0
  26. package/dist/core/feature-merger.js +139 -0
  27. package/dist/core/index.d.ts +5 -0
  28. package/dist/core/index.js +924 -0
  29. package/dist/core/lockfile.d.ts +50 -0
  30. package/dist/core/lockfile.js +72 -0
  31. package/dist/core/metarepo.d.ts +26 -0
  32. package/dist/core/metarepo.js +218 -0
  33. package/dist/core/pack-loader.d.ts +61 -0
  34. package/dist/core/pack-loader.js +646 -0
  35. package/dist/exporters/cursor-plugin.d.ts +29 -0
  36. package/dist/exporters/cursor-plugin.js +258 -0
  37. package/dist/exporters/index.d.ts +1 -0
  38. package/dist/exporters/index.js +258 -0
  39. package/dist/features/agents.d.ts +48 -0
  40. package/dist/features/agents.js +190 -0
  41. package/dist/features/commands.d.ts +33 -0
  42. package/dist/features/commands.js +190 -0
  43. package/dist/features/hooks.d.ts +33 -0
  44. package/dist/features/hooks.js +182 -0
  45. package/dist/features/ignore.d.ts +21 -0
  46. package/dist/features/ignore.js +72 -0
  47. package/dist/features/index.d.ts +8 -0
  48. package/dist/features/index.js +426 -0
  49. package/dist/features/mcp.d.ts +34 -0
  50. package/dist/features/mcp.js +172 -0
  51. package/dist/features/plugins.d.ts +23 -0
  52. package/dist/features/plugins.js +168 -0
  53. package/dist/features/rules.d.ts +53 -0
  54. package/dist/features/rules.js +198 -0
  55. package/dist/features/skills.d.ts +42 -0
  56. package/dist/features/skills.js +198 -0
  57. package/dist/importers/claude-code.d.ts +5 -0
  58. package/dist/importers/claude-code.js +224 -0
  59. package/dist/importers/cursor.d.ts +5 -0
  60. package/dist/importers/cursor.js +288 -0
  61. package/dist/importers/opencode.d.ts +5 -0
  62. package/dist/importers/opencode.js +261 -0
  63. package/dist/importers/rulesync.d.ts +14 -0
  64. package/dist/importers/rulesync.js +280 -0
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.js +3464 -0
  67. package/dist/node/api.js +2852 -0
  68. package/dist/node/cli/export-cmd.js +786 -0
  69. package/dist/node/cli/generate.js +2018 -0
  70. package/dist/node/cli/import-cmd.js +691 -0
  71. package/dist/node/cli/init.js +214 -0
  72. package/dist/node/cli/install.js +610 -0
  73. package/dist/node/cli/pack/create.js +175 -0
  74. package/dist/node/cli/pack/enable.js +96 -0
  75. package/dist/node/cli/pack/list.js +699 -0
  76. package/dist/node/cli/pack/validate.js +364 -0
  77. package/dist/node/core/config.js +181 -0
  78. package/dist/node/core/dependency-resolver.js +151 -0
  79. package/dist/node/core/feature-merger.js +139 -0
  80. package/dist/node/core/index.js +924 -0
  81. package/dist/node/core/lockfile.js +72 -0
  82. package/dist/node/core/metarepo.js +218 -0
  83. package/dist/node/core/pack-loader.js +646 -0
  84. package/dist/node/exporters/cursor-plugin.js +258 -0
  85. package/dist/node/exporters/index.js +258 -0
  86. package/dist/node/features/agents.js +190 -0
  87. package/dist/node/features/commands.js +190 -0
  88. package/dist/node/features/hooks.js +182 -0
  89. package/dist/node/features/ignore.js +72 -0
  90. package/dist/node/features/index.js +426 -0
  91. package/dist/node/features/mcp.js +172 -0
  92. package/dist/node/features/plugins.js +168 -0
  93. package/dist/node/features/rules.js +198 -0
  94. package/dist/node/features/skills.js +198 -0
  95. package/dist/node/importers/claude-code.js +224 -0
  96. package/dist/node/importers/cursor.js +288 -0
  97. package/dist/node/importers/opencode.js +261 -0
  98. package/dist/node/importers/rulesync.js +280 -0
  99. package/dist/node/index.js +3464 -0
  100. package/dist/node/sources/git-ref.js +79 -0
  101. package/dist/node/sources/git.js +245 -0
  102. package/dist/node/sources/index.js +416 -0
  103. package/dist/node/sources/local.js +52 -0
  104. package/dist/node/sources/npm-ref.js +84 -0
  105. package/dist/node/sources/npm.js +211 -0
  106. package/dist/node/targets/additional-targets.js +428 -0
  107. package/dist/node/targets/agents-md.js +239 -0
  108. package/dist/node/targets/base-target.js +51 -0
  109. package/dist/node/targets/claude-code.js +490 -0
  110. package/dist/node/targets/codex-cli.js +297 -0
  111. package/dist/node/targets/copilot.js +390 -0
  112. package/dist/node/targets/cursor.js +441 -0
  113. package/dist/node/targets/gemini-cli.js +352 -0
  114. package/dist/node/targets/generic-md-target.js +319 -0
  115. package/dist/node/targets/index.js +1351 -0
  116. package/dist/node/targets/opencode.js +556 -0
  117. package/dist/node/targets/registry.js +1343 -0
  118. package/dist/node/utils/diff.js +144 -0
  119. package/dist/node/utils/filesystem.js +152 -0
  120. package/dist/node/utils/frontmatter.js +52 -0
  121. package/dist/node/utils/global.js +81 -0
  122. package/dist/node/utils/markdown.js +62 -0
  123. package/dist/sources/git-ref.d.ts +27 -0
  124. package/dist/sources/git-ref.js +79 -0
  125. package/dist/sources/git.d.ts +29 -0
  126. package/dist/sources/git.js +245 -0
  127. package/dist/sources/index.d.ts +5 -0
  128. package/dist/sources/index.js +416 -0
  129. package/dist/sources/local.d.ts +8 -0
  130. package/dist/sources/local.js +52 -0
  131. package/dist/sources/npm-ref.d.ts +30 -0
  132. package/dist/sources/npm-ref.js +84 -0
  133. package/dist/sources/npm.d.ts +20 -0
  134. package/dist/sources/npm.js +211 -0
  135. package/dist/targets/additional-targets.d.ts +65 -0
  136. package/dist/targets/additional-targets.js +428 -0
  137. package/dist/targets/agents-md.d.ts +13 -0
  138. package/dist/targets/agents-md.js +239 -0
  139. package/dist/targets/base-target.d.ts +61 -0
  140. package/dist/targets/base-target.js +51 -0
  141. package/dist/targets/claude-code.d.ts +13 -0
  142. package/dist/targets/claude-code.js +490 -0
  143. package/dist/targets/codex-cli.d.ts +12 -0
  144. package/dist/targets/codex-cli.js +297 -0
  145. package/dist/targets/copilot.d.ts +12 -0
  146. package/dist/targets/copilot.js +390 -0
  147. package/dist/targets/cursor.d.ts +13 -0
  148. package/dist/targets/cursor.js +441 -0
  149. package/dist/targets/gemini-cli.d.ts +12 -0
  150. package/dist/targets/gemini-cli.js +352 -0
  151. package/dist/targets/generic-md-target.d.ts +25 -0
  152. package/dist/targets/generic-md-target.js +319 -0
  153. package/dist/targets/index.d.ts +9 -0
  154. package/dist/targets/index.js +1351 -0
  155. package/dist/targets/opencode.d.ts +13 -0
  156. package/dist/targets/opencode.js +556 -0
  157. package/dist/targets/registry.d.ts +17 -0
  158. package/dist/targets/registry.js +1343 -0
  159. package/dist/utils/diff.d.ts +13 -0
  160. package/dist/utils/diff.js +144 -0
  161. package/dist/utils/filesystem.d.ts +49 -0
  162. package/dist/utils/filesystem.js +152 -0
  163. package/dist/utils/frontmatter.d.ts +19 -0
  164. package/dist/utils/frontmatter.js +52 -0
  165. package/dist/utils/global.d.ts +17 -0
  166. package/dist/utils/global.js +81 -0
  167. package/dist/utils/markdown.d.ts +20 -0
  168. package/dist/utils/markdown.js +62 -0
  169. package/package.json +808 -0
  170. package/templates/pack/pack.json +10 -0
  171. package/templates/pack/rules/overview.md +22 -0
  172. package/templates/workspace/agentpacks.jsonc +34 -0
@@ -0,0 +1,2018 @@
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/core/config.ts
33
+ var exports_config = {};
34
+ __export(exports_config, {
35
+ resolveTargets: () => resolveTargets,
36
+ resolveFeatures: () => resolveFeatures,
37
+ loadWorkspaceConfig: () => loadWorkspaceConfig,
38
+ loadPackManifest: () => loadPackManifest,
39
+ WorkspaceConfigSchema: () => WorkspaceConfigSchema,
40
+ TARGET_IDS: () => TARGET_IDS,
41
+ REPO_MODES: () => REPO_MODES,
42
+ PackManifestSchema: () => PackManifestSchema,
43
+ FEATURE_IDS: () => FEATURE_IDS
44
+ });
45
+ import { z } from "zod";
46
+ import { readFileSync, existsSync } from "fs";
47
+ import { resolve } from "path";
48
+ import { parse as parseJsonc } from "jsonc-parser";
49
+ function loadWorkspaceConfig(projectRoot) {
50
+ for (const filename of CONFIG_FILES) {
51
+ const filepath = resolve(projectRoot, filename);
52
+ if (existsSync(filepath)) {
53
+ const raw = readFileSync(filepath, "utf-8");
54
+ const parsed = parseJsonc(raw);
55
+ return WorkspaceConfigSchema.parse(parsed);
56
+ }
57
+ }
58
+ return WorkspaceConfigSchema.parse({});
59
+ }
60
+ function loadPackManifest(packDir) {
61
+ const filepath = resolve(packDir, "pack.json");
62
+ if (!existsSync(filepath)) {
63
+ const dirName = packDir.split("/").pop() ?? "unknown";
64
+ return PackManifestSchema.parse({ name: dirName });
65
+ }
66
+ const raw = readFileSync(filepath, "utf-8");
67
+ const parsed = JSON.parse(raw);
68
+ return PackManifestSchema.parse(parsed);
69
+ }
70
+ function resolveFeatures(config, targetId) {
71
+ const { features } = config;
72
+ if (features === "*") {
73
+ return [...FEATURE_IDS];
74
+ }
75
+ if (Array.isArray(features)) {
76
+ if (features.includes("*"))
77
+ return [...FEATURE_IDS];
78
+ return features.filter((f) => FEATURE_IDS.includes(f));
79
+ }
80
+ const targetFeatures = features[targetId];
81
+ if (!targetFeatures)
82
+ return [];
83
+ if (targetFeatures === "*")
84
+ return [...FEATURE_IDS];
85
+ if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
86
+ return [...FEATURE_IDS];
87
+ return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
88
+ }
89
+ function resolveTargets(config) {
90
+ if (config.targets === "*")
91
+ return [...TARGET_IDS];
92
+ return config.targets;
93
+ }
94
+ var TARGET_IDS, FEATURE_IDS, REPO_MODES, PackManifestSchema, FeaturesSchema, WorkspaceConfigSchema, CONFIG_FILES;
95
+ var init_config = __esm(() => {
96
+ TARGET_IDS = [
97
+ "opencode",
98
+ "cursor",
99
+ "claudecode",
100
+ "codexcli",
101
+ "geminicli",
102
+ "copilot",
103
+ "agentsmd",
104
+ "cline",
105
+ "kilo",
106
+ "roo",
107
+ "qwencode",
108
+ "kiro",
109
+ "factorydroid",
110
+ "antigravity",
111
+ "junie",
112
+ "augmentcode",
113
+ "windsurf",
114
+ "warp",
115
+ "replit",
116
+ "zed"
117
+ ];
118
+ FEATURE_IDS = [
119
+ "rules",
120
+ "commands",
121
+ "agents",
122
+ "skills",
123
+ "hooks",
124
+ "plugins",
125
+ "mcp",
126
+ "ignore"
127
+ ];
128
+ REPO_MODES = ["repo", "monorepo", "metarepo"];
129
+ PackManifestSchema = z.object({
130
+ name: z.string().min(1),
131
+ version: z.string().default("1.0.0"),
132
+ description: z.string().default(""),
133
+ author: z.union([
134
+ z.string(),
135
+ z.object({ name: z.string(), email: z.string().optional() })
136
+ ]).optional(),
137
+ tags: z.array(z.string()).default([]),
138
+ dependencies: z.array(z.string()).default([]),
139
+ conflicts: z.array(z.string()).default([]),
140
+ targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
141
+ features: z.union([z.literal("*"), z.array(z.string())]).default("*")
142
+ });
143
+ FeaturesSchema = z.union([
144
+ z.literal("*"),
145
+ z.array(z.string()),
146
+ z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
147
+ ]);
148
+ WorkspaceConfigSchema = z.object({
149
+ $schema: z.string().optional(),
150
+ packs: z.array(z.string()).default(["./packs/default"]),
151
+ disabled: z.array(z.string()).default([]),
152
+ targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
153
+ features: FeaturesSchema.default("*"),
154
+ mode: z.enum(REPO_MODES).default("repo"),
155
+ baseDirs: z.array(z.string()).default(["."]),
156
+ global: z.boolean().default(false),
157
+ delete: z.boolean().default(true),
158
+ verbose: z.boolean().default(false),
159
+ silent: z.boolean().default(false),
160
+ overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
161
+ sources: z.array(z.object({
162
+ source: z.string(),
163
+ packs: z.array(z.string()).optional(),
164
+ skills: z.array(z.string()).optional()
165
+ })).default([])
166
+ });
167
+ CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
168
+ });
169
+
170
+ // src/utils/filesystem.ts
171
+ import {
172
+ existsSync as existsSync2,
173
+ mkdirSync,
174
+ readFileSync as readFileSync2,
175
+ writeFileSync,
176
+ readdirSync,
177
+ statSync
178
+ } from "fs";
179
+ import { dirname, relative, join } from "path";
180
+ import { removeSync } from "fs-extra";
181
+ var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
182
+ var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
183
+ var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
184
+ function writeGeneratedFile(filepath, content, options = {}) {
185
+ const { header = true, type } = options;
186
+ const ext = type ?? inferFileType(filepath);
187
+ ensureDir(dirname(filepath));
188
+ let output = content;
189
+ if (header) {
190
+ const headerComment = getHeader(ext);
191
+ if (headerComment) {
192
+ output = `${headerComment}
193
+ ${content}`;
194
+ }
195
+ }
196
+ writeFileSync(filepath, output, "utf-8");
197
+ }
198
+ function writeGeneratedJson(filepath, data, options = {}) {
199
+ const json = JSON.stringify(data, null, 2);
200
+ writeGeneratedFile(filepath, json + `
201
+ `, { ...options, type: "json" });
202
+ }
203
+ function readFileOrNull(filepath) {
204
+ if (!existsSync2(filepath))
205
+ return null;
206
+ return readFileSync2(filepath, "utf-8");
207
+ }
208
+ function readJsonOrNull(filepath) {
209
+ const content = readFileOrNull(filepath);
210
+ if (content === null)
211
+ return null;
212
+ return JSON.parse(content);
213
+ }
214
+ function ensureDir(dirPath) {
215
+ if (!existsSync2(dirPath)) {
216
+ mkdirSync(dirPath, { recursive: true });
217
+ }
218
+ }
219
+ function removeIfExists(targetPath) {
220
+ if (existsSync2(targetPath)) {
221
+ removeSync(targetPath);
222
+ }
223
+ }
224
+ function listFiles(dirPath, options = {}) {
225
+ const { extension, recursive = false } = options;
226
+ if (!existsSync2(dirPath))
227
+ return [];
228
+ const results = [];
229
+ const entries = readdirSync(dirPath);
230
+ for (const entry of entries) {
231
+ const fullPath = join(dirPath, entry);
232
+ const stat = statSync(fullPath);
233
+ if (stat.isDirectory() && recursive) {
234
+ results.push(...listFiles(fullPath, options));
235
+ } else if (stat.isFile()) {
236
+ if (!extension || entry.endsWith(extension)) {
237
+ results.push(fullPath);
238
+ }
239
+ }
240
+ }
241
+ return results;
242
+ }
243
+ function listDirs(dirPath) {
244
+ if (!existsSync2(dirPath))
245
+ return [];
246
+ return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
247
+ }
248
+ function relPath(projectRoot, filepath) {
249
+ return relative(projectRoot, filepath);
250
+ }
251
+ function isGeneratedFile(filepath) {
252
+ const content = readFileOrNull(filepath);
253
+ if (!content)
254
+ return false;
255
+ return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
256
+ }
257
+ function inferFileType(filepath) {
258
+ if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
259
+ return "json";
260
+ if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
261
+ return "ts";
262
+ if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
263
+ return "js";
264
+ return "md";
265
+ }
266
+ function getHeader(type) {
267
+ switch (type) {
268
+ case "md":
269
+ return GENERATED_HEADER_MD;
270
+ case "json":
271
+ return GENERATED_HEADER_JSON;
272
+ case "js":
273
+ case "ts":
274
+ return GENERATED_HEADER_JS;
275
+ default:
276
+ return null;
277
+ }
278
+ }
279
+
280
+ // src/utils/frontmatter.ts
281
+ import matter from "gray-matter";
282
+ function parseFrontmatter(source) {
283
+ const { data, content } = matter(source);
284
+ return {
285
+ data,
286
+ content: content.trim(),
287
+ raw: source
288
+ };
289
+ }
290
+ function serializeFrontmatter(data, content) {
291
+ const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
292
+ if (Object.keys(filtered).length === 0) {
293
+ return content;
294
+ }
295
+ return matter.stringify(content, filtered);
296
+ }
297
+
298
+ // src/features/rules.ts
299
+ import { readFileSync as readFileSync3 } from "fs";
300
+ import { basename } from "path";
301
+ function parseRules(rulesDir, packName) {
302
+ const files = listFiles(rulesDir, { extension: ".md" });
303
+ return files.map((filepath) => parseRuleFile(filepath, packName));
304
+ }
305
+ function parseRuleFile(filepath, packName) {
306
+ const raw = readFileSync3(filepath, "utf-8");
307
+ const { data, content } = parseFrontmatter(raw);
308
+ return {
309
+ name: basename(filepath, ".md"),
310
+ sourcePath: filepath,
311
+ packName,
312
+ meta: data,
313
+ content
314
+ };
315
+ }
316
+ function ruleMatchesTarget(rule, targetId) {
317
+ const { targets } = rule.meta;
318
+ if (!targets || targets === "*")
319
+ return true;
320
+ if (Array.isArray(targets) && targets.includes("*"))
321
+ return true;
322
+ return Array.isArray(targets) && targets.includes(targetId);
323
+ }
324
+ function getRootRules(rules) {
325
+ return rules.filter((r) => r.meta.root === true);
326
+ }
327
+ function getDetailRules(rules) {
328
+ return rules.filter((r) => r.meta.root !== true);
329
+ }
330
+
331
+ // src/features/commands.ts
332
+ import { readFileSync as readFileSync4 } from "fs";
333
+ import { basename as basename2 } from "path";
334
+ function parseCommands(commandsDir, packName) {
335
+ const files = listFiles(commandsDir, { extension: ".md" });
336
+ return files.map((filepath) => parseCommandFile(filepath, packName));
337
+ }
338
+ function parseCommandFile(filepath, packName) {
339
+ const raw = readFileSync4(filepath, "utf-8");
340
+ const { data, content } = parseFrontmatter(raw);
341
+ return {
342
+ name: basename2(filepath, ".md"),
343
+ sourcePath: filepath,
344
+ packName,
345
+ meta: data,
346
+ content
347
+ };
348
+ }
349
+ function commandMatchesTarget(cmd, targetId) {
350
+ const { targets } = cmd.meta;
351
+ if (!targets || targets === "*")
352
+ return true;
353
+ if (Array.isArray(targets) && targets.includes("*"))
354
+ return true;
355
+ return Array.isArray(targets) && targets.includes(targetId);
356
+ }
357
+
358
+ // src/features/agents.ts
359
+ import { readFileSync as readFileSync5 } from "fs";
360
+ import { basename as basename3 } from "path";
361
+ function parseAgents(agentsDir, packName) {
362
+ const files = listFiles(agentsDir, { extension: ".md" });
363
+ return files.map((filepath) => parseAgentFile(filepath, packName));
364
+ }
365
+ function parseAgentFile(filepath, packName) {
366
+ const raw = readFileSync5(filepath, "utf-8");
367
+ const { data, content } = parseFrontmatter(raw);
368
+ return {
369
+ name: data.name ?? basename3(filepath, ".md"),
370
+ sourcePath: filepath,
371
+ packName,
372
+ meta: data,
373
+ content
374
+ };
375
+ }
376
+ function agentMatchesTarget(agent, targetId) {
377
+ const { targets } = agent.meta;
378
+ if (!targets || targets === "*")
379
+ return true;
380
+ if (Array.isArray(targets) && targets.includes("*"))
381
+ return true;
382
+ return Array.isArray(targets) && targets.includes(targetId);
383
+ }
384
+
385
+ // src/features/skills.ts
386
+ import { readFileSync as readFileSync6, existsSync as existsSync3 } from "fs";
387
+ import { basename as basename4, join as join2 } from "path";
388
+ function parseSkills(skillsDir, packName) {
389
+ const dirs = listDirs(skillsDir);
390
+ const skills = [];
391
+ for (const dir of dirs) {
392
+ const skillMd = join2(dir, "SKILL.md");
393
+ if (existsSync3(skillMd)) {
394
+ skills.push(parseSkillFile(skillMd, dir, packName));
395
+ }
396
+ }
397
+ return skills;
398
+ }
399
+ function parseSkillFile(filepath, skillDir, packName) {
400
+ const raw = readFileSync6(filepath, "utf-8");
401
+ const { data, content } = parseFrontmatter(raw);
402
+ return {
403
+ name: data.name ?? basename4(skillDir),
404
+ sourcePath: filepath,
405
+ sourceDir: skillDir,
406
+ packName,
407
+ meta: data,
408
+ content
409
+ };
410
+ }
411
+ function skillMatchesTarget(skill, targetId) {
412
+ const { targets } = skill.meta;
413
+ if (!targets || targets === "*")
414
+ return true;
415
+ if (Array.isArray(targets) && targets.includes("*"))
416
+ return true;
417
+ return Array.isArray(targets) && targets.includes(targetId);
418
+ }
419
+
420
+ // src/features/hooks.ts
421
+ import { join as join3 } from "path";
422
+ var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
423
+ function parseHooks(packDir, packName) {
424
+ const hooksPath = join3(packDir, "hooks", "hooks.json");
425
+ const raw = readJsonOrNull(hooksPath);
426
+ if (!raw)
427
+ return null;
428
+ const shared = raw.hooks ?? {};
429
+ const targetOverrides = {};
430
+ for (const key of TARGET_OVERRIDE_KEYS) {
431
+ const override = raw[key];
432
+ if (override && typeof override === "object" && "hooks" in override && override.hooks) {
433
+ targetOverrides[key] = override.hooks;
434
+ }
435
+ }
436
+ return {
437
+ packName,
438
+ sourcePath: hooksPath,
439
+ version: raw.version,
440
+ shared,
441
+ targetOverrides
442
+ };
443
+ }
444
+ function resolveHooksForTarget(hooks, targetId) {
445
+ const merged = {};
446
+ for (const [event, entries] of Object.entries(hooks.shared)) {
447
+ merged[event] = [...entries];
448
+ }
449
+ const overrides = hooks.targetOverrides[targetId];
450
+ if (overrides) {
451
+ for (const [event, entries] of Object.entries(overrides)) {
452
+ merged[event] = [...merged[event] ?? [], ...entries];
453
+ }
454
+ }
455
+ return merged;
456
+ }
457
+
458
+ // src/features/plugins.ts
459
+ import { readFileSync as readFileSync7, existsSync as existsSync4 } from "fs";
460
+ import { basename as basename5, join as join4 } from "path";
461
+ function parsePlugins(packDir, packName) {
462
+ const pluginsDir = join4(packDir, "plugins");
463
+ if (!existsSync4(pluginsDir))
464
+ return [];
465
+ const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
466
+ const jsFiles = listFiles(pluginsDir, { extension: ".js" });
467
+ const allFiles = [...tsFiles, ...jsFiles];
468
+ return allFiles.map((filepath) => parsePluginFile(filepath, packName));
469
+ }
470
+ function parsePluginFile(filepath, packName) {
471
+ const content = readFileSync7(filepath, "utf-8");
472
+ const ext = filepath.endsWith(".ts") ? "ts" : "js";
473
+ return {
474
+ name: basename5(filepath, `.${ext}`),
475
+ sourcePath: filepath,
476
+ packName,
477
+ content,
478
+ extension: ext
479
+ };
480
+ }
481
+
482
+ // src/features/mcp.ts
483
+ import { join as join5 } from "path";
484
+ function parseMcp(packDir, packName) {
485
+ const mcpPath = join5(packDir, "mcp.json");
486
+ const raw = readJsonOrNull(mcpPath);
487
+ if (!raw?.mcpServers)
488
+ return null;
489
+ return {
490
+ packName,
491
+ sourcePath: mcpPath,
492
+ servers: raw.mcpServers
493
+ };
494
+ }
495
+ function mergeMcpConfigs(configs) {
496
+ const servers = {};
497
+ const warnings = [];
498
+ for (const config of configs) {
499
+ for (const [name, entry] of Object.entries(config.servers)) {
500
+ if (name in servers) {
501
+ warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
502
+ continue;
503
+ }
504
+ servers[name] = entry;
505
+ }
506
+ }
507
+ return { servers, warnings };
508
+ }
509
+
510
+ // src/features/ignore.ts
511
+ import { existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
512
+ import { join as join6 } from "path";
513
+ var IGNORE_FILES = ["ignore", ".aiignore"];
514
+ function parseIgnore(packDir, packName) {
515
+ for (const filename of IGNORE_FILES) {
516
+ const filepath = join6(packDir, filename);
517
+ if (existsSync5(filepath)) {
518
+ const raw = readFileSync8(filepath, "utf-8");
519
+ const patterns = parseIgnoreContent(raw);
520
+ return {
521
+ packName,
522
+ sourcePath: filepath,
523
+ patterns
524
+ };
525
+ }
526
+ }
527
+ return null;
528
+ }
529
+ function parseIgnoreContent(content) {
530
+ return content.split(`
531
+ `).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
532
+ }
533
+ function mergeIgnorePatterns(configs) {
534
+ const seen = new Set;
535
+ const result = [];
536
+ for (const config of configs) {
537
+ for (const pattern of config.patterns) {
538
+ if (!seen.has(pattern)) {
539
+ seen.add(pattern);
540
+ result.push(pattern);
541
+ }
542
+ }
543
+ }
544
+ return result;
545
+ }
546
+
547
+ // src/core/pack-loader.ts
548
+ init_config();
549
+ import { existsSync as existsSync6 } from "fs";
550
+ import { resolve as resolve3, isAbsolute } from "path";
551
+ class PackLoader {
552
+ projectRoot;
553
+ config;
554
+ constructor(projectRoot, config) {
555
+ this.projectRoot = projectRoot;
556
+ this.config = config;
557
+ }
558
+ loadAll() {
559
+ const warnings = [];
560
+ const packs = [];
561
+ const disabledSet = new Set(this.config.disabled);
562
+ for (const packRef of this.config.packs) {
563
+ const packDir = this.resolvePackPath(packRef);
564
+ if (!packDir) {
565
+ warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
566
+ continue;
567
+ }
568
+ if (!existsSync6(packDir)) {
569
+ warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
570
+ continue;
571
+ }
572
+ const manifest = loadPackManifest(packDir);
573
+ if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
574
+ continue;
575
+ }
576
+ const loaded = this.loadPack(packDir, manifest);
577
+ packs.push(loaded);
578
+ }
579
+ return { packs, warnings };
580
+ }
581
+ loadPack(packDir, manifest) {
582
+ const name = manifest.name;
583
+ const rulesDir = resolve3(packDir, "rules");
584
+ const commandsDir = resolve3(packDir, "commands");
585
+ const agentsDir = resolve3(packDir, "agents");
586
+ const skillsDir = resolve3(packDir, "skills");
587
+ return {
588
+ manifest,
589
+ directory: packDir,
590
+ rules: existsSync6(rulesDir) ? parseRules(rulesDir, name) : [],
591
+ commands: existsSync6(commandsDir) ? parseCommands(commandsDir, name) : [],
592
+ agents: existsSync6(agentsDir) ? parseAgents(agentsDir, name) : [],
593
+ skills: existsSync6(skillsDir) ? parseSkills(skillsDir, name) : [],
594
+ hooks: parseHooks(packDir, name),
595
+ plugins: parsePlugins(packDir, name),
596
+ mcp: parseMcp(packDir, name),
597
+ ignore: parseIgnore(packDir, name)
598
+ };
599
+ }
600
+ loadForBaseDir(baseDir) {
601
+ const baseDirRoot = resolve3(this.projectRoot, baseDir);
602
+ const localConfigPath = resolve3(baseDirRoot, "agentpacks.jsonc");
603
+ if (!existsSync6(localConfigPath)) {
604
+ return { packs: [], warnings: [] };
605
+ }
606
+ const { loadWorkspaceConfig: loadWorkspaceConfig2 } = (init_config(), __toCommonJS(exports_config));
607
+ const localConfig = loadWorkspaceConfig2(baseDirRoot);
608
+ const loader = new PackLoader(baseDirRoot, localConfig);
609
+ return loader.loadAll();
610
+ }
611
+ resolveCuratedPack(packRef) {
612
+ const curatedDir = resolve3(this.projectRoot, ".agentpacks", ".curated");
613
+ let packName = packRef;
614
+ if (packName.startsWith("npm:"))
615
+ packName = packName.slice(4);
616
+ if (packName.startsWith("github:"))
617
+ packName = packName.slice(7);
618
+ if (packName.startsWith("@"))
619
+ packName = packName.slice(1);
620
+ if (packName.includes("/")) {
621
+ const parts = packName.split("/");
622
+ packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
623
+ }
624
+ packName = packName.split("@")[0].split(":")[0];
625
+ const resolved = resolve3(curatedDir, packName);
626
+ return existsSync6(resolved) ? resolved : null;
627
+ }
628
+ resolvePackPath(packRef) {
629
+ if (packRef.startsWith("./") || packRef.startsWith("../")) {
630
+ return resolve3(this.projectRoot, packRef);
631
+ }
632
+ if (isAbsolute(packRef)) {
633
+ return packRef;
634
+ }
635
+ if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
636
+ return this.resolveCuratedPack(packRef);
637
+ }
638
+ if (packRef.startsWith("github:") || packRef.includes("/")) {
639
+ return this.resolveCuratedPack(packRef);
640
+ }
641
+ return resolve3(this.projectRoot, packRef);
642
+ }
643
+ }
644
+
645
+ // src/core/feature-merger.ts
646
+ class FeatureMerger {
647
+ packs;
648
+ warnings = [];
649
+ constructor(packs) {
650
+ this.packs = packs;
651
+ }
652
+ merge() {
653
+ this.warnings = [];
654
+ const features = {
655
+ rules: this.mergeRules(),
656
+ commands: this.mergeByName("commands"),
657
+ agents: this.mergeByName("agents"),
658
+ skills: this.mergeByName("skills"),
659
+ hooks: this.mergeHooks(),
660
+ plugins: this.mergePlugins(),
661
+ mcpServers: this.mergeMcp(),
662
+ ignorePatterns: this.mergeIgnore()
663
+ };
664
+ return { features, warnings: this.warnings };
665
+ }
666
+ mergeRules() {
667
+ const seen = new Map;
668
+ const result = [];
669
+ for (const pack of this.packs) {
670
+ for (const rule of pack.rules) {
671
+ const existing = seen.get(rule.name);
672
+ if (existing) {
673
+ this.warnings.push(`Rule "${rule.name}" from pack "${rule.packName}" skipped (already defined by "${existing}").`);
674
+ continue;
675
+ }
676
+ seen.set(rule.name, rule.packName);
677
+ result.push(rule);
678
+ }
679
+ }
680
+ return result;
681
+ }
682
+ mergeByName(featureKey) {
683
+ const seen = new Map;
684
+ const result = [];
685
+ for (const pack of this.packs) {
686
+ const items = pack[featureKey];
687
+ for (const item of items) {
688
+ const existing = seen.get(item.name);
689
+ if (existing) {
690
+ this.warnings.push(`${featureKey.slice(0, -1)} "${item.name}" from pack "${item.packName}" skipped (already defined by "${existing}").`);
691
+ continue;
692
+ }
693
+ seen.set(item.name, item.packName);
694
+ result.push(item);
695
+ }
696
+ }
697
+ return result;
698
+ }
699
+ mergeHooks() {
700
+ return this.packs.map((p) => p.hooks).filter((h) => h !== null);
701
+ }
702
+ mergePlugins() {
703
+ const seen = new Map;
704
+ const result = [];
705
+ for (const pack of this.packs) {
706
+ for (const plugin of pack.plugins) {
707
+ const key = `${plugin.name}.${plugin.extension}`;
708
+ const existing = seen.get(key);
709
+ if (existing) {
710
+ this.warnings.push(`Plugin "${key}" from pack "${plugin.packName}" skipped (already defined by "${existing}").`);
711
+ continue;
712
+ }
713
+ seen.set(key, plugin.packName);
714
+ result.push(plugin);
715
+ }
716
+ }
717
+ return result;
718
+ }
719
+ mergeMcp() {
720
+ const servers = {};
721
+ for (const pack of this.packs) {
722
+ if (!pack.mcp)
723
+ continue;
724
+ for (const [name, entry] of Object.entries(pack.mcp.servers)) {
725
+ if (name in servers) {
726
+ this.warnings.push(`MCP server "${name}" from pack "${pack.manifest.name}" skipped (already defined).`);
727
+ continue;
728
+ }
729
+ servers[name] = entry;
730
+ }
731
+ }
732
+ return servers;
733
+ }
734
+ mergeIgnore() {
735
+ const seen = new Set;
736
+ const result = [];
737
+ for (const pack of this.packs) {
738
+ if (!pack.ignore)
739
+ continue;
740
+ for (const pattern of pack.ignore.patterns) {
741
+ if (!seen.has(pattern)) {
742
+ seen.add(pattern);
743
+ result.push(pattern);
744
+ }
745
+ }
746
+ }
747
+ return result;
748
+ }
749
+ }
750
+
751
+ // src/targets/base-target.ts
752
+ class BaseTarget {
753
+ supportsFeature(feature) {
754
+ return this.supportedFeatures.includes(feature);
755
+ }
756
+ getEffectiveFeatures(enabledFeatures) {
757
+ return enabledFeatures.filter((f) => this.supportsFeature(f));
758
+ }
759
+ createResult(filesWritten = [], filesDeleted = [], warnings = []) {
760
+ return {
761
+ targetId: this.id,
762
+ filesWritten,
763
+ filesDeleted,
764
+ warnings
765
+ };
766
+ }
767
+ }
768
+
769
+ // src/utils/markdown.ts
770
+ function stripGeneratedHeader(content) {
771
+ return content.replace(/^<!-- Generated by agentpacks.*-->\n/, "").replace(/^\/\/ Generated by agentpacks.*\n/, "");
772
+ }
773
+ function packNameToIdentifier(packName) {
774
+ return packName.split(/[-_.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
775
+ }
776
+ function extractFirstHeading(content) {
777
+ const match = content.match(/^#{1,6}\s+(.+)$/m);
778
+ return match?.[1]?.trim() ?? null;
779
+ }
780
+ function combineMarkdown(sections, separator = `
781
+
782
+ ---
783
+
784
+ `) {
785
+ return sections.filter(Boolean).join(separator);
786
+ }
787
+ function wrapSection(heading, content, level = 2) {
788
+ const prefix = "#".repeat(level);
789
+ return `${prefix} ${heading}
790
+
791
+ ${content}`;
792
+ }
793
+
794
+ // src/targets/opencode.ts
795
+ import { resolve as resolve4, join as join7 } from "path";
796
+ var TARGET_ID = "opencode";
797
+
798
+ class OpenCodeTarget extends BaseTarget {
799
+ id = TARGET_ID;
800
+ name = "OpenCode";
801
+ supportedFeatures = [
802
+ "rules",
803
+ "commands",
804
+ "agents",
805
+ "skills",
806
+ "hooks",
807
+ "plugins",
808
+ "mcp",
809
+ "ignore"
810
+ ];
811
+ generate(options) {
812
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
813
+ const root = resolve4(projectRoot, baseDir);
814
+ const effective = this.getEffectiveFeatures(enabledFeatures);
815
+ const filesWritten = [];
816
+ const filesDeleted = [];
817
+ const warnings = [];
818
+ const opencodeDir = resolve4(root, ".opencode");
819
+ if (effective.includes("agents")) {
820
+ const agentDir = resolve4(opencodeDir, "agent");
821
+ if (deleteExisting) {
822
+ removeIfExists(agentDir);
823
+ filesDeleted.push(agentDir);
824
+ }
825
+ ensureDir(agentDir);
826
+ const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
827
+ for (const agent of agents) {
828
+ const filepath = join7(agentDir, `${agent.name}.md`);
829
+ writeGeneratedFile(filepath, agent.content);
830
+ filesWritten.push(filepath);
831
+ }
832
+ }
833
+ if (effective.includes("skills")) {
834
+ const skillDir = resolve4(opencodeDir, "skill");
835
+ if (deleteExisting) {
836
+ removeIfExists(skillDir);
837
+ filesDeleted.push(skillDir);
838
+ }
839
+ ensureDir(skillDir);
840
+ const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
841
+ for (const skill of skills) {
842
+ const skillSubDir = join7(skillDir, skill.name);
843
+ ensureDir(skillSubDir);
844
+ const filepath = join7(skillSubDir, "SKILL.md");
845
+ writeGeneratedFile(filepath, skill.content);
846
+ filesWritten.push(filepath);
847
+ }
848
+ }
849
+ if (effective.includes("commands")) {
850
+ const cmdDir = resolve4(opencodeDir, "command");
851
+ if (deleteExisting) {
852
+ removeIfExists(cmdDir);
853
+ filesDeleted.push(cmdDir);
854
+ }
855
+ ensureDir(cmdDir);
856
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
857
+ for (const cmd of commands) {
858
+ const filepath = join7(cmdDir, `${cmd.name}.md`);
859
+ writeGeneratedFile(filepath, cmd.content);
860
+ filesWritten.push(filepath);
861
+ }
862
+ }
863
+ if (effective.includes("hooks") || effective.includes("plugins")) {
864
+ const pluginsDir = resolve4(opencodeDir, "plugins");
865
+ ensureDir(pluginsDir);
866
+ if (effective.includes("hooks")) {
867
+ for (const hookSet of features.hooks) {
868
+ const events = resolveHooksForTarget(hookSet, TARGET_ID);
869
+ if (Object.keys(events).length > 0) {
870
+ const filepath = join7(pluginsDir, `agentpacks-${hookSet.packName}.ts`);
871
+ const content = generateOpenCodeHookPlugin(hookSet.packName, events);
872
+ writeGeneratedFile(filepath, content, { type: "ts" });
873
+ filesWritten.push(filepath);
874
+ }
875
+ }
876
+ }
877
+ if (effective.includes("plugins")) {
878
+ for (const plugin of features.plugins) {
879
+ const filepath = join7(pluginsDir, `agentpacks-${plugin.packName}-${plugin.name}.${plugin.extension}`);
880
+ writeGeneratedFile(filepath, plugin.content, {
881
+ type: plugin.extension
882
+ });
883
+ filesWritten.push(filepath);
884
+ }
885
+ }
886
+ }
887
+ if (effective.includes("mcp")) {
888
+ const mcpEntries = Object.entries(features.mcpServers);
889
+ if (mcpEntries.length > 0) {
890
+ const opencodeConfig = buildOpenCodeMcp(features.mcpServers);
891
+ const filepath = resolve4(root, "opencode.json");
892
+ writeGeneratedJson(filepath, opencodeConfig, { header: false });
893
+ filesWritten.push(filepath);
894
+ }
895
+ }
896
+ if (effective.includes("rules")) {
897
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
898
+ const rootRules = getRootRules(rules);
899
+ const detailRules = getDetailRules(rules);
900
+ if (detailRules.length > 0) {
901
+ const memoriesDir = resolve4(opencodeDir, "memories");
902
+ if (deleteExisting) {
903
+ removeIfExists(memoriesDir);
904
+ filesDeleted.push(memoriesDir);
905
+ }
906
+ ensureDir(memoriesDir);
907
+ for (const rule of detailRules) {
908
+ const filepath = join7(memoriesDir, `${rule.name}.md`);
909
+ writeGeneratedFile(filepath, rule.content);
910
+ filesWritten.push(filepath);
911
+ }
912
+ }
913
+ }
914
+ return this.createResult(filesWritten, filesDeleted, warnings);
915
+ }
916
+ }
917
+ function buildOpenCodeMcp(servers) {
918
+ const mcp = {};
919
+ for (const [name, entry] of Object.entries(servers)) {
920
+ if (entry.url) {
921
+ mcp[name] = {
922
+ type: "remote",
923
+ url: entry.url,
924
+ enabled: true,
925
+ ...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {}
926
+ };
927
+ } else if (entry.command) {
928
+ const cmd = entry.args ? [entry.command, ...entry.args] : [entry.command];
929
+ mcp[name] = {
930
+ type: "local",
931
+ command: cmd,
932
+ enabled: true,
933
+ ...entry.env && Object.keys(entry.env).length > 0 ? { environment: entry.env } : {}
934
+ };
935
+ }
936
+ }
937
+ return {
938
+ $schema: "https://opencode.ai/config.json",
939
+ mcp
940
+ };
941
+ }
942
+ function generateOpenCodeHookPlugin(packName, events) {
943
+ const identifier = packNameToIdentifier(packName);
944
+ const hookMap = mapHookEvents(events);
945
+ const hookEntries = Object.entries(hookMap).map(([event, handlers]) => {
946
+ const body = handlers.map((h) => {
947
+ const matcherGuard = h.matcher ? `if (!/(?:${h.matcher})/.test(String(input?.tool ?? ""))) return;
948
+ ` : "";
949
+ return ` ${matcherGuard}await $\`${h.command}\`;`;
950
+ }).join(`
951
+ `);
952
+ return ` "${event}": async (input, output) => {
953
+ ${body}
954
+ },`;
955
+ }).join(`
956
+ `);
957
+ return `import type { Plugin } from "@opencode-ai/plugin";
958
+
959
+ export const ${identifier}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
960
+ return {
961
+ ${hookEntries}
962
+ };
963
+ };
964
+ `;
965
+ }
966
+ function mapHookEvents(events) {
967
+ const mapped = {};
968
+ const eventMapping = {
969
+ sessionStart: "session.created",
970
+ postToolUse: "tool.execute.after",
971
+ preToolUse: "tool.execute.before",
972
+ stop: "session.idle",
973
+ afterFileEdit: "file.edited",
974
+ afterShellExecution: "command.executed"
975
+ };
976
+ for (const [event, handlers] of Object.entries(events)) {
977
+ const opencodeEvent = eventMapping[event] ?? event;
978
+ if (!mapped[opencodeEvent]) {
979
+ mapped[opencodeEvent] = [];
980
+ }
981
+ mapped[opencodeEvent].push(...handlers.filter((h) => h.command));
982
+ }
983
+ return mapped;
984
+ }
985
+
986
+ // src/targets/cursor.ts
987
+ import { resolve as resolve5, join as join8 } from "path";
988
+ var TARGET_ID2 = "cursor";
989
+
990
+ class CursorTarget extends BaseTarget {
991
+ id = TARGET_ID2;
992
+ name = "Cursor";
993
+ supportedFeatures = [
994
+ "rules",
995
+ "commands",
996
+ "agents",
997
+ "skills",
998
+ "hooks",
999
+ "mcp",
1000
+ "ignore"
1001
+ ];
1002
+ generate(options) {
1003
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1004
+ const root = resolve5(projectRoot, baseDir);
1005
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1006
+ const filesWritten = [];
1007
+ const filesDeleted = [];
1008
+ const warnings = [];
1009
+ const cursorDir = resolve5(root, ".cursor");
1010
+ if (effective.includes("rules")) {
1011
+ const rulesDir = resolve5(cursorDir, "rules");
1012
+ if (deleteExisting) {
1013
+ removeIfExists(rulesDir);
1014
+ filesDeleted.push(rulesDir);
1015
+ }
1016
+ ensureDir(rulesDir);
1017
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID2));
1018
+ for (const rule of rules) {
1019
+ const cursorMeta = rule.meta.cursor ?? {};
1020
+ const frontmatter = {
1021
+ description: cursorMeta.description ?? rule.meta.description ?? "",
1022
+ alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
1023
+ };
1024
+ const globs = cursorMeta.globs ?? rule.meta.globs;
1025
+ if (globs) {
1026
+ frontmatter.globs = globs;
1027
+ }
1028
+ const filepath = join8(rulesDir, `${rule.name}.mdc`);
1029
+ const content = serializeFrontmatter(frontmatter, rule.content);
1030
+ writeGeneratedFile(filepath, content);
1031
+ filesWritten.push(filepath);
1032
+ }
1033
+ }
1034
+ if (effective.includes("agents")) {
1035
+ const agentsDir = resolve5(cursorDir, "agents");
1036
+ if (deleteExisting) {
1037
+ removeIfExists(agentsDir);
1038
+ filesDeleted.push(agentsDir);
1039
+ }
1040
+ ensureDir(agentsDir);
1041
+ const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID2));
1042
+ for (const agent of agents) {
1043
+ const frontmatter = {
1044
+ name: agent.name,
1045
+ description: agent.meta.description ?? ""
1046
+ };
1047
+ const filepath = join8(agentsDir, `${agent.name}.md`);
1048
+ const content = serializeFrontmatter(frontmatter, agent.content);
1049
+ writeGeneratedFile(filepath, content);
1050
+ filesWritten.push(filepath);
1051
+ }
1052
+ }
1053
+ if (effective.includes("skills")) {
1054
+ const skillsDir = resolve5(cursorDir, "skills");
1055
+ if (deleteExisting) {
1056
+ removeIfExists(skillsDir);
1057
+ filesDeleted.push(skillsDir);
1058
+ }
1059
+ ensureDir(skillsDir);
1060
+ const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID2));
1061
+ for (const skill of skills) {
1062
+ const skillSubDir = join8(skillsDir, skill.name);
1063
+ ensureDir(skillSubDir);
1064
+ const frontmatter = {
1065
+ name: skill.name,
1066
+ description: skill.meta.description ?? ""
1067
+ };
1068
+ const filepath = join8(skillSubDir, "SKILL.md");
1069
+ const content = serializeFrontmatter(frontmatter, skill.content);
1070
+ writeGeneratedFile(filepath, content);
1071
+ filesWritten.push(filepath);
1072
+ }
1073
+ }
1074
+ if (effective.includes("commands")) {
1075
+ const commandsDir = resolve5(cursorDir, "commands");
1076
+ if (deleteExisting) {
1077
+ removeIfExists(commandsDir);
1078
+ filesDeleted.push(commandsDir);
1079
+ }
1080
+ ensureDir(commandsDir);
1081
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID2));
1082
+ for (const cmd of commands) {
1083
+ const filepath = join8(commandsDir, `${cmd.name}.md`);
1084
+ writeGeneratedFile(filepath, cmd.content);
1085
+ filesWritten.push(filepath);
1086
+ }
1087
+ }
1088
+ if (effective.includes("mcp")) {
1089
+ const mcpEntries = Object.entries(features.mcpServers);
1090
+ if (mcpEntries.length > 0) {
1091
+ const mcpConfig = buildCursorMcp(features.mcpServers);
1092
+ const filepath = resolve5(cursorDir, "mcp.json");
1093
+ writeGeneratedJson(filepath, mcpConfig, { header: false });
1094
+ filesWritten.push(filepath);
1095
+ }
1096
+ }
1097
+ if (effective.includes("ignore")) {
1098
+ if (features.ignorePatterns.length > 0) {
1099
+ const filepath = resolve5(root, ".cursorignore");
1100
+ const content = features.ignorePatterns.join(`
1101
+ `) + `
1102
+ `;
1103
+ writeGeneratedFile(filepath, content);
1104
+ filesWritten.push(filepath);
1105
+ }
1106
+ }
1107
+ return this.createResult(filesWritten, filesDeleted, warnings);
1108
+ }
1109
+ }
1110
+ function buildCursorMcp(servers) {
1111
+ const mcpServers = {};
1112
+ for (const [name, entry] of Object.entries(servers)) {
1113
+ if (entry.url) {
1114
+ mcpServers[name] = { url: entry.url };
1115
+ } else if (entry.command) {
1116
+ mcpServers[name] = {
1117
+ command: entry.command,
1118
+ ...entry.args ? { args: entry.args } : {},
1119
+ ...entry.env ? { env: entry.env } : {}
1120
+ };
1121
+ }
1122
+ }
1123
+ return { mcpServers };
1124
+ }
1125
+
1126
+ // src/targets/claude-code.ts
1127
+ import { resolve as resolve6, join as join9 } from "path";
1128
+ var TARGET_ID3 = "claudecode";
1129
+
1130
+ class ClaudeCodeTarget extends BaseTarget {
1131
+ id = TARGET_ID3;
1132
+ name = "Claude Code";
1133
+ supportedFeatures = [
1134
+ "rules",
1135
+ "commands",
1136
+ "agents",
1137
+ "skills",
1138
+ "hooks",
1139
+ "mcp",
1140
+ "ignore"
1141
+ ];
1142
+ generate(options) {
1143
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1144
+ const root = resolve6(projectRoot, baseDir);
1145
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1146
+ const filesWritten = [];
1147
+ const filesDeleted = [];
1148
+ const warnings = [];
1149
+ const claudeDir = resolve6(root, ".claude");
1150
+ if (effective.includes("rules")) {
1151
+ const rulesDir = resolve6(claudeDir, "rules");
1152
+ if (deleteExisting) {
1153
+ removeIfExists(rulesDir);
1154
+ filesDeleted.push(rulesDir);
1155
+ }
1156
+ ensureDir(rulesDir);
1157
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID3));
1158
+ const rootRules = getRootRules(rules);
1159
+ const detailRules = getDetailRules(rules);
1160
+ if (rootRules.length > 0) {
1161
+ const claudeMd = rootRules.map((r) => r.content).join(`
1162
+
1163
+ `);
1164
+ const filepath = resolve6(claudeDir, "CLAUDE.md");
1165
+ writeGeneratedFile(filepath, claudeMd);
1166
+ filesWritten.push(filepath);
1167
+ }
1168
+ for (const rule of detailRules) {
1169
+ const filepath = join9(rulesDir, `${rule.name}.md`);
1170
+ writeGeneratedFile(filepath, rule.content);
1171
+ filesWritten.push(filepath);
1172
+ }
1173
+ }
1174
+ if (effective.includes("agents")) {
1175
+ const agentsDir = resolve6(claudeDir, "agents");
1176
+ if (deleteExisting) {
1177
+ removeIfExists(agentsDir);
1178
+ filesDeleted.push(agentsDir);
1179
+ }
1180
+ ensureDir(agentsDir);
1181
+ const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID3));
1182
+ for (const agent of agents) {
1183
+ const filepath = join9(agentsDir, `${agent.name}.md`);
1184
+ writeGeneratedFile(filepath, agent.content);
1185
+ filesWritten.push(filepath);
1186
+ }
1187
+ }
1188
+ if (effective.includes("skills")) {
1189
+ const skillsDir = resolve6(claudeDir, "skills");
1190
+ if (deleteExisting) {
1191
+ removeIfExists(skillsDir);
1192
+ filesDeleted.push(skillsDir);
1193
+ }
1194
+ ensureDir(skillsDir);
1195
+ const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID3));
1196
+ for (const skill of skills) {
1197
+ const skillSubDir = join9(skillsDir, skill.name);
1198
+ ensureDir(skillSubDir);
1199
+ const filepath = join9(skillSubDir, "SKILL.md");
1200
+ writeGeneratedFile(filepath, skill.content);
1201
+ filesWritten.push(filepath);
1202
+ }
1203
+ }
1204
+ if (effective.includes("commands")) {
1205
+ const commandsDir = resolve6(claudeDir, "commands");
1206
+ if (deleteExisting) {
1207
+ removeIfExists(commandsDir);
1208
+ filesDeleted.push(commandsDir);
1209
+ }
1210
+ ensureDir(commandsDir);
1211
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID3));
1212
+ for (const cmd of commands) {
1213
+ const filepath = join9(commandsDir, `${cmd.name}.md`);
1214
+ writeGeneratedFile(filepath, cmd.content);
1215
+ filesWritten.push(filepath);
1216
+ }
1217
+ }
1218
+ if (effective.includes("hooks") || effective.includes("mcp") || effective.includes("ignore")) {
1219
+ const settings = buildClaudeSettings(options, effective);
1220
+ if (Object.keys(settings).length > 0) {
1221
+ const filepath = resolve6(claudeDir, "settings.json");
1222
+ const existing = readJsonOrNull(filepath) ?? {};
1223
+ const merged = { ...existing, ...settings };
1224
+ writeGeneratedJson(filepath, merged, { header: false });
1225
+ filesWritten.push(filepath);
1226
+ }
1227
+ }
1228
+ return this.createResult(filesWritten, filesDeleted, warnings);
1229
+ }
1230
+ }
1231
+ function buildClaudeSettings(options, effective) {
1232
+ const settings = {};
1233
+ if (effective.includes("hooks")) {
1234
+ const allHookEntries = {};
1235
+ for (const hookSet of options.features.hooks) {
1236
+ const events = resolveHooksForTarget(hookSet, TARGET_ID3);
1237
+ for (const [event, entries] of Object.entries(events)) {
1238
+ const pascalEvent = toPascalCase(event);
1239
+ if (!allHookEntries[pascalEvent]) {
1240
+ allHookEntries[pascalEvent] = [];
1241
+ }
1242
+ allHookEntries[pascalEvent].push(...entries.map((e) => ({
1243
+ type: e.type ?? "command",
1244
+ ...e.matcher ? { matcher: e.matcher } : {},
1245
+ command: e.command
1246
+ })));
1247
+ }
1248
+ }
1249
+ if (Object.keys(allHookEntries).length > 0) {
1250
+ settings.hooks = allHookEntries;
1251
+ }
1252
+ }
1253
+ if (effective.includes("mcp")) {
1254
+ const mcpEntries = Object.entries(options.features.mcpServers);
1255
+ if (mcpEntries.length > 0) {
1256
+ const mcpServers = {};
1257
+ for (const [name, entry] of mcpEntries) {
1258
+ if (entry.url) {
1259
+ mcpServers[name] = { url: entry.url };
1260
+ } else if (entry.command) {
1261
+ mcpServers[name] = {
1262
+ command: entry.command,
1263
+ ...entry.args ? { args: entry.args } : {},
1264
+ ...entry.env ? { env: entry.env } : {}
1265
+ };
1266
+ }
1267
+ }
1268
+ settings.mcpServers = mcpServers;
1269
+ }
1270
+ }
1271
+ return settings;
1272
+ }
1273
+ function toPascalCase(str) {
1274
+ return str.charAt(0).toUpperCase() + str.slice(1);
1275
+ }
1276
+
1277
+ // src/targets/codex-cli.ts
1278
+ import { resolve as resolve7, join as join10 } from "path";
1279
+ var TARGET_ID4 = "codexcli";
1280
+
1281
+ class CodexCliTarget extends BaseTarget {
1282
+ id = TARGET_ID4;
1283
+ name = "Codex CLI";
1284
+ supportedFeatures = ["rules", "skills", "mcp", "hooks"];
1285
+ generate(options) {
1286
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1287
+ const root = resolve7(projectRoot, baseDir);
1288
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1289
+ const filesWritten = [];
1290
+ const filesDeleted = [];
1291
+ const warnings = [];
1292
+ const codexDir = resolve7(root, ".codex");
1293
+ if (effective.includes("rules")) {
1294
+ const memoriesDir = resolve7(codexDir, "memories");
1295
+ if (deleteExisting) {
1296
+ removeIfExists(memoriesDir);
1297
+ filesDeleted.push(memoriesDir);
1298
+ }
1299
+ ensureDir(memoriesDir);
1300
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID4));
1301
+ for (const rule of rules) {
1302
+ const filepath = join10(memoriesDir, `${rule.name}.md`);
1303
+ writeGeneratedFile(filepath, rule.content);
1304
+ filesWritten.push(filepath);
1305
+ }
1306
+ }
1307
+ if (effective.includes("skills")) {
1308
+ const skillsDir = resolve7(codexDir, "skills");
1309
+ if (deleteExisting) {
1310
+ removeIfExists(skillsDir);
1311
+ filesDeleted.push(skillsDir);
1312
+ }
1313
+ ensureDir(skillsDir);
1314
+ const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID4));
1315
+ for (const skill of skills) {
1316
+ const skillSubDir = join10(skillsDir, skill.name);
1317
+ ensureDir(skillSubDir);
1318
+ const filepath = join10(skillSubDir, "SKILL.md");
1319
+ writeGeneratedFile(filepath, skill.content);
1320
+ filesWritten.push(filepath);
1321
+ }
1322
+ }
1323
+ return this.createResult(filesWritten, filesDeleted, warnings);
1324
+ }
1325
+ }
1326
+
1327
+ // src/targets/gemini-cli.ts
1328
+ import { resolve as resolve8, join as join11 } from "path";
1329
+ var TARGET_ID5 = "geminicli";
1330
+
1331
+ class GeminiCliTarget extends BaseTarget {
1332
+ id = TARGET_ID5;
1333
+ name = "Gemini CLI";
1334
+ supportedFeatures = [
1335
+ "rules",
1336
+ "commands",
1337
+ "mcp",
1338
+ "ignore",
1339
+ "skills",
1340
+ "hooks"
1341
+ ];
1342
+ generate(options) {
1343
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1344
+ const root = resolve8(projectRoot, baseDir);
1345
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1346
+ const filesWritten = [];
1347
+ const filesDeleted = [];
1348
+ const warnings = [];
1349
+ const geminiDir = resolve8(root, ".gemini");
1350
+ if (effective.includes("rules")) {
1351
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID5));
1352
+ const rootRules = getRootRules(rules);
1353
+ const detailRules = getDetailRules(rules);
1354
+ if (rootRules.length > 0) {
1355
+ const geminiMd = rootRules.map((r) => r.content).join(`
1356
+
1357
+ `);
1358
+ const filepath = resolve8(root, "GEMINI.md");
1359
+ writeGeneratedFile(filepath, geminiMd);
1360
+ filesWritten.push(filepath);
1361
+ }
1362
+ if (detailRules.length > 0) {
1363
+ const memoriesDir = resolve8(geminiDir, "memories");
1364
+ if (deleteExisting) {
1365
+ removeIfExists(memoriesDir);
1366
+ filesDeleted.push(memoriesDir);
1367
+ }
1368
+ ensureDir(memoriesDir);
1369
+ for (const rule of detailRules) {
1370
+ const filepath = join11(memoriesDir, `${rule.name}.md`);
1371
+ writeGeneratedFile(filepath, rule.content);
1372
+ filesWritten.push(filepath);
1373
+ }
1374
+ }
1375
+ }
1376
+ if (effective.includes("commands")) {
1377
+ const commandsDir = resolve8(geminiDir, "commands");
1378
+ if (deleteExisting) {
1379
+ removeIfExists(commandsDir);
1380
+ filesDeleted.push(commandsDir);
1381
+ }
1382
+ ensureDir(commandsDir);
1383
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID5));
1384
+ for (const cmd of commands) {
1385
+ const toml = buildGeminiCommand(cmd.name, cmd.meta.description ?? "", cmd.content);
1386
+ const filepath = join11(commandsDir, `${cmd.name}.toml`);
1387
+ writeGeneratedFile(filepath, toml, { type: "md" });
1388
+ filesWritten.push(filepath);
1389
+ }
1390
+ }
1391
+ if (effective.includes("mcp")) {
1392
+ const mcpEntries = Object.entries(features.mcpServers);
1393
+ if (mcpEntries.length > 0) {
1394
+ const settings = buildGeminiSettings(features.mcpServers);
1395
+ const filepath = resolve8(geminiDir, "settings.json");
1396
+ writeGeneratedJson(filepath, settings, { header: false });
1397
+ filesWritten.push(filepath);
1398
+ }
1399
+ }
1400
+ if (effective.includes("ignore")) {
1401
+ if (features.ignorePatterns.length > 0) {
1402
+ const filepath = resolve8(root, ".geminiignore");
1403
+ const content = features.ignorePatterns.join(`
1404
+ `) + `
1405
+ `;
1406
+ writeGeneratedFile(filepath, content);
1407
+ filesWritten.push(filepath);
1408
+ }
1409
+ }
1410
+ return this.createResult(filesWritten, filesDeleted, warnings);
1411
+ }
1412
+ }
1413
+ function buildGeminiCommand(name, description, content) {
1414
+ return `[command]
1415
+ name = "${name}"
1416
+ description = "${description}"
1417
+
1418
+ [prompt]
1419
+ content = """
1420
+ ${content}
1421
+ """
1422
+ `;
1423
+ }
1424
+ function buildGeminiSettings(servers) {
1425
+ const mcpServers = {};
1426
+ for (const [name, entry] of Object.entries(servers)) {
1427
+ if (entry.command) {
1428
+ mcpServers[name] = {
1429
+ command: entry.command,
1430
+ ...entry.args ? { args: entry.args } : {},
1431
+ ...entry.env ? { env: entry.env } : {}
1432
+ };
1433
+ } else if (entry.url) {
1434
+ mcpServers[name] = { url: entry.url };
1435
+ }
1436
+ }
1437
+ return { mcpServers };
1438
+ }
1439
+
1440
+ // src/targets/copilot.ts
1441
+ import { resolve as resolve9, join as join12 } from "path";
1442
+ var TARGET_ID6 = "copilot";
1443
+
1444
+ class CopilotTarget extends BaseTarget {
1445
+ id = TARGET_ID6;
1446
+ name = "GitHub Copilot";
1447
+ supportedFeatures = [
1448
+ "rules",
1449
+ "commands",
1450
+ "agents",
1451
+ "skills",
1452
+ "mcp",
1453
+ "ignore"
1454
+ ];
1455
+ generate(options) {
1456
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1457
+ const root = resolve9(projectRoot, baseDir);
1458
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1459
+ const filesWritten = [];
1460
+ const filesDeleted = [];
1461
+ const warnings = [];
1462
+ const githubDir = resolve9(root, ".github");
1463
+ if (effective.includes("rules")) {
1464
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID6));
1465
+ if (rules.length > 0) {
1466
+ const combinedContent = rules.map((r) => r.content).join(`
1467
+
1468
+ ---
1469
+
1470
+ `);
1471
+ const filepath = resolve9(githubDir, "copilot-instructions.md");
1472
+ ensureDir(githubDir);
1473
+ writeGeneratedFile(filepath, combinedContent);
1474
+ filesWritten.push(filepath);
1475
+ }
1476
+ }
1477
+ if (effective.includes("agents")) {
1478
+ const copilotDir = resolve9(githubDir, "copilot");
1479
+ const agentsDir = resolve9(copilotDir, "agents");
1480
+ if (deleteExisting) {
1481
+ removeIfExists(agentsDir);
1482
+ filesDeleted.push(agentsDir);
1483
+ }
1484
+ ensureDir(agentsDir);
1485
+ const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID6));
1486
+ for (const agent of agents) {
1487
+ const filepath = join12(agentsDir, `${agent.name}.md`);
1488
+ writeGeneratedFile(filepath, agent.content);
1489
+ filesWritten.push(filepath);
1490
+ }
1491
+ }
1492
+ if (effective.includes("skills")) {
1493
+ const copilotDir = resolve9(githubDir, "copilot");
1494
+ const skillsDir = resolve9(copilotDir, "skills");
1495
+ if (deleteExisting) {
1496
+ removeIfExists(skillsDir);
1497
+ filesDeleted.push(skillsDir);
1498
+ }
1499
+ ensureDir(skillsDir);
1500
+ const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID6));
1501
+ for (const skill of skills) {
1502
+ const skillSubDir = join12(skillsDir, skill.name);
1503
+ ensureDir(skillSubDir);
1504
+ const filepath = join12(skillSubDir, "SKILL.md");
1505
+ writeGeneratedFile(filepath, skill.content);
1506
+ filesWritten.push(filepath);
1507
+ }
1508
+ }
1509
+ if (effective.includes("commands")) {
1510
+ const copilotDir = resolve9(githubDir, "copilot");
1511
+ const commandsDir = resolve9(copilotDir, "commands");
1512
+ if (deleteExisting) {
1513
+ removeIfExists(commandsDir);
1514
+ filesDeleted.push(commandsDir);
1515
+ }
1516
+ ensureDir(commandsDir);
1517
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID6));
1518
+ for (const cmd of commands) {
1519
+ const filepath = join12(commandsDir, `${cmd.name}.md`);
1520
+ writeGeneratedFile(filepath, cmd.content);
1521
+ filesWritten.push(filepath);
1522
+ }
1523
+ }
1524
+ if (effective.includes("ignore")) {}
1525
+ return this.createResult(filesWritten, filesDeleted, warnings);
1526
+ }
1527
+ }
1528
+
1529
+ // src/targets/agents-md.ts
1530
+ import { resolve as resolve10 } from "path";
1531
+ class AgentsMdTarget extends BaseTarget {
1532
+ id = "agentsmd";
1533
+ name = "AGENTS.md";
1534
+ supportedFeatures = ["rules"];
1535
+ generate(options) {
1536
+ const { projectRoot, baseDir, features } = options;
1537
+ const root = resolve10(projectRoot, baseDir);
1538
+ const filesWritten = [];
1539
+ const warnings = [];
1540
+ const rootRules = getRootRules(features.rules);
1541
+ if (rootRules.length === 0) {
1542
+ warnings.push("No root rules found. AGENTS.md will not be generated.");
1543
+ return this.createResult(filesWritten, [], warnings);
1544
+ }
1545
+ const sections = rootRules.map((r) => r.content);
1546
+ const content = sections.join(`
1547
+
1548
+ `);
1549
+ const filepath = resolve10(root, "AGENTS.md");
1550
+ writeGeneratedFile(filepath, content);
1551
+ filesWritten.push(filepath);
1552
+ return this.createResult(filesWritten, [], warnings);
1553
+ }
1554
+ }
1555
+
1556
+ // src/targets/generic-md-target.ts
1557
+ import { resolve as resolve11, join as join13 } from "path";
1558
+ function createGenericMdTarget(config) {
1559
+ return new GenericMdTarget(config);
1560
+ }
1561
+
1562
+ class GenericMdTarget extends BaseTarget {
1563
+ id;
1564
+ name;
1565
+ supportedFeatures;
1566
+ config;
1567
+ constructor(config) {
1568
+ super();
1569
+ this.id = config.id;
1570
+ this.name = config.name;
1571
+ this.supportedFeatures = config.supportedFeatures;
1572
+ this.config = config;
1573
+ }
1574
+ generate(options) {
1575
+ const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
1576
+ const root = resolve11(projectRoot, baseDir);
1577
+ const effective = this.getEffectiveFeatures(enabledFeatures);
1578
+ const filesWritten = [];
1579
+ const filesDeleted = [];
1580
+ const warnings = [];
1581
+ const configDir = resolve11(root, this.config.configDir);
1582
+ const rulesSubDir = this.config.rulesDir ?? "rules";
1583
+ const ext = this.config.ruleExtension ?? ".md";
1584
+ if (effective.includes("rules")) {
1585
+ const rulesDir = resolve11(configDir, rulesSubDir);
1586
+ if (deleteExisting) {
1587
+ removeIfExists(rulesDir);
1588
+ filesDeleted.push(rulesDir);
1589
+ }
1590
+ ensureDir(rulesDir);
1591
+ const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
1592
+ for (const rule of rules) {
1593
+ const filepath = join13(rulesDir, `${rule.name}${ext}`);
1594
+ writeGeneratedFile(filepath, rule.content);
1595
+ filesWritten.push(filepath);
1596
+ }
1597
+ }
1598
+ if (effective.includes("commands")) {
1599
+ const commandsDir = resolve11(configDir, "commands");
1600
+ if (deleteExisting) {
1601
+ removeIfExists(commandsDir);
1602
+ filesDeleted.push(commandsDir);
1603
+ }
1604
+ ensureDir(commandsDir);
1605
+ const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
1606
+ for (const cmd of commands) {
1607
+ const filepath = join13(commandsDir, `${cmd.name}.md`);
1608
+ writeGeneratedFile(filepath, cmd.content);
1609
+ filesWritten.push(filepath);
1610
+ }
1611
+ }
1612
+ if (effective.includes("mcp")) {
1613
+ const mcpEntries = Object.entries(features.mcpServers);
1614
+ if (mcpEntries.length > 0) {
1615
+ const mcpDir = this.config.mcpInConfigDir ? configDir : root;
1616
+ const filepath = resolve11(mcpDir, "mcp.json");
1617
+ writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
1618
+ header: false
1619
+ });
1620
+ filesWritten.push(filepath);
1621
+ }
1622
+ }
1623
+ if (effective.includes("ignore") && this.config.ignoreFile) {
1624
+ if (features.ignorePatterns.length > 0) {
1625
+ const filepath = resolve11(root, this.config.ignoreFile);
1626
+ writeGeneratedFile(filepath, features.ignorePatterns.join(`
1627
+ `) + `
1628
+ `);
1629
+ filesWritten.push(filepath);
1630
+ }
1631
+ }
1632
+ return this.createResult(filesWritten, filesDeleted, warnings);
1633
+ }
1634
+ }
1635
+
1636
+ // src/targets/additional-targets.ts
1637
+ var ClineTarget = createGenericMdTarget({
1638
+ id: "cline",
1639
+ name: "Cline",
1640
+ configDir: ".cline",
1641
+ supportedFeatures: ["rules", "commands", "mcp", "ignore"],
1642
+ ignoreFile: ".clineignore",
1643
+ mcpInConfigDir: true
1644
+ });
1645
+ var KiloTarget = createGenericMdTarget({
1646
+ id: "kilo",
1647
+ name: "Kilo Code",
1648
+ configDir: ".kilo",
1649
+ supportedFeatures: ["rules", "commands", "mcp", "ignore"],
1650
+ ignoreFile: ".kiloignore",
1651
+ mcpInConfigDir: true
1652
+ });
1653
+ var RooTarget = createGenericMdTarget({
1654
+ id: "roo",
1655
+ name: "Roo Code",
1656
+ configDir: ".roo",
1657
+ supportedFeatures: ["rules", "commands", "mcp", "ignore"],
1658
+ ignoreFile: ".rooignore",
1659
+ mcpInConfigDir: true
1660
+ });
1661
+ var QwenCodeTarget = createGenericMdTarget({
1662
+ id: "qwencode",
1663
+ name: "Qwen Code",
1664
+ configDir: ".qwencode",
1665
+ supportedFeatures: ["rules", "mcp", "ignore"],
1666
+ ignoreFile: ".qwencodeignore",
1667
+ mcpInConfigDir: true
1668
+ });
1669
+ var KiroTarget = createGenericMdTarget({
1670
+ id: "kiro",
1671
+ name: "Kiro",
1672
+ configDir: ".kiro",
1673
+ supportedFeatures: ["rules", "mcp"],
1674
+ mcpInConfigDir: true
1675
+ });
1676
+ var FactoryDroidTarget = createGenericMdTarget({
1677
+ id: "factorydroid",
1678
+ name: "Factory Droid",
1679
+ configDir: ".factorydroid",
1680
+ supportedFeatures: ["rules", "mcp"],
1681
+ mcpInConfigDir: true
1682
+ });
1683
+ var AntiGravityTarget = createGenericMdTarget({
1684
+ id: "antigravity",
1685
+ name: "AntiGravity",
1686
+ configDir: ".antigravity",
1687
+ supportedFeatures: ["rules", "mcp"],
1688
+ mcpInConfigDir: true
1689
+ });
1690
+ var JunieTarget = createGenericMdTarget({
1691
+ id: "junie",
1692
+ name: "Junie",
1693
+ configDir: ".junie",
1694
+ supportedFeatures: ["rules", "mcp"],
1695
+ mcpInConfigDir: true
1696
+ });
1697
+ var AugmentCodeTarget = createGenericMdTarget({
1698
+ id: "augmentcode",
1699
+ name: "Augment Code",
1700
+ configDir: ".augmentcode",
1701
+ supportedFeatures: ["rules", "mcp"],
1702
+ mcpInConfigDir: true
1703
+ });
1704
+ var WindsurfTarget = createGenericMdTarget({
1705
+ id: "windsurf",
1706
+ name: "Windsurf",
1707
+ configDir: ".windsurf",
1708
+ supportedFeatures: ["rules", "mcp", "ignore"],
1709
+ ignoreFile: ".windsurfignore",
1710
+ mcpInConfigDir: true
1711
+ });
1712
+ var WarpTarget = createGenericMdTarget({
1713
+ id: "warp",
1714
+ name: "Warp",
1715
+ configDir: ".warp",
1716
+ supportedFeatures: ["rules"]
1717
+ });
1718
+ var ReplitTarget = createGenericMdTarget({
1719
+ id: "replit",
1720
+ name: "Replit Agent",
1721
+ configDir: ".replit",
1722
+ supportedFeatures: ["rules", "mcp"],
1723
+ mcpInConfigDir: true
1724
+ });
1725
+ var ZedTarget = createGenericMdTarget({
1726
+ id: "zed",
1727
+ name: "Zed",
1728
+ configDir: ".zed",
1729
+ supportedFeatures: ["rules", "mcp"],
1730
+ mcpInConfigDir: true
1731
+ });
1732
+
1733
+ // src/targets/registry.ts
1734
+ var TARGETS = [
1735
+ new OpenCodeTarget,
1736
+ new CursorTarget,
1737
+ new ClaudeCodeTarget,
1738
+ new CodexCliTarget,
1739
+ new GeminiCliTarget,
1740
+ new CopilotTarget,
1741
+ new AgentsMdTarget,
1742
+ ClineTarget,
1743
+ KiloTarget,
1744
+ RooTarget,
1745
+ QwenCodeTarget,
1746
+ KiroTarget,
1747
+ FactoryDroidTarget,
1748
+ AntiGravityTarget,
1749
+ JunieTarget,
1750
+ AugmentCodeTarget,
1751
+ WindsurfTarget,
1752
+ WarpTarget,
1753
+ ReplitTarget,
1754
+ ZedTarget
1755
+ ];
1756
+ var targetMap = new Map(TARGETS.map((t) => [t.id, t]));
1757
+ function getTarget(id) {
1758
+ return targetMap.get(id);
1759
+ }
1760
+ function getAllTargets() {
1761
+ return [...TARGETS];
1762
+ }
1763
+ function getTargets(ids) {
1764
+ return ids.map((id) => targetMap.get(id)).filter((t) => t !== undefined);
1765
+ }
1766
+ function listTargetIds() {
1767
+ return TARGETS.map((t) => t.id);
1768
+ }
1769
+
1770
+ // src/utils/diff.ts
1771
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
1772
+ function diffFile(filepath, newContent) {
1773
+ if (!existsSync7(filepath)) {
1774
+ return {
1775
+ filepath,
1776
+ status: "added",
1777
+ diffLines: formatAddedDiff(filepath, newContent)
1778
+ };
1779
+ }
1780
+ const existing = readFileSync9(filepath, "utf-8");
1781
+ if (existing === newContent) {
1782
+ return { filepath, status: "unchanged", diffLines: [] };
1783
+ }
1784
+ return {
1785
+ filepath,
1786
+ status: "modified",
1787
+ diffLines: computeUnifiedDiff(filepath, existing, newContent)
1788
+ };
1789
+ }
1790
+ function formatAddedDiff(filepath, content) {
1791
+ const lines = [
1792
+ `--- /dev/null`,
1793
+ `+++ ${filepath}`,
1794
+ `@@ -0,0 +1,${content.split(`
1795
+ `).length} @@`
1796
+ ];
1797
+ for (const line of content.split(`
1798
+ `)) {
1799
+ lines.push(`+${line}`);
1800
+ }
1801
+ return lines;
1802
+ }
1803
+ function computeUnifiedDiff(filepath, oldContent, newContent) {
1804
+ const oldLines = oldContent.split(`
1805
+ `);
1806
+ const newLines = newContent.split(`
1807
+ `);
1808
+ const result = [`--- ${filepath}`, `+++ ${filepath}`];
1809
+ const hunks = findHunks(oldLines, newLines);
1810
+ for (const hunk of hunks) {
1811
+ result.push(`@@ -${hunk.oldStart + 1},${hunk.oldCount} +${hunk.newStart + 1},${hunk.newCount} @@`);
1812
+ for (const line of hunk.lines) {
1813
+ result.push(line);
1814
+ }
1815
+ }
1816
+ return result;
1817
+ }
1818
+ function findHunks(oldLines, newLines) {
1819
+ const CONTEXT = 3;
1820
+ const changes = [];
1821
+ let oi = 0;
1822
+ let ni = 0;
1823
+ while (oi < oldLines.length || ni < newLines.length) {
1824
+ if (oi < oldLines.length && ni < newLines.length && oldLines[oi] === newLines[ni]) {
1825
+ changes.push({ type: " ", line: oldLines[oi], oldIdx: oi, newIdx: ni });
1826
+ oi++;
1827
+ ni++;
1828
+ } else if (ni < newLines.length && (oi >= oldLines.length || !newLines.slice(ni).includes(oldLines[oi]))) {
1829
+ changes.push({ type: "+", line: newLines[ni], oldIdx: oi, newIdx: ni });
1830
+ ni++;
1831
+ } else {
1832
+ changes.push({ type: "-", line: oldLines[oi], oldIdx: oi, newIdx: oi });
1833
+ oi++;
1834
+ }
1835
+ }
1836
+ const hunks = [];
1837
+ let currentHunk = null;
1838
+ let unchangedCount = 0;
1839
+ for (const change of changes) {
1840
+ if (change.type === " ") {
1841
+ unchangedCount++;
1842
+ if (currentHunk && unchangedCount <= CONTEXT) {
1843
+ currentHunk.lines.push(` ${change.line}`);
1844
+ currentHunk.oldCount++;
1845
+ currentHunk.newCount++;
1846
+ } else if (currentHunk && unchangedCount > CONTEXT * 2) {
1847
+ hunks.push(currentHunk);
1848
+ currentHunk = null;
1849
+ }
1850
+ } else {
1851
+ if (!currentHunk) {
1852
+ const contextStart = Math.max(0, changes.indexOf(change) - CONTEXT);
1853
+ currentHunk = {
1854
+ oldStart: change.oldIdx - Math.min(CONTEXT, changes.indexOf(change) - contextStart),
1855
+ oldCount: 0,
1856
+ newStart: change.newIdx - Math.min(CONTEXT, changes.indexOf(change) - contextStart),
1857
+ newCount: 0,
1858
+ lines: []
1859
+ };
1860
+ for (let i = contextStart;i < changes.indexOf(change); i++) {
1861
+ if (changes[i].type === " ") {
1862
+ currentHunk.lines.push(` ${changes[i].line}`);
1863
+ currentHunk.oldCount++;
1864
+ currentHunk.newCount++;
1865
+ }
1866
+ }
1867
+ }
1868
+ unchangedCount = 0;
1869
+ currentHunk.lines.push(`${change.type}${change.line}`);
1870
+ if (change.type === "-")
1871
+ currentHunk.oldCount++;
1872
+ if (change.type === "+")
1873
+ currentHunk.newCount++;
1874
+ }
1875
+ }
1876
+ if (currentHunk)
1877
+ hunks.push(currentHunk);
1878
+ return hunks;
1879
+ }
1880
+
1881
+ // src/cli/generate.ts
1882
+ init_config();
1883
+ import { existsSync as existsSync8, readFileSync as readFileSync10 } from "fs";
1884
+ import chalk from "chalk";
1885
+ function runGenerate(projectRoot, options) {
1886
+ const config = loadWorkspaceConfig(projectRoot);
1887
+ if (options.targets) {
1888
+ const targetList = options.targets === "*" ? "*" : options.targets.split(",");
1889
+ config.targets = targetList;
1890
+ }
1891
+ if (options.features) {
1892
+ const featureList = options.features === "*" ? "*" : options.features.split(",");
1893
+ config.features = featureList;
1894
+ }
1895
+ if (options.verbose !== undefined) {
1896
+ config.verbose = options.verbose;
1897
+ }
1898
+ const verbose = config.verbose;
1899
+ if (verbose)
1900
+ console.log(chalk.dim("Loading packs..."));
1901
+ const loader = new PackLoader(projectRoot, config);
1902
+ const { packs, warnings: loadWarnings } = loader.loadAll();
1903
+ for (const w of loadWarnings) {
1904
+ console.log(chalk.yellow(` warn: ${w}`));
1905
+ }
1906
+ if (packs.length === 0) {
1907
+ console.log(chalk.red("No packs loaded. Nothing to generate."));
1908
+ console.log(chalk.dim("Run 'agentpacks init' to create a default pack."));
1909
+ return;
1910
+ }
1911
+ if (verbose) {
1912
+ console.log(chalk.dim(` Loaded ${packs.length} pack(s): ${packs.map((p) => p.manifest.name).join(", ")}`));
1913
+ }
1914
+ if (verbose)
1915
+ console.log(chalk.dim("Merging features..."));
1916
+ const merger = new FeatureMerger(packs);
1917
+ const { features, warnings: mergeWarnings } = merger.merge();
1918
+ for (const w of mergeWarnings) {
1919
+ console.log(chalk.yellow(` warn: ${w}`));
1920
+ }
1921
+ const targetIds = resolveTargets(config);
1922
+ if (!targetIds.includes("agentsmd")) {
1923
+ targetIds.push("agentsmd");
1924
+ }
1925
+ const targets = getTargets(targetIds);
1926
+ if (targets.length === 0) {
1927
+ console.log(chalk.red("No valid targets found."));
1928
+ return;
1929
+ }
1930
+ const allResults = [];
1931
+ const diffEntries = [];
1932
+ for (const baseDir of config.baseDirs) {
1933
+ for (const target of targets) {
1934
+ const enabledFeatures = resolveFeatures(config, target.id);
1935
+ const effectiveFeatures = enabledFeatures.filter((f) => target.supportsFeature(f));
1936
+ if (effectiveFeatures.length === 0 && target.id !== "agentsmd") {
1937
+ if (verbose) {
1938
+ console.log(chalk.dim(` Skipping ${target.name} (no enabled features)`));
1939
+ }
1940
+ continue;
1941
+ }
1942
+ if (options.dryRun && !options.diff) {
1943
+ console.log(chalk.cyan(` [dry-run] Would generate ${target.name} in ${baseDir}`));
1944
+ continue;
1945
+ }
1946
+ const generateOptions = {
1947
+ projectRoot,
1948
+ baseDir,
1949
+ features,
1950
+ enabledFeatures,
1951
+ deleteExisting: options.diff ? false : config.delete,
1952
+ global: config.global,
1953
+ verbose: config.verbose
1954
+ };
1955
+ const preSnapshot = new Map;
1956
+ try {
1957
+ const result = target.generate(generateOptions);
1958
+ allResults.push(result);
1959
+ if (options.diff) {
1960
+ for (const filepath of result.filesWritten) {
1961
+ const newContent = existsSync8(filepath) ? readFileSync10(filepath, "utf-8") : "";
1962
+ const entry = diffFile(filepath, newContent);
1963
+ if (entry.status !== "unchanged") {
1964
+ diffEntries.push(entry);
1965
+ }
1966
+ }
1967
+ }
1968
+ for (const w of result.warnings) {
1969
+ console.log(chalk.yellow(` warn [${target.name}]: ${w}`));
1970
+ }
1971
+ if (verbose && result.filesWritten.length > 0) {
1972
+ console.log(chalk.dim(` ${target.name}: wrote ${result.filesWritten.length} file(s)`));
1973
+ }
1974
+ } catch (err) {
1975
+ const message = err instanceof Error ? err.message : String(err);
1976
+ console.log(chalk.red(` error [${target.name}]: ${message}`));
1977
+ }
1978
+ }
1979
+ }
1980
+ if (options.diff && diffEntries.length > 0) {
1981
+ const added = diffEntries.filter((e) => e.status === "added").length;
1982
+ const modified = diffEntries.filter((e) => e.status === "modified").length;
1983
+ console.log(chalk.bold(`
1984
+ Diff: ${added} added, ${modified} modified
1985
+ `));
1986
+ for (const entry of diffEntries) {
1987
+ const label = entry.status === "added" ? chalk.green("[+] " + entry.filepath) : chalk.yellow("[M] " + entry.filepath);
1988
+ console.log(label);
1989
+ if (verbose) {
1990
+ for (const line of entry.diffLines.slice(0, 50)) {
1991
+ if (line.startsWith("+") && !line.startsWith("+++")) {
1992
+ console.log(chalk.green(line));
1993
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
1994
+ console.log(chalk.red(line));
1995
+ } else {
1996
+ console.log(chalk.dim(line));
1997
+ }
1998
+ }
1999
+ if (entry.diffLines.length > 50) {
2000
+ console.log(chalk.dim(` ... ${entry.diffLines.length - 50} more lines`));
2001
+ }
2002
+ }
2003
+ }
2004
+ console.log();
2005
+ } else if (options.diff) {
2006
+ console.log(chalk.dim("No changes detected."));
2007
+ }
2008
+ if (!options.dryRun) {
2009
+ const totalWritten = allResults.reduce((sum, r) => sum + r.filesWritten.length, 0);
2010
+ const totalDeleted = allResults.reduce((sum, r) => sum + r.filesDeleted.length, 0);
2011
+ const targetNames = allResults.map((r) => r.targetId);
2012
+ const uniqueTargets = [...new Set(targetNames)];
2013
+ console.log(chalk.green(`Generated ${totalWritten} file(s) for ${uniqueTargets.length} target(s)` + (totalDeleted > 0 ? ` (cleaned ${totalDeleted} dir(s))` : "")));
2014
+ }
2015
+ }
2016
+ export {
2017
+ runGenerate
2018
+ };