agentpacks 0.3.0 → 0.4.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 (166) hide show
  1. package/README.md +168 -8
  2. package/dist/api.d.ts +2 -0
  3. package/dist/api.js +929 -409
  4. package/dist/cli/export-cmd.js +281 -149
  5. package/dist/cli/generate.js +740 -247
  6. package/dist/cli/import-cmd.js +57 -85
  7. package/dist/cli/info.d.ts +4 -0
  8. package/dist/cli/info.js +232 -0
  9. package/dist/cli/init.js +8 -36
  10. package/dist/cli/install.js +414 -129
  11. package/dist/cli/login.d.ts +9 -0
  12. package/dist/cli/login.js +202 -0
  13. package/dist/cli/models-explain.d.ts +16 -0
  14. package/dist/cli/models-explain.js +1205 -0
  15. package/dist/cli/pack/create.js +4 -32
  16. package/dist/cli/pack/enable.js +1 -29
  17. package/dist/cli/pack/list.js +266 -134
  18. package/dist/cli/pack/validate.js +274 -127
  19. package/dist/cli/publish.d.ts +8 -0
  20. package/dist/cli/publish.js +672 -0
  21. package/dist/cli/search.d.ts +12 -0
  22. package/dist/cli/search.js +210 -0
  23. package/dist/core/config.d.ts +2 -1
  24. package/dist/core/config.js +74 -117
  25. package/dist/core/dependency-resolver.js +4 -28
  26. package/dist/core/feature-merger.d.ts +7 -0
  27. package/dist/core/feature-merger.js +289 -29
  28. package/dist/core/index.js +283 -140
  29. package/dist/core/lockfile.js +0 -28
  30. package/dist/core/metarepo.js +74 -116
  31. package/dist/core/pack-loader.d.ts +2 -0
  32. package/dist/core/pack-loader.js +266 -133
  33. package/dist/core/profile-resolver.d.ts +75 -0
  34. package/dist/core/profile-resolver.js +111 -0
  35. package/dist/exporters/cursor-plugin.js +4 -32
  36. package/dist/exporters/index.js +4 -32
  37. package/dist/features/agents.d.ts +5 -0
  38. package/dist/features/agents.js +2 -30
  39. package/dist/features/commands.js +2 -30
  40. package/dist/features/hooks.js +2 -30
  41. package/dist/features/ignore.js +0 -28
  42. package/dist/features/index.d.ts +1 -0
  43. package/dist/features/index.js +176 -31
  44. package/dist/features/mcp.js +2 -30
  45. package/dist/features/models.d.ts +167 -0
  46. package/dist/features/models.js +293 -0
  47. package/dist/features/plugins.js +2 -30
  48. package/dist/features/rules.js +2 -30
  49. package/dist/features/skills.js +2 -30
  50. package/dist/importers/claude-code.js +10 -38
  51. package/dist/importers/cursor.js +15 -43
  52. package/dist/importers/opencode.js +16 -44
  53. package/dist/importers/rulesync.js +22 -50
  54. package/dist/index.js +1710 -538
  55. package/dist/node/api.js +929 -409
  56. package/dist/node/cli/export-cmd.js +281 -149
  57. package/dist/node/cli/generate.js +740 -247
  58. package/dist/node/cli/import-cmd.js +57 -85
  59. package/dist/node/cli/info.js +232 -0
  60. package/dist/node/cli/init.js +8 -36
  61. package/dist/node/cli/install.js +414 -129
  62. package/dist/node/cli/login.js +202 -0
  63. package/dist/node/cli/models-explain.js +1205 -0
  64. package/dist/node/cli/pack/create.js +4 -32
  65. package/dist/node/cli/pack/enable.js +1 -29
  66. package/dist/node/cli/pack/list.js +266 -134
  67. package/dist/node/cli/pack/validate.js +274 -127
  68. package/dist/node/cli/publish.js +672 -0
  69. package/dist/node/cli/search.js +210 -0
  70. package/dist/node/core/config.js +74 -117
  71. package/dist/node/core/dependency-resolver.js +4 -28
  72. package/dist/node/core/feature-merger.js +289 -29
  73. package/dist/node/core/index.js +283 -140
  74. package/dist/node/core/lockfile.js +0 -28
  75. package/dist/node/core/metarepo.js +74 -116
  76. package/dist/node/core/pack-loader.js +266 -133
  77. package/dist/node/core/profile-resolver.js +111 -0
  78. package/dist/node/exporters/cursor-plugin.js +4 -32
  79. package/dist/node/exporters/index.js +4 -32
  80. package/dist/node/features/agents.js +2 -30
  81. package/dist/node/features/commands.js +2 -30
  82. package/dist/node/features/hooks.js +2 -30
  83. package/dist/node/features/ignore.js +0 -28
  84. package/dist/node/features/index.js +176 -31
  85. package/dist/node/features/mcp.js +2 -30
  86. package/dist/node/features/models.js +293 -0
  87. package/dist/node/features/plugins.js +2 -30
  88. package/dist/node/features/rules.js +2 -30
  89. package/dist/node/features/skills.js +2 -30
  90. package/dist/node/importers/claude-code.js +10 -38
  91. package/dist/node/importers/cursor.js +15 -43
  92. package/dist/node/importers/opencode.js +16 -44
  93. package/dist/node/importers/rulesync.js +22 -50
  94. package/dist/node/index.js +1710 -538
  95. package/dist/node/sources/git-ref.js +7 -30
  96. package/dist/node/sources/git.js +7 -30
  97. package/dist/node/sources/index.js +337 -39
  98. package/dist/node/sources/local.js +0 -28
  99. package/dist/node/sources/npm-ref.js +0 -28
  100. package/dist/node/sources/npm.js +10 -37
  101. package/dist/node/sources/registry-ref.js +37 -0
  102. package/dist/node/sources/registry.js +355 -0
  103. package/dist/node/targets/additional-targets.js +196 -37
  104. package/dist/node/targets/agents-md.js +5 -33
  105. package/dist/node/targets/base-target.js +0 -28
  106. package/dist/node/targets/claude-code.js +211 -41
  107. package/dist/node/targets/codex-cli.js +7 -35
  108. package/dist/node/targets/copilot.js +202 -41
  109. package/dist/node/targets/cursor.js +188 -40
  110. package/dist/node/targets/gemini-cli.js +10 -38
  111. package/dist/node/targets/generic-md-target.js +196 -37
  112. package/dist/node/targets/index.js +414 -106
  113. package/dist/node/targets/opencode.js +171 -51
  114. package/dist/node/targets/registry.js +414 -106
  115. package/dist/node/utils/credentials.js +38 -0
  116. package/dist/node/utils/diff.js +22 -34
  117. package/dist/node/utils/filesystem.js +2 -30
  118. package/dist/node/utils/frontmatter.js +0 -28
  119. package/dist/node/utils/global.js +3 -31
  120. package/dist/node/utils/markdown.js +0 -28
  121. package/dist/node/utils/model-allowlist.js +110 -0
  122. package/dist/node/utils/model-guidance.js +78 -0
  123. package/dist/node/utils/registry-client.js +142 -0
  124. package/dist/node/utils/tarball.js +49 -0
  125. package/dist/sources/git-ref.js +7 -30
  126. package/dist/sources/git.d.ts +2 -2
  127. package/dist/sources/git.js +7 -30
  128. package/dist/sources/index.d.ts +2 -0
  129. package/dist/sources/index.js +337 -39
  130. package/dist/sources/local.js +0 -28
  131. package/dist/sources/npm-ref.js +0 -28
  132. package/dist/sources/npm.js +10 -37
  133. package/dist/sources/registry-ref.d.ts +30 -0
  134. package/dist/sources/registry-ref.js +37 -0
  135. package/dist/sources/registry.d.ts +18 -0
  136. package/dist/sources/registry.js +355 -0
  137. package/dist/targets/additional-targets.js +196 -37
  138. package/dist/targets/agents-md.js +5 -33
  139. package/dist/targets/base-target.d.ts +2 -0
  140. package/dist/targets/base-target.js +0 -28
  141. package/dist/targets/claude-code.js +211 -41
  142. package/dist/targets/codex-cli.js +7 -35
  143. package/dist/targets/copilot.js +202 -41
  144. package/dist/targets/cursor.js +188 -40
  145. package/dist/targets/gemini-cli.js +10 -38
  146. package/dist/targets/generic-md-target.js +196 -37
  147. package/dist/targets/index.js +414 -106
  148. package/dist/targets/opencode.js +171 -51
  149. package/dist/targets/registry.js +414 -106
  150. package/dist/utils/credentials.d.ts +19 -0
  151. package/dist/utils/credentials.js +38 -0
  152. package/dist/utils/diff.js +22 -34
  153. package/dist/utils/filesystem.js +2 -30
  154. package/dist/utils/frontmatter.js +0 -28
  155. package/dist/utils/global.js +3 -31
  156. package/dist/utils/markdown.js +0 -28
  157. package/dist/utils/model-allowlist.d.ts +39 -0
  158. package/dist/utils/model-allowlist.js +110 -0
  159. package/dist/utils/model-guidance.d.ts +6 -0
  160. package/dist/utils/model-guidance.js +78 -0
  161. package/dist/utils/registry-client.d.ts +141 -0
  162. package/dist/utils/registry-client.js +142 -0
  163. package/dist/utils/tarball.d.ts +13 -0
  164. package/dist/utils/tarball.js +49 -0
  165. package/package.json +171 -5
  166. package/templates/pack/models.json +38 -0
@@ -0,0 +1,167 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Agent model assignment.
4
+ */
5
+ export declare const AgentModelSchema: z.ZodObject<{
6
+ model: z.ZodString;
7
+ temperature: z.ZodOptional<z.ZodNumber>;
8
+ top_p: z.ZodOptional<z.ZodNumber>;
9
+ }, z.core.$strip>;
10
+ export type AgentModel = z.infer<typeof AgentModelSchema>;
11
+ /**
12
+ * Model profile — a named preset for default/small model selection.
13
+ * Supports inheritance via `extends` to compose profiles.
14
+ */
15
+ export declare const ModelProfileSchema: z.ZodObject<{
16
+ extends: z.ZodOptional<z.ZodString>;
17
+ description: z.ZodOptional<z.ZodString>;
18
+ default: z.ZodOptional<z.ZodString>;
19
+ small: z.ZodOptional<z.ZodString>;
20
+ agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
21
+ model: z.ZodString;
22
+ temperature: z.ZodOptional<z.ZodNumber>;
23
+ top_p: z.ZodOptional<z.ZodNumber>;
24
+ }, z.core.$strip>>>;
25
+ }, z.core.$strip>;
26
+ export type ModelProfile = z.infer<typeof ModelProfileSchema>;
27
+ /**
28
+ * Structured routing condition — richer than simple key=value.
29
+ * Supports task complexity, urgency, budget, context needs, and tool usage.
30
+ */
31
+ export declare const RoutingConditionSchema: z.ZodObject<{
32
+ complexity: z.ZodOptional<z.ZodEnum<{
33
+ low: "low";
34
+ medium: "medium";
35
+ high: "high";
36
+ critical: "critical";
37
+ }>>;
38
+ urgency: z.ZodOptional<z.ZodEnum<{
39
+ low: "low";
40
+ high: "high";
41
+ normal: "normal";
42
+ }>>;
43
+ budget: z.ZodOptional<z.ZodEnum<{
44
+ minimal: "minimal";
45
+ standard: "standard";
46
+ premium: "premium";
47
+ }>>;
48
+ contextWindowNeed: z.ZodOptional<z.ZodEnum<{
49
+ small: "small";
50
+ medium: "medium";
51
+ large: "large";
52
+ max: "max";
53
+ }>>;
54
+ toolUseIntensity: z.ZodOptional<z.ZodEnum<{
55
+ none: "none";
56
+ light: "light";
57
+ heavy: "heavy";
58
+ }>>;
59
+ }, z.core.$strip>;
60
+ export type RoutingCondition = z.infer<typeof RoutingConditionSchema>;
61
+ /**
62
+ * Routing rule — maps task context to a profile.
63
+ *
64
+ * `when` accepts either:
65
+ * - Simple key=value pairs: `{ task: "review", language: "rust" }`
66
+ * - Structured conditions: `{ complexity: "high", budget: "premium" }`
67
+ * Both forms can be mixed.
68
+ */
69
+ export declare const RoutingRuleSchema: z.ZodObject<{
70
+ when: z.ZodRecord<z.ZodString, z.ZodString>;
71
+ use: z.ZodString;
72
+ description: z.ZodOptional<z.ZodString>;
73
+ priority: z.ZodOptional<z.ZodNumber>;
74
+ }, z.core.$strip>;
75
+ export type RoutingRule = z.infer<typeof RoutingRuleSchema>;
76
+ /**
77
+ * Provider model options/variants.
78
+ */
79
+ export declare const ProviderModelSchema: z.ZodObject<{
80
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
81
+ variants: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
82
+ }, z.core.$strip>;
83
+ export declare const ProviderConfigSchema: z.ZodObject<{
84
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
85
+ models: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
86
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
87
+ variants: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
88
+ }, z.core.$strip>>>;
89
+ }, z.core.$strip>;
90
+ export type ProviderConfig = z.infer<typeof ProviderConfigSchema>;
91
+ /**
92
+ * Full models.json schema for a pack.
93
+ */
94
+ export declare const ModelsSchema: z.ZodObject<{
95
+ default: z.ZodOptional<z.ZodString>;
96
+ small: z.ZodOptional<z.ZodString>;
97
+ agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
98
+ model: z.ZodString;
99
+ temperature: z.ZodOptional<z.ZodNumber>;
100
+ top_p: z.ZodOptional<z.ZodNumber>;
101
+ }, z.core.$strip>>>;
102
+ profiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
103
+ extends: z.ZodOptional<z.ZodString>;
104
+ description: z.ZodOptional<z.ZodString>;
105
+ default: z.ZodOptional<z.ZodString>;
106
+ small: z.ZodOptional<z.ZodString>;
107
+ agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
108
+ model: z.ZodString;
109
+ temperature: z.ZodOptional<z.ZodNumber>;
110
+ top_p: z.ZodOptional<z.ZodNumber>;
111
+ }, z.core.$strip>>>;
112
+ }, z.core.$strip>>>;
113
+ providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
114
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
115
+ models: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
116
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
117
+ variants: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
118
+ }, z.core.$strip>>>;
119
+ }, z.core.$strip>>>;
120
+ routing: z.ZodOptional<z.ZodArray<z.ZodObject<{
121
+ when: z.ZodRecord<z.ZodString, z.ZodString>;
122
+ use: z.ZodString;
123
+ description: z.ZodOptional<z.ZodString>;
124
+ priority: z.ZodOptional<z.ZodNumber>;
125
+ }, z.core.$strip>>>;
126
+ overrides: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
127
+ default: z.ZodOptional<z.ZodString>;
128
+ small: z.ZodOptional<z.ZodString>;
129
+ agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
130
+ model: z.ZodString;
131
+ temperature: z.ZodOptional<z.ZodNumber>;
132
+ top_p: z.ZodOptional<z.ZodNumber>;
133
+ }, z.core.$strip>>>;
134
+ }, z.core.$strip>>>;
135
+ }, z.core.$strip>;
136
+ export type ModelsConfig = z.infer<typeof ModelsSchema>;
137
+ /**
138
+ * Parsed models configuration from a pack.
139
+ */
140
+ export interface ParsedModels {
141
+ packName: string;
142
+ sourcePath: string;
143
+ config: ModelsConfig;
144
+ }
145
+ /**
146
+ * Parse models configuration from a pack's models.json file.
147
+ */
148
+ export declare function parseModels(packDir: string, packName: string): ParsedModels | null;
149
+ /**
150
+ * Merge multiple models configs.
151
+ * Strategy:
152
+ * - default, small: first-pack-wins
153
+ * - agents: merge by name, first-pack-wins per agent
154
+ * - profiles: additive (unique name), first-pack-wins on name conflict
155
+ * - providers: deep merge by provider key, first-pack-wins on scalar conflicts
156
+ * - routing: additive with original order preserved
157
+ * - overrides: first-pack-wins per target key
158
+ */
159
+ export declare function mergeModelsConfigs(configs: ParsedModels[]): {
160
+ config: ModelsConfig;
161
+ warnings: string[];
162
+ };
163
+ /**
164
+ * Scan a models config for potential secrets/credentials.
165
+ * Returns an array of warning messages for each detected secret.
166
+ */
167
+ export declare function scanModelsForSecrets(config: ModelsConfig): string[];
@@ -0,0 +1,293 @@
1
+ // @bun
2
+ var __require = import.meta.require;
3
+
4
+ // src/utils/filesystem.ts
5
+ import {
6
+ existsSync,
7
+ mkdirSync,
8
+ readFileSync,
9
+ writeFileSync,
10
+ readdirSync,
11
+ rmSync,
12
+ statSync
13
+ } from "fs";
14
+ import { dirname, relative, join } 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/features/models.ts
115
+ import { join as join2 } from "path";
116
+ import { z } from "zod";
117
+ var SECRET_PATTERNS = [
118
+ /["']api[_-]?key["']\s*:/i,
119
+ /["']apiKey["']\s*:/i,
120
+ /["']secret["']\s*:/i,
121
+ /["']password["']\s*:/i,
122
+ /["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
123
+ /["']private[_-]?key["']\s*:/i,
124
+ /-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
125
+ /sk-[a-zA-Z0-9]{20,}/,
126
+ /Bearer\s+[a-zA-Z0-9._-]{20,}/
127
+ ];
128
+ var AgentModelSchema = z.object({
129
+ model: z.string(),
130
+ temperature: z.number().min(0).max(2).optional(),
131
+ top_p: z.number().min(0).max(1).optional()
132
+ });
133
+ var ModelProfileSchema = z.object({
134
+ extends: z.string().optional(),
135
+ description: z.string().optional(),
136
+ default: z.string().optional(),
137
+ small: z.string().optional(),
138
+ agents: z.record(z.string(), AgentModelSchema).optional()
139
+ });
140
+ var RoutingConditionSchema = z.object({
141
+ complexity: z.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
142
+ urgency: z.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
143
+ budget: z.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
144
+ contextWindowNeed: z.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
145
+ toolUseIntensity: z.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
146
+ });
147
+ var RoutingRuleSchema = z.object({
148
+ when: z.record(z.string(), z.string()),
149
+ use: z.string(),
150
+ description: z.string().optional(),
151
+ priority: z.number().optional()
152
+ });
153
+ var ProviderModelSchema = z.object({
154
+ options: z.record(z.string(), z.unknown()).optional(),
155
+ variants: z.record(z.string(), z.record(z.string(), z.unknown())).optional()
156
+ });
157
+ var ProviderConfigSchema = z.object({
158
+ options: z.record(z.string(), z.unknown()).optional(),
159
+ models: z.record(z.string(), ProviderModelSchema).optional()
160
+ });
161
+ var ModelsSchema = z.object({
162
+ default: z.string().optional(),
163
+ small: z.string().optional(),
164
+ agents: z.record(z.string(), AgentModelSchema).optional(),
165
+ profiles: z.record(z.string(), ModelProfileSchema).optional(),
166
+ providers: z.record(z.string(), ProviderConfigSchema).optional(),
167
+ routing: z.array(RoutingRuleSchema).optional(),
168
+ overrides: z.record(z.string(), z.object({
169
+ default: z.string().optional(),
170
+ small: z.string().optional(),
171
+ agents: z.record(z.string(), AgentModelSchema).optional()
172
+ })).optional()
173
+ });
174
+ function parseModels(packDir, packName) {
175
+ const modelsPath = join2(packDir, "models.json");
176
+ const raw = readJsonOrNull(modelsPath);
177
+ if (!raw)
178
+ return null;
179
+ const parsed = ModelsSchema.parse(raw);
180
+ return {
181
+ packName,
182
+ sourcePath: modelsPath,
183
+ config: parsed
184
+ };
185
+ }
186
+ function mergeModelsConfigs(configs) {
187
+ const warnings = [];
188
+ const result = {};
189
+ for (const entry of configs) {
190
+ const { config, packName } = entry;
191
+ if (config.default !== undefined && result.default === undefined) {
192
+ result.default = config.default;
193
+ } else if (config.default !== undefined && result.default !== undefined) {
194
+ warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
195
+ }
196
+ if (config.small !== undefined && result.small === undefined) {
197
+ result.small = config.small;
198
+ } else if (config.small !== undefined && result.small !== undefined) {
199
+ warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
200
+ }
201
+ if (config.agents) {
202
+ if (!result.agents)
203
+ result.agents = {};
204
+ for (const [name, assignment] of Object.entries(config.agents)) {
205
+ if (name in result.agents) {
206
+ warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
207
+ continue;
208
+ }
209
+ result.agents[name] = assignment;
210
+ }
211
+ }
212
+ if (config.profiles) {
213
+ if (!result.profiles)
214
+ result.profiles = {};
215
+ for (const [name, profile] of Object.entries(config.profiles)) {
216
+ if (name in result.profiles) {
217
+ warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
218
+ continue;
219
+ }
220
+ result.profiles[name] = profile;
221
+ }
222
+ }
223
+ if (config.providers) {
224
+ if (!result.providers)
225
+ result.providers = {};
226
+ for (const [providerName, providerConfig] of Object.entries(config.providers)) {
227
+ if (!(providerName in result.providers)) {
228
+ result.providers[providerName] = providerConfig;
229
+ } else {
230
+ const existing = result.providers[providerName];
231
+ if (!existing) {
232
+ result.providers[providerName] = providerConfig;
233
+ continue;
234
+ }
235
+ if (providerConfig.options) {
236
+ existing.options = {
237
+ ...providerConfig.options,
238
+ ...existing.options
239
+ };
240
+ }
241
+ if (providerConfig.models) {
242
+ if (!existing.models)
243
+ existing.models = {};
244
+ for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
245
+ if (!(modelName in existing.models)) {
246
+ existing.models[modelName] = modelConfig;
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ if (config.routing) {
254
+ if (!result.routing)
255
+ result.routing = [];
256
+ result.routing.push(...config.routing);
257
+ }
258
+ if (config.overrides) {
259
+ if (!result.overrides)
260
+ result.overrides = {};
261
+ for (const [targetId, override] of Object.entries(config.overrides)) {
262
+ if (targetId in result.overrides) {
263
+ warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
264
+ continue;
265
+ }
266
+ result.overrides[targetId] = override;
267
+ }
268
+ }
269
+ }
270
+ return { config: result, warnings };
271
+ }
272
+ function scanModelsForSecrets(config) {
273
+ const warnings = [];
274
+ const json = JSON.stringify(config);
275
+ for (const pattern of SECRET_PATTERNS) {
276
+ if (pattern.test(json)) {
277
+ warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
278
+ }
279
+ }
280
+ return warnings;
281
+ }
282
+ export {
283
+ scanModelsForSecrets,
284
+ parseModels,
285
+ mergeModelsConfigs,
286
+ RoutingRuleSchema,
287
+ RoutingConditionSchema,
288
+ ProviderModelSchema,
289
+ ProviderConfigSchema,
290
+ ModelsSchema,
291
+ ModelProfileSchema,
292
+ AgentModelSchema
293
+ };
@@ -1,32 +1,4 @@
1
1
  // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __moduleCache = /* @__PURE__ */ new WeakMap;
7
- var __toCommonJS = (from) => {
8
- var entry = __moduleCache.get(from), desc;
9
- if (entry)
10
- return entry;
11
- entry = __defProp({}, "__esModule", { value: true });
12
- if (from && typeof from === "object" || typeof from === "function")
13
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- }));
17
- __moduleCache.set(from, entry);
18
- return entry;
19
- };
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, {
23
- get: all[name],
24
- enumerable: true,
25
- configurable: true,
26
- set: (newValue) => all[name] = () => newValue
27
- });
28
- };
29
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
2
  var __require = import.meta.require;
31
3
 
32
4
  // src/utils/filesystem.ts
@@ -36,10 +8,10 @@ import {
36
8
  readFileSync,
37
9
  writeFileSync,
38
10
  readdirSync,
11
+ rmSync,
39
12
  statSync
40
13
  } from "fs";
41
14
  import { dirname, relative, join } from "path";
42
- import { removeSync } from "fs-extra";
43
15
  var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
44
16
  var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
45
17
  var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
@@ -80,7 +52,7 @@ function ensureDir(dirPath) {
80
52
  }
81
53
  function removeIfExists(targetPath) {
82
54
  if (existsSync(targetPath)) {
83
- removeSync(targetPath);
55
+ rmSync(targetPath, { recursive: true, force: true });
84
56
  }
85
57
  }
86
58
  function listFiles(dirPath, options = {}) {
@@ -1,32 +1,4 @@
1
1
  // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __moduleCache = /* @__PURE__ */ new WeakMap;
7
- var __toCommonJS = (from) => {
8
- var entry = __moduleCache.get(from), desc;
9
- if (entry)
10
- return entry;
11
- entry = __defProp({}, "__esModule", { value: true });
12
- if (from && typeof from === "object" || typeof from === "function")
13
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- }));
17
- __moduleCache.set(from, entry);
18
- return entry;
19
- };
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, {
23
- get: all[name],
24
- enumerable: true,
25
- configurable: true,
26
- set: (newValue) => all[name] = () => newValue
27
- });
28
- };
29
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
2
  var __require = import.meta.require;
31
3
 
32
4
  // src/utils/filesystem.ts
@@ -36,10 +8,10 @@ import {
36
8
  readFileSync,
37
9
  writeFileSync,
38
10
  readdirSync,
11
+ rmSync,
39
12
  statSync
40
13
  } from "fs";
41
14
  import { dirname, relative, join } from "path";
42
- import { removeSync } from "fs-extra";
43
15
  var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
44
16
  var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
45
17
  var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
@@ -80,7 +52,7 @@ function ensureDir(dirPath) {
80
52
  }
81
53
  function removeIfExists(targetPath) {
82
54
  if (existsSync(targetPath)) {
83
- removeSync(targetPath);
55
+ rmSync(targetPath, { recursive: true, force: true });
84
56
  }
85
57
  }
86
58
  function listFiles(dirPath, options = {}) {
@@ -1,32 +1,4 @@
1
1
  // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __moduleCache = /* @__PURE__ */ new WeakMap;
7
- var __toCommonJS = (from) => {
8
- var entry = __moduleCache.get(from), desc;
9
- if (entry)
10
- return entry;
11
- entry = __defProp({}, "__esModule", { value: true });
12
- if (from && typeof from === "object" || typeof from === "function")
13
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- }));
17
- __moduleCache.set(from, entry);
18
- return entry;
19
- };
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, {
23
- get: all[name],
24
- enumerable: true,
25
- configurable: true,
26
- set: (newValue) => all[name] = () => newValue
27
- });
28
- };
29
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
2
  var __require = import.meta.require;
31
3
 
32
4
  // src/utils/filesystem.ts
@@ -36,10 +8,10 @@ import {
36
8
  readFileSync,
37
9
  writeFileSync,
38
10
  readdirSync,
11
+ rmSync,
39
12
  statSync
40
13
  } from "fs";
41
14
  import { dirname, relative, join } from "path";
42
- import { removeSync } from "fs-extra";
43
15
  var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
44
16
  var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
45
17
  var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
@@ -80,7 +52,7 @@ function ensureDir(dirPath) {
80
52
  }
81
53
  function removeIfExists(targetPath) {
82
54
  if (existsSync(targetPath)) {
83
- removeSync(targetPath);
55
+ rmSync(targetPath, { recursive: true, force: true });
84
56
  }
85
57
  }
86
58
  function listFiles(dirPath, options = {}) {