Skip to content

Highlight @file references and command options in message text - #1145

Open
snimu wants to merge 13 commits into
mainfrom
feat/queue-path-arg-highlighting
Open

Highlight @file references and command options in message text#1145
snimu wants to merge 13 commits into
mainfrom
feat/queue-path-arg-highlighting

Conversation

@snimu

@snimu snimu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

ENG-5282 · Linear: RES-1275 https://linear.app/primeintellect/issue/RES-1275

What this does

When you write a message in Prime Agent, three kinds of special text now each get their own color, so they are easy to tell apart at a glance:

  • Commands like /compact stay violet (as before).
  • File references like @src/main.ts are now shown in green. They previously had no color at all.
  • Command options like --global in /rlm-max-depth --global are now shown in blue. They also previously had no color.

The colors show up everywhere the message text appears: while you type it, in the list of queued messages waiting to be sent, and in messages that were already sent.

Example:

image

Why

Commands were already highlighted, but file references and options were plain text. That made it easy to miss a typo in a file path or an option name, and messages with several parts were harder to scan.

How it works

  • One shared helper finds the file references and options in the text and applies the colors. All the places that show message text use this same helper, so there is no duplicated matching logic and the colors cannot drift apart.
  • All colors come from the theme, so custom themes can restyle them.
  • Two subtle cases needed real care, and both were caught by review rounds during development:
    • Sent messages are rendered through the markdown formatter, which adds its own styling. The helper marks the special text before formatting and colors it after, so highlights survive formatting and text that wraps across lines is colored completely.
    • The editor colors text by its exact position in what you typed, so two identical words — one a file reference, one plain text — are told apart correctly even after scrolling.
  • To support that last point, the shared text editor now tells subclasses which part of the original text each display line shows (a small, backward-compatible addition; existing editors are unaffected).

Changes

  • New shared helper: prompt-highlight.ts (+188 lines).
  • Editor, queued-message preview, and sent-message components now use it; the sent-message component lost some duplicated masking code in the process (−41 lines there).
  • Text editor in the TUI package passes source positions to its styling hook (+20 lines, optional parameters, no behavior change for existing users).
  • Tests for the editor and message rendering (+121 lines).
  • One changelog entry each for the coding agent and the TUI package.

Lines changed: source +249/−44, tests +121/−0, changelogs +3/−0, total +373/−44.

Checks

  • npm run check clean.
  • Focused tests: 34/34 (user-message 13, custom-editor 21); the full TUI package suite (~200 tests) passes.
  • Went through three review rounds; the first two caught real rendering bugs (highlights lost after formatting, wrong text colored after scrolling) that the final version fixes.

Note

Low Risk
Changes are limited to terminal rendering and styling; no auth, persistence, or command execution behavior is altered beyond visual token rules.

Overview
Adds shared prompt highlighting so @file references, --flags, and (for argument-taking slash commands) bare -- separators pick up theme colors everywhere message text appears: the input editor, queued previews, sent user messages, and slash-command messages.

A new prompt-highlight module centralizes token detection and styling. The editor uses source-line offsets from an extended TUI styleDisplayText hook so wrapped or scrolled lines color only the real token spans, not duplicate plain text. Sent messages mask tokens before Markdown layout and restore colors afterward, including correct copy/selection text via PromptTokenMask.

Reviewed by Cursor Bugbot for commit 285ccf4. Bugbot is set up for automated code reviews on this repo. Configure here.

LOC

Total src: +286/−48 (net +238); tests: +160/−1 (net +159).

Note

Highlight @file references and --flags in interactive editor, previews, and sent messages

  • Adds PromptTokenMask and ArgTokenHighlighter in prompt-highlight.ts to mask and color @path, --flag, and bare -- tokens across Markdown layout and wrapped editor lines while preserving grapheme widths.
  • Extends Editor.styleDisplayText and LayoutLine in editor.ts with source-line and source-offset coordinates so subclasses can style wrapped chunks by their logical source position.
  • Applies shared argument-token styling in custom-editor.ts, user-message.ts, slash-command-message.ts, and interactive-mode.ts. Bare -- is highlighted only for recognized argument-taking slash commands.
  • Behavioral Change: Mid-word @ and -- sequences are excluded from highlighting; tokens split by cursor escape sequences or line wrapping retain their color. Literal private-use mask-range characters in input are left uncorrupted and selection regions return unmasked source text.

Macroscope summarized 285ccf4.

Comment thread packages/coding-agent/src/modes/interactive/components/prompt-highlight.ts Outdated
Comment thread packages/coding-agent/src/modes/interactive/components/prompt-highlight.ts Outdated
@snimu

snimu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Update

The PR now also highlights a standalone -- in slash commands, in the same blue as options.

In a command like /new --name bla -- hello, the bare -- marks where options end and the message text begins — it is part of the command's structure, not of your text. It is only colored inside recognized slash commands; in ordinary messages, -- stays plain (people often type it as a dash in prose).

This added a net 6 lines of source code and three tests.

Comment thread packages/coding-agent/src/modes/interactive/components/user-message.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit aac41f2. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant