nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Command completion prioritizes 'ends with' over 'starts with'

Open JimStenstrom opened this issue 11 months ago • 0 comments

Description

When typing /l + Tab for command completion, /model appears before /lsp even though /lsp starts with 'l' and /model only ends with 'l'.

This is because the fuzzy scoring algorithm in source/utils/fuzzy-matching.ts ranks "ends with" (850) higher than "starts with" (800):

// Text ends with query
if (lowerText.endsWith(lowerQuery)) {
    return 850;  // Higher score
}

// Text starts with query
if (lowerText.startsWith(lowerQuery)) {
    return 800;  // Lower score
}

For command completion, prefix matching should be prioritized over suffix matching.

Environment

  • Nanocoder version: 1.19.2

Steps to Reproduce

  1. Type /l
  2. Press Tab

Expected Behavior

/lsp should appear first since it starts with 'l'

Actual Behavior

/model appears first because it ends with 'l' (score 850 > 800)

Proposed Fix

Swap the priority scores:

  • "starts with" → 850
  • "ends with" → 800

Or create a separate scoring function for command completion that prioritizes prefix matches.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

JimStenstrom avatar Dec 26 '25 04:12 JimStenstrom