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,1268 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
var TARGET_IDS = [
|
|
10
|
-
"opencode",
|
|
11
|
-
"cursor",
|
|
12
|
-
"claudecode",
|
|
13
|
-
"codexcli",
|
|
14
|
-
"mistralvibe",
|
|
15
|
-
"geminicli",
|
|
16
|
-
"copilot",
|
|
17
|
-
"agentsmd",
|
|
18
|
-
"cline",
|
|
19
|
-
"kilo",
|
|
20
|
-
"roo",
|
|
21
|
-
"qwencode",
|
|
22
|
-
"kiro",
|
|
23
|
-
"factorydroid",
|
|
24
|
-
"antigravity",
|
|
25
|
-
"junie",
|
|
26
|
-
"augmentcode",
|
|
27
|
-
"windsurf",
|
|
28
|
-
"warp",
|
|
29
|
-
"replit",
|
|
30
|
-
"zed"
|
|
31
|
-
];
|
|
32
|
-
var FEATURE_IDS = [
|
|
33
|
-
"rules",
|
|
34
|
-
"commands",
|
|
35
|
-
"agents",
|
|
36
|
-
"skills",
|
|
37
|
-
"hooks",
|
|
38
|
-
"plugins",
|
|
39
|
-
"mcp",
|
|
40
|
-
"ignore",
|
|
41
|
-
"models"
|
|
42
|
-
];
|
|
43
|
-
var REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
44
|
-
var PackManifestSchema = z.object({
|
|
45
|
-
name: z.string().min(1),
|
|
46
|
-
version: z.string().default("1.0.0"),
|
|
47
|
-
description: z.string().default(""),
|
|
48
|
-
author: z.union([
|
|
49
|
-
z.string(),
|
|
50
|
-
z.object({ name: z.string(), email: z.string().optional() })
|
|
51
|
-
]).optional(),
|
|
52
|
-
homepage: z.string().optional(),
|
|
53
|
-
repository: z.union([
|
|
54
|
-
z.string(),
|
|
55
|
-
z.object({ url: z.string(), type: z.string().optional() })
|
|
56
|
-
]).optional(),
|
|
57
|
-
license: z.string().optional(),
|
|
58
|
-
logo: z.string().optional(),
|
|
59
|
-
tags: z.array(z.string()).default([]),
|
|
60
|
-
dependencies: z.array(z.string()).default([]),
|
|
61
|
-
conflicts: z.array(z.string()).default([]),
|
|
62
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
63
|
-
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
64
|
-
});
|
|
65
|
-
var FeaturesSchema = z.union([
|
|
66
|
-
z.literal("*"),
|
|
67
|
-
z.array(z.string()),
|
|
68
|
-
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
69
|
-
]);
|
|
70
|
-
var WorkspaceConfigSchema = z.object({
|
|
71
|
-
$schema: z.string().optional(),
|
|
72
|
-
packs: z.array(z.string()).default(["./packs/default"]),
|
|
73
|
-
disabled: z.array(z.string()).default([]),
|
|
74
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
75
|
-
features: FeaturesSchema.default("*"),
|
|
76
|
-
mode: z.enum(REPO_MODES).default("repo"),
|
|
77
|
-
baseDirs: z.array(z.string()).default(["."]),
|
|
78
|
-
global: z.boolean().default(false),
|
|
79
|
-
delete: z.boolean().default(true),
|
|
80
|
-
verbose: z.boolean().default(false),
|
|
81
|
-
silent: z.boolean().default(false),
|
|
82
|
-
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
83
|
-
sources: z.array(z.object({
|
|
84
|
-
source: z.string(),
|
|
85
|
-
packs: z.array(z.string()).optional(),
|
|
86
|
-
skills: z.array(z.string()).optional()
|
|
87
|
-
})).default([]),
|
|
88
|
-
modelProfile: z.string().optional()
|
|
89
|
-
});
|
|
90
|
-
var CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
91
|
-
function loadWorkspaceConfig(projectRoot) {
|
|
92
|
-
for (const filename of CONFIG_FILES) {
|
|
93
|
-
const filepath = resolve(projectRoot, filename);
|
|
94
|
-
if (existsSync(filepath)) {
|
|
95
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
96
|
-
const parsed = parseJsonc(raw);
|
|
97
|
-
return WorkspaceConfigSchema.parse(parsed);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return WorkspaceConfigSchema.parse({});
|
|
101
|
-
}
|
|
102
|
-
function loadPackManifest(packDir) {
|
|
103
|
-
const filepath = resolve(packDir, "pack.json");
|
|
104
|
-
if (!existsSync(filepath)) {
|
|
105
|
-
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
106
|
-
return PackManifestSchema.parse({ name: dirName });
|
|
107
|
-
}
|
|
108
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
109
|
-
const parsed = JSON.parse(raw);
|
|
110
|
-
return PackManifestSchema.parse(parsed);
|
|
111
|
-
}
|
|
112
|
-
function resolveFeatures(config, targetId) {
|
|
113
|
-
const { features } = config;
|
|
114
|
-
if (features === "*") {
|
|
115
|
-
return [...FEATURE_IDS];
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(features)) {
|
|
118
|
-
if (features.includes("*"))
|
|
119
|
-
return [...FEATURE_IDS];
|
|
120
|
-
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
121
|
-
}
|
|
122
|
-
const targetFeatures = features[targetId];
|
|
123
|
-
if (!targetFeatures)
|
|
124
|
-
return [];
|
|
125
|
-
if (targetFeatures === "*")
|
|
126
|
-
return [...FEATURE_IDS];
|
|
127
|
-
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
128
|
-
return [...FEATURE_IDS];
|
|
129
|
-
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
130
|
-
}
|
|
131
|
-
function resolveTargets(config) {
|
|
132
|
-
if (config.targets === "*")
|
|
133
|
-
return [...TARGET_IDS];
|
|
134
|
-
return config.targets;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/utils/filesystem.ts
|
|
138
|
-
import {
|
|
139
|
-
existsSync as existsSync2,
|
|
140
|
-
mkdirSync,
|
|
141
|
-
readdirSync,
|
|
142
|
-
readFileSync as readFileSync2,
|
|
143
|
-
rmSync,
|
|
144
|
-
statSync,
|
|
145
|
-
writeFileSync
|
|
146
|
-
} from "fs";
|
|
147
|
-
import { dirname, join, relative } from "path";
|
|
148
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
149
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
150
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
151
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
152
|
-
const { header = true, type } = options;
|
|
153
|
-
const ext = type ?? inferFileType(filepath);
|
|
154
|
-
ensureDir(dirname(filepath));
|
|
155
|
-
let output = content;
|
|
156
|
-
if (header) {
|
|
157
|
-
const headerComment = getHeader(ext);
|
|
158
|
-
if (headerComment) {
|
|
159
|
-
output = `${headerComment}
|
|
160
|
-
${content}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
writeFileSync(filepath, output, "utf-8");
|
|
164
|
-
}
|
|
165
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
166
|
-
const json = JSON.stringify(data, null, 2);
|
|
167
|
-
writeGeneratedFile(filepath, json + `
|
|
168
|
-
`, { ...options, type: "json" });
|
|
169
|
-
}
|
|
170
|
-
function readFileOrNull(filepath) {
|
|
171
|
-
if (!existsSync2(filepath))
|
|
172
|
-
return null;
|
|
173
|
-
return readFileSync2(filepath, "utf-8");
|
|
174
|
-
}
|
|
175
|
-
function readJsonOrNull(filepath) {
|
|
176
|
-
const content = readFileOrNull(filepath);
|
|
177
|
-
if (content === null)
|
|
178
|
-
return null;
|
|
179
|
-
return JSON.parse(content);
|
|
180
|
-
}
|
|
181
|
-
function ensureDir(dirPath) {
|
|
182
|
-
if (!existsSync2(dirPath)) {
|
|
183
|
-
mkdirSync(dirPath, { recursive: true });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function removeIfExists(targetPath) {
|
|
187
|
-
if (existsSync2(targetPath)) {
|
|
188
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function listFiles(dirPath, options = {}) {
|
|
192
|
-
const { extension, recursive = false } = options;
|
|
193
|
-
if (!existsSync2(dirPath))
|
|
194
|
-
return [];
|
|
195
|
-
const results = [];
|
|
196
|
-
const entries = readdirSync(dirPath);
|
|
197
|
-
for (const entry of entries) {
|
|
198
|
-
const fullPath = join(dirPath, entry);
|
|
199
|
-
const stat = statSync(fullPath);
|
|
200
|
-
if (stat.isDirectory() && recursive) {
|
|
201
|
-
results.push(...listFiles(fullPath, options));
|
|
202
|
-
} else if (stat.isFile()) {
|
|
203
|
-
if (!extension || entry.endsWith(extension)) {
|
|
204
|
-
results.push(fullPath);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return results;
|
|
209
|
-
}
|
|
210
|
-
function listDirs(dirPath) {
|
|
211
|
-
if (!existsSync2(dirPath))
|
|
212
|
-
return [];
|
|
213
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
214
|
-
}
|
|
215
|
-
function relPath(projectRoot, filepath) {
|
|
216
|
-
return relative(projectRoot, filepath);
|
|
217
|
-
}
|
|
218
|
-
function isGeneratedFile(filepath) {
|
|
219
|
-
const content = readFileOrNull(filepath);
|
|
220
|
-
if (!content)
|
|
221
|
-
return false;
|
|
222
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
223
|
-
}
|
|
224
|
-
function inferFileType(filepath) {
|
|
225
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
226
|
-
return "json";
|
|
227
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
228
|
-
return "ts";
|
|
229
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
230
|
-
return "js";
|
|
231
|
-
return "md";
|
|
232
|
-
}
|
|
233
|
-
function getHeader(type) {
|
|
234
|
-
switch (type) {
|
|
235
|
-
case "md":
|
|
236
|
-
return GENERATED_HEADER_MD;
|
|
237
|
-
case "json":
|
|
238
|
-
return GENERATED_HEADER_JSON;
|
|
239
|
-
case "js":
|
|
240
|
-
case "ts":
|
|
241
|
-
return GENERATED_HEADER_JS;
|
|
242
|
-
default:
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/features/models.ts
|
|
248
|
-
import { join as join2 } from "path";
|
|
249
|
-
import { z as z2 } from "zod";
|
|
250
|
-
var SECRET_PATTERNS = [
|
|
251
|
-
/["']api[_-]?key["']\s*:/i,
|
|
252
|
-
/["']apiKey["']\s*:/i,
|
|
253
|
-
/["']secret["']\s*:/i,
|
|
254
|
-
/["']password["']\s*:/i,
|
|
255
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
256
|
-
/["']private[_-]?key["']\s*:/i,
|
|
257
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
258
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
259
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
260
|
-
];
|
|
261
|
-
var AgentModelSchema = z2.object({
|
|
262
|
-
model: z2.string(),
|
|
263
|
-
temperature: z2.number().min(0).max(2).optional(),
|
|
264
|
-
top_p: z2.number().min(0).max(1).optional()
|
|
265
|
-
});
|
|
266
|
-
var ModelProfileSchema = z2.object({
|
|
267
|
-
extends: z2.string().optional(),
|
|
268
|
-
description: z2.string().optional(),
|
|
269
|
-
default: z2.string().optional(),
|
|
270
|
-
small: z2.string().optional(),
|
|
271
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
272
|
-
});
|
|
273
|
-
var RoutingConditionSchema = z2.object({
|
|
274
|
-
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
275
|
-
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
276
|
-
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
277
|
-
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
278
|
-
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
279
|
-
});
|
|
280
|
-
var RoutingRuleSchema = z2.object({
|
|
281
|
-
when: z2.record(z2.string(), z2.string()),
|
|
282
|
-
use: z2.string(),
|
|
283
|
-
description: z2.string().optional(),
|
|
284
|
-
priority: z2.number().optional()
|
|
285
|
-
});
|
|
286
|
-
var ProviderModelSchema = z2.object({
|
|
287
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
288
|
-
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
289
|
-
});
|
|
290
|
-
var ProviderConfigSchema = z2.object({
|
|
291
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
292
|
-
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
293
|
-
});
|
|
294
|
-
var ModelsSchema = z2.object({
|
|
295
|
-
default: z2.string().optional(),
|
|
296
|
-
small: z2.string().optional(),
|
|
297
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
298
|
-
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
299
|
-
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
300
|
-
routing: z2.array(RoutingRuleSchema).optional(),
|
|
301
|
-
overrides: z2.record(z2.string(), z2.object({
|
|
302
|
-
default: z2.string().optional(),
|
|
303
|
-
small: z2.string().optional(),
|
|
304
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
305
|
-
})).optional()
|
|
306
|
-
});
|
|
307
|
-
function parseModels(packDir, packName) {
|
|
308
|
-
const modelsPath = join2(packDir, "models.json");
|
|
309
|
-
const raw = readJsonOrNull(modelsPath);
|
|
310
|
-
if (!raw)
|
|
311
|
-
return null;
|
|
312
|
-
const parsed = ModelsSchema.parse(raw);
|
|
313
|
-
return {
|
|
314
|
-
packName,
|
|
315
|
-
sourcePath: modelsPath,
|
|
316
|
-
config: parsed
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function mergeModelsConfigs(configs) {
|
|
320
|
-
const warnings = [];
|
|
321
|
-
const result = {};
|
|
322
|
-
for (const entry of configs) {
|
|
323
|
-
const { config, packName } = entry;
|
|
324
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
325
|
-
result.default = config.default;
|
|
326
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
327
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
328
|
-
}
|
|
329
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
330
|
-
result.small = config.small;
|
|
331
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
332
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
333
|
-
}
|
|
334
|
-
if (config.agents) {
|
|
335
|
-
if (!result.agents)
|
|
336
|
-
result.agents = {};
|
|
337
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
338
|
-
if (name in result.agents) {
|
|
339
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
result.agents[name] = assignment;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (config.profiles) {
|
|
346
|
-
if (!result.profiles)
|
|
347
|
-
result.profiles = {};
|
|
348
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
349
|
-
if (name in result.profiles) {
|
|
350
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
result.profiles[name] = profile;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (config.providers) {
|
|
357
|
-
if (!result.providers)
|
|
358
|
-
result.providers = {};
|
|
359
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
360
|
-
if (!(providerName in result.providers)) {
|
|
361
|
-
result.providers[providerName] = providerConfig;
|
|
362
|
-
} else {
|
|
363
|
-
const existing = result.providers[providerName];
|
|
364
|
-
if (!existing) {
|
|
365
|
-
result.providers[providerName] = providerConfig;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (providerConfig.options) {
|
|
369
|
-
existing.options = {
|
|
370
|
-
...providerConfig.options,
|
|
371
|
-
...existing.options
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
if (providerConfig.models) {
|
|
375
|
-
if (!existing.models)
|
|
376
|
-
existing.models = {};
|
|
377
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
378
|
-
if (!(modelName in existing.models)) {
|
|
379
|
-
existing.models[modelName] = modelConfig;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (config.routing) {
|
|
387
|
-
if (!result.routing)
|
|
388
|
-
result.routing = [];
|
|
389
|
-
result.routing.push(...config.routing);
|
|
390
|
-
}
|
|
391
|
-
if (config.overrides) {
|
|
392
|
-
if (!result.overrides)
|
|
393
|
-
result.overrides = {};
|
|
394
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
395
|
-
if (targetId in result.overrides) {
|
|
396
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
result.overrides[targetId] = override;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return { config: result, warnings };
|
|
404
|
-
}
|
|
405
|
-
function scanModelsForSecrets(config) {
|
|
406
|
-
const warnings = [];
|
|
407
|
-
const json = JSON.stringify(config);
|
|
408
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
409
|
-
if (pattern.test(json)) {
|
|
410
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return warnings;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/core/feature-merger.ts
|
|
417
|
-
class FeatureMerger {
|
|
418
|
-
packs;
|
|
419
|
-
warnings = [];
|
|
420
|
-
constructor(packs) {
|
|
421
|
-
this.packs = packs;
|
|
422
|
-
}
|
|
423
|
-
merge() {
|
|
424
|
-
this.warnings = [];
|
|
425
|
-
const features = {
|
|
426
|
-
rules: this.mergeRules(),
|
|
427
|
-
commands: this.mergeByName("commands"),
|
|
428
|
-
agents: this.mergeByName("agents"),
|
|
429
|
-
skills: this.mergeByName("skills"),
|
|
430
|
-
hooks: this.mergeHooks(),
|
|
431
|
-
plugins: this.mergePlugins(),
|
|
432
|
-
mcpServers: this.mergeMcp(),
|
|
433
|
-
ignorePatterns: this.mergeIgnore(),
|
|
434
|
-
models: this.mergeModels()
|
|
435
|
-
};
|
|
436
|
-
return { features, warnings: this.warnings };
|
|
437
|
-
}
|
|
438
|
-
mergeRules() {
|
|
439
|
-
const seen = new Map;
|
|
440
|
-
const result = [];
|
|
441
|
-
for (const pack of this.packs) {
|
|
442
|
-
for (const rule of pack.rules) {
|
|
443
|
-
const existing = seen.get(rule.name);
|
|
444
|
-
if (existing) {
|
|
445
|
-
this.warnings.push(`Rule "${rule.name}" from pack "${rule.packName}" skipped (already defined by "${existing}").`);
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
seen.set(rule.name, rule.packName);
|
|
449
|
-
result.push(rule);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
mergeByName(featureKey) {
|
|
455
|
-
const seen = new Map;
|
|
456
|
-
const result = [];
|
|
457
|
-
for (const pack of this.packs) {
|
|
458
|
-
const items = pack[featureKey];
|
|
459
|
-
for (const item of items) {
|
|
460
|
-
const existing = seen.get(item.name);
|
|
461
|
-
if (existing) {
|
|
462
|
-
this.warnings.push(`${featureKey.slice(0, -1)} "${item.name}" from pack "${item.packName}" skipped (already defined by "${existing}").`);
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
seen.set(item.name, item.packName);
|
|
466
|
-
result.push(item);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return result;
|
|
470
|
-
}
|
|
471
|
-
mergeHooks() {
|
|
472
|
-
return this.packs.map((p) => p.hooks).filter((h) => h !== null);
|
|
473
|
-
}
|
|
474
|
-
mergePlugins() {
|
|
475
|
-
const seen = new Map;
|
|
476
|
-
const result = [];
|
|
477
|
-
for (const pack of this.packs) {
|
|
478
|
-
for (const plugin of pack.plugins) {
|
|
479
|
-
const key = `${plugin.name}.${plugin.extension}`;
|
|
480
|
-
const existing = seen.get(key);
|
|
481
|
-
if (existing) {
|
|
482
|
-
this.warnings.push(`Plugin "${key}" from pack "${plugin.packName}" skipped (already defined by "${existing}").`);
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
seen.set(key, plugin.packName);
|
|
486
|
-
result.push(plugin);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return result;
|
|
490
|
-
}
|
|
491
|
-
mergeMcp() {
|
|
492
|
-
const servers = {};
|
|
493
|
-
for (const pack of this.packs) {
|
|
494
|
-
if (!pack.mcp)
|
|
495
|
-
continue;
|
|
496
|
-
for (const [name, entry] of Object.entries(pack.mcp.servers)) {
|
|
497
|
-
if (name in servers) {
|
|
498
|
-
this.warnings.push(`MCP server "${name}" from pack "${pack.manifest.name}" skipped (already defined).`);
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
servers[name] = entry;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return servers;
|
|
505
|
-
}
|
|
506
|
-
mergeIgnore() {
|
|
507
|
-
const seen = new Set;
|
|
508
|
-
const result = [];
|
|
509
|
-
for (const pack of this.packs) {
|
|
510
|
-
if (!pack.ignore)
|
|
511
|
-
continue;
|
|
512
|
-
for (const pattern of pack.ignore.patterns) {
|
|
513
|
-
if (!seen.has(pattern)) {
|
|
514
|
-
seen.add(pattern);
|
|
515
|
-
result.push(pattern);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return result;
|
|
520
|
-
}
|
|
521
|
-
mergeModels() {
|
|
522
|
-
const configs = this.packs.map((p) => p.models).filter((m) => m != null);
|
|
523
|
-
if (configs.length === 0)
|
|
524
|
-
return null;
|
|
525
|
-
const { config, warnings } = mergeModelsConfigs(configs);
|
|
526
|
-
this.warnings.push(...warnings);
|
|
527
|
-
return config;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// src/utils/frontmatter.ts
|
|
532
|
-
import matter from "gray-matter";
|
|
533
|
-
function parseFrontmatter(source) {
|
|
534
|
-
const { data, content } = matter(source);
|
|
535
|
-
return {
|
|
536
|
-
data,
|
|
537
|
-
content: content.trim(),
|
|
538
|
-
raw: source
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function serializeFrontmatter(data, content) {
|
|
542
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
543
|
-
if (Object.keys(filtered).length === 0) {
|
|
544
|
-
return content;
|
|
545
|
-
}
|
|
546
|
-
return matter.stringify(content, filtered);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// src/features/agents.ts
|
|
550
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
551
|
-
import { basename } from "path";
|
|
552
|
-
function parseAgents(agentsDir, packName) {
|
|
553
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
554
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
555
|
-
}
|
|
556
|
-
function parseAgentFile(filepath, packName) {
|
|
557
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
558
|
-
const { data, content } = parseFrontmatter(raw);
|
|
559
|
-
return {
|
|
560
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
561
|
-
sourcePath: filepath,
|
|
562
|
-
packName,
|
|
563
|
-
meta: data,
|
|
564
|
-
content
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function agentMatchesTarget(agent, targetId) {
|
|
568
|
-
const { targets } = agent.meta;
|
|
569
|
-
if (!targets || targets === "*")
|
|
570
|
-
return true;
|
|
571
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
572
|
-
return true;
|
|
573
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// src/features/commands.ts
|
|
577
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
578
|
-
import { basename as basename2 } from "path";
|
|
579
|
-
function parseCommands(commandsDir, packName) {
|
|
580
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
581
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
582
|
-
}
|
|
583
|
-
function parseCommandFile(filepath, packName) {
|
|
584
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
585
|
-
const { data, content } = parseFrontmatter(raw);
|
|
586
|
-
return {
|
|
587
|
-
name: basename2(filepath, ".md"),
|
|
588
|
-
sourcePath: filepath,
|
|
589
|
-
packName,
|
|
590
|
-
meta: data,
|
|
591
|
-
content
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
595
|
-
const { targets } = cmd.meta;
|
|
596
|
-
if (!targets || targets === "*")
|
|
597
|
-
return true;
|
|
598
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
599
|
-
return true;
|
|
600
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// src/features/hooks.ts
|
|
604
|
-
import { join as join3 } from "path";
|
|
605
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
606
|
-
function parseHooks(packDir, packName) {
|
|
607
|
-
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
608
|
-
const raw = readJsonOrNull(hooksPath);
|
|
609
|
-
if (!raw)
|
|
610
|
-
return null;
|
|
611
|
-
const shared = raw.hooks ?? {};
|
|
612
|
-
const targetOverrides = {};
|
|
613
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
614
|
-
const override = raw[key];
|
|
615
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
616
|
-
targetOverrides[key] = override.hooks;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
return {
|
|
620
|
-
packName,
|
|
621
|
-
sourcePath: hooksPath,
|
|
622
|
-
version: raw.version,
|
|
623
|
-
shared,
|
|
624
|
-
targetOverrides
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
628
|
-
const merged = {};
|
|
629
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
630
|
-
merged[event] = [...entries];
|
|
631
|
-
}
|
|
632
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
633
|
-
if (overrides) {
|
|
634
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
635
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return merged;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// src/features/ignore.ts
|
|
642
|
-
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
643
|
-
import { join as join4 } from "path";
|
|
644
|
-
var IGNORE_FILES = ["ignore", ".aiignore"];
|
|
645
|
-
function parseIgnore(packDir, packName) {
|
|
646
|
-
for (const filename of IGNORE_FILES) {
|
|
647
|
-
const filepath = join4(packDir, filename);
|
|
648
|
-
if (existsSync3(filepath)) {
|
|
649
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
650
|
-
const patterns = parseIgnoreContent(raw);
|
|
651
|
-
return {
|
|
652
|
-
packName,
|
|
653
|
-
sourcePath: filepath,
|
|
654
|
-
patterns
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
|
-
function parseIgnoreContent(content) {
|
|
661
|
-
return content.split(`
|
|
662
|
-
`).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
663
|
-
}
|
|
664
|
-
function mergeIgnorePatterns(configs) {
|
|
665
|
-
const seen = new Set;
|
|
666
|
-
const result = [];
|
|
667
|
-
for (const config of configs) {
|
|
668
|
-
for (const pattern of config.patterns) {
|
|
669
|
-
if (!seen.has(pattern)) {
|
|
670
|
-
seen.add(pattern);
|
|
671
|
-
result.push(pattern);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
return result;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// src/features/mcp.ts
|
|
679
|
-
import { join as join5 } from "path";
|
|
680
|
-
function parseMcp(packDir, packName) {
|
|
681
|
-
const mcpPath = join5(packDir, "mcp.json");
|
|
682
|
-
const raw = readJsonOrNull(mcpPath);
|
|
683
|
-
if (!raw?.mcpServers)
|
|
684
|
-
return null;
|
|
685
|
-
return {
|
|
686
|
-
packName,
|
|
687
|
-
sourcePath: mcpPath,
|
|
688
|
-
servers: raw.mcpServers
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
function mergeMcpConfigs(configs) {
|
|
692
|
-
const servers = {};
|
|
693
|
-
const warnings = [];
|
|
694
|
-
for (const config of configs) {
|
|
695
|
-
for (const [name, entry] of Object.entries(config.servers)) {
|
|
696
|
-
if (name in servers) {
|
|
697
|
-
warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
|
|
698
|
-
continue;
|
|
699
|
-
}
|
|
700
|
-
servers[name] = entry;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return { servers, warnings };
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// src/features/plugins.ts
|
|
707
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
708
|
-
import { basename as basename3, join as join6 } from "path";
|
|
709
|
-
function parsePlugins(packDir, packName) {
|
|
710
|
-
const pluginsDir = join6(packDir, "plugins");
|
|
711
|
-
if (!existsSync4(pluginsDir))
|
|
712
|
-
return [];
|
|
713
|
-
const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
|
|
714
|
-
const jsFiles = listFiles(pluginsDir, { extension: ".js" });
|
|
715
|
-
const allFiles = [...tsFiles, ...jsFiles];
|
|
716
|
-
return allFiles.map((filepath) => parsePluginFile(filepath, packName));
|
|
717
|
-
}
|
|
718
|
-
function parsePluginFile(filepath, packName) {
|
|
719
|
-
const content = readFileSync6(filepath, "utf-8");
|
|
720
|
-
const ext = filepath.endsWith(".ts") ? "ts" : "js";
|
|
721
|
-
return {
|
|
722
|
-
name: basename3(filepath, `.${ext}`),
|
|
723
|
-
sourcePath: filepath,
|
|
724
|
-
packName,
|
|
725
|
-
content,
|
|
726
|
-
extension: ext
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// src/features/rules.ts
|
|
731
|
-
import { readFileSync as readFileSync7 } from "fs";
|
|
732
|
-
import { basename as basename4 } from "path";
|
|
733
|
-
function parseRules(rulesDir, packName) {
|
|
734
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
735
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
736
|
-
}
|
|
737
|
-
function parseRuleFile(filepath, packName) {
|
|
738
|
-
const raw = readFileSync7(filepath, "utf-8");
|
|
739
|
-
const { data, content } = parseFrontmatter(raw);
|
|
740
|
-
return {
|
|
741
|
-
name: basename4(filepath, ".md"),
|
|
742
|
-
sourcePath: filepath,
|
|
743
|
-
packName,
|
|
744
|
-
meta: data,
|
|
745
|
-
content
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
749
|
-
const { targets } = rule.meta;
|
|
750
|
-
if (!targets || targets === "*")
|
|
751
|
-
return true;
|
|
752
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
753
|
-
return true;
|
|
754
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
755
|
-
}
|
|
756
|
-
function getRootRules(rules) {
|
|
757
|
-
return rules.filter((r) => r.meta.root === true);
|
|
758
|
-
}
|
|
759
|
-
function getDetailRules(rules) {
|
|
760
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// src/features/skills.ts
|
|
764
|
-
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
765
|
-
import { basename as basename5, join as join7 } from "path";
|
|
766
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
767
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
768
|
-
function parseSkills(skillsDir, packName) {
|
|
769
|
-
const dirs = listDirs(skillsDir);
|
|
770
|
-
const skills = [];
|
|
771
|
-
for (const dir of dirs) {
|
|
772
|
-
const skillMd = join7(dir, "SKILL.md");
|
|
773
|
-
if (existsSync5(skillMd)) {
|
|
774
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return skills;
|
|
778
|
-
}
|
|
779
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
780
|
-
const raw = readFileSync8(filepath, "utf-8");
|
|
781
|
-
const { data, content } = parseFrontmatter(raw);
|
|
782
|
-
return {
|
|
783
|
-
name: data.name ?? basename5(skillDir),
|
|
784
|
-
sourcePath: filepath,
|
|
785
|
-
sourceDir: skillDir,
|
|
786
|
-
packName,
|
|
787
|
-
meta: data,
|
|
788
|
-
content
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function buildSkillFrontmatter(skill) {
|
|
792
|
-
return {
|
|
793
|
-
...skill.meta,
|
|
794
|
-
name: skill.name
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
function serializeSkill(skill) {
|
|
798
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
799
|
-
}
|
|
800
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
801
|
-
const { data, content } = parseFrontmatter(source);
|
|
802
|
-
const normalized = {
|
|
803
|
-
...data,
|
|
804
|
-
name: skillName
|
|
805
|
-
};
|
|
806
|
-
let addedDescription = false;
|
|
807
|
-
const description = normalized.description;
|
|
808
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
809
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
810
|
-
addedDescription = true;
|
|
811
|
-
}
|
|
812
|
-
return {
|
|
813
|
-
content: serializeFrontmatter(normalized, content),
|
|
814
|
-
addedDescription
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
818
|
-
const errors = [];
|
|
819
|
-
const dirName = basename5(skill.sourceDir);
|
|
820
|
-
const declaredName = skill.meta.name;
|
|
821
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
822
|
-
errors.push('Missing required frontmatter field "name".');
|
|
823
|
-
} else {
|
|
824
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
825
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
826
|
-
}
|
|
827
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
828
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
829
|
-
}
|
|
830
|
-
if (declaredName !== dirName) {
|
|
831
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
const description = skill.meta.description;
|
|
835
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
836
|
-
errors.push('Missing required frontmatter field "description".');
|
|
837
|
-
}
|
|
838
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
839
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
840
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
841
|
-
}
|
|
842
|
-
return errors;
|
|
843
|
-
}
|
|
844
|
-
function skillMatchesTarget(skill, targetId) {
|
|
845
|
-
const { targets } = skill.meta;
|
|
846
|
-
if (!targets || targets === "*")
|
|
847
|
-
return true;
|
|
848
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
849
|
-
return true;
|
|
850
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// src/core/pack-loader.ts
|
|
854
|
-
import { existsSync as existsSync6 } from "fs";
|
|
855
|
-
import { isAbsolute, resolve as resolve2 } from "path";
|
|
856
|
-
class PackLoader {
|
|
857
|
-
projectRoot;
|
|
858
|
-
config;
|
|
859
|
-
constructor(projectRoot, config) {
|
|
860
|
-
this.projectRoot = projectRoot;
|
|
861
|
-
this.config = config;
|
|
862
|
-
}
|
|
863
|
-
loadAll() {
|
|
864
|
-
const warnings = [];
|
|
865
|
-
const packs = [];
|
|
866
|
-
const disabledSet = new Set(this.config.disabled);
|
|
867
|
-
for (const packRef of this.config.packs) {
|
|
868
|
-
const packDir = this.resolvePackPath(packRef);
|
|
869
|
-
if (!packDir) {
|
|
870
|
-
warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
|
|
871
|
-
continue;
|
|
872
|
-
}
|
|
873
|
-
if (!existsSync6(packDir)) {
|
|
874
|
-
warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
|
|
875
|
-
continue;
|
|
876
|
-
}
|
|
877
|
-
const manifest = loadPackManifest(packDir);
|
|
878
|
-
if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
|
|
879
|
-
continue;
|
|
880
|
-
}
|
|
881
|
-
const loaded = this.loadPack(packDir, manifest);
|
|
882
|
-
packs.push(loaded);
|
|
883
|
-
}
|
|
884
|
-
return { packs, warnings };
|
|
885
|
-
}
|
|
886
|
-
loadPack(packDir, manifest) {
|
|
887
|
-
const name = manifest.name;
|
|
888
|
-
const rulesDir = resolve2(packDir, "rules");
|
|
889
|
-
const commandsDir = resolve2(packDir, "commands");
|
|
890
|
-
const agentsDir = resolve2(packDir, "agents");
|
|
891
|
-
const skillsDir = resolve2(packDir, "skills");
|
|
892
|
-
return {
|
|
893
|
-
manifest,
|
|
894
|
-
directory: packDir,
|
|
895
|
-
rules: existsSync6(rulesDir) ? parseRules(rulesDir, name) : [],
|
|
896
|
-
commands: existsSync6(commandsDir) ? parseCommands(commandsDir, name) : [],
|
|
897
|
-
agents: existsSync6(agentsDir) ? parseAgents(agentsDir, name) : [],
|
|
898
|
-
skills: existsSync6(skillsDir) ? parseSkills(skillsDir, name) : [],
|
|
899
|
-
hooks: parseHooks(packDir, name),
|
|
900
|
-
plugins: parsePlugins(packDir, name),
|
|
901
|
-
mcp: parseMcp(packDir, name),
|
|
902
|
-
ignore: parseIgnore(packDir, name),
|
|
903
|
-
models: parseModels(packDir, name)
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
loadForBaseDir(baseDir) {
|
|
907
|
-
const baseDirRoot = resolve2(this.projectRoot, baseDir);
|
|
908
|
-
const localConfigPath = resolve2(baseDirRoot, "agentpacks.jsonc");
|
|
909
|
-
if (!existsSync6(localConfigPath)) {
|
|
910
|
-
return { packs: [], warnings: [] };
|
|
911
|
-
}
|
|
912
|
-
const localConfig = loadWorkspaceConfig(baseDirRoot);
|
|
913
|
-
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
914
|
-
return loader.loadAll();
|
|
915
|
-
}
|
|
916
|
-
resolveCuratedPack(packRef) {
|
|
917
|
-
const curatedDir = resolve2(this.projectRoot, ".agentpacks", ".curated");
|
|
918
|
-
let packName = packRef;
|
|
919
|
-
if (packName.startsWith("registry:"))
|
|
920
|
-
packName = packName.slice(9);
|
|
921
|
-
if (packName.startsWith("npm:"))
|
|
922
|
-
packName = packName.slice(4);
|
|
923
|
-
if (packName.startsWith("github:"))
|
|
924
|
-
packName = packName.slice(7);
|
|
925
|
-
if (packName.startsWith("@"))
|
|
926
|
-
packName = packName.slice(1);
|
|
927
|
-
if (packName.includes("/")) {
|
|
928
|
-
const parts = packName.split("/");
|
|
929
|
-
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
930
|
-
}
|
|
931
|
-
const withoutVersion = packName.split("@")[0] ?? packName;
|
|
932
|
-
packName = withoutVersion.split(":")[0] ?? withoutVersion;
|
|
933
|
-
const resolved = resolve2(curatedDir, packName);
|
|
934
|
-
return existsSync6(resolved) ? resolved : null;
|
|
935
|
-
}
|
|
936
|
-
resolvePackPath(packRef) {
|
|
937
|
-
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
938
|
-
return resolve2(this.projectRoot, packRef);
|
|
939
|
-
}
|
|
940
|
-
if (isAbsolute(packRef)) {
|
|
941
|
-
return packRef;
|
|
942
|
-
}
|
|
943
|
-
if (packRef.startsWith("registry:")) {
|
|
944
|
-
return this.resolveCuratedPack(packRef);
|
|
945
|
-
}
|
|
946
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
947
|
-
return this.resolveCuratedPack(packRef);
|
|
948
|
-
}
|
|
949
|
-
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
950
|
-
return this.resolveCuratedPack(packRef);
|
|
951
|
-
}
|
|
952
|
-
return resolve2(this.projectRoot, packRef);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// src/core/profile-resolver.ts
|
|
957
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
958
|
-
let defaultModel = merged.default;
|
|
959
|
-
let smallModel = merged.small;
|
|
960
|
-
let agents = { ...merged.agents };
|
|
961
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
962
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
963
|
-
if (resolvedProfile.default)
|
|
964
|
-
defaultModel = resolvedProfile.default;
|
|
965
|
-
if (resolvedProfile.small)
|
|
966
|
-
smallModel = resolvedProfile.small;
|
|
967
|
-
if (resolvedProfile.agents) {
|
|
968
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
if (targetId) {
|
|
972
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
973
|
-
if (targetOverride) {
|
|
974
|
-
if (targetOverride.default)
|
|
975
|
-
defaultModel = targetOverride.default;
|
|
976
|
-
if (targetOverride.small)
|
|
977
|
-
smallModel = targetOverride.small;
|
|
978
|
-
if (targetOverride.agents) {
|
|
979
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
const providers = {};
|
|
984
|
-
if (merged.providers) {
|
|
985
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
986
|
-
providers[name] = {
|
|
987
|
-
...config.options ? { options: config.options } : {},
|
|
988
|
-
...config.models ? { models: config.models } : {}
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
993
|
-
const profiles = {};
|
|
994
|
-
if (merged.profiles) {
|
|
995
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
996
|
-
profiles[name] = {
|
|
997
|
-
description: profile.description,
|
|
998
|
-
default: profile.default,
|
|
999
|
-
small: profile.small
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
return {
|
|
1004
|
-
default: defaultModel,
|
|
1005
|
-
small: smallModel,
|
|
1006
|
-
agents,
|
|
1007
|
-
providers,
|
|
1008
|
-
routing: merged.routing ?? [],
|
|
1009
|
-
profileNames,
|
|
1010
|
-
activeProfile: modelProfile,
|
|
1011
|
-
profiles
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
1015
|
-
const fromModels = resolved.agents[agentName];
|
|
1016
|
-
if (fromModels) {
|
|
1017
|
-
return {
|
|
1018
|
-
model: fromModels.model,
|
|
1019
|
-
temperature: fromModels.temperature,
|
|
1020
|
-
top_p: fromModels.top_p
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
if (frontmatterModel) {
|
|
1024
|
-
return { model: frontmatterModel };
|
|
1025
|
-
}
|
|
1026
|
-
return {};
|
|
1027
|
-
}
|
|
1028
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
1029
|
-
const visited = new Set;
|
|
1030
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
1031
|
-
}
|
|
1032
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
1033
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
1034
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
1035
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
1036
|
-
}
|
|
1037
|
-
if (visited.has(name)) {
|
|
1038
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" → ")}`);
|
|
1039
|
-
}
|
|
1040
|
-
const profile = profiles[name];
|
|
1041
|
-
if (!profile) {
|
|
1042
|
-
throw new Error(`Profile "${name}" not found`);
|
|
1043
|
-
}
|
|
1044
|
-
visited.add(name);
|
|
1045
|
-
if (!profile.extends) {
|
|
1046
|
-
return { ...profile };
|
|
1047
|
-
}
|
|
1048
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
1049
|
-
return {
|
|
1050
|
-
description: profile.description ?? parent.description,
|
|
1051
|
-
default: profile.default ?? parent.default,
|
|
1052
|
-
small: profile.small ?? parent.small,
|
|
1053
|
-
agents: {
|
|
1054
|
-
...parent.agents,
|
|
1055
|
-
...profile.agents
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
// src/utils/model-guidance.ts
|
|
1061
|
-
function generateModelGuidanceMarkdown(resolved) {
|
|
1062
|
-
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0 && Object.keys(resolved.profiles).length === 0) {
|
|
1063
|
-
return null;
|
|
1064
|
-
}
|
|
1065
|
-
const lines = [];
|
|
1066
|
-
lines.push("# Model Configuration");
|
|
1067
|
-
lines.push("");
|
|
1068
|
-
lines.push("Use the following model preferences when working in this project.");
|
|
1069
|
-
lines.push("");
|
|
1070
|
-
if (resolved.default || resolved.small) {
|
|
1071
|
-
lines.push("## Default Models");
|
|
1072
|
-
lines.push("");
|
|
1073
|
-
if (resolved.default) {
|
|
1074
|
-
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
1075
|
-
}
|
|
1076
|
-
if (resolved.small) {
|
|
1077
|
-
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
1078
|
-
}
|
|
1079
|
-
lines.push("");
|
|
1080
|
-
}
|
|
1081
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
1082
|
-
if (agentEntries.length > 0) {
|
|
1083
|
-
lines.push("## Agent Model Assignments");
|
|
1084
|
-
lines.push("");
|
|
1085
|
-
lines.push("| Agent | Model | Temperature |");
|
|
1086
|
-
lines.push("| --- | --- | --- |");
|
|
1087
|
-
for (const [name, assignment] of agentEntries) {
|
|
1088
|
-
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "—";
|
|
1089
|
-
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
1090
|
-
}
|
|
1091
|
-
lines.push("");
|
|
1092
|
-
}
|
|
1093
|
-
if (Object.keys(resolved.profiles).length > 0) {
|
|
1094
|
-
lines.push("## Available Profiles");
|
|
1095
|
-
lines.push("");
|
|
1096
|
-
lines.push("| Profile | Description | Default Model |");
|
|
1097
|
-
lines.push("| --- | --- | --- |");
|
|
1098
|
-
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
1099
|
-
lines.push(`| ${name} | ${profile.description ?? "—"} | ${profile.default ?? "—"} |`);
|
|
1100
|
-
}
|
|
1101
|
-
lines.push("");
|
|
1102
|
-
}
|
|
1103
|
-
if (resolved.activeProfile) {
|
|
1104
|
-
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
1105
|
-
lines.push("");
|
|
1106
|
-
}
|
|
1107
|
-
if (resolved.routing.length > 0) {
|
|
1108
|
-
lines.push("## Task-Aware Routing");
|
|
1109
|
-
lines.push("");
|
|
1110
|
-
lines.push("Select the appropriate profile based on the task context:");
|
|
1111
|
-
lines.push("");
|
|
1112
|
-
lines.push("| Condition | Profile | Description |");
|
|
1113
|
-
lines.push("| --- | --- | --- |");
|
|
1114
|
-
for (const rule of resolved.routing) {
|
|
1115
|
-
const conditions = Object.entries(rule.when).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
1116
|
-
const desc = rule.description ?? "—";
|
|
1117
|
-
lines.push(`| ${conditions} | ${rule.use} | ${desc} |`);
|
|
1118
|
-
}
|
|
1119
|
-
lines.push("");
|
|
1120
|
-
lines.push("### Condition Reference");
|
|
1121
|
-
lines.push("");
|
|
1122
|
-
lines.push("- **complexity**: low | medium | high | critical");
|
|
1123
|
-
lines.push("- **urgency**: low | normal | high");
|
|
1124
|
-
lines.push("- **budget**: minimal | standard | premium");
|
|
1125
|
-
lines.push("- **contextWindowNeed**: small | medium | large | max");
|
|
1126
|
-
lines.push("- **toolUseIntensity**: none | light | heavy");
|
|
1127
|
-
lines.push("");
|
|
1128
|
-
}
|
|
1129
|
-
return lines.join(`
|
|
1130
|
-
`);
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
// src/cli/models-explain.ts
|
|
1134
|
-
import chalk from "chalk";
|
|
1135
|
-
import { resolve as resolve3 } from "path";
|
|
1136
|
-
function runModelsExplain(options) {
|
|
1137
|
-
const projectRoot = resolve3(options.config ?? ".");
|
|
1138
|
-
const config = loadWorkspaceConfig(projectRoot);
|
|
1139
|
-
const loader = new PackLoader(projectRoot, config);
|
|
1140
|
-
const { packs } = loader.loadAll();
|
|
1141
|
-
if (packs.length === 0) {
|
|
1142
|
-
console.log(chalk.red("No packs loaded. Run `agentpacks init` first."));
|
|
1143
|
-
process.exit(1);
|
|
1144
|
-
}
|
|
1145
|
-
const merger = new FeatureMerger(packs);
|
|
1146
|
-
const { features: merged } = merger.merge();
|
|
1147
|
-
if (!merged.models) {
|
|
1148
|
-
console.log(chalk.dim("No model configuration found in your packs."));
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
const profile = options.profile;
|
|
1152
|
-
const target = options.target;
|
|
1153
|
-
const resolved = resolveModels(merged.models, profile, target);
|
|
1154
|
-
console.log(chalk.bold(`
|
|
1
|
+
import{createRequire as Uq}from"node:module";var KB=Uq(import.meta.url);import{existsSync as N,readFileSync as z}from"fs";import{parse as Jq}from"jsonc-parser";import{resolve as v}from"path";import{z as V}from"zod";var Kq=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],A=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],Lq=["repo","monorepo","metarepo"],R=V.object({name:V.string().min(1),version:V.string().default("1.0.0"),description:V.string().default(""),author:V.union([V.string(),V.object({name:V.string(),email:V.string().optional()})]).optional(),homepage:V.string().optional(),repository:V.union([V.string(),V.object({url:V.string(),type:V.string().optional()})]).optional(),license:V.string().optional(),logo:V.string().optional(),tags:V.array(V.string()).default([]),dependencies:V.array(V.string()).default([]),conflicts:V.array(V.string()).default([]),targets:V.union([V.literal("*"),V.array(V.string())]).default("*"),features:V.union([V.literal("*"),V.array(V.string())]).default("*")}),Hq=V.union([V.literal("*"),V.array(V.string()),V.record(V.string(),V.union([V.literal("*"),V.array(V.string())]))]),D=V.object({$schema:V.string().optional(),packs:V.array(V.string()).default(["./packs/default"]),disabled:V.array(V.string()).default([]),targets:V.union([V.literal("*"),V.array(V.string())]).default("*"),features:Hq.default("*"),mode:V.enum(Lq).default("repo"),baseDirs:V.array(V.string()).default(["."]),global:V.boolean().default(!1),delete:V.boolean().default(!0),verbose:V.boolean().default(!1),silent:V.boolean().default(!1),overrides:V.record(V.string(),V.record(V.string(),V.string())).default({}),sources:V.array(V.object({source:V.string(),packs:V.array(V.string()).optional(),skills:V.array(V.string()).optional()})).default([]),modelProfile:V.string().optional()}),Gq=["agentpacks.local.jsonc","agentpacks.jsonc"];function F(q){for(let Q of Gq){let B=v(q,Q);if(N(B)){let Z=z(B,"utf-8"),$=Jq(Z);return D.parse($)}}return D.parse({})}function u(q){let Q=v(q,"pack.json");if(!N(Q)){let $=q.split("/").pop()??"unknown";return R.parse({name:$})}let B=z(Q,"utf-8"),Z=JSON.parse(B);return R.parse(Z)}function CB(q,Q){let{features:B}=q;if(B==="*")return[...A];if(Array.isArray(B)){if(B.includes("*"))return[...A];return B.filter(($)=>A.includes($))}let Z=B[Q];if(!Z)return[];if(Z==="*")return[...A];if(Array.isArray(Z)&&Z.includes("*"))return[...A];return Z.filter(($)=>A.includes($))}function TB(q){if(q.targets==="*")return[...Kq];return q.targets}import{existsSync as M,mkdirSync as Oq,readdirSync as h,readFileSync as bq,rmSync as Cq,statSync as k,writeFileSync as Tq}from"fs";import{dirname as xq,join as g,relative as _q}from"path";var m="<!-- Generated by agentpacks. DO NOT EDIT. -->",f="// Generated by agentpacks. DO NOT EDIT.",d="// Generated by agentpacks. DO NOT EDIT.";function Aq(q,Q,B={}){let{header:Z=!0,type:$}=B,Y=$??jq(q);Iq(xq(q));let W=Q;if(Z){let J=Mq(Y);if(J)W=`${J}
|
|
2
|
+
${Q}`}Tq(q,W,"utf-8")}function IB(q,Q,B={}){let Z=JSON.stringify(Q,null,2);Aq(q,Z+`
|
|
3
|
+
`,{...B,type:"json"})}function p(q){if(!M(q))return null;return bq(q,"utf-8")}function I(q){let Q=p(q);if(Q===null)return null;return JSON.parse(Q)}function Iq(q){if(!M(q))Oq(q,{recursive:!0})}function jB(q){if(M(q))Cq(q,{recursive:!0,force:!0})}function O(q,Q={}){let{extension:B,recursive:Z=!1}=Q;if(!M(q))return[];let $=[],Y=h(q);for(let W of Y){let J=g(q,W),L=k(J);if(L.isDirectory()&&Z)$.push(...O(J,Q));else if(L.isFile()){if(!B||W.endsWith(B))$.push(J)}}return $}function c(q){if(!M(q))return[];return h(q).map((Q)=>g(q,Q)).filter((Q)=>k(Q).isDirectory())}function MB(q,Q){return _q(q,Q)}function wB(q){let Q=p(q);if(!Q)return!1;return Q.startsWith(m)||Q.startsWith(f)||Q.startsWith(d)}function jq(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 Mq(q){switch(q){case"md":return m;case"json":return f;case"js":case"ts":return d;default:return null}}import{join as wq}from"path";import{z as X}from"zod";var Fq=[/["']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,}/],E=X.object({model:X.string(),temperature:X.number().min(0).max(2).optional(),top_p:X.number().min(0).max(1).optional()}),Pq=X.object({extends:X.string().optional(),description:X.string().optional(),default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),E).optional()}),SB=X.object({complexity:X.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:X.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:X.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:X.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:X.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),Eq=X.object({when:X.record(X.string(),X.string()),use:X.string(),description:X.string().optional(),priority:X.number().optional()}),yq=X.object({options:X.record(X.string(),X.unknown()).optional(),variants:X.record(X.string(),X.record(X.string(),X.unknown())).optional()}),Sq=X.object({options:X.record(X.string(),X.unknown()).optional(),models:X.record(X.string(),yq).optional()}),Rq=X.object({default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),E).optional(),profiles:X.record(X.string(),Pq).optional(),providers:X.record(X.string(),Sq).optional(),routing:X.array(Eq).optional(),overrides:X.record(X.string(),X.object({default:X.string().optional(),small:X.string().optional(),agents:X.record(X.string(),E).optional()})).optional()});function n(q,Q){let B=wq(q,"models.json"),Z=I(B);if(!Z)return null;let $=Rq.parse(Z);return{packName:Q,sourcePath:B,config:$}}function o(q){let Q=[],B={};for(let Z of q){let{config:$,packName:Y}=Z;if($.default!==void 0&&B.default===void 0)B.default=$.default;else if($.default!==void 0&&B.default!==void 0)Q.push(`Models "default" from pack "${Y}" skipped (already defined).`);if($.small!==void 0&&B.small===void 0)B.small=$.small;else if($.small!==void 0&&B.small!==void 0)Q.push(`Models "small" from pack "${Y}" skipped (already defined).`);if($.agents){if(!B.agents)B.agents={};for(let[W,J]of Object.entries($.agents)){if(W in B.agents){Q.push(`Models agent "${W}" from pack "${Y}" skipped (already defined).`);continue}B.agents[W]=J}}if($.profiles){if(!B.profiles)B.profiles={};for(let[W,J]of Object.entries($.profiles)){if(W in B.profiles){Q.push(`Models profile "${W}" from pack "${Y}" skipped (already defined).`);continue}B.profiles[W]=J}}if($.providers){if(!B.providers)B.providers={};for(let[W,J]of Object.entries($.providers))if(!(W in B.providers))B.providers[W]=J;else{let L=B.providers[W];if(!L){B.providers[W]=J;continue}if(J.options)L.options={...J.options,...L.options};if(J.models){if(!L.models)L.models={};for(let[U,G]of Object.entries(J.models))if(!(U in L.models))L.models[U]=G}}}if($.routing){if(!B.routing)B.routing=[];B.routing.push(...$.routing)}if($.overrides){if(!B.overrides)B.overrides={};for(let[W,J]of Object.entries($.overrides)){if(W in B.overrides){Q.push(`Models override for target "${W}" from pack "${Y}" skipped (already defined).`);continue}B.overrides[W]=J}}}return{config:B,warnings:Q}}function RB(q){let Q=[],B=JSON.stringify(q);for(let Z of Fq)if(Z.test(B))Q.push(`Potential secret detected in models.json matching pattern: ${Z.source}`);return Q}class y{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 Z of B.rules){let $=q.get(Z.name);if($){this.warnings.push(`Rule "${Z.name}" from pack "${Z.packName}" skipped (already defined by "${$}").`);continue}q.set(Z.name,Z.packName),Q.push(Z)}return Q}mergeByName(q){let Q=new Map,B=[];for(let Z of this.packs){let $=Z[q];for(let Y of $){let W=Q.get(Y.name);if(W){this.warnings.push(`${q.slice(0,-1)} "${Y.name}" from pack "${Y.packName}" skipped (already defined by "${W}").`);continue}Q.set(Y.name,Y.packName),B.push(Y)}}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 Z of B.plugins){let $=`${Z.name}.${Z.extension}`,Y=q.get($);if(Y){this.warnings.push(`Plugin "${$}" from pack "${Z.packName}" skipped (already defined by "${Y}").`);continue}q.set($,Z.packName),Q.push(Z)}return Q}mergeMcp(){let q={};for(let Q of this.packs){if(!Q.mcp)continue;for(let[B,Z]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]=Z}}return q}mergeIgnore(){let q=new Set,Q=[];for(let B of this.packs){if(!B.ignore)continue;for(let Z of B.ignore.patterns)if(!q.has(Z))q.add(Z),Q.push(Z)}return Q}mergeModels(){let q=this.packs.map((Z)=>Z.models).filter((Z)=>Z!=null);if(q.length===0)return null;let{config:Q,warnings:B}=o(q);return this.warnings.push(...B),Q}}import l from"gray-matter";function T(q){let{data:Q,content:B}=l(q);return{data:Q,content:B.trim(),raw:q}}function S(q,Q){let B=Object.fromEntries(Object.entries(q).filter(([,Z])=>Z!==void 0));if(Object.keys(B).length===0)return Q;return l.stringify(Q,B)}import{readFileSync as Dq}from"fs";import{basename as Nq}from"path";function i(q,Q){return O(q,{extension:".md"}).map((Z)=>zq(Z,Q))}function zq(q,Q){let B=Dq(q,"utf-8"),{data:Z,content:$}=T(B);return{name:Z.name??Nq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function fB(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{readFileSync as vq}from"fs";import{basename as uq}from"path";function s(q,Q){return O(q,{extension:".md"}).map((Z)=>hq(Z,Q))}function hq(q,Q){let B=vq(q,"utf-8"),{data:Z,content:$}=T(B);return{name:uq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function lB(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{join as kq}from"path";var gq=["cursor","claudecode","codexcli","opencode"];function t(q,Q){let B=kq(q,"hooks","hooks.json"),Z=I(B);if(!Z)return null;let $=Z.hooks??{},Y={};for(let W of gq){let J=Z[W];if(J&&typeof J==="object"&&"hooks"in J&&J.hooks)Y[W]=J.hooks}return{packName:Q,sourcePath:B,version:Z.version,shared:$,targetOverrides:Y}}function rB(q,Q){let B={};for(let[$,Y]of Object.entries(q.shared))B[$]=[...Y];let Z=q.targetOverrides[Q];if(Z)for(let[$,Y]of Object.entries(Z))B[$]=[...B[$]??[],...Y];return B}import{existsSync as mq,readFileSync as fq}from"fs";import{join as dq}from"path";var pq=["ignore",".aiignore"];function r(q,Q){for(let B of pq){let Z=dq(q,B);if(mq(Z)){let $=fq(Z,"utf-8"),Y=cq($);return{packName:Q,sourcePath:Z,patterns:Y}}}return null}function cq(q){return q.split(`
|
|
4
|
+
`).map((Q)=>Q.trim()).filter((Q)=>Q.length>0&&!Q.startsWith("#"))}function BQ(q){let Q=new Set,B=[];for(let Z of q)for(let $ of Z.patterns)if(!Q.has($))Q.add($),B.push($);return B}import{join as nq}from"path";function a(q,Q){let B=nq(q,"mcp.json"),Z=I(B);if(!Z?.mcpServers)return null;return{packName:Q,sourcePath:B,servers:Z.mcpServers}}function YQ(q){let Q={},B=[];for(let Z of q)for(let[$,Y]of Object.entries(Z.servers)){if($ in Q){B.push(`MCP server "${$}" from pack "${Z.packName}" skipped (already defined).`);continue}Q[$]=Y}return{servers:Q,warnings:B}}import{existsSync as oq,readFileSync as lq}from"fs";import{basename as iq,join as sq}from"path";function e(q,Q){let B=sq(q,"plugins");if(!oq(B))return[];let Z=O(B,{extension:".ts"}),$=O(B,{extension:".js"});return[...Z,...$].map((W)=>tq(W,Q))}function tq(q,Q){let B=lq(q,"utf-8"),Z=q.endsWith(".ts")?"ts":"js";return{name:iq(q,`.${Z}`),sourcePath:q,packName:Q,content:B,extension:Z}}import{readFileSync as rq}from"fs";import{basename as aq}from"path";function qq(q,Q){return O(q,{extension:".md"}).map((Z)=>eq(Z,Q))}function eq(q,Q){let B=rq(q,"utf-8"),{data:Z,content:$}=T(B);return{name:aq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function OQ(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}function bQ(q){return q.filter((Q)=>Q.meta.root===!0)}function CQ(q){return q.filter((Q)=>Q.meta.root!==!0)}import{existsSync as qB,readFileSync as BB}from"fs";import{basename as Qq,join as QB}from"path";var ZB=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,Bq=64;function Zq(q,Q){let B=c(q),Z=[];for(let $ of B){let Y=QB($,"SKILL.md");if(qB(Y))Z.push($B(Y,$,Q))}return Z}function $B(q,Q,B){let Z=BB(q,"utf-8"),{data:$,content:Y}=T(Z);return{name:$.name??Qq(Q),sourcePath:q,sourceDir:Q,packName:B,meta:$,content:Y}}function YB(q){return{...q.meta,name:q.name}}function jQ(q){return S(YB(q),q.content)}function MQ(q,Q){let{data:B,content:Z}=T(q),$={...B,name:Q},Y=!1,W=$.description;if(typeof W!=="string"||W.trim().length===0)$.description=`Imported skill: ${Q}`,Y=!0;return{content:S($,Z),addedDescription:Y}}function wQ(q){let Q=[],B=Qq(q.sourceDir),Z=q.meta.name;if(typeof Z!=="string"||Z.trim().length===0)Q.push('Missing required frontmatter field "name".');else{if(Z.length>Bq)Q.push(`Invalid "name": must be at most ${Bq} characters.`);if(!ZB.test(Z))Q.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==B)Q.push(`Invalid "name": must match containing directory "${B}".`)}let $=q.meta.description;if(typeof $!=="string"||$.trim().length===0)Q.push('Missing required frontmatter field "description".');let Y=q.meta["allowed-tools"];if(Y!==void 0&&(!Array.isArray(Y)||Y.some((W)=>typeof W!=="string"||W.length===0)))Q.push('Invalid "allowed-tools": expected an array of non-empty strings.');return Q}function FQ(q,Q){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Q)}import{existsSync as _}from"fs";import{isAbsolute as VB,resolve as b}from"path";class P{projectRoot;config;constructor(q,Q){this.projectRoot=q,this.config=Q}loadAll(){let q=[],Q=[],B=new Set(this.config.disabled);for(let Z of this.config.packs){let $=this.resolvePackPath(Z);if(!$){q.push(`Pack "${Z}" could not be resolved. Skipping.`);continue}if(!_($)){q.push(`Pack directory "${$}" does not exist. Skipping.`);continue}let Y=u($);if(B.has(Y.name)||B.has(Z))continue;let W=this.loadPack($,Y);Q.push(W)}return{packs:Q,warnings:q}}loadPack(q,Q){let B=Q.name,Z=b(q,"rules"),$=b(q,"commands"),Y=b(q,"agents"),W=b(q,"skills");return{manifest:Q,directory:q,rules:_(Z)?qq(Z,B):[],commands:_($)?s($,B):[],agents:_(Y)?i(Y,B):[],skills:_(W)?Zq(W,B):[],hooks:t(q,B),plugins:e(q,B),mcp:a(q,B),ignore:r(q,B),models:n(q,B)}}loadForBaseDir(q){let Q=b(this.projectRoot,q),B=b(Q,"agentpacks.jsonc");if(!_(B))return{packs:[],warnings:[]};let Z=F(Q);return new P(Q,Z).loadAll()}resolveCuratedPack(q){let Q=b(this.projectRoot,".agentpacks",".curated"),B=q;if(B.startsWith("registry:"))B=B.slice(9);if(B.startsWith("npm:"))B=B.slice(4);if(B.startsWith("github:"))B=B.slice(7);if(B.startsWith("@"))B=B.slice(1);if(B.includes("/")){let Y=B.split("/");B=B.includes("@")?Y.join("-"):Y[Y.length-1]??B}let Z=B.split("@")[0]??B;B=Z.split(":")[0]??Z;let $=b(Q,B);return _($)?$:null}resolvePackPath(q){if(q.startsWith("./")||q.startsWith("../"))return b(this.projectRoot,q);if(VB(q))return q;if(q.startsWith("registry:"))return this.resolveCuratedPack(q);if(q.startsWith("@")||q.startsWith("npm:")||!q.includes("/"))return this.resolveCuratedPack(q);if(q.startsWith("github:")||q.includes("/"))return this.resolveCuratedPack(q);return b(this.projectRoot,q)}}function Yq(q,Q,B){let{default:Z,small:$}=q,Y={...q.agents};if(Q&&q.profiles?.[Q]){let U=WB(Q,q.profiles);if(U.default)Z=U.default;if(U.small)$=U.small;if(U.agents)Y={...Y,...U.agents}}if(B){let U=q.overrides?.[B];if(U){if(U.default)Z=U.default;if(U.small)$=U.small;if(U.agents)Y={...Y,...U.agents}}}let W={};if(q.providers)for(let[U,G]of Object.entries(q.providers))W[U]={...G.options?{options:G.options}:{},...G.models?{models:G.models}:{}};let J=Object.keys(q.profiles??{}),L={};if(q.profiles)for(let[U,G]of Object.entries(q.profiles))L[U]={description:G.description,default:G.default,small:G.small};return{default:Z,small:$,agents:Y,providers:W,routing:q.routing??[],profileNames:J,activeProfile:Q,profiles:L}}function fQ(q,Q,B){let Z=q.agents[Q];if(Z)return{model:Z.model,temperature:Z.temperature,top_p:Z.top_p};if(B)return{model:B};return{}}function WB(q,Q){return Vq(q,Q,new Set,0)}var $q=10;function Vq(q,Q,B,Z){if(Z>$q)throw Error(`Profile inheritance too deep (max ${$q}): ${q}`);if(B.has(q))throw Error(`Circular profile inheritance detected: ${[...B,q].join(" → ")}`);let $=Q[q];if(!$)throw Error(`Profile "${q}" not found`);if(B.add(q),!$.extends)return{...$};let Y=Vq($.extends,Q,B,Z+1);return{description:$.description??Y.description,default:$.default??Y.default,small:$.small??Y.small,agents:{...Y.agents,...$.agents}}}function Wq(q){if(!q.default&&!q.small&&Object.keys(q.agents).length===0&&Object.keys(q.profiles).length===0)return null;let Q=[];if(Q.push("# Model Configuration"),Q.push(""),Q.push("Use the following model preferences when working in this project."),Q.push(""),q.default||q.small){if(Q.push("## Default Models"),Q.push(""),q.default)Q.push(`- **Primary model**: ${q.default}`);if(q.small)Q.push(`- **Lightweight tasks** (titles, summaries): ${q.small}`);Q.push("")}let B=Object.entries(q.agents);if(B.length>0){Q.push("## Agent Model Assignments"),Q.push(""),Q.push("| Agent | Model | Temperature |"),Q.push("| --- | --- | --- |");for(let[Z,$]of B){let Y=$.temperature!==void 0?String($.temperature):"—";Q.push(`| ${Z} | ${$.model} | ${Y} |`)}Q.push("")}if(Object.keys(q.profiles).length>0){Q.push("## Available Profiles"),Q.push(""),Q.push("| Profile | Description | Default Model |"),Q.push("| --- | --- | --- |");for(let[Z,$]of Object.entries(q.profiles))Q.push(`| ${Z} | ${$.description??"—"} | ${$.default??"—"} |`);Q.push("")}if(q.activeProfile)Q.push(`**Active profile**: \`${q.activeProfile}\``),Q.push("");if(q.routing.length>0){Q.push("## Task-Aware Routing"),Q.push(""),Q.push("Select the appropriate profile based on the task context:"),Q.push(""),Q.push("| Condition | Profile | Description |"),Q.push("| --- | --- | --- |");for(let Z of q.routing){let $=Object.entries(Z.when).map(([W,J])=>`${W}=${J}`).join(", "),Y=Z.description??"—";Q.push(`| ${$} | ${Z.use} | ${Y} |`)}Q.push(""),Q.push("### Condition Reference"),Q.push(""),Q.push("- **complexity**: low | medium | high | critical"),Q.push("- **urgency**: low | normal | high"),Q.push("- **budget**: minimal | standard | premium"),Q.push("- **contextWindowNeed**: small | medium | large | max"),Q.push("- **toolUseIntensity**: none | light | heavy"),Q.push("")}return Q.join(`
|
|
5
|
+
`)}import K from"chalk";import{resolve as XB}from"path";function rQ(q){let Q=XB(q.config??"."),B=F(Q),Z=new P(Q,B),{packs:$}=Z.loadAll();if($.length===0)console.log(K.red("No packs loaded. Run `agentpacks init` first.")),process.exit(1);let Y=new y($),{features:W}=Y.merge();if(!W.models){console.log(K.dim("No model configuration found in your packs."));return}let{profile:J,target:L}=q,U=Yq(W.models,J,L);if(console.log(K.bold(`
|
|
1155
6
|
\uD83D\uDCCB Model Configuration Summary
|
|
1156
|
-
`));
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
if (
|
|
1161
|
-
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
if (target) {
|
|
1167
|
-
console.log(` ${chalk.dim("Target:")} ${chalk.yellow(target)}`);
|
|
1168
|
-
}
|
|
1169
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
1170
|
-
if (agentEntries.length > 0) {
|
|
1171
|
-
console.log(chalk.bold(`
|
|
1172
|
-
Agent Assignments:`));
|
|
1173
|
-
for (const [name, config2] of agentEntries) {
|
|
1174
|
-
const temp = config2.temperature !== undefined ? ` (temp: ${config2.temperature})` : "";
|
|
1175
|
-
console.log(` ${chalk.dim("•")} ${name}: ${chalk.cyan(config2.model)}${chalk.dim(temp)}`);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
if (resolved.profileNames.length > 0) {
|
|
1179
|
-
console.log(chalk.bold(`
|
|
1180
|
-
Available Profiles:`));
|
|
1181
|
-
for (const name of resolved.profileNames) {
|
|
1182
|
-
const profileData = resolved.profiles[name];
|
|
1183
|
-
const desc = profileData?.description ?? "";
|
|
1184
|
-
const active = name === resolved.activeProfile ? chalk.green(" ← active") : "";
|
|
1185
|
-
console.log(` ${chalk.dim("•")} ${name}${active}${desc ? chalk.dim(` — ${desc}`) : ""}`);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
if (resolved.routing.length > 0) {
|
|
1189
|
-
console.log(chalk.bold(`
|
|
1190
|
-
Routing Rules:`));
|
|
1191
|
-
for (const rule of resolved.routing) {
|
|
1192
|
-
const conditions = Object.entries(rule.when).map(([k, v]) => `${chalk.yellow(k)}=${chalk.cyan(v)}`).join(", ");
|
|
1193
|
-
const desc = rule.description;
|
|
1194
|
-
console.log(` ${chalk.dim("•")} When ${conditions} → use ${chalk.green(rule.use)}${desc ? chalk.dim(` (${desc})`) : ""}`);
|
|
1195
|
-
}
|
|
1196
|
-
if (options.task) {
|
|
1197
|
-
console.log(chalk.bold(`
|
|
1198
|
-
Task Analysis:`));
|
|
1199
|
-
console.log(` ${chalk.dim("Task:")} "${options.task}"`);
|
|
1200
|
-
const matched = matchTaskToRouting(options.task, resolved.routing);
|
|
1201
|
-
if (matched) {
|
|
1202
|
-
console.log(` ${chalk.green("✓")} Matched rule: ${chalk.green(matched.use)}`);
|
|
1203
|
-
const conditions = Object.entries(matched.when).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
1204
|
-
console.log(` ${chalk.dim(" Conditions:")} ${conditions}`);
|
|
1205
|
-
} else {
|
|
1206
|
-
console.log(` ${chalk.yellow("○")} No routing rule matched — using default profile`);
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
1211
|
-
if (guidance) {
|
|
1212
|
-
console.log(chalk.bold(`
|
|
1213
|
-
Generated Guidance Preview:`));
|
|
1214
|
-
console.log(chalk.dim(" " + "─".repeat(50)));
|
|
1215
|
-
for (const line of guidance.split(`
|
|
1216
|
-
`).slice(0, 20)) {
|
|
1217
|
-
console.log(` ${chalk.dim(line)}`);
|
|
1218
|
-
}
|
|
1219
|
-
if (guidance.split(`
|
|
1220
|
-
`).length > 20) {
|
|
1221
|
-
console.log(chalk.dim(` ... (${guidance.split(`
|
|
1222
|
-
`).length - 20} more lines)`));
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
console.log("");
|
|
1226
|
-
}
|
|
1227
|
-
function matchTaskToRouting(task, routing) {
|
|
1228
|
-
const lowerTask = task.toLowerCase();
|
|
1229
|
-
const complexityKeywords = {
|
|
1230
|
-
critical: ["critical", "security", "production", "hotfix"],
|
|
1231
|
-
high: ["refactor", "architecture", "complex", "rewrite", "migrate"],
|
|
1232
|
-
medium: ["feature", "implement", "update", "modify"],
|
|
1233
|
-
low: ["fix", "typo", "comment", "rename", "format"]
|
|
1234
|
-
};
|
|
1235
|
-
const urgencyKeywords = {
|
|
1236
|
-
high: ["urgent", "asap", "emergency", "hotfix", "critical"],
|
|
1237
|
-
normal: ["feature", "implement", "add"],
|
|
1238
|
-
low: ["cleanup", "refactor", "docs", "todo"]
|
|
1239
|
-
};
|
|
1240
|
-
const inferred = {};
|
|
1241
|
-
for (const [level, keywords] of Object.entries(complexityKeywords)) {
|
|
1242
|
-
if (keywords.some((kw) => lowerTask.includes(kw))) {
|
|
1243
|
-
inferred["complexity"] = level;
|
|
1244
|
-
break;
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
for (const [level, keywords] of Object.entries(urgencyKeywords)) {
|
|
1248
|
-
if (keywords.some((kw) => lowerTask.includes(kw))) {
|
|
1249
|
-
inferred["urgency"] = level;
|
|
1250
|
-
break;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
for (const rule of routing) {
|
|
1254
|
-
const matches = Object.entries(rule.when).every(([key, value]) => {
|
|
1255
|
-
if (inferred[key] === value)
|
|
1256
|
-
return true;
|
|
1257
|
-
if (lowerTask.includes(value.toLowerCase()))
|
|
1258
|
-
return true;
|
|
1259
|
-
return false;
|
|
1260
|
-
});
|
|
1261
|
-
if (matches)
|
|
1262
|
-
return rule;
|
|
1263
|
-
}
|
|
1264
|
-
return null;
|
|
1265
|
-
}
|
|
1266
|
-
export {
|
|
1267
|
-
runModelsExplain
|
|
1268
|
-
};
|
|
7
|
+
`)),U.default)console.log(` ${K.dim("Default model:")} ${K.cyan(U.default)}`);if(U.small)console.log(` ${K.dim("Small model:")} ${K.cyan(U.small)}`);if(U.activeProfile)console.log(` ${K.dim("Active profile:")} ${K.green(U.activeProfile)}`);if(L)console.log(` ${K.dim("Target:")} ${K.yellow(L)}`);let G=Object.entries(U.agents);if(G.length>0){console.log(K.bold(`
|
|
8
|
+
Agent Assignments:`));for(let[H,x]of G){let C=x.temperature!==void 0?` (temp: ${x.temperature})`:"";console.log(` ${K.dim("•")} ${H}: ${K.cyan(x.model)}${K.dim(C)}`)}}if(U.profileNames.length>0){console.log(K.bold(`
|
|
9
|
+
Available Profiles:`));for(let H of U.profileNames){let C=U.profiles[H]?.description??"",j=H===U.activeProfile?K.green(" ← active"):"";console.log(` ${K.dim("•")} ${H}${j}${C?K.dim(` — ${C}`):""}`)}}if(U.routing.length>0){console.log(K.bold(`
|
|
10
|
+
Routing Rules:`));for(let H of U.routing){let x=Object.entries(H.when).map(([j,Xq])=>`${K.yellow(j)}=${K.cyan(Xq)}`).join(", "),C=H.description;console.log(` ${K.dim("•")} When ${x} → use ${K.green(H.use)}${C?K.dim(` (${C})`):""}`)}if(q.task){console.log(K.bold(`
|
|
11
|
+
Task Analysis:`)),console.log(` ${K.dim("Task:")} "${q.task}"`);let H=UB(q.task,U.routing);if(H){console.log(` ${K.green("✓")} Matched rule: ${K.green(H.use)}`);let x=Object.entries(H.when).map(([C,j])=>`${C}=${j}`).join(", ");console.log(` ${K.dim(" Conditions:")} ${x}`)}else console.log(` ${K.yellow("○")} No routing rule matched — using default profile`)}}let w=Wq(U);if(w){console.log(K.bold(`
|
|
12
|
+
Generated Guidance Preview:`)),console.log(K.dim(" "+"─".repeat(50)));for(let H of w.split(`
|
|
13
|
+
`).slice(0,20))console.log(` ${K.dim(H)}`);if(w.split(`
|
|
14
|
+
`).length>20)console.log(K.dim(` ... (${w.split(`
|
|
15
|
+
`).length-20} more lines)`))}console.log("")}function UB(q,Q){let B=q.toLowerCase(),Z={critical:["critical","security","production","hotfix"],high:["refactor","architecture","complex","rewrite","migrate"],medium:["feature","implement","update","modify"],low:["fix","typo","comment","rename","format"]},$={high:["urgent","asap","emergency","hotfix","critical"],normal:["feature","implement","add"],low:["cleanup","refactor","docs","todo"]},Y={};for(let[W,J]of Object.entries(Z))if(J.some((L)=>B.includes(L))){Y.complexity=W;break}for(let[W,J]of Object.entries($))if(J.some((L)=>B.includes(L))){Y.urgency=W;break}for(let W of Q)if(Object.entries(W.when).every(([L,U])=>{if(Y[L]===U)return!0;if(B.includes(U.toLowerCase()))return!0;return!1}))return W;return null}export{rQ as runModelsExplain};
|