agentpacks 0.2.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.d.ts +32 -0
- package/dist/api.js +2852 -0
- package/dist/cli/export-cmd.d.ts +12 -0
- package/dist/cli/export-cmd.js +786 -0
- package/dist/cli/generate.d.ts +13 -0
- package/dist/cli/generate.js +2018 -0
- package/dist/cli/import-cmd.d.ts +9 -0
- package/dist/cli/import-cmd.js +691 -0
- package/dist/cli/init.d.ts +5 -0
- package/dist/cli/init.js +214 -0
- package/dist/cli/install.d.ts +11 -0
- package/dist/cli/install.js +610 -0
- package/dist/cli/pack/create.d.ts +4 -0
- package/dist/cli/pack/create.js +175 -0
- package/dist/cli/pack/enable.d.ts +8 -0
- package/dist/cli/pack/enable.js +96 -0
- package/dist/cli/pack/list.d.ts +4 -0
- package/dist/cli/pack/list.js +699 -0
- package/dist/cli/pack/validate.d.ts +4 -0
- package/dist/cli/pack/validate.js +364 -0
- package/dist/core/config.d.ts +77 -0
- package/dist/core/config.js +181 -0
- package/dist/core/dependency-resolver.d.ts +38 -0
- package/dist/core/dependency-resolver.js +151 -0
- package/dist/core/feature-merger.d.ts +61 -0
- package/dist/core/feature-merger.js +139 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +924 -0
- package/dist/core/lockfile.d.ts +50 -0
- package/dist/core/lockfile.js +72 -0
- package/dist/core/metarepo.d.ts +26 -0
- package/dist/core/metarepo.js +218 -0
- package/dist/core/pack-loader.d.ts +61 -0
- package/dist/core/pack-loader.js +646 -0
- package/dist/exporters/cursor-plugin.d.ts +29 -0
- package/dist/exporters/cursor-plugin.js +258 -0
- package/dist/exporters/index.d.ts +1 -0
- package/dist/exporters/index.js +258 -0
- package/dist/features/agents.d.ts +48 -0
- package/dist/features/agents.js +190 -0
- package/dist/features/commands.d.ts +33 -0
- package/dist/features/commands.js +190 -0
- package/dist/features/hooks.d.ts +33 -0
- package/dist/features/hooks.js +182 -0
- package/dist/features/ignore.d.ts +21 -0
- package/dist/features/ignore.js +72 -0
- package/dist/features/index.d.ts +8 -0
- package/dist/features/index.js +426 -0
- package/dist/features/mcp.d.ts +34 -0
- package/dist/features/mcp.js +172 -0
- package/dist/features/plugins.d.ts +23 -0
- package/dist/features/plugins.js +168 -0
- package/dist/features/rules.d.ts +53 -0
- package/dist/features/rules.js +198 -0
- package/dist/features/skills.d.ts +42 -0
- package/dist/features/skills.js +198 -0
- package/dist/importers/claude-code.d.ts +5 -0
- package/dist/importers/claude-code.js +224 -0
- package/dist/importers/cursor.d.ts +5 -0
- package/dist/importers/cursor.js +288 -0
- package/dist/importers/opencode.d.ts +5 -0
- package/dist/importers/opencode.js +261 -0
- package/dist/importers/rulesync.d.ts +14 -0
- package/dist/importers/rulesync.js +280 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3464 -0
- package/dist/node/api.js +2852 -0
- package/dist/node/cli/export-cmd.js +786 -0
- package/dist/node/cli/generate.js +2018 -0
- package/dist/node/cli/import-cmd.js +691 -0
- package/dist/node/cli/init.js +214 -0
- package/dist/node/cli/install.js +610 -0
- package/dist/node/cli/pack/create.js +175 -0
- package/dist/node/cli/pack/enable.js +96 -0
- package/dist/node/cli/pack/list.js +699 -0
- package/dist/node/cli/pack/validate.js +364 -0
- package/dist/node/core/config.js +181 -0
- package/dist/node/core/dependency-resolver.js +151 -0
- package/dist/node/core/feature-merger.js +139 -0
- package/dist/node/core/index.js +924 -0
- package/dist/node/core/lockfile.js +72 -0
- package/dist/node/core/metarepo.js +218 -0
- package/dist/node/core/pack-loader.js +646 -0
- package/dist/node/exporters/cursor-plugin.js +258 -0
- package/dist/node/exporters/index.js +258 -0
- package/dist/node/features/agents.js +190 -0
- package/dist/node/features/commands.js +190 -0
- package/dist/node/features/hooks.js +182 -0
- package/dist/node/features/ignore.js +72 -0
- package/dist/node/features/index.js +426 -0
- package/dist/node/features/mcp.js +172 -0
- package/dist/node/features/plugins.js +168 -0
- package/dist/node/features/rules.js +198 -0
- package/dist/node/features/skills.js +198 -0
- package/dist/node/importers/claude-code.js +224 -0
- package/dist/node/importers/cursor.js +288 -0
- package/dist/node/importers/opencode.js +261 -0
- package/dist/node/importers/rulesync.js +280 -0
- package/dist/node/index.js +3464 -0
- package/dist/node/sources/git-ref.js +79 -0
- package/dist/node/sources/git.js +245 -0
- package/dist/node/sources/index.js +416 -0
- package/dist/node/sources/local.js +52 -0
- package/dist/node/sources/npm-ref.js +84 -0
- package/dist/node/sources/npm.js +211 -0
- package/dist/node/targets/additional-targets.js +428 -0
- package/dist/node/targets/agents-md.js +239 -0
- package/dist/node/targets/base-target.js +51 -0
- package/dist/node/targets/claude-code.js +490 -0
- package/dist/node/targets/codex-cli.js +297 -0
- package/dist/node/targets/copilot.js +390 -0
- package/dist/node/targets/cursor.js +441 -0
- package/dist/node/targets/gemini-cli.js +352 -0
- package/dist/node/targets/generic-md-target.js +319 -0
- package/dist/node/targets/index.js +1351 -0
- package/dist/node/targets/opencode.js +556 -0
- package/dist/node/targets/registry.js +1343 -0
- package/dist/node/utils/diff.js +144 -0
- package/dist/node/utils/filesystem.js +152 -0
- package/dist/node/utils/frontmatter.js +52 -0
- package/dist/node/utils/global.js +81 -0
- package/dist/node/utils/markdown.js +62 -0
- package/dist/sources/git-ref.d.ts +27 -0
- package/dist/sources/git-ref.js +79 -0
- package/dist/sources/git.d.ts +29 -0
- package/dist/sources/git.js +245 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.js +416 -0
- package/dist/sources/local.d.ts +8 -0
- package/dist/sources/local.js +52 -0
- package/dist/sources/npm-ref.d.ts +30 -0
- package/dist/sources/npm-ref.js +84 -0
- package/dist/sources/npm.d.ts +20 -0
- package/dist/sources/npm.js +211 -0
- package/dist/targets/additional-targets.d.ts +65 -0
- package/dist/targets/additional-targets.js +428 -0
- package/dist/targets/agents-md.d.ts +13 -0
- package/dist/targets/agents-md.js +239 -0
- package/dist/targets/base-target.d.ts +61 -0
- package/dist/targets/base-target.js +51 -0
- package/dist/targets/claude-code.d.ts +13 -0
- package/dist/targets/claude-code.js +490 -0
- package/dist/targets/codex-cli.d.ts +12 -0
- package/dist/targets/codex-cli.js +297 -0
- package/dist/targets/copilot.d.ts +12 -0
- package/dist/targets/copilot.js +390 -0
- package/dist/targets/cursor.d.ts +13 -0
- package/dist/targets/cursor.js +441 -0
- package/dist/targets/gemini-cli.d.ts +12 -0
- package/dist/targets/gemini-cli.js +352 -0
- package/dist/targets/generic-md-target.d.ts +25 -0
- package/dist/targets/generic-md-target.js +319 -0
- package/dist/targets/index.d.ts +9 -0
- package/dist/targets/index.js +1351 -0
- package/dist/targets/opencode.d.ts +13 -0
- package/dist/targets/opencode.js +556 -0
- package/dist/targets/registry.d.ts +17 -0
- package/dist/targets/registry.js +1343 -0
- package/dist/utils/diff.d.ts +13 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/filesystem.d.ts +49 -0
- package/dist/utils/filesystem.js +152 -0
- package/dist/utils/frontmatter.d.ts +19 -0
- package/dist/utils/frontmatter.js +52 -0
- package/dist/utils/global.d.ts +17 -0
- package/dist/utils/global.js +81 -0
- package/dist/utils/markdown.d.ts +20 -0
- package/dist/utils/markdown.js +62 -0
- package/package.json +808 -0
- package/templates/pack/pack.json +10 -0
- package/templates/pack/rules/overview.md +22 -0
- package/templates/workspace/agentpacks.jsonc +34 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
30
|
+
var __require = import.meta.require;
|
|
31
|
+
|
|
32
|
+
// src/core/config.ts
|
|
33
|
+
var exports_config = {};
|
|
34
|
+
__export(exports_config, {
|
|
35
|
+
resolveTargets: () => resolveTargets,
|
|
36
|
+
resolveFeatures: () => resolveFeatures,
|
|
37
|
+
loadWorkspaceConfig: () => loadWorkspaceConfig,
|
|
38
|
+
loadPackManifest: () => loadPackManifest,
|
|
39
|
+
WorkspaceConfigSchema: () => WorkspaceConfigSchema,
|
|
40
|
+
TARGET_IDS: () => TARGET_IDS,
|
|
41
|
+
REPO_MODES: () => REPO_MODES,
|
|
42
|
+
PackManifestSchema: () => PackManifestSchema,
|
|
43
|
+
FEATURE_IDS: () => FEATURE_IDS
|
|
44
|
+
});
|
|
45
|
+
import { z } from "zod";
|
|
46
|
+
import { readFileSync, existsSync } from "fs";
|
|
47
|
+
import { resolve } from "path";
|
|
48
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
49
|
+
function loadWorkspaceConfig(projectRoot) {
|
|
50
|
+
for (const filename of CONFIG_FILES) {
|
|
51
|
+
const filepath = resolve(projectRoot, filename);
|
|
52
|
+
if (existsSync(filepath)) {
|
|
53
|
+
const raw = readFileSync(filepath, "utf-8");
|
|
54
|
+
const parsed = parseJsonc(raw);
|
|
55
|
+
return WorkspaceConfigSchema.parse(parsed);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return WorkspaceConfigSchema.parse({});
|
|
59
|
+
}
|
|
60
|
+
function loadPackManifest(packDir) {
|
|
61
|
+
const filepath = resolve(packDir, "pack.json");
|
|
62
|
+
if (!existsSync(filepath)) {
|
|
63
|
+
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
64
|
+
return PackManifestSchema.parse({ name: dirName });
|
|
65
|
+
}
|
|
66
|
+
const raw = readFileSync(filepath, "utf-8");
|
|
67
|
+
const parsed = JSON.parse(raw);
|
|
68
|
+
return PackManifestSchema.parse(parsed);
|
|
69
|
+
}
|
|
70
|
+
function resolveFeatures(config, targetId) {
|
|
71
|
+
const { features } = config;
|
|
72
|
+
if (features === "*") {
|
|
73
|
+
return [...FEATURE_IDS];
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(features)) {
|
|
76
|
+
if (features.includes("*"))
|
|
77
|
+
return [...FEATURE_IDS];
|
|
78
|
+
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
79
|
+
}
|
|
80
|
+
const targetFeatures = features[targetId];
|
|
81
|
+
if (!targetFeatures)
|
|
82
|
+
return [];
|
|
83
|
+
if (targetFeatures === "*")
|
|
84
|
+
return [...FEATURE_IDS];
|
|
85
|
+
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
86
|
+
return [...FEATURE_IDS];
|
|
87
|
+
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
88
|
+
}
|
|
89
|
+
function resolveTargets(config) {
|
|
90
|
+
if (config.targets === "*")
|
|
91
|
+
return [...TARGET_IDS];
|
|
92
|
+
return config.targets;
|
|
93
|
+
}
|
|
94
|
+
var TARGET_IDS, FEATURE_IDS, REPO_MODES, PackManifestSchema, FeaturesSchema, WorkspaceConfigSchema, CONFIG_FILES;
|
|
95
|
+
var init_config = __esm(() => {
|
|
96
|
+
TARGET_IDS = [
|
|
97
|
+
"opencode",
|
|
98
|
+
"cursor",
|
|
99
|
+
"claudecode",
|
|
100
|
+
"codexcli",
|
|
101
|
+
"geminicli",
|
|
102
|
+
"copilot",
|
|
103
|
+
"agentsmd",
|
|
104
|
+
"cline",
|
|
105
|
+
"kilo",
|
|
106
|
+
"roo",
|
|
107
|
+
"qwencode",
|
|
108
|
+
"kiro",
|
|
109
|
+
"factorydroid",
|
|
110
|
+
"antigravity",
|
|
111
|
+
"junie",
|
|
112
|
+
"augmentcode",
|
|
113
|
+
"windsurf",
|
|
114
|
+
"warp",
|
|
115
|
+
"replit",
|
|
116
|
+
"zed"
|
|
117
|
+
];
|
|
118
|
+
FEATURE_IDS = [
|
|
119
|
+
"rules",
|
|
120
|
+
"commands",
|
|
121
|
+
"agents",
|
|
122
|
+
"skills",
|
|
123
|
+
"hooks",
|
|
124
|
+
"plugins",
|
|
125
|
+
"mcp",
|
|
126
|
+
"ignore"
|
|
127
|
+
];
|
|
128
|
+
REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
129
|
+
PackManifestSchema = z.object({
|
|
130
|
+
name: z.string().min(1),
|
|
131
|
+
version: z.string().default("1.0.0"),
|
|
132
|
+
description: z.string().default(""),
|
|
133
|
+
author: z.union([
|
|
134
|
+
z.string(),
|
|
135
|
+
z.object({ name: z.string(), email: z.string().optional() })
|
|
136
|
+
]).optional(),
|
|
137
|
+
tags: z.array(z.string()).default([]),
|
|
138
|
+
dependencies: z.array(z.string()).default([]),
|
|
139
|
+
conflicts: z.array(z.string()).default([]),
|
|
140
|
+
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
141
|
+
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
142
|
+
});
|
|
143
|
+
FeaturesSchema = z.union([
|
|
144
|
+
z.literal("*"),
|
|
145
|
+
z.array(z.string()),
|
|
146
|
+
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
147
|
+
]);
|
|
148
|
+
WorkspaceConfigSchema = z.object({
|
|
149
|
+
$schema: z.string().optional(),
|
|
150
|
+
packs: z.array(z.string()).default(["./packs/default"]),
|
|
151
|
+
disabled: z.array(z.string()).default([]),
|
|
152
|
+
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
153
|
+
features: FeaturesSchema.default("*"),
|
|
154
|
+
mode: z.enum(REPO_MODES).default("repo"),
|
|
155
|
+
baseDirs: z.array(z.string()).default(["."]),
|
|
156
|
+
global: z.boolean().default(false),
|
|
157
|
+
delete: z.boolean().default(true),
|
|
158
|
+
verbose: z.boolean().default(false),
|
|
159
|
+
silent: z.boolean().default(false),
|
|
160
|
+
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
161
|
+
sources: z.array(z.object({
|
|
162
|
+
source: z.string(),
|
|
163
|
+
packs: z.array(z.string()).optional(),
|
|
164
|
+
skills: z.array(z.string()).optional()
|
|
165
|
+
})).default([])
|
|
166
|
+
});
|
|
167
|
+
CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// src/utils/filesystem.ts
|
|
171
|
+
import {
|
|
172
|
+
existsSync as existsSync2,
|
|
173
|
+
mkdirSync,
|
|
174
|
+
readFileSync as readFileSync2,
|
|
175
|
+
writeFileSync,
|
|
176
|
+
readdirSync,
|
|
177
|
+
statSync
|
|
178
|
+
} from "fs";
|
|
179
|
+
import { dirname, relative, join } from "path";
|
|
180
|
+
import { removeSync } from "fs-extra";
|
|
181
|
+
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
182
|
+
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
183
|
+
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
184
|
+
function writeGeneratedFile(filepath, content, options = {}) {
|
|
185
|
+
const { header = true, type } = options;
|
|
186
|
+
const ext = type ?? inferFileType(filepath);
|
|
187
|
+
ensureDir(dirname(filepath));
|
|
188
|
+
let output = content;
|
|
189
|
+
if (header) {
|
|
190
|
+
const headerComment = getHeader(ext);
|
|
191
|
+
if (headerComment) {
|
|
192
|
+
output = `${headerComment}
|
|
193
|
+
${content}`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
writeFileSync(filepath, output, "utf-8");
|
|
197
|
+
}
|
|
198
|
+
function writeGeneratedJson(filepath, data, options = {}) {
|
|
199
|
+
const json = JSON.stringify(data, null, 2);
|
|
200
|
+
writeGeneratedFile(filepath, json + `
|
|
201
|
+
`, { ...options, type: "json" });
|
|
202
|
+
}
|
|
203
|
+
function readFileOrNull(filepath) {
|
|
204
|
+
if (!existsSync2(filepath))
|
|
205
|
+
return null;
|
|
206
|
+
return readFileSync2(filepath, "utf-8");
|
|
207
|
+
}
|
|
208
|
+
function readJsonOrNull(filepath) {
|
|
209
|
+
const content = readFileOrNull(filepath);
|
|
210
|
+
if (content === null)
|
|
211
|
+
return null;
|
|
212
|
+
return JSON.parse(content);
|
|
213
|
+
}
|
|
214
|
+
function ensureDir(dirPath) {
|
|
215
|
+
if (!existsSync2(dirPath)) {
|
|
216
|
+
mkdirSync(dirPath, { recursive: true });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function removeIfExists(targetPath) {
|
|
220
|
+
if (existsSync2(targetPath)) {
|
|
221
|
+
removeSync(targetPath);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function listFiles(dirPath, options = {}) {
|
|
225
|
+
const { extension, recursive = false } = options;
|
|
226
|
+
if (!existsSync2(dirPath))
|
|
227
|
+
return [];
|
|
228
|
+
const results = [];
|
|
229
|
+
const entries = readdirSync(dirPath);
|
|
230
|
+
for (const entry of entries) {
|
|
231
|
+
const fullPath = join(dirPath, entry);
|
|
232
|
+
const stat = statSync(fullPath);
|
|
233
|
+
if (stat.isDirectory() && recursive) {
|
|
234
|
+
results.push(...listFiles(fullPath, options));
|
|
235
|
+
} else if (stat.isFile()) {
|
|
236
|
+
if (!extension || entry.endsWith(extension)) {
|
|
237
|
+
results.push(fullPath);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return results;
|
|
242
|
+
}
|
|
243
|
+
function listDirs(dirPath) {
|
|
244
|
+
if (!existsSync2(dirPath))
|
|
245
|
+
return [];
|
|
246
|
+
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
247
|
+
}
|
|
248
|
+
function relPath(projectRoot, filepath) {
|
|
249
|
+
return relative(projectRoot, filepath);
|
|
250
|
+
}
|
|
251
|
+
function isGeneratedFile(filepath) {
|
|
252
|
+
const content = readFileOrNull(filepath);
|
|
253
|
+
if (!content)
|
|
254
|
+
return false;
|
|
255
|
+
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
256
|
+
}
|
|
257
|
+
function inferFileType(filepath) {
|
|
258
|
+
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
259
|
+
return "json";
|
|
260
|
+
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
261
|
+
return "ts";
|
|
262
|
+
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
263
|
+
return "js";
|
|
264
|
+
return "md";
|
|
265
|
+
}
|
|
266
|
+
function getHeader(type) {
|
|
267
|
+
switch (type) {
|
|
268
|
+
case "md":
|
|
269
|
+
return GENERATED_HEADER_MD;
|
|
270
|
+
case "json":
|
|
271
|
+
return GENERATED_HEADER_JSON;
|
|
272
|
+
case "js":
|
|
273
|
+
case "ts":
|
|
274
|
+
return GENERATED_HEADER_JS;
|
|
275
|
+
default:
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/utils/frontmatter.ts
|
|
281
|
+
import matter from "gray-matter";
|
|
282
|
+
function parseFrontmatter(source) {
|
|
283
|
+
const { data, content } = matter(source);
|
|
284
|
+
return {
|
|
285
|
+
data,
|
|
286
|
+
content: content.trim(),
|
|
287
|
+
raw: source
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function serializeFrontmatter(data, content) {
|
|
291
|
+
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
292
|
+
if (Object.keys(filtered).length === 0) {
|
|
293
|
+
return content;
|
|
294
|
+
}
|
|
295
|
+
return matter.stringify(content, filtered);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/features/rules.ts
|
|
299
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
300
|
+
import { basename } from "path";
|
|
301
|
+
function parseRules(rulesDir, packName) {
|
|
302
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
303
|
+
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
304
|
+
}
|
|
305
|
+
function parseRuleFile(filepath, packName) {
|
|
306
|
+
const raw = readFileSync3(filepath, "utf-8");
|
|
307
|
+
const { data, content } = parseFrontmatter(raw);
|
|
308
|
+
return {
|
|
309
|
+
name: basename(filepath, ".md"),
|
|
310
|
+
sourcePath: filepath,
|
|
311
|
+
packName,
|
|
312
|
+
meta: data,
|
|
313
|
+
content
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function ruleMatchesTarget(rule, targetId) {
|
|
317
|
+
const { targets } = rule.meta;
|
|
318
|
+
if (!targets || targets === "*")
|
|
319
|
+
return true;
|
|
320
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
321
|
+
return true;
|
|
322
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
323
|
+
}
|
|
324
|
+
function getRootRules(rules) {
|
|
325
|
+
return rules.filter((r) => r.meta.root === true);
|
|
326
|
+
}
|
|
327
|
+
function getDetailRules(rules) {
|
|
328
|
+
return rules.filter((r) => r.meta.root !== true);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/features/commands.ts
|
|
332
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
333
|
+
import { basename as basename2 } from "path";
|
|
334
|
+
function parseCommands(commandsDir, packName) {
|
|
335
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
336
|
+
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
337
|
+
}
|
|
338
|
+
function parseCommandFile(filepath, packName) {
|
|
339
|
+
const raw = readFileSync4(filepath, "utf-8");
|
|
340
|
+
const { data, content } = parseFrontmatter(raw);
|
|
341
|
+
return {
|
|
342
|
+
name: basename2(filepath, ".md"),
|
|
343
|
+
sourcePath: filepath,
|
|
344
|
+
packName,
|
|
345
|
+
meta: data,
|
|
346
|
+
content
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function commandMatchesTarget(cmd, targetId) {
|
|
350
|
+
const { targets } = cmd.meta;
|
|
351
|
+
if (!targets || targets === "*")
|
|
352
|
+
return true;
|
|
353
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
354
|
+
return true;
|
|
355
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/features/agents.ts
|
|
359
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
360
|
+
import { basename as basename3 } from "path";
|
|
361
|
+
function parseAgents(agentsDir, packName) {
|
|
362
|
+
const files = listFiles(agentsDir, { extension: ".md" });
|
|
363
|
+
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
364
|
+
}
|
|
365
|
+
function parseAgentFile(filepath, packName) {
|
|
366
|
+
const raw = readFileSync5(filepath, "utf-8");
|
|
367
|
+
const { data, content } = parseFrontmatter(raw);
|
|
368
|
+
return {
|
|
369
|
+
name: data.name ?? basename3(filepath, ".md"),
|
|
370
|
+
sourcePath: filepath,
|
|
371
|
+
packName,
|
|
372
|
+
meta: data,
|
|
373
|
+
content
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function agentMatchesTarget(agent, targetId) {
|
|
377
|
+
const { targets } = agent.meta;
|
|
378
|
+
if (!targets || targets === "*")
|
|
379
|
+
return true;
|
|
380
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
381
|
+
return true;
|
|
382
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/features/skills.ts
|
|
386
|
+
import { readFileSync as readFileSync6, existsSync as existsSync3 } from "fs";
|
|
387
|
+
import { basename as basename4, join as join2 } from "path";
|
|
388
|
+
function parseSkills(skillsDir, packName) {
|
|
389
|
+
const dirs = listDirs(skillsDir);
|
|
390
|
+
const skills = [];
|
|
391
|
+
for (const dir of dirs) {
|
|
392
|
+
const skillMd = join2(dir, "SKILL.md");
|
|
393
|
+
if (existsSync3(skillMd)) {
|
|
394
|
+
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return skills;
|
|
398
|
+
}
|
|
399
|
+
function parseSkillFile(filepath, skillDir, packName) {
|
|
400
|
+
const raw = readFileSync6(filepath, "utf-8");
|
|
401
|
+
const { data, content } = parseFrontmatter(raw);
|
|
402
|
+
return {
|
|
403
|
+
name: data.name ?? basename4(skillDir),
|
|
404
|
+
sourcePath: filepath,
|
|
405
|
+
sourceDir: skillDir,
|
|
406
|
+
packName,
|
|
407
|
+
meta: data,
|
|
408
|
+
content
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function skillMatchesTarget(skill, targetId) {
|
|
412
|
+
const { targets } = skill.meta;
|
|
413
|
+
if (!targets || targets === "*")
|
|
414
|
+
return true;
|
|
415
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
416
|
+
return true;
|
|
417
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/features/hooks.ts
|
|
421
|
+
import { join as join3 } from "path";
|
|
422
|
+
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
423
|
+
function parseHooks(packDir, packName) {
|
|
424
|
+
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
425
|
+
const raw = readJsonOrNull(hooksPath);
|
|
426
|
+
if (!raw)
|
|
427
|
+
return null;
|
|
428
|
+
const shared = raw.hooks ?? {};
|
|
429
|
+
const targetOverrides = {};
|
|
430
|
+
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
431
|
+
const override = raw[key];
|
|
432
|
+
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
433
|
+
targetOverrides[key] = override.hooks;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
packName,
|
|
438
|
+
sourcePath: hooksPath,
|
|
439
|
+
version: raw.version,
|
|
440
|
+
shared,
|
|
441
|
+
targetOverrides
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function resolveHooksForTarget(hooks, targetId) {
|
|
445
|
+
const merged = {};
|
|
446
|
+
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
447
|
+
merged[event] = [...entries];
|
|
448
|
+
}
|
|
449
|
+
const overrides = hooks.targetOverrides[targetId];
|
|
450
|
+
if (overrides) {
|
|
451
|
+
for (const [event, entries] of Object.entries(overrides)) {
|
|
452
|
+
merged[event] = [...merged[event] ?? [], ...entries];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return merged;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/features/plugins.ts
|
|
459
|
+
import { readFileSync as readFileSync7, existsSync as existsSync4 } from "fs";
|
|
460
|
+
import { basename as basename5, join as join4 } from "path";
|
|
461
|
+
function parsePlugins(packDir, packName) {
|
|
462
|
+
const pluginsDir = join4(packDir, "plugins");
|
|
463
|
+
if (!existsSync4(pluginsDir))
|
|
464
|
+
return [];
|
|
465
|
+
const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
|
|
466
|
+
const jsFiles = listFiles(pluginsDir, { extension: ".js" });
|
|
467
|
+
const allFiles = [...tsFiles, ...jsFiles];
|
|
468
|
+
return allFiles.map((filepath) => parsePluginFile(filepath, packName));
|
|
469
|
+
}
|
|
470
|
+
function parsePluginFile(filepath, packName) {
|
|
471
|
+
const content = readFileSync7(filepath, "utf-8");
|
|
472
|
+
const ext = filepath.endsWith(".ts") ? "ts" : "js";
|
|
473
|
+
return {
|
|
474
|
+
name: basename5(filepath, `.${ext}`),
|
|
475
|
+
sourcePath: filepath,
|
|
476
|
+
packName,
|
|
477
|
+
content,
|
|
478
|
+
extension: ext
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/features/mcp.ts
|
|
483
|
+
import { join as join5 } from "path";
|
|
484
|
+
function parseMcp(packDir, packName) {
|
|
485
|
+
const mcpPath = join5(packDir, "mcp.json");
|
|
486
|
+
const raw = readJsonOrNull(mcpPath);
|
|
487
|
+
if (!raw?.mcpServers)
|
|
488
|
+
return null;
|
|
489
|
+
return {
|
|
490
|
+
packName,
|
|
491
|
+
sourcePath: mcpPath,
|
|
492
|
+
servers: raw.mcpServers
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function mergeMcpConfigs(configs) {
|
|
496
|
+
const servers = {};
|
|
497
|
+
const warnings = [];
|
|
498
|
+
for (const config of configs) {
|
|
499
|
+
for (const [name, entry] of Object.entries(config.servers)) {
|
|
500
|
+
if (name in servers) {
|
|
501
|
+
warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
servers[name] = entry;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return { servers, warnings };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/features/ignore.ts
|
|
511
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
512
|
+
import { join as join6 } from "path";
|
|
513
|
+
var IGNORE_FILES = ["ignore", ".aiignore"];
|
|
514
|
+
function parseIgnore(packDir, packName) {
|
|
515
|
+
for (const filename of IGNORE_FILES) {
|
|
516
|
+
const filepath = join6(packDir, filename);
|
|
517
|
+
if (existsSync5(filepath)) {
|
|
518
|
+
const raw = readFileSync8(filepath, "utf-8");
|
|
519
|
+
const patterns = parseIgnoreContent(raw);
|
|
520
|
+
return {
|
|
521
|
+
packName,
|
|
522
|
+
sourcePath: filepath,
|
|
523
|
+
patterns
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
function parseIgnoreContent(content) {
|
|
530
|
+
return content.split(`
|
|
531
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
532
|
+
}
|
|
533
|
+
function mergeIgnorePatterns(configs) {
|
|
534
|
+
const seen = new Set;
|
|
535
|
+
const result = [];
|
|
536
|
+
for (const config of configs) {
|
|
537
|
+
for (const pattern of config.patterns) {
|
|
538
|
+
if (!seen.has(pattern)) {
|
|
539
|
+
seen.add(pattern);
|
|
540
|
+
result.push(pattern);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/core/pack-loader.ts
|
|
548
|
+
init_config();
|
|
549
|
+
import { existsSync as existsSync6 } from "fs";
|
|
550
|
+
import { resolve as resolve3, isAbsolute } from "path";
|
|
551
|
+
class PackLoader {
|
|
552
|
+
projectRoot;
|
|
553
|
+
config;
|
|
554
|
+
constructor(projectRoot, config) {
|
|
555
|
+
this.projectRoot = projectRoot;
|
|
556
|
+
this.config = config;
|
|
557
|
+
}
|
|
558
|
+
loadAll() {
|
|
559
|
+
const warnings = [];
|
|
560
|
+
const packs = [];
|
|
561
|
+
const disabledSet = new Set(this.config.disabled);
|
|
562
|
+
for (const packRef of this.config.packs) {
|
|
563
|
+
const packDir = this.resolvePackPath(packRef);
|
|
564
|
+
if (!packDir) {
|
|
565
|
+
warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (!existsSync6(packDir)) {
|
|
569
|
+
warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
const manifest = loadPackManifest(packDir);
|
|
573
|
+
if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const loaded = this.loadPack(packDir, manifest);
|
|
577
|
+
packs.push(loaded);
|
|
578
|
+
}
|
|
579
|
+
return { packs, warnings };
|
|
580
|
+
}
|
|
581
|
+
loadPack(packDir, manifest) {
|
|
582
|
+
const name = manifest.name;
|
|
583
|
+
const rulesDir = resolve3(packDir, "rules");
|
|
584
|
+
const commandsDir = resolve3(packDir, "commands");
|
|
585
|
+
const agentsDir = resolve3(packDir, "agents");
|
|
586
|
+
const skillsDir = resolve3(packDir, "skills");
|
|
587
|
+
return {
|
|
588
|
+
manifest,
|
|
589
|
+
directory: packDir,
|
|
590
|
+
rules: existsSync6(rulesDir) ? parseRules(rulesDir, name) : [],
|
|
591
|
+
commands: existsSync6(commandsDir) ? parseCommands(commandsDir, name) : [],
|
|
592
|
+
agents: existsSync6(agentsDir) ? parseAgents(agentsDir, name) : [],
|
|
593
|
+
skills: existsSync6(skillsDir) ? parseSkills(skillsDir, name) : [],
|
|
594
|
+
hooks: parseHooks(packDir, name),
|
|
595
|
+
plugins: parsePlugins(packDir, name),
|
|
596
|
+
mcp: parseMcp(packDir, name),
|
|
597
|
+
ignore: parseIgnore(packDir, name)
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
loadForBaseDir(baseDir) {
|
|
601
|
+
const baseDirRoot = resolve3(this.projectRoot, baseDir);
|
|
602
|
+
const localConfigPath = resolve3(baseDirRoot, "agentpacks.jsonc");
|
|
603
|
+
if (!existsSync6(localConfigPath)) {
|
|
604
|
+
return { packs: [], warnings: [] };
|
|
605
|
+
}
|
|
606
|
+
const { loadWorkspaceConfig: loadWorkspaceConfig2 } = (init_config(), __toCommonJS(exports_config));
|
|
607
|
+
const localConfig = loadWorkspaceConfig2(baseDirRoot);
|
|
608
|
+
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
609
|
+
return loader.loadAll();
|
|
610
|
+
}
|
|
611
|
+
resolveCuratedPack(packRef) {
|
|
612
|
+
const curatedDir = resolve3(this.projectRoot, ".agentpacks", ".curated");
|
|
613
|
+
let packName = packRef;
|
|
614
|
+
if (packName.startsWith("npm:"))
|
|
615
|
+
packName = packName.slice(4);
|
|
616
|
+
if (packName.startsWith("github:"))
|
|
617
|
+
packName = packName.slice(7);
|
|
618
|
+
if (packName.startsWith("@"))
|
|
619
|
+
packName = packName.slice(1);
|
|
620
|
+
if (packName.includes("/")) {
|
|
621
|
+
const parts = packName.split("/");
|
|
622
|
+
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
623
|
+
}
|
|
624
|
+
packName = packName.split("@")[0].split(":")[0];
|
|
625
|
+
const resolved = resolve3(curatedDir, packName);
|
|
626
|
+
return existsSync6(resolved) ? resolved : null;
|
|
627
|
+
}
|
|
628
|
+
resolvePackPath(packRef) {
|
|
629
|
+
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
630
|
+
return resolve3(this.projectRoot, packRef);
|
|
631
|
+
}
|
|
632
|
+
if (isAbsolute(packRef)) {
|
|
633
|
+
return packRef;
|
|
634
|
+
}
|
|
635
|
+
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
636
|
+
return this.resolveCuratedPack(packRef);
|
|
637
|
+
}
|
|
638
|
+
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
639
|
+
return this.resolveCuratedPack(packRef);
|
|
640
|
+
}
|
|
641
|
+
return resolve3(this.projectRoot, packRef);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
export {
|
|
645
|
+
PackLoader
|
|
646
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LoadedPack } from '../core/pack-loader.js';
|
|
2
|
+
/**
|
|
3
|
+
* Cursor plugin manifest shape.
|
|
4
|
+
*/
|
|
5
|
+
interface CursorPluginManifest {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
description: string;
|
|
9
|
+
author?: string;
|
|
10
|
+
tags?: string[];
|
|
11
|
+
rules?: string[];
|
|
12
|
+
agents?: string[];
|
|
13
|
+
skills?: string[];
|
|
14
|
+
commands?: string[];
|
|
15
|
+
mcp?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Export result.
|
|
19
|
+
*/
|
|
20
|
+
export interface CursorPluginExportResult {
|
|
21
|
+
outputDir: string;
|
|
22
|
+
filesWritten: string[];
|
|
23
|
+
manifest: CursorPluginManifest;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Export a loaded pack as a Cursor plugin directory.
|
|
27
|
+
*/
|
|
28
|
+
export declare function exportCursorPlugin(pack: LoadedPack, outputDir: string): CursorPluginExportResult;
|
|
29
|
+
export {};
|