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,700 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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/agents.ts
|
|
133
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
134
|
-
import { basename } from "path";
|
|
135
|
-
function parseAgents(agentsDir, packName) {
|
|
136
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
137
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
138
|
-
}
|
|
139
|
-
function parseAgentFile(filepath, packName) {
|
|
140
|
-
const raw = readFileSync2(filepath, "utf-8");
|
|
141
|
-
const { data, content } = parseFrontmatter(raw);
|
|
142
|
-
return {
|
|
143
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
144
|
-
sourcePath: filepath,
|
|
145
|
-
packName,
|
|
146
|
-
meta: data,
|
|
147
|
-
content
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function agentMatchesTarget(agent, targetId) {
|
|
151
|
-
const { targets } = agent.meta;
|
|
152
|
-
if (!targets || targets === "*")
|
|
153
|
-
return true;
|
|
154
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
155
|
-
return true;
|
|
156
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// src/features/commands.ts
|
|
160
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
161
|
-
import { basename as basename2 } from "path";
|
|
162
|
-
function parseCommands(commandsDir, packName) {
|
|
163
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
164
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
165
|
-
}
|
|
166
|
-
function parseCommandFile(filepath, packName) {
|
|
167
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
168
|
-
const { data, content } = parseFrontmatter(raw);
|
|
169
|
-
return {
|
|
170
|
-
name: basename2(filepath, ".md"),
|
|
171
|
-
sourcePath: filepath,
|
|
172
|
-
packName,
|
|
173
|
-
meta: data,
|
|
174
|
-
content
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
178
|
-
const { targets } = cmd.meta;
|
|
179
|
-
if (!targets || targets === "*")
|
|
180
|
-
return true;
|
|
181
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
182
|
-
return true;
|
|
183
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// src/features/hooks.ts
|
|
187
|
-
import { join as join2 } from "path";
|
|
188
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
189
|
-
function parseHooks(packDir, packName) {
|
|
190
|
-
const hooksPath = join2(packDir, "hooks", "hooks.json");
|
|
191
|
-
const raw = readJsonOrNull(hooksPath);
|
|
192
|
-
if (!raw)
|
|
193
|
-
return null;
|
|
194
|
-
const shared = raw.hooks ?? {};
|
|
195
|
-
const targetOverrides = {};
|
|
196
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
197
|
-
const override = raw[key];
|
|
198
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
199
|
-
targetOverrides[key] = override.hooks;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
packName,
|
|
204
|
-
sourcePath: hooksPath,
|
|
205
|
-
version: raw.version,
|
|
206
|
-
shared,
|
|
207
|
-
targetOverrides
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
211
|
-
const merged = {};
|
|
212
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
213
|
-
merged[event] = [...entries];
|
|
214
|
-
}
|
|
215
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
216
|
-
if (overrides) {
|
|
217
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
218
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return merged;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/features/rules.ts
|
|
225
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
226
|
-
import { basename as basename3 } from "path";
|
|
227
|
-
function parseRules(rulesDir, packName) {
|
|
228
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
229
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
230
|
-
}
|
|
231
|
-
function parseRuleFile(filepath, packName) {
|
|
232
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
233
|
-
const { data, content } = parseFrontmatter(raw);
|
|
234
|
-
return {
|
|
235
|
-
name: basename3(filepath, ".md"),
|
|
236
|
-
sourcePath: filepath,
|
|
237
|
-
packName,
|
|
238
|
-
meta: data,
|
|
239
|
-
content
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
243
|
-
const { targets } = rule.meta;
|
|
244
|
-
if (!targets || targets === "*")
|
|
245
|
-
return true;
|
|
246
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
247
|
-
return true;
|
|
248
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
249
|
-
}
|
|
250
|
-
function getRootRules(rules) {
|
|
251
|
-
return rules.filter((r) => r.meta.root === true);
|
|
252
|
-
}
|
|
253
|
-
function getDetailRules(rules) {
|
|
254
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// src/features/skills.ts
|
|
258
|
-
import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
259
|
-
import { basename as basename4, join as join3 } from "path";
|
|
260
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
261
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
262
|
-
function parseSkills(skillsDir, packName) {
|
|
263
|
-
const dirs = listDirs(skillsDir);
|
|
264
|
-
const skills = [];
|
|
265
|
-
for (const dir of dirs) {
|
|
266
|
-
const skillMd = join3(dir, "SKILL.md");
|
|
267
|
-
if (existsSync2(skillMd)) {
|
|
268
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return skills;
|
|
272
|
-
}
|
|
273
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
274
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
275
|
-
const { data, content } = parseFrontmatter(raw);
|
|
276
|
-
return {
|
|
277
|
-
name: data.name ?? basename4(skillDir),
|
|
278
|
-
sourcePath: filepath,
|
|
279
|
-
sourceDir: skillDir,
|
|
280
|
-
packName,
|
|
281
|
-
meta: data,
|
|
282
|
-
content
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function buildSkillFrontmatter(skill) {
|
|
286
|
-
return {
|
|
287
|
-
...skill.meta,
|
|
288
|
-
name: skill.name
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function serializeSkill(skill) {
|
|
292
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
293
|
-
}
|
|
294
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
295
|
-
const { data, content } = parseFrontmatter(source);
|
|
296
|
-
const normalized = {
|
|
297
|
-
...data,
|
|
298
|
-
name: skillName
|
|
299
|
-
};
|
|
300
|
-
let addedDescription = false;
|
|
301
|
-
const description = normalized.description;
|
|
302
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
303
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
304
|
-
addedDescription = true;
|
|
305
|
-
}
|
|
306
|
-
return {
|
|
307
|
-
content: serializeFrontmatter(normalized, content),
|
|
308
|
-
addedDescription
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
312
|
-
const errors = [];
|
|
313
|
-
const dirName = basename4(skill.sourceDir);
|
|
314
|
-
const declaredName = skill.meta.name;
|
|
315
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
316
|
-
errors.push('Missing required frontmatter field "name".');
|
|
317
|
-
} else {
|
|
318
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
319
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
320
|
-
}
|
|
321
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
322
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
323
|
-
}
|
|
324
|
-
if (declaredName !== dirName) {
|
|
325
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
const description = skill.meta.description;
|
|
329
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
330
|
-
errors.push('Missing required frontmatter field "description".');
|
|
331
|
-
}
|
|
332
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
333
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
334
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
335
|
-
}
|
|
336
|
-
return errors;
|
|
337
|
-
}
|
|
338
|
-
function skillMatchesTarget(skill, targetId) {
|
|
339
|
-
const { targets } = skill.meta;
|
|
340
|
-
if (!targets || targets === "*")
|
|
341
|
-
return true;
|
|
342
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
343
|
-
return true;
|
|
344
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/core/profile-resolver.ts
|
|
348
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
349
|
-
let defaultModel = merged.default;
|
|
350
|
-
let smallModel = merged.small;
|
|
351
|
-
let agents = { ...merged.agents };
|
|
352
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
353
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
354
|
-
if (resolvedProfile.default)
|
|
355
|
-
defaultModel = resolvedProfile.default;
|
|
356
|
-
if (resolvedProfile.small)
|
|
357
|
-
smallModel = resolvedProfile.small;
|
|
358
|
-
if (resolvedProfile.agents) {
|
|
359
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (targetId) {
|
|
363
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
364
|
-
if (targetOverride) {
|
|
365
|
-
if (targetOverride.default)
|
|
366
|
-
defaultModel = targetOverride.default;
|
|
367
|
-
if (targetOverride.small)
|
|
368
|
-
smallModel = targetOverride.small;
|
|
369
|
-
if (targetOverride.agents) {
|
|
370
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
const providers = {};
|
|
375
|
-
if (merged.providers) {
|
|
376
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
377
|
-
providers[name] = {
|
|
378
|
-
...config.options ? { options: config.options } : {},
|
|
379
|
-
...config.models ? { models: config.models } : {}
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
384
|
-
const profiles = {};
|
|
385
|
-
if (merged.profiles) {
|
|
386
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
387
|
-
profiles[name] = {
|
|
388
|
-
description: profile.description,
|
|
389
|
-
default: profile.default,
|
|
390
|
-
small: profile.small
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
default: defaultModel,
|
|
396
|
-
small: smallModel,
|
|
397
|
-
agents,
|
|
398
|
-
providers,
|
|
399
|
-
routing: merged.routing ?? [],
|
|
400
|
-
profileNames,
|
|
401
|
-
activeProfile: modelProfile,
|
|
402
|
-
profiles
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
406
|
-
const fromModels = resolved.agents[agentName];
|
|
407
|
-
if (fromModels) {
|
|
408
|
-
return {
|
|
409
|
-
model: fromModels.model,
|
|
410
|
-
temperature: fromModels.temperature,
|
|
411
|
-
top_p: fromModels.top_p
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if (frontmatterModel) {
|
|
415
|
-
return { model: frontmatterModel };
|
|
416
|
-
}
|
|
417
|
-
return {};
|
|
418
|
-
}
|
|
419
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
420
|
-
const visited = new Set;
|
|
421
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
422
|
-
}
|
|
423
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
424
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
425
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
426
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
427
|
-
}
|
|
428
|
-
if (visited.has(name)) {
|
|
429
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" → ")}`);
|
|
430
|
-
}
|
|
431
|
-
const profile = profiles[name];
|
|
432
|
-
if (!profile) {
|
|
433
|
-
throw new Error(`Profile "${name}" not found`);
|
|
434
|
-
}
|
|
435
|
-
visited.add(name);
|
|
436
|
-
if (!profile.extends) {
|
|
437
|
-
return { ...profile };
|
|
438
|
-
}
|
|
439
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
440
|
-
return {
|
|
441
|
-
description: profile.description ?? parent.description,
|
|
442
|
-
default: profile.default ?? parent.default,
|
|
443
|
-
small: profile.small ?? parent.small,
|
|
444
|
-
agents: {
|
|
445
|
-
...parent.agents,
|
|
446
|
-
...profile.agents
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// src/targets/base-target.ts
|
|
452
|
-
class BaseTarget {
|
|
453
|
-
supportsFeature(feature) {
|
|
454
|
-
return this.supportedFeatures.includes(feature);
|
|
455
|
-
}
|
|
456
|
-
getEffectiveFeatures(enabledFeatures) {
|
|
457
|
-
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
458
|
-
}
|
|
459
|
-
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
460
|
-
return {
|
|
461
|
-
targetId: this.id,
|
|
462
|
-
filesWritten,
|
|
463
|
-
filesDeleted,
|
|
464
|
-
warnings
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/targets/cursor.ts
|
|
470
|
-
import { join as join4, resolve } from "path";
|
|
471
|
-
var TARGET_ID = "cursor";
|
|
472
|
-
|
|
473
|
-
class CursorTarget extends BaseTarget {
|
|
474
|
-
id = TARGET_ID;
|
|
475
|
-
name = "Cursor";
|
|
476
|
-
supportedFeatures = [
|
|
477
|
-
"rules",
|
|
478
|
-
"commands",
|
|
479
|
-
"agents",
|
|
480
|
-
"skills",
|
|
481
|
-
"hooks",
|
|
482
|
-
"mcp",
|
|
483
|
-
"ignore",
|
|
484
|
-
"models"
|
|
485
|
-
];
|
|
486
|
-
generate(options) {
|
|
487
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
488
|
-
const root = resolve(projectRoot, baseDir);
|
|
489
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
490
|
-
const filesWritten = [];
|
|
491
|
-
const filesDeleted = [];
|
|
492
|
-
const warnings = [];
|
|
493
|
-
const cursorDir = resolve(root, ".cursor");
|
|
494
|
-
if (effective.includes("rules")) {
|
|
495
|
-
const rulesDir = resolve(cursorDir, "rules");
|
|
496
|
-
if (deleteExisting) {
|
|
497
|
-
removeIfExists(rulesDir);
|
|
498
|
-
filesDeleted.push(rulesDir);
|
|
499
|
-
}
|
|
500
|
-
ensureDir(rulesDir);
|
|
501
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
|
|
502
|
-
for (const rule of rules) {
|
|
503
|
-
const cursorMeta = rule.meta.cursor ?? {};
|
|
504
|
-
const frontmatter = {
|
|
505
|
-
description: cursorMeta.description ?? rule.meta.description ?? "",
|
|
506
|
-
alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
|
|
507
|
-
};
|
|
508
|
-
const globs = cursorMeta.globs ?? rule.meta.globs;
|
|
509
|
-
if (globs) {
|
|
510
|
-
frontmatter.globs = globs;
|
|
511
|
-
}
|
|
512
|
-
const filepath = join4(rulesDir, `${rule.name}.mdc`);
|
|
513
|
-
const content = serializeFrontmatter(frontmatter, rule.content);
|
|
514
|
-
writeGeneratedFile(filepath, content);
|
|
515
|
-
filesWritten.push(filepath);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (effective.includes("agents")) {
|
|
519
|
-
const agentsDir = resolve(cursorDir, "agents");
|
|
520
|
-
if (deleteExisting) {
|
|
521
|
-
removeIfExists(agentsDir);
|
|
522
|
-
filesDeleted.push(agentsDir);
|
|
523
|
-
}
|
|
524
|
-
ensureDir(agentsDir);
|
|
525
|
-
const resolvedModels = features.models ? resolveModels(features.models, options.modelProfile, TARGET_ID) : null;
|
|
526
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
|
|
527
|
-
for (const agent of agents) {
|
|
528
|
-
const frontmatter = {
|
|
529
|
-
name: agent.name,
|
|
530
|
-
description: agent.meta.description ?? ""
|
|
531
|
-
};
|
|
532
|
-
const cursorMeta = agent.meta.cursor ?? {};
|
|
533
|
-
const modelsAgent = resolvedModels?.agents[agent.name];
|
|
534
|
-
const model = modelsAgent?.model ?? cursorMeta.model;
|
|
535
|
-
if (model) {
|
|
536
|
-
frontmatter.model = model;
|
|
537
|
-
}
|
|
538
|
-
const filepath = join4(agentsDir, `${agent.name}.md`);
|
|
539
|
-
const content = serializeFrontmatter(frontmatter, agent.content);
|
|
540
|
-
writeGeneratedFile(filepath, content);
|
|
541
|
-
filesWritten.push(filepath);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (effective.includes("skills")) {
|
|
545
|
-
const skillsDir = resolve(cursorDir, "skills");
|
|
546
|
-
if (deleteExisting) {
|
|
547
|
-
removeIfExists(skillsDir);
|
|
548
|
-
filesDeleted.push(skillsDir);
|
|
549
|
-
}
|
|
550
|
-
ensureDir(skillsDir);
|
|
551
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
|
|
552
|
-
for (const skill of skills) {
|
|
553
|
-
const skillSubDir = join4(skillsDir, skill.name);
|
|
554
|
-
ensureDir(skillSubDir);
|
|
555
|
-
const filepath = join4(skillSubDir, "SKILL.md");
|
|
556
|
-
const content = serializeSkill(skill);
|
|
557
|
-
writeGeneratedFile(filepath, content);
|
|
558
|
-
filesWritten.push(filepath);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
if (effective.includes("commands")) {
|
|
562
|
-
const commandsDir = resolve(cursorDir, "commands");
|
|
563
|
-
if (deleteExisting) {
|
|
564
|
-
removeIfExists(commandsDir);
|
|
565
|
-
filesDeleted.push(commandsDir);
|
|
566
|
-
}
|
|
567
|
-
ensureDir(commandsDir);
|
|
568
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
|
|
569
|
-
for (const cmd of commands) {
|
|
570
|
-
const filepath = join4(commandsDir, `${cmd.name}.md`);
|
|
571
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
572
|
-
filesWritten.push(filepath);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
if (effective.includes("hooks")) {
|
|
576
|
-
const hooksFilepath = resolve(cursorDir, "hooks.json");
|
|
577
|
-
if (deleteExisting) {
|
|
578
|
-
removeIfExists(hooksFilepath);
|
|
579
|
-
filesDeleted.push(hooksFilepath);
|
|
580
|
-
}
|
|
581
|
-
const mergedHooks = {};
|
|
582
|
-
for (const hookSet of features.hooks) {
|
|
583
|
-
const events = resolveHooksForTarget(hookSet, TARGET_ID);
|
|
584
|
-
for (const [event, entries] of Object.entries(events)) {
|
|
585
|
-
if (!mergedHooks[event]) {
|
|
586
|
-
mergedHooks[event] = [];
|
|
587
|
-
}
|
|
588
|
-
mergedHooks[event].push(...entries);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
if (Object.keys(mergedHooks).length > 0) {
|
|
592
|
-
const hooksVersion = features.hooks.find((h) => h.version !== undefined)?.version ?? 1;
|
|
593
|
-
writeGeneratedJson(hooksFilepath, { version: hooksVersion, hooks: mergedHooks }, { header: false });
|
|
594
|
-
filesWritten.push(hooksFilepath);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
if (effective.includes("mcp")) {
|
|
598
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
599
|
-
if (mcpEntries.length > 0) {
|
|
600
|
-
const mcpConfig = buildCursorMcp(features.mcpServers);
|
|
601
|
-
const filepath = resolve(cursorDir, "mcp.json");
|
|
602
|
-
writeGeneratedJson(filepath, mcpConfig, { header: false });
|
|
603
|
-
filesWritten.push(filepath);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
if (effective.includes("ignore")) {
|
|
607
|
-
if (features.ignorePatterns.length > 0) {
|
|
608
|
-
const filepath = resolve(root, ".cursorignore");
|
|
609
|
-
const content = features.ignorePatterns.join(`
|
|
610
|
-
`) + `
|
|
611
|
-
`;
|
|
612
|
-
writeGeneratedFile(filepath, content);
|
|
613
|
-
filesWritten.push(filepath);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
if (effective.includes("models") && features.models) {
|
|
617
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID);
|
|
618
|
-
const guidanceContent = buildCursorModelGuidance(resolved);
|
|
619
|
-
if (guidanceContent) {
|
|
620
|
-
const rulesDir = resolve(cursorDir, "rules");
|
|
621
|
-
ensureDir(rulesDir);
|
|
622
|
-
const filepath = join4(rulesDir, "model-config.mdc");
|
|
623
|
-
writeGeneratedFile(filepath, guidanceContent, { header: false });
|
|
624
|
-
filesWritten.push(filepath);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
function buildCursorMcp(servers) {
|
|
631
|
-
const mcpServers = {};
|
|
632
|
-
for (const [name, entry] of Object.entries(servers)) {
|
|
633
|
-
if (entry.url) {
|
|
634
|
-
mcpServers[name] = { url: entry.url };
|
|
635
|
-
} else if (entry.command) {
|
|
636
|
-
mcpServers[name] = {
|
|
637
|
-
command: entry.command,
|
|
638
|
-
...entry.args ? { args: entry.args } : {},
|
|
639
|
-
...entry.env ? { env: entry.env } : {}
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return { mcpServers };
|
|
644
|
-
}
|
|
645
|
-
function buildCursorModelGuidance(resolved) {
|
|
646
|
-
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0) {
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
const frontmatter = {
|
|
650
|
-
description: "Model configuration and selection guidelines for this workspace",
|
|
651
|
-
alwaysApply: true
|
|
652
|
-
};
|
|
653
|
-
const lines = [];
|
|
654
|
-
lines.push("# Model Configuration");
|
|
655
|
-
lines.push("");
|
|
656
|
-
lines.push("Use the following model preferences when working in this project.");
|
|
657
|
-
lines.push("");
|
|
658
|
-
if (resolved.default || resolved.small) {
|
|
659
|
-
lines.push("## Default Models");
|
|
660
|
-
lines.push("");
|
|
661
|
-
if (resolved.default) {
|
|
662
|
-
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
663
|
-
}
|
|
664
|
-
if (resolved.small) {
|
|
665
|
-
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
666
|
-
}
|
|
667
|
-
lines.push("");
|
|
668
|
-
}
|
|
669
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
670
|
-
if (agentEntries.length > 0) {
|
|
671
|
-
lines.push("## Agent Model Assignments");
|
|
672
|
-
lines.push("");
|
|
673
|
-
lines.push("| Agent | Model | Temperature |");
|
|
674
|
-
lines.push("| --- | --- | --- |");
|
|
675
|
-
for (const [name, assignment] of agentEntries) {
|
|
676
|
-
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "—";
|
|
677
|
-
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
678
|
-
}
|
|
679
|
-
lines.push("");
|
|
680
|
-
}
|
|
681
|
-
if (Object.keys(resolved.profiles).length > 0) {
|
|
682
|
-
lines.push("## Available Profiles");
|
|
683
|
-
lines.push("");
|
|
684
|
-
lines.push("| Profile | Description | Default Model |");
|
|
685
|
-
lines.push("| --- | --- | --- |");
|
|
686
|
-
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
687
|
-
lines.push(`| ${name} | ${profile.description ?? "—"} | ${profile.default ?? "—"} |`);
|
|
688
|
-
}
|
|
689
|
-
lines.push("");
|
|
690
|
-
}
|
|
691
|
-
if (resolved.activeProfile) {
|
|
692
|
-
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
693
|
-
lines.push("");
|
|
694
|
-
}
|
|
695
|
-
return serializeFrontmatter(frontmatter, lines.join(`
|
|
696
|
-
`));
|
|
697
|
-
}
|
|
698
|
-
export {
|
|
699
|
-
CursorTarget
|
|
700
|
-
};
|
|
1
|
+
import{createRequire as Qq}from"node:module";var Nq=Qq(import.meta.url);import{existsSync as M,mkdirSync as Uq,readdirSync as D,readFileSync as Zq,rmSync as $q,statSync as k,writeFileSync as Yq}from"fs";import{dirname as Bq,join as v,relative as Vq}from"path";var u="<!-- Generated by agentpacks. DO NOT EDIT. -->",h="// Generated by agentpacks. DO NOT EDIT.",g="// Generated by agentpacks. DO NOT EDIT.";function w(q,U,Q={}){let{header:Z=!0,type:$}=Q,Y=$??Kq(q);G(Bq(q));let L=U;if(Z){let J=Xq(Y);if(J)L=`${J}
|
|
2
|
+
${U}`}Yq(q,L,"utf-8")}function F(q,U,Q={}){let Z=JSON.stringify(U,null,2);w(q,Z+`
|
|
3
|
+
`,{...Q,type:"json"})}function c(q){if(!M(q))return null;return Zq(q,"utf-8")}function p(q){let U=c(q);if(U===null)return null;return JSON.parse(U)}function G(q){if(!M(q))Uq(q,{recursive:!0})}function I(q){if(M(q))$q(q,{recursive:!0,force:!0})}function _(q,U={}){let{extension:Q,recursive:Z=!1}=U;if(!M(q))return[];let $=[],Y=D(q);for(let L of Y){let J=v(q,L),W=k(J);if(W.isDirectory()&&Z)$.push(..._(J,U));else if(W.isFile()){if(!Q||L.endsWith(Q))$.push(J)}}return $}function m(q){if(!M(q))return[];return D(q).map((U)=>v(q,U)).filter((U)=>k(U).isDirectory())}function vq(q,U){return Vq(q,U)}function uq(q){let U=c(q);if(!U)return!1;return U.startsWith(u)||U.startsWith(h)||U.startsWith(g)}function Kq(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 Xq(q){switch(q){case"md":return u;case"json":return h;case"js":case"ts":return g;default:return null}}import f from"gray-matter";function b(q){let{data:U,content:Q}=f(q);return{data:U,content:Q.trim(),raw:q}}function A(q,U){let Q=Object.fromEntries(Object.entries(q).filter(([,Z])=>Z!==void 0));if(Object.keys(Q).length===0)return U;return f.stringify(U,Q)}import{readFileSync as Jq}from"fs";import{basename as Lq}from"path";function nq(q,U){return _(q,{extension:".md"}).map((Z)=>zq(Z,U))}function zq(q,U){let Q=Jq(q,"utf-8"),{data:Z,content:$}=b(Q);return{name:Z.name??Lq(q,".md"),sourcePath:q,packName:U,meta:Z,content:$}}function d(q,U){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(U)}import{readFileSync as Wq}from"fs";import{basename as Oq}from"path";function rq(q,U){return _(q,{extension:".md"}).map((Z)=>Cq(Z,U))}function Cq(q,U){let Q=Wq(q,"utf-8"),{data:Z,content:$}=b(Q);return{name:Oq(q,".md"),sourcePath:q,packName:U,meta:Z,content:$}}function n(q,U){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(U)}import{join as xq}from"path";var bq=["cursor","claudecode","codexcli","opencode"];function QQ(q,U){let Q=xq(q,"hooks","hooks.json"),Z=p(Q);if(!Z)return null;let $=Z.hooks??{},Y={};for(let L of bq){let J=Z[L];if(J&&typeof J==="object"&&"hooks"in J&&J.hooks)Y[L]=J.hooks}return{packName:U,sourcePath:Q,version:Z.version,shared:$,targetOverrides:Y}}function o(q,U){let Q={};for(let[$,Y]of Object.entries(q.shared))Q[$]=[...Y];let Z=q.targetOverrides[U];if(Z)for(let[$,Y]of Object.entries(Z))Q[$]=[...Q[$]??[],...Y];return Q}import{readFileSync as Hq}from"fs";import{basename as wq}from"path";function VQ(q,U){return _(q,{extension:".md"}).map((Z)=>Gq(Z,U))}function Gq(q,U){let Q=Hq(q,"utf-8"),{data:Z,content:$}=b(Q);return{name:wq(q,".md"),sourcePath:q,packName:U,meta:Z,content:$}}function a(q,U){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(U)}function KQ(q){return q.filter((U)=>U.meta.root===!0)}function XQ(q){return q.filter((U)=>U.meta.root!==!0)}import{existsSync as Rq,readFileSync as jq}from"fs";import{basename as s,join as _q}from"path";var Aq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,l=64;function CQ(q,U){let Q=m(q),Z=[];for(let $ of Q){let Y=_q($,"SKILL.md");if(Rq(Y))Z.push(Iq(Y,$,U))}return Z}function Iq(q,U,Q){let Z=jq(q,"utf-8"),{data:$,content:Y}=b(Z);return{name:$.name??s(U),sourcePath:q,sourceDir:U,packName:Q,meta:$,content:Y}}function Sq(q){return{...q.meta,name:q.name}}function i(q){return A(Sq(q),q.content)}function xQ(q,U){let{data:Q,content:Z}=b(q),$={...Q,name:U},Y=!1,L=$.description;if(typeof L!=="string"||L.trim().length===0)$.description=`Imported skill: ${U}`,Y=!0;return{content:A($,Z),addedDescription:Y}}function bQ(q){let U=[],Q=s(q.sourceDir),Z=q.meta.name;if(typeof Z!=="string"||Z.trim().length===0)U.push('Missing required frontmatter field "name".');else{if(Z.length>l)U.push(`Invalid "name": must be at most ${l} characters.`);if(!Aq.test(Z))U.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==Q)U.push(`Invalid "name": must match containing directory "${Q}".`)}let $=q.meta.description;if(typeof $!=="string"||$.trim().length===0)U.push('Missing required frontmatter field "description".');let Y=q.meta["allowed-tools"];if(Y!==void 0&&(!Array.isArray(Y)||Y.some((L)=>typeof L!=="string"||L.length===0)))U.push('Invalid "allowed-tools": expected an array of non-empty strings.');return U}function r(q,U){let{targets:Q}=q.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(U)}function P(q,U,Q){let{default:Z,small:$}=q,Y={...q.agents};if(U&&q.profiles?.[U]){let K=Mq(U,q.profiles);if(K.default)Z=K.default;if(K.small)$=K.small;if(K.agents)Y={...Y,...K.agents}}if(Q){let K=q.overrides?.[Q];if(K){if(K.default)Z=K.default;if(K.small)$=K.small;if(K.agents)Y={...Y,...K.agents}}}let L={};if(q.providers)for(let[K,C]of Object.entries(q.providers))L[K]={...C.options?{options:C.options}:{},...C.models?{models:C.models}:{}};let J=Object.keys(q.profiles??{}),W={};if(q.profiles)for(let[K,C]of Object.entries(q.profiles))W[K]={description:C.description,default:C.default,small:C.small};return{default:Z,small:$,agents:Y,providers:L,routing:q.routing??[],profileNames:J,activeProfile:U,profiles:W}}function wQ(q,U,Q){let Z=q.agents[U];if(Z)return{model:Z.model,temperature:Z.temperature,top_p:Z.top_p};if(Q)return{model:Q};return{}}function Mq(q,U){return e(q,U,new Set,0)}var t=10;function e(q,U,Q,Z){if(Z>t)throw Error(`Profile inheritance too deep (max ${t}): ${q}`);if(Q.has(q))throw Error(`Circular profile inheritance detected: ${[...Q,q].join(" → ")}`);let $=U[q];if(!$)throw Error(`Profile "${q}" not found`);if(Q.add(q),!$.extends)return{...$};let Y=e($.extends,U,Q,Z+1);return{description:$.description??Y.description,default:$.default??Y.default,small:$.small??Y.small,agents:{...Y.agents,...$.agents}}}class N{supportsFeature(q){return this.supportedFeatures.includes(q)}getEffectiveFeatures(q){return q.filter((U)=>this.supportsFeature(U))}createResult(q=[],U=[],Q=[]){return{targetId:this.id,filesWritten:q,filesDeleted:U,warnings:Q}}}import{join as S,resolve as x}from"path";var R="cursor";class Tq extends N{id=R;name="Cursor";supportedFeatures=["rules","commands","agents","skills","hooks","mcp","ignore","models"];generate(q){let{projectRoot:U,baseDir:Q,features:Z,enabledFeatures:$,deleteExisting:Y}=q,L=x(U,Q),J=this.getEffectiveFeatures($),W=[],K=[],C=[],j=x(L,".cursor");if(J.includes("rules")){let B=x(j,"rules");if(Y)I(B),K.push(B);G(B);let z=Z.rules.filter((V)=>a(V,R));for(let V of z){let X=V.meta.cursor??{},O={description:X.description??V.meta.description??"",alwaysApply:X.alwaysApply??V.meta.root??!1},H=X.globs??V.meta.globs;if(H)O.globs=H;let y=S(B,`${V.name}.mdc`),T=A(O,V.content);w(y,T),W.push(y)}}if(J.includes("agents")){let B=x(j,"agents");if(Y)I(B),K.push(B);G(B);let z=Z.models?P(Z.models,q.modelProfile,R):null,V=Z.agents.filter((X)=>d(X,R));for(let X of V){let O={name:X.name,description:X.meta.description??""},H=X.meta.cursor??{},T=z?.agents[X.name]?.model??H.model;if(T)O.model=T;let E=S(B,`${X.name}.md`),qq=A(O,X.content);w(E,qq),W.push(E)}}if(J.includes("skills")){let B=x(j,"skills");if(Y)I(B),K.push(B);G(B);let z=Z.skills.filter((V)=>r(V,R));for(let V of z){let X=S(B,V.name);G(X);let O=S(X,"SKILL.md"),H=i(V);w(O,H),W.push(O)}}if(J.includes("commands")){let B=x(j,"commands");if(Y)I(B),K.push(B);G(B);let z=Z.commands.filter((V)=>n(V,R));for(let V of z){let X=S(B,`${V.name}.md`);w(X,V.content),W.push(X)}}if(J.includes("hooks")){let B=x(j,"hooks.json");if(Y)I(B),K.push(B);let z={};for(let V of Z.hooks){let X=o(V,R);for(let[O,H]of Object.entries(X)){if(!z[O])z[O]=[];z[O].push(...H)}}if(Object.keys(z).length>0){let V=Z.hooks.find((X)=>X.version!==void 0)?.version??1;F(B,{version:V,hooks:z},{header:!1}),W.push(B)}}if(J.includes("mcp")){if(Object.entries(Z.mcpServers).length>0){let z=yq(Z.mcpServers),V=x(j,"mcp.json");F(V,z,{header:!1}),W.push(V)}}if(J.includes("ignore")){if(Z.ignorePatterns.length>0){let B=x(L,".cursorignore"),z=Z.ignorePatterns.join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`;w(B,z),W.push(B)}}if(J.includes("models")&&Z.models){let B=P(Z.models,q.modelProfile,R),z=Fq(B);if(z){let V=x(j,"rules");G(V);let X=S(V,"model-config.mdc");w(X,z,{header:!1}),W.push(X)}}return this.createResult(W,K,C)}}function yq(q){let U={};for(let[Q,Z]of Object.entries(q))if(Z.url)U[Q]={url:Z.url};else if(Z.command)U[Q]={command:Z.command,...Z.args?{args:Z.args}:{},...Z.env?{env:Z.env}:{}};return{mcpServers:U}}function Fq(q){if(!q.default&&!q.small&&Object.keys(q.agents).length===0)return null;let U={description:"Model configuration and selection guidelines for this workspace",alwaysApply:!0},Q=[];if(Q.push("# Model Configuration"),Q.push(""),Q.push("Use the following model preferences when working in this project."),Q.push(""),q.default||q.small){if(Q.push("## Default Models"),Q.push(""),q.default)Q.push(`- **Primary model**: ${q.default}`);if(q.small)Q.push(`- **Lightweight tasks** (titles, summaries): ${q.small}`);Q.push("")}let Z=Object.entries(q.agents);if(Z.length>0){Q.push("## Agent Model Assignments"),Q.push(""),Q.push("| Agent | Model | Temperature |"),Q.push("| --- | --- | --- |");for(let[$,Y]of Z){let L=Y.temperature!==void 0?String(Y.temperature):"—";Q.push(`| ${$} | ${Y.model} | ${L} |`)}Q.push("")}if(Object.keys(q.profiles).length>0){Q.push("## Available Profiles"),Q.push(""),Q.push("| Profile | Description | Default Model |"),Q.push("| --- | --- | --- |");for(let[$,Y]of Object.entries(q.profiles))Q.push(`| ${$} | ${Y.description??"—"} | ${Y.default??"—"} |`);Q.push("")}if(q.activeProfile)Q.push(`**Active profile**: \`${q.activeProfile}\``),Q.push("");return A(U,Q.join(`
|
|
6
|
+
`))}export{Tq as CursorTarget};
|