feat: add formal PR reviews and Pi/OpenCode backends #29

Merged
nimmo merged 4 commits from feat/issue-28-agent-cli into main 2026-10-07 21:14:35 +01:00
Owner

Reviews can now run headless coding agents to investigate callers and definitions beyond the diff, and optionally publish formal Forgejo review decisions. This repository is configured to use Pi with strata/strata on the future Vega host runner and publish formal COMMENT reviews after merge; approval and request-changes authority remain disabled. The tool's default behavior for other repositories remains advisory comments.

Adds configurable Pi and bundled OpenCode backends alongside the existing HTTP providers. The OpenCode adapter extracts only a completed final response from its JSON event stream and explicitly rejects unknown or missing event types. Both CLI backends validate reports, enforce accepted-output limits, clean up temporary files, and terminate the process group on timeout. Publishing credentials are excluded from the child environment. Pi defaults to strata/strata, selected from documented live synthetic samples; other installations can choose their own provider/model. OpenCode requires an explicit model and provides a dedicated agent with navigation permissions. CLI executables remain runner dependencies, and agent permissions are not an OS sandbox.

Formal reviews are opt-in through trusted base-branch configuration. Approval and request-changes authority are separately configurable, with conservative approval checks and reviews attached to the exact reviewed head commit.

The repository configuration uses Vega's system Pi wrapper with navigation tools and optional integrations disabled. It retains second-pass validation and allows a 40-minute workflow budget for two 15-minute model passes plus checks. Vega must have a registered host runner with the vega label and a service user able to access the Pi wrapper and Strata credentials. Pi starts on Vega, but an active Forgejo runner service was not found during verification; its deployment remains infrastructure work outside this PR. No Pi setup on Nova is needed.

Validation:

  • 65 unit tests passed; the optional installed-CLI smoke test is separate.
  • Installed OpenCode 1.18.35 passed the loopback fixture test, including an actual file-read tool call, final report extraction, and an unchanged checkout.
  • Native x86_64-linux nix flake check --no-update-lock-file passed for the implementation and parser fix; aarch64-linux was skipped as incompatible with the validation host.
  • The final repository configuration parses with the reviewer's parser and passes formal-review configuration validation.
  • Pi live regression and clean-control results and configuration instructions are included in the documentation.

This PR's model configuration still comes from the base branch, so its automatic review uses Ollama until merge. The workflow runner change may route this PR's checks to Vega before merge and queue them until that runner is registered.

Closes #27.
Closes #28.

Reviews can now run headless coding agents to investigate callers and definitions beyond the diff, and optionally publish formal Forgejo review decisions. This repository is configured to use Pi with `strata/strata` on the future Vega host runner and publish formal `COMMENT` reviews after merge; approval and request-changes authority remain disabled. The tool's default behavior for other repositories remains advisory comments. Adds configurable Pi and bundled OpenCode backends alongside the existing HTTP providers. The OpenCode adapter extracts only a completed final response from its JSON event stream and explicitly rejects unknown or missing event types. Both CLI backends validate reports, enforce accepted-output limits, clean up temporary files, and terminate the process group on timeout. Publishing credentials are excluded from the child environment. Pi defaults to `strata/strata`, selected from documented live synthetic samples; other installations can choose their own provider/model. OpenCode requires an explicit model and provides a dedicated agent with navigation permissions. CLI executables remain runner dependencies, and agent permissions are not an OS sandbox. Formal reviews are opt-in through trusted base-branch configuration. Approval and request-changes authority are separately configurable, with conservative approval checks and reviews attached to the exact reviewed head commit. The repository configuration uses Vega's system Pi wrapper with navigation tools and optional integrations disabled. It retains second-pass validation and allows a 40-minute workflow budget for two 15-minute model passes plus checks. Vega must have a registered host runner with the `vega` label and a service user able to access the Pi wrapper and Strata credentials. Pi starts on Vega, but an active Forgejo runner service was not found during verification; its deployment remains infrastructure work outside this PR. No Pi setup on Nova is needed. Validation: - 65 unit tests passed; the optional installed-CLI smoke test is separate. - Installed OpenCode 1.18.35 passed the loopback fixture test, including an actual file-read tool call, final report extraction, and an unchanged checkout. - Native x86_64-linux `nix flake check --no-update-lock-file` passed for the implementation and parser fix; aarch64-linux was skipped as incompatible with the validation host. - The final repository configuration parses with the reviewer's parser and passes formal-review configuration validation. - Pi live regression and clean-control results and configuration instructions are included in the documentation. This PR's model configuration still comes from the base branch, so its automatic review uses Ollama until merge. The workflow runner change may route this PR's checks to Vega before merge and queue them until that runner is registered. Closes #27. Closes #28.
feat: add headless Pi and OpenCode review backends (#28)
All checks were successful
Build and publish container image / prepare-tags (push) Successful in 2s
Build and publish container image / build-and-push (push) Successful in 52s
AI pull-request review / review (pull_request) Successful in 1m40s
5bec6004f5
First-time contributor

Automated code review

Reviewed commit: 9dab3bffa307a35e5f41a53dc569c27fc5576ab1

Verdict: Requires further work

Resolve the blocking or important findings and investigate failed deterministic checks before merging.

Overall assessment

The pull request introduces headless agent backends (Pi and OpenCode) for AI-driven code reviews, enabling the reviewer to navigate the codebase beyond the immediate diff. It also implements formal PR review decisions (COMMENT, REQUEST_CHANGES, APPROVED) via Forgejo's API, controlled by explicit configuration flags. The changes include a new agent_cli_review function, event parsing for OpenCode, validation logic for formal reviews, and extensive unit tests covering these new paths. Documentation is updated to reflect the new capabilities and configuration options.

Blocking findings

None.

Important findings

  • OpenCode adapter rejects unknown event types but does not validate known event structure strictly enough against schema changes (reviewer.py:580; medium confidence)
    The parse_opencode_events function iterates through lines and checks for specific event types. If an unknown type is encountered, it raises a ValueError. However, for known types like 'text', it checks for 'id' and 'text' keys but does not enforce that the entire structure matches a strict schema beyond these basic checks. While this prevents injection of arbitrary data, it relies on the assumption that future versions of OpenCode will not change the structure of known events in a way that breaks the parser without changing the event type.
    Impact: If OpenCode changes the structure of a known event type (e.g., adding required fields or changing types), the parser might accept malformed data or fail silently if not caught by subsequent validation. This could lead to incomplete or incorrect review reports being generated.
    Suggested fix: Consider adding more robust schema validation for each known event type, perhaps using a library like pydantic or explicit checks for all expected fields and their types. Additionally, log the raw event data (sanitized) when an error occurs to aid in debugging protocol changes.

Suggestions

  • Hardcoded default Pi model may not be suitable for all deployments (reviewer.py:39; medium confidence)
    DEFAULT_PI_MODEL = "strata/strata" is defined as a constant. The agent_cli_review function uses this as the default if no model is specified in the config for Pi providers.
    Impact: Users deploying this reviewer on systems without the 'strata/strata' model will encounter errors or unexpected behavior unless they explicitly configure the model. While the documentation mentions this, relying on a hardcoded default can lead to confusion.
    Suggested fix: Consider making the default model configurable via an environment variable (e.g., DEFAULT_PI_MODEL_ENV) that can be set at build time or runtime, or require the model to be explicitly specified in the configuration for Pi providers, similar to OpenCode. Alternatively, provide a clear error message if the default model is not available.

Tests and validation

  • unit-tests: success

Questions

  • Has the OpenCode adapter been tested against multiple versions of the OpenCode CLI to ensure backward compatibility with event structures?
  • Are there any plans to support other agent backends beyond Pi and OpenCode, and if so, is the agent_cli_review function designed to be extensible for future additions?

Review limitations

  • The review is based on the provided diff and documentation. I have not executed the code or run the tests myself.
  • The impact of the hardcoded default Pi model depends on the specific deployment environment, which is not fully known.
  • The OpenCode adapter's robustness to future protocol changes is a potential area for improvement, but its current behavior is acceptable given the explicit rejection of unknown event types.

Diff coverage

  • .forgejo/ai-review.yml: reviewed — included in a context-limited batch
  • .forgejo/workflows/ai-review.yml: reviewed — included in a context-limited batch
  • README.md: reviewed — included in a context-limited batch
  • action.yml: reviewed — included in a context-limited batch
  • docs/pi-live-sample.md: reviewed — included in a context-limited batch
  • reviewer.py: reviewed — included in a context-limited batch
  • tests/fixtures/agent_review.json: reviewed — included in a context-limited batch
  • tests/fixtures/formal_review_events.json: reviewed — included in a context-limited batch
  • tests/test_agent_cli.py: reviewed — included in a context-limited batch
  • tests/test_opencode_smoke.py: reviewed — included in a context-limited batch
  • tests/test_reviewer.py: reviewed — included in a context-limited batch
Review metadata
  • Reviewer: forgejo-ai-review v1
  • Model: qwen3.6:35b-a3b-q8_0
  • Guidance loaded: .forgejo/ai-review.yml, docs/pi-live-sample.md, README.md
  • Commits considered: 4
  • Previous automated review: updated
  • Findings: 2
<!-- forgejo-ai-review:v1 --> ## Automated code review Reviewed commit: `9dab3bffa307a35e5f41a53dc569c27fc5576ab1` ## Verdict: Requires further work Resolve the blocking or important findings and investigate failed deterministic checks before merging. ### Overall assessment The pull request introduces headless agent backends (Pi and OpenCode) for AI-driven code reviews, enabling the reviewer to navigate the codebase beyond the immediate diff. It also implements formal PR review decisions (COMMENT, REQUEST_CHANGES, APPROVED) via Forgejo's API, controlled by explicit configuration flags. The changes include a new `agent_cli_review` function, event parsing for OpenCode, validation logic for formal reviews, and extensive unit tests covering these new paths. Documentation is updated to reflect the new capabilities and configuration options. ### Blocking findings None. ### Important findings - **OpenCode adapter rejects unknown event types but does not validate known event structure strictly enough against schema changes** (reviewer.py:580; medium confidence) The `parse_opencode_events` function iterates through lines and checks for specific event types. If an unknown type is encountered, it raises a ValueError. However, for known types like 'text', it checks for 'id' and 'text' keys but does not enforce that the entire structure matches a strict schema beyond these basic checks. While this prevents injection of arbitrary data, it relies on the assumption that future versions of OpenCode will not change the structure of known events in a way that breaks the parser without changing the event type. Impact: If OpenCode changes the structure of a known event type (e.g., adding required fields or changing types), the parser might accept malformed data or fail silently if not caught by subsequent validation. This could lead to incomplete or incorrect review reports being generated. Suggested fix: Consider adding more robust schema validation for each known event type, perhaps using a library like `pydantic` or explicit checks for all expected fields and their types. Additionally, log the raw event data (sanitized) when an error occurs to aid in debugging protocol changes. ### Suggestions - **Hardcoded default Pi model may not be suitable for all deployments** (reviewer.py:39; medium confidence) DEFAULT_PI_MODEL = "strata/strata" is defined as a constant. The `agent_cli_review` function uses this as the default if no model is specified in the config for Pi providers. Impact: Users deploying this reviewer on systems without the 'strata/strata' model will encounter errors or unexpected behavior unless they explicitly configure the model. While the documentation mentions this, relying on a hardcoded default can lead to confusion. Suggested fix: Consider making the default model configurable via an environment variable (e.g., `DEFAULT_PI_MODEL_ENV`) that can be set at build time or runtime, or require the model to be explicitly specified in the configuration for Pi providers, similar to OpenCode. Alternatively, provide a clear error message if the default model is not available. ### Tests and validation - unit-tests: **success** ### Questions - Has the OpenCode adapter been tested against multiple versions of the OpenCode CLI to ensure backward compatibility with event structures? - Are there any plans to support other agent backends beyond Pi and OpenCode, and if so, is the `agent_cli_review` function designed to be extensible for future additions? ### Review limitations - The review is based on the provided diff and documentation. I have not executed the code or run the tests myself. - The impact of the hardcoded default Pi model depends on the specific deployment environment, which is not fully known. - The OpenCode adapter's robustness to future protocol changes is a potential area for improvement, but its current behavior is acceptable given the explicit rejection of unknown event types. ### Diff coverage - `.forgejo/ai-review.yml`: **reviewed** — included in a context-limited batch - `.forgejo/workflows/ai-review.yml`: **reviewed** — included in a context-limited batch - `README.md`: **reviewed** — included in a context-limited batch - `action.yml`: **reviewed** — included in a context-limited batch - `docs/pi-live-sample.md`: **reviewed** — included in a context-limited batch - `reviewer.py`: **reviewed** — included in a context-limited batch - `tests/fixtures/agent_review.json`: **reviewed** — included in a context-limited batch - `tests/fixtures/formal_review_events.json`: **reviewed** — included in a context-limited batch - `tests/test_agent_cli.py`: **reviewed** — included in a context-limited batch - `tests/test_opencode_smoke.py`: **reviewed** — included in a context-limited batch - `tests/test_reviewer.py`: **reviewed** — included in a context-limited batch <details><summary>Review metadata</summary> - Reviewer: forgejo-ai-review v1 - Model: qwen3.6:35b-a3b-q8_0 - Guidance loaded: .forgejo/ai-review.yml, docs/pi-live-sample.md, README.md - Commits considered: 4 - Previous automated review: updated - Findings: 2 </details>
fix: reject unknown OpenCode review events
All checks were successful
Build and publish container image / prepare-tags (push) Successful in 1s
Build and publish container image / build-and-push (push) Successful in 25s
AI pull-request review / review (pull_request) Successful in 1m27s
e683506a5e
config: enable Pi formal comment reviews on Vega
All checks were successful
Build and publish container image / prepare-tags (push) Successful in 2s
Build and publish container image / build-and-push (push) Successful in 12s
AI pull-request review / review (pull_request) Successful in 1m37s
9dab3bffa3
nimmo merged commit eec8f0a26d into main 2026-10-07 21:14:35 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nimmo/forgejo-auto-pr-review!29
No description provided.