diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index f92d3305bf1..19d968cda1a 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -20,6 +20,7 @@ import { ReadTool } from "../../tool/read" import { WebFetchTool } from "../../tool/webfetch" import { EditTool } from "../../tool/edit" import { WriteTool } from "../../tool/write" +import { ApplyPatchTool } from "../../tool/apply_patch" import { CodeSearchTool } from "../../tool/codesearch" import { WebSearchTool } from "../../tool/websearch" import { TaskTool } from "../../tool/task" @@ -153,6 +154,38 @@ function edit(info: ToolProps) { ) } +function applypatch(info: ToolProps) { + const files = Array.isArray(info.metadata.files) ? info.metadata.files : [] + if (!files.length) { + block( + { + icon: "%", + title: "Patch", + }, + info.metadata.diff, + ) + return + } + + for (const file of files) { + const title = + file.type === "delete" + ? `Deleted ${file.relativePath}` + : file.type === "add" + ? `Created ${file.relativePath}` + : file.type === "move" + ? `Moved ${normalizePath(file.filePath)} -> ${file.relativePath}` + : `Patched ${file.relativePath}` + block( + { + icon: "%", + title, + }, + file.diff, + ) + } +} + function codesearch(info: ToolProps) { inline({ icon: "◇", @@ -419,6 +452,7 @@ export const RunCommand = cmd({ if (part.tool === "write") return write(props(part)) if (part.tool === "webfetch") return webfetch(props(part)) if (part.tool === "edit") return edit(props(part)) + if (part.tool === "apply_patch") return applypatch(props(part)) if (part.tool === "codesearch") return codesearch(props(part)) if (part.tool === "websearch") return websearch(props(part)) if (part.tool === "task") return task(props(part)) diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx index a50cd96fc84..66d0be7b73b 100644 --- a/packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx +++ b/packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx @@ -54,6 +54,10 @@ function EditBody(props: { request: PermissionRequest }) { const filepath = createMemo(() => (props.request.metadata?.filepath as string) ?? "") const diff = createMemo(() => (props.request.metadata?.diff as string) ?? "") + const files = createMemo(() => { + const value = props.request.metadata?.files + return Array.isArray(value) ? value : [] + }) const view = createMemo(() => { const diffStyle = config.diff_style @@ -63,9 +67,58 @@ function EditBody(props: { request: PermissionRequest }) { const ft = createMemo(() => filetype(filepath())) + function title(file: { type: string; relativePath: string; filePath: string }) { + if (file.type === "delete") return "# Deleted " + file.relativePath + if (file.type === "add") return "# Created " + file.relativePath + if (file.type === "move") return "# Moved " + normalizePath(file.filePath) + " -> " + file.relativePath + return "# Patched " + file.relativePath + } + return ( - + 0}> + + + + {(file) => ( + + + {title(file)} + + + + )} + + + + + - + No diff provided