Skip to content

Commit 7ad9224

Browse files
tianjianjiangclaude
andcommitted
docs(agents): add development guardrails, C++ language server docs, and Claude Code automation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 040097e commit 7ad9224

8 files changed

Lines changed: 448 additions & 54 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
command -v jq >/dev/null 2>&1 || exit 0
9+
10+
INPUT=$(cat)
11+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
12+
13+
if [[ -z "$FILE_PATH" ]]; then
14+
exit 0
15+
fi
16+
17+
# Reject paths with newlines or path traversal
18+
if [[ "$FILE_PATH" =~ $'\n' ]] || [[ "$FILE_PATH" == *".."* ]]; then
19+
exit 2
20+
fi
21+
22+
# Block generated data files in Source/Data/ (absolute or relative paths)
23+
case "$FILE_PATH" in
24+
*/Source/Data/data.txt|*/Source/Data/data-plain-bpmf.txt|*/Source/Data/associated-phrases-v2.txt| \
25+
Source/Data/data.txt|Source/Data/data-plain-bpmf.txt|Source/Data/associated-phrases-v2.txt)
26+
echo "Blocked: $FILE_PATH is a generated file. Edit the source and rebuild instead." >&2
27+
exit 2
28+
;;
29+
esac

.claude/hooks/format-cpp.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
command -v jq >/dev/null 2>&1 || exit 0
8+
9+
# Read stdin JSON and extract file_path
10+
INPUT=$(cat)
11+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
12+
13+
if [[ -z "$FILE_PATH" ]]; then
14+
exit 0
15+
fi
16+
17+
# Reject paths with newlines, nulls, or path traversal
18+
if [[ "$FILE_PATH" =~ $'\n' ]] || [[ "$FILE_PATH" =~ $'\0' ]] || [[ "$FILE_PATH" == *".."* ]]; then
19+
exit 0
20+
fi
21+
22+
# Only format C++/ObjC source files
23+
case "$FILE_PATH" in
24+
*.cpp|*.h|*.mm|*.m)
25+
if [[ -f "$FILE_PATH" ]]; then
26+
xcrun clang-format -i -- "$FILE_PATH"
27+
fi
28+
;;
29+
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 -DCMAKE_EXPORT_COMPILE_COMMANDS=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.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ xcuserdata
1616
.vscode
1717
__pycache__
1818
codecov_comment.md
19-
DerivedData
19+
DerivedData
20+
compile_commands.json
21+
.cache

0 commit comments

Comments
 (0)