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,364 @@
|
|
|
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/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/cli/pack/validate.ts
|
|
281
|
+
init_config();
|
|
282
|
+
import { existsSync as existsSync3 } from "fs";
|
|
283
|
+
import { resolve as resolve3, join as join2 } from "path";
|
|
284
|
+
import chalk from "chalk";
|
|
285
|
+
function runPackValidate(projectRoot) {
|
|
286
|
+
const config = loadWorkspaceConfig(projectRoot);
|
|
287
|
+
let hasErrors = false;
|
|
288
|
+
for (const packRef of config.packs) {
|
|
289
|
+
const packDir = resolvePackDir(projectRoot, packRef);
|
|
290
|
+
console.log(chalk.bold(`
|
|
291
|
+
Validating pack: ${packRef}`));
|
|
292
|
+
if (!packDir || !existsSync3(packDir)) {
|
|
293
|
+
console.log(chalk.red(` ERROR: Pack directory not found: ${packRef}`));
|
|
294
|
+
hasErrors = true;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const packJsonPath = resolve3(packDir, "pack.json");
|
|
298
|
+
if (!existsSync3(packJsonPath)) {
|
|
299
|
+
console.log(chalk.yellow(" warn: No pack.json found. Name will be inferred from directory."));
|
|
300
|
+
} else {
|
|
301
|
+
try {
|
|
302
|
+
loadPackManifest(packDir);
|
|
303
|
+
console.log(chalk.green(" pack.json: valid"));
|
|
304
|
+
} catch (err) {
|
|
305
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
306
|
+
console.log(chalk.red(` ERROR pack.json: ${message}`));
|
|
307
|
+
hasErrors = true;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const subdirs = ["rules", "commands", "agents", "skills"];
|
|
311
|
+
for (const sub of subdirs) {
|
|
312
|
+
const subDir = join2(packDir, sub);
|
|
313
|
+
if (existsSync3(subDir)) {
|
|
314
|
+
if (sub === "skills") {
|
|
315
|
+
const skillDirs = listDirs(subDir);
|
|
316
|
+
for (const skillDir of skillDirs) {
|
|
317
|
+
const skillMd = join2(skillDir, "SKILL.md");
|
|
318
|
+
if (!existsSync3(skillMd)) {
|
|
319
|
+
console.log(chalk.yellow(` warn: skills/${skillDir.split("/").pop()} missing SKILL.md`));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
console.log(chalk.green(` ${sub}/: ${skillDirs.length} skill(s)`));
|
|
323
|
+
} else {
|
|
324
|
+
const files = listFiles(subDir, { extension: ".md" });
|
|
325
|
+
console.log(chalk.green(` ${sub}/: ${files.length} file(s)`));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const optionalFiles = ["mcp.json", "ignore", ".aiignore"];
|
|
330
|
+
for (const file of optionalFiles) {
|
|
331
|
+
if (existsSync3(join2(packDir, file))) {
|
|
332
|
+
console.log(chalk.green(` ${file}: present`));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const hooksJson = join2(packDir, "hooks", "hooks.json");
|
|
336
|
+
if (existsSync3(hooksJson)) {
|
|
337
|
+
console.log(chalk.green(" hooks/hooks.json: present"));
|
|
338
|
+
}
|
|
339
|
+
const pluginsDir = join2(packDir, "plugins");
|
|
340
|
+
if (existsSync3(pluginsDir)) {
|
|
341
|
+
const pluginFiles = [
|
|
342
|
+
...listFiles(pluginsDir, { extension: ".ts" }),
|
|
343
|
+
...listFiles(pluginsDir, { extension: ".js" })
|
|
344
|
+
];
|
|
345
|
+
console.log(chalk.green(` plugins/: ${pluginFiles.length} file(s)`));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
console.log();
|
|
349
|
+
if (hasErrors) {
|
|
350
|
+
console.log(chalk.red("Validation failed with errors."));
|
|
351
|
+
process.exit(1);
|
|
352
|
+
} else {
|
|
353
|
+
console.log(chalk.green("All packs valid."));
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function resolvePackDir(projectRoot, packRef) {
|
|
357
|
+
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
358
|
+
return resolve3(projectRoot, packRef);
|
|
359
|
+
}
|
|
360
|
+
return resolve3(projectRoot, packRef);
|
|
361
|
+
}
|
|
362
|
+
export {
|
|
363
|
+
runPackValidate
|
|
364
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
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/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
|
+
init_config();
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
resolveTargets,
|
|
173
|
+
resolveFeatures,
|
|
174
|
+
loadWorkspaceConfig,
|
|
175
|
+
loadPackManifest,
|
|
176
|
+
WorkspaceConfigSchema,
|
|
177
|
+
TARGET_IDS,
|
|
178
|
+
REPO_MODES,
|
|
179
|
+
PackManifestSchema,
|
|
180
|
+
FEATURE_IDS
|
|
181
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
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/dependency-resolver.ts
|
|
33
|
+
function buildDependencyGraph(manifests) {
|
|
34
|
+
const graph = new Map;
|
|
35
|
+
for (const m of manifests) {
|
|
36
|
+
graph.set(m.name, {
|
|
37
|
+
name: m.name,
|
|
38
|
+
manifest: m,
|
|
39
|
+
dependencies: m.dependencies,
|
|
40
|
+
conflicts: m.conflicts
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return graph;
|
|
44
|
+
}
|
|
45
|
+
function resolveDependencies(manifests) {
|
|
46
|
+
const graph = buildDependencyGraph(manifests);
|
|
47
|
+
const allNames = new Set(graph.keys());
|
|
48
|
+
const missingDeps = [];
|
|
49
|
+
for (const [name, node] of graph) {
|
|
50
|
+
for (const dep of node.dependencies) {
|
|
51
|
+
if (!allNames.has(dep)) {
|
|
52
|
+
missingDeps.push([name, dep]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const { sorted, cycles } = topologicalSort(graph);
|
|
57
|
+
const conflictPairs = detectConflicts(graph);
|
|
58
|
+
const ok = cycles.length === 0 && conflictPairs.length === 0 && missingDeps.length === 0;
|
|
59
|
+
return { sorted, cycles, conflictPairs, missingDeps, ok };
|
|
60
|
+
}
|
|
61
|
+
function topologicalSort(graph) {
|
|
62
|
+
const inDegree = new Map;
|
|
63
|
+
for (const name of graph.keys()) {
|
|
64
|
+
inDegree.set(name, 0);
|
|
65
|
+
}
|
|
66
|
+
for (const [, node] of graph) {
|
|
67
|
+
for (const dep of node.dependencies) {
|
|
68
|
+
if (graph.has(dep)) {
|
|
69
|
+
inDegree.set(dep, (inDegree.get(dep) ?? 0) + 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const queue = [];
|
|
74
|
+
for (const [name, degree] of inDegree) {
|
|
75
|
+
if (degree === 0)
|
|
76
|
+
queue.push(name);
|
|
77
|
+
}
|
|
78
|
+
const sorted = [];
|
|
79
|
+
while (queue.length > 0) {
|
|
80
|
+
const current = queue.shift();
|
|
81
|
+
sorted.push(current);
|
|
82
|
+
const node = graph.get(current);
|
|
83
|
+
for (const dep of node.dependencies) {
|
|
84
|
+
if (!graph.has(dep))
|
|
85
|
+
continue;
|
|
86
|
+
const newDegree = (inDegree.get(dep) ?? 1) - 1;
|
|
87
|
+
inDegree.set(dep, newDegree);
|
|
88
|
+
if (newDegree === 0) {
|
|
89
|
+
queue.push(dep);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const cycles = [];
|
|
94
|
+
if (sorted.length < graph.size) {
|
|
95
|
+
const remaining = new Set;
|
|
96
|
+
for (const name of graph.keys()) {
|
|
97
|
+
if (!sorted.includes(name))
|
|
98
|
+
remaining.add(name);
|
|
99
|
+
}
|
|
100
|
+
const visited = new Set;
|
|
101
|
+
for (const start of remaining) {
|
|
102
|
+
if (visited.has(start))
|
|
103
|
+
continue;
|
|
104
|
+
const cycle = traceCycle(start, graph, remaining);
|
|
105
|
+
if (cycle.length > 0) {
|
|
106
|
+
cycles.push(cycle);
|
|
107
|
+
for (const n of cycle)
|
|
108
|
+
visited.add(n);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { sorted: sorted.reverse(), cycles };
|
|
113
|
+
}
|
|
114
|
+
function traceCycle(start, graph, remaining) {
|
|
115
|
+
const path = [];
|
|
116
|
+
const pathSet = new Set;
|
|
117
|
+
let current = start;
|
|
118
|
+
while (current && !pathSet.has(current)) {
|
|
119
|
+
path.push(current);
|
|
120
|
+
pathSet.add(current);
|
|
121
|
+
const node = graph.get(current);
|
|
122
|
+
if (!node)
|
|
123
|
+
break;
|
|
124
|
+
current = node.dependencies.find((d) => remaining.has(d) && graph.has(d));
|
|
125
|
+
}
|
|
126
|
+
if (current && pathSet.has(current)) {
|
|
127
|
+
const cycleStart = path.indexOf(current);
|
|
128
|
+
return path.slice(cycleStart);
|
|
129
|
+
}
|
|
130
|
+
return path;
|
|
131
|
+
}
|
|
132
|
+
function detectConflicts(graph) {
|
|
133
|
+
const conflicts = [];
|
|
134
|
+
const seen = new Set;
|
|
135
|
+
for (const [name, node] of graph) {
|
|
136
|
+
for (const conflict of node.conflicts) {
|
|
137
|
+
if (graph.has(conflict)) {
|
|
138
|
+
const key = [name, conflict].sort().join(":");
|
|
139
|
+
if (!seen.has(key)) {
|
|
140
|
+
seen.add(key);
|
|
141
|
+
conflicts.push([name, conflict]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return conflicts;
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
resolveDependencies,
|
|
150
|
+
buildDependencyGraph
|
|
151
|
+
};
|