# Contributing

kurama is a small Go project with a safety promise: a default run must not break
a working browser. Contributions are welcome if they respect that promise,
follow the existing package boundaries, and come with tests.

## Development setup

Requirements:

- Go 1.24 or newer.
- Firefox for integration work.
- Optional: Python 3.9+, `selenium`, and `pytest` for the GUI test suite. The
  product and its integration tests use the bundled geckodriver.

```bash
git clone https://codeberg.org/farba/kurama.git
cd kurama
go build ./...
go test ./...
go run ./cmd/kurama
```

There is no JavaScript build step. The GUI is plain HTML, CSS, and ES modules
embedded with `go:embed`.

Useful commands:

```bash
go run ./cmd/kurama cli
go run ./cmd/kurama apply --dry-run --preset balanced
go run ./cmd/kurama serve --json
python -m pytest tests/selenium -v
```

## Branch and commit style

The project uses short-lived feature branches merged into `rewrite/v2` during the
v2 rewrite, then into `main`:

```
main
└── rewrite/v2
    ├── feat/…
    ├── fix/…
    └── docs/…
```

- One concern per branch.
- Commit messages use `type(scope): imperative summary`, for example
  `feat(addons): install selected add-ons through WebDriver`.
- Explain **why** in the body, not just what changed. Mention user-visible
  behaviour, safety implications, and tests.
- Keep commits buildable. Avoid mixing formatting-only changes with logic.
- Do not rewrite published history.

Example:

```
fix(browser): expand Windows %VAR% paths before detection

Firefox can be registered with an environment variable in profiles.ini.
Path checks compared the literal %APPDATA% string and reported a missing
profile. Expand the variable first while preserving unknown variables.
```

## Adding a preference bundle

1. Create `internal/prefs/data/<name>.txt` using only:
   `user_pref("name", value);`, comments, and blank lines.
2. Add a `model.Option` to `internal/catalog/options.go`:
   - unique `ID` used by the CLI and URL,
   - plain-language title, summary, and description,
   - a `Warning` when the change can break a site or service,
   - honest `Risk`: `low`, `medium`, or `high`,
   - `Default: false` unless the change is effectively free,
   - the file name.
3. Decide which presets enable it. Do not add high-risk options to Balanced.
4. Add the package's validation coverage if the syntax is unusual.
5. Update `docs/configuration.md` and `docs/gui.md` when the user-facing list
   changes.

Preference rules:

- Prefer prefs that are supported by current Firefox and documented upstream.
- Do not lock prefs. Users must be able to change them.
- Do not add a pref merely because it sounds private. Measure the breakage.
- Never disable a security feature (signature checks, safe browsing, updates)
  just to make another feature easier.
- Do not claim network anonymity. kurama changes browser behaviour, not IP
  identity.
- Comments in preference files are for contributors and curious users. Keep
  them accurate.

Phoenix, Betterfox, and arkenfox are inspiration, not code to copy. If you port a
specific idea, keep the source attribution and verify the license. kurama is
GPL-3.0; do not paste code with an incompatible license.

## Adding an add-on

1. Add a `model.Addon` in `internal/catalog/addons.go` with a stable ID and an
   `https://addons.mozilla.org/.../addon/<slug>/` URL.
2. Add slug parsing coverage in `internal/addons/amo_test.go`.
3. Set `Recommended` only for broadly useful, low-surprise add-ons.
4. Add a `Warning` or `Note` for add-ons with prerequisites or conflicts.
5. If the add-on is bundled, it also needs a signed XPI in
   `internal/addons/data/` and an `IsBundled` entry.
6. Update `docs/addons.md`.

Do not add an add-on that requires payment, a subscription, or a desktop app
without saying so in the description.

## Adding a bookmark or interest

Bookmarks and interests are data, not code:

- `internal/catalog/bookmarks.go` — ID, title, URL, description, interest tags,
  `Essential` only for near-universal sites.
- `internal/catalog/interests.go` — broad, plain-language categories.

Use HTTPS URLs, stable sites, and no affiliate or tracking links. Keep
descriptions short enough for a card.

## Changing the GUI

The browser GUI has strict constraints:

- No inline `<script>` or `style="..."` attributes. The CSP is
  `default-src 'self'; script-src 'self'; style-src 'self'; ...`.
- No third-party fonts, scripts, images, or analytics.
- Dynamic dimensions are set through the CSS object model, not style strings.
- Render with the project's tagged template helpers so user text is escaped.
  `html` escapes interpolations; `raw` is only for trusted markup.
- Keep ES modules small and grouped under `views/`.
- Every interactive control needs a label, keyboard access, and a visible focus
  state.
- Test at 390 px width; the page must not scroll horizontally.
- The theme must work in dark and light modes.

Selenium selectors live in `tests/selenium/kurama/gui.py`. If you rename a data
attribute, update the page object.

## Changing the API or security model

The loopback server is a security boundary. Changes here need extra care:

- Keep the default bind to `127.0.0.1`.
- Keep token → HttpOnly, SameSite=Strict cookie exchange.
- Keep Host and Origin checks on state-changing requests.
- Do not add a CORS allowlist or wildcard.
- Validate uploaded files by kind, extension, size, and destination.
- Never return absolute paths outside the selected profile or session upload
  directory without a reason.
- Add a test for every new route and for every rejection path.

## Adding tests

- Unit tests go next to the package as `*_test.go`.
- Tests must not touch the developer's real browser profiles; use `t.TempDir()`
  or a synthetic browser.
- Network tests are opt-in and tagged or marked so CI stays hermetic.
- For a bug fix, add a test that fails before the fix.
- For the Selenium suite, use the existing fixtures and page object. Mark tests
  with `gui`, `profile`, `network`, or `slow` as appropriate.

See [testing.md](testing.md).

## Documentation

Docs live in `docs/`. Update the relevant page in the same commit as the
behaviour change. The root `README.md` is the front door; the download page `index.html` is a
static site with supporting assets under `website/`, and it is not generated
from the GUI.

Keep instructions runnable on Windows, Linux, and macOS. When a path differs, say
so explicitly.

## Formatting and checks

```bash
gofmt -w $(git ls-files '*.go')
go vet ./...
go build ./...
go test ./...
```

Use the repository's `.editorconfig`: UTF-8, LF, final newline, two-space
indent except Go and Makefile.

Before opening a pull request:

1. Rebase on the current target branch.
2. Run the unit tests and any relevant integration/Selenium tests.
3. Update docs and the changelog-like commit body.
4. Describe the user-visible impact and any remaining risk.

## License

By contributing, you agree that your changes are licensed under
GPL-3.0-or-later, the same license as kurama. Preserve copyright notices and
attribution in preference files and documentation.
