@devries-cameron20 / t3code-1 / commits / d61058debf
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(web): reuse repeated inline skill lookups (#29008)

Co-authored-by: maria-rcks <maria@kuuro.net>

luke committed Nov 3, 2026 at 23:07 UTC d61058debf93bc9d691a19001c9f35276d015e0d
2 files changed +32 -2
packages/shared/src/inlineSkills.test.ts
+24 -1
@@ -1,5 +1,5 @@
1 import { describe, expect, it } from "vite-plus/test";
2 -import { formatProviderSkillDisplayName } from "./inlineSkills.ts";
2 +import { formatProviderSkillDisplayName, matchInlineSkills } from "./inlineSkills.ts";
3
4 describe("formatProviderSkillDisplayName", () => {
5 it.each([
@@ -17,3 +17,26 @@ describe("formatProviderSkillDisplayName", () => {
17 );
18 });
19 });
20 +
21 +describe("matchInlineSkills", () => {
22 + it("preserves offsets, skill identity, first-name precedence, and unknown tokens", () => {
23 + const first = { name: "design", displayName: "Design" };
24 + const duplicate = { name: "design", displayName: "Other design" };
25 + const namespaced = { name: "pdf:pdf" };
26 + const matches = [
27 + ...matchInlineSkills("Use $design then $missing and $pdf:pdf, $pdf:pdf $design", [
28 + first,
29 + duplicate,
30 + namespaced,
31 + ]),
32 + ];
33 + expect(matches).toEqual([
34 + { start: 4, end: 11, skill: first, rawText: "$design" },
35 + { start: 40, end: 48, skill: namespaced, rawText: "$pdf:pdf" },
36 + { start: 49, end: 56, skill: first, rawText: "$design" },
37 + ]);
38 + expect(matches[0]?.skill).toBe(first);
39 + expect(matches[1]?.skill).toBe(namespaced);
40 + expect(matches[2]?.skill).toBe(first);
41 + });
42 +});
packages/shared/src/inlineSkills.ts
+8 -1
@@ -15,9 +15,16 @@ export function* matchInlineSkills<Skill extends InlineSkill>(
15 text: string,
16 skills: readonly Skill[],
17 ) {
18 + const byName = new Map<string, Skill | undefined>();
19 for (const match of text.matchAll(SKILL_TOKEN_REGEX)) {
20 const name = match[2] ?? "";
20 - const skill = skills.find((candidate) => candidate.name === name);
21 + if (!byName.has(name)) {
22 + byName.set(
23 + name,
24 + skills.find((candidate) => candidate.name === name),
25 + );
26 + }
27 + const skill = byName.get(name);
28 if (!skill) continue;
29 const start = match.index + (match[1]?.length ?? 0);
30 yield { start, end: match.index + match[0].length, skill, rawText: `$${name}` };