-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,13 +86,30 @@ export async function parseMentions( | |
| maxReadFileLine?: number, | ||
| ): Promise<string> { | ||
| const mentions: Set<string> = new Set() | ||
| const commandMentions: Set<string> = new Set() | ||
| const validCommandMentions: Set<string> = new Set() | ||
|
||
|
|
||
| // 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 before replacing text | ||
| const commandMatches = Array.from(text.matchAll(commandRegexGlobal)) | ||
| const commandExistenceChecks = await Promise.all( | ||
| commandMatches.map(async ([match, commandName]) => { | ||
| try { | ||
| const command = await getCommand(cwd, commandName) | ||
mrubens marked this conversation as resolved.
Show resolved
Hide resolved
mrubens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return { match, commandName, exists: !!command } | ||
|
||
| } catch (error) { | ||
| // If there's an error checking command existence, treat it as non-existent | ||
| return { match, commandName, exists: false } | ||
| } | ||
| }), | ||
| ) | ||
|
|
||
| // Only replace text for commands that actually exist | ||
| let parsedText = text | ||
| for (const { match, commandName, exists } of commandExistenceChecks) { | ||
| if (exists) { | ||
| validCommandMentions.add(commandName) | ||
| parsedText = parsedText.replace(match, `Command '${commandName}' (see below for command content)`) | ||
| } | ||
| } | ||
|
|
||
| // Second pass: handle regular mentions | ||
| parsedText = parsedText.replace(mentionRegexGlobal, (match, mention) => { | ||
|
|
@@ -213,8 +230,8 @@ export async function parseMentions( | |
| } | ||
| } | ||
|
|
||
| // Process command mentions | ||
| for (const commandName of commandMentions) { | ||
| // Process valid command mentions only | ||
| for (const commandName of validCommandMentions) { | ||
| try { | ||
| const command = await getCommand(cwd, commandName) | ||
|
||
| if (command) { | ||
|
|
@@ -224,9 +241,9 @@ export async function parseMentions( | |
| } | ||
| 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>` | ||
| } | ||
| // Note: We don't add error messages for non-existent commands anymore | ||
|
||
| // since we only process commands that we've already verified exist | ||
mrubens marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } 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>` | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test efficiency: The mock is being called 4 times for the same commands, which reflects the duplicate API calls in the production code. This suggests the performance issue mentioned in the main implementation.