agentpacks 0.9.0 → 1.0.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 +41 -14
- package/dist/api.js +403 -179
- package/dist/cli/export-cmd.js +58 -5
- package/dist/cli/generate.js +268 -59
- package/dist/cli/import-cmd.js +203 -95
- package/dist/cli/install.js +1 -0
- package/dist/cli/models-explain.js +56 -0
- package/dist/cli/pack/list.js +56 -0
- package/dist/cli/pack/validate.js +143 -18
- package/dist/cli/publish.js +1 -0
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/metarepo.js +1 -0
- package/dist/core/pack-loader.js +56 -0
- package/dist/exporters/cursor-plugin.js +109 -22
- package/dist/exporters/index.js +109 -22
- package/dist/features/index.d.ts +1 -1
- package/dist/features/index.js +59 -0
- package/dist/features/skills.d.ts +22 -0
- package/dist/features/skills.js +60 -1
- package/dist/importers/cursor.js +122 -26
- package/dist/importers/opencode.js +138 -24
- package/dist/importers/rulesync.js +147 -33
- package/dist/index.js +484 -244
- package/dist/node/api.js +403 -179
- package/dist/node/cli/export-cmd.js +58 -5
- package/dist/node/cli/generate.js +268 -59
- package/dist/node/cli/import-cmd.js +203 -95
- package/dist/node/cli/install.js +1 -0
- package/dist/node/cli/models-explain.js +56 -0
- package/dist/node/cli/pack/list.js +56 -0
- package/dist/node/cli/pack/validate.js +143 -18
- package/dist/node/cli/publish.js +1 -0
- package/dist/node/core/config.js +1 -0
- package/dist/node/core/index.js +56 -0
- package/dist/node/core/metarepo.js +1 -0
- package/dist/node/core/pack-loader.js +56 -0
- package/dist/node/exporters/cursor-plugin.js +109 -22
- package/dist/node/exporters/index.js +109 -22
- package/dist/node/features/index.js +59 -0
- package/dist/node/features/skills.js +60 -1
- package/dist/node/importers/cursor.js +122 -26
- package/dist/node/importers/opencode.js +138 -24
- package/dist/node/importers/rulesync.js +147 -33
- package/dist/node/index.js +484 -244
- package/dist/node/targets/claude-code.js +56 -1
- package/dist/node/targets/codex-cli.js +56 -1
- package/dist/node/targets/copilot.js +56 -1
- package/dist/node/targets/cursor.js +56 -5
- package/dist/node/targets/index.js +268 -59
- package/dist/node/targets/mistral-vibe.js +661 -0
- package/dist/node/targets/opencode.js +56 -1
- package/dist/node/targets/registry.js +267 -59
- package/dist/node/utils/model-allowlist.js +6 -2
- package/dist/targets/claude-code.js +56 -1
- package/dist/targets/codex-cli.js +56 -1
- package/dist/targets/copilot.js +56 -1
- package/dist/targets/cursor.js +56 -5
- package/dist/targets/index.d.ts +1 -0
- package/dist/targets/index.js +268 -59
- package/dist/targets/mistral-vibe.d.ts +13 -0
- package/dist/targets/mistral-vibe.js +661 -0
- package/dist/targets/opencode.js +56 -1
- package/dist/targets/registry.js +267 -59
- package/dist/utils/model-allowlist.js +6 -2
- package/package.json +15 -3
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// src/utils/filesystem.ts
|
|
5
|
+
import {
|
|
6
|
+
existsSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
statSync
|
|
13
|
+
} from "fs";
|
|
14
|
+
import { dirname, relative, join } 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/rules.ts
|
|
133
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
134
|
+
import { basename } from "path";
|
|
135
|
+
function parseRules(rulesDir, packName) {
|
|
136
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
137
|
+
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
138
|
+
}
|
|
139
|
+
function parseRuleFile(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 ruleMatchesTarget(rule, targetId) {
|
|
151
|
+
const { targets } = rule.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
|
+
function getRootRules(rules) {
|
|
159
|
+
return rules.filter((r) => r.meta.root === true);
|
|
160
|
+
}
|
|
161
|
+
function getDetailRules(rules) {
|
|
162
|
+
return rules.filter((r) => r.meta.root !== true);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/features/commands.ts
|
|
166
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
167
|
+
import { basename as basename2 } from "path";
|
|
168
|
+
function parseCommands(commandsDir, packName) {
|
|
169
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
170
|
+
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
171
|
+
}
|
|
172
|
+
function parseCommandFile(filepath, packName) {
|
|
173
|
+
const raw = readFileSync3(filepath, "utf-8");
|
|
174
|
+
const { data, content } = parseFrontmatter(raw);
|
|
175
|
+
return {
|
|
176
|
+
name: basename2(filepath, ".md"),
|
|
177
|
+
sourcePath: filepath,
|
|
178
|
+
packName,
|
|
179
|
+
meta: data,
|
|
180
|
+
content
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function commandMatchesTarget(cmd, targetId) {
|
|
184
|
+
const { targets } = cmd.meta;
|
|
185
|
+
if (!targets || targets === "*")
|
|
186
|
+
return true;
|
|
187
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
188
|
+
return true;
|
|
189
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/features/agents.ts
|
|
193
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
194
|
+
import { basename as basename3 } from "path";
|
|
195
|
+
function parseAgents(agentsDir, packName) {
|
|
196
|
+
const files = listFiles(agentsDir, { extension: ".md" });
|
|
197
|
+
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
198
|
+
}
|
|
199
|
+
function parseAgentFile(filepath, packName) {
|
|
200
|
+
const raw = readFileSync4(filepath, "utf-8");
|
|
201
|
+
const { data, content } = parseFrontmatter(raw);
|
|
202
|
+
return {
|
|
203
|
+
name: data.name ?? basename3(filepath, ".md"),
|
|
204
|
+
sourcePath: filepath,
|
|
205
|
+
packName,
|
|
206
|
+
meta: data,
|
|
207
|
+
content
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function agentMatchesTarget(agent, targetId) {
|
|
211
|
+
const { targets } = agent.meta;
|
|
212
|
+
if (!targets || targets === "*")
|
|
213
|
+
return true;
|
|
214
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
215
|
+
return true;
|
|
216
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/features/skills.ts
|
|
220
|
+
import { readFileSync as readFileSync5, existsSync as existsSync2 } from "fs";
|
|
221
|
+
import { basename as basename4, join as join2 } from "path";
|
|
222
|
+
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
223
|
+
var SKILL_NAME_MAX_LENGTH = 64;
|
|
224
|
+
function parseSkills(skillsDir, packName) {
|
|
225
|
+
const dirs = listDirs(skillsDir);
|
|
226
|
+
const skills = [];
|
|
227
|
+
for (const dir of dirs) {
|
|
228
|
+
const skillMd = join2(dir, "SKILL.md");
|
|
229
|
+
if (existsSync2(skillMd)) {
|
|
230
|
+
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return skills;
|
|
234
|
+
}
|
|
235
|
+
function parseSkillFile(filepath, skillDir, packName) {
|
|
236
|
+
const raw = readFileSync5(filepath, "utf-8");
|
|
237
|
+
const { data, content } = parseFrontmatter(raw);
|
|
238
|
+
return {
|
|
239
|
+
name: data.name ?? basename4(skillDir),
|
|
240
|
+
sourcePath: filepath,
|
|
241
|
+
sourceDir: skillDir,
|
|
242
|
+
packName,
|
|
243
|
+
meta: data,
|
|
244
|
+
content
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function buildSkillFrontmatter(skill) {
|
|
248
|
+
return {
|
|
249
|
+
...skill.meta,
|
|
250
|
+
name: skill.name
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function serializeSkill(skill) {
|
|
254
|
+
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
255
|
+
}
|
|
256
|
+
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
257
|
+
const { data, content } = parseFrontmatter(source);
|
|
258
|
+
const normalized = {
|
|
259
|
+
...data,
|
|
260
|
+
name: skillName
|
|
261
|
+
};
|
|
262
|
+
let addedDescription = false;
|
|
263
|
+
const description = normalized.description;
|
|
264
|
+
if (typeof description !== "string" || description.trim().length === 0) {
|
|
265
|
+
normalized.description = `Imported skill: ${skillName}`;
|
|
266
|
+
addedDescription = true;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
content: serializeFrontmatter(normalized, content),
|
|
270
|
+
addedDescription
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function validateAgentSkillsFrontmatter(skill) {
|
|
274
|
+
const errors = [];
|
|
275
|
+
const dirName = basename4(skill.sourceDir);
|
|
276
|
+
const declaredName = skill.meta.name;
|
|
277
|
+
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
278
|
+
errors.push('Missing required frontmatter field "name".');
|
|
279
|
+
} else {
|
|
280
|
+
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
281
|
+
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
282
|
+
}
|
|
283
|
+
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
284
|
+
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
285
|
+
}
|
|
286
|
+
if (declaredName !== dirName) {
|
|
287
|
+
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const description = skill.meta.description;
|
|
291
|
+
if (typeof description !== "string" || description.trim().length === 0) {
|
|
292
|
+
errors.push('Missing required frontmatter field "description".');
|
|
293
|
+
}
|
|
294
|
+
const allowedTools = skill.meta["allowed-tools"];
|
|
295
|
+
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
296
|
+
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
297
|
+
}
|
|
298
|
+
return errors;
|
|
299
|
+
}
|
|
300
|
+
function skillMatchesTarget(skill, targetId) {
|
|
301
|
+
const { targets } = skill.meta;
|
|
302
|
+
if (!targets || targets === "*")
|
|
303
|
+
return true;
|
|
304
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
305
|
+
return true;
|
|
306
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/core/profile-resolver.ts
|
|
310
|
+
function resolveModels(merged, modelProfile, targetId) {
|
|
311
|
+
let defaultModel = merged.default;
|
|
312
|
+
let smallModel = merged.small;
|
|
313
|
+
let agents = { ...merged.agents };
|
|
314
|
+
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
315
|
+
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
316
|
+
if (resolvedProfile.default)
|
|
317
|
+
defaultModel = resolvedProfile.default;
|
|
318
|
+
if (resolvedProfile.small)
|
|
319
|
+
smallModel = resolvedProfile.small;
|
|
320
|
+
if (resolvedProfile.agents) {
|
|
321
|
+
agents = { ...agents, ...resolvedProfile.agents };
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (targetId) {
|
|
325
|
+
const targetOverride = merged.overrides?.[targetId];
|
|
326
|
+
if (targetOverride) {
|
|
327
|
+
if (targetOverride.default)
|
|
328
|
+
defaultModel = targetOverride.default;
|
|
329
|
+
if (targetOverride.small)
|
|
330
|
+
smallModel = targetOverride.small;
|
|
331
|
+
if (targetOverride.agents) {
|
|
332
|
+
agents = { ...agents, ...targetOverride.agents };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const providers = {};
|
|
337
|
+
if (merged.providers) {
|
|
338
|
+
for (const [name, config] of Object.entries(merged.providers)) {
|
|
339
|
+
providers[name] = {
|
|
340
|
+
...config.options ? { options: config.options } : {},
|
|
341
|
+
...config.models ? { models: config.models } : {}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const profileNames = Object.keys(merged.profiles ?? {});
|
|
346
|
+
const profiles = {};
|
|
347
|
+
if (merged.profiles) {
|
|
348
|
+
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
349
|
+
profiles[name] = {
|
|
350
|
+
description: profile.description,
|
|
351
|
+
default: profile.default,
|
|
352
|
+
small: profile.small
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
default: defaultModel,
|
|
358
|
+
small: smallModel,
|
|
359
|
+
agents,
|
|
360
|
+
providers,
|
|
361
|
+
routing: merged.routing ?? [],
|
|
362
|
+
profileNames,
|
|
363
|
+
activeProfile: modelProfile,
|
|
364
|
+
profiles
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
368
|
+
const fromModels = resolved.agents[agentName];
|
|
369
|
+
if (fromModels) {
|
|
370
|
+
return {
|
|
371
|
+
model: fromModels.model,
|
|
372
|
+
temperature: fromModels.temperature,
|
|
373
|
+
top_p: fromModels.top_p
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (frontmatterModel) {
|
|
377
|
+
return { model: frontmatterModel };
|
|
378
|
+
}
|
|
379
|
+
return {};
|
|
380
|
+
}
|
|
381
|
+
function resolveProfileInheritance(profileName, profiles) {
|
|
382
|
+
const visited = new Set;
|
|
383
|
+
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
384
|
+
}
|
|
385
|
+
var MAX_INHERITANCE_DEPTH = 10;
|
|
386
|
+
function resolveProfileChain(name, profiles, visited, depth) {
|
|
387
|
+
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
388
|
+
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
389
|
+
}
|
|
390
|
+
if (visited.has(name)) {
|
|
391
|
+
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" \u2192 ")}`);
|
|
392
|
+
}
|
|
393
|
+
const profile = profiles[name];
|
|
394
|
+
if (!profile) {
|
|
395
|
+
throw new Error(`Profile "${name}" not found`);
|
|
396
|
+
}
|
|
397
|
+
visited.add(name);
|
|
398
|
+
if (!profile.extends) {
|
|
399
|
+
return { ...profile };
|
|
400
|
+
}
|
|
401
|
+
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
402
|
+
return {
|
|
403
|
+
description: profile.description ?? parent.description,
|
|
404
|
+
default: profile.default ?? parent.default,
|
|
405
|
+
small: profile.small ?? parent.small,
|
|
406
|
+
agents: {
|
|
407
|
+
...parent.agents,
|
|
408
|
+
...profile.agents
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/targets/base-target.ts
|
|
414
|
+
class BaseTarget {
|
|
415
|
+
supportsFeature(feature) {
|
|
416
|
+
return this.supportedFeatures.includes(feature);
|
|
417
|
+
}
|
|
418
|
+
getEffectiveFeatures(enabledFeatures) {
|
|
419
|
+
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
420
|
+
}
|
|
421
|
+
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
422
|
+
return {
|
|
423
|
+
targetId: this.id,
|
|
424
|
+
filesWritten,
|
|
425
|
+
filesDeleted,
|
|
426
|
+
warnings
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/utils/model-guidance.ts
|
|
432
|
+
function generateModelGuidanceMarkdown(resolved) {
|
|
433
|
+
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0 && Object.keys(resolved.profiles).length === 0) {
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
const lines = [];
|
|
437
|
+
lines.push("# Model Configuration");
|
|
438
|
+
lines.push("");
|
|
439
|
+
lines.push("Use the following model preferences when working in this project.");
|
|
440
|
+
lines.push("");
|
|
441
|
+
if (resolved.default || resolved.small) {
|
|
442
|
+
lines.push("## Default Models");
|
|
443
|
+
lines.push("");
|
|
444
|
+
if (resolved.default) {
|
|
445
|
+
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
446
|
+
}
|
|
447
|
+
if (resolved.small) {
|
|
448
|
+
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
449
|
+
}
|
|
450
|
+
lines.push("");
|
|
451
|
+
}
|
|
452
|
+
const agentEntries = Object.entries(resolved.agents);
|
|
453
|
+
if (agentEntries.length > 0) {
|
|
454
|
+
lines.push("## Agent Model Assignments");
|
|
455
|
+
lines.push("");
|
|
456
|
+
lines.push("| Agent | Model | Temperature |");
|
|
457
|
+
lines.push("| --- | --- | --- |");
|
|
458
|
+
for (const [name, assignment] of agentEntries) {
|
|
459
|
+
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "\u2014";
|
|
460
|
+
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
461
|
+
}
|
|
462
|
+
lines.push("");
|
|
463
|
+
}
|
|
464
|
+
if (Object.keys(resolved.profiles).length > 0) {
|
|
465
|
+
lines.push("## Available Profiles");
|
|
466
|
+
lines.push("");
|
|
467
|
+
lines.push("| Profile | Description | Default Model |");
|
|
468
|
+
lines.push("| --- | --- | --- |");
|
|
469
|
+
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
470
|
+
lines.push(`| ${name} | ${profile.description ?? "\u2014"} | ${profile.default ?? "\u2014"} |`);
|
|
471
|
+
}
|
|
472
|
+
lines.push("");
|
|
473
|
+
}
|
|
474
|
+
if (resolved.activeProfile) {
|
|
475
|
+
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
476
|
+
lines.push("");
|
|
477
|
+
}
|
|
478
|
+
if (resolved.routing.length > 0) {
|
|
479
|
+
lines.push("## Task-Aware Routing");
|
|
480
|
+
lines.push("");
|
|
481
|
+
lines.push("Select the appropriate profile based on the task context:");
|
|
482
|
+
lines.push("");
|
|
483
|
+
lines.push("| Condition | Profile | Description |");
|
|
484
|
+
lines.push("| --- | --- | --- |");
|
|
485
|
+
for (const rule of resolved.routing) {
|
|
486
|
+
const conditions = Object.entries(rule.when).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
487
|
+
const desc = rule.description ?? "\u2014";
|
|
488
|
+
lines.push(`| ${conditions} | ${rule.use} | ${desc} |`);
|
|
489
|
+
}
|
|
490
|
+
lines.push("");
|
|
491
|
+
lines.push("### Condition Reference");
|
|
492
|
+
lines.push("");
|
|
493
|
+
lines.push("- **complexity**: low | medium | high | critical");
|
|
494
|
+
lines.push("- **urgency**: low | normal | high");
|
|
495
|
+
lines.push("- **budget**: minimal | standard | premium");
|
|
496
|
+
lines.push("- **contextWindowNeed**: small | medium | large | max");
|
|
497
|
+
lines.push("- **toolUseIntensity**: none | light | heavy");
|
|
498
|
+
lines.push("");
|
|
499
|
+
}
|
|
500
|
+
return lines.join(`
|
|
501
|
+
`);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/targets/mistral-vibe.ts
|
|
505
|
+
import { resolve, join as join3 } from "path";
|
|
506
|
+
var TARGET_ID = "mistralvibe";
|
|
507
|
+
|
|
508
|
+
class MistralVibeTarget extends BaseTarget {
|
|
509
|
+
id = TARGET_ID;
|
|
510
|
+
name = "Mistral Vibe";
|
|
511
|
+
supportedFeatures = [
|
|
512
|
+
"rules",
|
|
513
|
+
"commands",
|
|
514
|
+
"agents",
|
|
515
|
+
"skills",
|
|
516
|
+
"mcp",
|
|
517
|
+
"ignore",
|
|
518
|
+
"models"
|
|
519
|
+
];
|
|
520
|
+
generate(options) {
|
|
521
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
522
|
+
const root = resolve(projectRoot, baseDir);
|
|
523
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
524
|
+
const filesWritten = [];
|
|
525
|
+
const filesDeleted = [];
|
|
526
|
+
const warnings = [];
|
|
527
|
+
const vibeDir = resolve(root, ".vibe");
|
|
528
|
+
ensureDir(vibeDir);
|
|
529
|
+
if (effective.includes("rules")) {
|
|
530
|
+
const rulesDir = resolve(vibeDir, "rules");
|
|
531
|
+
if (deleteExisting) {
|
|
532
|
+
removeIfExists(rulesDir);
|
|
533
|
+
filesDeleted.push(rulesDir);
|
|
534
|
+
}
|
|
535
|
+
ensureDir(rulesDir);
|
|
536
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
|
|
537
|
+
for (const rule of rules) {
|
|
538
|
+
const filepath = join3(rulesDir, `${rule.name}.md`);
|
|
539
|
+
writeGeneratedFile(filepath, rule.content);
|
|
540
|
+
filesWritten.push(filepath);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (effective.includes("agents")) {
|
|
544
|
+
const agentsDir = resolve(vibeDir, "agents");
|
|
545
|
+
if (deleteExisting) {
|
|
546
|
+
removeIfExists(agentsDir);
|
|
547
|
+
filesDeleted.push(agentsDir);
|
|
548
|
+
}
|
|
549
|
+
ensureDir(agentsDir);
|
|
550
|
+
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
|
|
551
|
+
for (const agent of agents) {
|
|
552
|
+
const filepath = join3(agentsDir, `${agent.name}.md`);
|
|
553
|
+
writeGeneratedFile(filepath, agent.content);
|
|
554
|
+
filesWritten.push(filepath);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (effective.includes("skills")) {
|
|
558
|
+
const skillsDir = resolve(vibeDir, "skills");
|
|
559
|
+
if (deleteExisting) {
|
|
560
|
+
removeIfExists(skillsDir);
|
|
561
|
+
filesDeleted.push(skillsDir);
|
|
562
|
+
}
|
|
563
|
+
ensureDir(skillsDir);
|
|
564
|
+
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
|
|
565
|
+
for (const skill of skills) {
|
|
566
|
+
const skillSubDir = join3(skillsDir, skill.name);
|
|
567
|
+
ensureDir(skillSubDir);
|
|
568
|
+
const filepath = join3(skillSubDir, "SKILL.md");
|
|
569
|
+
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
570
|
+
filesWritten.push(filepath);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (effective.includes("commands")) {
|
|
574
|
+
const commandsDir = resolve(vibeDir, "commands");
|
|
575
|
+
if (deleteExisting) {
|
|
576
|
+
removeIfExists(commandsDir);
|
|
577
|
+
filesDeleted.push(commandsDir);
|
|
578
|
+
}
|
|
579
|
+
ensureDir(commandsDir);
|
|
580
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
|
|
581
|
+
for (const command of commands) {
|
|
582
|
+
const filepath = join3(commandsDir, `${command.name}.md`);
|
|
583
|
+
writeGeneratedFile(filepath, command.content);
|
|
584
|
+
filesWritten.push(filepath);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
let hasMcpConfig = false;
|
|
588
|
+
if (effective.includes("mcp")) {
|
|
589
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
590
|
+
if (mcpEntries.length > 0) {
|
|
591
|
+
const filepath = resolve(vibeDir, "mcp.json");
|
|
592
|
+
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
593
|
+
header: false
|
|
594
|
+
});
|
|
595
|
+
filesWritten.push(filepath);
|
|
596
|
+
hasMcpConfig = true;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (effective.includes("ignore") && features.ignorePatterns.length > 0) {
|
|
600
|
+
const filepath = resolve(root, ".vibeignore");
|
|
601
|
+
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
602
|
+
`) + `
|
|
603
|
+
`);
|
|
604
|
+
filesWritten.push(filepath);
|
|
605
|
+
}
|
|
606
|
+
let defaultModel;
|
|
607
|
+
let smallModel;
|
|
608
|
+
if (effective.includes("models") && features.models) {
|
|
609
|
+
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID);
|
|
610
|
+
defaultModel = resolved.default;
|
|
611
|
+
smallModel = resolved.small;
|
|
612
|
+
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
613
|
+
if (guidance) {
|
|
614
|
+
const filepath = join3(vibeDir, "model-config.md");
|
|
615
|
+
writeGeneratedFile(filepath, guidance);
|
|
616
|
+
filesWritten.push(filepath);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const vibeConfig = buildVibeConfigToml({
|
|
620
|
+
hasMcpConfig,
|
|
621
|
+
defaultModel,
|
|
622
|
+
smallModel,
|
|
623
|
+
profile: options.modelProfile
|
|
624
|
+
});
|
|
625
|
+
if (vibeConfig.length > 0) {
|
|
626
|
+
const filepath = resolve(vibeDir, "config.toml");
|
|
627
|
+
writeGeneratedFile(filepath, vibeConfig);
|
|
628
|
+
filesWritten.push(filepath);
|
|
629
|
+
}
|
|
630
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function buildVibeConfigToml(options) {
|
|
634
|
+
const lines = [];
|
|
635
|
+
if (options.defaultModel || options.smallModel || options.profile) {
|
|
636
|
+
lines.push("[models]");
|
|
637
|
+
if (options.defaultModel) {
|
|
638
|
+
lines.push(`default = "${escapeTomlString(options.defaultModel)}"`);
|
|
639
|
+
}
|
|
640
|
+
if (options.smallModel) {
|
|
641
|
+
lines.push(`small = "${escapeTomlString(options.smallModel)}"`);
|
|
642
|
+
}
|
|
643
|
+
if (options.profile) {
|
|
644
|
+
lines.push(`profile = "${escapeTomlString(options.profile)}"`);
|
|
645
|
+
}
|
|
646
|
+
lines.push("");
|
|
647
|
+
}
|
|
648
|
+
if (options.hasMcpConfig) {
|
|
649
|
+
lines.push("[mcp]");
|
|
650
|
+
lines.push('config_path = ".vibe/mcp.json"');
|
|
651
|
+
lines.push("");
|
|
652
|
+
}
|
|
653
|
+
return lines.join(`
|
|
654
|
+
`).trim();
|
|
655
|
+
}
|
|
656
|
+
function escapeTomlString(value) {
|
|
657
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
658
|
+
}
|
|
659
|
+
export {
|
|
660
|
+
MistralVibeTarget
|
|
661
|
+
};
|