@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 +24 -25
- package/package.json +1 -1
- package/src/cli/main.ts +15 -5
- package/src/cli/slash-dispatch.test.ts +1 -1
- package/src/cli/slash-dispatch.ts +47 -31
- package/src/desktop/bridge.ts +13 -12
- package/src/index.ts +3 -0
- package/src/runtime.ts +16 -6
- package/src/skills/catalog.test.ts +55 -6
- package/src/skills/catalog.ts +29 -10
- package/src/skills/loader.test.ts +32 -0
- package/src/skills/loader.ts +58 -27
- package/src/skills/registry.test.ts +423 -7
- package/src/skills/registry.ts +539 -50
- package/src/tools/read-skill.ts +35 -11
- package/src/tools/subagent.test.ts +29 -0
package/src/tools/read-skill.ts
CHANGED
|
@@ -2,18 +2,46 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { errorResult, type McpToolDefinition, textResult } from "../core/mcp.ts";
|
|
4
4
|
import type { Skill } from "../skills/loader.ts";
|
|
5
|
+
import { catalogRefsMatch, skillNameFromCatalogId } from "../skills/registry.ts";
|
|
5
6
|
import { PathEscapeError, resolveUnderCwd } from "./paths.ts";
|
|
6
7
|
|
|
8
|
+
function resolveSkill(skills: Skill[], name: string): Skill | { error: string } {
|
|
9
|
+
const wanted = name.trim();
|
|
10
|
+
if (!wanted) return { error: "name is empty" };
|
|
11
|
+
const byRef = skills.filter(
|
|
12
|
+
(skill) => skill.catalogRef && catalogRefsMatch(skill.catalogRef, wanted),
|
|
13
|
+
);
|
|
14
|
+
if (byRef.length === 1 && byRef[0]) return byRef[0];
|
|
15
|
+
const yaml = skillNameFromCatalogId(wanted).toLowerCase() || wanted.toLowerCase();
|
|
16
|
+
const byName = skills.filter((skill) => skill.name.toLowerCase() === yaml);
|
|
17
|
+
if (byName.length === 1 && byName[0]) return byName[0];
|
|
18
|
+
if (byName.length > 1) {
|
|
19
|
+
const ids = byName.map((skill) => skill.catalogRef || skill.name).join(", ");
|
|
20
|
+
return {
|
|
21
|
+
error: `Several skills named ${JSON.stringify(wanted)}. Use one of: ${ids}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const known =
|
|
25
|
+
skills
|
|
26
|
+
.map((skill) => skill.catalogRef || skill.name)
|
|
27
|
+
.toSorted((left, right) => left.localeCompare(right))
|
|
28
|
+
.join(", ") || "(none)";
|
|
29
|
+
return { error: `Unknown skill ${JSON.stringify(name)}. Loaded: ${known}` };
|
|
30
|
+
}
|
|
31
|
+
|
|
7
32
|
export function createReadSkillTool(skills: Skill[]): McpToolDefinition {
|
|
8
|
-
const byName = new Map(skills.map((s) => [s.name.toLowerCase(), s]));
|
|
9
33
|
return {
|
|
10
34
|
name: "read_skill",
|
|
11
35
|
description:
|
|
12
|
-
"Read a loaded skill by name (user or project). Optional `file` reads a reference next to that skill (e.g. references/anti-slop.md). Prefer this over guessing skill contents.",
|
|
36
|
+
"Read a loaded skill by name or catalog id (user or project). Optional `file` reads a reference next to that skill (e.g. references/anti-slop.md). Prefer this over guessing skill contents.",
|
|
13
37
|
inputSchema: {
|
|
14
38
|
type: "object",
|
|
15
39
|
properties: {
|
|
16
|
-
name: {
|
|
40
|
+
name: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description:
|
|
43
|
+
"Skill name or catalog id from the prompt (e.g. copywriting or anthropics/skills/frontend-design).",
|
|
44
|
+
},
|
|
17
45
|
file: {
|
|
18
46
|
type: "string",
|
|
19
47
|
description: "Optional path relative to that skill's folder.",
|
|
@@ -23,16 +51,12 @@ export function createReadSkillTool(skills: Skill[]): McpToolDefinition {
|
|
|
23
51
|
},
|
|
24
52
|
async handler(raw) {
|
|
25
53
|
const name = typeof raw.name === "string" ? raw.name.trim() : "";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!skill) {
|
|
29
|
-
const known = [...byName.keys()].sort().join(", ") || "(none)";
|
|
30
|
-
return errorResult(`Unknown skill ${JSON.stringify(name)}. Loaded: ${known}`);
|
|
31
|
-
}
|
|
54
|
+
const matched = resolveSkill(skills, name);
|
|
55
|
+
if ("error" in matched) return errorResult(matched.error);
|
|
32
56
|
const file = typeof raw.file === "string" ? raw.file.trim() : "";
|
|
33
|
-
if (!file) return textResult(`# ${
|
|
57
|
+
if (!file) return textResult(`# ${matched.name}\n\n${matched.body}`);
|
|
34
58
|
try {
|
|
35
|
-
const abs = resolveUnderCwd(dirname(
|
|
59
|
+
const abs = resolveUnderCwd(dirname(matched.path), file);
|
|
36
60
|
return textResult(readFileSync(abs, "utf8"));
|
|
37
61
|
} catch (err) {
|
|
38
62
|
if (err instanceof PathEscapeError) return errorResult(err.message);
|
|
@@ -33,6 +33,35 @@ describe("read_skill", () => {
|
|
|
33
33
|
const missing = await tool.handler({ name: "not-a-skill" });
|
|
34
34
|
expect(missing.isError).toBe(true);
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
test("asks for a catalog id when two loaded skills share a YAML name", async () => {
|
|
38
|
+
const tool = createReadSkillTool([
|
|
39
|
+
{
|
|
40
|
+
name: "frontend-design",
|
|
41
|
+
description: "a",
|
|
42
|
+
body: "# Acme",
|
|
43
|
+
path: "/tmp/acme/SKILL.md",
|
|
44
|
+
relPath: "acme/SKILL.md",
|
|
45
|
+
source: "user",
|
|
46
|
+
catalogRef: "acme/pack/frontend-design",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "frontend-design",
|
|
50
|
+
description: "b",
|
|
51
|
+
body: "# Other",
|
|
52
|
+
path: "/tmp/other/SKILL.md",
|
|
53
|
+
relPath: "other/SKILL.md",
|
|
54
|
+
source: "user",
|
|
55
|
+
catalogRef: "other/ui/frontend-design",
|
|
56
|
+
},
|
|
57
|
+
]);
|
|
58
|
+
const ambiguous = await tool.handler({ name: "frontend-design" });
|
|
59
|
+
expect(ambiguous.isError).toBe(true);
|
|
60
|
+
expect(ambiguous.content[0]?.text).toContain("acme/pack/frontend-design");
|
|
61
|
+
const picked = await tool.handler({ name: "other/ui/frontend-design" });
|
|
62
|
+
expect(picked.isError).toBeFalsy();
|
|
63
|
+
expect(picked.content[0]?.text).toContain("# Other");
|
|
64
|
+
});
|
|
36
65
|
});
|
|
37
66
|
|
|
38
67
|
describe("task subagent", () => {
|