Skip to content

Commit 976d8e9

Browse files
Shivamclaude
authored andcommitted
fix(skills): deduplicate slash commands by skillName across all interfaces
Move skill-command deduplication by skillName from the Discord-only `dedupeSkillCommandsForDiscord` into `listSkillCommandsForAgents` so every interface (TUI, Slack, text) consistently sees a clean command list without platform-specific workarounds. When multiple agents share a skill with the same name the old code emitted `github` + `github_2` and relied on Discord to collapse them. Now `listSkillCommandsForAgents` returns only the first registration per skillName, and the Discord-specific wrapper is removed. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 61b3246 commit 976d8e9

File tree

4 files changed

+70
-49
lines changed

4 files changed

+70
-49
lines changed

src/auto-reply/skill-commands.test.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ vi.mock("../agents/skills.js", () => {
6262

6363
let listSkillCommandsForAgents: typeof import("./skill-commands.js").listSkillCommandsForAgents;
6464
let resolveSkillCommandInvocation: typeof import("./skill-commands.js").resolveSkillCommandInvocation;
65+
let skillCommandsTesting: typeof import("./skill-commands.js").__testing;
6566

6667
beforeAll(async () => {
67-
({ listSkillCommandsForAgents, resolveSkillCommandInvocation } =
68+
({ listSkillCommandsForAgents, resolveSkillCommandInvocation, __testing: skillCommandsTesting } =
6869
await import("./skill-commands.js"));
6970
});
7071

@@ -106,7 +107,7 @@ describe("resolveSkillCommandInvocation", () => {
106107
});
107108

108109
describe("listSkillCommandsForAgents", () => {
109-
it("merges command names across agents and de-duplicates", async () => {
110+
it("deduplicates by skillName across agents, keeping the first registration", async () => {
110111
const baseDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-"));
111112
const mainWorkspace = path.join(baseDir, "main");
112113
const researchWorkspace = path.join(baseDir, "research");
@@ -124,8 +125,45 @@ describe("listSkillCommandsForAgents", () => {
124125
},
125126
});
126127
const names = commands.map((entry) => entry.name);
128+
// demo-skill appears in both workspaces; only the first registration (demo_skill) survives.
127129
expect(names).toContain("demo_skill");
128-
expect(names).toContain("demo_skill_2");
130+
expect(names).not.toContain("demo_skill_2");
131+
// extra-skill is unique to the research workspace and should be present.
129132
expect(names).toContain("extra_skill");
130133
});
131134
});
135+
136+
describe("dedupeBySkillName", () => {
137+
it("keeps the first entry when multiple commands share a skillName", () => {
138+
const input = [
139+
{ name: "github", skillName: "github", description: "GitHub" },
140+
{ name: "github_2", skillName: "github", description: "GitHub" },
141+
{ name: "weather", skillName: "weather", description: "Weather" },
142+
{ name: "weather_2", skillName: "weather", description: "Weather" },
143+
];
144+
const output = skillCommandsTesting.dedupeBySkillName(input);
145+
expect(output.map((e) => e.name)).toEqual(["github", "weather"]);
146+
});
147+
148+
it("matches skillName case-insensitively", () => {
149+
const input = [
150+
{ name: "ClawHub", skillName: "ClawHub", description: "ClawHub" },
151+
{ name: "clawhub_2", skillName: "clawhub", description: "ClawHub" },
152+
];
153+
const output = skillCommandsTesting.dedupeBySkillName(input);
154+
expect(output).toHaveLength(1);
155+
expect(output[0]?.name).toBe("ClawHub");
156+
});
157+
158+
it("passes through commands with an empty skillName", () => {
159+
const input = [
160+
{ name: "a", skillName: "", description: "A" },
161+
{ name: "b", skillName: "", description: "B" },
162+
];
163+
expect(skillCommandsTesting.dedupeBySkillName(input)).toHaveLength(2);
164+
});
165+
166+
it("returns an empty array for empty input", () => {
167+
expect(skillCommandsTesting.dedupeBySkillName([])).toEqual([]);
168+
});
169+
});

src/auto-reply/skill-commands.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ export function listSkillCommandsForWorkspace(params: {
4141
});
4242
}
4343

44+
// Deduplicate skill commands by skillName, keeping the first registration.
45+
// When multiple agents have a skill with the same name (e.g. one with a
46+
// workspace override and one from bundled), the suffix-renamed entries
47+
// (github_2, github_3…) are dropped so every interface sees a clean list.
48+
function dedupeBySkillName(commands: SkillCommandSpec[]): SkillCommandSpec[] {
49+
const seen = new Set<string>();
50+
const out: SkillCommandSpec[] = [];
51+
for (const cmd of commands) {
52+
const key = cmd.skillName.trim().toLowerCase();
53+
if (key && seen.has(key)) {
54+
continue;
55+
}
56+
if (key) {
57+
seen.add(key);
58+
}
59+
out.push(cmd);
60+
}
61+
return out;
62+
}
63+
4464
export function listSkillCommandsForAgents(params: {
4565
cfg: OpenClawConfig;
4666
agentIds?: string[];
@@ -72,9 +92,16 @@ export function listSkillCommandsForAgents(params: {
7292
entries.push(command);
7393
}
7494
}
75-
return entries;
95+
// Dedupe by skillName across workspaces so every interface (Discord, TUI,
96+
// Slack, text) sees a consistent command list without platform-specific
97+
// workarounds.
98+
return dedupeBySkillName(entries);
7699
}
77100

101+
export const __testing = {
102+
dedupeBySkillName,
103+
};
104+
78105
function normalizeSkillCommandLookup(value: string): string {
79106
return value
80107
.trim()

src/discord/monitor/provider.skill-dedupe.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { __testing } from "./provider.js";
33

4-
describe("dedupeSkillCommandsForDiscord", () => {
5-
it("keeps first command per skillName and drops suffix duplicates", () => {
6-
const input = [
7-
{ name: "github", skillName: "github", description: "GitHub" },
8-
{ name: "github_2", skillName: "github", description: "GitHub" },
9-
{ name: "weather", skillName: "weather", description: "Weather" },
10-
{ name: "weather_2", skillName: "weather", description: "Weather" },
11-
];
12-
13-
const output = __testing.dedupeSkillCommandsForDiscord(input);
14-
expect(output.map((entry) => entry.name)).toEqual(["github", "weather"]);
15-
});
16-
17-
it("treats skillName case-insensitively", () => {
18-
const input = [
19-
{ name: "ClawHub", skillName: "ClawHub", description: "ClawHub" },
20-
{ name: "clawhub_2", skillName: "clawhub", description: "ClawHub" },
21-
];
22-
const output = __testing.dedupeSkillCommandsForDiscord(input);
23-
expect(output).toHaveLength(1);
24-
expect(output[0]?.name).toBe("ClawHub");
25-
});
26-
});
27-
284
describe("resolveThreadBindingsEnabled", () => {
295
it("defaults to enabled when unset", () => {
306
expect(

src/discord/monitor/provider.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,6 @@ function formatThreadBindingSessionTtlLabel(ttlMs: number): string {
149149
return label === "disabled" ? "off" : label;
150150
}
151151

152-
function dedupeSkillCommandsForDiscord(
153-
skillCommands: ReturnType<typeof listSkillCommandsForAgents>,
154-
) {
155-
const seen = new Set<string>();
156-
const deduped: ReturnType<typeof listSkillCommandsForAgents> = [];
157-
for (const command of skillCommands) {
158-
const key = command.skillName.trim().toLowerCase();
159-
if (!key) {
160-
deduped.push(command);
161-
continue;
162-
}
163-
if (seen.has(key)) {
164-
continue;
165-
}
166-
seen.add(key);
167-
deduped.push(command);
168-
}
169-
return deduped;
170-
}
171152

172153
async function deployDiscordCommands(params: {
173154
client: Client;
@@ -334,7 +315,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
334315
const maxDiscordCommands = 100;
335316
let skillCommands =
336317
nativeEnabled && nativeSkillsEnabled
337-
? dedupeSkillCommandsForDiscord(listSkillCommandsForAgents({ cfg }))
318+
? listSkillCommandsForAgents({ cfg })
338319
: [];
339320
let commandSpecs = nativeEnabled
340321
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "discord" })
@@ -637,7 +618,6 @@ async function clearDiscordNativeCommands(params: {
637618

638619
export const __testing = {
639620
createDiscordGatewayPlugin,
640-
dedupeSkillCommandsForDiscord,
641621
resolveDiscordRuntimeGroupPolicy: resolveOpenProviderRuntimeGroupPolicy,
642622
resolveDefaultGroupPolicy,
643623
resolveDiscordRestFetch,

0 commit comments

Comments
 (0)