agentpacks 1.7.13 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
package/dist/targets/opencode.js
CHANGED
|
@@ -1,731 +1,22 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
existsSync,
|
|
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/agents.ts
|
|
133
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
134
|
-
import { basename } from "path";
|
|
135
|
-
function parseAgents(agentsDir, packName) {
|
|
136
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
137
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
138
|
-
}
|
|
139
|
-
function parseAgentFile(filepath, packName) {
|
|
140
|
-
const raw = readFileSync2(filepath, "utf-8");
|
|
141
|
-
const { data, content } = parseFrontmatter(raw);
|
|
142
|
-
return {
|
|
143
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
144
|
-
sourcePath: filepath,
|
|
145
|
-
packName,
|
|
146
|
-
meta: data,
|
|
147
|
-
content
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function agentMatchesTarget(agent, targetId) {
|
|
151
|
-
const { targets } = agent.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/commands.ts
|
|
160
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
161
|
-
import { basename as basename2 } from "path";
|
|
162
|
-
function parseCommands(commandsDir, packName) {
|
|
163
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
164
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
165
|
-
}
|
|
166
|
-
function parseCommandFile(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 commandMatchesTarget(cmd, targetId) {
|
|
178
|
-
const { targets } = cmd.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
|
-
|
|
186
|
-
// src/features/hooks.ts
|
|
187
|
-
import { join as join2 } from "path";
|
|
188
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
189
|
-
function parseHooks(packDir, packName) {
|
|
190
|
-
const hooksPath = join2(packDir, "hooks", "hooks.json");
|
|
191
|
-
const raw = readJsonOrNull(hooksPath);
|
|
192
|
-
if (!raw)
|
|
193
|
-
return null;
|
|
194
|
-
const shared = raw.hooks ?? {};
|
|
195
|
-
const targetOverrides = {};
|
|
196
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
197
|
-
const override = raw[key];
|
|
198
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
199
|
-
targetOverrides[key] = override.hooks;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
packName,
|
|
204
|
-
sourcePath: hooksPath,
|
|
205
|
-
version: raw.version,
|
|
206
|
-
shared,
|
|
207
|
-
targetOverrides
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
211
|
-
const merged = {};
|
|
212
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
213
|
-
merged[event] = [...entries];
|
|
214
|
-
}
|
|
215
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
216
|
-
if (overrides) {
|
|
217
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
218
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return merged;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/features/rules.ts
|
|
225
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
226
|
-
import { basename as basename3 } from "path";
|
|
227
|
-
function parseRules(rulesDir, packName) {
|
|
228
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
229
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
230
|
-
}
|
|
231
|
-
function parseRuleFile(filepath, packName) {
|
|
232
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
233
|
-
const { data, content } = parseFrontmatter(raw);
|
|
234
|
-
return {
|
|
235
|
-
name: basename3(filepath, ".md"),
|
|
236
|
-
sourcePath: filepath,
|
|
237
|
-
packName,
|
|
238
|
-
meta: data,
|
|
239
|
-
content
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
243
|
-
const { targets } = rule.meta;
|
|
244
|
-
if (!targets || targets === "*")
|
|
245
|
-
return true;
|
|
246
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
247
|
-
return true;
|
|
248
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
249
|
-
}
|
|
250
|
-
function getRootRules(rules) {
|
|
251
|
-
return rules.filter((r) => r.meta.root === true);
|
|
252
|
-
}
|
|
253
|
-
function getDetailRules(rules) {
|
|
254
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// src/features/skills.ts
|
|
258
|
-
import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
259
|
-
import { basename as basename4, join as join3 } from "path";
|
|
260
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
261
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
262
|
-
function parseSkills(skillsDir, packName) {
|
|
263
|
-
const dirs = listDirs(skillsDir);
|
|
264
|
-
const skills = [];
|
|
265
|
-
for (const dir of dirs) {
|
|
266
|
-
const skillMd = join3(dir, "SKILL.md");
|
|
267
|
-
if (existsSync2(skillMd)) {
|
|
268
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return skills;
|
|
272
|
-
}
|
|
273
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
274
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
275
|
-
const { data, content } = parseFrontmatter(raw);
|
|
276
|
-
return {
|
|
277
|
-
name: data.name ?? basename4(skillDir),
|
|
278
|
-
sourcePath: filepath,
|
|
279
|
-
sourceDir: skillDir,
|
|
280
|
-
packName,
|
|
281
|
-
meta: data,
|
|
282
|
-
content
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function buildSkillFrontmatter(skill) {
|
|
286
|
-
return {
|
|
287
|
-
...skill.meta,
|
|
288
|
-
name: skill.name
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function serializeSkill(skill) {
|
|
292
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
293
|
-
}
|
|
294
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
295
|
-
const { data, content } = parseFrontmatter(source);
|
|
296
|
-
const normalized = {
|
|
297
|
-
...data,
|
|
298
|
-
name: skillName
|
|
299
|
-
};
|
|
300
|
-
let addedDescription = false;
|
|
301
|
-
const description = normalized.description;
|
|
302
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
303
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
304
|
-
addedDescription = true;
|
|
305
|
-
}
|
|
306
|
-
return {
|
|
307
|
-
content: serializeFrontmatter(normalized, content),
|
|
308
|
-
addedDescription
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
312
|
-
const errors = [];
|
|
313
|
-
const dirName = basename4(skill.sourceDir);
|
|
314
|
-
const declaredName = skill.meta.name;
|
|
315
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
316
|
-
errors.push('Missing required frontmatter field "name".');
|
|
317
|
-
} else {
|
|
318
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
319
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
320
|
-
}
|
|
321
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
322
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
323
|
-
}
|
|
324
|
-
if (declaredName !== dirName) {
|
|
325
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
const description = skill.meta.description;
|
|
329
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
330
|
-
errors.push('Missing required frontmatter field "description".');
|
|
331
|
-
}
|
|
332
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
333
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
334
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
335
|
-
}
|
|
336
|
-
return errors;
|
|
337
|
-
}
|
|
338
|
-
function skillMatchesTarget(skill, targetId) {
|
|
339
|
-
const { targets } = skill.meta;
|
|
340
|
-
if (!targets || targets === "*")
|
|
341
|
-
return true;
|
|
342
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
343
|
-
return true;
|
|
344
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/core/profile-resolver.ts
|
|
348
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
349
|
-
let defaultModel = merged.default;
|
|
350
|
-
let smallModel = merged.small;
|
|
351
|
-
let agents = { ...merged.agents };
|
|
352
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
353
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
354
|
-
if (resolvedProfile.default)
|
|
355
|
-
defaultModel = resolvedProfile.default;
|
|
356
|
-
if (resolvedProfile.small)
|
|
357
|
-
smallModel = resolvedProfile.small;
|
|
358
|
-
if (resolvedProfile.agents) {
|
|
359
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (targetId) {
|
|
363
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
364
|
-
if (targetOverride) {
|
|
365
|
-
if (targetOverride.default)
|
|
366
|
-
defaultModel = targetOverride.default;
|
|
367
|
-
if (targetOverride.small)
|
|
368
|
-
smallModel = targetOverride.small;
|
|
369
|
-
if (targetOverride.agents) {
|
|
370
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
const providers = {};
|
|
375
|
-
if (merged.providers) {
|
|
376
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
377
|
-
providers[name] = {
|
|
378
|
-
...config.options ? { options: config.options } : {},
|
|
379
|
-
...config.models ? { models: config.models } : {}
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
384
|
-
const profiles = {};
|
|
385
|
-
if (merged.profiles) {
|
|
386
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
387
|
-
profiles[name] = {
|
|
388
|
-
description: profile.description,
|
|
389
|
-
default: profile.default,
|
|
390
|
-
small: profile.small
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
default: defaultModel,
|
|
396
|
-
small: smallModel,
|
|
397
|
-
agents,
|
|
398
|
-
providers,
|
|
399
|
-
routing: merged.routing ?? [],
|
|
400
|
-
profileNames,
|
|
401
|
-
activeProfile: modelProfile,
|
|
402
|
-
profiles
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
406
|
-
const fromModels = resolved.agents[agentName];
|
|
407
|
-
if (fromModels) {
|
|
408
|
-
return {
|
|
409
|
-
model: fromModels.model,
|
|
410
|
-
temperature: fromModels.temperature,
|
|
411
|
-
top_p: fromModels.top_p
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if (frontmatterModel) {
|
|
415
|
-
return { model: frontmatterModel };
|
|
416
|
-
}
|
|
417
|
-
return {};
|
|
418
|
-
}
|
|
419
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
420
|
-
const visited = new Set;
|
|
421
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
422
|
-
}
|
|
423
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
424
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
425
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
426
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
427
|
-
}
|
|
428
|
-
if (visited.has(name)) {
|
|
429
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" \u2192 ")}`);
|
|
430
|
-
}
|
|
431
|
-
const profile = profiles[name];
|
|
432
|
-
if (!profile) {
|
|
433
|
-
throw new Error(`Profile "${name}" not found`);
|
|
434
|
-
}
|
|
435
|
-
visited.add(name);
|
|
436
|
-
if (!profile.extends) {
|
|
437
|
-
return { ...profile };
|
|
438
|
-
}
|
|
439
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
440
|
-
return {
|
|
441
|
-
description: profile.description ?? parent.description,
|
|
442
|
-
default: profile.default ?? parent.default,
|
|
443
|
-
small: profile.small ?? parent.small,
|
|
444
|
-
agents: {
|
|
445
|
-
...parent.agents,
|
|
446
|
-
...profile.agents
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// src/targets/base-target.ts
|
|
452
|
-
class BaseTarget {
|
|
453
|
-
supportsFeature(feature) {
|
|
454
|
-
return this.supportedFeatures.includes(feature);
|
|
455
|
-
}
|
|
456
|
-
getEffectiveFeatures(enabledFeatures) {
|
|
457
|
-
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
458
|
-
}
|
|
459
|
-
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
460
|
-
return {
|
|
461
|
-
targetId: this.id,
|
|
462
|
-
filesWritten,
|
|
463
|
-
filesDeleted,
|
|
464
|
-
warnings
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/utils/markdown.ts
|
|
470
|
-
function stripGeneratedHeader(content) {
|
|
471
|
-
return content.replace(/^<!-- Generated by agentpacks.*-->\n/, "").replace(/^\/\/ Generated by agentpacks.*\n/, "");
|
|
472
|
-
}
|
|
473
|
-
function packNameToIdentifier(packName) {
|
|
474
|
-
return packName.split(/[-_.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
475
|
-
}
|
|
476
|
-
function extractFirstHeading(content) {
|
|
477
|
-
const match = content.match(/^#{1,6}\s+(.+)$/m);
|
|
478
|
-
return match?.[1]?.trim() ?? null;
|
|
479
|
-
}
|
|
480
|
-
function combineMarkdown(sections, separator = `
|
|
2
|
+
var Dq=import.meta.require;import{existsSync as F,mkdirSync as $q,readdirSync as D,readFileSync as Bq,rmSync as Vq,statSync as k,writeFileSync as Yq}from"fs";import{dirname as Kq,join as u,relative as Xq}from"path";var v="<!-- Generated by agentpacks. DO NOT EDIT. -->",h="// Generated by agentpacks. DO NOT EDIT.",g="// Generated by agentpacks. DO NOT EDIT.";function G(q,Q,U={}){let{header:Z=!0,type:$}=U,B=$??Jq(q);w(Kq(q));let J=Q;if(Z){let Y=zq(B);if(Y)J=`${Y}
|
|
3
|
+
${Q}`}Yq(q,J,"utf-8")}function c(q,Q,U={}){let Z=JSON.stringify(Q,null,2);G(q,Z+`
|
|
4
|
+
`,{...U,type:"json"})}function m(q){if(!F(q))return null;return Bq(q,"utf-8")}function p(q){let Q=m(q);if(Q===null)return null;return JSON.parse(Q)}function w(q){if(!F(q))$q(q,{recursive:!0})}function M(q){if(F(q))Vq(q,{recursive:!0,force:!0})}function A(q,Q={}){let{extension:U,recursive:Z=!1}=Q;if(!F(q))return[];let $=[],B=D(q);for(let J of B){let Y=u(q,J),W=k(Y);if(W.isDirectory()&&Z)$.push(...A(Y,Q));else if(W.isFile()){if(!U||J.endsWith(U))$.push(Y)}}return $}function f(q){if(!F(q))return[];return D(q).map((Q)=>u(q,Q)).filter((Q)=>k(Q).isDirectory())}function hq(q,Q){return Xq(q,Q)}function gq(q){let Q=m(q);if(!Q)return!1;return Q.startsWith(v)||Q.startsWith(h)||Q.startsWith(g)}function Jq(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 zq(q){switch(q){case"md":return v;case"json":return h;case"js":case"ts":return g;default:return null}}import d from"gray-matter";function O(q){let{data:Q,content:U}=d(q);return{data:Q,content:U.trim(),raw:q}}function T(q,Q){let U=Object.fromEntries(Object.entries(q).filter(([,Z])=>Z!==void 0));if(Object.keys(U).length===0)return Q;return d.stringify(Q,U)}import{readFileSync as Lq}from"fs";import{basename as Wq}from"path";function sq(q,Q){return A(q,{extension:".md"}).map((Z)=>bq(Z,Q))}function bq(q,Q){let U=Lq(q,"utf-8"),{data:Z,content:$}=O(U);return{name:Z.name??Wq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function n(q,Q){let{targets:U}=q.meta;if(!U||U==="*")return!0;if(Array.isArray(U)&&U.includes("*"))return!0;return Array.isArray(U)&&U.includes(Q)}import{readFileSync as xq}from"fs";import{basename as Hq}from"path";function eq(q,Q){return A(q,{extension:".md"}).map((Z)=>Oq(Z,Q))}function Oq(q,Q){let U=xq(q,"utf-8"),{data:Z,content:$}=O(U);return{name:Hq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function o(q,Q){let{targets:U}=q.meta;if(!U||U==="*")return!0;if(Array.isArray(U)&&U.includes("*"))return!0;return Array.isArray(U)&&U.includes(Q)}import{join as Cq}from"path";var Gq=["cursor","claudecode","codexcli","opencode"];function ZQ(q,Q){let U=Cq(q,"hooks","hooks.json"),Z=p(U);if(!Z)return null;let $=Z.hooks??{},B={};for(let J of Gq){let Y=Z[J];if(Y&&typeof Y==="object"&&"hooks"in Y&&Y.hooks)B[J]=Y.hooks}return{packName:Q,sourcePath:U,version:Z.version,shared:$,targetOverrides:B}}function s(q,Q){let U={};for(let[$,B]of Object.entries(q.shared))U[$]=[...B];let Z=q.targetOverrides[Q];if(Z)for(let[$,B]of Object.entries(Z))U[$]=[...U[$]??[],...B];return U}import{readFileSync as wq}from"fs";import{basename as Rq}from"path";function XQ(q,Q){return A(q,{extension:".md"}).map((Z)=>jq(Z,Q))}function jq(q,Q){let U=wq(q,"utf-8"),{data:Z,content:$}=O(U);return{name:Rq(q,".md"),sourcePath:q,packName:Q,meta:Z,content:$}}function l(q,Q){let{targets:U}=q.meta;if(!U||U==="*")return!0;if(Array.isArray(U)&&U.includes("*"))return!0;return Array.isArray(U)&&U.includes(Q)}function JQ(q){return q.filter((Q)=>Q.meta.root===!0)}function a(q){return q.filter((Q)=>Q.meta.root!==!0)}import{existsSync as Aq,readFileSync as _q}from"fs";import{basename as r,join as Iq}from"path";var Sq=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,i=64;function HQ(q,Q){let U=f(q),Z=[];for(let $ of U){let B=Iq($,"SKILL.md");if(Aq(B))Z.push(Fq(B,$,Q))}return Z}function Fq(q,Q,U){let Z=_q(q,"utf-8"),{data:$,content:B}=O(Z);return{name:$.name??r(Q),sourcePath:q,sourceDir:Q,packName:U,meta:$,content:B}}function Mq(q){return{...q.meta,name:q.name}}function t(q){return T(Mq(q),q.content)}function OQ(q,Q){let{data:U,content:Z}=O(q),$={...U,name:Q},B=!1,J=$.description;if(typeof J!=="string"||J.trim().length===0)$.description=`Imported skill: ${Q}`,B=!0;return{content:T($,Z),addedDescription:B}}function CQ(q){let Q=[],U=r(q.sourceDir),Z=q.meta.name;if(typeof Z!=="string"||Z.trim().length===0)Q.push('Missing required frontmatter field "name".');else{if(Z.length>i)Q.push(`Invalid "name": must be at most ${i} characters.`);if(!Sq.test(Z))Q.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Z!==U)Q.push(`Invalid "name": must match containing directory "${U}".`)}let $=q.meta.description;if(typeof $!=="string"||$.trim().length===0)Q.push('Missing required frontmatter field "description".');let B=q.meta["allowed-tools"];if(B!==void 0&&(!Array.isArray(B)||B.some((J)=>typeof J!=="string"||J.length===0)))Q.push('Invalid "allowed-tools": expected an array of non-empty strings.');return Q}function e(q,Q){let{targets:U}=q.meta;if(!U||U==="*")return!0;if(Array.isArray(U)&&U.includes("*"))return!0;return Array.isArray(U)&&U.includes(Q)}function P(q,Q,U){let{default:Z,small:$}=q,B={...q.agents};if(Q&&q.profiles?.[Q]){let X=Tq(Q,q.profiles);if(X.default)Z=X.default;if(X.small)$=X.small;if(X.agents)B={...B,...X.agents}}if(U){let X=q.overrides?.[U];if(X){if(X.default)Z=X.default;if(X.small)$=X.small;if(X.agents)B={...B,...X.agents}}}let J={};if(q.providers)for(let[X,H]of Object.entries(q.providers))J[X]={...H.options?{options:H.options}:{},...H.models?{models:H.models}:{}};let Y=Object.keys(q.profiles??{}),W={};if(q.profiles)for(let[X,H]of Object.entries(q.profiles))W[X]={description:H.description,default:H.default,small:H.small};return{default:Z,small:$,agents:B,providers:J,routing:q.routing??[],profileNames:Y,activeProfile:Q,profiles:W}}function wQ(q,Q,U){let Z=q.agents[Q];if(Z)return{model:Z.model,temperature:Z.temperature,top_p:Z.top_p};if(U)return{model:U};return{}}function Tq(q,Q){return Qq(q,Q,new Set,0)}var qq=10;function Qq(q,Q,U,Z){if(Z>qq)throw Error(`Profile inheritance too deep (max ${qq}): ${q}`);if(U.has(q))throw Error(`Circular profile inheritance detected: ${[...U,q].join(" \u2192 ")}`);let $=Q[q];if(!$)throw Error(`Profile "${q}" not found`);if(U.add(q),!$.extends)return{...$};let B=Qq($.extends,Q,U,Z+1);return{description:$.description??B.description,default:$.default??B.default,small:$.small??B.small,agents:{...B.agents,...$.agents}}}class y{supportsFeature(q){return this.supportedFeatures.includes(q)}getEffectiveFeatures(q){return q.filter((Q)=>this.supportsFeature(Q))}createResult(q=[],Q=[],U=[]){return{targetId:this.id,filesWritten:q,filesDeleted:Q,warnings:U}}}function AQ(q){return q.replace(/^<!-- Generated by agentpacks.*-->\n/,"").replace(/^\/\/ Generated by agentpacks.*\n/,"")}function Uq(q){return q.split(/[-_.]/).filter((Q)=>Q.length>0).map((Q)=>Q.charAt(0).toUpperCase()+Q.slice(1)).join("")}function _Q(q){return q.match(/^#{1,6}\s+(.+)$/m)?.[1]?.trim()??null}function IQ(q,Q=`
|
|
481
5
|
|
|
482
6
|
---
|
|
483
7
|
|
|
484
|
-
`) {
|
|
485
|
-
return sections.filter(Boolean).join(separator);
|
|
486
|
-
}
|
|
487
|
-
function wrapSection(heading, content, level = 2) {
|
|
488
|
-
const prefix = "#".repeat(level);
|
|
489
|
-
return `${prefix} ${heading}
|
|
8
|
+
`){return q.filter(Boolean).join(Q)}function SQ(q,Q,U=2){return`${"#".repeat(U)} ${q}
|
|
490
9
|
|
|
491
|
-
${content}
|
|
492
|
-
}
|
|
10
|
+
${Q}`}import{join as _,resolve as R}from"path";var j="opencode";class Pq extends y{id=j;name="OpenCode";supportedFeatures=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"];generate(q){let{projectRoot:Q,baseDir:U,features:Z,enabledFeatures:$,deleteExisting:B}=q,J=R(Q,U),Y=this.getEffectiveFeatures($),W=[],X=[],H=[],S=R(J,".opencode");if(Y.includes("agents")){let z=R(S,"agent");if(B)M(z),X.push(z);w(z);let K=Z.models?P(Z.models,q.modelProfile,j):null,V=Z.agents.filter((L)=>n(L,j));for(let L of V){let b=_(z,`${L.name}.md`),C={},x=L.meta.opencode??{},I=K?.agents[L.name],N=I?.model??x.model,E=I?.temperature??x.temperature;if(N)C.model=N;if(E!==void 0)C.temperature=E;if(x.mode)C.mode=x.mode;if(x.top_p!==void 0)C.top_p=x.top_p;let Zq=Object.keys(C).length>0?T(C,L.content):L.content;G(b,Zq),W.push(b)}}if(Y.includes("skills")){let z=R(S,"skill");if(B)M(z),X.push(z);w(z);let K=Z.skills.filter((V)=>e(V,j));for(let V of K){let L=_(z,V.name);w(L);let b=_(L,"SKILL.md");G(b,t(V)),W.push(b)}}if(Y.includes("commands")){let z=R(S,"command");if(B)M(z),X.push(z);w(z);let K=Z.commands.filter((V)=>o(V,j));for(let V of K){let L=_(z,`${V.name}.md`);G(L,V.content),W.push(L)}}if(Y.includes("hooks")||Y.includes("plugins")){let z=R(S,"plugins");if(w(z),Y.includes("hooks"))for(let K of Z.hooks){let V=s(K,j);if(Object.keys(V).length>0){let L=_(z,`agentpacks-${K.packName}.ts`),b=Nq(K.packName,V);G(L,b,{type:"ts"}),W.push(L)}}if(Y.includes("plugins"))for(let K of Z.plugins){let V=_(z,`agentpacks-${K.packName}-${K.name}.${K.extension}`);G(V,K.content,{type:K.extension}),W.push(V)}}if(Y.includes("mcp")||Y.includes("models")){let z=R(J,"opencode.json"),K={$schema:"https://opencode.ai/config.json"};if(Y.includes("mcp")){if(Object.entries(Z.mcpServers).length>0)K.mcp=yq(Z.mcpServers)}if(Y.includes("models")&&Z.models){let V=P(Z.models,q.modelProfile,j);if(V.default)K.model=V.default;if(V.small)K.small_model=V.small;if(Object.keys(V.providers).length>0)K.provider=V.providers;let L=Object.entries(V.agents);if(L.length>0){let b={};for(let[C,x]of L){let I={model:x.model};if(x.temperature!==void 0)I.temperature=x.temperature;if(x.top_p!==void 0)I.top_p=x.top_p;b[C]=I}K.agent=b}}if(Object.keys(K).length>1)c(z,K,{header:!1}),W.push(z)}if(Y.includes("rules")){let z=Z.rules.filter((V)=>l(V,j)),K=a(z);if(K.length>0){let V=R(S,"memories");if(B)M(V),X.push(V);w(V);for(let L of K){let b=_(V,`${L.name}.md`);G(b,L.content),W.push(b)}}}return this.createResult(W,X,H)}}function yq(q){let Q={};for(let[U,Z]of Object.entries(q))if(Z.url)Q[U]={type:"remote",url:Z.url,enabled:!0,...Z.headers&&Object.keys(Z.headers).length>0?{headers:Z.headers}:{}};else if(Z.command){let $=Z.args?[Z.command,...Z.args]:[Z.command];Q[U]={type:"local",command:$,enabled:!0,...Z.env&&Object.keys(Z.env).length>0?{environment:Z.env}:{}}}return Q}function Nq(q,Q){let U=Uq(q),Z=Eq(Q),$=Object.entries(Z).map(([B,J])=>{let Y=J.map((W)=>{return` ${W.matcher?`if (!/(?:${W.matcher})/.test(String(input?.tool ?? ""))) return;
|
|
11
|
+
`:""}await $\`${W.command}\`;`}).join(`
|
|
12
|
+
`);return` "${B}": async (input, output) => {
|
|
13
|
+
${Y}
|
|
14
|
+
},`}).join(`
|
|
15
|
+
`);return`import type { Plugin } from "@opencode-ai/plugin";
|
|
493
16
|
|
|
494
|
-
|
|
495
|
-
import { join as join4, resolve } from "path";
|
|
496
|
-
var TARGET_ID = "opencode";
|
|
497
|
-
|
|
498
|
-
class OpenCodeTarget extends BaseTarget {
|
|
499
|
-
id = TARGET_ID;
|
|
500
|
-
name = "OpenCode";
|
|
501
|
-
supportedFeatures = [
|
|
502
|
-
"rules",
|
|
503
|
-
"commands",
|
|
504
|
-
"agents",
|
|
505
|
-
"skills",
|
|
506
|
-
"hooks",
|
|
507
|
-
"plugins",
|
|
508
|
-
"mcp",
|
|
509
|
-
"ignore",
|
|
510
|
-
"models"
|
|
511
|
-
];
|
|
512
|
-
generate(options) {
|
|
513
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
514
|
-
const root = resolve(projectRoot, baseDir);
|
|
515
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
516
|
-
const filesWritten = [];
|
|
517
|
-
const filesDeleted = [];
|
|
518
|
-
const warnings = [];
|
|
519
|
-
const opencodeDir = resolve(root, ".opencode");
|
|
520
|
-
if (effective.includes("agents")) {
|
|
521
|
-
const agentDir = resolve(opencodeDir, "agent");
|
|
522
|
-
if (deleteExisting) {
|
|
523
|
-
removeIfExists(agentDir);
|
|
524
|
-
filesDeleted.push(agentDir);
|
|
525
|
-
}
|
|
526
|
-
ensureDir(agentDir);
|
|
527
|
-
const resolvedModels = features.models ? resolveModels(features.models, options.modelProfile, TARGET_ID) : null;
|
|
528
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
|
|
529
|
-
for (const agent of agents) {
|
|
530
|
-
const filepath = join4(agentDir, `${agent.name}.md`);
|
|
531
|
-
const fm = {};
|
|
532
|
-
const oc = agent.meta.opencode ?? {};
|
|
533
|
-
const modelsAgent = resolvedModels?.agents[agent.name];
|
|
534
|
-
const agentModel = modelsAgent?.model ?? oc.model;
|
|
535
|
-
const agentTemp = modelsAgent?.temperature ?? oc.temperature;
|
|
536
|
-
if (agentModel)
|
|
537
|
-
fm.model = agentModel;
|
|
538
|
-
if (agentTemp !== undefined)
|
|
539
|
-
fm.temperature = agentTemp;
|
|
540
|
-
if (oc.mode)
|
|
541
|
-
fm.mode = oc.mode;
|
|
542
|
-
if (oc.top_p !== undefined)
|
|
543
|
-
fm.top_p = oc.top_p;
|
|
544
|
-
const content = Object.keys(fm).length > 0 ? serializeFrontmatter(fm, agent.content) : agent.content;
|
|
545
|
-
writeGeneratedFile(filepath, content);
|
|
546
|
-
filesWritten.push(filepath);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (effective.includes("skills")) {
|
|
550
|
-
const skillDir = resolve(opencodeDir, "skill");
|
|
551
|
-
if (deleteExisting) {
|
|
552
|
-
removeIfExists(skillDir);
|
|
553
|
-
filesDeleted.push(skillDir);
|
|
554
|
-
}
|
|
555
|
-
ensureDir(skillDir);
|
|
556
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
|
|
557
|
-
for (const skill of skills) {
|
|
558
|
-
const skillSubDir = join4(skillDir, skill.name);
|
|
559
|
-
ensureDir(skillSubDir);
|
|
560
|
-
const filepath = join4(skillSubDir, "SKILL.md");
|
|
561
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
562
|
-
filesWritten.push(filepath);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
if (effective.includes("commands")) {
|
|
566
|
-
const cmdDir = resolve(opencodeDir, "command");
|
|
567
|
-
if (deleteExisting) {
|
|
568
|
-
removeIfExists(cmdDir);
|
|
569
|
-
filesDeleted.push(cmdDir);
|
|
570
|
-
}
|
|
571
|
-
ensureDir(cmdDir);
|
|
572
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
|
|
573
|
-
for (const cmd of commands) {
|
|
574
|
-
const filepath = join4(cmdDir, `${cmd.name}.md`);
|
|
575
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
576
|
-
filesWritten.push(filepath);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
if (effective.includes("hooks") || effective.includes("plugins")) {
|
|
580
|
-
const pluginsDir = resolve(opencodeDir, "plugins");
|
|
581
|
-
ensureDir(pluginsDir);
|
|
582
|
-
if (effective.includes("hooks")) {
|
|
583
|
-
for (const hookSet of features.hooks) {
|
|
584
|
-
const events = resolveHooksForTarget(hookSet, TARGET_ID);
|
|
585
|
-
if (Object.keys(events).length > 0) {
|
|
586
|
-
const filepath = join4(pluginsDir, `agentpacks-${hookSet.packName}.ts`);
|
|
587
|
-
const content = generateOpenCodeHookPlugin(hookSet.packName, events);
|
|
588
|
-
writeGeneratedFile(filepath, content, { type: "ts" });
|
|
589
|
-
filesWritten.push(filepath);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
if (effective.includes("plugins")) {
|
|
594
|
-
for (const plugin of features.plugins) {
|
|
595
|
-
const filepath = join4(pluginsDir, `agentpacks-${plugin.packName}-${plugin.name}.${plugin.extension}`);
|
|
596
|
-
writeGeneratedFile(filepath, plugin.content, {
|
|
597
|
-
type: plugin.extension
|
|
598
|
-
});
|
|
599
|
-
filesWritten.push(filepath);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
if (effective.includes("mcp") || effective.includes("models")) {
|
|
604
|
-
const filepath = resolve(root, "opencode.json");
|
|
605
|
-
const opencodeConfig = {
|
|
606
|
-
$schema: "https://opencode.ai/config.json"
|
|
607
|
-
};
|
|
608
|
-
if (effective.includes("mcp")) {
|
|
609
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
610
|
-
if (mcpEntries.length > 0) {
|
|
611
|
-
opencodeConfig.mcp = buildOpenCodeMcpServers(features.mcpServers);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
if (effective.includes("models") && features.models) {
|
|
615
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID);
|
|
616
|
-
if (resolved.default)
|
|
617
|
-
opencodeConfig.model = resolved.default;
|
|
618
|
-
if (resolved.small)
|
|
619
|
-
opencodeConfig.small_model = resolved.small;
|
|
620
|
-
if (Object.keys(resolved.providers).length > 0) {
|
|
621
|
-
opencodeConfig.provider = resolved.providers;
|
|
622
|
-
}
|
|
623
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
624
|
-
if (agentEntries.length > 0) {
|
|
625
|
-
const agentConfig = {};
|
|
626
|
-
for (const [name, assignment] of agentEntries) {
|
|
627
|
-
const config = { model: assignment.model };
|
|
628
|
-
if (assignment.temperature !== undefined) {
|
|
629
|
-
config.temperature = assignment.temperature;
|
|
630
|
-
}
|
|
631
|
-
if (assignment.top_p !== undefined) {
|
|
632
|
-
config.top_p = assignment.top_p;
|
|
633
|
-
}
|
|
634
|
-
agentConfig[name] = config;
|
|
635
|
-
}
|
|
636
|
-
opencodeConfig.agent = agentConfig;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
if (Object.keys(opencodeConfig).length > 1) {
|
|
640
|
-
writeGeneratedJson(filepath, opencodeConfig, { header: false });
|
|
641
|
-
filesWritten.push(filepath);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (effective.includes("rules")) {
|
|
645
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
|
|
646
|
-
const detailRules = getDetailRules(rules);
|
|
647
|
-
if (detailRules.length > 0) {
|
|
648
|
-
const memoriesDir = resolve(opencodeDir, "memories");
|
|
649
|
-
if (deleteExisting) {
|
|
650
|
-
removeIfExists(memoriesDir);
|
|
651
|
-
filesDeleted.push(memoriesDir);
|
|
652
|
-
}
|
|
653
|
-
ensureDir(memoriesDir);
|
|
654
|
-
for (const rule of detailRules) {
|
|
655
|
-
const filepath = join4(memoriesDir, `${rule.name}.md`);
|
|
656
|
-
writeGeneratedFile(filepath, rule.content);
|
|
657
|
-
filesWritten.push(filepath);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
function buildOpenCodeMcpServers(servers) {
|
|
665
|
-
const mcp = {};
|
|
666
|
-
for (const [name, entry] of Object.entries(servers)) {
|
|
667
|
-
if (entry.url) {
|
|
668
|
-
mcp[name] = {
|
|
669
|
-
type: "remote",
|
|
670
|
-
url: entry.url,
|
|
671
|
-
enabled: true,
|
|
672
|
-
...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {}
|
|
673
|
-
};
|
|
674
|
-
} else if (entry.command) {
|
|
675
|
-
const cmd = entry.args ? [entry.command, ...entry.args] : [entry.command];
|
|
676
|
-
mcp[name] = {
|
|
677
|
-
type: "local",
|
|
678
|
-
command: cmd,
|
|
679
|
-
enabled: true,
|
|
680
|
-
...entry.env && Object.keys(entry.env).length > 0 ? { environment: entry.env } : {}
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return mcp;
|
|
685
|
-
}
|
|
686
|
-
function generateOpenCodeHookPlugin(packName, events) {
|
|
687
|
-
const identifier = packNameToIdentifier(packName);
|
|
688
|
-
const hookMap = mapHookEvents(events);
|
|
689
|
-
const hookEntries = Object.entries(hookMap).map(([event, handlers]) => {
|
|
690
|
-
const body = handlers.map((h) => {
|
|
691
|
-
const matcherGuard = h.matcher ? `if (!/(?:${h.matcher})/.test(String(input?.tool ?? ""))) return;
|
|
692
|
-
` : "";
|
|
693
|
-
return ` ${matcherGuard}await $\`${h.command}\`;`;
|
|
694
|
-
}).join(`
|
|
695
|
-
`);
|
|
696
|
-
return ` "${event}": async (input, output) => {
|
|
697
|
-
${body}
|
|
698
|
-
},`;
|
|
699
|
-
}).join(`
|
|
700
|
-
`);
|
|
701
|
-
return `import type { Plugin } from "@opencode-ai/plugin";
|
|
702
|
-
|
|
703
|
-
export const ${identifier}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
17
|
+
export const ${U}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
704
18
|
return {
|
|
705
|
-
${
|
|
706
|
-
};
|
|
707
|
-
};
|
|
708
|
-
`;
|
|
709
|
-
}
|
|
710
|
-
function mapHookEvents(events) {
|
|
711
|
-
const mapped = {};
|
|
712
|
-
const eventMapping = {
|
|
713
|
-
sessionStart: "session.created",
|
|
714
|
-
postToolUse: "tool.execute.after",
|
|
715
|
-
preToolUse: "tool.execute.before",
|
|
716
|
-
stop: "session.idle",
|
|
717
|
-
afterFileEdit: "file.edited",
|
|
718
|
-
afterShellExecution: "command.executed"
|
|
19
|
+
${$}
|
|
719
20
|
};
|
|
720
|
-
for (const [event, handlers] of Object.entries(events)) {
|
|
721
|
-
const opencodeEvent = eventMapping[event] ?? event;
|
|
722
|
-
if (!mapped[opencodeEvent]) {
|
|
723
|
-
mapped[opencodeEvent] = [];
|
|
724
|
-
}
|
|
725
|
-
mapped[opencodeEvent].push(...handlers.filter((h) => h.command));
|
|
726
|
-
}
|
|
727
|
-
return mapped;
|
|
728
|
-
}
|
|
729
|
-
export {
|
|
730
|
-
OpenCodeTarget
|
|
731
21
|
};
|
|
22
|
+
`}function Eq(q){let Q={},U={sessionStart:"session.created",postToolUse:"tool.execute.after",preToolUse:"tool.execute.before",stop:"session.idle",afterFileEdit:"file.edited",afterShellExecution:"command.executed"};for(let[Z,$]of Object.entries(q)){let B=U[Z]??Z;if(!Q[B])Q[B]=[];Q[B].push(...$.filter((J)=>J.command))}return Q}export{Pq as OpenCodeTarget};
|