Skip to content

Commit 63f4a27

Browse files
committed
fix: remove hardcoded npm pattern suggestions
- Remove automatic addition of generic 'npm' and 'npm run' patterns - Remove unused translation keys for hardcoded npm suggestions - Let LLM suggestions be the sole source of command patterns - Improves security by avoiding overly broad permission patterns - Fix React hooks linting warning
1 parent 38fb80f commit 63f4a27

File tree

2 files changed

+11
-67
lines changed

2 files changed

+11
-67
lines changed

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

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,13 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
110110
// Found an operator, process the current command
111111
const trimmedCommand = currentCommand.trim()
112112
if (trimmedCommand) {
113-
// For npm commands, generate multiple pattern options
114-
if (trimmedCommand.startsWith("npm ")) {
115-
// Add the specific pattern
116-
const specificPattern = extractCommandPattern(trimmedCommand)
117-
if (specificPattern) {
118-
patterns.push({
119-
pattern: specificPattern,
120-
description: getPatternDescription(specificPattern),
121-
})
122-
}
123-
124-
// Add broader npm patterns
125-
if (trimmedCommand.startsWith("npm run ")) {
126-
// Add "npm run" pattern
127-
patterns.push({
128-
pattern: "npm run",
129-
description: t("chat:commandExecution.allowAllNpmRun"),
130-
})
131-
}
132-
133-
// Add "npm" pattern
113+
// Extract pattern for the command
114+
const pattern = extractCommandPattern(trimmedCommand)
115+
if (pattern) {
134116
patterns.push({
135-
pattern: "npm",
136-
description: t("chat:commandExecution.allowAllNpm"),
117+
pattern,
118+
description: getPatternDescription(pattern),
137119
})
138-
} else {
139-
// For non-npm commands, just add the extracted pattern
140-
const pattern = extractCommandPattern(trimmedCommand)
141-
if (pattern) {
142-
patterns.push({
143-
pattern,
144-
description: getPatternDescription(pattern),
145-
})
146-
}
147120
}
148121
}
149122
currentCommand = ""
@@ -162,40 +135,13 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
162135
// Process the last command
163136
const trimmedCommand = currentCommand.trim()
164137
if (trimmedCommand) {
165-
// For npm commands, generate multiple pattern options
166-
if (trimmedCommand.startsWith("npm ")) {
167-
// Add the specific pattern
168-
const specificPattern = extractCommandPattern(trimmedCommand)
169-
if (specificPattern) {
170-
patterns.push({
171-
pattern: specificPattern,
172-
description: getPatternDescription(specificPattern),
173-
})
174-
}
175-
176-
// Add broader npm patterns
177-
if (trimmedCommand.startsWith("npm run ")) {
178-
// Add "npm run" pattern
179-
patterns.push({
180-
pattern: "npm run",
181-
description: t("chat:commandExecution.allowAllNpmRun"),
182-
})
183-
}
184-
185-
// Add "npm" pattern
138+
// Extract pattern for the command
139+
const pattern = extractCommandPattern(trimmedCommand)
140+
if (pattern) {
186141
patterns.push({
187-
pattern: "npm",
188-
description: t("chat:commandExecution.allowAllNpm"),
142+
pattern,
143+
description: getPatternDescription(pattern),
189144
})
190-
} else {
191-
// For non-npm commands, just add the extracted pattern
192-
const pattern = extractCommandPattern(trimmedCommand)
193-
if (pattern) {
194-
patterns.push({
195-
pattern,
196-
description: getPatternDescription(pattern),
197-
})
198-
}
199145
}
200146
}
201147

@@ -205,7 +151,7 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
205151
)
206152

207153
return uniquePatterns
208-
}, [command, suggestions, showSuggestions, t])
154+
}, [command, suggestions, showSuggestions])
209155

210156
// The command's output can either come from the text associated with the
211157
// task message (this is the case for completed commands) or from the

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@
212212
"pid": "PID: {{pid}}",
213213
"exited": "Exited ({{exitCode}})",
214214
"addToAllowedCommands": "Add to Allowed Auto-Execute Commands",
215-
"allowAllNpmRun": "Allow all npm run commands",
216-
"allowAllNpm": "Allow all npm commands",
217215
"manageCommands": "Manage Command Permissions",
218216
"commandManagementDescription": "Click ✓ to allow auto-execution, ✗ to deny execution"
219217
},

0 commit comments

Comments
 (0)