@supercorks/skills-installer 1.8.0 → 1.9.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/lib/github-auth.js +72 -0
- package/lib/skills.js +4 -8
- package/lib/subagents.js +4 -8
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for authenticated GitHub API requests.
|
|
3
|
+
* Uses env tokens first, then falls back to `gh auth token` when available.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { execFileSync } from 'child_process';
|
|
7
|
+
|
|
8
|
+
let cachedToken = '';
|
|
9
|
+
let tokenResolved = false;
|
|
10
|
+
|
|
11
|
+
function normalizeToken(raw) {
|
|
12
|
+
if (!raw || typeof raw !== 'string') return '';
|
|
13
|
+
return raw.trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readTokenFromGhCli() {
|
|
17
|
+
try {
|
|
18
|
+
const token = execFileSync('gh', ['auth', 'token'], {
|
|
19
|
+
encoding: 'utf-8',
|
|
20
|
+
stdio: ['ignore', 'pipe', 'ignore']
|
|
21
|
+
});
|
|
22
|
+
return normalizeToken(token);
|
|
23
|
+
} catch {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a GitHub token if available.
|
|
30
|
+
* Resolution order: GITHUB_TOKEN -> GH_TOKEN -> gh auth token.
|
|
31
|
+
* Value is cached for process lifetime.
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
export function getGitHubAuthToken() {
|
|
35
|
+
if (tokenResolved) return cachedToken;
|
|
36
|
+
|
|
37
|
+
tokenResolved = true;
|
|
38
|
+
cachedToken =
|
|
39
|
+
normalizeToken(process.env.GITHUB_TOKEN) ||
|
|
40
|
+
normalizeToken(process.env.GH_TOKEN) ||
|
|
41
|
+
readTokenFromGhCli() ||
|
|
42
|
+
'';
|
|
43
|
+
|
|
44
|
+
return cachedToken;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Build GitHub API headers with optional auth.
|
|
49
|
+
* @param {string} [userAgent='@supercorks/skills-installer']
|
|
50
|
+
* @returns {Record<string, string>}
|
|
51
|
+
*/
|
|
52
|
+
export function getGitHubHeaders(userAgent = '@supercorks/skills-installer') {
|
|
53
|
+
const headers = {
|
|
54
|
+
Accept: 'application/vnd.github.v3+json',
|
|
55
|
+
'User-Agent': userAgent
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const token = getGitHubAuthToken();
|
|
59
|
+
if (token) {
|
|
60
|
+
headers.Authorization = `Bearer ${token}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return headers;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Test-only cache reset helper.
|
|
68
|
+
*/
|
|
69
|
+
export function __resetGitHubAuthCacheForTests() {
|
|
70
|
+
cachedToken = '';
|
|
71
|
+
tokenResolved = false;
|
|
72
|
+
}
|
package/lib/skills.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Fetch and parse available skills from the GitHub repository
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { getGitHubHeaders } from './github-auth.js';
|
|
6
|
+
|
|
5
7
|
const REPO_OWNER = 'supercorks';
|
|
6
8
|
const REPO_NAME = 'agent-skills';
|
|
7
9
|
const GITHUB_API = 'https://api.github.com';
|
|
@@ -26,10 +28,7 @@ export async function fetchAvailableSkills() {
|
|
|
26
28
|
const repoUrl = `${GITHUB_API}/repos/${REPO_OWNER}/${REPO_NAME}/contents`;
|
|
27
29
|
|
|
28
30
|
const response = await fetch(repoUrl, {
|
|
29
|
-
headers:
|
|
30
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
31
|
-
'User-Agent': '@supercorks/skills-installer'
|
|
32
|
-
}
|
|
31
|
+
headers: getGitHubHeaders()
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
if (!response.ok) {
|
|
@@ -61,10 +60,7 @@ export async function fetchSkillMetadata(skillFolder) {
|
|
|
61
60
|
|
|
62
61
|
try {
|
|
63
62
|
const response = await fetch(skillMdUrl, {
|
|
64
|
-
headers:
|
|
65
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
66
|
-
'User-Agent': '@supercorks/skills-installer'
|
|
67
|
-
}
|
|
63
|
+
headers: getGitHubHeaders()
|
|
68
64
|
});
|
|
69
65
|
|
|
70
66
|
if (!response.ok) {
|
package/lib/subagents.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Fetch and parse available subagents from the GitHub repository
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { getGitHubHeaders } from './github-auth.js';
|
|
6
|
+
|
|
5
7
|
const SUBAGENTS_REPO_OWNER = 'supercorks';
|
|
6
8
|
const SUBAGENTS_REPO_NAME = 'subagents';
|
|
7
9
|
const GITHUB_API = 'https://api.github.com';
|
|
@@ -24,10 +26,7 @@ export async function fetchAvailableSubagents() {
|
|
|
24
26
|
const repoUrl = `${GITHUB_API}/repos/${SUBAGENTS_REPO_OWNER}/${SUBAGENTS_REPO_NAME}/contents`;
|
|
25
27
|
|
|
26
28
|
const response = await fetch(repoUrl, {
|
|
27
|
-
headers:
|
|
28
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
29
|
-
'User-Agent': '@supercorks/skills-installer'
|
|
30
|
-
}
|
|
29
|
+
headers: getGitHubHeaders()
|
|
31
30
|
});
|
|
32
31
|
|
|
33
32
|
if (!response.ok) {
|
|
@@ -59,10 +58,7 @@ export async function fetchSubagentMetadata(filename) {
|
|
|
59
58
|
|
|
60
59
|
try {
|
|
61
60
|
const response = await fetch(fileUrl, {
|
|
62
|
-
headers:
|
|
63
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
64
|
-
'User-Agent': '@supercorks/skills-installer'
|
|
65
|
-
}
|
|
61
|
+
headers: getGitHubHeaders()
|
|
66
62
|
});
|
|
67
63
|
|
|
68
64
|
if (!response.ok) {
|