mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 15:13:46 +00:00
add permission system
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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
|
||||
}>
|
||||
|
||||
Reference in New Issue
Block a user