|
| 1 | +# Contributing to Bobby |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Bobby! This document provides guidelines for contributing to the project. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Getting Started](#getting-started) |
| 8 | +- [Development Setup](#development-setup) |
| 9 | +- [Code Architecture](#code-architecture) |
| 10 | +- [Contributing Guidelines](#contributing-guidelines) |
| 11 | +- [Pull Request Process](#pull-request-process) |
| 12 | +- [Bug Reports](#bug-reports) |
| 13 | +- [Feature Requests](#feature-requests) |
| 14 | + |
| 15 | +## Getting Started |
| 16 | + |
| 17 | +Bobby is a Discord bot that uses Claude Code to analyze codebases and answer questions. It's built with: |
| 18 | + |
| 19 | +- **Bun**: Fast JavaScript runtime |
| 20 | +- **Discord.js**: Discord bot framework |
| 21 | +- **Claude Code CLI**: AI-powered code analysis |
| 22 | +- **GitHub CLI**: Automated issue creation |
| 23 | + |
| 24 | +## Development Setup |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | + |
| 28 | +- [Bun](https://bun.sh/) runtime |
| 29 | +- Discord Bot Token (see README.md for setup) |
| 30 | +- Anthropic API Key |
| 31 | +- GitHub Personal Access Token |
| 32 | + |
| 33 | +### Local Development |
| 34 | + |
| 35 | +1. **Clone the repository**: |
| 36 | + ```bash |
| 37 | + git clone https://github.com/your-org/bobby.git |
| 38 | + cd bobby |
| 39 | + ``` |
| 40 | + |
| 41 | +2. **Install dependencies**: |
| 42 | + ```bash |
| 43 | + bun install |
| 44 | + ``` |
| 45 | + |
| 46 | +3. **Install required CLI tools**: |
| 47 | + ```bash |
| 48 | + # Install Claude Code CLI |
| 49 | + bun install -g @anthropic-ai/claude-code |
| 50 | + |
| 51 | + # Install GitHub CLI (platform specific) |
| 52 | + # See: https://github.com/cli/cli#installation |
| 53 | + ``` |
| 54 | + |
| 55 | +4. **Set up environment variables**: |
| 56 | + ```bash |
| 57 | + cp .env.example .env |
| 58 | + # Edit .env with your tokens and configuration |
| 59 | + ``` |
| 60 | + |
| 61 | +5. **Run the development server**: |
| 62 | + ```bash |
| 63 | + bun run dev |
| 64 | + ``` |
| 65 | + |
| 66 | +### Docker Development |
| 67 | + |
| 68 | +For testing the full Docker setup: |
| 69 | + |
| 70 | +```bash |
| 71 | +# Build the image |
| 72 | +docker build -t bobby-bot . |
| 73 | + |
| 74 | +# Run with your configuration |
| 75 | +docker run --env-file .env bobby-bot |
| 76 | +``` |
| 77 | + |
| 78 | +## Code Architecture |
| 79 | + |
| 80 | +### Core Components |
| 81 | + |
| 82 | +#### `index.js` - Main Application |
| 83 | +- **Discord Client Setup**: Initializes Discord.js client with required intents |
| 84 | +- **Message Handling**: Processes mentions and thread-based conversations |
| 85 | +- **Session Management**: Manages Claude Code sessions per Discord thread |
| 86 | +- **Streaming Responses**: Real-time response streaming from Claude Code |
| 87 | + |
| 88 | +#### `entrypoint.sh` - Docker Initialization |
| 89 | +- Environment validation |
| 90 | +- GitHub authentication |
| 91 | +- Repository cloning and syncing |
| 92 | +- Service startup |
| 93 | + |
| 94 | +### Key Functions |
| 95 | + |
| 96 | +#### `processWithClaude(query, channel, sessionId)` |
| 97 | +Handles the core interaction with Claude Code CLI: |
| 98 | +- Spawns Claude Code process with streaming output |
| 99 | +- Manages session continuity across thread conversations |
| 100 | +- Processes real-time JSON responses |
| 101 | +- Handles error cases and fallbacks |
| 102 | + |
| 103 | +#### Thread Management |
| 104 | +- `isNewBobbyCall()`: Detects new mentions in channels |
| 105 | +- `isThreadFollowUp()`: Identifies follow-up messages in threads |
| 106 | +- `extractSessionId()`: Extracts session ID from thread names |
| 107 | +- Thread naming: `Bobby - Title - session-id` |
| 108 | + |
| 109 | +#### Security Features |
| 110 | +- Server whitelist validation (`guildCreate` event) |
| 111 | +- Environment variable validation |
| 112 | +- Token masking in logs |
| 113 | + |
| 114 | +### Data Flow |
| 115 | + |
| 116 | +1. **New Conversation**: |
| 117 | + ``` |
| 118 | + User mentions Bobby → Create thread → Start new Claude session → Stream response → Update thread name |
| 119 | + ``` |
| 120 | + |
| 121 | +2. **Thread Follow-up**: |
| 122 | + ``` |
| 123 | + User message in thread → Extract session ID → Resume Claude session → Stream response |
| 124 | + ``` |
| 125 | + |
| 126 | +3. **Bug Detection**: |
| 127 | + ``` |
| 128 | + Claude detects issue → Creates GitHub issue → Returns issue link in response |
| 129 | + ``` |
| 130 | + |
| 131 | +## Contributing Guidelines |
| 132 | + |
| 133 | +### Code Style |
| 134 | + |
| 135 | +- Use modern JavaScript (ES6+) |
| 136 | +- Follow existing formatting patterns |
| 137 | +- Add comments for complex logic |
| 138 | +- Use descriptive variable names |
| 139 | + |
| 140 | +### Commit Messages |
| 141 | + |
| 142 | +Use conventional commit format: |
| 143 | +``` |
| 144 | +type(scope): description |
| 145 | +
|
| 146 | +feat(discord): add thread-based session management |
| 147 | +fix(claude): handle streaming response edge cases |
| 148 | +docs(readme): update Docker setup instructions |
| 149 | +``` |
| 150 | + |
| 151 | +### Branch Naming |
| 152 | + |
| 153 | +- `feature/description` - New features |
| 154 | +- `fix/description` - Bug fixes |
| 155 | +- `docs/description` - Documentation updates |
| 156 | +- `refactor/description` - Code refactoring |
| 157 | + |
| 158 | +### Testing |
| 159 | + |
| 160 | +- Test Discord bot functionality in a development server |
| 161 | +- Verify Claude Code integration with different query types |
| 162 | +- Test Docker deployment with environment variable variations |
| 163 | +- Validate GitHub issue creation workflow |
| 164 | + |
| 165 | +## Pull Request Process |
| 166 | + |
| 167 | +1. **Fork the repository** and create your feature branch |
| 168 | +2. **Make your changes** following the guidelines above |
| 169 | +3. **Test thoroughly** - ensure no regressions |
| 170 | +4. **Update documentation** if needed |
| 171 | +5. **Submit a pull request** with: |
| 172 | + - Clear description of changes |
| 173 | + - Link to any related issues |
| 174 | + - Screenshots/demos for UI changes |
| 175 | + |
| 176 | +### PR Template |
| 177 | + |
| 178 | +```markdown |
| 179 | +## Description |
| 180 | +Brief description of changes |
| 181 | + |
| 182 | +## Type of Change |
| 183 | +- [ ] Bug fix |
| 184 | +- [ ] New feature |
| 185 | +- [ ] Documentation update |
| 186 | +- [ ] Refactoring |
| 187 | + |
| 188 | +## Testing |
| 189 | +- [ ] Tested locally |
| 190 | +- [ ] Tested in Docker |
| 191 | +- [ ] Discord integration verified |
| 192 | +- [ ] Claude Code integration verified |
| 193 | + |
| 194 | +## Checklist |
| 195 | +- [ ] Code follows project style guidelines |
| 196 | +- [ ] Self-review completed |
| 197 | +- [ ] Documentation updated |
| 198 | +- [ ] No sensitive information exposed |
| 199 | +``` |
| 200 | + |
| 201 | +## Bug Reports |
| 202 | + |
| 203 | +When reporting bugs, include: |
| 204 | + |
| 205 | +1. **Environment details**: |
| 206 | + - Operating system |
| 207 | + - Bun version |
| 208 | + - Docker version (if applicable) |
| 209 | + |
| 210 | +2. **Steps to reproduce**: |
| 211 | + - Exact Discord commands used |
| 212 | + - Expected vs actual behavior |
| 213 | + - Error messages or logs |
| 214 | + |
| 215 | +3. **Configuration**: |
| 216 | + - Environment variables (without sensitive values) |
| 217 | + - Discord server setup |
| 218 | + - Repository configuration |
| 219 | + |
| 220 | +## Feature Requests |
| 221 | + |
| 222 | +For new features: |
| 223 | + |
| 224 | +1. **Use case description**: Why is this feature needed? |
| 225 | +2. **Proposed solution**: How should it work? |
| 226 | +3. **Alternatives considered**: Other approaches you've thought about |
| 227 | +4. **Implementation details**: Technical considerations (if applicable) |
| 228 | + |
| 229 | +## Code of Conduct |
| 230 | + |
| 231 | +- Be respectful and inclusive |
| 232 | +- Focus on constructive feedback |
| 233 | +- Help newcomers learn and contribute |
| 234 | +- Keep discussions relevant and professional |
| 235 | + |
| 236 | +## Getting Help |
| 237 | + |
| 238 | +- **Issues**: Create a GitHub issue for bugs or questions |
| 239 | +- **Discussions**: Use GitHub Discussions for general questions |
| 240 | +- **Discord**: Join our development Discord server (link in README) |
| 241 | + |
| 242 | +## Security |
| 243 | + |
| 244 | +If you find security vulnerabilities: |
| 245 | + |
| 246 | +1. **DO NOT** create a public issue |
| 247 | +2. Email security concerns to [security email] |
| 248 | +3. Allow time for fixing before public disclosure |
| 249 | + |
| 250 | +## Recognition |
| 251 | + |
| 252 | +Contributors will be recognized in: |
| 253 | +- README.md contributors section |
| 254 | +- Release notes for significant contributions |
| 255 | +- Special thanks for first-time contributors |
| 256 | + |
| 257 | +Thank you for contributing to Bobby! 🤖 |
0 commit comments