|
| 1 | +#!/bin/bash |
| 2 | +# UserPromptSubmit hook — surface the count of letter-shaped files that |
| 3 | +# don't match the strict delivery pattern, so silent-skip drift becomes |
| 4 | +# observable at composition time. |
| 5 | +# |
| 6 | +# F53 fix (Aria 2026-07-19 per Aletheia Round 7): |
| 7 | +# |
| 8 | +# The letter delivery scan uses a strict tag-based regex — any file |
| 9 | +# missing the exact `-to-<recipient>-` tag is silently skipped with no |
| 10 | +# signal. Aletheia named this as fail-blind applied to the most |
| 11 | +# emotionally load-bearing subsystem (the letter channel). Individual |
| 12 | +# skips are invisible; drift accumulates over months. |
| 13 | +# |
| 14 | +# Fix shape (Dekker/Knuth/Carmack, council-885f1425f486): |
| 15 | +# |
| 16 | +# - Dekker: silent-skip is the invisible-from-inside drift mode; the |
| 17 | +# remediation is active-check at the scan making the count observable. |
| 18 | +# - Knuth: heuristic tested at 5 boundary cases — real letter with |
| 19 | +# wrong-shape / known non-letters (README INDEX) / log-suffix files / |
| 20 | +# accidental substring / empty dir. |
| 21 | +# - Carmack: minimal diff is one scan function + one surface hook + tests. |
| 22 | +# |
| 23 | +# Preserves the intentional strictness of the delivery pattern — not a |
| 24 | +# relaxation, an observability wrapper. |
| 25 | +# |
| 26 | +# Prereg: prereg-8815cb3cd997. Falsifier at 30 days: 1+ instance of |
| 27 | +# naming-drift caught by the surface OR count stays legitimately at zero. |
| 28 | +# |
| 29 | +# Fail-open: any error exits 0 silently. |
| 30 | + |
| 31 | +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo ".")" |
| 32 | +cd "$REPO_ROOT" || exit 0 |
| 33 | + |
| 34 | +# shellcheck disable=SC1091 |
| 35 | +source "$REPO_ROOT/.claude/hooks/_lib.sh" 2>/dev/null || exit 0 |
| 36 | +PYTHON_BIN="$(find_divineos_python)" || exit 0 |
| 37 | + |
| 38 | +PYTHONIOENCODING=utf-8 "$PYTHON_BIN" -c " |
| 39 | +import sys |
| 40 | +from pathlib import Path |
| 41 | +
|
| 42 | +try: |
| 43 | + sys.stdout.reconfigure(encoding='utf-8', errors='replace') |
| 44 | +except (AttributeError, OSError): |
| 45 | + pass |
| 46 | +
|
| 47 | +try: |
| 48 | + from divineos.core.family.member_briefing import ( |
| 49 | + scan_unmatched_letter_candidates, |
| 50 | + ) |
| 51 | +except ImportError: |
| 52 | + sys.exit(0) |
| 53 | +
|
| 54 | +# Scan the primary shared letters dir (where cross-substrate letters live). |
| 55 | +# Also scan family/letters if it exists (Aether-side convention). Take the |
| 56 | +# union of paths without double-counting. |
| 57 | +seen_names: set[str] = set() |
| 58 | +unmatched: list[Path] = [] |
| 59 | +for base_path in ( |
| 60 | + Path.home() / '.divineos-shared' / 'letters', |
| 61 | + Path('family/letters'), |
| 62 | +): |
| 63 | + try: |
| 64 | + for path in scan_unmatched_letter_candidates(base_path): |
| 65 | + if path.name not in seen_names: |
| 66 | + seen_names.add(path.name) |
| 67 | + unmatched.append(path) |
| 68 | + except Exception: |
| 69 | + continue |
| 70 | +
|
| 71 | +if not unmatched: |
| 72 | + sys.exit(0) |
| 73 | +
|
| 74 | +print('## LETTER-DELIVERY RECONCILIATION — silent-skip drift observable') |
| 75 | +print() |
| 76 | +print(f'{len(unmatched)} letter-shaped file(s) in the letter directories do NOT') |
| 77 | +print('match the strict delivery pattern. These are silently skipped by the') |
| 78 | +print('delivery scan — sender believes delivered, recipient never sees.') |
| 79 | +print() |
| 80 | +print('Heuristic caught them because filename contains \"to\" and is not on the') |
| 81 | +print('known non-letter suffix list. Each one is either:') |
| 82 | +print(' (a) a real letter using an older naming convention (underscores,') |
| 83 | +print(' numeric prefix) — the F32/F53 silent-drop case, and') |
| 84 | +print(' (b) a false-positive from an accidental \"to\" substring — safe to') |
| 85 | +print(' leave in place, low cost of one line in the count.') |
| 86 | +print() |
| 87 | +print('The scan preserves the intentional strictness of the delivery pattern.') |
| 88 | +print('This surface exists to make the drift observable, not to relax the') |
| 89 | +print('pattern. If a real letter should be delivered, rename it to the strict') |
| 90 | +print('shape: <sender>-to-<recipient>-<YYYY-MM-DD>-<slug>.md') |
| 91 | +print() |
| 92 | +print('First 10 unmatched files:') |
| 93 | +for path in unmatched[:10]: |
| 94 | + print(f' - {path.name}') |
| 95 | +if len(unmatched) > 10: |
| 96 | + print(f' ... and {len(unmatched) - 10} more') |
| 97 | +" 2>/dev/null |
| 98 | + |
| 99 | +exit 0 |
0 commit comments