agentpacks 1.7.13 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
|
@@ -1,478 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
mkdirSync,
|
|
8
|
-
readdirSync,
|
|
9
|
-
readFileSync,
|
|
10
|
-
rmSync,
|
|
11
|
-
statSync,
|
|
12
|
-
writeFileSync
|
|
13
|
-
} from "fs";
|
|
14
|
-
import { dirname, join, relative } from "path";
|
|
15
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
16
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
17
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
18
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
19
|
-
const { header = true, type } = options;
|
|
20
|
-
const ext = type ?? inferFileType(filepath);
|
|
21
|
-
ensureDir(dirname(filepath));
|
|
22
|
-
let output = content;
|
|
23
|
-
if (header) {
|
|
24
|
-
const headerComment = getHeader(ext);
|
|
25
|
-
if (headerComment) {
|
|
26
|
-
output = `${headerComment}
|
|
27
|
-
${content}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
writeFileSync(filepath, output, "utf-8");
|
|
31
|
-
}
|
|
32
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
33
|
-
const json = JSON.stringify(data, null, 2);
|
|
34
|
-
writeGeneratedFile(filepath, json + `
|
|
35
|
-
`, { ...options, type: "json" });
|
|
36
|
-
}
|
|
37
|
-
function readFileOrNull(filepath) {
|
|
38
|
-
if (!existsSync(filepath))
|
|
39
|
-
return null;
|
|
40
|
-
return readFileSync(filepath, "utf-8");
|
|
41
|
-
}
|
|
42
|
-
function readJsonOrNull(filepath) {
|
|
43
|
-
const content = readFileOrNull(filepath);
|
|
44
|
-
if (content === null)
|
|
45
|
-
return null;
|
|
46
|
-
return JSON.parse(content);
|
|
47
|
-
}
|
|
48
|
-
function ensureDir(dirPath) {
|
|
49
|
-
if (!existsSync(dirPath)) {
|
|
50
|
-
mkdirSync(dirPath, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function removeIfExists(targetPath) {
|
|
54
|
-
if (existsSync(targetPath)) {
|
|
55
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function listFiles(dirPath, options = {}) {
|
|
59
|
-
const { extension, recursive = false } = options;
|
|
60
|
-
if (!existsSync(dirPath))
|
|
61
|
-
return [];
|
|
62
|
-
const results = [];
|
|
63
|
-
const entries = readdirSync(dirPath);
|
|
64
|
-
for (const entry of entries) {
|
|
65
|
-
const fullPath = join(dirPath, entry);
|
|
66
|
-
const stat = statSync(fullPath);
|
|
67
|
-
if (stat.isDirectory() && recursive) {
|
|
68
|
-
results.push(...listFiles(fullPath, options));
|
|
69
|
-
} else if (stat.isFile()) {
|
|
70
|
-
if (!extension || entry.endsWith(extension)) {
|
|
71
|
-
results.push(fullPath);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return results;
|
|
76
|
-
}
|
|
77
|
-
function listDirs(dirPath) {
|
|
78
|
-
if (!existsSync(dirPath))
|
|
79
|
-
return [];
|
|
80
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
81
|
-
}
|
|
82
|
-
function relPath(projectRoot, filepath) {
|
|
83
|
-
return relative(projectRoot, filepath);
|
|
84
|
-
}
|
|
85
|
-
function isGeneratedFile(filepath) {
|
|
86
|
-
const content = readFileOrNull(filepath);
|
|
87
|
-
if (!content)
|
|
88
|
-
return false;
|
|
89
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
90
|
-
}
|
|
91
|
-
function inferFileType(filepath) {
|
|
92
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
93
|
-
return "json";
|
|
94
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
95
|
-
return "ts";
|
|
96
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
97
|
-
return "js";
|
|
98
|
-
return "md";
|
|
99
|
-
}
|
|
100
|
-
function getHeader(type) {
|
|
101
|
-
switch (type) {
|
|
102
|
-
case "md":
|
|
103
|
-
return GENERATED_HEADER_MD;
|
|
104
|
-
case "json":
|
|
105
|
-
return GENERATED_HEADER_JSON;
|
|
106
|
-
case "js":
|
|
107
|
-
case "ts":
|
|
108
|
-
return GENERATED_HEADER_JS;
|
|
109
|
-
default:
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/utils/frontmatter.ts
|
|
115
|
-
import matter from "gray-matter";
|
|
116
|
-
function parseFrontmatter(source) {
|
|
117
|
-
const { data, content } = matter(source);
|
|
118
|
-
return {
|
|
119
|
-
data,
|
|
120
|
-
content: content.trim(),
|
|
121
|
-
raw: source
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function serializeFrontmatter(data, content) {
|
|
125
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
126
|
-
if (Object.keys(filtered).length === 0) {
|
|
127
|
-
return content;
|
|
128
|
-
}
|
|
129
|
-
return matter.stringify(content, filtered);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// src/features/commands.ts
|
|
133
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
134
|
-
import { basename } from "path";
|
|
135
|
-
function parseCommands(commandsDir, packName) {
|
|
136
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
137
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
138
|
-
}
|
|
139
|
-
function parseCommandFile(filepath, packName) {
|
|
140
|
-
const raw = readFileSync2(filepath, "utf-8");
|
|
141
|
-
const { data, content } = parseFrontmatter(raw);
|
|
142
|
-
return {
|
|
143
|
-
name: basename(filepath, ".md"),
|
|
144
|
-
sourcePath: filepath,
|
|
145
|
-
packName,
|
|
146
|
-
meta: data,
|
|
147
|
-
content
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
151
|
-
const { targets } = cmd.meta;
|
|
152
|
-
if (!targets || targets === "*")
|
|
153
|
-
return true;
|
|
154
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
155
|
-
return true;
|
|
156
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// src/features/rules.ts
|
|
160
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
161
|
-
import { basename as basename2 } from "path";
|
|
162
|
-
function parseRules(rulesDir, packName) {
|
|
163
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
164
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
165
|
-
}
|
|
166
|
-
function parseRuleFile(filepath, packName) {
|
|
167
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
168
|
-
const { data, content } = parseFrontmatter(raw);
|
|
169
|
-
return {
|
|
170
|
-
name: basename2(filepath, ".md"),
|
|
171
|
-
sourcePath: filepath,
|
|
172
|
-
packName,
|
|
173
|
-
meta: data,
|
|
174
|
-
content
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
178
|
-
const { targets } = rule.meta;
|
|
179
|
-
if (!targets || targets === "*")
|
|
180
|
-
return true;
|
|
181
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
182
|
-
return true;
|
|
183
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
184
|
-
}
|
|
185
|
-
function getRootRules(rules) {
|
|
186
|
-
return rules.filter((r) => r.meta.root === true);
|
|
187
|
-
}
|
|
188
|
-
function getDetailRules(rules) {
|
|
189
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/core/profile-resolver.ts
|
|
193
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
194
|
-
let defaultModel = merged.default;
|
|
195
|
-
let smallModel = merged.small;
|
|
196
|
-
let agents = { ...merged.agents };
|
|
197
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
198
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
199
|
-
if (resolvedProfile.default)
|
|
200
|
-
defaultModel = resolvedProfile.default;
|
|
201
|
-
if (resolvedProfile.small)
|
|
202
|
-
smallModel = resolvedProfile.small;
|
|
203
|
-
if (resolvedProfile.agents) {
|
|
204
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (targetId) {
|
|
208
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
209
|
-
if (targetOverride) {
|
|
210
|
-
if (targetOverride.default)
|
|
211
|
-
defaultModel = targetOverride.default;
|
|
212
|
-
if (targetOverride.small)
|
|
213
|
-
smallModel = targetOverride.small;
|
|
214
|
-
if (targetOverride.agents) {
|
|
215
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const providers = {};
|
|
220
|
-
if (merged.providers) {
|
|
221
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
222
|
-
providers[name] = {
|
|
223
|
-
...config.options ? { options: config.options } : {},
|
|
224
|
-
...config.models ? { models: config.models } : {}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
229
|
-
const profiles = {};
|
|
230
|
-
if (merged.profiles) {
|
|
231
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
232
|
-
profiles[name] = {
|
|
233
|
-
description: profile.description,
|
|
234
|
-
default: profile.default,
|
|
235
|
-
small: profile.small
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
default: defaultModel,
|
|
241
|
-
small: smallModel,
|
|
242
|
-
agents,
|
|
243
|
-
providers,
|
|
244
|
-
routing: merged.routing ?? [],
|
|
245
|
-
profileNames,
|
|
246
|
-
activeProfile: modelProfile,
|
|
247
|
-
profiles
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
251
|
-
const fromModels = resolved.agents[agentName];
|
|
252
|
-
if (fromModels) {
|
|
253
|
-
return {
|
|
254
|
-
model: fromModels.model,
|
|
255
|
-
temperature: fromModels.temperature,
|
|
256
|
-
top_p: fromModels.top_p
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
if (frontmatterModel) {
|
|
260
|
-
return { model: frontmatterModel };
|
|
261
|
-
}
|
|
262
|
-
return {};
|
|
263
|
-
}
|
|
264
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
265
|
-
const visited = new Set;
|
|
266
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
267
|
-
}
|
|
268
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
269
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
270
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
271
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
272
|
-
}
|
|
273
|
-
if (visited.has(name)) {
|
|
274
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" → ")}`);
|
|
275
|
-
}
|
|
276
|
-
const profile = profiles[name];
|
|
277
|
-
if (!profile) {
|
|
278
|
-
throw new Error(`Profile "${name}" not found`);
|
|
279
|
-
}
|
|
280
|
-
visited.add(name);
|
|
281
|
-
if (!profile.extends) {
|
|
282
|
-
return { ...profile };
|
|
283
|
-
}
|
|
284
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
285
|
-
return {
|
|
286
|
-
description: profile.description ?? parent.description,
|
|
287
|
-
default: profile.default ?? parent.default,
|
|
288
|
-
small: profile.small ?? parent.small,
|
|
289
|
-
agents: {
|
|
290
|
-
...parent.agents,
|
|
291
|
-
...profile.agents
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/utils/model-guidance.ts
|
|
297
|
-
function generateModelGuidanceMarkdown(resolved) {
|
|
298
|
-
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0 && Object.keys(resolved.profiles).length === 0) {
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
const lines = [];
|
|
302
|
-
lines.push("# Model Configuration");
|
|
303
|
-
lines.push("");
|
|
304
|
-
lines.push("Use the following model preferences when working in this project.");
|
|
305
|
-
lines.push("");
|
|
306
|
-
if (resolved.default || resolved.small) {
|
|
307
|
-
lines.push("## Default Models");
|
|
308
|
-
lines.push("");
|
|
309
|
-
if (resolved.default) {
|
|
310
|
-
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
311
|
-
}
|
|
312
|
-
if (resolved.small) {
|
|
313
|
-
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
314
|
-
}
|
|
315
|
-
lines.push("");
|
|
316
|
-
}
|
|
317
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
318
|
-
if (agentEntries.length > 0) {
|
|
319
|
-
lines.push("## Agent Model Assignments");
|
|
320
|
-
lines.push("");
|
|
321
|
-
lines.push("| Agent | Model | Temperature |");
|
|
322
|
-
lines.push("| --- | --- | --- |");
|
|
323
|
-
for (const [name, assignment] of agentEntries) {
|
|
324
|
-
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "—";
|
|
325
|
-
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
326
|
-
}
|
|
327
|
-
lines.push("");
|
|
328
|
-
}
|
|
329
|
-
if (Object.keys(resolved.profiles).length > 0) {
|
|
330
|
-
lines.push("## Available Profiles");
|
|
331
|
-
lines.push("");
|
|
332
|
-
lines.push("| Profile | Description | Default Model |");
|
|
333
|
-
lines.push("| --- | --- | --- |");
|
|
334
|
-
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
335
|
-
lines.push(`| ${name} | ${profile.description ?? "—"} | ${profile.default ?? "—"} |`);
|
|
336
|
-
}
|
|
337
|
-
lines.push("");
|
|
338
|
-
}
|
|
339
|
-
if (resolved.activeProfile) {
|
|
340
|
-
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
341
|
-
lines.push("");
|
|
342
|
-
}
|
|
343
|
-
if (resolved.routing.length > 0) {
|
|
344
|
-
lines.push("## Task-Aware Routing");
|
|
345
|
-
lines.push("");
|
|
346
|
-
lines.push("Select the appropriate profile based on the task context:");
|
|
347
|
-
lines.push("");
|
|
348
|
-
lines.push("| Condition | Profile | Description |");
|
|
349
|
-
lines.push("| --- | --- | --- |");
|
|
350
|
-
for (const rule of resolved.routing) {
|
|
351
|
-
const conditions = Object.entries(rule.when).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
352
|
-
const desc = rule.description ?? "—";
|
|
353
|
-
lines.push(`| ${conditions} | ${rule.use} | ${desc} |`);
|
|
354
|
-
}
|
|
355
|
-
lines.push("");
|
|
356
|
-
lines.push("### Condition Reference");
|
|
357
|
-
lines.push("");
|
|
358
|
-
lines.push("- **complexity**: low | medium | high | critical");
|
|
359
|
-
lines.push("- **urgency**: low | normal | high");
|
|
360
|
-
lines.push("- **budget**: minimal | standard | premium");
|
|
361
|
-
lines.push("- **contextWindowNeed**: small | medium | large | max");
|
|
362
|
-
lines.push("- **toolUseIntensity**: none | light | heavy");
|
|
363
|
-
lines.push("");
|
|
364
|
-
}
|
|
365
|
-
return lines.join(`
|
|
366
|
-
`);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// src/targets/base-target.ts
|
|
370
|
-
class BaseTarget {
|
|
371
|
-
supportsFeature(feature) {
|
|
372
|
-
return this.supportedFeatures.includes(feature);
|
|
373
|
-
}
|
|
374
|
-
getEffectiveFeatures(enabledFeatures) {
|
|
375
|
-
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
376
|
-
}
|
|
377
|
-
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
378
|
-
return {
|
|
379
|
-
targetId: this.id,
|
|
380
|
-
filesWritten,
|
|
381
|
-
filesDeleted,
|
|
382
|
-
warnings
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// src/targets/generic-md-target.ts
|
|
388
|
-
import { join as join2, resolve } from "path";
|
|
389
|
-
function createGenericMdTarget(config) {
|
|
390
|
-
return new GenericMdTarget(config);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
class GenericMdTarget extends BaseTarget {
|
|
394
|
-
id;
|
|
395
|
-
name;
|
|
396
|
-
supportedFeatures;
|
|
397
|
-
config;
|
|
398
|
-
constructor(config) {
|
|
399
|
-
super();
|
|
400
|
-
this.id = config.id;
|
|
401
|
-
this.name = config.name;
|
|
402
|
-
this.supportedFeatures = config.supportedFeatures;
|
|
403
|
-
this.config = config;
|
|
404
|
-
}
|
|
405
|
-
generate(options) {
|
|
406
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
407
|
-
const root = resolve(projectRoot, baseDir);
|
|
408
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
409
|
-
const filesWritten = [];
|
|
410
|
-
const filesDeleted = [];
|
|
411
|
-
const warnings = [];
|
|
412
|
-
const configDir = resolve(root, this.config.configDir);
|
|
413
|
-
const rulesSubDir = this.config.rulesDir ?? "rules";
|
|
414
|
-
const ext = this.config.ruleExtension ?? ".md";
|
|
415
|
-
if (effective.includes("rules")) {
|
|
416
|
-
const rulesDir = resolve(configDir, rulesSubDir);
|
|
417
|
-
if (deleteExisting) {
|
|
418
|
-
removeIfExists(rulesDir);
|
|
419
|
-
filesDeleted.push(rulesDir);
|
|
420
|
-
}
|
|
421
|
-
ensureDir(rulesDir);
|
|
422
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
|
|
423
|
-
for (const rule of rules) {
|
|
424
|
-
const filepath = join2(rulesDir, `${rule.name}${ext}`);
|
|
425
|
-
writeGeneratedFile(filepath, rule.content);
|
|
426
|
-
filesWritten.push(filepath);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (effective.includes("commands")) {
|
|
430
|
-
const commandsDir = resolve(configDir, "commands");
|
|
431
|
-
if (deleteExisting) {
|
|
432
|
-
removeIfExists(commandsDir);
|
|
433
|
-
filesDeleted.push(commandsDir);
|
|
434
|
-
}
|
|
435
|
-
ensureDir(commandsDir);
|
|
436
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
|
|
437
|
-
for (const cmd of commands) {
|
|
438
|
-
const filepath = join2(commandsDir, `${cmd.name}.md`);
|
|
439
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
440
|
-
filesWritten.push(filepath);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
if (effective.includes("mcp")) {
|
|
444
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
445
|
-
if (mcpEntries.length > 0) {
|
|
446
|
-
const mcpDir = this.config.mcpInConfigDir ? configDir : root;
|
|
447
|
-
const filepath = resolve(mcpDir, "mcp.json");
|
|
448
|
-
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
449
|
-
header: false
|
|
450
|
-
});
|
|
451
|
-
filesWritten.push(filepath);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (effective.includes("ignore") && this.config.ignoreFile) {
|
|
455
|
-
if (features.ignorePatterns.length > 0) {
|
|
456
|
-
const filepath = resolve(root, this.config.ignoreFile);
|
|
457
|
-
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
458
|
-
`) + `
|
|
459
|
-
`);
|
|
460
|
-
filesWritten.push(filepath);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (effective.includes("models") && features.models) {
|
|
464
|
-
const resolved = resolveModels(features.models, options.modelProfile, this.id);
|
|
465
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
466
|
-
if (guidance) {
|
|
467
|
-
ensureDir(configDir);
|
|
468
|
-
const filepath = join2(configDir, "model-config.md");
|
|
469
|
-
writeGeneratedFile(filepath, guidance);
|
|
470
|
-
filesWritten.push(filepath);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
export {
|
|
477
|
-
createGenericMdTarget
|
|
478
|
-
};
|
|
1
|
+
import{createRequire as f}from"node:module";var Zq=f(import.meta.url);import{existsSync as x,mkdirSync as d,readdirSync as k,readFileSync as n,rmSync as o,statSync as A,writeFileSync as s}from"fs";import{dirname as a,join as R,relative as l}from"path";var S="<!-- Generated by agentpacks. DO NOT EDIT. -->",F="// Generated by agentpacks. DO NOT EDIT.",M="// Generated by agentpacks. DO NOT EDIT.";function O(q,K,L={}){let{header:Q=!0,type:V}=L,Z=V??i(q);I(a(q));let U=K;if(Q){let $=r(Z);if($)U=`${$}
|
|
2
|
+
${K}`}s(q,U,"utf-8")}function N(q,K,L={}){let Q=JSON.stringify(K,null,2);O(q,Q+`
|
|
3
|
+
`,{...L,type:"json"})}function y(q){if(!x(q))return null;return n(q,"utf-8")}function Uq(q){let K=y(q);if(K===null)return null;return JSON.parse(K)}function I(q){if(!x(q))d(q,{recursive:!0})}function _(q){if(x(q))o(q,{recursive:!0,force:!0})}function G(q,K={}){let{extension:L,recursive:Q=!1}=K;if(!x(q))return[];let V=[],Z=k(q);for(let U of Z){let $=R(q,U),X=A($);if(X.isDirectory()&&Q)V.push(...G($,K));else if(X.isFile()){if(!L||U.endsWith(L))V.push($)}}return V}function Xq(q){if(!x(q))return[];return k(q).map((K)=>R(q,K)).filter((K)=>A(K).isDirectory())}function Jq(q,K){return l(q,K)}function Wq(q){let K=y(q);if(!K)return!1;return K.startsWith(S)||K.startsWith(F)||K.startsWith(M)}function i(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 r(q){switch(q){case"md":return S;case"json":return F;case"js":case"ts":return M;default:return null}}import E from"gray-matter";function T(q){let{data:K,content:L}=E(q);return{data:K,content:L.trim(),raw:q}}function Cq(q,K){let L=Object.fromEntries(Object.entries(q).filter(([,Q])=>Q!==void 0));if(Object.keys(L).length===0)return K;return E.stringify(K,L)}import{readFileSync as t}from"fs";import{basename as e}from"path";function _q(q,K){return G(q,{extension:".md"}).map((Q)=>qq(Q,K))}function qq(q,K){let L=t(q,"utf-8"),{data:Q,content:V}=T(L);return{name:e(q,".md"),sourcePath:q,packName:K,meta:Q,content:V}}function P(q,K){let{targets:L}=q.meta;if(!L||L==="*")return!0;if(Array.isArray(L)&&L.includes("*"))return!0;return Array.isArray(L)&&L.includes(K)}import{readFileSync as Kq}from"fs";import{basename as Lq}from"path";function Sq(q,K){return G(q,{extension:".md"}).map((Q)=>Qq(Q,K))}function Qq(q,K){let L=Kq(q,"utf-8"),{data:Q,content:V}=T(L);return{name:Lq(q,".md"),sourcePath:q,packName:K,meta:Q,content:V}}function D(q,K){let{targets:L}=q.meta;if(!L||L==="*")return!0;if(Array.isArray(L)&&L.includes("*"))return!0;return Array.isArray(L)&&L.includes(K)}function Fq(q){return q.filter((K)=>K.meta.root===!0)}function Mq(q){return q.filter((K)=>K.meta.root!==!0)}function v(q,K,L){let{default:Q,small:V}=q,Z={...q.agents};if(K&&q.profiles?.[K]){let Y=Vq(K,q.profiles);if(Y.default)Q=Y.default;if(Y.small)V=Y.small;if(Y.agents)Z={...Z,...Y.agents}}if(L){let Y=q.overrides?.[L];if(Y){if(Y.default)Q=Y.default;if(Y.small)V=Y.small;if(Y.agents)Z={...Z,...Y.agents}}}let U={};if(q.providers)for(let[Y,J]of Object.entries(q.providers))U[Y]={...J.options?{options:J.options}:{},...J.models?{models:J.models}:{}};let $=Object.keys(q.profiles??{}),X={};if(q.profiles)for(let[Y,J]of Object.entries(q.profiles))X[Y]={description:J.description,default:J.default,small:J.small};return{default:Q,small:V,agents:Z,providers:U,routing:q.routing??[],profileNames:$,activeProfile:K,profiles:X}}function yq(q,K,L){let Q=q.agents[K];if(Q)return{model:Q.model,temperature:Q.temperature,top_p:Q.top_p};if(L)return{model:L};return{}}function Vq(q,K){return h(q,K,new Set,0)}var u=10;function h(q,K,L,Q){if(Q>u)throw Error(`Profile inheritance too deep (max ${u}): ${q}`);if(L.has(q))throw Error(`Circular profile inheritance detected: ${[...L,q].join(" → ")}`);let V=K[q];if(!V)throw Error(`Profile "${q}" not found`);if(L.add(q),!V.extends)return{...V};let Z=h(V.extends,K,L,Q+1);return{description:V.description??Z.description,default:V.default??Z.default,small:V.small??Z.small,agents:{...Z.agents,...V.agents}}}function c(q){if(!q.default&&!q.small&&Object.keys(q.agents).length===0&&Object.keys(q.profiles).length===0)return null;let K=[];if(K.push("# Model Configuration"),K.push(""),K.push("Use the following model preferences when working in this project."),K.push(""),q.default||q.small){if(K.push("## Default Models"),K.push(""),q.default)K.push(`- **Primary model**: ${q.default}`);if(q.small)K.push(`- **Lightweight tasks** (titles, summaries): ${q.small}`);K.push("")}let L=Object.entries(q.agents);if(L.length>0){K.push("## Agent Model Assignments"),K.push(""),K.push("| Agent | Model | Temperature |"),K.push("| --- | --- | --- |");for(let[Q,V]of L){let Z=V.temperature!==void 0?String(V.temperature):"—";K.push(`| ${Q} | ${V.model} | ${Z} |`)}K.push("")}if(Object.keys(q.profiles).length>0){K.push("## Available Profiles"),K.push(""),K.push("| Profile | Description | Default Model |"),K.push("| --- | --- | --- |");for(let[Q,V]of Object.entries(q.profiles))K.push(`| ${Q} | ${V.description??"—"} | ${V.default??"—"} |`);K.push("")}if(q.activeProfile)K.push(`**Active profile**: \`${q.activeProfile}\``),K.push("");if(q.routing.length>0){K.push("## Task-Aware Routing"),K.push(""),K.push("Select the appropriate profile based on the task context:"),K.push(""),K.push("| Condition | Profile | Description |"),K.push("| --- | --- | --- |");for(let Q of q.routing){let V=Object.entries(Q.when).map(([U,$])=>`${U}=${$}`).join(", "),Z=Q.description??"—";K.push(`| ${V} | ${Q.use} | ${Z} |`)}K.push(""),K.push("### Condition Reference"),K.push(""),K.push("- **complexity**: low | medium | high | critical"),K.push("- **urgency**: low | normal | high"),K.push("- **budget**: minimal | standard | premium"),K.push("- **contextWindowNeed**: small | medium | large | max"),K.push("- **toolUseIntensity**: none | light | heavy"),K.push("")}return K.join(`
|
|
4
|
+
`)}class w{supportsFeature(q){return this.supportedFeatures.includes(q)}getEffectiveFeatures(q){return q.filter((K)=>this.supportsFeature(K))}createResult(q=[],K=[],L=[]){return{targetId:this.id,filesWritten:q,filesDeleted:K,warnings:L}}}import{join as j,resolve as b}from"path";function fq(q){return new g(q)}class g extends w{id;name;supportedFeatures;config;constructor(q){super();this.id=q.id,this.name=q.name,this.supportedFeatures=q.supportedFeatures,this.config=q}generate(q){let{projectRoot:K,baseDir:L,features:Q,enabledFeatures:V,deleteExisting:Z}=q,U=b(K,L),$=this.getEffectiveFeatures(V),X=[],Y=[],J=[],C=b(U,this.config.configDir),m=this.config.rulesDir??"rules",p=this.config.ruleExtension??".md";if($.includes("rules")){let z=b(C,m);if(Z)_(z),Y.push(z);I(z);let W=Q.rules.filter((B)=>D(B,this.id));for(let B of W){let H=j(z,`${B.name}${p}`);O(H,B.content),X.push(H)}}if($.includes("commands")){let z=b(C,"commands");if(Z)_(z),Y.push(z);I(z);let W=Q.commands.filter((B)=>P(B,this.id));for(let B of W){let H=j(z,`${B.name}.md`);O(H,B.content),X.push(H)}}if($.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let W=this.config.mcpInConfigDir?C:U,B=b(W,"mcp.json");N(B,{mcpServers:Q.mcpServers},{header:!1}),X.push(B)}}if($.includes("ignore")&&this.config.ignoreFile){if(Q.ignorePatterns.length>0){let z=b(U,this.config.ignoreFile);O(z,Q.ignorePatterns.join(`
|
|
5
|
+
`)+`
|
|
6
|
+
`),X.push(z)}}if($.includes("models")&&Q.models){let z=v(Q.models,q.modelProfile,this.id),W=c(z);if(W){I(C);let B=j(C,"model-config.md");O(B,W),X.push(B)}}return this.createResult(X,Y,J)}}export{fq as createGenericMdTarget};
|