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.
Files changed (172) hide show
  1. package/dist/api.d.ts +32 -0
  2. package/dist/api.js +2852 -0
  3. package/dist/cli/export-cmd.d.ts +12 -0
  4. package/dist/cli/export-cmd.js +786 -0
  5. package/dist/cli/generate.d.ts +13 -0
  6. package/dist/cli/generate.js +2018 -0
  7. package/dist/cli/import-cmd.d.ts +9 -0
  8. package/dist/cli/import-cmd.js +691 -0
  9. package/dist/cli/init.d.ts +5 -0
  10. package/dist/cli/init.js +214 -0
  11. package/dist/cli/install.d.ts +11 -0
  12. package/dist/cli/install.js +610 -0
  13. package/dist/cli/pack/create.d.ts +4 -0
  14. package/dist/cli/pack/create.js +175 -0
  15. package/dist/cli/pack/enable.d.ts +8 -0
  16. package/dist/cli/pack/enable.js +96 -0
  17. package/dist/cli/pack/list.d.ts +4 -0
  18. package/dist/cli/pack/list.js +699 -0
  19. package/dist/cli/pack/validate.d.ts +4 -0
  20. package/dist/cli/pack/validate.js +364 -0
  21. package/dist/core/config.d.ts +77 -0
  22. package/dist/core/config.js +181 -0
  23. package/dist/core/dependency-resolver.d.ts +38 -0
  24. package/dist/core/dependency-resolver.js +151 -0
  25. package/dist/core/feature-merger.d.ts +61 -0
  26. package/dist/core/feature-merger.js +139 -0
  27. package/dist/core/index.d.ts +5 -0
  28. package/dist/core/index.js +924 -0
  29. package/dist/core/lockfile.d.ts +50 -0
  30. package/dist/core/lockfile.js +72 -0
  31. package/dist/core/metarepo.d.ts +26 -0
  32. package/dist/core/metarepo.js +218 -0
  33. package/dist/core/pack-loader.d.ts +61 -0
  34. package/dist/core/pack-loader.js +646 -0
  35. package/dist/exporters/cursor-plugin.d.ts +29 -0
  36. package/dist/exporters/cursor-plugin.js +258 -0
  37. package/dist/exporters/index.d.ts +1 -0
  38. package/dist/exporters/index.js +258 -0
  39. package/dist/features/agents.d.ts +48 -0
  40. package/dist/features/agents.js +190 -0
  41. package/dist/features/commands.d.ts +33 -0
  42. package/dist/features/commands.js +190 -0
  43. package/dist/features/hooks.d.ts +33 -0
  44. package/dist/features/hooks.js +182 -0
  45. package/dist/features/ignore.d.ts +21 -0
  46. package/dist/features/ignore.js +72 -0
  47. package/dist/features/index.d.ts +8 -0
  48. package/dist/features/index.js +426 -0
  49. package/dist/features/mcp.d.ts +34 -0
  50. package/dist/features/mcp.js +172 -0
  51. package/dist/features/plugins.d.ts +23 -0
  52. package/dist/features/plugins.js +168 -0
  53. package/dist/features/rules.d.ts +53 -0
  54. package/dist/features/rules.js +198 -0
  55. package/dist/features/skills.d.ts +42 -0
  56. package/dist/features/skills.js +198 -0
  57. package/dist/importers/claude-code.d.ts +5 -0
  58. package/dist/importers/claude-code.js +224 -0
  59. package/dist/importers/cursor.d.ts +5 -0
  60. package/dist/importers/cursor.js +288 -0
  61. package/dist/importers/opencode.d.ts +5 -0
  62. package/dist/importers/opencode.js +261 -0
  63. package/dist/importers/rulesync.d.ts +14 -0
  64. package/dist/importers/rulesync.js +280 -0
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.js +3464 -0
  67. package/dist/node/api.js +2852 -0
  68. package/dist/node/cli/export-cmd.js +786 -0
  69. package/dist/node/cli/generate.js +2018 -0
  70. package/dist/node/cli/import-cmd.js +691 -0
  71. package/dist/node/cli/init.js +214 -0
  72. package/dist/node/cli/install.js +610 -0
  73. package/dist/node/cli/pack/create.js +175 -0
  74. package/dist/node/cli/pack/enable.js +96 -0
  75. package/dist/node/cli/pack/list.js +699 -0
  76. package/dist/node/cli/pack/validate.js +364 -0
  77. package/dist/node/core/config.js +181 -0
  78. package/dist/node/core/dependency-resolver.js +151 -0
  79. package/dist/node/core/feature-merger.js +139 -0
  80. package/dist/node/core/index.js +924 -0
  81. package/dist/node/core/lockfile.js +72 -0
  82. package/dist/node/core/metarepo.js +218 -0
  83. package/dist/node/core/pack-loader.js +646 -0
  84. package/dist/node/exporters/cursor-plugin.js +258 -0
  85. package/dist/node/exporters/index.js +258 -0
  86. package/dist/node/features/agents.js +190 -0
  87. package/dist/node/features/commands.js +190 -0
  88. package/dist/node/features/hooks.js +182 -0
  89. package/dist/node/features/ignore.js +72 -0
  90. package/dist/node/features/index.js +426 -0
  91. package/dist/node/features/mcp.js +172 -0
  92. package/dist/node/features/plugins.js +168 -0
  93. package/dist/node/features/rules.js +198 -0
  94. package/dist/node/features/skills.js +198 -0
  95. package/dist/node/importers/claude-code.js +224 -0
  96. package/dist/node/importers/cursor.js +288 -0
  97. package/dist/node/importers/opencode.js +261 -0
  98. package/dist/node/importers/rulesync.js +280 -0
  99. package/dist/node/index.js +3464 -0
  100. package/dist/node/sources/git-ref.js +79 -0
  101. package/dist/node/sources/git.js +245 -0
  102. package/dist/node/sources/index.js +416 -0
  103. package/dist/node/sources/local.js +52 -0
  104. package/dist/node/sources/npm-ref.js +84 -0
  105. package/dist/node/sources/npm.js +211 -0
  106. package/dist/node/targets/additional-targets.js +428 -0
  107. package/dist/node/targets/agents-md.js +239 -0
  108. package/dist/node/targets/base-target.js +51 -0
  109. package/dist/node/targets/claude-code.js +490 -0
  110. package/dist/node/targets/codex-cli.js +297 -0
  111. package/dist/node/targets/copilot.js +390 -0
  112. package/dist/node/targets/cursor.js +441 -0
  113. package/dist/node/targets/gemini-cli.js +352 -0
  114. package/dist/node/targets/generic-md-target.js +319 -0
  115. package/dist/node/targets/index.js +1351 -0
  116. package/dist/node/targets/opencode.js +556 -0
  117. package/dist/node/targets/registry.js +1343 -0
  118. package/dist/node/utils/diff.js +144 -0
  119. package/dist/node/utils/filesystem.js +152 -0
  120. package/dist/node/utils/frontmatter.js +52 -0
  121. package/dist/node/utils/global.js +81 -0
  122. package/dist/node/utils/markdown.js +62 -0
  123. package/dist/sources/git-ref.d.ts +27 -0
  124. package/dist/sources/git-ref.js +79 -0
  125. package/dist/sources/git.d.ts +29 -0
  126. package/dist/sources/git.js +245 -0
  127. package/dist/sources/index.d.ts +5 -0
  128. package/dist/sources/index.js +416 -0
  129. package/dist/sources/local.d.ts +8 -0
  130. package/dist/sources/local.js +52 -0
  131. package/dist/sources/npm-ref.d.ts +30 -0
  132. package/dist/sources/npm-ref.js +84 -0
  133. package/dist/sources/npm.d.ts +20 -0
  134. package/dist/sources/npm.js +211 -0
  135. package/dist/targets/additional-targets.d.ts +65 -0
  136. package/dist/targets/additional-targets.js +428 -0
  137. package/dist/targets/agents-md.d.ts +13 -0
  138. package/dist/targets/agents-md.js +239 -0
  139. package/dist/targets/base-target.d.ts +61 -0
  140. package/dist/targets/base-target.js +51 -0
  141. package/dist/targets/claude-code.d.ts +13 -0
  142. package/dist/targets/claude-code.js +490 -0
  143. package/dist/targets/codex-cli.d.ts +12 -0
  144. package/dist/targets/codex-cli.js +297 -0
  145. package/dist/targets/copilot.d.ts +12 -0
  146. package/dist/targets/copilot.js +390 -0
  147. package/dist/targets/cursor.d.ts +13 -0
  148. package/dist/targets/cursor.js +441 -0
  149. package/dist/targets/gemini-cli.d.ts +12 -0
  150. package/dist/targets/gemini-cli.js +352 -0
  151. package/dist/targets/generic-md-target.d.ts +25 -0
  152. package/dist/targets/generic-md-target.js +319 -0
  153. package/dist/targets/index.d.ts +9 -0
  154. package/dist/targets/index.js +1351 -0
  155. package/dist/targets/opencode.d.ts +13 -0
  156. package/dist/targets/opencode.js +556 -0
  157. package/dist/targets/registry.d.ts +17 -0
  158. package/dist/targets/registry.js +1343 -0
  159. package/dist/utils/diff.d.ts +13 -0
  160. package/dist/utils/diff.js +144 -0
  161. package/dist/utils/filesystem.d.ts +49 -0
  162. package/dist/utils/filesystem.js +152 -0
  163. package/dist/utils/frontmatter.d.ts +19 -0
  164. package/dist/utils/frontmatter.js +52 -0
  165. package/dist/utils/global.d.ts +17 -0
  166. package/dist/utils/global.js +81 -0
  167. package/dist/utils/markdown.d.ts +20 -0
  168. package/dist/utils/markdown.js +62 -0
  169. package/package.json +808 -0
  170. package/templates/pack/pack.json +10 -0
  171. package/templates/pack/rules/overview.md +22 -0
  172. package/templates/workspace/agentpacks.jsonc +34 -0
@@ -0,0 +1,258 @@
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/exporters/cursor-plugin.ts
161
+ import { resolve as resolve2, join as join2 } from "path";
162
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
163
+ function exportCursorPlugin(pack, outputDir) {
164
+ const filesWritten = [];
165
+ const pluginDir = resolve2(outputDir, pack.manifest.name);
166
+ mkdirSync2(pluginDir, { recursive: true });
167
+ const manifest = {
168
+ name: pack.manifest.name,
169
+ version: pack.manifest.version,
170
+ description: pack.manifest.description
171
+ };
172
+ if (pack.manifest.author) {
173
+ manifest.author = typeof pack.manifest.author === "string" ? pack.manifest.author : pack.manifest.author.name;
174
+ }
175
+ if (pack.manifest.tags.length > 0) {
176
+ manifest.tags = pack.manifest.tags;
177
+ }
178
+ if (pack.rules.length > 0) {
179
+ const rulesDir = join2(pluginDir, "rules");
180
+ ensureDir(rulesDir);
181
+ manifest.rules = [];
182
+ for (const rule of pack.rules) {
183
+ const cursorMeta = rule.meta.cursor ?? {};
184
+ const fm = {
185
+ description: cursorMeta.description ?? rule.meta.description ?? "",
186
+ alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
187
+ };
188
+ const globs = cursorMeta.globs ?? rule.meta.globs;
189
+ if (globs)
190
+ fm.globs = globs;
191
+ const filename = `${rule.name}.mdc`;
192
+ const filepath = join2(rulesDir, filename);
193
+ writeFileSync2(filepath, serializeFrontmatter(fm, rule.content));
194
+ filesWritten.push(filepath);
195
+ manifest.rules.push(filename);
196
+ }
197
+ }
198
+ if (pack.agents.length > 0) {
199
+ const agentsDir = join2(pluginDir, "agents");
200
+ ensureDir(agentsDir);
201
+ manifest.agents = [];
202
+ for (const agent of pack.agents) {
203
+ const fm = {
204
+ name: agent.name,
205
+ description: agent.meta.description ?? ""
206
+ };
207
+ const filename = `${agent.name}.md`;
208
+ const filepath = join2(agentsDir, filename);
209
+ writeFileSync2(filepath, serializeFrontmatter(fm, agent.content));
210
+ filesWritten.push(filepath);
211
+ manifest.agents.push(filename);
212
+ }
213
+ }
214
+ if (pack.skills.length > 0) {
215
+ const skillsDir = join2(pluginDir, "skills");
216
+ ensureDir(skillsDir);
217
+ manifest.skills = [];
218
+ for (const skill of pack.skills) {
219
+ const skillSubDir = join2(skillsDir, skill.name);
220
+ ensureDir(skillSubDir);
221
+ const fm = {
222
+ name: skill.name,
223
+ description: skill.meta.description ?? ""
224
+ };
225
+ const filepath = join2(skillSubDir, "SKILL.md");
226
+ writeFileSync2(filepath, serializeFrontmatter(fm, skill.content));
227
+ filesWritten.push(filepath);
228
+ manifest.skills.push(skill.name);
229
+ }
230
+ }
231
+ if (pack.commands.length > 0) {
232
+ const commandsDir = join2(pluginDir, "commands");
233
+ ensureDir(commandsDir);
234
+ manifest.commands = [];
235
+ for (const cmd of pack.commands) {
236
+ const filename = `${cmd.name}.md`;
237
+ const filepath = join2(commandsDir, filename);
238
+ writeFileSync2(filepath, cmd.content);
239
+ filesWritten.push(filepath);
240
+ manifest.commands.push(filename);
241
+ }
242
+ }
243
+ if (pack.mcp && Object.keys(pack.mcp.servers).length > 0) {
244
+ manifest.mcp = true;
245
+ const filepath = join2(pluginDir, "mcp.json");
246
+ writeFileSync2(filepath, JSON.stringify({ mcpServers: pack.mcp.servers }, null, 2) + `
247
+ `);
248
+ filesWritten.push(filepath);
249
+ }
250
+ const manifestPath = join2(pluginDir, "manifest.json");
251
+ writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2) + `
252
+ `);
253
+ filesWritten.push(manifestPath);
254
+ return { outputDir: pluginDir, filesWritten, manifest };
255
+ }
256
+ export {
257
+ exportCursorPlugin
258
+ };
@@ -0,0 +1,258 @@
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/exporters/cursor-plugin.ts
161
+ import { resolve as resolve2, join as join2 } from "path";
162
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
163
+ function exportCursorPlugin(pack, outputDir) {
164
+ const filesWritten = [];
165
+ const pluginDir = resolve2(outputDir, pack.manifest.name);
166
+ mkdirSync2(pluginDir, { recursive: true });
167
+ const manifest = {
168
+ name: pack.manifest.name,
169
+ version: pack.manifest.version,
170
+ description: pack.manifest.description
171
+ };
172
+ if (pack.manifest.author) {
173
+ manifest.author = typeof pack.manifest.author === "string" ? pack.manifest.author : pack.manifest.author.name;
174
+ }
175
+ if (pack.manifest.tags.length > 0) {
176
+ manifest.tags = pack.manifest.tags;
177
+ }
178
+ if (pack.rules.length > 0) {
179
+ const rulesDir = join2(pluginDir, "rules");
180
+ ensureDir(rulesDir);
181
+ manifest.rules = [];
182
+ for (const rule of pack.rules) {
183
+ const cursorMeta = rule.meta.cursor ?? {};
184
+ const fm = {
185
+ description: cursorMeta.description ?? rule.meta.description ?? "",
186
+ alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
187
+ };
188
+ const globs = cursorMeta.globs ?? rule.meta.globs;
189
+ if (globs)
190
+ fm.globs = globs;
191
+ const filename = `${rule.name}.mdc`;
192
+ const filepath = join2(rulesDir, filename);
193
+ writeFileSync2(filepath, serializeFrontmatter(fm, rule.content));
194
+ filesWritten.push(filepath);
195
+ manifest.rules.push(filename);
196
+ }
197
+ }
198
+ if (pack.agents.length > 0) {
199
+ const agentsDir = join2(pluginDir, "agents");
200
+ ensureDir(agentsDir);
201
+ manifest.agents = [];
202
+ for (const agent of pack.agents) {
203
+ const fm = {
204
+ name: agent.name,
205
+ description: agent.meta.description ?? ""
206
+ };
207
+ const filename = `${agent.name}.md`;
208
+ const filepath = join2(agentsDir, filename);
209
+ writeFileSync2(filepath, serializeFrontmatter(fm, agent.content));
210
+ filesWritten.push(filepath);
211
+ manifest.agents.push(filename);
212
+ }
213
+ }
214
+ if (pack.skills.length > 0) {
215
+ const skillsDir = join2(pluginDir, "skills");
216
+ ensureDir(skillsDir);
217
+ manifest.skills = [];
218
+ for (const skill of pack.skills) {
219
+ const skillSubDir = join2(skillsDir, skill.name);
220
+ ensureDir(skillSubDir);
221
+ const fm = {
222
+ name: skill.name,
223
+ description: skill.meta.description ?? ""
224
+ };
225
+ const filepath = join2(skillSubDir, "SKILL.md");
226
+ writeFileSync2(filepath, serializeFrontmatter(fm, skill.content));
227
+ filesWritten.push(filepath);
228
+ manifest.skills.push(skill.name);
229
+ }
230
+ }
231
+ if (pack.commands.length > 0) {
232
+ const commandsDir = join2(pluginDir, "commands");
233
+ ensureDir(commandsDir);
234
+ manifest.commands = [];
235
+ for (const cmd of pack.commands) {
236
+ const filename = `${cmd.name}.md`;
237
+ const filepath = join2(commandsDir, filename);
238
+ writeFileSync2(filepath, cmd.content);
239
+ filesWritten.push(filepath);
240
+ manifest.commands.push(filename);
241
+ }
242
+ }
243
+ if (pack.mcp && Object.keys(pack.mcp.servers).length > 0) {
244
+ manifest.mcp = true;
245
+ const filepath = join2(pluginDir, "mcp.json");
246
+ writeFileSync2(filepath, JSON.stringify({ mcpServers: pack.mcp.servers }, null, 2) + `
247
+ `);
248
+ filesWritten.push(filepath);
249
+ }
250
+ const manifestPath = join2(pluginDir, "manifest.json");
251
+ writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2) + `
252
+ `);
253
+ filesWritten.push(manifestPath);
254
+ return { outputDir: pluginDir, filesWritten, manifest };
255
+ }
256
+ export {
257
+ exportCursorPlugin
258
+ };
@@ -0,0 +1,190 @@
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/agents.ts
161
+ import { readFileSync as readFileSync2 } from "fs";
162
+ import { basename } from "path";
163
+ function parseAgents(agentsDir, packName) {
164
+ const files = listFiles(agentsDir, { extension: ".md" });
165
+ return files.map((filepath) => parseAgentFile(filepath, packName));
166
+ }
167
+ function parseAgentFile(filepath, packName) {
168
+ const raw = readFileSync2(filepath, "utf-8");
169
+ const { data, content } = parseFrontmatter(raw);
170
+ return {
171
+ name: data.name ?? basename(filepath, ".md"),
172
+ sourcePath: filepath,
173
+ packName,
174
+ meta: data,
175
+ content
176
+ };
177
+ }
178
+ function agentMatchesTarget(agent, targetId) {
179
+ const { targets } = agent.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
+ export {
187
+ parseAgents,
188
+ parseAgentFile,
189
+ agentMatchesTarget
190
+ };