File size: 8,312 Bytes
8baf122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
---
title: "Code Conventions"
description: "Code style and convention guidelines for contributing to Bifrost."
icon: "brush"
---

## Commit Message Format

All commits to Bifrost should follow a standardized format. This ensures clear history and makes it easy to understand changes at a glance.

### Format

```
[type]: description

Optional body with more details
```

### Types

- **feat** - New feature
- **fix** - Bug fix
- **refactor** - Code refactoring (no feature change, no bug fix)
- **docs** - Documentation changes
- **test** - Test changes
- **chore** - Build, dependencies, tooling changes
- **perf** - Performance improvements

### Key Rule: Always List Affected Packages

For every commit, **explicitly mention all packages/directories that were modified**. This is crucial for understanding the scope of changes.

```
[fix]: Handle null pointer in model response

Affected packages:
- core/providers/openai/
- core/schemas/

Impact: Fixes intermittent crashes when provider returns malformed response
```

### Examples

**Good:**
```
[feat]: Add retry logic to MCP client manager

Implements exponential backoff for transient errors (connection timeouts, network issues).
Retries only for transient errors, fails immediately for permanent errors (auth, config).

Affected packages:
- core/mcp/clientmanager.go - Connection retry logic
- core/mcp/utils.go - Retry executor and error classification
- core/mcp/healthmonitor.go - Automatic reconnection

Tests:
- Added tests for retry backoff progression
- Added tests for error classification
```

**Better (if changes are significant to multiple packages):**
```
[feat]: Add resilient MCP connection handling

Commit 1: [feat]: MCP utils - Add retry executor with exponential backoff
Commit 2: [fix]: MCP client - Use retry logic for connection establishment
Commit 3: [feat]: MCP health monitor - Add automatic reconnection
```

## Go Code Conventions

### Style Guidelines

1. **Follow standard Go conventions**
   - Use `gofmt` for formatting
   - Run `make fmt` before committing

2. **Naming**
   - Use meaningful variable names
   - Avoid single letters except in loops
   - Use `camelCase` for variables and functions
   - Use `PascalCase` for exported types

3. **Comments**
   - Comment exported functions and types
   - Use clear, concise comments
   - Explain *why*, not *what*

4. **Error Handling**
   - Always check and handle errors
   - Provide context in error messages
   - Don't ignore errors with `_`

### Structure

```go
// Exported functions first
func NewClient(config Config) (*Client, error) {
    // implementation
}

// Exported methods
func (c *Client) Do(ctx context.Context) error {
    // implementation
}

// Unexported helper functions
func (c *Client) validate() error {
    // implementation
}
```

### Documentation

Each package should have:
- A `package` comment
- Exported function/type comments
- Complex logic explanations

```go
// Package mcp provides Model Context Protocol integration
// for connecting AI models to external tools and services.
package mcp

// Client manages connections to MCP servers.
type Client struct {
    // fields...
}

// Connect establishes a connection to the MCP server.
// Returns an error if the connection fails.
func (c *Client) Connect(ctx context.Context) error {
    // implementation
}
```

## TypeScript/React Code Conventions

### Style Guidelines

1. **Use TypeScript** - Avoid `any` types when possible
2. **Use functional components** - No class components
3. **Props interface**
   ```typescript
   interface ButtonProps {
     onClick: () => void;
     children: React.ReactNode;
   }
   ```

4. **Naming**
   - Components: `PascalCase`
   - Functions/variables: `camelCase`
   - Constants: `UPPER_SNAKE_CASE`

### Structure

```typescript
// Imports
import React from 'react';
import { useContext } from 'react';

// Types
interface Props {
  id: string;
  onSubmit: (data: FormData) => Promise<void>;
}

// Component
export const MyComponent: React.FC<Props> = ({ id, onSubmit }) => {
  return (
    <div>
      {/* implementation */}
    </div>
  );
};
```

## Testing Conventions

### Go Tests

1. **Test file naming**: `*_test.go`
2. **Test function naming**: `Test<FunctionName>`
3. **Table-driven tests for multiple cases**

```go
func TestProcessRequest(t *testing.T) {
    tests := []struct {
        name    string
        input   string
        want    string
        wantErr bool
    }{
        {"valid input", "test", "result", false},
        {"invalid input", "", "", true},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := ProcessRequest(tt.input)
            if (err != nil) != tt.wantErr {
                t.Errorf("unexpected error: %v", err)
            }
            if got != tt.want {
                t.Errorf("got %s, want %s", got, tt.want)
            }
        })
    }
}
```

### Running Tests

```bash
# Run all tests
make test-all

# Run specific test suite
make test-core PROVIDER=openai

# Run specific test case
make test-core PROVIDER=openai TESTCASE=TestName/SubTest
```

## Documentation Conventions

### MDX Files

1. **Front matter**
   ```mdx
   ---
   title: "Feature Name"
   description: "Brief description of the feature"
   icon: "icon-name"
   ---
   ```

2. **Headings** - Use H2 (`##`) as top level in body
3. **Code blocks** - Always include language: ` ```go`
4. **Links** - Use relative paths: `/features/caching`

### Examples

```mdx
---
title: "Semantic Caching"
description: "Intelligent response caching based on semantic similarity"
icon: "database"
---

## Overview

Semantic caching intelligently caches responses...

## Configuration

```yaml
plugins:
  semantic_cache:
    enabled: true
```

<Note>
This is important information that needs highlighting.
</Note>

## Benefits

- Reduces costs by 30-40%
- Improves latency for similar queries
```

## Pull Request Conventions

See [Raising a PR](/contributing/raising-a-pr) for detailed guidelines. Key points:

1. **Commit messages**: Follow `[type]: description` format
2. **Package listing**: Always mention affected packages
3. **Changelog updates**: Update `changelog.md` for each affected package
4. **Tests**: Ensure all tests pass before opening PR
5. **Documentation**: Update docs if behavior changes

## Changelog Format

For each package you modify, update its `changelog.md` file at the top with:

```
[type]: description [@Your Name](https://github.com/yourname)
```

**Example:**
```markdown
[feat]: add semantic caching support for image generation [@prathammaxim](https://github.com/prathammaxim)
[fix]: handle null pointer in response parsing [@username](https://github.com/username)
[refactor]: simplify model caching logic [@username](https://github.com/username)
```

**File locations:**
- `core/changelog.md`
- `framework/changelog.md`
- `transports/changelog.md`
- `plugins/{plugin-name}/changelog.md`

## Code Quality Standards

Before submitting code:

### Go Code
```bash
# Format code
make fmt

# Run linter
make lint

# Run tests
make test-all
```

### TypeScript/React
- Use ESLint configuration from project
- Run Prettier for formatting
- Ensure TypeScript compilation succeeds

## Key Principles

1. **Clarity** - Code should be easy to understand
2. **Consistency** - Follow existing patterns in codebase
3. **Testing** - All code should have tests
4. **Documentation** - Document public APIs and complex logic
5. **Simplicity** - Avoid over-engineering
6. **Performance** - Consider performance implications of changes

## Common Pitfalls

❌ **Don't:**
- Submit PRs without running tests
- Use `fmt.Println` for logging (use logger)
- Ignore error handling
- Create huge functions (>100 lines)
- Mix refactoring with feature changes
- Forget to list affected packages in commit messages

✅ **Do:**
- Run `make test-all` before opening PR
- Use structured logging
- Handle all error cases
- Keep functions focused and testable
- Make logical, focused commits
- Always mention affected packages and changes

## Getting Help

- See [Setting up the repository](/contributing/setting-up-repo) for development setup
- Check [Architecture docs](/architecture) to understand the codebase
- Ask in [Discord](https://discord.gg/exN5KAydbU) if you have questions