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,261 @@
|
|
|
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/importers/opencode.ts
|
|
143
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, copyFileSync } from "fs";
|
|
144
|
+
import { resolve as resolve2, join as join2, basename } from "path";
|
|
145
|
+
function importFromOpenCode(projectRoot, outputPackDir) {
|
|
146
|
+
const warnings = [];
|
|
147
|
+
const filesImported = [];
|
|
148
|
+
const ocDir = resolve2(projectRoot, ".opencode");
|
|
149
|
+
if (!existsSync2(ocDir)) {
|
|
150
|
+
return {
|
|
151
|
+
packDir: "",
|
|
152
|
+
filesImported: [],
|
|
153
|
+
warnings: ["No .opencode/ directory found."],
|
|
154
|
+
configGenerated: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const packDir = outputPackDir ?? resolve2(projectRoot, "packs", "opencode-import");
|
|
158
|
+
ensureDir(packDir);
|
|
159
|
+
importDirMd(resolve2(ocDir, "rules"), resolve2(packDir, "rules"), filesImported);
|
|
160
|
+
importDirMd(resolve2(ocDir, "commands"), resolve2(packDir, "commands"), filesImported);
|
|
161
|
+
importDirMd(resolve2(ocDir, "agents"), resolve2(packDir, "agents"), filesImported);
|
|
162
|
+
const skillDir = resolve2(ocDir, "skill");
|
|
163
|
+
if (existsSync2(skillDir)) {
|
|
164
|
+
const outSkillDir = resolve2(packDir, "skills");
|
|
165
|
+
ensureDir(outSkillDir);
|
|
166
|
+
const dirs = listDirs(skillDir);
|
|
167
|
+
for (const dir of dirs) {
|
|
168
|
+
const name = basename(dir);
|
|
169
|
+
if (name.startsWith("."))
|
|
170
|
+
continue;
|
|
171
|
+
const skillMd = join2(dir, "SKILL.md");
|
|
172
|
+
if (existsSync2(skillMd)) {
|
|
173
|
+
const outDir = join2(outSkillDir, name);
|
|
174
|
+
ensureDir(outDir);
|
|
175
|
+
copyFileSync(skillMd, join2(outDir, "SKILL.md"));
|
|
176
|
+
filesImported.push(join2(outDir, "SKILL.md"));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const pluginsDir = resolve2(ocDir, "plugins");
|
|
181
|
+
if (existsSync2(pluginsDir)) {
|
|
182
|
+
const outPluginsDir = resolve2(packDir, "plugins");
|
|
183
|
+
ensureDir(outPluginsDir);
|
|
184
|
+
const files = listFiles(pluginsDir);
|
|
185
|
+
for (const file of files) {
|
|
186
|
+
if (file.endsWith(".ts") || file.endsWith(".js")) {
|
|
187
|
+
const dest2 = join2(outPluginsDir, basename(file));
|
|
188
|
+
copyFileSync(file, dest2);
|
|
189
|
+
filesImported.push(dest2);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const agentsMd = resolve2(projectRoot, "AGENTS.md");
|
|
194
|
+
if (existsSync2(agentsMd)) {
|
|
195
|
+
const outRulesDir = resolve2(packDir, "rules");
|
|
196
|
+
ensureDir(outRulesDir);
|
|
197
|
+
const raw = readFileSync2(agentsMd, "utf-8");
|
|
198
|
+
const ruleContent = [
|
|
199
|
+
"---",
|
|
200
|
+
"root: true",
|
|
201
|
+
'description: "AGENTS.md root rules"',
|
|
202
|
+
"---",
|
|
203
|
+
"",
|
|
204
|
+
raw
|
|
205
|
+
].join(`
|
|
206
|
+
`);
|
|
207
|
+
const dest2 = join2(outRulesDir, "agents-md-root.md");
|
|
208
|
+
writeFileSync2(dest2, ruleContent);
|
|
209
|
+
filesImported.push(dest2);
|
|
210
|
+
}
|
|
211
|
+
const ocJson = resolve2(projectRoot, "opencode.json");
|
|
212
|
+
if (existsSync2(ocJson)) {
|
|
213
|
+
try {
|
|
214
|
+
const raw = readFileSync2(ocJson, "utf-8");
|
|
215
|
+
const config = JSON.parse(raw);
|
|
216
|
+
const mcpObj = config.mcp;
|
|
217
|
+
if (mcpObj) {
|
|
218
|
+
const dest2 = join2(packDir, "mcp.json");
|
|
219
|
+
writeFileSync2(dest2, JSON.stringify({ servers: mcpObj }, null, 2) + `
|
|
220
|
+
`);
|
|
221
|
+
filesImported.push(dest2);
|
|
222
|
+
}
|
|
223
|
+
} catch {
|
|
224
|
+
warnings.push("Failed to parse opencode.json");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const ocIgnore = resolve2(projectRoot, ".opencodeignore");
|
|
228
|
+
if (existsSync2(ocIgnore)) {
|
|
229
|
+
copyFileSync(ocIgnore, join2(packDir, "ignore"));
|
|
230
|
+
filesImported.push(join2(packDir, "ignore"));
|
|
231
|
+
}
|
|
232
|
+
const packJson = {
|
|
233
|
+
name: "opencode-import",
|
|
234
|
+
version: "1.0.0",
|
|
235
|
+
description: "Imported from OpenCode",
|
|
236
|
+
tags: ["imported", "opencode"],
|
|
237
|
+
dependencies: [],
|
|
238
|
+
conflicts: [],
|
|
239
|
+
targets: "*",
|
|
240
|
+
features: "*"
|
|
241
|
+
};
|
|
242
|
+
const dest = join2(packDir, "pack.json");
|
|
243
|
+
writeFileSync2(dest, JSON.stringify(packJson, null, 2) + `
|
|
244
|
+
`);
|
|
245
|
+
filesImported.push(dest);
|
|
246
|
+
return { packDir, filesImported, warnings, configGenerated: false };
|
|
247
|
+
}
|
|
248
|
+
function importDirMd(srcDir, outDir, filesImported) {
|
|
249
|
+
if (!existsSync2(srcDir))
|
|
250
|
+
return;
|
|
251
|
+
ensureDir(outDir);
|
|
252
|
+
const files = listFiles(srcDir, { extension: ".md" });
|
|
253
|
+
for (const file of files) {
|
|
254
|
+
const dest = join2(outDir, basename(file));
|
|
255
|
+
copyFileSync(file, dest);
|
|
256
|
+
filesImported.push(dest);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
export {
|
|
260
|
+
importFromOpenCode
|
|
261
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a rulesync import operation.
|
|
3
|
+
*/
|
|
4
|
+
export interface ImportResult {
|
|
5
|
+
packDir: string;
|
|
6
|
+
filesImported: string[];
|
|
7
|
+
warnings: string[];
|
|
8
|
+
configGenerated: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Import from an existing .rulesync/ directory into an agentpacks pack.
|
|
12
|
+
* Reads .rulesync/ and rulesync.jsonc, creates a pack at the specified output dir.
|
|
13
|
+
*/
|
|
14
|
+
export declare function importFromRulesync(projectRoot: string, outputPackDir?: string): ImportResult;
|
|
@@ -0,0 +1,280 @@
|
|
|
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/importers/rulesync.ts
|
|
143
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, copyFileSync, writeFileSync as writeFileSync2 } from "fs";
|
|
144
|
+
import { resolve as resolve2, join as join2, basename } from "path";
|
|
145
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
146
|
+
function importFromRulesync(projectRoot, outputPackDir) {
|
|
147
|
+
const rulesyncDir = resolve2(projectRoot, ".rulesync");
|
|
148
|
+
const warnings = [];
|
|
149
|
+
const filesImported = [];
|
|
150
|
+
if (!existsSync2(rulesyncDir)) {
|
|
151
|
+
return {
|
|
152
|
+
packDir: "",
|
|
153
|
+
filesImported: [],
|
|
154
|
+
warnings: ["No .rulesync/ directory found."],
|
|
155
|
+
configGenerated: false
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const packDir = outputPackDir ?? resolve2(projectRoot, "packs", "default");
|
|
159
|
+
ensureDir(packDir);
|
|
160
|
+
const rulesDir = resolve2(rulesyncDir, "rules");
|
|
161
|
+
if (existsSync2(rulesDir)) {
|
|
162
|
+
const outRulesDir = resolve2(packDir, "rules");
|
|
163
|
+
ensureDir(outRulesDir);
|
|
164
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
165
|
+
for (const file of files) {
|
|
166
|
+
const dest = join2(outRulesDir, basename(file));
|
|
167
|
+
copyFileSync(file, dest);
|
|
168
|
+
filesImported.push(dest);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const commandsDir = resolve2(rulesyncDir, "commands");
|
|
172
|
+
if (existsSync2(commandsDir)) {
|
|
173
|
+
const outCommandsDir = resolve2(packDir, "commands");
|
|
174
|
+
ensureDir(outCommandsDir);
|
|
175
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
176
|
+
for (const file of files) {
|
|
177
|
+
const dest = join2(outCommandsDir, basename(file));
|
|
178
|
+
copyFileSync(file, dest);
|
|
179
|
+
filesImported.push(dest);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const subagentsDir = resolve2(rulesyncDir, "subagents");
|
|
183
|
+
if (existsSync2(subagentsDir)) {
|
|
184
|
+
const outAgentsDir = resolve2(packDir, "agents");
|
|
185
|
+
ensureDir(outAgentsDir);
|
|
186
|
+
const files = listFiles(subagentsDir, { extension: ".md" });
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
const dest = join2(outAgentsDir, basename(file));
|
|
189
|
+
copyFileSync(file, dest);
|
|
190
|
+
filesImported.push(dest);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const skillsDir = resolve2(rulesyncDir, "skills");
|
|
194
|
+
if (existsSync2(skillsDir)) {
|
|
195
|
+
const outSkillsDir = resolve2(packDir, "skills");
|
|
196
|
+
ensureDir(outSkillsDir);
|
|
197
|
+
const skillDirs = listDirs(skillsDir);
|
|
198
|
+
for (const skillDir of skillDirs) {
|
|
199
|
+
const skillName = basename(skillDir);
|
|
200
|
+
if (skillName.startsWith("."))
|
|
201
|
+
continue;
|
|
202
|
+
const skillMd = join2(skillDir, "SKILL.md");
|
|
203
|
+
if (existsSync2(skillMd)) {
|
|
204
|
+
const outSkillDir = join2(outSkillsDir, skillName);
|
|
205
|
+
ensureDir(outSkillDir);
|
|
206
|
+
copyFileSync(skillMd, join2(outSkillDir, "SKILL.md"));
|
|
207
|
+
filesImported.push(join2(outSkillDir, "SKILL.md"));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const hooksJson = resolve2(rulesyncDir, "hooks.json");
|
|
212
|
+
if (existsSync2(hooksJson)) {
|
|
213
|
+
const outHooksDir = resolve2(packDir, "hooks");
|
|
214
|
+
ensureDir(outHooksDir);
|
|
215
|
+
copyFileSync(hooksJson, join2(outHooksDir, "hooks.json"));
|
|
216
|
+
filesImported.push(join2(outHooksDir, "hooks.json"));
|
|
217
|
+
}
|
|
218
|
+
const mcpJson = resolve2(rulesyncDir, "mcp.json");
|
|
219
|
+
if (existsSync2(mcpJson)) {
|
|
220
|
+
copyFileSync(mcpJson, join2(packDir, "mcp.json"));
|
|
221
|
+
filesImported.push(join2(packDir, "mcp.json"));
|
|
222
|
+
}
|
|
223
|
+
const aiIgnore = resolve2(rulesyncDir, ".aiignore");
|
|
224
|
+
const rulesyncIgnore = resolve2(projectRoot, ".rulesyncignore");
|
|
225
|
+
if (existsSync2(aiIgnore)) {
|
|
226
|
+
copyFileSync(aiIgnore, join2(packDir, "ignore"));
|
|
227
|
+
filesImported.push(join2(packDir, "ignore"));
|
|
228
|
+
} else if (existsSync2(rulesyncIgnore)) {
|
|
229
|
+
copyFileSync(rulesyncIgnore, join2(packDir, "ignore"));
|
|
230
|
+
filesImported.push(join2(packDir, "ignore"));
|
|
231
|
+
}
|
|
232
|
+
const packJson = {
|
|
233
|
+
name: "default",
|
|
234
|
+
version: "1.0.0",
|
|
235
|
+
description: "Imported from rulesync",
|
|
236
|
+
tags: ["imported", "rulesync"],
|
|
237
|
+
dependencies: [],
|
|
238
|
+
conflicts: [],
|
|
239
|
+
targets: "*",
|
|
240
|
+
features: "*"
|
|
241
|
+
};
|
|
242
|
+
writeFileSync2(join2(packDir, "pack.json"), JSON.stringify(packJson, null, 2) + `
|
|
243
|
+
`);
|
|
244
|
+
filesImported.push(join2(packDir, "pack.json"));
|
|
245
|
+
let configGenerated = false;
|
|
246
|
+
const rulesyncConfig = resolve2(projectRoot, "rulesync.jsonc");
|
|
247
|
+
if (existsSync2(rulesyncConfig)) {
|
|
248
|
+
const agentpacksConfig = convertRulesyncConfig(rulesyncConfig, packDir, projectRoot);
|
|
249
|
+
const configPath = resolve2(projectRoot, "agentpacks.jsonc");
|
|
250
|
+
writeFileSync2(configPath, agentpacksConfig);
|
|
251
|
+
configGenerated = true;
|
|
252
|
+
}
|
|
253
|
+
return { packDir, filesImported, warnings, configGenerated };
|
|
254
|
+
}
|
|
255
|
+
function convertRulesyncConfig(rulesyncPath, packDir, projectRoot) {
|
|
256
|
+
const raw = readFileSync2(rulesyncPath, "utf-8");
|
|
257
|
+
const parsed = parseJsonc(raw);
|
|
258
|
+
const targets = parsed.targets ?? ["opencode", "cursor", "claudecode"];
|
|
259
|
+
const features = parsed.features ?? ["*"];
|
|
260
|
+
const baseDirs = parsed.baseDirs ?? ["."];
|
|
261
|
+
const global = parsed.global ?? false;
|
|
262
|
+
const deleteVal = parsed.delete ?? true;
|
|
263
|
+
const relPackDir = "./" + join2("packs", "default");
|
|
264
|
+
const config = {
|
|
265
|
+
$schema: "https://unpkg.com/agentpacks/schema.json",
|
|
266
|
+
packs: [relPackDir],
|
|
267
|
+
disabled: [],
|
|
268
|
+
targets,
|
|
269
|
+
features,
|
|
270
|
+
mode: baseDirs.length > 1 ? "monorepo" : "repo",
|
|
271
|
+
baseDirs,
|
|
272
|
+
global,
|
|
273
|
+
delete: deleteVal
|
|
274
|
+
};
|
|
275
|
+
return JSON.stringify(config, null, 2) + `
|
|
276
|
+
`;
|
|
277
|
+
}
|
|
278
|
+
export {
|
|
279
|
+
importFromRulesync
|
|
280
|
+
};
|
package/dist/index.d.ts
ADDED