examples: precommit-example/ — template spec + pre-commit config + README (S19.2)
- SHA
34278d3ad8c5506f97a4e188b3493d6c3749de87- Parents
-
c87edf2 - Tree
fd2705b
34278d3
34278d3ad8c5506f97a4e188b3493d6c3749de87c87edf2
fd2705b| Status | File | + | - |
|---|---|---|---|
| A |
examples/precommit-example/.pre-commit-config.yaml
|
27 | 0 |
| A |
examples/precommit-example/README.md
|
72 | 0 |
| A |
examples/precommit-example/sway.yaml
|
42 | 0 |
examples/precommit-example/.pre-commit-config.yamladded@@ -0,0 +1,27 @@ | ||
| 1 | +# Consumer-side pre-commit config — plug this into your repo's | |
| 2 | +# ``.pre-commit-config.yaml`` to gate the adapter on every commit. | |
| 3 | +# | |
| 4 | +# Rev pinning: sway hasn't tagged a release yet (pre-v0.1.0). Pin to a | |
| 5 | +# specific commit SHA rather than ``HEAD`` so the gate's behavior | |
| 6 | +# doesn't drift under you on upstream changes. Bump the SHA | |
| 7 | +# deliberately when you want to pick up new probes. After v0.1.0 | |
| 8 | +# ships you'll switch to ``rev: v0.1.0`` and forget about it. | |
| 9 | + | |
| 10 | +repos: | |
| 11 | + - repo: https://github.com/tenseleyFlow/sway | |
| 12 | + # Pin to a specific commit — update deliberately when you want | |
| 13 | + # upstream changes. Replace with a tag like ``v0.1.0`` once sway | |
| 14 | + # publishes its first release. | |
| 15 | + rev: 2ecd9a0c9d65a9b9576a185597c88f41444f9646 | |
| 16 | + hooks: | |
| 17 | + # Recommended: ``sway-gate`` uses the sway install on your PATH. | |
| 18 | + # Fastest path; assumes you've ``pip install 'dlm-sway[hf]'``. | |
| 19 | + - id: sway-gate | |
| 20 | + args: ["examples/precommit-example/sway.yaml", "--threshold=0.0"] | |
| 21 | + | |
| 22 | + # Alternative — uncomment if you don't have sway installed | |
| 23 | + # system-wide. Pre-commit will build a fresh venv and install | |
| 24 | + # sway + torch + transformers (~5 GB) on first run. | |
| 25 | + # | |
| 26 | + # - id: sway-gate-isolated | |
| 27 | + # args: ["examples/precommit-example/sway.yaml", "--threshold=0.0"] | |
examples/precommit-example/README.mdadded@@ -0,0 +1,72 @@ | ||
| 1 | +# Pre-commit gate example | |
| 2 | + | |
| 3 | +A copy-paste recipe for plugging `sway gate` into any repo's `git | |
| 4 | +commit` flow via [pre-commit.com](https://pre-commit.com). | |
| 5 | + | |
| 6 | +## What this gives you | |
| 7 | + | |
| 8 | +On every `git commit` that touches `sway.yaml`, a `.dlm` document, or | |
| 9 | +an `adapter/` directory, pre-commit runs `sway gate` against your | |
| 10 | +spec. A FAIL verdict aborts the commit with the terminal banner | |
| 11 | +you'd see from `sway gate` directly. No more "oops, I broke the | |
| 12 | +adapter and didn't notice until the next manual `sway run`." | |
| 13 | + | |
| 14 | +## Which variant | |
| 15 | + | |
| 16 | +sway ships two hooks. Pick whichever matches your install posture: | |
| 17 | + | |
| 18 | +| Hook | When to use | Cost | | |
| 19 | +|---|---|---| | |
| 20 | +| `sway-gate` | sway is already on your `PATH` (`pip install 'dlm-sway[hf]'`) | Milliseconds of hook overhead + the actual gate runtime | | |
| 21 | +| `sway-gate-isolated` | fresh venv, no existing sway install | First run installs sway + torch + transformers (~5 GB, ~2 min). Subsequent runs reuse the cached venv. | | |
| 22 | + | |
| 23 | +This example shows `sway-gate` as the default and `sway-gate-isolated` | |
| 24 | +commented out. Swap them in `.pre-commit-config.yaml` if you want the | |
| 25 | +isolated variant. | |
| 26 | + | |
| 27 | +## Setup (4 steps) | |
| 28 | + | |
| 29 | +1. Install pre-commit: `pipx install pre-commit` (or `pip install | |
| 30 | + pre-commit` if you don't use pipx). | |
| 31 | +2. Copy this directory's `.pre-commit-config.yaml` into your repo | |
| 32 | + root. If you already have one, merge the `- repo:` block. | |
| 33 | +3. Edit `sway.yaml` in your repo to point at your real base model | |
| 34 | + and adapter paths. | |
| 35 | +4. Install the hook: `pre-commit install`. | |
| 36 | + | |
| 37 | +That's it. The next `git commit` that matches the hook's file filter | |
| 38 | +will run `sway gate` before the commit finalizes. | |
| 39 | + | |
| 40 | +## Rev pinning | |
| 41 | + | |
| 42 | +The example's `.pre-commit-config.yaml` pins to a specific commit | |
| 43 | +SHA because sway hasn't tagged a v0.1.0 release yet. Pinning to | |
| 44 | +`HEAD` would silently drift your gate's behavior on every `pre-commit | |
| 45 | +autoupdate`; pinning to a SHA is the honest pre-release pattern. | |
| 46 | + | |
| 47 | +Bump the SHA deliberately when you want to pick up new probes or | |
| 48 | +bug fixes. After sway publishes v0.1.0 you'll switch to | |
| 49 | +`rev: v0.1.0` and forget about SHAs. | |
| 50 | + | |
| 51 | +## Scope discipline | |
| 52 | + | |
| 53 | +The hook **only gates** — exits non-zero on FAIL, zero on PASS. It | |
| 54 | +does not emit JSON / markdown reports; those are for `sway run` | |
| 55 | +(called ad-hoc or in a separate CI job). Keeping the hook focused | |
| 56 | +means `git commit` stays fast and the gate's verdict stays the | |
| 57 | +headline signal. | |
| 58 | + | |
| 59 | +## Trying it locally before committing | |
| 60 | + | |
| 61 | +If you want to see the hook fire before integrating it into a real | |
| 62 | +repo: | |
| 63 | + | |
| 64 | +```bash | |
| 65 | +# From your repo's root, after copying the config in and editing | |
| 66 | +# the spec paths: | |
| 67 | +pre-commit run sway-gate --all-files | |
| 68 | +``` | |
| 69 | + | |
| 70 | +That runs the hook against every tracked file and surfaces the | |
| 71 | +full terminal report. A subsequent `git commit` will run the hook | |
| 72 | +only against staged files — same logic, narrower scope. | |
examples/precommit-example/sway.yamladded@@ -0,0 +1,42 @@ | ||
| 1 | +# Minimal sway spec — template for the pre-commit-gate recipe. | |
| 2 | +# | |
| 3 | +# Replace the ``base`` and ``adapter`` paths below with your own. The | |
| 4 | +# default values are placeholders documenting the shape the hook | |
| 5 | +# expects. Running ``sway gate`` against this verbatim will fail | |
| 6 | +# because the paths don't resolve — that's by design; the user | |
| 7 | +# customizes before plugging the hook in. | |
| 8 | +# | |
| 9 | +# See README "Pre-commit" section for the full walk-through. | |
| 10 | + | |
| 11 | +version: 1 | |
| 12 | +models: | |
| 13 | + base: | |
| 14 | + base: HuggingFaceTB/SmolLM2-135M-Instruct | |
| 15 | + kind: hf | |
| 16 | + adapter: path/to/your/adapter | |
| 17 | + dtype: fp32 | |
| 18 | + device: cpu | |
| 19 | + ft: | |
| 20 | + base: HuggingFaceTB/SmolLM2-135M-Instruct | |
| 21 | + kind: hf | |
| 22 | + adapter: path/to/your/adapter | |
| 23 | + dtype: fp32 | |
| 24 | + device: cpu | |
| 25 | +defaults: | |
| 26 | + seed: 0 | |
| 27 | + differential: true | |
| 28 | + # The gate's exit-code threshold. 0.0 means "any pass is acceptable"; | |
| 29 | + # real specs raise this to 0.6 or 0.8 for a meaningful quality bar. | |
| 30 | + coverage_threshold: 0.0 | |
| 31 | +suite: | |
| 32 | + # One cheap probe keeps the pre-commit hook fast. Add more probes as | |
| 33 | + # the adapter gets more surface area worth gating. | |
| 34 | + - name: dk | |
| 35 | + kind: delta_kl | |
| 36 | + prompts: | |
| 37 | + - The capital of France is | |
| 38 | + - Python decorators are | |
| 39 | + - Water boils at | |
| 40 | + - Mitochondria are | |
| 41 | + divergence: js | |
| 42 | + assert_mean_gte: 0.0 | |