chipp 0.3.0

Rust client for the Chipp.ai API - OpenAI-compatible chat completions with streaming support
Documentation
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# Contributing to chipp-rs

Thank you for your interest in contributing to chipp-rs! This document provides guidelines and instructions for contributing.

## Table of Contents

- [Code of Conduct]#code-of-conduct
- [How to Contribute]#how-to-contribute
- [Development Setup]#development-setup
- [Pre-Commit Hooks]#pre-commit-hooks
- [Code Quality Standards]#code-quality-standards
- [Testing]#testing
- [Pull Request Process]#pull-request-process
- [Release Process]#release-process

---

## Code of Conduct

We are committed to providing a welcoming and inclusive environment. All contributors are expected to:

- Be respectful and inclusive in language and actions
- Accept constructive criticism gracefully
- Focus on what is best for the community and project
- Show empathy towards other community members

Harassment, trolling, or exclusionary behavior will not be tolerated.

---

## How to Contribute

### Reporting Bugs

Found a bug? Please [open an issue](https://github.com/paulbreuler/chipp-rs/issues/new) with:

- **Clear title**: Brief description of the bug
- **Environment**: Rust version, OS, chipp version
- **Steps to reproduce**: Minimal code example if possible
- **Expected behavior**: What you expected to happen
- **Actual behavior**: What actually happened
- **Error messages**: Full error output, stack traces

### Suggesting Features

Have an idea? Please [open an issue](https://github.com/paulbreuler/chipp-rs/issues/new) with:

- **Use case**: What problem does this solve?
- **Proposed solution**: How should it work?
- **Alternatives considered**: Other approaches you've thought about
- **Examples**: API design ideas, code snippets

### Contributing Code

1. Check [existing issues]https://github.com/paulbreuler/chipp-rs/issues for something to work on
2. Comment on the issue to let others know you're working on it
3. Fork the repository and create a feature branch
4. Follow the [Development Setup]#development-setup below
5. Submit a pull request following the [PR Process]#pull-request-process

---

## Development Setup

### Prerequisites

- **Rust 1.83+** (MSRV): Install via [rustup]https://rustup.rs/ <!-- x-sync-msrv: Cargo.toml rust-version -->
  ```bash
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  rustup component add rustfmt clippy
  ```

- **Just** (optional but recommended): Command runner for common tasks
  ```bash
  # Using Homebrew (macOS)
  brew install just

  # Using cargo
  cargo install just
  ```

- **Pre-commit** (optional): Git hooks for automatic quality checks
  ```bash
  # Using pip
  pip install pre-commit

  # Using Homebrew (macOS)
  brew install pre-commit
  ```

### Clone and Setup

```bash
# Clone the repository
git clone https://github.com/paulbreuler/chipp-rs.git
cd chipp-rs/chipp-rs

# Install pre-commit hooks (optional)
pre-commit install

# Verify setup
cargo build
cargo test
```

### Quick Start with Just

If you have `just` installed, you can run common tasks easily:

```bash
# Run all quality checks (fmt, clippy, tests, docs)
just quality

# Format code
just fmt

# Run tests
just test

# Build docs and open in browser
just docs-open

# See all available commands
just --list
```

---

## Pre-Commit Hooks

Pre-commit hooks automatically enforce code quality standards before commits are allowed.

### What Gets Checked

The pre-commit hooks run the following checks:

1. **`cargo fmt --check`** - Verifies code is formatted correctly
2. **`cargo clippy`** - Lints code and enforces zero warnings
3. **File quality checks** - Trailing whitespace, file endings, YAML/TOML syntax, etc.

### Installing Hooks

After cloning the repository, install the hooks:

```bash
pre-commit install
```

This creates a `.git/hooks/pre-commit` script that runs automatically on every commit.

### Running Hooks Manually

You can run the hooks manually without committing:

```bash
# Run on all files
pre-commit run --all-files

# Run on staged files only
pre-commit run

# Run a specific hook
pre-commit run cargo-fmt
pre-commit run cargo-clippy
```

### Bypassing Hooks (Emergency Only)

If you need to commit without running hooks (not recommended):

```bash
git commit --no-verify -m "Emergency fix"
```

**Note**: CI will still run these checks, so bypassing locally only delays the feedback.

### Updating Hooks

To update pre-commit hooks to the latest versions:

```bash
pre-commit autoupdate
```

### Common Issues

**Issue**: `cargo fmt` or `cargo clippy` not found

**Solution**: Ensure Rust toolchain is installed and in your PATH:
```bash
rustup component add rustfmt clippy
```

**Issue**: Hooks are slow

**Solution**: Hooks run `cargo clippy` on the entire workspace, which can be slow. Consider:
- Running `cargo clippy` manually before committing
- Using `--no-verify` for WIP commits (but fix before pushing)

---

## Code Quality Standards

All PRs must pass the same checks as CI. Here's what CI runs:

| Check | Command | Requirement |
|-------|---------|-------------|
| Formatting | `cargo fmt --all -- --check` | No formatting issues |
| Linting | `cargo clippy --all-targets --all-features -- -D warnings` | Zero warnings |
| Tests | `cargo test --verbose` | All tests pass |
| Doc tests | `cargo test --doc` | All doc examples compile |
| Documentation | `cargo doc --no-deps --all-features` | No doc warnings |
| Coverage | `cargo llvm-cov` | ≥80% line coverage |
| MSRV | `cargo check` with Rust 1.83 | Compiles on MSRV | <!-- x-sync-msrv: Cargo.toml rust-version -->
| Semver | `cargo semver-checks check-release` | No breaking changes (minor/patch) |

### Quick Check: Run All Quality Checks

```bash
# Using just (recommended)
just quality

# Or manually
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --verbose
cargo test --doc
cargo doc --no-deps --all-features
```

### Formatting

All code must be formatted with `rustfmt`:

```bash
cargo fmt --all
```

We use the default `rustfmt` configuration. Do not commit unformatted code.

### Linting

All code must pass `clippy` with zero warnings:

```bash
cargo clippy --all-targets --all-features -- -D warnings
```

Fix all clippy warnings before committing. If you believe a warning is a false positive, use `#[allow(clippy::lint_name)]` with a comment explaining why.

### Documentation

- **Every public item** must have documentation
- **Examples** in doc comments must compile and run
- **Crate-level docs** in `src/lib.rs` must be comprehensive

Verify docs build without warnings:

```bash
cargo doc --no-deps --all-features
```

Preview locally: `cargo doc --open`

Documentation is automatically built on [docs.rs](https://docs.rs/chipp) when published.

### Testing

- **Unit tests** for all public APIs
- **Integration tests** for real API calls (gated behind `integration-tests` feature)
- **Doc tests** for all examples in documentation
- **Code coverage**: Minimum 80% line coverage required

Run tests:

```bash
# Unit tests
cargo test --lib

# Integration tests (requires API key)
export CHIPP_API_KEY="your-api-key"
export CHIPP_APP_NAME_ID="your-app-name-id"
cargo test --features integration-tests -- --ignored

# Doc tests
cargo test --doc
```

### Code Coverage

We enforce a minimum of **80% line coverage** for all code changes.

**Check coverage locally:**

```bash
# Generate HTML coverage report (shows uncovered lines)
just coverage

# Check if coverage meets 80% threshold (shows uncovered lines)
just coverage-check

# View detailed coverage report in browser
open target/llvm-cov/html/index.html
```

**Understanding coverage output:**

The `--show-missing-lines` flag provides detailed information about uncovered code:

```
TOTAL    297    144    51.52%    29    11    62.07%    246    114    53.66%    0    0    -
Uncovered Lines:
/path/to/src/lib.rs: 217, 218, 219, 358, 359, 360, ...
```

This shows:
- **Line coverage**: 53.66% (246 total lines, 114 uncovered)
- **Region coverage**: 51.52% (297 regions, 144 uncovered)
- **Function coverage**: 62.07% (29 functions, 11 uncovered)
- **Uncovered lines**: Exact line numbers that need test coverage

**Install cargo-llvm-cov:**

```bash
cargo install cargo-llvm-cov
```

**Coverage requirements:**

- All new features must include tests
- Bug fixes should include regression tests
- Coverage must not decrease with new PRs
- Integration tests are excluded from coverage (require API keys)

**CI enforcement:**

- GitHub Actions automatically checks coverage on all PRs using `cargo-llvm-cov`
- PRs that drop coverage below 80% will fail CI
- No external services required - all coverage checking is done locally in CI

**Viewing coverage:**

After running `just coverage`, open `target/llvm-cov/html/index.html` in your browser to see:
- Line-by-line coverage
- Function coverage
- Branch coverage
- Uncovered code highlighted in red

---

## Pull Request Process

### Branch Naming

Use descriptive branch names with a type prefix:

```
<type>/issue-<number>-<short-description>
```

Examples:
- `feat/issue-26-add-health-check`
- `fix/issue-15-timeout-handling`
- `docs/contributing-update`

### Before Submitting

1. **Run all checks locally**:
   ```bash
   # Using just (recommended)
   just quality

   # Or manually
   cargo fmt --all
   cargo clippy --all-targets --all-features -- -D warnings
   cargo test --verbose
   cargo test --doc
   cargo doc --no-deps --all-features
   ```

2. **Update documentation**:
   - Add/update doc comments for new/changed APIs
   - Update README.md if adding features

3. **Add tests**:
   - Unit tests for new functionality
   - Integration tests for API changes (feature-gated)
   - Doc tests for examples

### Conventional Commit Format

We use [Conventional Commits](https://www.conventionalcommits.org/) for all commits and PR titles:

| Type | Description |
|------|-------------|
| `feat:` | New feature |
| `fix:` | Bug fix |
| `docs:` | Documentation only |
| `style:` | Formatting, whitespace |
| `refactor:` | Code change (no new feature or fix) |
| `perf:` | Performance improvement |
| `test:` | Adding or updating tests |
| `chore:` | Maintenance, dependencies |

**Breaking changes**: Add `!` after the type (e.g., `feat!: remove deprecated API`)

Examples:
```
feat: add exponential backoff retry logic
fix: handle partial SSE events in streaming
docs: add error handling examples
test: add unit tests for retry behavior
feat!: change chat() return type to Result
```

### PR Guidelines

- **Title**: Use conventional commit format
- **Description**: Explain what changed and why
- **Link issues**: Reference related issues (e.g., `Closes #123`)
- **Keep focused**: One feature/fix per PR
- **Rebase**: Keep commits clean and rebased on latest main

### Review Process

1. **Automated checks**: All CI checks must pass
2. **Code review**: At least one maintainer approval required
3. **Documentation**: Verify docs are complete and accurate
4. **Testing**: Verify tests cover new functionality

---

## Release Process

> **Note**: Releases are automated via [Release Please]https://github.com/googleapis/release-please. Contributors don't need to manage versions or changelogs manually.

### How It Works

1. **Write conventional commits** - Your commit messages determine the version bump:
   - `feat:` → Minor version bump (0.1.0 → 0.2.0)
   - `fix:` → Patch version bump (0.1.0 → 0.1.1)
   - `feat!:` or `fix!:` → Major version bump (0.1.0 → 1.0.0)

2. **Merge to main** - When PRs are merged, Release Please:
   - Analyzes conventional commits since last release
   - Creates/updates a Release PR with version bump and changelog

3. **Merge Release PR** - When maintainers merge the Release PR:
   - Git tag is created automatically
   - GitHub Release is published
   - Crate is published to crates.io via CI

### Versioning

We follow [Semantic Versioning](https://semver.org/):

| Version | When to use | Example commits |
|---------|-------------|-----------------|
| **MAJOR** (1.0.0) | Breaking changes | `feat!: remove deprecated API` |
| **MINOR** (0.2.0) | New features | `feat: add health check methods` |
| **PATCH** (0.1.1) | Bug fixes | `fix: handle timeout correctly` |

### Manual Changelog (git-cliff)

For local previews or manual changelog generation, we also support [git-cliff](https://git-cliff.org/):

```bash
# Preview unreleased changes
git-cliff --unreleased

# Generate full changelog
git-cliff --output CHANGELOG.md
```

The repository includes a `cliff.toml` configuration file for changelog formatting.

---

## Getting Help

- **Issues**: [Open an issue]https://github.com/paulbreuler/chipp-rs/issues/new for bugs or feature requests
- **Documentation**: See [README.md]README.md and [docs.rs/chipp]https://docs.rs/chipp

---

## License

By contributing, you agree that your contributions will be licensed under the same license as the project (MIT OR Apache-2.0).

This is a standard open-source licensing practice. You retain copyright to your contributions while granting the project permission to use them.