Skip to content

Add OpenCode agent adapter - #63

Merged
vsn411 merged 1 commit into
secfoo-com:mainfrom
dbdefault:feat/opencode-adapter
Nov 10, 2026
Merged

vsn411 merged 1 commit into
secfoo-com:mainfrom
dbdefault:feat/opencode-adapter

Conversation

@dbdefault

@dbdefault dbdefault commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #49

Adds an adapter for OpenCode (opencode run), tested against opencode 1.18.34 (recorded in the module docstring). Follows PR #27 (Droid/Devin).

What changed

  • src/secfoo/agents/opencode.py: new OpenCodeAdapter (build_command, extract_report, extract_usage)
  • Registered in registry.py and the AgentId enum in cli.py (secfoo run --agent opencode); -m model flag added to the model-selection test table
  • README / docs/REFERENCE.md supported-agent lists
  • base.py: one small optional hook, extra_env (class attribute, empty by default). env is passed to Popen only when non-empty, so existing adapters are unaffected.
  • tests/test_agents/test_opencode.py: fake-binary tests, no real API calls

Command

opencode run --pure --format json --dir <workdir> [-m provider/model], prompt on stdin.

Requirements from the issue

  • Non-interactive: prompt via stdin, no trust/auth prompt (verified: without credentials it exits with a 401 API error event instead of hanging).
  • Read-only: --auto is not used. Because opencode's default agent allows bash/edit even without --auto, the adapter also sets OPENCODE_PERMISSION and OPENCODE_CONFIG_CONTENT to deny bash, edit and webfetch. Both are set so an inherited OPENCODE_PERMISSION or a project opencode.json that allows them cannot widen access. Manually verified with opencode debug agent build, and with a live run (free model) asked to create a file and run a shell command: both were refused and no file was created.
  • Tests: fake binary, assert no --auto, assert both deny env vars reach the subprocess, assert other adapters still launch without an env kwarg.

Verification

  • pytest tests/test_agents: 124 passed
  • Real run against a free OpenCode model confirmed the JSON events the parser reads (text, step_finish tokens/cost).

Known limits

  • Full pytest tests on my Windows machine (after secfoo vendor mermaid and installing the PDF/DOCX deps): 1002 passed, 4 failed, all unrelated to this change and Windows-specific: 3 POSIX file-permission-mode assertions (0600 is not representable on Windows) and 1 symlink test (needs symlink privilege).
  • ruff check . reports pre-existing violations on main; the new files add none.
  • I did not verify that per-agent permission overrides in a user's own opencode config are also blocked; the global and inherited cases are.

@vsn411
vsn411 merged commit 615de3b into secfoo-com:main Nov 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New agent adapter: add support for another coding-agent CLI

2 participants