feat(pre-commit): replace TOML filter with Rust summary handler + uv run alias#1992
Open
jugrajsingh wants to merge 2 commits into
Open
feat(pre-commit): replace TOML filter with Rust summary handler + uv run alias#1992jugrajsingh wants to merge 2 commits into
jugrajsingh wants to merge 2 commits into
Conversation
Issue rtk-ai#184 was closed with a TOML-based filter, but the TOML pipeline can only strip lines by regex — it cannot count, group, or summarise. In practice the previous pre-commit.toml filter only removed [INFO] Installing environment noise and saved ~0% on real runs. Add a proper Rust subcommand that parses pre-commit's hook-result lines and collapses them into a single summary plus verbatim blocks for any failed hook. Achieves 80-95% reduction on passing runs while keeping all failure context intact. - src/cmds/python/precommit_cmd.rs: parser + filter + 9 unit tests including token-savings assertion (>=60%) against real fixtures - src/main.rs: register Commands::PreCommit (clap name pre-commit), match arm dispatching to precommit_cmd::run, add to is_operational_command list - src/core/toml_filter.rs: bump filter-count tests 59->58 to reflect removal of the now-superseded TOML filter - src/filters/pre-commit.toml: deleted (Rust handler replaces it) - tests/fixtures/pre_commit_{pass,fail}.txt: real captured outputs used for unit tests and the savings assertion - Cargo.lock: version field refreshed by cargo build Output shape: pass: 9 hooks: 7 passed, 2 skipped failure: summary line + verbatim block per failed hook autofix: summary line + re-stage and retry hint Real-world smoke test: 720 bytes -> 29 bytes (96.0% reduction). 1894 tests pass; clippy clean; fmt clean. Refs rtk-ai#184
In uv-managed projects pre-commit lives inside .venv/bin/ and the canonical invocation is 'uv run pre-commit run ...'. The previous rewrite rule only matched bare 'pre-commit', so the hook never rewrote the uv form — every such call went raw, losing the 90% savings. - src/discover/rules.rs: extend pre-commit rule's regex pattern to ^(?:uv run )?pre-commit\b and add 'uv run pre-commit' (longest first) to rewrite_prefixes. Bump savings_pct 65->90 to reflect the measured ~96% on a real repo's passing runs. - src/cmds/python/precommit_cmd.rs: new build_precommit_command() helper that picks pre-commit if on PATH, else 'uv run pre-commit' when uv is on PATH and a pyproject.toml exists in cwd or an ancestor. Falls through to plain pre-commit otherwise so command-not-found surfaces cleanly. Adds 2 unit tests for the pyproject walk. - src/discover/registry.rs: 3 new rewrite tests covering 'pre-commit run ...', 'uv run pre-commit run --files ...', and bare 'uv run pre-commit'. Verified end-to-end: 'rtk rewrite "uv run pre-commit run --files X"' emits 'rtk pre-commit run --files X'; live 'rtk pre-commit run --all-files' in a real repo still hits 96.0% reduction. 1899 tests pass (was 1894 + 5 new); clippy clean; fmt clean. Refs rtk-ai#1711 (uv run wrappers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the TOML-based
pre-commitfilter with a Rust subcommand that produces a real one-line summary plus verbatim blocks for failing hooks. Also recognisesuv run pre-commitas an alias so the rewrite layer fires inside uv-managed projects.Closes / supersedes the implementation merged via #184 (which the TOML pipeline couldn't deliver on — counting and conditional summarisation aren't expressible as line-strip regexes).
Motivation
The previous
src/filters/pre-commit.tomlonly stripped[INFO] Installing environmentinstall noise plus blank lines, then capped at 40 lines. On real passing runs (9 hooks ofPassed/Skippedlines) it left output essentially unchanged — measured savings ~0% on representative workloads.The TOML pipeline (
strip_lines_matching,max_lines,replace, …) can drop and truncate lines, but it can't:9 hooks: 7 passed, 2 skippeduv run pre-commitWhat's in this PR
1. Rust handler (
src/cmds/python/precommit_cmd.rs)Parses each line, buckets hooks by status, and renders:
9 hooks: 7 passed, 2 skippedhook id,exit code, file:line errors)9 hooks: 8 passed, 1 autofixed — re-stage and retryPass-through for
install,autoupdate,clean,--help,--version, etc. — onlyrunis filtered.2.
uv run pre-commitaliasExtends the existing pre-commit rule:
pattern: r"^(?:uv run )?pre-commit\b"rewrite_prefixes: &["uv run pre-commit", "pre-commit"](longest first)Handler does auto-resolution: prefers
pre-commiton PATH; falls back touv run pre-commitwhenuvis on PATH and apyproject.tomlis reachable in cwd or an ancestor. Falls through to plainpre-commitotherwise so command-not-found surfaces cleanly.3.
Commands::PreCommitclap variantAdds the missing top-level variant (
clap name = "pre-commit") and dispatches toprecommit_cmd::run. Registered inis_operational_command.4. Removes the now-redundant
src/filters/pre-commit.tomlThe Rust handler supersedes it. Tests for
test_builtin_filter_countetc. updated accordingly (59 → 58).Measured impact
720 bytes → 29 bytes (96.0% reduction)Tests
precommit_cmd.rs(regex parsing, summary rendering, autofix detection, pyproject walk, savings assertion against real fixture)discover/registry.rs(bare form,uv runform, no-args form)cargo fmt --all,cargo clippy --all-targets,cargo test --allall cleanNotes for reviewers
tests/fixtures/pre_commit_{pass,fail}.txtwere captured from actual pre-commit runs and sanitised (no internal paths).unsafe, no async, nounwrap()outsidelazy_static!regex literal.Refs
uv runwrappers (this addresses the pre-commit case)