Skip to content

Add documentation for GitHub Action issue-comment.yml #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions docs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ Before using MyCoder with a specific provider, you need to provide the appropria
export ANTHROPIC_API_KEY=your-api-key
# or
export OPENAI_API_KEY=your-api-key
# or
export MISTRAL_API_KEY=your-api-key
# or
export XAI_API_KEY=your-api-key
```

2. Create a `.env` file in your working directory with the appropriate key:
Expand All @@ -61,10 +57,8 @@ MyCoder supports multiple AI providers:
| Provider | Environment Variable | Models |
| ---------- | -------------------- | ------------------------------------ |
| Anthropic | `ANTHROPIC_API_KEY` | claude-3-opus, claude-3-sonnet, etc. |
| OpenAI | `OPENAI_API_KEY` | gpt-4o, o3-mini, etc. |
| Mistral AI | `MISTRAL_API_KEY` | mistral-large, mistral-medium, etc. |
| xAI/Grok | `XAI_API_KEY` | grok-1 |
| Ollama | N/A (local) | Various local models |
| OpenAI | `OPENAI_API_KEY` | gpt-4o, gpt-4-turbo, etc. |
| Ollama | N/A (local) | Models with tool calling support |

You can specify which provider and model to use with the `--provider` and `--model` options:

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Currently available as a research preview, MyCoder is built to work alongside de

## Key Features

- **AI-Powered**: Supports multiple AI providers including Anthropic, OpenAI, Mistral AI, xAI/Grok, and Ollama
- **AI-Powered**: Supports multiple AI providers including Anthropic, OpenAI, and Ollama
- **Extensible Tool System**: Includes tools for file operations, shell commands, web browsing, and more
- **Parallel Execution**: Can spawn sub-agents to work on different parts of a task simultaneously
- **Self-Modification**: Capable of modifying code, including its own codebase
Expand Down
19 changes: 19 additions & 0 deletions docs/providers/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ Anthropic offers several Claude models with different capabilities and price poi
- Claude models have a 200K token context window, allowing for large codebases to be processed
- For cost-sensitive applications, consider using Claude Haiku for simpler tasks

## Token Caching

MyCoder implements token caching for Anthropic's Claude models to optimize performance and reduce API costs:

- Token caching stores and reuses parts of the conversation history
- The Anthropic provider uses Claude's native cache control mechanisms
- This significantly reduces token usage for repeated or similar queries
- Cache efficiency is automatically optimized based on conversation context

You can enable or disable token caching in your configuration:

```javascript
export default {
provider: 'anthropic',
model: 'claude-3-7-sonnet-20250219',
tokenCache: true, // Enable token caching (default is true)
};
```

## Troubleshooting

If you encounter issues with Anthropic's Claude:
Expand Down
4 changes: 3 additions & 1 deletion docs/providers/openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ export default {

## Supported Models

OpenAI offers several models with different capabilities:
MyCoder supports all OpenAI models that have tool/function calling capabilities. Here are some recommended models:

- `gpt-4o` (recommended) - Latest model with strong reasoning and tool-calling capabilities
- `gpt-4-turbo` - Strong performance with 128K context window
- `gpt-4` - Original GPT-4 model with 8K context window
- `gpt-3.5-turbo` - More affordable option for simpler tasks

You can use any other OpenAI model that supports function calling with MyCoder. The OpenAI provider is not limited to just these listed models.

## Best Practices

- GPT-4o provides the best balance of performance and cost for most MyCoder tasks
Expand Down
201 changes: 201 additions & 0 deletions docs/usage/github-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
sidebar_position: 6
---

# GitHub Action Integration

MyCoder can be seamlessly integrated into your GitHub workflow through GitHub Actions, enabling powerful automation for your repositories. This guide focuses on the `issue-comment.yml` GitHub Action, which allows you to trigger MyCoder directly from issue or PR comments.

## How It Works

The `issue-comment.yml` GitHub Action monitors comments on issues and pull requests for a specific trigger phrase (typically `/mycoder`). When detected, it launches MyCoder with the context of the issue or PR, allowing it to:

- Analyze and respond to issues
- Implement requested features
- Review pull requests
- Generate documentation
- Create new PRs with changes
- And much more

This integration creates a convenient, chat-like interface with MyCoder directly within your GitHub workflow.

## Benefits

- **Seamless Workflow Integration**: Interact with MyCoder without leaving GitHub
- **Parallel Processing**: Run multiple MyCoder instances simultaneously on different tasks
- **Contextual Understanding**: MyCoder has full access to the repository, issues, and PRs
- **Automated Task Execution**: Trigger complex tasks with a simple comment
- **Collaboration Enhancement**: AI assistance directly in your team's workflow

## Setup Guide

To add the MyCoder GitHub Action to your repository, create a file at `.github/workflows/issue-comment.yml` with the following configuration:

```yaml
name: MyCoder Issue Comment Action

on:
issue_comment:
types: [created]

# Top-level permissions for all jobs
permissions:
contents: write # Required for checkout, commit, push
issues: write # Required for issue comments
pull-requests: write # Required for creating PRs
discussions: write # For interaction capabilities
statuses: write # For creating commit statuses
checks: write # For creating check runs
actions: read # For inspecting workflow runs
packages: read # In case you need to access GitHub packages

env:
PNPM_VERSION: 10.2.1 # Adjust based on your project requirements

jobs:
process-comment:
runs-on: ubuntu-latest
# Only run if comment contains '/mycoder' AND commenter is authorized
if: |
contains(github.event.comment.body, '/mycoder') &&
contains(fromJson('["username1", "username2"]'), github.event.comment.user.login)
steps:
- name: Extract prompt from comment
id: extract-prompt
run: |
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

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}

- name: Install dependencies
run: pnpm install

- name: Install browsers
run: cd packages/agent && pnpm exec playwright install --with-deps chromium

- name: Configure Git
run: |
git config --global user.name "Your Name (via MyCoder)"
git config --global user.email "[email protected]"

- run:
pnpm install -g mycoder

# Auth GitHub CLI with the token
- name: Configure GitHub CLI
run: |
echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
# Verify auth status
gh auth status

- env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
echo "Running MyCoder for issue #${{ github.event.issue.number }}"
mycoder --userWarning false --upgradeCheck false --githubMode true --userPrompt false "On issue #${{ github.event.issue.number }} in comment ${{ steps.extract-prompt.outputs.comment_url }} the user invoked the mycoder CLI via /mycoder. Can you try to do what they requested or if it is unclear, respond with a comment to that effect to encourage them to be more clear."
```

## Best Practices

### Security Considerations

:::caution Important Security Warning
Only allow trusted individuals to trigger MyCoder via comments. With full repository access, MyCoder could potentially make significant changes if instructed maliciously.
:::

Restrict execution by specifying authorized users:

```yaml
if: |
contains(github.event.comment.body, '/mycoder') &&
contains(fromJson('["trusted-user1", "trusted-user2"]'), github.event.comment.user.login)
```

For open source projects, be especially careful about who can trigger automated workflows.

### Using Personal Access Tokens

While GitHub Actions provides a built-in `GITHUB_TOKEN`, using a Personal Access Token (PAT) is recommended:

- **Why**: Using a PAT preserves standard CI behavior on submitted PRs
- **How**: Store your PAT as a repository secret (`GH_PAT`) and reference it in the workflow

```yaml
- name: Configure GitHub CLI
run: |
echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
```

### Disable User Prompts

Always run MyCoder with user prompts disabled in GitHub Actions:

```bash
mycoder --userPrompt false
```

This prevents the workflow from hanging indefinitely waiting for user input.

### Git Configuration

Configure Git with appropriate user information for commits made by MyCoder:

```yaml
- name: Configure Git
run: |
git config --global user.name "Your Name (via MyCoder)"
git config --global user.email "[email protected]"
```

This clearly identifies commits made automatically by MyCoder.

## Usage Examples

### Trigger MyCoder on an Issue

Comment on any issue with:

```
/mycoder Please analyze this issue and suggest a solution.
```

### Request Documentation

```
/mycoder Please create documentation for the recently added feature XYZ.
```

### Code Review

```
/mycoder Please review this PR and suggest improvements.
```

### Feature Implementation

```
/mycoder Please implement the feature described in this issue and create a PR.
```

## Troubleshooting

If you encounter issues with the GitHub Action:

1. Check the Action logs for error messages
2. Verify that all required secrets are properly configured
3. Ensure the permissions are correctly set
4. Confirm that the commenter is in the authorized users list

## Conclusion

The MyCoder GitHub Action integration provides a powerful way to incorporate AI assistance directly into your development workflow. By following the best practices outlined above, you can safely leverage MyCoder to enhance productivity and collaboration within your GitHub repositories.