From ce439ccd0ffa46e63d7e5d6a6c9c40ab8a48502b Mon Sep 17 00:00:00 2001 From: deathpie <10750179+deathpie@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:28:07 -0500 Subject: [PATCH] docs: add the lefthook hook standard --- .prettierignore | 9 ++--- hooks/core.yml | 80 +++++++++++++++++++++++++++++++++++++++++++ hooks/owner.yml | 12 +++++++ scripts/core-drift.ts | 30 +++++++++------- standards/core.md | 40 +++++++++++++++++++++- standards/owner.md | 35 +++++++++++++++---- 6 files changed, 181 insertions(+), 25 deletions(-) create mode 100644 hooks/core.yml create mode 100644 hooks/owner.yml diff --git a/.prettierignore b/.prettierignore index f56ceef..8f8b955 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,7 @@ -# The two standard copies are byte-identical files: standards/core.md is shared -# between five owner repositories and scripts/core-drift.ts is copied from the -# standards directory. `just core-drift` compares core.md by hash, and formatting -# either file would break that comparison. +# The verbatim copies are byte-identical files: standards/core.md and +# hooks/core.yml are shared between five owner repositories and +# scripts/core-drift.ts is copied from the standards directory. `just core-drift` +# compares both shared files by hash, and formatting one would break it. standards/core.md +hooks/core.yml scripts/core-drift.ts diff --git a/hooks/core.yml b/hooks/core.yml new file mode 100644 index 0000000..c08e755 --- /dev/null +++ b/hooks/core.yml @@ -0,0 +1,80 @@ +# hooks/core.yml — byte-identical in the five owner .github repositories. +# Loaded by each repository's lefthook.yml through `remotes` at a pinned tag. +# Dispatcher only: every job calls a `just` recipe from the contract in +# standards/core.md C7.8. Repository jobs use their own names and never +# redefine a job named here. +min_version: 2.2.2 +assert_lefthook_installed: true +glob_matcher: doublestar +skip_lfs: true + +pre-commit: + parallel: true + jobs: + - name: core-fmt + glob: "**/*.{ts,tsx,js,jsx,mjs,cjs,mts,cts,json,jsonc,yml,yaml,md,toml,css,html}" + run: just fmt {staged_files} + stage_fixed: true + fail_text: "Formatting could not be applied; run `just fmt` and read the error." + + - name: core-lint + glob: "**/*.{ts,tsx,js,jsx,mjs,cjs,mts,cts}" + run: just lint {staged_files} + fail_text: "Lint failed on staged files; fix the findings and stage again." + + - name: core-secrets + run: just secrets-staged + fail_text: "A staged secret was found. Remove it; if it was ever pushed, rotate it." + + - name: core-forbidden-files + run: just forbidden-files {staged_files} + fail_text: "A forbidden or oversized file is staged (env file, key, kubeconfig, >5 MB)." + + - name: core-whitespace + run: git diff --cached --check + fail_text: "Staged whitespace errors or conflict markers; fix them and stage again." + + - name: core-workflows + glob: ".github/workflows/*.{yml,yaml}" + run: just workflows {staged_files} + fail_text: "actionlint or zizmor rejected a workflow." + + - name: core-shell + glob: "**/*.{sh,bash}" + run: just shellcheck {staged_files} + fail_text: "shellcheck findings in staged shell scripts." + + - name: core-agent-files + glob: + - "AGENTS.md" + - ".agents/**" + - ".claude/**" + run: just agent-files + fail_text: "Agent files are inconsistent (C8.3); run `just agent-files`." + +commit-msg: + jobs: + - name: core-conventional + run: just commit-msg {1} + +pre-push: + piped: true + jobs: + - name: core-policy + use_stdin: true + run: just hook-pre-push + fail_text: "Push refused. main changes only through a pull request (C2.1), or the pushed range failed the secret scan." + + - name: core-fast-check + run: just pre-push-check + fail_text: "Fast pre-push checks failed; run `just check` for the full set." + +post-checkout: + jobs: + - name: core-deps-refresh + run: just deps-refresh + +post-merge: + jobs: + - name: core-deps-refresh + run: just deps-refresh diff --git a/hooks/owner.yml b/hooks/owner.yml new file mode 100644 index 0000000..591e109 --- /dev/null +++ b/hooks/owner.yml @@ -0,0 +1,12 @@ +# hooks/owner.yml — deathpie owner hook jobs. Loaded with hooks/core.yml via remotes. +# Every job calls a `just` recipe listed in standards/owner.md. Repository jobs +# never reuse an `owner-*` name. +pre-commit: + jobs: + - name: owner-privacy-identity + run: just privacy-identity + fail_text: "The author or committer email is not the owner's GitHub no-reply address." + + - name: owner-privacy-staged + run: just privacy-staged + fail_text: "A staged blob contains private material. Remove it and stage again." diff --git a/scripts/core-drift.ts b/scripts/core-drift.ts index a4c240a..b2fe0d2 100755 --- a/scripts/core-drift.ts +++ b/scripts/core-drift.ts @@ -1,5 +1,5 @@ #!/usr/bin/env bun -// Compares standards/core.md across the five owner .github repositories. +// Compares standards/core.md and hooks/core.yml across the five owner .github repositories. // Runs locally only: it needs gh logged in as both deathpie and simpsonm09, // because no single token can read every owner (homelab's .github is private). // gh runs from the temp directory so the per-owner gh wrapper picks the token @@ -18,19 +18,23 @@ function run(cmd: string[]): string { return p.stdout.toString(); } -const local = sha(readFileSync("standards/core.md", "utf8")); +const files = ["standards/core.md", "hooks/core.yml"]; let drift = false; -for (const owner of owners) { - let hash: string; - try { - const body = run(["gh", "api", "-H", "Accept: application/vnd.github.raw", `repos/${owner}/.github/contents/standards/core.md`]); - hash = sha(body); - } catch (error) { - hash = `unreadable (${(error as Error).message.split("\n")[0]})`; +for (const file of files) { + const local = sha(readFileSync(file, "utf8")); + console.log(file); + for (const owner of owners) { + let hash: string; + try { + const body = run(["gh", "api", "-H", "Accept: application/vnd.github.raw", `repos/${owner}/.github/contents/${file}`]); + hash = sha(body); + } catch (error) { + hash = `unreadable (${(error as Error).message.split("\n")[0]})`; + } + const same = hash === local; + if (!same) drift = true; + console.log(` ${same ? "ok " : "DRIFT"} ${owner.padEnd(22)} ${hash}`); } - const same = hash === local; - if (!same) drift = true; - console.log(`${same ? "ok " : "DRIFT"} ${owner.padEnd(22)} ${hash}`); + console.log(` local ${local}`); } -console.log(`local ${local}`); process.exit(drift ? 1 : 0); diff --git a/standards/core.md b/standards/core.md index cbf246d..eea3265 100644 --- a/standards/core.md +++ b/standards/core.md @@ -4,7 +4,8 @@ This file is byte-identical in every owner's `.github` repository: `deathpie/.github`, `simpsonm09/.github`, `sakuragaoka-homelab/.github`, `awepeeps/.github` and `simpsonm09-projects/.github`, at `standards/core.md`. Change it in one pull request per owner, with the same content, or not at all. -`just core-drift` in any of those repositories compares the five copies. +`just core-drift` in any of those repositories compares the five copies of +this file and of `hooks/core.yml`. Each owner adds `standards/owner.md`. An owner standard may tighten any rule here. It may loosen only a rule marked **(profile)**, and it says how. @@ -129,6 +130,43 @@ without a reason or a date is drift. standard toolchain behind the same recipe names. - C7.7 `.editorconfig` is present. `.gitattributes` contains `* text=auto eol=lf`. +- C7.8 Git hooks run through Lefthook, pinned in `mise.toml` as + `"aqua:evilmartians/lefthook"`. Each owner's `.github` repository holds + `hooks/core.yml` (byte-identical across owners) and `hooks/owner.yml` + (owner jobs named `owner-*`), released as an annotated tag `hooks-v`. + A repository's `lefthook.yml` loads both through `remotes` at that tag and + adds its own jobs under names that never start with `core-` or `owner-`. + `just hooks` removes a local `core.hooksPath` only when it equals + `.githooks`, refuses any other value or a global one, runs + `lefthook install`, and then asserts that `lefthook dump` contains the + `core-*` and `owner-*` jobs, because a failed remote fetch only warns. + `lefthook-local.yml` is git-ignored. +- C7.9 CI has a `hooks` job: `lefthook install`, the same `lefthook dump` + assertion, then `lefthook validate` (which does not fetch remotes on its + own). +- C7.10 The hook recipe contract. Every repository defines these recipes; a + recipe with nothing to do exits 0. Variadic recipes need + `set positional-arguments`. + + | Recipe | Hook | Does | + | --- | --- | --- | + | `fmt *files` | pre-commit | formats the given files (all when none); fixes are re-staged | + | `lint *files` | pre-commit | lints the given files, check only | + | `secrets-staged` | pre-commit | `gitleaks git --staged --redact` | + | `forbidden-files *files` | pre-commit | rejects `.env*` except `*.example`, `*.pem`, `*.key`, `id_*`, kubeconfig, files over 5 MB | + | `workflows *files` | pre-commit | `actionlint` and `zizmor` | + | `shellcheck *files` | pre-commit | `shellcheck` | + | `agent-files` | pre-commit | C8.3 | + | `commit-msg file` | commit-msg | warns when the subject is not a Conventional Commit; never fails | + | `hook-pre-push` | pre-push | reads the pushed ref lines from stdin, refuses `refs/heads/main`, scans the exact pushed range with gitleaks plus the owner's scans | + | `pre-push-check` | pre-push | fast subset: type check and the tests the diff can reach | + | `deps-refresh` | post-checkout, post-merge | `bun install` when `bun.lock` changed, `mise install` when `mise.toml` changed | + + Budgets: pre-commit under 3 seconds and pre-push under 30 seconds on a + typical change. +- C7.11 Agents never skip hooks: no `LEFTHOOK=0`, no `--no-verify`, no + `lefthook-local.yml`. Hooks are advisory for humans; rulesets, the + direct-push guard and CI are the enforcement. ## C8. Agent instructions and skills diff --git a/standards/owner.md b/standards/owner.md index ee36888..890430f 100644 --- a/standards/owner.md +++ b/standards/owner.md @@ -49,9 +49,10 @@ request itself is the only gate and the missing check is a backlog row, not a qu The same three pieces in every repository: -1. `.githooks/pre-push`, installed by `just hooks`. It refuses a push whose remote ref is `main` - and refuses a commit whose `git log --format=%G?` is not `G` (a good SSH signature). An - owner-approved recovery may set `ALLOW_MAIN_PUSH=1` for one push. +1. `hooks/core.yml` and `hooks/owner.yml`, loaded through Lefthook and installed by `just hooks`. + The `core-policy` job refuses a push whose remote ref is `main` and refuses a commit whose + `git log --format=%G?` is not `G` (a good SSH signature). An owner-approved recovery may set + `ALLOW_MAIN_PUSH=1` for one push. 2. `.github/workflows/guard-direct-push.yml`, the same design as `sakuragaoka-homelab/agent-tooling`: after a push to `main` it asks the API whether every new commit belongs to a merged pull request, opens or comments on one `direct-push` issue, and @@ -92,9 +93,9 @@ C7.5 asks for `install`, `fmt`, `fmt-check`, `lint`, `typecheck`, `test`, `check `agent-files` in every repository. This repository has only what a docs-only tree can run: `default`, `fmt`, `fmt-check` and `check`, plus `core-drift`. The rest go into `docs/exceptions.md` as C7.5 exceptions, with the reason that there is nothing to install, lint, -typecheck or test (backlog). In a repository with scripts, `hooks` installs `.githooks/pre-push` -and `agent-files` fails when `.agents/skills` and `.claude/skills` disagree or a skill names a -missing recipe. +typecheck or test (backlog). In a repository with scripts, `hooks` runs `lefthook install` and +asserts that `lefthook dump` contains the `core-*` and `owner-*` jobs, and `agent-files` fails +when `.agents/skills` and `.claude/skills` disagree or a skill names a missing recipe. `just check` in `.github` runs `fmt-check`; `core-drift` needs `gh` logged in as two accounts, so it stays a local command and never a required check. @@ -107,6 +108,26 @@ CI median (C5.1): none of the six repositories has a workflow run, so there is n report. Each repository records its first median after 20 pull-request runs; until then the backlog row stays open rather than claiming a number. +## Git hooks + +Hooks run through Lefthook, pinned in `mise.toml` as `"aqua:evilmartians/lefthook"` (C7.8). Each +repository's `lefthook.yml` loads `hooks/core.yml` and `hooks/owner.yml` from this repository +through `remotes` at the annotated tag `hooks-v2`, and adds its own jobs under names that never +start with `core-` or `owner-`. Repositories migrate from the old `.githooks` launchers to Lefthook +per core C7.8. + +This owner's `hooks/owner.yml` jobs run before every commit: + +| Job | Recipe | Behaviour | +| ------------------------ | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `owner-privacy-identity` | `just privacy-identity` | Fails unless the effective author and committer email, including environment overrides, is the GitHub no-reply address. | +| `owner-privacy-staged` | `just privacy-staged` | Fails when a staged blob contains an IP address, an email other than the no-reply address, a hostname from the local denylist, a serial number or a token. | + +`just hooks` removes a local `core.hooksPath` only when it equals `.githooks`, refuses any other +value or a global one, runs `lefthook install`, and then asserts that `lefthook dump` contains the +`core-*` and `owner-*` jobs, because a failed remote fetch only warns. `lefthook-local.yml` is +git-ignored, and agents never skip hooks: no `LEFTHOOK=0`, no `--no-verify` (C7.11). + ## Owner rules 1. **Privacy baseline.** Treat every repository as if it could become public. No personal @@ -168,7 +189,7 @@ listed: every repository has `runs.total_count: 0`. | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `.github` | C1.5 wiki and Projects on. C2.1 no ruleset. C2.3 settings still allow merge and rebase. C2.6 `delete_branch_on_merge=false` and a stale `chore/t3-project-icon` branch. C1.6 no MIT `LICENSE`. C2.2 and C5.1 no `check` workflow, so no required status check. C7.5 `install`, `lint`, `typecheck`, `test`, `hooks` and `agent-files` have nothing to run. | Owner applies the `main` ruleset and turns the merge settings to squash-only with branch deletion. Add an MIT `LICENSE`, a `checks.yml` running `just check`, and exception rows for the recipes that do not apply to a docs-only repository. Delete the stale branch. | | `deathpie` | C1.2 no description. C1.5 wiki and Projects on. C2.1 no ruleset. C2.6 stale `chore/t3-project-icon`. C1.6 no license. C7.5 and C7.7 no `justfile`, `mise.toml`, `.editorconfig` or `.gitattributes`. C8.1 no `AGENTS.md`. C2.2 no required check. | One pull request with the description, the ruleset and the same cheap skeleton as `.github`. Record C1.6 as an exception while the repository is a two-file profile README. | -| `deathpie-discord` | C2.1 no hook, guard or automerge workflow. C3.2 no `dependabot.yml`. C1.5 Projects on. C2.5 `save/opentofu-pilot-handoff` and three merged `chore/*` branches remain. C7.5 and C7.7 no `justfile`, `mise.toml`, `.editorconfig` or `.gitattributes`. | Add `.githooks/pre-push`, the two workflows, `dependabot.yml` for `github-actions`, the toolchain skeleton and `AGENTS.md` updates for the new recipes. Delete the `save/` and merged branches after confirming the handoff document exists. No CI: data-only. | +| `deathpie-discord` | C2.1 no hook, guard or automerge workflow. C3.2 no `dependabot.yml`. C1.5 Projects on. C2.5 `save/opentofu-pilot-handoff` and three merged `chore/*` branches remain. C7.5 and C7.7 no `justfile`, `mise.toml`, `.editorconfig` or `.gitattributes`. | Add `lefthook.yml` loading the `hooks-v2` remotes, the two workflows, `dependabot.yml` for `github-actions`, the toolchain skeleton and `AGENTS.md` updates for the new recipes. Delete the `save/` and merged branches after confirming the handoff document exists. No CI: data-only. | | `nsfw-model-testing` | C2.1 no hook, guard or automerge workflow. C3.2 no `dependabot.yml`. C5.1 no required check in a repository that ships a script. C8.1 no `AGENTS.md`. C7.5 and C7.7 no `justfile`, `mise.toml`, `.editorconfig` or `.gitattributes`. C1.5 Projects on. C2.5 stale `save/research-notes-prereinstall-20261029` branch. | Same protection and dependency files, plus `justfile` with `check` (`fmt-check`, `actionlint`, `zizmor`, PSScriptAnalyzer) and a `checks.yml`; `AGENTS.md` covering the model tree and the adult-content constraints. Delete the `save/` branch after the notes land in `docs/`. | | `sd-card-tools` | C2.1 no hook, guard or automerge workflow. C3.2 no `dependabot.yml`. C5.1 no required check. C8.1 no `AGENTS.md`, and the destructive-script rule has nowhere to live. Owner rule 5: `format-photos.sh` plans and asks for `FORMAT`, but `--yes` bypasses the word and there is no dry-run default. C7.7 no `.editorconfig` or `.gitattributes`. C1.5 Projects on. | Add protection, dependency and toolchain files with `check` = `fmt-check` plus `shellcheck`. Make `--dry-run` the default when `--yes` is absent, keep `FORMAT` as the interactive word, and state both in a new `AGENTS.md` with the `targets.conf` privacy rule. | | `wow-forever-settings` | C2.1 no hook, guard or automerge workflow. C3.2 no `dependabot.yml`. C5.1 no required check. C8.1 no `AGENTS.md`; the constraints live in README prose. C7.4 four Python helpers (`export_portable_settings.py`, `make_snapshot_linux.py`, `restore_snapshot_linux.py`, `compare_savedvariables.py`). Owner rule 5: restore and apply need a dry-run default and a confirmation word; `restore_snapshot_linux.py` has `--dry-run` only as an option. C7.7 `.gitattributes` has byte rules but no `* text=auto eol=lf`. C2.5 `docs/research-keyboard-party-invites` remains. | Add protection, dependency and toolchain files; `check` = `fmt-check`, `actionlint`, `zizmor`, `py_compile` until the migration. Port the helpers to Bun TypeScript one at a time, recording an exception for any that cannot move. Add the global `text=auto` line above the `/WTF/**` byte rules, and `AGENTS.md` with the dry-run and confirmation rules. |