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,56 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
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
|
-
};
|
|
1
|
+
import{createRequire as D}from"node:module";var F=D(import.meta.url);function H(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 J(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 K(b){return`${b.owner}/${b.repo}`}export{H as parseGitSourceRef,J as isGitPackRef,K as gitSourceKey};
|
package/dist/node/sources/git.js
CHANGED
|
@@ -1,222 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
};
|
|
1
|
+
import{createRequire as y}from"node:module";var l=y(import.meta.url);import{createHash as u}from"crypto";import{existsSync as h,readFileSync as f,writeFileSync as k}from"fs";import{resolve as b}from"path";var d=1,j="agentpacks.lock";function t(q){let z=b(q,j);if(!h(z))return{lockfileVersion:d,sources:{}};let Q=f(z,"utf-8");return JSON.parse(Q)}function o(q,z){let Q=b(q,j);k(Q,JSON.stringify(z,null,2)+`
|
|
2
|
+
`)}function m(q,z){return q.sources[z]}function w(q,z,Q){q.sources[z]=Q}function I(q){return`sha256-${u("sha256").update(q).digest("hex")}`}function r(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 qq(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 n(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 Zq(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 n(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{n as resolveGitRef,Zq as installGitSource,O as fetchGitFile,F as fetchGitDirectory};
|