Apply Patch / Edit permission view only shows the first file
Description
Re-logging this issue for the OpenCode 2.x codebase as both legacy #17076 and #36119 were closed automatically by bots despite the bug remaining unresolved.
Current Behavior: When a model groups multiple file changes into a single apply_patch payload, the EditBody component in packages/tui/src/routes/session/permission.tsx only maps the first file's diff text. Granting permission silently applies all subsequent, hidden file modifications.
Expected Behavior: The permission TUI should utilize the request.metadata.files array to let users switch tabs or cycle through all files contained in the patch payload before approving.
Plugins
No response
OpenCode version
v2.0.28
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
Windows Terminal
Thanks for re-filing this for v2. I reproduced it on v2.0.28, and it still happens on the latest dev (3a69bae).
How I reproduced it:
- Set
editpermission to ask. - Have the model send a single
patch(apply_patch) call that updatessrc/alpha.tsandsrc/beta.tsand createssrc/gamma.ts. - The permission prompt says Edit src/alpha.ts and shows only alpha's diff. Nothing in the prompt shows the other two files.
- After Allow once, all three files are changed.
The recording and screenshots below show the prompt and the result after approving, and the script below reproduces it.
The cause is that the TUI's permission presentation (permissionPresentation in packages/tui/src/util/permission.ts) reads only metadata.files[0], even though the request includes every file and its diff.
Related earlier reports from v1, both closed: #17076 and #36119. #23262 was an earlier PR that added file cycling to this prompt.
https://github.com/user-attachments/assets/d24b2c4c-b128-41cc-a2c6-1d7d80d2c735
Reproduction script (drive.ts)
// Repro for anomalyco/opencode#55337: multi-file patch permission prompt only shows the first file.
import { Effect } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
const patchText = [
"*** Begin Patch",
"*** Update File: src/alpha.ts",
"@@",
"-export const alpha = 1",
"+export const alpha = 100",
"*** Update File: src/beta.ts",
"@@",
"-export const beta = 2",
"+export const beta = \"HIDDEN_CHANGE_IN_BETA\"",
"*** Add File: src/gamma.ts",
"+export const gamma = \"HIDDEN_NEW_FILE_GAMMA\"",
"*** End Patch",
].join("\n")
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
tui: { recording: true, viewport: { cols: 120, rows: 40 } },
config: {
permissions: [
{ action: "*", resource: "*", effect: "allow" },
{ action: "edit", resource: "*", effect: "ask" },
],
},
project: {
git: true,
files: {
"src/alpha.ts": "export const alpha = 1\n",
"src/beta.ts": "export const beta = 2\n",
},
},
},
({ ui, llm }) =>
Effect.gen(function* () {
yield* llm.queue(
Llm.toolCall({ index: 0, id: "call_patch", name: "patch", input: { patchText } }),
Llm.finish("tool-calls"),
)
yield* llm.queue(Llm.text("Done."))
yield* ui.submit("Update alpha, beta and add gamma in one patch")
yield* ui.waitFor("Permission required", { timeout: 30000 })
yield* Effect.sleep(1500)
yield* ui.screenshot("permission-prompt")
const frame = yield* ui.capture()
const text = JSON.stringify(frame)
yield* Effect.log(`prompt shows beta change: ${text.includes("HIDDEN_CHANGE_IN_BETA")}`)
yield* Effect.log(`prompt shows gamma file: ${text.includes("HIDDEN_NEW_FILE_GAMMA")}`)
// Approve once
yield* ui.enter()
yield* ui.waitFor("Done.", { timeout: 30000 })
yield* Effect.sleep(1500)
yield* ui.screenshot("after-approve")
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
I'm looking at this and plan to open a fix shortly.
@drakeo338 thanks for the PR! When will it be merged?
I'm looking forward to this feature being added. Really miss it in current version.