Skip to content

feat(guardian): add opencode-go DeepSeek provider over GitHub OIDC - #777

Merged
zaebee merged 3 commits into
mainfrom
agent/guardian-opencode-provider-de9e51a50e7a
Nov 5, 2026
Merged

zaebee merged 3 commits into
mainfrom
agent/guardian-opencode-provider-de9e51a50e7a

Conversation

@it-start

@it-start it-start commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

This is by an automated agent, not a human.

What changed

  • Adds src/cgis/guardian/providers/opencode.py: a DeepSeek finder over the opencode-go OpenAI-compatible gateway (https://opencode.ai/inference/go/openai/v1), with max_tokens, an explicit reasoning_effort (default low), optional GUARDIAN_TEMPERATURE, a client user agent and a stable per-run x-opencode-session header. A 429 raises OpenCodeQuotaError, any other HTTP error raises, and a length finish or a reasoning-only reply raises instead of being returned as a verdict.
  • Extracts the shared OpenAI-compatible plumbing (_shared_payload, generate_content, generate_structured, response_format and temperature application) into providers/openai_compatible.py, which OpenRouter and OpenCode Go both use. Each provider keeps its own _payload with its reasoning knob (reasoning vs reasoning_effort). This removes the duplication Sonar flagged.
  • Registers it in runner.build_provider under opencode-go (canonical) and opencode (the provider's own hyphen-free name, from which the review fingerprint derives its module path). The model defaults to deepseek-v4.1-flash; GUARDIAN_MODEL, GUARDIAN_OPENCODE_EFFORT and GUARDIAN_OPENCODE_BASE_URL configure it, and auto-detection prefers OPENCODE_API_KEY. Anthropic and its explicit effort setting are unchanged.
  • Adds opencode to the review fingerprint's known-provider set.
  • Moves the reusable workflow to GitHub OIDC: the review job gains id-token: write, and a Sign in to OpenCode (OIDC) step exchanges the short-lived GitHub token for an inference token immediately before the review, writing it to GITHUB_ENV. There is no static OPENCODE_API_KEY secret, and the review step does not set that variable. The step parses JSON with uv run --frozen python (a self-hosted runner need not have python3 on PATH) and signs in only for opencode-go, opencode, or an unset GUARDIAN_PROVIDER; an explicit other provider logs that OpenCode is not selected and skips. ANTHROPIC_API_KEY stays declared and passed. GUARDIAN_ANTHROPIC_EFFORT is no longer passed; GUARDIAN_OPENCODE_EFFORT is.
  • The repository caller (guardian.yml) also grants id-token: write.
  • Docs: README provider list, opencode-go example and OIDC setup; PRIVACY provider list.

Verification

  • make format && make lint && make type-check && make pytest && make doc-coverage — all green.
  • New tests/unit/test_guardian_opencode.py covers the default and overridden URL, bearer/user-agent/session headers, max_tokens, timeout, reasoning_effort, 429, other 4xx, finish_reason=length, empty content beside reasoning_content, usage recording and structured output. The existing OpenRouter suite remains green after the shared-base extraction.
  • Runner, workflow and fingerprint tests pin the selector aliases, default model, environment wiring, OIDC step shape and ordering, id-token in both workflows, the absence of a static key, and the step's independence from jq. The sign-in shell was also exercised against a fake curl for the missing-token, success and 4xx paths.

Limitations

  • Live end-to-end against opencode-go was not run: this environment has no OIDC token or inference key. After merge, enable OIDC for GitHub Actions in the Opencode console, set OPENCODE_CLIENT_ID for the calling repository, and run /guardian review.
  • Bench/calibrate numbers are out of scope per the issue thread and follow in a separate issue.
  • The issue stays open until the post-merge live run.

Refs #775

)

The finder moves to opencode-go / deepseek-v4.1-flash, so a review no longer needs an ANTHROPIC_API_KEY. The reusable workflow mints a short-lived inference token by exchanging a GitHub OIDC token; there is no static OPENCODE_API_KEY secret.

Co-authored-by: Andrey Gromov <305761+zaebee@users.noreply.github.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the OpenCode Go provider, enabling DeepSeek model integration via an OpenAI-compatible gateway and supporting passwordless GitHub Actions OIDC authentication. The changes include the new provider implementation, runner integration, documentation updates, and comprehensive unit tests. The review feedback correctly identifies an opportunity to make the provider's initialization more robust against null values and simplifies the URL parsing logic.

Comment thread src/cgis/guardian/providers/opencode.py Resolved
Sonar flagged 25 duplicated lines between the new opencode provider and openrouter: the shared payload, temperature application, generate_content and generate_structured now live in providers/openai_compatible.py, with each provider keeping its own _payload (reasoning vs reasoning_effort). Also folds the OpenCode constructor's duplicate defaulting into one expression per the Gemini review.

Co-authored-by: Andrey Gromov <305761+zaebee@users.noreply.github.com>
@it-start
it-start force-pushed the agent/guardian-opencode-provider-de9e51a50e7a branch from 8f398a2 to ff39b15 Compare November 5, 2026 17:31
Parse the OIDC and token-exchange JSON with 'uv run --frozen python' instead of assuming python3 is on PATH, and skip sign-in when GUARDIAN_PROVIDER explicitly names another provider. The empty value still signs in so the minted key keeps opencode as the autodetected provider.

Co-authored-by: Andrey Gromov <305761+zaebee@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@zaebee
zaebee merged commit 33ec492 into main Nov 5, 2026
5 checks passed
@zaebee
zaebee deleted the agent/guardian-opencode-provider-de9e51a50e7a branch November 5, 2026 17:54
@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

/guardian review

2 similar comments
@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

/guardian review

@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

/guardian review

@codegraph-guardian codegraph-guardian Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Guardian could not produce structured output; raw response below.

  • [src/cgis/guardian/providers/base.py, src/cgis/guardian/providers/openai_compatible.py, src/cgis/guardian/providers/opencode.py, src/cgis/guardian/providers/openrouter.py, src/cgis/guardian/runner.py, tests/unit/test_guardian_runner.py]: ⚠ finder call failed
  • [src/cgis/guardian/review_fingerprint.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_opencode.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_providers_name.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_review_script.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_workflow.py]: ⚠ finder call failed
  • [tests/unit/test_review_fingerprint_closure.py]: ⚠ finder call failed

🤖 deepseek-v4.1-flash · graph 6/12 files (50%)

@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

/guardian review

@codegraph-guardian codegraph-guardian Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Guardian could not produce structured output; raw response below.

  • [src/cgis/guardian/providers/base.py, src/cgis/guardian/providers/openai_compatible.py, src/cgis/guardian/providers/opencode.py, src/cgis/guardian/providers/openrouter.py, src/cgis/guardian/runner.py, tests/unit/test_guardian_runner.py]: ⚠ finder call failed
  • [src/cgis/guardian/review_fingerprint.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_opencode.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_providers_name.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_review_script.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_workflow.py]: ⚠ finder call failed
  • [tests/unit/test_review_fingerprint_closure.py]: ⚠ finder call failed

🤖 deepseek-v4.1-flash · graph 6/12 files (50%)

@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

/guardian review

@codegraph-guardian codegraph-guardian Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Guardian could not produce structured output; raw response below.

  • [src/cgis/guardian/providers/base.py, src/cgis/guardian/providers/openai_compatible.py, src/cgis/guardian/providers/opencode.py, src/cgis/guardian/providers/openrouter.py, src/cgis/guardian/runner.py, tests/unit/test_guardian_runner.py]: ⚠ finder call failed
  • [src/cgis/guardian/review_fingerprint.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_opencode.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_providers_name.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_review_script.py]: ⚠ finder call failed
  • [tests/unit/test_guardian_workflow.py]: ⚠ finder call failed
  • [tests/unit/test_review_fingerprint_closure.py]: ⚠ finder call failed

🤖 deepseek-v4.1-flash · graph 6/12 files (50%)

github-actions Bot added a commit that referenced this pull request Nov 5, 2026
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.

2 participants