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.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
|
@@ -1,366 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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/rulesync.ts
|
|
223
|
-
import { copyFileSync, existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
224
|
-
import { parse as parseJsonc } from "jsonc-parser";
|
|
225
|
-
import { basename as basename2, join as join3, resolve } from "path";
|
|
226
|
-
function importFromRulesync(projectRoot, outputPackDir) {
|
|
227
|
-
const rulesyncDir = resolve(projectRoot, ".rulesync");
|
|
228
|
-
const warnings = [];
|
|
229
|
-
const filesImported = [];
|
|
230
|
-
if (!existsSync3(rulesyncDir)) {
|
|
231
|
-
return {
|
|
232
|
-
packDir: "",
|
|
233
|
-
filesImported: [],
|
|
234
|
-
warnings: ["No .rulesync/ directory found."],
|
|
235
|
-
configGenerated: false
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
const packDir = outputPackDir ?? resolve(projectRoot, "packs", "default");
|
|
239
|
-
ensureDir(packDir);
|
|
240
|
-
const rulesDir = resolve(rulesyncDir, "rules");
|
|
241
|
-
if (existsSync3(rulesDir)) {
|
|
242
|
-
const outRulesDir = resolve(packDir, "rules");
|
|
243
|
-
ensureDir(outRulesDir);
|
|
244
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
245
|
-
for (const file of files) {
|
|
246
|
-
const dest = join3(outRulesDir, basename2(file));
|
|
247
|
-
copyFileSync(file, dest);
|
|
248
|
-
filesImported.push(dest);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const commandsDir = resolve(rulesyncDir, "commands");
|
|
252
|
-
if (existsSync3(commandsDir)) {
|
|
253
|
-
const outCommandsDir = resolve(packDir, "commands");
|
|
254
|
-
ensureDir(outCommandsDir);
|
|
255
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
256
|
-
for (const file of files) {
|
|
257
|
-
const dest = join3(outCommandsDir, basename2(file));
|
|
258
|
-
copyFileSync(file, dest);
|
|
259
|
-
filesImported.push(dest);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
const subagentsDir = resolve(rulesyncDir, "subagents");
|
|
263
|
-
if (existsSync3(subagentsDir)) {
|
|
264
|
-
const outAgentsDir = resolve(packDir, "agents");
|
|
265
|
-
ensureDir(outAgentsDir);
|
|
266
|
-
const files = listFiles(subagentsDir, { extension: ".md" });
|
|
267
|
-
for (const file of files) {
|
|
268
|
-
const dest = join3(outAgentsDir, basename2(file));
|
|
269
|
-
copyFileSync(file, dest);
|
|
270
|
-
filesImported.push(dest);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
const skillsDir = resolve(rulesyncDir, "skills");
|
|
274
|
-
if (existsSync3(skillsDir)) {
|
|
275
|
-
const outSkillsDir = resolve(packDir, "skills");
|
|
276
|
-
ensureDir(outSkillsDir);
|
|
277
|
-
const skillDirs = listDirs(skillsDir);
|
|
278
|
-
for (const skillDir of skillDirs) {
|
|
279
|
-
const skillName = basename2(skillDir);
|
|
280
|
-
if (skillName.startsWith("."))
|
|
281
|
-
continue;
|
|
282
|
-
const skillMd = join3(skillDir, "SKILL.md");
|
|
283
|
-
if (existsSync3(skillMd)) {
|
|
284
|
-
const outSkillDir = join3(outSkillsDir, skillName);
|
|
285
|
-
ensureDir(outSkillDir);
|
|
286
|
-
const rawSkill = readFileSync3(skillMd, "utf-8");
|
|
287
|
-
const normalized = normalizeImportedSkillMarkdown(rawSkill, skillName);
|
|
288
|
-
const dest = join3(outSkillDir, "SKILL.md");
|
|
289
|
-
writeFileSync2(dest, normalized.content);
|
|
290
|
-
filesImported.push(dest);
|
|
291
|
-
if (normalized.addedDescription) {
|
|
292
|
-
warnings.push(`skills/${skillName}/SKILL.md missing description; added import placeholder.`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const hooksJson = resolve(rulesyncDir, "hooks.json");
|
|
298
|
-
if (existsSync3(hooksJson)) {
|
|
299
|
-
const outHooksDir = resolve(packDir, "hooks");
|
|
300
|
-
ensureDir(outHooksDir);
|
|
301
|
-
copyFileSync(hooksJson, join3(outHooksDir, "hooks.json"));
|
|
302
|
-
filesImported.push(join3(outHooksDir, "hooks.json"));
|
|
303
|
-
}
|
|
304
|
-
const mcpJson = resolve(rulesyncDir, "mcp.json");
|
|
305
|
-
if (existsSync3(mcpJson)) {
|
|
306
|
-
copyFileSync(mcpJson, join3(packDir, "mcp.json"));
|
|
307
|
-
filesImported.push(join3(packDir, "mcp.json"));
|
|
308
|
-
}
|
|
309
|
-
const aiIgnore = resolve(rulesyncDir, ".aiignore");
|
|
310
|
-
const rulesyncIgnore = resolve(projectRoot, ".rulesyncignore");
|
|
311
|
-
if (existsSync3(aiIgnore)) {
|
|
312
|
-
copyFileSync(aiIgnore, join3(packDir, "ignore"));
|
|
313
|
-
filesImported.push(join3(packDir, "ignore"));
|
|
314
|
-
} else if (existsSync3(rulesyncIgnore)) {
|
|
315
|
-
copyFileSync(rulesyncIgnore, join3(packDir, "ignore"));
|
|
316
|
-
filesImported.push(join3(packDir, "ignore"));
|
|
317
|
-
}
|
|
318
|
-
const packJson = {
|
|
319
|
-
name: "default",
|
|
320
|
-
version: "1.0.0",
|
|
321
|
-
description: "Imported from rulesync",
|
|
322
|
-
tags: ["imported", "rulesync"],
|
|
323
|
-
dependencies: [],
|
|
324
|
-
conflicts: [],
|
|
325
|
-
targets: "*",
|
|
326
|
-
features: "*"
|
|
327
|
-
};
|
|
328
|
-
writeFileSync2(join3(packDir, "pack.json"), JSON.stringify(packJson, null, 2) + `
|
|
329
|
-
`);
|
|
330
|
-
filesImported.push(join3(packDir, "pack.json"));
|
|
331
|
-
let configGenerated = false;
|
|
332
|
-
const rulesyncConfig = resolve(projectRoot, "rulesync.jsonc");
|
|
333
|
-
if (existsSync3(rulesyncConfig)) {
|
|
334
|
-
const agentpacksConfig = convertRulesyncConfig(rulesyncConfig, packDir);
|
|
335
|
-
const configPath = resolve(projectRoot, "agentpacks.jsonc");
|
|
336
|
-
writeFileSync2(configPath, agentpacksConfig);
|
|
337
|
-
configGenerated = true;
|
|
338
|
-
}
|
|
339
|
-
return { packDir, filesImported, warnings, configGenerated };
|
|
340
|
-
}
|
|
341
|
-
function convertRulesyncConfig(rulesyncPath, _packDir) {
|
|
342
|
-
const raw = readFileSync3(rulesyncPath, "utf-8");
|
|
343
|
-
const parsed = parseJsonc(raw);
|
|
344
|
-
const targets = parsed.targets ?? ["opencode", "cursor", "claudecode"];
|
|
345
|
-
const features = parsed.features ?? ["*"];
|
|
346
|
-
const baseDirs = parsed.baseDirs ?? ["."];
|
|
347
|
-
const global = parsed.global ?? false;
|
|
348
|
-
const deleteVal = parsed.delete ?? true;
|
|
349
|
-
const relPackDir = "./" + join3("packs", "default");
|
|
350
|
-
const config = {
|
|
351
|
-
$schema: "https://unpkg.com/agentpacks/schema.json",
|
|
352
|
-
packs: [relPackDir],
|
|
353
|
-
disabled: [],
|
|
354
|
-
targets,
|
|
355
|
-
features,
|
|
356
|
-
mode: baseDirs.length > 1 ? "monorepo" : "repo",
|
|
357
|
-
baseDirs,
|
|
358
|
-
global,
|
|
359
|
-
delete: deleteVal
|
|
360
|
-
};
|
|
361
|
-
return JSON.stringify(config, null, 2) + `
|
|
362
|
-
`;
|
|
363
|
-
}
|
|
364
|
-
export {
|
|
365
|
-
importFromRulesync
|
|
366
|
-
};
|
|
2
|
+
var zq=import.meta.require;import{existsSync as M,mkdirSync as r,readdirSync as y,readFileSync as t,rmSync as i,statSync as u,writeFileSync as e}from"fs";import{dirname as qq,join as h,relative as Bq}from"path";var f="<!-- Generated by agentpacks. DO NOT EDIT. -->",D="// Generated by agentpacks. DO NOT EDIT.",k="// Generated by agentpacks. DO NOT EDIT.";function Qq(q,B,Q={}){let{header:Y=!0,type:W}=Q,U=W??Uq(q);C(qq(q));let Z=B;if(Y){let O=Wq(U);if(O)Z=`${O}
|
|
3
|
+
${B}`}e(q,Z,"utf-8")}function Hq(q,B,Q={}){let Y=JSON.stringify(B,null,2);Qq(q,Y+`
|
|
4
|
+
`,{...Q,type:"json"})}function d(q){if(!M(q))return null;return t(q,"utf-8")}function Mq(q){let B=d(q);if(B===null)return null;return JSON.parse(B)}function C(q){if(!M(q))r(q,{recursive:!0})}function bq(q){if(M(q))i(q,{recursive:!0,force:!0})}function b(q,B={}){let{extension:Q,recursive:Y=!1}=B;if(!M(q))return[];let W=[],U=y(q);for(let Z of U){let O=h(q,Z),G=u(O);if(G.isDirectory()&&Y)W.push(...b(O,B));else if(G.isFile()){if(!Q||Z.endsWith(Q))W.push(O)}}return W}function w(q){if(!M(q))return[];return y(q).map((B)=>h(q,B)).filter((B)=>u(B).isDirectory())}function Tq(q,B){return Bq(q,B)}function wq(q){let B=d(q);if(!B)return!1;return B.startsWith(f)||B.startsWith(D)||B.startsWith(k)}function Uq(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 Wq(q){switch(q){case"md":return f;case"json":return D;case"js":case"ts":return k;default:return null}}import p from"gray-matter";function I(q){let{data:B,content:Q}=p(q);return{data:B,content:Q.trim(),raw:q}}function _(q,B){let Q=Object.fromEntries(Object.entries(q).filter(([,Y])=>Y!==void 0));if(Object.keys(Q).length===0)return B;return p.stringify(B,Q)}import{existsSync as Yq,readFileSync as Zq}from"fs";import{basename as n,join as $q}from"path";var Vq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,c=64;function Pq(q,B){let Q=w(q),Y=[];for(let W of Q){let U=$q(W,"SKILL.md");if(Yq(U))Y.push(Xq(U,W,B))}return Y}function Xq(q,B,Q){let Y=Zq(q,"utf-8"),{data:W,content:U}=I(Y);return{name:W.name??n(B),sourcePath:q,sourceDir:B,packName:Q,meta:W,content:U}}function Kq(q){return{...q.meta,name:q.name}}function Nq(q){return _(Kq(q),q.content)}function o(q,B){let{data:Q,content:Y}=I(q),W={...Q,name:B},U=!1,Z=W.description;if(typeof Z!=="string"||Z.trim().length===0)W.description=`Imported skill: ${B}`,U=!0;return{content:_(W,Y),addedDescription:U}}function Eq(q){let B=[],Q=n(q.sourceDir),Y=q.meta.name;if(typeof Y!=="string"||Y.trim().length===0)B.push('Missing required frontmatter field "name".');else{if(Y.length>c)B.push(`Invalid "name": must be at most ${c} characters.`);if(!Vq.test(Y))B.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Y!==Q)B.push(`Invalid "name": must match containing directory "${Q}".`)}let W=q.meta.description;if(typeof W!=="string"||W.trim().length===0)B.push('Missing required frontmatter field "description".');let U=q.meta["allowed-tools"];if(U!==void 0&&(!Array.isArray(U)||U.some((Z)=>typeof Z!=="string"||Z.length===0)))B.push('Invalid "allowed-tools": expected an array of non-empty strings.');return B}function gq(q,B){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(B)}import{copyFileSync as H,existsSync as z,readFileSync as a,writeFileSync as v}from"fs";import{parse as Oq}from"jsonc-parser";import{basename as x,join as X,resolve as V}from"path";function fq(q,B){let Q=V(q,".rulesync"),Y=[],W=[];if(!z(Q))return{packDir:"",filesImported:[],warnings:["No .rulesync/ directory found."],configGenerated:!1};let U=B??V(q,"packs","default");C(U);let Z=V(Q,"rules");if(z(Z)){let $=V(U,"rules");C($);let J=b(Z,{extension:".md"});for(let L of J){let K=X($,x(L));H(L,K),W.push(K)}}let O=V(Q,"commands");if(z(O)){let $=V(U,"commands");C($);let J=b(O,{extension:".md"});for(let L of J){let K=X($,x(L));H(L,K),W.push(K)}}let G=V(Q,"subagents");if(z(G)){let $=V(U,"agents");C($);let J=b(G,{extension:".md"});for(let L of J){let K=X($,x(L));H(L,K),W.push(K)}}let A=V(Q,"skills");if(z(A)){let $=V(U,"skills");C($);let J=w(A);for(let L of J){let K=x(L);if(K.startsWith("."))continue;let g=X(L,"SKILL.md");if(z(g)){let j=X($,K);C(j);let l=a(g,"utf-8"),S=o(l,K),m=X(j,"SKILL.md");if(v(m,S.content),W.push(m),S.addedDescription)Y.push(`skills/${K}/SKILL.md missing description; added import placeholder.`)}}}let T=V(Q,"hooks.json");if(z(T)){let $=V(U,"hooks");C($),H(T,X($,"hooks.json")),W.push(X($,"hooks.json"))}let R=V(Q,"mcp.json");if(z(R))H(R,X(U,"mcp.json")),W.push(X(U,"mcp.json"));let F=V(Q,".aiignore"),P=V(q,".rulesyncignore");if(z(F))H(F,X(U,"ignore")),W.push(X(U,"ignore"));else if(z(P))H(P,X(U,"ignore")),W.push(X(U,"ignore"));let s={name:"default",version:"1.0.0",description:"Imported from rulesync",tags:["imported","rulesync"],dependencies:[],conflicts:[],targets:"*",features:"*"};v(X(U,"pack.json"),JSON.stringify(s,null,2)+`
|
|
5
|
+
`),W.push(X(U,"pack.json"));let N=!1,E=V(q,"rulesync.jsonc");if(z(E)){let $=Lq(E,U),J=V(q,"agentpacks.jsonc");v(J,$),N=!0}return{packDir:U,filesImported:W,warnings:Y,configGenerated:N}}function Lq(q,B){let Q=a(q,"utf-8"),Y=Oq(Q),W=Y.targets??["opencode","cursor","claudecode"],U=Y.features??["*"],Z=Y.baseDirs??["."],O=Y.global??!1,G=Y.delete??!0,T={$schema:"https://unpkg.com/agentpacks/schema.json",packs:["./"+X("packs","default")],disabled:[],targets:W,features:U,mode:Z.length>1?"monorepo":"repo",baseDirs:Z,global:O,delete:G};return JSON.stringify(T,null,2)+`
|
|
6
|
+
`}export{fq as importFromRulesync};
|