@useavalon/caelence-agent 0.1.1-canary.1 → 0.2.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.
package/README.md CHANGED
@@ -4,11 +4,9 @@
4
4
 
5
5
  # Caelence agent
6
6
 
7
- A coding agent on this machine
7
+ A coding agent that runs on this machine, as a desktop app or as a terminal UI.
8
8
 
9
- Desktop app, or the terminal.
10
-
11
- [`@useavalon/caelence-agent`](https://www.npmjs.com/package/@useavalon/caelence-agent) on npm. Needs [Bun](https://bun.sh) 1.2 or later.
9
+ The package is [`@useavalon/caelence-agent`](https://www.npmjs.com/package/@useavalon/caelence-agent) on npm and needs [Bun](https://bun.sh) 1.2 or later.
12
10
 
13
11
  ## Install
14
12
 
@@ -17,23 +15,24 @@ bun add -g @useavalon/caelence-agent
17
15
  caelence desktop
18
16
  ```
19
17
 
20
- `caelence desktop` opens the OS window. Paste an OpenRouter key in **Settings** after it opens. You do not need to export `OPENROUTER_API_KEY` in the terminal. The window needs [Rust](https://rustup.rs).
18
+ `caelence desktop` starts the desktop app, and you paste an OpenRouter key in Settings. The window build needs [Rust](https://rustup.rs) on the machine.
21
19
 
22
20
  <p align="center">
23
21
  <img src="brand/previews/desktop-chat.png" alt="Desktop chat" width="720" />
24
22
  </p>
25
23
 
26
- Or the terminal:
24
+ For the terminal UI:
27
25
 
28
26
  ```bash
27
+ export OPENROUTER_API_KEY=…
29
28
  caelence
30
29
  ```
31
30
 
32
- `caelence` opens the terminal UI. Paste an OpenRouter key with `/settings key <token>`. In a git repo, that repo is the workspace. `--cwd` picks a folder. `caelence-agent` and `harness` are the same CLI.
31
+ `caelence` starts the terminal UI. Run it from a git repository and that repo is the project; otherwise files are kept under `~/.harness/workspace`. `--cwd` overrides both. `caelence-agent` and `harness` are the same command.
33
32
 
34
33
  ## Config
35
34
 
36
- Optional. Without `harness.config.ts`, these defaults apply.
35
+ You can run with no config file, in which case the defaults below apply. To change them, add `harness.config.ts` at the project root:
37
36
 
38
37
  ```ts
39
38
  import type { HarnessConfig } from "@useavalon/caelence-agent";
@@ -61,7 +60,7 @@ export default {
61
60
  | `.harness/sessions/` | Session logs |
62
61
  | `~/.harness/integrations.json` | Connected hosted MCP servers |
63
62
 
64
- Desktop Settings stores a key in `~/.harness`. Optional env: `OPENROUTER_API_KEY`, `OPENROUTER_MODEL`, `OPENROUTER_BASE_URL`. In the TUI, `/settings key <token>` does the same.
63
+ The desktop stores the OpenRouter key in `~/.harness`. The terminal UI reads `OPENROUTER_API_KEY`, and optionally `OPENROUTER_MODEL` and `OPENROUTER_BASE_URL`.
65
64
 
66
65
  ## Commands
67
66
 
@@ -79,11 +78,13 @@ caelence skill remove <name> Uninstall a user skill, or disable a project skill
79
78
  caelence help This list
80
79
  ```
81
80
 
82
- Flags: `--mode ask|plan|agent`, `--cwd <path>`, `-m` / `--message <text>`. `caelence init --examples` writes a host scaffold (`--name` sets the config name).
81
+ Flags: `--mode ask|plan|agent`, `--cwd <path>`, `-m` / `--message <text>`.
82
+
83
+ `caelence chat -m` is the non-interactive path for scripts and CI: it sends one message, prints the reply and any tool lines, then exits without opening the desktop or the terminal UI. `--mode` still applies, and if stdin is not a TTY, tool approval is deny.
83
84
 
84
- `caelence chat -m "…"` runs one turn, prints the reply (and tool lines), then exits. For a script or CI: no desktop, no TUI. `--mode` still applies. Without a TTY, tool approval is deny.
85
+ `caelence init` only appends `.harness/` to `.gitignore` so session logs are not committed. If you want a starter host project, `caelence init --examples` writes a sample `harness.config.ts`, `AGENTS.md`, a skill, and an eval, with `--name` setting the config name.
85
86
 
86
- Type `/` for slash commands. Tab completes in the terminal UI.
87
+ In the desktop and the terminal UI, `/` opens slash commands, and Tab completes them in the terminal.
87
88
 
88
89
  <p align="center">
89
90
  <img src="brand/previews/desktop-commands.png" alt="Desktop slash commands" width="720" />
@@ -110,11 +111,13 @@ Type `/` for slash commands. Tab completes in the terminal UI.
110
111
  /exit quit
111
112
  ```
112
113
 
113
- `/skill add --project <name>` writes into the project `skillsDir`. `/skill new <name> <what it should do>` authors a project skill from a brief.
114
+ `/skill add --project` installs into the project's `skillsDir` rather than the user store. `/skill new` takes a name and a short brief and authors a project skill from that.
114
115
 
115
116
  ## Skills
116
117
 
117
- A skill is a `SKILL.md` with YAML `name` and `description`. Skills in `~/.harness/skills` and in the project load; the project wins on name clash. Bundled skills and skills.sh are a catalog: add one and it starts working. The agent also reads `skills/`, `.cursor/skills`, and `.claude/skills` when those folders exist. Disable a project skill from `/skill find` to keep the file and drop it from the prompt.
118
+ A skill is a `SKILL.md` file whose YAML front matter has `name` and `description`. Anything you add from the catalog is copied into `~/.harness/skills`; skills that already live in the current project load as well, and the project copy wins when the names collide.
119
+
120
+ The package also ships a catalog of bundled skills and popular listings from skills.sh, but those are not injected into the prompt until you add them. Once added they behave like any other skill. Existing `skills/`, `.cursor/skills`, and `.claude/skills` folders in the repo are picked up automatically. If you want a project skill on disk but out of the prompt, disable it from `/skill find` instead of deleting the file.
118
121
 
119
122
  <p align="center">
120
123
  <img src="brand/previews/desktop-skills.png" alt="Desktop skills" width="720" />
@@ -127,7 +130,7 @@ A skill is a `SKILL.md` with YAML `name` and `description`. Skills in `~/.harnes
127
130
 
128
131
  ## Integrations
129
132
 
130
- Hosted MCP servers the agent can call. Connect from the desktop sidebar or `/integrations`. Sign-in is in the browser; those tools show up on the next turn.
133
+ Hosted MCP servers show up as extra tools the agent can call. You connect them from the desktop sidebar or with `/integrations` in the terminal; the browser handles sign-in, and the tools are available on the following turn.
131
134
 
132
135
  <p align="center">
133
136
  <img src="brand/previews/desktop-integrations.png" alt="Desktop integrations" width="720" />
@@ -139,9 +142,9 @@ Hosted MCP servers the agent can call. Connect from the desktop sidebar or `/int
139
142
  | Google or Microsoft | Desktop OAuth client in Settings |
140
143
  | Figma | Dev Mode MCP in Figma desktop |
141
144
 
142
- Connections are stored in `~/.harness/integrations.json`. Disconnect removes that row.
145
+ Most catalog servers only need that browser sign-in. Google Workspace and Microsoft 365 need a desktop OAuth client pasted in Settings first, and Figma talks to the Dev Mode MCP server running in Figma desktop.
143
146
 
144
- `mcp` in `harness.config.ts` adds local stdio servers (`command`, `args`, `env`) for this project.
147
+ Each connection is stored in `~/.harness/integrations.json`, and disconnecting removes that row. Local stdio servers are configured separately through `mcp` in `harness.config.ts` (`command`, `args`, `env`).
145
148
 
146
149
  ## Modes
147
150
 
@@ -151,11 +154,11 @@ Connections are stored in `~/.harness/integrations.json`. Disconnect removes tha
151
154
  | `plan` | Ask plus `todo_write` |
152
155
  | `agent` | Writes, `exec`, `git_commit`, and `task` |
153
156
 
154
- `/mode ask`, `/mode plan`, or `/mode agent`. `exec` and `git_commit` ask for approval by default (`prompt`). `auto` still denies destructive commands. Local exec is the host machine, not a sandbox.
157
+ Start in `ask`, `plan`, or `agent` with `/mode`, which changes which tools are available. `exec` and `git_commit` prompt for approval by default (`prompt`), and `auto` still refuses destructive commands. Local exec is the host machine rather than a sandbox.
155
158
 
156
159
  ## Library
157
160
 
158
- The desktop, TUI, and `caelence chat -m` all call `createHarness`. Call it from your own UI, bot, or script.
161
+ The desktop, the terminal UI, and `caelence chat -m` all call `createHarness`, so you can drive the same runtime from a bot, a script, or another host UI.
159
162
 
160
163
  ```bash
161
164
  bun add @useavalon/caelence-agent
@@ -172,11 +175,9 @@ await harness.runTurn("fix the failing test", (event) => {
172
175
  harness.close();
173
176
  ```
174
177
 
175
- `runTurn` streams `AgentEvent`s (text, tools, usage, errors) and writes the session under `.harness/sessions`. Optional: `config`, `mode`, `provider`, `extraTools`, `approvalPolicy`, `observability`.
178
+ `runTurn` streams `AgentEvent`s (text, tools, usage, errors) while it writes the session under `.harness/sessions`. Optional arguments include `config`, `mode`, `provider`, `extraTools`, `approvalPolicy`, and `observability`: pass a fake provider in tests, add MCP tools of your own through `extraTools`, and implement `approvalAsk` when a host UI needs to prompt for `exec` and `git_commit`.
176
179
 
177
- You can pass a custom model provider in tests. `extraTools` adds MCP tools of your own. `approvalAsk` on `runTurn` is how a host UI prompts for `exec` and `git_commit`.
178
-
179
- Other exports from the same package:
180
+ If you only need types or tracing, `HarnessConfig` / `loadConfig` and the observability entry do not require constructing a harness at all.
180
181
 
181
182
  | Import | Use |
182
183
  |------|------|
@@ -186,8 +187,6 @@ Other exports from the same package:
186
187
  | `initHost` | Add `.harness/` to `.gitignore`. `examples: true` writes a host scaffold |
187
188
  | `@useavalon/caelence-agent/observability` | Langfuse, gates, `runLocalExperiment` |
188
189
 
189
- Config types and observability do not require `createHarness`.
190
-
191
190
  ## License
192
191
 
193
192
  [MIT](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.1.1-canary.1",
3
+ "version": "0.2.0",
4
4
  "description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/cli/main.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
- import { resolve } from "node:path";
3
+ import { homedir } from "node:os";
4
+ import { dirname, resolve } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { resolveAgentCwd } from "../agent-cwd.ts";
6
7
  import { loadConfig, resolveOpenRouter } from "../config.ts";
@@ -117,18 +118,24 @@ function desktopToolchainEnv(desktopDir: string, cwd: string): NodeJS.ProcessEnv
117
118
  const cargoHome = resolve(desktopDir, ".toolchain/cargo");
118
119
  const rustupHome = resolve(desktopDir, ".toolchain/rustup");
119
120
  const cargoBin = resolve(cargoHome, "bin");
121
+ const bunDir = dirname(process.execPath);
122
+ const systemCargoBin = resolve(homedir(), ".cargo/bin");
120
123
  const env: NodeJS.ProcessEnv = { ...process.env, HARNESS_CWD: cwd };
124
+ const pathDirs = [bunDir];
121
125
  if (existsSync(resolve(cargoBin, "cargo"))) {
122
126
  env.CARGO_HOME = cargoHome;
123
127
  env.RUSTUP_HOME = rustupHome;
124
- env.PATH = `${cargoBin}:${env.PATH ?? ""}`;
128
+ pathDirs.unshift(cargoBin);
129
+ } else if (existsSync(resolve(systemCargoBin, "cargo"))) {
130
+ pathDirs.unshift(systemCargoBin);
125
131
  }
132
+ env.PATH = pathDirs.join(":");
126
133
  return env;
127
134
  }
128
135
 
129
136
  function hasCargo(env: NodeJS.ProcessEnv): boolean {
130
137
  if (env.CARGO_HOME && existsSync(resolve(env.CARGO_HOME, "bin/cargo"))) return true;
131
- return (env.PATH ?? "").split(":").some((dir) => dir && existsSync(resolve(dir, "cargo")));
138
+ return existsSync(resolve(homedir(), ".cargo/bin/cargo"));
132
139
  }
133
140
 
134
141
  function takeFlag(args: string[], name: string): { value?: string; rest: string[] } {
@@ -200,7 +207,7 @@ async function runDesktop(cwd: string): Promise<number> {
200
207
  );
201
208
  return 1;
202
209
  }
203
- const child = spawn("bun", [resolve(desktopDir, "scripts/run-tauri.ts")], {
210
+ const child = spawn(process.execPath, [resolve(desktopDir, "scripts/run-tauri.ts")], {
204
211
  cwd: desktopDir,
205
212
  env,
206
213
  stdio: "inherit",
@@ -251,7 +258,10 @@ async function runSkillAdd(
251
258
  ...(action.skill ? { skill: action.skill } : {}),
252
259
  });
253
260
  if ("error" in result) {
254
- const extra = result.choices?.length ? ` Available: ${result.choices.join(", ")}` : "";
261
+ const extra =
262
+ result.choices && result.choices.length > 1 && result.choices.length <= 8
263
+ ? ` Available: ${result.choices.join(", ")}`
264
+ : "";
255
265
  process.stderr.write(`${result.error}${extra}\n`);
256
266
  return 1;
257
267
  }
@@ -220,7 +220,7 @@ describe("dispatchSlash", () => {
220
220
  expect(result.picker).toBe("skill");
221
221
  expect(result.title).toBe("Skills");
222
222
  expect(result.items.some((item) => item.id === "bundled@copywriting")).toBe(true);
223
- expect(result.items.some((item) => item.id === "acme/pack@hello")).toBe(true);
223
+ expect(result.items.some((item) => item.id === "acme/pack/hello")).toBe(true);
224
224
  }
225
225
  } finally {
226
226
  clearPopularSkillsCache();
@@ -15,7 +15,14 @@ import { type GeneratedMedia, generateImage, generateVideo } from "../media/open
15
15
  import { readMediaPrefs, writeMediaPrefs } from "../media/prefs.ts";
16
16
  import type { HarnessRuntime } from "../runtime.ts";
17
17
  import { browseSkillCatalog } from "../skills/catalog.ts";
18
- import { searchSkillCatalog, skillCatalogRef, skillIsCatalogHit } from "../skills/registry.ts";
18
+ import {
19
+ findSkillForCatalogId,
20
+ isBundledCatalogId,
21
+ searchSkillCatalog,
22
+ skillCatalogRef,
23
+ skillIsCatalogHit,
24
+ skillNameFromCatalogId,
25
+ } from "../skills/registry.ts";
19
26
  import { parseSkillCommand, SKILL_COMMAND_USAGE } from "../skills/skill-command.ts";
20
27
  import { type MediaModelOption, mediaModelLabel, mediaPickerItems } from "./media-models.ts";
21
28
  import { modelPickerItems } from "./models.ts";
@@ -204,6 +211,38 @@ async function handleSkillFind(harness: HarnessRuntime, query: string): Promise<
204
211
  };
205
212
  }
206
213
 
214
+ async function handleSkillAdd(
215
+ harness: HarnessRuntime,
216
+ parsed: Extract<ReturnType<typeof parseSkillCommand>, { action: "add" }>,
217
+ ): Promise<SlashOutcome> {
218
+ const result = await harness.addSkill(parsed.source, {
219
+ scope: parsed.scope,
220
+ ...(parsed.skill ? { skill: parsed.skill } : {}),
221
+ });
222
+ return { kind: "text", text: "error" in result ? result.error : `Loaded ${result.rel}` };
223
+ }
224
+
225
+ async function handleSkillRemove(
226
+ harness: HarnessRuntime,
227
+ parsed: Extract<ReturnType<typeof parseSkillCommand>, { action: "remove" }>,
228
+ ): Promise<SlashOutcome> {
229
+ const loaded = findSkillForCatalogId(harness.skills, parsed.name);
230
+ const result = harness.removeSkill(parsed.name);
231
+ const verb = loaded && loaded.source !== "user" ? "Disabled" : "Removed";
232
+ return {
233
+ kind: "text",
234
+ text: result.ok ? `${verb} ${parsed.name}` : (result.error ?? "Could not remove."),
235
+ };
236
+ }
237
+
238
+ async function handleSkillNew(
239
+ harness: HarnessRuntime,
240
+ parsed: Extract<ReturnType<typeof parseSkillCommand>, { action: "new" }>,
241
+ ): Promise<SlashOutcome> {
242
+ const result = await harness.authorSkill(parsed.name, parsed.brief);
243
+ return { kind: "text", text: "error" in result ? result.error : `Wrote ${result.rel}` };
244
+ }
245
+
207
246
  async function handleSkillSlash(
208
247
  harness: HarnessRuntime,
209
248
  arg: string,
@@ -213,28 +252,9 @@ async function handleSkillSlash(
213
252
  const parsed = parseSkillCommand(payload);
214
253
  if ("error" in parsed) return { kind: "text", text: parsed.error };
215
254
  if (parsed.action === "find") return handleSkillFind(harness, parsed.query);
216
- if (parsed.action === "add") {
217
- const result = await harness.addSkill(parsed.source, {
218
- scope: parsed.scope,
219
- ...(parsed.skill ? { skill: parsed.skill } : {}),
220
- });
221
- return { kind: "text", text: "error" in result ? result.error : `Loaded ${result.rel}` };
222
- }
223
- if (parsed.action === "remove") {
224
- const loaded = harness.skills.find(
225
- (skill) => skill.name.toLowerCase() === parsed.name.toLowerCase(),
226
- );
227
- const result = harness.removeSkill(parsed.name);
228
- const verb = loaded && loaded.source !== "user" ? "Disabled" : "Removed";
229
- return {
230
- kind: "text",
231
- text: result.ok ? `${verb} ${parsed.name}` : (result.error ?? "Could not remove."),
232
- };
233
- }
234
- if (parsed.action === "new") {
235
- const result = await harness.authorSkill(parsed.name, parsed.brief);
236
- return { kind: "text", text: "error" in result ? result.error : `Wrote ${result.rel}` };
237
- }
255
+ if (parsed.action === "add") return handleSkillAdd(harness, parsed);
256
+ if (parsed.action === "remove") return handleSkillRemove(harness, parsed);
257
+ if (parsed.action === "new") return handleSkillNew(harness, parsed);
238
258
  return { kind: "text", text: SKILL_COMMAND_USAGE };
239
259
  }
240
260
 
@@ -408,18 +428,14 @@ async function applySkillPicker(
408
428
  harness: HarnessRuntime,
409
429
  id: string,
410
430
  ): Promise<{ kind: "text"; text: string }> {
411
- const name = id.split("@").pop()?.trim() ?? id;
412
- if (harness.disabledSkills().some((entry) => entry === name.toLowerCase())) {
431
+ const name = skillNameFromCatalogId(id);
432
+ if (isBundledCatalogId(id) && harness.disabledSkills().includes(name.toLowerCase())) {
413
433
  harness.enableSkill(name);
414
434
  return { kind: "text", text: `Enabled ${name}` };
415
435
  }
416
- const loaded =
417
- harness.skills.find((skill) => skill.catalogRef === id) ??
418
- harness.skills.find(
419
- (skill) => skill.source !== "user" && skill.name.toLowerCase() === name.toLowerCase(),
420
- );
436
+ const loaded = findSkillForCatalogId(harness.skills, id);
421
437
  if (loaded) {
422
- const result = harness.removeSkill(loaded.name);
438
+ const result = harness.removeSkill(loaded.catalogRef ?? loaded.name);
423
439
  const verb = loaded.source === "user" ? "Removed" : "Disabled";
424
440
  return {
425
441
  kind: "text",
@@ -33,7 +33,12 @@ import {
33
33
  refreshPopularSkills,
34
34
  withDisabledCatalogSkills,
35
35
  } from "../skills/catalog.ts";
36
- import { searchSkillCatalog } from "../skills/registry.ts";
36
+ import {
37
+ findSkillForCatalogId,
38
+ isBundledCatalogId,
39
+ searchSkillCatalog,
40
+ skillNameFromCatalogId,
41
+ } from "../skills/registry.ts";
37
42
  import { openResolvedPath, resolveLocalPath } from "./open-local.ts";
38
43
  import { readPreviewCache, writePreviewCache } from "./preview-cache.ts";
39
44
  import { applyStoredOpenRouterKey, maskSecret, writeOpenRouterKey } from "./secrets.ts";
@@ -423,20 +428,16 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
423
428
  const body = await readJson(req);
424
429
  const id = typeof body.id === "string" ? body.id.trim() : "";
425
430
  if (!id) return json({ error: "id is required." }, 400);
426
- const name = id.split("@").pop()?.trim() ?? id;
427
- if (harness.disabledSkills().some((entry) => entry === name.toLowerCase())) {
431
+ const name = skillNameFromCatalogId(id);
432
+ if (isBundledCatalogId(id) && harness.disabledSkills().includes(name.toLowerCase())) {
428
433
  harness.enableSkill(name);
429
434
  return json({ ok: true, ...skillsPage() });
430
435
  }
431
- const loaded =
432
- harness.skills.find((skill) => skill.catalogRef === id) ??
433
- harness.skills.find(
434
- (skill) => skill.source !== "user" && skill.name.toLowerCase() === name.toLowerCase(),
435
- );
436
- if (loaded && loaded.source !== "user") {
436
+ const loaded = findSkillForCatalogId(harness.skills, id);
437
+ if (loaded?.source !== "user" && loaded) {
437
438
  return json({ error: `${loaded.name} is already in the project.` }, 400);
438
439
  }
439
- if (!loaded || loaded.catalogRef !== id) {
440
+ if (!loaded) {
440
441
  const result = await harness.addSkill(id);
441
442
  if ("error" in result) return json({ error: result.error }, 400);
442
443
  }
@@ -447,9 +448,9 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
447
448
  const body = await readJson(req);
448
449
  const id = typeof body.id === "string" ? body.id.trim() : "";
449
450
  const name =
450
- (typeof body.name === "string" ? body.name.trim() : "") || id.split("@").pop()?.trim() || "";
451
+ (typeof body.name === "string" ? body.name.trim() : "") || id || skillNameFromCatalogId(id);
451
452
  if (!name) return json({ error: "name is required." }, 400);
452
- const result = harness.removeSkill(name);
453
+ const result = harness.removeSkill(id || name);
453
454
  if (!result.ok) return json({ error: result.error ?? "Could not remove." }, 400);
454
455
  return json({ ok: true, ...skillsPage() });
455
456
  };
package/src/index.ts CHANGED
@@ -129,6 +129,8 @@ export {
129
129
  export {
130
130
  BUNDLED_PACKS,
131
131
  bundledRegistryHits,
132
+ catalogRefsMatch,
133
+ findSkillForCatalogId,
132
134
  formatRegistryHits,
133
135
  installBundledSkills,
134
136
  installSkillFromSource,
@@ -140,6 +142,7 @@ export {
140
142
  searchSkillsSh,
141
143
  skillCatalogRef,
142
144
  skillIsCatalogHit,
145
+ skillNameFromCatalogId,
143
146
  } from "./skills/registry.ts";
144
147
  export { parseSkillCommand, SKILL_COMMAND_USAGE, SKILL_FIND_HINT } from "./skills/skill-command.ts";
145
148
  export { userSkillsDir } from "./skills/user-dir.ts";
package/src/runtime.ts CHANGED
@@ -59,7 +59,14 @@ import {
59
59
  type Skill,
60
60
  skillCatalogPrompt,
61
61
  } from "./skills/loader.ts";
62
- import { installSkillFromSource, removeSkillFromRoots, searchSkills } from "./skills/registry.ts";
62
+ import {
63
+ findSkillForCatalogId,
64
+ installSkillFromSource,
65
+ isBundledCatalogId,
66
+ removeSkillFromRoots,
67
+ searchSkills,
68
+ skillNameFromCatalogId,
69
+ } from "./skills/registry.ts";
63
70
  import { userSkillsDir } from "./skills/user-dir.ts";
64
71
  import { createGitTools } from "./tools/git.ts";
65
72
  import { createLocalTools } from "./tools/local.ts";
@@ -338,8 +345,8 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
338
345
  return { ok: true };
339
346
  },
340
347
  async addSkill(source, options) {
341
- const name = source.split("@").pop()?.trim() ?? source;
342
- if (isSkillDisabled(cwd, name)) {
348
+ const name = skillNameFromCatalogId(source);
349
+ if (isBundledCatalogId(source) && name && isSkillDisabled(cwd, name)) {
343
350
  runtime.enableSkill(name);
344
351
  return { rel: name };
345
352
  }
@@ -351,7 +358,10 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
351
358
  ...(options?.skill ? { skill: options.skill } : {}),
352
359
  });
353
360
  if ("error" in result) {
354
- const extra = result.choices?.length ? ` Available: ${result.choices.join(", ")}` : "";
361
+ const extra =
362
+ result.choices && result.choices.length > 1 && result.choices.length <= 8
363
+ ? ` Available: ${result.choices.join(", ")}`
364
+ : "";
355
365
  return { error: `${result.error}${extra}` };
356
366
  }
357
367
  runtime.reloadSkills();
@@ -365,13 +375,13 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
365
375
  return { rel: `${root}/${result.rel}` };
366
376
  },
367
377
  removeSkill(name) {
368
- const loaded = skills.find((skill) => skill.name.toLowerCase() === name.trim().toLowerCase());
378
+ const loaded = findSkillForCatalogId(skills, name);
369
379
  if (loaded && loaded.source !== "user") {
370
380
  disableSkills(cwd, loaded.name);
371
381
  runtime.reloadSkills();
372
382
  return { ok: true };
373
383
  }
374
- const result = removeSkillFromRoots(name, removableRoots());
384
+ const result = removeSkillFromRoots(loaded?.catalogRef ?? name, removableRoots());
375
385
  if (!result.removed) return { ok: false, error: result.reason };
376
386
  runtime.reloadSkills();
377
387
  return { ok: true };
@@ -15,9 +15,11 @@ import {
15
15
  skillBlurb,
16
16
  writePopularSkillsCache,
17
17
  } from "./catalog.ts";
18
+ import { clearGithubSkillFolderCache } from "./registry.ts";
18
19
 
19
20
  afterEach(() => {
20
21
  clearPopularSkillsCache();
22
+ clearGithubSkillFolderCache();
21
23
  });
22
24
 
23
25
  describe("catalog skills", () => {
@@ -57,7 +59,7 @@ describe("catalog skills", () => {
57
59
  loaded,
58
60
  );
59
61
  expect(remote).toMatchObject({
60
- id: "anthropics/skills@frontend-design",
62
+ id: "anthropics/skills/frontend-design",
61
63
  status: "user",
62
64
  origin: "skills.sh",
63
65
  installs: 10,
@@ -97,6 +99,9 @@ describe("catalog skills", () => {
97
99
  );
98
100
  expect(anthropics.status).toBe("user");
99
101
  expect(other.status).toBe("off");
102
+ expect(anthropics.source).toBe("anthropics/skills");
103
+ expect(other.source).toBe("pbakaus/impeccable");
104
+ expect(anthropics.id).not.toBe(other.id);
100
105
  });
101
106
 
102
107
  test("page lists bundled skills and extra user skills separately", () => {
@@ -134,11 +139,13 @@ describe("catalog skills", () => {
134
139
  expect(cached.hits[0]?.name).toBe("hello");
135
140
  expect(cachedPopularSkills(process.env)[0]?.name).toBe("hello");
136
141
 
137
- let called = 0;
142
+ let searched = 0;
138
143
  const hits = await refreshPopularSkills(async (url) => {
139
- called += 1;
140
- expect(url).toContain("q=frontend");
141
- expect(url).toContain("limit=16");
144
+ const href = String(url);
145
+ if (href.includes("/git/trees/")) return new Response("missing", { status: 404 });
146
+ searched += 1;
147
+ expect(href).toContain("q=frontend");
148
+ expect(href).toContain("limit=16");
142
149
  return Response.json({
143
150
  skills: [
144
151
  {
@@ -150,7 +157,7 @@ describe("catalog skills", () => {
150
157
  ],
151
158
  });
152
159
  }, process.env);
153
- expect(called).toBe(1);
160
+ expect(searched).toBe(1);
154
161
  expect(hits[0]).toMatchObject({ name: "hello", installs: 99 });
155
162
  } finally {
156
163
  if (prev === undefined) delete process.env.HARNESS_HOME;
@@ -185,4 +192,46 @@ describe("catalog skills", () => {
185
192
  await rm(home, { recursive: true, force: true });
186
193
  }
187
194
  });
195
+
196
+ test("browse drops cached skills.sh names missing from the GitHub repo", async () => {
197
+ const home = await mkdtemp(join(tmpdir(), "harness-browse-ghost-"));
198
+ const prev = process.env.HARNESS_HOME;
199
+ process.env.HARNESS_HOME = home;
200
+ try {
201
+ writePopularSkillsCache(
202
+ [
203
+ {
204
+ id: "openai/skills/frontend-skill",
205
+ name: "frontend-skill",
206
+ source: "openai/skills",
207
+ installs: 1600,
208
+ },
209
+ {
210
+ id: "openai/skills/chatgpt-apps",
211
+ name: "chatgpt-apps",
212
+ source: "openai/skills",
213
+ installs: 12,
214
+ },
215
+ ],
216
+ process.env,
217
+ );
218
+ const hits = await browseSkillCatalog(async (url) => {
219
+ if (String(url).includes("/repos/openai/skills/git/trees/")) {
220
+ return Response.json({
221
+ tree: [
222
+ { path: "skills/aspnet-core/SKILL.md", type: "blob" },
223
+ { path: "skills/chatgpt-apps/SKILL.md", type: "blob" },
224
+ ],
225
+ });
226
+ }
227
+ throw new Error(`unexpected ${url}`);
228
+ }, process.env);
229
+ expect(hits.some((hit) => hit.name === "frontend-skill")).toBe(false);
230
+ expect(hits.some((hit) => hit.name === "chatgpt-apps")).toBe(true);
231
+ } finally {
232
+ if (prev === undefined) delete process.env.HARNESS_HOME;
233
+ else process.env.HARNESS_HOME = prev;
234
+ await rm(home, { recursive: true, force: true });
235
+ }
236
+ });
188
237
  });
@@ -4,7 +4,10 @@ import { harnessHome } from "../desktop/secrets.ts";
4
4
  import {
5
5
  bundledPackStepNames,
6
6
  bundledRegistryHits,
7
+ dropUninstallableCatalogHits,
7
8
  type FetchLike,
9
+ filterGithubCatalogHits,
10
+ isInstallableSkillsShHit,
8
11
  type RegistryHit,
9
12
  searchSkillsSh,
10
13
  skillCatalogRef,
@@ -114,6 +117,7 @@ export function decorateCatalogSkill(
114
117
  ): CatalogSkill {
115
118
  const current = loaded.find((skill) => skillIsCatalogHit(skill, hit));
116
119
  const off = new Set([...disabled].map((name) => name.toLowerCase()));
120
+ const disabledHit = hit.source === "bundled" && off.has(hit.name.toLowerCase());
117
121
  return {
118
122
  id: skillCatalogRef(hit),
119
123
  name: hit.name,
@@ -121,10 +125,18 @@ export function decorateCatalogSkill(
121
125
  origin: hit.source === "bundled" ? "bundled" : "skills.sh",
122
126
  source: hit.source === "host" ? "project" : hit.source,
123
127
  ...(typeof hit.installs === "number" ? { installs: hit.installs } : {}),
124
- status: catalogStatus(current, off.has(hit.name.toLowerCase())),
128
+ status: catalogStatus(current, disabledHit),
125
129
  };
126
130
  }
127
131
 
132
+ function catalogOwnerRepo(ref?: string): string {
133
+ const value = ref?.trim();
134
+ if (!value || /^(bundled|user|host|project)[@/]/i.test(value)) return "";
135
+ const parts = value.replaceAll("@", "/").split("/").filter(Boolean);
136
+ if (parts.length >= 2) return `${parts[0]}/${parts[1]}`;
137
+ return "";
138
+ }
139
+
128
140
  export function buildSkillsPage(
129
141
  loaded: Array<{ name: string; source: string; description?: string; catalogRef?: string }>,
130
142
  popularHits: RegistryHit[],
@@ -133,22 +145,23 @@ export function buildSkillsPage(
133
145
  const bundled = bundledSkillHits().map((hit) => decorateCatalogSkill(hit, loaded, disabled));
134
146
  const bundledNames = new Set(bundled.map((item) => item.name.toLowerCase()));
135
147
  const steps = bundledPackStepNames();
136
- const popular = popularHits
148
+ const popular = dropUninstallableCatalogHits(popularHits)
137
149
  .filter((hit) => hit.source !== "bundled" && !bundledNames.has(hit.name.toLowerCase()))
138
150
  .map((hit) => decorateCatalogSkill(hit, loaded, disabled));
139
- const seen = new Set([...bundledNames, ...popular.map((item) => item.name.toLowerCase())]);
151
+ const listed = [...bundledSkillHits(), ...popularHits];
140
152
  const extra = loaded
141
153
  .filter((skill) => {
142
154
  const key = skill.name.toLowerCase();
143
155
  if (steps.has(key)) return false;
144
- return !seen.has(key);
156
+ return !listed.some((hit) => skillIsCatalogHit(skill, hit));
145
157
  })
146
158
  .map((skill) =>
147
159
  decorateCatalogSkill(
148
160
  {
149
161
  id: skill.catalogRef ?? `${skill.source}/${skill.name}`,
150
162
  name: skill.name,
151
- source: skill.source === "user" ? "user" : "project",
163
+ source:
164
+ catalogOwnerRepo(skill.catalogRef) || (skill.source === "user" ? "user" : "project"),
152
165
  description: skill.description ?? "",
153
166
  },
154
167
  loaded,
@@ -178,7 +191,7 @@ function parseHitRow(row: unknown): RegistryHit | undefined {
178
191
  const name = typeof item.name === "string" ? item.name.trim() : "";
179
192
  const source = typeof item.source === "string" ? item.source.trim() : "";
180
193
  const id = typeof item.id === "string" ? item.id.trim() : "";
181
- if (!name || !source) return undefined;
194
+ if (!name || !source || !isInstallableSkillsShHit({ source })) return undefined;
182
195
  return {
183
196
  id: id || `${source}/${name}`,
184
197
  name,
@@ -251,10 +264,16 @@ export async function browseSkillCatalog(
251
264
  const cached = readPopularSkillsCache(env);
252
265
  const popular = cached.stale ? await refreshPopularSkills(fetchFn, env) : cached.hits;
253
266
  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
- ];
267
+ const remote = await filterGithubCatalogHits(
268
+ popular.filter(
269
+ (hit) =>
270
+ hit.source !== "bundled" &&
271
+ isInstallableSkillsShHit(hit) &&
272
+ !seen.has(hit.name.toLowerCase()),
273
+ ),
274
+ fetchFn,
275
+ );
276
+ return [...bundled, ...remote];
258
277
  }
259
278
 
260
279
  export async function refreshPopularSkills(