Skip to content

feat: add cross-harness workflow guard hooks (#102) - #105

Merged
q-soriarty merged 56 commits into
developfrom
feature/102-workflow-guard
Nov 19, 2026
Merged

q-soriarty merged 56 commits into
developfrom
feature/102-workflow-guard

Conversation

@q-soriarty

@q-soriarty q-soriarty commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an optional enforcement guard for the skill's rules: hooks/guard.mjs (Node ≥ 20, no dependencies) hooks into AI coding harnesses before they run git/gh commands, plus optional commit-msg/pre-push git-hook shims. The skill itself stays self-contained; the guard is opt-in tooling.

  • Rules (16 ids, e.g. conventional-commit, protected-commit, branch-name, branch-issue, fresh-base, pr-base, force-push, no-verify, no-ai-attribution, merge-method, merge-gate, test-plan-ticked): deny > ask > warn > allow, one-line messages with what to do instead, fail-open on parse/state errors
  • Harnesses: Claude Code and Codex CLI adapters; merge-gate asks where the harness can ask, otherwise needs WORKFLOW_GUARD_APPROVE=<PR>
  • Management: install | update | doctor | repair | uninstall | enable | disable; scope opt-in (per-repo .git-workflow.json) or all
  • Wiring: install scripts register the hooks (--scope, --no-hooks); CI guard-tests matrix on Ubuntu/macOS/Windows with Node 20; issue templates use fix: / feat: prefixes
  • Docs: SKILL.md "Enforcement (optional)" section and guard commands, conventional issue-title rule, release issue title chore(release): prepare X.Y.Z; README guard section incl. a tested / not tested table; CLAUDE.md; CHANGELOG [Unreleased]
  • Includes develop (feat: add epic branches as a branch type #99 epic branches, feat: regulate rebase instead of forbidding it #101 rebase rules); the guard's force-push rule matches the Rebase Rules
  • No version bump (happens on the release branch)

Closes #102

Test plan

Automated:

  • ./scripts/lint.sh — All checks passed
  • node --test hooks/test/ on Linux (Node 26) — 211/211
  • Windows VM (Node 26, Git Bash) — 202 pass + 2 intentional symlink skips (at 5be1c2f, before the Task 12 docs/fix commits)
  • CI guard-tests on ubuntu/macos/windows with Node 20 — all green (first run caught a Windows 8.3 short-path bug in update, fixed in a696936)

Manual (throwaway repos, deleted afterwards):

  • Linux + Claude Code, local repo: reminder, conventional-commit, protected-commit, branch-name, no-ai-attribution, no-verify, force-push (incl. bash -c, timeout, +refspec), protected-delete, merge-method deny; plain echo no false positive
  • Linux + Claude Code, GitHub repo: branch-issue (missing/closed), fresh-base, pr-base (explicit and omitted base), conventional-title, closes-one-per-line, test-plan-ticked, merge-gate, tag-on-main deny; epic/* merge allowed; merge-gate ask shown in default and auto mode, user No → not merged; dontAsk → deny with approval hint, wrong number rejected, agent did not self-approve, WORKFLOW_GUARD_APPROVE after user yes merged
  • Linux + Codex CLI 0.170, local and GitHub repo: reminder and denies fire (commands arrive as exec_command); merge-gate deny with approval hint, wrong number rejected, approval path merged; epic/* merge allowed
  • Windows VM + Claude Code (Git Bash): same rule ids deny as on Linux; cd /c/... drive paths work; merge-gate ask shown; git-hook shims (commit-msg, pre-push) checked over SSH
  • Linux install script with a temporary HOME: install, re-run (scope kept), --no-hooks, --uninstall

Not tested (also listed in the README):

  • macOS with a harness, install_macos.sh (only the automated suite runs, in CI)
  • Windows + Codex CLI
  • Windows PowerShell commands (not guarded yet, phase 2)
  • install_windows.ps1 (not executed)
  • Copilot CLI, Gemini CLI, Cursor (no adapter yet)
  • GUI git clients with the git-hook shims

Checklist

  • All workflow invariants are preserved (atomic commits, conventional commits, no AI signatures, gitflow, issue-driven, PR-only merges, semver)
  • Decision guides cover the new/changed rules
  • Tested by invoking the skill in a Claude Code session
  • All content is in English

Design for enforcing the skill's rules through a shared Node.js guard
engine, harness hook adapters (Claude Code and Codex CLI first), git
hooks as a backstop and a session-start reminder.

Refs #102
Add the guard.mjs entry point with a hook dispatch table, tool-input
command extraction (Bash, Codex shell, context-mode), the Claude Code and
Codex adapters, and the session-start reminder.

Refs #102
Only off, warn, ask and deny change a finding; "on" and unknown values
keep the rule's own decision instead of silently allowing. A configured
ask becomes deny where the harness or git hook cannot ask, and the
raw-text fallback now honours warn and off.

Refs #102
A chained pre-push.local that read stdin (git-lfs does) left the guard
with no refs, so a push to a protected branch passed. The shim now
captures the ref list once and feeds it to both hooks; older shims are
recognised as ours and upgraded in place.

Refs #102
Only an explicit "no such issue" reply marks an issue missing; a
repository or auth error is unknown. Refs or repos that start with a
dash never reach gh. The fetch timeout drops to 5 s so a slow network
stays inside the hook budget. Adds memoised branchExists and
defaultBranch queries.

Refs #102
git branch -f, checkout -B and switch -C on a protected or existing
local branch reset it, so branch-name, branch-issue and fresh-base no
longer deny them. pr-base without --base now checks the repository's
default branch instead of assuming develop.

Refs #102
timeout DURATION, xargs (including -I templates and value flags) and
eval hid gh pr merge --squash and git push --force from the parsed
rules. eval arguments are re-parsed like bash -c, under the same depth
cap.

Refs #102
gh -R o/r pr merge and gh pr -R o/r merge were not recognised, so the
merge rules never ran. -R now folds into repo for every gh sub, the
merge rules drop their R fallback, and pr edit passes the repo to its
pr view lookup.

Refs #102
--trailer values now reach the attribution scan. -uno and -S<keyid>
take an attached value, so -uno is no longer read as --no-verify.
-F and --body-file read only regular files up to 1 MiB, so a FIFO or
device cannot hang the hook.

Refs #102
- add Bash to the Codex PreToolUse matcher; Codex reports shell calls
  under that tool name
- refuse a non-array hooks.<Event> instead of replacing it
- raise the registered hook timeout to 30 s
- write configs through symlinks and keep the file mode
- install with scope opt-in prints how to enable a repository
- repair backs up an invalid user config to <file>.bak first
- doctor repo checks in tests use the exec stub

Refs #102
A stale registration made guard.mjs hook exit 2, which Claude Code
treats as a block for every Bash call. It now exits 0 with one warning
line and no output.

Refs #102
Resolved cwd expectations use path.resolve, so they hold on Windows
where the parser yields drive-letter paths.

Refs #102
Run the guard install after the skill symlink when node is available,
and the guard uninstall on --uninstall. Add --no-hooks and --scope.

Refs #102
Without --scope, install keeps a valid scope from the user config and
merges harnesses with earlier runs. An explicit --scope still wins.

Refs #102
The repository bootstrap in SKILL.md runs `git checkout -b develop`;
branch-name denied it as an invalid name.

Refs #102
A string such as "codex" in the user config was spread into single
characters.

Refs #102
Without .git-workflow.json, disable reported the guard as inactive
even when the user scope is all.

Refs #102
…ands

Add the issue-title rule the conventional-title check already enforces,
resolve the guard path from the skill directory, describe what disable
really does, and note how a human allows recovery force-pushes on
shared branches.

Refs #102
Run enable inside the target repository, say what uninstall leaves
behind, explain the on level, and state the force-push rule as the
skill does.

Refs #102
State which platform, harness and install-script combinations were
exercised before release (Linux Claude Code and Codex, Windows Claude
Code) and mark the untested ones (macOS, Windows Codex and PowerShell,
install_windows.ps1, Copilot/Gemini/Cursor, GUI git clients) so that
"supported" is not read as "verified".

Refs #102
fs.realpathSync does not expand Windows 8.3 short names, so a skill dir
under C:\Users\RUNNER~1\... never matched the long path git reports and
update treated the clone as "not a git clone". Use realpathSync.native,
which resolves short names on Windows and is a no-op change elsewhere.

Refs #102
@q-soriarty
q-soriarty merged commit dc8da90 into develop Nov 19, 2026
4 checks passed
@q-soriarty
q-soriarty deleted the feature/102-workflow-guard branch November 19, 2026 09:25
@q-soriarty q-soriarty mentioned this pull request Nov 19, 2026
10 tasks done
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.

1 participant