First off, thank you for considering contributing to Code Buddy! It's people like you that make Code Buddy such a great tool.
- Code of Conduct
- Getting Started
- Development Process
- Pull Request Process
- Coding Standards
- Testing Guidelines
- Commit Message Guidelines
- Project Structure
This project and everyone participating in it is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
- Node.js 16.0.0 or higher
- npm or yarn
- Git
- ripgrep (optional, for better search performance)
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/code-buddy.git cd code-buddy -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env # Add your GROK_API_KEY to .env -
Run the development build:
npm run dev
-
Run tests:
npm test
Always create a new branch for your work:
git checkout -b feature/your-feature-name
# or
git checkout -b fix/bug-descriptionBranch naming convention:
feature/- New featuresfix/- Bug fixesdocs/- Documentation changesrefactor/- Code refactoringtest/- Adding or updating testschore/- Maintenance tasks
- Make your changes in your feature branch
- Add tests for any new functionality
- Ensure all tests pass:
npm test - Ensure type checking passes:
npm run typecheck - Ensure linting passes:
npm run lint - Format your code:
npm run format
# Development mode with hot reload
npm run dev
# Build and run
npm run build
npm start
# Run with specific directory
npm run dev -- -d /path/to/project-
Update documentation if you're adding or changing features
-
Add tests for new functionality:
- Unit tests in
__tests__directories - Aim for 80%+ code coverage
- Test edge cases and error conditions
- Unit tests in
-
Ensure all checks pass:
npm run typecheck # TypeScript checks npm run lint # Linting npm test # Tests npm run format:check # Code formatting
-
Update the README.md with details of changes if applicable
-
Commit your changes following our commit message guidelines
-
Push to your fork:
git push origin feature/your-feature-name
-
Create a Pull Request from your fork to our
mainbranch -
Address review feedback - a maintainer will review your PR and may request changes
- Keep PRs focused on a single feature or fix
- Write clear PR descriptions explaining what and why
- Link related issues in the PR description
- Ensure CI/CD checks pass
- Be responsive to feedback
- Keep your PR up to date with the main branch
- Use TypeScript for all new code
- Enable strict type checking (we're working towards full strict mode)
- Avoid
anytypes - useunknownif type is truly unknown - Prefer interfaces over types for object shapes
- Use const assertions where appropriate
We use Prettier and ESLint to maintain consistent code style:
# Auto-format code
npm run format
# Check formatting
npm run format:check
# Lint code
npm run lint
# Auto-fix linting issues
npm run lint:fixKey style points:
- Use single quotes for strings
- Use semicolons
- 2 spaces for indentation
- Max line length: 100 characters
- Use arrow functions for callbacks
- Use async/await over promises
src/
├── agent/ # Core agent logic
├── codebuddy/ # Grok API client and tools
├── tools/ # Tool implementations
├── ui/ # UI components
├── utils/ # Utility functions
├── types/ # TypeScript type definitions
└── hooks/ # React hooks
- Files: kebab-case (e.g.,
text-editor.ts) - Components: PascalCase (e.g.,
ChatInterface.tsx) - Functions: camelCase (e.g.,
processMessage) - Constants: UPPER_SNAKE_CASE (e.g.,
MAX_RETRIES) - Interfaces/Types: PascalCase (e.g.,
ToolDefinition)
- Add JSDoc comments for all public functions and classes
- Include parameter descriptions and return types
- Add usage examples where helpful
- Document edge cases and assumptions
Example:
/**
* Validates a file path to prevent path traversal attacks
*
* @param inputPath - The path to validate (can be relative or absolute)
* @param workingDir - The base working directory
* @returns The resolved absolute path if valid
* @throws {Error} If path traversal is detected
*
* @example
* ```typescript
* const safePath = validatePath('../config.json', '/home/user/project');
* ```
*/
export function validatePath(inputPath: string, workingDir: string): string {
// Implementation
}- Unit tests go in
__tests__directories next to the code they test - Name test files with
.test.tsor.spec.tsextension - Use descriptive test names that explain what is being tested
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
describe('MyModule', () => {
describe('myFunction', () => {
it('should handle normal case', () => {
const result = myFunction('input');
expect(result).toBe('expected');
});
it('should handle edge case', () => {
const result = myFunction('');
expect(result).toBe('');
});
it('should throw on invalid input', () => {
expect(() => myFunction(null)).toThrow('Invalid input');
});
});
});- Aim for 80%+ code coverage
- Test happy paths and edge cases
- Test error conditions
- Mock external dependencies (API calls, file system, etc.)
# Run tests in watch mode
npm test
# Run tests once
npm run test:run
# Run with coverage
npm run test:coverage
# Run with UI
npm run test:uiWe follow the Conventional Commits specification.
<type>(<scope>): <subject>
<body>
<footer>
Must be one of:
- feat: New feature
- fix: Bug fix
- docs: Documentation only changes
- style: Code style changes (formatting, etc.)
- refactor: Code refactoring
- perf: Performance improvements
- test: Adding or updating tests
- chore: Maintenance tasks
- ci: CI/CD changes
- build: Build system changes
The scope should be the name of the affected module:
agenttoolsuiapisecurity
feat(tools): add new search tool with fuzzy matching
This adds a new search tool that uses ripgrep for fast searching
and includes fuzzy matching for file names.
Closes #123
fix(security): prevent path traversal attacks
Implement path validation to ensure all file operations stay
within the working directory.
BREAKING CHANGE: File paths outside working directory now throw errors
docs: update installation instructions
Add macOS-specific instructions and troubleshooting section.
- Use the imperative mood ("add feature" not "added feature")
- Don't capitalize the first letter of the subject
- No period at the end of the subject
- Limit subject line to 100 characters
- Separate subject from body with a blank line
- Wrap body at 72 characters
- Use body to explain what and why, not how
code-buddy/
├── .github/ # GitHub workflows and templates
│ └── workflows/ # CI/CD workflows
├── .husky/ # Git hooks
├── src/
│ ├── agent/ # Core agent logic (CodeBuddyAgent)
│ ├── codebuddy/ # Grok API client and tool definitions
│ ├── tools/ # Tool implementations
│ │ ├── bash-tool.ts
│ │ ├── file-tool.ts
│ │ ├── search-tool.ts
│ │ └── text-editor.ts
│ ├── ui/ # Ink/React UI components
│ │ ├── components/ # React components
│ │ └── utils/ # UI utilities
│ ├── utils/ # Utility functions
│ │ ├── path-validator.ts
│ │ ├── command-validator.ts
│ │ ├── confirmation-service.ts
│ │ ├── settings.ts
│ │ └── token-counter.ts
│ ├── types/ # TypeScript type definitions
│ ├── hooks/ # React hooks
│ └── index.ts # CLI entry point
├── dist/ # Compiled output
├── tests/ # Integration and E2E tests
├── AUDIT.md # Technical audit report
├── CONTRIBUTING.md # This file
├── ARCHITECTURE.md # Architecture documentation
└── README.md # User documentation
- Documentation: Check the README.md and ARCHITECTURE.md
- Issues: Browse existing issues
- Discussions: Join GitHub Discussions
- Discord: Join our Discord community
Contributors will be recognized in:
- The project README
- Release notes
- Our contributors page
Thank you for your contributions! 🎉