Skip to content

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Jul 27, 2025

This PR does 3 things:

  1. Improves the search code tool with additional parameters for the LLM to play with (repoNamesFilterRegexp, languageNamesFilter, fileNamesFilterRegexp, and limit).
  2. Adds searchReposTool and listAllReposTool. searchReposTool is possibly unnecessary so something we can consider removing prior to merging.
  3. Removes the search scope constraint that required at least 1 search scope to be selected.

Summary by CodeRabbit

  • New Features

    • Added repository search and listing tools, allowing users to search for repositories by name and view all available repositories.
    • Enhanced chat interface to display results and status for repository search and listing actions.
    • Improved code search with advanced filter options for repository names, languages, and file patterns.
  • Improvements

    • The chat submit button is now always enabled, regardless of selected search scopes.
    • Error messages for failed file loads are now more descriptive.
    • Search query construction is more flexible, supporting multiple filters.
  • Bug Fixes

    • Prevented display of empty repository search scopes in tooltips.
  • Documentation

    • Updated changelog with new features and changes.
  • Tests

    • Added comprehensive tests for search query construction utility.

Copy link

coderabbitai bot commented Jul 27, 2025

Walkthrough

This change introduces two new repository discovery tools—searchReposTool and listAllReposTool—to the chat agent, updates the code search tool to support advanced filtering, and removes the requirement for users to select repositories before submitting queries. The UI and type system are updated to support these features, and comprehensive tests are added for the new search query builder utility.

Changes

Cohort / File(s) Change Summary
Changelog Update
CHANGELOG.md
Added changelog entries for new repository tools, improved search code tool filters, and removal of search scope constraint.
ChatBox Context Selector Removal
packages/web/src/app/[domain]/chat/components/newChatPanel.tsx, packages/web/src/app/[domain]/components/homepage/agenticSearch.tsx, packages/web/src/features/chat/components/chatThread/chatThread.tsx
Removed onContextSelectorOpenChanged prop from ChatBox usage, decoupling context selector state from the chat box.
ChatBox Submission Logic Simplification
packages/web/src/features/chat/components/chatBox/chatBox.tsx
Removed logic and UI that disabled submission when no search scopes were selected; updated props and removed related warnings/tooltips.
Agent Tool and Prompt Updates
packages/web/src/features/chat/agent.ts
Added unconditional inclusion of searchReposTool and listAllReposTool to agent tools; updated system prompt to a general tool usage instruction instead of enumerating specific tools.
Details Card Tool Rendering
packages/web/src/features/chat/components/chatThread/detailsCard.tsx
Added rendering logic for new SearchReposToolComponent and ListAllReposToolComponent in chat thinking steps; improved search scopes tooltip condition to check for non-empty array.
Tool Components: New and Enhanced
packages/web/src/features/chat/components/chatThread/tools/searchReposToolComponent.tsx, packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx, packages/web/src/features/chat/components/chatThread/tools/searchCodeToolComponent.tsx
Added new React components for repository search and list tools; enhanced code search tool component to display constructed queries using new buildSearchQuery utility.
Tool Constants and Types
packages/web/src/features/chat/constants.ts, packages/web/src/features/chat/types.ts
Added new tool names and UI part types for searchRepos and listAllRepos; extended type definitions to include these new tools.
Chat Tools Implementation
packages/web/src/features/chat/tools.ts
Enhanced createCodeSearchTool input schema to support multiple filters; added new tools searchReposTool (fuzzy repo search) and listAllReposTool (list all repos) with input/output schemas and logic.
Search Query Utility and Tests
packages/web/src/features/chat/utils.ts, packages/web/src/features/chat/utils.test.ts
Added buildSearchQuery utility to construct complex search queries from multiple filters; added comprehensive unit tests covering various filter combinations and edge cases.
Error Message Enhancement
packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx
Improved error message rendering to show query error message if available before falling back to generic unknown error.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBox
    participant Agent
    participant Tools
    participant RepoService

    User->>ChatBox: Submit query (no repo selected)
    ChatBox->>Agent: Send query
    Agent->>Tools: Use searchReposTool/listAllReposTool
    Tools->>RepoService: Fetch and/or search repositories
    RepoService-->>Tools: Return repository list
    Tools-->>Agent: Provide repo info
    Agent-->>ChatBox: Respond with results
    ChatBox-->>User: Display results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

sourcebot-team

Poem

A bunny with code in its hat,
Hopped through the chat and improved it—just like that!
Now searching for repos is easy and bright,
With filters and tools, all queries take flight.
No scope selection woes, just hop and explore,
This rabbit’s new features will help you find more!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b06a00 and be2141f.

📒 Files selected for processing (1)
  • packages/web/src/features/chat/agent.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/features/chat/agent.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bkellam/improved_search_tool

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@brendan-kellam brendan-kellam force-pushed the bkellam/improved_search_tool branch from 3f0ff11 to 2e722e3 Compare July 29, 2025 06:48
@brendan-kellam brendan-kellam changed the title chore(ask_sb): Add additional capabilities to the search code tool feat(ask_sb): Add additional capabilities to the search code tool Jul 29, 2025
@brendan-kellam brendan-kellam changed the title feat(ask_sb): Add additional capabilities to the search code tool feat(ask_sb): Improved search tool ; tools for listing / searching repos ; removed search scope constraint Jul 29, 2025
@brendan-kellam brendan-kellam requested a review from msukkari July 29, 2025 08:21
@brendan-kellam brendan-kellam marked this pull request as ready for review July 29, 2025 08:24
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/web/src/features/chat/tools.ts (1)

172-172: Fix documentation inconsistency for limit default

The description says "default: 100" but the actual default is 10.

-        limit: z.number().default(10).describe("Maximum number of matches to return (default: 100)"),
+        limit: z.number().default(10).describe("Maximum number of matches to return (default: 10)"),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4343b3c and 0b06a00.

📒 Files selected for processing (16)
  • CHANGELOG.md (2 hunks)
  • packages/web/src/app/[domain]/chat/components/newChatPanel.tsx (0 hunks)
  • packages/web/src/app/[domain]/components/homepage/agenticSearch.tsx (0 hunks)
  • packages/web/src/features/chat/agent.ts (3 hunks)
  • packages/web/src/features/chat/components/chatBox/chatBox.tsx (4 hunks)
  • packages/web/src/features/chat/components/chatThread/chatThread.tsx (0 hunks)
  • packages/web/src/features/chat/components/chatThread/detailsCard.tsx (3 hunks)
  • packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx (1 hunks)
  • packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx (1 hunks)
  • packages/web/src/features/chat/components/chatThread/tools/searchCodeToolComponent.tsx (1 hunks)
  • packages/web/src/features/chat/components/chatThread/tools/searchReposToolComponent.tsx (1 hunks)
  • packages/web/src/features/chat/constants.ts (2 hunks)
  • packages/web/src/features/chat/tools.ts (3 hunks)
  • packages/web/src/features/chat/types.ts (2 hunks)
  • packages/web/src/features/chat/utils.test.ts (2 hunks)
  • packages/web/src/features/chat/utils.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/web/src/app/[domain]/chat/components/newChatPanel.tsx
  • packages/web/src/app/[domain]/components/homepage/agenticSearch.tsx
  • packages/web/src/features/chat/components/chatThread/chatThread.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*

📄 CodeRabbit Inference Engine (.cursor/rules/style.mdc)

Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

Files:

  • CHANGELOG.md
  • packages/web/src/features/chat/types.ts
  • packages/web/src/features/chat/constants.ts
  • packages/web/src/features/chat/components/chatThread/tools/searchCodeToolComponent.tsx
  • packages/web/src/features/chat/components/chatBox/chatBox.tsx
  • packages/web/src/features/chat/agent.ts
  • packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx
  • packages/web/src/features/chat/utils.ts
  • packages/web/src/features/chat/tools.ts
  • packages/web/src/features/chat/components/chatThread/detailsCard.tsx
  • packages/web/src/features/chat/components/chatThread/tools/searchReposToolComponent.tsx
  • packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx
  • packages/web/src/features/chat/utils.test.ts
🧬 Code Graph Analysis (7)
packages/web/src/features/chat/types.ts (2)
packages/web/src/features/chat/constants.ts (1)
  • toolNames (12-19)
packages/web/src/features/chat/tools.ts (2)
  • SearchReposTool (249-249)
  • ListAllReposTool (268-268)
packages/web/src/features/chat/components/chatThread/tools/searchCodeToolComponent.tsx (3)
packages/web/src/features/chat/tools.ts (1)
  • SearchCodeToolUIPart (215-215)
packages/web/src/features/chat/utils.ts (1)
  • buildSearchQuery (334-368)
packages/web/src/app/components/codeSnippet.tsx (1)
  • CodeSnippet (3-12)
packages/web/src/features/chat/agent.ts (2)
packages/web/src/features/chat/constants.ts (1)
  • toolNames (12-19)
packages/web/src/features/chat/tools.ts (2)
  • searchReposTool (217-247)
  • listAllReposTool (254-266)
packages/web/src/features/chat/tools.ts (3)
packages/web/src/features/chat/utils.ts (1)
  • buildSearchQuery (334-368)
packages/web/src/lib/constants.ts (1)
  • SINGLE_TENANT_ORG_DOMAIN (34-34)
packages/web/src/features/chat/constants.ts (1)
  • toolNames (12-19)
packages/web/src/features/chat/components/chatThread/detailsCard.tsx (2)
packages/web/src/features/chat/components/chatThread/tools/searchReposToolComponent.tsx (1)
  • SearchReposToolComponent (11-63)
packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx (1)
  • ListAllReposToolComponent (11-66)
packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx (2)
packages/web/src/features/chat/components/chatThread/tools/shared.tsx (2)
  • ToolHeader (90-133)
  • TreeList (41-78)
packages/web/src/app/components/codeSnippet.tsx (1)
  • CodeSnippet (3-12)
packages/web/src/features/chat/utils.test.ts (1)
packages/web/src/features/chat/utils.ts (1)
  • buildSearchQuery (334-368)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (34)
packages/web/src/features/chat/utils.ts (1)

334-368: LGTM! Well-structured query builder utility.

The buildSearchQuery function correctly constructs search queries by conditionally appending different filter types. The implementation properly handles:

  • Exact repository matching with reposet:
  • Grouped OR clauses for language, file, and repository regex filters
  • Proper array length validation before applying filters

The query construction logic is sound and the conditional checks prevent unnecessary filter application.

CHANGELOG.md (2)

16-16: LGTM! Clear changelog entry for new repository tools.

The entry accurately describes the addition of searchReposTool and listAllReposTool with proper PR reference.


25-26: LGTM! Comprehensive changelog entries for search improvements.

The entries clearly document:

  1. Enhanced search code tool with new filter options
  2. Removal of search scope constraint

Both changes are properly categorized and reference the correct PR.

packages/web/src/features/chat/types.ts (2)

6-6: LGTM! Properly imported new tool types.

The import statement correctly includes the new SearchReposTool and ListAllReposTool types.


86-87: LGTM! Consistent type mapping for new tools.

The new tool types are properly mapped using the correct tool names from constants, following the established pattern.

packages/web/src/features/chat/components/chatThread/referencedSourcesListView.tsx (1)

224-224: LGTM! Improved error message detail.

The enhanced error reporting now includes the query error message when available, providing better debugging information for failed file loads.

packages/web/src/features/chat/constants.ts (2)

17-18: LGTM! Consistent tool name additions.

The new tool names searchRepos and listAllRepos follow the established naming convention and are properly added to the constants.


29-30: LGTM! Proper UI visibility configuration.

The corresponding UI part types are correctly added to ensure the new tools are visible in the chat interface.

packages/web/src/features/chat/components/chatThread/tools/searchCodeToolComponent.tsx (3)

14-14: LGTM!

The import statement correctly references the buildSearchQuery utility function from the proper path.


20-33: LGTM!

The displayQuery memoization is well-implemented with proper state guards and correct parameter mapping to the buildSearchQuery utility. The dependency array is appropriate for the memoization.


41-45: LGTM!

The label computation correctly uses the new displayQuery for a more comprehensive search query display, and the dependency array is properly updated to include displayQuery.

packages/web/src/features/chat/components/chatThread/detailsCard.tsx (3)

15-16: LGTM!

The new tool component imports follow the established pattern and naming convention used by other tool components in the file.


68-68: LGTM!

The explicit length check prevents unnecessary tooltip rendering when no search scopes are selected, which aligns well with the removal of search scope constraints in this PR.


186-199: LGTM!

The new switch cases for repository tools follow the established pattern exactly, with proper React key props and correct component prop passing.

packages/web/src/features/chat/agent.ts (3)

9-9: LGTM!

The import statement correctly adds the new repository tools following the established import pattern.


57-63: LGTM!

Excellent conditional logic for adding repository discovery tools only when no search scopes are selected. The comment clearly explains the business reasoning, and the implementation uses clean object spread syntax with proper tool name constants.


195-195: LGTM!

The system prompt generalization makes the agent more flexible by referencing "available tools" instead of enumerating specific ones, while preserving essential instructions about tool usage and explanations.

packages/web/src/features/chat/components/chatBox/chatBox.tsx (4)

8-8: LGTM!

The import cleanup properly removes unused dependencies related to toast notifications and warning icons that are no longer needed after removing search scope constraints.

Also applies to: 11-11


100-102: LGTM!

The submit disabling logic correctly removes the "no-repos-selected" constraint while preserving all other validation reasons. The dependency array is properly updated to reflect the removed logic.

Also applies to: 141-141


145-145: LGTM!

The onSubmit callback is appropriately simplified by removing search scope validation and directly delegating to the provided callback function.


284-292: LGTM!

The submit button UI is appropriately simplified by removing the complex tooltip and warning logic while maintaining proper disabled state handling and visual styling.

packages/web/src/features/chat/components/chatThread/tools/listAllReposToolComponent.tsx (3)

1-10: LGTM!

The component imports and structure follow the established pattern used by other tool components, with proper TypeScript typing and all necessary dependencies.


11-24: LGTM!

The state management and label logic are properly implemented with appropriate React hooks usage and comprehensive state handling that covers all possible tool states with descriptive labels.


26-65: LGTM!

The rendering logic is excellently implemented following the established tool component pattern. It includes proper error handling, good empty state messaging, helpful repository count information, and consistent use of shared UI components with appropriate icons and text truncation.

packages/web/src/features/chat/utils.test.ts (2)

2-2: LGTM: Import statement correctly updated

The import statement properly includes the new buildSearchQuery function that's being tested.


355-514: Excellent comprehensive test coverage for buildSearchQuery

The test suite is well-structured and covers all the essential scenarios:

  • Base functionality without filters
  • Individual filter types and their expected output formats
  • Empty filter handling (correctly ignored)
  • Complex combinations of multiple filters
  • Edge cases including empty queries and special characters

The test assertions match the expected behavior described in the relevant code snippet from utils.ts (lines 333-367). The tests verify proper filter formatting:

  • repoNamesFilter uses comma-separated format: reposet:repo1,repo2
  • languageNamesFilter uses OR format: ( lang:typescript or lang:javascript )
  • fileNamesFilterRegexp uses OR format: ( file:*.ts or file:*.js )
  • repoNamesFilterRegexp uses OR format: ( repo:org/repo1 or repo:org/repo2 )
packages/web/src/features/chat/components/chatThread/tools/searchReposToolComponent.tsx (3)

1-10: LGTM: Clean imports and component setup

The component follows established patterns with proper imports from the chat features, utilities, and UI components. The use of 'use client' directive is appropriate for this interactive component.


11-24: Well-implemented state management and dynamic labeling

The component properly manages the isExpanded state and uses a memoized label that dynamically updates based on the tool's execution state. The label implementation correctly handles all possible states:

  • Shows "Searching repositories..." during streaming
  • Shows error message for failed calls
  • Shows the search query with proper formatting for successful states

The use of CodeSnippet with truncation for displaying the query is consistent with other tool components.


26-62: Excellent implementation following established UI patterns

The component structure is consistent with other tool components in the codebase:

  • Uses the shared ToolHeader component with proper loading/error state handling
  • Implements conditional rendering based on tool state and expansion
  • Proper error handling using isServiceError utility
  • Clean result display with TreeList for consistent styling
  • Appropriate use of icons (BookMarkedIcon) and styling classes
  • Handles empty results with a user-friendly message

The component correctly handles the service error case and displays repository results in a readable format with consistent spacing and typography.

packages/web/src/features/chat/tools.ts (5)

9-12: LGTM: Appropriate new imports for enhanced functionality

The new imports are properly added:

  • buildSearchQuery utility for constructing complex search queries
  • getRepos action for fetching repository data
  • Fuse library for fuzzy search functionality

All imports align with the enhanced tool capabilities.


140-185: Excellent enhancement of code search tool with comprehensive filtering

The enhanced createCodeSearchTool properly implements multiple filtering capabilities:

Input Schema Improvements:

  • Renamed query to queryRegexp with detailed regex usage documentation
  • Added optional filters for repo names (regex), languages, and file names (regex)
  • Proper Zod validation with descriptive documentation
  • Sensible default limit of 10 (though line 172 says default 100 - minor documentation inconsistency)

Implementation:

  • Correctly uses the buildSearchQuery utility to construct the final query
  • Properly handles the selectedRepos parameter alongside new filters
  • Uses the limit parameter instead of hardcoded 100

The tool now provides much more granular control over search scope while maintaining backward compatibility.


217-247: Well-implemented fuzzy search repository tool

The searchReposTool implementation is solid:

Strengths:

  • Clear description and input schema with appropriate defaults
  • Proper error handling for service errors from getRepos
  • Good Fuse.js configuration with weighted keys for fuzzy searching
  • Reasonable threshold (0.4) for matching strictness
  • Results are properly sorted by score (lower score = better match)
  • Returns only repository names for clean output

Configuration Details:

  • Weights favor repoName (0.7) over repoDisplayName (0.3) which makes sense
  • Threshold of 0.4 provides good balance between strict and fuzzy matching
  • Minimum match character length of 1 allows single-character searches

254-266: Simple and effective repository listing tool

The listAllReposTool provides a straightforward way to discover all available repositories:

  • Clean implementation with no input parameters needed
  • Proper error handling matching the pattern used in other tools
  • Returns simple array of repository names for easy consumption
  • Good complement to the search tool for repository discovery

212-271: Excellent type definitions following established patterns

All the new and updated tools have comprehensive type definitions:

  • SearchCodeTool, SearchReposTool, and ListAllReposTool with proper inference
  • Input/Output types for each tool
  • UI part types that integrate with the chat system
  • Consistent naming convention matching the toolNames constants

The type system ensures type safety throughout the chat tool ecosystem.

msukkari
msukkari previously approved these changes Jul 29, 2025
@msukkari msukkari merged commit 211ad8f into main Jul 29, 2025
6 checks passed
@msukkari msukkari deleted the bkellam/improved_search_tool branch July 29, 2025 17:43
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.

2 participants