skillgrove 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +38 -2
- package/bin/skillgrove.mjs +315 -0
- package/lib/api.mjs +196 -0
- package/lib/install.mjs +143 -0
- package/lib/targets.json +20 -0
- package/lib/zip.mjs +94 -0
- package/package.json +28 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SkillGrove
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# skillgrove
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install [SkillGrove](https://skillgrove.dev) Agent Skills into Claude Code, Codex or Cursor with one command.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx --yes skillgrove@0.1 install launch-video --agent claude-code
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Or paste a skill's prompt into your agent ("Read https://skillgrove.dev/skills/launch-video/install.md and follow it") and it runs this for you.
|
|
10
|
+
|
|
11
|
+
The first time, it shows a code and opens https://skillgrove.dev/device in your browser: sign in, check the code, click Approve. Pro skills need a Pro plan; if the account has none, it opens the pricing page and continues once the payment arrives.
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
| Command | What it does |
|
|
16
|
+
| ---------------------------------------- | ----------------------------------------------------------------- |
|
|
17
|
+
| `skillgrove install <slug>...` | Install one or more skills |
|
|
18
|
+
| `skillgrove update [slug...]` | Update installed skills to their latest version |
|
|
19
|
+
| `skillgrove list` | List installed SkillGrove skills and whether an update is out |
|
|
20
|
+
| `skillgrove login` / `logout` / `whoami` | Sign this computer in, sign it out (everywhere), show the account |
|
|
21
|
+
|
|
22
|
+
Options: `--agent claude-code|codex|cursor`, `--project` (install into the current project), `--force` (replace a folder SkillGrove didn't install, keeping a backup), `--wait <minutes>`, `--no-open`, `--json`.
|
|
23
|
+
|
|
24
|
+
| Agent | All projects | One project (`--project`) |
|
|
25
|
+
| ----------- | ------------------ | ------------------------- |
|
|
26
|
+
| Claude Code | `~/.claude/skills` | `.claude/skills` |
|
|
27
|
+
| Codex | `~/.agents/skills` | `.agents/skills` |
|
|
28
|
+
| Cursor | `~/.cursor/skills` | `.cursor/skills` |
|
|
29
|
+
|
|
30
|
+
## Security
|
|
31
|
+
|
|
32
|
+
- No dependencies: only Node.js 22.2+ built-ins.
|
|
33
|
+
- The install token can only download skills: never billing or account settings. Only its hash is stored on the server. It's saved in `~/.config/skillgrove/credentials.json` (mode 0600) and never printed. Sign a computer out on your [account page](https://skillgrove.dev/account#devices) or with `skillgrove logout`.
|
|
34
|
+
- Every zip is checked against its SHA-256 before unpacking. Paths outside the skill folder, absolute paths and symbolic links are refused, and nothing is written until the whole zip has been checked.
|
|
35
|
+
- Folders without a `.skillgrove.json` marker (your own skills) are never overwritten unless you pass `--force`, which keeps a backup.
|
|
36
|
+
|
|
37
|
+
`SKILLGROVE_URL` points the CLI at another server (local development).
|
|
38
|
+
|
|
39
|
+
MIT licensed. The skills themselves have their own licenses (see each skill's `LICENSE.md`).
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// skillgrove: install SkillGrove skills into Claude Code, Codex or Cursor.
|
|
3
|
+
// npx --yes skillgrove@0.1 install <slug> --agent claude-code
|
|
4
|
+
// Run `skillgrove help` for every command. Docs: https://skillgrove.dev/install/agent.md
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ApiError,
|
|
10
|
+
catalog,
|
|
11
|
+
downloadSkill,
|
|
12
|
+
forgetLogin,
|
|
13
|
+
login,
|
|
14
|
+
logout,
|
|
15
|
+
openBrowser,
|
|
16
|
+
savedLogin,
|
|
17
|
+
SITE,
|
|
18
|
+
skillStatus,
|
|
19
|
+
VERSION,
|
|
20
|
+
whoami,
|
|
21
|
+
} from '../lib/api.mjs';
|
|
22
|
+
import {
|
|
23
|
+
AGENTS,
|
|
24
|
+
allSkillDirs,
|
|
25
|
+
detectAgent,
|
|
26
|
+
InstallError,
|
|
27
|
+
installZip,
|
|
28
|
+
listInstalled,
|
|
29
|
+
skillsDir,
|
|
30
|
+
TARGETS,
|
|
31
|
+
} from '../lib/install.mjs';
|
|
32
|
+
import { ZipError } from '../lib/zip.mjs';
|
|
33
|
+
|
|
34
|
+
const HELP = `skillgrove ${VERSION}: install SkillGrove skills into your coding agent.
|
|
35
|
+
|
|
36
|
+
Usage
|
|
37
|
+
skillgrove install <slug>... [--agent <agent>] [--project] [--force]
|
|
38
|
+
skillgrove update [<slug>...] [--agent <agent>] [--project]
|
|
39
|
+
skillgrove list
|
|
40
|
+
skillgrove login | logout | whoami
|
|
41
|
+
|
|
42
|
+
Options
|
|
43
|
+
--agent <agent> ${AGENTS.join(', ')} (detected inside Claude Code)
|
|
44
|
+
--project install into the current project instead of for all projects
|
|
45
|
+
--force replace a folder SkillGrove didn't install (keeps a backup)
|
|
46
|
+
--wait <minutes> how long to wait for a payment or confirmation (default 15)
|
|
47
|
+
--no-open don't open the browser, only print the link
|
|
48
|
+
--json print one line of JSON with the result
|
|
49
|
+
-v, --version print the version
|
|
50
|
+
|
|
51
|
+
Skills: ${SITE}/skills Agents: ${SITE}/install/agent.md`;
|
|
52
|
+
|
|
53
|
+
let args;
|
|
54
|
+
try {
|
|
55
|
+
args = parseArgs({
|
|
56
|
+
allowPositionals: true,
|
|
57
|
+
options: {
|
|
58
|
+
agent: { type: 'string' },
|
|
59
|
+
project: { type: 'boolean', default: false },
|
|
60
|
+
force: { type: 'boolean', default: false },
|
|
61
|
+
wait: { type: 'string', default: '15' },
|
|
62
|
+
'no-open': { type: 'boolean', default: false },
|
|
63
|
+
json: { type: 'boolean', default: false },
|
|
64
|
+
version: { type: 'boolean', short: 'v', default: false },
|
|
65
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(`${error.message}\n\n${HELP}`);
|
|
70
|
+
process.exit(2);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { values: opts, positionals } = args;
|
|
74
|
+
const [command, ...rest] = positionals;
|
|
75
|
+
const asJson = opts.json;
|
|
76
|
+
const shouldOpen = !opts['no-open'];
|
|
77
|
+
// Progress for people: stdout normally, stderr with --json so stdout stays one JSON line.
|
|
78
|
+
const say = (line = '') => (asJson ? process.stderr : process.stdout).write(`${line}\n`);
|
|
79
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
80
|
+
|
|
81
|
+
function finish(result) {
|
|
82
|
+
if (asJson) process.stdout.write(JSON.stringify({ ok: true, ...result }) + '\n');
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function fail(code, message, extra = {}) {
|
|
87
|
+
if (asJson) process.stdout.write(JSON.stringify({ ok: false, error: code, message, ...extra }) + '\n');
|
|
88
|
+
else console.error(`skillgrove: ${message}${extra.url ? `\n ${extra.url}` : ''}`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resolveAgent({ required }) {
|
|
93
|
+
const agent = opts.agent ?? detectAgent();
|
|
94
|
+
if (agent && !TARGETS[agent]) fail('bad_agent', `Unknown agent "${agent}". Use --agent ${AGENTS.join(' | ')}.`);
|
|
95
|
+
if (!agent && required) {
|
|
96
|
+
fail('agent_required', `Which agent is this for? Add --agent ${AGENTS.join(' | ')}.`, { agents: AGENTS });
|
|
97
|
+
}
|
|
98
|
+
return agent ?? null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A token for this device, signing in first if there is none. */
|
|
102
|
+
async function ensureToken(agent) {
|
|
103
|
+
const saved = savedLogin();
|
|
104
|
+
if (saved) return saved.token;
|
|
105
|
+
await login({ agent, say, open: shouldOpen });
|
|
106
|
+
return savedLogin().token;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Calls fn(token); if the token was revoked or expired, signs in again once and retries. */
|
|
110
|
+
async function withToken(agent, fn) {
|
|
111
|
+
const token = await ensureToken(agent);
|
|
112
|
+
try {
|
|
113
|
+
return await fn(token);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!(error instanceof ApiError) || error.code !== 'unauthorized') throw error;
|
|
116
|
+
forgetLogin();
|
|
117
|
+
say('This device was signed out. Signing in again.');
|
|
118
|
+
return fn(await ensureToken(agent));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const WAITING = {
|
|
123
|
+
needs_plan: 'is a Pro skill and this account has no Pro plan. Opening the pricing page; waiting for the payment',
|
|
124
|
+
needs_consent:
|
|
125
|
+
'is your first Pro download. Confirm immediate delivery on the page that opens (only you can do this); waiting',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Polls the skill's state until it can be downloaded, waiting on the user's browser. */
|
|
129
|
+
async function waitUntilReady(token, slug) {
|
|
130
|
+
let status = await skillStatus(token, slug);
|
|
131
|
+
const deadline = Date.now() + Math.max(1, Number(opts.wait) || 15) * 60 * 1000;
|
|
132
|
+
let opened = null;
|
|
133
|
+
while (status.state === 'needs_plan' || status.state === 'needs_consent') {
|
|
134
|
+
if (opened !== status.state) {
|
|
135
|
+
opened = status.state;
|
|
136
|
+
say(`${status.title} ${WAITING[status.state]}...`);
|
|
137
|
+
say(` ${status.url}`);
|
|
138
|
+
if (shouldOpen) openBrowser(status.url);
|
|
139
|
+
}
|
|
140
|
+
if (Date.now() > deadline) {
|
|
141
|
+
throw new ApiError(
|
|
142
|
+
status.state,
|
|
143
|
+
`Still waiting after ${opts.wait} minutes. Finish in the browser, then run the same command again.`,
|
|
144
|
+
{
|
|
145
|
+
url: status.url,
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
await sleep(5000);
|
|
150
|
+
status = await skillStatus(token, slug);
|
|
151
|
+
}
|
|
152
|
+
if (status.state === 'limit')
|
|
153
|
+
throw new ApiError('limit', "Today's download limit is reached. It resets at 00:00 UTC.");
|
|
154
|
+
if (status.state === 'unavailable')
|
|
155
|
+
throw new ApiError('unavailable', `${status.title} isn't available for download yet.`);
|
|
156
|
+
return status;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function installOne(token, slug, agent, { project = opts.project, quietIfCurrent = false } = {}) {
|
|
160
|
+
const dir = skillsDir(agent, { project });
|
|
161
|
+
const status = await waitUntilReady(token, slug);
|
|
162
|
+
const current = listInstalled([{ agent, scope: project ? 'project' : 'user', dir }]).find((s) => s.slug === slug);
|
|
163
|
+
if (quietIfCurrent && current?.version === status.version) {
|
|
164
|
+
say(`${slug} is up to date (${status.version}).`);
|
|
165
|
+
return { slug, version: status.version, path: current.path, agent, updated: false };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
say(`Downloading ${status.title} ${status.version}...`);
|
|
169
|
+
const { zip, sha256 } = await downloadSkill(token, slug);
|
|
170
|
+
const actual = createHash('sha256').update(zip).digest('hex');
|
|
171
|
+
if (actual !== sha256 || (status.sha256 && actual !== status.sha256)) {
|
|
172
|
+
throw new InstallError(
|
|
173
|
+
'checksum',
|
|
174
|
+
`The download of ${slug} doesn't match its SHA-256. Nothing was installed; try again.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const result = installZip(zip, {
|
|
178
|
+
slug,
|
|
179
|
+
dir,
|
|
180
|
+
version: status.version,
|
|
181
|
+
sha256: actual,
|
|
182
|
+
source: SITE,
|
|
183
|
+
force: opts.force,
|
|
184
|
+
});
|
|
185
|
+
say(`Installed ${status.title} ${status.version} in ${result.path}`);
|
|
186
|
+
if (result.backup) say(` Your previous folder was kept as ${result.backup}`);
|
|
187
|
+
return { slug, version: status.version, path: result.path, agent, example: status.example_prompt, updated: true };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** What --json reports for each installed skill. */
|
|
191
|
+
const summary = ({ slug, version, path, agent }) => ({ slug, version, path, agent });
|
|
192
|
+
|
|
193
|
+
async function cmdInstall(slugs) {
|
|
194
|
+
if (slugs.length === 0)
|
|
195
|
+
fail('usage', 'Name the skill to install, e.g. skillgrove install launch-video. See ' + `${SITE}/skills`);
|
|
196
|
+
const agent = resolveAgent({ required: true });
|
|
197
|
+
const installed = await withToken(agent, async (token) => {
|
|
198
|
+
const done = [];
|
|
199
|
+
for (const slug of slugs) done.push(await installOne(token, slug, agent));
|
|
200
|
+
return done;
|
|
201
|
+
});
|
|
202
|
+
say();
|
|
203
|
+
say(`Ready in ${TARGETS[agent].label}. If it doesn't show up, start a new session. Try asking:`);
|
|
204
|
+
for (const s of installed) if (s.example) say(` ${s.example.split('\n')[0]}`);
|
|
205
|
+
finish({ installed: installed.map(summary) });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function cmdUpdate(slugs) {
|
|
209
|
+
const agent = resolveAgent({ required: false });
|
|
210
|
+
const dirs = allSkillDirs().filter((d) => (!agent || d.agent === agent) && (!opts.project || d.scope === 'project'));
|
|
211
|
+
const installed = listInstalled(dirs).filter((s) => slugs.length === 0 || slugs.includes(s.slug));
|
|
212
|
+
if (installed.length === 0) {
|
|
213
|
+
say('No SkillGrove skills to update here.');
|
|
214
|
+
finish({ updated: [] });
|
|
215
|
+
}
|
|
216
|
+
const results = await withToken(agent ?? installed[0].agent, async (token) => {
|
|
217
|
+
const out = [];
|
|
218
|
+
for (const s of installed) {
|
|
219
|
+
out.push(await installOne(token, s.slug, s.agent, { project: s.scope === 'project', quietIfCurrent: true }));
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
});
|
|
223
|
+
finish({ updated: results.filter((r) => r.updated).map(summary) });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function cmdList() {
|
|
227
|
+
const installed = listInstalled(allSkillDirs());
|
|
228
|
+
let latest = {};
|
|
229
|
+
try {
|
|
230
|
+
latest = Object.fromEntries((await catalog()).skills.map((s) => [s.slug, s.version]));
|
|
231
|
+
} catch {
|
|
232
|
+
// Offline: list without the "update available" note.
|
|
233
|
+
}
|
|
234
|
+
const rows = installed.map((s) => ({
|
|
235
|
+
slug: s.slug,
|
|
236
|
+
version: s.version,
|
|
237
|
+
agent: s.agent,
|
|
238
|
+
scope: s.scope,
|
|
239
|
+
path: s.path,
|
|
240
|
+
latest: latest[s.slug] ?? null,
|
|
241
|
+
}));
|
|
242
|
+
if (!asJson) {
|
|
243
|
+
if (rows.length === 0) say('No SkillGrove skills installed. Browse them at ' + `${SITE}/skills`);
|
|
244
|
+
for (const r of rows) {
|
|
245
|
+
const note = r.latest && r.latest !== r.version ? ` (update available: ${r.latest})` : '';
|
|
246
|
+
say(
|
|
247
|
+
`${r.slug} ${r.version} ${TARGETS[r.agent].label}, ${r.scope === 'user' ? 'all projects' : 'this project'}${note}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
finish({ skills: rows });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function cmdLogin() {
|
|
255
|
+
const agent = resolveAgent({ required: false });
|
|
256
|
+
if (savedLogin()) forgetLogin();
|
|
257
|
+
const { email } = await login({ agent, say, open: shouldOpen });
|
|
258
|
+
finish({ email });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function cmdLogout() {
|
|
262
|
+
const saved = savedLogin();
|
|
263
|
+
if (saved) {
|
|
264
|
+
await logout(saved.token).catch(() => {});
|
|
265
|
+
forgetLogin();
|
|
266
|
+
}
|
|
267
|
+
say(saved ? 'Signed out. This device can no longer install skills with your account.' : 'Not signed in.');
|
|
268
|
+
finish({});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function cmdWhoami() {
|
|
272
|
+
const saved = savedLogin();
|
|
273
|
+
if (!saved) fail('unauthorized', 'Not signed in. Run: npx skillgrove login');
|
|
274
|
+
const me = await whoami(saved.token).catch((error) => {
|
|
275
|
+
if (error.code === 'unauthorized') forgetLogin();
|
|
276
|
+
throw error;
|
|
277
|
+
});
|
|
278
|
+
say(
|
|
279
|
+
`${me.email} · ${me.plan === 'free' ? 'Free plan' : me.plan === 'lifetime' ? 'Lifetime' : 'Pro yearly'} · ${SITE}`
|
|
280
|
+
);
|
|
281
|
+
finish(me);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const COMMANDS = {
|
|
285
|
+
install: cmdInstall,
|
|
286
|
+
add: cmdInstall,
|
|
287
|
+
update: cmdUpdate,
|
|
288
|
+
list: cmdList,
|
|
289
|
+
ls: cmdList,
|
|
290
|
+
login: cmdLogin,
|
|
291
|
+
logout: cmdLogout,
|
|
292
|
+
whoami: cmdWhoami,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
if (opts.version) {
|
|
296
|
+
console.log(VERSION);
|
|
297
|
+
process.exit(0);
|
|
298
|
+
}
|
|
299
|
+
if (opts.help || !command || command === 'help') {
|
|
300
|
+
console.log(HELP);
|
|
301
|
+
process.exit(command || opts.help ? 0 : 2);
|
|
302
|
+
}
|
|
303
|
+
if (!COMMANDS[command]) {
|
|
304
|
+
console.error(`Unknown command "${command}".\n\n${HELP}`);
|
|
305
|
+
process.exit(2);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
try {
|
|
309
|
+
await COMMANDS[command](rest);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (error instanceof ApiError || error instanceof InstallError)
|
|
312
|
+
fail(error.code, error.message, error.url ? { url: error.url } : {});
|
|
313
|
+
if (error instanceof ZipError) fail('bad_zip', `${error.message} Nothing was installed.`);
|
|
314
|
+
fail('unexpected', error?.stack ?? String(error));
|
|
315
|
+
}
|
package/lib/api.mjs
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Talking to skillgrove.dev: the install token on disk, the device sign-in, and the
|
|
2
|
+
// /api/cli/* calls. The token is never printed and never part of --json output.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { homedir, platform, release } from 'node:os';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
9
|
+
export const CLIENT_ID = 'skillgrove-cli';
|
|
10
|
+
|
|
11
|
+
/** The site to talk to. SKILLGROVE_URL points it at a local dev server. */
|
|
12
|
+
export const SITE = (process.env.SKILLGROVE_URL || 'https://skillgrove.dev').replace(/\/+$/, '');
|
|
13
|
+
|
|
14
|
+
export class ApiError extends Error {
|
|
15
|
+
constructor(code, message, extra = {}) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.code = code;
|
|
18
|
+
Object.assign(this, extra);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------- credentials on disk
|
|
23
|
+
|
|
24
|
+
export function credentialsPath(env = process.env) {
|
|
25
|
+
const base =
|
|
26
|
+
platform() === 'win32'
|
|
27
|
+
? env.APPDATA || join(homedir(), 'AppData', 'Roaming')
|
|
28
|
+
: env.XDG_CONFIG_HOME || join(homedir(), '.config');
|
|
29
|
+
return join(base, 'skillgrove', 'credentials.json');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readCredentials() {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(readFileSync(credentialsPath(), 'utf8'));
|
|
35
|
+
} catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The saved sign-in for SITE: { token, email } or null. Kept per site, so dev and live don't mix. */
|
|
41
|
+
export function savedLogin() {
|
|
42
|
+
const entry = readCredentials()[SITE];
|
|
43
|
+
return entry?.token ? entry : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function writeCredentials(all) {
|
|
47
|
+
const file = credentialsPath();
|
|
48
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
49
|
+
writeFileSync(file, JSON.stringify(all, null, 2) + '\n', { mode: 0o600 });
|
|
50
|
+
if (platform() !== 'win32') chmodSync(file, 0o600);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function saveLogin(login) {
|
|
54
|
+
writeCredentials({ ...readCredentials(), [SITE]: login });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function forgetLogin() {
|
|
58
|
+
const all = readCredentials();
|
|
59
|
+
delete all[SITE];
|
|
60
|
+
if (Object.keys(all).length) writeCredentials(all);
|
|
61
|
+
else rmSync(credentialsPath(), { force: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------- HTTP
|
|
65
|
+
|
|
66
|
+
const OS_NAMES = { darwin: 'macOS', win32: 'Windows', linux: 'Linux' };
|
|
67
|
+
|
|
68
|
+
/** What the account page and the approval page call this device. */
|
|
69
|
+
export function deviceLabel(agent) {
|
|
70
|
+
const os = OS_NAMES[platform()] ?? platform();
|
|
71
|
+
const AGENT_NAMES = { 'claude-code': 'Claude Code', codex: 'Codex', cursor: 'Cursor' };
|
|
72
|
+
return agent ? `${os} · ${AGENT_NAMES[agent] ?? agent}` : `${os} · terminal`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const baseHeaders = () => ({
|
|
76
|
+
'user-agent': `skillgrove-cli/${VERSION} (node ${process.version}; ${platform()} ${release()})`,
|
|
77
|
+
'x-skillgrove-cli': VERSION,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
async function request(path, { method = 'GET', token, body, accept = 'application/json' } = {}) {
|
|
81
|
+
const headers = { ...baseHeaders(), accept };
|
|
82
|
+
if (token) headers.authorization = `Bearer ${token}`;
|
|
83
|
+
if (body !== undefined) headers['content-type'] = 'application/json';
|
|
84
|
+
let res;
|
|
85
|
+
try {
|
|
86
|
+
res = await fetch(`${SITE}${path}`, {
|
|
87
|
+
method,
|
|
88
|
+
headers,
|
|
89
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
90
|
+
});
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw new ApiError(
|
|
93
|
+
'network',
|
|
94
|
+
`Can't reach ${SITE} (${error.cause?.code ?? error.message}). Check the connection and try again.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return res;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function json(res) {
|
|
101
|
+
const data = await res.json().catch(() => null);
|
|
102
|
+
if (!res.ok) {
|
|
103
|
+
throw new ApiError(
|
|
104
|
+
data?.error ?? `http_${res.status}`,
|
|
105
|
+
data?.message ?? data?.error_description ?? `${SITE} answered ${res.status}.`,
|
|
106
|
+
{ status: res.status, ...(data?.url && { url: data.url }) }
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return data;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------- device sign-in
|
|
113
|
+
|
|
114
|
+
/** Opens a URL in the default browser; quietly does nothing if it can't. */
|
|
115
|
+
export function openBrowser(url) {
|
|
116
|
+
const [cmd, args] =
|
|
117
|
+
platform() === 'darwin'
|
|
118
|
+
? ['open', [url]]
|
|
119
|
+
: platform() === 'win32'
|
|
120
|
+
? ['cmd', ['/c', 'start', '', url.replace(/&/g, '^&')]]
|
|
121
|
+
: ['xdg-open', [url]];
|
|
122
|
+
try {
|
|
123
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
124
|
+
child.on('error', () => {});
|
|
125
|
+
child.unref();
|
|
126
|
+
} catch {
|
|
127
|
+
// No browser here (SSH, CI): the URL is printed anyway.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Signs this device in: shows a code, opens /device, waits for the user to approve it,
|
|
135
|
+
* then swaps the session for an install token. `say` prints progress for the user.
|
|
136
|
+
*/
|
|
137
|
+
export async function login({ agent, say, open = true }) {
|
|
138
|
+
const label = deviceLabel(agent);
|
|
139
|
+
const device = await json(await request('/api/cli/login', { method: 'POST', body: { label } }));
|
|
140
|
+
const code =
|
|
141
|
+
device.user_code.length === 8 ? `${device.user_code.slice(0, 4)}-${device.user_code.slice(4)}` : device.user_code;
|
|
142
|
+
|
|
143
|
+
say(`To sign in, open ${device.verification_uri_complete}`);
|
|
144
|
+
say(`and check that it shows the code ${code}. Then click Approve.`);
|
|
145
|
+
if (open) openBrowser(device.verification_uri_complete);
|
|
146
|
+
say('Waiting for approval (the code works for 10 minutes)...');
|
|
147
|
+
|
|
148
|
+
let interval = (device.interval || 5) * 1000;
|
|
149
|
+
const deadline = Date.now() + device.expires_in * 1000;
|
|
150
|
+
while (Date.now() < deadline) {
|
|
151
|
+
await sleep(interval);
|
|
152
|
+
const res = await request('/api/auth/device/token', {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
body: {
|
|
155
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
156
|
+
device_code: device.device_code,
|
|
157
|
+
client_id: CLIENT_ID,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const data = await res.json().catch(() => ({}));
|
|
161
|
+
if (res.ok && data.access_token) {
|
|
162
|
+
const issued = await json(
|
|
163
|
+
await request('/api/cli/exchange', { method: 'POST', token: data.access_token, body: { label } })
|
|
164
|
+
);
|
|
165
|
+
saveLogin({ token: issued.token, email: issued.email });
|
|
166
|
+
say(`Signed in as ${issued.email}.`);
|
|
167
|
+
return { email: issued.email };
|
|
168
|
+
}
|
|
169
|
+
if (data.error === 'authorization_pending') continue;
|
|
170
|
+
if (data.error === 'slow_down') {
|
|
171
|
+
interval += 5000;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (data.error === 'access_denied') throw new ApiError('access_denied', 'The sign-in was denied in the browser.');
|
|
175
|
+
if (data.error === 'expired_token') break;
|
|
176
|
+
throw new ApiError(data.error ?? 'login_failed', data.error_description ?? `Sign-in failed (${res.status}).`);
|
|
177
|
+
}
|
|
178
|
+
throw new ApiError('expired', 'The sign-in code expired before it was approved. Run the command again.');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---------------------------------------------------------------- CLI API
|
|
182
|
+
|
|
183
|
+
export const whoami = (token) => request('/api/cli/whoami', { token }).then(json);
|
|
184
|
+
export const logout = (token) => request('/api/cli/logout', { method: 'POST', token }).then(json);
|
|
185
|
+
export const skillStatus = (token, slug) =>
|
|
186
|
+
request(`/api/cli/skills/${encodeURIComponent(slug)}`, { token }).then(json);
|
|
187
|
+
|
|
188
|
+
/** The skill's zip and the checksum the server sent with it. */
|
|
189
|
+
export async function downloadSkill(token, slug) {
|
|
190
|
+
const res = await request(`/api/cli/download/${encodeURIComponent(slug)}`, { token, accept: 'application/zip' });
|
|
191
|
+
if (!res.ok) await json(res);
|
|
192
|
+
return { zip: Buffer.from(await res.arrayBuffer()), sha256: res.headers.get('x-skillgrove-sha256') };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The public catalog (no sign-in needed): versions for `list`. */
|
|
196
|
+
export const catalog = () => request('/skills.json').then(json);
|
package/lib/install.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Where skills go and how a zip becomes a skill folder: unpacked into a temporary folder
|
|
2
|
+
// next to the target, then swapped in, so a failed install never leaves half a skill.
|
|
3
|
+
// Each installed folder gets a `.skillgrove.json` marker; folders without one (the user's
|
|
4
|
+
// own skills) are never overwritten unless --force, which keeps a backup.
|
|
5
|
+
import {
|
|
6
|
+
existsSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
renameSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
chmodSync,
|
|
14
|
+
} from 'node:fs';
|
|
15
|
+
import { homedir } from 'node:os';
|
|
16
|
+
import { join, resolve, sep } from 'node:path';
|
|
17
|
+
|
|
18
|
+
import { readZip, safeEntryPath } from './zip.mjs';
|
|
19
|
+
|
|
20
|
+
/** Skills folders per agent; the website reads the same file (src/lib/skills.ts). */
|
|
21
|
+
export const TARGETS = JSON.parse(readFileSync(new URL('./targets.json', import.meta.url), 'utf8'));
|
|
22
|
+
export const AGENTS = Object.keys(TARGETS);
|
|
23
|
+
export const MARKER = '.skillgrove.json';
|
|
24
|
+
|
|
25
|
+
const expandHome = (dir) => (dir.startsWith('~/') ? join(homedir(), dir.slice(2)) : dir);
|
|
26
|
+
|
|
27
|
+
/** The skills folder for an agent: the user-wide one, or the project's with `project`. */
|
|
28
|
+
export function skillsDir(agent, { project = false, cwd = process.cwd() } = {}) {
|
|
29
|
+
const target = TARGETS[agent];
|
|
30
|
+
if (!target) throw new Error(`Unknown agent "${agent}". Use one of: ${AGENTS.join(', ')}.`);
|
|
31
|
+
return project ? resolve(cwd, target.project) : expandHome(target.user);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The agent this process runs under, when it says so in the environment; else null. */
|
|
35
|
+
export function detectAgent(env = process.env) {
|
|
36
|
+
if (env.CLAUDECODE === '1') return 'claude-code';
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readMarker(dir) {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(readFileSync(join(dir, MARKER), 'utf8'));
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Every SkillGrove skill installed in the given skills folders. */
|
|
49
|
+
export function listInstalled(dirs) {
|
|
50
|
+
const found = [];
|
|
51
|
+
for (const { agent, scope, dir } of dirs) {
|
|
52
|
+
if (!existsSync(dir)) continue;
|
|
53
|
+
for (const name of readdirSync(dir)) {
|
|
54
|
+
const marker = readMarker(join(dir, name));
|
|
55
|
+
if (marker?.slug === name) found.push({ agent, scope, dir, path: join(dir, name), ...marker });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** All folders the CLI may have installed into: every agent, user-wide and this project. */
|
|
62
|
+
export function allSkillDirs(cwd = process.cwd()) {
|
|
63
|
+
return AGENTS.flatMap((agent) => [
|
|
64
|
+
{ agent, scope: 'user', dir: skillsDir(agent) },
|
|
65
|
+
{ agent, scope: 'project', dir: skillsDir(agent, { project: true, cwd }) },
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class InstallError extends Error {
|
|
70
|
+
constructor(code, message) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.code = code;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Unpacks a verified skill zip into `<dir>/<slug>/`. Returns { path, replaced, backup }.
|
|
78
|
+
* Refuses to overwrite a folder SkillGrove didn't install unless `force` (then the old
|
|
79
|
+
* folder is renamed to `<slug>.bak-<time>`).
|
|
80
|
+
*/
|
|
81
|
+
export function installZip(zip, { slug, dir, version, sha256, source, force = false, now = new Date() }) {
|
|
82
|
+
const entries = readZip(zip);
|
|
83
|
+
const files = entries.map((e) => ({ ...e, parts: safeEntryPath(e.name, slug) }));
|
|
84
|
+
if (!files.some((f) => !f.dir && f.parts.length === 1 && f.parts[0] === 'SKILL.md')) {
|
|
85
|
+
throw new InstallError('bad_zip', `The zip has no ${slug}/SKILL.md.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const dest = join(dir, slug);
|
|
89
|
+
const existing = existsSync(dest);
|
|
90
|
+
const ours = existing && readMarker(dest)?.slug === slug;
|
|
91
|
+
if (existing && !ours && !force) {
|
|
92
|
+
throw new InstallError(
|
|
93
|
+
'exists',
|
|
94
|
+
`${dest} already exists and wasn't installed by SkillGrove. Move it away, or run again with --force (it keeps a backup).`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
mkdirSync(dir, { recursive: true });
|
|
99
|
+
const stamp = `${now.getTime().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
100
|
+
const temp = join(dir, `.${slug}.skillgrove-new-${stamp}`);
|
|
101
|
+
try {
|
|
102
|
+
mkdirSync(temp);
|
|
103
|
+
for (const f of files) {
|
|
104
|
+
const target = join(temp, ...f.parts);
|
|
105
|
+
if (!resolve(target).startsWith(resolve(temp) + sep) && resolve(target) !== resolve(temp)) {
|
|
106
|
+
throw new InstallError('bad_zip', `Refused path: ${f.name}`);
|
|
107
|
+
}
|
|
108
|
+
if (f.dir) {
|
|
109
|
+
mkdirSync(target, { recursive: true });
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
mkdirSync(join(target, '..'), { recursive: true });
|
|
113
|
+
writeFileSync(target, f.data);
|
|
114
|
+
// Executable scripts stay executable; everything else is plain read/write.
|
|
115
|
+
if (process.platform !== 'win32') chmodSync(target, f.mode && f.mode & 0o111 ? 0o755 : 0o644);
|
|
116
|
+
}
|
|
117
|
+
writeFileSync(
|
|
118
|
+
join(temp, MARKER),
|
|
119
|
+
JSON.stringify({ slug, version, sha256, installed_at: now.toISOString(), source }, null, 2) + '\n'
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
let backup = null;
|
|
123
|
+
let old = null;
|
|
124
|
+
if (existing && ours) {
|
|
125
|
+
old = join(dir, `.${slug}.skillgrove-old-${stamp}`);
|
|
126
|
+
renameSync(dest, old);
|
|
127
|
+
} else if (existing) {
|
|
128
|
+
backup = join(dir, `${slug}.bak-${now.toISOString().replace(/[:.]/g, '-')}`);
|
|
129
|
+
renameSync(dest, backup);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
renameSync(temp, dest);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (old) renameSync(old, dest);
|
|
135
|
+
if (backup) renameSync(backup, dest);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
if (old) rmSync(old, { recursive: true, force: true });
|
|
139
|
+
return { path: dest, replaced: Boolean(existing), backup };
|
|
140
|
+
} finally {
|
|
141
|
+
rmSync(temp, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
}
|
package/lib/targets.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"claude-code": {
|
|
3
|
+
"label": "Claude Code",
|
|
4
|
+
"user": "~/.claude/skills",
|
|
5
|
+
"project": ".claude/skills",
|
|
6
|
+
"docs": "https://code.claude.com/docs/en/skills"
|
|
7
|
+
},
|
|
8
|
+
"codex": {
|
|
9
|
+
"label": "Codex",
|
|
10
|
+
"user": "~/.agents/skills",
|
|
11
|
+
"project": ".agents/skills",
|
|
12
|
+
"docs": "https://developers.openai.com/codex/build-skills"
|
|
13
|
+
},
|
|
14
|
+
"cursor": {
|
|
15
|
+
"label": "Cursor",
|
|
16
|
+
"user": "~/.cursor/skills",
|
|
17
|
+
"project": ".cursor/skills",
|
|
18
|
+
"docs": "https://cursor.com/docs/skills"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/lib/zip.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// A small ZIP reader for the zips SkillGrove serves (stored or deflate entries, no
|
|
2
|
+
// encryption, no ZIP64). Every name is checked before anything is written: see
|
|
3
|
+
// safeEntryPath(). Uses only node:zlib.
|
|
4
|
+
import { crc32, inflateRawSync } from 'node:zlib';
|
|
5
|
+
|
|
6
|
+
/** Limits on what one skill zip may unpack to. */
|
|
7
|
+
export const MAX_TOTAL_BYTES = 100 * 1024 * 1024;
|
|
8
|
+
export const MAX_ENTRIES = 5000;
|
|
9
|
+
|
|
10
|
+
const EOCD = 0x06054b50;
|
|
11
|
+
const CENTRAL = 0x02014b50;
|
|
12
|
+
const LOCAL = 0x04034b50;
|
|
13
|
+
|
|
14
|
+
export class ZipError extends Error {}
|
|
15
|
+
|
|
16
|
+
function findEnd(buf) {
|
|
17
|
+
const stop = Math.max(0, buf.length - 22 - 0xffff);
|
|
18
|
+
for (let i = buf.length - 22; i >= stop; i--) if (buf.readUInt32LE(i) === EOCD) return i;
|
|
19
|
+
throw new ZipError('Not a zip file (no end of central directory).');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The entries of a zip: { name, dir, mode, data } with data already inflated and its
|
|
24
|
+
* CRC checked. `mode` is the Unix permission bits when the zip recorded them, else null.
|
|
25
|
+
* Symbolic links and anything that isn't a plain file or folder are refused.
|
|
26
|
+
*/
|
|
27
|
+
export function readZip(buf) {
|
|
28
|
+
const end = findEnd(buf);
|
|
29
|
+
const count = buf.readUInt16LE(end + 10);
|
|
30
|
+
const size = buf.readUInt32LE(end + 12);
|
|
31
|
+
let offset = buf.readUInt32LE(end + 16);
|
|
32
|
+
if (count === 0xffff || size === 0xffffffff || offset === 0xffffffff) throw new ZipError('ZIP64 is not supported.');
|
|
33
|
+
if (count > MAX_ENTRIES) throw new ZipError(`Too many files in the zip (${count}).`);
|
|
34
|
+
|
|
35
|
+
const entries = [];
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (let i = 0; i < count; i++) {
|
|
38
|
+
if (offset + 46 > buf.length || buf.readUInt32LE(offset) !== CENTRAL)
|
|
39
|
+
throw new ZipError('Corrupt central directory.');
|
|
40
|
+
const madeBy = buf.readUInt16LE(offset + 4);
|
|
41
|
+
const flags = buf.readUInt16LE(offset + 8);
|
|
42
|
+
const method = buf.readUInt16LE(offset + 10);
|
|
43
|
+
const crc = buf.readUInt32LE(offset + 16);
|
|
44
|
+
const compressed = buf.readUInt32LE(offset + 20);
|
|
45
|
+
const uncompressed = buf.readUInt32LE(offset + 24);
|
|
46
|
+
const nameLen = buf.readUInt16LE(offset + 28);
|
|
47
|
+
const extraLen = buf.readUInt16LE(offset + 30);
|
|
48
|
+
const commentLen = buf.readUInt16LE(offset + 32);
|
|
49
|
+
const attrs = buf.readUInt32LE(offset + 38);
|
|
50
|
+
const local = buf.readUInt32LE(offset + 42);
|
|
51
|
+
const name = buf.subarray(offset + 46, offset + 46 + nameLen).toString('utf8');
|
|
52
|
+
offset += 46 + nameLen + extraLen + commentLen;
|
|
53
|
+
|
|
54
|
+
if (flags & 1) throw new ZipError(`${name}: encrypted entries are not supported.`);
|
|
55
|
+
const unixMode = madeBy >> 8 === 3 ? attrs >>> 16 : 0;
|
|
56
|
+
const type = unixMode & 0o170000;
|
|
57
|
+
const dir = name.endsWith('/') || type === 0o040000;
|
|
58
|
+
if (type && type !== 0o100000 && type !== 0o040000)
|
|
59
|
+
throw new ZipError(`${name}: links and special files are refused.`);
|
|
60
|
+
|
|
61
|
+
total += uncompressed;
|
|
62
|
+
if (total > MAX_TOTAL_BYTES) throw new ZipError('The zip unpacks to more than 100 MB.');
|
|
63
|
+
|
|
64
|
+
let data = Buffer.alloc(0);
|
|
65
|
+
if (!dir) {
|
|
66
|
+
if (local + 30 > buf.length || buf.readUInt32LE(local) !== LOCAL) throw new ZipError(`${name}: corrupt entry.`);
|
|
67
|
+
const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28);
|
|
68
|
+
const raw = buf.subarray(start, start + compressed);
|
|
69
|
+
if (raw.length !== compressed) throw new ZipError(`${name}: truncated.`);
|
|
70
|
+
if (method === 0) data = Buffer.from(raw);
|
|
71
|
+
else if (method === 8) data = inflateRawSync(raw, { maxOutputLength: Math.max(uncompressed, 1) });
|
|
72
|
+
else throw new ZipError(`${name}: compression method ${method} is not supported.`);
|
|
73
|
+
if (data.length !== uncompressed || crc32(data) !== crc) throw new ZipError(`${name}: checksum mismatch.`);
|
|
74
|
+
}
|
|
75
|
+
entries.push({ name, dir, mode: unixMode ? unixMode & 0o777 : null, data });
|
|
76
|
+
}
|
|
77
|
+
return entries;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The entry's path inside the skill folder, as path segments, or an error. Every entry
|
|
82
|
+
* must sit under `<slug>/`; absolute paths, drive letters, backslashes, `.` and `..`
|
|
83
|
+
* segments are refused, so nothing can be written outside the skill folder.
|
|
84
|
+
*/
|
|
85
|
+
export function safeEntryPath(name, slug) {
|
|
86
|
+
if (name.includes('\\') || name.includes('\0') || name.startsWith('/') || /^[a-zA-Z]:/.test(name)) {
|
|
87
|
+
throw new ZipError(`Refused unsafe path in zip: ${name}`);
|
|
88
|
+
}
|
|
89
|
+
const parts = name.replace(/\/$/, '').split('/');
|
|
90
|
+
if (parts[0] !== slug) throw new ZipError(`Refused path outside the ${slug}/ folder: ${name}`);
|
|
91
|
+
const rest = parts.slice(1);
|
|
92
|
+
if (rest.some((p) => p === '' || p === '.' || p === '..')) throw new ZipError(`Refused unsafe path in zip: ${name}`);
|
|
93
|
+
return rest;
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skillgrove",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install SkillGrove Agent Skills into Claude Code, Codex or Cursor with one command.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent-skills",
|
|
7
|
+
"claude-code",
|
|
8
|
+
"codex",
|
|
9
|
+
"cursor",
|
|
10
|
+
"skills"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://skillgrove.dev/install/agent.md",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"skillgrove": "bin/skillgrove.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"lib/",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.2"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "node --test test/*.test.mjs"
|
|
29
|
+
}
|
|
30
|
+
}
|