Files
boshu2__agentops/hooks/go-complexity-precommit.sh
T
Boden Fuller 744bcabeb9 chore(cli,ci,docs): tech debt swarm — 10 fixes across scripts, hooks, CI, docs
- Fix hardcoded /tmp path in test-json-flag-consistency.sh (use mktemp)
- Add graceful skip for missing jq/python3 in check-contract-compatibility.sh
- Fix import grouping in maturity_test.go
- Update .agents/retros/ → .agents/learnings/ in ratchet gate.go
- Extract _validate_restricted_cmd to lib/hook-helpers.sh (shared lib)
- Wire test-json-flag-consistency.sh into CI (new validate.yml job)
- Add post-merge naming cleanup step to swarm local-mode.md
- Document operationalization heuristics in plan SKILL.md
- Create check-file-manifest-overlap.sh for pre-spawn conflict detection
- Wire file manifest overlap check into CI with self-tests
- Pre-mortem fixes: bash 4+ guard, mktemp in CI self-tests
2026-03-05 13:12:54 -05:00

45 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# PostToolUse hook: check cyclomatic complexity of modified Go files.
# Non-blocking (exit 0) — logs warnings to stderr for visibility.
set -euo pipefail
# shellcheck source=../lib/hook-helpers.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/hook-helpers.sh"
# Only trigger on Edit/Write tool use against .go files
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // ""' 2>/dev/null) || TOOL_NAME=""
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // ""' 2>/dev/null) || FILE_PATH=""
# Normalize: strip repo root prefix if path is absolute
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ "$FILE_PATH" == /* ]]; then
FILE_PATH="${FILE_PATH#"$REPO_ROOT"/}"
fi
case "$TOOL_NAME" in
Edit|Write) ;;
*) exit 0 ;;
esac
[[ "$FILE_PATH" == *.go ]] || exit 0
[[ "$FILE_PATH" == cli/* ]] || exit 0
# Skip test files
[[ "$FILE_PATH" != *_test.go ]] || exit 0
if ! command -v gocyclo &>/dev/null; then
exit 0
fi
# Check complexity of the modified file
VIOLATIONS=$(gocyclo -over 15 "$FILE_PATH" 2>/dev/null || true)
if [[ -n "$VIOLATIONS" ]]; then
echo "Complexity warning in $FILE_PATH:" >&2
echo "$VIOLATIONS" >&2
echo "Consider extracting helpers to reduce CC below 15." >&2
fi
# Always exit 0 — this is advisory, not blocking
exit 0