# Contributing to Korr

Thanks for your interest in Korr! Bug reports, documentation fixes, examples,
packages and code are all welcome. This guide explains how the project works and
how to get a change merged.

By taking part you agree to follow the [Code of Conduct](CODE_OF_CONDUCT.md).
Security problems go through [SECURITY.md](SECURITY.md), not public issues.

## Ways to contribute

* **Report a bug**: open an [issue](https://github.com/refkinscallv/korr/issues/new/choose)
  with the smallest `.krr` program that shows the problem, what you expected, what
  happened, and the output of `korr version` and your OS.
* **Suggest a feature**: open an issue first and describe the problem it solves.
  Korr aims to stay small, safe and easy to learn, so new syntax and built-ins are
  discussed before anyone writes code.
* **Improve the docs**: typos, unclear explanations and missing examples are
  among the most useful contributions. Docs live in `docs/en/`.
* **Write a package**: share reusable Korr code as a Git repository; see
  [Packages](docs/en/09-packages.md).
* **Fix an issue**: issues labelled `good first issue` are a good start. Comment
  on the issue so others know you are working on it.

## Development setup

You need the latest stable [Rust](https://rustup.rs) (`rustup update stable`; 1.85
is the minimum), a C compiler and Git. `./install.sh` sets all of them up.

```bash
git clone https://github.com/refkinscallv/korr.git
cd korr
cargo build --release
./target/release/korr -e 'print("ready")'
```

Install your build locally (binary + editor support) with `./install.sh`, or only
refresh the editor support with `./install.sh --editors-only`.

## Project layout

The [internals documentation](docs/internals/README.md) explains how every part
works; the table below is the short version.

| Path | What it is |
|---|---|
| `src/syntax/` | lexer, parser and syntax tree types |
| `src/compiler/` | name resolution (`resolver.rs`) and the bytecode compiler |
| `src/runtime/` | the virtual machine (`vm.rs`), values (`value.rs`), runtime services (`interp.rs`) |
| `src/stdlib/` | built-in functions and modules (`http`, `db`, `json`, `crypto`, ...) |
| `src/tools/` | the package manager (`pkg.rs`) and `korr setup` (`setup.rs`) |
| `src/cli/` | the `korr` command: run, REPL, test runner, `korr build`, `korr new` |
| `tests/` | Korr test suites (`*_test.krr`) and Rust integration tests |
| `examples/` | example programs and the `korr new` starter project |
| `editors/` | VS Code, Sublime Text and Vim support; `editors/tools/gen-editors.py` |
| `bench/` | benchmarks against PHP, Node.js and Python |
| `docs/en/` | the documentation |

## Making a change

1. Fork the repository and create a branch from `main`:
   `git checkout -b fix-string-split`.
2. Make your change. Keep it focused: one bug or feature per pull request.
3. Add or update tests (see below) and documentation.
4. Run the checks:

   ```bash
   cargo test --release                  # Rust unit + integration tests
   ./target/release/korr test tests      # Korr test suites
   ./target/release/korr test examples
   cargo fmt --check                     # formatting
   cargo clippy --release --all-targets -- -D warnings
   python3 scripts/check-docs.py         # links and code blocks in the docs
   ```

5. Commit with a clear message: a short summary line (imperative, under ~70
   characters, e.g. `Fix str.split with an empty separator`), a blank line, then
   what changed and why if it is not obvious.
6. Push and open a pull request against `main`. Fill in the template and link the
   issue (`Fixes #123`). CI runs the tests on Linux, macOS and Windows.

A maintainer reviews every pull request. Expect questions and requests for
changes; that is normal and not a rejection. Once CI passes and the review is
approved, the maintainer merges it.

## Guidelines

### Code

* **Safe Rust only.** No `unsafe` code in the interpreter, VM or standard library.
  The only exception is the operating-system random number call on Windows in
  `src/stdlib/crypto.rs`.
* **Security first.** User input must never reach a shell (`os.exec` passes
  arguments directly), HTML templates escape by default, SQL uses parameters,
  and limits (body size, nesting depth, recursion) stay in place. Read
  [Security model](docs/en/11-security.md) before touching these areas.
* **Speed matters, measured.** For changes to the compiler or VM, run
  `python3 bench/run.py` (or `--only <case>`) before and after, and include the numbers
  in the pull request. Do not trade safety for speed.
* **Clear errors.** Runtime and compile errors say what went wrong, where, and
  ideally how to fix it (`rt_hint(...)`).
* Follow the style of the surrounding code, and do not reformat code your change
  does not touch (it makes reviews hard).
* No new dependencies without discussing them first. Optional ones go behind a
  Cargo feature (see `Cargo.toml`) so the minimal build stays dependency-free.

### Tests

* Language features and built-ins: add a `test_*` function to the matching
  `tests/*_test.krr` file. Tests use `assert(...)` and `assert_eq(...)`.
* CLI behaviour, bundling and anything outside a single program: `tests/cli.rs`.
* Small Rust units: a `#[cfg(test)] mod tests` block next to the code
  (see `src/tools/pkg.rs`).
* Tests must pass on Linux, macOS and Windows: build paths with `path.join` and
  compare with `path.sep`, never hard-code `/`.

### Documentation

* Docs are in English, in `docs/en/`. Every user-visible change updates them in
  the same pull request.
* Code blocks marked `korr` must run as written; mark a block that only
  illustrates syntax with a first line `// no-check`.
* After changing the standard-library tables in
  `docs/en/05-standard-library.md`, regenerate the editor completion data:
  `python3 editors/tools/gen-editors.py`.
* Note user-visible changes in [CHANGELOG.md](CHANGELOG.md) under *Unreleased*.

## Releases (maintainers)

Follow [Releases and versioning](docs/internals/09-releases.md#release-gates):
every release passes the four gates (bugs, end-to-end security, documentation,
benchmarks) of `scripts/release-check.sh <version>` before it is tagged.

## Maintainer

Korr is created and maintained by [refkinscallv](https://github.com/refkinscallv).

## License

Korr is released under the [MIT License](https://github.com/refkinscallv/korr/blob/main/LICENSE). By contributing, you agree
that your contributions are licensed under the same license.
