Skip to content

Commit 8362771

Browse files
committed
fix: ensure unique command patterns and trim whitespace in command extraction
1 parent c4f5c5f commit 8362771

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

webview-ui/src/components/chat/CommandPatternSelector.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ export const CommandPatternSelector: React.FC<CommandPatternSelectorProps> = ({
3434
// Create a combined list with full command first, then patterns
3535
const allPatterns = useMemo(() => {
3636
const fullCommandPattern: CommandPattern = { pattern: command }
37-
return [fullCommandPattern, ...patterns]
37+
38+
// Create a set to track unique patterns we've already seen
39+
const seenPatterns = new Set<string>()
40+
seenPatterns.add(command) // Add the full command first
41+
42+
// Filter out any patterns that are duplicates or are the same as the full command
43+
const uniquePatterns = patterns.filter((p) => {
44+
if (seenPatterns.has(p.pattern)) {
45+
return false
46+
}
47+
seenPatterns.add(p.pattern)
48+
return true
49+
})
50+
51+
return [fullCommandPattern, ...uniquePatterns]
3852
}, [command, patterns])
3953

4054
const getPatternStatus = (pattern: string): "allowed" | "denied" | "none" => {

webview-ui/src/utils/command-parser.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,11 @@ function extractFromTokens(tokens: string[], patterns: Set<string>): void {
5151

5252
// Build patterns progressively up to 3 levels
5353
let pattern = mainCmd
54-
patterns.add(pattern)
54+
patterns.add(pattern.trim())
5555

5656
for (let i = 1; i < Math.min(tokens.length, 3); i++) {
5757
const token = tokens[i]
58-
59-
// Stop at flags (starting with -)
60-
if (token.startsWith("-")) break
61-
62-
// Stop at paths (starting with / or ~)
63-
if (token.startsWith("/") || token.startsWith("~")) break
64-
65-
// Stop at file extensions
66-
if (token.includes(".") && /\.\w+$/.test(token)) break
67-
68-
// Stop at colons (like image:tag)
69-
if (token.includes(":")) break
70-
71-
// Stop at dots (like . for current directory)
72-
if (token === ".") break
73-
7458
pattern += ` ${token}`
75-
patterns.add(pattern)
59+
patterns.add(pattern.trim()) // Ensure no trailing whitespace
7660
}
7761
}

0 commit comments

Comments
 (0)