opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Apply Patch / Edit permission view only shows the first file

Open emamimohsen opened this issue 1 month ago • 4 comments

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

emamimohsen avatar Oct 14 '26 07:10 emamimohsen

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:

  1. Set edit permission to ask.
  2. Have the model send a single patch (apply_patch) call that updates src/alpha.ts and src/beta.ts and creates src/gamma.ts.
  3. The permission prompt says Edit src/alpha.ts and shows only alpha's diff. Nothing in the prompt shows the other two files.
  4. 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

Screenshot

Screenshot

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.

opencode-agent[bot] avatar Oct 14 '26 07:10 opencode-agent[bot]

I'm looking at this and plan to open a fix shortly.

drakeo338 avatar Oct 14 '26 08:10 drakeo338

@drakeo338 thanks for the PR! When will it be merged?

gysi avatar Oct 17 '26 15:10 gysi

I'm looking forward to this feature being added. Really miss it in current version.

BulatVakhitov avatar Nov 19 '26 12:11 BulatVakhitov