rulepack
Run ast-grep checks from shared, versioned rule packs in any repo.
Why
Agents write more of the code now, and reviewing it means correcting the same preferences again and again: a naming habit, a test layout, an exception style. If an agent writes the code and you review it, it should write the code the way you would.
Prose rules in Markdown help, but an agent follows them only some of the time. rulepack turns those preferences into static, deterministic checks wherever a check can express them, so a broken rule fails the same way every time and the agent fixes it before you see the diff. Packs make the rules portable: write the checks once in a source repo, version them, and select them from any repo. Each repo pins the commit it runs in a lockfile, so a check changes only when the repo updates the pin.
Integrate rulepack in your repository
This guide adds shared packs to a repo, runs them on every commit through pre-commit and on every pull request in CI. The examples use the packs mstack publishes; any repo or folder with a packs.toml works the same way.
1. Install the CLI
You need uv and git.
uv tool install rulepack
rulepack --version
Or run any command without installing, with uvx rulepack <command>.
2. Set up in one step
From the repo root:
rulepack init --source mstack=https://github.com/justmatias/mstack@v8.1.0 --pre-commit --ci github
--source NAME=URL@REF names a pack source, a git repo at a tag, branch or commit (the last @ separates the URL and the ref). Repeat it for more sources. init shows the plan and asks before it writes (--yes skips the question, --dry-run writes nothing). It never overwrites a file, so a second run changes nothing. It writes:
| File | What it holds |
|---|---|
.rulepack.toml |
The config: an empty packs list and a [sources.mstack] table. |
rulepack.lock |
The commit each git source's ref resolved to. init fetches it into the cache. |
.pre-commit-config.yaml |
The rulepack hooks, pinned to the installed version. An existing file gets a new entry in repos:. |
.github/workflows/rulepack.yml |
A workflow that runs the rulepack action on pushes to main and on pull requests. |
Two more flags:
--checks-dir lintalso creates emptylint/rules/andlint/rule-tests/, for checks the repo keeps itself. They run next to the packs' checks, and a local check replaces a pack check with the same ID. Without the flag,initat a terminal asks whether to keep the repo's own checks inlint/.--poeaddslint-rulesandlint-rules-changedpoe tasks, topyproject.tomlor, without one,poe_tasks.toml.
3. Select packs
List what the sources offer:
$ rulepack packs list
mstack: https://github.com/justmatias/mstack@v8.1.0 (7ed440b6faad0dc8f1fc88640b6bb466b650e768)
mstack/python-core: no-bare-except, no-isort-off, no-manual-init-boilerplate, ...
mstack/testing: conftest-has-only-fixtures, no-broad-pytest-raises, ...
Select packs as <source>/<pack> in .rulepack.toml:
packs = ["mstack/python-core", "mstack/testing"]
[sources.mstack]
git = "https://github.com/justmatias/mstack"
ref = "v8.1.0"
Then run every check on the whole repo:
rulepack lint
Commit .rulepack.toml and rulepack.lock together. rulepack lint never writes the lock: it fails and tells you to run rulepack packs lock when a git source is missing from the lock or its git or ref no longer matches the config.
-
Add a source. Add a
[sources.<name>]table, then runrulepack packs lock. It pins the new source and keeps the existing pins. A source is either a git repo (gitandref) or a local folder (path, relative to the config file). Path sources are not locked. -
Update a pin. Change
refand runrulepack packs lock, or keep the ref and runrulepack packs update(every source) orrulepack packs update mstack(one) to re-resolve a branch or a moved tag. -
Adjust a check. Turn one off or change its severity without leaving the pack:
[pack_overrides] disable = ["no-module-docstring"] severity = { no-sleep-in-tests = "warning" }
4. Run on every commit with pre-commit
rulepack init --pre-commit adds this entry. pre-commit installs rulepack at that tag in its own environment, so the repo needs nothing else:
repos:
- repo: https://github.com/justmatias/rulepack
rev: v0.14.1 # a release tag; init writes the installed version
hooks:
- id: rulepack-lint # ast-grep scan of the staged files; warnings fail too
- id: rulepack-rules # the rule tests, when a YAML file changes
Then install pre-commit, if you don't have it, and the hooks:
uv tool install pre-commit
pre-commit install
rulepack ships no commit-msg hook. Its hooks declare no stage, so they run at every stage you install: if you also install commit-msg hooks, add default_stages: [pre-commit] at the top of the config so they run only at the pre-commit stage. The first run fetches the locked commits into the cache, so it needs network access once.
5. Run in CI
rulepack init --ci github writes this workflow (shortened here). The action runs the full scan, and on pull requests also the scan of the changed files, where warnings fail too. It needs the full history to find the base branch:
on:
push:
branches: ["main"]
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: justmatias/rulepack@v0.14.1
Inputs: mode (full, changed or both; the default is both on pull requests and full otherwise), base-ref (default origin/<the pull request's base branch>), rulepack-version (default the action's own ref), python-version and working-directory.
On other CI providers, call the CLI directly. The changed-files scan needs the base branch and the history back to the merge base, so check out the full history and fetch the target branch:
uvx --from git+https://github.com/justmatias/rulepack@v0.14.1 rulepack lint
# On a merge request, also scan the changed files with warnings failing:
uvx --from git+https://github.com/justmatias/rulepack@v0.14.1 rulepack lint --changed --base-ref origin/main
6. Check agent edits as they happen
rulepack hook post-edit scans the files an agent just edited, and rulepack hook stop scans the changed files when the agent stops. Both read a Claude Code, Codex or Cursor hook payload on stdin and report findings so the agent fixes them in the same session. In Claude Code, add them to .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{ "matcher": "Edit|MultiEdit|Write", "hooks": [{ "type": "command", "command": "rulepack hook post-edit" }] }
],
"Stop": [
{ "hooks": [{ "type": "command", "command": "rulepack hook stop" }] }
]
}
}
- They run only in repos with a
.rulepack.toml, and[hooks] enabled = falseturns them off for a repo. - Stop reports the same findings only once per session.
- A run that fails or takes longer than
[hooks] timeout(10 seconds by default) logs a warning and lets the agent continue. - Hooks read the pack sources from the cache. When a locked commit is not cached yet, the hook fetches it within that time budget, so run
rulepack packs lockonce after cloning to fill the cache up front.
7. Migrate from mstack v6
rulepack replaces mstack v6's mstack lint and its bundled packs. mstack now publishes those packs as a source.
-
Rename
.mstack.tomlto.rulepack.toml(or copy it, if you keep mstack v6 hooks, as in step 5). rulepack ignores.mstack.toml. -
Prefix each pack with its source, and declare the source. A v6 selection such as
packs = ["python-core", "testing"]becomes:packs = ["mstack/python-core", "mstack/testing"] [sources.mstack] git = "https://github.com/justmatias/mstack" ref = "v8.1.0"
mstack's
gitpack held prose only and has no checks, so drop it. -
Keep
[scan],[hooks],[changed]and[pack_overrides]. Replacesgconfigwithchecks_dir, the folder that holdsrules/andrule-tests/(checks_dir = "lint-rules"if the repo kept mstack's default path, because rulepack's default islint), and delete that folder'ssgconfig.ymlunless it sets more thanruleDirs: [rules]andtestConfigs: [{testDir: rule-tests}]. Delete the keys rulepack does not read (rules_dir,importlinter,pre_commit_config,[domain_check]and[commits]): unknown keys are an error. -
Run
rulepack packs lock, thenrulepack lint, and commit the config andrulepack.lock. -
In
.pre-commit-config.yaml, replacemstack-lintandmstack-ruleswithrulepack-lintandrulepack-rulesfrom the entry in step 4. Formstack-imports, use import-linter's own pre-commit hook, which needs the project importable in the hook's environment.mstack-exceptions,mstack-domain-checkandmstack-commit-msghave no rulepack counterpart: drop them, or keep them from mstack v6 together with a.mstack.tomlthat holds their settings (such as[commits]and[domain_check]).
Reference
docs/reference.md lists every command, flag and configuration key.
Contributing
Bug reports, ideas and pull requests are welcome. CONTRIBUTING.md covers the setup, the checks to run and how a pull request title decides the release. Report security problems privately, as SECURITY.md describes, and follow the Code of Conduct.
License
MIT. See LICENSE.
Metadata
Release files for rulepack 0.14.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rulepack-0.14.1.tar.gz | 29.8 kB | With provenance | Details for rulepack-0.14.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rulepack-0.14.1-py3-none-any.whl | Python 3 | none | any | Details for rulepack-0.14.1-py3-none-any.whl |
Total release size: 69.6 kB
Release files / rulepack-0.14.1.tar.gz
| Download URL | rulepack-0.14.1.tar.gz |
|---|---|
| Size | 29.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37193dee4b65c3a75db820c9d07edb89418b299d35e92496400ac1d1c5a66d9b
|
|
BLAKE2b-256 checksum How to use checksums |
31e295ed74359a870c1937ebf5646f6964bebc036f6605f5bbd52807984f0967
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / rulepack-0.14.1-py3-none-any.whl
| Download URL | rulepack-0.14.1-py3-none-any.whl |
|---|---|
| Size | 39.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
521b927dc370060c83172142392ff72ec58f0f8346bd902d5151ee363f86791b
|
|
BLAKE2b-256 checksum How to use checksums |
cdb8383a4f82461fdccda0d86ddab689669b784bdef5187b25d76112dfc881e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for rulepack 0.14.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rulepack-0.14.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.