agent/claude/code/hooks.json
Snider 817502b5f2
feat: Add test coverage tracking and reporting (#89)
This commit introduces a new feature to track test coverage over time and warn when it drops.

The new `/core:coverage` command can be used to display the current coverage, compare it to the last commit, and show a historical trend.

A pre-commit hook has also been added to warn when coverage drops.

Key changes:
- Created `claude/code/commands/coverage.sh` to handle coverage calculation, history tracking, and reporting.
- Created `claude/code/scripts/check-coverage.sh` to be used as a pre-commit hook.
- Created `.coverage-history.json` to store coverage history.
- Updated `claude/code/hooks.json` to add the new pre-commit hook.

Known limitations:
- The actual test coverage calculation is not implemented. A mock value is used as a placeholder. This is because I was unable to find the project's testing framework or a command to generate test coverage. A `TODO` has been added to the `coverage.sh` script to indicate where the real command should be added.
- The pre-commit hook is not being triggered. I have debugged the issue extensively, but the cause is still unknown. The `check-coverage.sh` script is fully functional and can be run manually.
2026-02-02 07:22:54 +00:00

122 lines
3.4 KiB
JSON

{
"$schema": "https://claude.ai/schemas/hooks.json",
"hooks": {
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/detect-module.sh"
}
],
"description": "Detect current module and export context variables",
"once": true
},
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/prefer-core.sh"
}
],
"description": "Block destructive commands (rm -rf, sed -i, xargs rm) and enforce core CLI"
},
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/block-docs.sh"
}
],
"description": "Block random .md file creation"
},
{
"matcher": "tool == \"Write\" || tool == \"Edit\"",
"hooks": [
{
"type": "command",
"command": "echo \"${tool_input.content}\" | ${CLAUDE_PLUGIN_ROOT}/scripts/detect-secrets.sh ${tool_input.filepath}"
}
],
"description": "Detect secrets in code before writing or editing files."
}
],
"PostToolUse": [
{
"matcher": "tool == \"Bash\" && tool_input.command matches \"^git commit\"",
"hooks": [{
"type": "command",
"command": "bash claude/code/scripts/check-coverage.sh"
}],
"description": "Warn when coverage drops"
},
{
"matcher": "tool == \"Edit\" && tool_input.file_path matches \"\\.go$\"",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/go-format.sh"
}
],
"description": "Auto-format Go files after edits"
},
{
"matcher": "tool == \"Edit\" && tool_input.file_path matches \"\\.php$\"",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/php-format.sh"
}
],
"description": "Auto-format PHP files after edits"
},
{
"matcher": "tool == \"Edit\"",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/check-debug.sh"
}
],
"description": "Warn about debug statements (dd, dump, fmt.Println)"
},
{
"matcher": "tool == \"Bash\" && tool_input.command matches \"^git commit\"",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/post-commit-check.sh"
}
],
"description": "Warn about uncommitted work after git commit"
}
],
"PreCompact": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/pre-compact.sh"
}
],
"description": "Save state before auto-compact to prevent amnesia"
}
],
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/session-start.sh"
}
],
"description": "Restore recent session context on startup"
}
]
}
}