fix: truncate skill command descriptions to 100 chars for Discord (#1018)
* fix: truncate skill command descriptions to 100 chars for Discord Discord slash commands have a 100 character limit for descriptions. Skill descriptions were not being truncated, causing command registration to fail with an empty error from the Discord API. * style: format * style: format
This commit is contained in:
@@ -87,12 +87,7 @@ function parseFrontmatterBool(value: string | undefined, fallback: boolean): boo
|
||||
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
normalized === "false" ||
|
||||
normalized === "0" ||
|
||||
normalized === "no" ||
|
||||
normalized === "off"
|
||||
) {
|
||||
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
||||
return false;
|
||||
}
|
||||
return fallback;
|
||||
|
||||
@@ -50,6 +50,8 @@ function filterSkillEntries(
|
||||
|
||||
const SKILL_COMMAND_MAX_LENGTH = 32;
|
||||
const SKILL_COMMAND_FALLBACK = "skill";
|
||||
// Discord command descriptions must be ≤100 characters
|
||||
const SKILL_COMMAND_DESCRIPTION_MAX_LENGTH = 100;
|
||||
|
||||
function sanitizeSkillCommandName(raw: string): string {
|
||||
const normalized = raw
|
||||
@@ -311,9 +313,7 @@ export function buildWorkspaceSkillCommandSpecs(
|
||||
opts?.skillFilter,
|
||||
opts?.eligibility,
|
||||
);
|
||||
const userInvocable = eligible.filter(
|
||||
(entry) => entry.invocation?.userInvocable !== false,
|
||||
);
|
||||
const userInvocable = eligible.filter((entry) => entry.invocation?.userInvocable !== false);
|
||||
const used = new Set<string>();
|
||||
for (const reserved of opts?.reservedNames ?? []) {
|
||||
used.add(reserved.toLowerCase());
|
||||
@@ -324,10 +324,15 @@ export function buildWorkspaceSkillCommandSpecs(
|
||||
const base = sanitizeSkillCommandName(entry.skill.name);
|
||||
const unique = resolveUniqueSkillCommandName(base, used);
|
||||
used.add(unique.toLowerCase());
|
||||
const rawDescription = entry.skill.description?.trim() || entry.skill.name;
|
||||
const description =
|
||||
rawDescription.length > SKILL_COMMAND_DESCRIPTION_MAX_LENGTH
|
||||
? rawDescription.slice(0, SKILL_COMMAND_DESCRIPTION_MAX_LENGTH - 1) + "…"
|
||||
: rawDescription;
|
||||
specs.push({
|
||||
name: unique,
|
||||
skillName: entry.skill.name,
|
||||
description: entry.skill.description?.trim() || entry.skill.name,
|
||||
description,
|
||||
});
|
||||
}
|
||||
return specs;
|
||||
|
||||
Reference in New Issue
Block a user