Skip to content

Apply Patch / Edit permission view only shows the first file #55337

Open

Description

@emamimohsen

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

Activity

  1. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    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.

    recording.mp4

    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.

  2. drakeo338 commented on Oct 14, 2026

    @drakeo338

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

  3. gysi commented on Oct 17, 2026

    @gysi

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

  4. BulatVakhitov commented on Nov 19, 2026

    @BulatVakhitov

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

  5. added a commit that references this issue on Dec 3, 2026
    4540306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions