fix(skills): support unicode currency symbols as skill aliases (#12098)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
Wilgotandmaria-rcks authored and GitHub committed 2026-09-17 02:19:50 -03:00
1 parent 01eb4b9a87
commit 2a47fc905a
24 files changed
+209 -78

No files matched your search

@@ -319,7 +319,7 @@ function appendRun(
}
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;
/(^|\s)\p{Sc}(?![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|$)/gu;
function formatSkillLabel(skill: SelectableMarkdownSkill): string {
const displayName = skill.displayName?.trim();
@@ -359,7 +359,7 @@ function decorateSkillRuns(
continue;
}
const start = (match.index ?? 0) + prefix.length;
const end = start + name.length + 1;
const end = (match.index ?? 0) + match[0].length;
if (start > cursor) {
decorated.push({ ...run, text: run.text.slice(cursor, start) });
}
@@ -155,8 +155,9 @@ export function ComposerEditor({
const selectedReference = selected
? collectComposerContextReferences(selected.source)[0]
: undefined;
const selectedSkill = selected?.source.startsWith("$")
? props.skills?.find((skill) => skill.name === selected.source.slice(1))
const selectedSkillName = selected?.source.match(/^\p{Sc}(.+)$/u)?.[1];
const selectedSkill = selectedSkillName
? props.skills?.find((skill) => skill.name === selectedSkillName)
: undefined;
const record = draft.context?.records.find(
(entry) => entry.contextId === selectedReference?.contextId,
@@ -366,7 +366,7 @@ export function useComposerCommandMenu({
if (trigger.kind === "skill") {
const enabledSkills = dedupeProviderSkillsByName(skills.filter(isProviderSkillUserInvocable));
const normalizedQuery = normalizeSearchQuery(trigger.query, {
trimLeadingPattern: /^\$+/,
trimLeadingPattern: /^\p{Sc}+/u,
});
if (!normalizedQuery) {
+24 -21
View File
@@ -307,28 +307,31 @@ describe("nativeMarkdownDocumentRuns", () => {
]);
});
it("decorates known skill references as selectable skill links", () => {
const node: MarkdownNode = {
type: "document",
children: [
{
type: "paragraph",
children: [{ type: "text", content: "Use $ui for this." }],
},
],
};
it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"decorates %s skill references as selectable skill links",
(prefix) => {
const node: MarkdownNode = {
type: "document",
children: [
{
type: "paragraph",
children: [{ type: "text", content: `Use ${prefix}ui for this.` }],
},
],
};
expect(nativeMarkdownDocumentRuns(node, [{ name: "ui", displayName: "UI" }])).toEqual([
{ text: "Use ", role: "body" },
{
text: "$ui",
role: "body",
skillName: "ui",
skillLabel: "UI",
},
{ text: " for this.", role: "body" },
]);
});
expect(nativeMarkdownDocumentRuns(node, [{ name: "ui", displayName: "UI" }])).toEqual([
{ text: "Use ", role: "body" },
{
text: `${prefix}ui`,
role: "body",
skillName: "ui",
skillLabel: "UI",
},
{ text: " for this.", role: "body" },
]);
},
);
it("decorates known skill references that begin with a digit", () => {
const node: MarkdownNode = {
@@ -43,13 +43,40 @@ describe("planClaudeSkillDispatch", () => {
});
});
it("dispatches currency-prefixed mentions and preserves their source boundaries", () => {
for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
expect(
planClaudeSkillDispatch(
`${symbol}review the diff, then ${symbol}implement the fixes`,
SKILLS,
),
).toEqual({
leadingText: "/review the diff, then",
commandText: "/implement the fixes",
skillName: "implement",
});
expect(planClaudeSkillDispatch(`${symbol}2spec for this`, SKILLS)).toEqual({
leadingText: undefined,
commandText: "/2spec for this",
skillName: "2spec",
});
expect(planClaudeSkillDispatch(`5${symbol}review ${symbol}unknown`, SKILLS)).toBeUndefined();
}
});
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();
const skillsWithCurrency = new Set([...SKILLS, "20", "20k", "100M", "1e6"]);
for (const symbol of ["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
expect(
planClaudeSkillDispatch(
`pay ${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6 tomorrow`,
skillsWithCurrency,
),
).toBeUndefined();
}
});
});
@@ -30,7 +30,7 @@
* dispatched skill are always the same set.
*/
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;
/(^|\s)\p{Sc}(?![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|$)/gu;
export interface ClaudeSkillDispatch {
/** Text before the dispatched mention, or `undefined` when it opens the prompt. */
@@ -54,7 +54,7 @@ export function planClaudeSkillDispatch(
const name = match[2] ?? "";
if (!skillNames.has(name)) return [];
const start = (match.index ?? 0) + (match[1]?.length ?? 0);
return [{ name, start, end: start + name.length + 1 }];
return [{ name, start, end: (match.index ?? 0) + match[0].length }];
});
const last = mentions.at(-1);
if (!last) {
@@ -66,7 +66,8 @@ export function planClaudeSkillDispatch(
const leadingWithInlineSlashes = mentions
.slice(0, -1)
.reduceRight(
(text, mention) => `${text.slice(0, mention.start)}/${text.slice(mention.start + 1)}`,
(text, mention) =>
`${text.slice(0, mention.start)}/${mention.name}${text.slice(mention.end)}`,
leading,
)
.trimEnd();
@@ -20,8 +20,8 @@ import { parse as parseYamlDocument } from "yaml";
const FRONTMATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
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);
/(^|\s)\p{Sc}(?![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|$)/gu;
const HAS_SKILL_MENTION_PATTERN = new RegExp(SKILL_MENTION_PATTERN.source, "u");
const MAX_SKILL_DEPTH = 10;
const MAX_SKILL_BYTES = FileSystem.Size(1_000_000);
const MAX_SKILL_SCAN_ENTRIES = 10_000;
@@ -154,6 +154,23 @@ function makeThreadOpenResponse(
}
describe("buildTurnStartParams", () => {
it.effect("sends currency skill aliases in Codex's canonical dollar form", () =>
Effect.gen(function* () {
for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
const prose = `${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6 5${symbol}review`;
const params = yield* buildTurnStartParams({
threadId: "provider-thread-1",
runtimeMode: "full-access",
prompt: `${symbol}review ${symbol}2spec $existing ${prose} ${symbol}last`,
});
NodeAssert.deepEqual(params.input, [
{ type: "text", text: `$review $2spec $existing ${prose} $last` },
]);
}
}),
);
it("keeps invalid turn values only in the schema cause", () => {
const secret = "codex-turn-input-secret-sentinel";
const error = Effect.runSync(
@@ -605,6 +605,10 @@ function buildCodexCollaborationMode(input: {
};
}
// Match the skill grammar used by Claude/Cursor, leaving currency amounts as prose.
const SKILL_MENTION_PATTERN =
/(^|\s)\p{Sc}(?![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|$)/gu;
export function buildTurnStartParams(input: {
readonly threadId: string;
readonly runtimeMode: RuntimeMode;
@@ -627,7 +631,7 @@ export function buildTurnStartParams(input: {
if (input.prompt) {
turnInput.push({
type: "text",
text: input.prompt,
text: input.prompt.replace(SKILL_MENTION_PATTERN, "$1$$$2"),
});
}
for (const attachment of input.attachments ?? []) {
@@ -461,6 +461,22 @@ describe("Cursor skills", () => {
);
});
it("rewrites currency-prefixed skill mentions into Cursor slash invocations", () => {
const names = new Set(["review", "2spec", "20k", "100M", "1e6"]);
for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
expect(hasCursorSkillMention(`please ${symbol}review this`)).toBe(true);
expect(hasCursorSkillMention(`please ${symbol}review this`)).toBe(true);
expect(rewriteCursorSkillMentions(`${symbol}review then ${symbol}2spec this`, names)).toBe(
"/review then /2spec this",
);
const money = `${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6`;
expect(hasCursorSkillMention(money)).toBe(false);
expect(rewriteCursorSkillMentions(money, names)).toBe(money);
const prose = `5${symbol}review ${symbol}unknown`;
expect(rewriteCursorSkillMentions(prose, names)).toBe(prose);
}
});
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.
@@ -12,7 +12,7 @@ import {
import { cn } from "~/lib/utils";
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;
/(^|\s)\p{Sc}(?![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|$)/gu;
type InlineSkill = Pick<ServerProviderSkill, "name" | "displayName">;
@@ -34,7 +34,7 @@ export function SkillInlineText(props: { text: string; skills: ReadonlyArray<Inl
nodes.push(props.text.slice(cursor, start));
}
nodes.push(<SkillChip key={`${start}:${name}`} skill={skill} rawText={rawText} />);
cursor = start + rawText.length;
cursor = (match.index ?? 0) + match[0].length;
}
if (cursor === 0) {
@@ -154,7 +154,7 @@ describe("splitPromptIntoComposerSegments", () => {
{ type: "text", text: " " },
{ type: "citation", citation, source },
{ type: "text", text: "\n" },
{ type: "skill", name: "review" },
{ type: "skill", name: "review", source: "$review" },
{ type: "text", text: " " },
{
type: "context-reference",
@@ -217,7 +217,7 @@ describe("splitPromptIntoComposerSegments", () => {
it("splits skill tokens followed by whitespace into skill segments", () => {
expect(splitPromptIntoComposerSegments("Use $review-follow-up please")).toEqual([
{ type: "text", text: "Use " },
{ type: "skill", name: "review-follow-up" },
{ type: "skill", name: "review-follow-up", source: "$review-follow-up" },
{ type: "text", text: " please" },
]);
});
@@ -225,7 +225,7 @@ 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: "skill", name: "2spec", source: "$2spec" },
{ type: "text", text: " please" },
]);
});
@@ -278,7 +278,7 @@ describe("splitPromptIntoComposerSegments", () => {
{ type: "text", text: "Inspect " },
terminalSegment,
{ type: "text", text: " " },
{ type: "skill", name: "review-follow-up" },
{ type: "skill", name: "review-follow-up", source: "$review-follow-up" },
{ type: "text", text: " after " },
{ type: "mention", path: "AGENTS.md", source: "@AGENTS.md" },
{ type: "text", text: " " },
+2 -1
View File
@@ -19,6 +19,7 @@ export type ComposerPromptSegment =
| {
type: "skill";
name: string;
source: string;
}
| {
type: "citation";
@@ -127,7 +128,7 @@ function splitPromptTextIntoComposerSegments(text: string): ComposerPromptSegmen
source: match.source,
});
} else {
segments.push({ type: "skill", name: match.value });
segments.push({ type: "skill", name: match.value, source: match.source });
}
cursor = match.end;
@@ -48,6 +48,12 @@ describe("composer list continuation", () => {
expect(listContinuationForEnter("1. foo", 1)).toBeNull();
});
it("refuses to split a supplementary currency skill chip", () => {
const value = "1. 𑿝review go";
const cursor = value.indexOf(" go") - 1;
expect(listContinuationForEnter(value, cursor)).toBeNull();
});
it("refuses to split an inline chip", () => {
const value = "1. @README.md go";
const cursor = value.indexOf("README") + 2;
@@ -73,7 +73,6 @@ function segmentSource(
segment: ReturnType<typeof splitPromptIntoComposerSegments>[number],
): string {
if (segment.type === "text") return segment.text;
if (segment.type === "skill") return `$${segment.name}`;
return segment.source;
}
+26 -16
View File
@@ -230,17 +230,20 @@ describe("detectComposerTrigger", () => {
});
});
it("detects $skill trigger at cursor", () => {
const text = "Use $gh-fi";
const trigger = detectComposerTrigger(text, text.length);
it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"detects %sskill trigger at cursor",
(prefix) => {
const text = `Use ${prefix}gh-fi`;
const trigger = detectComposerTrigger(text, text.length);
expect(trigger).toEqual({
kind: "skill",
query: "gh-fi",
rangeStart: "Use ".length,
rangeEnd: text.length,
});
});
expect(trigger).toEqual({
kind: "skill",
query: "gh-fi",
rangeStart: "Use ".length,
rangeEnd: text.length,
});
},
);
it("detects a pull request number at a token boundary", () => {
const text = "Compare this with #8737";
@@ -468,10 +471,10 @@ describe("expandCollapsedComposerCursor", () => {
expect(detectComposerTrigger(text, expandedCursor)).toBeNull();
});
it("maps collapsed skill cursor to expanded text cursor", () => {
const text = "run $review-follow-up then";
it.each(["$", "€", "𑿝"])("maps collapsed %s skill cursor to expanded text cursor", (prefix) => {
const text = `run ${prefix}review-follow-up then`;
const collapsedCursorAfterSkill = "run ".length + 2;
const expandedCursorAfterSkill = "run $review-follow-up ".length;
const expandedCursorAfterSkill = `run ${prefix}review-follow-up `.length;
expect(expandCollapsedComposerCursor(text, collapsedCursorAfterSkill)).toBe(
expandedCursorAfterSkill,
@@ -532,10 +535,10 @@ describe("collapseExpandedComposerCursor", () => {
expect(expandCollapsedComposerCursor(text, collapsedCursor)).toBe(expandedCursor);
});
it("maps expanded skill cursor back to collapsed cursor", () => {
const text = "run $review-follow-up then";
it.each(["$", "€", "𑿝"])("maps expanded %s skill cursor back to collapsed cursor", (prefix) => {
const text = `run ${prefix}review-follow-up then`;
const collapsedCursorAfterSkill = "run ".length + 2;
const expandedCursorAfterSkill = "run $review-follow-up ".length;
const expandedCursorAfterSkill = `run ${prefix}review-follow-up `.length;
expect(collapseExpandedComposerCursor(text, expandedCursorAfterSkill)).toBe(
collapsedCursorAfterSkill,
@@ -543,6 +546,13 @@ describe("collapseExpandedComposerCursor", () => {
});
});
it("preserves the caret before trailing text after mixed-width skill chips", () => {
const text = "𑿝ui a $review tail";
const expanded = "𑿝ui a $review ".length;
expect(collapseExpandedComposerCursor(text, expanded)).toBe(6);
expect(expandCollapsedComposerCursor(text, 6)).toBe(expanded);
});
describe("clampCollapsedComposerCursor", () => {
it("clamps to collapsed prompt length when mentions are present", () => {
const text = "open @AGENTS.md then ";
+5 -4
View File
@@ -88,7 +88,7 @@ export function expandCollapsedComposerCursor(text: string, cursorInput: number)
continue;
}
if (segment.type === "skill") {
const expandedLength = segment.name.length + 1;
const expandedLength = segment.source.length;
if (remaining <= 1) {
return expandedCursor + (remaining === 0 ? 0 : expandedLength);
}
@@ -164,7 +164,7 @@ export function collapseExpandedComposerCursor(text: string, cursorInput: number
continue;
}
if (segment.type === "skill") {
const expandedLength = segment.name.length + 1;
const expandedLength = segment.source.length;
if (remaining === 0) {
return collapsedCursor;
}
@@ -244,10 +244,11 @@ export function detectComposerTrigger(text: string, cursorInput: number): Compos
rangeEnd: cursor,
};
}
if (token.startsWith("$")) {
const skillPrefix = /^\p{Sc}/u.exec(token);
if (skillPrefix) {
return {
kind: "skill",
query: token.slice(1),
query: token.slice(skillPrefix[0].length),
rangeStart: tokenStart,
rangeEnd: cursor,
};
@@ -118,6 +118,16 @@ function roundTripPlain(value: string) {
}
describe("composer rich text document model", () => {
it.each(["€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"canonicalizes %s skill aliases while preserving amounts",
(prefix) => {
const value = `Use ${prefix}my-skill for ${prefix}20 please`;
const expected = `Use $my-skill for ${prefix}20 please`;
expect(roundTrip(value).value).toBe(expected);
expect(roundTripPlain(value).value).toBe(expected);
},
);
it.each([
"",
"\n\n",
+8
View File
@@ -13,6 +13,14 @@ function makeSkill(input: Partial<ServerProviderSkill> & Pick<ServerProviderSkil
}
describe("searchProviderSkills", () => {
it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"searches skills with a %s prefix",
(prefix) => {
const skill = makeSkill({ name: "review" });
expect(searchProviderSkills([skill], `${prefix}review`)).toEqual([skill]);
},
);
it("moves exact ui matches ahead of broader ui matches", () => {
const skills = [
makeSkill({
+1 -1
View File
@@ -75,7 +75,7 @@ export function searchProviderSkills(
limit = Number.POSITIVE_INFINITY,
): ServerProviderSkill[] {
const enabledSkills = dedupeProviderSkillsByName(skills.filter(isProviderSkillUserInvocable));
const normalizedQuery = normalizeSearchQuery(query, { trimLeadingPattern: /^\$+/ });
const normalizedQuery = normalizeSearchQuery(query, { trimLeadingPattern: /^\p{Sc}+/u });
if (!normalizedQuery) {
return enabledSkills;
@@ -31,16 +31,27 @@ 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.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"collects %s skill names that begin with a digit",
(prefix) => {
expect(collectComposerInlineTokens(`Use ${prefix}2spec next`)).toEqual([
{
type: "skill",
value: "2spec",
source: `${prefix}2spec`,
start: 4,
end: 9 + prefix.length,
},
]);
},
);
it.each(["€", "£", "¥", "₹", "₩", "₿", "𑿝"])("leaves %s currency amounts as text", (prefix) => {
expect(
collectComposerInlineTokens(
`${prefix}20 ${prefix}1_000 ${prefix}20k ${prefix}100M ${prefix}1e6 `,
),
).toEqual([]);
});
it("leaves digits-only dollar amounts and compact monetary expressions as text", () => {
+1 -1
View File
@@ -26,7 +26,7 @@ export interface CollectComposerInlineTokensOptions {
* 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;
/(^|\s)\p{Sc}(?![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)/gu;
const MENTION_TOKEN_REGEX = /(^|\s)@(?:"((?:\\.|[^"\\])*)"|([^\s@"]+))(?=\s)/g;
/**
* The label body is bounded rather than `*`. Unbounded, every whitespace in
+16 -1
View File
@@ -1,6 +1,21 @@
import { describe, expect, it } from "vite-plus/test";
import { serializeComposerFileLink } from "./composerTrigger.ts";
import { detectComposerTrigger, serializeComposerFileLink } from "./composerTrigger.ts";
describe("detectComposerTrigger", () => {
it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
"detects %s skill prefixes and their source range",
(prefix) => {
const text = `Use ${prefix}review`;
expect(detectComposerTrigger(text, text.length)).toEqual({
kind: "skill",
query: "review",
rangeStart: 4,
rangeEnd: text.length,
});
},
);
});
describe("serializeComposerFileLink", () => {
it("uses the basename as the markdown label", () => {
+3 -2
View File
@@ -108,10 +108,11 @@ export function detectComposerTrigger(
rangeStart: tokenStart,
rangeEnd: cursor,
};
if (token.startsWith("$")) {
const skillPrefix = /^\p{Sc}/u.exec(token);
if (skillPrefix) {
return {
kind: "skill",
query: token.slice(1),
query: token.slice(skillPrefix[0].length),
rangeStart: tokenStart,
rangeEnd: cursor,
};