Skip to content

Commit 52c758a

Browse files
authored
Merge pull request #32 from Team-Gamism/refactor/claude
refactor: Claude 설정 구조 재편 및 API 응답 형식 통일
2 parents caf75f6 + fd86edd commit 52c758a

38 files changed

Lines changed: 1270 additions & 572 deletions

PushAndPull/.claude/commands/commit.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

PushAndPull/.claude/commands/migrate.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

PushAndPull/.claude/commands/test.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

PushAndPull/.claude/hooks/commit-msg.sh

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# .claude/hooks/postToolUse.sh
3+
4+
INPUT=$(cat)
5+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty')
6+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
7+
8+
if [[ "$TOOL_NAME" != "Edit" && "$TOOL_NAME" != "Write" ]]; then
9+
exit 0
10+
fi
11+
12+
if [[ "$FILE_PATH" != *.cs ]]; then
13+
exit 0
14+
fi
15+
16+
echo "[Hook] C# file modified: $FILE_PATH" >&2
17+
18+
dotnet format --no-restore 2>/dev/null || echo "[Hook] format failed (ignored)" >&2
19+
20+
CACHE_FILE=".claude/.last_build_hash"
21+
22+
CURRENT_HASH=$(find . -name "*.cs" -not -path "*/obj/*" | sort | xargs md5sum 2>/dev/null | md5sum | cut -d' ' -f1)
23+
24+
LAST_HASH=""
25+
if [[ -f "$CACHE_FILE" ]]; then
26+
LAST_HASH=$(cat "$CACHE_FILE")
27+
fi
28+
29+
if [[ "$CURRENT_HASH" != "$LAST_HASH" ]]; then
30+
echo "[Hook] Running dotnet build..." >&2
31+
if dotnet build PushAndPull/PushAndPull.csproj --no-restore; then
32+
echo "$CURRENT_HASH" > "$CACHE_FILE"
33+
else
34+
echo "[Hook] Build failed" >&2
35+
exit 2
36+
fi
37+
else
38+
echo "[Hook] Skip build (no source changes)" >&2
39+
fi
40+
41+
echo "[Hook] Running tests..." >&2
42+
if dotnet test PushAndPull.Test/PushAndPull.Test.csproj --no-build --verbosity minimal; then
43+
echo "[Hook] Tests passed" >&2
44+
else
45+
echo "[Hook] Tests failed" >&2
46+
exit 2
47+
fi
48+
49+
exit 0
Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
#!/bin/bash
22
# .claude/hooks/preCommit.sh
3-
# Ensure tests pass before allowing dotnet build/run/publish (Claude Code PreToolUse hook)
43

5-
INPUT=$(cat)
6-
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty')
7-
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
4+
COMMIT_MSG="$TOOL_PARAMS_MESSAGE"
85

9-
if [[ "$TOOL_NAME" != "Bash" ]]; then
10-
exit 0
11-
fi
6+
# allowed types
7+
PATTERN="^(feat|fix|update|docs): .+"
128

13-
if [[ ! "$COMMAND" =~ dotnet[[:space:]]+(build|run|publish) ]]; then
14-
exit 0
9+
if [[ ! "$COMMIT_MSG" =~ $PATTERN ]]; then
10+
echo "[Hook] ✗ Invalid commit message format"
11+
echo ""
12+
echo "Expected:"
13+
echo " {type}: {Korean description}"
14+
echo ""
15+
echo "Types:"
16+
echo " feat — new feature"
17+
echo " fix — bug fix or missing DI/config"
18+
echo " update — modification to existing code"
19+
echo " docs — documentation changes"
20+
echo ""
21+
echo "Examples:"
22+
echo " feat: 방 생성 API 추가"
23+
echo " fix: 세션 DI 누락 수정"
24+
echo " update: Room 엔터티 수정"
25+
exit 1
1526
fi
1627

17-
echo "[Hook] Checking tests before proceeding..."
18-
19-
dotnet test PushAndPull/PushAndPull.sln --nologo --no-build 2>/dev/null
20-
RESULT=$?
28+
# punctuation check
29+
if [[ "$COMMIT_MSG" =~ [\.\!]$ ]]; then
30+
echo "[Hook] ✗ Do not end the message with punctuation"
31+
echo "Example: feat: 방 생성 API 추가"
32+
exit 1
33+
fi
2134

22-
if [ $RESULT -ne 0 ]; then
23-
echo "[Hook] ✗ Tests failed — fix tests before running dotnet $BASH_REMATCH[1]"
24-
exit 2
35+
# ensure single line
36+
if [[ "$COMMIT_MSG" == *$'\n'* ]]; then
37+
echo "[Hook] ✗ Commit body is not allowed"
38+
echo "Use subject line only"
39+
exit 1
2540
fi
2641

27-
echo "[Hook] ✓ Tests passed"
28-
exit 0
42+
echo "[Hook] ✓ Commit message format valid"
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
#!/bin/bash
2-
# .claude/hooks/preToolUser.sh
2+
# .claude/hooks/preToolUse.sh
33
# Block dangerous commands before execution (Claude Code PreToolUse hook)
44

55
INPUT=$(cat)
66
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty')
77
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
88

9-
if [[ "$TOOL_NAME" != "Bash" ]]; then
10-
exit 0
11-
fi
9+
[[ "$TOOL_NAME" != "Bash" ]] && exit 0
1210

13-
NORMALIZED=$(echo "$COMMAND" | tr -s ' ')
11+
NORMALIZED=$(echo "$COMMAND" | tr -s ' ' | tr -d '\n')
1412

15-
BLOCKED_PATTERNS=(
16-
"rm -rf /"
17-
"rm -rf \."
18-
"rm -rf ~"
19-
"rm -rf \*"
20-
"sudo .*rm"
21-
"> /dev/"
22-
"dd if="
13+
DANGEROUS_KEYWORDS=(
14+
"rm -rf"
2315
"mkfs"
24-
"curl .*\| .*sh"
25-
"curl .*\| .*bash"
26-
"wget .*\| .*sh"
27-
"wget .*\| .*bash"
16+
"dd if="
17+
"shutdown"
18+
"reboot"
19+
"kill -9 -1"
20+
":(){"
21+
"> /dev/sda"
22+
"chmod -R 777 /"
23+
"chown -R root"
2824
)
2925

30-
for pattern in "${BLOCKED_PATTERNS[@]}"; do
31-
if [[ "$NORMALIZED" =~ $pattern ]]; then
32-
echo "[Hook] ✗ Blocked dangerous command"
33-
echo "Command: $COMMAND"
34-
echo "Reason: matched pattern '$pattern'"
26+
for keyword in "${DANGEROUS_KEYWORDS[@]}"; do
27+
if [[ "$NORMALIZED" == *"$keyword"* ]]; then
28+
echo "[Hook] ✗ Blocked dangerous keyword: $keyword" >&2
29+
echo "Command: $COMMAND" >&2
3530
exit 2
3631
fi
3732
done
3833

34+
# rm -rf / or rm -rf *
35+
if [[ "$NORMALIZED" =~ rm[[:space:]]+-rf.*(/|\*) ]]; then
36+
echo "[Hook] ✗ Blocked root/wildcard deletion" >&2
37+
exit 2
38+
fi
39+
40+
# curl/wget → pipe/redirect → sh/bash
41+
if [[ "$NORMALIZED" =~ (curl|wget).*(\||>).*(sh|bash) ]]; then
42+
echo "[Hook] ✗ Blocked remote execution" >&2
43+
exit 2
44+
fi
45+
3946
exit 0

0 commit comments

Comments
 (0)