github jdx/hk v2.15.0
v2.15.0: hk: config imports, CI annotations, per-hook jobs, and nine new builtins

45 minutes ago

hk 2.15.0 lets hk.pkl import hk's own modules through hk: URIs, so configs no longer need a version bump on every upgrade. hk check can now report findings as GitHub Actions annotations and GitLab Code Quality reports, and hooks can set their own jobs and hide_when_done. Each run writes per-step output files for agents and CI, and hk init --mise installs the detected linters. This release adds builtins for C#, C/C++, Clojure, Kotlin, Snakemake, API specs, reStructuredText, Python security and GitHub's Actions lockfile. It also fixes pre-push runs that update several refs, index locking during read-only runs, and Windows batching through pnpm exec/npx.

Added

  • hk: module URIs (#1912). Configs can import the modules of the hk that evaluates them, so you no longer bump a versioned package:// URL on each upgrade. hk serves these modules from its own binary, so they work offline and never download anything. hk init, hk migrate pre-commit, the examples and the docs now generate this form:

    amends "hk:/Config.pkl"
    import "hk:/Builtins.pkl"

    Single builtins are available as hk:/builtins/<name>.pkl. package:// URLs keep working, and they remain the option for pkl-lsp (0.9.0 and earlier can't resolve hk:), for plain pkl without hk, and for shared packages that should pin one schema. The plain pkl CLI can resolve hk: through the new hk read command, an external module reader: run pkl eval --external-module-reader 'hk=hk read' hk.pkl, or register hk read under evaluatorSettings.externalModuleReaders in a PklProject.

  • CI-native reporting (#1938). hk check, hk fix and hk run accept two new flags:

    • --github-annotations prints a workflow command for each finding, so GitHub shows it inline on the pull request. Annotations don't need GitHub Advanced Security. A failed step with no parsed findings gets one ::error with its output, and so does a run that fails before its hook starts. When GITHUB_STEP_SUMMARY is set, hk also appends a Markdown job summary with each step's status, duration and findings. With --format json/jsonl, annotations go to stderr.
    • --gitlab-code-quality PATH writes a Code Quality report for the merge request widget. Fingerprints don't include line numbers, so moving code doesn't make a finding look new.
    - run: hk check --all --github-annotations

    Findings come from steps that set diagnostic_format, the same source as --sarif. Absolute paths inside the repository are made repository-relative. A run that fails before its hook starts now also writes the requested --sarif and --junit-xml reports. The CI docs now cover jdx/hk-action, which installs a pinned hk and passes --github-annotations when the installed hk supports it (#1941).

  • Per-hook jobs and hide_when_done (#1933). A hook can limit how many of its steps run at once, or hide each step's output after it succeeds:

    hooks {
      ["pre-commit"] { jobs = 2; steps = linters }
      ["post-checkout"] { hide_when_done = true; steps = linters }
    }

    A hook's value overrides the top-level hk.pkl setting. hk.jobs git config, HK_JOBS/HK_HIDE_WHEN_DONE and --jobs still override it. hk validate now warns when a hook's env sets an hk setting such as HK_JOBS, because that env only reaches the step commands and hk never reads it.

  • One output file per step (#1943). Each hook run also writes every step's output summary to <step>.log in HK_OUTPUT_DIR, which defaults to <git-dir>/hk/output/. An agent or CI job can read one step's output without loading the whole run. Step names are percent-encoded in the file names, for example lint/js becomes lint%2Fjs.log. Each run deletes .log files left by earlier runs, and overlapping runs take a lock, so the directory never mixes output from two runs.

  • hk init --mise adds the linters' tools (#1939). Along with hk, the generated mise.toml now lists each detected or selected builtin's tools at latest, so mise install installs everything the hooks need. Tools already in mise.toml stay as they are, even under another backend (for example aqua:astral-sh/ruff counts as ruff). Language runtimes such as node, python or rust are never added; hk prints the mise use command for them instead. When a builtin step fails because its tool isn't installed, hk now ends the run with a hint such as mise use prettier shfmt shellharden.

  • New builtins:

    • gh_actions_lock checks that .github/workflows/actions.lock pins every action your workflows use. The check runs offline. The fix calls the GitHub API only when pins are missing, using GH_TOKEN/GITHUB_TOKEN when set (#1922).
    • csharpier formats C# and MSBuild files one file at a time, without a restore or build (#1958).
    • roslynator runs Roslynator's analyze/fix on the changed .cs files of a project or solution. It needs the Roslynator.Analyzers package in the project and runs dotnet restore first (#1957).
    • cppcheck runs the C/C++ static analyzer. clang_format, cpp_lint and cppcheck now share a "C/C++" category in the catalogue and the hk init picker (#1954).
    • clj_kondo lints Clojure, ClojureScript, EDN and babashka files, and cljstyle checks and fixes Clojure formatting (#1930).
    • detekt runs the detekt 1.x Kotlin analyzer and picks up detekt.yml or config/detekt/detekt.yml on top of the default rules. It is skipped on Windows (#1932).
    • snakefmt formats Snakemake files, and snakemake runs snakemake --lint once per workflow (#1956).
    • spectral lints OpenAPI, Swagger, AsyncAPI and Arazzo files. Without a project ruleset, it uses a default one. It is skipped on Windows (#1955).
    • bandit runs the Python security linter and reads [tool.bandit] in pyproject.toml or a .bandit file (#1931).
    • rstcheck checks reStructuredText files, including the code inside their code blocks (#1929).

    All of these except csharpier, cljstyle and snakefmt set diagnostic_format = "gcc", so their findings appear in --sarif, --json and the new CI reports. roslynator doesn't: its output isn't in a format hk parses.

Fixed

  • Pre-push with several refs (#1924, reported by @Gerry9000 in #1910). When one git push updated several refs, hk selected files from only the first ref, so commands such as git push origin feat-a feat-b or git push origin :old feat-b could push files that were never checked. hk now checks the files changed across every ref the push updates, and skips deletions. A step with requires_ref_range = true (such as gitleaks with scan = "commits") now fails on a multi-ref push and asks you to push the refs one at a time, instead of scanning only the first range. {{from_ref}}/{{to_ref}} hold the first range.
  • hk run pre-push --from-ref X --to-ref Y no longer waits on an open stdin (#1923, reported by @dev1952 in #1909). When both refs are given, hk doesn't read stdin, and hook_stdin is empty. Hooks run by git push are unaffected.
  • Read-only runs no longer lock or rewrite .git/index (#1928, reported by @Gerry9000 in #1911). hk check and hooks that don't stash or stage now read status with GIT_OPTIONAL_LOCKS=0, so they no longer collide with a git add or git commit running in the same worktree.
  • output.log covers the whole run (#1940). HK_OUTPUT_FILE (default <git-dir>/hk/output.log) now holds every step's output summary from the latest hook run, with each step's status and no ANSI codes. Before, it held only the single failure that ended the run. Each run replaces the file, passing runs included. The file is removed when no step produced output.
  • Windows batching through package managers (#1935, reported by @hcoona in #1919). Commands that start with npm, npx, pnpm, pnpx or yarn (including native .exe installs) are now split into batches that fit cmd.exe's 8191-character limit. Before, large runs failed with The command line is too long.
  • check_added_large_files skips Git LFS files (#1934, reported by @CallumKerson in #1920). Files with filter=lfs are no longer reported, which matches pre-commit's behavior.
  • hadolint matches more Dockerfile names (#1953). It now lints *.Dockerfile, lowercase dockerfile names and Podman/Buildah Containerfile variants. It no longer passes files in directories named like Dockerfiles.d/, or *.dockerignore files.
  • Config cache with optional imports (#1946, reported by @pawelad in #1945). hk now reloads the config when the file named by an optional import without a wildcard, such as import* "extra.pkl", is created or deleted.

Full Changelog: v2.14.0...v2.15.0

💚 Sponsor hk

hk is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.

If hk speeds up your pre-commit loop or makes linting less painful, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep hk fast, free, and independent.

Don't miss a new hk release

NewReleases is sending notifications on new releases.