Skip to content
Open
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
16 changes: 15 additions & 1 deletion packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CodeSearchTool } from "./codesearch"
import { Flag } from "@/flag/flag"
import { Log } from "@/util/log"
import { LspTool } from "./lsp"
import { Permission } from "../permission"

export namespace ToolRegistry {
const log = Log.create({ service: "tool.registry" })
Expand Down Expand Up @@ -64,7 +65,20 @@ export namespace ToolRegistry {
parameters: z.object(def.args),
description: def.description,
execute: async (args, ctx) => {
const result = await def.execute(args as any, ctx)
const result = await def.execute(args as any, {
...ctx,
askPermission: async (input) => {
await Permission.ask({
type: input.type,
title: input.title,
pattern: input.pattern,
sessionID: ctx.sessionID,
messageID: ctx.messageID,
callID: ctx.callID,
metadata: input.metadata,
})
},
})
return {
title: "",
output: result,
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ export type ToolContext = {
messageID: string
agent: string
abort: AbortSignal
/**
* Request user permission for an action. Throws if user denies.
* @param input Permission request details
*/
askPermission?: (input: {
type: string
title: string
pattern?: string | string[]
metadata: Record<string, any>
}) => Promise<void>
}

export function tool<Args extends z.ZodRawShape>(input: {
Expand Down