Skip to content
TypeScript

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

Wilgot2a47fc905a7a
diff --git a/apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts b/apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts
index ec8cf74fee2..04682874db0 100644
--- a/apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts
+++ b/apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts
@@ -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) });
}
diff --git a/apps/mobile/src/components/ComposerEditor.tsx b/apps/mobile/src/components/ComposerEditor.tsx
index f9112d78fb4..a697ad6bc11 100644
--- a/apps/mobile/src/components/ComposerEditor.tsx
+++ b/apps/mobile/src/components/ComposerEditor.tsx
@@ -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,
diff --git a/apps/mobile/src/features/threads/use-composer-command-menu.ts b/apps/mobile/src/features/threads/use-composer-command-menu.ts
index f2ff30fcd1f..b0b2cd42ecb 100644
--- a/apps/mobile/src/features/threads/use-composer-command-menu.ts
+++ b/apps/mobile/src/features/threads/use-composer-command-menu.ts
@@ -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) {
diff --git a/apps/mobile/src/lib/nativeMarkdownText.test.ts b/apps/mobile/src/lib/nativeMarkdownText.test.ts
index 3c4fa3ad0ae..d934a306aa0 100644
--- a/apps/mobile/src/lib/nativeMarkdownText.test.ts
+++ b/apps/mobile/src/lib/nativeMarkdownText.test.ts
@@ -307,28 +307,31 @@ describe("nativeMarkdownDocumentRuns", () => {
]);
});
- it("decorates known skill references as selectable skill links", () => {
- const node: MarkdownNode = {
- type: "document",
- children: [
+ 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" },
{
- type: "paragraph",
- children: [{ type: "text", content: "Use $ui for this." }],
+ text: `${prefix}ui`,
+ role: "body",
+ skillName: "ui",
+ skillLabel: "UI",
},
- ],
- };
-
- 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" },
- ]);
- });
+ { text: " for this.", role: "body" },
+ ]);
+ },
+ );
it("decorates known skill references that begin with a digit", () => {
const node: MarkdownNode = {
diff --git a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts
index e6e6da9d5e9..acb7809c3a0 100644
--- a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts
+++ b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts
@@ -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();
+ }
});
});
diff --git a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts
index 27e7dcf68bd..2dc106e8538 100644
--- a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts
+++ b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts
@@ -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();
diff --git a/apps/server/src/provider/Drivers/CursorSkills.ts b/apps/server/src/provider/Drivers/CursorSkills.ts
index 7f8d96d9881..0562f4d1b72 100644
--- a/apps/server/src/provider/Drivers/CursorSkills.ts
+++ b/apps/server/src/provider/Drivers/CursorSkills.ts
@@ -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;
diff --git a/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts b/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
index c6257221c73..c14dca7ccd1 100644
--- a/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
+++ b/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
@@ -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(
diff --git a/apps/server/src/provider/Layers/CodexSessionRuntime.ts b/apps/server/src/provider/Layers/CodexSessionRuntime.ts
index a04db140591..c26d6ae446d 100644
--- a/apps/server/src/provider/Layers/CodexSessionRuntime.ts
+++ b/apps/server/src/provider/Layers/CodexSessionRuntime.ts
@@ -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 ?? []) {
diff --git a/apps/server/src/provider/Layers/CursorProvider.test.ts b/apps/server/src/provider/Layers/CursorProvider.test.ts
index 04e46af6783..19cfd22c696 100644
--- a/apps/server/src/provider/Layers/CursorProvider.test.ts
+++ b/apps/server/src/provider/Layers/CursorProvider.test.ts
@@ -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.
diff --git a/apps/web/src/components/chat/SkillInlineText.tsx b/apps/web/src/components/chat/SkillInlineText.tsx
index 160204ee094..83930ea2d60 100644
--- a/apps/web/src/components/chat/SkillInlineText.tsx
+++ b/apps/web/src/components/chat/SkillInlineText.tsx
@@ -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) {
diff --git a/apps/web/src/composer-editor-mentions.test.ts b/apps/web/src/composer-editor-mentions.test.ts
index 7479a8439b6..0ce166a29ef 100644
--- a/apps/web/src/composer-editor-mentions.test.ts
+++ b/apps/web/src/composer-editor-mentions.test.ts
@@ -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: " " },
diff --git a/apps/web/src/composer-editor-mentions.ts b/apps/web/src/composer-editor-mentions.ts
index 879fcdc508f..e228c968d91 100644
--- a/apps/web/src/composer-editor-mentions.ts
+++ b/apps/web/src/composer-editor-mentions.ts
@@ -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;
diff --git a/apps/web/src/composer-list-continuation.test.ts b/apps/web/src/composer-list-continuation.test.ts
index ec56dfaacf7..b92514dd271 100644
--- a/apps/web/src/composer-list-continuation.test.ts
+++ b/apps/web/src/composer-list-continuation.test.ts
@@ -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;
diff --git a/apps/web/src/composer-list-continuation.ts b/apps/web/src/composer-list-continuation.ts
index 0672bbc1d27..952dfa54947 100644
--- a/apps/web/src/composer-list-continuation.ts
+++ b/apps/web/src/composer-list-continuation.ts
@@ -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;
}
diff --git a/apps/web/src/composer-logic.test.ts b/apps/web/src/composer-logic.test.ts
index 64ff906d41d..d4509516cba 100644
--- a/apps/web/src/composer-logic.test.ts
+++ b/apps/web/src/composer-logic.test.ts
@@ -230,17 +230,20 @@ describe("detectComposerTrigger", () => {
});
});
- it("detects $skill trigger at cursor", () => {
- const text = "Use $gh-fi";
- const trigger = detectComposerTrigger(text, text.length);
-
- expect(trigger).toEqual({
- kind: "skill",
- query: "gh-fi",
- rangeStart: "Use ".length,
- rangeEnd: 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,
+ });
+ },
+ );
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 ";
diff --git a/apps/web/src/composer-logic.ts b/apps/web/src/composer-logic.ts
index ed74adf51db..a2ed12b86b9 100644
--- a/apps/web/src/composer-logic.ts
+++ b/apps/web/src/composer-logic.ts
@@ -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,
};
diff --git a/apps/web/src/composer-rich-text-doc.test.ts b/apps/web/src/composer-rich-text-doc.test.ts
index 15c8db1e41f..a8798708974 100644
--- a/apps/web/src/composer-rich-text-doc.test.ts
+++ b/apps/web/src/composer-rich-text-doc.test.ts
@@ -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",
diff --git a/apps/web/src/providerSkillSearch.test.ts b/apps/web/src/providerSkillSearch.test.ts
index 01059d6148f..b02cd2805c2 100644
--- a/apps/web/src/providerSkillSearch.test.ts
+++ b/apps/web/src/providerSkillSearch.test.ts
@@ -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({
diff --git a/apps/web/src/providerSkillSearch.ts b/apps/web/src/providerSkillSearch.ts
index 21dd2874480..a570c92d91f 100644
--- a/apps/web/src/providerSkillSearch.ts
+++ b/apps/web/src/providerSkillSearch.ts
@@ -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;
diff --git a/packages/shared/src/composerInlineTokens.test.ts b/packages/shared/src/composerInlineTokens.test.ts
index 56243c2d84e..5f19fb2a998 100644
--- a/packages/shared/src/composerInlineTokens.test.ts
+++ b/packages/shared/src/composerInlineTokens.test.ts
@@ -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", () => {
diff --git a/packages/shared/src/composerInlineTokens.ts b/packages/shared/src/composerInlineTokens.ts
index bb39dd59947..e7f57f260ae 100644
--- a/packages/shared/src/composerInlineTokens.ts
+++ b/packages/shared/src/composerInlineTokens.ts
@@ -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
diff --git a/packages/shared/src/composerTrigger.test.ts b/packages/shared/src/composerTrigger.test.ts
index 4b276385445..06b7038dad2 100644
--- a/packages/shared/src/composerTrigger.test.ts
+++ b/packages/shared/src/composerTrigger.test.ts
@@ -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", () => {
diff --git a/packages/shared/src/composerTrigger.ts b/packages/shared/src/composerTrigger.ts
index 46e56dacfcd..6153978edb9 100644
--- a/packages/shared/src/composerTrigger.ts
+++ b/packages/shared/src/composerTrigger.ts
@@ -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,
};