Skip to content

Conversation

@electron271
Copy link
Member

@electron271 electron271 commented Aug 3, 2025

Description

tux will now suggest aliases if they are a closer match to ensure the user gets a more accurate recommendation

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

ran a bunch of wrong commands that are similar to aliases

Screenshots (if applicable)

Please add screenshots to help explain your changes.

Additional Information

Please add any other information that is important to this PR.

Summary by Sourcery

Enhance the command suggestion logic to evaluate aliases when determining the closest match and return the alias if it provides a better match than the original command name.

Enhancements:

  • Prioritize alias names over primary command names when computing Levenshtein distance for suggestions
  • Update internal logic to track and store the best-matching name (alias or command)
  • Adjust command suggestion docstring to reflect that aliases may be returned

Documentation:

  • Clarify in the docstring that suggestions can include aliases when they more closely match the user’s input

@electron271 electron271 self-assigned this Aug 3, 2025
@electron271 electron271 added category: meta Relating to architecture, systems and critical functions priority: medium labels Aug 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 3, 2025

Reviewer's Guide

Refactors command suggestion logic to return the closest-matching alias when it better matches user input, rather than always returning the command’s qualified name.

Class diagram for updated command suggestion logic

classDiagram
    class ErrorHandler {
        _suggest_command(ctx: Context) List~str~ | None
    }
    class Command {
        qualified_name: str
        aliases: List~str~
    }
    ErrorHandler --> Command : iterates over

    %% Highlighted logic change
    ErrorHandler : +Suggests best match (alias or qualified_name)
    Command : +aliases considered for suggestion
Loading

File-Level Changes

Change Details Files
Enhanced documentation to include alias suggestions
  • Updated return description to mention aliases in suggested output
  • Clarified alias preference behavior in docstring
tux/handlers/error.py
Updated match storage key to use the suggested name
  • Renamed comment to reflect storing name_to_suggest instead of qualified_name
  • Switched dictionary key from qualified_name to best_match_name
tux/handlers/error.py
Introduced best_match_name to track closest match
  • Declared best_match_name initialized to cmd.qualified_name
  • Assigned best_match_name when a lower Levenshtein distance is found
tux/handlers/error.py
Adjusted distance comparison and storage logic
  • Changed distance loop to update min_dist_for_cmd only when distance is strictly lower
  • Updated command_distances insertion and lookup to use best_match_name
tux/handlers/error.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @electron271 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `tux/handlers/error.py:1231` </location>
<code_context>
                 # than previously stored, update the distance.
-                current_min = command_distances.get(qualified_name, max_distance + 1)
+                current_min = command_distances.get(best_match_name, max_distance + 1)
                 if min_dist_for_cmd < current_min:
-                    command_distances[qualified_name] = min_dist_for_cmd
+                    command_distances[best_match_name] = min_dist_for_cmd

         # If no commands were within the distance threshold.
</code_context>

<issue_to_address>
Storing suggestions by best_match_name may lead to duplicate suggestions for commands with multiple close aliases.

To prevent redundant suggestions, deduplicate or select a single alias per command when multiple aliases meet the threshold.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                if distance < min_dist_for_cmd:
                    min_dist_for_cmd = distance
                    best_match_name = name

            # If the command is close enough, store its distance.
            if min_dist_for_cmd <= max_distance:
                # If we found a closer match for this command (e.g., via an alias)
                # than previously stored, update the distance.
                current_min = command_distances.get(best_match_name, max_distance + 1)
                if min_dist_for_cmd < current_min:
                    command_distances[best_match_name] = min_dist_for_cmd
=======
                if distance < min_dist_for_cmd:
                    min_dist_for_cmd = distance
                    best_match_name = name
                    canonical_name = qualified_name  # Track the canonical command name

            # If the command is close enough, store its distance.
            if min_dist_for_cmd <= max_distance:
                # Deduplicate by canonical command name, only keep the closest alias
                current_min = command_distances.get(canonical_name, max_distance + 1)
                if min_dist_for_cmd < current_min:
                    command_distances[canonical_name] = min_dist_for_cmd
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +1222 to +1232
if distance < min_dist_for_cmd:
min_dist_for_cmd = distance
best_match_name = name

# If the command is close enough, store its distance.
if min_dist_for_cmd <= max_distance:
# If we found a closer match for this command (e.g., via an alias)
# than previously stored, update the distance.
current_min = command_distances.get(qualified_name, max_distance + 1)
current_min = command_distances.get(best_match_name, max_distance + 1)
if min_dist_for_cmd < current_min:
command_distances[qualified_name] = min_dist_for_cmd
command_distances[best_match_name] = min_dist_for_cmd
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Storing suggestions by best_match_name may lead to duplicate suggestions for commands with multiple close aliases.

To prevent redundant suggestions, deduplicate or select a single alias per command when multiple aliases meet the threshold.

Suggested change
if distance < min_dist_for_cmd:
min_dist_for_cmd = distance
best_match_name = name
# If the command is close enough, store its distance.
if min_dist_for_cmd <= max_distance:
# If we found a closer match for this command (e.g., via an alias)
# than previously stored, update the distance.
current_min = command_distances.get(qualified_name, max_distance + 1)
current_min = command_distances.get(best_match_name, max_distance + 1)
if min_dist_for_cmd < current_min:
command_distances[qualified_name] = min_dist_for_cmd
command_distances[best_match_name] = min_dist_for_cmd
if distance < min_dist_for_cmd:
min_dist_for_cmd = distance
best_match_name = name
canonical_name = qualified_name # Track the canonical command name
# If the command is close enough, store its distance.
if min_dist_for_cmd <= max_distance:
# Deduplicate by canonical command name, only keep the closest alias
current_min = command_distances.get(canonical_name, max_distance + 1)
if min_dist_for_cmd < current_min:
command_distances[canonical_name] = min_dist_for_cmd

Copy link
Collaborator

@meatharvester meatharvester left a comment

Choose a reason for hiding this comment

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

everything looks good from what we tested so i think this is good to merge

@codecov
Copy link

codecov bot commented Aug 3, 2025

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.57%. Comparing base (1c151c4) to head (354a24f).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tux/handlers/error.py 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #999      +/-   ##
========================================
- Coverage   9.57%   9.57%   -0.01%     
========================================
  Files        123     123              
  Lines      10412   10415       +3     
  Branches    1278    1279       +1     
========================================
  Hits         997     997              
- Misses      9313    9316       +3     
  Partials     102     102              
Flag Coverage Δ *Carryforward flag
database 0.31% <ø> (+<0.01%) ⬆️ Carriedforward from 1c151c4
integration 5.85% <0.00%> (-0.01%) ⬇️
unit 6.30% <0.00%> (-0.01%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Core Bot Infrastructure 16.43% <ø> (ø)
Database Layer 0.00% <ø> (ø)
Bot Commands & Features 0.00% <ø> (ø)
Event & Error Handling ∅ <ø> (∅)
Utilities & Helpers ∅ <ø> (∅)
User Interface Components 0.00% <ø> (ø)
CLI Interface ∅ <ø> (∅)
External Service Wrappers ∅ <ø> (∅)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@electron271 electron271 merged commit 85084b5 into main Aug 3, 2025
33 checks passed
@electron271 electron271 deleted the command-suggestion-aliases branch August 3, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: meta Relating to architecture, systems and critical functions priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants