agentpacks 0.3.0 → 0.4.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/README.md +168 -8
- package/dist/api.d.ts +2 -0
- package/dist/api.js +929 -409
- package/dist/cli/export-cmd.js +281 -149
- package/dist/cli/generate.js +740 -247
- package/dist/cli/import-cmd.js +57 -85
- package/dist/cli/info.d.ts +4 -0
- package/dist/cli/info.js +232 -0
- package/dist/cli/init.js +8 -36
- package/dist/cli/install.js +414 -129
- package/dist/cli/login.d.ts +9 -0
- package/dist/cli/login.js +202 -0
- package/dist/cli/models-explain.d.ts +16 -0
- package/dist/cli/models-explain.js +1205 -0
- package/dist/cli/pack/create.js +4 -32
- package/dist/cli/pack/enable.js +1 -29
- package/dist/cli/pack/list.js +266 -134
- package/dist/cli/pack/validate.js +274 -127
- package/dist/cli/publish.d.ts +8 -0
- package/dist/cli/publish.js +672 -0
- package/dist/cli/search.d.ts +12 -0
- package/dist/cli/search.js +210 -0
- package/dist/core/config.d.ts +2 -1
- package/dist/core/config.js +74 -117
- package/dist/core/dependency-resolver.js +4 -28
- package/dist/core/feature-merger.d.ts +7 -0
- package/dist/core/feature-merger.js +289 -29
- package/dist/core/index.js +283 -140
- package/dist/core/lockfile.js +0 -28
- package/dist/core/metarepo.js +74 -116
- package/dist/core/pack-loader.d.ts +2 -0
- package/dist/core/pack-loader.js +266 -133
- package/dist/core/profile-resolver.d.ts +75 -0
- package/dist/core/profile-resolver.js +111 -0
- package/dist/exporters/cursor-plugin.js +4 -32
- package/dist/exporters/index.js +4 -32
- package/dist/features/agents.d.ts +5 -0
- package/dist/features/agents.js +2 -30
- package/dist/features/commands.js +2 -30
- package/dist/features/hooks.js +2 -30
- package/dist/features/ignore.js +0 -28
- package/dist/features/index.d.ts +1 -0
- package/dist/features/index.js +176 -31
- package/dist/features/mcp.js +2 -30
- package/dist/features/models.d.ts +167 -0
- package/dist/features/models.js +293 -0
- package/dist/features/plugins.js +2 -30
- package/dist/features/rules.js +2 -30
- package/dist/features/skills.js +2 -30
- package/dist/importers/claude-code.js +10 -38
- package/dist/importers/cursor.js +15 -43
- package/dist/importers/opencode.js +16 -44
- package/dist/importers/rulesync.js +22 -50
- package/dist/index.js +1710 -538
- package/dist/node/api.js +929 -409
- package/dist/node/cli/export-cmd.js +281 -149
- package/dist/node/cli/generate.js +740 -247
- package/dist/node/cli/import-cmd.js +57 -85
- package/dist/node/cli/info.js +232 -0
- package/dist/node/cli/init.js +8 -36
- package/dist/node/cli/install.js +414 -129
- package/dist/node/cli/login.js +202 -0
- package/dist/node/cli/models-explain.js +1205 -0
- package/dist/node/cli/pack/create.js +4 -32
- package/dist/node/cli/pack/enable.js +1 -29
- package/dist/node/cli/pack/list.js +266 -134
- package/dist/node/cli/pack/validate.js +274 -127
- package/dist/node/cli/publish.js +672 -0
- package/dist/node/cli/search.js +210 -0
- package/dist/node/core/config.js +74 -117
- package/dist/node/core/dependency-resolver.js +4 -28
- package/dist/node/core/feature-merger.js +289 -29
- package/dist/node/core/index.js +283 -140
- package/dist/node/core/lockfile.js +0 -28
- package/dist/node/core/metarepo.js +74 -116
- package/dist/node/core/pack-loader.js +266 -133
- package/dist/node/core/profile-resolver.js +111 -0
- package/dist/node/exporters/cursor-plugin.js +4 -32
- package/dist/node/exporters/index.js +4 -32
- package/dist/node/features/agents.js +2 -30
- package/dist/node/features/commands.js +2 -30
- package/dist/node/features/hooks.js +2 -30
- package/dist/node/features/ignore.js +0 -28
- package/dist/node/features/index.js +176 -31
- package/dist/node/features/mcp.js +2 -30
- package/dist/node/features/models.js +293 -0
- package/dist/node/features/plugins.js +2 -30
- package/dist/node/features/rules.js +2 -30
- package/dist/node/features/skills.js +2 -30
- package/dist/node/importers/claude-code.js +10 -38
- package/dist/node/importers/cursor.js +15 -43
- package/dist/node/importers/opencode.js +16 -44
- package/dist/node/importers/rulesync.js +22 -50
- package/dist/node/index.js +1710 -538
- package/dist/node/sources/git-ref.js +7 -30
- package/dist/node/sources/git.js +7 -30
- package/dist/node/sources/index.js +337 -39
- package/dist/node/sources/local.js +0 -28
- package/dist/node/sources/npm-ref.js +0 -28
- package/dist/node/sources/npm.js +10 -37
- package/dist/node/sources/registry-ref.js +37 -0
- package/dist/node/sources/registry.js +355 -0
- package/dist/node/targets/additional-targets.js +196 -37
- package/dist/node/targets/agents-md.js +5 -33
- package/dist/node/targets/base-target.js +0 -28
- package/dist/node/targets/claude-code.js +211 -41
- package/dist/node/targets/codex-cli.js +7 -35
- package/dist/node/targets/copilot.js +202 -41
- package/dist/node/targets/cursor.js +188 -40
- package/dist/node/targets/gemini-cli.js +10 -38
- package/dist/node/targets/generic-md-target.js +196 -37
- package/dist/node/targets/index.js +414 -106
- package/dist/node/targets/opencode.js +171 -51
- package/dist/node/targets/registry.js +414 -106
- package/dist/node/utils/credentials.js +38 -0
- package/dist/node/utils/diff.js +22 -34
- package/dist/node/utils/filesystem.js +2 -30
- package/dist/node/utils/frontmatter.js +0 -28
- package/dist/node/utils/global.js +3 -31
- package/dist/node/utils/markdown.js +0 -28
- package/dist/node/utils/model-allowlist.js +110 -0
- package/dist/node/utils/model-guidance.js +78 -0
- package/dist/node/utils/registry-client.js +142 -0
- package/dist/node/utils/tarball.js +49 -0
- package/dist/sources/git-ref.js +7 -30
- package/dist/sources/git.d.ts +2 -2
- package/dist/sources/git.js +7 -30
- package/dist/sources/index.d.ts +2 -0
- package/dist/sources/index.js +337 -39
- package/dist/sources/local.js +0 -28
- package/dist/sources/npm-ref.js +0 -28
- package/dist/sources/npm.js +10 -37
- package/dist/sources/registry-ref.d.ts +30 -0
- package/dist/sources/registry-ref.js +37 -0
- package/dist/sources/registry.d.ts +18 -0
- package/dist/sources/registry.js +355 -0
- package/dist/targets/additional-targets.js +196 -37
- package/dist/targets/agents-md.js +5 -33
- package/dist/targets/base-target.d.ts +2 -0
- package/dist/targets/base-target.js +0 -28
- package/dist/targets/claude-code.js +211 -41
- package/dist/targets/codex-cli.js +7 -35
- package/dist/targets/copilot.js +202 -41
- package/dist/targets/cursor.js +188 -40
- package/dist/targets/gemini-cli.js +10 -38
- package/dist/targets/generic-md-target.js +196 -37
- package/dist/targets/index.js +414 -106
- package/dist/targets/opencode.js +171 -51
- package/dist/targets/registry.js +414 -106
- package/dist/utils/credentials.d.ts +19 -0
- package/dist/utils/credentials.js +38 -0
- package/dist/utils/diff.js +22 -34
- package/dist/utils/filesystem.js +2 -30
- package/dist/utils/frontmatter.js +0 -28
- package/dist/utils/global.js +3 -31
- package/dist/utils/markdown.js +0 -28
- package/dist/utils/model-allowlist.d.ts +39 -0
- package/dist/utils/model-allowlist.js +110 -0
- package/dist/utils/model-guidance.d.ts +6 -0
- package/dist/utils/model-guidance.js +78 -0
- package/dist/utils/registry-client.d.ts +141 -0
- package/dist/utils/registry-client.js +142 -0
- package/dist/utils/tarball.d.ts +13 -0
- package/dist/utils/tarball.js +49 -0
- package/package.json +171 -5
- package/templates/pack/models.json +38 -0
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/core/config.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { readFileSync, existsSync } from "fs";
|
|
7
|
+
import { resolve } from "path";
|
|
8
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
9
|
+
var TARGET_IDS = [
|
|
10
|
+
"opencode",
|
|
11
|
+
"cursor",
|
|
12
|
+
"claudecode",
|
|
13
|
+
"codexcli",
|
|
14
|
+
"geminicli",
|
|
15
|
+
"copilot",
|
|
16
|
+
"agentsmd",
|
|
17
|
+
"cline",
|
|
18
|
+
"kilo",
|
|
19
|
+
"roo",
|
|
20
|
+
"qwencode",
|
|
21
|
+
"kiro",
|
|
22
|
+
"factorydroid",
|
|
23
|
+
"antigravity",
|
|
24
|
+
"junie",
|
|
25
|
+
"augmentcode",
|
|
26
|
+
"windsurf",
|
|
27
|
+
"warp",
|
|
28
|
+
"replit",
|
|
29
|
+
"zed"
|
|
30
|
+
];
|
|
31
|
+
var FEATURE_IDS = [
|
|
32
|
+
"rules",
|
|
33
|
+
"commands",
|
|
34
|
+
"agents",
|
|
35
|
+
"skills",
|
|
36
|
+
"hooks",
|
|
37
|
+
"plugins",
|
|
38
|
+
"mcp",
|
|
39
|
+
"ignore",
|
|
40
|
+
"models"
|
|
41
|
+
];
|
|
42
|
+
var REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
43
|
+
var PackManifestSchema = z.object({
|
|
44
|
+
name: z.string().min(1),
|
|
45
|
+
version: z.string().default("1.0.0"),
|
|
46
|
+
description: z.string().default(""),
|
|
47
|
+
author: z.union([
|
|
48
|
+
z.string(),
|
|
49
|
+
z.object({ name: z.string(), email: z.string().optional() })
|
|
50
|
+
]).optional(),
|
|
51
|
+
tags: z.array(z.string()).default([]),
|
|
52
|
+
dependencies: z.array(z.string()).default([]),
|
|
53
|
+
conflicts: z.array(z.string()).default([]),
|
|
54
|
+
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
55
|
+
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
56
|
+
});
|
|
57
|
+
var FeaturesSchema = z.union([
|
|
58
|
+
z.literal("*"),
|
|
59
|
+
z.array(z.string()),
|
|
60
|
+
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
61
|
+
]);
|
|
62
|
+
var WorkspaceConfigSchema = z.object({
|
|
63
|
+
$schema: z.string().optional(),
|
|
64
|
+
packs: z.array(z.string()).default(["./packs/default"]),
|
|
65
|
+
disabled: z.array(z.string()).default([]),
|
|
66
|
+
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
67
|
+
features: FeaturesSchema.default("*"),
|
|
68
|
+
mode: z.enum(REPO_MODES).default("repo"),
|
|
69
|
+
baseDirs: z.array(z.string()).default(["."]),
|
|
70
|
+
global: z.boolean().default(false),
|
|
71
|
+
delete: z.boolean().default(true),
|
|
72
|
+
verbose: z.boolean().default(false),
|
|
73
|
+
silent: z.boolean().default(false),
|
|
74
|
+
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
75
|
+
sources: z.array(z.object({
|
|
76
|
+
source: z.string(),
|
|
77
|
+
packs: z.array(z.string()).optional(),
|
|
78
|
+
skills: z.array(z.string()).optional()
|
|
79
|
+
})).default([]),
|
|
80
|
+
modelProfile: z.string().optional()
|
|
81
|
+
});
|
|
82
|
+
var CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
83
|
+
function loadWorkspaceConfig(projectRoot) {
|
|
84
|
+
for (const filename of CONFIG_FILES) {
|
|
85
|
+
const filepath = resolve(projectRoot, filename);
|
|
86
|
+
if (existsSync(filepath)) {
|
|
87
|
+
const raw = readFileSync(filepath, "utf-8");
|
|
88
|
+
const parsed = parseJsonc(raw);
|
|
89
|
+
return WorkspaceConfigSchema.parse(parsed);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return WorkspaceConfigSchema.parse({});
|
|
93
|
+
}
|
|
94
|
+
function loadPackManifest(packDir) {
|
|
95
|
+
const filepath = resolve(packDir, "pack.json");
|
|
96
|
+
if (!existsSync(filepath)) {
|
|
97
|
+
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
98
|
+
return PackManifestSchema.parse({ name: dirName });
|
|
99
|
+
}
|
|
100
|
+
const raw = readFileSync(filepath, "utf-8");
|
|
101
|
+
const parsed = JSON.parse(raw);
|
|
102
|
+
return PackManifestSchema.parse(parsed);
|
|
103
|
+
}
|
|
104
|
+
function resolveFeatures(config, targetId) {
|
|
105
|
+
const { features } = config;
|
|
106
|
+
if (features === "*") {
|
|
107
|
+
return [...FEATURE_IDS];
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(features)) {
|
|
110
|
+
if (features.includes("*"))
|
|
111
|
+
return [...FEATURE_IDS];
|
|
112
|
+
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
113
|
+
}
|
|
114
|
+
const targetFeatures = features[targetId];
|
|
115
|
+
if (!targetFeatures)
|
|
116
|
+
return [];
|
|
117
|
+
if (targetFeatures === "*")
|
|
118
|
+
return [...FEATURE_IDS];
|
|
119
|
+
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
120
|
+
return [...FEATURE_IDS];
|
|
121
|
+
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
122
|
+
}
|
|
123
|
+
function resolveTargets(config) {
|
|
124
|
+
if (config.targets === "*")
|
|
125
|
+
return [...TARGET_IDS];
|
|
126
|
+
return config.targets;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/utils/filesystem.ts
|
|
130
|
+
import {
|
|
131
|
+
existsSync as existsSync2,
|
|
132
|
+
mkdirSync,
|
|
133
|
+
readFileSync as readFileSync2,
|
|
134
|
+
writeFileSync,
|
|
135
|
+
readdirSync,
|
|
136
|
+
rmSync,
|
|
137
|
+
statSync
|
|
138
|
+
} from "fs";
|
|
139
|
+
import { dirname, relative, join } from "path";
|
|
140
|
+
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
141
|
+
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
142
|
+
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
143
|
+
function writeGeneratedFile(filepath, content, options = {}) {
|
|
144
|
+
const { header = true, type } = options;
|
|
145
|
+
const ext = type ?? inferFileType(filepath);
|
|
146
|
+
ensureDir(dirname(filepath));
|
|
147
|
+
let output = content;
|
|
148
|
+
if (header) {
|
|
149
|
+
const headerComment = getHeader(ext);
|
|
150
|
+
if (headerComment) {
|
|
151
|
+
output = `${headerComment}
|
|
152
|
+
${content}`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
writeFileSync(filepath, output, "utf-8");
|
|
156
|
+
}
|
|
157
|
+
function writeGeneratedJson(filepath, data, options = {}) {
|
|
158
|
+
const json = JSON.stringify(data, null, 2);
|
|
159
|
+
writeGeneratedFile(filepath, json + `
|
|
160
|
+
`, { ...options, type: "json" });
|
|
161
|
+
}
|
|
162
|
+
function readFileOrNull(filepath) {
|
|
163
|
+
if (!existsSync2(filepath))
|
|
164
|
+
return null;
|
|
165
|
+
return readFileSync2(filepath, "utf-8");
|
|
166
|
+
}
|
|
167
|
+
function readJsonOrNull(filepath) {
|
|
168
|
+
const content = readFileOrNull(filepath);
|
|
169
|
+
if (content === null)
|
|
170
|
+
return null;
|
|
171
|
+
return JSON.parse(content);
|
|
172
|
+
}
|
|
173
|
+
function ensureDir(dirPath) {
|
|
174
|
+
if (!existsSync2(dirPath)) {
|
|
175
|
+
mkdirSync(dirPath, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function removeIfExists(targetPath) {
|
|
179
|
+
if (existsSync2(targetPath)) {
|
|
180
|
+
rmSync(targetPath, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function listFiles(dirPath, options = {}) {
|
|
184
|
+
const { extension, recursive = false } = options;
|
|
185
|
+
if (!existsSync2(dirPath))
|
|
186
|
+
return [];
|
|
187
|
+
const results = [];
|
|
188
|
+
const entries = readdirSync(dirPath);
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
const fullPath = join(dirPath, entry);
|
|
191
|
+
const stat = statSync(fullPath);
|
|
192
|
+
if (stat.isDirectory() && recursive) {
|
|
193
|
+
results.push(...listFiles(fullPath, options));
|
|
194
|
+
} else if (stat.isFile()) {
|
|
195
|
+
if (!extension || entry.endsWith(extension)) {
|
|
196
|
+
results.push(fullPath);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return results;
|
|
201
|
+
}
|
|
202
|
+
function listDirs(dirPath) {
|
|
203
|
+
if (!existsSync2(dirPath))
|
|
204
|
+
return [];
|
|
205
|
+
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
206
|
+
}
|
|
207
|
+
function relPath(projectRoot, filepath) {
|
|
208
|
+
return relative(projectRoot, filepath);
|
|
209
|
+
}
|
|
210
|
+
function isGeneratedFile(filepath) {
|
|
211
|
+
const content = readFileOrNull(filepath);
|
|
212
|
+
if (!content)
|
|
213
|
+
return false;
|
|
214
|
+
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
215
|
+
}
|
|
216
|
+
function inferFileType(filepath) {
|
|
217
|
+
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
218
|
+
return "json";
|
|
219
|
+
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
220
|
+
return "ts";
|
|
221
|
+
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
222
|
+
return "js";
|
|
223
|
+
return "md";
|
|
224
|
+
}
|
|
225
|
+
function getHeader(type) {
|
|
226
|
+
switch (type) {
|
|
227
|
+
case "md":
|
|
228
|
+
return GENERATED_HEADER_MD;
|
|
229
|
+
case "json":
|
|
230
|
+
return GENERATED_HEADER_JSON;
|
|
231
|
+
case "js":
|
|
232
|
+
case "ts":
|
|
233
|
+
return GENERATED_HEADER_JS;
|
|
234
|
+
default:
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/features/models.ts
|
|
240
|
+
import { join as join2 } from "path";
|
|
241
|
+
import { z as z2 } from "zod";
|
|
242
|
+
var SECRET_PATTERNS = [
|
|
243
|
+
/["']api[_-]?key["']\s*:/i,
|
|
244
|
+
/["']apiKey["']\s*:/i,
|
|
245
|
+
/["']secret["']\s*:/i,
|
|
246
|
+
/["']password["']\s*:/i,
|
|
247
|
+
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
248
|
+
/["']private[_-]?key["']\s*:/i,
|
|
249
|
+
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
250
|
+
/sk-[a-zA-Z0-9]{20,}/,
|
|
251
|
+
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
252
|
+
];
|
|
253
|
+
var AgentModelSchema = z2.object({
|
|
254
|
+
model: z2.string(),
|
|
255
|
+
temperature: z2.number().min(0).max(2).optional(),
|
|
256
|
+
top_p: z2.number().min(0).max(1).optional()
|
|
257
|
+
});
|
|
258
|
+
var ModelProfileSchema = z2.object({
|
|
259
|
+
extends: z2.string().optional(),
|
|
260
|
+
description: z2.string().optional(),
|
|
261
|
+
default: z2.string().optional(),
|
|
262
|
+
small: z2.string().optional(),
|
|
263
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
264
|
+
});
|
|
265
|
+
var RoutingConditionSchema = z2.object({
|
|
266
|
+
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
267
|
+
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
268
|
+
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
269
|
+
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
270
|
+
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
271
|
+
});
|
|
272
|
+
var RoutingRuleSchema = z2.object({
|
|
273
|
+
when: z2.record(z2.string(), z2.string()),
|
|
274
|
+
use: z2.string(),
|
|
275
|
+
description: z2.string().optional(),
|
|
276
|
+
priority: z2.number().optional()
|
|
277
|
+
});
|
|
278
|
+
var ProviderModelSchema = z2.object({
|
|
279
|
+
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
280
|
+
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
281
|
+
});
|
|
282
|
+
var ProviderConfigSchema = z2.object({
|
|
283
|
+
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
284
|
+
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
285
|
+
});
|
|
286
|
+
var ModelsSchema = z2.object({
|
|
287
|
+
default: z2.string().optional(),
|
|
288
|
+
small: z2.string().optional(),
|
|
289
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
290
|
+
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
291
|
+
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
292
|
+
routing: z2.array(RoutingRuleSchema).optional(),
|
|
293
|
+
overrides: z2.record(z2.string(), z2.object({
|
|
294
|
+
default: z2.string().optional(),
|
|
295
|
+
small: z2.string().optional(),
|
|
296
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
297
|
+
})).optional()
|
|
298
|
+
});
|
|
299
|
+
function parseModels(packDir, packName) {
|
|
300
|
+
const modelsPath = join2(packDir, "models.json");
|
|
301
|
+
const raw = readJsonOrNull(modelsPath);
|
|
302
|
+
if (!raw)
|
|
303
|
+
return null;
|
|
304
|
+
const parsed = ModelsSchema.parse(raw);
|
|
305
|
+
return {
|
|
306
|
+
packName,
|
|
307
|
+
sourcePath: modelsPath,
|
|
308
|
+
config: parsed
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function mergeModelsConfigs(configs) {
|
|
312
|
+
const warnings = [];
|
|
313
|
+
const result = {};
|
|
314
|
+
for (const entry of configs) {
|
|
315
|
+
const { config, packName } = entry;
|
|
316
|
+
if (config.default !== undefined && result.default === undefined) {
|
|
317
|
+
result.default = config.default;
|
|
318
|
+
} else if (config.default !== undefined && result.default !== undefined) {
|
|
319
|
+
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
320
|
+
}
|
|
321
|
+
if (config.small !== undefined && result.small === undefined) {
|
|
322
|
+
result.small = config.small;
|
|
323
|
+
} else if (config.small !== undefined && result.small !== undefined) {
|
|
324
|
+
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
325
|
+
}
|
|
326
|
+
if (config.agents) {
|
|
327
|
+
if (!result.agents)
|
|
328
|
+
result.agents = {};
|
|
329
|
+
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
330
|
+
if (name in result.agents) {
|
|
331
|
+
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
result.agents[name] = assignment;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (config.profiles) {
|
|
338
|
+
if (!result.profiles)
|
|
339
|
+
result.profiles = {};
|
|
340
|
+
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
341
|
+
if (name in result.profiles) {
|
|
342
|
+
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
result.profiles[name] = profile;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (config.providers) {
|
|
349
|
+
if (!result.providers)
|
|
350
|
+
result.providers = {};
|
|
351
|
+
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
352
|
+
if (!(providerName in result.providers)) {
|
|
353
|
+
result.providers[providerName] = providerConfig;
|
|
354
|
+
} else {
|
|
355
|
+
const existing = result.providers[providerName];
|
|
356
|
+
if (!existing) {
|
|
357
|
+
result.providers[providerName] = providerConfig;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (providerConfig.options) {
|
|
361
|
+
existing.options = {
|
|
362
|
+
...providerConfig.options,
|
|
363
|
+
...existing.options
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (providerConfig.models) {
|
|
367
|
+
if (!existing.models)
|
|
368
|
+
existing.models = {};
|
|
369
|
+
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
370
|
+
if (!(modelName in existing.models)) {
|
|
371
|
+
existing.models[modelName] = modelConfig;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (config.routing) {
|
|
379
|
+
if (!result.routing)
|
|
380
|
+
result.routing = [];
|
|
381
|
+
result.routing.push(...config.routing);
|
|
382
|
+
}
|
|
383
|
+
if (config.overrides) {
|
|
384
|
+
if (!result.overrides)
|
|
385
|
+
result.overrides = {};
|
|
386
|
+
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
387
|
+
if (targetId in result.overrides) {
|
|
388
|
+
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
result.overrides[targetId] = override;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return { config: result, warnings };
|
|
396
|
+
}
|
|
397
|
+
function scanModelsForSecrets(config) {
|
|
398
|
+
const warnings = [];
|
|
399
|
+
const json = JSON.stringify(config);
|
|
400
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
401
|
+
if (pattern.test(json)) {
|
|
402
|
+
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return warnings;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/utils/registry-client.ts
|
|
409
|
+
var DEFAULT_REGISTRY_URL = "https://registry.agentpacks.dev";
|
|
410
|
+
function createRegistryClient(config) {
|
|
411
|
+
return new RegistryClient({
|
|
412
|
+
registryUrl: config?.registryUrl ?? DEFAULT_REGISTRY_URL,
|
|
413
|
+
authToken: config?.authToken,
|
|
414
|
+
timeout: config?.timeout ?? 30000
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
class RegistryClient {
|
|
419
|
+
config;
|
|
420
|
+
constructor(config) {
|
|
421
|
+
this.config = {
|
|
422
|
+
registryUrl: config.registryUrl.replace(/\/+$/, ""),
|
|
423
|
+
authToken: config.authToken,
|
|
424
|
+
timeout: config.timeout ?? 30000
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
async search(params) {
|
|
428
|
+
const searchParams = new URLSearchParams;
|
|
429
|
+
if (params.query)
|
|
430
|
+
searchParams.set("q", params.query);
|
|
431
|
+
if (params.tags?.length)
|
|
432
|
+
searchParams.set("tags", params.tags.join(","));
|
|
433
|
+
if (params.targets?.length)
|
|
434
|
+
searchParams.set("targets", params.targets.join(","));
|
|
435
|
+
if (params.features?.length)
|
|
436
|
+
searchParams.set("features", params.features.join(","));
|
|
437
|
+
if (params.author)
|
|
438
|
+
searchParams.set("author", params.author);
|
|
439
|
+
if (params.sort)
|
|
440
|
+
searchParams.set("sort", params.sort);
|
|
441
|
+
if (params.limit)
|
|
442
|
+
searchParams.set("limit", String(params.limit));
|
|
443
|
+
if (params.offset)
|
|
444
|
+
searchParams.set("offset", String(params.offset));
|
|
445
|
+
const url = `${this.config.registryUrl}/packs?${searchParams.toString()}`;
|
|
446
|
+
const res = await this.fetch(url);
|
|
447
|
+
return res;
|
|
448
|
+
}
|
|
449
|
+
async info(packName) {
|
|
450
|
+
const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}`;
|
|
451
|
+
const res = await this.fetch(url);
|
|
452
|
+
return res;
|
|
453
|
+
}
|
|
454
|
+
async download(packName, version = "latest") {
|
|
455
|
+
const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}/versions/${encodeURIComponent(version)}/download`;
|
|
456
|
+
const response = await fetch(url, {
|
|
457
|
+
headers: this.headers(),
|
|
458
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
459
|
+
});
|
|
460
|
+
if (!response.ok) {
|
|
461
|
+
throw new RegistryApiError(response.status, `Failed to download ${packName}@${version}: ${response.statusText}`);
|
|
462
|
+
}
|
|
463
|
+
const integrity = response.headers.get("x-integrity") ?? "";
|
|
464
|
+
const data = await response.arrayBuffer();
|
|
465
|
+
return { data, integrity };
|
|
466
|
+
}
|
|
467
|
+
async publish(tarball, metadata) {
|
|
468
|
+
if (!this.config.authToken) {
|
|
469
|
+
throw new Error("Authentication required. Run `agentpacks login` first.");
|
|
470
|
+
}
|
|
471
|
+
const formData = new FormData;
|
|
472
|
+
formData.append("tarball", new Blob([tarball], { type: "application/gzip" }), `${metadata.name}-${metadata.version}.tgz`);
|
|
473
|
+
formData.append("metadata", JSON.stringify(metadata));
|
|
474
|
+
const url = `${this.config.registryUrl}/packs`;
|
|
475
|
+
const response = await fetch(url, {
|
|
476
|
+
method: "POST",
|
|
477
|
+
headers: {
|
|
478
|
+
Authorization: `Bearer ${this.config.authToken}`
|
|
479
|
+
},
|
|
480
|
+
body: formData,
|
|
481
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
482
|
+
});
|
|
483
|
+
if (!response.ok) {
|
|
484
|
+
const body = await response.text();
|
|
485
|
+
throw new RegistryApiError(response.status, `Publish failed: ${body || response.statusText}`);
|
|
486
|
+
}
|
|
487
|
+
return await response.json();
|
|
488
|
+
}
|
|
489
|
+
async featured(limit) {
|
|
490
|
+
const url = limit ? `${this.config.registryUrl}/featured?limit=${limit}` : `${this.config.registryUrl}/featured`;
|
|
491
|
+
const res = await this.fetch(url);
|
|
492
|
+
return res.packs;
|
|
493
|
+
}
|
|
494
|
+
async tags() {
|
|
495
|
+
const url = `${this.config.registryUrl}/tags`;
|
|
496
|
+
const res = await this.fetch(url);
|
|
497
|
+
return res.tags;
|
|
498
|
+
}
|
|
499
|
+
async stats() {
|
|
500
|
+
const url = `${this.config.registryUrl}/stats`;
|
|
501
|
+
return await this.fetch(url);
|
|
502
|
+
}
|
|
503
|
+
async health() {
|
|
504
|
+
try {
|
|
505
|
+
const url = `${this.config.registryUrl}/health`;
|
|
506
|
+
await this.fetch(url);
|
|
507
|
+
return true;
|
|
508
|
+
} catch {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
async fetch(url) {
|
|
513
|
+
const response = await fetch(url, {
|
|
514
|
+
headers: this.headers(),
|
|
515
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
516
|
+
});
|
|
517
|
+
if (!response.ok) {
|
|
518
|
+
const body = await response.text();
|
|
519
|
+
throw new RegistryApiError(response.status, body || response.statusText);
|
|
520
|
+
}
|
|
521
|
+
return response.json();
|
|
522
|
+
}
|
|
523
|
+
headers() {
|
|
524
|
+
const h = {
|
|
525
|
+
Accept: "application/json"
|
|
526
|
+
};
|
|
527
|
+
if (this.config.authToken) {
|
|
528
|
+
h["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
529
|
+
}
|
|
530
|
+
return h;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
class RegistryApiError extends Error {
|
|
535
|
+
status;
|
|
536
|
+
constructor(status, message) {
|
|
537
|
+
super(message);
|
|
538
|
+
this.name = "RegistryApiError";
|
|
539
|
+
this.status = status;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/utils/credentials.ts
|
|
544
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
545
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
546
|
+
import { homedir } from "os";
|
|
547
|
+
var CONFIG_DIR = join3(homedir(), ".config", "agentpacks");
|
|
548
|
+
var CREDENTIALS_FILE = join3(CONFIG_DIR, "credentials.json");
|
|
549
|
+
function loadCredentials() {
|
|
550
|
+
if (!existsSync3(CREDENTIALS_FILE)) {
|
|
551
|
+
return { registryUrl: "https://registry.agentpacks.dev" };
|
|
552
|
+
}
|
|
553
|
+
try {
|
|
554
|
+
const raw = readFileSync3(CREDENTIALS_FILE, "utf-8");
|
|
555
|
+
return JSON.parse(raw);
|
|
556
|
+
} catch {
|
|
557
|
+
return { registryUrl: "https://registry.agentpacks.dev" };
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function saveCredentials(credentials) {
|
|
561
|
+
mkdirSync2(dirname2(CREDENTIALS_FILE), { recursive: true });
|
|
562
|
+
writeFileSync2(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2) + `
|
|
563
|
+
`, {
|
|
564
|
+
mode: 384
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
function clearCredentials() {
|
|
568
|
+
if (existsSync3(CREDENTIALS_FILE)) {
|
|
569
|
+
writeFileSync2(CREDENTIALS_FILE, JSON.stringify({ registryUrl: "https://registry.agentpacks.dev" }) + `
|
|
570
|
+
`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/utils/tarball.ts
|
|
575
|
+
import { execSync } from "child_process";
|
|
576
|
+
import { readFileSync as readFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync3, rmSync as rmSync2 } from "fs";
|
|
577
|
+
import { join as join4, resolve as resolve2 } from "path";
|
|
578
|
+
import { createHash } from "crypto";
|
|
579
|
+
import { tmpdir } from "os";
|
|
580
|
+
async function createTarball(packDir) {
|
|
581
|
+
const absDir = resolve2(packDir);
|
|
582
|
+
const tmpFile = join4(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
583
|
+
try {
|
|
584
|
+
execSync(`tar -czf "${tmpFile}" -C "${absDir}" .`, {
|
|
585
|
+
stdio: "pipe"
|
|
586
|
+
});
|
|
587
|
+
const buffer = readFileSync4(tmpFile);
|
|
588
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
589
|
+
} finally {
|
|
590
|
+
if (existsSync4(tmpFile)) {
|
|
591
|
+
rmSync2(tmpFile);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
async function extractTarball(data, targetDir) {
|
|
596
|
+
mkdirSync3(targetDir, { recursive: true });
|
|
597
|
+
const tmpFile = join4(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
598
|
+
try {
|
|
599
|
+
const buffer = Buffer.from(data);
|
|
600
|
+
const { writeFileSync: writeFileSync3 } = await import("fs");
|
|
601
|
+
writeFileSync3(tmpFile, buffer);
|
|
602
|
+
execSync(`tar -xzf "${tmpFile}" -C "${targetDir}"`, {
|
|
603
|
+
stdio: "pipe"
|
|
604
|
+
});
|
|
605
|
+
} finally {
|
|
606
|
+
if (existsSync4(tmpFile)) {
|
|
607
|
+
rmSync2(tmpFile);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function computeTarballIntegrity(data) {
|
|
612
|
+
const hash = createHash("sha256").update(Buffer.from(data)).digest("hex");
|
|
613
|
+
return `sha256-${hash}`;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/cli/publish.ts
|
|
617
|
+
import { resolve as resolve3 } from "path";
|
|
618
|
+
import { existsSync as existsSync5 } from "fs";
|
|
619
|
+
import chalk from "chalk";
|
|
620
|
+
async function runPublish(projectRoot, options) {
|
|
621
|
+
const credentials = loadCredentials();
|
|
622
|
+
if (!credentials.token) {
|
|
623
|
+
console.log(chalk.red("Not authenticated. Run `agentpacks login` first."));
|
|
624
|
+
process.exit(1);
|
|
625
|
+
}
|
|
626
|
+
const packDir = resolve3(projectRoot);
|
|
627
|
+
const packJsonPath = resolve3(packDir, "pack.json");
|
|
628
|
+
if (!existsSync5(packJsonPath)) {
|
|
629
|
+
console.log(chalk.red("No pack.json found. Are you in a pack directory?"));
|
|
630
|
+
process.exit(1);
|
|
631
|
+
}
|
|
632
|
+
const manifest = loadPackManifest(packDir);
|
|
633
|
+
console.log(chalk.bold(`Publishing ${manifest.name}@${manifest.version}...`));
|
|
634
|
+
const models = parseModels(packDir, manifest.name);
|
|
635
|
+
if (models) {
|
|
636
|
+
const secretWarnings = scanModelsForSecrets(models.config);
|
|
637
|
+
if (secretWarnings.length > 0) {
|
|
638
|
+
console.log(chalk.red(`
|
|
639
|
+
Blocked: secrets detected in models.json:`));
|
|
640
|
+
for (const w of secretWarnings) {
|
|
641
|
+
console.log(chalk.red(` - ${w}`));
|
|
642
|
+
}
|
|
643
|
+
process.exit(1);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (options.verbose)
|
|
647
|
+
console.log(chalk.dim(" Creating tarball..."));
|
|
648
|
+
const tarball = await createTarball(packDir);
|
|
649
|
+
if (options.verbose)
|
|
650
|
+
console.log(chalk.dim(" Uploading..."));
|
|
651
|
+
const client = createRegistryClient({
|
|
652
|
+
registryUrl: credentials.registryUrl,
|
|
653
|
+
authToken: credentials.token
|
|
654
|
+
});
|
|
655
|
+
try {
|
|
656
|
+
const result = await client.publish(tarball, {
|
|
657
|
+
name: manifest.name,
|
|
658
|
+
version: manifest.version,
|
|
659
|
+
manifest
|
|
660
|
+
});
|
|
661
|
+
console.log(chalk.green(`
|
|
662
|
+
Published ${result.name}@${result.version}`));
|
|
663
|
+
console.log(chalk.dim(` integrity: ${result.integrity}`));
|
|
664
|
+
} catch (err) {
|
|
665
|
+
console.log(chalk.red(`
|
|
666
|
+
Publish failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
667
|
+
process.exit(1);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
export {
|
|
671
|
+
runPublish
|
|
672
|
+
};
|