fix(skills): support names beginning with digits (#9244)

Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-09-04 18:13:43 -07:00
1 parent 896fe82f2f
commit 82f64cd8d0
11 files changed
+157 -7

No files matched your search

@@ -195,7 +195,8 @@ function appendRun(
return runs;
}
const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;
const SKILL_TOKEN_REGEX =
/(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;
function formatSkillLabel(skill: SelectableMarkdownSkill): string {
const displayName = skill.displayName?.trim();
@@ -226,6 +226,29 @@ describe("nativeMarkdownDocumentRuns", () => {
]);
});
it("decorates known skill references that begin with a digit", () => {
const node: MarkdownNode = {
type: "document",
children: [
{
type: "paragraph",
children: [{ type: "text", content: "Use $2spec for this." }],
},
],
};
expect(nativeMarkdownDocumentRuns(node, [{ name: "2spec", displayName: "2Spec" }])).toEqual([
{ text: "Use ", role: "body" },
{
text: "$2spec",
role: "body",
skillName: "2spec",
skillLabel: "2Spec",
},
{ text: " for this.", role: "body" },
]);
});
it("decorates known skill references inside blockquotes", () => {
const node: MarkdownNode = {
type: "blockquote",
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vite-plus/test";
import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
const SKILLS = new Set(["implement", "review", "re-release-version"]);
const SKILLS = new Set(["2spec", "implement", "review", "re-release-version"]);
describe("planClaudeSkillDispatch", () => {
it("leaves a prompt without a known skill untouched", () => {
@@ -27,6 +27,14 @@ describe("planClaudeSkillDispatch", () => {
});
});
it("dispatches a known skill whose name begins with a digit", () => {
expect(planClaudeSkillDispatch("use $2spec for this", SKILLS)).toEqual({
leadingText: "use",
commandText: "/2spec for this",
skillName: "2spec",
});
});
it("dispatches the last mention and rewrites earlier ones inline", () => {
expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({
leadingText: "/review the diff, then",
@@ -38,4 +46,10 @@ describe("planClaudeSkillDispatch", () => {
it("ignores a dollar token glued to other text", () => {
expect(planClaudeSkillDispatch("cost is 5$implement", SKILLS)).toBeUndefined();
});
it("ignores currency amounts and compact monetary expressions", () => {
const skillsWithCurrency = new Set([...SKILLS, "20", "20k", "100M"]);
expect(planClaudeSkillDispatch("pay $20 tomorrow", skillsWithCurrency)).toBeUndefined();
expect(planClaudeSkillDispatch("budget is $20k tomorrow", skillsWithCurrency)).toBeUndefined();
});
});
@@ -29,7 +29,8 @@
* (`packages/shared/src/composerInlineTokens.ts`), so a rendered chip and a
* dispatched skill are always the same set.
*/
const SKILL_MENTION_PATTERN = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;
const SKILL_MENTION_PATTERN =
/(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;
export interface ClaudeSkillDispatch {
/** Text before the dispatched mention, or `undefined` when it opens the prompt. */
@@ -19,8 +19,9 @@ import * as Schema from "effect/Schema";
import { parse as parseYamlDocument } from "yaml";
const FRONTMATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
const SKILL_MENTION_PATTERN = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;
const HAS_SKILL_MENTION_PATTERN = /(^|\s)\$[a-zA-Z][a-zA-Z0-9:_-]*(?=\s|$)/;
const SKILL_MENTION_PATTERN =
/(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;
const HAS_SKILL_MENTION_PATTERN = new RegExp(SKILL_MENTION_PATTERN.source);
const MAX_SKILL_DEPTH = 10;
const MAX_SKILL_BYTES = FileSystem.Size(1_000_000);
const MAX_SKILL_SCAN_ENTRIES = 10_000;
@@ -455,6 +455,24 @@ describe("Cursor skills", () => {
"please /review this",
);
});
it("detects and invokes digit-leading Cursor skills without rewriting money", () => {
const names = new Set(["2spec", "20k", "100M", "1e6"]);
// Repeated presence checks must not carry a global-regex cursor.
expect(hasCursorSkillMention("use $2spec here")).toBe(true);
expect(hasCursorSkillMention("use $2spec here")).toBe(true);
expect(rewriteCursorSkillMentions("use $2spec here", names)).toBe("use /2spec here");
expect(rewriteCursorSkillMentions("use $2spec here", new Set())).toBe("use $2spec here");
for (const text of [
"pay $20 tomorrow",
"budget $20k here",
"cost $100M total",
"limit $1e6 here",
]) {
expect(hasCursorSkillMention(text)).toBe(false);
expect(rewriteCursorSkillMentions(text, names)).toBe(text);
}
});
});
describe("getCursorFallbackModels", () => {
@@ -293,6 +293,46 @@ describe("hasMarkdownFilePrimaryAction", () => {
});
});
describe("ChatMarkdown skill chips", () => {
it("updates digit-leading skill labels when discovered skills change", async () => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
let renderer: ReactTestRenderer | undefined;
const text = "Use $2spec with a $20k budget.";
try {
await act(async () => {
renderer = create(<ChatMarkdown cwd="/tmp/project" text={text} />);
});
const mounted = renderer!;
const labels = (label: string) =>
mounted.root.findAllByType("span").filter((node) => node.children.includes(label));
expect(labels("2Spec")).toHaveLength(0);
await act(async () => {
mounted.update(
<ChatMarkdown
cwd="/tmp/project"
text={text}
skills={[
{ name: "2spec", displayName: "2Spec" },
{ name: "20k", displayName: "MoneySkill" },
]}
/>,
);
});
expect(labels("2Spec")).toHaveLength(1);
expect(labels("MoneySkill")).toHaveLength(0);
await act(async () => {
mounted.update(<ChatMarkdown cwd="/tmp/project" text={text} skills={[]} />);
});
expect(labels("2Spec")).toHaveLength(0);
} finally {
await act(async () => renderer?.unmount());
vi.unstubAllGlobals();
}
});
});
describe("ChatMarkdown file option chips", () => {
it("keeps the fallback button text selectable", () => {
const html = renderToStaticMarkup(
@@ -10,7 +10,8 @@ import {
} from "../composerInlineChip";
import { cn } from "~/lib/utils";
const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;
const SKILL_TOKEN_REGEX =
/(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;
type InlineSkill = Pick<ServerProviderSkill, "name" | "displayName">;
@@ -198,6 +198,29 @@ describe("splitPromptIntoComposerSegments", () => {
]);
});
it("splits digit-leading skill tokens into skill segments", () => {
expect(splitPromptIntoComposerSegments("Use $2spec please")).toEqual([
{ type: "text", text: "Use " },
{ type: "skill", name: "2spec" },
{ type: "text", text: " please" },
]);
});
it("keeps digits-only dollar amounts and compact monetary expressions as text", () => {
expect(splitPromptIntoComposerSegments("I'll pay $20 tomorrow")).toEqual([
{ type: "text", text: "I'll pay $20 tomorrow" },
]);
expect(splitPromptIntoComposerSegments("Budget is $20k tomorrow")).toEqual([
{ type: "text", text: "Budget is $20k tomorrow" },
]);
expect(splitPromptIntoComposerSegments("Cost is $100M total")).toEqual([
{ type: "text", text: "Cost is $100M total" },
]);
expect(splitPromptIntoComposerSegments("Limit is $1e6 here")).toEqual([
{ type: "text", text: "Limit is $1e6 here" },
]);
});
it("does not convert an incomplete trailing skill token", () => {
expect(splitPromptIntoComposerSegments("Use $review-follow-up")).toEqual([
{ type: "text", text: "Use $review-follow-up" },
@@ -31,6 +31,26 @@ describe("collectComposerInlineTokens", () => {
]);
});
it("collects skill names that begin with a digit", () => {
expect(collectComposerInlineTokens("Use $2spec next")).toEqual([
{
type: "skill",
value: "2spec",
source: "$2spec",
start: 4,
end: 10,
},
]);
});
it("leaves digits-only dollar amounts and compact monetary expressions as text", () => {
expect(collectComposerInlineTokens("I'll pay $20 tomorrow")).toEqual([]);
expect(collectComposerInlineTokens("Budget is $1_000 total")).toEqual([]);
expect(collectComposerInlineTokens("Budget is $20k tomorrow")).toEqual([]);
expect(collectComposerInlineTokens("Cost is $100M total")).toEqual([]);
expect(collectComposerInlineTokens("Limit is $1e6 here")).toEqual([]);
});
it("does not convert incomplete trailing tokens", () => {
expect(collectComposerInlineTokens("Use $ui")).toEqual([]);
expect(collectComposerInlineTokens("Inspect @AGENTS.md")).toEqual([]);
+9 -1
View File
@@ -18,7 +18,15 @@ export interface CollectComposerInlineTokensOptions {
readonly preserveTrailingFrom?: ReadonlyArray<ComposerInlineToken>;
}
const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s)/g;
/**
* A skill name may start with a digit, but compact monetary amounts and
* numeric expressions like "$20", "$20k", "$100M", and "$1e6" must stay prose:
* the composer chips any matched `$name` token, known or not. Tokens beginning
* with digits must not match numbers with currency/exponent suffixes, and must
* contain at least one letter.
*/
const SKILL_TOKEN_REGEX =
/(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s)/g;
const MENTION_TOKEN_REGEX = /(^|\s)@(?:"((?:\\.|[^"\\])*)"|([^\s@"]+))(?=\s)/g;
/**
* The label body is bounded rather than `*`. Unbounded, every whitespace in