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
package/dist/core/pack-loader.js
CHANGED
|
@@ -1,51 +1,85 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
-
var __toCommonJS = (from) => {
|
|
8
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
-
if (entry)
|
|
10
|
-
return entry;
|
|
11
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
}));
|
|
17
|
-
__moduleCache.set(from, entry);
|
|
18
|
-
return entry;
|
|
19
|
-
};
|
|
20
|
-
var __export = (target, all) => {
|
|
21
|
-
for (var name in all)
|
|
22
|
-
__defProp(target, name, {
|
|
23
|
-
get: all[name],
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
set: (newValue) => all[name] = () => newValue
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
30
2
|
var __require = import.meta.require;
|
|
31
3
|
|
|
32
4
|
// src/core/config.ts
|
|
33
|
-
var exports_config = {};
|
|
34
|
-
__export(exports_config, {
|
|
35
|
-
resolveTargets: () => resolveTargets,
|
|
36
|
-
resolveFeatures: () => resolveFeatures,
|
|
37
|
-
loadWorkspaceConfig: () => loadWorkspaceConfig,
|
|
38
|
-
loadPackManifest: () => loadPackManifest,
|
|
39
|
-
WorkspaceConfigSchema: () => WorkspaceConfigSchema,
|
|
40
|
-
TARGET_IDS: () => TARGET_IDS,
|
|
41
|
-
REPO_MODES: () => REPO_MODES,
|
|
42
|
-
PackManifestSchema: () => PackManifestSchema,
|
|
43
|
-
FEATURE_IDS: () => FEATURE_IDS
|
|
44
|
-
});
|
|
45
5
|
import { z } from "zod";
|
|
46
6
|
import { readFileSync, existsSync } from "fs";
|
|
47
7
|
import { resolve } from "path";
|
|
48
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"];
|
|
49
83
|
function loadWorkspaceConfig(projectRoot) {
|
|
50
84
|
for (const filename of CONFIG_FILES) {
|
|
51
85
|
const filepath = resolve(projectRoot, filename);
|
|
@@ -91,81 +125,6 @@ function resolveTargets(config) {
|
|
|
91
125
|
return [...TARGET_IDS];
|
|
92
126
|
return config.targets;
|
|
93
127
|
}
|
|
94
|
-
var TARGET_IDS, FEATURE_IDS, REPO_MODES, PackManifestSchema, FeaturesSchema, WorkspaceConfigSchema, CONFIG_FILES;
|
|
95
|
-
var init_config = __esm(() => {
|
|
96
|
-
TARGET_IDS = [
|
|
97
|
-
"opencode",
|
|
98
|
-
"cursor",
|
|
99
|
-
"claudecode",
|
|
100
|
-
"codexcli",
|
|
101
|
-
"geminicli",
|
|
102
|
-
"copilot",
|
|
103
|
-
"agentsmd",
|
|
104
|
-
"cline",
|
|
105
|
-
"kilo",
|
|
106
|
-
"roo",
|
|
107
|
-
"qwencode",
|
|
108
|
-
"kiro",
|
|
109
|
-
"factorydroid",
|
|
110
|
-
"antigravity",
|
|
111
|
-
"junie",
|
|
112
|
-
"augmentcode",
|
|
113
|
-
"windsurf",
|
|
114
|
-
"warp",
|
|
115
|
-
"replit",
|
|
116
|
-
"zed"
|
|
117
|
-
];
|
|
118
|
-
FEATURE_IDS = [
|
|
119
|
-
"rules",
|
|
120
|
-
"commands",
|
|
121
|
-
"agents",
|
|
122
|
-
"skills",
|
|
123
|
-
"hooks",
|
|
124
|
-
"plugins",
|
|
125
|
-
"mcp",
|
|
126
|
-
"ignore"
|
|
127
|
-
];
|
|
128
|
-
REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
129
|
-
PackManifestSchema = z.object({
|
|
130
|
-
name: z.string().min(1),
|
|
131
|
-
version: z.string().default("1.0.0"),
|
|
132
|
-
description: z.string().default(""),
|
|
133
|
-
author: z.union([
|
|
134
|
-
z.string(),
|
|
135
|
-
z.object({ name: z.string(), email: z.string().optional() })
|
|
136
|
-
]).optional(),
|
|
137
|
-
tags: z.array(z.string()).default([]),
|
|
138
|
-
dependencies: z.array(z.string()).default([]),
|
|
139
|
-
conflicts: z.array(z.string()).default([]),
|
|
140
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
141
|
-
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
142
|
-
});
|
|
143
|
-
FeaturesSchema = z.union([
|
|
144
|
-
z.literal("*"),
|
|
145
|
-
z.array(z.string()),
|
|
146
|
-
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
147
|
-
]);
|
|
148
|
-
WorkspaceConfigSchema = z.object({
|
|
149
|
-
$schema: z.string().optional(),
|
|
150
|
-
packs: z.array(z.string()).default(["./packs/default"]),
|
|
151
|
-
disabled: z.array(z.string()).default([]),
|
|
152
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
153
|
-
features: FeaturesSchema.default("*"),
|
|
154
|
-
mode: z.enum(REPO_MODES).default("repo"),
|
|
155
|
-
baseDirs: z.array(z.string()).default(["."]),
|
|
156
|
-
global: z.boolean().default(false),
|
|
157
|
-
delete: z.boolean().default(true),
|
|
158
|
-
verbose: z.boolean().default(false),
|
|
159
|
-
silent: z.boolean().default(false),
|
|
160
|
-
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
161
|
-
sources: z.array(z.object({
|
|
162
|
-
source: z.string(),
|
|
163
|
-
packs: z.array(z.string()).optional(),
|
|
164
|
-
skills: z.array(z.string()).optional()
|
|
165
|
-
})).default([])
|
|
166
|
-
});
|
|
167
|
-
CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
168
|
-
});
|
|
169
128
|
|
|
170
129
|
// src/utils/filesystem.ts
|
|
171
130
|
import {
|
|
@@ -174,10 +133,10 @@ import {
|
|
|
174
133
|
readFileSync as readFileSync2,
|
|
175
134
|
writeFileSync,
|
|
176
135
|
readdirSync,
|
|
136
|
+
rmSync,
|
|
177
137
|
statSync
|
|
178
138
|
} from "fs";
|
|
179
139
|
import { dirname, relative, join } from "path";
|
|
180
|
-
import { removeSync } from "fs-extra";
|
|
181
140
|
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
182
141
|
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
183
142
|
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
@@ -218,7 +177,7 @@ function ensureDir(dirPath) {
|
|
|
218
177
|
}
|
|
219
178
|
function removeIfExists(targetPath) {
|
|
220
179
|
if (existsSync2(targetPath)) {
|
|
221
|
-
|
|
180
|
+
rmSync(targetPath, { recursive: true, force: true });
|
|
222
181
|
}
|
|
223
182
|
}
|
|
224
183
|
function listFiles(dirPath, options = {}) {
|
|
@@ -544,10 +503,178 @@ function mergeIgnorePatterns(configs) {
|
|
|
544
503
|
return result;
|
|
545
504
|
}
|
|
546
505
|
|
|
506
|
+
// src/features/models.ts
|
|
507
|
+
import { join as join7 } from "path";
|
|
508
|
+
import { z as z2 } from "zod";
|
|
509
|
+
var SECRET_PATTERNS = [
|
|
510
|
+
/["']api[_-]?key["']\s*:/i,
|
|
511
|
+
/["']apiKey["']\s*:/i,
|
|
512
|
+
/["']secret["']\s*:/i,
|
|
513
|
+
/["']password["']\s*:/i,
|
|
514
|
+
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
515
|
+
/["']private[_-]?key["']\s*:/i,
|
|
516
|
+
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
517
|
+
/sk-[a-zA-Z0-9]{20,}/,
|
|
518
|
+
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
519
|
+
];
|
|
520
|
+
var AgentModelSchema = z2.object({
|
|
521
|
+
model: z2.string(),
|
|
522
|
+
temperature: z2.number().min(0).max(2).optional(),
|
|
523
|
+
top_p: z2.number().min(0).max(1).optional()
|
|
524
|
+
});
|
|
525
|
+
var ModelProfileSchema = z2.object({
|
|
526
|
+
extends: z2.string().optional(),
|
|
527
|
+
description: z2.string().optional(),
|
|
528
|
+
default: z2.string().optional(),
|
|
529
|
+
small: z2.string().optional(),
|
|
530
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
531
|
+
});
|
|
532
|
+
var RoutingConditionSchema = z2.object({
|
|
533
|
+
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
534
|
+
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
535
|
+
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
536
|
+
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
537
|
+
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
538
|
+
});
|
|
539
|
+
var RoutingRuleSchema = z2.object({
|
|
540
|
+
when: z2.record(z2.string(), z2.string()),
|
|
541
|
+
use: z2.string(),
|
|
542
|
+
description: z2.string().optional(),
|
|
543
|
+
priority: z2.number().optional()
|
|
544
|
+
});
|
|
545
|
+
var ProviderModelSchema = z2.object({
|
|
546
|
+
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
547
|
+
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
548
|
+
});
|
|
549
|
+
var ProviderConfigSchema = z2.object({
|
|
550
|
+
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
551
|
+
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
552
|
+
});
|
|
553
|
+
var ModelsSchema = z2.object({
|
|
554
|
+
default: z2.string().optional(),
|
|
555
|
+
small: z2.string().optional(),
|
|
556
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
557
|
+
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
558
|
+
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
559
|
+
routing: z2.array(RoutingRuleSchema).optional(),
|
|
560
|
+
overrides: z2.record(z2.string(), z2.object({
|
|
561
|
+
default: z2.string().optional(),
|
|
562
|
+
small: z2.string().optional(),
|
|
563
|
+
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
564
|
+
})).optional()
|
|
565
|
+
});
|
|
566
|
+
function parseModels(packDir, packName) {
|
|
567
|
+
const modelsPath = join7(packDir, "models.json");
|
|
568
|
+
const raw = readJsonOrNull(modelsPath);
|
|
569
|
+
if (!raw)
|
|
570
|
+
return null;
|
|
571
|
+
const parsed = ModelsSchema.parse(raw);
|
|
572
|
+
return {
|
|
573
|
+
packName,
|
|
574
|
+
sourcePath: modelsPath,
|
|
575
|
+
config: parsed
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function mergeModelsConfigs(configs) {
|
|
579
|
+
const warnings = [];
|
|
580
|
+
const result = {};
|
|
581
|
+
for (const entry of configs) {
|
|
582
|
+
const { config, packName } = entry;
|
|
583
|
+
if (config.default !== undefined && result.default === undefined) {
|
|
584
|
+
result.default = config.default;
|
|
585
|
+
} else if (config.default !== undefined && result.default !== undefined) {
|
|
586
|
+
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
587
|
+
}
|
|
588
|
+
if (config.small !== undefined && result.small === undefined) {
|
|
589
|
+
result.small = config.small;
|
|
590
|
+
} else if (config.small !== undefined && result.small !== undefined) {
|
|
591
|
+
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
592
|
+
}
|
|
593
|
+
if (config.agents) {
|
|
594
|
+
if (!result.agents)
|
|
595
|
+
result.agents = {};
|
|
596
|
+
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
597
|
+
if (name in result.agents) {
|
|
598
|
+
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
result.agents[name] = assignment;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (config.profiles) {
|
|
605
|
+
if (!result.profiles)
|
|
606
|
+
result.profiles = {};
|
|
607
|
+
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
608
|
+
if (name in result.profiles) {
|
|
609
|
+
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
result.profiles[name] = profile;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (config.providers) {
|
|
616
|
+
if (!result.providers)
|
|
617
|
+
result.providers = {};
|
|
618
|
+
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
619
|
+
if (!(providerName in result.providers)) {
|
|
620
|
+
result.providers[providerName] = providerConfig;
|
|
621
|
+
} else {
|
|
622
|
+
const existing = result.providers[providerName];
|
|
623
|
+
if (!existing) {
|
|
624
|
+
result.providers[providerName] = providerConfig;
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (providerConfig.options) {
|
|
628
|
+
existing.options = {
|
|
629
|
+
...providerConfig.options,
|
|
630
|
+
...existing.options
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
if (providerConfig.models) {
|
|
634
|
+
if (!existing.models)
|
|
635
|
+
existing.models = {};
|
|
636
|
+
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
637
|
+
if (!(modelName in existing.models)) {
|
|
638
|
+
existing.models[modelName] = modelConfig;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (config.routing) {
|
|
646
|
+
if (!result.routing)
|
|
647
|
+
result.routing = [];
|
|
648
|
+
result.routing.push(...config.routing);
|
|
649
|
+
}
|
|
650
|
+
if (config.overrides) {
|
|
651
|
+
if (!result.overrides)
|
|
652
|
+
result.overrides = {};
|
|
653
|
+
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
654
|
+
if (targetId in result.overrides) {
|
|
655
|
+
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
result.overrides[targetId] = override;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return { config: result, warnings };
|
|
663
|
+
}
|
|
664
|
+
function scanModelsForSecrets(config) {
|
|
665
|
+
const warnings = [];
|
|
666
|
+
const json = JSON.stringify(config);
|
|
667
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
668
|
+
if (pattern.test(json)) {
|
|
669
|
+
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return warnings;
|
|
673
|
+
}
|
|
674
|
+
|
|
547
675
|
// src/core/pack-loader.ts
|
|
548
|
-
init_config();
|
|
549
676
|
import { existsSync as existsSync6 } from "fs";
|
|
550
|
-
import { resolve as
|
|
677
|
+
import { resolve as resolve2, isAbsolute } from "path";
|
|
551
678
|
class PackLoader {
|
|
552
679
|
projectRoot;
|
|
553
680
|
config;
|
|
@@ -580,10 +707,10 @@ class PackLoader {
|
|
|
580
707
|
}
|
|
581
708
|
loadPack(packDir, manifest) {
|
|
582
709
|
const name = manifest.name;
|
|
583
|
-
const rulesDir =
|
|
584
|
-
const commandsDir =
|
|
585
|
-
const agentsDir =
|
|
586
|
-
const skillsDir =
|
|
710
|
+
const rulesDir = resolve2(packDir, "rules");
|
|
711
|
+
const commandsDir = resolve2(packDir, "commands");
|
|
712
|
+
const agentsDir = resolve2(packDir, "agents");
|
|
713
|
+
const skillsDir = resolve2(packDir, "skills");
|
|
587
714
|
return {
|
|
588
715
|
manifest,
|
|
589
716
|
directory: packDir,
|
|
@@ -594,23 +721,25 @@ class PackLoader {
|
|
|
594
721
|
hooks: parseHooks(packDir, name),
|
|
595
722
|
plugins: parsePlugins(packDir, name),
|
|
596
723
|
mcp: parseMcp(packDir, name),
|
|
597
|
-
ignore: parseIgnore(packDir, name)
|
|
724
|
+
ignore: parseIgnore(packDir, name),
|
|
725
|
+
models: parseModels(packDir, name)
|
|
598
726
|
};
|
|
599
727
|
}
|
|
600
728
|
loadForBaseDir(baseDir) {
|
|
601
|
-
const baseDirRoot =
|
|
602
|
-
const localConfigPath =
|
|
729
|
+
const baseDirRoot = resolve2(this.projectRoot, baseDir);
|
|
730
|
+
const localConfigPath = resolve2(baseDirRoot, "agentpacks.jsonc");
|
|
603
731
|
if (!existsSync6(localConfigPath)) {
|
|
604
732
|
return { packs: [], warnings: [] };
|
|
605
733
|
}
|
|
606
|
-
const
|
|
607
|
-
const localConfig = loadWorkspaceConfig2(baseDirRoot);
|
|
734
|
+
const localConfig = loadWorkspaceConfig(baseDirRoot);
|
|
608
735
|
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
609
736
|
return loader.loadAll();
|
|
610
737
|
}
|
|
611
738
|
resolveCuratedPack(packRef) {
|
|
612
|
-
const curatedDir =
|
|
739
|
+
const curatedDir = resolve2(this.projectRoot, ".agentpacks", ".curated");
|
|
613
740
|
let packName = packRef;
|
|
741
|
+
if (packName.startsWith("registry:"))
|
|
742
|
+
packName = packName.slice(9);
|
|
614
743
|
if (packName.startsWith("npm:"))
|
|
615
744
|
packName = packName.slice(4);
|
|
616
745
|
if (packName.startsWith("github:"))
|
|
@@ -621,24 +750,28 @@ class PackLoader {
|
|
|
621
750
|
const parts = packName.split("/");
|
|
622
751
|
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
623
752
|
}
|
|
624
|
-
|
|
625
|
-
|
|
753
|
+
const withoutVersion = packName.split("@")[0] ?? packName;
|
|
754
|
+
packName = withoutVersion.split(":")[0] ?? withoutVersion;
|
|
755
|
+
const resolved = resolve2(curatedDir, packName);
|
|
626
756
|
return existsSync6(resolved) ? resolved : null;
|
|
627
757
|
}
|
|
628
758
|
resolvePackPath(packRef) {
|
|
629
759
|
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
630
|
-
return
|
|
760
|
+
return resolve2(this.projectRoot, packRef);
|
|
631
761
|
}
|
|
632
762
|
if (isAbsolute(packRef)) {
|
|
633
763
|
return packRef;
|
|
634
764
|
}
|
|
765
|
+
if (packRef.startsWith("registry:")) {
|
|
766
|
+
return this.resolveCuratedPack(packRef);
|
|
767
|
+
}
|
|
635
768
|
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
636
769
|
return this.resolveCuratedPack(packRef);
|
|
637
770
|
}
|
|
638
771
|
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
639
772
|
return this.resolveCuratedPack(packRef);
|
|
640
773
|
}
|
|
641
|
-
return
|
|
774
|
+
return resolve2(this.projectRoot, packRef);
|
|
642
775
|
}
|
|
643
776
|
}
|
|
644
777
|
export {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ModelsConfig, AgentModel, ModelProfile } from '../features/models.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolved model configuration after profile activation and target overrides.
|
|
4
|
+
*/
|
|
5
|
+
export interface ResolvedModels {
|
|
6
|
+
/** Primary model ID */
|
|
7
|
+
default?: string;
|
|
8
|
+
/** Lightweight/small model ID */
|
|
9
|
+
small?: string;
|
|
10
|
+
/** Per-agent model assignments */
|
|
11
|
+
agents: Record<string, AgentModel>;
|
|
12
|
+
/** Provider configurations (options, model-level options, variants) */
|
|
13
|
+
providers: Record<string, {
|
|
14
|
+
options?: Record<string, unknown>;
|
|
15
|
+
models?: Record<string, {
|
|
16
|
+
options?: Record<string, unknown>;
|
|
17
|
+
variants?: Record<string, Record<string, unknown>>;
|
|
18
|
+
}>;
|
|
19
|
+
}>;
|
|
20
|
+
/** Routing rules (passthrough for guidance generation) */
|
|
21
|
+
routing: {
|
|
22
|
+
when: Record<string, string>;
|
|
23
|
+
use: string;
|
|
24
|
+
}[];
|
|
25
|
+
/** Available profile names (for guidance docs) */
|
|
26
|
+
profileNames: string[];
|
|
27
|
+
/** Active profile name (if any) */
|
|
28
|
+
activeProfile?: string;
|
|
29
|
+
/** All profiles (for guidance docs) */
|
|
30
|
+
profiles: Record<string, {
|
|
31
|
+
description?: string;
|
|
32
|
+
default?: string;
|
|
33
|
+
small?: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the effective model configuration from merged models data.
|
|
38
|
+
*
|
|
39
|
+
* Resolution order:
|
|
40
|
+
* 1. Start with base merged config (default, small, agents, providers)
|
|
41
|
+
* 2. Apply selected profile overlay (if modelProfile is set)
|
|
42
|
+
* 3. Apply target-specific overrides (if target has overrides)
|
|
43
|
+
*
|
|
44
|
+
* @param merged - The merged ModelsConfig from all packs
|
|
45
|
+
* @param modelProfile - The active profile name (from workspace config)
|
|
46
|
+
* @param targetId - The target to resolve for (applies target overrides)
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveModels(merged: ModelsConfig, modelProfile?: string, targetId?: string): ResolvedModels;
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the effective model for a specific agent.
|
|
51
|
+
* Priority: models feature agents > agent frontmatter model > default model.
|
|
52
|
+
*
|
|
53
|
+
* @param resolved - The resolved model config
|
|
54
|
+
* @param agentName - The agent name to look up
|
|
55
|
+
* @param frontmatterModel - Model from agent frontmatter (lower priority)
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolveAgentModel(resolved: ResolvedModels, agentName: string, frontmatterModel?: string): {
|
|
58
|
+
model?: string;
|
|
59
|
+
temperature?: number;
|
|
60
|
+
top_p?: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Resolve profile inheritance by following `extends` chains.
|
|
64
|
+
*
|
|
65
|
+
* A profile with `extends: "parent"` inherits all fields from the parent
|
|
66
|
+
* profile, with the child's fields taking precedence.
|
|
67
|
+
*
|
|
68
|
+
* Cycle detection: tracks visited profile names; throws on cycle.
|
|
69
|
+
* Max depth: 10 levels (to prevent runaway resolution).
|
|
70
|
+
*
|
|
71
|
+
* @param profileName - The profile to resolve
|
|
72
|
+
* @param profiles - All available profiles
|
|
73
|
+
* @returns Fully resolved profile with inherited fields applied
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolveProfileInheritance(profileName: string, profiles: Record<string, ModelProfile>): ModelProfile;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// src/core/profile-resolver.ts
|
|
5
|
+
function resolveModels(merged, modelProfile, targetId) {
|
|
6
|
+
let defaultModel = merged.default;
|
|
7
|
+
let smallModel = merged.small;
|
|
8
|
+
let agents = { ...merged.agents };
|
|
9
|
+
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
10
|
+
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
11
|
+
if (resolvedProfile.default)
|
|
12
|
+
defaultModel = resolvedProfile.default;
|
|
13
|
+
if (resolvedProfile.small)
|
|
14
|
+
smallModel = resolvedProfile.small;
|
|
15
|
+
if (resolvedProfile.agents) {
|
|
16
|
+
agents = { ...agents, ...resolvedProfile.agents };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (targetId) {
|
|
20
|
+
const targetOverride = merged.overrides?.[targetId];
|
|
21
|
+
if (targetOverride) {
|
|
22
|
+
if (targetOverride.default)
|
|
23
|
+
defaultModel = targetOverride.default;
|
|
24
|
+
if (targetOverride.small)
|
|
25
|
+
smallModel = targetOverride.small;
|
|
26
|
+
if (targetOverride.agents) {
|
|
27
|
+
agents = { ...agents, ...targetOverride.agents };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const providers = {};
|
|
32
|
+
if (merged.providers) {
|
|
33
|
+
for (const [name, config] of Object.entries(merged.providers)) {
|
|
34
|
+
providers[name] = {
|
|
35
|
+
...config.options ? { options: config.options } : {},
|
|
36
|
+
...config.models ? { models: config.models } : {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const profileNames = Object.keys(merged.profiles ?? {});
|
|
41
|
+
const profiles = {};
|
|
42
|
+
if (merged.profiles) {
|
|
43
|
+
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
44
|
+
profiles[name] = {
|
|
45
|
+
description: profile.description,
|
|
46
|
+
default: profile.default,
|
|
47
|
+
small: profile.small
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
default: defaultModel,
|
|
53
|
+
small: smallModel,
|
|
54
|
+
agents,
|
|
55
|
+
providers,
|
|
56
|
+
routing: merged.routing ?? [],
|
|
57
|
+
profileNames,
|
|
58
|
+
activeProfile: modelProfile,
|
|
59
|
+
profiles
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
63
|
+
const fromModels = resolved.agents[agentName];
|
|
64
|
+
if (fromModels) {
|
|
65
|
+
return {
|
|
66
|
+
model: fromModels.model,
|
|
67
|
+
temperature: fromModels.temperature,
|
|
68
|
+
top_p: fromModels.top_p
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (frontmatterModel) {
|
|
72
|
+
return { model: frontmatterModel };
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
function resolveProfileInheritance(profileName, profiles) {
|
|
77
|
+
const visited = new Set;
|
|
78
|
+
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
79
|
+
}
|
|
80
|
+
var MAX_INHERITANCE_DEPTH = 10;
|
|
81
|
+
function resolveProfileChain(name, profiles, visited, depth) {
|
|
82
|
+
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
83
|
+
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
84
|
+
}
|
|
85
|
+
if (visited.has(name)) {
|
|
86
|
+
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" \u2192 ")}`);
|
|
87
|
+
}
|
|
88
|
+
const profile = profiles[name];
|
|
89
|
+
if (!profile) {
|
|
90
|
+
throw new Error(`Profile "${name}" not found`);
|
|
91
|
+
}
|
|
92
|
+
visited.add(name);
|
|
93
|
+
if (!profile.extends) {
|
|
94
|
+
return { ...profile };
|
|
95
|
+
}
|
|
96
|
+
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
97
|
+
return {
|
|
98
|
+
description: profile.description ?? parent.description,
|
|
99
|
+
default: profile.default ?? parent.default,
|
|
100
|
+
small: profile.small ?? parent.small,
|
|
101
|
+
agents: {
|
|
102
|
+
...parent.agents,
|
|
103
|
+
...profile.agents
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
resolveProfileInheritance,
|
|
109
|
+
resolveModels,
|
|
110
|
+
resolveAgentModel
|
|
111
|
+
};
|