@@ -214,6 +214,53 @@ before/after walkthrough. |
| 214 | pip install 'dlm-sway[hf,pytest]' | 214 | pip install 'dlm-sway[hf,pytest]' |
| 215 | ``` | 215 | ``` |
| 216 | | 216 | |
| | 217 | +## Pre-commit |
| | 218 | + |
| | 219 | +For teams using [pre-commit.com](https://pre-commit.com), sway ships |
| | 220 | +a `.pre-commit-hooks.yaml` declaring two hooks that run `sway gate` |
| | 221 | +before every commit touching a spec, `.dlm` document, or adapter |
| | 222 | +file. Add 4–5 lines to your `.pre-commit-config.yaml`: |
| | 223 | + |
| | 224 | +```yaml |
| | 225 | +repos: |
| | 226 | + - repo: https://github.com/tenseleyFlow/sway |
| | 227 | + rev: 2ecd9a0c9d65a9b9576a185597c88f41444f9646 # pin to a SHA |
| | 228 | + hooks: |
| | 229 | + - id: sway-gate |
| | 230 | + args: ["sway.yaml", "--threshold=0.6"] |
| | 231 | +``` |
| | 232 | + |
| | 233 | +Two variants ship; pick whichever fits your install posture: |
| | 234 | + |
| | 235 | +| Hook | When to use | First-run cost | |
| | 236 | +|---|---|---| |
| | 237 | +| `sway-gate` | you already ran `pip install 'dlm-sway[hf]'` | ~none — uses the sway binary on your `PATH` | |
| | 238 | +| `sway-gate-isolated` | fresh venv, no existing sway install | ~2 min + ~5 GB — pre-commit builds a fresh venv and installs sway + torch + transformers | |
| | 239 | + |
| | 240 | +The recommended default is `sway-gate`. Switch to |
| | 241 | +`sway-gate-isolated` if you can't rely on a host-level sway install. |
| | 242 | + |
| | 243 | +### Rev pinning |
| | 244 | + |
| | 245 | +The example above pins to a commit SHA. Sway is pre-v0.1.0 — no |
| | 246 | +tagged release yet. Pinning to `HEAD` would silently drift your |
| | 247 | +gate's behavior under every `pre-commit autoupdate`; a SHA is the |
| | 248 | +honest pre-release pattern. Bump it deliberately when you want to |
| | 249 | +pick up upstream changes. After sway publishes v0.1.0 the recipe |
| | 250 | +switches to `rev: v0.1.0` and the SHA churn stops. |
| | 251 | + |
| | 252 | +### Scope |
| | 253 | + |
| | 254 | +The hook **only gates** — exits non-zero on FAIL, zero on PASS. No |
| | 255 | +`--json` / `--markdown` report flags are surfaced; those belong in |
| | 256 | +`sway run` (ad-hoc or in a separate CI job). Keeps `git commit` fast |
| | 257 | +and the gate's verdict uncluttered. |
| | 258 | + |
| | 259 | +See [`examples/precommit-example/`](examples/precommit-example/) for |
| | 260 | +the full walk-through including the `sway.yaml` template, the |
| | 261 | +consumer-side `.pre-commit-config.yaml`, and the |
| | 262 | +try-it-locally-before-you-install recipe. |
| | 263 | + |
| 217 | ## The `.dlm` integration | 264 | ## The `.dlm` integration |
| 218 | | 265 | |
| 219 | If you trained your adapter via the [DocumentLanguageModel | 266 | If you trained your adapter via the [DocumentLanguageModel |