mirror of
https://github.com/sst/opencode.git
synced 2025-08-11 16:58:08 +00:00
permissions disallow support (#1627)
Some checks are pending
deploy / deploy (push) Waiting to run
Some checks are pending
deploy / deploy (push) Waiting to run
This commit is contained in:
parent
6b25b7e95e
commit
a48274f82b
4 changed files with 29 additions and 14 deletions
|
@ -224,7 +224,7 @@ export namespace Config {
|
||||||
})
|
})
|
||||||
export type Layout = z.infer<typeof Layout>
|
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 type Permission = z.infer<typeof Permission>
|
||||||
|
|
||||||
export const Info = z
|
export const Info = z
|
||||||
|
|
|
@ -728,7 +728,7 @@ export namespace Session {
|
||||||
|
|
||||||
const enabledTools = pipe(
|
const enabledTools = pipe(
|
||||||
mode.tools,
|
mode.tools,
|
||||||
mergeDeep(ToolRegistry.enabled(input.providerID, input.modelID)),
|
mergeDeep(await ToolRegistry.enabled(input.providerID, input.modelID)),
|
||||||
mergeDeep(input.tools ?? {}),
|
mergeDeep(input.tools ?? {}),
|
||||||
)
|
)
|
||||||
for (const item of await ToolRegistry.tools(input.providerID, input.modelID)) {
|
for (const item of await ToolRegistry.tools(input.providerID, input.modelID)) {
|
||||||
|
|
|
@ -93,7 +93,7 @@ export const BashTool = Tool.define("bash", {
|
||||||
|
|
||||||
// always allow cd if it passes above check
|
// always allow cd if it passes above check
|
||||||
if (!needsAsk && command[0] !== "cd") {
|
if (!needsAsk && command[0] !== "cd") {
|
||||||
const ask = (() => {
|
const action = (() => {
|
||||||
for (const [pattern, value] of Object.entries(permissions)) {
|
for (const [pattern, value] of Object.entries(permissions)) {
|
||||||
const match = Wildcard.match(node.text, pattern)
|
const match = Wildcard.match(node.text, pattern)
|
||||||
log.info("checking", { text: node.text.trim(), pattern, match })
|
log.info("checking", { text: node.text.trim(), pattern, match })
|
||||||
|
@ -101,7 +101,12 @@ export const BashTool = Tool.define("bash", {
|
||||||
}
|
}
|
||||||
return "ask"
|
return "ask"
|
||||||
})()
|
})()
|
||||||
if (ask === "ask") needsAsk = true
|
if (action === "deny") {
|
||||||
|
throw new Error(
|
||||||
|
"The user has specifically restricted access to this command, you are not allowed to execute it.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (action === "ask") needsAsk = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { TodoWriteTool, TodoReadTool } from "./todo"
|
||||||
import { WebFetchTool } from "./webfetch"
|
import { WebFetchTool } from "./webfetch"
|
||||||
import { WriteTool } from "./write"
|
import { WriteTool } from "./write"
|
||||||
import { InvalidTool } from "./invalid"
|
import { InvalidTool } from "./invalid"
|
||||||
|
import { Config } from "../config/config"
|
||||||
|
|
||||||
export namespace ToolRegistry {
|
export namespace ToolRegistry {
|
||||||
const ALL = [
|
const ALL = [
|
||||||
|
@ -65,11 +66,19 @@ export namespace ToolRegistry {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function enabled(_providerID: string, modelID: string): Record<string, boolean> {
|
export async function enabled(_providerID: string, modelID: string): Promise<Record<string, boolean>> {
|
||||||
|
const cfg = await Config.get()
|
||||||
|
const result: Record<string, boolean> = {}
|
||||||
|
|
||||||
|
if (cfg.permission?.edit === "deny") {
|
||||||
|
result["edit"] = false
|
||||||
|
result["patch"] = false
|
||||||
|
result["write"] = false
|
||||||
|
}
|
||||||
|
|
||||||
if (modelID.toLowerCase().includes("claude")) {
|
if (modelID.toLowerCase().includes("claude")) {
|
||||||
return {
|
result["patch"] = false
|
||||||
patch: false,
|
return result
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -79,13 +88,14 @@ export namespace ToolRegistry {
|
||||||
modelID.includes("o3") ||
|
modelID.includes("o3") ||
|
||||||
modelID.includes("codex")
|
modelID.includes("codex")
|
||||||
) {
|
) {
|
||||||
return {
|
result["patch"] = false
|
||||||
patch: false,
|
result["todowrite"] = false
|
||||||
todowrite: false,
|
result["todoread"] = false
|
||||||
todoread: false,
|
|
||||||
}
|
return result
|
||||||
}
|
}
|
||||||
return {}
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeGeminiParameters(schema: z.ZodTypeAny, visited = new Set()): z.ZodTypeAny {
|
function sanitizeGeminiParameters(schema: z.ZodTypeAny, visited = new Set()): z.ZodTypeAny {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue