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.
Files changed (147) hide show
  1. package/dist/api.js +48 -3658
  2. package/dist/cli/export-cmd.js +7 -1027
  3. package/dist/cli/generate.js +39 -2731
  4. package/dist/cli/import-cmd.js +19 -770
  5. package/dist/cli/info.js +4 -231
  6. package/dist/cli/init.js +9 -185
  7. package/dist/cli/install.js +4 -902
  8. package/dist/cli/login.js +6 -201
  9. package/dist/cli/models-explain.js +14 -1266
  10. package/dist/cli/pack/create.js +4 -146
  11. package/dist/cli/pack/enable.js +2 -65
  12. package/dist/cli/pack/list.js +5 -893
  13. package/dist/cli/pack/validate.js +4 -642
  14. package/dist/cli/publish.js +8 -679
  15. package/dist/cli/search.js +4 -209
  16. package/dist/core/config.d.ts +1 -1
  17. package/dist/core/config.js +1 -145
  18. package/dist/core/dependency-resolver.js +1 -126
  19. package/dist/core/feature-merger.js +3 -398
  20. package/dist/core/index.js +5 -1129
  21. package/dist/core/lockfile.js +2 -43
  22. package/dist/core/metarepo.js +1 -183
  23. package/dist/core/pack-loader.js +4 -841
  24. package/dist/core/profile-resolver.js +1 -110
  25. package/dist/exporters/cursor-plugin.js +6 -404
  26. package/dist/exporters/index.js +6 -404
  27. package/dist/features/agents.js +3 -161
  28. package/dist/features/commands.js +3 -161
  29. package/dist/features/hooks.js +3 -153
  30. package/dist/features/ignore.js +2 -43
  31. package/dist/features/index.js +4 -629
  32. package/dist/features/mcp.js +3 -143
  33. package/dist/features/models.js +3 -292
  34. package/dist/features/plugins.js +3 -139
  35. package/dist/features/rules.d.ts +0 -1
  36. package/dist/features/rules.js +3 -169
  37. package/dist/features/skills.js +3 -228
  38. package/dist/importers/claude-code.js +6 -195
  39. package/dist/importers/cursor.js +5 -355
  40. package/dist/importers/opencode.js +6 -346
  41. package/dist/importers/rulesync.js +5 -365
  42. package/dist/index.js +89 -4934
  43. package/dist/node/api.js +48 -3659
  44. package/dist/node/cli/export-cmd.js +7 -1028
  45. package/dist/node/cli/generate.js +39 -2732
  46. package/dist/node/cli/import-cmd.js +19 -771
  47. package/dist/node/cli/info.js +4 -232
  48. package/dist/node/cli/init.js +9 -186
  49. package/dist/node/cli/install.js +4 -903
  50. package/dist/node/cli/login.js +6 -202
  51. package/dist/node/cli/models-explain.js +14 -1267
  52. package/dist/node/cli/pack/create.js +4 -147
  53. package/dist/node/cli/pack/enable.js +2 -66
  54. package/dist/node/cli/pack/list.js +5 -894
  55. package/dist/node/cli/pack/validate.js +4 -643
  56. package/dist/node/cli/publish.js +8 -680
  57. package/dist/node/cli/search.js +4 -210
  58. package/dist/node/core/config.js +1 -146
  59. package/dist/node/core/dependency-resolver.js +1 -127
  60. package/dist/node/core/feature-merger.js +3 -399
  61. package/dist/node/core/index.js +5 -1130
  62. package/dist/node/core/lockfile.js +2 -44
  63. package/dist/node/core/metarepo.js +1 -184
  64. package/dist/node/core/pack-loader.js +4 -842
  65. package/dist/node/core/profile-resolver.js +1 -111
  66. package/dist/node/exporters/cursor-plugin.js +6 -405
  67. package/dist/node/exporters/index.js +6 -405
  68. package/dist/node/features/agents.js +3 -162
  69. package/dist/node/features/commands.js +3 -162
  70. package/dist/node/features/hooks.js +3 -154
  71. package/dist/node/features/ignore.js +2 -44
  72. package/dist/node/features/index.js +4 -630
  73. package/dist/node/features/mcp.js +3 -144
  74. package/dist/node/features/models.js +3 -293
  75. package/dist/node/features/plugins.js +3 -140
  76. package/dist/node/features/rules.js +3 -170
  77. package/dist/node/features/skills.js +3 -229
  78. package/dist/node/importers/claude-code.js +6 -196
  79. package/dist/node/importers/cursor.js +5 -356
  80. package/dist/node/importers/opencode.js +6 -347
  81. package/dist/node/importers/rulesync.js +5 -366
  82. package/dist/node/index.js +89 -4935
  83. package/dist/node/sources/git-ref.js +1 -56
  84. package/dist/node/sources/git.js +2 -222
  85. package/dist/node/sources/index.js +4 -714
  86. package/dist/node/sources/local.js +1 -24
  87. package/dist/node/sources/npm-ref.js +1 -56
  88. package/dist/node/sources/npm.js +2 -184
  89. package/dist/node/sources/registry-ref.js +1 -37
  90. package/dist/node/sources/registry.js +4 -355
  91. package/dist/node/targets/additional-targets.js +6 -587
  92. package/dist/node/targets/base-target.js +1 -23
  93. package/dist/node/targets/claude-code.js +6 -714
  94. package/dist/node/targets/codex-cli.js +3 -324
  95. package/dist/node/targets/copilot.js +5 -603
  96. package/dist/node/targets/cursor.js +6 -700
  97. package/dist/node/targets/gemini-cli.js +10 -319
  98. package/dist/node/targets/generic-md-target.js +6 -478
  99. package/dist/node/targets/index.js +32 -1873
  100. package/dist/node/targets/mistral-vibe.js +7 -661
  101. package/dist/node/targets/opencode.js +13 -723
  102. package/dist/node/targets/registry.js +32 -1864
  103. package/dist/node/utils/credentials.js +3 -38
  104. package/dist/node/utils/diff.js +5 -132
  105. package/dist/node/utils/filesystem.js +3 -124
  106. package/dist/node/utils/frontmatter.js +1 -24
  107. package/dist/node/utils/global.js +1 -53
  108. package/dist/node/utils/markdown.js +3 -30
  109. package/dist/node/utils/model-allowlist.js +1 -126
  110. package/dist/node/utils/model-guidance.js +2 -78
  111. package/dist/node/utils/registry-client.js +1 -142
  112. package/dist/node/utils/tarball.js +1 -49
  113. package/dist/sources/git-ref.js +1 -55
  114. package/dist/sources/git.js +2 -221
  115. package/dist/sources/index.js +4 -713
  116. package/dist/sources/local.js +1 -23
  117. package/dist/sources/npm-ref.js +1 -55
  118. package/dist/sources/npm.js +2 -183
  119. package/dist/sources/registry-ref.js +1 -36
  120. package/dist/sources/registry.js +4 -354
  121. package/dist/targets/additional-targets.js +6 -586
  122. package/dist/targets/base-target.js +1 -22
  123. package/dist/targets/claude-code.js +6 -713
  124. package/dist/targets/codex-cli.js +3 -323
  125. package/dist/targets/copilot.js +5 -602
  126. package/dist/targets/cursor.js +6 -699
  127. package/dist/targets/gemini-cli.js +10 -318
  128. package/dist/targets/generic-md-target.js +6 -477
  129. package/dist/targets/index.d.ts +0 -1
  130. package/dist/targets/index.js +32 -1872
  131. package/dist/targets/mistral-vibe.js +7 -660
  132. package/dist/targets/opencode.js +13 -722
  133. package/dist/targets/registry.js +32 -1863
  134. package/dist/utils/credentials.js +3 -37
  135. package/dist/utils/diff.js +5 -131
  136. package/dist/utils/filesystem.js +3 -123
  137. package/dist/utils/frontmatter.js +1 -23
  138. package/dist/utils/global.js +1 -52
  139. package/dist/utils/markdown.js +3 -29
  140. package/dist/utils/model-allowlist.js +1 -125
  141. package/dist/utils/model-guidance.js +2 -77
  142. package/dist/utils/registry-client.js +1 -141
  143. package/dist/utils/tarball.js +1 -48
  144. package/package.json +4 -16
  145. package/dist/node/targets/agents-md.js +0 -211
  146. package/dist/targets/agents-md.d.ts +0 -13
  147. package/dist/targets/agents-md.js +0 -211
@@ -1,842 +1,4 @@
1
- import { createRequire } from "node:module";
2
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
-
4
- // src/core/config.ts
5
- import { existsSync, readFileSync } from "fs";
6
- import { parse as parseJsonc } from "jsonc-parser";
7
- import { resolve } from "path";
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
- export {
841
- PackLoader
842
- };
1
+ import{createRequire as r}from"node:module";var iq=r(import.meta.url);import{existsSync as A,readFileSync as w}from"fs";import{parse as t}from"jsonc-parser";import{resolve as j}from"path";import{z as Y}from"zod";var a=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],O=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],e=["repo","monorepo","metarepo"],I=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("*")}),qq=Y.union([Y.literal("*"),Y.array(Y.string()),Y.record(Y.string(),Y.union([Y.literal("*"),Y.array(Y.string())]))]),_=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:qq.default("*"),mode:Y.enum(e).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()}),Bq=["agentpacks.local.jsonc","agentpacks.jsonc"];function P(q){for(let Q of Bq){let B=j(q,Q);if(A(B)){let Z=w(B,"utf-8"),$=t(Z);return _.parse($)}}return _.parse({})}function v(q){let Q=j(q,"pack.json");if(!A(Q)){let $=q.split("/").pop()??"unknown";return I.parse({name:$})}let B=w(Q,"utf-8"),Z=JSON.parse(B);return I.parse(Z)}function BB(q,Q){let{features:B}=q;if(B==="*")return[...O];if(Array.isArray(B)){if(B.includes("*"))return[...O];return B.filter(($)=>O.includes($))}let Z=B[Q];if(!Z)return[];if(Z==="*")return[...O];if(Array.isArray(Z)&&Z.includes("*"))return[...O];return Z.filter(($)=>O.includes($))}function QB(q){if(q.targets==="*")return[...a];return q.targets}import{existsSync as C,mkdirSync as Qq,readdirSync as F,readFileSync as Zq,rmSync as $q,statSync as y,writeFileSync as Yq}from"fs";import{dirname as Xq,join as E,relative as Vq}from"path";var S="<!-- Generated by agentpacks. DO NOT EDIT. -->",R="// Generated by agentpacks. DO NOT EDIT.",N="// Generated by agentpacks. DO NOT EDIT.";function Wq(q,Q,B={}){let{header:Z=!0,type:$}=B,V=$??Uq(q);Kq(Xq(q));let W=Q;if(Z){let K=Jq(V);if(K)W=`${K}
2
+ ${Q}`}Yq(q,W,"utf-8")}function XB(q,Q,B={}){let Z=JSON.stringify(Q,null,2);Wq(q,Z+`
3
+ `,{...B,type:"json"})}function D(q){if(!C(q))return null;return Zq(q,"utf-8")}function b(q){let Q=D(q);if(Q===null)return null;return JSON.parse(Q)}function Kq(q){if(!C(q))Qq(q,{recursive:!0})}function VB(q){if(C(q))$q(q,{recursive:!0,force:!0})}function J(q,Q={}){let{extension:B,recursive:Z=!1}=Q;if(!C(q))return[];let $=[],V=F(q);for(let W of V){let K=E(q,W),U=y(K);if(U.isDirectory()&&Z)$.push(...J(K,Q));else if(U.isFile()){if(!B||W.endsWith(B))$.push(K)}}return $}function u(q){if(!C(q))return[];return F(q).map((Q)=>E(q,Q)).filter((Q)=>y(Q).isDirectory())}function WB(q,Q){return Vq(q,Q)}function KB(q){let Q=D(q);if(!Q)return!1;return Q.startsWith(S)||Q.startsWith(R)||Q.startsWith(N)}function Uq(q){if(q.endsWith(".json")||q.endsWith(".jsonc"))return"json";if(q.endsWith(".ts")||q.endsWith(".mts"))return"ts";if(q.endsWith(".js")||q.endsWith(".mjs"))return"js";return"md"}function Jq(q){switch(q){case"md":return S;case"json":return R;case"js":case"ts":return N;default:return null}}import{join as Hq}from"path";import{z as X}from"zod";var Lq=[/["']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,}/],M=X.object({model:X.string(),temperature:X.number().min(0).max(2).optional(),top_p:X.number().min(0).max(1).optional()}),Gq=X.object({extends:X.string().optional(),description:X.string().optional(),default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),M).optional()}),GB=X.object({complexity:X.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:X.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:X.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:X.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:X.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),Oq=X.object({when:X.record(X.string(),X.string()),use:X.string(),description:X.string().optional(),priority:X.number().optional()}),bq=X.object({options:X.record(X.string(),X.unknown()).optional(),variants:X.record(X.string(),X.record(X.string(),X.unknown())).optional()}),Cq=X.object({options:X.record(X.string(),X.unknown()).optional(),models:X.record(X.string(),bq).optional()}),Mq=X.object({default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),M).optional(),profiles:X.record(X.string(),Gq).optional(),providers:X.record(X.string(),Cq).optional(),routing:X.array(Oq).optional(),overrides:X.record(X.string(),X.object({default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),M).optional()})).optional()});function z(q,Q){let B=Hq(q,"models.json"),Z=b(B);if(!Z)return null;let $=Mq.parse(Z);return{packName:Q,sourcePath:B,config:$}}function OB(q){let Q=[],B={};for(let Z of q){let{config:$,packName:V}=Z;if($.default!==void 0&&B.default===void 0)B.default=$.default;else if($.default!==void 0&&B.default!==void 0)Q.push(`Models "default" from pack "${V}" skipped (already defined).`);if($.small!==void 0&&B.small===void 0)B.small=$.small;else if($.small!==void 0&&B.small!==void 0)Q.push(`Models "small" from pack "${V}" skipped (already defined).`);if($.agents){if(!B.agents)B.agents={};for(let[W,K]of Object.entries($.agents)){if(W in B.agents){Q.push(`Models agent "${W}" from pack "${V}" skipped (already defined).`);continue}B.agents[W]=K}}if($.profiles){if(!B.profiles)B.profiles={};for(let[W,K]of Object.entries($.profiles)){if(W in B.profiles){Q.push(`Models profile "${W}" from pack "${V}" skipped (already defined).`);continue}B.profiles[W]=K}}if($.providers){if(!B.providers)B.providers={};for(let[W,K]of Object.entries($.providers))if(!(W in B.providers))B.providers[W]=K;else{let U=B.providers[W];if(!U){B.providers[W]=K;continue}if(K.options)U.options={...K.options,...U.options};if(K.models){if(!U.models)U.models={};for(let[x,i]of Object.entries(K.models))if(!(x in U.models))U.models[x]=i}}}if($.routing){if(!B.routing)B.routing=[];B.routing.push(...$.routing)}if($.overrides){if(!B.overrides)B.overrides={};for(let[W,K]of Object.entries($.overrides)){if(W in B.overrides){Q.push(`Models override for target "${W}" from pack "${V}" skipped (already defined).`);continue}B.overrides[W]=K}}}return{config:B,warnings:Q}}function bB(q){let Q=[],B=JSON.stringify(q);for(let Z of Lq)if(Z.test(B))Q.push(`Potential secret detected in models.json matching pattern: ${Z.source}`);return Q}import h from"gray-matter";function L(q){let{data:Q,content:B}=h(q);return{data:Q,content:B.trim(),raw:q}}function T(q,Q){let B=Object.fromEntries(Object.entries(q).filter(([,Z])=>Z!==void 0));if(Object.keys(B).length===0)return Q;return h.stringify(Q,B)}import{readFileSync as Tq}from"fs";import{basename as xq}from"path";function g(q,Q){return J(q,{extension:".md"}).map((Z)=>Iq(Z,Q))}function Iq(q,Q){let B=Tq(q,"utf-8"),{data:Z,content:$}=L(B);return{name:Z.name??xq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function wB(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{readFileSync as _q}from"fs";import{basename as Aq}from"path";function d(q,Q){return J(q,{extension:".md"}).map((Z)=>wq(Z,Q))}function wq(q,Q){let B=_q(q,"utf-8"),{data:Z,content:$}=L(B);return{name:Aq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function EB(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{join as jq}from"path";var Pq=["cursor","claudecode","codexcli","opencode"];function m(q,Q){let B=jq(q,"hooks","hooks.json"),Z=b(B);if(!Z)return null;let $=Z.hooks??{},V={};for(let W of Pq){let K=Z[W];if(K&&typeof K==="object"&&"hooks"in K&&K.hooks)V[W]=K.hooks}return{packName:Q,sourcePath:B,version:Z.version,shared:$,targetOverrides:V}}function DB(q,Q){let B={};for(let[$,V]of Object.entries(q.shared))B[$]=[...V];let Z=q.targetOverrides[Q];if(Z)for(let[$,V]of Object.entries(Z))B[$]=[...B[$]??[],...V];return B}import{existsSync as vq,readFileSync as Fq}from"fs";import{join as yq}from"path";var Eq=["ignore",".aiignore"];function k(q,Q){for(let B of Eq){let Z=yq(q,B);if(vq(Z)){let $=Fq(Z,"utf-8"),V=Sq($);return{packName:Q,sourcePath:Z,patterns:V}}}return null}function Sq(q){return q.split(`
4
+ `).map((Q)=>Q.trim()).filter((Q)=>Q.length>0&&!Q.startsWith("#"))}function gB(q){let Q=new Set,B=[];for(let Z of q)for(let $ of Z.patterns)if(!Q.has($))Q.add($),B.push($);return B}import{join as Rq}from"path";function f(q,Q){let B=Rq(q,"mcp.json"),Z=b(B);if(!Z?.mcpServers)return null;return{packName:Q,sourcePath:B,servers:Z.mcpServers}}function fB(q){let Q={},B=[];for(let Z of q)for(let[$,V]of Object.entries(Z.servers)){if($ in Q){B.push(`MCP server "${$}" from pack "${Z.packName}" skipped (already defined).`);continue}Q[$]=V}return{servers:Q,warnings:B}}import{existsSync as Nq,readFileSync as Dq}from"fs";import{basename as uq,join as zq}from"path";function o(q,Q){let B=zq(q,"plugins");if(!Nq(B))return[];let Z=J(B,{extension:".ts"}),$=J(B,{extension:".js"});return[...Z,...$].map((W)=>hq(W,Q))}function hq(q,Q){let B=Dq(q,"utf-8"),Z=q.endsWith(".ts")?"ts":"js";return{name:uq(q,`.${Z}`),sourcePath:q,packName:Q,content:B,extension:Z}}import{readFileSync as gq}from"fs";import{basename as dq}from"path";function p(q,Q){return J(q,{extension:".md"}).map((Z)=>mq(Z,Q))}function mq(q,Q){let B=gq(q,"utf-8"),{data:Z,content:$}=L(B);return{name:dq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function aB(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}function eB(q){return q.filter((Q)=>Q.meta.root===!0)}function qQ(q){return q.filter((Q)=>Q.meta.root!==!0)}import{existsSync as kq,readFileSync as fq}from"fs";import{basename as n,join as oq}from"path";var pq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,c=64;function l(q,Q){let B=u(q),Z=[];for(let $ of B){let V=oq($,"SKILL.md");if(kq(V))Z.push(cq(V,$,Q))}return Z}function cq(q,Q,B){let Z=fq(q,"utf-8"),{data:$,content:V}=L(Z);return{name:$.name??n(Q),sourcePath:q,sourceDir:Q,packName:B,meta:$,content:V}}function nq(q){return{...q.meta,name:q.name}}function XQ(q){return T(nq(q),q.content)}function VQ(q,Q){let{data:B,content:Z}=L(q),$={...B,name:Q},V=!1,W=$.description;if(typeof W!=="string"||W.trim().length===0)$.description=`Imported skill: ${Q}`,V=!0;return{content:T($,Z),addedDescription:V}}function WQ(q){let Q=[],B=n(q.sourceDir),Z=q.meta.name;if(typeof Z!=="string"||Z.trim().length===0)Q.push('Missing required frontmatter field "name".');else{if(Z.length>c)Q.push(`Invalid "name": must be at most ${c} characters.`);if(!pq.test(Z))Q.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==B)Q.push(`Invalid "name": must match containing directory "${B}".`)}let $=q.meta.description;if(typeof $!=="string"||$.trim().length===0)Q.push('Missing required frontmatter field "description".');let V=q.meta["allowed-tools"];if(V!==void 0&&(!Array.isArray(V)||V.some((W)=>typeof W!=="string"||W.length===0)))Q.push('Invalid "allowed-tools": expected an array of non-empty strings.');return Q}function KQ(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{existsSync as G}from"fs";import{isAbsolute as lq,resolve as H}from"path";class s{projectRoot;config;constructor(q,Q){this.projectRoot=q,this.config=Q}loadAll(){let q=[],Q=[],B=new Set(this.config.disabled);for(let Z of this.config.packs){let $=this.resolvePackPath(Z);if(!$){q.push(`Pack "${Z}" could not be resolved. Skipping.`);continue}if(!G($)){q.push(`Pack directory "${$}" does not exist. Skipping.`);continue}let V=v($);if(B.has(V.name)||B.has(Z))continue;let W=this.loadPack($,V);Q.push(W)}return{packs:Q,warnings:q}}loadPack(q,Q){let B=Q.name,Z=H(q,"rules"),$=H(q,"commands"),V=H(q,"agents"),W=H(q,"skills");return{manifest:Q,directory:q,rules:G(Z)?p(Z,B):[],commands:G($)?d($,B):[],agents:G(V)?g(V,B):[],skills:G(W)?l(W,B):[],hooks:m(q,B),plugins:o(q,B),mcp:f(q,B),ignore:k(q,B),models:z(q,B)}}loadForBaseDir(q){let Q=H(this.projectRoot,q),B=H(Q,"agentpacks.jsonc");if(!G(B))return{packs:[],warnings:[]};let Z=P(Q);return new s(Q,Z).loadAll()}resolveCuratedPack(q){let Q=H(this.projectRoot,".agentpacks",".curated"),B=q;if(B.startsWith("registry:"))B=B.slice(9);if(B.startsWith("npm:"))B=B.slice(4);if(B.startsWith("github:"))B=B.slice(7);if(B.startsWith("@"))B=B.slice(1);if(B.includes("/")){let V=B.split("/");B=B.includes("@")?V.join("-"):V[V.length-1]??B}let Z=B.split("@")[0]??B;B=Z.split(":")[0]??Z;let $=H(Q,B);return G($)?$:null}resolvePackPath(q){if(q.startsWith("./")||q.startsWith("../"))return H(this.projectRoot,q);if(lq(q))return q;if(q.startsWith("registry:"))return this.resolveCuratedPack(q);if(q.startsWith("@")||q.startsWith("npm:")||!q.includes("/"))return this.resolveCuratedPack(q);if(q.startsWith("github:")||q.includes("/"))return this.resolveCuratedPack(q);return H(this.projectRoot,q)}}export{s as PackLoader};