|
| 1 | +# Contributing to GOPAL |
| 2 | + |
| 3 | +Thanks for considering a contribution. GOPAL is an open, community-curated library of [OPA](https://www.openpolicyagent.org/) Rego policies encoding AI-governance requirements; the more eyes on each rule, the better the policies get. |
| 4 | + |
| 5 | +## What we welcome |
| 6 | + |
| 7 | +- **New policies** for an existing framework (e.g. an additional EU AI Act article) |
| 8 | +- **New frameworks** (e.g. UK AI Principles, California SB-1047 successor, MAS banking AI guidance) |
| 9 | +- **New industry verticals** (e.g. media, energy, defence) |
| 10 | +- **Fixes** for bugs in existing policy logic |
| 11 | +- **Tests** — every policy should have a sibling `*_test.rego`. Missing tests on existing policies are open invitations. |
| 12 | +- **Translations** — the README ships in 5 languages. Native-speaker review of any of them is gold. |
| 13 | +- **Documentation** improvements (CONTRIBUTING, README, AGENTS, STYLE) |
| 14 | + |
| 15 | +## Before you open a PR |
| 16 | + |
| 17 | +1. **Open or check an issue first.** For new frameworks or larger additions, a quick "I'm planning to add X" comment avoids duplicate work. |
| 18 | +2. **Run the same checks CI runs.** See [Development](#development) below. |
| 19 | +3. **Match the existing policy shape.** Every policy file follows the same structure (package, imports, METADATA, default deny, allow rule, report). See [diagrams/diagram3_policy_anatomy_light.svg](diagrams/diagram3_policy_anatomy_light.svg) and any existing `.rego` for the canonical pattern. |
| 20 | +4. **Add a test sibling.** A new `foo.rego` needs a `foo_test.rego` covering both allow and deny cases. |
| 21 | +5. **Update [CHANGELOG.md](CHANGELOG.md)** under `[Unreleased]` with a one-line entry describing your change. |
| 22 | + |
| 23 | +## Development |
| 24 | + |
| 25 | +```bash |
| 26 | +# One-time setup |
| 27 | +pip install pre-commit |
| 28 | +curl -L -o opa https://openpolicyagent.org/downloads/latest/opa_linux_amd64 \ |
| 29 | + && chmod +x opa && sudo mv opa /usr/local/bin/ |
| 30 | +curl -L -o regal https://github.com/StyraInc/regal/releases/latest/download/regal_Linux_x86_64 \ |
| 31 | + && chmod +x regal && sudo mv regal /usr/local/bin/ |
| 32 | +pre-commit install |
| 33 | + |
| 34 | +# Run the checks CI runs |
| 35 | +opa check --ignore custom/ . |
| 36 | +regal lint --ignore-files custom/ . |
| 37 | + |
| 38 | +# Run tests for a specific package |
| 39 | +opa test international/eu_ai_act/v1/ |
| 40 | +``` |
| 41 | + |
| 42 | +If `opa check` fails it usually means a typo in a package path or an undeclared rule. If `regal lint` fails, run with `--format pretty` for human-readable advice on the issue. |
| 43 | + |
| 44 | +## Policy authoring conventions |
| 45 | + |
| 46 | +- **Package path mirrors the directory.** `international/eu_ai_act/v1/transparency.rego` declares `package international.eu_ai_act.v1.transparency`. |
| 47 | +- **Default deny.** Every policy starts with `default allow := false` so a missing rule produces a safe (deny) result, never an accidental allow. |
| 48 | +- **Metadata comments.** Use `# METADATA` followed by `# title:` and `# description:` so the rule is human-readable in audit reports. |
| 49 | +- **Report composition.** Use `data.helper_functions.reporting.compose_report(...)` to produce the standardized output shape — don't roll your own report dict. The helper guarantees the field names auditors expect. |
| 50 | +- **Versioning.** New frameworks go under `<framework>/v1/`. When a regulation amends, the old `v1/` stays put and a new `v2/` ships alongside. See [COMPATIBILITY.md](COMPATIBILITY.md). |
| 51 | +- **Reference data needed?** Add it as a constant inside the policy or under a sibling `_data.rego`. Avoid runtime dependencies on external services. |
| 52 | + |
| 53 | +## Adding a new framework |
| 54 | + |
| 55 | +The fastest path: |
| 56 | + |
| 57 | +1. Decide where it goes: `international/`, `industry_specific/`, `global/`, or `operational/`. |
| 58 | +2. `mkdir <category>/<framework>/v1/` |
| 59 | +3. Drop in a first policy that follows the standard shape. The [`draft-rego-policy`](skills/draft-rego-policy/SKILL.md) skill scaffolds this for you under Claude Code. |
| 60 | +4. Add a test sibling. |
| 61 | +5. Update the README count + add a row under "What's Inside". |
| 62 | +6. Open a PR. |
| 63 | + |
| 64 | +## PR review |
| 65 | + |
| 66 | +PRs are reviewed for: |
| 67 | + |
| 68 | +1. **Correctness** — does the policy logic accurately encode the regulation? |
| 69 | +2. **Test coverage** — does the test cover both allow and deny? Edge cases? |
| 70 | +3. **Style** — `opa check` + `regal lint` clean? Matches existing patterns? |
| 71 | +4. **Scope** — single concern per PR, easier to revert. |
| 72 | + |
| 73 | +We aim to respond within 5 business days. Larger framework additions may take longer if the regulator's text needs verification. |
| 74 | + |
| 75 | +## Custom policies |
| 76 | + |
| 77 | +The `custom/` directory is `.gitignore`d and CI-skipped — that's where your organization's proprietary rules go. They evaluate alongside the public set without ever being pushed to this repo. See the [README's Custom Policies section](README.md#custom-policies). |
| 78 | + |
| 79 | +## Community |
| 80 | + |
| 81 | +- **Questions** — open a [Discussion](https://github.com/Principled-Evolution/gopal/discussions) or comment on the relevant issue. |
| 82 | +- **Security disclosures** — see [SECURITY.md](SECURITY.md). Do not file public issues for vulnerabilities. |
| 83 | +- **Code of conduct** — be kind, assume good faith, focus on the work. |
| 84 | + |
| 85 | +## License |
| 86 | + |
| 87 | +By contributing, you agree your contributions will be licensed under the [Apache License 2.0](LICENSE), the same license as GOPAL itself. |
0 commit comments