@useavalon/caelence-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +201 -0
  2. package/bin/harness.ts +10 -0
  3. package/package.json +75 -0
  4. package/skills/copy-editor/SKILL.md +74 -0
  5. package/skills/copy-editor/references/anti-slop.md +62 -0
  6. package/skills/copy-editor/references/ui-states.md +46 -0
  7. package/skills/copy-editor/scripts/lint-copy.py +78 -0
  8. package/skills/copy-harry-dry/SKILL.md +120 -0
  9. package/skills/copy-rmbc/SKILL.md +97 -0
  10. package/skills/copywriting/SKILL.md +73 -0
  11. package/skills/impeccable/SKILL.md +133 -0
  12. package/skills/impeccable/references/visual-slop.md +36 -0
  13. package/src/cli/main.test.ts +36 -0
  14. package/src/cli/main.ts +384 -0
  15. package/src/cli/media-models.ts +82 -0
  16. package/src/cli/models.ts +43 -0
  17. package/src/cli/openrouter-live.test.ts +35 -0
  18. package/src/cli/openrouter-live.ts +72 -0
  19. package/src/cli/openrouter-modality.test.ts +25 -0
  20. package/src/cli/openrouter-modality.ts +83 -0
  21. package/src/cli/picker.test.ts +53 -0
  22. package/src/cli/picker.ts +48 -0
  23. package/src/cli/plain-text.ts +15 -0
  24. package/src/cli/slash-dispatch.test.ts +213 -0
  25. package/src/cli/slash-dispatch.ts +298 -0
  26. package/src/cli/slash.test.ts +113 -0
  27. package/src/cli/slash.ts +119 -0
  28. package/src/cli/theme.test.ts +10 -0
  29. package/src/cli/theme.ts +44 -0
  30. package/src/cli/tui-layout.test.ts +33 -0
  31. package/src/cli/tui-layout.ts +33 -0
  32. package/src/cli/tui-screen.test.ts +33 -0
  33. package/src/cli/tui-screen.ts +13 -0
  34. package/src/cli/tui.tsx +735 -0
  35. package/src/config.ts +86 -0
  36. package/src/core/approval.test.ts +60 -0
  37. package/src/core/approval.ts +83 -0
  38. package/src/core/auto-router.test.ts +31 -0
  39. package/src/core/auto-router.ts +66 -0
  40. package/src/core/errors.ts +67 -0
  41. package/src/core/events.ts +85 -0
  42. package/src/core/hooks.test.ts +66 -0
  43. package/src/core/hooks.ts +94 -0
  44. package/src/core/ids.ts +6 -0
  45. package/src/core/instructions.test.ts +49 -0
  46. package/src/core/instructions.ts +44 -0
  47. package/src/core/logger.ts +45 -0
  48. package/src/core/mcp.ts +191 -0
  49. package/src/core/mode.test.ts +63 -0
  50. package/src/core/mode.ts +60 -0
  51. package/src/core/run-turn.test.ts +339 -0
  52. package/src/core/run-turn.ts +487 -0
  53. package/src/core/session.test.ts +203 -0
  54. package/src/core/session.ts +349 -0
  55. package/src/core/stdio-mcp.ts +143 -0
  56. package/src/core/strands.ts +262 -0
  57. package/src/core/usage.test.ts +69 -0
  58. package/src/core/usage.ts +171 -0
  59. package/src/desktop/bridge.test.ts +331 -0
  60. package/src/desktop/bridge.ts +729 -0
  61. package/src/desktop/open-local.test.ts +40 -0
  62. package/src/desktop/open-local.ts +52 -0
  63. package/src/desktop/preview-cache.test.ts +36 -0
  64. package/src/desktop/preview-cache.ts +63 -0
  65. package/src/desktop/secrets.test.ts +44 -0
  66. package/src/desktop/secrets.ts +60 -0
  67. package/src/evals/runner.test.ts +43 -0
  68. package/src/evals/runner.ts +225 -0
  69. package/src/index.ts +132 -0
  70. package/src/init.test.ts +54 -0
  71. package/src/init.ts +117 -0
  72. package/src/integrations/catalog-data.json +424 -0
  73. package/src/integrations/catalog.ts +81 -0
  74. package/src/integrations/connect.ts +231 -0
  75. package/src/integrations/integrations.test.ts +329 -0
  76. package/src/integrations/marks/airtable.svg +1 -0
  77. package/src/integrations/marks/algolia-mcp.svg +1 -0
  78. package/src/integrations/marks/canva.jpg +0 -0
  79. package/src/integrations/marks/cloudflare-mcp.svg +1 -0
  80. package/src/integrations/marks/contentful-mcp.svg +1 -0
  81. package/src/integrations/marks/craft.png +0 -0
  82. package/src/integrations/marks/dinero.png +0 -0
  83. package/src/integrations/marks/figma.svg +1 -0
  84. package/src/integrations/marks/gitlab.svg +1 -0
  85. package/src/integrations/marks/google-calendar.svg +1 -0
  86. package/src/integrations/marks/google-docs.svg +1 -0
  87. package/src/integrations/marks/google-drive.svg +1 -0
  88. package/src/integrations/marks/google-gmail.svg +1 -0
  89. package/src/integrations/marks/google-sheets.svg +1 -0
  90. package/src/integrations/marks/google-slides.svg +1 -0
  91. package/src/integrations/marks/granola.png +0 -0
  92. package/src/integrations/marks/jira.svg +1 -0
  93. package/src/integrations/marks/linear.svg +1 -0
  94. package/src/integrations/marks/microsoft-365.svg +7 -0
  95. package/src/integrations/marks/miro.svg +1 -0
  96. package/src/integrations/marks/mixpanel-mcp.svg +1 -0
  97. package/src/integrations/marks/monday.png +0 -0
  98. package/src/integrations/marks/mux-mcp.png +0 -0
  99. package/src/integrations/marks/neon-mcp.svg +1 -0
  100. package/src/integrations/marks/notion.svg +1 -0
  101. package/src/integrations/marks/paddle-mcp.svg +1 -0
  102. package/src/integrations/marks/posthog-mcp.svg +1 -0
  103. package/src/integrations/marks/prismic-mcp.svg +1 -0
  104. package/src/integrations/marks/replicate-mcp.svg +1 -0
  105. package/src/integrations/marks/resend-mcp.svg +1 -0
  106. package/src/integrations/marks/sanity-mcp.svg +1 -0
  107. package/src/integrations/marks/sceneplane.png +0 -0
  108. package/src/integrations/marks/sentry-mcp.svg +1 -0
  109. package/src/integrations/marks/stripe-mcp.svg +1 -0
  110. package/src/integrations/marks/supabase-mcp.svg +1 -0
  111. package/src/integrations/marks/upstash-mcp.svg +1 -0
  112. package/src/integrations/marks/vercel.svg +1 -0
  113. package/src/integrations/marks/webflow.svg +1 -0
  114. package/src/integrations/mcp-oauth.test.ts +39 -0
  115. package/src/integrations/mcp-oauth.ts +330 -0
  116. package/src/integrations/oauth-clients.test.ts +77 -0
  117. package/src/integrations/oauth-clients.ts +127 -0
  118. package/src/integrations/oauth.ts +145 -0
  119. package/src/integrations/remote-mcp.ts +307 -0
  120. package/src/integrations/store.ts +149 -0
  121. package/src/media/openrouter-generate.test.ts +80 -0
  122. package/src/media/openrouter-generate.ts +178 -0
  123. package/src/media/prefs.ts +54 -0
  124. package/src/observability/categories.ts +41 -0
  125. package/src/observability/create.test.ts +56 -0
  126. package/src/observability/create.ts +45 -0
  127. package/src/observability/experiments.ts +113 -0
  128. package/src/observability/fake.ts +191 -0
  129. package/src/observability/index.ts +57 -0
  130. package/src/observability/judges.ts +91 -0
  131. package/src/observability/langfuse.ts +275 -0
  132. package/src/observability/noop.ts +33 -0
  133. package/src/observability/observability.test.ts +113 -0
  134. package/src/observability/prompts.ts +98 -0
  135. package/src/observability/regression-items.ts +158 -0
  136. package/src/observability/sanitize.test.ts +26 -0
  137. package/src/observability/sanitize.ts +57 -0
  138. package/src/observability/types.ts +122 -0
  139. package/src/observability/version.ts +41 -0
  140. package/src/product.ts +2 -0
  141. package/src/runtime.test.ts +98 -0
  142. package/src/runtime.ts +438 -0
  143. package/src/skills/author-skill.ts +49 -0
  144. package/src/skills/create-skill.test.ts +108 -0
  145. package/src/skills/create-skill.ts +70 -0
  146. package/src/skills/loader.test.ts +122 -0
  147. package/src/skills/loader.ts +162 -0
  148. package/src/skills/registry.test.ts +190 -0
  149. package/src/skills/registry.ts +402 -0
  150. package/src/skills/skill-command.ts +53 -0
  151. package/src/skills/user-dir.ts +8 -0
  152. package/src/tools/git.test.ts +71 -0
  153. package/src/tools/git.ts +126 -0
  154. package/src/tools/local.ts +258 -0
  155. package/src/tools/paths.test.ts +24 -0
  156. package/src/tools/paths.ts +39 -0
  157. package/src/tools/read-skill.ts +43 -0
  158. package/src/tools/subagent.test.ts +77 -0
  159. package/src/tools/subagent.ts +74 -0
  160. package/src/tools/todo.test.ts +25 -0
  161. package/src/tools/todo.ts +70 -0
@@ -0,0 +1,122 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdirSync, writeFileSync } from "node:fs";
3
+ import { mkdtemp, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import {
7
+ bundledSkillsDir,
8
+ loadMergedSkills,
9
+ loadSkills,
10
+ mergeSkills,
11
+ parseSkillMarkdown,
12
+ skillCatalogPrompt,
13
+ stripFrontmatter,
14
+ } from "../skills/loader.ts";
15
+
16
+ const minimal = join(import.meta.dir, "../../examples/minimal");
17
+
18
+ describe("skill loader", () => {
19
+ test("strips yaml frontmatter and folded description", () => {
20
+ const md = `---
21
+ name: hello
22
+ description: >-
23
+ Sample skill used by harness tests. Load when the user mentions hello.
24
+ ---
25
+
26
+ # Hello
27
+
28
+ Body here.
29
+ `;
30
+ const { attrs, body } = stripFrontmatter(md);
31
+ expect(attrs.name).toBe("hello");
32
+ expect(attrs.description).toContain("Sample skill");
33
+ expect(body.startsWith("# Hello")).toBe(true);
34
+ });
35
+
36
+ test("loads example host skills", () => {
37
+ const skills = loadSkills(join(minimal, "skills"));
38
+ expect(skills.length).toBe(1);
39
+ expect(skills[0]?.name).toBe("hello");
40
+ expect(skills[0]?.relPath).toBe("hello/SKILL.md");
41
+ expect(skills[0]?.body).toContain("short greeting");
42
+ });
43
+
44
+ test("parseSkillMarkdown falls back to folder name", () => {
45
+ const skill = parseSkillMarkdown("# bare", "/tmp/skills/foo/SKILL.md", "/tmp/skills");
46
+ expect(skill.name).toBe("foo");
47
+ });
48
+
49
+ test("loads bundled copy skills from the package catalog", () => {
50
+ const bundled = loadSkills(bundledSkillsDir());
51
+ const names = bundled.map((s) => s.name);
52
+ expect(names).toContain("copywriting");
53
+ expect(names).toContain("copy-rmbc");
54
+ expect(names).toContain("copy-harry-dry");
55
+ expect(names).toContain("copy-editor");
56
+ expect(names).toContain("impeccable");
57
+ expect(bundled.find((s) => s.name === "copywriting")?.body).not.toContain("Caelence product");
58
+ expect(bundled.find((s) => s.name === "copywriting")?.body).toContain("impeccable");
59
+ expect(bundled.find((s) => s.name === "impeccable")?.body).toContain("design.md");
60
+ expect(bundled.find((s) => s.name === "impeccable")?.body).not.toContain("#9BB35B");
61
+ });
62
+
63
+ test("does not auto-load the bundled catalog", async () => {
64
+ const cwd = await mkdtemp(join(tmpdir(), "harness-sk-empty-"));
65
+ try {
66
+ const merged = loadMergedSkills(cwd);
67
+ expect(merged.map((s) => s.name)).not.toContain("copywriting");
68
+ expect(merged.map((s) => s.name)).not.toContain("impeccable");
69
+ } finally {
70
+ await rm(cwd, { recursive: true, force: true });
71
+ }
72
+ });
73
+
74
+ test("host skills override user skills of the same name", async () => {
75
+ const cwd = await mkdtemp(join(tmpdir(), "harness-sk-"));
76
+ try {
77
+ const user = join(cwd, "user");
78
+ const host = join(cwd, "host");
79
+ mkdirSync(join(user, "copywriting"), { recursive: true });
80
+ mkdirSync(join(host, "copywriting"), { recursive: true });
81
+ writeFileSync(
82
+ join(user, "copywriting", "SKILL.md"),
83
+ "---\nname: copywriting\ndescription: user\n---\n\n# User\n",
84
+ );
85
+ writeFileSync(
86
+ join(host, "copywriting", "SKILL.md"),
87
+ "---\nname: copywriting\ndescription: host override\n---\n\n# Host\n",
88
+ );
89
+ const merged = loadMergedSkills(host, user);
90
+ const copy = merged.find((s) => s.name === "copywriting");
91
+ expect(copy?.source).toBe("host");
92
+ expect(copy?.body).toContain("# Host");
93
+ expect(merged.find((s) => s.name === "copy-rmbc")).toBeUndefined();
94
+ } finally {
95
+ await rm(cwd, { recursive: true, force: true });
96
+ }
97
+ });
98
+
99
+ test("skill catalog lists names only", () => {
100
+ const catalog = skillCatalogPrompt([
101
+ {
102
+ name: "copywriting",
103
+ description: "Routes copy work through a long folded description that must not leak.",
104
+ body: "# body",
105
+ path: "/tmp/copywriting/SKILL.md",
106
+ relPath: "copywriting/SKILL.md",
107
+ source: "host",
108
+ },
109
+ ]);
110
+ expect(catalog).toContain("- copywriting (host)");
111
+ expect(catalog).not.toContain("Routes copy");
112
+ });
113
+
114
+ test("mergeSkills last writer wins", () => {
115
+ const a = parseSkillMarkdown("---\nname: x\n---\nA", "/b/x/SKILL.md", "/b");
116
+ const b = parseSkillMarkdown("---\nname: x\n---\nB", "/h/x/SKILL.md", "/h");
117
+ const merged = mergeSkills([{ ...a, source: "bundled" }], [{ ...b, source: "host" }]);
118
+ expect(merged).toHaveLength(1);
119
+ expect(merged[0]?.body).toBe("B");
120
+ expect(merged[0]?.source).toBe("host");
121
+ });
122
+ });
@@ -0,0 +1,162 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, join, relative, resolve } from "node:path";
3
+ import { Glob } from "bun";
4
+ import { shouldSkipDir } from "../tools/paths.ts";
5
+
6
+ export interface Skill {
7
+ name: string;
8
+ description: string;
9
+ body: string;
10
+ path: string;
11
+ relPath: string;
12
+ source: "bundled" | "host" | "user";
13
+ }
14
+
15
+ export function stripFrontmatter(md: string): { attrs: Record<string, string>; body: string } {
16
+ const trimmed = md.replace(/^\uFEFF/, "");
17
+ if (!trimmed.startsWith("---")) return { attrs: {}, body: trimmed.trim() };
18
+ const end = trimmed.indexOf("\n---", 3);
19
+ if (end < 0) return { attrs: {}, body: trimmed.trim() };
20
+ const raw = trimmed.slice(3, end).replace(/^\n/, "");
21
+ const body = trimmed
22
+ .slice(end + 4)
23
+ .replace(/^\s*\n/, "")
24
+ .trim();
25
+ return { attrs: parseFrontmatter(raw), body };
26
+ }
27
+
28
+ function parseFrontmatter(raw: string): Record<string, string> {
29
+ const attrs: Record<string, string> = {};
30
+ const lines = raw.split("\n");
31
+ let i = 0;
32
+ while (i < lines.length) {
33
+ const line = lines[i] ?? "";
34
+ const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
35
+ if (!match) {
36
+ i += 1;
37
+ continue;
38
+ }
39
+ const key = match[1] ?? "";
40
+ let value = (match[2] ?? "").trim();
41
+ if (value === ">" || value === ">|" || value === ">-" || value === "|" || value === "|-") {
42
+ const folded: string[] = [];
43
+ i += 1;
44
+ while (i < lines.length) {
45
+ const next = lines[i] ?? "";
46
+ if (/^[A-Za-z0-9_-]+:\s*/.test(next) && !/^\s/.test(next)) break;
47
+ folded.push(next.replace(/^\s{2,}/, ""));
48
+ i += 1;
49
+ }
50
+ attrs[key] = folded.join(" ").replace(/\s+/g, " ").trim();
51
+ continue;
52
+ }
53
+ if (
54
+ (value.startsWith('"') && value.endsWith('"')) ||
55
+ (value.startsWith("'") && value.endsWith("'"))
56
+ ) {
57
+ value = value.slice(1, -1);
58
+ }
59
+ attrs[key] = value;
60
+ i += 1;
61
+ }
62
+ return attrs;
63
+ }
64
+
65
+ export function parseSkillMarkdown(md: string, absPath: string, root: string): Skill {
66
+ const { attrs, body } = stripFrontmatter(md);
67
+ const name = attrs.name?.trim() || dirname(absPath).split("/").pop() || "skill";
68
+ const description = attrs.description?.trim() || "";
69
+ return {
70
+ name,
71
+ description,
72
+ body,
73
+ path: absPath,
74
+ relPath: relative(root, absPath).split("\\").join("/"),
75
+ source: "host",
76
+ };
77
+ }
78
+
79
+ export function bundledSkillsDir(): string {
80
+ return join(import.meta.dir, "..", "..", "skills");
81
+ }
82
+
83
+ /** Later writers win. Used to overlay host skills on a catalog or user store. */
84
+ export function mergeSkills(first: Skill[], host: Skill[]): Skill[] {
85
+ const byName = new Map<string, Skill>();
86
+ for (const skill of first) byName.set(skill.name.toLowerCase(), skill);
87
+ for (const skill of host) byName.set(skill.name.toLowerCase(), { ...skill, source: "host" });
88
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
89
+ }
90
+
91
+ /** Skills shipped with the package. Not loaded until `/skill add`. */
92
+ export function listBundledSkills(): Skill[] {
93
+ return loadSkills(bundledSkillsDir()).map((skill) => ({ ...skill, source: "bundled" as const }));
94
+ }
95
+
96
+ /** Extra folders we read so a host is not locked to Cursor. Writes still go to config.skillsDir. */
97
+ export const CONVENTIONAL_HOST_SKILL_DIRS = ["skills", ".cursor/skills", ".claude/skills"] as const;
98
+
99
+ export function resolveHostSkillDirs(cwd: string, configured: string): string[] {
100
+ const seen = new Set<string>();
101
+ const out: string[] = [];
102
+ for (const rel of [configured, ...CONVENTIONAL_HOST_SKILL_DIRS]) {
103
+ const abs = resolve(cwd, rel);
104
+ if (seen.has(abs)) continue;
105
+ seen.add(abs);
106
+ if (existsSync(abs)) out.push(abs);
107
+ }
108
+ if (out.length === 0) out.push(resolve(cwd, configured));
109
+ return out;
110
+ }
111
+
112
+ export function loadMergedSkills(hostSkillsDir: string | string[], userDir?: string): Skill[] {
113
+ const dirs = Array.isArray(hostSkillsDir) ? hostSkillsDir : [hostSkillsDir];
114
+ const byName = new Map<string, Skill>();
115
+ if (userDir) {
116
+ for (const skill of loadSkills(userDir)) {
117
+ byName.set(skill.name.toLowerCase(), { ...skill, source: "user" });
118
+ }
119
+ }
120
+ for (const dir of dirs) {
121
+ for (const skill of loadSkills(dir)) {
122
+ byName.set(skill.name.toLowerCase(), { ...skill, source: "host" });
123
+ }
124
+ }
125
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
126
+ }
127
+
128
+ export function loadSkills(skillsDir: string): Skill[] {
129
+ const skills: Skill[] = [];
130
+ try {
131
+ const glob = new Glob("**/SKILL.md");
132
+ for (const rel of glob.scanSync({ cwd: skillsDir, onlyFiles: true, dot: false })) {
133
+ const parts = rel.split("/");
134
+ if (parts.some((p) => shouldSkipDir(p))) continue;
135
+ const abs = join(skillsDir, rel);
136
+ const md = readFileSync(abs, "utf8");
137
+ skills.push(parseSkillMarkdown(md, abs, skillsDir));
138
+ }
139
+ } catch {
140
+ return [];
141
+ }
142
+ skills.sort((a, b) => a.name.localeCompare(b.name));
143
+ return skills;
144
+ }
145
+
146
+ export function skillCatalogPrompt(skills: Skill[]): string {
147
+ if (skills.length === 0) return "";
148
+ const lines = skills.map((s) => `- ${s.name} (${s.source})`);
149
+ return [
150
+ "## Skills",
151
+ "Skills are instruction files, not tools. When a task matches a name, read it with read_skill. Do not list or quote these unless the user asks.",
152
+ ...lines,
153
+ ].join("\n");
154
+ }
155
+
156
+ export function skillBodiesForNames(skills: Skill[], names: string[]): string {
157
+ const wanted = new Set(names.map((n) => n.trim().toLowerCase()));
158
+ return skills
159
+ .filter((s) => wanted.has(s.name.toLowerCase()))
160
+ .map((s) => `# Skill: ${s.name}\n\n${s.body}`)
161
+ .join("\n\n");
162
+ }
@@ -0,0 +1,190 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { mkdtemp, readFile, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { loadMergedSkills } from "./loader.ts";
7
+ import {
8
+ bundledRegistryHits,
9
+ formatRegistryHits,
10
+ installBundledSkills,
11
+ installSkillFromSource,
12
+ parseBundledSkillRef,
13
+ parseSkillSource,
14
+ removeSkillFromRoots,
15
+ searchSkills,
16
+ searchSkillsSh,
17
+ } from "./registry.ts";
18
+ import { parseSkillCommand } from "./skill-command.ts";
19
+
20
+ describe("parseSkillSource", () => {
21
+ test("accepts owner/repo@skill and skills.sh urls", () => {
22
+ expect(parseSkillSource("anthropics/skills@frontend-design")).toEqual({
23
+ owner: "anthropics",
24
+ repo: "skills",
25
+ skill: "frontend-design",
26
+ ref: "HEAD",
27
+ });
28
+ expect(parseSkillSource("https://skills.sh/anthropics/skills/frontend-design")).toMatchObject({
29
+ owner: "anthropics",
30
+ repo: "skills",
31
+ skill: "frontend-design",
32
+ });
33
+ });
34
+ });
35
+
36
+ describe("parseSkillCommand", () => {
37
+ test("routes find, add, and new", () => {
38
+ expect(parseSkillCommand("find frontend")).toEqual({ action: "find", query: "frontend" });
39
+ expect(parseSkillCommand("add copywriting")).toEqual({
40
+ action: "add",
41
+ source: "copywriting",
42
+ scope: "user",
43
+ });
44
+ expect(parseSkillCommand("add anthropics/skills@frontend-design")).toEqual({
45
+ action: "add",
46
+ source: "anthropics/skills@frontend-design",
47
+ scope: "user",
48
+ });
49
+ expect(parseSkillCommand("find")).toEqual({ action: "find", query: "" });
50
+ expect(parseSkillCommand("add --project acme/pack hello")).toEqual({
51
+ action: "add",
52
+ source: "acme/pack",
53
+ skill: "hello",
54
+ scope: "project",
55
+ });
56
+ expect(parseSkillCommand("new")).toHaveProperty("error");
57
+ });
58
+ });
59
+
60
+ describe("searchSkillsSh", () => {
61
+ test("maps the public search payload", async () => {
62
+ const hits = await searchSkillsSh(
63
+ "frontend-design",
64
+ async () =>
65
+ new Response(
66
+ JSON.stringify({
67
+ skills: [
68
+ {
69
+ id: "anthropics/skills/frontend-design",
70
+ name: "frontend-design",
71
+ source: "anthropics/skills",
72
+ installs: 10,
73
+ },
74
+ ],
75
+ }),
76
+ ),
77
+ );
78
+ expect(hits[0]).toEqual({
79
+ id: "anthropics/skills/frontend-design",
80
+ name: "frontend-design",
81
+ source: "anthropics/skills",
82
+ installs: 10,
83
+ });
84
+ expect(formatRegistryHits(hits)).toBe("anthropics/skills@frontend-design 10");
85
+ });
86
+ });
87
+
88
+ describe("installSkillFromSource", () => {
89
+ test("downloads a GitHub skill into the user store", async () => {
90
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
91
+ try {
92
+ const result = await installSkillFromSource({
93
+ source: "acme/pack@hello",
94
+ destRoot: dest,
95
+ fetchFn: async (url) => {
96
+ if (url.includes("/git/trees/")) {
97
+ return Response.json({
98
+ tree: [
99
+ { path: "skills/hello/SKILL.md", type: "blob" },
100
+ { path: "skills/hello/references/note.md", type: "blob" },
101
+ ],
102
+ });
103
+ }
104
+ if (url.endsWith("skills/hello/SKILL.md")) {
105
+ return new Response(
106
+ "---\nname: hello\ndescription: demo\n---\n\n# Hello\n\nDo the work.\n",
107
+ );
108
+ }
109
+ if (url.endsWith("note.md")) return new Response("# note\n");
110
+ return new Response("missing", { status: 404 });
111
+ },
112
+ });
113
+ expect(result).toEqual({ name: "hello", rel: "hello/SKILL.md" });
114
+ const body = await readFile(join(dest, "hello", "SKILL.md"), "utf8");
115
+ expect(body).toContain("# Hello");
116
+ } finally {
117
+ await rm(dest, { recursive: true, force: true });
118
+ }
119
+ });
120
+ });
121
+
122
+ describe("bundled catalog", () => {
123
+ test("parses a bare name or bundled@ tag", () => {
124
+ expect(parseBundledSkillRef("copywriting")).toBe("copywriting");
125
+ expect(parseBundledSkillRef("bundled@impeccable")).toBe("impeccable");
126
+ expect(parseBundledSkillRef("anthropics/skills@frontend-design")).toBeUndefined();
127
+ });
128
+
129
+ test("find lists bundled copy skills without a network call", async () => {
130
+ const hits = bundledRegistryHits("copy");
131
+ expect(hits.map((hit) => hit.name)).toContain("copywriting");
132
+ expect(hits.map((hit) => hit.name)).toContain("copy-editor");
133
+ const listed = await searchSkills(
134
+ "copy",
135
+ async () => new Response(JSON.stringify({ skills: [] })),
136
+ );
137
+ expect(listed).toContain("bundled@copywriting");
138
+ expect(listed).toContain("bundled@copy-editor");
139
+ });
140
+
141
+ test("installs the writing pack and removes it", async () => {
142
+ const dest = await mkdtemp(join(tmpdir(), "harness-bundled-"));
143
+ try {
144
+ const result = await installSkillFromSource({ source: "copywriting", destRoot: dest });
145
+ expect(result).toMatchObject({
146
+ name: "copywriting",
147
+ rel: "copywriting/SKILL.md",
148
+ installed: ["copywriting", "copy-rmbc", "copy-harry-dry", "copy-editor"],
149
+ });
150
+ expect(existsSync(join(dest, "copy-editor", "references", "anti-slop.md"))).toBe(true);
151
+ const merged = loadMergedSkills("/tmp/does-not-exist-host", dest);
152
+ expect(merged.map((skill) => skill.name)).toEqual(
153
+ expect.arrayContaining(["copywriting", "copy-rmbc", "copy-harry-dry", "copy-editor"]),
154
+ );
155
+ expect(merged.every((skill) => skill.source === "user")).toBe(true);
156
+ expect(merged.map((skill) => skill.name)).not.toContain("impeccable");
157
+
158
+ const one = installBundledSkills("impeccable", dest);
159
+ expect("error" in one).toBe(false);
160
+ expect(existsSync(join(dest, "impeccable", "references", "visual-slop.md"))).toBe(true);
161
+
162
+ const removed = removeSkillFromRoots("copywriting", [dest]);
163
+ expect(removed.removed).toBe(true);
164
+ expect(existsSync(join(dest, "copywriting"))).toBe(false);
165
+ expect(existsSync(join(dest, "copy-editor"))).toBe(false);
166
+ expect(existsSync(join(dest, "impeccable"))).toBe(true);
167
+ } finally {
168
+ await rm(dest, { recursive: true, force: true });
169
+ }
170
+ });
171
+ });
172
+
173
+ describe("user skill source", () => {
174
+ test("marks ~/.harness skills as user and lets host win", async () => {
175
+ const root = await mkdtemp(join(tmpdir(), "harness-merge-src-"));
176
+ try {
177
+ const user = join(root, "user");
178
+ const host = join(root, "host");
179
+ mkdirSync(join(user, "shared"), { recursive: true });
180
+ mkdirSync(join(host, "shared"), { recursive: true });
181
+ writeFileSync(join(user, "shared", "SKILL.md"), "---\nname: shared\n---\n\n# User\n");
182
+ writeFileSync(join(host, "shared", "SKILL.md"), "---\nname: shared\n---\n\n# Host\n");
183
+ const merged = loadMergedSkills(host, user);
184
+ expect(merged.find((skill) => skill.name === "shared")?.source).toBe("host");
185
+ expect(merged.find((skill) => skill.name === "shared")?.body).toContain("# Host");
186
+ } finally {
187
+ await rm(root, { recursive: true, force: true });
188
+ }
189
+ });
190
+ });