Skip to content

Fix slash command suggestion filtering#1664

Open
chioarub wants to merge 1 commit into
Gitlawb:mainfrom
chioarub:fix/slash-command-prefix-pruning
Open

Fix slash command suggestion filtering#1664
chioarub wants to merge 1 commit into
Gitlawb:mainfrom
chioarub:fix/slash-command-prefix-pruning

Conversation

@chioarub

@chioarub chioarub commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Filters slash command suggestions to visible name or alias matches for typed slash queries, including substring matches.
  • Preserves existing fuzzy ranking as a tie-breaker instead of allowing description-only rows into the visible list.
  • Hardens command metadata reads so broken dynamic getters cannot break rendering, completion, or command acceptance.

Root Cause

Typed slash queries still allowed fuzzy description matches to remain visible, so the list often stayed broad even when the typed characters did not appear in a command identifier. Some hook and apply paths also re-read dynamic command metadata directly after suggestions were generated.

Validation

  • bun test src/utils/suggestions/commandSuggestions.test.ts
  • bun test src/utils/suggestions/commandSuggestions.test.ts src/components/PromptInput/PromptInputFooterSuggestions.test.tsx
  • bun run typecheck
  • bun run build
  • git diff --check
  • node bin/openclaude --version
  • Runtime command corpus check for /, /co, /con, /len, /view, and /prov

Notes

The full serial suite still reports unrelated order-dependent failures in auto-compact and export tests. The exact failing files pass when run directly: bun test src/services/compact/autoCompact.test.ts src/commands/export/export.test.ts.

Summary by CodeRabbit

  • Bug Fixes

    • Improved robustness of command suggestion matching to handle edge cases where command metadata becomes unavailable or invalid.
    • Enhanced exact command name lookup and filtering logic for more reliable autocompletion.
  • Tests

    • Expanded test coverage for command suggestion behavior, including edge cases and filtering scenarios.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 70347fd5-ba16-43d5-b0d8-0d5b8935c2ee

📥 Commits

Reviewing files that changed from the base of the PR and between a36ef46 and a038ae2.

📒 Files selected for processing (3)
  • src/hooks/useTypeahead.tsx
  • src/utils/suggestions/commandSuggestions.test.ts
  • src/utils/suggestions/commandSuggestions.ts
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise in code

Files:

  • src/hooks/useTypeahead.tsx
  • src/utils/suggestions/commandSuggestions.test.ts
  • src/utils/suggestions/commandSuggestions.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/hooks/useTypeahead.tsx
  • src/utils/suggestions/commandSuggestions.test.ts
  • src/utils/suggestions/commandSuggestions.ts
**

⚙️ CodeRabbit configuration file

**: # Contributing to OpenClaude

Thanks for contributing.

OpenClaude is a fast-moving open-source coding-agent CLI with support for multiple providers, local backends, MCP, and a terminal-first workflow. The best contributions here are focused, well-tested, and easy to review.

Before You Start

  • Search existing issues and discussions before opening a new thread.
  • Check open pull requests for work that overlaps with your contribution. If a PR already exists that addresses the same change, open an issue or discussion first to align on direction — duplicate PRs may be closed without review.
  • Use issues for confirmed bugs and actionable feature work.
  • Use discussions for setup help, ideas, and general community conversation.
  • For larger changes, open an issue first so the scope is clear before implementation.
  • For security reports, follow SECURITY.md.

Pull Requests

Every PR needs a reason. Your PR description must include:

  • what changed and why
  • the user or developer impact
  • the exact checks you ran
  • a linked issue when one exists, using Fixes fix: skip assertMinVersion for third-party providers #123, `Closes `#123, or another clear link
  • screenshots when the PR touches UI, terminal presentation, or the VS Code extension
  • which provider path was tested when the PR changes provider behavior

The PR author is responsible for ensuring their PR is merge-ready. PRs with merge conflicts will not be reviewed or approved until the conflicts are resolved.

Issues are the recommended starting point for anything non-trivial — opening one first helps avoid wasted effort if the change is out of scope or already being worked on. Small fixes, doc corrections, and obvious improvements can stand on their own without a linked issue, as long as the PR description explains the intent.

What Gets Closed Without Review

PRs may be closed without review...

Files:

  • src/hooks/useTypeahead.tsx
  • src/utils/suggestions/commandSuggestions.test.ts
  • src/utils/suggestions/commandSuggestions.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/suggestions/commandSuggestions.test.ts
🔇 Additional comments (22)
src/utils/suggestions/commandSuggestions.ts (15)

55-65: LGTM!


95-153: LGTM!


155-177: LGTM!


196-205: LGTM!


291-306: LGTM!


318-335: LGTM!


351-379: LGTM!


381-399: LGTM!


416-426: LGTM!


432-441: LGTM!


447-465: LGTM!


467-477: LGTM!


538-623: LGTM!


625-776: LGTM!


781-829: LGTM!

src/utils/suggestions/commandSuggestions.test.ts (4)

17-66: LGTM!


79-186: LGTM!


284-699: LGTM!


721-1082: LGTM!

src/hooks/useTypeahead.tsx (3)

7-7: LGTM!

Also applies to: 25-34


389-389: LGTM!


738-738: LGTM!


📝 Walkthrough

Walkthrough

Refactors commandSuggestions.ts to build suggestions from precomputed CommandSearchSnapshot objects instead of reading Command properties directly, adding safe getter wrappers (safeCommandAliases, etc.), new lookup helpers (findCommandByExactName, findCommandByNameOrAlias), and a snapshot-driven Fuse index. useTypeahead delegates max-width and exact-match logic to the new helpers. Tests are substantially expanded to cover throwing-getter resilience and identifier-based filtering.

Changes

Safe snapshot-driven command suggestions

Layer / File(s) Summary
Safe metadata helpers and snapshot construction
src/utils/suggestions/commandSuggestions.ts
Adds safeCommandAliases with try/catch logging; introduces getCommandFuseForSnapshots; updates snapshot aliases derivation to use the safe helper; refines isCommandMetadata type guard; removes getCommand import; extends getCommandId to accept an optional precomputed name.
New lookup, parsing, and width helpers
src/utils/suggestions/commandSuggestions.ts
Adds findCommandByExactName, findCommandByNameOrAlias, commandNameFromSuggestionDisplay; updates getCommandSuggestionsMaxWidth to use safeIsHidden/safeCommandName; switches findMatchedAlias from prefix to substring matching; extends createCommandSuggestionItem and adds createCommandSuggestionItemFromSnapshot.
Safe match resolution
src/utils/suggestions/commandSuggestions.ts
Updates getBestCommandMatch and getCommandSuggestionForEnter to use safeCommandName; rewrites applyCommandSuggestion to resolve via findCommandByNameOrAlias with early returns on name-parse failure.
generateCommandSuggestions '/' branch refactored to snapshots
src/utils/suggestions/commandSuggestions.ts
Replaces direct Command iteration with CommandSearchSnapshot objects for visibility filtering, recently-used scoring, ID deduplication, and category partitioning; return mapping uses createCommandSuggestionItemFromSnapshot.
generateCommandSuggestions non-empty query branch and ranking
src/utils/suggestions/commandSuggestions.ts
Rewrites hidden-exact detection, Fuse indexing (getCommandFuseForSnapshots), withMeta precomputation, getMatchRank-based sorting with Fuse score/usage tie-breakers, nullish-safe score delta, and snapshot-based result conversion.
useTypeahead delegation to new helpers
src/hooks/useTypeahead.tsx
Splits Command type import; adds findCommandByExactName to named imports; delegates allCommandsMaxWidth to getCommandSuggestionsMaxWidth; replaces inline getCommandName comparison with findCommandByExactName.
Test helper expansion and localization rewrites
src/utils/suggestions/commandSuggestions.test.ts
Extends promptCommand helper to accept aliases and isHidden; rewrites localization assertions for built-in/bundled/plugin descriptions using substring checks and per-source ownership expectations.
Regression tests for throwing getter resilience
src/utils/suggestions/commandSuggestions.test.ts
Adds tests for commands with throwing name, aliases, isHidden, and description getters across bare / listing, typed lookup, exact-name Enter, getBestCommandMatch, applyCommandSuggestion, and getCommandSuggestionsMaxWidth.
Identifier filtering and ranking test suite
src/utils/suggestions/commandSuggestions.test.ts
New generateCommandSuggestions identifier filtering describe block covering query-length pruning, word-boundary/separator-part inclusion, alias substring matching, and ranking order.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Gitlawb/openclaude#1431: Introduced getCommandSuggestionsMaxWidth and exact-name finder helpers that this PR now delegates to from useTypeahead.
  • Gitlawb/openclaude#1657: Changes the same commandSuggestions.ts and useTypeahead.tsx pipeline to handle problematic command metadata and reranking behavior.

Suggested reviewers

  • kevincodex1
  • jatmn
🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix slash command suggestion filtering' accurately describes the main change—improving how slash command suggestions are filtered to match visible names/aliases.
Description check ✅ Passed The description covers summary, root cause, and validation steps, but lacks explicit impact section and testing checkboxes from the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Risk Surface Disclosed ✅ Passed PR does not touch auth, provider routing, permissions, network behavior, background execution, startup/config, skills/plugins/MCP systems, CI permissions, or release scripts. Changes are scoped to...
No Hidden Policy Change ✅ Passed No hidden policy changes detected. The PR contains only technical refactoring of command suggestion filtering and metadata hardening. The policySettings categorization is defensive type-consistent...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Comment @coderabbitai help to get the list of available commands and usage tips.

@chioarub chioarub marked this pull request as ready for review June 16, 2026 07:08
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@kevincodex1 kevincodex1 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.

lgtm

@kevincodex1 kevincodex1 requested a review from jatmn June 16, 2026 07:24
@kevincodex1

Copy link
Copy Markdown
Contributor

hello @chioarub can you comment a video of this? I fixed an issue earlier in slash command not responding

@chioarub

Copy link
Copy Markdown
Contributor Author

Screencast_20260616_105359.webm
Here is a short demo from this PR branch.

It shows that slash commands still respond, and that typing after / now narrows the visible suggestions to matching command names/aliases, including substring matches.

@kevincodex1

Copy link
Copy Markdown
Contributor

awesome thank you @chioarub . please have a look @jatmn

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution. I do not see any actionable issues from my review.

@kevincodex1 LGTM

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