mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:47:39 +00:00
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:
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user