agentpacks 1.7.13 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
|
@@ -1,399 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// src/utils/filesystem.ts
|
|
5
|
-
import {
|
|
6
|
-
existsSync,
|
|
7
|
-
mkdirSync,
|
|
8
|
-
readdirSync,
|
|
9
|
-
readFileSync,
|
|
10
|
-
rmSync,
|
|
11
|
-
statSync,
|
|
12
|
-
writeFileSync
|
|
13
|
-
} from "fs";
|
|
14
|
-
import { dirname, join, relative } from "path";
|
|
15
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
16
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
17
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
18
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
19
|
-
const { header = true, type } = options;
|
|
20
|
-
const ext = type ?? inferFileType(filepath);
|
|
21
|
-
ensureDir(dirname(filepath));
|
|
22
|
-
let output = content;
|
|
23
|
-
if (header) {
|
|
24
|
-
const headerComment = getHeader(ext);
|
|
25
|
-
if (headerComment) {
|
|
26
|
-
output = `${headerComment}
|
|
27
|
-
${content}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
writeFileSync(filepath, output, "utf-8");
|
|
31
|
-
}
|
|
32
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
33
|
-
const json = JSON.stringify(data, null, 2);
|
|
34
|
-
writeGeneratedFile(filepath, json + `
|
|
35
|
-
`, { ...options, type: "json" });
|
|
36
|
-
}
|
|
37
|
-
function readFileOrNull(filepath) {
|
|
38
|
-
if (!existsSync(filepath))
|
|
39
|
-
return null;
|
|
40
|
-
return readFileSync(filepath, "utf-8");
|
|
41
|
-
}
|
|
42
|
-
function readJsonOrNull(filepath) {
|
|
43
|
-
const content = readFileOrNull(filepath);
|
|
44
|
-
if (content === null)
|
|
45
|
-
return null;
|
|
46
|
-
return JSON.parse(content);
|
|
47
|
-
}
|
|
48
|
-
function ensureDir(dirPath) {
|
|
49
|
-
if (!existsSync(dirPath)) {
|
|
50
|
-
mkdirSync(dirPath, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function removeIfExists(targetPath) {
|
|
54
|
-
if (existsSync(targetPath)) {
|
|
55
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function listFiles(dirPath, options = {}) {
|
|
59
|
-
const { extension, recursive = false } = options;
|
|
60
|
-
if (!existsSync(dirPath))
|
|
61
|
-
return [];
|
|
62
|
-
const results = [];
|
|
63
|
-
const entries = readdirSync(dirPath);
|
|
64
|
-
for (const entry of entries) {
|
|
65
|
-
const fullPath = join(dirPath, entry);
|
|
66
|
-
const stat = statSync(fullPath);
|
|
67
|
-
if (stat.isDirectory() && recursive) {
|
|
68
|
-
results.push(...listFiles(fullPath, options));
|
|
69
|
-
} else if (stat.isFile()) {
|
|
70
|
-
if (!extension || entry.endsWith(extension)) {
|
|
71
|
-
results.push(fullPath);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return results;
|
|
76
|
-
}
|
|
77
|
-
function listDirs(dirPath) {
|
|
78
|
-
if (!existsSync(dirPath))
|
|
79
|
-
return [];
|
|
80
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
81
|
-
}
|
|
82
|
-
function relPath(projectRoot, filepath) {
|
|
83
|
-
return relative(projectRoot, filepath);
|
|
84
|
-
}
|
|
85
|
-
function isGeneratedFile(filepath) {
|
|
86
|
-
const content = readFileOrNull(filepath);
|
|
87
|
-
if (!content)
|
|
88
|
-
return false;
|
|
89
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
90
|
-
}
|
|
91
|
-
function inferFileType(filepath) {
|
|
92
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
93
|
-
return "json";
|
|
94
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
95
|
-
return "ts";
|
|
96
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
97
|
-
return "js";
|
|
98
|
-
return "md";
|
|
99
|
-
}
|
|
100
|
-
function getHeader(type) {
|
|
101
|
-
switch (type) {
|
|
102
|
-
case "md":
|
|
103
|
-
return GENERATED_HEADER_MD;
|
|
104
|
-
case "json":
|
|
105
|
-
return GENERATED_HEADER_JSON;
|
|
106
|
-
case "js":
|
|
107
|
-
case "ts":
|
|
108
|
-
return GENERATED_HEADER_JS;
|
|
109
|
-
default:
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/features/models.ts
|
|
115
|
-
import { join as join2 } from "path";
|
|
116
|
-
import { z } from "zod";
|
|
117
|
-
var SECRET_PATTERNS = [
|
|
118
|
-
/["']api[_-]?key["']\s*:/i,
|
|
119
|
-
/["']apiKey["']\s*:/i,
|
|
120
|
-
/["']secret["']\s*:/i,
|
|
121
|
-
/["']password["']\s*:/i,
|
|
122
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
123
|
-
/["']private[_-]?key["']\s*:/i,
|
|
124
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
125
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
126
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
127
|
-
];
|
|
128
|
-
var AgentModelSchema = z.object({
|
|
129
|
-
model: z.string(),
|
|
130
|
-
temperature: z.number().min(0).max(2).optional(),
|
|
131
|
-
top_p: z.number().min(0).max(1).optional()
|
|
132
|
-
});
|
|
133
|
-
var ModelProfileSchema = z.object({
|
|
134
|
-
extends: z.string().optional(),
|
|
135
|
-
description: z.string().optional(),
|
|
136
|
-
default: z.string().optional(),
|
|
137
|
-
small: z.string().optional(),
|
|
138
|
-
agents: z.record(z.string(), AgentModelSchema).optional()
|
|
139
|
-
});
|
|
140
|
-
var RoutingConditionSchema = z.object({
|
|
141
|
-
complexity: z.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
142
|
-
urgency: z.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
143
|
-
budget: z.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
144
|
-
contextWindowNeed: z.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
145
|
-
toolUseIntensity: z.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
146
|
-
});
|
|
147
|
-
var RoutingRuleSchema = z.object({
|
|
148
|
-
when: z.record(z.string(), z.string()),
|
|
149
|
-
use: z.string(),
|
|
150
|
-
description: z.string().optional(),
|
|
151
|
-
priority: z.number().optional()
|
|
152
|
-
});
|
|
153
|
-
var ProviderModelSchema = z.object({
|
|
154
|
-
options: z.record(z.string(), z.unknown()).optional(),
|
|
155
|
-
variants: z.record(z.string(), z.record(z.string(), z.unknown())).optional()
|
|
156
|
-
});
|
|
157
|
-
var ProviderConfigSchema = z.object({
|
|
158
|
-
options: z.record(z.string(), z.unknown()).optional(),
|
|
159
|
-
models: z.record(z.string(), ProviderModelSchema).optional()
|
|
160
|
-
});
|
|
161
|
-
var ModelsSchema = z.object({
|
|
162
|
-
default: z.string().optional(),
|
|
163
|
-
small: z.string().optional(),
|
|
164
|
-
agents: z.record(z.string(), AgentModelSchema).optional(),
|
|
165
|
-
profiles: z.record(z.string(), ModelProfileSchema).optional(),
|
|
166
|
-
providers: z.record(z.string(), ProviderConfigSchema).optional(),
|
|
167
|
-
routing: z.array(RoutingRuleSchema).optional(),
|
|
168
|
-
overrides: z.record(z.string(), z.object({
|
|
169
|
-
default: z.string().optional(),
|
|
170
|
-
small: z.string().optional(),
|
|
171
|
-
agents: z.record(z.string(), AgentModelSchema).optional()
|
|
172
|
-
})).optional()
|
|
173
|
-
});
|
|
174
|
-
function parseModels(packDir, packName) {
|
|
175
|
-
const modelsPath = join2(packDir, "models.json");
|
|
176
|
-
const raw = readJsonOrNull(modelsPath);
|
|
177
|
-
if (!raw)
|
|
178
|
-
return null;
|
|
179
|
-
const parsed = ModelsSchema.parse(raw);
|
|
180
|
-
return {
|
|
181
|
-
packName,
|
|
182
|
-
sourcePath: modelsPath,
|
|
183
|
-
config: parsed
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function mergeModelsConfigs(configs) {
|
|
187
|
-
const warnings = [];
|
|
188
|
-
const result = {};
|
|
189
|
-
for (const entry of configs) {
|
|
190
|
-
const { config, packName } = entry;
|
|
191
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
192
|
-
result.default = config.default;
|
|
193
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
194
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
195
|
-
}
|
|
196
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
197
|
-
result.small = config.small;
|
|
198
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
199
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
200
|
-
}
|
|
201
|
-
if (config.agents) {
|
|
202
|
-
if (!result.agents)
|
|
203
|
-
result.agents = {};
|
|
204
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
205
|
-
if (name in result.agents) {
|
|
206
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
result.agents[name] = assignment;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (config.profiles) {
|
|
213
|
-
if (!result.profiles)
|
|
214
|
-
result.profiles = {};
|
|
215
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
216
|
-
if (name in result.profiles) {
|
|
217
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
result.profiles[name] = profile;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (config.providers) {
|
|
224
|
-
if (!result.providers)
|
|
225
|
-
result.providers = {};
|
|
226
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
227
|
-
if (!(providerName in result.providers)) {
|
|
228
|
-
result.providers[providerName] = providerConfig;
|
|
229
|
-
} else {
|
|
230
|
-
const existing = result.providers[providerName];
|
|
231
|
-
if (!existing) {
|
|
232
|
-
result.providers[providerName] = providerConfig;
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (providerConfig.options) {
|
|
236
|
-
existing.options = {
|
|
237
|
-
...providerConfig.options,
|
|
238
|
-
...existing.options
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (providerConfig.models) {
|
|
242
|
-
if (!existing.models)
|
|
243
|
-
existing.models = {};
|
|
244
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
245
|
-
if (!(modelName in existing.models)) {
|
|
246
|
-
existing.models[modelName] = modelConfig;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (config.routing) {
|
|
254
|
-
if (!result.routing)
|
|
255
|
-
result.routing = [];
|
|
256
|
-
result.routing.push(...config.routing);
|
|
257
|
-
}
|
|
258
|
-
if (config.overrides) {
|
|
259
|
-
if (!result.overrides)
|
|
260
|
-
result.overrides = {};
|
|
261
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
262
|
-
if (targetId in result.overrides) {
|
|
263
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
result.overrides[targetId] = override;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return { config: result, warnings };
|
|
271
|
-
}
|
|
272
|
-
function scanModelsForSecrets(config) {
|
|
273
|
-
const warnings = [];
|
|
274
|
-
const json = JSON.stringify(config);
|
|
275
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
276
|
-
if (pattern.test(json)) {
|
|
277
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return warnings;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// src/core/feature-merger.ts
|
|
284
|
-
class FeatureMerger {
|
|
285
|
-
packs;
|
|
286
|
-
warnings = [];
|
|
287
|
-
constructor(packs) {
|
|
288
|
-
this.packs = packs;
|
|
289
|
-
}
|
|
290
|
-
merge() {
|
|
291
|
-
this.warnings = [];
|
|
292
|
-
const features = {
|
|
293
|
-
rules: this.mergeRules(),
|
|
294
|
-
commands: this.mergeByName("commands"),
|
|
295
|
-
agents: this.mergeByName("agents"),
|
|
296
|
-
skills: this.mergeByName("skills"),
|
|
297
|
-
hooks: this.mergeHooks(),
|
|
298
|
-
plugins: this.mergePlugins(),
|
|
299
|
-
mcpServers: this.mergeMcp(),
|
|
300
|
-
ignorePatterns: this.mergeIgnore(),
|
|
301
|
-
models: this.mergeModels()
|
|
302
|
-
};
|
|
303
|
-
return { features, warnings: this.warnings };
|
|
304
|
-
}
|
|
305
|
-
mergeRules() {
|
|
306
|
-
const seen = new Map;
|
|
307
|
-
const result = [];
|
|
308
|
-
for (const pack of this.packs) {
|
|
309
|
-
for (const rule of pack.rules) {
|
|
310
|
-
const existing = seen.get(rule.name);
|
|
311
|
-
if (existing) {
|
|
312
|
-
this.warnings.push(`Rule "${rule.name}" from pack "${rule.packName}" skipped (already defined by "${existing}").`);
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
seen.set(rule.name, rule.packName);
|
|
316
|
-
result.push(rule);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return result;
|
|
320
|
-
}
|
|
321
|
-
mergeByName(featureKey) {
|
|
322
|
-
const seen = new Map;
|
|
323
|
-
const result = [];
|
|
324
|
-
for (const pack of this.packs) {
|
|
325
|
-
const items = pack[featureKey];
|
|
326
|
-
for (const item of items) {
|
|
327
|
-
const existing = seen.get(item.name);
|
|
328
|
-
if (existing) {
|
|
329
|
-
this.warnings.push(`${featureKey.slice(0, -1)} "${item.name}" from pack "${item.packName}" skipped (already defined by "${existing}").`);
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
seen.set(item.name, item.packName);
|
|
333
|
-
result.push(item);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return result;
|
|
337
|
-
}
|
|
338
|
-
mergeHooks() {
|
|
339
|
-
return this.packs.map((p) => p.hooks).filter((h) => h !== null);
|
|
340
|
-
}
|
|
341
|
-
mergePlugins() {
|
|
342
|
-
const seen = new Map;
|
|
343
|
-
const result = [];
|
|
344
|
-
for (const pack of this.packs) {
|
|
345
|
-
for (const plugin of pack.plugins) {
|
|
346
|
-
const key = `${plugin.name}.${plugin.extension}`;
|
|
347
|
-
const existing = seen.get(key);
|
|
348
|
-
if (existing) {
|
|
349
|
-
this.warnings.push(`Plugin "${key}" from pack "${plugin.packName}" skipped (already defined by "${existing}").`);
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
seen.set(key, plugin.packName);
|
|
353
|
-
result.push(plugin);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return result;
|
|
357
|
-
}
|
|
358
|
-
mergeMcp() {
|
|
359
|
-
const servers = {};
|
|
360
|
-
for (const pack of this.packs) {
|
|
361
|
-
if (!pack.mcp)
|
|
362
|
-
continue;
|
|
363
|
-
for (const [name, entry] of Object.entries(pack.mcp.servers)) {
|
|
364
|
-
if (name in servers) {
|
|
365
|
-
this.warnings.push(`MCP server "${name}" from pack "${pack.manifest.name}" skipped (already defined).`);
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
servers[name] = entry;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return servers;
|
|
372
|
-
}
|
|
373
|
-
mergeIgnore() {
|
|
374
|
-
const seen = new Set;
|
|
375
|
-
const result = [];
|
|
376
|
-
for (const pack of this.packs) {
|
|
377
|
-
if (!pack.ignore)
|
|
378
|
-
continue;
|
|
379
|
-
for (const pattern of pack.ignore.patterns) {
|
|
380
|
-
if (!seen.has(pattern)) {
|
|
381
|
-
seen.add(pattern);
|
|
382
|
-
result.push(pattern);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return result;
|
|
387
|
-
}
|
|
388
|
-
mergeModels() {
|
|
389
|
-
const configs = this.packs.map((p) => p.models).filter((m) => m != null);
|
|
390
|
-
if (configs.length === 0)
|
|
391
|
-
return null;
|
|
392
|
-
const { config, warnings } = mergeModelsConfigs(configs);
|
|
393
|
-
this.warnings.push(...warnings);
|
|
394
|
-
return config;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
export {
|
|
398
|
-
FeatureMerger
|
|
399
|
-
};
|
|
1
|
+
import{createRequire as w}from"node:module";var p=w(import.meta.url);import{existsSync as $,mkdirSync as C,readdirSync as K,readFileSync as A,rmSync as D,statSync as J,writeFileSync as v}from"fs";import{dirname as R,join as O,relative as x}from"path";var F="<!-- Generated by agentpacks. DO NOT EDIT. -->",G="// Generated by agentpacks. DO NOT EDIT.",H="// Generated by agentpacks. DO NOT EDIT.";function N(q,Q,B={}){let{header:U=!0,type:V}=B,X=V??P(q);k(R(q));let W=Q;if(U){let Y=y(X);if(Y)W=`${Y}
|
|
2
|
+
${Q}`}v(q,W,"utf-8")}function n(q,Q,B={}){let U=JSON.stringify(Q,null,2);N(q,U+`
|
|
3
|
+
`,{...B,type:"json"})}function j(q){if(!$(q))return null;return A(q,"utf-8")}function T(q){let Q=j(q);if(Q===null)return null;return JSON.parse(Q)}function k(q){if(!$(q))C(q,{recursive:!0})}function a(q){if($(q))D(q,{recursive:!0,force:!0})}function S(q,Q={}){let{extension:B,recursive:U=!1}=Q;if(!$(q))return[];let V=[],X=K(q);for(let W of X){let Y=O(q,W),Z=J(Y);if(Z.isDirectory()&&U)V.push(...S(Y,Q));else if(Z.isFile()){if(!B||W.endsWith(B))V.push(Y)}}return V}function r(q){if(!$(q))return[];return K(q).map((Q)=>O(q,Q)).filter((Q)=>J(Q).isDirectory())}function i(q,Q){return x(q,Q)}function t(q){let Q=j(q);if(!Q)return!1;return Q.startsWith(F)||Q.startsWith(G)||Q.startsWith(H)}function P(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 y(q){switch(q){case"md":return F;case"json":return G;case"js":case"ts":return H;default:return null}}import{join as E}from"path";import{z as L}from"zod";var z=[/["']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,}/],b=L.object({model:L.string(),temperature:L.number().min(0).max(2).optional(),top_p:L.number().min(0).max(1).optional()}),m=L.object({extends:L.string().optional(),description:L.string().optional(),default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),b).optional()}),Qq=L.object({complexity:L.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:L.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:L.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:L.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:L.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),d=L.object({when:L.record(L.string(),L.string()),use:L.string(),description:L.string().optional(),priority:L.number().optional()}),u=L.object({options:L.record(L.string(),L.unknown()).optional(),variants:L.record(L.string(),L.record(L.string(),L.unknown())).optional()}),h=L.object({options:L.record(L.string(),L.unknown()).optional(),models:L.record(L.string(),u).optional()}),g=L.object({default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),b).optional(),profiles:L.record(L.string(),m).optional(),providers:L.record(L.string(),h).optional(),routing:L.array(d).optional(),overrides:L.record(L.string(),L.object({default:L.string().optional(),small:L.string().optional(),agents:L.record(L.string(),b).optional()})).optional()});function Uq(q,Q){let B=E(q,"models.json"),U=T(B);if(!U)return null;let V=g.parse(U);return{packName:Q,sourcePath:B,config:V}}function M(q){let Q=[],B={};for(let U of q){let{config:V,packName:X}=U;if(V.default!==void 0&&B.default===void 0)B.default=V.default;else if(V.default!==void 0&&B.default!==void 0)Q.push(`Models "default" from pack "${X}" skipped (already defined).`);if(V.small!==void 0&&B.small===void 0)B.small=V.small;else if(V.small!==void 0&&B.small!==void 0)Q.push(`Models "small" from pack "${X}" skipped (already defined).`);if(V.agents){if(!B.agents)B.agents={};for(let[W,Y]of Object.entries(V.agents)){if(W in B.agents){Q.push(`Models agent "${W}" from pack "${X}" skipped (already defined).`);continue}B.agents[W]=Y}}if(V.profiles){if(!B.profiles)B.profiles={};for(let[W,Y]of Object.entries(V.profiles)){if(W in B.profiles){Q.push(`Models profile "${W}" from pack "${X}" skipped (already defined).`);continue}B.profiles[W]=Y}}if(V.providers){if(!B.providers)B.providers={};for(let[W,Y]of Object.entries(V.providers))if(!(W in B.providers))B.providers[W]=Y;else{let Z=B.providers[W];if(!Z){B.providers[W]=Y;continue}if(Y.options)Z.options={...Y.options,...Z.options};if(Y.models){if(!Z.models)Z.models={};for(let[I,_]of Object.entries(Y.models))if(!(I in Z.models))Z.models[I]=_}}}if(V.routing){if(!B.routing)B.routing=[];B.routing.push(...V.routing)}if(V.overrides){if(!B.overrides)B.overrides={};for(let[W,Y]of Object.entries(V.overrides)){if(W in B.overrides){Q.push(`Models override for target "${W}" from pack "${X}" skipped (already defined).`);continue}B.overrides[W]=Y}}}return{config:B,warnings:Q}}function Vq(q){let Q=[],B=JSON.stringify(q);for(let U of z)if(U.test(B))Q.push(`Potential secret detected in models.json matching pattern: ${U.source}`);return Q}class c{packs;warnings=[];constructor(q){this.packs=q}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 q=new Map,Q=[];for(let B of this.packs)for(let U of B.rules){let V=q.get(U.name);if(V){this.warnings.push(`Rule "${U.name}" from pack "${U.packName}" skipped (already defined by "${V}").`);continue}q.set(U.name,U.packName),Q.push(U)}return Q}mergeByName(q){let Q=new Map,B=[];for(let U of this.packs){let V=U[q];for(let X of V){let W=Q.get(X.name);if(W){this.warnings.push(`${q.slice(0,-1)} "${X.name}" from pack "${X.packName}" skipped (already defined by "${W}").`);continue}Q.set(X.name,X.packName),B.push(X)}}return B}mergeHooks(){return this.packs.map((q)=>q.hooks).filter((q)=>q!==null)}mergePlugins(){let q=new Map,Q=[];for(let B of this.packs)for(let U of B.plugins){let V=`${U.name}.${U.extension}`,X=q.get(V);if(X){this.warnings.push(`Plugin "${V}" from pack "${U.packName}" skipped (already defined by "${X}").`);continue}q.set(V,U.packName),Q.push(U)}return Q}mergeMcp(){let q={};for(let Q of this.packs){if(!Q.mcp)continue;for(let[B,U]of Object.entries(Q.mcp.servers)){if(B in q){this.warnings.push(`MCP server "${B}" from pack "${Q.manifest.name}" skipped (already defined).`);continue}q[B]=U}}return q}mergeIgnore(){let q=new Set,Q=[];for(let B of this.packs){if(!B.ignore)continue;for(let U of B.ignore.patterns)if(!q.has(U))q.add(U),Q.push(U)}return Q}mergeModels(){let q=this.packs.map((U)=>U.models).filter((U)=>U!=null);if(q.length===0)return null;let{config:Q,warnings:B}=M(q);return this.warnings.push(...B),Q}}export{c as FeatureMerger};
|