Skip to content

fix(opencode): preserve prompt tool enables with empty agent permissions#17064

Open
jquense wants to merge 1 commit intoanomalyco:devfrom
jquense:jq/fix-prompt-permissions
Open

fix(opencode): preserve prompt tool enables with empty agent permissions#17064
jquense wants to merge 1 commit intoanomalyco:devfrom
jquense:jq/fix-prompt-permissions

Conversation

@jquense
Copy link
Contributor

@jquense jquense commented Mar 11, 2026

Issue for this PR

Closes #17063

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When an agent has permission: {}, prompt-level tool enables can be dropped before the model request is built.

This PR applies session/prompt permission overrides in the same pre-request filtering path that decides which tools are exposed to the model, and adds a regression test for the tools: { question: true } case.

How did you verify your code works?

  • added regression coverage in packages/opencode/test/session/llm.test.ts
  • reproduced the bug with a local SDK repro script
  • confirmed the repro succeeds against the local dev server with this change
Repro script used for testing

packages/sdk/js/example/question-permission-repro.ts

import { createOpencodeClient } from "@opencode-ai/sdk/v2"
import { spawn } from "node:child_process"

const key = process.env.ANTHROPIC_API_KEY

if (!key) {
  throw new Error("Set ANTHROPIC_API_KEY before running this repro")
}

const port = 4100 + Math.floor(Math.random() * 1000)
const proc = spawn("bun", ["run", "dev", "--", "serve", `--hostname=127.0.0.1`, `--port=${port}`], {
  cwd: new URL("../../../../", import.meta.url),
  env: {
    ...process.env,
    OPENCODE_CONFIG_CONTENT: JSON.stringify({
      enabled_providers: ["anthropic"],
      provider: {
        anthropic: {
          options: {
            apiKey: key,
          },
        },
      },
      agent: {
        repro: {
          mode: "primary",
          model: "anthropic/claude-sonnet-4-5-20250929",
          permission: {},
        },
      },
    }),
  },
})

proc.stdout?.pipe(process.stdout)
proc.stderr?.pipe(process.stderr)

const url = await new Promise<string>((resolve, reject) => {
  let out = ""
  const timeout = setTimeout(() => done(new Error(`timed out waiting for dev server\n${out}`)), 15000)
  const done = (err?: Error) => {
    clearTimeout(timeout)
    proc.stdout?.off("data", onStdout)
    proc.stderr?.off("data", onStderr)
    proc.off("error", onError)
    proc.off("exit", onExit)
    if (err) reject(err)
  }
  const onStdout = (chunk: Buffer) => {
    out += chunk.toString()
    for (const line of out.split("\n")) {
      const match = line.match(/opencode server listening on\s+(https?:\/\/\S+)/)
      if (!match) continue
      done()
      resolve(match[1]!)
      return
    }
  }
  const onStderr = (chunk: Buffer) => {
    out += chunk.toString()
  }
  const onError = (err: Error) => done(err)
  const onExit = (code: number | null) => done(new Error(`dev server exited early: ${code}\n${out}`))
  proc.stdout?.on("data", onStdout)
  proc.stderr?.on("data", onStderr)
  proc.on("error", onError)
  proc.on("exit", onExit)
})

const client = createOpencodeClient({ baseUrl: url })
const session = await client.session.create()
const sessionID = session.data!.id

console.log("session:", sessionID)
console.log("sending prompt")

const result = await client.session.prompt({
  sessionID,
  agent: "repro",
  tools: {
    question: true,
  },
  parts: [
    {
      type: "text",
      text: "do you have a question tool?",
    },
  ],
})

console.log(result.data?.parts?.find((part) => part.type === "text")?.text)

proc.kill()

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 11, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdk.prompt({ tools }) does not override agent configured permissions

1 participant