Skip to content

Commit fe48e62

Browse files
tianjianjiangclaude
andcommitted
docs(agents): add development guardrails and Claude Code automation
- CRITICAL pre-edit checklist (branch/worktree, dual build system, C++17, conventional commits) - C++17-only standard with prohibited C++20/C++23 features list - Build system integration rules (dual CMake + Xcode .pbxproj) - PR review and code-first verification guardrails - PostToolUse hook: auto-format C++/ObjC via clang-format - PreToolUse hook: block edits to generated data files - /engine-test and branch-guard skills - Fix runtime version (11.0), blob reader name, bridge utility references Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent fb72feb commit fe48e62

7 files changed

Lines changed: 406 additions & 51 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# PreToolUse hook: block direct edits to generated dictionary data files.
3+
# These files are produced by the dictionary compiler and must not be edited manually.
4+
# Exit code 2 blocks the tool from executing.
5+
6+
set -euo pipefail
7+
8+
INPUT=$(cat)
9+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
10+
11+
if [[ -z "$FILE_PATH" ]]; then
12+
exit 0
13+
fi
14+
15+
# Block generated data files in Source/Data/
16+
case "$FILE_PATH" in
17+
*/Source/Data/data.txt|*/Source/Data/data-plain-bpmf.txt|*/Source/Data/associated-phrases-v2.txt)
18+
echo "Blocked: $FILE_PATH is a generated file. Edit the source and rebuild instead." >&2
19+
exit 2
20+
;;
21+
esac

.claude/hooks/format-cpp.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# PostToolUse hook: auto-format C++/ObjC files with clang-format after edits.
3+
# Reads the tool input JSON from stdin to extract the edited file path.
4+
5+
set -euo pipefail
6+
7+
# Read stdin JSON and extract file_path
8+
INPUT=$(cat)
9+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
10+
11+
if [[ -z "$FILE_PATH" ]]; then
12+
exit 0
13+
fi
14+
15+
# Only format C++/ObjC source files
16+
case "$FILE_PATH" in
17+
*.cpp|*.h|*.mm|*.m)
18+
if [[ -f "$FILE_PATH" ]]; then
19+
xcrun clang-format -i "$FILE_PATH"
20+
fi
21+
;;
22+
esac

.claude/settings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "bash .claude/hooks/format-cpp.sh"
10+
}
11+
]
12+
}
13+
],
14+
"PreToolUse": [
15+
{
16+
"matcher": "Edit|Write",
17+
"hooks": [
18+
{
19+
"type": "command",
20+
"command": "bash .claude/hooks/block-generated-data.sh"
21+
}
22+
]
23+
}
24+
]
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description: Verify branch and worktree before making edits
3+
user-invocable: false
4+
---
5+
6+
# Branch Guard
7+
8+
Before editing files, verify:
9+
10+
1. **Current branch**: Run `git rev-parse --abbrev-ref HEAD` and confirm it matches the expected branch for the current task.
11+
12+
2. **Worktree isolation**: Run `git rev-parse --show-toplevel` and confirm edits target the correct worktree directory.
13+
14+
3. **Clean state**: Run `git status --porcelain` and warn if there are uncommitted changes that might conflict.
15+
16+
If any check fails, stop and alert the user before proceeding.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Build and run C++ engine tests
3+
user-invocable: true
4+
---
5+
6+
# /engine-test
7+
8+
Build and run the full C++ engine unit tests.
9+
10+
## Steps
11+
12+
1. Create the build directory if needed:
13+
```bash
14+
mkdir -p Source/Engine/build
15+
```
16+
17+
2. Configure with CMake:
18+
```bash
19+
cd Source/Engine/build && cmake -DENABLE_TEST=ON ..
20+
```
21+
22+
3. Build:
23+
```bash
24+
cd Source/Engine/build && make -j$(sysctl -n hw.ncpu)
25+
```
26+
27+
4. Run tests:
28+
```bash
29+
cd Source/Engine/build && ctest --output-on-failure
30+
```
31+
32+
Report test results. If any tests fail, show the failing test names and output.

0 commit comments

Comments
 (0)