diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 864cbc6..b38535f 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -11,12 +11,12 @@ on: types: [submitted] jobs: + # Standard Claude trigger - responds to @claude mentions claude: if: | (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || - (github.event_name == 'issues' && github.event.action == 'labeled' && github.event.label.name == 'claude-working') || (github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'assigned') && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) runs-on: ubuntu-latest permissions: @@ -39,16 +39,56 @@ jobs: CRON_SECRET: ${{ secrets.CRON_SECRET }} with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} - - # Allow Claude to read CI results and manage issues/PRs additional_permissions: | actions: read - # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. - # prompt: 'Update the pull request description to include a summary of changes.' + # Label-triggered Claude - for tool-request pipeline + claude-label-trigger: + if: github.event_name == 'issues' && github.event.action == 'labeled' && github.event.label.name == 'claude-working' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + issues: write + id-token: write + actions: read + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 - # Optional: Add claude_args to customize behavior and configuration - # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md - # or https://code.claude.com/docs/en/cli-reference for available options - # claude_args: '--allowed-tools Bash(gh pr:*)' + - name: Get prompt from issue comments + id: get-prompt + uses: actions/github-script@v7 + with: + script: | + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + per_page: 100 + }); + // Find the most recent comment with @claude + const claudeComments = comments.data.filter(c => c.body.includes('@claude')); + if (claudeComments.length > 0) { + const latestComment = claudeComments[claudeComments.length - 1]; + core.setOutput('prompt', latestComment.body); + core.setOutput('found', 'true'); + } else { + core.setOutput('found', 'false'); + core.setFailed('No @claude comment found in issue'); + } + + - name: Run Claude Code + if: steps.get-prompt.outputs.found == 'true' + uses: anthropics/claude-code-action@v1 + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + CRON_SECRET: ${{ secrets.CRON_SECRET }} + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + additional_permissions: | + actions: read + prompt: ${{ steps.get-prompt.outputs.prompt }}