Skip to content

fix(vscode): sort slash commands by relevance (exact > prefix > substring) - #11557

Merged
markijbema merged 8 commits into
Kilo-Org:mainfrom
rakshith1928:feature/improve-slash-command-sorting
Jun 25, 2026
Merged

fix(vscode): sort slash commands by relevance (exact > prefix > substring)#11557
markijbema merged 8 commits into
Kilo-Org:mainfrom
rakshith1928:feature/improve-slash-command-sorting

Conversation

@rakshith1928

@rakshith1928 rakshith1928 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Issue

Fixes #11534

Context

When a user types a slash-command (e.g., /commit), the dropdown results appear in their loading order rather than sorted by relevance. Since the first result is selected by default, typing an exact command name and hitting Enter frequently inserts a different command frustrating for users who expect /commit to match /commit first.

Implementation

Added a getMatchScore() function in webview-ui/src/hooks/useSlashCommand.ts that scores each command by match quality against the typed query:

  • Exact name match (score 3) e.g., typing commit matches /commit
  • Prefix match (score 2) e.g., typing com matches /commit, /compact
  • Substring match in name/description/hints (score 1) fallback
    The results() function now sorts descending by score, placing exact matches at the top, followed by prefix matches, then substring matches. Stable sort preserves original order for same-score items.

Screenshots / Video

  • Before
Screenshot 2026-06-23 045923
  • After
Screenshot 2026-06-23 045713

How to Test

Manual/local verification

  • bun test ./tests/unit/use-slash-command-sorting.test.ts - 5/5 tests pass
  • bun script/typecheck.ts --project webview-ui/tsconfig.json - clean exit (0 errors)

Reviewer test steps

  1. Launch extension: bun run extension (or bun run dev + extension host)
  2. Open chat panel, type /c -> observe dropdown ordering
  3. Type /commit ->confirm /commit appears first (exact match selected)
  4. Type /com -> confirm /commit and /compact appear before any substring-only matches
  5. Type /smol-> confirm /compact appears first (hint match)
  6. Type /xyz123 -> confirm "No commands found"

Blocked checks and substitute verification

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

TRAVIX 26 Discord

action?: () => void
}

const getMatchScore = (cmd: SlashCommandEntry, lower: string): number => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: This test reimplements the production matcher instead of exercising it

getMatchScore() and sortResults() here are a second copy of the new hook logic, so the suite can stay green even if useSlashCommand().results() regresses or the two copies drift apart later. Testing the hook directly, or asserting through a single shared helper, would give this PR real protection against future ordering bugs.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/kilo-vscode/tests/unit/use-slash-command-sorting.test.ts
  • packages/kilo-vscode/webview-ui/src/hooks/useSlashCommand.ts
Previous Review Summaries (4 snapshots, latest commit 14a8d7a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 14a8d7a)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • packages/kilo-vscode/tests/unit/use-slash-command-sorting.test.ts

Previous review (commit d086710)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • .changeset/slash-command-sorting.md

Previous review (commit 590d8e4)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
.changeset/* N/A This changes user-visible slash-command ordering in the VS Code extension, but the PR still does not include a changeset entry.
Files Reviewed (2 files)
  • packages/kilo-vscode/webview-ui/src/hooks/useSlashCommand.ts
  • packages/kilo-vscode/tests/unit/use-slash-command-sorting.test.ts

Fix these issues in Kilo Cloud

Previous review (commit 121c12d)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/tests/unit/use-slash-command-sorting.test.ts 10 The new test copies getMatchScore() / sortResults() instead of exercising useSlashCommand(), so it can pass even if the production matcher regresses.
.changeset/* N/A This changes user-visible slash-command ordering in the VS Code extension, but the PR does not appear to include a changeset entry.
Files Reviewed (2 files)
  • packages/kilo-vscode/webview-ui/src/hooks/useSlashCommand.ts
  • packages/kilo-vscode/tests/unit/use-slash-command-sorting.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by gpt-5.4-20260305 · Input: 39.3K · Output: 4.2K · Cached: 151.5K

Review guidance: REVIEW.md from base branch main

@rakshith1928 rakshith1928 changed the title fix(vscode): sort slash commands by relevance (exact > prefix > subst… fix(vscode): sort slash commands by relevance (exact > prefix > substring) Jun 23, 2026

@markijbema markijbema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please extract the sorting in a function and test that instead? I feel this could be the most readable unittest in the world, and doesnt need mocking at all.

so extract sortByScore, which gets the array of matches and the search string, and returns an array.

@rakshith1928
rakshith1928 requested review from a team and markijbema June 23, 2026 11:54
@rakshith1928

Copy link
Copy Markdown
Contributor Author

Updated the PR: extracted "sortByScore" and rewrote the tests as pure function tests with no mocking.

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Nice fix, @rakshith1928 !

@markijbema

Copy link
Copy Markdown
Contributor

@rakshith1928 I'll merge it, no need to do additional merges from main; we got some issues with flakey tests, I'm also looking into them!

@markijbema
markijbema merged commit 5e51827 into Kilo-Org:main Jun 25, 2026
20 checks passed
@johnnyeric

Copy link
Copy Markdown
Contributor

Hey @rakshith1928, could you please link your GitHub account to the Kilo account? This way, we can grant you credits for the merged PRs.
Once you have done that, please message johnny[at]kilocode.ai

t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…lash-command-sorting

fix(vscode): sort slash commands by relevance (exact > prefix > substring)
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.

[VSCode] Improve sorting of slash-commands

4 participants