Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

@marius-kilocode marius-kilocode commented Dec 30, 2025

Problem: When typing / in the CLI to trigger command autocomplete, the first entry was not visually selected, requiring users to press arrow down before they could select a command.

Root Cause: The suggestion action atoms were resetting selectedIndexAtom to -1 when clearing suggestions.

This works for all autocompletion (@ / and also model selections)

image

@changeset-bot
Copy link

changeset-bot bot commented Dec 30, 2025

🦋 Changeset detected

Latest commit: d24db47

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

This PR includes changesets to release 1 package
Name Type
@kilocode/cli 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

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Dec 30, 2025

✅ No Issues Found

3 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • cli/src/state/atoms/ui.ts - Core fix for selection behavior
  • cli/src/state/atoms/__tests__/default-selection.test.ts - Comprehensive test coverage
  • .changeset/cli-slash-command-default-selection.md - Changeset

Checked: Security, bugs, logic errors, edge cases, code patterns

Analysis:

  • The fix correctly addresses the root cause: suggestion atoms were resetting selectedIndexAtom to -1 when clearing, which caused the first entry to not be selected when new suggestions appeared
  • The new behavior only sets index to 0 when suggestions are provided, and does not modify the index when clearing (allowing other suggestion types to maintain their selection)
  • This is consistent with existing patterns in approval.ts which also resets to 0 for new messages
  • The setFollowupSuggestionsAtom intentionally uses -1 for different UX (allows custom typing) - this is preserved
  • Tests are comprehensive and cover all suggestion types plus cross-menu isolation
  • No breaking changes to UI components which handle indices safely with bounds checking

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Dec 30, 2025

✅ No Issues Found

3 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files Reviewed:

  • .changeset/cli-slash-command-default-selection.md (changeset - trivial)
  • cli/src/state/atoms/__tests__/default-selection.test.ts (new test file)
  • cli/src/state/atoms/ui.ts (core fix)

Summary:
This PR fixes a UX issue where the first entry in autocomplete dropdowns was not visually selected by default when typing / to trigger command suggestions.

Root Cause & Fix:
The action atoms (setSuggestionsAtom, setArgumentSuggestionsAtom, setFileMentionSuggestionsAtom) were resetting selectedIndexAtom to -1 when clearing suggestions. The fix changes this to only set selectedIndexAtom to 0 when new suggestions are provided, without resetting when clearing.

Checked:

  • ✅ Security: No concerns (UI state management only)
  • ✅ Bugs: Logic is correct and consistent with existing patterns
  • ✅ Performance: No impact (simple conditional logic)
  • ✅ Error handling: N/A for this change
  • ✅ Test coverage: Comprehensive tests added covering all suggestion types

Code Quality:

  • Tests follow existing patterns in the codebase
  • Changes are minimal and focused
  • Comments explain the reasoning clearly

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Dec 30, 2025

✅ No Issues Found

3 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • cli/src/state/atoms/ui.ts - Core fix for selection behavior
  • cli/src/state/atoms/__tests__/default-selection.test.ts - Comprehensive test coverage
  • .changeset/cli-slash-command-default-selection.md - Changeset

Summary:
This PR correctly fixes the issue where the first entry in dropdown menus was not selected by default when typing / to trigger command autocomplete.

Root Cause Analysis:
The previous implementation reset selectedIndexAtom to -1 when clearing suggestions. This caused interference between different suggestion types (commands, arguments, file mentions) - when one type was cleared, it would reset the shared selection index, affecting other active suggestion types.

Fix Verification:

  • When suggestions are SET (length > 0): resets to index 0 ✓
  • When suggestions are CLEARED (length === 0): does NOT touch the index ✓
  • setFollowupSuggestionsAtom still correctly uses -1 (by design for custom typing) ✓
  • setPendingApprovalAtom still correctly resets to 0 for new messages ✓

Checked: Security, bugs, logic errors, edge cases, test coverage

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Dec 30, 2025

✅ No Issues Found

3 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • cli/src/state/atoms/ui.ts - Core fix for selection behavior
  • cli/src/state/atoms/__tests__/default-selection.test.ts - Comprehensive test coverage
  • .changeset/cli-slash-command-default-selection.md - Changeset

Changes Analyzed:
The fix correctly addresses the root cause where selectedIndexAtom was being reset to -1 when clearing suggestions. The new behavior:

  • Only sets selectedIndexAtom to 0 when new suggestions are provided
  • Does not reset to -1 when clearing, allowing other suggestion types to maintain their selection
  • Preserves intentional -1 behavior for followup suggestions (allows custom typing)

Checked: Security, bugs, state management, edge cases, test coverage

Quality Notes:

  • Well-documented code with clear comments explaining the rationale
  • Comprehensive test coverage for all suggestion types
  • Proper handling of cross-menu selection isolation
  • No breaking changes to existing behavior

@marius-kilocode marius-kilocode enabled auto-merge (squash) December 30, 2025 18:34
@jdm64
Copy link
Contributor

jdm64 commented Dec 31, 2025

An alternative solution is in #4708. That solution sets selectedIndexAtom to -1 if there are no suggestions of all types.

@marius-kilocode
Copy link
Collaborator Author

Closing this. We adopt the approach of #4708 instead.

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.

3 participants