Repository navigation
fix(shared): file mentions of __init__.py keep their name as the label - #31593
Merged
juliusmarminge merged 6 commits intoNov 15, 2026
Merged
juliusmarminge merged 6 commits into
juliusmarminge merged 6 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@-mentioning a Python package file such as
pkg/__init__.pyin the composer sends[__init__.py](pkg/__init__.py). Markdown reads the__init__in the label as bold, so the sent message shows a stray bold "init.py" next to the__init__.pyfile chip. The same happens for__main__.pyand any file name with emphasis or code markers. Thread search also indexes the label as "init.py".Steps: in a project with
pkg/__init__.py, type@__init__in the composer, pick the file, and send.Change
escapeMarkdownLinkLabelinpackages/shared/src/composerTrigger.tsescaped only\,[and]. It now also escapes*,_and`, asmarkdownLabelinpackages/shared/src/codexFileCitations.tsalready does. The label then renders as the file name,isMarkdownFileLinkLabelmatches it against the path, and chat shows only the chip.The serializer is shared, so this covers every caller: web composer @-mentions, file browser and drag-to-mention, mobile mentions, and the server triage prompt. The composer's own chip parser already unescapes any
\xin a label (collectMentionTokensinpackages/shared/src/composerInlineTokens.ts), so mentions still turn into chips in the editor.Thread search (
apps/server/src/orchestration-v2/ThreadSearch.ts) swaps each link for its raw label before matching. With escaped labels, a search for__init__.pywould miss the mention, so it now drops Markdown backslash escapes from the label first, matching what the thread shows.Scope and approval
A very small, focused fix for an obvious bug: a file name renders as different text than the file it names, and #16619 fixed the same
__init__.pyemphasis problem for pasted paths. I searched issues and PRs for "init.py", "dunder", "file mention underscore bold", "escapeMarkdownLinkLabel", "serializeComposerFileLink" and similar phrasings and found no existing report or fix.Verification
serializeComposerFileLinktests inpackages/shared/src/composerTrigger.test.ts. They parse the serialized link with remark and check that the label text equals the file name, for__init__.py,__main__.py,*draft*.mdand`tick`.ts. On main all 4 fail (for exampleexpected 'init.py' to be '__init__.py'). With the fix they pass:vp test run packages/shared/src/composerTrigger.test.ts packages/shared/src/composerInlineTokens.test.tsgives 65 passed.collectComposerInlineTokensstill returns a mention token for escaped links topkg/__init__.py,C:\repo\__main__.pyanddocs/My File (draft).md.apps/server/src/orchestration-v2/ThreadSearch.test.tswith a stored mention[\_\_init\_\_.py](pkg/__init__.py). Without the search change, a search for__init__.pyreturns nothing; with it, the thread matches with the snippetFix __init__.py(26 passed).vp run check:changed: format, lint, knip, typecheck (34 packages) and tests pass.vp run dev(web, macOS, Replay provider) with a demo project containingpkg/__init__.py. I picked the file from the @ menu and sent it, on main and then on this branch.Before (main):
After (this branch):
Not checked: the desktop app and mobile client. Both render through the same shared serializer. Names with
*or backticks are not file-link chips at all (looksLikeFilePathrejects them), so for those this fix only stops the label text from being garbled.Code and verification by Claude Opus 5.5 in Claude Code, run from T3 Code.
🤖 Generated with Claude Code