Skip to content

Keep policy engine decoupled from hook runner #41

Description

@dpritchett

Context

snag's core value is pattern-based policy enforcement across git hook phases. The hook runner (lefthook, husky, pre-commit, raw .git/hooks/) is a separate concern.

Today the policy engine (diff.go, msg.go, push.go, prepare.go, rebase.go, config.go, patterns.go) has zero lefthook awareness. This is good. The lefthook coupling is isolated to two places:

  1. snag install (install_hooks.go) — writes lefthook YAML configs
  2. Detection/nudge (checkout.go + shell.go) — checks for lefthook config files or .git/hooks/ scripts

Goal

Preserve this separation so snag can support other hook runners (husky, pre-commit, raw .git/hooks/) in the future without touching the policy engine.

What a multi-runner pivot would look like

  • snag install becomes runner-aware: snag install --runner=lefthook vs --runner=husky vs --runner=git-hooks
  • Nudge detection in checkout.go and shell hooks in shell.go learn to detect other runners
  • Hint messages become dynamic ("run: snag install && lefthook install" vs "run: npx husky install")
  • Policy engine stays untouched

Ground rules

  • Policy commands must never import or reference a hook runner. diff.go should never know what lefthook is.
  • Runner-specific code stays in install_hooks.go, checkout.go, and shell.go. If a new file needs runner awareness, that's a design smell.
  • Config format (snag.toml) must remain runner-agnostic. No lefthook, husky, or pre-commit concepts leak into snag.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions