Skip to content

feat: lore hooks install/uninstall + CI integration (closes #41)#52

Open
Ian-stetsenko wants to merge 5 commits into
mainfrom
feat/hooks-install
Open

feat: lore hooks install/uninstall + CI integration (closes #41)#52
Ian-stetsenko wants to merge 5 commits into
mainfrom
feat/hooks-install

Conversation

@Ian-stetsenko

@Ian-stetsenko Ian-stetsenko commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

Adds commit-msg hook management for automated Lore protocol enforcement — locally via git hooks and in CI via GitHub Actions.

New commands

  • lore hooks install — installs a commit-msg hook to .git/hooks/ that runs lore validate --last 1 --strict
  • lore hooks install --force — overwrites existing non-Lore hooks (backs up to .bak)
  • lore hooks uninstall — removes Lore-managed hooks only (refuses to delete user-managed hooks)

Generated hook script

The hook automatically skips:

  • Merge commits (configurable via skip_patterns)
  • fixup!/squash! commits (configurable via allow_fixup)
  • Commits by specific authors like dependabot[bot] (configurable via skip_authors)
  • Falls back from lore to npx lore-protocol when the CLI isn't on PATH

Configuration

New [hooks] section in .lore/config.toml:

[hooks]
enforce = true                   # Use --strict flag (false = soft mode, warnings only)
allow_fixup = true               # Skip fixup!/squash! commits
skip_authors = []                # Authors to skip (e.g., ["dependabot[bot]"])
skip_patterns = ["^Merge "]      # Message patterns to skip

CI Integration

GitHub Actions.github/workflows/lore-validate.yml:

- run: node ./bin/lore.js validate --since origin/main --strict

pre-commit framework.pre-commit-hooks.yaml:

repos:
  - repo: https://github.com/Ian-stetsenko/lore-protocol
    rev: v0.5.0
    hooks:
      - id: lore-validate
        stages: [commit-msg]

Husky:

# .husky/commit-msg
npx lore validate --last 1 --strict

Any CI (GitLab, Bitbucket, Jenkins, CircleCI):

npx lore-protocol validate --since origin/main --strict

Files changed (12)

New:

  • src/commands/hooks.ts — command registration
  • src/interfaces/hook-installer.tsIHookInstaller interface
  • src/services/hook-installer.ts — filesystem operations for hook management
  • src/services/hook-script-generator.ts — generates bash hook script from config
  • .pre-commit-hooks.yaml — pre-commit framework integration
  • .github/workflows/lore-validate.yml — GitHub Actions workflow
  • tests/unit/services/hook-installer.test.ts — 9 tests
  • tests/unit/services/hook-script-generator.test.ts — 11 tests

Modified:

  • src/main.ts — wires HookInstaller + HookScriptGenerator into composition root
  • src/types/config.ts — adds hooks section to LoreConfig
  • src/services/config-loader.ts — adds hooks to CAMEL_TO_SNAKE mapping
  • src/commands/init.ts — adds [hooks] to default config template

Test plan

  • 444 tests pass (28 test files)
  • Build and typecheck pass
  • Manual smoke tests:
    • lore hooks install → creates hook, verified content
    • lore hooks install again → updates existing Lore hook
    • lore hooks uninstall → removes hook
    • lore hooks --help and lore hooks install --help show correct usage
  • Generated hook script includes all skip conditions and lore/npx fallback

🤖 Generated with Claude Code

Closes #41

Ian-stetsenko and others added 4 commits May 11, 2026 22:36
Add commit-msg hook management for Lore protocol enforcement:

- `lore hooks install` — installs commit-msg hook to .git/hooks/
- `lore hooks uninstall` — removes Lore-managed hooks only
- Hook validates commits via `lore validate --last 1 --strict`
- Skips merge commits, fixup/squash commits, configurable authors
- Falls back from `lore` to `npx lore-protocol` when not on PATH
- Detects existing non-Lore hooks (requires --force to overwrite, backs up to .bak)
- [hooks] config section: enforce, allow_fixup, skip_authors, skip_patterns
- .pre-commit-hooks.yaml for pre-commit framework integration
- .github/workflows/lore-validate.yml for GitHub Actions CI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Critical fixes:
- Sanitize skipPatterns and skipAuthors before interpolating into bash
  script (prevents shell injection via shared .lore/config.toml)
- Hook uses `lore validate --commit-msg-file` instead of `--last 1`
  (commit-msg hook fires before commit exists in git history)
- Add --commit-msg-file flag to validate command for hook integration

Major fixes:
- HookInstaller depends on IHookScriptGenerator interface, not concrete
  class (DIP compliance per CLAUDE.md)
- Extract resolveRepoRoot helper to DRY install/uninstall error handling
- Pass trailerParser to validate command for commit message file parsing

Tests updated for new script content and shell injection filtering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Same bug as the generated hook script — commit-msg hook fires before
the commit exists, so --last 1 validates the previous commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Most existing commits don't have Lore trailers yet. The workflow runs
validation but uses continue-on-error so PRs aren't blocked. Remove
continue-on-error and add --strict once all contributors use lore commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Ian-stetsenko Ian-stetsenko self-assigned this May 12, 2026
@c-ferrier

Copy link
Copy Markdown
Contributor

Before looking at this commit, I had missed this that validate takes in --since and turns it into a git range.... whereas --since elsewhere is expected to be a date...

Thoughts

should validate be --sinceRef ? to be clear? or we just know that --since has different meanings in different commands? Or should --since everywhere else be able to take things other than dates? Should validate take in a date? etc. just trying to rationalize expected behavior for --since

@c-ferrier

c-ferrier commented May 20, 2026

Copy link
Copy Markdown
Contributor

Just a follow up on the --since comment, in #55 i made a comment #55 (comment) which describes the changes I made in 43941eb which basically creates a better --since and --until processor that can deal with ISO Dates, references (besides in validate are buggy and return incorrect data) and relative dates (which depend on git, and silently blow up in the JS code but that error is eaten).

Looking forward to hearing your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: CI pipeline to enforce Lore commits on branches

2 participants