@devries-cameron20 / t3code-1 / commits / 5c3721e20a
Fork 0

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

fix(composer): mentions of files like `posts.$postId.tsx` or `[id].tsx` stay chips (#22922)

Co-authored-by: Victor Vogel <satsdev@only21mil.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 14:13 UTC 5c3721e20aa3c19d7ab414c40734752f9c053c90
4 files changed +97 -4
apps/web/src/composer-rich-text-doc.test.ts
+23
@@ -5,6 +5,7 @@ import { Node as ProseMirrorNode } from "@tiptap/pm/model";
5 import { EditorState, TextSelection } from "@tiptap/pm/state";
6 import { splitBlockKeepMarks } from "@tiptap/pm/commands";
7 import { describe, expect, it, onTestFinished } from "vite-plus/test";
8 +import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
9
10 import {
11 collapseExpandedComposerCursor,
@@ -91,6 +92,28 @@ function roundTrip(value: string) {
92 }
93
94 describe("editable math source", () => {
95 + it.each(["app/routes/posts.$postId.tsx", "pages/posts/[id].tsx"])(
96 + "keeps a mentioned file whose name looks like TeX as a chip: %s",
97 + (path) => {
98 + const source = `fix ${serializeComposerFileLink(path)} please`;
99 + const map = roundTrip(source);
100 + expect(map.value).toBe(source);
101 + expect(
102 + map.runs.filter((run) => run.kind === "token" && run.nodeName === "composer-mention"),
103 + ).toHaveLength(1);
104 + },
105 + );
106 +
107 + it.each([
108 + "before $x + @README.md$ after",
109 + "before \\(x + @README.md\\) after",
110 + "\\[x + @README.md\\] after",
111 + ])("keeps a mention that ends a formula inside the formula: %s", (source) => {
112 + const map = roundTrip(source);
113 + expect(map.value).toBe(source);
114 + expect(map.runs.some((run) => run.kind === "token")).toBe(false);
115 + });
116 +
117 it.each([
118 "Area $x_i^2$ after",
119 "before \\(\\frac{1}{2}\\) after",
apps/web/src/composer-rich-text-doc.ts
+2 -2
@@ -35,7 +35,7 @@ import { splitPromptIntoComposerSegments } from "~/composer-editor-mentions";
35 import { nextOrderedMarkerText } from "~/composer-list-continuation";
36 import { parseInlineMarkdown, RICH_TEXT_DELIMITERS, type RichTextMark } from "~/composer-rich-text";
37 import { collectInlineContextIds } from "~/lib/composerContextReferences";
38 -import { markdownMathRanges } from "@t3tools/shared/markdownMath";
38 +import { composerMathRanges } from "@t3tools/shared/composerInlineTokens";
39
40 export type SkillMeta = { label: string; description: string | null };
41
@@ -576,7 +576,7 @@ export function buildTiptapContent(
576 const atomSources: string[] = [];
577 const literal = value.slice(0, options?.literalLength ?? 0);
578 const remainder = value.slice(literal.length);
579 - const formulas = markdownMathRanges(remainder);
579 + const formulas = composerMathRanges(remainder);
580 let offset = 0;
581 const chunks: Array<{ text: string } | { source: string }> = [];
582 for (const formula of formulas) {
packages/shared/src/composerInlineTokens.test.ts
+44 -1
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { collectComposerInlineTokens } from "./composerInlineTokens.ts";
3 +import { collectComposerInlineTokens, composerMathRanges } from "./composerInlineTokens.ts";
4 +import { serializeComposerFileLink } from "./composerTrigger.ts";
5
6 describe("collectComposerInlineTokens", () => {
7 it("collects file links, mentions, and skills with source ranges", () => {
@@ -176,4 +177,46 @@ describe("collectComposerInlineTokens", () => {
177 "$real-skill",
178 ]);
179 });
180 +
181 + it.each([
182 + "app/routes/posts.$postId.tsx",
183 + "src/routes/_chat.$environmentId.$threadId.tsx",
184 + "pages/posts/[id].tsx",
185 + "app/blog/[...slug].tsx",
186 + ])("keeps a file link whose name looks like TeX as one mention: %s", (path) => {
187 + const link = serializeComposerFileLink(path);
188 + expect(collectComposerInlineTokens(`fix ${link} please`)).toMatchObject([
189 + { type: "mention", value: path, source: link },
190 + ]);
191 + });
192 +
193 + it.each(["app/routes/posts.$postId.tsx", "pages/posts/[id].tsx"])(
194 + "preserves a confirmed TeX-like pill when its trailing delimiter is removed: %s",
195 + (path) => {
196 + const link = serializeComposerFileLink(path);
197 + const confirmed = collectComposerInlineTokens(`fix ${link} `);
198 +
199 + expect(confirmed).toMatchObject([{ type: "mention", value: path, source: link }]);
200 + expect(
201 + collectComposerInlineTokens(`fix ${link}`, { preserveTrailingFrom: confirmed }),
202 + ).toEqual(confirmed);
203 + expect(collectComposerInlineTokens(`fix ${link}`)).toEqual([]);
204 + },
205 + );
206 +
207 + it.each([
208 + "before $x + @README.md$ after",
209 + "before \\(x + @README.md\\) after",
210 + "\\[x + @README.md\\] after",
211 + "\\[\\text{use @README.md}\\] then go ",
212 + ])("keeps a mention that ends a formula inside the formula: %s", (source) => {
213 + expect(collectComposerInlineTokens(source)).toEqual([]);
214 + });
215 +
216 + it("still finds a formula after a mention that starts the line", () => {
217 + const link = serializeComposerFileLink("app/routes/posts.$postId.tsx");
218 + expect(composerMathRanges(`${link} sets $x_i$`).map((formula) => formula.source)).toEqual([
219 + "$x_i$",
220 + ]);
221 + });
222 });
packages/shared/src/composerInlineTokens.ts
+28 -1
@@ -99,6 +99,32 @@ function collectMentionTokens(text: string): ComposerInlineToken[] {
99 return matches;
100 }
101
102 +/**
103 + * Formulas in composer text, ignoring the `$` and `\[` that file names such as
104 + * `posts.$postId.tsx` or `[id].tsx` put into a file link. File links are masked with letters,
105 + * not spaces, so a link at the start of a line cannot become an indented code block.
106 + * Bare `@path` mentions are not masked: one such as `@README.md$` can run into a formula's
107 + * closing delimiter, and a mention written inside a real formula stays covered by it.
108 + */
109 +export function composerMathRanges(
110 + text: string,
111 + mentions: ReadonlyArray<ComposerInlineToken> = collectMentionTokens(text),
112 +) {
113 + let masked = text;
114 + for (const mention of mentions) {
115 + if (mention.type !== "mention" || !mention.source.startsWith("[")) continue;
116 + masked =
117 + masked.slice(0, mention.start) +
118 + "x".repeat(mention.end - mention.start) +
119 + masked.slice(mention.end);
120 + }
121 + return markdownMathRanges(masked).map(({ start, end }) => ({
122 + start,
123 + end,
124 + source: text.slice(start, end),
125 + }));
126 +}
127 +
128 export function collectComposerInlineTokens(
129 text: string,
130 options: CollectComposerInlineTokensOptions = {},
@@ -138,7 +164,8 @@ export function collectComposerInlineTokens(
164
165 // TeX can contain literal skill and file tokens, especially inside \text{}.
166 // They remain formula source rather than becoming composer context chips.
141 - const math = matches.length > 0 ? markdownMathRanges(text) : [];
167 + // Confirmed trailing file links are masked too, so a kept chip is not read as TeX.
168 + const math = matches.length > 0 ? composerMathRanges(text, matches) : [];
169 return matches
170 .filter(
171 (match) => !math.some((formula) => match.start < formula.end && match.end > formula.start),