From 036739af2f4c4b9b0086fb0966a266c1feeb7208 Mon Sep 17 00:00:00 2001 From: alientechsw <43017062+alientechsw@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:16:47 -0800 Subject: [PATCH 1/5] devx: scan committed content in check-pii.sh, not the worktree Follow-up to #645 (CodeRabbit PII thread r4774305100). - With a base ref, list files with a two-commit diff (base..HEAD) and read each file's committed content via git show HEAD:. A commit adding PII no longer passes when the worktree file was restored to clean content. - With no argument, read staged files from the index (git show :) instead of the worktree. - Match the patterns with grep -E: they are written as extended regex and plain grep never matched the SSN interval. - Fail closed when the base ref is missing instead of silently scanning the wrong set. - Files deleted at HEAD are skipped. --- SKILLS/nc-devx/scripts/check-pii.sh | 74 ++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/SKILLS/nc-devx/scripts/check-pii.sh b/SKILLS/nc-devx/scripts/check-pii.sh index f9496281..ee57421e 100644 --- a/SKILLS/nc-devx/scripts/check-pii.sh +++ b/SKILLS/nc-devx/scripts/check-pii.sh @@ -1,6 +1,21 @@ #!/bin/bash # NoteCraft PII Scanner - Checks for personally identifiable information -# Run: bash SKILLS/nc-devx/scripts/check-pii.sh [--fix] +# Run: bash SKILLS/nc-devx/scripts/check-pii.sh [--fix] [base-ref] +# +# What it scans, and where the content comes from: +# base-ref given (e.g. origin/main): the files changed against that ref, +# read from their COMMITTED content at HEAD (git show HEAD:). +# A commit that adds PII is caught even if the worktree file was +# restored to clean content afterwards. The file list itself comes +# from a two-commit diff (base..HEAD), not from the worktree: a +# one-arg `git diff ` compares base to the worktree, so a +# fully restored worktree would list nothing and the scan would +# never run. +# no argument: the staged files, read from the INDEX (git show :), +# not from the worktree. +# --fix: same scan as no argument, plus fix guidance after reporting. +# The scan never reads worktree files inside a git repo: worktree content +# is not what gets committed or pushed. # PII patterns to detect # Project-specific patterns (add your own as needed): @@ -11,19 +26,30 @@ PII_PATTERNS=( ) FIX_MODE=false +BASE_REF="" if [[ "$1" == "--fix" ]]; then FIX_MODE=true +elif [[ -n "$1" ]]; then + BASE_REF="$1" fi -# Determine what to scan +# Determine what to scan, and where its content comes from. +SCAN_MODE="worktree" # head | index | worktree if git rev-parse --git-dir > /dev/null 2>&1; then - # In a git repo: scan staged files if committing, all files if pushed - if [[ -n "$1" ]] && [[ "$1" != "--fix" ]]; then - # Called by cargo xtask pre-push: scan all changes - FILES=$(git diff origin/main --name-only 2>/dev/null || git diff --cached --name-only) + if [[ -n "$BASE_REF" ]]; then + # Called by the pre-push hook and by CI: scan the changes against + # the base ref. Fail closed if the ref is missing: scanning the + # wrong set (or nothing) would silently pass PII through. + if ! git rev-parse --verify --quiet "$BASE_REF" > /dev/null 2>&1; then + echo "check-pii: base ref '$BASE_REF' not found. Run 'git fetch origin' and try again." >&2 + exit 1 + fi + FILES=$(git diff "$BASE_REF" HEAD --name-only) + SCAN_MODE="head" else - # Called from pre-commit: scan staged files + # Called from pre-commit: scan staged files, from the index. FILES=$(git diff --cached --name-only) + SCAN_MODE="index" fi else # Not in git repo: scan current directory @@ -41,20 +67,46 @@ ISSUES_FILE=$(mktemp) # Scan each file while IFS= read -r file; do [[ -z "$file" ]] && continue - [[ ! -f "$file" ]] && continue + + # Fetch the content to scan. Inside a git repo this is the committed + # (HEAD) or staged (index) content, never the worktree file. + scan_target="$file" + tmp_file="" + if [[ "$SCAN_MODE" == "head" ]]; then + tmp_file=$(mktemp) + if ! git show "HEAD:$file" > "$tmp_file" 2>/dev/null; then + rm -f "$tmp_file" + continue # deleted at HEAD: nothing to push for this path + fi + scan_target="$tmp_file" + elif [[ "$SCAN_MODE" == "index" ]]; then + tmp_file=$(mktemp) + if ! git show ":$file" > "$tmp_file" 2>/dev/null; then + rm -f "$tmp_file" + continue # removed from the index + fi + scan_target="$tmp_file" + else + [[ ! -f "$file" ]] && continue + fi # Skip binary files - if file "$file" | grep -q "binary"; then + if file "$scan_target" | grep -q "binary"; then + [[ -n "$tmp_file" ]] && rm -f "$tmp_file" continue fi - # Check each pattern + # Check each pattern. The patterns are written as extended regex + # (unescaped {n,m} intervals), so grep needs -E: plain grep reads + # them as basic regex, where "{3}" is literal text and an SSN + # would never match. for pattern in "${PII_PATTERNS[@]}"; do - if grep -q "$pattern" "$file" 2>/dev/null; then + if grep -Eq "$pattern" "$scan_target" 2>/dev/null; then echo "$file: Found '$pattern'" >> "$ISSUES_FILE" FOUND_ISSUES=$((FOUND_ISSUES + 1)) fi done + [[ -n "$tmp_file" ]] && rm -f "$tmp_file" done <<< "$FILES" if [[ $FOUND_ISSUES -gt 0 ]]; then From a002eab2eb5465cf0eb3e4371a56ec1fc53358d2 Mon Sep 17 00:00:00 2001 From: alientechsw <43017062+alientechsw@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:22:42 -0800 Subject: [PATCH 2/5] ci: scan PII against origin/main with full history --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ad9bf00..49d20df4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,12 +237,14 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 - name: Install Rust run: rustup install - name: Branch check run: cargo xtask check-branch - name: PII scanner - run: bash SKILLS/nc-devx/scripts/check-pii.sh + run: bash SKILLS/nc-devx/scripts/check-pii.sh origin/main - name: Layers run: cargo xtask layers - name: Assets From 9509d40ee315e1150eda4a661753884c420e19b1 Mon Sep 17 00:00:00 2001 From: alientechsw <43017062+alientechsw@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:30:52 -0800 Subject: [PATCH 3/5] nightly: add warning-only i18n audit job --- .github/workflows/nightly-release.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml index 87f30765..21f5ba19 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly-release.yml @@ -277,7 +277,24 @@ jobs: echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "### NoteCraft $TAG (\`$(git rev-parse --short "$sha")\`)" >>"$GITHUB_STEP_SUMMARY" - test: + i18n-audit: + name: i18n audit (warning only) + # No `needs`: this runs every night, even when there is no release, + # so missing locale entries surface within a day of landing. + # `continue-on-error` keeps it a warning: the job shows orange when + # the audit fails, but the run stays green and no release job + # depends on this one. + continue-on-error: true + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install Rust + run: rustup install + - name: i18n audit + run: cargo xtask i18n-audit + + test: name: Build and test the tagged commit needs: prepare if: needs.prepare.outputs.release == 'true' From 919cdeb6fc24981cf880925234fb1887806d7723 Mon Sep 17 00:00:00 2001 From: alientechsw <43017062+alientechsw@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:51:55 -0800 Subject: [PATCH 4/5] fix(ci): correct YAML indentation in ci and nightly workflows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 248ab34a..93803152 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -241,7 +241,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - fetch-depth: 0 + fetch-depth: 0 - name: Install Rust run: rustup install - name: Branch check From d4bb049ddbeb6b4f0b92349b51345712a935c132 Mon Sep 17 00:00:00 2001 From: alientechsw <43017062+alientechsw@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:01:40 -0800 Subject: [PATCH 5/5] fix(ci): correct YAML indentation in ci and nightly workflows --- .github/workflows/nightly-release.yml | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml index 21f5ba19..7164b4ef 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly-release.yml @@ -278,23 +278,23 @@ jobs: echo "### NoteCraft $TAG (\`$(git rev-parse --short "$sha")\`)" >>"$GITHUB_STEP_SUMMARY" i18n-audit: - name: i18n audit (warning only) - # No `needs`: this runs every night, even when there is no release, - # so missing locale entries surface within a day of landing. - # `continue-on-error` keeps it a warning: the job shows orange when - # the audit fails, but the run stays green and no release job - # depends on this one. - continue-on-error: true - runs-on: ubuntu-24.04 - timeout-minutes: 30 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Install Rust - run: rustup install - - name: i18n audit - run: cargo xtask i18n-audit + name: i18n audit (warning only) + # No `needs`: this runs every night, even when there is no release, + # so missing locale entries surface within a day of landing. + # `continue-on-error` keeps it a warning: the job shows orange when + # the audit fails, but the run stays green and no release job + # depends on this one. + continue-on-error: true + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install Rust + run: rustup install + - name: i18n audit + run: cargo xtask i18n-audit - test: + test: name: Build and test the tagged commit needs: prepare if: needs.prepare.outputs.release == 'true'