agentpacks 1.7.13 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/api.js +48 -3658
  2. package/dist/cli/export-cmd.js +7 -1027
  3. package/dist/cli/generate.js +39 -2731
  4. package/dist/cli/import-cmd.js +19 -770
  5. package/dist/cli/info.js +4 -231
  6. package/dist/cli/init.js +9 -185
  7. package/dist/cli/install.js +4 -902
  8. package/dist/cli/login.js +6 -201
  9. package/dist/cli/models-explain.js +14 -1266
  10. package/dist/cli/pack/create.js +4 -146
  11. package/dist/cli/pack/enable.js +2 -65
  12. package/dist/cli/pack/list.js +5 -893
  13. package/dist/cli/pack/validate.js +4 -642
  14. package/dist/cli/publish.js +8 -679
  15. package/dist/cli/search.js +4 -209
  16. package/dist/core/config.d.ts +1 -1
  17. package/dist/core/config.js +1 -145
  18. package/dist/core/dependency-resolver.js +1 -126
  19. package/dist/core/feature-merger.js +3 -398
  20. package/dist/core/index.js +5 -1129
  21. package/dist/core/lockfile.js +2 -43
  22. package/dist/core/metarepo.js +1 -183
  23. package/dist/core/pack-loader.js +4 -841
  24. package/dist/core/profile-resolver.js +1 -110
  25. package/dist/exporters/cursor-plugin.js +6 -404
  26. package/dist/exporters/index.js +6 -404
  27. package/dist/features/agents.js +3 -161
  28. package/dist/features/commands.js +3 -161
  29. package/dist/features/hooks.js +3 -153
  30. package/dist/features/ignore.js +2 -43
  31. package/dist/features/index.js +4 -629
  32. package/dist/features/mcp.js +3 -143
  33. package/dist/features/models.js +3 -292
  34. package/dist/features/plugins.js +3 -139
  35. package/dist/features/rules.d.ts +0 -1
  36. package/dist/features/rules.js +3 -169
  37. package/dist/features/skills.js +3 -228
  38. package/dist/importers/claude-code.js +6 -195
  39. package/dist/importers/cursor.js +5 -355
  40. package/dist/importers/opencode.js +6 -346
  41. package/dist/importers/rulesync.js +5 -365
  42. package/dist/index.js +89 -4934
  43. package/dist/node/api.js +48 -3659
  44. package/dist/node/cli/export-cmd.js +7 -1028
  45. package/dist/node/cli/generate.js +39 -2732
  46. package/dist/node/cli/import-cmd.js +19 -771
  47. package/dist/node/cli/info.js +4 -232
  48. package/dist/node/cli/init.js +9 -186
  49. package/dist/node/cli/install.js +4 -903
  50. package/dist/node/cli/login.js +6 -202
  51. package/dist/node/cli/models-explain.js +14 -1267
  52. package/dist/node/cli/pack/create.js +4 -147
  53. package/dist/node/cli/pack/enable.js +2 -66
  54. package/dist/node/cli/pack/list.js +5 -894
  55. package/dist/node/cli/pack/validate.js +4 -643
  56. package/dist/node/cli/publish.js +8 -680
  57. package/dist/node/cli/search.js +4 -210
  58. package/dist/node/core/config.js +1 -146
  59. package/dist/node/core/dependency-resolver.js +1 -127
  60. package/dist/node/core/feature-merger.js +3 -399
  61. package/dist/node/core/index.js +5 -1130
  62. package/dist/node/core/lockfile.js +2 -44
  63. package/dist/node/core/metarepo.js +1 -184
  64. package/dist/node/core/pack-loader.js +4 -842
  65. package/dist/node/core/profile-resolver.js +1 -111
  66. package/dist/node/exporters/cursor-plugin.js +6 -405
  67. package/dist/node/exporters/index.js +6 -405
  68. package/dist/node/features/agents.js +3 -162
  69. package/dist/node/features/commands.js +3 -162
  70. package/dist/node/features/hooks.js +3 -154
  71. package/dist/node/features/ignore.js +2 -44
  72. package/dist/node/features/index.js +4 -630
  73. package/dist/node/features/mcp.js +3 -144
  74. package/dist/node/features/models.js +3 -293
  75. package/dist/node/features/plugins.js +3 -140
  76. package/dist/node/features/rules.js +3 -170
  77. package/dist/node/features/skills.js +3 -229
  78. package/dist/node/importers/claude-code.js +6 -196
  79. package/dist/node/importers/cursor.js +5 -356
  80. package/dist/node/importers/opencode.js +6 -347
  81. package/dist/node/importers/rulesync.js +5 -366
  82. package/dist/node/index.js +89 -4935
  83. package/dist/node/sources/git-ref.js +1 -56
  84. package/dist/node/sources/git.js +2 -222
  85. package/dist/node/sources/index.js +4 -714
  86. package/dist/node/sources/local.js +1 -24
  87. package/dist/node/sources/npm-ref.js +1 -56
  88. package/dist/node/sources/npm.js +2 -184
  89. package/dist/node/sources/registry-ref.js +1 -37
  90. package/dist/node/sources/registry.js +4 -355
  91. package/dist/node/targets/additional-targets.js +6 -587
  92. package/dist/node/targets/base-target.js +1 -23
  93. package/dist/node/targets/claude-code.js +6 -714
  94. package/dist/node/targets/codex-cli.js +3 -324
  95. package/dist/node/targets/copilot.js +5 -603
  96. package/dist/node/targets/cursor.js +6 -700
  97. package/dist/node/targets/gemini-cli.js +10 -319
  98. package/dist/node/targets/generic-md-target.js +6 -478
  99. package/dist/node/targets/index.js +32 -1873
  100. package/dist/node/targets/mistral-vibe.js +7 -661
  101. package/dist/node/targets/opencode.js +13 -723
  102. package/dist/node/targets/registry.js +32 -1864
  103. package/dist/node/utils/credentials.js +3 -38
  104. package/dist/node/utils/diff.js +5 -132
  105. package/dist/node/utils/filesystem.js +3 -124
  106. package/dist/node/utils/frontmatter.js +1 -24
  107. package/dist/node/utils/global.js +1 -53
  108. package/dist/node/utils/markdown.js +3 -30
  109. package/dist/node/utils/model-allowlist.js +1 -126
  110. package/dist/node/utils/model-guidance.js +2 -78
  111. package/dist/node/utils/registry-client.js +1 -142
  112. package/dist/node/utils/tarball.js +1 -49
  113. package/dist/sources/git-ref.js +1 -55
  114. package/dist/sources/git.js +2 -221
  115. package/dist/sources/index.js +4 -713
  116. package/dist/sources/local.js +1 -23
  117. package/dist/sources/npm-ref.js +1 -55
  118. package/dist/sources/npm.js +2 -183
  119. package/dist/sources/registry-ref.js +1 -36
  120. package/dist/sources/registry.js +4 -354
  121. package/dist/targets/additional-targets.js +6 -586
  122. package/dist/targets/base-target.js +1 -22
  123. package/dist/targets/claude-code.js +6 -713
  124. package/dist/targets/codex-cli.js +3 -323
  125. package/dist/targets/copilot.js +5 -602
  126. package/dist/targets/cursor.js +6 -699
  127. package/dist/targets/gemini-cli.js +10 -318
  128. package/dist/targets/generic-md-target.js +6 -477
  129. package/dist/targets/index.d.ts +0 -1
  130. package/dist/targets/index.js +32 -1872
  131. package/dist/targets/mistral-vibe.js +7 -660
  132. package/dist/targets/opencode.js +13 -722
  133. package/dist/targets/registry.js +32 -1863
  134. package/dist/utils/credentials.js +3 -37
  135. package/dist/utils/diff.js +5 -131
  136. package/dist/utils/filesystem.js +3 -123
  137. package/dist/utils/frontmatter.js +1 -23
  138. package/dist/utils/global.js +1 -52
  139. package/dist/utils/markdown.js +3 -29
  140. package/dist/utils/model-allowlist.js +1 -125
  141. package/dist/utils/model-guidance.js +2 -77
  142. package/dist/utils/registry-client.js +1 -141
  143. package/dist/utils/tarball.js +1 -48
  144. package/package.json +4 -16
  145. package/dist/node/targets/agents-md.js +0 -211
  146. package/dist/targets/agents-md.d.ts +0 -13
  147. package/dist/targets/agents-md.js +0 -211
@@ -1,478 +1,6 @@
1
- import { createRequire } from "node:module";
2
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
-
4
- // src/utils/filesystem.ts
5
- import {
6
- existsSync,
7
- mkdirSync,
8
- readdirSync,
9
- readFileSync,
10
- rmSync,
11
- statSync,
12
- writeFileSync
13
- } from "fs";
14
- import { dirname, join, relative } from "path";
15
- var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
16
- var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
17
- var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
18
- function writeGeneratedFile(filepath, content, options = {}) {
19
- const { header = true, type } = options;
20
- const ext = type ?? inferFileType(filepath);
21
- ensureDir(dirname(filepath));
22
- let output = content;
23
- if (header) {
24
- const headerComment = getHeader(ext);
25
- if (headerComment) {
26
- output = `${headerComment}
27
- ${content}`;
28
- }
29
- }
30
- writeFileSync(filepath, output, "utf-8");
31
- }
32
- function writeGeneratedJson(filepath, data, options = {}) {
33
- const json = JSON.stringify(data, null, 2);
34
- writeGeneratedFile(filepath, json + `
35
- `, { ...options, type: "json" });
36
- }
37
- function readFileOrNull(filepath) {
38
- if (!existsSync(filepath))
39
- return null;
40
- return readFileSync(filepath, "utf-8");
41
- }
42
- function readJsonOrNull(filepath) {
43
- const content = readFileOrNull(filepath);
44
- if (content === null)
45
- return null;
46
- return JSON.parse(content);
47
- }
48
- function ensureDir(dirPath) {
49
- if (!existsSync(dirPath)) {
50
- mkdirSync(dirPath, { recursive: true });
51
- }
52
- }
53
- function removeIfExists(targetPath) {
54
- if (existsSync(targetPath)) {
55
- rmSync(targetPath, { recursive: true, force: true });
56
- }
57
- }
58
- function listFiles(dirPath, options = {}) {
59
- const { extension, recursive = false } = options;
60
- if (!existsSync(dirPath))
61
- return [];
62
- const results = [];
63
- const entries = readdirSync(dirPath);
64
- for (const entry of entries) {
65
- const fullPath = join(dirPath, entry);
66
- const stat = statSync(fullPath);
67
- if (stat.isDirectory() && recursive) {
68
- results.push(...listFiles(fullPath, options));
69
- } else if (stat.isFile()) {
70
- if (!extension || entry.endsWith(extension)) {
71
- results.push(fullPath);
72
- }
73
- }
74
- }
75
- return results;
76
- }
77
- function listDirs(dirPath) {
78
- if (!existsSync(dirPath))
79
- return [];
80
- return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
81
- }
82
- function relPath(projectRoot, filepath) {
83
- return relative(projectRoot, filepath);
84
- }
85
- function isGeneratedFile(filepath) {
86
- const content = readFileOrNull(filepath);
87
- if (!content)
88
- return false;
89
- return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
90
- }
91
- function inferFileType(filepath) {
92
- if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
93
- return "json";
94
- if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
95
- return "ts";
96
- if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
97
- return "js";
98
- return "md";
99
- }
100
- function getHeader(type) {
101
- switch (type) {
102
- case "md":
103
- return GENERATED_HEADER_MD;
104
- case "json":
105
- return GENERATED_HEADER_JSON;
106
- case "js":
107
- case "ts":
108
- return GENERATED_HEADER_JS;
109
- default:
110
- return null;
111
- }
112
- }
113
-
114
- // src/utils/frontmatter.ts
115
- import matter from "gray-matter";
116
- function parseFrontmatter(source) {
117
- const { data, content } = matter(source);
118
- return {
119
- data,
120
- content: content.trim(),
121
- raw: source
122
- };
123
- }
124
- function serializeFrontmatter(data, content) {
125
- const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
126
- if (Object.keys(filtered).length === 0) {
127
- return content;
128
- }
129
- return matter.stringify(content, filtered);
130
- }
131
-
132
- // src/features/commands.ts
133
- import { readFileSync as readFileSync2 } from "fs";
134
- import { basename } from "path";
135
- function parseCommands(commandsDir, packName) {
136
- const files = listFiles(commandsDir, { extension: ".md" });
137
- return files.map((filepath) => parseCommandFile(filepath, packName));
138
- }
139
- function parseCommandFile(filepath, packName) {
140
- const raw = readFileSync2(filepath, "utf-8");
141
- const { data, content } = parseFrontmatter(raw);
142
- return {
143
- name: basename(filepath, ".md"),
144
- sourcePath: filepath,
145
- packName,
146
- meta: data,
147
- content
148
- };
149
- }
150
- function commandMatchesTarget(cmd, targetId) {
151
- const { targets } = cmd.meta;
152
- if (!targets || targets === "*")
153
- return true;
154
- if (Array.isArray(targets) && targets.includes("*"))
155
- return true;
156
- return Array.isArray(targets) && targets.includes(targetId);
157
- }
158
-
159
- // src/features/rules.ts
160
- import { readFileSync as readFileSync3 } from "fs";
161
- import { basename as basename2 } from "path";
162
- function parseRules(rulesDir, packName) {
163
- const files = listFiles(rulesDir, { extension: ".md" });
164
- return files.map((filepath) => parseRuleFile(filepath, packName));
165
- }
166
- function parseRuleFile(filepath, packName) {
167
- const raw = readFileSync3(filepath, "utf-8");
168
- const { data, content } = parseFrontmatter(raw);
169
- return {
170
- name: basename2(filepath, ".md"),
171
- sourcePath: filepath,
172
- packName,
173
- meta: data,
174
- content
175
- };
176
- }
177
- function ruleMatchesTarget(rule, targetId) {
178
- const { targets } = rule.meta;
179
- if (!targets || targets === "*")
180
- return true;
181
- if (Array.isArray(targets) && targets.includes("*"))
182
- return true;
183
- return Array.isArray(targets) && targets.includes(targetId);
184
- }
185
- function getRootRules(rules) {
186
- return rules.filter((r) => r.meta.root === true);
187
- }
188
- function getDetailRules(rules) {
189
- return rules.filter((r) => r.meta.root !== true);
190
- }
191
-
192
- // src/core/profile-resolver.ts
193
- function resolveModels(merged, modelProfile, targetId) {
194
- let defaultModel = merged.default;
195
- let smallModel = merged.small;
196
- let agents = { ...merged.agents };
197
- if (modelProfile && merged.profiles?.[modelProfile]) {
198
- const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
199
- if (resolvedProfile.default)
200
- defaultModel = resolvedProfile.default;
201
- if (resolvedProfile.small)
202
- smallModel = resolvedProfile.small;
203
- if (resolvedProfile.agents) {
204
- agents = { ...agents, ...resolvedProfile.agents };
205
- }
206
- }
207
- if (targetId) {
208
- const targetOverride = merged.overrides?.[targetId];
209
- if (targetOverride) {
210
- if (targetOverride.default)
211
- defaultModel = targetOverride.default;
212
- if (targetOverride.small)
213
- smallModel = targetOverride.small;
214
- if (targetOverride.agents) {
215
- agents = { ...agents, ...targetOverride.agents };
216
- }
217
- }
218
- }
219
- const providers = {};
220
- if (merged.providers) {
221
- for (const [name, config] of Object.entries(merged.providers)) {
222
- providers[name] = {
223
- ...config.options ? { options: config.options } : {},
224
- ...config.models ? { models: config.models } : {}
225
- };
226
- }
227
- }
228
- const profileNames = Object.keys(merged.profiles ?? {});
229
- const profiles = {};
230
- if (merged.profiles) {
231
- for (const [name, profile] of Object.entries(merged.profiles)) {
232
- profiles[name] = {
233
- description: profile.description,
234
- default: profile.default,
235
- small: profile.small
236
- };
237
- }
238
- }
239
- return {
240
- default: defaultModel,
241
- small: smallModel,
242
- agents,
243
- providers,
244
- routing: merged.routing ?? [],
245
- profileNames,
246
- activeProfile: modelProfile,
247
- profiles
248
- };
249
- }
250
- function resolveAgentModel(resolved, agentName, frontmatterModel) {
251
- const fromModels = resolved.agents[agentName];
252
- if (fromModels) {
253
- return {
254
- model: fromModels.model,
255
- temperature: fromModels.temperature,
256
- top_p: fromModels.top_p
257
- };
258
- }
259
- if (frontmatterModel) {
260
- return { model: frontmatterModel };
261
- }
262
- return {};
263
- }
264
- function resolveProfileInheritance(profileName, profiles) {
265
- const visited = new Set;
266
- return resolveProfileChain(profileName, profiles, visited, 0);
267
- }
268
- var MAX_INHERITANCE_DEPTH = 10;
269
- function resolveProfileChain(name, profiles, visited, depth) {
270
- if (depth > MAX_INHERITANCE_DEPTH) {
271
- throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
272
- }
273
- if (visited.has(name)) {
274
- throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" → ")}`);
275
- }
276
- const profile = profiles[name];
277
- if (!profile) {
278
- throw new Error(`Profile "${name}" not found`);
279
- }
280
- visited.add(name);
281
- if (!profile.extends) {
282
- return { ...profile };
283
- }
284
- const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
285
- return {
286
- description: profile.description ?? parent.description,
287
- default: profile.default ?? parent.default,
288
- small: profile.small ?? parent.small,
289
- agents: {
290
- ...parent.agents,
291
- ...profile.agents
292
- }
293
- };
294
- }
295
-
296
- // src/utils/model-guidance.ts
297
- function generateModelGuidanceMarkdown(resolved) {
298
- if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0 && Object.keys(resolved.profiles).length === 0) {
299
- return null;
300
- }
301
- const lines = [];
302
- lines.push("# Model Configuration");
303
- lines.push("");
304
- lines.push("Use the following model preferences when working in this project.");
305
- lines.push("");
306
- if (resolved.default || resolved.small) {
307
- lines.push("## Default Models");
308
- lines.push("");
309
- if (resolved.default) {
310
- lines.push(`- **Primary model**: ${resolved.default}`);
311
- }
312
- if (resolved.small) {
313
- lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
314
- }
315
- lines.push("");
316
- }
317
- const agentEntries = Object.entries(resolved.agents);
318
- if (agentEntries.length > 0) {
319
- lines.push("## Agent Model Assignments");
320
- lines.push("");
321
- lines.push("| Agent | Model | Temperature |");
322
- lines.push("| --- | --- | --- |");
323
- for (const [name, assignment] of agentEntries) {
324
- const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "—";
325
- lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
326
- }
327
- lines.push("");
328
- }
329
- if (Object.keys(resolved.profiles).length > 0) {
330
- lines.push("## Available Profiles");
331
- lines.push("");
332
- lines.push("| Profile | Description | Default Model |");
333
- lines.push("| --- | --- | --- |");
334
- for (const [name, profile] of Object.entries(resolved.profiles)) {
335
- lines.push(`| ${name} | ${profile.description ?? "—"} | ${profile.default ?? "—"} |`);
336
- }
337
- lines.push("");
338
- }
339
- if (resolved.activeProfile) {
340
- lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
341
- lines.push("");
342
- }
343
- if (resolved.routing.length > 0) {
344
- lines.push("## Task-Aware Routing");
345
- lines.push("");
346
- lines.push("Select the appropriate profile based on the task context:");
347
- lines.push("");
348
- lines.push("| Condition | Profile | Description |");
349
- lines.push("| --- | --- | --- |");
350
- for (const rule of resolved.routing) {
351
- const conditions = Object.entries(rule.when).map(([k, v]) => `${k}=${v}`).join(", ");
352
- const desc = rule.description ?? "—";
353
- lines.push(`| ${conditions} | ${rule.use} | ${desc} |`);
354
- }
355
- lines.push("");
356
- lines.push("### Condition Reference");
357
- lines.push("");
358
- lines.push("- **complexity**: low | medium | high | critical");
359
- lines.push("- **urgency**: low | normal | high");
360
- lines.push("- **budget**: minimal | standard | premium");
361
- lines.push("- **contextWindowNeed**: small | medium | large | max");
362
- lines.push("- **toolUseIntensity**: none | light | heavy");
363
- lines.push("");
364
- }
365
- return lines.join(`
366
- `);
367
- }
368
-
369
- // src/targets/base-target.ts
370
- class BaseTarget {
371
- supportsFeature(feature) {
372
- return this.supportedFeatures.includes(feature);
373
- }
374
- getEffectiveFeatures(enabledFeatures) {
375
- return enabledFeatures.filter((f) => this.supportsFeature(f));
376
- }
377
- createResult(filesWritten = [], filesDeleted = [], warnings = []) {
378
- return {
379
- targetId: this.id,
380
- filesWritten,
381
- filesDeleted,
382
- warnings
383
- };
384
- }
385
- }
386
-
387
- // src/targets/generic-md-target.ts
388
- import { join as join2, resolve } from "path";
389
- function createGenericMdTarget(config) {
390
- return new GenericMdTarget(config);
391
- }
392
-
393
- class GenericMdTarget extends BaseTarget {
394
- id;
395
- name;
396
- supportedFeatures;
397
- config;
398
- constructor(config) {
399
- super();
400
- this.id = config.id;
401
- this.name = config.name;
402
- this.supportedFeatures = config.supportedFeatures;
403
- this.config = config;
404
- }
405
- generate(options) {
406
- const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
407
- const root = resolve(projectRoot, baseDir);
408
- const effective = this.getEffectiveFeatures(enabledFeatures);
409
- const filesWritten = [];
410
- const filesDeleted = [];
411
- const warnings = [];
412
- const configDir = resolve(root, this.config.configDir);
413
- const rulesSubDir = this.config.rulesDir ?? "rules";
414
- const ext = this.config.ruleExtension ?? ".md";
415
- if (effective.includes("rules")) {
416
- const rulesDir = resolve(configDir, rulesSubDir);
417
- if (deleteExisting) {
418
- removeIfExists(rulesDir);
419
- filesDeleted.push(rulesDir);
420
- }
421
- ensureDir(rulesDir);
422
- const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
423
- for (const rule of rules) {
424
- const filepath = join2(rulesDir, `${rule.name}${ext}`);
425
- writeGeneratedFile(filepath, rule.content);
426
- filesWritten.push(filepath);
427
- }
428
- }
429
- if (effective.includes("commands")) {
430
- const commandsDir = resolve(configDir, "commands");
431
- if (deleteExisting) {
432
- removeIfExists(commandsDir);
433
- filesDeleted.push(commandsDir);
434
- }
435
- ensureDir(commandsDir);
436
- const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
437
- for (const cmd of commands) {
438
- const filepath = join2(commandsDir, `${cmd.name}.md`);
439
- writeGeneratedFile(filepath, cmd.content);
440
- filesWritten.push(filepath);
441
- }
442
- }
443
- if (effective.includes("mcp")) {
444
- const mcpEntries = Object.entries(features.mcpServers);
445
- if (mcpEntries.length > 0) {
446
- const mcpDir = this.config.mcpInConfigDir ? configDir : root;
447
- const filepath = resolve(mcpDir, "mcp.json");
448
- writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
449
- header: false
450
- });
451
- filesWritten.push(filepath);
452
- }
453
- }
454
- if (effective.includes("ignore") && this.config.ignoreFile) {
455
- if (features.ignorePatterns.length > 0) {
456
- const filepath = resolve(root, this.config.ignoreFile);
457
- writeGeneratedFile(filepath, features.ignorePatterns.join(`
458
- `) + `
459
- `);
460
- filesWritten.push(filepath);
461
- }
462
- }
463
- if (effective.includes("models") && features.models) {
464
- const resolved = resolveModels(features.models, options.modelProfile, this.id);
465
- const guidance = generateModelGuidanceMarkdown(resolved);
466
- if (guidance) {
467
- ensureDir(configDir);
468
- const filepath = join2(configDir, "model-config.md");
469
- writeGeneratedFile(filepath, guidance);
470
- filesWritten.push(filepath);
471
- }
472
- }
473
- return this.createResult(filesWritten, filesDeleted, warnings);
474
- }
475
- }
476
- export {
477
- createGenericMdTarget
478
- };
1
+ import{createRequire as f}from"node:module";var Zq=f(import.meta.url);import{existsSync as x,mkdirSync as d,readdirSync as k,readFileSync as n,rmSync as o,statSync as A,writeFileSync as s}from"fs";import{dirname as a,join as R,relative as l}from"path";var S="<!-- Generated by agentpacks. DO NOT EDIT. -->",F="// Generated by agentpacks. DO NOT EDIT.",M="// Generated by agentpacks. DO NOT EDIT.";function O(q,K,L={}){let{header:Q=!0,type:V}=L,Z=V??i(q);I(a(q));let U=K;if(Q){let $=r(Z);if($)U=`${$}
2
+ ${K}`}s(q,U,"utf-8")}function N(q,K,L={}){let Q=JSON.stringify(K,null,2);O(q,Q+`
3
+ `,{...L,type:"json"})}function y(q){if(!x(q))return null;return n(q,"utf-8")}function Uq(q){let K=y(q);if(K===null)return null;return JSON.parse(K)}function I(q){if(!x(q))d(q,{recursive:!0})}function _(q){if(x(q))o(q,{recursive:!0,force:!0})}function G(q,K={}){let{extension:L,recursive:Q=!1}=K;if(!x(q))return[];let V=[],Z=k(q);for(let U of Z){let $=R(q,U),X=A($);if(X.isDirectory()&&Q)V.push(...G($,K));else if(X.isFile()){if(!L||U.endsWith(L))V.push($)}}return V}function Xq(q){if(!x(q))return[];return k(q).map((K)=>R(q,K)).filter((K)=>A(K).isDirectory())}function Jq(q,K){return l(q,K)}function Wq(q){let K=y(q);if(!K)return!1;return K.startsWith(S)||K.startsWith(F)||K.startsWith(M)}function i(q){if(q.endsWith(".json")||q.endsWith(".jsonc"))return"json";if(q.endsWith(".ts")||q.endsWith(".mts"))return"ts";if(q.endsWith(".js")||q.endsWith(".mjs"))return"js";return"md"}function r(q){switch(q){case"md":return S;case"json":return F;case"js":case"ts":return M;default:return null}}import E from"gray-matter";function T(q){let{data:K,content:L}=E(q);return{data:K,content:L.trim(),raw:q}}function Cq(q,K){let L=Object.fromEntries(Object.entries(q).filter(([,Q])=>Q!==void 0));if(Object.keys(L).length===0)return K;return E.stringify(K,L)}import{readFileSync as t}from"fs";import{basename as e}from"path";function _q(q,K){return G(q,{extension:".md"}).map((Q)=>qq(Q,K))}function qq(q,K){let L=t(q,"utf-8"),{data:Q,content:V}=T(L);return{name:e(q,".md"),sourcePath:q,packName:K,meta:Q,content:V}}function P(q,K){let{targets:L}=q.meta;if(!L||L==="*")return!0;if(Array.isArray(L)&&L.includes("*"))return!0;return Array.isArray(L)&&L.includes(K)}import{readFileSync as Kq}from"fs";import{basename as Lq}from"path";function Sq(q,K){return G(q,{extension:".md"}).map((Q)=>Qq(Q,K))}function Qq(q,K){let L=Kq(q,"utf-8"),{data:Q,content:V}=T(L);return{name:Lq(q,".md"),sourcePath:q,packName:K,meta:Q,content:V}}function D(q,K){let{targets:L}=q.meta;if(!L||L==="*")return!0;if(Array.isArray(L)&&L.includes("*"))return!0;return Array.isArray(L)&&L.includes(K)}function Fq(q){return q.filter((K)=>K.meta.root===!0)}function Mq(q){return q.filter((K)=>K.meta.root!==!0)}function v(q,K,L){let{default:Q,small:V}=q,Z={...q.agents};if(K&&q.profiles?.[K]){let Y=Vq(K,q.profiles);if(Y.default)Q=Y.default;if(Y.small)V=Y.small;if(Y.agents)Z={...Z,...Y.agents}}if(L){let Y=q.overrides?.[L];if(Y){if(Y.default)Q=Y.default;if(Y.small)V=Y.small;if(Y.agents)Z={...Z,...Y.agents}}}let U={};if(q.providers)for(let[Y,J]of Object.entries(q.providers))U[Y]={...J.options?{options:J.options}:{},...J.models?{models:J.models}:{}};let $=Object.keys(q.profiles??{}),X={};if(q.profiles)for(let[Y,J]of Object.entries(q.profiles))X[Y]={description:J.description,default:J.default,small:J.small};return{default:Q,small:V,agents:Z,providers:U,routing:q.routing??[],profileNames:$,activeProfile:K,profiles:X}}function yq(q,K,L){let Q=q.agents[K];if(Q)return{model:Q.model,temperature:Q.temperature,top_p:Q.top_p};if(L)return{model:L};return{}}function Vq(q,K){return h(q,K,new Set,0)}var u=10;function h(q,K,L,Q){if(Q>u)throw Error(`Profile inheritance too deep (max ${u}): ${q}`);if(L.has(q))throw Error(`Circular profile inheritance detected: ${[...L,q].join(" → ")}`);let V=K[q];if(!V)throw Error(`Profile "${q}" not found`);if(L.add(q),!V.extends)return{...V};let Z=h(V.extends,K,L,Q+1);return{description:V.description??Z.description,default:V.default??Z.default,small:V.small??Z.small,agents:{...Z.agents,...V.agents}}}function c(q){if(!q.default&&!q.small&&Object.keys(q.agents).length===0&&Object.keys(q.profiles).length===0)return null;let K=[];if(K.push("# Model Configuration"),K.push(""),K.push("Use the following model preferences when working in this project."),K.push(""),q.default||q.small){if(K.push("## Default Models"),K.push(""),q.default)K.push(`- **Primary model**: ${q.default}`);if(q.small)K.push(`- **Lightweight tasks** (titles, summaries): ${q.small}`);K.push("")}let L=Object.entries(q.agents);if(L.length>0){K.push("## Agent Model Assignments"),K.push(""),K.push("| Agent | Model | Temperature |"),K.push("| --- | --- | --- |");for(let[Q,V]of L){let Z=V.temperature!==void 0?String(V.temperature):"—";K.push(`| ${Q} | ${V.model} | ${Z} |`)}K.push("")}if(Object.keys(q.profiles).length>0){K.push("## Available Profiles"),K.push(""),K.push("| Profile | Description | Default Model |"),K.push("| --- | --- | --- |");for(let[Q,V]of Object.entries(q.profiles))K.push(`| ${Q} | ${V.description??"—"} | ${V.default??"—"} |`);K.push("")}if(q.activeProfile)K.push(`**Active profile**: \`${q.activeProfile}\``),K.push("");if(q.routing.length>0){K.push("## Task-Aware Routing"),K.push(""),K.push("Select the appropriate profile based on the task context:"),K.push(""),K.push("| Condition | Profile | Description |"),K.push("| --- | --- | --- |");for(let Q of q.routing){let V=Object.entries(Q.when).map(([U,$])=>`${U}=${$}`).join(", "),Z=Q.description??"—";K.push(`| ${V} | ${Q.use} | ${Z} |`)}K.push(""),K.push("### Condition Reference"),K.push(""),K.push("- **complexity**: low | medium | high | critical"),K.push("- **urgency**: low | normal | high"),K.push("- **budget**: minimal | standard | premium"),K.push("- **contextWindowNeed**: small | medium | large | max"),K.push("- **toolUseIntensity**: none | light | heavy"),K.push("")}return K.join(`
4
+ `)}class w{supportsFeature(q){return this.supportedFeatures.includes(q)}getEffectiveFeatures(q){return q.filter((K)=>this.supportsFeature(K))}createResult(q=[],K=[],L=[]){return{targetId:this.id,filesWritten:q,filesDeleted:K,warnings:L}}}import{join as j,resolve as b}from"path";function fq(q){return new g(q)}class g extends w{id;name;supportedFeatures;config;constructor(q){super();this.id=q.id,this.name=q.name,this.supportedFeatures=q.supportedFeatures,this.config=q}generate(q){let{projectRoot:K,baseDir:L,features:Q,enabledFeatures:V,deleteExisting:Z}=q,U=b(K,L),$=this.getEffectiveFeatures(V),X=[],Y=[],J=[],C=b(U,this.config.configDir),m=this.config.rulesDir??"rules",p=this.config.ruleExtension??".md";if($.includes("rules")){let z=b(C,m);if(Z)_(z),Y.push(z);I(z);let W=Q.rules.filter((B)=>D(B,this.id));for(let B of W){let H=j(z,`${B.name}${p}`);O(H,B.content),X.push(H)}}if($.includes("commands")){let z=b(C,"commands");if(Z)_(z),Y.push(z);I(z);let W=Q.commands.filter((B)=>P(B,this.id));for(let B of W){let H=j(z,`${B.name}.md`);O(H,B.content),X.push(H)}}if($.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let W=this.config.mcpInConfigDir?C:U,B=b(W,"mcp.json");N(B,{mcpServers:Q.mcpServers},{header:!1}),X.push(B)}}if($.includes("ignore")&&this.config.ignoreFile){if(Q.ignorePatterns.length>0){let z=b(U,this.config.ignoreFile);O(z,Q.ignorePatterns.join(`
5
+ `)+`
6
+ `),X.push(z)}}if($.includes("models")&&Q.models){let z=v(Q.models,q.modelProfile,this.id),W=c(z);if(W){I(C);let B=j(C,"model-config.md");O(B,W),X.push(B)}}return this.createResult(X,Y,J)}}export{fq as createGenericMdTarget};