agentpacks 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +32 -0
- package/dist/api.js +2852 -0
- package/dist/cli/export-cmd.d.ts +12 -0
- package/dist/cli/export-cmd.js +786 -0
- package/dist/cli/generate.d.ts +13 -0
- package/dist/cli/generate.js +2018 -0
- package/dist/cli/import-cmd.d.ts +9 -0
- package/dist/cli/import-cmd.js +691 -0
- package/dist/cli/init.d.ts +5 -0
- package/dist/cli/init.js +214 -0
- package/dist/cli/install.d.ts +11 -0
- package/dist/cli/install.js +610 -0
- package/dist/cli/pack/create.d.ts +4 -0
- package/dist/cli/pack/create.js +175 -0
- package/dist/cli/pack/enable.d.ts +8 -0
- package/dist/cli/pack/enable.js +96 -0
- package/dist/cli/pack/list.d.ts +4 -0
- package/dist/cli/pack/list.js +699 -0
- package/dist/cli/pack/validate.d.ts +4 -0
- package/dist/cli/pack/validate.js +364 -0
- package/dist/core/config.d.ts +77 -0
- package/dist/core/config.js +181 -0
- package/dist/core/dependency-resolver.d.ts +38 -0
- package/dist/core/dependency-resolver.js +151 -0
- package/dist/core/feature-merger.d.ts +61 -0
- package/dist/core/feature-merger.js +139 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +924 -0
- package/dist/core/lockfile.d.ts +50 -0
- package/dist/core/lockfile.js +72 -0
- package/dist/core/metarepo.d.ts +26 -0
- package/dist/core/metarepo.js +218 -0
- package/dist/core/pack-loader.d.ts +61 -0
- package/dist/core/pack-loader.js +646 -0
- package/dist/exporters/cursor-plugin.d.ts +29 -0
- package/dist/exporters/cursor-plugin.js +258 -0
- package/dist/exporters/index.d.ts +1 -0
- package/dist/exporters/index.js +258 -0
- package/dist/features/agents.d.ts +48 -0
- package/dist/features/agents.js +190 -0
- package/dist/features/commands.d.ts +33 -0
- package/dist/features/commands.js +190 -0
- package/dist/features/hooks.d.ts +33 -0
- package/dist/features/hooks.js +182 -0
- package/dist/features/ignore.d.ts +21 -0
- package/dist/features/ignore.js +72 -0
- package/dist/features/index.d.ts +8 -0
- package/dist/features/index.js +426 -0
- package/dist/features/mcp.d.ts +34 -0
- package/dist/features/mcp.js +172 -0
- package/dist/features/plugins.d.ts +23 -0
- package/dist/features/plugins.js +168 -0
- package/dist/features/rules.d.ts +53 -0
- package/dist/features/rules.js +198 -0
- package/dist/features/skills.d.ts +42 -0
- package/dist/features/skills.js +198 -0
- package/dist/importers/claude-code.d.ts +5 -0
- package/dist/importers/claude-code.js +224 -0
- package/dist/importers/cursor.d.ts +5 -0
- package/dist/importers/cursor.js +288 -0
- package/dist/importers/opencode.d.ts +5 -0
- package/dist/importers/opencode.js +261 -0
- package/dist/importers/rulesync.d.ts +14 -0
- package/dist/importers/rulesync.js +280 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3464 -0
- package/dist/node/api.js +2852 -0
- package/dist/node/cli/export-cmd.js +786 -0
- package/dist/node/cli/generate.js +2018 -0
- package/dist/node/cli/import-cmd.js +691 -0
- package/dist/node/cli/init.js +214 -0
- package/dist/node/cli/install.js +610 -0
- package/dist/node/cli/pack/create.js +175 -0
- package/dist/node/cli/pack/enable.js +96 -0
- package/dist/node/cli/pack/list.js +699 -0
- package/dist/node/cli/pack/validate.js +364 -0
- package/dist/node/core/config.js +181 -0
- package/dist/node/core/dependency-resolver.js +151 -0
- package/dist/node/core/feature-merger.js +139 -0
- package/dist/node/core/index.js +924 -0
- package/dist/node/core/lockfile.js +72 -0
- package/dist/node/core/metarepo.js +218 -0
- package/dist/node/core/pack-loader.js +646 -0
- package/dist/node/exporters/cursor-plugin.js +258 -0
- package/dist/node/exporters/index.js +258 -0
- package/dist/node/features/agents.js +190 -0
- package/dist/node/features/commands.js +190 -0
- package/dist/node/features/hooks.js +182 -0
- package/dist/node/features/ignore.js +72 -0
- package/dist/node/features/index.js +426 -0
- package/dist/node/features/mcp.js +172 -0
- package/dist/node/features/plugins.js +168 -0
- package/dist/node/features/rules.js +198 -0
- package/dist/node/features/skills.js +198 -0
- package/dist/node/importers/claude-code.js +224 -0
- package/dist/node/importers/cursor.js +288 -0
- package/dist/node/importers/opencode.js +261 -0
- package/dist/node/importers/rulesync.js +280 -0
- package/dist/node/index.js +3464 -0
- package/dist/node/sources/git-ref.js +79 -0
- package/dist/node/sources/git.js +245 -0
- package/dist/node/sources/index.js +416 -0
- package/dist/node/sources/local.js +52 -0
- package/dist/node/sources/npm-ref.js +84 -0
- package/dist/node/sources/npm.js +211 -0
- package/dist/node/targets/additional-targets.js +428 -0
- package/dist/node/targets/agents-md.js +239 -0
- package/dist/node/targets/base-target.js +51 -0
- package/dist/node/targets/claude-code.js +490 -0
- package/dist/node/targets/codex-cli.js +297 -0
- package/dist/node/targets/copilot.js +390 -0
- package/dist/node/targets/cursor.js +441 -0
- package/dist/node/targets/gemini-cli.js +352 -0
- package/dist/node/targets/generic-md-target.js +319 -0
- package/dist/node/targets/index.js +1351 -0
- package/dist/node/targets/opencode.js +556 -0
- package/dist/node/targets/registry.js +1343 -0
- package/dist/node/utils/diff.js +144 -0
- package/dist/node/utils/filesystem.js +152 -0
- package/dist/node/utils/frontmatter.js +52 -0
- package/dist/node/utils/global.js +81 -0
- package/dist/node/utils/markdown.js +62 -0
- package/dist/sources/git-ref.d.ts +27 -0
- package/dist/sources/git-ref.js +79 -0
- package/dist/sources/git.d.ts +29 -0
- package/dist/sources/git.js +245 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.js +416 -0
- package/dist/sources/local.d.ts +8 -0
- package/dist/sources/local.js +52 -0
- package/dist/sources/npm-ref.d.ts +30 -0
- package/dist/sources/npm-ref.js +84 -0
- package/dist/sources/npm.d.ts +20 -0
- package/dist/sources/npm.js +211 -0
- package/dist/targets/additional-targets.d.ts +65 -0
- package/dist/targets/additional-targets.js +428 -0
- package/dist/targets/agents-md.d.ts +13 -0
- package/dist/targets/agents-md.js +239 -0
- package/dist/targets/base-target.d.ts +61 -0
- package/dist/targets/base-target.js +51 -0
- package/dist/targets/claude-code.d.ts +13 -0
- package/dist/targets/claude-code.js +490 -0
- package/dist/targets/codex-cli.d.ts +12 -0
- package/dist/targets/codex-cli.js +297 -0
- package/dist/targets/copilot.d.ts +12 -0
- package/dist/targets/copilot.js +390 -0
- package/dist/targets/cursor.d.ts +13 -0
- package/dist/targets/cursor.js +441 -0
- package/dist/targets/gemini-cli.d.ts +12 -0
- package/dist/targets/gemini-cli.js +352 -0
- package/dist/targets/generic-md-target.d.ts +25 -0
- package/dist/targets/generic-md-target.js +319 -0
- package/dist/targets/index.d.ts +9 -0
- package/dist/targets/index.js +1351 -0
- package/dist/targets/opencode.d.ts +13 -0
- package/dist/targets/opencode.js +556 -0
- package/dist/targets/registry.d.ts +17 -0
- package/dist/targets/registry.js +1343 -0
- package/dist/utils/diff.d.ts +13 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/filesystem.d.ts +49 -0
- package/dist/utils/filesystem.js +152 -0
- package/dist/utils/frontmatter.d.ts +19 -0
- package/dist/utils/frontmatter.js +52 -0
- package/dist/utils/global.d.ts +17 -0
- package/dist/utils/global.js +81 -0
- package/dist/utils/markdown.d.ts +20 -0
- package/dist/utils/markdown.js +62 -0
- package/package.json +808 -0
- package/templates/pack/pack.json +10 -0
- package/templates/pack/rules/overview.md +22 -0
- package/templates/workspace/agentpacks.jsonc +34 -0
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
30
|
+
var __require = import.meta.require;
|
|
31
|
+
|
|
32
|
+
// src/utils/filesystem.ts
|
|
33
|
+
import {
|
|
34
|
+
existsSync,
|
|
35
|
+
mkdirSync,
|
|
36
|
+
readFileSync,
|
|
37
|
+
writeFileSync,
|
|
38
|
+
readdirSync,
|
|
39
|
+
statSync
|
|
40
|
+
} from "fs";
|
|
41
|
+
import { dirname, relative, join } from "path";
|
|
42
|
+
import { removeSync } from "fs-extra";
|
|
43
|
+
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
44
|
+
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
45
|
+
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
46
|
+
function writeGeneratedFile(filepath, content, options = {}) {
|
|
47
|
+
const { header = true, type } = options;
|
|
48
|
+
const ext = type ?? inferFileType(filepath);
|
|
49
|
+
ensureDir(dirname(filepath));
|
|
50
|
+
let output = content;
|
|
51
|
+
if (header) {
|
|
52
|
+
const headerComment = getHeader(ext);
|
|
53
|
+
if (headerComment) {
|
|
54
|
+
output = `${headerComment}
|
|
55
|
+
${content}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
writeFileSync(filepath, output, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
function writeGeneratedJson(filepath, data, options = {}) {
|
|
61
|
+
const json = JSON.stringify(data, null, 2);
|
|
62
|
+
writeGeneratedFile(filepath, json + `
|
|
63
|
+
`, { ...options, type: "json" });
|
|
64
|
+
}
|
|
65
|
+
function readFileOrNull(filepath) {
|
|
66
|
+
if (!existsSync(filepath))
|
|
67
|
+
return null;
|
|
68
|
+
return readFileSync(filepath, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
function readJsonOrNull(filepath) {
|
|
71
|
+
const content = readFileOrNull(filepath);
|
|
72
|
+
if (content === null)
|
|
73
|
+
return null;
|
|
74
|
+
return JSON.parse(content);
|
|
75
|
+
}
|
|
76
|
+
function ensureDir(dirPath) {
|
|
77
|
+
if (!existsSync(dirPath)) {
|
|
78
|
+
mkdirSync(dirPath, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function removeIfExists(targetPath) {
|
|
82
|
+
if (existsSync(targetPath)) {
|
|
83
|
+
removeSync(targetPath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function listFiles(dirPath, options = {}) {
|
|
87
|
+
const { extension, recursive = false } = options;
|
|
88
|
+
if (!existsSync(dirPath))
|
|
89
|
+
return [];
|
|
90
|
+
const results = [];
|
|
91
|
+
const entries = readdirSync(dirPath);
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const fullPath = join(dirPath, entry);
|
|
94
|
+
const stat = statSync(fullPath);
|
|
95
|
+
if (stat.isDirectory() && recursive) {
|
|
96
|
+
results.push(...listFiles(fullPath, options));
|
|
97
|
+
} else if (stat.isFile()) {
|
|
98
|
+
if (!extension || entry.endsWith(extension)) {
|
|
99
|
+
results.push(fullPath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
function listDirs(dirPath) {
|
|
106
|
+
if (!existsSync(dirPath))
|
|
107
|
+
return [];
|
|
108
|
+
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
109
|
+
}
|
|
110
|
+
function relPath(projectRoot, filepath) {
|
|
111
|
+
return relative(projectRoot, filepath);
|
|
112
|
+
}
|
|
113
|
+
function isGeneratedFile(filepath) {
|
|
114
|
+
const content = readFileOrNull(filepath);
|
|
115
|
+
if (!content)
|
|
116
|
+
return false;
|
|
117
|
+
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
118
|
+
}
|
|
119
|
+
function inferFileType(filepath) {
|
|
120
|
+
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
121
|
+
return "json";
|
|
122
|
+
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
123
|
+
return "ts";
|
|
124
|
+
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
125
|
+
return "js";
|
|
126
|
+
return "md";
|
|
127
|
+
}
|
|
128
|
+
function getHeader(type) {
|
|
129
|
+
switch (type) {
|
|
130
|
+
case "md":
|
|
131
|
+
return GENERATED_HEADER_MD;
|
|
132
|
+
case "json":
|
|
133
|
+
return GENERATED_HEADER_JSON;
|
|
134
|
+
case "js":
|
|
135
|
+
case "ts":
|
|
136
|
+
return GENERATED_HEADER_JS;
|
|
137
|
+
default:
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/frontmatter.ts
|
|
143
|
+
import matter from "gray-matter";
|
|
144
|
+
function parseFrontmatter(source) {
|
|
145
|
+
const { data, content } = matter(source);
|
|
146
|
+
return {
|
|
147
|
+
data,
|
|
148
|
+
content: content.trim(),
|
|
149
|
+
raw: source
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function serializeFrontmatter(data, content) {
|
|
153
|
+
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
154
|
+
if (Object.keys(filtered).length === 0) {
|
|
155
|
+
return content;
|
|
156
|
+
}
|
|
157
|
+
return matter.stringify(content, filtered);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/importers/rulesync.ts
|
|
161
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, copyFileSync, writeFileSync as writeFileSync2 } from "fs";
|
|
162
|
+
import { resolve as resolve2, join as join2, basename } from "path";
|
|
163
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
164
|
+
function importFromRulesync(projectRoot, outputPackDir) {
|
|
165
|
+
const rulesyncDir = resolve2(projectRoot, ".rulesync");
|
|
166
|
+
const warnings = [];
|
|
167
|
+
const filesImported = [];
|
|
168
|
+
if (!existsSync2(rulesyncDir)) {
|
|
169
|
+
return {
|
|
170
|
+
packDir: "",
|
|
171
|
+
filesImported: [],
|
|
172
|
+
warnings: ["No .rulesync/ directory found."],
|
|
173
|
+
configGenerated: false
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const packDir = outputPackDir ?? resolve2(projectRoot, "packs", "default");
|
|
177
|
+
ensureDir(packDir);
|
|
178
|
+
const rulesDir = resolve2(rulesyncDir, "rules");
|
|
179
|
+
if (existsSync2(rulesDir)) {
|
|
180
|
+
const outRulesDir = resolve2(packDir, "rules");
|
|
181
|
+
ensureDir(outRulesDir);
|
|
182
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
183
|
+
for (const file of files) {
|
|
184
|
+
const dest = join2(outRulesDir, basename(file));
|
|
185
|
+
copyFileSync(file, dest);
|
|
186
|
+
filesImported.push(dest);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const commandsDir = resolve2(rulesyncDir, "commands");
|
|
190
|
+
if (existsSync2(commandsDir)) {
|
|
191
|
+
const outCommandsDir = resolve2(packDir, "commands");
|
|
192
|
+
ensureDir(outCommandsDir);
|
|
193
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
194
|
+
for (const file of files) {
|
|
195
|
+
const dest = join2(outCommandsDir, basename(file));
|
|
196
|
+
copyFileSync(file, dest);
|
|
197
|
+
filesImported.push(dest);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const subagentsDir = resolve2(rulesyncDir, "subagents");
|
|
201
|
+
if (existsSync2(subagentsDir)) {
|
|
202
|
+
const outAgentsDir = resolve2(packDir, "agents");
|
|
203
|
+
ensureDir(outAgentsDir);
|
|
204
|
+
const files = listFiles(subagentsDir, { extension: ".md" });
|
|
205
|
+
for (const file of files) {
|
|
206
|
+
const dest = join2(outAgentsDir, basename(file));
|
|
207
|
+
copyFileSync(file, dest);
|
|
208
|
+
filesImported.push(dest);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const skillsDir = resolve2(rulesyncDir, "skills");
|
|
212
|
+
if (existsSync2(skillsDir)) {
|
|
213
|
+
const outSkillsDir = resolve2(packDir, "skills");
|
|
214
|
+
ensureDir(outSkillsDir);
|
|
215
|
+
const skillDirs = listDirs(skillsDir);
|
|
216
|
+
for (const skillDir of skillDirs) {
|
|
217
|
+
const skillName = basename(skillDir);
|
|
218
|
+
if (skillName.startsWith("."))
|
|
219
|
+
continue;
|
|
220
|
+
const skillMd = join2(skillDir, "SKILL.md");
|
|
221
|
+
if (existsSync2(skillMd)) {
|
|
222
|
+
const outSkillDir = join2(outSkillsDir, skillName);
|
|
223
|
+
ensureDir(outSkillDir);
|
|
224
|
+
copyFileSync(skillMd, join2(outSkillDir, "SKILL.md"));
|
|
225
|
+
filesImported.push(join2(outSkillDir, "SKILL.md"));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const hooksJson = resolve2(rulesyncDir, "hooks.json");
|
|
230
|
+
if (existsSync2(hooksJson)) {
|
|
231
|
+
const outHooksDir = resolve2(packDir, "hooks");
|
|
232
|
+
ensureDir(outHooksDir);
|
|
233
|
+
copyFileSync(hooksJson, join2(outHooksDir, "hooks.json"));
|
|
234
|
+
filesImported.push(join2(outHooksDir, "hooks.json"));
|
|
235
|
+
}
|
|
236
|
+
const mcpJson = resolve2(rulesyncDir, "mcp.json");
|
|
237
|
+
if (existsSync2(mcpJson)) {
|
|
238
|
+
copyFileSync(mcpJson, join2(packDir, "mcp.json"));
|
|
239
|
+
filesImported.push(join2(packDir, "mcp.json"));
|
|
240
|
+
}
|
|
241
|
+
const aiIgnore = resolve2(rulesyncDir, ".aiignore");
|
|
242
|
+
const rulesyncIgnore = resolve2(projectRoot, ".rulesyncignore");
|
|
243
|
+
if (existsSync2(aiIgnore)) {
|
|
244
|
+
copyFileSync(aiIgnore, join2(packDir, "ignore"));
|
|
245
|
+
filesImported.push(join2(packDir, "ignore"));
|
|
246
|
+
} else if (existsSync2(rulesyncIgnore)) {
|
|
247
|
+
copyFileSync(rulesyncIgnore, join2(packDir, "ignore"));
|
|
248
|
+
filesImported.push(join2(packDir, "ignore"));
|
|
249
|
+
}
|
|
250
|
+
const packJson = {
|
|
251
|
+
name: "default",
|
|
252
|
+
version: "1.0.0",
|
|
253
|
+
description: "Imported from rulesync",
|
|
254
|
+
tags: ["imported", "rulesync"],
|
|
255
|
+
dependencies: [],
|
|
256
|
+
conflicts: [],
|
|
257
|
+
targets: "*",
|
|
258
|
+
features: "*"
|
|
259
|
+
};
|
|
260
|
+
writeFileSync2(join2(packDir, "pack.json"), JSON.stringify(packJson, null, 2) + `
|
|
261
|
+
`);
|
|
262
|
+
filesImported.push(join2(packDir, "pack.json"));
|
|
263
|
+
let configGenerated = false;
|
|
264
|
+
const rulesyncConfig = resolve2(projectRoot, "rulesync.jsonc");
|
|
265
|
+
if (existsSync2(rulesyncConfig)) {
|
|
266
|
+
const agentpacksConfig = convertRulesyncConfig(rulesyncConfig, packDir, projectRoot);
|
|
267
|
+
const configPath = resolve2(projectRoot, "agentpacks.jsonc");
|
|
268
|
+
writeFileSync2(configPath, agentpacksConfig);
|
|
269
|
+
configGenerated = true;
|
|
270
|
+
}
|
|
271
|
+
return { packDir, filesImported, warnings, configGenerated };
|
|
272
|
+
}
|
|
273
|
+
function convertRulesyncConfig(rulesyncPath, packDir, projectRoot) {
|
|
274
|
+
const raw = readFileSync2(rulesyncPath, "utf-8");
|
|
275
|
+
const parsed = parseJsonc(raw);
|
|
276
|
+
const targets = parsed.targets ?? ["opencode", "cursor", "claudecode"];
|
|
277
|
+
const features = parsed.features ?? ["*"];
|
|
278
|
+
const baseDirs = parsed.baseDirs ?? ["."];
|
|
279
|
+
const global = parsed.global ?? false;
|
|
280
|
+
const deleteVal = parsed.delete ?? true;
|
|
281
|
+
const relPackDir = "./" + join2("packs", "default");
|
|
282
|
+
const config = {
|
|
283
|
+
$schema: "https://unpkg.com/agentpacks/schema.json",
|
|
284
|
+
packs: [relPackDir],
|
|
285
|
+
disabled: [],
|
|
286
|
+
targets,
|
|
287
|
+
features,
|
|
288
|
+
mode: baseDirs.length > 1 ? "monorepo" : "repo",
|
|
289
|
+
baseDirs,
|
|
290
|
+
global,
|
|
291
|
+
delete: deleteVal
|
|
292
|
+
};
|
|
293
|
+
return JSON.stringify(config, null, 2) + `
|
|
294
|
+
`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/importers/cursor.ts
|
|
298
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3, copyFileSync as copyFileSync2 } from "fs";
|
|
299
|
+
import { resolve as resolve3, join as join3, basename as basename2 } from "path";
|
|
300
|
+
function importFromCursor(projectRoot, outputPackDir) {
|
|
301
|
+
const cursorDir = resolve3(projectRoot, ".cursor");
|
|
302
|
+
const warnings = [];
|
|
303
|
+
const filesImported = [];
|
|
304
|
+
if (!existsSync3(cursorDir)) {
|
|
305
|
+
return {
|
|
306
|
+
packDir: "",
|
|
307
|
+
filesImported: [],
|
|
308
|
+
warnings: ["No .cursor/ directory found."],
|
|
309
|
+
configGenerated: false
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
const packDir = outputPackDir ?? resolve3(projectRoot, "packs", "cursor-import");
|
|
313
|
+
ensureDir(packDir);
|
|
314
|
+
const rulesDir = resolve3(cursorDir, "rules");
|
|
315
|
+
if (existsSync3(rulesDir)) {
|
|
316
|
+
const outRulesDir = resolve3(packDir, "rules");
|
|
317
|
+
ensureDir(outRulesDir);
|
|
318
|
+
const files = listFiles(rulesDir, { extension: ".mdc" });
|
|
319
|
+
for (const file of files) {
|
|
320
|
+
const raw = readFileSync3(file, "utf-8");
|
|
321
|
+
const { data, content } = parseFrontmatter(raw);
|
|
322
|
+
const meta = {};
|
|
323
|
+
if (data.description)
|
|
324
|
+
meta.description = data.description;
|
|
325
|
+
if (data.alwaysApply)
|
|
326
|
+
meta.root = true;
|
|
327
|
+
if (data.globs)
|
|
328
|
+
meta.globs = data.globs;
|
|
329
|
+
meta.cursor = { ...data };
|
|
330
|
+
const mdContent = buildAgentpacksRule(meta, content);
|
|
331
|
+
const name = basename2(file, ".mdc");
|
|
332
|
+
const dest = join3(outRulesDir, `${name}.md`);
|
|
333
|
+
writeFileSync3(dest, mdContent);
|
|
334
|
+
filesImported.push(dest);
|
|
335
|
+
}
|
|
336
|
+
const mdFiles = listFiles(rulesDir, { extension: ".md" });
|
|
337
|
+
for (const file of mdFiles) {
|
|
338
|
+
const dest = join3(outRulesDir, basename2(file));
|
|
339
|
+
copyFileSync2(file, dest);
|
|
340
|
+
filesImported.push(dest);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const agentsDir = resolve3(cursorDir, "agents");
|
|
344
|
+
if (existsSync3(agentsDir)) {
|
|
345
|
+
const outDir = resolve3(packDir, "agents");
|
|
346
|
+
ensureDir(outDir);
|
|
347
|
+
const files = listFiles(agentsDir, { extension: ".md" });
|
|
348
|
+
for (const file of files) {
|
|
349
|
+
const dest = join3(outDir, basename2(file));
|
|
350
|
+
copyFileSync2(file, dest);
|
|
351
|
+
filesImported.push(dest);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const skillsDir = resolve3(cursorDir, "skills");
|
|
355
|
+
if (existsSync3(skillsDir)) {
|
|
356
|
+
const outDir = resolve3(packDir, "skills");
|
|
357
|
+
ensureDir(outDir);
|
|
358
|
+
const dirs = listDirs(skillsDir);
|
|
359
|
+
for (const dir of dirs) {
|
|
360
|
+
const name = basename2(dir);
|
|
361
|
+
const skillMd = join3(dir, "SKILL.md");
|
|
362
|
+
if (existsSync3(skillMd)) {
|
|
363
|
+
const outSkillDir = join3(outDir, name);
|
|
364
|
+
ensureDir(outSkillDir);
|
|
365
|
+
copyFileSync2(skillMd, join3(outSkillDir, "SKILL.md"));
|
|
366
|
+
filesImported.push(join3(outSkillDir, "SKILL.md"));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const commandsDir = resolve3(cursorDir, "commands");
|
|
371
|
+
if (existsSync3(commandsDir)) {
|
|
372
|
+
const outDir = resolve3(packDir, "commands");
|
|
373
|
+
ensureDir(outDir);
|
|
374
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
375
|
+
for (const file of files) {
|
|
376
|
+
const dest = join3(outDir, basename2(file));
|
|
377
|
+
copyFileSync2(file, dest);
|
|
378
|
+
filesImported.push(dest);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const mcpJson = resolve3(cursorDir, "mcp.json");
|
|
382
|
+
if (existsSync3(mcpJson)) {
|
|
383
|
+
copyFileSync2(mcpJson, join3(packDir, "mcp.json"));
|
|
384
|
+
filesImported.push(join3(packDir, "mcp.json"));
|
|
385
|
+
}
|
|
386
|
+
const cursorIgnore = resolve3(projectRoot, ".cursorignore");
|
|
387
|
+
if (existsSync3(cursorIgnore)) {
|
|
388
|
+
copyFileSync2(cursorIgnore, join3(packDir, "ignore"));
|
|
389
|
+
filesImported.push(join3(packDir, "ignore"));
|
|
390
|
+
}
|
|
391
|
+
writePackJson(packDir, "cursor-import", filesImported);
|
|
392
|
+
return { packDir, filesImported, warnings, configGenerated: false };
|
|
393
|
+
}
|
|
394
|
+
function buildAgentpacksRule(meta, content) {
|
|
395
|
+
const lines = ["---"];
|
|
396
|
+
for (const [k, v] of Object.entries(meta)) {
|
|
397
|
+
if (typeof v === "object") {
|
|
398
|
+
lines.push(`${k}: ${JSON.stringify(v)}`);
|
|
399
|
+
} else {
|
|
400
|
+
lines.push(`${k}: ${v}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
lines.push("---", "", content);
|
|
404
|
+
return lines.join(`
|
|
405
|
+
`);
|
|
406
|
+
}
|
|
407
|
+
function writePackJson(packDir, name, filesImported) {
|
|
408
|
+
const packJson = {
|
|
409
|
+
name,
|
|
410
|
+
version: "1.0.0",
|
|
411
|
+
description: `Imported from Cursor`,
|
|
412
|
+
tags: ["imported", "cursor"],
|
|
413
|
+
dependencies: [],
|
|
414
|
+
conflicts: [],
|
|
415
|
+
targets: "*",
|
|
416
|
+
features: "*"
|
|
417
|
+
};
|
|
418
|
+
const dest = join3(packDir, "pack.json");
|
|
419
|
+
writeFileSync3(dest, JSON.stringify(packJson, null, 2) + `
|
|
420
|
+
`);
|
|
421
|
+
filesImported.push(dest);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/importers/claude-code.ts
|
|
425
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4, copyFileSync as copyFileSync3 } from "fs";
|
|
426
|
+
import { resolve as resolve4, join as join4, basename as basename3 } from "path";
|
|
427
|
+
function importFromClaudeCode(projectRoot, outputPackDir) {
|
|
428
|
+
const warnings = [];
|
|
429
|
+
const filesImported = [];
|
|
430
|
+
const claudeDir = resolve4(projectRoot, ".claude");
|
|
431
|
+
const hasClaudeMd = existsSync4(resolve4(projectRoot, "CLAUDE.md"));
|
|
432
|
+
const hasClaudeDir = existsSync4(claudeDir);
|
|
433
|
+
if (!hasClaudeMd && !hasClaudeDir) {
|
|
434
|
+
return {
|
|
435
|
+
packDir: "",
|
|
436
|
+
filesImported: [],
|
|
437
|
+
warnings: ["No CLAUDE.md or .claude/ directory found."],
|
|
438
|
+
configGenerated: false
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const packDir = outputPackDir ?? resolve4(projectRoot, "packs", "claude-import");
|
|
442
|
+
ensureDir(packDir);
|
|
443
|
+
const rulesDir = resolve4(packDir, "rules");
|
|
444
|
+
ensureDir(rulesDir);
|
|
445
|
+
if (hasClaudeMd) {
|
|
446
|
+
const raw = readFileSync4(resolve4(projectRoot, "CLAUDE.md"), "utf-8");
|
|
447
|
+
const ruleContent = [
|
|
448
|
+
"---",
|
|
449
|
+
"root: true",
|
|
450
|
+
'description: "Root Claude Code rules"',
|
|
451
|
+
"---",
|
|
452
|
+
"",
|
|
453
|
+
raw
|
|
454
|
+
].join(`
|
|
455
|
+
`);
|
|
456
|
+
const dest = join4(rulesDir, "claude-root.md");
|
|
457
|
+
writeFileSync4(dest, ruleContent);
|
|
458
|
+
filesImported.push(dest);
|
|
459
|
+
}
|
|
460
|
+
if (hasClaudeDir) {
|
|
461
|
+
const claudeRulesDir = resolve4(claudeDir, "rules");
|
|
462
|
+
if (existsSync4(claudeRulesDir)) {
|
|
463
|
+
const files = listFiles(claudeRulesDir, { extension: ".md" });
|
|
464
|
+
for (const file of files) {
|
|
465
|
+
const dest = join4(rulesDir, basename3(file));
|
|
466
|
+
copyFileSync3(file, dest);
|
|
467
|
+
filesImported.push(dest);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const settingsPath = resolve4(claudeDir, "settings.json");
|
|
471
|
+
if (existsSync4(settingsPath)) {
|
|
472
|
+
try {
|
|
473
|
+
const raw = readFileSync4(settingsPath, "utf-8");
|
|
474
|
+
const settings = JSON.parse(raw);
|
|
475
|
+
const mcpServers = settings.mcpServers ?? settings.mcp_servers;
|
|
476
|
+
if (mcpServers && typeof mcpServers === "object") {
|
|
477
|
+
const mcpConfig = { servers: mcpServers };
|
|
478
|
+
const dest = join4(packDir, "mcp.json");
|
|
479
|
+
writeFileSync4(dest, JSON.stringify(mcpConfig, null, 2) + `
|
|
480
|
+
`);
|
|
481
|
+
filesImported.push(dest);
|
|
482
|
+
}
|
|
483
|
+
} catch {
|
|
484
|
+
warnings.push("Failed to parse .claude/settings.json");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const packJson = {
|
|
489
|
+
name: "claude-import",
|
|
490
|
+
version: "1.0.0",
|
|
491
|
+
description: "Imported from Claude Code",
|
|
492
|
+
tags: ["imported", "claude-code"],
|
|
493
|
+
dependencies: [],
|
|
494
|
+
conflicts: [],
|
|
495
|
+
targets: "*",
|
|
496
|
+
features: "*"
|
|
497
|
+
};
|
|
498
|
+
const packJsonPath = join4(packDir, "pack.json");
|
|
499
|
+
writeFileSync4(packJsonPath, JSON.stringify(packJson, null, 2) + `
|
|
500
|
+
`);
|
|
501
|
+
filesImported.push(packJsonPath);
|
|
502
|
+
return { packDir, filesImported, warnings, configGenerated: false };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/importers/opencode.ts
|
|
506
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync5, copyFileSync as copyFileSync4 } from "fs";
|
|
507
|
+
import { resolve as resolve5, join as join5, basename as basename4 } from "path";
|
|
508
|
+
function importFromOpenCode(projectRoot, outputPackDir) {
|
|
509
|
+
const warnings = [];
|
|
510
|
+
const filesImported = [];
|
|
511
|
+
const ocDir = resolve5(projectRoot, ".opencode");
|
|
512
|
+
if (!existsSync5(ocDir)) {
|
|
513
|
+
return {
|
|
514
|
+
packDir: "",
|
|
515
|
+
filesImported: [],
|
|
516
|
+
warnings: ["No .opencode/ directory found."],
|
|
517
|
+
configGenerated: false
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
const packDir = outputPackDir ?? resolve5(projectRoot, "packs", "opencode-import");
|
|
521
|
+
ensureDir(packDir);
|
|
522
|
+
importDirMd(resolve5(ocDir, "rules"), resolve5(packDir, "rules"), filesImported);
|
|
523
|
+
importDirMd(resolve5(ocDir, "commands"), resolve5(packDir, "commands"), filesImported);
|
|
524
|
+
importDirMd(resolve5(ocDir, "agents"), resolve5(packDir, "agents"), filesImported);
|
|
525
|
+
const skillDir = resolve5(ocDir, "skill");
|
|
526
|
+
if (existsSync5(skillDir)) {
|
|
527
|
+
const outSkillDir = resolve5(packDir, "skills");
|
|
528
|
+
ensureDir(outSkillDir);
|
|
529
|
+
const dirs = listDirs(skillDir);
|
|
530
|
+
for (const dir of dirs) {
|
|
531
|
+
const name = basename4(dir);
|
|
532
|
+
if (name.startsWith("."))
|
|
533
|
+
continue;
|
|
534
|
+
const skillMd = join5(dir, "SKILL.md");
|
|
535
|
+
if (existsSync5(skillMd)) {
|
|
536
|
+
const outDir = join5(outSkillDir, name);
|
|
537
|
+
ensureDir(outDir);
|
|
538
|
+
copyFileSync4(skillMd, join5(outDir, "SKILL.md"));
|
|
539
|
+
filesImported.push(join5(outDir, "SKILL.md"));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const pluginsDir = resolve5(ocDir, "plugins");
|
|
544
|
+
if (existsSync5(pluginsDir)) {
|
|
545
|
+
const outPluginsDir = resolve5(packDir, "plugins");
|
|
546
|
+
ensureDir(outPluginsDir);
|
|
547
|
+
const files = listFiles(pluginsDir);
|
|
548
|
+
for (const file of files) {
|
|
549
|
+
if (file.endsWith(".ts") || file.endsWith(".js")) {
|
|
550
|
+
const dest2 = join5(outPluginsDir, basename4(file));
|
|
551
|
+
copyFileSync4(file, dest2);
|
|
552
|
+
filesImported.push(dest2);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const agentsMd = resolve5(projectRoot, "AGENTS.md");
|
|
557
|
+
if (existsSync5(agentsMd)) {
|
|
558
|
+
const outRulesDir = resolve5(packDir, "rules");
|
|
559
|
+
ensureDir(outRulesDir);
|
|
560
|
+
const raw = readFileSync5(agentsMd, "utf-8");
|
|
561
|
+
const ruleContent = [
|
|
562
|
+
"---",
|
|
563
|
+
"root: true",
|
|
564
|
+
'description: "AGENTS.md root rules"',
|
|
565
|
+
"---",
|
|
566
|
+
"",
|
|
567
|
+
raw
|
|
568
|
+
].join(`
|
|
569
|
+
`);
|
|
570
|
+
const dest2 = join5(outRulesDir, "agents-md-root.md");
|
|
571
|
+
writeFileSync5(dest2, ruleContent);
|
|
572
|
+
filesImported.push(dest2);
|
|
573
|
+
}
|
|
574
|
+
const ocJson = resolve5(projectRoot, "opencode.json");
|
|
575
|
+
if (existsSync5(ocJson)) {
|
|
576
|
+
try {
|
|
577
|
+
const raw = readFileSync5(ocJson, "utf-8");
|
|
578
|
+
const config = JSON.parse(raw);
|
|
579
|
+
const mcpObj = config.mcp;
|
|
580
|
+
if (mcpObj) {
|
|
581
|
+
const dest2 = join5(packDir, "mcp.json");
|
|
582
|
+
writeFileSync5(dest2, JSON.stringify({ servers: mcpObj }, null, 2) + `
|
|
583
|
+
`);
|
|
584
|
+
filesImported.push(dest2);
|
|
585
|
+
}
|
|
586
|
+
} catch {
|
|
587
|
+
warnings.push("Failed to parse opencode.json");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const ocIgnore = resolve5(projectRoot, ".opencodeignore");
|
|
591
|
+
if (existsSync5(ocIgnore)) {
|
|
592
|
+
copyFileSync4(ocIgnore, join5(packDir, "ignore"));
|
|
593
|
+
filesImported.push(join5(packDir, "ignore"));
|
|
594
|
+
}
|
|
595
|
+
const packJson = {
|
|
596
|
+
name: "opencode-import",
|
|
597
|
+
version: "1.0.0",
|
|
598
|
+
description: "Imported from OpenCode",
|
|
599
|
+
tags: ["imported", "opencode"],
|
|
600
|
+
dependencies: [],
|
|
601
|
+
conflicts: [],
|
|
602
|
+
targets: "*",
|
|
603
|
+
features: "*"
|
|
604
|
+
};
|
|
605
|
+
const dest = join5(packDir, "pack.json");
|
|
606
|
+
writeFileSync5(dest, JSON.stringify(packJson, null, 2) + `
|
|
607
|
+
`);
|
|
608
|
+
filesImported.push(dest);
|
|
609
|
+
return { packDir, filesImported, warnings, configGenerated: false };
|
|
610
|
+
}
|
|
611
|
+
function importDirMd(srcDir, outDir, filesImported) {
|
|
612
|
+
if (!existsSync5(srcDir))
|
|
613
|
+
return;
|
|
614
|
+
ensureDir(outDir);
|
|
615
|
+
const files = listFiles(srcDir, { extension: ".md" });
|
|
616
|
+
for (const file of files) {
|
|
617
|
+
const dest = join5(outDir, basename4(file));
|
|
618
|
+
copyFileSync4(file, dest);
|
|
619
|
+
filesImported.push(dest);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// src/cli/import-cmd.ts
|
|
624
|
+
import chalk from "chalk";
|
|
625
|
+
function runImport(projectRoot, options) {
|
|
626
|
+
const { from, output } = options;
|
|
627
|
+
switch (from) {
|
|
628
|
+
case "rulesync": {
|
|
629
|
+
console.log(chalk.dim("Importing from .rulesync/ ..."));
|
|
630
|
+
const result = importFromRulesync(projectRoot, output);
|
|
631
|
+
if (result.warnings.length > 0) {
|
|
632
|
+
for (const w of result.warnings) {
|
|
633
|
+
console.log(chalk.yellow(` warn: ${w}`));
|
|
634
|
+
}
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
console.log(chalk.green(`Imported ${result.filesImported.length} file(s) to ${result.packDir}`));
|
|
638
|
+
if (result.configGenerated) {
|
|
639
|
+
console.log(chalk.green("Generated agentpacks.jsonc from rulesync.jsonc"));
|
|
640
|
+
}
|
|
641
|
+
console.log(chalk.cyan(`
|
|
642
|
+
Next steps:`), `
|
|
643
|
+
1. Review the imported pack at`, chalk.bold(result.packDir), `
|
|
644
|
+
2. Run`, chalk.bold("agentpacks generate"), "to generate tool configs");
|
|
645
|
+
break;
|
|
646
|
+
}
|
|
647
|
+
case "cursor": {
|
|
648
|
+
console.log(chalk.dim("Importing from .cursor/ ..."));
|
|
649
|
+
const cursorResult = importFromCursor(projectRoot, output);
|
|
650
|
+
printImportResult(cursorResult, "Cursor");
|
|
651
|
+
break;
|
|
652
|
+
}
|
|
653
|
+
case "claude":
|
|
654
|
+
case "claudecode":
|
|
655
|
+
case "claude-code": {
|
|
656
|
+
console.log(chalk.dim("Importing from Claude Code..."));
|
|
657
|
+
const claudeResult = importFromClaudeCode(projectRoot, output);
|
|
658
|
+
printImportResult(claudeResult, "Claude Code");
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
case "opencode": {
|
|
662
|
+
console.log(chalk.dim("Importing from .opencode/ ..."));
|
|
663
|
+
const ocResult = importFromOpenCode(projectRoot, output);
|
|
664
|
+
printImportResult(ocResult, "OpenCode");
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
default:
|
|
668
|
+
console.log(chalk.red(`Unknown import source: "${from}"`));
|
|
669
|
+
console.log(chalk.dim("Supported sources: rulesync, cursor, claude-code, opencode"));
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
function printImportResult(result, sourceName) {
|
|
674
|
+
if (result.warnings.length > 0 && result.filesImported.length === 0) {
|
|
675
|
+
for (const w of result.warnings) {
|
|
676
|
+
console.log(chalk.yellow(` warn: ${w}`));
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
for (const w of result.warnings) {
|
|
681
|
+
console.log(chalk.yellow(` warn: ${w}`));
|
|
682
|
+
}
|
|
683
|
+
console.log(chalk.green(`Imported ${result.filesImported.length} file(s) from ${sourceName} to ${result.packDir}`));
|
|
684
|
+
console.log(chalk.cyan(`
|
|
685
|
+
Next steps:`), `
|
|
686
|
+
1. Review the imported pack at`, chalk.bold(result.packDir), `
|
|
687
|
+
2. Run`, chalk.bold("agentpacks generate"), "to generate tool configs");
|
|
688
|
+
}
|
|
689
|
+
export {
|
|
690
|
+
runImport
|
|
691
|
+
};
|