Skip to content

Feature Request: Dual Chunk Attention for Long Context #245

Feature Request: Dual Chunk Attention for Long Context

Feature Request: Dual Chunk Attention for Long Context #245

name: Claude Copy PR to Main
on:
issue_comment:
types: [created]
jobs:
copy-to-main:
name: Copy PR to Main
if: |
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '/claude copy')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
env:
GH_TOKEN: ${{ secrets.PAT }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.issue.number }}
steps:
- name: Check commenter has write access
env:
COMMENTER: ${{ github.event.comment.user.login }}
run: |
PERMISSION=$(gh api repos/$REPO/collaborators/$COMMENTER/permission --jq .permission)
if [[ "$PERMISSION" != "admin" && "$PERMISSION" != "write" ]]; then
gh pr comment $PR_NUMBER --repo $REPO --body "❌ You do not have write access to use \`/claude copy\`."
exit 1
fi
- name: Check PR is merged and targets non-main
run: |
PR_JSON=$(gh pr view $PR_NUMBER --repo $REPO --json baseRefName,mergedAt)
PR_BASE=$(echo "$PR_JSON" | jq -r .baseRefName)
PR_MERGED=$(echo "$PR_JSON" | jq -r .mergedAt)
if [ "$PR_BASE" = "main" ]; then
gh pr comment $PR_NUMBER --repo $REPO --body "❌ This PR already targets \`main\`. \`/claude copy\` only works on PRs targeting non-main branches."
exit 1
fi
if [ "$PR_MERGED" = "null" ] || [ -z "$PR_MERGED" ]; then
gh pr comment $PR_NUMBER --repo $REPO --body "❌ This PR has not been merged yet. \`/claude copy\` only works on merged PRs."
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Fetch PR head ref from fork
run: |
git fetch origin pull/$PR_NUMBER/head:pr-$PR_NUMBER-head
- name: Run Claude Copy to Main
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
trigger_phrase: "/claude copy"
github_token: ${{ secrets.PAT }}
prompt: |
REPO: ${{ env.REPO }}
PR NUMBER: ${{ env.PR_NUMBER }}
You are a PR copy assistant. Your job is to apply the final changes from a merged PR onto a new branch based on `main` and create a new PR targeting `main`.
The PR's commits originated from a fork and have been fetched locally as the branch: pr-${PR_NUMBER}-head
STEPS:
1. Get the PR details (title, body, and base branch):
gh pr view $PR_NUMBER --repo $REPO --json title,body,baseRefName
2. Configure git for committing (use the svcnvidia-nemo-ci service account since secrets.PAT belongs to it):
git config user.name "svcnvidia-nemo-ci"
git config user.email "svcnvidia-nemo-ci@nvidia.com"
3. Create a new branch from `main`:
git checkout main
git pull origin main
git checkout -b copy-pr-${PR_NUMBER}-to-main
4. Generate a patch of the PR's final changes and apply it:
MERGE_BASE=$(git merge-base origin/<baseRefName> pr-${PR_NUMBER}-head)
git diff $MERGE_BASE pr-${PR_NUMBER}-head | git apply --3way
(Replace <baseRefName> with the actual base branch name from step 1.)
If the apply fails due to merge conflicts:
a. Identify conflicted files: git diff --name-only --diff-filter=U
b. For each conflicted file, read its contents to see the conflict markers
c. Resolve the conflicts by favoring the `main` branch side when there is a genuine
conflict between the two sides. The goal is to bring the PR's changes into main
without overriding what is already on main.
d. Stage the resolved files: git add <file>
5. Commit the changes:
git add -A
git commit -m "Copy PR #${PR_NUMBER} to main"
6. Push the new branch:
git push origin copy-pr-${PR_NUMBER}-to-main
7. Create a new PR targeting `main`:
gh pr create --repo $REPO \
--base main \
--head copy-pr-${PR_NUMBER}-to-main \
--title "[Copy to main] <original PR title>" \
--body "🤖 **This PR was auto-generated by Claude** via the \`/claude copy\` command.\n\nCherry-picked from #${PR_NUMBER}.\n\n---\n\n<original PR body>"
8. Comment on the original PR with a link to the newly created PR.
IMPORTANT:
- When resolving merge conflicts, favor `main` over the non-main branch. Do not override changes already on main.
- Do NOT force push.
claude_args: |
--allowedTools "Bash(git:*),Bash(gh:*),Read,Edit"
--model "claude-opus-4-6"