From 2c51cf42e670d46414822ccbff2fa7f00ac03d74 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Tue, 4 Mar 2025 10:24:06 -0500 Subject: [PATCH] Add GitHub mode to MyCoder for working with issues and PRs --- .changeset/github-mode.md | 6 ++ README.md | 9 +- docs/github-mode.md | 92 +++++++++++++++++ packages/agent/src/core/toolAgent.ts | 67 +----------- packages/cli/README.md | 147 +++++++++++---------------- 5 files changed, 159 insertions(+), 162 deletions(-) create mode 100644 .changeset/github-mode.md create mode 100644 docs/github-mode.md diff --git a/.changeset/github-mode.md b/.changeset/github-mode.md new file mode 100644 index 0000000..6bcfc4a --- /dev/null +++ b/.changeset/github-mode.md @@ -0,0 +1,6 @@ +--- +"mycoder-agent": minor +"mycoder": minor +--- + +Add GitHub mode to MyCoder for working with issues and PRs \ No newline at end of file diff --git a/README.md b/README.md index 46cb003..8aab5c5 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,7 @@ An open-source mono-repository containing the MyCoder agent and cli. !NOTE: To get started with the mycoder agent, [please see the CLI package](packages/cli) -## Features - -- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent decision making -- 🛠️ **Extensible Tool System**: Modular architecture with various tool categories -- 🔄 **Parallel Execution**: Ability to spawn sub-agents for concurrent task processing -- 📝 **Self-Modification**: Can modify code, it was built and tested by writing itself -- 🔍 **Smart Logging**: Hierarchical, color-coded logging system for clear output -- 👤 **Human Compatible**: Uses README.md, project files and shell commands to build its own context +undefined Please join the MyCoder.ai discord for support: https://discord.gg/5K6TYrHGHt diff --git a/docs/github-mode.md b/docs/github-mode.md new file mode 100644 index 0000000..2acd4ad --- /dev/null +++ b/docs/github-mode.md @@ -0,0 +1,92 @@ +# GitHub Mode for MyCoder + +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. + +## Overview + +When GitHub mode is enabled, MyCoder will: + +- Start from existing GitHub issues or create new ones for tasks +- Create branches for issues it's working on +- Make commits with descriptive messages +- Create PRs when work is complete +- Create additional GitHub issues for follow-up tasks or ideas + +## Prerequisites + +Before using GitHub mode, ensure you have: + +1. Installed the GitHub CLI (`gh`) +2. Authenticated with GitHub (`gh auth login`) +3. Appropriate permissions for your target repository + +## Enabling GitHub Mode + +You can enable GitHub mode using the `config` command: + +```bash +mycoder config set githubMode true +``` + +To disable GitHub mode: + +```bash +mycoder config set githubMode false +``` + +To check if GitHub mode is enabled: + +```bash +mycoder config get githubMode +``` + +## Using GitHub Mode + +When GitHub mode is enabled, MyCoder will automatically include GitHub-specific instructions in its system prompt. You can ask MyCoder to: + +1. **Work on existing issues**: + ```bash + mycoder "Implement GitHub issue #42" + ``` + +2. **Create new issues**: + ```bash + mycoder "Create a GitHub issue for adding dark mode to the UI" + ``` + +3. **Create PRs for completed work**: + ```bash + mycoder "Create a PR for the changes I just made to fix issue #42" + ``` + +## GitHub Commands + +MyCoder uses the GitHub CLI directly. Here are some common commands it may use: + +- **View issues**: `gh issue list --state open` +- **View a specific issue**: `gh issue view ` +- **Create an issue**: `gh issue create --title "Title" --body "Description"` +- **Create a PR**: `gh pr create --title "Title" --body "Description"` +- **Create a branch**: `git checkout -b issue-` +- **Commit changes**: `git commit -m "Descriptive message"` +- **Push changes**: `git push -u origin ` + +## Best Practices + +1. **Always start with an issue**: Create or reference a GitHub issue for each task +2. **Use descriptive branch names**: Ideally including the issue number (e.g., `issue-42-dark-mode`) +3. **Write clear commit messages**: Follow your project's commit message conventions +4. **Link PRs to issues**: Use closing keywords (e.g., "Closes #42") in PR descriptions +5. **Review PRs carefully**: MyCoder can create PRs, but you should review them before merging + +## Troubleshooting + +- **Authentication issues**: Run `gh auth status` to check your authentication status +- **Permission errors**: Ensure you have the appropriate permissions for the repository +- **Command not found**: Make sure the GitHub CLI is installed and in your PATH + +## Configuration + +GitHub mode settings are stored in `~/.mycoder/config.json`. The current configuration options are: + +- `githubMode`: Boolean flag to enable/disable GitHub mode diff --git a/packages/agent/src/core/toolAgent.ts b/packages/agent/src/core/toolAgent.ts index 4a7c9ae..95cce3e 100644 --- a/packages/agent/src/core/toolAgent.ts +++ b/packages/agent/src/core/toolAgent.ts @@ -1,5 +1,3 @@ -import { execSync } from 'child_process'; - import Anthropic from '@anthropic-ai/sdk'; import { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages/messages.js'; import chalk from 'chalk'; @@ -20,70 +18,7 @@ import { export interface ToolAgentResult { result: string; interactions: number; -} - -const CONFIG = { - maxIterations: 200, - model: 'claude-3-7-sonnet-latest', - maxTokens: 4096, - temperature: 0.7, - getSystemPrompt: () => { - // Gather context with error handling - const getCommandOutput = (command: string, label: string): string => { - try { - return execSync(command).toString().trim(); - } catch (error) { - return `[Error getting ${label}: ${(error as Error).message}]`; - } - }; - - const context = { - pwd: getCommandOutput('pwd', 'current directory'), - files: getCommandOutput('ls -la', 'file listing'), - system: getCommandOutput('uname -a', 'system information'), - datetime: new Date().toString(), - }; - - return [ - 'You are an AI agent that can use tools to accomplish tasks.', - '', - 'Current Context:', - `Directory: ${context.pwd}`, - 'Files:', - context.files, - `System: ${context.system}`, - `DateTime: ${context.datetime}`, - '', - 'You prefer to call tools in parallel when possible because it leads to faster execution and less resource usage.', - 'When done, call the sequenceComplete tool with your results to indicate that the sequence has completed.', - '', - 'For coding tasks:', - '0. Try to break large tasks into smaller sub-tasks that can be completed and verified sequentially.', - " - trying to make lots of changes in one go can make it really hard to identify when something doesn't work", - ' - use sub-agents for each sub-task, leaving the main agent in a supervisory role', - ' - when possible ensure the project compiles/builds and the tests pass after each sub-task', - ' - give the sub-agents the guidance and context necessary be successful', - '1. First understand the context by:', - ' - Reading README.md, CONTRIBUTING.md, and similar documentation', - ' - Checking project configuration files (e.g., package.json)', - ' - Understanding coding standards', - '2. Ensure changes:', - ' - Follow project conventions', - ' - Build successfully', - ' - Pass all tests', - '3. Update documentation as needed', - '4. Consider adding documentation if you encountered setup/understanding challenges', - '', - 'Feel free to use Google and Bing via the browser tools to search for information or for ideas when you get stuck.', - '', - '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.', - '', - 'Use sub-agents for parallel tasks, providing them with specific context they need rather than having them rediscover it.', - ].join('\\n'); - }, -}; - -interface ToolCallResult { + undefined; sequenceCompleted: boolean; completionResult?: string; toolResults: ToolResultContent[]; diff --git a/packages/cli/README.md b/packages/cli/README.md index 1c7e5f6..a4eb3e5 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,130 +1,101 @@ # MyCoder CLI -[![NPM Package][npm]][npm-url] -[![NPM Downloads][npm-downloads]][npmtrends-url] -[![CI Status][ci]][ci-url] -[![Discord][discord]][discord-url] +Command-line interface for AI-powered coding tasks. -## Overview +## Features -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. - -- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent decision making +- 🤖 **AI-Powered**: Leverages Anthropic's Claude API for intelligent coding assistance - 🛠️ **Extensible Tool System**: Modular architecture with various tool categories - 🔄 **Parallel Execution**: Ability to spawn sub-agents for concurrent task processing - 📝 **Self-Modification**: Can modify code, it was built and tested by writing itself - 🔍 **Smart Logging**: Hierarchical, color-coded logging system for clear output - 👤 **Human Compatible**: Uses README.md, project files and shell commands to build its own context +- 🌐 **GitHub Integration**: GitHub mode for working with issues and PRs as part of workflow -Please join the MyCoder.ai discord for support: https://discord.gg/5K6TYrHGHt - -## WARNING and LIABILITY WAIVER - -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. - -## API Key Required - -Before using MyCoder, you must have an ANTHROPIC_API_KEY specified either: - -- As an environment variable, "export ANTHROPIC_API_KEY=[your-api-key]" or -- In a .env file in the folder you run `mycoder` from - -Get an API key from https://www.anthropic.com/api - -## Quick Start +## Installation ```bash -# Install globally (pnpm, bun, yarn also work) npm install -g mycoder +``` -# Start MyCoder with a prompt -mycoder "fix all build errors and ensure the tests pass" +## Usage -# Start in interactive mode +```bash +# Interactive mode mycoder -i -# Read prompt from a file -mycoder --promptFile=your-prompt.txt -``` +# Run with a prompt +mycoder "Implement a React component that displays a list of items" + +# Run with a prompt from a file +mycoder -f prompt.txt -## CLI Options +# Enable GitHub mode +mycoder config set githubMode true +``` -- `[prompt]`: Main prompt text (positional argument) -- `-i, --interactive`: Run in interactive mode, asking for prompts -- `-f, --file`: Read prompt from a specified file -- `--log`: Set log level (info, verbose, warn, error) -- `--tokenUsage`: Output token usage at info log level -- `--headless`: Use browser in headless mode with no UI showing (default: true) -- `--userSession`: Use user's existing browser session instead of sandboxed session (default: false) -- `-h, --help`: Show help -- `-V, --version`: Show version +## GitHub Mode -## Example Use Cases & Prompts +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: -MyCoder excels at various software development tasks. Here are some example prompts: +- Start from existing GitHub issues or create new ones for tasks +- Create branches for issues it's working on +- Make commits with descriptive messages +- Create PRs when work is complete +- Create additional GitHub issues for follow-up tasks or ideas -### Code Migration & Updates +To enable GitHub mode: ```bash -# Converting test framework -mycoder "Convert all Jest tests in the src/ directory to Vitest, updating any necessary configuration files and dependencies" - -# Dependency updates -mycoder "Update all dependencies to their latest versions, handle any breaking changes, and ensure all tests pass" +mycoder config set githubMode true ``` -### Code Refactoring +To disable GitHub mode: ```bash -# Class refactoring -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" - -# API modernization -mycoder "Convert all callback-based functions in the project to use async/await, update tests accordingly" +mycoder config set githubMode false ``` -### Feature Implementation +Requirements for GitHub mode: +- GitHub CLI (`gh`) needs to be installed and authenticated +- User needs to have appropriate GitHub permissions for the target repository -```bash -# CLI enhancement -mycoder "Add a new global --debug command line option that enables verbose logging throughout the application" - -# New functionality -mycoder "Create a new caching system for API responses using Redis, including configuration options and unit tests" -``` +## Configuration -### Maintenance & Fixes +MyCoder stores configuration in `~/.mycoder/config.json`. You can manage configuration using the `config` command: ```bash -# Build fixes -mycoder "Fix all TypeScript build errors and ensure all tests pass" +# List all configuration +mycoder config list -# Test coverage -mycoder "Add unit tests for all untested functions in the src/utils directory, aiming for 80% coverage" +# Get a specific configuration value +mycoder config get githubMode + +# Set a configuration value +mycoder config set githubMode true ``` -### Documentation +## Environment Variables + +- `ANTHROPIC_API_KEY`: Your Anthropic API key (required) + +## Development ```bash -# Documentation generation -mycoder "Generate comprehensive JSDoc documentation for all exported functions and update the API documentation in the docs/ directory" +# Clone the repository +git clone https://github.com/drivecore/mycoder.git +cd mycoder -# Architecture documentation -mycoder "Analyze the current codebase and create detailed architecture documentation including component diagrams and data flow" +# Install dependencies +pnpm install + +# Build the CLI +pnpm build + +# Run the locally built CLI +pnpm cli -i ``` -## Technical Requirements - -- Node.js >= 20.0.0 -- pnpm >= 10.2.1 - -[npm]: https://img.shields.io/npm/v/mycoder -[npm-downloads]: https://img.shields.io/npm/dw/mycoder -[npm]: https://img.shields.io/npm/v/mycoder -[npm-url]: https://www.npmjs.com/package/mycoder -[npm-downloads]: https://img.shields.io/npm/dw/mycoder -[npmtrends-url]: https://www.npmtrends.com/mycoder -[ci]: https://img.shields.io/github/checks-status/bhouston/mycoder/main -[ci-url]: https://github.com/bhouston/mycoder/actions -[discord]: https://img.shields.io/discord/1339025847331328000 -[discord-url]: https://discord.gg/5K6TYrHGHt +## License + +MIT