Skip to content

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

Merged
juliusmarminge merged 6 commits into
pingdotgg:mainfrom
matyasrathonyi:fix/escape-file-mention-label-emphasis
Nov 15, 2026
Merged

juliusmarminge merged 6 commits into
pingdotgg:mainfrom
matyasrathonyi:fix/escape-file-mention-label-emphasis

Conversation

@matyasrathonyi

@matyasrathonyi matyasrathonyi commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

@-mentioning a Python package file such as pkg/__init__.py in 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__.py file chip. The same happens for __main__.py and 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

escapeMarkdownLinkLabel in packages/shared/src/composerTrigger.ts escaped only \, [ and ]. It now also escapes *, _ and `, as markdownLabel in packages/shared/src/codexFileCitations.ts already does. The label then renders as the file name, isMarkdownFileLinkLabel matches 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 \x in a label (collectMentionTokens in packages/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__.py would 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__.py emphasis 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

  • Added rows to the existing serializeComposerFileLink tests in packages/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*.md and `tick`.ts. On main all 4 fail (for example expected '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.ts gives 65 passed.
  • Checked separately (not committed) that collectComposerInlineTokens still returns a mention token for escaped links to pkg/__init__.py, C:\repo\__main__.py and docs/My File (draft).md.
  • Extended the "matches messages as they read, with links as their text" case in apps/server/src/orchestration-v2/ThreadSearch.test.ts with a stored mention [\_\_init\_\_.py](pkg/__init__.py). Without the search change, a search for __init__.py returns nothing; with it, the thread matches with the snippet Fix __init__.py (26 passed).
  • vp run check:changed: format, lint, knip, typecheck (34 packages) and tests pass.
  • Manual check in vp run dev (web, macOS, Replay provider) with a demo project containing pkg/__init__.py. I picked the file from the @ menu and sent it, on main and then on this branch.

Before (main):

Before: a bold "init.py" appears next to the init.py chip

After (this branch):

After: only the init.py chip appears

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 (looksLikeFilePath rejects 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants