add permission system

This commit is contained in:
Dax Raad
2025-06-02 19:51:26 -04:00
parent 863e7a093e
commit 786db364d2
4 changed files with 158 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import { Tool } from "./tool"
import { FileTimes } from "./util/file-times"
import { LSP } from "../lsp"
import { diffLines } from "diff"
import { Permission } from "../permission"
const DESCRIPTION = `Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the Bash tool with the 'mv' command instead. For larger file edits, use the FileWrite tool to overwrite files.
@@ -61,7 +62,7 @@ export const EditTool = Tool.define({
oldString: z.string().describe("The text to replace"),
newString: z.string().describe("The text to replace it with"),
}),
async execute(params) {
async execute(params, ctx) {
if (!params.filePath) {
throw new Error("filePath is required")
}
@@ -71,6 +72,17 @@ export const EditTool = Tool.define({
filePath = path.join(process.cwd(), filePath)
}
await Permission.ask({
id: "opencode.edit",
sessionID: ctx.sessionID,
title: "Edit this file: " + filePath,
metadata: {
filePath,
oldString: params.oldString,
newString: params.newString,
},
})
let contentOld = ""
let contentNew = ""
await (async () => {

View File

@@ -1,6 +1,9 @@
import type { StandardSchemaV1 } from "@standard-schema/spec"
export namespace Tool {
export type Context = {
sessionID: string
}
export interface Info<
Parameters extends StandardSchemaV1 = StandardSchemaV1,
Metadata extends Record<string, any> = Record<string, any>,
@@ -8,7 +11,10 @@ export namespace Tool {
id: string
description: string
parameters: Parameters
execute(args: StandardSchemaV1.InferOutput<Parameters>): Promise<{
execute(
args: StandardSchemaV1.InferOutput<Parameters>,
ctx: Context,
): Promise<{
metadata: Metadata
output: string
}>