Skip to content

feat: add fetch_pr_review_context tool to review-dispatch plugin - #697

Merged
jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/fetch-pr-review-context
Oct 10, 2026
Merged

jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/fetch-pr-review-context

Conversation

@jflowers

Copy link
Copy Markdown
Contributor

Summary

Add a new fetch_pr_review_context tool to the review-dispatch
plugin that consolidates 5+ sequential gh CLI calls into one
deterministic fetch. The tool retrieves PR metadata, CI checks,
the full diff (persisted to disk with 0o600 permissions),
existing reviews, inline comments, and pre-computed derived
fields — reducing review dispatch latency and eliminating shell
injection risk via Bun.spawn argument arrays.

How to Test

  • Run the plugin test suite:
    make plugin-test
    
  • Targeted test file:
    npx vitest run .opencode/test/fetch-pr-review-context.test.ts
    
  • Acceptance scenarios from the spec:
    • Valid PR number returns structured metadata
    • Complete output populates all fields; diff_path points to a
      readable file
    • Missing gh CLI returns gh_not_found error
    • Diff saved to $TMPDIR/opencode/pr-<number>-diff.patch
      with 0o600
    • PR not found returns pr_not_found error

How to Demo

  1. Open a PR on this repository
  2. In OpenCode, invoke fetch_pr_review_context with the PR
    number
  3. Observe the structured response: title, body, base/head refs
    and SHAs, files list, diff path, CI checks, existing reviews,
    and inline comments
  4. Verify the diff file exists at the returned diff_path with
    0o600 permissions

Key Files Changed

File Change
.opencode/plugins/review-dispatch/index.ts New fetch_pr_review_context tool implementation (Bun.spawn, structured errors, threshold detection)
.opencode/test/fetch-pr-review-context.test.ts Comprehensive test suite
internal/scaffold/assets/opencode/plugins/review-dispatch/index.ts Scaffold asset copy kept in sync
openspec/changes/fetch-pr-review-context/ OpenSpec artifacts: proposal, design, specs, tasks
CHANGELOG.md Added entry for the new tool
.opencode/test/plugin-integration.test.ts Register tool in integration test
.opencode/test/scratch-smoke.test.ts Register tool in smoke test
.gitignore Ignore temp diff artifacts
.uf/dewey/learnings/*.md Dewey learnings from the change workflow

This PR was generated by /uf.finale (AI-assisted).

Proposal, design, specs, and tasks for a new
fetch_pr_review_context tool in the review-dispatch plugin
that combines Steps 0-3.5 of review commands into one
deterministic tool call, eliminating ~15-20s of LLM think
time per review session.
- Implement deterministic PR context fetch: metadata, CI checks,
  diff (0o600 temp file), reviews, inline comments, derived fields
- Use Bun.spawn with argument arrays for shell injection resistance
- Add comprehensive test suite (fetch-pr-review-context.test.ts)
- Update OpenSpec design to document Bun.spawn decision
- Sync scaffold asset copy and register tool in plugin
- Add CHANGELOG entry and Dewey learnings

Assisted-by: mimo-v2.6-pro
Generated with AI assistance (mimo-v2.6-pro)
@jflowers
jflowers requested a review from a team as a code owner October 10, 2026 17:43

@jflowers jflowers left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review: #697 — feat: add fetch_pr_review_context tool to review-dispatch plugin

Summary

This PR adds a fetch_pr_review_context tool that consolidates 5+ sequential gh CLI calls into one deterministic fetch. The implementation uses Bun.spawn with argument arrays for shell injection resistance, persists diffs to $TMPDIR/opencode/pr-<number>-diff.patch with O_EXCL + 0o600, and includes comprehensive error handling with structured warnings. The test suite (1053 lines) covers happy paths, error modes, and concurrency.

Verdict: APPROVE WITH ADVISORIES — Two medium-severity advisories and five low-severity observations. None block merge.

Dispatch Provenance

Agent Verdict
divisor-adversary APPROVE WITH ADVISORIES
divisor-architect APPROVE WITH ADVISORIES
divisor-curator APPROVE
divisor-guard APPROVE WITH ADVISORIES

Findings

Security

  • MEDIUM — $TMPDIR/opencode/ parent dir created with mkdir({recursive:true, mode:0o700}) does not enforce 0o700 on an already-existing directory. On macOS, open('wx') does not imply O_NOFOLLOW, so a symlink race is theoretically possible between unlink() and open('wx'). Blast radius limited since diff content is non-secret PR data. (.opencode/plugins/review-dispatch/index.ts)
  • LOW — runGhCommand reads stdout/stderr without size limits. Time-bounded by 30s AbortSignal.timeout but not size-bounded. Practical risk negligible. (.opencode/plugins/review-dispatch/index.ts)
  • LOW — JSON.parse(raw) calls lack runtime schema validation. Low risk since gh CLI has stable JSON output. (.opencode/plugins/review-dispatch/index.ts)

Architecture

  • LOW — warnings typed as string[] while other arrays use ReadonlyArray<T>. (.opencode/plugins/review-dispatch/index.ts)

Alignment — see inline comments


Artifact: e8fb723e-c3f0-4c11-8aa7-b819d3814c71
This review was generated by /uf.review-pr (AI-assisted).

- [x] 1.2 Implement `fetchPrReviewContext()` function.
Files: `.opencode/plugins/review-dispatch/index.ts`
Sub-tasks:
- [x] 1.2a Validate `gh` CLI availability and auth

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

MEDIUM — intent-drift (divisor-guard)

Sub-task 1.2a references "via BunShell (FR-004)" but the implementation uses Bun.spawn with argument arrays. Sub-task 1.2h references partial_failure error code which was replaced by graceful degradation with warnings. design.md was correctly updated with a "Design evolution note" but tasks.md was not updated to match.

This is a spec artifact drift — when design decision D2 evolved during implementation, the update propagated to design.md and the spec but not to tasks.md.


### III. Observable Quality
**Assessment**: PASS — Returns machine-parseable JSON with
all fields typed. Diff saved to inspectable file on disk.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LOW — intent-drift (divisor-guard)

The "Testability" section states "BunShell calls are injectable" but the implementation uses Bun.spawn, not BunShell. Minor documentation inconsistency — the proposal was written before design decision D2 evolved.


// ── Test infrastructure ──────────────────────────────────────

type BunRuntime = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LOW — convention-consistency (divisor-architect)

originalBunSpawn is declared at module scope but never used — appears to be a leftover from an earlier test approach where Bun.spawn was saved/restored globally. The current pattern uses per-test restore() closures instead. Consider removing this unused declaration.

@jflowers
jflowers merged commit 052473a into unbound-force:main Oct 10, 2026
16 checks passed
@jflowers
jflowers deleted the opsx/fetch-pr-review-context branch November 15, 2026 21:36
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.

1 participant