bip-skills 1.4.3
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 +492 -0
- package/ThirdPartyNoticeText.txt +213 -0
- package/bin/cli.mjs +14 -0
- package/dist/_chunks/libs/@clack/core.mjs +767 -0
- package/dist/_chunks/libs/@clack/prompts.mjs +334 -0
- package/dist/_chunks/libs/@kwsites/file-exists.mjs +562 -0
- package/dist/_chunks/libs/@kwsites/promise-deferred.mjs +37 -0
- package/dist/_chunks/libs/esprima.mjs +5338 -0
- package/dist/_chunks/libs/extend-shallow.mjs +31 -0
- package/dist/_chunks/libs/gray-matter.mjs +2596 -0
- package/dist/_chunks/libs/simple-git.mjs +3584 -0
- package/dist/_chunks/libs/xdg-basedir.mjs +14 -0
- package/dist/_chunks/rolldown-runtime.mjs +24 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +4141 -0
- package/package.json +112 -0
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,4141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { r as __toESM } from "./_chunks/rolldown-runtime.mjs";
|
|
3
|
+
import { l as pD, u as require_picocolors } from "./_chunks/libs/@clack/core.mjs";
|
|
4
|
+
import { a as Y, c as ve, i as Se, l as xe, n as M, o as be, r as Me, s as fe, t as Ie, u as ye } from "./_chunks/libs/@clack/prompts.mjs";
|
|
5
|
+
import "./_chunks/libs/@kwsites/file-exists.mjs";
|
|
6
|
+
import "./_chunks/libs/@kwsites/promise-deferred.mjs";
|
|
7
|
+
import { t as esm_default } from "./_chunks/libs/simple-git.mjs";
|
|
8
|
+
import { t as require_gray_matter } from "./_chunks/libs/gray-matter.mjs";
|
|
9
|
+
import "./_chunks/libs/extend-shallow.mjs";
|
|
10
|
+
import "./_chunks/libs/esprima.mjs";
|
|
11
|
+
import { t as xdgConfig } from "./_chunks/libs/xdg-basedir.mjs";
|
|
12
|
+
import { execSync, spawn, spawnSync } from "child_process";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
14
|
+
import { basename, dirname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
15
|
+
import { homedir, platform, tmpdir } from "os";
|
|
16
|
+
import { createHash } from "crypto";
|
|
17
|
+
import { fileURLToPath } from "url";
|
|
18
|
+
import * as readline from "readline";
|
|
19
|
+
import { Writable } from "stream";
|
|
20
|
+
import { access, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm, stat, symlink, writeFile } from "fs/promises";
|
|
21
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
22
|
+
const AGENTS_DIR$2 = ".agents";
|
|
23
|
+
const SKILLS_SUBDIR = "skills";
|
|
24
|
+
const CLI_PACKAGE_NAME = "bip-skills";
|
|
25
|
+
const CLI_BINARY_NAME = "bip-skills";
|
|
26
|
+
const CLI_NPX_COMMAND = `npx ${CLI_PACKAGE_NAME}`;
|
|
27
|
+
const DEFAULT_WELL_KNOWN_BASE_URL = "https://sun.yyuap.com";
|
|
28
|
+
const DEFAULT_DISCOVERY_SITE_URL = DEFAULT_WELL_KNOWN_BASE_URL;
|
|
29
|
+
const DEFAULT_SEARCH_API_BASE = DEFAULT_WELL_KNOWN_BASE_URL;
|
|
30
|
+
const DEFAULT_GIT_HOST = "git.yonyou.com";
|
|
31
|
+
const DEFAULT_GIT_BASE_URL = `https://${DEFAULT_GIT_HOST}`;
|
|
32
|
+
function isYyuapHost(hostname) {
|
|
33
|
+
return hostname === "yyuap.com" || hostname.endsWith(".yyuap.com");
|
|
34
|
+
}
|
|
35
|
+
function isAllowedReportingUrl(url) {
|
|
36
|
+
try {
|
|
37
|
+
return isYyuapHost(new URL(url).hostname);
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isDebugLoggingEnabled() {
|
|
43
|
+
const value = process.env.SKILLS_DEBUG;
|
|
44
|
+
return value === "1" || value === "true";
|
|
45
|
+
}
|
|
46
|
+
function debugLog(message) {
|
|
47
|
+
if (isDebugLoggingEnabled()) console.log(message);
|
|
48
|
+
}
|
|
49
|
+
function getOwnerRepo(parsed) {
|
|
50
|
+
if (parsed.type === "local") return null;
|
|
51
|
+
if (!parsed.url.startsWith("http://") && !parsed.url.startsWith("https://")) return null;
|
|
52
|
+
try {
|
|
53
|
+
let path = new URL(parsed.url).pathname.slice(1);
|
|
54
|
+
path = path.replace(/\.git$/, "");
|
|
55
|
+
if (path.includes("/")) return path;
|
|
56
|
+
} catch {}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function parseOwnerRepo(ownerRepo) {
|
|
60
|
+
const match = ownerRepo.match(/^([^/]+)\/([^/]+)$/);
|
|
61
|
+
if (match) return {
|
|
62
|
+
owner: match[1],
|
|
63
|
+
repo: match[2]
|
|
64
|
+
};
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
async function isRepoPrivate(owner, repo) {
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`);
|
|
70
|
+
if (!res.ok) return null;
|
|
71
|
+
return (await res.json()).private === true;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function isLocalPath(input) {
|
|
77
|
+
return isAbsolute(input) || input.startsWith("./") || input.startsWith("../") || input === "." || input === ".." || /^[a-zA-Z]:[/\\]/.test(input);
|
|
78
|
+
}
|
|
79
|
+
const SOURCE_ALIASES = { "coinbase/agentWallet": "coinbase/agentic-wallet-skills" };
|
|
80
|
+
function buildDefaultGitUrl(repoPath) {
|
|
81
|
+
return `${DEFAULT_GIT_BASE_URL}/${repoPath.replace(/\.git$/, "")}.git`;
|
|
82
|
+
}
|
|
83
|
+
function parseSource(input) {
|
|
84
|
+
const alias = SOURCE_ALIASES[input];
|
|
85
|
+
if (alias) input = alias;
|
|
86
|
+
if (isLocalPath(input)) {
|
|
87
|
+
const resolvedPath = resolve(input);
|
|
88
|
+
return {
|
|
89
|
+
type: "local",
|
|
90
|
+
url: resolvedPath,
|
|
91
|
+
localPath: resolvedPath
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const wellKnownAtSkillMatch = input.match(/^(https?:\/\/.+)@([a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?)$/);
|
|
95
|
+
if (wellKnownAtSkillMatch) {
|
|
96
|
+
const [, baseUrl, skillFilter] = wellKnownAtSkillMatch;
|
|
97
|
+
if (baseUrl && skillFilter && isWellKnownUrl(baseUrl)) return {
|
|
98
|
+
type: "well-known",
|
|
99
|
+
url: baseUrl,
|
|
100
|
+
skillFilter
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const githubTreeWithPathMatch = input.match(/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)\/(.+)/);
|
|
104
|
+
if (githubTreeWithPathMatch) {
|
|
105
|
+
const [, owner, repo, ref, subpath] = githubTreeWithPathMatch;
|
|
106
|
+
return {
|
|
107
|
+
type: "github",
|
|
108
|
+
url: `https://github.com/${owner}/${repo}.git`,
|
|
109
|
+
ref,
|
|
110
|
+
subpath
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const githubTreeMatch = input.match(/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)$/);
|
|
114
|
+
if (githubTreeMatch) {
|
|
115
|
+
const [, owner, repo, ref] = githubTreeMatch;
|
|
116
|
+
return {
|
|
117
|
+
type: "github",
|
|
118
|
+
url: `https://github.com/${owner}/${repo}.git`,
|
|
119
|
+
ref
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const githubRepoMatch = input.match(/github\.com\/([^/]+)\/([^/]+)/);
|
|
123
|
+
if (githubRepoMatch) {
|
|
124
|
+
const [, owner, repo] = githubRepoMatch;
|
|
125
|
+
return {
|
|
126
|
+
type: "github",
|
|
127
|
+
url: `https://github.com/${owner}/${repo.replace(/\.git$/, "")}.git`
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const gitlabTreeWithPathMatch = input.match(/^(https?):\/\/([^/]+)\/(.+?)\/-\/tree\/([^/]+)\/(.+)/);
|
|
131
|
+
if (gitlabTreeWithPathMatch) {
|
|
132
|
+
const [, protocol, hostname, repoPath, ref, subpath] = gitlabTreeWithPathMatch;
|
|
133
|
+
if (hostname !== "github.com" && repoPath) return {
|
|
134
|
+
type: "gitlab",
|
|
135
|
+
url: `${protocol}://${hostname}/${repoPath.replace(/\.git$/, "")}.git`,
|
|
136
|
+
ref,
|
|
137
|
+
subpath
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const gitlabTreeMatch = input.match(/^(https?):\/\/([^/]+)\/(.+?)\/-\/tree\/([^/]+)$/);
|
|
141
|
+
if (gitlabTreeMatch) {
|
|
142
|
+
const [, protocol, hostname, repoPath, ref] = gitlabTreeMatch;
|
|
143
|
+
if (hostname !== "github.com" && repoPath) return {
|
|
144
|
+
type: "gitlab",
|
|
145
|
+
url: `${protocol}://${hostname}/${repoPath.replace(/\.git$/, "")}.git`,
|
|
146
|
+
ref
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const gitlabRepoMatch = input.match(/gitlab\.com\/(.+?)(?:\.git)?\/?$/);
|
|
150
|
+
if (gitlabRepoMatch) {
|
|
151
|
+
const repoPath = gitlabRepoMatch[1];
|
|
152
|
+
if (repoPath.includes("/")) return {
|
|
153
|
+
type: "gitlab",
|
|
154
|
+
url: `https://gitlab.com/${repoPath}.git`
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const atSkillMatch = input.match(/^([^/]+)\/([^/@]+)@(.+)$/);
|
|
158
|
+
if (atSkillMatch && !input.includes(":") && !input.startsWith(".") && !input.startsWith("/")) {
|
|
159
|
+
const [, owner, repo, skillFilter] = atSkillMatch;
|
|
160
|
+
return {
|
|
161
|
+
type: "gitlab",
|
|
162
|
+
url: buildDefaultGitUrl(`${owner}/${repo}`),
|
|
163
|
+
skillFilter
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const shorthandMatch = input.match(/^([^/]+)\/([^/]+)(?:\/(.+))?$/);
|
|
167
|
+
if (shorthandMatch && !input.includes(":") && !input.startsWith(".") && !input.startsWith("/")) {
|
|
168
|
+
const [, owner, repo, subpath] = shorthandMatch;
|
|
169
|
+
return {
|
|
170
|
+
type: "gitlab",
|
|
171
|
+
url: buildDefaultGitUrl(`${owner}/${repo}`),
|
|
172
|
+
subpath
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (isWellKnownUrl(input)) return {
|
|
176
|
+
type: "well-known",
|
|
177
|
+
url: input
|
|
178
|
+
};
|
|
179
|
+
return {
|
|
180
|
+
type: "git",
|
|
181
|
+
url: input
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function isWellKnownUrl(input) {
|
|
185
|
+
if (!input.startsWith("http://") && !input.startsWith("https://")) return false;
|
|
186
|
+
try {
|
|
187
|
+
const parsed = new URL(input);
|
|
188
|
+
if ([
|
|
189
|
+
"github.com",
|
|
190
|
+
"gitlab.com",
|
|
191
|
+
"raw.githubusercontent.com"
|
|
192
|
+
].includes(parsed.hostname)) return false;
|
|
193
|
+
if (input.endsWith(".git")) return false;
|
|
194
|
+
return true;
|
|
195
|
+
} catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const silentOutput = new Writable({ write(_chunk, _encoding, callback) {
|
|
200
|
+
callback();
|
|
201
|
+
} });
|
|
202
|
+
const S_STEP_ACTIVE = import_picocolors.default.green("◆");
|
|
203
|
+
const S_STEP_CANCEL = import_picocolors.default.red("■");
|
|
204
|
+
const S_STEP_SUBMIT = import_picocolors.default.green("◇");
|
|
205
|
+
const S_RADIO_ACTIVE = import_picocolors.default.green("●");
|
|
206
|
+
const S_RADIO_INACTIVE = import_picocolors.default.dim("○");
|
|
207
|
+
import_picocolors.default.green("✓");
|
|
208
|
+
const S_BULLET = import_picocolors.default.green("•");
|
|
209
|
+
const S_BAR = import_picocolors.default.dim("│");
|
|
210
|
+
const S_BAR_H = import_picocolors.default.dim("─");
|
|
211
|
+
const cancelSymbol = Symbol("cancel");
|
|
212
|
+
async function searchMultiselect(options) {
|
|
213
|
+
const { message, items, maxVisible = 8, initialSelected = [], required = false, lockedSection } = options;
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
const rl = readline.createInterface({
|
|
216
|
+
input: process.stdin,
|
|
217
|
+
output: silentOutput,
|
|
218
|
+
terminal: false
|
|
219
|
+
});
|
|
220
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
221
|
+
readline.emitKeypressEvents(process.stdin, rl);
|
|
222
|
+
let query = "";
|
|
223
|
+
let cursor = 0;
|
|
224
|
+
const selected = new Set(initialSelected);
|
|
225
|
+
let lastRenderHeight = 0;
|
|
226
|
+
const lockedValues = lockedSection ? lockedSection.items.map((i) => i.value) : [];
|
|
227
|
+
const filter = (item, q) => {
|
|
228
|
+
if (!q) return true;
|
|
229
|
+
const lowerQ = q.toLowerCase();
|
|
230
|
+
return item.label.toLowerCase().includes(lowerQ) || String(item.value).toLowerCase().includes(lowerQ);
|
|
231
|
+
};
|
|
232
|
+
const getFiltered = () => {
|
|
233
|
+
return items.filter((item) => filter(item, query));
|
|
234
|
+
};
|
|
235
|
+
const clearRender = () => {
|
|
236
|
+
if (lastRenderHeight > 0) {
|
|
237
|
+
process.stdout.write(`\x1b[${lastRenderHeight}A`);
|
|
238
|
+
for (let i = 0; i < lastRenderHeight; i++) process.stdout.write("\x1B[2K\x1B[1B");
|
|
239
|
+
process.stdout.write(`\x1b[${lastRenderHeight}A`);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
const render = (state = "active") => {
|
|
243
|
+
clearRender();
|
|
244
|
+
const lines = [];
|
|
245
|
+
const filtered = getFiltered();
|
|
246
|
+
const icon = state === "active" ? S_STEP_ACTIVE : state === "cancel" ? S_STEP_CANCEL : S_STEP_SUBMIT;
|
|
247
|
+
lines.push(`${icon} ${import_picocolors.default.bold(message)}`);
|
|
248
|
+
if (state === "active") {
|
|
249
|
+
if (lockedSection && lockedSection.items.length > 0) {
|
|
250
|
+
lines.push(`${S_BAR}`);
|
|
251
|
+
const lockedTitle = `${import_picocolors.default.bold(lockedSection.title)} ${import_picocolors.default.dim("── always included")}`;
|
|
252
|
+
lines.push(`${S_BAR} ${S_BAR_H}${S_BAR_H} ${lockedTitle} ${S_BAR_H.repeat(12)}`);
|
|
253
|
+
for (const item of lockedSection.items) lines.push(`${S_BAR} ${S_BULLET} ${import_picocolors.default.bold(item.label)}`);
|
|
254
|
+
lines.push(`${S_BAR}`);
|
|
255
|
+
lines.push(`${S_BAR} ${S_BAR_H}${S_BAR_H} ${import_picocolors.default.bold("Additional agents")} ${S_BAR_H.repeat(29)}`);
|
|
256
|
+
}
|
|
257
|
+
const searchLine = `${S_BAR} ${import_picocolors.default.dim("Search:")} ${query}${import_picocolors.default.inverse(" ")}`;
|
|
258
|
+
lines.push(searchLine);
|
|
259
|
+
lines.push(`${S_BAR} ${import_picocolors.default.dim("↑↓ move, space select, enter confirm")}`);
|
|
260
|
+
lines.push(`${S_BAR}`);
|
|
261
|
+
const visibleStart = Math.max(0, Math.min(cursor - Math.floor(maxVisible / 2), filtered.length - maxVisible));
|
|
262
|
+
const visibleEnd = Math.min(filtered.length, visibleStart + maxVisible);
|
|
263
|
+
const visibleItems = filtered.slice(visibleStart, visibleEnd);
|
|
264
|
+
if (filtered.length === 0) lines.push(`${S_BAR} ${import_picocolors.default.dim("No matches found")}`);
|
|
265
|
+
else {
|
|
266
|
+
for (let i = 0; i < visibleItems.length; i++) {
|
|
267
|
+
const item = visibleItems[i];
|
|
268
|
+
const actualIndex = visibleStart + i;
|
|
269
|
+
const isSelected = selected.has(item.value);
|
|
270
|
+
const isCursor = actualIndex === cursor;
|
|
271
|
+
const radio = isSelected ? S_RADIO_ACTIVE : S_RADIO_INACTIVE;
|
|
272
|
+
const label = isCursor ? import_picocolors.default.underline(item.label) : item.label;
|
|
273
|
+
const hint = item.hint ? import_picocolors.default.dim(` (${item.hint})`) : "";
|
|
274
|
+
const prefix = isCursor ? import_picocolors.default.cyan("❯") : " ";
|
|
275
|
+
lines.push(`${S_BAR} ${prefix} ${radio} ${label}${hint}`);
|
|
276
|
+
}
|
|
277
|
+
const hiddenBefore = visibleStart;
|
|
278
|
+
const hiddenAfter = filtered.length - visibleEnd;
|
|
279
|
+
if (hiddenBefore > 0 || hiddenAfter > 0) {
|
|
280
|
+
const parts = [];
|
|
281
|
+
if (hiddenBefore > 0) parts.push(`↑ ${hiddenBefore} more`);
|
|
282
|
+
if (hiddenAfter > 0) parts.push(`↓ ${hiddenAfter} more`);
|
|
283
|
+
lines.push(`${S_BAR} ${import_picocolors.default.dim(parts.join(" "))}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
lines.push(`${S_BAR}`);
|
|
287
|
+
const allSelectedLabels = [...lockedSection ? lockedSection.items.map((i) => i.label) : [], ...items.filter((item) => selected.has(item.value)).map((item) => item.label)];
|
|
288
|
+
if (allSelectedLabels.length === 0) lines.push(`${S_BAR} ${import_picocolors.default.dim("Selected: (none)")}`);
|
|
289
|
+
else {
|
|
290
|
+
const summary = allSelectedLabels.length <= 3 ? allSelectedLabels.join(", ") : `${allSelectedLabels.slice(0, 3).join(", ")} +${allSelectedLabels.length - 3} more`;
|
|
291
|
+
lines.push(`${S_BAR} ${import_picocolors.default.green("Selected:")} ${summary}`);
|
|
292
|
+
}
|
|
293
|
+
lines.push(`${import_picocolors.default.dim("└")}`);
|
|
294
|
+
} else if (state === "submit") {
|
|
295
|
+
const allSelectedLabels = [...lockedSection ? lockedSection.items.map((i) => i.label) : [], ...items.filter((item) => selected.has(item.value)).map((item) => item.label)];
|
|
296
|
+
lines.push(`${S_BAR} ${import_picocolors.default.dim(allSelectedLabels.join(", "))}`);
|
|
297
|
+
} else if (state === "cancel") lines.push(`${S_BAR} ${import_picocolors.default.strikethrough(import_picocolors.default.dim("Cancelled"))}`);
|
|
298
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
299
|
+
lastRenderHeight = lines.length;
|
|
300
|
+
};
|
|
301
|
+
const cleanup = () => {
|
|
302
|
+
process.stdin.removeListener("keypress", keypressHandler);
|
|
303
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
304
|
+
rl.close();
|
|
305
|
+
};
|
|
306
|
+
const submit = () => {
|
|
307
|
+
if (required && selected.size === 0 && lockedValues.length === 0) return;
|
|
308
|
+
render("submit");
|
|
309
|
+
cleanup();
|
|
310
|
+
resolve([...lockedValues, ...Array.from(selected)]);
|
|
311
|
+
};
|
|
312
|
+
const cancel = () => {
|
|
313
|
+
render("cancel");
|
|
314
|
+
cleanup();
|
|
315
|
+
resolve(cancelSymbol);
|
|
316
|
+
};
|
|
317
|
+
const keypressHandler = (_str, key) => {
|
|
318
|
+
if (!key) return;
|
|
319
|
+
const filtered = getFiltered();
|
|
320
|
+
if (key.name === "return") {
|
|
321
|
+
submit();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (key.name === "escape" || key.ctrl && key.name === "c") {
|
|
325
|
+
cancel();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (key.name === "up") {
|
|
329
|
+
cursor = Math.max(0, cursor - 1);
|
|
330
|
+
render();
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (key.name === "down") {
|
|
334
|
+
cursor = Math.min(filtered.length - 1, cursor + 1);
|
|
335
|
+
render();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (key.name === "space") {
|
|
339
|
+
const item = filtered[cursor];
|
|
340
|
+
if (item) if (selected.has(item.value)) selected.delete(item.value);
|
|
341
|
+
else selected.add(item.value);
|
|
342
|
+
render();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (key.name === "backspace") {
|
|
346
|
+
query = query.slice(0, -1);
|
|
347
|
+
cursor = 0;
|
|
348
|
+
render();
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (key.sequence && !key.ctrl && !key.meta && key.sequence.length === 1) {
|
|
352
|
+
query += key.sequence;
|
|
353
|
+
cursor = 0;
|
|
354
|
+
render();
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
process.stdin.on("keypress", keypressHandler);
|
|
359
|
+
render();
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
const CLONE_TIMEOUT_MS = 6e4;
|
|
363
|
+
var GitCloneError = class extends Error {
|
|
364
|
+
url;
|
|
365
|
+
isTimeout;
|
|
366
|
+
isAuthError;
|
|
367
|
+
constructor(message, url, isTimeout = false, isAuthError = false) {
|
|
368
|
+
super(message);
|
|
369
|
+
this.name = "GitCloneError";
|
|
370
|
+
this.url = url;
|
|
371
|
+
this.isTimeout = isTimeout;
|
|
372
|
+
this.isAuthError = isAuthError;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
async function cloneRepo(url, ref) {
|
|
376
|
+
const tempDir = await mkdtemp(join(tmpdir(), "skills-"));
|
|
377
|
+
const git = esm_default({
|
|
378
|
+
timeout: { block: CLONE_TIMEOUT_MS },
|
|
379
|
+
env: {
|
|
380
|
+
...process.env,
|
|
381
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
const cloneOptions = ref ? [
|
|
385
|
+
"--depth",
|
|
386
|
+
"1",
|
|
387
|
+
"--branch",
|
|
388
|
+
ref
|
|
389
|
+
] : ["--depth", "1"];
|
|
390
|
+
try {
|
|
391
|
+
await git.clone(url, tempDir, cloneOptions);
|
|
392
|
+
return tempDir;
|
|
393
|
+
} catch (error) {
|
|
394
|
+
await rm(tempDir, {
|
|
395
|
+
recursive: true,
|
|
396
|
+
force: true
|
|
397
|
+
}).catch(() => {});
|
|
398
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
399
|
+
const isTimeout = errorMessage.includes("block timeout") || errorMessage.includes("timed out");
|
|
400
|
+
const isAuthError = errorMessage.includes("Authentication failed") || errorMessage.includes("could not read Username") || errorMessage.includes("Permission denied") || errorMessage.includes("Repository not found");
|
|
401
|
+
if (isTimeout) throw new GitCloneError("Clone timed out after 60s. This often happens with private repos that require authentication.\n Ensure you have access and your SSH keys or credentials are configured:\n - For SSH: ssh-add -l (to check loaded keys)\n - For HTTPS: gh auth status (if using GitHub CLI)", url, true, false);
|
|
402
|
+
if (isAuthError) throw new GitCloneError(`Authentication failed for ${url}.\n - For private repos, ensure you have access\n - For SSH: Check your keys with 'ssh -T git@github.com'\n - For HTTPS: Run 'gh auth login' or configure git credentials`, url, false, true);
|
|
403
|
+
throw new GitCloneError(`Failed to clone ${url}: ${errorMessage}`, url, false, false);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
async function cleanupTempDir(dir) {
|
|
407
|
+
const normalizedDir = normalize(resolve(dir));
|
|
408
|
+
const normalizedTmpDir = normalize(resolve(tmpdir()));
|
|
409
|
+
if (!normalizedDir.startsWith(normalizedTmpDir + sep) && normalizedDir !== normalizedTmpDir) throw new Error("Attempted to clean up directory outside of temp directory");
|
|
410
|
+
await rm(dir, {
|
|
411
|
+
recursive: true,
|
|
412
|
+
force: true
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
var import_gray_matter = /* @__PURE__ */ __toESM(require_gray_matter(), 1);
|
|
416
|
+
function isContainedIn(targetPath, basePath) {
|
|
417
|
+
const normalizedBase = normalize(resolve(basePath));
|
|
418
|
+
const normalizedTarget = normalize(resolve(targetPath));
|
|
419
|
+
return normalizedTarget.startsWith(normalizedBase + sep) || normalizedTarget === normalizedBase;
|
|
420
|
+
}
|
|
421
|
+
function isValidRelativePath(path) {
|
|
422
|
+
return path.startsWith("./");
|
|
423
|
+
}
|
|
424
|
+
async function getPluginSkillPaths(basePath) {
|
|
425
|
+
const searchDirs = [];
|
|
426
|
+
const addPluginSkillPaths = (pluginBase, skills) => {
|
|
427
|
+
if (!isContainedIn(pluginBase, basePath)) return;
|
|
428
|
+
if (skills && skills.length > 0) for (const skillPath of skills) {
|
|
429
|
+
if (!isValidRelativePath(skillPath)) continue;
|
|
430
|
+
const skillDir = dirname(join(pluginBase, skillPath));
|
|
431
|
+
if (isContainedIn(skillDir, basePath)) searchDirs.push(skillDir);
|
|
432
|
+
}
|
|
433
|
+
searchDirs.push(join(pluginBase, "skills"));
|
|
434
|
+
};
|
|
435
|
+
try {
|
|
436
|
+
const content = await readFile(join(basePath, ".claude-plugin/marketplace.json"), "utf-8");
|
|
437
|
+
const manifest = JSON.parse(content);
|
|
438
|
+
const pluginRoot = manifest.metadata?.pluginRoot;
|
|
439
|
+
if (pluginRoot === void 0 || isValidRelativePath(pluginRoot)) for (const plugin of manifest.plugins ?? []) {
|
|
440
|
+
if (typeof plugin.source !== "string" && plugin.source !== void 0) continue;
|
|
441
|
+
if (plugin.source !== void 0 && !isValidRelativePath(plugin.source)) continue;
|
|
442
|
+
addPluginSkillPaths(join(basePath, pluginRoot ?? "", plugin.source ?? ""), plugin.skills);
|
|
443
|
+
}
|
|
444
|
+
} catch {}
|
|
445
|
+
try {
|
|
446
|
+
const content = await readFile(join(basePath, ".claude-plugin/plugin.json"), "utf-8");
|
|
447
|
+
addPluginSkillPaths(basePath, JSON.parse(content).skills);
|
|
448
|
+
} catch {}
|
|
449
|
+
return searchDirs;
|
|
450
|
+
}
|
|
451
|
+
async function getPluginGroupings(basePath) {
|
|
452
|
+
const groupings = /* @__PURE__ */ new Map();
|
|
453
|
+
try {
|
|
454
|
+
const content = await readFile(join(basePath, ".claude-plugin/marketplace.json"), "utf-8");
|
|
455
|
+
const manifest = JSON.parse(content);
|
|
456
|
+
const pluginRoot = manifest.metadata?.pluginRoot;
|
|
457
|
+
if (pluginRoot === void 0 || isValidRelativePath(pluginRoot)) for (const plugin of manifest.plugins ?? []) {
|
|
458
|
+
if (!plugin.name) continue;
|
|
459
|
+
if (typeof plugin.source !== "string" && plugin.source !== void 0) continue;
|
|
460
|
+
if (plugin.source !== void 0 && !isValidRelativePath(plugin.source)) continue;
|
|
461
|
+
const pluginBase = join(basePath, pluginRoot ?? "", plugin.source ?? "");
|
|
462
|
+
if (!isContainedIn(pluginBase, basePath)) continue;
|
|
463
|
+
if (plugin.skills && plugin.skills.length > 0) for (const skillPath of plugin.skills) {
|
|
464
|
+
if (!isValidRelativePath(skillPath)) continue;
|
|
465
|
+
const skillDir = join(pluginBase, skillPath);
|
|
466
|
+
if (isContainedIn(skillDir, basePath)) groupings.set(resolve(skillDir), plugin.name);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} catch {}
|
|
470
|
+
try {
|
|
471
|
+
const content = await readFile(join(basePath, ".claude-plugin/plugin.json"), "utf-8");
|
|
472
|
+
const manifest = JSON.parse(content);
|
|
473
|
+
if (manifest.name && manifest.skills && manifest.skills.length > 0) for (const skillPath of manifest.skills) {
|
|
474
|
+
if (!isValidRelativePath(skillPath)) continue;
|
|
475
|
+
const skillDir = join(basePath, skillPath);
|
|
476
|
+
if (isContainedIn(skillDir, basePath)) groupings.set(resolve(skillDir), manifest.name);
|
|
477
|
+
}
|
|
478
|
+
} catch {}
|
|
479
|
+
return groupings;
|
|
480
|
+
}
|
|
481
|
+
const SKIP_DIRS = [
|
|
482
|
+
"node_modules",
|
|
483
|
+
".git",
|
|
484
|
+
"dist",
|
|
485
|
+
"build",
|
|
486
|
+
"__pycache__"
|
|
487
|
+
];
|
|
488
|
+
function shouldInstallInternalSkills() {
|
|
489
|
+
const envValue = process.env.INSTALL_INTERNAL_SKILLS;
|
|
490
|
+
return envValue === "1" || envValue === "true";
|
|
491
|
+
}
|
|
492
|
+
async function hasSkillMd(dir) {
|
|
493
|
+
try {
|
|
494
|
+
return (await stat(join(dir, "SKILL.md"))).isFile();
|
|
495
|
+
} catch {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
async function parseSkillMd(skillMdPath, options) {
|
|
500
|
+
try {
|
|
501
|
+
const content = await readFile(skillMdPath, "utf-8");
|
|
502
|
+
const { data } = (0, import_gray_matter.default)(content);
|
|
503
|
+
if (!data.name || !data.description) return null;
|
|
504
|
+
if (typeof data.name !== "string" || typeof data.description !== "string") return null;
|
|
505
|
+
if (data.metadata?.internal === true && !shouldInstallInternalSkills() && !options?.includeInternal) return null;
|
|
506
|
+
return {
|
|
507
|
+
name: data.name,
|
|
508
|
+
description: data.description,
|
|
509
|
+
path: dirname(skillMdPath),
|
|
510
|
+
rawContent: content,
|
|
511
|
+
metadata: data.metadata
|
|
512
|
+
};
|
|
513
|
+
} catch {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async function findSkillDirs(dir, depth = 0, maxDepth = 5) {
|
|
518
|
+
if (depth > maxDepth) return [];
|
|
519
|
+
try {
|
|
520
|
+
const [hasSkill, entries] = await Promise.all([hasSkillMd(dir), readdir(dir, { withFileTypes: true }).catch(() => [])]);
|
|
521
|
+
const currentDir = hasSkill ? [dir] : [];
|
|
522
|
+
const subDirResults = await Promise.all(entries.filter((entry) => entry.isDirectory() && !SKIP_DIRS.includes(entry.name)).map((entry) => findSkillDirs(join(dir, entry.name), depth + 1, maxDepth)));
|
|
523
|
+
return [...currentDir, ...subDirResults.flat()];
|
|
524
|
+
} catch {
|
|
525
|
+
return [];
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
async function discoverSkills(basePath, subpath, options) {
|
|
529
|
+
const skills = [];
|
|
530
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
531
|
+
const searchPath = subpath ? join(basePath, subpath) : basePath;
|
|
532
|
+
const pluginGroupings = await getPluginGroupings(searchPath);
|
|
533
|
+
const enhanceSkill = (skill) => {
|
|
534
|
+
const resolvedPath = resolve(skill.path);
|
|
535
|
+
if (pluginGroupings.has(resolvedPath)) skill.pluginName = pluginGroupings.get(resolvedPath);
|
|
536
|
+
return skill;
|
|
537
|
+
};
|
|
538
|
+
if (await hasSkillMd(searchPath)) {
|
|
539
|
+
let skill = await parseSkillMd(join(searchPath, "SKILL.md"), options);
|
|
540
|
+
if (skill) {
|
|
541
|
+
skill = enhanceSkill(skill);
|
|
542
|
+
skills.push(skill);
|
|
543
|
+
seenNames.add(skill.name);
|
|
544
|
+
if (!options?.fullDepth) return skills;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const prioritySearchDirs = [
|
|
548
|
+
searchPath,
|
|
549
|
+
join(searchPath, "skills"),
|
|
550
|
+
join(searchPath, "skills/.curated"),
|
|
551
|
+
join(searchPath, "skills/.experimental"),
|
|
552
|
+
join(searchPath, "skills/.system"),
|
|
553
|
+
join(searchPath, ".agent/skills"),
|
|
554
|
+
join(searchPath, ".agents/skills"),
|
|
555
|
+
join(searchPath, ".claude/skills"),
|
|
556
|
+
join(searchPath, ".cline/skills"),
|
|
557
|
+
join(searchPath, ".codebuddy/skills"),
|
|
558
|
+
join(searchPath, ".codex/skills"),
|
|
559
|
+
join(searchPath, ".commandcode/skills"),
|
|
560
|
+
join(searchPath, ".continue/skills"),
|
|
561
|
+
join(searchPath, ".github/skills"),
|
|
562
|
+
join(searchPath, ".goose/skills"),
|
|
563
|
+
join(searchPath, ".iflow/skills"),
|
|
564
|
+
join(searchPath, ".junie/skills"),
|
|
565
|
+
join(searchPath, ".kilocode/skills"),
|
|
566
|
+
join(searchPath, ".kiro/skills"),
|
|
567
|
+
join(searchPath, ".mux/skills"),
|
|
568
|
+
join(searchPath, ".neovate/skills"),
|
|
569
|
+
join(searchPath, ".opencode/skills"),
|
|
570
|
+
join(searchPath, ".openhands/skills"),
|
|
571
|
+
join(searchPath, ".pi/skills"),
|
|
572
|
+
join(searchPath, ".qoder/skills"),
|
|
573
|
+
join(searchPath, ".roo/skills"),
|
|
574
|
+
join(searchPath, ".trae/skills"),
|
|
575
|
+
join(searchPath, ".windsurf/skills"),
|
|
576
|
+
join(searchPath, ".zencoder/skills")
|
|
577
|
+
];
|
|
578
|
+
prioritySearchDirs.push(...await getPluginSkillPaths(searchPath));
|
|
579
|
+
for (const dir of prioritySearchDirs) try {
|
|
580
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
581
|
+
for (const entry of entries) if (entry.isDirectory()) {
|
|
582
|
+
const skillDir = join(dir, entry.name);
|
|
583
|
+
if (await hasSkillMd(skillDir)) {
|
|
584
|
+
let skill = await parseSkillMd(join(skillDir, "SKILL.md"), options);
|
|
585
|
+
if (skill && !seenNames.has(skill.name)) {
|
|
586
|
+
skill = enhanceSkill(skill);
|
|
587
|
+
skills.push(skill);
|
|
588
|
+
seenNames.add(skill.name);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
} catch {}
|
|
593
|
+
if (skills.length === 0 || options?.fullDepth) {
|
|
594
|
+
const allSkillDirs = await findSkillDirs(searchPath);
|
|
595
|
+
for (const skillDir of allSkillDirs) {
|
|
596
|
+
let skill = await parseSkillMd(join(skillDir, "SKILL.md"), options);
|
|
597
|
+
if (skill && !seenNames.has(skill.name)) {
|
|
598
|
+
skill = enhanceSkill(skill);
|
|
599
|
+
skills.push(skill);
|
|
600
|
+
seenNames.add(skill.name);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return skills;
|
|
605
|
+
}
|
|
606
|
+
function getSkillDisplayName(skill) {
|
|
607
|
+
return skill.name || basename(skill.path);
|
|
608
|
+
}
|
|
609
|
+
function filterSkills(skills, inputNames) {
|
|
610
|
+
const normalizedInputs = inputNames.map((n) => n.toLowerCase());
|
|
611
|
+
return skills.filter((skill) => {
|
|
612
|
+
const name = skill.name.toLowerCase();
|
|
613
|
+
const displayName = getSkillDisplayName(skill).toLowerCase();
|
|
614
|
+
return normalizedInputs.some((input) => input === name || input === displayName);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
const home = homedir();
|
|
618
|
+
const configHome = xdgConfig ?? join(home, ".config");
|
|
619
|
+
const codexHome = process.env.CODEX_HOME?.trim() || join(home, ".codex");
|
|
620
|
+
const claudeHome = process.env.CLAUDE_CONFIG_DIR?.trim() || join(home, ".claude");
|
|
621
|
+
function getOpenClawGlobalSkillsDir(homeDir = home, pathExists = existsSync) {
|
|
622
|
+
if (pathExists(join(homeDir, ".openclaw"))) return join(homeDir, ".openclaw/skills");
|
|
623
|
+
if (pathExists(join(homeDir, ".clawdbot"))) return join(homeDir, ".clawdbot/skills");
|
|
624
|
+
if (pathExists(join(homeDir, ".moltbot"))) return join(homeDir, ".moltbot/skills");
|
|
625
|
+
return join(homeDir, ".openclaw/skills");
|
|
626
|
+
}
|
|
627
|
+
const agents = {
|
|
628
|
+
amp: {
|
|
629
|
+
name: "amp",
|
|
630
|
+
displayName: "Amp",
|
|
631
|
+
skillsDir: ".agents/skills",
|
|
632
|
+
globalSkillsDir: join(configHome, "agents/skills"),
|
|
633
|
+
detectInstalled: async () => {
|
|
634
|
+
return existsSync(join(configHome, "amp"));
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
antigravity: {
|
|
638
|
+
name: "antigravity",
|
|
639
|
+
displayName: "Antigravity",
|
|
640
|
+
skillsDir: ".agent/skills",
|
|
641
|
+
globalSkillsDir: join(home, ".gemini/antigravity/skills"),
|
|
642
|
+
detectInstalled: async () => {
|
|
643
|
+
return existsSync(join(home, ".gemini/antigravity"));
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
augment: {
|
|
647
|
+
name: "augment",
|
|
648
|
+
displayName: "Augment",
|
|
649
|
+
skillsDir: ".augment/skills",
|
|
650
|
+
globalSkillsDir: join(home, ".augment/skills"),
|
|
651
|
+
detectInstalled: async () => {
|
|
652
|
+
return existsSync(join(home, ".augment"));
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
"claude-code": {
|
|
656
|
+
name: "claude-code",
|
|
657
|
+
displayName: "Claude Code",
|
|
658
|
+
skillsDir: ".claude/skills",
|
|
659
|
+
globalSkillsDir: join(claudeHome, "skills"),
|
|
660
|
+
detectInstalled: async () => {
|
|
661
|
+
return existsSync(claudeHome);
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
openclaw: {
|
|
665
|
+
name: "openclaw",
|
|
666
|
+
displayName: "OpenClaw",
|
|
667
|
+
skillsDir: "skills",
|
|
668
|
+
globalSkillsDir: getOpenClawGlobalSkillsDir(),
|
|
669
|
+
detectInstalled: async () => {
|
|
670
|
+
return existsSync(join(home, ".openclaw")) || existsSync(join(home, ".clawdbot")) || existsSync(join(home, ".moltbot"));
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
cline: {
|
|
674
|
+
name: "cline",
|
|
675
|
+
displayName: "Cline",
|
|
676
|
+
skillsDir: ".agents/skills",
|
|
677
|
+
globalSkillsDir: join(home, ".agents", "skills"),
|
|
678
|
+
detectInstalled: async () => {
|
|
679
|
+
return existsSync(join(home, ".cline"));
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
codebuddy: {
|
|
683
|
+
name: "codebuddy",
|
|
684
|
+
displayName: "CodeBuddy",
|
|
685
|
+
skillsDir: ".codebuddy/skills",
|
|
686
|
+
globalSkillsDir: join(home, ".codebuddy/skills"),
|
|
687
|
+
detectInstalled: async () => {
|
|
688
|
+
return existsSync(join(process.cwd(), ".codebuddy")) || existsSync(join(home, ".codebuddy"));
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
codex: {
|
|
692
|
+
name: "codex",
|
|
693
|
+
displayName: "Codex",
|
|
694
|
+
skillsDir: ".agents/skills",
|
|
695
|
+
globalSkillsDir: join(codexHome, "skills"),
|
|
696
|
+
detectInstalled: async () => {
|
|
697
|
+
return existsSync(codexHome) || existsSync("/etc/codex");
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
"command-code": {
|
|
701
|
+
name: "command-code",
|
|
702
|
+
displayName: "Command Code",
|
|
703
|
+
skillsDir: ".commandcode/skills",
|
|
704
|
+
globalSkillsDir: join(home, ".commandcode/skills"),
|
|
705
|
+
detectInstalled: async () => {
|
|
706
|
+
return existsSync(join(home, ".commandcode"));
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
continue: {
|
|
710
|
+
name: "continue",
|
|
711
|
+
displayName: "Continue",
|
|
712
|
+
skillsDir: ".continue/skills",
|
|
713
|
+
globalSkillsDir: join(home, ".continue/skills"),
|
|
714
|
+
detectInstalled: async () => {
|
|
715
|
+
return existsSync(join(process.cwd(), ".continue")) || existsSync(join(home, ".continue"));
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
cortex: {
|
|
719
|
+
name: "cortex",
|
|
720
|
+
displayName: "Cortex Code",
|
|
721
|
+
skillsDir: ".cortex/skills",
|
|
722
|
+
globalSkillsDir: join(home, ".snowflake/cortex/skills"),
|
|
723
|
+
detectInstalled: async () => {
|
|
724
|
+
return existsSync(join(home, ".snowflake/cortex"));
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
crush: {
|
|
728
|
+
name: "crush",
|
|
729
|
+
displayName: "Crush",
|
|
730
|
+
skillsDir: ".crush/skills",
|
|
731
|
+
globalSkillsDir: join(home, ".config/crush/skills"),
|
|
732
|
+
detectInstalled: async () => {
|
|
733
|
+
return existsSync(join(home, ".config/crush"));
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
cursor: {
|
|
737
|
+
name: "cursor",
|
|
738
|
+
displayName: "Cursor",
|
|
739
|
+
skillsDir: ".agents/skills",
|
|
740
|
+
globalSkillsDir: join(home, ".cursor/skills"),
|
|
741
|
+
detectInstalled: async () => {
|
|
742
|
+
return existsSync(join(home, ".cursor"));
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
droid: {
|
|
746
|
+
name: "droid",
|
|
747
|
+
displayName: "Droid",
|
|
748
|
+
skillsDir: ".factory/skills",
|
|
749
|
+
globalSkillsDir: join(home, ".factory/skills"),
|
|
750
|
+
detectInstalled: async () => {
|
|
751
|
+
return existsSync(join(home, ".factory"));
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
"gemini-cli": {
|
|
755
|
+
name: "gemini-cli",
|
|
756
|
+
displayName: "Gemini CLI",
|
|
757
|
+
skillsDir: ".agents/skills",
|
|
758
|
+
globalSkillsDir: join(home, ".gemini/skills"),
|
|
759
|
+
detectInstalled: async () => {
|
|
760
|
+
return existsSync(join(home, ".gemini"));
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
"github-copilot": {
|
|
764
|
+
name: "github-copilot",
|
|
765
|
+
displayName: "GitHub Copilot",
|
|
766
|
+
skillsDir: ".agents/skills",
|
|
767
|
+
globalSkillsDir: join(home, ".copilot/skills"),
|
|
768
|
+
detectInstalled: async () => {
|
|
769
|
+
return existsSync(join(home, ".copilot"));
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
goose: {
|
|
773
|
+
name: "goose",
|
|
774
|
+
displayName: "Goose",
|
|
775
|
+
skillsDir: ".goose/skills",
|
|
776
|
+
globalSkillsDir: join(configHome, "goose/skills"),
|
|
777
|
+
detectInstalled: async () => {
|
|
778
|
+
return existsSync(join(configHome, "goose"));
|
|
779
|
+
}
|
|
780
|
+
},
|
|
781
|
+
junie: {
|
|
782
|
+
name: "junie",
|
|
783
|
+
displayName: "Junie",
|
|
784
|
+
skillsDir: ".junie/skills",
|
|
785
|
+
globalSkillsDir: join(home, ".junie/skills"),
|
|
786
|
+
detectInstalled: async () => {
|
|
787
|
+
return existsSync(join(home, ".junie"));
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
"iflow-cli": {
|
|
791
|
+
name: "iflow-cli",
|
|
792
|
+
displayName: "iFlow CLI",
|
|
793
|
+
skillsDir: ".iflow/skills",
|
|
794
|
+
globalSkillsDir: join(home, ".iflow/skills"),
|
|
795
|
+
detectInstalled: async () => {
|
|
796
|
+
return existsSync(join(home, ".iflow"));
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
kilo: {
|
|
800
|
+
name: "kilo",
|
|
801
|
+
displayName: "Kilo Code",
|
|
802
|
+
skillsDir: ".kilocode/skills",
|
|
803
|
+
globalSkillsDir: join(home, ".kilocode/skills"),
|
|
804
|
+
detectInstalled: async () => {
|
|
805
|
+
return existsSync(join(home, ".kilocode"));
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
"kimi-cli": {
|
|
809
|
+
name: "kimi-cli",
|
|
810
|
+
displayName: "Kimi Code CLI",
|
|
811
|
+
skillsDir: ".agents/skills",
|
|
812
|
+
globalSkillsDir: join(home, ".config/agents/skills"),
|
|
813
|
+
detectInstalled: async () => {
|
|
814
|
+
return existsSync(join(home, ".kimi"));
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
"kiro-cli": {
|
|
818
|
+
name: "kiro-cli",
|
|
819
|
+
displayName: "Kiro CLI",
|
|
820
|
+
skillsDir: ".kiro/skills",
|
|
821
|
+
globalSkillsDir: join(home, ".kiro/skills"),
|
|
822
|
+
detectInstalled: async () => {
|
|
823
|
+
return existsSync(join(home, ".kiro"));
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
kode: {
|
|
827
|
+
name: "kode",
|
|
828
|
+
displayName: "Kode",
|
|
829
|
+
skillsDir: ".kode/skills",
|
|
830
|
+
globalSkillsDir: join(home, ".kode/skills"),
|
|
831
|
+
detectInstalled: async () => {
|
|
832
|
+
return existsSync(join(home, ".kode"));
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
mcpjam: {
|
|
836
|
+
name: "mcpjam",
|
|
837
|
+
displayName: "MCPJam",
|
|
838
|
+
skillsDir: ".mcpjam/skills",
|
|
839
|
+
globalSkillsDir: join(home, ".mcpjam/skills"),
|
|
840
|
+
detectInstalled: async () => {
|
|
841
|
+
return existsSync(join(home, ".mcpjam"));
|
|
842
|
+
}
|
|
843
|
+
},
|
|
844
|
+
"mistral-vibe": {
|
|
845
|
+
name: "mistral-vibe",
|
|
846
|
+
displayName: "Mistral Vibe",
|
|
847
|
+
skillsDir: ".vibe/skills",
|
|
848
|
+
globalSkillsDir: join(home, ".vibe/skills"),
|
|
849
|
+
detectInstalled: async () => {
|
|
850
|
+
return existsSync(join(home, ".vibe"));
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
mux: {
|
|
854
|
+
name: "mux",
|
|
855
|
+
displayName: "Mux",
|
|
856
|
+
skillsDir: ".mux/skills",
|
|
857
|
+
globalSkillsDir: join(home, ".mux/skills"),
|
|
858
|
+
detectInstalled: async () => {
|
|
859
|
+
return existsSync(join(home, ".mux"));
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
opencode: {
|
|
863
|
+
name: "opencode",
|
|
864
|
+
displayName: "OpenCode",
|
|
865
|
+
skillsDir: ".agents/skills",
|
|
866
|
+
globalSkillsDir: join(configHome, "opencode/skills"),
|
|
867
|
+
detectInstalled: async () => {
|
|
868
|
+
return existsSync(join(configHome, "opencode"));
|
|
869
|
+
}
|
|
870
|
+
},
|
|
871
|
+
openhands: {
|
|
872
|
+
name: "openhands",
|
|
873
|
+
displayName: "OpenHands",
|
|
874
|
+
skillsDir: ".openhands/skills",
|
|
875
|
+
globalSkillsDir: join(home, ".openhands/skills"),
|
|
876
|
+
detectInstalled: async () => {
|
|
877
|
+
return existsSync(join(home, ".openhands"));
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
pi: {
|
|
881
|
+
name: "pi",
|
|
882
|
+
displayName: "Pi",
|
|
883
|
+
skillsDir: ".pi/skills",
|
|
884
|
+
globalSkillsDir: join(home, ".pi/agent/skills"),
|
|
885
|
+
detectInstalled: async () => {
|
|
886
|
+
return existsSync(join(home, ".pi/agent"));
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
qoder: {
|
|
890
|
+
name: "qoder",
|
|
891
|
+
displayName: "Qoder",
|
|
892
|
+
skillsDir: ".qoder/skills",
|
|
893
|
+
globalSkillsDir: join(home, ".qoder/skills"),
|
|
894
|
+
detectInstalled: async () => {
|
|
895
|
+
return existsSync(join(home, ".qoder"));
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
"qwen-code": {
|
|
899
|
+
name: "qwen-code",
|
|
900
|
+
displayName: "Qwen Code",
|
|
901
|
+
skillsDir: ".qwen/skills",
|
|
902
|
+
globalSkillsDir: join(home, ".qwen/skills"),
|
|
903
|
+
detectInstalled: async () => {
|
|
904
|
+
return existsSync(join(home, ".qwen"));
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
replit: {
|
|
908
|
+
name: "replit",
|
|
909
|
+
displayName: "Replit",
|
|
910
|
+
skillsDir: ".agents/skills",
|
|
911
|
+
globalSkillsDir: join(configHome, "agents/skills"),
|
|
912
|
+
showInUniversalList: false,
|
|
913
|
+
detectInstalled: async () => {
|
|
914
|
+
return existsSync(join(process.cwd(), ".replit"));
|
|
915
|
+
}
|
|
916
|
+
},
|
|
917
|
+
roo: {
|
|
918
|
+
name: "roo",
|
|
919
|
+
displayName: "Roo Code",
|
|
920
|
+
skillsDir: ".roo/skills",
|
|
921
|
+
globalSkillsDir: join(home, ".roo/skills"),
|
|
922
|
+
detectInstalled: async () => {
|
|
923
|
+
return existsSync(join(home, ".roo"));
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
trae: {
|
|
927
|
+
name: "trae",
|
|
928
|
+
displayName: "Trae",
|
|
929
|
+
skillsDir: ".trae/skills",
|
|
930
|
+
globalSkillsDir: join(home, ".trae/skills"),
|
|
931
|
+
detectInstalled: async () => {
|
|
932
|
+
return existsSync(join(home, ".trae"));
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
"trae-cn": {
|
|
936
|
+
name: "trae-cn",
|
|
937
|
+
displayName: "Trae CN",
|
|
938
|
+
skillsDir: ".trae/skills",
|
|
939
|
+
globalSkillsDir: join(home, ".trae-cn/skills"),
|
|
940
|
+
detectInstalled: async () => {
|
|
941
|
+
return existsSync(join(home, ".trae-cn"));
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
windsurf: {
|
|
945
|
+
name: "windsurf",
|
|
946
|
+
displayName: "Windsurf",
|
|
947
|
+
skillsDir: ".windsurf/skills",
|
|
948
|
+
globalSkillsDir: join(home, ".codeium/windsurf/skills"),
|
|
949
|
+
detectInstalled: async () => {
|
|
950
|
+
return existsSync(join(home, ".codeium/windsurf"));
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
zencoder: {
|
|
954
|
+
name: "zencoder",
|
|
955
|
+
displayName: "Zencoder",
|
|
956
|
+
skillsDir: ".zencoder/skills",
|
|
957
|
+
globalSkillsDir: join(home, ".zencoder/skills"),
|
|
958
|
+
detectInstalled: async () => {
|
|
959
|
+
return existsSync(join(home, ".zencoder"));
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
neovate: {
|
|
963
|
+
name: "neovate",
|
|
964
|
+
displayName: "Neovate",
|
|
965
|
+
skillsDir: ".neovate/skills",
|
|
966
|
+
globalSkillsDir: join(home, ".neovate/skills"),
|
|
967
|
+
detectInstalled: async () => {
|
|
968
|
+
return existsSync(join(home, ".neovate"));
|
|
969
|
+
}
|
|
970
|
+
},
|
|
971
|
+
pochi: {
|
|
972
|
+
name: "pochi",
|
|
973
|
+
displayName: "Pochi",
|
|
974
|
+
skillsDir: ".pochi/skills",
|
|
975
|
+
globalSkillsDir: join(home, ".pochi/skills"),
|
|
976
|
+
detectInstalled: async () => {
|
|
977
|
+
return existsSync(join(home, ".pochi"));
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
adal: {
|
|
981
|
+
name: "adal",
|
|
982
|
+
displayName: "AdaL",
|
|
983
|
+
skillsDir: ".adal/skills",
|
|
984
|
+
globalSkillsDir: join(home, ".adal/skills"),
|
|
985
|
+
detectInstalled: async () => {
|
|
986
|
+
return existsSync(join(home, ".adal"));
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
universal: {
|
|
990
|
+
name: "universal",
|
|
991
|
+
displayName: "Universal",
|
|
992
|
+
skillsDir: ".agents/skills",
|
|
993
|
+
globalSkillsDir: join(configHome, "agents/skills"),
|
|
994
|
+
showInUniversalList: false,
|
|
995
|
+
detectInstalled: async () => false
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
async function detectInstalledAgents() {
|
|
999
|
+
return (await Promise.all(Object.entries(agents).map(async ([type, config]) => ({
|
|
1000
|
+
type,
|
|
1001
|
+
installed: await config.detectInstalled()
|
|
1002
|
+
})))).filter((r) => r.installed).map((r) => r.type);
|
|
1003
|
+
}
|
|
1004
|
+
function getUniversalAgents() {
|
|
1005
|
+
return Object.entries(agents).filter(([_, config]) => config.skillsDir === ".agents/skills" && config.showInUniversalList !== false).map(([type]) => type);
|
|
1006
|
+
}
|
|
1007
|
+
function getNonUniversalAgents() {
|
|
1008
|
+
return Object.entries(agents).filter(([_, config]) => config.skillsDir !== ".agents/skills").map(([type]) => type);
|
|
1009
|
+
}
|
|
1010
|
+
function isUniversalAgent(type) {
|
|
1011
|
+
return agents[type].skillsDir === ".agents/skills";
|
|
1012
|
+
}
|
|
1013
|
+
function sanitizeName(name) {
|
|
1014
|
+
return name.toLowerCase().replace(/[^a-z0-9._]+/g, "-").replace(/^[.\-]+|[.\-]+$/g, "").substring(0, 255) || "unnamed-skill";
|
|
1015
|
+
}
|
|
1016
|
+
function isPathSafe(basePath, targetPath) {
|
|
1017
|
+
const normalizedBase = normalize(resolve(basePath));
|
|
1018
|
+
const normalizedTarget = normalize(resolve(targetPath));
|
|
1019
|
+
return normalizedTarget.startsWith(normalizedBase + sep) || normalizedTarget === normalizedBase;
|
|
1020
|
+
}
|
|
1021
|
+
function getCanonicalSkillsDir(global, cwd) {
|
|
1022
|
+
return join(global ? homedir() : cwd || process.cwd(), AGENTS_DIR$2, SKILLS_SUBDIR);
|
|
1023
|
+
}
|
|
1024
|
+
function getAgentBaseDir(agentType, global, cwd) {
|
|
1025
|
+
if (isUniversalAgent(agentType)) return getCanonicalSkillsDir(global, cwd);
|
|
1026
|
+
const agent = agents[agentType];
|
|
1027
|
+
const baseDir = global ? homedir() : cwd || process.cwd();
|
|
1028
|
+
if (global) {
|
|
1029
|
+
if (agent.globalSkillsDir === void 0) return join(baseDir, agent.skillsDir);
|
|
1030
|
+
return agent.globalSkillsDir;
|
|
1031
|
+
}
|
|
1032
|
+
return join(baseDir, agent.skillsDir);
|
|
1033
|
+
}
|
|
1034
|
+
function resolveSymlinkTarget(linkPath, linkTarget) {
|
|
1035
|
+
return resolve(dirname(linkPath), linkTarget);
|
|
1036
|
+
}
|
|
1037
|
+
async function cleanAndCreateDirectory(path) {
|
|
1038
|
+
try {
|
|
1039
|
+
await rm(path, {
|
|
1040
|
+
recursive: true,
|
|
1041
|
+
force: true
|
|
1042
|
+
});
|
|
1043
|
+
} catch {}
|
|
1044
|
+
await mkdir(path, { recursive: true });
|
|
1045
|
+
}
|
|
1046
|
+
async function resolveParentSymlinks(path) {
|
|
1047
|
+
const resolved = resolve(path);
|
|
1048
|
+
const dir = dirname(resolved);
|
|
1049
|
+
const base = basename(resolved);
|
|
1050
|
+
try {
|
|
1051
|
+
return join(await realpath(dir), base);
|
|
1052
|
+
} catch {
|
|
1053
|
+
return resolved;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
async function createSymlink(target, linkPath) {
|
|
1057
|
+
try {
|
|
1058
|
+
const resolvedTarget = resolve(target);
|
|
1059
|
+
const resolvedLinkPath = resolve(linkPath);
|
|
1060
|
+
const [realTarget, realLinkPath] = await Promise.all([realpath(resolvedTarget).catch(() => resolvedTarget), realpath(resolvedLinkPath).catch(() => resolvedLinkPath)]);
|
|
1061
|
+
if (realTarget === realLinkPath) return true;
|
|
1062
|
+
if (await resolveParentSymlinks(target) === await resolveParentSymlinks(linkPath)) return true;
|
|
1063
|
+
try {
|
|
1064
|
+
if ((await lstat(linkPath)).isSymbolicLink()) {
|
|
1065
|
+
if (resolveSymlinkTarget(linkPath, await readlink(linkPath)) === resolvedTarget) return true;
|
|
1066
|
+
await rm(linkPath);
|
|
1067
|
+
} else await rm(linkPath, { recursive: true });
|
|
1068
|
+
} catch (err) {
|
|
1069
|
+
if (err && typeof err === "object" && "code" in err && err.code === "ELOOP") try {
|
|
1070
|
+
await rm(linkPath, { force: true });
|
|
1071
|
+
} catch {}
|
|
1072
|
+
}
|
|
1073
|
+
const linkDir = dirname(linkPath);
|
|
1074
|
+
await mkdir(linkDir, { recursive: true });
|
|
1075
|
+
await symlink(relative(await resolveParentSymlinks(linkDir), target), linkPath, platform() === "win32" ? "junction" : void 0);
|
|
1076
|
+
return true;
|
|
1077
|
+
} catch {
|
|
1078
|
+
return false;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
async function installSkillForAgent(skill, agentType, options = {}) {
|
|
1082
|
+
const agent = agents[agentType];
|
|
1083
|
+
const isGlobal = options.global ?? false;
|
|
1084
|
+
const cwd = options.cwd || process.cwd();
|
|
1085
|
+
if (isGlobal && agent.globalSkillsDir === void 0) return {
|
|
1086
|
+
success: false,
|
|
1087
|
+
path: "",
|
|
1088
|
+
mode: options.mode ?? "symlink",
|
|
1089
|
+
error: `${agent.displayName} does not support global skill installation`
|
|
1090
|
+
};
|
|
1091
|
+
const skillName = sanitizeName(skill.name || basename(skill.path));
|
|
1092
|
+
const canonicalBase = getCanonicalSkillsDir(isGlobal, cwd);
|
|
1093
|
+
const canonicalDir = join(canonicalBase, skillName);
|
|
1094
|
+
const agentBase = getAgentBaseDir(agentType, isGlobal, cwd);
|
|
1095
|
+
const agentDir = join(agentBase, skillName);
|
|
1096
|
+
const installMode = options.mode ?? "symlink";
|
|
1097
|
+
if (!isPathSafe(canonicalBase, canonicalDir)) return {
|
|
1098
|
+
success: false,
|
|
1099
|
+
path: agentDir,
|
|
1100
|
+
mode: installMode,
|
|
1101
|
+
error: "Invalid skill name: potential path traversal detected"
|
|
1102
|
+
};
|
|
1103
|
+
if (!isPathSafe(agentBase, agentDir)) return {
|
|
1104
|
+
success: false,
|
|
1105
|
+
path: agentDir,
|
|
1106
|
+
mode: installMode,
|
|
1107
|
+
error: "Invalid skill name: potential path traversal detected"
|
|
1108
|
+
};
|
|
1109
|
+
try {
|
|
1110
|
+
if (installMode === "copy") {
|
|
1111
|
+
await cleanAndCreateDirectory(agentDir);
|
|
1112
|
+
await copyDirectory(skill.path, agentDir);
|
|
1113
|
+
return {
|
|
1114
|
+
success: true,
|
|
1115
|
+
path: agentDir,
|
|
1116
|
+
mode: "copy"
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
await cleanAndCreateDirectory(canonicalDir);
|
|
1120
|
+
await copyDirectory(skill.path, canonicalDir);
|
|
1121
|
+
if (isGlobal && isUniversalAgent(agentType)) return {
|
|
1122
|
+
success: true,
|
|
1123
|
+
path: canonicalDir,
|
|
1124
|
+
canonicalPath: canonicalDir,
|
|
1125
|
+
mode: "symlink"
|
|
1126
|
+
};
|
|
1127
|
+
if (!await createSymlink(canonicalDir, agentDir)) {
|
|
1128
|
+
await cleanAndCreateDirectory(agentDir);
|
|
1129
|
+
await copyDirectory(skill.path, agentDir);
|
|
1130
|
+
return {
|
|
1131
|
+
success: true,
|
|
1132
|
+
path: agentDir,
|
|
1133
|
+
canonicalPath: canonicalDir,
|
|
1134
|
+
mode: "symlink",
|
|
1135
|
+
symlinkFailed: true
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
return {
|
|
1139
|
+
success: true,
|
|
1140
|
+
path: agentDir,
|
|
1141
|
+
canonicalPath: canonicalDir,
|
|
1142
|
+
mode: "symlink"
|
|
1143
|
+
};
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
return {
|
|
1146
|
+
success: false,
|
|
1147
|
+
path: agentDir,
|
|
1148
|
+
mode: installMode,
|
|
1149
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const EXCLUDE_FILES = new Set(["metadata.json"]);
|
|
1154
|
+
const EXCLUDE_DIRS = new Set([".git"]);
|
|
1155
|
+
const isExcluded = (name, isDirectory = false) => {
|
|
1156
|
+
if (EXCLUDE_FILES.has(name)) return true;
|
|
1157
|
+
if (name.startsWith("_")) return true;
|
|
1158
|
+
if (isDirectory && EXCLUDE_DIRS.has(name)) return true;
|
|
1159
|
+
return false;
|
|
1160
|
+
};
|
|
1161
|
+
async function copyDirectory(src, dest) {
|
|
1162
|
+
await mkdir(dest, { recursive: true });
|
|
1163
|
+
const entries = await readdir(src, { withFileTypes: true });
|
|
1164
|
+
await Promise.all(entries.filter((entry) => !isExcluded(entry.name, entry.isDirectory())).map(async (entry) => {
|
|
1165
|
+
const srcPath = join(src, entry.name);
|
|
1166
|
+
const destPath = join(dest, entry.name);
|
|
1167
|
+
if (entry.isDirectory()) await copyDirectory(srcPath, destPath);
|
|
1168
|
+
else await cp(srcPath, destPath, {
|
|
1169
|
+
dereference: true,
|
|
1170
|
+
recursive: true
|
|
1171
|
+
});
|
|
1172
|
+
}));
|
|
1173
|
+
}
|
|
1174
|
+
async function isSkillInstalled(skillName, agentType, options = {}) {
|
|
1175
|
+
const agent = agents[agentType];
|
|
1176
|
+
const sanitized = sanitizeName(skillName);
|
|
1177
|
+
if (options.global && agent.globalSkillsDir === void 0) return false;
|
|
1178
|
+
const targetBase = options.global ? agent.globalSkillsDir : join(options.cwd || process.cwd(), agent.skillsDir);
|
|
1179
|
+
const skillDir = join(targetBase, sanitized);
|
|
1180
|
+
if (!isPathSafe(targetBase, skillDir)) return false;
|
|
1181
|
+
try {
|
|
1182
|
+
await access(skillDir);
|
|
1183
|
+
return true;
|
|
1184
|
+
} catch {
|
|
1185
|
+
return false;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function getInstallPath(skillName, agentType, options = {}) {
|
|
1189
|
+
agents[agentType];
|
|
1190
|
+
options.cwd || process.cwd();
|
|
1191
|
+
const sanitized = sanitizeName(skillName);
|
|
1192
|
+
const targetBase = getAgentBaseDir(agentType, options.global ?? false, options.cwd);
|
|
1193
|
+
const installPath = join(targetBase, sanitized);
|
|
1194
|
+
if (!isPathSafe(targetBase, installPath)) throw new Error("Invalid skill name: potential path traversal detected");
|
|
1195
|
+
return installPath;
|
|
1196
|
+
}
|
|
1197
|
+
function getCanonicalPath(skillName, options = {}) {
|
|
1198
|
+
const sanitized = sanitizeName(skillName);
|
|
1199
|
+
const canonicalBase = getCanonicalSkillsDir(options.global ?? false, options.cwd);
|
|
1200
|
+
const canonicalPath = join(canonicalBase, sanitized);
|
|
1201
|
+
if (!isPathSafe(canonicalBase, canonicalPath)) throw new Error("Invalid skill name: potential path traversal detected");
|
|
1202
|
+
return canonicalPath;
|
|
1203
|
+
}
|
|
1204
|
+
async function installWellKnownSkillForAgent(skill, agentType, options = {}) {
|
|
1205
|
+
const agent = agents[agentType];
|
|
1206
|
+
const isGlobal = options.global ?? false;
|
|
1207
|
+
const cwd = options.cwd || process.cwd();
|
|
1208
|
+
const installMode = options.mode ?? "symlink";
|
|
1209
|
+
if (isGlobal && agent.globalSkillsDir === void 0) return {
|
|
1210
|
+
success: false,
|
|
1211
|
+
path: "",
|
|
1212
|
+
mode: installMode,
|
|
1213
|
+
error: `${agent.displayName} does not support global skill installation`
|
|
1214
|
+
};
|
|
1215
|
+
const skillName = sanitizeName(skill.installName);
|
|
1216
|
+
const canonicalBase = getCanonicalSkillsDir(isGlobal, cwd);
|
|
1217
|
+
const canonicalDir = join(canonicalBase, skillName);
|
|
1218
|
+
const agentBase = getAgentBaseDir(agentType, isGlobal, cwd);
|
|
1219
|
+
const agentDir = join(agentBase, skillName);
|
|
1220
|
+
if (!isPathSafe(canonicalBase, canonicalDir)) return {
|
|
1221
|
+
success: false,
|
|
1222
|
+
path: agentDir,
|
|
1223
|
+
mode: installMode,
|
|
1224
|
+
error: "Invalid skill name: potential path traversal detected"
|
|
1225
|
+
};
|
|
1226
|
+
if (!isPathSafe(agentBase, agentDir)) return {
|
|
1227
|
+
success: false,
|
|
1228
|
+
path: agentDir,
|
|
1229
|
+
mode: installMode,
|
|
1230
|
+
error: "Invalid skill name: potential path traversal detected"
|
|
1231
|
+
};
|
|
1232
|
+
async function writeSkillFiles(targetDir) {
|
|
1233
|
+
for (const [filePath, content] of skill.files) {
|
|
1234
|
+
const fullPath = join(targetDir, filePath);
|
|
1235
|
+
if (!isPathSafe(targetDir, fullPath)) continue;
|
|
1236
|
+
const parentDir = dirname(fullPath);
|
|
1237
|
+
if (parentDir !== targetDir) await mkdir(parentDir, { recursive: true });
|
|
1238
|
+
await writeFile(fullPath, content, "utf-8");
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
try {
|
|
1242
|
+
if (installMode === "copy") {
|
|
1243
|
+
await cleanAndCreateDirectory(agentDir);
|
|
1244
|
+
await writeSkillFiles(agentDir);
|
|
1245
|
+
return {
|
|
1246
|
+
success: true,
|
|
1247
|
+
path: agentDir,
|
|
1248
|
+
mode: "copy"
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
await cleanAndCreateDirectory(canonicalDir);
|
|
1252
|
+
await writeSkillFiles(canonicalDir);
|
|
1253
|
+
if (isGlobal && isUniversalAgent(agentType)) return {
|
|
1254
|
+
success: true,
|
|
1255
|
+
path: canonicalDir,
|
|
1256
|
+
canonicalPath: canonicalDir,
|
|
1257
|
+
mode: "symlink"
|
|
1258
|
+
};
|
|
1259
|
+
if (!await createSymlink(canonicalDir, agentDir)) {
|
|
1260
|
+
await cleanAndCreateDirectory(agentDir);
|
|
1261
|
+
await writeSkillFiles(agentDir);
|
|
1262
|
+
return {
|
|
1263
|
+
success: true,
|
|
1264
|
+
path: agentDir,
|
|
1265
|
+
canonicalPath: canonicalDir,
|
|
1266
|
+
mode: "symlink",
|
|
1267
|
+
symlinkFailed: true
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
success: true,
|
|
1272
|
+
path: agentDir,
|
|
1273
|
+
canonicalPath: canonicalDir,
|
|
1274
|
+
mode: "symlink"
|
|
1275
|
+
};
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
return {
|
|
1278
|
+
success: false,
|
|
1279
|
+
path: agentDir,
|
|
1280
|
+
mode: installMode,
|
|
1281
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
async function listInstalledSkills(options = {}) {
|
|
1286
|
+
const cwd = options.cwd || process.cwd();
|
|
1287
|
+
const skillsMap = /* @__PURE__ */ new Map();
|
|
1288
|
+
const scopes = [];
|
|
1289
|
+
const detectedAgents = await detectInstalledAgents();
|
|
1290
|
+
const agentFilter = options.agentFilter;
|
|
1291
|
+
const agentsToCheck = agentFilter ? detectedAgents.filter((a) => agentFilter.includes(a)) : detectedAgents;
|
|
1292
|
+
const scopeTypes = [];
|
|
1293
|
+
if (options.global === void 0) scopeTypes.push({ global: false }, { global: true });
|
|
1294
|
+
else scopeTypes.push({ global: options.global });
|
|
1295
|
+
for (const { global: isGlobal } of scopeTypes) {
|
|
1296
|
+
scopes.push({
|
|
1297
|
+
global: isGlobal,
|
|
1298
|
+
path: getCanonicalSkillsDir(isGlobal, cwd)
|
|
1299
|
+
});
|
|
1300
|
+
for (const agentType of agentsToCheck) {
|
|
1301
|
+
const agent = agents[agentType];
|
|
1302
|
+
if (isGlobal && agent.globalSkillsDir === void 0) continue;
|
|
1303
|
+
const agentDir = isGlobal ? agent.globalSkillsDir : join(cwd, agent.skillsDir);
|
|
1304
|
+
if (!scopes.some((s) => s.path === agentDir && s.global === isGlobal)) scopes.push({
|
|
1305
|
+
global: isGlobal,
|
|
1306
|
+
path: agentDir,
|
|
1307
|
+
agentType
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
for (const scope of scopes) try {
|
|
1312
|
+
const entries = await readdir(scope.path, { withFileTypes: true });
|
|
1313
|
+
for (const entry of entries) {
|
|
1314
|
+
if (!entry.isDirectory()) continue;
|
|
1315
|
+
const skillDir = join(scope.path, entry.name);
|
|
1316
|
+
const skillMdPath = join(skillDir, "SKILL.md");
|
|
1317
|
+
try {
|
|
1318
|
+
await stat(skillMdPath);
|
|
1319
|
+
} catch {
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
const skill = await parseSkillMd(skillMdPath);
|
|
1323
|
+
if (!skill) continue;
|
|
1324
|
+
const scopeKey = scope.global ? "global" : "project";
|
|
1325
|
+
const skillKey = `${scopeKey}:${skill.name}`;
|
|
1326
|
+
if (scope.agentType) {
|
|
1327
|
+
if (skillsMap.has(skillKey)) {
|
|
1328
|
+
const existing = skillsMap.get(skillKey);
|
|
1329
|
+
if (!existing.agents.includes(scope.agentType)) existing.agents.push(scope.agentType);
|
|
1330
|
+
} else skillsMap.set(skillKey, {
|
|
1331
|
+
name: skill.name,
|
|
1332
|
+
description: skill.description,
|
|
1333
|
+
path: skillDir,
|
|
1334
|
+
canonicalPath: skillDir,
|
|
1335
|
+
scope: scopeKey,
|
|
1336
|
+
agents: [scope.agentType]
|
|
1337
|
+
});
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
const sanitizedSkillName = sanitizeName(skill.name);
|
|
1341
|
+
const installedAgents = [];
|
|
1342
|
+
for (const agentType of agentsToCheck) {
|
|
1343
|
+
const agent = agents[agentType];
|
|
1344
|
+
if (scope.global && agent.globalSkillsDir === void 0) continue;
|
|
1345
|
+
const agentBase = scope.global ? agent.globalSkillsDir : join(cwd, agent.skillsDir);
|
|
1346
|
+
let found = false;
|
|
1347
|
+
const possibleNames = Array.from(new Set([
|
|
1348
|
+
entry.name,
|
|
1349
|
+
sanitizedSkillName,
|
|
1350
|
+
skill.name.toLowerCase().replace(/\s+/g, "-").replace(/[\/\\:\0]/g, "")
|
|
1351
|
+
]));
|
|
1352
|
+
for (const possibleName of possibleNames) {
|
|
1353
|
+
const agentSkillDir = join(agentBase, possibleName);
|
|
1354
|
+
if (!isPathSafe(agentBase, agentSkillDir)) continue;
|
|
1355
|
+
try {
|
|
1356
|
+
await access(agentSkillDir);
|
|
1357
|
+
found = true;
|
|
1358
|
+
break;
|
|
1359
|
+
} catch {}
|
|
1360
|
+
}
|
|
1361
|
+
if (!found) try {
|
|
1362
|
+
const agentEntries = await readdir(agentBase, { withFileTypes: true });
|
|
1363
|
+
for (const agentEntry of agentEntries) {
|
|
1364
|
+
if (!agentEntry.isDirectory()) continue;
|
|
1365
|
+
const candidateDir = join(agentBase, agentEntry.name);
|
|
1366
|
+
if (!isPathSafe(agentBase, candidateDir)) continue;
|
|
1367
|
+
try {
|
|
1368
|
+
const candidateSkillMd = join(candidateDir, "SKILL.md");
|
|
1369
|
+
await stat(candidateSkillMd);
|
|
1370
|
+
const candidateSkill = await parseSkillMd(candidateSkillMd);
|
|
1371
|
+
if (candidateSkill && candidateSkill.name === skill.name) {
|
|
1372
|
+
found = true;
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
} catch {}
|
|
1376
|
+
}
|
|
1377
|
+
} catch {}
|
|
1378
|
+
if (found) installedAgents.push(agentType);
|
|
1379
|
+
}
|
|
1380
|
+
if (skillsMap.has(skillKey)) {
|
|
1381
|
+
const existing = skillsMap.get(skillKey);
|
|
1382
|
+
for (const agent of installedAgents) if (!existing.agents.includes(agent)) existing.agents.push(agent);
|
|
1383
|
+
} else skillsMap.set(skillKey, {
|
|
1384
|
+
name: skill.name,
|
|
1385
|
+
description: skill.description,
|
|
1386
|
+
path: skillDir,
|
|
1387
|
+
canonicalPath: skillDir,
|
|
1388
|
+
scope: scopeKey,
|
|
1389
|
+
agents: installedAgents
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
} catch {}
|
|
1393
|
+
return Array.from(skillsMap.values());
|
|
1394
|
+
}
|
|
1395
|
+
function getAllowedReportingUrl(envVarName) {
|
|
1396
|
+
const value = process.env[envVarName];
|
|
1397
|
+
if (!value) return null;
|
|
1398
|
+
return isAllowedReportingUrl(value) ? value : null;
|
|
1399
|
+
}
|
|
1400
|
+
const TELEMETRY_URL = getAllowedReportingUrl("SKILLS_TELEMETRY_URL");
|
|
1401
|
+
const AUDIT_URL = getAllowedReportingUrl("SKILLS_AUDIT_URL");
|
|
1402
|
+
let cliVersion = null;
|
|
1403
|
+
function isCI() {
|
|
1404
|
+
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.CIRCLECI || process.env.TRAVIS || process.env.BUILDKITE || process.env.JENKINS_URL || process.env.TEAMCITY_VERSION);
|
|
1405
|
+
}
|
|
1406
|
+
function isEnabled() {
|
|
1407
|
+
return !process.env.DISABLE_TELEMETRY && !process.env.DO_NOT_TRACK;
|
|
1408
|
+
}
|
|
1409
|
+
function setVersion(version) {
|
|
1410
|
+
cliVersion = version;
|
|
1411
|
+
}
|
|
1412
|
+
async function fetchAuditData(source, skillSlugs, timeoutMs = 3e3) {
|
|
1413
|
+
if (!AUDIT_URL) return null;
|
|
1414
|
+
if (skillSlugs.length === 0) return null;
|
|
1415
|
+
try {
|
|
1416
|
+
const params = new URLSearchParams({
|
|
1417
|
+
source,
|
|
1418
|
+
skills: skillSlugs.join(",")
|
|
1419
|
+
});
|
|
1420
|
+
const controller = new AbortController();
|
|
1421
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
1422
|
+
const response = await fetch(`${AUDIT_URL}?${params.toString()}`, { signal: controller.signal });
|
|
1423
|
+
clearTimeout(timeout);
|
|
1424
|
+
if (!response.ok) return null;
|
|
1425
|
+
return await response.json();
|
|
1426
|
+
} catch {
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
function track(data) {
|
|
1431
|
+
if (!TELEMETRY_URL) return;
|
|
1432
|
+
if (!isEnabled()) return;
|
|
1433
|
+
try {
|
|
1434
|
+
const params = new URLSearchParams();
|
|
1435
|
+
if (cliVersion) params.set("v", cliVersion);
|
|
1436
|
+
if (isCI()) params.set("ci", "1");
|
|
1437
|
+
for (const [key, value] of Object.entries(data)) if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
1438
|
+
fetch(`${TELEMETRY_URL}?${params.toString()}`).catch(() => {});
|
|
1439
|
+
} catch {}
|
|
1440
|
+
}
|
|
1441
|
+
var ProviderRegistryImpl = class {
|
|
1442
|
+
providers = [];
|
|
1443
|
+
register(provider) {
|
|
1444
|
+
if (this.providers.some((p) => p.id === provider.id)) throw new Error(`Provider with id "${provider.id}" already registered`);
|
|
1445
|
+
this.providers.push(provider);
|
|
1446
|
+
}
|
|
1447
|
+
findProvider(url) {
|
|
1448
|
+
for (const provider of this.providers) if (provider.match(url).matches) return provider;
|
|
1449
|
+
return null;
|
|
1450
|
+
}
|
|
1451
|
+
getProviders() {
|
|
1452
|
+
return [...this.providers];
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
new ProviderRegistryImpl();
|
|
1456
|
+
var WellKnownProvider = class {
|
|
1457
|
+
id = "well-known";
|
|
1458
|
+
displayName = "Well-Known Skills";
|
|
1459
|
+
WELL_KNOWN_PATH = ".well-known/skills";
|
|
1460
|
+
INDEX_FILE = "index.json";
|
|
1461
|
+
match(url) {
|
|
1462
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) return { matches: false };
|
|
1463
|
+
try {
|
|
1464
|
+
const parsed = new URL(url);
|
|
1465
|
+
if ([
|
|
1466
|
+
"github.com",
|
|
1467
|
+
"gitlab.com",
|
|
1468
|
+
"huggingface.co",
|
|
1469
|
+
DEFAULT_GIT_HOST
|
|
1470
|
+
].includes(parsed.hostname)) return { matches: false };
|
|
1471
|
+
return {
|
|
1472
|
+
matches: true,
|
|
1473
|
+
sourceIdentifier: `wellknown/${parsed.hostname}`
|
|
1474
|
+
};
|
|
1475
|
+
} catch {
|
|
1476
|
+
return { matches: false };
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
async fetchIndex(baseUrl) {
|
|
1480
|
+
try {
|
|
1481
|
+
const parsed = new URL(baseUrl);
|
|
1482
|
+
const basePath = parsed.pathname.replace(/\/$/, "");
|
|
1483
|
+
const urlsToTry = [{
|
|
1484
|
+
indexUrl: `${parsed.protocol}//${parsed.host}${basePath}/${this.WELL_KNOWN_PATH}/${this.INDEX_FILE}`,
|
|
1485
|
+
baseUrl: `${parsed.protocol}//${parsed.host}${basePath}`
|
|
1486
|
+
}];
|
|
1487
|
+
if (basePath && basePath !== "") urlsToTry.push({
|
|
1488
|
+
indexUrl: `${parsed.protocol}//${parsed.host}/${this.WELL_KNOWN_PATH}/${this.INDEX_FILE}`,
|
|
1489
|
+
baseUrl: `${parsed.protocol}//${parsed.host}`
|
|
1490
|
+
});
|
|
1491
|
+
for (const { indexUrl, baseUrl: resolvedBase } of urlsToTry) try {
|
|
1492
|
+
debugLog(`[well-known] requesting index: ${indexUrl}`);
|
|
1493
|
+
const response = await fetch(indexUrl);
|
|
1494
|
+
if (!response.ok) {
|
|
1495
|
+
debugLog(`[well-known] index response status: ${response.status} ${response.statusText}`);
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
const responseText = await response.text();
|
|
1499
|
+
debugLog(`[well-known] index response body: ${responseText}`);
|
|
1500
|
+
const index = JSON.parse(responseText);
|
|
1501
|
+
if (!index.skills || !Array.isArray(index.skills)) continue;
|
|
1502
|
+
let allValid = true;
|
|
1503
|
+
for (const entry of index.skills) if (!this.isValidSkillEntry(entry)) {
|
|
1504
|
+
allValid = false;
|
|
1505
|
+
break;
|
|
1506
|
+
}
|
|
1507
|
+
if (allValid) return {
|
|
1508
|
+
index,
|
|
1509
|
+
resolvedBaseUrl: resolvedBase
|
|
1510
|
+
};
|
|
1511
|
+
} catch {
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
return null;
|
|
1515
|
+
} catch {
|
|
1516
|
+
return null;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
isValidSkillEntry(entry) {
|
|
1520
|
+
if (!entry || typeof entry !== "object") return false;
|
|
1521
|
+
const e = entry;
|
|
1522
|
+
if (typeof e.name !== "string" || !e.name) return false;
|
|
1523
|
+
if (typeof e.description !== "string" || !e.description) return false;
|
|
1524
|
+
if (!Array.isArray(e.files) || e.files.length === 0) return false;
|
|
1525
|
+
if (!/^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$/.test(e.name) && e.name.length > 1) {
|
|
1526
|
+
if (e.name.length === 1 && !/^[a-z0-9]$/.test(e.name)) return false;
|
|
1527
|
+
}
|
|
1528
|
+
for (const file of e.files) {
|
|
1529
|
+
if (typeof file !== "string") return false;
|
|
1530
|
+
if (file.startsWith("/") || file.startsWith("\\") || file.includes("..")) return false;
|
|
1531
|
+
}
|
|
1532
|
+
if (!e.files.some((f) => typeof f === "string" && f.toLowerCase() === "skill.md")) return false;
|
|
1533
|
+
return true;
|
|
1534
|
+
}
|
|
1535
|
+
async fetchSkill(url) {
|
|
1536
|
+
try {
|
|
1537
|
+
const parsed = new URL(url);
|
|
1538
|
+
const result = await this.fetchIndex(url);
|
|
1539
|
+
if (!result) return null;
|
|
1540
|
+
const { index, resolvedBaseUrl } = result;
|
|
1541
|
+
let skillName = null;
|
|
1542
|
+
const pathMatch = parsed.pathname.match(/\/.well-known\/skills\/([^/]+)\/?$/);
|
|
1543
|
+
if (pathMatch && pathMatch[1] && pathMatch[1] !== "index.json") skillName = pathMatch[1];
|
|
1544
|
+
else if (index.skills.length === 1) skillName = index.skills[0].name;
|
|
1545
|
+
if (!skillName) return null;
|
|
1546
|
+
const skillEntry = index.skills.find((s) => s.name === skillName);
|
|
1547
|
+
if (!skillEntry) return null;
|
|
1548
|
+
return this.fetchSkillByEntry(resolvedBaseUrl, skillEntry);
|
|
1549
|
+
} catch {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
async fetchSkillByEntry(baseUrl, entry) {
|
|
1554
|
+
try {
|
|
1555
|
+
const skillBaseUrl = `${baseUrl.replace(/\/$/, "")}/${this.WELL_KNOWN_PATH}/${entry.name}`;
|
|
1556
|
+
const skillMdUrl = `${skillBaseUrl}/SKILL.md`;
|
|
1557
|
+
const response = await fetch(skillMdUrl);
|
|
1558
|
+
if (!response.ok) return null;
|
|
1559
|
+
const content = await response.text();
|
|
1560
|
+
const { data } = (0, import_gray_matter.default)(content);
|
|
1561
|
+
if (!data.name || !data.description) return null;
|
|
1562
|
+
const files = /* @__PURE__ */ new Map();
|
|
1563
|
+
files.set("SKILL.md", content);
|
|
1564
|
+
const filePromises = entry.files.filter((f) => f.toLowerCase() !== "skill.md").map(async (filePath) => {
|
|
1565
|
+
try {
|
|
1566
|
+
const fileUrl = `${skillBaseUrl}/${filePath}`;
|
|
1567
|
+
const fileResponse = await fetch(fileUrl);
|
|
1568
|
+
if (fileResponse.ok) return {
|
|
1569
|
+
path: filePath,
|
|
1570
|
+
content: await fileResponse.text()
|
|
1571
|
+
};
|
|
1572
|
+
} catch {}
|
|
1573
|
+
return null;
|
|
1574
|
+
});
|
|
1575
|
+
const fileResults = await Promise.all(filePromises);
|
|
1576
|
+
for (const result of fileResults) if (result) files.set(result.path, result.content);
|
|
1577
|
+
return {
|
|
1578
|
+
name: data.name,
|
|
1579
|
+
description: data.description,
|
|
1580
|
+
content,
|
|
1581
|
+
installName: entry.name,
|
|
1582
|
+
sourceUrl: skillMdUrl,
|
|
1583
|
+
metadata: data.metadata,
|
|
1584
|
+
files,
|
|
1585
|
+
indexEntry: entry
|
|
1586
|
+
};
|
|
1587
|
+
} catch {
|
|
1588
|
+
return null;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
async fetchAllSkills(url) {
|
|
1592
|
+
try {
|
|
1593
|
+
const result = await this.fetchIndex(url);
|
|
1594
|
+
if (!result) return [];
|
|
1595
|
+
const { index, resolvedBaseUrl } = result;
|
|
1596
|
+
const skillPromises = index.skills.map((entry) => this.fetchSkillByEntry(resolvedBaseUrl, entry));
|
|
1597
|
+
return (await Promise.all(skillPromises)).filter((s) => s !== null);
|
|
1598
|
+
} catch {
|
|
1599
|
+
return [];
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
toRawUrl(url) {
|
|
1603
|
+
try {
|
|
1604
|
+
const parsed = new URL(url);
|
|
1605
|
+
if (url.toLowerCase().endsWith("/skill.md")) return url;
|
|
1606
|
+
const pathMatch = parsed.pathname.match(/\/.well-known\/skills\/([^/]+)\/?$/);
|
|
1607
|
+
if (pathMatch && pathMatch[1]) {
|
|
1608
|
+
const basePath = parsed.pathname.replace(/\/.well-known\/skills\/.*$/, "");
|
|
1609
|
+
return `${parsed.protocol}//${parsed.host}${basePath}/${this.WELL_KNOWN_PATH}/${pathMatch[1]}/SKILL.md`;
|
|
1610
|
+
}
|
|
1611
|
+
const basePath = parsed.pathname.replace(/\/$/, "");
|
|
1612
|
+
return `${parsed.protocol}//${parsed.host}${basePath}/${this.WELL_KNOWN_PATH}/${this.INDEX_FILE}`;
|
|
1613
|
+
} catch {
|
|
1614
|
+
return url;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
getSourceIdentifier(url) {
|
|
1618
|
+
try {
|
|
1619
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
1620
|
+
} catch {
|
|
1621
|
+
return "unknown";
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
async hasSkillsIndex(url) {
|
|
1625
|
+
return await this.fetchIndex(url) !== null;
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
const wellKnownProvider = new WellKnownProvider();
|
|
1629
|
+
const AGENTS_DIR$1 = ".agents";
|
|
1630
|
+
const LOCK_FILE$1 = ".skill-lock.json";
|
|
1631
|
+
const CURRENT_VERSION$1 = 3;
|
|
1632
|
+
function getSkillLockPath$1() {
|
|
1633
|
+
return join(homedir(), AGENTS_DIR$1, LOCK_FILE$1);
|
|
1634
|
+
}
|
|
1635
|
+
async function readSkillLock$1() {
|
|
1636
|
+
const lockPath = getSkillLockPath$1();
|
|
1637
|
+
try {
|
|
1638
|
+
const content = await readFile(lockPath, "utf-8");
|
|
1639
|
+
const parsed = JSON.parse(content);
|
|
1640
|
+
if (typeof parsed.version !== "number" || !parsed.skills) return createEmptyLockFile();
|
|
1641
|
+
if (parsed.version < CURRENT_VERSION$1) return createEmptyLockFile();
|
|
1642
|
+
return parsed;
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
return createEmptyLockFile();
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
async function writeSkillLock(lock) {
|
|
1648
|
+
const lockPath = getSkillLockPath$1();
|
|
1649
|
+
await mkdir(dirname(lockPath), { recursive: true });
|
|
1650
|
+
await writeFile(lockPath, JSON.stringify(lock, null, 2), "utf-8");
|
|
1651
|
+
}
|
|
1652
|
+
function getGitHubToken() {
|
|
1653
|
+
if (process.env.GITHUB_TOKEN) return process.env.GITHUB_TOKEN;
|
|
1654
|
+
if (process.env.GH_TOKEN) return process.env.GH_TOKEN;
|
|
1655
|
+
try {
|
|
1656
|
+
const token = execSync("gh auth token", {
|
|
1657
|
+
encoding: "utf-8",
|
|
1658
|
+
stdio: [
|
|
1659
|
+
"pipe",
|
|
1660
|
+
"pipe",
|
|
1661
|
+
"pipe"
|
|
1662
|
+
]
|
|
1663
|
+
}).trim();
|
|
1664
|
+
if (token) return token;
|
|
1665
|
+
} catch {}
|
|
1666
|
+
return null;
|
|
1667
|
+
}
|
|
1668
|
+
async function fetchSkillFolderHash(ownerRepo, skillPath, token) {
|
|
1669
|
+
let folderPath = skillPath.replace(/\\/g, "/");
|
|
1670
|
+
if (folderPath.endsWith("/SKILL.md")) folderPath = folderPath.slice(0, -9);
|
|
1671
|
+
else if (folderPath.endsWith("SKILL.md")) folderPath = folderPath.slice(0, -8);
|
|
1672
|
+
if (folderPath.endsWith("/")) folderPath = folderPath.slice(0, -1);
|
|
1673
|
+
for (const branch of ["main", "master"]) try {
|
|
1674
|
+
const url = `https://api.github.com/repos/${ownerRepo}/git/trees/${branch}?recursive=1`;
|
|
1675
|
+
const headers = {
|
|
1676
|
+
Accept: "application/vnd.github.v3+json",
|
|
1677
|
+
"User-Agent": "skills-cli"
|
|
1678
|
+
};
|
|
1679
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
1680
|
+
const response = await fetch(url, { headers });
|
|
1681
|
+
if (!response.ok) continue;
|
|
1682
|
+
const data = await response.json();
|
|
1683
|
+
if (!folderPath) return data.sha;
|
|
1684
|
+
const folderEntry = data.tree.find((entry) => entry.type === "tree" && entry.path === folderPath);
|
|
1685
|
+
if (folderEntry) return folderEntry.sha;
|
|
1686
|
+
} catch {
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
return null;
|
|
1690
|
+
}
|
|
1691
|
+
async function addSkillToLock(skillName, entry) {
|
|
1692
|
+
const lock = await readSkillLock$1();
|
|
1693
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1694
|
+
const existingEntry = lock.skills[skillName];
|
|
1695
|
+
lock.skills[skillName] = {
|
|
1696
|
+
...entry,
|
|
1697
|
+
installedAt: existingEntry?.installedAt ?? now,
|
|
1698
|
+
updatedAt: now
|
|
1699
|
+
};
|
|
1700
|
+
await writeSkillLock(lock);
|
|
1701
|
+
}
|
|
1702
|
+
async function removeSkillFromLock(skillName) {
|
|
1703
|
+
const lock = await readSkillLock$1();
|
|
1704
|
+
if (!(skillName in lock.skills)) return false;
|
|
1705
|
+
delete lock.skills[skillName];
|
|
1706
|
+
await writeSkillLock(lock);
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
async function getSkillFromLock(skillName) {
|
|
1710
|
+
return (await readSkillLock$1()).skills[skillName] ?? null;
|
|
1711
|
+
}
|
|
1712
|
+
async function getAllLockedSkills() {
|
|
1713
|
+
return (await readSkillLock$1()).skills;
|
|
1714
|
+
}
|
|
1715
|
+
function createEmptyLockFile() {
|
|
1716
|
+
return {
|
|
1717
|
+
version: CURRENT_VERSION$1,
|
|
1718
|
+
skills: {},
|
|
1719
|
+
dismissed: {}
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
async function isPromptDismissed(promptKey) {
|
|
1723
|
+
return (await readSkillLock$1()).dismissed?.[promptKey] === true;
|
|
1724
|
+
}
|
|
1725
|
+
async function dismissPrompt(promptKey) {
|
|
1726
|
+
const lock = await readSkillLock$1();
|
|
1727
|
+
if (!lock.dismissed) lock.dismissed = {};
|
|
1728
|
+
lock.dismissed[promptKey] = true;
|
|
1729
|
+
await writeSkillLock(lock);
|
|
1730
|
+
}
|
|
1731
|
+
async function getLastSelectedAgents() {
|
|
1732
|
+
return (await readSkillLock$1()).lastSelectedAgents;
|
|
1733
|
+
}
|
|
1734
|
+
async function saveSelectedAgents(agents) {
|
|
1735
|
+
const lock = await readSkillLock$1();
|
|
1736
|
+
lock.lastSelectedAgents = agents;
|
|
1737
|
+
await writeSkillLock(lock);
|
|
1738
|
+
}
|
|
1739
|
+
const LOCAL_LOCK_FILE = "skills-lock.json";
|
|
1740
|
+
const CURRENT_VERSION = 1;
|
|
1741
|
+
function getLocalLockPath(cwd) {
|
|
1742
|
+
return join(cwd || process.cwd(), LOCAL_LOCK_FILE);
|
|
1743
|
+
}
|
|
1744
|
+
async function readLocalLock(cwd) {
|
|
1745
|
+
const lockPath = getLocalLockPath(cwd);
|
|
1746
|
+
try {
|
|
1747
|
+
const content = await readFile(lockPath, "utf-8");
|
|
1748
|
+
const parsed = JSON.parse(content);
|
|
1749
|
+
if (typeof parsed.version !== "number" || !parsed.skills) return createEmptyLocalLock();
|
|
1750
|
+
if (parsed.version < CURRENT_VERSION) return createEmptyLocalLock();
|
|
1751
|
+
return parsed;
|
|
1752
|
+
} catch {
|
|
1753
|
+
return createEmptyLocalLock();
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
async function writeLocalLock(lock, cwd) {
|
|
1757
|
+
const lockPath = getLocalLockPath(cwd);
|
|
1758
|
+
const sortedSkills = {};
|
|
1759
|
+
for (const key of Object.keys(lock.skills).sort()) sortedSkills[key] = lock.skills[key];
|
|
1760
|
+
const sorted = {
|
|
1761
|
+
version: lock.version,
|
|
1762
|
+
skills: sortedSkills
|
|
1763
|
+
};
|
|
1764
|
+
await writeFile(lockPath, JSON.stringify(sorted, null, 2) + "\n", "utf-8");
|
|
1765
|
+
}
|
|
1766
|
+
async function computeSkillFolderHash(skillDir) {
|
|
1767
|
+
const files = [];
|
|
1768
|
+
await collectFiles(skillDir, skillDir, files);
|
|
1769
|
+
files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
1770
|
+
const hash = createHash("sha256");
|
|
1771
|
+
for (const file of files) {
|
|
1772
|
+
hash.update(file.relativePath);
|
|
1773
|
+
hash.update(file.content);
|
|
1774
|
+
}
|
|
1775
|
+
return hash.digest("hex");
|
|
1776
|
+
}
|
|
1777
|
+
async function collectFiles(baseDir, currentDir, results) {
|
|
1778
|
+
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
1779
|
+
await Promise.all(entries.map(async (entry) => {
|
|
1780
|
+
const fullPath = join(currentDir, entry.name);
|
|
1781
|
+
if (entry.isDirectory()) {
|
|
1782
|
+
if (entry.name === ".git" || entry.name === "node_modules") return;
|
|
1783
|
+
await collectFiles(baseDir, fullPath, results);
|
|
1784
|
+
} else if (entry.isFile()) {
|
|
1785
|
+
const content = await readFile(fullPath);
|
|
1786
|
+
const relativePath = relative(baseDir, fullPath).split("\\").join("/");
|
|
1787
|
+
results.push({
|
|
1788
|
+
relativePath,
|
|
1789
|
+
content
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
}));
|
|
1793
|
+
}
|
|
1794
|
+
async function addSkillToLocalLock(skillName, entry, cwd) {
|
|
1795
|
+
const lock = await readLocalLock(cwd);
|
|
1796
|
+
lock.skills[skillName] = entry;
|
|
1797
|
+
await writeLocalLock(lock, cwd);
|
|
1798
|
+
}
|
|
1799
|
+
function createEmptyLocalLock() {
|
|
1800
|
+
return {
|
|
1801
|
+
version: CURRENT_VERSION,
|
|
1802
|
+
skills: {}
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
var version$1 = "1.4.3";
|
|
1806
|
+
const isCancelled$1 = (value) => typeof value === "symbol";
|
|
1807
|
+
async function isSourcePrivate(source) {
|
|
1808
|
+
const ownerRepo = parseOwnerRepo(source);
|
|
1809
|
+
if (!ownerRepo) return false;
|
|
1810
|
+
return isRepoPrivate(ownerRepo.owner, ownerRepo.repo);
|
|
1811
|
+
}
|
|
1812
|
+
function initTelemetry(version) {
|
|
1813
|
+
setVersion(version);
|
|
1814
|
+
}
|
|
1815
|
+
function riskLabel(risk) {
|
|
1816
|
+
switch (risk) {
|
|
1817
|
+
case "critical": return import_picocolors.default.red(import_picocolors.default.bold("Critical Risk"));
|
|
1818
|
+
case "high": return import_picocolors.default.red("High Risk");
|
|
1819
|
+
case "medium": return import_picocolors.default.yellow("Med Risk");
|
|
1820
|
+
case "low": return import_picocolors.default.green("Low Risk");
|
|
1821
|
+
case "safe": return import_picocolors.default.green("Safe");
|
|
1822
|
+
default: return import_picocolors.default.dim("--");
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
function socketLabel(audit) {
|
|
1826
|
+
if (!audit) return import_picocolors.default.dim("--");
|
|
1827
|
+
const count = audit.alerts ?? 0;
|
|
1828
|
+
return count > 0 ? import_picocolors.default.red(`${count} alert${count !== 1 ? "s" : ""}`) : import_picocolors.default.green("0 alerts");
|
|
1829
|
+
}
|
|
1830
|
+
function padEnd(str, width) {
|
|
1831
|
+
const visible = str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
1832
|
+
const pad = Math.max(0, width - visible.length);
|
|
1833
|
+
return str + " ".repeat(pad);
|
|
1834
|
+
}
|
|
1835
|
+
function buildSecurityLines(auditData, skills, source) {
|
|
1836
|
+
if (!auditData) return [];
|
|
1837
|
+
if (!skills.some((s) => {
|
|
1838
|
+
const data = auditData[s.slug];
|
|
1839
|
+
return data && Object.keys(data).length > 0;
|
|
1840
|
+
})) return [];
|
|
1841
|
+
const nameWidth = Math.min(Math.max(...skills.map((s) => s.displayName.length)), 36);
|
|
1842
|
+
const lines = [];
|
|
1843
|
+
const header = padEnd("", nameWidth + 2) + padEnd(import_picocolors.default.dim("Gen"), 18) + padEnd(import_picocolors.default.dim("Socket"), 18) + import_picocolors.default.dim("Snyk");
|
|
1844
|
+
lines.push(header);
|
|
1845
|
+
for (const skill of skills) {
|
|
1846
|
+
const data = auditData[skill.slug];
|
|
1847
|
+
const name = skill.displayName.length > nameWidth ? skill.displayName.slice(0, nameWidth - 1) + "…" : skill.displayName;
|
|
1848
|
+
const ath = data?.ath ? riskLabel(data.ath.risk) : import_picocolors.default.dim("--");
|
|
1849
|
+
const socket = data?.socket ? socketLabel(data.socket) : import_picocolors.default.dim("--");
|
|
1850
|
+
const snyk = data?.snyk ? riskLabel(data.snyk.risk) : import_picocolors.default.dim("--");
|
|
1851
|
+
lines.push(padEnd(import_picocolors.default.cyan(name), nameWidth + 2) + padEnd(ath, 18) + padEnd(socket, 18) + snyk);
|
|
1852
|
+
}
|
|
1853
|
+
lines.push("");
|
|
1854
|
+
lines.push(`${import_picocolors.default.dim("Details:")} ${import_picocolors.default.dim(`${DEFAULT_DISCOVERY_SITE_URL}/${source}`)}`);
|
|
1855
|
+
return lines;
|
|
1856
|
+
}
|
|
1857
|
+
function shortenPath$2(fullPath, cwd) {
|
|
1858
|
+
const home = homedir();
|
|
1859
|
+
if (fullPath === home || fullPath.startsWith(home + sep)) return "~" + fullPath.slice(home.length);
|
|
1860
|
+
if (fullPath === cwd || fullPath.startsWith(cwd + sep)) return "." + fullPath.slice(cwd.length);
|
|
1861
|
+
return fullPath;
|
|
1862
|
+
}
|
|
1863
|
+
function formatList$1(items, maxShow = 5) {
|
|
1864
|
+
if (items.length <= maxShow) return items.join(", ");
|
|
1865
|
+
const shown = items.slice(0, maxShow);
|
|
1866
|
+
const remaining = items.length - maxShow;
|
|
1867
|
+
return `${shown.join(", ")} +${remaining} more`;
|
|
1868
|
+
}
|
|
1869
|
+
function splitAgentsByType(agentTypes) {
|
|
1870
|
+
const universal = [];
|
|
1871
|
+
const symlinked = [];
|
|
1872
|
+
for (const a of agentTypes) if (isUniversalAgent(a)) universal.push(agents[a].displayName);
|
|
1873
|
+
else symlinked.push(agents[a].displayName);
|
|
1874
|
+
return {
|
|
1875
|
+
universal,
|
|
1876
|
+
symlinked
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
function buildAgentSummaryLines(targetAgents, installMode) {
|
|
1880
|
+
const lines = [];
|
|
1881
|
+
const { universal, symlinked } = splitAgentsByType(targetAgents);
|
|
1882
|
+
if (installMode === "symlink") {
|
|
1883
|
+
if (universal.length > 0) lines.push(` ${import_picocolors.default.green("universal:")} ${formatList$1(universal)}`);
|
|
1884
|
+
if (symlinked.length > 0) lines.push(` ${import_picocolors.default.dim("symlink →")} ${formatList$1(symlinked)}`);
|
|
1885
|
+
} else {
|
|
1886
|
+
const allNames = targetAgents.map((a) => agents[a].displayName);
|
|
1887
|
+
lines.push(` ${import_picocolors.default.dim("copy →")} ${formatList$1(allNames)}`);
|
|
1888
|
+
}
|
|
1889
|
+
return lines;
|
|
1890
|
+
}
|
|
1891
|
+
function ensureUniversalAgents(targetAgents) {
|
|
1892
|
+
const universalAgents = getUniversalAgents();
|
|
1893
|
+
const result = [...targetAgents];
|
|
1894
|
+
for (const ua of universalAgents) if (!result.includes(ua)) result.push(ua);
|
|
1895
|
+
return result;
|
|
1896
|
+
}
|
|
1897
|
+
function buildResultLines(results, targetAgents) {
|
|
1898
|
+
const lines = [];
|
|
1899
|
+
const { universal, symlinked: symlinkAgents } = splitAgentsByType(targetAgents);
|
|
1900
|
+
const successfulSymlinks = results.filter((r) => !r.symlinkFailed && !universal.includes(r.agent)).map((r) => r.agent);
|
|
1901
|
+
const failedSymlinks = results.filter((r) => r.symlinkFailed).map((r) => r.agent);
|
|
1902
|
+
if (universal.length > 0) lines.push(` ${import_picocolors.default.green("universal:")} ${formatList$1(universal)}`);
|
|
1903
|
+
if (successfulSymlinks.length > 0) lines.push(` ${import_picocolors.default.dim("symlinked:")} ${formatList$1(successfulSymlinks)}`);
|
|
1904
|
+
if (failedSymlinks.length > 0) lines.push(` ${import_picocolors.default.yellow("copied:")} ${formatList$1(failedSymlinks)}`);
|
|
1905
|
+
return lines;
|
|
1906
|
+
}
|
|
1907
|
+
function multiselect(opts) {
|
|
1908
|
+
return fe({
|
|
1909
|
+
...opts,
|
|
1910
|
+
options: opts.options,
|
|
1911
|
+
message: `${opts.message} ${import_picocolors.default.dim("(space to toggle)")}`
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
async function promptForAgents(message, choices) {
|
|
1915
|
+
let lastSelected;
|
|
1916
|
+
try {
|
|
1917
|
+
lastSelected = await getLastSelectedAgents();
|
|
1918
|
+
} catch {}
|
|
1919
|
+
const validAgents = choices.map((c) => c.value);
|
|
1920
|
+
const defaultValues = [
|
|
1921
|
+
"claude-code",
|
|
1922
|
+
"opencode",
|
|
1923
|
+
"codex"
|
|
1924
|
+
].filter((a) => validAgents.includes(a));
|
|
1925
|
+
let initialValues = [];
|
|
1926
|
+
if (lastSelected && lastSelected.length > 0) initialValues = lastSelected.filter((a) => validAgents.includes(a));
|
|
1927
|
+
if (initialValues.length === 0) initialValues = defaultValues;
|
|
1928
|
+
const selected = await searchMultiselect({
|
|
1929
|
+
message,
|
|
1930
|
+
items: choices,
|
|
1931
|
+
initialSelected: initialValues,
|
|
1932
|
+
required: true
|
|
1933
|
+
});
|
|
1934
|
+
if (!isCancelled$1(selected)) try {
|
|
1935
|
+
await saveSelectedAgents(selected);
|
|
1936
|
+
} catch {}
|
|
1937
|
+
return selected;
|
|
1938
|
+
}
|
|
1939
|
+
async function selectAgentsInteractive(options) {
|
|
1940
|
+
const supportsGlobalFilter = (a) => !options.global || agents[a].globalSkillsDir;
|
|
1941
|
+
const universalAgents = getUniversalAgents().filter(supportsGlobalFilter);
|
|
1942
|
+
const otherAgents = getNonUniversalAgents().filter(supportsGlobalFilter);
|
|
1943
|
+
const universalSection = {
|
|
1944
|
+
title: "Universal (.agents/skills)",
|
|
1945
|
+
items: universalAgents.map((a) => ({
|
|
1946
|
+
value: a,
|
|
1947
|
+
label: agents[a].displayName
|
|
1948
|
+
}))
|
|
1949
|
+
};
|
|
1950
|
+
const otherChoices = otherAgents.map((a) => ({
|
|
1951
|
+
value: a,
|
|
1952
|
+
label: agents[a].displayName,
|
|
1953
|
+
hint: options.global ? agents[a].globalSkillsDir : agents[a].skillsDir
|
|
1954
|
+
}));
|
|
1955
|
+
let lastSelected;
|
|
1956
|
+
try {
|
|
1957
|
+
lastSelected = await getLastSelectedAgents();
|
|
1958
|
+
} catch {}
|
|
1959
|
+
const selected = await searchMultiselect({
|
|
1960
|
+
message: "Which agents do you want to install to?",
|
|
1961
|
+
items: otherChoices,
|
|
1962
|
+
initialSelected: lastSelected ? lastSelected.filter((a) => otherAgents.includes(a) && !universalAgents.includes(a)) : [],
|
|
1963
|
+
lockedSection: universalSection
|
|
1964
|
+
});
|
|
1965
|
+
if (!isCancelled$1(selected)) try {
|
|
1966
|
+
await saveSelectedAgents(selected);
|
|
1967
|
+
} catch {}
|
|
1968
|
+
return selected;
|
|
1969
|
+
}
|
|
1970
|
+
setVersion(version$1);
|
|
1971
|
+
function isBareSkillNameSource(source) {
|
|
1972
|
+
return /^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$/.test(source);
|
|
1973
|
+
}
|
|
1974
|
+
function shouldProbeDefaultWellKnownPath(source) {
|
|
1975
|
+
return source.includes("/") && !source.includes("@") && !source.startsWith("http://") && !source.startsWith("https://") && !source.startsWith("git@") && !source.startsWith("ssh://") && !source.startsWith("./") && !source.startsWith("../") && source !== "." && source !== "..";
|
|
1976
|
+
}
|
|
1977
|
+
async function handleWellKnownSkills(source, url, options, spinner, allowFallback = false) {
|
|
1978
|
+
spinner.start("Discovering skills from well-known endpoint...");
|
|
1979
|
+
const skills = await wellKnownProvider.fetchAllSkills(url);
|
|
1980
|
+
if (skills.length === 0) {
|
|
1981
|
+
if (allowFallback) {
|
|
1982
|
+
spinner.stop(import_picocolors.default.yellow("Default well-known endpoint unavailable"));
|
|
1983
|
+
return false;
|
|
1984
|
+
}
|
|
1985
|
+
spinner.stop(import_picocolors.default.red("No skills found"));
|
|
1986
|
+
Se(import_picocolors.default.red("No skills found at this URL. Make sure the server has a /.well-known/skills/index.json file."));
|
|
1987
|
+
process.exit(1);
|
|
1988
|
+
}
|
|
1989
|
+
spinner.stop(`Found ${import_picocolors.default.green(skills.length)} skill${skills.length > 1 ? "s" : ""}`);
|
|
1990
|
+
for (const skill of skills) {
|
|
1991
|
+
M.info(`Skill: ${import_picocolors.default.cyan(skill.installName)}`);
|
|
1992
|
+
M.message(import_picocolors.default.dim(skill.description));
|
|
1993
|
+
if (skill.files.size > 1) M.message(import_picocolors.default.dim(` Files: ${Array.from(skill.files.keys()).join(", ")}`));
|
|
1994
|
+
}
|
|
1995
|
+
if (options.list) {
|
|
1996
|
+
console.log();
|
|
1997
|
+
M.step(import_picocolors.default.bold("Available Skills"));
|
|
1998
|
+
for (const skill of skills) {
|
|
1999
|
+
M.message(` ${import_picocolors.default.cyan(skill.installName)}`);
|
|
2000
|
+
M.message(` ${import_picocolors.default.dim(skill.description)}`);
|
|
2001
|
+
if (skill.files.size > 1) M.message(` ${import_picocolors.default.dim(`Files: ${skill.files.size}`)}`);
|
|
2002
|
+
}
|
|
2003
|
+
console.log();
|
|
2004
|
+
Se("Run without --list to install");
|
|
2005
|
+
process.exit(0);
|
|
2006
|
+
}
|
|
2007
|
+
let selectedSkills;
|
|
2008
|
+
if (options.skill?.includes("*")) {
|
|
2009
|
+
selectedSkills = skills;
|
|
2010
|
+
M.info(`Installing all ${skills.length} skills`);
|
|
2011
|
+
} else if (options.skill && options.skill.length > 0) {
|
|
2012
|
+
selectedSkills = skills.filter((s) => options.skill.some((name) => s.installName.toLowerCase() === name.toLowerCase() || s.name.toLowerCase() === name.toLowerCase()));
|
|
2013
|
+
if (selectedSkills.length === 0) {
|
|
2014
|
+
if (allowFallback) {
|
|
2015
|
+
M.info(`Skill not found on default well-known endpoint: ${options.skill.join(", ")}`);
|
|
2016
|
+
return false;
|
|
2017
|
+
}
|
|
2018
|
+
M.error(`No matching skills found for: ${options.skill.join(", ")}`);
|
|
2019
|
+
M.info("Available skills:");
|
|
2020
|
+
for (const s of skills) M.message(` - ${s.installName}`);
|
|
2021
|
+
process.exit(1);
|
|
2022
|
+
}
|
|
2023
|
+
} else if (skills.length === 1) {
|
|
2024
|
+
selectedSkills = skills;
|
|
2025
|
+
const firstSkill = skills[0];
|
|
2026
|
+
M.info(`Skill: ${import_picocolors.default.cyan(firstSkill.installName)}`);
|
|
2027
|
+
} else if (options.yes) {
|
|
2028
|
+
selectedSkills = skills;
|
|
2029
|
+
M.info(`Installing all ${skills.length} skills`);
|
|
2030
|
+
} else {
|
|
2031
|
+
const selected = await multiselect({
|
|
2032
|
+
message: "Select skills to install",
|
|
2033
|
+
options: skills.map((s) => ({
|
|
2034
|
+
value: s,
|
|
2035
|
+
label: s.installName,
|
|
2036
|
+
hint: s.description.length > 60 ? s.description.slice(0, 57) + "..." : s.description
|
|
2037
|
+
})),
|
|
2038
|
+
required: true
|
|
2039
|
+
});
|
|
2040
|
+
if (pD(selected)) {
|
|
2041
|
+
xe("Installation cancelled");
|
|
2042
|
+
process.exit(0);
|
|
2043
|
+
}
|
|
2044
|
+
selectedSkills = selected;
|
|
2045
|
+
}
|
|
2046
|
+
let targetAgents;
|
|
2047
|
+
const validAgents = Object.keys(agents);
|
|
2048
|
+
if (options.agent?.includes("*")) {
|
|
2049
|
+
targetAgents = validAgents;
|
|
2050
|
+
M.info(`Installing to all ${targetAgents.length} agents`);
|
|
2051
|
+
} else if (options.agent && options.agent.length > 0) {
|
|
2052
|
+
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
2053
|
+
if (invalidAgents.length > 0) {
|
|
2054
|
+
M.error(`Invalid agents: ${invalidAgents.join(", ")}`);
|
|
2055
|
+
M.info(`Valid agents: ${validAgents.join(", ")}`);
|
|
2056
|
+
process.exit(1);
|
|
2057
|
+
}
|
|
2058
|
+
targetAgents = options.agent;
|
|
2059
|
+
} else {
|
|
2060
|
+
spinner.start("Loading agents...");
|
|
2061
|
+
const installedAgents = await detectInstalledAgents();
|
|
2062
|
+
const totalAgents = Object.keys(agents).length;
|
|
2063
|
+
spinner.stop(`${totalAgents} agents`);
|
|
2064
|
+
if (installedAgents.length === 0) if (options.yes) {
|
|
2065
|
+
targetAgents = validAgents;
|
|
2066
|
+
M.info("Installing to all agents");
|
|
2067
|
+
} else {
|
|
2068
|
+
M.info("Select agents to install skills to");
|
|
2069
|
+
const selected = await promptForAgents("Which agents do you want to install to?", Object.entries(agents).map(([key, config]) => ({
|
|
2070
|
+
value: key,
|
|
2071
|
+
label: config.displayName
|
|
2072
|
+
})));
|
|
2073
|
+
if (pD(selected)) {
|
|
2074
|
+
xe("Installation cancelled");
|
|
2075
|
+
process.exit(0);
|
|
2076
|
+
}
|
|
2077
|
+
targetAgents = selected;
|
|
2078
|
+
}
|
|
2079
|
+
else if (installedAgents.length === 1 || options.yes) {
|
|
2080
|
+
targetAgents = ensureUniversalAgents(installedAgents);
|
|
2081
|
+
if (installedAgents.length === 1) {
|
|
2082
|
+
const firstAgent = installedAgents[0];
|
|
2083
|
+
M.info(`Installing to: ${import_picocolors.default.cyan(agents[firstAgent].displayName)}`);
|
|
2084
|
+
} else M.info(`Installing to: ${installedAgents.map((a) => import_picocolors.default.cyan(agents[a].displayName)).join(", ")}`);
|
|
2085
|
+
} else {
|
|
2086
|
+
const selected = await selectAgentsInteractive({ global: options.global });
|
|
2087
|
+
if (pD(selected)) {
|
|
2088
|
+
xe("Installation cancelled");
|
|
2089
|
+
process.exit(0);
|
|
2090
|
+
}
|
|
2091
|
+
targetAgents = selected;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
let installGlobally = options.global ?? false;
|
|
2095
|
+
const supportsGlobal = targetAgents.some((a) => agents[a].globalSkillsDir !== void 0);
|
|
2096
|
+
if (options.global === void 0 && !options.yes && supportsGlobal) {
|
|
2097
|
+
const scope = await ve({
|
|
2098
|
+
message: "Installation scope",
|
|
2099
|
+
options: [{
|
|
2100
|
+
value: false,
|
|
2101
|
+
label: "Project",
|
|
2102
|
+
hint: "Install in current directory (committed with your project)"
|
|
2103
|
+
}, {
|
|
2104
|
+
value: true,
|
|
2105
|
+
label: "Global",
|
|
2106
|
+
hint: "Install in home directory (available across all projects)"
|
|
2107
|
+
}]
|
|
2108
|
+
});
|
|
2109
|
+
if (pD(scope)) {
|
|
2110
|
+
xe("Installation cancelled");
|
|
2111
|
+
process.exit(0);
|
|
2112
|
+
}
|
|
2113
|
+
installGlobally = scope;
|
|
2114
|
+
}
|
|
2115
|
+
let installMode = options.copy ? "copy" : "symlink";
|
|
2116
|
+
if (!options.copy && !options.yes) {
|
|
2117
|
+
const modeChoice = await ve({
|
|
2118
|
+
message: "Installation method",
|
|
2119
|
+
options: [{
|
|
2120
|
+
value: "symlink",
|
|
2121
|
+
label: "Symlink (Recommended)",
|
|
2122
|
+
hint: "Single source of truth, easy updates"
|
|
2123
|
+
}, {
|
|
2124
|
+
value: "copy",
|
|
2125
|
+
label: "Copy to all agents",
|
|
2126
|
+
hint: "Independent copies for each agent"
|
|
2127
|
+
}]
|
|
2128
|
+
});
|
|
2129
|
+
if (pD(modeChoice)) {
|
|
2130
|
+
xe("Installation cancelled");
|
|
2131
|
+
process.exit(0);
|
|
2132
|
+
}
|
|
2133
|
+
installMode = modeChoice;
|
|
2134
|
+
}
|
|
2135
|
+
const cwd = process.cwd();
|
|
2136
|
+
const summaryLines = [];
|
|
2137
|
+
targetAgents.map((a) => agents[a].displayName);
|
|
2138
|
+
const overwriteChecks = await Promise.all(selectedSkills.flatMap((skill) => targetAgents.map(async (agent) => ({
|
|
2139
|
+
skillName: skill.installName,
|
|
2140
|
+
agent,
|
|
2141
|
+
installed: await isSkillInstalled(skill.installName, agent, { global: installGlobally })
|
|
2142
|
+
}))));
|
|
2143
|
+
const overwriteStatus = /* @__PURE__ */ new Map();
|
|
2144
|
+
for (const { skillName, agent, installed } of overwriteChecks) {
|
|
2145
|
+
if (!overwriteStatus.has(skillName)) overwriteStatus.set(skillName, /* @__PURE__ */ new Map());
|
|
2146
|
+
overwriteStatus.get(skillName).set(agent, installed);
|
|
2147
|
+
}
|
|
2148
|
+
for (const skill of selectedSkills) {
|
|
2149
|
+
if (summaryLines.length > 0) summaryLines.push("");
|
|
2150
|
+
const shortCanonical = shortenPath$2(getCanonicalPath(skill.installName, { global: installGlobally }), cwd);
|
|
2151
|
+
summaryLines.push(`${import_picocolors.default.cyan(shortCanonical)}`);
|
|
2152
|
+
summaryLines.push(...buildAgentSummaryLines(targetAgents, installMode));
|
|
2153
|
+
if (skill.files.size > 1) summaryLines.push(` ${import_picocolors.default.dim("files:")} ${skill.files.size}`);
|
|
2154
|
+
const skillOverwrites = overwriteStatus.get(skill.installName);
|
|
2155
|
+
const overwriteAgents = targetAgents.filter((a) => skillOverwrites?.get(a)).map((a) => agents[a].displayName);
|
|
2156
|
+
if (overwriteAgents.length > 0) summaryLines.push(` ${import_picocolors.default.yellow("overwrites:")} ${formatList$1(overwriteAgents)}`);
|
|
2157
|
+
}
|
|
2158
|
+
console.log();
|
|
2159
|
+
Me(summaryLines.join("\n"), "Installation Summary");
|
|
2160
|
+
if (!options.yes) {
|
|
2161
|
+
const confirmed = await ye({ message: "Proceed with installation?" });
|
|
2162
|
+
if (pD(confirmed) || !confirmed) {
|
|
2163
|
+
xe("Installation cancelled");
|
|
2164
|
+
process.exit(0);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
spinner.start("Installing skills...");
|
|
2168
|
+
const results = [];
|
|
2169
|
+
for (const skill of selectedSkills) for (const agent of targetAgents) {
|
|
2170
|
+
const result = await installWellKnownSkillForAgent(skill, agent, {
|
|
2171
|
+
global: installGlobally,
|
|
2172
|
+
mode: installMode
|
|
2173
|
+
});
|
|
2174
|
+
results.push({
|
|
2175
|
+
skill: skill.installName,
|
|
2176
|
+
agent: agents[agent].displayName,
|
|
2177
|
+
...result
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2180
|
+
spinner.stop("Installation complete");
|
|
2181
|
+
console.log();
|
|
2182
|
+
const successful = results.filter((r) => r.success);
|
|
2183
|
+
const failed = results.filter((r) => !r.success);
|
|
2184
|
+
const sourceIdentifier = wellKnownProvider.getSourceIdentifier(url);
|
|
2185
|
+
const skillFiles = {};
|
|
2186
|
+
for (const skill of selectedSkills) skillFiles[skill.installName] = skill.sourceUrl;
|
|
2187
|
+
if (await isSourcePrivate(sourceIdentifier) !== true) track({
|
|
2188
|
+
event: "install",
|
|
2189
|
+
source: sourceIdentifier,
|
|
2190
|
+
skills: selectedSkills.map((s) => s.installName).join(","),
|
|
2191
|
+
agents: targetAgents.join(","),
|
|
2192
|
+
...installGlobally && { global: "1" },
|
|
2193
|
+
skillFiles: JSON.stringify(skillFiles),
|
|
2194
|
+
sourceType: "well-known"
|
|
2195
|
+
});
|
|
2196
|
+
if (successful.length > 0 && installGlobally) {
|
|
2197
|
+
const successfulSkillNames = new Set(successful.map((r) => r.skill));
|
|
2198
|
+
for (const skill of selectedSkills) if (successfulSkillNames.has(skill.installName)) try {
|
|
2199
|
+
await addSkillToLock(skill.installName, {
|
|
2200
|
+
source: sourceIdentifier,
|
|
2201
|
+
sourceType: "well-known",
|
|
2202
|
+
sourceUrl: skill.sourceUrl,
|
|
2203
|
+
skillFolderHash: ""
|
|
2204
|
+
});
|
|
2205
|
+
} catch {}
|
|
2206
|
+
}
|
|
2207
|
+
if (successful.length > 0 && !installGlobally) {
|
|
2208
|
+
const successfulSkillNames = new Set(successful.map((r) => r.skill));
|
|
2209
|
+
for (const skill of selectedSkills) if (successfulSkillNames.has(skill.installName)) try {
|
|
2210
|
+
const matchingResult = successful.find((r) => r.skill === skill.installName);
|
|
2211
|
+
const installDir = matchingResult?.canonicalPath || matchingResult?.path;
|
|
2212
|
+
if (installDir) {
|
|
2213
|
+
const computedHash = await computeSkillFolderHash(installDir);
|
|
2214
|
+
await addSkillToLocalLock(skill.installName, {
|
|
2215
|
+
source: sourceIdentifier,
|
|
2216
|
+
sourceType: "well-known",
|
|
2217
|
+
computedHash
|
|
2218
|
+
}, cwd);
|
|
2219
|
+
}
|
|
2220
|
+
} catch {}
|
|
2221
|
+
}
|
|
2222
|
+
if (successful.length > 0) {
|
|
2223
|
+
const bySkill = /* @__PURE__ */ new Map();
|
|
2224
|
+
for (const r of successful) {
|
|
2225
|
+
const skillResults = bySkill.get(r.skill) || [];
|
|
2226
|
+
skillResults.push(r);
|
|
2227
|
+
bySkill.set(r.skill, skillResults);
|
|
2228
|
+
}
|
|
2229
|
+
const skillCount = bySkill.size;
|
|
2230
|
+
const symlinkFailures = successful.filter((r) => r.mode === "symlink" && r.symlinkFailed);
|
|
2231
|
+
const copiedAgents = symlinkFailures.map((r) => r.agent);
|
|
2232
|
+
const resultLines = [];
|
|
2233
|
+
for (const [skillName, skillResults] of bySkill) {
|
|
2234
|
+
const firstResult = skillResults[0];
|
|
2235
|
+
if (firstResult.mode === "copy") {
|
|
2236
|
+
resultLines.push(`${import_picocolors.default.green("✓")} ${skillName} ${import_picocolors.default.dim("(copied)")}`);
|
|
2237
|
+
for (const r of skillResults) {
|
|
2238
|
+
const shortPath = shortenPath$2(r.path, cwd);
|
|
2239
|
+
resultLines.push(` ${import_picocolors.default.dim("→")} ${shortPath}`);
|
|
2240
|
+
}
|
|
2241
|
+
} else {
|
|
2242
|
+
if (firstResult.canonicalPath) {
|
|
2243
|
+
const shortPath = shortenPath$2(firstResult.canonicalPath, cwd);
|
|
2244
|
+
resultLines.push(`${import_picocolors.default.green("✓")} ${shortPath}`);
|
|
2245
|
+
} else resultLines.push(`${import_picocolors.default.green("✓")} ${skillName}`);
|
|
2246
|
+
resultLines.push(...buildResultLines(skillResults, targetAgents));
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
const title = import_picocolors.default.green(`Installed ${skillCount} skill${skillCount !== 1 ? "s" : ""}`);
|
|
2250
|
+
Me(resultLines.join("\n"), title);
|
|
2251
|
+
if (symlinkFailures.length > 0) {
|
|
2252
|
+
M.warn(import_picocolors.default.yellow(`Symlinks failed for: ${formatList$1(copiedAgents)}`));
|
|
2253
|
+
M.message(import_picocolors.default.dim(" Files were copied instead. On Windows, enable Developer Mode for symlink support."));
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
if (failed.length > 0) {
|
|
2257
|
+
console.log();
|
|
2258
|
+
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
2259
|
+
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill} → ${r.agent}: ${import_picocolors.default.dim(r.error)}`);
|
|
2260
|
+
}
|
|
2261
|
+
console.log();
|
|
2262
|
+
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
2263
|
+
await promptForFindSkills(options, targetAgents);
|
|
2264
|
+
return true;
|
|
2265
|
+
}
|
|
2266
|
+
async function runAdd(args, options = {}) {
|
|
2267
|
+
let source = args[0] || DEFAULT_WELL_KNOWN_BASE_URL;
|
|
2268
|
+
let installTipShown = false;
|
|
2269
|
+
const showInstallTip = () => {
|
|
2270
|
+
if (installTipShown) return;
|
|
2271
|
+
M.message(import_picocolors.default.dim("Tip: use the --yes (-y) and --global (-g) flags to install without prompts."));
|
|
2272
|
+
installTipShown = true;
|
|
2273
|
+
};
|
|
2274
|
+
if (options.all) {
|
|
2275
|
+
options.skill = ["*"];
|
|
2276
|
+
options.agent = ["*"];
|
|
2277
|
+
options.yes = true;
|
|
2278
|
+
}
|
|
2279
|
+
console.log();
|
|
2280
|
+
Ie(import_picocolors.default.bgCyan(import_picocolors.default.black(" bip-skills ")));
|
|
2281
|
+
if (!process.stdin.isTTY) showInstallTip();
|
|
2282
|
+
let tempDir = null;
|
|
2283
|
+
try {
|
|
2284
|
+
const spinner = Y();
|
|
2285
|
+
if (source && isBareSkillNameSource(source)) {
|
|
2286
|
+
options.skill = options.skill || [];
|
|
2287
|
+
if (!options.skill.includes(source)) options.skill.push(source);
|
|
2288
|
+
if (await handleWellKnownSkills(source, DEFAULT_WELL_KNOWN_BASE_URL, options, spinner, true)) return;
|
|
2289
|
+
Se(import_picocolors.default.red(`No skills found for: ${source}`));
|
|
2290
|
+
process.exit(1);
|
|
2291
|
+
}
|
|
2292
|
+
if (source && shouldProbeDefaultWellKnownPath(source)) {
|
|
2293
|
+
if (await handleWellKnownSkills(source, `${DEFAULT_WELL_KNOWN_BASE_URL}/${source.replace(/^\/+/, "")}`, options, spinner, true)) return;
|
|
2294
|
+
M.info(`Falling back to source parsing: ${import_picocolors.default.cyan(source)}`);
|
|
2295
|
+
}
|
|
2296
|
+
spinner.start("Parsing source...");
|
|
2297
|
+
const parsed = parseSource(source);
|
|
2298
|
+
spinner.stop(`Source: ${parsed.type === "local" ? parsed.localPath : parsed.url}${parsed.ref ? ` @ ${import_picocolors.default.yellow(parsed.ref)}` : ""}${parsed.subpath ? ` (${parsed.subpath})` : ""}${parsed.skillFilter ? ` ${import_picocolors.default.dim("@")}${import_picocolors.default.cyan(parsed.skillFilter)}` : ""}`);
|
|
2299
|
+
if (parsed.skillFilter) {
|
|
2300
|
+
options.skill = options.skill || [];
|
|
2301
|
+
if (!options.skill.includes(parsed.skillFilter)) options.skill.push(parsed.skillFilter);
|
|
2302
|
+
}
|
|
2303
|
+
if (parsed.type === "well-known") {
|
|
2304
|
+
await handleWellKnownSkills(source, parsed.url, options, spinner);
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
let skillsDir;
|
|
2308
|
+
if (parsed.type === "local") {
|
|
2309
|
+
spinner.start("Validating local path...");
|
|
2310
|
+
if (!existsSync(parsed.localPath)) {
|
|
2311
|
+
spinner.stop(import_picocolors.default.red("Path not found"));
|
|
2312
|
+
Se(import_picocolors.default.red(`Local path does not exist: ${parsed.localPath}`));
|
|
2313
|
+
process.exit(1);
|
|
2314
|
+
}
|
|
2315
|
+
skillsDir = parsed.localPath;
|
|
2316
|
+
spinner.stop("Local path validated");
|
|
2317
|
+
} else {
|
|
2318
|
+
spinner.start("Cloning repository...");
|
|
2319
|
+
tempDir = await cloneRepo(parsed.url, parsed.ref);
|
|
2320
|
+
skillsDir = tempDir;
|
|
2321
|
+
spinner.stop("Repository cloned");
|
|
2322
|
+
}
|
|
2323
|
+
const includeInternal = !!(options.skill && options.skill.length > 0);
|
|
2324
|
+
spinner.start("Discovering skills...");
|
|
2325
|
+
const skills = await discoverSkills(skillsDir, parsed.subpath, {
|
|
2326
|
+
includeInternal,
|
|
2327
|
+
fullDepth: options.fullDepth
|
|
2328
|
+
});
|
|
2329
|
+
if (skills.length === 0) {
|
|
2330
|
+
spinner.stop(import_picocolors.default.red("No skills found"));
|
|
2331
|
+
Se(import_picocolors.default.red("No valid skills found. Skills require a SKILL.md with name and description."));
|
|
2332
|
+
await cleanup(tempDir);
|
|
2333
|
+
process.exit(1);
|
|
2334
|
+
}
|
|
2335
|
+
spinner.stop(`Found ${import_picocolors.default.green(skills.length)} skill${skills.length > 1 ? "s" : ""}`);
|
|
2336
|
+
if (options.list) {
|
|
2337
|
+
console.log();
|
|
2338
|
+
M.step(import_picocolors.default.bold("Available Skills"));
|
|
2339
|
+
const groupedSkills = {};
|
|
2340
|
+
const ungroupedSkills = [];
|
|
2341
|
+
for (const skill of skills) if (skill.pluginName) {
|
|
2342
|
+
const group = skill.pluginName;
|
|
2343
|
+
if (!groupedSkills[group]) groupedSkills[group] = [];
|
|
2344
|
+
groupedSkills[group].push(skill);
|
|
2345
|
+
} else ungroupedSkills.push(skill);
|
|
2346
|
+
const sortedGroups = Object.keys(groupedSkills).sort();
|
|
2347
|
+
for (const group of sortedGroups) {
|
|
2348
|
+
const title = group.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2349
|
+
console.log(import_picocolors.default.bold(title));
|
|
2350
|
+
for (const skill of groupedSkills[group]) {
|
|
2351
|
+
M.message(` ${import_picocolors.default.cyan(getSkillDisplayName(skill))}`);
|
|
2352
|
+
M.message(` ${import_picocolors.default.dim(skill.description)}`);
|
|
2353
|
+
}
|
|
2354
|
+
console.log();
|
|
2355
|
+
}
|
|
2356
|
+
if (ungroupedSkills.length > 0) {
|
|
2357
|
+
if (sortedGroups.length > 0) console.log(import_picocolors.default.bold("General"));
|
|
2358
|
+
for (const skill of ungroupedSkills) {
|
|
2359
|
+
M.message(` ${import_picocolors.default.cyan(getSkillDisplayName(skill))}`);
|
|
2360
|
+
M.message(` ${import_picocolors.default.dim(skill.description)}`);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
console.log();
|
|
2364
|
+
Se("Use --skill <name> to install specific skills");
|
|
2365
|
+
await cleanup(tempDir);
|
|
2366
|
+
process.exit(0);
|
|
2367
|
+
}
|
|
2368
|
+
let selectedSkills;
|
|
2369
|
+
if (options.skill?.includes("*")) {
|
|
2370
|
+
selectedSkills = skills;
|
|
2371
|
+
M.info(`Installing all ${skills.length} skills`);
|
|
2372
|
+
} else if (options.skill && options.skill.length > 0) {
|
|
2373
|
+
selectedSkills = filterSkills(skills, options.skill);
|
|
2374
|
+
if (selectedSkills.length === 0) {
|
|
2375
|
+
M.error(`No matching skills found for: ${options.skill.join(", ")}`);
|
|
2376
|
+
M.info("Available skills:");
|
|
2377
|
+
for (const s of skills) M.message(` - ${getSkillDisplayName(s)}`);
|
|
2378
|
+
await cleanup(tempDir);
|
|
2379
|
+
process.exit(1);
|
|
2380
|
+
}
|
|
2381
|
+
M.info(`Selected ${selectedSkills.length} skill${selectedSkills.length !== 1 ? "s" : ""}: ${selectedSkills.map((s) => import_picocolors.default.cyan(getSkillDisplayName(s))).join(", ")}`);
|
|
2382
|
+
} else if (skills.length === 1) {
|
|
2383
|
+
selectedSkills = skills;
|
|
2384
|
+
const firstSkill = skills[0];
|
|
2385
|
+
M.info(`Skill: ${import_picocolors.default.cyan(getSkillDisplayName(firstSkill))}`);
|
|
2386
|
+
M.message(import_picocolors.default.dim(firstSkill.description));
|
|
2387
|
+
} else if (options.yes) {
|
|
2388
|
+
selectedSkills = skills;
|
|
2389
|
+
M.info(`Installing all ${skills.length} skills`);
|
|
2390
|
+
} else {
|
|
2391
|
+
const sortedSkills = [...skills].sort((a, b) => {
|
|
2392
|
+
if (a.pluginName && !b.pluginName) return -1;
|
|
2393
|
+
if (!a.pluginName && b.pluginName) return 1;
|
|
2394
|
+
if (a.pluginName && b.pluginName && a.pluginName !== b.pluginName) return a.pluginName.localeCompare(b.pluginName);
|
|
2395
|
+
return getSkillDisplayName(a).localeCompare(getSkillDisplayName(b));
|
|
2396
|
+
});
|
|
2397
|
+
const hasGroups = sortedSkills.some((s) => s.pluginName);
|
|
2398
|
+
let selected;
|
|
2399
|
+
if (hasGroups) {
|
|
2400
|
+
const kebabToTitle = (s) => s.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2401
|
+
const grouped = {};
|
|
2402
|
+
for (const s of sortedSkills) {
|
|
2403
|
+
const groupName = s.pluginName ? kebabToTitle(s.pluginName) : "Other";
|
|
2404
|
+
if (!grouped[groupName]) grouped[groupName] = [];
|
|
2405
|
+
grouped[groupName].push({
|
|
2406
|
+
value: s,
|
|
2407
|
+
label: getSkillDisplayName(s),
|
|
2408
|
+
hint: s.description.length > 60 ? s.description.slice(0, 57) + "..." : s.description
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
selected = await be({
|
|
2412
|
+
message: `Select skills to install ${import_picocolors.default.dim("(space to toggle)")}`,
|
|
2413
|
+
options: grouped,
|
|
2414
|
+
required: true
|
|
2415
|
+
});
|
|
2416
|
+
} else selected = await multiselect({
|
|
2417
|
+
message: "Select skills to install",
|
|
2418
|
+
options: sortedSkills.map((s) => ({
|
|
2419
|
+
value: s,
|
|
2420
|
+
label: getSkillDisplayName(s),
|
|
2421
|
+
hint: s.description.length > 60 ? s.description.slice(0, 57) + "..." : s.description
|
|
2422
|
+
})),
|
|
2423
|
+
required: true
|
|
2424
|
+
});
|
|
2425
|
+
if (pD(selected)) {
|
|
2426
|
+
xe("Installation cancelled");
|
|
2427
|
+
await cleanup(tempDir);
|
|
2428
|
+
process.exit(0);
|
|
2429
|
+
}
|
|
2430
|
+
selectedSkills = selected;
|
|
2431
|
+
}
|
|
2432
|
+
const ownerRepoForAudit = getOwnerRepo(parsed);
|
|
2433
|
+
const auditPromise = ownerRepoForAudit ? fetchAuditData(ownerRepoForAudit, selectedSkills.map((s) => getSkillDisplayName(s))) : Promise.resolve(null);
|
|
2434
|
+
let targetAgents;
|
|
2435
|
+
const validAgents = Object.keys(agents);
|
|
2436
|
+
if (options.agent?.includes("*")) {
|
|
2437
|
+
targetAgents = validAgents;
|
|
2438
|
+
M.info(`Installing to all ${targetAgents.length} agents`);
|
|
2439
|
+
} else if (options.agent && options.agent.length > 0) {
|
|
2440
|
+
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
2441
|
+
if (invalidAgents.length > 0) {
|
|
2442
|
+
M.error(`Invalid agents: ${invalidAgents.join(", ")}`);
|
|
2443
|
+
M.info(`Valid agents: ${validAgents.join(", ")}`);
|
|
2444
|
+
await cleanup(tempDir);
|
|
2445
|
+
process.exit(1);
|
|
2446
|
+
}
|
|
2447
|
+
targetAgents = options.agent;
|
|
2448
|
+
} else {
|
|
2449
|
+
spinner.start("Loading agents...");
|
|
2450
|
+
const installedAgents = await detectInstalledAgents();
|
|
2451
|
+
const totalAgents = Object.keys(agents).length;
|
|
2452
|
+
spinner.stop(`${totalAgents} agents`);
|
|
2453
|
+
if (installedAgents.length === 0) if (options.yes) {
|
|
2454
|
+
targetAgents = validAgents;
|
|
2455
|
+
M.info("Installing to all agents");
|
|
2456
|
+
} else {
|
|
2457
|
+
M.info("Select agents to install skills to");
|
|
2458
|
+
const selected = await promptForAgents("Which agents do you want to install to?", Object.entries(agents).map(([key, config]) => ({
|
|
2459
|
+
value: key,
|
|
2460
|
+
label: config.displayName
|
|
2461
|
+
})));
|
|
2462
|
+
if (pD(selected)) {
|
|
2463
|
+
xe("Installation cancelled");
|
|
2464
|
+
await cleanup(tempDir);
|
|
2465
|
+
process.exit(0);
|
|
2466
|
+
}
|
|
2467
|
+
targetAgents = selected;
|
|
2468
|
+
}
|
|
2469
|
+
else if (installedAgents.length === 1 || options.yes) {
|
|
2470
|
+
targetAgents = ensureUniversalAgents(installedAgents);
|
|
2471
|
+
if (installedAgents.length === 1) {
|
|
2472
|
+
const firstAgent = installedAgents[0];
|
|
2473
|
+
M.info(`Installing to: ${import_picocolors.default.cyan(agents[firstAgent].displayName)}`);
|
|
2474
|
+
} else M.info(`Installing to: ${installedAgents.map((a) => import_picocolors.default.cyan(agents[a].displayName)).join(", ")}`);
|
|
2475
|
+
} else {
|
|
2476
|
+
const selected = await selectAgentsInteractive({ global: options.global });
|
|
2477
|
+
if (pD(selected)) {
|
|
2478
|
+
xe("Installation cancelled");
|
|
2479
|
+
await cleanup(tempDir);
|
|
2480
|
+
process.exit(0);
|
|
2481
|
+
}
|
|
2482
|
+
targetAgents = selected;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
let installGlobally = options.global ?? false;
|
|
2486
|
+
const supportsGlobal = targetAgents.some((a) => agents[a].globalSkillsDir !== void 0);
|
|
2487
|
+
if (options.global === void 0 && !options.yes && supportsGlobal) {
|
|
2488
|
+
const scope = await ve({
|
|
2489
|
+
message: "Installation scope",
|
|
2490
|
+
options: [{
|
|
2491
|
+
value: false,
|
|
2492
|
+
label: "Project",
|
|
2493
|
+
hint: "Install in current directory (committed with your project)"
|
|
2494
|
+
}, {
|
|
2495
|
+
value: true,
|
|
2496
|
+
label: "Global",
|
|
2497
|
+
hint: "Install in home directory (available across all projects)"
|
|
2498
|
+
}]
|
|
2499
|
+
});
|
|
2500
|
+
if (pD(scope)) {
|
|
2501
|
+
xe("Installation cancelled");
|
|
2502
|
+
await cleanup(tempDir);
|
|
2503
|
+
process.exit(0);
|
|
2504
|
+
}
|
|
2505
|
+
installGlobally = scope;
|
|
2506
|
+
}
|
|
2507
|
+
let installMode = options.copy ? "copy" : "symlink";
|
|
2508
|
+
if (!options.copy && !options.yes) {
|
|
2509
|
+
const modeChoice = await ve({
|
|
2510
|
+
message: "Installation method",
|
|
2511
|
+
options: [{
|
|
2512
|
+
value: "symlink",
|
|
2513
|
+
label: "Symlink (Recommended)",
|
|
2514
|
+
hint: "Single source of truth, easy updates"
|
|
2515
|
+
}, {
|
|
2516
|
+
value: "copy",
|
|
2517
|
+
label: "Copy to all agents",
|
|
2518
|
+
hint: "Independent copies for each agent"
|
|
2519
|
+
}]
|
|
2520
|
+
});
|
|
2521
|
+
if (pD(modeChoice)) {
|
|
2522
|
+
xe("Installation cancelled");
|
|
2523
|
+
await cleanup(tempDir);
|
|
2524
|
+
process.exit(0);
|
|
2525
|
+
}
|
|
2526
|
+
installMode = modeChoice;
|
|
2527
|
+
}
|
|
2528
|
+
const cwd = process.cwd();
|
|
2529
|
+
const summaryLines = [];
|
|
2530
|
+
targetAgents.map((a) => agents[a].displayName);
|
|
2531
|
+
const overwriteChecks = await Promise.all(selectedSkills.flatMap((skill) => targetAgents.map(async (agent) => ({
|
|
2532
|
+
skillName: skill.name,
|
|
2533
|
+
agent,
|
|
2534
|
+
installed: await isSkillInstalled(skill.name, agent, { global: installGlobally })
|
|
2535
|
+
}))));
|
|
2536
|
+
const overwriteStatus = /* @__PURE__ */ new Map();
|
|
2537
|
+
for (const { skillName, agent, installed } of overwriteChecks) {
|
|
2538
|
+
if (!overwriteStatus.has(skillName)) overwriteStatus.set(skillName, /* @__PURE__ */ new Map());
|
|
2539
|
+
overwriteStatus.get(skillName).set(agent, installed);
|
|
2540
|
+
}
|
|
2541
|
+
const groupedSummary = {};
|
|
2542
|
+
const ungroupedSummary = [];
|
|
2543
|
+
for (const skill of selectedSkills) if (skill.pluginName) {
|
|
2544
|
+
const group = skill.pluginName;
|
|
2545
|
+
if (!groupedSummary[group]) groupedSummary[group] = [];
|
|
2546
|
+
groupedSummary[group].push(skill);
|
|
2547
|
+
} else ungroupedSummary.push(skill);
|
|
2548
|
+
const printSkillSummary = (skills) => {
|
|
2549
|
+
for (const skill of skills) {
|
|
2550
|
+
if (summaryLines.length > 0) summaryLines.push("");
|
|
2551
|
+
const shortCanonical = shortenPath$2(getCanonicalPath(skill.name, { global: installGlobally }), cwd);
|
|
2552
|
+
summaryLines.push(`${import_picocolors.default.cyan(shortCanonical)}`);
|
|
2553
|
+
summaryLines.push(...buildAgentSummaryLines(targetAgents, installMode));
|
|
2554
|
+
const skillOverwrites = overwriteStatus.get(skill.name);
|
|
2555
|
+
const overwriteAgents = targetAgents.filter((a) => skillOverwrites?.get(a)).map((a) => agents[a].displayName);
|
|
2556
|
+
if (overwriteAgents.length > 0) summaryLines.push(` ${import_picocolors.default.yellow("overwrites:")} ${formatList$1(overwriteAgents)}`);
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
const sortedGroups = Object.keys(groupedSummary).sort();
|
|
2560
|
+
for (const group of sortedGroups) {
|
|
2561
|
+
const title = group.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2562
|
+
summaryLines.push("");
|
|
2563
|
+
summaryLines.push(import_picocolors.default.bold(title));
|
|
2564
|
+
printSkillSummary(groupedSummary[group]);
|
|
2565
|
+
}
|
|
2566
|
+
if (ungroupedSummary.length > 0) {
|
|
2567
|
+
if (sortedGroups.length > 0) {
|
|
2568
|
+
summaryLines.push("");
|
|
2569
|
+
summaryLines.push(import_picocolors.default.bold("General"));
|
|
2570
|
+
}
|
|
2571
|
+
printSkillSummary(ungroupedSummary);
|
|
2572
|
+
}
|
|
2573
|
+
console.log();
|
|
2574
|
+
Me(summaryLines.join("\n"), "Installation Summary");
|
|
2575
|
+
try {
|
|
2576
|
+
const auditData = await auditPromise;
|
|
2577
|
+
if (auditData && ownerRepoForAudit) {
|
|
2578
|
+
const securityLines = buildSecurityLines(auditData, selectedSkills.map((s) => ({
|
|
2579
|
+
slug: getSkillDisplayName(s),
|
|
2580
|
+
displayName: getSkillDisplayName(s)
|
|
2581
|
+
})), ownerRepoForAudit);
|
|
2582
|
+
if (securityLines.length > 0) Me(securityLines.join("\n"), "Security Risk Assessments");
|
|
2583
|
+
}
|
|
2584
|
+
} catch {}
|
|
2585
|
+
if (!options.yes) {
|
|
2586
|
+
const confirmed = await ye({ message: "Proceed with installation?" });
|
|
2587
|
+
if (pD(confirmed) || !confirmed) {
|
|
2588
|
+
xe("Installation cancelled");
|
|
2589
|
+
await cleanup(tempDir);
|
|
2590
|
+
process.exit(0);
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
spinner.start("Installing skills...");
|
|
2594
|
+
const results = [];
|
|
2595
|
+
for (const skill of selectedSkills) for (const agent of targetAgents) {
|
|
2596
|
+
const result = await installSkillForAgent(skill, agent, {
|
|
2597
|
+
global: installGlobally,
|
|
2598
|
+
mode: installMode
|
|
2599
|
+
});
|
|
2600
|
+
results.push({
|
|
2601
|
+
skill: getSkillDisplayName(skill),
|
|
2602
|
+
agent: agents[agent].displayName,
|
|
2603
|
+
pluginName: skill.pluginName,
|
|
2604
|
+
...result
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
spinner.stop("Installation complete");
|
|
2608
|
+
console.log();
|
|
2609
|
+
const successful = results.filter((r) => r.success);
|
|
2610
|
+
const failed = results.filter((r) => !r.success);
|
|
2611
|
+
const skillFiles = {};
|
|
2612
|
+
for (const skill of selectedSkills) {
|
|
2613
|
+
let relativePath;
|
|
2614
|
+
if (tempDir && skill.path === tempDir) relativePath = "SKILL.md";
|
|
2615
|
+
else if (tempDir && skill.path.startsWith(tempDir + sep)) relativePath = skill.path.slice(tempDir.length + 1).split(sep).join("/") + "/SKILL.md";
|
|
2616
|
+
else continue;
|
|
2617
|
+
skillFiles[skill.name] = relativePath;
|
|
2618
|
+
}
|
|
2619
|
+
const normalizedSource = getOwnerRepo(parsed);
|
|
2620
|
+
if (normalizedSource) {
|
|
2621
|
+
const ownerRepo = parseOwnerRepo(normalizedSource);
|
|
2622
|
+
if (ownerRepo) {
|
|
2623
|
+
if (await isRepoPrivate(ownerRepo.owner, ownerRepo.repo) === false) track({
|
|
2624
|
+
event: "install",
|
|
2625
|
+
source: normalizedSource,
|
|
2626
|
+
skills: selectedSkills.map((s) => s.name).join(","),
|
|
2627
|
+
agents: targetAgents.join(","),
|
|
2628
|
+
...installGlobally && { global: "1" },
|
|
2629
|
+
skillFiles: JSON.stringify(skillFiles)
|
|
2630
|
+
});
|
|
2631
|
+
} else track({
|
|
2632
|
+
event: "install",
|
|
2633
|
+
source: normalizedSource,
|
|
2634
|
+
skills: selectedSkills.map((s) => s.name).join(","),
|
|
2635
|
+
agents: targetAgents.join(","),
|
|
2636
|
+
...installGlobally && { global: "1" },
|
|
2637
|
+
skillFiles: JSON.stringify(skillFiles)
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
if (successful.length > 0 && installGlobally && normalizedSource) {
|
|
2641
|
+
const successfulSkillNames = new Set(successful.map((r) => r.skill));
|
|
2642
|
+
for (const skill of selectedSkills) {
|
|
2643
|
+
const skillDisplayName = getSkillDisplayName(skill);
|
|
2644
|
+
if (successfulSkillNames.has(skillDisplayName)) try {
|
|
2645
|
+
let skillFolderHash = "";
|
|
2646
|
+
const skillPathValue = skillFiles[skill.name];
|
|
2647
|
+
if (parsed.type === "github" && skillPathValue) {
|
|
2648
|
+
const hash = await fetchSkillFolderHash(normalizedSource, skillPathValue);
|
|
2649
|
+
if (hash) skillFolderHash = hash;
|
|
2650
|
+
}
|
|
2651
|
+
await addSkillToLock(skill.name, {
|
|
2652
|
+
source: normalizedSource,
|
|
2653
|
+
sourceType: parsed.type,
|
|
2654
|
+
sourceUrl: parsed.url,
|
|
2655
|
+
skillPath: skillPathValue,
|
|
2656
|
+
skillFolderHash,
|
|
2657
|
+
pluginName: skill.pluginName
|
|
2658
|
+
});
|
|
2659
|
+
} catch {}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
if (successful.length > 0 && !installGlobally) {
|
|
2663
|
+
const successfulSkillNames = new Set(successful.map((r) => r.skill));
|
|
2664
|
+
for (const skill of selectedSkills) {
|
|
2665
|
+
const skillDisplayName = getSkillDisplayName(skill);
|
|
2666
|
+
if (successfulSkillNames.has(skillDisplayName)) try {
|
|
2667
|
+
const computedHash = await computeSkillFolderHash(skill.path);
|
|
2668
|
+
await addSkillToLocalLock(skill.name, {
|
|
2669
|
+
source: normalizedSource || parsed.url,
|
|
2670
|
+
sourceType: parsed.type,
|
|
2671
|
+
computedHash
|
|
2672
|
+
}, cwd);
|
|
2673
|
+
} catch {}
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
if (successful.length > 0) {
|
|
2677
|
+
const bySkill = /* @__PURE__ */ new Map();
|
|
2678
|
+
const groupedResults = {};
|
|
2679
|
+
const ungroupedResults = [];
|
|
2680
|
+
for (const r of successful) {
|
|
2681
|
+
const skillResults = bySkill.get(r.skill) || [];
|
|
2682
|
+
skillResults.push(r);
|
|
2683
|
+
bySkill.set(r.skill, skillResults);
|
|
2684
|
+
if (skillResults.length === 1) if (r.pluginName) {
|
|
2685
|
+
const group = r.pluginName;
|
|
2686
|
+
if (!groupedResults[group]) groupedResults[group] = [];
|
|
2687
|
+
groupedResults[group].push(r);
|
|
2688
|
+
} else ungroupedResults.push(r);
|
|
2689
|
+
}
|
|
2690
|
+
const skillCount = bySkill.size;
|
|
2691
|
+
const symlinkFailures = successful.filter((r) => r.mode === "symlink" && r.symlinkFailed);
|
|
2692
|
+
const copiedAgents = symlinkFailures.map((r) => r.agent);
|
|
2693
|
+
const resultLines = [];
|
|
2694
|
+
const printSkillResults = (entries) => {
|
|
2695
|
+
for (const entry of entries) {
|
|
2696
|
+
const skillResults = bySkill.get(entry.skill) || [];
|
|
2697
|
+
const firstResult = skillResults[0];
|
|
2698
|
+
if (firstResult.mode === "copy") {
|
|
2699
|
+
resultLines.push(`${import_picocolors.default.green("✓")} ${entry.skill} ${import_picocolors.default.dim("(copied)")}`);
|
|
2700
|
+
for (const r of skillResults) {
|
|
2701
|
+
const shortPath = shortenPath$2(r.path, cwd);
|
|
2702
|
+
resultLines.push(` ${import_picocolors.default.dim("→")} ${shortPath}`);
|
|
2703
|
+
}
|
|
2704
|
+
} else {
|
|
2705
|
+
if (firstResult.canonicalPath) {
|
|
2706
|
+
const shortPath = shortenPath$2(firstResult.canonicalPath, cwd);
|
|
2707
|
+
resultLines.push(`${import_picocolors.default.green("✓")} ${shortPath}`);
|
|
2708
|
+
} else resultLines.push(`${import_picocolors.default.green("✓")} ${entry.skill}`);
|
|
2709
|
+
resultLines.push(...buildResultLines(skillResults, targetAgents));
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
};
|
|
2713
|
+
const sortedResultGroups = Object.keys(groupedResults).sort();
|
|
2714
|
+
for (const group of sortedResultGroups) {
|
|
2715
|
+
const title = group.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2716
|
+
resultLines.push("");
|
|
2717
|
+
resultLines.push(import_picocolors.default.bold(title));
|
|
2718
|
+
printSkillResults(groupedResults[group]);
|
|
2719
|
+
}
|
|
2720
|
+
if (ungroupedResults.length > 0) {
|
|
2721
|
+
if (sortedResultGroups.length > 0) {
|
|
2722
|
+
resultLines.push("");
|
|
2723
|
+
resultLines.push(import_picocolors.default.bold("General"));
|
|
2724
|
+
}
|
|
2725
|
+
printSkillResults(ungroupedResults);
|
|
2726
|
+
}
|
|
2727
|
+
const title = import_picocolors.default.green(`Installed ${skillCount} skill${skillCount !== 1 ? "s" : ""}`);
|
|
2728
|
+
Me(resultLines.join("\n"), title);
|
|
2729
|
+
if (symlinkFailures.length > 0) {
|
|
2730
|
+
M.warn(import_picocolors.default.yellow(`Symlinks failed for: ${formatList$1(copiedAgents)}`));
|
|
2731
|
+
M.message(import_picocolors.default.dim(" Files were copied instead. On Windows, enable Developer Mode for symlink support."));
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
if (failed.length > 0) {
|
|
2735
|
+
console.log();
|
|
2736
|
+
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
2737
|
+
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill} → ${r.agent}: ${import_picocolors.default.dim(r.error)}`);
|
|
2738
|
+
}
|
|
2739
|
+
console.log();
|
|
2740
|
+
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
2741
|
+
await promptForFindSkills(options, targetAgents);
|
|
2742
|
+
} catch (error) {
|
|
2743
|
+
if (error instanceof GitCloneError) {
|
|
2744
|
+
M.error(import_picocolors.default.red("Failed to clone repository"));
|
|
2745
|
+
for (const line of error.message.split("\n")) M.message(import_picocolors.default.dim(line));
|
|
2746
|
+
} else M.error(error instanceof Error ? error.message : "Unknown error occurred");
|
|
2747
|
+
showInstallTip();
|
|
2748
|
+
Se(import_picocolors.default.red("Installation failed"));
|
|
2749
|
+
process.exit(1);
|
|
2750
|
+
} finally {
|
|
2751
|
+
await cleanup(tempDir);
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
async function cleanup(tempDir) {
|
|
2755
|
+
if (tempDir) try {
|
|
2756
|
+
await cleanupTempDir(tempDir);
|
|
2757
|
+
} catch {}
|
|
2758
|
+
}
|
|
2759
|
+
async function promptForFindSkills(options, targetAgents) {
|
|
2760
|
+
if (!process.stdin.isTTY) return;
|
|
2761
|
+
if (options?.yes) return;
|
|
2762
|
+
try {
|
|
2763
|
+
if (await isPromptDismissed("findSkillsPrompt")) return;
|
|
2764
|
+
if (await isSkillInstalled("find-skills", "claude-code", { global: true })) {
|
|
2765
|
+
await dismissPrompt("findSkillsPrompt");
|
|
2766
|
+
return;
|
|
2767
|
+
}
|
|
2768
|
+
console.log();
|
|
2769
|
+
M.message(import_picocolors.default.dim("One-time prompt - you won't be asked again if you dismiss."));
|
|
2770
|
+
const install = await ye({ message: `Install the ${import_picocolors.default.cyan("find-skills")} skill? It helps your agent discover and suggest skills.` });
|
|
2771
|
+
if (pD(install)) {
|
|
2772
|
+
await dismissPrompt("findSkillsPrompt");
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
if (install) {
|
|
2776
|
+
await dismissPrompt("findSkillsPrompt");
|
|
2777
|
+
const findSkillsAgents = targetAgents?.filter((a) => a !== "replit");
|
|
2778
|
+
if (!findSkillsAgents || findSkillsAgents.length === 0) return;
|
|
2779
|
+
console.log();
|
|
2780
|
+
M.step("Installing find-skills skill...");
|
|
2781
|
+
try {
|
|
2782
|
+
await runAdd([DEFAULT_WELL_KNOWN_BASE_URL], {
|
|
2783
|
+
skill: ["find-skills"],
|
|
2784
|
+
global: true,
|
|
2785
|
+
yes: true,
|
|
2786
|
+
agent: findSkillsAgents
|
|
2787
|
+
});
|
|
2788
|
+
} catch {
|
|
2789
|
+
M.warn("Failed to install find-skills. You can try again with:");
|
|
2790
|
+
M.message(import_picocolors.default.dim(` ${CLI_NPX_COMMAND} add ${DEFAULT_WELL_KNOWN_BASE_URL} --skill find-skills -g -y --all`));
|
|
2791
|
+
}
|
|
2792
|
+
} else {
|
|
2793
|
+
await dismissPrompt("findSkillsPrompt");
|
|
2794
|
+
M.message(import_picocolors.default.dim(`You can install it later with: ${CLI_NPX_COMMAND} add ${DEFAULT_WELL_KNOWN_BASE_URL} --skill find-skills`));
|
|
2795
|
+
}
|
|
2796
|
+
} catch {}
|
|
2797
|
+
}
|
|
2798
|
+
function parseAddOptions(args) {
|
|
2799
|
+
const options = {};
|
|
2800
|
+
const source = [];
|
|
2801
|
+
for (let i = 0; i < args.length; i++) {
|
|
2802
|
+
const arg = args[i];
|
|
2803
|
+
if (arg === "-g" || arg === "--global") options.global = true;
|
|
2804
|
+
else if (arg === "-y" || arg === "--yes") options.yes = true;
|
|
2805
|
+
else if (arg === "-l" || arg === "--list") options.list = true;
|
|
2806
|
+
else if (arg === "--all") options.all = true;
|
|
2807
|
+
else if (arg === "-a" || arg === "--agent") {
|
|
2808
|
+
options.agent = options.agent || [];
|
|
2809
|
+
i++;
|
|
2810
|
+
let nextArg = args[i];
|
|
2811
|
+
while (i < args.length && nextArg && !nextArg.startsWith("-")) {
|
|
2812
|
+
options.agent.push(nextArg);
|
|
2813
|
+
i++;
|
|
2814
|
+
nextArg = args[i];
|
|
2815
|
+
}
|
|
2816
|
+
i--;
|
|
2817
|
+
} else if (arg === "-s" || arg === "--skill") {
|
|
2818
|
+
options.skill = options.skill || [];
|
|
2819
|
+
i++;
|
|
2820
|
+
let nextArg = args[i];
|
|
2821
|
+
while (i < args.length && nextArg && !nextArg.startsWith("-")) {
|
|
2822
|
+
options.skill.push(nextArg);
|
|
2823
|
+
i++;
|
|
2824
|
+
nextArg = args[i];
|
|
2825
|
+
}
|
|
2826
|
+
i--;
|
|
2827
|
+
} else if (arg === "--full-depth") options.fullDepth = true;
|
|
2828
|
+
else if (arg === "--copy") options.copy = true;
|
|
2829
|
+
else if (arg && !arg.startsWith("-")) source.push(arg);
|
|
2830
|
+
}
|
|
2831
|
+
return {
|
|
2832
|
+
source,
|
|
2833
|
+
options
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
const RESET$2 = "\x1B[0m";
|
|
2837
|
+
const BOLD$2 = "\x1B[1m";
|
|
2838
|
+
const DIM$2 = "\x1B[38;5;102m";
|
|
2839
|
+
const TEXT$1 = "\x1B[38;5;145m";
|
|
2840
|
+
const CYAN$1 = "\x1B[36m";
|
|
2841
|
+
const SEARCH_API_BASE = process.env.SKILLS_API_URL || DEFAULT_SEARCH_API_BASE;
|
|
2842
|
+
function formatInstalls(count) {
|
|
2843
|
+
if (!count || count <= 0) return "";
|
|
2844
|
+
if (count >= 1e6) return `${(count / 1e6).toFixed(1).replace(/\.0$/, "")}M installs`;
|
|
2845
|
+
if (count >= 1e3) return `${(count / 1e3).toFixed(1).replace(/\.0$/, "")}K installs`;
|
|
2846
|
+
return `${count} install${count === 1 ? "" : "s"}`;
|
|
2847
|
+
}
|
|
2848
|
+
async function searchSkillsAPI(query) {
|
|
2849
|
+
try {
|
|
2850
|
+
const url = `${SEARCH_API_BASE}/api/search?q=${encodeURIComponent(query)}&limit=10`;
|
|
2851
|
+
debugLog(`[find] requesting search: ${url}`);
|
|
2852
|
+
const res = await fetch(url);
|
|
2853
|
+
debugLog(`[find] search response status: ${res.status} ${res.statusText}`);
|
|
2854
|
+
const responseText = await res.text();
|
|
2855
|
+
debugLog(`[find] search response body: ${responseText}`);
|
|
2856
|
+
if (!res.ok) return [];
|
|
2857
|
+
return JSON.parse(responseText).skills.map((skill) => ({
|
|
2858
|
+
name: skill.name,
|
|
2859
|
+
slug: skill.id,
|
|
2860
|
+
source: skill.source || "",
|
|
2861
|
+
installs: skill.installs
|
|
2862
|
+
}));
|
|
2863
|
+
} catch {
|
|
2864
|
+
return [];
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
const HIDE_CURSOR = "\x1B[?25l";
|
|
2868
|
+
const SHOW_CURSOR = "\x1B[?25h";
|
|
2869
|
+
const CLEAR_DOWN = "\x1B[J";
|
|
2870
|
+
const MOVE_UP = (n) => `\x1b[${n}A`;
|
|
2871
|
+
const MOVE_TO_COL = (n) => `\x1b[${n}G`;
|
|
2872
|
+
async function runSearchPrompt(initialQuery = "") {
|
|
2873
|
+
let results = [];
|
|
2874
|
+
let selectedIndex = 0;
|
|
2875
|
+
let query = initialQuery;
|
|
2876
|
+
let loading = false;
|
|
2877
|
+
let debounceTimer = null;
|
|
2878
|
+
let lastRenderedLines = 0;
|
|
2879
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
2880
|
+
readline.emitKeypressEvents(process.stdin);
|
|
2881
|
+
process.stdin.resume();
|
|
2882
|
+
process.stdout.write(HIDE_CURSOR);
|
|
2883
|
+
function render() {
|
|
2884
|
+
if (lastRenderedLines > 0) process.stdout.write(MOVE_UP(lastRenderedLines) + MOVE_TO_COL(1));
|
|
2885
|
+
process.stdout.write(CLEAR_DOWN);
|
|
2886
|
+
const lines = [];
|
|
2887
|
+
const cursor = `${BOLD$2}_${RESET$2}`;
|
|
2888
|
+
lines.push(`${TEXT$1}Search skills:${RESET$2} ${query}${cursor}`);
|
|
2889
|
+
lines.push("");
|
|
2890
|
+
if (!query || query.length < 2) lines.push(`${DIM$2}Start typing to search (min 2 chars)${RESET$2}`);
|
|
2891
|
+
else if (results.length === 0 && loading) lines.push(`${DIM$2}Searching...${RESET$2}`);
|
|
2892
|
+
else if (results.length === 0) lines.push(`${DIM$2}No skills found${RESET$2}`);
|
|
2893
|
+
else {
|
|
2894
|
+
const visible = results.slice(0, 8);
|
|
2895
|
+
for (let i = 0; i < visible.length; i++) {
|
|
2896
|
+
const skill = visible[i];
|
|
2897
|
+
const isSelected = i === selectedIndex;
|
|
2898
|
+
const arrow = isSelected ? `${BOLD$2}>${RESET$2}` : " ";
|
|
2899
|
+
const name = isSelected ? `${BOLD$2}${skill.name}${RESET$2}` : `${TEXT$1}${skill.name}${RESET$2}`;
|
|
2900
|
+
const source = skill.source ? ` ${DIM$2}${skill.source}${RESET$2}` : "";
|
|
2901
|
+
const installs = formatInstalls(skill.installs);
|
|
2902
|
+
const installsBadge = installs ? ` ${CYAN$1}${installs}${RESET$2}` : "";
|
|
2903
|
+
const loadingIndicator = loading && i === 0 ? ` ${DIM$2}...${RESET$2}` : "";
|
|
2904
|
+
lines.push(` ${arrow} ${name}${source}${installsBadge}${loadingIndicator}`);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
lines.push("");
|
|
2908
|
+
lines.push(`${DIM$2}up/down navigate | enter select | esc cancel${RESET$2}`);
|
|
2909
|
+
for (const line of lines) process.stdout.write(line + "\n");
|
|
2910
|
+
lastRenderedLines = lines.length;
|
|
2911
|
+
}
|
|
2912
|
+
function triggerSearch(q) {
|
|
2913
|
+
if (debounceTimer) {
|
|
2914
|
+
clearTimeout(debounceTimer);
|
|
2915
|
+
debounceTimer = null;
|
|
2916
|
+
}
|
|
2917
|
+
loading = false;
|
|
2918
|
+
if (!q || q.length < 2) {
|
|
2919
|
+
results = [];
|
|
2920
|
+
selectedIndex = 0;
|
|
2921
|
+
render();
|
|
2922
|
+
return;
|
|
2923
|
+
}
|
|
2924
|
+
loading = true;
|
|
2925
|
+
render();
|
|
2926
|
+
const debounceMs = Math.max(150, 350 - q.length * 50);
|
|
2927
|
+
debounceTimer = setTimeout(async () => {
|
|
2928
|
+
try {
|
|
2929
|
+
results = await searchSkillsAPI(q);
|
|
2930
|
+
selectedIndex = 0;
|
|
2931
|
+
} catch {
|
|
2932
|
+
results = [];
|
|
2933
|
+
} finally {
|
|
2934
|
+
loading = false;
|
|
2935
|
+
debounceTimer = null;
|
|
2936
|
+
render();
|
|
2937
|
+
}
|
|
2938
|
+
}, debounceMs);
|
|
2939
|
+
}
|
|
2940
|
+
if (initialQuery) triggerSearch(initialQuery);
|
|
2941
|
+
render();
|
|
2942
|
+
return new Promise((resolve) => {
|
|
2943
|
+
function cleanup() {
|
|
2944
|
+
process.stdin.removeListener("keypress", handleKeypress);
|
|
2945
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
2946
|
+
process.stdout.write(SHOW_CURSOR);
|
|
2947
|
+
process.stdin.pause();
|
|
2948
|
+
}
|
|
2949
|
+
function handleKeypress(_ch, key) {
|
|
2950
|
+
if (!key) return;
|
|
2951
|
+
if (key.name === "escape" || key.ctrl && key.name === "c") {
|
|
2952
|
+
cleanup();
|
|
2953
|
+
resolve(null);
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
if (key.name === "return") {
|
|
2957
|
+
cleanup();
|
|
2958
|
+
resolve(results[selectedIndex] || null);
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
if (key.name === "up") {
|
|
2962
|
+
selectedIndex = Math.max(0, selectedIndex - 1);
|
|
2963
|
+
render();
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2966
|
+
if (key.name === "down") {
|
|
2967
|
+
selectedIndex = Math.min(Math.max(0, results.length - 1), selectedIndex + 1);
|
|
2968
|
+
render();
|
|
2969
|
+
return;
|
|
2970
|
+
}
|
|
2971
|
+
if (key.name === "backspace") {
|
|
2972
|
+
if (query.length > 0) {
|
|
2973
|
+
query = query.slice(0, -1);
|
|
2974
|
+
triggerSearch(query);
|
|
2975
|
+
}
|
|
2976
|
+
return;
|
|
2977
|
+
}
|
|
2978
|
+
if (key.sequence && !key.ctrl && !key.meta && key.sequence.length === 1) {
|
|
2979
|
+
const char = key.sequence;
|
|
2980
|
+
if (char >= " " && char <= "~") {
|
|
2981
|
+
query += char;
|
|
2982
|
+
triggerSearch(query);
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
process.stdin.on("keypress", handleKeypress);
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
async function runFind(args) {
|
|
2990
|
+
const query = args.join(" ");
|
|
2991
|
+
const isNonInteractive = !process.stdin.isTTY;
|
|
2992
|
+
const agentTip = `${DIM$2}Tip: if running in a coding agent, follow these steps:${RESET$2}
|
|
2993
|
+
${DIM$2} 1) ${CLI_NPX_COMMAND} find [query]${RESET$2}
|
|
2994
|
+
${DIM$2} 2) ${CLI_NPX_COMMAND} add <owner/repo@skill>${RESET$2}`;
|
|
2995
|
+
if (query) {
|
|
2996
|
+
const results = await searchSkillsAPI(query);
|
|
2997
|
+
track({
|
|
2998
|
+
event: "find",
|
|
2999
|
+
query,
|
|
3000
|
+
resultCount: String(results.length)
|
|
3001
|
+
});
|
|
3002
|
+
if (results.length === 0) {
|
|
3003
|
+
console.log(`${DIM$2}No skills found for "${query}"${RESET$2}`);
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
console.log(`${DIM$2}Install with${RESET$2} ${CLI_NPX_COMMAND} add <owner/repo@skill>`);
|
|
3007
|
+
console.log();
|
|
3008
|
+
for (const skill of results.slice(0, 6)) {
|
|
3009
|
+
const pkg = skill.source || skill.slug;
|
|
3010
|
+
const installs = formatInstalls(skill.installs);
|
|
3011
|
+
console.log(`${TEXT$1}${pkg}@${skill.name}${RESET$2}${installs ? ` ${CYAN$1}${installs}${RESET$2}` : ""}`);
|
|
3012
|
+
console.log(`${DIM$2}└ ${DEFAULT_DISCOVERY_SITE_URL}/${skill.slug}${RESET$2}`);
|
|
3013
|
+
console.log();
|
|
3014
|
+
}
|
|
3015
|
+
return;
|
|
3016
|
+
}
|
|
3017
|
+
if (isNonInteractive) {
|
|
3018
|
+
console.log(agentTip);
|
|
3019
|
+
console.log();
|
|
3020
|
+
}
|
|
3021
|
+
const selected = await runSearchPrompt();
|
|
3022
|
+
track({
|
|
3023
|
+
event: "find",
|
|
3024
|
+
query: "",
|
|
3025
|
+
resultCount: selected ? "1" : "0",
|
|
3026
|
+
interactive: "1"
|
|
3027
|
+
});
|
|
3028
|
+
if (!selected) {
|
|
3029
|
+
console.log(`${DIM$2}Search cancelled${RESET$2}`);
|
|
3030
|
+
console.log();
|
|
3031
|
+
return;
|
|
3032
|
+
}
|
|
3033
|
+
const pkg = selected.source || selected.slug;
|
|
3034
|
+
const skillName = selected.name;
|
|
3035
|
+
console.log();
|
|
3036
|
+
console.log(`${TEXT$1}Installing ${BOLD$2}${skillName}${RESET$2} from ${DIM$2}${pkg}${RESET$2}...`);
|
|
3037
|
+
console.log();
|
|
3038
|
+
const { source, options } = parseAddOptions([
|
|
3039
|
+
pkg,
|
|
3040
|
+
"--skill",
|
|
3041
|
+
skillName
|
|
3042
|
+
]);
|
|
3043
|
+
await runAdd(source, options);
|
|
3044
|
+
console.log();
|
|
3045
|
+
if (selected.slug) console.log(`${DIM$2}View the skill at${RESET$2} ${TEXT$1}${DEFAULT_DISCOVERY_SITE_URL}/${selected.slug}${RESET$2}`);
|
|
3046
|
+
else console.log(`${DIM$2}Discover more skills at${RESET$2} ${TEXT$1}${DEFAULT_DISCOVERY_SITE_URL}${RESET$2}`);
|
|
3047
|
+
console.log();
|
|
3048
|
+
}
|
|
3049
|
+
const isCancelled = (value) => typeof value === "symbol";
|
|
3050
|
+
function shortenPath$1(fullPath, cwd) {
|
|
3051
|
+
const home = homedir();
|
|
3052
|
+
if (fullPath === home || fullPath.startsWith(home + sep)) return "~" + fullPath.slice(home.length);
|
|
3053
|
+
if (fullPath === cwd || fullPath.startsWith(cwd + sep)) return "." + fullPath.slice(cwd.length);
|
|
3054
|
+
return fullPath;
|
|
3055
|
+
}
|
|
3056
|
+
async function discoverNodeModuleSkills(cwd) {
|
|
3057
|
+
const nodeModulesDir = join(cwd, "node_modules");
|
|
3058
|
+
const skills = [];
|
|
3059
|
+
let topNames;
|
|
3060
|
+
try {
|
|
3061
|
+
topNames = await readdir(nodeModulesDir);
|
|
3062
|
+
} catch {
|
|
3063
|
+
return skills;
|
|
3064
|
+
}
|
|
3065
|
+
const processPackageDir = async (pkgDir, packageName) => {
|
|
3066
|
+
const rootSkill = await parseSkillMd(join(pkgDir, "SKILL.md"));
|
|
3067
|
+
if (rootSkill) {
|
|
3068
|
+
skills.push({
|
|
3069
|
+
...rootSkill,
|
|
3070
|
+
packageName
|
|
3071
|
+
});
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
const searchDirs = [
|
|
3075
|
+
pkgDir,
|
|
3076
|
+
join(pkgDir, "skills"),
|
|
3077
|
+
join(pkgDir, ".agents", "skills")
|
|
3078
|
+
];
|
|
3079
|
+
for (const searchDir of searchDirs) try {
|
|
3080
|
+
const entries = await readdir(searchDir);
|
|
3081
|
+
for (const name of entries) {
|
|
3082
|
+
const skillDir = join(searchDir, name);
|
|
3083
|
+
try {
|
|
3084
|
+
if (!(await stat(skillDir)).isDirectory()) continue;
|
|
3085
|
+
} catch {
|
|
3086
|
+
continue;
|
|
3087
|
+
}
|
|
3088
|
+
const skill = await parseSkillMd(join(skillDir, "SKILL.md"));
|
|
3089
|
+
if (skill) skills.push({
|
|
3090
|
+
...skill,
|
|
3091
|
+
packageName
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
3094
|
+
} catch {}
|
|
3095
|
+
};
|
|
3096
|
+
await Promise.all(topNames.map(async (name) => {
|
|
3097
|
+
if (name.startsWith(".")) return;
|
|
3098
|
+
const fullPath = join(nodeModulesDir, name);
|
|
3099
|
+
try {
|
|
3100
|
+
if (!(await stat(fullPath)).isDirectory()) return;
|
|
3101
|
+
} catch {
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
if (name.startsWith("@")) try {
|
|
3105
|
+
const scopeNames = await readdir(fullPath);
|
|
3106
|
+
await Promise.all(scopeNames.map(async (scopedName) => {
|
|
3107
|
+
const scopedPath = join(fullPath, scopedName);
|
|
3108
|
+
try {
|
|
3109
|
+
if (!(await stat(scopedPath)).isDirectory()) return;
|
|
3110
|
+
} catch {
|
|
3111
|
+
return;
|
|
3112
|
+
}
|
|
3113
|
+
await processPackageDir(scopedPath, `${name}/${scopedName}`);
|
|
3114
|
+
}));
|
|
3115
|
+
} catch {}
|
|
3116
|
+
else await processPackageDir(fullPath, name);
|
|
3117
|
+
}));
|
|
3118
|
+
return skills;
|
|
3119
|
+
}
|
|
3120
|
+
async function runSync(args, options = {}) {
|
|
3121
|
+
const cwd = process.cwd();
|
|
3122
|
+
console.log();
|
|
3123
|
+
Ie(import_picocolors.default.bgCyan(import_picocolors.default.black(" bip-skills experimental_sync ")));
|
|
3124
|
+
const spinner = Y();
|
|
3125
|
+
spinner.start("Scanning node_modules for skills...");
|
|
3126
|
+
const discoveredSkills = await discoverNodeModuleSkills(cwd);
|
|
3127
|
+
if (discoveredSkills.length === 0) {
|
|
3128
|
+
spinner.stop(import_picocolors.default.yellow("No skills found"));
|
|
3129
|
+
Se(import_picocolors.default.dim("No SKILL.md files found in node_modules."));
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
spinner.stop(`Found ${import_picocolors.default.green(String(discoveredSkills.length))} skill${discoveredSkills.length > 1 ? "s" : ""} in node_modules`);
|
|
3133
|
+
for (const skill of discoveredSkills) {
|
|
3134
|
+
M.info(`${import_picocolors.default.cyan(skill.name)} ${import_picocolors.default.dim(`from ${skill.packageName}`)}`);
|
|
3135
|
+
if (skill.description) M.message(import_picocolors.default.dim(` ${skill.description}`));
|
|
3136
|
+
}
|
|
3137
|
+
const localLock = await readLocalLock(cwd);
|
|
3138
|
+
const toInstall = [];
|
|
3139
|
+
const upToDate = [];
|
|
3140
|
+
if (options.force) {
|
|
3141
|
+
toInstall.push(...discoveredSkills);
|
|
3142
|
+
M.info(import_picocolors.default.dim("Force mode: reinstalling all skills"));
|
|
3143
|
+
} else {
|
|
3144
|
+
for (const skill of discoveredSkills) {
|
|
3145
|
+
const existingEntry = localLock.skills[skill.name];
|
|
3146
|
+
if (existingEntry) {
|
|
3147
|
+
if (await computeSkillFolderHash(skill.path) === existingEntry.computedHash) {
|
|
3148
|
+
upToDate.push(skill.name);
|
|
3149
|
+
continue;
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
toInstall.push(skill);
|
|
3153
|
+
}
|
|
3154
|
+
if (upToDate.length > 0) M.info(import_picocolors.default.dim(`${upToDate.length} skill${upToDate.length !== 1 ? "s" : ""} already up to date`));
|
|
3155
|
+
if (toInstall.length === 0) {
|
|
3156
|
+
console.log();
|
|
3157
|
+
Se(import_picocolors.default.green("All skills are up to date."));
|
|
3158
|
+
return;
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
M.info(`${toInstall.length} skill${toInstall.length !== 1 ? "s" : ""} to install/update`);
|
|
3162
|
+
let targetAgents;
|
|
3163
|
+
const validAgents = Object.keys(agents);
|
|
3164
|
+
const universalAgents = getUniversalAgents();
|
|
3165
|
+
if (options.agent?.includes("*")) {
|
|
3166
|
+
targetAgents = validAgents;
|
|
3167
|
+
M.info(`Installing to all ${targetAgents.length} agents`);
|
|
3168
|
+
} else if (options.agent && options.agent.length > 0) {
|
|
3169
|
+
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
3170
|
+
if (invalidAgents.length > 0) {
|
|
3171
|
+
M.error(`Invalid agents: ${invalidAgents.join(", ")}`);
|
|
3172
|
+
M.info(`Valid agents: ${validAgents.join(", ")}`);
|
|
3173
|
+
process.exit(1);
|
|
3174
|
+
}
|
|
3175
|
+
targetAgents = options.agent;
|
|
3176
|
+
} else {
|
|
3177
|
+
spinner.start("Loading agents...");
|
|
3178
|
+
const installedAgents = await detectInstalledAgents();
|
|
3179
|
+
const totalAgents = Object.keys(agents).length;
|
|
3180
|
+
spinner.stop(`${totalAgents} agents`);
|
|
3181
|
+
if (installedAgents.length === 0) if (options.yes) {
|
|
3182
|
+
targetAgents = universalAgents;
|
|
3183
|
+
M.info("Installing to universal agents");
|
|
3184
|
+
} else {
|
|
3185
|
+
const selected = await searchMultiselect({
|
|
3186
|
+
message: "Which agents do you want to install to?",
|
|
3187
|
+
items: getNonUniversalAgents().map((a) => ({
|
|
3188
|
+
value: a,
|
|
3189
|
+
label: agents[a].displayName,
|
|
3190
|
+
hint: agents[a].skillsDir
|
|
3191
|
+
})),
|
|
3192
|
+
initialSelected: [],
|
|
3193
|
+
lockedSection: {
|
|
3194
|
+
title: "Universal (.agents/skills)",
|
|
3195
|
+
items: universalAgents.map((a) => ({
|
|
3196
|
+
value: a,
|
|
3197
|
+
label: agents[a].displayName
|
|
3198
|
+
}))
|
|
3199
|
+
}
|
|
3200
|
+
});
|
|
3201
|
+
if (isCancelled(selected)) {
|
|
3202
|
+
xe("Sync cancelled");
|
|
3203
|
+
process.exit(0);
|
|
3204
|
+
}
|
|
3205
|
+
targetAgents = selected;
|
|
3206
|
+
}
|
|
3207
|
+
else if (installedAgents.length === 1 || options.yes) {
|
|
3208
|
+
targetAgents = [...installedAgents];
|
|
3209
|
+
for (const ua of universalAgents) if (!targetAgents.includes(ua)) targetAgents.push(ua);
|
|
3210
|
+
} else {
|
|
3211
|
+
const selected = await searchMultiselect({
|
|
3212
|
+
message: "Which agents do you want to install to?",
|
|
3213
|
+
items: getNonUniversalAgents().filter((a) => installedAgents.includes(a)).map((a) => ({
|
|
3214
|
+
value: a,
|
|
3215
|
+
label: agents[a].displayName,
|
|
3216
|
+
hint: agents[a].skillsDir
|
|
3217
|
+
})),
|
|
3218
|
+
initialSelected: installedAgents.filter((a) => !universalAgents.includes(a)),
|
|
3219
|
+
lockedSection: {
|
|
3220
|
+
title: "Universal (.agents/skills)",
|
|
3221
|
+
items: universalAgents.map((a) => ({
|
|
3222
|
+
value: a,
|
|
3223
|
+
label: agents[a].displayName
|
|
3224
|
+
}))
|
|
3225
|
+
}
|
|
3226
|
+
});
|
|
3227
|
+
if (isCancelled(selected)) {
|
|
3228
|
+
xe("Sync cancelled");
|
|
3229
|
+
process.exit(0);
|
|
3230
|
+
}
|
|
3231
|
+
targetAgents = selected;
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
const summaryLines = [];
|
|
3235
|
+
for (const skill of toInstall) {
|
|
3236
|
+
const shortCanonical = shortenPath$1(getCanonicalPath(skill.name, { global: false }), cwd);
|
|
3237
|
+
summaryLines.push(`${import_picocolors.default.cyan(skill.name)} ${import_picocolors.default.dim(`← ${skill.packageName}`)}`);
|
|
3238
|
+
summaryLines.push(` ${import_picocolors.default.dim(shortCanonical)}`);
|
|
3239
|
+
}
|
|
3240
|
+
console.log();
|
|
3241
|
+
Me(summaryLines.join("\n"), "Sync Summary");
|
|
3242
|
+
if (!options.yes) {
|
|
3243
|
+
const confirmed = await ye({ message: "Proceed with sync?" });
|
|
3244
|
+
if (pD(confirmed) || !confirmed) {
|
|
3245
|
+
xe("Sync cancelled");
|
|
3246
|
+
process.exit(0);
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
spinner.start("Syncing skills...");
|
|
3250
|
+
const results = [];
|
|
3251
|
+
for (const skill of toInstall) for (const agent of targetAgents) {
|
|
3252
|
+
const result = await installSkillForAgent(skill, agent, {
|
|
3253
|
+
global: false,
|
|
3254
|
+
cwd,
|
|
3255
|
+
mode: "symlink"
|
|
3256
|
+
});
|
|
3257
|
+
results.push({
|
|
3258
|
+
skill: skill.name,
|
|
3259
|
+
packageName: skill.packageName,
|
|
3260
|
+
agent: agents[agent].displayName,
|
|
3261
|
+
success: result.success,
|
|
3262
|
+
path: result.path,
|
|
3263
|
+
canonicalPath: result.canonicalPath,
|
|
3264
|
+
error: result.error
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
spinner.stop("Sync complete");
|
|
3268
|
+
const successful = results.filter((r) => r.success);
|
|
3269
|
+
const failed = results.filter((r) => !r.success);
|
|
3270
|
+
const successfulSkillNames = new Set(successful.map((r) => r.skill));
|
|
3271
|
+
for (const skill of toInstall) if (successfulSkillNames.has(skill.name)) try {
|
|
3272
|
+
const computedHash = await computeSkillFolderHash(skill.path);
|
|
3273
|
+
await addSkillToLocalLock(skill.name, {
|
|
3274
|
+
source: skill.packageName,
|
|
3275
|
+
sourceType: "node_modules",
|
|
3276
|
+
computedHash
|
|
3277
|
+
}, cwd);
|
|
3278
|
+
} catch {}
|
|
3279
|
+
console.log();
|
|
3280
|
+
if (successful.length > 0) {
|
|
3281
|
+
const bySkill = /* @__PURE__ */ new Map();
|
|
3282
|
+
for (const r of successful) {
|
|
3283
|
+
const skillResults = bySkill.get(r.skill) || [];
|
|
3284
|
+
skillResults.push(r);
|
|
3285
|
+
bySkill.set(r.skill, skillResults);
|
|
3286
|
+
}
|
|
3287
|
+
const resultLines = [];
|
|
3288
|
+
for (const [skillName, skillResults] of bySkill) {
|
|
3289
|
+
const firstResult = skillResults[0];
|
|
3290
|
+
const pkg = toInstall.find((s) => s.name === skillName)?.packageName;
|
|
3291
|
+
if (firstResult.canonicalPath) {
|
|
3292
|
+
const shortPath = shortenPath$1(firstResult.canonicalPath, cwd);
|
|
3293
|
+
resultLines.push(`${import_picocolors.default.green("✓")} ${skillName} ${import_picocolors.default.dim(`← ${pkg}`)}`);
|
|
3294
|
+
resultLines.push(` ${import_picocolors.default.dim(shortPath)}`);
|
|
3295
|
+
} else resultLines.push(`${import_picocolors.default.green("✓")} ${skillName} ${import_picocolors.default.dim(`← ${pkg}`)}`);
|
|
3296
|
+
}
|
|
3297
|
+
const skillCount = bySkill.size;
|
|
3298
|
+
const title = import_picocolors.default.green(`Synced ${skillCount} skill${skillCount !== 1 ? "s" : ""}`);
|
|
3299
|
+
Me(resultLines.join("\n"), title);
|
|
3300
|
+
}
|
|
3301
|
+
if (failed.length > 0) {
|
|
3302
|
+
console.log();
|
|
3303
|
+
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
3304
|
+
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill} → ${r.agent}: ${import_picocolors.default.dim(r.error)}`);
|
|
3305
|
+
}
|
|
3306
|
+
track({
|
|
3307
|
+
event: "experimental_sync",
|
|
3308
|
+
skillCount: String(toInstall.length),
|
|
3309
|
+
successCount: String(successfulSkillNames.size),
|
|
3310
|
+
agents: targetAgents.join(",")
|
|
3311
|
+
});
|
|
3312
|
+
console.log();
|
|
3313
|
+
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
3314
|
+
}
|
|
3315
|
+
function parseSyncOptions(args) {
|
|
3316
|
+
const options = {};
|
|
3317
|
+
for (let i = 0; i < args.length; i++) {
|
|
3318
|
+
const arg = args[i];
|
|
3319
|
+
if (arg === "-y" || arg === "--yes") options.yes = true;
|
|
3320
|
+
else if (arg === "-f" || arg === "--force") options.force = true;
|
|
3321
|
+
else if (arg === "-a" || arg === "--agent") {
|
|
3322
|
+
options.agent = options.agent || [];
|
|
3323
|
+
i++;
|
|
3324
|
+
let nextArg = args[i];
|
|
3325
|
+
while (i < args.length && nextArg && !nextArg.startsWith("-")) {
|
|
3326
|
+
options.agent.push(nextArg);
|
|
3327
|
+
i++;
|
|
3328
|
+
nextArg = args[i];
|
|
3329
|
+
}
|
|
3330
|
+
i--;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
return { options };
|
|
3334
|
+
}
|
|
3335
|
+
async function runInstallFromLock(args) {
|
|
3336
|
+
const lock = await readLocalLock(process.cwd());
|
|
3337
|
+
const skillEntries = Object.entries(lock.skills);
|
|
3338
|
+
if (skillEntries.length === 0) {
|
|
3339
|
+
M.warn("No project skills found in skills-lock.json");
|
|
3340
|
+
M.info(`Add project-level skills with ${import_picocolors.default.cyan(`${CLI_NPX_COMMAND} add <package>`)} (without ${import_picocolors.default.cyan("-g")})`);
|
|
3341
|
+
return;
|
|
3342
|
+
}
|
|
3343
|
+
const universalAgentNames = getUniversalAgents();
|
|
3344
|
+
const nodeModuleSkills = [];
|
|
3345
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
3346
|
+
for (const [skillName, entry] of skillEntries) {
|
|
3347
|
+
if (entry.sourceType === "node_modules") {
|
|
3348
|
+
nodeModuleSkills.push(skillName);
|
|
3349
|
+
continue;
|
|
3350
|
+
}
|
|
3351
|
+
const existing = bySource.get(entry.source);
|
|
3352
|
+
if (existing) existing.skills.push(skillName);
|
|
3353
|
+
else bySource.set(entry.source, {
|
|
3354
|
+
sourceType: entry.sourceType,
|
|
3355
|
+
skills: [skillName]
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
const remoteCount = skillEntries.length - nodeModuleSkills.length;
|
|
3359
|
+
if (remoteCount > 0) M.info(`Restoring ${import_picocolors.default.cyan(String(remoteCount))} skill${remoteCount !== 1 ? "s" : ""} from skills-lock.json into ${import_picocolors.default.dim(".agents/skills/")}`);
|
|
3360
|
+
for (const [source, { skills }] of bySource) try {
|
|
3361
|
+
await runAdd([source], {
|
|
3362
|
+
skill: skills,
|
|
3363
|
+
agent: universalAgentNames,
|
|
3364
|
+
yes: true
|
|
3365
|
+
});
|
|
3366
|
+
} catch (error) {
|
|
3367
|
+
M.error(`Failed to install from ${import_picocolors.default.cyan(source)}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3368
|
+
}
|
|
3369
|
+
if (nodeModuleSkills.length > 0) {
|
|
3370
|
+
M.info(`${import_picocolors.default.cyan(String(nodeModuleSkills.length))} skill${nodeModuleSkills.length !== 1 ? "s" : ""} from node_modules`);
|
|
3371
|
+
try {
|
|
3372
|
+
const { options: syncOptions } = parseSyncOptions(args);
|
|
3373
|
+
await runSync(args, {
|
|
3374
|
+
...syncOptions,
|
|
3375
|
+
yes: true,
|
|
3376
|
+
agent: universalAgentNames
|
|
3377
|
+
});
|
|
3378
|
+
} catch (error) {
|
|
3379
|
+
M.error(`Failed to sync node_modules skills: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
const RESET$1 = "\x1B[0m";
|
|
3384
|
+
const BOLD$1 = "\x1B[1m";
|
|
3385
|
+
const DIM$1 = "\x1B[38;5;102m";
|
|
3386
|
+
const CYAN = "\x1B[36m";
|
|
3387
|
+
const YELLOW = "\x1B[33m";
|
|
3388
|
+
function shortenPath(fullPath, cwd) {
|
|
3389
|
+
const home = homedir();
|
|
3390
|
+
if (fullPath.startsWith(home)) return fullPath.replace(home, "~");
|
|
3391
|
+
if (fullPath.startsWith(cwd)) return "." + fullPath.slice(cwd.length);
|
|
3392
|
+
return fullPath;
|
|
3393
|
+
}
|
|
3394
|
+
function formatList(items, maxShow = 5) {
|
|
3395
|
+
if (items.length <= maxShow) return items.join(", ");
|
|
3396
|
+
const shown = items.slice(0, maxShow);
|
|
3397
|
+
const remaining = items.length - maxShow;
|
|
3398
|
+
return `${shown.join(", ")} +${remaining} more`;
|
|
3399
|
+
}
|
|
3400
|
+
function parseListOptions(args) {
|
|
3401
|
+
const options = {};
|
|
3402
|
+
for (let i = 0; i < args.length; i++) {
|
|
3403
|
+
const arg = args[i];
|
|
3404
|
+
if (arg === "-g" || arg === "--global") options.global = true;
|
|
3405
|
+
else if (arg === "-a" || arg === "--agent") {
|
|
3406
|
+
options.agent = options.agent || [];
|
|
3407
|
+
while (i + 1 < args.length && !args[i + 1].startsWith("-")) options.agent.push(args[++i]);
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
return options;
|
|
3411
|
+
}
|
|
3412
|
+
async function runList(args) {
|
|
3413
|
+
const options = parseListOptions(args);
|
|
3414
|
+
const scope = options.global === true ? true : false;
|
|
3415
|
+
let agentFilter;
|
|
3416
|
+
if (options.agent && options.agent.length > 0) {
|
|
3417
|
+
const validAgents = Object.keys(agents);
|
|
3418
|
+
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
3419
|
+
if (invalidAgents.length > 0) {
|
|
3420
|
+
console.log(`${YELLOW}Invalid agents: ${invalidAgents.join(", ")}${RESET$1}`);
|
|
3421
|
+
console.log(`${DIM$1}Valid agents: ${validAgents.join(", ")}${RESET$1}`);
|
|
3422
|
+
process.exit(1);
|
|
3423
|
+
}
|
|
3424
|
+
agentFilter = options.agent;
|
|
3425
|
+
}
|
|
3426
|
+
const installedSkills = await listInstalledSkills({
|
|
3427
|
+
global: scope,
|
|
3428
|
+
agentFilter
|
|
3429
|
+
});
|
|
3430
|
+
const lockedSkills = await getAllLockedSkills();
|
|
3431
|
+
const cwd = process.cwd();
|
|
3432
|
+
const scopeLabel = scope ? "Global" : "Project";
|
|
3433
|
+
if (installedSkills.length === 0) {
|
|
3434
|
+
console.log(`${DIM$1}No ${scopeLabel.toLowerCase()} skills found.${RESET$1}`);
|
|
3435
|
+
if (scope) console.log(`${DIM$1}Try listing project skills without -g${RESET$1}`);
|
|
3436
|
+
else console.log(`${DIM$1}Try listing global skills with -g${RESET$1}`);
|
|
3437
|
+
return;
|
|
3438
|
+
}
|
|
3439
|
+
function printSkill(skill, indent = false) {
|
|
3440
|
+
const prefix = indent ? " " : "";
|
|
3441
|
+
const shortPath = shortenPath(skill.canonicalPath, cwd);
|
|
3442
|
+
const agentNames = skill.agents.map((a) => agents[a].displayName);
|
|
3443
|
+
const agentInfo = skill.agents.length > 0 ? formatList(agentNames) : `${YELLOW}not linked${RESET$1}`;
|
|
3444
|
+
console.log(`${prefix}${CYAN}${skill.name}${RESET$1} ${DIM$1}${shortPath}${RESET$1}`);
|
|
3445
|
+
console.log(`${prefix} ${DIM$1}Agents:${RESET$1} ${agentInfo}`);
|
|
3446
|
+
}
|
|
3447
|
+
console.log(`${BOLD$1}${scopeLabel} Skills${RESET$1}`);
|
|
3448
|
+
console.log();
|
|
3449
|
+
const groupedSkills = {};
|
|
3450
|
+
const ungroupedSkills = [];
|
|
3451
|
+
for (const skill of installedSkills) {
|
|
3452
|
+
const lockEntry = lockedSkills[skill.name];
|
|
3453
|
+
if (lockEntry?.pluginName) {
|
|
3454
|
+
const group = lockEntry.pluginName;
|
|
3455
|
+
if (!groupedSkills[group]) groupedSkills[group] = [];
|
|
3456
|
+
groupedSkills[group].push(skill);
|
|
3457
|
+
} else ungroupedSkills.push(skill);
|
|
3458
|
+
}
|
|
3459
|
+
if (Object.keys(groupedSkills).length > 0) {
|
|
3460
|
+
const sortedGroups = Object.keys(groupedSkills).sort();
|
|
3461
|
+
for (const group of sortedGroups) {
|
|
3462
|
+
const title = group.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3463
|
+
console.log(`${BOLD$1}${title}${RESET$1}`);
|
|
3464
|
+
const skills = groupedSkills[group];
|
|
3465
|
+
if (skills) for (const skill of skills) printSkill(skill, true);
|
|
3466
|
+
console.log();
|
|
3467
|
+
}
|
|
3468
|
+
if (ungroupedSkills.length > 0) {
|
|
3469
|
+
console.log(`${BOLD$1}General${RESET$1}`);
|
|
3470
|
+
for (const skill of ungroupedSkills) printSkill(skill, true);
|
|
3471
|
+
console.log();
|
|
3472
|
+
}
|
|
3473
|
+
} else {
|
|
3474
|
+
for (const skill of installedSkills) printSkill(skill);
|
|
3475
|
+
console.log();
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
async function removeCommand(skillNames, options) {
|
|
3479
|
+
const isGlobal = options.global ?? false;
|
|
3480
|
+
const cwd = process.cwd();
|
|
3481
|
+
const spinner = Y();
|
|
3482
|
+
spinner.start("Scanning for installed skills...");
|
|
3483
|
+
const skillNamesSet = /* @__PURE__ */ new Set();
|
|
3484
|
+
const scanDir = async (dir) => {
|
|
3485
|
+
try {
|
|
3486
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
3487
|
+
for (const entry of entries) if (entry.isDirectory()) skillNamesSet.add(entry.name);
|
|
3488
|
+
} catch (err) {
|
|
3489
|
+
if (err instanceof Error && err.code !== "ENOENT") M.warn(`Could not scan directory ${dir}: ${err.message}`);
|
|
3490
|
+
}
|
|
3491
|
+
};
|
|
3492
|
+
if (isGlobal) {
|
|
3493
|
+
await scanDir(getCanonicalSkillsDir(true, cwd));
|
|
3494
|
+
for (const agent of Object.values(agents)) if (agent.globalSkillsDir !== void 0) await scanDir(agent.globalSkillsDir);
|
|
3495
|
+
} else {
|
|
3496
|
+
await scanDir(getCanonicalSkillsDir(false, cwd));
|
|
3497
|
+
for (const agent of Object.values(agents)) await scanDir(join(cwd, agent.skillsDir));
|
|
3498
|
+
}
|
|
3499
|
+
const installedSkills = Array.from(skillNamesSet).sort();
|
|
3500
|
+
spinner.stop(`Found ${installedSkills.length} unique installed skill(s)`);
|
|
3501
|
+
if (installedSkills.length === 0) {
|
|
3502
|
+
Se(import_picocolors.default.yellow("No skills found to remove."));
|
|
3503
|
+
return;
|
|
3504
|
+
}
|
|
3505
|
+
if (options.agent && options.agent.length > 0) {
|
|
3506
|
+
const validAgents = Object.keys(agents);
|
|
3507
|
+
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
3508
|
+
if (invalidAgents.length > 0) {
|
|
3509
|
+
M.error(`Invalid agents: ${invalidAgents.join(", ")}`);
|
|
3510
|
+
M.info(`Valid agents: ${validAgents.join(", ")}`);
|
|
3511
|
+
process.exit(1);
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
let selectedSkills = [];
|
|
3515
|
+
if (options.all) selectedSkills = installedSkills;
|
|
3516
|
+
else if (skillNames.length > 0) {
|
|
3517
|
+
selectedSkills = installedSkills.filter((s) => skillNames.some((name) => name.toLowerCase() === s.toLowerCase()));
|
|
3518
|
+
if (selectedSkills.length === 0) {
|
|
3519
|
+
M.error(`No matching skills found for: ${skillNames.join(", ")}`);
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
} else {
|
|
3523
|
+
const choices = installedSkills.map((s) => ({
|
|
3524
|
+
value: s,
|
|
3525
|
+
label: s
|
|
3526
|
+
}));
|
|
3527
|
+
const selected = await fe({
|
|
3528
|
+
message: `Select skills to remove ${import_picocolors.default.dim("(space to toggle)")}`,
|
|
3529
|
+
options: choices,
|
|
3530
|
+
required: true
|
|
3531
|
+
});
|
|
3532
|
+
if (pD(selected)) {
|
|
3533
|
+
xe("Removal cancelled");
|
|
3534
|
+
process.exit(0);
|
|
3535
|
+
}
|
|
3536
|
+
selectedSkills = selected;
|
|
3537
|
+
}
|
|
3538
|
+
let targetAgents;
|
|
3539
|
+
if (options.agent && options.agent.length > 0) targetAgents = options.agent;
|
|
3540
|
+
else {
|
|
3541
|
+
targetAgents = Object.keys(agents);
|
|
3542
|
+
spinner.stop(`Targeting ${targetAgents.length} potential agent(s)`);
|
|
3543
|
+
}
|
|
3544
|
+
if (!options.yes) {
|
|
3545
|
+
console.log();
|
|
3546
|
+
M.info("Skills to remove:");
|
|
3547
|
+
for (const skill of selectedSkills) M.message(` ${import_picocolors.default.red("•")} ${skill}`);
|
|
3548
|
+
console.log();
|
|
3549
|
+
const confirmed = await ye({ message: `Are you sure you want to uninstall ${selectedSkills.length} skill(s)?` });
|
|
3550
|
+
if (pD(confirmed) || !confirmed) {
|
|
3551
|
+
xe("Removal cancelled");
|
|
3552
|
+
process.exit(0);
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
spinner.start("Removing skills...");
|
|
3556
|
+
const results = [];
|
|
3557
|
+
for (const skillName of selectedSkills) try {
|
|
3558
|
+
const canonicalPath = getCanonicalPath(skillName, {
|
|
3559
|
+
global: isGlobal,
|
|
3560
|
+
cwd
|
|
3561
|
+
});
|
|
3562
|
+
for (const agentKey of targetAgents) {
|
|
3563
|
+
const agent = agents[agentKey];
|
|
3564
|
+
const skillPath = getInstallPath(skillName, agentKey, {
|
|
3565
|
+
global: isGlobal,
|
|
3566
|
+
cwd
|
|
3567
|
+
});
|
|
3568
|
+
const pathsToCleanup = new Set([skillPath]);
|
|
3569
|
+
const sanitizedName = sanitizeName(skillName);
|
|
3570
|
+
if (isGlobal && agent.globalSkillsDir) pathsToCleanup.add(join(agent.globalSkillsDir, sanitizedName));
|
|
3571
|
+
else pathsToCleanup.add(join(cwd, agent.skillsDir, sanitizedName));
|
|
3572
|
+
for (const pathToCleanup of pathsToCleanup) {
|
|
3573
|
+
if (pathToCleanup === canonicalPath) continue;
|
|
3574
|
+
try {
|
|
3575
|
+
if (await lstat(pathToCleanup).catch(() => null)) await rm(pathToCleanup, {
|
|
3576
|
+
recursive: true,
|
|
3577
|
+
force: true
|
|
3578
|
+
});
|
|
3579
|
+
} catch (err) {
|
|
3580
|
+
M.warn(`Could not remove skill from ${agent.displayName}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
const remainingAgents = (await detectInstalledAgents()).filter((a) => !targetAgents.includes(a));
|
|
3585
|
+
let isStillUsed = false;
|
|
3586
|
+
for (const agentKey of remainingAgents) if (await lstat(getInstallPath(skillName, agentKey, {
|
|
3587
|
+
global: isGlobal,
|
|
3588
|
+
cwd
|
|
3589
|
+
})).catch(() => null)) {
|
|
3590
|
+
isStillUsed = true;
|
|
3591
|
+
break;
|
|
3592
|
+
}
|
|
3593
|
+
if (!isStillUsed) await rm(canonicalPath, {
|
|
3594
|
+
recursive: true,
|
|
3595
|
+
force: true
|
|
3596
|
+
});
|
|
3597
|
+
const lockEntry = isGlobal ? await getSkillFromLock(skillName) : null;
|
|
3598
|
+
const effectiveSource = lockEntry?.source || "local";
|
|
3599
|
+
const effectiveSourceType = lockEntry?.sourceType || "local";
|
|
3600
|
+
if (isGlobal) await removeSkillFromLock(skillName);
|
|
3601
|
+
results.push({
|
|
3602
|
+
skill: skillName,
|
|
3603
|
+
success: true,
|
|
3604
|
+
source: effectiveSource,
|
|
3605
|
+
sourceType: effectiveSourceType
|
|
3606
|
+
});
|
|
3607
|
+
} catch (err) {
|
|
3608
|
+
results.push({
|
|
3609
|
+
skill: skillName,
|
|
3610
|
+
success: false,
|
|
3611
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3612
|
+
});
|
|
3613
|
+
}
|
|
3614
|
+
spinner.stop("Removal process complete");
|
|
3615
|
+
const successful = results.filter((r) => r.success);
|
|
3616
|
+
const failed = results.filter((r) => !r.success);
|
|
3617
|
+
if (successful.length > 0) {
|
|
3618
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
3619
|
+
for (const r of successful) {
|
|
3620
|
+
const source = r.source || "local";
|
|
3621
|
+
const existing = bySource.get(source) || { skills: [] };
|
|
3622
|
+
existing.skills.push(r.skill);
|
|
3623
|
+
existing.sourceType = r.sourceType;
|
|
3624
|
+
bySource.set(source, existing);
|
|
3625
|
+
}
|
|
3626
|
+
for (const [source, data] of bySource) track({
|
|
3627
|
+
event: "remove",
|
|
3628
|
+
source,
|
|
3629
|
+
skills: data.skills.join(","),
|
|
3630
|
+
agents: targetAgents.join(","),
|
|
3631
|
+
...isGlobal && { global: "1" },
|
|
3632
|
+
sourceType: data.sourceType
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
if (successful.length > 0) M.success(import_picocolors.default.green(`Successfully removed ${successful.length} skill(s)`));
|
|
3636
|
+
if (failed.length > 0) {
|
|
3637
|
+
M.error(import_picocolors.default.red(`Failed to remove ${failed.length} skill(s)`));
|
|
3638
|
+
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill}: ${r.error}`);
|
|
3639
|
+
}
|
|
3640
|
+
console.log();
|
|
3641
|
+
Se(import_picocolors.default.green("Done!"));
|
|
3642
|
+
}
|
|
3643
|
+
function parseRemoveOptions(args) {
|
|
3644
|
+
const options = {};
|
|
3645
|
+
const skills = [];
|
|
3646
|
+
for (let i = 0; i < args.length; i++) {
|
|
3647
|
+
const arg = args[i];
|
|
3648
|
+
if (arg === "-g" || arg === "--global") options.global = true;
|
|
3649
|
+
else if (arg === "-y" || arg === "--yes") options.yes = true;
|
|
3650
|
+
else if (arg === "--all") options.all = true;
|
|
3651
|
+
else if (arg === "-a" || arg === "--agent") {
|
|
3652
|
+
options.agent = options.agent || [];
|
|
3653
|
+
i++;
|
|
3654
|
+
let nextArg = args[i];
|
|
3655
|
+
while (i < args.length && nextArg && !nextArg.startsWith("-")) {
|
|
3656
|
+
options.agent.push(nextArg);
|
|
3657
|
+
i++;
|
|
3658
|
+
nextArg = args[i];
|
|
3659
|
+
}
|
|
3660
|
+
i--;
|
|
3661
|
+
} else if (arg && !arg.startsWith("-")) skills.push(arg);
|
|
3662
|
+
}
|
|
3663
|
+
return {
|
|
3664
|
+
skills,
|
|
3665
|
+
options
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
3669
|
+
function getVersion() {
|
|
3670
|
+
try {
|
|
3671
|
+
const pkgPath = join(__dirname, "..", "package.json");
|
|
3672
|
+
return JSON.parse(readFileSync(pkgPath, "utf-8")).version;
|
|
3673
|
+
} catch {
|
|
3674
|
+
return "0.0.0";
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
const VERSION = getVersion();
|
|
3678
|
+
initTelemetry(VERSION);
|
|
3679
|
+
const RESET = "\x1B[0m";
|
|
3680
|
+
const BOLD = "\x1B[1m";
|
|
3681
|
+
const DIM = "\x1B[38;5;102m";
|
|
3682
|
+
const TEXT = "\x1B[38;5;145m";
|
|
3683
|
+
const LOGO_LINES = [
|
|
3684
|
+
"███████╗██╗ ██╗██╗██╗ ██╗ ███████╗",
|
|
3685
|
+
"██╔════╝██║ ██╔╝██║██║ ██║ ██╔════╝",
|
|
3686
|
+
"███████╗█████╔╝ ██║██║ ██║ ███████╗",
|
|
3687
|
+
"╚════██║██╔═██╗ ██║██║ ██║ ╚════██║",
|
|
3688
|
+
"███████║██║ ██╗██║███████╗███████╗███████║",
|
|
3689
|
+
"╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚══════╝"
|
|
3690
|
+
];
|
|
3691
|
+
const GRAYS = [
|
|
3692
|
+
"\x1B[38;5;250m",
|
|
3693
|
+
"\x1B[38;5;248m",
|
|
3694
|
+
"\x1B[38;5;245m",
|
|
3695
|
+
"\x1B[38;5;243m",
|
|
3696
|
+
"\x1B[38;5;240m",
|
|
3697
|
+
"\x1B[38;5;238m"
|
|
3698
|
+
];
|
|
3699
|
+
function showLogo() {
|
|
3700
|
+
console.log();
|
|
3701
|
+
LOGO_LINES.forEach((line, i) => {
|
|
3702
|
+
console.log(`${GRAYS[i]}${line}${RESET}`);
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
function showBanner() {
|
|
3706
|
+
showLogo();
|
|
3707
|
+
console.log();
|
|
3708
|
+
console.log(`${DIM}The open agent skills ecosystem${RESET}`);
|
|
3709
|
+
console.log();
|
|
3710
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} add ${DIM}<package>${RESET} ${DIM}Add a new skill${RESET}`);
|
|
3711
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} remove${RESET} ${DIM}Remove installed skills${RESET}`);
|
|
3712
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} list${RESET} ${DIM}List installed skills${RESET}`);
|
|
3713
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} find ${DIM}[query]${RESET} ${DIM}Search for skills${RESET}`);
|
|
3714
|
+
console.log();
|
|
3715
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} check${RESET} ${DIM}Check for updates${RESET}`);
|
|
3716
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} update${RESET} ${DIM}Update all skills${RESET}`);
|
|
3717
|
+
console.log();
|
|
3718
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} experimental_install${RESET} ${DIM}Restore from skills-lock.json${RESET}`);
|
|
3719
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} init ${DIM}[name]${RESET} ${DIM}Create a new skill${RESET}`);
|
|
3720
|
+
console.log(` ${DIM}$${RESET} ${TEXT}${CLI_NPX_COMMAND} experimental_sync${RESET} ${DIM}Sync skills from node_modules${RESET}`);
|
|
3721
|
+
console.log();
|
|
3722
|
+
console.log(`${DIM}try:${RESET} ${CLI_NPX_COMMAND} add ${DEFAULT_WELL_KNOWN_BASE_URL}`);
|
|
3723
|
+
console.log();
|
|
3724
|
+
console.log(`Discover more skills at ${TEXT}${DEFAULT_DISCOVERY_SITE_URL}/${RESET}`);
|
|
3725
|
+
console.log();
|
|
3726
|
+
}
|
|
3727
|
+
function showHelp() {
|
|
3728
|
+
console.log(`
|
|
3729
|
+
${BOLD}Usage:${RESET} ${CLI_BINARY_NAME} <command> [options]
|
|
3730
|
+
|
|
3731
|
+
${BOLD}Manage Skills:${RESET}
|
|
3732
|
+
add <package> Add a skill package (alias: a)
|
|
3733
|
+
e.g. yonyou/skilling
|
|
3734
|
+
${DEFAULT_WELL_KNOWN_BASE_URL}
|
|
3735
|
+
https://${DEFAULT_GIT_HOST}/group/repo
|
|
3736
|
+
remove [skills] Remove installed skills
|
|
3737
|
+
list, ls List installed skills
|
|
3738
|
+
find [query] Search for skills interactively
|
|
3739
|
+
|
|
3740
|
+
${BOLD}Updates:${RESET}
|
|
3741
|
+
check Check for available skill updates
|
|
3742
|
+
update Update all skills to latest versions
|
|
3743
|
+
|
|
3744
|
+
${BOLD}Project:${RESET}
|
|
3745
|
+
experimental_install Restore skills from skills-lock.json
|
|
3746
|
+
init [name] Initialize a skill (creates <name>/SKILL.md or ./SKILL.md)
|
|
3747
|
+
experimental_sync Sync skills from node_modules into agent directories
|
|
3748
|
+
|
|
3749
|
+
${BOLD}Add Options:${RESET}
|
|
3750
|
+
-g, --global Install skill globally (user-level) instead of project-level
|
|
3751
|
+
-a, --agent <agents> Specify agents to install to (use '*' for all agents)
|
|
3752
|
+
-s, --skill <skills> Specify skill names to install (use '*' for all skills)
|
|
3753
|
+
-l, --list List available skills in the repository without installing
|
|
3754
|
+
-y, --yes Skip confirmation prompts
|
|
3755
|
+
--copy Copy files instead of symlinking to agent directories
|
|
3756
|
+
--all Shorthand for --skill '*' --agent '*' -y
|
|
3757
|
+
--full-depth Search all subdirectories even when a root SKILL.md exists
|
|
3758
|
+
|
|
3759
|
+
${BOLD}Remove Options:${RESET}
|
|
3760
|
+
-g, --global Remove from global scope
|
|
3761
|
+
-a, --agent <agents> Remove from specific agents (use '*' for all agents)
|
|
3762
|
+
-s, --skill <skills> Specify skills to remove (use '*' for all skills)
|
|
3763
|
+
-y, --yes Skip confirmation prompts
|
|
3764
|
+
--all Shorthand for --skill '*' --agent '*' -y
|
|
3765
|
+
|
|
3766
|
+
${BOLD}Experimental Sync Options:${RESET}
|
|
3767
|
+
-a, --agent <agents> Specify agents to install to (use '*' for all agents)
|
|
3768
|
+
-y, --yes Skip confirmation prompts
|
|
3769
|
+
|
|
3770
|
+
${BOLD}List Options:${RESET}
|
|
3771
|
+
-g, --global List global skills (default: project)
|
|
3772
|
+
-a, --agent <agents> Filter by specific agents
|
|
3773
|
+
|
|
3774
|
+
${BOLD}Options:${RESET}
|
|
3775
|
+
--help, -h Show this help message
|
|
3776
|
+
--version, -v Show version number
|
|
3777
|
+
|
|
3778
|
+
${BOLD}Examples:${RESET}
|
|
3779
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} add yonyou/skilling
|
|
3780
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} add ${DEFAULT_WELL_KNOWN_BASE_URL} -g
|
|
3781
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} add yonyou/skilling --agent claude-code cursor
|
|
3782
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} add yonyou/skilling --skill pr-review commit
|
|
3783
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove ${DIM}# interactive remove${RESET}
|
|
3784
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove web-design ${DIM}# remove by name${RESET}
|
|
3785
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} rm --global frontend-design
|
|
3786
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} list ${DIM}# list project skills${RESET}
|
|
3787
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} ls -g ${DIM}# list global skills${RESET}
|
|
3788
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} ls -a claude-code ${DIM}# filter by agent${RESET}
|
|
3789
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} find ${DIM}# interactive search${RESET}
|
|
3790
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} find typescript ${DIM}# search by keyword${RESET}
|
|
3791
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} check
|
|
3792
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} update
|
|
3793
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} experimental_install ${DIM}# restore from skills-lock.json${RESET}
|
|
3794
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} init my-skill
|
|
3795
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} experimental_sync ${DIM}# sync from node_modules${RESET}
|
|
3796
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} experimental_sync -y ${DIM}# sync without prompts${RESET}
|
|
3797
|
+
|
|
3798
|
+
Discover more skills at ${TEXT}${DEFAULT_DISCOVERY_SITE_URL}/${RESET}
|
|
3799
|
+
`);
|
|
3800
|
+
}
|
|
3801
|
+
function showRemoveHelp() {
|
|
3802
|
+
console.log(`
|
|
3803
|
+
${BOLD}Usage:${RESET} ${CLI_BINARY_NAME} remove [skills...] [options]
|
|
3804
|
+
|
|
3805
|
+
${BOLD}Description:${RESET}
|
|
3806
|
+
Remove installed skills from agents. If no skill names are provided,
|
|
3807
|
+
an interactive selection menu will be shown.
|
|
3808
|
+
|
|
3809
|
+
${BOLD}Arguments:${RESET}
|
|
3810
|
+
skills Optional skill names to remove (space-separated)
|
|
3811
|
+
|
|
3812
|
+
${BOLD}Options:${RESET}
|
|
3813
|
+
-g, --global Remove from global scope (~/) instead of project scope
|
|
3814
|
+
-a, --agent Remove from specific agents (use '*' for all agents)
|
|
3815
|
+
-s, --skill Specify skills to remove (use '*' for all skills)
|
|
3816
|
+
-y, --yes Skip confirmation prompts
|
|
3817
|
+
--all Shorthand for --skill '*' --agent '*' -y
|
|
3818
|
+
|
|
3819
|
+
${BOLD}Examples:${RESET}
|
|
3820
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove ${DIM}# interactive selection${RESET}
|
|
3821
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove my-skill ${DIM}# remove specific skill${RESET}
|
|
3822
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove skill1 skill2 -y ${DIM}# remove multiple skills${RESET}
|
|
3823
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove --global my-skill ${DIM}# remove from global scope${RESET}
|
|
3824
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} rm --agent claude-code my-skill ${DIM}# remove from specific agent${RESET}
|
|
3825
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove --all ${DIM}# remove all skills${RESET}
|
|
3826
|
+
${DIM}$${RESET} ${CLI_BINARY_NAME} remove --skill '*' -a cursor ${DIM}# remove all skills from cursor${RESET}
|
|
3827
|
+
|
|
3828
|
+
Discover more skills at ${TEXT}${DEFAULT_DISCOVERY_SITE_URL}/${RESET}
|
|
3829
|
+
`);
|
|
3830
|
+
}
|
|
3831
|
+
function runInit(args) {
|
|
3832
|
+
const cwd = process.cwd();
|
|
3833
|
+
const skillName = args[0] || basename(cwd);
|
|
3834
|
+
const hasName = args[0] !== void 0;
|
|
3835
|
+
const skillDir = hasName ? join(cwd, skillName) : cwd;
|
|
3836
|
+
const skillFile = join(skillDir, "SKILL.md");
|
|
3837
|
+
const displayPath = hasName ? `${skillName}/SKILL.md` : "SKILL.md";
|
|
3838
|
+
if (existsSync(skillFile)) {
|
|
3839
|
+
console.log(`${TEXT}Skill already exists at ${DIM}${displayPath}${RESET}`);
|
|
3840
|
+
return;
|
|
3841
|
+
}
|
|
3842
|
+
if (hasName) mkdirSync(skillDir, { recursive: true });
|
|
3843
|
+
writeFileSync(skillFile, `---
|
|
3844
|
+
name: ${skillName}
|
|
3845
|
+
description: A brief description of what this skill does
|
|
3846
|
+
---
|
|
3847
|
+
|
|
3848
|
+
# ${skillName}
|
|
3849
|
+
|
|
3850
|
+
Instructions for the agent to follow when this skill is activated.
|
|
3851
|
+
|
|
3852
|
+
## When to use
|
|
3853
|
+
|
|
3854
|
+
Describe when this skill should be used.
|
|
3855
|
+
|
|
3856
|
+
## Instructions
|
|
3857
|
+
|
|
3858
|
+
1. First step
|
|
3859
|
+
2. Second step
|
|
3860
|
+
3. Additional steps as needed
|
|
3861
|
+
`);
|
|
3862
|
+
console.log(`${TEXT}Initialized skill: ${DIM}${skillName}${RESET}`);
|
|
3863
|
+
console.log();
|
|
3864
|
+
console.log(`${DIM}Created:${RESET}`);
|
|
3865
|
+
console.log(` ${displayPath}`);
|
|
3866
|
+
console.log();
|
|
3867
|
+
console.log(`${DIM}Next steps:${RESET}`);
|
|
3868
|
+
console.log(` 1. Edit ${TEXT}${displayPath}${RESET} to define your skill instructions`);
|
|
3869
|
+
console.log(` 2. Update the ${TEXT}name${RESET} and ${TEXT}description${RESET} in the frontmatter`);
|
|
3870
|
+
console.log();
|
|
3871
|
+
console.log(`${DIM}Publishing:${RESET}`);
|
|
3872
|
+
console.log(` ${DIM}Git:${RESET} Push to ${TEXT}${DEFAULT_GIT_HOST}${RESET}, then ${TEXT}${CLI_NPX_COMMAND} add <owner>/<repo>${RESET}`);
|
|
3873
|
+
console.log(` ${DIM}URL:${RESET} Publish an RFC 8615 index, then ${TEXT}${CLI_NPX_COMMAND} add ${DEFAULT_WELL_KNOWN_BASE_URL}${hasName ? `/${skillName}` : ""}${RESET}`);
|
|
3874
|
+
console.log();
|
|
3875
|
+
console.log(`Browse existing skills for inspiration at ${TEXT}${DEFAULT_DISCOVERY_SITE_URL}/${RESET}`);
|
|
3876
|
+
console.log();
|
|
3877
|
+
}
|
|
3878
|
+
const AGENTS_DIR = ".agents";
|
|
3879
|
+
const LOCK_FILE = ".skill-lock.json";
|
|
3880
|
+
const CURRENT_LOCK_VERSION = 3;
|
|
3881
|
+
function getSkillLockPath() {
|
|
3882
|
+
return join(homedir(), AGENTS_DIR, LOCK_FILE);
|
|
3883
|
+
}
|
|
3884
|
+
function readSkillLock() {
|
|
3885
|
+
const lockPath = getSkillLockPath();
|
|
3886
|
+
try {
|
|
3887
|
+
const content = readFileSync(lockPath, "utf-8");
|
|
3888
|
+
const parsed = JSON.parse(content);
|
|
3889
|
+
if (typeof parsed.version !== "number" || !parsed.skills) return {
|
|
3890
|
+
version: CURRENT_LOCK_VERSION,
|
|
3891
|
+
skills: {}
|
|
3892
|
+
};
|
|
3893
|
+
if (parsed.version < CURRENT_LOCK_VERSION) return {
|
|
3894
|
+
version: CURRENT_LOCK_VERSION,
|
|
3895
|
+
skills: {}
|
|
3896
|
+
};
|
|
3897
|
+
return parsed;
|
|
3898
|
+
} catch {
|
|
3899
|
+
return {
|
|
3900
|
+
version: CURRENT_LOCK_VERSION,
|
|
3901
|
+
skills: {}
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
async function runCheck(args = []) {
|
|
3906
|
+
console.log(`${TEXT}Checking for skill updates...${RESET}`);
|
|
3907
|
+
console.log();
|
|
3908
|
+
const lock = readSkillLock();
|
|
3909
|
+
const skillNames = Object.keys(lock.skills);
|
|
3910
|
+
if (skillNames.length === 0) {
|
|
3911
|
+
console.log(`${DIM}No skills tracked in lock file.${RESET}`);
|
|
3912
|
+
console.log(`${DIM}Install skills with${RESET} ${TEXT}${CLI_NPX_COMMAND} add <package>${RESET}`);
|
|
3913
|
+
return;
|
|
3914
|
+
}
|
|
3915
|
+
const token = getGitHubToken();
|
|
3916
|
+
const skillsBySource = /* @__PURE__ */ new Map();
|
|
3917
|
+
let skippedCount = 0;
|
|
3918
|
+
for (const skillName of skillNames) {
|
|
3919
|
+
const entry = lock.skills[skillName];
|
|
3920
|
+
if (!entry) continue;
|
|
3921
|
+
if (entry.sourceType !== "github" || !entry.skillFolderHash || !entry.skillPath) {
|
|
3922
|
+
skippedCount++;
|
|
3923
|
+
continue;
|
|
3924
|
+
}
|
|
3925
|
+
const existing = skillsBySource.get(entry.source) || [];
|
|
3926
|
+
existing.push({
|
|
3927
|
+
name: skillName,
|
|
3928
|
+
entry
|
|
3929
|
+
});
|
|
3930
|
+
skillsBySource.set(entry.source, existing);
|
|
3931
|
+
}
|
|
3932
|
+
const totalSkills = skillNames.length - skippedCount;
|
|
3933
|
+
if (totalSkills === 0) {
|
|
3934
|
+
console.log(`${DIM}No GitHub skills to check.${RESET}`);
|
|
3935
|
+
return;
|
|
3936
|
+
}
|
|
3937
|
+
console.log(`${DIM}Checking ${totalSkills} skill(s) for updates...${RESET}`);
|
|
3938
|
+
const updates = [];
|
|
3939
|
+
const errors = [];
|
|
3940
|
+
for (const [source, skills] of skillsBySource) for (const { name, entry } of skills) try {
|
|
3941
|
+
const latestHash = await fetchSkillFolderHash(source, entry.skillPath, token);
|
|
3942
|
+
if (!latestHash) {
|
|
3943
|
+
errors.push({
|
|
3944
|
+
name,
|
|
3945
|
+
source,
|
|
3946
|
+
error: "Could not fetch from GitHub"
|
|
3947
|
+
});
|
|
3948
|
+
continue;
|
|
3949
|
+
}
|
|
3950
|
+
if (latestHash !== entry.skillFolderHash) updates.push({
|
|
3951
|
+
name,
|
|
3952
|
+
source
|
|
3953
|
+
});
|
|
3954
|
+
} catch (err) {
|
|
3955
|
+
errors.push({
|
|
3956
|
+
name,
|
|
3957
|
+
source,
|
|
3958
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
3959
|
+
});
|
|
3960
|
+
}
|
|
3961
|
+
console.log();
|
|
3962
|
+
if (updates.length === 0) console.log(`${TEXT}✓ All skills are up to date${RESET}`);
|
|
3963
|
+
else {
|
|
3964
|
+
console.log(`${TEXT}${updates.length} update(s) available:${RESET}`);
|
|
3965
|
+
console.log();
|
|
3966
|
+
for (const update of updates) {
|
|
3967
|
+
console.log(` ${TEXT}↑${RESET} ${update.name}`);
|
|
3968
|
+
console.log(` ${DIM}source: ${update.source}${RESET}`);
|
|
3969
|
+
}
|
|
3970
|
+
console.log();
|
|
3971
|
+
console.log(`${DIM}Run${RESET} ${TEXT}${CLI_NPX_COMMAND} update${RESET} ${DIM}to update all skills${RESET}`);
|
|
3972
|
+
}
|
|
3973
|
+
if (errors.length > 0) {
|
|
3974
|
+
console.log();
|
|
3975
|
+
console.log(`${DIM}Could not check ${errors.length} skill(s) (may need reinstall)${RESET}`);
|
|
3976
|
+
}
|
|
3977
|
+
track({
|
|
3978
|
+
event: "check",
|
|
3979
|
+
skillCount: String(totalSkills),
|
|
3980
|
+
updatesAvailable: String(updates.length)
|
|
3981
|
+
});
|
|
3982
|
+
console.log();
|
|
3983
|
+
}
|
|
3984
|
+
async function runUpdate() {
|
|
3985
|
+
console.log(`${TEXT}Checking for skill updates...${RESET}`);
|
|
3986
|
+
console.log();
|
|
3987
|
+
const lock = readSkillLock();
|
|
3988
|
+
const skillNames = Object.keys(lock.skills);
|
|
3989
|
+
if (skillNames.length === 0) {
|
|
3990
|
+
console.log(`${DIM}No skills tracked in lock file.${RESET}`);
|
|
3991
|
+
console.log(`${DIM}Install skills with${RESET} ${TEXT}${CLI_NPX_COMMAND} add <package>${RESET}`);
|
|
3992
|
+
return;
|
|
3993
|
+
}
|
|
3994
|
+
const token = getGitHubToken();
|
|
3995
|
+
const updates = [];
|
|
3996
|
+
let checkedCount = 0;
|
|
3997
|
+
for (const skillName of skillNames) {
|
|
3998
|
+
const entry = lock.skills[skillName];
|
|
3999
|
+
if (!entry) continue;
|
|
4000
|
+
if (entry.sourceType !== "github" || !entry.skillFolderHash || !entry.skillPath) continue;
|
|
4001
|
+
checkedCount++;
|
|
4002
|
+
try {
|
|
4003
|
+
const latestHash = await fetchSkillFolderHash(entry.source, entry.skillPath, token);
|
|
4004
|
+
if (latestHash && latestHash !== entry.skillFolderHash) updates.push({
|
|
4005
|
+
name: skillName,
|
|
4006
|
+
source: entry.source,
|
|
4007
|
+
entry
|
|
4008
|
+
});
|
|
4009
|
+
} catch {}
|
|
4010
|
+
}
|
|
4011
|
+
if (checkedCount === 0) {
|
|
4012
|
+
console.log(`${DIM}No skills to check.${RESET}`);
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
if (updates.length === 0) {
|
|
4016
|
+
console.log(`${TEXT}✓ All skills are up to date${RESET}`);
|
|
4017
|
+
console.log();
|
|
4018
|
+
return;
|
|
4019
|
+
}
|
|
4020
|
+
console.log(`${TEXT}Found ${updates.length} update(s)${RESET}`);
|
|
4021
|
+
console.log();
|
|
4022
|
+
let successCount = 0;
|
|
4023
|
+
let failCount = 0;
|
|
4024
|
+
for (const update of updates) {
|
|
4025
|
+
console.log(`${TEXT}Updating ${update.name}...${RESET}`);
|
|
4026
|
+
let installUrl = update.entry.sourceUrl;
|
|
4027
|
+
if (update.entry.skillPath) {
|
|
4028
|
+
let skillFolder = update.entry.skillPath;
|
|
4029
|
+
if (skillFolder.endsWith("/SKILL.md")) skillFolder = skillFolder.slice(0, -9);
|
|
4030
|
+
else if (skillFolder.endsWith("SKILL.md")) skillFolder = skillFolder.slice(0, -8);
|
|
4031
|
+
if (skillFolder.endsWith("/")) skillFolder = skillFolder.slice(0, -1);
|
|
4032
|
+
installUrl = update.entry.sourceUrl.replace(/\.git$/, "").replace(/\/$/, "");
|
|
4033
|
+
installUrl = `${installUrl}/tree/main/${skillFolder}`;
|
|
4034
|
+
}
|
|
4035
|
+
if (spawnSync("npx", [
|
|
4036
|
+
"-y",
|
|
4037
|
+
CLI_PACKAGE_NAME,
|
|
4038
|
+
"add",
|
|
4039
|
+
installUrl,
|
|
4040
|
+
"-g",
|
|
4041
|
+
"-y"
|
|
4042
|
+
], { stdio: [
|
|
4043
|
+
"inherit",
|
|
4044
|
+
"pipe",
|
|
4045
|
+
"pipe"
|
|
4046
|
+
] }).status === 0) {
|
|
4047
|
+
successCount++;
|
|
4048
|
+
console.log(` ${TEXT}✓${RESET} Updated ${update.name}`);
|
|
4049
|
+
} else {
|
|
4050
|
+
failCount++;
|
|
4051
|
+
console.log(` ${DIM}✗ Failed to update ${update.name}${RESET}`);
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
console.log();
|
|
4055
|
+
if (successCount > 0) console.log(`${TEXT}✓ Updated ${successCount} skill(s)${RESET}`);
|
|
4056
|
+
if (failCount > 0) console.log(`${DIM}Failed to update ${failCount} skill(s)${RESET}`);
|
|
4057
|
+
track({
|
|
4058
|
+
event: "update",
|
|
4059
|
+
skillCount: String(updates.length),
|
|
4060
|
+
successCount: String(successCount),
|
|
4061
|
+
failCount: String(failCount)
|
|
4062
|
+
});
|
|
4063
|
+
console.log();
|
|
4064
|
+
}
|
|
4065
|
+
async function main() {
|
|
4066
|
+
const args = process.argv.slice(2);
|
|
4067
|
+
if (args.length === 0) {
|
|
4068
|
+
showBanner();
|
|
4069
|
+
return;
|
|
4070
|
+
}
|
|
4071
|
+
const command = args[0];
|
|
4072
|
+
const restArgs = args.slice(1);
|
|
4073
|
+
switch (command) {
|
|
4074
|
+
case "find":
|
|
4075
|
+
case "search":
|
|
4076
|
+
case "f":
|
|
4077
|
+
case "s":
|
|
4078
|
+
showLogo();
|
|
4079
|
+
console.log();
|
|
4080
|
+
await runFind(restArgs);
|
|
4081
|
+
break;
|
|
4082
|
+
case "init":
|
|
4083
|
+
showLogo();
|
|
4084
|
+
console.log();
|
|
4085
|
+
runInit(restArgs);
|
|
4086
|
+
break;
|
|
4087
|
+
case "experimental_install":
|
|
4088
|
+
showLogo();
|
|
4089
|
+
await runInstallFromLock(restArgs);
|
|
4090
|
+
break;
|
|
4091
|
+
case "i":
|
|
4092
|
+
case "install":
|
|
4093
|
+
case "a":
|
|
4094
|
+
case "add": {
|
|
4095
|
+
showLogo();
|
|
4096
|
+
const { source: addSource, options: addOpts } = parseAddOptions(restArgs);
|
|
4097
|
+
await runAdd(addSource, addOpts);
|
|
4098
|
+
break;
|
|
4099
|
+
}
|
|
4100
|
+
case "remove":
|
|
4101
|
+
case "rm":
|
|
4102
|
+
case "r":
|
|
4103
|
+
if (restArgs.includes("--help") || restArgs.includes("-h")) {
|
|
4104
|
+
showRemoveHelp();
|
|
4105
|
+
break;
|
|
4106
|
+
}
|
|
4107
|
+
const { skills, options: removeOptions } = parseRemoveOptions(restArgs);
|
|
4108
|
+
await removeCommand(skills, removeOptions);
|
|
4109
|
+
break;
|
|
4110
|
+
case "experimental_sync": {
|
|
4111
|
+
showLogo();
|
|
4112
|
+
const { options: syncOptions } = parseSyncOptions(restArgs);
|
|
4113
|
+
await runSync(restArgs, syncOptions);
|
|
4114
|
+
break;
|
|
4115
|
+
}
|
|
4116
|
+
case "list":
|
|
4117
|
+
case "ls":
|
|
4118
|
+
await runList(restArgs);
|
|
4119
|
+
break;
|
|
4120
|
+
case "check":
|
|
4121
|
+
runCheck(restArgs);
|
|
4122
|
+
break;
|
|
4123
|
+
case "update":
|
|
4124
|
+
case "upgrade":
|
|
4125
|
+
runUpdate();
|
|
4126
|
+
break;
|
|
4127
|
+
case "--help":
|
|
4128
|
+
case "-h":
|
|
4129
|
+
showHelp();
|
|
4130
|
+
break;
|
|
4131
|
+
case "--version":
|
|
4132
|
+
case "-v":
|
|
4133
|
+
console.log(VERSION);
|
|
4134
|
+
break;
|
|
4135
|
+
default:
|
|
4136
|
+
console.log(`Unknown command: ${command}`);
|
|
4137
|
+
console.log(`Run ${BOLD}${CLI_BINARY_NAME} --help${RESET} for usage.`);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
main();
|
|
4141
|
+
export {};
|