slliks 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/README.md +83 -2
- package/dist/banner.js +20 -0
- package/dist/cli.js +360 -0
- package/dist/github.js +133 -0
- package/dist/link.js +44 -0
- package/dist/prompt.js +84 -0
- package/dist/skills.js +110 -0
- package/dist/targets.js +53 -0
- package/package.json +32 -4
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# slliks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`skills` de trás pra frente. Um CLI pequeno para instalar agent skills (pastas com `SKILL.md`)
|
|
4
|
+
direto de uma URL do GitHub, no projeto ou no seu diretório de skills de usuário.
|
|
5
|
+
|
|
6
|
+
Pergunta só o que você não informou, sem telemetria, sem dependências em runtime e sem lockfile no projeto:
|
|
7
|
+
ele só copia a pasta da skill para o lugar certo.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx slliks add https://github.com/anthropics/skills/tree/main/skills/pdf
|
|
11
|
+
# ou, instalado globalmente (npm i -g slliks), use o atalho:
|
|
12
|
+
lliks add anthropics/skills -s pdf -g
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Comandos
|
|
16
|
+
|
|
17
|
+
| Comando | O que faz |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `slliks add <source>` | Instala skill(s) (aliases: `install`, `i`) |
|
|
20
|
+
| `slliks find <source>` | Lista as skills disponíveis na fonte |
|
|
21
|
+
| `slliks list` | Lista as skills instaladas (`ls`) |
|
|
22
|
+
| `slliks remove <name...>` | Remove skills instaladas (`rm`), incluindo os links |
|
|
23
|
+
| `slliks link [name...]` | Cria links de `.agents/skills` nas outras pastas de agente |
|
|
24
|
+
|
|
25
|
+
## Fontes aceitas
|
|
26
|
+
|
|
27
|
+
- `owner/repo` ou `owner/repo/caminho/da/skill`
|
|
28
|
+
- `https://github.com/owner/repo`
|
|
29
|
+
- `https://github.com/owner/repo/tree/<branch>/<caminho>`
|
|
30
|
+
- `https://github.com/owner/repo/blob/<branch>/<caminho>/SKILL.md`
|
|
31
|
+
- `https://raw.githubusercontent.com/owner/repo/<branch>/<caminho>/SKILL.md`
|
|
32
|
+
|
|
33
|
+
Se a fonte tiver várias skills, ele mostra uma lista para escolher; ou passe `-s <name>` (repetível) / `--all`.
|
|
34
|
+
|
|
35
|
+
## Opções
|
|
36
|
+
|
|
37
|
+
| Flag | |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `-g, --global` | instala no usuário (`~`), vale pra todos os projetos |
|
|
40
|
+
| `-p, --project` | instala no projeto atual |
|
|
41
|
+
| `-y, --yes` | não pergunta nada, usa os padrões |
|
|
42
|
+
| `-a, --agent <list>` | `cursor`, `claude`, `agents` ou `all` (separados por vírgula) |
|
|
43
|
+
| `-d, --dir <path>` | diretório de skills explícito |
|
|
44
|
+
| `-s, --skill <name>` | escolhe a skill (repetível) |
|
|
45
|
+
| `--all` | instala todas |
|
|
46
|
+
| `-n, --name <name>` | renomeia a skill instalada |
|
|
47
|
+
| `-f, --force` | sobrescreve (ou troca uma cópia por link) |
|
|
48
|
+
| `-l, --link` | uma cópia em `.agents/skills`, symlinks nas outras pastas |
|
|
49
|
+
| `--copy` | cópia independente em cada pasta |
|
|
50
|
+
|
|
51
|
+
**Projeto ou usuário?** No terminal, se você não passar `-g`/`-p`, ele pergunta;
|
|
52
|
+
o mesmo vale para a pasta do agente (sem `-a`) e para quais skills (sem `-s`/`--all`).
|
|
53
|
+
|
|
54
|
+
Com `--yes`, ou fora de um terminal (CI, scripts), ele não pergunta: instala no projeto,
|
|
55
|
+
na primeira pasta que existir entre `.cursor`, `.claude` e `.agents` (senão `.cursor/skills`).
|
|
56
|
+
`$SLLIKS_AGENT` fixa a pasta.
|
|
57
|
+
|
|
58
|
+
## Uma pasta só para todos os agentes (`--link`)
|
|
59
|
+
|
|
60
|
+
Se você usa mais de um agente (Claude, Cursor…), não precisa de uma cópia da skill em cada pasta:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
lliks add owner/repo -s pdf --link
|
|
64
|
+
# ✓ pdf → .agents/skills/pdf
|
|
65
|
+
# ↳ .cursor/skills/pdf (link)
|
|
66
|
+
# ↳ .claude/skills/pdf (link)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
A cópia real fica em `.agents/skills`, e as outras pastas viram symlinks relativos para ela
|
|
70
|
+
(junction no Windows). Sem `-a`, ele cria links em todas as pastas de agente que já existem.
|
|
71
|
+
No modo interativo, se você marcar mais de uma pasta, ele pergunta se quer **Link** ou **Copy**.
|
|
72
|
+
|
|
73
|
+
Já tem skills em `.agents/skills`? Unifique com `lliks link` (use `--force` para trocar
|
|
74
|
+
cópias antigas em `.claude`/`.cursor` por links). `lliks rm <name>` remove a cópia e os links.
|
|
75
|
+
|
|
76
|
+
**Repos privados / rate limit:** defina `GITHUB_TOKEN` (ou `GH_TOKEN`).
|
|
77
|
+
|
|
78
|
+
## Desenvolvimento
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install
|
|
82
|
+
npm run build
|
|
83
|
+
npm test
|
|
84
|
+
```
|
package/dist/banner.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const LETTERS = {
|
|
2
|
+
s: ['█▀▀▀', '▀▀▀█', '▀▀▀▀'],
|
|
3
|
+
l: ['█ ', '█ ', '▀▀▀▀'],
|
|
4
|
+
i: ['█', '█', '▀'],
|
|
5
|
+
k: ['█ ▄▀', '█▀▄ ', '▀ ▀'],
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Two-tone block logo: the leading "s" dimmed, "lliks" bright,
|
|
9
|
+
* so both command names read in one mark.
|
|
10
|
+
*/
|
|
11
|
+
export function banner(version, useColor) {
|
|
12
|
+
const dim = (s) => (useColor ? `\x1b[90m${s}\x1b[0m` : s);
|
|
13
|
+
const bright = (s) => (useColor ? `\x1b[1;97m${s}\x1b[0m` : s);
|
|
14
|
+
const rows = [0, 1, 2].map((r) => {
|
|
15
|
+
const head = LETTERS.s[r];
|
|
16
|
+
const tail = [...'lliks'].map((ch) => LETTERS[ch][r]).join(' ');
|
|
17
|
+
return ` ${dim(head)} ${bright(tail)}`;
|
|
18
|
+
});
|
|
19
|
+
return `\n${rows.join('\n')}\n ${dim(`skills, backwards · v${version}`)}\n`;
|
|
20
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { promises as fs } from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { GitHubClient, parseSource } from './github.js';
|
|
8
|
+
import { discoverSkills, installSkill, listLocalSkills, sanitizeName } from './skills.js';
|
|
9
|
+
import { AGENTS, CANONICAL_AGENT, baseDir, detectAgent, existingAgents, installTargets, scanTargets } from './targets.js';
|
|
10
|
+
import { linkSkill, linkTarget } from './link.js';
|
|
11
|
+
import { canPrompt, multiselect, select } from './prompt.js';
|
|
12
|
+
import { banner } from './banner.js';
|
|
13
|
+
const color = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
14
|
+
const c = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
15
|
+
const dim = c(2);
|
|
16
|
+
const green = c(32);
|
|
17
|
+
const red = c(31);
|
|
18
|
+
const bold = c(1);
|
|
19
|
+
const cyan = c(36);
|
|
20
|
+
const HELP = `${bold('slliks')} ${dim('(alias: lliks)')} — install agent skills from GitHub
|
|
21
|
+
|
|
22
|
+
${bold('Usage')}
|
|
23
|
+
slliks add <source> [options] install skill(s)
|
|
24
|
+
slliks find <source> list skills available at <source>
|
|
25
|
+
slliks list [options] list installed skills (alias: ls)
|
|
26
|
+
slliks remove <name...> [options] remove installed skills (alias: rm)
|
|
27
|
+
slliks link [name...] [options] symlink .agents/skills into other agent folders
|
|
28
|
+
|
|
29
|
+
${bold('Source')}
|
|
30
|
+
owner/repo[/path]
|
|
31
|
+
https://github.com/owner/repo
|
|
32
|
+
https://github.com/owner/repo/tree/<branch>/<path/to/skill>
|
|
33
|
+
https://github.com/owner/repo/blob/<branch>/<path>/SKILL.md
|
|
34
|
+
|
|
35
|
+
${bold('Options')}
|
|
36
|
+
-g, --global install for the user (~), all projects
|
|
37
|
+
-p, --project install in the current project
|
|
38
|
+
-a, --agent <list> cursor | claude | agents | all (comma separated)
|
|
39
|
+
-d, --dir <path> install into an explicit skills directory
|
|
40
|
+
-s, --skill <name> pick a skill when the source has several (repeatable)
|
|
41
|
+
--all install every skill found at the source
|
|
42
|
+
-n, --name <name> rename the installed skill (single skill only)
|
|
43
|
+
-f, --force overwrite an existing skill (or replace a copy with a link)
|
|
44
|
+
-l, --link one copy in .agents/skills, symlinks in the other folders
|
|
45
|
+
--copy independent copy in each folder (skips the question)
|
|
46
|
+
-y, --yes never ask; use defaults (project + detected folder)
|
|
47
|
+
-h, --help show this help
|
|
48
|
+
-v, --version show version
|
|
49
|
+
|
|
50
|
+
${bold('Defaults')}
|
|
51
|
+
In a terminal, add asks what you left out: which skills, project or user,
|
|
52
|
+
and which agent folder. With --yes or no TTY (CI, scripts) it does not ask:
|
|
53
|
+
project scope, first existing of .cursor/.claude/.agents, else .cursor.
|
|
54
|
+
$SLLIKS_AGENT sets the folder. Private repos / rate limits: set $GITHUB_TOKEN.
|
|
55
|
+
`;
|
|
56
|
+
function version() {
|
|
57
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
58
|
+
return pkg.version;
|
|
59
|
+
}
|
|
60
|
+
function tilde(p) {
|
|
61
|
+
const home = os.homedir();
|
|
62
|
+
return p.startsWith(home + path.sep) ? `~${p.slice(home.length)}` : path.relative(process.cwd(), p) || '.';
|
|
63
|
+
}
|
|
64
|
+
async function resolveSource(input, gh) {
|
|
65
|
+
const src = parseSource(input);
|
|
66
|
+
const ref = {
|
|
67
|
+
owner: src.owner,
|
|
68
|
+
repo: src.repo,
|
|
69
|
+
branch: src.branch || (await gh.defaultBranch(src.owner, src.repo)),
|
|
70
|
+
};
|
|
71
|
+
const skills = discoverSkills(await gh.tree(ref), src.path, src.repo);
|
|
72
|
+
if (skills.length === 0) {
|
|
73
|
+
throw new Error(`No SKILL.md found at ${src.owner}/${src.repo}${src.path ? `/${src.path}` : ''} (${ref.branch})`);
|
|
74
|
+
}
|
|
75
|
+
return { ref, skills };
|
|
76
|
+
}
|
|
77
|
+
function printRemote(skills) {
|
|
78
|
+
const w = Math.max(...skills.map((s) => s.name.length));
|
|
79
|
+
for (const s of skills)
|
|
80
|
+
console.log(` ${s.name.padEnd(w)} ${dim(s.folder || '(repo root)')}`);
|
|
81
|
+
}
|
|
82
|
+
async function cmdAdd(source, v, t) {
|
|
83
|
+
if (interactive(v))
|
|
84
|
+
console.log(banner(version(), !!color));
|
|
85
|
+
const gh = new GitHubClient();
|
|
86
|
+
const { ref, skills } = await resolveSource(source, gh);
|
|
87
|
+
let chosen;
|
|
88
|
+
const wanted = v.skill ?? [];
|
|
89
|
+
if (wanted.length > 0) {
|
|
90
|
+
chosen = wanted.map((w) => {
|
|
91
|
+
const hit = skills.find((s) => s.name === w || s.folder === w);
|
|
92
|
+
if (!hit)
|
|
93
|
+
throw new Error(`Skill "${w}" not found. Available: ${skills.map((s) => s.name).join(', ')}`);
|
|
94
|
+
return hit;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (skills.length === 1 || v.all) {
|
|
98
|
+
chosen = skills;
|
|
99
|
+
}
|
|
100
|
+
else if (interactive(v)) {
|
|
101
|
+
chosen = await multiselect(`${skills.length} skills in ${ref.owner}/${ref.repo}, which ones?`, skills.map((s) => ({ label: s.name, hint: s.folder || '(repo root)', value: s })), false);
|
|
102
|
+
if (chosen.length === 0) {
|
|
103
|
+
console.log(dim('Nothing selected.'));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(`Found ${skills.length} skills in ${ref.owner}/${ref.repo}:`);
|
|
109
|
+
printRemote(skills);
|
|
110
|
+
console.log(`\nPick with ${bold('-s <name>')} (repeatable) or install everything with ${bold('--all')}.`);
|
|
111
|
+
process.exitCode = 1;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (v.name) {
|
|
115
|
+
if (chosen.length !== 1)
|
|
116
|
+
throw new Error('--name only works when installing a single skill');
|
|
117
|
+
chosen = [{ ...chosen[0], name: sanitizeName(v.name) }];
|
|
118
|
+
}
|
|
119
|
+
if (v.link && v.copy)
|
|
120
|
+
throw new Error('Use either --link or --copy, not both');
|
|
121
|
+
if (v.link && t.dir)
|
|
122
|
+
throw new Error('--link cannot be combined with --dir');
|
|
123
|
+
if (!t.dir && interactive(v)) {
|
|
124
|
+
if (!v.global && !v.project) {
|
|
125
|
+
t.global = await select('Install where?', [
|
|
126
|
+
{ label: 'Project', hint: `${tilde(t.cwd)} (this repo only)`, value: false },
|
|
127
|
+
{ label: 'User', hint: '~ (all projects)', value: true },
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
if (!t.agent && !process.env.SLLIKS_AGENT) {
|
|
131
|
+
const base = baseDir(t);
|
|
132
|
+
const existing = existingAgents(base);
|
|
133
|
+
const fallback = detectAgent(base);
|
|
134
|
+
const picked = await multiselect('Which agent folders?', Object.keys(AGENTS).map((a) => ({ label: a, hint: showDir(t, a), value: a })), (a) => (existing.length ? existing.includes(a) : a === fallback));
|
|
135
|
+
if (picked.length === 0) {
|
|
136
|
+
console.log(dim('Nothing selected.'));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
t.agent = picked.join(',');
|
|
140
|
+
}
|
|
141
|
+
if (!v.link && !v.copy && installTargets(t).length > 1) {
|
|
142
|
+
v.link = await select('Several folders, how?', [
|
|
143
|
+
{ label: 'Link', hint: `one copy in ${showDir(t, CANONICAL_AGENT)}, symlinks in the others (recommended)`, value: true },
|
|
144
|
+
{ label: 'Copy', hint: 'independent copy in each folder', value: false },
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (v.link && !t.agent && !process.env.SLLIKS_AGENT) {
|
|
149
|
+
// Non-interactive --link: unify every agent folder that already exists.
|
|
150
|
+
const existing = existingAgents(baseDir(t));
|
|
151
|
+
t.agent = existing.length ? existing.join(',') : CANONICAL_AGENT;
|
|
152
|
+
}
|
|
153
|
+
const targets = installTargets(t);
|
|
154
|
+
let failed = 0;
|
|
155
|
+
const fail = (name, err) => {
|
|
156
|
+
failed++;
|
|
157
|
+
console.error(`${red('✗')} ${name}: ${err.message}`);
|
|
158
|
+
};
|
|
159
|
+
if (v.link) {
|
|
160
|
+
const canonical = path.join(baseDir(t), AGENTS[CANONICAL_AGENT], 'skills');
|
|
161
|
+
const linkDirs = targets.filter((x) => x.agent !== CANONICAL_AGENT).map((x) => x.dir);
|
|
162
|
+
for (const skill of chosen) {
|
|
163
|
+
let dest;
|
|
164
|
+
try {
|
|
165
|
+
dest = await installSkill(gh, ref, skill, canonical, { force: !!v.force });
|
|
166
|
+
console.log(`${green('✓')} ${skill.name} ${dim('→')} ${tilde(dest)} ${dim(`(${skill.files.length} files)`)}`);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
fail(skill.name, err);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
for (const dir of linkDirs) {
|
|
173
|
+
try {
|
|
174
|
+
await linkSkill(dest, path.join(dir, skill.name), !!v.force);
|
|
175
|
+
console.log(` ${cyan('↳')} ${tilde(path.join(dir, skill.name))} ${dim('(link)')}`);
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
fail(skill.name, err);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
for (const skill of chosen) {
|
|
185
|
+
for (const target of targets) {
|
|
186
|
+
try {
|
|
187
|
+
const dest = await installSkill(gh, ref, skill, target.dir, { force: !!v.force });
|
|
188
|
+
console.log(`${green('✓')} ${skill.name} ${dim('→')} ${tilde(dest)} ${dim(`(${skill.files.length} files)`)}`);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
fail(skill.name, err);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (failed)
|
|
197
|
+
process.exitCode = 1;
|
|
198
|
+
}
|
|
199
|
+
function showDir(t, agent) {
|
|
200
|
+
return t.global ? `~/${AGENTS[agent]}/skills` : `${AGENTS[agent]}/skills`;
|
|
201
|
+
}
|
|
202
|
+
/** Point other agent folders at the skills already in .agents/skills. */
|
|
203
|
+
async function cmdLink(names, v, t) {
|
|
204
|
+
const base = baseDir(t);
|
|
205
|
+
const canonical = path.join(base, AGENTS[CANONICAL_AGENT], 'skills');
|
|
206
|
+
const available = await listLocalSkills(canonical);
|
|
207
|
+
if (available.length === 0) {
|
|
208
|
+
throw new Error(`No skills in ${tilde(canonical)} to link. Install with: slliks add <source> --link`);
|
|
209
|
+
}
|
|
210
|
+
const chosen = names.length ? names : available.map((s) => s.name);
|
|
211
|
+
const agents = t.agent
|
|
212
|
+
? t.agent.split(',').map((a) => a.trim())
|
|
213
|
+
: existingAgents(base).filter((a) => a !== CANONICAL_AGENT);
|
|
214
|
+
if (agents.length === 0) {
|
|
215
|
+
throw new Error(`No other agent folder found in ${tilde(base)}. Pick one with -a cursor,claude`);
|
|
216
|
+
}
|
|
217
|
+
for (const a of agents)
|
|
218
|
+
if (!AGENTS[a])
|
|
219
|
+
throw new Error(`Unknown agent "${a}"`);
|
|
220
|
+
let failed = 0;
|
|
221
|
+
for (const name of chosen) {
|
|
222
|
+
const src = available.find((s) => s.name === name);
|
|
223
|
+
if (!src) {
|
|
224
|
+
console.error(`${red('✗')} ${name}: not in ${tilde(canonical)}`);
|
|
225
|
+
failed++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
for (const a of agents.filter((x) => x !== CANONICAL_AGENT)) {
|
|
229
|
+
const linkPath = path.join(base, AGENTS[a], 'skills', name);
|
|
230
|
+
try {
|
|
231
|
+
const r = await linkSkill(src.dir, linkPath, !!v.force);
|
|
232
|
+
const note = r === 'already-linked' ? dim('(already linked)') : r === 'replaced' ? dim('(copy replaced by link)') : '';
|
|
233
|
+
console.log(`${green('✓')} ${tilde(linkPath)} ${dim('→')} ${tilde(src.dir)} ${note}`);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
console.error(`${red('✗')} ${name}: ${err.message}`);
|
|
237
|
+
failed++;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (failed)
|
|
242
|
+
process.exitCode = 1;
|
|
243
|
+
}
|
|
244
|
+
async function cmdFind(source) {
|
|
245
|
+
const { ref, skills } = await resolveSource(source, new GitHubClient());
|
|
246
|
+
console.log(`${skills.length} skill(s) in ${ref.owner}/${ref.repo}@${ref.branch}:`);
|
|
247
|
+
printRemote(skills);
|
|
248
|
+
}
|
|
249
|
+
async function cmdList(t) {
|
|
250
|
+
let total = 0;
|
|
251
|
+
for (const target of scanTargets(t)) {
|
|
252
|
+
const skills = await listLocalSkills(target.dir);
|
|
253
|
+
if (skills.length === 0)
|
|
254
|
+
continue;
|
|
255
|
+
total += skills.length;
|
|
256
|
+
console.log(bold(tilde(target.dir)));
|
|
257
|
+
for (const s of skills) {
|
|
258
|
+
const desc = s.description.length > 80 ? `${s.description.slice(0, 77)}...` : s.description;
|
|
259
|
+
const to = await linkTarget(s.dir);
|
|
260
|
+
const via = to ? ` ${cyan('→')} ${dim(tilde(to))}` : '';
|
|
261
|
+
console.log(` ${s.name}${via}${desc && !to ? ` ${dim(desc)}` : ''}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (total === 0)
|
|
265
|
+
console.log(dim(`No skills installed${t.global ? ' globally' : ' in this project'}.`));
|
|
266
|
+
}
|
|
267
|
+
async function cmdRemove(names, t) {
|
|
268
|
+
let failed = 0;
|
|
269
|
+
for (const name of names) {
|
|
270
|
+
if (sanitizeName(name) !== name) {
|
|
271
|
+
console.error(`${red('✗')} invalid skill name: ${name}`);
|
|
272
|
+
failed++;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
let removed = 0;
|
|
276
|
+
for (const target of scanTargets(t)) {
|
|
277
|
+
const dir = path.join(target.dir, name);
|
|
278
|
+
const isLink = (await linkTarget(dir)) !== null;
|
|
279
|
+
if (!isLink) {
|
|
280
|
+
try {
|
|
281
|
+
await fs.stat(path.join(dir, 'SKILL.md'));
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
288
|
+
removed++;
|
|
289
|
+
console.log(`${green('✓')} removed ${tilde(dir)}${isLink ? dim(' (link)') : ''}`);
|
|
290
|
+
}
|
|
291
|
+
if (!removed) {
|
|
292
|
+
console.error(`${red('✗')} ${name}: not installed${t.global ? ' globally' : ' in this project'}`);
|
|
293
|
+
failed++;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (failed)
|
|
297
|
+
process.exitCode = 1;
|
|
298
|
+
}
|
|
299
|
+
function interactive(v) {
|
|
300
|
+
return !v.yes && canPrompt();
|
|
301
|
+
}
|
|
302
|
+
async function main(argv) {
|
|
303
|
+
const { values, positionals } = parseArgs({
|
|
304
|
+
args: argv,
|
|
305
|
+
allowPositionals: true,
|
|
306
|
+
options: {
|
|
307
|
+
global: { type: 'boolean', short: 'g' },
|
|
308
|
+
project: { type: 'boolean', short: 'p' },
|
|
309
|
+
yes: { type: 'boolean', short: 'y' },
|
|
310
|
+
agent: { type: 'string', short: 'a' },
|
|
311
|
+
dir: { type: 'string', short: 'd' },
|
|
312
|
+
skill: { type: 'string', short: 's', multiple: true },
|
|
313
|
+
all: { type: 'boolean' },
|
|
314
|
+
name: { type: 'string', short: 'n' },
|
|
315
|
+
force: { type: 'boolean', short: 'f' },
|
|
316
|
+
link: { type: 'boolean', short: 'l' },
|
|
317
|
+
copy: { type: 'boolean' },
|
|
318
|
+
help: { type: 'boolean', short: 'h' },
|
|
319
|
+
version: { type: 'boolean', short: 'v' },
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
const v = values;
|
|
323
|
+
if (v.version)
|
|
324
|
+
return console.log(version());
|
|
325
|
+
const [cmd, ...args] = positionals;
|
|
326
|
+
if (v.help || !cmd || cmd === 'help')
|
|
327
|
+
return console.log(`${banner(version(), !!color)}\n${HELP}`);
|
|
328
|
+
if (v.global && v.project)
|
|
329
|
+
throw new Error('Use either --global or --project, not both');
|
|
330
|
+
const t = { global: !!v.global, agent: v.agent, dir: v.dir, cwd: process.cwd() };
|
|
331
|
+
switch (cmd) {
|
|
332
|
+
case 'add':
|
|
333
|
+
case 'install':
|
|
334
|
+
case 'i':
|
|
335
|
+
if (!args[0])
|
|
336
|
+
throw new Error('Usage: slliks add <source>');
|
|
337
|
+
return cmdAdd(args[0], v, t);
|
|
338
|
+
case 'find':
|
|
339
|
+
case 'search':
|
|
340
|
+
if (!args[0])
|
|
341
|
+
throw new Error('Usage: slliks find <source>');
|
|
342
|
+
return cmdFind(args[0]);
|
|
343
|
+
case 'list':
|
|
344
|
+
case 'ls':
|
|
345
|
+
return cmdList(t);
|
|
346
|
+
case 'link':
|
|
347
|
+
return cmdLink(args, v, t);
|
|
348
|
+
case 'remove':
|
|
349
|
+
case 'rm':
|
|
350
|
+
if (args.length === 0)
|
|
351
|
+
throw new Error('Usage: slliks remove <name...>');
|
|
352
|
+
return cmdRemove(args, t);
|
|
353
|
+
default:
|
|
354
|
+
throw new Error(`Unknown command "${cmd}". Run slliks --help.`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
358
|
+
console.error(`${red('error')} ${err.message}`);
|
|
359
|
+
process.exitCode = 1;
|
|
360
|
+
});
|
package/dist/github.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const NAME_RE = /^[A-Za-z0-9_.-]+$/;
|
|
2
|
+
/**
|
|
3
|
+
* Accepts:
|
|
4
|
+
* - owner/repo[/sub/folder]
|
|
5
|
+
* - https://github.com/owner/repo[.git]
|
|
6
|
+
* - https://github.com/owner/repo/tree/<branch>/<folder>
|
|
7
|
+
* - https://github.com/owner/repo/blob/<branch>/<folder>/SKILL.md
|
|
8
|
+
* - https://raw.githubusercontent.com/owner/repo/<branch>/<folder>/SKILL.md
|
|
9
|
+
*/
|
|
10
|
+
export function parseSource(input) {
|
|
11
|
+
const raw = (input ?? '').trim();
|
|
12
|
+
if (!raw)
|
|
13
|
+
throw new Error('Missing source URL');
|
|
14
|
+
// Shorthand: owner/repo[/path]
|
|
15
|
+
if (!/^[a-z]+:\/\//i.test(raw)) {
|
|
16
|
+
const segs = raw.split('/').filter(Boolean);
|
|
17
|
+
if (segs.length < 2 || !NAME_RE.test(segs[0]) || !NAME_RE.test(segs[1])) {
|
|
18
|
+
throw new Error(`Invalid source "${raw}". Use owner/repo or a GitHub URL.`);
|
|
19
|
+
}
|
|
20
|
+
return { owner: segs[0], repo: stripGit(segs[1]), branch: '', path: segs.slice(2).join('/') };
|
|
21
|
+
}
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new Error(`Invalid URL: ${raw}`);
|
|
28
|
+
}
|
|
29
|
+
if (url.protocol !== 'https:')
|
|
30
|
+
throw new Error('Only https URLs are supported');
|
|
31
|
+
const segs = url.pathname.split('/').filter(Boolean).map(decodeURIComponent);
|
|
32
|
+
if (url.hostname === 'raw.githubusercontent.com') {
|
|
33
|
+
if (segs.length < 3)
|
|
34
|
+
throw new Error('Raw URL must include owner, repo and branch');
|
|
35
|
+
return {
|
|
36
|
+
owner: segs[0],
|
|
37
|
+
repo: segs[1],
|
|
38
|
+
branch: segs[2],
|
|
39
|
+
path: folderOf(segs.slice(3)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (url.hostname !== 'github.com' && url.hostname !== 'www.github.com') {
|
|
43
|
+
throw new Error('Only github.com URLs are supported for now');
|
|
44
|
+
}
|
|
45
|
+
if (segs.length < 2)
|
|
46
|
+
throw new Error('URL must include owner and repository');
|
|
47
|
+
const owner = segs[0];
|
|
48
|
+
const repo = stripGit(segs[1]);
|
|
49
|
+
const kind = segs[2];
|
|
50
|
+
if (kind === undefined)
|
|
51
|
+
return { owner, repo, branch: '', path: '' };
|
|
52
|
+
if (kind === 'tree' || kind === 'blob') {
|
|
53
|
+
if (!segs[3])
|
|
54
|
+
throw new Error('Missing branch name in URL');
|
|
55
|
+
const rest = segs.slice(4);
|
|
56
|
+
return {
|
|
57
|
+
owner,
|
|
58
|
+
repo,
|
|
59
|
+
branch: segs[3],
|
|
60
|
+
path: kind === 'blob' ? folderOf(rest) : rest.join('/'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`Unsupported GitHub URL: ${raw}`);
|
|
64
|
+
}
|
|
65
|
+
/** A blob URL pointing at a file means "the folder containing it". */
|
|
66
|
+
function folderOf(segs) {
|
|
67
|
+
if (segs.length === 0)
|
|
68
|
+
return '';
|
|
69
|
+
const last = segs[segs.length - 1];
|
|
70
|
+
return /\.[A-Za-z0-9]+$/.test(last) ? segs.slice(0, -1).join('/') : segs.join('/');
|
|
71
|
+
}
|
|
72
|
+
function stripGit(name) {
|
|
73
|
+
return name.endsWith('.git') ? name.slice(0, -4) : name;
|
|
74
|
+
}
|
|
75
|
+
export class GitHubClient {
|
|
76
|
+
token;
|
|
77
|
+
fetchImpl;
|
|
78
|
+
constructor(token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN, fetchImpl = globalThis.fetch) {
|
|
79
|
+
this.token = token;
|
|
80
|
+
this.fetchImpl = fetchImpl;
|
|
81
|
+
}
|
|
82
|
+
headers(accept) {
|
|
83
|
+
const h = { 'User-Agent': 'slliks', Accept: accept };
|
|
84
|
+
if (this.token)
|
|
85
|
+
h.Authorization = `Bearer ${this.token}`;
|
|
86
|
+
return h;
|
|
87
|
+
}
|
|
88
|
+
async get(url, accept) {
|
|
89
|
+
const res = await this.fetchImpl(url, {
|
|
90
|
+
headers: this.headers(accept),
|
|
91
|
+
signal: AbortSignal.timeout(20_000),
|
|
92
|
+
});
|
|
93
|
+
if (res.ok)
|
|
94
|
+
return res;
|
|
95
|
+
if (res.status === 404)
|
|
96
|
+
throw new Error(`Not found: ${url}${this.token ? '' : ' (private repo? set GITHUB_TOKEN)'}`);
|
|
97
|
+
if (res.status === 403 || res.status === 429) {
|
|
98
|
+
throw new Error(`GitHub rate limit or forbidden (HTTP ${res.status}). Set GITHUB_TOKEN to raise the limit.`);
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`GitHub request failed (HTTP ${res.status}): ${url}`);
|
|
101
|
+
}
|
|
102
|
+
async json(url) {
|
|
103
|
+
const res = await this.get(url, 'application/vnd.github+json');
|
|
104
|
+
const body = (await res.json());
|
|
105
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
106
|
+
throw new Error('Unexpected GitHub API response');
|
|
107
|
+
}
|
|
108
|
+
return body;
|
|
109
|
+
}
|
|
110
|
+
async defaultBranch(owner, repo) {
|
|
111
|
+
const body = await this.json(`https://api.github.com/repos/${enc(owner)}/${enc(repo)}`);
|
|
112
|
+
if (typeof body.default_branch !== 'string')
|
|
113
|
+
throw new Error('Could not resolve default branch');
|
|
114
|
+
return body.default_branch;
|
|
115
|
+
}
|
|
116
|
+
async tree(ref) {
|
|
117
|
+
const body = await this.json(`https://api.github.com/repos/${enc(ref.owner)}/${enc(ref.repo)}/git/trees/${enc(ref.branch)}?recursive=1`);
|
|
118
|
+
if (!Array.isArray(body.tree))
|
|
119
|
+
throw new Error('Could not read repository tree');
|
|
120
|
+
if (body.truncated === true) {
|
|
121
|
+
process.stderr.write('warning: repository tree is truncated by GitHub; some skills may be missing\n');
|
|
122
|
+
}
|
|
123
|
+
return body.tree.filter((i) => typeof i.path === 'string' && typeof i.type === 'string');
|
|
124
|
+
}
|
|
125
|
+
async file(ref, filePath) {
|
|
126
|
+
const p = filePath.split('/').map(enc).join('/');
|
|
127
|
+
const res = await this.get(`https://raw.githubusercontent.com/${enc(ref.owner)}/${enc(ref.repo)}/${enc(ref.branch)}/${p}`, '*/*');
|
|
128
|
+
return Buffer.from(await res.arrayBuffer());
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function enc(s) {
|
|
132
|
+
return encodeURIComponent(s);
|
|
133
|
+
}
|
package/dist/link.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
/** `.claude/skills/pdf` instead of a long absolute path in messages. */
|
|
4
|
+
function short(p) {
|
|
5
|
+
return p.split(path.sep).slice(-3).join('/');
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Makes `linkPath` a symlink to `targetDir`.
|
|
9
|
+
* Relative links on POSIX (survive moving the repo / home), junctions on Windows
|
|
10
|
+
* (no admin rights needed). Never deletes a real folder unless `force`.
|
|
11
|
+
*/
|
|
12
|
+
export async function linkSkill(targetDir, linkPath, force) {
|
|
13
|
+
let replaced = false;
|
|
14
|
+
const st = await fs.lstat(linkPath).catch(() => null);
|
|
15
|
+
if (st) {
|
|
16
|
+
if (st.isSymbolicLink()) {
|
|
17
|
+
const current = path.resolve(path.dirname(linkPath), await fs.readlink(linkPath));
|
|
18
|
+
if (path.resolve(current) === path.resolve(targetDir))
|
|
19
|
+
return 'already-linked';
|
|
20
|
+
if (!force)
|
|
21
|
+
throw new Error(`${short(linkPath)} links somewhere else (use --force to relink)`);
|
|
22
|
+
}
|
|
23
|
+
else if (!force) {
|
|
24
|
+
throw new Error(`a real copy already exists at ${short(linkPath)} (use --force to replace it with a link)`);
|
|
25
|
+
}
|
|
26
|
+
await fs.rm(linkPath, { recursive: true, force: true });
|
|
27
|
+
replaced = true;
|
|
28
|
+
}
|
|
29
|
+
await fs.mkdir(path.dirname(linkPath), { recursive: true });
|
|
30
|
+
if (process.platform === 'win32') {
|
|
31
|
+
await fs.symlink(path.resolve(targetDir), linkPath, 'junction');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await fs.symlink(path.relative(path.dirname(linkPath), targetDir), linkPath, 'dir');
|
|
35
|
+
}
|
|
36
|
+
return replaced ? 'replaced' : 'linked';
|
|
37
|
+
}
|
|
38
|
+
/** Where a symlinked skill points to, or null if it is a real folder. */
|
|
39
|
+
export async function linkTarget(p) {
|
|
40
|
+
const st = await fs.lstat(p).catch(() => null);
|
|
41
|
+
if (!st?.isSymbolicLink())
|
|
42
|
+
return null;
|
|
43
|
+
return path.resolve(path.dirname(p), await fs.readlink(p));
|
|
44
|
+
}
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as readline from 'node:readline';
|
|
2
|
+
const out = process.stdout;
|
|
3
|
+
const color = out.isTTY && !process.env.NO_COLOR;
|
|
4
|
+
const esc = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
5
|
+
const dim = esc(2);
|
|
6
|
+
const cyan = esc(36);
|
|
7
|
+
const bold = esc(1);
|
|
8
|
+
export function canPrompt() {
|
|
9
|
+
return !!process.stdin.isTTY && !!out.isTTY && !process.env.CI;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Tiny raw-mode list prompt. Single select: ↑/↓ + enter.
|
|
13
|
+
* Multi select: ↑/↓, space toggles, `a` toggles all, enter confirms.
|
|
14
|
+
*/
|
|
15
|
+
function run(title, choices, multi, initial, checked) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const stdin = process.stdin;
|
|
18
|
+
let cursor = initial;
|
|
19
|
+
let drawn = 0;
|
|
20
|
+
const help = multi ? dim('↑/↓ move · space select · a all · enter confirm') : dim('↑/↓ move · enter confirm');
|
|
21
|
+
const render = () => {
|
|
22
|
+
const lines = [`${cyan('?')} ${bold(title)} ${help}`];
|
|
23
|
+
choices.forEach((c, i) => {
|
|
24
|
+
const active = i === cursor;
|
|
25
|
+
const mark = multi ? (checked[i] ? cyan('◉') : dim('◯')) : active ? cyan('●') : dim('○');
|
|
26
|
+
const label = active ? cyan(c.label) : c.label;
|
|
27
|
+
lines.push(`${active ? cyan('❯') : ' '} ${mark} ${label}${c.hint ? ` ${dim(c.hint)}` : ''}`);
|
|
28
|
+
});
|
|
29
|
+
if (drawn)
|
|
30
|
+
out.write(`\x1b[${drawn}A`);
|
|
31
|
+
for (const l of lines)
|
|
32
|
+
out.write(`\x1b[2K${l}\n`);
|
|
33
|
+
drawn = lines.length;
|
|
34
|
+
};
|
|
35
|
+
const finish = (result) => {
|
|
36
|
+
stdin.off('keypress', onKey);
|
|
37
|
+
stdin.setRawMode(false);
|
|
38
|
+
stdin.pause();
|
|
39
|
+
out.write(`\x1b[${drawn}A\x1b[J`);
|
|
40
|
+
out.write('\x1b[?25h');
|
|
41
|
+
if (result === null) {
|
|
42
|
+
out.write(`${dim('cancelled')}\n`);
|
|
43
|
+
process.exit(130);
|
|
44
|
+
}
|
|
45
|
+
const summary = choices.filter((c) => result.includes(c.value)).map((c) => c.label).join(', ');
|
|
46
|
+
out.write(`${cyan('✔')} ${bold(title)} ${dim('›')} ${summary || dim('nothing')}\n`);
|
|
47
|
+
resolve(result);
|
|
48
|
+
};
|
|
49
|
+
const onKey = (_, key) => {
|
|
50
|
+
if (!key)
|
|
51
|
+
return;
|
|
52
|
+
if ((key.ctrl && key.name === 'c') || key.name === 'escape')
|
|
53
|
+
return finish(null);
|
|
54
|
+
if (key.name === 'up' || key.name === 'k')
|
|
55
|
+
cursor = (cursor - 1 + choices.length) % choices.length;
|
|
56
|
+
else if (key.name === 'down' || key.name === 'j')
|
|
57
|
+
cursor = (cursor + 1) % choices.length;
|
|
58
|
+
else if (multi && key.name === 'space')
|
|
59
|
+
checked[cursor] = !checked[cursor];
|
|
60
|
+
else if (multi && key.name === 'a') {
|
|
61
|
+
const all = checked.every(Boolean);
|
|
62
|
+
checked.fill(!all);
|
|
63
|
+
}
|
|
64
|
+
else if (key.name === 'return') {
|
|
65
|
+
return finish(multi ? choices.filter((_, i) => checked[i]).map((c) => c.value) : [choices[cursor].value]);
|
|
66
|
+
}
|
|
67
|
+
render();
|
|
68
|
+
};
|
|
69
|
+
readline.emitKeypressEvents(stdin);
|
|
70
|
+
stdin.setRawMode(true);
|
|
71
|
+
stdin.resume();
|
|
72
|
+
stdin.on('keypress', onKey);
|
|
73
|
+
out.write('\x1b[?25l');
|
|
74
|
+
render();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export async function select(title, choices, initial = 0) {
|
|
78
|
+
const [v] = await run(title, choices, false, Math.max(0, initial), []);
|
|
79
|
+
return v;
|
|
80
|
+
}
|
|
81
|
+
export function multiselect(title, choices, preselected = true) {
|
|
82
|
+
const pick = typeof preselected === 'function' ? preselected : () => preselected;
|
|
83
|
+
return run(title, choices, true, 0, choices.map((c) => pick(c.value)));
|
|
84
|
+
}
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
/** Finds every folder containing a SKILL.md under `prefix`, with the files belonging to it. */
|
|
4
|
+
export function discoverSkills(tree, prefix, repoName) {
|
|
5
|
+
const blobs = tree
|
|
6
|
+
.filter((i) => i.type === 'blob' && !i.path.startsWith('.git/') && !i.path.includes('/.git/'))
|
|
7
|
+
.map((i) => i.path);
|
|
8
|
+
const folders = blobs
|
|
9
|
+
.filter((p) => p === 'SKILL.md' || p.endsWith('/SKILL.md'))
|
|
10
|
+
.map((p) => (p === 'SKILL.md' ? '' : p.slice(0, -'/SKILL.md'.length)))
|
|
11
|
+
.filter((f) => !prefix || f === prefix || f.startsWith(`${prefix}/`))
|
|
12
|
+
.sort();
|
|
13
|
+
return folders.map((folder) => {
|
|
14
|
+
const nested = folders.filter((f) => f !== folder && isInside(f, folder));
|
|
15
|
+
const files = blobs.filter((p) => isInside(p, folder) && !nested.some((n) => isInside(p, n)));
|
|
16
|
+
return { folder, name: sanitizeName(folder ? path.posix.basename(folder) : repoName), files };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function isInside(p, folder) {
|
|
20
|
+
return folder === '' || p === folder || p.startsWith(`${folder}/`);
|
|
21
|
+
}
|
|
22
|
+
export function sanitizeName(name) {
|
|
23
|
+
const clean = name.replace(/[^A-Za-z0-9._-]/g, '-').replace(/^[.-]+/, '');
|
|
24
|
+
return clean || 'skill';
|
|
25
|
+
}
|
|
26
|
+
export function relativeTo(folder, filePath) {
|
|
27
|
+
return folder ? filePath.slice(folder.length + 1) : filePath;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Downloads a skill into `<destRoot>/<name>`. Files land in a temp dir first and are
|
|
31
|
+
* moved into place at the end, so a failed download never leaves a half-installed skill.
|
|
32
|
+
*/
|
|
33
|
+
export async function installSkill(gh, ref, skill, destRoot, opts) {
|
|
34
|
+
const dest = path.join(destRoot, skill.name);
|
|
35
|
+
if ((await exists(dest)) && !opts.force) {
|
|
36
|
+
throw new Error(`already installed in ${path.basename(path.dirname(destRoot))}/skills (use --force to overwrite)`);
|
|
37
|
+
}
|
|
38
|
+
await fs.mkdir(destRoot, { recursive: true });
|
|
39
|
+
const tmp = await fs.mkdtemp(path.join(destRoot, `.${skill.name}.slliks-`));
|
|
40
|
+
try {
|
|
41
|
+
const queue = [...skill.files];
|
|
42
|
+
const worker = async () => {
|
|
43
|
+
for (let f = queue.shift(); f !== undefined; f = queue.shift()) {
|
|
44
|
+
const rel = relativeTo(skill.folder, f);
|
|
45
|
+
const target = path.resolve(tmp, rel);
|
|
46
|
+
if (!target.startsWith(tmp + path.sep))
|
|
47
|
+
throw new Error(`Refusing unsafe path: ${f}`);
|
|
48
|
+
const data = await gh.file(ref, f);
|
|
49
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
50
|
+
await fs.writeFile(target, data);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
await Promise.all(Array.from({ length: opts.concurrency ?? 8 }, worker));
|
|
54
|
+
if (!(await exists(path.join(tmp, 'SKILL.md'))))
|
|
55
|
+
throw new Error('SKILL.md missing from download');
|
|
56
|
+
await fs.rm(dest, { recursive: true, force: true });
|
|
57
|
+
await fs.rename(tmp, dest);
|
|
58
|
+
return dest;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function listLocalSkills(skillsDir) {
|
|
66
|
+
let entries;
|
|
67
|
+
try {
|
|
68
|
+
entries = await fs.readdir(skillsDir, { withFileTypes: true });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const e of entries) {
|
|
75
|
+
if (!(e.isDirectory() || e.isSymbolicLink()) || e.name.startsWith('.'))
|
|
76
|
+
continue;
|
|
77
|
+
const dir = path.join(skillsDir, e.name);
|
|
78
|
+
let md;
|
|
79
|
+
try {
|
|
80
|
+
md = await fs.readFile(path.join(dir, 'SKILL.md'), 'utf8');
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
out.push({ name: e.name, dir, description: frontmatter(md).description ?? '' });
|
|
86
|
+
}
|
|
87
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
88
|
+
}
|
|
89
|
+
/** Minimal YAML frontmatter reader: top-level `key: value` lines only. */
|
|
90
|
+
export function frontmatter(md) {
|
|
91
|
+
const m = md.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
92
|
+
if (!m)
|
|
93
|
+
return {};
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
96
|
+
const kv = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
|
|
97
|
+
if (kv)
|
|
98
|
+
out[kv[1]] = kv[2].trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
export async function exists(p) {
|
|
103
|
+
try {
|
|
104
|
+
await fs.stat(p);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/targets.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
/** Agent name -> dot-folder that holds its `skills/` directory. */
|
|
5
|
+
export const AGENTS = {
|
|
6
|
+
cursor: '.cursor',
|
|
7
|
+
claude: '.claude',
|
|
8
|
+
agents: '.agents',
|
|
9
|
+
};
|
|
10
|
+
export function baseDir(opts) {
|
|
11
|
+
return opts.global ? (opts.home ?? os.homedir()) : opts.cwd;
|
|
12
|
+
}
|
|
13
|
+
function parseAgents(spec) {
|
|
14
|
+
const names = spec === 'all' ? Object.keys(AGENTS) : spec.split(',').map((s) => s.trim()).filter(Boolean);
|
|
15
|
+
for (const n of names) {
|
|
16
|
+
if (!AGENTS[n])
|
|
17
|
+
throw new Error(`Unknown agent "${n}". Use one of: ${Object.keys(AGENTS).join(', ')}, all`);
|
|
18
|
+
}
|
|
19
|
+
return [...new Set(names)];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Where to install. Order of precedence:
|
|
23
|
+
* --dir > --agent > $SLLIKS_AGENT > first existing of .cursor/.claude/.agents > cursor
|
|
24
|
+
* Auto-detect picks exactly one folder so a single install never fans out silently.
|
|
25
|
+
*/
|
|
26
|
+
export function installTargets(opts) {
|
|
27
|
+
if (opts.dir)
|
|
28
|
+
return [{ agent: 'custom', dir: path.resolve(opts.cwd, opts.dir) }];
|
|
29
|
+
const base = baseDir(opts);
|
|
30
|
+
const spec = opts.agent ?? process.env.SLLIKS_AGENT;
|
|
31
|
+
if (spec)
|
|
32
|
+
return parseAgents(spec).map((a) => ({ agent: a, dir: path.join(base, AGENTS[a], 'skills') }));
|
|
33
|
+
const agent = detectAgent(base);
|
|
34
|
+
return [{ agent, dir: path.join(base, AGENTS[agent], 'skills') }];
|
|
35
|
+
}
|
|
36
|
+
/** Every agent whose dot-folder already exists in `base`. */
|
|
37
|
+
export function existingAgents(base) {
|
|
38
|
+
return Object.keys(AGENTS).filter((a) => existsSync(path.join(base, AGENTS[a])));
|
|
39
|
+
}
|
|
40
|
+
/** The shared folder every linked install points to. */
|
|
41
|
+
export const CANONICAL_AGENT = 'agents';
|
|
42
|
+
/** First agent folder that already exists in `base`, else cursor. */
|
|
43
|
+
export function detectAgent(base) {
|
|
44
|
+
return Object.keys(AGENTS).find((a) => existsSync(path.join(base, AGENTS[a]))) ?? 'cursor';
|
|
45
|
+
}
|
|
46
|
+
/** Where to look for installed skills (list/remove): every known folder unless narrowed. */
|
|
47
|
+
export function scanTargets(opts) {
|
|
48
|
+
if (opts.dir)
|
|
49
|
+
return [{ agent: 'custom', dir: path.resolve(opts.cwd, opts.dir) }];
|
|
50
|
+
const base = baseDir(opts);
|
|
51
|
+
const names = opts.agent ? parseAgents(opts.agent) : Object.keys(AGENTS);
|
|
52
|
+
return names.map((a) => ({ agent: a, dir: path.join(base, AGENTS[a], 'skills') }));
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slliks",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install agent skills from a GitHub URL into your project or user skills folder. No prompts, no telemetry, no runtime deps.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"slliks": "dist/cli.js",
|
|
8
|
+
"lliks": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18.17"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
19
|
+
"test": "tsc -p tsconfig.test.json && node --test dist-test/test/*.test.js",
|
|
20
|
+
"prepublishOnly": "npm run build && npm test"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"skills",
|
|
24
|
+
"agent-skills",
|
|
25
|
+
"claude",
|
|
26
|
+
"cursor",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"typescript": "^5.6.0"
|
|
33
|
+
}
|
|
34
|
+
}
|