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,111 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
// src/core/profile-resolver.ts
|
|
5
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
6
|
-
let defaultModel = merged.default;
|
|
7
|
-
let smallModel = merged.small;
|
|
8
|
-
let agents = { ...merged.agents };
|
|
9
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
10
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
11
|
-
if (resolvedProfile.default)
|
|
12
|
-
defaultModel = resolvedProfile.default;
|
|
13
|
-
if (resolvedProfile.small)
|
|
14
|
-
smallModel = resolvedProfile.small;
|
|
15
|
-
if (resolvedProfile.agents) {
|
|
16
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (targetId) {
|
|
20
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
21
|
-
if (targetOverride) {
|
|
22
|
-
if (targetOverride.default)
|
|
23
|
-
defaultModel = targetOverride.default;
|
|
24
|
-
if (targetOverride.small)
|
|
25
|
-
smallModel = targetOverride.small;
|
|
26
|
-
if (targetOverride.agents) {
|
|
27
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const providers = {};
|
|
32
|
-
if (merged.providers) {
|
|
33
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
34
|
-
providers[name] = {
|
|
35
|
-
...config.options ? { options: config.options } : {},
|
|
36
|
-
...config.models ? { models: config.models } : {}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
41
|
-
const profiles = {};
|
|
42
|
-
if (merged.profiles) {
|
|
43
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
44
|
-
profiles[name] = {
|
|
45
|
-
description: profile.description,
|
|
46
|
-
default: profile.default,
|
|
47
|
-
small: profile.small
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
default: defaultModel,
|
|
53
|
-
small: smallModel,
|
|
54
|
-
agents,
|
|
55
|
-
providers,
|
|
56
|
-
routing: merged.routing ?? [],
|
|
57
|
-
profileNames,
|
|
58
|
-
activeProfile: modelProfile,
|
|
59
|
-
profiles
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
63
|
-
const fromModels = resolved.agents[agentName];
|
|
64
|
-
if (fromModels) {
|
|
65
|
-
return {
|
|
66
|
-
model: fromModels.model,
|
|
67
|
-
temperature: fromModels.temperature,
|
|
68
|
-
top_p: fromModels.top_p
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (frontmatterModel) {
|
|
72
|
-
return { model: frontmatterModel };
|
|
73
|
-
}
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
77
|
-
const visited = new Set;
|
|
78
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
79
|
-
}
|
|
80
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
81
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
82
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
83
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
84
|
-
}
|
|
85
|
-
if (visited.has(name)) {
|
|
86
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" \u2192 ")}`);
|
|
87
|
-
}
|
|
88
|
-
const profile = profiles[name];
|
|
89
|
-
if (!profile) {
|
|
90
|
-
throw new Error(`Profile "${name}" not found`);
|
|
91
|
-
}
|
|
92
|
-
visited.add(name);
|
|
93
|
-
if (!profile.extends) {
|
|
94
|
-
return { ...profile };
|
|
95
|
-
}
|
|
96
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
97
|
-
return {
|
|
98
|
-
description: profile.description ?? parent.description,
|
|
99
|
-
default: profile.default ?? parent.default,
|
|
100
|
-
small: profile.small ?? parent.small,
|
|
101
|
-
agents: {
|
|
102
|
-
...parent.agents,
|
|
103
|
-
...profile.agents
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
resolveProfileInheritance,
|
|
109
|
-
resolveModels,
|
|
110
|
-
resolveAgentModel
|
|
111
|
-
};
|
|
2
|
+
var S=import.meta.require;function V(b,q,x){let{default:y,small:k}=b,z={...b.agents};if(q&&b.profiles?.[q]){let j=Q(q,b.profiles);if(j.default)y=j.default;if(j.small)k=j.small;if(j.agents)z={...z,...j.agents}}if(x){let j=b.overrides?.[x];if(j){if(j.default)y=j.default;if(j.small)k=j.small;if(j.agents)z={...z,...j.agents}}}let F={};if(b.providers)for(let[j,B]of Object.entries(b.providers))F[j]={...B.options?{options:B.options}:{},...B.models?{models:B.models}:{}};let L=Object.keys(b.profiles??{}),G={};if(b.profiles)for(let[j,B]of Object.entries(b.profiles))G[j]={description:B.description,default:B.default,small:B.small};return{default:y,small:k,agents:z,providers:F,routing:b.routing??[],profileNames:L,activeProfile:q,profiles:G}}function W(b,q,x){let y=b.agents[q];if(y)return{model:y.model,temperature:y.temperature,top_p:y.top_p};if(x)return{model:x};return{}}function Q(b,q){return K(b,q,new Set,0)}var J=10;function K(b,q,x,y){if(y>J)throw Error(`Profile inheritance too deep (max ${J}): ${b}`);if(x.has(b))throw Error(`Circular profile inheritance detected: ${[...x,b].join(" \u2192 ")}`);let k=q[b];if(!k)throw Error(`Profile "${b}" not found`);if(x.add(b),!k.extends)return{...k};let z=K(k.extends,q,x,y+1);return{description:k.description??z.description,default:k.default??z.default,small:k.small??z.small,agents:{...z.agents,...k.agents}}}export{Q as resolveProfileInheritance,V as resolveModels,W as resolveAgentModel};
|
|
@@ -1,405 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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/hooks.ts
|
|
133
|
-
import { join as join2 } from "path";
|
|
134
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
135
|
-
function parseHooks(packDir, packName) {
|
|
136
|
-
const hooksPath = join2(packDir, "hooks", "hooks.json");
|
|
137
|
-
const raw = readJsonOrNull(hooksPath);
|
|
138
|
-
if (!raw)
|
|
139
|
-
return null;
|
|
140
|
-
const shared = raw.hooks ?? {};
|
|
141
|
-
const targetOverrides = {};
|
|
142
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
143
|
-
const override = raw[key];
|
|
144
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
145
|
-
targetOverrides[key] = override.hooks;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
packName,
|
|
150
|
-
sourcePath: hooksPath,
|
|
151
|
-
version: raw.version,
|
|
152
|
-
shared,
|
|
153
|
-
targetOverrides
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
157
|
-
const merged = {};
|
|
158
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
159
|
-
merged[event] = [...entries];
|
|
160
|
-
}
|
|
161
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
162
|
-
if (overrides) {
|
|
163
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
164
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return merged;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/features/skills.ts
|
|
171
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
172
|
-
import { basename, join as join3 } from "path";
|
|
173
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
174
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
175
|
-
function parseSkills(skillsDir, packName) {
|
|
176
|
-
const dirs = listDirs(skillsDir);
|
|
177
|
-
const skills = [];
|
|
178
|
-
for (const dir of dirs) {
|
|
179
|
-
const skillMd = join3(dir, "SKILL.md");
|
|
180
|
-
if (existsSync2(skillMd)) {
|
|
181
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return skills;
|
|
185
|
-
}
|
|
186
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
187
|
-
const raw = readFileSync2(filepath, "utf-8");
|
|
188
|
-
const { data, content } = parseFrontmatter(raw);
|
|
189
|
-
return {
|
|
190
|
-
name: data.name ?? basename(skillDir),
|
|
191
|
-
sourcePath: filepath,
|
|
192
|
-
sourceDir: skillDir,
|
|
193
|
-
packName,
|
|
194
|
-
meta: data,
|
|
195
|
-
content
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function buildSkillFrontmatter(skill) {
|
|
199
|
-
return {
|
|
200
|
-
...skill.meta,
|
|
201
|
-
name: skill.name
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function serializeSkill(skill) {
|
|
205
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
206
|
-
}
|
|
207
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
208
|
-
const { data, content } = parseFrontmatter(source);
|
|
209
|
-
const normalized = {
|
|
210
|
-
...data,
|
|
211
|
-
name: skillName
|
|
212
|
-
};
|
|
213
|
-
let addedDescription = false;
|
|
214
|
-
const description = normalized.description;
|
|
215
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
216
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
217
|
-
addedDescription = true;
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
content: serializeFrontmatter(normalized, content),
|
|
221
|
-
addedDescription
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
225
|
-
const errors = [];
|
|
226
|
-
const dirName = basename(skill.sourceDir);
|
|
227
|
-
const declaredName = skill.meta.name;
|
|
228
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
229
|
-
errors.push('Missing required frontmatter field "name".');
|
|
230
|
-
} else {
|
|
231
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
232
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
233
|
-
}
|
|
234
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
235
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
236
|
-
}
|
|
237
|
-
if (declaredName !== dirName) {
|
|
238
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const description = skill.meta.description;
|
|
242
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
243
|
-
errors.push('Missing required frontmatter field "description".');
|
|
244
|
-
}
|
|
245
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
246
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
247
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
248
|
-
}
|
|
249
|
-
return errors;
|
|
250
|
-
}
|
|
251
|
-
function skillMatchesTarget(skill, targetId) {
|
|
252
|
-
const { targets } = skill.meta;
|
|
253
|
-
if (!targets || targets === "*")
|
|
254
|
-
return true;
|
|
255
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
256
|
-
return true;
|
|
257
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// src/exporters/cursor-plugin.ts
|
|
261
|
-
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
262
|
-
import { join as join4, resolve } from "path";
|
|
263
|
-
function exportCursorPlugin(pack, outputDir) {
|
|
264
|
-
const filesWritten = [];
|
|
265
|
-
const pluginName = normalizeCursorPluginName(pack.manifest.name);
|
|
266
|
-
const pluginDir = resolve(outputDir, pluginName);
|
|
267
|
-
mkdirSync2(pluginDir, { recursive: true });
|
|
268
|
-
const manifest = {
|
|
269
|
-
name: pluginName
|
|
270
|
-
};
|
|
271
|
-
if (pack.manifest.version) {
|
|
272
|
-
manifest.version = pack.manifest.version;
|
|
273
|
-
}
|
|
274
|
-
if (pack.manifest.description) {
|
|
275
|
-
manifest.description = pack.manifest.description;
|
|
276
|
-
}
|
|
277
|
-
const author = toCursorPluginAuthor(pack.manifest.author);
|
|
278
|
-
if (author) {
|
|
279
|
-
manifest.author = author;
|
|
280
|
-
}
|
|
281
|
-
if (pack.manifest.homepage) {
|
|
282
|
-
manifest.homepage = pack.manifest.homepage;
|
|
283
|
-
}
|
|
284
|
-
if (pack.manifest.repository) {
|
|
285
|
-
manifest.repository = typeof pack.manifest.repository === "string" ? pack.manifest.repository : pack.manifest.repository.url;
|
|
286
|
-
}
|
|
287
|
-
if (pack.manifest.license) {
|
|
288
|
-
manifest.license = pack.manifest.license;
|
|
289
|
-
}
|
|
290
|
-
if (pack.manifest.logo) {
|
|
291
|
-
manifest.logo = pack.manifest.logo;
|
|
292
|
-
}
|
|
293
|
-
if (pack.manifest.tags.length > 0) {
|
|
294
|
-
manifest.keywords = pack.manifest.tags;
|
|
295
|
-
}
|
|
296
|
-
if (pack.rules.length > 0) {
|
|
297
|
-
const rulesDir = join4(pluginDir, "rules");
|
|
298
|
-
ensureDir(rulesDir);
|
|
299
|
-
manifest.rules = "rules";
|
|
300
|
-
for (const rule of pack.rules) {
|
|
301
|
-
const cursorMeta = rule.meta.cursor ?? {};
|
|
302
|
-
const fm = {
|
|
303
|
-
description: cursorMeta.description ?? rule.meta.description ?? "",
|
|
304
|
-
alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
|
|
305
|
-
};
|
|
306
|
-
const globs = cursorMeta.globs ?? rule.meta.globs;
|
|
307
|
-
if (globs)
|
|
308
|
-
fm.globs = globs;
|
|
309
|
-
const filename = `${rule.name}.mdc`;
|
|
310
|
-
const filepath = join4(rulesDir, filename);
|
|
311
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, rule.content));
|
|
312
|
-
filesWritten.push(filepath);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (pack.agents.length > 0) {
|
|
316
|
-
const agentsDir = join4(pluginDir, "agents");
|
|
317
|
-
ensureDir(agentsDir);
|
|
318
|
-
manifest.agents = "agents";
|
|
319
|
-
for (const agent of pack.agents) {
|
|
320
|
-
const fm = {
|
|
321
|
-
name: agent.name,
|
|
322
|
-
description: agent.meta.description ?? ""
|
|
323
|
-
};
|
|
324
|
-
const filename = `${agent.name}.md`;
|
|
325
|
-
const filepath = join4(agentsDir, filename);
|
|
326
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, agent.content));
|
|
327
|
-
filesWritten.push(filepath);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (pack.skills.length > 0) {
|
|
331
|
-
const skillsDir = join4(pluginDir, "skills");
|
|
332
|
-
ensureDir(skillsDir);
|
|
333
|
-
manifest.skills = "skills";
|
|
334
|
-
for (const skill of pack.skills) {
|
|
335
|
-
const skillSubDir = join4(skillsDir, skill.name);
|
|
336
|
-
ensureDir(skillSubDir);
|
|
337
|
-
const filepath = join4(skillSubDir, "SKILL.md");
|
|
338
|
-
const content = serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
339
|
-
writeFileSync2(filepath, content);
|
|
340
|
-
filesWritten.push(filepath);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (pack.commands.length > 0) {
|
|
344
|
-
const commandsDir = join4(pluginDir, "commands");
|
|
345
|
-
ensureDir(commandsDir);
|
|
346
|
-
manifest.commands = "commands";
|
|
347
|
-
for (const cmd of pack.commands) {
|
|
348
|
-
const fm = {
|
|
349
|
-
name: cmd.name
|
|
350
|
-
};
|
|
351
|
-
if (cmd.meta.description) {
|
|
352
|
-
fm.description = cmd.meta.description;
|
|
353
|
-
}
|
|
354
|
-
const filename = `${cmd.name}.md`;
|
|
355
|
-
const filepath = join4(commandsDir, filename);
|
|
356
|
-
writeFileSync2(filepath, serializeFrontmatter(fm, cmd.content));
|
|
357
|
-
filesWritten.push(filepath);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (pack.hooks) {
|
|
361
|
-
const events = resolveHooksForTarget(pack.hooks, "cursor");
|
|
362
|
-
if (Object.keys(events).length > 0) {
|
|
363
|
-
const hooksDir = join4(pluginDir, "hooks");
|
|
364
|
-
ensureDir(hooksDir);
|
|
365
|
-
const filepath = join4(hooksDir, "hooks.json");
|
|
366
|
-
writeFileSync2(filepath, JSON.stringify({ version: pack.hooks.version ?? 1, hooks: events }, null, 2) + `
|
|
367
|
-
`);
|
|
368
|
-
filesWritten.push(filepath);
|
|
369
|
-
manifest.hooks = "hooks/hooks.json";
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (pack.mcp && Object.keys(pack.mcp.servers).length > 0) {
|
|
373
|
-
manifest.mcpServers = ".mcp.json";
|
|
374
|
-
const filepath = join4(pluginDir, ".mcp.json");
|
|
375
|
-
writeFileSync2(filepath, JSON.stringify({ mcpServers: pack.mcp.servers }, null, 2) + `
|
|
376
|
-
`);
|
|
377
|
-
filesWritten.push(filepath);
|
|
378
|
-
}
|
|
379
|
-
const manifestDir = join4(pluginDir, ".cursor-plugin");
|
|
380
|
-
ensureDir(manifestDir);
|
|
381
|
-
const manifestPath = join4(manifestDir, "plugin.json");
|
|
382
|
-
writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2) + `
|
|
383
|
-
`);
|
|
384
|
-
filesWritten.push(manifestPath);
|
|
385
|
-
return { outputDir: pluginDir, filesWritten, manifest };
|
|
386
|
-
}
|
|
387
|
-
function normalizeCursorPluginName(name) {
|
|
388
|
-
const normalized = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/-+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[^a-z0-9]+$/, "");
|
|
389
|
-
return normalized.length > 0 ? normalized : "agentpacks-plugin";
|
|
390
|
-
}
|
|
391
|
-
function toCursorPluginAuthor(author) {
|
|
392
|
-
if (!author) {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
if (typeof author === "string") {
|
|
396
|
-
return { name: author };
|
|
397
|
-
}
|
|
398
|
-
return {
|
|
399
|
-
name: author.name,
|
|
400
|
-
...author.email ? { email: author.email } : {}
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
export {
|
|
404
|
-
exportCursorPlugin
|
|
405
|
-
};
|
|
2
|
+
var cn=import.meta.require;import{existsSync as q,mkdirSync as F,readdirSync as Q,readFileSync as G,rmSync as A,statSync as U,writeFileSync as S}from"fs";import{dirname as D,join as Z,relative as e}from"path";var v="<!-- Generated by agentpacks. DO NOT EDIT. -->",V="// Generated by agentpacks. DO NOT EDIT.",Y="// Generated by agentpacks. DO NOT EDIT.";function T(n,s,o={}){let{header:u=!0,type:m}=o,g=m??_(n);$(D(n));let f=s;if(u){let C=N(g);if(C)f=`${C}
|
|
3
|
+
${s}`}S(n,f,"utf-8")}function $n(n,s,o={}){let u=JSON.stringify(s,null,2);T(n,u+`
|
|
4
|
+
`,{...o,type:"json"})}function x(n){if(!q(n))return null;return G(n,"utf-8")}function J(n){let s=x(n);if(s===null)return null;return JSON.parse(s)}function $(n){if(!q(n))F(n,{recursive:!0})}function bn(n){if(q(n))A(n,{recursive:!0,force:!0})}function p(n,s={}){let{extension:o,recursive:u=!1}=s;if(!q(n))return[];let m=[],g=Q(n);for(let f of g){let C=Z(n,f),W=U(C);if(W.isDirectory()&&u)m.push(...p(C,s));else if(W.isFile()){if(!o||f.endsWith(o))m.push(C)}}return m}function K(n){if(!q(n))return[];return Q(n).map((s)=>Z(n,s)).filter((s)=>U(s).isDirectory())}function Ln(n,s){return e(n,s)}function jn(n){let s=x(n);if(!s)return!1;return s.startsWith(v)||s.startsWith(V)||s.startsWith(Y)}function _(n){if(n.endsWith(".json")||n.endsWith(".jsonc"))return"json";if(n.endsWith(".ts")||n.endsWith(".mts"))return"ts";if(n.endsWith(".js")||n.endsWith(".mjs"))return"js";return"md"}function N(n){switch(n){case"md":return v;case"json":return V;case"js":case"ts":return Y;default:return null}}import X from"gray-matter";function y(n){let{data:s,content:o}=X(n);return{data:s,content:o.trim(),raw:n}}function L(n,s){let o=Object.fromEntries(Object.entries(n).filter(([,u])=>u!==void 0));if(Object.keys(o).length===0)return s;return X.stringify(s,o)}import{join as d}from"path";var h=["cursor","claudecode","codexcli","opencode"];function Qn(n,s){let o=d(n,"hooks","hooks.json"),u=J(o);if(!u)return null;let m=u.hooks??{},g={};for(let f of h){let C=u[f];if(C&&typeof C==="object"&&"hooks"in C&&C.hooks)g[f]=C.hooks}return{packName:s,sourcePath:o,version:u.version,shared:m,targetOverrides:g}}function M(n,s){let o={};for(let[m,g]of Object.entries(n.shared))o[m]=[...g];let u=n.targetOverrides[s];if(u)for(let[m,g]of Object.entries(u))o[m]=[...o[m]??[],...g];return o}import{existsSync as E,readFileSync as k}from"fs";import{basename as R,join as l}from"path";var a=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,O=64;function xn(n,s){let o=K(n),u=[];for(let m of o){let g=l(m,"SKILL.md");if(E(g))u.push(nn(g,m,s))}return u}function nn(n,s,o){let u=k(n,"utf-8"),{data:m,content:g}=y(u);return{name:m.name??R(s),sourcePath:n,sourceDir:s,packName:o,meta:m,content:g}}function z(n){return{...n.meta,name:n.name}}function Jn(n){return L(z(n),n.content)}function Kn(n,s){let{data:o,content:u}=y(n),m={...o,name:s},g=!1,f=m.description;if(typeof f!=="string"||f.trim().length===0)m.description=`Imported skill: ${s}`,g=!0;return{content:L(m,u),addedDescription:g}}function Xn(n){let s=[],o=R(n.sourceDir),u=n.meta.name;if(typeof u!=="string"||u.trim().length===0)s.push('Missing required frontmatter field "name".');else{if(u.length>O)s.push(`Invalid "name": must be at most ${O} characters.`);if(!a.test(u))s.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(u!==o)s.push(`Invalid "name": must match containing directory "${o}".`)}let m=n.meta.description;if(typeof m!=="string"||m.trim().length===0)s.push('Missing required frontmatter field "description".');let g=n.meta["allowed-tools"];if(g!==void 0&&(!Array.isArray(g)||g.some((f)=>typeof f!=="string"||f.length===0)))s.push('Invalid "allowed-tools": expected an array of non-empty strings.');return s}function Mn(n,s){let{targets:o}=n.meta;if(!o||o==="*")return!0;if(Array.isArray(o)&&o.includes("*"))return!0;return Array.isArray(o)&&o.includes(s)}import{copyFileSync as I,existsSync as P,mkdirSync as sn,writeFileSync as j}from"fs";import{dirname as on,join as r,resolve as mn}from"path";function An(n,s){let o=[],u=gn(n.manifest.name),m=mn(s,u);sn(m,{recursive:!0});let g={name:u};if(n.manifest.version)g.version=n.manifest.version;if(n.manifest.description)g.description=n.manifest.description;let f=un(n.manifest.author);if(f)g.author=f;if(n.manifest.homepage)g.homepage=n.manifest.homepage;if(n.manifest.repository)g.repository=typeof n.manifest.repository==="string"?n.manifest.repository:n.manifest.repository.url;if(n.manifest.license)g.license=n.manifest.license;if(n.manifest.logo)g.logo=n.manifest.logo;if(n.manifest.tags.length>0)g.keywords=n.manifest.tags;if(n.rules.length>0){let c=r(m,"rules");$(c),g.rules="rules";for(let i of n.rules){let t=i.meta.cursor??{},b={description:t.description??i.meta.description??"",alwaysApply:t.alwaysApply??i.meta.root??!1},w=t.globs??i.meta.globs;if(w)b.globs=w;let H=`${i.name}.mdc`,B=r(c,H);j(B,L(b,i.content)),o.push(B)}}if(n.agents.length>0){let c=r(m,"agents");$(c),g.agents="agents";for(let i of n.agents){let t={name:i.name,description:i.meta.description??""},b=`${i.name}.md`,w=r(c,b);j(w,L(t,i.content)),o.push(w)}}if(n.skills.length>0){let c=r(m,"skills");$(c),g.skills="skills";for(let i of n.skills){let t=r(c,i.name);$(t);let b=r(t,"SKILL.md"),w=L(z(i),i.content);j(b,w),o.push(b)}}if(n.commands.length>0){let c=r(m,"commands");$(c),g.commands="commands";for(let i of n.commands){let t={name:i.name};if(i.meta.description)t.description=i.meta.description;let b=`${i.name}.md`,w=r(c,b);j(w,L(t,i.content)),o.push(w)}}if(n.hooks){let c=M(n.hooks,"cursor");if(Object.keys(c).length>0){let i=r(m,"hooks");$(i);let t=r(i,"hooks.json");j(t,JSON.stringify({version:n.hooks.version??1,hooks:c},null,2)+`
|
|
5
|
+
`),o.push(t),g.hooks="hooks/hooks.json"}}if(n.mcp&&Object.keys(n.mcp.servers).length>0){g.mcpServers=".mcp.json";let c=r(m,".mcp.json");j(c,JSON.stringify({mcpServers:n.mcp.servers},null,2)+`
|
|
6
|
+
`),o.push(c)}rn(n,m,o),fn(n,m,o);let C=r(m,".cursor-plugin");$(C);let W=r(C,"plugin.json");return j(W,JSON.stringify(g,null,2)+`
|
|
7
|
+
`),o.push(W),{outputDir:m,filesWritten:o,manifest:g}}function gn(n){let s=n.toLowerCase().replace(/[^a-z0-9.-]+/g,"-").replace(/-+/g,"-").replace(/^[^a-z0-9]+/,"").replace(/[^a-z0-9]+$/,"");return s.length>0?s:"agentpacks-plugin"}function un(n){if(!n)return null;if(typeof n==="string")return{name:n};return{name:n.name,...n.email?{email:n.email}:{}}}function rn(n,s,o){let u=r(n.directory,"README.md");if(!P(u))return;let m=r(s,"README.md");I(u,m),o.push(m)}function fn(n,s,o){if(!n.manifest.logo)return;let u=r(n.directory,n.manifest.logo);if(!P(u))return;let m=r(s,n.manifest.logo);$(on(m)),I(u,m),o.push(m)}export{An as exportCursorPlugin};
|