fix: restore ctrl-1, ctrl-2... shortcuts for quick agent selection#1816
fix: restore ctrl-1, ctrl-2... shortcuts for quick agent selection#1816dgageot merged 1 commit intodocker:mainfrom
Conversation
These shortcuts were accidentally dropped during the parallel session support refactoring in commit 0069cad. This re-adds the `parseCtrlNumberKey` utility and intercepts `ctrl+1` through `ctrl+9` in the global key press handler, delegating to a new `handleSwitchToAgentByIndex` function. Assisted-By: cagent
There was a problem hiding this comment.
Review Summary
This PR successfully restores the ctrl+1-9 shortcuts for quick agent selection. The implementation is mostly sound, with one notable consideration about the key parsing approach.
Finding: 1 medium-severity issue about using a more robust key detection method.
| // parseCtrlNumberKey checks if msg is ctrl+1 through ctrl+9 and returns the index (0-8), or -1 if not matched | ||
| func parseCtrlNumberKey(msg tea.KeyPressMsg) int { | ||
| s := msg.String() | ||
| if len(s) == 6 && s[:5] == "ctrl+" && s[5] >= '1' && s[5] <= '9' { |
There was a problem hiding this comment.
parseCtrlNumberKey relies on fragile string format matching instead of direct key inspection
The function uses msg.String() with exact length and string prefix matching (len(s) == 6 && s[:5] == "ctrl+"), which is fragile. While Bubble Tea's String() method is generally consistent, a more robust approach would be to inspect the KeyPressMsg fields directly (such as Code, Runes, Alt, Ctrl).
If the string format ever changes across Bubble Tea versions or terminal configurations, ctrl+number shortcuts would be silently ignored. Consider using the structured fields of KeyPressMsg for more reliable key detection.
Severity: Medium - The feature works in practice, but could break silently with library updates.
These shortcuts were accidentally dropped during the parallel session support refactoring in commit 0069cad.
This re-adds the
parseCtrlNumberKeyutility and interceptsctrl+1throughctrl+9in the global key press handler, delegating to a newhandleSwitchToAgentByIndexfunction.Assisted-By: cagent