fix(tui): resolve @ file mentions to absolute paths on send - #2711
fix(tui): resolve @ file mentions to absolute paths on send#2711fdciabdul wants to merge 3 commits into
Conversation
@ 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 detectedLatest commit: e65bc42 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 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".
| this.state.appState.additionalDirs, | ||
| ); | ||
| if (enrichedText !== text) { | ||
| this.sendMessage(session, text, { parts: [{ type: 'text', text: enrichedText }] }); |
There was a problem hiding this comment.
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 👍 / 👎.
| const enrichedText = buildTextWithResolvedMentions( | ||
| text, | ||
| this.state.appState.workDir, | ||
| this.state.appState.additionalDirs, | ||
| ); |
There was a problem hiding this comment.
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.
|
Addressed both findings:
@codex review |
There was a problem hiding this comment.
💡 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".
| parts: grounding === undefined ? extraction.parts : [...extraction.parts, grounding], | ||
| imageAttachmentIds: extraction.imageAttachmentIds, | ||
| }); | ||
| } else if (grounding !== undefined) { | ||
| this.sendMessage(session, text, { parts: [{ type: 'text', text }, grounding] }); |
There was a problem hiding this comment.
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 👍 / 👎.
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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 withls/findbefore 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
gen-changesetsskill.gen-docsskill, or this PR needs no doc update. (no doc update needed — internal prompt-construction behavior)