feat: OpenCode v1.1.1 permission system compatibility (#489)
* feat: add OpenCode v1.1.1 version detection and permission compatibility utilities - Add opencode-version.ts: Detect installed OpenCode version and support API - Add permission-compat.ts: Compatibility layer for permission system migration - Add comprehensive tests (418 lines total) - Export new utilities from shared/index.ts 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode) * fix: update agent permission configs for OpenCode v1.1.1 compatibility - Fix document-writer: change invalid 'permission: { background_task: deny }' to 'tools: { background_task: false }' - Fix explore: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Fix oracle: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Align all agents with v1.1.1 permission system structure 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { supportsNewPermissionSystem as checkNewPermissionSystem } from "./opencode-version"
|
||||
|
||||
export type PermissionValue = "ask" | "allow" | "deny"
|
||||
export type BashPermission = PermissionValue | Record<string, PermissionValue>
|
||||
|
||||
export interface StandardPermission {
|
||||
edit?: PermissionValue
|
||||
bash?: BashPermission
|
||||
webfetch?: PermissionValue
|
||||
doom_loop?: PermissionValue
|
||||
external_directory?: PermissionValue
|
||||
}
|
||||
|
||||
export interface ToolsConfig {
|
||||
[toolName: string]: boolean
|
||||
}
|
||||
|
||||
export interface AgentPermissionConfig {
|
||||
permission?: StandardPermission
|
||||
tools?: ToolsConfig
|
||||
}
|
||||
|
||||
export { checkNewPermissionSystem as supportsNewPermissionSystemFromCompat }
|
||||
|
||||
export function createToolDenyList(toolNames: string[]): ToolsConfig {
|
||||
return Object.fromEntries(toolNames.map((name) => [name, false]))
|
||||
}
|
||||
|
||||
export function permissionValueToBoolean(value: PermissionValue): boolean {
|
||||
return value === "allow"
|
||||
}
|
||||
|
||||
export function booleanToPermissionValue(value: boolean): PermissionValue {
|
||||
return value ? "allow" : "deny"
|
||||
}
|
||||
|
||||
export function convertToolsToPermission(
|
||||
tools: ToolsConfig
|
||||
): Record<string, PermissionValue> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(tools).map(([key, value]) => [
|
||||
key,
|
||||
booleanToPermissionValue(value),
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
export function convertPermissionToTools(
|
||||
permission: Record<string, PermissionValue>
|
||||
): ToolsConfig {
|
||||
return Object.fromEntries(
|
||||
Object.entries(permission)
|
||||
.filter(([, value]) => value !== "ask")
|
||||
.map(([key, value]) => [key, permissionValueToBoolean(value)])
|
||||
)
|
||||
}
|
||||
|
||||
export function createAgentRestrictions(config: {
|
||||
denyTools?: string[]
|
||||
permission?: StandardPermission
|
||||
}): AgentPermissionConfig {
|
||||
const result: AgentPermissionConfig = {}
|
||||
|
||||
if (config.denyTools && config.denyTools.length > 0) {
|
||||
result.tools = createToolDenyList(config.denyTools)
|
||||
}
|
||||
|
||||
if (config.permission) {
|
||||
result.permission = config.permission
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user