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 <noreply@anthropic.com>
This commit is contained in:
Shivam
2026-02-26 09:07:14 +05:30
committed by Shakker
parent 5d5fa0dac8
commit 48decefbf4
4 changed files with 70 additions and 49 deletions

View File

@@ -1,30 +1,6 @@
import { describe, expect, it } from "vitest";
import { __testing } from "./provider.js";
describe("dedupeSkillCommandsForDiscord", () => {
it("keeps first command per skillName and drops suffix duplicates", () => {
const input = [
{ name: "github", skillName: "github", description: "GitHub" },
{ name: "github_2", skillName: "github", description: "GitHub" },
{ name: "weather", skillName: "weather", description: "Weather" },
{ name: "weather_2", skillName: "weather", description: "Weather" },
];
const output = __testing.dedupeSkillCommandsForDiscord(input);
expect(output.map((entry) => entry.name)).toEqual(["github", "weather"]);
});
it("treats skillName case-insensitively", () => {
const input = [
{ name: "ClawHub", skillName: "ClawHub", description: "ClawHub" },
{ name: "clawhub_2", skillName: "clawhub", description: "ClawHub" },
];
const output = __testing.dedupeSkillCommandsForDiscord(input);
expect(output).toHaveLength(1);
expect(output[0]?.name).toBe("ClawHub");
});
});
describe("resolveThreadBindingsEnabled", () => {
it("defaults to enabled when unset", () => {
expect(

View File

@@ -126,25 +126,6 @@ function formatThreadBindingDurationForConfigLabel(durationMs: number): string {
return label === "disabled" ? "off" : label;
}
function dedupeSkillCommandsForDiscord(
skillCommands: ReturnType<typeof listSkillCommandsForAgents>,
) {
const seen = new Set<string>();
const deduped: ReturnType<typeof listSkillCommandsForAgents> = [];
for (const command of skillCommands) {
const key = command.skillName.trim().toLowerCase();
if (!key) {
deduped.push(command);
continue;
}
if (seen.has(key)) {
continue;
}
seen.add(key);
deduped.push(command);
}
return deduped;
}
function appendPluginCommandSpecs(params: {
commandSpecs: NativeCommandSpec[];
@@ -434,7 +415,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
const maxDiscordCommands = 100;
let skillCommands =
nativeEnabled && nativeSkillsEnabled
? dedupeSkillCommandsForDiscord(listSkillCommandsForAgents({ cfg }))
? listSkillCommandsForAgents({ cfg })
: [];
let commandSpecs = nativeEnabled
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "discord" })
@@ -819,7 +800,6 @@ async function clearDiscordNativeCommands(params: {
export const __testing = {
createDiscordGatewayPlugin,
dedupeSkillCommandsForDiscord,
resolveDiscordRuntimeGroupPolicy: resolveOpenProviderRuntimeGroupPolicy,
resolveDefaultGroupPolicy,
resolveDiscordRestFetch,