Skip to content

Add reusable review bot framework and agent-mode design reviewer - #208

Merged
jwbron merged 8 commits into
mainfrom
egg/review-bot-framework
Feb 7, 2026
Merged

jwbron merged 8 commits into
mainfrom
egg/review-bot-framework

Conversation

@james-in-a-box

@james-in-a-box james-in-a-box Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Creates an agent-mode design review bot that enforces guidelines from docs/guides/agent-mode-design.md
  • Adds a reusable GitHub workflow (reusable-review.yml) for common review bot operations
  • Simplifies caller workflows by moving should-run logic into the reusable workflow

Key Components

action/build-agent-mode-design-review-prompt.sh

Specialized review bot that checks for:

  1. Pre-fetching data the agent could fetch itself
  2. Requiring structured output for human-facing content
  3. Post-processing pipelines that parse agent output
  4. Specifying "how" instead of "what"
  5. Constraints beyond what the sandbox enforces

.github/workflows/reusable-review.yml

Reusable workflow with inputs for pr_number, prompt_script, bot_name, timeout, and optional is_draft, pr_title, event_name for skip logic. Handles:

  • Draft PR and [skip-review] detection (via should-run job)
  • PR metadata fetching
  • Bot-specific review marker detection
  • Review dismissal
  • Prompt building and egg execution

.github/workflows/on-pull-request.yml and on-pull-request-agent-mode-design.yml

Simplified caller workflows that pass PR context to the reusable workflow and let it handle the should-run logic.

Issue: #207

Test plan

  • All 21 action tests pass (12 for build-review-prompt.sh + 9 for build-agent-mode-design-review-prompt.sh)
  • Shellcheck passes on new bash scripts
  • Ruff passes on new Python tests
  • Verify reusable workflow works in GitHub Actions (requires manual test after merge)

Authored-by: egg

This change introduces a reusable framework for building specialized
review bots and creates a new agent-mode design review bot that enforces
the guidelines from docs/guides/agent-mode-design.md.

Key changes:
- review-bot-base.sh: Reusable bash module providing common functions
  for fetching rules, loading conventions, handling re-reviews, and
  building prompts
- build-agent-mode-design-review-prompt.sh: New specialized review bot
  that checks for agent-mode design anti-patterns (pre-fetching,
  structured output for humans, post-processing pipelines, etc.)
- reusable-review.yml: Reusable GitHub workflow that handles PR
  metadata fetching, review marker detection, and bot execution
- Refactored build-review-prompt.sh and on-pull-request.yml to use
  the new framework

Issue: #207

Authored-by: egg
@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg is investigating the Lint check failure...

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box it seems that this pr itself might not align with the guidelines in this document: https://github.com/jwbron/egg/blob/main/docs/guides/agent-mode-design.md. Should we simplify the reusable review bot workflow?

Pass PR title through an environment variable instead of directly
interpolating in the inline script. This fixes two issues:
- SC2193 shellcheck warning about string comparison
- Security: avoids script injection from untrusted PR title input

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg autofix completed. View run logs

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Agent-Mode Design Analysis

@jwbron — you're right. This PR has alignment issues with the guidelines in docs/guides/agent-mode-design.md:

Issues Found

1. Pre-fetching in reusable-review.yml (lines 58-136)

The workflow pre-fetches PR metadata and scans all reviews/comments to find the last review commit. Per guideline #1, this is problematic — the agent could fetch this via gh pr view and gh api itself.

2. Procedural instructions in review-bot-base.sh (lines 78-84)

The build_rereview_preamble() tells the agent how to re-review:

1. Use `git diff ${LAST_REVIEW_COMMIT}..HEAD`...
2. Use `gh pr view ${PR_NUMBER} --comments`...

Per guideline #4, this should specify "what" not "how." The agent should decide its own approach.

3. Framework adds indirection for marginal benefit

Both prompt scripts are ~50 lines. The shared framework adds complexity without reducing meaningful duplication.

What's Aligned ✓

The core prompts are good — they describe outcomes, not procedures, and the agent posts reviews directly.

Recommended Simplification

Remove pre-fetching entirely. The workflow becomes:

- name: Run egg review
  uses: jwbron/egg/action@main
  with:
    prompt: |
      Review PR #${{ inputs.pr_number }} in ${{ github.repository }}.
      
      Read docs/guides/agent-mode-design.md for context on what to check.
      Post your review on the PR.

The agent can:

  • Fetch PR metadata itself via gh pr view
  • Check its own previous reviews via gh api
  • Decide what context it needs

This would eliminate review-bot-base.sh entirely — each bot becomes a simple prompt file.

Should I implement this simplification?

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box, yes, move forward with your suggestion in #208 (comment).

Remove pre-fetching and framework indirection that violated agent-mode
design principles. The agent can fetch PR metadata, previous reviews,
and context itself via `gh` commands.

Changes:
- Remove review-bot-base.sh framework and prompt builder scripts
- Inline simple prompts directly in workflow files
- Remove pre-fetching of PR metadata and review marker scanning
- Remove related tests (32 tests removed, 0 remaining)

The workflows now pass minimal orientation context (PR number, repo)
and let the agent decide what it needs.

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Simplification Complete

I've simplified the review bot workflows per the agent-mode design guidelines. Here's what changed:

Removed (1,161 lines deleted)

  • action/review-bot-base.sh — Framework that added indirection for marginal benefit
  • action/build-review-prompt.sh — Prompt builder with procedural instructions
  • action/build-agent-mode-design-review-prompt.sh — Specialized prompt builder
  • All 32 related tests

Simplified reusable-review.yml

  • Removed pre-fetching of PR metadata and review marker scanning (lines 58-136)
  • Removed prompt_script input — prompts are now inline
  • Removed skip_dismiss option — unnecessary with simplified approach
  • Workflow is now 103 lines (was 201)

Updated calling workflows

Now pass simple, declarative prompts:

Code review (on-pull-request.yml):

Review PR #N in repo/name.

Focus on security issues, correctness, and code quality. 
Skip style issues that linters catch.

If this repo has .egg/review-rules.md, follow those rules. 
Otherwise use your judgment.

Post your review on the PR.

Agent-mode design review (on-pull-request-agent-mode-design.yml):

Review PR #N in repo/name.

Read docs/guides/agent-mode-design.md for context on what to check.

Post your review on the PR.

The agent can:

  • Fetch PR metadata itself via gh pr view
  • Check its own previous reviews via gh api
  • Decide what context it needs

This eliminates the violations identified in the earlier analysis: no more pre-fetching, no more procedural instructions specifying "how" instead of "what."

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box I think the last change was an overcorrection. The re-review logic is important, for example. We need to keep that. We should have a shared base review bot that keeps the functionality of the existing review bot. The new agent-mode design reviewer should use that base.

The previous simplification removed too much functionality. This commit
restores the re-review detection and context while aligning with
agent-mode design principles:

- Restored build-review-prompt.sh with declarative re-review context
  (tells agent "what" to focus on, not "how" to do it)
- Restored last-review-commit detection in reusable-review.yml
- Restored dismiss-previous-reviews step
- Added review_focus parameter for specialized review bots
- Agent-mode design reviewer now uses shared base with focus parameter

The re-review prompt provides context (last review commit, focus areas)
but lets the agent decide how to check for changes and verify feedback.

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Restored Re-Review Logic

I've restored the re-review functionality while keeping it aligned with agent-mode design principles.

What's Restored

  1. action/build-review-prompt.sh - Builds review prompts with re-review context
  2. Last review detection - Scans for <!-- egg-automated-review bot=<name> commit=<sha> --> markers in reviews/comments
  3. Review dismissal - Supersedes previous bot reviews when new review starts
  4. Trusted checkout security - Builds prompt from main branch, not PR code

Key Design Change

The original re-review instructions were procedural ("how"):

1. Use `git diff ${LAST_REVIEW_COMMIT}..HEAD`...
2. Use `gh pr view ${PR_NUMBER} --comments`...

The new re-review instructions are declarative ("what"):

## Re-Review Context

This is a **re-review**. You previously reviewed this PR at commit `abc123def`.

- Focus on changes since your last review
- Check whether previous feedback was addressed
- Don't repeat comments on unchanged code

The agent can decide how to check the diff and verify feedback was addressed.

Shared Base

Both workflows now use reusable-review.yml with a review_focus parameter:

  • Standard review: no focus, uses default review rules
  • Agent-mode design review: review_focus: agent-mode-design, checks docs/guides/agent-mode-design.md

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box there's still a lot of logic that was removed from the existing review bot workflow. This was needed! Let's restore that and keep the workflow as-is other than making it reusable.

james-in-a-box Bot pushed a commit that referenced this pull request Feb 7, 2026
Addresses feedback from PR #208 where the agent overcorrected when
aligning a workflow with the design doc, removing useful functionality
like re-review detection. The document was too prescriptive, leading to
rigid interpretation rather than balanced implementation.

Key changes:
- Add upfront disclaimer that these are guidelines, not absolute rules
- Clarify that providing useful context (re-review info, metadata) is
  fine - the anti-pattern is constraining, not informing
- Add "Applying These Guidelines" section emphasizing preservation of
  valuable functionality and incremental refactoring
- Rename "Anti-Patterns to Avoid" to "Anti-Patterns vs. Good Patterns"
- Add examples of good patterns: shared infrastructure, composition
- Soften implementation checklist language from "reconsider" to
  "use judgment"

Authored-by: egg
Restores the detailed procedural instructions in build-review-prompt.sh
that were removed in the previous simplification. The re-review prompts
now include specific git diff and gh pr view commands as in the original.

Changes:
- Restore build-review-prompt.sh to match original with procedural re-review
  instructions (git diff, gh pr view --comments)
- Add concurrency group to reusable-review.yml
- Replace REVIEW_FOCUS parameter with prompt_script input for flexibility
- Create separate build-agent-mode-design-review-prompt.sh for specialized
  reviews
- Restore tests for build-review-prompt.sh (12 tests)
- Add tests for build-agent-mode-design-review-prompt.sh (9 tests)

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Restored Workflow Logic

I've restored the review bot workflow logic while keeping it reusable. Here's what changed:

Restored in build-review-prompt.sh

The original procedural re-review instructions are back:

1. **Review only new changes**: Use `git diff ${LAST_REVIEW_COMMIT}..HEAD`...
2. **Check previous feedback**: Use `gh pr view ${PR_NUMBER} --comments`...
3. **Verify issues addressed**: Confirm that any concerns from your previous review have been addressed.
4. **Focus on the delta**: Your new review should focus on the changes since...

Restored in reusable-review.yml

  • Concurrency group: egg-${{ inputs.bot_name }}-${{ inputs.pr_number }} with cancel-in-progress
  • prompt_script input: Replaced REVIEW_FOCUS with prompt_script for flexibility — allows each bot to use its own prompt builder

New Agent-Mode Design Prompt Builder

Created action/build-agent-mode-design-review-prompt.sh as a separate script for the agent-mode design reviewer. It includes the same procedural re-review structure but focuses on agent-mode design principles.

Tests

  • Restored 12 tests for build-review-prompt.sh
  • Added 9 tests for build-agent-mode-design-review-prompt.sh
  • All 21 tests pass

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box much better. Now update the action names to be a bit more relevant to what the actions do.

jwbron added a commit that referenced this pull request Feb 7, 2026
* Refine agent-mode design guidelines for balanced implementation

Addresses feedback from PR #208 where the agent overcorrected when
aligning a workflow with the design doc, removing useful functionality
like re-review detection. The document was too prescriptive, leading to
rigid interpretation rather than balanced implementation.

Key changes:
- Add upfront disclaimer that these are guidelines, not absolute rules
- Clarify that providing useful context (re-review info, metadata) is
  fine - the anti-pattern is constraining, not informing
- Add "Applying These Guidelines" section emphasizing preservation of
  valuable functionality and incremental refactoring
- Rename "Anti-Patterns to Avoid" to "Anti-Patterns vs. Good Patterns"
- Add examples of good patterns: shared infrastructure, composition
- Soften implementation checklist language from "reconsider" to
  "use judgment"

Authored-by: egg

* Remove specific examples from guidelines section

Generalizes the guidance in the "Applying These Guidelines" section
by removing explicit references to re-review detection. The principles
are clearer without tying them to specific implementation examples.

Authored-by: egg

---------

Co-authored-by: jwbron <8340608+jwbron@users.noreply.github.com>
Update step names in review bot workflows to better describe what each
step does:

- "Generate bot token" → "Generate GitHub App token for bot"
- "Fetch PR metadata" → "Fetch PR head branch and repo"
- "Get last review info" → "Find last bot review commit for re-review context"
- "Dismiss previous bot reviews" → "Dismiss stale bot reviews"
- "Build review prompt" → "Build review prompt from trusted main branch"
- "Checkout PR branch" → "Checkout PR code for review"
- "Run egg review" → "Run egg to review and post feedback"
- "Post status comment" → "Post workflow run status to PR"
- "Check conditions" → "Check if PR is ready for review"

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated Workflow Step Names

I've updated the step names across the review workflows to better describe what each step does:

Before After
Generate bot token Generate GitHub App token for bot
Fetch PR metadata Fetch PR head branch and repo
Get last review info Find last bot review commit for re-review context
Dismiss previous bot reviews Dismiss stale bot reviews
Build review prompt Build review prompt from trusted main branch
Checkout PR branch Checkout PR code for review
Run egg review Run egg to review and post feedback
Post status comment Post workflow run status to PR
Check conditions Check if PR is ready for review

These names now clearly indicate the purpose of each step in the workflow run logs.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box review this pr

@james-in-a-box james-in-a-box Bot 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.

Code Review

I've reviewed the changes in this PR. The review bot framework looks well-structured overall, but there are a few issues to address.

Issues

1. Missing executable permission on build-agent-mode-design-review-prompt.sh

The new script at action/build-agent-mode-design-review-prompt.sh is missing the executable bit:

-rw-r--r-- 1 egg egg 4092 action/build-agent-mode-design-review-prompt.sh

Compare to build-review-prompt.sh which has it:

-rwxr-xr-x 1 egg egg 4635 action/build-review-prompt.sh

While bash script.sh works without the executable bit, this is inconsistent with the other scripts in the action/ directory. Consider adding chmod +x to make it consistent.

2. Unrelated changes to self-improvement.yml

This PR includes significant changes to the self-improvement workflow that don't appear to be related to the review bot framework:

  • The original workflow used egg (the agent) to analyze logs and create GitHub issues for recurring problems
  • The new version replaces this with a Python script that only generates static reports
  • The issues: write permission was removed
  • The dry_run input option was removed
  • The agent-based analysis with intelligent issue creation was replaced with basic log collection

This changes the fundamental purpose of the self-improvement workflow. If this is intentional, it should be in a separate PR. If it was accidental, the original behavior should be restored.

3. Inaccurate test count in PR description

The PR description states "All 32 action tests pass (12 existing + 20 new)" but the actual counts are:

  • 21 action tests total (12 for build-review-prompt.sh + 9 for build-agent-mode-design-review-prompt.sh)
  • 20 self-improvement tests

This is a minor documentation issue.

Positive Observations

  • The reusable workflow structure (reusable-review.yml) is clean and reduces duplication
  • The specialized review workflows (on-pull-request.yml, on-pull-request-agent-mode-design.yml) make good use of the reusable workflow
  • Tests for the new prompt builder are comprehensive
  • Shellcheck passes on the bash scripts
  • The concurrency groups prevent duplicate review runs

Recommendation

Please address the executable permission issue and clarify whether the self-improvement workflow changes are intentional (and if so, move them to a separate PR).

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@james-in-a-box james-in-a-box Bot 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.

Code Review

CI: All checks passing.

Issues

1. Missing executable permission on build-agent-mode-design-review-prompt.sh

The new script is created with mode 100644 while the existing build-review-prompt.sh is 100755. The workflow runs it via bash ${{ inputs.prompt_script }} so it works, but it's inconsistent with the rest of action/. This was flagged in the earlier automated review and not addressed.

2. Outdated PR description

The PR description still references components that were removed during review iterations:

  • action/review-bot-base.sh (removed)
  • fetch_bot_rules(), load_conventions(), build_rereview_preamble(), build_bot_prompt() (removed)
  • "All 32 action tests pass (12 existing + 20 new)" — actual count is 21 (12 + 9)

The description should be updated to reflect the current state of the PR.

3. Duplicated should-run job

Both on-pull-request.yml and on-pull-request-agent-mode-design.yml contain identical should-run logic (skip drafts, skip [skip-review] in title, always run for workflow_dispatch). This could be moved into reusable-review.yml to avoid duplication, especially since adding a third review bot would mean triplicating it.

4. prompt_script chicken-and-egg on first run

The reusable workflow checks out main (for security) then runs bash ${{ inputs.prompt_script }}. The agent-mode design workflow passes action/build-agent-mode-design-review-prompt.sh, which won't exist on main until this PR is merged. Any PR matching the paths filter that triggers this workflow before merge will fail at the "Build review prompt" step. This resolves itself after merge, but may cause a spurious failure on this PR or any concurrent PRs.

Observations (non-blocking)

  • Bot-specific marker regex in reusable-review.yml is a good improvement over the original generic pattern — each bot now only finds its own review markers.
  • Concurrency groups are correctly scoped per bot name (egg-${{ inputs.bot_name }}-${{ inputs.pr_number }}), preventing cross-bot cancellation.
  • Unconditional PR metadata fetch: The original workflow conditionally fetched PR metadata only for workflow_dispatch. The reusable workflow fetches unconditionally, which is correct since github.event.pull_request context isn't passed through workflow_call. Costs one extra API call on pull_request events but is the right approach.
  • The test coverage for the new prompt builder is solid — covers initial review, re-review, required variables, and edge cases.

Recommendation

Fix the executable permission and update the PR description. The should-run duplication and first-run issue are worth discussing but not blockers.

— Authored by egg

@jwbron

jwbron commented Feb 7, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box address the above feedback

- Add executable permission to build-agent-mode-design-review-prompt.sh
  for consistency with other scripts in action/
- Move duplicated should-run logic into reusable-review.yml, eliminating
  code duplication across caller workflows
- Simplify on-pull-request.yml and on-pull-request-agent-mode-design.yml
  to only pass inputs to the reusable workflow

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Addressed Feedback

1. Executable permission — Added chmod +x to build-agent-mode-design-review-prompt.sh for consistency with other scripts in action/.

2. Duplicated should-run logic — Moved into reusable-review.yml as a new job. The reusable workflow now accepts is_draft, pr_title, and event_name inputs to handle the skip logic internally. This eliminates the duplicate code from both caller workflows.

3. PR description — Updated to reflect the current state: removed references to review-bot-base.sh (which was removed in previous iterations), and corrected the test count to 21 (12 + 9).

4. Regarding the prompt_script chicken-and-egg issue — This is noted in the original review as non-blocking. The workflow checks out main for security reasons, so any new prompt_script won't exist until after merge. This resolves itself after the first merge and is a known limitation of the security model.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@jwbron
jwbron merged commit 34e9839 into main Feb 7, 2026
8 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.

1 participant