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,643 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
var TARGET_IDS = [
|
|
10
|
-
"opencode",
|
|
11
|
-
"cursor",
|
|
12
|
-
"claudecode",
|
|
13
|
-
"codexcli",
|
|
14
|
-
"mistralvibe",
|
|
15
|
-
"geminicli",
|
|
16
|
-
"copilot",
|
|
17
|
-
"agentsmd",
|
|
18
|
-
"cline",
|
|
19
|
-
"kilo",
|
|
20
|
-
"roo",
|
|
21
|
-
"qwencode",
|
|
22
|
-
"kiro",
|
|
23
|
-
"factorydroid",
|
|
24
|
-
"antigravity",
|
|
25
|
-
"junie",
|
|
26
|
-
"augmentcode",
|
|
27
|
-
"windsurf",
|
|
28
|
-
"warp",
|
|
29
|
-
"replit",
|
|
30
|
-
"zed"
|
|
31
|
-
];
|
|
32
|
-
var FEATURE_IDS = [
|
|
33
|
-
"rules",
|
|
34
|
-
"commands",
|
|
35
|
-
"agents",
|
|
36
|
-
"skills",
|
|
37
|
-
"hooks",
|
|
38
|
-
"plugins",
|
|
39
|
-
"mcp",
|
|
40
|
-
"ignore",
|
|
41
|
-
"models"
|
|
42
|
-
];
|
|
43
|
-
var REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
44
|
-
var PackManifestSchema = z.object({
|
|
45
|
-
name: z.string().min(1),
|
|
46
|
-
version: z.string().default("1.0.0"),
|
|
47
|
-
description: z.string().default(""),
|
|
48
|
-
author: z.union([
|
|
49
|
-
z.string(),
|
|
50
|
-
z.object({ name: z.string(), email: z.string().optional() })
|
|
51
|
-
]).optional(),
|
|
52
|
-
homepage: z.string().optional(),
|
|
53
|
-
repository: z.union([
|
|
54
|
-
z.string(),
|
|
55
|
-
z.object({ url: z.string(), type: z.string().optional() })
|
|
56
|
-
]).optional(),
|
|
57
|
-
license: z.string().optional(),
|
|
58
|
-
logo: z.string().optional(),
|
|
59
|
-
tags: z.array(z.string()).default([]),
|
|
60
|
-
dependencies: z.array(z.string()).default([]),
|
|
61
|
-
conflicts: z.array(z.string()).default([]),
|
|
62
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
63
|
-
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
64
|
-
});
|
|
65
|
-
var FeaturesSchema = z.union([
|
|
66
|
-
z.literal("*"),
|
|
67
|
-
z.array(z.string()),
|
|
68
|
-
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
69
|
-
]);
|
|
70
|
-
var WorkspaceConfigSchema = z.object({
|
|
71
|
-
$schema: z.string().optional(),
|
|
72
|
-
packs: z.array(z.string()).default(["./packs/default"]),
|
|
73
|
-
disabled: z.array(z.string()).default([]),
|
|
74
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
75
|
-
features: FeaturesSchema.default("*"),
|
|
76
|
-
mode: z.enum(REPO_MODES).default("repo"),
|
|
77
|
-
baseDirs: z.array(z.string()).default(["."]),
|
|
78
|
-
global: z.boolean().default(false),
|
|
79
|
-
delete: z.boolean().default(true),
|
|
80
|
-
verbose: z.boolean().default(false),
|
|
81
|
-
silent: z.boolean().default(false),
|
|
82
|
-
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
83
|
-
sources: z.array(z.object({
|
|
84
|
-
source: z.string(),
|
|
85
|
-
packs: z.array(z.string()).optional(),
|
|
86
|
-
skills: z.array(z.string()).optional()
|
|
87
|
-
})).default([]),
|
|
88
|
-
modelProfile: z.string().optional()
|
|
89
|
-
});
|
|
90
|
-
var CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
91
|
-
function loadWorkspaceConfig(projectRoot) {
|
|
92
|
-
for (const filename of CONFIG_FILES) {
|
|
93
|
-
const filepath = resolve(projectRoot, filename);
|
|
94
|
-
if (existsSync(filepath)) {
|
|
95
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
96
|
-
const parsed = parseJsonc(raw);
|
|
97
|
-
return WorkspaceConfigSchema.parse(parsed);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return WorkspaceConfigSchema.parse({});
|
|
101
|
-
}
|
|
102
|
-
function loadPackManifest(packDir) {
|
|
103
|
-
const filepath = resolve(packDir, "pack.json");
|
|
104
|
-
if (!existsSync(filepath)) {
|
|
105
|
-
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
106
|
-
return PackManifestSchema.parse({ name: dirName });
|
|
107
|
-
}
|
|
108
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
109
|
-
const parsed = JSON.parse(raw);
|
|
110
|
-
return PackManifestSchema.parse(parsed);
|
|
111
|
-
}
|
|
112
|
-
function resolveFeatures(config, targetId) {
|
|
113
|
-
const { features } = config;
|
|
114
|
-
if (features === "*") {
|
|
115
|
-
return [...FEATURE_IDS];
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(features)) {
|
|
118
|
-
if (features.includes("*"))
|
|
119
|
-
return [...FEATURE_IDS];
|
|
120
|
-
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
121
|
-
}
|
|
122
|
-
const targetFeatures = features[targetId];
|
|
123
|
-
if (!targetFeatures)
|
|
124
|
-
return [];
|
|
125
|
-
if (targetFeatures === "*")
|
|
126
|
-
return [...FEATURE_IDS];
|
|
127
|
-
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
128
|
-
return [...FEATURE_IDS];
|
|
129
|
-
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
130
|
-
}
|
|
131
|
-
function resolveTargets(config) {
|
|
132
|
-
if (config.targets === "*")
|
|
133
|
-
return [...TARGET_IDS];
|
|
134
|
-
return config.targets;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/utils/filesystem.ts
|
|
138
|
-
import {
|
|
139
|
-
existsSync as existsSync2,
|
|
140
|
-
mkdirSync,
|
|
141
|
-
readdirSync,
|
|
142
|
-
readFileSync as readFileSync2,
|
|
143
|
-
rmSync,
|
|
144
|
-
statSync,
|
|
145
|
-
writeFileSync
|
|
146
|
-
} from "fs";
|
|
147
|
-
import { dirname, join, relative } from "path";
|
|
148
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
149
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
150
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
151
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
152
|
-
const { header = true, type } = options;
|
|
153
|
-
const ext = type ?? inferFileType(filepath);
|
|
154
|
-
ensureDir(dirname(filepath));
|
|
155
|
-
let output = content;
|
|
156
|
-
if (header) {
|
|
157
|
-
const headerComment = getHeader(ext);
|
|
158
|
-
if (headerComment) {
|
|
159
|
-
output = `${headerComment}
|
|
160
|
-
${content}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
writeFileSync(filepath, output, "utf-8");
|
|
164
|
-
}
|
|
165
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
166
|
-
const json = JSON.stringify(data, null, 2);
|
|
167
|
-
writeGeneratedFile(filepath, json + `
|
|
168
|
-
`, { ...options, type: "json" });
|
|
169
|
-
}
|
|
170
|
-
function readFileOrNull(filepath) {
|
|
171
|
-
if (!existsSync2(filepath))
|
|
172
|
-
return null;
|
|
173
|
-
return readFileSync2(filepath, "utf-8");
|
|
174
|
-
}
|
|
175
|
-
function readJsonOrNull(filepath) {
|
|
176
|
-
const content = readFileOrNull(filepath);
|
|
177
|
-
if (content === null)
|
|
178
|
-
return null;
|
|
179
|
-
return JSON.parse(content);
|
|
180
|
-
}
|
|
181
|
-
function ensureDir(dirPath) {
|
|
182
|
-
if (!existsSync2(dirPath)) {
|
|
183
|
-
mkdirSync(dirPath, { recursive: true });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function removeIfExists(targetPath) {
|
|
187
|
-
if (existsSync2(targetPath)) {
|
|
188
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function listFiles(dirPath, options = {}) {
|
|
192
|
-
const { extension, recursive = false } = options;
|
|
193
|
-
if (!existsSync2(dirPath))
|
|
194
|
-
return [];
|
|
195
|
-
const results = [];
|
|
196
|
-
const entries = readdirSync(dirPath);
|
|
197
|
-
for (const entry of entries) {
|
|
198
|
-
const fullPath = join(dirPath, entry);
|
|
199
|
-
const stat = statSync(fullPath);
|
|
200
|
-
if (stat.isDirectory() && recursive) {
|
|
201
|
-
results.push(...listFiles(fullPath, options));
|
|
202
|
-
} else if (stat.isFile()) {
|
|
203
|
-
if (!extension || entry.endsWith(extension)) {
|
|
204
|
-
results.push(fullPath);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return results;
|
|
209
|
-
}
|
|
210
|
-
function listDirs(dirPath) {
|
|
211
|
-
if (!existsSync2(dirPath))
|
|
212
|
-
return [];
|
|
213
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
214
|
-
}
|
|
215
|
-
function relPath(projectRoot, filepath) {
|
|
216
|
-
return relative(projectRoot, filepath);
|
|
217
|
-
}
|
|
218
|
-
function isGeneratedFile(filepath) {
|
|
219
|
-
const content = readFileOrNull(filepath);
|
|
220
|
-
if (!content)
|
|
221
|
-
return false;
|
|
222
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
223
|
-
}
|
|
224
|
-
function inferFileType(filepath) {
|
|
225
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
226
|
-
return "json";
|
|
227
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
228
|
-
return "ts";
|
|
229
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
230
|
-
return "js";
|
|
231
|
-
return "md";
|
|
232
|
-
}
|
|
233
|
-
function getHeader(type) {
|
|
234
|
-
switch (type) {
|
|
235
|
-
case "md":
|
|
236
|
-
return GENERATED_HEADER_MD;
|
|
237
|
-
case "json":
|
|
238
|
-
return GENERATED_HEADER_JSON;
|
|
239
|
-
case "js":
|
|
240
|
-
case "ts":
|
|
241
|
-
return GENERATED_HEADER_JS;
|
|
242
|
-
default:
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/features/models.ts
|
|
248
|
-
import { join as join2 } from "path";
|
|
249
|
-
import { z as z2 } from "zod";
|
|
250
|
-
var SECRET_PATTERNS = [
|
|
251
|
-
/["']api[_-]?key["']\s*:/i,
|
|
252
|
-
/["']apiKey["']\s*:/i,
|
|
253
|
-
/["']secret["']\s*:/i,
|
|
254
|
-
/["']password["']\s*:/i,
|
|
255
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
256
|
-
/["']private[_-]?key["']\s*:/i,
|
|
257
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
258
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
259
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
260
|
-
];
|
|
261
|
-
var AgentModelSchema = z2.object({
|
|
262
|
-
model: z2.string(),
|
|
263
|
-
temperature: z2.number().min(0).max(2).optional(),
|
|
264
|
-
top_p: z2.number().min(0).max(1).optional()
|
|
265
|
-
});
|
|
266
|
-
var ModelProfileSchema = z2.object({
|
|
267
|
-
extends: z2.string().optional(),
|
|
268
|
-
description: z2.string().optional(),
|
|
269
|
-
default: z2.string().optional(),
|
|
270
|
-
small: z2.string().optional(),
|
|
271
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
272
|
-
});
|
|
273
|
-
var RoutingConditionSchema = z2.object({
|
|
274
|
-
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
275
|
-
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
276
|
-
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
277
|
-
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
278
|
-
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
279
|
-
});
|
|
280
|
-
var RoutingRuleSchema = z2.object({
|
|
281
|
-
when: z2.record(z2.string(), z2.string()),
|
|
282
|
-
use: z2.string(),
|
|
283
|
-
description: z2.string().optional(),
|
|
284
|
-
priority: z2.number().optional()
|
|
285
|
-
});
|
|
286
|
-
var ProviderModelSchema = z2.object({
|
|
287
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
288
|
-
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
289
|
-
});
|
|
290
|
-
var ProviderConfigSchema = z2.object({
|
|
291
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
292
|
-
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
293
|
-
});
|
|
294
|
-
var ModelsSchema = z2.object({
|
|
295
|
-
default: z2.string().optional(),
|
|
296
|
-
small: z2.string().optional(),
|
|
297
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
298
|
-
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
299
|
-
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
300
|
-
routing: z2.array(RoutingRuleSchema).optional(),
|
|
301
|
-
overrides: z2.record(z2.string(), z2.object({
|
|
302
|
-
default: z2.string().optional(),
|
|
303
|
-
small: z2.string().optional(),
|
|
304
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
305
|
-
})).optional()
|
|
306
|
-
});
|
|
307
|
-
function parseModels(packDir, packName) {
|
|
308
|
-
const modelsPath = join2(packDir, "models.json");
|
|
309
|
-
const raw = readJsonOrNull(modelsPath);
|
|
310
|
-
if (!raw)
|
|
311
|
-
return null;
|
|
312
|
-
const parsed = ModelsSchema.parse(raw);
|
|
313
|
-
return {
|
|
314
|
-
packName,
|
|
315
|
-
sourcePath: modelsPath,
|
|
316
|
-
config: parsed
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function mergeModelsConfigs(configs) {
|
|
320
|
-
const warnings = [];
|
|
321
|
-
const result = {};
|
|
322
|
-
for (const entry of configs) {
|
|
323
|
-
const { config, packName } = entry;
|
|
324
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
325
|
-
result.default = config.default;
|
|
326
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
327
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
328
|
-
}
|
|
329
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
330
|
-
result.small = config.small;
|
|
331
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
332
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
333
|
-
}
|
|
334
|
-
if (config.agents) {
|
|
335
|
-
if (!result.agents)
|
|
336
|
-
result.agents = {};
|
|
337
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
338
|
-
if (name in result.agents) {
|
|
339
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
result.agents[name] = assignment;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (config.profiles) {
|
|
346
|
-
if (!result.profiles)
|
|
347
|
-
result.profiles = {};
|
|
348
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
349
|
-
if (name in result.profiles) {
|
|
350
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
result.profiles[name] = profile;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (config.providers) {
|
|
357
|
-
if (!result.providers)
|
|
358
|
-
result.providers = {};
|
|
359
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
360
|
-
if (!(providerName in result.providers)) {
|
|
361
|
-
result.providers[providerName] = providerConfig;
|
|
362
|
-
} else {
|
|
363
|
-
const existing = result.providers[providerName];
|
|
364
|
-
if (!existing) {
|
|
365
|
-
result.providers[providerName] = providerConfig;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (providerConfig.options) {
|
|
369
|
-
existing.options = {
|
|
370
|
-
...providerConfig.options,
|
|
371
|
-
...existing.options
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
if (providerConfig.models) {
|
|
375
|
-
if (!existing.models)
|
|
376
|
-
existing.models = {};
|
|
377
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
378
|
-
if (!(modelName in existing.models)) {
|
|
379
|
-
existing.models[modelName] = modelConfig;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (config.routing) {
|
|
387
|
-
if (!result.routing)
|
|
388
|
-
result.routing = [];
|
|
389
|
-
result.routing.push(...config.routing);
|
|
390
|
-
}
|
|
391
|
-
if (config.overrides) {
|
|
392
|
-
if (!result.overrides)
|
|
393
|
-
result.overrides = {};
|
|
394
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
395
|
-
if (targetId in result.overrides) {
|
|
396
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
result.overrides[targetId] = override;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return { config: result, warnings };
|
|
404
|
-
}
|
|
405
|
-
function scanModelsForSecrets(config) {
|
|
406
|
-
const warnings = [];
|
|
407
|
-
const json = JSON.stringify(config);
|
|
408
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
409
|
-
if (pattern.test(json)) {
|
|
410
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return warnings;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/utils/frontmatter.ts
|
|
417
|
-
import matter from "gray-matter";
|
|
418
|
-
function parseFrontmatter(source) {
|
|
419
|
-
const { data, content } = matter(source);
|
|
420
|
-
return {
|
|
421
|
-
data,
|
|
422
|
-
content: content.trim(),
|
|
423
|
-
raw: source
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function serializeFrontmatter(data, content) {
|
|
427
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
428
|
-
if (Object.keys(filtered).length === 0) {
|
|
429
|
-
return content;
|
|
430
|
-
}
|
|
431
|
-
return matter.stringify(content, filtered);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// src/features/skills.ts
|
|
435
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
436
|
-
import { basename, join as join3 } from "path";
|
|
437
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
438
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
439
|
-
function parseSkills(skillsDir, packName) {
|
|
440
|
-
const dirs = listDirs(skillsDir);
|
|
441
|
-
const skills = [];
|
|
442
|
-
for (const dir of dirs) {
|
|
443
|
-
const skillMd = join3(dir, "SKILL.md");
|
|
444
|
-
if (existsSync3(skillMd)) {
|
|
445
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return skills;
|
|
449
|
-
}
|
|
450
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
451
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
452
|
-
const { data, content } = parseFrontmatter(raw);
|
|
453
|
-
return {
|
|
454
|
-
name: data.name ?? basename(skillDir),
|
|
455
|
-
sourcePath: filepath,
|
|
456
|
-
sourceDir: skillDir,
|
|
457
|
-
packName,
|
|
458
|
-
meta: data,
|
|
459
|
-
content
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
function buildSkillFrontmatter(skill) {
|
|
463
|
-
return {
|
|
464
|
-
...skill.meta,
|
|
465
|
-
name: skill.name
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
function serializeSkill(skill) {
|
|
469
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
470
|
-
}
|
|
471
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
472
|
-
const { data, content } = parseFrontmatter(source);
|
|
473
|
-
const normalized = {
|
|
474
|
-
...data,
|
|
475
|
-
name: skillName
|
|
476
|
-
};
|
|
477
|
-
let addedDescription = false;
|
|
478
|
-
const description = normalized.description;
|
|
479
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
480
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
481
|
-
addedDescription = true;
|
|
482
|
-
}
|
|
483
|
-
return {
|
|
484
|
-
content: serializeFrontmatter(normalized, content),
|
|
485
|
-
addedDescription
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
489
|
-
const errors = [];
|
|
490
|
-
const dirName = basename(skill.sourceDir);
|
|
491
|
-
const declaredName = skill.meta.name;
|
|
492
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
493
|
-
errors.push('Missing required frontmatter field "name".');
|
|
494
|
-
} else {
|
|
495
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
496
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
497
|
-
}
|
|
498
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
499
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
500
|
-
}
|
|
501
|
-
if (declaredName !== dirName) {
|
|
502
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const description = skill.meta.description;
|
|
506
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
507
|
-
errors.push('Missing required frontmatter field "description".');
|
|
508
|
-
}
|
|
509
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
510
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
511
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
512
|
-
}
|
|
513
|
-
return errors;
|
|
514
|
-
}
|
|
515
|
-
function skillMatchesTarget(skill, targetId) {
|
|
516
|
-
const { targets } = skill.meta;
|
|
517
|
-
if (!targets || targets === "*")
|
|
518
|
-
return true;
|
|
519
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
520
|
-
return true;
|
|
521
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// src/cli/pack/validate.ts
|
|
525
|
-
import chalk from "chalk";
|
|
526
|
-
import { existsSync as existsSync4 } from "fs";
|
|
527
|
-
import { basename as basename2, join as join4, resolve as resolve2 } from "path";
|
|
528
|
-
function runPackValidate(projectRoot) {
|
|
529
|
-
const config = loadWorkspaceConfig(projectRoot);
|
|
530
|
-
let hasErrors = false;
|
|
531
|
-
for (const packRef of config.packs) {
|
|
532
|
-
const packDir = resolvePackDir(projectRoot, packRef);
|
|
533
|
-
console.log(chalk.bold(`
|
|
534
|
-
Validating pack: ${packRef}`));
|
|
535
|
-
if (!packDir || !existsSync4(packDir)) {
|
|
536
|
-
console.log(chalk.red(` ERROR: Pack directory not found: ${packRef}`));
|
|
537
|
-
hasErrors = true;
|
|
538
|
-
continue;
|
|
539
|
-
}
|
|
540
|
-
const packJsonPath = resolve2(packDir, "pack.json");
|
|
541
|
-
if (!existsSync4(packJsonPath)) {
|
|
542
|
-
console.log(chalk.yellow(" warn: No pack.json found. Name will be inferred from directory."));
|
|
543
|
-
} else {
|
|
544
|
-
try {
|
|
545
|
-
loadPackManifest(packDir);
|
|
546
|
-
console.log(chalk.green(" pack.json: valid"));
|
|
547
|
-
} catch (err) {
|
|
548
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
549
|
-
console.log(chalk.red(` ERROR pack.json: ${message}`));
|
|
550
|
-
hasErrors = true;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
const subdirs = ["rules", "commands", "agents", "skills"];
|
|
554
|
-
for (const sub of subdirs) {
|
|
555
|
-
const subDir = join4(packDir, sub);
|
|
556
|
-
if (existsSync4(subDir)) {
|
|
557
|
-
if (sub === "skills") {
|
|
558
|
-
const skillDirs = listDirs(subDir);
|
|
559
|
-
for (const skillDir of skillDirs) {
|
|
560
|
-
const skillName = basename2(skillDir);
|
|
561
|
-
const skillMd = join4(skillDir, "SKILL.md");
|
|
562
|
-
if (!existsSync4(skillMd)) {
|
|
563
|
-
console.log(chalk.yellow(` warn: skills/${skillName} missing SKILL.md`));
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
try {
|
|
567
|
-
const parsed = parseSkillFile(skillMd, skillDir, "__validation__");
|
|
568
|
-
const skillErrors = validateAgentSkillsFrontmatter(parsed);
|
|
569
|
-
for (const err of skillErrors) {
|
|
570
|
-
console.log(chalk.red(` ERROR skills/${skillName}/SKILL.md: ${err}`));
|
|
571
|
-
}
|
|
572
|
-
if (skillErrors.length > 0) {
|
|
573
|
-
hasErrors = true;
|
|
574
|
-
}
|
|
575
|
-
} catch (err) {
|
|
576
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
577
|
-
console.log(chalk.red(` ERROR skills/${skillName}/SKILL.md: failed to parse (${message})`));
|
|
578
|
-
hasErrors = true;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
console.log(chalk.green(` ${sub}/: ${skillDirs.length} skill(s)`));
|
|
582
|
-
} else {
|
|
583
|
-
const files = listFiles(subDir, { extension: ".md" });
|
|
584
|
-
console.log(chalk.green(` ${sub}/: ${files.length} file(s)`));
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
const optionalFiles = ["mcp.json", "ignore", ".aiignore"];
|
|
589
|
-
for (const file of optionalFiles) {
|
|
590
|
-
if (existsSync4(join4(packDir, file))) {
|
|
591
|
-
console.log(chalk.green(` ${file}: present`));
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
const hooksJson = join4(packDir, "hooks", "hooks.json");
|
|
595
|
-
if (existsSync4(hooksJson)) {
|
|
596
|
-
console.log(chalk.green(" hooks/hooks.json: present"));
|
|
597
|
-
}
|
|
598
|
-
const pluginsDir = join4(packDir, "plugins");
|
|
599
|
-
if (existsSync4(pluginsDir)) {
|
|
600
|
-
const pluginFiles = [
|
|
601
|
-
...listFiles(pluginsDir, { extension: ".ts" }),
|
|
602
|
-
...listFiles(pluginsDir, { extension: ".js" })
|
|
603
|
-
];
|
|
604
|
-
console.log(chalk.green(` plugins/: ${pluginFiles.length} file(s)`));
|
|
605
|
-
}
|
|
606
|
-
const modelsJsonPath = join4(packDir, "models.json");
|
|
607
|
-
if (existsSync4(modelsJsonPath)) {
|
|
608
|
-
try {
|
|
609
|
-
const parsed = parseModels(packDir, "validate");
|
|
610
|
-
if (parsed) {
|
|
611
|
-
console.log(chalk.green(" models.json: valid"));
|
|
612
|
-
const secretWarnings = scanModelsForSecrets(parsed.config);
|
|
613
|
-
if (secretWarnings.length > 0) {
|
|
614
|
-
for (const w of secretWarnings) {
|
|
615
|
-
console.log(chalk.red(` ERROR models.json: ${w}`));
|
|
616
|
-
}
|
|
617
|
-
hasErrors = true;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
} catch (err) {
|
|
621
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
622
|
-
console.log(chalk.red(` ERROR models.json: ${message}`));
|
|
623
|
-
hasErrors = true;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
console.log();
|
|
628
|
-
if (hasErrors) {
|
|
629
|
-
console.log(chalk.red("Validation failed with errors."));
|
|
630
|
-
process.exit(1);
|
|
631
|
-
} else {
|
|
632
|
-
console.log(chalk.green("All packs valid."));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
function resolvePackDir(projectRoot, packRef) {
|
|
636
|
-
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
637
|
-
return resolve2(projectRoot, packRef);
|
|
638
|
-
}
|
|
639
|
-
return resolve2(projectRoot, packRef);
|
|
640
|
-
}
|
|
641
|
-
export {
|
|
642
|
-
runPackValidate
|
|
643
|
-
};
|
|
2
|
+
var Nq=import.meta.require;import{existsSync as u,readFileSync as m}from"fs";import{parse as Bq}from"jsonc-parser";import{resolve as g}from"path";import{z as Q}from"zod";var Qq=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],C=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],Yq=["repo","monorepo","metarepo"],E=Q.object({name:Q.string().min(1),version:Q.string().default("1.0.0"),description:Q.string().default(""),author:Q.union([Q.string(),Q.object({name:Q.string(),email:Q.string().optional()})]).optional(),homepage:Q.string().optional(),repository:Q.union([Q.string(),Q.object({url:Q.string(),type:Q.string().optional()})]).optional(),license:Q.string().optional(),logo:Q.string().optional(),tags:Q.array(Q.string()).default([]),dependencies:Q.array(Q.string()).default([]),conflicts:Q.array(Q.string()).default([]),targets:Q.union([Q.literal("*"),Q.array(Q.string())]).default("*"),features:Q.union([Q.literal("*"),Q.array(Q.string())]).default("*")}),Zq=Q.union([Q.literal("*"),Q.array(Q.string()),Q.record(Q.string(),Q.union([Q.literal("*"),Q.array(Q.string())]))]),S=Q.object({$schema:Q.string().optional(),packs:Q.array(Q.string()).default(["./packs/default"]),disabled:Q.array(Q.string()).default([]),targets:Q.union([Q.literal("*"),Q.array(Q.string())]).default("*"),features:Zq.default("*"),mode:Q.enum(Yq).default("repo"),baseDirs:Q.array(Q.string()).default(["."]),global:Q.boolean().default(!1),delete:Q.boolean().default(!0),verbose:Q.boolean().default(!1),silent:Q.boolean().default(!1),overrides:Q.record(Q.string(),Q.record(Q.string(),Q.string())).default({}),sources:Q.array(Q.object({source:Q.string(),packs:Q.array(Q.string()).optional(),skills:Q.array(Q.string()).optional()})).default([]),modelProfile:Q.string().optional()}),$q=["agentpacks.local.jsonc","agentpacks.jsonc"];function k(q){for(let Y of $q){let B=g(q,Y);if(u(B)){let V=m(B,"utf-8"),Z=Bq(V);return S.parse(Z)}}return S.parse({})}function h(q){let Y=g(q,"pack.json");if(!u(Y)){let Z=q.split("/").pop()??"unknown";return E.parse({name:Z})}let B=m(Y,"utf-8"),V=JSON.parse(B);return E.parse(V)}function mq(q,Y){let{features:B}=q;if(B==="*")return[...C];if(Array.isArray(B)){if(B.includes("*"))return[...C];return B.filter((Z)=>C.includes(Z))}let V=B[Y];if(!V)return[];if(V==="*")return[...C];if(Array.isArray(V)&&V.includes("*"))return[...C];return V.filter((Z)=>C.includes(Z))}function gq(q){if(q.targets==="*")return[...Qq];return q.targets}import{existsSync as M,mkdirSync as Vq,readdirSync as z,readFileSync as Xq,rmSync as Kq,statSync as f,writeFileSync as Wq}from"fs";import{dirname as Uq,join as d,relative as Oq}from"path";var p="<!-- Generated by agentpacks. DO NOT EDIT. -->",c="// Generated by agentpacks. DO NOT EDIT.",n="// Generated by agentpacks. DO NOT EDIT.";function Hq(q,Y,B={}){let{header:V=!0,type:Z}=B,K=Z??Lq(q);Jq(Uq(q));let X=Y;if(V){let W=Gq(K);if(W)X=`${W}
|
|
3
|
+
${Y}`}Wq(q,X,"utf-8")}function fq(q,Y,B={}){let V=JSON.stringify(Y,null,2);Hq(q,V+`
|
|
4
|
+
`,{...B,type:"json"})}function o(q){if(!M(q))return null;return Xq(q,"utf-8")}function l(q){let Y=o(q);if(Y===null)return null;return JSON.parse(Y)}function Jq(q){if(!M(q))Vq(q,{recursive:!0})}function dq(q){if(M(q))Kq(q,{recursive:!0,force:!0})}function v(q,Y={}){let{extension:B,recursive:V=!1}=Y;if(!M(q))return[];let Z=[],K=z(q);for(let X of K){let W=d(q,X),H=f(W);if(H.isDirectory()&&V)Z.push(...v(W,Y));else if(H.isFile()){if(!B||X.endsWith(B))Z.push(W)}}return Z}function x(q){if(!M(q))return[];return z(q).map((Y)=>d(q,Y)).filter((Y)=>f(Y).isDirectory())}function pq(q,Y){return Oq(q,Y)}function cq(q){let Y=o(q);if(!Y)return!1;return Y.startsWith(p)||Y.startsWith(c)||Y.startsWith(n)}function Lq(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 Gq(q){switch(q){case"md":return p;case"json":return c;case"js":case"ts":return n;default:return null}}import{join as bq}from"path";import{z as $}from"zod";var Cq=[/["']api[_-]?key["']\s*:/i,/["']apiKey["']\s*:/i,/["']secret["']\s*:/i,/["']password["']\s*:/i,/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,/["']private[_-]?key["']\s*:/i,/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,/sk-[a-zA-Z0-9]{20,}/,/Bearer\s+[a-zA-Z0-9._-]{20,}/],F=$.object({model:$.string(),temperature:$.number().min(0).max(2).optional(),top_p:$.number().min(0).max(1).optional()}),Iq=$.object({extends:$.string().optional(),description:$.string().optional(),default:$.string().optional(),small:$.string().optional(),agents:$.record($.string(),F).optional()}),iq=$.object({complexity:$.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:$.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:$.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:$.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:$.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),wq=$.object({when:$.record($.string(),$.string()),use:$.string(),description:$.string().optional(),priority:$.number().optional()}),Mq=$.object({options:$.record($.string(),$.unknown()).optional(),variants:$.record($.string(),$.record($.string(),$.unknown())).optional()}),vq=$.object({options:$.record($.string(),$.unknown()).optional(),models:$.record($.string(),Mq).optional()}),Tq=$.object({default:$.string().optional(),small:$.string().optional(),agents:$.record($.string(),F).optional(),profiles:$.record($.string(),Iq).optional(),providers:$.record($.string(),vq).optional(),routing:$.array(wq).optional(),overrides:$.record($.string(),$.object({default:$.string().optional(),small:$.string().optional(),agents:$.record($.string(),F).optional()})).optional()});function s(q,Y){let B=bq(q,"models.json"),V=l(B);if(!V)return null;let Z=Tq.parse(V);return{packName:Y,sourcePath:B,config:Z}}function aq(q){let Y=[],B={};for(let V of q){let{config:Z,packName:K}=V;if(Z.default!==void 0&&B.default===void 0)B.default=Z.default;else if(Z.default!==void 0&&B.default!==void 0)Y.push(`Models "default" from pack "${K}" skipped (already defined).`);if(Z.small!==void 0&&B.small===void 0)B.small=Z.small;else if(Z.small!==void 0&&B.small!==void 0)Y.push(`Models "small" from pack "${K}" skipped (already defined).`);if(Z.agents){if(!B.agents)B.agents={};for(let[X,W]of Object.entries(Z.agents)){if(X in B.agents){Y.push(`Models agent "${X}" from pack "${K}" skipped (already defined).`);continue}B.agents[X]=W}}if(Z.profiles){if(!B.profiles)B.profiles={};for(let[X,W]of Object.entries(Z.profiles)){if(X in B.profiles){Y.push(`Models profile "${X}" from pack "${K}" skipped (already defined).`);continue}B.profiles[X]=W}}if(Z.providers){if(!B.providers)B.providers={};for(let[X,W]of Object.entries(Z.providers))if(!(X in B.providers))B.providers[X]=W;else{let H=B.providers[X];if(!H){B.providers[X]=W;continue}if(W.options)H.options={...W.options,...H.options};if(W.models){if(!H.models)H.models={};for(let[G,A]of Object.entries(W.models))if(!(G in H.models))H.models[G]=A}}}if(Z.routing){if(!B.routing)B.routing=[];B.routing.push(...Z.routing)}if(Z.overrides){if(!B.overrides)B.overrides={};for(let[X,W]of Object.entries(Z.overrides)){if(X in B.overrides){Y.push(`Models override for target "${X}" from pack "${K}" skipped (already defined).`);continue}B.overrides[X]=W}}}return{config:B,warnings:Y}}function i(q){let Y=[],B=JSON.stringify(q);for(let V of Cq)if(V.test(B))Y.push(`Potential secret detected in models.json matching pattern: ${V.source}`);return Y}import a from"gray-matter";function P(q){let{data:Y,content:B}=a(q);return{data:Y,content:B.trim(),raw:q}}function y(q,Y){let B=Object.fromEntries(Object.entries(q).filter(([,V])=>V!==void 0));if(Object.keys(B).length===0)return Y;return a.stringify(Y,B)}import{existsSync as xq,readFileSync as Aq}from"fs";import{basename as t,join as _q}from"path";var jq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,r=64;function ZB(q,Y){let B=x(q),V=[];for(let Z of B){let K=_q(Z,"SKILL.md");if(xq(K))V.push(N(K,Z,Y))}return V}function N(q,Y,B){let V=Aq(q,"utf-8"),{data:Z,content:K}=P(V);return{name:Z.name??t(Y),sourcePath:q,sourceDir:Y,packName:B,meta:Z,content:K}}function Fq(q){return{...q.meta,name:q.name}}function $B(q){return y(Fq(q),q.content)}function VB(q,Y){let{data:B,content:V}=P(q),Z={...B,name:Y},K=!1,X=Z.description;if(typeof X!=="string"||X.trim().length===0)Z.description=`Imported skill: ${Y}`,K=!0;return{content:y(Z,V),addedDescription:K}}function e(q){let Y=[],B=t(q.sourceDir),V=q.meta.name;if(typeof V!=="string"||V.trim().length===0)Y.push('Missing required frontmatter field "name".');else{if(V.length>r)Y.push(`Invalid "name": must be at most ${r} characters.`);if(!jq.test(V))Y.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(V!==B)Y.push(`Invalid "name": must match containing directory "${B}".`)}let Z=q.meta.description;if(typeof Z!=="string"||Z.trim().length===0)Y.push('Missing required frontmatter field "description".');let K=q.meta["allowed-tools"];if(K!==void 0&&(!Array.isArray(K)||K.some((X)=>typeof X!=="string"||X.length===0)))Y.push('Invalid "allowed-tools": expected an array of non-empty strings.');return Y}function XB(q,Y){let{targets:B}=q.meta;if(!B||B==="*")return!0;if(Array.isArray(B)&&B.includes("*"))return!0;return Array.isArray(B)&&B.includes(Y)}import O from"chalk";import{existsSync as L}from"fs";import{basename as Pq,join as I,resolve as R}from"path";function bB(q){let Y=k(q),B=!1;for(let V of Y.packs){let Z=yq(q,V);if(console.log(O.bold(`
|
|
5
|
+
Validating pack: ${V}`)),!Z||!L(Z)){console.log(O.red(` ERROR: Pack directory not found: ${V}`)),B=!0;continue}let K=R(Z,"pack.json");if(!L(K))console.log(O.yellow(" warn: No pack.json found. Name will be inferred from directory."));else try{h(Z),console.log(O.green(" pack.json: valid"))}catch(U){let J=U instanceof Error?U.message:String(U);console.log(O.red(` ERROR pack.json: ${J}`)),B=!0}let X=["rules","commands","agents","skills"];for(let U of X){let J=I(Z,U);if(L(J))if(U==="skills"){let b=x(J);for(let _ of b){let j=Pq(_),D=I(_,"SKILL.md");if(!L(D)){console.log(O.yellow(` warn: skills/${j} missing SKILL.md`));continue}try{let w=N(D,_,"__validation__"),T=e(w);for(let qq of T)console.log(O.red(` ERROR skills/${j}/SKILL.md: ${qq}`));if(T.length>0)B=!0}catch(w){let T=w instanceof Error?w.message:String(w);console.log(O.red(` ERROR skills/${j}/SKILL.md: failed to parse (${T})`)),B=!0}}console.log(O.green(` ${U}/: ${b.length} skill(s)`))}else{let b=v(J,{extension:".md"});console.log(O.green(` ${U}/: ${b.length} file(s)`))}}let W=["mcp.json","ignore",".aiignore"];for(let U of W)if(L(I(Z,U)))console.log(O.green(` ${U}: present`));let H=I(Z,"hooks","hooks.json");if(L(H))console.log(O.green(" hooks/hooks.json: present"));let G=I(Z,"plugins");if(L(G)){let U=[...v(G,{extension:".ts"}),...v(G,{extension:".js"})];console.log(O.green(` plugins/: ${U.length} file(s)`))}let A=I(Z,"models.json");if(L(A))try{let U=s(Z,"validate");if(U){console.log(O.green(" models.json: valid"));let J=i(U.config);if(J.length>0){for(let b of J)console.log(O.red(` ERROR models.json: ${b}`));B=!0}}}catch(U){let J=U instanceof Error?U.message:String(U);console.log(O.red(` ERROR models.json: ${J}`)),B=!0}}if(console.log(),B)console.log(O.red("Validation failed with errors.")),process.exit(1);else console.log(O.green("All packs valid."))}function yq(q,Y){if(Y.startsWith("./")||Y.startsWith("../"))return R(q,Y);return R(q,Y)}export{bB as runPackValidate};
|