mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: ensure unique command patterns and trim whitespace in command extraction
This commit is contained in:
parent
c4f5c5f97f
commit
83627716b4
2 changed files with 17 additions and 19 deletions
|
|
@ -34,7 +34,21 @@ export const CommandPatternSelector: React.FC<CommandPatternSelectorProps> = ({
|
|||
// Create a combined list with full command first, then patterns
|
||||
const allPatterns = useMemo(() => {
|
||||
const fullCommandPattern: CommandPattern = { pattern: command }
|
||||
return [fullCommandPattern, ...patterns]
|
||||
|
||||
// Create a set to track unique patterns we've already seen
|
||||
const seenPatterns = new Set<string>()
|
||||
seenPatterns.add(command) // Add the full command first
|
||||
|
||||
// Filter out any patterns that are duplicates or are the same as the full command
|
||||
const uniquePatterns = patterns.filter((p) => {
|
||||
if (seenPatterns.has(p.pattern)) {
|
||||
return false
|
||||
}
|
||||
seenPatterns.add(p.pattern)
|
||||
return true
|
||||
})
|
||||
|
||||
return [fullCommandPattern, ...uniquePatterns]
|
||||
}, [command, patterns])
|
||||
|
||||
const getPatternStatus = (pattern: string): "allowed" | "denied" | "none" => {
|
||||
|
|
|
|||
|
|
@ -51,27 +51,11 @@ function extractFromTokens(tokens: string[], patterns: Set<string>): void {
|
|||
|
||||
// Build patterns progressively up to 3 levels
|
||||
let pattern = mainCmd
|
||||
patterns.add(pattern)
|
||||
patterns.add(pattern.trim())
|
||||
|
||||
for (let i = 1; i < Math.min(tokens.length, 3); i++) {
|
||||
const token = tokens[i]
|
||||
|
||||
// Stop at flags (starting with -)
|
||||
if (token.startsWith("-")) break
|
||||
|
||||
// Stop at paths (starting with / or ~)
|
||||
if (token.startsWith("/") || token.startsWith("~")) break
|
||||
|
||||
// Stop at file extensions
|
||||
if (token.includes(".") && /\.\w+$/.test(token)) break
|
||||
|
||||
// Stop at colons (like image:tag)
|
||||
if (token.includes(":")) break
|
||||
|
||||
// Stop at dots (like . for current directory)
|
||||
if (token === ".") break
|
||||
|
||||
pattern += ` ${token}`
|
||||
patterns.add(pattern)
|
||||
patterns.add(pattern.trim()) // Ensure no trailing whitespace
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue