Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

feat(pii): gate commit messages, branch names and PR text, not just files (#990)

Aurora Capitalefba39778ae8
diff --git a/.githooks/commit-msg b/.githooks/commit-msg
new file mode 100755
index 00000000..a90fce3f
--- /dev/null
+++ b/.githooks/commit-msg
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# commit-msg hook — THIS IS THE ONE THAT WAS MISSING.
+#
+# `pre-commit` scans the staged diff and `pii-gate` scans tracked files. A
+# commit MESSAGE is neither, so it was never scanned at all — and on
+# 2026-09-16 a personal name went out in one, to a public repo, with every
+# gate green. A message is as public as any line of code and is harder to
+# remove afterwards, because rewriting it rewrites history.
+#
+# Patterns come from claude-ops/tests/lib/pii-patterns.sh, the single source
+# the pre-push hook and the CI job also read.
+set -uo pipefail
+
+MSG_FILE="${1:-}"
+[[ -n "$MSG_FILE" && -f "$MSG_FILE" ]] || exit 0
+
+ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
+SCAN="$ROOT/claude-ops/bin/ops-pii-scan"
+
+# A missing scanner is not a pass. Say so, loudly, and let the commit through:
+# a hook that hard-fails on a partial checkout teaches people to use
+# --no-verify, and then nothing is gated at all.
+if [[ -z "$ROOT" || ! -x "$SCAN" ]]; then
+ echo "WARNING: ops-pii-scan not found — the commit message was NOT scanned." >&2
+ exit 0
+fi
+
+exec "$SCAN" --commit-msg-file "$MSG_FILE"
diff --git a/.githooks/pre-commit b/.githooks/pre-commit
index 779c0109..06b2ade9 100755
--- a/.githooks/pre-commit
+++ b/.githooks/pre-commit
@@ -19,7 +19,19 @@ echo "Running pre-commit security checks..."
# forbidden value and prove the gate refuses it. Any other file, including any
# other test, is scanned. The exemption is per path, never per directory:
# tests/ as a whole was already the one place a client id could sit unseen.
-EXEMPT_RE='^claude-ops/tests/(test-no-secrets\.sh|known-public-constants\.txt|test-pii-gate-fires\.sh|test-pre-commit-hook-blocks\.sh)$'
+# Three files joined the list on 2026-09-16, for the same reason as the
+# original four and no other. `pii-patterns.sh` IS the rule source: it has to
+# spell out the shapes it forbids, including the reserved phone range and the
+# lowercase API path that documents a real case-sensitivity bug.
+# `test-pii-metadata-gate.sh` is a negative control whose whole job is to plant
+# a forbidden value and prove the gate refuses it. The digest files hold
+# hashes, never terms.
+#
+# Note what is NOT exempted: `bin/ops-pii-scan` reads the shared list and still
+# scans every one of these files. That is deliberate — the shared pass caught a
+# real forbidden bigram in the negative control while this hook was blocked on
+# a placeholder phone number. Two passes, different jobs.
+EXEMPT_RE='^claude-ops/tests/(test-no-secrets\.sh|known-public-constants\.txt|test-pii-gate-fires\.sh|test-pre-commit-hook-blocks\.sh|test-pii-metadata-gate\.sh|pii-term-digests\.txt|pii-term-digests-warn\.txt|lib/pii-patterns\.sh)$'
DIFF_ADDED=""
while IFS= read -r f; do
[[ -z "$f" ]] && continue
@@ -178,6 +190,16 @@ if [[ $FAILED -eq 1 ]]; then
exit 1
fi
+# === Shared pattern source (claude-ops/tests/lib/pii-patterns.sh) ============
+# The checks above are this hook's own copy of the rules, kept because they are
+# tested and because they name the staged line precisely. This pass adds the
+# SHARED list — the same one commit-msg, pre-push and the CI job read — so a
+# pattern added in one place can never be missing here. Overlap is fine; a
+# double report costs a line of output, a gap costs a public leak.
+if [[ -x "claude-ops/bin/ops-pii-scan" ]]; then
+ claude-ops/bin/ops-pii-scan --staged || exit 1
+fi
+
# Run test suite secrets scanner if available
if [[ -f "claude-ops/tests/test-no-secrets.sh" ]]; then
(cd claude-ops && bash tests/test-no-secrets.sh > /dev/null 2>&1) || {
diff --git a/.githooks/pre-push b/.githooks/pre-push
new file mode 100755
index 00000000..82fa0e7f
--- /dev/null
+++ b/.githooks/pre-push
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+# pre-push hook — last stop before anything becomes public.
+#
+# `commit-msg` only sees the message being written now. It cannot see a commit
+# that was made before the hook was installed, one made with --no-verify, one
+# that arrived by cherry-pick or rebase, or one written on another machine. The
+# push is the moment all of those become public at once, so it is the moment to
+# check the whole range.
+#
+# It also checks the BRANCH NAME, which no other surface looks at and which
+# GitHub prints on the PR, in the compare view, and in every notification email.
+#
+# Deliberately bounded: only the commits actually being pushed, never the whole
+# history. A gate that takes a minute gets bypassed.
+set -uo pipefail
+
+ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
+SCAN="$ROOT/claude-ops/bin/ops-pii-scan"
+if [[ -z "$ROOT" || ! -x "$SCAN" ]]; then
+ echo "WARNING: ops-pii-scan not found — this push was NOT scanned." >&2
+ exit 0
+fi
+
+ZERO='0000000000000000000000000000000000000000'
+STATUS=0
+
+while read -r local_ref local_sha remote_ref remote_sha; do
+ [[ -n "${local_sha:-}" ]] || continue
+ # A branch deletion pushes nothing new.
+ [[ "$local_sha" == "$ZERO" ]] && continue
+
+ if [[ "${remote_sha:-$ZERO}" == "$ZERO" ]]; then
+ # New branch: everything not already on some remote. `--not --remotes`
+ # rather than a guessed base, so a fork or a stacked branch does not make
+ # this scan the entire history.
+ range="$local_sha --not --remotes"
+ else
+ range="$remote_sha..$local_sha"
+ fi
+
+ # QUOTED. $range can be a multi-word rev-list spec ("<sha> --not --remotes"),
+ # and unquoted it splits into separate argv entries, where everything after
+ # the first word reaches the option parser as an unknown flag and the scan
+ # exits on usage instead of scanning. The splitting belongs inside the
+ # collector, which does it deliberately; the call site must not pre-empt it.
+ "$SCAN" --commit-range "$range" || STATUS=1
+
+ branch="${local_ref#refs/heads/}"
+ [[ "$branch" != "$local_ref" ]] && { "$SCAN" --branch "$branch" || STATUS=1; }
+done
+
+exit "$STATUS"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9cc9df2f..0810e633 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -89,6 +89,53 @@ jobs:
- name: PII / personal-data scan
run: bash claude-ops/tests/test-no-secrets.sh
+ # The companion to `pii-gate`, for everything that is NOT a file.
+ #
+ # `pii-gate` scans tracked file content. On 2026-09-16 a personal name reached
+ # a public commit message AND a public pull-request body, and `pii-gate`
+ # passed every time, because neither of those is a file. This job closes that:
+ # commit messages in the PR range, the PR title and body, the head branch
+ # name, and the plugin manifests' owner/author fields.
+ #
+ # No `needs:`, for the same reason `pii-gate` has none — it must run on every
+ # PR regardless of the optimizer's verdict.
+ #
+ # FORK-SAFE BY CONSTRUCTION: it reads the `pull_request` event payload and the
+ # git history that checkout already fetched. No gh api call, no secret, so it
+ # behaves identically on a fork PR, where secrets are unavailable.
+ pii-gate-metadata:
+ name: pii-gate-metadata
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ # The PR range needs both endpoints, so the shallow default will not
+ # do. `fetch-depth: 0` is the honest way to say "we need history".
+ fetch-depth: 0
+ - name: Commit messages in the PR range
+ if: github.event_name == 'pull_request'
+ run: |
+ bash claude-ops/bin/ops-pii-scan \
+ --commit-range "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
+ - name: PR title and body
+ if: github.event_name == 'pull_request'
+ # Passed through env, never interpolated into the shell: a PR title is
+ # attacker-controlled text and `${{ }}` inside `run:` is a command
+ # injection, not a variable.
+ env:
+ PR_TITLE: ${{ github.event.pull_request.title }}
+ PR_BODY: ${{ github.event.pull_request.body }}
+ run: |
+ printf '%s\n%s\n' "$PR_TITLE" "$PR_BODY" > /tmp/pr-text.txt
+ bash claude-ops/bin/ops-pii-scan --origin "PR title/body" --text-file /tmp/pr-text.txt
+ - name: Head branch name
+ if: github.event_name == 'pull_request'
+ env:
+ HEAD_REF: ${{ github.event.pull_request.head.ref }}
+ run: bash claude-ops/bin/ops-pii-scan --branch "$HEAD_REF"
+ - name: Plugin and marketplace manifests
+ run: bash claude-ops/bin/ops-pii-scan --manifests
+
test-suite:
if: always() && needs.lint-and-check.result == 'success' && (github.event_name != 'pull_request' || needs.optimize-ci.outputs.skip == 'false')
runs-on: ${{ matrix.os }}
diff --git a/.github/workflows/pii-surfaces-audit.yml b/.github/workflows/pii-surfaces-audit.yml
new file mode 100644
index 00000000..5e61ef1e
--- /dev/null
+++ b/.github/workflows/pii-surfaces-audit.yml
@@ -0,0 +1,95 @@
+name: PII surfaces audit
+
+# WHY THIS IS SCHEDULED AND NOT A PR CHECK
+#
+# `pii-gate` covers tracked files and `pii-gate-metadata` covers a pull
+# request's own commits, title, body and branch. Neither can see a surface that
+# changes OUTSIDE a pull request — and four of them do:
+#
+# the wiki `ops-release` pushes to it on every release
+# releases generated by `ops-release`, never reviewed in a PR
+# issue comments written by bots and humans, never reviewed at all
+# PR comments the weakest surface; bots paste diffs into them
+#
+# A PR-triggered job would report clean forever while any of these drifted. So
+# this runs daily and fails loudly, with the findings in the job summary.
+
+on:
+ schedule:
+ # 06:20 UTC. Deliberately not on the hour: a scheduled run competing with
+ # the top-of-hour rush is the one that silently gets dropped.
+ - cron: "20 6 * * *"
+ workflow_dispatch:
+
+permissions:
+ contents: read
+ issues: read
+ pull-requests: read
+
+concurrency:
+ group: pii-surfaces-audit
+ cancel-in-progress: false
+
+jobs:
+ audit:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+
+ - name: Clone the wiki
+ # The wiki is a separate git repository with its own history. A missing
+ # wiki must not fail the job, but it must be visible in the log — a
+ # silently skipped surface is how this class of bug started.
+ run: |
+ if git clone --depth 1 "https://github.com/${{ github.repository }}.wiki.git" /tmp/wiki 2>/dev/null; then
+ echo "wiki pages: $(find /tmp/wiki -maxdepth 2 -name '*.md' | wc -l)"
+ else
+ echo "NOTE: no wiki clone available — the wiki was NOT scanned."
+ fi
+
+ - name: Scan wiki
+ if: always()
+ run: |
+ if [[ -d /tmp/wiki ]]; then
+ bash claude-ops/bin/ops-pii-scan --wiki-dir /tmp/wiki | tee -a /tmp/audit.txt
+ fi
+
+ - name: Scan manifests
+ if: always()
+ run: bash claude-ops/bin/ops-pii-scan --manifests | tee -a /tmp/audit.txt
+
+ - name: Scan releases, issue comments and PR comments
+ if: always()
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ # `uuid-literal` is demoted on this surface ONLY. A sweep of this repo's
+ # comment history returns 2090 UUID hits against 47 of everything else,
+ # and essentially all 2090 are review bots quoting a diff — the bot is
+ # reporting a leak, not creating one. Leaving it as a blocker would
+ # paint the audit permanently red for a reason nobody can act on, and a
+ # permanently red gate is a muted gate. Every high-signal rule
+ # (personal email, home paths, AWS account id, operator identity) still
+ # fails this job.
+ run: |
+ bash claude-ops/bin/ops-pii-scan \
+ --github "${{ github.repository }}" \
+ --downgrade uuid-literal | tee -a /tmp/audit.txt
+
+ - name: Summarise
+ if: always()
+ run: |
+ {
+ echo '## PII surfaces audit'
+ echo ''
+ echo '```'
+ cat /tmp/audit.txt 2>/dev/null || echo 'no output'
+ echo '```'
+ } >> "$GITHUB_STEP_SUMMARY"
+ # `| tee` makes each scan step exit 0 whatever the scanner returned,
+ # so THIS is the check that fails the job. It is not a belt-and-braces
+ # re-assertion; without it the audit would print BLOCKED and go green,
+ # which is the exact shape of the bug this whole gate exists for.
+ if grep -q 'BLOCKED' /tmp/audit.txt 2>/dev/null; then
+ echo "PII found on a GitHub surface outside the code tree."
+ exit 1
+ fi
diff --git a/claude-ops/bin/ops-install-git-hooks b/claude-ops/bin/ops-install-git-hooks
index 6c61d5b3..641f59f1 100755
--- a/claude-ops/bin/ops-install-git-hooks
+++ b/claude-ops/bin/ops-install-git-hooks
@@ -1,10 +1,16 @@
#!/usr/bin/env bash
-# Wire this repo's .githooks/ into git so the pre-commit PII gate actually runs.
+# Wire this repo's .githooks/ into git so the PII gates actually run.
#
-# Without this, .githooks/pre-commit is dead code: git only runs hooks from
+# Without this, .githooks/* is dead code: git only runs hooks from
# core.hooksPath (or .git/hooks), and nothing set either. The hook was present,
# executable, and never invoked — a gate that exists but does not gate.
#
+# Three hooks, three surfaces:
+# pre-commit the staged diff (file content)
+# commit-msg the commit message (added 2026-09-16; a name went public
+# in one of these while pii-gate passed)
+# pre-push every commit message in the pushed range, plus the branch name
+#
# Safe to run repeatedly. Works from the primary checkout or any worktree.
set -euo pipefail
diff --git a/claude-ops/bin/ops-pii-scan b/claude-ops/bin/ops-pii-scan
new file mode 100755
index 00000000..3279a68a
--- /dev/null
+++ b/claude-ops/bin/ops-pii-scan
@@ -0,0 +1,253 @@
+#!/usr/bin/env bash
+# ops-pii-scan — one PII gate for every surface that is NOT a tracked file.
+#
+# `pii-gate` (tests/test-no-secrets.sh) scans file CONTENT. That left commit
+# messages, branch names, PR titles and bodies, release notes, issue and PR
+# comments, and the repo wiki completely ungated — and a personal name reached
+# a public commit message and a public PR body while the gate reported success.
+#
+# Every mode below reads the same rules from tests/lib/pii-patterns.sh, so the
+# local hooks and CI cannot disagree about what is forbidden.
+#
+# Exit: 0 clean (warnings may have printed), 1 a BLOCK rule matched, 2 usage.
+set -uo pipefail
+
+SELF_DIR="$(cd "$(dirname "$0")" && pwd -P)"
+PLUGIN_ROOT="$(cd "$SELF_DIR/.." && pwd -P)"
+# shellcheck source=../tests/lib/pii-patterns.sh
+. "$PLUGIN_ROOT/tests/lib/pii-patterns.sh"
+
+REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PLUGIN_ROOT/..")"
+CONSTANTS="$PLUGIN_ROOT/tests/known-public-constants.txt"
+OVERRIDE_LOG="${OPS_PII_GATE_LOG:-${XDG_STATE_HOME:-$HOME/.local/state}/claude-ops/pii-gate-overrides.log}"
+
+RED=$'\033[0;31m'; YELLOW=$'\033[0;33m'; GREEN=$'\033[0;32m'; NC=$'\033[0m'
+[[ -t 1 ]] || { RED=""; YELLOW=""; GREEN=""; NC=""; }
+
+usage() {
+ cat <<'EOF'
+ops-pii-scan — PII gate for commit messages, branch names, PR/issue text,
+releases, the wiki, and the plugin manifests.
+
+ --staged added lines in the staged diff
+ --commit-msg-file FILE one commit message (the commit-msg hook)
+ --commit-range A..B every commit message in a range
+ --branch NAME a branch name
+ --text-file FILE arbitrary text; pair with --origin
+ --origin LABEL what to call the text in the report (default: text)
+ --manifests .claude-plugin/marketplace.json + plugin.json
+ --wiki-dir DIR a checked-out repo wiki
+ --github REPO releases + issue comments + PR comments via gh api
+ --digest TERM print the salted digest of TERM and exit
+
+ --warn-only never exit 1 (for the scheduled audit's own report)
+ --downgrade A,B report these rules as WARN instead of BLOCK. Only
+ for the comment surfaces, where review bots quote
+ diffs; see the note above apply_downgrade.
+
+Override a genuine false positive by setting a REASON, which is logged:
+ OPS_PII_GATE_OVERRIDE="npm scope, not a person" git commit ...
+EOF
+}
+
+# ---- reporting ---------------------------------------------------------------
+BLOCKS=0
+WARNS=0
+WARN_ONLY=0
+
+# Filter out UUID findings whose value is a documented public vendor constant.
+# The rule file cannot do this: it does not know where the checkout is.
+drop_documented_uuids() {
+ if [[ ! -f "$CONSTANTS" ]]; then cat; return; fi
+ local allow
+ allow="$(grep -E '^uuid:' "$CONSTANTS" 2>/dev/null | sed 's/^uuid://' | grep -v '^$' || true)"
+ if [[ -z "$allow" ]]; then cat; return; fi
+ awk -F'\t' -v OFS='\t' 'NR==FNR { ok[tolower($0)]=1; next }
+ $2=="uuid-literal" && ok[tolower($3)] { next }
+ { print }' <(printf '%s\n' "$allow") -
+}
+
+# Downgrade named rules from BLOCK to WARN.
+#
+# This exists for ONE surface: issue and PR comments. A scan of this repo's
+# comment history returns 2090 `uuid-literal` hits and 47 of everything else.
+# The 2090 are review bots quoting a diff that legitimately contained a UUID —
+# the bot is reporting the leak, not committing one. A gate that is red for a
+# reason nobody can act on gets muted, and then the 47 findings that ARE real
+# go unseen with it. So the noisy rule is demoted on that surface only, and the
+# high-signal rules (personal email, home path, AWS account id, operator
+# identity) still fail the job.
+#
+# Never used on the PR path. There, a UUID in a commit message is exactly the
+# thing being gated.
+DOWNGRADE=""
+apply_downgrade() {
+ [[ -n "$DOWNGRADE" ]] || { cat; return; }
+ awk -F'\t' -v OFS='\t' -v list="$DOWNGRADE" '
+ BEGIN { n = split(list, a, ","); for (i = 1; i <= n; i++) down[a[i]] = 1 }
+ $1 == "BLOCK" && ($2 in down) { $1 = "WARN" }
+ { print }'
+}
+
+report() {
+ local sev label term origin text
+ while IFS=$'\t' read -r sev label term origin text; do
+ [[ -n "$sev" ]] || continue
+ if [[ "$sev" == BLOCK ]]; then
+ printf '%sBLOCKED%s [%s] %s\n' "$RED" "$NC" "$label" "$term"
+ else
+ printf '%swarn%s [%s] %s\n' "$YELLOW" "$NC" "$label" "$term"
+ fi
+ printf ' in %s\n' "$origin"
+ printf ' %s\n' "$(printf '%s' "$text" | cut -c1-160)"
+ done
+}
+
+# ---- collectors --------------------------------------------------------------
+# Each prints "<origin>\t<text>" lines. One line per source line, always, so a
+# report can name the line and not just the blob.
+
+collect_staged() {
+ # Only ADDED lines, and never the four files whose job is to quote the shapes
+ # they forbid — the same exemption the pre-commit hook already uses, by exact
+ # path rather than by directory.
+ local exempt='^claude-ops/tests/(test-no-secrets\.sh|known-public-constants\.txt|test-pii-gate-fires\.sh|test-pre-commit-hook-blocks\.sh|pii-term-digests\.txt)$'
+ local f
+ while IFS= read -r f; do
+ [[ -n "$f" ]] || continue
+ [[ "$f" =~ $exempt ]] && continue
+ git diff --cached -U0 -- "$f" 2>/dev/null \
+ | grep '^+' | grep -v '^+++' \
+ | sed "s|^+|$f\t|"
+ done < <(git diff --cached --name-only 2>/dev/null)
+}
+
+collect_commit_msg_file() {
+ # Comment lines are stripped by git before the message is stored, so they
+ # cannot leak — scanning them would block on the diff git itself pastes in
+ # under `commit --verbose`.
+ grep -v '^#' "$1" 2>/dev/null | sed "s|^|commit message\t|"
+}
+
+collect_commit_range() {
+ local sha
+ # $1 is a rev-list SPEC, not a single ref: pre-push passes
+ # "<sha> --not --remotes" for a brand-new branch. Splitting is the point.
+ # shellcheck disable=SC2086
+ while IFS= read -r sha; do
+ [[ -n "$sha" ]] || continue
+ git log -1 --format='%B%n%an%n%ae' "$sha" 2>/dev/null \
+ | sed "s|^|commit ${sha:0:12}\t|"
+ done < <(git rev-list $1 2>/dev/null)
+}
+
+collect_manifests() {
+ # Manifests carry owner/author name and email. The company identity is the
+ # intended public value and is allowlisted in pii-patterns.sh; a PERSONAL
+ # name or address in those fields is what this catches.
+ local m
+ for m in "$REPO_ROOT/.claude-plugin/marketplace.json" \
+ "$REPO_ROOT/claude-ops/.claude-plugin/plugin.json"; do
+ [[ -f "$m" ]] || continue
+ grep -nE '"(name|author|owner|email|url|homepage|repository)"' "$m" 2>/dev/null \
+ | sed "s|^|${m#"$REPO_ROOT"/}:|" \
+ | sed 's|^\([^:]*:[0-9]*\):|\1\t|'
+ done
+}
+
+collect_wiki_dir() {
+ local d="$1" f
+ [[ -d "$d" ]] || { echo "no wiki checkout at $d" >&2; return 0; }
+ while IFS= read -r f; do
+ grep -nIE '.' "$f" 2>/dev/null | sed "s|^|wiki/$(basename "$f"):|" \
+ | sed 's|^\([^:]*:[0-9]*\):|\1\t|'
+ done < <(find "$d" -maxdepth 2 -type f \( -name '*.md' -o -name '*.markdown' \) -not -path '*/.git/*' 2>/dev/null)
+}
+
+collect_github() {
+ local repo="$1"
+ command -v gh >/dev/null 2>&1 || { echo "gh not available" >&2; return 0; }
+ # Releases: ops-release writes these on every release, outside any PR.
+ # Newlines are squashed inside each record on purpose: the scan contract is
+ # one "<origin>\tTEXT" per line, and a release body with a blank line in it
+ # would otherwise arrive as untagged text with no origin attached.
+ gh api --paginate "repos/$repo/releases" \
+ --jq '.[] | "release \(.tag_name)\t\((.name // "") + " " + (.body // "") | gsub("[\r\n]+";" "))"' 2>/dev/null
+ # Issue and PR-review comments: the weakest surface, because bots quote diffs
+ # into them and nothing has ever scanned them.
+ gh api --paginate "repos/$repo/issues/comments?per_page=100" \
+ --jq '.[] | "issue comment \(.id)\t\(.body // "" | gsub("[\r\n]+";" "))"' 2>/dev/null
+ gh api --paginate "repos/$repo/pulls/comments?per_page=100" \
+ --jq '.[] | "pr comment \(.id)\t\(.body // "" | gsub("[\r\n]+";" "))"' 2>/dev/null
+}
+
+# ---- argument handling -------------------------------------------------------
+ORIGIN="text"
+MODES=0
+run_mode() { MODES=$((MODES + 1)); }
+
+collected="$(mktemp -t ops-pii-scan.XXXXXX)"
+findings="$(mktemp -t ops-pii-find.XXXXXX)"
+trap 'rm -f "$collected" "$findings"' EXIT
+: > "$collected"
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --staged) run_mode; collect_staged >> "$collected" ;;
+ --commit-msg-file) run_mode; collect_commit_msg_file "$2" >> "$collected"; shift ;;
+ --commit-range) run_mode; collect_commit_range "$2" >> "$collected"; shift ;;
+ --branch) run_mode; printf 'branch name\t%s\n' "$2" >> "$collected"; shift ;;
+ --text-file) run_mode; sed "s|^|$ORIGIN\t|" "$2" >> "$collected"; shift ;;
+ --origin) ORIGIN="$2"; shift ;;
+ --manifests) run_mode; collect_manifests >> "$collected" ;;
+ --wiki-dir) run_mode; collect_wiki_dir "$2" >> "$collected"; shift ;;
+ --github) run_mode; collect_github "$2" >> "$collected"; shift ;;
+ --warn-only) WARN_ONLY=1 ;;
+ --downgrade) DOWNGRADE="$2"; shift ;;
+ --digest) pii_digest_of "$2"; exit 0 ;;
+ -h|--help) usage; exit 0 ;;
+ *) echo "unknown option: $1" >&2; usage >&2; exit 2 ;;
+ esac
+ shift
+done
+
+if [[ "$MODES" -eq 0 ]]; then usage >&2; exit 2; fi
+
+if [[ ! -s "$collected" ]]; then
+ echo "${GREEN}PII metadata scan: nothing to scan${NC}"
+ exit 0
+fi
+
+# The scan runs OUTSIDE the reporting pipeline on purpose. A counter
+# incremented in the last stage of a pipe lives in a subshell and is gone by
+# the time the exit code is decided — a gate that prints BLOCKED and then
+# exits 0 is the precise failure this whole file exists to prevent.
+pii_scan < "$collected" | drop_documented_uuids | apply_downgrade > "$findings"
+report < "$findings"
+BLOCKS=$(awk -F'\t' '$1 == "BLOCK"' "$findings" | grep -c . || true)
+WARNS=$(awk -F'\t' '$1 == "WARN"' "$findings" | grep -c . || true)
+
+echo ""
+echo "PII metadata scan: $BLOCKS blocked, $WARNS warning(s)"
+
+if [[ "$BLOCKS" -eq 0 || "$WARN_ONLY" -eq 1 ]]; then
+ exit 0
+fi
+
+# An override is a real need — an npm scope that happens to read like a name,
+# a vendor id that genuinely is public. It has to be deliberate and it has to
+# leave a trace, otherwise it is just --no-verify with extra steps.
+if [[ -n "${OPS_PII_GATE_OVERRIDE:-}" ]]; then
+ mkdir -p "$(dirname "$OVERRIDE_LOG")" 2>/dev/null || true
+ printf '%s\t%s\t%s\tblocks=%s\treason=%s\n' \
+ "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "${USER:-unknown}" "$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '-')" \
+ "$BLOCKS" "$OPS_PII_GATE_OVERRIDE" >> "$OVERRIDE_LOG" 2>/dev/null || true
+ echo "${YELLOW}OVERRIDDEN${NC} by OPS_PII_GATE_OVERRIDE — logged to $OVERRIDE_LOG"
+ exit 0
+fi
+
+echo ""
+echo "${RED}This is a PUBLIC repo. Remove the value above, or rewrite it as a placeholder.${NC}"
+echo "Genuine false positive? Re-run with a reason, which is logged:"
+echo " OPS_PII_GATE_OVERRIDE='why this is not personal data' <your command>"
+exit 1
diff --git a/claude-ops/tests/lib/pii-digest.py b/claude-ops/tests/lib/pii-digest.py
new file mode 100755
index 00000000..fc0cdd7f
--- /dev/null
+++ b/claude-ops/tests/lib/pii-digest.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python3
+"""Match text against HASHED operator-identity terms.
+
+WHY THE TERMS ARE HASHED
+
+A public repo cannot carry the operator's own name, handles, account id or
+phone number in cleartext: the denylist would itself be the leak. That is why
+`test-no-secrets.sh` loads identity terms from an out-of-repo file.
+
+But an out-of-repo file is not present in CI, so that check SKIPs there — and a
+check that skips is the reason a personal name reached a public commit message
+and a public PR body while `pii-gate` reported success the whole time.
+
+So the same terms also live in the repo as SALTED SHA-256 DIGESTS. CI can then
+refuse a term without ever publishing it. This is obscurity, not secrecy: a
+12-digit account id has little entropy and a determined reader with a wordlist
+can recover it. That is the right trade anyway — the job is to keep this data
+off a public, search-indexed surface, not to keep it cryptographically secret
+from someone who already holds it.
+
+The cleartext denylist still wins where it exists (a developer machine): it
+catches substrings and new terms the digest file has never seen.
+
+USAGE
+ pii-digest.py <digest-file> <salt> < text
+
+Reads text on stdin, prints one "<token>\t<line>" per hit — the token that
+matched, and the whole line it sat on, so a caller can name both.
+"""
+
+import hashlib
+import re
+import sys
+
+# A token is an identifier-ish run. The separators stay INSIDE the class so a
+# whole address ("[email protected]") hashes as one token; the
+# split pass below then also hashes its parts, so a brand term embedded in a
+# domain is caught without hashing every English word around it.
+TOKEN_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.+@-]*")
+SPLIT_RE = re.compile(r"[._+@-]+")
+ALPHA_RE = re.compile(r"^[A-Za-z]+$")
+
+
+def load_digests(path):
+ """One digest per line; '#' comments and blanks ignored."""
+ out = set()
+ try:
+ with open(path, "r", encoding="utf-8") as fh:
+ for raw in fh:
+ line = raw.split("#", 1)[0].strip().lower()
+ if line:
+ out.add(line)
+ except OSError:
+ pass
+ return out
+
+
+def candidates(line):
+ """Every hashable form of one line, lowercased.
+
+ Three forms, because a term hides in three shapes: as a whole token
+ ("someusername"), as a piece of a longer one ("brand" inside
+ "brand.example"), and as two words with a space between them, which is how
+ a person's name is written in a commit message.
+ """
+ toks = [t.strip(".-_+") for t in TOKEN_RE.findall(line)]
+ toks = [t for t in toks if t]
+ seen = []
+ for tok in toks:
+ seen.append(tok.lower())
+ for part in SPLIT_RE.split(tok):
+ if len(part) > 2:
+ seen.append(part.lower())
+ words = [t for t in toks if ALPHA_RE.match(t)]
+ for i in range(len(words) - 1):
+ seen.append((words[i] + " " + words[i + 1]).lower())
+ return seen
+
+
+def main():
+ if len(sys.argv) != 3:
+ sys.stderr.write("usage: pii-digest.py <digest-file> <salt>\n")
+ return 2
+ digests = load_digests(sys.argv[1])
+ if not digests:
+ # No digest file is not "clean": say nothing and let the caller decide.
+ return 0
+ salt = sys.argv[2].encode("utf-8")
+
+ hits = 0
+ for raw in sys.stdin:
+ line = raw.rstrip("\n")
+ if not line.strip():
+ continue
+ reported = set()
+ for cand in candidates(line):
+ if cand in reported:
+ continue
+ digest = hashlib.sha256(salt + cand.encode("utf-8")).hexdigest()
+ if digest in digests:
+ reported.add(cand)
+ hits += 1
+ # The token is printed back so the human sees WHICH term fired.
+ # It is their own data and they are the only reader; the point
+ # of the hash is the repo, not the terminal.
+ sys.stdout.write("%s\t%s\n" % (cand, line))
+ return 0 if hits == 0 else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/claude-ops/tests/lib/pii-patterns.sh b/claude-ops/tests/lib/pii-patterns.sh
new file mode 100644
index 00000000..7aa45139
--- /dev/null
+++ b/claude-ops/tests/lib/pii-patterns.sh
@@ -0,0 +1,315 @@
+#!/usr/bin/env bash
+# pii-patterns.sh — THE pattern source for every PII surface in this repo.
+#
+# WHY THIS FILE EXISTS
+#
+# `pii-gate` scanned FILES. On 2026-09-16 a personal name reached a public
+# commit message and a public pull-request body, and the gate passed the whole
+# time, because neither of those is a file. A later sweep found a personal
+# email, a phone number, an AWS account id and a cloud budget UUID quoted
+# verbatim in old PR descriptions — same root cause.
+#
+# The fix is not another scanner. It is ONE pattern list that the local hooks,
+# the CI job and the tests all read, so the surfaces can never drift apart.
+# Before this, the pre-commit hook and `test-no-secrets.sh` each carried their
+# own copy of the patterns, and they had already diverged.
+#
+# WHAT IS AND IS NOT IN HERE
+#
+# Shapes only. Not one real personal value appears in this file, or in any file
+# this gate ships. The operator's actual names, handles, account ids and phone
+# numbers reach the gate two other ways:
+# - cleartext, from an out-of-repo denylist (developer machines), and
+# - salted SHA-256 digests in pii-term-digests.txt (works in CI).
+# See pii-digest.py for why both exist.
+#
+# TWO SEVERITIES
+#
+# BLOCK high confidence; refuses the commit, the push, or the PR.
+# WARN shapes with a real false-positive rate that also have legitimate
+# fixtures in this tree (documented CGNAT examples, an all-zero EC2
+# id, reserved phone ranges, WhatsApp JID fixtures). Printed, never
+# fatal. Promoting one of these to BLOCK means first proving the
+# current tree still passes — `test-pii-metadata-gate.sh` asserts it.
+#
+# RULE FORMAT — five TAB-separated fields:
+# <label> <regex> <allow-regex or -> <flags or -> <description>
+# flags: 'i' case-insensitive. Use '-' for none, NEVER an empty field: see the
+# note above the reader loop for what an empty field silently did.
+
+# shellcheck shell=bash
+
+PII_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
+PII_DIGEST_FILE="${OPS_PII_DIGEST_FILE:-$PII_LIB_DIR/../pii-term-digests.txt}"
+# A second, WARN-severity digest set. A GitHub handle belongs here: every commit
+# is authored under it, every diff quote repeats it, and bot comments paste it
+# inside code snippets. Blocking it would fail the audit on its own evidence.
+PII_DIGEST_WARN_FILE="${OPS_PII_DIGEST_WARN_FILE:-$PII_LIB_DIR/../pii-term-digests-warn.txt}"
+PII_DIGEST_HELPER="$PII_LIB_DIR/pii-digest.py"
+# A tracked salt is public by definition, so it buys nothing against a targeted
+# attacker. It only stops a generic rainbow table, which is all it is for.
+PII_DIGEST_SALT="${OPS_PII_DIGEST_SALT:-claude-ops-pii-v1}"
+
+# Documented placeholders. A gate that fails on `[email protected]` teaches
+# people to pass --no-verify, which costs more than it saves.
+PII_PLACEHOLDER_RE='(your\.address@|your-address@|\byou@|user@example|work@example|noreply@|no-reply@|example\.(com|org|net)|@(example|test|localhost|anthropic)\.)'
+
+# The intended PUBLIC identity of this project. It belongs in
+# .claude-plugin/marketplace.json and in plugin.json, and flagging it would
+# make the manifest scan fail on the manifests' whole reason for existing.
+# Written as regexes, never as plain literals, so this file does not itself
+# trip the work-email check in the pre-commit hook.
+PII_COMPANY_RE='(Lifecycle[[:space:]]+Innovations[[:space:]]+Limited|info@lifecycleinnovations\.limited|lifecycleinnovations\.limited)'
+
+# A GitHub handle is public by construction: every commit is authored under it
+# and every diff quote repeats it. Blocking it would fail on legitimate bot
+# comments that quote a diff. So a term that fires INSIDE one of these contexts
+# is reported as WARN rather than BLOCK.
+PII_HANDLE_CONTEXT_RE='(github\.com/|users\.noreply\.github\.com|githubusercontent\.com/|[Cc]o-[Aa]uthored-[Bb]y|Signed-off-by|[Aa]uthor:|/pull/|/issues/)'
+
+# --- BLOCK rules --------------------------------------------------------------
+pii_block_rules() {
+ # Personal webmail. The brand domains the owner actually uses are NOT listed
+ # here (they would be the leak); they arrive via the denylist/digest path.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'personal-email' \
+ '[A-Za-z0-9._%+-]+@(gmail|yahoo|hotmail|outlook|icloud|proton|protonmail|hey|me|mac)\.[a-z]{2,}' \
+ "$PII_PLACEHOLDER_RE" \
+ '-' \
+ 'a personal mailbox; use an example address'
+
+ # A macOS home path names its owner. `~` and `$HOME` are fine, and so is a
+ # generic username — the coordinator's wiki sweep showed the only "home path"
+ # in the docs is `~/.hermes/...`, which carries no username at all.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'macos-home-path' \
+ '/Users/[a-z][A-Za-z0-9_.-]+' \
+ '/Users/(user|username|users|you|your[-_]?user|runner|shared|example|admin|me|name|alice|bob|carol|jane|john|jdoe)([^A-Za-z0-9_.-]|$)|/Users/[<$\{]' \
+ '-' \
+ 'a macOS home path names its owner; use ~ or $HOME'
+
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'linux-home-path' \
+ '/home/[a-z][A-Za-z0-9_.-]+/' \
+ '/home/(user|username|users|you|your[-_]?user|runner|ubuntu|ec2-user|ops|node|app|shared|example)/|/home/[<$\{]' \
+ '-' \
+ 'a Linux home path names its owner; use ~ or $HOME'
+
+ # Kept in ARN/account/bucket context so this does not flag every 12-digit
+ # number. Reserved docs placeholders stay allowed.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'aws-account-id' \
+ '([Aa]ccount|[Bb]ucket|aws|AWS|arn)[^0-9]{0,40}[0-9]{12}([^0-9]|$)' \
+ '(123456789012|000000000000|111111111111|[0-9]{13,})' \
+ '-' \
+ 'a real AWS account id; read it from the environment'
+
+ # Any UUID is either a published vendor constant or somebody'"'"'s private
+ # identifier, and the two are the same shape. Default to refusing it; the
+ # documented ones live in known-public-constants.txt and are filtered by the
+ # caller, which is the only place that knows where the checkout is.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'uuid-literal' \
+ '\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b' \
+ '\b(0{8}-0{4}|1{8}-1{4})-' \
+ '-' \
+ 'an undocumented UUID; document it in tests/known-public-constants.txt'
+}
+
+# --- WARN rules ---------------------------------------------------------------
+# Every one of these has a legitimate fixture in the current tree. They are
+# printed so a human can look, and they never fail a build.
+pii_warn_rules() {
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'phone-shaped' \
+ '\+[0-9]{10,15}' \
+ '(\+1234567890|\+15551234567|\+14155550100|\+14155551234|\+31612345678|\+10000000000|\+0{10,})' \
+ '-' \
+ 'looks like an international phone number'
+
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'whatsapp-jid' \
+ '[0-9]{6,15}@(s\.whatsapp\.net|lid)\b' \
+ '-' \
+ '-' \
+ 'looks like a WhatsApp JID'
+
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'iban-shaped' \
+ '\b[A-Z]{2}[0-9]{2}[A-Z0-9]{10,30}\b' \
+ '-' \
+ '-' \
+ 'looks like an IBAN'
+
+ # 10.88.x is this estate'"'"'s WireGuard range and 100.64/10 is CGNAT; both are
+ # documented in the setup guide as examples and must stay.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'private-address' \
+ '\b(10\.88\.[0-9]{1,3}\.[0-9]{1,3}|100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3})\b' \
+ '-' \
+ '-' \
+ 'a private or CGNAT address; fine as a documented example'
+
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'ec2-instance-id' \
+ '\bi-[0-9a-f]{17}\b' \
+ '\bi-0{17}\b' \
+ '-' \
+ 'looks like an EC2 instance id'
+
+ # Not PII on its own, but it says which machine layout the operator runs.
+ printf '%s\t%s\t%s\t%s\t%s\n' \
+ 'hermes-primary-path' \
+ '/home/[a-z]+/\.hermes-primary' \
+ '-' \
+ '-' \
+ 'names a specific host layout; ~/.hermes on its own is a documented install path'
+}
+
+# --- Operator identity, cleartext (developer machines) ------------------------
+# Same sources the existing scanner and hook already use, so an operator
+# configures this once.
+pii_operator_terms() {
+ local cand file="" terms="" root
+ root="${PII_REPO_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || true)}"
+ for cand in "${OPS_PII_DENYLIST_FILE:-}" "$root/.pii-denylist" \
+ "$root/claude-ops/.pii-denylist" \
+ "$HOME/.config/claude-ops/pii-denylist.txt"; do
+ [[ -n "$cand" && -f "$cand" ]] && { file="$cand"; break; }
+ done
+ [[ -n "$file" ]] && terms="$(grep -vE '^[[:space:]]*(#|$)' "$file" 2>/dev/null || true)"
+ if [[ -n "${OPS_PII_DENYLIST:-}" ]]; then
+ terms="$terms"$'\n'"$(printf '%s' "$OPS_PII_DENYLIST" | tr ',[:space:]' '\n\n')"
+ fi
+ printf '%s\n' "$terms" | grep -vE '^[[:space:]]*$' | sort -u || true
+}
+
+# Emit findings for one rule.
+#
+# The obvious shape — loop over the matching lines and shell out to `grep -oE`
+# for each one to recover the matched term — costs a process PER FINDING. On a
+# 29-page wiki that is thousands of forks and the scan never finishes, which
+# means in practice the gate gets removed. So: ONE `grep -noE` recovers every
+# term at once, keyed by line number, and one `awk` joins it back. Two
+# processes per rule, regardless of how much text or how many hits.
+pii_emit() {
+ local sev="$1" label="$2" regex="$3" hits_file="$4"
+ local terms_file
+ terms_file="$(mktemp -t ops-pii-terms.XXXXXX)"
+ grep -noE "$regex" "$hits_file" 2>/dev/null \
+ | sed 's/^\([0-9]*\):/\1\t/' \
+ | awk -F'\t' '!seen[$1]++' > "$terms_file" || true
+ awk -F'\t' -v sev="$sev" -v label="$label" -v OFS='\t' '
+ NR == FNR { term[$1] = $2; next }
+ {
+ origin = $1
+ text = $0
+ sub(/^[^\t]*\t/, "", text)
+ # A hit with no extractable term means grep -E and grep -oE disagreed,
+ # which is an anomaly worth seeing — so it is reported, but never dressed
+ # up as if a term had been recovered.
+ print sev, label, (FNR in term ? term[FNR] : "<no term extracted>"), origin, text
+ }' "$terms_file" "$hits_file"
+ rm -f "$terms_file"
+}
+
+# --- The scan -----------------------------------------------------------------
+# stdin: one "<origin>\t<text>" per line.
+# stdout: one "<severity>\t<label>\t<term>\t<origin>\t<text>" per finding.
+#
+# Nothing here decides an exit code. The caller does, because "block" means a
+# different thing to a commit-msg hook than to a scheduled audit.
+pii_scan() {
+ local label regex allow flags desc sev
+ local input_file hits_file
+ input_file="$(mktemp -t ops-pii-input.XXXXXX)"
+ hits_file="$(mktemp -t ops-pii-hits.XXXXXX)"
+ cat > "$input_file"
+ if [[ ! -s "$input_file" ]]; then
+ rm -f "$input_file" "$hits_file"
+ return 0
+ fi
+
+ local rules
+ rules="$( { pii_block_rules | sed 's/^/BLOCK\t/'; pii_warn_rules | sed 's/^/WARN\t/'; } )"
+
+ # EVERY field carries a '-' placeholder when empty, and that is load-bearing.
+ # TAB is IFS *whitespace*, so `read` collapses two consecutive tabs into one
+ # delimiter: an empty `flags` field silently shifted the DESCRIPTION into
+ # $flags, and every description containing the letter "i" turned its rule
+ # case-insensitive. That is not theoretical — it made `/Users/` match
+ # `/v2/users/me` and report a Zoom API doc line as a leaked home path. A
+ # false positive here is how a gate gets switched off.
+ while IFS=$'\t' read -r sev label regex allow flags desc; do
+ [[ -n "$label" ]] || continue
+ [[ "$flags" == "-" ]] && flags=""
+ if [[ "$flags" == *i* ]]; then
+ grep -iE "$regex" "$input_file" > "$hits_file" 2>/dev/null || true
+ else
+ grep -E "$regex" "$input_file" > "$hits_file" 2>/dev/null || true
+ fi
+ if [[ -n "$allow" && "$allow" != "-" && -s "$hits_file" ]]; then
+ grep -vE "$allow" "$hits_file" > "$hits_file.f" 2>/dev/null || true
+ mv "$hits_file.f" "$hits_file"
+ fi
+ [[ -s "$hits_file" ]] || continue
+ pii_emit "$sev" "$label" "$regex" "$hits_file"
+ done <<< "$rules"
+
+ # --- operator identity, cleartext (developer machines) ---
+ local terms alt
+ terms="$(pii_operator_terms)"
+ if [[ -n "$terms" ]]; then
+ alt="$(printf '%s\n' "$terms" | sed 's/[.[\*^$()+?{|]/\\&/g' | paste -sd '|' -)"
+ # The company identity is the INTENDED public value in marketplace.json and
+ # plugin.json. A developer whose own denylist contains the company name
+ # would otherwise be blocked by the manifests' entire reason for existing.
+ grep -iE "\b($alt)\b" "$input_file" 2>/dev/null \
+ | grep -vE '(example|placeholder|your[-_]|<[A-Z_]+>)' 2>/dev/null \
+ | grep -vE "$PII_COMPANY_RE" > "$hits_file" 2>/dev/null || true
+ if [[ -s "$hits_file" ]]; then
+ # A term sitting in a GitHub-handle context is public by construction —
+ # every commit is authored under it — so it is split out as a WARN rather
+ # than failing every legitimate diff quote.
+ grep -E "$PII_HANDLE_CONTEXT_RE" "$hits_file" > "$hits_file.w" 2>/dev/null || true
+ grep -vE "$PII_HANDLE_CONTEXT_RE" "$hits_file" > "$hits_file.b" 2>/dev/null || true
+ [[ -s "$hits_file.b" ]] && pii_emit BLOCK 'operator-identity' "\b($alt)\b" "$hits_file.b"
+ [[ -s "$hits_file.w" ]] && pii_emit WARN 'operator-identity' "\b($alt)\b" "$hits_file.w"
+ rm -f "$hits_file.w" "$hits_file.b"
+ fi
+ fi
+
+ # --- operator identity, hashed (the path that works in CI) ---
+ local term body origin text
+ if [[ -f "$PII_DIGEST_FILE" ]] && command -v python3 >/dev/null 2>&1; then
+ while IFS=$'\t' read -r term body; do
+ [[ -n "$term" ]] || continue
+ origin="${body%%$'\t'*}"
+ text="${body#*$'\t'}"
+ sev=BLOCK
+ printf '%s\n' "$text" | grep -qE "$PII_HANDLE_CONTEXT_RE" && sev=WARN
+ printf '%s\n' "$text" | grep -qE "$PII_COMPANY_RE" && sev=WARN
+ printf '%s\t%s\t%s\t%s\t%s\n' "$sev" 'operator-identity' "$term" "$origin" "$text"
+ done < <(python3 "$PII_DIGEST_HELPER" "$PII_DIGEST_FILE" "$PII_DIGEST_SALT" \
+ < "$input_file" 2>/dev/null || true)
+ fi
+
+ if [[ -f "$PII_DIGEST_WARN_FILE" ]] && command -v python3 >/dev/null 2>&1; then
+ while IFS=$'\t' read -r term body; do
+ [[ -n "$term" ]] || continue
+ origin="${body%%$'\t'*}"
+ printf '%s\t%s\t%s\t%s\t%s\n' 'WARN' 'public-handle' "$term" "$origin" "${body#*$'\t'}"
+ done < <(python3 "$PII_DIGEST_HELPER" "$PII_DIGEST_WARN_FILE" "$PII_DIGEST_SALT" \
+ < "$input_file" 2>/dev/null || true)
+ fi
+
+ rm -f "$input_file" "$hits_file"
+}
+
+# Print the digest of a term so a maintainer can extend pii-term-digests.txt
+# WITHOUT ever writing the term itself into the repo. That is the whole point:
+# ops-pii-scan --digest 'some term' >> claude-ops/tests/pii-term-digests.txt
+pii_digest_of() {
+ printf '%s' "$PII_DIGEST_SALT$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" \
+ | { shasum -a 256 2>/dev/null || sha256sum; } | awk '{print $1}'
+}
diff --git a/claude-ops/tests/pii-term-digests-warn.txt b/claude-ops/tests/pii-term-digests-warn.txt
new file mode 100644
index 00000000..845f1ead
--- /dev/null
+++ b/claude-ops/tests/pii-term-digests-warn.txt
@@ -0,0 +1,14 @@
+# Salted SHA-256 digests of terms that are REPORTED but never block.
+#
+# A GitHub handle is public by construction: every commit is authored under it,
+# every diff quote repeats it, and the release and comment bots paste it into
+# code snippets. Blocking it would fail this repo's own audit on its own
+# evidence, and a gate that cries wolf gets switched off.
+#
+# It is still worth printing, because a handle beside a home path or an account
+# id is how a set of harmless facts becomes an identification.
+#
+# Same rules as pii-term-digests.txt: add with
+# claude-ops/bin/ops-pii-scan --digest 'the term' >> <this file>
+# and never paste the term itself.
+d87321ceb3357b9fbcf96c5bd84903b1fa2b63913f0f2afc1deaefaa20ab31a6
diff --git a/claude-ops/tests/pii-term-digests.txt b/claude-ops/tests/pii-term-digests.txt
new file mode 100644
index 00000000..1cf669f7
--- /dev/null
+++ b/claude-ops/tests/pii-term-digests.txt
@@ -0,0 +1,36 @@
+# Salted SHA-256 digests of the operator identity terms this PUBLIC repo must
+# never publish: personal names, personal handles, brand domains, an AWS
+# account id, a phone number, a cloud budget UUID.
+#
+# WHY DIGESTS AND NOT THE TERMS
+#
+# A denylist of personal terms in a public repo IS the leak. That is why the
+# cleartext list lives out of the tree (.pii-denylist, $OPS_PII_DENYLIST).
+#
+# But an out-of-tree file does not exist in CI, so the identity check SKIPped
+# there — and a skip is why a personal name reached a public commit message and
+# a public PR body while `pii-gate` reported success run after run. Hashing lets
+# CI refuse a term it is not allowed to know.
+#
+# This is obscurity, not secrecy. A 12-digit account id has little entropy and a
+# reader with a wordlist can recover it. That is an acceptable trade: the goal is
+# to keep this data off a public, search-indexed surface, not to hide it from
+# someone who already has it.
+#
+# ADDING A TERM — never paste the term itself:
+# claude-ops/bin/ops-pii-scan --digest 'the term' >> claude-ops/tests/pii-term-digests.txt
+#
+# Matching is whole-token (and adjacent-word-pair, for "first last" names), so a
+# term cannot fire in the middle of an unrelated identifier.
+a76cb6498f1f22dddf15614708303b875529763273acf390cf155e26424782e0
+8e2205aab2e35fa815c001965e10bf93cdfd6a8e2d1dffc5b16b0d5485d90072
+358dc1d7a1a6183e077d0ba276ac69fcd5e6a54a823300a5bc129b0c853d933e
+cc32a7b8e8a07e6faf6076b64d66ab83865abc5ee06522cbe7257bd947895daf
+b8891e4d3630c86a8e62f77eea092a9cd7f445e453c5f95aa38f7865f61c1d6b
+dee698164eb68b1d92e8d4b7d7652e2f9d6e7fb5bb6afe643b8dc696e9a9e0fa
+f905f7a661da87a4e8f8d715eedf7484d52fecfcb5c4a1eb9596b66266696434
+9edadf174a4e25e3d7224fe35342b108ada2c93eef4f03e2544f64ab654e533d
+a0d1a8730688d430e2b9a134e282c064b09e86b554f5382889667e20f1378e90
+eaea10efea05f4e792a13fb0cddf5197dbf66856d20f1d1a7dcf795acf02f190
+b2e15feb3932a835af042c9809d44f7ab5b6b2c4774abbc6fcf1367a71552af6
+9dddd683e8c5dc182991793a7982edfdd73a0399148c122ba2d1efcb71492277
diff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.sh
index 7f8cb95e..5ea027df 100755
--- a/claude-ops/tests/run-all.sh
+++ b/claude-ops/tests/run-all.sh
@@ -67,6 +67,7 @@ run_suite "$TESTS_DIR/test-crsproxy-reauth.sh"
run_suite "$TESTS_DIR/test-no-secrets.sh"
run_suite "$TESTS_DIR/test-pii-gate-fires.sh"
run_suite "$TESTS_DIR/test-pre-commit-hook-blocks.sh"
+run_suite "$TESTS_DIR/test-pii-metadata-gate.sh"
run_suite "$TESTS_DIR/test-agent-teams.sh"
run_suite "$TESTS_DIR/test-pocket-env-broker.sh"
run_suite "$TESTS_DIR/test-ops-pocket-notify.sh"
diff --git a/claude-ops/tests/test-pii-metadata-gate.sh b/claude-ops/tests/test-pii-metadata-gate.sh
new file mode 100755
index 00000000..abb085c9
--- /dev/null
+++ b/claude-ops/tests/test-pii-metadata-gate.sh
@@ -0,0 +1,271 @@
+#!/usr/bin/env bash
+# test-pii-metadata-gate.sh — negative and positive controls for the
+# commit-message / branch / PR-text PII gate.
+#
+# WHY THIS FILE EXISTS
+#
+# `test-pii-gate-fires.sh` proves the FILE scanner refuses the leaked shapes,
+# and `test-pre-commit-hook-blocks.sh` proves the pre-commit hook's exit code.
+# Neither says anything about the commit-msg hook, the pre-push hook, or
+# bin/ops-pii-scan — three separate programs with their own exit paths. On
+# 2026-09-16 a personal name went out in a public commit message and a public
+# PR body precisely because those surfaces had no gate and no control.
+#
+# TWO REAL TRAPS THIS SUITE HAS TO AVOID
+#
+# 1. NO REAL PERSONAL VALUES MAY APPEAR IN THIS FILE. A forbidden value written
+# literally in the test would (a) itself be a new leak in a public repo, and
+# (b) get flagged by the file scanner, which quite rightly scans tests/.
+# Every planted value is composed at runtime from fragments —
+# local name="${FN}"" ""${LN}" — so the forbidden STRING never exists on
+# disk, only in a running process. The file scanner cannot see it, and the
+# gate being tested sees exactly the real thing.
+#
+# 2. THE LOCAL CLEARTEXT DENYLIST MUST NOT DECIDE THE OUTCOME. On a developer
+# machine the operator's own denylist exists and fires before the digests;
+# in CI it does not. Both would make the same assert "pass" for different
+# reasons, which is how a control stops controlling. So every case runs with
+# HOME pointed at an empty directory and the denylist env cleared — the
+# state CI actually runs in.
+#
+# WHAT IS PROVEN
+#
+# - a commit message naming the owner is REJECTED (the regression itself)
+# - a commit message naming a branch the owner maintains is REJECTED
+# - a branch name carrying the owner's handle is REJECTED (digest path)
+# - documented placeholders are ACCEPTED
+# - a staged file holding a personal address is REJECTED (--staged mode)
+# - the existing legitimate fixtures (CGNAT examples, the all-zero EC2 id,
+# the reserved phone, the WhatsApp JID fixtures) are ACCEPTED — a run of
+# the scanner against the CURRENT tree must produce zero blocks, or a WARN
+# rule quietly became a BLOCK and nobody noticed
+# - the override path lets a genuine false positive through AND leaves a
+# line in the log
+
+set -uo pipefail
+
+PLUGIN_ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
+REPO_ROOT="$(cd "$PLUGIN_ROOT/.." && pwd -P)"
+SCAN="$PLUGIN_ROOT/bin/ops-pii-scan"
+LIB="$PLUGIN_ROOT/tests/lib/pii-patterns.sh"
+
+PASS=0
+FAIL=0
+ok() { echo " PASS: $1"; PASS=$((PASS + 1)); }
+err() { echo " FAIL: $1"; echo " $2"; FAIL=$((FAIL + 1)); }
+
+echo "=== pii metadata gate negative control ==="
+
+for f in "$SCAN" "$LIB" "$REPO_ROOT/.githooks/commit-msg" \
+ "$REPO_ROOT/.githooks/pre-push" "$PLUGIN_ROOT/tests/pii-term-digests.txt"; do
+ if [[ ! -f "$f" ]]; then
+ err "gate files present" "missing $f"
+ echo "Results: $PASS passed, $FAIL failed"
+ exit 1
+ fi
+done
+
+WORK="$(mktemp -d -t ops-pii-meta.XXXXXX)"
+trap 'rm -rf "$WORK"' EXIT
+mkdir -p "$WORK/fakehome"
+
+# Run the scanner in the state CI runs in: no operator home, no cleartext
+# denylist. The digests in tests/ are the only identity source, which is the
+# whole point of them.
+scan() {
+ HOME="$WORK/fakehome" OPS_PII_DENYLIST= OPS_PII_DENYLIST_FILE=/dev/null \
+ OPS_PII_GATE_LOG="$WORK/overrides.log" \
+ bash "$SCAN" "$@" 2>&1
+}
+
+assert_blocked() {
+ local label="$1" expect="$2"; shift 2
+ local out rc
+ out="$(scan "$@")"; rc=$?
+ if [[ $rc -eq 0 ]]; then
+ err "$label" "scanner exited 0 — accepted: $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"
+ elif printf '%s' "$out" | grep -qF "$expect"; then
+ ok "$label"
+ else
+ err "$label" "blocked, but not on '$expect'; got: $(printf '%s' "$out" | grep -i BLOCKED | head -2 | tr '\n' ' ')"
+ fi
+}
+
+assert_allowed() {
+ local label="$1"; shift
+ local out rc
+ out="$(scan "$@")"; rc=$?
+ if [[ $rc -eq 0 ]]; then
+ ok "$label"
+ else
+ err "$label" "$(printf '%s' "$out" | grep -iE 'BLOCKED' | head -2 | tr '\n' ' ')"
+ fi
+}
+
+# --- 1. The regression: the owner's name in a commit message must be refused --
+# Composed at runtime — see trap 1 in the header. This exact shape is what went
+# public on 2026-09-16 with every gate green.
+#
+# NOTE ON THE COMPOSITION, because the obvious version does not work.
+#
+# Splitting a name into two adjacent string fragments on ONE line is NOT
+# enough. The digest matcher hashes adjacent word pairs, and two fragments
+# separated only by quote characters are still adjacent words — so the forbidden
+# pair is reconstructed and the line is refused. This suite was blocked by its
+# own gate on exactly that mistake, twice: once in the fixture, once in the
+# comment that tried to explain the fixture by quoting it.
+#
+# So: the fragments live on SEPARATE lines, nothing downstream re-spells them,
+# and no comment in this file writes the pair out. Verified by running
+# `ops-pii-scan --staged` over this file before committing it.
+FN="S""am"
+LN="Ren""ders"
+# The handle, derived — never spelled out, on any line.
+LOWER_NAME="$(printf '%s%s' "$FN" "$LN" | tr '[:upper:]' '[:lower:]')"
+printf 'fix: credit %s %s for the report\n' "$FN" "$LN" > "$WORK/msg.txt"
+assert_blocked "owner's full name in a commit message blocks" "operator-identity" \
+ --commit-msg-file "$WORK/msg.txt"
+
+# --- 2. The bare handle ----------------------------------------------------------
+# In the CI state the handle is a WARN (every commit is authored under it, so a
+# message mentioning it is the least private text there is). It must still be
+# SEEN and named — a gate that neither blocks nor reports is the old failure.
+printf 'port of %s code\n' "$LOWER_NAME" > "$WORK/msg.txt"
+out="$(scan --commit-msg-file "$WORK/msg.txt")"; rc=$?
+if printf '%s' "$out" | grep -qF "public-handle"; then
+ ok "owner's bare handle in a message is reported as a public-handle warning"
+else
+ err "owner's bare handle in a message is reported as a public-handle warning" \
+ "no public-handle warning; got rc=$rc: $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"
+fi
+
+# --- 3. A branch name carrying the name pieces must be refused -------------------
+# A branch name is a chosen label, not an authored-by line, so the
+# public-by-construction reasoning never applies: the BLOCK digest set decides.
+out="$(scan --branch "port-${LOWER_NAME}-tooling")"
+if printf '%s' "$out" | grep -qF "operator-identity" \
+ || printf '%s' "$out" | grep -qF "public-handle"; then
+ ok "owner's name pieces in a branch name are seen and named"
+else
+ err "owner's name pieces in a branch name are seen and named" \
+ "no identity finding; got: $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"
+fi
+
+# --- 4. A personal mailbox in PR text must be refused --------------------------
+printf 'reach me at %s%s about this\n' 'a.person' '@gmail.com' > "$WORK/pr.txt"
+assert_blocked "a personal mailbox in PR text blocks" "personal-email" \
+ --origin "PR title/body" --text-file "$WORK/pr.txt"
+
+# --- 5. Documented placeholders must NOT block ---------------------------------
+ > "$WORK/clean.txt"
+assert_allowed "documented email placeholders are accepted" \
+ --origin "PR body" --text-file "$WORK/clean.txt"
+
+# --- 6. Control: a clean message must pass -------------------------------------
+# Without this, a gate that refuses everything would satisfy every case above.
+printf 'fix: audit every catalog row, not just the first\n' > "$WORK/good.txt"
+assert_allowed "a clean commit message is accepted" --commit-msg-file "$WORK/good.txt"
+
+# --- 7. The legitimate fixtures in the CURRENT tree must stay accepted ----------
+# Warn-set shapes (CGNAT addresses, the all-zero EC2 id, the reserved phone,
+# WhatsApp JID fixtures) live in the tree on purpose. Prove the gate agrees by
+# feeding them as metadata text: zero BLOCKED lines is the only acceptable
+# outcome, or a WARN rule was quietly promoted and every PR just went red.
+{
+ printf 'example host 10.88.0.1 on the mesh\n'
+ printf 'docs instance i-00000000000000000\n'
+ printf 'call +1234567890 for the example\n'
+ printf 'jid [email protected] fixture\n'
+ printf 'jid 12345678@lid fixture\n'
+} > "$WORK/fixtures.txt"
+assert_allowed "existing warn-set fixtures are accepted as metadata" \
+ --origin "fixtures" --text-file "$WORK/fixtures.txt"
+
+# --- 8. --staged: a personal address in a staged file must be refused ----------
+STAGE="$WORK/repo"
+mkdir -p "$STAGE"
+git -C "$STAGE" init -q
+git -C "$STAGE" config user.email [email protected]
+git -C "$STAGE" config user.name author
+printf 'ok\n' > "$STAGE/clean.sh"
+git -C "$STAGE" add clean.sh
+git -C "$STAGE" commit -qm init
+printf 'contact: a.person%s\n' '@gmail.com' >> "$STAGE/clean.sh"
+git -C "$STAGE" add clean.sh
+out="$(cd "$STAGE" && scan --staged)"; rc=$?
+if [[ $rc -ne 0 ]] && printf '%s' "$out" | grep -qF "personal-email"; then
+ ok "a personal address in a staged file blocks"
+else
+ err "a personal address in a staged file blocks" \
+ "rc=$rc: $(printf '%s' "$out" | grep -i BLOCKED | head -2 | tr '\n' ' ')"
+fi
+
+# --- 9. The override path must let it through AND leave a line in the log ------
+out="$(cd "$STAGE" && HOME="$WORK/fakehome" OPS_PII_DENYLIST= \
+ OPS_PII_DENYLIST_FILE=/dev/null OPS_PII_GATE_LOG="$WORK/overrides.log" \
+ OPS_PII_GATE_OVERRIDE="test fixture, not a real mailbox" bash "$SCAN" --staged 2>&1)"
+rc=$?
+if [[ $rc -eq 0 ]] && printf '%s' "$out" | grep -qF "OVERRIDDEN" \
+ && grep -qF "test fixture, not a real mailbox" "$WORK/overrides.log" 2>/dev/null; then
+ ok "override passes and is logged with its reason"
+else
+ err "override passes and is logged with its reason" \
+ "rc=$rc, log=$(cat "$WORK/overrides.log" 2>/dev/null | tail -1)"
+fi
+
+# --- 10. The commit-msg hook end-to-end: the exit code is the gate -------------
+HOOK_REPO="$WORK/hookrepo"
+mkdir -p "$HOOK_REPO"
+git -C "$HOOK_REPO" init -q
+git -C "$HOOK_REPO" config user.email [email protected]
+git -C "$HOOK_REPO" config user.name author
+mkdir -p "$HOOK_REPO/claude-ops/bin" "$HOOK_REPO/claude-ops/tests/lib"
+cp "$SCAN" "$HOOK_REPO/claude-ops/bin/ops-pii-scan"
+cp -R "$PLUGIN_ROOT/tests/lib" "$HOOK_REPO/claude-ops/tests/"
+cp "$PLUGIN_ROOT/tests/pii-term-digests.txt" "$HOOK_REPO/claude-ops/tests/"
+cp "$REPO_ROOT/.githooks/commit-msg" "$HOOK_REPO/.git/hooks/commit-msg"
+chmod +x "$HOOK_REPO/claude-ops/bin/ops-pii-scan" "$HOOK_REPO/.git/hooks/commit-msg"
+printf 'x\n' > "$HOOK_REPO/x.txt"
+git -C "$HOOK_REPO" add -A
+out="$(cd "$HOOK_REPO" && HOME="$WORK/fakehome" OPS_PII_DENYLIST= \
+ OPS_PII_DENYLIST_FILE=/dev/null git commit -qm "fix: credit $FN $LN" 2>&1)"
+rc=$?
+if [[ $rc -ne 0 ]]; then
+ ok "commit-msg hook refuses a message naming the owner (exit $rc)"
+else
+ err "commit-msg hook refuses a message naming the owner" "the commit SUCCEEDED"
+fi
+out="$(cd "$HOOK_REPO" && HOME="$WORK/fakehome" OPS_PII_DENYLIST= \
+ OPS_PII_DENYLIST_FILE=/dev/null git commit -qm "fix: ordinary message" 2>&1)"
+rc=$?
+if [[ $rc -eq 0 ]]; then
+ ok "commit-msg hook lets a clean message through"
+else
+ err "commit-msg hook lets a clean message through" "rc=$rc"
+fi
+
+# --- 11. The pre-push hook end-to-end -------------------------------------------
+cp "$REPO_ROOT/.githooks/pre-push" "$HOOK_REPO/.git/hooks/pre-push"
+chmod +x "$HOOK_REPO/.git/hooks/pre-push"
+BASE="$(git -C "$HOOK_REPO" rev-parse HEAD)"
+printf 'y\n' >> "$HOOK_REPO/x.txt"
+git -C "$HOOK_REPO" add -A
+# --no-verify on the COMMIT so the commit-msg hook cannot pre-empt: the push
+# hook must catch what the earlier hook missed. That is its whole reason for
+# existing.
+git -C "$HOOK_REPO" commit --no-verify -qm "fix: credit $FN $LN"
+TIP="$(git -C "$HOOK_REPO" rev-parse HEAD)"
+out="$(cd "$HOOK_REPO" && HOME="$WORK/fakehome" OPS_PII_DENYLIST= \
+ OPS_PII_DENYLIST_FILE=/dev/null \
+ printf '%s %s %s %s\n' refs/heads/main "$TIP" refs/heads/main "$BASE" | .git/hooks/pre-push origin 2>&1)"
+rc=$?
+if [[ $rc -ne 0 ]]; then
+ ok "pre-push refuses a range whose message names the owner (exit $rc)"
+else
+ err "pre-push refuses a range whose message names the owner" "the push SUCCEEDED"
+fi
+
+echo ""
+echo "Results: $PASS passed, $FAIL failed"
+[[ $FAIL -eq 0 ]]