This file provides guidance to AI coding agents when working with code in this repository.
pks is a Rust CLI tool — a high-performance reimplementation of Shopify's packwerk Ruby gem. It checks boundaries between Ruby "packs" (packages) in a modular Rails/Ruby application. The binary is named pks; the Rust library crate is named packs.
# Build
cargo build
cargo build --release
# Run all tests
cargo test
# Run a single test by name
cargo test test_name
# Run a specific integration test file
cargo test --test check_test
# Lint
cargo clippy --all-targets --all-features
cargo fmt --all -- --check # check only
cargo fmt --all # apply formatting
# Check compilation without building
cargo checkRustfmt is configured with max_width=80 (.rustfmt.toml). CI runs clippy with -Dwarnings so all warnings are errors.
src/main.rs— callscli::run(), maps errors to exit codes (0 = ok, 1 = violations found, 2 = internal error)src/lib.rs— exposespub mod packs::clifor theserde_magnusRuby FFI consumerssrc/packs.rs— module declarations and top-level public functions (check,update,validate,add_dependency, etc.)
src/packs/cli.rs— CLI argument parsing withclap. BuildsConfiguration, dispatches topacks::*functions.src/packs/configuration.rs—Configurationstruct (the central data object passed everywhere). Built frompackwerk.ymlviaraw_configuration.rs+walk_directory.rs.src/packs/checker.rs— Core violation-checking engine. DefinesCheckerInterfaceandValidatorInterfacetraits,Violation/ViolationIdentifiertypes, andcheck_all()/update()/validate_all().src/packs/checker/— Individual checkers:dependency,privacy,visibility,layer,folder_privacy. Each implementsCheckerInterface.src/packs/parsing/— File parsing. Two modes:- Packwerk mode (default): Zeitwerk-based constant resolution from file paths (
parsing/ruby/zeitwerk/) - Experimental mode (
--experimental-parser): AST-based usinglib-ruby-parser(parsing/ruby/experimental/) - Both Ruby (
.rb,.rake,Gemfile,.gemspec) and ERB (.erb) are supported.
- Packwerk mode (default): Zeitwerk-based constant resolution from file paths (
src/packs/pack.rs/pack_set.rs—Packstruct (represents onepackage.yml) andPackSet(the collection).src/packs/package_todo.rs— Read/writepackage_todo.ymlfiles that record allowed violations.src/packs/caching/— Per-file MD5-based cache for parsed results (tmp/cache/packwerk/by default).--no-cachedisables it.
configuration::get()readspackwerk.yml, walks the directory tree, buildsPackSetandConfiguration.reference_extractor::get_all_references()processes files in parallel (viarayon), extractingReferenceobjects.- Each
CheckerInterfaceimpl runs against every reference to produceViolations. CheckAllBuilderseparates violations into reportable, stale, and strict-mode violations by comparing against recorded violations inpackage_todo.yml.- Output is formatted via
text.rs(packwerk format),csv.rs, orjson.rs.
Integration tests live in tests/ and use fixture Ruby apps in tests/fixtures/. The tests/common/mod.rs provides shared test helpers. Most tests use assert_cmd to invoke the compiled binary.