Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export namespace Config {
})
export type Layout = z.infer<typeof Layout>

export const Permission = z.union([z.literal("ask"), z.literal("allow")])
export const Permission = z.union([z.literal("ask"), z.literal("allow"), z.literal("deny")])
export type Permission = z.infer<typeof Permission>

export const Info = z
Expand Down
7 changes: 5 additions & 2 deletions packages/opencode/src/tool/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ export const BashTool = Tool.define("bash", {

// always allow cd if it passes above check
if (!needsAsk && command[0] !== "cd") {
const ask = (() => {
const action = (() => {
for (const [pattern, value] of Object.entries(permissions)) {
const match = Wildcard.match(node.text, pattern)
log.info("checking", { text: node.text.trim(), pattern, match })
if (match) return value
}
return "ask"
})()
if (ask === "ask") needsAsk = true
if (action === "ask") needsAsk = true
if (action === "deny") {
throw new Error(`Command "${node.text.trim()}" is not allowed by permission configuration`)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/tool/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const EditTool = Tool.define("edit", {
diff,
},
})
} else if (cfg.permission?.edit === "deny") {
throw new Error(`File editing is not allowed by permission configuration`)
}
await Bun.write(filePath, params.newString)
await Bus.publish(File.Event.Edited, {
Expand Down Expand Up @@ -89,6 +91,8 @@ export const EditTool = Tool.define("edit", {
diff,
},
})
} else if (cfg.permission?.edit === "deny") {
throw new Error(`File editing is not allowed by permission configuration`)
}

await file.write(contentNew)
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/tool/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const WriteTool = Tool.define("write", {
exists,
},
})
else if (cfg.permission?.edit === "deny") {
throw new Error(`File writing is not allowed by permission configuration`)
}

await Bun.write(filepath, params.content)
await Bus.publish(File.Event.Edited, {
Expand Down
Loading