@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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -137
  3. package/brand/logo/favicon-agent-bg-16.svg +7 -0
  4. package/brand/logo/favicon-agent-bg-32.svg +7 -0
  5. package/brand/previews/desktop-chat.png +0 -0
  6. package/brand/previews/desktop-commands.png +0 -0
  7. package/brand/previews/desktop-integrations.png +0 -0
  8. package/brand/previews/desktop-skills.png +0 -0
  9. package/package.json +5 -3
  10. package/skills/impeccable/LICENSE +13 -0
  11. package/skills/impeccable/NOTICE +14 -0
  12. package/skills/impeccable/SKILL.md +2 -1
  13. package/src/agent-cwd.ts +51 -0
  14. package/src/cli/agent-cwd.test.ts +65 -0
  15. package/src/cli/main.test.ts +5 -0
  16. package/src/cli/main.ts +282 -201
  17. package/src/cli/picker.test.ts +59 -1
  18. package/src/cli/picker.ts +46 -0
  19. package/src/cli/slash-dispatch.test.ts +116 -7
  20. package/src/cli/slash-dispatch.ts +343 -174
  21. package/src/cli/slash.test.ts +25 -2
  22. package/src/cli/slash.ts +37 -8
  23. package/src/cli/theme.test.ts +7 -0
  24. package/src/cli/theme.ts +6 -6
  25. package/src/cli/tui.tsx +385 -217
  26. package/src/config.ts +1 -1
  27. package/src/core/strands.ts +10 -1
  28. package/src/desktop/bridge.test.ts +56 -1
  29. package/src/desktop/bridge.ts +527 -390
  30. package/src/desktop/uploads.test.ts +57 -0
  31. package/src/desktop/uploads.ts +92 -0
  32. package/src/index.ts +26 -2
  33. package/src/init.test.ts +19 -2
  34. package/src/init.ts +25 -17
  35. package/src/integrations/loopback.test.ts +17 -0
  36. package/src/integrations/loopback.ts +91 -0
  37. package/src/observability/prompts.ts +1 -1
  38. package/src/product.ts +3 -1
  39. package/src/runtime.test.ts +24 -0
  40. package/src/runtime.ts +48 -5
  41. package/src/skills/catalog.test.ts +188 -0
  42. package/src/skills/catalog.ts +279 -0
  43. package/src/skills/disabled.test.ts +27 -0
  44. package/src/skills/disabled.ts +59 -0
  45. package/src/skills/loader.test.ts +31 -0
  46. package/src/skills/loader.ts +31 -4
  47. package/src/skills/registry.test.ts +64 -3
  48. package/src/skills/registry.ts +248 -93
  49. package/src/skills/skill-command.ts +2 -0
@@ -0,0 +1,188 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import {
6
+ browseSkillCatalog,
7
+ buildSkillsPage,
8
+ cachedPopularSkills,
9
+ clearPopularSkillsCache,
10
+ decorateCatalogSkill,
11
+ formatInstallCount,
12
+ POPULAR_SKILL_SEED,
13
+ readPopularSkillsCache,
14
+ refreshPopularSkills,
15
+ skillBlurb,
16
+ writePopularSkillsCache,
17
+ } from "./catalog.ts";
18
+
19
+ afterEach(() => {
20
+ clearPopularSkillsCache();
21
+ });
22
+
23
+ describe("catalog skills", () => {
24
+ test("blurb and install counts stay short", () => {
25
+ expect(skillBlurb("Routes copy work through a pipeline of checks.")).toContain("Routes copy");
26
+ expect(skillBlurb("word ".repeat(80)).endsWith("…")).toBe(true);
27
+ expect(formatInstallCount(891_500)).toBe("891.5K");
28
+ expect(formatInstallCount(3_400_000)).toBe("3.4M");
29
+ expect(formatInstallCount(12)).toBe("12");
30
+ });
31
+
32
+ test("marks project skills as in-project and user skills as removable", () => {
33
+ const loaded = [
34
+ { name: "copywriting", source: "host", description: "Router" },
35
+ {
36
+ name: "frontend-design",
37
+ source: "user",
38
+ catalogRef: "anthropics/skills@frontend-design",
39
+ },
40
+ ];
41
+ const bundled = decorateCatalogSkill(
42
+ { id: "bundled/copywriting", name: "copywriting", source: "bundled", description: "Router" },
43
+ loaded,
44
+ );
45
+ expect(bundled).toMatchObject({
46
+ id: "bundled@copywriting",
47
+ status: "project",
48
+ origin: "bundled",
49
+ });
50
+ const remote = decorateCatalogSkill(
51
+ {
52
+ id: "anthropics/skills/frontend-design",
53
+ name: "frontend-design",
54
+ source: "anthropics/skills",
55
+ installs: 10,
56
+ },
57
+ loaded,
58
+ );
59
+ expect(remote).toMatchObject({
60
+ id: "anthropics/skills@frontend-design",
61
+ status: "user",
62
+ origin: "skills.sh",
63
+ installs: 10,
64
+ });
65
+ expect(
66
+ decorateCatalogSkill(
67
+ { id: "bundled/copywriting", name: "copywriting", source: "bundled" },
68
+ loaded,
69
+ ["copywriting"],
70
+ ).status,
71
+ ).toBe("off");
72
+ });
73
+
74
+ test("marks only the installed frontend-design source as added", () => {
75
+ const loaded = [
76
+ {
77
+ name: "frontend-design",
78
+ source: "user",
79
+ catalogRef: "anthropics/skills@frontend-design",
80
+ },
81
+ ];
82
+ const anthropics = decorateCatalogSkill(
83
+ {
84
+ id: "anthropics/skills/frontend-design",
85
+ name: "frontend-design",
86
+ source: "anthropics/skills",
87
+ },
88
+ loaded,
89
+ );
90
+ const other = decorateCatalogSkill(
91
+ {
92
+ id: "pbakaus/impeccable/frontend-design",
93
+ name: "frontend-design",
94
+ source: "pbakaus/impeccable",
95
+ },
96
+ loaded,
97
+ );
98
+ expect(anthropics.status).toBe("user");
99
+ expect(other.status).toBe("off");
100
+ });
101
+
102
+ test("page lists bundled skills and extra user skills separately", () => {
103
+ const page = buildSkillsPage(
104
+ [
105
+ { name: "copywriting", source: "host" },
106
+ { name: "copy-rmbc", source: "host" },
107
+ { name: "my-notes", source: "user" },
108
+ ],
109
+ POPULAR_SKILL_SEED,
110
+ );
111
+ expect(
112
+ page.bundled.some((item) => item.name === "copywriting" && item.status === "project"),
113
+ ).toBe(true);
114
+ expect(page.loaded.some((item) => item.name === "my-notes" && item.status === "user")).toBe(
115
+ true,
116
+ );
117
+ expect(page.popular.some((item) => item.name === "copywriting")).toBe(false);
118
+ expect(page.bundled.some((item) => item.name === "copy-editor")).toBe(false);
119
+ expect(page.bundled.some((item) => item.name === "impeccable")).toBe(true);
120
+ expect(page.loaded.some((item) => item.name === "copy-rmbc")).toBe(false);
121
+ });
122
+
123
+ test("popular cache round-trips and refresh uses a bounded search", async () => {
124
+ const home = await mkdtemp(join(tmpdir(), "harness-popular-"));
125
+ const prev = process.env.HARNESS_HOME;
126
+ process.env.HARNESS_HOME = home;
127
+ try {
128
+ writePopularSkillsCache(
129
+ [{ id: "acme/pack/hello", name: "hello", source: "acme/pack", installs: 9 }],
130
+ process.env,
131
+ );
132
+ const cached = readPopularSkillsCache(process.env);
133
+ expect(cached.stale).toBe(false);
134
+ expect(cached.hits[0]?.name).toBe("hello");
135
+ expect(cachedPopularSkills(process.env)[0]?.name).toBe("hello");
136
+
137
+ let called = 0;
138
+ const hits = await refreshPopularSkills(async (url) => {
139
+ called += 1;
140
+ expect(url).toContain("q=frontend");
141
+ expect(url).toContain("limit=16");
142
+ return Response.json({
143
+ skills: [
144
+ {
145
+ id: "acme/pack/hello",
146
+ name: "hello",
147
+ source: "acme/pack",
148
+ installs: 99,
149
+ },
150
+ ],
151
+ });
152
+ }, process.env);
153
+ expect(called).toBe(1);
154
+ expect(hits[0]).toMatchObject({ name: "hello", installs: 99 });
155
+ } finally {
156
+ if (prev === undefined) delete process.env.HARNESS_HOME;
157
+ else process.env.HARNESS_HOME = prev;
158
+ await rm(home, { recursive: true, force: true });
159
+ }
160
+ });
161
+
162
+ test("browse lists bundled skills then cached popular skills.sh hits", async () => {
163
+ const home = await mkdtemp(join(tmpdir(), "harness-browse-"));
164
+ const prev = process.env.HARNESS_HOME;
165
+ process.env.HARNESS_HOME = home;
166
+ try {
167
+ writePopularSkillsCache(
168
+ [
169
+ { id: "acme/pack/hello", name: "hello", source: "acme/pack", installs: 9 },
170
+ { id: "pbakaus/impeccable/impeccable", name: "impeccable", source: "pbakaus/impeccable" },
171
+ ],
172
+ process.env,
173
+ );
174
+ const hits = await browseSkillCatalog(async () => {
175
+ throw new Error("should use the fresh cache");
176
+ }, process.env);
177
+ expect(hits.some((hit) => hit.name === "copywriting" && hit.source === "bundled")).toBe(true);
178
+ expect(hits.some((hit) => hit.name === "impeccable" && hit.source === "bundled")).toBe(true);
179
+ expect(hits.some((hit) => hit.name === "hello")).toBe(true);
180
+ expect(hits.filter((hit) => hit.name === "impeccable")).toHaveLength(1);
181
+ expect(hits[0]?.source).toBe("bundled");
182
+ } finally {
183
+ if (prev === undefined) delete process.env.HARNESS_HOME;
184
+ else process.env.HARNESS_HOME = prev;
185
+ await rm(home, { recursive: true, force: true });
186
+ }
187
+ });
188
+ });
@@ -0,0 +1,279 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { harnessHome } from "../desktop/secrets.ts";
4
+ import {
5
+ bundledPackStepNames,
6
+ bundledRegistryHits,
7
+ type FetchLike,
8
+ type RegistryHit,
9
+ searchSkillsSh,
10
+ skillCatalogRef,
11
+ skillIsCatalogHit,
12
+ } from "./registry.ts";
13
+
14
+ export const POPULAR_TTL_MS = 24 * 60 * 60 * 1000;
15
+ const POPULAR_LIMIT = 16;
16
+ const POPULAR_QUERY = "frontend";
17
+
18
+ /** Shown before the first skills.sh fetch, and if the network call fails. */
19
+ export const POPULAR_SKILL_SEED: RegistryHit[] = [
20
+ { id: "anthropics/skills/frontend-design", name: "frontend-design", source: "anthropics/skills" },
21
+ {
22
+ id: "vercel-labs/agent-skills/vercel-react-best-practices",
23
+ name: "vercel-react-best-practices",
24
+ source: "vercel-labs/agent-skills",
25
+ },
26
+ {
27
+ id: "vercel-labs/agent-skills/web-design-guidelines",
28
+ name: "web-design-guidelines",
29
+ source: "vercel-labs/agent-skills",
30
+ },
31
+ {
32
+ id: "vercel-labs/agent-browser/agent-browser",
33
+ name: "agent-browser",
34
+ source: "vercel-labs/agent-browser",
35
+ },
36
+ { id: "obra/superpowers/brainstorming", name: "brainstorming", source: "obra/superpowers" },
37
+ {
38
+ id: "obra/superpowers/test-driven-development",
39
+ name: "test-driven-development",
40
+ source: "obra/superpowers",
41
+ },
42
+ { id: "pbakaus/impeccable/impeccable", name: "impeccable", source: "pbakaus/impeccable" },
43
+ { id: "anthropics/skills/xlsx", name: "xlsx", source: "anthropics/skills" },
44
+ { id: "supabase/agent-skills/supabase", name: "supabase", source: "supabase/agent-skills" },
45
+ {
46
+ id: "nextlevelbuilder/ui-ux-pro-max-skill/ui-ux-pro-max",
47
+ name: "ui-ux-pro-max",
48
+ source: "nextlevelbuilder/ui-ux-pro-max-skill",
49
+ },
50
+ ];
51
+
52
+ export type SkillInstallStatus = "off" | "user" | "project";
53
+
54
+ export interface CatalogSkill {
55
+ id: string;
56
+ name: string;
57
+ description: string;
58
+ origin: "bundled" | "skills.sh";
59
+ source: string;
60
+ installs?: number;
61
+ status: SkillInstallStatus;
62
+ }
63
+
64
+ export interface SkillsPage {
65
+ bundled: CatalogSkill[];
66
+ popular: CatalogSkill[];
67
+ loaded: CatalogSkill[];
68
+ }
69
+
70
+ export function skillBlurb(text: string, max = 140): string {
71
+ const one = text.replace(/\s+/g, " ").trim();
72
+ if (!one) return "";
73
+ if (one.length <= max) return one;
74
+ const clipped = one.slice(0, max - 1);
75
+ const cut = clipped.lastIndexOf(" ");
76
+ return `${(cut > 80 ? clipped.slice(0, cut) : clipped).trimEnd()}…`;
77
+ }
78
+
79
+ export function formatInstallCount(count: number): string {
80
+ if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
81
+ if (count >= 1_000) return `${(count / 1_000).toFixed(1).replace(/\.0$/, "")}K`;
82
+ return String(count);
83
+ }
84
+
85
+ export function bundledSkillHits(query = ""): RegistryHit[] {
86
+ return bundledRegistryHits(query);
87
+ }
88
+
89
+ export function withDisabledCatalogSkills(
90
+ loaded: Array<{ name: string; source: string; description?: string; catalogRef?: string }>,
91
+ disabled: Iterable<string>,
92
+ ): Array<{ name: string; source: string; description?: string; catalogRef?: string }> {
93
+ const seen = new Set(loaded.map((skill) => skill.name.toLowerCase()));
94
+ const extra = [...disabled]
95
+ .map((name) => name.trim().toLowerCase())
96
+ .filter((name) => name && !seen.has(name))
97
+ .map((name) => ({ name, source: "host" as const }));
98
+ return extra.length === 0 ? loaded : [...loaded, ...extra];
99
+ }
100
+
101
+ function catalogStatus(
102
+ current: { source: string } | undefined,
103
+ disabled: boolean,
104
+ ): "user" | "project" | "off" {
105
+ if (disabled || !current) return "off";
106
+ if (current.source === "user") return "user";
107
+ return "project";
108
+ }
109
+
110
+ export function decorateCatalogSkill(
111
+ hit: RegistryHit,
112
+ loaded: Array<{ name: string; source: string; description?: string; catalogRef?: string }>,
113
+ disabled: Iterable<string> = [],
114
+ ): CatalogSkill {
115
+ const current = loaded.find((skill) => skillIsCatalogHit(skill, hit));
116
+ const off = new Set([...disabled].map((name) => name.toLowerCase()));
117
+ return {
118
+ id: skillCatalogRef(hit),
119
+ name: hit.name,
120
+ description: skillBlurb(hit.description || current?.description || ""),
121
+ origin: hit.source === "bundled" ? "bundled" : "skills.sh",
122
+ source: hit.source === "host" ? "project" : hit.source,
123
+ ...(typeof hit.installs === "number" ? { installs: hit.installs } : {}),
124
+ status: catalogStatus(current, off.has(hit.name.toLowerCase())),
125
+ };
126
+ }
127
+
128
+ export function buildSkillsPage(
129
+ loaded: Array<{ name: string; source: string; description?: string; catalogRef?: string }>,
130
+ popularHits: RegistryHit[],
131
+ disabled: Iterable<string> = [],
132
+ ): SkillsPage {
133
+ const bundled = bundledSkillHits().map((hit) => decorateCatalogSkill(hit, loaded, disabled));
134
+ const bundledNames = new Set(bundled.map((item) => item.name.toLowerCase()));
135
+ const steps = bundledPackStepNames();
136
+ const popular = popularHits
137
+ .filter((hit) => hit.source !== "bundled" && !bundledNames.has(hit.name.toLowerCase()))
138
+ .map((hit) => decorateCatalogSkill(hit, loaded, disabled));
139
+ const seen = new Set([...bundledNames, ...popular.map((item) => item.name.toLowerCase())]);
140
+ const extra = loaded
141
+ .filter((skill) => {
142
+ const key = skill.name.toLowerCase();
143
+ if (steps.has(key)) return false;
144
+ return !seen.has(key);
145
+ })
146
+ .map((skill) =>
147
+ decorateCatalogSkill(
148
+ {
149
+ id: skill.catalogRef ?? `${skill.source}/${skill.name}`,
150
+ name: skill.name,
151
+ source: skill.source === "user" ? "user" : "project",
152
+ description: skill.description ?? "",
153
+ },
154
+ loaded,
155
+ disabled,
156
+ ),
157
+ );
158
+ return { bundled, popular, loaded: extra };
159
+ }
160
+
161
+ let memory: { home: string; expires: number; hits: RegistryHit[] } | null = null;
162
+
163
+ export function clearPopularSkillsCache(): void {
164
+ memory = null;
165
+ }
166
+
167
+ function popularPath(env: Record<string, string | undefined> = process.env): string {
168
+ return resolve(harnessHome(env), "skills-sh-popular.json");
169
+ }
170
+
171
+ function cacheHome(env: Record<string, string | undefined> = process.env): string {
172
+ return harnessHome(env);
173
+ }
174
+
175
+ function parseHitRow(row: unknown): RegistryHit | undefined {
176
+ if (!row || typeof row !== "object") return undefined;
177
+ const item = row as Record<string, unknown>;
178
+ const name = typeof item.name === "string" ? item.name.trim() : "";
179
+ const source = typeof item.source === "string" ? item.source.trim() : "";
180
+ const id = typeof item.id === "string" ? item.id.trim() : "";
181
+ if (!name || !source) return undefined;
182
+ return {
183
+ id: id || `${source}/${name}`,
184
+ name,
185
+ source,
186
+ ...(typeof item.installs === "number" ? { installs: item.installs } : {}),
187
+ ...(typeof item.description === "string" ? { description: item.description } : {}),
188
+ };
189
+ }
190
+
191
+ function parseHits(raw: unknown): RegistryHit[] | undefined {
192
+ if (!raw || typeof raw !== "object") return undefined;
193
+ const hits = (raw as { hits?: unknown }).hits;
194
+ if (!Array.isArray(hits)) return undefined;
195
+ const out: RegistryHit[] = [];
196
+ for (const row of hits) {
197
+ const hit = parseHitRow(row);
198
+ if (hit) out.push(hit);
199
+ }
200
+ return out;
201
+ }
202
+
203
+ export function readPopularSkillsCache(
204
+ env: Record<string, string | undefined> = process.env,
205
+ now = Date.now(),
206
+ ): { hits: RegistryHit[]; stale: boolean } {
207
+ if (memory?.hits.length && memory.home === cacheHome(env)) {
208
+ return { hits: memory.hits, stale: memory.expires <= now };
209
+ }
210
+ if (!existsSync(popularPath(env))) {
211
+ return { hits: POPULAR_SKILL_SEED, stale: true };
212
+ }
213
+ try {
214
+ const parsed = JSON.parse(readFileSync(popularPath(env), "utf8")) as {
215
+ expires?: number;
216
+ hits?: unknown;
217
+ };
218
+ const hits = parseHits(parsed);
219
+ if (!hits || hits.length === 0) return { hits: POPULAR_SKILL_SEED, stale: true };
220
+ const expires = typeof parsed.expires === "number" ? parsed.expires : 0;
221
+ memory = { home: cacheHome(env), expires, hits };
222
+ return { hits, stale: expires <= now };
223
+ } catch {
224
+ return { hits: POPULAR_SKILL_SEED, stale: true };
225
+ }
226
+ }
227
+
228
+ export function writePopularSkillsCache(
229
+ hits: RegistryHit[],
230
+ env: Record<string, string | undefined> = process.env,
231
+ now = Date.now(),
232
+ ): void {
233
+ const expires = now + POPULAR_TTL_MS;
234
+ memory = { home: cacheHome(env), expires, hits };
235
+ const path = popularPath(env);
236
+ mkdirSync(resolve(path, ".."), { recursive: true });
237
+ writeFileSync(path, `${JSON.stringify({ expires, hits }, null, "\t")}\n`);
238
+ }
239
+
240
+ export function cachedPopularSkills(
241
+ env: Record<string, string | undefined> = process.env,
242
+ ): RegistryHit[] {
243
+ return readPopularSkillsCache(env).hits;
244
+ }
245
+
246
+ export async function browseSkillCatalog(
247
+ fetchFn: FetchLike = fetch,
248
+ env: Record<string, string | undefined> = process.env,
249
+ ): Promise<RegistryHit[]> {
250
+ const bundled = bundledRegistryHits("");
251
+ const cached = readPopularSkillsCache(env);
252
+ const popular = cached.stale ? await refreshPopularSkills(fetchFn, env) : cached.hits;
253
+ const seen = new Set(bundled.map((hit) => hit.name.toLowerCase()));
254
+ return [
255
+ ...bundled,
256
+ ...popular.filter((hit) => hit.source !== "bundled" && !seen.has(hit.name.toLowerCase())),
257
+ ];
258
+ }
259
+
260
+ export async function refreshPopularSkills(
261
+ fetchFn: FetchLike = fetch,
262
+ env: Record<string, string | undefined> = process.env,
263
+ ): Promise<RegistryHit[]> {
264
+ try {
265
+ const remote = await searchSkillsSh(POPULAR_QUERY, fetchFn, { limit: POPULAR_LIMIT });
266
+ const byId = new Map<string, RegistryHit>();
267
+ for (const hit of [...remote, ...POPULAR_SKILL_SEED]) {
268
+ const key = skillCatalogRef(hit);
269
+ if (!byId.has(key)) byId.set(key, hit);
270
+ }
271
+ const hits = [...byId.values()]
272
+ .sort((a, b) => (b.installs ?? 0) - (a.installs ?? 0))
273
+ .slice(0, POPULAR_LIMIT);
274
+ if (hits.length > 0) writePopularSkillsCache(hits, env);
275
+ return hits.length > 0 ? hits : cachedPopularSkills(env);
276
+ } catch {
277
+ return cachedPopularSkills(env);
278
+ }
279
+ }
@@ -0,0 +1,27 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import {
6
+ disableSkills,
7
+ enableSkills,
8
+ isSkillDisabled,
9
+ readDisabledSkillNames,
10
+ } from "./disabled.ts";
11
+
12
+ describe("disabled skills", () => {
13
+ test("disabling copywriting also hides the pipeline steps", async () => {
14
+ const cwd = await mkdtemp(join(tmpdir(), "harness-disabled-"));
15
+ try {
16
+ expect(disableSkills(cwd, "copywriting")).toContain("copy-editor");
17
+ expect(isSkillDisabled(cwd, "copywriting")).toBe(true);
18
+ expect(isSkillDisabled(cwd, "copy-rmbc")).toBe(true);
19
+ expect(readDisabledSkillNames(cwd).has("impeccable")).toBe(false);
20
+ enableSkills(cwd, "copywriting");
21
+ expect(isSkillDisabled(cwd, "copywriting")).toBe(false);
22
+ expect(isSkillDisabled(cwd, "copy-editor")).toBe(false);
23
+ } finally {
24
+ await rm(cwd, { recursive: true, force: true });
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,59 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { bundledInstallNames } from "./registry.ts";
4
+
5
+ export function disabledSkillsPath(cwd: string): string {
6
+ return resolve(cwd, ".harness", "disabled-skills.json");
7
+ }
8
+
9
+ function expandSkillNames(name: string): string[] {
10
+ const key = name.trim().toLowerCase();
11
+ if (!key) return [];
12
+ return (bundledInstallNames(key) ?? [key]).map((entry) => entry.toLowerCase());
13
+ }
14
+
15
+ export function readDisabledSkillNames(cwd: string): Set<string> {
16
+ const path = disabledSkillsPath(cwd);
17
+ if (!existsSync(path)) return new Set();
18
+ try {
19
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as { names?: unknown };
20
+ if (!Array.isArray(parsed.names)) return new Set();
21
+ return new Set(
22
+ parsed.names
23
+ .filter((entry): entry is string => typeof entry === "string")
24
+ .map((entry) => entry.trim().toLowerCase())
25
+ .filter(Boolean),
26
+ );
27
+ } catch {
28
+ return new Set();
29
+ }
30
+ }
31
+
32
+ function writeDisabledSkillNames(cwd: string, names: Set<string>): void {
33
+ const path = disabledSkillsPath(cwd);
34
+ mkdirSync(resolve(path, ".."), { recursive: true });
35
+ const list = [...names].sort();
36
+ writeFileSync(path, `${JSON.stringify({ names: list }, null, "\t")}\n`);
37
+ }
38
+
39
+ export function isSkillDisabled(cwd: string, name: string): boolean {
40
+ return readDisabledSkillNames(cwd).has(name.trim().toLowerCase());
41
+ }
42
+
43
+ export function disableSkills(cwd: string, name: string): string[] {
44
+ const added = expandSkillNames(name);
45
+ if (added.length === 0) return [];
46
+ const names = readDisabledSkillNames(cwd);
47
+ for (const entry of added) names.add(entry);
48
+ writeDisabledSkillNames(cwd, names);
49
+ return added;
50
+ }
51
+
52
+ export function enableSkills(cwd: string, name: string): string[] {
53
+ const removed = expandSkillNames(name);
54
+ if (removed.length === 0) return [];
55
+ const names = readDisabledSkillNames(cwd);
56
+ for (const entry of removed) names.delete(entry);
57
+ writeDisabledSkillNames(cwd, names);
58
+ return removed;
59
+ }
@@ -5,10 +5,12 @@ import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import {
7
7
  bundledSkillsDir,
8
+ isBundledCatalogDir,
8
9
  loadMergedSkills,
9
10
  loadSkills,
10
11
  mergeSkills,
11
12
  parseSkillMarkdown,
13
+ resolveHostSkillDirs,
12
14
  skillCatalogPrompt,
13
15
  stripFrontmatter,
14
16
  } from "../skills/loader.ts";
@@ -41,6 +43,25 @@ Body here.
41
43
  expect(skills[0]?.body).toContain("short greeting");
42
44
  });
43
45
 
46
+ test("does not load nested SKILL.md files as extra skills", async () => {
47
+ const cwd = await mkdtemp(join(tmpdir(), "harness-nested-skill-"));
48
+ try {
49
+ mkdirSync(join(cwd, "frontend-design", "xlsx"), { recursive: true });
50
+ writeFileSync(
51
+ join(cwd, "frontend-design", "SKILL.md"),
52
+ "---\nname: frontend-design\n---\n\n# UI\n",
53
+ );
54
+ writeFileSync(
55
+ join(cwd, "frontend-design", "xlsx", "SKILL.md"),
56
+ "---\nname: xlsx\n---\n\n# Sheets\n",
57
+ );
58
+ const skills = loadSkills(cwd);
59
+ expect(skills.map((skill) => skill.name)).toEqual(["frontend-design"]);
60
+ } finally {
61
+ await rm(cwd, { recursive: true, force: true });
62
+ }
63
+ });
64
+
44
65
  test("parseSkillMarkdown falls back to folder name", () => {
45
66
  const skill = parseSkillMarkdown("# bare", "/tmp/skills/foo/SKILL.md", "/tmp/skills");
46
67
  expect(skill.name).toBe("foo");
@@ -71,6 +92,16 @@ Body here.
71
92
  }
72
93
  });
73
94
 
95
+ test("skips the package catalog when cwd/skills is that folder", () => {
96
+ const root = join(import.meta.dir, "../..");
97
+ expect(isBundledCatalogDir(bundledSkillsDir())).toBe(true);
98
+ const dirs = resolveHostSkillDirs(root, "skills");
99
+ expect(dirs.some((dir) => isBundledCatalogDir(dir))).toBe(false);
100
+ const merged = loadMergedSkills(dirs);
101
+ expect(merged.map((skill) => skill.name)).not.toContain("copywriting");
102
+ expect(merged.map((skill) => skill.name)).not.toContain("impeccable");
103
+ });
104
+
74
105
  test("host skills override user skills of the same name", async () => {
75
106
  const cwd = await mkdtemp(join(tmpdir(), "harness-sk-"));
76
107
  try {
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync } from "node:fs";
1
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
2
2
  import { dirname, join, relative, resolve } from "node:path";
3
3
  import { Glob } from "bun";
4
4
  import { shouldSkipDir } from "../tools/paths.ts";
@@ -10,6 +10,8 @@ export interface Skill {
10
10
  path: string;
11
11
  relPath: string;
12
12
  source: "bundled" | "host" | "user";
13
+ /** Catalog id this copy was installed from, e.g. anthropics/skills@frontend-design. */
14
+ catalogRef?: string;
13
15
  }
14
16
 
15
17
  export function stripFrontmatter(md: string): { attrs: Record<string, string>; body: string } {
@@ -62,6 +64,8 @@ function parseFrontmatter(raw: string): Record<string, string> {
62
64
  return attrs;
63
65
  }
64
66
 
67
+ export const SKILL_CATALOG_REF_FILE = ".catalog-ref";
68
+
65
69
  export function parseSkillMarkdown(md: string, absPath: string, root: string): Skill {
66
70
  const { attrs, body } = stripFrontmatter(md);
67
71
  const name = attrs.name?.trim() || dirname(absPath).split("/").pop() || "skill";
@@ -80,6 +84,19 @@ export function bundledSkillsDir(): string {
80
84
  return join(import.meta.dir, "..", "..", "skills");
81
85
  }
82
86
 
87
+ /** True when `abs` is the package catalog, not a host project overlay. */
88
+ export function isBundledCatalogDir(abs: string): boolean {
89
+ const bundled = bundledSkillsDir();
90
+ try {
91
+ if (existsSync(abs) && existsSync(bundled)) {
92
+ return realpathSync(abs) === realpathSync(bundled);
93
+ }
94
+ } catch {
95
+ /* compare resolved paths below */
96
+ }
97
+ return resolve(abs) === resolve(bundled);
98
+ }
99
+
83
100
  /** Later writers win. Used to overlay host skills on a catalog or user store. */
84
101
  export function mergeSkills(first: Skill[], host: Skill[]): Skill[] {
85
102
  const byName = new Map<string, Skill>();
@@ -101,11 +118,14 @@ export function resolveHostSkillDirs(cwd: string, configured: string): string[]
101
118
  const out: string[] = [];
102
119
  for (const rel of [configured, ...CONVENTIONAL_HOST_SKILL_DIRS]) {
103
120
  const abs = resolve(cwd, rel);
104
- if (seen.has(abs)) continue;
121
+ if (seen.has(abs) || isBundledCatalogDir(abs)) continue;
105
122
  seen.add(abs);
106
123
  if (existsSync(abs)) out.push(abs);
107
124
  }
108
- if (out.length === 0) out.push(resolve(cwd, configured));
125
+ if (out.length === 0) {
126
+ const fallback = resolve(cwd, configured);
127
+ if (!isBundledCatalogDir(fallback)) out.push(fallback);
128
+ }
109
129
  return out;
110
130
  }
111
131
 
@@ -131,10 +151,17 @@ export function loadSkills(skillsDir: string): Skill[] {
131
151
  const glob = new Glob("**/SKILL.md");
132
152
  for (const rel of glob.scanSync({ cwd: skillsDir, onlyFiles: true, dot: false })) {
133
153
  const parts = rel.split("/");
154
+ if (parts.length !== 2 || parts[1] !== "SKILL.md") continue;
134
155
  if (parts.some((p) => shouldSkipDir(p))) continue;
135
156
  const abs = join(skillsDir, rel);
136
157
  const md = readFileSync(abs, "utf8");
137
- skills.push(parseSkillMarkdown(md, abs, skillsDir));
158
+ const skill = parseSkillMarkdown(md, abs, skillsDir);
159
+ const catalogRefPath = join(dirname(abs), SKILL_CATALOG_REF_FILE);
160
+ if (existsSync(catalogRefPath)) {
161
+ const catalogRef = readFileSync(catalogRefPath, "utf8").trim();
162
+ if (catalogRef) skill.catalogRef = catalogRef;
163
+ }
164
+ skills.push(skill);
138
165
  }
139
166
  } catch {
140
167
  return [];