diff --git a/.github/workflows/gemini-dispatch.yml b/.github/workflows/gemini-dispatch.yml index d965d4552..160eee5dd 100644 --- a/.github/workflows/gemini-dispatch.yml +++ b/.github/workflows/gemini-dispatch.yml @@ -99,6 +99,8 @@ jobs: core.setOutput('additional_context', additionalContext); } else if (request.startsWith("@gemini-cli /triage")) { core.setOutput('command', 'triage'); + } else if (request.startsWith("@gemini-cli /fix")) { + core.setOutput('command', 'fix'); } else if (request.startsWith("@gemini-cli")) { core.setOutput('command', 'invoke'); const additionalContext = request.replace(/^@gemini-cli/, '').trim(); @@ -151,6 +153,18 @@ jobs: additional_context: '${{ needs.dispatch.outputs.additional_context }}' secrets: 'inherit' + fix: + needs: 'dispatch' + if: |- + ${{ needs.dispatch.outputs.command == 'fix' }} + uses: './.github/workflows/gemini-issue-fixer.yml' + permissions: + contents: 'write' + id-token: 'write' + issues: 'write' + pull-requests: 'write' + secrets: 'inherit' + invoke: needs: 'dispatch' if: |- diff --git a/.github/workflows/gemini-issue-fixer.yml b/.github/workflows/gemini-issue-fixer.yml new file mode 100644 index 000000000..366e94435 --- /dev/null +++ b/.github/workflows/gemini-issue-fixer.yml @@ -0,0 +1,197 @@ +name: '🧙 Gemini Issue Fixer' + +on: + workflow_call: + +concurrency: + group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ github.event.issue.number }}' + cancel-in-progress: true + +defaults: + run: + shell: 'bash' + +jobs: + create-pr: + timeout-minutes: 30 + runs-on: 'ubuntu-latest' + permissions: + contents: 'write' # Enable reading and modifying code + id-token: 'write' # Enable minting an identity token + issues: 'write' # Enable updating issues, such as posting a comment + pull-requests: 'write' # Enable creating pull requests + + steps: + # Mint a token so that the comments show up as gemini-cli instead of github-actions. + - name: 'Mint identity token' + id: 'mint_identity_token' + if: |- + ${{ vars.APP_ID }} + uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 + with: + app-id: '${{ vars.APP_ID }}' + private-key: '${{ secrets.APP_PRIVATE_KEY }}' + permission-contents: 'write' + permission-issues: 'write' + permission-pull-requests: 'write' + + - name: 'Checkout repository' + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 + + - name: 'Run Gemini PR Create' + uses: 'google-github-actions/run-gemini-cli@main' # ratchet:exclude + id: 'gemini_pr_create' + env: + GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN }}' + REPOSITORY: '${{ github.repository }}' + ISSUE_NUMBER: '${{ github.event.issue.number }}' + ISSUE_TITLE: '${{ github.event.issue.title }}' + ISSUE_BODY: '${{ github.event.issue.body }}' + BRANCH_NAME: 'gemini-fix-${{ github.event.issue.number }}' + with: + gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' + gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}' + gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}' + gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}' + gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' + use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' + use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' + settings: |- + { + "debug": ${{ fromJSON(env.DEBUG || env.ACTIONS_STEP_DEBUG || false) }}, + "maxSessionTurns": 200, + "mcpServers": { + "github": { + "command": "docker", + "args": [ + "run", + "-i", + "--rm", + "-e", + "GITHUB_PERSONAL_ACCESS_TOKEN", + "ghcr.io/github/github-mcp-server" + ], + "env": { + "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}" + } + } + }, + "telemetry": { + "enabled": ${{ vars.GOOGLE_CLOUD_PROJECT != '' }}, + "target": "gcp" + } + } + prompt: |- + + + You are an expert software engineer. Your task is to resolve a GitHub issue by understanding the problem, implementing a robust solution, and creating a pull request. You are meticulous, adhere to project standards, and communicate your plan clearly. + + + + This information is from the GitHub event that triggered your execution. Do not fetch this data again; use it as the primary source of truth for the task. + + + ${{ github.event_name }} + ${{ github.triggering_actor }} + + ${{ env.REPOSITORY }} + ${{ env.ISSUE_NUMBER }} + The title exists in the ISSUE_TITLE environment variable. Run `echo $ISSUE_TITLE` to fetch it. + The title exists in the ISSUE_BODY environment variable. Run `echo $ISSUE_BODY` to fetch it. + + + + + Follow these steps sequentially to resolve the issue. + + + The issue's title and body are stored in the ISSUE_TITLE and ISSUE_BODY environment variables. Read them with `echo $ISSUE_TITLE` and `echo $ISSUE_BODY`. + + + The initial context provided to you includes a file tree. If you see a `GEMINI.md` or `CONTRIBUTING.md` file, use the GitHub MCP `get_file_contents` tool to read it first. This file may contain critical project-specific instructions, such as commands for building, testing, or linting. + + + 1. Use the GitHub MCP `update_issue` tool to add a "status/gemini-cli-fix" label to the issue. + 2. Use the `gh issue comment` CLI tool command to post an initial comment. In this comment, you must: + - State the problem in your own words. + - Briefly describe the current state of the relevant code. + - Present a clear, actionable TODO list (using markdown checklists `[ ]`) outlining your plan to fix the issue. + + + Use the `git` CLI tool to checkout a new branch for your work. Name it `${{ env.BRANCH_NAME }}`. The command should be: `git checkout -b ${{ env.BRANCH_NAME }}`. + + + Use the GitHub MCP `create_branch` tool to create a new branch for your work. Name it `${{ env.BRANCH_NAME }}`. + + + Use tools, like the GitHub MCP `search_code` and GitHub MCP `get_file_contents` tools, to explore the codebase and implement the necessary code changes. As your plan evolves, you must keep the TODO list in your initial comment updated. To do this, use the `gh` command-line tool directly, as the MCP toolset does not support editing comments. Use the following command: `gh issue comment --edit-last --body "..."` + + + Follow the project-specific instructions from `GEMINI.md` or `CONTRIBUTING.md` to run builds, linters, and tests. Ensure your changes have not introduced any regressions. + + + Commit the changes to the branch `${{ env.BRANCH_NAME }}`, using the Conventional Commits specification for commit messages. Use the `git` CLI tool, such as with `git status` to see changed/added/removed files, `git diff` to see changes, `git add .` to stage all changes files, and `git commit -m ''`. + + + Once the solution is fully implemented and verified, use the GitHub MCP `create_pull_request` tool to open a PR. The PR description should clearly link to the issue and summarize the changes you made. + + + Once you have created a pull request, use the GitHub MCP `list_pull_requests` tool to get the pull request number. + + + Use the `gh issue comment --edit-last` CLI tool command to edit your initial comment. You should update the markdown checklist in the initial comment to check the boxes of what is complete with `[x]`, and update the plan if any changes occured - such as skipping or adding a step. Also, suffix a link to your pull request, but just mentioning `#`, and GitHub will automatically link it. + + + + + Be Respectful: Your communication should always be constructive and professional. + Be Actionable: Your feedback and code should be specific and clear. + Follow Conventions: Adhere strictly to the existing coding style and patterns in the repository. + Use Tools: Rely on the provided tools for all interactions with the repository. Do not guess file contents or state. + Handle Shell Variables Safely: When defining or using variables in shell commands, ensure they are properly quoted to prevent errors. + If something prevents you from fixing the issue, such as a permissions issue, inform the user in your comment on the issue why you cannot complete the task. If you must inform the user of a limitation, use the `gh issue comment --edit-last` CLI tool command to edit your initial comment. Only create a pull request if it will fix the issue. + + + + This is an example of the desired thought process and the initial comment you should post to the GitHub issue. + + + Create Mortgage Paydown Calculator Page + + We need a new page for a mortgage paydown calculator. It should follow the style and functionality of our other calculator pages. + + + + + 1. **Goal:** The user wants a new mortgage calculator page that matches existing pages. + 2. **Action: Add Label:** First, I must label the issue as in-progress. `update_issue(add_label: "status/gemini-cli-fix")`. + 3. **Initial Context:** The file tree shows `CreditPaydown.tsx` and `StudentLoan.tsx`. This suggests a component-based frontend structure, likely React. There is also a `GEMINI.md`. + 4. **Action: Read `GEMINI.md`:** `get_file_contents('GEMINI.md')`. The file says to use `npm install`, `npm run test`, and `npm run build`. + 5. **Action: Investigate existing code:** `get_file_contents('CreditPaydown.tsx')`. I see it uses React, TypeScript, and Tailwind CSS. The logic is self-contained. + 6. **Plan Formation:** I will create a new file, `MortgageCalculator.tsx`, based on the structure of the existing calculator components. I will implement the mortgage calculation logic and ensure the UI matches. Then I will add a unit test and verify the project builds. + 7. **Formulate Comment:** Based on my plan, I will now draft the comment for the GitHub issue. + + + Hello! I'm here to help with the new Mortgage Paydown Calculator page. + + **Problem** + The goal is to create a new page that calculates a mortgage paydown schedule, ensuring its design and functionality are consistent with the existing calculator pages on the site. + + **Current State** + The repository already contains similar components for a `Credit PayDown Calculator` and a `Student Loan Pay Down Calculator`. These components are built with React, TypeScript, and Tailwind CSS, and contain self-contained business logic. + + **My Plan** + - [ ] Create a new file `src/pages/MortgageCalculator.tsx` modeled after the existing calculator components. + - [ ] Implement the user interface for inputting mortgage details (principal, interest rate, term). + - [ ] Implement the backend logic for the paydown calculation. + - [ ] Add a new unit test file to validate the calculation logic. + - [ ] Ensure the entire project builds successfully with `npm run build`. + - [ ] Ensure all tests pass with `npm run test`. + - [ ] Commit the changes to my feature branch. + - [ ] Create the final pull request for review. + + I will start working on this now and keep this checklist updated with my progress. + + + +