|
| 1 | +# Agent Rules for Apache Pekko Samples |
| 2 | + |
| 3 | +If this file conflicts with community conventions, update this file. |
| 4 | + |
| 5 | +## Worktree Rules |
| 6 | + |
| 7 | +- Base new work on `origin/main` unless the user or maintainer requests another branch. |
| 8 | +- Keep every PR scoped to one change. |
| 9 | +- Do not mix behavior changes, formatting churn, dependency updates, and unrelated cleanup. |
| 10 | +- Do not revert user changes or unrelated local changes. |
| 11 | +- Use `rg` or `rg --files` for repository searches. |
| 12 | +- Read neighboring code before editing. |
| 13 | +- Preserve existing license and copyright notices. |
| 14 | +- Do not add `@author` tags. |
| 15 | +- Follow the Licensing Rules below for every new file. |
| 16 | + |
| 17 | +## Project Structure |
| 18 | + |
| 19 | +- Each sample is a standalone sbt project in its own directory (e.g., `pekko-sample-cluster-java/`). |
| 20 | +- Each sample has its own `build.sbt` and `README.md`. |
| 21 | +- Samples come in Java and Scala variants where applicable. |
| 22 | +- The `docs-gen/` directory generates documentation from samples. |
| 23 | + |
| 24 | +## Licensing Rules |
| 25 | + |
| 26 | +- Do not hand-write or invent license headers. Let sbt manage them. |
| 27 | +- For new files, run `sbt headerCreateAll` to add the correct header. Do not manually paste header text. |
| 28 | +- Existing files with copyright statements must keep those copyright statements intact. Never delete or rewrite an existing copyright notice; only add information. |
| 29 | +- New files containing new code must use the standard Apache license header. |
| 30 | + |
| 31 | +## PR Rules |
| 32 | + |
| 33 | +- Every sample change must keep the sample compilable and runnable. |
| 34 | +- Sample changes must update the corresponding `README.md`. |
| 35 | +- Java and Scala variants of the same sample must stay in sync. |
| 36 | +- Dependency changes must verify Apache-compatible licenses. |
| 37 | +- Do not break the `docs-gen` build when changing samples referenced by documentation. |
| 38 | + |
| 39 | +## Formatting Rules |
| 40 | + |
| 41 | +- Prefer native scalafmt for changed Scala and SBT files when it is available. |
| 42 | + |
| 43 | +```shell |
| 44 | +git fetch origin main |
| 45 | +scalafmt --mode diff-ref=origin/main |
| 46 | +scalafmt --list --mode diff-ref=origin/main |
| 47 | +``` |
| 48 | + |
| 49 | +- If native scalafmt is not installed, use the sbt scalafmt tasks or record that scalafmt could not be run. |
| 50 | + |
| 51 | +```shell |
| 52 | +sbt scalafmtAll scalafmtSbt |
| 53 | +sbt scalafmtCheckAll scalafmtSbtCheck |
| 54 | +``` |
| 55 | + |
| 56 | +- Use JDK 17 for Java formatter tasks. |
| 57 | + |
| 58 | +```shell |
| 59 | +export JAVA_HOME=$(/usr/libexec/java_home -v 17) |
| 60 | +export PATH="$JAVA_HOME/bin:$PATH" |
| 61 | +sbt javafmtAll |
| 62 | +``` |
| 63 | + |
| 64 | +- Run header generation before PR. |
| 65 | + |
| 66 | +```shell |
| 67 | +sbt headerCreateAll |
| 68 | +``` |
| 69 | + |
| 70 | +- Do not rely on IDE formatting alone. |
| 71 | +- Do not commit unrelated formatting changes. |
| 72 | + |
| 73 | +## Validation Rules |
| 74 | + |
| 75 | +- Run the sample's tests. |
| 76 | + |
| 77 | +```shell |
| 78 | +cd pekko-sample-name |
| 79 | +sbt test |
| 80 | +``` |
| 81 | + |
| 82 | +- Compile the sample to verify it remains valid. |
| 83 | + |
| 84 | +```shell |
| 85 | +cd pekko-sample-name |
| 86 | +sbt compile |
| 87 | +``` |
| 88 | + |
| 89 | +- Run docs-gen to verify documentation generation. |
| 90 | + |
| 91 | +```shell |
| 92 | +cd docs-gen |
| 93 | +sbt run |
| 94 | +``` |
| 95 | + |
| 96 | +- Always run `git diff --check`. |
| 97 | +- Do not assume local tools such as `sbt` or `scalafmt` are installed; if a required tool is missing, record the missing tool and skipped command in `Tests`. |
| 98 | +- Skipped or environment-failed commands must be recorded in `Tests`. |
| 99 | + |
| 100 | +## Code Rules |
| 101 | + |
| 102 | +- Samples must be self-contained and easy to understand. |
| 103 | +- Prefer clarity over cleverness in sample code. |
| 104 | +- Each sample should demonstrate a specific Pekko feature or pattern. |
| 105 | +- Keep Java and Scala variants functionally equivalent. |
| 106 | +- Use `scala.jdk.*` converters for Java/Scala interop in Scala samples. |
| 107 | + |
| 108 | +## Commit and PR Format |
| 109 | + |
| 110 | +- Use this body format for non-trivial commits. |
| 111 | + |
| 112 | +```text |
| 113 | +Motivation: |
| 114 | +Problem or requirement. |
| 115 | +
|
| 116 | +Modification: |
| 117 | +Change summary. |
| 118 | +
|
| 119 | +Result: |
| 120 | +New outcome. |
| 121 | +
|
| 122 | +Tests: |
| 123 | +- command/result or Not run - docs only |
| 124 | +
|
| 125 | +References: |
| 126 | +Fixes #1234, Refs #1234, or None - <short context> |
| 127 | +``` |
| 128 | + |
| 129 | +- Use this PR body format. |
| 130 | + |
| 131 | +```markdown |
| 132 | +### Motivation |
| 133 | +Problem or requirement. |
| 134 | + |
| 135 | +### Modification |
| 136 | +Change summary. |
| 137 | + |
| 138 | +### Result |
| 139 | +New outcome. |
| 140 | + |
| 141 | +### Tests |
| 142 | +- command/result or Not run - docs only |
| 143 | + |
| 144 | +### References |
| 145 | +Fixes #1234, Refs #1234, or None - <short context> |
| 146 | +``` |
| 147 | + |
| 148 | +- Never omit `Tests`. |
| 149 | +- Never omit `References`. |
| 150 | +- Use `Refs #...`, `Fixes #...`, or `None - <short context>`. |
| 151 | +- Do not add `Co-authored-by` or AI-assistant trailers to commits or PR descriptions. |
0 commit comments