-
Notifications
You must be signed in to change notification settings - Fork 7.9k
TUI/Core: preserve duplicate skill/app mention selection across submit + resume #10855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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: 5def75d495
ℹ️ 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".
17c1372 to
ffdefc3
Compare
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| struct ComposerMentionBinding { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codex can you help me understand how we use MentionBinding? More specially:
- When do we set MentionBinding;
- How do we clear MentionBinding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answer
1. When do we set MentionBinding?
- On mention selection from the popup: when a user picks a skill/app mention,
insert_selected_mentioninserts the$tokenas an element and stores the binding (mention+path) inmention_bindingskeyed by that element id. codex-rs/tui/src/bottom_pane/chat_composer.rsL1846-L1861 - When restoring a draft with bindings:
set_text_content_with_mention_bindingsrehydrates mention bindings viabind_mentions_from_snapshot, which scans for$tokenoccurrences and rebuilds the binding map to match the restored text/elements. codex-rs/tui/src/bottom_pane/chat_composer.rsL777-L815 codex-rs/tui/src/bottom_pane/chat_composer.rsL1912-L1944
2. How do we clear MentionBinding?
- Fresh draft resets:
set_text_contentroutes toset_text_content_with_mention_bindings(..., Vec::new()), which explicitly clearsself.mention_bindingsbefore any new content is set, so starting fresh clears all bindings. codex-rs/tui/src/bottom_pane/chat_composer.rsL757-L796 - Explicit drain:
take_mention_bindingsremoves any bindings tied to current mention elements and then clears the map entirely, returning the drained bindings. codex-rs/tui/src/bottom_pane/chat_composer.rsL426-L440 - Snapshot rebind:
bind_mentions_from_snapshotalways clears existing bindings before re-adding the snapshot’s bindings, so rehydrate paths replace the current map rather than merge with it. codex-rs/tui/src/bottom_pane/chat_composer.rsL1912-L1944
Commands Used
sed -n '1,220p' codex-rs/tui/src/bottom_pane/chat_composer.rsrg -n "MentionBinding" codex-rs/tui/src/bottom_pane/chat_composer.rssed -n '260,520p' codex-rs/tui/src/bottom_pane/chat_composer.rssed -n '780,980p' codex-rs/tui/src/bottom_pane/chat_composer.rssed -n '1820,1985p' codex-rs/tui/src/bottom_pane/chat_composer.rsrg -n "mention_bindings\\.clear|mention_bindings =|mention_bindings\\.insert" codex-rs/tui/src/bottom_pane/chat_composer.rsrg -n "set_text_content\\(" -n codex-rs/tui/src/bottom_pane/chat_composer.rsrg -n "take_mention_bindings\\(|mention_bindings\\(" codex-rs/tui/srcsed -n '220,520p' codex-rs/tui/src/bottom_pane/mod.rssed -n '3000,3095p' codex-rs/tui/src/chatwidget.rsnl -ba codex-rs/tui/src/bottom_pane/chat_composer.rs | sed -n '720,860p'nl -ba codex-rs/tui/src/bottom_pane/chat_composer.rs | sed -n '1828,1935p'nl -ba codex-rs/tui/src/bottom_pane/chat_composer.rs | sed -n '1935,1965p'nl -ba codex-rs/tui/src/bottom_pane/chat_composer.rs | sed -n '420,450p'
What changed
codex-rs/core/src/skills/injection.rs, we now honor explicitUserInput::Skill { name, path }first, then fall back to text mentions only when safe.codex-rs/tui/src/bottom_pane/chat_composer.rs, mention selection is now token-bound (selected mention is tied to the specific inserted$token), and we snapshot bindings at submit time so selection is not lost.codex-rs/tui/src/chatwidget.rsandcodex-rs/tui/src/bottom_pane/mod.rs, submit/queue paths now consume the submit-time mention snapshot (instead of rereading cleared composer state).codex-rs/tui/src/mention_codec.rsandcodex-rs/tui/src/bottom_pane/chat_composer_history.rs, history now round-trips mention targets so resume restores the same selected duplicate.codex-rs/tui/src/bottom_pane/skill_popup.rsandcodex-rs/tui/src/bottom_pane/chat_composer.rs, duplicate labels are normalized to[Repo]/[App], app rows no longer showConnected -, and description space is a bit wider.Before vs now
Manual test
cd /Users/daniels/code/codex/codex-rscargo build -p codex-cli --bin codex./target/debug/codex$and pick a duplicate entry (not the first one).[Repo][App]Connected -Expected: it keeps the same selected duplicate target.
/resumeto reopen the session and send again.Expected: restored mention still resolves to the same duplicate target.