@sureshsankaran/opencode-destructive-check 1.0.2 → 1.0.3
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 +18 -8
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.3",
|
|
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
|
@@ -308,22 +308,31 @@ const destructiveCheck: Plugin = async () => {
|
|
|
308
308
|
async ["permission.ask"](
|
|
309
309
|
input: {
|
|
310
310
|
id: string
|
|
311
|
-
type
|
|
311
|
+
// Old permission system uses 'type', new system uses 'permission'
|
|
312
|
+
type?: string
|
|
313
|
+
permission?: string
|
|
312
314
|
pattern?: string | string[]
|
|
315
|
+
patterns?: string[]
|
|
313
316
|
sessionID: string
|
|
314
|
-
messageID
|
|
317
|
+
messageID?: string
|
|
315
318
|
callID?: string
|
|
316
|
-
title
|
|
319
|
+
title?: string
|
|
317
320
|
metadata: Record<string, unknown>
|
|
318
|
-
time
|
|
321
|
+
time?: { created: number }
|
|
319
322
|
},
|
|
320
323
|
output: { status: "ask" | "deny" | "allow" },
|
|
321
324
|
): Promise<void> {
|
|
322
325
|
const stats = getStats(input.sessionID)
|
|
323
326
|
|
|
327
|
+
// Get permission type from either old or new system
|
|
328
|
+
const permissionType = input.permission || input.type || ""
|
|
329
|
+
|
|
324
330
|
// Check if this is a bash/command execution permission
|
|
325
|
-
if (
|
|
326
|
-
|
|
331
|
+
if (permissionType === "bash" || permissionType === "command" || permissionType === "shell") {
|
|
332
|
+
// Get command from patterns (new system) or metadata/title (old system)
|
|
333
|
+
const patterns =
|
|
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 || ""
|
|
327
336
|
|
|
328
337
|
if (command) {
|
|
329
338
|
const match = checkCommand(command)
|
|
@@ -347,8 +356,9 @@ const destructiveCheck: Plugin = async () => {
|
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
// Check file operations
|
|
350
|
-
if (
|
|
351
|
-
const patterns =
|
|
359
|
+
if (permissionType === "write" || permissionType === "edit" || permissionType === "delete") {
|
|
360
|
+
const patterns =
|
|
361
|
+
input.patterns || (Array.isArray(input.pattern) ? input.pattern : input.pattern ? [input.pattern] : [])
|
|
352
362
|
for (const p of patterns) {
|
|
353
363
|
if (isDangerousPath(p)) {
|
|
354
364
|
stats.permissionsRequested++
|