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,202 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ // src/utils/registry-client.ts
5
+ var DEFAULT_REGISTRY_URL = "https://registry.agentpacks.dev";
6
+ function createRegistryClient(config) {
7
+ return new RegistryClient({
8
+ registryUrl: config?.registryUrl ?? DEFAULT_REGISTRY_URL,
9
+ authToken: config?.authToken,
10
+ timeout: config?.timeout ?? 30000
11
+ });
12
+ }
13
+
14
+ class RegistryClient {
15
+ config;
16
+ constructor(config) {
17
+ this.config = {
18
+ registryUrl: config.registryUrl.replace(/\/+$/, ""),
19
+ authToken: config.authToken,
20
+ timeout: config.timeout ?? 30000
21
+ };
22
+ }
23
+ async search(params) {
24
+ const searchParams = new URLSearchParams;
25
+ if (params.query)
26
+ searchParams.set("q", params.query);
27
+ if (params.tags?.length)
28
+ searchParams.set("tags", params.tags.join(","));
29
+ if (params.targets?.length)
30
+ searchParams.set("targets", params.targets.join(","));
31
+ if (params.features?.length)
32
+ searchParams.set("features", params.features.join(","));
33
+ if (params.author)
34
+ searchParams.set("author", params.author);
35
+ if (params.sort)
36
+ searchParams.set("sort", params.sort);
37
+ if (params.limit)
38
+ searchParams.set("limit", String(params.limit));
39
+ if (params.offset)
40
+ searchParams.set("offset", String(params.offset));
41
+ const url = `${this.config.registryUrl}/packs?${searchParams.toString()}`;
42
+ const res = await this.fetch(url);
43
+ return res;
44
+ }
45
+ async info(packName) {
46
+ const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}`;
47
+ const res = await this.fetch(url);
48
+ return res;
49
+ }
50
+ async download(packName, version = "latest") {
51
+ const url = `${this.config.registryUrl}/packs/${encodeURIComponent(packName)}/versions/${encodeURIComponent(version)}/download`;
52
+ const response = await fetch(url, {
53
+ headers: this.headers(),
54
+ signal: AbortSignal.timeout(this.config.timeout)
55
+ });
56
+ if (!response.ok) {
57
+ throw new RegistryApiError(response.status, `Failed to download ${packName}@${version}: ${response.statusText}`);
58
+ }
59
+ const integrity = response.headers.get("x-integrity") ?? "";
60
+ const data = await response.arrayBuffer();
61
+ return { data, integrity };
62
+ }
63
+ async publish(tarball, metadata) {
64
+ if (!this.config.authToken) {
65
+ throw new Error("Authentication required. Run `agentpacks login` first.");
66
+ }
67
+ const formData = new FormData;
68
+ formData.append("tarball", new Blob([tarball], { type: "application/gzip" }), `${metadata.name}-${metadata.version}.tgz`);
69
+ formData.append("metadata", JSON.stringify(metadata));
70
+ const url = `${this.config.registryUrl}/packs`;
71
+ const response = await fetch(url, {
72
+ method: "POST",
73
+ headers: {
74
+ Authorization: `Bearer ${this.config.authToken}`
75
+ },
76
+ body: formData,
77
+ signal: AbortSignal.timeout(this.config.timeout)
78
+ });
79
+ if (!response.ok) {
80
+ const body = await response.text();
81
+ throw new RegistryApiError(response.status, `Publish failed: ${body || response.statusText}`);
82
+ }
83
+ return await response.json();
84
+ }
85
+ async featured(limit) {
86
+ const url = limit ? `${this.config.registryUrl}/featured?limit=${limit}` : `${this.config.registryUrl}/featured`;
87
+ const res = await this.fetch(url);
88
+ return res.packs;
89
+ }
90
+ async tags() {
91
+ const url = `${this.config.registryUrl}/tags`;
92
+ const res = await this.fetch(url);
93
+ return res.tags;
94
+ }
95
+ async stats() {
96
+ const url = `${this.config.registryUrl}/stats`;
97
+ return await this.fetch(url);
98
+ }
99
+ async health() {
100
+ try {
101
+ const url = `${this.config.registryUrl}/health`;
102
+ await this.fetch(url);
103
+ return true;
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+ async fetch(url) {
109
+ const response = await fetch(url, {
110
+ headers: this.headers(),
111
+ signal: AbortSignal.timeout(this.config.timeout)
112
+ });
113
+ if (!response.ok) {
114
+ const body = await response.text();
115
+ throw new RegistryApiError(response.status, body || response.statusText);
116
+ }
117
+ return response.json();
118
+ }
119
+ headers() {
120
+ const h = {
121
+ Accept: "application/json"
122
+ };
123
+ if (this.config.authToken) {
124
+ h["Authorization"] = `Bearer ${this.config.authToken}`;
125
+ }
126
+ return h;
127
+ }
128
+ }
129
+
130
+ class RegistryApiError extends Error {
131
+ status;
132
+ constructor(status, message) {
133
+ super(message);
134
+ this.name = "RegistryApiError";
135
+ this.status = status;
136
+ }
137
+ }
138
+
139
+ // src/utils/credentials.ts
140
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
141
+ import { join, dirname } from "path";
142
+ import { homedir } from "os";
143
+ var CONFIG_DIR = join(homedir(), ".config", "agentpacks");
144
+ var CREDENTIALS_FILE = join(CONFIG_DIR, "credentials.json");
145
+ function loadCredentials() {
146
+ if (!existsSync(CREDENTIALS_FILE)) {
147
+ return { registryUrl: "https://registry.agentpacks.dev" };
148
+ }
149
+ try {
150
+ const raw = readFileSync(CREDENTIALS_FILE, "utf-8");
151
+ return JSON.parse(raw);
152
+ } catch {
153
+ return { registryUrl: "https://registry.agentpacks.dev" };
154
+ }
155
+ }
156
+ function saveCredentials(credentials) {
157
+ mkdirSync(dirname(CREDENTIALS_FILE), { recursive: true });
158
+ writeFileSync(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2) + `
159
+ `, {
160
+ mode: 384
161
+ });
162
+ }
163
+ function clearCredentials() {
164
+ if (existsSync(CREDENTIALS_FILE)) {
165
+ writeFileSync(CREDENTIALS_FILE, JSON.stringify({ registryUrl: "https://registry.agentpacks.dev" }) + `
166
+ `);
167
+ }
168
+ }
169
+
170
+ // src/cli/login.ts
171
+ import chalk from "chalk";
172
+ async function runLogin(options) {
173
+ const registryUrl = options.registry ?? "https://registry.agentpacks.dev";
174
+ if (!options.token) {
175
+ console.log(chalk.bold(`agentpacks login
176
+ `));
177
+ console.log("To authenticate, you need an API token.");
178
+ console.log(`Get one at: ${chalk.cyan(`${registryUrl}/account/tokens`)}
179
+ `);
180
+ console.log("Then run:");
181
+ console.log(chalk.dim(` agentpacks login --token <your-token>
182
+ `));
183
+ return;
184
+ }
185
+ const client = createRegistryClient({
186
+ registryUrl,
187
+ authToken: options.token
188
+ });
189
+ const healthy = await client.health();
190
+ if (!healthy) {
191
+ console.log(chalk.yellow(`Warning: Could not reach registry at ${registryUrl}`));
192
+ }
193
+ saveCredentials({
194
+ registryUrl,
195
+ token: options.token
196
+ });
197
+ console.log(chalk.green(`Authenticated with ${registryUrl}`));
198
+ console.log(chalk.dim("Credentials saved to ~/.config/agentpacks/credentials.json"));
199
+ }
200
+ export {
201
+ runLogin
202
+ };