AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
chore(git): identity-guard hooks — stop concurrent-session identity leaks at commit time
xerj-orgb8617dabaa6e
diff --git a/scripts/git-hooks/commit-msg b/scripts/git-hooks/commit-msgnew file mode 100755index 000000000..b831992be--- /dev/null+++ b/scripts/git-hooks/commit-msg@@ -0,0 +1,17 @@+#!/bin/sh+# XERJ identity guard — commit-msg hook.+#+# FOR xerj-org AGENT-FLEET MACHINES ONLY.+#+# Enforces the standing repository directive (2026-07-22): commit+# messages must not carry Claude / AI co-author trailers. The history is+# authored as xerj-org, full stop.+#+# $1 is the path to the commit message file.++if grep -qiE '^[[:space:]]*Co-Authored-By:.*(claude|anthropic|noreply@anthropic\.com)' "$1"; then+ echo "identity-guard: refusing commit — Co-Authored-By Claude/Anthropic trailer found." >&2+ echo "identity-guard: this repository never carries AI co-author trailers (directive 2026-07-22)." >&2+ exit 1+fi+exit 0diff --git a/scripts/git-hooks/install.sh b/scripts/git-hooks/install.shnew file mode 100755index 000000000..cffe0f7b6--- /dev/null+++ b/scripts/git-hooks/install.sh@@ -0,0 +1,28 @@+#!/bin/sh+# Install the XERJ identity-guard hooks into this clone's shared .git/hooks.+#+# FOR xerj-org AGENT-FLEET MACHINES ONLY — enforces the xerj-org identity+# on every worktree of the clone (hooks are shared across worktrees when+# core.hooksPath is unset). Do not run on a personal contributor checkout.+#+# Usage: scripts/git-hooks/install.sh+set -eu++here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)+git_common=$(git rev-parse --git-common-dir)++if hooks_path=$(git config --get core.hooksPath); then+ echo "install: core.hooksPath is set ($hooks_path); refusing to guess. Install manually." >&2+ exit 1+fi++for hook in pre-commit commit-msg; do+ dst="$git_common/hooks/$hook"+ if [ -e "$dst" ] && ! cmp -s "$here/$hook" "$dst"; then+ echo "install: $dst already exists and differs; not overwriting." >&2+ exit 1+ fi+ cp "$here/$hook" "$dst"+ chmod +x "$dst"+ echo "installed $dst"+donediff --git a/scripts/git-hooks/pre-commit b/scripts/git-hooks/pre-commitnew file mode 100755index 000000000..61f04e431--- /dev/null+++ b/scripts/git-hooks/pre-commit@@ -0,0 +1,53 @@+#!/bin/sh+# XERJ identity guard — pre-commit hook.+#+# FOR xerj-org AGENT-FLEET MACHINES ONLY. Do not install on a personal+# contributor checkout; it enforces the xerj-org committer identity.+#+# Why this exists: many concurrent agent sessions share one repository+# (one .git, many worktrees, one shared repo-local config). Twice on+# 2026-08-08 a session's transient identity override (env var or a+# momentary `git config user.email` edit of the shared config) leaked a+# personal e-mail address into commits that reached the public repo+# (PR #219 commit c16320bb, PR #231 commit 15082748), and on 2026-08-04+# the same mechanism leaked a third-party address into main. Config+# audits cannot stop a transient override; refusing the commit can.+#+# What it checks: the exact author and committer ident git is about to+# use (`git var` resolves env vars AND config, in the same order commit+# does). Anything but the sanctioned xerj-org identities is refused.+#+# Coverage note (honest): pre-commit runs on `git commit` (including+# --amend) but NOT on rebase/cherry-pick continuation commits, and+# `git commit --no-verify` bypasses it. It is a guard rail, not a+# security boundary.++allowed_1='xerj-org <[email protected]>'+allowed_2='xerj-org <[email protected]>'++# `git var GIT_AUTHOR_IDENT` -> "Name <email> epoch tz"; strip the date.+author=$(git var GIT_AUTHOR_IDENT | sed 's/ [0-9][0-9]* [+-][0-9][0-9]*$//')+committer=$(git var GIT_COMMITTER_IDENT | sed 's/ [0-9][0-9]* [+-][0-9][0-9]*$//')++fail=0+case "$author" in+ "$allowed_1"|"$allowed_2") ;;+ *) echo "identity-guard: refusing commit — author is '$author'" >&2; fail=1 ;;+esac+case "$committer" in+ "$allowed_1"|"$allowed_2") ;;+ *) echo "identity-guard: refusing commit — committer is '$committer'" >&2; fail=1 ;;+esac++if [ "$fail" -ne 0 ]; then+ cat >&2 <<'EOF'+identity-guard: commits in this repository must be authored as+identity-guard: xerj-org <[email protected]>+identity-guard: fix with:+identity-guard: git config user.name xerj-org+identity-guard: git config user.email [email protected]+identity-guard: and unset any GIT_AUTHOR_* / GIT_COMMITTER_* overrides.+EOF+ exit 1+fi+exit 0diff --git a/scripts/git-hooks/test.sh b/scripts/git-hooks/test.shnew file mode 100755index 000000000..03ea88e6f--- /dev/null+++ b/scripts/git-hooks/test.sh@@ -0,0 +1,73 @@+#!/bin/sh+# Self-test for the XERJ identity-guard hooks.+#+# Builds a scratch repository, proves the failure mode exists WITHOUT the+# hooks (a leaked identity commits successfully), installs the hooks, and+# proves each guard: wrong author/committer refused, correct identity+# accepted, Claude co-author trailer refused.+#+# Exits 0 only if every assertion holds. No network, no shared state.+set -eu++here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)+tmp=$(mktemp -d)+trap 'rm -rf "$tmp"' EXIT++fails=0+check() { # check <desc> <expected 0|1> <actual-exit>+ if [ "$2" -eq 0 ] && [ "$3" -eq 0 ]; then echo "PASS: $1";+ elif [ "$2" -ne 0 ] && [ "$3" -ne 0 ]; then echo "PASS: $1";+ else echo "FAIL: $1 (expected exit $2, got $3)"; fails=$((fails+1)); fi+}++git init -q "$tmp/repo"+cd "$tmp/repo"+git config user.name xerj-org+git config user.email [email protected]++# 1. Without the hooks the leak is silent — this is the bug being fixed.+rc=0; git -c [email protected] -c user.name=xerj-org \+ commit -q --allow-empty -m "leak without hooks" || rc=$?+check "without hooks, a leaked identity commits (the pre-fix failure)" 0 "$rc"+leaked_email=$(git log -1 --format=%ae)+[ "$leaked_email" = "[email protected]" ] || { echo "FAIL: leak not recorded"; fails=$((fails+1)); }++# Install the hooks.+cp "$here/pre-commit" "$here/commit-msg" .git/hooks/+chmod +x .git/hooks/pre-commit .git/hooks/commit-msg++# 2. Wrong email via config — refused.+rc=0; git -c [email protected] commit -q --allow-empty -m x 2>/dev/null || rc=$?+check "wrong config email refused" 1 "$rc"++# 3. Wrong email via environment — refused.+rc=0; [email protected] GIT_AUTHOR_NAME=xerj-org \+ git commit -q --allow-empty -m x 2>/dev/null || rc=$?+check "wrong env author refused" 1 "$rc"++# 4. Wrong committer via environment — refused.+rc=0; [email protected] GIT_COMMITTER_NAME=xerj-org \+ git commit -q --allow-empty -m x 2>/dev/null || rc=$?+check "wrong env committer refused" 1 "$rc"++# 5. Wrong name, sanctioned email — refused.+rc=0; git -c user.name=somebody commit -q --allow-empty -m x 2>/dev/null || rc=$?+check "wrong name refused" 1 "$rc"++# 6. Claude co-author trailer — refused.+rc=0; git commit -q --allow-empty \+ -m "ok subject" -m "Co-Authored-By: Claude <[email protected]>" 2>/dev/null || rc=$?+check "Claude co-author trailer refused" 1 "$rc"++# 7. Correct identity — accepted.+rc=0; git commit -q --allow-empty -m "good identity" || rc=$?+check "sanctioned identity accepted" 0 "$rc"++# 8. Noreply variant — accepted.+rc=0; git -c [email protected] \+ commit -q --allow-empty -m "noreply variant" || rc=$?+check "noreply variant accepted" 0 "$rc"++echo "---"+if [ "$fails" -eq 0 ]; then echo "identity-guard test: ALL PASS"; else+ echo "identity-guard test: $fails FAILURE(S)"; exit 1; fi