-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Skip interpolation for non-existent slash commands #6475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ import { UrlContentFetcher } from "../../services/browser/UrlContentFetcher" | |
| import { FileContextTracker } from "../context-tracking/FileContextTracker" | ||
|
|
||
| import { RooIgnoreController } from "../ignore/RooIgnoreController" | ||
| import { getCommand } from "../../services/command/commands" | ||
| import { getCommand, type Command } from "../../services/command/commands" | ||
|
|
||
| import { t } from "../../i18n" | ||
|
|
||
|
|
@@ -86,13 +86,38 @@ export async function parseMentions( | |
| maxReadFileLine?: number, | ||
| ): Promise<string> { | ||
| const mentions: Set<string> = new Set() | ||
| const commandMentions: Set<string> = new Set() | ||
| const validCommands: Map<string, Command> = new Map() | ||
|
|
||
| // First pass: extract command mentions (starting with /) | ||
| let parsedText = text.replace(commandRegexGlobal, (match, commandName) => { | ||
| commandMentions.add(commandName) | ||
| return `Command '${commandName}' (see below for command content)` | ||
| }) | ||
| // First pass: check which command mentions exist and cache the results | ||
| const commandMatches = Array.from(text.matchAll(commandRegexGlobal)) | ||
| const uniqueCommandNames = new Set(commandMatches.map(([, commandName]) => commandName)) | ||
|
|
||
| const commandExistenceChecks = await Promise.all( | ||
| Array.from(uniqueCommandNames).map(async (commandName) => { | ||
| try { | ||
| const command = await getCommand(cwd, commandName) | ||
mrubens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return { commandName, command } | ||
| } catch (error) { | ||
| // If there's an error checking command existence, treat it as non-existent | ||
| return { commandName, command: undefined } | ||
| } | ||
| }), | ||
| ) | ||
|
|
||
| // Store valid commands for later use | ||
| for (const { commandName, command } of commandExistenceChecks) { | ||
| if (command) { | ||
| validCommands.set(commandName, command) | ||
| } | ||
| } | ||
|
|
||
| // Only replace text for commands that actually exist | ||
| let parsedText = text | ||
| for (const [match, commandName] of commandMatches) { | ||
| if (validCommands.has(commandName)) { | ||
| parsedText = parsedText.replace(match, `Command '${commandName}' (see below for command content)`) | ||
| } | ||
| } | ||
|
|
||
| // Second pass: handle regular mentions | ||
| parsedText = parsedText.replace(mentionRegexGlobal, (match, mention) => { | ||
|
|
@@ -213,20 +238,15 @@ export async function parseMentions( | |
| } | ||
| } | ||
|
|
||
| // Process command mentions | ||
| for (const commandName of commandMentions) { | ||
| // Process valid command mentions using cached results | ||
| for (const [commandName, command] of validCommands) { | ||
| try { | ||
| const command = await getCommand(cwd, commandName) | ||
| if (command) { | ||
| let commandOutput = "" | ||
| if (command.description) { | ||
| commandOutput += `Description: ${command.description}\n\n` | ||
| } | ||
| commandOutput += command.content | ||
| parsedText += `\n\n<command name="${commandName}">\n${commandOutput}\n</command>` | ||
| } else { | ||
| parsedText += `\n\n<command name="${commandName}">\nCommand '${commandName}' not found. Available commands can be found in .roo/commands/ or ~/.roo/commands/\n</command>` | ||
| let commandOutput = "" | ||
| if (command.description) { | ||
| commandOutput += `Description: ${command.description}\n\n` | ||
| } | ||
| commandOutput += command.content | ||
| parsedText += `\n\n<command name="${commandName}">\n${commandOutput}\n</command>` | ||
| } catch (error) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error handling inconsistency: If getCommand() fails here after passing the existence check, we show an error message. This creates a scenario where a 'verified existing' command can still fail. Is this the intended behavior? |
||
| parsedText += `\n\n<command name="${commandName}">\nError loading command '${commandName}': ${error.message}\n</command>` | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.