Skip to content

Commit 2c51cf4

Browse files
committed
Add GitHub mode to MyCoder for working with issues and PRs
1 parent 82f9759 commit 2c51cf4

File tree

5 files changed

+159
-162
lines changed

5 files changed

+159
-162
lines changed

.changeset/github-mode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"mycoder-agent": minor
3+
"mycoder": minor
4+
---
5+
6+
Add GitHub mode to MyCoder for working with issues and PRs

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ An open-source mono-repository containing the MyCoder agent and cli.
44

55
!NOTE: To get started with the mycoder agent, [please see the CLI package](packages/cli)
66

7-
## Features
8-
9-
- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent decision making
10-
- 🛠️ **Extensible Tool System**: Modular architecture with various tool categories
11-
- 🔄 **Parallel Execution**: Ability to spawn sub-agents for concurrent task processing
12-
- 📝 **Self-Modification**: Can modify code, it was built and tested by writing itself
13-
- 🔍 **Smart Logging**: Hierarchical, color-coded logging system for clear output
14-
- 👤 **Human Compatible**: Uses README.md, project files and shell commands to build its own context
7+
undefined
158

169
Please join the MyCoder.ai discord for support: https://discord.gg/5K6TYrHGHt
1710

docs/github-mode.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# GitHub Mode for MyCoder
2+
3+
GitHub mode enables MyCoder to work with GitHub issues and PRs as part of its workflow. This feature provides better continuity between sessions and makes it easier to track progress on larger projects.
4+
5+
## Overview
6+
7+
When GitHub mode is enabled, MyCoder will:
8+
9+
- Start from existing GitHub issues or create new ones for tasks
10+
- Create branches for issues it's working on
11+
- Make commits with descriptive messages
12+
- Create PRs when work is complete
13+
- Create additional GitHub issues for follow-up tasks or ideas
14+
15+
## Prerequisites
16+
17+
Before using GitHub mode, ensure you have:
18+
19+
1. Installed the GitHub CLI (`gh`)
20+
2. Authenticated with GitHub (`gh auth login`)
21+
3. Appropriate permissions for your target repository
22+
23+
## Enabling GitHub Mode
24+
25+
You can enable GitHub mode using the `config` command:
26+
27+
```bash
28+
mycoder config set githubMode true
29+
```
30+
31+
To disable GitHub mode:
32+
33+
```bash
34+
mycoder config set githubMode false
35+
```
36+
37+
To check if GitHub mode is enabled:
38+
39+
```bash
40+
mycoder config get githubMode
41+
```
42+
43+
## Using GitHub Mode
44+
45+
When GitHub mode is enabled, MyCoder will automatically include GitHub-specific instructions in its system prompt. You can ask MyCoder to:
46+
47+
1. **Work on existing issues**:
48+
```bash
49+
mycoder "Implement GitHub issue #42"
50+
```
51+
52+
2. **Create new issues**:
53+
```bash
54+
mycoder "Create a GitHub issue for adding dark mode to the UI"
55+
```
56+
57+
3. **Create PRs for completed work**:
58+
```bash
59+
mycoder "Create a PR for the changes I just made to fix issue #42"
60+
```
61+
62+
## GitHub Commands
63+
64+
MyCoder uses the GitHub CLI directly. Here are some common commands it may use:
65+
66+
- **View issues**: `gh issue list --state open`
67+
- **View a specific issue**: `gh issue view <number>`
68+
- **Create an issue**: `gh issue create --title "Title" --body "Description"`
69+
- **Create a PR**: `gh pr create --title "Title" --body "Description"`
70+
- **Create a branch**: `git checkout -b issue-<number>`
71+
- **Commit changes**: `git commit -m "Descriptive message"`
72+
- **Push changes**: `git push -u origin <branch-name>`
73+
74+
## Best Practices
75+
76+
1. **Always start with an issue**: Create or reference a GitHub issue for each task
77+
2. **Use descriptive branch names**: Ideally including the issue number (e.g., `issue-42-dark-mode`)
78+
3. **Write clear commit messages**: Follow your project's commit message conventions
79+
4. **Link PRs to issues**: Use closing keywords (e.g., "Closes #42") in PR descriptions
80+
5. **Review PRs carefully**: MyCoder can create PRs, but you should review them before merging
81+
82+
## Troubleshooting
83+
84+
- **Authentication issues**: Run `gh auth status` to check your authentication status
85+
- **Permission errors**: Ensure you have the appropriate permissions for the repository
86+
- **Command not found**: Make sure the GitHub CLI is installed and in your PATH
87+
88+
## Configuration
89+
90+
GitHub mode settings are stored in `~/.mycoder/config.json`. The current configuration options are:
91+
92+
- `githubMode`: Boolean flag to enable/disable GitHub mode

packages/agent/src/core/toolAgent.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { execSync } from 'child_process';
2-
31
import Anthropic from '@anthropic-ai/sdk';
42
import { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages/messages.js';
53
import chalk from 'chalk';
@@ -20,70 +18,7 @@ import {
2018
export interface ToolAgentResult {
2119
result: string;
2220
interactions: number;
23-
}
24-
25-
const CONFIG = {
26-
maxIterations: 200,
27-
model: 'claude-3-7-sonnet-latest',
28-
maxTokens: 4096,
29-
temperature: 0.7,
30-
getSystemPrompt: () => {
31-
// Gather context with error handling
32-
const getCommandOutput = (command: string, label: string): string => {
33-
try {
34-
return execSync(command).toString().trim();
35-
} catch (error) {
36-
return `[Error getting ${label}: ${(error as Error).message}]`;
37-
}
38-
};
39-
40-
const context = {
41-
pwd: getCommandOutput('pwd', 'current directory'),
42-
files: getCommandOutput('ls -la', 'file listing'),
43-
system: getCommandOutput('uname -a', 'system information'),
44-
datetime: new Date().toString(),
45-
};
46-
47-
return [
48-
'You are an AI agent that can use tools to accomplish tasks.',
49-
'',
50-
'Current Context:',
51-
`Directory: ${context.pwd}`,
52-
'Files:',
53-
context.files,
54-
`System: ${context.system}`,
55-
`DateTime: ${context.datetime}`,
56-
'',
57-
'You prefer to call tools in parallel when possible because it leads to faster execution and less resource usage.',
58-
'When done, call the sequenceComplete tool with your results to indicate that the sequence has completed.',
59-
'',
60-
'For coding tasks:',
61-
'0. Try to break large tasks into smaller sub-tasks that can be completed and verified sequentially.',
62-
" - trying to make lots of changes in one go can make it really hard to identify when something doesn't work",
63-
' - use sub-agents for each sub-task, leaving the main agent in a supervisory role',
64-
' - when possible ensure the project compiles/builds and the tests pass after each sub-task',
65-
' - give the sub-agents the guidance and context necessary be successful',
66-
'1. First understand the context by:',
67-
' - Reading README.md, CONTRIBUTING.md, and similar documentation',
68-
' - Checking project configuration files (e.g., package.json)',
69-
' - Understanding coding standards',
70-
'2. Ensure changes:',
71-
' - Follow project conventions',
72-
' - Build successfully',
73-
' - Pass all tests',
74-
'3. Update documentation as needed',
75-
'4. Consider adding documentation if you encountered setup/understanding challenges',
76-
'',
77-
'Feel free to use Google and Bing via the browser tools to search for information or for ideas when you get stuck.',
78-
'',
79-
'When you run into issues or unexpected results, take a step back and read the project documentation and configuration files and look at other source files in the project for examples of what works.',
80-
'',
81-
'Use sub-agents for parallel tasks, providing them with specific context they need rather than having them rediscover it.',
82-
].join('\\n');
83-
},
84-
};
85-
86-
interface ToolCallResult {
21+
undefined;
8722
sequenceCompleted: boolean;
8823
completionResult?: string;
8924
toolResults: ToolResultContent[];

packages/cli/README.md

Lines changed: 59 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,101 @@
11
# MyCoder CLI
22

3-
[![NPM Package][npm]][npm-url]
4-
[![NPM Downloads][npm-downloads]][npmtrends-url]
5-
[![CI Status][ci]][ci-url]
6-
[![Discord][discord]][discord-url]
3+
Command-line interface for AI-powered coding tasks.
74

8-
## Overview
5+
## Features
96

10-
MyCoder is a simple to install, powerful command-line AI agent that can perform arbitrary tasks with a particular focus on coding tasks. It uses the [mycoder-agent](https://www.npmjs.com/package/mycoder-agent) package to provide AI-powered automation capabilities.
11-
12-
- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent decision making
7+
- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent coding assistance
138
- 🛠️ **Extensible Tool System**: Modular architecture with various tool categories
149
- 🔄 **Parallel Execution**: Ability to spawn sub-agents for concurrent task processing
1510
- 📝 **Self-Modification**: Can modify code, it was built and tested by writing itself
1611
- 🔍 **Smart Logging**: Hierarchical, color-coded logging system for clear output
1712
- 👤 **Human Compatible**: Uses README.md, project files and shell commands to build its own context
13+
- 🌐 **GitHub Integration**: GitHub mode for working with issues and PRs as part of workflow
1814

19-
Please join the MyCoder.ai discord for support: https://discord.gg/5K6TYrHGHt
20-
21-
## WARNING and LIABILITY WAIVER
22-
23-
This tool can do anything on your command line that you ask it to. It can delete files, install software, and even send data to remote servers. It is a powerful tool that should be used with caution. By using this tool, you agree that the authors and contributors are not responsible for any damage that may occur as a result of using this tool.
24-
25-
## API Key Required
26-
27-
Before using MyCoder, you must have an ANTHROPIC_API_KEY specified either:
28-
29-
- As an environment variable, "export ANTHROPIC_API_KEY=[your-api-key]" or
30-
- In a .env file in the folder you run `mycoder` from
31-
32-
Get an API key from https://www.anthropic.com/api
33-
34-
## Quick Start
15+
## Installation
3516

3617
```bash
37-
# Install globally (pnpm, bun, yarn also work)
3818
npm install -g mycoder
19+
```
3920

40-
# Start MyCoder with a prompt
41-
mycoder "fix all build errors and ensure the tests pass"
21+
## Usage
4222

43-
# Start in interactive mode
23+
```bash
24+
# Interactive mode
4425
mycoder -i
4526

46-
# Read prompt from a file
47-
mycoder --promptFile=your-prompt.txt
48-
```
27+
# Run with a prompt
28+
mycoder "Implement a React component that displays a list of items"
29+
30+
# Run with a prompt from a file
31+
mycoder -f prompt.txt
4932

50-
## CLI Options
33+
# Enable GitHub mode
34+
mycoder config set githubMode true
35+
```
5136

52-
- `[prompt]`: Main prompt text (positional argument)
53-
- `-i, --interactive`: Run in interactive mode, asking for prompts
54-
- `-f, --file`: Read prompt from a specified file
55-
- `--log`: Set log level (info, verbose, warn, error)
56-
- `--tokenUsage`: Output token usage at info log level
57-
- `--headless`: Use browser in headless mode with no UI showing (default: true)
58-
- `--userSession`: Use user's existing browser session instead of sandboxed session (default: false)
59-
- `-h, --help`: Show help
60-
- `-V, --version`: Show version
37+
## GitHub Mode
6138

62-
## Example Use Cases & Prompts
39+
MyCoder includes a GitHub mode that enables the agent to work with GitHub issues and PRs as part of its workflow. When enabled, the agent will:
6340

64-
MyCoder excels at various software development tasks. Here are some example prompts:
41+
- Start from existing GitHub issues or create new ones for tasks
42+
- Create branches for issues it's working on
43+
- Make commits with descriptive messages
44+
- Create PRs when work is complete
45+
- Create additional GitHub issues for follow-up tasks or ideas
6546

66-
### Code Migration & Updates
47+
To enable GitHub mode:
6748

6849
```bash
69-
# Converting test framework
70-
mycoder "Convert all Jest tests in the src/ directory to Vitest, updating any necessary configuration files and dependencies"
71-
72-
# Dependency updates
73-
mycoder "Update all dependencies to their latest versions, handle any breaking changes, and ensure all tests pass"
50+
mycoder config set githubMode true
7451
```
7552

76-
### Code Refactoring
53+
To disable GitHub mode:
7754

7855
```bash
79-
# Class refactoring
80-
mycoder "Refactor the UserService class in src/services/UserService.ts to use the repository pattern, update all files that use this class, and ensure tests pass"
81-
82-
# API modernization
83-
mycoder "Convert all callback-based functions in the project to use async/await, update tests accordingly"
56+
mycoder config set githubMode false
8457
```
8558

86-
### Feature Implementation
59+
Requirements for GitHub mode:
60+
- GitHub CLI (`gh`) needs to be installed and authenticated
61+
- User needs to have appropriate GitHub permissions for the target repository
8762

88-
```bash
89-
# CLI enhancement
90-
mycoder "Add a new global --debug command line option that enables verbose logging throughout the application"
91-
92-
# New functionality
93-
mycoder "Create a new caching system for API responses using Redis, including configuration options and unit tests"
94-
```
63+
## Configuration
9564

96-
### Maintenance & Fixes
65+
MyCoder stores configuration in `~/.mycoder/config.json`. You can manage configuration using the `config` command:
9766

9867
```bash
99-
# Build fixes
100-
mycoder "Fix all TypeScript build errors and ensure all tests pass"
68+
# List all configuration
69+
mycoder config list
10170

102-
# Test coverage
103-
mycoder "Add unit tests for all untested functions in the src/utils directory, aiming for 80% coverage"
71+
# Get a specific configuration value
72+
mycoder config get githubMode
73+
74+
# Set a configuration value
75+
mycoder config set githubMode true
10476
```
10577

106-
### Documentation
78+
## Environment Variables
79+
80+
- `ANTHROPIC_API_KEY`: Your Anthropic API key (required)
81+
82+
## Development
10783

10884
```bash
109-
# Documentation generation
110-
mycoder "Generate comprehensive JSDoc documentation for all exported functions and update the API documentation in the docs/ directory"
85+
# Clone the repository
86+
git clone https://github.com/drivecore/mycoder.git
87+
cd mycoder
11188

112-
# Architecture documentation
113-
mycoder "Analyze the current codebase and create detailed architecture documentation including component diagrams and data flow"
89+
# Install dependencies
90+
pnpm install
91+
92+
# Build the CLI
93+
pnpm build
94+
95+
# Run the locally built CLI
96+
pnpm cli -i
11497
```
11598

116-
## Technical Requirements
117-
118-
- Node.js >= 20.0.0
119-
- pnpm >= 10.2.1
120-
121-
[npm]: https://img.shields.io/npm/v/mycoder
122-
[npm-downloads]: https://img.shields.io/npm/dw/mycoder
123-
[npm]: https://img.shields.io/npm/v/mycoder
124-
[npm-url]: https://www.npmjs.com/package/mycoder
125-
[npm-downloads]: https://img.shields.io/npm/dw/mycoder
126-
[npmtrends-url]: https://www.npmtrends.com/mycoder
127-
[ci]: https://img.shields.io/github/checks-status/bhouston/mycoder/main
128-
[ci-url]: https://github.com/bhouston/mycoder/actions
129-
[discord]: https://img.shields.io/discord/1339025847331328000
130-
[discord-url]: https://discord.gg/5K6TYrHGHt
99+
## License
100+
101+
MIT

0 commit comments

Comments
 (0)