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.
- package/dist/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
|
@@ -1,142 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
export {
|
|
139
|
-
createRegistryClient,
|
|
140
|
-
RegistryClient,
|
|
141
|
-
RegistryApiError
|
|
142
|
-
};
|
|
1
|
+
import{createRequire as K}from"node:module";var M=K(import.meta.url);function Q(j){return new J({registryUrl:j?.registryUrl??"https://registry.agentpacks.dev",authToken:j?.authToken,timeout:j?.timeout??30000})}class J{config;constructor(j){this.config={registryUrl:j.registryUrl.replace(/\/+$/,""),authToken:j.authToken,timeout:j.timeout??30000}}async search(j){let q=new URLSearchParams;if(j.query)q.set("q",j.query);if(j.tags?.length)q.set("tags",j.tags.join(","));if(j.targets?.length)q.set("targets",j.targets.join(","));if(j.features?.length)q.set("features",j.features.join(","));if(j.author)q.set("author",j.author);if(j.sort)q.set("sort",j.sort);if(j.limit)q.set("limit",String(j.limit));if(j.offset)q.set("offset",String(j.offset));let x=`${this.config.registryUrl}/packs?${q.toString()}`;return await this.fetch(x)}async info(j){let q=`${this.config.registryUrl}/packs/${encodeURIComponent(j)}`;return await this.fetch(q)}async download(j,q="latest"){let x=`${this.config.registryUrl}/packs/${encodeURIComponent(j)}/versions/${encodeURIComponent(q)}/download`,z=await fetch(x,{headers:this.headers(),signal:AbortSignal.timeout(this.config.timeout)});if(!z.ok)throw new F(z.status,`Failed to download ${j}@${q}: ${z.statusText}`);let B=z.headers.get("x-integrity")??"";return{data:await z.arrayBuffer(),integrity:B}}async publish(j,q){if(!this.config.authToken)throw Error("Authentication required. Run `agentpacks login` first.");let x=new FormData;x.append("tarball",new Blob([j],{type:"application/gzip"}),`${q.name}-${q.version}.tgz`),x.append("metadata",JSON.stringify(q));let z=`${this.config.registryUrl}/packs`,B=await fetch(z,{method:"POST",headers:{Authorization:`Bearer ${this.config.authToken}`},body:x,signal:AbortSignal.timeout(this.config.timeout)});if(!B.ok){let G=await B.text();throw new F(B.status,`Publish failed: ${G||B.statusText}`)}return await B.json()}async featured(j){let q=j?`${this.config.registryUrl}/featured?limit=${j}`:`${this.config.registryUrl}/featured`;return(await this.fetch(q)).packs}async tags(){let j=`${this.config.registryUrl}/tags`;return(await this.fetch(j)).tags}async stats(){let j=`${this.config.registryUrl}/stats`;return await this.fetch(j)}async health(){try{let j=`${this.config.registryUrl}/health`;return await this.fetch(j),!0}catch{return!1}}async fetch(j){let q=await fetch(j,{headers:this.headers(),signal:AbortSignal.timeout(this.config.timeout)});if(!q.ok){let x=await q.text();throw new F(q.status,x||q.statusText)}return q.json()}headers(){let j={Accept:"application/json"};if(this.config.authToken)j.Authorization=`Bearer ${this.config.authToken}`;return j}}class F extends Error{status;constructor(j,q){super(q);this.name="RegistryApiError",this.status=j}}export{Q as createRegistryClient,J as RegistryClient,F as RegistryApiError};
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
// src/utils/tarball.ts
|
|
5
|
-
import { execSync } from "child_process";
|
|
6
|
-
import { createHash } from "crypto";
|
|
7
|
-
import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
8
|
-
import { tmpdir } from "os";
|
|
9
|
-
import { join, resolve } from "path";
|
|
10
|
-
async function createTarball(packDir) {
|
|
11
|
-
const absDir = resolve(packDir);
|
|
12
|
-
const tmpFile = join(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
13
|
-
try {
|
|
14
|
-
execSync(`tar -czf "${tmpFile}" -C "${absDir}" .`, {
|
|
15
|
-
stdio: "pipe"
|
|
16
|
-
});
|
|
17
|
-
const buffer = readFileSync(tmpFile);
|
|
18
|
-
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
19
|
-
} finally {
|
|
20
|
-
if (existsSync(tmpFile)) {
|
|
21
|
-
rmSync(tmpFile);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function extractTarball(data, targetDir) {
|
|
26
|
-
mkdirSync(targetDir, { recursive: true });
|
|
27
|
-
const tmpFile = join(tmpdir(), `agentpacks-${Date.now()}.tgz`);
|
|
28
|
-
try {
|
|
29
|
-
const buffer = Buffer.from(data);
|
|
30
|
-
const { writeFileSync } = await import("fs");
|
|
31
|
-
writeFileSync(tmpFile, buffer);
|
|
32
|
-
execSync(`tar -xzf "${tmpFile}" -C "${targetDir}"`, {
|
|
33
|
-
stdio: "pipe"
|
|
34
|
-
});
|
|
35
|
-
} finally {
|
|
36
|
-
if (existsSync(tmpFile)) {
|
|
37
|
-
rmSync(tmpFile);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function computeTarballIntegrity(data) {
|
|
42
|
-
const hash = createHash("sha256").update(Buffer.from(data)).digest("hex");
|
|
43
|
-
return `sha256-${hash}`;
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
extractTarball,
|
|
47
|
-
createTarball,
|
|
48
|
-
computeTarballIntegrity
|
|
49
|
-
};
|
|
1
|
+
import{createRequire as O}from"node:module";var P=O(import.meta.url);import{execSync as I}from"child_process";import{createHash as Q}from"crypto";import{existsSync as J,mkdirSync as R,readFileSync as T,rmSync as K}from"fs";import{tmpdir as L}from"os";import{join as M,resolve as U}from"path";async function w(E){let G=U(E),q=M(L(),`agentpacks-${Date.now()}.tgz`);try{I(`tar -czf "${q}" -C "${G}" .`,{stdio:"pipe"});let z=T(q);return z.buffer.slice(z.byteOffset,z.byteOffset+z.byteLength)}finally{if(J(q))K(q)}}async function B(E,G){R(G,{recursive:!0});let q=M(L(),`agentpacks-${Date.now()}.tgz`);try{let z=Buffer.from(E),{writeFileSync:N}=await import("fs");N(q,z),I(`tar -xzf "${q}" -C "${G}"`,{stdio:"pipe"})}finally{if(J(q))K(q)}}function C(E){return`sha256-${Q("sha256").update(Buffer.from(E)).digest("hex")}`}export{B as extractTarball,w as createTarball,C as computeTarballIntegrity};
|
package/dist/sources/git-ref.js
CHANGED
|
@@ -1,56 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
// src/sources/git-ref.ts
|
|
5
|
-
function parseGitSourceRef(source) {
|
|
6
|
-
let s = source;
|
|
7
|
-
if (s.startsWith("github:")) {
|
|
8
|
-
s = s.slice(7);
|
|
9
|
-
}
|
|
10
|
-
let path = "";
|
|
11
|
-
const atIdx = s.indexOf("@");
|
|
12
|
-
const colonIdx = s.indexOf(":", atIdx > -1 ? atIdx : 0);
|
|
13
|
-
if (colonIdx > -1) {
|
|
14
|
-
path = s.slice(colonIdx + 1);
|
|
15
|
-
s = s.slice(0, colonIdx);
|
|
16
|
-
}
|
|
17
|
-
let ref = "main";
|
|
18
|
-
if (atIdx > -1) {
|
|
19
|
-
ref = s.slice(atIdx + 1);
|
|
20
|
-
s = s.slice(0, atIdx);
|
|
21
|
-
}
|
|
22
|
-
const parts = s.split("/");
|
|
23
|
-
if (parts.length < 2) {
|
|
24
|
-
throw new Error(`Invalid git source reference: "${source}". Expected owner/repo format.`);
|
|
25
|
-
}
|
|
26
|
-
const owner = parts[0];
|
|
27
|
-
const repo = parts[1];
|
|
28
|
-
if (!owner || !repo) {
|
|
29
|
-
throw new Error(`Invalid git source reference: "${source}". Expected owner/repo format.`);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
owner,
|
|
33
|
-
repo,
|
|
34
|
-
ref,
|
|
35
|
-
path: path || ""
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function isGitPackRef(packRef) {
|
|
39
|
-
if (packRef.startsWith("github:"))
|
|
40
|
-
return true;
|
|
41
|
-
if (packRef.startsWith("./") || packRef.startsWith("../") || packRef.startsWith("/")) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:"))
|
|
45
|
-
return false;
|
|
46
|
-
const parts = packRef.split("/");
|
|
47
|
-
return parts.length === 2 && !packRef.includes("node_modules");
|
|
48
|
-
}
|
|
49
|
-
function gitSourceKey(parsed) {
|
|
50
|
-
return `${parsed.owner}/${parsed.repo}`;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
parseGitSourceRef,
|
|
54
|
-
isGitPackRef,
|
|
55
|
-
gitSourceKey
|
|
56
|
-
};
|
|
2
|
+
var D=import.meta.require;function F(b){let g=b;if(g.startsWith("github:"))g=g.slice(7);let v="",j=g.indexOf("@"),m=g.indexOf(":",j>-1?j:0);if(m>-1)v=g.slice(m+1),g=g.slice(0,m);let z="main";if(j>-1)z=g.slice(j+1),g=g.slice(0,j);let q=g.split("/");if(q.length<2)throw Error(`Invalid git source reference: "${b}". Expected owner/repo format.`);let A=q[0],C=q[1];if(!A||!C)throw Error(`Invalid git source reference: "${b}". Expected owner/repo format.`);return{owner:A,repo:C,ref:z,path:v||""}}function G(b){if(b.startsWith("github:"))return!0;if(b.startsWith("./")||b.startsWith("../")||b.startsWith("/"))return!1;if(b.startsWith("@")||b.startsWith("npm:"))return!1;return b.split("/").length===2&&!b.includes("node_modules")}function H(b){return`${b.owner}/${b.repo}`}export{F as parseGitSourceRef,G as isGitPackRef,H as gitSourceKey};
|
package/dist/sources/git.js
CHANGED
|
@@ -1,222 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
// src/core/lockfile.ts
|
|
5
|
-
import { createHash } from "crypto";
|
|
6
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
var LOCKFILE_VERSION = 1;
|
|
9
|
-
var LOCKFILE_NAME = "agentpacks.lock";
|
|
10
|
-
function loadLockfile(projectRoot) {
|
|
11
|
-
const filepath = resolve(projectRoot, LOCKFILE_NAME);
|
|
12
|
-
if (!existsSync(filepath)) {
|
|
13
|
-
return { lockfileVersion: LOCKFILE_VERSION, sources: {} };
|
|
14
|
-
}
|
|
15
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
16
|
-
return JSON.parse(raw);
|
|
17
|
-
}
|
|
18
|
-
function saveLockfile(projectRoot, lockfile) {
|
|
19
|
-
const filepath = resolve(projectRoot, LOCKFILE_NAME);
|
|
20
|
-
writeFileSync(filepath, JSON.stringify(lockfile, null, 2) + `
|
|
21
|
-
`);
|
|
22
|
-
}
|
|
23
|
-
function getLockedSource(lockfile, sourceKey) {
|
|
24
|
-
return lockfile.sources[sourceKey];
|
|
25
|
-
}
|
|
26
|
-
function setLockedSource(lockfile, sourceKey, entry) {
|
|
27
|
-
lockfile.sources[sourceKey] = entry;
|
|
28
|
-
}
|
|
29
|
-
function computeIntegrity(content) {
|
|
30
|
-
const hash = createHash("sha256").update(content).digest("hex");
|
|
31
|
-
return `sha256-${hash}`;
|
|
32
|
-
}
|
|
33
|
-
function isLockfileFrozenValid(lockfile, sourceKeys) {
|
|
34
|
-
const missing = sourceKeys.filter((key) => !(key in lockfile.sources));
|
|
35
|
-
return { valid: missing.length === 0, missing };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/sources/git-ref.ts
|
|
39
|
-
function parseGitSourceRef(source) {
|
|
40
|
-
let s = source;
|
|
41
|
-
if (s.startsWith("github:")) {
|
|
42
|
-
s = s.slice(7);
|
|
43
|
-
}
|
|
44
|
-
let path = "";
|
|
45
|
-
const atIdx = s.indexOf("@");
|
|
46
|
-
const colonIdx = s.indexOf(":", atIdx > -1 ? atIdx : 0);
|
|
47
|
-
if (colonIdx > -1) {
|
|
48
|
-
path = s.slice(colonIdx + 1);
|
|
49
|
-
s = s.slice(0, colonIdx);
|
|
50
|
-
}
|
|
51
|
-
let ref = "main";
|
|
52
|
-
if (atIdx > -1) {
|
|
53
|
-
ref = s.slice(atIdx + 1);
|
|
54
|
-
s = s.slice(0, atIdx);
|
|
55
|
-
}
|
|
56
|
-
const parts = s.split("/");
|
|
57
|
-
if (parts.length < 2) {
|
|
58
|
-
throw new Error(`Invalid git source reference: "${source}". Expected owner/repo format.`);
|
|
59
|
-
}
|
|
60
|
-
const owner = parts[0];
|
|
61
|
-
const repo = parts[1];
|
|
62
|
-
if (!owner || !repo) {
|
|
63
|
-
throw new Error(`Invalid git source reference: "${source}". Expected owner/repo format.`);
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
owner,
|
|
67
|
-
repo,
|
|
68
|
-
ref,
|
|
69
|
-
path: path || ""
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function isGitPackRef(packRef) {
|
|
73
|
-
if (packRef.startsWith("github:"))
|
|
74
|
-
return true;
|
|
75
|
-
if (packRef.startsWith("./") || packRef.startsWith("../") || packRef.startsWith("/")) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:"))
|
|
79
|
-
return false;
|
|
80
|
-
const parts = packRef.split("/");
|
|
81
|
-
return parts.length === 2 && !packRef.includes("node_modules");
|
|
82
|
-
}
|
|
83
|
-
function gitSourceKey(parsed) {
|
|
84
|
-
return `${parsed.owner}/${parsed.repo}`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// src/sources/git.ts
|
|
88
|
-
import { mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
89
|
-
import { join, resolve as resolve2 } from "path";
|
|
90
|
-
var GITHUB_API = "https://api.github.com";
|
|
91
|
-
function githubHeaders(token) {
|
|
92
|
-
const h = {
|
|
93
|
-
Accept: "application/vnd.github.v3+json",
|
|
94
|
-
"User-Agent": "agentpacks"
|
|
95
|
-
};
|
|
96
|
-
if (token)
|
|
97
|
-
h.Authorization = `token ${token}`;
|
|
98
|
-
return h;
|
|
99
|
-
}
|
|
100
|
-
async function resolveGitRef(parsed, token) {
|
|
101
|
-
const base = `${GITHUB_API}/repos/${parsed.owner}/${parsed.repo}/git/ref`;
|
|
102
|
-
const res = await fetch(`${base}/heads/${parsed.ref}`, {
|
|
103
|
-
headers: githubHeaders(token)
|
|
104
|
-
});
|
|
105
|
-
if (!res.ok) {
|
|
106
|
-
const tagRes = await fetch(`${base}/tags/${parsed.ref}`, {
|
|
107
|
-
headers: githubHeaders(token)
|
|
108
|
-
});
|
|
109
|
-
if (!tagRes.ok) {
|
|
110
|
-
throw new Error(`Could not resolve ref "${parsed.ref}" for ${parsed.owner}/${parsed.repo}: ${res.status}`);
|
|
111
|
-
}
|
|
112
|
-
const tagData = await tagRes.json();
|
|
113
|
-
return tagData.object.sha;
|
|
114
|
-
}
|
|
115
|
-
const data = await res.json();
|
|
116
|
-
return data.object.sha;
|
|
117
|
-
}
|
|
118
|
-
async function fetchGitDirectory(parsed, sha, subpath, token) {
|
|
119
|
-
const path = parsed.path ? `${parsed.path}/${subpath}` : subpath;
|
|
120
|
-
const url = `${GITHUB_API}/repos/${parsed.owner}/${parsed.repo}/contents/${path}?ref=${sha}`;
|
|
121
|
-
const res = await fetch(url, { headers: githubHeaders(token) });
|
|
122
|
-
if (!res.ok)
|
|
123
|
-
return [];
|
|
124
|
-
return await res.json();
|
|
125
|
-
}
|
|
126
|
-
async function fetchGitFile(downloadUrl, token) {
|
|
127
|
-
const headers = { "User-Agent": "agentpacks" };
|
|
128
|
-
if (token)
|
|
129
|
-
headers.Authorization = `token ${token}`;
|
|
130
|
-
const res = await fetch(downloadUrl, { headers });
|
|
131
|
-
if (!res.ok) {
|
|
132
|
-
throw new Error(`Failed to fetch ${downloadUrl}: ${res.status}`);
|
|
133
|
-
}
|
|
134
|
-
return res.text();
|
|
135
|
-
}
|
|
136
|
-
async function fetchAndWriteSubdir(parsed, sha, remotePath, localDir, installed, token) {
|
|
137
|
-
mkdirSync(localDir, { recursive: true });
|
|
138
|
-
const entries = await fetchGitDirectory(parsed, sha, remotePath, token);
|
|
139
|
-
for (const entry of entries) {
|
|
140
|
-
if (entry.type === "file" && entry.download_url) {
|
|
141
|
-
const content = await fetchGitFile(entry.download_url, token);
|
|
142
|
-
const filepath = join(localDir, entry.name);
|
|
143
|
-
writeFileSync2(filepath, content);
|
|
144
|
-
installed.push(filepath);
|
|
145
|
-
} else if (entry.type === "dir") {
|
|
146
|
-
await fetchAndWriteSubdir(parsed, sha, `${remotePath}/${entry.name}`, join(localDir, entry.name), installed, token);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async function installGitSource(projectRoot, source, lockfile, options = {}) {
|
|
151
|
-
const parsed = parseGitSourceRef(source);
|
|
152
|
-
const sourceKey = gitSourceKey(parsed);
|
|
153
|
-
const installed = [];
|
|
154
|
-
const warnings = [];
|
|
155
|
-
let resolvedSha;
|
|
156
|
-
const locked = getLockedSource(lockfile, sourceKey);
|
|
157
|
-
if (options.frozen && !locked) {
|
|
158
|
-
throw new Error(`Frozen mode: no lockfile entry for source "${sourceKey}".`);
|
|
159
|
-
}
|
|
160
|
-
if (locked && !options.update) {
|
|
161
|
-
resolvedSha = locked.resolvedRef;
|
|
162
|
-
} else {
|
|
163
|
-
resolvedSha = await resolveGitRef(parsed, options.token);
|
|
164
|
-
}
|
|
165
|
-
const basePath = parsed.path || "packs";
|
|
166
|
-
const entries = await fetchGitDirectory(parsed, resolvedSha, basePath, options.token);
|
|
167
|
-
const curatedDir = resolve2(projectRoot, ".agentpacks", ".curated");
|
|
168
|
-
mkdirSync(curatedDir, { recursive: true });
|
|
169
|
-
const newLockEntry = {
|
|
170
|
-
requestedRef: parsed.ref,
|
|
171
|
-
resolvedRef: resolvedSha,
|
|
172
|
-
resolvedAt: new Date().toISOString(),
|
|
173
|
-
skills: {},
|
|
174
|
-
packs: {}
|
|
175
|
-
};
|
|
176
|
-
const packDirs = entries.filter((e) => e.type === "dir");
|
|
177
|
-
for (const packEntry of packDirs) {
|
|
178
|
-
const packName = packEntry.name;
|
|
179
|
-
const packOutDir = resolve2(curatedDir, packName);
|
|
180
|
-
const packFiles = await fetchGitDirectory(parsed, resolvedSha, `${basePath}/${packName}`, options.token);
|
|
181
|
-
mkdirSync(packOutDir, { recursive: true });
|
|
182
|
-
for (const file of packFiles) {
|
|
183
|
-
if (file.type === "file" && file.download_url) {
|
|
184
|
-
const content = await fetchGitFile(file.download_url, options.token);
|
|
185
|
-
writeFileSync2(join(packOutDir, file.name), content);
|
|
186
|
-
installed.push(join(packOutDir, file.name));
|
|
187
|
-
if (newLockEntry.packs) {
|
|
188
|
-
newLockEntry.packs[packName] = {
|
|
189
|
-
integrity: computeIntegrity(content)
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
} else if (file.type === "dir") {
|
|
193
|
-
await fetchAndWriteSubdir(parsed, resolvedSha, `${basePath}/${packName}/${file.name}`, join(packOutDir, file.name), installed, options.token);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (packDirs.length === 0) {
|
|
198
|
-
const fileEntries = entries.filter((e) => e.type === "file");
|
|
199
|
-
if (fileEntries.length > 0) {
|
|
200
|
-
const packName = parsed.path.split("/").pop() ?? parsed.repo;
|
|
201
|
-
const packOutDir = resolve2(curatedDir, packName);
|
|
202
|
-
mkdirSync(packOutDir, { recursive: true });
|
|
203
|
-
for (const file of entries) {
|
|
204
|
-
if (file.type === "file" && file.download_url) {
|
|
205
|
-
const content = await fetchGitFile(file.download_url, options.token);
|
|
206
|
-
writeFileSync2(join(packOutDir, file.name), content);
|
|
207
|
-
installed.push(join(packOutDir, file.name));
|
|
208
|
-
} else if (file.type === "dir") {
|
|
209
|
-
await fetchAndWriteSubdir(parsed, resolvedSha, `${basePath}/${file.name}`, join(packOutDir, file.name), installed, options.token);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
setLockedSource(lockfile, sourceKey, newLockEntry);
|
|
215
|
-
return { installed, warnings };
|
|
216
|
-
}
|
|
217
|
-
export {
|
|
218
|
-
resolveGitRef,
|
|
219
|
-
installGitSource,
|
|
220
|
-
fetchGitFile,
|
|
221
|
-
fetchGitDirectory
|
|
222
|
-
};
|
|
2
|
+
var n=import.meta.require;import{createHash as y}from"crypto";import{existsSync as u,readFileSync as h,writeFileSync as f}from"fs";import{resolve as b}from"path";var k=1,j="agentpacks.lock";function a(q){let z=b(q,j);if(!u(z))return{lockfileVersion:k,sources:{}};let Q=h(z,"utf-8");return JSON.parse(Q)}function s(q,z){let Q=b(q,j);f(Q,JSON.stringify(z,null,2)+`
|
|
3
|
+
`)}function m(q,z){return q.sources[z]}function w(q,z,Q){q.sources[z]=Q}function I(q){return`sha256-${y("sha256").update(q).digest("hex")}`}function t(q,z){let Q=z.filter((J)=>!(J in q.sources));return{valid:Q.length===0,missing:Q}}function D(q){let z=q;if(z.startsWith("github:"))z=z.slice(7);let Q="",J=z.indexOf("@"),X=z.indexOf(":",J>-1?J:0);if(X>-1)Q=z.slice(X+1),z=z.slice(0,X);let Y="main";if(J>-1)Y=z.slice(J+1),z=z.slice(0,J);let Z=z.split("/");if(Z.length<2)throw Error(`Invalid git source reference: "${q}". Expected owner/repo format.`);let $=Z[0],V=Z[1];if(!$||!V)throw Error(`Invalid git source reference: "${q}". Expected owner/repo format.`);return{owner:$,repo:V,ref:Y,path:Q||""}}function r(q){if(q.startsWith("github:"))return!0;if(q.startsWith("./")||q.startsWith("../")||q.startsWith("/"))return!1;if(q.startsWith("@")||q.startsWith("npm:"))return!1;return q.split("/").length===2&&!q.includes("node_modules")}function S(q){return`${q.owner}/${q.repo}`}import{mkdirSync as H,writeFileSync as P}from"fs";import{join as C,resolve as G}from"path";var R="https://api.github.com";function L(q){let z={Accept:"application/vnd.github.v3+json","User-Agent":"agentpacks"};if(q)z.Authorization=`token ${q}`;return z}async function d(q,z){let Q=`${R}/repos/${q.owner}/${q.repo}/git/ref`,J=await fetch(`${Q}/heads/${q.ref}`,{headers:L(z)});if(!J.ok){let Y=await fetch(`${Q}/tags/${q.ref}`,{headers:L(z)});if(!Y.ok)throw Error(`Could not resolve ref "${q.ref}" for ${q.owner}/${q.repo}: ${J.status}`);return(await Y.json()).object.sha}return(await J.json()).object.sha}async function F(q,z,Q,J){let X=q.path?`${q.path}/${Q}`:Q,Y=`${R}/repos/${q.owner}/${q.repo}/contents/${X}?ref=${z}`,Z=await fetch(Y,{headers:L(J)});if(!Z.ok)return[];return await Z.json()}async function O(q,z){let Q={"User-Agent":"agentpacks"};if(z)Q.Authorization=`token ${z}`;let J=await fetch(q,{headers:Q});if(!J.ok)throw Error(`Failed to fetch ${q}: ${J.status}`);return J.text()}async function g(q,z,Q,J,X,Y){H(J,{recursive:!0});let Z=await F(q,z,Q,Y);for(let $ of Z)if($.type==="file"&&$.download_url){let V=await O($.download_url,Y),_=C(J,$.name);P(_,V),X.push(_)}else if($.type==="dir")await g(q,z,`${Q}/${$.name}`,C(J,$.name),X,Y)}async function Xq(q,z,Q,J={}){let X=D(z),Y=S(X),Z=[],$=[],V,_=m(Q,Y);if(J.frozen&&!_)throw Error(`Frozen mode: no lockfile entry for source "${Y}".`);if(_&&!J.update)V=_.resolvedRef;else V=await d(X,J.token);let U=X.path||"packs",N=await F(X,V,U,J.token),x=G(q,".agentpacks",".curated");H(x,{recursive:!0});let E={requestedRef:X.ref,resolvedRef:V,resolvedAt:new Date().toISOString(),skills:{},packs:{}},K=N.filter((A)=>A.type==="dir");for(let A of K){let W=A.name,B=G(x,W),M=await F(X,V,`${U}/${W}`,J.token);H(B,{recursive:!0});for(let T of M)if(T.type==="file"&&T.download_url){let v=await O(T.download_url,J.token);if(P(C(B,T.name),v),Z.push(C(B,T.name)),E.packs)E.packs[W]={integrity:I(v)}}else if(T.type==="dir")await g(X,V,`${U}/${W}/${T.name}`,C(B,T.name),Z,J.token)}if(K.length===0){if(N.filter((W)=>W.type==="file").length>0){let W=X.path.split("/").pop()??X.repo,B=G(x,W);H(B,{recursive:!0});for(let M of N)if(M.type==="file"&&M.download_url){let T=await O(M.download_url,J.token);P(C(B,M.name),T),Z.push(C(B,M.name))}else if(M.type==="dir")await g(X,V,`${U}/${M.name}`,C(B,M.name),Z,J.token)}}return w(Q,Y,E),{installed:Z,warnings:$}}export{d as resolveGitRef,Xq as installGitSource,O as fetchGitFile,F as fetchGitDirectory};
|