diff --git a/.agents/skills b/.agents/skills new file mode 120000 index 000000000000..454b8427cd75 --- /dev/null +++ b/.agents/skills @@ -0,0 +1 @@ +../.claude/skills \ No newline at end of file diff --git a/.codex/hooks.json b/.codex/hooks.json new file mode 100644 index 000000000000..7a5437cf53de --- /dev/null +++ b/.codex/hooks.json @@ -0,0 +1,17 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "\"$(git rev-parse --show-toplevel)/Scripts/codex-hooks/swift-format-and-lint.sh\"", + "timeout": 60, + "statusMessage": "Formatting and linting Swift..." + } + ] + } + ] + } +} diff --git a/Scripts/codex-hooks/swift-format-and-lint.sh b/Scripts/codex-hooks/swift-format-and-lint.sh new file mode 100755 index 000000000000..3e24f61265d7 --- /dev/null +++ b/Scripts/codex-hooks/swift-format-and-lint.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Codex PostToolUse hook: format and lint Swift files edited through apply_patch. +# Codex provides the applied patch in tool_input.command, while Claude Code provides +# the edited path directly. Support both payloads so the hook remains easy to reuse. + +files=$(jq -r ' + .tool_input.file_path? // empty, + ((.tool_input.command? // .tool_input.patch? // "") | split("\n")[] | + if startswith("*** Update File: ") then ltrimstr("*** Update File: ") + elif startswith("*** Add File: ") then ltrimstr("*** Add File: ") + else empty + end) +' | awk '/\.swift$/ { print }' | sort -u) + +[ -n "$files" ] || exit 0 + +for file in $files; do + [ -f "$file" ] || continue + xcrun swift format --in-place "$file" 2>/dev/null || true +done + +command -v rake >/dev/null 2>&1 || exit 0 + +status=0 +for file in $files; do + [ -f "$file" ] || continue + out=$(rake -s "lint[$file]" 2>&1) + if [ -n "$out" ]; then + echo "$out" >&2 + status=2 + fi +done + +exit "$status"