Skip to content

fix(tui): resolve @ file mentions to absolute paths on send - #2711

Open
fdciabdul wants to merge 3 commits into
MoonshotAI:mainfrom
fdciabdul:fix/resolve-file-mentions
Open

fix(tui): resolve @ file mentions to absolute paths on send#2711
fdciabdul wants to merge 3 commits into
MoonshotAI:mainfrom
fdciabdul:fix/resolve-file-mentions

Conversation

@fdciabdul

Copy link
Copy Markdown

Related Issue

Resolve #2688

Problem

@ file mentions only ever insert a literal path string into the message text — there is no signal telling the model that the mentioned file actually exists at that location. As a result, the agent has to rediscover a mentioned file with ls/find before it can act on it, even when the mention already points straight at it.

What changed

Added a resolver that scans submitted text for @mention / @"quoted mention" tokens, checks each against the workspace root and additional dirs (also handling ~ and absolute paths), and appends a <mentioned-files> grounding block naming the real absolute path for anything that resolves. Only the text sent to the model gains the annotation; the transcript entry shown to the user is unchanged, the same way pasted media already splits display text from prompt parts.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill.
  • Ran gen-docs skill, or this PR needs no doc update. (no doc update needed — internal prompt-construction behavior)

@ mention only ever inserted literal path text, so the agent had to
rediscover a mentioned file itself with ls/find before acting on it,
even when the mention already pointed straight at it.
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e65bc42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0687645116

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Outdated
this.state.appState.additionalDirs,
);
if (enrichedText !== text) {
this.sendMessage(session, text, { parts: [{ type: 'text', text: enrichedText }] });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep mention grounding out of persisted prompts

When a message contains a resolvable mention, this sends enrichedText as the actual prompt payload, not just as a transient model hint. The engine derives session metadata and replayed user messages from that payload (promptMetadataTextFromContentParts / replay contentPartsToText), so after a resume/session-list/export the user-visible prompt can include the <mentioned-files> block and absolute paths even though the live transcript was appended with the original text. This affects any prompt with a resolved @ mention; the grounding should be kept out of persisted/display metadata or stripped before replay/metadata generation.

Useful? React with 👍 / 👎.

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Outdated
Comment on lines +1300 to +1304
const enrichedText = buildTextWithResolvedMentions(
text,
this.state.appState.workDir,
this.state.appState.additionalDirs,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve mentions on all prompt send paths

Resolving mentions only in this non-media Enter-submit branch leaves other supported prompt paths with raw @ tokens: a prompt that also has an image/video placeholder takes the extraction.hasMedia branch above, and Ctrl-S steering builds SteerInputItems in editor-keyboard and calls steerMessage without reaching this call. In those cases the model still has to rediscover the file, so the fix should enrich text parts in a common SDK-input path rather than only here.

Useful? React with 👍 / 👎.

…send paths

Address review feedback: the grounding block was leaking into session
metadata (title/lastPrompt) and replayed history because it was sent
merged into the same text part that gets persisted. Send it as a
separate part instead, and strip it back out wherever persisted
content is turned into display text.

Also resolve mentions on every text-carrying send path (media
messages, Ctrl-S steer), not just the plain-text Enter submit.
@fdciabdul

Copy link
Copy Markdown
Author

Addressed both findings:

  1. Grounding block now sent as a separate prompt part instead of merged into the persisted text part, and stripped back out wherever persisted content becomes display text (TUI replay, session title/lastPrompt metadata).
  2. Mentions now resolve on every text-carrying send path: plain text, text+media, and Ctrl-S steer — not just the plain-text Enter submit.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b8b0e99af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1303 to +1307
parts: grounding === undefined ? extraction.parts : [...extraction.parts, grounding],
imageAttachmentIds: extraction.imageAttachmentIds,
});
} else if (grounding !== undefined) {
this.sendMessage(session, text, { parts: [{ type: 'text', text }, grounding] });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scrub grounding from legacy metadata and exports

When a prompt with a resolved @mention is sent here, the new text part is persisted in session history for every engine, but the scrubbers added in this commit cover only TUI replay and agent-core-v2 metadata. Fresh evidence: /export-md still formats text parts verbatim in apps/kimi-code/src/tui/utils/export-markdown.ts:34, and the legacy metadata helper in packages/agent-core/src/session/prompt-metadata.ts:41 still removes only image-compression captions. In legacy sessions (KIMI_CODE_LEGACY_FLAG) or any Markdown export, users will still see the <mentioned-files> block and absolute paths, so the grounding needs to be stripped in those remaining display/metadata paths too.

Useful? React with 👍 / 👎.

@fdciabdul

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

Mention file always searching and list directory

1 participant