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,211 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
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 = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
|
+
|
|
32
|
+
// src/core/lockfile.ts
|
|
33
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
34
|
+
import { resolve } from "path";
|
|
35
|
+
import { createHash } from "crypto";
|
|
36
|
+
var LOCKFILE_VERSION = 1;
|
|
37
|
+
var LOCKFILE_NAME = "agentpacks.lock";
|
|
38
|
+
function loadLockfile(projectRoot) {
|
|
39
|
+
const filepath = resolve(projectRoot, LOCKFILE_NAME);
|
|
40
|
+
if (!existsSync(filepath)) {
|
|
41
|
+
return { lockfileVersion: LOCKFILE_VERSION, sources: {} };
|
|
42
|
+
}
|
|
43
|
+
const raw = readFileSync(filepath, "utf-8");
|
|
44
|
+
return JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
function saveLockfile(projectRoot, lockfile) {
|
|
47
|
+
const filepath = resolve(projectRoot, LOCKFILE_NAME);
|
|
48
|
+
writeFileSync(filepath, JSON.stringify(lockfile, null, 2) + `
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
function getLockedSource(lockfile, sourceKey) {
|
|
52
|
+
return lockfile.sources[sourceKey];
|
|
53
|
+
}
|
|
54
|
+
function setLockedSource(lockfile, sourceKey, entry) {
|
|
55
|
+
lockfile.sources[sourceKey] = entry;
|
|
56
|
+
}
|
|
57
|
+
function computeIntegrity(content) {
|
|
58
|
+
const hash = createHash("sha256").update(content).digest("hex");
|
|
59
|
+
return `sha256-${hash}`;
|
|
60
|
+
}
|
|
61
|
+
function isLockfileFrozenValid(lockfile, sourceKeys) {
|
|
62
|
+
const missing = sourceKeys.filter((key) => !(key in lockfile.sources));
|
|
63
|
+
return { valid: missing.length === 0, missing };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/sources/npm-ref.ts
|
|
67
|
+
function parseNpmSourceRef(source) {
|
|
68
|
+
let s = source;
|
|
69
|
+
if (s.startsWith("npm:")) {
|
|
70
|
+
s = s.slice(4);
|
|
71
|
+
}
|
|
72
|
+
let path = "";
|
|
73
|
+
const pathColonIdx = findPathColon(s);
|
|
74
|
+
if (pathColonIdx > -1) {
|
|
75
|
+
path = s.slice(pathColonIdx + 1);
|
|
76
|
+
s = s.slice(0, pathColonIdx);
|
|
77
|
+
}
|
|
78
|
+
let version = "latest";
|
|
79
|
+
const versionAtIdx = findVersionAt(s);
|
|
80
|
+
if (versionAtIdx > -1) {
|
|
81
|
+
version = s.slice(versionAtIdx + 1);
|
|
82
|
+
s = s.slice(0, versionAtIdx);
|
|
83
|
+
}
|
|
84
|
+
if (!s) {
|
|
85
|
+
throw new Error(`Invalid npm source reference: "${source}". Expected package name.`);
|
|
86
|
+
}
|
|
87
|
+
return { packageName: s, version, path };
|
|
88
|
+
}
|
|
89
|
+
function findPathColon(s) {
|
|
90
|
+
const startAfter = s.startsWith("@") ? s.indexOf("/") + 1 : 0;
|
|
91
|
+
const vAt = findVersionAt(s);
|
|
92
|
+
const searchFrom = vAt > -1 ? vAt : startAfter;
|
|
93
|
+
return s.indexOf(":", searchFrom);
|
|
94
|
+
}
|
|
95
|
+
function findVersionAt(s) {
|
|
96
|
+
if (s.startsWith("@")) {
|
|
97
|
+
const slashIdx = s.indexOf("/");
|
|
98
|
+
if (slashIdx === -1)
|
|
99
|
+
return -1;
|
|
100
|
+
return s.indexOf("@", slashIdx + 1);
|
|
101
|
+
}
|
|
102
|
+
return s.indexOf("@");
|
|
103
|
+
}
|
|
104
|
+
function isNpmPackRef(packRef) {
|
|
105
|
+
if (packRef.startsWith("npm:"))
|
|
106
|
+
return true;
|
|
107
|
+
if (packRef.startsWith("@") && packRef.includes("/"))
|
|
108
|
+
return true;
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function npmSourceKey(parsed) {
|
|
112
|
+
return `npm:${parsed.packageName}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/sources/npm.ts
|
|
116
|
+
import { mkdirSync, existsSync as existsSync2 } from "fs";
|
|
117
|
+
import { resolve as resolve2, join } from "path";
|
|
118
|
+
import { execSync } from "child_process";
|
|
119
|
+
var NPM_REGISTRY = "https://registry.npmjs.org";
|
|
120
|
+
async function resolveNpmVersion(parsed) {
|
|
121
|
+
const url = `${NPM_REGISTRY}/${encodeURIComponent(parsed.packageName)}/${parsed.version}`;
|
|
122
|
+
const res = await fetch(url, {
|
|
123
|
+
headers: { Accept: "application/json" }
|
|
124
|
+
});
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
throw new Error(`Could not resolve npm package "${parsed.packageName}@${parsed.version}": ${res.status}`);
|
|
127
|
+
}
|
|
128
|
+
const data = await res.json();
|
|
129
|
+
return { version: data.version, tarball: data.dist.tarball };
|
|
130
|
+
}
|
|
131
|
+
async function installNpmSource(projectRoot, source, lockfile, options = {}) {
|
|
132
|
+
const parsed = parseNpmSourceRef(source);
|
|
133
|
+
const sourceKey = npmSourceKey(parsed);
|
|
134
|
+
const installed = [];
|
|
135
|
+
const warnings = [];
|
|
136
|
+
const locked = getLockedSource(lockfile, sourceKey);
|
|
137
|
+
if (options.frozen && !locked) {
|
|
138
|
+
throw new Error(`Frozen mode: no lockfile entry for source "${sourceKey}".`);
|
|
139
|
+
}
|
|
140
|
+
let resolvedVersion;
|
|
141
|
+
let tarballUrl;
|
|
142
|
+
if (locked && !options.update) {
|
|
143
|
+
resolvedVersion = locked.resolvedRef;
|
|
144
|
+
tarballUrl = "";
|
|
145
|
+
} else {
|
|
146
|
+
const resolved = await resolveNpmVersion(parsed);
|
|
147
|
+
resolvedVersion = resolved.version;
|
|
148
|
+
tarballUrl = resolved.tarball;
|
|
149
|
+
}
|
|
150
|
+
const curatedDir = resolve2(projectRoot, ".agentpacks", ".curated");
|
|
151
|
+
mkdirSync(curatedDir, { recursive: true });
|
|
152
|
+
const packDir = extractNpmPack(parsed, resolvedVersion, curatedDir, installed, warnings);
|
|
153
|
+
const newEntry = {
|
|
154
|
+
requestedRef: parsed.version,
|
|
155
|
+
resolvedRef: resolvedVersion,
|
|
156
|
+
resolvedAt: new Date().toISOString(),
|
|
157
|
+
skills: {},
|
|
158
|
+
packs: {}
|
|
159
|
+
};
|
|
160
|
+
setLockedSource(lockfile, sourceKey, newEntry);
|
|
161
|
+
return { installed, warnings };
|
|
162
|
+
}
|
|
163
|
+
function extractNpmPack(parsed, version, curatedDir, installed, warnings) {
|
|
164
|
+
const pkgSpec = `${parsed.packageName}@${version}`;
|
|
165
|
+
const packName = parsed.packageName.replace(/^@/, "").replace(/\//g, "-");
|
|
166
|
+
const packOutDir = resolve2(curatedDir, packName);
|
|
167
|
+
try {
|
|
168
|
+
const tmpDir = resolve2(curatedDir, ".tmp-npm");
|
|
169
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
170
|
+
execSync(`npm pack ${pkgSpec} --pack-destination "${tmpDir}"`, {
|
|
171
|
+
stdio: "pipe",
|
|
172
|
+
timeout: 30000
|
|
173
|
+
});
|
|
174
|
+
const tgzFiles = __require("fs").readdirSync(tmpDir).filter((f) => f.endsWith(".tgz"));
|
|
175
|
+
if (tgzFiles.length === 0) {
|
|
176
|
+
warnings.push(`No tarball found for ${pkgSpec}`);
|
|
177
|
+
return packOutDir;
|
|
178
|
+
}
|
|
179
|
+
const tgzPath = join(tmpDir, tgzFiles[0]);
|
|
180
|
+
mkdirSync(packOutDir, { recursive: true });
|
|
181
|
+
execSync(`tar xzf "${tgzPath}" -C "${packOutDir}" --strip-components=1`, {
|
|
182
|
+
stdio: "pipe",
|
|
183
|
+
timeout: 15000
|
|
184
|
+
});
|
|
185
|
+
execSync(`rm -rf "${tmpDir}"`, { stdio: "pipe" });
|
|
186
|
+
const subpath = parsed.path || "";
|
|
187
|
+
const targetDir = subpath ? join(packOutDir, subpath) : packOutDir;
|
|
188
|
+
if (existsSync2(targetDir)) {
|
|
189
|
+
collectFiles(targetDir, installed);
|
|
190
|
+
}
|
|
191
|
+
} catch (err) {
|
|
192
|
+
warnings.push(`Failed to extract npm pack ${pkgSpec}: ${err instanceof Error ? err.message : String(err)}`);
|
|
193
|
+
}
|
|
194
|
+
return packOutDir;
|
|
195
|
+
}
|
|
196
|
+
function collectFiles(dir, out) {
|
|
197
|
+
const fs = __require("fs");
|
|
198
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
199
|
+
for (const entry of entries) {
|
|
200
|
+
const full = join(dir, entry.name);
|
|
201
|
+
if (entry.isDirectory()) {
|
|
202
|
+
collectFiles(full, out);
|
|
203
|
+
} else {
|
|
204
|
+
out.push(full);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
resolveNpmVersion,
|
|
210
|
+
installNpmSource
|
|
211
|
+
};
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
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 = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
|
+
|
|
32
|
+
// src/utils/filesystem.ts
|
|
33
|
+
import {
|
|
34
|
+
existsSync,
|
|
35
|
+
mkdirSync,
|
|
36
|
+
readFileSync,
|
|
37
|
+
writeFileSync,
|
|
38
|
+
readdirSync,
|
|
39
|
+
statSync
|
|
40
|
+
} from "fs";
|
|
41
|
+
import { dirname, relative, join } from "path";
|
|
42
|
+
import { removeSync } from "fs-extra";
|
|
43
|
+
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
44
|
+
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
45
|
+
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
46
|
+
function writeGeneratedFile(filepath, content, options = {}) {
|
|
47
|
+
const { header = true, type } = options;
|
|
48
|
+
const ext = type ?? inferFileType(filepath);
|
|
49
|
+
ensureDir(dirname(filepath));
|
|
50
|
+
let output = content;
|
|
51
|
+
if (header) {
|
|
52
|
+
const headerComment = getHeader(ext);
|
|
53
|
+
if (headerComment) {
|
|
54
|
+
output = `${headerComment}
|
|
55
|
+
${content}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
writeFileSync(filepath, output, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
function writeGeneratedJson(filepath, data, options = {}) {
|
|
61
|
+
const json = JSON.stringify(data, null, 2);
|
|
62
|
+
writeGeneratedFile(filepath, json + `
|
|
63
|
+
`, { ...options, type: "json" });
|
|
64
|
+
}
|
|
65
|
+
function readFileOrNull(filepath) {
|
|
66
|
+
if (!existsSync(filepath))
|
|
67
|
+
return null;
|
|
68
|
+
return readFileSync(filepath, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
function readJsonOrNull(filepath) {
|
|
71
|
+
const content = readFileOrNull(filepath);
|
|
72
|
+
if (content === null)
|
|
73
|
+
return null;
|
|
74
|
+
return JSON.parse(content);
|
|
75
|
+
}
|
|
76
|
+
function ensureDir(dirPath) {
|
|
77
|
+
if (!existsSync(dirPath)) {
|
|
78
|
+
mkdirSync(dirPath, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function removeIfExists(targetPath) {
|
|
82
|
+
if (existsSync(targetPath)) {
|
|
83
|
+
removeSync(targetPath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function listFiles(dirPath, options = {}) {
|
|
87
|
+
const { extension, recursive = false } = options;
|
|
88
|
+
if (!existsSync(dirPath))
|
|
89
|
+
return [];
|
|
90
|
+
const results = [];
|
|
91
|
+
const entries = readdirSync(dirPath);
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const fullPath = join(dirPath, entry);
|
|
94
|
+
const stat = statSync(fullPath);
|
|
95
|
+
if (stat.isDirectory() && recursive) {
|
|
96
|
+
results.push(...listFiles(fullPath, options));
|
|
97
|
+
} else if (stat.isFile()) {
|
|
98
|
+
if (!extension || entry.endsWith(extension)) {
|
|
99
|
+
results.push(fullPath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
function listDirs(dirPath) {
|
|
106
|
+
if (!existsSync(dirPath))
|
|
107
|
+
return [];
|
|
108
|
+
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
109
|
+
}
|
|
110
|
+
function relPath(projectRoot, filepath) {
|
|
111
|
+
return relative(projectRoot, filepath);
|
|
112
|
+
}
|
|
113
|
+
function isGeneratedFile(filepath) {
|
|
114
|
+
const content = readFileOrNull(filepath);
|
|
115
|
+
if (!content)
|
|
116
|
+
return false;
|
|
117
|
+
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
118
|
+
}
|
|
119
|
+
function inferFileType(filepath) {
|
|
120
|
+
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
121
|
+
return "json";
|
|
122
|
+
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
123
|
+
return "ts";
|
|
124
|
+
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
125
|
+
return "js";
|
|
126
|
+
return "md";
|
|
127
|
+
}
|
|
128
|
+
function getHeader(type) {
|
|
129
|
+
switch (type) {
|
|
130
|
+
case "md":
|
|
131
|
+
return GENERATED_HEADER_MD;
|
|
132
|
+
case "json":
|
|
133
|
+
return GENERATED_HEADER_JSON;
|
|
134
|
+
case "js":
|
|
135
|
+
case "ts":
|
|
136
|
+
return GENERATED_HEADER_JS;
|
|
137
|
+
default:
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/frontmatter.ts
|
|
143
|
+
import matter from "gray-matter";
|
|
144
|
+
function parseFrontmatter(source) {
|
|
145
|
+
const { data, content } = matter(source);
|
|
146
|
+
return {
|
|
147
|
+
data,
|
|
148
|
+
content: content.trim(),
|
|
149
|
+
raw: source
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function serializeFrontmatter(data, content) {
|
|
153
|
+
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
154
|
+
if (Object.keys(filtered).length === 0) {
|
|
155
|
+
return content;
|
|
156
|
+
}
|
|
157
|
+
return matter.stringify(content, filtered);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/features/rules.ts
|
|
161
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
162
|
+
import { basename } from "path";
|
|
163
|
+
function parseRules(rulesDir, packName) {
|
|
164
|
+
const files = listFiles(rulesDir, { extension: ".md" });
|
|
165
|
+
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
166
|
+
}
|
|
167
|
+
function parseRuleFile(filepath, packName) {
|
|
168
|
+
const raw = readFileSync2(filepath, "utf-8");
|
|
169
|
+
const { data, content } = parseFrontmatter(raw);
|
|
170
|
+
return {
|
|
171
|
+
name: basename(filepath, ".md"),
|
|
172
|
+
sourcePath: filepath,
|
|
173
|
+
packName,
|
|
174
|
+
meta: data,
|
|
175
|
+
content
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function ruleMatchesTarget(rule, targetId) {
|
|
179
|
+
const { targets } = rule.meta;
|
|
180
|
+
if (!targets || targets === "*")
|
|
181
|
+
return true;
|
|
182
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
183
|
+
return true;
|
|
184
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
185
|
+
}
|
|
186
|
+
function getRootRules(rules) {
|
|
187
|
+
return rules.filter((r) => r.meta.root === true);
|
|
188
|
+
}
|
|
189
|
+
function getDetailRules(rules) {
|
|
190
|
+
return rules.filter((r) => r.meta.root !== true);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/features/commands.ts
|
|
194
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
195
|
+
import { basename as basename2 } from "path";
|
|
196
|
+
function parseCommands(commandsDir, packName) {
|
|
197
|
+
const files = listFiles(commandsDir, { extension: ".md" });
|
|
198
|
+
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
199
|
+
}
|
|
200
|
+
function parseCommandFile(filepath, packName) {
|
|
201
|
+
const raw = readFileSync3(filepath, "utf-8");
|
|
202
|
+
const { data, content } = parseFrontmatter(raw);
|
|
203
|
+
return {
|
|
204
|
+
name: basename2(filepath, ".md"),
|
|
205
|
+
sourcePath: filepath,
|
|
206
|
+
packName,
|
|
207
|
+
meta: data,
|
|
208
|
+
content
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function commandMatchesTarget(cmd, targetId) {
|
|
212
|
+
const { targets } = cmd.meta;
|
|
213
|
+
if (!targets || targets === "*")
|
|
214
|
+
return true;
|
|
215
|
+
if (Array.isArray(targets) && targets.includes("*"))
|
|
216
|
+
return true;
|
|
217
|
+
return Array.isArray(targets) && targets.includes(targetId);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/targets/base-target.ts
|
|
221
|
+
class BaseTarget {
|
|
222
|
+
supportsFeature(feature) {
|
|
223
|
+
return this.supportedFeatures.includes(feature);
|
|
224
|
+
}
|
|
225
|
+
getEffectiveFeatures(enabledFeatures) {
|
|
226
|
+
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
227
|
+
}
|
|
228
|
+
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
229
|
+
return {
|
|
230
|
+
targetId: this.id,
|
|
231
|
+
filesWritten,
|
|
232
|
+
filesDeleted,
|
|
233
|
+
warnings
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/targets/generic-md-target.ts
|
|
239
|
+
import { resolve as resolve2, join as join2 } from "path";
|
|
240
|
+
function createGenericMdTarget(config) {
|
|
241
|
+
return new GenericMdTarget(config);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
class GenericMdTarget extends BaseTarget {
|
|
245
|
+
id;
|
|
246
|
+
name;
|
|
247
|
+
supportedFeatures;
|
|
248
|
+
config;
|
|
249
|
+
constructor(config) {
|
|
250
|
+
super();
|
|
251
|
+
this.id = config.id;
|
|
252
|
+
this.name = config.name;
|
|
253
|
+
this.supportedFeatures = config.supportedFeatures;
|
|
254
|
+
this.config = config;
|
|
255
|
+
}
|
|
256
|
+
generate(options) {
|
|
257
|
+
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
258
|
+
const root = resolve2(projectRoot, baseDir);
|
|
259
|
+
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
260
|
+
const filesWritten = [];
|
|
261
|
+
const filesDeleted = [];
|
|
262
|
+
const warnings = [];
|
|
263
|
+
const configDir = resolve2(root, this.config.configDir);
|
|
264
|
+
const rulesSubDir = this.config.rulesDir ?? "rules";
|
|
265
|
+
const ext = this.config.ruleExtension ?? ".md";
|
|
266
|
+
if (effective.includes("rules")) {
|
|
267
|
+
const rulesDir = resolve2(configDir, rulesSubDir);
|
|
268
|
+
if (deleteExisting) {
|
|
269
|
+
removeIfExists(rulesDir);
|
|
270
|
+
filesDeleted.push(rulesDir);
|
|
271
|
+
}
|
|
272
|
+
ensureDir(rulesDir);
|
|
273
|
+
const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
|
|
274
|
+
for (const rule of rules) {
|
|
275
|
+
const filepath = join2(rulesDir, `${rule.name}${ext}`);
|
|
276
|
+
writeGeneratedFile(filepath, rule.content);
|
|
277
|
+
filesWritten.push(filepath);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (effective.includes("commands")) {
|
|
281
|
+
const commandsDir = resolve2(configDir, "commands");
|
|
282
|
+
if (deleteExisting) {
|
|
283
|
+
removeIfExists(commandsDir);
|
|
284
|
+
filesDeleted.push(commandsDir);
|
|
285
|
+
}
|
|
286
|
+
ensureDir(commandsDir);
|
|
287
|
+
const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
|
|
288
|
+
for (const cmd of commands) {
|
|
289
|
+
const filepath = join2(commandsDir, `${cmd.name}.md`);
|
|
290
|
+
writeGeneratedFile(filepath, cmd.content);
|
|
291
|
+
filesWritten.push(filepath);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (effective.includes("mcp")) {
|
|
295
|
+
const mcpEntries = Object.entries(features.mcpServers);
|
|
296
|
+
if (mcpEntries.length > 0) {
|
|
297
|
+
const mcpDir = this.config.mcpInConfigDir ? configDir : root;
|
|
298
|
+
const filepath = resolve2(mcpDir, "mcp.json");
|
|
299
|
+
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
300
|
+
header: false
|
|
301
|
+
});
|
|
302
|
+
filesWritten.push(filepath);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (effective.includes("ignore") && this.config.ignoreFile) {
|
|
306
|
+
if (features.ignorePatterns.length > 0) {
|
|
307
|
+
const filepath = resolve2(root, this.config.ignoreFile);
|
|
308
|
+
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
309
|
+
`) + `
|
|
310
|
+
`);
|
|
311
|
+
filesWritten.push(filepath);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/targets/additional-targets.ts
|
|
319
|
+
var ClineTarget = createGenericMdTarget({
|
|
320
|
+
id: "cline",
|
|
321
|
+
name: "Cline",
|
|
322
|
+
configDir: ".cline",
|
|
323
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
324
|
+
ignoreFile: ".clineignore",
|
|
325
|
+
mcpInConfigDir: true
|
|
326
|
+
});
|
|
327
|
+
var KiloTarget = createGenericMdTarget({
|
|
328
|
+
id: "kilo",
|
|
329
|
+
name: "Kilo Code",
|
|
330
|
+
configDir: ".kilo",
|
|
331
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
332
|
+
ignoreFile: ".kiloignore",
|
|
333
|
+
mcpInConfigDir: true
|
|
334
|
+
});
|
|
335
|
+
var RooTarget = createGenericMdTarget({
|
|
336
|
+
id: "roo",
|
|
337
|
+
name: "Roo Code",
|
|
338
|
+
configDir: ".roo",
|
|
339
|
+
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
340
|
+
ignoreFile: ".rooignore",
|
|
341
|
+
mcpInConfigDir: true
|
|
342
|
+
});
|
|
343
|
+
var QwenCodeTarget = createGenericMdTarget({
|
|
344
|
+
id: "qwencode",
|
|
345
|
+
name: "Qwen Code",
|
|
346
|
+
configDir: ".qwencode",
|
|
347
|
+
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
348
|
+
ignoreFile: ".qwencodeignore",
|
|
349
|
+
mcpInConfigDir: true
|
|
350
|
+
});
|
|
351
|
+
var KiroTarget = createGenericMdTarget({
|
|
352
|
+
id: "kiro",
|
|
353
|
+
name: "Kiro",
|
|
354
|
+
configDir: ".kiro",
|
|
355
|
+
supportedFeatures: ["rules", "mcp"],
|
|
356
|
+
mcpInConfigDir: true
|
|
357
|
+
});
|
|
358
|
+
var FactoryDroidTarget = createGenericMdTarget({
|
|
359
|
+
id: "factorydroid",
|
|
360
|
+
name: "Factory Droid",
|
|
361
|
+
configDir: ".factorydroid",
|
|
362
|
+
supportedFeatures: ["rules", "mcp"],
|
|
363
|
+
mcpInConfigDir: true
|
|
364
|
+
});
|
|
365
|
+
var AntiGravityTarget = createGenericMdTarget({
|
|
366
|
+
id: "antigravity",
|
|
367
|
+
name: "AntiGravity",
|
|
368
|
+
configDir: ".antigravity",
|
|
369
|
+
supportedFeatures: ["rules", "mcp"],
|
|
370
|
+
mcpInConfigDir: true
|
|
371
|
+
});
|
|
372
|
+
var JunieTarget = createGenericMdTarget({
|
|
373
|
+
id: "junie",
|
|
374
|
+
name: "Junie",
|
|
375
|
+
configDir: ".junie",
|
|
376
|
+
supportedFeatures: ["rules", "mcp"],
|
|
377
|
+
mcpInConfigDir: true
|
|
378
|
+
});
|
|
379
|
+
var AugmentCodeTarget = createGenericMdTarget({
|
|
380
|
+
id: "augmentcode",
|
|
381
|
+
name: "Augment Code",
|
|
382
|
+
configDir: ".augmentcode",
|
|
383
|
+
supportedFeatures: ["rules", "mcp"],
|
|
384
|
+
mcpInConfigDir: true
|
|
385
|
+
});
|
|
386
|
+
var WindsurfTarget = createGenericMdTarget({
|
|
387
|
+
id: "windsurf",
|
|
388
|
+
name: "Windsurf",
|
|
389
|
+
configDir: ".windsurf",
|
|
390
|
+
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
391
|
+
ignoreFile: ".windsurfignore",
|
|
392
|
+
mcpInConfigDir: true
|
|
393
|
+
});
|
|
394
|
+
var WarpTarget = createGenericMdTarget({
|
|
395
|
+
id: "warp",
|
|
396
|
+
name: "Warp",
|
|
397
|
+
configDir: ".warp",
|
|
398
|
+
supportedFeatures: ["rules"]
|
|
399
|
+
});
|
|
400
|
+
var ReplitTarget = createGenericMdTarget({
|
|
401
|
+
id: "replit",
|
|
402
|
+
name: "Replit Agent",
|
|
403
|
+
configDir: ".replit",
|
|
404
|
+
supportedFeatures: ["rules", "mcp"],
|
|
405
|
+
mcpInConfigDir: true
|
|
406
|
+
});
|
|
407
|
+
var ZedTarget = createGenericMdTarget({
|
|
408
|
+
id: "zed",
|
|
409
|
+
name: "Zed",
|
|
410
|
+
configDir: ".zed",
|
|
411
|
+
supportedFeatures: ["rules", "mcp"],
|
|
412
|
+
mcpInConfigDir: true
|
|
413
|
+
});
|
|
414
|
+
export {
|
|
415
|
+
ZedTarget,
|
|
416
|
+
WindsurfTarget,
|
|
417
|
+
WarpTarget,
|
|
418
|
+
RooTarget,
|
|
419
|
+
ReplitTarget,
|
|
420
|
+
QwenCodeTarget,
|
|
421
|
+
KiroTarget,
|
|
422
|
+
KiloTarget,
|
|
423
|
+
JunieTarget,
|
|
424
|
+
FactoryDroidTarget,
|
|
425
|
+
ClineTarget,
|
|
426
|
+
AugmentCodeTarget,
|
|
427
|
+
AntiGravityTarget
|
|
428
|
+
};
|