BurningTimesAi/scripts/audit_junction_ensure.sh

79 lines
3.1 KiB
Bash
Raw Normal View History

feat(#48 D·F·G): C36 신설 + audit 중앙 통합 + 관련 보완 G (a) audit 중앙 통합 (C34 3종 저장소 확장) - scripts/audit_junction_ensure.sh 신설 (SessionStart + UserPromptSubmit hook) - scripts/sync_audit_{repo_to_central,central_to_repo}.sh 신설 - memory/org/audit_logs/ SOT 디렉토리 신설 (PC별 hostname 폴더) - .claude/settings.json hook 체인 편입 - scripts/git-hooks/post-commit audit sync 추가 - SKILL.md C34-1·C34-3 3종 저장소 확장 + C34-17 audit 특수 조항 신설 G (b) 코어룰 보완 — PM 임의 변형 방지 (PD님 직접 지시) - SKILL.md C36 헌법급 신설 (PM 자율 판단 범위 상한 · 방향·원칙 수준 축소·희석 금지) - C36-2 판정 기준 3종 명시 (pm-auditor Major 지적 반영) - SKILL.md C31-1 H 그룹 신설 (C36 자기검증 강제) - SKILL.md P11 보완 (규칙 변경 제안에 C36 적용) - .claude/agents/pm-auditor.md 5-E 신설 - memory/org/feedback_pm_surface_rationale_proposal.md 적용 범위 제한 (방향·원칙 수준 오적용 금지) - memory/org/feedback_pm_over_conservative_interpretation.md 6회차 변종 기록 D. .live/README.md 복구 - 중앙 저장소 $HOME/.claude/nerdnavis-live/README.md 신설 - SKILL.md C34와 역할 분담 (실무 사용 쿡북) - .live/ junction 경유로 레포에서도 접근 E. 진행하지 않음 (PD님 지시) F. plan-auditor 2번 섹션에 백업 포맷 이미 반영 확인 (추가 확장 불요) pm-auditor 사전 감사 Major 1·Minor 2·Improvement 2 수용. 헌법 제1원칙 ⑤ 직결. feedback_pm_over_conservative_interpretation 6회차 변종 구조 차단. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 03:12:30 +00:00
#!/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/nerdnavis-audit"
MARKER_NAME=".junction-marker"
# 디렉토리 매핑: 로컬 디렉토리명(점 제외) | 중앙 하위 디렉토리명
MAPPINGS=(
"nerdnavis_auditor_calls|auditor_calls"
"nerdnavis_warning_ignored|warning_ignored"
"nerdnavis_bypass_log|bypass_log"
)
# 1. 중앙 저장소 최상위 + marker 보장
mkdir -p "$CENTRAL_AUDIT" 2>/dev/null
if [ ! -f "$CENTRAL_AUDIT/$MARKER_NAME" ]; then
echo "nerdnavis-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 "nerdnavis-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