#!/bin/bash # SessionStart + UserPromptSubmit hook — C35 audit 로그 3종 디렉토리 중앙 junction 보장 # 2026-04-20 #48 G 집행 신설 — PD님 직접 지시 "어떤 PC에서도 일관 상태 동시화" # 관련 규칙: C34-17 audit 특수 조항 · C36 PM 재량 상한 · 헌법 제1원칙 ⑤ CENTRAL_AUDIT="$HOME/.claude/burningtimes-audit" MARKER_NAME=".junction-marker" # 디렉토리 매핑: 로컬 디렉토리명(점 제외) | 중앙 하위 디렉토리명 MAPPINGS=( "burningtimes_auditor_calls|auditor_calls" "burningtimes_warning_ignored|warning_ignored" "burningtimes_bypass_log|bypass_log" ) # 1. 중앙 저장소 최상위 + marker 보장 mkdir -p "$CENTRAL_AUDIT" 2>/dev/null if [ ! -f "$CENTRAL_AUDIT/$MARKER_NAME" ]; then echo "burningtimes-audit central junction target (C34-17, 2026-04-20 #48 G)" > "$CENTRAL_AUDIT/$MARKER_NAME" 2>/dev/null fi # 2. 각 매핑 처리 for MAPPING in "${MAPPINGS[@]}"; do LOCAL_NAME="${MAPPING%|*}" CENTRAL_SUB="${MAPPING#*|}" LOCAL_DIR="$HOME/.claude/.$LOCAL_NAME" CENTRAL_DIR="$CENTRAL_AUDIT/$CENTRAL_SUB" # 중앙 하위 디렉토리 + sub marker 보장 mkdir -p "$CENTRAL_DIR" 2>/dev/null if [ ! -f "$CENTRAL_DIR/$MARKER_NAME" ]; then echo "burningtimes-audit/$CENTRAL_SUB junction target (C34-17)" > "$CENTRAL_DIR/$MARKER_NAME" 2>/dev/null fi # sentinel 판정: 로컬에서 marker 접근 가능하면 이미 연결 완료 if [ -f "$LOCAL_DIR/$MARKER_NAME" ]; then continue fi # 로컬이 실체 디렉토리이면 백업 후 이관 (C6-1 원본 보호) if [ -d "$LOCAL_DIR" ] && [ ! -L "$LOCAL_DIR" ]; then BAK="$LOCAL_DIR.bak_$(date +%Y%m%d_%H%M)" # 기존 파일 중앙으로 이관 (덮어쓰기 안 함) for f in "$LOCAL_DIR"/*.log "$LOCAL_DIR"/*.txt; do [ -f "$f" ] || continue BASENAME=$(basename "$f") [ ! -f "$CENTRAL_DIR/$BASENAME" ] && cp "$f" "$CENTRAL_DIR/$BASENAME" 2>/dev/null done mv "$LOCAL_DIR" "$BAK" 2>/dev/null || { echo "⚠️ [Audit Junction:$CENTRAL_SUB] 백업 실패 — Degraded" >&2; continue; } echo "📦 [Audit Junction:$CENTRAL_SUB] 기존 백업: $BAK" fi # Junction 생성 (3회 재시도) ATTEMPT=0 while [ "$ATTEMPT" -lt "3" ]; do ATTEMPT=$((ATTEMPT + 1)) if command -v powershell >/dev/null 2>&1; then CENTRAL_WIN=$(cygpath -w "$CENTRAL_DIR" 2>/dev/null || echo "$CENTRAL_DIR") LOCAL_WIN=$(cygpath -w "$LOCAL_DIR" 2>/dev/null || echo "$LOCAL_DIR") powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -ItemType Junction -Path '$LOCAL_WIN' -Target '$CENTRAL_WIN' -Force | Out-Null" >/dev/null 2>&1 else ln -s "$CENTRAL_DIR" "$LOCAL_DIR" 2>/dev/null fi if [ -f "$LOCAL_DIR/$MARKER_NAME" ]; then [ "$ATTEMPT" -eq 1 ] && echo "✅ [Audit Junction:$CENTRAL_SUB] $LOCAL_DIR → $CENTRAL_DIR" [ "$ATTEMPT" -gt 1 ] && echo "✅ [Audit Junction:$CENTRAL_SUB] 연결 성공 (재시도 $ATTEMPT회)" break fi sleep 1 done if [ ! -f "$LOCAL_DIR/$MARKER_NAME" ]; then mkdir -p "$LOCAL_DIR" 2>/dev/null echo "⚠️ [Audit Junction:$CENTRAL_SUB] 생성 실패 — Degraded 모드 (로컬 사용)" >&2 fi done exit 0