@useavalon/caelence-agent 0.1.0 → 0.1.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +129 -137
- package/brand/logo/favicon-agent-bg-16.svg +7 -0
- package/brand/logo/favicon-agent-bg-32.svg +7 -0
- package/brand/previews/desktop-chat.png +0 -0
- package/brand/previews/desktop-commands.png +0 -0
- package/brand/previews/desktop-integrations.png +0 -0
- package/brand/previews/desktop-skills.png +0 -0
- package/package.json +5 -3
- package/skills/impeccable/LICENSE +13 -0
- package/skills/impeccable/NOTICE +14 -0
- package/skills/impeccable/SKILL.md +2 -1
- package/src/agent-cwd.ts +51 -0
- package/src/cli/agent-cwd.test.ts +65 -0
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +282 -201
- package/src/cli/picker.test.ts +59 -1
- package/src/cli/picker.ts +46 -0
- package/src/cli/slash-dispatch.test.ts +116 -7
- package/src/cli/slash-dispatch.ts +343 -174
- package/src/cli/slash.test.ts +25 -2
- package/src/cli/slash.ts +37 -8
- package/src/cli/theme.test.ts +7 -0
- package/src/cli/theme.ts +6 -6
- package/src/cli/tui.tsx +385 -217
- package/src/config.ts +1 -1
- package/src/core/strands.ts +10 -1
- package/src/desktop/bridge.test.ts +56 -1
- package/src/desktop/bridge.ts +527 -390
- package/src/desktop/uploads.test.ts +57 -0
- package/src/desktop/uploads.ts +92 -0
- package/src/index.ts +26 -2
- package/src/init.test.ts +19 -2
- package/src/init.ts +25 -17
- package/src/integrations/loopback.test.ts +17 -0
- package/src/integrations/loopback.ts +91 -0
- package/src/observability/prompts.ts +1 -1
- package/src/product.ts +3 -1
- package/src/runtime.test.ts +24 -0
- package/src/runtime.ts +48 -5
- package/src/skills/catalog.test.ts +188 -0
- package/src/skills/catalog.ts +279 -0
- package/src/skills/disabled.test.ts +27 -0
- package/src/skills/disabled.ts +59 -0
- package/src/skills/loader.test.ts +31 -0
- package/src/skills/loader.ts +31 -4
- package/src/skills/registry.test.ts +64 -3
- package/src/skills/registry.ts +248 -93
- package/src/skills/skill-command.ts +2 -0
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
parseBundledSkillRef,
|
|
13
13
|
parseSkillSource,
|
|
14
14
|
removeSkillFromRoots,
|
|
15
|
+
searchSkillCatalog,
|
|
15
16
|
searchSkills,
|
|
16
17
|
searchSkillsSh,
|
|
17
18
|
} from "./registry.ts";
|
|
@@ -113,6 +114,47 @@ describe("installSkillFromSource", () => {
|
|
|
113
114
|
expect(result).toEqual({ name: "hello", rel: "hello/SKILL.md" });
|
|
114
115
|
const body = await readFile(join(dest, "hello", "SKILL.md"), "utf8");
|
|
115
116
|
expect(body).toContain("# Hello");
|
|
117
|
+
expect(await readFile(join(dest, "hello", ".catalog-ref"), "utf8")).toBe("acme/pack@hello\n");
|
|
118
|
+
} finally {
|
|
119
|
+
await rm(dest, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("installs one named skill from a repo that contains several", async () => {
|
|
124
|
+
const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
|
|
125
|
+
try {
|
|
126
|
+
const result = await installSkillFromSource({
|
|
127
|
+
source: "acme/pack@frontend-design",
|
|
128
|
+
destRoot: dest,
|
|
129
|
+
fetchFn: async (url) => {
|
|
130
|
+
if (url.includes("/git/trees/")) {
|
|
131
|
+
return Response.json({
|
|
132
|
+
tree: [
|
|
133
|
+
{ path: "skills/xlsx/SKILL.md", type: "blob" },
|
|
134
|
+
{ path: "skills/frontend-design/SKILL.md", type: "blob" },
|
|
135
|
+
{ path: "archive/frontend-design/SKILL.md", type: "blob" },
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (url.endsWith("skills/frontend-design/SKILL.md")) {
|
|
140
|
+
return new Response(
|
|
141
|
+
"---\nname: frontend-design\ndescription: ui\n---\n\n# Anthropic\n",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (url.endsWith("archive/frontend-design/SKILL.md")) {
|
|
145
|
+
return new Response("---\nname: frontend-design\ndescription: old\n---\n\n# Old\n");
|
|
146
|
+
}
|
|
147
|
+
if (url.endsWith("skills/xlsx/SKILL.md")) {
|
|
148
|
+
return new Response("---\nname: xlsx\ndescription: sheets\n---\n\n# Xlsx\n");
|
|
149
|
+
}
|
|
150
|
+
return new Response("missing", { status: 404 });
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
expect(result).toEqual({ name: "frontend-design", rel: "frontend-design/SKILL.md" });
|
|
154
|
+
const body = await readFile(join(dest, "frontend-design", "SKILL.md"), "utf8");
|
|
155
|
+
expect(body).toContain("# Anthropic");
|
|
156
|
+
expect(existsSync(join(dest, "xlsx"))).toBe(false);
|
|
157
|
+
expect(existsSync(join(dest, "frontend-design", "xlsx"))).toBe(false);
|
|
116
158
|
} finally {
|
|
117
159
|
await rm(dest, { recursive: true, force: true });
|
|
118
160
|
}
|
|
@@ -129,13 +171,33 @@ describe("bundled catalog", () => {
|
|
|
129
171
|
test("find lists bundled copy skills without a network call", async () => {
|
|
130
172
|
const hits = bundledRegistryHits("copy");
|
|
131
173
|
expect(hits.map((hit) => hit.name)).toContain("copywriting");
|
|
132
|
-
expect(hits.map((hit) => hit.name)).toContain("copy-editor");
|
|
174
|
+
expect(hits.map((hit) => hit.name)).not.toContain("copy-editor");
|
|
133
175
|
const listed = await searchSkills(
|
|
134
176
|
"copy",
|
|
135
177
|
async () => new Response(JSON.stringify({ skills: [] })),
|
|
136
178
|
);
|
|
137
179
|
expect(listed).toContain("bundled@copywriting");
|
|
138
|
-
expect(listed).toContain("bundled@copy-editor");
|
|
180
|
+
expect(listed).not.toContain("bundled@copy-editor");
|
|
181
|
+
const catalog = await searchSkillCatalog(
|
|
182
|
+
"copy",
|
|
183
|
+
async () =>
|
|
184
|
+
new Response(
|
|
185
|
+
JSON.stringify({
|
|
186
|
+
skills: [
|
|
187
|
+
{
|
|
188
|
+
id: "acme/pack/copywriting",
|
|
189
|
+
name: "copywriting",
|
|
190
|
+
source: "acme/pack",
|
|
191
|
+
installs: 3,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
}),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
expect(catalog.some((hit) => hit.source === "bundled" && hit.name === "copywriting")).toBe(
|
|
198
|
+
true,
|
|
199
|
+
);
|
|
200
|
+
expect(catalog.some((hit) => hit.source === "acme/pack")).toBe(true);
|
|
139
201
|
});
|
|
140
202
|
|
|
141
203
|
test("installs the writing pack and removes it", async () => {
|
|
@@ -153,7 +215,6 @@ describe("bundled catalog", () => {
|
|
|
153
215
|
expect.arrayContaining(["copywriting", "copy-rmbc", "copy-harry-dry", "copy-editor"]),
|
|
154
216
|
);
|
|
155
217
|
expect(merged.every((skill) => skill.source === "user")).toBe(true);
|
|
156
|
-
expect(merged.map((skill) => skill.name)).not.toContain("impeccable");
|
|
157
218
|
|
|
158
219
|
const one = installBundledSkills("impeccable", dest);
|
|
159
220
|
expect("error" in one).toBe(false);
|
package/src/skills/registry.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { errorMessage } from "../core/errors.ts";
|
|
4
|
+
import { listBundledSkills, parseSkillMarkdown, SKILL_CATALOG_REF_FILE } from "./loader.ts";
|
|
4
5
|
|
|
5
6
|
/** Bare names that install more than one catalog folder. */
|
|
6
7
|
export const BUNDLED_PACKS: Record<string, readonly string[]> = {
|
|
@@ -8,15 +9,67 @@ export const BUNDLED_PACKS: Record<string, readonly string[]> = {
|
|
|
8
9
|
copywriting: ["copywriting", "copy-rmbc", "copy-harry-dry", "copy-editor"],
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
function catalogPackNames(): string[] {
|
|
13
|
+
return Object.keys(BUNDLED_PACKS).filter((key) => key !== "copy");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Pipeline steps that are not addable on their own. */
|
|
17
|
+
function packStepNames(): Set<string> {
|
|
18
|
+
const steps = new Set<string>();
|
|
19
|
+
for (const pack of catalogPackNames()) {
|
|
20
|
+
for (const member of BUNDLED_PACKS[pack] ?? []) {
|
|
21
|
+
if (member !== pack) steps.add(member);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return steps;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function bundledPackStepNames(): Set<string> {
|
|
28
|
+
return packStepNames();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SEARCH_URL = trimTrailingSlashes(process.env.SKILLS_API_URL?.trim() || "https://skills.sh");
|
|
12
32
|
const MAX_FILES = 40;
|
|
13
33
|
const MAX_FILE_BYTES = 512 * 1024;
|
|
14
34
|
|
|
35
|
+
function trimTrailingSlashes(value: string): string {
|
|
36
|
+
let end = value.length;
|
|
37
|
+
while (end > 0 && value.endsWith("/")) {
|
|
38
|
+
value = value.slice(0, -1);
|
|
39
|
+
end = value.length;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isRepoToken(value: string): boolean {
|
|
45
|
+
return /^[A-Za-z0-9_.-]+$/.test(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseGithubPath(pathname: string): ParsedSkillSource | undefined {
|
|
49
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
50
|
+
const owner = parts[0];
|
|
51
|
+
const repoRaw = parts[1];
|
|
52
|
+
if (!owner || !repoRaw) return undefined;
|
|
53
|
+
const repo = repoRaw.replace(/\.git$/, "");
|
|
54
|
+
const kind = parts[2];
|
|
55
|
+
if (kind !== "tree" && kind !== "blob") return { owner, repo, ref: "HEAD" };
|
|
56
|
+
const ref = parts[3] || "HEAD";
|
|
57
|
+
const rest = parts.slice(4).join("/");
|
|
58
|
+
const path = trimTrailingSlashes(rest.replace(/\/SKILL\.md$/i, ""));
|
|
59
|
+
return {
|
|
60
|
+
owner,
|
|
61
|
+
repo,
|
|
62
|
+
ref,
|
|
63
|
+
...(path ? { path, skill: path.split("/").pop() } : {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
15
67
|
export interface RegistryHit {
|
|
16
68
|
name: string;
|
|
17
69
|
source: string;
|
|
18
70
|
installs?: number;
|
|
19
71
|
id: string;
|
|
72
|
+
description?: string;
|
|
20
73
|
}
|
|
21
74
|
|
|
22
75
|
export interface ParsedSkillSource {
|
|
@@ -29,61 +82,74 @@ export interface ParsedSkillSource {
|
|
|
29
82
|
|
|
30
83
|
export type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
|
|
31
84
|
|
|
32
|
-
|
|
33
|
-
|
|
85
|
+
function parseHttpSkillSource(
|
|
86
|
+
value: string,
|
|
34
87
|
): ParsedSkillSource | { url: string } | { error: string } {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return parseSkillSource(skillsSh[1].replace(/\/+$/, ""));
|
|
88
|
+
let url: URL;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(value);
|
|
91
|
+
} catch {
|
|
92
|
+
return { url: value };
|
|
41
93
|
}
|
|
94
|
+
const host = url.hostname.toLowerCase();
|
|
95
|
+
if (host === "skills.sh" || host === "www.skills.sh") {
|
|
96
|
+
return parseSkillSource(trimTrailingSlashes(url.pathname).replace(/^\//, ""));
|
|
97
|
+
}
|
|
98
|
+
if (host === "github.com" || host === "www.github.com") {
|
|
99
|
+
const parsed = parseGithubPath(url.pathname);
|
|
100
|
+
if (parsed) return parsed;
|
|
101
|
+
}
|
|
102
|
+
if (host === "raw.githubusercontent.com") {
|
|
103
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
104
|
+
const owner = parts[0];
|
|
105
|
+
const repo = parts[1];
|
|
106
|
+
const ref = parts[2] || "HEAD";
|
|
107
|
+
const path = parts
|
|
108
|
+
.slice(3)
|
|
109
|
+
.join("/")
|
|
110
|
+
.replace(/\/SKILL\.md$/i, "");
|
|
111
|
+
if (owner && repo) return { owner, repo, ref, ...(path ? { path } : {}) };
|
|
112
|
+
}
|
|
113
|
+
return { url: value };
|
|
114
|
+
}
|
|
42
115
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ref:
|
|
54
|
-
|
|
55
|
-
...(path ? { skill: path.split("/").pop() } : {}),
|
|
56
|
-
};
|
|
116
|
+
function parseOwnerRepo(value: string): ParsedSkillSource | undefined {
|
|
117
|
+
const at = value.indexOf("@");
|
|
118
|
+
if (at > 0) {
|
|
119
|
+
const left = value.slice(0, at);
|
|
120
|
+
const skill = value.slice(at + 1);
|
|
121
|
+
const slash = left.indexOf("/");
|
|
122
|
+
if (slash > 0) {
|
|
123
|
+
const owner = left.slice(0, slash);
|
|
124
|
+
const repo = left.slice(slash + 1);
|
|
125
|
+
if (isRepoToken(owner) && isRepoToken(repo) && skill) {
|
|
126
|
+
return { owner, repo, skill, ref: "HEAD" };
|
|
127
|
+
}
|
|
57
128
|
}
|
|
58
|
-
const rawGh = /^https?:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)\/(.*)$/i.exec(
|
|
59
|
-
value,
|
|
60
|
-
);
|
|
61
|
-
if (rawGh) {
|
|
62
|
-
const path = (rawGh[4] ?? "").replace(/\/SKILL\.md$/i, "");
|
|
63
|
-
return {
|
|
64
|
-
owner: rawGh[1] ?? "",
|
|
65
|
-
repo: rawGh[2] ?? "",
|
|
66
|
-
ref: rawGh[3] || "HEAD",
|
|
67
|
-
...(path ? { path } : {}),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return { url: value };
|
|
71
129
|
}
|
|
130
|
+
const parts = value.split("/");
|
|
131
|
+
const owner = parts[0];
|
|
132
|
+
const repo = parts[1];
|
|
133
|
+
if (!owner || !repo || !isRepoToken(owner) || !isRepoToken(repo)) return undefined;
|
|
134
|
+
const path = trimTrailingSlashes(parts.slice(2).join("/"));
|
|
135
|
+
return {
|
|
136
|
+
owner,
|
|
137
|
+
repo,
|
|
138
|
+
ref: "HEAD",
|
|
139
|
+
...(path ? { path, skill: path.split("/").pop() } : {}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
72
142
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
owner: repo[1] ?? "",
|
|
82
|
-
repo: repo[2] ?? "",
|
|
83
|
-
ref: "HEAD",
|
|
84
|
-
...(path ? { path, skill: path.split("/").pop() } : {}),
|
|
85
|
-
};
|
|
143
|
+
export function parseSkillSource(
|
|
144
|
+
raw: string,
|
|
145
|
+
): ParsedSkillSource | { url: string } | { error: string } {
|
|
146
|
+
const value = raw.trim();
|
|
147
|
+
if (!value) return { error: "Source is empty." };
|
|
148
|
+
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
149
|
+
return parseHttpSkillSource(value);
|
|
86
150
|
}
|
|
151
|
+
const parsed = parseOwnerRepo(value);
|
|
152
|
+
if (parsed) return parsed;
|
|
87
153
|
return {
|
|
88
154
|
error: "Use a bundled name, owner/repo, owner/repo@skill, or a GitHub / skills.sh URL.",
|
|
89
155
|
};
|
|
@@ -92,9 +158,9 @@ export function parseSkillSource(
|
|
|
92
158
|
export function parseBundledSkillRef(raw: string): string | undefined {
|
|
93
159
|
const value = raw.trim();
|
|
94
160
|
if (!value) return undefined;
|
|
95
|
-
const tagged = /^(?:bundled[@/])([
|
|
161
|
+
const tagged = /^(?:bundled[@/])([a-z0-9_.-]+)$/i.exec(value);
|
|
96
162
|
if (tagged?.[1]) return tagged[1];
|
|
97
|
-
if (
|
|
163
|
+
if (isRepoToken(value) && !value.includes("/")) return value;
|
|
98
164
|
return undefined;
|
|
99
165
|
}
|
|
100
166
|
|
|
@@ -103,6 +169,10 @@ export function bundledInstallNames(name: string): string[] | undefined {
|
|
|
103
169
|
if (!key) return undefined;
|
|
104
170
|
const pack = BUNDLED_PACKS[key];
|
|
105
171
|
if (pack) return [...pack];
|
|
172
|
+
for (const packName of catalogPackNames()) {
|
|
173
|
+
const members = BUNDLED_PACKS[packName] ?? [];
|
|
174
|
+
if (members.some((member) => member === key)) return [...members];
|
|
175
|
+
}
|
|
106
176
|
const found = listBundledSkills().find((skill) => skill.name.toLowerCase() === key);
|
|
107
177
|
return found ? [found.name] : undefined;
|
|
108
178
|
}
|
|
@@ -111,8 +181,10 @@ export function bundledRegistryHits(query: string): RegistryHit[] {
|
|
|
111
181
|
const q = query.trim().toLowerCase();
|
|
112
182
|
const seen = new Set<string>();
|
|
113
183
|
const hits: RegistryHit[] = [];
|
|
114
|
-
|
|
115
|
-
|
|
184
|
+
const catalog = listBundledSkills();
|
|
185
|
+
const byName = new Map(catalog.map((skill) => [skill.name.toLowerCase(), skill]));
|
|
186
|
+
const steps = packStepNames();
|
|
187
|
+
for (const pack of catalogPackNames()) {
|
|
116
188
|
const members = BUNDLED_PACKS[pack] ?? [];
|
|
117
189
|
if (
|
|
118
190
|
q &&
|
|
@@ -123,14 +195,27 @@ export function bundledRegistryHits(query: string): RegistryHit[] {
|
|
|
123
195
|
continue;
|
|
124
196
|
}
|
|
125
197
|
seen.add(pack);
|
|
126
|
-
|
|
198
|
+
const skill = byName.get(pack);
|
|
199
|
+
hits.push({
|
|
200
|
+
id: `bundled/${pack}`,
|
|
201
|
+
name: pack,
|
|
202
|
+
source: "bundled",
|
|
203
|
+
...(skill?.description ? { description: skill.description } : {}),
|
|
204
|
+
});
|
|
127
205
|
}
|
|
128
|
-
for (const skill of
|
|
206
|
+
for (const skill of catalog) {
|
|
129
207
|
const key = skill.name.toLowerCase();
|
|
130
|
-
if (
|
|
131
|
-
if (
|
|
208
|
+
if (steps.has(key) || seen.has(key)) continue;
|
|
209
|
+
if (q && q !== "bundled" && !key.includes(q) && !skill.description.toLowerCase().includes(q)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
132
212
|
seen.add(key);
|
|
133
|
-
hits.push({
|
|
213
|
+
hits.push({
|
|
214
|
+
id: `bundled/${skill.name}`,
|
|
215
|
+
name: skill.name,
|
|
216
|
+
source: "bundled",
|
|
217
|
+
description: skill.description,
|
|
218
|
+
});
|
|
134
219
|
}
|
|
135
220
|
return hits;
|
|
136
221
|
}
|
|
@@ -139,15 +224,53 @@ export function formatBundledHits(hits: RegistryHit[]): string {
|
|
|
139
224
|
return hits.map((hit) => `bundled@${hit.name}`).join("\n");
|
|
140
225
|
}
|
|
141
226
|
|
|
227
|
+
export function skillCatalogRef(hit: RegistryHit): string {
|
|
228
|
+
if (hit.source === "bundled") return `bundled@${hit.name}`;
|
|
229
|
+
return `${hit.source}@${hit.name}`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** True when this loaded skill is the catalog row, not another skill with the same name. */
|
|
233
|
+
export function skillIsCatalogHit(
|
|
234
|
+
skill: { name: string; source: string; catalogRef?: string },
|
|
235
|
+
hit: RegistryHit,
|
|
236
|
+
): boolean {
|
|
237
|
+
const ref = skillCatalogRef(hit);
|
|
238
|
+
if (skill.catalogRef) return skill.catalogRef === ref || skill.catalogRef === hit.id;
|
|
239
|
+
if (skill.source === "user") {
|
|
240
|
+
return (
|
|
241
|
+
skill.name.toLowerCase() === hit.name.toLowerCase() &&
|
|
242
|
+
(hit.source === "user" || hit.source === "project")
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
return skill.name.toLowerCase() === hit.name.toLowerCase();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export async function searchSkillCatalog(
|
|
249
|
+
query: string,
|
|
250
|
+
fetchFn: FetchLike = fetch,
|
|
251
|
+
): Promise<RegistryHit[]> {
|
|
252
|
+
const bundled = bundledRegistryHits(query);
|
|
253
|
+
try {
|
|
254
|
+
const remote = await searchSkillsSh(query, fetchFn, { limit: 16 });
|
|
255
|
+
const seen = new Set(bundled.map((hit) => skillCatalogRef(hit)));
|
|
256
|
+
return [...bundled, ...remote.filter((hit) => !seen.has(skillCatalogRef(hit)))];
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (bundled.length > 0) return bundled;
|
|
259
|
+
throw err;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
142
263
|
export async function searchSkills(query: string, fetchFn: FetchLike = fetch): Promise<string> {
|
|
143
|
-
const bundled = formatBundledHits(bundledRegistryHits(query));
|
|
144
264
|
try {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
265
|
+
const hits = await searchSkillCatalog(query, fetchFn);
|
|
266
|
+
if (hits.length === 0) return "No matches.";
|
|
267
|
+
const bundled = hits.filter((hit) => hit.source === "bundled");
|
|
268
|
+
const remote = hits.filter((hit) => hit.source !== "bundled");
|
|
269
|
+
return [formatBundledHits(bundled), remote.length > 0 ? formatRegistryHits(remote) : ""]
|
|
270
|
+
.filter(Boolean)
|
|
271
|
+
.join("\n");
|
|
148
272
|
} catch (err) {
|
|
149
|
-
|
|
150
|
-
return err instanceof Error ? err.message : String(err);
|
|
273
|
+
return errorMessage(err);
|
|
151
274
|
}
|
|
152
275
|
}
|
|
153
276
|
|
|
@@ -158,10 +281,7 @@ export function installBundledSkills(
|
|
|
158
281
|
const names = bundledInstallNames(name);
|
|
159
282
|
const catalog = listBundledSkills();
|
|
160
283
|
if (!names) {
|
|
161
|
-
const choices =
|
|
162
|
-
...Object.keys(BUNDLED_PACKS).filter((key) => key !== "copy"),
|
|
163
|
-
...catalog.map((skill) => skill.name),
|
|
164
|
-
].filter((value, index, all) => all.indexOf(value) === index);
|
|
284
|
+
const choices = bundledRegistryHits("").map((hit) => hit.name);
|
|
165
285
|
return { error: `No bundled skill ${JSON.stringify(name)}.`, choices };
|
|
166
286
|
}
|
|
167
287
|
const byName = new Map(catalog.map((skill) => [skill.name.toLowerCase(), skill]));
|
|
@@ -179,8 +299,9 @@ export function installBundledSkills(
|
|
|
179
299
|
try {
|
|
180
300
|
rmSync(dest, { recursive: true, force: true });
|
|
181
301
|
cpSync(dirname(skill.path), dest, { recursive: true });
|
|
302
|
+
writeFileSync(join(dest, SKILL_CATALOG_REF_FILE), `bundled@${slug}\n`);
|
|
182
303
|
} catch (err) {
|
|
183
|
-
return { error:
|
|
304
|
+
return { error: errorMessage(err) };
|
|
184
305
|
}
|
|
185
306
|
installed.push(slug);
|
|
186
307
|
}
|
|
@@ -191,10 +312,12 @@ export function installBundledSkills(
|
|
|
191
312
|
export async function searchSkillsSh(
|
|
192
313
|
query: string,
|
|
193
314
|
fetchFn: FetchLike = fetch,
|
|
315
|
+
options: { limit?: number } = {},
|
|
194
316
|
): Promise<RegistryHit[]> {
|
|
195
317
|
const q = query.trim();
|
|
196
318
|
if (!q) return [];
|
|
197
|
-
const
|
|
319
|
+
const limit = String(Math.min(Math.max(options.limit ?? 10, 1), 20));
|
|
320
|
+
const url = `${SEARCH_URL}/api/search?${new URLSearchParams({ q, limit }).toString()}`;
|
|
198
321
|
const res = await fetchFn(url, { headers: { accept: "application/json" } });
|
|
199
322
|
if (!res.ok) throw new Error(`skills.sh search failed (${res.status})`);
|
|
200
323
|
const data = (await res.json()) as {
|
|
@@ -237,11 +360,17 @@ export async function installSkillFromSource(input: {
|
|
|
237
360
|
if ("url" in parsed)
|
|
238
361
|
return installFromDirectUrl(parsed.url, input.destRoot, input.fetchFn ?? fetch);
|
|
239
362
|
const skill = input.skill?.trim() || parsed.skill;
|
|
363
|
+
const catalogRef = input.source.includes("@")
|
|
364
|
+
? input.source
|
|
365
|
+
: skill
|
|
366
|
+
? `${parsed.owner}/${parsed.repo}@${skill}`
|
|
367
|
+
: `${parsed.owner}/${parsed.repo}`;
|
|
240
368
|
return installFromGithub({
|
|
241
369
|
...parsed,
|
|
242
370
|
skill,
|
|
243
371
|
destRoot: input.destRoot,
|
|
244
372
|
fetchFn: input.fetchFn ?? fetch,
|
|
373
|
+
catalogRef,
|
|
245
374
|
});
|
|
246
375
|
}
|
|
247
376
|
|
|
@@ -260,11 +389,31 @@ async function installFromDirectUrl(
|
|
|
260
389
|
return writeSkillDir(destRoot, parsed.name, { "SKILL.md": markdown });
|
|
261
390
|
}
|
|
262
391
|
|
|
392
|
+
function skillFolderName(path: string, repo: string): string {
|
|
393
|
+
return dirname(path) === "." ? repo : (dirname(path).split("/").pop() ?? path);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function skillPathMatches(path: string, wanted: string, input: ParsedSkillSource): boolean {
|
|
397
|
+
const folder = skillFolderName(path, input.repo);
|
|
398
|
+
if (folder.toLowerCase() !== wanted) return false;
|
|
399
|
+
const lower = path.toLowerCase();
|
|
400
|
+
if (input.path) {
|
|
401
|
+
const prefix = input.path.toLowerCase().replace(/\/+$/, "");
|
|
402
|
+
return lower === `${prefix}/skill.md` || lower.startsWith(`${prefix}/`);
|
|
403
|
+
}
|
|
404
|
+
return lower === `${wanted}/skill.md` || lower.endsWith(`/${wanted}/skill.md`);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function pickSkillMd(matches: string[]): string {
|
|
408
|
+
return [...matches].sort((a, b) => a.length - b.length || a.localeCompare(b))[0] ?? "";
|
|
409
|
+
}
|
|
410
|
+
|
|
263
411
|
async function installFromGithub(
|
|
264
412
|
input: ParsedSkillSource & {
|
|
265
413
|
destRoot: string;
|
|
266
414
|
fetchFn: FetchLike;
|
|
267
415
|
skill?: string;
|
|
416
|
+
catalogRef?: string;
|
|
268
417
|
},
|
|
269
418
|
): Promise<{ name: string; rel: string } | { error: string; choices?: string[] }> {
|
|
270
419
|
const treeUrl = `https://api.github.com/repos/${input.owner}/${input.repo}/git/trees/${input.ref}?recursive=1`;
|
|
@@ -287,35 +436,23 @@ async function installFromGithub(
|
|
|
287
436
|
|
|
288
437
|
const wanted = input.skill?.toLowerCase() || input.path?.split("/").pop()?.toLowerCase();
|
|
289
438
|
const matches = wanted
|
|
290
|
-
? skillFiles.filter((path) =>
|
|
291
|
-
const folder = dirname(path) === "." ? input.repo : dirname(path).split("/").pop();
|
|
292
|
-
return (
|
|
293
|
-
folder?.toLowerCase() === wanted ||
|
|
294
|
-
path.toLowerCase() === `${wanted}/skill.md` ||
|
|
295
|
-
path.toLowerCase().endsWith(`/${wanted}/skill.md`) ||
|
|
296
|
-
(input.path && path.toLowerCase().startsWith(`${input.path.toLowerCase()}/`))
|
|
297
|
-
);
|
|
298
|
-
})
|
|
439
|
+
? skillFiles.filter((path) => skillPathMatches(path, wanted, input))
|
|
299
440
|
: skillFiles;
|
|
300
441
|
|
|
301
442
|
if (matches.length === 0) {
|
|
302
443
|
return {
|
|
303
444
|
error: `No skill ${JSON.stringify(input.skill)} in ${input.owner}/${input.repo}.`,
|
|
304
|
-
choices: skillFiles.map((path) =>
|
|
305
|
-
dirname(path) === "." ? input.repo : (dirname(path).split("/").pop() ?? path),
|
|
306
|
-
),
|
|
445
|
+
choices: skillFiles.map((path) => skillFolderName(path, input.repo)),
|
|
307
446
|
};
|
|
308
447
|
}
|
|
309
448
|
if (matches.length > 1 && !wanted) {
|
|
310
449
|
return {
|
|
311
450
|
error: "Repo has several skills. Add @name.",
|
|
312
|
-
choices: matches.map((path) =>
|
|
313
|
-
dirname(path) === "." ? input.repo : (dirname(path).split("/").pop() ?? path),
|
|
314
|
-
),
|
|
451
|
+
choices: matches.map((path) => skillFolderName(path, input.repo)),
|
|
315
452
|
};
|
|
316
453
|
}
|
|
317
454
|
|
|
318
|
-
const skillMd = matches
|
|
455
|
+
const skillMd = pickSkillMd(matches);
|
|
319
456
|
const root = dirname(skillMd) === "." ? "" : dirname(skillMd);
|
|
320
457
|
const files = (data.tree ?? [])
|
|
321
458
|
.map((node) => node.path ?? "")
|
|
@@ -324,6 +461,23 @@ async function installFromGithub(
|
|
|
324
461
|
);
|
|
325
462
|
if (files.length > MAX_FILES) return { error: `Skill has more than ${MAX_FILES} files.` };
|
|
326
463
|
|
|
464
|
+
const downloaded = await downloadSkillFiles(input, files, skillMd, root);
|
|
465
|
+
if ("error" in downloaded) return downloaded;
|
|
466
|
+
const markdown = downloaded.files["SKILL.md"];
|
|
467
|
+
if (!markdown) return { error: "Could not download SKILL.md." };
|
|
468
|
+
const name = parseSkillMarkdown(markdown, "SKILL.md", ".").name;
|
|
469
|
+
const catalogRef =
|
|
470
|
+
input.catalogRef?.trim() ||
|
|
471
|
+
(input.skill ? `${input.owner}/${input.repo}@${input.skill}` : undefined);
|
|
472
|
+
return writeSkillDir(input.destRoot, name, downloaded.files, catalogRef);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async function downloadSkillFiles(
|
|
476
|
+
input: ParsedSkillSource & { fetchFn: FetchLike },
|
|
477
|
+
files: string[],
|
|
478
|
+
skillMd: string,
|
|
479
|
+
root: string,
|
|
480
|
+
): Promise<{ files: Record<string, string> } | { error: string }> {
|
|
327
481
|
const downloaded: Record<string, string> = {};
|
|
328
482
|
for (const path of files) {
|
|
329
483
|
if (!path.endsWith(".md") && !path.endsWith(".txt") && path !== skillMd) continue;
|
|
@@ -336,16 +490,14 @@ async function installFromGithub(
|
|
|
336
490
|
if (!rel || rel.includes("..")) continue;
|
|
337
491
|
downloaded[rel] = text;
|
|
338
492
|
}
|
|
339
|
-
|
|
340
|
-
if (!markdown) return { error: "Could not download SKILL.md." };
|
|
341
|
-
const name = parseSkillMarkdown(markdown, "SKILL.md", ".").name;
|
|
342
|
-
return writeSkillDir(input.destRoot, name, downloaded);
|
|
493
|
+
return { files: downloaded };
|
|
343
494
|
}
|
|
344
495
|
|
|
345
496
|
function writeSkillDir(
|
|
346
497
|
destRoot: string,
|
|
347
498
|
name: string,
|
|
348
499
|
files: Record<string, string>,
|
|
500
|
+
catalogRef?: string,
|
|
349
501
|
): { name: string; rel: string } | { error: string } {
|
|
350
502
|
const slug = name
|
|
351
503
|
.trim()
|
|
@@ -363,8 +515,11 @@ function writeSkillDir(
|
|
|
363
515
|
mkdirSync(dirname(abs), { recursive: true });
|
|
364
516
|
writeFileSync(abs, body, "utf8");
|
|
365
517
|
}
|
|
518
|
+
if (catalogRef?.trim()) {
|
|
519
|
+
writeFileSync(join(dest, SKILL_CATALOG_REF_FILE), `${catalogRef.trim()}\n`);
|
|
520
|
+
}
|
|
366
521
|
} catch (err) {
|
|
367
|
-
return { error:
|
|
522
|
+
return { error: errorMessage(err) };
|
|
368
523
|
}
|
|
369
524
|
return { name: slug, rel: `${slug}/SKILL.md` };
|
|
370
525
|
}
|
|
@@ -381,7 +536,7 @@ export function removeInstalledSkill(
|
|
|
381
536
|
rmSync(dest, { recursive: true, force: true });
|
|
382
537
|
return { removed: true };
|
|
383
538
|
} catch (err) {
|
|
384
|
-
return { removed: false, reason:
|
|
539
|
+
return { removed: false, reason: errorMessage(err) };
|
|
385
540
|
}
|
|
386
541
|
}
|
|
387
542
|
|