agentpacks 1.7.13 → 1.8.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 (147) hide show
  1. package/dist/api.js +48 -3658
  2. package/dist/cli/export-cmd.js +7 -1027
  3. package/dist/cli/generate.js +39 -2731
  4. package/dist/cli/import-cmd.js +19 -770
  5. package/dist/cli/info.js +4 -231
  6. package/dist/cli/init.js +9 -185
  7. package/dist/cli/install.js +4 -902
  8. package/dist/cli/login.js +6 -201
  9. package/dist/cli/models-explain.js +14 -1266
  10. package/dist/cli/pack/create.js +4 -146
  11. package/dist/cli/pack/enable.js +2 -65
  12. package/dist/cli/pack/list.js +5 -893
  13. package/dist/cli/pack/validate.js +4 -642
  14. package/dist/cli/publish.js +8 -679
  15. package/dist/cli/search.js +4 -209
  16. package/dist/core/config.d.ts +1 -1
  17. package/dist/core/config.js +1 -145
  18. package/dist/core/dependency-resolver.js +1 -126
  19. package/dist/core/feature-merger.js +3 -398
  20. package/dist/core/index.js +5 -1129
  21. package/dist/core/lockfile.js +2 -43
  22. package/dist/core/metarepo.js +1 -183
  23. package/dist/core/pack-loader.js +4 -841
  24. package/dist/core/profile-resolver.js +1 -110
  25. package/dist/exporters/cursor-plugin.js +6 -404
  26. package/dist/exporters/index.js +6 -404
  27. package/dist/features/agents.js +3 -161
  28. package/dist/features/commands.js +3 -161
  29. package/dist/features/hooks.js +3 -153
  30. package/dist/features/ignore.js +2 -43
  31. package/dist/features/index.js +4 -629
  32. package/dist/features/mcp.js +3 -143
  33. package/dist/features/models.js +3 -292
  34. package/dist/features/plugins.js +3 -139
  35. package/dist/features/rules.d.ts +0 -1
  36. package/dist/features/rules.js +3 -169
  37. package/dist/features/skills.js +3 -228
  38. package/dist/importers/claude-code.js +6 -195
  39. package/dist/importers/cursor.js +5 -355
  40. package/dist/importers/opencode.js +6 -346
  41. package/dist/importers/rulesync.js +5 -365
  42. package/dist/index.js +89 -4934
  43. package/dist/node/api.js +48 -3659
  44. package/dist/node/cli/export-cmd.js +7 -1028
  45. package/dist/node/cli/generate.js +39 -2732
  46. package/dist/node/cli/import-cmd.js +19 -771
  47. package/dist/node/cli/info.js +4 -232
  48. package/dist/node/cli/init.js +9 -186
  49. package/dist/node/cli/install.js +4 -903
  50. package/dist/node/cli/login.js +6 -202
  51. package/dist/node/cli/models-explain.js +14 -1267
  52. package/dist/node/cli/pack/create.js +4 -147
  53. package/dist/node/cli/pack/enable.js +2 -66
  54. package/dist/node/cli/pack/list.js +5 -894
  55. package/dist/node/cli/pack/validate.js +4 -643
  56. package/dist/node/cli/publish.js +8 -680
  57. package/dist/node/cli/search.js +4 -210
  58. package/dist/node/core/config.js +1 -146
  59. package/dist/node/core/dependency-resolver.js +1 -127
  60. package/dist/node/core/feature-merger.js +3 -399
  61. package/dist/node/core/index.js +5 -1130
  62. package/dist/node/core/lockfile.js +2 -44
  63. package/dist/node/core/metarepo.js +1 -184
  64. package/dist/node/core/pack-loader.js +4 -842
  65. package/dist/node/core/profile-resolver.js +1 -111
  66. package/dist/node/exporters/cursor-plugin.js +6 -405
  67. package/dist/node/exporters/index.js +6 -405
  68. package/dist/node/features/agents.js +3 -162
  69. package/dist/node/features/commands.js +3 -162
  70. package/dist/node/features/hooks.js +3 -154
  71. package/dist/node/features/ignore.js +2 -44
  72. package/dist/node/features/index.js +4 -630
  73. package/dist/node/features/mcp.js +3 -144
  74. package/dist/node/features/models.js +3 -293
  75. package/dist/node/features/plugins.js +3 -140
  76. package/dist/node/features/rules.js +3 -170
  77. package/dist/node/features/skills.js +3 -229
  78. package/dist/node/importers/claude-code.js +6 -196
  79. package/dist/node/importers/cursor.js +5 -356
  80. package/dist/node/importers/opencode.js +6 -347
  81. package/dist/node/importers/rulesync.js +5 -366
  82. package/dist/node/index.js +89 -4935
  83. package/dist/node/sources/git-ref.js +1 -56
  84. package/dist/node/sources/git.js +2 -222
  85. package/dist/node/sources/index.js +4 -714
  86. package/dist/node/sources/local.js +1 -24
  87. package/dist/node/sources/npm-ref.js +1 -56
  88. package/dist/node/sources/npm.js +2 -184
  89. package/dist/node/sources/registry-ref.js +1 -37
  90. package/dist/node/sources/registry.js +4 -355
  91. package/dist/node/targets/additional-targets.js +6 -587
  92. package/dist/node/targets/base-target.js +1 -23
  93. package/dist/node/targets/claude-code.js +6 -714
  94. package/dist/node/targets/codex-cli.js +3 -324
  95. package/dist/node/targets/copilot.js +5 -603
  96. package/dist/node/targets/cursor.js +6 -700
  97. package/dist/node/targets/gemini-cli.js +10 -319
  98. package/dist/node/targets/generic-md-target.js +6 -478
  99. package/dist/node/targets/index.js +32 -1873
  100. package/dist/node/targets/mistral-vibe.js +7 -661
  101. package/dist/node/targets/opencode.js +13 -723
  102. package/dist/node/targets/registry.js +32 -1864
  103. package/dist/node/utils/credentials.js +3 -38
  104. package/dist/node/utils/diff.js +5 -132
  105. package/dist/node/utils/filesystem.js +3 -124
  106. package/dist/node/utils/frontmatter.js +1 -24
  107. package/dist/node/utils/global.js +1 -53
  108. package/dist/node/utils/markdown.js +3 -30
  109. package/dist/node/utils/model-allowlist.js +1 -126
  110. package/dist/node/utils/model-guidance.js +2 -78
  111. package/dist/node/utils/registry-client.js +1 -142
  112. package/dist/node/utils/tarball.js +1 -49
  113. package/dist/sources/git-ref.js +1 -55
  114. package/dist/sources/git.js +2 -221
  115. package/dist/sources/index.js +4 -713
  116. package/dist/sources/local.js +1 -23
  117. package/dist/sources/npm-ref.js +1 -55
  118. package/dist/sources/npm.js +2 -183
  119. package/dist/sources/registry-ref.js +1 -36
  120. package/dist/sources/registry.js +4 -354
  121. package/dist/targets/additional-targets.js +6 -586
  122. package/dist/targets/base-target.js +1 -22
  123. package/dist/targets/claude-code.js +6 -713
  124. package/dist/targets/codex-cli.js +3 -323
  125. package/dist/targets/copilot.js +5 -602
  126. package/dist/targets/cursor.js +6 -699
  127. package/dist/targets/gemini-cli.js +10 -318
  128. package/dist/targets/generic-md-target.js +6 -477
  129. package/dist/targets/index.d.ts +0 -1
  130. package/dist/targets/index.js +32 -1872
  131. package/dist/targets/mistral-vibe.js +7 -660
  132. package/dist/targets/opencode.js +13 -722
  133. package/dist/targets/registry.js +32 -1863
  134. package/dist/utils/credentials.js +3 -37
  135. package/dist/utils/diff.js +5 -131
  136. package/dist/utils/filesystem.js +3 -123
  137. package/dist/utils/frontmatter.js +1 -23
  138. package/dist/utils/global.js +1 -52
  139. package/dist/utils/markdown.js +3 -29
  140. package/dist/utils/model-allowlist.js +1 -125
  141. package/dist/utils/model-guidance.js +2 -77
  142. package/dist/utils/registry-client.js +1 -141
  143. package/dist/utils/tarball.js +1 -48
  144. package/package.json +4 -16
  145. package/dist/node/targets/agents-md.js +0 -211
  146. package/dist/targets/agents-md.d.ts +0 -13
  147. package/dist/targets/agents-md.js +0 -211
@@ -1,771 +1,20 @@
1
1
  // @bun
2
- var __require = import.meta.require;
3
-
4
- // src/utils/filesystem.ts
5
- import {
6
- existsSync,
7
- mkdirSync,
8
- readdirSync,
9
- readFileSync,
10
- rmSync,
11
- statSync,
12
- writeFileSync
13
- } from "fs";
14
- import { dirname, join, relative } from "path";
15
- var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
16
- var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
17
- var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
18
- function writeGeneratedFile(filepath, content, options = {}) {
19
- const { header = true, type } = options;
20
- const ext = type ?? inferFileType(filepath);
21
- ensureDir(dirname(filepath));
22
- let output = content;
23
- if (header) {
24
- const headerComment = getHeader(ext);
25
- if (headerComment) {
26
- output = `${headerComment}
27
- ${content}`;
28
- }
29
- }
30
- writeFileSync(filepath, output, "utf-8");
31
- }
32
- function writeGeneratedJson(filepath, data, options = {}) {
33
- const json = JSON.stringify(data, null, 2);
34
- writeGeneratedFile(filepath, json + `
35
- `, { ...options, type: "json" });
36
- }
37
- function readFileOrNull(filepath) {
38
- if (!existsSync(filepath))
39
- return null;
40
- return readFileSync(filepath, "utf-8");
41
- }
42
- function readJsonOrNull(filepath) {
43
- const content = readFileOrNull(filepath);
44
- if (content === null)
45
- return null;
46
- return JSON.parse(content);
47
- }
48
- function ensureDir(dirPath) {
49
- if (!existsSync(dirPath)) {
50
- mkdirSync(dirPath, { recursive: true });
51
- }
52
- }
53
- function removeIfExists(targetPath) {
54
- if (existsSync(targetPath)) {
55
- rmSync(targetPath, { recursive: true, force: true });
56
- }
57
- }
58
- function listFiles(dirPath, options = {}) {
59
- const { extension, recursive = false } = options;
60
- if (!existsSync(dirPath))
61
- return [];
62
- const results = [];
63
- const entries = readdirSync(dirPath);
64
- for (const entry of entries) {
65
- const fullPath = join(dirPath, entry);
66
- const stat = statSync(fullPath);
67
- if (stat.isDirectory() && recursive) {
68
- results.push(...listFiles(fullPath, options));
69
- } else if (stat.isFile()) {
70
- if (!extension || entry.endsWith(extension)) {
71
- results.push(fullPath);
72
- }
73
- }
74
- }
75
- return results;
76
- }
77
- function listDirs(dirPath) {
78
- if (!existsSync(dirPath))
79
- return [];
80
- return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
81
- }
82
- function relPath(projectRoot, filepath) {
83
- return relative(projectRoot, filepath);
84
- }
85
- function isGeneratedFile(filepath) {
86
- const content = readFileOrNull(filepath);
87
- if (!content)
88
- return false;
89
- return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
90
- }
91
- function inferFileType(filepath) {
92
- if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
93
- return "json";
94
- if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
95
- return "ts";
96
- if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
97
- return "js";
98
- return "md";
99
- }
100
- function getHeader(type) {
101
- switch (type) {
102
- case "md":
103
- return GENERATED_HEADER_MD;
104
- case "json":
105
- return GENERATED_HEADER_JSON;
106
- case "js":
107
- case "ts":
108
- return GENERATED_HEADER_JS;
109
- default:
110
- return null;
111
- }
112
- }
113
-
114
- // src/utils/frontmatter.ts
115
- import matter from "gray-matter";
116
- function parseFrontmatter(source) {
117
- const { data, content } = matter(source);
118
- return {
119
- data,
120
- content: content.trim(),
121
- raw: source
122
- };
123
- }
124
- function serializeFrontmatter(data, content) {
125
- const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
126
- if (Object.keys(filtered).length === 0) {
127
- return content;
128
- }
129
- return matter.stringify(content, filtered);
130
- }
131
-
132
- // src/features/skills.ts
133
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
134
- import { basename, join as join2 } from "path";
135
- var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
136
- var SKILL_NAME_MAX_LENGTH = 64;
137
- function parseSkills(skillsDir, packName) {
138
- const dirs = listDirs(skillsDir);
139
- const skills = [];
140
- for (const dir of dirs) {
141
- const skillMd = join2(dir, "SKILL.md");
142
- if (existsSync2(skillMd)) {
143
- skills.push(parseSkillFile(skillMd, dir, packName));
144
- }
145
- }
146
- return skills;
147
- }
148
- function parseSkillFile(filepath, skillDir, packName) {
149
- const raw = readFileSync2(filepath, "utf-8");
150
- const { data, content } = parseFrontmatter(raw);
151
- return {
152
- name: data.name ?? basename(skillDir),
153
- sourcePath: filepath,
154
- sourceDir: skillDir,
155
- packName,
156
- meta: data,
157
- content
158
- };
159
- }
160
- function buildSkillFrontmatter(skill) {
161
- return {
162
- ...skill.meta,
163
- name: skill.name
164
- };
165
- }
166
- function serializeSkill(skill) {
167
- return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
168
- }
169
- function normalizeImportedSkillMarkdown(source, skillName) {
170
- const { data, content } = parseFrontmatter(source);
171
- const normalized = {
172
- ...data,
173
- name: skillName
174
- };
175
- let addedDescription = false;
176
- const description = normalized.description;
177
- if (typeof description !== "string" || description.trim().length === 0) {
178
- normalized.description = `Imported skill: ${skillName}`;
179
- addedDescription = true;
180
- }
181
- return {
182
- content: serializeFrontmatter(normalized, content),
183
- addedDescription
184
- };
185
- }
186
- function validateAgentSkillsFrontmatter(skill) {
187
- const errors = [];
188
- const dirName = basename(skill.sourceDir);
189
- const declaredName = skill.meta.name;
190
- if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
191
- errors.push('Missing required frontmatter field "name".');
192
- } else {
193
- if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
194
- errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
195
- }
196
- if (!SKILL_NAME_PATTERN.test(declaredName)) {
197
- errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
198
- }
199
- if (declaredName !== dirName) {
200
- errors.push(`Invalid "name": must match containing directory "${dirName}".`);
201
- }
202
- }
203
- const description = skill.meta.description;
204
- if (typeof description !== "string" || description.trim().length === 0) {
205
- errors.push('Missing required frontmatter field "description".');
206
- }
207
- const allowedTools = skill.meta["allowed-tools"];
208
- if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
209
- errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
210
- }
211
- return errors;
212
- }
213
- function skillMatchesTarget(skill, targetId) {
214
- const { targets } = skill.meta;
215
- if (!targets || targets === "*")
216
- return true;
217
- if (Array.isArray(targets) && targets.includes("*"))
218
- return true;
219
- return Array.isArray(targets) && targets.includes(targetId);
220
- }
221
-
222
- // src/importers/claude-code.ts
223
- import { copyFileSync, existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
224
- import { basename as basename2, join as join3, resolve } from "path";
225
- function importFromClaudeCode(projectRoot, outputPackDir) {
226
- const warnings = [];
227
- const filesImported = [];
228
- const claudeDir = resolve(projectRoot, ".claude");
229
- const hasClaudeMd = existsSync3(resolve(projectRoot, "CLAUDE.md"));
230
- const hasClaudeDir = existsSync3(claudeDir);
231
- if (!hasClaudeMd && !hasClaudeDir) {
232
- return {
233
- packDir: "",
234
- filesImported: [],
235
- warnings: ["No CLAUDE.md or .claude/ directory found."],
236
- configGenerated: false
237
- };
238
- }
239
- const packDir = outputPackDir ?? resolve(projectRoot, "packs", "claude-import");
240
- ensureDir(packDir);
241
- const rulesDir = resolve(packDir, "rules");
242
- ensureDir(rulesDir);
243
- if (hasClaudeMd) {
244
- const raw = readFileSync3(resolve(projectRoot, "CLAUDE.md"), "utf-8");
245
- const ruleContent = [
246
- "---",
247
- "root: true",
248
- 'description: "Root Claude Code rules"',
249
- "---",
250
- "",
251
- raw
252
- ].join(`
253
- `);
254
- const dest = join3(rulesDir, "claude-root.md");
255
- writeFileSync2(dest, ruleContent);
256
- filesImported.push(dest);
257
- }
258
- if (hasClaudeDir) {
259
- const claudeRulesDir = resolve(claudeDir, "rules");
260
- if (existsSync3(claudeRulesDir)) {
261
- const files = listFiles(claudeRulesDir, { extension: ".md" });
262
- for (const file of files) {
263
- const dest = join3(rulesDir, basename2(file));
264
- copyFileSync(file, dest);
265
- filesImported.push(dest);
266
- }
267
- }
268
- const settingsPath = resolve(claudeDir, "settings.json");
269
- if (existsSync3(settingsPath)) {
270
- try {
271
- const raw = readFileSync3(settingsPath, "utf-8");
272
- const settings = JSON.parse(raw);
273
- const mcpServers = settings.mcpServers ?? settings.mcp_servers;
274
- if (mcpServers && typeof mcpServers === "object") {
275
- const mcpConfig = { servers: mcpServers };
276
- const dest = join3(packDir, "mcp.json");
277
- writeFileSync2(dest, JSON.stringify(mcpConfig, null, 2) + `
278
- `);
279
- filesImported.push(dest);
280
- }
281
- } catch {
282
- warnings.push("Failed to parse .claude/settings.json");
283
- }
284
- }
285
- }
286
- const packJson = {
287
- name: "claude-import",
288
- version: "1.0.0",
289
- description: "Imported from Claude Code",
290
- tags: ["imported", "claude-code"],
291
- dependencies: [],
292
- conflicts: [],
293
- targets: "*",
294
- features: "*"
295
- };
296
- const packJsonPath = join3(packDir, "pack.json");
297
- writeFileSync2(packJsonPath, JSON.stringify(packJson, null, 2) + `
298
- `);
299
- filesImported.push(packJsonPath);
300
- return { packDir, filesImported, warnings, configGenerated: false };
301
- }
302
-
303
- // src/importers/cursor.ts
304
- import { copyFileSync as copyFileSync2, existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
305
- import { basename as basename3, join as join4, resolve as resolve2 } from "path";
306
- function importFromCursor(projectRoot, outputPackDir) {
307
- const cursorDir = resolve2(projectRoot, ".cursor");
308
- const warnings = [];
309
- const filesImported = [];
310
- if (!existsSync4(cursorDir)) {
311
- return {
312
- packDir: "",
313
- filesImported: [],
314
- warnings: ["No .cursor/ directory found."],
315
- configGenerated: false
316
- };
317
- }
318
- const packDir = outputPackDir ?? resolve2(projectRoot, "packs", "cursor-import");
319
- ensureDir(packDir);
320
- const rulesDir = resolve2(cursorDir, "rules");
321
- if (existsSync4(rulesDir)) {
322
- const outRulesDir = resolve2(packDir, "rules");
323
- ensureDir(outRulesDir);
324
- const files = listFiles(rulesDir, { extension: ".mdc" });
325
- for (const file of files) {
326
- const raw = readFileSync4(file, "utf-8");
327
- const { data, content } = parseFrontmatter(raw);
328
- const meta = {};
329
- if (data.description)
330
- meta.description = data.description;
331
- if (data.alwaysApply)
332
- meta.root = true;
333
- if (data.globs)
334
- meta.globs = data.globs;
335
- meta.cursor = { ...data };
336
- const mdContent = buildAgentpacksRule(meta, content);
337
- const name = basename3(file, ".mdc");
338
- const dest = join4(outRulesDir, `${name}.md`);
339
- writeFileSync3(dest, mdContent);
340
- filesImported.push(dest);
341
- }
342
- const mdFiles = listFiles(rulesDir, { extension: ".md" });
343
- for (const file of mdFiles) {
344
- const dest = join4(outRulesDir, basename3(file));
345
- copyFileSync2(file, dest);
346
- filesImported.push(dest);
347
- }
348
- }
349
- const agentsDir = resolve2(cursorDir, "agents");
350
- if (existsSync4(agentsDir)) {
351
- const outDir = resolve2(packDir, "agents");
352
- ensureDir(outDir);
353
- const files = listFiles(agentsDir, { extension: ".md" });
354
- for (const file of files) {
355
- const dest = join4(outDir, basename3(file));
356
- copyFileSync2(file, dest);
357
- filesImported.push(dest);
358
- }
359
- }
360
- const skillsDir = resolve2(cursorDir, "skills");
361
- if (existsSync4(skillsDir)) {
362
- const outDir = resolve2(packDir, "skills");
363
- ensureDir(outDir);
364
- const dirs = listDirs(skillsDir);
365
- for (const dir of dirs) {
366
- const name = basename3(dir);
367
- const skillMd = join4(dir, "SKILL.md");
368
- if (existsSync4(skillMd)) {
369
- const outSkillDir = join4(outDir, name);
370
- ensureDir(outSkillDir);
371
- const rawSkill = readFileSync4(skillMd, "utf-8");
372
- const normalized = normalizeImportedSkillMarkdown(rawSkill, name);
373
- const dest = join4(outSkillDir, "SKILL.md");
374
- writeFileSync3(dest, normalized.content);
375
- filesImported.push(dest);
376
- if (normalized.addedDescription) {
377
- warnings.push(`skills/${name}/SKILL.md missing description; added import placeholder.`);
378
- }
379
- }
380
- }
381
- }
382
- const commandsDir = resolve2(cursorDir, "commands");
383
- if (existsSync4(commandsDir)) {
384
- const outDir = resolve2(packDir, "commands");
385
- ensureDir(outDir);
386
- const files = listFiles(commandsDir, { extension: ".md" });
387
- for (const file of files) {
388
- const dest = join4(outDir, basename3(file));
389
- copyFileSync2(file, dest);
390
- filesImported.push(dest);
391
- }
392
- }
393
- const mcpJson = resolve2(cursorDir, "mcp.json");
394
- if (existsSync4(mcpJson)) {
395
- copyFileSync2(mcpJson, join4(packDir, "mcp.json"));
396
- filesImported.push(join4(packDir, "mcp.json"));
397
- }
398
- const cursorIgnore = resolve2(projectRoot, ".cursorignore");
399
- if (existsSync4(cursorIgnore)) {
400
- copyFileSync2(cursorIgnore, join4(packDir, "ignore"));
401
- filesImported.push(join4(packDir, "ignore"));
402
- }
403
- writePackJson(packDir, "cursor-import", filesImported);
404
- return { packDir, filesImported, warnings, configGenerated: false };
405
- }
406
- function buildAgentpacksRule(meta, content) {
407
- const lines = ["---"];
408
- for (const [k, v] of Object.entries(meta)) {
409
- if (typeof v === "object") {
410
- lines.push(`${k}: ${JSON.stringify(v)}`);
411
- } else {
412
- lines.push(`${k}: ${v}`);
413
- }
414
- }
415
- lines.push("---", "", content);
416
- return lines.join(`
417
- `);
418
- }
419
- function writePackJson(packDir, name, filesImported) {
420
- const packJson = {
421
- name,
422
- version: "1.0.0",
423
- description: `Imported from Cursor`,
424
- tags: ["imported", "cursor"],
425
- dependencies: [],
426
- conflicts: [],
427
- targets: "*",
428
- features: "*"
429
- };
430
- const dest = join4(packDir, "pack.json");
431
- writeFileSync3(dest, JSON.stringify(packJson, null, 2) + `
432
- `);
433
- filesImported.push(dest);
434
- }
435
-
436
- // src/importers/opencode.ts
437
- import { copyFileSync as copyFileSync3, existsSync as existsSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
438
- import { basename as basename4, join as join5, resolve as resolve3 } from "path";
439
- function importFromOpenCode(projectRoot, outputPackDir) {
440
- const warnings = [];
441
- const filesImported = [];
442
- const ocDir = resolve3(projectRoot, ".opencode");
443
- if (!existsSync5(ocDir)) {
444
- return {
445
- packDir: "",
446
- filesImported: [],
447
- warnings: ["No .opencode/ directory found."],
448
- configGenerated: false
449
- };
450
- }
451
- const packDir = outputPackDir ?? resolve3(projectRoot, "packs", "opencode-import");
452
- ensureDir(packDir);
453
- importDirMd(resolve3(ocDir, "rules"), resolve3(packDir, "rules"), filesImported);
454
- importDirMd(resolve3(ocDir, "commands"), resolve3(packDir, "commands"), filesImported);
455
- importDirMd(resolve3(ocDir, "agents"), resolve3(packDir, "agents"), filesImported);
456
- const skillDir = resolve3(ocDir, "skill");
457
- if (existsSync5(skillDir)) {
458
- const outSkillDir = resolve3(packDir, "skills");
459
- ensureDir(outSkillDir);
460
- const dirs = listDirs(skillDir);
461
- for (const dir of dirs) {
462
- const name = basename4(dir);
463
- if (name.startsWith("."))
464
- continue;
465
- const skillMd = join5(dir, "SKILL.md");
466
- if (existsSync5(skillMd)) {
467
- const outDir = join5(outSkillDir, name);
468
- ensureDir(outDir);
469
- const rawSkill = readFileSync5(skillMd, "utf-8");
470
- const normalized = normalizeImportedSkillMarkdown(rawSkill, name);
471
- const dest2 = join5(outDir, "SKILL.md");
472
- writeFileSync4(dest2, normalized.content);
473
- filesImported.push(dest2);
474
- if (normalized.addedDescription) {
475
- warnings.push(`skills/${name}/SKILL.md missing description; added import placeholder.`);
476
- }
477
- }
478
- }
479
- }
480
- const pluginsDir = resolve3(ocDir, "plugins");
481
- if (existsSync5(pluginsDir)) {
482
- const outPluginsDir = resolve3(packDir, "plugins");
483
- ensureDir(outPluginsDir);
484
- const files = listFiles(pluginsDir);
485
- for (const file of files) {
486
- if (file.endsWith(".ts") || file.endsWith(".js")) {
487
- const dest2 = join5(outPluginsDir, basename4(file));
488
- copyFileSync3(file, dest2);
489
- filesImported.push(dest2);
490
- }
491
- }
492
- }
493
- const agentsMd = resolve3(projectRoot, "AGENTS.md");
494
- if (existsSync5(agentsMd)) {
495
- const outRulesDir = resolve3(packDir, "rules");
496
- ensureDir(outRulesDir);
497
- const raw = readFileSync5(agentsMd, "utf-8");
498
- const ruleContent = [
499
- "---",
500
- "root: true",
501
- 'description: "AGENTS.md root rules"',
502
- "---",
503
- "",
504
- raw
505
- ].join(`
506
- `);
507
- const dest2 = join5(outRulesDir, "agents-md-root.md");
508
- writeFileSync4(dest2, ruleContent);
509
- filesImported.push(dest2);
510
- }
511
- const ocJson = resolve3(projectRoot, "opencode.json");
512
- if (existsSync5(ocJson)) {
513
- try {
514
- const raw = readFileSync5(ocJson, "utf-8");
515
- const config = JSON.parse(raw);
516
- const mcpObj = config.mcp;
517
- if (mcpObj) {
518
- const dest2 = join5(packDir, "mcp.json");
519
- writeFileSync4(dest2, JSON.stringify({ servers: mcpObj }, null, 2) + `
520
- `);
521
- filesImported.push(dest2);
522
- }
523
- } catch {
524
- warnings.push("Failed to parse opencode.json");
525
- }
526
- }
527
- const ocIgnore = resolve3(projectRoot, ".opencodeignore");
528
- if (existsSync5(ocIgnore)) {
529
- copyFileSync3(ocIgnore, join5(packDir, "ignore"));
530
- filesImported.push(join5(packDir, "ignore"));
531
- }
532
- const packJson = {
533
- name: "opencode-import",
534
- version: "1.0.0",
535
- description: "Imported from OpenCode",
536
- tags: ["imported", "opencode"],
537
- dependencies: [],
538
- conflicts: [],
539
- targets: "*",
540
- features: "*"
541
- };
542
- const dest = join5(packDir, "pack.json");
543
- writeFileSync4(dest, JSON.stringify(packJson, null, 2) + `
544
- `);
545
- filesImported.push(dest);
546
- return { packDir, filesImported, warnings, configGenerated: false };
547
- }
548
- function importDirMd(srcDir, outDir, filesImported) {
549
- if (!existsSync5(srcDir))
550
- return;
551
- ensureDir(outDir);
552
- const files = listFiles(srcDir, { extension: ".md" });
553
- for (const file of files) {
554
- const dest = join5(outDir, basename4(file));
555
- copyFileSync3(file, dest);
556
- filesImported.push(dest);
557
- }
558
- }
559
-
560
- // src/importers/rulesync.ts
561
- import { copyFileSync as copyFileSync4, existsSync as existsSync6, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "fs";
562
- import { parse as parseJsonc } from "jsonc-parser";
563
- import { basename as basename5, join as join6, resolve as resolve4 } from "path";
564
- function importFromRulesync(projectRoot, outputPackDir) {
565
- const rulesyncDir = resolve4(projectRoot, ".rulesync");
566
- const warnings = [];
567
- const filesImported = [];
568
- if (!existsSync6(rulesyncDir)) {
569
- return {
570
- packDir: "",
571
- filesImported: [],
572
- warnings: ["No .rulesync/ directory found."],
573
- configGenerated: false
574
- };
575
- }
576
- const packDir = outputPackDir ?? resolve4(projectRoot, "packs", "default");
577
- ensureDir(packDir);
578
- const rulesDir = resolve4(rulesyncDir, "rules");
579
- if (existsSync6(rulesDir)) {
580
- const outRulesDir = resolve4(packDir, "rules");
581
- ensureDir(outRulesDir);
582
- const files = listFiles(rulesDir, { extension: ".md" });
583
- for (const file of files) {
584
- const dest = join6(outRulesDir, basename5(file));
585
- copyFileSync4(file, dest);
586
- filesImported.push(dest);
587
- }
588
- }
589
- const commandsDir = resolve4(rulesyncDir, "commands");
590
- if (existsSync6(commandsDir)) {
591
- const outCommandsDir = resolve4(packDir, "commands");
592
- ensureDir(outCommandsDir);
593
- const files = listFiles(commandsDir, { extension: ".md" });
594
- for (const file of files) {
595
- const dest = join6(outCommandsDir, basename5(file));
596
- copyFileSync4(file, dest);
597
- filesImported.push(dest);
598
- }
599
- }
600
- const subagentsDir = resolve4(rulesyncDir, "subagents");
601
- if (existsSync6(subagentsDir)) {
602
- const outAgentsDir = resolve4(packDir, "agents");
603
- ensureDir(outAgentsDir);
604
- const files = listFiles(subagentsDir, { extension: ".md" });
605
- for (const file of files) {
606
- const dest = join6(outAgentsDir, basename5(file));
607
- copyFileSync4(file, dest);
608
- filesImported.push(dest);
609
- }
610
- }
611
- const skillsDir = resolve4(rulesyncDir, "skills");
612
- if (existsSync6(skillsDir)) {
613
- const outSkillsDir = resolve4(packDir, "skills");
614
- ensureDir(outSkillsDir);
615
- const skillDirs = listDirs(skillsDir);
616
- for (const skillDir of skillDirs) {
617
- const skillName = basename5(skillDir);
618
- if (skillName.startsWith("."))
619
- continue;
620
- const skillMd = join6(skillDir, "SKILL.md");
621
- if (existsSync6(skillMd)) {
622
- const outSkillDir = join6(outSkillsDir, skillName);
623
- ensureDir(outSkillDir);
624
- const rawSkill = readFileSync6(skillMd, "utf-8");
625
- const normalized = normalizeImportedSkillMarkdown(rawSkill, skillName);
626
- const dest = join6(outSkillDir, "SKILL.md");
627
- writeFileSync5(dest, normalized.content);
628
- filesImported.push(dest);
629
- if (normalized.addedDescription) {
630
- warnings.push(`skills/${skillName}/SKILL.md missing description; added import placeholder.`);
631
- }
632
- }
633
- }
634
- }
635
- const hooksJson = resolve4(rulesyncDir, "hooks.json");
636
- if (existsSync6(hooksJson)) {
637
- const outHooksDir = resolve4(packDir, "hooks");
638
- ensureDir(outHooksDir);
639
- copyFileSync4(hooksJson, join6(outHooksDir, "hooks.json"));
640
- filesImported.push(join6(outHooksDir, "hooks.json"));
641
- }
642
- const mcpJson = resolve4(rulesyncDir, "mcp.json");
643
- if (existsSync6(mcpJson)) {
644
- copyFileSync4(mcpJson, join6(packDir, "mcp.json"));
645
- filesImported.push(join6(packDir, "mcp.json"));
646
- }
647
- const aiIgnore = resolve4(rulesyncDir, ".aiignore");
648
- const rulesyncIgnore = resolve4(projectRoot, ".rulesyncignore");
649
- if (existsSync6(aiIgnore)) {
650
- copyFileSync4(aiIgnore, join6(packDir, "ignore"));
651
- filesImported.push(join6(packDir, "ignore"));
652
- } else if (existsSync6(rulesyncIgnore)) {
653
- copyFileSync4(rulesyncIgnore, join6(packDir, "ignore"));
654
- filesImported.push(join6(packDir, "ignore"));
655
- }
656
- const packJson = {
657
- name: "default",
658
- version: "1.0.0",
659
- description: "Imported from rulesync",
660
- tags: ["imported", "rulesync"],
661
- dependencies: [],
662
- conflicts: [],
663
- targets: "*",
664
- features: "*"
665
- };
666
- writeFileSync5(join6(packDir, "pack.json"), JSON.stringify(packJson, null, 2) + `
667
- `);
668
- filesImported.push(join6(packDir, "pack.json"));
669
- let configGenerated = false;
670
- const rulesyncConfig = resolve4(projectRoot, "rulesync.jsonc");
671
- if (existsSync6(rulesyncConfig)) {
672
- const agentpacksConfig = convertRulesyncConfig(rulesyncConfig, packDir);
673
- const configPath = resolve4(projectRoot, "agentpacks.jsonc");
674
- writeFileSync5(configPath, agentpacksConfig);
675
- configGenerated = true;
676
- }
677
- return { packDir, filesImported, warnings, configGenerated };
678
- }
679
- function convertRulesyncConfig(rulesyncPath, _packDir) {
680
- const raw = readFileSync6(rulesyncPath, "utf-8");
681
- const parsed = parseJsonc(raw);
682
- const targets = parsed.targets ?? ["opencode", "cursor", "claudecode"];
683
- const features = parsed.features ?? ["*"];
684
- const baseDirs = parsed.baseDirs ?? ["."];
685
- const global = parsed.global ?? false;
686
- const deleteVal = parsed.delete ?? true;
687
- const relPackDir = "./" + join6("packs", "default");
688
- const config = {
689
- $schema: "https://unpkg.com/agentpacks/schema.json",
690
- packs: [relPackDir],
691
- disabled: [],
692
- targets,
693
- features,
694
- mode: baseDirs.length > 1 ? "monorepo" : "repo",
695
- baseDirs,
696
- global,
697
- delete: deleteVal
698
- };
699
- return JSON.stringify(config, null, 2) + `
700
- `;
701
- }
702
-
703
- // src/cli/import-cmd.ts
704
- import chalk from "chalk";
705
- function runImport(projectRoot, options) {
706
- const { from, output } = options;
707
- switch (from) {
708
- case "rulesync": {
709
- console.log(chalk.dim("Importing from .rulesync/ ..."));
710
- const result = importFromRulesync(projectRoot, output);
711
- if (result.warnings.length > 0) {
712
- for (const w of result.warnings) {
713
- console.log(chalk.yellow(` warn: ${w}`));
714
- }
715
- return;
716
- }
717
- console.log(chalk.green(`Imported ${result.filesImported.length} file(s) to ${result.packDir}`));
718
- if (result.configGenerated) {
719
- console.log(chalk.green("Generated agentpacks.jsonc from rulesync.jsonc"));
720
- }
721
- console.log(chalk.cyan(`
722
- Next steps:`), `
723
- 1. Review the imported pack at`, chalk.bold(result.packDir), `
724
- 2. Run`, chalk.bold("agentpacks generate"), "to generate tool configs");
725
- break;
726
- }
727
- case "cursor": {
728
- console.log(chalk.dim("Importing from .cursor/ ..."));
729
- const cursorResult = importFromCursor(projectRoot, output);
730
- printImportResult(cursorResult, "Cursor");
731
- break;
732
- }
733
- case "claude":
734
- case "claudecode":
735
- case "claude-code": {
736
- console.log(chalk.dim("Importing from Claude Code..."));
737
- const claudeResult = importFromClaudeCode(projectRoot, output);
738
- printImportResult(claudeResult, "Claude Code");
739
- break;
740
- }
741
- case "opencode": {
742
- console.log(chalk.dim("Importing from .opencode/ ..."));
743
- const ocResult = importFromOpenCode(projectRoot, output);
744
- printImportResult(ocResult, "OpenCode");
745
- break;
746
- }
747
- default:
748
- console.log(chalk.red(`Unknown import source: "${from}"`));
749
- console.log(chalk.dim("Supported sources: rulesync, cursor, claude-code, opencode"));
750
- break;
751
- }
752
- }
753
- function printImportResult(result, sourceName) {
754
- if (result.warnings.length > 0 && result.filesImported.length === 0) {
755
- for (const w of result.warnings) {
756
- console.log(chalk.yellow(` warn: ${w}`));
757
- }
758
- return;
759
- }
760
- for (const w of result.warnings) {
761
- console.log(chalk.yellow(` warn: ${w}`));
762
- }
763
- console.log(chalk.green(`Imported ${result.filesImported.length} file(s) from ${sourceName} to ${result.packDir}`));
764
- console.log(chalk.cyan(`
765
- Next steps:`), `
766
- 1. Review the imported pack at`, chalk.bold(result.packDir), `
767
- 2. Run`, chalk.bold("agentpacks generate"), "to generate tool configs");
768
- }
769
- export {
770
- runImport
771
- };
2
+ var pq=import.meta.require;import{existsSync as m,mkdirSync as Mq,readdirSync as Yq,readFileSync as Eq,rmSync as Nq,statSync as Zq,writeFileSync as xq}from"fs";import{dirname as wq,join as $q,relative as Pq}from"path";var Vq="<!-- Generated by agentpacks. DO NOT EDIT. -->",Wq="// Generated by agentpacks. DO NOT EDIT.",Xq="// Generated by agentpacks. DO NOT EDIT.";function Iq(q,Y,Q={}){let{header:Z=!0,type:B}=Q,U=B??gq(q);O(wq(q));let X=Y;if(Z){let G=vq(U);if(G)X=`${G}
3
+ ${Y}`}xq(q,X,"utf-8")}function lq(q,Y,Q={}){let Z=JSON.stringify(Y,null,2);Iq(q,Z+`
4
+ `,{...Q,type:"json"})}function Kq(q){if(!m(q))return null;return Eq(q,"utf-8")}function oq(q){let Y=Kq(q);if(Y===null)return null;return JSON.parse(Y)}function O(q){if(!m(q))Mq(q,{recursive:!0})}function sq(q){if(m(q))Nq(q,{recursive:!0,force:!0})}function E(q,Y={}){let{extension:Q,recursive:Z=!1}=Y;if(!m(q))return[];let B=[],U=Yq(q);for(let X of U){let G=$q(q,X),_=Zq(G);if(_.isDirectory()&&Z)B.push(...E(G,Y));else if(_.isFile()){if(!Q||X.endsWith(Q))B.push(G)}}return B}function F(q){if(!m(q))return[];return Yq(q).map((Y)=>$q(q,Y)).filter((Y)=>Zq(Y).isDirectory())}function tq(q,Y){return Pq(q,Y)}function iq(q){let Y=Kq(q);if(!Y)return!1;return Y.startsWith(Vq)||Y.startsWith(Wq)||Y.startsWith(Xq)}function gq(q){if(q.endsWith(".json")||q.endsWith(".jsonc"))return"json";if(q.endsWith(".ts")||q.endsWith(".mts"))return"ts";if(q.endsWith(".js")||q.endsWith(".mjs"))return"js";return"md"}function vq(q){switch(q){case"md":return Vq;case"json":return Wq;case"js":case"ts":return Xq;default:return null}}import Oq from"gray-matter";function D(q){let{data:Y,content:Q}=Oq(q);return{data:Y,content:Q.trim(),raw:q}}function l(q,Y){let Q=Object.fromEntries(Object.entries(q).filter(([,Z])=>Z!==void 0));if(Object.keys(Q).length===0)return Y;return Oq.stringify(Y,Q)}import{existsSync as Fq,readFileSync as Rq}from"fs";import{basename as Gq,join as hq}from"path";var jq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,Lq=64;function ZB(q,Y){let Q=F(q),Z=[];for(let B of Q){let U=hq(B,"SKILL.md");if(Fq(U))Z.push(Sq(U,B,Y))}return Z}function Sq(q,Y,Q){let Z=Rq(q,"utf-8"),{data:B,content:U}=D(Z);return{name:B.name??Gq(Y),sourcePath:q,sourceDir:Y,packName:Q,meta:B,content:U}}function yq(q){return{...q.meta,name:q.name}}function $B(q){return l(yq(q),q.content)}function f(q,Y){let{data:Q,content:Z}=D(q),B={...Q,name:Y},U=!1,X=B.description;if(typeof X!=="string"||X.trim().length===0)B.description=`Imported skill: ${Y}`,U=!0;return{content:l(B,Z),addedDescription:U}}function VB(q){let Y=[],Q=Gq(q.sourceDir),Z=q.meta.name;if(typeof Z!=="string"||Z.trim().length===0)Y.push('Missing required frontmatter field "name".');else{if(Z.length>Lq)Y.push(`Invalid "name": must be at most ${Lq} characters.`);if(!jq.test(Z))Y.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==Q)Y.push(`Invalid "name": must match containing directory "${Q}".`)}let B=q.meta.description;if(typeof B!=="string"||B.trim().length===0)Y.push('Missing required frontmatter field "description".');let U=q.meta["allowed-tools"];if(U!==void 0&&(!Array.isArray(U)||U.some((X)=>typeof X!=="string"||X.length===0)))Y.push('Invalid "allowed-tools": expected an array of non-empty strings.');return Y}function WB(q,Y){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(Y)}import{copyFileSync as fq,existsSync as p,readFileSync as Hq,writeFileSync as o}from"fs";import{basename as kq,join as c,resolve as S}from"path";function Tq(q,Y){let Q=[],Z=[],B=S(q,".claude"),U=p(S(q,"CLAUDE.md")),X=p(B);if(!U&&!X)return{packDir:"",filesImported:[],warnings:["No CLAUDE.md or .claude/ directory found."],configGenerated:!1};let G=Y??S(q,"packs","claude-import");O(G);let _=S(G,"rules");if(O(_),U){let H=["---","root: true",'description: "Root Claude Code rules"',"---","",Hq(S(q,"CLAUDE.md"),"utf-8")].join(`
5
+ `),W=c(_,"claude-root.md");o(W,H),Z.push(W)}if(X){let I=S(B,"rules");if(p(I)){let W=E(I,{extension:".md"});for(let L of W){let $=c(_,kq(L));fq(L,$),Z.push($)}}let H=S(B,"settings.json");if(p(H))try{let W=Hq(H,"utf-8"),L=JSON.parse(W),$=L.mcpServers??L.mcp_servers;if($&&typeof $==="object"){let K={servers:$},V=c(G,"mcp.json");o(V,JSON.stringify(K,null,2)+`
6
+ `),Z.push(V)}}catch{Q.push("Failed to parse .claude/settings.json")}}let P={name:"claude-import",version:"1.0.0",description:"Imported from Claude Code",tags:["imported","claude-code"],dependencies:[],conflicts:[],targets:"*",features:"*"},N=c(G,"pack.json");return o(N,JSON.stringify(P,null,2)+`
7
+ `),Z.push(N),{packDir:G,filesImported:Z,warnings:Q,configGenerated:!1}}import{copyFileSync as u,existsSync as R,readFileSync as zq,writeFileSync as s}from"fs";import{basename as d,join as w,resolve as x}from"path";function Jq(q,Y){let Q=x(q,".cursor"),Z=[],B=[];if(!R(Q))return{packDir:"",filesImported:[],warnings:["No .cursor/ directory found."],configGenerated:!1};let U=Y??x(q,"packs","cursor-import");O(U);let X=x(Q,"rules");if(R(X)){let H=x(U,"rules");O(H);let W=E(X,{extension:".mdc"});for(let $ of W){let K=zq($,"utf-8"),{data:V,content:b}=D(K),T={};if(V.description)T.description=V.description;if(V.alwaysApply)T.root=!0;if(V.globs)T.globs=V.globs;T.cursor={...V};let z=mq(T,b),j=d($,".mdc"),k=w(H,`${j}.md`);s(k,z),B.push(k)}let L=E(X,{extension:".md"});for(let $ of L){let K=w(H,d($));u($,K),B.push(K)}}let G=x(Q,"agents");if(R(G)){let H=x(U,"agents");O(H);let W=E(G,{extension:".md"});for(let L of W){let $=w(H,d(L));u(L,$),B.push($)}}let _=x(Q,"skills");if(R(_)){let H=x(U,"skills");O(H);let W=F(_);for(let L of W){let $=d(L),K=w(L,"SKILL.md");if(R(K)){let V=w(H,$);O(V);let b=zq(K,"utf-8"),T=f(b,$),z=w(V,"SKILL.md");if(s(z,T.content),B.push(z),T.addedDescription)Z.push(`skills/${$}/SKILL.md missing description; added import placeholder.`)}}}let P=x(Q,"commands");if(R(P)){let H=x(U,"commands");O(H);let W=E(P,{extension:".md"});for(let L of W){let $=w(H,d(L));u(L,$),B.push($)}}let N=x(Q,"mcp.json");if(R(N))u(N,w(U,"mcp.json")),B.push(w(U,"mcp.json"));let I=x(q,".cursorignore");if(R(I))u(I,w(U,"ignore")),B.push(w(U,"ignore"));return Dq(U,"cursor-import",B),{packDir:U,filesImported:B,warnings:Z,configGenerated:!1}}function mq(q,Y){let Q=["---"];for(let[Z,B]of Object.entries(q))if(typeof B==="object")Q.push(`${Z}: ${JSON.stringify(B)}`);else Q.push(`${Z}: ${B}`);return Q.push("---","",Y),Q.join(`
8
+ `)}function Dq(q,Y,Q){let Z={name:Y,version:"1.0.0",description:"Imported from Cursor",tags:["imported","cursor"],dependencies:[],conflicts:[],targets:"*",features:"*"},B=w(q,"pack.json");s(B,JSON.stringify(Z,null,2)+`
9
+ `),Q.push(B)}import{copyFileSync as r,existsSync as h,readFileSync as t,writeFileSync as n}from"fs";import{basename as e,join as v,resolve as M}from"path";function _q(q,Y){let Q=[],Z=[],B=M(q,".opencode");if(!h(B))return{packDir:"",filesImported:[],warnings:["No .opencode/ directory found."],configGenerated:!1};let U=Y??M(q,"packs","opencode-import");O(U),i(M(B,"rules"),M(U,"rules"),Z),i(M(B,"commands"),M(U,"commands"),Z),i(M(B,"agents"),M(U,"agents"),Z);let X=M(B,"skill");if(h(X)){let W=M(U,"skills");O(W);let L=F(X);for(let $ of L){let K=e($);if(K.startsWith("."))continue;let V=v($,"SKILL.md");if(h(V)){let b=v(W,K);O(b);let T=t(V,"utf-8"),z=f(T,K),j=v(b,"SKILL.md");if(n(j,z.content),Z.push(j),z.addedDescription)Q.push(`skills/${K}/SKILL.md missing description; added import placeholder.`)}}}let G=M(B,"plugins");if(h(G)){let W=M(U,"plugins");O(W);let L=E(G);for(let $ of L)if($.endsWith(".ts")||$.endsWith(".js")){let K=v(W,e($));r($,K),Z.push(K)}}let _=M(q,"AGENTS.md");if(h(_)){let W=M(U,"rules");O(W);let $=["---","root: true",'description: "AGENTS.md root rules"',"---","",t(_,"utf-8")].join(`
10
+ `),K=v(W,"agents-md-root.md");n(K,$),Z.push(K)}let P=M(q,"opencode.json");if(h(P))try{let W=t(P,"utf-8"),$=JSON.parse(W).mcp;if($){let K=v(U,"mcp.json");n(K,JSON.stringify({servers:$},null,2)+`
11
+ `),Z.push(K)}}catch{Q.push("Failed to parse opencode.json")}let N=M(q,".opencodeignore");if(h(N))r(N,v(U,"ignore")),Z.push(v(U,"ignore"));let I={name:"opencode-import",version:"1.0.0",description:"Imported from OpenCode",tags:["imported","opencode"],dependencies:[],conflicts:[],targets:"*",features:"*"},H=v(U,"pack.json");return n(H,JSON.stringify(I,null,2)+`
12
+ `),Z.push(H),{packDir:U,filesImported:Z,warnings:Q,configGenerated:!1}}function i(q,Y,Q){if(!h(q))return;O(Y);let Z=E(q,{extension:".md"});for(let B of Z){let U=v(Y,e(B));r(B,U),Q.push(U)}}import{copyFileSync as y,existsSync as g,readFileSync as Aq,writeFileSync as qq}from"fs";import{parse as uq}from"jsonc-parser";import{basename as a,join as C,resolve as A}from"path";function Cq(q,Y){let Q=A(q,".rulesync"),Z=[],B=[];if(!g(Q))return{packDir:"",filesImported:[],warnings:["No .rulesync/ directory found."],configGenerated:!1};let U=Y??A(q,"packs","default");O(U);let X=A(Q,"rules");if(g(X)){let V=A(U,"rules");O(V);let b=E(X,{extension:".md"});for(let T of b){let z=C(V,a(T));y(T,z),B.push(z)}}let G=A(Q,"commands");if(g(G)){let V=A(U,"commands");O(V);let b=E(G,{extension:".md"});for(let T of b){let z=C(V,a(T));y(T,z),B.push(z)}}let _=A(Q,"subagents");if(g(_)){let V=A(U,"agents");O(V);let b=E(_,{extension:".md"});for(let T of b){let z=C(V,a(T));y(T,z),B.push(z)}}let P=A(Q,"skills");if(g(P)){let V=A(U,"skills");O(V);let b=F(P);for(let T of b){let z=a(T);if(z.startsWith("."))continue;let j=C(T,"SKILL.md");if(g(j)){let k=C(V,z);O(k);let bq=Aq(j,"utf-8"),Qq=f(bq,z),Uq=C(k,"SKILL.md");if(qq(Uq,Qq.content),B.push(Uq),Qq.addedDescription)Z.push(`skills/${z}/SKILL.md missing description; added import placeholder.`)}}}let N=A(Q,"hooks.json");if(g(N)){let V=A(U,"hooks");O(V),y(N,C(V,"hooks.json")),B.push(C(V,"hooks.json"))}let I=A(Q,"mcp.json");if(g(I))y(I,C(U,"mcp.json")),B.push(C(U,"mcp.json"));let H=A(Q,".aiignore"),W=A(q,".rulesyncignore");if(g(H))y(H,C(U,"ignore")),B.push(C(U,"ignore"));else if(g(W))y(W,C(U,"ignore")),B.push(C(U,"ignore"));let L={name:"default",version:"1.0.0",description:"Imported from rulesync",tags:["imported","rulesync"],dependencies:[],conflicts:[],targets:"*",features:"*"};qq(C(U,"pack.json"),JSON.stringify(L,null,2)+`
13
+ `),B.push(C(U,"pack.json"));let $=!1,K=A(q,"rulesync.jsonc");if(g(K)){let V=dq(K,U),b=A(q,"agentpacks.jsonc");qq(b,V),$=!0}return{packDir:U,filesImported:B,warnings:Z,configGenerated:$}}function dq(q,Y){let Q=Aq(q,"utf-8"),Z=uq(Q),B=Z.targets??["opencode","cursor","claudecode"],U=Z.features??["*"],X=Z.baseDirs??["."],G=Z.global??!1,_=Z.delete??!0,N={$schema:"https://unpkg.com/agentpacks/schema.json",packs:["./"+C("packs","default")],disabled:[],targets:B,features:U,mode:X.length>1?"monorepo":"repo",baseDirs:X,global:G,delete:_};return JSON.stringify(N,null,2)+`
14
+ `}import J from"chalk";function yB(q,Y){let{from:Q,output:Z}=Y;switch(Q){case"rulesync":{console.log(J.dim("Importing from .rulesync/ ..."));let B=Cq(q,Z);if(B.warnings.length>0){for(let U of B.warnings)console.log(J.yellow(` warn: ${U}`));return}if(console.log(J.green(`Imported ${B.filesImported.length} file(s) to ${B.packDir}`)),B.configGenerated)console.log(J.green("Generated agentpacks.jsonc from rulesync.jsonc"));console.log(J.cyan(`
15
+ Next steps:`),`
16
+ 1. Review the imported pack at`,J.bold(B.packDir),`
17
+ 2. Run`,J.bold("agentpacks generate"),"to generate tool configs");break}case"cursor":{console.log(J.dim("Importing from .cursor/ ..."));let B=Jq(q,Z);Bq(B,"Cursor");break}case"claude":case"claudecode":case"claude-code":{console.log(J.dim("Importing from Claude Code..."));let B=Tq(q,Z);Bq(B,"Claude Code");break}case"opencode":{console.log(J.dim("Importing from .opencode/ ..."));let B=_q(q,Z);Bq(B,"OpenCode");break}default:console.log(J.red(`Unknown import source: "${Q}"`)),console.log(J.dim("Supported sources: rulesync, cursor, claude-code, opencode"));break}}function Bq(q,Y){if(q.warnings.length>0&&q.filesImported.length===0){for(let Q of q.warnings)console.log(J.yellow(` warn: ${Q}`));return}for(let Q of q.warnings)console.log(J.yellow(` warn: ${Q}`));console.log(J.green(`Imported ${q.filesImported.length} file(s) from ${Y} to ${q.packDir}`)),console.log(J.cyan(`
18
+ Next steps:`),`
19
+ 1. Review the imported pack at`,J.bold(q.packDir),`
20
+ 2. Run`,J.bold("agentpacks generate"),"to generate tool configs")}export{yB as runImport};