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,1028 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
var TARGET_IDS = [
|
|
10
|
-
"opencode",
|
|
11
|
-
"cursor",
|
|
12
|
-
"claudecode",
|
|
13
|
-
"codexcli",
|
|
14
|
-
"mistralvibe",
|
|
15
|
-
"geminicli",
|
|
16
|
-
"copilot",
|
|
17
|
-
"agentsmd",
|
|
18
|
-
"cline",
|
|
19
|
-
"kilo",
|
|
20
|
-
"roo",
|
|
21
|
-
"qwencode",
|
|
22
|
-
"kiro",
|
|
23
|
-
"factorydroid",
|
|
24
|
-
"antigravity",
|
|
25
|
-
"junie",
|
|
26
|
-
"augmentcode",
|
|
27
|
-
"windsurf",
|
|
28
|
-
"warp",
|
|
29
|
-
"replit",
|
|
30
|
-
"zed"
|
|
31
|
-
];
|
|
32
|
-
var FEATURE_IDS = [
|
|
33
|
-
"rules",
|
|
34
|
-
"commands",
|
|
35
|
-
"agents",
|
|
36
|
-
"skills",
|
|
37
|
-
"hooks",
|
|
38
|
-
"plugins",
|
|
39
|
-
"mcp",
|
|
40
|
-
"ignore",
|
|
41
|
-
"models"
|
|
42
|
-
];
|
|
43
|
-
var REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
44
|
-
var PackManifestSchema = z.object({
|
|
45
|
-
name: z.string().min(1),
|
|
46
|
-
version: z.string().default("1.0.0"),
|
|
47
|
-
description: z.string().default(""),
|
|
48
|
-
author: z.union([
|
|
49
|
-
z.string(),
|
|
50
|
-
z.object({ name: z.string(), email: z.string().optional() })
|
|
51
|
-
]).optional(),
|
|
52
|
-
homepage: z.string().optional(),
|
|
53
|
-
repository: z.union([
|
|
54
|
-
z.string(),
|
|
55
|
-
z.object({ url: z.string(), type: z.string().optional() })
|
|
56
|
-
]).optional(),
|
|
57
|
-
license: z.string().optional(),
|
|
58
|
-
logo: z.string().optional(),
|
|
59
|
-
tags: z.array(z.string()).default([]),
|
|
60
|
-
dependencies: z.array(z.string()).default([]),
|
|
61
|
-
conflicts: z.array(z.string()).default([]),
|
|
62
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
63
|
-
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
64
|
-
});
|
|
65
|
-
var FeaturesSchema = z.union([
|
|
66
|
-
z.literal("*"),
|
|
67
|
-
z.array(z.string()),
|
|
68
|
-
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
69
|
-
]);
|
|
70
|
-
var WorkspaceConfigSchema = z.object({
|
|
71
|
-
$schema: z.string().optional(),
|
|
72
|
-
packs: z.array(z.string()).default(["./packs/default"]),
|
|
73
|
-
disabled: z.array(z.string()).default([]),
|
|
74
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
75
|
-
features: FeaturesSchema.default("*"),
|
|
76
|
-
mode: z.enum(REPO_MODES).default("repo"),
|
|
77
|
-
baseDirs: z.array(z.string()).default(["."]),
|
|
78
|
-
global: z.boolean().default(false),
|
|
79
|
-
delete: z.boolean().default(true),
|
|
80
|
-
verbose: z.boolean().default(false),
|
|
81
|
-
silent: z.boolean().default(false),
|
|
82
|
-
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
83
|
-
sources: z.array(z.object({
|
|
84
|
-
source: z.string(),
|
|
85
|
-
packs: z.array(z.string()).optional(),
|
|
86
|
-
skills: z.array(z.string()).optional()
|
|
87
|
-
})).default([]),
|
|
88
|
-
modelProfile: z.string().optional()
|
|
89
|
-
});
|
|
90
|
-
var CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
91
|
-
function loadWorkspaceConfig(projectRoot) {
|
|
92
|
-
for (const filename of CONFIG_FILES) {
|
|
93
|
-
const filepath = resolve(projectRoot, filename);
|
|
94
|
-
if (existsSync(filepath)) {
|
|
95
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
96
|
-
const parsed = parseJsonc(raw);
|
|
97
|
-
return WorkspaceConfigSchema.parse(parsed);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return WorkspaceConfigSchema.parse({});
|
|
101
|
-
}
|
|
102
|
-
function loadPackManifest(packDir) {
|
|
103
|
-
const filepath = resolve(packDir, "pack.json");
|
|
104
|
-
if (!existsSync(filepath)) {
|
|
105
|
-
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
106
|
-
return PackManifestSchema.parse({ name: dirName });
|
|
107
|
-
}
|
|
108
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
109
|
-
const parsed = JSON.parse(raw);
|
|
110
|
-
return PackManifestSchema.parse(parsed);
|
|
111
|
-
}
|
|
112
|
-
function resolveFeatures(config, targetId) {
|
|
113
|
-
const { features } = config;
|
|
114
|
-
if (features === "*") {
|
|
115
|
-
return [...FEATURE_IDS];
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(features)) {
|
|
118
|
-
if (features.includes("*"))
|
|
119
|
-
return [...FEATURE_IDS];
|
|
120
|
-
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
121
|
-
}
|
|
122
|
-
const targetFeatures = features[targetId];
|
|
123
|
-
if (!targetFeatures)
|
|
124
|
-
return [];
|
|
125
|
-
if (targetFeatures === "*")
|
|
126
|
-
return [...FEATURE_IDS];
|
|
127
|
-
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
128
|
-
return [...FEATURE_IDS];
|
|
129
|
-
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
130
|
-
}
|
|
131
|
-
function resolveTargets(config) {
|
|
132
|
-
if (config.targets === "*")
|
|
133
|
-
return [...TARGET_IDS];
|
|
134
|
-
return config.targets;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/utils/filesystem.ts
|
|
138
|
-
import {
|
|
139
|
-
existsSync as existsSync2,
|
|
140
|
-
mkdirSync,
|
|
141
|
-
readdirSync,
|
|
142
|
-
readFileSync as readFileSync2,
|
|
143
|
-
rmSync,
|
|
144
|
-
statSync,
|
|
145
|
-
writeFileSync
|
|
146
|
-
} from "fs";
|
|
147
|
-
import { dirname, join, relative } from "path";
|
|
148
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
149
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
150
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
151
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
152
|
-
const { header = true, type } = options;
|
|
153
|
-
const ext = type ?? inferFileType(filepath);
|
|
154
|
-
ensureDir(dirname(filepath));
|
|
155
|
-
let output = content;
|
|
156
|
-
if (header) {
|
|
157
|
-
const headerComment = getHeader(ext);
|
|
158
|
-
if (headerComment) {
|
|
159
|
-
output = `${headerComment}
|
|
160
|
-
${content}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
writeFileSync(filepath, output, "utf-8");
|
|
164
|
-
}
|
|
165
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
166
|
-
const json = JSON.stringify(data, null, 2);
|
|
167
|
-
writeGeneratedFile(filepath, json + `
|
|
168
|
-
`, { ...options, type: "json" });
|
|
169
|
-
}
|
|
170
|
-
function readFileOrNull(filepath) {
|
|
171
|
-
if (!existsSync2(filepath))
|
|
172
|
-
return null;
|
|
173
|
-
return readFileSync2(filepath, "utf-8");
|
|
174
|
-
}
|
|
175
|
-
function readJsonOrNull(filepath) {
|
|
176
|
-
const content = readFileOrNull(filepath);
|
|
177
|
-
if (content === null)
|
|
178
|
-
return null;
|
|
179
|
-
return JSON.parse(content);
|
|
180
|
-
}
|
|
181
|
-
function ensureDir(dirPath) {
|
|
182
|
-
if (!existsSync2(dirPath)) {
|
|
183
|
-
mkdirSync(dirPath, { recursive: true });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function removeIfExists(targetPath) {
|
|
187
|
-
if (existsSync2(targetPath)) {
|
|
188
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function listFiles(dirPath, options = {}) {
|
|
192
|
-
const { extension, recursive = false } = options;
|
|
193
|
-
if (!existsSync2(dirPath))
|
|
194
|
-
return [];
|
|
195
|
-
const results = [];
|
|
196
|
-
const entries = readdirSync(dirPath);
|
|
197
|
-
for (const entry of entries) {
|
|
198
|
-
const fullPath = join(dirPath, entry);
|
|
199
|
-
const stat = statSync(fullPath);
|
|
200
|
-
if (stat.isDirectory() && recursive) {
|
|
201
|
-
results.push(...listFiles(fullPath, options));
|
|
202
|
-
} else if (stat.isFile()) {
|
|
203
|
-
if (!extension || entry.endsWith(extension)) {
|
|
204
|
-
results.push(fullPath);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return results;
|
|
209
|
-
}
|
|
210
|
-
function listDirs(dirPath) {
|
|
211
|
-
if (!existsSync2(dirPath))
|
|
212
|
-
return [];
|
|
213
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
214
|
-
}
|
|
215
|
-
function relPath(projectRoot, filepath) {
|
|
216
|
-
return relative(projectRoot, filepath);
|
|
217
|
-
}
|
|
218
|
-
function isGeneratedFile(filepath) {
|
|
219
|
-
const content = readFileOrNull(filepath);
|
|
220
|
-
if (!content)
|
|
221
|
-
return false;
|
|
222
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
223
|
-
}
|
|
224
|
-
function inferFileType(filepath) {
|
|
225
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
226
|
-
return "json";
|
|
227
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
228
|
-
return "ts";
|
|
229
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
230
|
-
return "js";
|
|
231
|
-
return "md";
|
|
232
|
-
}
|
|
233
|
-
function getHeader(type) {
|
|
234
|
-
switch (type) {
|
|
235
|
-
case "md":
|
|
236
|
-
return GENERATED_HEADER_MD;
|
|
237
|
-
case "json":
|
|
238
|
-
return GENERATED_HEADER_JSON;
|
|
239
|
-
case "js":
|
|
240
|
-
case "ts":
|
|
241
|
-
return GENERATED_HEADER_JS;
|
|
242
|
-
default:
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/features/models.ts
|
|
248
|
-
import { join as join2 } from "path";
|
|
249
|
-
import { z as z2 } from "zod";
|
|
250
|
-
var SECRET_PATTERNS = [
|
|
251
|
-
/["']api[_-]?key["']\s*:/i,
|
|
252
|
-
/["']apiKey["']\s*:/i,
|
|
253
|
-
/["']secret["']\s*:/i,
|
|
254
|
-
/["']password["']\s*:/i,
|
|
255
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
256
|
-
/["']private[_-]?key["']\s*:/i,
|
|
257
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
258
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
259
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
260
|
-
];
|
|
261
|
-
var AgentModelSchema = z2.object({
|
|
262
|
-
model: z2.string(),
|
|
263
|
-
temperature: z2.number().min(0).max(2).optional(),
|
|
264
|
-
top_p: z2.number().min(0).max(1).optional()
|
|
265
|
-
});
|
|
266
|
-
var ModelProfileSchema = z2.object({
|
|
267
|
-
extends: z2.string().optional(),
|
|
268
|
-
description: z2.string().optional(),
|
|
269
|
-
default: z2.string().optional(),
|
|
270
|
-
small: z2.string().optional(),
|
|
271
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
272
|
-
});
|
|
273
|
-
var RoutingConditionSchema = z2.object({
|
|
274
|
-
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
275
|
-
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
276
|
-
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
277
|
-
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
278
|
-
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
279
|
-
});
|
|
280
|
-
var RoutingRuleSchema = z2.object({
|
|
281
|
-
when: z2.record(z2.string(), z2.string()),
|
|
282
|
-
use: z2.string(),
|
|
283
|
-
description: z2.string().optional(),
|
|
284
|
-
priority: z2.number().optional()
|
|
285
|
-
});
|
|
286
|
-
var ProviderModelSchema = z2.object({
|
|
287
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
288
|
-
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
289
|
-
});
|
|
290
|
-
var ProviderConfigSchema = z2.object({
|
|
291
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
292
|
-
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
293
|
-
});
|
|
294
|
-
var ModelsSchema = z2.object({
|
|
295
|
-
default: z2.string().optional(),
|
|
296
|
-
small: z2.string().optional(),
|
|
297
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
298
|
-
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
299
|
-
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
300
|
-
routing: z2.array(RoutingRuleSchema).optional(),
|
|
301
|
-
overrides: z2.record(z2.string(), z2.object({
|
|
302
|
-
default: z2.string().optional(),
|
|
303
|
-
small: z2.string().optional(),
|
|
304
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
305
|
-
})).optional()
|
|
306
|
-
});
|
|
307
|
-
function parseModels(packDir, packName) {
|
|
308
|
-
const modelsPath = join2(packDir, "models.json");
|
|
309
|
-
const raw = readJsonOrNull(modelsPath);
|
|
310
|
-
if (!raw)
|
|
311
|
-
return null;
|
|
312
|
-
const parsed = ModelsSchema.parse(raw);
|
|
313
|
-
return {
|
|
314
|
-
packName,
|
|
315
|
-
sourcePath: modelsPath,
|
|
316
|
-
config: parsed
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function mergeModelsConfigs(configs) {
|
|
320
|
-
const warnings = [];
|
|
321
|
-
const result = {};
|
|
322
|
-
for (const entry of configs) {
|
|
323
|
-
const { config, packName } = entry;
|
|
324
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
325
|
-
result.default = config.default;
|
|
326
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
327
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
328
|
-
}
|
|
329
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
330
|
-
result.small = config.small;
|
|
331
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
332
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
333
|
-
}
|
|
334
|
-
if (config.agents) {
|
|
335
|
-
if (!result.agents)
|
|
336
|
-
result.agents = {};
|
|
337
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
338
|
-
if (name in result.agents) {
|
|
339
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
result.agents[name] = assignment;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (config.profiles) {
|
|
346
|
-
if (!result.profiles)
|
|
347
|
-
result.profiles = {};
|
|
348
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
349
|
-
if (name in result.profiles) {
|
|
350
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
result.profiles[name] = profile;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (config.providers) {
|
|
357
|
-
if (!result.providers)
|
|
358
|
-
result.providers = {};
|
|
359
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
360
|
-
if (!(providerName in result.providers)) {
|
|
361
|
-
result.providers[providerName] = providerConfig;
|
|
362
|
-
} else {
|
|
363
|
-
const existing = result.providers[providerName];
|
|
364
|
-
if (!existing) {
|
|
365
|
-
result.providers[providerName] = providerConfig;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (providerConfig.options) {
|
|
369
|
-
existing.options = {
|
|
370
|
-
...providerConfig.options,
|
|
371
|
-
...existing.options
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
if (providerConfig.models) {
|
|
375
|
-
if (!existing.models)
|
|
376
|
-
existing.models = {};
|
|
377
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
378
|
-
if (!(modelName in existing.models)) {
|
|
379
|
-
existing.models[modelName] = modelConfig;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (config.routing) {
|
|
387
|
-
if (!result.routing)
|
|
388
|
-
result.routing = [];
|
|
389
|
-
result.routing.push(...config.routing);
|
|
390
|
-
}
|
|
391
|
-
if (config.overrides) {
|
|
392
|
-
if (!result.overrides)
|
|
393
|
-
result.overrides = {};
|
|
394
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
395
|
-
if (targetId in result.overrides) {
|
|
396
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
result.overrides[targetId] = override;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return { config: result, warnings };
|
|
404
|
-
}
|
|
405
|
-
function scanModelsForSecrets(config) {
|
|
406
|
-
const warnings = [];
|
|
407
|
-
const json = JSON.stringify(config);
|
|
408
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
409
|
-
if (pattern.test(json)) {
|
|
410
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return warnings;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/utils/frontmatter.ts
|
|
417
|
-
import matter from "gray-matter";
|
|
418
|
-
function parseFrontmatter(source) {
|
|
419
|
-
const { data, content } = matter(source);
|
|
420
|
-
return {
|
|
421
|
-
data,
|
|
422
|
-
content: content.trim(),
|
|
423
|
-
raw: source
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function serializeFrontmatter(data, content) {
|
|
427
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
428
|
-
if (Object.keys(filtered).length === 0) {
|
|
429
|
-
return content;
|
|
430
|
-
}
|
|
431
|
-
return matter.stringify(content, filtered);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// src/features/agents.ts
|
|
435
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
436
|
-
import { basename } from "path";
|
|
437
|
-
function parseAgents(agentsDir, packName) {
|
|
438
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
439
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
440
|
-
}
|
|
441
|
-
function parseAgentFile(filepath, packName) {
|
|
442
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
443
|
-
const { data, content } = parseFrontmatter(raw);
|
|
444
|
-
return {
|
|
445
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
446
|
-
sourcePath: filepath,
|
|
447
|
-
packName,
|
|
448
|
-
meta: data,
|
|
449
|
-
content
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
function agentMatchesTarget(agent, targetId) {
|
|
453
|
-
const { targets } = agent.meta;
|
|
454
|
-
if (!targets || targets === "*")
|
|
455
|
-
return true;
|
|
456
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
457
|
-
return true;
|
|
458
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// src/features/commands.ts
|
|
462
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
463
|
-
import { basename as basename2 } from "path";
|
|
464
|
-
function parseCommands(commandsDir, packName) {
|
|
465
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
466
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
467
|
-
}
|
|
468
|
-
function parseCommandFile(filepath, packName) {
|
|
469
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
470
|
-
const { data, content } = parseFrontmatter(raw);
|
|
471
|
-
return {
|
|
472
|
-
name: basename2(filepath, ".md"),
|
|
473
|
-
sourcePath: filepath,
|
|
474
|
-
packName,
|
|
475
|
-
meta: data,
|
|
476
|
-
content
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
480
|
-
const { targets } = cmd.meta;
|
|
481
|
-
if (!targets || targets === "*")
|
|
482
|
-
return true;
|
|
483
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
484
|
-
return true;
|
|
485
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// src/features/hooks.ts
|
|
489
|
-
import { join as join3 } from "path";
|
|
490
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
491
|
-
function parseHooks(packDir, packName) {
|
|
492
|
-
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
493
|
-
const raw = readJsonOrNull(hooksPath);
|
|
494
|
-
if (!raw)
|
|
495
|
-
return null;
|
|
496
|
-
const shared = raw.hooks ?? {};
|
|
497
|
-
const targetOverrides = {};
|
|
498
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
499
|
-
const override = raw[key];
|
|
500
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
501
|
-
targetOverrides[key] = override.hooks;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return {
|
|
505
|
-
packName,
|
|
506
|
-
sourcePath: hooksPath,
|
|
507
|
-
version: raw.version,
|
|
508
|
-
shared,
|
|
509
|
-
targetOverrides
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
513
|
-
const merged = {};
|
|
514
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
515
|
-
merged[event] = [...entries];
|
|
516
|
-
}
|
|
517
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
518
|
-
if (overrides) {
|
|
519
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
520
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return merged;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// src/features/ignore.ts
|
|
527
|
-
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
528
|
-
import { join as join4 } from "path";
|
|
529
|
-
var IGNORE_FILES = ["ignore", ".aiignore"];
|
|
530
|
-
function parseIgnore(packDir, packName) {
|
|
531
|
-
for (const filename of IGNORE_FILES) {
|
|
532
|
-
const filepath = join4(packDir, filename);
|
|
533
|
-
if (existsSync3(filepath)) {
|
|
534
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
535
|
-
const patterns = parseIgnoreContent(raw);
|
|
536
|
-
return {
|
|
537
|
-
packName,
|
|
538
|
-
sourcePath: filepath,
|
|
539
|
-
patterns
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return null;
|
|
544
|
-
}
|
|
545
|
-
function parseIgnoreContent(content) {
|
|
546
|
-
return content.split(`
|
|
547
|
-
`).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
548
|
-
}
|
|
549
|
-
function mergeIgnorePatterns(configs) {
|
|
550
|
-
const seen = new Set;
|
|
551
|
-
const result = [];
|
|
552
|
-
for (const config of configs) {
|
|
553
|
-
for (const pattern of config.patterns) {
|
|
554
|
-
if (!seen.has(pattern)) {
|
|
555
|
-
seen.add(pattern);
|
|
556
|
-
result.push(pattern);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// src/features/mcp.ts
|
|
564
|
-
import { join as join5 } from "path";
|
|
565
|
-
function parseMcp(packDir, packName) {
|
|
566
|
-
const mcpPath = join5(packDir, "mcp.json");
|
|
567
|
-
const raw = readJsonOrNull(mcpPath);
|
|
568
|
-
if (!raw?.mcpServers)
|
|
569
|
-
return null;
|
|
570
|
-
return {
|
|
571
|
-
packName,
|
|
572
|
-
sourcePath: mcpPath,
|
|
573
|
-
servers: raw.mcpServers
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
function mergeMcpConfigs(configs) {
|
|
577
|
-
const servers = {};
|
|
578
|
-
const warnings = [];
|
|
579
|
-
for (const config of configs) {
|
|
580
|
-
for (const [name, entry] of Object.entries(config.servers)) {
|
|
581
|
-
if (name in servers) {
|
|
582
|
-
warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
|
|
583
|
-
continue;
|
|
584
|
-
}
|
|
585
|
-
servers[name] = entry;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
return { servers, warnings };
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// src/features/plugins.ts
|
|
592
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
593
|
-
import { basename as basename3, join as join6 } from "path";
|
|
594
|
-
function parsePlugins(packDir, packName) {
|
|
595
|
-
const pluginsDir = join6(packDir, "plugins");
|
|
596
|
-
if (!existsSync4(pluginsDir))
|
|
597
|
-
return [];
|
|
598
|
-
const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
|
|
599
|
-
const jsFiles = listFiles(pluginsDir, { extension: ".js" });
|
|
600
|
-
const allFiles = [...tsFiles, ...jsFiles];
|
|
601
|
-
return allFiles.map((filepath) => parsePluginFile(filepath, packName));
|
|
602
|
-
}
|
|
603
|
-
function parsePluginFile(filepath, packName) {
|
|
604
|
-
const content = readFileSync6(filepath, "utf-8");
|
|
605
|
-
const ext = filepath.endsWith(".ts") ? "ts" : "js";
|
|
606
|
-
return {
|
|
607
|
-
name: basename3(filepath, `.${ext}`),
|
|
608
|
-
sourcePath: filepath,
|
|
609
|
-
packName,
|
|
610
|
-
content,
|
|
611
|
-
extension: ext
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// src/features/rules.ts
|
|
616
|
-
import { readFileSync as readFileSync7 } from "fs";
|
|
617
|
-
import { basename as basename4 } from "path";
|
|
618
|
-
function parseRules(rulesDir, packName) {
|
|
619
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
620
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
621
|
-
}
|
|
622
|
-
function parseRuleFile(filepath, packName) {
|
|
623
|
-
const raw = readFileSync7(filepath, "utf-8");
|
|
624
|
-
const { data, content } = parseFrontmatter(raw);
|
|
625
|
-
return {
|
|
626
|
-
name: basename4(filepath, ".md"),
|
|
627
|
-
sourcePath: filepath,
|
|
628
|
-
packName,
|
|
629
|
-
meta: data,
|
|
630
|
-
content
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
634
|
-
const { targets } = rule.meta;
|
|
635
|
-
if (!targets || targets === "*")
|
|
636
|
-
return true;
|
|
637
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
638
|
-
return true;
|
|
639
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
640
|
-
}
|
|
641
|
-
function getRootRules(rules) {
|
|
642
|
-
return rules.filter((r) => r.meta.root === true);
|
|
643
|
-
}
|
|
644
|
-
function getDetailRules(rules) {
|
|
645
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// src/features/skills.ts
|
|
649
|
-
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
650
|
-
import { basename as basename5, join as join7 } from "path";
|
|
651
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
652
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
653
|
-
function parseSkills(skillsDir, packName) {
|
|
654
|
-
const dirs = listDirs(skillsDir);
|
|
655
|
-
const skills = [];
|
|
656
|
-
for (const dir of dirs) {
|
|
657
|
-
const skillMd = join7(dir, "SKILL.md");
|
|
658
|
-
if (existsSync5(skillMd)) {
|
|
659
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return skills;
|
|
663
|
-
}
|
|
664
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
665
|
-
const raw = readFileSync8(filepath, "utf-8");
|
|
666
|
-
const { data, content } = parseFrontmatter(raw);
|
|
667
|
-
return {
|
|
668
|
-
name: data.name ?? basename5(skillDir),
|
|
669
|
-
sourcePath: filepath,
|
|
670
|
-
sourceDir: skillDir,
|
|
671
|
-
packName,
|
|
672
|
-
meta: data,
|
|
673
|
-
content
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
function buildSkillFrontmatter(skill) {
|
|
677
|
-
return {
|
|
678
|
-
...skill.meta,
|
|
679
|
-
name: skill.name
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
function serializeSkill(skill) {
|
|
683
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
684
|
-
}
|
|
685
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
686
|
-
const { data, content } = parseFrontmatter(source);
|
|
687
|
-
const normalized = {
|
|
688
|
-
...data,
|
|
689
|
-
name: skillName
|
|
690
|
-
};
|
|
691
|
-
let addedDescription = false;
|
|
692
|
-
const description = normalized.description;
|
|
693
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
694
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
695
|
-
addedDescription = true;
|
|
696
|
-
}
|
|
697
|
-
return {
|
|
698
|
-
content: serializeFrontmatter(normalized, content),
|
|
699
|
-
addedDescription
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
703
|
-
const errors = [];
|
|
704
|
-
const dirName = basename5(skill.sourceDir);
|
|
705
|
-
const declaredName = skill.meta.name;
|
|
706
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
707
|
-
errors.push('Missing required frontmatter field "name".');
|
|
708
|
-
} else {
|
|
709
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
710
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
711
|
-
}
|
|
712
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
713
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
714
|
-
}
|
|
715
|
-
if (declaredName !== dirName) {
|
|
716
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
const description = skill.meta.description;
|
|
720
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
721
|
-
errors.push('Missing required frontmatter field "description".');
|
|
722
|
-
}
|
|
723
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
724
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
725
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
726
|
-
}
|
|
727
|
-
return errors;
|
|
728
|
-
}
|
|
729
|
-
function skillMatchesTarget(skill, targetId) {
|
|
730
|
-
const { targets } = skill.meta;
|
|
731
|
-
if (!targets || targets === "*")
|
|
732
|
-
return true;
|
|
733
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
734
|
-
return true;
|
|
735
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// src/core/pack-loader.ts
|
|
739
|
-
import { existsSync as existsSync6 } from "fs";
|
|
740
|
-
import { isAbsolute, resolve as resolve2 } from "path";
|
|
741
|
-
class PackLoader {
|
|
742
|
-
projectRoot;
|
|
743
|
-
config;
|
|
744
|
-
constructor(projectRoot, config) {
|
|
745
|
-
this.projectRoot = projectRoot;
|
|
746
|
-
this.config = config;
|
|
747
|
-
}
|
|
748
|
-
loadAll() {
|
|
749
|
-
const warnings = [];
|
|
750
|
-
const packs = [];
|
|
751
|
-
const disabledSet = new Set(this.config.disabled);
|
|
752
|
-
for (const packRef of this.config.packs) {
|
|
753
|
-
const packDir = this.resolvePackPath(packRef);
|
|
754
|
-
if (!packDir) {
|
|
755
|
-
warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
|
|
756
|
-
continue;
|
|
757
|
-
}
|
|
758
|
-
if (!existsSync6(packDir)) {
|
|
759
|
-
warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
|
|
760
|
-
continue;
|
|
761
|
-
}
|
|
762
|
-
const manifest = loadPackManifest(packDir);
|
|
763
|
-
if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
|
|
764
|
-
continue;
|
|
765
|
-
}
|
|
766
|
-
const loaded = this.loadPack(packDir, manifest);
|
|
767
|
-
packs.push(loaded);
|
|
768
|
-
}
|
|
769
|
-
return { packs, warnings };
|
|
770
|
-
}
|
|
771
|
-
loadPack(packDir, manifest) {
|
|
772
|
-
const name = manifest.name;
|
|
773
|
-
const rulesDir = resolve2(packDir, "rules");
|
|
774
|
-
const commandsDir = resolve2(packDir, "commands");
|
|
775
|
-
const agentsDir = resolve2(packDir, "agents");
|
|
776
|
-
const skillsDir = resolve2(packDir, "skills");
|
|
777
|
-
return {
|
|
778
|
-
manifest,
|
|
779
|
-
directory: packDir,
|
|
780
|
-
rules: existsSync6(rulesDir) ? parseRules(rulesDir, name) : [],
|
|
781
|
-
commands: existsSync6(commandsDir) ? parseCommands(commandsDir, name) : [],
|
|
782
|
-
agents: existsSync6(agentsDir) ? parseAgents(agentsDir, name) : [],
|
|
783
|
-
skills: existsSync6(skillsDir) ? parseSkills(skillsDir, name) : [],
|
|
784
|
-
hooks: parseHooks(packDir, name),
|
|
785
|
-
plugins: parsePlugins(packDir, name),
|
|
786
|
-
mcp: parseMcp(packDir, name),
|
|
787
|
-
ignore: parseIgnore(packDir, name),
|
|
788
|
-
models: parseModels(packDir, name)
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
loadForBaseDir(baseDir) {
|
|
792
|
-
const baseDirRoot = resolve2(this.projectRoot, baseDir);
|
|
793
|
-
const localConfigPath = resolve2(baseDirRoot, "agentpacks.jsonc");
|
|
794
|
-
if (!existsSync6(localConfigPath)) {
|
|
795
|
-
return { packs: [], warnings: [] };
|
|
796
|
-
}
|
|
797
|
-
const localConfig = loadWorkspaceConfig(baseDirRoot);
|
|
798
|
-
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
799
|
-
return loader.loadAll();
|
|
800
|
-
}
|
|
801
|
-
resolveCuratedPack(packRef) {
|
|
802
|
-
const curatedDir = resolve2(this.projectRoot, ".agentpacks", ".curated");
|
|
803
|
-
let packName = packRef;
|
|
804
|
-
if (packName.startsWith("registry:"))
|
|
805
|
-
packName = packName.slice(9);
|
|
806
|
-
if (packName.startsWith("npm:"))
|
|
807
|
-
packName = packName.slice(4);
|
|
808
|
-
if (packName.startsWith("github:"))
|
|
809
|
-
packName = packName.slice(7);
|
|
810
|
-
if (packName.startsWith("@"))
|
|
811
|
-
packName = packName.slice(1);
|
|
812
|
-
if (packName.includes("/")) {
|
|
813
|
-
const parts = packName.split("/");
|
|
814
|
-
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
815
|
-
}
|
|
816
|
-
const withoutVersion = packName.split("@")[0] ?? packName;
|
|
817
|
-
packName = withoutVersion.split(":")[0] ?? withoutVersion;
|
|
818
|
-
const resolved = resolve2(curatedDir, packName);
|
|
819
|
-
return existsSync6(resolved) ? resolved : null;
|
|
820
|
-
}
|
|
821
|
-
resolvePackPath(packRef) {
|
|
822
|
-
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
823
|
-
return resolve2(this.projectRoot, packRef);
|
|
824
|
-
}
|
|
825
|
-
if (isAbsolute(packRef)) {
|
|
826
|
-
return packRef;
|
|
827
|
-
}
|
|
828
|
-
if (packRef.startsWith("registry:")) {
|
|
829
|
-
return this.resolveCuratedPack(packRef);
|
|
830
|
-
}
|
|
831
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
832
|
-
return this.resolveCuratedPack(packRef);
|
|
833
|
-
}
|
|
834
|
-
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
835
|
-
return this.resolveCuratedPack(packRef);
|
|
836
|
-
}
|
|
837
|
-
return resolve2(this.projectRoot, packRef);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// src/exporters/cursor-plugin.ts
|
|
842
|
-
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
843
|
-
import { join as join8, resolve as resolve3 } from "path";
|
|
844
|
-
function exportCursorPlugin(pack, outputDir) {
|
|
845
|
-
const filesWritten = [];
|
|
846
|
-
const pluginName = normalizeCursorPluginName(pack.manifest.name);
|
|
847
|
-
const pluginDir = resolve3(outputDir, pluginName);
|
|
848
|
-
mkdirSync2(pluginDir, { recursive: true });
|
|
849
|
-
const manifest = {
|
|
850
|
-
name: pluginName
|
|
851
|
-
};
|
|
852
|
-
if (pack.manifest.version) {
|
|
853
|
-
manifest.version = pack.manifest.version;
|
|
854
|
-
}
|
|
855
|
-
if (pack.manifest.description) {
|
|
856
|
-
manifest.description = pack.manifest.description;
|
|
857
|
-
}
|
|
858
|
-
const author = toCursorPluginAuthor(pack.manifest.author);
|
|
859
|
-
if (author) {
|
|
860
|
-
manifest.author = author;
|
|
861
|
-
}
|
|
862
|
-
if (pack.manifest.homepage) {
|
|
863
|
-
manifest.homepage = pack.manifest.homepage;
|
|
864
|
-
}
|
|
865
|
-
if (pack.manifest.repository) {
|
|
866
|
-
manifest.repository = typeof pack.manifest.repository === "string" ? pack.manifest.repository : pack.manifest.repository.url;
|
|
867
|
-
}
|
|
868
|
-
if (pack.manifest.license) {
|
|
869
|
-
manifest.license = pack.manifest.license;
|
|
870
|
-
}
|
|
871
|
-
if (pack.manifest.logo) {
|
|
872
|
-
manifest.logo = pack.manifest.logo;
|
|
873
|
-
}
|
|
874
|
-
if (pack.manifest.tags.length > 0) {
|
|
875
|
-
manifest.keywords = pack.manifest.tags;
|
|
876
|
-
}
|
|
877
|
-
if (pack.rules.length > 0) {
|
|
878
|
-
const rulesDir = join8(pluginDir, "rules");
|
|
879
|
-
ensureDir(rulesDir);
|
|
880
|
-
manifest.rules = "rules";
|
|
881
|
-
for (const rule of pack.rules) {
|
|
882
|
-
const cursorMeta = rule.meta.cursor ?? {};
|
|
883
|
-
const fm = {
|
|
884
|
-
description: cursorMeta.description ?? rule.meta.description ?? "",
|
|
885
|
-
alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
|
|
886
|
-
};
|
|
887
|
-
const globs = cursorMeta.globs ?? rule.meta.globs;
|
|
888
|
-
if (globs)
|
|
889
|
-
fm.globs = globs;
|
|
890
|
-
const filename = `${rule.name}.mdc`;
|
|
891
|
-
const filepath = join8(rulesDir, filename);
|
|
892
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, rule.content));
|
|
893
|
-
filesWritten.push(filepath);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
if (pack.agents.length > 0) {
|
|
897
|
-
const agentsDir = join8(pluginDir, "agents");
|
|
898
|
-
ensureDir(agentsDir);
|
|
899
|
-
manifest.agents = "agents";
|
|
900
|
-
for (const agent of pack.agents) {
|
|
901
|
-
const fm = {
|
|
902
|
-
name: agent.name,
|
|
903
|
-
description: agent.meta.description ?? ""
|
|
904
|
-
};
|
|
905
|
-
const filename = `${agent.name}.md`;
|
|
906
|
-
const filepath = join8(agentsDir, filename);
|
|
907
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, agent.content));
|
|
908
|
-
filesWritten.push(filepath);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
if (pack.skills.length > 0) {
|
|
912
|
-
const skillsDir = join8(pluginDir, "skills");
|
|
913
|
-
ensureDir(skillsDir);
|
|
914
|
-
manifest.skills = "skills";
|
|
915
|
-
for (const skill of pack.skills) {
|
|
916
|
-
const skillSubDir = join8(skillsDir, skill.name);
|
|
917
|
-
ensureDir(skillSubDir);
|
|
918
|
-
const filepath = join8(skillSubDir, "SKILL.md");
|
|
919
|
-
const content = serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
920
|
-
writeFileSync2(filepath, content);
|
|
921
|
-
filesWritten.push(filepath);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
if (pack.commands.length > 0) {
|
|
925
|
-
const commandsDir = join8(pluginDir, "commands");
|
|
926
|
-
ensureDir(commandsDir);
|
|
927
|
-
manifest.commands = "commands";
|
|
928
|
-
for (const cmd of pack.commands) {
|
|
929
|
-
const fm = {
|
|
930
|
-
name: cmd.name
|
|
931
|
-
};
|
|
932
|
-
if (cmd.meta.description) {
|
|
933
|
-
fm.description = cmd.meta.description;
|
|
934
|
-
}
|
|
935
|
-
const filename = `${cmd.name}.md`;
|
|
936
|
-
const filepath = join8(commandsDir, filename);
|
|
937
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, cmd.content));
|
|
938
|
-
filesWritten.push(filepath);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
if (pack.hooks) {
|
|
942
|
-
const events = resolveHooksForTarget(pack.hooks, "cursor");
|
|
943
|
-
if (Object.keys(events).length > 0) {
|
|
944
|
-
const hooksDir = join8(pluginDir, "hooks");
|
|
945
|
-
ensureDir(hooksDir);
|
|
946
|
-
const filepath = join8(hooksDir, "hooks.json");
|
|
947
|
-
writeFileSync2(filepath, JSON.stringify({ version: pack.hooks.version ?? 1, hooks: events }, null, 2) + `
|
|
948
|
-
`);
|
|
949
|
-
filesWritten.push(filepath);
|
|
950
|
-
manifest.hooks = "hooks/hooks.json";
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
if (pack.mcp && Object.keys(pack.mcp.servers).length > 0) {
|
|
954
|
-
manifest.mcpServers = ".mcp.json";
|
|
955
|
-
const filepath = join8(pluginDir, ".mcp.json");
|
|
956
|
-
writeFileSync2(filepath, JSON.stringify({ mcpServers: pack.mcp.servers }, null, 2) + `
|
|
957
|
-
`);
|
|
958
|
-
filesWritten.push(filepath);
|
|
959
|
-
}
|
|
960
|
-
const manifestDir = join8(pluginDir, ".cursor-plugin");
|
|
961
|
-
ensureDir(manifestDir);
|
|
962
|
-
const manifestPath = join8(manifestDir, "plugin.json");
|
|
963
|
-
writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2) + `
|
|
964
|
-
`);
|
|
965
|
-
filesWritten.push(manifestPath);
|
|
966
|
-
return { outputDir: pluginDir, filesWritten, manifest };
|
|
967
|
-
}
|
|
968
|
-
function normalizeCursorPluginName(name) {
|
|
969
|
-
const normalized = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/-+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[^a-z0-9]+$/, "");
|
|
970
|
-
return normalized.length > 0 ? normalized : "agentpacks-plugin";
|
|
971
|
-
}
|
|
972
|
-
function toCursorPluginAuthor(author) {
|
|
973
|
-
if (!author) {
|
|
974
|
-
return null;
|
|
975
|
-
}
|
|
976
|
-
if (typeof author === "string") {
|
|
977
|
-
return { name: author };
|
|
978
|
-
}
|
|
979
|
-
return {
|
|
980
|
-
name: author.name,
|
|
981
|
-
...author.email ? { email: author.email } : {}
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
// src/cli/export-cmd.ts
|
|
986
|
-
import chalk from "chalk";
|
|
987
|
-
import { resolve as resolve4 } from "path";
|
|
988
|
-
function runExport(projectRoot, options) {
|
|
989
|
-
const config = loadWorkspaceConfig(projectRoot);
|
|
990
|
-
const verbose = options.verbose ?? config.verbose;
|
|
991
|
-
const loader = new PackLoader(projectRoot, config);
|
|
992
|
-
const { packs, warnings: loadWarnings } = loader.loadAll();
|
|
993
|
-
for (const w of loadWarnings) {
|
|
994
|
-
console.log(chalk.yellow(` warn: ${w}`));
|
|
995
|
-
}
|
|
996
|
-
if (packs.length === 0) {
|
|
997
|
-
console.log(chalk.red("No packs loaded. Nothing to export."));
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
const packsToExport = options.pack ? packs.filter((p) => p.manifest.name === options.pack) : packs;
|
|
1001
|
-
if (packsToExport.length === 0) {
|
|
1002
|
-
console.log(chalk.red(`Pack "${options.pack}" not found.`));
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
const outputDir = resolve4(projectRoot, options.output ?? "dist/cursor-plugins");
|
|
1006
|
-
switch (options.format) {
|
|
1007
|
-
case "cursor-plugin": {
|
|
1008
|
-
let totalFiles = 0;
|
|
1009
|
-
for (const pack of packsToExport) {
|
|
1010
|
-
if (verbose) {
|
|
1011
|
-
console.log(chalk.dim(` Exporting ${pack.manifest.name}...`));
|
|
1012
|
-
}
|
|
1013
|
-
const result = exportCursorPlugin(pack, outputDir);
|
|
1014
|
-
totalFiles += result.filesWritten.length;
|
|
1015
|
-
if (verbose) {
|
|
1016
|
-
console.log(chalk.dim(` ${result.filesWritten.length} file(s) written`));
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
console.log(chalk.green(`Exported ${packsToExport.length} pack(s) as Cursor plugins (${totalFiles} files) to ${outputDir}`));
|
|
1020
|
-
break;
|
|
1021
|
-
}
|
|
1022
|
-
default:
|
|
1023
|
-
console.log(chalk.red(`Unknown export format: "${options.format}". Supported: cursor-plugin`));
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
export {
|
|
1027
|
-
runExport
|
|
1028
|
-
};
|
|
1
|
+
import{createRequire as W0}from"node:module";var C$=W0(import.meta.url);import{existsSync as g,readFileSync as R}from"fs";import{parse as J0}from"jsonc-parser";import{resolve as D}from"path";import{z as Y}from"zod";var U0=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],T=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],H0=["repo","monorepo","metarepo"],S=Y.object({name:Y.string().min(1),version:Y.string().default("1.0.0"),description:Y.string().default(""),author:Y.union([Y.string(),Y.object({name:Y.string(),email:Y.string().optional()})]).optional(),homepage:Y.string().optional(),repository:Y.union([Y.string(),Y.object({url:Y.string(),type:Y.string().optional()})]).optional(),license:Y.string().optional(),logo:Y.string().optional(),tags:Y.array(Y.string()).default([]),dependencies:Y.array(Y.string()).default([]),conflicts:Y.array(Y.string()).default([]),targets:Y.union([Y.literal("*"),Y.array(Y.string())]).default("*"),features:Y.union([Y.literal("*"),Y.array(Y.string())]).default("*")}),O0=Y.union([Y.literal("*"),Y.array(Y.string()),Y.record(Y.string(),Y.union([Y.literal("*"),Y.array(Y.string())]))]),m=Y.object({$schema:Y.string().optional(),packs:Y.array(Y.string()).default(["./packs/default"]),disabled:Y.array(Y.string()).default([]),targets:Y.union([Y.literal("*"),Y.array(Y.string())]).default("*"),features:O0.default("*"),mode:Y.enum(H0).default("repo"),baseDirs:Y.array(Y.string()).default(["."]),global:Y.boolean().default(!1),delete:Y.boolean().default(!0),verbose:Y.boolean().default(!1),silent:Y.boolean().default(!1),overrides:Y.record(Y.string(),Y.record(Y.string(),Y.string())).default({}),sources:Y.array(Y.object({source:Y.string(),packs:Y.array(Y.string()).optional(),skills:Y.array(Y.string()).optional()})).default([]),modelProfile:Y.string().optional()}),C0=["agentpacks.local.jsonc","agentpacks.jsonc"];function j($){for(let B of C0){let q=D($,B);if(g(q)){let Z=R(q,"utf-8"),Q=J0(Z);return m.parse(Q)}}return m.parse({})}function N($){let B=D($,"pack.json");if(!g(B)){let Q=$.split("/").pop()??"unknown";return S.parse({name:Q})}let q=R(B,"utf-8"),Z=JSON.parse(q);return S.parse(Z)}function A$($,B){let{features:q}=$;if(q==="*")return[...T];if(Array.isArray(q)){if(q.includes("*"))return[...T];return q.filter((Q)=>T.includes(Q))}let Z=q[B];if(!Z)return[];if(Z==="*")return[...T];if(Array.isArray(Z)&&Z.includes("*"))return[...T];return Z.filter((Q)=>T.includes(Q))}function x$($){if($.targets==="*")return[...U0];return $.targets}import{existsSync as _,mkdirSync as b0,readdirSync as h,readFileSync as G0,rmSync as M0,statSync as d,writeFileSync as w0}from"fs";import{dirname as u0,join as o,relative as A0}from"path";var z="<!-- Generated by agentpacks. DO NOT EDIT. -->",f="// Generated by agentpacks. DO NOT EDIT.",k="// Generated by agentpacks. DO NOT EDIT.";function x0($,B,q={}){let{header:Z=!0,type:Q}=q,K=Q??y0($);b(u0($));let X=B;if(Z){let V=P0(K);if(V)X=`${V}
|
|
2
|
+
${B}`}w0($,X,"utf-8")}function I$($,B,q={}){let Z=JSON.stringify(B,null,2);x0($,Z+`
|
|
3
|
+
`,{...q,type:"json"})}function s($){if(!_($))return null;return G0($,"utf-8")}function I($){let B=s($);if(B===null)return null;return JSON.parse(B)}function b($){if(!_($))b0($,{recursive:!0})}function _$($){if(_($))M0($,{recursive:!0,force:!0})}function G($,B={}){let{extension:q,recursive:Z=!1}=B;if(!_($))return[];let Q=[],K=h($);for(let X of K){let V=o($,X),O=d(V);if(O.isDirectory()&&Z)Q.push(...G(V,B));else if(O.isFile()){if(!q||X.endsWith(q))Q.push(V)}}return Q}function c($){if(!_($))return[];return h($).map((B)=>o($,B)).filter((B)=>d(B).isDirectory())}function j$($,B){return A0($,B)}function v$($){let B=s($);if(!B)return!1;return B.startsWith(z)||B.startsWith(f)||B.startsWith(k)}function y0($){if($.endsWith(".json")||$.endsWith(".jsonc"))return"json";if($.endsWith(".ts")||$.endsWith(".mts"))return"ts";if($.endsWith(".js")||$.endsWith(".mjs"))return"js";return"md"}function P0($){switch($){case"md":return z;case"json":return f;case"js":case"ts":return k;default:return null}}import{join as T0}from"path";import{z as L}from"zod";var I0=[/["']api[_-]?key["']\s*:/i,/["']apiKey["']\s*:/i,/["']secret["']\s*:/i,/["']password["']\s*:/i,/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,/["']private[_-]?key["']\s*:/i,/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,/sk-[a-zA-Z0-9]{20,}/,/Bearer\s+[a-zA-Z0-9._-]{20,}/],F=L.object({model:L.string(),temperature:L.number().min(0).max(2).optional(),top_p:L.number().min(0).max(1).optional()}),_0=L.object({extends:L.string().optional(),description:L.string().optional(),default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),F).optional()}),m$=L.object({complexity:L.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:L.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:L.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:L.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:L.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),j0=L.object({when:L.record(L.string(),L.string()),use:L.string(),description:L.string().optional(),priority:L.number().optional()}),v0=L.object({options:L.record(L.string(),L.unknown()).optional(),variants:L.record(L.string(),L.record(L.string(),L.unknown())).optional()}),F0=L.object({options:L.record(L.string(),L.unknown()).optional(),models:L.record(L.string(),v0).optional()}),n0=L.object({default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),F).optional(),profiles:L.record(L.string(),_0).optional(),providers:L.record(L.string(),F0).optional(),routing:L.array(j0).optional(),overrides:L.record(L.string(),L.object({default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),F).optional()})).optional()});function i($,B){let q=T0($,"models.json"),Z=I(q);if(!Z)return null;let Q=n0.parse(Z);return{packName:B,sourcePath:q,config:Q}}function g$($){let B=[],q={};for(let Z of $){let{config:Q,packName:K}=Z;if(Q.default!==void 0&&q.default===void 0)q.default=Q.default;else if(Q.default!==void 0&&q.default!==void 0)B.push(`Models "default" from pack "${K}" skipped (already defined).`);if(Q.small!==void 0&&q.small===void 0)q.small=Q.small;else if(Q.small!==void 0&&q.small!==void 0)B.push(`Models "small" from pack "${K}" skipped (already defined).`);if(Q.agents){if(!q.agents)q.agents={};for(let[X,V]of Object.entries(Q.agents)){if(X in q.agents){B.push(`Models agent "${X}" from pack "${K}" skipped (already defined).`);continue}q.agents[X]=V}}if(Q.profiles){if(!q.profiles)q.profiles={};for(let[X,V]of Object.entries(Q.profiles)){if(X in q.profiles){B.push(`Models profile "${X}" from pack "${K}" skipped (already defined).`);continue}q.profiles[X]=V}}if(Q.providers){if(!q.providers)q.providers={};for(let[X,V]of Object.entries(Q.providers))if(!(X in q.providers))q.providers[X]=V;else{let O=q.providers[X];if(!O){q.providers[X]=V;continue}if(V.options)O.options={...V.options,...O.options};if(V.models){if(!O.models)O.models={};for(let[J,W]of Object.entries(V.models))if(!(J in O.models))O.models[J]=W}}}if(Q.routing){if(!q.routing)q.routing=[];q.routing.push(...Q.routing)}if(Q.overrides){if(!q.overrides)q.overrides={};for(let[X,V]of Object.entries(Q.overrides)){if(X in q.overrides){B.push(`Models override for target "${X}" from pack "${K}" skipped (already defined).`);continue}q.overrides[X]=V}}}return{config:q,warnings:B}}function R$($){let B=[],q=JSON.stringify($);for(let Z of I0)if(Z.test(q))B.push(`Potential secret detected in models.json matching pattern: ${Z.source}`);return B}import l from"gray-matter";function u($){let{data:B,content:q}=l($);return{data:B,content:q.trim(),raw:$}}function A($,B){let q=Object.fromEntries(Object.entries($).filter(([,Z])=>Z!==void 0));if(Object.keys(q).length===0)return B;return l.stringify(B,q)}import{readFileSync as E0}from"fs";import{basename as S0}from"path";function p($,B){return G($,{extension:".md"}).map((Z)=>m0(Z,B))}function m0($,B){let q=E0($,"utf-8"),{data:Z,content:Q}=u(q);return{name:Z.name??S0($,".md"),sourcePath:$,packName:B,meta:Z,content:Q}}function k$($,B){let{targets:q}=$.meta;if(!q||q==="*")return!0;if(Array.isArray(q)&&q.includes("*"))return!0;return Array.isArray(q)&&q.includes(B)}import{readFileSync as g0}from"fs";import{basename as R0}from"path";function r($,B){return G($,{extension:".md"}).map((Z)=>D0(Z,B))}function D0($,B){let q=g0($,"utf-8"),{data:Z,content:Q}=u(q);return{name:R0($,".md"),sourcePath:$,packName:B,meta:Z,content:Q}}function r$($,B){let{targets:q}=$.meta;if(!q||q==="*")return!0;if(Array.isArray(q)&&q.includes("*"))return!0;return Array.isArray(q)&&q.includes(B)}import{join as N0}from"path";var h0=["cursor","claudecode","codexcli","opencode"];function t($,B){let q=N0($,"hooks","hooks.json"),Z=I(q);if(!Z)return null;let Q=Z.hooks??{},K={};for(let X of h0){let V=Z[X];if(V&&typeof V==="object"&&"hooks"in V&&V.hooks)K[X]=V.hooks}return{packName:B,sourcePath:q,version:Z.version,shared:Q,targetOverrides:K}}function a($,B){let q={};for(let[Q,K]of Object.entries($.shared))q[Q]=[...K];let Z=$.targetOverrides[B];if(Z)for(let[Q,K]of Object.entries(Z))q[Q]=[...q[Q]??[],...K];return q}import{existsSync as d0,readFileSync as o0}from"fs";import{join as z0}from"path";var f0=["ignore",".aiignore"];function e($,B){for(let q of f0){let Z=z0($,q);if(d0(Z)){let Q=o0(Z,"utf-8"),K=k0(Q);return{packName:B,sourcePath:Z,patterns:K}}}return null}function k0($){return $.split(`
|
|
4
|
+
`).map((B)=>B.trim()).filter((B)=>B.length>0&&!B.startsWith("#"))}function Q2($){let B=new Set,q=[];for(let Z of $)for(let Q of Z.patterns)if(!B.has(Q))B.add(Q),q.push(Q);return q}import{join as s0}from"path";function $0($,B){let q=s0($,"mcp.json"),Z=I(q);if(!Z?.mcpServers)return null;return{packName:B,sourcePath:q,servers:Z.mcpServers}}function L2($){let B={},q=[];for(let Z of $)for(let[Q,K]of Object.entries(Z.servers)){if(Q in B){q.push(`MCP server "${Q}" from pack "${Z.packName}" skipped (already defined).`);continue}B[Q]=K}return{servers:B,warnings:q}}import{existsSync as c0,readFileSync as i0}from"fs";import{basename as l0,join as p0}from"path";function q0($,B){let q=p0($,"plugins");if(!c0(q))return[];let Z=G(q,{extension:".ts"}),Q=G(q,{extension:".js"});return[...Z,...Q].map((X)=>r0(X,B))}function r0($,B){let q=i0($,"utf-8"),Z=$.endsWith(".ts")?"ts":"js";return{name:l0($,`.${Z}`),sourcePath:$,packName:B,content:q,extension:Z}}import{readFileSync as t0}from"fs";import{basename as a0}from"path";function B0($,B){return G($,{extension:".md"}).map((Z)=>e0(Z,B))}function e0($,B){let q=t0($,"utf-8"),{data:Z,content:Q}=u(q);return{name:a0($,".md"),sourcePath:$,packName:B,meta:Z,content:Q}}function G2($,B){let{targets:q}=$.meta;if(!q||q==="*")return!0;if(Array.isArray(q)&&q.includes("*"))return!0;return Array.isArray(q)&&q.includes(B)}function M2($){return $.filter((B)=>B.meta.root===!0)}function w2($){return $.filter((B)=>B.meta.root!==!0)}import{existsSync as $$,readFileSync as q$}from"fs";import{basename as Z0,join as B$}from"path";var Q$=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,Q0=64;function Y0($,B){let q=c($),Z=[];for(let Q of q){let K=B$(Q,"SKILL.md");if($$(K))Z.push(Z$(K,Q,B))}return Z}function Z$($,B,q){let Z=q$($,"utf-8"),{data:Q,content:K}=u(Z);return{name:Q.name??Z0(B),sourcePath:$,sourceDir:B,packName:q,meta:Q,content:K}}function n($){return{...$.meta,name:$.name}}function T2($){return A(n($),$.content)}function I2($,B){let{data:q,content:Z}=u($),Q={...q,name:B},K=!1,X=Q.description;if(typeof X!=="string"||X.trim().length===0)Q.description=`Imported skill: ${B}`,K=!0;return{content:A(Q,Z),addedDescription:K}}function _2($){let B=[],q=Z0($.sourceDir),Z=$.meta.name;if(typeof Z!=="string"||Z.trim().length===0)B.push('Missing required frontmatter field "name".');else{if(Z.length>Q0)B.push(`Invalid "name": must be at most ${Q0} characters.`);if(!Q$.test(Z))B.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==q)B.push(`Invalid "name": must match containing directory "${q}".`)}let Q=$.meta.description;if(typeof Q!=="string"||Q.trim().length===0)B.push('Missing required frontmatter field "description".');let K=$.meta["allowed-tools"];if(K!==void 0&&(!Array.isArray(K)||K.some((X)=>typeof X!=="string"||X.length===0)))B.push('Invalid "allowed-tools": expected an array of non-empty strings.');return B}function j2($,B){let{targets:q}=$.meta;if(!q||q==="*")return!0;if(Array.isArray(q)&&q.includes("*"))return!0;return Array.isArray(q)&&q.includes(B)}import{existsSync as x}from"fs";import{isAbsolute as Y$,resolve as M}from"path";class v{projectRoot;config;constructor($,B){this.projectRoot=$,this.config=B}loadAll(){let $=[],B=[],q=new Set(this.config.disabled);for(let Z of this.config.packs){let Q=this.resolvePackPath(Z);if(!Q){$.push(`Pack "${Z}" could not be resolved. Skipping.`);continue}if(!x(Q)){$.push(`Pack directory "${Q}" does not exist. Skipping.`);continue}let K=N(Q);if(q.has(K.name)||q.has(Z))continue;let X=this.loadPack(Q,K);B.push(X)}return{packs:B,warnings:$}}loadPack($,B){let q=B.name,Z=M($,"rules"),Q=M($,"commands"),K=M($,"agents"),X=M($,"skills");return{manifest:B,directory:$,rules:x(Z)?B0(Z,q):[],commands:x(Q)?r(Q,q):[],agents:x(K)?p(K,q):[],skills:x(X)?Y0(X,q):[],hooks:t($,q),plugins:q0($,q),mcp:$0($,q),ignore:e($,q),models:i($,q)}}loadForBaseDir($){let B=M(this.projectRoot,$),q=M(B,"agentpacks.jsonc");if(!x(q))return{packs:[],warnings:[]};let Z=j(B);return new v(B,Z).loadAll()}resolveCuratedPack($){let B=M(this.projectRoot,".agentpacks",".curated"),q=$;if(q.startsWith("registry:"))q=q.slice(9);if(q.startsWith("npm:"))q=q.slice(4);if(q.startsWith("github:"))q=q.slice(7);if(q.startsWith("@"))q=q.slice(1);if(q.includes("/")){let K=q.split("/");q=q.includes("@")?K.join("-"):K[K.length-1]??q}let Z=q.split("@")[0]??q;q=Z.split(":")[0]??Z;let Q=M(B,q);return x(Q)?Q:null}resolvePackPath($){if($.startsWith("./")||$.startsWith("../"))return M(this.projectRoot,$);if(Y$($))return $;if($.startsWith("registry:"))return this.resolveCuratedPack($);if($.startsWith("@")||$.startsWith("npm:")||!$.includes("/"))return this.resolveCuratedPack($);if($.startsWith("github:")||$.includes("/"))return this.resolveCuratedPack($);return M(this.projectRoot,$)}}import{copyFileSync as K0,existsSync as L0,mkdirSync as K$,writeFileSync as y}from"fs";import{dirname as L$,join as U,resolve as X$}from"path";function X0($,B){let q=[],Z=V$($.manifest.name),Q=X$(B,Z);K$(Q,{recursive:!0});let K={name:Z};if($.manifest.version)K.version=$.manifest.version;if($.manifest.description)K.description=$.manifest.description;let X=W$($.manifest.author);if(X)K.author=X;if($.manifest.homepage)K.homepage=$.manifest.homepage;if($.manifest.repository)K.repository=typeof $.manifest.repository==="string"?$.manifest.repository:$.manifest.repository.url;if($.manifest.license)K.license=$.manifest.license;if($.manifest.logo)K.logo=$.manifest.logo;if($.manifest.tags.length>0)K.keywords=$.manifest.tags;if($.rules.length>0){let J=U(Q,"rules");b(J),K.rules="rules";for(let W of $.rules){let H=W.meta.cursor??{},w={description:H.description??W.meta.description??"",alwaysApply:H.alwaysApply??W.meta.root??!1},C=H.globs??W.meta.globs;if(C)w.globs=C;let V0=`${W.name}.mdc`,E=U(J,V0);y(E,A(w,W.content)),q.push(E)}}if($.agents.length>0){let J=U(Q,"agents");b(J),K.agents="agents";for(let W of $.agents){let H={name:W.name,description:W.meta.description??""},w=`${W.name}.md`,C=U(J,w);y(C,A(H,W.content)),q.push(C)}}if($.skills.length>0){let J=U(Q,"skills");b(J),K.skills="skills";for(let W of $.skills){let H=U(J,W.name);b(H);let w=U(H,"SKILL.md"),C=A(n(W),W.content);y(w,C),q.push(w)}}if($.commands.length>0){let J=U(Q,"commands");b(J),K.commands="commands";for(let W of $.commands){let H={name:W.name};if(W.meta.description)H.description=W.meta.description;let w=`${W.name}.md`,C=U(J,w);y(C,A(H,W.content)),q.push(C)}}if($.hooks){let J=a($.hooks,"cursor");if(Object.keys(J).length>0){let W=U(Q,"hooks");b(W);let H=U(W,"hooks.json");y(H,JSON.stringify({version:$.hooks.version??1,hooks:J},null,2)+`
|
|
5
|
+
`),q.push(H),K.hooks="hooks/hooks.json"}}if($.mcp&&Object.keys($.mcp.servers).length>0){K.mcpServers=".mcp.json";let J=U(Q,".mcp.json");y(J,JSON.stringify({mcpServers:$.mcp.servers},null,2)+`
|
|
6
|
+
`),q.push(J)}J$($,Q,q),U$($,Q,q);let V=U(Q,".cursor-plugin");b(V);let O=U(V,"plugin.json");return y(O,JSON.stringify(K,null,2)+`
|
|
7
|
+
`),q.push(O),{outputDir:Q,filesWritten:q,manifest:K}}function V$($){let B=$.toLowerCase().replace(/[^a-z0-9.-]+/g,"-").replace(/-+/g,"-").replace(/^[^a-z0-9]+/,"").replace(/[^a-z0-9]+$/,"");return B.length>0?B:"agentpacks-plugin"}function W$($){if(!$)return null;if(typeof $==="string")return{name:$};return{name:$.name,...$.email?{email:$.email}:{}}}function J$($,B,q){let Z=U($.directory,"README.md");if(!L0(Z))return;let Q=U(B,"README.md");K0(Z,Q),q.push(Q)}function U$($,B,q){if(!$.manifest.logo)return;let Z=U($.directory,$.manifest.logo);if(!L0(Z))return;let Q=U(B,$.manifest.logo);b(L$(Q)),K0(Z,Q),q.push(Q)}import P from"chalk";import{resolve as H$}from"path";function q9($,B){let q=j($),Z=B.verbose??q.verbose,Q=new v($,q),{packs:K,warnings:X}=Q.loadAll();for(let J of X)console.log(P.yellow(` warn: ${J}`));if(K.length===0){console.log(P.red("No packs loaded. Nothing to export."));return}let V=B.pack?K.filter((J)=>J.manifest.name===B.pack):K;if(V.length===0){console.log(P.red(`Pack "${B.pack}" not found.`));return}let O=H$($,B.output??"dist/cursor-plugins");switch(B.format){case"cursor-plugin":{let J=0;for(let W of V){if(Z)console.log(P.dim(` Exporting ${W.manifest.name}...`));let H=X0(W,O);if(J+=H.filesWritten.length,Z)console.log(P.dim(` ${H.filesWritten.length} file(s) written`))}console.log(P.green(`Exported ${V.length} pack(s) as Cursor plugins (${J} files) to ${O}`));break}default:console.log(P.red(`Unknown export format: "${B.format}". Supported: cursor-plugin`))}}export{q9 as runExport};
|