Skip to main content

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 lint also writes lint/sgconfig.yml with empty rules/ and 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, init at a terminal asks whether to keep the repo's own checks in lint/.
  • --poe adds lint-rules and lint-rules-changed poe tasks, to pyproject.toml or, 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 run rulepack packs lock. It pins the new source and keeps the existing pins. A source is either a git repo (git and ref) or a local folder (path, relative to the config file). Path sources are not locked.

  • Update a pin. Change ref and run rulepack packs lock, or keep the ref and run rulepack packs update (every source) or rulepack 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.13.0   # 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.13.0

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.13.0 rulepack lint
# On a merge request, also scan the changed files with warnings failing:
uvx --from git+https://github.com/justmatias/rulepack@v0.13.0 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 = false turns 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 lock once 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.

  1. Rename .mstack.toml to .rulepack.toml (or copy it, if you keep mstack v6 hooks, as in step 5). rulepack ignores .mstack.toml.

  2. 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 git pack held prose only and has no checks, so drop it.

  3. Keep sgconfig, [scan], [hooks], [changed] and [pack_overrides]. Set sgconfig = "lint-rules/sgconfig.yml" if the repo kept mstack's default path, because rulepack's default is lint/sgconfig.yml. Delete the keys rulepack does not read (rules_dir, importlinter, pre_commit_config, [domain_check] and [commits]): unknown keys are an error.

  4. Run rulepack packs lock, then rulepack lint, and commit the config and rulepack.lock.

  5. In .pre-commit-config.yaml, replace mstack-lint and mstack-rules with rulepack-lint and rulepack-rules from the entry in step 4. For mstack-imports, use import-linter's own pre-commit hook, which needs the project importable in the hook's environment. mstack-exceptions, mstack-domain-check and mstack-commit-msg have no rulepack counterpart: drop them, or keep them from mstack v6 together with a .mstack.toml that 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.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rulepack 0.13.0
File Size Uploaded Provenance Actions
rulepack-0.13.0.tar.gz 28.5 kB With provenance Details for rulepack-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rulepack 0.13.0
File Interpreter ABI Platform Actions
rulepack-0.13.0-py3-none-any.whl Python 3 none any Details for rulepack-0.13.0-py3-none-any.whl

Total release size: 66.9 kB

Release files / rulepack-0.13.0.tar.gz

Download URL rulepack-0.13.0.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
05c304ab20da3829626f0b70e2775a21f184fefbc43a90fffde449c3c86d0a06
BLAKE2b-256 checksum
How to use checksums
34deccac4d79a52d29414c92d0652503a8b075065878516c6099f5b19e68d7fa
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 29, 2026.

Transparency log

Release files / rulepack-0.13.0-py3-none-any.whl

Download URL rulepack-0.13.0-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c5b8737ffb75b308c1253f1ecbf31c56a29b8799bd17c92595c09c96774e608
BLAKE2b-256 checksum
How to use checksums
ab8157ed3c66a44d81462e2bc55027d7f08c620e6aa1f9709a437e2db85f484e
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 29, 2026.

Transparency log

Security for rulepack 0.13.0

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.

Select from 2 files

Attestation for rulepack-0.13.0.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 29, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page