agentpacks 1.7.13 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
package/dist/cli/publish.js
CHANGED
|
@@ -1,680 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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/credentials.ts
|
|
417
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
418
|
-
import { homedir } from "os";
|
|
419
|
-
import { dirname as dirname2, join as join3 } from "path";
|
|
420
|
-
var CONFIG_DIR = join3(homedir(), ".config", "agentpacks");
|
|
421
|
-
var CREDENTIALS_FILE = join3(CONFIG_DIR, "credentials.json");
|
|
422
|
-
function loadCredentials() {
|
|
423
|
-
if (!existsSync3(CREDENTIALS_FILE)) {
|
|
424
|
-
return { registryUrl: "https://registry.agentpacks.dev" };
|
|
425
|
-
}
|
|
426
|
-
try {
|
|
427
|
-
const raw = readFileSync3(CREDENTIALS_FILE, "utf-8");
|
|
428
|
-
return JSON.parse(raw);
|
|
429
|
-
} catch {
|
|
430
|
-
return { registryUrl: "https://registry.agentpacks.dev" };
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
function saveCredentials(credentials) {
|
|
434
|
-
mkdirSync2(dirname2(CREDENTIALS_FILE), { recursive: true });
|
|
435
|
-
writeFileSync2(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2) + `
|
|
436
|
-
`, {
|
|
437
|
-
mode: 384
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
function clearCredentials() {
|
|
441
|
-
if (existsSync3(CREDENTIALS_FILE)) {
|
|
442
|
-
writeFileSync2(CREDENTIALS_FILE, JSON.stringify({ registryUrl: "https://registry.agentpacks.dev" }) + `
|
|
443
|
-
`);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// src/utils/registry-client.ts
|
|
448
|
-
var DEFAULT_REGISTRY_URL = "https://registry.agentpacks.dev";
|
|
449
|
-
function createRegistryClient(config) {
|
|
450
|
-
return new RegistryClient({
|
|
451
|
-
registryUrl: config?.registryUrl ?? DEFAULT_REGISTRY_URL,
|
|
452
|
-
authToken: config?.authToken,
|
|
453
|
-
timeout: config?.timeout ?? 30000
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
class RegistryClient {
|
|
458
|
-
config;
|
|
459
|
-
constructor(config) {
|
|
460
|
-
this.config = {
|
|
461
|
-
registryUrl: config.registryUrl.replace(/\/+$/, ""),
|
|
462
|
-
authToken: config.authToken,
|
|
463
|
-
timeout: config.timeout ?? 30000
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
async search(params) {
|
|
467
|
-
const searchParams = new URLSearchParams;
|
|
468
|
-
if (params.query)
|
|
469
|
-
searchParams.set("q", params.query);
|
|
470
|
-
if (params.tags?.length)
|
|
471
|
-
searchParams.set("tags", params.tags.join(","));
|
|
472
|
-
if (params.targets?.length)
|
|
473
|
-
searchParams.set("targets", params.targets.join(","));
|
|
474
|
-
if (params.features?.length)
|
|
475
|
-
searchParams.set("features", params.features.join(","));
|
|
476
|
-
if (params.author)
|
|
477
|
-
searchParams.set("author", params.author);
|
|
478
|
-
if (params.sort)
|
|
479
|
-
searchParams.set("sort", params.sort);
|
|
480
|
-
if (params.limit)
|
|
481
|
-
searchParams.set("limit", String(params.limit));
|
|
482
|
-
if (params.offset)
|
|
483
|
-
searchParams.set("offset", String(params.offset));
|
|
484
|
-
const url = `${this.config.registryUrl}/packs?${searchParams.toString()}`;
|
|
485
|
-
const res = await this.fetch(url);
|
|
486
|
-
return res;
|
|
487
|
-
}
|
|
488
|
-
async info(packName) {
|
|
489
|
-
const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}`;
|
|
490
|
-
const res = await this.fetch(url);
|
|
491
|
-
return res;
|
|
492
|
-
}
|
|
493
|
-
async download(packName, version = "latest") {
|
|
494
|
-
const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}/versions/${encodeURIComponent(version)}/download`;
|
|
495
|
-
const response = await fetch(url, {
|
|
496
|
-
headers: this.headers(),
|
|
497
|
-
signal: AbortSignal.timeout(this.config.timeout)
|
|
498
|
-
});
|
|
499
|
-
if (!response.ok) {
|
|
500
|
-
throw new RegistryApiError(response.status, `Failed to download ${packName}@${version}: ${response.statusText}`);
|
|
501
|
-
}
|
|
502
|
-
const integrity = response.headers.get("x-integrity") ?? "";
|
|
503
|
-
const data = await response.arrayBuffer();
|
|
504
|
-
return { data, integrity };
|
|
505
|
-
}
|
|
506
|
-
async publish(tarball, metadata) {
|
|
507
|
-
if (!this.config.authToken) {
|
|
508
|
-
throw new Error("Authentication required. Run `agentpacks login` first.");
|
|
509
|
-
}
|
|
510
|
-
const formData = new FormData;
|
|
511
|
-
formData.append("tarball", new Blob([tarball], { type: "application/gzip" }), `${metadata.name}-${metadata.version}.tgz`);
|
|
512
|
-
formData.append("metadata", JSON.stringify(metadata));
|
|
513
|
-
const url = `${this.config.registryUrl}/packs`;
|
|
514
|
-
const response = await fetch(url, {
|
|
515
|
-
method: "POST",
|
|
516
|
-
headers: {
|
|
517
|
-
Authorization: `Bearer ${this.config.authToken}`
|
|
518
|
-
},
|
|
519
|
-
body: formData,
|
|
520
|
-
signal: AbortSignal.timeout(this.config.timeout)
|
|
521
|
-
});
|
|
522
|
-
if (!response.ok) {
|
|
523
|
-
const body = await response.text();
|
|
524
|
-
throw new RegistryApiError(response.status, `Publish failed: ${body || response.statusText}`);
|
|
525
|
-
}
|
|
526
|
-
return await response.json();
|
|
527
|
-
}
|
|
528
|
-
async featured(limit) {
|
|
529
|
-
const url = limit ? `${this.config.registryUrl}/featured?limit=${limit}` : `${this.config.registryUrl}/featured`;
|
|
530
|
-
const res = await this.fetch(url);
|
|
531
|
-
return res.packs;
|
|
532
|
-
}
|
|
533
|
-
async tags() {
|
|
534
|
-
const url = `${this.config.registryUrl}/tags`;
|
|
535
|
-
const res = await this.fetch(url);
|
|
536
|
-
return res.tags;
|
|
537
|
-
}
|
|
538
|
-
async stats() {
|
|
539
|
-
const url = `${this.config.registryUrl}/stats`;
|
|
540
|
-
return await this.fetch(url);
|
|
541
|
-
}
|
|
542
|
-
async health() {
|
|
543
|
-
try {
|
|
544
|
-
const url = `${this.config.registryUrl}/health`;
|
|
545
|
-
await this.fetch(url);
|
|
546
|
-
return true;
|
|
547
|
-
} catch {
|
|
548
|
-
return false;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
async fetch(url) {
|
|
552
|
-
const response = await fetch(url, {
|
|
553
|
-
headers: this.headers(),
|
|
554
|
-
signal: AbortSignal.timeout(this.config.timeout)
|
|
555
|
-
});
|
|
556
|
-
if (!response.ok) {
|
|
557
|
-
const body = await response.text();
|
|
558
|
-
throw new RegistryApiError(response.status, body || response.statusText);
|
|
559
|
-
}
|
|
560
|
-
return response.json();
|
|
561
|
-
}
|
|
562
|
-
headers() {
|
|
563
|
-
const h = {
|
|
564
|
-
Accept: "application/json"
|
|
565
|
-
};
|
|
566
|
-
if (this.config.authToken) {
|
|
567
|
-
h["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
568
|
-
}
|
|
569
|
-
return h;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
class RegistryApiError extends Error {
|
|
574
|
-
status;
|
|
575
|
-
constructor(status, message) {
|
|
576
|
-
super(message);
|
|
577
|
-
this.name = "RegistryApiError";
|
|
578
|
-
this.status = status;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// src/utils/tarball.ts
|
|
583
|
-
import { execSync } from "child_process";
|
|
584
|
-
import { createHash } from "crypto";
|
|
585
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, rmSync as rmSync2 } from "fs";
|
|
586
|
-
import { tmpdir } from "os";
|
|
587
|
-
import { join as join4, resolve as resolve2 } from "path";
|
|
588
|
-
async function createTarball(packDir) {
|
|
589
|
-
const absDir = resolve2(packDir);
|
|
590
|
-
const tmpFile = join4(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
591
|
-
try {
|
|
592
|
-
execSync(`tar -czf "${tmpFile}" -C "${absDir}" .`, {
|
|
593
|
-
stdio: "pipe"
|
|
594
|
-
});
|
|
595
|
-
const buffer = readFileSync4(tmpFile);
|
|
596
|
-
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
597
|
-
} finally {
|
|
598
|
-
if (existsSync4(tmpFile)) {
|
|
599
|
-
rmSync2(tmpFile);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
async function extractTarball(data, targetDir) {
|
|
604
|
-
mkdirSync3(targetDir, { recursive: true });
|
|
605
|
-
const tmpFile = join4(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
606
|
-
try {
|
|
607
|
-
const buffer = Buffer.from(data);
|
|
608
|
-
const { writeFileSync: writeFileSync3 } = await import("fs");
|
|
609
|
-
writeFileSync3(tmpFile, buffer);
|
|
610
|
-
execSync(`tar -xzf "${tmpFile}" -C "${targetDir}"`, {
|
|
611
|
-
stdio: "pipe"
|
|
612
|
-
});
|
|
613
|
-
} finally {
|
|
614
|
-
if (existsSync4(tmpFile)) {
|
|
615
|
-
rmSync2(tmpFile);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
function computeTarballIntegrity(data) {
|
|
620
|
-
const hash = createHash("sha256").update(Buffer.from(data)).digest("hex");
|
|
621
|
-
return `sha256-${hash}`;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// src/cli/publish.ts
|
|
625
|
-
import chalk from "chalk";
|
|
626
|
-
import { existsSync as existsSync5 } from "fs";
|
|
627
|
-
import { resolve as resolve3 } from "path";
|
|
628
|
-
async function runPublish(projectRoot, options) {
|
|
629
|
-
const credentials = loadCredentials();
|
|
630
|
-
if (!credentials.token) {
|
|
631
|
-
console.log(chalk.red("Not authenticated. Run `agentpacks login` first."));
|
|
632
|
-
process.exit(1);
|
|
633
|
-
}
|
|
634
|
-
const packDir = resolve3(projectRoot);
|
|
635
|
-
const packJsonPath = resolve3(packDir, "pack.json");
|
|
636
|
-
if (!existsSync5(packJsonPath)) {
|
|
637
|
-
console.log(chalk.red("No pack.json found. Are you in a pack directory?"));
|
|
638
|
-
process.exit(1);
|
|
639
|
-
}
|
|
640
|
-
const manifest = loadPackManifest(packDir);
|
|
641
|
-
console.log(chalk.bold(`Publishing ${manifest.name}@${manifest.version}...`));
|
|
642
|
-
const models = parseModels(packDir, manifest.name);
|
|
643
|
-
if (models) {
|
|
644
|
-
const secretWarnings = scanModelsForSecrets(models.config);
|
|
645
|
-
if (secretWarnings.length > 0) {
|
|
646
|
-
console.log(chalk.red(`
|
|
647
|
-
Blocked: secrets detected in models.json:`));
|
|
648
|
-
for (const w of secretWarnings) {
|
|
649
|
-
console.log(chalk.red(` - ${w}`));
|
|
650
|
-
}
|
|
651
|
-
process.exit(1);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (options.verbose)
|
|
655
|
-
console.log(chalk.dim(" Creating tarball..."));
|
|
656
|
-
const tarball = await createTarball(packDir);
|
|
657
|
-
if (options.verbose)
|
|
658
|
-
console.log(chalk.dim(" Uploading..."));
|
|
659
|
-
const client = createRegistryClient({
|
|
660
|
-
registryUrl: credentials.registryUrl,
|
|
661
|
-
authToken: credentials.token
|
|
662
|
-
});
|
|
663
|
-
try {
|
|
664
|
-
const result = await client.publish(tarball, {
|
|
665
|
-
name: manifest.name,
|
|
666
|
-
version: manifest.version,
|
|
667
|
-
manifest
|
|
668
|
-
});
|
|
669
|
-
console.log(chalk.green(`
|
|
670
|
-
Published ${result.name}@${result.version}`));
|
|
671
|
-
console.log(chalk.dim(` integrity: ${result.integrity}`));
|
|
672
|
-
} catch (err) {
|
|
673
|
-
console.log(chalk.red(`
|
|
674
|
-
Publish failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
675
|
-
process.exit(1);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
export {
|
|
679
|
-
runPublish
|
|
680
|
-
};
|
|
2
|
+
var s=import.meta.require;import{existsSync as v,readFileSync as T}from"fs";import{parse as i}from"jsonc-parser";import{resolve as C}from"path";import{z as X}from"zod";var t=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],G=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],r=["repo","monorepo","metarepo"],j=X.object({name:X.string().min(1),version:X.string().default("1.0.0"),description:X.string().default(""),author:X.union([X.string(),X.object({name:X.string(),email:X.string().optional()})]).optional(),homepage:X.string().optional(),repository:X.union([X.string(),X.object({url:X.string(),type:X.string().optional()})]).optional(),license:X.string().optional(),logo:X.string().optional(),tags:X.array(X.string()).default([]),dependencies:X.array(X.string()).default([]),conflicts:X.array(X.string()).default([]),targets:X.union([X.literal("*"),X.array(X.string())]).default("*"),features:X.union([X.literal("*"),X.array(X.string())]).default("*")}),a=X.union([X.literal("*"),X.array(X.string()),X.record(X.string(),X.union([X.literal("*"),X.array(X.string())]))]),x=X.object({$schema:X.string().optional(),packs:X.array(X.string()).default(["./packs/default"]),disabled:X.array(X.string()).default([]),targets:X.union([X.literal("*"),X.array(X.string())]).default("*"),features:a.default("*"),mode:X.enum(r).default("repo"),baseDirs:X.array(X.string()).default(["."]),global:X.boolean().default(!1),delete:X.boolean().default(!0),verbose:X.boolean().default(!1),silent:X.boolean().default(!1),overrides:X.record(X.string(),X.record(X.string(),X.string())).default({}),sources:X.array(X.object({source:X.string(),packs:X.array(X.string()).optional(),skills:X.array(X.string()).optional()})).default([]),modelProfile:X.string().optional()}),e=["agentpacks.local.jsonc","agentpacks.jsonc"];function yq(q){for(let K of e){let Q=C(q,K);if(v(Q)){let Z=T(Q,"utf-8"),$=i(Z);return x.parse($)}}return x.parse({})}function I(q){let K=C(q,"pack.json");if(!v(K)){let $=q.split("/").pop()??"unknown";return j.parse({name:$})}let Q=T(K,"utf-8"),Z=JSON.parse(Q);return j.parse(Z)}function Sq(q,K){let{features:Q}=q;if(Q==="*")return[...G];if(Array.isArray(Q)){if(Q.includes("*"))return[...G];return Q.filter(($)=>G.includes($))}let Z=Q[K];if(!Z)return[];if(Z==="*")return[...G];if(Array.isArray(Z)&&Z.includes("*"))return[...G];return Z.filter(($)=>G.includes($))}function Eq(q){if(q.targets==="*")return[...t];return q.targets}import{existsSync as L,mkdirSync as qq,readdirSync as _,readFileSync as Kq,rmSync as Qq,statSync as A,writeFileSync as Xq}from"fs";import{dirname as Yq,join as N,relative as Zq}from"path";var F="<!-- Generated by agentpacks. DO NOT EDIT. -->",P="// Generated by agentpacks. DO NOT EDIT.",k="// Generated by agentpacks. DO NOT EDIT.";function $q(q,K,Q={}){let{header:Z=!0,type:$}=Q,W=$??Wq(q);Bq(Yq(q));let B=K;if(Z){let V=Uq(W);if(V)B=`${V}
|
|
3
|
+
${K}`}Xq(q,B,"utf-8")}function hq(q,K,Q={}){let Z=JSON.stringify(K,null,2);$q(q,Z+`
|
|
4
|
+
`,{...Q,type:"json"})}function R(q){if(!L(q))return null;return Kq(q,"utf-8")}function D(q){let K=R(q);if(K===null)return null;return JSON.parse(K)}function Bq(q){if(!L(q))qq(q,{recursive:!0})}function zq(q){if(L(q))Qq(q,{recursive:!0,force:!0})}function Vq(q,K={}){let{extension:Q,recursive:Z=!1}=K;if(!L(q))return[];let $=[],W=_(q);for(let B of W){let V=N(q,B),J=A(V);if(J.isDirectory()&&Z)$.push(...Vq(V,K));else if(J.isFile()){if(!Q||B.endsWith(Q))$.push(V)}}return $}function mq(q){if(!L(q))return[];return _(q).map((K)=>N(q,K)).filter((K)=>A(K).isDirectory())}function fq(q,K){return Zq(q,K)}function pq(q){let K=R(q);if(!K)return!1;return K.startsWith(F)||K.startsWith(P)||K.startsWith(k)}function Wq(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 Uq(q){switch(q){case"md":return F;case"json":return P;case"js":case"ts":return k;default:return null}}import{join as Jq}from"path";import{z as Y}from"zod";var Oq=[/["']api[_-]?key["']\s*:/i,/["']apiKey["']\s*:/i,/["']secret["']\s*:/i,/["']password["']\s*:/i,/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,/["']private[_-]?key["']\s*:/i,/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,/sk-[a-zA-Z0-9]{20,}/,/Bearer\s+[a-zA-Z0-9._-]{20,}/],w=Y.object({model:Y.string(),temperature:Y.number().min(0).max(2).optional(),top_p:Y.number().min(0).max(1).optional()}),Gq=Y.object({extends:Y.string().optional(),description:Y.string().optional(),default:Y.string().optional(),small:Y.string().optional(),agents:Y.record(Y.string(),w).optional()}),sq=Y.object({complexity:Y.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:Y.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:Y.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:Y.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:Y.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),Hq=Y.object({when:Y.record(Y.string(),Y.string()),use:Y.string(),description:Y.string().optional(),priority:Y.number().optional()}),Lq=Y.object({options:Y.record(Y.string(),Y.unknown()).optional(),variants:Y.record(Y.string(),Y.record(Y.string(),Y.unknown())).optional()}),Mq=Y.object({options:Y.record(Y.string(),Y.unknown()).optional(),models:Y.record(Y.string(),Lq).optional()}),bq=Y.object({default:Y.string().optional(),small:Y.string().optional(),agents:Y.record(Y.string(),w).optional(),profiles:Y.record(Y.string(),Gq).optional(),providers:Y.record(Y.string(),Mq).optional(),routing:Y.array(Hq).optional(),overrides:Y.record(Y.string(),Y.object({default:Y.string().optional(),small:Y.string().optional(),agents:Y.record(Y.string(),w).optional()})).optional()});function y(q,K){let Q=Jq(q,"models.json"),Z=D(Q);if(!Z)return null;let $=bq.parse(Z);return{packName:K,sourcePath:Q,config:$}}function iq(q){let K=[],Q={};for(let Z of q){let{config:$,packName:W}=Z;if($.default!==void 0&&Q.default===void 0)Q.default=$.default;else if($.default!==void 0&&Q.default!==void 0)K.push(`Models "default" from pack "${W}" skipped (already defined).`);if($.small!==void 0&&Q.small===void 0)Q.small=$.small;else if($.small!==void 0&&Q.small!==void 0)K.push(`Models "small" from pack "${W}" skipped (already defined).`);if($.agents){if(!Q.agents)Q.agents={};for(let[B,V]of Object.entries($.agents)){if(B in Q.agents){K.push(`Models agent "${B}" from pack "${W}" skipped (already defined).`);continue}Q.agents[B]=V}}if($.profiles){if(!Q.profiles)Q.profiles={};for(let[B,V]of Object.entries($.profiles)){if(B in Q.profiles){K.push(`Models profile "${B}" from pack "${W}" skipped (already defined).`);continue}Q.profiles[B]=V}}if($.providers){if(!Q.providers)Q.providers={};for(let[B,V]of Object.entries($.providers))if(!(B in Q.providers))Q.providers[B]=V;else{let J=Q.providers[B];if(!J){Q.providers[B]=V;continue}if(V.options)J.options={...V.options,...J.options};if(V.models){if(!J.models)J.models={};for(let[U,b]of Object.entries(V.models))if(!(U in J.models))J.models[U]=b}}}if($.routing){if(!Q.routing)Q.routing=[];Q.routing.push(...$.routing)}if($.overrides){if(!Q.overrides)Q.overrides={};for(let[B,V]of Object.entries($.overrides)){if(B in Q.overrides){K.push(`Models override for target "${B}" from pack "${W}" skipped (already defined).`);continue}Q.overrides[B]=V}}}return{config:Q,warnings:K}}function S(q){let K=[],Q=JSON.stringify(q);for(let Z of Oq)if(Z.test(Q))K.push(`Potential secret detected in models.json matching pattern: ${Z.source}`);return K}import{existsSync as E,mkdirSync as wq,readFileSync as jq,writeFileSync as u}from"fs";import{homedir as xq}from"os";import{dirname as vq,join as g}from"path";var Tq=g(xq(),".config","agentpacks"),H=g(Tq,"credentials.json");function d(){if(!E(H))return{registryUrl:"https://registry.agentpacks.dev"};try{let q=jq(H,"utf-8");return JSON.parse(q)}catch{return{registryUrl:"https://registry.agentpacks.dev"}}}function qK(q){wq(vq(H),{recursive:!0}),u(H,JSON.stringify(q,null,2)+`
|
|
5
|
+
`,{mode:384})}function KK(){if(E(H))u(H,JSON.stringify({registryUrl:"https://registry.agentpacks.dev"})+`
|
|
6
|
+
`)}function h(q){return new z({registryUrl:q?.registryUrl??"https://registry.agentpacks.dev",authToken:q?.authToken,timeout:q?.timeout??30000})}class z{config;constructor(q){this.config={registryUrl:q.registryUrl.replace(/\/+$/,""),authToken:q.authToken,timeout:q.timeout??30000}}async search(q){let K=new URLSearchParams;if(q.query)K.set("q",q.query);if(q.tags?.length)K.set("tags",q.tags.join(","));if(q.targets?.length)K.set("targets",q.targets.join(","));if(q.features?.length)K.set("features",q.features.join(","));if(q.author)K.set("author",q.author);if(q.sort)K.set("sort",q.sort);if(q.limit)K.set("limit",String(q.limit));if(q.offset)K.set("offset",String(q.offset));let Q=`${this.config.registryUrl}/packs?${K.toString()}`;return await this.fetch(Q)}async info(q){let K=`${this.config.registryUrl}/packs/${encodeURIComponent(q)}`;return await this.fetch(K)}async download(q,K="latest"){let Q=`${this.config.registryUrl}/packs/${encodeURIComponent(q)}/versions/${encodeURIComponent(K)}/download`,Z=await fetch(Q,{headers:this.headers(),signal:AbortSignal.timeout(this.config.timeout)});if(!Z.ok)throw new M(Z.status,`Failed to download ${q}@${K}: ${Z.statusText}`);let $=Z.headers.get("x-integrity")??"";return{data:await Z.arrayBuffer(),integrity:$}}async publish(q,K){if(!this.config.authToken)throw Error("Authentication required. Run `agentpacks login` first.");let Q=new FormData;Q.append("tarball",new Blob([q],{type:"application/gzip"}),`${K.name}-${K.version}.tgz`),Q.append("metadata",JSON.stringify(K));let Z=`${this.config.registryUrl}/packs`,$=await fetch(Z,{method:"POST",headers:{Authorization:`Bearer ${this.config.authToken}`},body:Q,signal:AbortSignal.timeout(this.config.timeout)});if(!$.ok){let W=await $.text();throw new M($.status,`Publish failed: ${W||$.statusText}`)}return await $.json()}async featured(q){let K=q?`${this.config.registryUrl}/featured?limit=${q}`:`${this.config.registryUrl}/featured`;return(await this.fetch(K)).packs}async tags(){let q=`${this.config.registryUrl}/tags`;return(await this.fetch(q)).tags}async stats(){let q=`${this.config.registryUrl}/stats`;return await this.fetch(q)}async health(){try{let q=`${this.config.registryUrl}/health`;return await this.fetch(q),!0}catch{return!1}}async fetch(q){let K=await fetch(q,{headers:this.headers(),signal:AbortSignal.timeout(this.config.timeout)});if(!K.ok){let Q=await K.text();throw new M(K.status,Q||K.statusText)}return K.json()}headers(){let q={Accept:"application/json"};if(this.config.authToken)q.Authorization=`Bearer ${this.config.authToken}`;return q}}class M extends Error{status;constructor(q,K){super(K);this.name="RegistryApiError",this.status=q}}import{execSync as m}from"child_process";import{createHash as Cq}from"crypto";import{existsSync as f,mkdirSync as Iq,readFileSync as _q,rmSync as p}from"fs";import{tmpdir as c}from"os";import{join as l,resolve as Aq}from"path";async function o(q){let K=Aq(q),Q=l(c(),`agentpacks-${Date.now()}.tgz`);try{m(`tar -czf "${Q}" -C "${K}" .`,{stdio:"pipe"});let Z=_q(Q);return Z.buffer.slice(Z.byteOffset,Z.byteOffset+Z.byteLength)}finally{if(f(Q))p(Q)}}async function WK(q,K){Iq(K,{recursive:!0});let Q=l(c(),`agentpacks-${Date.now()}.tgz`);try{let Z=Buffer.from(q),{writeFileSync:$}=await import("fs");$(Q,Z),m(`tar -xzf "${Q}" -C "${K}"`,{stdio:"pipe"})}finally{if(f(Q))p(Q)}}function UK(q){return`sha256-${Cq("sha256").update(Buffer.from(q)).digest("hex")}`}import O from"chalk";import{existsSync as Nq}from"fs";import{resolve as n}from"path";async function xK(q,K){let Q=d();if(!Q.token)console.log(O.red("Not authenticated. Run `agentpacks login` first.")),process.exit(1);let Z=n(q),$=n(Z,"pack.json");if(!Nq($))console.log(O.red("No pack.json found. Are you in a pack directory?")),process.exit(1);let W=I(Z);console.log(O.bold(`Publishing ${W.name}@${W.version}...`));let B=y(Z,W.name);if(B){let U=S(B.config);if(U.length>0){console.log(O.red(`
|
|
7
|
+
Blocked: secrets detected in models.json:`));for(let b of U)console.log(O.red(` - ${b}`));process.exit(1)}}if(K.verbose)console.log(O.dim(" Creating tarball..."));let V=await o(Z);if(K.verbose)console.log(O.dim(" Uploading..."));let J=h({registryUrl:Q.registryUrl,authToken:Q.token});try{let U=await J.publish(V,{name:W.name,version:W.version,manifest:W});console.log(O.green(`
|
|
8
|
+
Published ${U.name}@${U.version}`)),console.log(O.dim(` integrity: ${U.integrity}`))}catch(U){console.log(O.red(`
|
|
9
|
+
Publish failed: ${U instanceof Error?U.message:String(U)}`)),process.exit(1)}}export{xK as runPublish};
|