From 136950f4bd6d14e544bbd415ed313f7842a9b9a2 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Mon, 10 Mar 2025 11:55:07 -0400 Subject: [PATCH 1/4] feat: add GitHub Action for issue comment commands Implements a GitHub Action that responds to /mycoder pr and /mycoder plan commands in issue comments. This allows users to trigger MyCoder directly from GitHub issues. Closes #162. --- .github/workflows/issue-comment.yml | 59 +++++++++++++++++++++++++++++ README.md | 9 +++++ docs/github-comment-commands.md | 55 +++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 .github/workflows/issue-comment.yml create mode 100644 docs/github-comment-commands.md diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml new file mode 100644 index 0000000..9ebd47e --- /dev/null +++ b/.github/workflows/issue-comment.yml @@ -0,0 +1,59 @@ +name: MyCoder Issue Comment Action + +on: + issue_comment: + types: [created] + +permissions: + contents: write + issues: write + pull-requests: write + +env: + PNPM_VERSION: 10.2.1 + +jobs: + process-comment: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, '/mycoder pr') || contains(github.event.comment.body, '/mycoder plan') + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: ${{ env.PNPM_VERSION }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'pnpm' + + - name: Install MyCoder + run: pnpm install -g mycoder + + - name: Run MyCoder PR command + if: contains(github.event.comment.body, '/mycoder pr') + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + XAI_API_KEY: ${{ secrets.XAI_API_KEY }} + MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }} + run: | + echo "Running MyCoder to implement PR for issue #${{ github.event.issue.number }}" + mycoder --githubMode true "Implement a PR for GitHub issue #${{ github.event.issue.number }}. The issue can be found at ${{ github.event.issue.html_url }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." + + - name: Run MyCoder Plan command + if: contains(github.event.comment.body, '/mycoder plan') + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + XAI_API_KEY: ${{ secrets.XAI_API_KEY }} + MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }} + run: | + echo "Running MyCoder to create implementation plan for issue #${{ github.event.issue.number }}" + mycoder --githubMode true "Review GitHub issue #${{ github.event.issue.number }} at ${{ github.event.issue.html_url }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file diff --git a/README.md b/README.md index f4f2365..123219b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,15 @@ mycoder -f prompt.txt mycoder config set githubMode true ``` +### GitHub Comment Commands + +MyCoder can be triggered directly from GitHub issue comments using special commands: + +- `/mycoder pr` - Implements a PR for the given issue +- `/mycoder plan` - Generates an implementation plan as a comment + +[Learn more about GitHub comment commands](docs/github-comment-commands.md) + ## Packages - [mycoder](packages/cli) - Command-line interface for MyCoder diff --git a/docs/github-comment-commands.md b/docs/github-comment-commands.md new file mode 100644 index 0000000..d59a10a --- /dev/null +++ b/docs/github-comment-commands.md @@ -0,0 +1,55 @@ +# GitHub Comment Commands + +MyCoder provides automated actions in response to specific commands in GitHub issue comments. This feature allows you to trigger MyCoder directly from GitHub issues. + +## Available Commands + +### `/mycoder pr` + +When you add a comment with `/mycoder pr` to any issue, MyCoder will: + +1. Check out the repository +2. Review the issue details +3. Implement a solution according to the requirements +4. Create a pull request that addresses the issue + +Example: +``` +This looks like a great feature to add! + +/mycoder pr +``` + +### `/mycoder plan` + +When you add a comment with `/mycoder plan` to any issue, MyCoder will: + +1. Review the issue details +2. Create a comprehensive implementation plan +3. Post the plan as a comment on the issue + +Example: +``` +I'm not sure about the best approach for this. + +/mycoder plan +``` + +## How It Works + +This functionality is implemented as a GitHub Action that runs whenever a new comment is added to an issue. The action checks for these specific command patterns and triggers MyCoder with the appropriate instructions. + +## Requirements + +For this feature to work in your repository: + +1. The GitHub Action workflow must be present in your repository +2. You need to configure the necessary API keys as GitHub secrets: + - `GITHUB_TOKEN` (automatically provided) + - `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `XAI_API_KEY`, or `MISTRAL_API_KEY` (depending on your preferred model) + +## Limitations + +- The action runs with GitHub's default timeout limits +- Complex implementations may require multiple iterations +- The AI model's capabilities determine the quality of the implementation or plan \ No newline at end of file From 4a9e23b8f9a84e9d8b80b08f8a787d1770635575 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Mon, 10 Mar 2025 12:01:22 -0400 Subject: [PATCH 2/4] fix CI missing keys. --- .github/workflows/ci.yml | 3 +++ .github/workflows/issue-comment.yml | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e44ffae..11f8a09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,9 @@ jobs: run: cd packages/agent && pnpm exec playwright install --with-deps chromium - name: Test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: pnpm test - name: Lint diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml index 9ebd47e..22df704 100644 --- a/.github/workflows/issue-comment.yml +++ b/.github/workflows/issue-comment.yml @@ -31,29 +31,25 @@ jobs: node-version-file: .nvmrc cache: 'pnpm' - - name: Install MyCoder - run: pnpm install -g mycoder + - name: Install MyCoder globally + run: | + # Skip tests when installing globally + pnpm install -g mycoder --no-frozen-lockfile --ignore-scripts - name: Run MyCoder PR command if: contains(github.event.comment.body, '/mycoder pr') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - XAI_API_KEY: ${{ secrets.XAI_API_KEY }} - MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }} run: | echo "Running MyCoder to implement PR for issue #${{ github.event.issue.number }}" - mycoder --githubMode true "Implement a PR for GitHub issue #${{ github.event.issue.number }}. The issue can be found at ${{ github.event.issue.html_url }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." + mycoder --githubMode true "Implement a PR for GitHub issue #${{ github.event.issue.number }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." - name: Run MyCoder Plan command if: contains(github.event.comment.body, '/mycoder plan') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - XAI_API_KEY: ${{ secrets.XAI_API_KEY }} - MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }} run: | echo "Running MyCoder to create implementation plan for issue #${{ github.event.issue.number }}" - mycoder --githubMode true "Review GitHub issue #${{ github.event.issue.number }} at ${{ github.event.issue.html_url }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file + mycoder --githubMode true "Review GitHub issue #${{ github.event.issue.number }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file From 42831a4fe47551a67cfb51ec27cd527cd3c6de6c Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Mon, 10 Mar 2025 14:34:34 -0400 Subject: [PATCH 3/4] ensure userprompt is false on Github Action workflows --- .github/workflows/issue-comment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml index 22df704..ada50c9 100644 --- a/.github/workflows/issue-comment.yml +++ b/.github/workflows/issue-comment.yml @@ -43,7 +43,7 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | echo "Running MyCoder to implement PR for issue #${{ github.event.issue.number }}" - mycoder --githubMode true "Implement a PR for GitHub issue #${{ github.event.issue.number }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." + mycoder --githubMode true --userPrompt false "Implement a PR for GitHub issue #${{ github.event.issue.number }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." - name: Run MyCoder Plan command if: contains(github.event.comment.body, '/mycoder plan') @@ -52,4 +52,4 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | echo "Running MyCoder to create implementation plan for issue #${{ github.event.issue.number }}" - mycoder --githubMode true "Review GitHub issue #${{ github.event.issue.number }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file + mycoder --githubMode true --userPrompt false "Review GitHub issue #${{ github.event.issue.number }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file From 69d347db37406a263791f9acaffe5ba9f501f891 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Mon, 10 Mar 2025 14:40:07 -0400 Subject: [PATCH 4/4] Make /mycoder command more flexible and context-aware --- .github/workflows/issue-comment.yml | 35 ++++++++++------- README.md | 12 ++++-- docs/github-comment-commands.md | 59 ++++++++++++++++++++--------- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml index ada50c9..4015c38 100644 --- a/.github/workflows/issue-comment.yml +++ b/.github/workflows/issue-comment.yml @@ -15,8 +15,25 @@ env: jobs: process-comment: runs-on: ubuntu-latest - if: contains(github.event.comment.body, '/mycoder pr') || contains(github.event.comment.body, '/mycoder plan') + if: contains(github.event.comment.body, '/mycoder') steps: + - name: Extract prompt from comment + id: extract-prompt + run: | + COMMENT="${{ github.event.comment.body }}" + if [[ "$COMMENT" =~ "/mycoder "(.+) ]]; then + PROMPT="${BASH_REMATCH[1]}" + elif [[ "$COMMENT" =~ "/mycoder" ]]; then + # If just /mycoder with no text after, use a default prompt + PROMPT="Please review this issue and suggest next steps." + else + echo "No valid /mycoder command found" + exit 1 + fi + echo "prompt=$PROMPT" >> $GITHUB_OUTPUT + echo "comment_url=${{ github.event.comment.html_url }}" >> $GITHUB_OUTPUT + echo "comment_id=${{ github.event.comment.id }}" >> $GITHUB_OUTPUT + - name: Checkout repository uses: actions/checkout@v3 @@ -36,20 +53,10 @@ jobs: # Skip tests when installing globally pnpm install -g mycoder --no-frozen-lockfile --ignore-scripts - - name: Run MyCoder PR command - if: contains(github.event.comment.body, '/mycoder pr') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - run: | - echo "Running MyCoder to implement PR for issue #${{ github.event.issue.number }}" - mycoder --githubMode true --userPrompt false "Implement a PR for GitHub issue #${{ github.event.issue.number }}. Please review the issue details and implement a solution according to the requirements. After implementation, create a pull request that addresses this issue." - - - name: Run MyCoder Plan command - if: contains(github.event.comment.body, '/mycoder plan') + - name: Run MyCoder with prompt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | - echo "Running MyCoder to create implementation plan for issue #${{ github.event.issue.number }}" - mycoder --githubMode true --userPrompt false "Review GitHub issue #${{ github.event.issue.number }} and create an implementation plan. Post your plan as a comment on the issue. Be thorough and consider all requirements mentioned in the issue description." \ No newline at end of file + echo "Running MyCoder for issue #${{ github.event.issue.number }} with prompt: ${{ steps.extract-prompt.outputs.prompt }}" + mycoder --githubMode true --userPrompt false "On issue #${{ github.event.issue.number }} the user asked: '${{ steps.extract-prompt.outputs.prompt }}' in comment ${{ steps.extract-prompt.outputs.comment_url }}. Please address this request. If you create a PR or take actions outside the scope of this issue, please report back to the issue with a comment explaining what you did." \ No newline at end of file diff --git a/README.md b/README.md index 123219b..56cf4c5 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,16 @@ mycoder config set githubMode true ### GitHub Comment Commands -MyCoder can be triggered directly from GitHub issue comments using special commands: +MyCoder can be triggered directly from GitHub issue comments using the flexible `/mycoder` command: -- `/mycoder pr` - Implements a PR for the given issue -- `/mycoder plan` - Generates an implementation plan as a comment +``` +/mycoder [your instructions here] +``` + +Examples: +- `/mycoder implement a PR for this issue` +- `/mycoder create an implementation plan` +- `/mycoder suggest test cases for this feature` [Learn more about GitHub comment commands](docs/github-comment-commands.md) diff --git a/docs/github-comment-commands.md b/docs/github-comment-commands.md index d59a10a..531fac6 100644 --- a/docs/github-comment-commands.md +++ b/docs/github-comment-commands.md @@ -1,43 +1,68 @@ # GitHub Comment Commands -MyCoder provides automated actions in response to specific commands in GitHub issue comments. This feature allows you to trigger MyCoder directly from GitHub issues. +MyCoder provides automated actions in response to `/mycoder` commands in GitHub issue comments. This feature allows you to trigger MyCoder directly from GitHub issues with flexible prompts. -## Available Commands +## How to Use -### `/mycoder pr` +Simply add a comment to any GitHub issue with `/mycoder` followed by your instructions: -When you add a comment with `/mycoder pr` to any issue, MyCoder will: +``` +/mycoder [your instructions here] +``` + +MyCoder will process your instructions in the context of the issue and respond accordingly. +## Examples + +### Creating a PR + +``` +/mycoder implement a PR for this issue +``` + +MyCoder will: 1. Check out the repository 2. Review the issue details 3. Implement a solution according to the requirements 4. Create a pull request that addresses the issue -Example: -``` -This looks like a great feature to add! +### Creating an Implementation Plan -/mycoder pr +``` +/mycoder create an implementation plan for this issue ``` -### `/mycoder plan` - -When you add a comment with `/mycoder plan` to any issue, MyCoder will: - +MyCoder will: 1. Review the issue details 2. Create a comprehensive implementation plan 3. Post the plan as a comment on the issue -Example: +### Other Use Cases + +The `/mycoder` command is flexible and can handle various requests: + +``` +/mycoder suggest test cases for this feature +``` + +``` +/mycoder analyze the performance implications of this change ``` -I'm not sure about the best approach for this. -/mycoder plan +``` +/mycoder recommend libraries we could use for this implementation ``` ## How It Works -This functionality is implemented as a GitHub Action that runs whenever a new comment is added to an issue. The action checks for these specific command patterns and triggers MyCoder with the appropriate instructions. +This functionality is implemented as a GitHub Action that runs whenever a new comment is added to an issue. The action checks for the `/mycoder` command pattern and triggers MyCoder with the appropriate instructions. + +MyCoder receives context about: +- The issue number +- The specific prompt you provided +- The comment URL where the command was triggered + +If MyCoder creates a PR or takes actions outside the scope of the issue, it will report back to the issue with a comment explaining what was done. ## Requirements @@ -52,4 +77,4 @@ For this feature to work in your repository: - The action runs with GitHub's default timeout limits - Complex implementations may require multiple iterations -- The AI model's capabilities determine the quality of the implementation or plan \ No newline at end of file +- The AI model's capabilities determine the quality of the results \ No newline at end of file