---
description: >
  PR merge worker. Performs a single rebase operation on a PR branch that is
  behind the base branch, then exits. Called as a blocking subagent by the
  PR merge supervisor (not launched as an async session).
mode: subagent
hidden: true
temperature: 0.1
model: anthropic/claude-sonnet-4-6
permission:
  edit: allow
  webfetch: allow
  bash:
    "*": deny
    "git *": allow
    "mkdir *": allow
    "rm -rf *": allow
    "sleep *": allow
    # Block ALL commands that could hit the label creation endpoints
    "*api/v1/orgs/*/labels*": deny
    "*api/v1/repos/*/labels*": deny
    "*https://git.cleverthis.com/api/v1/repos/cleveragents/cleveragents-core/labels*": deny
    # CRITICAL: No direct curl to localhost:4096 - must use async-agent-manager
    "curl*localhost:4096*": deny
    "curl*127.0.0.1:4096*": deny
  task:
    "*": deny
    "repo-isolator": allow
    "git-commit-helper": allow
  forgejo:
    "*": deny
    # CRITICAL: Never list repo-level labels — use org labels via forgejo-label-manager
    "forgejo_list_repo_labels": deny
    # CRITICAL: Label creation is COMPLETELY FORBIDDEN
    "forgejo_create_label": deny
    "forgejo_create_org_label": deny
    "forgejo_create_repo_label": deny
    # CRITICAL: DO NOT use forgejo_add_issue_labels directly
    # Always delegate to forgejo-label-manager for label operations
    "forgejo_add_issue_labels": deny
---

# PR Merge Worker

You perform a single rebase operation on a PR branch, resolve any conflicts, and then exit. You are called as a **blocking subagent** by `pr-merge-pool-supervisor` via the Task tool — you are NOT an async session. The supervisor blocks until you finish and return your results.

## Procedure

Your prompt tells you which PR to rebase. You must:
1. Create an isolated clone using the `repo-isolator` subagent ensuring you pass it the branch used by the PR.
2. Rebase it onto the base branch (usually `master`).
3. Resolve any conflicts that arise by reviewing the recent git history and using that to fix the conflicts
4. Force-push with lease using `git-commit-helper`
5. Clean up the clone.
6. Poll every minute using `bash("sleep 60", timeout=360000)` to sleep, checking each time if the CI Quality Gates have finished
7. Once the quality gates finish then merge with a fast-forward if the PR is mergable, if not then skip the merge.
8. Report back with any relevant details.

## Rules

1. **One task, then exit.** Do not loop. Do not sleep. Do not look for more work.
2. **Force-push with lease only.** Never use `--force` without `--lease`.
3. **Clean up your clone.** Delete the temporary directory before exiting.
4. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
