- .claude/settings.json (공유) 신설, hooks 를 settings.local.json 에서 이동 - bash_guard (PreToolUse): 로컬 스택 기동·운영 DB alembic·_test 아닌 pytest·main 강제 push·위험 rm 차단, main push/deploy.sh 는 장중 경고와 함께 확인 요청, backend 커밋 전 유닛 스위트 게이트 - rules_check (PostToolUse): py_compile + CLAUDE.md 규칙(json.dumps, except 후 logger.debug, except-pass, 실시간 계층 DB I/O) — diff 추가 라인만 - session_context (SessionStart): 브랜치·미커밋·장 상태·alembic head 주입 - stop_check (Stop): frontend 변경 시 tsc - auto-orchestrate: 서브에이전트 보고·시스템 알림·질문형 프롬프트 오발동 제거 - /deploy 스킬 + deploy.sh / prod_smoke.sh: 테스트→dev push→main 병합→재기동 감시→공개 API 스모크 - 팀 에이전트·orchestrate 스킬 추적 시작, settings.local.json 추적 해제(.gitignore) - CLAUDE.md §9 하네스 - 훅 테스트 69 passed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.5 KiB
Python
Executable File
53 lines
1.5 KiB
Python
Executable File
"""하네스 훅 공용 유틸 (표준 라이브러리 전용)."""
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
KST = timezone(timedelta(hours=9))
|
|
|
|
|
|
def kst_now() -> datetime:
|
|
override = os.environ.get("HARNESS_NOW_KST") # 테스트용: 2026-10-02T10:00
|
|
if override:
|
|
try:
|
|
return datetime.fromisoformat(override).replace(tzinfo=KST)
|
|
except ValueError:
|
|
pass
|
|
return datetime.now(KST)
|
|
|
|
|
|
def market_state(now: datetime) -> str:
|
|
"""'휴장-주말' | '장전' | '장중' | '장후'. 공휴일은 판정하지 않는다(market_schedule 과 동일 한계)."""
|
|
if now.weekday() >= 5:
|
|
return "휴장-주말"
|
|
hm = now.hour * 60 + now.minute
|
|
if hm < 8 * 60 + 30:
|
|
return "장전"
|
|
if hm <= 15 * 60 + 40:
|
|
return "장중"
|
|
return "장후"
|
|
|
|
|
|
def read_stdin_json() -> dict:
|
|
try:
|
|
data = json.load(sys.stdin)
|
|
return data if isinstance(data, dict) else {}
|
|
except Exception:
|
|
return {}
|
|
|
|
|
|
def project_dir(data: dict | None = None) -> str:
|
|
return os.environ.get("CLAUDE_PROJECT_DIR") or (data or {}).get("cwd") or os.getcwd()
|
|
|
|
|
|
def git(args: list[str], cwd: str, timeout: float = 5.0) -> tuple[int, str]:
|
|
try:
|
|
p = subprocess.run(
|
|
["git", *args], cwd=cwd, capture_output=True, text=True, timeout=timeout
|
|
)
|
|
return p.returncode, p.stdout
|
|
except Exception:
|
|
return 1, ""
|