@sureshsankaran/opencode-destructive-check 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +25 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sureshsankaran/opencode-destructive-check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "OpenCode plugin that checks for destructive commands before any tool/bash call and asks for permission",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/src/index.ts
CHANGED
|
@@ -329,12 +329,34 @@ const destructiveCheck: Plugin = async () => {
|
|
|
329
329
|
|
|
330
330
|
// Check if this is a bash/command execution permission
|
|
331
331
|
if (permissionType === "bash" || permissionType === "command" || permissionType === "shell") {
|
|
332
|
-
// Get
|
|
332
|
+
// Get commands from patterns (new system) or metadata/title (old system)
|
|
333
333
|
const patterns =
|
|
334
334
|
input.patterns || (Array.isArray(input.pattern) ? input.pattern : input.pattern ? [input.pattern] : [])
|
|
335
|
-
const command = patterns.join(" ") || (input.metadata?.command as string) || input.title || ""
|
|
336
335
|
|
|
337
|
-
|
|
336
|
+
// Check each pattern individually for destructive commands
|
|
337
|
+
for (const pattern of patterns) {
|
|
338
|
+
const match = checkCommand(pattern)
|
|
339
|
+
if (match) {
|
|
340
|
+
stats.permissionsRequested++
|
|
341
|
+
globalStats.permissionsRequested++
|
|
342
|
+
stats.lastMatch = match
|
|
343
|
+
|
|
344
|
+
console.warn(
|
|
345
|
+
`[destructive-check] PERMISSION REQUIRED: ${match.severity.toUpperCase()} destructive command detected`,
|
|
346
|
+
)
|
|
347
|
+
console.warn(` Category: ${match.category}`)
|
|
348
|
+
console.warn(` Severity: ${match.severity}`)
|
|
349
|
+
console.warn(` Command: ${pattern.slice(0, 100)}${pattern.length > 100 ? "..." : ""}`)
|
|
350
|
+
|
|
351
|
+
// Ask for permission for all severity levels
|
|
352
|
+
output.status = "ask"
|
|
353
|
+
return
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Also check joined patterns and metadata as fallback
|
|
358
|
+
const command = patterns.join(" ") || (input.metadata?.command as string) || input.title || ""
|
|
359
|
+
if (command && patterns.length === 0) {
|
|
338
360
|
const match = checkCommand(command)
|
|
339
361
|
if (match) {
|
|
340
362
|
stats.permissionsRequested++
|