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
package/dist/node/core/index.js
CHANGED
|
@@ -1,1130 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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/core/dependency-resolver.ts
|
|
138
|
-
function buildDependencyGraph(manifests) {
|
|
139
|
-
const graph = new Map;
|
|
140
|
-
for (const m of manifests) {
|
|
141
|
-
graph.set(m.name, {
|
|
142
|
-
name: m.name,
|
|
143
|
-
manifest: m,
|
|
144
|
-
dependencies: m.dependencies,
|
|
145
|
-
conflicts: m.conflicts
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return graph;
|
|
149
|
-
}
|
|
150
|
-
function resolveDependencies(manifests) {
|
|
151
|
-
const graph = buildDependencyGraph(manifests);
|
|
152
|
-
const allNames = new Set(graph.keys());
|
|
153
|
-
const missingDeps = [];
|
|
154
|
-
for (const [name, node] of graph) {
|
|
155
|
-
for (const dep of node.dependencies) {
|
|
156
|
-
if (!allNames.has(dep)) {
|
|
157
|
-
missingDeps.push([name, dep]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const { sorted, cycles } = topologicalSort(graph);
|
|
162
|
-
const conflictPairs = detectConflicts(graph);
|
|
163
|
-
const ok = cycles.length === 0 && conflictPairs.length === 0 && missingDeps.length === 0;
|
|
164
|
-
return { sorted, cycles, conflictPairs, missingDeps, ok };
|
|
165
|
-
}
|
|
166
|
-
function topologicalSort(graph) {
|
|
167
|
-
const inDegree = new Map;
|
|
168
|
-
for (const name of graph.keys()) {
|
|
169
|
-
inDegree.set(name, 0);
|
|
170
|
-
}
|
|
171
|
-
for (const [, node] of graph) {
|
|
172
|
-
for (const dep of node.dependencies) {
|
|
173
|
-
if (graph.has(dep)) {
|
|
174
|
-
inDegree.set(dep, (inDegree.get(dep) ?? 0) + 1);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const queue = [];
|
|
179
|
-
for (const [name, degree] of inDegree) {
|
|
180
|
-
if (degree === 0)
|
|
181
|
-
queue.push(name);
|
|
182
|
-
}
|
|
183
|
-
const sorted = [];
|
|
184
|
-
while (queue.length > 0) {
|
|
185
|
-
const current = queue.shift();
|
|
186
|
-
if (!current)
|
|
187
|
-
continue;
|
|
188
|
-
sorted.push(current);
|
|
189
|
-
const node = graph.get(current);
|
|
190
|
-
if (!node)
|
|
191
|
-
continue;
|
|
192
|
-
for (const dep of node.dependencies) {
|
|
193
|
-
if (!graph.has(dep))
|
|
194
|
-
continue;
|
|
195
|
-
const newDegree = (inDegree.get(dep) ?? 1) - 1;
|
|
196
|
-
inDegree.set(dep, newDegree);
|
|
197
|
-
if (newDegree === 0) {
|
|
198
|
-
queue.push(dep);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const cycles = [];
|
|
203
|
-
if (sorted.length < graph.size) {
|
|
204
|
-
const remaining = new Set;
|
|
205
|
-
for (const name of graph.keys()) {
|
|
206
|
-
if (!sorted.includes(name))
|
|
207
|
-
remaining.add(name);
|
|
208
|
-
}
|
|
209
|
-
const visited = new Set;
|
|
210
|
-
for (const start of remaining) {
|
|
211
|
-
if (visited.has(start))
|
|
212
|
-
continue;
|
|
213
|
-
const cycle = traceCycle(start, graph, remaining);
|
|
214
|
-
if (cycle.length > 0) {
|
|
215
|
-
cycles.push(cycle);
|
|
216
|
-
for (const n of cycle)
|
|
217
|
-
visited.add(n);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return { sorted: sorted.reverse(), cycles };
|
|
222
|
-
}
|
|
223
|
-
function traceCycle(start, graph, remaining) {
|
|
224
|
-
const path = [];
|
|
225
|
-
const pathSet = new Set;
|
|
226
|
-
let current = start;
|
|
227
|
-
while (current && !pathSet.has(current)) {
|
|
228
|
-
path.push(current);
|
|
229
|
-
pathSet.add(current);
|
|
230
|
-
const node = graph.get(current);
|
|
231
|
-
if (!node)
|
|
232
|
-
break;
|
|
233
|
-
current = node.dependencies.find((d) => remaining.has(d) && graph.has(d));
|
|
234
|
-
}
|
|
235
|
-
if (current && pathSet.has(current)) {
|
|
236
|
-
const cycleStart = path.indexOf(current);
|
|
237
|
-
return path.slice(cycleStart);
|
|
238
|
-
}
|
|
239
|
-
return path;
|
|
240
|
-
}
|
|
241
|
-
function detectConflicts(graph) {
|
|
242
|
-
const conflicts = [];
|
|
243
|
-
const seen = new Set;
|
|
244
|
-
for (const [name, node] of graph) {
|
|
245
|
-
for (const conflict of node.conflicts) {
|
|
246
|
-
if (graph.has(conflict)) {
|
|
247
|
-
const key = [name, conflict].sort().join(":");
|
|
248
|
-
if (!seen.has(key)) {
|
|
249
|
-
seen.add(key);
|
|
250
|
-
conflicts.push([name, conflict]);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return conflicts;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/utils/filesystem.ts
|
|
259
|
-
import {
|
|
260
|
-
existsSync as existsSync2,
|
|
261
|
-
mkdirSync,
|
|
262
|
-
readdirSync,
|
|
263
|
-
readFileSync as readFileSync2,
|
|
264
|
-
rmSync,
|
|
265
|
-
statSync,
|
|
266
|
-
writeFileSync
|
|
267
|
-
} from "fs";
|
|
268
|
-
import { dirname, join, relative } from "path";
|
|
269
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
270
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
271
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
272
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
273
|
-
const { header = true, type } = options;
|
|
274
|
-
const ext = type ?? inferFileType(filepath);
|
|
275
|
-
ensureDir(dirname(filepath));
|
|
276
|
-
let output = content;
|
|
277
|
-
if (header) {
|
|
278
|
-
const headerComment = getHeader(ext);
|
|
279
|
-
if (headerComment) {
|
|
280
|
-
output = `${headerComment}
|
|
281
|
-
${content}`;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
writeFileSync(filepath, output, "utf-8");
|
|
285
|
-
}
|
|
286
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
287
|
-
const json = JSON.stringify(data, null, 2);
|
|
288
|
-
writeGeneratedFile(filepath, json + `
|
|
289
|
-
`, { ...options, type: "json" });
|
|
290
|
-
}
|
|
291
|
-
function readFileOrNull(filepath) {
|
|
292
|
-
if (!existsSync2(filepath))
|
|
293
|
-
return null;
|
|
294
|
-
return readFileSync2(filepath, "utf-8");
|
|
295
|
-
}
|
|
296
|
-
function readJsonOrNull(filepath) {
|
|
297
|
-
const content = readFileOrNull(filepath);
|
|
298
|
-
if (content === null)
|
|
299
|
-
return null;
|
|
300
|
-
return JSON.parse(content);
|
|
301
|
-
}
|
|
302
|
-
function ensureDir(dirPath) {
|
|
303
|
-
if (!existsSync2(dirPath)) {
|
|
304
|
-
mkdirSync(dirPath, { recursive: true });
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
function removeIfExists(targetPath) {
|
|
308
|
-
if (existsSync2(targetPath)) {
|
|
309
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
function listFiles(dirPath, options = {}) {
|
|
313
|
-
const { extension, recursive = false } = options;
|
|
314
|
-
if (!existsSync2(dirPath))
|
|
315
|
-
return [];
|
|
316
|
-
const results = [];
|
|
317
|
-
const entries = readdirSync(dirPath);
|
|
318
|
-
for (const entry of entries) {
|
|
319
|
-
const fullPath = join(dirPath, entry);
|
|
320
|
-
const stat = statSync(fullPath);
|
|
321
|
-
if (stat.isDirectory() && recursive) {
|
|
322
|
-
results.push(...listFiles(fullPath, options));
|
|
323
|
-
} else if (stat.isFile()) {
|
|
324
|
-
if (!extension || entry.endsWith(extension)) {
|
|
325
|
-
results.push(fullPath);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return results;
|
|
330
|
-
}
|
|
331
|
-
function listDirs(dirPath) {
|
|
332
|
-
if (!existsSync2(dirPath))
|
|
333
|
-
return [];
|
|
334
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
335
|
-
}
|
|
336
|
-
function relPath(projectRoot, filepath) {
|
|
337
|
-
return relative(projectRoot, filepath);
|
|
338
|
-
}
|
|
339
|
-
function isGeneratedFile(filepath) {
|
|
340
|
-
const content = readFileOrNull(filepath);
|
|
341
|
-
if (!content)
|
|
342
|
-
return false;
|
|
343
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
344
|
-
}
|
|
345
|
-
function inferFileType(filepath) {
|
|
346
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
347
|
-
return "json";
|
|
348
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
349
|
-
return "ts";
|
|
350
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
351
|
-
return "js";
|
|
352
|
-
return "md";
|
|
353
|
-
}
|
|
354
|
-
function getHeader(type) {
|
|
355
|
-
switch (type) {
|
|
356
|
-
case "md":
|
|
357
|
-
return GENERATED_HEADER_MD;
|
|
358
|
-
case "json":
|
|
359
|
-
return GENERATED_HEADER_JSON;
|
|
360
|
-
case "js":
|
|
361
|
-
case "ts":
|
|
362
|
-
return GENERATED_HEADER_JS;
|
|
363
|
-
default:
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/features/models.ts
|
|
369
|
-
import { join as join2 } from "path";
|
|
370
|
-
import { z as z2 } from "zod";
|
|
371
|
-
var SECRET_PATTERNS = [
|
|
372
|
-
/["']api[_-]?key["']\s*:/i,
|
|
373
|
-
/["']apiKey["']\s*:/i,
|
|
374
|
-
/["']secret["']\s*:/i,
|
|
375
|
-
/["']password["']\s*:/i,
|
|
376
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
377
|
-
/["']private[_-]?key["']\s*:/i,
|
|
378
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
379
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
380
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
381
|
-
];
|
|
382
|
-
var AgentModelSchema = z2.object({
|
|
383
|
-
model: z2.string(),
|
|
384
|
-
temperature: z2.number().min(0).max(2).optional(),
|
|
385
|
-
top_p: z2.number().min(0).max(1).optional()
|
|
386
|
-
});
|
|
387
|
-
var ModelProfileSchema = z2.object({
|
|
388
|
-
extends: z2.string().optional(),
|
|
389
|
-
description: z2.string().optional(),
|
|
390
|
-
default: z2.string().optional(),
|
|
391
|
-
small: z2.string().optional(),
|
|
392
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
393
|
-
});
|
|
394
|
-
var RoutingConditionSchema = z2.object({
|
|
395
|
-
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
396
|
-
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
397
|
-
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
398
|
-
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
399
|
-
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
400
|
-
});
|
|
401
|
-
var RoutingRuleSchema = z2.object({
|
|
402
|
-
when: z2.record(z2.string(), z2.string()),
|
|
403
|
-
use: z2.string(),
|
|
404
|
-
description: z2.string().optional(),
|
|
405
|
-
priority: z2.number().optional()
|
|
406
|
-
});
|
|
407
|
-
var ProviderModelSchema = z2.object({
|
|
408
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
409
|
-
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
410
|
-
});
|
|
411
|
-
var ProviderConfigSchema = z2.object({
|
|
412
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
413
|
-
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
414
|
-
});
|
|
415
|
-
var ModelsSchema = z2.object({
|
|
416
|
-
default: z2.string().optional(),
|
|
417
|
-
small: z2.string().optional(),
|
|
418
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
419
|
-
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
420
|
-
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
421
|
-
routing: z2.array(RoutingRuleSchema).optional(),
|
|
422
|
-
overrides: z2.record(z2.string(), z2.object({
|
|
423
|
-
default: z2.string().optional(),
|
|
424
|
-
small: z2.string().optional(),
|
|
425
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
426
|
-
})).optional()
|
|
427
|
-
});
|
|
428
|
-
function parseModels(packDir, packName) {
|
|
429
|
-
const modelsPath = join2(packDir, "models.json");
|
|
430
|
-
const raw = readJsonOrNull(modelsPath);
|
|
431
|
-
if (!raw)
|
|
432
|
-
return null;
|
|
433
|
-
const parsed = ModelsSchema.parse(raw);
|
|
434
|
-
return {
|
|
435
|
-
packName,
|
|
436
|
-
sourcePath: modelsPath,
|
|
437
|
-
config: parsed
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function mergeModelsConfigs(configs) {
|
|
441
|
-
const warnings = [];
|
|
442
|
-
const result = {};
|
|
443
|
-
for (const entry of configs) {
|
|
444
|
-
const { config, packName } = entry;
|
|
445
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
446
|
-
result.default = config.default;
|
|
447
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
448
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
449
|
-
}
|
|
450
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
451
|
-
result.small = config.small;
|
|
452
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
453
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
454
|
-
}
|
|
455
|
-
if (config.agents) {
|
|
456
|
-
if (!result.agents)
|
|
457
|
-
result.agents = {};
|
|
458
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
459
|
-
if (name in result.agents) {
|
|
460
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
result.agents[name] = assignment;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
if (config.profiles) {
|
|
467
|
-
if (!result.profiles)
|
|
468
|
-
result.profiles = {};
|
|
469
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
470
|
-
if (name in result.profiles) {
|
|
471
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
result.profiles[name] = profile;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (config.providers) {
|
|
478
|
-
if (!result.providers)
|
|
479
|
-
result.providers = {};
|
|
480
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
481
|
-
if (!(providerName in result.providers)) {
|
|
482
|
-
result.providers[providerName] = providerConfig;
|
|
483
|
-
} else {
|
|
484
|
-
const existing = result.providers[providerName];
|
|
485
|
-
if (!existing) {
|
|
486
|
-
result.providers[providerName] = providerConfig;
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
if (providerConfig.options) {
|
|
490
|
-
existing.options = {
|
|
491
|
-
...providerConfig.options,
|
|
492
|
-
...existing.options
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
if (providerConfig.models) {
|
|
496
|
-
if (!existing.models)
|
|
497
|
-
existing.models = {};
|
|
498
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
499
|
-
if (!(modelName in existing.models)) {
|
|
500
|
-
existing.models[modelName] = modelConfig;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (config.routing) {
|
|
508
|
-
if (!result.routing)
|
|
509
|
-
result.routing = [];
|
|
510
|
-
result.routing.push(...config.routing);
|
|
511
|
-
}
|
|
512
|
-
if (config.overrides) {
|
|
513
|
-
if (!result.overrides)
|
|
514
|
-
result.overrides = {};
|
|
515
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
516
|
-
if (targetId in result.overrides) {
|
|
517
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
518
|
-
continue;
|
|
519
|
-
}
|
|
520
|
-
result.overrides[targetId] = override;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return { config: result, warnings };
|
|
525
|
-
}
|
|
526
|
-
function scanModelsForSecrets(config) {
|
|
527
|
-
const warnings = [];
|
|
528
|
-
const json = JSON.stringify(config);
|
|
529
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
530
|
-
if (pattern.test(json)) {
|
|
531
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
return warnings;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// src/core/feature-merger.ts
|
|
538
|
-
class FeatureMerger {
|
|
539
|
-
packs;
|
|
540
|
-
warnings = [];
|
|
541
|
-
constructor(packs) {
|
|
542
|
-
this.packs = packs;
|
|
543
|
-
}
|
|
544
|
-
merge() {
|
|
545
|
-
this.warnings = [];
|
|
546
|
-
const features = {
|
|
547
|
-
rules: this.mergeRules(),
|
|
548
|
-
commands: this.mergeByName("commands"),
|
|
549
|
-
agents: this.mergeByName("agents"),
|
|
550
|
-
skills: this.mergeByName("skills"),
|
|
551
|
-
hooks: this.mergeHooks(),
|
|
552
|
-
plugins: this.mergePlugins(),
|
|
553
|
-
mcpServers: this.mergeMcp(),
|
|
554
|
-
ignorePatterns: this.mergeIgnore(),
|
|
555
|
-
models: this.mergeModels()
|
|
556
|
-
};
|
|
557
|
-
return { features, warnings: this.warnings };
|
|
558
|
-
}
|
|
559
|
-
mergeRules() {
|
|
560
|
-
const seen = new Map;
|
|
561
|
-
const result = [];
|
|
562
|
-
for (const pack of this.packs) {
|
|
563
|
-
for (const rule of pack.rules) {
|
|
564
|
-
const existing = seen.get(rule.name);
|
|
565
|
-
if (existing) {
|
|
566
|
-
this.warnings.push(`Rule "${rule.name}" from pack "${rule.packName}" skipped (already defined by "${existing}").`);
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
seen.set(rule.name, rule.packName);
|
|
570
|
-
result.push(rule);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
return result;
|
|
574
|
-
}
|
|
575
|
-
mergeByName(featureKey) {
|
|
576
|
-
const seen = new Map;
|
|
577
|
-
const result = [];
|
|
578
|
-
for (const pack of this.packs) {
|
|
579
|
-
const items = pack[featureKey];
|
|
580
|
-
for (const item of items) {
|
|
581
|
-
const existing = seen.get(item.name);
|
|
582
|
-
if (existing) {
|
|
583
|
-
this.warnings.push(`${featureKey.slice(0, -1)} "${item.name}" from pack "${item.packName}" skipped (already defined by "${existing}").`);
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
seen.set(item.name, item.packName);
|
|
587
|
-
result.push(item);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return result;
|
|
591
|
-
}
|
|
592
|
-
mergeHooks() {
|
|
593
|
-
return this.packs.map((p) => p.hooks).filter((h) => h !== null);
|
|
594
|
-
}
|
|
595
|
-
mergePlugins() {
|
|
596
|
-
const seen = new Map;
|
|
597
|
-
const result = [];
|
|
598
|
-
for (const pack of this.packs) {
|
|
599
|
-
for (const plugin of pack.plugins) {
|
|
600
|
-
const key = `${plugin.name}.${plugin.extension}`;
|
|
601
|
-
const existing = seen.get(key);
|
|
602
|
-
if (existing) {
|
|
603
|
-
this.warnings.push(`Plugin "${key}" from pack "${plugin.packName}" skipped (already defined by "${existing}").`);
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
seen.set(key, plugin.packName);
|
|
607
|
-
result.push(plugin);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
return result;
|
|
611
|
-
}
|
|
612
|
-
mergeMcp() {
|
|
613
|
-
const servers = {};
|
|
614
|
-
for (const pack of this.packs) {
|
|
615
|
-
if (!pack.mcp)
|
|
616
|
-
continue;
|
|
617
|
-
for (const [name, entry] of Object.entries(pack.mcp.servers)) {
|
|
618
|
-
if (name in servers) {
|
|
619
|
-
this.warnings.push(`MCP server "${name}" from pack "${pack.manifest.name}" skipped (already defined).`);
|
|
620
|
-
continue;
|
|
621
|
-
}
|
|
622
|
-
servers[name] = entry;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
return servers;
|
|
626
|
-
}
|
|
627
|
-
mergeIgnore() {
|
|
628
|
-
const seen = new Set;
|
|
629
|
-
const result = [];
|
|
630
|
-
for (const pack of this.packs) {
|
|
631
|
-
if (!pack.ignore)
|
|
632
|
-
continue;
|
|
633
|
-
for (const pattern of pack.ignore.patterns) {
|
|
634
|
-
if (!seen.has(pattern)) {
|
|
635
|
-
seen.add(pattern);
|
|
636
|
-
result.push(pattern);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return result;
|
|
641
|
-
}
|
|
642
|
-
mergeModels() {
|
|
643
|
-
const configs = this.packs.map((p) => p.models).filter((m) => m != null);
|
|
644
|
-
if (configs.length === 0)
|
|
645
|
-
return null;
|
|
646
|
-
const { config, warnings } = mergeModelsConfigs(configs);
|
|
647
|
-
this.warnings.push(...warnings);
|
|
648
|
-
return config;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/core/lockfile.ts
|
|
653
|
-
import { createHash } from "crypto";
|
|
654
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
655
|
-
import { resolve as resolve2 } from "path";
|
|
656
|
-
var LOCKFILE_VERSION = 1;
|
|
657
|
-
var LOCKFILE_NAME = "agentpacks.lock";
|
|
658
|
-
function loadLockfile(projectRoot) {
|
|
659
|
-
const filepath = resolve2(projectRoot, LOCKFILE_NAME);
|
|
660
|
-
if (!existsSync3(filepath)) {
|
|
661
|
-
return { lockfileVersion: LOCKFILE_VERSION, sources: {} };
|
|
662
|
-
}
|
|
663
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
664
|
-
return JSON.parse(raw);
|
|
665
|
-
}
|
|
666
|
-
function saveLockfile(projectRoot, lockfile) {
|
|
667
|
-
const filepath = resolve2(projectRoot, LOCKFILE_NAME);
|
|
668
|
-
writeFileSync2(filepath, JSON.stringify(lockfile, null, 2) + `
|
|
669
|
-
`);
|
|
670
|
-
}
|
|
671
|
-
function getLockedSource(lockfile, sourceKey) {
|
|
672
|
-
return lockfile.sources[sourceKey];
|
|
673
|
-
}
|
|
674
|
-
function setLockedSource(lockfile, sourceKey, entry) {
|
|
675
|
-
lockfile.sources[sourceKey] = entry;
|
|
676
|
-
}
|
|
677
|
-
function computeIntegrity(content) {
|
|
678
|
-
const hash = createHash("sha256").update(content).digest("hex");
|
|
679
|
-
return `sha256-${hash}`;
|
|
680
|
-
}
|
|
681
|
-
function isLockfileFrozenValid(lockfile, sourceKeys) {
|
|
682
|
-
const missing = sourceKeys.filter((key) => !(key in lockfile.sources));
|
|
683
|
-
return { valid: missing.length === 0, missing };
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// src/utils/frontmatter.ts
|
|
687
|
-
import matter from "gray-matter";
|
|
688
|
-
function parseFrontmatter(source) {
|
|
689
|
-
const { data, content } = matter(source);
|
|
690
|
-
return {
|
|
691
|
-
data,
|
|
692
|
-
content: content.trim(),
|
|
693
|
-
raw: source
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
function serializeFrontmatter(data, content) {
|
|
697
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
698
|
-
if (Object.keys(filtered).length === 0) {
|
|
699
|
-
return content;
|
|
700
|
-
}
|
|
701
|
-
return matter.stringify(content, filtered);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// src/features/agents.ts
|
|
705
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
706
|
-
import { basename } from "path";
|
|
707
|
-
function parseAgents(agentsDir, packName) {
|
|
708
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
709
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
710
|
-
}
|
|
711
|
-
function parseAgentFile(filepath, packName) {
|
|
712
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
713
|
-
const { data, content } = parseFrontmatter(raw);
|
|
714
|
-
return {
|
|
715
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
716
|
-
sourcePath: filepath,
|
|
717
|
-
packName,
|
|
718
|
-
meta: data,
|
|
719
|
-
content
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
function agentMatchesTarget(agent, targetId) {
|
|
723
|
-
const { targets } = agent.meta;
|
|
724
|
-
if (!targets || targets === "*")
|
|
725
|
-
return true;
|
|
726
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
727
|
-
return true;
|
|
728
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// src/features/commands.ts
|
|
732
|
-
import { readFileSync as readFileSync5 } from "fs";
|
|
733
|
-
import { basename as basename2 } from "path";
|
|
734
|
-
function parseCommands(commandsDir, packName) {
|
|
735
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
736
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
737
|
-
}
|
|
738
|
-
function parseCommandFile(filepath, packName) {
|
|
739
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
740
|
-
const { data, content } = parseFrontmatter(raw);
|
|
741
|
-
return {
|
|
742
|
-
name: basename2(filepath, ".md"),
|
|
743
|
-
sourcePath: filepath,
|
|
744
|
-
packName,
|
|
745
|
-
meta: data,
|
|
746
|
-
content
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
750
|
-
const { targets } = cmd.meta;
|
|
751
|
-
if (!targets || targets === "*")
|
|
752
|
-
return true;
|
|
753
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
754
|
-
return true;
|
|
755
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
// src/features/hooks.ts
|
|
759
|
-
import { join as join3 } from "path";
|
|
760
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
761
|
-
function parseHooks(packDir, packName) {
|
|
762
|
-
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
763
|
-
const raw = readJsonOrNull(hooksPath);
|
|
764
|
-
if (!raw)
|
|
765
|
-
return null;
|
|
766
|
-
const shared = raw.hooks ?? {};
|
|
767
|
-
const targetOverrides = {};
|
|
768
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
769
|
-
const override = raw[key];
|
|
770
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
771
|
-
targetOverrides[key] = override.hooks;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
return {
|
|
775
|
-
packName,
|
|
776
|
-
sourcePath: hooksPath,
|
|
777
|
-
version: raw.version,
|
|
778
|
-
shared,
|
|
779
|
-
targetOverrides
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
783
|
-
const merged = {};
|
|
784
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
785
|
-
merged[event] = [...entries];
|
|
786
|
-
}
|
|
787
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
788
|
-
if (overrides) {
|
|
789
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
790
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
return merged;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
// src/features/ignore.ts
|
|
797
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
798
|
-
import { join as join4 } from "path";
|
|
799
|
-
var IGNORE_FILES = ["ignore", ".aiignore"];
|
|
800
|
-
function parseIgnore(packDir, packName) {
|
|
801
|
-
for (const filename of IGNORE_FILES) {
|
|
802
|
-
const filepath = join4(packDir, filename);
|
|
803
|
-
if (existsSync4(filepath)) {
|
|
804
|
-
const raw = readFileSync6(filepath, "utf-8");
|
|
805
|
-
const patterns = parseIgnoreContent(raw);
|
|
806
|
-
return {
|
|
807
|
-
packName,
|
|
808
|
-
sourcePath: filepath,
|
|
809
|
-
patterns
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
815
|
-
function parseIgnoreContent(content) {
|
|
816
|
-
return content.split(`
|
|
817
|
-
`).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
818
|
-
}
|
|
819
|
-
function mergeIgnorePatterns(configs) {
|
|
820
|
-
const seen = new Set;
|
|
821
|
-
const result = [];
|
|
822
|
-
for (const config of configs) {
|
|
823
|
-
for (const pattern of config.patterns) {
|
|
824
|
-
if (!seen.has(pattern)) {
|
|
825
|
-
seen.add(pattern);
|
|
826
|
-
result.push(pattern);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
return result;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// src/features/mcp.ts
|
|
834
|
-
import { join as join5 } from "path";
|
|
835
|
-
function parseMcp(packDir, packName) {
|
|
836
|
-
const mcpPath = join5(packDir, "mcp.json");
|
|
837
|
-
const raw = readJsonOrNull(mcpPath);
|
|
838
|
-
if (!raw?.mcpServers)
|
|
839
|
-
return null;
|
|
840
|
-
return {
|
|
841
|
-
packName,
|
|
842
|
-
sourcePath: mcpPath,
|
|
843
|
-
servers: raw.mcpServers
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
function mergeMcpConfigs(configs) {
|
|
847
|
-
const servers = {};
|
|
848
|
-
const warnings = [];
|
|
849
|
-
for (const config of configs) {
|
|
850
|
-
for (const [name, entry] of Object.entries(config.servers)) {
|
|
851
|
-
if (name in servers) {
|
|
852
|
-
warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
|
|
853
|
-
continue;
|
|
854
|
-
}
|
|
855
|
-
servers[name] = entry;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return { servers, warnings };
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// src/features/plugins.ts
|
|
862
|
-
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
|
|
863
|
-
import { basename as basename3, join as join6 } from "path";
|
|
864
|
-
function parsePlugins(packDir, packName) {
|
|
865
|
-
const pluginsDir = join6(packDir, "plugins");
|
|
866
|
-
if (!existsSync5(pluginsDir))
|
|
867
|
-
return [];
|
|
868
|
-
const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
|
|
869
|
-
const jsFiles = listFiles(pluginsDir, { extension: ".js" });
|
|
870
|
-
const allFiles = [...tsFiles, ...jsFiles];
|
|
871
|
-
return allFiles.map((filepath) => parsePluginFile(filepath, packName));
|
|
872
|
-
}
|
|
873
|
-
function parsePluginFile(filepath, packName) {
|
|
874
|
-
const content = readFileSync7(filepath, "utf-8");
|
|
875
|
-
const ext = filepath.endsWith(".ts") ? "ts" : "js";
|
|
876
|
-
return {
|
|
877
|
-
name: basename3(filepath, `.${ext}`),
|
|
878
|
-
sourcePath: filepath,
|
|
879
|
-
packName,
|
|
880
|
-
content,
|
|
881
|
-
extension: ext
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
// src/features/rules.ts
|
|
886
|
-
import { readFileSync as readFileSync8 } from "fs";
|
|
887
|
-
import { basename as basename4 } from "path";
|
|
888
|
-
function parseRules(rulesDir, packName) {
|
|
889
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
890
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
891
|
-
}
|
|
892
|
-
function parseRuleFile(filepath, packName) {
|
|
893
|
-
const raw = readFileSync8(filepath, "utf-8");
|
|
894
|
-
const { data, content } = parseFrontmatter(raw);
|
|
895
|
-
return {
|
|
896
|
-
name: basename4(filepath, ".md"),
|
|
897
|
-
sourcePath: filepath,
|
|
898
|
-
packName,
|
|
899
|
-
meta: data,
|
|
900
|
-
content
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
904
|
-
const { targets } = rule.meta;
|
|
905
|
-
if (!targets || targets === "*")
|
|
906
|
-
return true;
|
|
907
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
908
|
-
return true;
|
|
909
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
910
|
-
}
|
|
911
|
-
function getRootRules(rules) {
|
|
912
|
-
return rules.filter((r) => r.meta.root === true);
|
|
913
|
-
}
|
|
914
|
-
function getDetailRules(rules) {
|
|
915
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
// src/features/skills.ts
|
|
919
|
-
import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
920
|
-
import { basename as basename5, join as join7 } from "path";
|
|
921
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
922
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
923
|
-
function parseSkills(skillsDir, packName) {
|
|
924
|
-
const dirs = listDirs(skillsDir);
|
|
925
|
-
const skills = [];
|
|
926
|
-
for (const dir of dirs) {
|
|
927
|
-
const skillMd = join7(dir, "SKILL.md");
|
|
928
|
-
if (existsSync6(skillMd)) {
|
|
929
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
return skills;
|
|
933
|
-
}
|
|
934
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
935
|
-
const raw = readFileSync9(filepath, "utf-8");
|
|
936
|
-
const { data, content } = parseFrontmatter(raw);
|
|
937
|
-
return {
|
|
938
|
-
name: data.name ?? basename5(skillDir),
|
|
939
|
-
sourcePath: filepath,
|
|
940
|
-
sourceDir: skillDir,
|
|
941
|
-
packName,
|
|
942
|
-
meta: data,
|
|
943
|
-
content
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
function buildSkillFrontmatter(skill) {
|
|
947
|
-
return {
|
|
948
|
-
...skill.meta,
|
|
949
|
-
name: skill.name
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
function serializeSkill(skill) {
|
|
953
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
954
|
-
}
|
|
955
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
956
|
-
const { data, content } = parseFrontmatter(source);
|
|
957
|
-
const normalized = {
|
|
958
|
-
...data,
|
|
959
|
-
name: skillName
|
|
960
|
-
};
|
|
961
|
-
let addedDescription = false;
|
|
962
|
-
const description = normalized.description;
|
|
963
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
964
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
965
|
-
addedDescription = true;
|
|
966
|
-
}
|
|
967
|
-
return {
|
|
968
|
-
content: serializeFrontmatter(normalized, content),
|
|
969
|
-
addedDescription
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
973
|
-
const errors = [];
|
|
974
|
-
const dirName = basename5(skill.sourceDir);
|
|
975
|
-
const declaredName = skill.meta.name;
|
|
976
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
977
|
-
errors.push('Missing required frontmatter field "name".');
|
|
978
|
-
} else {
|
|
979
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
980
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
981
|
-
}
|
|
982
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
983
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
984
|
-
}
|
|
985
|
-
if (declaredName !== dirName) {
|
|
986
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
const description = skill.meta.description;
|
|
990
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
991
|
-
errors.push('Missing required frontmatter field "description".');
|
|
992
|
-
}
|
|
993
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
994
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
995
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
996
|
-
}
|
|
997
|
-
return errors;
|
|
998
|
-
}
|
|
999
|
-
function skillMatchesTarget(skill, targetId) {
|
|
1000
|
-
const { targets } = skill.meta;
|
|
1001
|
-
if (!targets || targets === "*")
|
|
1002
|
-
return true;
|
|
1003
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
1004
|
-
return true;
|
|
1005
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
// src/core/pack-loader.ts
|
|
1009
|
-
import { existsSync as existsSync7 } from "fs";
|
|
1010
|
-
import { isAbsolute, resolve as resolve3 } from "path";
|
|
1011
|
-
class PackLoader {
|
|
1012
|
-
projectRoot;
|
|
1013
|
-
config;
|
|
1014
|
-
constructor(projectRoot, config) {
|
|
1015
|
-
this.projectRoot = projectRoot;
|
|
1016
|
-
this.config = config;
|
|
1017
|
-
}
|
|
1018
|
-
loadAll() {
|
|
1019
|
-
const warnings = [];
|
|
1020
|
-
const packs = [];
|
|
1021
|
-
const disabledSet = new Set(this.config.disabled);
|
|
1022
|
-
for (const packRef of this.config.packs) {
|
|
1023
|
-
const packDir = this.resolvePackPath(packRef);
|
|
1024
|
-
if (!packDir) {
|
|
1025
|
-
warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
|
|
1026
|
-
continue;
|
|
1027
|
-
}
|
|
1028
|
-
if (!existsSync7(packDir)) {
|
|
1029
|
-
warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
|
|
1030
|
-
continue;
|
|
1031
|
-
}
|
|
1032
|
-
const manifest = loadPackManifest(packDir);
|
|
1033
|
-
if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
|
|
1034
|
-
continue;
|
|
1035
|
-
}
|
|
1036
|
-
const loaded = this.loadPack(packDir, manifest);
|
|
1037
|
-
packs.push(loaded);
|
|
1038
|
-
}
|
|
1039
|
-
return { packs, warnings };
|
|
1040
|
-
}
|
|
1041
|
-
loadPack(packDir, manifest) {
|
|
1042
|
-
const name = manifest.name;
|
|
1043
|
-
const rulesDir = resolve3(packDir, "rules");
|
|
1044
|
-
const commandsDir = resolve3(packDir, "commands");
|
|
1045
|
-
const agentsDir = resolve3(packDir, "agents");
|
|
1046
|
-
const skillsDir = resolve3(packDir, "skills");
|
|
1047
|
-
return {
|
|
1048
|
-
manifest,
|
|
1049
|
-
directory: packDir,
|
|
1050
|
-
rules: existsSync7(rulesDir) ? parseRules(rulesDir, name) : [],
|
|
1051
|
-
commands: existsSync7(commandsDir) ? parseCommands(commandsDir, name) : [],
|
|
1052
|
-
agents: existsSync7(agentsDir) ? parseAgents(agentsDir, name) : [],
|
|
1053
|
-
skills: existsSync7(skillsDir) ? parseSkills(skillsDir, name) : [],
|
|
1054
|
-
hooks: parseHooks(packDir, name),
|
|
1055
|
-
plugins: parsePlugins(packDir, name),
|
|
1056
|
-
mcp: parseMcp(packDir, name),
|
|
1057
|
-
ignore: parseIgnore(packDir, name),
|
|
1058
|
-
models: parseModels(packDir, name)
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
loadForBaseDir(baseDir) {
|
|
1062
|
-
const baseDirRoot = resolve3(this.projectRoot, baseDir);
|
|
1063
|
-
const localConfigPath = resolve3(baseDirRoot, "agentpacks.jsonc");
|
|
1064
|
-
if (!existsSync7(localConfigPath)) {
|
|
1065
|
-
return { packs: [], warnings: [] };
|
|
1066
|
-
}
|
|
1067
|
-
const localConfig = loadWorkspaceConfig(baseDirRoot);
|
|
1068
|
-
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
1069
|
-
return loader.loadAll();
|
|
1070
|
-
}
|
|
1071
|
-
resolveCuratedPack(packRef) {
|
|
1072
|
-
const curatedDir = resolve3(this.projectRoot, ".agentpacks", ".curated");
|
|
1073
|
-
let packName = packRef;
|
|
1074
|
-
if (packName.startsWith("registry:"))
|
|
1075
|
-
packName = packName.slice(9);
|
|
1076
|
-
if (packName.startsWith("npm:"))
|
|
1077
|
-
packName = packName.slice(4);
|
|
1078
|
-
if (packName.startsWith("github:"))
|
|
1079
|
-
packName = packName.slice(7);
|
|
1080
|
-
if (packName.startsWith("@"))
|
|
1081
|
-
packName = packName.slice(1);
|
|
1082
|
-
if (packName.includes("/")) {
|
|
1083
|
-
const parts = packName.split("/");
|
|
1084
|
-
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
1085
|
-
}
|
|
1086
|
-
const withoutVersion = packName.split("@")[0] ?? packName;
|
|
1087
|
-
packName = withoutVersion.split(":")[0] ?? withoutVersion;
|
|
1088
|
-
const resolved = resolve3(curatedDir, packName);
|
|
1089
|
-
return existsSync7(resolved) ? resolved : null;
|
|
1090
|
-
}
|
|
1091
|
-
resolvePackPath(packRef) {
|
|
1092
|
-
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
1093
|
-
return resolve3(this.projectRoot, packRef);
|
|
1094
|
-
}
|
|
1095
|
-
if (isAbsolute(packRef)) {
|
|
1096
|
-
return packRef;
|
|
1097
|
-
}
|
|
1098
|
-
if (packRef.startsWith("registry:")) {
|
|
1099
|
-
return this.resolveCuratedPack(packRef);
|
|
1100
|
-
}
|
|
1101
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
1102
|
-
return this.resolveCuratedPack(packRef);
|
|
1103
|
-
}
|
|
1104
|
-
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
1105
|
-
return this.resolveCuratedPack(packRef);
|
|
1106
|
-
}
|
|
1107
|
-
return resolve3(this.projectRoot, packRef);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
export {
|
|
1111
|
-
setLockedSource,
|
|
1112
|
-
saveLockfile,
|
|
1113
|
-
resolveTargets,
|
|
1114
|
-
resolveFeatures,
|
|
1115
|
-
resolveDependencies,
|
|
1116
|
-
loadWorkspaceConfig,
|
|
1117
|
-
loadPackManifest,
|
|
1118
|
-
loadLockfile,
|
|
1119
|
-
isLockfileFrozenValid,
|
|
1120
|
-
getLockedSource,
|
|
1121
|
-
computeIntegrity,
|
|
1122
|
-
buildDependencyGraph,
|
|
1123
|
-
WorkspaceConfigSchema,
|
|
1124
|
-
TARGET_IDS,
|
|
1125
|
-
REPO_MODES,
|
|
1126
|
-
PackManifestSchema,
|
|
1127
|
-
PackLoader,
|
|
1128
|
-
FeatureMerger,
|
|
1129
|
-
FEATURE_IDS
|
|
1130
|
-
};
|
|
1
|
+
import{createRequire as ZB}from"node:module";var TQ=ZB(import.meta.url);import{existsSync as F,readFileSync as v}from"fs";import{parse as $B}from"jsonc-parser";import{resolve as E}from"path";import{z as X}from"zod";var S=["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"],y=["repo","monorepo","metarepo"],x=X.object({name:X.string().min(1),version:X.string().default("1.0.0"),description:X.string().default(""),author:X.union([X.string(),X.object({name:X.string(),email:X.string().optional()})]).optional(),homepage:X.string().optional(),repository:X.union([X.string(),X.object({url:X.string(),type:X.string().optional()})]).optional(),license:X.string().optional(),logo:X.string().optional(),tags:X.array(X.string()).default([]),dependencies:X.array(X.string()).default([]),conflicts:X.array(X.string()).default([]),targets:X.union([X.literal("*"),X.array(X.string())]).default("*"),features:X.union([X.literal("*"),X.array(X.string())]).default("*")}),YB=X.union([X.literal("*"),X.array(X.string()),X.record(X.string(),X.union([X.literal("*"),X.array(X.string())]))]),I=X.object({$schema:X.string().optional(),packs:X.array(X.string()).default(["./packs/default"]),disabled:X.array(X.string()).default([]),targets:X.union([X.literal("*"),X.array(X.string())]).default("*"),features:YB.default("*"),mode:X.enum(y).default("repo"),baseDirs:X.array(X.string()).default(["."]),global:X.boolean().default(!1),delete:X.boolean().default(!0),verbose:X.boolean().default(!1),silent:X.boolean().default(!1),overrides:X.record(X.string(),X.record(X.string(),X.string())).default({}),sources:X.array(X.object({source:X.string(),packs:X.array(X.string()).optional(),skills:X.array(X.string()).optional()})).default([]),modelProfile:X.string().optional()}),XB=["agentpacks.local.jsonc","agentpacks.jsonc"];function _(B){for(let W of XB){let Q=E(B,W);if(F(Q)){let Z=v(Q,"utf-8"),$=$B(Z);return I.parse($)}}return I.parse({})}function A(B){let W=E(B,"pack.json");if(!F(W)){let $=B.split("/").pop()??"unknown";return x.parse({name:$})}let Q=v(W,"utf-8"),Z=JSON.parse(Q);return x.parse(Z)}function VB(B,W){let{features:Q}=B;if(Q==="*")return[...O];if(Array.isArray(Q)){if(Q.includes("*"))return[...O];return Q.filter(($)=>O.includes($))}let Z=Q[W];if(!Z)return[];if(Z==="*")return[...O];if(Array.isArray(Z)&&Z.includes("*"))return[...O];return Z.filter(($)=>O.includes($))}function qB(B){if(B.targets==="*")return[...S];return B.targets}function R(B){let W=new Map;for(let Q of B)W.set(Q.name,{name:Q.name,manifest:Q,dependencies:Q.dependencies,conflicts:Q.conflicts});return W}function UB(B){let W=R(B),Q=new Set(W.keys()),Z=[];for(let[J,b]of W)for(let C of b.dependencies)if(!Q.has(C))Z.push([J,C]);let{sorted:$,cycles:Y}=JB(W),V=HB(W),U=Y.length===0&&V.length===0&&Z.length===0;return{sorted:$,cycles:Y,conflictPairs:V,missingDeps:Z,ok:U}}function JB(B){let W=new Map;for(let Y of B.keys())W.set(Y,0);for(let[,Y]of B)for(let V of Y.dependencies)if(B.has(V))W.set(V,(W.get(V)??0)+1);let Q=[];for(let[Y,V]of W)if(V===0)Q.push(Y);let Z=[];while(Q.length>0){let Y=Q.shift();if(!Y)continue;Z.push(Y);let V=B.get(Y);if(!V)continue;for(let U of V.dependencies){if(!B.has(U))continue;let J=(W.get(U)??1)-1;if(W.set(U,J),J===0)Q.push(U)}}let $=[];if(Z.length<B.size){let Y=new Set;for(let U of B.keys())if(!Z.includes(U))Y.add(U);let V=new Set;for(let U of Y){if(V.has(U))continue;let J=LB(U,B,Y);if(J.length>0){$.push(J);for(let b of J)V.add(b)}}}return{sorted:Z.reverse(),cycles:$}}function LB(B,W,Q){let Z=[],$=new Set,Y=B;while(Y&&!$.has(Y)){Z.push(Y),$.add(Y);let V=W.get(Y);if(!V)break;Y=V.dependencies.find((U)=>Q.has(U)&&W.has(U))}if(Y&&$.has(Y)){let V=Z.indexOf(Y);return Z.slice(V)}return Z}function HB(B){let W=[],Q=new Set;for(let[Z,$]of B)for(let Y of $.conflicts)if(B.has(Y)){let V=[Z,Y].sort().join(":");if(!Q.has(V))Q.add(V),W.push([Z,Y])}return W}import{existsSync as M,mkdirSync as GB,readdirSync as N,readFileSync as OB,rmSync as KB,statSync as D,writeFileSync as bB}from"fs";import{dirname as TB,join as z,relative as MB}from"path";var u="<!-- Generated by agentpacks. DO NOT EDIT. -->",h="// Generated by agentpacks. DO NOT EDIT.",k="// Generated by agentpacks. DO NOT EDIT.";function CB(B,W,Q={}){let{header:Z=!0,type:$}=Q,Y=$??IB(B);xB(TB(B));let V=W;if(Z){let U=_B(Y);if(U)V=`${U}
|
|
2
|
+
${W}`}bB(B,V,"utf-8")}function FQ(B,W,Q={}){let Z=JSON.stringify(W,null,2);CB(B,Z+`
|
|
3
|
+
`,{...Q,type:"json"})}function d(B){if(!M(B))return null;return OB(B,"utf-8")}function T(B){let W=d(B);if(W===null)return null;return JSON.parse(W)}function xB(B){if(!M(B))GB(B,{recursive:!0})}function vQ(B){if(M(B))KB(B,{recursive:!0,force:!0})}function L(B,W={}){let{extension:Q,recursive:Z=!1}=W;if(!M(B))return[];let $=[],Y=N(B);for(let V of Y){let U=z(B,V),J=D(U);if(J.isDirectory()&&Z)$.push(...L(U,W));else if(J.isFile()){if(!Q||V.endsWith(Q))$.push(U)}}return $}function m(B){if(!M(B))return[];return N(B).map((W)=>z(B,W)).filter((W)=>D(W).isDirectory())}function EQ(B,W){return MB(B,W)}function SQ(B){let W=d(B);if(!W)return!1;return W.startsWith(u)||W.startsWith(h)||W.startsWith(k)}function IB(B){if(B.endsWith(".json")||B.endsWith(".jsonc"))return"json";if(B.endsWith(".ts")||B.endsWith(".mts"))return"ts";if(B.endsWith(".js")||B.endsWith(".mjs"))return"js";return"md"}function _B(B){switch(B){case"md":return u;case"json":return h;case"js":case"ts":return k;default:return null}}import{join as AB}from"path";import{z as q}from"zod";var wB=[/["']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,}/],w=q.object({model:q.string(),temperature:q.number().min(0).max(2).optional(),top_p:q.number().min(0).max(1).optional()}),PB=q.object({extends:q.string().optional(),description:q.string().optional(),default:q.string().optional(),small:q.string().optional(),agents:q.record(q.string(),w).optional()}),zQ=q.object({complexity:q.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:q.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:q.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:q.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:q.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),jB=q.object({when:q.record(q.string(),q.string()),use:q.string(),description:q.string().optional(),priority:q.number().optional()}),FB=q.object({options:q.record(q.string(),q.unknown()).optional(),variants:q.record(q.string(),q.record(q.string(),q.unknown())).optional()}),vB=q.object({options:q.record(q.string(),q.unknown()).optional(),models:q.record(q.string(),FB).optional()}),EB=q.object({default:q.string().optional(),small:q.string().optional(),agents:q.record(q.string(),w).optional(),profiles:q.record(q.string(),PB).optional(),providers:q.record(q.string(),vB).optional(),routing:q.array(jB).optional(),overrides:q.record(q.string(),q.object({default:q.string().optional(),small:q.string().optional(),agents:q.record(q.string(),w).optional()})).optional()});function g(B,W){let Q=AB(B,"models.json"),Z=T(Q);if(!Z)return null;let $=EB.parse(Z);return{packName:W,sourcePath:Q,config:$}}function f(B){let W=[],Q={};for(let Z of B){let{config:$,packName:Y}=Z;if($.default!==void 0&&Q.default===void 0)Q.default=$.default;else if($.default!==void 0&&Q.default!==void 0)W.push(`Models "default" from pack "${Y}" skipped (already defined).`);if($.small!==void 0&&Q.small===void 0)Q.small=$.small;else if($.small!==void 0&&Q.small!==void 0)W.push(`Models "small" from pack "${Y}" skipped (already defined).`);if($.agents){if(!Q.agents)Q.agents={};for(let[V,U]of Object.entries($.agents)){if(V in Q.agents){W.push(`Models agent "${V}" from pack "${Y}" skipped (already defined).`);continue}Q.agents[V]=U}}if($.profiles){if(!Q.profiles)Q.profiles={};for(let[V,U]of Object.entries($.profiles)){if(V in Q.profiles){W.push(`Models profile "${V}" from pack "${Y}" skipped (already defined).`);continue}Q.profiles[V]=U}}if($.providers){if(!Q.providers)Q.providers={};for(let[V,U]of Object.entries($.providers))if(!(V in Q.providers))Q.providers[V]=U;else{let J=Q.providers[V];if(!J){Q.providers[V]=U;continue}if(U.options)J.options={...U.options,...J.options};if(U.models){if(!J.models)J.models={};for(let[b,C]of Object.entries(U.models))if(!(b in J.models))J.models[b]=C}}}if($.routing){if(!Q.routing)Q.routing=[];Q.routing.push(...$.routing)}if($.overrides){if(!Q.overrides)Q.overrides={};for(let[V,U]of Object.entries($.overrides)){if(V in Q.overrides){W.push(`Models override for target "${V}" from pack "${Y}" skipped (already defined).`);continue}Q.overrides[V]=U}}}return{config:Q,warnings:W}}function uQ(B){let W=[],Q=JSON.stringify(B);for(let Z of wB)if(Z.test(Q))W.push(`Potential secret detected in models.json matching pattern: ${Z.source}`);return W}class o{packs;warnings=[];constructor(B){this.packs=B}merge(){return this.warnings=[],{features:{rules:this.mergeRules(),commands:this.mergeByName("commands"),agents:this.mergeByName("agents"),skills:this.mergeByName("skills"),hooks:this.mergeHooks(),plugins:this.mergePlugins(),mcpServers:this.mergeMcp(),ignorePatterns:this.mergeIgnore(),models:this.mergeModels()},warnings:this.warnings}}mergeRules(){let B=new Map,W=[];for(let Q of this.packs)for(let Z of Q.rules){let $=B.get(Z.name);if($){this.warnings.push(`Rule "${Z.name}" from pack "${Z.packName}" skipped (already defined by "${$}").`);continue}B.set(Z.name,Z.packName),W.push(Z)}return W}mergeByName(B){let W=new Map,Q=[];for(let Z of this.packs){let $=Z[B];for(let Y of $){let V=W.get(Y.name);if(V){this.warnings.push(`${B.slice(0,-1)} "${Y.name}" from pack "${Y.packName}" skipped (already defined by "${V}").`);continue}W.set(Y.name,Y.packName),Q.push(Y)}}return Q}mergeHooks(){return this.packs.map((B)=>B.hooks).filter((B)=>B!==null)}mergePlugins(){let B=new Map,W=[];for(let Q of this.packs)for(let Z of Q.plugins){let $=`${Z.name}.${Z.extension}`,Y=B.get($);if(Y){this.warnings.push(`Plugin "${$}" from pack "${Z.packName}" skipped (already defined by "${Y}").`);continue}B.set($,Z.packName),W.push(Z)}return W}mergeMcp(){let B={};for(let W of this.packs){if(!W.mcp)continue;for(let[Q,Z]of Object.entries(W.mcp.servers)){if(Q in B){this.warnings.push(`MCP server "${Q}" from pack "${W.manifest.name}" skipped (already defined).`);continue}B[Q]=Z}}return B}mergeIgnore(){let B=new Set,W=[];for(let Q of this.packs){if(!Q.ignore)continue;for(let Z of Q.ignore.patterns)if(!B.has(Z))B.add(Z),W.push(Z)}return W}mergeModels(){let B=this.packs.map((Z)=>Z.models).filter((Z)=>Z!=null);if(B.length===0)return null;let{config:W,warnings:Q}=f(B);return this.warnings.push(...Q),W}}import{createHash as SB}from"crypto";import{existsSync as yB,readFileSync as RB,writeFileSync as NB}from"fs";import{resolve as p}from"path";var DB=1,c="agentpacks.lock";function zB(B){let W=p(B,c);if(!yB(W))return{lockfileVersion:DB,sources:{}};let Q=RB(W,"utf-8");return JSON.parse(Q)}function uB(B,W){let Q=p(B,c);NB(Q,JSON.stringify(W,null,2)+`
|
|
4
|
+
`)}function hB(B,W){return B.sources[W]}function kB(B,W,Q){B.sources[W]=Q}function dB(B){return`sha256-${SB("sha256").update(B).digest("hex")}`}function mB(B,W){let Q=W.filter((Z)=>!(Z in B.sources));return{valid:Q.length===0,missing:Q}}import n from"gray-matter";function G(B){let{data:W,content:Q}=n(B);return{data:W,content:Q.trim(),raw:B}}function P(B,W){let Q=Object.fromEntries(Object.entries(B).filter(([,Z])=>Z!==void 0));if(Object.keys(Q).length===0)return W;return n.stringify(W,Q)}import{readFileSync as gB}from"fs";import{basename as fB}from"path";function l(B,W){return L(B,{extension:".md"}).map((Z)=>oB(Z,W))}function oB(B,W){let Q=gB(B,"utf-8"),{data:Z,content:$}=G(Q);return{name:Z.name??fB(B,".md"),sourcePath:B,packName:W,meta:Z,content:$}}function rQ(B,W){let{targets:Q}=B.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(W)}import{readFileSync as pB}from"fs";import{basename as cB}from"path";function s(B,W){return L(B,{extension:".md"}).map((Z)=>nB(Z,W))}function nB(B,W){let Q=pB(B,"utf-8"),{data:Z,content:$}=G(Q);return{name:cB(B,".md"),sourcePath:B,packName:W,meta:Z,content:$}}function WW(B,W){let{targets:Q}=B.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(W)}import{join as lB}from"path";var sB=["cursor","claudecode","codexcli","opencode"];function i(B,W){let Q=lB(B,"hooks","hooks.json"),Z=T(Q);if(!Z)return null;let $=Z.hooks??{},Y={};for(let V of sB){let U=Z[V];if(U&&typeof U==="object"&&"hooks"in U&&U.hooks)Y[V]=U.hooks}return{packName:W,sourcePath:Q,version:Z.version,shared:$,targetOverrides:Y}}function XW(B,W){let Q={};for(let[$,Y]of Object.entries(B.shared))Q[$]=[...Y];let Z=B.targetOverrides[W];if(Z)for(let[$,Y]of Object.entries(Z))Q[$]=[...Q[$]??[],...Y];return Q}import{existsSync as iB,readFileSync as rB}from"fs";import{join as tB}from"path";var aB=["ignore",".aiignore"];function r(B,W){for(let Q of aB){let Z=tB(B,Q);if(iB(Z)){let $=rB(Z,"utf-8"),Y=eB($);return{packName:W,sourcePath:Z,patterns:Y}}}return null}function eB(B){return B.split(`
|
|
5
|
+
`).map((W)=>W.trim()).filter((W)=>W.length>0&&!W.startsWith("#"))}function JW(B){let W=new Set,Q=[];for(let Z of B)for(let $ of Z.patterns)if(!W.has($))W.add($),Q.push($);return Q}import{join as BQ}from"path";function t(B,W){let Q=BQ(B,"mcp.json"),Z=T(Q);if(!Z?.mcpServers)return null;return{packName:W,sourcePath:Q,servers:Z.mcpServers}}function OW(B){let W={},Q=[];for(let Z of B)for(let[$,Y]of Object.entries(Z.servers)){if($ in W){Q.push(`MCP server "${$}" from pack "${Z.packName}" skipped (already defined).`);continue}W[$]=Y}return{servers:W,warnings:Q}}import{existsSync as QQ,readFileSync as WQ}from"fs";import{basename as ZQ,join as $Q}from"path";function a(B,W){let Q=$Q(B,"plugins");if(!QQ(Q))return[];let Z=L(Q,{extension:".ts"}),$=L(Q,{extension:".js"});return[...Z,...$].map((V)=>YQ(V,W))}function YQ(B,W){let Q=WQ(B,"utf-8"),Z=B.endsWith(".ts")?"ts":"js";return{name:ZQ(B,`.${Z}`),sourcePath:B,packName:W,content:Q,extension:Z}}import{readFileSync as XQ}from"fs";import{basename as VQ}from"path";function e(B,W){return L(B,{extension:".md"}).map((Z)=>qQ(Z,W))}function qQ(B,W){let Q=XQ(B,"utf-8"),{data:Z,content:$}=G(Q);return{name:VQ(B,".md"),sourcePath:B,packName:W,meta:Z,content:$}}function wW(B,W){let{targets:Q}=B.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(W)}function PW(B){return B.filter((W)=>W.meta.root===!0)}function jW(B){return B.filter((W)=>W.meta.root!==!0)}import{existsSync as UQ,readFileSync as JQ}from"fs";import{basename as QB,join as LQ}from"path";var HQ=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,BB=64;function WB(B,W){let Q=m(B),Z=[];for(let $ of Q){let Y=LQ($,"SKILL.md");if(UQ(Y))Z.push(GQ(Y,$,W))}return Z}function GQ(B,W,Q){let Z=JQ(B,"utf-8"),{data:$,content:Y}=G(Z);return{name:$.name??QB(W),sourcePath:B,sourceDir:W,packName:Q,meta:$,content:Y}}function OQ(B){return{...B.meta,name:B.name}}function RW(B){return P(OQ(B),B.content)}function NW(B,W){let{data:Q,content:Z}=G(B),$={...Q,name:W},Y=!1,V=$.description;if(typeof V!=="string"||V.trim().length===0)$.description=`Imported skill: ${W}`,Y=!0;return{content:P($,Z),addedDescription:Y}}function DW(B){let W=[],Q=QB(B.sourceDir),Z=B.meta.name;if(typeof Z!=="string"||Z.trim().length===0)W.push('Missing required frontmatter field "name".');else{if(Z.length>BB)W.push(`Invalid "name": must be at most ${BB} characters.`);if(!HQ.test(Z))W.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==Q)W.push(`Invalid "name": must match containing directory "${Q}".`)}let $=B.meta.description;if(typeof $!=="string"||$.trim().length===0)W.push('Missing required frontmatter field "description".');let Y=B.meta["allowed-tools"];if(Y!==void 0&&(!Array.isArray(Y)||Y.some((V)=>typeof V!=="string"||V.length===0)))W.push('Invalid "allowed-tools": expected an array of non-empty strings.');return W}function zW(B,W){let{targets:Q}=B.meta;if(!Q||Q==="*")return!0;if(Array.isArray(Q)&&Q.includes("*"))return!0;return Array.isArray(Q)&&Q.includes(W)}import{existsSync as K}from"fs";import{isAbsolute as KQ,resolve as H}from"path";class j{projectRoot;config;constructor(B,W){this.projectRoot=B,this.config=W}loadAll(){let B=[],W=[],Q=new Set(this.config.disabled);for(let Z of this.config.packs){let $=this.resolvePackPath(Z);if(!$){B.push(`Pack "${Z}" could not be resolved. Skipping.`);continue}if(!K($)){B.push(`Pack directory "${$}" does not exist. Skipping.`);continue}let Y=A($);if(Q.has(Y.name)||Q.has(Z))continue;let V=this.loadPack($,Y);W.push(V)}return{packs:W,warnings:B}}loadPack(B,W){let Q=W.name,Z=H(B,"rules"),$=H(B,"commands"),Y=H(B,"agents"),V=H(B,"skills");return{manifest:W,directory:B,rules:K(Z)?e(Z,Q):[],commands:K($)?s($,Q):[],agents:K(Y)?l(Y,Q):[],skills:K(V)?WB(V,Q):[],hooks:i(B,Q),plugins:a(B,Q),mcp:t(B,Q),ignore:r(B,Q),models:g(B,Q)}}loadForBaseDir(B){let W=H(this.projectRoot,B),Q=H(W,"agentpacks.jsonc");if(!K(Q))return{packs:[],warnings:[]};let Z=_(W);return new j(W,Z).loadAll()}resolveCuratedPack(B){let W=H(this.projectRoot,".agentpacks",".curated"),Q=B;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 Y=Q.split("/");Q=Q.includes("@")?Y.join("-"):Y[Y.length-1]??Q}let Z=Q.split("@")[0]??Q;Q=Z.split(":")[0]??Z;let $=H(W,Q);return K($)?$:null}resolvePackPath(B){if(B.startsWith("./")||B.startsWith("../"))return H(this.projectRoot,B);if(KQ(B))return B;if(B.startsWith("registry:"))return this.resolveCuratedPack(B);if(B.startsWith("@")||B.startsWith("npm:")||!B.includes("/"))return this.resolveCuratedPack(B);if(B.startsWith("github:")||B.includes("/"))return this.resolveCuratedPack(B);return H(this.projectRoot,B)}}export{kB as setLockedSource,uB as saveLockfile,qB as resolveTargets,VB as resolveFeatures,UB as resolveDependencies,_ as loadWorkspaceConfig,A as loadPackManifest,zB as loadLockfile,mB as isLockfileFrozenValid,hB as getLockedSource,dB as computeIntegrity,R as buildDependencyGraph,I as WorkspaceConfigSchema,S as TARGET_IDS,y as REPO_MODES,x as PackManifestSchema,j as PackLoader,o as FeatureMerger,O as FEATURE_IDS};
|