@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,57 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdtemp, readFile, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import {
6
+ composeUploadMessage,
7
+ isTextUpload,
8
+ parseIncomingUploads,
9
+ safeUploadName,
10
+ saveUploads,
11
+ } from "./uploads.ts";
12
+
13
+ describe("uploads", () => {
14
+ test("parses named base64 attachments and ignores junk", () => {
15
+ expect(
16
+ parseIncomingUploads([
17
+ { name: " a.txt ", mime: "text/plain", data: "YQ==" },
18
+ { name: "", data: "YQ==" },
19
+ { mime: "text/plain", data: "YQ==" },
20
+ "nope",
21
+ ]),
22
+ ).toEqual([{ name: "a.txt", mime: "text/plain", data: "YQ==" }]);
23
+ });
24
+
25
+ test("treats source and markdown as text", () => {
26
+ expect(isTextUpload("notes.md", "application/octet-stream")).toBe(true);
27
+ expect(isTextUpload("shot.png", "image/png")).toBe(false);
28
+ expect(isTextUpload("data.json", "application/json")).toBe(true);
29
+ });
30
+
31
+ test("sanitizes upload names", () => {
32
+ expect(safeUploadName("../weird name!.png")).toBe("weird_name_.png");
33
+ expect(safeUploadName("...")).toBe("file");
34
+ });
35
+
36
+ test("writes files and composes a message with text excerpts", async () => {
37
+ const cwd = await mkdtemp(join(tmpdir(), "harness-uploads-"));
38
+ try {
39
+ const saved = saveUploads(cwd, [
40
+ { name: "note.txt", mime: "text/plain", data: Buffer.from("hello").toString("base64") },
41
+ { name: "shot.png", mime: "image/png", data: Buffer.from([0x89, 0x50]).toString("base64") },
42
+ ]);
43
+ expect(saved).toHaveLength(2);
44
+ expect(saved[0]?.rel.startsWith(".harness/uploads/")).toBe(true);
45
+ expect(saved[0]?.excerpt).toBe("hello");
46
+ expect(saved[1]?.excerpt).toBeUndefined();
47
+ const body = await readFile(join(cwd, saved[0]?.rel ?? ""), "utf8");
48
+ expect(body).toBe("hello");
49
+ expect(composeUploadMessage("look", saved)).toContain("look");
50
+ expect(composeUploadMessage("look", saved)).toContain(saved[0]?.rel ?? "");
51
+ expect(composeUploadMessage("look", saved)).toContain("```\nhello\n```");
52
+ expect(composeUploadMessage("", saved)).toContain(saved[1]?.rel ?? "");
53
+ } finally {
54
+ await rm(cwd, { recursive: true, force: true });
55
+ }
56
+ });
57
+ });
@@ -0,0 +1,92 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { toProjectRel } from "../tools/paths.ts";
4
+
5
+ export const MAX_UPLOADS = 8;
6
+ export const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
7
+ const TEXT_EXCERPT_BYTES = 100_000;
8
+
9
+ const TEXT_MIME =
10
+ /^(text\/|application\/(json|xml|javascript|sql|yaml|x-yaml|toml|x-sh|x-httpd-php))/i;
11
+ const TEXT_EXT =
12
+ /\.(txt|md|markdown|json|csv|tsv|ts|tsx|js|jsx|mjs|cjs|css|scss|html|htm|xml|yml|yaml|toml|py|rs|go|sh|bash|zsh|env|svg|log|ini|cfg)$/i;
13
+
14
+ export interface IncomingUpload {
15
+ name: string;
16
+ mime: string;
17
+ data: string;
18
+ }
19
+
20
+ export interface SavedUpload {
21
+ name: string;
22
+ rel: string;
23
+ mime: string;
24
+ excerpt?: string;
25
+ }
26
+
27
+ export function parseIncomingUploads(raw: unknown): IncomingUpload[] {
28
+ if (!Array.isArray(raw)) return [];
29
+ const out: IncomingUpload[] = [];
30
+ for (const item of raw) {
31
+ if (!item || typeof item !== "object") continue;
32
+ const rec = item as Record<string, unknown>;
33
+ const name = typeof rec.name === "string" ? rec.name.trim() : "";
34
+ const data = typeof rec.data === "string" ? rec.data.trim() : "";
35
+ const mime =
36
+ typeof rec.mime === "string" && rec.mime.trim()
37
+ ? rec.mime.trim()
38
+ : "application/octet-stream";
39
+ if (!name || !data) continue;
40
+ out.push({ name, mime, data });
41
+ if (out.length >= MAX_UPLOADS) break;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ export function isTextUpload(name: string, mime: string): boolean {
47
+ return TEXT_MIME.test(mime) || TEXT_EXT.test(name);
48
+ }
49
+
50
+ export function safeUploadName(name: string): string {
51
+ const trimmed = name.trim() || "file";
52
+ const base = trimmed.replace(/[^\w.-]+/g, "_").replace(/^[._]+/, "");
53
+ return (base || "file").slice(0, 120);
54
+ }
55
+
56
+ export function saveUploads(cwd: string, items: IncomingUpload[]): SavedUpload[] {
57
+ if (items.length === 0) return [];
58
+ const dir = resolve(cwd, ".harness", "uploads");
59
+ mkdirSync(dir, { recursive: true });
60
+ const saved: SavedUpload[] = [];
61
+ for (const item of items) {
62
+ const bytes = Buffer.from(item.data, "base64");
63
+ if (bytes.byteLength === 0 || bytes.byteLength > MAX_UPLOAD_BYTES) continue;
64
+ const unique = `${Date.now()}-${saved.length}-${safeUploadName(item.name)}`;
65
+ const abs = resolve(dir, unique);
66
+ writeFileSync(abs, bytes);
67
+ const rel = toProjectRel(cwd, abs);
68
+ const excerpt =
69
+ isTextUpload(item.name, item.mime) && bytes.byteLength <= TEXT_EXCERPT_BYTES
70
+ ? bytes.toString("utf8")
71
+ : undefined;
72
+ saved.push({
73
+ name: item.name,
74
+ rel,
75
+ mime: item.mime,
76
+ ...(excerpt !== undefined ? { excerpt } : {}),
77
+ });
78
+ }
79
+ return saved;
80
+ }
81
+
82
+ export function composeUploadMessage(text: string, files: SavedUpload[]): string {
83
+ if (files.length === 0) return text;
84
+ const blocks = files.map((file) => {
85
+ if (file.excerpt !== undefined) {
86
+ return `Attached \`${file.rel}\` (${file.name}):\n\n\`\`\`\n${file.excerpt}\n\`\`\``;
87
+ }
88
+ return `Attached \`${file.rel}\` (${file.name}, ${file.mime}). Use that project path.`;
89
+ });
90
+ const body = text.trim();
91
+ return body ? `${body}\n\n${blocks.join("\n\n")}` : blocks.join("\n\n");
92
+ }
package/src/index.ts CHANGED
@@ -88,13 +88,34 @@ export {
88
88
  startObservability,
89
89
  WEBSITE_GENERATION_REGRESSION,
90
90
  } from "./observability/index.ts";
91
- export { PRODUCT_NAME } from "./product.ts";
91
+ export { CLI_NAME, PRODUCT_NAME } from "./product.ts";
92
92
  export { type CreateHarnessOptions, createHarness, type HarnessRuntime } from "./runtime.ts";
93
93
  export { authorSkillMarkdown, SKILL_AUTHOR_SYSTEM } from "./skills/author-skill.ts";
94
+ export {
95
+ browseSkillCatalog,
96
+ buildSkillsPage,
97
+ bundledSkillHits,
98
+ type CatalogSkill,
99
+ cachedPopularSkills,
100
+ decorateCatalogSkill,
101
+ formatInstallCount,
102
+ POPULAR_SKILL_SEED,
103
+ refreshPopularSkills,
104
+ type SkillsPage,
105
+ skillBlurb,
106
+ withDisabledCatalogSkills,
107
+ } from "./skills/catalog.ts";
94
108
  export { createHostSkill, parseSkillNewArgs, unwrapMarkdownFence } from "./skills/create-skill.ts";
109
+ export {
110
+ disableSkills,
111
+ enableSkills,
112
+ isSkillDisabled,
113
+ readDisabledSkillNames,
114
+ } from "./skills/disabled.ts";
95
115
  export {
96
116
  bundledSkillsDir,
97
117
  CONVENTIONAL_HOST_SKILL_DIRS,
118
+ isBundledCatalogDir,
98
119
  listBundledSkills,
99
120
  loadMergedSkills,
100
121
  loadSkills,
@@ -114,10 +135,13 @@ export {
114
135
  parseBundledSkillRef,
115
136
  parseSkillSource,
116
137
  removeSkillFromRoots,
138
+ searchSkillCatalog,
117
139
  searchSkills,
118
140
  searchSkillsSh,
141
+ skillCatalogRef,
142
+ skillIsCatalogHit,
119
143
  } from "./skills/registry.ts";
120
- export { parseSkillCommand, SKILL_COMMAND_USAGE } from "./skills/skill-command.ts";
144
+ export { parseSkillCommand, SKILL_COMMAND_USAGE, SKILL_FIND_HINT } from "./skills/skill-command.ts";
121
145
  export { userSkillsDir } from "./skills/user-dir.ts";
122
146
  export { createGitTools } from "./tools/git.ts";
123
147
  export { createLocalTools } from "./tools/local.ts";
package/src/init.test.ts CHANGED
@@ -6,16 +6,33 @@ import { initHost } from "./init.ts";
6
6
  import { createLocalTools } from "./tools/local.ts";
7
7
 
8
8
  describe("initHost", () => {
9
- test("writes config, skill, eval, and gitignore", async () => {
9
+ test("default only gitignores .harness/", async () => {
10
10
  const cwd = await mkdtemp(join(tmpdir(), "harness-init-"));
11
11
  try {
12
12
  const first = initHost({ cwd, name: "demo" });
13
+ expect(first.created).toEqual([".gitignore"]);
14
+ expect(first.created).not.toContain("harness.config.ts");
15
+ expect(first.created).not.toContain("AGENTS.md");
16
+ const gitignore = await readFile(join(cwd, ".gitignore"), "utf8");
17
+ expect(gitignore).toContain(".harness/");
18
+ const second = initHost({ cwd, name: "demo" });
19
+ expect(second.skipped).toContain(".gitignore");
20
+ } finally {
21
+ await rm(cwd, { recursive: true, force: true });
22
+ }
23
+ });
24
+
25
+ test("examples writes config, skill, eval, and gitignore", async () => {
26
+ const cwd = await mkdtemp(join(tmpdir(), "harness-init-"));
27
+ try {
28
+ const first = initHost({ cwd, name: "demo", examples: true });
13
29
  expect(first.created).toContain("harness.config.ts");
14
30
  expect(first.created).toContain("AGENTS.md");
15
31
  const config = await readFile(join(cwd, "harness.config.ts"), "utf8");
16
32
  expect(config).toContain('name: "demo"');
33
+ expect(config).toContain('model: "openrouter/auto"');
17
34
  expect(config).toContain('mode: "agent"');
18
- const second = initHost({ cwd, name: "demo" });
35
+ const second = initHost({ cwd, name: "demo", examples: true });
19
36
  expect(second.skipped).toContain("harness.config.ts");
20
37
  } finally {
21
38
  await rm(cwd, { recursive: true, force: true });
package/src/init.ts CHANGED
@@ -4,6 +4,8 @@ import { join } from "node:path";
4
4
  export interface InitOptions {
5
5
  cwd: string;
6
6
  name?: string;
7
+ /** Write harness.config.ts, AGENTS.md, a sample skill, and a smoke eval. */
8
+ examples?: boolean;
7
9
  }
8
10
 
9
11
  const AGENTS = `# Agent instructions
@@ -51,7 +53,7 @@ function configSource(name: string): string {
51
53
 
52
54
  export default {
53
55
  name: ${JSON.stringify(name)},
54
- model: "~x-ai/grok-latest",
56
+ model: "openrouter/auto",
55
57
  instructionsFile: "AGENTS.md",
56
58
  skillsDir: "skills",
57
59
  evalsDir: "evals",
@@ -78,13 +80,33 @@ function writeNew(
78
80
  created.push(rel);
79
81
  }
80
82
 
81
- /** Write host-project files. Existing files are left untouched. */
83
+ function ignoreHarnessDir(cwd: string, created: string[], skipped: string[]): void {
84
+ const gitignorePath = join(cwd, ".gitignore");
85
+ if (existsSync(gitignorePath)) {
86
+ const current = readFileSync(gitignorePath, "utf8");
87
+ if (!current.split("\n").some((line) => line.trim() === ".harness/")) {
88
+ appendFileSync(gitignorePath, current.endsWith("\n") ? ".harness/\n" : "\n.harness/\n");
89
+ created.push(".gitignore (append .harness/)");
90
+ } else {
91
+ skipped.push(".gitignore");
92
+ }
93
+ return;
94
+ }
95
+ writeFileSync(gitignorePath, ".harness/\n", "utf8");
96
+ created.push(".gitignore");
97
+ }
98
+
99
+ /** Ignore `.harness/`. With `examples`, also write a host scaffold. Existing files stay. */
82
100
  export function initHost(options: InitOptions): { created: string[]; skipped: string[] } {
83
101
  const cwd = options.cwd;
84
- const name = options.name ?? "caelence";
85
102
  const created: string[] = [];
86
103
  const skipped: string[] = [];
87
104
 
105
+ ignoreHarnessDir(cwd, created, skipped);
106
+
107
+ if (!options.examples) return { created, skipped };
108
+
109
+ const name = options.name ?? "caelence";
88
110
  mkdirSync(join(cwd, "skills", "hello"), { recursive: true });
89
111
  mkdirSync(join(cwd, "evals", "smoke"), { recursive: true });
90
112
 
@@ -99,19 +121,5 @@ export function initHost(options: InitOptions): { created: string[]; skipped: st
99
121
  writeNew(join(cwd, "skills/hello/SKILL.md"), SKILL, created, skipped, "skills/hello/SKILL.md");
100
122
  writeNew(join(cwd, "evals/smoke/eval.ts"), EVAL, created, skipped, "evals/smoke/eval.ts");
101
123
 
102
- const gitignorePath = join(cwd, ".gitignore");
103
- if (existsSync(gitignorePath)) {
104
- const current = readFileSync(gitignorePath, "utf8");
105
- if (!current.split("\n").some((line) => line.trim() === ".harness/")) {
106
- appendFileSync(gitignorePath, current.endsWith("\n") ? ".harness/\n" : "\n.harness/\n");
107
- created.push(".gitignore (append .harness/)");
108
- } else {
109
- skipped.push(".gitignore");
110
- }
111
- } else {
112
- writeFileSync(gitignorePath, ".harness/\n", "utf8");
113
- created.push(".gitignore");
114
- }
115
-
116
124
  return { created, skipped };
117
125
  }
@@ -0,0 +1,17 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { startOAuthLoopback } from "./loopback.ts";
3
+
4
+ describe("oauth loopback", () => {
5
+ test("serves the callback page and resolves the waiter", async () => {
6
+ const loopback = startOAuthLoopback({ timeoutMs: 2_000 });
7
+ try {
8
+ const pending = loopback.waitForCallback("abc");
9
+ const res = await fetch(`${loopback.redirectUri}?state=abc&code=tok`);
10
+ expect(res.ok).toBe(true);
11
+ expect(await res.text()).toContain("Connected");
12
+ expect(await pending).toEqual({ code: "tok", error: undefined });
13
+ } finally {
14
+ loopback.stop();
15
+ }
16
+ });
17
+ });
@@ -0,0 +1,91 @@
1
+ import { type OAuthCallback, oauthResultPage } from "./connect.ts";
2
+
3
+ export interface OAuthLoopback {
4
+ redirectUri: string;
5
+ waitForCallback: (state: string) => Promise<OAuthCallback>;
6
+ stop: () => void;
7
+ }
8
+
9
+ function html(body: string, status: number): Response {
10
+ return new Response(body, {
11
+ status,
12
+ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" },
13
+ });
14
+ }
15
+
16
+ /** Loopback HTTP server so a TUI or CLI can finish MCP OAuth in the browser. */
17
+ export function startOAuthLoopback(options?: { timeoutMs?: number }): OAuthLoopback {
18
+ const waiters = new Map<string, (result: OAuthCallback) => void>();
19
+ const timeoutMs = options?.timeoutMs ?? 180_000;
20
+ const server = Bun.serve({
21
+ hostname: "127.0.0.1",
22
+ port: 0,
23
+ fetch(req) {
24
+ const url = new URL(req.url);
25
+ if (req.method !== "GET" || url.pathname !== "/oauth/callback") {
26
+ return new Response("Not found", { status: 404 });
27
+ }
28
+ const state = url.searchParams.get("state")?.trim() ?? "";
29
+ const code = url.searchParams.get("code")?.trim() ?? "";
30
+ const error = url.searchParams.get("error")?.trim() ?? "";
31
+ const resolve = waiters.get(state);
32
+ if (!resolve) {
33
+ return html(
34
+ oauthResultPage(
35
+ false,
36
+ "This sign-in is no longer waiting. Close this tab and try Connect again.",
37
+ ),
38
+ 400,
39
+ );
40
+ }
41
+ waiters.delete(state);
42
+ resolve({ code: code || undefined, error: error || undefined });
43
+ const ok = Boolean(code) && !error;
44
+ return html(
45
+ oauthResultPage(
46
+ ok,
47
+ ok
48
+ ? "You can close this tab and return to Caelence agent."
49
+ : "Close this tab and try Connect again.",
50
+ ),
51
+ ok ? 200 : 400,
52
+ );
53
+ },
54
+ });
55
+ return {
56
+ redirectUri: `http://127.0.0.1:${server.port}/oauth/callback`,
57
+ waitForCallback(state) {
58
+ return new Promise<OAuthCallback>((resolve, reject) => {
59
+ const timer = setTimeout(() => {
60
+ waiters.delete(state);
61
+ reject(new Error("Sign-in timed out. Try Connect again."));
62
+ }, timeoutMs);
63
+ waiters.set(state, (result) => {
64
+ clearTimeout(timer);
65
+ resolve(result);
66
+ });
67
+ });
68
+ },
69
+ stop() {
70
+ server.stop();
71
+ },
72
+ };
73
+ }
74
+
75
+ export async function withOAuthLoopback<T>(
76
+ run: (ctx: {
77
+ redirectUri: string;
78
+ waitForCallback: (state: string) => Promise<OAuthCallback>;
79
+ }) => Promise<T>,
80
+ options?: { timeoutMs?: number },
81
+ ): Promise<T> {
82
+ const loopback = startOAuthLoopback(options);
83
+ try {
84
+ return await run({
85
+ redirectUri: loopback.redirectUri,
86
+ waitForCallback: loopback.waitForCallback,
87
+ });
88
+ } finally {
89
+ loopback.stop();
90
+ }
91
+ }
@@ -31,7 +31,7 @@ export function promptVersionMap(bodies: Record<string, string>): Record<string,
31
31
  return out;
32
32
  }
33
33
 
34
- /** Git-backed copy / visual-QA skills shipped with the harness. */
34
+ /** Git-backed copy / visual-QA skills shipped with the package. */
35
35
  export function harnessPromptRecords(): PromptRecord[] {
36
36
  const dir = join(import.meta.dir, "..", "..", "skills");
37
37
  const out: PromptRecord[] = [];
package/src/product.ts CHANGED
@@ -1,2 +1,4 @@
1
- /** User-facing product name. The package, bin, and config files stay `harness`. */
1
+ /** User-facing product name. */
2
2
  export const PRODUCT_NAME = "Caelence agent";
3
+ /** Command users run. `harness` and `caelence-agent` are aliases. */
4
+ export const CLI_NAME = "caelence";
@@ -62,6 +62,30 @@ describe("createHarness modes", () => {
62
62
  }
63
63
  });
64
64
 
65
+ test("starts without an OpenRouter key", async () => {
66
+ const cwd = await mkdtemp(join(tmpdir(), "harness-nokey-"));
67
+ const previous = process.env.OPENROUTER_API_KEY;
68
+ delete process.env.OPENROUTER_API_KEY;
69
+ try {
70
+ const harness = await createHarness({
71
+ cwd,
72
+ config: DEFAULT_CONFIG,
73
+ constructAgent: () => ({
74
+ async run() {
75
+ throw new Error("should not run");
76
+ },
77
+ }),
78
+ observability: noopObservability,
79
+ });
80
+ expect(harness.hasApiKey).toBe(false);
81
+ harness.close();
82
+ } finally {
83
+ if (previous === undefined) delete process.env.OPENROUTER_API_KEY;
84
+ else process.env.OPENROUTER_API_KEY = previous;
85
+ await rm(cwd, { recursive: true, force: true });
86
+ }
87
+ });
88
+
65
89
  test("accumulates usage on the runtime", async () => {
66
90
  const cwd = await mkdtemp(join(tmpdir(), "harness-spend-"));
67
91
  try {
package/src/runtime.ts CHANGED
@@ -47,6 +47,13 @@ import { resolveAgentVersion } from "./observability/version.ts";
47
47
  import { authorSkillMarkdown } from "./skills/author-skill.ts";
48
48
  import { createHostSkill, parseSkillNewArgs } from "./skills/create-skill.ts";
49
49
  import {
50
+ disableSkills,
51
+ enableSkills,
52
+ isSkillDisabled,
53
+ readDisabledSkillNames,
54
+ } from "./skills/disabled.ts";
55
+ import {
56
+ isBundledCatalogDir,
50
57
  loadMergedSkills,
51
58
  resolveHostSkillDirs,
52
59
  type Skill,
@@ -93,6 +100,8 @@ export interface HarnessRuntime {
93
100
  integrationIds(): string[];
94
101
  authorSkill(name: string, brief: string): Promise<{ rel: string } | { error: string }>;
95
102
  findSkills(query: string): Promise<string>;
103
+ disabledSkills(): string[];
104
+ enableSkill(name: string): { ok: boolean };
96
105
  addSkill(
97
106
  source: string,
98
107
  options?: { skill?: string; scope?: "user" | "project" },
@@ -128,7 +137,18 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
128
137
  const skillsDir = resolve(cwd, config.skillsDir);
129
138
  const userDir = userSkillsDir();
130
139
  const hostSkillDirs = () => resolveHostSkillDirs(cwd, config.skillsDir);
131
- let skills = loadMergedSkills(hostSkillDirs(), userDir);
140
+ const removableRoots = () => {
141
+ const roots = [userDir];
142
+ if (!isBundledCatalogDir(skillsDir)) roots.push(skillsDir);
143
+ return roots;
144
+ };
145
+ const loadActiveSkills = (): Skill[] => {
146
+ const disabled = readDisabledSkillNames(cwd);
147
+ return loadMergedSkills(hostSkillDirs(), userDir).filter(
148
+ (skill) => !disabled.has(skill.name.toLowerCase()),
149
+ );
150
+ };
151
+ let skills = loadActiveSkills();
132
152
  const layers = loadInstructionLayers({ cwd, projectFile: config.instructionsFile });
133
153
  let mode = parseAgentMode(options.mode ?? config.mode);
134
154
  const composePrompt = (nextMode: AgentMode) =>
@@ -277,7 +297,7 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
277
297
  return next.messages.length > session.messages.length;
278
298
  },
279
299
  reloadSkills() {
280
- skills = loadMergedSkills(hostSkillDirs(), userDir);
300
+ skills = loadActiveSkills();
281
301
  systemPrompt = composePrompt(mode);
282
302
  return skills;
283
303
  },
@@ -309,8 +329,22 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
309
329
  async findSkills(query) {
310
330
  return searchSkills(query);
311
331
  },
332
+ disabledSkills() {
333
+ return [...readDisabledSkillNames(cwd)];
334
+ },
335
+ enableSkill(name) {
336
+ enableSkills(cwd, name);
337
+ runtime.reloadSkills();
338
+ return { ok: true };
339
+ },
312
340
  async addSkill(source, options) {
313
- const destRoot = options?.scope === "project" ? skillsDir : userDir;
341
+ const name = source.split("@").pop()?.trim() ?? source;
342
+ if (isSkillDisabled(cwd, name)) {
343
+ runtime.enableSkill(name);
344
+ return { rel: name };
345
+ }
346
+ const destRoot =
347
+ options?.scope === "project" && !isBundledCatalogDir(skillsDir) ? skillsDir : userDir;
314
348
  const result = await installSkillFromSource({
315
349
  source,
316
350
  destRoot,
@@ -324,11 +358,20 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
324
358
  if (result.installed && result.installed.length > 1) {
325
359
  return { rel: result.installed.join(", ") };
326
360
  }
327
- const root = options?.scope === "project" ? config.skillsDir : userDir;
361
+ const root =
362
+ options?.scope === "project" && !isBundledCatalogDir(skillsDir)
363
+ ? config.skillsDir
364
+ : userDir;
328
365
  return { rel: `${root}/${result.rel}` };
329
366
  },
330
367
  removeSkill(name) {
331
- const result = removeSkillFromRoots(name, [userDir, skillsDir]);
368
+ const loaded = skills.find((skill) => skill.name.toLowerCase() === name.trim().toLowerCase());
369
+ if (loaded && loaded.source !== "user") {
370
+ disableSkills(cwd, loaded.name);
371
+ runtime.reloadSkills();
372
+ return { ok: true };
373
+ }
374
+ const result = removeSkillFromRoots(name, removableRoots());
332
375
  if (!result.removed) return { ok: false, error: result.reason };
333
376
  runtime.reloadSkills();
334
377
  return { ok: true };