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

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

fix(shared): file mentions of __init__.py keep their name as the label (#31593)

Co-authored-by: Matyas Rathonyi <matyasrathonyi@imac-server2.tailacc4a3.ts.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

matyasrathonyi committed Nov 15, 2026 at 04:12 UTC 1cec1043eb56c94377eeabd1a09e81447df4476f
4 files changed +51 -2
apps/server/src/orchestration-v2/ThreadSearch.test.ts
+15
@@ -860,6 +860,7 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
860 const project = ProjectId.make("project:heron");
861 const labeled = ThreadId.make("thread:heron-label");
862 const addressOnly = ThreadId.make("thread:heron-address");
863 + const mention = ThreadId.make("thread:heron-mention");
864 yield* createProject(project);
865 yield* Effect.forEach(
866 [
@@ -867,6 +868,13 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
868 message(labeled, "heron-label", "assistant", "See [the heron plan](https://x.dev/a) now"),
869 thread(addressOnly, project),
870 message(addressOnly, "heron-address", "user", "Read [this](https://heron.dev/b)"),
871 + thread(mention, project),
872 + message(
873 + mention,
874 + "heron-mention",
875 + "user",
876 + String.raw`Fix [\_\_init\_\_.py](pkg/__init__.py) and [\_café\_.py](pkg/_caf%C3%A9_.py)`,
877 + ),
878 ],
879 projections.apply,
880 { discard: true },
@@ -876,6 +884,13 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
884 matches.map((match) => [match.threadId, match.snippet]),
885 [[labeled, "See the heron plan now"]],
886 );
887 + for (const query of ["__init__.py", "_café_.py"]) {
888 + const mentions = yield* search.search({ query });
889 + assert.deepEqual(
890 + mentions.matches.map((match) => [match.threadId, match.snippet]),
891 + [[mention, "Fix __init__.py and _café_.py"]],
892 + );
893 + }
894 }),
895 );
896
apps/server/src/orchestration-v2/messageSearchIndex.ts
+9 -1
@@ -48,13 +48,21 @@ const foldApostrophes = (text: string) => `replace(replace(${text}, '’', '''')
48 const readableText = (row: string) =>
49 `COALESCE(${row}.search_text, json_extract(${row}.payload_json, '$.text'))`;
50
51 +// A file mention stores `__init__.py` as `[\_\_init\_\_.py](...)`; the index
52 +// holds the label as it reads, so search can find the name as typed.
53 +const LINK_LABEL = /(!?\[)([^\]\n]*)(\]\([^)\s]*\))/g;
54 +
55 /**
56 * What search_text holds for a message: its text as it reads, a quote's
57 * percent-encoded link replaced by its words and comment. NULL when that is
58 * the stored text, so most messages store nothing extra.
59 */
60 export const readableSearchText = (text: string) => {
57 - const readable = assistantCitationsToPlainText(text);
61 + const readable = assistantCitationsToPlainText(text).replace(
62 + LINK_LABEL,
63 + (_link, open: string, label: string, close: string) =>
64 + open + label.replace(/\\([*_])/g, "$1") + close,
65 + );
66 return readable === text ? null : readable;
67 };
68
packages/shared/src/composerTrigger.test.ts
+24
@@ -1,3 +1,5 @@
1 +import remarkParse from "remark-parse";
2 +import { unified } from "unified";
3 import { describe, expect, it } from "vite-plus/test";
4
5 import {
@@ -6,6 +8,21 @@ import {
8 serializeComposerFileLink,
9 } from "./composerTrigger.ts";
10
11 +interface MarkdownNode {
12 + readonly type: string;
13 + readonly value?: string;
14 + readonly children?: ReadonlyArray<MarkdownNode>;
15 +}
16 +
17 +function parsedLinkLabel(markdown: string): string | undefined {
18 + const textOf = (node: MarkdownNode): string =>
19 + node.value ?? (node.children ?? []).map(textOf).join("");
20 + const find = (node: MarkdownNode): MarkdownNode | undefined =>
21 + node.type === "link" ? node : node.children?.map(find).find(Boolean);
22 + const link = find(unified().use(remarkParse).parse(markdown) as MarkdownNode);
23 + return link && textOf(link);
24 +}
25 +
26 describe("detectComposerTrigger", () => {
27 it.each([
28 ["Run /tmp/build.sh", "Run /tmp/build.sh".length],
@@ -91,6 +108,13 @@ describe("serializeComposerFileLink", () => {
108 );
109 });
110
111 + it.each([
112 + ["pkg/__init__.py", "__init__.py"],
113 + ["notes/*draft*.md", "*draft*.md"],
114 + ])("renders the mention of %j with its file name as the label", (path, basename) => {
115 + expect(parsedLinkLabel(serializeComposerFileLink(path))).toBe(basename);
116 + });
117 +
118 it("preserves paths that legitimately start with an at sign", () => {
119 expect(serializeComposerFileLink("@scope/package.json")).toBe(
120 "[package.json](@scope/package.json)",
packages/shared/src/composerTrigger.ts
+3 -1
@@ -18,8 +18,10 @@ function composerFileLinkBasename(path: string): string {
18 return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path;
19 }
20
21 +// Emphasis markers too: `__init__.py` would otherwise render as bold "init.py",
22 +// which no longer matches the path, so the label shows beside the chip.
23 function escapeMarkdownLinkLabel(label: string): string {
22 - return label.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]");
24 + return label.replace(/[\\[\]*_]/g, "\\$&");
25 }
26
27 function encodeMarkdownLinkDestination(path: string): string {