Thanks for taking the time to contribute.
This repo is a governed Rust service template + library. It bakes in:
- spec-as-code (ledger → features → tests → code),
- policy-as-code (Rego),
- LLM-native workflows (bundles, CLAUDE.md),
- Nix-pinned dev environment.
That means contributions should preserve (or improve) those properties, not bypass them.
- Rust (managed via
rustup, but we userust-toolchain.tomlin Nix) - Nix (recommended) or a native toolchain
- Git, GitHub account
Recommended:
justdirenv(optional, if you want auto devshell activation)
Golden path (Nix):
git clone https://github.com/EffortlessMetrics/Rust-Template.git
cd Rust-Template
# Enter devshell (Rust, conftest, yq, etc. pinned to match CI)
nix develop
# Sanity check
cargo run -p xtask -- selftestFallback (no Nix):
See docs/dev-environment.md. In this mode:
- Core checks and BDD work as usual.
- Policy tests are skipped locally unless you install
conftestyourself. - CI always enforces policies.
The xtask command provides a complete developer experience for this template.
Use flows, not individual commands, wherever possible.
nix developcargo xtask doctorcargo xtask check
doctorvalidates Rust, Cargo, Nix, and supporting toolscheckis the fast dev loop (fmt + clippy + tests)
-
Scaffold the AC:
cargo xtask ac-new AC-TPL-010 "User can cancel account" \ --story US-TPL-002 --requirement REQ-TPL-CANCEL -
Paste the AC snippet into
specs/spec_ledger.yamlunder the requirement -
Add a
@AC-TPL-010scenario to the appropriate file inspecs/features/ -
Regenerate the LLM bundle:
cargo xtask bundle implement_ac
-
Implement code + tests with LLM assistance
-
Run BDD and full gate:
cargo xtask bdd cargo xtask selftest
cargo xtask adr-new "Introduce order cancellation"
# edit docs/adr/NNNN-introduce-order-cancellation.md
cargo xtask adr-check- Record the decision in the ADR
- Link it from
specs/spec_ledger.yamlwhere appropriate
Whenever you touch Cargo.toml or Cargo.lock:
cargo xtask audit- Fix any vulnerabilities or license violations
- If you must accept a risk, document it in ADR-0007 before merging
cargo xtask release-prepare X.Y.Z # bump versions & seed changelog
# edit CHANGELOG.md entry as needed
cargo xtask release-verify # selftest + audit + docs-check
git commit -am "Release vX.Y.Z"
git tag -s vX.Y.Z -m "Release vX.Y.Z" # -s flag for GPG signing (recommended)
git push origin main --follow-tagsRecommended: Configure GPG signing for tags to ensure release authenticity. See docs/how-to/setup-tag-signing.md for setup instructions.
Version numbers are centrally tracked in specs/spec_ledger.yaml. All other files derive from this canonical source.
Canonical version authority: specs/spec_ledger.yaml → metadata.template_version
Files that must match:
| File | Pattern |
|---|---|
README.md |
H1 # ... (vX.Y.Z) or **Template Version:** vX.Y.Z |
CLAUDE.md |
H1 # ... (vX.Y.Z) |
docs/ROADMAP.md |
H1 # ... (vX.Y.Z) |
docs/KERNEL_SNAPSHOT.md |
H1 # Kernel Snapshot vX.Y.Z |
docs/explanation/TEMPLATE-CONTRACTS.md |
**Template Version:** vX.Y.Z |
specs/service_metadata.yaml |
template_version: vX.Y.Z |
specs/doc_index.yaml |
template_version: "X.Y.Z" |
CHANGELOG.md |
First version section ## [X.Y.Z] after [Unreleased] |
Bump workflow:
-
Update the canonical version:
# In specs/spec_ledger.yaml metadata: template_version: "X.Y.Z" last_updated: "YYYY-MM-DD"
-
Run
cargo xtask release-prepare X.Y.Z(updates most files automatically) -
Run
cargo xtask docs-checkto see any remaining mismatches -
Fix any files that weren't auto-updated
-
Run
cargo xtask selftestto validate -
Tag as
vX.Y.Z-kernel:git tag -s vX.Y.Z-kernel -m "Kernel release vX.Y.Z"
Verify canonical version programmatically:
cargo xtask version --json | jq .kernel_versioncargo xtask help-flowsShows a categorized map of all available commands organized by workflow.
This template treats governance as code. That shows up in three places:
- Pre-commit hooks
- Local selftest
- CI workflows
If you've installed the hooks via:
cargo xtask install-hooksthen git commit will run:
.git/hooks/pre-commit
→ cargo run -p xtask -- precommit
→ cargo xtask selftest (plus docs+spell checks)
Behaviour:
- The hook runs inside the Nix devshell when available.
- It automatically fixes and stages:
- Rust formatting (
cargo fmt --all) - Skills format (
SKILL.mdtidiness) - AC status report (
docs/feature_status.md)
- Rust formatting (
- It blocks the commit (hard gates) on:
- Clippy warnings
- Test failures
- Skills/Agents governance violations (policy errors)
- It warns but doesn't block (soft gates) on:
- Documentation consistency issues
- Spelling errors (unless
XTASK_STRICT_PRECOMMIT=1)
- It runs the full 8-step selftest, excluding
@ci-onlyBDD scenarios.
TL;DR: Just run git commit. Mechanical fixes are silent. Real failures show up clearly. If precommit fails, run nix develop -c cargo xtask precommit to see details, fix the issue, and commit again.
You should treat a red pre-commit as "something is actually wrong", not "test harness flaked".
The CI configuration mirrors and extends the local gates:
-
Tier 1:
cargo xtask selftest(required on main) -
Policy checks: OPA/Rego tests under
policy/*.rego -
Coverage/graph: AC coverage and graph invariants
-
Meta tests (CI-only):
AC-TPL-BDD-EXIT-CODES– harness exit semanticsAC-TPL-EXAMPLE-FORK-BUILDS– example fork builds and passes its own selftest
CI runs all BDD scenarios, including those tagged @ci-only:
CUCUMBER_TAG_EXPRESSION="" cargo test -p acceptance --test acceptanceLocal runs default to not @ci-only to avoid recursive selftest and git-worktree flakiness.
Before opening a PR:
nix develop
cargo xtask kernel-smoke
cargo xtask check
cargo xtask selftestIf selftest is red:
- Look at which gate failed (Core checks, BDD, Policy tests, etc.).
- Use
cargo xtask ac-statusto see which ACs are[FAIL]. - Fix the root cause or adjust the AC/tests in
specs/spec_ledger.yamlif you're intentionally changing the contract.
When bumping the template/kernel version:
-
Update
specs/spec_ledger.yamlmetadata.template_versionandlast_updated. -
Update
README.mdtemplate/kernel badges and "Kernel Version" in §14. -
Add/update the
[X.Y.Z]section inCHANGELOG.md. -
Update
docs/ROADMAP.mdfrontmatterlast_updatedand H1(vX.Y.Z). -
If needed, update
docs/KERNEL_SNAPSHOT.md. -
Run:
nix develop cargo xtask docs-check cargo xtask selftest
If docs-check or selftest fail, fix the misalignment before tagging.
Use topic branches:
feat/<area>-<short-description>fix/<area>-<short-description>docs/<area>-<short-description>
Example:
feat/app-http-tasks-apifix/policy-k8s-envfromdocs/llm-workflow-clarifications
For any doc changes, run cargo xtask docs-check before pushing.
CI treats doc issues as hard failures via XTASK_STRICT_PRECOMMIT=1.
See docs/how-to/change-docs-safely.md for detailed workflows.
Short, imperative subject:
feat(app-http): add tasks endpointfix(policy): avoid var shadowing in envFrom ruledocs: clarify Nix-first dev workflow
If a commit addresses a specific AC or issue, reference it in the body:
Implements AC-TPL-007 for metrics endpoint
Fixes #123
Before opening a PR:
# Inside nix develop (preferred)
cargo run -p xtask -- selftestThat runs:
fmt+clippy+ tests- BDD (Cucumber)
- AC status mapping
- LLM bundler checks
- Policy tests (if
conftestavailable, always in CI)
If you must skip some work locally (e.g., no Nix), make sure CI is green.
CI includes supply-chain hardening workflows (SBOM and provenance generation):
- Supply chain workflows:
.github/workflows/ci-supply-chain.ymlruns onv*.*.*tags- Generates an SBOM (
sbom.spdx.json) and build provenance for a source tarball - If this workflow fails on a release tag, fix it before publishing the GitHub Release
- Domain logic stays in
business-coreandmodel. - Adapters (HTTP, gRPC, DB) live in their crates and depend inward.
- Don't pull adapters into
business-core.
If you're unsure: check docs/explanation/hexagonal-architecture.md.
When you add or change behavior:
- Spec – update
specs/spec_ledger.yamlwith ACs and stories if needed. - BDD – add/update
.featurescenarios inspecs/features/. - Code – implement in the right crate (model/core/app-http/etc.).
- Tests – add unit/integration tests as needed.
- Policies – if infra/LLM behavior changes, update Rego + testdata.
- ADRs – for significant architectural changes:
- Copy
docs/templates/ADR-TEMPLATE.mdtodocs/adr/00XX-your-decision.md - Fill in context, decision, and consequences
- Reference it in
specs/spec_ledger.yaml(at story/requirement/AC level as appropriate) - Run
cargo run -p xtask -- adr-checkto validate references
- Copy
A typical feature flow:
-
Pick an AC (or add one) in
specs/spec_ledger.yaml. -
Add/update the matching scenario in
specs/features/*.feature. -
Generate an LLM bundle:
cargo run -p xtask -- bundle implement_ac
-
Use the instructions and prompts in
CLAUDE.mdto drive LLM-native changes. -
Apply/curate the changes locally.
-
Run:
cargo run -p xtask -- selftest
-
Commit and open a PR.
Useful commands:
# Fast path
cargo run -p xtask -- check
# Full template validation
cargo run -p xtask -- selftest
# Unit tests
cargo test --workspace
# BDD only
cargo run -p xtask -- bdd
# Policy tests only (if conftest installed)
cargo run -p xtask -- policy-testSome tests are marked #[ignore] when they:
- manipulate global state (e.g.,
set_current_dir), - or require external dependencies (e.g., Docker).
Those tests include comments explaining how to run them explicitly.
- Rust code:
rustfmt+clippy -D warnings - Rego: keep rules small and name things for intent, not implementation.
- YAML: prefer explicit structure over "clever" anchors for template users.
- Docs: short sections, headings, and examples. Avoid walls of text where possible.
We are committed to making participation in this project a harassment-free experience for everyone. Please read and follow our Code of Conduct.
This section is for changes that affect the kernel contract – the stable surfaces that forks and IDPs rely on.
A change is a kernel change if it modifies:
must_have_acACs inspecs/spec_ledger.yaml/platform/*endpoint response shapesxtaskgovernance commands (selftest, ac-status, kernel-status, idp-snapshot)- Schema files (
specs/openapi/**,specs/platform_schema.yaml) - Kernel documentation (
docs/KERNEL_SNAPSHOT.md,docs/IDP_CELL_CONTRACT.md)
Rule: Any kernel contract change requires ADR → version bump → kernel tag.
Step-by-step:
-
Draft an ADR explaining the change:
cargo xtask adr-new "Change X in kernel contract" # Edit docs/adr/NNNN-change-x-in-kernel-contract.md
-
Update the canonical version in
specs/spec_ledger.yaml:metadata: template_version: "X.Y.Z" # Increment appropriately last_updated: "YYYY-MM-DD"
-
Run release automation:
cargo xtask release-prepare X.Y.Z
-
Validate everything:
cargo xtask docs-check cargo xtask selftest
-
Generate release evidence:
cargo xtask release-bundle X.Y.Z
-
Tag the kernel:
git tag -s "vX.Y.Z-kernel" -m "Kernel release vX.Y.Z" git push origin main --tags
| Change Type | Example | Version Bump |
|---|---|---|
| Patch (3.3.8 → 3.3.9) | Bug fixes, doc clarifications, no API changes | Z |
| Minor (3.3.8 → 3.4.0) | New ACs, new endpoints, backward-compatible | Y |
| Major (3.3.8 → 4.0.0) | Breaking changes, removed/renamed endpoints | X |
Kernel-critical files are protected by CODEOWNERS. Changes to these files require review from kernel maintainers:
specs/spec_ledger.yamlspecs/openapi/**docs/KERNEL_SNAPSHOT.md,docs/IDP_CELL_CONTRACT.mdcrates/xtask/**crates/spec-runtime/**.github/workflows/tier1-selftest.yml
See CODEOWNERS for the full list.
- Detailed maintainer guide:
docs/how-to/maintain-kernel.md - Kernel evolution playbook:
docs/how-to/evolve-the-kernel.md - Current kernel snapshot:
docs/KERNEL_SNAPSHOT.md
If you're unsure whether a change fits:
-
Open a draft PR and describe:
- the problem,
- the AC or use case,
- your proposed approach.
-
Or open an issue referencing relevant ACs / features / policies.
Thanks again for contributing. This template is expressly meant to be used and evolved by people who care about governed, AI-assisted Rust services.