diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8b9a8daf..5c25d4ee 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -6,7 +6,8 @@ pass before it is proposed. How this project writes prose — README, changelog, release notes, commit messages, API documentation, and source comments — is set out separately in -[`WRITING.md`](WRITING.md). Read that before changing any of it. +[`WRITING.md`](WRITING.md). Read that before changing any of it. For layer +ownership, boundaries, and review rules, read [`REVIEW.md`](../REVIEW.md). A Gradle directory is a published artifact exactly when it declares a Maven publication, and the Gradle build fails when that set stops matching @@ -339,7 +340,43 @@ What a change is expected to carry: that say why rather than what, no abstraction without a second caller. Commit format is in [`WRITING.md`](WRITING.md). The constraints every change is -held to, whatever it touches, are in [`AGENTS.md`](../AGENTS.md). +held to, whatever it touches, are in [`AGENTS.md`](../AGENTS.md) and +[`REVIEW.md`](../REVIEW.md). + +For bug fixes and behavioural changes (against `origin/master`, or +`` when fixing a defect introduced earlier in the same pull +request), temporarily restore modified `src/main/` sources and remove newly +added `src/main/` sources while keeping `src/test/`, `integration-tests/`, and +`libtmux-junit5/` intact: + +```console +$ : "${BITE_TEST:?set BITE_TEST to the regression test}" && \ + wt=$(mktemp -d) && \ + git worktree add --quiet --detach "$wt" HEAD && \ + ( cd "$wt" && \ + base=${BITE_BASE:-origin/master} && \ + git diff --name-only --no-renames "$base" HEAD | \ + grep -E '(^|/)src/main/.*\.(java|kt|scala|clj)$' | \ + grep -Ev '^libtmux-junit5/' \ + > bite.files && \ + git restore --source="$base" --worktree \ + --pathspec-from-file=bite.files && \ + { ./gradlew test :integration-tests:test 2>&1 | tee bite.log; \ + grep -E ' > .* FAILED$' bite.log | \ + grep -F -- "$BITE_TEST"; } ); \ + bite=$?; \ + git worktree remove --force "$wt"; \ + test "$bite" -eq 0 +``` + +This runs in a disposable `git worktree` at `HEAD`, so the checkout and any +uncommitted edit stay untouched; commit the change first. Set `BITE_TEST` to +the test method's name. `BITE_BASE` defaults to `origin/master`; set it to the +pre-fix commit when the defect was introduced earlier in the same pull request. +The command succeeds only when the runner reports that test as failed, and it +prints the failure line. A missing runner, a build error or an import error +prints no such line, so it is not a bite. Check that the printed failure is the +assertion that describes the defect. ## Review @@ -351,8 +388,9 @@ Nothing here is automated beyond the checks on the pull request, and there is no approval quorum — this is a small project and says so rather than describing a process it does not run. -Disagreement about a rule is resolved by changing the rule in this file or in -[`WRITING.md`](WRITING.md), not by making an exception in review. +Disagreement about a rule is resolved by changing the rule in this file, +[`REVIEW.md`](../REVIEW.md), or [`WRITING.md`](WRITING.md), not by making an +exception in review. ## Releases diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..e6f9ad00 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ + + +Closes # + +### 1. Owner and boundary + +- Rule changed and module/package that owns it: +- Sibling entry points checked (Java/Kotlin/Scala/Clojure, `CommandChain`/control, `libtmux-mcp`/`libtmux-workspace`, or `N/A`): +- Why this belongs here (owner fix, boundary adapter, or single-PR ownership transfer): + +### 2. Failure before the fix (`N/A` for docs, lockfile bumps, or pure refactors) + +- Baseline (`` commit, or `` SHA if fixing a defect introduced in this PR): +- Failing input / command and observed failure before the fix: + +### 3. Verification and tool disclosure + +- Gates run (plus production-only revert check for behavioral fixes, or `N/A`): +- Declared workarounds in `.github/workarounds.toml` (`None` if none): +- Tool use: diff --git a/AGENTS.md b/AGENTS.md index d57f555b..7d971752 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,7 +20,7 @@ These hold for every change, whatever it touches: project's own servers are only safe to find and reap by their exact root. `.github/CONTRIBUTING.md` explains what goes wrong when they share. -## Additional guidance +## Which policy applies This file routes; it does not restate. Read the policy that governs the change being made: @@ -34,23 +34,24 @@ being made: are in [`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md#checking-the-scripts). - Contribution workflow, building, testing, and pull requests: [`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md) +- Design, planning, and pull request review decisions: [REVIEW.md](REVIEW.md) - Reporting a vulnerability: [GitHub security advisories](https://github.com/libtmux/libtmux-java/security/advisories/new) - Cutting a release: [`RELEASING.md`](RELEASING.md) -## Python typing - -Give callers the most precise signature that covers supported behavior. Use -`object` for a parameter only when every value is valid or when the function -accepts unknown input for validation. Narrow unknown values before using them. -Reserve `Any` for an inherently dynamic interface where Python cannot express -the input contract. Explain the reason there and keep unchecked values out of -the rest of the API. - -Before weakening a type, inspect real callers and try a precise alternative. -A union can describe known alternatives, a protocol can name the operations a -caller must provide, and a type parameter can preserve the relationship between -an input and its result. Try both a supported call and a plausible misuse with -ty. Check what downstream callers infer, whether the error is understandable, -and whether existing valid calls still work. Never widen a type, cast a value, -or suppress a diagnostic solely to make the checker pass. +## Java typing and error handling + +Express contracts on JDK 25 with JSpecify `@NullMarked` packages (enforced by +NullAway and Error Prone), Java records and sealed hierarchies, `Optional` +for absent lookup results, and `AutoCloseable` resource lifecycles +(`Server.start` with `try`-with-resources) while matching the observable tmux +semantics the ports document at [libtmux.org](https://libtmux.org) across Java, +Kotlin, Scala, and Clojure bindings. Keep `io.github.libtmux.internal` +unexported in `module-info.java` and keep `libtmux` free of runtime +dependencies. + +Surface tmux and validation failures through typed +`io.github.libtmux.exception` domain exceptions documented in `@throws`. Do not +swallow exceptions in empty `catch` blocks, widen typed contracts to `Object`, +or add `@SuppressWarnings` annotations solely to silence Error Prone, NullAway, +`javac`, Kotlin, Scala, or Clojure diagnostics instead of fixing the cause. diff --git a/REVIEW.md b/REVIEW.md new file mode 100644 index 00000000..7594e451 --- /dev/null +++ b/REVIEW.md @@ -0,0 +1,100 @@ +# Code and architecture review (`libtmux/libtmux-java`) + +Posture: `experimental` (pre-1.0 JDK 25 and multi-language JVM modules for +tmux; align observable semantics, target resolution, capability contracts, and +error taxonomy with the libtmux ports documented at +[libtmux.org](https://libtmux.org) while expressing APIs in native Java, +Kotlin, Scala, and Clojure idioms). + +[Posture](https://github.com/libtmux/.github/blob/HEAD/CONTRIBUTING.md#posture) +defines `experimental`, `stable` and `private`. + +Review the complete change against ``, including untracked files. Report +all findings in one pass without editing files. Follow +[writing rules](.github/WRITING.md), [MCP rules](libtmux-mcp/AGENTS.md), and +the organization +[AI policy](https://github.com/libtmux/.github/blob/HEAD/AI_POLICY.md). + +## 1. Layer ownership + +| Layer | Modules and paths | Owns | Must not own | +| --- | --- | --- | --- | +| Core JPMS module and BOM | `libtmux/`, `libtmux-bom/` | `io.github.libtmux` (`Server`, `Session`, `Window`, `Pane`, `batch`, `catalog`, `control`, `exception`, `format`, `query`, `snapshot`, `transport`), `@NullMarked` contracts, and aligned Maven BOM publications | Runtime dependencies, transitive `org.jspecify` / Error Prone module requirements, exported `io.github.libtmux.internal`, or CLI/MCP schemas | +| JVM language and codec modules | `libtmux-jackson/`, `libtmux-kotlin/`, `libtmux-scala/`, `libtmux-scala-cats/`, `libtmux-scala-ox/`, `libtmux-clojure/`, `libtmux-clojure-core-async/` | Jackson codecs and idiomatic Kotlin, Scala 3 (direct, Cats Effect, Ox), and Clojure (`core.async`) bindings delegating to `libtmux` | Duplicated tmux wire/control-mode parsing or raw `tmux` subprocess execution | +| Outer applications | `libtmux-workspace/`, `libtmux-workspace-cli/`, `libtmux-mcp/` | Declarative YAML session builder, workspace CLI, and detached-safe MCP server over `libtmux` | Raw `tmux` subprocess workarounds for missing `libtmux` APIs or modal interactive client UIs in `libtmux-mcp` | +| Quarantine, build-logic, and suites | `libtmux-junit5/`, `build-logic/`, `integration-tests/`, `module-tests/`, `docs/`, `examples/`, `benchmarks/`, `tools/mcp-swap/`, `scripts/` | `/tmp/libtmux-java-test/` (`tmux -L` / `-S` with `-f /dev/null`) `libtmux.tmux-quarantine` and `TmuxExtension` lifecycles, Doclet/codegen plugins, staged JPMS/BOM consumers, executed guide snippets, and CI/release checks | Touching ambient `TMUX` servers, bare `/tmp/libtmux-*` paths owned by sibling ports, or sockets past the 104-byte `sun_path` limit | + +### Changing the map + +Do not `BLOCK` against `:REVIEW.md`'s prior owner row when a pull request +migrates an invariant cleanly to a single owner, updates callers, +`libtmux-bom`, `MIGRATION.md` (when public APIs break), tests, and `REVIEW.md` +in the same diff, and states the old and new owner in the pull request +description. Weigh any boundary-adapter or ownership-transfer counter-case +before blocking on placement. + +### Rejected here + +- **Caller workarounds in `libtmux-mcp`, `libtmux-workspace*`, or language + wrappers**: extend `libtmux` first when downstream modules need a tmux + capability, and check sibling Java, Kotlin, Scala, and Clojure surfaces + where applicable. +- **Nullability, module-graph, or suppression shortcuts**: keep `@NullMarked` + (NullAway in JSpecify mode), Error Prone, `module-info.java`, and + `platformCoversEveryPublishedModule` clean without `@SuppressWarnings`, empty + `catch` blocks, or runtime dependencies in `libtmux`. +- **Control-mode and subprocess lifecycle hazards**: check split-frame reads, + octal escape decoding, `%begin`/`%end`/`%error` pairing, child process + reaping, and `Server.close()` / cancellation teardown. Reject fixed + `Thread.sleep` loops where `PaneWait` / `TextWait`, format queries, or `%end` + notifications provide deterministic readiness. +- **Unquarantined tmux servers or capability-claim drift**: live tests must run + under `libtmux.tmux-quarantine` or `TmuxExtension` inside + `/tmp/libtmux-java-test/` (`tmux -L` / `-S` with `-f /dev/null`, `TMUX` and + `LIBTMUX_SOCKET*` scrubbed) and pass `everyTestModuleIsQuarantined`. + `README.md`, module READMEs, and `capabilities.json` may claim only + implemented, tested features; reject Python-era instructions + (`## Python typing`). +- **Silent partial multi-step failure**: when a `CommandChain`, workspace + build, or batch MCP call spans multiple side effects, verify what state + persisted if step `N` fails and what `io.github.libtmux.exception` error + reaches callers before retry. + +## 2. Regression baseline and decision + +1. For bug fixes and behavioural changes, reproduce the failure on `` + against a real isolated tmux server (`integration-tests/` or quarantined + module test) rather than a mocked owner. When a follow-up commit fixes a + defect introduced earlier in the same open pull request that did not exist + on ``, cite `` and prove the regression test fails + there. +2. Verify that restoring modified non-test production sources and removing + newly added production sources makes the new test fail for the expected + reason, then restore production files and pass `./gradlew + :libtmux-mcp:test check`, `./gradlew :docs:test`, and `scripts/` (`ruff`, + `ty`, `pytest`). Track any temporary upstream workaround in + `.github/workarounds.toml` when introduced. +3. Emit `BLOCK` or `NO FINDINGS` (plus optional non-blocking `NOTE` items). + Every `BLOCK` must cite the file and broken rule or failing input, and state + a concrete test, command, or code observation that would prove the finding + wrong. + +## 3. Verdict + +These rules decide which findings block. + +- **Base run**: A finding that code misbehaves shows its check run on `` + and on the change, with one line of output from each. +- **Existing and separate**: Behavior `` already has does not block. + Report it as a `NOTE`, unless the change adds a promise the behavior breaks; + then the broken promise is the finding. +- **Unverified**: A gate nobody ran is unverified. Name the command that would + run it. It holds the merge until someone runs it, and it does not make the + verdict `BLOCK`. +- **Behavior defects**: A behavior defect blocks when a caller can reach it in + a supported environment, or when it breaks a promise in the pull request + description, a docstring, help text or the changelog. Otherwise it is a + `NOTE`. +- **Checks and claims**: A weakened check, a rule written in a second place and + a behavior claimed as tested with no test that bites block whether or not a + caller reaches them.