# Contributing
Fixes, parsers, patterns and bench results are all welcome. A change to a public type is worth an issue first, so we agree on the direction before you write it.
## Before you push
Run the checks CI runs:
```bash
hyperi-ci check
```
`hyperi-ci` is on PyPI. Install it with `uv tool install hyperi-ci`, or run it once with `uvx hyperi-ci check`. It runs the quality gates, the tests and the `wasm32-wasip2` build, as `.hyperi-ci.yaml` sets them.
Run tests by hand with `cargo nextest run --all-features`, never plain `cargo test`. nextest gives each test a process, and some tests reset state the whole process shares.
A speed change needs its bench. Run the bench before and after on an idle machine, and put both numbers in the pull request. [docs/performance.md](docs/performance.md) says which bench covers what.
## Commits
Commits follow [Conventional Commits](https://www.conventionalcommits.org/): `<type>(<scope>): <subject>`, scope optional. The type sets the next version, and CI cuts the release and the changelog on merge to `main`. Never edit a version number or `CHANGELOG.md` by hand.
| `fix`, `perf` | a bug fix, a speed-up | patch |
| `feat` | something a caller of the crate can do that they couldn't before | minor |
| `docs`, `test`, `refactor`, `build`, `ci`, `chore`, `style` | everything else | none |
Most changes are a `fix`. A major version is the maintainers' call: leave `!` and `BREAKING CHANGE:` out, and say in the pull request what a caller has to change.
To check each commit message as you write it:
```bash
git config core.hooksPath .githooks
```
## Pull requests
1. Fork, and branch from `main`.
2. Make the change, with its tests. A parser or pattern comes with lines it matches and lines it must reject.
3. Update the page in `docs/` that describes what you changed.
4. Run `hyperi-ci check`.
5. Open the pull request and say what changed and how you tested it.
## Licence for contributions
Contributions are licensed under the Apache License, Version 2.0, the same licence as the project.
## Context
### What this is
grippo is the parse, match and scrub engine, published as `grippo` on crates.io under Apache-2.0. It is a library: no async runtime, no network, no TLS, and the default features build for `wasm32-wasip2`. It assumes no application. A consumer's schema, field names and config loading belong to the consumer.
### Where things live
| `src/tier.rs`, `src/cost.rs` | `MatcherTier`, and the cost table read from `src/cost/x86_64.tsv` |
| `src/strmatch/` | the pattern classifier, the matcher, globs and signature sets |
| `src/field/`, `src/time/` | the field scanners, and timestamps to instants |
| `src/grok/` | the grok library (`patterns/`), the expander, the step planner and the compiled back end |
| `src/parse/` | the `Parser` trait, the sink, the chain driver, framing and config |
| `src/format/` | one stock parser a file, and `chain_tests.rs`, which runs them through the driver together |
| `src/scrub/`, `src/xml/`, `src/json.rs` | redaction, XML to JSON records, the JSON depth check |
| `grippo-macros/` | `pattern!`, `glob!` and `grok!`, in the workspace |
| `grippo-py/`, `fuzz/` | the Python binding and the fuzz target, each a separate workspace |
| `benches/`, `examples/`, `scripts/` | the Criterion benches, a workload for profile-guided builds, the optimised bench build |
| `tests/fixtures/` | scrub test strings and parity fixtures |
Three files are generated. A test fails when either of the first two is stale:
- `src/grok/stock.rs`: `cargo run -p grippo-macros --example stock > stock.rs`, then copy it over. The generator builds against the file it replaces.
- The table in `docs/replaces.md`, from `field::FIELDS`.
- `src/cost/x86_64.tsv`, written by the costs bench when `GRIPPO_COSTS_OUT` is set. A test fails when a field or a stock parser has no row in it.
### Commands that test a change
```bash
hyperi-ci check # everything below, as CI runs it
make quality # fmt, clippy, deny, audit
make test # the suite, under nextest
cargo build --target wasm32-wasip2 # the no-runtime-dependency gate
```
CI decides. Read the result of each CI job, never a local summary. A push that touches `docs/` or `*.md` alone starts no run, and a pull request always does.
### What tends to bite
| Declare rustflags under `[build]` | Put them under `[target.<triple>]` | cargo reads `build.rustflags` when no target entry exists, and a CI runner that sets `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` counts as one. The flags drop with no warning |
| Negate a file inside an excluded directory in `.gitignore` | Exclude with `.cargo/*` so the negation applies | `.cargo/` excludes the directory, so `!.cargo/config.toml` does nothing and the file never commits |
| Add a default-feature dependency that needs an OS runtime | Put it behind a feature | The `wasm32-wasip2` build fails, and so does every WASM and PyO3 consumer |
| Edit `src/grok/stock.rs` by hand | Change the pattern file and regenerate | The stale-file test fails |
| Call `unwrap`, `expect` or `panic!` in library code, or write `unsafe` | Return an error | The workspace lints deny all four. Tests may unwrap |
| Name another product's log tool, search tool or schema in a comment or a doc | Name the device, protocol or standard (syslog, CEF, an RFC) | Credits to other projects live in `NOTICE` and `docs/provenance.md` and nowhere else |
| Write a number into a doc from memory | Run the bench and copy its output into `docs/performance.md` with the date and build | A figure with no run behind it can't be checked |
### Where this sits
grippo depends on no other repository at build time. Its CI is the reusable Rust workflow in `hyperi-io/hyperi-ci`, called from `.github/workflows/ci.yml`, which runs the gates and cuts the release.
Inbound, any crate that depends on `grippo` or `grippo-macros` from crates.io follows a release here. `grippo-macros` asks for the `grippo` version it shipped with, so the two release together. A change to a public type or to the fields a stock parser writes reaches every consumer on its next update.