diff --git a/.github/workflows/respond-to-cubic-dev-ai.yml b/.github/workflows/respond-to-cubic-dev-ai.yml index 4c1db1a5f..5590fe31e 100644 --- a/.github/workflows/respond-to-cubic-dev-ai.yml +++ b/.github/workflows/respond-to-cubic-dev-ai.yml @@ -5,7 +5,7 @@ on: types: [created] permissions: - contents: read + contents: write pull-requests: write issues: write @@ -25,25 +25,88 @@ jobs: echo "contains_mention=false" >> $GITHUB_OUTPUT fi - - name: Get comment content + - name: Checkout PR branch if: steps.check-mention.outputs.contains_mention == 'true' - id: comment-content - run: | - # Store the comment body for debugging/logging - echo "Comment mentioning @continuedev from ${{ github.event.comment.user.login }}:" - echo "${{ github.event.comment.body }}" + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 - - name: Respond to @continuedev mention + - name: Get PR information if: steps.check-mention.outputs.contains_mention == 'true' + id: pr-info + uses: actions/github-script@v7 + with: + script: | + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + core.setOutput('head_ref', pr.head.ref); + core.setOutput('head_sha', pr.head.sha); + return pr; + + - name: Checkout PR branch + if: steps.check-mention.outputs.contains_mention == 'true' + run: | + git checkout ${{ steps.pr-info.outputs.head_ref }} + + - name: Setup Node.js + if: steps.check-mention.outputs.contains_mention == 'true' + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies and build CLI + if: steps.check-mention.outputs.contains_mention == 'true' + run: | + npm ci + npm run build + + - name: Start remote session + if: steps.check-mention.outputs.contains_mention == 'true' + id: remote-session + env: + CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} + run: | + # Create the prompt for the remote session + PROMPT="Please help with the following request from @${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}: + + ${{ github.event.comment.body }} + + Please analyze the current PR, understand the request, implement the necessary changes, and commit them to this branch." + + # Start remote session and capture JSON output + SESSION_OUTPUT=$(node dist/index.js remote -s "$PROMPT") + echo "Raw session output: $SESSION_OUTPUT" + + # Extract URL from JSON output + SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty') + + if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then + echo "Failed to extract session URL from output: $SESSION_OUTPUT" + exit 1 + fi + + echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT + echo "✅ Started remote session: $SESSION_URL" + + - name: Comment with session URL + if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url uses: actions/github-script@v7 with: script: | const commentBody = `👋 Thanks for mentioning @continuedev, @${{ github.event.comment.user.login }}! - I've received your comment: + I've started a remote session to help with your request: > ${{ github.event.comment.body }} - Your input has been acknowledged and will be reviewed by the team.`; + **🔗 Remote Session:** ${{ steps.remote-session.outputs.session_url }} + + The AI assistant is now working on your request and will make any necessary changes to this PR. You can follow the progress in the remote session link above.`; await github.rest.issues.createComment({ owner: context.repo.owner, @@ -52,8 +115,9 @@ jobs: body: commentBody }); - - name: Log acknowledgement + - name: Log session details if: steps.check-mention.outputs.contains_mention == 'true' run: | - echo "✅ Successfully acknowledged comment mentioning @continuedev from ${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}" + echo "✅ Successfully started remote session for comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}" + echo "Session URL: ${{ steps.remote-session.outputs.session_url }}" echo "Original comment: ${{ github.event.comment.body }}"