opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: auto-deny permissions and emit events in non-interactive mode

Open elithrar opened this issue 1 week ago • 1 comments

Fixes issues where permissions requests block indefinitely in CI/GitHub Actions, with no output indicating why. I keep running into this in CI runs, especially when the harness is trying to solve a problem or I'm testing/building plugins.

Since there's no way to prompt a user, it should just auto-deny by default + emit this to the logs so users can understand what happened.

Changes

  • Add isInteractive() utility - checks CI env var, OPENCODE_CLIENT, and TTY state
  • Auto-deny permission requests when !isInteractive() (no one to approve)
  • Emit permission.asked events before denying so they're visible in logs
  • Subscribe to permission events in github.ts and run.ts with actionable guidance on how to allow
  • Add OPENCODE_EMIT_SUBAGENT_EVENTS flag for verbose subagent output in CI
  • Add emit_subagent_events input to GitHub Action
  • Deny question permission by default in GitHub Action sessions (merged from dev)

isInteractive() Logic

Only auto-denies for the CLI client in non-TTY/CI environments:

  1. OPENCODE_FORCE_INTERACTIVE=true → interactive (for tests)
  2. CI=true → non-interactive (auto-deny)
  3. OPENCODE_CLIENT is not cli (e.g. desktop) → interactive (GUI handles permissions)
  4. Otherwise, check stdin.isTTY && stdout.isTTY

current possible OPENCODE_CLIENT values: cli (default), desktop

Example Output

When a permission is denied in CI:

| Denied  external_directory: /tmp/opencode-source
  To allow, add to opencode.json: { "permission": { "external_directory": "allow" } }

Merge Conflict Resolution

Resolved conflict with dev branch - combined:

  • Permission config from dev (deny question prompts in GitHub Action context)
  • Event unsubscribe cleanup from this PR branch

elithrar avatar Jan 04 '26 14:01 elithrar