#!/usr/bin/env bash # RailPose3D SessionStart hook: PLAN.md / PROGRESS.md 핵심을 컨텍스트에 주입. # stdin = 이벤트 JSON, stdout = JSON {"hookSpecificOutput": {"additionalContext": "..."}} set -e PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}" PLAN="$PROJECT_DIR/PLAN.md" PROG="$PROJECT_DIR/PROGRESS.md" # 파일 부재 시 안전 종료 if [ ! -f "$PLAN" ] || [ ! -f "$PROG" ]; then printf '{"hookSpecificOutput":{"additionalContext":"[RailPose3D] PLAN.md 또는 PROGRESS.md 누락. /start 가 없으므로 사용자에게 셋업 진행 여부를 확인할 것."}}' exit 0 fi # Current Sprint + Next Action + Blockers 섹션만 추출 (간단한 grep 기반) SUMMARY=$(awk ' /^## Current Sprint/ {f=1; print; next} /^## Next Action/ {f=1; print; next} /^## Blockers/ {f=1; print; next} /^## / {f=0} f {print} ' "$PROG" | head -60) # 다이렉트 echo 가 한국어/유니코드 안전하지 않으므로 jq 가 있으면 사용, 없으면 escape if command -v jq >/dev/null 2>&1; then jq -nc --arg ctx "[RailPose3D] 세션 시작. 첫 작업 전 PLAN.md + PROGRESS.md 를 읽고 작업 위치를 명시할 것. 현재 PROGRESS 요약: $SUMMARY 권장 첫 명령: /start" '{hookSpecificOutput:{additionalContext:$ctx}}' else # jq 없을 때 fallback — 큰따옴표/개행 escape ESCAPED=$(printf '%s' "$SUMMARY" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | awk '{printf "%s\\n", $0}') printf '{"hookSpecificOutput":{"additionalContext":"[RailPose3D] 세션 시작. PLAN.md + PROGRESS.md 우선 확인. 권장 첫 명령: /start\\n\\n%s"}}' "$ESCAPED" fi