# Lefthook configuration # See https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md # # To install: lefthook install # To skip: LEFTHOOK=0 git commit/push # To install tools: make bootstrap pre-commit: parallel: true commands: # Format and lint Go code with auto-fix (includes gofumpt and goimports) go-lint-fix: tags: backend lint style glob: "*.go" run: | if ! command -v golangci-lint > /dev/null 2>&1; then echo "⚠️ golangci-lint not found. Run 'make bootstrap' to install tools." echo " Skipping Go formatting and linting check..." exit 0 fi # Get unique package directories from staged files packages=$(echo {staged_files} | xargs -n1 dirname | sort -u | xargs -I {} echo "./{}") if [ -n "$packages" ]; then golangci-lint run --fix $packages fi stage_fixed: true # Flag comments whose wording is already carried by the code beside them. # Gated at full token coverage, where the comment adds nothing a reader # cannot get from the line itself; lower thresholds are for reporting, not # gating, because they need human judgement. comment-overlap: tags: backend lint style glob: "*.go" run: | if ! command -v go > /dev/null 2>&1; then echo "⚠️ go not found. Skipping comment overlap check..." exit 0 fi go run ./scripts/comment-overlap -threshold 1.0 -max-findings 0 {staged_files} # Lint shell scripts shellcheck: tags: shell lint glob: "*.sh" run: | if ! command -v shellcheck > /dev/null 2>&1; then echo "⚠️ shellcheck not found. Run 'make bootstrap' to install tools." echo " Skipping shell script linting..." exit 0 fi shellcheck {staged_files} # Fix markdown formatting issues markdownlint-fix: tags: docs style glob: "*.md" run: | if ! command -v markdownlint-cli2 > /dev/null 2>&1; then echo "⚠️ markdownlint-cli2 not found. Run 'make bootstrap' to install tools." echo " Skipping markdown auto-fix..." exit 0 fi markdownlint-cli2 --fix {staged_files} git add {staged_files} stage_fixed: true # Fail fast if any skill source can't be loaded — covers a missing # SKILL.md, unparseable frontmatter, an empty `name` or `description`, # a directory mismatch in bundled assets, or a malformed remote # registry entry. Full Agent Skills spec compliance # (https://agentskills.io/specification) is hand-reviewed in MRs, # not enforced here. validate-skills: tags: backend skills glob: "internal/commands/skills/**" run: | if ! command -v go > /dev/null 2>&1; then echo "⚠️ go not found. Skipping skills validation..." exit 0 fi go test ./internal/commands/skills/... # Check if documentation needs regeneration check-docs: tags: docs glob: - "internal/commands/**/*.go" - "cmd/gen-docs/*.go" - "cmd/gen-docs/**/*.go" - "README.md" run: | echo "Checking if documentation needs regeneration..." make gen-docs > /dev/null 2>&1 if git diff --quiet docs/ README.md; then echo "✔ Documentation is up to date." exit 0 else echo "" echo "✖ ERROR: Documentation changes detected!" echo "" echo "Command files were modified and documentation is out of sync." echo "The documentation has been regenerated for you." echo "" echo "Next steps:" echo " 1. Review the changes in docs/ and README.md" echo " 2. Stage the changes: git add docs/ README.md" echo " 3. Commit again" echo "" exit 1 fi commit-msg: commands: # Validate commit message format using conventional commits commitlint: run: | if ! command -v node > /dev/null 2>&1; then echo "⚠️ node not found. Commit message validation requires Node.js." echo " Skipping commit message validation..." exit 0 fi # Install commitlint dependencies if not already installed if [ ! -d "scripts/commit-lint/node_modules" ]; then echo "Installing commitlint dependencies (one-time setup)..." cd scripts/commit-lint && npm install else cd scripts/commit-lint fi npx commitlint --config .commitlintrc.js --edit {1} pre-push: parallel: true commands: # Build the project build: tags: backend run: make build # Lint Go code (only changes vs main) go-lint: tags: backend lint run: | if ! command -v golangci-lint > /dev/null 2>&1; then echo "⚠️ golangci-lint not found. Run 'make bootstrap' to install tools." echo " Skipping Go linting..." exit 0 fi golangci-lint run --new-from-rev=origin/main # Run unit tests on changed packages and their reverse dependencies go-test: tags: backend test run: make test-changed # Report how much of the push is comment rather than code. Advisory: the # repo distribution has no natural cutoff, so the number is context for # the author rather than a pass/fail line. comment-ratio: tags: backend lint style glob: "*.go" run: | if ! command -v go > /dev/null 2>&1; then echo "⚠️ go not found. Skipping comment ratio report..." exit 0 fi go run ./scripts/comment-ratio -base origin/main # Forbid //go:embed of .md files as help text; use heredoc.Doc instead check-embed: tags: backend lint glob: "internal/**/*.go" run: make check-embed # Forbid cobra.ExactArgs(0); use cobra.NoArgs instead check-args: tags: backend lint glob: "{internal,cmd}/**/*.go" run: make check-args # Check generated docs and Go code. Chained into one command because both # mutate the working tree and check git diff — running them in parallel # would cause false positives. check-generated: tags: backend docs run: | # Skip if no command files changed vs origin/main if git diff --quiet origin/main -- internal/commands/ cmd/gen-docs/ README.md; then echo "✔ No command changes detected. Skipping doc generation check." exit 0 fi make gen-docs > /dev/null 2>&1 if ! git diff --quiet docs/ README.md; then echo "✖ Generated docs, navigation, or README command list are out of date. Run 'make gen-docs', then commit." exit 1 fi echo "✔ Documentation is up to date." make generate > /dev/null 2>&1 if ! git diff --quiet; then echo "✖ Generated Go code is out of date. Run 'make generate' and commit." exit 1 fi echo "✔ Generated code is up to date." # Lint markdown files markdownlint: tags: docs lint glob: "*.md" run: | if ! command -v markdownlint-cli2 > /dev/null 2>&1; then echo "⚠️ markdownlint-cli2 not found. Run 'make bootstrap' to install tools." echo " Skipping markdown linting..." exit 0 fi markdownlint-cli2 {push_files} # Lint markdown tables and other rules that rumdl enforces rumdl: tags: docs lint glob: "*.md" run: | if ! command -v rumdl > /dev/null 2>&1; then echo "⚠️ rumdl not found. Run 'make bootstrap' to install tools." echo " Skipping rumdl linting..." exit 0 fi rumdl check --config docs/.rumdl/rumdl.toml {push_files} # Check prose style vale: tags: docs prose glob: "docs/**/*.md" run: | if ! command -v vale > /dev/null 2>&1; then echo "⚠️ vale not found. Run 'make bootstrap' to install tools." echo " Skipping prose checking..." exit 0 fi vale --minAlertLevel error {push_files} # Check links in documentation (can be slow) lychee: tags: docs links glob: "*.md" run: | if ! command -v lychee > /dev/null 2>&1; then echo "⚠️ lychee not found. Run 'make bootstrap' to install tools." echo " Skipping link checking..." exit 0 fi lychee --offline --include-fragments {push_files}